iat-three-manager 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,10 +1,9 @@
1
- import*as e from"three";import{DataTextureLoader as t,HalfFloatType as n,FloatType as r,RGBAFormat as i,LinearSRGBColorSpace as o,RedFormat as a,NoColorSpace as s,LinearFilter as c,DataUtils as l,Ray as u,Plane as h,MathUtils as d,EventDispatcher as p,Vector3 as f,MOUSE as m,TOUCH as g,Spherical as b,Quaternion as y,Vector2 as v,Object3D as x,Raycaster as w,MeshBasicMaterial as E,LineBasicMaterial as T,CylinderGeometry as A,BoxGeometry as C,BufferGeometry as O,Float32BufferAttribute as k,Mesh as S,OctahedronGeometry as R,Line as M,TorusGeometry as I,SphereGeometry as P,Euler as _,Matrix4 as N,PlaneGeometry as L,DoubleSide as D,BufferAttribute as j,Line3 as F,Triangle as U,Sphere as B,Box3 as z,BackSide as H,REVISION as V,FrontSide as G,BatchedMesh as W,Loader as X,FileLoader as q,SRGBColorSpace as Y,Color as K,TrianglesDrawMode as Q,TriangleFanDrawMode as Z,TriangleStripDrawMode as $,LoaderUtils as J,MeshPhysicalMaterial as ee,SpotLight as te,PointLight as ne,DirectionalLight as re,InstancedMesh as ie,InstancedBufferAttribute as oe,TextureLoader as ae,ImageBitmapLoader as se,InterleavedBuffer as ce,InterleavedBufferAttribute as le,LinearMipmapLinearFilter as ue,NearestMipmapLinearFilter as he,LinearMipmapNearestFilter as de,NearestMipmapNearestFilter as pe,NearestFilter as fe,RepeatWrapping as me,MirroredRepeatWrapping as ge,ClampToEdgeWrapping as be,PointsMaterial as ye,Material as ve,MeshStandardMaterial as xe,PropertyBinding as we,SkinnedMesh as Ee,LineSegments as Te,LineLoop as Ae,Points as Ce,Group as Oe,PerspectiveCamera as ke,OrthographicCamera as Se,Skeleton as Re,AnimationClip as Me,Bone as Ie,InterpolateDiscrete as Pe,InterpolateLinear as _e,Texture as Ne,VectorKeyframeTrack as Le,NumberKeyframeTrack as De,QuaternionKeyframeTrack as je,ColorManagement as Fe,Interpolant as Ue,MeshPhongMaterial as Be,DefaultLoadingManager as ze,Vector4 as He,Curve as Ve,MeshLambertMaterial as Ge,EquirectangularReflectionMapping as We,AmbientLight as Xe,Uint16BufferAttribute as qe,Matrix3 as Ye,ShapeUtils as Ke,Scene as Qe,Box2 as Ze,Shape as $e,Path as Je,ShapePath as et,AdditiveBlending as tt,DataTexture as nt,ConeGeometry as rt,Int32BufferAttribute as it,Sprite as ot,CanvasTexture as at,SpriteMaterial as st}from"three";
1
+ import*as e from"three";import{DataTextureLoader as t,HalfFloatType as n,FloatType as r,RGBAFormat as i,LinearSRGBColorSpace as o,RedFormat as a,NoColorSpace as s,LinearFilter as c,DataUtils as l,Ray as u,Plane as h,MathUtils as d,EventDispatcher as p,Vector3 as f,MOUSE as m,TOUCH as g,Spherical as b,Quaternion as y,Vector2 as v,Object3D as x,Raycaster as w,MeshBasicMaterial as E,LineBasicMaterial as T,CylinderGeometry as A,BoxGeometry as C,BufferGeometry as O,Float32BufferAttribute as k,Mesh as S,OctahedronGeometry as M,Line as R,TorusGeometry as I,SphereGeometry as P,Euler as _,Matrix4 as N,PlaneGeometry as L,DoubleSide as D,BufferAttribute as j,Line3 as F,Triangle as U,Sphere as B,Box3 as z,BackSide as H,REVISION as V,FrontSide as G,BatchedMesh as W,Loader as X,FileLoader as q,SRGBColorSpace as Y,Color as K,TrianglesDrawMode as Q,TriangleFanDrawMode as $,TriangleStripDrawMode as Z,LoaderUtils as J,MeshPhysicalMaterial as ee,SpotLight as te,PointLight as ne,DirectionalLight as re,InstancedMesh as ie,InstancedBufferAttribute as oe,TextureLoader as ae,ImageBitmapLoader as se,InterleavedBuffer as ce,InterleavedBufferAttribute as le,LinearMipmapLinearFilter as ue,NearestMipmapLinearFilter as he,LinearMipmapNearestFilter as de,NearestMipmapNearestFilter as pe,NearestFilter as fe,RepeatWrapping as me,MirroredRepeatWrapping as ge,ClampToEdgeWrapping as be,PointsMaterial as ye,Material as ve,MeshStandardMaterial as xe,PropertyBinding as we,SkinnedMesh as Ee,LineSegments as Te,LineLoop as Ae,Points as Ce,Group as Oe,PerspectiveCamera as ke,OrthographicCamera as Se,Skeleton as Me,AnimationClip as Re,Bone as Ie,InterpolateDiscrete as Pe,InterpolateLinear as _e,Texture as Ne,VectorKeyframeTrack as Le,NumberKeyframeTrack as De,QuaternionKeyframeTrack as je,ColorManagement as Fe,Interpolant as Ue,MeshPhongMaterial as Be,DefaultLoadingManager as ze,Vector4 as He,Curve as Ve,MeshLambertMaterial as Ge,EquirectangularReflectionMapping as We,AmbientLight as Xe,Uint16BufferAttribute as qe,Matrix3 as Ye,ShapeUtils as Ke,Scene as Qe,Box2 as $e,Shape as Ze,Path as Je,ShapePath as et,AdditiveBlending as tt,DataTexture as nt,ConeGeometry as rt,Int32BufferAttribute as it,Sprite as ot,CanvasTexture as at,SpriteMaterial as st}from"three";
2
2
  /*!
3
3
  fflate - fast JavaScript compression/decompression
4
4
  <https://101arrowz.github.io/fflate>
5
5
  Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
6
6
  version 0.6.9
7
- */var ct=function(e){return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};try{URL.revokeObjectURL(ct(""))}catch(e){ct=function(e){return"data:application/javascript;charset=UTF-8,"+encodeURI(e)}}var lt=Uint8Array,ut=Uint16Array,ht=Uint32Array,dt=new lt([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),pt=new lt([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ft=new lt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),mt=function(e,t){for(var n=new ut(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];var i=new ht(n[30]);for(r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)i[o]=o-n[r]<<5|r;return[n,i]},gt=mt(dt,2),bt=gt[0],yt=gt[1];bt[28]=258,yt[258]=28;for(var vt=mt(pt,0)[0],xt=new ut(32768),wt=0;wt<32768;++wt){var Et=(43690&wt)>>>1|(21845&wt)<<1;Et=(61680&(Et=(52428&Et)>>>2|(13107&Et)<<2))>>>4|(3855&Et)<<4,xt[wt]=((65280&Et)>>>8|(255&Et)<<8)>>>1}var Tt=function(e,t,n){for(var r=e.length,i=0,o=new ut(t);i<r;++i)++o[e[i]-1];var a,s=new ut(t);for(i=0;i<t;++i)s[i]=s[i-1]+o[i-1]<<1;if(n){a=new ut(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],h=s[e[i]-1]++<<u,d=h|(1<<u)-1;h<=d;++h)a[xt[h]>>>c]=l}else for(a=new ut(r),i=0;i<r;++i)e[i]&&(a[i]=xt[s[e[i]-1]++]>>>15-e[i]);return a},At=new lt(288);for(wt=0;wt<144;++wt)At[wt]=8;for(wt=144;wt<256;++wt)At[wt]=9;for(wt=256;wt<280;++wt)At[wt]=7;for(wt=280;wt<288;++wt)At[wt]=8;var Ct=new lt(32);for(wt=0;wt<32;++wt)Ct[wt]=5;var Ot=Tt(At,9,1),kt=Tt(Ct,5,1),St=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Rt=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(7&t)&n},Mt=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},It=function(e){return(e/8|0)+(7&e&&1)},Pt=function(e,t,n){var r=e.length;if(!r||n&&!n.l&&r<5)return t||new lt(0);var i=!t||n,o=!n||n.i;n||(n={}),t||(t=new lt(3*r));var a=function(e){var n=t.length;if(e>n){var r=new lt(Math.max(2*n,e));r.set(t),t=r}},s=n.f||0,c=n.p||0,l=n.b||0,u=n.l,h=n.d,d=n.m,p=n.n,f=8*r;do{if(!u){n.f=s=Rt(e,c,1);var m=Rt(e,c+1,3);if(c+=3,!m){var g=e[(k=It(c)+4)-4]|e[k-3]<<8,b=k+g;if(b>r){if(o)throw"unexpected EOF";break}i&&a(l+g),t.set(e.subarray(k,b),l),n.b=l+=g,n.p=c=8*b;continue}if(1==m)u=Ot,h=kt,d=9,p=5;else{if(2!=m)throw"invalid block type";var y=Rt(e,c,31)+257,v=Rt(e,c+10,15)+4,x=y+Rt(e,c+5,31)+1;c+=14;for(var w=new lt(x),E=new lt(19),T=0;T<v;++T)E[ft[T]]=Rt(e,c+3*T,7);c+=3*v;var A=St(E),C=(1<<A)-1,O=Tt(E,A,1);for(T=0;T<x;){var k,S=O[Rt(e,c,C)];if(c+=15&S,(k=S>>>4)<16)w[T++]=k;else{var R=0,M=0;for(16==k?(M=3+Rt(e,c,3),c+=2,R=w[T-1]):17==k?(M=3+Rt(e,c,7),c+=3):18==k&&(M=11+Rt(e,c,127),c+=7);M--;)w[T++]=R}}var I=w.subarray(0,y),P=w.subarray(y);d=St(I),p=St(P),u=Tt(I,d,1),h=Tt(P,p,1)}if(c>f){if(o)throw"unexpected EOF";break}}i&&a(l+131072);for(var _=(1<<d)-1,N=(1<<p)-1,L=c;;L=c){var D=(R=u[Mt(e,c)&_])>>>4;if((c+=15&R)>f){if(o)throw"unexpected EOF";break}if(!R)throw"invalid length/literal";if(D<256)t[l++]=D;else{if(256==D){L=c,u=null;break}var j=D-254;if(D>264){var F=dt[T=D-257];j=Rt(e,c,(1<<F)-1)+bt[T],c+=F}var U=h[Mt(e,c)&N],B=U>>>4;if(!U)throw"invalid distance";c+=15&U;P=vt[B];if(B>3){F=pt[B];P+=Mt(e,c)&(1<<F)-1,c+=F}if(c>f){if(o)throw"unexpected EOF";break}i&&a(l+131072);for(var z=l+j;l<z;l+=4)t[l]=t[l-P],t[l+1]=t[l+1-P],t[l+2]=t[l+2-P],t[l+3]=t[l+3-P];l=z}}n.l=u,n.p=L,n.b=l,u&&(s=1,n.m=d,n.d=h,n.n=p)}while(!s);return l==t.length?t:function(e,t,n){(null==n||n>e.length)&&(n=e.length);var r=new(e instanceof ut?ut:e instanceof ht?ht:lt)(n-t);return r.set(e.subarray(t,n)),r}(t,0,l)},_t=new lt(0);function Nt(e,t){return Pt((function(e){if(8!=(15&e[0])||e[0]>>>4>7||(e[0]<<8|e[1])%31)throw"invalid zlib data";if(32&e[1])throw"invalid zlib data: preset dictionaries not supported"}(e),e.subarray(2,-4)),t)}var Lt="undefined"!=typeof TextDecoder&&new TextDecoder;try{Lt.decode(_t,{stream:!0})}catch(e){}let Dt=class extends t{constructor(e){super(e),this.type=n}parse(e){const t=65536,c=14,u=65537,h=16384,d=Math.pow(2.7182818,2.2);const p={l:0,c:0,lc:0};function f(e,t,n,r,i){for(;n<e;)t=t<<8|Y(r,i),n+=8;n-=e,p.l=t>>n&(1<<e)-1,p.c=t,p.lc=n}const m=new Array(59);function g(e,t,n,r,i,o){const a=t;let s=0,c=0;for(;r<=i;r++){if(a.value-t.value>n)return!1;f(6,s,c,e,a);const l=p.l;if(s=p.c,c=p.lc,o[r]=l,63==l){if(a.value-t.value>n)throw new Error("Something wrong with hufUnpackEncTable");f(8,s,c,e,a);let l=p.l+6;if(s=p.c,c=p.lc,r+l>i+1)throw new Error("Something wrong with hufUnpackEncTable");for(;l--;)o[r++]=0;r--}else if(l>=59){let e=l-59+2;if(r+e>i+1)throw new Error("Something wrong with hufUnpackEncTable");for(;e--;)o[r++]=0;r--}}!function(e){for(let e=0;e<=58;++e)m[e]=0;for(let t=0;t<u;++t)m[e[t]]+=1;let t=0;for(let e=58;e>0;--e){const n=t+m[e]>>1;m[e]=t,t=n}for(let t=0;t<u;++t){const n=e[t];n>0&&(e[t]=n|m[n]++<<6)}}(o)}function b(e){return 63&e}function y(e){return e>>6}const v={c:0,lc:0};function x(e,t,n,r){e=e<<8|Y(n,r),t+=8,v.c=e,v.lc=t}const w={c:0,lc:0};function E(e,t,n,r,i,o,a,s,c){if(e==t){r<8&&(x(n,r,i,o),n=v.c,r=v.lc);let e=n>>(r-=8);if(e=new Uint8Array([e])[0],s.value+e>c)return!1;const t=a[s.value-1];for(;e-- >0;)a[s.value++]=t}else{if(!(s.value<c))return!1;a[s.value++]=e}w.c=n,w.lc=r}function T(e){return 65535&e}function A(e){const t=T(e);return t>32767?t-65536:t}const C={a:0,b:0};function O(e,t){const n=A(e),r=A(t),i=n+(1&r)+(r>>1),o=i,a=i-r;C.a=o,C.b=a}function k(e,t){const n=T(e),r=T(t),i=n-(r>>1)&65535,o=r+i-32768&65535;C.a=o,C.b=i}function S(e,t,n,r,i,o,a){const s=a<16384,c=n>i?i:n;let l,u,h=1;for(;h<=c;)h<<=1;for(h>>=1,l=h,h>>=1;h>=1;){u=0;const a=u+o*(i-l),c=o*h,d=o*l,p=r*h,f=r*l;let m,g,b,y;for(;u<=a;u+=d){let i=u;const o=u+r*(n-l);for(;i<=o;i+=f){const n=i+p,r=i+c,o=r+p;s?(O(e[i+t],e[r+t]),m=C.a,b=C.b,O(e[n+t],e[o+t]),g=C.a,y=C.b,O(m,g),e[i+t]=C.a,e[n+t]=C.b,O(b,y),e[r+t]=C.a,e[o+t]=C.b):(k(e[i+t],e[r+t]),m=C.a,b=C.b,k(e[n+t],e[o+t]),g=C.a,y=C.b,k(m,g),e[i+t]=C.a,e[n+t]=C.b,k(b,y),e[r+t]=C.a,e[o+t]=C.b)}if(n&h){const n=i+c;s?O(e[i+t],e[n+t]):k(e[i+t],e[n+t]),m=C.a,e[n+t]=C.b,e[i+t]=m}}if(i&h){let i=u;const o=u+r*(n-l);for(;i<=o;i+=f){const n=i+p;s?O(e[i+t],e[n+t]):k(e[i+t],e[n+t]),m=C.a,e[n+t]=C.b,e[i+t]=m}}l=h,h>>=1}return u}function R(e,t,n,r,i,o){const a=n.value,s=q(t,n),l=q(t,n);n.value+=4;const d=q(t,n);if(n.value+=4,s<0||s>=u||l<0||l>=u)throw new Error("Something wrong with HUF_ENCSIZE");const p=new Array(u),f=new Array(h);!function(e){for(let t=0;t<h;t++)e[t]={},e[t].len=0,e[t].lit=0,e[t].p=null}(f);if(g(e,n,r-(n.value-a),s,l,p),d>8*(r-(n.value-a)))throw new Error("Something wrong with hufUncompress");!function(e,t,n,r){for(;t<=n;t++){const n=y(e[t]),i=b(e[t]);if(n>>i)throw new Error("Invalid table entry");if(i>c){const e=r[n>>i-c];if(e.len)throw new Error("Invalid table entry");if(e.lit++,e.p){const t=e.p;e.p=new Array(e.lit);for(let n=0;n<e.lit-1;++n)e.p[n]=t[n]}else e.p=new Array(1);e.p[e.lit-1]=t}else if(i){let e=0;for(let o=1<<c-i;o>0;o--){const o=r[(n<<c-i)+e];if(o.len||o.p)throw new Error("Invalid table entry");o.len=i,o.lit=t,e++}}}}(p,s,l,f),function(e,t,n,r,i,o,a,s,l){let u=0,h=0;const d=a,p=Math.trunc(r.value+(i+7)/8);for(;r.value<p;)for(x(u,h,n,r),u=v.c,h=v.lc;h>=c;){const i=t[u>>h-c&16383];if(i.len)h-=i.len,E(i.lit,o,u,h,n,r,s,l,d),u=w.c,h=w.lc;else{if(!i.p)throw new Error("hufDecode issues");let t;for(t=0;t<i.lit;t++){const a=b(e[i.p[t]]);for(;h<a&&r.value<p;)x(u,h,n,r),u=v.c,h=v.lc;if(h>=a&&y(e[i.p[t]])==(u>>h-a&(1<<a)-1)){h-=a,E(i.p[t],o,u,h,n,r,s,l,d),u=w.c,h=w.lc;break}}if(t==i.lit)throw new Error("hufDecode issues")}}const f=8-i&7;for(u>>=f,h-=f;h>0;){const e=t[u<<c-h&16383];if(!e.len)throw new Error("hufDecode issues");h-=e.len,E(e.lit,o,u,h,n,r,s,l,d),u=w.c,h=w.lc}}(p,f,e,n,d,l,o,i,{value:0})}function M(e){for(let t=1;t<e.length;t++){const n=e[t-1]+e[t]-128;e[t]=n}}function I(e,t){let n=0,r=Math.floor((e.length+1)/2),i=0;const o=e.length-1;for(;!(i>o||(t[i++]=e[n++],i>o));)t[i++]=e[r++]}function P(e){let t=e.byteLength;const n=new Array;let r=0;const i=new DataView(e);for(;t>0;){const e=i.getInt8(r++);if(e<0){const o=-e;t-=o+1;for(let e=0;e<o;e++)n.push(i.getUint8(r++))}else{const o=e;t-=2;const a=i.getUint8(r++);for(let e=0;e<o+1;e++)n.push(a)}}return n}function _(e,t,n){let r,i=1;for(;i<64;)r=t[e.value],65280==r?i=64:r>>8==255?i+=255&r:(n[i]=r,i++),e.value++}function N(e,t){t[0]=J(e[0]),t[1]=J(e[1]),t[2]=J(e[5]),t[3]=J(e[6]),t[4]=J(e[14]),t[5]=J(e[15]),t[6]=J(e[27]),t[7]=J(e[28]),t[8]=J(e[2]),t[9]=J(e[4]),t[10]=J(e[7]),t[11]=J(e[13]),t[12]=J(e[16]),t[13]=J(e[26]),t[14]=J(e[29]),t[15]=J(e[42]),t[16]=J(e[3]),t[17]=J(e[8]),t[18]=J(e[12]),t[19]=J(e[17]),t[20]=J(e[25]),t[21]=J(e[30]),t[22]=J(e[41]),t[23]=J(e[43]),t[24]=J(e[9]),t[25]=J(e[11]),t[26]=J(e[18]),t[27]=J(e[24]),t[28]=J(e[31]),t[29]=J(e[40]),t[30]=J(e[44]),t[31]=J(e[53]),t[32]=J(e[10]),t[33]=J(e[19]),t[34]=J(e[23]),t[35]=J(e[32]),t[36]=J(e[39]),t[37]=J(e[45]),t[38]=J(e[52]),t[39]=J(e[54]),t[40]=J(e[20]),t[41]=J(e[22]),t[42]=J(e[33]),t[43]=J(e[38]),t[44]=J(e[46]),t[45]=J(e[51]),t[46]=J(e[55]),t[47]=J(e[60]),t[48]=J(e[21]),t[49]=J(e[34]),t[50]=J(e[37]),t[51]=J(e[47]),t[52]=J(e[50]),t[53]=J(e[56]),t[54]=J(e[59]),t[55]=J(e[61]),t[56]=J(e[35]),t[57]=J(e[36]),t[58]=J(e[48]),t[59]=J(e[49]),t[60]=J(e[57]),t[61]=J(e[58]),t[62]=J(e[62]),t[63]=J(e[63])}function L(e){const t=.5*Math.cos(.7853975),n=.5*Math.cos(3.14159/16),r=.5*Math.cos(3.14159/8),i=.5*Math.cos(3*3.14159/16),o=.5*Math.cos(.981746875),a=.5*Math.cos(3*3.14159/8),s=.5*Math.cos(1.374445625),c=new Array(4),l=new Array(4),u=new Array(4),h=new Array(4);for(let d=0;d<8;++d){const p=8*d;c[0]=r*e[p+2],c[1]=a*e[p+2],c[2]=r*e[p+6],c[3]=a*e[p+6],l[0]=n*e[p+1]+i*e[p+3]+o*e[p+5]+s*e[p+7],l[1]=i*e[p+1]-s*e[p+3]-n*e[p+5]-o*e[p+7],l[2]=o*e[p+1]-n*e[p+3]+s*e[p+5]+i*e[p+7],l[3]=s*e[p+1]-o*e[p+3]+i*e[p+5]-n*e[p+7],u[0]=t*(e[p+0]+e[p+4]),u[3]=t*(e[p+0]-e[p+4]),u[1]=c[0]+c[3],u[2]=c[1]-c[2],h[0]=u[0]+u[1],h[1]=u[3]+u[2],h[2]=u[3]-u[2],h[3]=u[0]-u[1],e[p+0]=h[0]+l[0],e[p+1]=h[1]+l[1],e[p+2]=h[2]+l[2],e[p+3]=h[3]+l[3],e[p+4]=h[3]-l[3],e[p+5]=h[2]-l[2],e[p+6]=h[1]-l[1],e[p+7]=h[0]-l[0]}for(let d=0;d<8;++d)c[0]=r*e[16+d],c[1]=a*e[16+d],c[2]=r*e[48+d],c[3]=a*e[48+d],l[0]=n*e[8+d]+i*e[24+d]+o*e[40+d]+s*e[56+d],l[1]=i*e[8+d]-s*e[24+d]-n*e[40+d]-o*e[56+d],l[2]=o*e[8+d]-n*e[24+d]+s*e[40+d]+i*e[56+d],l[3]=s*e[8+d]-o*e[24+d]+i*e[40+d]-n*e[56+d],u[0]=t*(e[d]+e[32+d]),u[3]=t*(e[d]-e[32+d]),u[1]=c[0]+c[3],u[2]=c[1]-c[2],h[0]=u[0]+u[1],h[1]=u[3]+u[2],h[2]=u[3]-u[2],h[3]=u[0]-u[1],e[0+d]=h[0]+l[0],e[8+d]=h[1]+l[1],e[16+d]=h[2]+l[2],e[24+d]=h[3]+l[3],e[32+d]=h[3]-l[3],e[40+d]=h[2]-l[2],e[48+d]=h[1]-l[1],e[56+d]=h[0]-l[0]}function D(e){for(let t=0;t<64;++t){const n=e[0][t],r=e[1][t],i=e[2][t];e[0][t]=n+1.5747*i,e[1][t]=n-.1873*r-.4682*i,e[2][t]=n+1.8556*r}}function j(e,t,n){for(let r=0;r<64;++r)t[n+r]=l.toHalfFloat(F(e[r]))}function F(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(d,Math.abs(e)-1)}function U(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function B(e){const t=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),n=new Uint8Array(P(t)),r=new Uint8Array(n.length);return M(n),I(n,r),new DataView(r.buffer)}function z(e){const t=Nt(e.array.slice(e.offset.value,e.offset.value+e.size)),n=new Uint8Array(t.length);return M(t),I(t,n),new DataView(n.buffer)}function H(e){const n=e.viewer,r={value:e.offset.value},i=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),o=new Uint8Array(8192);let a=0;const s=new Array(e.channels);for(let t=0;t<e.channels;t++)s[t]={},s[t].start=a,s[t].end=s[t].start,s[t].nx=e.width,s[t].ny=e.lines,s[t].size=e.type,a+=s[t].nx*s[t].ny*s[t].size;const c=ee(n,r),l=ee(n,r);if(l>=8192)throw new Error("Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(c<=l)for(let e=0;e<l-c+1;e++)o[e+c]=K(n,r);const u=new Uint16Array(t),h=function(e,n){let r=0;for(let i=0;i<t;++i)(0==i||e[i>>3]&1<<(7&i))&&(n[r++]=i);const i=r-1;for(;r<t;)n[r++]=0;return i}(o,u),d=q(n,r);R(e.array,n,r,d,i,a);for(let t=0;t<e.channels;++t){const e=s[t];for(let n=0;n<s[t].size;++n)S(i,e.start+n,e.nx,e.size,e.ny,e.nx*e.size,h)}!function(e,t,n){for(let r=0;r<n;++r)t[r]=e[t[r]]}(u,i,a);let p=0;const f=new Uint8Array(i.buffer.byteLength);for(let t=0;t<e.lines;t++)for(let t=0;t<e.channels;t++){const e=s[t],n=e.nx*e.size,r=new Uint8Array(i.buffer,2*e.end,2*n);f.set(r,p),p+=2*n,e.end+=n}return new DataView(f.buffer)}function V(e){const t=Nt(e.array.slice(e.offset.value,e.offset.value+e.size)),n=e.lines*e.channels*e.width,r=1==e.type?new Uint16Array(n):new Uint32Array(n);let i=0,o=0;const a=new Array(4);for(let n=0;n<e.lines;n++)for(let n=0;n<e.channels;n++){let n=0;switch(e.type){case 1:a[0]=i,a[1]=a[0]+e.width,i=a[1]+e.width;for(let i=0;i<e.width;++i){n+=t[a[0]++]<<8|t[a[1]++],r[o]=n,o++}break;case 2:a[0]=i,a[1]=a[0]+e.width,a[2]=a[1]+e.width,i=a[2]+e.width;for(let i=0;i<e.width;++i){n+=t[a[0]++]<<24|t[a[1]++]<<16|t[a[2]++]<<8,r[o]=n,o++}}}return new DataView(r.buffer)}function G(e){const t=e.viewer,n={value:e.offset.value},r=new Uint8Array(e.width*e.lines*(e.channels*e.type*2)),i={version:Q(t,n),unknownUncompressedSize:Q(t,n),unknownCompressedSize:Q(t,n),acCompressedSize:Q(t,n),dcCompressedSize:Q(t,n),rleCompressedSize:Q(t,n),rleUncompressedSize:Q(t,n),rleRawSize:Q(t,n),totalAcUncompressedCount:Q(t,n),totalDcUncompressedCount:Q(t,n),acCompression:Q(t,n)};if(i.version<2)throw new Error("EXRLoader.parse: "+ae.compression+" version "+i.version+" is unsupported");const o=new Array;let a=ee(t,n)-2;for(;a>0;){const e=W(t.buffer,n),r=K(t,n),i=r>>2&3,s=new Int8Array([(r>>4)-1])[0],c=K(t,n);o.push({name:e,index:s,type:c,compression:i}),a-=e.length+3}const s=ae.channels,c=new Array(e.channels);for(let t=0;t<e.channels;++t){const n=c[t]={},r=s[t];n.name=r.name,n.compression=0,n.decoded=!1,n.type=r.pixelType,n.pLinear=r.pLinear,n.width=e.width,n.height=e.lines}const l={idx:new Array(3)};for(let t=0;t<e.channels;++t){const e=c[t];for(let n=0;n<o.length;++n){const r=o[n];e.name==r.name&&(e.compression=r.compression,r.index>=0&&(l.idx[r.index]=t),e.offset=t)}}let u,h,d;if(i.acCompressedSize>0)switch(i.acCompression){case 0:u=new Uint16Array(i.totalAcUncompressedCount),R(e.array,t,n,i.acCompressedSize,u,i.totalAcUncompressedCount);break;case 1:const r=Nt(e.array.slice(n.value,n.value+i.totalAcUncompressedCount));u=new Uint16Array(r.buffer),n.value+=i.totalAcUncompressedCount}if(i.dcCompressedSize>0){const t={array:e.array,offset:n,size:i.dcCompressedSize};h=new Uint16Array(z(t).buffer),n.value+=i.dcCompressedSize}if(i.rleRawSize>0){d=P(Nt(e.array.slice(n.value,n.value+i.rleCompressedSize)).buffer),n.value+=i.rleCompressedSize}let p=0;const f=new Array(c.length);for(let e=0;e<f.length;++e)f[e]=new Array;for(let t=0;t<e.lines;++t)for(let t=0;t<c.length;++t)f[t].push(p),p+=c[t].width*e.type*2;!function(e,t,n,r,i,o){let a=new DataView(o.buffer);const s=n[e.idx[0]].width,c=n[e.idx[0]].height,l=Math.floor(s/8),u=Math.ceil(s/8),h=Math.ceil(c/8),d=s-8*(u-1),p=c-8*(h-1),f={value:0},m=new Array(3),g=new Array(3),b=new Array(3),y=new Array(3),v=new Array(3);for(let n=0;n<3;++n)v[n]=t[e.idx[n]],m[n]=n<1?0:m[n-1]+u*h,g[n]=new Float32Array(64),b[n]=new Uint16Array(64),y[n]=new Uint16Array(64*u);for(let t=0;t<h;++t){let o=8;t==h-1&&(o=p);let s=8;for(let e=0;e<u;++e){e==u-1&&(s=d);for(let e=0;e<3;++e)b[e].fill(0),b[e][0]=i[m[e]++],_(f,r,b[e]),N(b[e],g[e]),L(g[e]);D(g);for(let t=0;t<3;++t)j(g[t],y[t],64*e)}let c=0;for(let r=0;r<3;++r){const i=n[e.idx[r]].type;for(let e=8*t;e<8*t+o;++e){c=v[r][e];for(let t=0;t<l;++t){const n=64*t+8*(7&e);a.setUint16(c+0*i,y[r][n+0],!0),a.setUint16(c+2*i,y[r][n+1],!0),a.setUint16(c+4*i,y[r][n+2],!0),a.setUint16(c+6*i,y[r][n+3],!0),a.setUint16(c+8*i,y[r][n+4],!0),a.setUint16(c+10*i,y[r][n+5],!0),a.setUint16(c+12*i,y[r][n+6],!0),a.setUint16(c+14*i,y[r][n+7],!0),c+=16*i}}if(l!=u)for(let e=8*t;e<8*t+o;++e){const t=v[r][e]+8*l*2*i,n=64*l+8*(7&e);for(let e=0;e<s;++e)a.setUint16(t+2*e*i,y[r][n+e],!0)}}}const x=new Uint16Array(s);a=new DataView(o.buffer);for(let t=0;t<3;++t){n[e.idx[t]].decoded=!0;const r=n[e.idx[t]].type;if(2==n[t].type)for(let e=0;e<c;++e){const n=v[t][e];for(let e=0;e<s;++e)x[e]=a.getUint16(n+2*e*r,!0);for(let e=0;e<s;++e)a.setFloat32(n+2*e*r,J(x[e]),!0)}}}(l,f,c,u,h,r);for(let t=0;t<c.length;++t){const n=c[t];if(!n.decoded){if(2!==n.compression)throw new Error("EXRLoader.parse: unsupported channel compression");{let i=0,o=0;for(let a=0;a<e.lines;++a){let e=f[t][i];for(let t=0;t<n.width;++t){for(let t=0;t<2*n.type;++t)r[e++]=d[o+t*n.width*n.height];o++}i++}}}}return new DataView(r.buffer)}function W(e,t){const n=new Uint8Array(e);let r=0;for(;0!=n[t.value+r];)r+=1;const i=(new TextDecoder).decode(n.slice(t.value,t.value+r));return t.value=t.value+r+1,i}function X(e,t){const n=e.getInt32(t.value,!0);return t.value=t.value+4,n}function q(e,t){const n=e.getUint32(t.value,!0);return t.value=t.value+4,n}function Y(e,t){const n=e[t.value];return t.value=t.value+1,n}function K(e,t){const n=e.getUint8(t.value);return t.value=t.value+1,n}const Q=function(e,t){let n;return n="getBigInt64"in DataView.prototype?Number(e.getBigInt64(t.value,!0)):e.getUint32(t.value+4,!0)+Number(e.getUint32(t.value,!0)<<32),t.value+=8,n};function Z(e,t){const n=e.getFloat32(t.value,!0);return t.value+=4,n}function $(e,t){return l.toHalfFloat(Z(e,t))}function J(e){const t=(31744&e)>>10,n=1023&e;return(e>>15?-1:1)*(t?31===t?n?NaN:1/0:Math.pow(2,t-15)*(1+n/1024):n/1024*6103515625e-14)}function ee(e,t){const n=e.getUint16(t.value,!0);return t.value+=2,n}function te(e,t){return J(ee(e,t))}function ne(e,t,n,r,i){return"string"===r||"stringvector"===r||"iccProfile"===r?function(e,t,n){const r=(new TextDecoder).decode(new Uint8Array(e).slice(t.value,t.value+n));return t.value=t.value+n,r}(t,n,i):"chlist"===r?function(e,t,n,r){const i=n.value,o=[];for(;n.value<i+r-1;){const r=W(t,n),i=X(e,n),a=K(e,n);n.value+=3;const s=X(e,n),c=X(e,n);o.push({name:r,pixelType:i,pLinear:a,xSampling:s,ySampling:c})}return n.value+=1,o}(e,t,n,i):"chromaticities"===r?function(e,t){return{redX:Z(e,t),redY:Z(e,t),greenX:Z(e,t),greenY:Z(e,t),blueX:Z(e,t),blueY:Z(e,t),whiteX:Z(e,t),whiteY:Z(e,t)}}(e,n):"compression"===r?function(e,t){return["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"][K(e,t)]}(e,n):"box2i"===r?function(e,t){return{xMin:q(e,t),yMin:q(e,t),xMax:q(e,t),yMax:q(e,t)}}(e,n):"lineOrder"===r?function(e,t){return["INCREASING_Y"][K(e,t)]}(e,n):"float"===r?Z(e,n):"v2f"===r?function(e,t){return[Z(e,t),Z(e,t)]}(e,n):"v3f"===r?function(e,t){return[Z(e,t),Z(e,t),Z(e,t)]}(e,n):"int"===r?X(e,n):"rational"===r?function(e,t){return[X(e,t),q(e,t)]}(e,n):"timecode"===r?function(e,t){return[q(e,t),q(e,t)]}(e,n):"preview"===r?(n.value+=i,"skipped"):void(n.value+=i)}const re=new DataView(e),ie=new Uint8Array(e),oe={value:0},ae=function(e,t,n){const r={};if(20000630!=e.getUint32(0,!0))throw new Error("THREE.EXRLoader: Provided file doesn't appear to be in OpenEXR format.");r.version=e.getUint8(4);const i=e.getUint8(5);r.spec={singleTile:!!(2&i),longName:!!(4&i),deepFormat:!!(8&i),multiPart:!!(16&i)},n.value=8;let o=!0;for(;o;){const i=W(t,n);if(0==i)o=!1;else{const o=W(t,n),a=ne(e,t,n,o,q(e,n));void 0===a?console.warn(`THREE.EXRLoader: Skipped unknown header attribute type '${o}'.`):r[i]=a}}if(-5&i)throw console.error("THREE.EXRHeader:",r),new Error("THREE.EXRLoader: Provided file is currently unsupported.");return r}(re,e,oe),se=function(e,t,c,l,u){const h={size:0,viewer:t,array:c,offset:l,width:e.dataWindow.xMax-e.dataWindow.xMin+1,height:e.dataWindow.yMax-e.dataWindow.yMin+1,channels:e.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:e.channels[0].pixelType,uncompress:null,getter:null,format:null,colorSpace:o};switch(e.compression){case"NO_COMPRESSION":h.lines=1,h.uncompress=U;break;case"RLE_COMPRESSION":h.lines=1,h.uncompress=B;break;case"ZIPS_COMPRESSION":h.lines=1,h.uncompress=z;break;case"ZIP_COMPRESSION":h.lines=16,h.uncompress=z;break;case"PIZ_COMPRESSION":h.lines=32,h.uncompress=H;break;case"PXR24_COMPRESSION":h.lines=16,h.uncompress=V;break;case"DWAA_COMPRESSION":h.lines=32,h.uncompress=G;break;case"DWAB_COMPRESSION":h.lines=256,h.uncompress=G;break;default:throw new Error("EXRLoader.parse: "+e.compression+" is unsupported")}if(h.scanlineBlockSize=h.lines,1==h.type)switch(u){case r:h.getter=te,h.inputSize=2;break;case n:h.getter=ee,h.inputSize=2}else{if(2!=h.type)throw new Error("EXRLoader.parse: unsupported pixelType "+h.type+" for "+e.compression+".");switch(u){case r:h.getter=Z,h.inputSize=4;break;case n:h.getter=$,h.inputSize=4}}h.blockCount=(e.dataWindow.yMax+1)/h.scanlineBlockSize;for(let e=0;e<h.blockCount;e++)Q(t,l);h.outputChannels=3==h.channels?4:h.channels;const d=h.width*h.height*h.outputChannels;switch(u){case r:h.byteArray=new Float32Array(d),h.channels<h.outputChannels&&h.byteArray.fill(1,0,d);break;case n:h.byteArray=new Uint16Array(d),h.channels<h.outputChannels&&h.byteArray.fill(15360,0,d);break;default:console.error("THREE.EXRLoader: unsupported type: ",u)}return h.bytesPerLine=h.width*h.inputSize*h.channels,4==h.outputChannels?(h.format=i,h.colorSpace=o):(h.format=a,h.colorSpace=s),h}(ae,re,ie,oe,this.type),ce={value:0},le={R:0,G:1,B:2,A:3,Y:0};for(let e=0;e<se.height/se.scanlineBlockSize;e++){const t=q(re,oe);se.size=q(re,oe),se.lines=t+se.scanlineBlockSize>se.height?se.height-t:se.scanlineBlockSize;const n=se.size<se.lines*se.bytesPerLine?se.uncompress(se):U(se);oe.value+=se.size;for(let t=0;t<se.scanlineBlockSize;t++){const r=t+e*se.scanlineBlockSize;if(r>=se.height)break;for(let e=0;e<se.channels;e++){const i=le[ae.channels[e].name];for(let o=0;o<se.width;o++){ce.value=(t*(se.channels*se.width)+e*se.width+o)*se.inputSize;const a=(se.height-1-r)*(se.width*se.outputChannels)+o*se.outputChannels+i;se.byteArray[a]=se.getter(n,ce)}}}}return{header:ae,width:se.width,height:se.height,data:se.byteArray,format:se.format,colorSpace:se.colorSpace,type:this.type}}setDataType(e){return this.type=e,this}load(e,t,n,r){return super.load(e,function(e,n){e.colorSpace=n.colorSpace,e.minFilter=c,e.magFilter=c,e.generateMipmaps=!1,e.flipY=!1,t&&t(e,n)},n,r)}};const jt={type:"change"},Ft={type:"start"},Ut={type:"end"},Bt=new u,zt=new h,Ht=Math.cos(70*d.DEG2RAD);class Vt extends p{constructor(e,t){super(),this.object=e,this.domElement=t,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new f,this.cursor=new f,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=4,this.ctrlZoomSpeed=.05,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:-1,MIDDLE:m.ROTATE,RIGHT:m.PAN},this.touches={ONE:g.ROTATE,TWO:g.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.VIEW_TYPES={FRONT:"front",BACK:"back",LEFT:"left",RIGHT:"right",TOP:"top",BOTTOM:"bottom",ISOMETRIC:"isometric",FREE:"free"},this.viewDragStart=null,this.viewChangeRequested=!1,this.viewsInitialized=!1,this.horizontalViews=[],this.verticalViews=[],this.horizontalViewIndex=0,this.verticalViewIndex=0,this.originalCameraPosition=null,this.originalTarget=null,this.getPolarAngle=function(){return a.phi},this.getAzimuthalAngle=function(){return a.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(e){e.addEventListener("keydown",ne),this._domElementKeyEvents=e},this.stopListenToKeyEvents=function(){this._domElementKeyEvents.removeEventListener("keydown",ne),this._domElementKeyEvents=null},this.saveState=function(){n.target0.copy(n.target),n.position0.copy(n.object.position),n.zoom0=n.object.zoom},this.reset=function(){n.target.copy(n.target0),n.object.position.copy(n.position0),n.object.zoom=n.zoom0,n.object.updateProjectionMatrix(),n.dispatchEvent(jt),n.update(),i=r.NONE},this.setView=function(e){this.originalCameraPosition||(this.originalCameraPosition=this.object.position.clone(),this.originalTarget=this.target.clone());const t=this.target.clone(),n=this.getDistance();switch(e){case this.VIEW_TYPES.FRONT:this.object.position.set(t.x,t.y-n,t.z);break;case this.VIEW_TYPES.BACK:this.object.position.set(t.x,t.y+n,t.z);break;case this.VIEW_TYPES.RIGHT:this.object.position.set(t.x+n,t.y,t.z);break;case this.VIEW_TYPES.LEFT:this.object.position.set(t.x-n,t.y,t.z);break;case this.VIEW_TYPES.TOP:this.object.position.set(t.x,t.y,t.z+n);break;case this.VIEW_TYPES.BOTTOM:this.object.position.set(t.x,t.y,t.z-n);break;case this.VIEW_TYPES.ISOMETRIC:const e=n/Math.sqrt(3);this.object.position.set(t.x+e,t.y-e,t.z+e);break;case this.VIEW_TYPES.FREE:default:return void this.resetView()}this.object.lookAt(this.target),this.update(),this.dispatchEvent(jt)},this.resetView=function(){this.originalCameraPosition&&this.originalTarget&&(this.object.position.copy(this.originalCameraPosition),this.target.copy(this.originalTarget),this.object.lookAt(this.target),this.update(),this.dispatchEvent(jt))},this.update=function(){const t=new f,u=(new y).setFromUnitVectors(e.up,new f(0,1,0)),h=u.clone().invert(),d=new f,p=new y,m=new f,g=2*Math.PI;return function(b=null){const y=n.object.position;t.copy(y).sub(n.target),t.applyQuaternion(u),a.setFromVector3(t),n.autoRotate&&i===r.NONE&&P(function(e){return null!==e?2*Math.PI/60*n.autoRotateSpeed*e:2*Math.PI/60/60*n.autoRotateSpeed}(b)),n.enableDamping?(a.theta+=s.theta*n.dampingFactor,a.phi+=s.phi*n.dampingFactor):(a.theta+=s.theta,a.phi+=s.phi);let v=n.minAzimuthAngle,x=n.maxAzimuthAngle;isFinite(v)&&isFinite(x)&&(v<-Math.PI?v+=g:v>Math.PI&&(v-=g),x<-Math.PI?x+=g:x>Math.PI&&(x-=g),a.theta=v<=x?Math.max(v,Math.min(x,a.theta)):a.theta>(v+x)/2?Math.max(v,a.theta):Math.min(x,a.theta)),a.phi=Math.max(n.minPolarAngle,Math.min(n.maxPolarAngle,a.phi)),a.makeSafe(),!0===n.enableDamping?n.target.addScaledVector(l,n.dampingFactor):n.target.add(l),n.target.sub(n.cursor),n.target.clampLength(n.minTargetRadius,n.maxTargetRadius),n.target.add(n.cursor);let w=!1;if(n.zoomToCursor&&k||n.object.isOrthographicCamera)a.radius=B(a.radius);else{const e=a.radius;a.radius=B(a.radius*c),w=e!=a.radius}if(t.setFromSpherical(a),t.applyQuaternion(h),y.copy(n.target).add(t),n.object.lookAt(n.target),!0===n.enableDamping?(s.theta*=1-n.dampingFactor,s.phi*=1-n.dampingFactor,l.multiplyScalar(1-n.dampingFactor)):(s.set(0,0,0),l.set(0,0,0)),n.zoomToCursor&&k){let r=null;if(n.object.isPerspectiveCamera){const e=t.length();r=B(e*c);const i=e-r;n.object.position.addScaledVector(C,i),n.object.updateMatrixWorld(),w=!!i}else if(n.object.isOrthographicCamera){const e=new f(O.x,O.y,0);e.unproject(n.object);const i=n.object.zoom;n.object.zoom=Math.max(n.minZoom,Math.min(n.maxZoom,n.object.zoom/c)),n.object.updateProjectionMatrix(),w=i!==n.object.zoom;const o=new f(O.x,O.y,0);o.unproject(n.object),n.object.position.sub(o).add(e),n.object.updateMatrixWorld(),r=t.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),n.zoomToCursor=!1;null!==r&&(this.screenSpacePanning?n.target.set(0,0,-1).transformDirection(n.object.matrix).multiplyScalar(r).add(n.object.position):(Bt.origin.copy(n.object.position),Bt.direction.set(0,0,-1).transformDirection(n.object.matrix),Math.abs(n.object.up.dot(Bt.direction))<Ht?e.lookAt(n.target):(zt.setFromNormalAndCoplanarPoint(n.object.up,n.target),Bt.intersectPlane(zt,n.target))))}else if(n.object.isOrthographicCamera){const e=n.object.zoom;n.object.zoom=Math.max(n.minZoom,Math.min(n.maxZoom,n.object.zoom/c)),e!==n.object.zoom&&(n.object.updateProjectionMatrix(),w=!0)}return c=1,k=!1,!!(w||d.distanceToSquared(n.object.position)>o||8*(1-p.dot(n.object.quaternion))>o||m.distanceToSquared(n.target)>o)&&(n.dispatchEvent(jt),d.copy(n.object.position),p.copy(n.object.quaternion),m.copy(n.target),!0)}}(),this.dispose=function(){n.domElement.removeEventListener("contextmenu",ie),n.domElement.removeEventListener("pointerdown",Q),n.domElement.removeEventListener("pointercancel",$),n.domElement.removeEventListener("wheel",J),n.domElement.removeEventListener("pointermove",Z),n.domElement.removeEventListener("pointerup",$);n.domElement.getRootNode().removeEventListener("keydown",ee,{capture:!0}),null!==n._domElementKeyEvents&&(n._domElementKeyEvents.removeEventListener("keydown",ne),n._domElementKeyEvents=null)};const n=this,r={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let i=r.NONE;const o=1e-6,a=new b,s=new b;let c=1;const l=new f,u=new v,h=new v,d=new v,p=new v,x=new v,w=new v,E=new v,T=new v,A=new v,C=new f,O=new v;let k=!1;const S=[],R={};let M=!1;function I(e){const t=Math.abs(.01*e);return Math.pow(.95,n.zoomSpeed*t)}function P(e){s.theta-=e}function _(e){s.phi-=e}const N=function(){const e=new f;return function(t,n){e.setFromMatrixColumn(n,0),e.multiplyScalar(-t),l.add(e)}}(),L=function(){const e=new f;return function(t,r){!0===n.screenSpacePanning?e.setFromMatrixColumn(r,1):(e.setFromMatrixColumn(r,0),e.crossVectors(n.object.up,e)),e.multiplyScalar(t),l.add(e)}}(),D=function(){const e=new f;return function(t,r){const i=n.domElement;if(n.object.isPerspectiveCamera){const o=n.object.position;e.copy(o).sub(n.target);let a=e.length();a*=Math.tan(n.object.fov/2*Math.PI/180),N(2*t*a/i.clientHeight,n.object.matrix),L(2*r*a/i.clientHeight,n.object.matrix)}else n.object.isOrthographicCamera?(N(t*(n.object.right-n.object.left)/n.object.zoom/i.clientWidth,n.object.matrix),L(r*(n.object.top-n.object.bottom)/n.object.zoom/i.clientHeight,n.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),n.enablePan=!1)}}();function j(e){n.object.isPerspectiveCamera||n.object.isOrthographicCamera?c/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),n.enableZoom=!1)}function F(e){n.object.isPerspectiveCamera||n.object.isOrthographicCamera?c*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),n.enableZoom=!1)}function U(e,t){if(!n.zoomToCursor)return;k=!0;const r=n.domElement.getBoundingClientRect(),i=e-r.left,o=t-r.top,a=r.width,s=r.height;O.x=i/a*2-1,O.y=-o/s*2+1,C.set(O.x,O.y,1).unproject(n.object).sub(n.object.position).normalize()}function B(e){return Math.max(n.minDistance,Math.min(n.maxDistance,e))}function z(e){n.viewsInitialized||(n.horizontalViews=[n.VIEW_TYPES.LEFT,n.VIEW_TYPES.FRONT,n.VIEW_TYPES.RIGHT,n.VIEW_TYPES.BACK],n.verticalViews=[n.VIEW_TYPES.TOP,n.VIEW_TYPES.ISOMETRIC,n.VIEW_TYPES.BOTTOM,n.VIEW_TYPES.FREE],n.horizontalViewIndex=0,n.verticalViewIndex=0,n.viewsInitialized=!0),n.viewDragStart=new v(e.clientX,e.clientY),n.viewChangeRequested=!0,e.preventDefault(),e.stopPropagation()}function H(e){u.set(e.clientX,e.clientY)}function V(e){p.set(e.clientX,e.clientY)}function G(e){if(1===S.length)u.set(e.pageX,e.pageY);else{const t=ae(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);u.set(n,r)}}function W(e){if(1===S.length)p.set(e.pageX,e.pageY);else{const t=ae(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);p.set(n,r)}}function X(e){const t=ae(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);E.set(0,i)}function q(e){if(1==S.length)h.set(e.pageX,e.pageY);else{const t=ae(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);h.set(n,r)}d.subVectors(h,u).multiplyScalar(n.rotateSpeed);const t=n.domElement;P(2*Math.PI*d.x/t.clientHeight),_(2*Math.PI*d.y/t.clientHeight),u.copy(h)}function Y(e){if(1===S.length)x.set(e.pageX,e.pageY);else{const t=ae(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);x.set(n,r)}w.subVectors(x,p).multiplyScalar(n.panSpeed),D(w.x,w.y),p.copy(x)}function K(e){const t=ae(e),r=e.pageX-t.x,i=e.pageY-t.y,o=Math.sqrt(r*r+i*i);T.set(0,o),A.set(0,Math.pow(T.y/E.y,n.zoomSpeed)),j(A.y),E.copy(T);U(.5*(e.pageX+t.x),.5*(e.pageY+t.y))}function Q(e){!1!==n.enabled&&(0===S.length&&(n.domElement.setPointerCapture(e.pointerId),n.domElement.addEventListener("pointermove",Z),n.domElement.addEventListener("pointerup",$)),e.altKey&&1===e.button?z(e):function(e){for(let t=0;t<S.length;t++)if(S[t]==e.pointerId)return!0;return!1}(e)||(function(e){S.push(e.pointerId)}(e),"touch"===e.pointerType?re(e):function(e){let t;switch(e.button){case 0:t=n.mouseButtons.LEFT;break;case 1:t=e.altKey?-1:e.ctrlKey||e.metaKey?m.DOLLY:n.mouseButtons.MIDDLE;break;case 2:t=n.mouseButtons.RIGHT;break;default:t=-1}switch(t){case m.DOLLY:if(!1===n.enableZoom)return;!function(e){U(e.clientX,e.clientX),E.set(e.clientX,e.clientY)}(e),i=r.DOLLY;break;case m.ROTATE:if(e.ctrlKey||e.metaKey||e.shiftKey){if(!1===n.enablePan)return;V(e),i=r.PAN}else{if(!1===n.enableRotate)return;H(e),i=r.ROTATE}break;case m.PAN:if(e.ctrlKey||e.metaKey||e.shiftKey){if(!1===n.enableRotate)return;H(e),i=r.ROTATE}else{if(!1===n.enablePan)return;V(e),i=r.PAN}break;default:i=r.NONE}i!==r.NONE&&n.dispatchEvent(Ft)}(e)))}function Z(e){!1!==n.enabled&&(e.altKey&&n.viewChangeRequested&&n.viewDragStart?function(e){const t=new v(e.clientX,e.clientY),r=(new v).subVectors(t,n.viewDragStart),i=Math.abs(r.x),o=Math.abs(r.y);if(Math.max(i,o)>30){if(i>o){const e=r.x>0?1:-1;n.horizontalViewIndex=(n.horizontalViewIndex+e+n.horizontalViews.length)%n.horizontalViews.length,n.setView(n.horizontalViews[n.horizontalViewIndex])}else{const e=r.y>0?1:-1;n.verticalViewIndex=(n.verticalViewIndex+e+n.verticalViews.length)%n.verticalViews.length,n.setView(n.verticalViews[n.verticalViewIndex])}n.viewChangeRequested=!1,n.viewDragStart=null}e.altKey&&4===e.buttons&&(e.preventDefault(),e.stopPropagation())}(e):"touch"===e.pointerType?function(e){switch(oe(e),i){case r.TOUCH_ROTATE:if(!1===n.enableRotate)return;q(e),n.update();break;case r.TOUCH_PAN:if(!1===n.enablePan)return;Y(e),n.update();break;case r.TOUCH_DOLLY_PAN:if(!1===n.enableZoom&&!1===n.enablePan)return;!function(e){n.enableZoom&&K(e),n.enablePan&&Y(e)}(e),n.update();break;case r.TOUCH_DOLLY_ROTATE:if(!1===n.enableZoom&&!1===n.enableRotate)return;!function(e){n.enableZoom&&K(e),n.enableRotate&&q(e)}(e),n.update();break;default:i=r.NONE}}(e):function(e){switch(i){case r.ROTATE:if(!1===n.enableRotate)return;!function(e){h.set(e.clientX,e.clientY),d.subVectors(h,u).multiplyScalar(n.rotateSpeed);const t=n.domElement;P(2*Math.PI*d.x/t.clientHeight),_(2*Math.PI*d.y/t.clientHeight),u.copy(h),n.update()}(e);break;case r.DOLLY:if(!1===n.enableZoom)return;!function(e){T.set(e.clientX,e.clientY),A.subVectors(T,E),A.y>0?j(I(A.y)-n.ctrlZoomSpeed):A.y<0&&F(I(A.y)-n.ctrlZoomSpeed),E.copy(T),n.update()}(e);break;case r.PAN:if(!1===n.enablePan)return;!function(e){x.set(e.clientX,e.clientY),w.subVectors(x,p).multiplyScalar(n.panSpeed),D(w.x,w.y),p.copy(x),n.update()}(e)}}(e))}function $(e){switch(n.viewChangeRequested&&(n.viewChangeRequested=!1,n.viewDragStart=null),function(e){delete R[e.pointerId];for(let t=0;t<S.length;t++)if(S[t]==e.pointerId)return void S.splice(t,1)}(e),S.length){case 0:n.domElement.releasePointerCapture(e.pointerId),n.domElement.removeEventListener("pointermove",Z),n.domElement.removeEventListener("pointerup",$),n.dispatchEvent(Ut),i=r.NONE;break;case 1:const t=S[0],o=R[t];re({pointerId:t,pageX:o.x,pageY:o.y})}}function J(e){!1!==n.enabled&&!1!==n.enableZoom&&i===r.NONE&&(e.preventDefault(),n.dispatchEvent(Ft),function(e){U(e.clientX,e.clientY),e.deltaY<0?F(I(e.deltaY)):e.deltaY>0&&j(I(e.deltaY)),n.update()}(function(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100}e.ctrlKey&&!M&&(n.deltaY*=10);return n}(e)),n.dispatchEvent(Ut))}function ee(e){if("Control"===e.key){M=!0;n.domElement.getRootNode().addEventListener("keyup",te,{passive:!0,capture:!0})}}function te(e){if("Control"===e.key){M=!1;n.domElement.getRootNode().removeEventListener("keyup",te,{passive:!0,capture:!0})}}function ne(e){!1!==n.enabled&&!1!==n.enablePan&&function(e){let t=!1;switch(e.code){case n.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?_(2*Math.PI*n.rotateSpeed/n.domElement.clientHeight):D(0,n.keyPanSpeed),t=!0;break;case n.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?_(-2*Math.PI*n.rotateSpeed/n.domElement.clientHeight):D(0,-n.keyPanSpeed),t=!0;break;case n.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?P(2*Math.PI*n.rotateSpeed/n.domElement.clientHeight):D(n.keyPanSpeed,0),t=!0;break;case n.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?P(-2*Math.PI*n.rotateSpeed/n.domElement.clientHeight):D(-n.keyPanSpeed,0),t=!0}t&&(e.preventDefault(),n.update())}(e)}function re(e){switch(oe(e),S.length){case 1:switch(n.touches.ONE){case g.ROTATE:if(!1===n.enableRotate)return;G(e),i=r.TOUCH_ROTATE;break;case g.PAN:if(!1===n.enablePan)return;W(e),i=r.TOUCH_PAN;break;default:i=r.NONE}break;case 2:switch(n.touches.TWO){case g.DOLLY_PAN:if(!1===n.enableZoom&&!1===n.enablePan)return;!function(e){n.enableZoom&&X(e),n.enablePan&&W(e)}(e),i=r.TOUCH_DOLLY_PAN;break;case g.DOLLY_ROTATE:if(!1===n.enableZoom&&!1===n.enableRotate)return;!function(e){n.enableZoom&&X(e),n.enableRotate&&G(e)}(e),i=r.TOUCH_DOLLY_ROTATE;break;default:i=r.NONE}break;default:i=r.NONE}i!==r.NONE&&n.dispatchEvent(Ft)}function ie(e){!1!==n.enabled&&e.preventDefault()}function oe(e){let t=R[e.pointerId];void 0===t&&(t=new v,R[e.pointerId]=t),t.set(e.pageX,e.pageY)}function ae(e){const t=e.pointerId===S[0]?S[1]:S[0];return R[t]}n.domElement.addEventListener("contextmenu",ie),n.domElement.addEventListener("pointerdown",Q),n.domElement.addEventListener("pointercancel",$),n.domElement.addEventListener("wheel",J,{passive:!1});n.domElement.getRootNode().addEventListener("keydown",ee,{passive:!0,capture:!0}),this.update()}}const Gt=new w,Wt=new f,Xt=new f,qt=new y,Yt={X:new f(1,0,0),Y:new f(0,1,0),Z:new f(0,0,1)},Kt={type:"change"},Qt={type:"mouseDown"},Zt={type:"mouseUp",mode:null},$t={type:"objectChange"};class Jt extends x{constructor(e,t){super(),void 0===t&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),t=document),this.isTransformControls=!0,this.visible=!1,this.domElement=t,this.domElement.style.touchAction="none";const n=new wn;this._gizmo=n,this.add(n);const r=new En;this._plane=r,this.add(r);const i=this;function o(e,t){let o=t;Object.defineProperty(i,e,{get:function(){return void 0!==o?o:t},set:function(t){o!==t&&(o=t,r[e]=t,n[e]=t,i.dispatchEvent({type:e+"-changed",value:t}),i.dispatchEvent(Kt))}}),i[e]=t,r[e]=t,n[e]=t}o("camera",e),o("object",void 0),o("enabled",!0),o("axis",null),o("mode","translate"),o("translationSnap",null),o("rotationSnap",null),o("scaleSnap",null),o("space","world"),o("size",1),o("dragging",!1),o("showX",!0),o("showY",!0),o("showZ",!0);const a=new f,s=new f,c=new y,l=new y,u=new f,h=new y,d=new f,p=new f,m=new f,g=new f;o("worldPosition",a),o("worldPositionStart",s),o("worldQuaternion",c),o("worldQuaternionStart",l),o("cameraPosition",u),o("cameraQuaternion",h),o("pointStart",d),o("pointEnd",p),o("rotationAxis",m),o("rotationAngle",0),o("eye",g),this._offset=new f,this._startNorm=new f,this._endNorm=new f,this._cameraScale=new f,this._parentPosition=new f,this._parentQuaternion=new y,this._parentQuaternionInv=new y,this._parentScale=new f,this._worldScaleStart=new f,this._worldQuaternionInv=new y,this._worldScale=new f,this._positionStart=new f,this._quaternionStart=new y,this._scaleStart=new f,this._getPointer=en.bind(this),this._onPointerDown=nn.bind(this),this._onPointerHover=tn.bind(this),this._onPointerMove=rn.bind(this),this._onPointerUp=on.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){void 0!==this.object&&(this.object.updateMatrixWorld(),null===this.object.parent?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(e){if(void 0===this.object||!0===this.dragging)return;null!==e&&Gt.setFromCamera(e,this.camera);const t=an(this._gizmo.picker[this.mode],Gt);this.axis=t?t.object.name:null}pointerDown(e){if(void 0!==this.object&&!0!==this.dragging&&(null==e||0===e.button)&&null!==this.axis){null!==e&&Gt.setFromCamera(e,this.camera);const t=an(this._plane,Gt,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,Qt.mode=this.mode,this.dispatchEvent(Qt)}}pointerMove(e){const t=this.axis,n=this.mode,r=this.object;let i=this.space;if("scale"===n?i="local":"E"!==t&&"XYZE"!==t&&"XYZ"!==t||(i="world"),void 0===r||null===t||!1===this.dragging||null!==e&&-1!==e.button)return;null!==e&&Gt.setFromCamera(e,this.camera);const o=an(this._plane,Gt,!0);if(o){if(this.pointEnd.copy(o.point).sub(this.worldPositionStart),"translate"===n)this._offset.copy(this.pointEnd).sub(this.pointStart),"local"===i&&"XYZ"!==t&&this._offset.applyQuaternion(this._worldQuaternionInv),-1===t.indexOf("X")&&(this._offset.x=0),-1===t.indexOf("Y")&&(this._offset.y=0),-1===t.indexOf("Z")&&(this._offset.z=0),"local"===i&&"XYZ"!==t?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),r.position.copy(this._offset).add(this._positionStart),this.translationSnap&&("local"===i&&(r.position.applyQuaternion(qt.copy(this._quaternionStart).invert()),-1!==t.search("X")&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),-1!==t.search("Y")&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),-1!==t.search("Z")&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.position.applyQuaternion(this._quaternionStart)),"world"===i&&(r.parent&&r.position.add(Wt.setFromMatrixPosition(r.parent.matrixWorld)),-1!==t.search("X")&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),-1!==t.search("Y")&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),-1!==t.search("Z")&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.parent&&r.position.sub(Wt.setFromMatrixPosition(r.parent.matrixWorld))));else if("scale"===n){if(-1!==t.search("XYZ")){let e=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(e*=-1),Xt.set(e,e,e)}else Wt.copy(this.pointStart),Xt.copy(this.pointEnd),Wt.applyQuaternion(this._worldQuaternionInv),Xt.applyQuaternion(this._worldQuaternionInv),Xt.divide(Wt),-1===t.search("X")&&(Xt.x=1),-1===t.search("Y")&&(Xt.y=1),-1===t.search("Z")&&(Xt.z=1);r.scale.copy(this._scaleStart).multiply(Xt),this.scaleSnap&&(-1!==t.search("X")&&(r.scale.x=Math.round(r.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==t.search("Y")&&(r.scale.y=Math.round(r.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==t.search("Z")&&(r.scale.z=Math.round(r.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if("rotate"===n){this._offset.copy(this.pointEnd).sub(this.pointStart);const e=20/this.worldPosition.distanceTo(Wt.setFromMatrixPosition(this.camera.matrixWorld));let n=!1;"XYZE"===t?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(Wt.copy(this.rotationAxis).cross(this.eye))*e):"X"!==t&&"Y"!==t&&"Z"!==t||(this.rotationAxis.copy(Yt[t]),Wt.copy(Yt[t]),"local"===i&&Wt.applyQuaternion(this.worldQuaternion),Wt.cross(this.eye),0===Wt.length()?n=!0:this.rotationAngle=this._offset.dot(Wt.normalize())*e),("E"===t||n)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),"local"===i&&"E"!==t&&"XYZE"!==t?(r.quaternion.copy(this._quaternionStart),r.quaternion.multiply(qt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),r.quaternion.copy(qt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),r.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(Kt),this.dispatchEvent($t)}}pointerUp(e){null!==e&&0!==e.button||(this.dragging&&null!==this.axis&&(Zt.mode=this.mode,this.dispatchEvent(Zt)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}attach(e){return this.object=e,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(Kt),this.dispatchEvent($t),this.pointStart.copy(this.pointEnd))}getRaycaster(){return Gt}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}}function en(e){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:e.button};{const t=this.domElement.getBoundingClientRect();return{x:(e.clientX-t.left)/t.width*2-1,y:-(e.clientY-t.top)/t.height*2+1,button:e.button}}}function tn(e){if(this.enabled)switch(e.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(e))}}function nn(e){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(e.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(e)),this.pointerDown(this._getPointer(e)))}function rn(e){this.enabled&&this.pointerMove(this._getPointer(e))}function on(e){this.enabled&&(this.domElement.releasePointerCapture(e.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(e)))}function an(e,t,n){const r=t.intersectObject(e,!0);for(let e=0;e<r.length;e++)if(r[e].object.visible||n)return r[e];return!1}const sn=new _,cn=new f(0,1,0),ln=new f(0,0,0),un=new N,hn=new y,dn=new y,pn=new f,fn=new N,mn=new f(1,0,0),gn=new f(0,1,0),bn=new f(0,0,1),yn=new f,vn=new f,xn=new f;class wn extends x{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const e=new E({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new T({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),n=e.clone();n.opacity=.15;const r=t.clone();r.opacity=.5;const i=e.clone();i.color.setHex(16711680);const o=e.clone();o.color.setHex(65280);const a=e.clone();a.color.setHex(255);const s=e.clone();s.color.setHex(16711680),s.opacity=.5;const c=e.clone();c.color.setHex(65280),c.opacity=.5;const l=e.clone();l.color.setHex(255),l.opacity=.5;const u=e.clone();u.opacity=.25;const h=e.clone();h.color.setHex(16776960),h.opacity=.25;e.clone().color.setHex(16776960);const d=e.clone();d.color.setHex(7895160);const p=new A(0,.04,.1,12);p.translate(0,.05,0);const f=new C(.08,.08,.08);f.translate(0,.04,0);const m=new O;m.setAttribute("position",new k([0,0,0,1,0,0],3));const g=new A(.0075,.0075,.5,3);function b(e,t){const n=new I(e,.0075,3,64,t*Math.PI*2);return n.rotateY(Math.PI/2),n.rotateX(Math.PI/2),n}g.translate(0,.25,0);const y={X:[[new S(p,i),[.5,0,0],[0,0,-Math.PI/2]],[new S(p,i),[-.5,0,0],[0,0,Math.PI/2]],[new S(g,i),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new S(p,o),[0,.5,0]],[new S(p,o),[0,-.5,0],[Math.PI,0,0]],[new S(g,o)]],Z:[[new S(p,a),[0,0,.5],[Math.PI/2,0,0]],[new S(p,a),[0,0,-.5],[-Math.PI/2,0,0]],[new S(g,a),null,[Math.PI/2,0,0]]],XYZ:[[new S(new R(.1,0),u.clone()),[0,0,0]]],XY:[[new S(new C(.15,.15,.01),l.clone()),[.15,.15,0]]],YZ:[[new S(new C(.15,.15,.01),s.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new S(new C(.15,.15,.01),c.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},v={X:[[new S(new A(.2,0,.6,4),n),[.3,0,0],[0,0,-Math.PI/2]],[new S(new A(.2,0,.6,4),n),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new S(new A(.2,0,.6,4),n),[0,.3,0]],[new S(new A(.2,0,.6,4),n),[0,-.3,0],[0,0,Math.PI]]],Z:[[new S(new A(.2,0,.6,4),n),[0,0,.3],[Math.PI/2,0,0]],[new S(new A(.2,0,.6,4),n),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new S(new R(.2,0),n)]],XY:[[new S(new C(.2,.2,.01),n),[.15,.15,0]]],YZ:[[new S(new C(.2,.2,.01),n),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new S(new C(.2,.2,.01),n),[.15,0,.15],[-Math.PI/2,0,0]]]},w={START:[[new S(new R(.01,2),r),null,null,null,"helper"]],END:[[new S(new R(.01,2),r),null,null,null,"helper"]],DELTA:[[new M(function(){const e=new O;return e.setAttribute("position",new k([0,0,0,1,1,1],3)),e}(),r),null,null,null,"helper"]],X:[[new M(m,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new M(m,r.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new M(m,r.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},_={XYZE:[[new S(b(.5,1),d),null,[0,Math.PI/2,0]]],X:[[new S(b(.5,.5),i)]],Y:[[new S(b(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new S(b(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new S(b(.75,1),h),null,[0,Math.PI/2,0]]]},N={AXIS:[[new M(m,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},L={XYZE:[[new S(new P(.25,10,8),n)]],X:[[new S(new I(.5,.1,4,24),n),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new S(new I(.5,.1,4,24),n),[0,0,0],[Math.PI/2,0,0]]],Z:[[new S(new I(.5,.1,4,24),n),[0,0,0],[0,0,-Math.PI/2]]],E:[[new S(new I(.75,.1,2,24),n)]]},D={X:[[new S(f,i),[.5,0,0],[0,0,-Math.PI/2]],[new S(g,i),[0,0,0],[0,0,-Math.PI/2]],[new S(f,i),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new S(f,o),[0,.5,0]],[new S(g,o)],[new S(f,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new S(f,a),[0,0,.5],[Math.PI/2,0,0]],[new S(g,a),[0,0,0],[Math.PI/2,0,0]],[new S(f,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new S(new C(.15,.15,.01),l),[.15,.15,0]]],YZ:[[new S(new C(.15,.15,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new S(new C(.15,.15,.01),c),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new S(new C(.1,.1,.1),u.clone())]]},j={X:[[new S(new A(.2,0,.6,4),n),[.3,0,0],[0,0,-Math.PI/2]],[new S(new A(.2,0,.6,4),n),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new S(new A(.2,0,.6,4),n),[0,.3,0]],[new S(new A(.2,0,.6,4),n),[0,-.3,0],[0,0,Math.PI]]],Z:[[new S(new A(.2,0,.6,4),n),[0,0,.3],[Math.PI/2,0,0]],[new S(new A(.2,0,.6,4),n),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new S(new C(.2,.2,.01),n),[.15,.15,0]]],YZ:[[new S(new C(.2,.2,.01),n),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new S(new C(.2,.2,.01),n),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new S(new C(.2,.2,.2),n),[0,0,0]]]},F={X:[[new M(m,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new M(m,r.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new M(m,r.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function U(e){const t=new x;for(const n in e)for(let r=e[n].length;r--;){const i=e[n][r][0].clone(),o=e[n][r][1],a=e[n][r][2],s=e[n][r][3],c=e[n][r][4];i.name=n,i.tag=c,o&&i.position.set(o[0],o[1],o[2]),a&&i.rotation.set(a[0],a[1],a[2]),s&&i.scale.set(s[0],s[1],s[2]),i.updateMatrix();const l=i.geometry.clone();l.applyMatrix4(i.matrix),i.geometry=l,i.renderOrder=1/0,i.position.set(0,0,0),i.rotation.set(0,0,0),i.scale.set(1,1,1),t.add(i)}return t}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=U(y)),this.add(this.gizmo.rotate=U(_)),this.add(this.gizmo.scale=U(D)),this.add(this.picker.translate=U(v)),this.add(this.picker.rotate=U(L)),this.add(this.picker.scale=U(j)),this.add(this.helper.translate=U(w)),this.add(this.helper.rotate=U(N)),this.add(this.helper.scale=U(F)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){const t="local"===("scale"===this.mode?"local":this.space)?this.worldQuaternion:dn;this.gizmo.translate.visible="translate"===this.mode,this.gizmo.rotate.visible="rotate"===this.mode,this.gizmo.scale.visible="scale"===this.mode,this.helper.translate.visible="translate"===this.mode,this.helper.rotate.visible="rotate"===this.mode,this.helper.scale.visible="scale"===this.mode;let n=[];n=n.concat(this.picker[this.mode].children),n=n.concat(this.gizmo[this.mode].children),n=n.concat(this.helper[this.mode].children);for(let e=0;e<n.length;e++){const r=n[e];let i;if(r.visible=!0,r.rotation.set(0,0,0),r.position.copy(this.worldPosition),i=this.camera.isOrthographicCamera?(this.camera.top-this.camera.bottom)/this.camera.zoom:this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),r.scale.set(1,1,1).multiplyScalar(i*this.size/4),"helper"!==r.tag){if(r.quaternion.copy(t),"translate"===this.mode||"scale"===this.mode){const e=.99,n=.2;"X"===r.name&&Math.abs(cn.copy(mn).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"Y"===r.name&&Math.abs(cn.copy(gn).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"Z"===r.name&&Math.abs(cn.copy(bn).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"XY"===r.name&&Math.abs(cn.copy(bn).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"YZ"===r.name&&Math.abs(cn.copy(mn).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"XZ"===r.name&&Math.abs(cn.copy(gn).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1)}else"rotate"===this.mode&&(hn.copy(t),cn.copy(this.eye).applyQuaternion(qt.copy(t).invert()),-1!==r.name.search("E")&&r.quaternion.setFromRotationMatrix(un.lookAt(this.eye,ln,gn)),"X"===r.name&&(qt.setFromAxisAngle(mn,Math.atan2(-cn.y,cn.z)),qt.multiplyQuaternions(hn,qt),r.quaternion.copy(qt)),"Y"===r.name&&(qt.setFromAxisAngle(gn,Math.atan2(cn.x,cn.z)),qt.multiplyQuaternions(hn,qt),r.quaternion.copy(qt)),"Z"===r.name&&(qt.setFromAxisAngle(bn,Math.atan2(cn.y,cn.x)),qt.multiplyQuaternions(hn,qt),r.quaternion.copy(qt)));r.visible=r.visible&&(-1===r.name.indexOf("X")||this.showX),r.visible=r.visible&&(-1===r.name.indexOf("Y")||this.showY),r.visible=r.visible&&(-1===r.name.indexOf("Z")||this.showZ),r.visible=r.visible&&(-1===r.name.indexOf("E")||this.showX&&this.showY&&this.showZ),r.material._color=r.material._color||r.material.color.clone(),r.material._opacity=r.material._opacity||r.material.opacity,r.material.color.copy(r.material._color),r.material.opacity=r.material._opacity,this.enabled&&this.axis&&(r.name===this.axis||this.axis.split("").some(function(e){return r.name===e}))&&(r.material.color.setHex(16776960),r.material.opacity=1)}else r.visible=!1,"AXIS"===r.name?(r.visible=!!this.axis,"X"===this.axis&&(qt.setFromEuler(sn.set(0,0,0)),r.quaternion.copy(t).multiply(qt),Math.abs(cn.copy(mn).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),"Y"===this.axis&&(qt.setFromEuler(sn.set(0,0,Math.PI/2)),r.quaternion.copy(t).multiply(qt),Math.abs(cn.copy(gn).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),"Z"===this.axis&&(qt.setFromEuler(sn.set(0,Math.PI/2,0)),r.quaternion.copy(t).multiply(qt),Math.abs(cn.copy(bn).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),"XYZE"===this.axis&&(qt.setFromEuler(sn.set(0,Math.PI/2,0)),cn.copy(this.rotationAxis),r.quaternion.setFromRotationMatrix(un.lookAt(ln,cn,gn)),r.quaternion.multiply(qt),r.visible=this.dragging),"E"===this.axis&&(r.visible=!1)):"START"===r.name?(r.position.copy(this.worldPositionStart),r.visible=this.dragging):"END"===r.name?(r.position.copy(this.worldPosition),r.visible=this.dragging):"DELTA"===r.name?(r.position.copy(this.worldPositionStart),r.quaternion.copy(this.worldQuaternionStart),Wt.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),Wt.applyQuaternion(this.worldQuaternionStart.clone().invert()),r.scale.copy(Wt),r.visible=this.dragging):(r.quaternion.copy(t),this.dragging?r.position.copy(this.worldPositionStart):r.position.copy(this.worldPosition),this.axis&&(r.visible=-1!==this.axis.search(r.name)))}super.updateMatrixWorld(e)}}class En extends S{constructor(){super(new L(1e5,1e5,2,2),new E({visible:!1,wireframe:!0,side:D,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),"scale"===this.mode&&(t="local"),yn.copy(mn).applyQuaternion("local"===t?this.worldQuaternion:dn),vn.copy(gn).applyQuaternion("local"===t?this.worldQuaternion:dn),xn.copy(bn).applyQuaternion("local"===t?this.worldQuaternion:dn),cn.copy(vn),this.mode){case"translate":case"scale":switch(this.axis){case"X":cn.copy(this.eye).cross(yn),pn.copy(yn).cross(cn);break;case"Y":cn.copy(this.eye).cross(vn),pn.copy(vn).cross(cn);break;case"Z":cn.copy(this.eye).cross(xn),pn.copy(xn).cross(cn);break;case"XY":pn.copy(xn);break;case"YZ":pn.copy(yn);break;case"XZ":cn.copy(xn),pn.copy(vn);break;case"XYZ":case"E":pn.set(0,0,0)}break;default:pn.set(0,0,0)}0===pn.length()?this.quaternion.copy(this.cameraQuaternion):(fn.lookAt(Wt.set(0,0,0),pn,cn),this.quaternion.setFromRotationMatrix(fn)),super.updateMatrixWorld(e)}}const Tn=1.25,An=65535,Cn=Math.pow(2,-24),On=Symbol("SKIP_GENERATION");function kn(e){return function(e){return e.index?e.index.count:e.attributes.position.count}(e)/3}function Sn(e,t){if(!e.index){const n=e.attributes.position.count,r=function(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new j(r,1));for(let e=0;e<n;e++)r[e]=e}}function Rn(e,t){const n=kn(e),r=t||e.drawRange,i=r.start/3,o=(r.start+r.count)/3,a=Math.max(0,i),s=Math.min(n,o)-a;return[{offset:Math.floor(a),count:Math.floor(s)}]}function Mn(e,t){if(!e.groups||!e.groups.length)return Rn(e,t);const n=[],r=new Set,i=t||e.drawRange,o=i.start/3,a=(i.start+i.count)/3;for(const t of e.groups){const e=t.start/3,n=(t.start+t.count)/3;r.add(Math.max(o,e)),r.add(Math.min(a,n))}const s=Array.from(r.values()).sort((e,t)=>e-t);for(let e=0;e<s.length-1;e++){const t=s[e],r=s[e+1];n.push({offset:Math.floor(t),count:Math.floor(r-t)})}return n}function In(e,t,n,r,i){let o=1/0,a=1/0,s=1/0,c=-1/0,l=-1/0,u=-1/0,h=1/0,d=1/0,p=1/0,f=-1/0,m=-1/0,g=-1/0;for(let r=6*t,i=6*(t+n);r<i;r+=6){const t=e[r+0],n=e[r+1],i=t-n,b=t+n;i<o&&(o=i),b>c&&(c=b),t<h&&(h=t),t>f&&(f=t);const y=e[r+2],v=e[r+3],x=y-v,w=y+v;x<a&&(a=x),w>l&&(l=w),y<d&&(d=y),y>m&&(m=y);const E=e[r+4],T=e[r+5],A=E-T,C=E+T;A<s&&(s=A),C>u&&(u=C),E<p&&(p=E),E>g&&(g=E)}r[0]=o,r[1]=a,r[2]=s,r[3]=c,r[4]=l,r[5]=u,i[0]=h,i[1]=d,i[2]=p,i[3]=f,i[4]=m,i[5]=g}function Pn(e,t,n){return n.min.x=t[e],n.min.y=t[e+1],n.min.z=t[e+2],n.max.x=t[e+3],n.max.y=t[e+4],n.max.z=t[e+5],n}function _n(e){let t=-1,n=-1/0;for(let r=0;r<3;r++){const i=e[r+3]-e[r];i>n&&(n=i,t=r)}return t}function Nn(e,t){t.set(e)}function Ln(e,t,n){let r,i;for(let o=0;o<3;o++){const a=o+3;r=e[o],i=t[o],n[o]=r<i?r:i,r=e[a],i=t[a],n[a]=r>i?r:i}}function Dn(e,t,n){for(let r=0;r<3;r++){const i=t[e+2*r],o=t[e+2*r+1],a=i-o,s=i+o;a<n[r]&&(n[r]=a),s>n[r+3]&&(n[r+3]=s)}}function jn(e){const t=e[3]-e[0],n=e[4]-e[1],r=e[5]-e[2];return 2*(t*n+n*r+r*t)}const Fn=32,Un=(e,t)=>e.candidate-t.candidate,Bn=new Array(Fn).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),zn=new Float32Array(6);class Hn{constructor(){this.boundingData=new Float32Array(6)}}function Vn(e,t,n,r,i,o){let a=r,s=r+i-1;const c=o.pos,l=2*o.axis;for(;;){for(;a<=s&&n[6*a+l]<c;)a++;for(;a<=s&&n[6*s+l]>=c;)s--;if(!(a<s))return a;for(let e=0;e<3;e++){let n=t[3*a+e];t[3*a+e]=t[3*s+e],t[3*s+e]=n}for(let e=0;e<6;e++){let t=n[6*a+e];n[6*a+e]=n[6*s+e],n[6*s+e]=t}a++,s--}}function Gn(e,t,n,r,i,o){let a=r,s=r+i-1;const c=o.pos,l=2*o.axis;for(;;){for(;a<=s&&n[6*a+l]<c;)a++;for(;a<=s&&n[6*s+l]>=c;)s--;if(!(a<s))return a;{let t=e[a];e[a]=e[s],e[s]=t;for(let e=0;e<6;e++){let t=n[6*a+e];n[6*a+e]=n[6*s+e],n[6*s+e]=t}a++,s--}}}function Wn(e,t){return 65535===t[e+15]}function Xn(e,t){return t[e+6]}function qn(e,t){return t[e+14]}function Yn(e){return e+8}function Kn(e,t){return t[e+6]}function Qn(e,t){return t[e+7]}function Zn(e){return e}let $n,Jn,er,tr;const nr=Math.pow(2,32);function rr(e){return"count"in e?1:1+rr(e.left)+rr(e.right)}function ir(e,t,n){return $n=new Float32Array(n),Jn=new Uint32Array(n),er=new Uint16Array(n),tr=new Uint8Array(n),or(e,t)}function or(e,t){const n=e/4,r=e/2,i="count"in t,o=t.boundingData;for(let e=0;e<6;e++)$n[n+e]=o[e];if(i){if(t.buffer){const r=t.buffer;tr.set(new Uint8Array(r),e);for(let t=e,i=e+r.byteLength;t<i;t+=32){Wn(t/2,er)||(Jn[t/4+6]+=n)}return e+r.byteLength}{const i=t.offset,o=t.count;return Jn[n+6]=i,er[r+14]=o,er[r+15]=An,e+32}}{const r=t.left,i=t.right,o=t.splitAxis;let a;if(a=or(e+32,r),a/4>nr)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Jn[n+6]=a/4,a=or(a,i),Jn[n+7]=o,a}}function ar(e,t,n,r,i){const{maxDepth:o,verbose:a,maxLeafTris:s,strategy:c,onProgress:l,indirect:u}=i,h=e._indirectBuffer,d=e.geometry,p=d.index?d.index.array:null,f=u?Gn:Vn,m=kn(d),g=new Float32Array(6);let b=!1;const y=new Hn;return In(t,n,r,y.boundingData,g),function e(n,r,i,l=null,u=0){!b&&u>=o&&(b=!0,a&&(console.warn(`MeshBVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d)));if(i<=s||u>=o)return v(r+i),n.offset=r,n.count=i,n;const m=function(e,t,n,r,i,o){let a=-1,s=0;if(0===o)a=_n(t),-1!==a&&(s=(t[a]+t[a+3])/2);else if(1===o)a=_n(e),-1!==a&&(s=function(e,t,n,r){let i=0;for(let o=t,a=t+n;o<a;o++)i+=e[6*o+2*r];return i/n}(n,r,i,a));else if(2===o){const o=jn(e);let c=Tn*i;const l=6*r,u=6*(r+i);for(let e=0;e<3;e++){const r=t[e],h=(t[e+3]-r)/Fn;if(i<8){const t=[...Bn];t.length=i;let r=0;for(let i=l;i<u;i+=6,r++){const o=t[r];o.candidate=n[i+2*e],o.count=0;const{bounds:a,leftCacheBounds:s,rightCacheBounds:c}=o;for(let e=0;e<3;e++)c[e]=1/0,c[e+3]=-1/0,s[e]=1/0,s[e+3]=-1/0,a[e]=1/0,a[e+3]=-1/0;Dn(i,n,a)}t.sort(Un);let h=i;for(let e=0;e<h;e++){const n=t[e];for(;e+1<h&&t[e+1].candidate===n.candidate;)t.splice(e+1,1),h--}for(let r=l;r<u;r+=6){const i=n[r+2*e];for(let e=0;e<h;e++){const o=t[e];i>=o.candidate?Dn(r,n,o.rightCacheBounds):(Dn(r,n,o.leftCacheBounds),o.count++)}}for(let n=0;n<h;n++){const r=t[n],l=r.count,u=i-r.count,h=r.leftCacheBounds,d=r.rightCacheBounds;let p=0;0!==l&&(p=jn(h)/o);let f=0;0!==u&&(f=jn(d)/o);const m=1+Tn*(p*l+f*u);m<c&&(a=e,c=m,s=r.candidate)}}else{for(let e=0;e<Fn;e++){const t=Bn[e];t.count=0,t.candidate=r+h+e*h;const n=t.bounds;for(let e=0;e<3;e++)n[e]=1/0,n[e+3]=-1/0}for(let t=l;t<u;t+=6){let i=~~((n[t+2*e]-r)/h);i>=Fn&&(i=31);const o=Bn[i];o.count++,Dn(t,n,o.bounds)}const t=Bn[31];Nn(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){const t=Bn[e],n=Bn[e+1];Ln(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let d=0;for(let t=0;t<31;t++){const n=Bn[t],r=n.count,l=n.bounds,u=Bn[t+1].rightCacheBounds;0!==r&&(0===d?Nn(l,zn):Ln(l,zn,zn)),d+=r;let h=0,p=0;0!==d&&(h=jn(zn)/o);const f=i-d;0!==f&&(p=jn(u)/o);const m=1+Tn*(h*d+p*f);m<c&&(a=e,c=m,s=n.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${o} used.`);return{axis:a,pos:s}}(n.boundingData,l,t,r,i,c);if(-1===m.axis)return v(r+i),n.offset=r,n.count=i,n;const y=f(h,p,t,r,i,m);if(y===r||y===r+i)v(r+i),n.offset=r,n.count=i;else{n.splitAxis=m.axis;const o=new Hn,a=r,s=y-r;n.left=o,In(t,a,s,o.boundingData,g),e(o,a,s,g,u+1);const c=new Hn,l=y,h=i-s;n.right=c,In(t,l,h,c.boundingData,g),e(c,l,h,g,u+1)}return n}(y,n,r,g),y;function v(e){l&&l(e/m)}}function sr(e,t){const n=e.geometry;t.indirect&&(e._indirectBuffer=function(e,t){const n=(e.index?e.index.count:e.attributes.position.count)/3,r=n>65536,i=r?4:2,o=t?new SharedArrayBuffer(n*i):new ArrayBuffer(n*i),a=r?new Uint32Array(o):new Uint16Array(o);for(let e=0,t=a.length;e<t;e++)a[e]=e;return a}(n,t.useSharedArrayBuffer),function(e,t){const n=kn(e),r=Mn(e,t).sort((e,t)=>e.offset-t.offset),i=r[r.length-1];i.count=Math.min(n-i.offset,i.count);let o=0;return r.forEach(({count:e})=>o+=e),n!==o}(n,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),e._indirectBuffer||Sn(n,t);const r=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=function(e,t=null,n=null,r=null){const i=e.attributes.position,o=e.index?e.index.array:null,a=kn(e),s=i.normalized;let c;null===t?(c=new Float32Array(6*a),n=0,r=a):(c=t,n=n||0,r=r||a);const l=i.array,u=i.offset||0;let h=3;i.isInterleavedBufferAttribute&&(h=i.data.stride);const d=["getX","getY","getZ"];for(let e=n;e<n+r;e++){const t=3*e,n=6*e;let r=t+0,a=t+1,p=t+2;o&&(r=o[r],a=o[a],p=o[p]),s||(r=r*h+u,a=a*h+u,p=p*h+u);for(let e=0;e<3;e++){let t,o,u;s?(t=i[d[e]](r),o=i[d[e]](a),u=i[d[e]](p)):(t=l[r+e],o=l[a+e],u=l[p+e]);let h=t;o<h&&(h=o),u<h&&(h=u);let f=t;o>f&&(f=o),u>f&&(f=u);const m=(f-h)/2,g=2*e;c[n+g+0]=h+m,c[n+g+1]=m+(Math.abs(h)+m)*Cn}}return c}(n),o=t.indirect?Rn(n,t.range):Mn(n,t.range);e._roots=o.map(n=>{const o=ar(e,i,n.offset,n.count,t),a=rr(o),s=new r(32*a);return ir(0,o,s),s})}class cr{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,r=-1/0;for(let i=0,o=e.length;i<o;i++){const o=e[i][t];n=o<n?o:n,r=o>r?o:r}this.min=n,this.max=r}setFromPoints(e,t){let n=1/0,r=-1/0;for(let i=0,o=t.length;i<o;i++){const o=t[i],a=e.dot(o);n=a<n?a:n,r=a>r?a:r}this.min=n,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}}cr.prototype.setFromBox=function(){const e=new f;return function(t,n){const r=n.min,i=n.max;let o=1/0,a=-1/0;for(let n=0;n<=1;n++)for(let s=0;s<=1;s++)for(let c=0;c<=1;c++){e.x=r.x*n+i.x*(1-n),e.y=r.y*s+i.y*(1-s),e.z=r.z*c+i.z*(1-c);const l=t.dot(e);o=Math.min(l,o),a=Math.max(l,a)}this.min=o,this.max=a}}();const lr=function(){const e=new f,t=new f,n=new f;return function(r,i,o){const a=r.start,s=e,c=i.start,l=t;n.subVectors(a,c),e.subVectors(r.end,r.start),t.subVectors(i.end,i.start);const u=n.dot(l),h=l.dot(s),d=l.dot(l),p=n.dot(s),f=s.dot(s)*d-h*h;let m,g;m=0!==f?(u*h-p*d)/f:0,g=(u+m*h)/d,o.x=m,o.y=g}}(),ur=function(){const e=new v,t=new f,n=new f;return function(r,i,o,a){lr(r,i,e);let s=e.x,c=e.y;if(s>=0&&s<=1&&c>=0&&c<=1)return r.at(s,o),void i.at(c,a);if(s>=0&&s<=1)return c<0?i.at(0,a):i.at(1,a),void r.closestPointToPoint(a,!0,o);if(c>=0&&c<=1)return s<0?r.at(0,o):r.at(1,o),void i.closestPointToPoint(o,!0,a);{let e,l;e=s<0?r.start:r.end,l=c<0?i.start:i.end;const u=t,h=n;return r.closestPointToPoint(l,!0,t),i.closestPointToPoint(e,!0,n),u.distanceToSquared(l)<=h.distanceToSquared(e)?(o.copy(u),void a.copy(l)):(o.copy(e),void a.copy(h))}}}(),hr=function(){const e=new f,t=new f,n=new h,r=new F;return function(i,o){const{radius:a,center:s}=i,{a:c,b:l,c:u}=o;r.start=c,r.end=l;if(r.closestPointToPoint(s,!0,e).distanceTo(s)<=a)return!0;r.start=c,r.end=u;if(r.closestPointToPoint(s,!0,e).distanceTo(s)<=a)return!0;r.start=l,r.end=u;if(r.closestPointToPoint(s,!0,e).distanceTo(s)<=a)return!0;const h=o.getPlane(n);if(Math.abs(h.distanceToPoint(s))<=a){const e=h.projectPoint(s,t);if(o.containsPoint(e))return!0}return!1}}();function dr(e){return Math.abs(e)<1e-15}class pr extends U{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new f),this.satBounds=new Array(4).fill().map(()=>new cr),this.points=[this.a,this.b,this.c],this.sphere=new B,this.plane=new h,this.needsUpdate=!0}intersectsSphere(e){return hr(e,this)}update(){const e=this.a,t=this.b,n=this.c,r=this.points,i=this.satAxes,o=this.satBounds,a=i[0],s=o[0];this.getNormal(a),s.setFromPoints(a,r);const c=i[1],l=o[1];c.subVectors(e,t),l.setFromPoints(c,r);const u=i[2],h=o[2];u.subVectors(t,n),h.setFromPoints(u,r);const d=i[3],p=o[3];d.subVectors(n,e),p.setFromPoints(d,r),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(a,e),this.needsUpdate=!1}}pr.prototype.closestPointToSegment=function(){const e=new f,t=new f,n=new F;return function(r,i=null,o=null){const{start:a,end:s}=r,c=this.points;let l,u=1/0;for(let a=0;a<3;a++){const s=(a+1)%3;n.start.copy(c[a]),n.end.copy(c[s]),ur(n,r,e,t),l=e.distanceToSquared(t),l<u&&(u=l,i&&i.copy(e),o&&o.copy(t))}return this.closestPointToPoint(a,e),l=a.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),o&&o.copy(a)),this.closestPointToPoint(s,e),l=s.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),o&&o.copy(s)),Math.sqrt(u)}}(),pr.prototype.intersectsTriangle=function(){const e=new pr,t=new Array(3),n=new Array(3),r=new cr,i=new cr,o=new f,a=new f,s=new f,c=new f,l=new f,u=new F,h=new F,d=new F,p=new f;function m(e,t,n){const r=e.points;let i=0,o=-1;for(let e=0;e<3;e++){const{start:s,end:c}=u;s.copy(r[e]),c.copy(r[(e+1)%3]),u.delta(a);const l=dr(t.distanceToPoint(s));if(dr(t.normal.dot(a))&&l){n.copy(u),i=2;break}const h=t.intersectLine(u,p);if(!h&&l&&p.copy(s),(h||l)&&!dr(p.distanceTo(c))){if(i<=1){(1===i?n.start:n.end).copy(p),l&&(o=i)}else if(i>=2){(1===o?n.start:n.end).copy(p),i=2;break}if(i++,2===i&&-1===o)break}}return i}return function(a,u=null,p=!1){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(e.copy(a),e.update(),a=e);const f=this.plane,g=a.plane;if(Math.abs(f.normal.dot(g.normal))>1-1e-10){const e=this.satBounds,s=this.satAxes;n[0]=a.a,n[1]=a.b,n[2]=a.c;for(let t=0;t<4;t++){const i=e[t],o=s[t];if(r.setFromPoints(o,n),i.isSeparated(r))return!1}const c=a.satBounds,l=a.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let e=0;e<4;e++){const n=c[e],i=l[e];if(r.setFromPoints(i,t),n.isSeparated(r))return!1}for(let e=0;e<4;e++){const a=s[e];for(let e=0;e<4;e++){const s=l[e];if(o.crossVectors(a,s),r.setFromPoints(o,t),i.setFromPoints(o,n),r.isSeparated(i))return!1}}return u&&(p||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),u.start.set(0,0,0),u.end.set(0,0,0)),!0}{const e=m(this,g,h);if(1===e&&a.containsPoint(h.end))return u&&(u.start.copy(h.end),u.end.copy(h.end)),!0;if(2!==e)return!1;const t=m(a,f,d);if(1===t&&this.containsPoint(d.end))return u&&(u.start.copy(d.end),u.end.copy(d.end)),!0;if(2!==t)return!1;if(h.delta(s),d.delta(c),s.dot(c)<0){let e=d.start;d.start=d.end,d.end=e}const n=h.start.dot(s),r=h.end.dot(s),i=d.start.dot(s),o=d.end.dot(s);return(n===o||i===r||r<i!==n<o)&&(u&&(l.subVectors(h.start,d.start),l.dot(s)>0?u.start.copy(h.start):u.start.copy(d.start),l.subVectors(h.end,d.end),l.dot(s)<0?u.end.copy(h.end):u.end.copy(d.end)),!0)}}}(),pr.prototype.distanceToPoint=function(){const e=new f;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}(),pr.prototype.distanceToTriangle=function(){const e=new f,t=new f,n=["a","b","c"],r=new F,i=new F;return function(o,a=null,s=null){const c=a||s?r:null;if(this.intersectsTriangle(o,c))return(a||s)&&(a&&c.getCenter(a),s&&c.getCenter(s)),0;let l=1/0;for(let t=0;t<3;t++){let r;const i=n[t],c=o[i];this.closestPointToPoint(c,e),r=c.distanceToSquared(e),r<l&&(l=r,a&&a.copy(e),s&&s.copy(c));const u=this[i];o.closestPointToPoint(u,e),r=u.distanceToSquared(e),r<l&&(l=r,a&&a.copy(u),s&&s.copy(e))}for(let c=0;c<3;c++){const u=n[c],h=n[(c+1)%3];r.set(this[u],this[h]);for(let c=0;c<3;c++){const u=n[c],h=n[(c+1)%3];i.set(o[u],o[h]),ur(r,i,e,t);const d=e.distanceToSquared(t);d<l&&(l=d,a&&a.copy(e),s&&s.copy(t))}}return Math.sqrt(l)}}();class fr{constructor(e,t,n){this.isOrientedBox=!0,this.min=new f,this.max=new f,this.matrix=new N,this.invMatrix=new N,this.points=new Array(8).fill().map(()=>new f),this.satAxes=new Array(3).fill().map(()=>new f),this.satBounds=new Array(3).fill().map(()=>new cr),this.alignedSatBounds=new Array(3).fill().map(()=>new cr),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}fr.prototype.update=function(){const e=this.matrix,t=this.min,n=this.max,r=this.points;for(let i=0;i<=1;i++)for(let o=0;o<=1;o++)for(let a=0;a<=1;a++){const s=r[1*i|2*o|4*a];s.x=i?n.x:t.x,s.y=o?n.y:t.y,s.z=a?n.z:t.z,s.applyMatrix4(e)}const i=this.satBounds,o=this.satAxes,a=r[0];for(let e=0;e<3;e++){const t=o[e],n=i[e],s=r[1<<e];t.subVectors(a,s),n.setFromPoints(t,r)}const s=this.alignedSatBounds;s[0].setFromPointsField(r,"x"),s[1].setFromPointsField(r,"y"),s[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1},fr.prototype.intersectsBox=function(){const e=new cr;return function(t){this.needsUpdate&&this.update();const n=t.min,r=t.max,i=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(e.min=n.x,e.max=r.x,a[0].isSeparated(e))return!1;if(e.min=n.y,e.max=r.y,a[1].isSeparated(e))return!1;if(e.min=n.z,e.max=r.z,a[2].isSeparated(e))return!1;for(let n=0;n<3;n++){const r=o[n],a=i[n];if(e.setFromBox(r,t),a.isSeparated(e))return!1}return!0}}(),fr.prototype.intersectsTriangle=function(){const e=new pr,t=new Array(3),n=new cr,r=new cr,i=new f;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(e.copy(o),e.update(),o=e);const a=this.satBounds,s=this.satAxes;t[0]=o.a,t[1]=o.b,t[2]=o.c;for(let e=0;e<3;e++){const r=a[e],i=s[e];if(n.setFromPoints(i,t),r.isSeparated(n))return!1}const c=o.satBounds,l=o.satAxes,u=this.points;for(let e=0;e<3;e++){const t=c[e],r=l[e];if(n.setFromPoints(r,u),t.isSeparated(n))return!1}for(let e=0;e<3;e++){const o=s[e];for(let e=0;e<4;e++){const a=l[e];if(i.crossVectors(o,a),n.setFromPoints(i,t),r.setFromPoints(i,u),n.isSeparated(r))return!1}}return!0}}(),fr.prototype.closestPointToPoint=function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t},fr.prototype.distanceToPoint=function(){const e=new f;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}(),fr.prototype.distanceToBox=function(){const e=["x","y","z"],t=new Array(12).fill().map(()=>new F),n=new Array(12).fill().map(()=>new F),r=new f,i=new f;return function(o,a=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(s||c)&&(o.getCenter(i),this.closestPointToPoint(i,r),o.closestPointToPoint(r,i),s&&s.copy(r),c&&c.copy(i)),0;const l=a*a,u=o.min,h=o.max,d=this.points;let p=1/0;for(let e=0;e<8;e++){const t=d[e];i.copy(t).clamp(u,h);const n=t.distanceToSquared(i);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(i),n<l))return Math.sqrt(n)}let f=0;for(let r=0;r<3;r++)for(let i=0;i<=1;i++)for(let o=0;o<=1;o++){const a=(r+1)%3,s=(r+2)%3,c=1<<r|i<<a|o<<s,l=d[i<<a|o<<s],p=d[c];t[f].set(l,p);const m=e[r],g=e[a],b=e[s],y=n[f],v=y.start,x=y.end;v[m]=u[m],v[g]=i?u[g]:h[g],v[b]=o?u[b]:h[g],x[m]=h[m],x[g]=i?u[g]:h[g],x[b]=o?u[b]:h[g],f++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let n=0;n<=1;n++){i.x=e?h.x:u.x,i.y=t?h.y:u.y,i.z=n?h.z:u.z,this.closestPointToPoint(i,r);const o=i.distanceToSquared(r);if(o<p&&(p=o,s&&s.copy(r),c&&c.copy(i),o<l))return Math.sqrt(o)}for(let e=0;e<12;e++){const o=t[e];for(let e=0;e<12;e++){const t=n[e];ur(o,t,r,i);const a=r.distanceToSquared(i);if(a<p&&(p=a,s&&s.copy(r),c&&c.copy(i),a<l))return Math.sqrt(a)}}return Math.sqrt(p)}}();class mr{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return 0===e.length?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class gr extends mr{constructor(){super(()=>new pr)}}const br=new gr;const yr=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==e.length&&this.setBuffer(e.pop())}}};let vr,xr;const wr=[],Er=new mr(()=>new z);function Tr(e,t,n,r,i,o){vr=Er.getPrimitive(),xr=Er.getPrimitive(),wr.push(vr,xr),yr.setBuffer(e._roots[t]);const a=Ar(0,e.geometry,n,r,i,o);yr.clearBuffer(),Er.releasePrimitive(vr),Er.releasePrimitive(xr),wr.pop(),wr.pop();const s=wr.length;return s>0&&(xr=wr[s-1],vr=wr[s-2]),a}function Ar(e,t,n,r,i=null,o=0,a=0){const{float32Array:s,uint16Array:c,uint32Array:l}=yr;let u=2*e;if(Wn(u,c)){const h=Xn(e,l),d=qn(u,c);return Pn(e,s,vr),r(h,d,!1,a,o+e,vr)}{const p=Yn(e),f=Kn(e,l);let m,g,b,y,v=p,x=f;if(i&&(b=vr,y=xr,Pn(v,s,b),Pn(x,s,y),m=i(b),g=i(y),g<m)){v=f,x=p;const k=m;m=g,g=k,b=y}b||(b=vr,Pn(v,s,b));const w=n(b,Wn(2*v,c),m,a+1,o+v);let E;if(2===w){const S=C(v);E=r(S,O(v)-S,!0,a+1,o+v,b)}else E=w&&Ar(v,t,n,r,i,o,a+1);if(E)return!0;y=xr,Pn(x,s,y);const T=n(y,Wn(2*x,c),g,a+1,o+x);let A;if(2===T){const R=C(x);A=r(R,O(x)-R,!0,a+1,o+x,y)}else A=T&&Ar(x,t,n,r,i,o,a+1);return!!A;function C(e){const{uint16Array:t,uint32Array:n}=yr;let r=2*e;for(;!Wn(r,t);)r=2*(e=Yn(e));return Xn(e,n)}function O(e){const{uint16Array:t,uint32Array:n}=yr;let r=2*e;for(;!Wn(r,t);)r=2*(e=Kn(e,n));return Xn(e,n)+qn(r,t)}}}const Cr=new f,Or=new f;const kr=parseInt(V)>=169,Sr=new f,Rr=new f,Mr=new f,Ir=new v,Pr=new v,_r=new v,Nr=new f,Lr=new f,Dr=new f,jr=new f;function Fr(e,t,n,r,i,o,a,s,c,l,u){Sr.fromBufferAttribute(t,o),Rr.fromBufferAttribute(t,a),Mr.fromBufferAttribute(t,s);const h=function(e,t,n,r,i,o,a,s){let c;if(c=o===H?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,o!==D,i),null===c)return null;const l=e.origin.distanceTo(i);return l<a||l>s?null:{distance:l,point:i.clone()}}(e,Sr,Rr,Mr,jr,c,l,u);if(h){const t=new f;U.getBarycoord(jr,Sr,Rr,Mr,t),r&&(Ir.fromBufferAttribute(r,o),Pr.fromBufferAttribute(r,a),_r.fromBufferAttribute(r,s),h.uv=U.getInterpolation(jr,Sr,Rr,Mr,Ir,Pr,_r,new v)),i&&(Ir.fromBufferAttribute(i,o),Pr.fromBufferAttribute(i,a),_r.fromBufferAttribute(i,s),h.uv1=U.getInterpolation(jr,Sr,Rr,Mr,Ir,Pr,_r,new v)),n&&(Nr.fromBufferAttribute(n,o),Lr.fromBufferAttribute(n,a),Dr.fromBufferAttribute(n,s),h.normal=U.getInterpolation(jr,Sr,Rr,Mr,Nr,Lr,Dr,new f),h.normal.dot(e.direction)>0&&h.normal.multiplyScalar(-1));const c={a:o,b:a,c:s,normal:new f,materialIndex:0};U.getNormal(Sr,Rr,Mr,c.normal),h.face=c,h.faceIndex=o,kr&&(h.barycoord=t)}return h}function Ur(e,t,n,r,i,o,a){const s=3*r;let c=s+0,l=s+1,u=s+2;const h=e.index;e.index&&(c=h.getX(c),l=h.getX(l),u=h.getX(u));const{position:d,normal:p,uv:f,uv1:m}=e.attributes,g=Fr(n,d,p,f,m,c,l,u,t,o,a);return g?(g.faceIndex=r,i&&i.push(g),g):null}function Br(e,t,n,r){const i=e.a,o=e.b,a=e.c;let s=t,c=t+1,l=t+2;n&&(s=n.getX(s),c=n.getX(c),l=n.getX(l)),i.x=r.getX(s),i.y=r.getY(s),i.z=r.getZ(s),o.x=r.getX(c),o.y=r.getY(c),o.z=r.getZ(c),a.x=r.getX(l),a.y=r.getY(l),a.z=r.getZ(l)}function zr(e,t,n,r,i,o,a){const{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let n=e,s=t+e;n<s;n++){let e;if(e=n,Br(a,3*e,c,l),a.needsUpdate=!0,r(a,e,i,o))return!0}return!1}function Hr(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));const n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position;let o,a,s,c,l=0;const u=e._roots;for(let e=0,t=u.length;e<t;e++)o=u[e],a=new Uint32Array(o),s=new Uint16Array(o),c=new Float32Array(o),h(0,l),l+=o.byteLength;function h(e,n,o=!1){const l=2*e;if(s[l+15]===An){const t=a[e+6];let n=1/0,o=1/0,u=1/0,h=-1/0,d=-1/0,p=-1/0;for(let e=3*t,a=3*(t+s[l+14]);e<a;e++){let t=r[e];const a=i.getX(t),s=i.getY(t),c=i.getZ(t);a<n&&(n=a),a>h&&(h=a),s<o&&(o=s),s>d&&(d=s),c<u&&(u=c),c>p&&(p=c)}return(c[e+0]!==n||c[e+1]!==o||c[e+2]!==u||c[e+3]!==h||c[e+4]!==d||c[e+5]!==p)&&(c[e+0]=n,c[e+1]=o,c[e+2]=u,c[e+3]=h,c[e+4]=d,c[e+5]=p,!0)}{const r=e+8,i=a[e+6],s=r+n,l=i+n;let u=o,d=!1,p=!1;t?u||(d=t.has(s),p=t.has(l),u=!d&&!p):(d=!0,p=!0);const f=u||p;let m=!1;(u||d)&&(m=h(r,n,u));let g=!1;f&&(g=h(i,n,u));const b=m||g;if(b)for(let t=0;t<3;t++){const n=r+t,o=i+t,a=c[n],s=c[n+3],l=c[o],u=c[o+3];c[e+t]=a<l?a:l,c[e+t+3]=s>u?s:u}return b}}}function Vr(e,t,n,r,i){let o,a,s,c,l,u;const h=1/n.direction.x,d=1/n.direction.y,p=1/n.direction.z,f=n.origin.x,m=n.origin.y,g=n.origin.z;let b=t[e],y=t[e+3],v=t[e+1],x=t[e+3+1],w=t[e+2],E=t[e+3+2];return h>=0?(o=(b-f)*h,a=(y-f)*h):(o=(y-f)*h,a=(b-f)*h),d>=0?(s=(v-m)*d,c=(x-m)*d):(s=(x-m)*d,c=(v-m)*d),!(o>c||s>a)&&((s>o||isNaN(o))&&(o=s),(c<a||isNaN(a))&&(a=c),p>=0?(l=(w-g)*p,u=(E-g)*p):(l=(E-g)*p,u=(w-g)*p),!(o>u||l>a)&&((l>o||o!=o)&&(o=l),(u<a||a!=a)&&(a=u),o<=i&&a>=r))}function Gr(e,t,n,r,i,o,a){const{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let s=e,u=t+e;s<u;s++){let e;if(e=n.resolveTriangleIndex(s),Br(a,3*e,c,l),a.needsUpdate=!0,r(a,e,i,o))return!0}return!1}function Wr(e,t,n,r,i,o,a){yr.setBuffer(e._roots[t]),Xr(0,e,n,r,i,o,a),yr.clearBuffer()}function Xr(e,t,n,r,i,o,a){const{float32Array:s,uint16Array:c,uint32Array:l}=yr,u=2*e;if(Wn(u,c)){!function(e,t,n,r,i,o,a,s){const{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)Ur(c,t,n,e,o,a,s)}(t,n,r,Xn(e,l),qn(u,c),i,o,a)}else{const c=Yn(e);Vr(c,s,r,o,a)&&Xr(c,t,n,r,i,o,a);const u=Kn(e,l);Vr(u,s,r,o,a)&&Xr(u,t,n,r,i,o,a)}}const qr=["x","y","z"];function Yr(e,t,n,r,i,o){yr.setBuffer(e._roots[t]);const a=Kr(0,e,n,r,i,o);return yr.clearBuffer(),a}function Kr(e,t,n,r,i,o){const{float32Array:a,uint16Array:s,uint32Array:c}=yr;let l=2*e;if(Wn(l,s)){return function(e,t,n,r,i,o,a){const{geometry:s,_indirectBuffer:c}=e;let l=1/0,u=null;for(let e=r,c=r+i;e<c;e++){let r;r=Ur(s,t,n,e,null,o,a),r&&r.distance<l&&(u=r,l=r.distance)}return u}(t,n,r,Xn(e,c),qn(l,s),i,o)}{const s=Qn(e,c),l=qr[s],u=r.direction[l]>=0;let h,d;u?(h=Yn(e),d=Kn(e,c)):(h=Kn(e,c),d=Yn(e));const p=Vr(h,a,r,i,o)?Kr(h,t,n,r,i,o):null;if(p){const e=p.point[l];if(u?e<=a[d+s]:e>=a[d+s+3])return p}const f=Vr(d,a,r,i,o)?Kr(d,t,n,r,i,o):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const Qr=new z,Zr=new pr,$r=new pr,Jr=new N,ei=new fr,ti=new fr;function ni(e,t,n,r){yr.setBuffer(e._roots[t]);const i=ri(0,e,n,r);return yr.clearBuffer(),i}function ri(e,t,n,r,i=null){const{float32Array:o,uint16Array:a,uint32Array:s}=yr;let c=2*e;null===i&&(n.boundingBox||n.computeBoundingBox(),ei.set(n.boundingBox.min,n.boundingBox.max,r),i=ei);if(!Wn(c,a)){const a=e+8,c=s[e+6];Pn(a,o,Qr);if(i.intersectsBox(Qr)&&ri(a,t,n,r,i))return!0;Pn(c,o,Qr);return!!(i.intersectsBox(Qr)&&ri(c,t,n,r,i))}{const i=t.geometry,l=i.index,u=i.attributes.position,h=n.index,d=n.attributes.position,p=Xn(e,s),f=qn(c,a);if(Jr.copy(r).invert(),n.boundsTree){Pn(e,o,ti),ti.matrix.copy(Jr),ti.needsUpdate=!0;const t=n.boundsTree.shapecast({intersectsBounds:e=>ti.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let t=3*p,n=3*(f+p);t<n;t+=3)if(Br($r,t,l,u),$r.needsUpdate=!0,e.intersectsTriangle($r))return!0;return!1}});return t}for(let e=3*p,t=3*(f+p);e<t;e+=3){Br(Zr,e,l,u),Zr.a.applyMatrix4(Jr),Zr.b.applyMatrix4(Jr),Zr.c.applyMatrix4(Jr),Zr.needsUpdate=!0;for(let e=0,t=h.count;e<t;e+=3)if(Br($r,e,h,d),$r.needsUpdate=!0,Zr.intersectsTriangle($r))return!0}}}const ii=new N,oi=new fr,ai=new fr,si=new f,ci=new f,li=new f,ui=new f;function hi(e,t,n,r={},i={},o=0,a=1/0){t.boundingBox||t.computeBoundingBox(),oi.set(t.boundingBox.min,t.boundingBox.max,n),oi.needsUpdate=!0;const s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,h=t.index,d=br.getPrimitive(),p=br.getPrimitive();let f=si,m=ci,g=null,b=null;i&&(g=li,b=ui);let y=1/0,v=null,x=null;return ii.copy(n).invert(),ai.matrix.copy(ii),e.shapecast({boundsTraverseOrder:e=>oi.distanceToBox(e),intersectsBounds:(e,t,n)=>n<y&&n<a&&(t&&(ai.min.copy(e.min),ai.max.copy(e.max),ai.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree){return t.boundsTree.shapecast({boundsTraverseOrder:e=>ai.distanceToBox(e),intersectsBounds:(e,t,n)=>n<y&&n<a,intersectsRange:(t,i)=>{for(let a=t,s=t+i;a<s;a++){Br(p,3*a,h,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=e,n=e+r;t<n;t++){Br(d,3*t,l,c),d.needsUpdate=!0;const e=d.distanceToTriangle(p,f,g);if(e<y&&(m.copy(f),b&&b.copy(g),y=e,v=t,x=a),e<o)return!0}}}})}for(let i=0,a=kn(t);i<a;i++){Br(p,3*i,h,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=e,n=e+r;t<n;t++){Br(d,3*t,l,c),d.needsUpdate=!0;const e=d.distanceToTriangle(p,f,g);if(e<y&&(m.copy(f),b&&b.copy(g),y=e,v=t,x=i),e<o)return!0}}}}),br.releasePrimitive(d),br.releasePrimitive(p),y===1/0?null:(r.point?r.point.copy(m):r.point=m.clone(),r.distance=y,r.faceIndex=v,i&&(i.point?i.point.copy(b):i.point=b.clone(),i.point.applyMatrix4(ii),m.applyMatrix4(ii),i.distance=m.sub(i.point).length(),i.faceIndex=x),r)}function di(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));const n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position;let o,a,s,c,l=0;const u=e._roots;for(let e=0,t=u.length;e<t;e++)o=u[e],a=new Uint32Array(o),s=new Uint16Array(o),c=new Float32Array(o),h(0,l),l+=o.byteLength;function h(n,o,l=!1){const u=2*n;if(s[u+15]===An){const t=a[n+6];let o=1/0,l=1/0,h=1/0,d=-1/0,p=-1/0,f=-1/0;for(let n=t,a=t+s[u+14];n<a;n++){const t=3*e.resolveTriangleIndex(n);for(let e=0;e<3;e++){let n=t+e;n=r?r[n]:n;const a=i.getX(n),s=i.getY(n),c=i.getZ(n);a<o&&(o=a),a>d&&(d=a),s<l&&(l=s),s>p&&(p=s),c<h&&(h=c),c>f&&(f=c)}}return(c[n+0]!==o||c[n+1]!==l||c[n+2]!==h||c[n+3]!==d||c[n+4]!==p||c[n+5]!==f)&&(c[n+0]=o,c[n+1]=l,c[n+2]=h,c[n+3]=d,c[n+4]=p,c[n+5]=f,!0)}{const e=n+8,r=a[n+6],i=e+o,s=r+o;let u=l,d=!1,p=!1;t?u||(d=t.has(i),p=t.has(s),u=!d&&!p):(d=!0,p=!0);const f=u||p;let m=!1;(u||d)&&(m=h(e,o,u));let g=!1;f&&(g=h(r,o,u));const b=m||g;if(b)for(let t=0;t<3;t++){const i=e+t,o=r+t,a=c[i],s=c[i+3],l=c[o],u=c[o+3];c[n+t]=a<l?a:l,c[n+t+3]=s>u?s:u}return b}}}function pi(e,t,n,r,i,o,a){yr.setBuffer(e._roots[t]),fi(0,e,n,r,i,o,a),yr.clearBuffer()}function fi(e,t,n,r,i,o,a){const{float32Array:s,uint16Array:c,uint32Array:l}=yr,u=2*e;if(Wn(u,c)){!function(e,t,n,r,i,o,a,s){const{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)Ur(c,t,n,l?l[e]:e,o,a,s)}(t,n,r,Xn(e,l),qn(u,c),i,o,a)}else{const c=Yn(e);Vr(c,s,r,o,a)&&fi(c,t,n,r,i,o,a);const u=Kn(e,l);Vr(u,s,r,o,a)&&fi(u,t,n,r,i,o,a)}}const mi=["x","y","z"];function gi(e,t,n,r,i,o){yr.setBuffer(e._roots[t]);const a=bi(0,e,n,r,i,o);return yr.clearBuffer(),a}function bi(e,t,n,r,i,o){const{float32Array:a,uint16Array:s,uint32Array:c}=yr;let l=2*e;if(Wn(l,s)){return function(e,t,n,r,i,o,a){const{geometry:s,_indirectBuffer:c}=e;let l=1/0,u=null;for(let e=r,h=r+i;e<h;e++){let r;r=Ur(s,t,n,c?c[e]:e,null,o,a),r&&r.distance<l&&(u=r,l=r.distance)}return u}(t,n,r,Xn(e,c),qn(l,s),i,o)}{const s=Qn(e,c),l=mi[s],u=r.direction[l]>=0;let h,d;u?(h=Yn(e),d=Kn(e,c)):(h=Kn(e,c),d=Yn(e));const p=Vr(h,a,r,i,o)?bi(h,t,n,r,i,o):null;if(p){const e=p.point[l];if(u?e<=a[d+s]:e>=a[d+s+3])return p}const f=Vr(d,a,r,i,o)?bi(d,t,n,r,i,o):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const yi=new z,vi=new pr,xi=new pr,wi=new N,Ei=new fr,Ti=new fr;function Ai(e,t,n,r){yr.setBuffer(e._roots[t]);const i=Ci(0,e,n,r);return yr.clearBuffer(),i}function Ci(e,t,n,r,i=null){const{float32Array:o,uint16Array:a,uint32Array:s}=yr;let c=2*e;null===i&&(n.boundingBox||n.computeBoundingBox(),Ei.set(n.boundingBox.min,n.boundingBox.max,r),i=Ei);if(!Wn(c,a)){const a=e+8,c=s[e+6];Pn(a,o,yi);if(i.intersectsBox(yi)&&Ci(a,t,n,r,i))return!0;Pn(c,o,yi);return!!(i.intersectsBox(yi)&&Ci(c,t,n,r,i))}{const i=t.geometry,l=i.index,u=i.attributes.position,h=n.index,d=n.attributes.position,p=Xn(e,s),f=qn(c,a);if(wi.copy(r).invert(),n.boundsTree){Pn(e,o,Ti),Ti.matrix.copy(wi),Ti.needsUpdate=!0;const i=n.boundsTree.shapecast({intersectsBounds:e=>Ti.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let n=p,r=f+p;n<r;n++)if(Br(xi,3*t.resolveTriangleIndex(n),l,u),xi.needsUpdate=!0,e.intersectsTriangle(xi))return!0;return!1}});return i}for(let e=p,n=f+p;e<n;e++){const n=t.resolveTriangleIndex(e);Br(vi,3*n,l,u),vi.a.applyMatrix4(wi),vi.b.applyMatrix4(wi),vi.c.applyMatrix4(wi),vi.needsUpdate=!0;for(let e=0,t=h.count;e<t;e+=3)if(Br(xi,e,h,d),xi.needsUpdate=!0,vi.intersectsTriangle(xi))return!0}}}const Oi=new N,ki=new fr,Si=new fr,Ri=new f,Mi=new f,Ii=new f,Pi=new f;function _i(e,t,n,r={},i={},o=0,a=1/0){t.boundingBox||t.computeBoundingBox(),ki.set(t.boundingBox.min,t.boundingBox.max,n),ki.needsUpdate=!0;const s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,h=t.index,d=br.getPrimitive(),p=br.getPrimitive();let f=Ri,m=Mi,g=null,b=null;i&&(g=Ii,b=Pi);let y=1/0,v=null,x=null;return Oi.copy(n).invert(),Si.matrix.copy(Oi),e.shapecast({boundsTraverseOrder:e=>ki.distanceToBox(e),intersectsBounds:(e,t,n)=>n<y&&n<a&&(t&&(Si.min.copy(e.min),Si.max.copy(e.max),Si.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){const s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>Si.distanceToBox(e),intersectsBounds:(e,t,n)=>n<y&&n<a,intersectsRange:(t,a)=>{for(let w=t,E=t+a;w<E;w++){const t=s.resolveTriangleIndex(w);Br(p,3*t,h,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=r,n=r+i;t<n;t++){const n=e.resolveTriangleIndex(t);Br(d,3*n,l,c),d.needsUpdate=!0;const r=d.distanceToTriangle(p,f,g);if(r<y&&(m.copy(f),b&&b.copy(g),y=r,v=t,x=w),r<o)return!0}}}})}for(let a=0,s=kn(t);a<s;a++){Br(p,3*a,h,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=r,n=r+i;t<n;t++){const n=e.resolveTriangleIndex(t);Br(d,3*n,l,c),d.needsUpdate=!0;const r=d.distanceToTriangle(p,f,g);if(r<y&&(m.copy(f),b&&b.copy(g),y=r,v=t,x=a),r<o)return!0}}}}),br.releasePrimitive(d),br.releasePrimitive(p),y===1/0?null:(r.point?r.point.copy(m):r.point=m.clone(),r.distance=y,r.faceIndex=v,i&&(i.point?i.point.copy(b):i.point=b.clone(),i.point.applyMatrix4(Oi),m.applyMatrix4(Oi),i.distance=m.sub(i.point).length(),i.faceIndex=x),r)}const Ni=new yr.constructor,Li=new yr.constructor,Di=new mr(()=>new z),ji=new z,Fi=new z,Ui=new z,Bi=new z;let zi=!1;function Hi(e,t,n,r,i,o=0,a=0,s=0,c=0,l=null,u=!1){let h,d;u?(h=Li,d=Ni):(h=Ni,d=Li);const p=h.float32Array,f=h.uint32Array,m=h.uint16Array,g=d.float32Array,b=d.uint32Array,y=d.uint16Array,v=2*t,x=Wn(2*e,m),w=Wn(v,y);let E=!1;if(w&&x)E=u?i(Xn(t,b),qn(2*t,y),Xn(e,f),qn(2*e,m),c,a+t,s,o+e):i(Xn(e,f),qn(2*e,m),Xn(t,b),qn(2*t,y),s,o+e,c,a+t);else if(w){const l=Di.getPrimitive();Pn(t,g,l),l.applyMatrix4(n);const h=Yn(e),d=Kn(e,f);Pn(h,p,ji),Pn(d,p,Fi);const m=l.intersectsBox(ji),b=l.intersectsBox(Fi);E=m&&Hi(t,h,r,n,i,a,o,c,s+1,l,!u)||b&&Hi(t,d,r,n,i,a,o,c,s+1,l,!u),Di.releasePrimitive(l)}else{const h=Yn(t),d=Kn(t,b);Pn(h,g,Ui),Pn(d,g,Bi);const m=l.intersectsBox(Ui),y=l.intersectsBox(Bi);if(m&&y)E=Hi(e,h,n,r,i,o,a,s,c+1,l,u)||Hi(e,d,n,r,i,o,a,s,c+1,l,u);else if(m)if(x)E=Hi(e,h,n,r,i,o,a,s,c+1,l,u);else{const t=Di.getPrimitive();t.copy(Ui).applyMatrix4(n);const l=Yn(e),d=Kn(e,f);Pn(l,p,ji),Pn(d,p,Fi);const m=t.intersectsBox(ji),g=t.intersectsBox(Fi);E=m&&Hi(h,l,r,n,i,a,o,c,s+1,t,!u)||g&&Hi(h,d,r,n,i,a,o,c,s+1,t,!u),Di.releasePrimitive(t)}else if(y)if(x)E=Hi(e,d,n,r,i,o,a,s,c+1,l,u);else{const t=Di.getPrimitive();t.copy(Bi).applyMatrix4(n);const l=Yn(e),h=Kn(e,f);Pn(l,p,ji),Pn(h,p,Fi);const m=t.intersectsBox(ji),g=t.intersectsBox(Fi);E=m&&Hi(d,l,r,n,i,a,o,c,s+1,t,!u)||g&&Hi(d,h,r,n,i,a,o,c,s+1,t,!u),Di.releasePrimitive(t)}}return E}const Vi=new fr,Gi=new z,Wi={strategy:0,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Xi{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,r=e._roots,i=e._indirectBuffer,o=n.getIndex();let a;return a=t.cloneBuffers?{roots:r.map(e=>e.slice()),index:o?o.array.slice():null,indirectBuffer:i?i.slice():null}:{roots:r,index:o?o.array:null,indirectBuffer:i},a}static deserialize(e,t,n={}){n={setIndex:!0,indirect:Boolean(e.indirectBuffer),...n};const{index:r,roots:i,indirectBuffer:o}=e,a=new Xi(t,{...n,[On]:!0});if(a._roots=i,a._indirectBuffer=o||null,n.setIndex){const n=t.getIndex();if(null===n){const n=new j(e.index,1,!1);t.setIndex(n)}else n.array!==r&&(n.array.set(r),n.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(!e.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((t=Object.assign({...Wi,[On]:!1},t)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[On]||(sr(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new z))),this.resolveTriangleIndex=t.indirect?e=>this._indirectBuffer[e]:e=>e}refit(e=null){return(this.indirect?di:Hr)(this,e)}traverse(e,t=0){const n=this._roots[t],r=new Uint32Array(n),i=new Uint16Array(n);!function t(o,a=0){const s=2*o,c=i[s+15]===An;if(c){const t=r[o+6],l=i[s+14];e(a,c,new Float32Array(n,4*o,6),t,l)}else{const i=o+8,s=r[o+6],l=r[o+7];e(a,c,new Float32Array(n,4*o,6),l)||(t(i,a+1),t(s,a+1))}}(0)}raycast(e,t=G,n=0,r=1/0){const i=this._roots,o=this.geometry,a=[],s=t.isMaterial,c=Array.isArray(t),l=o.groups,u=s?t.side:t,h=this.indirect?pi:Wr;for(let o=0,s=i.length;o<s;o++){const i=c?t[l[o].materialIndex].side:u,s=a.length;if(h(this,o,i,e,a,n,r),c){const e=l[o].materialIndex;for(let t=s,n=a.length;t<n;t++)a[t].face.materialIndex=e}}return a}raycastFirst(e,t=G,n=0,r=1/0){const i=this._roots,o=this.geometry,a=t.isMaterial,s=Array.isArray(t);let c=null;const l=o.groups,u=a?t.side:t,h=this.indirect?gi:Yr;for(let o=0,a=i.length;o<a;o++){const i=h(this,o,s?t[l[o].materialIndex].side:u,e,n,r);null!=i&&(null==c||i.distance<c.distance)&&(c=i,s&&(i.face.materialIndex=l[o].materialIndex))}return c}intersectsGeometry(e,t){let n=!1;const r=this._roots,i=this.indirect?Ai:ni;for(let o=0,a=r.length;o<a&&(n=i(this,o,e,t),!n);o++);return n}shapecast(e){const t=br.getPrimitive(),n=this.indirect?Gr:zr;let{boundsTraverseOrder:r,intersectsBounds:i,intersectsRange:o,intersectsTriangle:a}=e;if(o&&a){const e=o;o=(r,i,o,s,c)=>!!e(r,i,o,s,c)||n(r,i,this,a,o,s,t)}else o||(o=a?(e,r,i,o)=>n(e,r,this,a,i,o,t):(e,t,n)=>n);let s=!1,c=0;const l=this._roots;for(let e=0,t=l.length;e<t;e++){const t=l[e];if(s=Tr(this,e,i,o,r,c),s)break;c+=t.byteLength}return br.releasePrimitive(t),s}bvhcast(e,t,n){let{intersectsRanges:r,intersectsTriangles:i}=n;const o=br.getPrimitive(),a=this.geometry.index,s=this.geometry.attributes.position,c=this.indirect?e=>{const t=this.resolveTriangleIndex(e);Br(o,3*t,a,s)}:e=>{Br(o,3*e,a,s)},l=br.getPrimitive(),u=e.geometry.index,h=e.geometry.attributes.position,d=e.indirect?t=>{const n=e.resolveTriangleIndex(t);Br(l,3*n,u,h)}:e=>{Br(l,3*e,u,h)};if(i){const e=(e,n,r,a,s,u,h,p)=>{for(let f=r,m=r+a;f<m;f++){d(f),l.a.applyMatrix4(t),l.b.applyMatrix4(t),l.c.applyMatrix4(t),l.needsUpdate=!0;for(let t=e,r=e+n;t<r;t++)if(c(t),o.needsUpdate=!0,i(o,l,t,f,s,u,h,p))return!0}return!1};if(r){const t=r;r=function(n,r,i,o,a,s,c,l){return!!t(n,r,i,o,a,s,c,l)||e(n,r,i,o,a,s,c,l)}}else r=e}return function(e,t,n,r){if(zi)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");zi=!0;const i=e._roots,o=t._roots;let a,s=0,c=0;const l=(new N).copy(n).invert();for(let e=0,t=i.length;e<t;e++){Ni.setBuffer(i[e]),c=0;const t=Di.getPrimitive();Pn(Zn(0),Ni.float32Array,t),t.applyMatrix4(l);for(let e=0,i=o.length;e<i&&(Li.setBuffer(o[e]),a=Hi(0,0,n,l,r,s,c,0,0,t),Li.clearBuffer(),c+=o[e].length,!a);e++);if(Di.releasePrimitive(t),Ni.clearBuffer(),s+=i[e].length,a)break}return zi=!1,a}(this,e,t,r)}intersectsBox(e,t){return Vi.set(e.min,e.max,t),Vi.needsUpdate=!0,this.shapecast({intersectsBounds:e=>Vi.intersectsBox(e),intersectsTriangle:e=>Vi.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},r={},i=0,o=1/0){return(this.indirect?_i:hi)(this,e,t,n,r,i,o)}closestPointToPoint(e,t={},n=0,r=1/0){return function(e,t,n={},r=0,i=1/0){const o=r*r,a=i*i;let s=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>(Cr.copy(t).clamp(e.min,e.max),Cr.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<a,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,Cr);const r=t.distanceToSquared(Cr);return r<s&&(Or.copy(Cr),s=r,c=n),r<o}}),s===1/0)return null;const l=Math.sqrt(s);return n.point?n.point.copy(Or):n.point=Or.clone(),n.distance=l,n.faceIndex=c,n}(this,e,t,n,r)}getBoundingBox(e){e.makeEmpty();return this._roots.forEach(t=>{Pn(0,new Float32Array(t),Gi),e.union(Gi)}),e}}function qi(e,t,n){return null===e?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(n.ray.origin),e.object=t,e)}const Yi=new u,Ki=new f,Qi=new N,Zi=S.prototype.raycast,$i=W.prototype.raycast,Ji=new f,eo=new S,to=[];function no(e,t){this.isBatchedMesh?ro.call(this,e,t):io.call(this,e,t)}function ro(e,t){if(this.boundsTrees){const n=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,o=this.matrixWorld;eo.material=this.material,eo.geometry=this.geometry;const a=eo.geometry.boundsTree,s=eo.geometry.drawRange;null===eo.geometry.boundingSphere&&(eo.geometry.boundingSphere=new B);for(let a=0,s=r.length;a<s;a++){if(!this.getVisibleAt(a))continue;const s=r[a].geometryIndex;if(eo.geometry.boundsTree=n[s],this.getMatrixAt(a,eo.matrixWorld).premultiply(o),!eo.geometry.boundsTree){this.getBoundingBoxAt(s,eo.geometry.boundingBox),this.getBoundingSphereAt(s,eo.geometry.boundingSphere);const e=i[s];eo.geometry.setDrawRange(e.start,e.count)}eo.raycast(e,to);for(let e=0,n=to.length;e<n;e++){const n=to[e];n.object=this,n.batchId=a,t.push(n)}to.length=0}eo.geometry.boundsTree=a,eo.geometry.drawRange=s,eo.material=null,eo.geometry=null}else $i.call(this,e,t)}function io(e,t){if(this.geometry.boundsTree){if(void 0===this.material)return;Qi.copy(this.matrixWorld).invert(),Yi.copy(e.ray).applyMatrix4(Qi),Ji.setFromMatrixScale(this.matrixWorld),Ki.copy(Yi.direction).multiply(Ji);const n=Ki.length(),r=e.near/n,i=e.far/n,o=this.geometry.boundsTree;if(!0===e.firstHitOnly){const n=qi(o.raycastFirst(Yi,this.material,r,i),this,e);n&&t.push(n)}else{const n=o.raycast(Yi,this.material,r,i);for(let r=0,i=n.length;r<i;r++){const i=qi(n[r],this,e);i&&t.push(i)}}}else Zi.call(this,e,t)}function oo(e={}){return this.boundsTree=new Xi(this,e),this.boundsTree}function ao(){this.boundsTree=null}e.BufferGeometry.prototype.computeBoundsTree=oo,e.BufferGeometry.prototype.disposeBoundsTree=ao,e.Mesh.prototype.raycast=no;class so extends e.Raycaster{constructor(){super(),this.bvhObjects=new Set}addBVH(e){e&&e.traverse(e=>{if(e.isMesh&&e.geometry&&!this.bvhObjects.has(e.uuid))try{e.geometry.attributes&&e.geometry.attributes.position&&(e.geometry.computeBoundsTree(),this.bvhObjects.add(e.uuid))}catch(e){console.warn("为对象添加BVH失败:",e)}})}updateBVH(e){e&&e.traverse(e=>{if(e.isMesh&&e.geometry)try{e.geometry.userData&&e.geometry.userData.needsBVHUpdate&&(e.geometry.boundsTree&&e.geometry.disposeBoundsTree(),e.geometry.computeBoundingBox(),e.geometry.computeBoundingSphere(),e.geometry.attributes&&e.geometry.attributes.position&&(e.geometry.computeBoundsTree(),console.log(`已更新对象 ${e.uuid} 的BVH`)),delete e.geometry.userData.needsBVHUpdate)}catch(e){console.warn("更新BVH失败:",e)}})}updateMultipleBVH(e){e&&0!==e.length&&e.forEach(e=>{this.updateBVH(e)})}removeBVH(e){e&&e.traverse(e=>{if(e.isMesh&&e.geometry&&this.bvhObjects.has(e.uuid))try{e.geometry.boundsTree&&e.geometry.disposeBoundsTree(),this.bvhObjects.delete(e.uuid)}catch(e){console.warn("移除BVH失败:",e)}})}clearAllBVH(){this.bvhObjects.forEach(e=>{}),this.bvhObjects.clear()}hasBVH(e){if(!e)return!1;let t=!1;return e.traverse(e=>{e.isMesh&&this.bvhObjects.has(e.uuid)&&(t=!0)}),t}}class co{constructor(){this.highlightedObjects=new Map,this.sharedOutlineMaterial=null}addHighlight(e,t=6974194,n=1.03){if(!e)return;if(Array.isArray(e))return void e.forEach(e=>{e&&this.addHighlight(e,t,n)});const r=e;if(r.userData.isSelected=!0,this.highlightedObjects.has(r.uuid))return void this.updateHighlightColor(r,t);this._processObjectRecursively(r,e=>{e.isMesh&&e.geometry&&(e.userData.highlighted=!0,this._createOutline(e,t,n))}),this.highlightedObjects.set(r.uuid,{object:r,color:t,scale:n})}removeHighlight(e){if(!e)return;this._processObjectRecursively(e,e=>{e.userData.outline&&(e.remove(e.userData.outline),e.userData.outline.material&&e.userData.outline.material!==this.sharedOutlineMaterial&&e.userData.outline.material.dispose(),e.userData.outline=null),e.userData.highlighted=!1,e.userData.isSelected=!1}),this.highlightedObjects.delete(e.uuid)}updateHighlightColor(e,t){if(!e||!this.highlightedObjects.has(e.uuid))return;this._processObjectRecursively(e,e=>{e.userData.outline&&e.userData.outline.material&&e.userData.outline.material.color.setHex(t)});const n=this.highlightedObjects.get(e.uuid);n&&(n.color=t)}updateDragHighlight(e,t){if(!e)return;this._processObjectRecursively(e,e=>{e.userData.outline&&e.userData.outline.material&&(t?void 0===e.userData.outline.userData.originalDragColor&&(e.userData.outline.userData.originalDragColor=e.userData.outline.material.color.getHex(),e.userData.outline.material.color.set(16777215)):void 0!==e.userData.outline.userData.originalDragColor&&(e.userData.outline.material.color.setHex(e.userData.outline.userData.originalDragColor),delete e.userData.outline.userData.originalDragColor))})}restoreDragColors(e){e&&0!==e.length&&e.forEach(e=>{this.updateDragHighlight(e,!1)})}updateHighlightTransform(e){if(!e||!this.highlightedObjects.has(e.uuid))return;const t=this.highlightedObjects.get(e.uuid),n=t?t.scale:1.03;this._processObjectRecursively(e,e=>{e.userData.outline&&(e.userData.outline.visible=e.visible,e.userData.outline.position.set(0,0,0),e.userData.outline.rotation.set(0,0,0),e.userData.outline.scale.set(n,n,n),e.userData.outline.updateMatrix(),e.userData.outline.updateMatrixWorld(!0))})}addMultipleHighlights(e,t=14964246){e.forEach(e=>this.addHighlight(e,t))}removeMultipleHighlights(e){e.forEach(e=>this.removeHighlight(e))}removeAllHighlights(){this.highlightedObjects.forEach(e=>{this.removeHighlight(e.object)}),this.highlightedObjects.clear()}clearAllHighlights(){this.highlightedObjects.forEach(e=>{this.removeHighlight(e.object)}),this.highlightedObjects.clear()}updateAllHighlights(){this.highlightedObjects.forEach(e=>{e.object.userData.highlighted&&this.updateHighlightTransform(e.object)})}scheduleUpdateHighlights(){this.batchUpdateTimer||(this.batchUpdateTimer=requestAnimationFrame(()=>{this.updateAllHighlights(),this.batchUpdateTimer=null}))}_createOutline(t,n,r){if(!t.geometry)return;const i=new e.MeshBasicMaterial({color:n,side:e.BackSide,transparent:!1,opacity:1}),o=new e.Mesh(t.geometry,i);o.scale.set(r,r,r),o.userData.isHidden=!0,o.userData.originalObject=t,o.matrixAutoUpdate=!0,o.renderOrder=-1,t.add(o),t.userData.outline=o}_processObjectRecursively(e,t){e&&(e.isMesh?t(e):(e.isGroup||e.isObject3D)&&e.children.forEach(e=>{(e.isMesh||e.isGroup||e.isObject3D)&&this._processObjectRecursively(e,t)}))}getHighlightCount(){return this.highlightedObjects.size}isHighlighted(e){return!!e&&this.highlightedObjects.has(e.uuid)}dispose(){this.clearAllHighlights(),this.sharedOutlineMaterial&&(this.sharedOutlineMaterial.dispose(),this.sharedOutlineMaterial=null),this.highlightedObjects.clear()}}class lo{constructor(e,t,n){this.container=e,this.sceneManager=t,this.objectManager=n,this.menuElement=null,this.isVisible=!1,this.selectedObjects=[],this.hideTimer=null,this.clipboard=null,this.hideDistance=50,this.distanceCheckTimer=null,this.mousePosition={x:0,y:0},this.createMenuElement(),this.bindEvents()}createMenuElement(){this.menuElement=document.createElement("div"),this.menuElement.className="context-menu",this.menuElement.style.cssText="\n position: absolute;\n min-width: 160px;\n\n color: var(--node-content-header-color);\n background: var(--node-content-background-color);\n border: 1px solid var(--node-border-color);\n\n box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);\n backdrop-filter: blur(16px);\n border-radius: 5px;\n z-index: 10000;\n display: none;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n user-select: none;\n opacity: 0;\n transform: translateY(-3px) scale(0.98);\n overflow: hidden;\n ";(this.container.parentElement||document.body).appendChild(this.menuElement)}bindEvents(){this.container.addEventListener("contextmenu",this.handleContextMenu.bind(this)),document.addEventListener("click",this.handleDocumentClick.bind(this)),document.addEventListener("mousemove",this.handleMouseMove.bind(this)),this.menuElement.addEventListener("mouseenter",this.handleMenuMouseEnter.bind(this)),this.menuElement.addEventListener("mouseleave",this.handleMenuMouseLeave.bind(this)),this.menuElement.addEventListener("click",e=>e.stopPropagation())}handleDocumentClick(e){this.menuElement&&this.menuElement.contains(e.target)||this.hideMenu()}handleMouseMove(e){this.mousePosition.x=e.clientX,this.mousePosition.y=e.clientY,this.isVisible&&this.menuElement&&this.checkDistanceAndHide()}checkDistanceAndHide(){if(!this.menuElement||!this.isVisible)return;const e=this.menuElement.getBoundingClientRect();this.getDistanceToRect(this.mousePosition,e)>this.hideDistance?this.hideTimer||(this.hideTimer=setTimeout(()=>{this.hideMenu()},200)):this.cancelHideTimer()}getDistanceToRect(e,t){const n=Math.max(t.left-e.x,0,e.x-t.right),r=Math.max(t.top-e.y,0,e.y-t.bottom);return Math.sqrt(n*n+r*r)}cancelHideTimer(){this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)}handleMenuMouseEnter(){this.cancelHideTimer()}handleMenuMouseLeave(){setTimeout(()=>{this.checkDistanceAndHide()},50)}handleContextMenu(e){e.preventDefault(),this.selectedObjects=this.objectManager.selectedObjects||[],0===this.selectedObjects.length?this.showSceneMenu(e.clientX,e.clientY):this.showObjectMenu(e.clientX,e.clientY)}getSVGIcon(e){return{copy:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/>\n </svg>',paste:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M19 2h-4.18C14.4.84 13.3 0 12 0c-1.3 0-2.4.84-2.82 2H5c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm7 18H5V4h2v3h10V4h2v16z"/>\n </svg>',delete:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/>\n </svg>',focus:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/>\n </svg>',reset:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/>\n </svg>',camera:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M9 3L7.17 5H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2h-3.17L15 3H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z"/>\n </svg>',eye:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>\n </svg>',light:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M9 21c0 .5.4 1 1 1h4c.6 0 1-.5 1-1v-1H9v1zm3-19C8.1 2 5 5.1 5 9c0 2.4 1.2 4.5 3 5.7V17c0 .5.4 1 1 1h6c.6 0 1-.5 1-1v-2.3c1.8-1.3 3-3.4 3-5.7 0-3.9-3.1-7-7-7z"/>\n </svg>',lattice:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"/>\n </svg>',cube:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M12.5 2L22 8.5v7L12.5 22 3 15.5v-7L12.5 2zM12 4.15L5.5 9 12 13.85 18.5 9 12 4.15zM5 10.5v5.5l6.5 4.5v-5.5L5 10.5zm13 0L11.5 15v5.5L18 16v-5.5z"/>\n </svg>',refresh:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/>\n </svg>'}[e]||""}showSceneMenu(e,t){const n=[{label:"粘贴",icon:"paste",action:()=>this.paste(),disabled:!this.hasClipboardData()},{type:"separator"},{label:"添加立方体",icon:"cube",action:()=>this.addCube()},{label:"重置视图",icon:"refresh",action:()=>this.resetView()}];this.showMenu(e,t,n)}showObjectMenu(e,t){const n=[],r=this.selectedObjects.length>1;n.push({label:r?"复制选中对象":"复制",icon:"copy",action:()=>this.copy()},{label:"粘贴",icon:"paste",action:()=>this.paste(),disabled:!this.hasClipboardData()},{label:r?"删除选中对象":"删除",icon:"delete",action:()=>this.delete()}),this.selectedObjects.length>0&&n.push({type:"separator"},{label:"聚焦对象",icon:"focus",action:()=>this.focusObject()},{label:"重置变换",icon:"reset",action:()=>this.resetTransform()});const i=this.selectedObjects.filter(e=>e.userData&&e.userData.isCameraHelper&&e.userData.parentCamera);i.length>0&&(n.push({type:"separator"},{label:"设置为活动相机",icon:"camera",action:()=>this.setActiveCamera(i[0])}),this.sceneManager.isInActiveCameraView()?n.push({label:"退出相机视角",icon:"reset",action:()=>this.exitCameraView()}):n.push({label:"切换到相机视角",icon:"eye",action:()=>this.switchToCameraView()}));const o=this.selectedObjects.filter(e=>e.userData&&e.userData.isLightHelper&&e.userData.parentLight);o.length>0&&n.push({type:"separator"},{label:"调整灯光强度",icon:"light",submenu:[{label:"增加强度",action:()=>this.adjustLightIntensity(o[0],.1)},{label:"减少强度",action:()=>this.adjustLightIntensity(o[0],-.1)},{label:"重置强度",action:()=>this.resetLightIntensity(o[0])}]});const a=this.selectedObjects.filter(e=>e.isMesh);if(a.length>0){const e=this.isObjectInLatticeMode(a[0]);n.push({type:"separator"},{label:e?"取消晶格":"创建晶格",icon:"lattice",action:()=>{e?this.exitLatticeGrid(a[0]):this.createLattice(a[0])}})}this.showMenu(e,t,n)}showMenu(e,t,n){this.menuElement.innerHTML="",n.forEach(e=>{if("separator"===e.type){const e=document.createElement("div");e.style.cssText="\n height: 1px;\n background: rgba(255, 255, 255, 0.03);\n margin: 0;\n ",this.menuElement.appendChild(e)}else{const t=this.createMenuItem(e);this.menuElement.appendChild(t)}}),this.menuElement.style.display="block",this.menuElement.style.visibility="hidden",this.menuElement.style.opacity="0";const r=this.menuElement.getBoundingClientRect(),i=this.container.getBoundingClientRect();let o=e-i.left-r.width/2,a=t-i.top-r.height/2;const s=10;o<s?o=s:o+r.width>i.width-s&&(o=i.width-r.width-s),a<s?a=s:a+r.height>i.height-s&&(a=i.height-r.height-s),this.menuElement.style.left=o+"px",this.menuElement.style.top=a+"px",this.menuElement.style.visibility="visible",this.menuElement.offsetHeight,this.menuElement.style.opacity="1",this.menuElement.style.transform="translateY(0) scale(1)",this.isVisible=!0,this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)}createMenuItem(e){const t=document.createElement("div");t.style.cssText=`\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 6px 10px;\n color: var(--node-content-header-color);\n opacity: ${e.disabled?"0.4":"0.82"};\n cursor: ${e.disabled?"not-allowed":"pointer"};\n transition: all 0.15s ease;\n font-size: 11px;\n font-weight: 500;\n border-bottom: 1px solid rgba(255, 255, 255, 0.03);\n position: relative;\n `;const n=this.getSVGIcon(e.icon);return t.innerHTML=`\n <span style="width: 14px; height: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">\n ${n}\n </span>\n <span style="flex: 1; font-weight: 500; font-size: 11px;">${e.label}</span>\n ${e.submenu?'<span style="font-size: 10px; color: var(--node-content-header-color); margin-left: auto; opacity: 0.6; transition: opacity 0.15s ease;">▶</span>':""}\n `,e.disabled||(t.addEventListener("mouseenter",()=>{t.style.backgroundColor="rgba(80, 90, 255, 0.18)",t.style.color="var(--node-content-header-color)",this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)}),t.addEventListener("mouseleave",()=>{t.style.backgroundColor="transparent",t.style.color="var(--node-content-header-color)"}),t.addEventListener("click",t=>{t.stopPropagation(),e.action&&e.action(),this.hideMenu()})),t}hideMenu(){this.menuElement&&this.isVisible&&(this.menuElement.style.opacity="0",this.menuElement.style.transform="translateY(-3px) scale(0.98)",setTimeout(()=>{this.menuElement.style.display="none",this.isVisible=!1},150)),this.cancelHideTimer(),this.distanceCheckTimer&&(clearTimeout(this.distanceCheckTimer),this.distanceCheckTimer=null)}copy(){if(0!==this.selectedObjects.length)try{this.clipboard=null,this.clipboard=this.selectedObjects.map(e=>this.cloneObjectData(e)),console.log(`已复制 ${this.selectedObjects.length} 个对象到剪贴板`)}catch(e){console.error("复制失败:",e)}}cloneObjectData(e){const t={type:e.type,name:e.name,position:e.position.clone(),rotation:e.rotation.clone(),scale:e.scale.clone(),visible:e.visible,userData:{...e.userData},originalObject:e};return e.isMesh&&(t.geometry=e.geometry,t.material=e.material),e.isLight&&(t.lightData={color:e.color.clone(),intensity:e.intensity,distance:e.distance,angle:e.angle,penumbra:e.penumbra,decay:e.decay}),e.isCamera&&(t.cameraData={fov:e.fov,aspect:e.aspect,near:e.near,far:e.far,zoom:e.zoom}),t}paste(){if(this.clipboard&&0!==this.clipboard.length)try{const t=[];this.clipboard.forEach(n=>{const r=this.createObjectFromData(n);r&&(r.position.add(new e.Vector3(1,0,1)),this.sceneManager.scene.add(r),t.push(r))}),t.length>0&&(this.sceneManager.addObjects(t),this.objectManager.clearSelection(),t.forEach(e=>{this.objectManager.selectedObjects.push(e),this.objectManager.outlineManager.addHighlight(e,6974194)}),t.length>0&&this.objectManager._attachTransformToMultipleObjects(t),this.objectManager.onSelectionChange&&this.objectManager.onSelectionChange(this.objectManager.selectedObjects)),this.clipboard=null}catch(e){console.error("粘贴失败:",e)}}createObjectFromData(t){let n=null;try{switch(t.type){case"Mesh":n=this.createMesh(t);break;case"DirectionalLight":n=this.createDirectionalLight(t);break;case"PointLight":n=this.createPointLight(t);break;case"SpotLight":n=this.createSpotLight(t);break;case"PerspectiveCamera":n=this.createPerspectiveCamera(t);break;case"OrthographicCamera":n=this.createOrthographicCamera(t);break;case"Group":n=this.createGroup(t);break;default:if(!t.originalObject||!t.originalObject.clone)return console.warn(`不支持的对象类型: ${t.type}`),null;n=t.originalObject.clone()}n&&(n.name=t.name+"_copy",n.position.copy(t.position),n.rotation.copy(t.rotation),n.scale.copy(t.scale),n.visible=t.visible,n.userData={selectable:!1!==t.userData.selectable,id:e.MathUtils.generateUUID()})}catch(e){return console.error("创建对象失败:",e),null}return n}createMesh(t){if(!t.geometry||!t.material)return console.warn("网格对象缺少几何体或材质"),null;const n=t.geometry.clone();let r;r=Array.isArray(t.material)?t.material.map(e=>e.clone()):t.material.clone();const i=new e.Mesh(n,r);return i.castShadow=t.originalObject.castShadow,i.receiveShadow=t.originalObject.receiveShadow,i}createDirectionalLight(t){const n=new e.DirectionalLight(t.lightData.color,t.lightData.intensity);return t.originalObject.castShadow&&(n.castShadow=!0,n.shadow.mapSize.copy(t.originalObject.shadow.mapSize),n.shadow.camera.copy(t.originalObject.shadow.camera)),n}createPointLight(t){const n=new e.PointLight(t.lightData.color,t.lightData.intensity,t.lightData.distance,t.lightData.decay);return t.originalObject.castShadow&&(n.castShadow=!0,n.shadow.mapSize.copy(t.originalObject.shadow.mapSize)),n}createSpotLight(t){const n=new e.SpotLight(t.lightData.color,t.lightData.intensity,t.lightData.distance,t.lightData.angle,t.lightData.penumbra,t.lightData.decay);return t.originalObject.castShadow&&(n.castShadow=!0,n.shadow.mapSize.copy(t.originalObject.shadow.mapSize)),n}createPerspectiveCamera(t){const n=new e.PerspectiveCamera(t.cameraData.fov,t.cameraData.aspect,t.cameraData.near,t.cameraData.far);return n.zoom=t.cameraData.zoom,n}createOrthographicCamera(t){const n=t.originalObject,r=new e.OrthographicCamera(n.left,n.right,n.top,n.bottom,t.cameraData.near,t.cameraData.far);return r.zoom=t.cameraData.zoom,r}createGroup(t){const n=new e.Group;return t.originalObject.children&&t.originalObject.children.length>0&&t.originalObject.children.forEach(e=>{const t=this.cloneObjectData(e),r=this.createObjectFromData(t);r&&n.add(r)}),n}hasClipboardData(){return this.clipboard&&this.clipboard.length>0}delete(){0!==this.selectedObjects.length&&this.sceneManager.deleteSelectedObjects()}focusObject(){this.sceneManager.focusSelectedObject()||console.error("聚焦失败")}resetTransform(){this.selectedObjects.forEach(e=>{e.position.set(0,0,0),e.rotation.set(0,0,0),e.scale.set(1,1,1),e.updateMatrix(),e.updateMatrixWorld(!0)})}setActiveCamera(e){if(e.userData&&e.userData.parentCamera){this.sceneManager.setActiveCamera(e.userData.parentCamera)||console.error("设置活动相机失败")}}switchToCameraView(){this.sceneManager.switchToActiveCameraView()||console.error("切换失败")}exitCameraView(){this.sceneManager.switchToMainCameraView()||console.error("退出失败")}adjustLightIntensity(e,t){if(e.userData&&e.userData.parentLight){const n=e.userData.parentLight;n.intensity,n.intensity=Math.max(0,n.intensity+t)}}resetLightIntensity(e){if(e.userData&&e.userData.parentLight){e.userData.parentLight.intensity=1}}isObjectInLatticeMode(e){return!(!e||!e.isMesh)&&(!(!e.userData||!e.userData.isLatticeMode)||(!(!e.userData||!e.userData.latticeHelper)||!!e.material&&(Array.isArray(e.material)?e.material.some(e=>e.wireframe):e.material.wireframe)))}createLattice(e){e&&e.isMesh&&(e.userData||(e.userData={}),e.userData.isLatticeMode=!0,this.sceneManager.createLattice(e))}exitLatticeGrid(e){if(e&&e.isMesh)try{e.userData&&(e.userData.isLatticeMode=!1,e.userData.latticeHelper&&(this.sceneManager.scene.remove(e.userData.latticeHelper),e.userData.latticeHelper.geometry&&e.userData.latticeHelper.geometry.dispose(),e.userData.latticeHelper.material&&e.userData.latticeHelper.material.dispose(),delete e.userData.latticeHelper)),e.material&&(Array.isArray(e.material)?e.material.forEach(e=>{e.wireframe&&(e.wireframe=!1)}):e.material.wireframe&&(e.material.wireframe=!1)),this.sceneManager.exitLatticeGrid&&this.sceneManager.exitLatticeGrid(e),console.log("已取消晶格模式")}catch(e){console.error("取消晶格失败:",e)}}addCube(){this.sceneManager.addCube()}resetView(){this.objectManager.orbitControls&&this.objectManager.orbitControls.reset()}dispose(){this.clipboard=null,this.cancelHideTimer(),this.distanceCheckTimer&&(clearTimeout(this.distanceCheckTimer),this.distanceCheckTimer=null),this.container.removeEventListener("contextmenu",this.handleContextMenu.bind(this)),document.removeEventListener("click",this.handleDocumentClick.bind(this)),document.removeEventListener("mousemove",this.handleMouseMove.bind(this)),this.menuElement&&(this.menuElement.removeEventListener("mouseenter",this.handleMenuMouseEnter.bind(this)),this.menuElement.removeEventListener("mouseleave",this.handleMenuMouseLeave.bind(this)),this.menuElement.parentElement&&this.menuElement.parentElement.removeChild(this.menuElement)),this.menuElement=null}}const uo={move:'<svg viewBox="0 0 24 24" width="24" height="24" fill="white" xmlns="http://www.w3.org/2000/svg">\n <path d="M12 2L16.2426 6.24264L14.8284 7.65685L12 4.82843L9.17157 7.65685L7.75736 6.24264L12 2ZM2 12L6.24264 7.75736L7.65685 9.17157L4.82843 12L7.65685 14.8284L6.24264 16.2426L2 12ZM22 12L17.7574 16.2426L16.3431 14.8284L19.1716 12L16.3431 9.17157L17.7574 7.75736L22 12ZM12 14C10.8954 14 10 13.1046 10 12C10 10.8954 10.8954 10 12 10C13.1046 10 14 10.8954 14 12C14 13.1046 13.1046 14 12 14ZM12 22L7.75736 17.7574L9.17157 16.3431L12 19.1716L14.8284 16.3431L16.2426 17.7574L12 22Z"></path>\n </svg>',rotate:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>\n <path d="M18 9l3 3l-3 3"></path>\n <path d="M15 12h6"></path>\n <path d="M6 9l-3 3l3 3"></path>\n <path d="M3 12h6"></path>\n</svg>',scale:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>\n <path d="M9 18l3 3l3 -3"></path>\n <path d="M12 15v6"></path>\n <path d="M15 6l-3 -3l-3 3"></path>\n <path d="M12 3v6"></path>\n</svg>'};class ho extends e.Object3D{constructor(){super(),this.isSelectionProxy=!0,this.type="SelectionProxy",this.targetObjects=[],this.initialMatrices=new Map,this.initialPositions=new Map,this.initialRotations=new Map,this.initialScales=new Map,this.initialRelativePositions=new Map,this._tempVector=new e.Vector3,this._tempBox=new e.Box3,this.initialProxyPosition=new e.Vector3,this.initialProxyQuaternion=new e.Quaternion,this.initialProxyScale=new e.Vector3(1,1,1)}setTargets(e){this._clearData(),e&&0!==e.length&&(this.targetObjects=e.filter(e=>e&&e.visible),this._updateProxyCenter(),this._saveInitialStates())}_clearData(){this.targetObjects=[],[this.initialMatrices,this.initialPositions,this.initialRotations,this.initialScales,this.initialRelativePositions].forEach(e=>e.clear())}_updateProxyCenter(){if(0===this.targetObjects.length)return;const t=new e.Box3;t.makeEmpty(),this.targetObjects.forEach(n=>{let r;if(n.updateMatrixWorld(!0),n.geometry)n.geometry.boundingBox||n.geometry.computeBoundingBox(),r=n.geometry.boundingBox.clone(),r.applyMatrix4(n.matrixWorld);else{r=new e.Box3;const t=new e.Vector3;n.getWorldPosition(t),r.expandByPoint(t)}t.union(r)});const n=new e.Vector3;t.getCenter(n),this.position.copy(n),this.quaternion.identity(),this.scale.set(1,1,1),this.updateMatrix(),this.updateMatrixWorld(!0)}_saveInitialStates(){this.initialProxyPosition.copy(this.position),this.initialProxyQuaternion.copy(this.quaternion),this.initialProxyScale.copy(this.scale),this.updateMatrixWorld(!0);const t=new e.Vector3;this.getWorldPosition(t),this.targetObjects.forEach(n=>{n.updateMatrixWorld(!0);const r=n.uuid;this.initialMatrices.set(r,n.matrixWorld.clone()),this.initialPositions.set(r,n.position.clone()),this.initialRotations.set(r,n.quaternion.clone()),this.initialScales.set(r,n.scale.clone());const i=new e.Vector3;n.getWorldPosition(i);const o=i.sub(t);this.initialRelativePositions.set(r,o)})}applyTransformToTargets(){if(0===this.targetObjects.length)return;this.updateMatrixWorld(!0),new e.Matrix4;const t=new e.Vector3,n=new e.Quaternion,r=new e.Vector3,i=new e.Vector3,o=new e.Vector3,a=new e.Matrix4;this.getWorldPosition(i),this.targetObjects.forEach(e=>{const s=e.uuid,c=this.initialRelativePositions.get(s);if(!c)return;o.copy(c),o.applyQuaternion(this.quaternion),o.multiply(this.scale),o.add(i),e.parent?(e.parent.updateWorldMatrix(!0,!1),a.copy(e.parent.matrixWorld).invert(),t.copy(o),t.applyMatrix4(a),e.position.copy(t)):e.position.copy(o);const l=this.initialRotations.get(s),u=this.initialScales.get(s);l&&u&&(n.copy(l),e.quaternion.copy(n),e.quaternion.premultiply(this.quaternion),r.copy(u),r.multiply(this.scale),e.scale.copy(r)),e.updateMatrix(),e.updateMatrixWorld(!0)})}dispose(){this._clearData()}}class po{constructor(t,n,r,i=null,o=null,a=null){this.scene=t,this.camera=n,this.domElement=r,this.onObjectsChanged=i,this.onSelectionChange=o,this.onTransformChange=a,this.reusableVector=new e.Vector3,this.reusableBox3=new e.Box3,this.isBaned=!1,this.selectableObjects=[],this.selectedObjects=[],this.isSelecting=!1,this.selectStartPosition={x:0,y:0},this.selectEndPosition={x:0,y:0},this.isMouseDown=!1,this.transforming=!1,this.selectionGroup=null,this.highlightColor=new e.Color(3355647),this._initSelectionBox(),this._initControls(),this.raycaster=new so,this.pointer=new e.Vector2,this._addEventListeners(),this.outlineManager=new co,this.contextMenu=null}setSceneManager(e){this.sceneManager=e,this.contextMenu||(this.contextMenu=new lo(this.domElement,e,this))}_initSelectionBox(){this.selectionBoxElement=document.createElement("div"),this.selectionBoxElement.className="selection-box",this.selectionBoxElement.style.cssText="\n position: absolute; border: 2px dashed #646cff;\n pointer-events: none; display: none; z-index: 9999; transform-origin: top left;\n will-change: transform, width, height; top: 0; left: 0;\n ";const e=this.domElement.parentElement||this.domElement;this.domElement.parentElement?e.appendChild(this.selectionBoxElement):this.domElement.insertAdjacentElement("afterend",this.selectionBoxElement)}_initControls(){this.orbitControls=new Vt(this.camera,this.domElement),this.orbitControls.enableDamping=!1,this.transformControls=new Jt(this.camera,this.domElement),Object.assign(this.transformControls,{size:.5,translationSnap:0,rotationSnap:null,scaleSnap:null,mode:"translate",space:"world",sensitivity:2}),this.transformControls.userData.renderThrottle=1,this.transformControls.userData.frameCount=0;const e=this.transformControls._gizmo.children[0].children;this.transformControls._gizmo.children[0].children=e.filter((e,t)=>![1,4,7].includes(t)),this.selectionProxy=new ho,this.scene.add(this.selectionProxy),this.transformControls.addEventListener("dragging-changed",this._onTransformDragging.bind(this)),this.transformControls.addEventListener("change",this._onTransformChange.bind(this)),this.transformControls.addEventListener("mouseenter",this._onTransformMouseEnter.bind(this)),this.transformControls.addEventListener("mouseleave",this._onTransformMouseLeave.bind(this)),this.transformMode="translate",this.scene.add(this.transformControls),this._initCursorStyles()}_initCursorStyles(){this.cursorStyles={move:this._createCursorFromSVG(uo.move),rotate:this._createCursorFromSVG(uo.rotate),scale:this._createCursorFromSVG(uo.scale)},this.defaultCursor=this.domElement.style.cursor||"default"}_createCursorFromSVG(e){const t=document.createElement("div");t.innerHTML=e;const n=t.querySelector("svg");if(!n)return"default";n.setAttribute("width","24"),n.setAttribute("height","24");const r=(new XMLSerializer).serializeToString(n);return`url("${`data:image/svg+xml,${encodeURIComponent(r)}`}") 12 12, auto`}_onTransformMouseEnter(){this._updateCursorStyle()}_onTransformMouseLeave(){this.transforming||this._resetCursorStyle()}_updateCursorStyle(){const e={translate:"move",rotate:"rotate",scale:"scale"}[this.transformMode];e&&this.cursorStyles[e]&&(this.domElement.style.cursor=this.cursorStyles[e])}_resetCursorStyle(){this.domElement.style.cursor=this.defaultCursor}_onTransformChange(){this.transforming&&this.selectionProxy.targetObjects.length>0&&(this.selectionProxy.applyTransformToTargets(),this.selectedObjects.forEach(e=>this._updateObjectHighlight(e))),this.selectedObjects.forEach(e=>{this._updateHelperTarget(e)})}_updateHelperTarget(e){e&&e.userData&&(e.userData.isLightHelper&&e.userData.updateLight&&e.userData.updateLight(),e.userData.isCameraHelper&&e.userData.updateCamera&&this.transforming&&e.userData.updateCamera())}_onTransformDragging(e){this.orbitControls.enabled=!e.value,this.transforming=e.value,e.value?(this._updateCursorStyle(),this._recordInitialTransformState()):(this._resetCursorStyle(),this._recordTransformHistory(),this.selectionProxy.targetObjects.length>0&&(this.selectionProxy.setTargets(this.selectedObjects),this.selectedObjects.forEach(e=>{this._updateObjectHighlight(e),this._updateHelperTarget(e)}))),this.selectedObjects.forEach(t=>this._updateHighlightColorForDrag(t,e.value))}_recordTransformHistory(){if(!this.initialTransformState||0===this.initialTransformState.length)return;const e=this.scene.userData.sceneManager;if(!e)return void console.warn("无法找到场景管理器,无法记录变换历史");let t=!1;const n=this.selectedObjects.map(e=>{const n=this.initialTransformState.find(t=>t.object===e);return!n||e.position.equals(n.position)&&e.quaternion.equals(n.quaternion)&&e.scale.equals(n.scale)||(t=!0),{object:e,position:e.position.clone(),rotation:e.rotation.clone(),quaternion:e.quaternion.clone(),scale:e.scale.clone(),matrix:e.matrix.clone()}});if(!t)return void(this.initialTransformState=null);const r={type:"TRANSFORM",data:{initialState:[...this.initialTransformState],finalState:[...n]},undo:()=>this._applyTransformState(r.data.initialState),redo:()=>this._applyTransformState(r.data.finalState)};e.addActionToHistory(r),this.initialTransformState=null}_applyTransformState(e){e&&e.forEach(e=>{e&&e.object&&(e.object.position.copy(e.position),e.object.quaternion.copy(e.quaternion),e.object.scale.copy(e.scale),e.object.updateMatrix(),e.object.updateMatrixWorld(!0))})}_recordInitialTransformState(){this.selectedObjects&&0!==this.selectedObjects.length?this.initialTransformState=this.selectedObjects.map(e=>e?{object:e,position:e.position.clone(),rotation:e.rotation.clone(),quaternion:e.quaternion.clone(),scale:e.scale.clone(),matrix:e.matrix.clone()}:null).filter(Boolean):this.initialTransformState=null}_updateHighlightColorForDrag(e,t){this.outlineManager.updateDragHighlight(e,t)}_updateObjectHighlight(e){this.outlineManager.updateHighlightTransform(e)}_addEventListeners(){const e=[this._onPointerDown,this._onPointerMove,this._onPointerUp];["pointerdown","pointermove","pointerup"].forEach((t,n)=>{this.domElement.addEventListener(t,e[n].bind(this))}),window.addEventListener("keydown",this._onKeyDown.bind(this))}removeEventListeners(){const e=[this._onPointerDown,this._onPointerMove,this._onPointerUp];["pointerdown","pointermove","pointerup"].forEach((t,n)=>{this.domElement.removeEventListener(t,e[n].bind(this))}),window.removeEventListener("keydown",this._onKeyDown.bind(this))}_onKeyDown(e){const t={g:"translate",r:"rotate",s:"scale"}[e.key.toLowerCase()];t&&this.setTransformMode(t)}setTransformMode(e){["translate","rotate","scale"].includes(e)&&(this.transformControls.setMode(e),this.transformMode=e,(this.transformControls.dragging||this.transforming)&&this._updateCursorStyle(),this.onTransformChange&&this.onTransformChange(e))}getTransformMode(){return this.transformMode}_updateSelectionBox(){if(!this.isSelecting)return void(this.selectionBoxElement.style.display="none");const e=this.domElement.parentElement.getBoundingClientRect(),t=Math.min(this.selectStartPosition.x,this.selectEndPosition.x)-e.left,n=Math.min(this.selectStartPosition.y,this.selectEndPosition.y)-e.top,r=Math.abs(this.selectEndPosition.x-this.selectStartPosition.x),i=Math.abs(this.selectEndPosition.y-this.selectStartPosition.y);Object.assign(this.selectionBoxElement.style,{display:"block",transform:`translate(${t}px, ${n}px)`,width:`${r}px`,height:`${i}px`})}_onPointerDown(e){if(this.isBaned||0!==e.button||this.transforming)return;e.preventDefault(),this.isMouseDown=!0;const t=this.domElement.getBoundingClientRect();this.pointer.x=(e.clientX-t.left)/t.width*2-1,this.pointer.y=-(e.clientY-t.top)/t.height*2+1,this.selectStartPosition={x:e.clientX,y:e.clientY},this.raycaster.setFromCamera(this.pointer,this.camera);const n=this.raycaster.intersectObjects(this.selectableObjects,!0);if(n.length>0){const t=n[0].object;this._ensureObjectUserData(t);const r=this._findSelectableParent(t);r&&this._handleObjectSelection(r,e.shiftKey)}else e.shiftKey||this._clearSelectionAndTransforms()}_findSelectableParent(e){if(!e)return null;let t=e;for(;t;){if(this._ensureObjectUserData(t),!0===t.userData.selectable)return t;if(t=t.parent,t===this.scene)break}return null}_ensureObjectUserData(e){e.userData||(e.userData={}),void 0===e.userData.selectable&&(e.userData.selectable=!0)}_handleObjectSelection(e,t){if(e&&!1!==e.userData.selectable){if(t)this._toggleObjectSelection(e);else{if(this.clearSelection(),this.outlineManager.addHighlight(e,6974194),this.selectedObjects.push(e),this._removeSelectionGroup(),e.userData&&e.userData.isCameraHelper&&e.userData.parentCamera){const t=e.userData.parentCamera;t.updateMatrixWorld(!0),e.updateMatrixWorld(!0),e.position.copy(t.position),e.quaternion.copy(t.quaternion),e.updateMatrix(),e.updateMatrixWorld(!0)}this.transformControls.attach(e)}this.onSelectionChange&&this.onSelectionChange(this.selectedObjects)}}_toggleObjectSelection(e){const t=this.selectedObjects.indexOf(e);-1!==t?(this.outlineManager.removeHighlight(e),this.selectedObjects.splice(t,1),0===t&&this.selectedObjects.length>0&&this.outlineManager.updateHighlightColor(this.selectedObjects[0],14964246)):(this.selectedObjects.push(e),1===this.selectedObjects.length?this.outlineManager.addHighlight(e,14964246):(this.outlineManager.addHighlight(e,6974194),this.outlineManager.updateHighlightColor(this.selectedObjects[0],14964246))),this.selectedObjects.length>0?this._attachTransformToMultipleObjects(this.selectedObjects):this._clearSelectionAndTransforms()}_clearSelectionAndTransforms(){this.clearSelection(),this.transformControls.detach(),this._removeSelectionGroup(),this.onSelectionChange&&this.onSelectionChange(this.selectedObjects)}_removeSelectionGroup(){this.selectionGroup&&(this.scene.remove(this.selectionGroup),this.selectionGroup=null)}_onPointerMove(e){if(this.isBaned||1!==e.buttons||this.transforming||!this.isMouseDown)return;this.selectEndPosition={x:e.clientX,y:e.clientY};Math.sqrt(Math.pow(this.selectEndPosition.x-this.selectStartPosition.x,2)+Math.pow(this.selectEndPosition.y-this.selectStartPosition.y,2))>10&&(this.isSelecting=!0,this._updateSelectionBox())}_onPointerUp(e){if(!this.isBaned&&0===e.button&&!this.transforming&&this.isMouseDown&&(this.isMouseDown=!1,this.isSelecting)){const t=this.domElement.getBoundingClientRect(),n={startX:(this.selectStartPosition.x-t.left)/t.width*2-1,startY:-(this.selectStartPosition.y-t.top)/t.height*2+1,endX:(this.selectEndPosition.x-t.left)/t.width*2-1,endY:-(this.selectEndPosition.y-t.top)/t.height*2+1};e.shiftKey||(this.clearSelection(),this.transformControls.detach()),this._selectObjectsInBox(n),this.isSelecting=!1,this._updateSelectionBox(),this.onSelectionChange&&this.onSelectionChange(this.selectedObjects)}}_selectObjectsInBox(e){const[t,n,r,i]=[Math.min(e.startX,e.endX),Math.max(e.startX,e.endX),Math.min(e.startY,e.endY),Math.max(e.startY,e.endY)],o=this.reusableVector,a=new Set,s=[];for(let e=0;e<this.selectableObjects.length;e++){const c=this.selectableObjects[e];if(c.visible){if(c.updateMatrixWorld(!0),o.setFromMatrixPosition(c.matrixWorld),o.project(this.camera),this._isInSelectionBox(o,t,n,r,i)&&-1===this.selectedObjects.indexOf(c)){const e=this._findSelectableParent(c);e&&-1===s.indexOf(e)&&(s.push(e),this.selectedObjects.push(e));continue}this._checkChildrenInSelectionBox(c,t,n,r,i,o,a,s)}}s.length>0&&(this.selectedObjects.length===s.length?(this.outlineManager.addHighlight(s[0],6974194),s.length>1&&this.outlineManager.addMultipleHighlights(s.slice(1),14964246)):(this.outlineManager.addMultipleHighlights(s,14964246),this.selectedObjects.length>0&&this.outlineManager.updateHighlightColor(this.selectedObjects[0],6974194))),this.selectedObjects.length>0&&this._attachTransformToMultipleObjects(this.selectedObjects)}_isInSelectionBox(e,t,n,r,i){return e.x>=t&&e.x<=n&&e.y>=r&&e.y<=i}_checkChildrenInSelectionBox(e,t,n,r,i,o,a,s){e.children&&0!==e.children.length&&e.visible&&(e.uuid&&a.has(e.uuid)||(e.uuid&&a.add(e.uuid),e.children.forEach(e=>{if(e.visible){if(e.isObject3D&&(e.updateMatrixWorld(!0),o.setFromMatrixPosition(e.matrixWorld),o.project(this.camera),this._isInSelectionBox(o,t,n,r,i)&&-1===this.selectedObjects.indexOf(e))){const t=this._findSelectableParent(e);t&&-1===s.indexOf(t)&&(s.push(t),this.selectedObjects.push(t))}this._checkChildrenInSelectionBox(e,t,n,r,i,o,a,s)}})))}addObjects(e){console.log(e,"objects");(Array.isArray(e)?e:[e]).forEach(e=>this._addSelectableObject(e))}_addSelectableObject(e){if(console.log(e,"添加可选择对象"),e.userData||(e.userData={}),void 0===e.userData.selectable&&(e.userData.selectable=!0),e.isMesh&&e.material?Array.isArray(e.material)?e.userData.originalColors=e.material.map(e=>e.color?e.color.getHex():16777215):e.material.color?e.userData.originalColor=e.material.color.getHex():e.userData.originalColor=16777215:e.userData.originalColor=16777215,!0===e.userData.selectable&&-1===this.selectableObjects.indexOf(e)){if(this.selectableObjects.push(e),e.geometry||e.isObject3D)try{this.raycaster.addBVH(e)}catch(e){console.warn("添加BVH失败:",e)}this.onObjectsChanged&&this.onObjectsChanged(this.selectableObjects)}}removeSelectableObjects(e){this.clearSelection();(Array.isArray(e)?e:[e]).forEach(e=>this._removeSelectableObject(e))}_removeSelectableObject(e){if(e){if(this._removeObjectFromSelectables(e),e.userData){if(e.userData.isLightHelper&&e.userData.parentLight){const t=e.userData.parentLight;t.parent&&t.parent.remove(t)}if(e.userData.isCameraHelper&&e.userData.parentCamera){const t=e.userData.parentCamera;t.parent&&t.parent.remove(t)}}if(e.isGroup||e.children&&e.children.length>0){[...e.children].forEach(e=>{this._removeObjectFromSelectables(e)})}e.parent?e.parent.remove(e):this.scene.remove(e),this._cleanupInvalidSelectedObjects(),this._disposeObject(e)}}_removeObjectFromSelectables(e){const t=this.selectableObjects.indexOf(e);if(-1!==t&&(this.selectableObjects.splice(t,1),e.geometry))try{this.raycaster.removeBVH(e)}catch(e){console.warn("移除BVH失败:",e)}const n=this.selectedObjects.indexOf(e);-1!==n&&(this.outlineManager.removeHighlight(e),this.selectedObjects.splice(n,1),this.selectedObjects.length>0?this._attachTransformToMultipleObjects(this.selectedObjects):(this.transformControls.detach(),this._removeSelectionGroup()),this.onSelectionChange&&this.onSelectionChange(this.selectedObjects))}_disposeObject(e){if(e.geometry&&e.geometry.dispose(),e.material){(Array.isArray(e.material)?e.material:[e.material]).forEach(e=>{e.map&&e.map.dispose(),e.dispose()})}e.dispose&&"function"==typeof e.dispose&&e.dispose()}clearSelection(){this.transformControls.detach(),this.selectionProxy&&this.selectionProxy.dispose(),this.outlineManager.removeMultipleHighlights(this.selectedObjects),this.selectedObjects.length=0}_isObjectInSceneGraph(e){if(!e)return!1;let t=e;for(;t.parent;)if(t=t.parent,t===this.scene)return!0;return this.scene.children.includes(e)}_cleanupInvalidSelectedObjects(){const e=this.selectedObjects.filter(e=>this._isObjectInSceneGraph(e));e.length!==this.selectedObjects.length&&(this.selectedObjects.forEach(e=>{this._isObjectInSceneGraph(e)||this.outlineManager.removeHighlight(e)}),this.selectedObjects=e,0===this.selectedObjects.length?this._clearSelectionAndTransforms():this._attachTransformToMultipleObjects(this.selectedObjects),this.onSelectionChange&&this.onSelectionChange(this.selectedObjects))}_attachTransformToMultipleObjects(e){if(!e||0===e.length)return;const t=e.filter(e=>this._isObjectInSceneGraph(e));if(0!==t.length)if(1!==t.length){this._isObjectInSceneGraph(this.selectionProxy)||this.scene.add(this.selectionProxy);try{this.selectionProxy.setTargets(t),this.transformControls.attach(this.selectionProxy)}catch(e){console.warn("无法附加变换控制器到选择代理:",e),this.transformControls.detach()}}else try{this.transformControls.attach(t[0])}catch(e){console.warn("无法附加变换控制器到对象:",e),this.transformControls.detach()}else this.transformControls.detach()}update(){if(this.selectedObjects.length>0&&this._cleanupInvalidSelectedObjects(),this.transformControls&&this.transforming){const e=this.transformControls.userData.renderThrottle||1;this.transformControls.userData.frameCount=(this.transformControls.userData.frameCount||0)+1,this.transformControls.userData.frameCount%e===0&&this.transformControls.updateMatrixWorld(!0)}this.selectedObjects.length>0&&this.outlineManager.updateAllHighlights()}dispose(){this.removeEventListeners(),this._resetCursorStyle();try{this.transformControls.detach()}catch(e){console.warn("销毁时分离变换控制器失败:",e)}this.clearSelection(),this.selectionBoxElement&&this.selectionBoxElement.parentElement&&this.selectionBoxElement.parentElement.removeChild(this.selectionBoxElement),this.selectionBoxElement=null,this.selectionProxy&&(this.selectionProxy.dispose(),this.scene.remove(this.selectionProxy),this.selectionProxy=null),this.selectableObjects.length=0,this.selectedObjects.length=0,this.transformControls&&(this.transformControls.dispose(),this.scene.remove(this.transformControls)),this.orbitControls&&this.orbitControls.dispose(),this.outlineManager&&(this.outlineManager.dispose(),this.outlineManager=null),this.contextMenu&&(this.contextMenu.dispose(),this.contextMenu=null),this.reusableVector=null,this.reusableBox3=null,this.onSelectionChange=null,this.onTransformChange=null}updateDeformedObjects(e){if(!e||0===e.length)return;const t=[];e.forEach(e=>{e&&e.geometry&&this.selectableObjects.includes(e)&&e.geometry.userData&&e.geometry.userData.needsBVHUpdate&&t.push(e)}),t.length>0&&(console.log(`正在更新 ${t.length} 个对象的BVH`),this.raycaster.updateMultipleBVH(t)),this.updateSelectionProxyIfNeeded()}updateSelectionProxyIfNeeded(){this.selectedObjects.length>1&&this.transformControls.object===this.selectionProxy&&this.selectionProxy.targetObjects.length>0&&(this.selectionProxy.setTargets(this.selectedObjects),this.selectedObjects.forEach(e=>{this._updateObjectHighlight(e)}))}refreshSelectionProxy(){this.updateSelectionProxyIfNeeded()}}const fo=new WeakMap;class mo extends X{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,n,r){const i=new q(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,e=>{this.parse(e,t,r)},n,r)}parse(e,t,n=()=>{}){this.decodeDracoFile(e,t,null,null,Y).catch(n)}decodeDracoFile(e,t,n,r,i=o,a=()=>{}){const s={attributeIDs:n||this.defaultAttributeIDs,attributeTypes:r||this.defaultAttributeTypes,useUniqueIDs:!!n,vertexColorSpace:i};return this.decodeGeometry(e,s).then(t).catch(a)}decodeGeometry(e,t){const n=JSON.stringify(t);if(fo.has(e)){const t=fo.get(e);if(t.key===n)return t.promise;if(0===e.byteLength)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let r;const i=this.workerNextTaskID++,o=e.byteLength,a=this._getWorker(i,o).then(n=>(r=n,new Promise((n,o)=>{r._callbacks[i]={resolve:n,reject:o},r.postMessage({type:"decode",id:i,taskConfig:t,buffer:e},[e])}))).then(e=>this._createGeometry(e.geometry));return a.catch(()=>!0).then(()=>{r&&i&&this._releaseTask(r,i)}),fo.set(e,{key:n,promise:a}),a}_createGeometry(e){const t=new O;e.index&&t.setIndex(new j(e.index.array,1));for(let n=0;n<e.attributes.length;n++){const r=e.attributes[n],i=r.name,o=r.array,a=r.itemSize,s=new j(o,a);"color"===i&&(this._assignVertexColorSpace(s,r.vertexColorSpace),s.normalized=o instanceof Float32Array==!1),t.setAttribute(i,s)}return t}_assignVertexColorSpace(e,t){if(t!==Y)return;const n=new K;for(let t=0,r=e.count;t<r;t++)n.fromBufferAttribute(e,t).convertSRGBToLinear(),e.setXYZ(t,n.r,n.g,n.b)}_loadLibrary(e,t){const n=new q(this.manager);return n.setPath(this.decoderPath),n.setResponseType(t),n.setWithCredentials(this.withCredentials),new Promise((t,r)=>{n.load(e,t,void 0,r)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e="object"!=typeof WebAssembly||"js"===this.decoderConfig.type,t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(t=>{const n=t[0];e||(this.decoderConfig.wasmBinary=t[1]);const r=go.toString(),i=["/* draco decoder */",n,"","/* worker */",r.substring(r.indexOf("{")+1,r.lastIndexOf("}"))].join("\n");this.workerSourceURL=URL.createObjectURL(new Blob([i]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.length<this.workerLimit){const e=new Worker(this.workerSourceURL);e._callbacks={},e._taskCosts={},e._taskLoad=0,e.postMessage({type:"init",decoderConfig:this.decoderConfig}),e.onmessage=function(t){const n=t.data;switch(n.type){case"decode":e._callbacks[n.id].resolve(n);break;case"error":e._callbacks[n.id].reject(n);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+n.type+'"')}},this.workerPool.push(e)}else this.workerPool.sort(function(e,t){return e._taskLoad>t._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,""!==this.workerSourceURL&&URL.revokeObjectURL(this.workerSourceURL),this}}function go(){let e,t;function n(e,t,n,r,i,o){const a=o.num_components(),s=n.num_points()*a,c=s*i.BYTES_PER_ELEMENT,l=function(e,t){switch(t){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32}}(e,i),u=e._malloc(c);t.GetAttributeDataArrayForAllPoints(n,o,l,c,u);const h=new i(e.HEAPF32.buffer,u,s).slice();return e._free(u),{name:r,array:h,itemSize:a}}onmessage=function(r){const i=r.data;switch(i.type){case"init":e=i.decoderConfig,t=new Promise(function(t){e.onModuleLoaded=function(e){t({draco:e})},DracoDecoderModule(e)});break;case"decode":const r=i.buffer,o=i.taskConfig;t.then(e=>{const t=e.draco,a=new t.Decoder;try{const e=function(e,t,r,i){const o=i.attributeIDs,a=i.attributeTypes;let s,c;const l=t.GetEncodedGeometryType(r);if(l===e.TRIANGULAR_MESH)s=new e.Mesh,c=t.DecodeArrayToMesh(r,r.byteLength,s);else{if(l!==e.POINT_CLOUD)throw new Error("THREE.DRACOLoader: Unexpected geometry type.");s=new e.PointCloud,c=t.DecodeArrayToPointCloud(r,r.byteLength,s)}if(!c.ok()||0===s.ptr)throw new Error("THREE.DRACOLoader: Decoding failed: "+c.error_msg());const u={index:null,attributes:[]};for(const r in o){const c=self[a[r]];let l,h;if(i.useUniqueIDs)h=o[r],l=t.GetAttributeByUniqueId(s,h);else{if(h=t.GetAttributeId(s,e[o[r]]),-1===h)continue;l=t.GetAttribute(s,h)}const d=n(e,t,s,r,c,l);"color"===r&&(d.vertexColorSpace=i.vertexColorSpace),u.attributes.push(d)}l===e.TRIANGULAR_MESH&&(u.index=function(e,t,n){const r=n.num_faces(),i=3*r,o=4*i,a=e._malloc(o);t.GetTrianglesUInt32Array(n,o,a);const s=new Uint32Array(e.HEAPF32.buffer,a,i).slice();return e._free(a),{array:s,itemSize:1}}(e,t,s));return e.destroy(s),u}(t,a,new Int8Array(r),o),s=e.attributes.map(e=>e.array.buffer);e.index&&s.push(e.index.array.buffer),self.postMessage({type:"decode",id:i.id,geometry:e},s)}catch(e){console.error(e),self.postMessage({type:"error",id:i.id,error:e.message})}finally{t.destroy(a)}})}}}function bo(e,t){if(t===Q)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t===Z||t===$){let n=e.getIndex();if(null===n){const t=[],r=e.getAttribute("position");if(void 0===r)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}const r=n.count-2,i=[];if(t===Z)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));i.length/3!==r&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const o=e.clone();return o.setIndex(i),o.clearGroups(),o}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e}class yo extends X{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new Ao(e)}),this.register(function(e){return new _o(e)}),this.register(function(e){return new No(e)}),this.register(function(e){return new Lo(e)}),this.register(function(e){return new Oo(e)}),this.register(function(e){return new ko(e)}),this.register(function(e){return new So(e)}),this.register(function(e){return new Ro(e)}),this.register(function(e){return new To(e)}),this.register(function(e){return new Mo(e)}),this.register(function(e){return new Co(e)}),this.register(function(e){return new Po(e)}),this.register(function(e){return new Io(e)}),this.register(function(e){return new wo(e)}),this.register(function(e){return new Do(e)}),this.register(function(e){return new jo(e)})}load(e,t,n,r){const i=this;let o;if(""!==this.resourcePath)o=this.resourcePath;else if(""!==this.path){const t=J.extractUrlBase(e);o=J.resolveURL(t,this.path)}else o=J.extractUrlBase(e);this.manager.itemStart(e);const a=function(t){r?r(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},s=new q(this.manager);s.setPath(this.path),s.setResponseType("arraybuffer"),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,function(n){try{i.parse(n,o,function(n){t(n),i.manager.itemEnd(e)},a)}catch(e){a(e)}},n,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i;const o={},a={},s=new TextDecoder;if("string"==typeof e)i=JSON.parse(e);else if(e instanceof ArrayBuffer){if(s.decode(new Uint8Array(e,0,4))===Fo){try{o[xo.KHR_BINARY_GLTF]=new zo(e)}catch(e){return void(r&&r(e))}i=JSON.parse(o[xo.KHR_BINARY_GLTF].content)}else i=JSON.parse(s.decode(e))}else i=e;if(void 0===i.asset||i.asset.version[0]<2)return void(r&&r(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const c=new pa(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](c);t.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[t.name]=t,o[t.name]=!0}if(i.extensionsUsed)for(let e=0;e<i.extensionsUsed.length;++e){const t=i.extensionsUsed[e],n=i.extensionsRequired||[];switch(t){case xo.KHR_MATERIALS_UNLIT:o[t]=new Eo;break;case xo.KHR_DRACO_MESH_COMPRESSION:o[t]=new Ho(i,this.dracoLoader);break;case xo.KHR_TEXTURE_TRANSFORM:o[t]=new Vo;break;case xo.KHR_MESH_QUANTIZATION:o[t]=new Go;break;default:n.indexOf(t)>=0&&void 0===a[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}c.setExtensions(o),c.setPlugins(a),c.parse(n,r)}parseAsync(e,t){const n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}}function vo(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const xo={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class wo{constructor(e){this.parser=e,this.name=xo.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){const r=t[n];r.extensions&&r.extensions[this.name]&&void 0!==r.extensions[this.name].light&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){const t=this.parser,n="light:"+e;let r=t.cache.get(n);if(r)return r;const i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let s;const c=new K(16777215);void 0!==a.color&&c.setRGB(a.color[0],a.color[1],a.color[2],o);const l=void 0!==a.range?a.range:0;switch(a.type){case"directional":s=new re(c),s.target.position.set(0,0,-1),s.add(s.target);break;case"point":s=new ne(c),s.distance=l;break;case"spot":s=new te(c),s.distance=l,a.spot=a.spot||{},a.spot.innerConeAngle=void 0!==a.spot.innerConeAngle?a.spot.innerConeAngle:0,a.spot.outerConeAngle=void 0!==a.spot.outerConeAngle?a.spot.outerConeAngle:Math.PI/4,s.angle=a.spot.outerConeAngle,s.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,s.target.position.set(0,0,-1),s.add(s.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return s.position.set(0,0,0),s.decay=2,sa(s,a),void 0!==a.intensity&&(s.intensity=a.intensity),s.name=t.createUniqueName(a.name||"light_"+e),r=Promise.resolve(s),t.cache.add(n,r),r}getDependency(e,t){if("light"===e)return this._loadLight(t)}createNodeAttachment(e){const t=this,n=this.parser,r=n.json.nodes[e],i=(r.extensions&&r.extensions[this.name]||{}).light;return void 0===i?null:this._loadLight(i).then(function(e){return n._getNodeRef(t.cache,i,e)})}}class Eo{constructor(){this.name=xo.KHR_MATERIALS_UNLIT}getMaterialType(){return E}extendParams(e,t,n){const r=[];e.color=new K(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const t=i.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],o),e.opacity=t[3]}void 0!==i.baseColorTexture&&r.push(n.assignTexture(e,"map",i.baseColorTexture,Y))}return Promise.all(r)}}class To{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=n.extensions[this.name].emissiveStrength;return void 0!==r&&(t.emissiveIntensity=r),Promise.resolve()}}class Ao{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];if(void 0!==o.clearcoatFactor&&(t.clearcoat=o.clearcoatFactor),void 0!==o.clearcoatTexture&&i.push(n.assignTexture(t,"clearcoatMap",o.clearcoatTexture)),void 0!==o.clearcoatRoughnessFactor&&(t.clearcoatRoughness=o.clearcoatRoughnessFactor),void 0!==o.clearcoatRoughnessTexture&&i.push(n.assignTexture(t,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),void 0!==o.clearcoatNormalTexture&&(i.push(n.assignTexture(t,"clearcoatNormalMap",o.clearcoatNormalTexture)),void 0!==o.clearcoatNormalTexture.scale)){const e=o.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new v(e,e)}return Promise.all(i)}}class Co{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];return void 0!==o.iridescenceFactor&&(t.iridescence=o.iridescenceFactor),void 0!==o.iridescenceTexture&&i.push(n.assignTexture(t,"iridescenceMap",o.iridescenceTexture)),void 0!==o.iridescenceIor&&(t.iridescenceIOR=o.iridescenceIor),void 0===t.iridescenceThicknessRange&&(t.iridescenceThicknessRange=[100,400]),void 0!==o.iridescenceThicknessMinimum&&(t.iridescenceThicknessRange[0]=o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&(t.iridescenceThicknessRange[1]=o.iridescenceThicknessMaximum),void 0!==o.iridescenceThicknessTexture&&i.push(n.assignTexture(t,"iridescenceThicknessMap",o.iridescenceThicknessTexture)),Promise.all(i)}}class Oo{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_SHEEN}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[];t.sheenColor=new K(0,0,0),t.sheenRoughness=0,t.sheen=1;const a=r.extensions[this.name];if(void 0!==a.sheenColorFactor){const e=a.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],o)}return void 0!==a.sheenRoughnessFactor&&(t.sheenRoughness=a.sheenRoughnessFactor),void 0!==a.sheenColorTexture&&i.push(n.assignTexture(t,"sheenColorMap",a.sheenColorTexture,Y)),void 0!==a.sheenRoughnessTexture&&i.push(n.assignTexture(t,"sheenRoughnessMap",a.sheenRoughnessTexture)),Promise.all(i)}}class ko{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&i.push(n.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(i)}}class So{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_VOLUME}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],a=r.extensions[this.name];t.thickness=void 0!==a.thicknessFactor?a.thicknessFactor:0,void 0!==a.thicknessTexture&&i.push(n.assignTexture(t,"thicknessMap",a.thicknessTexture)),t.attenuationDistance=a.attenuationDistance||1/0;const s=a.attenuationColor||[1,1,1];return t.attenuationColor=(new K).setRGB(s[0],s[1],s[2],o),Promise.all(i)}}class Ro{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_IOR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=n.extensions[this.name];return t.ior=void 0!==r.ior?r.ior:1.5,Promise.resolve()}}class Mo{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_SPECULAR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],a=r.extensions[this.name];t.specularIntensity=void 0!==a.specularFactor?a.specularFactor:1,void 0!==a.specularTexture&&i.push(n.assignTexture(t,"specularIntensityMap",a.specularTexture));const s=a.specularColorFactor||[1,1,1];return t.specularColor=(new K).setRGB(s[0],s[1],s[2],o),void 0!==a.specularColorTexture&&i.push(n.assignTexture(t,"specularColorMap",a.specularColorTexture,Y)),Promise.all(i)}}class Io{constructor(e){this.parser=e,this.name=xo.EXT_MATERIALS_BUMP}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];return t.bumpScale=void 0!==o.bumpFactor?o.bumpFactor:1,void 0!==o.bumpTexture&&i.push(n.assignTexture(t,"bumpMap",o.bumpTexture)),Promise.all(i)}}class Po{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];return void 0!==o.anisotropyStrength&&(t.anisotropy=o.anisotropyStrength),void 0!==o.anisotropyRotation&&(t.anisotropyRotation=o.anisotropyRotation),void 0!==o.anisotropyTexture&&i.push(n.assignTexture(t,"anisotropyMap",o.anisotropyTexture)),Promise.all(i)}}class _o{constructor(e){this.parser=e,this.name=xo.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;const i=r.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,o)}}class No{constructor(e){this.parser=e,this.name=xo.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],a=r.images[o.source];let s=n.textureLoader;if(a.uri){const e=n.options.manager.getHandler(a.uri);null!==e&&(s=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,s);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class Lo{constructor(e){this.parser=e,this.name=xo.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],a=r.images[o.source];let s=n.textureLoader;if(a.uri){const e=n.options.manager.getHandler(a.uri);null!==e&&(s=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,s);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class Do{constructor(e){this.name=xo.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){const e=n.extensions[this.name],r=this.parser.getDependency("buffer",e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return r.then(function(t){const n=e.byteOffset||0,r=e.byteLength||0,o=e.count,a=e.byteStride,s=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(o,a,s,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){const t=new ArrayBuffer(o*a);return i.decodeGltfBuffer(new Uint8Array(t),o,a,s,e.mode,e.filter),t})})}return null}}class jo{constructor(e){this.name=xo.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||void 0===n.mesh)return null;const r=t.meshes[n.mesh];for(const e of r.primitives)if(e.mode!==Yo.TRIANGLES&&e.mode!==Yo.TRIANGLE_STRIP&&e.mode!==Yo.TRIANGLE_FAN&&void 0!==e.mode)return null;const i=n.extensions[this.name].attributes,o=[],a={};for(const e in i)o.push(this.parser.getDependency("accessor",i[e]).then(t=>(a[e]=t,a[e])));return o.length<1?null:(o.push(this.parser.createNodeMesh(e)),Promise.all(o).then(e=>{const t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(const e of n){const t=new N,n=new f,o=new y,s=new f(1,1,1),c=new ie(e.geometry,e.material,r);for(let e=0;e<r;e++)a.TRANSLATION&&n.fromBufferAttribute(a.TRANSLATION,e),a.ROTATION&&o.fromBufferAttribute(a.ROTATION,e),a.SCALE&&s.fromBufferAttribute(a.SCALE,e),c.setMatrixAt(e,t.compose(n,o,s));for(const t in a)if("_COLOR_0"===t){const e=a[t];c.instanceColor=new oe(e.array,e.itemSize,e.normalized)}else"TRANSLATION"!==t&&"ROTATION"!==t&&"SCALE"!==t&&e.geometry.setAttribute(t,a[t]);x.prototype.copy.call(c,e),this.parser.assignFinalMaterial(c),i.push(c)}return t.isGroup?(t.clear(),t.add(...i),t):i[0]}))}}const Fo="glTF",Uo=1313821514,Bo=5130562;class zo{constructor(e){this.name=xo.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,12),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==Fo)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-12,i=new DataView(e,12);let o=0;for(;o<r;){const t=i.getUint32(o,!0);o+=4;const r=i.getUint32(o,!0);if(o+=4,r===Uo){const r=new Uint8Array(e,12+o,t);this.content=n.decode(r)}else if(r===Bo){const n=12+o;this.body=e.slice(n,n+t)}o+=t}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Ho{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=xo.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,s={},c={},l={};for(const e in a){const t=Jo[e]||e.toLowerCase();s[t]=a[e]}for(const t in e.attributes){const r=Jo[t]||t.toLowerCase();if(void 0!==a[t]){const i=n.accessors[e.attributes[t]],o=Ko[i.componentType];l[r]=o.name,c[r]=!0===i.normalized}}return t.getDependency("bufferView",i).then(function(e){return new Promise(function(t,n){r.decodeDracoFile(e,function(e){for(const t in e.attributes){const n=e.attributes[t],r=c[t];void 0!==r&&(n.normalized=r)}t(e)},s,l,o,n)})})}}class Vo{constructor(){this.name=xo.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&t.texCoord!==e.channel||void 0!==t.offset||void 0!==t.rotation||void 0!==t.scale?(e=e.clone(),void 0!==t.texCoord&&(e.channel=t.texCoord),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e):e}}class Go{constructor(){this.name=xo.KHR_MESH_QUANTIZATION}}class Wo extends Ue{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){const t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r*3+r;for(let e=0;e!==r;e++)t[e]=n[i+e];return t}interpolate_(e,t,n,r){const i=this.resultBuffer,o=this.sampleValues,a=this.valueSize,s=2*a,c=3*a,l=r-t,u=(n-t)/l,h=u*u,d=h*u,p=e*c,f=p-c,m=-2*d+3*h,g=d-h,b=1-m,y=g-h+u;for(let e=0;e!==a;e++){const t=o[f+e+a],n=o[f+e+s]*l,r=o[p+e+a],c=o[p+e]*l;i[e]=b*t+y*n+m*r+g*c}return i}}const Xo=new y;class qo extends Wo{interpolate_(e,t,n,r){const i=super.interpolate_(e,t,n,r);return Xo.fromArray(i).normalize().toArray(i),i}}const Yo={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Ko={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Qo={9728:fe,9729:c,9984:pe,9985:de,9986:he,9987:ue},Zo={33071:be,33648:ge,10497:me},$o={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Jo={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},ea={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},ta={CUBICSPLINE:void 0,LINEAR:_e,STEP:Pe},na="OPAQUE",ra="MASK",ia="BLEND";function oa(e){return void 0===e.DefaultMaterial&&(e.DefaultMaterial=new xe({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:G})),e.DefaultMaterial}function aa(e,t,n){for(const r in n.extensions)void 0===e[r]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=n.extensions[r])}function sa(e,t){void 0!==t.extras&&("object"==typeof t.extras?Object.assign(e.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function ca(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let n=0,r=t.weights.length;n<r;n++)e.morphTargetInfluences[n]=t.weights[n];if(t.extras&&Array.isArray(t.extras.targetNames)){const n=t.extras.targetNames;if(e.morphTargetInfluences.length===n.length){e.morphTargetDictionary={};for(let t=0,r=n.length;t<r;t++)e.morphTargetDictionary[n[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function la(e){let t;const n=e.extensions&&e.extensions[xo.KHR_DRACO_MESH_COMPRESSION];if(t=n?"draco:"+n.bufferView+":"+n.indices+":"+ua(n.attributes):e.indices+":"+ua(e.attributes)+":"+e.mode,void 0!==e.targets)for(let n=0,r=e.targets.length;n<r;n++)t+=":"+ua(e.targets[n]);return t}function ua(e){let t="";const n=Object.keys(e).sort();for(let r=0,i=n.length;r<i;r++)t+=n[r]+":"+e[n[r]]+";";return t}function ha(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}const da=new N;class pa{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new vo,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=!1,i=-1;"undefined"!=typeof navigator&&(n=!0===/^((?!chrome|android).)*safari/i.test(navigator.userAgent),r=navigator.userAgent.indexOf("Firefox")>-1,i=r?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),"undefined"==typeof createImageBitmap||n||r&&i<98?this.textureLoader=new ae(this.options.manager):this.textureLoader=new se(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new q(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(t){const o={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return aa(i,o,r),sa(o,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(o)})).then(function(){e(o)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n<r;n++){const r=t[n].joints;for(let t=0,n=r.length;t<n;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){const r=e[t];void 0!==r.mesh&&(this._addNodeRef(this.meshCache,r.mesh),void 0!==r.skin&&(n[r.mesh].isSkinnedMesh=!0)),void 0!==r.camera&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;const r=n.clone(),i=(e,t)=>{const n=this.associations.get(e);null!=n&&this.associations.set(t,n);for(const[n,r]of e.children.entries())i(r,t.children[n])};return i(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){const r=e(t[n]);if(r)return r}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const n=[];for(let r=0;r<t.length;r++){const i=e(t[r]);i&&n.push(i)}return n}getDependency(e,t){const n=e+":"+t;let r=this.cache.get(n);if(!r){switch(e){case"scene":r=this.loadScene(t);break;case"node":r=this._invokeOne(function(e){return e.loadNode&&e.loadNode(t)});break;case"mesh":r=this._invokeOne(function(e){return e.loadMesh&&e.loadMesh(t)});break;case"accessor":r=this.loadAccessor(t);break;case"bufferView":r=this._invokeOne(function(e){return e.loadBufferView&&e.loadBufferView(t)});break;case"buffer":r=this.loadBuffer(t);break;case"material":r=this._invokeOne(function(e){return e.loadMaterial&&e.loadMaterial(t)});break;case"texture":r=this._invokeOne(function(e){return e.loadTexture&&e.loadTexture(t)});break;case"skin":r=this.loadSkin(t);break;case"animation":r=this._invokeOne(function(e){return e.loadAnimation&&e.loadAnimation(t)});break;case"camera":r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!r)throw new Error("Unknown type: "+e)}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){const n=this,r=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(r.map(function(t,r){return n.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],n=this.fileLoader;if(t.type&&"arraybuffer"!==t.type)throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(void 0===t.uri&&0===e)return Promise.resolve(this.extensions[xo.KHR_BINARY_GLTF].body);const r=this.options;return new Promise(function(e,i){n.load(J.resolveURL(t.uri,r.path),e,void 0,function(){i(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(e){const n=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+n)})}loadAccessor(e){const t=this,n=this.json,r=this.json.accessors[e];if(void 0===r.bufferView&&void 0===r.sparse){const e=$o[r.type],t=Ko[r.componentType],n=!0===r.normalized,i=new t(r.count*e);return Promise.resolve(new j(i,e,n))}const i=[];return void 0!==r.bufferView?i.push(this.getDependency("bufferView",r.bufferView)):i.push(null),void 0!==r.sparse&&(i.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(i).then(function(e){const i=e[0],o=$o[r.type],a=Ko[r.componentType],s=a.BYTES_PER_ELEMENT,c=s*o,l=r.byteOffset||0,u=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,h=!0===r.normalized;let d,p;if(u&&u!==c){const e=Math.floor(l/u),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+e+":"+r.count;let c=t.cache.get(n);c||(d=new a(i,e*u,r.count*u/s),c=new ce(d,u/s),t.cache.add(n,c)),p=new le(c,o,l%u/s,h)}else d=null===i?new a(r.count*o):new a(i,l,r.count*o),p=new j(d,o,h);if(void 0!==r.sparse){const t=$o.SCALAR,n=Ko[r.sparse.indices.componentType],s=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,l=new n(e[1],s,r.sparse.count*t),u=new a(e[2],c,r.sparse.count*o);null!==i&&(p=new j(p.array.slice(),p.itemSize,p.normalized));for(let e=0,t=l.length;e<t;e++){const t=l[e];if(p.setX(t,u[e*o]),o>=2&&p.setY(t,u[e*o+1]),o>=3&&p.setZ(t,u[e*o+2]),o>=4&&p.setW(t,u[e*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return p})}loadTexture(e){const t=this.json,n=this.options,r=t.textures[e].source,i=t.images[r];let o=this.textureLoader;if(i.uri){const e=n.manager.getHandler(i.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(e,t,n){const r=this,i=this.json,o=i.textures[e],a=i.images[t],s=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[s])return this.textureCache[s];const l=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=o.name||a.name||"",""===t.name&&"string"==typeof a.uri&&!1===a.uri.startsWith("data:image/")&&(t.name=a.uri);const n=(i.samplers||{})[o.sampler]||{};return t.magFilter=Qo[n.magFilter]||c,t.minFilter=Qo[n.minFilter]||ue,t.wrapS=Zo[n.wrapS]||me,t.wrapT=Zo[n.wrapT]||me,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[s]=l,l}loadImageSource(e,t){const n=this,r=this.json,i=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());const o=r.images[e],a=self.URL||self.webkitURL;let s=o.uri||"",c=!1;if(void 0!==o.bufferView)s=n.getDependency("bufferView",o.bufferView).then(function(e){c=!0;const t=new Blob([e],{type:o.mimeType});return s=a.createObjectURL(t),s});else if(void 0===o.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const l=Promise.resolve(s).then(function(e){return new Promise(function(n,r){let o=n;!0===t.isImageBitmapLoader&&(o=function(e){const t=new Ne(e);t.needsUpdate=!0,n(t)}),t.load(J.resolveURL(e,i.path),o,void 0,r)})}).then(function(e){var t;return!0===c&&a.revokeObjectURL(s),e.userData.mimeType=o.mimeType||((t=o.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){const i=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(void 0!==n.texCoord&&n.texCoord>0&&((o=o.clone()).channel=n.texCoord),i.extensions[xo.KHR_TEXTURE_TRANSFORM]){const e=void 0!==n.extensions?n.extensions[xo.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=i.associations.get(o);o=i.extensions[xo.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),i.associations.set(o,t)}}return void 0!==r&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let n=e.material;const r=void 0===t.attributes.tangent,i=void 0!==t.attributes.color,o=void 0===t.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+n.uuid;let t=this.cache.get(e);t||(t=new ye,ve.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){const e="LineBasicMaterial:"+n.uuid;let t=this.cache.get(e);t||(t=new T,ve.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||o){let e="ClonedMaterial:"+n.uuid+":";r&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),o&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return xe}loadMaterial(e){const t=this,n=this.json,r=this.extensions,i=n.materials[e];let a;const s={},c=[];if((i.extensions||{})[xo.KHR_MATERIALS_UNLIT]){const e=r[xo.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),c.push(e.extendParams(s,i,t))}else{const n=i.pbrMetallicRoughness||{};if(s.color=new K(1,1,1),s.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;s.color.setRGB(e[0],e[1],e[2],o),s.opacity=e[3]}void 0!==n.baseColorTexture&&c.push(t.assignTexture(s,"map",n.baseColorTexture,Y)),s.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,s.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(c.push(t.assignTexture(s,"metalnessMap",n.metallicRoughnessTexture)),c.push(t.assignTexture(s,"roughnessMap",n.metallicRoughnessTexture))),a=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,s)})))}!0===i.doubleSided&&(s.side=D);const l=i.alphaMode||na;if(l===ia?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,l===ra&&(s.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&a!==E&&(c.push(t.assignTexture(s,"normalMap",i.normalTexture)),s.normalScale=new v(1,1),void 0!==i.normalTexture.scale)){const e=i.normalTexture.scale;s.normalScale.set(e,e)}if(void 0!==i.occlusionTexture&&a!==E&&(c.push(t.assignTexture(s,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(s.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&a!==E){const e=i.emissiveFactor;s.emissive=(new K).setRGB(e[0],e[1],e[2],o)}return void 0!==i.emissiveTexture&&a!==E&&c.push(t.assignTexture(s,"emissiveMap",i.emissiveTexture,Y)),Promise.all(c).then(function(){const n=new a(s);return i.name&&(n.name=i.name),sa(n,i),t.associations.set(n,{materials:e}),i.extensions&&aa(r,n,i),n})}createUniqueName(e){const t=we.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,n=this.extensions,r=this.primitiveCache;function i(e){return n[xo.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then(function(n){return fa(n,e,t)})}const o=[];for(let n=0,a=e.length;n<a;n++){const a=e[n],s=la(a),c=r[s];if(c)o.push(c.promise);else{let e;e=a.extensions&&a.extensions[xo.KHR_DRACO_MESH_COMPRESSION]?i(a):fa(new O,a,t),r[s]={primitive:a,promise:e},o.push(e)}}return Promise.all(o)}loadMesh(e){const t=this,n=this.json,r=this.extensions,i=n.meshes[e],o=i.primitives,a=[];for(let e=0,t=o.length;e<t;e++){const t=void 0===o[e].material?oa(this.cache):this.getDependency("material",o[e].material);a.push(t)}return a.push(t.loadGeometries(o)),Promise.all(a).then(function(n){const a=n.slice(0,n.length-1),s=n[n.length-1],c=[];for(let n=0,l=s.length;n<l;n++){const l=s[n],u=o[n];let h;const d=a[n];if(u.mode===Yo.TRIANGLES||u.mode===Yo.TRIANGLE_STRIP||u.mode===Yo.TRIANGLE_FAN||void 0===u.mode)h=!0===i.isSkinnedMesh?new Ee(l,d):new S(l,d),!0===h.isSkinnedMesh&&h.normalizeSkinWeights(),u.mode===Yo.TRIANGLE_STRIP?h.geometry=bo(h.geometry,$):u.mode===Yo.TRIANGLE_FAN&&(h.geometry=bo(h.geometry,Z));else if(u.mode===Yo.LINES)h=new Te(l,d);else if(u.mode===Yo.LINE_STRIP)h=new M(l,d);else if(u.mode===Yo.LINE_LOOP)h=new Ae(l,d);else{if(u.mode!==Yo.POINTS)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+u.mode);h=new Ce(l,d)}Object.keys(h.geometry.morphAttributes).length>0&&ca(h,i),h.name=t.createUniqueName(i.name||"mesh_"+e),sa(h,i),u.extensions&&aa(r,h,u),t.assignFinalMaterial(h),c.push(h)}for(let n=0,r=c.length;n<r;n++)t.associations.set(c[n],{meshes:e,primitives:n});if(1===c.length)return i.extensions&&aa(r,c[0],i),c[0];const l=new Oe;i.extensions&&aa(r,l,i),t.associations.set(l,{meshes:e});for(let e=0,t=c.length;e<t;e++)l.add(c[e]);return l})}loadCamera(e){let t;const n=this.json.cameras[e],r=n[n.type];if(r)return"perspective"===n.type?t=new ke(d.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(t=new Se(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),sa(t,n),Promise.resolve(t);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],n=[];for(let e=0,r=t.joints.length;e<r;e++)n.push(this._loadNodeShallow(t.joints[e]));return void 0!==t.inverseBindMatrices?n.push(this.getDependency("accessor",t.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(e){const n=e.pop(),r=e,i=[],o=[];for(let e=0,a=r.length;e<a;e++){const a=r[e];if(a){i.push(a);const t=new N;null!==n&&t.fromArray(n.array,16*e),o.push(t)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[e])}return new Re(i,o)})}loadAnimation(e){const t=this.json,n=this,r=t.animations[e],i=r.name?r.name:"animation_"+e,o=[],a=[],s=[],c=[],l=[];for(let e=0,t=r.channels.length;e<t;e++){const t=r.channels[e],n=r.samplers[t.sampler],i=t.target,u=i.node,h=void 0!==r.parameters?r.parameters[n.input]:n.input,d=void 0!==r.parameters?r.parameters[n.output]:n.output;void 0!==i.node&&(o.push(this.getDependency("node",u)),a.push(this.getDependency("accessor",h)),s.push(this.getDependency("accessor",d)),c.push(n),l.push(i))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(s),Promise.all(c),Promise.all(l)]).then(function(e){const t=e[0],r=e[1],o=e[2],a=e[3],s=e[4],c=[];for(let e=0,i=t.length;e<i;e++){const i=t[e],l=r[e],u=o[e],h=a[e],d=s[e];if(void 0===i)continue;i.updateMatrix&&i.updateMatrix();const p=n._createAnimationTracks(i,l,u,h,d);if(p)for(let e=0;e<p.length;e++)c.push(p[e])}return new Me(i,void 0,c)})}createNodeMesh(e){const t=this.json,n=this,r=t.nodes[e];return void 0===r.mesh?null:n.getDependency("mesh",r.mesh).then(function(e){const t=n._getNodeRef(n.meshCache,r.mesh,e);return void 0!==r.weights&&t.traverse(function(e){if(e.isMesh)for(let t=0,n=r.weights.length;t<n;t++)e.morphTargetInfluences[t]=r.weights[t]}),t})}loadNode(e){const t=this,n=this.json.nodes[e],r=t._loadNodeShallow(e),i=[],o=n.children||[];for(let e=0,n=o.length;e<n;e++)i.push(t.getDependency("node",o[e]));const a=void 0===n.skin?Promise.resolve(null):t.getDependency("skin",n.skin);return Promise.all([r,Promise.all(i),a]).then(function(e){const t=e[0],n=e[1],r=e[2];null!==r&&t.traverse(function(e){e.isSkinnedMesh&&e.bind(r,da)});for(let e=0,r=n.length;e<r;e++)t.add(n[e]);return t})}_loadNodeShallow(e){const t=this.json,n=this.extensions,r=this;if(void 0!==this.nodeCache[e])return this.nodeCache[e];const i=t.nodes[e],o=i.name?r.createUniqueName(i.name):"",a=[],s=r._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return s&&a.push(s),void 0!==i.camera&&a.push(r.getDependency("camera",i.camera).then(function(e){return r._getNodeRef(r.cameraCache,i.camera,e)})),r._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){a.push(e)}),this.nodeCache[e]=Promise.all(a).then(function(t){let a;if(a=!0===i.isBone?new Ie:t.length>1?new Oe:1===t.length?t[0]:new x,a!==t[0])for(let e=0,n=t.length;e<n;e++)a.add(t[e]);if(i.name&&(a.userData.name=i.name,a.name=o),sa(a,i),i.extensions&&aa(n,a,i),void 0!==i.matrix){const e=new N;e.fromArray(i.matrix),a.applyMatrix4(e)}else void 0!==i.translation&&a.position.fromArray(i.translation),void 0!==i.rotation&&a.quaternion.fromArray(i.rotation),void 0!==i.scale&&a.scale.fromArray(i.scale);return r.associations.has(a)||r.associations.set(a,{}),r.associations.get(a).nodes=e,a}),this.nodeCache[e]}loadScene(e){const t=this.extensions,n=this.json.scenes[e],r=this,i=new Oe;n.name&&(i.name=r.createUniqueName(n.name)),sa(i,n),n.extensions&&aa(t,i,n);const o=n.nodes||[],a=[];for(let e=0,t=o.length;e<t;e++)a.push(r.getDependency("node",o[e]));return Promise.all(a).then(function(e){for(let t=0,n=e.length;t<n;t++)i.add(e[t]);return r.associations=(e=>{const t=new Map;for(const[e,n]of r.associations)(e instanceof ve||e instanceof Ne)&&t.set(e,n);return e.traverse(e=>{const n=r.associations.get(e);null!=n&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){const o=[],a=e.name?e.name:e.uuid,s=[];let c;switch(ea[i.path]===ea.weights?e.traverse(function(e){e.morphTargetInfluences&&s.push(e.name?e.name:e.uuid)}):s.push(a),ea[i.path]){case ea.weights:c=De;break;case ea.rotation:c=je;break;case ea.position:case ea.scale:c=Le;break;default:if(1===n.itemSize)c=De;else c=Le}const l=void 0!==r.interpolation?ta[r.interpolation]:_e,u=this._getArrayFromAccessor(n);for(let e=0,n=s.length;e<n;e++){const n=new c(s[e]+"."+ea[i.path],t.array,u,l);"CUBICSPLINE"===r.interpolation&&this._createCubicSplineTrackInterpolant(n),o.push(n)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const e=ha(t.constructor),n=new Float32Array(t.length);for(let r=0,i=t.length;r<i;r++)n[r]=t[r]*e;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof je?qo:Wo)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function fa(e,t,n){const r=t.attributes,i=[];function a(t,r){return n.getDependency("accessor",t).then(function(t){e.setAttribute(r,t)})}for(const t in r){const n=Jo[t]||t.toLowerCase();n in e.attributes||i.push(a(r[t],n))}if(void 0!==t.indices&&!e.index){const r=n.getDependency("accessor",t.indices).then(function(t){e.setIndex(t)});i.push(r)}return Fe.workingColorSpace!==o&&"COLOR_0"in r&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Fe.workingColorSpace}" not supported.`),sa(e,t),function(e,t,n){const r=t.attributes,i=new z;if(void 0===r.POSITION)return;{const e=n.json.accessors[r.POSITION],t=e.min,o=e.max;if(void 0===t||void 0===o)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(i.set(new f(t[0],t[1],t[2]),new f(o[0],o[1],o[2])),e.normalized){const t=ha(Ko[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}const o=t.targets;if(void 0!==o){const e=new f,t=new f;for(let r=0,i=o.length;r<i;r++){const i=o[r];if(void 0!==i.POSITION){const r=n.json.accessors[i.POSITION],o=r.min,a=r.max;if(void 0!==o&&void 0!==a){if(t.setX(Math.max(Math.abs(o[0]),Math.abs(a[0]))),t.setY(Math.max(Math.abs(o[1]),Math.abs(a[1]))),t.setZ(Math.max(Math.abs(o[2]),Math.abs(a[2]))),r.normalized){const e=ha(Ko[r.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}i.expandByVector(e)}e.boundingBox=i;const a=new B;i.getCenter(a.center),a.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=a}(e,t,n),Promise.all(i).then(function(){return void 0!==t.targets?function(e,t,n){let r=!1,i=!1,o=!1;for(let e=0,n=t.length;e<n;e++){const n=t[e];if(void 0!==n.POSITION&&(r=!0),void 0!==n.NORMAL&&(i=!0),void 0!==n.COLOR_0&&(o=!0),r&&i&&o)break}if(!r&&!i&&!o)return Promise.resolve(e);const a=[],s=[],c=[];for(let l=0,u=t.length;l<u;l++){const u=t[l];if(r){const t=void 0!==u.POSITION?n.getDependency("accessor",u.POSITION):e.attributes.position;a.push(t)}if(i){const t=void 0!==u.NORMAL?n.getDependency("accessor",u.NORMAL):e.attributes.normal;s.push(t)}if(o){const t=void 0!==u.COLOR_0?n.getDependency("accessor",u.COLOR_0):e.attributes.color;c.push(t)}}return Promise.all([Promise.all(a),Promise.all(s),Promise.all(c)]).then(function(t){const n=t[0],a=t[1],s=t[2];return r&&(e.morphAttributes.position=n),i&&(e.morphAttributes.normal=a),o&&(e.morphAttributes.color=s),e.morphTargetsRelative=!0,e})}(e,t.targets,n):e})}var ma=function(){var e=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),t=new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);if("object"!=typeof WebAssembly)return{supported:!1};var n,r=WebAssembly.validate(e)?"b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuikqbbebeedddilve9Weeeviebeoweuec:q;Aekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbwl79IV9RbDq;t9tqlbzik9:evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaec:q:yjjbfai86bbaecitc:q1jjbfab8Piw83ibaecefgecjd9hmbkk;h8JlHud97euo978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Rad;8qbbcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhwcbhDinaDae9pmeawaeaD9RaDawfae6Egqcsfgoc9WGgkci2hxakcethmaocl4cifcd4hPabaDad2fhscbhzdnincehHalhOcbhAdninaraO9RaP6miavcj;cbfaAak2fhCaOaPfhlcbhidnakc;ab6mbaral9Rc;Gb6mbcbhoinaCaofhidndndndndnaOaoco4fRbbgXciGPlbedibkaipxbbbbbbbbbbbbbbbbpklbxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklbalczfhlkdndndndndnaXcd4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklzxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklzalczfhlkdndndndndnaXcl4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklaxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklaalczfhlkdndndndndnaXco4Plbedibkaipxbbbbbbbbbbbbbbbbpkl8WxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalclfaYpQbfaXc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalcwfaYpQbfaXc:q:yjjbfRbbfhlxekaialpbbbpkl8Walczfhlkaoc;abfhiaocjefak0meaihoaral9Rc;Fb0mbkkdndnaiak9pmbaici4hoinaral9RcK6mdaCaifhXdndndndndnaOaico4fRbbaocoG4ciGPlbedibkaXpxbbbbbbbbbbbbbbbbpklbxikaXalpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaXalpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaXalpbbbpklbalczfhlkaocdfhoaiczfgiak6mbkkalTmbaAci6hHalhOaAcefgohAaoclSmdxekkcbhlaHceGmdkdnakTmbavcjdfazfhiavazfpbdbhYcbhXinaiavcj;cbfaXfgopblbgLcep9TaLpxeeeeeeeeeeeeeeeegQp9op9Hp9rgLaoakfpblbg8Acep9Ta8AaQp9op9Hp9rg8ApmbzeHdOiAlCvXoQrLgEaoamfpblbg3cep9Ta3aQp9op9Hp9rg3aoaxfpblbg5cep9Ta5aQp9op9Hp9rg5pmbzeHdOiAlCvXoQrLg8EpmbezHdiOAlvCXorQLgQaQpmbedibedibedibediaYp9UgYp9AdbbaiadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaEa8EpmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwKDYq8AkEx3m5P8Es8FgLa3a5pmwKDYq8AkEx3m5P8Es8Fg8ApmbezHdiOAlvCXorQLgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfhiaXczfgXak6mbkkazclfgzad6mbkasavcjdfaqad2;8qbbavavcjdfaqcufad2fad;8qbbaqaDfhDc9:hoalmexikkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;kbf8Kjjjjbaokwbz:bjjjbk;uzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecje;8kbavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhDcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgrc;Ve0mbavc;abfalarcl4cu7fcsGcitfgPydlhsaPydbhzdnarcsGgPak9pmbavaiarcu7fcsGcdtfydbaxaPEhraPThPdndnadcd9hmbabaDcetfgHaz87ebaHcdfas87ebaHclfar87ebxekabaDcdtfgHazBdbaHclfasBdbaHcwfarBdbkaxaPfhxavc;abfalcitfgHarBdbaHasBdlavaicdtfarBdbavc;abfalcefcsGglcitfgHazBdbaHarBdlaiaPfhialcefhlxdkdndnaPcsSmbamaPfaPc987fcefhmxekaocefhrao8SbbgPcFeGhHdndnaPcu9mmbarhoxekaocvfhoaHcFbGhHcrhPdninar8SbbgOcFbGaPtaHVhHaOcu9kmearcefhraPcrfgPc8J9hmbxdkkarcefhokaHce4cbaHceG9R7amfhmkdndnadcd9hmbabaDcetfgraz87ebarcdfas87ebarclfam87ebxekabaDcdtfgrazBdbarclfasBdbarcwfamBdbkavc;abfalcitfgramBdbarasBdlavaicdtfamBdbavc;abfalcefcsGglcitfgrazBdbaramBdlaicefhialcefhlxekdnarcpe0mbaxcefgOavaiaqarcsGfRbbgPcl49RcsGcdtfydbaPcz6gHEhravaiaP9RcsGcdtfydbaOaHfgsaPcsGgOEhPaOThOdndnadcd9hmbabaDcetfgzax87ebazcdfar87ebazclfaP87ebxekabaDcdtfgzaxBdbazclfarBdbazcwfaPBdbkavaicdtfaxBdbavc;abfalcitfgzarBdbazaxBdlavaicefgicsGcdtfarBdbavc;abfalcefcsGcitfgzaPBdbazarBdlavaiaHfcsGgicdtfaPBdbavc;abfalcdfcsGglcitfgraxBdbaraPBdlalcefhlaiaOfhiasaOfhxxekaxcbaoRbbgzEgAarc;:eSgrfhsazcsGhCazcl4hXdndnazcs0mbascefhOxekashOavaiaX9RcsGcdtfydbhskdndnaCmbaOcefhxxekaOhxavaiaz9RcsGcdtfydbhOkdndnarTmbaocefhrxekaocdfhrao8SbegHcFeGhPdnaHcu9kmbaocofhAaPcFbGhPcrhodninar8SbbgHcFbGaotaPVhPaHcu9kmearcefhraocrfgoc8J9hmbkaAhrxekarcefhrkaPce4cbaPceG9R7amfgmhAkdndnaXcsSmbarhPxekarcefhPar8SbbgocFeGhHdnaocu9kmbarcvfhsaHcFbGhHcrhodninaP8SbbgrcFbGaotaHVhHarcu9kmeaPcefhPaocrfgoc8J9hmbkashPxekaPcefhPkaHce4cbaHceG9R7amfgmhskdndnaCcsSmbaPhoxekaPcefhoaP8SbbgrcFeGhHdnarcu9kmbaPcvfhOaHcFbGhHcrhrdninao8SbbgPcFbGartaHVhHaPcu9kmeaocefhoarcrfgrc8J9hmbkaOhoxekaocefhokaHce4cbaHceG9R7amfgmhOkdndnadcd9hmbabaDcetfgraA87ebarcdfas87ebarclfaO87ebxekabaDcdtfgraABdbarclfasBdbarcwfaOBdbkavc;abfalcitfgrasBdbaraABdlavaicdtfaABdbavc;abfalcefcsGcitfgraOBdbarasBdlavaicefgicsGcdtfasBdbavc;abfalcdfcsGcitfgraABdbaraOBdlavaiazcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiaDcifgDae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:llevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:EPliuo97eue978Jjjjjbca9Rhidndnadcl9hmbdnaec98GglTmbcbhvabhdinadadpbbbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbadczfhdavclfgval6mbkkalae9pmeaiaeciGgvcdtgdVcbczad9R;8kbaiabalcdtfglad;8qbbdnavTmbaiaipblbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpklbkalaiad;8qbbskdnaec98GgxTmbcbhvabhdinadczfglalpbbbgopxbbbbbbFFbbbbbbFFgkp9oadpbbbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpkbbadaDakp9oawaopmbezHdiOAlvCXorQLp9qpkbbadcafhdavclfgvax6mbkkaxae9pmbaiaeciGgvcitgdfcbcaad9R;8kbaiabaxcitfglad;8qbbdnavTmbaiaipblzgopxbbbbbbFFbbbbbbFFgkp9oaipblbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpklzaiaDakp9oawaopmbezHdiOAlvCXorQLp9qpklbkalaiad;8qbbkk;4wllue97euv978Jjjjjbc8W9Rhidnaec98GglTmbcbhvabhoinaiaopbbbgraoczfgwpbbbgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklbaopxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblbpEb:T:j83ibaocwfarp5eaipblbpEe:T:j83ibawaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblbpEd:T:j83ibaocKfakp5eaipblbpEi:T:j83ibaocafhoavclfgval6mbkkdnalae9pmbaiaeciGgvcitgofcbcaao9R;8kbaiabalcitfgwao;8qbbdnavTmbaiaipblbgraipblzgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklaaipxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblapEb:T:j83ibaiarp5eaipblapEe:T:j83iwaiaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblapEd:T:j83izaiakp5eaipblapEi:T:j83iKkawaiao;8qbbkk:Pddiue978Jjjjjbc;ab9Rhidnadcd4ae2glc98GgvTmbcbhdabheinaeaepbbbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepkbbaeczfheadclfgdav6mbkkdnaval9pmbaialciGgdcdtgeVcbc;abae9R;8kbaiabavcdtfgvae;8qbbdnadTmbaiaipblbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepklbkavaiae;8qbbkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkkebcjwklz9Tbb":"b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuikqbeeedddillviebeoweuec:q;iekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbol79IV9Rbrq:P8Yqdbk;3sezu8Jjjjjbcj;eb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Radz1jjjbhwcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhDcbhqinaqae9pmeaDaeaq9RaqaDfae6Egkcsfgocl4cifcd4hxdndndndnaoc9WGgmTmbcbhPcehsawcjdfhzalhHinaraH9Rax6midnaraHaxfgl9RcK6mbczhoinawcj;cbfaogifgoc9WfhOdndndndndnaHaic9WfgAco4fRbbaAci4coG4ciGPlbedibkaO9cb83ibaOcwf9cb83ibxikaOalRblalRbbgAco4gCaCciSgCE86bbaocGfalclfaCfgORbbaAcl4ciGgCaCciSgCE86bbaocVfaOaCfgORbbaAcd4ciGgCaCciSgCE86bbaoc7faOaCfgORbbaAciGgAaAciSgAE86bbaoctfaOaAfgARbbalRbegOco4gCaCciSgCE86bbaoc91faAaCfgARbbaOcl4ciGgCaCciSgCE86bbaoc4faAaCfgARbbaOcd4ciGgCaCciSgCE86bbaoc93faAaCfgARbbaOciGgOaOciSgOE86bbaoc94faAaOfgARbbalRbdgOco4gCaCciSgCE86bbaoc95faAaCfgARbbaOcl4ciGgCaCciSgCE86bbaoc96faAaCfgARbbaOcd4ciGgCaCciSgCE86bbaoc97faAaCfgARbbaOciGgOaOciSgOE86bbaoc98faAaOfgORbbalRbiglco4gAaAciSgAE86bbaoc99faOaAfgORbbalcl4ciGgAaAciSgAE86bbaoc9:faOaAfgORbbalcd4ciGgAaAciSgAE86bbaocufaOaAfgoRbbalciGglalciSglE86bbaoalfhlxdkaOalRbwalRbbgAcl4gCaCcsSgCE86bbaocGfalcwfaCfgORbbaAcsGgAaAcsSgAE86bbaocVfaOaAfgORbbalRbegAcl4gCaCcsSgCE86bbaoc7faOaCfgORbbaAcsGgAaAcsSgAE86bbaoctfaOaAfgORbbalRbdgAcl4gCaCcsSgCE86bbaoc91faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc4faOaAfgORbbalRbigAcl4gCaCcsSgCE86bbaoc93faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc94faOaAfgORbbalRblgAcl4gCaCcsSgCE86bbaoc95faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc96faOaAfgORbbalRbvgAcl4gCaCcsSgCE86bbaoc97faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc98faOaAfgORbbalRbogAcl4gCaCcsSgCE86bbaoc99faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc9:faOaAfgORbbalRbrglcl4gAaAcsSgAE86bbaocufaOaAfgoRbbalcsGglalcsSglE86bbaoalfhlxekaOal8Pbb83bbaOcwfalcwf8Pbb83bbalczfhlkdnaiam9pmbaiczfhoaral9RcL0mekkaiam6mialTmidnakTmbawaPfRbbhOcbhoazhiinaiawcj;cbfaofRbbgAce4cbaAceG9R7aOfgO86bbaiadfhiaocefgoak9hmbkkazcefhzaPcefgPad6hsalhHaPad9hmexvkkcbhlasceGmdxikalaxad2fhCdnakTmbcbhHcehsawcjdfhminaral9Rax6mialTmdalaxfhlawaHfRbbhOcbhoamhiinaiawcj;cbfaofRbbgAce4cbaAceG9R7aOfgO86bbaiadfhiaocefgoak9hmbkamcefhmaHcefgHad6hsaHad9hmbkaChlxikcbhocehsinaral9Rax6mdalTmealaxfhlaocefgoad6hsadao9hmbkaChlxdkcbhlasceGTmekc9:hoxikabaqad2fawcjdfakad2z1jjjb8Aawawcjdfakcufad2fadz1jjjb8Aakaqfhqalmbkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;ebf8Kjjjjbaok;yzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecjez:jjjjb8AavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhDcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgrc;Ve0mbavc;abfalarcl4cu7fcsGcitfgPydlhsaPydbhzdnarcsGgPak9pmbavaiarcu7fcsGcdtfydbaxaPEhraPThPdndnadcd9hmbabaDcetfgHaz87ebaHcdfas87ebaHclfar87ebxekabaDcdtfgHazBdbaHclfasBdbaHcwfarBdbkaxaPfhxavc;abfalcitfgHarBdbaHasBdlavaicdtfarBdbavc;abfalcefcsGglcitfgHazBdbaHarBdlaiaPfhialcefhlxdkdndnaPcsSmbamaPfaPc987fcefhmxekaocefhrao8SbbgPcFeGhHdndnaPcu9mmbarhoxekaocvfhoaHcFbGhHcrhPdninar8SbbgOcFbGaPtaHVhHaOcu9kmearcefhraPcrfgPc8J9hmbxdkkarcefhokaHce4cbaHceG9R7amfhmkdndnadcd9hmbabaDcetfgraz87ebarcdfas87ebarclfam87ebxekabaDcdtfgrazBdbarclfasBdbarcwfamBdbkavc;abfalcitfgramBdbarasBdlavaicdtfamBdbavc;abfalcefcsGglcitfgrazBdbaramBdlaicefhialcefhlxekdnarcpe0mbaxcefgOavaiaqarcsGfRbbgPcl49RcsGcdtfydbaPcz6gHEhravaiaP9RcsGcdtfydbaOaHfgsaPcsGgOEhPaOThOdndnadcd9hmbabaDcetfgzax87ebazcdfar87ebazclfaP87ebxekabaDcdtfgzaxBdbazclfarBdbazcwfaPBdbkavaicdtfaxBdbavc;abfalcitfgzarBdbazaxBdlavaicefgicsGcdtfarBdbavc;abfalcefcsGcitfgzaPBdbazarBdlavaiaHfcsGgicdtfaPBdbavc;abfalcdfcsGglcitfgraxBdbaraPBdlalcefhlaiaOfhiasaOfhxxekaxcbaoRbbgzEgAarc;:eSgrfhsazcsGhCazcl4hXdndnazcs0mbascefhOxekashOavaiaX9RcsGcdtfydbhskdndnaCmbaOcefhxxekaOhxavaiaz9RcsGcdtfydbhOkdndnarTmbaocefhrxekaocdfhrao8SbegHcFeGhPdnaHcu9kmbaocofhAaPcFbGhPcrhodninar8SbbgHcFbGaotaPVhPaHcu9kmearcefhraocrfgoc8J9hmbkaAhrxekarcefhrkaPce4cbaPceG9R7amfgmhAkdndnaXcsSmbarhPxekarcefhPar8SbbgocFeGhHdnaocu9kmbarcvfhsaHcFbGhHcrhodninaP8SbbgrcFbGaotaHVhHarcu9kmeaPcefhPaocrfgoc8J9hmbkashPxekaPcefhPkaHce4cbaHceG9R7amfgmhskdndnaCcsSmbaPhoxekaPcefhoaP8SbbgrcFeGhHdnarcu9kmbaPcvfhOaHcFbGhHcrhrdninao8SbbgPcFbGartaHVhHaPcu9kmeaocefhoarcrfgrc8J9hmbkaOhoxekaocefhokaHce4cbaHceG9R7amfgmhOkdndnadcd9hmbabaDcetfgraA87ebarcdfas87ebarclfaO87ebxekabaDcdtfgraABdbarclfasBdbarcwfaOBdbkavc;abfalcitfgrasBdbaraABdlavaicdtfaABdbavc;abfalcefcsGcitfgraOBdbarasBdlavaicefgicsGcdtfasBdbavc;abfalcdfcsGcitfgraABdbaraOBdlavaiazcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiaDcifgDae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:llevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk;siliui99iue99dnaeTmbcbhiabhlindndnJ;Zl81Zalcof8UebgvciV:Y:vgoal8Ueb:YNgrJb;:FSNJbbbZJbbb:;arJbbbb9GEMgw:lJbbb9p9DTmbaw:OhDxekcjjjj94hDkalclf8Uebhqalcdf8UebhkabavcefciGaiVcetfaD87ebdndnaoak:YNgwJb;:FSNJbbbZJbbb:;awJbbbb9GEMgx:lJbbb9p9DTmbax:Ohkxekcjjjj94hkkabavcdfciGaiVcetfak87ebdndnaoaq:YNgoJb;:FSNJbbbZJbbb:;aoJbbbb9GEMgx:lJbbb9p9DTmbax:Ohqxekcjjjj94hqkabavcufciGaiVcetfaq87ebdndnJbbjZararN:tawawN:taoaoN:tgrJbbbbarJbbbb9GE:rJb;:FSNJbbbZMgr:lJbbb9p9DTmbar:Ohqxekcjjjj94hqkabavciGaiVcetfaq87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2geTmbinababydbgdcwtcw91:Yadce91cjjj;8ifcjjj98G::NUdbabclfhbaecufgembkkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaiczfhiaeczfheadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkkkebcjwklz9Kbb",i=WebAssembly.instantiate(o(r),{}).then(function(e){(n=e.instance).exports.__wasm_call_ctors()});function o(e){for(var n=new Uint8Array(e.length),r=0;r<e.length;++r){var i=e.charCodeAt(r);n[r]=i>96?i-97:i>64?i-39:i+4}var o=0;for(r=0;r<e.length;++r)n[o++]=n[r]<60?t[n[r]]:64*(n[r]-60)+n[++r];return n.buffer.slice(0,o)}function a(e,t,r,i,o,a){var s=n.exports.sbrk,c=r+3&-4,l=s(c*i),u=s(o.length),h=new Uint8Array(n.exports.memory.buffer);h.set(o,u);var d=e(l,r,i,u,o.length);if(0==d&&a&&a(l,c,i),t.set(h.subarray(l,l+r*i)),s(l-s(0)),0!=d)throw new Error("Malformed buffer data: "+d)}var s={NONE:"",OCTAHEDRAL:"meshopt_decodeFilterOct",QUATERNION:"meshopt_decodeFilterQuat",EXPONENTIAL:"meshopt_decodeFilterExp"},c={ATTRIBUTES:"meshopt_decodeVertexBuffer",TRIANGLES:"meshopt_decodeIndexBuffer",INDICES:"meshopt_decodeIndexSequence"},l=[],u=0;function h(e){var t={object:new Worker(e),pending:0,requests:{}};return t.object.onmessage=function(e){var n=e.data;t.pending-=n.count,t.requests[n.id][n.action](n.value),delete t.requests[n.id]},t}function d(e){for(var t="var instance; var ready = WebAssembly.instantiate(new Uint8Array(["+new Uint8Array(o(r))+"]), {}).then(function(result) { instance = result.instance; instance.exports.__wasm_call_ctors(); });self.onmessage = workerProcess;"+a.toString()+p.toString(),n=new Blob([t],{type:"text/javascript"}),i=URL.createObjectURL(n),s=0;s<e;++s)l[s]=h(i);URL.revokeObjectURL(i)}function p(e){i.then(function(){var t=e.data;try{var r=new Uint8Array(t.count*t.size);a(n.exports[t.mode],r,t.count,t.size,t.source,n.exports[t.filter]),self.postMessage({id:t.id,count:t.count,action:"resolve",value:r},[r.buffer])}catch(e){self.postMessage({id:t.id,count:t.count,action:"reject",value:e})}})}return{ready:i,supported:!0,useWorkers:function(e){d(e)},decodeVertexBuffer:function(e,t,r,i,o){a(n.exports.meshopt_decodeVertexBuffer,e,t,r,i,n.exports[s[o]])},decodeIndexBuffer:function(e,t,r,i){a(n.exports.meshopt_decodeIndexBuffer,e,t,r,i)},decodeIndexSequence:function(e,t,r,i){a(n.exports.meshopt_decodeIndexSequence,e,t,r,i)},decodeGltfBuffer:function(e,t,r,i,o,l){a(n.exports[c[o]],e,t,r,i,n.exports[s[l]])},decodeGltfBufferAsync:function(e,t,r,o,h){return l.length>0?function(e,t,n,r,i){for(var o=l[0],a=1;a<l.length;++a)l[a].pending<o.pending&&(o=l[a]);return new Promise(function(a,s){var c=new Uint8Array(n),l=u++;o.pending+=e,o.requests[l]={resolve:a,reject:s},o.object.postMessage({id:l,count:e,size:t,source:c,mode:r,filter:i},[c.buffer])})}(e,t,r,c[o],s[h]):i.then(function(){var i=new Uint8Array(e*t);return a(n.exports[c[o]],i,e,t,r,n.exports[s[h]]),i})}}}();const ga=/^[og]\s*(.+)?/,ba=/^mtllib /,ya=/^usemtl /,va=/^usemap /,xa=/\s+/,wa=new f,Ea=new f,Ta=new f,Aa=new f,Ca=new f,Oa=new K;function ka(){const e={objects:[],object:{},vertices:[],normals:[],colors:[],uvs:[],materials:{},materialLibraries:[],startObject:function(e,t){if(this.object&&!1===this.object.fromDeclaration)return this.object.name=e,void(this.object.fromDeclaration=!1!==t);const n=this.object&&"function"==typeof this.object.currentMaterial?this.object.currentMaterial():void 0;if(this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0),this.object={name:e||"",fromDeclaration:!1!==t,geometry:{vertices:[],normals:[],colors:[],uvs:[],hasUVIndices:!1},materials:[],smooth:!0,startMaterial:function(e,t){const n=this._finalize(!1);n&&(n.inherited||n.groupCount<=0)&&this.materials.splice(n.index,1);const r={index:this.materials.length,name:e||"",mtllib:Array.isArray(t)&&t.length>0?t[t.length-1]:"",smooth:void 0!==n?n.smooth:this.smooth,groupStart:void 0!==n?n.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(e){const t={index:"number"==typeof e?e:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0,groupEnd:-1,groupCount:-1,inherited:!1};return t.clone=this.clone.bind(t),t}};return this.materials.push(r),r},currentMaterial:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]},_finalize:function(e){const t=this.currentMaterial();if(t&&-1===t.groupEnd&&(t.groupEnd=this.geometry.vertices.length/3,t.groupCount=t.groupEnd-t.groupStart,t.inherited=!1),e&&this.materials.length>1)for(let e=this.materials.length-1;e>=0;e--)this.materials[e].groupCount<=0&&this.materials.splice(e,1);return e&&0===this.materials.length&&this.materials.push({name:"",smooth:this.smooth}),t}},n&&n.name&&"function"==typeof n.clone){const e=n.clone(0);e.inherited=!0,this.object.materials.push(e)}this.objects.push(this.object)},finalize:function(){this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0)},parseVertexIndex:function(e,t){const n=parseInt(e,10);return 3*(n>=0?n-1:n+t/3)},parseNormalIndex:function(e,t){const n=parseInt(e,10);return 3*(n>=0?n-1:n+t/3)},parseUVIndex:function(e,t){const n=parseInt(e,10);return 2*(n>=0?n-1:n+t/2)},addVertex:function(e,t,n){const r=this.vertices,i=this.object.geometry.vertices;i.push(r[e+0],r[e+1],r[e+2]),i.push(r[t+0],r[t+1],r[t+2]),i.push(r[n+0],r[n+1],r[n+2])},addVertexPoint:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addVertexLine:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addNormal:function(e,t,n){const r=this.normals,i=this.object.geometry.normals;i.push(r[e+0],r[e+1],r[e+2]),i.push(r[t+0],r[t+1],r[t+2]),i.push(r[n+0],r[n+1],r[n+2])},addFaceNormal:function(e,t,n){const r=this.vertices,i=this.object.geometry.normals;wa.fromArray(r,e),Ea.fromArray(r,t),Ta.fromArray(r,n),Ca.subVectors(Ta,Ea),Aa.subVectors(wa,Ea),Ca.cross(Aa),Ca.normalize(),i.push(Ca.x,Ca.y,Ca.z),i.push(Ca.x,Ca.y,Ca.z),i.push(Ca.x,Ca.y,Ca.z)},addColor:function(e,t,n){const r=this.colors,i=this.object.geometry.colors;void 0!==r[e]&&i.push(r[e+0],r[e+1],r[e+2]),void 0!==r[t]&&i.push(r[t+0],r[t+1],r[t+2]),void 0!==r[n]&&i.push(r[n+0],r[n+1],r[n+2])},addUV:function(e,t,n){const r=this.uvs,i=this.object.geometry.uvs;i.push(r[e+0],r[e+1]),i.push(r[t+0],r[t+1]),i.push(r[n+0],r[n+1])},addDefaultUV:function(){const e=this.object.geometry.uvs;e.push(0,0),e.push(0,0),e.push(0,0)},addUVLine:function(e){const t=this.uvs;this.object.geometry.uvs.push(t[e+0],t[e+1])},addFace:function(e,t,n,r,i,o,a,s,c){const l=this.vertices.length;let u=this.parseVertexIndex(e,l),h=this.parseVertexIndex(t,l),d=this.parseVertexIndex(n,l);if(this.addVertex(u,h,d),this.addColor(u,h,d),void 0!==a&&""!==a){const e=this.normals.length;u=this.parseNormalIndex(a,e),h=this.parseNormalIndex(s,e),d=this.parseNormalIndex(c,e),this.addNormal(u,h,d)}else this.addFaceNormal(u,h,d);if(void 0!==r&&""!==r){const e=this.uvs.length;u=this.parseUVIndex(r,e),h=this.parseUVIndex(i,e),d=this.parseUVIndex(o,e),this.addUV(u,h,d),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(e){this.object.geometry.type="Points";const t=this.vertices.length;for(let n=0,r=e.length;n<r;n++){const r=this.parseVertexIndex(e[n],t);this.addVertexPoint(r),this.addColor(r)}},addLineGeometry:function(e,t){this.object.geometry.type="Line";const n=this.vertices.length,r=this.uvs.length;for(let t=0,r=e.length;t<r;t++)this.addVertexLine(this.parseVertexIndex(e[t],n));for(let e=0,n=t.length;e<n;e++)this.addUVLine(this.parseUVIndex(t[e],r))}};return e.startObject("",!1),e}class Sa extends X{constructor(e){super(e),this.materials=null}load(e,t,n,r){const i=this,o=new q(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}setMaterials(e){return this.materials=e,this}parse(e){const t=new ka;-1!==e.indexOf("\r\n")&&(e=e.replace(/\r\n/g,"\n")),-1!==e.indexOf("\\\n")&&(e=e.replace(/\\\n/g,""));const n=e.split("\n");let r=[];for(let e=0,i=n.length;e<i;e++){const i=n[e].trimStart();if(0===i.length)continue;const o=i.charAt(0);if("#"!==o)if("v"===o){const e=i.split(xa);switch(e[0]){case"v":t.vertices.push(parseFloat(e[1]),parseFloat(e[2]),parseFloat(e[3])),e.length>=7?(Oa.setRGB(parseFloat(e[4]),parseFloat(e[5]),parseFloat(e[6])).convertSRGBToLinear(),t.colors.push(Oa.r,Oa.g,Oa.b)):t.colors.push(void 0,void 0,void 0);break;case"vn":t.normals.push(parseFloat(e[1]),parseFloat(e[2]),parseFloat(e[3]));break;case"vt":t.uvs.push(parseFloat(e[1]),parseFloat(e[2]))}}else if("f"===o){const e=i.slice(1).trim().split(xa),n=[];for(let t=0,r=e.length;t<r;t++){const r=e[t];if(r.length>0){const e=r.split("/");n.push(e)}}const r=n[0];for(let e=1,i=n.length-1;e<i;e++){const i=n[e],o=n[e+1];t.addFace(r[0],i[0],o[0],r[1],i[1],o[1],r[2],i[2],o[2])}}else if("l"===o){const e=i.substring(1).trim().split(" ");let n=[];const r=[];if(-1===i.indexOf("/"))n=e;else for(let t=0,i=e.length;t<i;t++){const i=e[t].split("/");""!==i[0]&&n.push(i[0]),""!==i[1]&&r.push(i[1])}t.addLineGeometry(n,r)}else if("p"===o){const e=i.slice(1).trim().split(" ");t.addPointGeometry(e)}else if(null!==(r=ga.exec(i))){const e=(" "+r[0].slice(1).trim()).slice(1);t.startObject(e)}else if(ya.test(i))t.object.startMaterial(i.substring(7).trim(),t.materialLibraries);else if(ba.test(i))t.materialLibraries.push(i.substring(7).trim());else if(va.test(i))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if("s"===o){if(r=i.split(" "),r.length>1){const e=r[1].trim().toLowerCase();t.object.smooth="0"!==e&&"off"!==e}else t.object.smooth=!0;const e=t.object.currentMaterial();e&&(e.smooth=t.object.smooth)}else{if("\0"===i)continue;console.warn('THREE.OBJLoader: Unexpected line: "'+i+'"')}}t.finalize();const i=new Oe;i.materialLibraries=[].concat(t.materialLibraries);if(!0===!(1===t.objects.length&&0===t.objects[0].geometry.vertices.length))for(let e=0,n=t.objects.length;e<n;e++){const n=t.objects[e],r=n.geometry,o=n.materials,a="Line"===r.type,s="Points"===r.type;let c=!1;if(0===r.vertices.length)continue;const l=new O;l.setAttribute("position",new k(r.vertices,3)),r.normals.length>0&&l.setAttribute("normal",new k(r.normals,3)),r.colors.length>0&&(c=!0,l.setAttribute("color",new k(r.colors,3))),!0===r.hasUVIndices&&l.setAttribute("uv",new k(r.uvs,2));const u=[];for(let e=0,n=o.length;e<n;e++){const n=o[e],r=n.name+"_"+n.smooth+"_"+c;let i=t.materials[r];if(null!==this.materials)if(i=this.materials.create(n.name),!a||!i||i instanceof T){if(s&&i&&!(i instanceof ye)){const e=new ye({size:10,sizeAttenuation:!1});ve.prototype.copy.call(e,i),e.color.copy(i.color),e.map=i.map,i=e}}else{const e=new T;ve.prototype.copy.call(e,i),e.color.copy(i.color),i=e}void 0===i&&(i=a?new T:s?new ye({size:1,sizeAttenuation:!1}):new Be,i.name=n.name,i.flatShading=!n.smooth,i.vertexColors=c,t.materials[r]=i),u.push(i)}let h;if(u.length>1){for(let e=0,t=o.length;e<t;e++){const t=o[e];l.addGroup(t.groupStart,t.groupCount,e)}h=a?new Te(l,u):s?new Ce(l,u):new S(l,u)}else h=a?new Te(l,u[0]):s?new Ce(l,u[0]):new S(l,u[0]);h.name=n.name,i.add(h)}else if(t.vertices.length>0){const e=new ye({size:1,sizeAttenuation:!1}),n=new O;n.setAttribute("position",new k(t.vertices,3)),t.colors.length>0&&void 0!==t.colors[0]&&(n.setAttribute("color",new k(t.colors,3)),e.vertexColors=!0);const r=new Ce(n,e);i.add(r)}return i}}class Ra extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=""===this.path?J.extractUrlBase(e):this.path,a=new q(this.manager);a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}setMaterialOptions(e){return this.materialOptions=e,this}parse(e,t){const n=e.split("\n");let r={};const i=/\s+/,o={};for(let e=0;e<n.length;e++){let t=n[e];if(t=t.trim(),0===t.length||"#"===t.charAt(0))continue;const a=t.indexOf(" ");let s=a>=0?t.substring(0,a):t;s=s.toLowerCase();let c=a>=0?t.substring(a+1):"";if(c=c.trim(),"newmtl"===s)r={name:c},o[c]=r;else if("ka"===s||"kd"===s||"ks"===s||"ke"===s){const e=c.split(i,3);r[s]=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])]}else r[s]=c}const a=new Ma(this.resourcePath||t,this.materialOptions);return a.setCrossOrigin(this.crossOrigin),a.setManager(this.manager),a.setMaterials(o),a}}class Ma{constructor(e="",t={}){this.baseUrl=e,this.options=t,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.crossOrigin="anonymous",this.side=void 0!==this.options.side?this.options.side:G,this.wrap=void 0!==this.options.wrap?this.options.wrap:me}setCrossOrigin(e){return this.crossOrigin=e,this}setManager(e){this.manager=e}setMaterials(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}convert(e){if(!this.options)return e;const t={};for(const n in e){const r=e[n],i={};t[n]=i;for(const e in r){let t=!0,n=r[e];const o=e.toLowerCase();switch(o){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(n=[n[0]/255,n[1]/255,n[2]/255]),this.options&&this.options.ignoreZeroRGBs&&0===n[0]&&0===n[1]&&0===n[2]&&(t=!1)}t&&(i[o]=n)}}return t}preload(){for(const e in this.materialsInfo)this.create(e)}getIndex(e){return this.nameLookup[e]}getAsArray(){let e=0;for(const t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}create(e){return void 0===this.materials[e]&&this.createMaterial_(e),this.materials[e]}createMaterial_(e){const t=this,n=this.materialsInfo[e],r={name:e,side:this.side};function i(e,n){if(r[e])return;const i=t.getTextureParams(n,r),o=t.loadTexture((a=t.baseUrl,"string"!=typeof(s=i.url)||""===s?"":/^https?:\/\//i.test(s)?s:a+s));var a,s;o.repeat.copy(i.scale),o.offset.copy(i.offset),o.wrapS=t.wrap,o.wrapT=t.wrap,"map"!==e&&"emissiveMap"!==e||(o.colorSpace=Y),r[e]=o}for(const e in n){const t=n[e];let o;if(""!==t)switch(e.toLowerCase()){case"kd":r.color=(new K).fromArray(t).convertSRGBToLinear();break;case"ks":r.specular=(new K).fromArray(t).convertSRGBToLinear();break;case"ke":r.emissive=(new K).fromArray(t).convertSRGBToLinear();break;case"map_kd":i("map",t);break;case"map_ks":i("specularMap",t);break;case"map_ke":i("emissiveMap",t);break;case"norm":i("normalMap",t);break;case"map_bump":case"bump":i("bumpMap",t);break;case"map_d":i("alphaMap",t),r.transparent=!0;break;case"ns":r.shininess=parseFloat(t);break;case"d":o=parseFloat(t),o<1&&(r.opacity=o,r.transparent=!0);break;case"tr":o=parseFloat(t),this.options&&this.options.invertTrProperty&&(o=1-o),o>0&&(r.opacity=1-o,r.transparent=!0)}}return this.materials[e]=new Be(r),this.materials[e]}getTextureParams(e,t){const n={scale:new v(1,1),offset:new v(0,0)},r=e.split(/\s+/);let i;return i=r.indexOf("-bm"),i>=0&&(t.bumpScale=parseFloat(r[i+1]),r.splice(i,2)),i=r.indexOf("-s"),i>=0&&(n.scale.set(parseFloat(r[i+1]),parseFloat(r[i+2])),r.splice(i,4)),i=r.indexOf("-o"),i>=0&&(n.offset.set(parseFloat(r[i+1]),parseFloat(r[i+2])),r.splice(i,4)),n.url=r.join(" ").trim(),n}loadTexture(e,t,n,r,i){const o=void 0!==this.manager?this.manager:ze;let a=o.getHandler(e);null===a&&(a=new ae(o)),a.setCrossOrigin&&a.setCrossOrigin(this.crossOrigin);const s=a.load(e,n,r,i);return void 0!==t&&(s.mapping=t),s}}function Ia(e,t,n){const r=n.length-e-1;if(t>=n[r])return r-1;if(t<=n[e])return e;let i=e,o=r,a=Math.floor((i+o)/2);for(;t<n[a]||t>=n[a+1];)t<n[a]?o=a:i=a,a=Math.floor((i+o)/2);return a}function Pa(e,t){let n=1;for(let t=2;t<=e;++t)n*=t;let r=1;for(let e=2;e<=t;++e)r*=e;for(let n=2;n<=e-t;++n)r*=n;return n/r}function _a(e,t,n,r,i){const o=function(e,t,n,r,i){const o=i<e?i:e,a=[],s=Ia(e,r,t),c=function(e,t,n,r,i){const o=[];for(let e=0;e<=n;++e)o[e]=0;const a=[];for(let e=0;e<=r;++e)a[e]=o.slice(0);const s=[];for(let e=0;e<=n;++e)s[e]=o.slice(0);s[0][0]=1;const c=o.slice(0),l=o.slice(0);for(let r=1;r<=n;++r){c[r]=t-i[e+1-r],l[r]=i[e+r]-t;let n=0;for(let e=0;e<r;++e){const t=l[e+1],i=c[r-e];s[r][e]=t+i;const o=s[e][r-1]/s[r][e];s[e][r]=n+t*o,n=i*o}s[r][r]=n}for(let e=0;e<=n;++e)a[0][e]=s[e][n];for(let e=0;e<=n;++e){let t=0,i=1;const c=[];for(let e=0;e<=n;++e)c[e]=o.slice(0);c[0][0]=1;for(let o=1;o<=r;++o){let r=0;const l=e-o,u=n-o;e>=o&&(c[i][0]=c[t][0]/s[u+1][l],r=c[i][0]*s[l][u]);const h=e-1<=u?o-1:n-e;for(let e=l>=-1?1:-l;e<=h;++e)c[i][e]=(c[t][e]-c[t][e-1])/s[u+1][l+e],r+=c[i][e]*s[l+e][u];e<=u&&(c[i][o]=-c[t][o-1]/s[u+1][e],r+=c[i][o]*s[e][u]),a[o][e]=r;const d=t;t=i,i=d}}let u=n;for(let e=1;e<=r;++e){for(let t=0;t<=n;++t)a[e][t]*=u;u*=n-e}return a}(s,r,e,o,t),l=[];for(let e=0;e<n.length;++e){const t=n[e].clone(),r=t.w;t.x*=r,t.y*=r,t.z*=r,l[e]=t}for(let t=0;t<=o;++t){const n=l[s-e].clone().multiplyScalar(c[t][0]);for(let r=1;r<=e;++r)n.add(l[s-e+r].clone().multiplyScalar(c[t][r]));a[t]=n}for(let e=o+1;e<=i+1;++e)a[e]=new He(0,0,0);return a}(e,t,n,r,i);return function(e){const t=e.length,n=[],r=[];for(let i=0;i<t;++i){const t=e[i];n[i]=new f(t.x,t.y,t.z),r[i]=t.w}const i=[];for(let e=0;e<t;++e){const t=n[e].clone();for(let n=1;n<=e;++n)t.sub(i[e-n].clone().multiplyScalar(Pa(e,n)*r[n]));i[e]=t.divideScalar(r[0])}return i}(o)}class Na extends Ve{constructor(e,t,n,r,i){super(),this.degree=e,this.knots=t,this.controlPoints=[],this.startKnot=r||0,this.endKnot=i||this.knots.length-1;for(let e=0;e<n.length;++e){const t=n[e];this.controlPoints[e]=new He(t.x,t.y,t.z,t.w)}}getPoint(e,t=new f){const n=t,r=this.knots[this.startKnot]+e*(this.knots[this.endKnot]-this.knots[this.startKnot]),i=function(e,t,n,r){const i=Ia(e,r,t),o=function(e,t,n,r){const i=[],o=[],a=[];i[0]=1;for(let s=1;s<=n;++s){o[s]=t-r[e+1-s],a[s]=r[e+s]-t;let n=0;for(let e=0;e<s;++e){const t=a[e+1],r=o[s-e],c=i[e]/(t+r);i[e]=n+t*c,n=r*c}i[s]=n}return i}(i,r,e,t),a=new He(0,0,0,0);for(let t=0;t<=e;++t){const r=n[i-e+t],s=o[t],c=r.w*s;a.x+=r.x*c,a.y+=r.y*c,a.z+=r.z*c,a.w+=r.w*s}return a}(this.degree,this.knots,this.controlPoints,r);return 1!==i.w&&i.divideScalar(i.w),n.set(i.x,i.y,i.z)}getTangent(e,t=new f){const n=t,r=this.knots[0]+e*(this.knots[this.knots.length-1]-this.knots[0]),i=_a(this.degree,this.knots,this.controlPoints,r,1);return n.copy(i[1]).normalize(),n}}let La,Da,ja;class Fa extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=""===i.path?J.extractUrlBase(e):i.path,a=new q(this.manager);a.setPath(i.path),a.setResponseType("arraybuffer"),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e,t){if(function(e){const t="Kaydara FBX Binary \0";return e.byteLength>=t.length&&t===ts(e,0,t.length)}(e))La=(new Va).parse(e);else{const t=ts(e);if(!function(e){const t=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let n=0;function r(t){const r=e[t-1];return e=e.slice(n+t),n++,r}for(let e=0;e<t.length;++e){if(r(1)===t[e])return!1}return!0}(t))throw new Error("THREE.FBXLoader: Unknown format.");if(Xa(t)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+Xa(t));La=(new Ha).parse(t)}const n=new ae(this.manager).setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin);return new Ua(n,this.manager).parse(La)}}class Ua{constructor(e,t){this.textureLoader=e,this.manager=t}parse(){Da=this.parseConnections();const e=this.parseImages(),t=this.parseTextures(e),n=this.parseMaterials(t),r=this.parseDeformers(),i=(new Ba).parse(r);return this.parseScene(r,i,n),ja}parseConnections(){const e=new Map;if("Connections"in La){La.Connections.connections.forEach(function(t){const n=t[0],r=t[1],i=t[2];e.has(n)||e.set(n,{parents:[],children:[]});const o={ID:r,relationship:i};e.get(n).parents.push(o),e.has(r)||e.set(r,{parents:[],children:[]});const a={ID:n,relationship:i};e.get(r).children.push(a)})}return e}parseImages(){const e={},t={};if("Video"in La.Objects){const n=La.Objects.Video;for(const r in n){const i=n[r];if(e[parseInt(r)]=i.RelativeFilename||i.Filename,"Content"in i){const e=i.Content instanceof ArrayBuffer&&i.Content.byteLength>0,o="string"==typeof i.Content&&""!==i.Content;if(e||o){const e=this.parseImage(n[r]);t[i.RelativeFilename||i.Filename]=e}}}}for(const n in e){const r=e[n];void 0!==t[r]?e[n]=t[r]:e[n]=e[n].split("\\").pop()}return e}parseImage(e){const t=e.Content,n=e.RelativeFilename||e.Filename,r=n.slice(n.lastIndexOf(".")+1).toLowerCase();let i;switch(r){case"bmp":i="image/bmp";break;case"jpg":case"jpeg":i="image/jpeg";break;case"png":i="image/png";break;case"tif":i="image/tiff";break;case"tga":null===this.manager.getHandler(".tga")&&console.warn("FBXLoader: TGA loader not found, skipping ",n),i="image/tga";break;default:return void console.warn('FBXLoader: Image type "'+r+'" is not supported.')}if("string"==typeof t)return"data:"+i+";base64,"+t;{const e=new Uint8Array(t);return window.URL.createObjectURL(new Blob([e],{type:i}))}}parseTextures(e){const t=new Map;if("Texture"in La.Objects){const n=La.Objects.Texture;for(const r in n){const i=this.parseTexture(n[r],e);t.set(parseInt(r),i)}}return t}parseTexture(e,t){const n=this.loadTexture(e,t);n.ID=e.id,n.name=e.attrName;const r=e.WrapModeU,i=e.WrapModeV,o=void 0!==r?r.value:0,a=void 0!==i?i.value:0;if(n.wrapS=0===o?me:be,n.wrapT=0===a?me:be,"Scaling"in e){const t=e.Scaling.value;n.repeat.x=t[0],n.repeat.y=t[1]}if("Translation"in e){const t=e.Translation.value;n.offset.x=t[0],n.offset.y=t[1]}return n}loadTexture(e,t){let n;const r=this.textureLoader.path,i=Da.get(e.id).children;let o;void 0!==i&&i.length>0&&void 0!==t[i[0].ID]&&(n=t[i[0].ID],0!==n.indexOf("blob:")&&0!==n.indexOf("data:")||this.textureLoader.setPath(void 0));const a=e.FileName.slice(-3).toLowerCase();if("tga"===a){const t=this.manager.getHandler(".tga");null===t?(console.warn("FBXLoader: TGA loader not found, creating placeholder texture for",e.RelativeFilename),o=new Ne):(t.setPath(this.textureLoader.path),o=t.load(n))}else if("dds"===a){const t=this.manager.getHandler(".dds");null===t?(console.warn("FBXLoader: DDS loader not found, creating placeholder texture for",e.RelativeFilename),o=new Ne):(t.setPath(this.textureLoader.path),o=t.load(n))}else"psd"===a?(console.warn("FBXLoader: PSD textures are not supported, creating placeholder texture for",e.RelativeFilename),o=new Ne):o=this.textureLoader.load(n);return this.textureLoader.setPath(r),o}parseMaterials(e){const t=new Map;if("Material"in La.Objects){const n=La.Objects.Material;for(const r in n){const i=this.parseMaterial(n[r],e);null!==i&&t.set(parseInt(r),i)}}return t}parseMaterial(e,t){const n=e.id,r=e.attrName;let i=e.ShadingModel;if("object"==typeof i&&(i=i.value),!Da.has(n))return null;const o=this.parseParameters(e,t,n);let a;switch(i.toLowerCase()){case"phong":a=new Be;break;case"lambert":a=new Ge;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',i),a=new Be}return a.setValues(o),a.name=r,a}parseParameters(e,t,n){const r={};e.BumpFactor&&(r.bumpScale=e.BumpFactor.value),e.Diffuse?r.color=(new K).fromArray(e.Diffuse.value).convertSRGBToLinear():!e.DiffuseColor||"Color"!==e.DiffuseColor.type&&"ColorRGB"!==e.DiffuseColor.type||(r.color=(new K).fromArray(e.DiffuseColor.value).convertSRGBToLinear()),e.DisplacementFactor&&(r.displacementScale=e.DisplacementFactor.value),e.Emissive?r.emissive=(new K).fromArray(e.Emissive.value).convertSRGBToLinear():!e.EmissiveColor||"Color"!==e.EmissiveColor.type&&"ColorRGB"!==e.EmissiveColor.type||(r.emissive=(new K).fromArray(e.EmissiveColor.value).convertSRGBToLinear()),e.EmissiveFactor&&(r.emissiveIntensity=parseFloat(e.EmissiveFactor.value)),e.Opacity&&(r.opacity=parseFloat(e.Opacity.value)),r.opacity<1&&(r.transparent=!0),e.ReflectionFactor&&(r.reflectivity=e.ReflectionFactor.value),e.Shininess&&(r.shininess=e.Shininess.value),e.Specular?r.specular=(new K).fromArray(e.Specular.value).convertSRGBToLinear():e.SpecularColor&&"Color"===e.SpecularColor.type&&(r.specular=(new K).fromArray(e.SpecularColor.value).convertSRGBToLinear());const i=this;return Da.get(n).children.forEach(function(e){const n=e.relationship;switch(n){case"Bump":r.bumpMap=i.getTexture(t,e.ID);break;case"Maya|TEX_ao_map":r.aoMap=i.getTexture(t,e.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":r.map=i.getTexture(t,e.ID),void 0!==r.map&&(r.map.colorSpace=Y);break;case"DisplacementColor":r.displacementMap=i.getTexture(t,e.ID);break;case"EmissiveColor":r.emissiveMap=i.getTexture(t,e.ID),void 0!==r.emissiveMap&&(r.emissiveMap.colorSpace=Y);break;case"NormalMap":case"Maya|TEX_normal_map":r.normalMap=i.getTexture(t,e.ID);break;case"ReflectionColor":r.envMap=i.getTexture(t,e.ID),void 0!==r.envMap&&(r.envMap.mapping=We,r.envMap.colorSpace=Y);break;case"SpecularColor":r.specularMap=i.getTexture(t,e.ID),void 0!==r.specularMap&&(r.specularMap.colorSpace=Y);break;case"TransparentColor":case"TransparencyFactor":r.alphaMap=i.getTexture(t,e.ID),r.transparent=!0;break;default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",n)}}),r}getTexture(e,t){return"LayeredTexture"in La.Objects&&t in La.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=Da.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in La.Objects){const n=La.Objects.Deformer;for(const r in n){const i=n[r],o=Da.get(parseInt(r));if("Skin"===i.attrType){const t=this.parseSkeleton(o,n);t.ID=r,o.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),t.geometryID=o.parents[0].ID,e[r]=t}else if("BlendShape"===i.attrType){const e={id:r};e.rawTargets=this.parseMorphTargets(o,n),e.id=r,o.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[r]=e}}}return{skeletons:e,morphTargets:t}}parseSkeleton(e,t){const n=[];return e.children.forEach(function(e){const r=t[e.ID];if("Cluster"!==r.attrType)return;const i={ID:e.ID,indices:[],weights:[],transformLink:(new N).fromArray(r.TransformLink.a)};"Indexes"in r&&(i.indices=r.Indexes.a,i.weights=r.Weights.a),n.push(i)}),{rawBones:n,bones:[]}}parseMorphTargets(e,t){const n=[];for(let r=0;r<e.children.length;r++){const i=e.children[r],o=t[i.ID],a={name:o.attrName,initialWeight:o.DeformPercent,id:o.id,fullWeights:o.FullWeights.a};if("BlendShapeChannel"!==o.attrType)return;a.geoID=Da.get(parseInt(i.ID)).children.filter(function(e){return void 0===e.relationship})[0].ID,n.push(a)}return n}parseScene(e,t,n){ja=new Oe;const r=this.parseModels(e.skeletons,t,n),i=La.Objects.Model,o=this;r.forEach(function(e){const t=i[e.ID];o.setLookAtProperties(e,t);Da.get(e.ID).parents.forEach(function(t){const n=r.get(t.ID);void 0!==n&&n.add(e)}),null===e.parent&&ja.add(e)}),this.bindSkeleton(e.skeletons,t,r),this.addGlobalSceneSettings(),ja.traverse(function(e){if(e.userData.transformData){e.parent&&(e.userData.transformData.parentMatrix=e.parent.matrix,e.userData.transformData.parentMatrixWorld=e.parent.matrixWorld);const t=$a(e.userData.transformData);e.applyMatrix4(t),e.updateWorldMatrix()}});const a=(new za).parse();1===ja.children.length&&ja.children[0].isGroup&&(ja.children[0].animations=a,ja=ja.children[0]),ja.animations=a}parseModels(e,t,n){const r=new Map,i=La.Objects.Model;for(const o in i){const a=parseInt(o),s=i[o],c=Da.get(a);let l=this.buildSkeleton(c,e,a,s.attrName);if(!l){switch(s.attrType){case"Camera":l=this.createCamera(c);break;case"Light":l=this.createLight(c);break;case"Mesh":l=this.createMesh(c,t,n);break;case"NurbsCurve":l=this.createCurve(c,t);break;case"LimbNode":case"Root":l=new Ie;break;default:l=new Oe}l.name=s.attrName?we.sanitizeNodeName(s.attrName):"",l.userData.originalName=s.attrName,l.ID=a}this.getTransformData(l,s),r.set(a,l)}return r}buildSkeleton(e,t,n,r){let i=null;return e.parents.forEach(function(e){for(const o in t){const a=t[o];a.rawBones.forEach(function(t,o){if(t.ID===e.ID){const e=i;i=new Ie,i.matrixWorld.copy(t.transformLink),i.name=r?we.sanitizeNodeName(r):"",i.userData.originalName=r,i.ID=n,a.bones[o]=i,null!==e&&i.add(e)}})}}),i}createCamera(e){let t,n;if(e.children.forEach(function(e){const t=La.Objects.NodeAttribute[e.ID];void 0!==t&&(n=t)}),void 0===n)t=new x;else{let e=0;void 0!==n.CameraProjectionType&&1===n.CameraProjectionType.value&&(e=1);let r=1;void 0!==n.NearPlane&&(r=n.NearPlane.value/1e3);let i=1e3;void 0!==n.FarPlane&&(i=n.FarPlane.value/1e3);let o=window.innerWidth,a=window.innerHeight;void 0!==n.AspectWidth&&void 0!==n.AspectHeight&&(o=n.AspectWidth.value,a=n.AspectHeight.value);const s=o/a;let c=45;void 0!==n.FieldOfView&&(c=n.FieldOfView.value);const l=n.FocalLength?n.FocalLength.value:null;switch(e){case 0:t=new ke(c,s,r,i),null!==l&&t.setFocalLength(l);break;case 1:t=new Se(-o/2,o/2,a/2,-a/2,r,i);break;default:console.warn("THREE.FBXLoader: Unknown camera type "+e+"."),t=new x}}return t}createLight(e){let t,n;if(e.children.forEach(function(e){const t=La.Objects.NodeAttribute[e.ID];void 0!==t&&(n=t)}),void 0===n)t=new x;else{let e;e=void 0===n.LightType?0:n.LightType.value;let r=16777215;void 0!==n.Color&&(r=(new K).fromArray(n.Color.value).convertSRGBToLinear());let i=void 0===n.Intensity?1:n.Intensity.value/100;void 0!==n.CastLightOnObject&&0===n.CastLightOnObject.value&&(i=0);let o=0;void 0!==n.FarAttenuationEnd&&(o=void 0!==n.EnableFarAttenuation&&0===n.EnableFarAttenuation.value?0:n.FarAttenuationEnd.value);const a=1;switch(e){case 0:t=new ne(r,i,o,a);break;case 1:t=new re(r,i);break;case 2:let e=Math.PI/3;void 0!==n.InnerAngle&&(e=d.degToRad(n.InnerAngle.value));let s=0;void 0!==n.OuterAngle&&(s=d.degToRad(n.OuterAngle.value),s=Math.max(s,1)),t=new te(r,i,o,e,s,a);break;default:console.warn("THREE.FBXLoader: Unknown light type "+n.LightType.value+", defaulting to a PointLight."),t=new ne(r,i)}void 0!==n.CastShadows&&1===n.CastShadows.value&&(t.castShadow=!0)}return t}createMesh(e,t,n){let r,i=null,o=null;const a=[];return e.children.forEach(function(e){t.has(e.ID)&&(i=t.get(e.ID)),n.has(e.ID)&&a.push(n.get(e.ID))}),a.length>1?o=a:a.length>0?o=a[0]:(o=new Be({name:X.DEFAULT_MATERIAL_NAME,color:13421772}),a.push(o)),"color"in i.attributes&&a.forEach(function(e){e.vertexColors=!0}),i.FBX_Deformer?(r=new Ee(i,o),r.normalizeSkinWeights()):r=new S(i,o),r}createCurve(e,t){const n=e.children.reduce(function(e,n){return t.has(n.ID)&&(e=t.get(n.ID)),e},null),r=new T({name:X.DEFAULT_MATERIAL_NAME,color:3342591,linewidth:1});return new M(n,r)}getTransformData(e,t){const n={};"InheritType"in t&&(n.inheritType=parseInt(t.InheritType.value)),n.eulerOrder="RotationOrder"in t?Ja(t.RotationOrder.value):"ZYX","Lcl_Translation"in t&&(n.translation=t.Lcl_Translation.value),"PreRotation"in t&&(n.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(n.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(n.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(n.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(n.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(n.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(n.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(n.rotationPivot=t.RotationPivot.value),e.userData.transformData=n}setLookAtProperties(e,t){if("LookAtProperty"in t){Da.get(e.ID).children.forEach(function(t){if("LookAtProperty"===t.relationship){const n=La.Objects.Model[t.ID];if("Lcl_Translation"in n){const t=n.Lcl_Translation.value;void 0!==e.target?(e.target.position.fromArray(t),ja.add(e.target)):e.lookAt((new f).fromArray(t))}}})}}bindSkeleton(e,t,n){const r=this.parsePoseNodes();for(const i in e){const o=e[i];Da.get(parseInt(o.ID)).parents.forEach(function(e){if(t.has(e.ID)){const t=e.ID;Da.get(t).parents.forEach(function(e){if(n.has(e.ID)){n.get(e.ID).bind(new Re(o.bones),r[e.ID])}})}})}}parsePoseNodes(){const e={};if("Pose"in La.Objects){const t=La.Objects.Pose;for(const n in t)if("BindPose"===t[n].attrType&&t[n].NbPoseNodes>0){const r=t[n].PoseNode;Array.isArray(r)?r.forEach(function(t){e[t.Node]=(new N).fromArray(t.Matrix.a)}):e[r.Node]=(new N).fromArray(r.Matrix.a)}}return e}addGlobalSceneSettings(){if("GlobalSettings"in La){if("AmbientColor"in La.GlobalSettings){const e=La.GlobalSettings.AmbientColor.value,t=e[0],n=e[1],r=e[2];if(0!==t||0!==n||0!==r){const e=new K(t,n,r).convertSRGBToLinear();ja.add(new Xe(e,1))}}"UnitScaleFactor"in La.GlobalSettings&&(ja.userData.unitScaleFactor=La.GlobalSettings.UnitScaleFactor.value)}}}class Ba{constructor(){this.negativeMaterialIndices=!1}parse(e){const t=new Map;if("Geometry"in La.Objects){const n=La.Objects.Geometry;for(const r in n){const i=Da.get(parseInt(r)),o=this.parseGeometry(i,n[r],e);t.set(parseInt(r),o)}}return!0===this.negativeMaterialIndices&&console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."),t}parseGeometry(e,t,n){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,n);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,n){const r=n.skeletons,i=[],o=e.parents.map(function(e){return La.Objects.Model[e.ID]});if(0===o.length)return;const a=e.children.reduce(function(e,t){return void 0!==r[t.ID]&&(e=r[t.ID]),e},null);e.children.forEach(function(e){void 0!==n.morphTargets[e.ID]&&i.push(n.morphTargets[e.ID])});const s=o[0],c={};"RotationOrder"in s&&(c.eulerOrder=Ja(s.RotationOrder.value)),"InheritType"in s&&(c.inheritType=parseInt(s.InheritType.value)),"GeometricTranslation"in s&&(c.translation=s.GeometricTranslation.value),"GeometricRotation"in s&&(c.rotation=s.GeometricRotation.value),"GeometricScaling"in s&&(c.scale=s.GeometricScaling.value);const l=$a(c);return this.genGeometry(t,a,i,l)}genGeometry(e,t,n,r){const i=new O;e.attrName&&(i.name=e.attrName);const o=this.parseGeoNode(e,t),a=this.genBuffers(o),s=new k(a.vertex,3);if(s.applyMatrix4(r),i.setAttribute("position",s),a.colors.length>0&&i.setAttribute("color",new k(a.colors,3)),t&&(i.setAttribute("skinIndex",new qe(a.weightsIndices,4)),i.setAttribute("skinWeight",new k(a.vertexWeights,4)),i.FBX_Deformer=t),a.normal.length>0){const e=(new Ye).getNormalMatrix(r),t=new k(a.normal,3);t.applyNormalMatrix(e),i.setAttribute("normal",t)}if(a.uvs.forEach(function(e,t){const n=0===t?"uv":`uv${t}`;i.setAttribute(n,new k(a.uvs[t],2))}),o.material&&"AllSame"!==o.material.mappingType){let e=a.materialIndex[0],t=0;if(a.materialIndex.forEach(function(n,r){n!==e&&(i.addGroup(t,r-t,e),e=n,t=r)}),i.groups.length>0){const t=i.groups[i.groups.length-1],n=t.start+t.count;n!==a.materialIndex.length&&i.addGroup(n,a.materialIndex.length-n,e)}0===i.groups.length&&i.addGroup(0,a.materialIndex.length,a.materialIndex[0])}return this.addMorphTargets(i,e,n,r),i}parseGeoNode(e,t){const n={};if(n.vertexPositions=void 0!==e.Vertices?e.Vertices.a:[],n.vertexIndices=void 0!==e.PolygonVertexIndex?e.PolygonVertexIndex.a:[],e.LayerElementColor&&(n.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(n.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(n.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){n.uv=[];let t=0;for(;e.LayerElementUV[t];)e.LayerElementUV[t].UV&&n.uv.push(this.parseUVs(e.LayerElementUV[t])),t++}return n.weightTable={},null!==t&&(n.skeleton=t,t.rawBones.forEach(function(e,t){e.indices.forEach(function(r,i){void 0===n.weightTable[r]&&(n.weightTable[r]=[]),n.weightTable[r].push({id:t,weight:e.weights[i]})})})),n}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let n=0,r=0,i=!1,o=[],a=[],s=[],c=[],l=[],u=[];const h=this;return e.vertexIndices.forEach(function(d,p){let f,m=!1;d<0&&(d^=-1,m=!0);let g=[],b=[];if(o.push(3*d,3*d+1,3*d+2),e.color){const t=Ka(p,n,d,e.color);s.push(t[0],t[1],t[2])}if(e.skeleton){if(void 0!==e.weightTable[d]&&e.weightTable[d].forEach(function(e){b.push(e.weight),g.push(e.id)}),b.length>4){i||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),i=!0);const e=[0,0,0,0],t=[0,0,0,0];b.forEach(function(n,r){let i=n,o=g[r];t.forEach(function(t,n,r){if(i>t){r[n]=i,i=t;const a=e[n];e[n]=o,o=a}})}),g=e,b=t}for(;b.length<4;)b.push(0),g.push(0);for(let e=0;e<4;++e)l.push(b[e]),u.push(g[e])}if(e.normal){const t=Ka(p,n,d,e.normal);a.push(t[0],t[1],t[2])}e.material&&"AllSame"!==e.material.mappingType&&(f=Ka(p,n,d,e.material)[0],f<0&&(h.negativeMaterialIndices=!0,f=0)),e.uv&&e.uv.forEach(function(e,t){const r=Ka(p,n,d,e);void 0===c[t]&&(c[t]=[]),c[t].push(r[0]),c[t].push(r[1])}),r++,m&&(h.genFace(t,e,o,f,a,s,c,l,u,r),n++,r=0,o=[],a=[],s=[],c=[],l=[],u=[])}),t}getNormalNewell(e){const t=new f(0,0,0);for(let n=0;n<e.length;n++){const r=e[n],i=e[(n+1)%e.length];t.x+=(r.y-i.y)*(r.z+i.z),t.y+=(r.z-i.z)*(r.x+i.x),t.z+=(r.x-i.x)*(r.y+i.y)}return t.normalize(),t}getNormalTangentAndBitangent(e){const t=this.getNormalNewell(e),n=(Math.abs(t.z)>.5?new f(0,1,0):new f(0,0,1)).cross(t).normalize(),r=t.clone().cross(n).normalize();return{normal:t,tangent:n,bitangent:r}}flattenVertex(e,t,n){return new v(e.dot(t),e.dot(n))}genFace(e,t,n,r,i,o,a,s,c,l){let u;if(l>3){const e=[];for(let r=0;r<n.length;r+=3)e.push(new f(t.vertexPositions[n[r]],t.vertexPositions[n[r+1]],t.vertexPositions[n[r+2]]));const{tangent:r,bitangent:i}=this.getNormalTangentAndBitangent(e),o=[];for(const t of e)o.push(this.flattenVertex(t,r,i));u=Ke.triangulateShape(o,[])}else u=[[0,1,2]];for(const[l,h,d]of u)e.vertex.push(t.vertexPositions[n[3*l]]),e.vertex.push(t.vertexPositions[n[3*l+1]]),e.vertex.push(t.vertexPositions[n[3*l+2]]),e.vertex.push(t.vertexPositions[n[3*h]]),e.vertex.push(t.vertexPositions[n[3*h+1]]),e.vertex.push(t.vertexPositions[n[3*h+2]]),e.vertex.push(t.vertexPositions[n[3*d]]),e.vertex.push(t.vertexPositions[n[3*d+1]]),e.vertex.push(t.vertexPositions[n[3*d+2]]),t.skeleton&&(e.vertexWeights.push(s[4*l]),e.vertexWeights.push(s[4*l+1]),e.vertexWeights.push(s[4*l+2]),e.vertexWeights.push(s[4*l+3]),e.vertexWeights.push(s[4*h]),e.vertexWeights.push(s[4*h+1]),e.vertexWeights.push(s[4*h+2]),e.vertexWeights.push(s[4*h+3]),e.vertexWeights.push(s[4*d]),e.vertexWeights.push(s[4*d+1]),e.vertexWeights.push(s[4*d+2]),e.vertexWeights.push(s[4*d+3]),e.weightsIndices.push(c[4*l]),e.weightsIndices.push(c[4*l+1]),e.weightsIndices.push(c[4*l+2]),e.weightsIndices.push(c[4*l+3]),e.weightsIndices.push(c[4*h]),e.weightsIndices.push(c[4*h+1]),e.weightsIndices.push(c[4*h+2]),e.weightsIndices.push(c[4*h+3]),e.weightsIndices.push(c[4*d]),e.weightsIndices.push(c[4*d+1]),e.weightsIndices.push(c[4*d+2]),e.weightsIndices.push(c[4*d+3])),t.color&&(e.colors.push(o[3*l]),e.colors.push(o[3*l+1]),e.colors.push(o[3*l+2]),e.colors.push(o[3*h]),e.colors.push(o[3*h+1]),e.colors.push(o[3*h+2]),e.colors.push(o[3*d]),e.colors.push(o[3*d+1]),e.colors.push(o[3*d+2])),t.material&&"AllSame"!==t.material.mappingType&&(e.materialIndex.push(r),e.materialIndex.push(r),e.materialIndex.push(r)),t.normal&&(e.normal.push(i[3*l]),e.normal.push(i[3*l+1]),e.normal.push(i[3*l+2]),e.normal.push(i[3*h]),e.normal.push(i[3*h+1]),e.normal.push(i[3*h+2]),e.normal.push(i[3*d]),e.normal.push(i[3*d+1]),e.normal.push(i[3*d+2])),t.uv&&t.uv.forEach(function(t,n){void 0===e.uvs[n]&&(e.uvs[n]=[]),e.uvs[n].push(a[n][2*l]),e.uvs[n].push(a[n][2*l+1]),e.uvs[n].push(a[n][2*h]),e.uvs[n].push(a[n][2*h+1]),e.uvs[n].push(a[n][2*d]),e.uvs[n].push(a[n][2*d+1])})}addMorphTargets(e,t,n,r){if(0===n.length)return;e.morphTargetsRelative=!0,e.morphAttributes.position=[];const i=this;n.forEach(function(n){n.rawTargets.forEach(function(n){const o=La.Objects.Geometry[n.geoID];void 0!==o&&i.genMorphGeometry(e,t,o,r,n.name)})})}genMorphGeometry(e,t,n,r,i){const o=void 0!==t.PolygonVertexIndex?t.PolygonVertexIndex.a:[],a=void 0!==n.Vertices?n.Vertices.a:[],s=void 0!==n.Indexes?n.Indexes.a:[],c=3*e.attributes.position.count,l=new Float32Array(c);for(let e=0;e<s.length;e++){const t=3*s[e];l[t]=a[3*e],l[t+1]=a[3*e+1],l[t+2]=a[3*e+2]}const u={vertexIndices:o,vertexPositions:l},h=this.genBuffers(u),d=new k(h.vertex,3);d.name=i||n.attrName,d.applyMatrix4(r),e.morphAttributes.position.push(d)}parseNormals(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,r=e.Normals.a;let i=[];return"IndexToDirect"===n&&("NormalIndex"in e?i=e.NormalIndex.a:"NormalsIndex"in e&&(i=e.NormalsIndex.a)),{dataSize:3,buffer:r,indices:i,mappingType:t,referenceType:n}}parseUVs(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,r=e.UV.a;let i=[];return"IndexToDirect"===n&&(i=e.UVIndex.a),{dataSize:2,buffer:r,indices:i,mappingType:t,referenceType:n}}parseVertexColors(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,r=e.Colors.a;let i=[];"IndexToDirect"===n&&(i=e.ColorIndex.a);for(let e=0,t=new K;e<r.length;e+=4)t.fromArray(r,e).convertSRGBToLinear().toArray(r,e);return{dataSize:4,buffer:r,indices:i,mappingType:t,referenceType:n}}parseMaterialIndices(e){const t=e.MappingInformationType,n=e.ReferenceInformationType;if("NoMappingInformation"===t)return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:n};const r=e.Materials.a,i=[];for(let e=0;e<r.length;++e)i.push(e);return{dataSize:1,buffer:r,indices:i,mappingType:t,referenceType:n}}parseNurbsGeometry(e){const t=parseInt(e.Order);if(isNaN(t))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",e.Order,e.id),new O;const n=t-1,r=e.KnotVector.a,i=[],o=e.Points.a;for(let e=0,t=o.length;e<t;e+=4)i.push((new He).fromArray(o,e));let a,s;if("Closed"===e.Form)i.push(i[0]);else if("Periodic"===e.Form){a=n,s=r.length-1-a;for(let e=0;e<n;++e)i.push(i[e])}const c=new Na(n,r,i,a,s).getPoints(12*i.length);return(new O).setFromPoints(c)}}class za{parse(){const e=[],t=this.parseClips();if(void 0!==t)for(const n in t){const r=t[n],i=this.addClip(r);e.push(i)}return e}parseClips(){if(void 0===La.Objects.AnimationCurve)return;const e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);const t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}parseAnimationCurveNodes(){const e=La.Objects.AnimationCurveNode,t=new Map;for(const n in e){const r=e[n];if(null!==r.attrName.match(/S|R|T|DeformPercent/)){const e={id:r.id,attr:r.attrName,curves:{}};t.set(e.id,e)}}return t}parseAnimationCurves(e){const t=La.Objects.AnimationCurve;for(const n in t){const r={id:t[n].id,times:t[n].KeyTime.a.map(qa),values:t[n].KeyValueFloat.a},i=Da.get(r.id);if(void 0!==i){const t=i.parents[0].ID,n=i.parents[0].relationship;n.match(/X/)?e.get(t).curves.x=r:n.match(/Y/)?e.get(t).curves.y=r:n.match(/Z/)?e.get(t).curves.z=r:n.match(/DeformPercent/)&&e.has(t)&&(e.get(t).curves.morph=r)}}}parseAnimationLayers(e){const t=La.Objects.AnimationLayer,n=new Map;for(const r in t){const t=[],i=Da.get(parseInt(r));if(void 0!==i){i.children.forEach(function(n,r){if(e.has(n.ID)){const i=e.get(n.ID);if(void 0!==i.curves.x||void 0!==i.curves.y||void 0!==i.curves.z){if(void 0===t[r]){const e=Da.get(n.ID).parents.filter(function(e){return void 0!==e.relationship})[0].ID;if(void 0!==e){const i=La.Objects.Model[e.toString()];if(void 0===i)return void console.warn("THREE.FBXLoader: Encountered a unused curve.",n);const o={modelName:i.attrName?we.sanitizeNodeName(i.attrName):"",ID:i.id,initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1]};ja.traverse(function(e){e.ID===i.id&&(o.transform=e.matrix,e.userData.transformData&&(o.eulerOrder=e.userData.transformData.eulerOrder))}),o.transform||(o.transform=new N),"PreRotation"in i&&(o.preRotation=i.PreRotation.value),"PostRotation"in i&&(o.postRotation=i.PostRotation.value),t[r]=o}}t[r]&&(t[r][i.attr]=i)}else if(void 0!==i.curves.morph){if(void 0===t[r]){const e=Da.get(n.ID).parents.filter(function(e){return void 0!==e.relationship})[0].ID,i=Da.get(e).parents[0].ID,o=Da.get(i).parents[0].ID,a=Da.get(o).parents[0].ID,s=La.Objects.Model[a],c={modelName:s.attrName?we.sanitizeNodeName(s.attrName):"",morphName:La.Objects.Deformer[e].attrName};t[r]=c}t[r][i.attr]=i}}}),n.set(parseInt(r),t)}}return n}parseAnimStacks(e){const t=La.Objects.AnimationStack,n={};for(const r in t){const i=Da.get(parseInt(r)).children;i.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const o=e.get(i[0].ID);n[r]={name:t[r].attrName,layer:o}}return n}addClip(e){let t=[];const n=this;return e.layer.forEach(function(e){t=t.concat(n.generateTracks(e))}),new Me(e.name,-1,t)}generateTracks(e){const t=[];let n=new f,r=new f;if(e.transform&&e.transform.decompose(n,new y,r),n=n.toArray(),r=r.toArray(),void 0!==e.T&&Object.keys(e.T.curves).length>0){const r=this.generateVectorTrack(e.modelName,e.T.curves,n,"position");void 0!==r&&t.push(r)}if(void 0!==e.R&&Object.keys(e.R.curves).length>0){const n=this.generateRotationTrack(e.modelName,e.R.curves,e.preRotation,e.postRotation,e.eulerOrder);void 0!==n&&t.push(n)}if(void 0!==e.S&&Object.keys(e.S.curves).length>0){const n=this.generateVectorTrack(e.modelName,e.S.curves,r,"scale");void 0!==n&&t.push(n)}if(void 0!==e.DeformPercent){const n=this.generateMorphTrack(e);void 0!==n&&t.push(n)}return t}generateVectorTrack(e,t,n,r){const i=this.getTimesForAllAxes(t),o=this.getKeyframeTrackValues(i,t,n);return new Le(e+"."+r,i,o)}generateRotationTrack(e,t,n,r,i){let o,a;if(void 0!==t.x&&void 0!==t.y&&void 0!==t.z){const e=this.interpolateRotations(t.x,t.y,t.z,i);o=e[0],a=e[1]}void 0!==n&&((n=n.map(d.degToRad)).push(i),n=(new _).fromArray(n),n=(new y).setFromEuler(n)),void 0!==r&&((r=r.map(d.degToRad)).push(i),r=(new _).fromArray(r),r=(new y).setFromEuler(r).invert());const s=new y,c=new _,l=[];if(!a||!o)return new je(e+".quaternion",[],[]);for(let e=0;e<a.length;e+=3){if(c.set(a[e],a[e+1],a[e+2],i),s.setFromEuler(c),void 0!==n&&s.premultiply(n),void 0!==r&&s.multiply(r),e>2){(new y).fromArray(l,(e-3)/3*4).dot(s)<0&&s.set(-s.x,-s.y,-s.z,-s.w)}s.toArray(l,e/3*4)}return new je(e+".quaternion",o,l)}generateMorphTrack(e){const t=e.DeformPercent.curves.morph,n=t.values.map(function(e){return e/100}),r=ja.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new De(e.modelName+".morphTargetInfluences["+r+"]",t.times,n)}getTimesForAllAxes(e){let t=[];if(void 0!==e.x&&(t=t.concat(e.x.times)),void 0!==e.y&&(t=t.concat(e.y.times)),void 0!==e.z&&(t=t.concat(e.z.times)),t=t.sort(function(e,t){return e-t}),t.length>1){let e=1,n=t[0];for(let r=1;r<t.length;r++){const i=t[r];i!==n&&(t[e]=i,n=i,e++)}t=t.slice(0,e)}return t}getKeyframeTrackValues(e,t,n){const r=n,i=[];let o=-1,a=-1,s=-1;return e.forEach(function(e){if(t.x&&(o=t.x.times.indexOf(e)),t.y&&(a=t.y.times.indexOf(e)),t.z&&(s=t.z.times.indexOf(e)),-1!==o){const e=t.x.values[o];i.push(e),r[0]=e}else i.push(r[0]);if(-1!==a){const e=t.y.values[a];i.push(e),r[1]=e}else i.push(r[1]);if(-1!==s){const e=t.z.values[s];i.push(e),r[2]=e}else i.push(r[2])}),i}interpolateRotations(e,t,n,r){const i=[],o=[];i.push(e.times[0]),o.push(d.degToRad(e.values[0])),o.push(d.degToRad(t.values[0])),o.push(d.degToRad(n.values[0]));for(let a=1;a<e.values.length;a++){const s=[e.values[a-1],t.values[a-1],n.values[a-1]];if(isNaN(s[0])||isNaN(s[1])||isNaN(s[2]))continue;const c=s.map(d.degToRad),l=[e.values[a],t.values[a],n.values[a]];if(isNaN(l[0])||isNaN(l[1])||isNaN(l[2]))continue;const u=l.map(d.degToRad),h=[l[0]-s[0],l[1]-s[1],l[2]-s[2]],p=[Math.abs(h[0]),Math.abs(h[1]),Math.abs(h[2])];if(p[0]>=180||p[1]>=180||p[2]>=180){const t=Math.max(...p)/180,n=new _(...c,r),s=new _(...u,r),l=(new y).setFromEuler(n),h=(new y).setFromEuler(s);l.dot(h)&&h.set(-h.x,-h.y,-h.z,-h.w);const d=e.times[a-1],f=e.times[a]-d,m=new y,g=new _;for(let e=0;e<1;e+=1/t)m.copy(l.clone().slerp(h.clone(),e)),i.push(d+e*f),g.setFromQuaternion(m,r),o.push(g.x),o.push(g.y),o.push(g.z)}else i.push(e.times[a]),o.push(d.degToRad(e.values[a])),o.push(d.degToRad(t.values[a])),o.push(d.degToRad(n.values[a]))}return[i,o]}}class Ha{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new Wa,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,n=e.split(/[\r\n]+/);return n.forEach(function(e,r){const i=e.match(/^[\s\t]*;/),o=e.match(/^[\s\t]*$/);if(i||o)return;const a=e.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),s=e.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),c=e.match("^\\t{"+(t.currentIndent-1)+"}}");a?t.parseNodeBegin(e,a):s?t.parseNodeProperty(e,s,n[++r]):c?t.popStack():e.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(e)}),this.allNodes}parseNodeBegin(e,t){const n=t[1].trim().replace(/^"/,"").replace(/"$/,""),r=t[2].split(",").map(function(e){return e.trim().replace(/^"/,"").replace(/"$/,"")}),i={name:n},o=this.parseNodeAttr(r),a=this.getCurrentNode();0===this.currentIndent?this.allNodes.add(n,i):n in a?("PoseNode"===n?a.PoseNode.push(i):void 0!==a[n].id&&(a[n]={},a[n][a[n].id]=a[n]),""!==o.id&&(a[n][o.id]=i)):"number"==typeof o.id?(a[n]={},a[n][o.id]=i):"Properties70"!==n&&(a[n]="PoseNode"===n?[i]:i),"number"==typeof o.id&&(i.id=o.id),""!==o.name&&(i.attrName=o.name),""!==o.type&&(i.attrType=o.type),this.pushStack(i)}parseNodeAttr(e){let t=e[0];""!==e[0]&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let n="",r="";return e.length>1&&(n=e[1].replace(/^(\w+)::/,""),r=e[2]),{id:t,name:n,type:r}}parseNodeProperty(e,t,n){let r=t[1].replace(/^"/,"").replace(/"$/,"").trim(),i=t[2].replace(/^"/,"").replace(/"$/,"").trim();"Content"===r&&","===i&&(i=n.replace(/"/g,"").replace(/,$/,"").trim());const o=this.getCurrentNode();if("Properties70"!==o.name){if("C"===r){const e=i.split(",").slice(1),t=parseInt(e[0]),n=parseInt(e[1]);let a=i.split(",").slice(3);a=a.map(function(e){return e.trim().replace(/^"/,"")}),r="connections",i=[t,n],function(e,t){for(let n=0,r=e.length,i=t.length;n<i;n++,r++)e[r]=t[n]}(i,a),void 0===o[r]&&(o[r]=[])}"Node"===r&&(o.id=i),r in o&&Array.isArray(o[r])?o[r].push(i):"a"!==r?o[r]=i:o.a=i,this.setCurrentProp(o,r),"a"===r&&","!==i.slice(-1)&&(o.a=es(i))}else this.parseNodeSpecialProperty(e,r,i)}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,","!==e.slice(-1)&&(t.a=es(t.a))}parseNodeSpecialProperty(e,t,n){const r=n.split('",').map(function(e){return e.trim().replace(/^\"/,"").replace(/\s/,"_")}),i=r[0],o=r[1],a=r[2],s=r[3];let c=r[4];switch(o){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":c=parseFloat(c);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":c=es(c)}this.getPrevNode()[i]={type:o,type2:a,flag:s,value:c},this.setCurrentProp(this.getPrevNode(),i)}}class Va{parse(e){const t=new Ga(e);t.skip(23);const n=t.getUint32();if(n<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+n);const r=new Wa;for(;!this.endOfContent(t);){const e=this.parseNode(t,n);null!==e&&r.add(e.name,e)}return r}endOfContent(e){return e.size()%16==0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const n={},r=t>=7500?e.getUint64():e.getUint32(),i=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const o=e.getUint8(),a=e.getString(o);if(0===r)return null;const s=[];for(let t=0;t<i;t++)s.push(this.parseProperty(e));const c=s.length>0?s[0]:"",l=s.length>1?s[1]:"",u=s.length>2?s[2]:"";for(n.singleProperty=1===i&&e.getOffset()===r;r>e.getOffset();){const r=this.parseNode(e,t);null!==r&&this.parseSubNode(a,n,r)}return n.propertyList=s,"number"==typeof c&&(n.id=c),""!==l&&(n.attrName=l),""!==u&&(n.attrType=u),""!==a&&(n.name=a),n}parseSubNode(e,t,n){if(!0===n.singleProperty){const e=n.propertyList[0];Array.isArray(e)?(t[n.name]=n,n.a=e):t[n.name]=e}else if("Connections"===e&&"C"===n.name){const e=[];n.propertyList.forEach(function(t,n){0!==n&&e.push(t)}),void 0===t.connections&&(t.connections=[]),t.connections.push(e)}else if("Properties70"===n.name){Object.keys(n).forEach(function(e){t[e]=n[e]})}else if("Properties70"===e&&"P"===n.name){let e=n.propertyList[0],r=n.propertyList[1];const i=n.propertyList[2],o=n.propertyList[3];let a;0===e.indexOf("Lcl ")&&(e=e.replace("Lcl ","Lcl_")),0===r.indexOf("Lcl ")&&(r=r.replace("Lcl ","Lcl_")),a="Color"===r||"ColorRGB"===r||"Vector"===r||"Vector3D"===r||0===r.indexOf("Lcl_")?[n.propertyList[4],n.propertyList[5],n.propertyList[6]]:n.propertyList[4],t[e]={type:r,type2:i,flag:o,value:a}}else void 0===t[n.name]?"number"==typeof n.id?(t[n.name]={},t[n.name][n.id]=n):t[n.name]=n:"PoseNode"===n.name?(Array.isArray(t[n.name])||(t[n.name]=[t[n.name]]),t[n.name].push(n)):void 0===t[n.name][n.id]&&(t[n.name][n.id]=n)}parseProperty(e){const t=e.getString(1);let n;switch(t){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return n=e.getUint32(),e.getArrayBuffer(n);case"S":return n=e.getUint32(),e.getString(n);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const r=e.getUint32(),i=e.getUint32(),o=e.getUint32();if(0===i)switch(t){case"b":case"c":return e.getBooleanArray(r);case"d":return e.getFloat64Array(r);case"f":return e.getFloat32Array(r);case"i":return e.getInt32Array(r);case"l":return e.getInt64Array(r)}const a=Nt(new Uint8Array(e.getArrayBuffer(o))),s=new Ga(a.buffer);switch(t){case"b":case"c":return s.getBooleanArray(r);case"d":return s.getFloat64Array(r);case"f":return s.getFloat32Array(r);case"i":return s.getInt32Array(r);case"l":return s.getInt64Array(r)}break;default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}}class Ga{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=void 0===t||t,this._textDecoder=new TextDecoder}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return!(1&~this.getUint8())}getBooleanArray(e){const t=[];for(let n=0;n<e;n++)t.push(this.getBoolean());return t}getUint8(){const e=this.dv.getUint8(this.offset);return this.offset+=1,e}getInt16(){const e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}getInt32(){const e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}getInt32Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getInt32());return t}getUint32(){const e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}getInt64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),2147483648&t?(t=4294967295&~t,e=4294967295&~e,4294967295===e&&(t=t+1&4294967295),e=e+1&4294967295,-(4294967296*t+e)):4294967296*t+e}getInt64Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getInt64());return t}getUint64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),4294967296*t+e}getFloat32(){const e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}getFloat32Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getFloat32());return t}getFloat64(){const e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}getFloat64Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getFloat64());return t}getArrayBuffer(e){const t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}getString(e){const t=this.offset;let n=new Uint8Array(this.dv.buffer,t,e);this.skip(e);const r=n.indexOf(0);return r>=0&&(n=new Uint8Array(this.dv.buffer,t,r)),this._textDecoder.decode(n)}}class Wa{add(e,t){this[e]=t}}function Xa(e){const t=e.match(/FBXVersion: (\d+)/);if(t){return parseInt(t[1])}throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function qa(e){return e/46186158e3}const Ya=[];function Ka(e,t,n,r){let i;switch(r.mappingType){case"ByPolygonVertex":i=e;break;case"ByPolygon":i=t;break;case"ByVertice":i=n;break;case"AllSame":i=r.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+r.mappingType)}"IndexToDirect"===r.referenceType&&(i=r.indices[i]);const o=i*r.dataSize,a=o+r.dataSize;return function(e,t,n,r){for(let i=n,o=0;i<r;i++,o++)e[o]=t[i];return e}(Ya,r.buffer,o,a)}const Qa=new _,Za=new f;function $a(e){const t=new N,n=new N,r=new N,i=new N,o=new N,a=new N,s=new N,c=new N,l=new N,u=new N,h=new N,p=new N,m=e.inheritType?e.inheritType:0;if(e.translation&&t.setPosition(Za.fromArray(e.translation)),e.preRotation){const t=e.preRotation.map(d.degToRad);t.push(e.eulerOrder||_.DEFAULT_ORDER),n.makeRotationFromEuler(Qa.fromArray(t))}if(e.rotation){const t=e.rotation.map(d.degToRad);t.push(e.eulerOrder||_.DEFAULT_ORDER),r.makeRotationFromEuler(Qa.fromArray(t))}if(e.postRotation){const t=e.postRotation.map(d.degToRad);t.push(e.eulerOrder||_.DEFAULT_ORDER),i.makeRotationFromEuler(Qa.fromArray(t)),i.invert()}e.scale&&o.scale(Za.fromArray(e.scale)),e.scalingOffset&&s.setPosition(Za.fromArray(e.scalingOffset)),e.scalingPivot&&a.setPosition(Za.fromArray(e.scalingPivot)),e.rotationOffset&&c.setPosition(Za.fromArray(e.rotationOffset)),e.rotationPivot&&l.setPosition(Za.fromArray(e.rotationPivot)),e.parentMatrixWorld&&(h.copy(e.parentMatrix),u.copy(e.parentMatrixWorld));const g=n.clone().multiply(r).multiply(i),b=new N;b.extractRotation(u);const y=new N;y.copyPosition(u);const v=y.clone().invert().multiply(u),x=b.clone().invert().multiply(v),w=o,E=new N;if(0===m)E.copy(b).multiply(g).multiply(x).multiply(w);else if(1===m)E.copy(b).multiply(x).multiply(g).multiply(w);else{const e=(new N).scale((new f).setFromMatrixScale(h)).clone().invert(),t=x.clone().multiply(e);E.copy(b).multiply(g).multiply(t).multiply(w)}const T=l.clone().invert(),A=a.clone().invert();let C=t.clone().multiply(c).multiply(l).multiply(n).multiply(r).multiply(i).multiply(T).multiply(s).multiply(a).multiply(o).multiply(A);const O=(new N).copyPosition(C),k=u.clone().multiply(O);return p.copyPosition(k),C=p.clone().multiply(E),C.premultiply(u.invert()),C}function Ja(e){const t=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return 6===(e=e||0)?(console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),t[0]):t[e]}function es(e){return e.split(",").map(function(e){return parseFloat(e)})}function ts(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=e.byteLength),(new TextDecoder).decode(new Uint8Array(e,t,n))}let ns=class extends t{constructor(e){super(e)}parse(e){const t=0,n=1,r=2,i=3,o=9,a=10,s=11,c=48,l=4,u=0,h=1,d=2,p=3;if(e.length<19)throw new Error("THREE.TGALoader: Not enough data to contain header.");let f=0;const m=new Uint8Array(e),g={id_length:m[f++],colormap_type:m[f++],image_type:m[f++],colormap_index:m[f++]|m[f++]<<8,colormap_length:m[f++]|m[f++]<<8,colormap_size:m[f++],origin:[m[f++]|m[f++]<<8,m[f++]|m[f++]<<8],width:m[f++]|m[f++]<<8,height:m[f++]|m[f++]<<8,pixel_size:m[f++],flags:m[f++]};if(function(e){switch(e.image_type){case n:case o:if(e.colormap_length>256||24!==e.colormap_size||1!==e.colormap_type)throw new Error("THREE.TGALoader: Invalid type colormap data for indexed type.");break;case r:case i:case a:case s:if(e.colormap_type)throw new Error("THREE.TGALoader: Invalid type colormap data for colormap type.");break;case t:throw new Error("THREE.TGALoader: No data.");default:throw new Error("THREE.TGALoader: Invalid type "+e.image_type)}if(e.width<=0||e.height<=0)throw new Error("THREE.TGALoader: Invalid image size.");if(8!==e.pixel_size&&16!==e.pixel_size&&24!==e.pixel_size&&32!==e.pixel_size)throw new Error("THREE.TGALoader: Invalid pixel size "+e.pixel_size)}(g),g.id_length+f>e.length)throw new Error("THREE.TGALoader: No data.");f+=g.id_length;let b=!1,y=!1,v=!1;switch(g.image_type){case o:b=!0,y=!0;break;case n:y=!0;break;case a:b=!0;break;case r:break;case s:b=!0,v=!0;break;case i:v=!0}const x=new Uint8Array(g.width*g.height*4),w=function(e,t,n,r,i){let o,a;const s=n.pixel_size>>3,c=n.width*n.height*s;if(t&&(a=i.subarray(r,r+=n.colormap_length*(n.colormap_size>>3))),e){let e,t,n;o=new Uint8Array(c);let a=0;const l=new Uint8Array(s);for(;a<c;)if(e=i[r++],t=1+(127&e),128&e){for(n=0;n<s;++n)l[n]=i[r++];for(n=0;n<t;++n)o.set(l,a+n*s);a+=s*t}else{for(t*=s,n=0;n<t;++n)o[a+n]=i[r++];a+=t}}else o=i.subarray(r,r+=t?n.width*n.height:c);return{pixel_data:o,palettes:a}}(b,y,g,f,m);return function(e,t,n,r,i){let o,a,s,f,m,b;switch((g.flags&c)>>l){default:case d:o=0,s=1,m=t,a=0,f=1,b=n;break;case u:o=0,s=1,m=t,a=n-1,f=-1,b=-1;break;case p:o=t-1,s=-1,m=-1,a=0,f=1,b=n;break;case h:o=t-1,s=-1,m=-1,a=n-1,f=-1,b=-1}if(v)switch(g.pixel_size){case 8:!function(e,t,n,r,i,o,a,s){let c,l,u,h=0;const d=g.width;for(u=t;u!==r;u+=n)for(l=i;l!==a;l+=o,h++)c=s[h],e[4*(l+d*u)+0]=c,e[4*(l+d*u)+1]=c,e[4*(l+d*u)+2]=c,e[4*(l+d*u)+3]=255}(e,a,f,b,o,s,m,r);break;case 16:!function(e,t,n,r,i,o,a,s){let c,l,u=0;const h=g.width;for(l=t;l!==r;l+=n)for(c=i;c!==a;c+=o,u+=2)e[4*(c+h*l)+0]=s[u+0],e[4*(c+h*l)+1]=s[u+0],e[4*(c+h*l)+2]=s[u+0],e[4*(c+h*l)+3]=s[u+1]}(e,a,f,b,o,s,m,r);break;default:throw new Error("THREE.TGALoader: Format not supported.")}else switch(g.pixel_size){case 8:!function(e,t,n,r,i,o,a,s,c){const l=c;let u,h,d,p=0;const f=g.width;for(d=t;d!==r;d+=n)for(h=i;h!==a;h+=o,p++)u=s[p],e[4*(h+f*d)+3]=255,e[4*(h+f*d)+2]=l[3*u+0],e[4*(h+f*d)+1]=l[3*u+1],e[4*(h+f*d)+0]=l[3*u+2]}(e,a,f,b,o,s,m,r,i);break;case 16:!function(e,t,n,r,i,o,a,s){let c,l,u,h=0;const d=g.width;for(u=t;u!==r;u+=n)for(l=i;l!==a;l+=o,h+=2)c=s[h+0]+(s[h+1]<<8),e[4*(l+d*u)+0]=(31744&c)>>7,e[4*(l+d*u)+1]=(992&c)>>2,e[4*(l+d*u)+2]=(31&c)<<3,e[4*(l+d*u)+3]=32768&c?0:255}(e,a,f,b,o,s,m,r);break;case 24:!function(e,t,n,r,i,o,a,s){let c,l,u=0;const h=g.width;for(l=t;l!==r;l+=n)for(c=i;c!==a;c+=o,u+=3)e[4*(c+h*l)+3]=255,e[4*(c+h*l)+2]=s[u+0],e[4*(c+h*l)+1]=s[u+1],e[4*(c+h*l)+0]=s[u+2]}(e,a,f,b,o,s,m,r);break;case 32:!function(e,t,n,r,i,o,a,s){let c,l,u=0;const h=g.width;for(l=t;l!==r;l+=n)for(c=i;c!==a;c+=o,u+=4)e[4*(c+h*l)+2]=s[u+0],e[4*(c+h*l)+1]=s[u+1],e[4*(c+h*l)+0]=s[u+2],e[4*(c+h*l)+3]=s[u+3]}(e,a,f,b,o,s,m,r);break;default:throw new Error("THREE.TGALoader: Format not supported.")}}(x,g.width,g.height,w.pixel_data,w.palettes),{data:x,width:g.width,height:g.height,flipY:!0,generateMipmaps:!0,minFilter:ue}}};class rs extends X{load(e,t,n,r){const i=this,o=""===i.path?J.extractUrlBase(e):i.path,a=new q(i.manager);a.setPath(i.path),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e,t){function n(e,t){const n=[],r=e.childNodes;for(let e=0,i=r.length;e<i;e++){const i=r[e];i.nodeName===t&&n.push(i)}return n}function r(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,r=t.length;e<r;e++)n[e]=t[e];return n}function i(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,r=t.length;e<r;e++)n[e]=parseFloat(t[e]);return n}function o(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,r=t.length;e<r;e++)n[e]=parseInt(t[e]);return n}function a(e){return e.substring(1)}function s(){return"three_default_"+Nt++}function c(e){return 0===Object.keys(e).length}function l(e){return void 0!==e&&!0===e.hasAttribute("meter")?parseFloat(e.getAttribute("meter")):1}function u(e){return void 0!==e?e.textContent:"Y_UP"}function h(e,t,r,i){const o=n(e,t)[0];if(void 0!==o){const e=n(o,r);for(let t=0;t<e.length;t++)i(e[t])}}function p(e,t){for(const n in e){e[n].build=t(e[n])}}function m(e,t){return void 0!==e.build||(e.build=t(e)),e.build}function g(e){const t={inputs:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"input"===r.nodeName){const e=a(r.getAttribute("source")),n=r.getAttribute("semantic");t.inputs[n]=e}}return t}function b(e){const t={};let n=e.getAttribute("target").split("/");const r=n.shift();let i=n.shift();const o=-1!==i.indexOf("("),s=-1!==i.indexOf(".");if(s)n=i.split("."),i=n.shift(),t.member=n.shift();else if(o){const e=i.split("(");i=e.shift();for(let t=0;t<e.length;t++)e[t]=parseInt(e[t].replace(/\)/,""));t.indices=e}return t.id=r,t.sid=i,t.arraySyntax=o,t.memberSyntax=s,t.sampler=a(e.getAttribute("source")),t}function x(e){const t=[],n=e.channels,r=e.samplers,i=e.sources;for(const e in n)if(n.hasOwnProperty(e)){const o=n[e],a=r[o.sampler],s=a.inputs.INPUT,c=a.inputs.OUTPUT;P(A(o,i[s],i[c]),t)}return t}function w(e){return m(Lt.animations[e],x)}function A(e,t,n){const r=Lt.nodes[e.id],i=xt(r.id),o=r.transforms[e.sid],a=r.matrix.clone().transpose();let s,c,l,u,h,d;const p={};switch(o){case"matrix":for(l=0,u=t.array.length;l<u;l++)if(s=t.array[l],c=l*n.stride,void 0===p[s]&&(p[s]={}),!0===e.arraySyntax){const t=n.array[c],r=e.indices[0]+4*e.indices[1];p[s][r]=t}else for(h=0,d=n.stride;h<d;h++)p[s][h]=n.array[c+h];break;case"translate":case"rotate":case"scale":console.warn('THREE.ColladaLoader: Animation transform type "%s" not yet implemented.',o)}const f=function(e,t){const n=[];for(const t in e)n.push({time:parseFloat(t),value:e[t]});n.sort(r);for(let e=0;e<16;e++)_(n,e,t.elements[e]);return n;function r(e,t){return e.time-t.time}}(p,a);return{name:i.uuid,keyframes:f}}const C=new f,R=new f,I=new y;function P(e,t){const n=e.keyframes,r=e.name,i=[],o=[],a=[],s=[];for(let e=0,t=n.length;e<t;e++){const t=n[e],r=t.time,c=t.value;lt.fromArray(c).transpose(),lt.decompose(C,I,R),i.push(r),o.push(C.x,C.y,C.z),a.push(I.x,I.y,I.z,I.w),s.push(R.x,R.y,R.z)}return o.length>0&&t.push(new Le(r+".position",i,o)),a.length>0&&t.push(new je(r+".quaternion",i,a)),s.length>0&&t.push(new Le(r+".scale",i,s)),t}function _(e,t,n){let r,i,o,a=!0;for(i=0,o=e.length;i<o;i++)r=e[i],void 0===r.value[t]?r.value[t]=null:a=!1;if(!0===a)for(i=0,o=e.length;i<o;i++)r=e[i],r.value[t]=n;else!function(e,t){let n,r;for(let i=0,o=e.length;i<o;i++){const o=e[i];if(null===o.value[t]){if(n=L(e,i,t),r=j(e,i,t),null===n){o.value[t]=r.value[t];continue}if(null===r){o.value[t]=n.value[t];continue}F(o,n,r,t)}}}(e,t)}function L(e,t,n){for(;t>=0;){const r=e[t];if(null!==r.value[n])return r;t--}return null}function j(e,t,n){for(;t<e.length;){const r=e[t];if(null!==r.value[n])return r;t++}return null}function F(e,t,n,r){n.time-t.time!==0?e.value[r]=(e.time-t.time)*(n.value[r]-t.value[r])/(n.time-t.time)+t.value[r]:e.value[r]=t.value[r]}function U(e){const t=[],n=e.name,r=e.end-e.start||-1,i=e.animations;for(let e=0,n=i.length;e<n;e++){const n=w(i[e]);for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return new Me(n,r,t)}function B(e){return m(Lt.clips[e],U)}function z(e){const t={sources:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"bind_shape_matrix":t.bindShapeMatrix=i(r.textContent);break;case"source":const e=r.getAttribute("id");t.sources[e]=Ue(r);break;case"joints":t.joints=H(r);break;case"vertex_weights":t.vertexWeights=V(r)}}return t}function H(e){const t={inputs:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"input"===r.nodeName){const e=r.getAttribute("semantic"),n=a(r.getAttribute("source"));t.inputs[e]=n}}return t}function V(e){const t={inputs:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"input":const e=r.getAttribute("semantic"),n=a(r.getAttribute("source")),i=parseInt(r.getAttribute("offset"));t.inputs[e]={id:n,offset:i};break;case"vcount":t.vcount=o(r.textContent);break;case"v":t.v=o(r.textContent)}}return t}function W(e){const t={id:e.id},n=Lt.geometries[t.id];return void 0!==e.skin&&(t.skin=function(e){const t=4,n={joints:[],indices:{array:[],stride:t},weights:{array:[],stride:t}},r=e.sources,i=e.vertexWeights,o=i.vcount,a=i.v,s=i.inputs.JOINT.offset,c=i.inputs.WEIGHT.offset,l=e.sources[e.joints.inputs.JOINT],u=e.sources[e.joints.inputs.INV_BIND_MATRIX],h=r[i.inputs.WEIGHT.id].array;let d,p,f,m=0;for(d=0,f=o.length;d<f;d++){const e=o[d],r=[];for(p=0;p<e;p++){const e=a[m+s],t=h[a[m+c]];r.push({index:e,weight:t}),m+=2}for(r.sort(g),p=0;p<t;p++){const e=r[p];void 0!==e?(n.indices.array.push(e.index),n.weights.array.push(e.weight)):(n.indices.array.push(0),n.weights.array.push(0))}}e.bindShapeMatrix?n.bindMatrix=(new N).fromArray(e.bindShapeMatrix).transpose():n.bindMatrix=(new N).identity();for(d=0,f=l.array.length;d<f;d++){const e=l.array[d],t=(new N).fromArray(u.array,d*u.stride).transpose();n.joints.push({name:e,boneInverse:t})}return n;function g(e,t){return t.weight-e.weight}}(e.skin),n.sources.skinIndices=t.skin.indices,n.sources.skinWeights=t.skin.weights),t}function q(e){return m(Lt.controllers[e],W)}function Q(e){return void 0!==e.build?e.build:e.init_from}function Z(e){const t=Lt.images[e];return void 0!==t?m(t,Q):(console.warn("THREE.ColladaLoader: Couldn't find image with ID:",e),null)}function $(e){const t={surfaces:{},samplers:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"newparam":J(r,t);break;case"technique":t.technique=oe(r);break;case"extra":t.extra=de(r)}}return t}function J(e,t){const n=e.getAttribute("sid");for(let r=0,i=e.childNodes.length;r<i;r++){const i=e.childNodes[r];if(1===i.nodeType)switch(i.nodeName){case"surface":t.surfaces[n]=ee(i);break;case"sampler2D":t.samplers[n]=ie(i)}}}function ee(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"init_from"===r.nodeName)t.init_from=r.textContent}return t}function ie(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"source"===r.nodeName)t.source=r.textContent}return t}function oe(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"constant":case"lambert":case"blinn":case"phong":t.type=r.nodeName,t.parameters=se(r);break;case"extra":t.extra=de(r)}}return t}function se(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"emission":case"diffuse":case"specular":case"bump":case"ambient":case"shininess":case"transparency":t[r.nodeName]=ce(r);break;case"transparent":t[r.nodeName]={opaque:r.hasAttribute("opaque")?r.getAttribute("opaque"):"A_ONE",data:ce(r)}}}return t}function ce(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"color":t[r.nodeName]=i(r.textContent);break;case"float":t[r.nodeName]=parseFloat(r.textContent);break;case"texture":t[r.nodeName]={id:r.getAttribute("texture"),extra:le(r)}}}return t}function le(e){const t={technique:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"extra"===r.nodeName)ue(r,t)}return t}function ue(e,t){for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique"===r.nodeName)he(r,t)}}function he(e,t){for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"repeatU":case"repeatV":case"offsetU":case"offsetV":t.technique[r.nodeName]=parseFloat(r.textContent);break;case"wrapU":case"wrapV":"TRUE"===r.textContent.toUpperCase()?t.technique[r.nodeName]=1:"FALSE"===r.textContent.toUpperCase()?t.technique[r.nodeName]=0:t.technique[r.nodeName]=parseInt(r.textContent);break;case"bump":t[r.nodeName]=fe(r)}}}function de(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique"===r.nodeName)t.technique=pe(r)}return t}function pe(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"double_sided":t[r.nodeName]=parseInt(r.textContent);break;case"bump":t[r.nodeName]=fe(r)}}return t}function fe(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"texture"===r.nodeName)t[r.nodeName]={id:r.getAttribute("texture"),texcoord:r.getAttribute("texcoord"),extra:le(r)}}return t}function ge(e){return e}function ye(e){const t=(n=e.url,m(Lt.effects[n],ge));var n;const r=t.profile.technique;let i;switch(r.type){case"phong":case"blinn":i=new Be;break;case"lambert":i=new Ge;break;default:i=new E}function o(e,n=null){const r=t.profile.samplers[e.id];let i=null;if(void 0!==r){i=Z(t.profile.surfaces[r.source].init_from)}else console.warn("THREE.ColladaLoader: Undefined sampler. Access image directly (see #12530)."),i=Z(e.id);if(null!==i){const t=function(e){let t,n=e.slice((e.lastIndexOf(".")-1>>>0)+2);n=n.toLowerCase(),t="tga"===n?Mt:Rt;return t}(i);if(void 0!==t){const r=t.load(i),o=e.extra;if(void 0!==o&&void 0!==o.technique&&!1===c(o.technique)){const e=o.technique;r.wrapS=e.wrapU?me:be,r.wrapT=e.wrapV?me:be,r.offset.set(e.offsetU||0,e.offsetV||0),r.repeat.set(e.repeatU||1,e.repeatV||1)}else r.wrapS=me,r.wrapT=me;return null!==n&&(r.colorSpace=n),r}return console.warn("THREE.ColladaLoader: Loader for texture %s not found.",i),null}return console.warn("THREE.ColladaLoader: Couldn't create texture with ID:",e.id),null}i.name=e.name||"";const a=r.parameters;for(const e in a){const t=a[e];switch(e){case"diffuse":t.color&&i.color.fromArray(t.color),t.texture&&(i.map=o(t.texture,Y));break;case"specular":t.color&&i.specular&&i.specular.fromArray(t.color),t.texture&&(i.specularMap=o(t.texture));break;case"bump":t.texture&&(i.normalMap=o(t.texture));break;case"ambient":t.texture&&(i.lightMap=o(t.texture,Y));break;case"shininess":t.float&&i.shininess&&(i.shininess=t.float);break;case"emission":t.color&&i.emissive&&i.emissive.fromArray(t.color),t.texture&&(i.emissiveMap=o(t.texture,Y))}}i.color.convertSRGBToLinear(),i.specular&&i.specular.convertSRGBToLinear(),i.emissive&&i.emissive.convertSRGBToLinear();let s=a.transparent,l=a.transparency;if(void 0===l&&s&&(l={float:1}),void 0===s&&l&&(s={opaque:"A_ONE",data:{color:[1,1,1,1]}}),s&&l)if(s.data.texture)i.transparent=!0;else{const e=s.data.color;switch(s.opaque){case"A_ONE":i.opacity=e[3]*l.float;break;case"RGB_ZERO":i.opacity=1-e[0]*l.float;break;case"A_ZERO":i.opacity=1-e[3]*l.float;break;case"RGB_ONE":i.opacity=e[0]*l.float;break;default:console.warn('THREE.ColladaLoader: Invalid opaque type "%s" of transparent tag.',s.opaque)}i.opacity<1&&(i.transparent=!0)}if(void 0!==r.extra&&void 0!==r.extra.technique){const e=r.extra.technique;for(const t in e){const n=e[t];switch(t){case"double_sided":i.side=1===n?D:G;break;case"bump":i.normalMap=o(n.texture),i.normalScale=new v(1,1)}}}return i}function ve(e){return m(Lt.materials[e],ye)}function xe(e){for(let t=0;t<e.childNodes.length;t++){const n=e.childNodes[t];if("technique_common"===n.nodeName)return we(n)}return{}}function we(e){const t={};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];switch(r.nodeName){case"perspective":case"orthographic":t.technique=r.nodeName,t.parameters=Ae(r)}}return t}function Ae(e){const t={};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];switch(r.nodeName){case"xfov":case"yfov":case"xmag":case"ymag":case"znear":case"zfar":case"aspect_ratio":t[r.nodeName]=parseFloat(r.textContent)}}return t}function Ce(e){let t;switch(e.optics.technique){case"perspective":t=new ke(e.optics.parameters.yfov,e.optics.parameters.aspect_ratio,e.optics.parameters.znear,e.optics.parameters.zfar);break;case"orthographic":let n=e.optics.parameters.ymag,r=e.optics.parameters.xmag;const i=e.optics.parameters.aspect_ratio;r=void 0===r?n*i:r,n=void 0===n?r/i:n,r*=.5,n*=.5,t=new Se(-r,r,n,-n,e.optics.parameters.znear,e.optics.parameters.zfar);break;default:t=new ke}return t.name=e.name||"",t}function Pe(e){const t=Lt.cameras[e];return void 0!==t?m(t,Ce):(console.warn("THREE.ColladaLoader: Couldn't find camera with ID:",e),null)}function _e(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"directional":case"point":case"spot":case"ambient":t.technique=r.nodeName,t.parameters=Ne(r)}}return t}function Ne(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"color":const e=i(r.textContent);t.color=(new K).fromArray(e).convertSRGBToLinear();break;case"falloff_angle":t.falloffAngle=parseFloat(r.textContent);break;case"quadratic_attenuation":const n=parseFloat(r.textContent);t.distance=n?Math.sqrt(1/n):0}}return t}function De(e){let t;switch(e.technique){case"directional":t=new re;break;case"point":t=new ne;break;case"spot":t=new te;break;case"ambient":t=new Xe}return e.parameters.color&&t.color.copy(e.parameters.color),e.parameters.distance&&(t.distance=e.parameters.distance),t}function Fe(e){const t=Lt.lights[e];return void 0!==t?m(t,De):(console.warn("THREE.ColladaLoader: Couldn't find light with ID:",e),null)}function Ue(e){const t={array:[],stride:3};for(let o=0;o<e.childNodes.length;o++){const a=e.childNodes[o];if(1===a.nodeType)switch(a.nodeName){case"float_array":t.array=i(a.textContent);break;case"Name_array":t.array=r(a.textContent);break;case"technique_common":const e=n(a,"accessor")[0];void 0!==e&&(t.stride=parseInt(e.getAttribute("stride")))}}return t}function ze(e){const t={};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];1===r.nodeType&&(t[r.getAttribute("semantic")]=a(r.getAttribute("source")))}return t}function He(e){const t={type:e.nodeName,material:e.getAttribute("material"),count:parseInt(e.getAttribute("count")),inputs:{},stride:0,hasUV:!1};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"input":const e=a(r.getAttribute("source")),n=r.getAttribute("semantic"),i=parseInt(r.getAttribute("offset")),s=parseInt(r.getAttribute("set")),c=s>0?n+s:n;t.inputs[c]={id:e,offset:i},t.stride=Math.max(t.stride,i+1),"TEXCOORD"===n&&(t.hasUV=!0);break;case"vcount":t.vcount=o(r.textContent);break;case"p":t.p=o(r.textContent)}}return t}function Ve(e){let t=0;for(let n=0,r=e.length;n<r;n++){!0===e[n].hasUV&&t++}t>0&&t<e.length&&(e.uvsNeedsFix=!0)}function We(e){const t={},n=e.sources,r=e.vertices,i=e.primitives;if(0===i.length)return{};const o=function(e){const t={};for(let n=0;n<e.length;n++){const r=e[n];void 0===t[r.type]&&(t[r.type]=[]),t[r.type].push(r)}return t}(i);for(const e in o){const i=o[e];Ve(i),t[e]=qe(i,n,r)}return t}function qe(e,t,n){const r={},i={array:[],stride:0},o={array:[],stride:0},a={array:[],stride:0},s={array:[],stride:0},c={array:[],stride:0},l=[],u=4,h=[],d=4,p=new O,f=[];let m=0;for(let r=0;r<e.length;r++){const u=e[r],d=u.inputs;let g=0;switch(u.type){case"lines":case"linestrips":g=2*u.count;break;case"triangles":g=3*u.count;break;case"polylist":for(let e=0;e<u.count;e++){const t=u.vcount[e];switch(t){case 3:g+=3;break;case 4:g+=6;break;default:g+=3*(t-2)}}break;default:console.warn("THREE.ColladaLoader: Unknow primitive type:",u.type)}p.addGroup(m,g,r),m+=g,u.material&&f.push(u.material);for(const r in d){const p=d[r];switch(r){case"VERTEX":for(const r in n){const d=n[r];switch(r){case"POSITION":const n=i.array.length;if(Ye(u,t[d],p.offset,i.array),i.stride=t[d].stride,t.skinWeights&&t.skinIndices&&(Ye(u,t.skinIndices,p.offset,l),Ye(u,t.skinWeights,p.offset,h)),!1===u.hasUV&&!0===e.uvsNeedsFix){const e=(i.array.length-n)/i.stride;for(let t=0;t<e;t++)a.array.push(0,0)}break;case"NORMAL":Ye(u,t[d],p.offset,o.array),o.stride=t[d].stride;break;case"COLOR":Ye(u,t[d],p.offset,c.array),c.stride=t[d].stride;break;case"TEXCOORD":Ye(u,t[d],p.offset,a.array),a.stride=t[d].stride;break;case"TEXCOORD1":Ye(u,t[d],p.offset,s.array),a.stride=t[d].stride;break;default:console.warn('THREE.ColladaLoader: Semantic "%s" not handled in geometry build process.',r)}}break;case"NORMAL":Ye(u,t[p.id],p.offset,o.array),o.stride=t[p.id].stride;break;case"COLOR":Ye(u,t[p.id],p.offset,c.array,!0),c.stride=t[p.id].stride;break;case"TEXCOORD":Ye(u,t[p.id],p.offset,a.array),a.stride=t[p.id].stride;break;case"TEXCOORD1":Ye(u,t[p.id],p.offset,s.array),s.stride=t[p.id].stride}}}return i.array.length>0&&p.setAttribute("position",new k(i.array,i.stride)),o.array.length>0&&p.setAttribute("normal",new k(o.array,o.stride)),c.array.length>0&&p.setAttribute("color",new k(c.array,c.stride)),a.array.length>0&&p.setAttribute("uv",new k(a.array,a.stride)),s.array.length>0&&p.setAttribute("uv1",new k(s.array,s.stride)),l.length>0&&p.setAttribute("skinIndex",new k(l,u)),h.length>0&&p.setAttribute("skinWeight",new k(h,d)),r.data=p,r.type=e[0].type,r.materialKeys=f,r}function Ye(e,t,n,r,i=!1){const o=e.p,a=e.stride,s=e.vcount;function c(e){let t=o[e+n]*u;const a=t+u;for(;t<a;t++)r.push(l[t]);if(i){const e=r.length-u-1;It.setRGB(r[e+0],r[e+1],r[e+2]).convertSRGBToLinear(),r[e+0]=It.r,r[e+1]=It.g,r[e+2]=It.b}}const l=t.array,u=t.stride;if(void 0!==e.vcount){let e=0;for(let t=0,n=s.length;t<n;t++){const n=s[t];if(4===n){const t=e+1*a,n=e+2*a,r=e+3*a;c(e+0*a),c(t),c(r),c(t),c(n),c(r)}else if(3===n){const t=e+1*a,n=e+2*a;c(e+0*a),c(t),c(n)}else if(n>4)for(let t=1,r=n-2;t<=r;t++){const n=e+a*t,r=e+a*(t+1);c(e+0*a),c(n),c(r)}e+=a*n}}else for(let e=0,t=o.length;e<t;e+=a)c(e)}function Ke(e){return m(Lt.geometries[e],We)}function Ze(e){return void 0!==e.build?e.build:e}function $e(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"joint":t.joints[r.getAttribute("sid")]=Je(r);break;case"link":t.links.push(tt(r))}}}function Je(e){let t;for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"prismatic":case"revolute":t=et(r)}}return t}function et(e){const t={sid:e.getAttribute("sid"),name:e.getAttribute("name")||"",axis:new f,limits:{min:0,max:0},type:e.nodeName,static:!1,zeroPosition:0,middlePosition:0};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"axis":const e=i(r.textContent);t.axis.fromArray(e);break;case"limits":const n=r.getElementsByTagName("max")[0],o=r.getElementsByTagName("min")[0];t.limits.max=parseFloat(n.textContent),t.limits.min=parseFloat(o.textContent)}}return t.limits.min>=t.limits.max&&(t.static=!0),t.middlePosition=(t.limits.min+t.limits.max)/2,t}function tt(e){const t={sid:e.getAttribute("sid"),name:e.getAttribute("name")||"",attachments:[],transforms:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"attachment_full":t.attachments.push(nt(r));break;case"matrix":case"translate":case"rotate":t.transforms.push(rt(r))}}return t}function nt(e){const t={joint:e.getAttribute("joint").split("/").pop(),transforms:[],links:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"link":t.links.push(tt(r));break;case"matrix":case"translate":case"rotate":t.transforms.push(rt(r))}}return t}function rt(e){const t={type:e.nodeName},n=i(e.textContent);switch(t.type){case"matrix":t.obj=new N,t.obj.fromArray(n).transpose();break;case"translate":t.obj=new f,t.obj.fromArray(n);break;case"rotate":t.obj=new f,t.obj.fromArray(n),t.angle=d.degToRad(n[3])}return t}function it(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique_common"===r.nodeName)ot(r,t)}}function ot(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"inertia":t.inertia=i(r.textContent);break;case"mass":t.mass=i(r.textContent)[0]}}}function at(e){const t={target:e.getAttribute("target").split("/").pop()};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"axis"===r.nodeName){const e=r.getElementsByTagName("param")[0];t.axis=e.textContent;const n=t.axis.split("inst_").pop().split("axis")[0];t.jointIndex=n.substring(0,n.length-1)}}return t}function st(e){return void 0!==e.build?e.build:e}function ct(e){const t=[],n=Ct.querySelector('[id="'+e.id+'"]');for(let e=0;e<n.childNodes.length;e++){const r=n.childNodes[e];if(1!==r.nodeType)continue;let o,a;switch(r.nodeName){case"matrix":o=i(r.textContent);const e=(new N).fromArray(o).transpose();t.push({sid:r.getAttribute("sid"),type:r.nodeName,obj:e});break;case"translate":case"scale":o=i(r.textContent),a=(new f).fromArray(o),t.push({sid:r.getAttribute("sid"),type:r.nodeName,obj:a});break;case"rotate":o=i(r.textContent),a=(new f).fromArray(o);const n=d.degToRad(o[3]);t.push({sid:r.getAttribute("sid"),type:r.nodeName,obj:a,angle:n})}}return t}const lt=new N,ut=new f;function ht(e){const t={name:e.getAttribute("name")||"",type:e.getAttribute("type"),id:e.getAttribute("id"),sid:e.getAttribute("sid"),matrix:new N,nodes:[],instanceCameras:[],instanceControllers:[],instanceLights:[],instanceGeometries:[],instanceNodes:[],transforms:{}};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1!==r.nodeType)continue;let o;switch(r.nodeName){case"node":t.nodes.push(r.getAttribute("id")),ht(r);break;case"instance_camera":t.instanceCameras.push(a(r.getAttribute("url")));break;case"instance_controller":t.instanceControllers.push(dt(r));break;case"instance_light":t.instanceLights.push(a(r.getAttribute("url")));break;case"instance_geometry":t.instanceGeometries.push(dt(r));break;case"instance_node":t.instanceNodes.push(a(r.getAttribute("url")));break;case"matrix":o=i(r.textContent),t.matrix.multiply(lt.fromArray(o).transpose()),t.transforms[r.getAttribute("sid")]=r.nodeName;break;case"translate":o=i(r.textContent),ut.fromArray(o),t.matrix.multiply(lt.makeTranslation(ut.x,ut.y,ut.z)),t.transforms[r.getAttribute("sid")]=r.nodeName;break;case"rotate":o=i(r.textContent);const e=d.degToRad(o[3]);t.matrix.multiply(lt.makeRotationAxis(ut.fromArray(o),e)),t.transforms[r.getAttribute("sid")]=r.nodeName;break;case"scale":o=i(r.textContent),t.matrix.scale(ut.fromArray(o)),t.transforms[r.getAttribute("sid")]=r.nodeName;break;case"extra":break;default:console.log(r)}}return vt(t.id)?console.warn("THREE.ColladaLoader: There is already a node with ID %s. Exclude current node from further processing.",t.id):Lt.nodes[t.id]=t,t}function dt(e){const t={id:a(e.getAttribute("url")),materials:{},skeletons:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];switch(r.nodeName){case"bind_material":const e=r.getElementsByTagName("instance_material");for(let n=0;n<e.length;n++){const r=e[n],i=r.getAttribute("symbol"),o=r.getAttribute("target");t.materials[i]=a(o)}break;case"skeleton":t.skeletons.push(a(r.textContent))}}return t}function pt(e,t){const n=[],r=[];let i,o,a;for(i=0;i<e.length;i++){const r=e[i];let o;if(vt(r))o=xt(r),ft(o,t,n);else if(Et(r)){const e=Lt.visualScenes[r].children;for(let r=0;r<e.length;r++){const i=e[r];if("JOINT"===i.type){ft(xt(i.id),t,n)}}}else console.error("THREE.ColladaLoader: Unable to find root bone of skeleton with ID:",r)}for(i=0;i<t.length;i++)for(o=0;o<n.length;o++)if(a=n[o],a.bone.name===t[i].name){r[i]=a,a.processed=!0;break}for(i=0;i<n.length;i++)a=n[i],!1===a.processed&&(r.push(a),a.processed=!0);const s=[],c=[];for(i=0;i<r.length;i++)a=r[i],s.push(a.bone),c.push(a.boneInverse);return new Re(s,c)}function ft(e,t,n){e.traverse(function(e){if(!0===e.isBone){let r;for(let n=0;n<t.length;n++){const i=t[n];if(i.name===e.name){r=i.boneInverse;break}}void 0===r&&(r=new N),n.push({bone:e,boneInverse:r,processed:!1})}})}function mt(e){const t=[],n=e.matrix,r=e.nodes,i=e.type,o=e.instanceCameras,a=e.instanceControllers,s=e.instanceLights,c=e.instanceGeometries,l=e.instanceNodes;for(let e=0,n=r.length;e<n;e++)t.push(xt(r[e]));for(let e=0,n=o.length;e<n;e++){const n=Pe(o[e]);null!==n&&t.push(n.clone())}for(let e=0,n=a.length;e<n;e++){const n=a[e],r=q(n.id),i=yt(Ke(r.id),n.materials),o=pt(n.skeletons,r.skin.joints);for(let e=0,n=i.length;e<n;e++){const n=i[e];n.isSkinnedMesh&&(n.bind(o,r.skin.bindMatrix),n.normalizeSkinWeights()),t.push(n)}}for(let e=0,n=s.length;e<n;e++){const n=Fe(s[e]);null!==n&&t.push(n.clone())}for(let e=0,n=c.length;e<n;e++){const n=c[e],r=yt(Ke(n.id),n.materials);for(let e=0,n=r.length;e<n;e++)t.push(r[e])}for(let e=0,n=l.length;e<n;e++)t.push(xt(l[e]).clone());let u;if(0===r.length&&1===t.length)u=t[0];else{u="JOINT"===i?new Ie:new Oe;for(let e=0;e<t.length;e++)u.add(t[e])}return u.name="JOINT"===i?e.sid:e.name,u.matrix.copy(n),u.matrix.decompose(u.position,u.quaternion,u.scale),u}const gt=new E({name:X.DEFAULT_MATERIAL_NAME,color:16711935});function bt(e,t){const n=[];for(let r=0,i=e.length;r<i;r++){const i=t[e[r]];void 0===i?(console.warn("THREE.ColladaLoader: Material with key %s not found. Apply fallback material.",e[r]),n.push(gt)):n.push(ve(i))}return n}function yt(e,t){const n=[];for(const r in e){const i=e[r],o=bt(i.materialKeys,t);if(0===o.length&&("lines"===r||"linestrips"===r?o.push(new T):o.push(new Be)),"lines"===r||"linestrips"===r)for(let e=0,t=o.length;e<t;e++){const t=o[e];if(!0===t.isMeshPhongMaterial||!0===t.isMeshLambertMaterial){const n=new T;n.color.copy(t.color),n.opacity=t.opacity,n.transparent=t.transparent,o[e]=n}}const a=void 0!==i.data.attributes.skinIndex,s=1===o.length?o[0]:o;let c;switch(r){case"lines":c=new Te(i.data,s);break;case"linestrips":c=new M(i.data,s);break;case"triangles":case"polylist":c=a?new Ee(i.data,s):new S(i.data,s)}n.push(c)}return n}function vt(e){return void 0!==Lt.nodes[e]}function xt(e){return m(Lt.nodes[e],mt)}function wt(e){const t=new Oe;t.name=e.name;const n=e.children;for(let e=0;e<n.length;e++){const r=n[e];t.add(xt(r.id))}return t}function Et(e){return void 0!==Lt.visualScenes[e]}function Tt(e){return m(Lt.visualScenes[e],wt)}if(0===e.length)return{scene:new Qe};const At=(new DOMParser).parseFromString(e,"application/xml"),Ct=n(At,"COLLADA")[0],Ot=At.getElementsByTagName("parsererror")[0];if(void 0!==Ot){const e=n(Ot,"div")[0];let t;return t=e?e.textContent:function(e){let t="";const n=[e];for(;n.length;){const e=n.shift();e.nodeType===Node.TEXT_NODE?t+=e.textContent:(t+="\n",n.push.apply(n,e.childNodes))}return t.trim()}(Ot),console.error("THREE.ColladaLoader: Failed to parse collada file.\n",t),null}const kt=Ct.getAttribute("version");console.debug("THREE.ColladaLoader: File version",kt);const St=function(e){return{unit:l(n(e,"unit")[0]),upAxis:u(n(e,"up_axis")[0])}}(n(Ct,"asset")[0]),Rt=new ae(this.manager);let Mt;Rt.setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin),ns&&(Mt=new ns(this.manager),Mt.setPath(this.resourcePath||t));const It=new K,Pt=[];let _t={},Nt=0;const Lt={animations:{},clips:{},controllers:{},images:{},effects:{},materials:{},cameras:{},lights:{},geometries:{},nodes:{},visualScenes:{},kinematicsModels:{},physicsModels:{},kinematicsScenes:{}};h(Ct,"library_animations","animation",function e(t){const n={sources:{},samplers:{},channels:{}};let r=!1;for(let i=0,o=t.childNodes.length;i<o;i++){const o=t.childNodes[i];if(1!==o.nodeType)continue;let a;switch(o.nodeName){case"source":a=o.getAttribute("id"),n.sources[a]=Ue(o);break;case"sampler":a=o.getAttribute("id"),n.samplers[a]=g(o);break;case"channel":a=o.getAttribute("target"),n.channels[a]=b(o);break;case"animation":e(o),r=!0;break;default:console.log(o)}}!1===r&&(Lt.animations[t.getAttribute("id")||d.generateUUID()]=n)}),h(Ct,"library_animation_clips","animation_clip",function(e){const t={name:e.getAttribute("id")||"default",start:parseFloat(e.getAttribute("start")||0),end:parseFloat(e.getAttribute("end")||0),animations:[]};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"instance_animation"===r.nodeName)t.animations.push(a(r.getAttribute("url")))}Lt.clips[e.getAttribute("id")]=t}),h(Ct,"library_controllers","controller",function(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"skin":t.id=a(r.getAttribute("source")),t.skin=z(r);break;case"morph":t.id=a(r.getAttribute("source")),console.warn("THREE.ColladaLoader: Morph target animation not supported yet.")}}Lt.controllers[e.getAttribute("id")]=t}),h(Ct,"library_images","image",function(e){const t={init_from:n(e,"init_from")[0].textContent};Lt.images[e.getAttribute("id")]=t}),h(Ct,"library_effects","effect",function(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"profile_COMMON"===r.nodeName)t.profile=$(r)}Lt.effects[e.getAttribute("id")]=t}),h(Ct,"library_materials","material",function(e){const t={name:e.getAttribute("name")};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"instance_effect"===r.nodeName)t.url=a(r.getAttribute("url"))}Lt.materials[e.getAttribute("id")]=t}),h(Ct,"library_cameras","camera",function(e){const t={name:e.getAttribute("name")};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"optics"===r.nodeName)t.optics=xe(r)}Lt.cameras[e.getAttribute("id")]=t}),h(Ct,"library_lights","light",function(e){let t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique_common"===r.nodeName)t=_e(r)}Lt.lights[e.getAttribute("id")]=t}),h(Ct,"library_geometries","geometry",function(e){const t={name:e.getAttribute("name"),sources:{},vertices:{},primitives:[]},r=n(e,"mesh")[0];if(void 0!==r){for(let e=0;e<r.childNodes.length;e++){const n=r.childNodes[e];if(1!==n.nodeType)continue;const i=n.getAttribute("id");switch(n.nodeName){case"source":t.sources[i]=Ue(n);break;case"vertices":t.vertices=ze(n);break;case"polygons":console.warn("THREE.ColladaLoader: Unsupported primitive type: ",n.nodeName);break;case"lines":case"linestrips":case"polylist":case"triangles":t.primitives.push(He(n));break;default:console.log(n)}}Lt.geometries[e.getAttribute("id")]=t}}),h(Ct,"library_nodes","node",ht),h(Ct,"library_visual_scenes","visual_scene",function(e){const t={name:e.getAttribute("name"),children:[]};!function(e){const t=e.getElementsByTagName("node");for(let e=0;e<t.length;e++){const n=t[e];!1===n.hasAttribute("id")&&n.setAttribute("id",s())}}(e);const r=n(e,"node");for(let e=0;e<r.length;e++)t.children.push(ht(r[e]));Lt.visualScenes[e.getAttribute("id")]=t}),h(Ct,"library_kinematics_models","kinematics_model",function(e){const t={name:e.getAttribute("name")||"",joints:{},links:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique_common"===r.nodeName)$e(r,t)}Lt.kinematicsModels[e.getAttribute("id")]=t}),h(Ct,"library_physics_models","physics_model",function(e){const t={name:e.getAttribute("name")||"",rigidBodies:{}};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"rigid_body"===r.nodeName)t.rigidBodies[r.getAttribute("name")]={},it(r,t.rigidBodies[r.getAttribute("name")])}Lt.physicsModels[e.getAttribute("id")]=t}),h(Ct,"scene","instance_kinematics_scene",function(e){const t={bindJointAxis:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"bind_joint_axis"===r.nodeName)t.bindJointAxis.push(at(r))}Lt.kinematicsScenes[a(e.getAttribute("url"))]=t}),p(Lt.animations,x),p(Lt.clips,U),p(Lt.controllers,W),p(Lt.images,Q),p(Lt.effects,ge),p(Lt.materials,ye),p(Lt.cameras,Ce),p(Lt.lights,De),p(Lt.geometries,We),p(Lt.visualScenes,wt),function(){const e=Lt.clips;if(!0===c(e)){if(!1===c(Lt.animations)){const e=[];for(const t in Lt.animations){const n=w(t);for(let t=0,r=n.length;t<r;t++)e.push(n[t])}Pt.push(new Me("default",-1,e))}}else for(const t in e)Pt.push(B(t))}(),function(){const e=Object.keys(Lt.kinematicsModels)[0],t=Object.keys(Lt.kinematicsScenes)[0],n=Object.keys(Lt.visualScenes)[0];if(void 0===e||void 0===t)return;const r=(i=e,m(Lt.kinematicsModels[i],Ze));var i;const o=function(e){return m(Lt.kinematicsScenes[e],st)}(t),a=Tt(n),s=o.bindJointAxis,c={};for(let e=0,t=s.length;e<t;e++){const t=s[e],n=Ct.querySelector('[sid="'+t.target+'"]');if(n){const e=n.parentElement;l(t.jointIndex,e)}}function l(e,t){const n=t.getAttribute("name"),i=r.joints[e];a.traverse(function(r){r.name===n&&(c[e]={object:r,transforms:ct(t),joint:i,position:i.zeroPosition})})}const u=new N;_t={joints:r&&r.joints,getJointValue:function(e){const t=c[e];if(t)return t.position;console.warn("THREE.ColladaLoader: Joint "+e+" doesn't exist.")},setJointValue:function(e,t){const n=c[e];if(n){const r=n.joint;if(t>r.limits.max||t<r.limits.min)console.warn("THREE.ColladaLoader: Joint "+e+" value "+t+" outside of limits (min: "+r.limits.min+", max: "+r.limits.max+").");else if(r.static)console.warn("THREE.ColladaLoader: Joint "+e+" is static.");else{const i=n.object,o=r.axis,a=n.transforms;lt.identity();for(let n=0;n<a.length;n++){const i=a[n];if(i.sid&&-1!==i.sid.indexOf(e))switch(r.type){case"revolute":lt.multiply(u.makeRotationAxis(o,d.degToRad(t)));break;case"prismatic":lt.multiply(u.makeTranslation(o.x*t,o.y*t,o.z*t));break;default:console.warn("THREE.ColladaLoader: Unknown joint type: "+r.type)}else switch(i.type){case"matrix":lt.multiply(i.obj);break;case"translate":lt.multiply(u.makeTranslation(i.obj.x,i.obj.y,i.obj.z));break;case"scale":lt.scale(i.obj);break;case"rotate":lt.multiply(u.makeRotationAxis(i.obj,i.angle))}}i.matrix.copy(lt),i.matrix.decompose(i.position,i.quaternion,i.scale),c[e].position=t}}else console.log("THREE.ColladaLoader: "+e+" does not exist.")}}}();const Dt=function(e){return Tt(a(n(e,"instance_visual_scene")[0].getAttribute("url")))}(n(Ct,"scene")[0]);return Dt.animations=Pt,"Z_UP"===St.upAxis&&(console.warn("THREE.ColladaLoader: You are loading an asset with a Z-UP coordinate system. The loader just rotates the asset to transform it into Y-UP. The vertex data are not converted, see #24289."),Dt.rotation.set(-Math.PI/2,0,0)),Dt.scale.multiplyScalar(St.unit),{get animations(){return console.warn("THREE.ColladaLoader: Please access animations over scene.animations now."),Pt},kinematics:_t,library:Lt,scene:Dt}}}const is=new K;class os extends X{constructor(e){super(e),this.propertyNameMapping={},this.customPropertyMapping={}}load(e,t,n,r){const i=this,o=new q(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}setPropertyNameMapping(e){this.propertyNameMapping=e}setCustomPropertyNameMapping(e){this.customPropertyMapping=e}parse(e){function t(e,t=0){let n="";const r=/^ply([\s\S]*)end_header(\r\n|\r|\n)/.exec(e);null!==r&&(n=r[1]);const i={comments:[],elements:[],headerLength:t,objInfo:""},o=n.split(/\r\n|\r|\n/);let a;function s(e,t){const n={type:e[0]};return"list"===n.type?(n.name=e[3],n.countType=e[1],n.itemType=e[2]):n.name=e[1],n.name in t&&(n.name=t[n.name]),n}for(let e=0;e<o.length;e++){let t=o[e];if(t=t.trim(),""===t)continue;const n=t.split(/\s+/),r=n.shift();switch(t=n.join(" "),r){case"format":i.format=n[0],i.version=n[1];break;case"comment":i.comments.push(t);break;case"element":void 0!==a&&i.elements.push(a),a={},a.name=n[0],a.count=parseInt(n[1]),a.properties=[];break;case"property":a.properties.push(s(n,d.propertyNameMapping));break;case"obj_info":i.objInfo=t;break;default:console.log("unhandled",r,n)}}return void 0!==a&&i.elements.push(a),i}function n(e,t){switch(t){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(e);case"float":case"double":case"float32":case"float64":return parseFloat(e)}}function r(e,t){const r={};for(let i=0;i<e.length;i++){if(t.empty())return null;if("list"===e[i].type){const o=[],a=n(t.next(),e[i].countType);for(let r=0;r<a;r++){if(t.empty())return null;o.push(n(t.next(),e[i].itemType))}r[e[i].name]=o}else r[e[i].name]=n(t.next(),e[i].type)}return r}function i(){const e={indices:[],vertices:[],normals:[],uvs:[],faceVertexUvs:[],colors:[],faceVertexColors:[]};for(const t of Object.keys(d.customPropertyMapping))e[t]=[];return e}function o(e){const t=e.map(e=>e.name);function n(e){for(let n=0,r=e.length;n<r;n++){const r=e[n];if(t.includes(r))return r}return null}return{attrX:n(["x","px","posx"])||"x",attrY:n(["y","py","posy"])||"y",attrZ:n(["z","pz","posz"])||"z",attrNX:n(["nx","normalx"]),attrNY:n(["ny","normaly"]),attrNZ:n(["nz","normalz"]),attrS:n(["s","u","texture_u","tx"]),attrT:n(["t","v","texture_v","ty"]),attrR:n(["red","diffuse_red","r","diffuse_r"]),attrG:n(["green","diffuse_green","g","diffuse_g"]),attrB:n(["blue","diffuse_blue","b","diffuse_b"])}}function a(e,t){const n=i();let a,l;a=null!==(l=/end_header\s+(\S[\s\S]*\S|\S)\s*$/.exec(e))?l[1].split(/\s+/):[];const u=new as(a);e:for(let e=0;e<t.elements.length;e++){const i=t.elements[e],a=o(i.properties);for(let e=0;e<i.count;e++){const e=r(i.properties,u);if(!e)break e;c(n,i.name,e,a)}}return s(n)}function s(e){let t=new O;e.indices.length>0&&t.setIndex(e.indices),t.setAttribute("position",new k(e.vertices,3)),e.normals.length>0&&t.setAttribute("normal",new k(e.normals,3)),e.uvs.length>0&&t.setAttribute("uv",new k(e.uvs,2)),e.colors.length>0&&t.setAttribute("color",new k(e.colors,3)),(e.faceVertexUvs.length>0||e.faceVertexColors.length>0)&&(t=t.toNonIndexed(),e.faceVertexUvs.length>0&&t.setAttribute("uv",new k(e.faceVertexUvs,2)),e.faceVertexColors.length>0&&t.setAttribute("color",new k(e.faceVertexColors,3)));for(const n of Object.keys(d.customPropertyMapping))e[n].length>0&&t.setAttribute(n,new k(e[n],d.customPropertyMapping[n].length));return t.computeBoundingSphere(),t}function c(e,t,n,r){if("vertex"===t){e.vertices.push(n[r.attrX],n[r.attrY],n[r.attrZ]),null!==r.attrNX&&null!==r.attrNY&&null!==r.attrNZ&&e.normals.push(n[r.attrNX],n[r.attrNY],n[r.attrNZ]),null!==r.attrS&&null!==r.attrT&&e.uvs.push(n[r.attrS],n[r.attrT]),null!==r.attrR&&null!==r.attrG&&null!==r.attrB&&(is.setRGB(n[r.attrR]/255,n[r.attrG]/255,n[r.attrB]/255).convertSRGBToLinear(),e.colors.push(is.r,is.g,is.b));for(const t of Object.keys(d.customPropertyMapping))for(const r of d.customPropertyMapping[t])e[t].push(n[r])}else if("face"===t){const t=n.vertex_indices||n.vertex_index,i=n.texcoord;3===t.length?(e.indices.push(t[0],t[1],t[2]),i&&6===i.length&&(e.faceVertexUvs.push(i[0],i[1]),e.faceVertexUvs.push(i[2],i[3]),e.faceVertexUvs.push(i[4],i[5]))):4===t.length&&(e.indices.push(t[0],t[1],t[3]),e.indices.push(t[1],t[2],t[3])),null!==r.attrR&&null!==r.attrG&&null!==r.attrB&&(is.setRGB(n[r.attrR]/255,n[r.attrG]/255,n[r.attrB]/255).convertSRGBToLinear(),e.faceVertexColors.push(is.r,is.g,is.b),e.faceVertexColors.push(is.r,is.g,is.b),e.faceVertexColors.push(is.r,is.g,is.b))}}function l(e,t){const n={};let r=0;for(let i=0;i<t.length;i++){const o=t[i],a=o.valueReader;if("list"===o.type){const t=[],i=o.countReader.read(e+r);r+=o.countReader.size;for(let n=0;n<i;n++)t.push(a.read(e+r)),r+=a.size;n[o.name]=t}else n[o.name]=a.read(e+r),r+=a.size}return[n,r]}function u(e,t,n){function r(e,t,n){switch(t){case"int8":case"char":return{read:t=>e.getInt8(t),size:1};case"uint8":case"uchar":return{read:t=>e.getUint8(t),size:1};case"int16":case"short":return{read:t=>e.getInt16(t,n),size:2};case"uint16":case"ushort":return{read:t=>e.getUint16(t,n),size:2};case"int32":case"int":return{read:t=>e.getInt32(t,n),size:4};case"uint32":case"uint":return{read:t=>e.getUint32(t,n),size:4};case"float32":case"float":return{read:t=>e.getFloat32(t,n),size:4};case"float64":case"double":return{read:t=>e.getFloat64(t,n),size:8}}}for(let i=0,o=e.length;i<o;i++){const o=e[i];"list"===o.type?(o.countReader=r(t,o.countType,n),o.valueReader=r(t,o.itemType,n)):o.valueReader=r(t,o.type,n)}}let h;const d=this;if(e instanceof ArrayBuffer){const n=new Uint8Array(e),{headerText:r,headerLength:d}=function(e){let t=0,n=!0,r="";const i=[],o=(new TextDecoder).decode(e.subarray(0,5)),a=/^ply\r\n/.test(o);do{const o=String.fromCharCode(e[t++]);"\n"!==o&&"\r"!==o?r+=o:("end_header"===r&&(n=!1),""!==r&&(i.push(r),r=""))}while(n&&t<e.length);return!0===a&&t++,{headerText:i.join("\r")+"\r",headerLength:t}}(n),p=t(r,d);if("ascii"===p.format){h=a((new TextDecoder).decode(n),p)}else h=function(e,t){const n=i(),r="binary_little_endian"===t.format,a=new DataView(e,t.headerLength);let h,d=0;for(let e=0;e<t.elements.length;e++){const i=t.elements[e],s=i.properties,p=o(s);u(s,a,r);for(let e=0;e<i.count;e++){h=l(d,s),d+=h[1];const e=h[0];c(n,i.name,e,p)}}return s(n)}(e,p)}else h=a(e,t(e));return h}}class as{constructor(e){this.arr=e,this.i=0}empty(){return this.i>=this.arr.length}next(){return this.arr[this.i++]}}class ss extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=new q(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){function t(e,t,n){for(let r=0,i=e.length;r<i;r++)if(e[r]!==t.getUint8(n+r))return!1;return!0}const n=function(e){if("string"==typeof e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=255&e.charCodeAt(n);return t.buffer||t}return e}(e);return function(e){const n=new DataView(e);if(84+50*n.getUint32(80,!0)===n.byteLength)return!0;const r=[115,111,108,105,100];for(let e=0;e<5;e++)if(t(r,n,e))return!1;return!0}(n)?function(e){const t=new DataView(e),n=t.getUint32(80,!0);let r,i,o,a,s,c,l,u,h=!1;for(let e=0;e<70;e++)1129270351==t.getUint32(e,!1)&&82==t.getUint8(e+4)&&61==t.getUint8(e+5)&&(h=!0,a=new Float32Array(3*n*3),s=t.getUint8(e+6)/255,c=t.getUint8(e+7)/255,l=t.getUint8(e+8)/255,u=t.getUint8(e+9)/255);const d=new O,p=new Float32Array(3*n*3),f=new Float32Array(3*n*3),m=new K;for(let e=0;e<n;e++){const n=84+50*e,u=t.getFloat32(n,!0),d=t.getFloat32(n+4,!0),g=t.getFloat32(n+8,!0);if(h){const e=t.getUint16(n+48,!0);32768&e?(r=s,i=c,o=l):(r=(31&e)/31,i=(e>>5&31)/31,o=(e>>10&31)/31)}for(let s=1;s<=3;s++){const c=n+12*s,l=3*e*3+3*(s-1);p[l]=t.getFloat32(c,!0),p[l+1]=t.getFloat32(c+4,!0),p[l+2]=t.getFloat32(c+8,!0),f[l]=u,f[l+1]=d,f[l+2]=g,h&&(m.set(r,i,o).convertSRGBToLinear(),a[l]=m.r,a[l+1]=m.g,a[l+2]=m.b)}}return d.setAttribute("position",new j(p,3)),d.setAttribute("normal",new j(f,3)),h&&(d.setAttribute("color",new j(a,3)),d.hasColors=!0,d.alpha=u),d}(n):function(e){const t=new O,n=/solid([\s\S]*?)endsolid/g,r=/facet([\s\S]*?)endfacet/g,i=/solid\s(.+)/;let o=0;const a=/[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source,s=new RegExp("vertex"+a+a+a,"g"),c=new RegExp("normal"+a+a+a,"g"),l=[],u=[],h=[],d=new f;let p,m=0,g=0,b=0;for(;null!==(p=n.exec(e));){g=b;const e=p[0],n=null!==(p=i.exec(e))?p[1]:"";for(h.push(n);null!==(p=r.exec(e));){let e=0,t=0;const n=p[0];for(;null!==(p=c.exec(n));)d.x=parseFloat(p[1]),d.y=parseFloat(p[2]),d.z=parseFloat(p[3]),t++;for(;null!==(p=s.exec(n));)l.push(parseFloat(p[1]),parseFloat(p[2]),parseFloat(p[3])),u.push(d.x,d.y,d.z),e++,b++;1!==t&&console.error("THREE.STLLoader: Something isn't right with the normal of face number "+o),3!==e&&console.error("THREE.STLLoader: Something isn't right with the vertices of face number "+o),o++}const a=g,f=b-g;t.userData.groupNames=h,t.addGroup(a,f,m),m++}return t.setAttribute("position",new k(l,3)),t.setAttribute("normal",new k(u,3)),t}("string"!=typeof(r=e)?(new TextDecoder).decode(r):r);var r}}const cs=Y;class ls extends X{constructor(e){super(e),this.defaultDPI=90,this.defaultUnit="px"}load(e,t,n,r){const i=this,o=new q(i.manager);o.setPath(i.path),o.setRequestHeader(i.requestHeader),o.setWithCredentials(i.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){const t=this;function n(e,t,n,i,o,a,s,c){if(0==t||0==n)return void e.lineTo(c.x,c.y);i=i*Math.PI/180,t=Math.abs(t),n=Math.abs(n);const l=(s.x-c.x)/2,u=(s.y-c.y)/2,h=Math.cos(i)*l+Math.sin(i)*u,d=-Math.sin(i)*l+Math.cos(i)*u;let p=t*t,f=n*n;const m=h*h,g=d*d,b=m/p+g/f;if(b>1){const e=Math.sqrt(b);p=(t*=e)*t,f=(n*=e)*n}const y=p*g+f*m,v=(p*f-y)/y;let x=Math.sqrt(Math.max(0,v));o===a&&(x=-x);const w=x*t*d/n,E=-x*n*h/t,T=Math.cos(i)*w-Math.sin(i)*E+(s.x+c.x)/2,A=Math.sin(i)*w+Math.cos(i)*E+(s.y+c.y)/2,C=r(1,0,(h-w)/t,(d-E)/n),O=r((h-w)/t,(d-E)/n,(-h-w)/t,(-d-E)/n)%(2*Math.PI);e.currentPath.absellipse(T,A,t,n,C,C+O,0===a,i)}function r(e,t,n,r){const i=e*n+t*r,o=Math.sqrt(e*e+t*t)*Math.sqrt(n*n+r*r);let a=Math.acos(Math.max(-1,Math.min(1,i/o)));return e*r-t*n<0&&(a=-a),a}function i(e,t){t=Object.assign({},t);let n={};if(e.hasAttribute("class")){const t=e.getAttribute("class").split(/\s/).filter(Boolean).map(e=>e.trim());for(let e=0;e<t.length;e++)n=Object.assign(n,g["."+t[e]])}function r(r,i,o){void 0===o&&(o=function(e){return e.startsWith("url")&&console.warn("SVGLoader: url access in attributes is not implemented."),e}),e.hasAttribute(r)&&(t[i]=o(e.getAttribute(r))),n[r]&&(t[i]=o(n[r])),e.style&&""!==e.style[r]&&(t[i]=o(e.style[r]))}function i(e){return Math.max(0,Math.min(1,l(e)))}function o(e){return Math.max(0,l(e))}return e.hasAttribute("id")&&(n=Object.assign(n,g["#"+e.getAttribute("id")])),r("fill","fill"),r("fill-opacity","fillOpacity",i),r("fill-rule","fillRule"),r("opacity","opacity",i),r("stroke","stroke"),r("stroke-opacity","strokeOpacity",i),r("stroke-width","strokeWidth",o),r("stroke-linejoin","strokeLineJoin"),r("stroke-linecap","strokeLineCap"),r("stroke-miterlimit","strokeMiterLimit",o),r("visibility","visibility"),t}function o(e,t){return e-(t-e)}function a(e,t,n){if("string"!=typeof e)throw new TypeError("Invalid input: "+typeof e);const r={WHITESPACE:/[ \t\r\n]/,DIGIT:/[\d]/,SIGN:/[-+]/,POINT:/\./,COMMA:/,/,EXP:/e/i,FLAGS:/[01]/};let i=0,o=!0,a="",s="";const c=[];function l(e,t,n){const r=new SyntaxError('Unexpected character "'+e+'" at index '+t+".");throw r.partial=n,r}function u(){""!==a&&(""===s?c.push(Number(a)):c.push(Number(a)*Math.pow(10,Number(s)))),a="",s=""}let h;const d=e.length;for(let p=0;p<d;p++)if(h=e[p],Array.isArray(t)&&t.includes(c.length%n)&&r.FLAGS.test(h))i=1,a=h,u();else{if(0===i){if(r.WHITESPACE.test(h))continue;if(r.DIGIT.test(h)||r.SIGN.test(h)){i=1,a=h;continue}if(r.POINT.test(h)){i=2,a=h;continue}r.COMMA.test(h)&&(o&&l(h,p,c),o=!0)}if(1===i){if(r.DIGIT.test(h)){a+=h;continue}if(r.POINT.test(h)){a+=h,i=2;continue}if(r.EXP.test(h)){i=3;continue}r.SIGN.test(h)&&1===a.length&&r.SIGN.test(a[0])&&l(h,p,c)}if(2===i){if(r.DIGIT.test(h)){a+=h;continue}if(r.EXP.test(h)){i=3;continue}r.POINT.test(h)&&"."===a[a.length-1]&&l(h,p,c)}if(3===i){if(r.DIGIT.test(h)){s+=h;continue}if(r.SIGN.test(h)){if(""===s){s+=h;continue}1===s.length&&r.SIGN.test(s)&&l(h,p,c)}}r.WHITESPACE.test(h)?(u(),i=0,o=!1):r.COMMA.test(h)?(u(),i=0,o=!0):r.SIGN.test(h)?(u(),i=1,a=h):r.POINT.test(h)?(u(),i=2,a=h):l(h,p,c)}return u(),c}const s=["mm","cm","in","pt","pc","px"],c={mm:{mm:1,cm:.1,in:1/25.4,pt:72/25.4,pc:6/25.4,px:-1},cm:{mm:10,cm:1,in:1/2.54,pt:72/2.54,pc:6/2.54,px:-1},in:{mm:25.4,cm:2.54,in:1,pt:72,pc:6,px:-1},pt:{mm:25.4/72,cm:2.54/72,in:1/72,pt:1,pc:6/72,px:-1},pc:{mm:25.4/6,cm:2.54/6,in:1/6,pt:12,pc:1,px:-1},px:{px:1}};function l(e){let n,r="px";if("string"==typeof e||e instanceof String)for(let t=0,n=s.length;t<n;t++){const n=s[t];if(e.endsWith(n)){r=n,e=e.substring(0,e.length-n.length);break}}return"px"===r&&"px"!==t.defaultUnit?n=c.in[t.defaultUnit]/t.defaultDPI:(n=c[r][t.defaultUnit],n<0&&(n=c[r].in*t.defaultDPI)),n*parseFloat(e)}function u(e){const t=e.elements;return t[0]*t[4]-t[1]*t[3]<0}function h(e){const t=e.elements,n=t[0]*t[3]+t[1]*t[4];if(0===n)return!1;const r=d(e),i=p(e);return Math.abs(n/(r*i))>Number.EPSILON}function d(e){const t=e.elements;return Math.sqrt(t[0]*t[0]+t[1]*t[1])}function p(e){const t=e.elements;return Math.sqrt(t[3]*t[3]+t[4]*t[4])}const m=[],g={},b=[],y=new Ye,x=new Ye,w=new Ye,E=new Ye,T=new v,A=new f,C=new Ye,O=(new DOMParser).parseFromString(e,"image/svg+xml");!function e(t,r){if(1!==t.nodeType)return;const s=function(e){if(!(e.hasAttribute("transform")||"use"===e.nodeName&&(e.hasAttribute("x")||e.hasAttribute("y"))))return null;const t=function(e){const t=new Ye,n=y;if("use"===e.nodeName&&(e.hasAttribute("x")||e.hasAttribute("y"))){const n=l(e.getAttribute("x")),r=l(e.getAttribute("y"));t.translate(n,r)}if(e.hasAttribute("transform")){const r=e.getAttribute("transform").split(")");for(let e=r.length-1;e>=0;e--){const i=r[e].trim();if(""===i)continue;const o=i.indexOf("("),s=i.length;if(o>0&&o<s){const e=i.slice(0,o),t=a(i.slice(o+1));switch(n.identity(),e){case"translate":if(t.length>=1){const e=t[0];let r=0;t.length>=2&&(r=t[1]),n.translate(e,r)}break;case"rotate":if(t.length>=1){let e=0,r=0,i=0;e=t[0]*Math.PI/180,t.length>=3&&(r=t[1],i=t[2]),x.makeTranslation(-r,-i),w.makeRotation(e),E.multiplyMatrices(w,x),x.makeTranslation(r,i),n.multiplyMatrices(x,E)}break;case"scale":if(t.length>=1){const e=t[0];let r=e;t.length>=2&&(r=t[1]),n.scale(e,r)}break;case"skewX":1===t.length&&n.set(1,Math.tan(t[0]*Math.PI/180),0,0,1,0,0,0,1);break;case"skewY":1===t.length&&n.set(1,0,0,Math.tan(t[0]*Math.PI/180),1,0,0,0,1);break;case"matrix":6===t.length&&n.set(t[0],t[2],t[4],t[1],t[3],t[5],0,0,1)}}t.premultiply(n)}}return t}(e);b.length>0&&t.premultiply(b[b.length-1]);return C.copy(t),b.push(t),t}(t);let c=!1,O=null;switch(t.nodeName){case"svg":case"g":r=i(t,r);break;case"style":!function(e){if(!e.sheet||!e.sheet.cssRules||!e.sheet.cssRules.length)return;for(let t=0;t<e.sheet.cssRules.length;t++){const n=e.sheet.cssRules[t];if(1!==n.type)continue;const r=n.selectorText.split(/,/gm).filter(Boolean).map(e=>e.trim());for(let e=0;e<r.length;e++){const t=Object.fromEntries(Object.entries(n.style).filter(([,e])=>""!==e));g[r[e]]=Object.assign(g[r[e]]||{},t)}}}(t);break;case"path":r=i(t,r),t.hasAttribute("d")&&(O=function(e){const t=new et,r=new v,i=new v,s=new v;let c=!0,l=!1;const u=e.getAttribute("d");if(""===u||"none"===u)return null;const h=u.match(/[a-df-z][^a-df-z]*/gi);for(let e=0,u=h.length;e<u;e++){const u=h[e],d=u.charAt(0),p=u.slice(1).trim();let f;switch(!0===c&&(l=!0,c=!1),d){case"M":f=a(p);for(let e=0,n=f.length;e<n;e+=2)r.x=f[e+0],r.y=f[e+1],i.x=r.x,i.y=r.y,0===e?t.moveTo(r.x,r.y):t.lineTo(r.x,r.y),0===e&&s.copy(r);break;case"H":f=a(p);for(let e=0,n=f.length;e<n;e++)r.x=f[e],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"V":f=a(p);for(let e=0,n=f.length;e<n;e++)r.y=f[e],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"L":f=a(p);for(let e=0,n=f.length;e<n;e+=2)r.x=f[e+0],r.y=f[e+1],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"C":f=a(p);for(let e=0,n=f.length;e<n;e+=6)t.bezierCurveTo(f[e+0],f[e+1],f[e+2],f[e+3],f[e+4],f[e+5]),i.x=f[e+2],i.y=f[e+3],r.x=f[e+4],r.y=f[e+5],0===e&&!0===l&&s.copy(r);break;case"S":f=a(p);for(let e=0,n=f.length;e<n;e+=4)t.bezierCurveTo(o(r.x,i.x),o(r.y,i.y),f[e+0],f[e+1],f[e+2],f[e+3]),i.x=f[e+0],i.y=f[e+1],r.x=f[e+2],r.y=f[e+3],0===e&&!0===l&&s.copy(r);break;case"Q":f=a(p);for(let e=0,n=f.length;e<n;e+=4)t.quadraticCurveTo(f[e+0],f[e+1],f[e+2],f[e+3]),i.x=f[e+0],i.y=f[e+1],r.x=f[e+2],r.y=f[e+3],0===e&&!0===l&&s.copy(r);break;case"T":f=a(p);for(let e=0,n=f.length;e<n;e+=2){const n=o(r.x,i.x),a=o(r.y,i.y);t.quadraticCurveTo(n,a,f[e+0],f[e+1]),i.x=n,i.y=a,r.x=f[e+0],r.y=f[e+1],0===e&&!0===l&&s.copy(r)}break;case"A":f=a(p,[3,4],7);for(let e=0,o=f.length;e<o;e+=7){if(f[e+5]==r.x&&f[e+6]==r.y)continue;const o=r.clone();r.x=f[e+5],r.y=f[e+6],i.x=r.x,i.y=r.y,n(t,f[e],f[e+1],f[e+2],f[e+3],f[e+4],o,r),0===e&&!0===l&&s.copy(r)}break;case"m":f=a(p);for(let e=0,n=f.length;e<n;e+=2)r.x+=f[e+0],r.y+=f[e+1],i.x=r.x,i.y=r.y,0===e?t.moveTo(r.x,r.y):t.lineTo(r.x,r.y),0===e&&s.copy(r);break;case"h":f=a(p);for(let e=0,n=f.length;e<n;e++)r.x+=f[e],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"v":f=a(p);for(let e=0,n=f.length;e<n;e++)r.y+=f[e],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"l":f=a(p);for(let e=0,n=f.length;e<n;e+=2)r.x+=f[e+0],r.y+=f[e+1],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"c":f=a(p);for(let e=0,n=f.length;e<n;e+=6)t.bezierCurveTo(r.x+f[e+0],r.y+f[e+1],r.x+f[e+2],r.y+f[e+3],r.x+f[e+4],r.y+f[e+5]),i.x=r.x+f[e+2],i.y=r.y+f[e+3],r.x+=f[e+4],r.y+=f[e+5],0===e&&!0===l&&s.copy(r);break;case"s":f=a(p);for(let e=0,n=f.length;e<n;e+=4)t.bezierCurveTo(o(r.x,i.x),o(r.y,i.y),r.x+f[e+0],r.y+f[e+1],r.x+f[e+2],r.y+f[e+3]),i.x=r.x+f[e+0],i.y=r.y+f[e+1],r.x+=f[e+2],r.y+=f[e+3],0===e&&!0===l&&s.copy(r);break;case"q":f=a(p);for(let e=0,n=f.length;e<n;e+=4)t.quadraticCurveTo(r.x+f[e+0],r.y+f[e+1],r.x+f[e+2],r.y+f[e+3]),i.x=r.x+f[e+0],i.y=r.y+f[e+1],r.x+=f[e+2],r.y+=f[e+3],0===e&&!0===l&&s.copy(r);break;case"t":f=a(p);for(let e=0,n=f.length;e<n;e+=2){const n=o(r.x,i.x),a=o(r.y,i.y);t.quadraticCurveTo(n,a,r.x+f[e+0],r.y+f[e+1]),i.x=n,i.y=a,r.x=r.x+f[e+0],r.y=r.y+f[e+1],0===e&&!0===l&&s.copy(r)}break;case"a":f=a(p,[3,4],7);for(let e=0,o=f.length;e<o;e+=7){if(0==f[e+5]&&0==f[e+6])continue;const o=r.clone();r.x+=f[e+5],r.y+=f[e+6],i.x=r.x,i.y=r.y,n(t,f[e],f[e+1],f[e+2],f[e+3],f[e+4],o,r),0===e&&!0===l&&s.copy(r)}break;case"Z":case"z":t.currentPath.autoClose=!0,t.currentPath.curves.length>0&&(r.copy(s),t.currentPath.currentPoint.copy(r),c=!0);break;default:console.warn(u)}l=!1}return t}(t));break;case"rect":r=i(t,r),O=function(e){const t=l(e.getAttribute("x")||0),n=l(e.getAttribute("y")||0),r=l(e.getAttribute("rx")||e.getAttribute("ry")||0),i=l(e.getAttribute("ry")||e.getAttribute("rx")||0),o=l(e.getAttribute("width")),a=l(e.getAttribute("height")),s=.448084975506,c=new et;c.moveTo(t+r,n),c.lineTo(t+o-r,n),(0!==r||0!==i)&&c.bezierCurveTo(t+o-r*s,n,t+o,n+i*s,t+o,n+i);c.lineTo(t+o,n+a-i),(0!==r||0!==i)&&c.bezierCurveTo(t+o,n+a-i*s,t+o-r*s,n+a,t+o-r,n+a);c.lineTo(t+r,n+a),(0!==r||0!==i)&&c.bezierCurveTo(t+r*s,n+a,t,n+a-i*s,t,n+a-i);c.lineTo(t,n+i),(0!==r||0!==i)&&c.bezierCurveTo(t,n+i*s,t+r*s,n,t+r,n);return c}(t);break;case"polygon":r=i(t,r),O=function(e){function t(e,t,n){const o=l(t),a=l(n);0===i?r.moveTo(o,a):r.lineTo(o,a),i++}const n=/([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g,r=new et;let i=0;return e.getAttribute("points").replace(n,t),r.currentPath.autoClose=!0,r}(t);break;case"polyline":r=i(t,r),O=function(e){function t(e,t,n){const o=l(t),a=l(n);0===i?r.moveTo(o,a):r.lineTo(o,a),i++}const n=/([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g,r=new et;let i=0;return e.getAttribute("points").replace(n,t),r.currentPath.autoClose=!1,r}(t);break;case"circle":r=i(t,r),O=function(e){const t=l(e.getAttribute("cx")||0),n=l(e.getAttribute("cy")||0),r=l(e.getAttribute("r")||0),i=new Je;i.absarc(t,n,r,0,2*Math.PI);const o=new et;return o.subPaths.push(i),o}(t);break;case"ellipse":r=i(t,r),O=function(e){const t=l(e.getAttribute("cx")||0),n=l(e.getAttribute("cy")||0),r=l(e.getAttribute("rx")||0),i=l(e.getAttribute("ry")||0),o=new Je;o.absellipse(t,n,r,i,0,2*Math.PI);const a=new et;return a.subPaths.push(o),a}(t);break;case"line":r=i(t,r),O=function(e){const t=l(e.getAttribute("x1")||0),n=l(e.getAttribute("y1")||0),r=l(e.getAttribute("x2")||0),i=l(e.getAttribute("y2")||0),o=new et;return o.moveTo(t,n),o.lineTo(r,i),o.currentPath.autoClose=!1,o}(t);break;case"defs":c=!0;break;case"use":r=i(t,r);const s=(t.getAttributeNS("http://www.w3.org/1999/xlink","href")||"").substring(1),u=t.viewportElement.getElementById(s);u?e(u,r):console.warn("SVGLoader: 'use node' references non-existent node id: "+s)}O&&(void 0!==r.fill&&"none"!==r.fill&&O.color.setStyle(r.fill,cs),function(e,t){function n(e){A.set(e.x,e.y,1).applyMatrix3(t),e.set(A.x,A.y)}function r(e){const n=e.xRadius,r=e.yRadius,i=Math.cos(e.aRotation),o=Math.sin(e.aRotation),a=new f(n*i,n*o,0),s=new f(-r*o,r*i,0),c=a.applyMatrix3(t),l=s.applyMatrix3(t),h=y.set(c.x,l.x,0,c.y,l.y,0,0,0,1),d=x.copy(h).invert(),p=w.copy(d).transpose().multiply(d).elements,m=function(e,t,n){let r,i,o,a,s;const c=e+n,l=e-n,u=Math.sqrt(l*l+4*t*t);c>0?(r=.5*(c+u),s=1/r,i=e*s*n-t*s*t):c<0?i=.5*(c-u):(r=.5*u,i=-.5*u);o=l>0?l+u:l-u;Math.abs(o)>2*Math.abs(t)?(s=-2*t/o,a=1/Math.sqrt(1+s*s),o=s*a):0===Math.abs(t)?(o=1,a=0):(s=-.5*o/t,o=1/Math.sqrt(1+s*s),a=s*o);l>0&&(s=o,o=-a,a=s);return{rt1:r,rt2:i,cs:o,sn:a}}(p[0],p[1],p[4]),g=Math.sqrt(m.rt1),b=Math.sqrt(m.rt2);e.xRadius=1/g,e.yRadius=1/b,e.aRotation=Math.atan2(m.sn,m.cs);if(!((e.aEndAngle-e.aStartAngle)%(2*Math.PI)<Number.EPSILON)){const n=x.set(g,0,0,0,b,0,0,0,1),r=w.set(m.cs,m.sn,0,-m.sn,m.cs,0,0,0,1),i=n.multiply(r).multiply(h),o=e=>{const{x:t,y:n}=new f(Math.cos(e),Math.sin(e),0).applyMatrix3(i);return Math.atan2(n,t)};e.aStartAngle=o(e.aStartAngle),e.aEndAngle=o(e.aEndAngle),u(t)&&(e.aClockwise=!e.aClockwise)}}function i(e){const n=d(t),r=p(t);e.xRadius*=n,e.yRadius*=r;const i=n>Number.EPSILON?Math.atan2(t.elements[1],t.elements[0]):Math.atan2(-t.elements[3],t.elements[4]);e.aRotation+=i,u(t)&&(e.aStartAngle*=-1,e.aEndAngle*=-1,e.aClockwise=!e.aClockwise)}const o=e.subPaths;for(let e=0,a=o.length;e<a;e++){const a=o[e].curves;for(let e=0;e<a.length;e++){const o=a[e];o.isLineCurve?(n(o.v1),n(o.v2)):o.isCubicBezierCurve?(n(o.v0),n(o.v1),n(o.v2),n(o.v3)):o.isQuadraticBezierCurve?(n(o.v0),n(o.v1),n(o.v2)):o.isEllipseCurve&&(T.set(o.aX,o.aY),n(T),o.aX=T.x,o.aY=T.y,h(t)?r(o):i(o))}}}(O,C),m.push(O),O.userData={node:t,style:r});const k=t.childNodes;for(let t=0;t<k.length;t++){const n=k[t];c&&"style"!==n.nodeName&&"defs"!==n.nodeName||e(n,r)}s&&(b.pop(),b.length>0?C.copy(b[b.length-1]):C.identity())}(O.documentElement,{fill:"#000",fillOpacity:1,strokeOpacity:1,strokeWidth:1,strokeLineJoin:"miter",strokeLineCap:"butt",strokeMiterLimit:4});return{paths:m,xml:O.documentElement}}static createShapes(e){const t=999999999,n=0,r=1,i=2,o=3,a=4,s=5,c=6,l={loc:n,t:0};function u(e,t,r,o){const a=e.x,s=t.x,c=r.x,u=o.x,d=e.y,p=t.y,f=r.y,m=o.y,g=(u-c)*(d-f)-(m-f)*(a-c),b=(m-f)*(s-a)-(u-c)*(p-d),y=g/b,v=((s-a)*(d-f)-(p-d)*(a-c))/b;if(0===b&&0!==g||y<=0||y>=1||v<0||v>1)return null;if(0===g&&0===b){for(let c=0;c<2;c++){if(h(0===c?r:o,e,t),l.loc==n){const e=0===c?r:o;return{x:e.x,y:e.y,t:l.t}}if(l.loc==i){return{x:+(a+l.t*(s-a)).toPrecision(10),y:+(d+l.t*(p-d)).toPrecision(10),t:l.t}}}return null}for(let i=0;i<2;i++)if(h(0===i?r:o,e,t),l.loc==n){const e=0===i?r:o;return{x:e.x,y:e.y,t:l.t}}return{x:+(a+y*(s-a)).toPrecision(10),y:+(d+y*(p-d)).toPrecision(10),t:y}}function h(e,t,u){const h=u.x-t.x,d=u.y-t.y,p=e.x-t.x,f=e.y-t.y,m=h*f-p*d;if(e.x===t.x&&e.y===t.y)return l.loc=n,void(l.t=0);if(e.x===u.x&&e.y===u.y)return l.loc=r,void(l.t=1);if(m<-Number.EPSILON)return void(l.loc=o);if(m>Number.EPSILON)return void(l.loc=a);if(h*p<0||d*f<0)return void(l.loc=s);if(Math.sqrt(h*h+d*d)<Math.sqrt(p*p+f*f))return void(l.loc=c);let g;g=0!==h?p/h:f/d,l.loc=i,l.t=g}function d(e,t,n){const r=new v;t.getCenter(r);const i=[];return n.forEach(t=>{if(t.boundingBox.containsPoint(r)){const n=function(e,t){const n=[],r=[];for(let i=1;i<e.length;i++){const o=e[i-1],a=e[i];for(let e=1;e<t.length;e++){const i=u(o,a,t[e-1],t[e]);null!==i&&void 0===n.find(e=>e.t<=i.t+Number.EPSILON&&e.t>=i.t-Number.EPSILON)&&(n.push(i),r.push(new v(i.x,i.y)))}}return r}(e,t.points);n.forEach(e=>{i.push({identifier:t.identifier,isCW:t.isCW,point:e})})}}),i.sort((e,t)=>e.point.x-t.point.x),i}let p=t,f=-999999999,m=e.subPaths.map(e=>{const n=e.getPoints();let r=-999999999,i=t,o=-999999999,a=t;for(let e=0;e<n.length;e++){const t=n[e];t.y>r&&(r=t.y),t.y<i&&(i=t.y),t.x>o&&(o=t.x),t.x<a&&(a=t.x)}return f<=o&&(f=o+1),p>=a&&(p=a-1),{curves:e.curves,points:n,isCW:Ke.isClockWise(n),identifier:-1,boundingBox:new Ze(new v(a,i),new v(o,r))}});m=m.filter(e=>e.points.length>1);for(let e=0;e<m.length;e++)m[e].identifier=e;const g=m.map(t=>function(e,t,n,r,i){null!=i&&""!==i||(i="nonzero");const o=new v;e.boundingBox.getCenter(o);const a=d([new v(n,o.y),new v(r,o.y)],e.boundingBox,t);a.sort((e,t)=>e.point.x-t.point.x);const s=[],c=[];a.forEach(t=>{t.identifier===e.identifier?s.push(t):c.push(t)});const l=s[0].point.x,u=[];let h=0;for(;h<c.length&&c[h].point.x<l;)u.length>0&&u[u.length-1]===c[h].identifier?u.pop():u.push(c[h].identifier),h++;if(u.push(e.identifier),"evenodd"===i){const t=u.length%2==0,n=u[u.length-2];return{identifier:e.identifier,isHole:t,for:n}}if("nonzero"===i){let n=!0,r=null,i=null;for(let e=0;e<u.length;e++){const o=u[e];n?(i=t[o].isCW,n=!1,r=o):i!==t[o].isCW&&(i=t[o].isCW,n=!0)}return{identifier:e.identifier,isHole:n,for:r}}console.warn('fill-rule: "'+i+'" is currently not implemented.')}(t,m,p,f,e.userData?e.userData.style.fillRule:void 0)),b=[];return m.forEach(e=>{if(!g[e.identifier].isHole){const t=new $e;t.curves=e.curves;g.filter(t=>t.isHole&&t.for===e.identifier).forEach(e=>{const n=m[e.identifier],r=new Je;r.curves=n.curves,t.holes.push(r)}),b.push(t)}}),b}static getStrokeStyle(e,t,n,r,i){return{strokeColor:t=void 0!==t?t:"#000",strokeWidth:e=void 0!==e?e:1,strokeLineJoin:n=void 0!==n?n:"miter",strokeLineCap:r=void 0!==r?r:"butt",strokeMiterLimit:i=void 0!==i?i:4}}static pointsToStroke(e,t,n,r){const i=[],o=[],a=[];if(0===ls.pointsToStrokeWithBuffers(e,t,n,r,i,o,a))return null;const s=new O;return s.setAttribute("position",new k(i,3)),s.setAttribute("normal",new k(o,3)),s.setAttribute("uv",new k(a,2)),s}static pointsToStrokeWithBuffers(e,t,n,r,i,o,a,s){const c=new v,l=new v,u=new v,h=new v,d=new v,p=new v,f=new v,m=new v,g=new v,b=new v,y=new v,x=new v,w=new v,E=new v,T=new v,A=new v,C=new v;n=void 0!==n?n:12,r=void 0!==r?r:.001,s=void 0!==s?s:0,e=function(e){let t=!1;for(let n=1,i=e.length-1;n<i;n++)if(e[n].distanceTo(e[n+1])<r){t=!0;break}if(!t)return e;const n=[];n.push(e[0]);for(let t=1,i=e.length-1;t<i;t++)e[t].distanceTo(e[t+1])>=r&&n.push(e[t]);return n.push(e[e.length-1]),n}(e);const O=e.length;if(O<2)return 0;const k=e[0].equals(e[O-1]);let S,R,M=e[0];const I=t.strokeWidth/2,P=1/(O-1);let _,N,L,D,j=0,F=!1,U=0,B=3*s,z=2*s;H(e[0],e[1],c).multiplyScalar(I),m.copy(e[0]).sub(c),g.copy(e[0]).add(c),b.copy(m),y.copy(g);for(let n=1;n<O;n++){S=e[n],R=n===O-1?k?e[1]:void 0:e[n+1];const r=c;if(H(M,S,r),u.copy(r).multiplyScalar(I),x.copy(S).sub(u),w.copy(S).add(u),_=j+P,N=!1,void 0!==R){H(S,R,l),u.copy(l).multiplyScalar(I),E.copy(S).sub(u),T.copy(S).add(u),L=!0,u.subVectors(R,M),r.dot(u)<0&&(L=!1),1===n&&(F=L),u.subVectors(R,S),u.normalize();const e=Math.abs(r.dot(u));if(e>Number.EPSILON){const n=I/e;u.multiplyScalar(-n),h.subVectors(S,M),d.copy(h).setLength(n).add(u),A.copy(d).negate();const r=d.length(),i=h.length();h.divideScalar(i),p.subVectors(R,S);const o=p.length();switch(p.divideScalar(o),h.dot(A)<i&&p.dot(A)<o&&(N=!0),C.copy(d).add(S),A.add(S),D=!1,N?L?(T.copy(A),w.copy(A)):(E.copy(A),x.copy(A)):W(),t.strokeLineJoin){case"bevel":X(L,N,_);break;case"round":q(L,N),L?G(S,x,E,_,0):G(S,T,w,_,1);break;default:const e=I*t.strokeMiterLimit/r;if(e<1){if("miter-clip"!==t.strokeLineJoin){X(L,N,_);break}q(L,N),L?(p.subVectors(C,x).multiplyScalar(e).add(x),f.subVectors(C,E).multiplyScalar(e).add(E),V(x,_,0),V(p,_,0),V(S,_,.5),V(S,_,.5),V(p,_,0),V(f,_,0),V(S,_,.5),V(f,_,0),V(E,_,0)):(p.subVectors(C,w).multiplyScalar(e).add(w),f.subVectors(C,T).multiplyScalar(e).add(T),V(w,_,1),V(p,_,1),V(S,_,.5),V(S,_,.5),V(p,_,1),V(f,_,1),V(S,_,.5),V(f,_,1),V(T,_,1))}else N?(L?(V(g,j,1),V(m,j,0),V(C,_,0),V(g,j,1),V(C,_,0),V(A,_,1)):(V(g,j,1),V(m,j,0),V(C,_,1),V(m,j,0),V(A,_,0),V(C,_,1)),L?E.copy(C):T.copy(C)):L?(V(x,_,0),V(C,_,0),V(S,_,.5),V(S,_,.5),V(C,_,0),V(E,_,0)):(V(w,_,1),V(C,_,1),V(S,_,.5),V(S,_,.5),V(C,_,1),V(T,_,1)),D=!0}}else W()}else W();k||n!==O-1||Y(e[0],b,y,L,!0,j),j=_,M=S,m.copy(E),g.copy(T)}if(k){if(N&&i){let e=C,t=A;F!==L&&(e=A,t=C),L?(D||F)&&(t.toArray(i,0),t.toArray(i,9),D&&e.toArray(i,3)):!D&&F||(t.toArray(i,3),t.toArray(i,9),D&&e.toArray(i,0))}}else Y(S,x,w,L,!1,_);return U;function H(e,t,n){return n.subVectors(t,e),n.set(-n.y,n.x).normalize()}function V(e,t,n){i&&(i[B]=e.x,i[B+1]=e.y,i[B+2]=0,o&&(o[B]=0,o[B+1]=0,o[B+2]=1),B+=3,a&&(a[z]=t,a[z+1]=n,z+=2)),U+=3}function G(e,t,r,i,o){c.copy(t).sub(e).normalize(),l.copy(r).sub(e).normalize();let a=Math.PI;const s=c.dot(l);Math.abs(s)<1&&(a=Math.abs(Math.acos(s))),a/=n,u.copy(t);for(let t=0,r=n-1;t<r;t++)h.copy(u).rotateAround(e,a),V(u,i,o),V(h,i,o),V(e,i,.5),u.copy(h);V(h,i,o),V(r,i,o),V(e,i,.5)}function W(){V(g,j,1),V(m,j,0),V(x,_,0),V(g,j,1),V(x,_,0),V(w,_,1)}function X(e,t,n){t?e?(V(g,j,1),V(m,j,0),V(x,_,0),V(g,j,1),V(x,_,0),V(A,_,1),V(x,n,0),V(E,n,0),V(A,n,.5)):(V(g,j,1),V(m,j,0),V(w,_,1),V(m,j,0),V(A,_,0),V(w,_,1),V(w,n,1),V(A,n,0),V(T,n,1)):e?(V(x,n,0),V(E,n,0),V(S,n,.5)):(V(w,n,1),V(T,n,0),V(S,n,.5))}function q(e,t){t&&(e?(V(g,j,1),V(m,j,0),V(x,_,0),V(g,j,1),V(x,_,0),V(A,_,1),V(x,j,0),V(S,_,.5),V(A,_,1),V(S,_,.5),V(E,j,0),V(A,_,1)):(V(g,j,1),V(m,j,0),V(w,_,1),V(m,j,0),V(A,_,0),V(w,_,1),V(w,j,1),V(A,_,0),V(S,_,.5),V(S,_,.5),V(A,_,0),V(T,j,1)))}function Y(e,n,r,o,s,d){switch(t.strokeLineCap){case"round":s?G(e,r,n,d,.5):G(e,n,r,d,.5);break;case"square":if(s)c.subVectors(n,e),l.set(c.y,-c.x),u.addVectors(c,l).add(e),h.subVectors(l,c).add(e),o?(u.toArray(i,3),h.toArray(i,0),h.toArray(i,9)):(u.toArray(i,3),1===a[7]?h.toArray(i,9):u.toArray(i,9),h.toArray(i,0));else{c.subVectors(r,e),l.set(c.y,-c.x),u.addVectors(c,l).add(e),h.subVectors(l,c).add(e);const t=i.length;o?(u.toArray(i,t-3),h.toArray(i,t-6),h.toArray(i,t-12)):(h.toArray(i,t-6),u.toArray(i,t-3),h.toArray(i,t-12))}}}}}class us extends X{constructor(e){super(e),this.debug=!1,this.group=null,this.materials=[],this.meshes=[]}load(e,t,n,r){const i=this,o=""===this.path?J.extractUrlBase(e):this.path,a=new q(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e,t){this.group=new Oe,this.materials=[],this.meshes=[],this.readFile(e,t);for(let e=0;e<this.meshes.length;e++)this.group.add(this.meshes[e]);return this.group}readFile(e,t){const n=new DataView(e),r=new hs(n,0,this.debugMessage);if(r.id===ps||r.id===fs||r.id===ds){let e=r.readChunk();for(;e;){if(e.id===ms){const t=e.readDWord();this.debugMessage("3DS file version: "+t)}else e.id===Es?this.readMeshData(e,t):this.debugMessage("Unknown main chunk: "+e.hexId);e=r.readChunk()}}this.debugMessage("Parsed "+this.meshes.length+" meshes")}readMeshData(e,t){let n=e.readChunk();for(;n;){if(n.id===Ts){const e=+n.readDWord();this.debugMessage("Mesh Version: "+e)}else if(n.id===As){const e=n.readFloat();this.debugMessage("Master scale: "+e),this.group.scale.set(e,e,e)}else n.id===Ws?(this.debugMessage("Named Object"),this.readNamedObject(n)):n.id===Cs?(this.debugMessage("Material"),this.readMaterialEntry(n,t)):this.debugMessage("Unknown MDATA chunk: "+n.hexId);n=e.readChunk()}}readNamedObject(e){const t=e.readString();let n=e.readChunk();for(;n;){if(n.id===Xs){const e=this.readMesh(n);e.name=t,this.meshes.push(e)}else this.debugMessage("Unknown named object chunk: "+n.hexId);n=e.readChunk()}}readMaterialEntry(e,t){let n=e.readChunk();const r=new Be;for(;n;){if(n.id===Os)r.name=n.readString(),this.debugMessage(" Name: "+r.name);else if(n.id===Ns)this.debugMessage(" Wireframe"),r.wireframe=!0;else if(n.id===Ls){const e=n.readByte();r.wireframeLinewidth=e,this.debugMessage(" Wireframe Thickness: "+e)}else if(n.id===Ps)r.side=D,this.debugMessage(" DoubleSided");else if(n.id===_s)this.debugMessage(" Additive Blending"),r.blending=tt;else if(n.id===Ss)this.debugMessage(" Diffuse Color"),r.color=this.readColor(n);else if(n.id===Rs)this.debugMessage(" Specular Color"),r.specular=this.readColor(n);else if(n.id===ks)this.debugMessage(" Ambient color"),r.color=this.readColor(n);else if(n.id===Ms){const e=this.readPercentage(n);r.shininess=100*e,this.debugMessage(" Shininess : "+e)}else if(n.id===Is){const e=this.readPercentage(n);r.opacity=1-e,this.debugMessage(" Transparency : "+e),r.transparent=r.opacity<1}else n.id===Ds?(this.debugMessage(" ColorMap"),r.map=this.readMap(n,t)):n.id===Fs?(this.debugMessage(" BumpMap"),r.bumpMap=this.readMap(n,t)):n.id===js?(this.debugMessage(" OpacityMap"),r.alphaMap=this.readMap(n,t)):n.id===Us?(this.debugMessage(" SpecularMap"),r.specularMap=this.readMap(n,t)):this.debugMessage(" Unknown material chunk: "+n.hexId);n=e.readChunk()}this.materials[r.name]=r}readMesh(e){let t=e.readChunk();const n=new O,r=new Be,i=new S(n,r);for(i.name="mesh";t;){if(t.id===qs){const e=t.readWord();this.debugMessage(" Vertex: "+e);const r=[];for(let n=0;n<e;n++)r.push(t.readFloat()),r.push(t.readFloat()),r.push(t.readFloat());n.setAttribute("position",new k(r,3))}else if(t.id===Ys)this.readFaceArray(t,i);else if(t.id===Qs){const e=t.readWord();this.debugMessage(" UV: "+e);const r=[];for(let n=0;n<e;n++)r.push(t.readFloat()),r.push(t.readFloat());n.setAttribute("uv",new k(r,2))}else if(t.id===Zs){this.debugMessage(" Tranformation Matrix (TODO)");const e=[];for(let n=0;n<12;n++)e[n]=t.readFloat();const r=new N;r.elements[0]=e[0],r.elements[1]=e[6],r.elements[2]=e[3],r.elements[3]=e[9],r.elements[4]=e[2],r.elements[5]=e[8],r.elements[6]=e[5],r.elements[7]=e[11],r.elements[8]=e[1],r.elements[9]=e[7],r.elements[10]=e[4],r.elements[11]=e[10],r.elements[12]=0,r.elements[13]=0,r.elements[14]=0,r.elements[15]=1,r.transpose();const o=new N;o.copy(r).invert(),n.applyMatrix4(o),r.decompose(i.position,i.quaternion,i.scale)}else this.debugMessage(" Unknown mesh chunk: "+t.hexId);t=e.readChunk()}return n.computeVertexNormals(),i}readFaceArray(e,t){const n=e.readWord();this.debugMessage(" Faces: "+n);const r=[];for(let t=0;t<n;++t)r.push(e.readWord(),e.readWord(),e.readWord()),e.readWord();t.geometry.setIndex(r);let i=0,o=0;for(;!e.endOfChunk;){const n=e.readChunk();if(n.id===Ks){this.debugMessage(" Material Group");const e=this.readMaterialGroup(n),r=3*e.index.length;t.geometry.addGroup(o,r,i),o+=r,i++;const a=this.materials[e.name];!1===Array.isArray(t.material)&&(t.material=[]),void 0!==a&&t.material.push(a)}else this.debugMessage(" Unknown face array chunk: "+n.hexId)}1===t.material.length&&(t.material=t.material[0])}readMap(e,t){let n=e.readChunk(),r={};const i=new ae(this.manager);for(i.setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin);n;){if(n.id===Bs){const e=n.readString();r=i.load(e),this.debugMessage(" File: "+t+e)}else n.id===Vs?(r.offset.x=n.readFloat(),this.debugMessage(" OffsetX: "+r.offset.x)):n.id===Gs?(r.offset.y=n.readFloat(),this.debugMessage(" OffsetY: "+r.offset.y)):n.id===zs?(r.repeat.x=n.readFloat(),this.debugMessage(" RepeatX: "+r.repeat.x)):n.id===Hs?(r.repeat.y=n.readFloat(),this.debugMessage(" RepeatY: "+r.repeat.y)):this.debugMessage(" Unknown map chunk: "+n.hexId);n=e.readChunk()}return r}readMaterialGroup(e){const t=e.readString(),n=e.readWord();this.debugMessage(" Name: "+t),this.debugMessage(" Faces: "+n);const r=[];for(let t=0;t<n;++t)r.push(e.readWord());return{name:t,index:r}}readColor(e){const t=e.readChunk(),n=new K;if(t.id===bs||t.id===ys){const e=t.readByte(),r=t.readByte(),i=t.readByte();n.setRGB(e/255,r/255,i/255),this.debugMessage(" Color: "+n.r+", "+n.g+", "+n.b)}else if(t.id===gs||t.id===vs){const e=t.readFloat(),r=t.readFloat(),i=t.readFloat();n.setRGB(e,r,i),this.debugMessage(" Color: "+n.r+", "+n.g+", "+n.b)}else this.debugMessage(" Unknown color chunk: "+t.hexId);return n}readPercentage(e){const t=e.readChunk();switch(t.id){case xs:return t.readShort()/100;case ws:return t.readFloat();default:return this.debugMessage(" Unknown percentage chunk: "+t.hexId),0}}debugMessage(e){this.debug&&console.log(e)}}class hs{constructor(e,t,n){this.data=e,this.offset=t,this.position=t,this.debugMessage=n,this.debugMessage instanceof Function&&(this.debugMessage=function(){}),this.id=this.readWord(),this.size=this.readDWord(),this.end=this.offset+this.size,this.end>e.byteLength&&this.debugMessage("Bad chunk size for chunk at "+t)}readChunk(){if(this.endOfChunk)return null;try{const e=new hs(this.data,this.position,this.debugMessage);return this.position+=e.size,e}catch(e){return this.debugMessage("Unable to read chunk at "+this.position),null}}get hexId(){return this.id.toString(16)}get endOfChunk(){return this.position>=this.end}readByte(){const e=this.data.getUint8(this.position,!0);return this.position+=1,e}readFloat(){try{const e=this.data.getFloat32(this.position,!0);return this.position+=4,e}catch(e){return this.debugMessage(e+" "+this.position+" "+this.data.byteLength),0}}readInt(){const e=this.data.getInt32(this.position,!0);return this.position+=4,e}readShort(){const e=this.data.getInt16(this.position,!0);return this.position+=2,e}readDWord(){const e=this.data.getUint32(this.position,!0);return this.position+=4,e}readWord(){const e=this.data.getUint16(this.position,!0);return this.position+=2,e}readString(){let e="",t=this.readByte();for(;t;)e+=String.fromCharCode(t),t=this.readByte();return e}}const ds=19789,ps=15786,fs=49725,ms=2,gs=16,bs=17,ys=18,vs=19,xs=48,ws=49,Es=15677,Ts=15678,As=256,Cs=45055,Os=40960,ks=40976,Ss=40992,Rs=41008,Ms=41024,Is=41040,Ps=41089,_s=41091,Ns=41093,Ls=41095,Ds=41472,js=41488,Fs=41520,Us=41476,Bs=41728,zs=41812,Hs=41814,Vs=41816,Gs=41818,Ws=16384,Xs=16640,qs=16656,Ys=16672,Ks=16688,Qs=16704,Zs=16736;
7
+ */var ct=function(e){return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};try{URL.revokeObjectURL(ct(""))}catch(e){ct=function(e){return"data:application/javascript;charset=UTF-8,"+encodeURI(e)}}var lt=Uint8Array,ut=Uint16Array,ht=Uint32Array,dt=new lt([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),pt=new lt([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ft=new lt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),mt=function(e,t){for(var n=new ut(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];var i=new ht(n[30]);for(r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)i[o]=o-n[r]<<5|r;return[n,i]},gt=mt(dt,2),bt=gt[0],yt=gt[1];bt[28]=258,yt[258]=28;for(var vt=mt(pt,0)[0],xt=new ut(32768),wt=0;wt<32768;++wt){var Et=(43690&wt)>>>1|(21845&wt)<<1;Et=(61680&(Et=(52428&Et)>>>2|(13107&Et)<<2))>>>4|(3855&Et)<<4,xt[wt]=((65280&Et)>>>8|(255&Et)<<8)>>>1}var Tt=function(e,t,n){for(var r=e.length,i=0,o=new ut(t);i<r;++i)++o[e[i]-1];var a,s=new ut(t);for(i=0;i<t;++i)s[i]=s[i-1]+o[i-1]<<1;if(n){a=new ut(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],h=s[e[i]-1]++<<u,d=h|(1<<u)-1;h<=d;++h)a[xt[h]>>>c]=l}else for(a=new ut(r),i=0;i<r;++i)e[i]&&(a[i]=xt[s[e[i]-1]++]>>>15-e[i]);return a},At=new lt(288);for(wt=0;wt<144;++wt)At[wt]=8;for(wt=144;wt<256;++wt)At[wt]=9;for(wt=256;wt<280;++wt)At[wt]=7;for(wt=280;wt<288;++wt)At[wt]=8;var Ct=new lt(32);for(wt=0;wt<32;++wt)Ct[wt]=5;var Ot=Tt(At,9,1),kt=Tt(Ct,5,1),St=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Mt=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(7&t)&n},Rt=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},It=function(e){return(e/8|0)+(7&e&&1)},Pt=function(e,t,n){var r=e.length;if(!r||n&&!n.l&&r<5)return t||new lt(0);var i=!t||n,o=!n||n.i;n||(n={}),t||(t=new lt(3*r));var a=function(e){var n=t.length;if(e>n){var r=new lt(Math.max(2*n,e));r.set(t),t=r}},s=n.f||0,c=n.p||0,l=n.b||0,u=n.l,h=n.d,d=n.m,p=n.n,f=8*r;do{if(!u){n.f=s=Mt(e,c,1);var m=Mt(e,c+1,3);if(c+=3,!m){var g=e[(k=It(c)+4)-4]|e[k-3]<<8,b=k+g;if(b>r){if(o)throw"unexpected EOF";break}i&&a(l+g),t.set(e.subarray(k,b),l),n.b=l+=g,n.p=c=8*b;continue}if(1==m)u=Ot,h=kt,d=9,p=5;else{if(2!=m)throw"invalid block type";var y=Mt(e,c,31)+257,v=Mt(e,c+10,15)+4,x=y+Mt(e,c+5,31)+1;c+=14;for(var w=new lt(x),E=new lt(19),T=0;T<v;++T)E[ft[T]]=Mt(e,c+3*T,7);c+=3*v;var A=St(E),C=(1<<A)-1,O=Tt(E,A,1);for(T=0;T<x;){var k,S=O[Mt(e,c,C)];if(c+=15&S,(k=S>>>4)<16)w[T++]=k;else{var M=0,R=0;for(16==k?(R=3+Mt(e,c,3),c+=2,M=w[T-1]):17==k?(R=3+Mt(e,c,7),c+=3):18==k&&(R=11+Mt(e,c,127),c+=7);R--;)w[T++]=M}}var I=w.subarray(0,y),P=w.subarray(y);d=St(I),p=St(P),u=Tt(I,d,1),h=Tt(P,p,1)}if(c>f){if(o)throw"unexpected EOF";break}}i&&a(l+131072);for(var _=(1<<d)-1,N=(1<<p)-1,L=c;;L=c){var D=(M=u[Rt(e,c)&_])>>>4;if((c+=15&M)>f){if(o)throw"unexpected EOF";break}if(!M)throw"invalid length/literal";if(D<256)t[l++]=D;else{if(256==D){L=c,u=null;break}var j=D-254;if(D>264){var F=dt[T=D-257];j=Mt(e,c,(1<<F)-1)+bt[T],c+=F}var U=h[Rt(e,c)&N],B=U>>>4;if(!U)throw"invalid distance";c+=15&U;P=vt[B];if(B>3){F=pt[B];P+=Rt(e,c)&(1<<F)-1,c+=F}if(c>f){if(o)throw"unexpected EOF";break}i&&a(l+131072);for(var z=l+j;l<z;l+=4)t[l]=t[l-P],t[l+1]=t[l+1-P],t[l+2]=t[l+2-P],t[l+3]=t[l+3-P];l=z}}n.l=u,n.p=L,n.b=l,u&&(s=1,n.m=d,n.d=h,n.n=p)}while(!s);return l==t.length?t:function(e,t,n){(null==n||n>e.length)&&(n=e.length);var r=new(e instanceof ut?ut:e instanceof ht?ht:lt)(n-t);return r.set(e.subarray(t,n)),r}(t,0,l)},_t=new lt(0);function Nt(e,t){return Pt((function(e){if(8!=(15&e[0])||e[0]>>>4>7||(e[0]<<8|e[1])%31)throw"invalid zlib data";if(32&e[1])throw"invalid zlib data: preset dictionaries not supported"}(e),e.subarray(2,-4)),t)}var Lt="undefined"!=typeof TextDecoder&&new TextDecoder;try{Lt.decode(_t,{stream:!0})}catch(e){}let Dt=class extends t{constructor(e){super(e),this.type=n}parse(e){const t=65536,c=14,u=65537,h=16384,d=Math.pow(2.7182818,2.2);const p={l:0,c:0,lc:0};function f(e,t,n,r,i){for(;n<e;)t=t<<8|Y(r,i),n+=8;n-=e,p.l=t>>n&(1<<e)-1,p.c=t,p.lc=n}const m=new Array(59);function g(e,t,n,r,i,o){const a=t;let s=0,c=0;for(;r<=i;r++){if(a.value-t.value>n)return!1;f(6,s,c,e,a);const l=p.l;if(s=p.c,c=p.lc,o[r]=l,63==l){if(a.value-t.value>n)throw new Error("Something wrong with hufUnpackEncTable");f(8,s,c,e,a);let l=p.l+6;if(s=p.c,c=p.lc,r+l>i+1)throw new Error("Something wrong with hufUnpackEncTable");for(;l--;)o[r++]=0;r--}else if(l>=59){let e=l-59+2;if(r+e>i+1)throw new Error("Something wrong with hufUnpackEncTable");for(;e--;)o[r++]=0;r--}}!function(e){for(let e=0;e<=58;++e)m[e]=0;for(let t=0;t<u;++t)m[e[t]]+=1;let t=0;for(let e=58;e>0;--e){const n=t+m[e]>>1;m[e]=t,t=n}for(let t=0;t<u;++t){const n=e[t];n>0&&(e[t]=n|m[n]++<<6)}}(o)}function b(e){return 63&e}function y(e){return e>>6}const v={c:0,lc:0};function x(e,t,n,r){e=e<<8|Y(n,r),t+=8,v.c=e,v.lc=t}const w={c:0,lc:0};function E(e,t,n,r,i,o,a,s,c){if(e==t){r<8&&(x(n,r,i,o),n=v.c,r=v.lc);let e=n>>(r-=8);if(e=new Uint8Array([e])[0],s.value+e>c)return!1;const t=a[s.value-1];for(;e-- >0;)a[s.value++]=t}else{if(!(s.value<c))return!1;a[s.value++]=e}w.c=n,w.lc=r}function T(e){return 65535&e}function A(e){const t=T(e);return t>32767?t-65536:t}const C={a:0,b:0};function O(e,t){const n=A(e),r=A(t),i=n+(1&r)+(r>>1),o=i,a=i-r;C.a=o,C.b=a}function k(e,t){const n=T(e),r=T(t),i=n-(r>>1)&65535,o=r+i-32768&65535;C.a=o,C.b=i}function S(e,t,n,r,i,o,a){const s=a<16384,c=n>i?i:n;let l,u,h=1;for(;h<=c;)h<<=1;for(h>>=1,l=h,h>>=1;h>=1;){u=0;const a=u+o*(i-l),c=o*h,d=o*l,p=r*h,f=r*l;let m,g,b,y;for(;u<=a;u+=d){let i=u;const o=u+r*(n-l);for(;i<=o;i+=f){const n=i+p,r=i+c,o=r+p;s?(O(e[i+t],e[r+t]),m=C.a,b=C.b,O(e[n+t],e[o+t]),g=C.a,y=C.b,O(m,g),e[i+t]=C.a,e[n+t]=C.b,O(b,y),e[r+t]=C.a,e[o+t]=C.b):(k(e[i+t],e[r+t]),m=C.a,b=C.b,k(e[n+t],e[o+t]),g=C.a,y=C.b,k(m,g),e[i+t]=C.a,e[n+t]=C.b,k(b,y),e[r+t]=C.a,e[o+t]=C.b)}if(n&h){const n=i+c;s?O(e[i+t],e[n+t]):k(e[i+t],e[n+t]),m=C.a,e[n+t]=C.b,e[i+t]=m}}if(i&h){let i=u;const o=u+r*(n-l);for(;i<=o;i+=f){const n=i+p;s?O(e[i+t],e[n+t]):k(e[i+t],e[n+t]),m=C.a,e[n+t]=C.b,e[i+t]=m}}l=h,h>>=1}return u}function M(e,t,n,r,i,o){const a=n.value,s=q(t,n),l=q(t,n);n.value+=4;const d=q(t,n);if(n.value+=4,s<0||s>=u||l<0||l>=u)throw new Error("Something wrong with HUF_ENCSIZE");const p=new Array(u),f=new Array(h);!function(e){for(let t=0;t<h;t++)e[t]={},e[t].len=0,e[t].lit=0,e[t].p=null}(f);if(g(e,n,r-(n.value-a),s,l,p),d>8*(r-(n.value-a)))throw new Error("Something wrong with hufUncompress");!function(e,t,n,r){for(;t<=n;t++){const n=y(e[t]),i=b(e[t]);if(n>>i)throw new Error("Invalid table entry");if(i>c){const e=r[n>>i-c];if(e.len)throw new Error("Invalid table entry");if(e.lit++,e.p){const t=e.p;e.p=new Array(e.lit);for(let n=0;n<e.lit-1;++n)e.p[n]=t[n]}else e.p=new Array(1);e.p[e.lit-1]=t}else if(i){let e=0;for(let o=1<<c-i;o>0;o--){const o=r[(n<<c-i)+e];if(o.len||o.p)throw new Error("Invalid table entry");o.len=i,o.lit=t,e++}}}}(p,s,l,f),function(e,t,n,r,i,o,a,s,l){let u=0,h=0;const d=a,p=Math.trunc(r.value+(i+7)/8);for(;r.value<p;)for(x(u,h,n,r),u=v.c,h=v.lc;h>=c;){const i=t[u>>h-c&16383];if(i.len)h-=i.len,E(i.lit,o,u,h,n,r,s,l,d),u=w.c,h=w.lc;else{if(!i.p)throw new Error("hufDecode issues");let t;for(t=0;t<i.lit;t++){const a=b(e[i.p[t]]);for(;h<a&&r.value<p;)x(u,h,n,r),u=v.c,h=v.lc;if(h>=a&&y(e[i.p[t]])==(u>>h-a&(1<<a)-1)){h-=a,E(i.p[t],o,u,h,n,r,s,l,d),u=w.c,h=w.lc;break}}if(t==i.lit)throw new Error("hufDecode issues")}}const f=8-i&7;for(u>>=f,h-=f;h>0;){const e=t[u<<c-h&16383];if(!e.len)throw new Error("hufDecode issues");h-=e.len,E(e.lit,o,u,h,n,r,s,l,d),u=w.c,h=w.lc}}(p,f,e,n,d,l,o,i,{value:0})}function R(e){for(let t=1;t<e.length;t++){const n=e[t-1]+e[t]-128;e[t]=n}}function I(e,t){let n=0,r=Math.floor((e.length+1)/2),i=0;const o=e.length-1;for(;!(i>o||(t[i++]=e[n++],i>o));)t[i++]=e[r++]}function P(e){let t=e.byteLength;const n=new Array;let r=0;const i=new DataView(e);for(;t>0;){const e=i.getInt8(r++);if(e<0){const o=-e;t-=o+1;for(let e=0;e<o;e++)n.push(i.getUint8(r++))}else{const o=e;t-=2;const a=i.getUint8(r++);for(let e=0;e<o+1;e++)n.push(a)}}return n}function _(e,t,n){let r,i=1;for(;i<64;)r=t[e.value],65280==r?i=64:r>>8==255?i+=255&r:(n[i]=r,i++),e.value++}function N(e,t){t[0]=J(e[0]),t[1]=J(e[1]),t[2]=J(e[5]),t[3]=J(e[6]),t[4]=J(e[14]),t[5]=J(e[15]),t[6]=J(e[27]),t[7]=J(e[28]),t[8]=J(e[2]),t[9]=J(e[4]),t[10]=J(e[7]),t[11]=J(e[13]),t[12]=J(e[16]),t[13]=J(e[26]),t[14]=J(e[29]),t[15]=J(e[42]),t[16]=J(e[3]),t[17]=J(e[8]),t[18]=J(e[12]),t[19]=J(e[17]),t[20]=J(e[25]),t[21]=J(e[30]),t[22]=J(e[41]),t[23]=J(e[43]),t[24]=J(e[9]),t[25]=J(e[11]),t[26]=J(e[18]),t[27]=J(e[24]),t[28]=J(e[31]),t[29]=J(e[40]),t[30]=J(e[44]),t[31]=J(e[53]),t[32]=J(e[10]),t[33]=J(e[19]),t[34]=J(e[23]),t[35]=J(e[32]),t[36]=J(e[39]),t[37]=J(e[45]),t[38]=J(e[52]),t[39]=J(e[54]),t[40]=J(e[20]),t[41]=J(e[22]),t[42]=J(e[33]),t[43]=J(e[38]),t[44]=J(e[46]),t[45]=J(e[51]),t[46]=J(e[55]),t[47]=J(e[60]),t[48]=J(e[21]),t[49]=J(e[34]),t[50]=J(e[37]),t[51]=J(e[47]),t[52]=J(e[50]),t[53]=J(e[56]),t[54]=J(e[59]),t[55]=J(e[61]),t[56]=J(e[35]),t[57]=J(e[36]),t[58]=J(e[48]),t[59]=J(e[49]),t[60]=J(e[57]),t[61]=J(e[58]),t[62]=J(e[62]),t[63]=J(e[63])}function L(e){const t=.5*Math.cos(.7853975),n=.5*Math.cos(3.14159/16),r=.5*Math.cos(3.14159/8),i=.5*Math.cos(3*3.14159/16),o=.5*Math.cos(.981746875),a=.5*Math.cos(3*3.14159/8),s=.5*Math.cos(1.374445625),c=new Array(4),l=new Array(4),u=new Array(4),h=new Array(4);for(let d=0;d<8;++d){const p=8*d;c[0]=r*e[p+2],c[1]=a*e[p+2],c[2]=r*e[p+6],c[3]=a*e[p+6],l[0]=n*e[p+1]+i*e[p+3]+o*e[p+5]+s*e[p+7],l[1]=i*e[p+1]-s*e[p+3]-n*e[p+5]-o*e[p+7],l[2]=o*e[p+1]-n*e[p+3]+s*e[p+5]+i*e[p+7],l[3]=s*e[p+1]-o*e[p+3]+i*e[p+5]-n*e[p+7],u[0]=t*(e[p+0]+e[p+4]),u[3]=t*(e[p+0]-e[p+4]),u[1]=c[0]+c[3],u[2]=c[1]-c[2],h[0]=u[0]+u[1],h[1]=u[3]+u[2],h[2]=u[3]-u[2],h[3]=u[0]-u[1],e[p+0]=h[0]+l[0],e[p+1]=h[1]+l[1],e[p+2]=h[2]+l[2],e[p+3]=h[3]+l[3],e[p+4]=h[3]-l[3],e[p+5]=h[2]-l[2],e[p+6]=h[1]-l[1],e[p+7]=h[0]-l[0]}for(let d=0;d<8;++d)c[0]=r*e[16+d],c[1]=a*e[16+d],c[2]=r*e[48+d],c[3]=a*e[48+d],l[0]=n*e[8+d]+i*e[24+d]+o*e[40+d]+s*e[56+d],l[1]=i*e[8+d]-s*e[24+d]-n*e[40+d]-o*e[56+d],l[2]=o*e[8+d]-n*e[24+d]+s*e[40+d]+i*e[56+d],l[3]=s*e[8+d]-o*e[24+d]+i*e[40+d]-n*e[56+d],u[0]=t*(e[d]+e[32+d]),u[3]=t*(e[d]-e[32+d]),u[1]=c[0]+c[3],u[2]=c[1]-c[2],h[0]=u[0]+u[1],h[1]=u[3]+u[2],h[2]=u[3]-u[2],h[3]=u[0]-u[1],e[0+d]=h[0]+l[0],e[8+d]=h[1]+l[1],e[16+d]=h[2]+l[2],e[24+d]=h[3]+l[3],e[32+d]=h[3]-l[3],e[40+d]=h[2]-l[2],e[48+d]=h[1]-l[1],e[56+d]=h[0]-l[0]}function D(e){for(let t=0;t<64;++t){const n=e[0][t],r=e[1][t],i=e[2][t];e[0][t]=n+1.5747*i,e[1][t]=n-.1873*r-.4682*i,e[2][t]=n+1.8556*r}}function j(e,t,n){for(let r=0;r<64;++r)t[n+r]=l.toHalfFloat(F(e[r]))}function F(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(d,Math.abs(e)-1)}function U(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function B(e){const t=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),n=new Uint8Array(P(t)),r=new Uint8Array(n.length);return R(n),I(n,r),new DataView(r.buffer)}function z(e){const t=Nt(e.array.slice(e.offset.value,e.offset.value+e.size)),n=new Uint8Array(t.length);return R(t),I(t,n),new DataView(n.buffer)}function H(e){const n=e.viewer,r={value:e.offset.value},i=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),o=new Uint8Array(8192);let a=0;const s=new Array(e.channels);for(let t=0;t<e.channels;t++)s[t]={},s[t].start=a,s[t].end=s[t].start,s[t].nx=e.width,s[t].ny=e.lines,s[t].size=e.type,a+=s[t].nx*s[t].ny*s[t].size;const c=ee(n,r),l=ee(n,r);if(l>=8192)throw new Error("Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(c<=l)for(let e=0;e<l-c+1;e++)o[e+c]=K(n,r);const u=new Uint16Array(t),h=function(e,n){let r=0;for(let i=0;i<t;++i)(0==i||e[i>>3]&1<<(7&i))&&(n[r++]=i);const i=r-1;for(;r<t;)n[r++]=0;return i}(o,u),d=q(n,r);M(e.array,n,r,d,i,a);for(let t=0;t<e.channels;++t){const e=s[t];for(let n=0;n<s[t].size;++n)S(i,e.start+n,e.nx,e.size,e.ny,e.nx*e.size,h)}!function(e,t,n){for(let r=0;r<n;++r)t[r]=e[t[r]]}(u,i,a);let p=0;const f=new Uint8Array(i.buffer.byteLength);for(let t=0;t<e.lines;t++)for(let t=0;t<e.channels;t++){const e=s[t],n=e.nx*e.size,r=new Uint8Array(i.buffer,2*e.end,2*n);f.set(r,p),p+=2*n,e.end+=n}return new DataView(f.buffer)}function V(e){const t=Nt(e.array.slice(e.offset.value,e.offset.value+e.size)),n=e.lines*e.channels*e.width,r=1==e.type?new Uint16Array(n):new Uint32Array(n);let i=0,o=0;const a=new Array(4);for(let n=0;n<e.lines;n++)for(let n=0;n<e.channels;n++){let n=0;switch(e.type){case 1:a[0]=i,a[1]=a[0]+e.width,i=a[1]+e.width;for(let i=0;i<e.width;++i){n+=t[a[0]++]<<8|t[a[1]++],r[o]=n,o++}break;case 2:a[0]=i,a[1]=a[0]+e.width,a[2]=a[1]+e.width,i=a[2]+e.width;for(let i=0;i<e.width;++i){n+=t[a[0]++]<<24|t[a[1]++]<<16|t[a[2]++]<<8,r[o]=n,o++}}}return new DataView(r.buffer)}function G(e){const t=e.viewer,n={value:e.offset.value},r=new Uint8Array(e.width*e.lines*(e.channels*e.type*2)),i={version:Q(t,n),unknownUncompressedSize:Q(t,n),unknownCompressedSize:Q(t,n),acCompressedSize:Q(t,n),dcCompressedSize:Q(t,n),rleCompressedSize:Q(t,n),rleUncompressedSize:Q(t,n),rleRawSize:Q(t,n),totalAcUncompressedCount:Q(t,n),totalDcUncompressedCount:Q(t,n),acCompression:Q(t,n)};if(i.version<2)throw new Error("EXRLoader.parse: "+ae.compression+" version "+i.version+" is unsupported");const o=new Array;let a=ee(t,n)-2;for(;a>0;){const e=W(t.buffer,n),r=K(t,n),i=r>>2&3,s=new Int8Array([(r>>4)-1])[0],c=K(t,n);o.push({name:e,index:s,type:c,compression:i}),a-=e.length+3}const s=ae.channels,c=new Array(e.channels);for(let t=0;t<e.channels;++t){const n=c[t]={},r=s[t];n.name=r.name,n.compression=0,n.decoded=!1,n.type=r.pixelType,n.pLinear=r.pLinear,n.width=e.width,n.height=e.lines}const l={idx:new Array(3)};for(let t=0;t<e.channels;++t){const e=c[t];for(let n=0;n<o.length;++n){const r=o[n];e.name==r.name&&(e.compression=r.compression,r.index>=0&&(l.idx[r.index]=t),e.offset=t)}}let u,h,d;if(i.acCompressedSize>0)switch(i.acCompression){case 0:u=new Uint16Array(i.totalAcUncompressedCount),M(e.array,t,n,i.acCompressedSize,u,i.totalAcUncompressedCount);break;case 1:const r=Nt(e.array.slice(n.value,n.value+i.totalAcUncompressedCount));u=new Uint16Array(r.buffer),n.value+=i.totalAcUncompressedCount}if(i.dcCompressedSize>0){const t={array:e.array,offset:n,size:i.dcCompressedSize};h=new Uint16Array(z(t).buffer),n.value+=i.dcCompressedSize}if(i.rleRawSize>0){d=P(Nt(e.array.slice(n.value,n.value+i.rleCompressedSize)).buffer),n.value+=i.rleCompressedSize}let p=0;const f=new Array(c.length);for(let e=0;e<f.length;++e)f[e]=new Array;for(let t=0;t<e.lines;++t)for(let t=0;t<c.length;++t)f[t].push(p),p+=c[t].width*e.type*2;!function(e,t,n,r,i,o){let a=new DataView(o.buffer);const s=n[e.idx[0]].width,c=n[e.idx[0]].height,l=Math.floor(s/8),u=Math.ceil(s/8),h=Math.ceil(c/8),d=s-8*(u-1),p=c-8*(h-1),f={value:0},m=new Array(3),g=new Array(3),b=new Array(3),y=new Array(3),v=new Array(3);for(let n=0;n<3;++n)v[n]=t[e.idx[n]],m[n]=n<1?0:m[n-1]+u*h,g[n]=new Float32Array(64),b[n]=new Uint16Array(64),y[n]=new Uint16Array(64*u);for(let t=0;t<h;++t){let o=8;t==h-1&&(o=p);let s=8;for(let e=0;e<u;++e){e==u-1&&(s=d);for(let e=0;e<3;++e)b[e].fill(0),b[e][0]=i[m[e]++],_(f,r,b[e]),N(b[e],g[e]),L(g[e]);D(g);for(let t=0;t<3;++t)j(g[t],y[t],64*e)}let c=0;for(let r=0;r<3;++r){const i=n[e.idx[r]].type;for(let e=8*t;e<8*t+o;++e){c=v[r][e];for(let t=0;t<l;++t){const n=64*t+8*(7&e);a.setUint16(c+0*i,y[r][n+0],!0),a.setUint16(c+2*i,y[r][n+1],!0),a.setUint16(c+4*i,y[r][n+2],!0),a.setUint16(c+6*i,y[r][n+3],!0),a.setUint16(c+8*i,y[r][n+4],!0),a.setUint16(c+10*i,y[r][n+5],!0),a.setUint16(c+12*i,y[r][n+6],!0),a.setUint16(c+14*i,y[r][n+7],!0),c+=16*i}}if(l!=u)for(let e=8*t;e<8*t+o;++e){const t=v[r][e]+8*l*2*i,n=64*l+8*(7&e);for(let e=0;e<s;++e)a.setUint16(t+2*e*i,y[r][n+e],!0)}}}const x=new Uint16Array(s);a=new DataView(o.buffer);for(let t=0;t<3;++t){n[e.idx[t]].decoded=!0;const r=n[e.idx[t]].type;if(2==n[t].type)for(let e=0;e<c;++e){const n=v[t][e];for(let e=0;e<s;++e)x[e]=a.getUint16(n+2*e*r,!0);for(let e=0;e<s;++e)a.setFloat32(n+2*e*r,J(x[e]),!0)}}}(l,f,c,u,h,r);for(let t=0;t<c.length;++t){const n=c[t];if(!n.decoded){if(2!==n.compression)throw new Error("EXRLoader.parse: unsupported channel compression");{let i=0,o=0;for(let a=0;a<e.lines;++a){let e=f[t][i];for(let t=0;t<n.width;++t){for(let t=0;t<2*n.type;++t)r[e++]=d[o+t*n.width*n.height];o++}i++}}}}return new DataView(r.buffer)}function W(e,t){const n=new Uint8Array(e);let r=0;for(;0!=n[t.value+r];)r+=1;const i=(new TextDecoder).decode(n.slice(t.value,t.value+r));return t.value=t.value+r+1,i}function X(e,t){const n=e.getInt32(t.value,!0);return t.value=t.value+4,n}function q(e,t){const n=e.getUint32(t.value,!0);return t.value=t.value+4,n}function Y(e,t){const n=e[t.value];return t.value=t.value+1,n}function K(e,t){const n=e.getUint8(t.value);return t.value=t.value+1,n}const Q=function(e,t){let n;return n="getBigInt64"in DataView.prototype?Number(e.getBigInt64(t.value,!0)):e.getUint32(t.value+4,!0)+Number(e.getUint32(t.value,!0)<<32),t.value+=8,n};function $(e,t){const n=e.getFloat32(t.value,!0);return t.value+=4,n}function Z(e,t){return l.toHalfFloat($(e,t))}function J(e){const t=(31744&e)>>10,n=1023&e;return(e>>15?-1:1)*(t?31===t?n?NaN:1/0:Math.pow(2,t-15)*(1+n/1024):n/1024*6103515625e-14)}function ee(e,t){const n=e.getUint16(t.value,!0);return t.value+=2,n}function te(e,t){return J(ee(e,t))}function ne(e,t,n,r,i){return"string"===r||"stringvector"===r||"iccProfile"===r?function(e,t,n){const r=(new TextDecoder).decode(new Uint8Array(e).slice(t.value,t.value+n));return t.value=t.value+n,r}(t,n,i):"chlist"===r?function(e,t,n,r){const i=n.value,o=[];for(;n.value<i+r-1;){const r=W(t,n),i=X(e,n),a=K(e,n);n.value+=3;const s=X(e,n),c=X(e,n);o.push({name:r,pixelType:i,pLinear:a,xSampling:s,ySampling:c})}return n.value+=1,o}(e,t,n,i):"chromaticities"===r?function(e,t){return{redX:$(e,t),redY:$(e,t),greenX:$(e,t),greenY:$(e,t),blueX:$(e,t),blueY:$(e,t),whiteX:$(e,t),whiteY:$(e,t)}}(e,n):"compression"===r?function(e,t){return["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"][K(e,t)]}(e,n):"box2i"===r?function(e,t){return{xMin:q(e,t),yMin:q(e,t),xMax:q(e,t),yMax:q(e,t)}}(e,n):"lineOrder"===r?function(e,t){return["INCREASING_Y"][K(e,t)]}(e,n):"float"===r?$(e,n):"v2f"===r?function(e,t){return[$(e,t),$(e,t)]}(e,n):"v3f"===r?function(e,t){return[$(e,t),$(e,t),$(e,t)]}(e,n):"int"===r?X(e,n):"rational"===r?function(e,t){return[X(e,t),q(e,t)]}(e,n):"timecode"===r?function(e,t){return[q(e,t),q(e,t)]}(e,n):"preview"===r?(n.value+=i,"skipped"):void(n.value+=i)}const re=new DataView(e),ie=new Uint8Array(e),oe={value:0},ae=function(e,t,n){const r={};if(20000630!=e.getUint32(0,!0))throw new Error("THREE.EXRLoader: Provided file doesn't appear to be in OpenEXR format.");r.version=e.getUint8(4);const i=e.getUint8(5);r.spec={singleTile:!!(2&i),longName:!!(4&i),deepFormat:!!(8&i),multiPart:!!(16&i)},n.value=8;let o=!0;for(;o;){const i=W(t,n);if(0==i)o=!1;else{const o=W(t,n),a=ne(e,t,n,o,q(e,n));void 0===a?console.warn(`THREE.EXRLoader: Skipped unknown header attribute type '${o}'.`):r[i]=a}}if(-5&i)throw console.error("THREE.EXRHeader:",r),new Error("THREE.EXRLoader: Provided file is currently unsupported.");return r}(re,e,oe),se=function(e,t,c,l,u){const h={size:0,viewer:t,array:c,offset:l,width:e.dataWindow.xMax-e.dataWindow.xMin+1,height:e.dataWindow.yMax-e.dataWindow.yMin+1,channels:e.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:e.channels[0].pixelType,uncompress:null,getter:null,format:null,colorSpace:o};switch(e.compression){case"NO_COMPRESSION":h.lines=1,h.uncompress=U;break;case"RLE_COMPRESSION":h.lines=1,h.uncompress=B;break;case"ZIPS_COMPRESSION":h.lines=1,h.uncompress=z;break;case"ZIP_COMPRESSION":h.lines=16,h.uncompress=z;break;case"PIZ_COMPRESSION":h.lines=32,h.uncompress=H;break;case"PXR24_COMPRESSION":h.lines=16,h.uncompress=V;break;case"DWAA_COMPRESSION":h.lines=32,h.uncompress=G;break;case"DWAB_COMPRESSION":h.lines=256,h.uncompress=G;break;default:throw new Error("EXRLoader.parse: "+e.compression+" is unsupported")}if(h.scanlineBlockSize=h.lines,1==h.type)switch(u){case r:h.getter=te,h.inputSize=2;break;case n:h.getter=ee,h.inputSize=2}else{if(2!=h.type)throw new Error("EXRLoader.parse: unsupported pixelType "+h.type+" for "+e.compression+".");switch(u){case r:h.getter=$,h.inputSize=4;break;case n:h.getter=Z,h.inputSize=4}}h.blockCount=(e.dataWindow.yMax+1)/h.scanlineBlockSize;for(let e=0;e<h.blockCount;e++)Q(t,l);h.outputChannels=3==h.channels?4:h.channels;const d=h.width*h.height*h.outputChannels;switch(u){case r:h.byteArray=new Float32Array(d),h.channels<h.outputChannels&&h.byteArray.fill(1,0,d);break;case n:h.byteArray=new Uint16Array(d),h.channels<h.outputChannels&&h.byteArray.fill(15360,0,d);break;default:console.error("THREE.EXRLoader: unsupported type: ",u)}return h.bytesPerLine=h.width*h.inputSize*h.channels,4==h.outputChannels?(h.format=i,h.colorSpace=o):(h.format=a,h.colorSpace=s),h}(ae,re,ie,oe,this.type),ce={value:0},le={R:0,G:1,B:2,A:3,Y:0};for(let e=0;e<se.height/se.scanlineBlockSize;e++){const t=q(re,oe);se.size=q(re,oe),se.lines=t+se.scanlineBlockSize>se.height?se.height-t:se.scanlineBlockSize;const n=se.size<se.lines*se.bytesPerLine?se.uncompress(se):U(se);oe.value+=se.size;for(let t=0;t<se.scanlineBlockSize;t++){const r=t+e*se.scanlineBlockSize;if(r>=se.height)break;for(let e=0;e<se.channels;e++){const i=le[ae.channels[e].name];for(let o=0;o<se.width;o++){ce.value=(t*(se.channels*se.width)+e*se.width+o)*se.inputSize;const a=(se.height-1-r)*(se.width*se.outputChannels)+o*se.outputChannels+i;se.byteArray[a]=se.getter(n,ce)}}}}return{header:ae,width:se.width,height:se.height,data:se.byteArray,format:se.format,colorSpace:se.colorSpace,type:this.type}}setDataType(e){return this.type=e,this}load(e,t,n,r){return super.load(e,function(e,n){e.colorSpace=n.colorSpace,e.minFilter=c,e.magFilter=c,e.generateMipmaps=!1,e.flipY=!1,t&&t(e,n)},n,r)}};const jt={type:"change"},Ft={type:"start"},Ut={type:"end"},Bt=new u,zt=new h,Ht=Math.cos(70*d.DEG2RAD);class Vt extends p{constructor(e,t){super(),this.object=e,this.domElement=t,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new f,this.cursor=new f,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=4,this.ctrlZoomSpeed=.05,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:-1,MIDDLE:m.ROTATE,RIGHT:m.PAN},this.touches={ONE:g.ROTATE,TWO:g.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.VIEW_TYPES={FRONT:"front",BACK:"back",LEFT:"left",RIGHT:"right",TOP:"top",BOTTOM:"bottom",ISOMETRIC:"isometric",FREE:"free"},this.viewDragStart=null,this.viewChangeRequested=!1,this.viewsInitialized=!1,this.horizontalViews=[],this.verticalViews=[],this.horizontalViewIndex=0,this.verticalViewIndex=0,this.originalCameraPosition=null,this.originalTarget=null,this.getPolarAngle=function(){return a.phi},this.getAzimuthalAngle=function(){return a.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(e){e.addEventListener("keydown",ne),this._domElementKeyEvents=e},this.stopListenToKeyEvents=function(){this._domElementKeyEvents.removeEventListener("keydown",ne),this._domElementKeyEvents=null},this.saveState=function(){n.target0.copy(n.target),n.position0.copy(n.object.position),n.zoom0=n.object.zoom},this.reset=function(){n.target.copy(n.target0),n.object.position.copy(n.position0),n.object.zoom=n.zoom0,n.object.updateProjectionMatrix(),n.dispatchEvent(jt),n.update(),i=r.NONE},this.setView=function(e){this.originalCameraPosition||(this.originalCameraPosition=this.object.position.clone(),this.originalTarget=this.target.clone());const t=this.target.clone(),n=this.getDistance();switch(e){case this.VIEW_TYPES.FRONT:this.object.position.set(t.x,t.y-n,t.z);break;case this.VIEW_TYPES.BACK:this.object.position.set(t.x,t.y+n,t.z);break;case this.VIEW_TYPES.RIGHT:this.object.position.set(t.x+n,t.y,t.z);break;case this.VIEW_TYPES.LEFT:this.object.position.set(t.x-n,t.y,t.z);break;case this.VIEW_TYPES.TOP:this.object.position.set(t.x,t.y,t.z+n);break;case this.VIEW_TYPES.BOTTOM:this.object.position.set(t.x,t.y,t.z-n);break;case this.VIEW_TYPES.ISOMETRIC:const e=n/Math.sqrt(3);this.object.position.set(t.x+e,t.y-e,t.z+e);break;case this.VIEW_TYPES.FREE:default:return void this.resetView()}this.object.lookAt(this.target),this.update(),this.dispatchEvent(jt)},this.resetView=function(){this.originalCameraPosition&&this.originalTarget&&(this.object.position.copy(this.originalCameraPosition),this.target.copy(this.originalTarget),this.object.lookAt(this.target),this.update(),this.dispatchEvent(jt))},this.update=function(){const t=new f,u=(new y).setFromUnitVectors(e.up,new f(0,1,0)),h=u.clone().invert(),d=new f,p=new y,m=new f,g=2*Math.PI;return function(b=null){const y=n.object.position;t.copy(y).sub(n.target),t.applyQuaternion(u),a.setFromVector3(t),n.autoRotate&&i===r.NONE&&P(function(e){return null!==e?2*Math.PI/60*n.autoRotateSpeed*e:2*Math.PI/60/60*n.autoRotateSpeed}(b)),n.enableDamping?(a.theta+=s.theta*n.dampingFactor,a.phi+=s.phi*n.dampingFactor):(a.theta+=s.theta,a.phi+=s.phi);let v=n.minAzimuthAngle,x=n.maxAzimuthAngle;isFinite(v)&&isFinite(x)&&(v<-Math.PI?v+=g:v>Math.PI&&(v-=g),x<-Math.PI?x+=g:x>Math.PI&&(x-=g),a.theta=v<=x?Math.max(v,Math.min(x,a.theta)):a.theta>(v+x)/2?Math.max(v,a.theta):Math.min(x,a.theta)),a.phi=Math.max(n.minPolarAngle,Math.min(n.maxPolarAngle,a.phi)),a.makeSafe(),!0===n.enableDamping?n.target.addScaledVector(l,n.dampingFactor):n.target.add(l),n.target.sub(n.cursor),n.target.clampLength(n.minTargetRadius,n.maxTargetRadius),n.target.add(n.cursor);let w=!1;if(n.zoomToCursor&&k||n.object.isOrthographicCamera)a.radius=B(a.radius);else{const e=a.radius;a.radius=B(a.radius*c),w=e!=a.radius}if(t.setFromSpherical(a),t.applyQuaternion(h),y.copy(n.target).add(t),n.object.lookAt(n.target),!0===n.enableDamping?(s.theta*=1-n.dampingFactor,s.phi*=1-n.dampingFactor,l.multiplyScalar(1-n.dampingFactor)):(s.set(0,0,0),l.set(0,0,0)),n.zoomToCursor&&k){let r=null;if(n.object.isPerspectiveCamera){const e=t.length();r=B(e*c);const i=e-r;n.object.position.addScaledVector(C,i),n.object.updateMatrixWorld(),w=!!i}else if(n.object.isOrthographicCamera){const e=new f(O.x,O.y,0);e.unproject(n.object);const i=n.object.zoom;n.object.zoom=Math.max(n.minZoom,Math.min(n.maxZoom,n.object.zoom/c)),n.object.updateProjectionMatrix(),w=i!==n.object.zoom;const o=new f(O.x,O.y,0);o.unproject(n.object),n.object.position.sub(o).add(e),n.object.updateMatrixWorld(),r=t.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),n.zoomToCursor=!1;null!==r&&(this.screenSpacePanning?n.target.set(0,0,-1).transformDirection(n.object.matrix).multiplyScalar(r).add(n.object.position):(Bt.origin.copy(n.object.position),Bt.direction.set(0,0,-1).transformDirection(n.object.matrix),Math.abs(n.object.up.dot(Bt.direction))<Ht?e.lookAt(n.target):(zt.setFromNormalAndCoplanarPoint(n.object.up,n.target),Bt.intersectPlane(zt,n.target))))}else if(n.object.isOrthographicCamera){const e=n.object.zoom;n.object.zoom=Math.max(n.minZoom,Math.min(n.maxZoom,n.object.zoom/c)),e!==n.object.zoom&&(n.object.updateProjectionMatrix(),w=!0)}return c=1,k=!1,!!(w||d.distanceToSquared(n.object.position)>o||8*(1-p.dot(n.object.quaternion))>o||m.distanceToSquared(n.target)>o)&&(n.dispatchEvent(jt),d.copy(n.object.position),p.copy(n.object.quaternion),m.copy(n.target),!0)}}(),this.dispose=function(){n.domElement.removeEventListener("contextmenu",ie),n.domElement.removeEventListener("pointerdown",Q),n.domElement.removeEventListener("pointercancel",Z),n.domElement.removeEventListener("wheel",J),n.domElement.removeEventListener("pointermove",$),n.domElement.removeEventListener("pointerup",Z);n.domElement.getRootNode().removeEventListener("keydown",ee,{capture:!0}),null!==n._domElementKeyEvents&&(n._domElementKeyEvents.removeEventListener("keydown",ne),n._domElementKeyEvents=null)};const n=this,r={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let i=r.NONE;const o=1e-6,a=new b,s=new b;let c=1;const l=new f,u=new v,h=new v,d=new v,p=new v,x=new v,w=new v,E=new v,T=new v,A=new v,C=new f,O=new v;let k=!1;const S=[],M={};let R=!1;function I(e){const t=Math.abs(.01*e);return Math.pow(.95,n.zoomSpeed*t)}function P(e){s.theta-=e}function _(e){s.phi-=e}const N=function(){const e=new f;return function(t,n){e.setFromMatrixColumn(n,0),e.multiplyScalar(-t),l.add(e)}}(),L=function(){const e=new f;return function(t,r){!0===n.screenSpacePanning?e.setFromMatrixColumn(r,1):(e.setFromMatrixColumn(r,0),e.crossVectors(n.object.up,e)),e.multiplyScalar(t),l.add(e)}}(),D=function(){const e=new f;return function(t,r){const i=n.domElement;if(n.object.isPerspectiveCamera){const o=n.object.position;e.copy(o).sub(n.target);let a=e.length();a*=Math.tan(n.object.fov/2*Math.PI/180),N(2*t*a/i.clientHeight,n.object.matrix),L(2*r*a/i.clientHeight,n.object.matrix)}else n.object.isOrthographicCamera?(N(t*(n.object.right-n.object.left)/n.object.zoom/i.clientWidth,n.object.matrix),L(r*(n.object.top-n.object.bottom)/n.object.zoom/i.clientHeight,n.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),n.enablePan=!1)}}();function j(e){n.object.isPerspectiveCamera||n.object.isOrthographicCamera?c/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),n.enableZoom=!1)}function F(e){n.object.isPerspectiveCamera||n.object.isOrthographicCamera?c*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),n.enableZoom=!1)}function U(e,t){if(!n.zoomToCursor)return;k=!0;const r=n.domElement.getBoundingClientRect(),i=e-r.left,o=t-r.top,a=r.width,s=r.height;O.x=i/a*2-1,O.y=-o/s*2+1,C.set(O.x,O.y,1).unproject(n.object).sub(n.object.position).normalize()}function B(e){return Math.max(n.minDistance,Math.min(n.maxDistance,e))}function z(e){n.viewsInitialized||(n.horizontalViews=[n.VIEW_TYPES.LEFT,n.VIEW_TYPES.FRONT,n.VIEW_TYPES.RIGHT,n.VIEW_TYPES.BACK],n.verticalViews=[n.VIEW_TYPES.TOP,n.VIEW_TYPES.ISOMETRIC,n.VIEW_TYPES.BOTTOM,n.VIEW_TYPES.FREE],n.horizontalViewIndex=0,n.verticalViewIndex=0,n.viewsInitialized=!0),n.viewDragStart=new v(e.clientX,e.clientY),n.viewChangeRequested=!0,e.preventDefault(),e.stopPropagation()}function H(e){u.set(e.clientX,e.clientY)}function V(e){p.set(e.clientX,e.clientY)}function G(e){if(1===S.length)u.set(e.pageX,e.pageY);else{const t=ae(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);u.set(n,r)}}function W(e){if(1===S.length)p.set(e.pageX,e.pageY);else{const t=ae(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);p.set(n,r)}}function X(e){const t=ae(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);E.set(0,i)}function q(e){if(1==S.length)h.set(e.pageX,e.pageY);else{const t=ae(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);h.set(n,r)}d.subVectors(h,u).multiplyScalar(n.rotateSpeed);const t=n.domElement;P(2*Math.PI*d.x/t.clientHeight),_(2*Math.PI*d.y/t.clientHeight),u.copy(h)}function Y(e){if(1===S.length)x.set(e.pageX,e.pageY);else{const t=ae(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);x.set(n,r)}w.subVectors(x,p).multiplyScalar(n.panSpeed),D(w.x,w.y),p.copy(x)}function K(e){const t=ae(e),r=e.pageX-t.x,i=e.pageY-t.y,o=Math.sqrt(r*r+i*i);T.set(0,o),A.set(0,Math.pow(T.y/E.y,n.zoomSpeed)),j(A.y),E.copy(T);U(.5*(e.pageX+t.x),.5*(e.pageY+t.y))}function Q(e){!1!==n.enabled&&(0===S.length&&(n.domElement.setPointerCapture(e.pointerId),n.domElement.addEventListener("pointermove",$),n.domElement.addEventListener("pointerup",Z)),e.altKey&&1===e.button?z(e):function(e){for(let t=0;t<S.length;t++)if(S[t]==e.pointerId)return!0;return!1}(e)||(function(e){S.push(e.pointerId)}(e),"touch"===e.pointerType?re(e):function(e){let t;switch(e.button){case 0:t=n.mouseButtons.LEFT;break;case 1:t=e.altKey?-1:e.ctrlKey||e.metaKey?m.DOLLY:n.mouseButtons.MIDDLE;break;case 2:t=n.mouseButtons.RIGHT;break;default:t=-1}switch(t){case m.DOLLY:if(!1===n.enableZoom)return;!function(e){U(e.clientX,e.clientX),E.set(e.clientX,e.clientY)}(e),i=r.DOLLY;break;case m.ROTATE:if(e.ctrlKey||e.metaKey||e.shiftKey){if(!1===n.enablePan)return;V(e),i=r.PAN}else{if(!1===n.enableRotate)return;H(e),i=r.ROTATE}break;case m.PAN:if(e.ctrlKey||e.metaKey||e.shiftKey){if(!1===n.enableRotate)return;H(e),i=r.ROTATE}else{if(!1===n.enablePan)return;V(e),i=r.PAN}break;default:i=r.NONE}i!==r.NONE&&n.dispatchEvent(Ft)}(e)))}function $(e){!1!==n.enabled&&(e.altKey&&n.viewChangeRequested&&n.viewDragStart?function(e){const t=new v(e.clientX,e.clientY),r=(new v).subVectors(t,n.viewDragStart),i=Math.abs(r.x),o=Math.abs(r.y);if(Math.max(i,o)>30){if(i>o){const e=r.x>0?1:-1;n.horizontalViewIndex=(n.horizontalViewIndex+e+n.horizontalViews.length)%n.horizontalViews.length,n.setView(n.horizontalViews[n.horizontalViewIndex])}else{const e=r.y>0?1:-1;n.verticalViewIndex=(n.verticalViewIndex+e+n.verticalViews.length)%n.verticalViews.length,n.setView(n.verticalViews[n.verticalViewIndex])}n.viewChangeRequested=!1,n.viewDragStart=null}e.altKey&&4===e.buttons&&(e.preventDefault(),e.stopPropagation())}(e):"touch"===e.pointerType?function(e){switch(oe(e),i){case r.TOUCH_ROTATE:if(!1===n.enableRotate)return;q(e),n.update();break;case r.TOUCH_PAN:if(!1===n.enablePan)return;Y(e),n.update();break;case r.TOUCH_DOLLY_PAN:if(!1===n.enableZoom&&!1===n.enablePan)return;!function(e){n.enableZoom&&K(e),n.enablePan&&Y(e)}(e),n.update();break;case r.TOUCH_DOLLY_ROTATE:if(!1===n.enableZoom&&!1===n.enableRotate)return;!function(e){n.enableZoom&&K(e),n.enableRotate&&q(e)}(e),n.update();break;default:i=r.NONE}}(e):function(e){switch(i){case r.ROTATE:if(!1===n.enableRotate)return;!function(e){h.set(e.clientX,e.clientY),d.subVectors(h,u).multiplyScalar(n.rotateSpeed);const t=n.domElement;P(2*Math.PI*d.x/t.clientHeight),_(2*Math.PI*d.y/t.clientHeight),u.copy(h),n.update()}(e);break;case r.DOLLY:if(!1===n.enableZoom)return;!function(e){T.set(e.clientX,e.clientY),A.subVectors(T,E),A.y>0?j(I(A.y)-n.ctrlZoomSpeed):A.y<0&&F(I(A.y)-n.ctrlZoomSpeed),E.copy(T),n.update()}(e);break;case r.PAN:if(!1===n.enablePan)return;!function(e){x.set(e.clientX,e.clientY),w.subVectors(x,p).multiplyScalar(n.panSpeed),D(w.x,w.y),p.copy(x),n.update()}(e)}}(e))}function Z(e){switch(n.viewChangeRequested&&(n.viewChangeRequested=!1,n.viewDragStart=null),function(e){delete M[e.pointerId];for(let t=0;t<S.length;t++)if(S[t]==e.pointerId)return void S.splice(t,1)}(e),S.length){case 0:n.domElement.releasePointerCapture(e.pointerId),n.domElement.removeEventListener("pointermove",$),n.domElement.removeEventListener("pointerup",Z),n.dispatchEvent(Ut),i=r.NONE;break;case 1:const t=S[0],o=M[t];re({pointerId:t,pageX:o.x,pageY:o.y})}}function J(e){!1!==n.enabled&&!1!==n.enableZoom&&i===r.NONE&&(e.preventDefault(),n.dispatchEvent(Ft),function(e){U(e.clientX,e.clientY),e.deltaY<0?F(I(e.deltaY)):e.deltaY>0&&j(I(e.deltaY)),n.update()}(function(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100}e.ctrlKey&&!R&&(n.deltaY*=10);return n}(e)),n.dispatchEvent(Ut))}function ee(e){if("Control"===e.key){R=!0;n.domElement.getRootNode().addEventListener("keyup",te,{passive:!0,capture:!0})}}function te(e){if("Control"===e.key){R=!1;n.domElement.getRootNode().removeEventListener("keyup",te,{passive:!0,capture:!0})}}function ne(e){!1!==n.enabled&&!1!==n.enablePan&&function(e){let t=!1;switch(e.code){case n.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?_(2*Math.PI*n.rotateSpeed/n.domElement.clientHeight):D(0,n.keyPanSpeed),t=!0;break;case n.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?_(-2*Math.PI*n.rotateSpeed/n.domElement.clientHeight):D(0,-n.keyPanSpeed),t=!0;break;case n.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?P(2*Math.PI*n.rotateSpeed/n.domElement.clientHeight):D(n.keyPanSpeed,0),t=!0;break;case n.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?P(-2*Math.PI*n.rotateSpeed/n.domElement.clientHeight):D(-n.keyPanSpeed,0),t=!0}t&&(e.preventDefault(),n.update())}(e)}function re(e){switch(oe(e),S.length){case 1:switch(n.touches.ONE){case g.ROTATE:if(!1===n.enableRotate)return;G(e),i=r.TOUCH_ROTATE;break;case g.PAN:if(!1===n.enablePan)return;W(e),i=r.TOUCH_PAN;break;default:i=r.NONE}break;case 2:switch(n.touches.TWO){case g.DOLLY_PAN:if(!1===n.enableZoom&&!1===n.enablePan)return;!function(e){n.enableZoom&&X(e),n.enablePan&&W(e)}(e),i=r.TOUCH_DOLLY_PAN;break;case g.DOLLY_ROTATE:if(!1===n.enableZoom&&!1===n.enableRotate)return;!function(e){n.enableZoom&&X(e),n.enableRotate&&G(e)}(e),i=r.TOUCH_DOLLY_ROTATE;break;default:i=r.NONE}break;default:i=r.NONE}i!==r.NONE&&n.dispatchEvent(Ft)}function ie(e){!1!==n.enabled&&e.preventDefault()}function oe(e){let t=M[e.pointerId];void 0===t&&(t=new v,M[e.pointerId]=t),t.set(e.pageX,e.pageY)}function ae(e){const t=e.pointerId===S[0]?S[1]:S[0];return M[t]}n.domElement.addEventListener("contextmenu",ie),n.domElement.addEventListener("pointerdown",Q),n.domElement.addEventListener("pointercancel",Z),n.domElement.addEventListener("wheel",J,{passive:!1});n.domElement.getRootNode().addEventListener("keydown",ee,{passive:!0,capture:!0}),this.update()}}const Gt=new w,Wt=new f,Xt=new f,qt=new y,Yt={X:new f(1,0,0),Y:new f(0,1,0),Z:new f(0,0,1)},Kt={type:"change"},Qt={type:"mouseDown"},$t={type:"mouseUp",mode:null},Zt={type:"objectChange"};class Jt extends x{constructor(e,t){super(),void 0===t&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),t=document),this.isTransformControls=!0,this.visible=!1,this.domElement=t,this.domElement.style.touchAction="none";const n=new wn;this._gizmo=n,this.add(n);const r=new En;this._plane=r,this.add(r);const i=this;function o(e,t){let o=t;Object.defineProperty(i,e,{get:function(){return void 0!==o?o:t},set:function(t){o!==t&&(o=t,r[e]=t,n[e]=t,i.dispatchEvent({type:e+"-changed",value:t}),i.dispatchEvent(Kt))}}),i[e]=t,r[e]=t,n[e]=t}o("camera",e),o("object",void 0),o("enabled",!0),o("axis",null),o("mode","translate"),o("translationSnap",null),o("rotationSnap",null),o("scaleSnap",null),o("space","world"),o("size",1),o("dragging",!1),o("showX",!0),o("showY",!0),o("showZ",!0);const a=new f,s=new f,c=new y,l=new y,u=new f,h=new y,d=new f,p=new f,m=new f,g=new f;o("worldPosition",a),o("worldPositionStart",s),o("worldQuaternion",c),o("worldQuaternionStart",l),o("cameraPosition",u),o("cameraQuaternion",h),o("pointStart",d),o("pointEnd",p),o("rotationAxis",m),o("rotationAngle",0),o("eye",g),this._offset=new f,this._startNorm=new f,this._endNorm=new f,this._cameraScale=new f,this._parentPosition=new f,this._parentQuaternion=new y,this._parentQuaternionInv=new y,this._parentScale=new f,this._worldScaleStart=new f,this._worldQuaternionInv=new y,this._worldScale=new f,this._positionStart=new f,this._quaternionStart=new y,this._scaleStart=new f,this._getPointer=en.bind(this),this._onPointerDown=nn.bind(this),this._onPointerHover=tn.bind(this),this._onPointerMove=rn.bind(this),this._onPointerUp=on.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){void 0!==this.object&&(this.object.updateMatrixWorld(),null===this.object.parent?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(e){if(void 0===this.object||!0===this.dragging)return;null!==e&&Gt.setFromCamera(e,this.camera);const t=an(this._gizmo.picker[this.mode],Gt);this.axis=t?t.object.name:null}pointerDown(e){if(void 0!==this.object&&!0!==this.dragging&&(null==e||0===e.button)&&null!==this.axis){null!==e&&Gt.setFromCamera(e,this.camera);const t=an(this._plane,Gt,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,Qt.mode=this.mode,this.dispatchEvent(Qt)}}pointerMove(e){const t=this.axis,n=this.mode,r=this.object;let i=this.space;if("scale"===n?i="local":"E"!==t&&"XYZE"!==t&&"XYZ"!==t||(i="world"),void 0===r||null===t||!1===this.dragging||null!==e&&-1!==e.button)return;null!==e&&Gt.setFromCamera(e,this.camera);const o=an(this._plane,Gt,!0);if(o){if(this.pointEnd.copy(o.point).sub(this.worldPositionStart),"translate"===n)this._offset.copy(this.pointEnd).sub(this.pointStart),"local"===i&&"XYZ"!==t&&this._offset.applyQuaternion(this._worldQuaternionInv),-1===t.indexOf("X")&&(this._offset.x=0),-1===t.indexOf("Y")&&(this._offset.y=0),-1===t.indexOf("Z")&&(this._offset.z=0),"local"===i&&"XYZ"!==t?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),r.position.copy(this._offset).add(this._positionStart),this.translationSnap&&("local"===i&&(r.position.applyQuaternion(qt.copy(this._quaternionStart).invert()),-1!==t.search("X")&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),-1!==t.search("Y")&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),-1!==t.search("Z")&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.position.applyQuaternion(this._quaternionStart)),"world"===i&&(r.parent&&r.position.add(Wt.setFromMatrixPosition(r.parent.matrixWorld)),-1!==t.search("X")&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),-1!==t.search("Y")&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),-1!==t.search("Z")&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.parent&&r.position.sub(Wt.setFromMatrixPosition(r.parent.matrixWorld))));else if("scale"===n){if(-1!==t.search("XYZ")){let e=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(e*=-1),Xt.set(e,e,e)}else Wt.copy(this.pointStart),Xt.copy(this.pointEnd),Wt.applyQuaternion(this._worldQuaternionInv),Xt.applyQuaternion(this._worldQuaternionInv),Xt.divide(Wt),-1===t.search("X")&&(Xt.x=1),-1===t.search("Y")&&(Xt.y=1),-1===t.search("Z")&&(Xt.z=1);r.scale.copy(this._scaleStart).multiply(Xt),this.scaleSnap&&(-1!==t.search("X")&&(r.scale.x=Math.round(r.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==t.search("Y")&&(r.scale.y=Math.round(r.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==t.search("Z")&&(r.scale.z=Math.round(r.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if("rotate"===n){this._offset.copy(this.pointEnd).sub(this.pointStart);const e=20/this.worldPosition.distanceTo(Wt.setFromMatrixPosition(this.camera.matrixWorld));let n=!1;"XYZE"===t?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(Wt.copy(this.rotationAxis).cross(this.eye))*e):"X"!==t&&"Y"!==t&&"Z"!==t||(this.rotationAxis.copy(Yt[t]),Wt.copy(Yt[t]),"local"===i&&Wt.applyQuaternion(this.worldQuaternion),Wt.cross(this.eye),0===Wt.length()?n=!0:this.rotationAngle=this._offset.dot(Wt.normalize())*e),("E"===t||n)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),"local"===i&&"E"!==t&&"XYZE"!==t?(r.quaternion.copy(this._quaternionStart),r.quaternion.multiply(qt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),r.quaternion.copy(qt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),r.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(Kt),this.dispatchEvent(Zt)}}pointerUp(e){null!==e&&0!==e.button||(this.dragging&&null!==this.axis&&($t.mode=this.mode,this.dispatchEvent($t)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}attach(e){return this.object=e,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(Kt),this.dispatchEvent(Zt),this.pointStart.copy(this.pointEnd))}getRaycaster(){return Gt}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}}function en(e){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:e.button};{const t=this.domElement.getBoundingClientRect();return{x:(e.clientX-t.left)/t.width*2-1,y:-(e.clientY-t.top)/t.height*2+1,button:e.button}}}function tn(e){if(this.enabled)switch(e.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(e))}}function nn(e){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(e.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(e)),this.pointerDown(this._getPointer(e)))}function rn(e){this.enabled&&this.pointerMove(this._getPointer(e))}function on(e){this.enabled&&(this.domElement.releasePointerCapture(e.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(e)))}function an(e,t,n){const r=t.intersectObject(e,!0);for(let e=0;e<r.length;e++)if(r[e].object.visible||n)return r[e];return!1}const sn=new _,cn=new f(0,1,0),ln=new f(0,0,0),un=new N,hn=new y,dn=new y,pn=new f,fn=new N,mn=new f(1,0,0),gn=new f(0,1,0),bn=new f(0,0,1),yn=new f,vn=new f,xn=new f;class wn extends x{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const e=new E({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new T({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),n=e.clone();n.opacity=.15;const r=t.clone();r.opacity=.5;const i=e.clone();i.color.setHex(16711680);const o=e.clone();o.color.setHex(65280);const a=e.clone();a.color.setHex(255);const s=e.clone();s.color.setHex(16711680),s.opacity=.5;const c=e.clone();c.color.setHex(65280),c.opacity=.5;const l=e.clone();l.color.setHex(255),l.opacity=.5;const u=e.clone();u.opacity=.25;const h=e.clone();h.color.setHex(16776960),h.opacity=.25;e.clone().color.setHex(16776960);const d=e.clone();d.color.setHex(7895160);const p=new A(0,.04,.1,12);p.translate(0,.05,0);const f=new C(.08,.08,.08);f.translate(0,.04,0);const m=new O;m.setAttribute("position",new k([0,0,0,1,0,0],3));const g=new A(.0075,.0075,.5,3);function b(e,t){const n=new I(e,.0075,3,64,t*Math.PI*2);return n.rotateY(Math.PI/2),n.rotateX(Math.PI/2),n}g.translate(0,.25,0);const y={X:[[new S(p,i),[.5,0,0],[0,0,-Math.PI/2]],[new S(p,i),[-.5,0,0],[0,0,Math.PI/2]],[new S(g,i),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new S(p,o),[0,.5,0]],[new S(p,o),[0,-.5,0],[Math.PI,0,0]],[new S(g,o)]],Z:[[new S(p,a),[0,0,.5],[Math.PI/2,0,0]],[new S(p,a),[0,0,-.5],[-Math.PI/2,0,0]],[new S(g,a),null,[Math.PI/2,0,0]]],XYZ:[[new S(new M(.1,0),u.clone()),[0,0,0]]],XY:[[new S(new C(.15,.15,.01),l.clone()),[.15,.15,0]]],YZ:[[new S(new C(.15,.15,.01),s.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new S(new C(.15,.15,.01),c.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},v={X:[[new S(new A(.2,0,.6,4),n),[.3,0,0],[0,0,-Math.PI/2]],[new S(new A(.2,0,.6,4),n),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new S(new A(.2,0,.6,4),n),[0,.3,0]],[new S(new A(.2,0,.6,4),n),[0,-.3,0],[0,0,Math.PI]]],Z:[[new S(new A(.2,0,.6,4),n),[0,0,.3],[Math.PI/2,0,0]],[new S(new A(.2,0,.6,4),n),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new S(new M(.2,0),n)]],XY:[[new S(new C(.2,.2,.01),n),[.15,.15,0]]],YZ:[[new S(new C(.2,.2,.01),n),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new S(new C(.2,.2,.01),n),[.15,0,.15],[-Math.PI/2,0,0]]]},w={START:[[new S(new M(.01,2),r),null,null,null,"helper"]],END:[[new S(new M(.01,2),r),null,null,null,"helper"]],DELTA:[[new R(function(){const e=new O;return e.setAttribute("position",new k([0,0,0,1,1,1],3)),e}(),r),null,null,null,"helper"]],X:[[new R(m,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new R(m,r.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new R(m,r.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},_={XYZE:[[new S(b(.5,1),d),null,[0,Math.PI/2,0]]],X:[[new S(b(.5,.5),i)]],Y:[[new S(b(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new S(b(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new S(b(.75,1),h),null,[0,Math.PI/2,0]]]},N={AXIS:[[new R(m,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},L={XYZE:[[new S(new P(.25,10,8),n)]],X:[[new S(new I(.5,.1,4,24),n),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new S(new I(.5,.1,4,24),n),[0,0,0],[Math.PI/2,0,0]]],Z:[[new S(new I(.5,.1,4,24),n),[0,0,0],[0,0,-Math.PI/2]]],E:[[new S(new I(.75,.1,2,24),n)]]},D={X:[[new S(f,i),[.5,0,0],[0,0,-Math.PI/2]],[new S(g,i),[0,0,0],[0,0,-Math.PI/2]],[new S(f,i),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new S(f,o),[0,.5,0]],[new S(g,o)],[new S(f,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new S(f,a),[0,0,.5],[Math.PI/2,0,0]],[new S(g,a),[0,0,0],[Math.PI/2,0,0]],[new S(f,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new S(new C(.15,.15,.01),l),[.15,.15,0]]],YZ:[[new S(new C(.15,.15,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new S(new C(.15,.15,.01),c),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new S(new C(.1,.1,.1),u.clone())]]},j={X:[[new S(new A(.2,0,.6,4),n),[.3,0,0],[0,0,-Math.PI/2]],[new S(new A(.2,0,.6,4),n),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new S(new A(.2,0,.6,4),n),[0,.3,0]],[new S(new A(.2,0,.6,4),n),[0,-.3,0],[0,0,Math.PI]]],Z:[[new S(new A(.2,0,.6,4),n),[0,0,.3],[Math.PI/2,0,0]],[new S(new A(.2,0,.6,4),n),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new S(new C(.2,.2,.01),n),[.15,.15,0]]],YZ:[[new S(new C(.2,.2,.01),n),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new S(new C(.2,.2,.01),n),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new S(new C(.2,.2,.2),n),[0,0,0]]]},F={X:[[new R(m,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new R(m,r.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new R(m,r.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function U(e){const t=new x;for(const n in e)for(let r=e[n].length;r--;){const i=e[n][r][0].clone(),o=e[n][r][1],a=e[n][r][2],s=e[n][r][3],c=e[n][r][4];i.name=n,i.tag=c,o&&i.position.set(o[0],o[1],o[2]),a&&i.rotation.set(a[0],a[1],a[2]),s&&i.scale.set(s[0],s[1],s[2]),i.updateMatrix();const l=i.geometry.clone();l.applyMatrix4(i.matrix),i.geometry=l,i.renderOrder=1/0,i.position.set(0,0,0),i.rotation.set(0,0,0),i.scale.set(1,1,1),t.add(i)}return t}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=U(y)),this.add(this.gizmo.rotate=U(_)),this.add(this.gizmo.scale=U(D)),this.add(this.picker.translate=U(v)),this.add(this.picker.rotate=U(L)),this.add(this.picker.scale=U(j)),this.add(this.helper.translate=U(w)),this.add(this.helper.rotate=U(N)),this.add(this.helper.scale=U(F)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){const t="local"===("scale"===this.mode?"local":this.space)?this.worldQuaternion:dn;this.gizmo.translate.visible="translate"===this.mode,this.gizmo.rotate.visible="rotate"===this.mode,this.gizmo.scale.visible="scale"===this.mode,this.helper.translate.visible="translate"===this.mode,this.helper.rotate.visible="rotate"===this.mode,this.helper.scale.visible="scale"===this.mode;let n=[];n=n.concat(this.picker[this.mode].children),n=n.concat(this.gizmo[this.mode].children),n=n.concat(this.helper[this.mode].children);for(let e=0;e<n.length;e++){const r=n[e];let i;if(r.visible=!0,r.rotation.set(0,0,0),r.position.copy(this.worldPosition),i=this.camera.isOrthographicCamera?(this.camera.top-this.camera.bottom)/this.camera.zoom:this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),r.scale.set(1,1,1).multiplyScalar(i*this.size/4),"helper"!==r.tag){if(r.quaternion.copy(t),"translate"===this.mode||"scale"===this.mode){const e=.99,n=.2;"X"===r.name&&Math.abs(cn.copy(mn).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"Y"===r.name&&Math.abs(cn.copy(gn).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"Z"===r.name&&Math.abs(cn.copy(bn).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"XY"===r.name&&Math.abs(cn.copy(bn).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"YZ"===r.name&&Math.abs(cn.copy(mn).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),"XZ"===r.name&&Math.abs(cn.copy(gn).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1)}else"rotate"===this.mode&&(hn.copy(t),cn.copy(this.eye).applyQuaternion(qt.copy(t).invert()),-1!==r.name.search("E")&&r.quaternion.setFromRotationMatrix(un.lookAt(this.eye,ln,gn)),"X"===r.name&&(qt.setFromAxisAngle(mn,Math.atan2(-cn.y,cn.z)),qt.multiplyQuaternions(hn,qt),r.quaternion.copy(qt)),"Y"===r.name&&(qt.setFromAxisAngle(gn,Math.atan2(cn.x,cn.z)),qt.multiplyQuaternions(hn,qt),r.quaternion.copy(qt)),"Z"===r.name&&(qt.setFromAxisAngle(bn,Math.atan2(cn.y,cn.x)),qt.multiplyQuaternions(hn,qt),r.quaternion.copy(qt)));r.visible=r.visible&&(-1===r.name.indexOf("X")||this.showX),r.visible=r.visible&&(-1===r.name.indexOf("Y")||this.showY),r.visible=r.visible&&(-1===r.name.indexOf("Z")||this.showZ),r.visible=r.visible&&(-1===r.name.indexOf("E")||this.showX&&this.showY&&this.showZ),r.material._color=r.material._color||r.material.color.clone(),r.material._opacity=r.material._opacity||r.material.opacity,r.material.color.copy(r.material._color),r.material.opacity=r.material._opacity,this.enabled&&this.axis&&(r.name===this.axis||this.axis.split("").some(function(e){return r.name===e}))&&(r.material.color.setHex(16776960),r.material.opacity=1)}else r.visible=!1,"AXIS"===r.name?(r.visible=!!this.axis,"X"===this.axis&&(qt.setFromEuler(sn.set(0,0,0)),r.quaternion.copy(t).multiply(qt),Math.abs(cn.copy(mn).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),"Y"===this.axis&&(qt.setFromEuler(sn.set(0,0,Math.PI/2)),r.quaternion.copy(t).multiply(qt),Math.abs(cn.copy(gn).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),"Z"===this.axis&&(qt.setFromEuler(sn.set(0,Math.PI/2,0)),r.quaternion.copy(t).multiply(qt),Math.abs(cn.copy(bn).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),"XYZE"===this.axis&&(qt.setFromEuler(sn.set(0,Math.PI/2,0)),cn.copy(this.rotationAxis),r.quaternion.setFromRotationMatrix(un.lookAt(ln,cn,gn)),r.quaternion.multiply(qt),r.visible=this.dragging),"E"===this.axis&&(r.visible=!1)):"START"===r.name?(r.position.copy(this.worldPositionStart),r.visible=this.dragging):"END"===r.name?(r.position.copy(this.worldPosition),r.visible=this.dragging):"DELTA"===r.name?(r.position.copy(this.worldPositionStart),r.quaternion.copy(this.worldQuaternionStart),Wt.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),Wt.applyQuaternion(this.worldQuaternionStart.clone().invert()),r.scale.copy(Wt),r.visible=this.dragging):(r.quaternion.copy(t),this.dragging?r.position.copy(this.worldPositionStart):r.position.copy(this.worldPosition),this.axis&&(r.visible=-1!==this.axis.search(r.name)))}super.updateMatrixWorld(e)}}class En extends S{constructor(){super(new L(1e5,1e5,2,2),new E({visible:!1,wireframe:!0,side:D,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),"scale"===this.mode&&(t="local"),yn.copy(mn).applyQuaternion("local"===t?this.worldQuaternion:dn),vn.copy(gn).applyQuaternion("local"===t?this.worldQuaternion:dn),xn.copy(bn).applyQuaternion("local"===t?this.worldQuaternion:dn),cn.copy(vn),this.mode){case"translate":case"scale":switch(this.axis){case"X":cn.copy(this.eye).cross(yn),pn.copy(yn).cross(cn);break;case"Y":cn.copy(this.eye).cross(vn),pn.copy(vn).cross(cn);break;case"Z":cn.copy(this.eye).cross(xn),pn.copy(xn).cross(cn);break;case"XY":pn.copy(xn);break;case"YZ":pn.copy(yn);break;case"XZ":cn.copy(xn),pn.copy(vn);break;case"XYZ":case"E":pn.set(0,0,0)}break;default:pn.set(0,0,0)}0===pn.length()?this.quaternion.copy(this.cameraQuaternion):(fn.lookAt(Wt.set(0,0,0),pn,cn),this.quaternion.setFromRotationMatrix(fn)),super.updateMatrixWorld(e)}}const Tn=1.25,An=65535,Cn=Math.pow(2,-24),On=Symbol("SKIP_GENERATION");function kn(e){return function(e){return e.index?e.index.count:e.attributes.position.count}(e)/3}function Sn(e,t){if(!e.index){const n=e.attributes.position.count,r=function(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new j(r,1));for(let e=0;e<n;e++)r[e]=e}}function Mn(e,t){const n=kn(e),r=t||e.drawRange,i=r.start/3,o=(r.start+r.count)/3,a=Math.max(0,i),s=Math.min(n,o)-a;return[{offset:Math.floor(a),count:Math.floor(s)}]}function Rn(e,t){if(!e.groups||!e.groups.length)return Mn(e,t);const n=[],r=new Set,i=t||e.drawRange,o=i.start/3,a=(i.start+i.count)/3;for(const t of e.groups){const e=t.start/3,n=(t.start+t.count)/3;r.add(Math.max(o,e)),r.add(Math.min(a,n))}const s=Array.from(r.values()).sort((e,t)=>e-t);for(let e=0;e<s.length-1;e++){const t=s[e],r=s[e+1];n.push({offset:Math.floor(t),count:Math.floor(r-t)})}return n}function In(e,t,n,r,i){let o=1/0,a=1/0,s=1/0,c=-1/0,l=-1/0,u=-1/0,h=1/0,d=1/0,p=1/0,f=-1/0,m=-1/0,g=-1/0;for(let r=6*t,i=6*(t+n);r<i;r+=6){const t=e[r+0],n=e[r+1],i=t-n,b=t+n;i<o&&(o=i),b>c&&(c=b),t<h&&(h=t),t>f&&(f=t);const y=e[r+2],v=e[r+3],x=y-v,w=y+v;x<a&&(a=x),w>l&&(l=w),y<d&&(d=y),y>m&&(m=y);const E=e[r+4],T=e[r+5],A=E-T,C=E+T;A<s&&(s=A),C>u&&(u=C),E<p&&(p=E),E>g&&(g=E)}r[0]=o,r[1]=a,r[2]=s,r[3]=c,r[4]=l,r[5]=u,i[0]=h,i[1]=d,i[2]=p,i[3]=f,i[4]=m,i[5]=g}function Pn(e,t,n){return n.min.x=t[e],n.min.y=t[e+1],n.min.z=t[e+2],n.max.x=t[e+3],n.max.y=t[e+4],n.max.z=t[e+5],n}function _n(e){let t=-1,n=-1/0;for(let r=0;r<3;r++){const i=e[r+3]-e[r];i>n&&(n=i,t=r)}return t}function Nn(e,t){t.set(e)}function Ln(e,t,n){let r,i;for(let o=0;o<3;o++){const a=o+3;r=e[o],i=t[o],n[o]=r<i?r:i,r=e[a],i=t[a],n[a]=r>i?r:i}}function Dn(e,t,n){for(let r=0;r<3;r++){const i=t[e+2*r],o=t[e+2*r+1],a=i-o,s=i+o;a<n[r]&&(n[r]=a),s>n[r+3]&&(n[r+3]=s)}}function jn(e){const t=e[3]-e[0],n=e[4]-e[1],r=e[5]-e[2];return 2*(t*n+n*r+r*t)}const Fn=32,Un=(e,t)=>e.candidate-t.candidate,Bn=new Array(Fn).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),zn=new Float32Array(6);class Hn{constructor(){this.boundingData=new Float32Array(6)}}function Vn(e,t,n,r,i,o){let a=r,s=r+i-1;const c=o.pos,l=2*o.axis;for(;;){for(;a<=s&&n[6*a+l]<c;)a++;for(;a<=s&&n[6*s+l]>=c;)s--;if(!(a<s))return a;for(let e=0;e<3;e++){let n=t[3*a+e];t[3*a+e]=t[3*s+e],t[3*s+e]=n}for(let e=0;e<6;e++){let t=n[6*a+e];n[6*a+e]=n[6*s+e],n[6*s+e]=t}a++,s--}}function Gn(e,t,n,r,i,o){let a=r,s=r+i-1;const c=o.pos,l=2*o.axis;for(;;){for(;a<=s&&n[6*a+l]<c;)a++;for(;a<=s&&n[6*s+l]>=c;)s--;if(!(a<s))return a;{let t=e[a];e[a]=e[s],e[s]=t;for(let e=0;e<6;e++){let t=n[6*a+e];n[6*a+e]=n[6*s+e],n[6*s+e]=t}a++,s--}}}function Wn(e,t){return 65535===t[e+15]}function Xn(e,t){return t[e+6]}function qn(e,t){return t[e+14]}function Yn(e){return e+8}function Kn(e,t){return t[e+6]}function Qn(e,t){return t[e+7]}function $n(e){return e}let Zn,Jn,er,tr;const nr=Math.pow(2,32);function rr(e){return"count"in e?1:1+rr(e.left)+rr(e.right)}function ir(e,t,n){return Zn=new Float32Array(n),Jn=new Uint32Array(n),er=new Uint16Array(n),tr=new Uint8Array(n),or(e,t)}function or(e,t){const n=e/4,r=e/2,i="count"in t,o=t.boundingData;for(let e=0;e<6;e++)Zn[n+e]=o[e];if(i){if(t.buffer){const r=t.buffer;tr.set(new Uint8Array(r),e);for(let t=e,i=e+r.byteLength;t<i;t+=32){Wn(t/2,er)||(Jn[t/4+6]+=n)}return e+r.byteLength}{const i=t.offset,o=t.count;return Jn[n+6]=i,er[r+14]=o,er[r+15]=An,e+32}}{const r=t.left,i=t.right,o=t.splitAxis;let a;if(a=or(e+32,r),a/4>nr)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Jn[n+6]=a/4,a=or(a,i),Jn[n+7]=o,a}}function ar(e,t,n,r,i){const{maxDepth:o,verbose:a,maxLeafTris:s,strategy:c,onProgress:l,indirect:u}=i,h=e._indirectBuffer,d=e.geometry,p=d.index?d.index.array:null,f=u?Gn:Vn,m=kn(d),g=new Float32Array(6);let b=!1;const y=new Hn;return In(t,n,r,y.boundingData,g),function e(n,r,i,l=null,u=0){!b&&u>=o&&(b=!0,a&&(console.warn(`MeshBVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d)));if(i<=s||u>=o)return v(r+i),n.offset=r,n.count=i,n;const m=function(e,t,n,r,i,o){let a=-1,s=0;if(0===o)a=_n(t),-1!==a&&(s=(t[a]+t[a+3])/2);else if(1===o)a=_n(e),-1!==a&&(s=function(e,t,n,r){let i=0;for(let o=t,a=t+n;o<a;o++)i+=e[6*o+2*r];return i/n}(n,r,i,a));else if(2===o){const o=jn(e);let c=Tn*i;const l=6*r,u=6*(r+i);for(let e=0;e<3;e++){const r=t[e],h=(t[e+3]-r)/Fn;if(i<8){const t=[...Bn];t.length=i;let r=0;for(let i=l;i<u;i+=6,r++){const o=t[r];o.candidate=n[i+2*e],o.count=0;const{bounds:a,leftCacheBounds:s,rightCacheBounds:c}=o;for(let e=0;e<3;e++)c[e]=1/0,c[e+3]=-1/0,s[e]=1/0,s[e+3]=-1/0,a[e]=1/0,a[e+3]=-1/0;Dn(i,n,a)}t.sort(Un);let h=i;for(let e=0;e<h;e++){const n=t[e];for(;e+1<h&&t[e+1].candidate===n.candidate;)t.splice(e+1,1),h--}for(let r=l;r<u;r+=6){const i=n[r+2*e];for(let e=0;e<h;e++){const o=t[e];i>=o.candidate?Dn(r,n,o.rightCacheBounds):(Dn(r,n,o.leftCacheBounds),o.count++)}}for(let n=0;n<h;n++){const r=t[n],l=r.count,u=i-r.count,h=r.leftCacheBounds,d=r.rightCacheBounds;let p=0;0!==l&&(p=jn(h)/o);let f=0;0!==u&&(f=jn(d)/o);const m=1+Tn*(p*l+f*u);m<c&&(a=e,c=m,s=r.candidate)}}else{for(let e=0;e<Fn;e++){const t=Bn[e];t.count=0,t.candidate=r+h+e*h;const n=t.bounds;for(let e=0;e<3;e++)n[e]=1/0,n[e+3]=-1/0}for(let t=l;t<u;t+=6){let i=~~((n[t+2*e]-r)/h);i>=Fn&&(i=31);const o=Bn[i];o.count++,Dn(t,n,o.bounds)}const t=Bn[31];Nn(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){const t=Bn[e],n=Bn[e+1];Ln(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let d=0;for(let t=0;t<31;t++){const n=Bn[t],r=n.count,l=n.bounds,u=Bn[t+1].rightCacheBounds;0!==r&&(0===d?Nn(l,zn):Ln(l,zn,zn)),d+=r;let h=0,p=0;0!==d&&(h=jn(zn)/o);const f=i-d;0!==f&&(p=jn(u)/o);const m=1+Tn*(h*d+p*f);m<c&&(a=e,c=m,s=n.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${o} used.`);return{axis:a,pos:s}}(n.boundingData,l,t,r,i,c);if(-1===m.axis)return v(r+i),n.offset=r,n.count=i,n;const y=f(h,p,t,r,i,m);if(y===r||y===r+i)v(r+i),n.offset=r,n.count=i;else{n.splitAxis=m.axis;const o=new Hn,a=r,s=y-r;n.left=o,In(t,a,s,o.boundingData,g),e(o,a,s,g,u+1);const c=new Hn,l=y,h=i-s;n.right=c,In(t,l,h,c.boundingData,g),e(c,l,h,g,u+1)}return n}(y,n,r,g),y;function v(e){l&&l(e/m)}}function sr(e,t){const n=e.geometry;t.indirect&&(e._indirectBuffer=function(e,t){const n=(e.index?e.index.count:e.attributes.position.count)/3,r=n>65536,i=r?4:2,o=t?new SharedArrayBuffer(n*i):new ArrayBuffer(n*i),a=r?new Uint32Array(o):new Uint16Array(o);for(let e=0,t=a.length;e<t;e++)a[e]=e;return a}(n,t.useSharedArrayBuffer),function(e,t){const n=kn(e),r=Rn(e,t).sort((e,t)=>e.offset-t.offset),i=r[r.length-1];i.count=Math.min(n-i.offset,i.count);let o=0;return r.forEach(({count:e})=>o+=e),n!==o}(n,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),e._indirectBuffer||Sn(n,t);const r=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=function(e,t=null,n=null,r=null){const i=e.attributes.position,o=e.index?e.index.array:null,a=kn(e),s=i.normalized;let c;null===t?(c=new Float32Array(6*a),n=0,r=a):(c=t,n=n||0,r=r||a);const l=i.array,u=i.offset||0;let h=3;i.isInterleavedBufferAttribute&&(h=i.data.stride);const d=["getX","getY","getZ"];for(let e=n;e<n+r;e++){const t=3*e,n=6*e;let r=t+0,a=t+1,p=t+2;o&&(r=o[r],a=o[a],p=o[p]),s||(r=r*h+u,a=a*h+u,p=p*h+u);for(let e=0;e<3;e++){let t,o,u;s?(t=i[d[e]](r),o=i[d[e]](a),u=i[d[e]](p)):(t=l[r+e],o=l[a+e],u=l[p+e]);let h=t;o<h&&(h=o),u<h&&(h=u);let f=t;o>f&&(f=o),u>f&&(f=u);const m=(f-h)/2,g=2*e;c[n+g+0]=h+m,c[n+g+1]=m+(Math.abs(h)+m)*Cn}}return c}(n),o=t.indirect?Mn(n,t.range):Rn(n,t.range);e._roots=o.map(n=>{const o=ar(e,i,n.offset,n.count,t),a=rr(o),s=new r(32*a);return ir(0,o,s),s})}class cr{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,r=-1/0;for(let i=0,o=e.length;i<o;i++){const o=e[i][t];n=o<n?o:n,r=o>r?o:r}this.min=n,this.max=r}setFromPoints(e,t){let n=1/0,r=-1/0;for(let i=0,o=t.length;i<o;i++){const o=t[i],a=e.dot(o);n=a<n?a:n,r=a>r?a:r}this.min=n,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}}cr.prototype.setFromBox=function(){const e=new f;return function(t,n){const r=n.min,i=n.max;let o=1/0,a=-1/0;for(let n=0;n<=1;n++)for(let s=0;s<=1;s++)for(let c=0;c<=1;c++){e.x=r.x*n+i.x*(1-n),e.y=r.y*s+i.y*(1-s),e.z=r.z*c+i.z*(1-c);const l=t.dot(e);o=Math.min(l,o),a=Math.max(l,a)}this.min=o,this.max=a}}();const lr=function(){const e=new f,t=new f,n=new f;return function(r,i,o){const a=r.start,s=e,c=i.start,l=t;n.subVectors(a,c),e.subVectors(r.end,r.start),t.subVectors(i.end,i.start);const u=n.dot(l),h=l.dot(s),d=l.dot(l),p=n.dot(s),f=s.dot(s)*d-h*h;let m,g;m=0!==f?(u*h-p*d)/f:0,g=(u+m*h)/d,o.x=m,o.y=g}}(),ur=function(){const e=new v,t=new f,n=new f;return function(r,i,o,a){lr(r,i,e);let s=e.x,c=e.y;if(s>=0&&s<=1&&c>=0&&c<=1)return r.at(s,o),void i.at(c,a);if(s>=0&&s<=1)return c<0?i.at(0,a):i.at(1,a),void r.closestPointToPoint(a,!0,o);if(c>=0&&c<=1)return s<0?r.at(0,o):r.at(1,o),void i.closestPointToPoint(o,!0,a);{let e,l;e=s<0?r.start:r.end,l=c<0?i.start:i.end;const u=t,h=n;return r.closestPointToPoint(l,!0,t),i.closestPointToPoint(e,!0,n),u.distanceToSquared(l)<=h.distanceToSquared(e)?(o.copy(u),void a.copy(l)):(o.copy(e),void a.copy(h))}}}(),hr=function(){const e=new f,t=new f,n=new h,r=new F;return function(i,o){const{radius:a,center:s}=i,{a:c,b:l,c:u}=o;r.start=c,r.end=l;if(r.closestPointToPoint(s,!0,e).distanceTo(s)<=a)return!0;r.start=c,r.end=u;if(r.closestPointToPoint(s,!0,e).distanceTo(s)<=a)return!0;r.start=l,r.end=u;if(r.closestPointToPoint(s,!0,e).distanceTo(s)<=a)return!0;const h=o.getPlane(n);if(Math.abs(h.distanceToPoint(s))<=a){const e=h.projectPoint(s,t);if(o.containsPoint(e))return!0}return!1}}();function dr(e){return Math.abs(e)<1e-15}class pr extends U{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new f),this.satBounds=new Array(4).fill().map(()=>new cr),this.points=[this.a,this.b,this.c],this.sphere=new B,this.plane=new h,this.needsUpdate=!0}intersectsSphere(e){return hr(e,this)}update(){const e=this.a,t=this.b,n=this.c,r=this.points,i=this.satAxes,o=this.satBounds,a=i[0],s=o[0];this.getNormal(a),s.setFromPoints(a,r);const c=i[1],l=o[1];c.subVectors(e,t),l.setFromPoints(c,r);const u=i[2],h=o[2];u.subVectors(t,n),h.setFromPoints(u,r);const d=i[3],p=o[3];d.subVectors(n,e),p.setFromPoints(d,r),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(a,e),this.needsUpdate=!1}}pr.prototype.closestPointToSegment=function(){const e=new f,t=new f,n=new F;return function(r,i=null,o=null){const{start:a,end:s}=r,c=this.points;let l,u=1/0;for(let a=0;a<3;a++){const s=(a+1)%3;n.start.copy(c[a]),n.end.copy(c[s]),ur(n,r,e,t),l=e.distanceToSquared(t),l<u&&(u=l,i&&i.copy(e),o&&o.copy(t))}return this.closestPointToPoint(a,e),l=a.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),o&&o.copy(a)),this.closestPointToPoint(s,e),l=s.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),o&&o.copy(s)),Math.sqrt(u)}}(),pr.prototype.intersectsTriangle=function(){const e=new pr,t=new Array(3),n=new Array(3),r=new cr,i=new cr,o=new f,a=new f,s=new f,c=new f,l=new f,u=new F,h=new F,d=new F,p=new f;function m(e,t,n){const r=e.points;let i=0,o=-1;for(let e=0;e<3;e++){const{start:s,end:c}=u;s.copy(r[e]),c.copy(r[(e+1)%3]),u.delta(a);const l=dr(t.distanceToPoint(s));if(dr(t.normal.dot(a))&&l){n.copy(u),i=2;break}const h=t.intersectLine(u,p);if(!h&&l&&p.copy(s),(h||l)&&!dr(p.distanceTo(c))){if(i<=1){(1===i?n.start:n.end).copy(p),l&&(o=i)}else if(i>=2){(1===o?n.start:n.end).copy(p),i=2;break}if(i++,2===i&&-1===o)break}}return i}return function(a,u=null,p=!1){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(e.copy(a),e.update(),a=e);const f=this.plane,g=a.plane;if(Math.abs(f.normal.dot(g.normal))>1-1e-10){const e=this.satBounds,s=this.satAxes;n[0]=a.a,n[1]=a.b,n[2]=a.c;for(let t=0;t<4;t++){const i=e[t],o=s[t];if(r.setFromPoints(o,n),i.isSeparated(r))return!1}const c=a.satBounds,l=a.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let e=0;e<4;e++){const n=c[e],i=l[e];if(r.setFromPoints(i,t),n.isSeparated(r))return!1}for(let e=0;e<4;e++){const a=s[e];for(let e=0;e<4;e++){const s=l[e];if(o.crossVectors(a,s),r.setFromPoints(o,t),i.setFromPoints(o,n),r.isSeparated(i))return!1}}return u&&(p||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),u.start.set(0,0,0),u.end.set(0,0,0)),!0}{const e=m(this,g,h);if(1===e&&a.containsPoint(h.end))return u&&(u.start.copy(h.end),u.end.copy(h.end)),!0;if(2!==e)return!1;const t=m(a,f,d);if(1===t&&this.containsPoint(d.end))return u&&(u.start.copy(d.end),u.end.copy(d.end)),!0;if(2!==t)return!1;if(h.delta(s),d.delta(c),s.dot(c)<0){let e=d.start;d.start=d.end,d.end=e}const n=h.start.dot(s),r=h.end.dot(s),i=d.start.dot(s),o=d.end.dot(s);return(n===o||i===r||r<i!==n<o)&&(u&&(l.subVectors(h.start,d.start),l.dot(s)>0?u.start.copy(h.start):u.start.copy(d.start),l.subVectors(h.end,d.end),l.dot(s)<0?u.end.copy(h.end):u.end.copy(d.end)),!0)}}}(),pr.prototype.distanceToPoint=function(){const e=new f;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}(),pr.prototype.distanceToTriangle=function(){const e=new f,t=new f,n=["a","b","c"],r=new F,i=new F;return function(o,a=null,s=null){const c=a||s?r:null;if(this.intersectsTriangle(o,c))return(a||s)&&(a&&c.getCenter(a),s&&c.getCenter(s)),0;let l=1/0;for(let t=0;t<3;t++){let r;const i=n[t],c=o[i];this.closestPointToPoint(c,e),r=c.distanceToSquared(e),r<l&&(l=r,a&&a.copy(e),s&&s.copy(c));const u=this[i];o.closestPointToPoint(u,e),r=u.distanceToSquared(e),r<l&&(l=r,a&&a.copy(u),s&&s.copy(e))}for(let c=0;c<3;c++){const u=n[c],h=n[(c+1)%3];r.set(this[u],this[h]);for(let c=0;c<3;c++){const u=n[c],h=n[(c+1)%3];i.set(o[u],o[h]),ur(r,i,e,t);const d=e.distanceToSquared(t);d<l&&(l=d,a&&a.copy(e),s&&s.copy(t))}}return Math.sqrt(l)}}();class fr{constructor(e,t,n){this.isOrientedBox=!0,this.min=new f,this.max=new f,this.matrix=new N,this.invMatrix=new N,this.points=new Array(8).fill().map(()=>new f),this.satAxes=new Array(3).fill().map(()=>new f),this.satBounds=new Array(3).fill().map(()=>new cr),this.alignedSatBounds=new Array(3).fill().map(()=>new cr),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}fr.prototype.update=function(){const e=this.matrix,t=this.min,n=this.max,r=this.points;for(let i=0;i<=1;i++)for(let o=0;o<=1;o++)for(let a=0;a<=1;a++){const s=r[1*i|2*o|4*a];s.x=i?n.x:t.x,s.y=o?n.y:t.y,s.z=a?n.z:t.z,s.applyMatrix4(e)}const i=this.satBounds,o=this.satAxes,a=r[0];for(let e=0;e<3;e++){const t=o[e],n=i[e],s=r[1<<e];t.subVectors(a,s),n.setFromPoints(t,r)}const s=this.alignedSatBounds;s[0].setFromPointsField(r,"x"),s[1].setFromPointsField(r,"y"),s[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1},fr.prototype.intersectsBox=function(){const e=new cr;return function(t){this.needsUpdate&&this.update();const n=t.min,r=t.max,i=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(e.min=n.x,e.max=r.x,a[0].isSeparated(e))return!1;if(e.min=n.y,e.max=r.y,a[1].isSeparated(e))return!1;if(e.min=n.z,e.max=r.z,a[2].isSeparated(e))return!1;for(let n=0;n<3;n++){const r=o[n],a=i[n];if(e.setFromBox(r,t),a.isSeparated(e))return!1}return!0}}(),fr.prototype.intersectsTriangle=function(){const e=new pr,t=new Array(3),n=new cr,r=new cr,i=new f;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(e.copy(o),e.update(),o=e);const a=this.satBounds,s=this.satAxes;t[0]=o.a,t[1]=o.b,t[2]=o.c;for(let e=0;e<3;e++){const r=a[e],i=s[e];if(n.setFromPoints(i,t),r.isSeparated(n))return!1}const c=o.satBounds,l=o.satAxes,u=this.points;for(let e=0;e<3;e++){const t=c[e],r=l[e];if(n.setFromPoints(r,u),t.isSeparated(n))return!1}for(let e=0;e<3;e++){const o=s[e];for(let e=0;e<4;e++){const a=l[e];if(i.crossVectors(o,a),n.setFromPoints(i,t),r.setFromPoints(i,u),n.isSeparated(r))return!1}}return!0}}(),fr.prototype.closestPointToPoint=function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t},fr.prototype.distanceToPoint=function(){const e=new f;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}(),fr.prototype.distanceToBox=function(){const e=["x","y","z"],t=new Array(12).fill().map(()=>new F),n=new Array(12).fill().map(()=>new F),r=new f,i=new f;return function(o,a=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(s||c)&&(o.getCenter(i),this.closestPointToPoint(i,r),o.closestPointToPoint(r,i),s&&s.copy(r),c&&c.copy(i)),0;const l=a*a,u=o.min,h=o.max,d=this.points;let p=1/0;for(let e=0;e<8;e++){const t=d[e];i.copy(t).clamp(u,h);const n=t.distanceToSquared(i);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(i),n<l))return Math.sqrt(n)}let f=0;for(let r=0;r<3;r++)for(let i=0;i<=1;i++)for(let o=0;o<=1;o++){const a=(r+1)%3,s=(r+2)%3,c=1<<r|i<<a|o<<s,l=d[i<<a|o<<s],p=d[c];t[f].set(l,p);const m=e[r],g=e[a],b=e[s],y=n[f],v=y.start,x=y.end;v[m]=u[m],v[g]=i?u[g]:h[g],v[b]=o?u[b]:h[g],x[m]=h[m],x[g]=i?u[g]:h[g],x[b]=o?u[b]:h[g],f++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let n=0;n<=1;n++){i.x=e?h.x:u.x,i.y=t?h.y:u.y,i.z=n?h.z:u.z,this.closestPointToPoint(i,r);const o=i.distanceToSquared(r);if(o<p&&(p=o,s&&s.copy(r),c&&c.copy(i),o<l))return Math.sqrt(o)}for(let e=0;e<12;e++){const o=t[e];for(let e=0;e<12;e++){const t=n[e];ur(o,t,r,i);const a=r.distanceToSquared(i);if(a<p&&(p=a,s&&s.copy(r),c&&c.copy(i),a<l))return Math.sqrt(a)}}return Math.sqrt(p)}}();class mr{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return 0===e.length?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class gr extends mr{constructor(){super(()=>new pr)}}const br=new gr;const yr=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==e.length&&this.setBuffer(e.pop())}}};let vr,xr;const wr=[],Er=new mr(()=>new z);function Tr(e,t,n,r,i,o){vr=Er.getPrimitive(),xr=Er.getPrimitive(),wr.push(vr,xr),yr.setBuffer(e._roots[t]);const a=Ar(0,e.geometry,n,r,i,o);yr.clearBuffer(),Er.releasePrimitive(vr),Er.releasePrimitive(xr),wr.pop(),wr.pop();const s=wr.length;return s>0&&(xr=wr[s-1],vr=wr[s-2]),a}function Ar(e,t,n,r,i=null,o=0,a=0){const{float32Array:s,uint16Array:c,uint32Array:l}=yr;let u=2*e;if(Wn(u,c)){const h=Xn(e,l),d=qn(u,c);return Pn(e,s,vr),r(h,d,!1,a,o+e,vr)}{const p=Yn(e),f=Kn(e,l);let m,g,b,y,v=p,x=f;if(i&&(b=vr,y=xr,Pn(v,s,b),Pn(x,s,y),m=i(b),g=i(y),g<m)){v=f,x=p;const k=m;m=g,g=k,b=y}b||(b=vr,Pn(v,s,b));const w=n(b,Wn(2*v,c),m,a+1,o+v);let E;if(2===w){const S=C(v);E=r(S,O(v)-S,!0,a+1,o+v,b)}else E=w&&Ar(v,t,n,r,i,o,a+1);if(E)return!0;y=xr,Pn(x,s,y);const T=n(y,Wn(2*x,c),g,a+1,o+x);let A;if(2===T){const M=C(x);A=r(M,O(x)-M,!0,a+1,o+x,y)}else A=T&&Ar(x,t,n,r,i,o,a+1);return!!A;function C(e){const{uint16Array:t,uint32Array:n}=yr;let r=2*e;for(;!Wn(r,t);)r=2*(e=Yn(e));return Xn(e,n)}function O(e){const{uint16Array:t,uint32Array:n}=yr;let r=2*e;for(;!Wn(r,t);)r=2*(e=Kn(e,n));return Xn(e,n)+qn(r,t)}}}const Cr=new f,Or=new f;const kr=parseInt(V)>=169,Sr=new f,Mr=new f,Rr=new f,Ir=new v,Pr=new v,_r=new v,Nr=new f,Lr=new f,Dr=new f,jr=new f;function Fr(e,t,n,r,i,o,a,s,c,l,u){Sr.fromBufferAttribute(t,o),Mr.fromBufferAttribute(t,a),Rr.fromBufferAttribute(t,s);const h=function(e,t,n,r,i,o,a,s){let c;if(c=o===H?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,o!==D,i),null===c)return null;const l=e.origin.distanceTo(i);return l<a||l>s?null:{distance:l,point:i.clone()}}(e,Sr,Mr,Rr,jr,c,l,u);if(h){const t=new f;U.getBarycoord(jr,Sr,Mr,Rr,t),r&&(Ir.fromBufferAttribute(r,o),Pr.fromBufferAttribute(r,a),_r.fromBufferAttribute(r,s),h.uv=U.getInterpolation(jr,Sr,Mr,Rr,Ir,Pr,_r,new v)),i&&(Ir.fromBufferAttribute(i,o),Pr.fromBufferAttribute(i,a),_r.fromBufferAttribute(i,s),h.uv1=U.getInterpolation(jr,Sr,Mr,Rr,Ir,Pr,_r,new v)),n&&(Nr.fromBufferAttribute(n,o),Lr.fromBufferAttribute(n,a),Dr.fromBufferAttribute(n,s),h.normal=U.getInterpolation(jr,Sr,Mr,Rr,Nr,Lr,Dr,new f),h.normal.dot(e.direction)>0&&h.normal.multiplyScalar(-1));const c={a:o,b:a,c:s,normal:new f,materialIndex:0};U.getNormal(Sr,Mr,Rr,c.normal),h.face=c,h.faceIndex=o,kr&&(h.barycoord=t)}return h}function Ur(e,t,n,r,i,o,a){const s=3*r;let c=s+0,l=s+1,u=s+2;const h=e.index;e.index&&(c=h.getX(c),l=h.getX(l),u=h.getX(u));const{position:d,normal:p,uv:f,uv1:m}=e.attributes,g=Fr(n,d,p,f,m,c,l,u,t,o,a);return g?(g.faceIndex=r,i&&i.push(g),g):null}function Br(e,t,n,r){const i=e.a,o=e.b,a=e.c;let s=t,c=t+1,l=t+2;n&&(s=n.getX(s),c=n.getX(c),l=n.getX(l)),i.x=r.getX(s),i.y=r.getY(s),i.z=r.getZ(s),o.x=r.getX(c),o.y=r.getY(c),o.z=r.getZ(c),a.x=r.getX(l),a.y=r.getY(l),a.z=r.getZ(l)}function zr(e,t,n,r,i,o,a){const{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let n=e,s=t+e;n<s;n++){let e;if(e=n,Br(a,3*e,c,l),a.needsUpdate=!0,r(a,e,i,o))return!0}return!1}function Hr(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));const n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position;let o,a,s,c,l=0;const u=e._roots;for(let e=0,t=u.length;e<t;e++)o=u[e],a=new Uint32Array(o),s=new Uint16Array(o),c=new Float32Array(o),h(0,l),l+=o.byteLength;function h(e,n,o=!1){const l=2*e;if(s[l+15]===An){const t=a[e+6];let n=1/0,o=1/0,u=1/0,h=-1/0,d=-1/0,p=-1/0;for(let e=3*t,a=3*(t+s[l+14]);e<a;e++){let t=r[e];const a=i.getX(t),s=i.getY(t),c=i.getZ(t);a<n&&(n=a),a>h&&(h=a),s<o&&(o=s),s>d&&(d=s),c<u&&(u=c),c>p&&(p=c)}return(c[e+0]!==n||c[e+1]!==o||c[e+2]!==u||c[e+3]!==h||c[e+4]!==d||c[e+5]!==p)&&(c[e+0]=n,c[e+1]=o,c[e+2]=u,c[e+3]=h,c[e+4]=d,c[e+5]=p,!0)}{const r=e+8,i=a[e+6],s=r+n,l=i+n;let u=o,d=!1,p=!1;t?u||(d=t.has(s),p=t.has(l),u=!d&&!p):(d=!0,p=!0);const f=u||p;let m=!1;(u||d)&&(m=h(r,n,u));let g=!1;f&&(g=h(i,n,u));const b=m||g;if(b)for(let t=0;t<3;t++){const n=r+t,o=i+t,a=c[n],s=c[n+3],l=c[o],u=c[o+3];c[e+t]=a<l?a:l,c[e+t+3]=s>u?s:u}return b}}}function Vr(e,t,n,r,i){let o,a,s,c,l,u;const h=1/n.direction.x,d=1/n.direction.y,p=1/n.direction.z,f=n.origin.x,m=n.origin.y,g=n.origin.z;let b=t[e],y=t[e+3],v=t[e+1],x=t[e+3+1],w=t[e+2],E=t[e+3+2];return h>=0?(o=(b-f)*h,a=(y-f)*h):(o=(y-f)*h,a=(b-f)*h),d>=0?(s=(v-m)*d,c=(x-m)*d):(s=(x-m)*d,c=(v-m)*d),!(o>c||s>a)&&((s>o||isNaN(o))&&(o=s),(c<a||isNaN(a))&&(a=c),p>=0?(l=(w-g)*p,u=(E-g)*p):(l=(E-g)*p,u=(w-g)*p),!(o>u||l>a)&&((l>o||o!=o)&&(o=l),(u<a||a!=a)&&(a=u),o<=i&&a>=r))}function Gr(e,t,n,r,i,o,a){const{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let s=e,u=t+e;s<u;s++){let e;if(e=n.resolveTriangleIndex(s),Br(a,3*e,c,l),a.needsUpdate=!0,r(a,e,i,o))return!0}return!1}function Wr(e,t,n,r,i,o,a){yr.setBuffer(e._roots[t]),Xr(0,e,n,r,i,o,a),yr.clearBuffer()}function Xr(e,t,n,r,i,o,a){const{float32Array:s,uint16Array:c,uint32Array:l}=yr,u=2*e;if(Wn(u,c)){!function(e,t,n,r,i,o,a,s){const{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)Ur(c,t,n,e,o,a,s)}(t,n,r,Xn(e,l),qn(u,c),i,o,a)}else{const c=Yn(e);Vr(c,s,r,o,a)&&Xr(c,t,n,r,i,o,a);const u=Kn(e,l);Vr(u,s,r,o,a)&&Xr(u,t,n,r,i,o,a)}}const qr=["x","y","z"];function Yr(e,t,n,r,i,o){yr.setBuffer(e._roots[t]);const a=Kr(0,e,n,r,i,o);return yr.clearBuffer(),a}function Kr(e,t,n,r,i,o){const{float32Array:a,uint16Array:s,uint32Array:c}=yr;let l=2*e;if(Wn(l,s)){return function(e,t,n,r,i,o,a){const{geometry:s,_indirectBuffer:c}=e;let l=1/0,u=null;for(let e=r,c=r+i;e<c;e++){let r;r=Ur(s,t,n,e,null,o,a),r&&r.distance<l&&(u=r,l=r.distance)}return u}(t,n,r,Xn(e,c),qn(l,s),i,o)}{const s=Qn(e,c),l=qr[s],u=r.direction[l]>=0;let h,d;u?(h=Yn(e),d=Kn(e,c)):(h=Kn(e,c),d=Yn(e));const p=Vr(h,a,r,i,o)?Kr(h,t,n,r,i,o):null;if(p){const e=p.point[l];if(u?e<=a[d+s]:e>=a[d+s+3])return p}const f=Vr(d,a,r,i,o)?Kr(d,t,n,r,i,o):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const Qr=new z,$r=new pr,Zr=new pr,Jr=new N,ei=new fr,ti=new fr;function ni(e,t,n,r){yr.setBuffer(e._roots[t]);const i=ri(0,e,n,r);return yr.clearBuffer(),i}function ri(e,t,n,r,i=null){const{float32Array:o,uint16Array:a,uint32Array:s}=yr;let c=2*e;null===i&&(n.boundingBox||n.computeBoundingBox(),ei.set(n.boundingBox.min,n.boundingBox.max,r),i=ei);if(!Wn(c,a)){const a=e+8,c=s[e+6];Pn(a,o,Qr);if(i.intersectsBox(Qr)&&ri(a,t,n,r,i))return!0;Pn(c,o,Qr);return!!(i.intersectsBox(Qr)&&ri(c,t,n,r,i))}{const i=t.geometry,l=i.index,u=i.attributes.position,h=n.index,d=n.attributes.position,p=Xn(e,s),f=qn(c,a);if(Jr.copy(r).invert(),n.boundsTree){Pn(e,o,ti),ti.matrix.copy(Jr),ti.needsUpdate=!0;const t=n.boundsTree.shapecast({intersectsBounds:e=>ti.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let t=3*p,n=3*(f+p);t<n;t+=3)if(Br(Zr,t,l,u),Zr.needsUpdate=!0,e.intersectsTriangle(Zr))return!0;return!1}});return t}for(let e=3*p,t=3*(f+p);e<t;e+=3){Br($r,e,l,u),$r.a.applyMatrix4(Jr),$r.b.applyMatrix4(Jr),$r.c.applyMatrix4(Jr),$r.needsUpdate=!0;for(let e=0,t=h.count;e<t;e+=3)if(Br(Zr,e,h,d),Zr.needsUpdate=!0,$r.intersectsTriangle(Zr))return!0}}}const ii=new N,oi=new fr,ai=new fr,si=new f,ci=new f,li=new f,ui=new f;function hi(e,t,n,r={},i={},o=0,a=1/0){t.boundingBox||t.computeBoundingBox(),oi.set(t.boundingBox.min,t.boundingBox.max,n),oi.needsUpdate=!0;const s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,h=t.index,d=br.getPrimitive(),p=br.getPrimitive();let f=si,m=ci,g=null,b=null;i&&(g=li,b=ui);let y=1/0,v=null,x=null;return ii.copy(n).invert(),ai.matrix.copy(ii),e.shapecast({boundsTraverseOrder:e=>oi.distanceToBox(e),intersectsBounds:(e,t,n)=>n<y&&n<a&&(t&&(ai.min.copy(e.min),ai.max.copy(e.max),ai.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree){return t.boundsTree.shapecast({boundsTraverseOrder:e=>ai.distanceToBox(e),intersectsBounds:(e,t,n)=>n<y&&n<a,intersectsRange:(t,i)=>{for(let a=t,s=t+i;a<s;a++){Br(p,3*a,h,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=e,n=e+r;t<n;t++){Br(d,3*t,l,c),d.needsUpdate=!0;const e=d.distanceToTriangle(p,f,g);if(e<y&&(m.copy(f),b&&b.copy(g),y=e,v=t,x=a),e<o)return!0}}}})}for(let i=0,a=kn(t);i<a;i++){Br(p,3*i,h,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=e,n=e+r;t<n;t++){Br(d,3*t,l,c),d.needsUpdate=!0;const e=d.distanceToTriangle(p,f,g);if(e<y&&(m.copy(f),b&&b.copy(g),y=e,v=t,x=i),e<o)return!0}}}}),br.releasePrimitive(d),br.releasePrimitive(p),y===1/0?null:(r.point?r.point.copy(m):r.point=m.clone(),r.distance=y,r.faceIndex=v,i&&(i.point?i.point.copy(b):i.point=b.clone(),i.point.applyMatrix4(ii),m.applyMatrix4(ii),i.distance=m.sub(i.point).length(),i.faceIndex=x),r)}function di(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));const n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position;let o,a,s,c,l=0;const u=e._roots;for(let e=0,t=u.length;e<t;e++)o=u[e],a=new Uint32Array(o),s=new Uint16Array(o),c=new Float32Array(o),h(0,l),l+=o.byteLength;function h(n,o,l=!1){const u=2*n;if(s[u+15]===An){const t=a[n+6];let o=1/0,l=1/0,h=1/0,d=-1/0,p=-1/0,f=-1/0;for(let n=t,a=t+s[u+14];n<a;n++){const t=3*e.resolveTriangleIndex(n);for(let e=0;e<3;e++){let n=t+e;n=r?r[n]:n;const a=i.getX(n),s=i.getY(n),c=i.getZ(n);a<o&&(o=a),a>d&&(d=a),s<l&&(l=s),s>p&&(p=s),c<h&&(h=c),c>f&&(f=c)}}return(c[n+0]!==o||c[n+1]!==l||c[n+2]!==h||c[n+3]!==d||c[n+4]!==p||c[n+5]!==f)&&(c[n+0]=o,c[n+1]=l,c[n+2]=h,c[n+3]=d,c[n+4]=p,c[n+5]=f,!0)}{const e=n+8,r=a[n+6],i=e+o,s=r+o;let u=l,d=!1,p=!1;t?u||(d=t.has(i),p=t.has(s),u=!d&&!p):(d=!0,p=!0);const f=u||p;let m=!1;(u||d)&&(m=h(e,o,u));let g=!1;f&&(g=h(r,o,u));const b=m||g;if(b)for(let t=0;t<3;t++){const i=e+t,o=r+t,a=c[i],s=c[i+3],l=c[o],u=c[o+3];c[n+t]=a<l?a:l,c[n+t+3]=s>u?s:u}return b}}}function pi(e,t,n,r,i,o,a){yr.setBuffer(e._roots[t]),fi(0,e,n,r,i,o,a),yr.clearBuffer()}function fi(e,t,n,r,i,o,a){const{float32Array:s,uint16Array:c,uint32Array:l}=yr,u=2*e;if(Wn(u,c)){!function(e,t,n,r,i,o,a,s){const{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)Ur(c,t,n,l?l[e]:e,o,a,s)}(t,n,r,Xn(e,l),qn(u,c),i,o,a)}else{const c=Yn(e);Vr(c,s,r,o,a)&&fi(c,t,n,r,i,o,a);const u=Kn(e,l);Vr(u,s,r,o,a)&&fi(u,t,n,r,i,o,a)}}const mi=["x","y","z"];function gi(e,t,n,r,i,o){yr.setBuffer(e._roots[t]);const a=bi(0,e,n,r,i,o);return yr.clearBuffer(),a}function bi(e,t,n,r,i,o){const{float32Array:a,uint16Array:s,uint32Array:c}=yr;let l=2*e;if(Wn(l,s)){return function(e,t,n,r,i,o,a){const{geometry:s,_indirectBuffer:c}=e;let l=1/0,u=null;for(let e=r,h=r+i;e<h;e++){let r;r=Ur(s,t,n,c?c[e]:e,null,o,a),r&&r.distance<l&&(u=r,l=r.distance)}return u}(t,n,r,Xn(e,c),qn(l,s),i,o)}{const s=Qn(e,c),l=mi[s],u=r.direction[l]>=0;let h,d;u?(h=Yn(e),d=Kn(e,c)):(h=Kn(e,c),d=Yn(e));const p=Vr(h,a,r,i,o)?bi(h,t,n,r,i,o):null;if(p){const e=p.point[l];if(u?e<=a[d+s]:e>=a[d+s+3])return p}const f=Vr(d,a,r,i,o)?bi(d,t,n,r,i,o):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const yi=new z,vi=new pr,xi=new pr,wi=new N,Ei=new fr,Ti=new fr;function Ai(e,t,n,r){yr.setBuffer(e._roots[t]);const i=Ci(0,e,n,r);return yr.clearBuffer(),i}function Ci(e,t,n,r,i=null){const{float32Array:o,uint16Array:a,uint32Array:s}=yr;let c=2*e;null===i&&(n.boundingBox||n.computeBoundingBox(),Ei.set(n.boundingBox.min,n.boundingBox.max,r),i=Ei);if(!Wn(c,a)){const a=e+8,c=s[e+6];Pn(a,o,yi);if(i.intersectsBox(yi)&&Ci(a,t,n,r,i))return!0;Pn(c,o,yi);return!!(i.intersectsBox(yi)&&Ci(c,t,n,r,i))}{const i=t.geometry,l=i.index,u=i.attributes.position,h=n.index,d=n.attributes.position,p=Xn(e,s),f=qn(c,a);if(wi.copy(r).invert(),n.boundsTree){Pn(e,o,Ti),Ti.matrix.copy(wi),Ti.needsUpdate=!0;const i=n.boundsTree.shapecast({intersectsBounds:e=>Ti.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let n=p,r=f+p;n<r;n++)if(Br(xi,3*t.resolveTriangleIndex(n),l,u),xi.needsUpdate=!0,e.intersectsTriangle(xi))return!0;return!1}});return i}for(let e=p,n=f+p;e<n;e++){const n=t.resolveTriangleIndex(e);Br(vi,3*n,l,u),vi.a.applyMatrix4(wi),vi.b.applyMatrix4(wi),vi.c.applyMatrix4(wi),vi.needsUpdate=!0;for(let e=0,t=h.count;e<t;e+=3)if(Br(xi,e,h,d),xi.needsUpdate=!0,vi.intersectsTriangle(xi))return!0}}}const Oi=new N,ki=new fr,Si=new fr,Mi=new f,Ri=new f,Ii=new f,Pi=new f;function _i(e,t,n,r={},i={},o=0,a=1/0){t.boundingBox||t.computeBoundingBox(),ki.set(t.boundingBox.min,t.boundingBox.max,n),ki.needsUpdate=!0;const s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,h=t.index,d=br.getPrimitive(),p=br.getPrimitive();let f=Mi,m=Ri,g=null,b=null;i&&(g=Ii,b=Pi);let y=1/0,v=null,x=null;return Oi.copy(n).invert(),Si.matrix.copy(Oi),e.shapecast({boundsTraverseOrder:e=>ki.distanceToBox(e),intersectsBounds:(e,t,n)=>n<y&&n<a&&(t&&(Si.min.copy(e.min),Si.max.copy(e.max),Si.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){const s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>Si.distanceToBox(e),intersectsBounds:(e,t,n)=>n<y&&n<a,intersectsRange:(t,a)=>{for(let w=t,E=t+a;w<E;w++){const t=s.resolveTriangleIndex(w);Br(p,3*t,h,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=r,n=r+i;t<n;t++){const n=e.resolveTriangleIndex(t);Br(d,3*n,l,c),d.needsUpdate=!0;const r=d.distanceToTriangle(p,f,g);if(r<y&&(m.copy(f),b&&b.copy(g),y=r,v=t,x=w),r<o)return!0}}}})}for(let a=0,s=kn(t);a<s;a++){Br(p,3*a,h,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=r,n=r+i;t<n;t++){const n=e.resolveTriangleIndex(t);Br(d,3*n,l,c),d.needsUpdate=!0;const r=d.distanceToTriangle(p,f,g);if(r<y&&(m.copy(f),b&&b.copy(g),y=r,v=t,x=a),r<o)return!0}}}}),br.releasePrimitive(d),br.releasePrimitive(p),y===1/0?null:(r.point?r.point.copy(m):r.point=m.clone(),r.distance=y,r.faceIndex=v,i&&(i.point?i.point.copy(b):i.point=b.clone(),i.point.applyMatrix4(Oi),m.applyMatrix4(Oi),i.distance=m.sub(i.point).length(),i.faceIndex=x),r)}const Ni=new yr.constructor,Li=new yr.constructor,Di=new mr(()=>new z),ji=new z,Fi=new z,Ui=new z,Bi=new z;let zi=!1;function Hi(e,t,n,r,i,o=0,a=0,s=0,c=0,l=null,u=!1){let h,d;u?(h=Li,d=Ni):(h=Ni,d=Li);const p=h.float32Array,f=h.uint32Array,m=h.uint16Array,g=d.float32Array,b=d.uint32Array,y=d.uint16Array,v=2*t,x=Wn(2*e,m),w=Wn(v,y);let E=!1;if(w&&x)E=u?i(Xn(t,b),qn(2*t,y),Xn(e,f),qn(2*e,m),c,a+t,s,o+e):i(Xn(e,f),qn(2*e,m),Xn(t,b),qn(2*t,y),s,o+e,c,a+t);else if(w){const l=Di.getPrimitive();Pn(t,g,l),l.applyMatrix4(n);const h=Yn(e),d=Kn(e,f);Pn(h,p,ji),Pn(d,p,Fi);const m=l.intersectsBox(ji),b=l.intersectsBox(Fi);E=m&&Hi(t,h,r,n,i,a,o,c,s+1,l,!u)||b&&Hi(t,d,r,n,i,a,o,c,s+1,l,!u),Di.releasePrimitive(l)}else{const h=Yn(t),d=Kn(t,b);Pn(h,g,Ui),Pn(d,g,Bi);const m=l.intersectsBox(Ui),y=l.intersectsBox(Bi);if(m&&y)E=Hi(e,h,n,r,i,o,a,s,c+1,l,u)||Hi(e,d,n,r,i,o,a,s,c+1,l,u);else if(m)if(x)E=Hi(e,h,n,r,i,o,a,s,c+1,l,u);else{const t=Di.getPrimitive();t.copy(Ui).applyMatrix4(n);const l=Yn(e),d=Kn(e,f);Pn(l,p,ji),Pn(d,p,Fi);const m=t.intersectsBox(ji),g=t.intersectsBox(Fi);E=m&&Hi(h,l,r,n,i,a,o,c,s+1,t,!u)||g&&Hi(h,d,r,n,i,a,o,c,s+1,t,!u),Di.releasePrimitive(t)}else if(y)if(x)E=Hi(e,d,n,r,i,o,a,s,c+1,l,u);else{const t=Di.getPrimitive();t.copy(Bi).applyMatrix4(n);const l=Yn(e),h=Kn(e,f);Pn(l,p,ji),Pn(h,p,Fi);const m=t.intersectsBox(ji),g=t.intersectsBox(Fi);E=m&&Hi(d,l,r,n,i,a,o,c,s+1,t,!u)||g&&Hi(d,h,r,n,i,a,o,c,s+1,t,!u),Di.releasePrimitive(t)}}return E}const Vi=new fr,Gi=new z,Wi={strategy:0,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Xi{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,r=e._roots,i=e._indirectBuffer,o=n.getIndex();let a;return a=t.cloneBuffers?{roots:r.map(e=>e.slice()),index:o?o.array.slice():null,indirectBuffer:i?i.slice():null}:{roots:r,index:o?o.array:null,indirectBuffer:i},a}static deserialize(e,t,n={}){n={setIndex:!0,indirect:Boolean(e.indirectBuffer),...n};const{index:r,roots:i,indirectBuffer:o}=e,a=new Xi(t,{...n,[On]:!0});if(a._roots=i,a._indirectBuffer=o||null,n.setIndex){const n=t.getIndex();if(null===n){const n=new j(e.index,1,!1);t.setIndex(n)}else n.array!==r&&(n.array.set(r),n.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(!e.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((t=Object.assign({...Wi,[On]:!1},t)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[On]||(sr(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new z))),this.resolveTriangleIndex=t.indirect?e=>this._indirectBuffer[e]:e=>e}refit(e=null){return(this.indirect?di:Hr)(this,e)}traverse(e,t=0){const n=this._roots[t],r=new Uint32Array(n),i=new Uint16Array(n);!function t(o,a=0){const s=2*o,c=i[s+15]===An;if(c){const t=r[o+6],l=i[s+14];e(a,c,new Float32Array(n,4*o,6),t,l)}else{const i=o+8,s=r[o+6],l=r[o+7];e(a,c,new Float32Array(n,4*o,6),l)||(t(i,a+1),t(s,a+1))}}(0)}raycast(e,t=G,n=0,r=1/0){const i=this._roots,o=this.geometry,a=[],s=t.isMaterial,c=Array.isArray(t),l=o.groups,u=s?t.side:t,h=this.indirect?pi:Wr;for(let o=0,s=i.length;o<s;o++){const i=c?t[l[o].materialIndex].side:u,s=a.length;if(h(this,o,i,e,a,n,r),c){const e=l[o].materialIndex;for(let t=s,n=a.length;t<n;t++)a[t].face.materialIndex=e}}return a}raycastFirst(e,t=G,n=0,r=1/0){const i=this._roots,o=this.geometry,a=t.isMaterial,s=Array.isArray(t);let c=null;const l=o.groups,u=a?t.side:t,h=this.indirect?gi:Yr;for(let o=0,a=i.length;o<a;o++){const i=h(this,o,s?t[l[o].materialIndex].side:u,e,n,r);null!=i&&(null==c||i.distance<c.distance)&&(c=i,s&&(i.face.materialIndex=l[o].materialIndex))}return c}intersectsGeometry(e,t){let n=!1;const r=this._roots,i=this.indirect?Ai:ni;for(let o=0,a=r.length;o<a&&(n=i(this,o,e,t),!n);o++);return n}shapecast(e){const t=br.getPrimitive(),n=this.indirect?Gr:zr;let{boundsTraverseOrder:r,intersectsBounds:i,intersectsRange:o,intersectsTriangle:a}=e;if(o&&a){const e=o;o=(r,i,o,s,c)=>!!e(r,i,o,s,c)||n(r,i,this,a,o,s,t)}else o||(o=a?(e,r,i,o)=>n(e,r,this,a,i,o,t):(e,t,n)=>n);let s=!1,c=0;const l=this._roots;for(let e=0,t=l.length;e<t;e++){const t=l[e];if(s=Tr(this,e,i,o,r,c),s)break;c+=t.byteLength}return br.releasePrimitive(t),s}bvhcast(e,t,n){let{intersectsRanges:r,intersectsTriangles:i}=n;const o=br.getPrimitive(),a=this.geometry.index,s=this.geometry.attributes.position,c=this.indirect?e=>{const t=this.resolveTriangleIndex(e);Br(o,3*t,a,s)}:e=>{Br(o,3*e,a,s)},l=br.getPrimitive(),u=e.geometry.index,h=e.geometry.attributes.position,d=e.indirect?t=>{const n=e.resolveTriangleIndex(t);Br(l,3*n,u,h)}:e=>{Br(l,3*e,u,h)};if(i){const e=(e,n,r,a,s,u,h,p)=>{for(let f=r,m=r+a;f<m;f++){d(f),l.a.applyMatrix4(t),l.b.applyMatrix4(t),l.c.applyMatrix4(t),l.needsUpdate=!0;for(let t=e,r=e+n;t<r;t++)if(c(t),o.needsUpdate=!0,i(o,l,t,f,s,u,h,p))return!0}return!1};if(r){const t=r;r=function(n,r,i,o,a,s,c,l){return!!t(n,r,i,o,a,s,c,l)||e(n,r,i,o,a,s,c,l)}}else r=e}return function(e,t,n,r){if(zi)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");zi=!0;const i=e._roots,o=t._roots;let a,s=0,c=0;const l=(new N).copy(n).invert();for(let e=0,t=i.length;e<t;e++){Ni.setBuffer(i[e]),c=0;const t=Di.getPrimitive();Pn($n(0),Ni.float32Array,t),t.applyMatrix4(l);for(let e=0,i=o.length;e<i&&(Li.setBuffer(o[e]),a=Hi(0,0,n,l,r,s,c,0,0,t),Li.clearBuffer(),c+=o[e].length,!a);e++);if(Di.releasePrimitive(t),Ni.clearBuffer(),s+=i[e].length,a)break}return zi=!1,a}(this,e,t,r)}intersectsBox(e,t){return Vi.set(e.min,e.max,t),Vi.needsUpdate=!0,this.shapecast({intersectsBounds:e=>Vi.intersectsBox(e),intersectsTriangle:e=>Vi.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},r={},i=0,o=1/0){return(this.indirect?_i:hi)(this,e,t,n,r,i,o)}closestPointToPoint(e,t={},n=0,r=1/0){return function(e,t,n={},r=0,i=1/0){const o=r*r,a=i*i;let s=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>(Cr.copy(t).clamp(e.min,e.max),Cr.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<a,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,Cr);const r=t.distanceToSquared(Cr);return r<s&&(Or.copy(Cr),s=r,c=n),r<o}}),s===1/0)return null;const l=Math.sqrt(s);return n.point?n.point.copy(Or):n.point=Or.clone(),n.distance=l,n.faceIndex=c,n}(this,e,t,n,r)}getBoundingBox(e){e.makeEmpty();return this._roots.forEach(t=>{Pn(0,new Float32Array(t),Gi),e.union(Gi)}),e}}function qi(e,t,n){return null===e?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(n.ray.origin),e.object=t,e)}const Yi=new u,Ki=new f,Qi=new N,$i=S.prototype.raycast,Zi=W.prototype.raycast,Ji=new f,eo=new S,to=[];function no(e,t){this.isBatchedMesh?ro.call(this,e,t):io.call(this,e,t)}function ro(e,t){if(this.boundsTrees){const n=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,o=this.matrixWorld;eo.material=this.material,eo.geometry=this.geometry;const a=eo.geometry.boundsTree,s=eo.geometry.drawRange;null===eo.geometry.boundingSphere&&(eo.geometry.boundingSphere=new B);for(let a=0,s=r.length;a<s;a++){if(!this.getVisibleAt(a))continue;const s=r[a].geometryIndex;if(eo.geometry.boundsTree=n[s],this.getMatrixAt(a,eo.matrixWorld).premultiply(o),!eo.geometry.boundsTree){this.getBoundingBoxAt(s,eo.geometry.boundingBox),this.getBoundingSphereAt(s,eo.geometry.boundingSphere);const e=i[s];eo.geometry.setDrawRange(e.start,e.count)}eo.raycast(e,to);for(let e=0,n=to.length;e<n;e++){const n=to[e];n.object=this,n.batchId=a,t.push(n)}to.length=0}eo.geometry.boundsTree=a,eo.geometry.drawRange=s,eo.material=null,eo.geometry=null}else Zi.call(this,e,t)}function io(e,t){if(this.geometry.boundsTree){if(void 0===this.material)return;Qi.copy(this.matrixWorld).invert(),Yi.copy(e.ray).applyMatrix4(Qi),Ji.setFromMatrixScale(this.matrixWorld),Ki.copy(Yi.direction).multiply(Ji);const n=Ki.length(),r=e.near/n,i=e.far/n,o=this.geometry.boundsTree;if(!0===e.firstHitOnly){const n=qi(o.raycastFirst(Yi,this.material,r,i),this,e);n&&t.push(n)}else{const n=o.raycast(Yi,this.material,r,i);for(let r=0,i=n.length;r<i;r++){const i=qi(n[r],this,e);i&&t.push(i)}}}else $i.call(this,e,t)}function oo(e={}){return this.boundsTree=new Xi(this,e),this.boundsTree}function ao(){this.boundsTree=null}e.BufferGeometry.prototype.computeBoundsTree=oo,e.BufferGeometry.prototype.disposeBoundsTree=ao,e.Mesh.prototype.raycast=no;class so extends e.Raycaster{constructor(){super(),this.bvhObjects=new Set}addBVH(e){e&&e.traverse(e=>{if(e.isMesh&&e.geometry&&!this.bvhObjects.has(e.uuid))try{e.geometry.attributes&&e.geometry.attributes.position&&(e.geometry.computeBoundsTree(),this.bvhObjects.add(e.uuid))}catch(e){console.warn("为对象添加BVH失败:",e)}})}updateBVH(e){e&&e.traverse(e=>{if(e.isMesh&&e.geometry)try{e.geometry.userData&&e.geometry.userData.needsBVHUpdate&&(e.geometry.boundsTree&&e.geometry.disposeBoundsTree(),e.geometry.computeBoundingBox(),e.geometry.computeBoundingSphere(),e.geometry.attributes&&e.geometry.attributes.position&&(e.geometry.computeBoundsTree(),console.log(`已更新对象 ${e.uuid} 的BVH`)),delete e.geometry.userData.needsBVHUpdate)}catch(e){console.warn("更新BVH失败:",e)}})}updateMultipleBVH(e){e&&0!==e.length&&e.forEach(e=>{this.updateBVH(e)})}removeBVH(e){e&&e.traverse(e=>{if(e.isMesh&&e.geometry&&this.bvhObjects.has(e.uuid))try{e.geometry.boundsTree&&e.geometry.disposeBoundsTree(),this.bvhObjects.delete(e.uuid)}catch(e){console.warn("移除BVH失败:",e)}})}clearAllBVH(){this.bvhObjects.forEach(e=>{}),this.bvhObjects.clear()}hasBVH(e){if(!e)return!1;let t=!1;return e.traverse(e=>{e.isMesh&&this.bvhObjects.has(e.uuid)&&(t=!0)}),t}}class co{constructor(){this.highlightedObjects=new Map,this.sharedOutlineMaterial=null}addHighlight(e,t=6974194,n=1.03){if(!e)return;if(Array.isArray(e))return void e.forEach(e=>{e&&this.addHighlight(e,t,n)});const r=e;if(r.userData.isSelected=!0,this.highlightedObjects.has(r.uuid))return void this.updateHighlightColor(r,t);this._processObjectRecursively(r,e=>{e.isMesh&&e.geometry&&(e.userData.highlighted=!0,this._createOutline(e,t,n))}),this.highlightedObjects.set(r.uuid,{object:r,color:t,scale:n})}removeHighlight(e){if(!e)return;this._processObjectRecursively(e,e=>{e.userData.outline&&(e.remove(e.userData.outline),e.userData.outline.material&&e.userData.outline.material!==this.sharedOutlineMaterial&&e.userData.outline.material.dispose(),e.userData.outline=null),e.userData.highlighted=!1,e.userData.isSelected=!1}),this.highlightedObjects.delete(e.uuid)}updateHighlightColor(e,t){if(!e||!this.highlightedObjects.has(e.uuid))return;this._processObjectRecursively(e,e=>{e.userData.outline&&e.userData.outline.material&&e.userData.outline.material.color.setHex(t)});const n=this.highlightedObjects.get(e.uuid);n&&(n.color=t)}updateDragHighlight(e,t){if(!e)return;this._processObjectRecursively(e,e=>{e.userData.outline&&e.userData.outline.material&&(t?void 0===e.userData.outline.userData.originalDragColor&&(e.userData.outline.userData.originalDragColor=e.userData.outline.material.color.getHex(),e.userData.outline.material.color.set(16777215)):void 0!==e.userData.outline.userData.originalDragColor&&(e.userData.outline.material.color.setHex(e.userData.outline.userData.originalDragColor),delete e.userData.outline.userData.originalDragColor))})}restoreDragColors(e){e&&0!==e.length&&e.forEach(e=>{this.updateDragHighlight(e,!1)})}updateHighlightTransform(e){if(!e||!this.highlightedObjects.has(e.uuid))return;const t=this.highlightedObjects.get(e.uuid),n=t?t.scale:1.03;this._processObjectRecursively(e,e=>{e.userData.outline&&(e.userData.outline.visible=e.visible,e.userData.outline.position.set(0,0,0),e.userData.outline.rotation.set(0,0,0),e.userData.outline.scale.set(n,n,n),e.userData.outline.updateMatrix(),e.userData.outline.updateMatrixWorld(!0))})}addMultipleHighlights(e,t=14964246){e.forEach(e=>this.addHighlight(e,t))}removeMultipleHighlights(e){e.forEach(e=>this.removeHighlight(e))}removeAllHighlights(){this.highlightedObjects.forEach(e=>{this.removeHighlight(e.object)}),this.highlightedObjects.clear()}clearAllHighlights(){this.highlightedObjects.forEach(e=>{this.removeHighlight(e.object)}),this.highlightedObjects.clear()}updateAllHighlights(){this.highlightedObjects.forEach(e=>{e.object.userData.highlighted&&this.updateHighlightTransform(e.object)})}scheduleUpdateHighlights(){this.batchUpdateTimer||(this.batchUpdateTimer=requestAnimationFrame(()=>{this.updateAllHighlights(),this.batchUpdateTimer=null}))}_createOutline(t,n,r){if(!t.geometry)return;const i=new e.MeshBasicMaterial({color:n,side:e.BackSide,transparent:!1,opacity:1}),o=new e.Mesh(t.geometry,i);o.scale.set(r,r,r),o.userData.isHidden=!0,o.userData.originalObject=t,o.matrixAutoUpdate=!0,o.renderOrder=-1,t.add(o),t.userData.outline=o}_processObjectRecursively(e,t){e&&(e.isMesh?t(e):(e.isGroup||e.isObject3D)&&e.children.forEach(e=>{(e.isMesh||e.isGroup||e.isObject3D)&&this._processObjectRecursively(e,t)}))}getHighlightCount(){return this.highlightedObjects.size}isHighlighted(e){return!!e&&this.highlightedObjects.has(e.uuid)}dispose(){this.clearAllHighlights(),this.sharedOutlineMaterial&&(this.sharedOutlineMaterial.dispose(),this.sharedOutlineMaterial=null),this.highlightedObjects.clear()}}class lo{constructor(e,t,n){this.container=e,this.sceneManager=t,this.objectManager=n,this.menuElement=null,this.isVisible=!1,this.selectedObjects=[],this.hideTimer=null,this.clipboard=null,this.hideDistance=50,this.distanceCheckTimer=null,this.mousePosition={x:0,y:0},this.createMenuElement(),this.bindEvents()}createMenuElement(){this.menuElement=document.createElement("div"),this.menuElement.className="context-menu",this.menuElement.style.cssText="\n position: absolute;\n min-width: 160px;\n\n color: var(--node-content-header-color);\n background: var(--node-content-background-color);\n border: 1px solid var(--node-border-color);\n\n box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);\n backdrop-filter: blur(16px);\n border-radius: 5px;\n z-index: 10000;\n display: none;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n user-select: none;\n opacity: 0;\n transform: translateY(-3px) scale(0.98);\n overflow: hidden;\n ";(this.container.parentElement||document.body).appendChild(this.menuElement)}bindEvents(){this.container.addEventListener("contextmenu",this.handleContextMenu.bind(this)),document.addEventListener("click",this.handleDocumentClick.bind(this)),document.addEventListener("mousemove",this.handleMouseMove.bind(this)),this.menuElement.addEventListener("mouseenter",this.handleMenuMouseEnter.bind(this)),this.menuElement.addEventListener("mouseleave",this.handleMenuMouseLeave.bind(this)),this.menuElement.addEventListener("click",e=>e.stopPropagation())}handleDocumentClick(e){this.menuElement&&this.menuElement.contains(e.target)||this.hideMenu()}handleMouseMove(e){this.mousePosition.x=e.clientX,this.mousePosition.y=e.clientY,this.isVisible&&this.menuElement&&this.checkDistanceAndHide()}checkDistanceAndHide(){if(!this.menuElement||!this.isVisible)return;const e=this.menuElement.getBoundingClientRect();this.getDistanceToRect(this.mousePosition,e)>this.hideDistance?this.hideTimer||(this.hideTimer=setTimeout(()=>{this.hideMenu()},200)):this.cancelHideTimer()}getDistanceToRect(e,t){const n=Math.max(t.left-e.x,0,e.x-t.right),r=Math.max(t.top-e.y,0,e.y-t.bottom);return Math.sqrt(n*n+r*r)}cancelHideTimer(){this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)}handleMenuMouseEnter(){this.cancelHideTimer()}handleMenuMouseLeave(){setTimeout(()=>{this.checkDistanceAndHide()},50)}handleContextMenu(e){e.preventDefault(),this.selectedObjects=this.objectManager.selectedObjects||[],0===this.selectedObjects.length?this.showSceneMenu(e.clientX,e.clientY):this.showObjectMenu(e.clientX,e.clientY)}getSVGIcon(e){return{copy:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/>\n </svg>',paste:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M19 2h-4.18C14.4.84 13.3 0 12 0c-1.3 0-2.4.84-2.82 2H5c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm7 18H5V4h2v3h10V4h2v16z"/>\n </svg>',delete:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/>\n </svg>',focus:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path d="M8.976 21C4.05476 21 3 19.9452 3 15.024" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>\n <path d="M21 15.024C21 19.9452 19.9452 21 15.024 21" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>\n <path d="M15.024 3C19.9452 3 21 4.05476 21 8.976" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>\n <path d="M3 8.976C3 4.05476 4.05476 3 8.976 3" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>\n <path d="M12 9.5L12 14.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M14.5 12L9.5 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',reset:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/>\n </svg>',camera:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M9 3L7.17 5H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2h-3.17L15 3H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z"/>\n </svg>',eye:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>\n </svg>',light:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M9 21c0 .5.4 1 1 1h4c.6 0 1-.5 1-1v-1H9v1zm3-19C8.1 2 5 5.1 5 9c0 2.4 1.2 4.5 3 5.7V17c0 .5.4 1 1 1h6c.6 0 1-.5 1-1v-2.3c1.8-1.3 3-3.4 3-5.7 0-3.9-3.1-7-7-7z"/>\n </svg>',lattice:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"/>\n </svg>',cube:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path d="M10 4L11.9505 3.02477C11.9816 3.00918 12.0184 3.00918 12.0495 3.02477V3.02477L14 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 11L11.1056 11.5528C11.6686 11.8343 12.3314 11.8343 12.8944 11.5528L14 11" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M12 12V14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M18.5 6.5L19.9441 7.46274V7.46274C19.979 7.48602 20 7.52521 20 7.56717V9.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M19.5 7.5L18 8.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M5.5 6.5L4.05048 7.46635V7.46635C4.01894 7.48737 4 7.52277 4 7.56067V9.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M4 7.5L5.5 8.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M4 14.5V16.4469C4 16.4801 4.01658 16.5111 4.04417 16.5294V16.5294L5.5 17.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 20L11.9516 20.9758C11.9821 20.991 12.0179 20.991 12.0484 20.9758V20.9758L14 20" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M12 21V18.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M18.5 17.5L19.9612 16.5258V16.5258C19.9855 16.5097 20 16.4825 20 16.4534V14.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',refresh:'<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">\n <path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/>\n </svg>'}[e]||""}showSceneMenu(e,t){const n=[{label:"粘贴",icon:"paste",action:()=>this.paste(),disabled:!this.hasClipboardData()},{type:"separator"},{label:"添加立方体",icon:"cube",action:()=>this.addCube()},{label:"重置视图",icon:"refresh",action:()=>this.resetView()}];this.showMenu(e,t,n)}showObjectMenu(e,t){const n=[],r=this.selectedObjects.length>1;n.push({label:r?"复制选中对象":"复制",icon:"copy",action:()=>this.copy()},{label:"粘贴",icon:"paste",action:()=>this.paste(),disabled:!this.hasClipboardData()},{label:r?"删除选中对象":"删除",icon:"delete",action:()=>this.delete()}),this.selectedObjects.length>0&&n.push({type:"separator"},{label:"聚焦对象",icon:"focus",action:()=>this.focusObject()},{label:"重置变换",icon:"reset",action:()=>this.resetTransform()});const i=this.selectedObjects.filter(e=>e.userData&&e.userData.isCameraHelper&&e.userData.parentCamera);i.length>0&&(n.push({type:"separator"},{label:"设置为活动相机",icon:"camera",action:()=>this.setActiveCamera(i[0])}),this.sceneManager.isInActiveCameraView()?n.push({label:"退出相机视角",icon:"reset",action:()=>this.exitCameraView()}):n.push({label:"切换到相机视角",icon:"eye",action:()=>this.switchToCameraView()}));const o=this.selectedObjects.filter(e=>e.userData&&e.userData.isLightHelper&&e.userData.parentLight);o.length>0&&n.push({type:"separator"},{label:"调整灯光强度",icon:"light",submenu:[{label:"增加强度",action:()=>this.adjustLightIntensity(o[0],.1)},{label:"减少强度",action:()=>this.adjustLightIntensity(o[0],-.1)},{label:"重置强度",action:()=>this.resetLightIntensity(o[0])}]});const a=this.selectedObjects.filter(e=>e.isMesh);if(a.length>0){const e=this.isObjectInLatticeMode(a[0]);n.push({type:"separator"},{label:e?"取消晶格":"创建晶格",icon:"lattice",action:()=>{e?this.exitLatticeGrid(a[0]):this.createLattice(a[0])}})}this.showMenu(e,t,n)}showMenu(e,t,n){this.menuElement.innerHTML="",n.forEach(e=>{if("separator"===e.type){const e=document.createElement("div");e.style.cssText="\n height: 1px;\n background: rgba(255, 255, 255, 0.03);\n margin: 0;\n ",this.menuElement.appendChild(e)}else{const t=this.createMenuItem(e);this.menuElement.appendChild(t)}}),this.menuElement.style.display="block",this.menuElement.style.visibility="hidden",this.menuElement.style.opacity="0";const r=this.menuElement.getBoundingClientRect(),i=this.container.getBoundingClientRect();let o=e-i.left-r.width/2,a=t-i.top-r.height/2;const s=10;o<s?o=s:o+r.width>i.width-s&&(o=i.width-r.width-s),a<s?a=s:a+r.height>i.height-s&&(a=i.height-r.height-s),this.menuElement.style.left=o+"px",this.menuElement.style.top=a+"px",this.menuElement.style.visibility="visible",this.menuElement.offsetHeight,this.menuElement.style.opacity="1",this.menuElement.style.transform="translateY(0) scale(1)",this.isVisible=!0,this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)}createMenuItem(e){const t=document.createElement("div");t.style.cssText=`\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 6px 10px;\n color: var(--node-content-header-color);\n opacity: ${e.disabled?"0.4":"0.82"};\n cursor: ${e.disabled?"not-allowed":"pointer"};\n transition: all 0.15s ease;\n font-size: 11px;\n font-weight: 500;\n border-bottom: 1px solid rgba(255, 255, 255, 0.03);\n position: relative;\n `;const n=this.getSVGIcon(e.icon);return t.innerHTML=`\n <span style="width: 14px; height: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">\n ${n}\n </span>\n <span style="flex: 1; font-weight: 500; font-size: 11px;">${e.label}</span>\n ${e.submenu?'<span style="font-size: 10px; color: var(--node-content-header-color); margin-left: auto; opacity: 0.6; transition: opacity 0.15s ease;">▶</span>':""}\n `,e.disabled||(t.addEventListener("mouseenter",()=>{t.style.backgroundColor="rgba(80, 90, 255, 0.18)",t.style.color="var(--node-content-header-color)",this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)}),t.addEventListener("mouseleave",()=>{t.style.backgroundColor="transparent",t.style.color="var(--node-content-header-color)"}),t.addEventListener("click",t=>{t.stopPropagation(),e.action&&e.action(),this.hideMenu()})),t}hideMenu(){this.menuElement&&this.isVisible&&(this.menuElement.style.opacity="0",this.menuElement.style.transform="translateY(-3px) scale(0.98)",setTimeout(()=>{this.menuElement.style.display="none",this.isVisible=!1},150)),this.cancelHideTimer(),this.distanceCheckTimer&&(clearTimeout(this.distanceCheckTimer),this.distanceCheckTimer=null)}copy(){if(0!==this.selectedObjects.length)try{this.clipboard=null,this.clipboard=this.selectedObjects.map(e=>this.cloneObjectData(e)),console.log(`已复制 ${this.selectedObjects.length} 个对象到剪贴板`)}catch(e){console.error("复制失败:",e)}}cloneObjectData(e){const t={type:e.type,name:e.name,position:e.position.clone(),rotation:e.rotation.clone(),scale:e.scale.clone(),visible:e.visible,userData:{...e.userData},originalObject:e};return e.isMesh&&(t.geometry=e.geometry,t.material=e.material),e.isLight&&(t.lightData={color:e.color.clone(),intensity:e.intensity,distance:e.distance,angle:e.angle,penumbra:e.penumbra,decay:e.decay}),e.isCamera&&(t.cameraData={fov:e.fov,aspect:e.aspect,near:e.near,far:e.far,zoom:e.zoom}),t}paste(){if(this.clipboard&&0!==this.clipboard.length)try{const t=[];this.clipboard.forEach(n=>{const r=this.createObjectFromData(n);r&&(r.position.add(new e.Vector3(1,0,1)),this.sceneManager.scene.add(r),t.push(r))}),t.length>0&&(this.sceneManager.addObjects(t),this.objectManager.clearSelection(),t.forEach(e=>{this.objectManager.selectedObjects.push(e),this.objectManager.outlineManager.addHighlight(e,6974194)}),t.length>0&&this.objectManager._attachTransformToMultipleObjects(t),this.objectManager.onSelectionChange&&this.objectManager.onSelectionChange(this.objectManager.selectedObjects)),this.clipboard=null}catch(e){console.error("粘贴失败:",e)}}createObjectFromData(t){let n=null;try{switch(t.type){case"Mesh":n=this.createMesh(t);break;case"DirectionalLight":n=this.createDirectionalLight(t);break;case"PointLight":n=this.createPointLight(t);break;case"SpotLight":n=this.createSpotLight(t);break;case"PerspectiveCamera":n=this.createPerspectiveCamera(t);break;case"OrthographicCamera":n=this.createOrthographicCamera(t);break;case"Group":n=this.createGroup(t);break;default:if(!t.originalObject||!t.originalObject.clone)return console.warn(`不支持的对象类型: ${t.type}`),null;n=t.originalObject.clone()}n&&(n.name=t.name+"_copy",n.position.copy(t.position),n.rotation.copy(t.rotation),n.scale.copy(t.scale),n.visible=t.visible,n.userData={selectable:!1!==t.userData.selectable,id:e.MathUtils.generateUUID()})}catch(e){return console.error("创建对象失败:",e),null}return n}createMesh(t){if(!t.geometry||!t.material)return console.warn("网格对象缺少几何体或材质"),null;const n=t.geometry.clone();let r;r=Array.isArray(t.material)?t.material.map(e=>e.clone()):t.material.clone();const i=new e.Mesh(n,r);return i.castShadow=t.originalObject.castShadow,i.receiveShadow=t.originalObject.receiveShadow,i}createDirectionalLight(t){const n=new e.DirectionalLight(t.lightData.color,t.lightData.intensity);return t.originalObject.castShadow&&(n.castShadow=!0,n.shadow.mapSize.copy(t.originalObject.shadow.mapSize),n.shadow.camera.copy(t.originalObject.shadow.camera)),n}createPointLight(t){const n=new e.PointLight(t.lightData.color,t.lightData.intensity,t.lightData.distance,t.lightData.decay);return t.originalObject.castShadow&&(n.castShadow=!0,n.shadow.mapSize.copy(t.originalObject.shadow.mapSize)),n}createSpotLight(t){const n=new e.SpotLight(t.lightData.color,t.lightData.intensity,t.lightData.distance,t.lightData.angle,t.lightData.penumbra,t.lightData.decay);return t.originalObject.castShadow&&(n.castShadow=!0,n.shadow.mapSize.copy(t.originalObject.shadow.mapSize)),n}createPerspectiveCamera(t){const n=new e.PerspectiveCamera(t.cameraData.fov,t.cameraData.aspect,t.cameraData.near,t.cameraData.far);return n.zoom=t.cameraData.zoom,n}createOrthographicCamera(t){const n=t.originalObject,r=new e.OrthographicCamera(n.left,n.right,n.top,n.bottom,t.cameraData.near,t.cameraData.far);return r.zoom=t.cameraData.zoom,r}createGroup(t){const n=new e.Group;return t.originalObject.children&&t.originalObject.children.length>0&&t.originalObject.children.forEach(e=>{const t=this.cloneObjectData(e),r=this.createObjectFromData(t);r&&n.add(r)}),n}hasClipboardData(){return this.clipboard&&this.clipboard.length>0}delete(){0!==this.selectedObjects.length&&this.sceneManager.deleteSelectedObjects()}focusObject(){this.sceneManager.focusSelectedObject()||console.error("聚焦失败")}resetTransform(){this.selectedObjects.forEach(e=>{e.position.set(0,0,0),e.rotation.set(0,0,0),e.scale.set(1,1,1),e.updateMatrix(),e.updateMatrixWorld(!0)})}setActiveCamera(e){if(e.userData&&e.userData.parentCamera){this.sceneManager.setActiveCamera(e.userData.parentCamera)||console.error("设置活动相机失败")}}switchToCameraView(){this.sceneManager.switchToActiveCameraView()||console.error("切换失败")}exitCameraView(){this.sceneManager.switchToMainCameraView()||console.error("退出失败")}adjustLightIntensity(e,t){if(e.userData&&e.userData.parentLight){const n=e.userData.parentLight;n.intensity,n.intensity=Math.max(0,n.intensity+t)}}resetLightIntensity(e){if(e.userData&&e.userData.parentLight){e.userData.parentLight.intensity=1}}isObjectInLatticeMode(e){return!(!e||!e.isMesh)&&(!(!e.userData||!e.userData.isLatticeMode)||(!(!e.userData||!e.userData.latticeHelper)||!!e.material&&(Array.isArray(e.material)?e.material.some(e=>e.wireframe):e.material.wireframe)))}createLattice(e){e&&e.isMesh&&(e.userData||(e.userData={}),e.userData.isLatticeMode=!0,this.sceneManager.createLattice(e))}exitLatticeGrid(e){if(e&&e.isMesh)try{e.userData&&(e.userData.isLatticeMode=!1,e.userData.latticeHelper&&(this.sceneManager.scene.remove(e.userData.latticeHelper),e.userData.latticeHelper.geometry&&e.userData.latticeHelper.geometry.dispose(),e.userData.latticeHelper.material&&e.userData.latticeHelper.material.dispose(),delete e.userData.latticeHelper)),e.material&&(Array.isArray(e.material)?e.material.forEach(e=>{e.wireframe&&(e.wireframe=!1)}):e.material.wireframe&&(e.material.wireframe=!1)),this.sceneManager.exitLatticeGrid&&this.sceneManager.exitLatticeGrid(e),console.log("已取消晶格模式")}catch(e){console.error("取消晶格失败:",e)}}addCube(){this.sceneManager.addCube()}resetView(){this.objectManager.orbitControls&&this.objectManager.orbitControls.reset()}dispose(){this.clipboard=null,this.cancelHideTimer(),this.distanceCheckTimer&&(clearTimeout(this.distanceCheckTimer),this.distanceCheckTimer=null),this.container.removeEventListener("contextmenu",this.handleContextMenu.bind(this)),document.removeEventListener("click",this.handleDocumentClick.bind(this)),document.removeEventListener("mousemove",this.handleMouseMove.bind(this)),this.menuElement&&(this.menuElement.removeEventListener("mouseenter",this.handleMenuMouseEnter.bind(this)),this.menuElement.removeEventListener("mouseleave",this.handleMenuMouseLeave.bind(this)),this.menuElement.parentElement&&this.menuElement.parentElement.removeChild(this.menuElement)),this.menuElement=null}}const uo={move:'<svg viewBox="0 0 24 24" width="24" height="24" fill="white" xmlns="http://www.w3.org/2000/svg">\n <path d="M12 2L16.2426 6.24264L14.8284 7.65685L12 4.82843L9.17157 7.65685L7.75736 6.24264L12 2ZM2 12L6.24264 7.75736L7.65685 9.17157L4.82843 12L7.65685 14.8284L6.24264 16.2426L2 12ZM22 12L17.7574 16.2426L16.3431 14.8284L19.1716 12L16.3431 9.17157L17.7574 7.75736L22 12ZM12 14C10.8954 14 10 13.1046 10 12C10 10.8954 10.8954 10 12 10C13.1046 10 14 10.8954 14 12C14 13.1046 13.1046 14 12 14ZM12 22L7.75736 17.7574L9.17157 16.3431L12 19.1716L14.8284 16.3431L16.2426 17.7574L12 22Z"></path>\n </svg>',rotate:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>\n <path d="M18 9l3 3l-3 3"></path>\n <path d="M15 12h6"></path>\n <path d="M6 9l-3 3l3 3"></path>\n <path d="M3 12h6"></path>\n</svg>',scale:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>\n <path d="M9 18l3 3l3 -3"></path>\n <path d="M12 15v6"></path>\n <path d="M15 6l-3 -3l-3 3"></path>\n <path d="M12 3v6"></path>\n</svg>'};class ho extends e.Object3D{constructor(){super(),this.isSelectionProxy=!0,this.type="SelectionProxy",this.targetObjects=[],this.initialMatrices=new Map,this.initialPositions=new Map,this.initialRotations=new Map,this.initialScales=new Map,this.initialRelativePositions=new Map,this._tempVector=new e.Vector3,this._tempBox=new e.Box3,this.initialProxyPosition=new e.Vector3,this.initialProxyQuaternion=new e.Quaternion,this.initialProxyScale=new e.Vector3(1,1,1)}setTargets(e){this._clearData(),e&&0!==e.length&&(this.targetObjects=e.filter(e=>e&&e.visible),this._updateProxyCenter(),this._saveInitialStates())}_clearData(){this.targetObjects=[],[this.initialMatrices,this.initialPositions,this.initialRotations,this.initialScales,this.initialRelativePositions].forEach(e=>e.clear())}_updateProxyCenter(){if(0===this.targetObjects.length)return;const t=new e.Box3;t.makeEmpty(),this.targetObjects.forEach(n=>{let r;if(n.updateMatrixWorld(!0),n.geometry)n.geometry.boundingBox||n.geometry.computeBoundingBox(),r=n.geometry.boundingBox.clone(),r.applyMatrix4(n.matrixWorld);else{r=new e.Box3;const t=new e.Vector3;n.getWorldPosition(t),r.expandByPoint(t)}t.union(r)});const n=new e.Vector3;t.getCenter(n),this.position.copy(n),this.quaternion.identity(),this.scale.set(1,1,1),this.updateMatrix(),this.updateMatrixWorld(!0)}_saveInitialStates(){this.initialProxyPosition.copy(this.position),this.initialProxyQuaternion.copy(this.quaternion),this.initialProxyScale.copy(this.scale),this.updateMatrixWorld(!0);const t=new e.Vector3;this.getWorldPosition(t),this.targetObjects.forEach(n=>{n.updateMatrixWorld(!0);const r=n.uuid;this.initialMatrices.set(r,n.matrixWorld.clone()),this.initialPositions.set(r,n.position.clone()),this.initialRotations.set(r,n.quaternion.clone()),this.initialScales.set(r,n.scale.clone());const i=new e.Vector3;n.getWorldPosition(i);const o=i.sub(t);this.initialRelativePositions.set(r,o)})}applyTransformToTargets(){if(0===this.targetObjects.length)return;this.updateMatrixWorld(!0),new e.Matrix4;const t=new e.Vector3,n=new e.Quaternion,r=new e.Vector3,i=new e.Vector3,o=new e.Vector3,a=new e.Matrix4;this.getWorldPosition(i),this.targetObjects.forEach(e=>{const s=e.uuid,c=this.initialRelativePositions.get(s);if(!c)return;o.copy(c),o.applyQuaternion(this.quaternion),o.multiply(this.scale),o.add(i),e.parent?(e.parent.updateWorldMatrix(!0,!1),a.copy(e.parent.matrixWorld).invert(),t.copy(o),t.applyMatrix4(a),e.position.copy(t)):e.position.copy(o);const l=this.initialRotations.get(s),u=this.initialScales.get(s);l&&u&&(n.copy(l),e.quaternion.copy(n),e.quaternion.premultiply(this.quaternion),r.copy(u),r.multiply(this.scale),e.scale.copy(r)),e.updateMatrix(),e.updateMatrixWorld(!0)})}dispose(){this._clearData()}}class po{constructor(t,n,r,i=null,o=null,a=null){this.scene=t,this.camera=n,this.domElement=r,this.onObjectsChanged=i,this.onSelectionChange=o,this.onTransformChange=a,this.reusableVector=new e.Vector3,this.reusableBox3=new e.Box3,this.isBaned=!1,this.selectableObjects=[],this.selectedObjects=[],this.isSelecting=!1,this.selectStartPosition={x:0,y:0},this.selectEndPosition={x:0,y:0},this.isMouseDown=!1,this.transforming=!1,this.selectionGroup=null,this.highlightColor=new e.Color(3355647),this._initSelectionBox(),this._initControls(),this.raycaster=new so,this.pointer=new e.Vector2,this._addEventListeners(),this.outlineManager=new co,this.contextMenu=null}setSceneManager(e){this.sceneManager=e,this.contextMenu||(this.contextMenu=new lo(this.domElement,e,this))}_initSelectionBox(){this.selectionBoxElement=document.createElement("div"),this.selectionBoxElement.className="selection-box",this.selectionBoxElement.style.cssText="\n position: absolute; border: 2px dashed #646cff;\n pointer-events: none; display: none; z-index: 1; transform-origin: top left;\n will-change: transform, width, height; top: 0; left: 0;\n ";const e=this.domElement.parentElement||this.domElement;this.domElement.parentElement?e.appendChild(this.selectionBoxElement):this.domElement.insertAdjacentElement("afterend",this.selectionBoxElement)}_initControls(){this.orbitControls=new Vt(this.camera,this.domElement),this.orbitControls.enableDamping=!1,this.transformControls=new Jt(this.camera,this.domElement),Object.assign(this.transformControls,{size:.5,translationSnap:0,rotationSnap:null,scaleSnap:null,mode:"translate",space:"world",sensitivity:2}),this.transformControls.userData.renderThrottle=1,this.transformControls.userData.frameCount=0;const e=this.transformControls._gizmo.children[0].children;this.transformControls._gizmo.children[0].children=e.filter((e,t)=>![1,4,7].includes(t)),this.selectionProxy=new ho,this.scene.add(this.selectionProxy),this.transformControls.addEventListener("dragging-changed",this._onTransformDragging.bind(this)),this.transformControls.addEventListener("change",this._onTransformChange.bind(this)),this.transformControls.addEventListener("mouseenter",this._onTransformMouseEnter.bind(this)),this.transformControls.addEventListener("mouseleave",this._onTransformMouseLeave.bind(this)),this.transformMode="translate",this.scene.add(this.transformControls),this._initCursorStyles()}_initCursorStyles(){this.cursorStyles={move:this._createCursorFromSVG(uo.move),rotate:this._createCursorFromSVG(uo.rotate),scale:this._createCursorFromSVG(uo.scale)},this.defaultCursor=this.domElement.style.cursor||"default"}_createCursorFromSVG(e){const t=document.createElement("div");t.innerHTML=e;const n=t.querySelector("svg");if(!n)return"default";n.setAttribute("width","24"),n.setAttribute("height","24");const r=(new XMLSerializer).serializeToString(n);return`url("${`data:image/svg+xml,${encodeURIComponent(r)}`}") 12 12, auto`}_onTransformMouseEnter(){this._updateCursorStyle()}_onTransformMouseLeave(){this.transforming||this._resetCursorStyle()}_updateCursorStyle(){const e={translate:"move",rotate:"rotate",scale:"scale"}[this.transformMode];e&&this.cursorStyles[e]&&(this.domElement.style.cursor=this.cursorStyles[e])}_resetCursorStyle(){this.domElement.style.cursor=this.defaultCursor}_onTransformChange(){this.transforming&&this.selectionProxy.targetObjects.length>0&&(this.selectionProxy.applyTransformToTargets(),this.selectedObjects.forEach(e=>this._updateObjectHighlight(e))),this.selectedObjects.forEach(e=>{this._updateHelperTarget(e)})}_updateHelperTarget(e){e&&e.userData&&(e.userData.isLightHelper&&e.userData.updateLight&&e.userData.updateLight(),e.userData.isCameraHelper&&e.userData.updateCamera&&this.transforming&&e.userData.updateCamera())}_onTransformDragging(e){this.orbitControls.enabled=!e.value,this.transforming=e.value,e.value?(this._updateCursorStyle(),this._recordInitialTransformState()):(this._resetCursorStyle(),this._recordTransformHistory(),this.selectionProxy.targetObjects.length>0&&(this.selectionProxy.setTargets(this.selectedObjects),this.selectedObjects.forEach(e=>{this._updateObjectHighlight(e),this._updateHelperTarget(e)}))),this.selectedObjects.forEach(t=>this._updateHighlightColorForDrag(t,e.value))}_recordTransformHistory(){if(!this.initialTransformState||0===this.initialTransformState.length)return;const e=this.scene.userData.sceneManager;if(!e)return void console.warn("无法找到场景管理器,无法记录变换历史");let t=!1;const n=this.selectedObjects.map(e=>{const n=this.initialTransformState.find(t=>t.object===e);return!n||e.position.equals(n.position)&&e.quaternion.equals(n.quaternion)&&e.scale.equals(n.scale)||(t=!0),{object:e,position:e.position.clone(),rotation:e.rotation.clone(),quaternion:e.quaternion.clone(),scale:e.scale.clone(),matrix:e.matrix.clone()}});if(!t)return void(this.initialTransformState=null);const r={type:"TRANSFORM",data:{initialState:[...this.initialTransformState],finalState:[...n]},undo:()=>this._applyTransformState(r.data.initialState),redo:()=>this._applyTransformState(r.data.finalState)};e.addActionToHistory(r),this.initialTransformState=null}_applyTransformState(e){e&&e.forEach(e=>{e&&e.object&&(e.object.position.copy(e.position),e.object.quaternion.copy(e.quaternion),e.object.scale.copy(e.scale),e.object.updateMatrix(),e.object.updateMatrixWorld(!0))})}_recordInitialTransformState(){this.selectedObjects&&0!==this.selectedObjects.length?this.initialTransformState=this.selectedObjects.map(e=>e?{object:e,position:e.position.clone(),rotation:e.rotation.clone(),quaternion:e.quaternion.clone(),scale:e.scale.clone(),matrix:e.matrix.clone()}:null).filter(Boolean):this.initialTransformState=null}_updateHighlightColorForDrag(e,t){this.outlineManager.updateDragHighlight(e,t)}_updateObjectHighlight(e){this.outlineManager.updateHighlightTransform(e)}_addEventListeners(){const e=[this._onPointerDown,this._onPointerMove,this._onPointerUp];["pointerdown","pointermove","pointerup"].forEach((t,n)=>{this.domElement.addEventListener(t,e[n].bind(this))}),window.addEventListener("keydown",this._onKeyDown.bind(this))}removeEventListeners(){const e=[this._onPointerDown,this._onPointerMove,this._onPointerUp];["pointerdown","pointermove","pointerup"].forEach((t,n)=>{this.domElement.removeEventListener(t,e[n].bind(this))}),window.removeEventListener("keydown",this._onKeyDown.bind(this))}_onKeyDown(e){const t={g:"translate",r:"rotate",s:"scale"}[e.key.toLowerCase()];t&&this.setTransformMode(t)}setTransformMode(e){["translate","rotate","scale"].includes(e)&&(this.transformControls.setMode(e),this.transformMode=e,(this.transformControls.dragging||this.transforming)&&this._updateCursorStyle(),this.onTransformChange&&this.onTransformChange(e))}getTransformMode(){return this.transformMode}_updateSelectionBox(){if(!this.isSelecting)return void(this.selectionBoxElement.style.display="none");const e=this.domElement.parentElement.getBoundingClientRect(),t=Math.min(this.selectStartPosition.x,this.selectEndPosition.x)-e.left,n=Math.min(this.selectStartPosition.y,this.selectEndPosition.y)-e.top,r=Math.abs(this.selectEndPosition.x-this.selectStartPosition.x),i=Math.abs(this.selectEndPosition.y-this.selectStartPosition.y);Object.assign(this.selectionBoxElement.style,{display:"block",transform:`translate(${t}px, ${n}px)`,width:`${r}px`,height:`${i}px`})}_onPointerDown(e){if(this.isBaned||0!==e.button||this.transforming)return;e.preventDefault(),this.isMouseDown=!0;const t=this.domElement.getBoundingClientRect();this.pointer.x=(e.clientX-t.left)/t.width*2-1,this.pointer.y=-(e.clientY-t.top)/t.height*2+1,this.selectStartPosition={x:e.clientX,y:e.clientY},this.raycaster.setFromCamera(this.pointer,this.camera);const n=this.raycaster.intersectObjects(this.selectableObjects,!0);if(n.length>0){const t=n[0].object;this._ensureObjectUserData(t);const r=this._findSelectableParent(t);r&&this._handleObjectSelection(r,e.shiftKey)}else e.shiftKey||this._clearSelectionAndTransforms()}_findSelectableParent(e){if(!e)return null;let t=e;for(;t;){if(this._ensureObjectUserData(t),!0===t.userData.selectable)return t;if(t=t.parent,t===this.scene)break}return null}_ensureObjectUserData(e){e.userData||(e.userData={}),void 0===e.userData.selectable&&(e.userData.selectable=!0)}_handleObjectSelection(e,t){if(e&&!1!==e.userData.selectable){if(t)this._toggleObjectSelection(e);else{if(this.clearSelection(),this.outlineManager.addHighlight(e,6974194),this.selectedObjects.push(e),this._removeSelectionGroup(),e.userData&&e.userData.isCameraHelper&&e.userData.parentCamera){const t=e.userData.parentCamera;t.updateMatrixWorld(!0),e.updateMatrixWorld(!0),e.position.copy(t.position),e.quaternion.copy(t.quaternion),e.updateMatrix(),e.updateMatrixWorld(!0)}this.transformControls.attach(e)}this.onSelectionChange&&this.onSelectionChange(this.selectedObjects)}}_toggleObjectSelection(e){const t=this.selectedObjects.indexOf(e);-1!==t?(this.outlineManager.removeHighlight(e),this.selectedObjects.splice(t,1),0===t&&this.selectedObjects.length>0&&this.outlineManager.updateHighlightColor(this.selectedObjects[0],14964246)):(this.selectedObjects.push(e),1===this.selectedObjects.length?this.outlineManager.addHighlight(e,14964246):(this.outlineManager.addHighlight(e,6974194),this.outlineManager.updateHighlightColor(this.selectedObjects[0],14964246))),this.selectedObjects.length>0?this._attachTransformToMultipleObjects(this.selectedObjects):this._clearSelectionAndTransforms()}_clearSelectionAndTransforms(){this.clearSelection(),this.transformControls.detach(),this._removeSelectionGroup(),this.onSelectionChange&&this.onSelectionChange(this.selectedObjects)}_removeSelectionGroup(){this.selectionGroup&&(this.scene.remove(this.selectionGroup),this.selectionGroup=null)}_onPointerMove(e){if(this.isBaned||1!==e.buttons||this.transforming||!this.isMouseDown)return;this.selectEndPosition={x:e.clientX,y:e.clientY};Math.sqrt(Math.pow(this.selectEndPosition.x-this.selectStartPosition.x,2)+Math.pow(this.selectEndPosition.y-this.selectStartPosition.y,2))>10&&(this.isSelecting=!0,this._updateSelectionBox())}_onPointerUp(e){if(!this.isBaned&&0===e.button&&!this.transforming&&this.isMouseDown&&(this.isMouseDown=!1,this.isSelecting)){const t=this.domElement.getBoundingClientRect(),n={startX:(this.selectStartPosition.x-t.left)/t.width*2-1,startY:-(this.selectStartPosition.y-t.top)/t.height*2+1,endX:(this.selectEndPosition.x-t.left)/t.width*2-1,endY:-(this.selectEndPosition.y-t.top)/t.height*2+1};e.shiftKey||(this.clearSelection(),this.transformControls.detach()),this._selectObjectsInBox(n),this.isSelecting=!1,this._updateSelectionBox(),this.onSelectionChange&&this.onSelectionChange(this.selectedObjects)}}_selectObjectsInBox(e){const[t,n,r,i]=[Math.min(e.startX,e.endX),Math.max(e.startX,e.endX),Math.min(e.startY,e.endY),Math.max(e.startY,e.endY)],o=this.reusableVector,a=new Set,s=[];for(let e=0;e<this.selectableObjects.length;e++){const c=this.selectableObjects[e];if(c.visible){if(c.updateMatrixWorld(!0),o.setFromMatrixPosition(c.matrixWorld),o.project(this.camera),this._isInSelectionBox(o,t,n,r,i)&&-1===this.selectedObjects.indexOf(c)){const e=this._findSelectableParent(c);e&&-1===s.indexOf(e)&&(s.push(e),this.selectedObjects.push(e));continue}this._checkChildrenInSelectionBox(c,t,n,r,i,o,a,s)}}s.length>0&&(this.selectedObjects.length===s.length?(this.outlineManager.addHighlight(s[0],6974194),s.length>1&&this.outlineManager.addMultipleHighlights(s.slice(1),14964246)):(this.outlineManager.addMultipleHighlights(s,14964246),this.selectedObjects.length>0&&this.outlineManager.updateHighlightColor(this.selectedObjects[0],6974194))),this.selectedObjects.length>0&&this._attachTransformToMultipleObjects(this.selectedObjects)}_isInSelectionBox(e,t,n,r,i){return e.x>=t&&e.x<=n&&e.y>=r&&e.y<=i}_checkChildrenInSelectionBox(e,t,n,r,i,o,a,s){e.children&&0!==e.children.length&&e.visible&&(e.uuid&&a.has(e.uuid)||(e.uuid&&a.add(e.uuid),e.children.forEach(e=>{if(e.visible){if(e.isObject3D&&(e.updateMatrixWorld(!0),o.setFromMatrixPosition(e.matrixWorld),o.project(this.camera),this._isInSelectionBox(o,t,n,r,i)&&-1===this.selectedObjects.indexOf(e))){const t=this._findSelectableParent(e);t&&-1===s.indexOf(t)&&(s.push(t),this.selectedObjects.push(t))}this._checkChildrenInSelectionBox(e,t,n,r,i,o,a,s)}})))}addObjects(e){console.log(e,"objects");(Array.isArray(e)?e:[e]).forEach(e=>this._addSelectableObject(e))}_addSelectableObject(e){if(console.log(e,"添加可选择对象"),e.userData||(e.userData={}),void 0===e.userData.selectable&&(e.userData.selectable=!0),e.isMesh&&e.material?Array.isArray(e.material)?e.userData.originalColors=e.material.map(e=>e.color?e.color.getHex():16777215):e.material.color?e.userData.originalColor=e.material.color.getHex():e.userData.originalColor=16777215:e.userData.originalColor=16777215,!0===e.userData.selectable&&-1===this.selectableObjects.indexOf(e)){if(this.selectableObjects.push(e),e.geometry||e.isObject3D)try{this.raycaster.addBVH(e)}catch(e){console.warn("添加BVH失败:",e)}this.onObjectsChanged&&this.onObjectsChanged(this.selectableObjects)}}removeSelectableObjects(e){this.clearSelection();(Array.isArray(e)?e:[e]).forEach(e=>this._removeSelectableObject(e))}_removeSelectableObject(e){if(e){if(this._removeObjectFromSelectables(e),e.userData){if(e.userData.isLightHelper&&e.userData.parentLight){const t=e.userData.parentLight;t.parent&&t.parent.remove(t)}if(e.userData.isCameraHelper&&e.userData.parentCamera){const t=e.userData.parentCamera;t.parent&&t.parent.remove(t)}}if(e.isGroup||e.children&&e.children.length>0){[...e.children].forEach(e=>{this._removeObjectFromSelectables(e)})}e.parent?e.parent.remove(e):this.scene.remove(e),this._cleanupInvalidSelectedObjects(),this._disposeObject(e)}}_removeObjectFromSelectables(e){const t=this.selectableObjects.indexOf(e);if(-1!==t&&(this.selectableObjects.splice(t,1),e.geometry))try{this.raycaster.removeBVH(e)}catch(e){console.warn("移除BVH失败:",e)}const n=this.selectedObjects.indexOf(e);-1!==n&&(this.outlineManager.removeHighlight(e),this.selectedObjects.splice(n,1),this.selectedObjects.length>0?this._attachTransformToMultipleObjects(this.selectedObjects):(this.transformControls.detach(),this._removeSelectionGroup()),this.onSelectionChange&&this.onSelectionChange(this.selectedObjects))}_disposeObject(e){if(e.geometry&&e.geometry.dispose(),e.material){(Array.isArray(e.material)?e.material:[e.material]).forEach(e=>{e.map&&e.map.dispose(),e.dispose()})}e.dispose&&"function"==typeof e.dispose&&e.dispose()}clearSelection(){this.transformControls.detach(),this.selectionProxy&&this.selectionProxy.dispose(),this.outlineManager.removeMultipleHighlights(this.selectedObjects),this.selectedObjects.length=0}_isObjectInSceneGraph(e){if(!e)return!1;let t=e;for(;t.parent;)if(t=t.parent,t===this.scene)return!0;return this.scene.children.includes(e)}_cleanupInvalidSelectedObjects(){const e=this.selectedObjects.filter(e=>this._isObjectInSceneGraph(e));e.length!==this.selectedObjects.length&&(this.selectedObjects.forEach(e=>{this._isObjectInSceneGraph(e)||this.outlineManager.removeHighlight(e)}),this.selectedObjects=e,0===this.selectedObjects.length?this._clearSelectionAndTransforms():this._attachTransformToMultipleObjects(this.selectedObjects),this.onSelectionChange&&this.onSelectionChange(this.selectedObjects))}_attachTransformToMultipleObjects(e){if(!e||0===e.length)return;const t=e.filter(e=>this._isObjectInSceneGraph(e));if(0!==t.length)if(1!==t.length){this._isObjectInSceneGraph(this.selectionProxy)||this.scene.add(this.selectionProxy);try{this.selectionProxy.setTargets(t),this.transformControls.attach(this.selectionProxy)}catch(e){console.warn("无法附加变换控制器到选择代理:",e),this.transformControls.detach()}}else try{this.transformControls.attach(t[0])}catch(e){console.warn("无法附加变换控制器到对象:",e),this.transformControls.detach()}else this.transformControls.detach()}update(){if(this.selectedObjects.length>0&&this._cleanupInvalidSelectedObjects(),this.transformControls&&this.transforming){const e=this.transformControls.userData.renderThrottle||1;this.transformControls.userData.frameCount=(this.transformControls.userData.frameCount||0)+1,this.transformControls.userData.frameCount%e===0&&this.transformControls.updateMatrixWorld(!0)}this.selectedObjects.length>0&&this.outlineManager.updateAllHighlights()}dispose(){this.removeEventListeners(),this._resetCursorStyle();try{this.transformControls.detach()}catch(e){console.warn("销毁时分离变换控制器失败:",e)}this.clearSelection(),this.selectionBoxElement&&this.selectionBoxElement.parentElement&&this.selectionBoxElement.parentElement.removeChild(this.selectionBoxElement),this.selectionBoxElement=null,this.selectionProxy&&(this.selectionProxy.dispose(),this.scene.remove(this.selectionProxy),this.selectionProxy=null),this.selectableObjects.length=0,this.selectedObjects.length=0,this.transformControls&&(this.transformControls.dispose(),this.scene.remove(this.transformControls)),this.orbitControls&&this.orbitControls.dispose(),this.outlineManager&&(this.outlineManager.dispose(),this.outlineManager=null),this.contextMenu&&(this.contextMenu.dispose(),this.contextMenu=null),this.reusableVector=null,this.reusableBox3=null,this.onSelectionChange=null,this.onTransformChange=null}updateDeformedObjects(e){if(!e||0===e.length)return;const t=[];e.forEach(e=>{e&&e.geometry&&this.selectableObjects.includes(e)&&e.geometry.userData&&e.geometry.userData.needsBVHUpdate&&t.push(e)}),t.length>0&&(console.log(`正在更新 ${t.length} 个对象的BVH`),this.raycaster.updateMultipleBVH(t)),this.updateSelectionProxyIfNeeded()}updateSelectionProxyIfNeeded(){this.selectedObjects.length>1&&this.transformControls.object===this.selectionProxy&&this.selectionProxy.targetObjects.length>0&&(this.selectionProxy.setTargets(this.selectedObjects),this.selectedObjects.forEach(e=>{this._updateObjectHighlight(e)}))}refreshSelectionProxy(){this.updateSelectionProxyIfNeeded()}}const fo=new WeakMap;class mo extends X{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,n,r){const i=new q(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,e=>{this.parse(e,t,r)},n,r)}parse(e,t,n=()=>{}){this.decodeDracoFile(e,t,null,null,Y).catch(n)}decodeDracoFile(e,t,n,r,i=o,a=()=>{}){const s={attributeIDs:n||this.defaultAttributeIDs,attributeTypes:r||this.defaultAttributeTypes,useUniqueIDs:!!n,vertexColorSpace:i};return this.decodeGeometry(e,s).then(t).catch(a)}decodeGeometry(e,t){const n=JSON.stringify(t);if(fo.has(e)){const t=fo.get(e);if(t.key===n)return t.promise;if(0===e.byteLength)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let r;const i=this.workerNextTaskID++,o=e.byteLength,a=this._getWorker(i,o).then(n=>(r=n,new Promise((n,o)=>{r._callbacks[i]={resolve:n,reject:o},r.postMessage({type:"decode",id:i,taskConfig:t,buffer:e},[e])}))).then(e=>this._createGeometry(e.geometry));return a.catch(()=>!0).then(()=>{r&&i&&this._releaseTask(r,i)}),fo.set(e,{key:n,promise:a}),a}_createGeometry(e){const t=new O;e.index&&t.setIndex(new j(e.index.array,1));for(let n=0;n<e.attributes.length;n++){const r=e.attributes[n],i=r.name,o=r.array,a=r.itemSize,s=new j(o,a);"color"===i&&(this._assignVertexColorSpace(s,r.vertexColorSpace),s.normalized=o instanceof Float32Array==!1),t.setAttribute(i,s)}return t}_assignVertexColorSpace(e,t){if(t!==Y)return;const n=new K;for(let t=0,r=e.count;t<r;t++)n.fromBufferAttribute(e,t).convertSRGBToLinear(),e.setXYZ(t,n.r,n.g,n.b)}_loadLibrary(e,t){const n=new q(this.manager);return n.setPath(this.decoderPath),n.setResponseType(t),n.setWithCredentials(this.withCredentials),new Promise((t,r)=>{n.load(e,t,void 0,r)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e="object"!=typeof WebAssembly||"js"===this.decoderConfig.type,t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(t=>{const n=t[0];e||(this.decoderConfig.wasmBinary=t[1]);const r=go.toString(),i=["/* draco decoder */",n,"","/* worker */",r.substring(r.indexOf("{")+1,r.lastIndexOf("}"))].join("\n");this.workerSourceURL=URL.createObjectURL(new Blob([i]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.length<this.workerLimit){const e=new Worker(this.workerSourceURL);e._callbacks={},e._taskCosts={},e._taskLoad=0,e.postMessage({type:"init",decoderConfig:this.decoderConfig}),e.onmessage=function(t){const n=t.data;switch(n.type){case"decode":e._callbacks[n.id].resolve(n);break;case"error":e._callbacks[n.id].reject(n);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+n.type+'"')}},this.workerPool.push(e)}else this.workerPool.sort(function(e,t){return e._taskLoad>t._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,""!==this.workerSourceURL&&URL.revokeObjectURL(this.workerSourceURL),this}}function go(){let e,t;function n(e,t,n,r,i,o){const a=o.num_components(),s=n.num_points()*a,c=s*i.BYTES_PER_ELEMENT,l=function(e,t){switch(t){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32}}(e,i),u=e._malloc(c);t.GetAttributeDataArrayForAllPoints(n,o,l,c,u);const h=new i(e.HEAPF32.buffer,u,s).slice();return e._free(u),{name:r,array:h,itemSize:a}}onmessage=function(r){const i=r.data;switch(i.type){case"init":e=i.decoderConfig,t=new Promise(function(t){e.onModuleLoaded=function(e){t({draco:e})},DracoDecoderModule(e)});break;case"decode":const r=i.buffer,o=i.taskConfig;t.then(e=>{const t=e.draco,a=new t.Decoder;try{const e=function(e,t,r,i){const o=i.attributeIDs,a=i.attributeTypes;let s,c;const l=t.GetEncodedGeometryType(r);if(l===e.TRIANGULAR_MESH)s=new e.Mesh,c=t.DecodeArrayToMesh(r,r.byteLength,s);else{if(l!==e.POINT_CLOUD)throw new Error("THREE.DRACOLoader: Unexpected geometry type.");s=new e.PointCloud,c=t.DecodeArrayToPointCloud(r,r.byteLength,s)}if(!c.ok()||0===s.ptr)throw new Error("THREE.DRACOLoader: Decoding failed: "+c.error_msg());const u={index:null,attributes:[]};for(const r in o){const c=self[a[r]];let l,h;if(i.useUniqueIDs)h=o[r],l=t.GetAttributeByUniqueId(s,h);else{if(h=t.GetAttributeId(s,e[o[r]]),-1===h)continue;l=t.GetAttribute(s,h)}const d=n(e,t,s,r,c,l);"color"===r&&(d.vertexColorSpace=i.vertexColorSpace),u.attributes.push(d)}l===e.TRIANGULAR_MESH&&(u.index=function(e,t,n){const r=n.num_faces(),i=3*r,o=4*i,a=e._malloc(o);t.GetTrianglesUInt32Array(n,o,a);const s=new Uint32Array(e.HEAPF32.buffer,a,i).slice();return e._free(a),{array:s,itemSize:1}}(e,t,s));return e.destroy(s),u}(t,a,new Int8Array(r),o),s=e.attributes.map(e=>e.array.buffer);e.index&&s.push(e.index.array.buffer),self.postMessage({type:"decode",id:i.id,geometry:e},s)}catch(e){console.error(e),self.postMessage({type:"error",id:i.id,error:e.message})}finally{t.destroy(a)}})}}}function bo(e,t){if(t===Q)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t===$||t===Z){let n=e.getIndex();if(null===n){const t=[],r=e.getAttribute("position");if(void 0===r)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}const r=n.count-2,i=[];if(t===$)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));i.length/3!==r&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const o=e.clone();return o.setIndex(i),o.clearGroups(),o}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e}class yo extends X{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new Ao(e)}),this.register(function(e){return new _o(e)}),this.register(function(e){return new No(e)}),this.register(function(e){return new Lo(e)}),this.register(function(e){return new Oo(e)}),this.register(function(e){return new ko(e)}),this.register(function(e){return new So(e)}),this.register(function(e){return new Mo(e)}),this.register(function(e){return new To(e)}),this.register(function(e){return new Ro(e)}),this.register(function(e){return new Co(e)}),this.register(function(e){return new Po(e)}),this.register(function(e){return new Io(e)}),this.register(function(e){return new wo(e)}),this.register(function(e){return new Do(e)}),this.register(function(e){return new jo(e)})}load(e,t,n,r){const i=this;let o;if(""!==this.resourcePath)o=this.resourcePath;else if(""!==this.path){const t=J.extractUrlBase(e);o=J.resolveURL(t,this.path)}else o=J.extractUrlBase(e);this.manager.itemStart(e);const a=function(t){r?r(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},s=new q(this.manager);s.setPath(this.path),s.setResponseType("arraybuffer"),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,function(n){try{i.parse(n,o,function(n){t(n),i.manager.itemEnd(e)},a)}catch(e){a(e)}},n,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i;const o={},a={},s=new TextDecoder;if("string"==typeof e)i=JSON.parse(e);else if(e instanceof ArrayBuffer){if(s.decode(new Uint8Array(e,0,4))===Fo){try{o[xo.KHR_BINARY_GLTF]=new zo(e)}catch(e){return void(r&&r(e))}i=JSON.parse(o[xo.KHR_BINARY_GLTF].content)}else i=JSON.parse(s.decode(e))}else i=e;if(void 0===i.asset||i.asset.version[0]<2)return void(r&&r(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const c=new pa(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](c);t.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[t.name]=t,o[t.name]=!0}if(i.extensionsUsed)for(let e=0;e<i.extensionsUsed.length;++e){const t=i.extensionsUsed[e],n=i.extensionsRequired||[];switch(t){case xo.KHR_MATERIALS_UNLIT:o[t]=new Eo;break;case xo.KHR_DRACO_MESH_COMPRESSION:o[t]=new Ho(i,this.dracoLoader);break;case xo.KHR_TEXTURE_TRANSFORM:o[t]=new Vo;break;case xo.KHR_MESH_QUANTIZATION:o[t]=new Go;break;default:n.indexOf(t)>=0&&void 0===a[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}c.setExtensions(o),c.setPlugins(a),c.parse(n,r)}parseAsync(e,t){const n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}}function vo(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const xo={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class wo{constructor(e){this.parser=e,this.name=xo.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){const r=t[n];r.extensions&&r.extensions[this.name]&&void 0!==r.extensions[this.name].light&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){const t=this.parser,n="light:"+e;let r=t.cache.get(n);if(r)return r;const i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let s;const c=new K(16777215);void 0!==a.color&&c.setRGB(a.color[0],a.color[1],a.color[2],o);const l=void 0!==a.range?a.range:0;switch(a.type){case"directional":s=new re(c),s.target.position.set(0,0,-1),s.add(s.target);break;case"point":s=new ne(c),s.distance=l;break;case"spot":s=new te(c),s.distance=l,a.spot=a.spot||{},a.spot.innerConeAngle=void 0!==a.spot.innerConeAngle?a.spot.innerConeAngle:0,a.spot.outerConeAngle=void 0!==a.spot.outerConeAngle?a.spot.outerConeAngle:Math.PI/4,s.angle=a.spot.outerConeAngle,s.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,s.target.position.set(0,0,-1),s.add(s.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return s.position.set(0,0,0),s.decay=2,sa(s,a),void 0!==a.intensity&&(s.intensity=a.intensity),s.name=t.createUniqueName(a.name||"light_"+e),r=Promise.resolve(s),t.cache.add(n,r),r}getDependency(e,t){if("light"===e)return this._loadLight(t)}createNodeAttachment(e){const t=this,n=this.parser,r=n.json.nodes[e],i=(r.extensions&&r.extensions[this.name]||{}).light;return void 0===i?null:this._loadLight(i).then(function(e){return n._getNodeRef(t.cache,i,e)})}}class Eo{constructor(){this.name=xo.KHR_MATERIALS_UNLIT}getMaterialType(){return E}extendParams(e,t,n){const r=[];e.color=new K(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const t=i.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],o),e.opacity=t[3]}void 0!==i.baseColorTexture&&r.push(n.assignTexture(e,"map",i.baseColorTexture,Y))}return Promise.all(r)}}class To{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=n.extensions[this.name].emissiveStrength;return void 0!==r&&(t.emissiveIntensity=r),Promise.resolve()}}class Ao{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];if(void 0!==o.clearcoatFactor&&(t.clearcoat=o.clearcoatFactor),void 0!==o.clearcoatTexture&&i.push(n.assignTexture(t,"clearcoatMap",o.clearcoatTexture)),void 0!==o.clearcoatRoughnessFactor&&(t.clearcoatRoughness=o.clearcoatRoughnessFactor),void 0!==o.clearcoatRoughnessTexture&&i.push(n.assignTexture(t,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),void 0!==o.clearcoatNormalTexture&&(i.push(n.assignTexture(t,"clearcoatNormalMap",o.clearcoatNormalTexture)),void 0!==o.clearcoatNormalTexture.scale)){const e=o.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new v(e,e)}return Promise.all(i)}}class Co{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];return void 0!==o.iridescenceFactor&&(t.iridescence=o.iridescenceFactor),void 0!==o.iridescenceTexture&&i.push(n.assignTexture(t,"iridescenceMap",o.iridescenceTexture)),void 0!==o.iridescenceIor&&(t.iridescenceIOR=o.iridescenceIor),void 0===t.iridescenceThicknessRange&&(t.iridescenceThicknessRange=[100,400]),void 0!==o.iridescenceThicknessMinimum&&(t.iridescenceThicknessRange[0]=o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&(t.iridescenceThicknessRange[1]=o.iridescenceThicknessMaximum),void 0!==o.iridescenceThicknessTexture&&i.push(n.assignTexture(t,"iridescenceThicknessMap",o.iridescenceThicknessTexture)),Promise.all(i)}}class Oo{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_SHEEN}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[];t.sheenColor=new K(0,0,0),t.sheenRoughness=0,t.sheen=1;const a=r.extensions[this.name];if(void 0!==a.sheenColorFactor){const e=a.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],o)}return void 0!==a.sheenRoughnessFactor&&(t.sheenRoughness=a.sheenRoughnessFactor),void 0!==a.sheenColorTexture&&i.push(n.assignTexture(t,"sheenColorMap",a.sheenColorTexture,Y)),void 0!==a.sheenRoughnessTexture&&i.push(n.assignTexture(t,"sheenRoughnessMap",a.sheenRoughnessTexture)),Promise.all(i)}}class ko{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&i.push(n.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(i)}}class So{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_VOLUME}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],a=r.extensions[this.name];t.thickness=void 0!==a.thicknessFactor?a.thicknessFactor:0,void 0!==a.thicknessTexture&&i.push(n.assignTexture(t,"thicknessMap",a.thicknessTexture)),t.attenuationDistance=a.attenuationDistance||1/0;const s=a.attenuationColor||[1,1,1];return t.attenuationColor=(new K).setRGB(s[0],s[1],s[2],o),Promise.all(i)}}class Mo{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_IOR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=n.extensions[this.name];return t.ior=void 0!==r.ior?r.ior:1.5,Promise.resolve()}}class Ro{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_SPECULAR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],a=r.extensions[this.name];t.specularIntensity=void 0!==a.specularFactor?a.specularFactor:1,void 0!==a.specularTexture&&i.push(n.assignTexture(t,"specularIntensityMap",a.specularTexture));const s=a.specularColorFactor||[1,1,1];return t.specularColor=(new K).setRGB(s[0],s[1],s[2],o),void 0!==a.specularColorTexture&&i.push(n.assignTexture(t,"specularColorMap",a.specularColorTexture,Y)),Promise.all(i)}}class Io{constructor(e){this.parser=e,this.name=xo.EXT_MATERIALS_BUMP}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];return t.bumpScale=void 0!==o.bumpFactor?o.bumpFactor:1,void 0!==o.bumpTexture&&i.push(n.assignTexture(t,"bumpMap",o.bumpTexture)),Promise.all(i)}}class Po{constructor(e){this.parser=e,this.name=xo.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?ee:null}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];return void 0!==o.anisotropyStrength&&(t.anisotropy=o.anisotropyStrength),void 0!==o.anisotropyRotation&&(t.anisotropyRotation=o.anisotropyRotation),void 0!==o.anisotropyTexture&&i.push(n.assignTexture(t,"anisotropyMap",o.anisotropyTexture)),Promise.all(i)}}class _o{constructor(e){this.parser=e,this.name=xo.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;const i=r.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,o)}}class No{constructor(e){this.parser=e,this.name=xo.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],a=r.images[o.source];let s=n.textureLoader;if(a.uri){const e=n.options.manager.getHandler(a.uri);null!==e&&(s=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,s);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class Lo{constructor(e){this.parser=e,this.name=xo.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],a=r.images[o.source];let s=n.textureLoader;if(a.uri){const e=n.options.manager.getHandler(a.uri);null!==e&&(s=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,s);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class Do{constructor(e){this.name=xo.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){const e=n.extensions[this.name],r=this.parser.getDependency("buffer",e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return r.then(function(t){const n=e.byteOffset||0,r=e.byteLength||0,o=e.count,a=e.byteStride,s=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(o,a,s,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){const t=new ArrayBuffer(o*a);return i.decodeGltfBuffer(new Uint8Array(t),o,a,s,e.mode,e.filter),t})})}return null}}class jo{constructor(e){this.name=xo.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||void 0===n.mesh)return null;const r=t.meshes[n.mesh];for(const e of r.primitives)if(e.mode!==Yo.TRIANGLES&&e.mode!==Yo.TRIANGLE_STRIP&&e.mode!==Yo.TRIANGLE_FAN&&void 0!==e.mode)return null;const i=n.extensions[this.name].attributes,o=[],a={};for(const e in i)o.push(this.parser.getDependency("accessor",i[e]).then(t=>(a[e]=t,a[e])));return o.length<1?null:(o.push(this.parser.createNodeMesh(e)),Promise.all(o).then(e=>{const t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(const e of n){const t=new N,n=new f,o=new y,s=new f(1,1,1),c=new ie(e.geometry,e.material,r);for(let e=0;e<r;e++)a.TRANSLATION&&n.fromBufferAttribute(a.TRANSLATION,e),a.ROTATION&&o.fromBufferAttribute(a.ROTATION,e),a.SCALE&&s.fromBufferAttribute(a.SCALE,e),c.setMatrixAt(e,t.compose(n,o,s));for(const t in a)if("_COLOR_0"===t){const e=a[t];c.instanceColor=new oe(e.array,e.itemSize,e.normalized)}else"TRANSLATION"!==t&&"ROTATION"!==t&&"SCALE"!==t&&e.geometry.setAttribute(t,a[t]);x.prototype.copy.call(c,e),this.parser.assignFinalMaterial(c),i.push(c)}return t.isGroup?(t.clear(),t.add(...i),t):i[0]}))}}const Fo="glTF",Uo=1313821514,Bo=5130562;class zo{constructor(e){this.name=xo.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,12),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==Fo)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-12,i=new DataView(e,12);let o=0;for(;o<r;){const t=i.getUint32(o,!0);o+=4;const r=i.getUint32(o,!0);if(o+=4,r===Uo){const r=new Uint8Array(e,12+o,t);this.content=n.decode(r)}else if(r===Bo){const n=12+o;this.body=e.slice(n,n+t)}o+=t}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Ho{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=xo.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,s={},c={},l={};for(const e in a){const t=Jo[e]||e.toLowerCase();s[t]=a[e]}for(const t in e.attributes){const r=Jo[t]||t.toLowerCase();if(void 0!==a[t]){const i=n.accessors[e.attributes[t]],o=Ko[i.componentType];l[r]=o.name,c[r]=!0===i.normalized}}return t.getDependency("bufferView",i).then(function(e){return new Promise(function(t,n){r.decodeDracoFile(e,function(e){for(const t in e.attributes){const n=e.attributes[t],r=c[t];void 0!==r&&(n.normalized=r)}t(e)},s,l,o,n)})})}}class Vo{constructor(){this.name=xo.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&t.texCoord!==e.channel||void 0!==t.offset||void 0!==t.rotation||void 0!==t.scale?(e=e.clone(),void 0!==t.texCoord&&(e.channel=t.texCoord),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e):e}}class Go{constructor(){this.name=xo.KHR_MESH_QUANTIZATION}}class Wo extends Ue{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){const t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r*3+r;for(let e=0;e!==r;e++)t[e]=n[i+e];return t}interpolate_(e,t,n,r){const i=this.resultBuffer,o=this.sampleValues,a=this.valueSize,s=2*a,c=3*a,l=r-t,u=(n-t)/l,h=u*u,d=h*u,p=e*c,f=p-c,m=-2*d+3*h,g=d-h,b=1-m,y=g-h+u;for(let e=0;e!==a;e++){const t=o[f+e+a],n=o[f+e+s]*l,r=o[p+e+a],c=o[p+e]*l;i[e]=b*t+y*n+m*r+g*c}return i}}const Xo=new y;class qo extends Wo{interpolate_(e,t,n,r){const i=super.interpolate_(e,t,n,r);return Xo.fromArray(i).normalize().toArray(i),i}}const Yo={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Ko={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Qo={9728:fe,9729:c,9984:pe,9985:de,9986:he,9987:ue},$o={33071:be,33648:ge,10497:me},Zo={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Jo={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},ea={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},ta={CUBICSPLINE:void 0,LINEAR:_e,STEP:Pe},na="OPAQUE",ra="MASK",ia="BLEND";function oa(e){return void 0===e.DefaultMaterial&&(e.DefaultMaterial=new xe({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:G})),e.DefaultMaterial}function aa(e,t,n){for(const r in n.extensions)void 0===e[r]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=n.extensions[r])}function sa(e,t){void 0!==t.extras&&("object"==typeof t.extras?Object.assign(e.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function ca(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let n=0,r=t.weights.length;n<r;n++)e.morphTargetInfluences[n]=t.weights[n];if(t.extras&&Array.isArray(t.extras.targetNames)){const n=t.extras.targetNames;if(e.morphTargetInfluences.length===n.length){e.morphTargetDictionary={};for(let t=0,r=n.length;t<r;t++)e.morphTargetDictionary[n[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function la(e){let t;const n=e.extensions&&e.extensions[xo.KHR_DRACO_MESH_COMPRESSION];if(t=n?"draco:"+n.bufferView+":"+n.indices+":"+ua(n.attributes):e.indices+":"+ua(e.attributes)+":"+e.mode,void 0!==e.targets)for(let n=0,r=e.targets.length;n<r;n++)t+=":"+ua(e.targets[n]);return t}function ua(e){let t="";const n=Object.keys(e).sort();for(let r=0,i=n.length;r<i;r++)t+=n[r]+":"+e[n[r]]+";";return t}function ha(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}const da=new N;class pa{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new vo,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=!1,i=-1;"undefined"!=typeof navigator&&(n=!0===/^((?!chrome|android).)*safari/i.test(navigator.userAgent),r=navigator.userAgent.indexOf("Firefox")>-1,i=r?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),"undefined"==typeof createImageBitmap||n||r&&i<98?this.textureLoader=new ae(this.options.manager):this.textureLoader=new se(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new q(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(t){const o={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return aa(i,o,r),sa(o,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(o)})).then(function(){e(o)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n<r;n++){const r=t[n].joints;for(let t=0,n=r.length;t<n;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){const r=e[t];void 0!==r.mesh&&(this._addNodeRef(this.meshCache,r.mesh),void 0!==r.skin&&(n[r.mesh].isSkinnedMesh=!0)),void 0!==r.camera&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;const r=n.clone(),i=(e,t)=>{const n=this.associations.get(e);null!=n&&this.associations.set(t,n);for(const[n,r]of e.children.entries())i(r,t.children[n])};return i(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){const r=e(t[n]);if(r)return r}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const n=[];for(let r=0;r<t.length;r++){const i=e(t[r]);i&&n.push(i)}return n}getDependency(e,t){const n=e+":"+t;let r=this.cache.get(n);if(!r){switch(e){case"scene":r=this.loadScene(t);break;case"node":r=this._invokeOne(function(e){return e.loadNode&&e.loadNode(t)});break;case"mesh":r=this._invokeOne(function(e){return e.loadMesh&&e.loadMesh(t)});break;case"accessor":r=this.loadAccessor(t);break;case"bufferView":r=this._invokeOne(function(e){return e.loadBufferView&&e.loadBufferView(t)});break;case"buffer":r=this.loadBuffer(t);break;case"material":r=this._invokeOne(function(e){return e.loadMaterial&&e.loadMaterial(t)});break;case"texture":r=this._invokeOne(function(e){return e.loadTexture&&e.loadTexture(t)});break;case"skin":r=this.loadSkin(t);break;case"animation":r=this._invokeOne(function(e){return e.loadAnimation&&e.loadAnimation(t)});break;case"camera":r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!r)throw new Error("Unknown type: "+e)}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){const n=this,r=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(r.map(function(t,r){return n.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],n=this.fileLoader;if(t.type&&"arraybuffer"!==t.type)throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(void 0===t.uri&&0===e)return Promise.resolve(this.extensions[xo.KHR_BINARY_GLTF].body);const r=this.options;return new Promise(function(e,i){n.load(J.resolveURL(t.uri,r.path),e,void 0,function(){i(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(e){const n=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+n)})}loadAccessor(e){const t=this,n=this.json,r=this.json.accessors[e];if(void 0===r.bufferView&&void 0===r.sparse){const e=Zo[r.type],t=Ko[r.componentType],n=!0===r.normalized,i=new t(r.count*e);return Promise.resolve(new j(i,e,n))}const i=[];return void 0!==r.bufferView?i.push(this.getDependency("bufferView",r.bufferView)):i.push(null),void 0!==r.sparse&&(i.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(i).then(function(e){const i=e[0],o=Zo[r.type],a=Ko[r.componentType],s=a.BYTES_PER_ELEMENT,c=s*o,l=r.byteOffset||0,u=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,h=!0===r.normalized;let d,p;if(u&&u!==c){const e=Math.floor(l/u),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+e+":"+r.count;let c=t.cache.get(n);c||(d=new a(i,e*u,r.count*u/s),c=new ce(d,u/s),t.cache.add(n,c)),p=new le(c,o,l%u/s,h)}else d=null===i?new a(r.count*o):new a(i,l,r.count*o),p=new j(d,o,h);if(void 0!==r.sparse){const t=Zo.SCALAR,n=Ko[r.sparse.indices.componentType],s=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,l=new n(e[1],s,r.sparse.count*t),u=new a(e[2],c,r.sparse.count*o);null!==i&&(p=new j(p.array.slice(),p.itemSize,p.normalized));for(let e=0,t=l.length;e<t;e++){const t=l[e];if(p.setX(t,u[e*o]),o>=2&&p.setY(t,u[e*o+1]),o>=3&&p.setZ(t,u[e*o+2]),o>=4&&p.setW(t,u[e*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return p})}loadTexture(e){const t=this.json,n=this.options,r=t.textures[e].source,i=t.images[r];let o=this.textureLoader;if(i.uri){const e=n.manager.getHandler(i.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(e,t,n){const r=this,i=this.json,o=i.textures[e],a=i.images[t],s=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[s])return this.textureCache[s];const l=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=o.name||a.name||"",""===t.name&&"string"==typeof a.uri&&!1===a.uri.startsWith("data:image/")&&(t.name=a.uri);const n=(i.samplers||{})[o.sampler]||{};return t.magFilter=Qo[n.magFilter]||c,t.minFilter=Qo[n.minFilter]||ue,t.wrapS=$o[n.wrapS]||me,t.wrapT=$o[n.wrapT]||me,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[s]=l,l}loadImageSource(e,t){const n=this,r=this.json,i=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());const o=r.images[e],a=self.URL||self.webkitURL;let s=o.uri||"",c=!1;if(void 0!==o.bufferView)s=n.getDependency("bufferView",o.bufferView).then(function(e){c=!0;const t=new Blob([e],{type:o.mimeType});return s=a.createObjectURL(t),s});else if(void 0===o.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const l=Promise.resolve(s).then(function(e){return new Promise(function(n,r){let o=n;!0===t.isImageBitmapLoader&&(o=function(e){const t=new Ne(e);t.needsUpdate=!0,n(t)}),t.load(J.resolveURL(e,i.path),o,void 0,r)})}).then(function(e){var t;return!0===c&&a.revokeObjectURL(s),e.userData.mimeType=o.mimeType||((t=o.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){const i=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(void 0!==n.texCoord&&n.texCoord>0&&((o=o.clone()).channel=n.texCoord),i.extensions[xo.KHR_TEXTURE_TRANSFORM]){const e=void 0!==n.extensions?n.extensions[xo.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=i.associations.get(o);o=i.extensions[xo.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),i.associations.set(o,t)}}return void 0!==r&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let n=e.material;const r=void 0===t.attributes.tangent,i=void 0!==t.attributes.color,o=void 0===t.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+n.uuid;let t=this.cache.get(e);t||(t=new ye,ve.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){const e="LineBasicMaterial:"+n.uuid;let t=this.cache.get(e);t||(t=new T,ve.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||o){let e="ClonedMaterial:"+n.uuid+":";r&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),o&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return xe}loadMaterial(e){const t=this,n=this.json,r=this.extensions,i=n.materials[e];let a;const s={},c=[];if((i.extensions||{})[xo.KHR_MATERIALS_UNLIT]){const e=r[xo.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),c.push(e.extendParams(s,i,t))}else{const n=i.pbrMetallicRoughness||{};if(s.color=new K(1,1,1),s.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;s.color.setRGB(e[0],e[1],e[2],o),s.opacity=e[3]}void 0!==n.baseColorTexture&&c.push(t.assignTexture(s,"map",n.baseColorTexture,Y)),s.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,s.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(c.push(t.assignTexture(s,"metalnessMap",n.metallicRoughnessTexture)),c.push(t.assignTexture(s,"roughnessMap",n.metallicRoughnessTexture))),a=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,s)})))}!0===i.doubleSided&&(s.side=D);const l=i.alphaMode||na;if(l===ia?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,l===ra&&(s.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&a!==E&&(c.push(t.assignTexture(s,"normalMap",i.normalTexture)),s.normalScale=new v(1,1),void 0!==i.normalTexture.scale)){const e=i.normalTexture.scale;s.normalScale.set(e,e)}if(void 0!==i.occlusionTexture&&a!==E&&(c.push(t.assignTexture(s,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(s.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&a!==E){const e=i.emissiveFactor;s.emissive=(new K).setRGB(e[0],e[1],e[2],o)}return void 0!==i.emissiveTexture&&a!==E&&c.push(t.assignTexture(s,"emissiveMap",i.emissiveTexture,Y)),Promise.all(c).then(function(){const n=new a(s);return i.name&&(n.name=i.name),sa(n,i),t.associations.set(n,{materials:e}),i.extensions&&aa(r,n,i),n})}createUniqueName(e){const t=we.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,n=this.extensions,r=this.primitiveCache;function i(e){return n[xo.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then(function(n){return fa(n,e,t)})}const o=[];for(let n=0,a=e.length;n<a;n++){const a=e[n],s=la(a),c=r[s];if(c)o.push(c.promise);else{let e;e=a.extensions&&a.extensions[xo.KHR_DRACO_MESH_COMPRESSION]?i(a):fa(new O,a,t),r[s]={primitive:a,promise:e},o.push(e)}}return Promise.all(o)}loadMesh(e){const t=this,n=this.json,r=this.extensions,i=n.meshes[e],o=i.primitives,a=[];for(let e=0,t=o.length;e<t;e++){const t=void 0===o[e].material?oa(this.cache):this.getDependency("material",o[e].material);a.push(t)}return a.push(t.loadGeometries(o)),Promise.all(a).then(function(n){const a=n.slice(0,n.length-1),s=n[n.length-1],c=[];for(let n=0,l=s.length;n<l;n++){const l=s[n],u=o[n];let h;const d=a[n];if(u.mode===Yo.TRIANGLES||u.mode===Yo.TRIANGLE_STRIP||u.mode===Yo.TRIANGLE_FAN||void 0===u.mode)h=!0===i.isSkinnedMesh?new Ee(l,d):new S(l,d),!0===h.isSkinnedMesh&&h.normalizeSkinWeights(),u.mode===Yo.TRIANGLE_STRIP?h.geometry=bo(h.geometry,Z):u.mode===Yo.TRIANGLE_FAN&&(h.geometry=bo(h.geometry,$));else if(u.mode===Yo.LINES)h=new Te(l,d);else if(u.mode===Yo.LINE_STRIP)h=new R(l,d);else if(u.mode===Yo.LINE_LOOP)h=new Ae(l,d);else{if(u.mode!==Yo.POINTS)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+u.mode);h=new Ce(l,d)}Object.keys(h.geometry.morphAttributes).length>0&&ca(h,i),h.name=t.createUniqueName(i.name||"mesh_"+e),sa(h,i),u.extensions&&aa(r,h,u),t.assignFinalMaterial(h),c.push(h)}for(let n=0,r=c.length;n<r;n++)t.associations.set(c[n],{meshes:e,primitives:n});if(1===c.length)return i.extensions&&aa(r,c[0],i),c[0];const l=new Oe;i.extensions&&aa(r,l,i),t.associations.set(l,{meshes:e});for(let e=0,t=c.length;e<t;e++)l.add(c[e]);return l})}loadCamera(e){let t;const n=this.json.cameras[e],r=n[n.type];if(r)return"perspective"===n.type?t=new ke(d.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(t=new Se(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),sa(t,n),Promise.resolve(t);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],n=[];for(let e=0,r=t.joints.length;e<r;e++)n.push(this._loadNodeShallow(t.joints[e]));return void 0!==t.inverseBindMatrices?n.push(this.getDependency("accessor",t.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(e){const n=e.pop(),r=e,i=[],o=[];for(let e=0,a=r.length;e<a;e++){const a=r[e];if(a){i.push(a);const t=new N;null!==n&&t.fromArray(n.array,16*e),o.push(t)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[e])}return new Me(i,o)})}loadAnimation(e){const t=this.json,n=this,r=t.animations[e],i=r.name?r.name:"animation_"+e,o=[],a=[],s=[],c=[],l=[];for(let e=0,t=r.channels.length;e<t;e++){const t=r.channels[e],n=r.samplers[t.sampler],i=t.target,u=i.node,h=void 0!==r.parameters?r.parameters[n.input]:n.input,d=void 0!==r.parameters?r.parameters[n.output]:n.output;void 0!==i.node&&(o.push(this.getDependency("node",u)),a.push(this.getDependency("accessor",h)),s.push(this.getDependency("accessor",d)),c.push(n),l.push(i))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(s),Promise.all(c),Promise.all(l)]).then(function(e){const t=e[0],r=e[1],o=e[2],a=e[3],s=e[4],c=[];for(let e=0,i=t.length;e<i;e++){const i=t[e],l=r[e],u=o[e],h=a[e],d=s[e];if(void 0===i)continue;i.updateMatrix&&i.updateMatrix();const p=n._createAnimationTracks(i,l,u,h,d);if(p)for(let e=0;e<p.length;e++)c.push(p[e])}return new Re(i,void 0,c)})}createNodeMesh(e){const t=this.json,n=this,r=t.nodes[e];return void 0===r.mesh?null:n.getDependency("mesh",r.mesh).then(function(e){const t=n._getNodeRef(n.meshCache,r.mesh,e);return void 0!==r.weights&&t.traverse(function(e){if(e.isMesh)for(let t=0,n=r.weights.length;t<n;t++)e.morphTargetInfluences[t]=r.weights[t]}),t})}loadNode(e){const t=this,n=this.json.nodes[e],r=t._loadNodeShallow(e),i=[],o=n.children||[];for(let e=0,n=o.length;e<n;e++)i.push(t.getDependency("node",o[e]));const a=void 0===n.skin?Promise.resolve(null):t.getDependency("skin",n.skin);return Promise.all([r,Promise.all(i),a]).then(function(e){const t=e[0],n=e[1],r=e[2];null!==r&&t.traverse(function(e){e.isSkinnedMesh&&e.bind(r,da)});for(let e=0,r=n.length;e<r;e++)t.add(n[e]);return t})}_loadNodeShallow(e){const t=this.json,n=this.extensions,r=this;if(void 0!==this.nodeCache[e])return this.nodeCache[e];const i=t.nodes[e],o=i.name?r.createUniqueName(i.name):"",a=[],s=r._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return s&&a.push(s),void 0!==i.camera&&a.push(r.getDependency("camera",i.camera).then(function(e){return r._getNodeRef(r.cameraCache,i.camera,e)})),r._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){a.push(e)}),this.nodeCache[e]=Promise.all(a).then(function(t){let a;if(a=!0===i.isBone?new Ie:t.length>1?new Oe:1===t.length?t[0]:new x,a!==t[0])for(let e=0,n=t.length;e<n;e++)a.add(t[e]);if(i.name&&(a.userData.name=i.name,a.name=o),sa(a,i),i.extensions&&aa(n,a,i),void 0!==i.matrix){const e=new N;e.fromArray(i.matrix),a.applyMatrix4(e)}else void 0!==i.translation&&a.position.fromArray(i.translation),void 0!==i.rotation&&a.quaternion.fromArray(i.rotation),void 0!==i.scale&&a.scale.fromArray(i.scale);return r.associations.has(a)||r.associations.set(a,{}),r.associations.get(a).nodes=e,a}),this.nodeCache[e]}loadScene(e){const t=this.extensions,n=this.json.scenes[e],r=this,i=new Oe;n.name&&(i.name=r.createUniqueName(n.name)),sa(i,n),n.extensions&&aa(t,i,n);const o=n.nodes||[],a=[];for(let e=0,t=o.length;e<t;e++)a.push(r.getDependency("node",o[e]));return Promise.all(a).then(function(e){for(let t=0,n=e.length;t<n;t++)i.add(e[t]);return r.associations=(e=>{const t=new Map;for(const[e,n]of r.associations)(e instanceof ve||e instanceof Ne)&&t.set(e,n);return e.traverse(e=>{const n=r.associations.get(e);null!=n&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){const o=[],a=e.name?e.name:e.uuid,s=[];let c;switch(ea[i.path]===ea.weights?e.traverse(function(e){e.morphTargetInfluences&&s.push(e.name?e.name:e.uuid)}):s.push(a),ea[i.path]){case ea.weights:c=De;break;case ea.rotation:c=je;break;case ea.position:case ea.scale:c=Le;break;default:if(1===n.itemSize)c=De;else c=Le}const l=void 0!==r.interpolation?ta[r.interpolation]:_e,u=this._getArrayFromAccessor(n);for(let e=0,n=s.length;e<n;e++){const n=new c(s[e]+"."+ea[i.path],t.array,u,l);"CUBICSPLINE"===r.interpolation&&this._createCubicSplineTrackInterpolant(n),o.push(n)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const e=ha(t.constructor),n=new Float32Array(t.length);for(let r=0,i=t.length;r<i;r++)n[r]=t[r]*e;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof je?qo:Wo)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function fa(e,t,n){const r=t.attributes,i=[];function a(t,r){return n.getDependency("accessor",t).then(function(t){e.setAttribute(r,t)})}for(const t in r){const n=Jo[t]||t.toLowerCase();n in e.attributes||i.push(a(r[t],n))}if(void 0!==t.indices&&!e.index){const r=n.getDependency("accessor",t.indices).then(function(t){e.setIndex(t)});i.push(r)}return Fe.workingColorSpace!==o&&"COLOR_0"in r&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Fe.workingColorSpace}" not supported.`),sa(e,t),function(e,t,n){const r=t.attributes,i=new z;if(void 0===r.POSITION)return;{const e=n.json.accessors[r.POSITION],t=e.min,o=e.max;if(void 0===t||void 0===o)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(i.set(new f(t[0],t[1],t[2]),new f(o[0],o[1],o[2])),e.normalized){const t=ha(Ko[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}const o=t.targets;if(void 0!==o){const e=new f,t=new f;for(let r=0,i=o.length;r<i;r++){const i=o[r];if(void 0!==i.POSITION){const r=n.json.accessors[i.POSITION],o=r.min,a=r.max;if(void 0!==o&&void 0!==a){if(t.setX(Math.max(Math.abs(o[0]),Math.abs(a[0]))),t.setY(Math.max(Math.abs(o[1]),Math.abs(a[1]))),t.setZ(Math.max(Math.abs(o[2]),Math.abs(a[2]))),r.normalized){const e=ha(Ko[r.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}i.expandByVector(e)}e.boundingBox=i;const a=new B;i.getCenter(a.center),a.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=a}(e,t,n),Promise.all(i).then(function(){return void 0!==t.targets?function(e,t,n){let r=!1,i=!1,o=!1;for(let e=0,n=t.length;e<n;e++){const n=t[e];if(void 0!==n.POSITION&&(r=!0),void 0!==n.NORMAL&&(i=!0),void 0!==n.COLOR_0&&(o=!0),r&&i&&o)break}if(!r&&!i&&!o)return Promise.resolve(e);const a=[],s=[],c=[];for(let l=0,u=t.length;l<u;l++){const u=t[l];if(r){const t=void 0!==u.POSITION?n.getDependency("accessor",u.POSITION):e.attributes.position;a.push(t)}if(i){const t=void 0!==u.NORMAL?n.getDependency("accessor",u.NORMAL):e.attributes.normal;s.push(t)}if(o){const t=void 0!==u.COLOR_0?n.getDependency("accessor",u.COLOR_0):e.attributes.color;c.push(t)}}return Promise.all([Promise.all(a),Promise.all(s),Promise.all(c)]).then(function(t){const n=t[0],a=t[1],s=t[2];return r&&(e.morphAttributes.position=n),i&&(e.morphAttributes.normal=a),o&&(e.morphAttributes.color=s),e.morphTargetsRelative=!0,e})}(e,t.targets,n):e})}var ma=function(){var e=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),t=new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);if("object"!=typeof WebAssembly)return{supported:!1};var n,r=WebAssembly.validate(e)?"b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuikqbbebeedddilve9Weeeviebeoweuec:q;Aekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbwl79IV9RbDq;t9tqlbzik9:evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaec:q:yjjbfai86bbaecitc:q1jjbfab8Piw83ibaecefgecjd9hmbkk;h8JlHud97euo978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Rad;8qbbcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhwcbhDinaDae9pmeawaeaD9RaDawfae6Egqcsfgoc9WGgkci2hxakcethmaocl4cifcd4hPabaDad2fhscbhzdnincehHalhOcbhAdninaraO9RaP6miavcj;cbfaAak2fhCaOaPfhlcbhidnakc;ab6mbaral9Rc;Gb6mbcbhoinaCaofhidndndndndnaOaoco4fRbbgXciGPlbedibkaipxbbbbbbbbbbbbbbbbpklbxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklbalczfhlkdndndndndnaXcd4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklzxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklzalczfhlkdndndndndnaXcl4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklaxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklaalczfhlkdndndndndnaXco4Plbedibkaipxbbbbbbbbbbbbbbbbpkl8WxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalclfaYpQbfaXc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalcwfaYpQbfaXc:q:yjjbfRbbfhlxekaialpbbbpkl8Walczfhlkaoc;abfhiaocjefak0meaihoaral9Rc;Fb0mbkkdndnaiak9pmbaici4hoinaral9RcK6mdaCaifhXdndndndndnaOaico4fRbbaocoG4ciGPlbedibkaXpxbbbbbbbbbbbbbbbbpklbxikaXalpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaXalpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaXalpbbbpklbalczfhlkaocdfhoaiczfgiak6mbkkalTmbaAci6hHalhOaAcefgohAaoclSmdxekkcbhlaHceGmdkdnakTmbavcjdfazfhiavazfpbdbhYcbhXinaiavcj;cbfaXfgopblbgLcep9TaLpxeeeeeeeeeeeeeeeegQp9op9Hp9rgLaoakfpblbg8Acep9Ta8AaQp9op9Hp9rg8ApmbzeHdOiAlCvXoQrLgEaoamfpblbg3cep9Ta3aQp9op9Hp9rg3aoaxfpblbg5cep9Ta5aQp9op9Hp9rg5pmbzeHdOiAlCvXoQrLg8EpmbezHdiOAlvCXorQLgQaQpmbedibedibedibediaYp9UgYp9AdbbaiadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaEa8EpmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwKDYq8AkEx3m5P8Es8FgLa3a5pmwKDYq8AkEx3m5P8Es8Fg8ApmbezHdiOAlvCXorQLgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfhiaXczfgXak6mbkkazclfgzad6mbkasavcjdfaqad2;8qbbavavcjdfaqcufad2fad;8qbbaqaDfhDc9:hoalmexikkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;kbf8Kjjjjbaokwbz:bjjjbk;uzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecje;8kbavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhDcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgrc;Ve0mbavc;abfalarcl4cu7fcsGcitfgPydlhsaPydbhzdnarcsGgPak9pmbavaiarcu7fcsGcdtfydbaxaPEhraPThPdndnadcd9hmbabaDcetfgHaz87ebaHcdfas87ebaHclfar87ebxekabaDcdtfgHazBdbaHclfasBdbaHcwfarBdbkaxaPfhxavc;abfalcitfgHarBdbaHasBdlavaicdtfarBdbavc;abfalcefcsGglcitfgHazBdbaHarBdlaiaPfhialcefhlxdkdndnaPcsSmbamaPfaPc987fcefhmxekaocefhrao8SbbgPcFeGhHdndnaPcu9mmbarhoxekaocvfhoaHcFbGhHcrhPdninar8SbbgOcFbGaPtaHVhHaOcu9kmearcefhraPcrfgPc8J9hmbxdkkarcefhokaHce4cbaHceG9R7amfhmkdndnadcd9hmbabaDcetfgraz87ebarcdfas87ebarclfam87ebxekabaDcdtfgrazBdbarclfasBdbarcwfamBdbkavc;abfalcitfgramBdbarasBdlavaicdtfamBdbavc;abfalcefcsGglcitfgrazBdbaramBdlaicefhialcefhlxekdnarcpe0mbaxcefgOavaiaqarcsGfRbbgPcl49RcsGcdtfydbaPcz6gHEhravaiaP9RcsGcdtfydbaOaHfgsaPcsGgOEhPaOThOdndnadcd9hmbabaDcetfgzax87ebazcdfar87ebazclfaP87ebxekabaDcdtfgzaxBdbazclfarBdbazcwfaPBdbkavaicdtfaxBdbavc;abfalcitfgzarBdbazaxBdlavaicefgicsGcdtfarBdbavc;abfalcefcsGcitfgzaPBdbazarBdlavaiaHfcsGgicdtfaPBdbavc;abfalcdfcsGglcitfgraxBdbaraPBdlalcefhlaiaOfhiasaOfhxxekaxcbaoRbbgzEgAarc;:eSgrfhsazcsGhCazcl4hXdndnazcs0mbascefhOxekashOavaiaX9RcsGcdtfydbhskdndnaCmbaOcefhxxekaOhxavaiaz9RcsGcdtfydbhOkdndnarTmbaocefhrxekaocdfhrao8SbegHcFeGhPdnaHcu9kmbaocofhAaPcFbGhPcrhodninar8SbbgHcFbGaotaPVhPaHcu9kmearcefhraocrfgoc8J9hmbkaAhrxekarcefhrkaPce4cbaPceG9R7amfgmhAkdndnaXcsSmbarhPxekarcefhPar8SbbgocFeGhHdnaocu9kmbarcvfhsaHcFbGhHcrhodninaP8SbbgrcFbGaotaHVhHarcu9kmeaPcefhPaocrfgoc8J9hmbkashPxekaPcefhPkaHce4cbaHceG9R7amfgmhskdndnaCcsSmbaPhoxekaPcefhoaP8SbbgrcFeGhHdnarcu9kmbaPcvfhOaHcFbGhHcrhrdninao8SbbgPcFbGartaHVhHaPcu9kmeaocefhoarcrfgrc8J9hmbkaOhoxekaocefhokaHce4cbaHceG9R7amfgmhOkdndnadcd9hmbabaDcetfgraA87ebarcdfas87ebarclfaO87ebxekabaDcdtfgraABdbarclfasBdbarcwfaOBdbkavc;abfalcitfgrasBdbaraABdlavaicdtfaABdbavc;abfalcefcsGcitfgraOBdbarasBdlavaicefgicsGcdtfasBdbavc;abfalcdfcsGcitfgraABdbaraOBdlavaiazcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiaDcifgDae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:llevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:EPliuo97eue978Jjjjjbca9Rhidndnadcl9hmbdnaec98GglTmbcbhvabhdinadadpbbbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbadczfhdavclfgval6mbkkalae9pmeaiaeciGgvcdtgdVcbczad9R;8kbaiabalcdtfglad;8qbbdnavTmbaiaipblbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpklbkalaiad;8qbbskdnaec98GgxTmbcbhvabhdinadczfglalpbbbgopxbbbbbbFFbbbbbbFFgkp9oadpbbbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpkbbadaDakp9oawaopmbezHdiOAlvCXorQLp9qpkbbadcafhdavclfgvax6mbkkaxae9pmbaiaeciGgvcitgdfcbcaad9R;8kbaiabaxcitfglad;8qbbdnavTmbaiaipblzgopxbbbbbbFFbbbbbbFFgkp9oaipblbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpklzaiaDakp9oawaopmbezHdiOAlvCXorQLp9qpklbkalaiad;8qbbkk;4wllue97euv978Jjjjjbc8W9Rhidnaec98GglTmbcbhvabhoinaiaopbbbgraoczfgwpbbbgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklbaopxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblbpEb:T:j83ibaocwfarp5eaipblbpEe:T:j83ibawaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblbpEd:T:j83ibaocKfakp5eaipblbpEi:T:j83ibaocafhoavclfgval6mbkkdnalae9pmbaiaeciGgvcitgofcbcaao9R;8kbaiabalcitfgwao;8qbbdnavTmbaiaipblbgraipblzgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklaaipxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblapEb:T:j83ibaiarp5eaipblapEe:T:j83iwaiaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblapEd:T:j83izaiakp5eaipblapEi:T:j83iKkawaiao;8qbbkk:Pddiue978Jjjjjbc;ab9Rhidnadcd4ae2glc98GgvTmbcbhdabheinaeaepbbbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepkbbaeczfheadclfgdav6mbkkdnaval9pmbaialciGgdcdtgeVcbc;abae9R;8kbaiabavcdtfgvae;8qbbdnadTmbaiaipblbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepklbkavaiae;8qbbkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkkebcjwklz9Tbb":"b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuikqbeeedddillviebeoweuec:q;iekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbol79IV9Rbrq:P8Yqdbk;3sezu8Jjjjjbcj;eb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Radz1jjjbhwcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhDcbhqinaqae9pmeaDaeaq9RaqaDfae6Egkcsfgocl4cifcd4hxdndndndnaoc9WGgmTmbcbhPcehsawcjdfhzalhHinaraH9Rax6midnaraHaxfgl9RcK6mbczhoinawcj;cbfaogifgoc9WfhOdndndndndnaHaic9WfgAco4fRbbaAci4coG4ciGPlbedibkaO9cb83ibaOcwf9cb83ibxikaOalRblalRbbgAco4gCaCciSgCE86bbaocGfalclfaCfgORbbaAcl4ciGgCaCciSgCE86bbaocVfaOaCfgORbbaAcd4ciGgCaCciSgCE86bbaoc7faOaCfgORbbaAciGgAaAciSgAE86bbaoctfaOaAfgARbbalRbegOco4gCaCciSgCE86bbaoc91faAaCfgARbbaOcl4ciGgCaCciSgCE86bbaoc4faAaCfgARbbaOcd4ciGgCaCciSgCE86bbaoc93faAaCfgARbbaOciGgOaOciSgOE86bbaoc94faAaOfgARbbalRbdgOco4gCaCciSgCE86bbaoc95faAaCfgARbbaOcl4ciGgCaCciSgCE86bbaoc96faAaCfgARbbaOcd4ciGgCaCciSgCE86bbaoc97faAaCfgARbbaOciGgOaOciSgOE86bbaoc98faAaOfgORbbalRbiglco4gAaAciSgAE86bbaoc99faOaAfgORbbalcl4ciGgAaAciSgAE86bbaoc9:faOaAfgORbbalcd4ciGgAaAciSgAE86bbaocufaOaAfgoRbbalciGglalciSglE86bbaoalfhlxdkaOalRbwalRbbgAcl4gCaCcsSgCE86bbaocGfalcwfaCfgORbbaAcsGgAaAcsSgAE86bbaocVfaOaAfgORbbalRbegAcl4gCaCcsSgCE86bbaoc7faOaCfgORbbaAcsGgAaAcsSgAE86bbaoctfaOaAfgORbbalRbdgAcl4gCaCcsSgCE86bbaoc91faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc4faOaAfgORbbalRbigAcl4gCaCcsSgCE86bbaoc93faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc94faOaAfgORbbalRblgAcl4gCaCcsSgCE86bbaoc95faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc96faOaAfgORbbalRbvgAcl4gCaCcsSgCE86bbaoc97faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc98faOaAfgORbbalRbogAcl4gCaCcsSgCE86bbaoc99faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc9:faOaAfgORbbalRbrglcl4gAaAcsSgAE86bbaocufaOaAfgoRbbalcsGglalcsSglE86bbaoalfhlxekaOal8Pbb83bbaOcwfalcwf8Pbb83bbalczfhlkdnaiam9pmbaiczfhoaral9RcL0mekkaiam6mialTmidnakTmbawaPfRbbhOcbhoazhiinaiawcj;cbfaofRbbgAce4cbaAceG9R7aOfgO86bbaiadfhiaocefgoak9hmbkkazcefhzaPcefgPad6hsalhHaPad9hmexvkkcbhlasceGmdxikalaxad2fhCdnakTmbcbhHcehsawcjdfhminaral9Rax6mialTmdalaxfhlawaHfRbbhOcbhoamhiinaiawcj;cbfaofRbbgAce4cbaAceG9R7aOfgO86bbaiadfhiaocefgoak9hmbkamcefhmaHcefgHad6hsaHad9hmbkaChlxikcbhocehsinaral9Rax6mdalTmealaxfhlaocefgoad6hsadao9hmbkaChlxdkcbhlasceGTmekc9:hoxikabaqad2fawcjdfakad2z1jjjb8Aawawcjdfakcufad2fadz1jjjb8Aakaqfhqalmbkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;ebf8Kjjjjbaok;yzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecjez:jjjjb8AavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhDcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgrc;Ve0mbavc;abfalarcl4cu7fcsGcitfgPydlhsaPydbhzdnarcsGgPak9pmbavaiarcu7fcsGcdtfydbaxaPEhraPThPdndnadcd9hmbabaDcetfgHaz87ebaHcdfas87ebaHclfar87ebxekabaDcdtfgHazBdbaHclfasBdbaHcwfarBdbkaxaPfhxavc;abfalcitfgHarBdbaHasBdlavaicdtfarBdbavc;abfalcefcsGglcitfgHazBdbaHarBdlaiaPfhialcefhlxdkdndnaPcsSmbamaPfaPc987fcefhmxekaocefhrao8SbbgPcFeGhHdndnaPcu9mmbarhoxekaocvfhoaHcFbGhHcrhPdninar8SbbgOcFbGaPtaHVhHaOcu9kmearcefhraPcrfgPc8J9hmbxdkkarcefhokaHce4cbaHceG9R7amfhmkdndnadcd9hmbabaDcetfgraz87ebarcdfas87ebarclfam87ebxekabaDcdtfgrazBdbarclfasBdbarcwfamBdbkavc;abfalcitfgramBdbarasBdlavaicdtfamBdbavc;abfalcefcsGglcitfgrazBdbaramBdlaicefhialcefhlxekdnarcpe0mbaxcefgOavaiaqarcsGfRbbgPcl49RcsGcdtfydbaPcz6gHEhravaiaP9RcsGcdtfydbaOaHfgsaPcsGgOEhPaOThOdndnadcd9hmbabaDcetfgzax87ebazcdfar87ebazclfaP87ebxekabaDcdtfgzaxBdbazclfarBdbazcwfaPBdbkavaicdtfaxBdbavc;abfalcitfgzarBdbazaxBdlavaicefgicsGcdtfarBdbavc;abfalcefcsGcitfgzaPBdbazarBdlavaiaHfcsGgicdtfaPBdbavc;abfalcdfcsGglcitfgraxBdbaraPBdlalcefhlaiaOfhiasaOfhxxekaxcbaoRbbgzEgAarc;:eSgrfhsazcsGhCazcl4hXdndnazcs0mbascefhOxekashOavaiaX9RcsGcdtfydbhskdndnaCmbaOcefhxxekaOhxavaiaz9RcsGcdtfydbhOkdndnarTmbaocefhrxekaocdfhrao8SbegHcFeGhPdnaHcu9kmbaocofhAaPcFbGhPcrhodninar8SbbgHcFbGaotaPVhPaHcu9kmearcefhraocrfgoc8J9hmbkaAhrxekarcefhrkaPce4cbaPceG9R7amfgmhAkdndnaXcsSmbarhPxekarcefhPar8SbbgocFeGhHdnaocu9kmbarcvfhsaHcFbGhHcrhodninaP8SbbgrcFbGaotaHVhHarcu9kmeaPcefhPaocrfgoc8J9hmbkashPxekaPcefhPkaHce4cbaHceG9R7amfgmhskdndnaCcsSmbaPhoxekaPcefhoaP8SbbgrcFeGhHdnarcu9kmbaPcvfhOaHcFbGhHcrhrdninao8SbbgPcFbGartaHVhHaPcu9kmeaocefhoarcrfgrc8J9hmbkaOhoxekaocefhokaHce4cbaHceG9R7amfgmhOkdndnadcd9hmbabaDcetfgraA87ebarcdfas87ebarclfaO87ebxekabaDcdtfgraABdbarclfasBdbarcwfaOBdbkavc;abfalcitfgrasBdbaraABdlavaicdtfaABdbavc;abfalcefcsGcitfgraOBdbarasBdlavaicefgicsGcdtfasBdbavc;abfalcdfcsGcitfgraABdbaraOBdlavaiazcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiaDcifgDae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:llevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk;siliui99iue99dnaeTmbcbhiabhlindndnJ;Zl81Zalcof8UebgvciV:Y:vgoal8Ueb:YNgrJb;:FSNJbbbZJbbb:;arJbbbb9GEMgw:lJbbb9p9DTmbaw:OhDxekcjjjj94hDkalclf8Uebhqalcdf8UebhkabavcefciGaiVcetfaD87ebdndnaoak:YNgwJb;:FSNJbbbZJbbb:;awJbbbb9GEMgx:lJbbb9p9DTmbax:Ohkxekcjjjj94hkkabavcdfciGaiVcetfak87ebdndnaoaq:YNgoJb;:FSNJbbbZJbbb:;aoJbbbb9GEMgx:lJbbb9p9DTmbax:Ohqxekcjjjj94hqkabavcufciGaiVcetfaq87ebdndnJbbjZararN:tawawN:taoaoN:tgrJbbbbarJbbbb9GE:rJb;:FSNJbbbZMgr:lJbbb9p9DTmbar:Ohqxekcjjjj94hqkabavciGaiVcetfaq87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2geTmbinababydbgdcwtcw91:Yadce91cjjj;8ifcjjj98G::NUdbabclfhbaecufgembkkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaiczfhiaeczfheadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkkkebcjwklz9Kbb",i=WebAssembly.instantiate(o(r),{}).then(function(e){(n=e.instance).exports.__wasm_call_ctors()});function o(e){for(var n=new Uint8Array(e.length),r=0;r<e.length;++r){var i=e.charCodeAt(r);n[r]=i>96?i-97:i>64?i-39:i+4}var o=0;for(r=0;r<e.length;++r)n[o++]=n[r]<60?t[n[r]]:64*(n[r]-60)+n[++r];return n.buffer.slice(0,o)}function a(e,t,r,i,o,a){var s=n.exports.sbrk,c=r+3&-4,l=s(c*i),u=s(o.length),h=new Uint8Array(n.exports.memory.buffer);h.set(o,u);var d=e(l,r,i,u,o.length);if(0==d&&a&&a(l,c,i),t.set(h.subarray(l,l+r*i)),s(l-s(0)),0!=d)throw new Error("Malformed buffer data: "+d)}var s={NONE:"",OCTAHEDRAL:"meshopt_decodeFilterOct",QUATERNION:"meshopt_decodeFilterQuat",EXPONENTIAL:"meshopt_decodeFilterExp"},c={ATTRIBUTES:"meshopt_decodeVertexBuffer",TRIANGLES:"meshopt_decodeIndexBuffer",INDICES:"meshopt_decodeIndexSequence"},l=[],u=0;function h(e){var t={object:new Worker(e),pending:0,requests:{}};return t.object.onmessage=function(e){var n=e.data;t.pending-=n.count,t.requests[n.id][n.action](n.value),delete t.requests[n.id]},t}function d(e){for(var t="var instance; var ready = WebAssembly.instantiate(new Uint8Array(["+new Uint8Array(o(r))+"]), {}).then(function(result) { instance = result.instance; instance.exports.__wasm_call_ctors(); });self.onmessage = workerProcess;"+a.toString()+p.toString(),n=new Blob([t],{type:"text/javascript"}),i=URL.createObjectURL(n),s=0;s<e;++s)l[s]=h(i);URL.revokeObjectURL(i)}function p(e){i.then(function(){var t=e.data;try{var r=new Uint8Array(t.count*t.size);a(n.exports[t.mode],r,t.count,t.size,t.source,n.exports[t.filter]),self.postMessage({id:t.id,count:t.count,action:"resolve",value:r},[r.buffer])}catch(e){self.postMessage({id:t.id,count:t.count,action:"reject",value:e})}})}return{ready:i,supported:!0,useWorkers:function(e){d(e)},decodeVertexBuffer:function(e,t,r,i,o){a(n.exports.meshopt_decodeVertexBuffer,e,t,r,i,n.exports[s[o]])},decodeIndexBuffer:function(e,t,r,i){a(n.exports.meshopt_decodeIndexBuffer,e,t,r,i)},decodeIndexSequence:function(e,t,r,i){a(n.exports.meshopt_decodeIndexSequence,e,t,r,i)},decodeGltfBuffer:function(e,t,r,i,o,l){a(n.exports[c[o]],e,t,r,i,n.exports[s[l]])},decodeGltfBufferAsync:function(e,t,r,o,h){return l.length>0?function(e,t,n,r,i){for(var o=l[0],a=1;a<l.length;++a)l[a].pending<o.pending&&(o=l[a]);return new Promise(function(a,s){var c=new Uint8Array(n),l=u++;o.pending+=e,o.requests[l]={resolve:a,reject:s},o.object.postMessage({id:l,count:e,size:t,source:c,mode:r,filter:i},[c.buffer])})}(e,t,r,c[o],s[h]):i.then(function(){var i=new Uint8Array(e*t);return a(n.exports[c[o]],i,e,t,r,n.exports[s[h]]),i})}}}();const ga=/^[og]\s*(.+)?/,ba=/^mtllib /,ya=/^usemtl /,va=/^usemap /,xa=/\s+/,wa=new f,Ea=new f,Ta=new f,Aa=new f,Ca=new f,Oa=new K;function ka(){const e={objects:[],object:{},vertices:[],normals:[],colors:[],uvs:[],materials:{},materialLibraries:[],startObject:function(e,t){if(this.object&&!1===this.object.fromDeclaration)return this.object.name=e,void(this.object.fromDeclaration=!1!==t);const n=this.object&&"function"==typeof this.object.currentMaterial?this.object.currentMaterial():void 0;if(this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0),this.object={name:e||"",fromDeclaration:!1!==t,geometry:{vertices:[],normals:[],colors:[],uvs:[],hasUVIndices:!1},materials:[],smooth:!0,startMaterial:function(e,t){const n=this._finalize(!1);n&&(n.inherited||n.groupCount<=0)&&this.materials.splice(n.index,1);const r={index:this.materials.length,name:e||"",mtllib:Array.isArray(t)&&t.length>0?t[t.length-1]:"",smooth:void 0!==n?n.smooth:this.smooth,groupStart:void 0!==n?n.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(e){const t={index:"number"==typeof e?e:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0,groupEnd:-1,groupCount:-1,inherited:!1};return t.clone=this.clone.bind(t),t}};return this.materials.push(r),r},currentMaterial:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]},_finalize:function(e){const t=this.currentMaterial();if(t&&-1===t.groupEnd&&(t.groupEnd=this.geometry.vertices.length/3,t.groupCount=t.groupEnd-t.groupStart,t.inherited=!1),e&&this.materials.length>1)for(let e=this.materials.length-1;e>=0;e--)this.materials[e].groupCount<=0&&this.materials.splice(e,1);return e&&0===this.materials.length&&this.materials.push({name:"",smooth:this.smooth}),t}},n&&n.name&&"function"==typeof n.clone){const e=n.clone(0);e.inherited=!0,this.object.materials.push(e)}this.objects.push(this.object)},finalize:function(){this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0)},parseVertexIndex:function(e,t){const n=parseInt(e,10);return 3*(n>=0?n-1:n+t/3)},parseNormalIndex:function(e,t){const n=parseInt(e,10);return 3*(n>=0?n-1:n+t/3)},parseUVIndex:function(e,t){const n=parseInt(e,10);return 2*(n>=0?n-1:n+t/2)},addVertex:function(e,t,n){const r=this.vertices,i=this.object.geometry.vertices;i.push(r[e+0],r[e+1],r[e+2]),i.push(r[t+0],r[t+1],r[t+2]),i.push(r[n+0],r[n+1],r[n+2])},addVertexPoint:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addVertexLine:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addNormal:function(e,t,n){const r=this.normals,i=this.object.geometry.normals;i.push(r[e+0],r[e+1],r[e+2]),i.push(r[t+0],r[t+1],r[t+2]),i.push(r[n+0],r[n+1],r[n+2])},addFaceNormal:function(e,t,n){const r=this.vertices,i=this.object.geometry.normals;wa.fromArray(r,e),Ea.fromArray(r,t),Ta.fromArray(r,n),Ca.subVectors(Ta,Ea),Aa.subVectors(wa,Ea),Ca.cross(Aa),Ca.normalize(),i.push(Ca.x,Ca.y,Ca.z),i.push(Ca.x,Ca.y,Ca.z),i.push(Ca.x,Ca.y,Ca.z)},addColor:function(e,t,n){const r=this.colors,i=this.object.geometry.colors;void 0!==r[e]&&i.push(r[e+0],r[e+1],r[e+2]),void 0!==r[t]&&i.push(r[t+0],r[t+1],r[t+2]),void 0!==r[n]&&i.push(r[n+0],r[n+1],r[n+2])},addUV:function(e,t,n){const r=this.uvs,i=this.object.geometry.uvs;i.push(r[e+0],r[e+1]),i.push(r[t+0],r[t+1]),i.push(r[n+0],r[n+1])},addDefaultUV:function(){const e=this.object.geometry.uvs;e.push(0,0),e.push(0,0),e.push(0,0)},addUVLine:function(e){const t=this.uvs;this.object.geometry.uvs.push(t[e+0],t[e+1])},addFace:function(e,t,n,r,i,o,a,s,c){const l=this.vertices.length;let u=this.parseVertexIndex(e,l),h=this.parseVertexIndex(t,l),d=this.parseVertexIndex(n,l);if(this.addVertex(u,h,d),this.addColor(u,h,d),void 0!==a&&""!==a){const e=this.normals.length;u=this.parseNormalIndex(a,e),h=this.parseNormalIndex(s,e),d=this.parseNormalIndex(c,e),this.addNormal(u,h,d)}else this.addFaceNormal(u,h,d);if(void 0!==r&&""!==r){const e=this.uvs.length;u=this.parseUVIndex(r,e),h=this.parseUVIndex(i,e),d=this.parseUVIndex(o,e),this.addUV(u,h,d),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(e){this.object.geometry.type="Points";const t=this.vertices.length;for(let n=0,r=e.length;n<r;n++){const r=this.parseVertexIndex(e[n],t);this.addVertexPoint(r),this.addColor(r)}},addLineGeometry:function(e,t){this.object.geometry.type="Line";const n=this.vertices.length,r=this.uvs.length;for(let t=0,r=e.length;t<r;t++)this.addVertexLine(this.parseVertexIndex(e[t],n));for(let e=0,n=t.length;e<n;e++)this.addUVLine(this.parseUVIndex(t[e],r))}};return e.startObject("",!1),e}class Sa extends X{constructor(e){super(e),this.materials=null}load(e,t,n,r){const i=this,o=new q(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}setMaterials(e){return this.materials=e,this}parse(e){const t=new ka;-1!==e.indexOf("\r\n")&&(e=e.replace(/\r\n/g,"\n")),-1!==e.indexOf("\\\n")&&(e=e.replace(/\\\n/g,""));const n=e.split("\n");let r=[];for(let e=0,i=n.length;e<i;e++){const i=n[e].trimStart();if(0===i.length)continue;const o=i.charAt(0);if("#"!==o)if("v"===o){const e=i.split(xa);switch(e[0]){case"v":t.vertices.push(parseFloat(e[1]),parseFloat(e[2]),parseFloat(e[3])),e.length>=7?(Oa.setRGB(parseFloat(e[4]),parseFloat(e[5]),parseFloat(e[6])).convertSRGBToLinear(),t.colors.push(Oa.r,Oa.g,Oa.b)):t.colors.push(void 0,void 0,void 0);break;case"vn":t.normals.push(parseFloat(e[1]),parseFloat(e[2]),parseFloat(e[3]));break;case"vt":t.uvs.push(parseFloat(e[1]),parseFloat(e[2]))}}else if("f"===o){const e=i.slice(1).trim().split(xa),n=[];for(let t=0,r=e.length;t<r;t++){const r=e[t];if(r.length>0){const e=r.split("/");n.push(e)}}const r=n[0];for(let e=1,i=n.length-1;e<i;e++){const i=n[e],o=n[e+1];t.addFace(r[0],i[0],o[0],r[1],i[1],o[1],r[2],i[2],o[2])}}else if("l"===o){const e=i.substring(1).trim().split(" ");let n=[];const r=[];if(-1===i.indexOf("/"))n=e;else for(let t=0,i=e.length;t<i;t++){const i=e[t].split("/");""!==i[0]&&n.push(i[0]),""!==i[1]&&r.push(i[1])}t.addLineGeometry(n,r)}else if("p"===o){const e=i.slice(1).trim().split(" ");t.addPointGeometry(e)}else if(null!==(r=ga.exec(i))){const e=(" "+r[0].slice(1).trim()).slice(1);t.startObject(e)}else if(ya.test(i))t.object.startMaterial(i.substring(7).trim(),t.materialLibraries);else if(ba.test(i))t.materialLibraries.push(i.substring(7).trim());else if(va.test(i))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if("s"===o){if(r=i.split(" "),r.length>1){const e=r[1].trim().toLowerCase();t.object.smooth="0"!==e&&"off"!==e}else t.object.smooth=!0;const e=t.object.currentMaterial();e&&(e.smooth=t.object.smooth)}else{if("\0"===i)continue;console.warn('THREE.OBJLoader: Unexpected line: "'+i+'"')}}t.finalize();const i=new Oe;i.materialLibraries=[].concat(t.materialLibraries);if(!0===!(1===t.objects.length&&0===t.objects[0].geometry.vertices.length))for(let e=0,n=t.objects.length;e<n;e++){const n=t.objects[e],r=n.geometry,o=n.materials,a="Line"===r.type,s="Points"===r.type;let c=!1;if(0===r.vertices.length)continue;const l=new O;l.setAttribute("position",new k(r.vertices,3)),r.normals.length>0&&l.setAttribute("normal",new k(r.normals,3)),r.colors.length>0&&(c=!0,l.setAttribute("color",new k(r.colors,3))),!0===r.hasUVIndices&&l.setAttribute("uv",new k(r.uvs,2));const u=[];for(let e=0,n=o.length;e<n;e++){const n=o[e],r=n.name+"_"+n.smooth+"_"+c;let i=t.materials[r];if(null!==this.materials)if(i=this.materials.create(n.name),!a||!i||i instanceof T){if(s&&i&&!(i instanceof ye)){const e=new ye({size:10,sizeAttenuation:!1});ve.prototype.copy.call(e,i),e.color.copy(i.color),e.map=i.map,i=e}}else{const e=new T;ve.prototype.copy.call(e,i),e.color.copy(i.color),i=e}void 0===i&&(i=a?new T:s?new ye({size:1,sizeAttenuation:!1}):new Be,i.name=n.name,i.flatShading=!n.smooth,i.vertexColors=c,t.materials[r]=i),u.push(i)}let h;if(u.length>1){for(let e=0,t=o.length;e<t;e++){const t=o[e];l.addGroup(t.groupStart,t.groupCount,e)}h=a?new Te(l,u):s?new Ce(l,u):new S(l,u)}else h=a?new Te(l,u[0]):s?new Ce(l,u[0]):new S(l,u[0]);h.name=n.name,i.add(h)}else if(t.vertices.length>0){const e=new ye({size:1,sizeAttenuation:!1}),n=new O;n.setAttribute("position",new k(t.vertices,3)),t.colors.length>0&&void 0!==t.colors[0]&&(n.setAttribute("color",new k(t.colors,3)),e.vertexColors=!0);const r=new Ce(n,e);i.add(r)}return i}}class Ma extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=""===this.path?J.extractUrlBase(e):this.path,a=new q(this.manager);a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}setMaterialOptions(e){return this.materialOptions=e,this}parse(e,t){const n=e.split("\n");let r={};const i=/\s+/,o={};for(let e=0;e<n.length;e++){let t=n[e];if(t=t.trim(),0===t.length||"#"===t.charAt(0))continue;const a=t.indexOf(" ");let s=a>=0?t.substring(0,a):t;s=s.toLowerCase();let c=a>=0?t.substring(a+1):"";if(c=c.trim(),"newmtl"===s)r={name:c},o[c]=r;else if("ka"===s||"kd"===s||"ks"===s||"ke"===s){const e=c.split(i,3);r[s]=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])]}else r[s]=c}const a=new Ra(this.resourcePath||t,this.materialOptions);return a.setCrossOrigin(this.crossOrigin),a.setManager(this.manager),a.setMaterials(o),a}}class Ra{constructor(e="",t={}){this.baseUrl=e,this.options=t,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.crossOrigin="anonymous",this.side=void 0!==this.options.side?this.options.side:G,this.wrap=void 0!==this.options.wrap?this.options.wrap:me}setCrossOrigin(e){return this.crossOrigin=e,this}setManager(e){this.manager=e}setMaterials(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}convert(e){if(!this.options)return e;const t={};for(const n in e){const r=e[n],i={};t[n]=i;for(const e in r){let t=!0,n=r[e];const o=e.toLowerCase();switch(o){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(n=[n[0]/255,n[1]/255,n[2]/255]),this.options&&this.options.ignoreZeroRGBs&&0===n[0]&&0===n[1]&&0===n[2]&&(t=!1)}t&&(i[o]=n)}}return t}preload(){for(const e in this.materialsInfo)this.create(e)}getIndex(e){return this.nameLookup[e]}getAsArray(){let e=0;for(const t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}create(e){return void 0===this.materials[e]&&this.createMaterial_(e),this.materials[e]}createMaterial_(e){const t=this,n=this.materialsInfo[e],r={name:e,side:this.side};function i(e,n){if(r[e])return;const i=t.getTextureParams(n,r),o=t.loadTexture((a=t.baseUrl,"string"!=typeof(s=i.url)||""===s?"":/^https?:\/\//i.test(s)?s:a+s));var a,s;o.repeat.copy(i.scale),o.offset.copy(i.offset),o.wrapS=t.wrap,o.wrapT=t.wrap,"map"!==e&&"emissiveMap"!==e||(o.colorSpace=Y),r[e]=o}for(const e in n){const t=n[e];let o;if(""!==t)switch(e.toLowerCase()){case"kd":r.color=(new K).fromArray(t).convertSRGBToLinear();break;case"ks":r.specular=(new K).fromArray(t).convertSRGBToLinear();break;case"ke":r.emissive=(new K).fromArray(t).convertSRGBToLinear();break;case"map_kd":i("map",t);break;case"map_ks":i("specularMap",t);break;case"map_ke":i("emissiveMap",t);break;case"norm":i("normalMap",t);break;case"map_bump":case"bump":i("bumpMap",t);break;case"map_d":i("alphaMap",t),r.transparent=!0;break;case"ns":r.shininess=parseFloat(t);break;case"d":o=parseFloat(t),o<1&&(r.opacity=o,r.transparent=!0);break;case"tr":o=parseFloat(t),this.options&&this.options.invertTrProperty&&(o=1-o),o>0&&(r.opacity=1-o,r.transparent=!0)}}return this.materials[e]=new Be(r),this.materials[e]}getTextureParams(e,t){const n={scale:new v(1,1),offset:new v(0,0)},r=e.split(/\s+/);let i;return i=r.indexOf("-bm"),i>=0&&(t.bumpScale=parseFloat(r[i+1]),r.splice(i,2)),i=r.indexOf("-s"),i>=0&&(n.scale.set(parseFloat(r[i+1]),parseFloat(r[i+2])),r.splice(i,4)),i=r.indexOf("-o"),i>=0&&(n.offset.set(parseFloat(r[i+1]),parseFloat(r[i+2])),r.splice(i,4)),n.url=r.join(" ").trim(),n}loadTexture(e,t,n,r,i){const o=void 0!==this.manager?this.manager:ze;let a=o.getHandler(e);null===a&&(a=new ae(o)),a.setCrossOrigin&&a.setCrossOrigin(this.crossOrigin);const s=a.load(e,n,r,i);return void 0!==t&&(s.mapping=t),s}}function Ia(e,t,n){const r=n.length-e-1;if(t>=n[r])return r-1;if(t<=n[e])return e;let i=e,o=r,a=Math.floor((i+o)/2);for(;t<n[a]||t>=n[a+1];)t<n[a]?o=a:i=a,a=Math.floor((i+o)/2);return a}function Pa(e,t){let n=1;for(let t=2;t<=e;++t)n*=t;let r=1;for(let e=2;e<=t;++e)r*=e;for(let n=2;n<=e-t;++n)r*=n;return n/r}function _a(e,t,n,r,i){const o=function(e,t,n,r,i){const o=i<e?i:e,a=[],s=Ia(e,r,t),c=function(e,t,n,r,i){const o=[];for(let e=0;e<=n;++e)o[e]=0;const a=[];for(let e=0;e<=r;++e)a[e]=o.slice(0);const s=[];for(let e=0;e<=n;++e)s[e]=o.slice(0);s[0][0]=1;const c=o.slice(0),l=o.slice(0);for(let r=1;r<=n;++r){c[r]=t-i[e+1-r],l[r]=i[e+r]-t;let n=0;for(let e=0;e<r;++e){const t=l[e+1],i=c[r-e];s[r][e]=t+i;const o=s[e][r-1]/s[r][e];s[e][r]=n+t*o,n=i*o}s[r][r]=n}for(let e=0;e<=n;++e)a[0][e]=s[e][n];for(let e=0;e<=n;++e){let t=0,i=1;const c=[];for(let e=0;e<=n;++e)c[e]=o.slice(0);c[0][0]=1;for(let o=1;o<=r;++o){let r=0;const l=e-o,u=n-o;e>=o&&(c[i][0]=c[t][0]/s[u+1][l],r=c[i][0]*s[l][u]);const h=e-1<=u?o-1:n-e;for(let e=l>=-1?1:-l;e<=h;++e)c[i][e]=(c[t][e]-c[t][e-1])/s[u+1][l+e],r+=c[i][e]*s[l+e][u];e<=u&&(c[i][o]=-c[t][o-1]/s[u+1][e],r+=c[i][o]*s[e][u]),a[o][e]=r;const d=t;t=i,i=d}}let u=n;for(let e=1;e<=r;++e){for(let t=0;t<=n;++t)a[e][t]*=u;u*=n-e}return a}(s,r,e,o,t),l=[];for(let e=0;e<n.length;++e){const t=n[e].clone(),r=t.w;t.x*=r,t.y*=r,t.z*=r,l[e]=t}for(let t=0;t<=o;++t){const n=l[s-e].clone().multiplyScalar(c[t][0]);for(let r=1;r<=e;++r)n.add(l[s-e+r].clone().multiplyScalar(c[t][r]));a[t]=n}for(let e=o+1;e<=i+1;++e)a[e]=new He(0,0,0);return a}(e,t,n,r,i);return function(e){const t=e.length,n=[],r=[];for(let i=0;i<t;++i){const t=e[i];n[i]=new f(t.x,t.y,t.z),r[i]=t.w}const i=[];for(let e=0;e<t;++e){const t=n[e].clone();for(let n=1;n<=e;++n)t.sub(i[e-n].clone().multiplyScalar(Pa(e,n)*r[n]));i[e]=t.divideScalar(r[0])}return i}(o)}class Na extends Ve{constructor(e,t,n,r,i){super(),this.degree=e,this.knots=t,this.controlPoints=[],this.startKnot=r||0,this.endKnot=i||this.knots.length-1;for(let e=0;e<n.length;++e){const t=n[e];this.controlPoints[e]=new He(t.x,t.y,t.z,t.w)}}getPoint(e,t=new f){const n=t,r=this.knots[this.startKnot]+e*(this.knots[this.endKnot]-this.knots[this.startKnot]),i=function(e,t,n,r){const i=Ia(e,r,t),o=function(e,t,n,r){const i=[],o=[],a=[];i[0]=1;for(let s=1;s<=n;++s){o[s]=t-r[e+1-s],a[s]=r[e+s]-t;let n=0;for(let e=0;e<s;++e){const t=a[e+1],r=o[s-e],c=i[e]/(t+r);i[e]=n+t*c,n=r*c}i[s]=n}return i}(i,r,e,t),a=new He(0,0,0,0);for(let t=0;t<=e;++t){const r=n[i-e+t],s=o[t],c=r.w*s;a.x+=r.x*c,a.y+=r.y*c,a.z+=r.z*c,a.w+=r.w*s}return a}(this.degree,this.knots,this.controlPoints,r);return 1!==i.w&&i.divideScalar(i.w),n.set(i.x,i.y,i.z)}getTangent(e,t=new f){const n=t,r=this.knots[0]+e*(this.knots[this.knots.length-1]-this.knots[0]),i=_a(this.degree,this.knots,this.controlPoints,r,1);return n.copy(i[1]).normalize(),n}}let La,Da,ja;class Fa extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=""===i.path?J.extractUrlBase(e):i.path,a=new q(this.manager);a.setPath(i.path),a.setResponseType("arraybuffer"),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e,t){if(function(e){const t="Kaydara FBX Binary \0";return e.byteLength>=t.length&&t===ts(e,0,t.length)}(e))La=(new Va).parse(e);else{const t=ts(e);if(!function(e){const t=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let n=0;function r(t){const r=e[t-1];return e=e.slice(n+t),n++,r}for(let e=0;e<t.length;++e){if(r(1)===t[e])return!1}return!0}(t))throw new Error("THREE.FBXLoader: Unknown format.");if(Xa(t)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+Xa(t));La=(new Ha).parse(t)}const n=new ae(this.manager).setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin);return new Ua(n,this.manager).parse(La)}}class Ua{constructor(e,t){this.textureLoader=e,this.manager=t}parse(){Da=this.parseConnections();const e=this.parseImages(),t=this.parseTextures(e),n=this.parseMaterials(t),r=this.parseDeformers(),i=(new Ba).parse(r);return this.parseScene(r,i,n),ja}parseConnections(){const e=new Map;if("Connections"in La){La.Connections.connections.forEach(function(t){const n=t[0],r=t[1],i=t[2];e.has(n)||e.set(n,{parents:[],children:[]});const o={ID:r,relationship:i};e.get(n).parents.push(o),e.has(r)||e.set(r,{parents:[],children:[]});const a={ID:n,relationship:i};e.get(r).children.push(a)})}return e}parseImages(){const e={},t={};if("Video"in La.Objects){const n=La.Objects.Video;for(const r in n){const i=n[r];if(e[parseInt(r)]=i.RelativeFilename||i.Filename,"Content"in i){const e=i.Content instanceof ArrayBuffer&&i.Content.byteLength>0,o="string"==typeof i.Content&&""!==i.Content;if(e||o){const e=this.parseImage(n[r]);t[i.RelativeFilename||i.Filename]=e}}}}for(const n in e){const r=e[n];void 0!==t[r]?e[n]=t[r]:e[n]=e[n].split("\\").pop()}return e}parseImage(e){const t=e.Content,n=e.RelativeFilename||e.Filename,r=n.slice(n.lastIndexOf(".")+1).toLowerCase();let i;switch(r){case"bmp":i="image/bmp";break;case"jpg":case"jpeg":i="image/jpeg";break;case"png":i="image/png";break;case"tif":i="image/tiff";break;case"tga":null===this.manager.getHandler(".tga")&&console.warn("FBXLoader: TGA loader not found, skipping ",n),i="image/tga";break;default:return void console.warn('FBXLoader: Image type "'+r+'" is not supported.')}if("string"==typeof t)return"data:"+i+";base64,"+t;{const e=new Uint8Array(t);return window.URL.createObjectURL(new Blob([e],{type:i}))}}parseTextures(e){const t=new Map;if("Texture"in La.Objects){const n=La.Objects.Texture;for(const r in n){const i=this.parseTexture(n[r],e);t.set(parseInt(r),i)}}return t}parseTexture(e,t){const n=this.loadTexture(e,t);n.ID=e.id,n.name=e.attrName;const r=e.WrapModeU,i=e.WrapModeV,o=void 0!==r?r.value:0,a=void 0!==i?i.value:0;if(n.wrapS=0===o?me:be,n.wrapT=0===a?me:be,"Scaling"in e){const t=e.Scaling.value;n.repeat.x=t[0],n.repeat.y=t[1]}if("Translation"in e){const t=e.Translation.value;n.offset.x=t[0],n.offset.y=t[1]}return n}loadTexture(e,t){let n;const r=this.textureLoader.path,i=Da.get(e.id).children;let o;void 0!==i&&i.length>0&&void 0!==t[i[0].ID]&&(n=t[i[0].ID],0!==n.indexOf("blob:")&&0!==n.indexOf("data:")||this.textureLoader.setPath(void 0));const a=e.FileName.slice(-3).toLowerCase();if("tga"===a){const t=this.manager.getHandler(".tga");null===t?(console.warn("FBXLoader: TGA loader not found, creating placeholder texture for",e.RelativeFilename),o=new Ne):(t.setPath(this.textureLoader.path),o=t.load(n))}else if("dds"===a){const t=this.manager.getHandler(".dds");null===t?(console.warn("FBXLoader: DDS loader not found, creating placeholder texture for",e.RelativeFilename),o=new Ne):(t.setPath(this.textureLoader.path),o=t.load(n))}else"psd"===a?(console.warn("FBXLoader: PSD textures are not supported, creating placeholder texture for",e.RelativeFilename),o=new Ne):o=this.textureLoader.load(n);return this.textureLoader.setPath(r),o}parseMaterials(e){const t=new Map;if("Material"in La.Objects){const n=La.Objects.Material;for(const r in n){const i=this.parseMaterial(n[r],e);null!==i&&t.set(parseInt(r),i)}}return t}parseMaterial(e,t){const n=e.id,r=e.attrName;let i=e.ShadingModel;if("object"==typeof i&&(i=i.value),!Da.has(n))return null;const o=this.parseParameters(e,t,n);let a;switch(i.toLowerCase()){case"phong":a=new Be;break;case"lambert":a=new Ge;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',i),a=new Be}return a.setValues(o),a.name=r,a}parseParameters(e,t,n){const r={};e.BumpFactor&&(r.bumpScale=e.BumpFactor.value),e.Diffuse?r.color=(new K).fromArray(e.Diffuse.value).convertSRGBToLinear():!e.DiffuseColor||"Color"!==e.DiffuseColor.type&&"ColorRGB"!==e.DiffuseColor.type||(r.color=(new K).fromArray(e.DiffuseColor.value).convertSRGBToLinear()),e.DisplacementFactor&&(r.displacementScale=e.DisplacementFactor.value),e.Emissive?r.emissive=(new K).fromArray(e.Emissive.value).convertSRGBToLinear():!e.EmissiveColor||"Color"!==e.EmissiveColor.type&&"ColorRGB"!==e.EmissiveColor.type||(r.emissive=(new K).fromArray(e.EmissiveColor.value).convertSRGBToLinear()),e.EmissiveFactor&&(r.emissiveIntensity=parseFloat(e.EmissiveFactor.value)),e.Opacity&&(r.opacity=parseFloat(e.Opacity.value)),r.opacity<1&&(r.transparent=!0),e.ReflectionFactor&&(r.reflectivity=e.ReflectionFactor.value),e.Shininess&&(r.shininess=e.Shininess.value),e.Specular?r.specular=(new K).fromArray(e.Specular.value).convertSRGBToLinear():e.SpecularColor&&"Color"===e.SpecularColor.type&&(r.specular=(new K).fromArray(e.SpecularColor.value).convertSRGBToLinear());const i=this;return Da.get(n).children.forEach(function(e){const n=e.relationship;switch(n){case"Bump":r.bumpMap=i.getTexture(t,e.ID);break;case"Maya|TEX_ao_map":r.aoMap=i.getTexture(t,e.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":r.map=i.getTexture(t,e.ID),void 0!==r.map&&(r.map.colorSpace=Y);break;case"DisplacementColor":r.displacementMap=i.getTexture(t,e.ID);break;case"EmissiveColor":r.emissiveMap=i.getTexture(t,e.ID),void 0!==r.emissiveMap&&(r.emissiveMap.colorSpace=Y);break;case"NormalMap":case"Maya|TEX_normal_map":r.normalMap=i.getTexture(t,e.ID);break;case"ReflectionColor":r.envMap=i.getTexture(t,e.ID),void 0!==r.envMap&&(r.envMap.mapping=We,r.envMap.colorSpace=Y);break;case"SpecularColor":r.specularMap=i.getTexture(t,e.ID),void 0!==r.specularMap&&(r.specularMap.colorSpace=Y);break;case"TransparentColor":case"TransparencyFactor":r.alphaMap=i.getTexture(t,e.ID),r.transparent=!0;break;default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",n)}}),r}getTexture(e,t){return"LayeredTexture"in La.Objects&&t in La.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=Da.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in La.Objects){const n=La.Objects.Deformer;for(const r in n){const i=n[r],o=Da.get(parseInt(r));if("Skin"===i.attrType){const t=this.parseSkeleton(o,n);t.ID=r,o.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),t.geometryID=o.parents[0].ID,e[r]=t}else if("BlendShape"===i.attrType){const e={id:r};e.rawTargets=this.parseMorphTargets(o,n),e.id=r,o.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[r]=e}}}return{skeletons:e,morphTargets:t}}parseSkeleton(e,t){const n=[];return e.children.forEach(function(e){const r=t[e.ID];if("Cluster"!==r.attrType)return;const i={ID:e.ID,indices:[],weights:[],transformLink:(new N).fromArray(r.TransformLink.a)};"Indexes"in r&&(i.indices=r.Indexes.a,i.weights=r.Weights.a),n.push(i)}),{rawBones:n,bones:[]}}parseMorphTargets(e,t){const n=[];for(let r=0;r<e.children.length;r++){const i=e.children[r],o=t[i.ID],a={name:o.attrName,initialWeight:o.DeformPercent,id:o.id,fullWeights:o.FullWeights.a};if("BlendShapeChannel"!==o.attrType)return;a.geoID=Da.get(parseInt(i.ID)).children.filter(function(e){return void 0===e.relationship})[0].ID,n.push(a)}return n}parseScene(e,t,n){ja=new Oe;const r=this.parseModels(e.skeletons,t,n),i=La.Objects.Model,o=this;r.forEach(function(e){const t=i[e.ID];o.setLookAtProperties(e,t);Da.get(e.ID).parents.forEach(function(t){const n=r.get(t.ID);void 0!==n&&n.add(e)}),null===e.parent&&ja.add(e)}),this.bindSkeleton(e.skeletons,t,r),this.addGlobalSceneSettings(),ja.traverse(function(e){if(e.userData.transformData){e.parent&&(e.userData.transformData.parentMatrix=e.parent.matrix,e.userData.transformData.parentMatrixWorld=e.parent.matrixWorld);const t=Za(e.userData.transformData);e.applyMatrix4(t),e.updateWorldMatrix()}});const a=(new za).parse();1===ja.children.length&&ja.children[0].isGroup&&(ja.children[0].animations=a,ja=ja.children[0]),ja.animations=a}parseModels(e,t,n){const r=new Map,i=La.Objects.Model;for(const o in i){const a=parseInt(o),s=i[o],c=Da.get(a);let l=this.buildSkeleton(c,e,a,s.attrName);if(!l){switch(s.attrType){case"Camera":l=this.createCamera(c);break;case"Light":l=this.createLight(c);break;case"Mesh":l=this.createMesh(c,t,n);break;case"NurbsCurve":l=this.createCurve(c,t);break;case"LimbNode":case"Root":l=new Ie;break;default:l=new Oe}l.name=s.attrName?we.sanitizeNodeName(s.attrName):"",l.userData.originalName=s.attrName,l.ID=a}this.getTransformData(l,s),r.set(a,l)}return r}buildSkeleton(e,t,n,r){let i=null;return e.parents.forEach(function(e){for(const o in t){const a=t[o];a.rawBones.forEach(function(t,o){if(t.ID===e.ID){const e=i;i=new Ie,i.matrixWorld.copy(t.transformLink),i.name=r?we.sanitizeNodeName(r):"",i.userData.originalName=r,i.ID=n,a.bones[o]=i,null!==e&&i.add(e)}})}}),i}createCamera(e){let t,n;if(e.children.forEach(function(e){const t=La.Objects.NodeAttribute[e.ID];void 0!==t&&(n=t)}),void 0===n)t=new x;else{let e=0;void 0!==n.CameraProjectionType&&1===n.CameraProjectionType.value&&(e=1);let r=1;void 0!==n.NearPlane&&(r=n.NearPlane.value/1e3);let i=1e3;void 0!==n.FarPlane&&(i=n.FarPlane.value/1e3);let o=window.innerWidth,a=window.innerHeight;void 0!==n.AspectWidth&&void 0!==n.AspectHeight&&(o=n.AspectWidth.value,a=n.AspectHeight.value);const s=o/a;let c=45;void 0!==n.FieldOfView&&(c=n.FieldOfView.value);const l=n.FocalLength?n.FocalLength.value:null;switch(e){case 0:t=new ke(c,s,r,i),null!==l&&t.setFocalLength(l);break;case 1:t=new Se(-o/2,o/2,a/2,-a/2,r,i);break;default:console.warn("THREE.FBXLoader: Unknown camera type "+e+"."),t=new x}}return t}createLight(e){let t,n;if(e.children.forEach(function(e){const t=La.Objects.NodeAttribute[e.ID];void 0!==t&&(n=t)}),void 0===n)t=new x;else{let e;e=void 0===n.LightType?0:n.LightType.value;let r=16777215;void 0!==n.Color&&(r=(new K).fromArray(n.Color.value).convertSRGBToLinear());let i=void 0===n.Intensity?1:n.Intensity.value/100;void 0!==n.CastLightOnObject&&0===n.CastLightOnObject.value&&(i=0);let o=0;void 0!==n.FarAttenuationEnd&&(o=void 0!==n.EnableFarAttenuation&&0===n.EnableFarAttenuation.value?0:n.FarAttenuationEnd.value);const a=1;switch(e){case 0:t=new ne(r,i,o,a);break;case 1:t=new re(r,i);break;case 2:let e=Math.PI/3;void 0!==n.InnerAngle&&(e=d.degToRad(n.InnerAngle.value));let s=0;void 0!==n.OuterAngle&&(s=d.degToRad(n.OuterAngle.value),s=Math.max(s,1)),t=new te(r,i,o,e,s,a);break;default:console.warn("THREE.FBXLoader: Unknown light type "+n.LightType.value+", defaulting to a PointLight."),t=new ne(r,i)}void 0!==n.CastShadows&&1===n.CastShadows.value&&(t.castShadow=!0)}return t}createMesh(e,t,n){let r,i=null,o=null;const a=[];return e.children.forEach(function(e){t.has(e.ID)&&(i=t.get(e.ID)),n.has(e.ID)&&a.push(n.get(e.ID))}),a.length>1?o=a:a.length>0?o=a[0]:(o=new Be({name:X.DEFAULT_MATERIAL_NAME,color:13421772}),a.push(o)),"color"in i.attributes&&a.forEach(function(e){e.vertexColors=!0}),i.FBX_Deformer?(r=new Ee(i,o),r.normalizeSkinWeights()):r=new S(i,o),r}createCurve(e,t){const n=e.children.reduce(function(e,n){return t.has(n.ID)&&(e=t.get(n.ID)),e},null),r=new T({name:X.DEFAULT_MATERIAL_NAME,color:3342591,linewidth:1});return new R(n,r)}getTransformData(e,t){const n={};"InheritType"in t&&(n.inheritType=parseInt(t.InheritType.value)),n.eulerOrder="RotationOrder"in t?Ja(t.RotationOrder.value):"ZYX","Lcl_Translation"in t&&(n.translation=t.Lcl_Translation.value),"PreRotation"in t&&(n.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(n.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(n.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(n.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(n.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(n.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(n.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(n.rotationPivot=t.RotationPivot.value),e.userData.transformData=n}setLookAtProperties(e,t){if("LookAtProperty"in t){Da.get(e.ID).children.forEach(function(t){if("LookAtProperty"===t.relationship){const n=La.Objects.Model[t.ID];if("Lcl_Translation"in n){const t=n.Lcl_Translation.value;void 0!==e.target?(e.target.position.fromArray(t),ja.add(e.target)):e.lookAt((new f).fromArray(t))}}})}}bindSkeleton(e,t,n){const r=this.parsePoseNodes();for(const i in e){const o=e[i];Da.get(parseInt(o.ID)).parents.forEach(function(e){if(t.has(e.ID)){const t=e.ID;Da.get(t).parents.forEach(function(e){if(n.has(e.ID)){n.get(e.ID).bind(new Me(o.bones),r[e.ID])}})}})}}parsePoseNodes(){const e={};if("Pose"in La.Objects){const t=La.Objects.Pose;for(const n in t)if("BindPose"===t[n].attrType&&t[n].NbPoseNodes>0){const r=t[n].PoseNode;Array.isArray(r)?r.forEach(function(t){e[t.Node]=(new N).fromArray(t.Matrix.a)}):e[r.Node]=(new N).fromArray(r.Matrix.a)}}return e}addGlobalSceneSettings(){if("GlobalSettings"in La){if("AmbientColor"in La.GlobalSettings){const e=La.GlobalSettings.AmbientColor.value,t=e[0],n=e[1],r=e[2];if(0!==t||0!==n||0!==r){const e=new K(t,n,r).convertSRGBToLinear();ja.add(new Xe(e,1))}}"UnitScaleFactor"in La.GlobalSettings&&(ja.userData.unitScaleFactor=La.GlobalSettings.UnitScaleFactor.value)}}}class Ba{constructor(){this.negativeMaterialIndices=!1}parse(e){const t=new Map;if("Geometry"in La.Objects){const n=La.Objects.Geometry;for(const r in n){const i=Da.get(parseInt(r)),o=this.parseGeometry(i,n[r],e);t.set(parseInt(r),o)}}return!0===this.negativeMaterialIndices&&console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."),t}parseGeometry(e,t,n){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,n);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,n){const r=n.skeletons,i=[],o=e.parents.map(function(e){return La.Objects.Model[e.ID]});if(0===o.length)return;const a=e.children.reduce(function(e,t){return void 0!==r[t.ID]&&(e=r[t.ID]),e},null);e.children.forEach(function(e){void 0!==n.morphTargets[e.ID]&&i.push(n.morphTargets[e.ID])});const s=o[0],c={};"RotationOrder"in s&&(c.eulerOrder=Ja(s.RotationOrder.value)),"InheritType"in s&&(c.inheritType=parseInt(s.InheritType.value)),"GeometricTranslation"in s&&(c.translation=s.GeometricTranslation.value),"GeometricRotation"in s&&(c.rotation=s.GeometricRotation.value),"GeometricScaling"in s&&(c.scale=s.GeometricScaling.value);const l=Za(c);return this.genGeometry(t,a,i,l)}genGeometry(e,t,n,r){const i=new O;e.attrName&&(i.name=e.attrName);const o=this.parseGeoNode(e,t),a=this.genBuffers(o),s=new k(a.vertex,3);if(s.applyMatrix4(r),i.setAttribute("position",s),a.colors.length>0&&i.setAttribute("color",new k(a.colors,3)),t&&(i.setAttribute("skinIndex",new qe(a.weightsIndices,4)),i.setAttribute("skinWeight",new k(a.vertexWeights,4)),i.FBX_Deformer=t),a.normal.length>0){const e=(new Ye).getNormalMatrix(r),t=new k(a.normal,3);t.applyNormalMatrix(e),i.setAttribute("normal",t)}if(a.uvs.forEach(function(e,t){const n=0===t?"uv":`uv${t}`;i.setAttribute(n,new k(a.uvs[t],2))}),o.material&&"AllSame"!==o.material.mappingType){let e=a.materialIndex[0],t=0;if(a.materialIndex.forEach(function(n,r){n!==e&&(i.addGroup(t,r-t,e),e=n,t=r)}),i.groups.length>0){const t=i.groups[i.groups.length-1],n=t.start+t.count;n!==a.materialIndex.length&&i.addGroup(n,a.materialIndex.length-n,e)}0===i.groups.length&&i.addGroup(0,a.materialIndex.length,a.materialIndex[0])}return this.addMorphTargets(i,e,n,r),i}parseGeoNode(e,t){const n={};if(n.vertexPositions=void 0!==e.Vertices?e.Vertices.a:[],n.vertexIndices=void 0!==e.PolygonVertexIndex?e.PolygonVertexIndex.a:[],e.LayerElementColor&&(n.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(n.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(n.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){n.uv=[];let t=0;for(;e.LayerElementUV[t];)e.LayerElementUV[t].UV&&n.uv.push(this.parseUVs(e.LayerElementUV[t])),t++}return n.weightTable={},null!==t&&(n.skeleton=t,t.rawBones.forEach(function(e,t){e.indices.forEach(function(r,i){void 0===n.weightTable[r]&&(n.weightTable[r]=[]),n.weightTable[r].push({id:t,weight:e.weights[i]})})})),n}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let n=0,r=0,i=!1,o=[],a=[],s=[],c=[],l=[],u=[];const h=this;return e.vertexIndices.forEach(function(d,p){let f,m=!1;d<0&&(d^=-1,m=!0);let g=[],b=[];if(o.push(3*d,3*d+1,3*d+2),e.color){const t=Ka(p,n,d,e.color);s.push(t[0],t[1],t[2])}if(e.skeleton){if(void 0!==e.weightTable[d]&&e.weightTable[d].forEach(function(e){b.push(e.weight),g.push(e.id)}),b.length>4){i||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),i=!0);const e=[0,0,0,0],t=[0,0,0,0];b.forEach(function(n,r){let i=n,o=g[r];t.forEach(function(t,n,r){if(i>t){r[n]=i,i=t;const a=e[n];e[n]=o,o=a}})}),g=e,b=t}for(;b.length<4;)b.push(0),g.push(0);for(let e=0;e<4;++e)l.push(b[e]),u.push(g[e])}if(e.normal){const t=Ka(p,n,d,e.normal);a.push(t[0],t[1],t[2])}e.material&&"AllSame"!==e.material.mappingType&&(f=Ka(p,n,d,e.material)[0],f<0&&(h.negativeMaterialIndices=!0,f=0)),e.uv&&e.uv.forEach(function(e,t){const r=Ka(p,n,d,e);void 0===c[t]&&(c[t]=[]),c[t].push(r[0]),c[t].push(r[1])}),r++,m&&(h.genFace(t,e,o,f,a,s,c,l,u,r),n++,r=0,o=[],a=[],s=[],c=[],l=[],u=[])}),t}getNormalNewell(e){const t=new f(0,0,0);for(let n=0;n<e.length;n++){const r=e[n],i=e[(n+1)%e.length];t.x+=(r.y-i.y)*(r.z+i.z),t.y+=(r.z-i.z)*(r.x+i.x),t.z+=(r.x-i.x)*(r.y+i.y)}return t.normalize(),t}getNormalTangentAndBitangent(e){const t=this.getNormalNewell(e),n=(Math.abs(t.z)>.5?new f(0,1,0):new f(0,0,1)).cross(t).normalize(),r=t.clone().cross(n).normalize();return{normal:t,tangent:n,bitangent:r}}flattenVertex(e,t,n){return new v(e.dot(t),e.dot(n))}genFace(e,t,n,r,i,o,a,s,c,l){let u;if(l>3){const e=[];for(let r=0;r<n.length;r+=3)e.push(new f(t.vertexPositions[n[r]],t.vertexPositions[n[r+1]],t.vertexPositions[n[r+2]]));const{tangent:r,bitangent:i}=this.getNormalTangentAndBitangent(e),o=[];for(const t of e)o.push(this.flattenVertex(t,r,i));u=Ke.triangulateShape(o,[])}else u=[[0,1,2]];for(const[l,h,d]of u)e.vertex.push(t.vertexPositions[n[3*l]]),e.vertex.push(t.vertexPositions[n[3*l+1]]),e.vertex.push(t.vertexPositions[n[3*l+2]]),e.vertex.push(t.vertexPositions[n[3*h]]),e.vertex.push(t.vertexPositions[n[3*h+1]]),e.vertex.push(t.vertexPositions[n[3*h+2]]),e.vertex.push(t.vertexPositions[n[3*d]]),e.vertex.push(t.vertexPositions[n[3*d+1]]),e.vertex.push(t.vertexPositions[n[3*d+2]]),t.skeleton&&(e.vertexWeights.push(s[4*l]),e.vertexWeights.push(s[4*l+1]),e.vertexWeights.push(s[4*l+2]),e.vertexWeights.push(s[4*l+3]),e.vertexWeights.push(s[4*h]),e.vertexWeights.push(s[4*h+1]),e.vertexWeights.push(s[4*h+2]),e.vertexWeights.push(s[4*h+3]),e.vertexWeights.push(s[4*d]),e.vertexWeights.push(s[4*d+1]),e.vertexWeights.push(s[4*d+2]),e.vertexWeights.push(s[4*d+3]),e.weightsIndices.push(c[4*l]),e.weightsIndices.push(c[4*l+1]),e.weightsIndices.push(c[4*l+2]),e.weightsIndices.push(c[4*l+3]),e.weightsIndices.push(c[4*h]),e.weightsIndices.push(c[4*h+1]),e.weightsIndices.push(c[4*h+2]),e.weightsIndices.push(c[4*h+3]),e.weightsIndices.push(c[4*d]),e.weightsIndices.push(c[4*d+1]),e.weightsIndices.push(c[4*d+2]),e.weightsIndices.push(c[4*d+3])),t.color&&(e.colors.push(o[3*l]),e.colors.push(o[3*l+1]),e.colors.push(o[3*l+2]),e.colors.push(o[3*h]),e.colors.push(o[3*h+1]),e.colors.push(o[3*h+2]),e.colors.push(o[3*d]),e.colors.push(o[3*d+1]),e.colors.push(o[3*d+2])),t.material&&"AllSame"!==t.material.mappingType&&(e.materialIndex.push(r),e.materialIndex.push(r),e.materialIndex.push(r)),t.normal&&(e.normal.push(i[3*l]),e.normal.push(i[3*l+1]),e.normal.push(i[3*l+2]),e.normal.push(i[3*h]),e.normal.push(i[3*h+1]),e.normal.push(i[3*h+2]),e.normal.push(i[3*d]),e.normal.push(i[3*d+1]),e.normal.push(i[3*d+2])),t.uv&&t.uv.forEach(function(t,n){void 0===e.uvs[n]&&(e.uvs[n]=[]),e.uvs[n].push(a[n][2*l]),e.uvs[n].push(a[n][2*l+1]),e.uvs[n].push(a[n][2*h]),e.uvs[n].push(a[n][2*h+1]),e.uvs[n].push(a[n][2*d]),e.uvs[n].push(a[n][2*d+1])})}addMorphTargets(e,t,n,r){if(0===n.length)return;e.morphTargetsRelative=!0,e.morphAttributes.position=[];const i=this;n.forEach(function(n){n.rawTargets.forEach(function(n){const o=La.Objects.Geometry[n.geoID];void 0!==o&&i.genMorphGeometry(e,t,o,r,n.name)})})}genMorphGeometry(e,t,n,r,i){const o=void 0!==t.PolygonVertexIndex?t.PolygonVertexIndex.a:[],a=void 0!==n.Vertices?n.Vertices.a:[],s=void 0!==n.Indexes?n.Indexes.a:[],c=3*e.attributes.position.count,l=new Float32Array(c);for(let e=0;e<s.length;e++){const t=3*s[e];l[t]=a[3*e],l[t+1]=a[3*e+1],l[t+2]=a[3*e+2]}const u={vertexIndices:o,vertexPositions:l},h=this.genBuffers(u),d=new k(h.vertex,3);d.name=i||n.attrName,d.applyMatrix4(r),e.morphAttributes.position.push(d)}parseNormals(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,r=e.Normals.a;let i=[];return"IndexToDirect"===n&&("NormalIndex"in e?i=e.NormalIndex.a:"NormalsIndex"in e&&(i=e.NormalsIndex.a)),{dataSize:3,buffer:r,indices:i,mappingType:t,referenceType:n}}parseUVs(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,r=e.UV.a;let i=[];return"IndexToDirect"===n&&(i=e.UVIndex.a),{dataSize:2,buffer:r,indices:i,mappingType:t,referenceType:n}}parseVertexColors(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,r=e.Colors.a;let i=[];"IndexToDirect"===n&&(i=e.ColorIndex.a);for(let e=0,t=new K;e<r.length;e+=4)t.fromArray(r,e).convertSRGBToLinear().toArray(r,e);return{dataSize:4,buffer:r,indices:i,mappingType:t,referenceType:n}}parseMaterialIndices(e){const t=e.MappingInformationType,n=e.ReferenceInformationType;if("NoMappingInformation"===t)return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:n};const r=e.Materials.a,i=[];for(let e=0;e<r.length;++e)i.push(e);return{dataSize:1,buffer:r,indices:i,mappingType:t,referenceType:n}}parseNurbsGeometry(e){const t=parseInt(e.Order);if(isNaN(t))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",e.Order,e.id),new O;const n=t-1,r=e.KnotVector.a,i=[],o=e.Points.a;for(let e=0,t=o.length;e<t;e+=4)i.push((new He).fromArray(o,e));let a,s;if("Closed"===e.Form)i.push(i[0]);else if("Periodic"===e.Form){a=n,s=r.length-1-a;for(let e=0;e<n;++e)i.push(i[e])}const c=new Na(n,r,i,a,s).getPoints(12*i.length);return(new O).setFromPoints(c)}}class za{parse(){const e=[],t=this.parseClips();if(void 0!==t)for(const n in t){const r=t[n],i=this.addClip(r);e.push(i)}return e}parseClips(){if(void 0===La.Objects.AnimationCurve)return;const e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);const t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}parseAnimationCurveNodes(){const e=La.Objects.AnimationCurveNode,t=new Map;for(const n in e){const r=e[n];if(null!==r.attrName.match(/S|R|T|DeformPercent/)){const e={id:r.id,attr:r.attrName,curves:{}};t.set(e.id,e)}}return t}parseAnimationCurves(e){const t=La.Objects.AnimationCurve;for(const n in t){const r={id:t[n].id,times:t[n].KeyTime.a.map(qa),values:t[n].KeyValueFloat.a},i=Da.get(r.id);if(void 0!==i){const t=i.parents[0].ID,n=i.parents[0].relationship;n.match(/X/)?e.get(t).curves.x=r:n.match(/Y/)?e.get(t).curves.y=r:n.match(/Z/)?e.get(t).curves.z=r:n.match(/DeformPercent/)&&e.has(t)&&(e.get(t).curves.morph=r)}}}parseAnimationLayers(e){const t=La.Objects.AnimationLayer,n=new Map;for(const r in t){const t=[],i=Da.get(parseInt(r));if(void 0!==i){i.children.forEach(function(n,r){if(e.has(n.ID)){const i=e.get(n.ID);if(void 0!==i.curves.x||void 0!==i.curves.y||void 0!==i.curves.z){if(void 0===t[r]){const e=Da.get(n.ID).parents.filter(function(e){return void 0!==e.relationship})[0].ID;if(void 0!==e){const i=La.Objects.Model[e.toString()];if(void 0===i)return void console.warn("THREE.FBXLoader: Encountered a unused curve.",n);const o={modelName:i.attrName?we.sanitizeNodeName(i.attrName):"",ID:i.id,initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1]};ja.traverse(function(e){e.ID===i.id&&(o.transform=e.matrix,e.userData.transformData&&(o.eulerOrder=e.userData.transformData.eulerOrder))}),o.transform||(o.transform=new N),"PreRotation"in i&&(o.preRotation=i.PreRotation.value),"PostRotation"in i&&(o.postRotation=i.PostRotation.value),t[r]=o}}t[r]&&(t[r][i.attr]=i)}else if(void 0!==i.curves.morph){if(void 0===t[r]){const e=Da.get(n.ID).parents.filter(function(e){return void 0!==e.relationship})[0].ID,i=Da.get(e).parents[0].ID,o=Da.get(i).parents[0].ID,a=Da.get(o).parents[0].ID,s=La.Objects.Model[a],c={modelName:s.attrName?we.sanitizeNodeName(s.attrName):"",morphName:La.Objects.Deformer[e].attrName};t[r]=c}t[r][i.attr]=i}}}),n.set(parseInt(r),t)}}return n}parseAnimStacks(e){const t=La.Objects.AnimationStack,n={};for(const r in t){const i=Da.get(parseInt(r)).children;i.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const o=e.get(i[0].ID);n[r]={name:t[r].attrName,layer:o}}return n}addClip(e){let t=[];const n=this;return e.layer.forEach(function(e){t=t.concat(n.generateTracks(e))}),new Re(e.name,-1,t)}generateTracks(e){const t=[];let n=new f,r=new f;if(e.transform&&e.transform.decompose(n,new y,r),n=n.toArray(),r=r.toArray(),void 0!==e.T&&Object.keys(e.T.curves).length>0){const r=this.generateVectorTrack(e.modelName,e.T.curves,n,"position");void 0!==r&&t.push(r)}if(void 0!==e.R&&Object.keys(e.R.curves).length>0){const n=this.generateRotationTrack(e.modelName,e.R.curves,e.preRotation,e.postRotation,e.eulerOrder);void 0!==n&&t.push(n)}if(void 0!==e.S&&Object.keys(e.S.curves).length>0){const n=this.generateVectorTrack(e.modelName,e.S.curves,r,"scale");void 0!==n&&t.push(n)}if(void 0!==e.DeformPercent){const n=this.generateMorphTrack(e);void 0!==n&&t.push(n)}return t}generateVectorTrack(e,t,n,r){const i=this.getTimesForAllAxes(t),o=this.getKeyframeTrackValues(i,t,n);return new Le(e+"."+r,i,o)}generateRotationTrack(e,t,n,r,i){let o,a;if(void 0!==t.x&&void 0!==t.y&&void 0!==t.z){const e=this.interpolateRotations(t.x,t.y,t.z,i);o=e[0],a=e[1]}void 0!==n&&((n=n.map(d.degToRad)).push(i),n=(new _).fromArray(n),n=(new y).setFromEuler(n)),void 0!==r&&((r=r.map(d.degToRad)).push(i),r=(new _).fromArray(r),r=(new y).setFromEuler(r).invert());const s=new y,c=new _,l=[];if(!a||!o)return new je(e+".quaternion",[],[]);for(let e=0;e<a.length;e+=3){if(c.set(a[e],a[e+1],a[e+2],i),s.setFromEuler(c),void 0!==n&&s.premultiply(n),void 0!==r&&s.multiply(r),e>2){(new y).fromArray(l,(e-3)/3*4).dot(s)<0&&s.set(-s.x,-s.y,-s.z,-s.w)}s.toArray(l,e/3*4)}return new je(e+".quaternion",o,l)}generateMorphTrack(e){const t=e.DeformPercent.curves.morph,n=t.values.map(function(e){return e/100}),r=ja.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new De(e.modelName+".morphTargetInfluences["+r+"]",t.times,n)}getTimesForAllAxes(e){let t=[];if(void 0!==e.x&&(t=t.concat(e.x.times)),void 0!==e.y&&(t=t.concat(e.y.times)),void 0!==e.z&&(t=t.concat(e.z.times)),t=t.sort(function(e,t){return e-t}),t.length>1){let e=1,n=t[0];for(let r=1;r<t.length;r++){const i=t[r];i!==n&&(t[e]=i,n=i,e++)}t=t.slice(0,e)}return t}getKeyframeTrackValues(e,t,n){const r=n,i=[];let o=-1,a=-1,s=-1;return e.forEach(function(e){if(t.x&&(o=t.x.times.indexOf(e)),t.y&&(a=t.y.times.indexOf(e)),t.z&&(s=t.z.times.indexOf(e)),-1!==o){const e=t.x.values[o];i.push(e),r[0]=e}else i.push(r[0]);if(-1!==a){const e=t.y.values[a];i.push(e),r[1]=e}else i.push(r[1]);if(-1!==s){const e=t.z.values[s];i.push(e),r[2]=e}else i.push(r[2])}),i}interpolateRotations(e,t,n,r){const i=[],o=[];i.push(e.times[0]),o.push(d.degToRad(e.values[0])),o.push(d.degToRad(t.values[0])),o.push(d.degToRad(n.values[0]));for(let a=1;a<e.values.length;a++){const s=[e.values[a-1],t.values[a-1],n.values[a-1]];if(isNaN(s[0])||isNaN(s[1])||isNaN(s[2]))continue;const c=s.map(d.degToRad),l=[e.values[a],t.values[a],n.values[a]];if(isNaN(l[0])||isNaN(l[1])||isNaN(l[2]))continue;const u=l.map(d.degToRad),h=[l[0]-s[0],l[1]-s[1],l[2]-s[2]],p=[Math.abs(h[0]),Math.abs(h[1]),Math.abs(h[2])];if(p[0]>=180||p[1]>=180||p[2]>=180){const t=Math.max(...p)/180,n=new _(...c,r),s=new _(...u,r),l=(new y).setFromEuler(n),h=(new y).setFromEuler(s);l.dot(h)&&h.set(-h.x,-h.y,-h.z,-h.w);const d=e.times[a-1],f=e.times[a]-d,m=new y,g=new _;for(let e=0;e<1;e+=1/t)m.copy(l.clone().slerp(h.clone(),e)),i.push(d+e*f),g.setFromQuaternion(m,r),o.push(g.x),o.push(g.y),o.push(g.z)}else i.push(e.times[a]),o.push(d.degToRad(e.values[a])),o.push(d.degToRad(t.values[a])),o.push(d.degToRad(n.values[a]))}return[i,o]}}class Ha{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new Wa,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,n=e.split(/[\r\n]+/);return n.forEach(function(e,r){const i=e.match(/^[\s\t]*;/),o=e.match(/^[\s\t]*$/);if(i||o)return;const a=e.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),s=e.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),c=e.match("^\\t{"+(t.currentIndent-1)+"}}");a?t.parseNodeBegin(e,a):s?t.parseNodeProperty(e,s,n[++r]):c?t.popStack():e.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(e)}),this.allNodes}parseNodeBegin(e,t){const n=t[1].trim().replace(/^"/,"").replace(/"$/,""),r=t[2].split(",").map(function(e){return e.trim().replace(/^"/,"").replace(/"$/,"")}),i={name:n},o=this.parseNodeAttr(r),a=this.getCurrentNode();0===this.currentIndent?this.allNodes.add(n,i):n in a?("PoseNode"===n?a.PoseNode.push(i):void 0!==a[n].id&&(a[n]={},a[n][a[n].id]=a[n]),""!==o.id&&(a[n][o.id]=i)):"number"==typeof o.id?(a[n]={},a[n][o.id]=i):"Properties70"!==n&&(a[n]="PoseNode"===n?[i]:i),"number"==typeof o.id&&(i.id=o.id),""!==o.name&&(i.attrName=o.name),""!==o.type&&(i.attrType=o.type),this.pushStack(i)}parseNodeAttr(e){let t=e[0];""!==e[0]&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let n="",r="";return e.length>1&&(n=e[1].replace(/^(\w+)::/,""),r=e[2]),{id:t,name:n,type:r}}parseNodeProperty(e,t,n){let r=t[1].replace(/^"/,"").replace(/"$/,"").trim(),i=t[2].replace(/^"/,"").replace(/"$/,"").trim();"Content"===r&&","===i&&(i=n.replace(/"/g,"").replace(/,$/,"").trim());const o=this.getCurrentNode();if("Properties70"!==o.name){if("C"===r){const e=i.split(",").slice(1),t=parseInt(e[0]),n=parseInt(e[1]);let a=i.split(",").slice(3);a=a.map(function(e){return e.trim().replace(/^"/,"")}),r="connections",i=[t,n],function(e,t){for(let n=0,r=e.length,i=t.length;n<i;n++,r++)e[r]=t[n]}(i,a),void 0===o[r]&&(o[r]=[])}"Node"===r&&(o.id=i),r in o&&Array.isArray(o[r])?o[r].push(i):"a"!==r?o[r]=i:o.a=i,this.setCurrentProp(o,r),"a"===r&&","!==i.slice(-1)&&(o.a=es(i))}else this.parseNodeSpecialProperty(e,r,i)}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,","!==e.slice(-1)&&(t.a=es(t.a))}parseNodeSpecialProperty(e,t,n){const r=n.split('",').map(function(e){return e.trim().replace(/^\"/,"").replace(/\s/,"_")}),i=r[0],o=r[1],a=r[2],s=r[3];let c=r[4];switch(o){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":c=parseFloat(c);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":c=es(c)}this.getPrevNode()[i]={type:o,type2:a,flag:s,value:c},this.setCurrentProp(this.getPrevNode(),i)}}class Va{parse(e){const t=new Ga(e);t.skip(23);const n=t.getUint32();if(n<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+n);const r=new Wa;for(;!this.endOfContent(t);){const e=this.parseNode(t,n);null!==e&&r.add(e.name,e)}return r}endOfContent(e){return e.size()%16==0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const n={},r=t>=7500?e.getUint64():e.getUint32(),i=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const o=e.getUint8(),a=e.getString(o);if(0===r)return null;const s=[];for(let t=0;t<i;t++)s.push(this.parseProperty(e));const c=s.length>0?s[0]:"",l=s.length>1?s[1]:"",u=s.length>2?s[2]:"";for(n.singleProperty=1===i&&e.getOffset()===r;r>e.getOffset();){const r=this.parseNode(e,t);null!==r&&this.parseSubNode(a,n,r)}return n.propertyList=s,"number"==typeof c&&(n.id=c),""!==l&&(n.attrName=l),""!==u&&(n.attrType=u),""!==a&&(n.name=a),n}parseSubNode(e,t,n){if(!0===n.singleProperty){const e=n.propertyList[0];Array.isArray(e)?(t[n.name]=n,n.a=e):t[n.name]=e}else if("Connections"===e&&"C"===n.name){const e=[];n.propertyList.forEach(function(t,n){0!==n&&e.push(t)}),void 0===t.connections&&(t.connections=[]),t.connections.push(e)}else if("Properties70"===n.name){Object.keys(n).forEach(function(e){t[e]=n[e]})}else if("Properties70"===e&&"P"===n.name){let e=n.propertyList[0],r=n.propertyList[1];const i=n.propertyList[2],o=n.propertyList[3];let a;0===e.indexOf("Lcl ")&&(e=e.replace("Lcl ","Lcl_")),0===r.indexOf("Lcl ")&&(r=r.replace("Lcl ","Lcl_")),a="Color"===r||"ColorRGB"===r||"Vector"===r||"Vector3D"===r||0===r.indexOf("Lcl_")?[n.propertyList[4],n.propertyList[5],n.propertyList[6]]:n.propertyList[4],t[e]={type:r,type2:i,flag:o,value:a}}else void 0===t[n.name]?"number"==typeof n.id?(t[n.name]={},t[n.name][n.id]=n):t[n.name]=n:"PoseNode"===n.name?(Array.isArray(t[n.name])||(t[n.name]=[t[n.name]]),t[n.name].push(n)):void 0===t[n.name][n.id]&&(t[n.name][n.id]=n)}parseProperty(e){const t=e.getString(1);let n;switch(t){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return n=e.getUint32(),e.getArrayBuffer(n);case"S":return n=e.getUint32(),e.getString(n);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const r=e.getUint32(),i=e.getUint32(),o=e.getUint32();if(0===i)switch(t){case"b":case"c":return e.getBooleanArray(r);case"d":return e.getFloat64Array(r);case"f":return e.getFloat32Array(r);case"i":return e.getInt32Array(r);case"l":return e.getInt64Array(r)}const a=Nt(new Uint8Array(e.getArrayBuffer(o))),s=new Ga(a.buffer);switch(t){case"b":case"c":return s.getBooleanArray(r);case"d":return s.getFloat64Array(r);case"f":return s.getFloat32Array(r);case"i":return s.getInt32Array(r);case"l":return s.getInt64Array(r)}break;default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}}class Ga{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=void 0===t||t,this._textDecoder=new TextDecoder}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return!(1&~this.getUint8())}getBooleanArray(e){const t=[];for(let n=0;n<e;n++)t.push(this.getBoolean());return t}getUint8(){const e=this.dv.getUint8(this.offset);return this.offset+=1,e}getInt16(){const e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}getInt32(){const e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}getInt32Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getInt32());return t}getUint32(){const e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}getInt64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),2147483648&t?(t=4294967295&~t,e=4294967295&~e,4294967295===e&&(t=t+1&4294967295),e=e+1&4294967295,-(4294967296*t+e)):4294967296*t+e}getInt64Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getInt64());return t}getUint64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),4294967296*t+e}getFloat32(){const e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}getFloat32Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getFloat32());return t}getFloat64(){const e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}getFloat64Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getFloat64());return t}getArrayBuffer(e){const t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}getString(e){const t=this.offset;let n=new Uint8Array(this.dv.buffer,t,e);this.skip(e);const r=n.indexOf(0);return r>=0&&(n=new Uint8Array(this.dv.buffer,t,r)),this._textDecoder.decode(n)}}class Wa{add(e,t){this[e]=t}}function Xa(e){const t=e.match(/FBXVersion: (\d+)/);if(t){return parseInt(t[1])}throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function qa(e){return e/46186158e3}const Ya=[];function Ka(e,t,n,r){let i;switch(r.mappingType){case"ByPolygonVertex":i=e;break;case"ByPolygon":i=t;break;case"ByVertice":i=n;break;case"AllSame":i=r.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+r.mappingType)}"IndexToDirect"===r.referenceType&&(i=r.indices[i]);const o=i*r.dataSize,a=o+r.dataSize;return function(e,t,n,r){for(let i=n,o=0;i<r;i++,o++)e[o]=t[i];return e}(Ya,r.buffer,o,a)}const Qa=new _,$a=new f;function Za(e){const t=new N,n=new N,r=new N,i=new N,o=new N,a=new N,s=new N,c=new N,l=new N,u=new N,h=new N,p=new N,m=e.inheritType?e.inheritType:0;if(e.translation&&t.setPosition($a.fromArray(e.translation)),e.preRotation){const t=e.preRotation.map(d.degToRad);t.push(e.eulerOrder||_.DEFAULT_ORDER),n.makeRotationFromEuler(Qa.fromArray(t))}if(e.rotation){const t=e.rotation.map(d.degToRad);t.push(e.eulerOrder||_.DEFAULT_ORDER),r.makeRotationFromEuler(Qa.fromArray(t))}if(e.postRotation){const t=e.postRotation.map(d.degToRad);t.push(e.eulerOrder||_.DEFAULT_ORDER),i.makeRotationFromEuler(Qa.fromArray(t)),i.invert()}e.scale&&o.scale($a.fromArray(e.scale)),e.scalingOffset&&s.setPosition($a.fromArray(e.scalingOffset)),e.scalingPivot&&a.setPosition($a.fromArray(e.scalingPivot)),e.rotationOffset&&c.setPosition($a.fromArray(e.rotationOffset)),e.rotationPivot&&l.setPosition($a.fromArray(e.rotationPivot)),e.parentMatrixWorld&&(h.copy(e.parentMatrix),u.copy(e.parentMatrixWorld));const g=n.clone().multiply(r).multiply(i),b=new N;b.extractRotation(u);const y=new N;y.copyPosition(u);const v=y.clone().invert().multiply(u),x=b.clone().invert().multiply(v),w=o,E=new N;if(0===m)E.copy(b).multiply(g).multiply(x).multiply(w);else if(1===m)E.copy(b).multiply(x).multiply(g).multiply(w);else{const e=(new N).scale((new f).setFromMatrixScale(h)).clone().invert(),t=x.clone().multiply(e);E.copy(b).multiply(g).multiply(t).multiply(w)}const T=l.clone().invert(),A=a.clone().invert();let C=t.clone().multiply(c).multiply(l).multiply(n).multiply(r).multiply(i).multiply(T).multiply(s).multiply(a).multiply(o).multiply(A);const O=(new N).copyPosition(C),k=u.clone().multiply(O);return p.copyPosition(k),C=p.clone().multiply(E),C.premultiply(u.invert()),C}function Ja(e){const t=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return 6===(e=e||0)?(console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),t[0]):t[e]}function es(e){return e.split(",").map(function(e){return parseFloat(e)})}function ts(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=e.byteLength),(new TextDecoder).decode(new Uint8Array(e,t,n))}let ns=class extends t{constructor(e){super(e)}parse(e){const t=0,n=1,r=2,i=3,o=9,a=10,s=11,c=48,l=4,u=0,h=1,d=2,p=3;if(e.length<19)throw new Error("THREE.TGALoader: Not enough data to contain header.");let f=0;const m=new Uint8Array(e),g={id_length:m[f++],colormap_type:m[f++],image_type:m[f++],colormap_index:m[f++]|m[f++]<<8,colormap_length:m[f++]|m[f++]<<8,colormap_size:m[f++],origin:[m[f++]|m[f++]<<8,m[f++]|m[f++]<<8],width:m[f++]|m[f++]<<8,height:m[f++]|m[f++]<<8,pixel_size:m[f++],flags:m[f++]};if(function(e){switch(e.image_type){case n:case o:if(e.colormap_length>256||24!==e.colormap_size||1!==e.colormap_type)throw new Error("THREE.TGALoader: Invalid type colormap data for indexed type.");break;case r:case i:case a:case s:if(e.colormap_type)throw new Error("THREE.TGALoader: Invalid type colormap data for colormap type.");break;case t:throw new Error("THREE.TGALoader: No data.");default:throw new Error("THREE.TGALoader: Invalid type "+e.image_type)}if(e.width<=0||e.height<=0)throw new Error("THREE.TGALoader: Invalid image size.");if(8!==e.pixel_size&&16!==e.pixel_size&&24!==e.pixel_size&&32!==e.pixel_size)throw new Error("THREE.TGALoader: Invalid pixel size "+e.pixel_size)}(g),g.id_length+f>e.length)throw new Error("THREE.TGALoader: No data.");f+=g.id_length;let b=!1,y=!1,v=!1;switch(g.image_type){case o:b=!0,y=!0;break;case n:y=!0;break;case a:b=!0;break;case r:break;case s:b=!0,v=!0;break;case i:v=!0}const x=new Uint8Array(g.width*g.height*4),w=function(e,t,n,r,i){let o,a;const s=n.pixel_size>>3,c=n.width*n.height*s;if(t&&(a=i.subarray(r,r+=n.colormap_length*(n.colormap_size>>3))),e){let e,t,n;o=new Uint8Array(c);let a=0;const l=new Uint8Array(s);for(;a<c;)if(e=i[r++],t=1+(127&e),128&e){for(n=0;n<s;++n)l[n]=i[r++];for(n=0;n<t;++n)o.set(l,a+n*s);a+=s*t}else{for(t*=s,n=0;n<t;++n)o[a+n]=i[r++];a+=t}}else o=i.subarray(r,r+=t?n.width*n.height:c);return{pixel_data:o,palettes:a}}(b,y,g,f,m);return function(e,t,n,r,i){let o,a,s,f,m,b;switch((g.flags&c)>>l){default:case d:o=0,s=1,m=t,a=0,f=1,b=n;break;case u:o=0,s=1,m=t,a=n-1,f=-1,b=-1;break;case p:o=t-1,s=-1,m=-1,a=0,f=1,b=n;break;case h:o=t-1,s=-1,m=-1,a=n-1,f=-1,b=-1}if(v)switch(g.pixel_size){case 8:!function(e,t,n,r,i,o,a,s){let c,l,u,h=0;const d=g.width;for(u=t;u!==r;u+=n)for(l=i;l!==a;l+=o,h++)c=s[h],e[4*(l+d*u)+0]=c,e[4*(l+d*u)+1]=c,e[4*(l+d*u)+2]=c,e[4*(l+d*u)+3]=255}(e,a,f,b,o,s,m,r);break;case 16:!function(e,t,n,r,i,o,a,s){let c,l,u=0;const h=g.width;for(l=t;l!==r;l+=n)for(c=i;c!==a;c+=o,u+=2)e[4*(c+h*l)+0]=s[u+0],e[4*(c+h*l)+1]=s[u+0],e[4*(c+h*l)+2]=s[u+0],e[4*(c+h*l)+3]=s[u+1]}(e,a,f,b,o,s,m,r);break;default:throw new Error("THREE.TGALoader: Format not supported.")}else switch(g.pixel_size){case 8:!function(e,t,n,r,i,o,a,s,c){const l=c;let u,h,d,p=0;const f=g.width;for(d=t;d!==r;d+=n)for(h=i;h!==a;h+=o,p++)u=s[p],e[4*(h+f*d)+3]=255,e[4*(h+f*d)+2]=l[3*u+0],e[4*(h+f*d)+1]=l[3*u+1],e[4*(h+f*d)+0]=l[3*u+2]}(e,a,f,b,o,s,m,r,i);break;case 16:!function(e,t,n,r,i,o,a,s){let c,l,u,h=0;const d=g.width;for(u=t;u!==r;u+=n)for(l=i;l!==a;l+=o,h+=2)c=s[h+0]+(s[h+1]<<8),e[4*(l+d*u)+0]=(31744&c)>>7,e[4*(l+d*u)+1]=(992&c)>>2,e[4*(l+d*u)+2]=(31&c)<<3,e[4*(l+d*u)+3]=32768&c?0:255}(e,a,f,b,o,s,m,r);break;case 24:!function(e,t,n,r,i,o,a,s){let c,l,u=0;const h=g.width;for(l=t;l!==r;l+=n)for(c=i;c!==a;c+=o,u+=3)e[4*(c+h*l)+3]=255,e[4*(c+h*l)+2]=s[u+0],e[4*(c+h*l)+1]=s[u+1],e[4*(c+h*l)+0]=s[u+2]}(e,a,f,b,o,s,m,r);break;case 32:!function(e,t,n,r,i,o,a,s){let c,l,u=0;const h=g.width;for(l=t;l!==r;l+=n)for(c=i;c!==a;c+=o,u+=4)e[4*(c+h*l)+2]=s[u+0],e[4*(c+h*l)+1]=s[u+1],e[4*(c+h*l)+0]=s[u+2],e[4*(c+h*l)+3]=s[u+3]}(e,a,f,b,o,s,m,r);break;default:throw new Error("THREE.TGALoader: Format not supported.")}}(x,g.width,g.height,w.pixel_data,w.palettes),{data:x,width:g.width,height:g.height,flipY:!0,generateMipmaps:!0,minFilter:ue}}};class rs extends X{load(e,t,n,r){const i=this,o=""===i.path?J.extractUrlBase(e):i.path,a=new q(i.manager);a.setPath(i.path),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e,t){function n(e,t){const n=[],r=e.childNodes;for(let e=0,i=r.length;e<i;e++){const i=r[e];i.nodeName===t&&n.push(i)}return n}function r(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,r=t.length;e<r;e++)n[e]=t[e];return n}function i(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,r=t.length;e<r;e++)n[e]=parseFloat(t[e]);return n}function o(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,r=t.length;e<r;e++)n[e]=parseInt(t[e]);return n}function a(e){return e.substring(1)}function s(){return"three_default_"+Nt++}function c(e){return 0===Object.keys(e).length}function l(e){return void 0!==e&&!0===e.hasAttribute("meter")?parseFloat(e.getAttribute("meter")):1}function u(e){return void 0!==e?e.textContent:"Y_UP"}function h(e,t,r,i){const o=n(e,t)[0];if(void 0!==o){const e=n(o,r);for(let t=0;t<e.length;t++)i(e[t])}}function p(e,t){for(const n in e){e[n].build=t(e[n])}}function m(e,t){return void 0!==e.build||(e.build=t(e)),e.build}function g(e){const t={inputs:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"input"===r.nodeName){const e=a(r.getAttribute("source")),n=r.getAttribute("semantic");t.inputs[n]=e}}return t}function b(e){const t={};let n=e.getAttribute("target").split("/");const r=n.shift();let i=n.shift();const o=-1!==i.indexOf("("),s=-1!==i.indexOf(".");if(s)n=i.split("."),i=n.shift(),t.member=n.shift();else if(o){const e=i.split("(");i=e.shift();for(let t=0;t<e.length;t++)e[t]=parseInt(e[t].replace(/\)/,""));t.indices=e}return t.id=r,t.sid=i,t.arraySyntax=o,t.memberSyntax=s,t.sampler=a(e.getAttribute("source")),t}function x(e){const t=[],n=e.channels,r=e.samplers,i=e.sources;for(const e in n)if(n.hasOwnProperty(e)){const o=n[e],a=r[o.sampler],s=a.inputs.INPUT,c=a.inputs.OUTPUT;P(A(o,i[s],i[c]),t)}return t}function w(e){return m(Lt.animations[e],x)}function A(e,t,n){const r=Lt.nodes[e.id],i=xt(r.id),o=r.transforms[e.sid],a=r.matrix.clone().transpose();let s,c,l,u,h,d;const p={};switch(o){case"matrix":for(l=0,u=t.array.length;l<u;l++)if(s=t.array[l],c=l*n.stride,void 0===p[s]&&(p[s]={}),!0===e.arraySyntax){const t=n.array[c],r=e.indices[0]+4*e.indices[1];p[s][r]=t}else for(h=0,d=n.stride;h<d;h++)p[s][h]=n.array[c+h];break;case"translate":case"rotate":case"scale":console.warn('THREE.ColladaLoader: Animation transform type "%s" not yet implemented.',o)}const f=function(e,t){const n=[];for(const t in e)n.push({time:parseFloat(t),value:e[t]});n.sort(r);for(let e=0;e<16;e++)_(n,e,t.elements[e]);return n;function r(e,t){return e.time-t.time}}(p,a);return{name:i.uuid,keyframes:f}}const C=new f,M=new f,I=new y;function P(e,t){const n=e.keyframes,r=e.name,i=[],o=[],a=[],s=[];for(let e=0,t=n.length;e<t;e++){const t=n[e],r=t.time,c=t.value;lt.fromArray(c).transpose(),lt.decompose(C,I,M),i.push(r),o.push(C.x,C.y,C.z),a.push(I.x,I.y,I.z,I.w),s.push(M.x,M.y,M.z)}return o.length>0&&t.push(new Le(r+".position",i,o)),a.length>0&&t.push(new je(r+".quaternion",i,a)),s.length>0&&t.push(new Le(r+".scale",i,s)),t}function _(e,t,n){let r,i,o,a=!0;for(i=0,o=e.length;i<o;i++)r=e[i],void 0===r.value[t]?r.value[t]=null:a=!1;if(!0===a)for(i=0,o=e.length;i<o;i++)r=e[i],r.value[t]=n;else!function(e,t){let n,r;for(let i=0,o=e.length;i<o;i++){const o=e[i];if(null===o.value[t]){if(n=L(e,i,t),r=j(e,i,t),null===n){o.value[t]=r.value[t];continue}if(null===r){o.value[t]=n.value[t];continue}F(o,n,r,t)}}}(e,t)}function L(e,t,n){for(;t>=0;){const r=e[t];if(null!==r.value[n])return r;t--}return null}function j(e,t,n){for(;t<e.length;){const r=e[t];if(null!==r.value[n])return r;t++}return null}function F(e,t,n,r){n.time-t.time!==0?e.value[r]=(e.time-t.time)*(n.value[r]-t.value[r])/(n.time-t.time)+t.value[r]:e.value[r]=t.value[r]}function U(e){const t=[],n=e.name,r=e.end-e.start||-1,i=e.animations;for(let e=0,n=i.length;e<n;e++){const n=w(i[e]);for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return new Re(n,r,t)}function B(e){return m(Lt.clips[e],U)}function z(e){const t={sources:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"bind_shape_matrix":t.bindShapeMatrix=i(r.textContent);break;case"source":const e=r.getAttribute("id");t.sources[e]=Ue(r);break;case"joints":t.joints=H(r);break;case"vertex_weights":t.vertexWeights=V(r)}}return t}function H(e){const t={inputs:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"input"===r.nodeName){const e=r.getAttribute("semantic"),n=a(r.getAttribute("source"));t.inputs[e]=n}}return t}function V(e){const t={inputs:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"input":const e=r.getAttribute("semantic"),n=a(r.getAttribute("source")),i=parseInt(r.getAttribute("offset"));t.inputs[e]={id:n,offset:i};break;case"vcount":t.vcount=o(r.textContent);break;case"v":t.v=o(r.textContent)}}return t}function W(e){const t={id:e.id},n=Lt.geometries[t.id];return void 0!==e.skin&&(t.skin=function(e){const t=4,n={joints:[],indices:{array:[],stride:t},weights:{array:[],stride:t}},r=e.sources,i=e.vertexWeights,o=i.vcount,a=i.v,s=i.inputs.JOINT.offset,c=i.inputs.WEIGHT.offset,l=e.sources[e.joints.inputs.JOINT],u=e.sources[e.joints.inputs.INV_BIND_MATRIX],h=r[i.inputs.WEIGHT.id].array;let d,p,f,m=0;for(d=0,f=o.length;d<f;d++){const e=o[d],r=[];for(p=0;p<e;p++){const e=a[m+s],t=h[a[m+c]];r.push({index:e,weight:t}),m+=2}for(r.sort(g),p=0;p<t;p++){const e=r[p];void 0!==e?(n.indices.array.push(e.index),n.weights.array.push(e.weight)):(n.indices.array.push(0),n.weights.array.push(0))}}e.bindShapeMatrix?n.bindMatrix=(new N).fromArray(e.bindShapeMatrix).transpose():n.bindMatrix=(new N).identity();for(d=0,f=l.array.length;d<f;d++){const e=l.array[d],t=(new N).fromArray(u.array,d*u.stride).transpose();n.joints.push({name:e,boneInverse:t})}return n;function g(e,t){return t.weight-e.weight}}(e.skin),n.sources.skinIndices=t.skin.indices,n.sources.skinWeights=t.skin.weights),t}function q(e){return m(Lt.controllers[e],W)}function Q(e){return void 0!==e.build?e.build:e.init_from}function $(e){const t=Lt.images[e];return void 0!==t?m(t,Q):(console.warn("THREE.ColladaLoader: Couldn't find image with ID:",e),null)}function Z(e){const t={surfaces:{},samplers:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"newparam":J(r,t);break;case"technique":t.technique=oe(r);break;case"extra":t.extra=de(r)}}return t}function J(e,t){const n=e.getAttribute("sid");for(let r=0,i=e.childNodes.length;r<i;r++){const i=e.childNodes[r];if(1===i.nodeType)switch(i.nodeName){case"surface":t.surfaces[n]=ee(i);break;case"sampler2D":t.samplers[n]=ie(i)}}}function ee(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"init_from"===r.nodeName)t.init_from=r.textContent}return t}function ie(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"source"===r.nodeName)t.source=r.textContent}return t}function oe(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"constant":case"lambert":case"blinn":case"phong":t.type=r.nodeName,t.parameters=se(r);break;case"extra":t.extra=de(r)}}return t}function se(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"emission":case"diffuse":case"specular":case"bump":case"ambient":case"shininess":case"transparency":t[r.nodeName]=ce(r);break;case"transparent":t[r.nodeName]={opaque:r.hasAttribute("opaque")?r.getAttribute("opaque"):"A_ONE",data:ce(r)}}}return t}function ce(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"color":t[r.nodeName]=i(r.textContent);break;case"float":t[r.nodeName]=parseFloat(r.textContent);break;case"texture":t[r.nodeName]={id:r.getAttribute("texture"),extra:le(r)}}}return t}function le(e){const t={technique:{}};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"extra"===r.nodeName)ue(r,t)}return t}function ue(e,t){for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique"===r.nodeName)he(r,t)}}function he(e,t){for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"repeatU":case"repeatV":case"offsetU":case"offsetV":t.technique[r.nodeName]=parseFloat(r.textContent);break;case"wrapU":case"wrapV":"TRUE"===r.textContent.toUpperCase()?t.technique[r.nodeName]=1:"FALSE"===r.textContent.toUpperCase()?t.technique[r.nodeName]=0:t.technique[r.nodeName]=parseInt(r.textContent);break;case"bump":t[r.nodeName]=fe(r)}}}function de(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique"===r.nodeName)t.technique=pe(r)}return t}function pe(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"double_sided":t[r.nodeName]=parseInt(r.textContent);break;case"bump":t[r.nodeName]=fe(r)}}return t}function fe(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"texture"===r.nodeName)t[r.nodeName]={id:r.getAttribute("texture"),texcoord:r.getAttribute("texcoord"),extra:le(r)}}return t}function ge(e){return e}function ye(e){const t=(n=e.url,m(Lt.effects[n],ge));var n;const r=t.profile.technique;let i;switch(r.type){case"phong":case"blinn":i=new Be;break;case"lambert":i=new Ge;break;default:i=new E}function o(e,n=null){const r=t.profile.samplers[e.id];let i=null;if(void 0!==r){i=$(t.profile.surfaces[r.source].init_from)}else console.warn("THREE.ColladaLoader: Undefined sampler. Access image directly (see #12530)."),i=$(e.id);if(null!==i){const t=function(e){let t,n=e.slice((e.lastIndexOf(".")-1>>>0)+2);n=n.toLowerCase(),t="tga"===n?Rt:Mt;return t}(i);if(void 0!==t){const r=t.load(i),o=e.extra;if(void 0!==o&&void 0!==o.technique&&!1===c(o.technique)){const e=o.technique;r.wrapS=e.wrapU?me:be,r.wrapT=e.wrapV?me:be,r.offset.set(e.offsetU||0,e.offsetV||0),r.repeat.set(e.repeatU||1,e.repeatV||1)}else r.wrapS=me,r.wrapT=me;return null!==n&&(r.colorSpace=n),r}return console.warn("THREE.ColladaLoader: Loader for texture %s not found.",i),null}return console.warn("THREE.ColladaLoader: Couldn't create texture with ID:",e.id),null}i.name=e.name||"";const a=r.parameters;for(const e in a){const t=a[e];switch(e){case"diffuse":t.color&&i.color.fromArray(t.color),t.texture&&(i.map=o(t.texture,Y));break;case"specular":t.color&&i.specular&&i.specular.fromArray(t.color),t.texture&&(i.specularMap=o(t.texture));break;case"bump":t.texture&&(i.normalMap=o(t.texture));break;case"ambient":t.texture&&(i.lightMap=o(t.texture,Y));break;case"shininess":t.float&&i.shininess&&(i.shininess=t.float);break;case"emission":t.color&&i.emissive&&i.emissive.fromArray(t.color),t.texture&&(i.emissiveMap=o(t.texture,Y))}}i.color.convertSRGBToLinear(),i.specular&&i.specular.convertSRGBToLinear(),i.emissive&&i.emissive.convertSRGBToLinear();let s=a.transparent,l=a.transparency;if(void 0===l&&s&&(l={float:1}),void 0===s&&l&&(s={opaque:"A_ONE",data:{color:[1,1,1,1]}}),s&&l)if(s.data.texture)i.transparent=!0;else{const e=s.data.color;switch(s.opaque){case"A_ONE":i.opacity=e[3]*l.float;break;case"RGB_ZERO":i.opacity=1-e[0]*l.float;break;case"A_ZERO":i.opacity=1-e[3]*l.float;break;case"RGB_ONE":i.opacity=e[0]*l.float;break;default:console.warn('THREE.ColladaLoader: Invalid opaque type "%s" of transparent tag.',s.opaque)}i.opacity<1&&(i.transparent=!0)}if(void 0!==r.extra&&void 0!==r.extra.technique){const e=r.extra.technique;for(const t in e){const n=e[t];switch(t){case"double_sided":i.side=1===n?D:G;break;case"bump":i.normalMap=o(n.texture),i.normalScale=new v(1,1)}}}return i}function ve(e){return m(Lt.materials[e],ye)}function xe(e){for(let t=0;t<e.childNodes.length;t++){const n=e.childNodes[t];if("technique_common"===n.nodeName)return we(n)}return{}}function we(e){const t={};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];switch(r.nodeName){case"perspective":case"orthographic":t.technique=r.nodeName,t.parameters=Ae(r)}}return t}function Ae(e){const t={};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];switch(r.nodeName){case"xfov":case"yfov":case"xmag":case"ymag":case"znear":case"zfar":case"aspect_ratio":t[r.nodeName]=parseFloat(r.textContent)}}return t}function Ce(e){let t;switch(e.optics.technique){case"perspective":t=new ke(e.optics.parameters.yfov,e.optics.parameters.aspect_ratio,e.optics.parameters.znear,e.optics.parameters.zfar);break;case"orthographic":let n=e.optics.parameters.ymag,r=e.optics.parameters.xmag;const i=e.optics.parameters.aspect_ratio;r=void 0===r?n*i:r,n=void 0===n?r/i:n,r*=.5,n*=.5,t=new Se(-r,r,n,-n,e.optics.parameters.znear,e.optics.parameters.zfar);break;default:t=new ke}return t.name=e.name||"",t}function Pe(e){const t=Lt.cameras[e];return void 0!==t?m(t,Ce):(console.warn("THREE.ColladaLoader: Couldn't find camera with ID:",e),null)}function _e(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"directional":case"point":case"spot":case"ambient":t.technique=r.nodeName,t.parameters=Ne(r)}}return t}function Ne(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"color":const e=i(r.textContent);t.color=(new K).fromArray(e).convertSRGBToLinear();break;case"falloff_angle":t.falloffAngle=parseFloat(r.textContent);break;case"quadratic_attenuation":const n=parseFloat(r.textContent);t.distance=n?Math.sqrt(1/n):0}}return t}function De(e){let t;switch(e.technique){case"directional":t=new re;break;case"point":t=new ne;break;case"spot":t=new te;break;case"ambient":t=new Xe}return e.parameters.color&&t.color.copy(e.parameters.color),e.parameters.distance&&(t.distance=e.parameters.distance),t}function Fe(e){const t=Lt.lights[e];return void 0!==t?m(t,De):(console.warn("THREE.ColladaLoader: Couldn't find light with ID:",e),null)}function Ue(e){const t={array:[],stride:3};for(let o=0;o<e.childNodes.length;o++){const a=e.childNodes[o];if(1===a.nodeType)switch(a.nodeName){case"float_array":t.array=i(a.textContent);break;case"Name_array":t.array=r(a.textContent);break;case"technique_common":const e=n(a,"accessor")[0];void 0!==e&&(t.stride=parseInt(e.getAttribute("stride")))}}return t}function ze(e){const t={};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];1===r.nodeType&&(t[r.getAttribute("semantic")]=a(r.getAttribute("source")))}return t}function He(e){const t={type:e.nodeName,material:e.getAttribute("material"),count:parseInt(e.getAttribute("count")),inputs:{},stride:0,hasUV:!1};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"input":const e=a(r.getAttribute("source")),n=r.getAttribute("semantic"),i=parseInt(r.getAttribute("offset")),s=parseInt(r.getAttribute("set")),c=s>0?n+s:n;t.inputs[c]={id:e,offset:i},t.stride=Math.max(t.stride,i+1),"TEXCOORD"===n&&(t.hasUV=!0);break;case"vcount":t.vcount=o(r.textContent);break;case"p":t.p=o(r.textContent)}}return t}function Ve(e){let t=0;for(let n=0,r=e.length;n<r;n++){!0===e[n].hasUV&&t++}t>0&&t<e.length&&(e.uvsNeedsFix=!0)}function We(e){const t={},n=e.sources,r=e.vertices,i=e.primitives;if(0===i.length)return{};const o=function(e){const t={};for(let n=0;n<e.length;n++){const r=e[n];void 0===t[r.type]&&(t[r.type]=[]),t[r.type].push(r)}return t}(i);for(const e in o){const i=o[e];Ve(i),t[e]=qe(i,n,r)}return t}function qe(e,t,n){const r={},i={array:[],stride:0},o={array:[],stride:0},a={array:[],stride:0},s={array:[],stride:0},c={array:[],stride:0},l=[],u=4,h=[],d=4,p=new O,f=[];let m=0;for(let r=0;r<e.length;r++){const u=e[r],d=u.inputs;let g=0;switch(u.type){case"lines":case"linestrips":g=2*u.count;break;case"triangles":g=3*u.count;break;case"polylist":for(let e=0;e<u.count;e++){const t=u.vcount[e];switch(t){case 3:g+=3;break;case 4:g+=6;break;default:g+=3*(t-2)}}break;default:console.warn("THREE.ColladaLoader: Unknow primitive type:",u.type)}p.addGroup(m,g,r),m+=g,u.material&&f.push(u.material);for(const r in d){const p=d[r];switch(r){case"VERTEX":for(const r in n){const d=n[r];switch(r){case"POSITION":const n=i.array.length;if(Ye(u,t[d],p.offset,i.array),i.stride=t[d].stride,t.skinWeights&&t.skinIndices&&(Ye(u,t.skinIndices,p.offset,l),Ye(u,t.skinWeights,p.offset,h)),!1===u.hasUV&&!0===e.uvsNeedsFix){const e=(i.array.length-n)/i.stride;for(let t=0;t<e;t++)a.array.push(0,0)}break;case"NORMAL":Ye(u,t[d],p.offset,o.array),o.stride=t[d].stride;break;case"COLOR":Ye(u,t[d],p.offset,c.array),c.stride=t[d].stride;break;case"TEXCOORD":Ye(u,t[d],p.offset,a.array),a.stride=t[d].stride;break;case"TEXCOORD1":Ye(u,t[d],p.offset,s.array),a.stride=t[d].stride;break;default:console.warn('THREE.ColladaLoader: Semantic "%s" not handled in geometry build process.',r)}}break;case"NORMAL":Ye(u,t[p.id],p.offset,o.array),o.stride=t[p.id].stride;break;case"COLOR":Ye(u,t[p.id],p.offset,c.array,!0),c.stride=t[p.id].stride;break;case"TEXCOORD":Ye(u,t[p.id],p.offset,a.array),a.stride=t[p.id].stride;break;case"TEXCOORD1":Ye(u,t[p.id],p.offset,s.array),s.stride=t[p.id].stride}}}return i.array.length>0&&p.setAttribute("position",new k(i.array,i.stride)),o.array.length>0&&p.setAttribute("normal",new k(o.array,o.stride)),c.array.length>0&&p.setAttribute("color",new k(c.array,c.stride)),a.array.length>0&&p.setAttribute("uv",new k(a.array,a.stride)),s.array.length>0&&p.setAttribute("uv1",new k(s.array,s.stride)),l.length>0&&p.setAttribute("skinIndex",new k(l,u)),h.length>0&&p.setAttribute("skinWeight",new k(h,d)),r.data=p,r.type=e[0].type,r.materialKeys=f,r}function Ye(e,t,n,r,i=!1){const o=e.p,a=e.stride,s=e.vcount;function c(e){let t=o[e+n]*u;const a=t+u;for(;t<a;t++)r.push(l[t]);if(i){const e=r.length-u-1;It.setRGB(r[e+0],r[e+1],r[e+2]).convertSRGBToLinear(),r[e+0]=It.r,r[e+1]=It.g,r[e+2]=It.b}}const l=t.array,u=t.stride;if(void 0!==e.vcount){let e=0;for(let t=0,n=s.length;t<n;t++){const n=s[t];if(4===n){const t=e+1*a,n=e+2*a,r=e+3*a;c(e+0*a),c(t),c(r),c(t),c(n),c(r)}else if(3===n){const t=e+1*a,n=e+2*a;c(e+0*a),c(t),c(n)}else if(n>4)for(let t=1,r=n-2;t<=r;t++){const n=e+a*t,r=e+a*(t+1);c(e+0*a),c(n),c(r)}e+=a*n}}else for(let e=0,t=o.length;e<t;e+=a)c(e)}function Ke(e){return m(Lt.geometries[e],We)}function $e(e){return void 0!==e.build?e.build:e}function Ze(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"joint":t.joints[r.getAttribute("sid")]=Je(r);break;case"link":t.links.push(tt(r))}}}function Je(e){let t;for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"prismatic":case"revolute":t=et(r)}}return t}function et(e){const t={sid:e.getAttribute("sid"),name:e.getAttribute("name")||"",axis:new f,limits:{min:0,max:0},type:e.nodeName,static:!1,zeroPosition:0,middlePosition:0};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"axis":const e=i(r.textContent);t.axis.fromArray(e);break;case"limits":const n=r.getElementsByTagName("max")[0],o=r.getElementsByTagName("min")[0];t.limits.max=parseFloat(n.textContent),t.limits.min=parseFloat(o.textContent)}}return t.limits.min>=t.limits.max&&(t.static=!0),t.middlePosition=(t.limits.min+t.limits.max)/2,t}function tt(e){const t={sid:e.getAttribute("sid"),name:e.getAttribute("name")||"",attachments:[],transforms:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"attachment_full":t.attachments.push(nt(r));break;case"matrix":case"translate":case"rotate":t.transforms.push(rt(r))}}return t}function nt(e){const t={joint:e.getAttribute("joint").split("/").pop(),transforms:[],links:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"link":t.links.push(tt(r));break;case"matrix":case"translate":case"rotate":t.transforms.push(rt(r))}}return t}function rt(e){const t={type:e.nodeName},n=i(e.textContent);switch(t.type){case"matrix":t.obj=new N,t.obj.fromArray(n).transpose();break;case"translate":t.obj=new f,t.obj.fromArray(n);break;case"rotate":t.obj=new f,t.obj.fromArray(n),t.angle=d.degToRad(n[3])}return t}function it(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique_common"===r.nodeName)ot(r,t)}}function ot(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"inertia":t.inertia=i(r.textContent);break;case"mass":t.mass=i(r.textContent)[0]}}}function at(e){const t={target:e.getAttribute("target").split("/").pop()};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"axis"===r.nodeName){const e=r.getElementsByTagName("param")[0];t.axis=e.textContent;const n=t.axis.split("inst_").pop().split("axis")[0];t.jointIndex=n.substring(0,n.length-1)}}return t}function st(e){return void 0!==e.build?e.build:e}function ct(e){const t=[],n=Ct.querySelector('[id="'+e.id+'"]');for(let e=0;e<n.childNodes.length;e++){const r=n.childNodes[e];if(1!==r.nodeType)continue;let o,a;switch(r.nodeName){case"matrix":o=i(r.textContent);const e=(new N).fromArray(o).transpose();t.push({sid:r.getAttribute("sid"),type:r.nodeName,obj:e});break;case"translate":case"scale":o=i(r.textContent),a=(new f).fromArray(o),t.push({sid:r.getAttribute("sid"),type:r.nodeName,obj:a});break;case"rotate":o=i(r.textContent),a=(new f).fromArray(o);const n=d.degToRad(o[3]);t.push({sid:r.getAttribute("sid"),type:r.nodeName,obj:a,angle:n})}}return t}const lt=new N,ut=new f;function ht(e){const t={name:e.getAttribute("name")||"",type:e.getAttribute("type"),id:e.getAttribute("id"),sid:e.getAttribute("sid"),matrix:new N,nodes:[],instanceCameras:[],instanceControllers:[],instanceLights:[],instanceGeometries:[],instanceNodes:[],transforms:{}};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1!==r.nodeType)continue;let o;switch(r.nodeName){case"node":t.nodes.push(r.getAttribute("id")),ht(r);break;case"instance_camera":t.instanceCameras.push(a(r.getAttribute("url")));break;case"instance_controller":t.instanceControllers.push(dt(r));break;case"instance_light":t.instanceLights.push(a(r.getAttribute("url")));break;case"instance_geometry":t.instanceGeometries.push(dt(r));break;case"instance_node":t.instanceNodes.push(a(r.getAttribute("url")));break;case"matrix":o=i(r.textContent),t.matrix.multiply(lt.fromArray(o).transpose()),t.transforms[r.getAttribute("sid")]=r.nodeName;break;case"translate":o=i(r.textContent),ut.fromArray(o),t.matrix.multiply(lt.makeTranslation(ut.x,ut.y,ut.z)),t.transforms[r.getAttribute("sid")]=r.nodeName;break;case"rotate":o=i(r.textContent);const e=d.degToRad(o[3]);t.matrix.multiply(lt.makeRotationAxis(ut.fromArray(o),e)),t.transforms[r.getAttribute("sid")]=r.nodeName;break;case"scale":o=i(r.textContent),t.matrix.scale(ut.fromArray(o)),t.transforms[r.getAttribute("sid")]=r.nodeName;break;case"extra":break;default:console.log(r)}}return vt(t.id)?console.warn("THREE.ColladaLoader: There is already a node with ID %s. Exclude current node from further processing.",t.id):Lt.nodes[t.id]=t,t}function dt(e){const t={id:a(e.getAttribute("url")),materials:{},skeletons:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];switch(r.nodeName){case"bind_material":const e=r.getElementsByTagName("instance_material");for(let n=0;n<e.length;n++){const r=e[n],i=r.getAttribute("symbol"),o=r.getAttribute("target");t.materials[i]=a(o)}break;case"skeleton":t.skeletons.push(a(r.textContent))}}return t}function pt(e,t){const n=[],r=[];let i,o,a;for(i=0;i<e.length;i++){const r=e[i];let o;if(vt(r))o=xt(r),ft(o,t,n);else if(Et(r)){const e=Lt.visualScenes[r].children;for(let r=0;r<e.length;r++){const i=e[r];if("JOINT"===i.type){ft(xt(i.id),t,n)}}}else console.error("THREE.ColladaLoader: Unable to find root bone of skeleton with ID:",r)}for(i=0;i<t.length;i++)for(o=0;o<n.length;o++)if(a=n[o],a.bone.name===t[i].name){r[i]=a,a.processed=!0;break}for(i=0;i<n.length;i++)a=n[i],!1===a.processed&&(r.push(a),a.processed=!0);const s=[],c=[];for(i=0;i<r.length;i++)a=r[i],s.push(a.bone),c.push(a.boneInverse);return new Me(s,c)}function ft(e,t,n){e.traverse(function(e){if(!0===e.isBone){let r;for(let n=0;n<t.length;n++){const i=t[n];if(i.name===e.name){r=i.boneInverse;break}}void 0===r&&(r=new N),n.push({bone:e,boneInverse:r,processed:!1})}})}function mt(e){const t=[],n=e.matrix,r=e.nodes,i=e.type,o=e.instanceCameras,a=e.instanceControllers,s=e.instanceLights,c=e.instanceGeometries,l=e.instanceNodes;for(let e=0,n=r.length;e<n;e++)t.push(xt(r[e]));for(let e=0,n=o.length;e<n;e++){const n=Pe(o[e]);null!==n&&t.push(n.clone())}for(let e=0,n=a.length;e<n;e++){const n=a[e],r=q(n.id),i=yt(Ke(r.id),n.materials),o=pt(n.skeletons,r.skin.joints);for(let e=0,n=i.length;e<n;e++){const n=i[e];n.isSkinnedMesh&&(n.bind(o,r.skin.bindMatrix),n.normalizeSkinWeights()),t.push(n)}}for(let e=0,n=s.length;e<n;e++){const n=Fe(s[e]);null!==n&&t.push(n.clone())}for(let e=0,n=c.length;e<n;e++){const n=c[e],r=yt(Ke(n.id),n.materials);for(let e=0,n=r.length;e<n;e++)t.push(r[e])}for(let e=0,n=l.length;e<n;e++)t.push(xt(l[e]).clone());let u;if(0===r.length&&1===t.length)u=t[0];else{u="JOINT"===i?new Ie:new Oe;for(let e=0;e<t.length;e++)u.add(t[e])}return u.name="JOINT"===i?e.sid:e.name,u.matrix.copy(n),u.matrix.decompose(u.position,u.quaternion,u.scale),u}const gt=new E({name:X.DEFAULT_MATERIAL_NAME,color:16711935});function bt(e,t){const n=[];for(let r=0,i=e.length;r<i;r++){const i=t[e[r]];void 0===i?(console.warn("THREE.ColladaLoader: Material with key %s not found. Apply fallback material.",e[r]),n.push(gt)):n.push(ve(i))}return n}function yt(e,t){const n=[];for(const r in e){const i=e[r],o=bt(i.materialKeys,t);if(0===o.length&&("lines"===r||"linestrips"===r?o.push(new T):o.push(new Be)),"lines"===r||"linestrips"===r)for(let e=0,t=o.length;e<t;e++){const t=o[e];if(!0===t.isMeshPhongMaterial||!0===t.isMeshLambertMaterial){const n=new T;n.color.copy(t.color),n.opacity=t.opacity,n.transparent=t.transparent,o[e]=n}}const a=void 0!==i.data.attributes.skinIndex,s=1===o.length?o[0]:o;let c;switch(r){case"lines":c=new Te(i.data,s);break;case"linestrips":c=new R(i.data,s);break;case"triangles":case"polylist":c=a?new Ee(i.data,s):new S(i.data,s)}n.push(c)}return n}function vt(e){return void 0!==Lt.nodes[e]}function xt(e){return m(Lt.nodes[e],mt)}function wt(e){const t=new Oe;t.name=e.name;const n=e.children;for(let e=0;e<n.length;e++){const r=n[e];t.add(xt(r.id))}return t}function Et(e){return void 0!==Lt.visualScenes[e]}function Tt(e){return m(Lt.visualScenes[e],wt)}if(0===e.length)return{scene:new Qe};const At=(new DOMParser).parseFromString(e,"application/xml"),Ct=n(At,"COLLADA")[0],Ot=At.getElementsByTagName("parsererror")[0];if(void 0!==Ot){const e=n(Ot,"div")[0];let t;return t=e?e.textContent:function(e){let t="";const n=[e];for(;n.length;){const e=n.shift();e.nodeType===Node.TEXT_NODE?t+=e.textContent:(t+="\n",n.push.apply(n,e.childNodes))}return t.trim()}(Ot),console.error("THREE.ColladaLoader: Failed to parse collada file.\n",t),null}const kt=Ct.getAttribute("version");console.debug("THREE.ColladaLoader: File version",kt);const St=function(e){return{unit:l(n(e,"unit")[0]),upAxis:u(n(e,"up_axis")[0])}}(n(Ct,"asset")[0]),Mt=new ae(this.manager);let Rt;Mt.setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin),ns&&(Rt=new ns(this.manager),Rt.setPath(this.resourcePath||t));const It=new K,Pt=[];let _t={},Nt=0;const Lt={animations:{},clips:{},controllers:{},images:{},effects:{},materials:{},cameras:{},lights:{},geometries:{},nodes:{},visualScenes:{},kinematicsModels:{},physicsModels:{},kinematicsScenes:{}};h(Ct,"library_animations","animation",function e(t){const n={sources:{},samplers:{},channels:{}};let r=!1;for(let i=0,o=t.childNodes.length;i<o;i++){const o=t.childNodes[i];if(1!==o.nodeType)continue;let a;switch(o.nodeName){case"source":a=o.getAttribute("id"),n.sources[a]=Ue(o);break;case"sampler":a=o.getAttribute("id"),n.samplers[a]=g(o);break;case"channel":a=o.getAttribute("target"),n.channels[a]=b(o);break;case"animation":e(o),r=!0;break;default:console.log(o)}}!1===r&&(Lt.animations[t.getAttribute("id")||d.generateUUID()]=n)}),h(Ct,"library_animation_clips","animation_clip",function(e){const t={name:e.getAttribute("id")||"default",start:parseFloat(e.getAttribute("start")||0),end:parseFloat(e.getAttribute("end")||0),animations:[]};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"instance_animation"===r.nodeName)t.animations.push(a(r.getAttribute("url")))}Lt.clips[e.getAttribute("id")]=t}),h(Ct,"library_controllers","controller",function(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType)switch(r.nodeName){case"skin":t.id=a(r.getAttribute("source")),t.skin=z(r);break;case"morph":t.id=a(r.getAttribute("source")),console.warn("THREE.ColladaLoader: Morph target animation not supported yet.")}}Lt.controllers[e.getAttribute("id")]=t}),h(Ct,"library_images","image",function(e){const t={init_from:n(e,"init_from")[0].textContent};Lt.images[e.getAttribute("id")]=t}),h(Ct,"library_effects","effect",function(e){const t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"profile_COMMON"===r.nodeName)t.profile=Z(r)}Lt.effects[e.getAttribute("id")]=t}),h(Ct,"library_materials","material",function(e){const t={name:e.getAttribute("name")};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"instance_effect"===r.nodeName)t.url=a(r.getAttribute("url"))}Lt.materials[e.getAttribute("id")]=t}),h(Ct,"library_cameras","camera",function(e){const t={name:e.getAttribute("name")};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"optics"===r.nodeName)t.optics=xe(r)}Lt.cameras[e.getAttribute("id")]=t}),h(Ct,"library_lights","light",function(e){let t={};for(let n=0,r=e.childNodes.length;n<r;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique_common"===r.nodeName)t=_e(r)}Lt.lights[e.getAttribute("id")]=t}),h(Ct,"library_geometries","geometry",function(e){const t={name:e.getAttribute("name"),sources:{},vertices:{},primitives:[]},r=n(e,"mesh")[0];if(void 0!==r){for(let e=0;e<r.childNodes.length;e++){const n=r.childNodes[e];if(1!==n.nodeType)continue;const i=n.getAttribute("id");switch(n.nodeName){case"source":t.sources[i]=Ue(n);break;case"vertices":t.vertices=ze(n);break;case"polygons":console.warn("THREE.ColladaLoader: Unsupported primitive type: ",n.nodeName);break;case"lines":case"linestrips":case"polylist":case"triangles":t.primitives.push(He(n));break;default:console.log(n)}}Lt.geometries[e.getAttribute("id")]=t}}),h(Ct,"library_nodes","node",ht),h(Ct,"library_visual_scenes","visual_scene",function(e){const t={name:e.getAttribute("name"),children:[]};!function(e){const t=e.getElementsByTagName("node");for(let e=0;e<t.length;e++){const n=t[e];!1===n.hasAttribute("id")&&n.setAttribute("id",s())}}(e);const r=n(e,"node");for(let e=0;e<r.length;e++)t.children.push(ht(r[e]));Lt.visualScenes[e.getAttribute("id")]=t}),h(Ct,"library_kinematics_models","kinematics_model",function(e){const t={name:e.getAttribute("name")||"",joints:{},links:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"technique_common"===r.nodeName)Ze(r,t)}Lt.kinematicsModels[e.getAttribute("id")]=t}),h(Ct,"library_physics_models","physics_model",function(e){const t={name:e.getAttribute("name")||"",rigidBodies:{}};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"rigid_body"===r.nodeName)t.rigidBodies[r.getAttribute("name")]={},it(r,t.rigidBodies[r.getAttribute("name")])}Lt.physicsModels[e.getAttribute("id")]=t}),h(Ct,"scene","instance_kinematics_scene",function(e){const t={bindJointAxis:[]};for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(1===r.nodeType&&"bind_joint_axis"===r.nodeName)t.bindJointAxis.push(at(r))}Lt.kinematicsScenes[a(e.getAttribute("url"))]=t}),p(Lt.animations,x),p(Lt.clips,U),p(Lt.controllers,W),p(Lt.images,Q),p(Lt.effects,ge),p(Lt.materials,ye),p(Lt.cameras,Ce),p(Lt.lights,De),p(Lt.geometries,We),p(Lt.visualScenes,wt),function(){const e=Lt.clips;if(!0===c(e)){if(!1===c(Lt.animations)){const e=[];for(const t in Lt.animations){const n=w(t);for(let t=0,r=n.length;t<r;t++)e.push(n[t])}Pt.push(new Re("default",-1,e))}}else for(const t in e)Pt.push(B(t))}(),function(){const e=Object.keys(Lt.kinematicsModels)[0],t=Object.keys(Lt.kinematicsScenes)[0],n=Object.keys(Lt.visualScenes)[0];if(void 0===e||void 0===t)return;const r=(i=e,m(Lt.kinematicsModels[i],$e));var i;const o=function(e){return m(Lt.kinematicsScenes[e],st)}(t),a=Tt(n),s=o.bindJointAxis,c={};for(let e=0,t=s.length;e<t;e++){const t=s[e],n=Ct.querySelector('[sid="'+t.target+'"]');if(n){const e=n.parentElement;l(t.jointIndex,e)}}function l(e,t){const n=t.getAttribute("name"),i=r.joints[e];a.traverse(function(r){r.name===n&&(c[e]={object:r,transforms:ct(t),joint:i,position:i.zeroPosition})})}const u=new N;_t={joints:r&&r.joints,getJointValue:function(e){const t=c[e];if(t)return t.position;console.warn("THREE.ColladaLoader: Joint "+e+" doesn't exist.")},setJointValue:function(e,t){const n=c[e];if(n){const r=n.joint;if(t>r.limits.max||t<r.limits.min)console.warn("THREE.ColladaLoader: Joint "+e+" value "+t+" outside of limits (min: "+r.limits.min+", max: "+r.limits.max+").");else if(r.static)console.warn("THREE.ColladaLoader: Joint "+e+" is static.");else{const i=n.object,o=r.axis,a=n.transforms;lt.identity();for(let n=0;n<a.length;n++){const i=a[n];if(i.sid&&-1!==i.sid.indexOf(e))switch(r.type){case"revolute":lt.multiply(u.makeRotationAxis(o,d.degToRad(t)));break;case"prismatic":lt.multiply(u.makeTranslation(o.x*t,o.y*t,o.z*t));break;default:console.warn("THREE.ColladaLoader: Unknown joint type: "+r.type)}else switch(i.type){case"matrix":lt.multiply(i.obj);break;case"translate":lt.multiply(u.makeTranslation(i.obj.x,i.obj.y,i.obj.z));break;case"scale":lt.scale(i.obj);break;case"rotate":lt.multiply(u.makeRotationAxis(i.obj,i.angle))}}i.matrix.copy(lt),i.matrix.decompose(i.position,i.quaternion,i.scale),c[e].position=t}}else console.log("THREE.ColladaLoader: "+e+" does not exist.")}}}();const Dt=function(e){return Tt(a(n(e,"instance_visual_scene")[0].getAttribute("url")))}(n(Ct,"scene")[0]);return Dt.animations=Pt,"Z_UP"===St.upAxis&&(console.warn("THREE.ColladaLoader: You are loading an asset with a Z-UP coordinate system. The loader just rotates the asset to transform it into Y-UP. The vertex data are not converted, see #24289."),Dt.rotation.set(-Math.PI/2,0,0)),Dt.scale.multiplyScalar(St.unit),{get animations(){return console.warn("THREE.ColladaLoader: Please access animations over scene.animations now."),Pt},kinematics:_t,library:Lt,scene:Dt}}}const is=new K;class os extends X{constructor(e){super(e),this.propertyNameMapping={},this.customPropertyMapping={}}load(e,t,n,r){const i=this,o=new q(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}setPropertyNameMapping(e){this.propertyNameMapping=e}setCustomPropertyNameMapping(e){this.customPropertyMapping=e}parse(e){function t(e,t=0){let n="";const r=/^ply([\s\S]*)end_header(\r\n|\r|\n)/.exec(e);null!==r&&(n=r[1]);const i={comments:[],elements:[],headerLength:t,objInfo:""},o=n.split(/\r\n|\r|\n/);let a;function s(e,t){const n={type:e[0]};return"list"===n.type?(n.name=e[3],n.countType=e[1],n.itemType=e[2]):n.name=e[1],n.name in t&&(n.name=t[n.name]),n}for(let e=0;e<o.length;e++){let t=o[e];if(t=t.trim(),""===t)continue;const n=t.split(/\s+/),r=n.shift();switch(t=n.join(" "),r){case"format":i.format=n[0],i.version=n[1];break;case"comment":i.comments.push(t);break;case"element":void 0!==a&&i.elements.push(a),a={},a.name=n[0],a.count=parseInt(n[1]),a.properties=[];break;case"property":a.properties.push(s(n,d.propertyNameMapping));break;case"obj_info":i.objInfo=t;break;default:console.log("unhandled",r,n)}}return void 0!==a&&i.elements.push(a),i}function n(e,t){switch(t){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(e);case"float":case"double":case"float32":case"float64":return parseFloat(e)}}function r(e,t){const r={};for(let i=0;i<e.length;i++){if(t.empty())return null;if("list"===e[i].type){const o=[],a=n(t.next(),e[i].countType);for(let r=0;r<a;r++){if(t.empty())return null;o.push(n(t.next(),e[i].itemType))}r[e[i].name]=o}else r[e[i].name]=n(t.next(),e[i].type)}return r}function i(){const e={indices:[],vertices:[],normals:[],uvs:[],faceVertexUvs:[],colors:[],faceVertexColors:[]};for(const t of Object.keys(d.customPropertyMapping))e[t]=[];return e}function o(e){const t=e.map(e=>e.name);function n(e){for(let n=0,r=e.length;n<r;n++){const r=e[n];if(t.includes(r))return r}return null}return{attrX:n(["x","px","posx"])||"x",attrY:n(["y","py","posy"])||"y",attrZ:n(["z","pz","posz"])||"z",attrNX:n(["nx","normalx"]),attrNY:n(["ny","normaly"]),attrNZ:n(["nz","normalz"]),attrS:n(["s","u","texture_u","tx"]),attrT:n(["t","v","texture_v","ty"]),attrR:n(["red","diffuse_red","r","diffuse_r"]),attrG:n(["green","diffuse_green","g","diffuse_g"]),attrB:n(["blue","diffuse_blue","b","diffuse_b"])}}function a(e,t){const n=i();let a,l;a=null!==(l=/end_header\s+(\S[\s\S]*\S|\S)\s*$/.exec(e))?l[1].split(/\s+/):[];const u=new as(a);e:for(let e=0;e<t.elements.length;e++){const i=t.elements[e],a=o(i.properties);for(let e=0;e<i.count;e++){const e=r(i.properties,u);if(!e)break e;c(n,i.name,e,a)}}return s(n)}function s(e){let t=new O;e.indices.length>0&&t.setIndex(e.indices),t.setAttribute("position",new k(e.vertices,3)),e.normals.length>0&&t.setAttribute("normal",new k(e.normals,3)),e.uvs.length>0&&t.setAttribute("uv",new k(e.uvs,2)),e.colors.length>0&&t.setAttribute("color",new k(e.colors,3)),(e.faceVertexUvs.length>0||e.faceVertexColors.length>0)&&(t=t.toNonIndexed(),e.faceVertexUvs.length>0&&t.setAttribute("uv",new k(e.faceVertexUvs,2)),e.faceVertexColors.length>0&&t.setAttribute("color",new k(e.faceVertexColors,3)));for(const n of Object.keys(d.customPropertyMapping))e[n].length>0&&t.setAttribute(n,new k(e[n],d.customPropertyMapping[n].length));return t.computeBoundingSphere(),t}function c(e,t,n,r){if("vertex"===t){e.vertices.push(n[r.attrX],n[r.attrY],n[r.attrZ]),null!==r.attrNX&&null!==r.attrNY&&null!==r.attrNZ&&e.normals.push(n[r.attrNX],n[r.attrNY],n[r.attrNZ]),null!==r.attrS&&null!==r.attrT&&e.uvs.push(n[r.attrS],n[r.attrT]),null!==r.attrR&&null!==r.attrG&&null!==r.attrB&&(is.setRGB(n[r.attrR]/255,n[r.attrG]/255,n[r.attrB]/255).convertSRGBToLinear(),e.colors.push(is.r,is.g,is.b));for(const t of Object.keys(d.customPropertyMapping))for(const r of d.customPropertyMapping[t])e[t].push(n[r])}else if("face"===t){const t=n.vertex_indices||n.vertex_index,i=n.texcoord;3===t.length?(e.indices.push(t[0],t[1],t[2]),i&&6===i.length&&(e.faceVertexUvs.push(i[0],i[1]),e.faceVertexUvs.push(i[2],i[3]),e.faceVertexUvs.push(i[4],i[5]))):4===t.length&&(e.indices.push(t[0],t[1],t[3]),e.indices.push(t[1],t[2],t[3])),null!==r.attrR&&null!==r.attrG&&null!==r.attrB&&(is.setRGB(n[r.attrR]/255,n[r.attrG]/255,n[r.attrB]/255).convertSRGBToLinear(),e.faceVertexColors.push(is.r,is.g,is.b),e.faceVertexColors.push(is.r,is.g,is.b),e.faceVertexColors.push(is.r,is.g,is.b))}}function l(e,t){const n={};let r=0;for(let i=0;i<t.length;i++){const o=t[i],a=o.valueReader;if("list"===o.type){const t=[],i=o.countReader.read(e+r);r+=o.countReader.size;for(let n=0;n<i;n++)t.push(a.read(e+r)),r+=a.size;n[o.name]=t}else n[o.name]=a.read(e+r),r+=a.size}return[n,r]}function u(e,t,n){function r(e,t,n){switch(t){case"int8":case"char":return{read:t=>e.getInt8(t),size:1};case"uint8":case"uchar":return{read:t=>e.getUint8(t),size:1};case"int16":case"short":return{read:t=>e.getInt16(t,n),size:2};case"uint16":case"ushort":return{read:t=>e.getUint16(t,n),size:2};case"int32":case"int":return{read:t=>e.getInt32(t,n),size:4};case"uint32":case"uint":return{read:t=>e.getUint32(t,n),size:4};case"float32":case"float":return{read:t=>e.getFloat32(t,n),size:4};case"float64":case"double":return{read:t=>e.getFloat64(t,n),size:8}}}for(let i=0,o=e.length;i<o;i++){const o=e[i];"list"===o.type?(o.countReader=r(t,o.countType,n),o.valueReader=r(t,o.itemType,n)):o.valueReader=r(t,o.type,n)}}let h;const d=this;if(e instanceof ArrayBuffer){const n=new Uint8Array(e),{headerText:r,headerLength:d}=function(e){let t=0,n=!0,r="";const i=[],o=(new TextDecoder).decode(e.subarray(0,5)),a=/^ply\r\n/.test(o);do{const o=String.fromCharCode(e[t++]);"\n"!==o&&"\r"!==o?r+=o:("end_header"===r&&(n=!1),""!==r&&(i.push(r),r=""))}while(n&&t<e.length);return!0===a&&t++,{headerText:i.join("\r")+"\r",headerLength:t}}(n),p=t(r,d);if("ascii"===p.format){h=a((new TextDecoder).decode(n),p)}else h=function(e,t){const n=i(),r="binary_little_endian"===t.format,a=new DataView(e,t.headerLength);let h,d=0;for(let e=0;e<t.elements.length;e++){const i=t.elements[e],s=i.properties,p=o(s);u(s,a,r);for(let e=0;e<i.count;e++){h=l(d,s),d+=h[1];const e=h[0];c(n,i.name,e,p)}}return s(n)}(e,p)}else h=a(e,t(e));return h}}class as{constructor(e){this.arr=e,this.i=0}empty(){return this.i>=this.arr.length}next(){return this.arr[this.i++]}}class ss extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=new q(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){function t(e,t,n){for(let r=0,i=e.length;r<i;r++)if(e[r]!==t.getUint8(n+r))return!1;return!0}const n=function(e){if("string"==typeof e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=255&e.charCodeAt(n);return t.buffer||t}return e}(e);return function(e){const n=new DataView(e);if(84+50*n.getUint32(80,!0)===n.byteLength)return!0;const r=[115,111,108,105,100];for(let e=0;e<5;e++)if(t(r,n,e))return!1;return!0}(n)?function(e){const t=new DataView(e),n=t.getUint32(80,!0);let r,i,o,a,s,c,l,u,h=!1;for(let e=0;e<70;e++)1129270351==t.getUint32(e,!1)&&82==t.getUint8(e+4)&&61==t.getUint8(e+5)&&(h=!0,a=new Float32Array(3*n*3),s=t.getUint8(e+6)/255,c=t.getUint8(e+7)/255,l=t.getUint8(e+8)/255,u=t.getUint8(e+9)/255);const d=new O,p=new Float32Array(3*n*3),f=new Float32Array(3*n*3),m=new K;for(let e=0;e<n;e++){const n=84+50*e,u=t.getFloat32(n,!0),d=t.getFloat32(n+4,!0),g=t.getFloat32(n+8,!0);if(h){const e=t.getUint16(n+48,!0);32768&e?(r=s,i=c,o=l):(r=(31&e)/31,i=(e>>5&31)/31,o=(e>>10&31)/31)}for(let s=1;s<=3;s++){const c=n+12*s,l=3*e*3+3*(s-1);p[l]=t.getFloat32(c,!0),p[l+1]=t.getFloat32(c+4,!0),p[l+2]=t.getFloat32(c+8,!0),f[l]=u,f[l+1]=d,f[l+2]=g,h&&(m.set(r,i,o).convertSRGBToLinear(),a[l]=m.r,a[l+1]=m.g,a[l+2]=m.b)}}return d.setAttribute("position",new j(p,3)),d.setAttribute("normal",new j(f,3)),h&&(d.setAttribute("color",new j(a,3)),d.hasColors=!0,d.alpha=u),d}(n):function(e){const t=new O,n=/solid([\s\S]*?)endsolid/g,r=/facet([\s\S]*?)endfacet/g,i=/solid\s(.+)/;let o=0;const a=/[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source,s=new RegExp("vertex"+a+a+a,"g"),c=new RegExp("normal"+a+a+a,"g"),l=[],u=[],h=[],d=new f;let p,m=0,g=0,b=0;for(;null!==(p=n.exec(e));){g=b;const e=p[0],n=null!==(p=i.exec(e))?p[1]:"";for(h.push(n);null!==(p=r.exec(e));){let e=0,t=0;const n=p[0];for(;null!==(p=c.exec(n));)d.x=parseFloat(p[1]),d.y=parseFloat(p[2]),d.z=parseFloat(p[3]),t++;for(;null!==(p=s.exec(n));)l.push(parseFloat(p[1]),parseFloat(p[2]),parseFloat(p[3])),u.push(d.x,d.y,d.z),e++,b++;1!==t&&console.error("THREE.STLLoader: Something isn't right with the normal of face number "+o),3!==e&&console.error("THREE.STLLoader: Something isn't right with the vertices of face number "+o),o++}const a=g,f=b-g;t.userData.groupNames=h,t.addGroup(a,f,m),m++}return t.setAttribute("position",new k(l,3)),t.setAttribute("normal",new k(u,3)),t}("string"!=typeof(r=e)?(new TextDecoder).decode(r):r);var r}}const cs=Y;class ls extends X{constructor(e){super(e),this.defaultDPI=90,this.defaultUnit="px"}load(e,t,n,r){const i=this,o=new q(i.manager);o.setPath(i.path),o.setRequestHeader(i.requestHeader),o.setWithCredentials(i.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){const t=this;function n(e,t,n,i,o,a,s,c){if(0==t||0==n)return void e.lineTo(c.x,c.y);i=i*Math.PI/180,t=Math.abs(t),n=Math.abs(n);const l=(s.x-c.x)/2,u=(s.y-c.y)/2,h=Math.cos(i)*l+Math.sin(i)*u,d=-Math.sin(i)*l+Math.cos(i)*u;let p=t*t,f=n*n;const m=h*h,g=d*d,b=m/p+g/f;if(b>1){const e=Math.sqrt(b);p=(t*=e)*t,f=(n*=e)*n}const y=p*g+f*m,v=(p*f-y)/y;let x=Math.sqrt(Math.max(0,v));o===a&&(x=-x);const w=x*t*d/n,E=-x*n*h/t,T=Math.cos(i)*w-Math.sin(i)*E+(s.x+c.x)/2,A=Math.sin(i)*w+Math.cos(i)*E+(s.y+c.y)/2,C=r(1,0,(h-w)/t,(d-E)/n),O=r((h-w)/t,(d-E)/n,(-h-w)/t,(-d-E)/n)%(2*Math.PI);e.currentPath.absellipse(T,A,t,n,C,C+O,0===a,i)}function r(e,t,n,r){const i=e*n+t*r,o=Math.sqrt(e*e+t*t)*Math.sqrt(n*n+r*r);let a=Math.acos(Math.max(-1,Math.min(1,i/o)));return e*r-t*n<0&&(a=-a),a}function i(e,t){t=Object.assign({},t);let n={};if(e.hasAttribute("class")){const t=e.getAttribute("class").split(/\s/).filter(Boolean).map(e=>e.trim());for(let e=0;e<t.length;e++)n=Object.assign(n,g["."+t[e]])}function r(r,i,o){void 0===o&&(o=function(e){return e.startsWith("url")&&console.warn("SVGLoader: url access in attributes is not implemented."),e}),e.hasAttribute(r)&&(t[i]=o(e.getAttribute(r))),n[r]&&(t[i]=o(n[r])),e.style&&""!==e.style[r]&&(t[i]=o(e.style[r]))}function i(e){return Math.max(0,Math.min(1,l(e)))}function o(e){return Math.max(0,l(e))}return e.hasAttribute("id")&&(n=Object.assign(n,g["#"+e.getAttribute("id")])),r("fill","fill"),r("fill-opacity","fillOpacity",i),r("fill-rule","fillRule"),r("opacity","opacity",i),r("stroke","stroke"),r("stroke-opacity","strokeOpacity",i),r("stroke-width","strokeWidth",o),r("stroke-linejoin","strokeLineJoin"),r("stroke-linecap","strokeLineCap"),r("stroke-miterlimit","strokeMiterLimit",o),r("visibility","visibility"),t}function o(e,t){return e-(t-e)}function a(e,t,n){if("string"!=typeof e)throw new TypeError("Invalid input: "+typeof e);const r={WHITESPACE:/[ \t\r\n]/,DIGIT:/[\d]/,SIGN:/[-+]/,POINT:/\./,COMMA:/,/,EXP:/e/i,FLAGS:/[01]/};let i=0,o=!0,a="",s="";const c=[];function l(e,t,n){const r=new SyntaxError('Unexpected character "'+e+'" at index '+t+".");throw r.partial=n,r}function u(){""!==a&&(""===s?c.push(Number(a)):c.push(Number(a)*Math.pow(10,Number(s)))),a="",s=""}let h;const d=e.length;for(let p=0;p<d;p++)if(h=e[p],Array.isArray(t)&&t.includes(c.length%n)&&r.FLAGS.test(h))i=1,a=h,u();else{if(0===i){if(r.WHITESPACE.test(h))continue;if(r.DIGIT.test(h)||r.SIGN.test(h)){i=1,a=h;continue}if(r.POINT.test(h)){i=2,a=h;continue}r.COMMA.test(h)&&(o&&l(h,p,c),o=!0)}if(1===i){if(r.DIGIT.test(h)){a+=h;continue}if(r.POINT.test(h)){a+=h,i=2;continue}if(r.EXP.test(h)){i=3;continue}r.SIGN.test(h)&&1===a.length&&r.SIGN.test(a[0])&&l(h,p,c)}if(2===i){if(r.DIGIT.test(h)){a+=h;continue}if(r.EXP.test(h)){i=3;continue}r.POINT.test(h)&&"."===a[a.length-1]&&l(h,p,c)}if(3===i){if(r.DIGIT.test(h)){s+=h;continue}if(r.SIGN.test(h)){if(""===s){s+=h;continue}1===s.length&&r.SIGN.test(s)&&l(h,p,c)}}r.WHITESPACE.test(h)?(u(),i=0,o=!1):r.COMMA.test(h)?(u(),i=0,o=!0):r.SIGN.test(h)?(u(),i=1,a=h):r.POINT.test(h)?(u(),i=2,a=h):l(h,p,c)}return u(),c}const s=["mm","cm","in","pt","pc","px"],c={mm:{mm:1,cm:.1,in:1/25.4,pt:72/25.4,pc:6/25.4,px:-1},cm:{mm:10,cm:1,in:1/2.54,pt:72/2.54,pc:6/2.54,px:-1},in:{mm:25.4,cm:2.54,in:1,pt:72,pc:6,px:-1},pt:{mm:25.4/72,cm:2.54/72,in:1/72,pt:1,pc:6/72,px:-1},pc:{mm:25.4/6,cm:2.54/6,in:1/6,pt:12,pc:1,px:-1},px:{px:1}};function l(e){let n,r="px";if("string"==typeof e||e instanceof String)for(let t=0,n=s.length;t<n;t++){const n=s[t];if(e.endsWith(n)){r=n,e=e.substring(0,e.length-n.length);break}}return"px"===r&&"px"!==t.defaultUnit?n=c.in[t.defaultUnit]/t.defaultDPI:(n=c[r][t.defaultUnit],n<0&&(n=c[r].in*t.defaultDPI)),n*parseFloat(e)}function u(e){const t=e.elements;return t[0]*t[4]-t[1]*t[3]<0}function h(e){const t=e.elements,n=t[0]*t[3]+t[1]*t[4];if(0===n)return!1;const r=d(e),i=p(e);return Math.abs(n/(r*i))>Number.EPSILON}function d(e){const t=e.elements;return Math.sqrt(t[0]*t[0]+t[1]*t[1])}function p(e){const t=e.elements;return Math.sqrt(t[3]*t[3]+t[4]*t[4])}const m=[],g={},b=[],y=new Ye,x=new Ye,w=new Ye,E=new Ye,T=new v,A=new f,C=new Ye,O=(new DOMParser).parseFromString(e,"image/svg+xml");!function e(t,r){if(1!==t.nodeType)return;const s=function(e){if(!(e.hasAttribute("transform")||"use"===e.nodeName&&(e.hasAttribute("x")||e.hasAttribute("y"))))return null;const t=function(e){const t=new Ye,n=y;if("use"===e.nodeName&&(e.hasAttribute("x")||e.hasAttribute("y"))){const n=l(e.getAttribute("x")),r=l(e.getAttribute("y"));t.translate(n,r)}if(e.hasAttribute("transform")){const r=e.getAttribute("transform").split(")");for(let e=r.length-1;e>=0;e--){const i=r[e].trim();if(""===i)continue;const o=i.indexOf("("),s=i.length;if(o>0&&o<s){const e=i.slice(0,o),t=a(i.slice(o+1));switch(n.identity(),e){case"translate":if(t.length>=1){const e=t[0];let r=0;t.length>=2&&(r=t[1]),n.translate(e,r)}break;case"rotate":if(t.length>=1){let e=0,r=0,i=0;e=t[0]*Math.PI/180,t.length>=3&&(r=t[1],i=t[2]),x.makeTranslation(-r,-i),w.makeRotation(e),E.multiplyMatrices(w,x),x.makeTranslation(r,i),n.multiplyMatrices(x,E)}break;case"scale":if(t.length>=1){const e=t[0];let r=e;t.length>=2&&(r=t[1]),n.scale(e,r)}break;case"skewX":1===t.length&&n.set(1,Math.tan(t[0]*Math.PI/180),0,0,1,0,0,0,1);break;case"skewY":1===t.length&&n.set(1,0,0,Math.tan(t[0]*Math.PI/180),1,0,0,0,1);break;case"matrix":6===t.length&&n.set(t[0],t[2],t[4],t[1],t[3],t[5],0,0,1)}}t.premultiply(n)}}return t}(e);b.length>0&&t.premultiply(b[b.length-1]);return C.copy(t),b.push(t),t}(t);let c=!1,O=null;switch(t.nodeName){case"svg":case"g":r=i(t,r);break;case"style":!function(e){if(!e.sheet||!e.sheet.cssRules||!e.sheet.cssRules.length)return;for(let t=0;t<e.sheet.cssRules.length;t++){const n=e.sheet.cssRules[t];if(1!==n.type)continue;const r=n.selectorText.split(/,/gm).filter(Boolean).map(e=>e.trim());for(let e=0;e<r.length;e++){const t=Object.fromEntries(Object.entries(n.style).filter(([,e])=>""!==e));g[r[e]]=Object.assign(g[r[e]]||{},t)}}}(t);break;case"path":r=i(t,r),t.hasAttribute("d")&&(O=function(e){const t=new et,r=new v,i=new v,s=new v;let c=!0,l=!1;const u=e.getAttribute("d");if(""===u||"none"===u)return null;const h=u.match(/[a-df-z][^a-df-z]*/gi);for(let e=0,u=h.length;e<u;e++){const u=h[e],d=u.charAt(0),p=u.slice(1).trim();let f;switch(!0===c&&(l=!0,c=!1),d){case"M":f=a(p);for(let e=0,n=f.length;e<n;e+=2)r.x=f[e+0],r.y=f[e+1],i.x=r.x,i.y=r.y,0===e?t.moveTo(r.x,r.y):t.lineTo(r.x,r.y),0===e&&s.copy(r);break;case"H":f=a(p);for(let e=0,n=f.length;e<n;e++)r.x=f[e],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"V":f=a(p);for(let e=0,n=f.length;e<n;e++)r.y=f[e],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"L":f=a(p);for(let e=0,n=f.length;e<n;e+=2)r.x=f[e+0],r.y=f[e+1],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"C":f=a(p);for(let e=0,n=f.length;e<n;e+=6)t.bezierCurveTo(f[e+0],f[e+1],f[e+2],f[e+3],f[e+4],f[e+5]),i.x=f[e+2],i.y=f[e+3],r.x=f[e+4],r.y=f[e+5],0===e&&!0===l&&s.copy(r);break;case"S":f=a(p);for(let e=0,n=f.length;e<n;e+=4)t.bezierCurveTo(o(r.x,i.x),o(r.y,i.y),f[e+0],f[e+1],f[e+2],f[e+3]),i.x=f[e+0],i.y=f[e+1],r.x=f[e+2],r.y=f[e+3],0===e&&!0===l&&s.copy(r);break;case"Q":f=a(p);for(let e=0,n=f.length;e<n;e+=4)t.quadraticCurveTo(f[e+0],f[e+1],f[e+2],f[e+3]),i.x=f[e+0],i.y=f[e+1],r.x=f[e+2],r.y=f[e+3],0===e&&!0===l&&s.copy(r);break;case"T":f=a(p);for(let e=0,n=f.length;e<n;e+=2){const n=o(r.x,i.x),a=o(r.y,i.y);t.quadraticCurveTo(n,a,f[e+0],f[e+1]),i.x=n,i.y=a,r.x=f[e+0],r.y=f[e+1],0===e&&!0===l&&s.copy(r)}break;case"A":f=a(p,[3,4],7);for(let e=0,o=f.length;e<o;e+=7){if(f[e+5]==r.x&&f[e+6]==r.y)continue;const o=r.clone();r.x=f[e+5],r.y=f[e+6],i.x=r.x,i.y=r.y,n(t,f[e],f[e+1],f[e+2],f[e+3],f[e+4],o,r),0===e&&!0===l&&s.copy(r)}break;case"m":f=a(p);for(let e=0,n=f.length;e<n;e+=2)r.x+=f[e+0],r.y+=f[e+1],i.x=r.x,i.y=r.y,0===e?t.moveTo(r.x,r.y):t.lineTo(r.x,r.y),0===e&&s.copy(r);break;case"h":f=a(p);for(let e=0,n=f.length;e<n;e++)r.x+=f[e],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"v":f=a(p);for(let e=0,n=f.length;e<n;e++)r.y+=f[e],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"l":f=a(p);for(let e=0,n=f.length;e<n;e+=2)r.x+=f[e+0],r.y+=f[e+1],i.x=r.x,i.y=r.y,t.lineTo(r.x,r.y),0===e&&!0===l&&s.copy(r);break;case"c":f=a(p);for(let e=0,n=f.length;e<n;e+=6)t.bezierCurveTo(r.x+f[e+0],r.y+f[e+1],r.x+f[e+2],r.y+f[e+3],r.x+f[e+4],r.y+f[e+5]),i.x=r.x+f[e+2],i.y=r.y+f[e+3],r.x+=f[e+4],r.y+=f[e+5],0===e&&!0===l&&s.copy(r);break;case"s":f=a(p);for(let e=0,n=f.length;e<n;e+=4)t.bezierCurveTo(o(r.x,i.x),o(r.y,i.y),r.x+f[e+0],r.y+f[e+1],r.x+f[e+2],r.y+f[e+3]),i.x=r.x+f[e+0],i.y=r.y+f[e+1],r.x+=f[e+2],r.y+=f[e+3],0===e&&!0===l&&s.copy(r);break;case"q":f=a(p);for(let e=0,n=f.length;e<n;e+=4)t.quadraticCurveTo(r.x+f[e+0],r.y+f[e+1],r.x+f[e+2],r.y+f[e+3]),i.x=r.x+f[e+0],i.y=r.y+f[e+1],r.x+=f[e+2],r.y+=f[e+3],0===e&&!0===l&&s.copy(r);break;case"t":f=a(p);for(let e=0,n=f.length;e<n;e+=2){const n=o(r.x,i.x),a=o(r.y,i.y);t.quadraticCurveTo(n,a,r.x+f[e+0],r.y+f[e+1]),i.x=n,i.y=a,r.x=r.x+f[e+0],r.y=r.y+f[e+1],0===e&&!0===l&&s.copy(r)}break;case"a":f=a(p,[3,4],7);for(let e=0,o=f.length;e<o;e+=7){if(0==f[e+5]&&0==f[e+6])continue;const o=r.clone();r.x+=f[e+5],r.y+=f[e+6],i.x=r.x,i.y=r.y,n(t,f[e],f[e+1],f[e+2],f[e+3],f[e+4],o,r),0===e&&!0===l&&s.copy(r)}break;case"Z":case"z":t.currentPath.autoClose=!0,t.currentPath.curves.length>0&&(r.copy(s),t.currentPath.currentPoint.copy(r),c=!0);break;default:console.warn(u)}l=!1}return t}(t));break;case"rect":r=i(t,r),O=function(e){const t=l(e.getAttribute("x")||0),n=l(e.getAttribute("y")||0),r=l(e.getAttribute("rx")||e.getAttribute("ry")||0),i=l(e.getAttribute("ry")||e.getAttribute("rx")||0),o=l(e.getAttribute("width")),a=l(e.getAttribute("height")),s=.448084975506,c=new et;c.moveTo(t+r,n),c.lineTo(t+o-r,n),(0!==r||0!==i)&&c.bezierCurveTo(t+o-r*s,n,t+o,n+i*s,t+o,n+i);c.lineTo(t+o,n+a-i),(0!==r||0!==i)&&c.bezierCurveTo(t+o,n+a-i*s,t+o-r*s,n+a,t+o-r,n+a);c.lineTo(t+r,n+a),(0!==r||0!==i)&&c.bezierCurveTo(t+r*s,n+a,t,n+a-i*s,t,n+a-i);c.lineTo(t,n+i),(0!==r||0!==i)&&c.bezierCurveTo(t,n+i*s,t+r*s,n,t+r,n);return c}(t);break;case"polygon":r=i(t,r),O=function(e){function t(e,t,n){const o=l(t),a=l(n);0===i?r.moveTo(o,a):r.lineTo(o,a),i++}const n=/([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g,r=new et;let i=0;return e.getAttribute("points").replace(n,t),r.currentPath.autoClose=!0,r}(t);break;case"polyline":r=i(t,r),O=function(e){function t(e,t,n){const o=l(t),a=l(n);0===i?r.moveTo(o,a):r.lineTo(o,a),i++}const n=/([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g,r=new et;let i=0;return e.getAttribute("points").replace(n,t),r.currentPath.autoClose=!1,r}(t);break;case"circle":r=i(t,r),O=function(e){const t=l(e.getAttribute("cx")||0),n=l(e.getAttribute("cy")||0),r=l(e.getAttribute("r")||0),i=new Je;i.absarc(t,n,r,0,2*Math.PI);const o=new et;return o.subPaths.push(i),o}(t);break;case"ellipse":r=i(t,r),O=function(e){const t=l(e.getAttribute("cx")||0),n=l(e.getAttribute("cy")||0),r=l(e.getAttribute("rx")||0),i=l(e.getAttribute("ry")||0),o=new Je;o.absellipse(t,n,r,i,0,2*Math.PI);const a=new et;return a.subPaths.push(o),a}(t);break;case"line":r=i(t,r),O=function(e){const t=l(e.getAttribute("x1")||0),n=l(e.getAttribute("y1")||0),r=l(e.getAttribute("x2")||0),i=l(e.getAttribute("y2")||0),o=new et;return o.moveTo(t,n),o.lineTo(r,i),o.currentPath.autoClose=!1,o}(t);break;case"defs":c=!0;break;case"use":r=i(t,r);const s=(t.getAttributeNS("http://www.w3.org/1999/xlink","href")||"").substring(1),u=t.viewportElement.getElementById(s);u?e(u,r):console.warn("SVGLoader: 'use node' references non-existent node id: "+s)}O&&(void 0!==r.fill&&"none"!==r.fill&&O.color.setStyle(r.fill,cs),function(e,t){function n(e){A.set(e.x,e.y,1).applyMatrix3(t),e.set(A.x,A.y)}function r(e){const n=e.xRadius,r=e.yRadius,i=Math.cos(e.aRotation),o=Math.sin(e.aRotation),a=new f(n*i,n*o,0),s=new f(-r*o,r*i,0),c=a.applyMatrix3(t),l=s.applyMatrix3(t),h=y.set(c.x,l.x,0,c.y,l.y,0,0,0,1),d=x.copy(h).invert(),p=w.copy(d).transpose().multiply(d).elements,m=function(e,t,n){let r,i,o,a,s;const c=e+n,l=e-n,u=Math.sqrt(l*l+4*t*t);c>0?(r=.5*(c+u),s=1/r,i=e*s*n-t*s*t):c<0?i=.5*(c-u):(r=.5*u,i=-.5*u);o=l>0?l+u:l-u;Math.abs(o)>2*Math.abs(t)?(s=-2*t/o,a=1/Math.sqrt(1+s*s),o=s*a):0===Math.abs(t)?(o=1,a=0):(s=-.5*o/t,o=1/Math.sqrt(1+s*s),a=s*o);l>0&&(s=o,o=-a,a=s);return{rt1:r,rt2:i,cs:o,sn:a}}(p[0],p[1],p[4]),g=Math.sqrt(m.rt1),b=Math.sqrt(m.rt2);e.xRadius=1/g,e.yRadius=1/b,e.aRotation=Math.atan2(m.sn,m.cs);if(!((e.aEndAngle-e.aStartAngle)%(2*Math.PI)<Number.EPSILON)){const n=x.set(g,0,0,0,b,0,0,0,1),r=w.set(m.cs,m.sn,0,-m.sn,m.cs,0,0,0,1),i=n.multiply(r).multiply(h),o=e=>{const{x:t,y:n}=new f(Math.cos(e),Math.sin(e),0).applyMatrix3(i);return Math.atan2(n,t)};e.aStartAngle=o(e.aStartAngle),e.aEndAngle=o(e.aEndAngle),u(t)&&(e.aClockwise=!e.aClockwise)}}function i(e){const n=d(t),r=p(t);e.xRadius*=n,e.yRadius*=r;const i=n>Number.EPSILON?Math.atan2(t.elements[1],t.elements[0]):Math.atan2(-t.elements[3],t.elements[4]);e.aRotation+=i,u(t)&&(e.aStartAngle*=-1,e.aEndAngle*=-1,e.aClockwise=!e.aClockwise)}const o=e.subPaths;for(let e=0,a=o.length;e<a;e++){const a=o[e].curves;for(let e=0;e<a.length;e++){const o=a[e];o.isLineCurve?(n(o.v1),n(o.v2)):o.isCubicBezierCurve?(n(o.v0),n(o.v1),n(o.v2),n(o.v3)):o.isQuadraticBezierCurve?(n(o.v0),n(o.v1),n(o.v2)):o.isEllipseCurve&&(T.set(o.aX,o.aY),n(T),o.aX=T.x,o.aY=T.y,h(t)?r(o):i(o))}}}(O,C),m.push(O),O.userData={node:t,style:r});const k=t.childNodes;for(let t=0;t<k.length;t++){const n=k[t];c&&"style"!==n.nodeName&&"defs"!==n.nodeName||e(n,r)}s&&(b.pop(),b.length>0?C.copy(b[b.length-1]):C.identity())}(O.documentElement,{fill:"#000",fillOpacity:1,strokeOpacity:1,strokeWidth:1,strokeLineJoin:"miter",strokeLineCap:"butt",strokeMiterLimit:4});return{paths:m,xml:O.documentElement}}static createShapes(e){const t=999999999,n=0,r=1,i=2,o=3,a=4,s=5,c=6,l={loc:n,t:0};function u(e,t,r,o){const a=e.x,s=t.x,c=r.x,u=o.x,d=e.y,p=t.y,f=r.y,m=o.y,g=(u-c)*(d-f)-(m-f)*(a-c),b=(m-f)*(s-a)-(u-c)*(p-d),y=g/b,v=((s-a)*(d-f)-(p-d)*(a-c))/b;if(0===b&&0!==g||y<=0||y>=1||v<0||v>1)return null;if(0===g&&0===b){for(let c=0;c<2;c++){if(h(0===c?r:o,e,t),l.loc==n){const e=0===c?r:o;return{x:e.x,y:e.y,t:l.t}}if(l.loc==i){return{x:+(a+l.t*(s-a)).toPrecision(10),y:+(d+l.t*(p-d)).toPrecision(10),t:l.t}}}return null}for(let i=0;i<2;i++)if(h(0===i?r:o,e,t),l.loc==n){const e=0===i?r:o;return{x:e.x,y:e.y,t:l.t}}return{x:+(a+y*(s-a)).toPrecision(10),y:+(d+y*(p-d)).toPrecision(10),t:y}}function h(e,t,u){const h=u.x-t.x,d=u.y-t.y,p=e.x-t.x,f=e.y-t.y,m=h*f-p*d;if(e.x===t.x&&e.y===t.y)return l.loc=n,void(l.t=0);if(e.x===u.x&&e.y===u.y)return l.loc=r,void(l.t=1);if(m<-Number.EPSILON)return void(l.loc=o);if(m>Number.EPSILON)return void(l.loc=a);if(h*p<0||d*f<0)return void(l.loc=s);if(Math.sqrt(h*h+d*d)<Math.sqrt(p*p+f*f))return void(l.loc=c);let g;g=0!==h?p/h:f/d,l.loc=i,l.t=g}function d(e,t,n){const r=new v;t.getCenter(r);const i=[];return n.forEach(t=>{if(t.boundingBox.containsPoint(r)){const n=function(e,t){const n=[],r=[];for(let i=1;i<e.length;i++){const o=e[i-1],a=e[i];for(let e=1;e<t.length;e++){const i=u(o,a,t[e-1],t[e]);null!==i&&void 0===n.find(e=>e.t<=i.t+Number.EPSILON&&e.t>=i.t-Number.EPSILON)&&(n.push(i),r.push(new v(i.x,i.y)))}}return r}(e,t.points);n.forEach(e=>{i.push({identifier:t.identifier,isCW:t.isCW,point:e})})}}),i.sort((e,t)=>e.point.x-t.point.x),i}let p=t,f=-999999999,m=e.subPaths.map(e=>{const n=e.getPoints();let r=-999999999,i=t,o=-999999999,a=t;for(let e=0;e<n.length;e++){const t=n[e];t.y>r&&(r=t.y),t.y<i&&(i=t.y),t.x>o&&(o=t.x),t.x<a&&(a=t.x)}return f<=o&&(f=o+1),p>=a&&(p=a-1),{curves:e.curves,points:n,isCW:Ke.isClockWise(n),identifier:-1,boundingBox:new $e(new v(a,i),new v(o,r))}});m=m.filter(e=>e.points.length>1);for(let e=0;e<m.length;e++)m[e].identifier=e;const g=m.map(t=>function(e,t,n,r,i){null!=i&&""!==i||(i="nonzero");const o=new v;e.boundingBox.getCenter(o);const a=d([new v(n,o.y),new v(r,o.y)],e.boundingBox,t);a.sort((e,t)=>e.point.x-t.point.x);const s=[],c=[];a.forEach(t=>{t.identifier===e.identifier?s.push(t):c.push(t)});const l=s[0].point.x,u=[];let h=0;for(;h<c.length&&c[h].point.x<l;)u.length>0&&u[u.length-1]===c[h].identifier?u.pop():u.push(c[h].identifier),h++;if(u.push(e.identifier),"evenodd"===i){const t=u.length%2==0,n=u[u.length-2];return{identifier:e.identifier,isHole:t,for:n}}if("nonzero"===i){let n=!0,r=null,i=null;for(let e=0;e<u.length;e++){const o=u[e];n?(i=t[o].isCW,n=!1,r=o):i!==t[o].isCW&&(i=t[o].isCW,n=!0)}return{identifier:e.identifier,isHole:n,for:r}}console.warn('fill-rule: "'+i+'" is currently not implemented.')}(t,m,p,f,e.userData?e.userData.style.fillRule:void 0)),b=[];return m.forEach(e=>{if(!g[e.identifier].isHole){const t=new Ze;t.curves=e.curves;g.filter(t=>t.isHole&&t.for===e.identifier).forEach(e=>{const n=m[e.identifier],r=new Je;r.curves=n.curves,t.holes.push(r)}),b.push(t)}}),b}static getStrokeStyle(e,t,n,r,i){return{strokeColor:t=void 0!==t?t:"#000",strokeWidth:e=void 0!==e?e:1,strokeLineJoin:n=void 0!==n?n:"miter",strokeLineCap:r=void 0!==r?r:"butt",strokeMiterLimit:i=void 0!==i?i:4}}static pointsToStroke(e,t,n,r){const i=[],o=[],a=[];if(0===ls.pointsToStrokeWithBuffers(e,t,n,r,i,o,a))return null;const s=new O;return s.setAttribute("position",new k(i,3)),s.setAttribute("normal",new k(o,3)),s.setAttribute("uv",new k(a,2)),s}static pointsToStrokeWithBuffers(e,t,n,r,i,o,a,s){const c=new v,l=new v,u=new v,h=new v,d=new v,p=new v,f=new v,m=new v,g=new v,b=new v,y=new v,x=new v,w=new v,E=new v,T=new v,A=new v,C=new v;n=void 0!==n?n:12,r=void 0!==r?r:.001,s=void 0!==s?s:0,e=function(e){let t=!1;for(let n=1,i=e.length-1;n<i;n++)if(e[n].distanceTo(e[n+1])<r){t=!0;break}if(!t)return e;const n=[];n.push(e[0]);for(let t=1,i=e.length-1;t<i;t++)e[t].distanceTo(e[t+1])>=r&&n.push(e[t]);return n.push(e[e.length-1]),n}(e);const O=e.length;if(O<2)return 0;const k=e[0].equals(e[O-1]);let S,M,R=e[0];const I=t.strokeWidth/2,P=1/(O-1);let _,N,L,D,j=0,F=!1,U=0,B=3*s,z=2*s;H(e[0],e[1],c).multiplyScalar(I),m.copy(e[0]).sub(c),g.copy(e[0]).add(c),b.copy(m),y.copy(g);for(let n=1;n<O;n++){S=e[n],M=n===O-1?k?e[1]:void 0:e[n+1];const r=c;if(H(R,S,r),u.copy(r).multiplyScalar(I),x.copy(S).sub(u),w.copy(S).add(u),_=j+P,N=!1,void 0!==M){H(S,M,l),u.copy(l).multiplyScalar(I),E.copy(S).sub(u),T.copy(S).add(u),L=!0,u.subVectors(M,R),r.dot(u)<0&&(L=!1),1===n&&(F=L),u.subVectors(M,S),u.normalize();const e=Math.abs(r.dot(u));if(e>Number.EPSILON){const n=I/e;u.multiplyScalar(-n),h.subVectors(S,R),d.copy(h).setLength(n).add(u),A.copy(d).negate();const r=d.length(),i=h.length();h.divideScalar(i),p.subVectors(M,S);const o=p.length();switch(p.divideScalar(o),h.dot(A)<i&&p.dot(A)<o&&(N=!0),C.copy(d).add(S),A.add(S),D=!1,N?L?(T.copy(A),w.copy(A)):(E.copy(A),x.copy(A)):W(),t.strokeLineJoin){case"bevel":X(L,N,_);break;case"round":q(L,N),L?G(S,x,E,_,0):G(S,T,w,_,1);break;default:const e=I*t.strokeMiterLimit/r;if(e<1){if("miter-clip"!==t.strokeLineJoin){X(L,N,_);break}q(L,N),L?(p.subVectors(C,x).multiplyScalar(e).add(x),f.subVectors(C,E).multiplyScalar(e).add(E),V(x,_,0),V(p,_,0),V(S,_,.5),V(S,_,.5),V(p,_,0),V(f,_,0),V(S,_,.5),V(f,_,0),V(E,_,0)):(p.subVectors(C,w).multiplyScalar(e).add(w),f.subVectors(C,T).multiplyScalar(e).add(T),V(w,_,1),V(p,_,1),V(S,_,.5),V(S,_,.5),V(p,_,1),V(f,_,1),V(S,_,.5),V(f,_,1),V(T,_,1))}else N?(L?(V(g,j,1),V(m,j,0),V(C,_,0),V(g,j,1),V(C,_,0),V(A,_,1)):(V(g,j,1),V(m,j,0),V(C,_,1),V(m,j,0),V(A,_,0),V(C,_,1)),L?E.copy(C):T.copy(C)):L?(V(x,_,0),V(C,_,0),V(S,_,.5),V(S,_,.5),V(C,_,0),V(E,_,0)):(V(w,_,1),V(C,_,1),V(S,_,.5),V(S,_,.5),V(C,_,1),V(T,_,1)),D=!0}}else W()}else W();k||n!==O-1||Y(e[0],b,y,L,!0,j),j=_,R=S,m.copy(E),g.copy(T)}if(k){if(N&&i){let e=C,t=A;F!==L&&(e=A,t=C),L?(D||F)&&(t.toArray(i,0),t.toArray(i,9),D&&e.toArray(i,3)):!D&&F||(t.toArray(i,3),t.toArray(i,9),D&&e.toArray(i,0))}}else Y(S,x,w,L,!1,_);return U;function H(e,t,n){return n.subVectors(t,e),n.set(-n.y,n.x).normalize()}function V(e,t,n){i&&(i[B]=e.x,i[B+1]=e.y,i[B+2]=0,o&&(o[B]=0,o[B+1]=0,o[B+2]=1),B+=3,a&&(a[z]=t,a[z+1]=n,z+=2)),U+=3}function G(e,t,r,i,o){c.copy(t).sub(e).normalize(),l.copy(r).sub(e).normalize();let a=Math.PI;const s=c.dot(l);Math.abs(s)<1&&(a=Math.abs(Math.acos(s))),a/=n,u.copy(t);for(let t=0,r=n-1;t<r;t++)h.copy(u).rotateAround(e,a),V(u,i,o),V(h,i,o),V(e,i,.5),u.copy(h);V(h,i,o),V(r,i,o),V(e,i,.5)}function W(){V(g,j,1),V(m,j,0),V(x,_,0),V(g,j,1),V(x,_,0),V(w,_,1)}function X(e,t,n){t?e?(V(g,j,1),V(m,j,0),V(x,_,0),V(g,j,1),V(x,_,0),V(A,_,1),V(x,n,0),V(E,n,0),V(A,n,.5)):(V(g,j,1),V(m,j,0),V(w,_,1),V(m,j,0),V(A,_,0),V(w,_,1),V(w,n,1),V(A,n,0),V(T,n,1)):e?(V(x,n,0),V(E,n,0),V(S,n,.5)):(V(w,n,1),V(T,n,0),V(S,n,.5))}function q(e,t){t&&(e?(V(g,j,1),V(m,j,0),V(x,_,0),V(g,j,1),V(x,_,0),V(A,_,1),V(x,j,0),V(S,_,.5),V(A,_,1),V(S,_,.5),V(E,j,0),V(A,_,1)):(V(g,j,1),V(m,j,0),V(w,_,1),V(m,j,0),V(A,_,0),V(w,_,1),V(w,j,1),V(A,_,0),V(S,_,.5),V(S,_,.5),V(A,_,0),V(T,j,1)))}function Y(e,n,r,o,s,d){switch(t.strokeLineCap){case"round":s?G(e,r,n,d,.5):G(e,n,r,d,.5);break;case"square":if(s)c.subVectors(n,e),l.set(c.y,-c.x),u.addVectors(c,l).add(e),h.subVectors(l,c).add(e),o?(u.toArray(i,3),h.toArray(i,0),h.toArray(i,9)):(u.toArray(i,3),1===a[7]?h.toArray(i,9):u.toArray(i,9),h.toArray(i,0));else{c.subVectors(r,e),l.set(c.y,-c.x),u.addVectors(c,l).add(e),h.subVectors(l,c).add(e);const t=i.length;o?(u.toArray(i,t-3),h.toArray(i,t-6),h.toArray(i,t-12)):(h.toArray(i,t-6),u.toArray(i,t-3),h.toArray(i,t-12))}}}}}class us extends X{constructor(e){super(e),this.debug=!1,this.group=null,this.materials=[],this.meshes=[]}load(e,t,n,r){const i=this,o=""===this.path?J.extractUrlBase(e):this.path,a=new q(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e,t){this.group=new Oe,this.materials=[],this.meshes=[],this.readFile(e,t);for(let e=0;e<this.meshes.length;e++)this.group.add(this.meshes[e]);return this.group}readFile(e,t){const n=new DataView(e),r=new hs(n,0,this.debugMessage);if(r.id===ps||r.id===fs||r.id===ds){let e=r.readChunk();for(;e;){if(e.id===ms){const t=e.readDWord();this.debugMessage("3DS file version: "+t)}else e.id===Es?this.readMeshData(e,t):this.debugMessage("Unknown main chunk: "+e.hexId);e=r.readChunk()}}this.debugMessage("Parsed "+this.meshes.length+" meshes")}readMeshData(e,t){let n=e.readChunk();for(;n;){if(n.id===Ts){const e=+n.readDWord();this.debugMessage("Mesh Version: "+e)}else if(n.id===As){const e=n.readFloat();this.debugMessage("Master scale: "+e),this.group.scale.set(e,e,e)}else n.id===Ws?(this.debugMessage("Named Object"),this.readNamedObject(n)):n.id===Cs?(this.debugMessage("Material"),this.readMaterialEntry(n,t)):this.debugMessage("Unknown MDATA chunk: "+n.hexId);n=e.readChunk()}}readNamedObject(e){const t=e.readString();let n=e.readChunk();for(;n;){if(n.id===Xs){const e=this.readMesh(n);e.name=t,this.meshes.push(e)}else this.debugMessage("Unknown named object chunk: "+n.hexId);n=e.readChunk()}}readMaterialEntry(e,t){let n=e.readChunk();const r=new Be;for(;n;){if(n.id===Os)r.name=n.readString(),this.debugMessage(" Name: "+r.name);else if(n.id===Ns)this.debugMessage(" Wireframe"),r.wireframe=!0;else if(n.id===Ls){const e=n.readByte();r.wireframeLinewidth=e,this.debugMessage(" Wireframe Thickness: "+e)}else if(n.id===Ps)r.side=D,this.debugMessage(" DoubleSided");else if(n.id===_s)this.debugMessage(" Additive Blending"),r.blending=tt;else if(n.id===Ss)this.debugMessage(" Diffuse Color"),r.color=this.readColor(n);else if(n.id===Ms)this.debugMessage(" Specular Color"),r.specular=this.readColor(n);else if(n.id===ks)this.debugMessage(" Ambient color"),r.color=this.readColor(n);else if(n.id===Rs){const e=this.readPercentage(n);r.shininess=100*e,this.debugMessage(" Shininess : "+e)}else if(n.id===Is){const e=this.readPercentage(n);r.opacity=1-e,this.debugMessage(" Transparency : "+e),r.transparent=r.opacity<1}else n.id===Ds?(this.debugMessage(" ColorMap"),r.map=this.readMap(n,t)):n.id===Fs?(this.debugMessage(" BumpMap"),r.bumpMap=this.readMap(n,t)):n.id===js?(this.debugMessage(" OpacityMap"),r.alphaMap=this.readMap(n,t)):n.id===Us?(this.debugMessage(" SpecularMap"),r.specularMap=this.readMap(n,t)):this.debugMessage(" Unknown material chunk: "+n.hexId);n=e.readChunk()}this.materials[r.name]=r}readMesh(e){let t=e.readChunk();const n=new O,r=new Be,i=new S(n,r);for(i.name="mesh";t;){if(t.id===qs){const e=t.readWord();this.debugMessage(" Vertex: "+e);const r=[];for(let n=0;n<e;n++)r.push(t.readFloat()),r.push(t.readFloat()),r.push(t.readFloat());n.setAttribute("position",new k(r,3))}else if(t.id===Ys)this.readFaceArray(t,i);else if(t.id===Qs){const e=t.readWord();this.debugMessage(" UV: "+e);const r=[];for(let n=0;n<e;n++)r.push(t.readFloat()),r.push(t.readFloat());n.setAttribute("uv",new k(r,2))}else if(t.id===$s){this.debugMessage(" Tranformation Matrix (TODO)");const e=[];for(let n=0;n<12;n++)e[n]=t.readFloat();const r=new N;r.elements[0]=e[0],r.elements[1]=e[6],r.elements[2]=e[3],r.elements[3]=e[9],r.elements[4]=e[2],r.elements[5]=e[8],r.elements[6]=e[5],r.elements[7]=e[11],r.elements[8]=e[1],r.elements[9]=e[7],r.elements[10]=e[4],r.elements[11]=e[10],r.elements[12]=0,r.elements[13]=0,r.elements[14]=0,r.elements[15]=1,r.transpose();const o=new N;o.copy(r).invert(),n.applyMatrix4(o),r.decompose(i.position,i.quaternion,i.scale)}else this.debugMessage(" Unknown mesh chunk: "+t.hexId);t=e.readChunk()}return n.computeVertexNormals(),i}readFaceArray(e,t){const n=e.readWord();this.debugMessage(" Faces: "+n);const r=[];for(let t=0;t<n;++t)r.push(e.readWord(),e.readWord(),e.readWord()),e.readWord();t.geometry.setIndex(r);let i=0,o=0;for(;!e.endOfChunk;){const n=e.readChunk();if(n.id===Ks){this.debugMessage(" Material Group");const e=this.readMaterialGroup(n),r=3*e.index.length;t.geometry.addGroup(o,r,i),o+=r,i++;const a=this.materials[e.name];!1===Array.isArray(t.material)&&(t.material=[]),void 0!==a&&t.material.push(a)}else this.debugMessage(" Unknown face array chunk: "+n.hexId)}1===t.material.length&&(t.material=t.material[0])}readMap(e,t){let n=e.readChunk(),r={};const i=new ae(this.manager);for(i.setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin);n;){if(n.id===Bs){const e=n.readString();r=i.load(e),this.debugMessage(" File: "+t+e)}else n.id===Vs?(r.offset.x=n.readFloat(),this.debugMessage(" OffsetX: "+r.offset.x)):n.id===Gs?(r.offset.y=n.readFloat(),this.debugMessage(" OffsetY: "+r.offset.y)):n.id===zs?(r.repeat.x=n.readFloat(),this.debugMessage(" RepeatX: "+r.repeat.x)):n.id===Hs?(r.repeat.y=n.readFloat(),this.debugMessage(" RepeatY: "+r.repeat.y)):this.debugMessage(" Unknown map chunk: "+n.hexId);n=e.readChunk()}return r}readMaterialGroup(e){const t=e.readString(),n=e.readWord();this.debugMessage(" Name: "+t),this.debugMessage(" Faces: "+n);const r=[];for(let t=0;t<n;++t)r.push(e.readWord());return{name:t,index:r}}readColor(e){const t=e.readChunk(),n=new K;if(t.id===bs||t.id===ys){const e=t.readByte(),r=t.readByte(),i=t.readByte();n.setRGB(e/255,r/255,i/255),this.debugMessage(" Color: "+n.r+", "+n.g+", "+n.b)}else if(t.id===gs||t.id===vs){const e=t.readFloat(),r=t.readFloat(),i=t.readFloat();n.setRGB(e,r,i),this.debugMessage(" Color: "+n.r+", "+n.g+", "+n.b)}else this.debugMessage(" Unknown color chunk: "+t.hexId);return n}readPercentage(e){const t=e.readChunk();switch(t.id){case xs:return t.readShort()/100;case ws:return t.readFloat();default:return this.debugMessage(" Unknown percentage chunk: "+t.hexId),0}}debugMessage(e){this.debug&&console.log(e)}}class hs{constructor(e,t,n){this.data=e,this.offset=t,this.position=t,this.debugMessage=n,this.debugMessage instanceof Function&&(this.debugMessage=function(){}),this.id=this.readWord(),this.size=this.readDWord(),this.end=this.offset+this.size,this.end>e.byteLength&&this.debugMessage("Bad chunk size for chunk at "+t)}readChunk(){if(this.endOfChunk)return null;try{const e=new hs(this.data,this.position,this.debugMessage);return this.position+=e.size,e}catch(e){return this.debugMessage("Unable to read chunk at "+this.position),null}}get hexId(){return this.id.toString(16)}get endOfChunk(){return this.position>=this.end}readByte(){const e=this.data.getUint8(this.position,!0);return this.position+=1,e}readFloat(){try{const e=this.data.getFloat32(this.position,!0);return this.position+=4,e}catch(e){return this.debugMessage(e+" "+this.position+" "+this.data.byteLength),0}}readInt(){const e=this.data.getInt32(this.position,!0);return this.position+=4,e}readShort(){const e=this.data.getInt16(this.position,!0);return this.position+=2,e}readDWord(){const e=this.data.getUint32(this.position,!0);return this.position+=4,e}readWord(){const e=this.data.getUint16(this.position,!0);return this.position+=2,e}readString(){let e="",t=this.readByte();for(;t;)e+=String.fromCharCode(t),t=this.readByte();return e}}const ds=19789,ps=15786,fs=49725,ms=2,gs=16,bs=17,ys=18,vs=19,xs=48,ws=49,Es=15677,Ts=15678,As=256,Cs=45055,Os=40960,ks=40976,Ss=40992,Ms=41008,Rs=41024,Is=41040,Ps=41089,_s=41091,Ns=41093,Ls=41095,Ds=41472,js=41488,Fs=41520,Us=41476,Bs=41728,zs=41812,Hs=41814,Vs=41816,Gs=41818,Ws=16384,Xs=16640,qs=16656,Ys=16672,Ks=16688,Qs=16704,$s=16736;
8
8
  /*! chevrotain - v9.0.1 */
9
- var $s=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Js=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.VERSION=void 0,e.VERSION="9.0.1"}),ec=$s((e,t)=>{var n=e&&e.__spreadArray||function(e,t){for(var n=0,r=t.length,i=e.length;n<r;n++,i++)e[i]=t[n];return e};function r(e){return e&&0===e.length}function i(e){return null==e?[]:Object.keys(e)}function o(e){for(var t=[],n=Object.keys(e),r=0;r<n.length;r++)t.push(e[n[r]]);return t}function a(e,t){if(Array.isArray(e))for(var n=0;n<e.length;n++)t.call(null,e[n],n);else{if(!m(e))throw Error("non exhaustive match");var r=i(e);for(n=0;n<r.length;n++){var o=r[n],a=e[o];t.call(null,a,o)}}}function s(e,t){var n=[];if(Array.isArray(e))for(var r=0;r<e.length;r++){var i=e[r];t.call(null,i)&&n.push(i)}return n}function c(e,t){return s(e,function(e){return!t(e)})}function l(e,t){return!!m(e)&&e.hasOwnProperty(t)}function u(e,t){return void 0!==p(e,function(e){return e===t})}function h(e){for(var t=[],n=0;n<e.length;n++)t.push(e[n]);return t}function d(e){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}function p(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(t.call(null,r))return r}}function f(e,t,n){for(var r=Array.isArray(e),a=r?e:o(e),s=r?[]:i(e),c=n,l=0;l<a.length;l++)c=t.call(null,c,a[l],r?l:s[l]);return c}function m(e){return e instanceof Object}function g(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=0;r<t.length;r++)for(var o=t[r],a=i(o),s=0;s<a.length;s++){var c=a[s];l(e,c)||(e[c]=o[c])}return e}Object.defineProperty(e,"__esModule",{value:!0}),e.toFastProperties=e.timer=e.peek=e.isES2015MapSupported=e.PRINT_WARNING=e.PRINT_ERROR=e.packArray=e.IDENTITY=e.NOOP=e.merge=e.groupBy=e.defaults=e.assignNoOverwrite=e.assign=e.zipObject=e.sortBy=e.indexOf=e.some=e.difference=e.every=e.isObject=e.isRegExp=e.isArray=e.partial=e.uniq=e.compact=e.reduce=e.findAll=e.find=e.cloneObj=e.cloneArr=e.contains=e.has=e.pick=e.reject=e.filter=e.dropRight=e.drop=e.isFunction=e.isUndefined=e.isString=e.forEach=e.last=e.first=e.flatten=e.map=e.mapValues=e.values=e.keys=e.isEmpty=void 0,e.isEmpty=r,e.keys=i,e.values=o,e.mapValues=function(e,t){for(var n=[],r=i(e),o=0;o<r.length;o++){var a=r[o];n.push(t.call(null,e[a],a))}return n},e.map=function(e,t){for(var n=[],r=0;r<e.length;r++)n.push(t.call(null,e[r],r));return n},e.flatten=function e(t){for(var n=[],r=0;r<t.length;r++){var i=t[r];Array.isArray(i)?n=n.concat(e(i)):n.push(i)}return n},e.first=function(e){return r(e)?void 0:e[0]},e.last=function(e){var t=e&&e.length;return t?e[t-1]:void 0},e.forEach=a,e.isString=function(e){return"string"==typeof e},e.isUndefined=function(e){return void 0===e},e.isFunction=function(e){return e instanceof Function},e.drop=function(e,t){return void 0===t&&(t=1),e.slice(t,e.length)},e.dropRight=function(e,t){return void 0===t&&(t=1),e.slice(0,e.length-t)},e.filter=s,e.reject=c,e.pick=function(e,t){for(var n=Object.keys(e),r={},i=0;i<n.length;i++){var o=n[i],a=e[o];t(a)&&(r[o]=a)}return r},e.has=l,e.contains=u,e.cloneArr=h,e.cloneObj=d,e.find=p,e.findAll=function(e,t){for(var n=[],r=0;r<e.length;r++){var i=e[r];t.call(null,i)&&n.push(i)}return n},e.reduce=f,e.compact=function(e){return c(e,function(e){return null==e})},e.uniq=function(e,t){void 0===t&&(t=function(e){return e});var n=[];return f(e,function(e,r){var i=t(r);return u(n,i)?e:(n.push(i),e.concat(r))},[])},e.partial=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=[null].concat(t);return Function.bind.apply(e,r)},e.isArray=function(e){return Array.isArray(e)},e.isRegExp=function(e){return e instanceof RegExp},e.isObject=m,e.every=function(e,t){for(var n=0;n<e.length;n++)if(!t(e[n],n))return!1;return!0},e.difference=function(e,t){return c(e,function(e){return u(t,e)})},e.some=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n]))return!0;return!1},e.indexOf=function(e,t){for(var n=0;n<e.length;n++)if(e[n]===t)return n;return-1},e.sortBy=function(e,t){var n=h(e);return n.sort(function(e,n){return t(e)-t(n)}),n},e.zipObject=function(e,t){if(e.length!==t.length)throw Error("can't zipObject with different number of keys and values!");for(var n={},r=0;r<e.length;r++)n[e[r]]=t[r];return n},e.assign=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=0;r<t.length;r++)for(var o=t[r],a=i(o),s=0;s<a.length;s++){var c=a[s];e[c]=o[c]}return e},e.assignNoOverwrite=g,e.defaults=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return g.apply(void 0,n([{}],e))},e.groupBy=function(e,t){var n={};return a(e,function(e){var r=t(e),i=n[r];i?i.push(e):n[r]=[e]}),n},e.merge=function(e,t){for(var n=d(e),r=i(t),o=0;o<r.length;o++){var a=r[o],s=t[a];n[a]=s}return n},e.NOOP=function(){},e.IDENTITY=function(e){return e},e.packArray=function(e){for(var t=[],n=0;n<e.length;n++){var r=e[n];t.push(void 0!==r?r:void 0)}return t},e.PRINT_ERROR=function(e){console&&console.error&&console.error("Error: "+e)},e.PRINT_WARNING=function(e){console&&console.warn&&console.warn("Warning: "+e)},e.isES2015MapSupported=function(){return"function"==typeof Map},e.peek=function(e){return e[e.length-1]},e.timer=function(e){var t=(new Date).getTime(),n=e();return{time:(new Date).getTime()-t,value:n}},e.toFastProperties=function(e){function t(){}t.prototype=e;var n=new t;function r(){return typeof n.bar}return r(),r(),e}}),tc=$s((e,t)=>{var n,r;n="undefined"!=typeof self?self:e,r=function(){function e(){}e.prototype.saveState=function(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}},e.prototype.restoreState=function(e){this.idx=e.idx,this.input=e.input,this.groupIdx=e.groupIdx},e.prototype.pattern=function(e){this.idx=0,this.input=e,this.groupIdx=0,this.consumeChar("/");var t=this.disjunction();this.consumeChar("/");for(var n={type:"Flags",loc:{begin:this.idx,end:e.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};this.isRegExpFlag();)switch(this.popChar()){case"g":a(n,"global");break;case"i":a(n,"ignoreCase");break;case"m":a(n,"multiLine");break;case"u":a(n,"unicode");break;case"y":a(n,"sticky")}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:n,value:t,loc:this.loc(0)}},e.prototype.disjunction=function(){var e=[],t=this.idx;for(e.push(this.alternative());"|"===this.peekChar();)this.consumeChar("|"),e.push(this.alternative());return{type:"Disjunction",value:e,loc:this.loc(t)}},e.prototype.alternative=function(){for(var e=[],t=this.idx;this.isTerm();)e.push(this.term());return{type:"Alternative",value:e,loc:this.loc(t)}},e.prototype.term=function(){return this.isAssertion()?this.assertion():this.atom()},e.prototype.assertion=function(){var e=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(e)};case"$":return{type:"EndAnchor",loc:this.loc(e)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(e)};case"B":return{type:"NonWordBoundary",loc:this.loc(e)}}throw Error("Invalid Assertion Escape");case"(":var t;switch(this.consumeChar("?"),this.popChar()){case"=":t="Lookahead";break;case"!":t="NegativeLookahead"}s(t);var n=this.disjunction();return this.consumeChar(")"),{type:t,value:n,loc:this.loc(e)}}!function(){throw Error("Internal Error - Should never get here!")}()},e.prototype.quantifier=function(e){var t,n=this.idx;switch(this.popChar()){case"*":t={atLeast:0,atMost:1/0};break;case"+":t={atLeast:1,atMost:1/0};break;case"?":t={atLeast:0,atMost:1};break;case"{":var r=this.integerIncludingZero();switch(this.popChar()){case"}":t={atLeast:r,atMost:r};break;case",":t=this.isDigit()?{atLeast:r,atMost:this.integerIncludingZero()}:{atLeast:r,atMost:1/0},this.consumeChar("}")}if(!0===e&&void 0===t)return;s(t)}if(!0!==e||void 0!==t)return s(t),"?"===this.peekChar(0)?(this.consumeChar("?"),t.greedy=!1):t.greedy=!0,t.type="Quantifier",t.loc=this.loc(n),t},e.prototype.atom=function(){var e,t=this.idx;switch(this.peekChar()){case".":e=this.dotAll();break;case"\\":e=this.atomEscape();break;case"[":e=this.characterClass();break;case"(":e=this.group()}return void 0===e&&this.isPatternCharacter()&&(e=this.patternCharacter()),s(e),e.loc=this.loc(t),this.isQuantifier()&&(e.quantifier=this.quantifier()),e},e.prototype.dotAll=function(){return this.consumeChar("."),{type:"Set",complement:!0,value:[i("\n"),i("\r"),i("\u2028"),i("\u2029")]}},e.prototype.atomEscape=function(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}},e.prototype.decimalEscapeAtom=function(){return{type:"GroupBackReference",value:this.positiveInteger()}},e.prototype.characterClassEscape=function(){var e,t=!1;switch(this.popChar()){case"d":e=l;break;case"D":e=l,t=!0;break;case"s":e=h;break;case"S":e=h,t=!0;break;case"w":e=u;break;case"W":e=u,t=!0}return s(e),{type:"Set",value:e,complement:t}},e.prototype.controlEscapeAtom=function(){var e;switch(this.popChar()){case"f":e=i("\f");break;case"n":e=i("\n");break;case"r":e=i("\r");break;case"t":e=i("\t");break;case"v":e=i("\v")}return s(e),{type:"Character",value:e}},e.prototype.controlLetterEscapeAtom=function(){this.consumeChar("c");var e=this.popChar();if(!1===/[a-zA-Z]/.test(e))throw Error("Invalid ");return{type:"Character",value:e.toUpperCase().charCodeAt(0)-64}},e.prototype.nulCharacterAtom=function(){return this.consumeChar("0"),{type:"Character",value:i("\0")}},e.prototype.hexEscapeSequenceAtom=function(){return this.consumeChar("x"),this.parseHexDigits(2)},e.prototype.regExpUnicodeEscapeSequenceAtom=function(){return this.consumeChar("u"),this.parseHexDigits(4)},e.prototype.identityEscapeAtom=function(){return{type:"Character",value:i(this.popChar())}},e.prototype.classPatternCharacterAtom=function(){switch(this.peekChar()){case"\n":case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:return{type:"Character",value:i(this.popChar())}}},e.prototype.characterClass=function(){var e=[],t=!1;for(this.consumeChar("["),"^"===this.peekChar(0)&&(this.consumeChar("^"),t=!0);this.isClassAtom();){var n=this.classAtom();if("Character"===n.type&&this.isRangeDash()){this.consumeChar("-");var r=this.classAtom();if("Character"===r.type){if(r.value<n.value)throw Error("Range out of order in character class");e.push({from:n.value,to:r.value})}else o(n.value,e),e.push(i("-")),o(r.value,e)}else o(n.value,e)}return this.consumeChar("]"),{type:"Set",complement:t,value:e}},e.prototype.classAtom=function(){switch(this.peekChar()){case"]":case"\n":case"\r":case"\u2028":case"\u2029":throw Error("TBD");case"\\":return this.classEscape();default:return this.classPatternCharacterAtom()}},e.prototype.classEscape=function(){switch(this.consumeChar("\\"),this.peekChar()){case"b":return this.consumeChar("b"),{type:"Character",value:i("\b")};case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}},e.prototype.group=function(){var e=!0;"?"===(this.consumeChar("("),this.peekChar(0))?(this.consumeChar("?"),this.consumeChar(":"),e=!1):this.groupIdx++;var t=this.disjunction();this.consumeChar(")");var n={type:"Group",capturing:e,value:t};return e&&(n.idx=this.groupIdx),n},e.prototype.positiveInteger=function(){var e=this.popChar();if(!1===r.test(e))throw Error("Expecting a positive integer");for(;n.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)},e.prototype.integerIncludingZero=function(){var e=this.popChar();if(!1===n.test(e))throw Error("Expecting an integer");for(;n.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)},e.prototype.patternCharacter=function(){var e=this.popChar();switch(e){case"\n":case"\r":case"\u2028":case"\u2029":case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":throw Error("TBD");default:return{type:"Character",value:i(e)}}},e.prototype.isRegExpFlag=function(){switch(this.peekChar(0)){case"g":case"i":case"m":case"u":case"y":return!0;default:return!1}},e.prototype.isRangeDash=function(){return"-"===this.peekChar()&&this.isClassAtom(1)},e.prototype.isDigit=function(){return n.test(this.peekChar(0))},e.prototype.isClassAtom=function(e){switch(void 0===e&&(e=0),this.peekChar(e)){case"]":case"\n":case"\r":case"\u2028":case"\u2029":return!1;default:return!0}},e.prototype.isTerm=function(){return this.isAtom()||this.isAssertion()},e.prototype.isAtom=function(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case".":case"\\":case"[":case"(":return!0;default:return!1}},e.prototype.isAssertion=function(){switch(this.peekChar(0)){case"^":case"$":return!0;case"\\":switch(this.peekChar(1)){case"b":case"B":return!0;default:return!1}case"(":return"?"===this.peekChar(1)&&("="===this.peekChar(2)||"!"===this.peekChar(2));default:return!1}},e.prototype.isQuantifier=function(){var e=this.saveState();try{return void 0!==this.quantifier(!0)}catch(e){return!1}finally{this.restoreState(e)}},e.prototype.isPatternCharacter=function(){switch(this.peekChar()){case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":case"/":case"\n":case"\r":case"\u2028":case"\u2029":return!1;default:return!0}},e.prototype.parseHexDigits=function(e){for(var n="",r=0;r<e;r++){var i=this.popChar();if(!1===t.test(i))throw Error("Expecting a HexDecimal digits");n+=i}return{type:"Character",value:parseInt(n,16)}},e.prototype.peekChar=function(e){return void 0===e&&(e=0),this.input[this.idx+e]},e.prototype.popChar=function(){var e=this.peekChar(0);return this.consumeChar(),e},e.prototype.consumeChar=function(e){if(void 0!==e&&this.input[this.idx]!==e)throw Error("Expected: '"+e+"' but found: '"+this.input[this.idx]+"' at offset: "+this.idx);if(this.idx>=this.input.length)throw Error("Unexpected end of input");this.idx++},e.prototype.loc=function(e){return{begin:e,end:this.idx}};var t=/[0-9a-fA-F]/,n=/[0-9]/,r=/[1-9]/;function i(e){return e.charCodeAt(0)}function o(e,t){void 0!==e.length?e.forEach(function(e){t.push(e)}):t.push(e)}function a(e,t){if(!0===e[t])throw"duplicate flag "+t;e[t]=!0}function s(e){if(void 0===e)throw Error("Internal Error - Should never get here!")}var c,l=[];for(c=i("0");c<=i("9");c++)l.push(c);var u=[i("_")].concat(l);for(c=i("a");c<=i("z");c++)u.push(c);for(c=i("A");c<=i("Z");c++)u.push(c);var h=[i(" "),i("\f"),i("\n"),i("\r"),i("\t"),i("\v"),i("\t"),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i("\u2028"),i("\u2029"),i(" "),i(" "),i(" "),i("\ufeff")];function d(){}return d.prototype.visitChildren=function(e){for(var t in e){var n=e[t];e.hasOwnProperty(t)&&(void 0!==n.type?this.visit(n):Array.isArray(n)&&n.forEach(function(e){this.visit(e)},this))}},d.prototype.visit=function(e){switch(e.type){case"Pattern":this.visitPattern(e);break;case"Flags":this.visitFlags(e);break;case"Disjunction":this.visitDisjunction(e);break;case"Alternative":this.visitAlternative(e);break;case"StartAnchor":this.visitStartAnchor(e);break;case"EndAnchor":this.visitEndAnchor(e);break;case"WordBoundary":this.visitWordBoundary(e);break;case"NonWordBoundary":this.visitNonWordBoundary(e);break;case"Lookahead":this.visitLookahead(e);break;case"NegativeLookahead":this.visitNegativeLookahead(e);break;case"Character":this.visitCharacter(e);break;case"Set":this.visitSet(e);break;case"Group":this.visitGroup(e);break;case"GroupBackReference":this.visitGroupBackReference(e);break;case"Quantifier":this.visitQuantifier(e)}this.visitChildren(e)},d.prototype.visitPattern=function(e){},d.prototype.visitFlags=function(e){},d.prototype.visitDisjunction=function(e){},d.prototype.visitAlternative=function(e){},d.prototype.visitStartAnchor=function(e){},d.prototype.visitEndAnchor=function(e){},d.prototype.visitWordBoundary=function(e){},d.prototype.visitNonWordBoundary=function(e){},d.prototype.visitLookahead=function(e){},d.prototype.visitNegativeLookahead=function(e){},d.prototype.visitCharacter=function(e){},d.prototype.visitSet=function(e){},d.prototype.visitGroup=function(e){},d.prototype.visitGroupBackReference=function(e){},d.prototype.visitQuantifier=function(e){},{RegExpParser:e,BaseRegExpVisitor:d,VERSION:"0.5.0"}},"function"==typeof define&&define.amd?define([],r):"object"==typeof t&&t.exports?t.exports=r():n.regexpToAst=r()}),nc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.clearRegExpParserCache=e.getRegExpAst=void 0;var t=tc(),n={},r=new t.RegExpParser;e.getRegExpAst=function(e){var t=e.toString();if(n.hasOwnProperty(t))return n[t];var i=r.pattern(t);return n[t]=i,i},e.clearRegExpParserCache=function(){n={}}}),rc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.canMatchCharCode=e.firstCharOptimizedIndices=e.getOptimizedStartCodesIndices=e.failedOptimizationPrefixMsg=void 0;var r=tc(),i=ec(),o=nc(),a=ic(),s="Complement Sets are not supported for first char optimization";function c(e,t,n){switch(e.type){case"Disjunction":for(var r=0;r<e.value.length;r++)c(e.value[r],t,n);break;case"Alternative":var o=e.value;for(r=0;r<o.length;r++){var u=o[r];switch(u.type){case"EndAnchor":case"GroupBackReference":case"Lookahead":case"NegativeLookahead":case"StartAnchor":case"WordBoundary":case"NonWordBoundary":continue}var d=u;switch(d.type){case"Character":l(d.value,t,n);break;case"Set":if(!0===d.complement)throw Error(s);i.forEach(d.value,function(e){if("number"==typeof e)l(e,t,n);else{var r=e;if(!0===n)for(var i=r.from;i<=r.to;i++)l(i,t,n);else{for(i=r.from;i<=r.to&&i<a.minOptimizationVal;i++)l(i,t,n);if(r.to>=a.minOptimizationVal)for(var o=r.from>=a.minOptimizationVal?r.from:a.minOptimizationVal,s=r.to,c=a.charCodeToOptimizedIndex(o),u=a.charCodeToOptimizedIndex(s),h=c;h<=u;h++)t[h]=h}}});break;case"Group":c(d.value,t,n);break;default:throw Error("Non Exhaustive Match")}var p=void 0!==d.quantifier&&0===d.quantifier.atLeast;if("Group"===d.type&&!1===h(d)||"Group"!==d.type&&!1===p)break}break;default:throw Error("non exhaustive match!")}return i.values(t)}function l(e,t,n){var r=a.charCodeToOptimizedIndex(e);t[r]=r,!0===n&&function(e,t){var n=String.fromCharCode(e),r=n.toUpperCase();if(r!==n){t[i=a.charCodeToOptimizedIndex(r.charCodeAt(0))]=i}else{var i,o=n.toLowerCase();if(o!==n)t[i=a.charCodeToOptimizedIndex(o.charCodeAt(0))]=i}}(e,t)}function u(e,t){return i.find(e.value,function(e){if("number"==typeof e)return i.contains(t,e);var n=e;return void 0!==i.find(t,function(e){return n.from<=e&&e<=n.to})})}function h(e){return!(!e.quantifier||0!==e.quantifier.atLeast)||!!e.value&&(i.isArray(e.value)?i.every(e.value,h):h(e.value))}e.failedOptimizationPrefixMsg='Unable to use "first char" lexer optimizations:\n',e.getOptimizedStartCodesIndices=function(t,n){void 0===n&&(n=!1);try{var a=o.getRegExpAst(t);return c(a.value,{},a.flags.ignoreCase)}catch(o){if(o.message===s)n&&i.PRINT_WARNING(e.failedOptimizationPrefixMsg+"\tUnable to optimize: < "+t.toString()+" >\n\tComplement Sets cannot be automatically optimized.\n\tThis will disable the lexer's first char optimizations.\n\tSee: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.");else{var l="";n&&(l="\n\tThis will disable the lexer's first char optimizations.\n\tSee: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details."),i.PRINT_ERROR(e.failedOptimizationPrefixMsg+"\n\tFailed parsing: < "+t.toString()+" >\n\tUsing the regexp-to-ast library version: "+r.VERSION+"\n\tPlease open an issue at: https://github.com/bd82/regexp-to-ast/issues"+l)}}return[]},e.firstCharOptimizedIndices=c;var d=function(e){function t(t){var n=e.call(this)||this;return n.targetCharCodes=t,n.found=!1,n}return n(t,e),t.prototype.visitChildren=function(t){if(!0!==this.found){switch(t.type){case"Lookahead":return void this.visitLookahead(t);case"NegativeLookahead":return void this.visitNegativeLookahead(t)}e.prototype.visitChildren.call(this,t)}},t.prototype.visitCharacter=function(e){i.contains(this.targetCharCodes,e.value)&&(this.found=!0)},t.prototype.visitSet=function(e){e.complement?void 0===u(e,this.targetCharCodes)&&(this.found=!0):void 0!==u(e,this.targetCharCodes)&&(this.found=!0)},t}(r.BaseRegExpVisitor);e.canMatchCharCode=function(e,t){if(t instanceof RegExp){var n=o.getRegExpAst(t),r=new d(e);return r.visit(n),r.found}return void 0!==i.find(t,function(t){return i.contains(e,t.charCodeAt(0))})}}),ic=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.charCodeToOptimizedIndex=e.minOptimizationVal=e.buildLineBreakIssueMessage=e.LineTerminatorOptimizedTester=e.isShortPattern=e.isCustomPattern=e.cloneEmptyGroups=e.performWarningRuntimeChecks=e.performRuntimeChecks=e.addStickyFlag=e.addStartOfInput=e.findUnreachablePatterns=e.findModesThatDoNotExist=e.findInvalidGroupType=e.findDuplicatePatterns=e.findUnsupportedFlags=e.findStartOfInputAnchor=e.findEmptyMatchRegExps=e.findEndOfInputAnchor=e.findInvalidPatterns=e.findMissingPatterns=e.validatePatterns=e.analyzeTokenTypes=e.enableSticky=e.disableSticky=e.SUPPORT_STICKY=e.MODES=e.DEFAULT_MODE=void 0;var r=tc(),i=sc(),o=ec(),a=rc(),s=nc(),c="PATTERN";function l(e){var t=o.filter(e,function(e){return!o.has(e,c)}),n=o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- missing static 'PATTERN' property",type:i.LexerDefinitionErrorType.MISSING_PATTERN,tokenTypes:[e]}});return{errors:n,valid:o.difference(e,t)}}function u(e){var t=o.filter(e,function(e){var t=e[c];return!(o.isRegExp(t)||o.isFunction(t)||o.has(t,"exec")||o.isString(t))}),n=o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.",type:i.LexerDefinitionErrorType.INVALID_PATTERN,tokenTypes:[e]}});return{errors:n,valid:o.difference(e,t)}}e.DEFAULT_MODE="defaultMode",e.MODES="modes",e.SUPPORT_STICKY="boolean"==typeof new RegExp("(?:)").sticky,e.disableSticky=function(){e.SUPPORT_STICKY=!1},e.enableSticky=function(){e.SUPPORT_STICKY=!0},e.analyzeTokenTypes=function(t,n){var r,s=(n=o.defaults(n,{useSticky:e.SUPPORT_STICKY,debug:!1,safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r","\n"],tracer:function(e,t){return t()}})).tracer;s("initCharCodeToOptimizedIndexMap",function(){!function(){if(o.isEmpty(R)){R=new Array(65536);for(var e=0;e<65536;e++)R[e]=e>255?255+~~(e/255):e}}()}),s("Reject Lexer.NA",function(){r=o.reject(t,function(e){return e[c]===i.Lexer.NA})});var l,u,h,d,p,f,m,g,b,y,v,x=!1;s("Transform Patterns",function(){x=!1,l=o.map(r,function(e){var t=e[c];if(o.isRegExp(t)){var r=t.source;return 1!==r.length||"^"===r||"$"===r||"."===r||t.ignoreCase?2!==r.length||"\\"!==r[0]||o.contains(["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"],r[1])?n.useSticky?E(t):w(t):r[1]:r}if(o.isFunction(t))return x=!0,{exec:t};if(o.has(t,"exec"))return x=!0,t;if("string"==typeof t){if(1===t.length)return t;var i=t.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),a=new RegExp(i);return n.useSticky?E(a):w(a)}throw Error("non exhaustive match")})}),s("misc mapping",function(){u=o.map(r,function(e){return e.tokenTypeIdx}),h=o.map(r,function(e){var t=e.GROUP;if(t!==i.Lexer.SKIPPED){if(o.isString(t))return t;if(o.isUndefined(t))return!1;throw Error("non exhaustive match")}}),d=o.map(r,function(e){var t=e.LONGER_ALT;if(t)return o.indexOf(r,t)}),p=o.map(r,function(e){return e.PUSH_MODE}),f=o.map(r,function(e){return o.has(e,"POP_MODE")})}),s("Line Terminator Handling",function(){var e=k(n.lineTerminatorCharacters);m=o.map(r,function(e){return!1}),"onlyOffset"!==n.positionTracking&&(m=o.map(r,function(t){return o.has(t,"LINE_BREAKS")?t.LINE_BREAKS:!1===C(t,e)?a.canMatchCharCode(e,t.PATTERN):void 0}))}),s("Misc Mapping #2",function(){g=o.map(r,T),b=o.map(l,A),y=o.reduce(r,function(e,t){var n=t.GROUP;return o.isString(n)&&n!==i.Lexer.SKIPPED&&(e[n]=[]),e},{}),v=o.map(l,function(e,t){return{pattern:l[t],longerAlt:d[t],canLineTerminator:m[t],isCustom:g[t],short:b[t],group:h[t],push:p[t],pop:f[t],tokenTypeIdx:u[t],tokenType:r[t]}})});var O=!0,I=[];return n.safeMode||s("First Char Optimization",function(){I=o.reduce(r,function(e,t,r){if("string"==typeof t.PATTERN){var i=M(t.PATTERN.charCodeAt(0));S(e,i,v[r])}else if(o.isArray(t.START_CHARS_HINT)){var s;o.forEach(t.START_CHARS_HINT,function(t){var n=M("string"==typeof t?t.charCodeAt(0):t);s!==n&&(s=n,S(e,n,v[r]))})}else if(o.isRegExp(t.PATTERN))if(t.PATTERN.unicode)O=!1,n.ensureOptimizations&&o.PRINT_ERROR(a.failedOptimizationPrefixMsg+"\tUnable to analyze < "+t.PATTERN.toString()+" > pattern.\n\tThe regexp unicode flag is not currently supported by the regexp-to-ast library.\n\tThis will disable the lexer's first char optimizations.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE");else{var c=a.getOptimizedStartCodesIndices(t.PATTERN,n.ensureOptimizations);o.isEmpty(c)&&(O=!1),o.forEach(c,function(t){S(e,t,v[r])})}else n.ensureOptimizations&&o.PRINT_ERROR(a.failedOptimizationPrefixMsg+"\tTokenType: <"+t.name+"> is using a custom token pattern without providing <start_chars_hint> parameter.\n\tThis will disable the lexer's first char optimizations.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE"),O=!1;return e},[])}),s("ArrayPacking",function(){I=o.packArray(I)}),{emptyGroups:y,patternIdxToConfig:v,charCodeToPatternIdxToConfig:I,hasCustom:x,canBeOptimized:O}},e.validatePatterns=function(e,t){var n=[],r=l(e);n=n.concat(r.errors);var i=u(r.valid),a=i.valid;return n=(n=n.concat(i.errors)).concat(function(e){var t=[],n=o.filter(e,function(e){return o.isRegExp(e[c])});return t=t.concat(d(n)),t=t.concat(m(n)),t=t.concat(g(n)),t=t.concat(b(n)),t=t.concat(p(n)),t}(a)),n=(n=(n=n.concat(y(a))).concat(v(a,t))).concat(x(a))},e.findMissingPatterns=l,e.findInvalidPatterns=u;var h=/[^\\][\$]/;function d(e){var t=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.found=!1,t}return n(t,e),t.prototype.visitEndAnchor=function(e){this.found=!0},t}(r.BaseRegExpVisitor),a=o.filter(e,function(e){var n=e[c];try{var r=s.getRegExpAst(n),i=new t;return i.visit(r),i.found}catch(e){return h.test(n.source)}}),l=o.map(a,function(e){return{message:"Unexpected RegExp Anchor Error:\n\tToken Type: ->"+e.name+"<- static 'PATTERN' cannot contain end of input anchor '$'\n\tSee chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS\tfor details.",type:i.LexerDefinitionErrorType.EOI_ANCHOR_FOUND,tokenTypes:[e]}});return l}function p(e){var t=o.filter(e,function(e){return e[c].test("")});return o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- static 'PATTERN' must not match an empty string",type:i.LexerDefinitionErrorType.EMPTY_MATCH_PATTERN,tokenTypes:[e]}})}e.findEndOfInputAnchor=d,e.findEmptyMatchRegExps=p;var f=/[^\\[][\^]|^\^/;function m(e){var t=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.found=!1,t}return n(t,e),t.prototype.visitStartAnchor=function(e){this.found=!0},t}(r.BaseRegExpVisitor),a=o.filter(e,function(e){var n=e[c];try{var r=s.getRegExpAst(n),i=new t;return i.visit(r),i.found}catch(e){return f.test(n.source)}}),l=o.map(a,function(e){return{message:"Unexpected RegExp Anchor Error:\n\tToken Type: ->"+e.name+"<- static 'PATTERN' cannot contain start of input anchor '^'\n\tSee https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS\tfor details.",type:i.LexerDefinitionErrorType.SOI_ANCHOR_FOUND,tokenTypes:[e]}});return l}function g(e){var t=o.filter(e,function(e){var t=e[c];return t instanceof RegExp&&(t.multiline||t.global)});return o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:i.LexerDefinitionErrorType.UNSUPPORTED_FLAGS_FOUND,tokenTypes:[e]}})}function b(e){var t=[],n=o.map(e,function(n){return o.reduce(e,function(e,r){return n.PATTERN.source===r.PATTERN.source&&!o.contains(t,r)&&r.PATTERN!==i.Lexer.NA&&(t.push(r),e.push(r)),e},[])});n=o.compact(n);var r=o.filter(n,function(e){return e.length>1});return o.map(r,function(e){var t=o.map(e,function(e){return e.name});return{message:"The same RegExp pattern ->"+o.first(e).PATTERN+"<-has been used in all of the following Token Types: "+t.join(", ")+" <-",type:i.LexerDefinitionErrorType.DUPLICATE_PATTERNS_FOUND,tokenTypes:e}})}function y(e){var t=o.filter(e,function(e){if(!o.has(e,"GROUP"))return!1;var t=e.GROUP;return t!==i.Lexer.SKIPPED&&t!==i.Lexer.NA&&!o.isString(t)});return o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:i.LexerDefinitionErrorType.INVALID_GROUP_TYPE_FOUND,tokenTypes:[e]}})}function v(e,t){var n=o.filter(e,function(e){return void 0!==e.PUSH_MODE&&!o.contains(t,e.PUSH_MODE)}),r=o.map(n,function(e){return{message:"Token Type: ->"+e.name+"<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->"+e.PUSH_MODE+"<-which does not exist",type:i.LexerDefinitionErrorType.PUSH_MODE_DOES_NOT_EXIST,tokenTypes:[e]}});return r}function x(e){var t=[],n=o.reduce(e,function(e,t,n){var r=t.PATTERN;return r===i.Lexer.NA||(o.isString(r)?e.push({str:r,idx:n,tokenType:t}):o.isRegExp(r)&&function(e){var t=[".","\\","[","]","|","^","$","(",")","?","*","+","{"];return void 0===o.find(t,function(t){return-1!==e.source.indexOf(t)})}(r)&&e.push({str:r.source,idx:n,tokenType:t})),e},[]);return o.forEach(e,function(e,r){o.forEach(n,function(n){var a=n.str,s=n.idx,c=n.tokenType;if(r<s&&function(e,t){if(o.isRegExp(t)){var n=t.exec(e);return null!==n&&0===n.index}if(o.isFunction(t))return t(e,0,[],{});if(o.has(t,"exec"))return t.exec(e,0,[],{});if("string"==typeof t)return t===e;throw Error("non exhaustive match")}(a,e.PATTERN)){var l="Token: ->"+c.name+"<- can never be matched.\nBecause it appears AFTER the Token Type ->"+e.name+"<-in the lexer's definition.\nSee https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE";t.push({message:l,type:i.LexerDefinitionErrorType.UNREACHABLE_PATTERN,tokenTypes:[e,c]})}})}),t}function w(e){var t=e.ignoreCase?"i":"";return new RegExp("^(?:"+e.source+")",t)}function E(e){var t=e.ignoreCase?"iy":"y";return new RegExp(""+e.source,t)}function T(e){var t=e.PATTERN;if(o.isRegExp(t))return!1;if(o.isFunction(t))return!0;if(o.has(t,"exec"))return!0;if(o.isString(t))return!1;throw Error("non exhaustive match")}function A(e){return!(!o.isString(e)||1!==e.length)&&e.charCodeAt(0)}function C(e,t){if(o.has(e,"LINE_BREAKS"))return!1;if(o.isRegExp(e.PATTERN)){try{a.canMatchCharCode(t,e.PATTERN)}catch(e){return{issue:i.LexerDefinitionErrorType.IDENTIFY_TERMINATOR,errMsg:e.message}}return!1}if(o.isString(e.PATTERN))return!1;if(T(e))return{issue:i.LexerDefinitionErrorType.CUSTOM_LINE_BREAK};throw Error("non exhaustive match")}function O(e,t){if(t.issue===i.LexerDefinitionErrorType.IDENTIFY_TERMINATOR)return"Warning: unable to identify line terminator usage in pattern.\n\tThe problem is in the <"+e.name+"> Token Type\n\t Root cause: "+t.errMsg+".\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR";if(t.issue===i.LexerDefinitionErrorType.CUSTOM_LINE_BREAK)return"Warning: A Custom Token Pattern should specify the <line_breaks> option.\n\tThe problem is in the <"+e.name+"> Token Type\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK";throw Error("non exhaustive match")}function k(e){return o.map(e,function(e){return o.isString(e)&&e.length>0?e.charCodeAt(0):e})}function S(e,t,n){void 0===e[t]?e[t]=[n]:e[t].push(n)}e.findStartOfInputAnchor=m,e.findUnsupportedFlags=g,e.findDuplicatePatterns=b,e.findInvalidGroupType=y,e.findModesThatDoNotExist=v,e.findUnreachablePatterns=x,e.addStartOfInput=w,e.addStickyFlag=E,e.performRuntimeChecks=function(t,n,r){var a=[];return o.has(t,e.DEFAULT_MODE)||a.push({message:"A MultiMode Lexer cannot be initialized without a <"+e.DEFAULT_MODE+"> property in its definition\n",type:i.LexerDefinitionErrorType.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE}),o.has(t,e.MODES)||a.push({message:"A MultiMode Lexer cannot be initialized without a <"+e.MODES+"> property in its definition\n",type:i.LexerDefinitionErrorType.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY}),o.has(t,e.MODES)&&o.has(t,e.DEFAULT_MODE)&&!o.has(t.modes,t.defaultMode)&&a.push({message:"A MultiMode Lexer cannot be initialized with a "+e.DEFAULT_MODE+": <"+t.defaultMode+">which does not exist\n",type:i.LexerDefinitionErrorType.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST}),o.has(t,e.MODES)&&o.forEach(t.modes,function(e,t){o.forEach(e,function(e,n){o.isUndefined(e)&&a.push({message:"A Lexer cannot be initialized using an undefined Token Type. Mode:<"+t+"> at index: <"+n+">\n",type:i.LexerDefinitionErrorType.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED})})}),a},e.performWarningRuntimeChecks=function(e,t,n){var r=[],s=!1,l=o.compact(o.flatten(o.mapValues(e.modes,function(e){return e}))),u=o.reject(l,function(e){return e[c]===i.Lexer.NA}),h=k(n);return t&&o.forEach(u,function(e){var t=C(e,h);if(!1!==t){var n={message:O(e,t),type:t.issue,tokenType:e};r.push(n)}else o.has(e,"LINE_BREAKS")?!0===e.LINE_BREAKS&&(s=!0):a.canMatchCharCode(h,e.PATTERN)&&(s=!0)}),t&&!s&&r.push({message:"Warning: No LINE_BREAKS Found.\n\tThis Lexer has been defined to track line and column information,\n\tBut none of the Token Types can be identified as matching a line terminator.\n\tSee https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS\n\tfor details.",type:i.LexerDefinitionErrorType.NO_LINE_BREAKS_FLAGS}),r},e.cloneEmptyGroups=function(e){var t={},n=o.keys(e);return o.forEach(n,function(n){var r=e[n];if(!o.isArray(r))throw Error("non exhaustive match");t[n]=[]}),t},e.isCustomPattern=T,e.isShortPattern=A,e.LineTerminatorOptimizedTester={test:function(e){for(var t=e.length,n=this.lastIndex;n<t;n++){var r=e.charCodeAt(n);if(10===r)return this.lastIndex=n+1,!0;if(13===r)return 10===e.charCodeAt(n+1)?this.lastIndex=n+2:this.lastIndex=n+1,!0}return!1},lastIndex:0},e.buildLineBreakIssueMessage=O,e.minOptimizationVal=256;var R=[];function M(t){return t<e.minOptimizationVal?t:R[t]}e.charCodeToOptimizedIndex=M}),oc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.isTokenType=e.hasExtendingTokensTypesMapProperty=e.hasExtendingTokensTypesProperty=e.hasCategoriesProperty=e.hasShortKeyProperty=e.singleAssignCategoriesToksMap=e.assignCategoriesMapProp=e.assignCategoriesTokensProp=e.assignTokenDefaultProps=e.expandCategories=e.augmentTokenTypes=e.tokenIdxToClass=e.tokenShortNameIdx=e.tokenStructuredMatcherNoCategories=e.tokenStructuredMatcher=void 0;var t=ec();function n(e){for(var n=t.cloneArr(e),r=e,i=!0;i;){r=t.compact(t.flatten(t.map(r,function(e){return e.CATEGORIES})));var o=t.difference(r,n);n=n.concat(o),t.isEmpty(o)?i=!1:r=o}return n}function r(n){t.forEach(n,function(n){s(n)||(e.tokenIdxToClass[e.tokenShortNameIdx]=n,n.tokenTypeIdx=e.tokenShortNameIdx++),c(n)&&!t.isArray(n.CATEGORIES)&&(n.CATEGORIES=[n.CATEGORIES]),c(n)||(n.CATEGORIES=[]),l(n)||(n.categoryMatches=[]),u(n)||(n.categoryMatchesMap={})})}function i(n){t.forEach(n,function(n){n.categoryMatches=[],t.forEach(n.categoryMatchesMap,function(t,r){n.categoryMatches.push(e.tokenIdxToClass[r].tokenTypeIdx)})})}function o(e){t.forEach(e,function(e){a([],e)})}function a(e,n){t.forEach(e,function(e){n.categoryMatchesMap[e.tokenTypeIdx]=!0}),t.forEach(n.CATEGORIES,function(r){var i=e.concat(n);t.contains(i,r)||a(i,r)})}function s(e){return t.has(e,"tokenTypeIdx")}function c(e){return t.has(e,"CATEGORIES")}function l(e){return t.has(e,"categoryMatches")}function u(e){return t.has(e,"categoryMatchesMap")}e.tokenStructuredMatcher=function(e,t){var n=e.tokenTypeIdx;return n===t.tokenTypeIdx||!0===t.isParent&&!0===t.categoryMatchesMap[n]},e.tokenStructuredMatcherNoCategories=function(e,t){return e.tokenTypeIdx===t.tokenTypeIdx},e.tokenShortNameIdx=1,e.tokenIdxToClass={},e.augmentTokenTypes=function(e){var a=n(e);r(a),o(a),i(a),t.forEach(a,function(e){e.isParent=e.categoryMatches.length>0})},e.expandCategories=n,e.assignTokenDefaultProps=r,e.assignCategoriesTokensProp=i,e.assignCategoriesMapProp=o,e.singleAssignCategoriesToksMap=a,e.hasShortKeyProperty=s,e.hasCategoriesProperty=c,e.hasExtendingTokensTypesProperty=l,e.hasExtendingTokensTypesMapProperty=u,e.isTokenType=function(e){return t.has(e,"tokenTypeIdx")}}),ac=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defaultLexerErrorProvider=void 0,e.defaultLexerErrorProvider={buildUnableToPopLexerModeMessage:function(e){return"Unable to pop Lexer Mode after encountering Token ->"+e.image+"<- The Mode Stack is empty"},buildUnexpectedCharactersMessage:function(e,t,n,r,i){return"unexpected character: ->"+e.charAt(t)+"<- at offset: "+t+", skipped "+n+" characters."}}}),sc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Lexer=e.LexerDefinitionErrorType=void 0;var t,n=ic(),r=ec(),i=oc(),o=ac(),a=nc();(t=e.LexerDefinitionErrorType||(e.LexerDefinitionErrorType={}))[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",t[t.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",t[t.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",t[t.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",t[t.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",t[t.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",t[t.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",t[t.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK";var s={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:["\n","\r"],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:o.defaultLexerErrorProvider,traceInitPerf:!1,skipValidations:!1};Object.freeze(s);var c=function(){function e(e,t){var o=this;if(void 0===t&&(t=s),this.lexerDefinition=e,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.config=void 0,this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},"boolean"==typeof t)throw Error("The second argument to the Lexer constructor is now an ILexerConfig Object.\na boolean 2nd argument is no longer supported");this.config=r.merge(s,t);var c=this.config.traceInitPerf;!0===c?(this.traceInitMaxIdent=1/0,this.traceInitPerf=!0):"number"==typeof c&&(this.traceInitMaxIdent=c,this.traceInitPerf=!0),this.traceInitIndent=-1,this.TRACE_INIT("Lexer Constructor",function(){var c,l=!0;o.TRACE_INIT("Lexer Config handling",function(){if(o.config.lineTerminatorsPattern===s.lineTerminatorsPattern)o.config.lineTerminatorsPattern=n.LineTerminatorOptimizedTester;else if(o.config.lineTerminatorCharacters===s.lineTerminatorCharacters)throw Error("Error: Missing <lineTerminatorCharacters> property on the Lexer config.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS");if(t.safeMode&&t.ensureOptimizations)throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');o.trackStartLines=/full|onlyStart/i.test(o.config.positionTracking),o.trackEndLines=/full/i.test(o.config.positionTracking),r.isArray(e)?((c={modes:{}}).modes[n.DEFAULT_MODE]=r.cloneArr(e),c[n.DEFAULT_MODE]=n.DEFAULT_MODE):(l=!1,c=r.cloneObj(e))}),!1===o.config.skipValidations&&(o.TRACE_INIT("performRuntimeChecks",function(){o.lexerDefinitionErrors=o.lexerDefinitionErrors.concat(n.performRuntimeChecks(c,o.trackStartLines,o.config.lineTerminatorCharacters))}),o.TRACE_INIT("performWarningRuntimeChecks",function(){o.lexerDefinitionWarning=o.lexerDefinitionWarning.concat(n.performWarningRuntimeChecks(c,o.trackStartLines,o.config.lineTerminatorCharacters))})),c.modes=c.modes?c.modes:{},r.forEach(c.modes,function(e,t){c.modes[t]=r.reject(e,function(e){return r.isUndefined(e)})});var u=r.keys(c.modes);if(r.forEach(c.modes,function(e,a){o.TRACE_INIT("Mode: <"+a+"> processing",function(){var s;(o.modes.push(a),!1===o.config.skipValidations&&o.TRACE_INIT("validatePatterns",function(){o.lexerDefinitionErrors=o.lexerDefinitionErrors.concat(n.validatePatterns(e,u))}),r.isEmpty(o.lexerDefinitionErrors))&&(i.augmentTokenTypes(e),o.TRACE_INIT("analyzeTokenTypes",function(){s=n.analyzeTokenTypes(e,{lineTerminatorCharacters:o.config.lineTerminatorCharacters,positionTracking:t.positionTracking,ensureOptimizations:t.ensureOptimizations,safeMode:t.safeMode,tracer:o.TRACE_INIT.bind(o)})}),o.patternIdxToConfig[a]=s.patternIdxToConfig,o.charCodeToPatternIdxToConfig[a]=s.charCodeToPatternIdxToConfig,o.emptyGroups=r.merge(o.emptyGroups,s.emptyGroups),o.hasCustom=s.hasCustom||o.hasCustom,o.canModeBeOptimized[a]=s.canBeOptimized)})}),o.defaultMode=c.defaultMode,!r.isEmpty(o.lexerDefinitionErrors)&&!o.config.deferDefinitionErrorsHandling){var h=r.map(o.lexerDefinitionErrors,function(e){return e.message}).join("-----------------------\n");throw new Error("Errors detected in definition of Lexer:\n"+h)}r.forEach(o.lexerDefinitionWarning,function(e){r.PRINT_WARNING(e.message)}),o.TRACE_INIT("Choosing sub-methods implementations",function(){if(n.SUPPORT_STICKY?(o.chopInput=r.IDENTITY,o.match=o.matchWithTest):(o.updateLastIndex=r.NOOP,o.match=o.matchWithExec),l&&(o.handleModes=r.NOOP),!1===o.trackStartLines&&(o.computeNewColumn=r.IDENTITY),!1===o.trackEndLines&&(o.updateTokenEndLineColumnLocation=r.NOOP),/full/i.test(o.config.positionTracking))o.createTokenInstance=o.createFullToken;else if(/onlyStart/i.test(o.config.positionTracking))o.createTokenInstance=o.createStartOnlyToken;else{if(!/onlyOffset/i.test(o.config.positionTracking))throw Error('Invalid <positionTracking> config option: "'+o.config.positionTracking+'"');o.createTokenInstance=o.createOffsetOnlyToken}o.hasCustom?(o.addToken=o.addTokenUsingPush,o.handlePayload=o.handlePayloadWithCustom):(o.addToken=o.addTokenUsingMemberAccess,o.handlePayload=o.handlePayloadNoCustom)}),o.TRACE_INIT("Failed Optimization Warnings",function(){var e=r.reduce(o.canModeBeOptimized,function(e,t,n){return!1===t&&e.push(n),e},[]);if(t.ensureOptimizations&&!r.isEmpty(e))throw Error("Lexer Modes: < "+e.join(", ")+' > cannot be optimized.\n\t Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode.\n\t Or inspect the console log for details on how to resolve these issues.')}),o.TRACE_INIT("clearRegExpParserCache",function(){a.clearRegExpParserCache()}),o.TRACE_INIT("toFastProperties",function(){r.toFastProperties(o)})})}return e.prototype.tokenize=function(e,t){if(void 0===t&&(t=this.defaultMode),!r.isEmpty(this.lexerDefinitionErrors)){var n=r.map(this.lexerDefinitionErrors,function(e){return e.message}).join("-----------------------\n");throw new Error("Unable to Tokenize because Errors detected in definition of Lexer:\n"+n)}return this.tokenizeInternal(e,t)},e.prototype.tokenizeInternal=function(e,t){var i,o,a,s,c,l,u,h,d,p,f,m,g,b,y=this,v=e,x=v.length,w=0,E=0,T=this.hasCustom?0:Math.floor(e.length/10),A=new Array(T),C=[],O=this.trackStartLines?1:void 0,k=this.trackStartLines?1:void 0,S=n.cloneEmptyGroups(this.emptyGroups),R=this.trackStartLines,M=this.config.lineTerminatorsPattern,I=0,P=[],_=[],N=[],L=[];Object.freeze(L);var D=void 0;function j(){return P}function F(e){var t=n.charCodeToOptimizedIndex(e),r=_[t];return void 0===r?L:r}var U,B=function(e){if(1===N.length&&void 0===e.tokenType.PUSH_MODE){var t=y.config.errorMessageProvider.buildUnableToPopLexerModeMessage(e);C.push({offset:e.startOffset,line:void 0!==e.startLine?e.startLine:void 0,column:void 0!==e.startColumn?e.startColumn:void 0,length:e.image.length,message:t})}else{N.pop();var n=r.last(N);P=y.patternIdxToConfig[n],_=y.charCodeToPatternIdxToConfig[n],I=P.length;var i=y.canModeBeOptimized[n]&&!1===y.config.safeMode;D=_&&i?F:j}};function z(e){N.push(e),_=this.charCodeToPatternIdxToConfig[e],P=this.patternIdxToConfig[e],I=P.length,I=P.length;var t=this.canModeBeOptimized[e]&&!1===this.config.safeMode;D=_&&t?F:j}for(z.call(this,t);w<x;){c=null;var H=v.charCodeAt(w),V=D(H),G=V.length;for(i=0;i<G;i++){var W=(U=V[i]).pattern;if(l=null,!1!==(te=U.short)?H===te&&(c=W):!0===U.isCustom?null!==(b=W.exec(v,w,A,S))?(c=b[0],void 0!==b.payload&&(l=b.payload)):c=null:(this.updateLastIndex(W,w),c=this.match(W,e,w)),null!==c){if(void 0!==(s=U.longerAlt)){var X=P[s],q=X.pattern;u=null,!0===X.isCustom?null!==(b=q.exec(v,w,A,S))?(a=b[0],void 0!==b.payload&&(u=b.payload)):a=null:(this.updateLastIndex(q,w),a=this.match(q,e,w)),a&&a.length>c.length&&(c=a,l=u,U=X)}break}}if(null!==c){if(h=c.length,void 0!==(d=U.group)&&(p=U.tokenTypeIdx,f=this.createTokenInstance(c,w,p,U.tokenType,O,k,h),this.handlePayload(f,l),!1===d?E=this.addToken(A,E,f):S[d].push(f)),e=this.chopInput(e,h),w+=h,k=this.computeNewColumn(k,h),!0===R&&!0===U.canLineTerminator){var Y=0,K=void 0,Q=void 0;M.lastIndex=0;do{!0===(K=M.test(c))&&(Q=M.lastIndex-1,Y++)}while(!0===K);0!==Y&&(O+=Y,k=h-Q,this.updateTokenEndLineColumnLocation(f,d,Q,Y,O,k,h))}this.handleModes(U,B,z,f)}else{for(var Z=w,$=O,J=k,ee=!1;!ee&&w<x;)for(v.charCodeAt(w),e=this.chopInput(e,1),w++,o=0;o<I;o++){var te,ne=P[o];W=ne.pattern;if(!1!==(te=ne.short)?v.charCodeAt(w)===te&&(ee=!0):!0===ne.isCustom?ee=null!==W.exec(v,w,A,S):(this.updateLastIndex(W,w),ee=null!==W.exec(e)),!0===ee)break}m=w-Z,g=this.config.errorMessageProvider.buildUnexpectedCharactersMessage(v,Z,m,$,J),C.push({offset:Z,line:$,column:J,length:m,message:g})}}return this.hasCustom||(A.length=E),{tokens:A,groups:S,errors:C}},e.prototype.handleModes=function(e,t,n,r){if(!0===e.pop){var i=e.push;t(r),void 0!==i&&n.call(this,i)}else void 0!==e.push&&n.call(this,e.push)},e.prototype.chopInput=function(e,t){return e.substring(t)},e.prototype.updateLastIndex=function(e,t){e.lastIndex=t},e.prototype.updateTokenEndLineColumnLocation=function(e,t,n,r,i,o,a){var s,c;void 0!==t&&(c=(s=n===a-1)?-1:0,1===r&&!0===s||(e.endLine=i+c,e.endColumn=o-1-c))},e.prototype.computeNewColumn=function(e,t){return e+t},e.prototype.createTokenInstance=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return null},e.prototype.createOffsetOnlyToken=function(e,t,n,r){return{image:e,startOffset:t,tokenTypeIdx:n,tokenType:r}},e.prototype.createStartOnlyToken=function(e,t,n,r,i,o){return{image:e,startOffset:t,startLine:i,startColumn:o,tokenTypeIdx:n,tokenType:r}},e.prototype.createFullToken=function(e,t,n,r,i,o,a){return{image:e,startOffset:t,endOffset:t+a-1,startLine:i,endLine:i,startColumn:o,endColumn:o+a-1,tokenTypeIdx:n,tokenType:r}},e.prototype.addToken=function(e,t,n){return 666},e.prototype.addTokenUsingPush=function(e,t,n){return e.push(n),t},e.prototype.addTokenUsingMemberAccess=function(e,t,n){return e[t]=n,++t},e.prototype.handlePayload=function(e,t){},e.prototype.handlePayloadNoCustom=function(e,t){},e.prototype.handlePayloadWithCustom=function(e,t){null!==t&&(e.payload=t)},e.prototype.match=function(e,t,n){return null},e.prototype.matchWithTest=function(e,t,n){return!0===e.test(t)?t.substring(n,e.lastIndex):null},e.prototype.matchWithExec=function(e,t){var n=e.exec(t);return null!==n?n[0]:n},e.prototype.TRACE_INIT=function(e,t){if(!0===this.traceInitPerf){this.traceInitIndent++;var n=new Array(this.traceInitIndent+1).join("\t");this.traceInitIndent<this.traceInitMaxIdent&&console.log(n+"--\x3e <"+e+">");var i=r.timer(t),o=i.time,a=i.value,s=o>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&s(n+"<-- <"+e+"> time: "+o+"ms"),this.traceInitIndent--,a}return t()},e.SKIPPED="This marks a skipped Token pattern, this means each token identified by it willbe consumed and then thrown into oblivion, this can be used to for example to completely ignore whitespace.",e.NA=/NOT_APPLICABLE/,e}();e.Lexer=c}),cc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.tokenMatcher=e.createTokenInstance=e.EOF=e.createToken=e.hasTokenLabel=e.tokenName=e.tokenLabel=void 0;var t=ec(),n=sc(),r=oc();function i(e){return t.isString(e.LABEL)&&""!==e.LABEL}e.tokenLabel=function(e){return i(e)?e.LABEL:e.name},e.tokenName=function(e){return e.name},e.hasTokenLabel=i;var o="parent",a="categories",s="label",c="group",l="push_mode",u="pop_mode",h="longer_alt",d="line_breaks",p="start_chars_hint";function f(e){return function(e){var n=e.pattern,i={};if(i.name=e.name,t.isUndefined(n)||(i.PATTERN=n),t.has(e,o))throw"The parent property is no longer supported.\nSee: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.";return t.has(e,a)&&(i.CATEGORIES=e[a]),r.augmentTokenTypes([i]),t.has(e,s)&&(i.LABEL=e[s]),t.has(e,c)&&(i.GROUP=e[c]),t.has(e,u)&&(i.POP_MODE=e[u]),t.has(e,l)&&(i.PUSH_MODE=e[l]),t.has(e,h)&&(i.LONGER_ALT=e[h]),t.has(e,d)&&(i.LINE_BREAKS=e[d]),t.has(e,p)&&(i.START_CHARS_HINT=e[p]),i}(e)}e.createToken=f,e.EOF=f({name:"EOF",pattern:n.Lexer.NA}),r.augmentTokenTypes([e.EOF]),e.createTokenInstance=function(e,t,n,r,i,o,a,s){return{image:t,startOffset:n,endOffset:r,startLine:i,endLine:o,startColumn:a,endColumn:s,tokenTypeIdx:e.tokenTypeIdx,tokenType:e}},e.tokenMatcher=function(e,t){return r.tokenStructuredMatcher(e,t)}}),lc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.serializeProduction=e.serializeGrammar=e.Terminal=e.Alternation=e.RepetitionWithSeparator=e.Repetition=e.RepetitionMandatoryWithSeparator=e.RepetitionMandatory=e.Option=e.Alternative=e.Rule=e.NonTerminal=e.AbstractProduction=void 0;var r=ec(),i=cc(),o=function(){function e(e){this._definition=e}return Object.defineProperty(e.prototype,"definition",{get:function(){return this._definition},set:function(e){this._definition=e},enumerable:!1,configurable:!0}),e.prototype.accept=function(e){e.visit(this),r.forEach(this.definition,function(t){t.accept(e)})},e}();e.AbstractProduction=o;var a=function(e){function t(t){var n=e.call(this,[])||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),Object.defineProperty(t.prototype,"definition",{get:function(){return void 0!==this.referencedRule?this.referencedRule.definition:[]},set:function(e){},enumerable:!1,configurable:!0}),t.prototype.accept=function(e){e.visit(this)},t}(o);e.NonTerminal=a;var s=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.orgText="",r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.Rule=s;var c=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.ignoreAmbiguities=!1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.Alternative=c;var l=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.Option=l;var u=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.RepetitionMandatory=u;var h=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.RepetitionMandatoryWithSeparator=h;var d=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.Repetition=d;var p=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.RepetitionWithSeparator=p;var f=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,n.ignoreAmbiguities=!1,n.hasPredicates=!1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),Object.defineProperty(t.prototype,"definition",{get:function(){return this._definition},set:function(e){this._definition=e},enumerable:!1,configurable:!0}),t}(o);e.Alternation=f;var m=function(){function e(e){this.idx=1,r.assign(this,r.pick(e,function(e){return void 0!==e}))}return e.prototype.accept=function(e){e.visit(this)},e}();function g(e){function t(e){return r.map(e,g)}if(e instanceof a)return{type:"NonTerminal",name:e.nonTerminalName,idx:e.idx};if(e instanceof c)return{type:"Alternative",definition:t(e.definition)};if(e instanceof l)return{type:"Option",idx:e.idx,definition:t(e.definition)};if(e instanceof u)return{type:"RepetitionMandatory",idx:e.idx,definition:t(e.definition)};if(e instanceof h)return{type:"RepetitionMandatoryWithSeparator",idx:e.idx,separator:g(new m({terminalType:e.separator})),definition:t(e.definition)};if(e instanceof p)return{type:"RepetitionWithSeparator",idx:e.idx,separator:g(new m({terminalType:e.separator})),definition:t(e.definition)};if(e instanceof d)return{type:"Repetition",idx:e.idx,definition:t(e.definition)};if(e instanceof f)return{type:"Alternation",idx:e.idx,definition:t(e.definition)};if(e instanceof m){var n={type:"Terminal",name:e.terminalType.name,label:i.tokenLabel(e.terminalType),idx:e.idx},o=e.terminalType.PATTERN;return e.terminalType.PATTERN&&(n.pattern=r.isRegExp(o)?o.source:o),n}if(e instanceof s)return{type:"Rule",name:e.name,orgText:e.orgText,definition:t(e.definition)};throw Error("non exhaustive match")}e.Terminal=m,e.serializeGrammar=function(e){return r.map(e,g)},e.serializeProduction=g}),uc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RestWalker=void 0;var t=ec(),n=lc(),r=function(){function e(){}return e.prototype.walk=function(e,r){var i=this;void 0===r&&(r=[]),t.forEach(e.definition,function(o,a){var s=t.drop(e.definition,a+1);if(o instanceof n.NonTerminal)i.walkProdRef(o,s,r);else if(o instanceof n.Terminal)i.walkTerminal(o,s,r);else if(o instanceof n.Alternative)i.walkFlat(o,s,r);else if(o instanceof n.Option)i.walkOption(o,s,r);else if(o instanceof n.RepetitionMandatory)i.walkAtLeastOne(o,s,r);else if(o instanceof n.RepetitionMandatoryWithSeparator)i.walkAtLeastOneSep(o,s,r);else if(o instanceof n.RepetitionWithSeparator)i.walkManySep(o,s,r);else if(o instanceof n.Repetition)i.walkMany(o,s,r);else{if(!(o instanceof n.Alternation))throw Error("non exhaustive match");i.walkOr(o,s,r)}})},e.prototype.walkTerminal=function(e,t,n){},e.prototype.walkProdRef=function(e,t,n){},e.prototype.walkFlat=function(e,t,n){var r=t.concat(n);this.walk(e,r)},e.prototype.walkOption=function(e,t,n){var r=t.concat(n);this.walk(e,r)},e.prototype.walkAtLeastOne=function(e,t,r){var i=[new n.Option({definition:e.definition})].concat(t,r);this.walk(e,i)},e.prototype.walkAtLeastOneSep=function(e,t,n){var r=i(e,t,n);this.walk(e,r)},e.prototype.walkMany=function(e,t,r){var i=[new n.Option({definition:e.definition})].concat(t,r);this.walk(e,i)},e.prototype.walkManySep=function(e,t,n){var r=i(e,t,n);this.walk(e,r)},e.prototype.walkOr=function(e,r,i){var o=this,a=r.concat(i);t.forEach(e.definition,function(e){var t=new n.Alternative({definition:[e]});o.walk(t,a)})},e}();function i(e,t,r){return[new n.Option({definition:[new n.Terminal({terminalType:e.separator})].concat(e.definition)})].concat(t,r)}e.RestWalker=r}),hc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.GAstVisitor=void 0;var t=lc(),n=function(){function e(){}return e.prototype.visit=function(e){var n=e;switch(n.constructor){case t.NonTerminal:return this.visitNonTerminal(n);case t.Alternative:return this.visitAlternative(n);case t.Option:return this.visitOption(n);case t.RepetitionMandatory:return this.visitRepetitionMandatory(n);case t.RepetitionMandatoryWithSeparator:return this.visitRepetitionMandatoryWithSeparator(n);case t.RepetitionWithSeparator:return this.visitRepetitionWithSeparator(n);case t.Repetition:return this.visitRepetition(n);case t.Alternation:return this.visitAlternation(n);case t.Terminal:return this.visitTerminal(n);case t.Rule:return this.visitRule(n);default:throw Error("non exhaustive match")}},e.prototype.visitNonTerminal=function(e){},e.prototype.visitAlternative=function(e){},e.prototype.visitOption=function(e){},e.prototype.visitRepetition=function(e){},e.prototype.visitRepetitionMandatory=function(e){},e.prototype.visitRepetitionMandatoryWithSeparator=function(e){},e.prototype.visitRepetitionWithSeparator=function(e){},e.prototype.visitAlternation=function(e){},e.prototype.visitTerminal=function(e){},e.prototype.visitRule=function(e){},e}();e.GAstVisitor=n}),dc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.collectMethods=e.DslMethodsCollectorVisitor=e.getProductionDslName=e.isBranchingProd=e.isOptionalProd=e.isSequenceProd=void 0;var r=ec(),i=lc(),o=hc();e.isSequenceProd=function(e){return e instanceof i.Alternative||e instanceof i.Option||e instanceof i.Repetition||e instanceof i.RepetitionMandatory||e instanceof i.RepetitionMandatoryWithSeparator||e instanceof i.RepetitionWithSeparator||e instanceof i.Terminal||e instanceof i.Rule},e.isOptionalProd=function e(t,n){return void 0===n&&(n=[]),!!(t instanceof i.Option||t instanceof i.Repetition||t instanceof i.RepetitionWithSeparator)||(t instanceof i.Alternation?r.some(t.definition,function(t){return e(t,n)}):!(t instanceof i.NonTerminal&&r.contains(n,t))&&(t instanceof i.AbstractProduction&&(t instanceof i.NonTerminal&&n.push(t),r.every(t.definition,function(t){return e(t,n)}))))},e.isBranchingProd=function(e){return e instanceof i.Alternation},e.getProductionDslName=function(e){if(e instanceof i.NonTerminal)return"SUBRULE";if(e instanceof i.Option)return"OPTION";if(e instanceof i.Alternation)return"OR";if(e instanceof i.RepetitionMandatory)return"AT_LEAST_ONE";if(e instanceof i.RepetitionMandatoryWithSeparator)return"AT_LEAST_ONE_SEP";if(e instanceof i.RepetitionWithSeparator)return"MANY_SEP";if(e instanceof i.Repetition)return"MANY";if(e instanceof i.Terminal)return"CONSUME";throw Error("non exhaustive match")};var a=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.separator="-",t.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]},t}return n(t,e),t.prototype.reset=function(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}},t.prototype.visitTerminal=function(e){var t=e.terminalType.name+this.separator+"Terminal";r.has(this.dslMethods,t)||(this.dslMethods[t]=[]),this.dslMethods[t].push(e)},t.prototype.visitNonTerminal=function(e){var t=e.nonTerminalName+this.separator+"Terminal";r.has(this.dslMethods,t)||(this.dslMethods[t]=[]),this.dslMethods[t].push(e)},t.prototype.visitOption=function(e){this.dslMethods.option.push(e)},t.prototype.visitRepetitionWithSeparator=function(e){this.dslMethods.repetitionWithSeparator.push(e)},t.prototype.visitRepetitionMandatory=function(e){this.dslMethods.repetitionMandatory.push(e)},t.prototype.visitRepetitionMandatoryWithSeparator=function(e){this.dslMethods.repetitionMandatoryWithSeparator.push(e)},t.prototype.visitRepetition=function(e){this.dslMethods.repetition.push(e)},t.prototype.visitAlternation=function(e){this.dslMethods.alternation.push(e)},t}(o.GAstVisitor);e.DslMethodsCollectorVisitor=a;var s=new a;e.collectMethods=function(e){s.reset(),e.accept(s);var t=s.dslMethods;return s.reset(),t}}),pc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.firstForTerminal=e.firstForBranching=e.firstForSequence=e.first=void 0;var t=ec(),n=lc(),r=dc();function i(e){if(e instanceof n.NonTerminal)return i(e.referencedRule);if(e instanceof n.Terminal)return s(e);if(r.isSequenceProd(e))return o(e);if(r.isBranchingProd(e))return a(e);throw Error("non exhaustive match")}function o(e){for(var n,o=[],a=e.definition,s=0,c=a.length>s,l=!0;c&&l;)n=a[s],l=r.isOptionalProd(n),o=o.concat(i(n)),s+=1,c=a.length>s;return t.uniq(o)}function a(e){var n=t.map(e.definition,function(e){return i(e)});return t.uniq(t.flatten(n))}function s(e){return[e.terminalType]}e.first=i,e.firstForSequence=o,e.firstForBranching=a,e.firstForTerminal=s}),fc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.IN=void 0,e.IN="_~IN~_"}),mc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.buildInProdFollowPrefix=e.buildBetweenProdsFollowPrefix=e.computeAllProdsFollows=e.ResyncFollowsWalker=void 0;var r=uc(),i=pc(),o=ec(),a=fc(),s=lc(),c=function(e){function t(t){var n=e.call(this)||this;return n.topProd=t,n.follows={},n}return n(t,e),t.prototype.startWalking=function(){return this.walk(this.topProd),this.follows},t.prototype.walkTerminal=function(e,t,n){},t.prototype.walkProdRef=function(e,t,n){var r=l(e.referencedRule,e.idx)+this.topProd.name,o=t.concat(n),a=new s.Alternative({definition:o}),c=i.first(a);this.follows[r]=c},t}(r.RestWalker);function l(e,t){return e.name+t+a.IN}e.ResyncFollowsWalker=c,e.computeAllProdsFollows=function(e){var t={};return o.forEach(e,function(e){var n=new c(e).startWalking();o.assign(t,n)}),t},e.buildBetweenProdsFollowPrefix=l,e.buildInProdFollowPrefix=function(e){return e.terminalType.name+e.idx+a.IN}}),gc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defaultGrammarValidatorErrorProvider=e.defaultGrammarResolverErrorProvider=e.defaultParserErrorProvider=void 0;var t=cc(),n=ec(),r=ec(),i=lc(),o=dc();e.defaultParserErrorProvider={buildMismatchTokenMessage:function(e){var n=e.expected,r=e.actual;return e.previous,e.ruleName,"Expecting "+(t.hasTokenLabel(n)?"--\x3e "+t.tokenLabel(n)+" <--":"token of type --\x3e "+n.name+" <--")+" but found --\x3e '"+r.image+"' <--"},buildNotAllInputParsedMessage:function(e){var t=e.firstRedundant;return e.ruleName,"Redundant input, expecting EOF but found: "+t.image},buildNoViableAltMessage:function(e){var n=e.expectedPathsPerAlt,i=e.actual;e.previous;var o=e.customUserDescription;e.ruleName;var a="Expecting: ",s="\nbut found: '"+r.first(i).image+"'";if(o)return a+o+s;var c=r.reduce(n,function(e,t){return e.concat(t)},[]),l=r.map(c,function(e){return"["+r.map(e,function(e){return t.tokenLabel(e)}).join(", ")+"]"});return a+("one of these possible Token sequences:\n"+r.map(l,function(e,t){return" "+(t+1)+". "+e}).join("\n"))+s},buildEarlyExitMessage:function(e){var n=e.expectedIterationPaths,i=e.actual,o=e.customUserDescription;e.ruleName;var a="Expecting: ",s="\nbut found: '"+r.first(i).image+"'";return o?a+o+s:a+("expecting at least one iteration which starts with one of these possible Token sequences::\n <"+r.map(n,function(e){return"["+r.map(e,function(e){return t.tokenLabel(e)}).join(",")+"]"}).join(" ,")+">")+s}},Object.freeze(e.defaultParserErrorProvider),e.defaultGrammarResolverErrorProvider={buildRuleNotFoundError:function(e,t){return"Invalid grammar, reference to a rule which is not defined: ->"+t.nonTerminalName+"<-\ninside top level rule: ->"+e.name+"<-"}},e.defaultGrammarValidatorErrorProvider={buildDuplicateFoundError:function(e,t){var n,a=e.name,s=r.first(t),c=s.idx,l=o.getProductionDslName(s),u=(n=s)instanceof i.Terminal?n.terminalType.name:n instanceof i.NonTerminal?n.nonTerminalName:"",h="->"+l+(c>0?c:"")+"<- "+(u?"with argument: ->"+u+"<-":"")+"\n appears more than once ("+t.length+" times) in the top level rule: ->"+a+"<-.\n For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES\n ";return h=(h=h.replace(/[ \t]+/g," ")).replace(/\s\s+/g,"\n")},buildNamespaceConflictError:function(e){return"Namespace conflict found in grammar.\nThe grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <"+e.name+">.\nTo resolve this make sure each Terminal and Non-Terminal names are unique\nThis is easy to accomplish by using the convention that Terminal names start with an uppercase letter\nand Non-Terminal names start with a lower case letter."},buildAlternationPrefixAmbiguityError:function(e){var n=r.map(e.prefixPath,function(e){return t.tokenLabel(e)}).join(", "),i=0===e.alternation.idx?"":e.alternation.idx;return"Ambiguous alternatives: <"+e.ambiguityIndices.join(" ,")+"> due to common lookahead prefix\nin <OR"+i+"> inside <"+e.topLevelRule.name+"> Rule,\n<"+n+"> may appears as a prefix path in all these alternatives.\nSee: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX\nFor Further details."},buildAlternationAmbiguityError:function(e){var n=r.map(e.prefixPath,function(e){return t.tokenLabel(e)}).join(", "),i=0===e.alternation.idx?"":e.alternation.idx,o="Ambiguous Alternatives Detected: <"+e.ambiguityIndices.join(" ,")+"> in <OR"+i+"> inside <"+e.topLevelRule.name+"> Rule,\n<"+n+"> may appears as a prefix path in all these alternatives.\n";return o+="See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES\nFor Further details."},buildEmptyRepetitionError:function(e){var t=o.getProductionDslName(e.repetition);return 0!==e.repetition.idx&&(t+=e.repetition.idx),"The repetition <"+t+"> within Rule <"+e.topLevelRule.name+"> can never consume any tokens.\nThis could lead to an infinite loop."},buildTokenNameError:function(e){return"deprecated"},buildEmptyAlternationError:function(e){return"Ambiguous empty alternative: <"+(e.emptyChoiceIdx+1)+"> in <OR"+e.alternation.idx+"> inside <"+e.topLevelRule.name+"> Rule.\nOnly the last alternative may be an empty alternative."},buildTooManyAlternativesError:function(e){return"An Alternation cannot have more than 256 alternatives:\n<OR"+e.alternation.idx+"> inside <"+e.topLevelRule.name+"> Rule.\n has "+(e.alternation.definition.length+1)+" alternatives."},buildLeftRecursionError:function(e){var t=e.topLevelRule.name;return"Left Recursion found in grammar.\nrule: <"+t+"> can be invoked from itself (directly or indirectly)\nwithout consuming any Tokens. The grammar path that causes this is:\n "+(t+" --\x3e "+n.map(e.leftRecursionPath,function(e){return e.name}).concat([t]).join(" --\x3e "))+"\n To fix this refactor your grammar to remove the left recursion.\nsee: https://en.wikipedia.org/wiki/LL_parser#Left_Factoring."},buildInvalidRuleNameError:function(e){return"deprecated"},buildDuplicateRuleNameError:function(e){return"Duplicate definition, rule: ->"+(e.topLevelRule instanceof i.Rule?e.topLevelRule.name:e.topLevelRule)+"<- is already defined in the grammar: ->"+e.grammarName+"<-"}}}),bc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.GastRefResolverVisitor=e.resolveGrammar=void 0;var r=Fc(),i=ec(),o=hc();e.resolveGrammar=function(e,t){var n=new a(e,t);return n.resolveRefs(),n.errors};var a=function(e){function t(t,n){var r=e.call(this)||this;return r.nameToTopRule=t,r.errMsgProvider=n,r.errors=[],r}return n(t,e),t.prototype.resolveRefs=function(){var e=this;i.forEach(i.values(this.nameToTopRule),function(t){e.currTopLevel=t,t.accept(e)})},t.prototype.visitNonTerminal=function(e){var t=this.nameToTopRule[e.nonTerminalName];if(t)e.referencedRule=t;else{var n=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,e);this.errors.push({message:n,type:r.ParserDefinitionErrorType.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:e.nonTerminalName})}},t}(o.GAstVisitor);e.GastRefResolverVisitor=a}),yc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.nextPossibleTokensAfter=e.possiblePathsFrom=e.NextTerminalAfterAtLeastOneSepWalker=e.NextTerminalAfterAtLeastOneWalker=e.NextTerminalAfterManySepWalker=e.NextTerminalAfterManyWalker=e.AbstractNextTerminalAfterProductionWalker=e.NextAfterTokenWalker=e.AbstractNextPossibleTokensWalker=void 0;var r=uc(),i=ec(),o=pc(),a=lc(),s=function(e){function t(t,n){var r=e.call(this)||this;return r.topProd=t,r.path=n,r.possibleTokTypes=[],r.nextProductionName="",r.nextProductionOccurrence=0,r.found=!1,r.isAtEndOfPath=!1,r}return n(t,e),t.prototype.startWalking=function(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=i.cloneArr(this.path.ruleStack).reverse(),this.occurrenceStack=i.cloneArr(this.path.occurrenceStack).reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes},t.prototype.walk=function(t,n){void 0===n&&(n=[]),this.found||e.prototype.walk.call(this,t,n)},t.prototype.walkProdRef=function(e,t,n){if(e.referencedRule.name===this.nextProductionName&&e.idx===this.nextProductionOccurrence){var r=t.concat(n);this.updateExpectedNext(),this.walk(e.referencedRule,r)}},t.prototype.updateExpectedNext=function(){i.isEmpty(this.ruleStack)?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())},t}(r.RestWalker);e.AbstractNextPossibleTokensWalker=s;var c=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.path=n,r.nextTerminalName="",r.nextTerminalOccurrence=0,r.nextTerminalName=r.path.lastTok.name,r.nextTerminalOccurrence=r.path.lastTokOccurrence,r}return n(t,e),t.prototype.walkTerminal=function(e,t,n){if(this.isAtEndOfPath&&e.terminalType.name===this.nextTerminalName&&e.idx===this.nextTerminalOccurrence&&!this.found){var r=t.concat(n),i=new a.Alternative({definition:r});this.possibleTokTypes=o.first(i),this.found=!0}},t}(s);e.NextAfterTokenWalker=c;var l=function(e){function t(t,n){var r=e.call(this)||this;return r.topRule=t,r.occurrence=n,r.result={token:void 0,occurrence:void 0,isEndOfRule:void 0},r}return n(t,e),t.prototype.startWalking=function(){return this.walk(this.topRule),this.result},t}(r.RestWalker);e.AbstractNextTerminalAfterProductionWalker=l;var u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.walkMany=function(t,n,r){if(t.idx===this.occurrence){var o=i.first(n.concat(r));this.result.isEndOfRule=void 0===o,o instanceof a.Terminal&&(this.result.token=o.terminalType,this.result.occurrence=o.idx)}else e.prototype.walkMany.call(this,t,n,r)},t}(l);e.NextTerminalAfterManyWalker=u;var h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.walkManySep=function(t,n,r){if(t.idx===this.occurrence){var o=i.first(n.concat(r));this.result.isEndOfRule=void 0===o,o instanceof a.Terminal&&(this.result.token=o.terminalType,this.result.occurrence=o.idx)}else e.prototype.walkManySep.call(this,t,n,r)},t}(l);e.NextTerminalAfterManySepWalker=h;var d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.walkAtLeastOne=function(t,n,r){if(t.idx===this.occurrence){var o=i.first(n.concat(r));this.result.isEndOfRule=void 0===o,o instanceof a.Terminal&&(this.result.token=o.terminalType,this.result.occurrence=o.idx)}else e.prototype.walkAtLeastOne.call(this,t,n,r)},t}(l);e.NextTerminalAfterAtLeastOneWalker=d;var p=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.walkAtLeastOneSep=function(t,n,r){if(t.idx===this.occurrence){var o=i.first(n.concat(r));this.result.isEndOfRule=void 0===o,o instanceof a.Terminal&&(this.result.token=o.terminalType,this.result.occurrence=o.idx)}else e.prototype.walkAtLeastOneSep.call(this,t,n,r)},t}(l);function f(e,t,n,r){var o=i.cloneArr(n);o.push(e.name);var a=i.cloneArr(r);return a.push(1),{idx:t,def:e.definition,ruleStack:o,occurrenceStack:a}}e.NextTerminalAfterAtLeastOneSepWalker=p,e.possiblePathsFrom=function e(t,n,r){void 0===r&&(r=[]),r=i.cloneArr(r);var o=[],s=0;function c(a){var c=e(function(e){return e.concat(i.drop(t,s+1))}(a),n,r);return o.concat(c)}for(;r.length<n&&s<t.length;){var l=t[s];if(l instanceof a.Alternative)return c(l.definition);if(l instanceof a.NonTerminal)return c(l.definition);if(l instanceof a.Option)o=c(l.definition);else{if(l instanceof a.RepetitionMandatory)return c(u=l.definition.concat([new a.Repetition({definition:l.definition})]));if(l instanceof a.RepetitionMandatoryWithSeparator)return c(u=[new a.Alternative({definition:l.definition}),new a.Repetition({definition:[new a.Terminal({terminalType:l.separator})].concat(l.definition)})]);if(l instanceof a.RepetitionWithSeparator){var u=l.definition.concat([new a.Repetition({definition:[new a.Terminal({terminalType:l.separator})].concat(l.definition)})]);o=c(u)}else if(l instanceof a.Repetition){u=l.definition.concat([new a.Repetition({definition:l.definition})]);o=c(u)}else{if(l instanceof a.Alternation)return i.forEach(l.definition,function(e){!1===i.isEmpty(e.definition)&&(o=c(e.definition))}),o;if(!(l instanceof a.Terminal))throw Error("non exhaustive match");r.push(l.terminalType)}}s++}return o.push({partialPath:r,suffixDef:i.drop(t,s)}),o},e.nextPossibleTokensAfter=function(e,t,n,r){var o="EXIT_NONE_TERMINAL",s=[o],c="EXIT_ALTERNATIVE",l=!1,u=t.length,h=u-r-1,d=[],p=[];for(p.push({idx:-1,def:e,ruleStack:[],occurrenceStack:[]});!i.isEmpty(p);){var m=p.pop();if(m!==c){var g=m.def,b=m.idx,y=m.ruleStack,v=m.occurrenceStack;if(!i.isEmpty(g)){var x=g[0];if(x===o){var w={idx:b,def:i.drop(g),ruleStack:i.dropRight(y),occurrenceStack:i.dropRight(v)};p.push(w)}else if(x instanceof a.Terminal)if(b<u-1){var E=b+1;if(n(t[E],x.terminalType)){w={idx:E,def:i.drop(g),ruleStack:y,occurrenceStack:v};p.push(w)}}else{if(b!==u-1)throw Error("non exhaustive match");d.push({nextTokenType:x.terminalType,nextTokenOccurrence:x.idx,ruleStack:y,occurrenceStack:v}),l=!0}else if(x instanceof a.NonTerminal){var T=i.cloneArr(y);T.push(x.nonTerminalName);var A=i.cloneArr(v);A.push(x.idx);w={idx:b,def:x.definition.concat(s,i.drop(g)),ruleStack:T,occurrenceStack:A};p.push(w)}else if(x instanceof a.Option){var C={idx:b,def:i.drop(g),ruleStack:y,occurrenceStack:v};p.push(C),p.push(c);var O={idx:b,def:x.definition.concat(i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(O)}else if(x instanceof a.RepetitionMandatory){var k=new a.Repetition({definition:x.definition,idx:x.idx});w={idx:b,def:x.definition.concat([k],i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(w)}else if(x instanceof a.RepetitionMandatoryWithSeparator){var S=new a.Terminal({terminalType:x.separator});k=new a.Repetition({definition:[S].concat(x.definition),idx:x.idx}),w={idx:b,def:x.definition.concat([k],i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(w)}else if(x instanceof a.RepetitionWithSeparator){C={idx:b,def:i.drop(g),ruleStack:y,occurrenceStack:v};p.push(C),p.push(c);S=new a.Terminal({terminalType:x.separator});var R=new a.Repetition({definition:[S].concat(x.definition),idx:x.idx});O={idx:b,def:x.definition.concat([R],i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(O)}else if(x instanceof a.Repetition){C={idx:b,def:i.drop(g),ruleStack:y,occurrenceStack:v};p.push(C),p.push(c);R=new a.Repetition({definition:x.definition,idx:x.idx}),O={idx:b,def:x.definition.concat([R],i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(O)}else if(x instanceof a.Alternation)for(var M=x.definition.length-1;M>=0;M--){var I={idx:b,def:x.definition[M].definition.concat(i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(I),p.push(c)}else if(x instanceof a.Alternative)p.push({idx:b,def:x.definition.concat(i.drop(g)),ruleStack:y,occurrenceStack:v});else{if(!(x instanceof a.Rule))throw Error("non exhaustive match");p.push(f(x,b,y,v))}}}else l&&i.last(p).idx<=h&&p.pop()}return d}}),vc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.areTokenCategoriesNotUsed=e.isStrictPrefixOfPath=e.containsPath=e.getLookaheadPathsForOptionalProd=e.getLookaheadPathsForOr=e.lookAheadSequenceFromAlternatives=e.buildSingleAlternativeLookaheadFunction=e.buildAlternativesLookAheadFunc=e.buildLookaheadFuncForOptionalProd=e.buildLookaheadFuncForOr=e.getProdType=e.PROD_TYPE=void 0;var r,i=ec(),o=yc(),a=uc(),s=oc(),c=lc(),l=hc();!function(e){e[e.OPTION=0]="OPTION",e[e.REPETITION=1]="REPETITION",e[e.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",e[e.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",e[e.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",e[e.ALTERNATION=5]="ALTERNATION"}(r=e.PROD_TYPE||(e.PROD_TYPE={})),e.getProdType=function(e){if(e instanceof c.Option)return r.OPTION;if(e instanceof c.Repetition)return r.REPETITION;if(e instanceof c.RepetitionMandatory)return r.REPETITION_MANDATORY;if(e instanceof c.RepetitionMandatoryWithSeparator)return r.REPETITION_MANDATORY_WITH_SEPARATOR;if(e instanceof c.RepetitionWithSeparator)return r.REPETITION_WITH_SEPARATOR;if(e instanceof c.Alternation)return r.ALTERNATION;throw Error("non exhaustive match")},e.buildLookaheadFuncForOr=function(e,t,n,r,i,o){var a=g(e,t,n);return o(a,r,v(a)?s.tokenStructuredMatcherNoCategories:s.tokenStructuredMatcher,i)},e.buildLookaheadFuncForOptionalProd=function(e,t,n,r,i,o){var a=b(e,t,i,n),c=v(a)?s.tokenStructuredMatcherNoCategories:s.tokenStructuredMatcher;return o(a[0],c,r)},e.buildAlternativesLookAheadFunc=function(e,t,n,r){var o=e.length,a=i.every(e,function(e){return i.every(e,function(e){return 1===e.length})});if(t)return function(t){for(var r=i.map(t,function(e){return e.GATE}),a=0;a<o;a++){var s=e[a],c=s.length,l=r[a];if(void 0===l||!1!==l.call(this))e:for(var u=0;u<c;u++){for(var h=s[u],d=h.length,p=0;p<d;p++){var f=this.LA(p+1);if(!1===n(f,h[p]))continue e}return a}}};if(a&&!r){var s=i.map(e,function(e){return i.flatten(e)}),c=i.reduce(s,function(e,t,n){return i.forEach(t,function(t){i.has(e,t.tokenTypeIdx)||(e[t.tokenTypeIdx]=n),i.forEach(t.categoryMatches,function(t){i.has(e,t)||(e[t]=n)})}),e},[]);return function(){var e=this.LA(1);return c[e.tokenTypeIdx]}}return function(){for(var t=0;t<o;t++){var r=e[t],i=r.length;e:for(var a=0;a<i;a++){for(var s=r[a],c=s.length,l=0;l<c;l++){var u=this.LA(l+1);if(!1===n(u,s[l]))continue e}return t}}}},e.buildSingleAlternativeLookaheadFunction=function(e,t,n){var r=i.every(e,function(e){return 1===e.length}),o=e.length;if(r&&!n){var a=i.flatten(e);if(1===a.length&&i.isEmpty(a[0].categoryMatches)){var s=a[0].tokenTypeIdx;return function(){return this.LA(1).tokenTypeIdx===s}}var c=i.reduce(a,function(e,t,n){return e[t.tokenTypeIdx]=!0,i.forEach(t.categoryMatches,function(t){e[t]=!0}),e},[]);return function(){var e=this.LA(1);return!0===c[e.tokenTypeIdx]}}return function(){e:for(var n=0;n<o;n++){for(var r=e[n],i=r.length,a=0;a<i;a++){var s=this.LA(a+1);if(!1===t(s,r[a]))continue e}return!0}return!1}};var u=function(e){function t(t,n,r){var i=e.call(this)||this;return i.topProd=t,i.targetOccurrence=n,i.targetProdType=r,i}return n(t,e),t.prototype.startWalking=function(){return this.walk(this.topProd),this.restDef},t.prototype.checkIsTarget=function(e,t,n,r){return e.idx===this.targetOccurrence&&this.targetProdType===t&&(this.restDef=n.concat(r),!0)},t.prototype.walkOption=function(t,n,i){this.checkIsTarget(t,r.OPTION,n,i)||e.prototype.walkOption.call(this,t,n,i)},t.prototype.walkAtLeastOne=function(t,n,i){this.checkIsTarget(t,r.REPETITION_MANDATORY,n,i)||e.prototype.walkOption.call(this,t,n,i)},t.prototype.walkAtLeastOneSep=function(t,n,i){this.checkIsTarget(t,r.REPETITION_MANDATORY_WITH_SEPARATOR,n,i)||e.prototype.walkOption.call(this,t,n,i)},t.prototype.walkMany=function(t,n,i){this.checkIsTarget(t,r.REPETITION,n,i)||e.prototype.walkOption.call(this,t,n,i)},t.prototype.walkManySep=function(t,n,i){this.checkIsTarget(t,r.REPETITION_WITH_SEPARATOR,n,i)||e.prototype.walkOption.call(this,t,n,i)},t}(a.RestWalker),h=function(e){function t(t,n,r){var i=e.call(this)||this;return i.targetOccurrence=t,i.targetProdType=n,i.targetRef=r,i.result=[],i}return n(t,e),t.prototype.checkIsTarget=function(e,t){e.idx===this.targetOccurrence&&this.targetProdType===t&&(void 0===this.targetRef||e===this.targetRef)&&(this.result=e.definition)},t.prototype.visitOption=function(e){this.checkIsTarget(e,r.OPTION)},t.prototype.visitRepetition=function(e){this.checkIsTarget(e,r.REPETITION)},t.prototype.visitRepetitionMandatory=function(e){this.checkIsTarget(e,r.REPETITION_MANDATORY)},t.prototype.visitRepetitionMandatoryWithSeparator=function(e){this.checkIsTarget(e,r.REPETITION_MANDATORY_WITH_SEPARATOR)},t.prototype.visitRepetitionWithSeparator=function(e){this.checkIsTarget(e,r.REPETITION_WITH_SEPARATOR)},t.prototype.visitAlternation=function(e){this.checkIsTarget(e,r.ALTERNATION)},t}(l.GAstVisitor);function d(e){for(var t=new Array(e),n=0;n<e;n++)t[n]=[];return t}function p(e){for(var t=[""],n=0;n<e.length;n++){for(var r=e[n],i=[],o=0;o<t.length;o++){var a=t[o];i.push(a+"_"+r.tokenTypeIdx);for(var s=0;s<r.categoryMatches.length;s++){var c="_"+r.categoryMatches[s];i.push(a+c)}}t=i}return t}function f(e,t,n){for(var r=0;r<e.length;r++)if(r!==n)for(var i=e[r],o=0;o<t.length;o++){if(!0===i[t[o]])return!1}return!0}function m(e,t){for(var n=i.map(e,function(e){return o.possiblePathsFrom([e],1)}),r=d(n.length),a=i.map(n,function(e){var t={};return i.forEach(e,function(e){var n=p(e.partialPath);i.forEach(n,function(e){t[e]=!0})}),t}),s=n,c=1;c<=t;c++){var l=s;s=d(l.length);for(var u=function(e){for(var n=l[e],u=0;u<n.length;u++){var h=n[u].partialPath,d=n[u].suffixDef,m=p(h);if(f(a,m,e)||i.isEmpty(d)||h.length===t){var g=r[e];if(!1===y(g,h)){g.push(h);for(var b=0;b<m.length;b++){var v=m[b];a[e][v]=!0}}}else{var x=o.possiblePathsFrom(d,c+1,h);s[e]=s[e].concat(x),i.forEach(x,function(t){var n=p(t.partialPath);i.forEach(n,function(t){a[e][t]=!0})})}}},h=0;h<l.length;h++)u(h)}return r}function g(e,t,n,i){var o=new h(e,r.ALTERNATION,i);return t.accept(o),m(o.result,n)}function b(e,t,n,r){var i=new h(e,n);t.accept(i);var o=i.result,a=new u(t,e,n).startWalking();return m([new c.Alternative({definition:o}),new c.Alternative({definition:a})],r)}function y(e,t){e:for(var n=0;n<e.length;n++){var r=e[n];if(r.length===t.length){for(var i=0;i<r.length;i++){var o=t[i],a=r[i];if(!1===(o===a||void 0!==a.categoryMatchesMap[o.tokenTypeIdx]))continue e}return!0}}return!1}function v(e){return i.every(e,function(e){return i.every(e,function(e){return i.every(e,function(e){return i.isEmpty(e.categoryMatches)})})})}e.lookAheadSequenceFromAlternatives=m,e.getLookaheadPathsForOr=g,e.getLookaheadPathsForOptionalProd=b,e.containsPath=y,e.isStrictPrefixOfPath=function(e,t){return e.length<t.length&&i.every(e,function(e,n){var r=t[n];return e===r||r.categoryMatchesMap[e.tokenTypeIdx]})},e.areTokenCategoriesNotUsed=v}),xc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.checkPrefixAlternativesAmbiguities=e.validateSomeNonEmptyLookaheadPath=e.validateTooManyAlts=e.RepetionCollector=e.validateAmbiguousAlternationAlternatives=e.validateEmptyOrAlternative=e.getFirstNoneTerminal=e.validateNoLeftRecursion=e.validateRuleIsOverridden=e.validateRuleDoesNotAlreadyExist=e.OccurrenceValidationCollector=e.identifyProductionForDuplicates=e.validateGrammar=void 0;var r=ec(),i=ec(),o=Fc(),a=dc(),s=vc(),c=yc(),l=lc(),u=hc();function h(e){return a.getProductionDslName(e)+"_#_"+e.idx+"_#_"+d(e)}function d(e){return e instanceof l.Terminal?e.terminalType.name:e instanceof l.NonTerminal?e.nonTerminalName:""}e.validateGrammar=function(e,t,n,s,c){var l=r.map(e,function(e){return function(e,t){var n=new p;e.accept(n);var i=n.allProductions,s=r.groupBy(i,h),c=r.pick(s,function(e){return e.length>1}),l=r.map(r.values(c),function(n){var i=r.first(n),s=t.buildDuplicateFoundError(e,n),c=a.getProductionDslName(i),l={message:s,type:o.ParserDefinitionErrorType.DUPLICATE_PRODUCTIONS,ruleName:e.name,dslName:c,occurrence:i.idx},u=d(i);return u&&(l.parameter=u),l});return l}(e,s)}),u=r.map(e,function(e){return m(e,e,s)}),g=[],b=[],x=[];i.every(u,i.isEmpty)&&(g=i.map(e,function(e){return y(e,s)}),b=i.map(e,function(e){return v(e,t,s)}),x=E(e,t,s));var T=function(e,t,n){var r=[],a=i.map(t,function(e){return e.name});return i.forEach(e,function(e){var t=e.name;if(i.contains(a,t)){var s=n.buildNamespaceConflictError(e);r.push({message:s,type:o.ParserDefinitionErrorType.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:t})}}),r}(e,n,s),A=i.map(e,function(e){return w(e,s)}),C=i.map(e,function(t){return f(t,e,c,s)});return r.flatten(l.concat(x,u,g,b,T,A,C))},e.identifyProductionForDuplicates=h;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.allProductions=[],t}return n(t,e),t.prototype.visitNonTerminal=function(e){this.allProductions.push(e)},t.prototype.visitOption=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionWithSeparator=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionMandatory=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionMandatoryWithSeparator=function(e){this.allProductions.push(e)},t.prototype.visitRepetition=function(e){this.allProductions.push(e)},t.prototype.visitAlternation=function(e){this.allProductions.push(e)},t.prototype.visitTerminal=function(e){this.allProductions.push(e)},t}(u.GAstVisitor);function f(e,t,n,r){var a=[];if(i.reduce(t,function(t,n){return n.name===e.name?t+1:t},0)>1){var s=r.buildDuplicateRuleNameError({topLevelRule:e,grammarName:n});a.push({message:s,type:o.ParserDefinitionErrorType.DUPLICATE_RULE_NAME,ruleName:e.name})}return a}function m(e,t,n,i){void 0===i&&(i=[]);var a=[],s=g(t.definition);if(r.isEmpty(s))return[];var c=e.name;r.contains(s,e)&&a.push({message:n.buildLeftRecursionError({topLevelRule:e,leftRecursionPath:i}),type:o.ParserDefinitionErrorType.LEFT_RECURSION,ruleName:c});var l=r.difference(s,i.concat([e])),u=r.map(l,function(t){var o=r.cloneArr(i);return o.push(t),m(e,t,n,o)});return a.concat(r.flatten(u))}function g(e){var t=[];if(r.isEmpty(e))return t;var n=r.first(e);if(n instanceof l.NonTerminal)t.push(n.referencedRule);else if(n instanceof l.Alternative||n instanceof l.Option||n instanceof l.RepetitionMandatory||n instanceof l.RepetitionMandatoryWithSeparator||n instanceof l.RepetitionWithSeparator||n instanceof l.Repetition)t=t.concat(g(n.definition));else if(n instanceof l.Alternation)t=r.flatten(r.map(n.definition,function(e){return g(e.definition)}));else if(!(n instanceof l.Terminal))throw Error("non exhaustive match");var i=a.isOptionalProd(n),o=e.length>1;if(i&&o){var s=r.drop(e);return t.concat(g(s))}return t}e.OccurrenceValidationCollector=p,e.validateRuleDoesNotAlreadyExist=f,e.validateRuleIsOverridden=function(e,t,n){var i,a=[];return r.contains(t,e)||(i="Invalid rule override, rule: ->"+e+"<- cannot be overridden in the grammar: ->"+n+"<-as it is not defined in any of the super grammars ",a.push({message:i,type:o.ParserDefinitionErrorType.INVALID_RULE_OVERRIDE,ruleName:e})),a},e.validateNoLeftRecursion=m,e.getFirstNoneTerminal=g;var b=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.alternations=[],t}return n(t,e),t.prototype.visitAlternation=function(e){this.alternations.push(e)},t}(u.GAstVisitor);function y(e,t){var n=new b;e.accept(n);var i=n.alternations;return r.reduce(i,function(n,i){var a=r.dropRight(i.definition),s=r.map(a,function(n,a){var s=c.nextPossibleTokensAfter([n],[],null,1);return r.isEmpty(s)?{message:t.buildEmptyAlternationError({topLevelRule:e,alternation:i,emptyChoiceIdx:a}),type:o.ParserDefinitionErrorType.NONE_LAST_EMPTY_ALT,ruleName:e.name,occurrence:i.idx,alternative:a+1}:null});return n.concat(r.compact(s))},[])}function v(e,t,n){var a=new b;e.accept(a);var c=a.alternations;c=i.reject(c,function(e){return!0===e.ignoreAmbiguities});var l=r.reduce(c,function(a,c){var l=c.idx,u=c.maxLookahead||t,h=s.getLookaheadPathsForOr(l,e,u,c),d=function(e,t,n,a){var c=[],l=i.reduce(e,function(n,r,o){return!0===t.definition[o].ignoreAmbiguities||i.forEach(r,function(r){var a=[o];i.forEach(e,function(e,n){o!==n&&s.containsPath(e,r)&&!0!==t.definition[n].ignoreAmbiguities&&a.push(n)}),a.length>1&&!s.containsPath(c,r)&&(c.push(r),n.push({alts:a,path:r}))}),n},[]),u=r.map(l,function(e){var r=i.map(e.alts,function(e){return e+1});return{message:a.buildAlternationAmbiguityError({topLevelRule:n,alternation:t,ambiguityIndices:r,prefixPath:e.path}),type:o.ParserDefinitionErrorType.AMBIGUOUS_ALTS,ruleName:n.name,occurrence:t.idx,alternatives:[e.alts]}});return u}(h,c,e,n),p=T(h,c,e,n);return a.concat(d,p)},[]);return l}e.validateEmptyOrAlternative=y,e.validateAmbiguousAlternationAlternatives=v;var x=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.allProductions=[],t}return n(t,e),t.prototype.visitRepetitionWithSeparator=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionMandatory=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionMandatoryWithSeparator=function(e){this.allProductions.push(e)},t.prototype.visitRepetition=function(e){this.allProductions.push(e)},t}(u.GAstVisitor);function w(e,t){var n=new b;e.accept(n);var i=n.alternations;return r.reduce(i,function(n,r){return r.definition.length>255&&n.push({message:t.buildTooManyAlternativesError({topLevelRule:e,alternation:r}),type:o.ParserDefinitionErrorType.TOO_MANY_ALTS,ruleName:e.name,occurrence:r.idx}),n},[])}function E(e,t,n){var r=[];return i.forEach(e,function(e){var a=new x;e.accept(a);var c=a.allProductions;i.forEach(c,function(a){var c=s.getProdType(a),l=a.maxLookahead||t,u=a.idx,h=s.getLookaheadPathsForOptionalProd(u,e,c,l)[0];if(i.isEmpty(i.flatten(h))){var d=n.buildEmptyRepetitionError({topLevelRule:e,repetition:a});r.push({message:d,type:o.ParserDefinitionErrorType.NO_NON_EMPTY_LOOKAHEAD,ruleName:e.name})}})}),r}function T(e,t,n,r){var a=[],c=i.reduce(e,function(e,t,n){var r=i.map(t,function(e){return{idx:n,path:e}});return e.concat(r)},[]);return i.forEach(c,function(e){if(!0!==t.definition[e.idx].ignoreAmbiguities){var l=e.idx,u=e.path,h=i.findAll(c,function(e){return!0!==t.definition[e.idx].ignoreAmbiguities&&e.idx<l&&s.isStrictPrefixOfPath(e.path,u)}),d=i.map(h,function(e){var i=[e.idx+1,l+1],a=0===t.idx?"":t.idx;return{message:r.buildAlternationPrefixAmbiguityError({topLevelRule:n,alternation:t,ambiguityIndices:i,prefixPath:e.path}),type:o.ParserDefinitionErrorType.AMBIGUOUS_PREFIX_ALTS,ruleName:n.name,occurrence:a,alternatives:i}});a=a.concat(d)}}),a}e.RepetionCollector=x,e.validateTooManyAlts=w,e.validateSomeNonEmptyLookaheadPath=E,e.checkPrefixAlternativesAmbiguities=T}),wc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.validateGrammar=e.resolveGrammar=void 0;var t=ec(),n=bc(),r=xc(),i=gc();e.resolveGrammar=function(e){e=t.defaults(e,{errMsgProvider:i.defaultGrammarResolverErrorProvider});var r={};return t.forEach(e.rules,function(e){r[e.name]=e}),n.resolveGrammar(r,e.errMsgProvider)},e.validateGrammar=function(e){return e=t.defaults(e,{errMsgProvider:i.defaultGrammarValidatorErrorProvider}),r.validateGrammar(e.rules,e.maxLookahead,e.tokenTypes,e.errMsgProvider,e.grammarName)}}),Ec=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.EarlyExitException=e.NotAllInputParsedException=e.NoViableAltException=e.MismatchedTokenException=e.isRecognitionException=void 0;var r=ec(),i="MismatchedTokenException",o="NoViableAltException",a="EarlyExitException",s="NotAllInputParsedException",c=[i,o,a,s];Object.freeze(c),e.isRecognitionException=function(e){return r.contains(c,e.name)};var l=function(e){function t(t,n){var r=this.constructor,i=e.call(this,t)||this;return i.token=n,i.resyncedTokens=[],Object.setPrototypeOf(i,r.prototype),Error.captureStackTrace&&Error.captureStackTrace(i,i.constructor),i}return n(t,e),t}(Error),u=function(e){function t(t,n,r){var o=e.call(this,t,n)||this;return o.previousToken=r,o.name=i,o}return n(t,e),t}(l);e.MismatchedTokenException=u;var h=function(e){function t(t,n,r){var i=e.call(this,t,n)||this;return i.previousToken=r,i.name=o,i}return n(t,e),t}(l);e.NoViableAltException=h;var d=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.name=s,r}return n(t,e),t}(l);e.NotAllInputParsedException=d;var p=function(e){function t(t,n,r){var i=e.call(this,t,n)||this;return i.previousToken=r,i.name=a,i}return n(t,e),t}(l);e.EarlyExitException=p}),Tc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.attemptInRepetitionRecovery=e.Recoverable=e.InRuleRecoveryException=e.IN_RULE_RECOVERY_EXCEPTION=e.EOF_FOLLOW_KEY=void 0;var t=cc(),n=ec(),r=Ec(),i=fc(),o=Fc();function a(t){this.name=e.IN_RULE_RECOVERY_EXCEPTION,this.message=t}e.EOF_FOLLOW_KEY={},e.IN_RULE_RECOVERY_EXCEPTION="InRuleRecoveryException",e.InRuleRecoveryException=a,a.prototype=Error.prototype;var s=function(){function s(){}return s.prototype.initRecoverable=function(e){this.firstAfterRepMap={},this.resyncFollows={},this.recoveryEnabled=n.has(e,"recoveryEnabled")?e.recoveryEnabled:o.DEFAULT_PARSER_CONFIG.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=c)},s.prototype.getTokenToInsert=function(e){var n=t.createTokenInstance(e,"",NaN,NaN,NaN,NaN,NaN,NaN);return n.isInsertedInRecovery=!0,n},s.prototype.canTokenTypeBeInsertedInRecovery=function(e){return!0},s.prototype.tryInRepetitionRecovery=function(e,t,i,o){for(var a=this,s=this.findReSyncTokenType(),c=this.exportLexerState(),l=[],u=!1,h=this.LA(1),d=this.LA(1),p=function(){var e=a.LA(0),t=a.errorMessageProvider.buildMismatchTokenMessage({expected:o,actual:h,previous:e,ruleName:a.getCurrRuleFullName()}),i=new r.MismatchedTokenException(t,h,a.LA(0));i.resyncedTokens=n.dropRight(l),a.SAVE_ERROR(i)};!u;){if(this.tokenMatcher(d,o))return void p();if(i.call(this))return p(),void e.apply(this,t);this.tokenMatcher(d,s)?u=!0:(d=this.SKIP_TOKEN(),this.addToResyncTokens(d,l))}this.importLexerState(c)},s.prototype.shouldInRepetitionRecoveryBeTried=function(e,t,n){return!(!1===n||void 0===e||void 0===t||this.tokenMatcher(this.LA(1),e)||this.isBackTracking()||this.canPerformInRuleRecovery(e,this.getFollowsForInRuleRecovery(e,t)))},s.prototype.getFollowsForInRuleRecovery=function(e,t){var n=this.getCurrentGrammarPath(e,t);return this.getNextPossibleTokenTypes(n)},s.prototype.tryInRuleRecovery=function(e,t){if(this.canRecoverWithSingleTokenInsertion(e,t))return this.getTokenToInsert(e);if(this.canRecoverWithSingleTokenDeletion(e)){var n=this.SKIP_TOKEN();return this.consumeToken(),n}throw new a("sad sad panda")},s.prototype.canPerformInRuleRecovery=function(e,t){return this.canRecoverWithSingleTokenInsertion(e,t)||this.canRecoverWithSingleTokenDeletion(e)},s.prototype.canRecoverWithSingleTokenInsertion=function(e,t){var r=this;if(!this.canTokenTypeBeInsertedInRecovery(e)||n.isEmpty(t))return!1;var i=this.LA(1);return void 0!==n.find(t,function(e){return r.tokenMatcher(i,e)})},s.prototype.canRecoverWithSingleTokenDeletion=function(e){return this.tokenMatcher(this.LA(2),e)},s.prototype.isInCurrentRuleReSyncSet=function(e){var t=this.getCurrFollowKey(),r=this.getFollowSetFromFollowKey(t);return n.contains(r,e)},s.prototype.findReSyncTokenType=function(){for(var e=this.flattenFollowSet(),t=this.LA(1),r=2;;){var i=t.tokenType;if(n.contains(e,i))return i;t=this.LA(r),r++}},s.prototype.getCurrFollowKey=function(){if(1===this.RULE_STACK.length)return e.EOF_FOLLOW_KEY;var t=this.getLastExplicitRuleShortName(),n=this.getLastExplicitRuleOccurrenceIndex(),r=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(t),idxInCallingRule:n,inRule:this.shortRuleNameToFullName(r)}},s.prototype.buildFullFollowKeyStack=function(){var t=this,r=this.RULE_STACK,i=this.RULE_OCCURRENCE_STACK;return n.map(r,function(n,o){return 0===o?e.EOF_FOLLOW_KEY:{ruleName:t.shortRuleNameToFullName(n),idxInCallingRule:i[o],inRule:t.shortRuleNameToFullName(r[o-1])}})},s.prototype.flattenFollowSet=function(){var e=this,t=n.map(this.buildFullFollowKeyStack(),function(t){return e.getFollowSetFromFollowKey(t)});return n.flatten(t)},s.prototype.getFollowSetFromFollowKey=function(n){if(n===e.EOF_FOLLOW_KEY)return[t.EOF];var r=n.ruleName+n.idxInCallingRule+i.IN+n.inRule;return this.resyncFollows[r]},s.prototype.addToResyncTokens=function(e,n){return this.tokenMatcher(e,t.EOF)||n.push(e),n},s.prototype.reSyncTo=function(e){for(var t=[],r=this.LA(1);!1===this.tokenMatcher(r,e);)r=this.SKIP_TOKEN(),this.addToResyncTokens(r,t);return n.dropRight(t)},s.prototype.attemptInRepetitionRecovery=function(e,t,n,r,i,o,a){},s.prototype.getCurrentGrammarPath=function(e,t){return{ruleStack:this.getHumanReadableRuleStack(),occurrenceStack:n.cloneArr(this.RULE_OCCURRENCE_STACK),lastTok:e,lastTokOccurrence:t}},s.prototype.getHumanReadableRuleStack=function(){var e=this;return n.map(this.RULE_STACK,function(t){return e.shortRuleNameToFullName(t)})},s}();function c(e,n,r,i,o,a,s){var c=this.getKeyForAutomaticLookahead(i,o),l=this.firstAfterRepMap[c];if(void 0===l){var u=this.getCurrRuleFullName();l=new a(this.getGAstProductions()[u],o).startWalking(),this.firstAfterRepMap[c]=l}var h=l.token,d=l.occurrence,p=l.isEndOfRule;1===this.RULE_STACK.length&&p&&void 0===h&&(h=t.EOF,d=1),this.shouldInRepetitionRecoveryBeTried(h,d,s)&&this.tryInRepetitionRecovery(e,n,r,h)}e.Recoverable=s,e.attemptInRepetitionRecovery=c}),Ac=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getKeyForAutomaticLookahead=e.AT_LEAST_ONE_SEP_IDX=e.MANY_SEP_IDX=e.AT_LEAST_ONE_IDX=e.MANY_IDX=e.OPTION_IDX=e.OR_IDX=e.BITS_FOR_ALT_IDX=e.BITS_FOR_RULE_IDX=e.BITS_FOR_OCCURRENCE_IDX=e.BITS_FOR_METHOD_TYPE=void 0,e.BITS_FOR_METHOD_TYPE=4,e.BITS_FOR_OCCURRENCE_IDX=8,e.BITS_FOR_RULE_IDX=12,e.BITS_FOR_ALT_IDX=8,e.OR_IDX=1<<e.BITS_FOR_OCCURRENCE_IDX,e.OPTION_IDX=2<<e.BITS_FOR_OCCURRENCE_IDX,e.MANY_IDX=3<<e.BITS_FOR_OCCURRENCE_IDX,e.AT_LEAST_ONE_IDX=4<<e.BITS_FOR_OCCURRENCE_IDX,e.MANY_SEP_IDX=5<<e.BITS_FOR_OCCURRENCE_IDX,e.AT_LEAST_ONE_SEP_IDX=6<<e.BITS_FOR_OCCURRENCE_IDX,e.getKeyForAutomaticLookahead=function(e,t,n){return n|t|e},e.BITS_FOR_ALT_IDX}),Cc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.LooksAhead=void 0;var t=vc(),n=ec(),r=Fc(),i=Ac(),o=dc(),a=function(){function e(){}return e.prototype.initLooksAhead=function(e){this.dynamicTokensEnabled=n.has(e,"dynamicTokensEnabled")?e.dynamicTokensEnabled:r.DEFAULT_PARSER_CONFIG.dynamicTokensEnabled,this.maxLookahead=n.has(e,"maxLookahead")?e.maxLookahead:r.DEFAULT_PARSER_CONFIG.maxLookahead,this.lookAheadFuncsCache=n.isES2015MapSupported()?new Map:[],n.isES2015MapSupported()?(this.getLaFuncFromCache=this.getLaFuncFromMap,this.setLaFuncCache=this.setLaFuncCacheUsingMap):(this.getLaFuncFromCache=this.getLaFuncFromObj,this.setLaFuncCache=this.setLaFuncUsingObj)},e.prototype.preComputeLookaheadFunctions=function(e){var r=this;n.forEach(e,function(e){r.TRACE_INIT(e.name+" Rule Lookahead",function(){var a=o.collectMethods(e),s=a.alternation,c=a.repetition,l=a.option,u=a.repetitionMandatory,h=a.repetitionMandatoryWithSeparator,d=a.repetitionWithSeparator;n.forEach(s,function(n){var a=0===n.idx?"":n.idx;r.TRACE_INIT(""+o.getProductionDslName(n)+a,function(){var o=t.buildLookaheadFuncForOr(n.idx,e,n.maxLookahead||r.maxLookahead,n.hasPredicates,r.dynamicTokensEnabled,r.lookAheadBuilderForAlternatives),a=i.getKeyForAutomaticLookahead(r.fullRuleNameToShort[e.name],i.OR_IDX,n.idx);r.setLaFuncCache(a,o)})}),n.forEach(c,function(n){r.computeLookaheadFunc(e,n.idx,i.MANY_IDX,t.PROD_TYPE.REPETITION,n.maxLookahead,o.getProductionDslName(n))}),n.forEach(l,function(n){r.computeLookaheadFunc(e,n.idx,i.OPTION_IDX,t.PROD_TYPE.OPTION,n.maxLookahead,o.getProductionDslName(n))}),n.forEach(u,function(n){r.computeLookaheadFunc(e,n.idx,i.AT_LEAST_ONE_IDX,t.PROD_TYPE.REPETITION_MANDATORY,n.maxLookahead,o.getProductionDslName(n))}),n.forEach(h,function(n){r.computeLookaheadFunc(e,n.idx,i.AT_LEAST_ONE_SEP_IDX,t.PROD_TYPE.REPETITION_MANDATORY_WITH_SEPARATOR,n.maxLookahead,o.getProductionDslName(n))}),n.forEach(d,function(n){r.computeLookaheadFunc(e,n.idx,i.MANY_SEP_IDX,t.PROD_TYPE.REPETITION_WITH_SEPARATOR,n.maxLookahead,o.getProductionDslName(n))})})})},e.prototype.computeLookaheadFunc=function(e,n,r,o,a,s){var c=this;this.TRACE_INIT(""+s+(0===n?"":n),function(){var s=t.buildLookaheadFuncForOptionalProd(n,e,a||c.maxLookahead,c.dynamicTokensEnabled,o,c.lookAheadBuilderForOptional),l=i.getKeyForAutomaticLookahead(c.fullRuleNameToShort[e.name],r,n);c.setLaFuncCache(l,s)})},e.prototype.lookAheadBuilderForOptional=function(e,n,r){return t.buildSingleAlternativeLookaheadFunction(e,n,r)},e.prototype.lookAheadBuilderForAlternatives=function(e,n,r,i){return t.buildAlternativesLookAheadFunc(e,n,r,i)},e.prototype.getKeyForAutomaticLookahead=function(e,t){var n=this.getLastExplicitRuleShortName();return i.getKeyForAutomaticLookahead(n,e,t)},e.prototype.getLaFuncFromCache=function(e){},e.prototype.getLaFuncFromMap=function(e){return this.lookAheadFuncsCache.get(e)},e.prototype.getLaFuncFromObj=function(e){return this.lookAheadFuncsCache[e]},e.prototype.setLaFuncCache=function(e,t){},e.prototype.setLaFuncCacheUsingMap=function(e,t){this.lookAheadFuncsCache.set(e,t)},e.prototype.setLaFuncUsingObj=function(e,t){this.lookAheadFuncsCache[e]=t},e}();e.LooksAhead=a}),Oc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.addNoneTerminalToCst=e.addTerminalToCst=e.setNodeLocationFull=e.setNodeLocationOnlyOffset=void 0,e.setNodeLocationOnlyOffset=function(e,t){!0===isNaN(e.startOffset)?(e.startOffset=t.startOffset,e.endOffset=t.endOffset):e.endOffset<t.endOffset&&(e.endOffset=t.endOffset)},e.setNodeLocationFull=function(e,t){!0===isNaN(e.startOffset)?(e.startOffset=t.startOffset,e.startColumn=t.startColumn,e.startLine=t.startLine,e.endOffset=t.endOffset,e.endColumn=t.endColumn,e.endLine=t.endLine):e.endOffset<t.endOffset&&(e.endOffset=t.endOffset,e.endColumn=t.endColumn,e.endLine=t.endLine)},e.addTerminalToCst=function(e,t,n){void 0===e.children[n]?e.children[n]=[t]:e.children[n].push(t)},e.addNoneTerminalToCst=function(e,t,n){void 0===e.children[t]?e.children[t]=[n]:e.children[t].push(n)}}),kc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defineNameProp=e.functionName=e.classNameFromInstance=void 0;var t=ec();e.classNameFromInstance=function(e){return r(e.constructor)};var n="name";function r(e){return e.name||"anonymous"}e.functionName=r,e.defineNameProp=function(e,r){var i=Object.getOwnPropertyDescriptor(e,n);return!(!t.isUndefined(i)&&!i.configurable)&&(Object.defineProperty(e,n,{enumerable:!1,configurable:!0,writable:!1,value:r}),!0)}}),Sc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.validateRedundantMethods=e.validateMissingCstMethods=e.validateVisitor=e.CstVisitorDefinitionError=e.createBaseVisitorConstructorWithDefaults=e.createBaseSemanticVisitorConstructor=e.defaultVisit=void 0;var t,n,r=ec(),i=kc();function o(e,t){for(var n=r.keys(e),i=n.length,o=0;o<i;o++)for(var a=e[n[o]],s=a.length,c=0;c<s;c++){var l=a[c];void 0===l.tokenTypeIdx&&this[l.name](l.children,t)}}function a(e,t){var n=s(e,t),r=l(e,t);return n.concat(r)}function s(e,n){var o=r.map(n,function(n){if(!r.isFunction(e[n]))return{msg:"Missing visitor method: <"+n+"> on "+i.functionName(e.constructor)+" CST Visitor.",type:t.MISSING_METHOD,methodName:n}});return r.compact(o)}e.defaultVisit=o,e.createBaseSemanticVisitorConstructor=function(e,t){var n=function(){};i.defineNameProp(n,e+"BaseSemantics");var o={visit:function(e,t){if(r.isArray(e)&&(e=e[0]),!r.isUndefined(e))return this[e.name](e.children,t)},validateVisitor:function(){var e=a(this,t);if(!r.isEmpty(e)){var n=r.map(e,function(e){return e.msg});throw Error("Errors Detected in CST Visitor <"+i.functionName(this.constructor)+">:\n\t"+n.join("\n\n").replace(/\n/g,"\n\t"))}}};return(n.prototype=o).constructor=n,n._RULE_NAMES=t,n},e.createBaseVisitorConstructorWithDefaults=function(e,t,n){var a=function(){};i.defineNameProp(a,e+"BaseSemanticsWithDefaults");var s=Object.create(n.prototype);return r.forEach(t,function(e){s[e]=o}),(a.prototype=s).constructor=a,a},(n=t=e.CstVisitorDefinitionError||(e.CstVisitorDefinitionError={}))[n.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",n[n.MISSING_METHOD=1]="MISSING_METHOD",e.validateVisitor=a,e.validateMissingCstMethods=s;var c=["constructor","visit","validateVisitor"];function l(e,n){var o=[];for(var a in e)r.isFunction(e[a])&&!r.contains(c,a)&&!r.contains(n,a)&&o.push({msg:"Redundant visitor method: <"+a+"> on "+i.functionName(e.constructor)+" CST Visitor\nThere is no Grammar Rule corresponding to this method's name.\n",type:t.REDUNDANT_METHOD,methodName:a});return o}e.validateRedundantMethods=l}),Rc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeBuilder=void 0;var t=Oc(),n=ec(),r=Sc(),i=Fc(),o=function(){function e(){}return e.prototype.initTreeBuilder=function(e){if(this.CST_STACK=[],this.outputCst=e.outputCst,this.nodeLocationTracking=n.has(e,"nodeLocationTracking")?e.nodeLocationTracking:i.DEFAULT_PARSER_CONFIG.nodeLocationTracking,this.outputCst)if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=t.setNodeLocationFull,this.setNodeLocationFromNode=t.setNodeLocationFull,this.cstPostRule=n.NOOP,this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=n.NOOP,this.setNodeLocationFromNode=n.NOOP,this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=t.setNodeLocationOnlyOffset,this.setNodeLocationFromNode=t.setNodeLocationOnlyOffset,this.cstPostRule=n.NOOP,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=n.NOOP,this.setNodeLocationFromNode=n.NOOP,this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else{if(!/none/i.test(this.nodeLocationTracking))throw Error('Invalid <nodeLocationTracking> config option: "'+e.nodeLocationTracking+'"');this.setNodeLocationFromToken=n.NOOP,this.setNodeLocationFromNode=n.NOOP,this.cstPostRule=n.NOOP,this.setInitialNodeLocation=n.NOOP}else this.cstInvocationStateUpdate=n.NOOP,this.cstFinallyStateUpdate=n.NOOP,this.cstPostTerminal=n.NOOP,this.cstPostNonTerminal=n.NOOP,this.cstPostRule=n.NOOP},e.prototype.setInitialNodeLocationOnlyOffsetRecovery=function(e){e.location={startOffset:NaN,endOffset:NaN}},e.prototype.setInitialNodeLocationOnlyOffsetRegular=function(e){e.location={startOffset:this.LA(1).startOffset,endOffset:NaN}},e.prototype.setInitialNodeLocationFullRecovery=function(e){e.location={startOffset:NaN,startLine:NaN,startColumn:NaN,endOffset:NaN,endLine:NaN,endColumn:NaN}},e.prototype.setInitialNodeLocationFullRegular=function(e){var t=this.LA(1);e.location={startOffset:t.startOffset,startLine:t.startLine,startColumn:t.startColumn,endOffset:NaN,endLine:NaN,endColumn:NaN}},e.prototype.cstInvocationStateUpdate=function(e,t){var n={name:e,children:{}};this.setInitialNodeLocation(n),this.CST_STACK.push(n)},e.prototype.cstFinallyStateUpdate=function(){this.CST_STACK.pop()},e.prototype.cstPostRuleFull=function(e){var t=this.LA(0),n=e.location;n.startOffset<=t.startOffset?(n.endOffset=t.endOffset,n.endLine=t.endLine,n.endColumn=t.endColumn):(n.startOffset=NaN,n.startLine=NaN,n.startColumn=NaN)},e.prototype.cstPostRuleOnlyOffset=function(e){var t=this.LA(0),n=e.location;n.startOffset<=t.startOffset?n.endOffset=t.endOffset:n.startOffset=NaN},e.prototype.cstPostTerminal=function(e,n){var r=this.CST_STACK[this.CST_STACK.length-1];t.addTerminalToCst(r,n,e),this.setNodeLocationFromToken(r.location,n)},e.prototype.cstPostNonTerminal=function(e,n){var r=this.CST_STACK[this.CST_STACK.length-1];t.addNoneTerminalToCst(r,n,e),this.setNodeLocationFromNode(r.location,e.location)},e.prototype.getBaseCstVisitorConstructor=function(){if(n.isUndefined(this.baseCstVisitorConstructor)){var e=r.createBaseSemanticVisitorConstructor(this.className,n.keys(this.gastProductionsCache));return this.baseCstVisitorConstructor=e,e}return this.baseCstVisitorConstructor},e.prototype.getBaseCstVisitorConstructorWithDefaults=function(){if(n.isUndefined(this.baseCstVisitorWithDefaultsConstructor)){var e=r.createBaseVisitorConstructorWithDefaults(this.className,n.keys(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=e,e}return this.baseCstVisitorWithDefaultsConstructor},e.prototype.getLastExplicitRuleShortName=function(){var e=this.RULE_STACK;return e[e.length-1]},e.prototype.getPreviousExplicitRuleShortName=function(){var e=this.RULE_STACK;return e[e.length-2]},e.prototype.getLastExplicitRuleOccurrenceIndex=function(){var e=this.RULE_OCCURRENCE_STACK;return e[e.length-1]},e}();e.TreeBuilder=o}),Mc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.LexerAdapter=void 0;var t=Fc(),n=function(){function e(){}return e.prototype.initLexerAdapter=function(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1},Object.defineProperty(e.prototype,"input",{get:function(){return this.tokVector},set:function(e){if(!0!==this.selfAnalysisDone)throw Error("Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=e,this.tokVectorLength=e.length},enumerable:!1,configurable:!0}),e.prototype.SKIP_TOKEN=function(){return this.currIdx<=this.tokVector.length-2?(this.consumeToken(),this.LA(1)):t.END_OF_FILE},e.prototype.LA=function(e){var n=this.currIdx+e;return n<0||this.tokVectorLength<=n?t.END_OF_FILE:this.tokVector[n]},e.prototype.consumeToken=function(){this.currIdx++},e.prototype.exportLexerState=function(){return this.currIdx},e.prototype.importLexerState=function(e){this.currIdx=e},e.prototype.resetLexerState=function(){this.currIdx=-1},e.prototype.moveToTerminatedState=function(){this.currIdx=this.tokVector.length-1},e.prototype.getLexerPosition=function(){return this.exportLexerState()},e}();e.LexerAdapter=n}),Ic=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RecognizerApi=void 0;var t=ec(),n=Ec(),r=Fc(),i=gc(),o=xc(),a=lc(),s=function(){function e(){}return e.prototype.ACTION=function(e){return e.call(this)},e.prototype.consume=function(e,t,n){return this.consumeInternal(t,e,n)},e.prototype.subrule=function(e,t,n){return this.subruleInternal(t,e,n)},e.prototype.option=function(e,t){return this.optionInternal(t,e)},e.prototype.or=function(e,t){return this.orInternal(t,e)},e.prototype.many=function(e,t){return this.manyInternal(e,t)},e.prototype.atLeastOne=function(e,t){return this.atLeastOneInternal(e,t)},e.prototype.CONSUME=function(e,t){return this.consumeInternal(e,0,t)},e.prototype.CONSUME1=function(e,t){return this.consumeInternal(e,1,t)},e.prototype.CONSUME2=function(e,t){return this.consumeInternal(e,2,t)},e.prototype.CONSUME3=function(e,t){return this.consumeInternal(e,3,t)},e.prototype.CONSUME4=function(e,t){return this.consumeInternal(e,4,t)},e.prototype.CONSUME5=function(e,t){return this.consumeInternal(e,5,t)},e.prototype.CONSUME6=function(e,t){return this.consumeInternal(e,6,t)},e.prototype.CONSUME7=function(e,t){return this.consumeInternal(e,7,t)},e.prototype.CONSUME8=function(e,t){return this.consumeInternal(e,8,t)},e.prototype.CONSUME9=function(e,t){return this.consumeInternal(e,9,t)},e.prototype.SUBRULE=function(e,t){return this.subruleInternal(e,0,t)},e.prototype.SUBRULE1=function(e,t){return this.subruleInternal(e,1,t)},e.prototype.SUBRULE2=function(e,t){return this.subruleInternal(e,2,t)},e.prototype.SUBRULE3=function(e,t){return this.subruleInternal(e,3,t)},e.prototype.SUBRULE4=function(e,t){return this.subruleInternal(e,4,t)},e.prototype.SUBRULE5=function(e,t){return this.subruleInternal(e,5,t)},e.prototype.SUBRULE6=function(e,t){return this.subruleInternal(e,6,t)},e.prototype.SUBRULE7=function(e,t){return this.subruleInternal(e,7,t)},e.prototype.SUBRULE8=function(e,t){return this.subruleInternal(e,8,t)},e.prototype.SUBRULE9=function(e,t){return this.subruleInternal(e,9,t)},e.prototype.OPTION=function(e){return this.optionInternal(e,0)},e.prototype.OPTION1=function(e){return this.optionInternal(e,1)},e.prototype.OPTION2=function(e){return this.optionInternal(e,2)},e.prototype.OPTION3=function(e){return this.optionInternal(e,3)},e.prototype.OPTION4=function(e){return this.optionInternal(e,4)},e.prototype.OPTION5=function(e){return this.optionInternal(e,5)},e.prototype.OPTION6=function(e){return this.optionInternal(e,6)},e.prototype.OPTION7=function(e){return this.optionInternal(e,7)},e.prototype.OPTION8=function(e){return this.optionInternal(e,8)},e.prototype.OPTION9=function(e){return this.optionInternal(e,9)},e.prototype.OR=function(e){return this.orInternal(e,0)},e.prototype.OR1=function(e){return this.orInternal(e,1)},e.prototype.OR2=function(e){return this.orInternal(e,2)},e.prototype.OR3=function(e){return this.orInternal(e,3)},e.prototype.OR4=function(e){return this.orInternal(e,4)},e.prototype.OR5=function(e){return this.orInternal(e,5)},e.prototype.OR6=function(e){return this.orInternal(e,6)},e.prototype.OR7=function(e){return this.orInternal(e,7)},e.prototype.OR8=function(e){return this.orInternal(e,8)},e.prototype.OR9=function(e){return this.orInternal(e,9)},e.prototype.MANY=function(e){this.manyInternal(0,e)},e.prototype.MANY1=function(e){this.manyInternal(1,e)},e.prototype.MANY2=function(e){this.manyInternal(2,e)},e.prototype.MANY3=function(e){this.manyInternal(3,e)},e.prototype.MANY4=function(e){this.manyInternal(4,e)},e.prototype.MANY5=function(e){this.manyInternal(5,e)},e.prototype.MANY6=function(e){this.manyInternal(6,e)},e.prototype.MANY7=function(e){this.manyInternal(7,e)},e.prototype.MANY8=function(e){this.manyInternal(8,e)},e.prototype.MANY9=function(e){this.manyInternal(9,e)},e.prototype.MANY_SEP=function(e){this.manySepFirstInternal(0,e)},e.prototype.MANY_SEP1=function(e){this.manySepFirstInternal(1,e)},e.prototype.MANY_SEP2=function(e){this.manySepFirstInternal(2,e)},e.prototype.MANY_SEP3=function(e){this.manySepFirstInternal(3,e)},e.prototype.MANY_SEP4=function(e){this.manySepFirstInternal(4,e)},e.prototype.MANY_SEP5=function(e){this.manySepFirstInternal(5,e)},e.prototype.MANY_SEP6=function(e){this.manySepFirstInternal(6,e)},e.prototype.MANY_SEP7=function(e){this.manySepFirstInternal(7,e)},e.prototype.MANY_SEP8=function(e){this.manySepFirstInternal(8,e)},e.prototype.MANY_SEP9=function(e){this.manySepFirstInternal(9,e)},e.prototype.AT_LEAST_ONE=function(e){this.atLeastOneInternal(0,e)},e.prototype.AT_LEAST_ONE1=function(e){return this.atLeastOneInternal(1,e)},e.prototype.AT_LEAST_ONE2=function(e){this.atLeastOneInternal(2,e)},e.prototype.AT_LEAST_ONE3=function(e){this.atLeastOneInternal(3,e)},e.prototype.AT_LEAST_ONE4=function(e){this.atLeastOneInternal(4,e)},e.prototype.AT_LEAST_ONE5=function(e){this.atLeastOneInternal(5,e)},e.prototype.AT_LEAST_ONE6=function(e){this.atLeastOneInternal(6,e)},e.prototype.AT_LEAST_ONE7=function(e){this.atLeastOneInternal(7,e)},e.prototype.AT_LEAST_ONE8=function(e){this.atLeastOneInternal(8,e)},e.prototype.AT_LEAST_ONE9=function(e){this.atLeastOneInternal(9,e)},e.prototype.AT_LEAST_ONE_SEP=function(e){this.atLeastOneSepFirstInternal(0,e)},e.prototype.AT_LEAST_ONE_SEP1=function(e){this.atLeastOneSepFirstInternal(1,e)},e.prototype.AT_LEAST_ONE_SEP2=function(e){this.atLeastOneSepFirstInternal(2,e)},e.prototype.AT_LEAST_ONE_SEP3=function(e){this.atLeastOneSepFirstInternal(3,e)},e.prototype.AT_LEAST_ONE_SEP4=function(e){this.atLeastOneSepFirstInternal(4,e)},e.prototype.AT_LEAST_ONE_SEP5=function(e){this.atLeastOneSepFirstInternal(5,e)},e.prototype.AT_LEAST_ONE_SEP6=function(e){this.atLeastOneSepFirstInternal(6,e)},e.prototype.AT_LEAST_ONE_SEP7=function(e){this.atLeastOneSepFirstInternal(7,e)},e.prototype.AT_LEAST_ONE_SEP8=function(e){this.atLeastOneSepFirstInternal(8,e)},e.prototype.AT_LEAST_ONE_SEP9=function(e){this.atLeastOneSepFirstInternal(9,e)},e.prototype.RULE=function(e,n,o){if(void 0===o&&(o=r.DEFAULT_RULE_CONFIG),t.contains(this.definedRulesNames,e)){var a={message:i.defaultGrammarValidatorErrorProvider.buildDuplicateRuleNameError({topLevelRule:e,grammarName:this.className}),type:r.ParserDefinitionErrorType.DUPLICATE_RULE_NAME,ruleName:e};this.definitionErrors.push(a)}this.definedRulesNames.push(e);var s=this.defineRule(e,n,o);return this[e]=s,s},e.prototype.OVERRIDE_RULE=function(e,t,n){void 0===n&&(n=r.DEFAULT_RULE_CONFIG);var i=[];i=i.concat(o.validateRuleIsOverridden(e,this.definedRulesNames,this.className)),this.definitionErrors=this.definitionErrors.concat(i);var a=this.defineRule(e,t,n);return this[e]=a,a},e.prototype.BACKTRACK=function(e,t){return function(){this.isBackTrackingStack.push(1);var r=this.saveRecogState();try{return e.apply(this,t),!0}catch(e){if(n.isRecognitionException(e))return!1;throw e}finally{this.reloadRecogState(r),this.isBackTrackingStack.pop()}}},e.prototype.getGAstProductions=function(){return this.gastProductionsCache},e.prototype.getSerializedGastProductions=function(){return a.serializeGrammar(t.values(this.gastProductionsCache))},e}();e.RecognizerApi=s}),Pc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RecognizerEngine=void 0;var t=ec(),n=Ac(),r=Ec(),i=vc(),o=yc(),a=Fc(),s=Tc(),c=cc(),l=oc(),u=kc(),h=function(){function e(){}return e.prototype.initRecognizerEngine=function(e,n){if(this.className=u.classNameFromInstance(this),this.shortRuleNameToFull={},this.fullRuleNameToShort={},this.ruleShortNameIdx=256,this.tokenMatcher=l.tokenStructuredMatcherNoCategories,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[],this.gastProductionsCache={},t.has(n,"serializedGrammar"))throw Error("The Parser's configuration can no longer contain a <serializedGrammar> property.\n\tSee: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0\n\tFor Further details.");if(t.isArray(e)){if(t.isEmpty(e))throw Error("A Token Vocabulary cannot be empty.\n\tNote that the first argument for the parser constructor\n\tis no longer a Token vector (since v4.0).");if("number"==typeof e[0].startOffset)throw Error("The Parser constructor no longer accepts a token vector as the first argument.\n\tSee: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0\n\tFor Further details.")}if(t.isArray(e))this.tokensMap=t.reduce(e,function(e,t){return e[t.name]=t,e},{});else if(t.has(e,"modes")&&t.every(t.flatten(t.values(e.modes)),l.isTokenType)){var r=t.flatten(t.values(e.modes)),i=t.uniq(r);this.tokensMap=t.reduce(i,function(e,t){return e[t.name]=t,e},{})}else{if(!t.isObject(e))throw new Error("<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap=t.cloneObj(e)}this.tokensMap.EOF=c.EOF;var o=t.every(t.values(e),function(e){return t.isEmpty(e.categoryMatches)});this.tokenMatcher=o?l.tokenStructuredMatcherNoCategories:l.tokenStructuredMatcher,l.augmentTokenTypes(t.values(this.tokensMap))},e.prototype.defineRule=function(e,r,i){if(this.selfAnalysisDone)throw Error("Grammar rule <"+e+"> may not be defined after the 'performSelfAnalysis' method has been called'\nMake sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.");var o=t.has(i,"resyncEnabled")?i.resyncEnabled:a.DEFAULT_RULE_CONFIG.resyncEnabled,s=t.has(i,"recoveryValueFunc")?i.recoveryValueFunc:a.DEFAULT_RULE_CONFIG.recoveryValueFunc,c=this.ruleShortNameIdx<<n.BITS_FOR_METHOD_TYPE+n.BITS_FOR_OCCURRENCE_IDX;function l(e){try{if(!0===this.outputCst){r.apply(this,e);var t=this.CST_STACK[this.CST_STACK.length-1];return this.cstPostRule(t),t}return r.apply(this,e)}catch(e){return this.invokeRuleCatch(e,o,s)}finally{this.ruleFinallyStateUpdate()}}this.ruleShortNameIdx++,this.shortRuleNameToFull[c]=e,this.fullRuleNameToShort[e]=c;var u=function(t,n){return void 0===t&&(t=0),this.ruleInvocationStateUpdate(c,e,t),l.call(this,n)};return u.ruleName=e,u.originalGrammarAction=r,u},e.prototype.invokeRuleCatch=function(e,t,n){var i=1===this.RULE_STACK.length,o=t&&!this.isBackTracking()&&this.recoveryEnabled;if(r.isRecognitionException(e)){var a=e;if(o){var s,c=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(c))return a.resyncedTokens=this.reSyncTo(c),this.outputCst?((s=this.CST_STACK[this.CST_STACK.length-1]).recoveredNode=!0,s):n();throw this.outputCst&&((s=this.CST_STACK[this.CST_STACK.length-1]).recoveredNode=!0,a.partialCstResult=s),a}if(i)return this.moveToTerminatedState(),n();throw a}throw e},e.prototype.optionInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.OPTION_IDX,t);return this.optionInternalLogic(e,t,r)},e.prototype.optionInternalLogic=function(e,t,n){var r,i,o=this,a=this.getLaFuncFromCache(n);if(void 0!==e.DEF){if(r=e.DEF,void 0!==(i=e.GATE)){var s=a;a=function(){return i.call(o)&&s.call(o)}}}else r=e;if(!0===a.call(this))return r.call(this)},e.prototype.atLeastOneInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.AT_LEAST_ONE_IDX,e);return this.atLeastOneInternalLogic(e,t,r)},e.prototype.atLeastOneInternalLogic=function(e,t,r){var a,s,c=this,l=this.getLaFuncFromCache(r);if(void 0!==t.DEF){if(a=t.DEF,void 0!==(s=t.GATE)){var u=l;l=function(){return s.call(c)&&u.call(c)}}}else a=t;if(!0!==l.call(this))throw this.raiseEarlyExitException(e,i.PROD_TYPE.REPETITION_MANDATORY,t.ERR_MSG);for(var h=this.doSingleRepetition(a);!0===l.call(this)&&!0===h;)h=this.doSingleRepetition(a);this.attemptInRepetitionRecovery(this.atLeastOneInternal,[e,t],l,n.AT_LEAST_ONE_IDX,e,o.NextTerminalAfterAtLeastOneWalker)},e.prototype.atLeastOneSepFirstInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.AT_LEAST_ONE_SEP_IDX,e);this.atLeastOneSepFirstInternalLogic(e,t,r)},e.prototype.atLeastOneSepFirstInternalLogic=function(e,t,r){var a=this,s=t.DEF,c=t.SEP;if(!0!==this.getLaFuncFromCache(r).call(this))throw this.raiseEarlyExitException(e,i.PROD_TYPE.REPETITION_MANDATORY_WITH_SEPARATOR,t.ERR_MSG);s.call(this);for(var l=function(){return a.tokenMatcher(a.LA(1),c)};!0===this.tokenMatcher(this.LA(1),c);)this.CONSUME(c),s.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,c,l,s,o.NextTerminalAfterAtLeastOneSepWalker],l,n.AT_LEAST_ONE_SEP_IDX,e,o.NextTerminalAfterAtLeastOneSepWalker)},e.prototype.manyInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.MANY_IDX,e);return this.manyInternalLogic(e,t,r)},e.prototype.manyInternalLogic=function(e,t,r){var i,a,s=this,c=this.getLaFuncFromCache(r);if(void 0!==t.DEF){if(i=t.DEF,void 0!==(a=t.GATE)){var l=c;c=function(){return a.call(s)&&l.call(s)}}}else i=t;for(var u=!0;!0===c.call(this)&&!0===u;)u=this.doSingleRepetition(i);this.attemptInRepetitionRecovery(this.manyInternal,[e,t],c,n.MANY_IDX,e,o.NextTerminalAfterManyWalker,u)},e.prototype.manySepFirstInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.MANY_SEP_IDX,e);this.manySepFirstInternalLogic(e,t,r)},e.prototype.manySepFirstInternalLogic=function(e,t,r){var i=this,a=t.DEF,s=t.SEP;if(!0===this.getLaFuncFromCache(r).call(this)){a.call(this);for(var c=function(){return i.tokenMatcher(i.LA(1),s)};!0===this.tokenMatcher(this.LA(1),s);)this.CONSUME(s),a.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,s,c,a,o.NextTerminalAfterManySepWalker],c,n.MANY_SEP_IDX,e,o.NextTerminalAfterManySepWalker)}},e.prototype.repetitionSepSecondInternal=function(e,t,r,i,o){for(;r();)this.CONSUME(t),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,t,r,i,o],r,n.AT_LEAST_ONE_SEP_IDX,e,o)},e.prototype.doSingleRepetition=function(e){var t=this.getLexerPosition();return e.call(this),this.getLexerPosition()>t},e.prototype.orInternal=function(e,r){var i=this.getKeyForAutomaticLookahead(n.OR_IDX,r),o=t.isArray(e)?e:e.DEF,a=this.getLaFuncFromCache(i).call(this,o);if(void 0!==a)return o[a].ALT.call(this);this.raiseNoAltException(r,e.ERR_MSG)},e.prototype.ruleFinallyStateUpdate=function(){if(this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop(),this.cstFinallyStateUpdate(),0===this.RULE_STACK.length&&!1===this.isAtEndOfInput()){var e=this.LA(1),t=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:e,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new r.NotAllInputParsedException(t,e))}},e.prototype.subruleInternal=function(e,t,n){var r;try{var i=void 0!==n?n.ARGS:void 0;return r=e.call(this,t,i),this.cstPostNonTerminal(r,void 0!==n&&void 0!==n.LABEL?n.LABEL:e.ruleName),r}catch(t){this.subruleInternalError(t,n,e.ruleName)}},e.prototype.subruleInternalError=function(e,t,n){throw r.isRecognitionException(e)&&void 0!==e.partialCstResult&&(this.cstPostNonTerminal(e.partialCstResult,void 0!==t&&void 0!==t.LABEL?t.LABEL:n),delete e.partialCstResult),e},e.prototype.consumeInternal=function(e,t,n){var r;try{var i=this.LA(1);!0===this.tokenMatcher(i,e)?(this.consumeToken(),r=i):this.consumeInternalError(e,i,n)}catch(n){r=this.consumeInternalRecovery(e,t,n)}return this.cstPostTerminal(void 0!==n&&void 0!==n.LABEL?n.LABEL:e.name,r),r},e.prototype.consumeInternalError=function(e,t,n){var i,o=this.LA(0);throw i=void 0!==n&&n.ERR_MSG?n.ERR_MSG:this.errorMessageProvider.buildMismatchTokenMessage({expected:e,actual:t,previous:o,ruleName:this.getCurrRuleFullName()}),this.SAVE_ERROR(new r.MismatchedTokenException(i,t,o))},e.prototype.consumeInternalRecovery=function(e,t,n){if(!this.recoveryEnabled||"MismatchedTokenException"!==n.name||this.isBackTracking())throw n;var r=this.getFollowsForInRuleRecovery(e,t);try{return this.tryInRuleRecovery(e,r)}catch(e){throw e.name===s.IN_RULE_RECOVERY_EXCEPTION?n:e}},e.prototype.saveRecogState=function(){var e=this.errors,n=t.cloneArr(this.RULE_STACK);return{errors:e,lexerState:this.exportLexerState(),RULE_STACK:n,CST_STACK:this.CST_STACK}},e.prototype.reloadRecogState=function(e){this.errors=e.errors,this.importLexerState(e.lexerState),this.RULE_STACK=e.RULE_STACK},e.prototype.ruleInvocationStateUpdate=function(e,t,n){this.RULE_OCCURRENCE_STACK.push(n),this.RULE_STACK.push(e),this.cstInvocationStateUpdate(t,e)},e.prototype.isBackTracking=function(){return 0!==this.isBackTrackingStack.length},e.prototype.getCurrRuleFullName=function(){var e=this.getLastExplicitRuleShortName();return this.shortRuleNameToFull[e]},e.prototype.shortRuleNameToFullName=function(e){return this.shortRuleNameToFull[e]},e.prototype.isAtEndOfInput=function(){return this.tokenMatcher(this.LA(1),c.EOF)},e.prototype.reset=function(){this.resetLexerState(),this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK=[],this.CST_STACK=[],this.RULE_OCCURRENCE_STACK=[]},e}();e.RecognizerEngine=h}),_c=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ErrorHandler=void 0;var t=Ec(),n=ec(),r=vc(),i=Fc(),o=function(){function e(){}return e.prototype.initErrorHandler=function(e){this._errors=[],this.errorMessageProvider=n.has(e,"errorMessageProvider")?e.errorMessageProvider:i.DEFAULT_PARSER_CONFIG.errorMessageProvider},e.prototype.SAVE_ERROR=function(e){if(t.isRecognitionException(e))return e.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:n.cloneArr(this.RULE_OCCURRENCE_STACK)},this._errors.push(e),e;throw Error("Trying to save an Error which is not a RecognitionException")},Object.defineProperty(e.prototype,"errors",{get:function(){return n.cloneArr(this._errors)},set:function(e){this._errors=e},enumerable:!1,configurable:!0}),e.prototype.raiseEarlyExitException=function(e,n,i){for(var o=this.getCurrRuleFullName(),a=this.getGAstProductions()[o],s=r.getLookaheadPathsForOptionalProd(e,a,n,this.maxLookahead)[0],c=[],l=1;l<=this.maxLookahead;l++)c.push(this.LA(l));var u=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:s,actual:c,previous:this.LA(0),customUserDescription:i,ruleName:o});throw this.SAVE_ERROR(new t.EarlyExitException(u,this.LA(1),this.LA(0)))},e.prototype.raiseNoAltException=function(e,n){for(var i=this.getCurrRuleFullName(),o=this.getGAstProductions()[i],a=r.getLookaheadPathsForOr(e,o,this.maxLookahead),s=[],c=1;c<=this.maxLookahead;c++)s.push(this.LA(c));var l=this.LA(0),u=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:a,actual:s,previous:l,customUserDescription:n,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new t.NoViableAltException(u,this.LA(1),l))},e}();e.ErrorHandler=o}),Nc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ContentAssist=void 0;var t=yc(),n=ec(),r=function(){function e(){}return e.prototype.initContentAssist=function(){},e.prototype.computeContentAssist=function(e,r){var i=this.gastProductionsCache[e];if(n.isUndefined(i))throw Error("Rule ->"+e+"<- does not exist in this grammar.");return t.nextPossibleTokensAfter([i],r,this.tokenMatcher,this.maxLookahead)},e.prototype.getNextPossibleTokenTypes=function(e){var r=n.first(e.ruleStack),i=this.getGAstProductions()[r];return new t.NextAfterTokenWalker(i,e).startWalking()},e}();e.ContentAssist=r}),Lc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.GastRecorder=void 0;var t=ec(),n=lc(),r=sc(),i=oc(),o=cc(),a=Fc(),s=Ac(),c={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(c);var l=!0,u=Math.pow(2,s.BITS_FOR_OCCURRENCE_IDX)-1,h=o.createToken({name:"RECORDING_PHASE_TOKEN",pattern:r.Lexer.NA});i.augmentTokenTypes([h]);var d=o.createTokenInstance(h,"This IToken indicates the Parser is in Recording Phase\n\tSee: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details",-1,-1,-1,-1,-1,-1);Object.freeze(d);var p={name:"This CSTNode indicates the Parser is in Recording Phase\n\tSee: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details",children:{}},f=function(){function e(){}return e.prototype.initGastRecorder=function(e){this.recordingProdStack=[],this.RECORDING_PHASE=!1},e.prototype.enableRecording=function(){var e=this;this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",function(){for(var t=function(t){var n=t>0?t:"";e["CONSUME"+n]=function(e,n){return this.consumeInternalRecord(e,t,n)},e["SUBRULE"+n]=function(e,n){return this.subruleInternalRecord(e,t,n)},e["OPTION"+n]=function(e){return this.optionInternalRecord(e,t)},e["OR"+n]=function(e){return this.orInternalRecord(e,t)},e["MANY"+n]=function(e){this.manyInternalRecord(t,e)},e["MANY_SEP"+n]=function(e){this.manySepFirstInternalRecord(t,e)},e["AT_LEAST_ONE"+n]=function(e){this.atLeastOneInternalRecord(t,e)},e["AT_LEAST_ONE_SEP"+n]=function(e){this.atLeastOneSepFirstInternalRecord(t,e)}},n=0;n<10;n++)t(n);e.consume=function(e,t,n){return this.consumeInternalRecord(t,e,n)},e.subrule=function(e,t,n){return this.subruleInternalRecord(t,e,n)},e.option=function(e,t){return this.optionInternalRecord(t,e)},e.or=function(e,t){return this.orInternalRecord(t,e)},e.many=function(e,t){this.manyInternalRecord(e,t)},e.atLeastOne=function(e,t){this.atLeastOneInternalRecord(e,t)},e.ACTION=e.ACTION_RECORD,e.BACKTRACK=e.BACKTRACK_RECORD,e.LA=e.LA_RECORD})},e.prototype.disableRecording=function(){var e=this;this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",function(){for(var t=0;t<10;t++){var n=t>0?t:"";delete e["CONSUME"+n],delete e["SUBRULE"+n],delete e["OPTION"+n],delete e["OR"+n],delete e["MANY"+n],delete e["MANY_SEP"+n],delete e["AT_LEAST_ONE"+n],delete e["AT_LEAST_ONE_SEP"+n]}delete e.consume,delete e.subrule,delete e.option,delete e.or,delete e.many,delete e.atLeastOne,delete e.ACTION,delete e.BACKTRACK,delete e.LA})},e.prototype.ACTION_RECORD=function(e){},e.prototype.BACKTRACK_RECORD=function(e,t){return function(){return!0}},e.prototype.LA_RECORD=function(e){return a.END_OF_FILE},e.prototype.topLevelRuleRecord=function(e,t){try{var r=new n.Rule({definition:[],name:e});return r.name=e,this.recordingProdStack.push(r),t.call(this),this.recordingProdStack.pop(),r}catch(e){if(!0!==e.KNOWN_RECORDER_ERROR)try{e.message=e.message+'\n\t This error was thrown during the "grammar recording phase" For more info see:\n\thttps://chevrotain.io/docs/guide/internals.html#grammar-recording'}catch(t){throw e}throw e}},e.prototype.optionInternalRecord=function(e,t){return m.call(this,n.Option,e,t)},e.prototype.atLeastOneInternalRecord=function(e,t){m.call(this,n.RepetitionMandatory,t,e)},e.prototype.atLeastOneSepFirstInternalRecord=function(e,t){m.call(this,n.RepetitionMandatoryWithSeparator,t,e,l)},e.prototype.manyInternalRecord=function(e,t){m.call(this,n.Repetition,t,e)},e.prototype.manySepFirstInternalRecord=function(e,t){m.call(this,n.RepetitionWithSeparator,t,e,l)},e.prototype.orInternalRecord=function(e,t){return g.call(this,e,t)},e.prototype.subruleInternalRecord=function(e,r,i){if(y(r),!e||!1===t.has(e,"ruleName")){var o=new Error("<SUBRULE"+b(r)+"> argument is invalid expecting a Parser method reference but got: <"+JSON.stringify(e)+">\n inside top level rule: <"+this.recordingProdStack[0].name+">");throw o.KNOWN_RECORDER_ERROR=!0,o}var a=t.peek(this.recordingProdStack),s=e.ruleName,l=new n.NonTerminal({idx:r,nonTerminalName:s,referencedRule:void 0});return a.definition.push(l),this.outputCst?p:c},e.prototype.consumeInternalRecord=function(e,r,o){if(y(r),!i.hasShortKeyProperty(e)){var a=new Error("<CONSUME"+b(r)+"> argument is invalid expecting a TokenType reference but got: <"+JSON.stringify(e)+">\n inside top level rule: <"+this.recordingProdStack[0].name+">");throw a.KNOWN_RECORDER_ERROR=!0,a}var s=t.peek(this.recordingProdStack),c=new n.Terminal({idx:r,terminalType:e});return s.definition.push(c),d},e}();function m(e,n,r,i){void 0===i&&(i=!1),y(r);var o=t.peek(this.recordingProdStack),a=t.isFunction(n)?n:n.DEF,s=new e({definition:[],idx:r});return i&&(s.separator=n.SEP),t.has(n,"MAX_LOOKAHEAD")&&(s.maxLookahead=n.MAX_LOOKAHEAD),this.recordingProdStack.push(s),a.call(this),o.definition.push(s),this.recordingProdStack.pop(),c}function g(e,r){var i=this;y(r);var o=t.peek(this.recordingProdStack),a=!1===t.isArray(e),s=!1===a?e:e.DEF,l=new n.Alternation({definition:[],idx:r,ignoreAmbiguities:a&&!0===e.IGNORE_AMBIGUITIES});t.has(e,"MAX_LOOKAHEAD")&&(l.maxLookahead=e.MAX_LOOKAHEAD);var u=t.some(s,function(e){return t.isFunction(e.GATE)});return l.hasPredicates=u,o.definition.push(l),t.forEach(s,function(e){var r=new n.Alternative({definition:[]});l.definition.push(r),t.has(e,"IGNORE_AMBIGUITIES")?r.ignoreAmbiguities=e.IGNORE_AMBIGUITIES:t.has(e,"GATE")&&(r.ignoreAmbiguities=!0),i.recordingProdStack.push(r),e.ALT.call(i),i.recordingProdStack.pop()}),c}function b(e){return 0===e?"":""+e}function y(e){if(e<0||e>u){var t=new Error("Invalid DSL Method idx value: <"+e+">\n\tIdx value must be a none negative value smaller than "+(u+1));throw t.KNOWN_RECORDER_ERROR=!0,t}}e.GastRecorder=f}),Dc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.PerformanceTracer=void 0;var t=ec(),n=Fc(),r=function(){function e(){}return e.prototype.initPerformanceTracer=function(e){if(t.has(e,"traceInitPerf")){var r=e.traceInitPerf,i="number"==typeof r;this.traceInitMaxIdent=i?r:1/0,this.traceInitPerf=i?r>0:r}else this.traceInitMaxIdent=0,this.traceInitPerf=n.DEFAULT_PARSER_CONFIG.traceInitPerf;this.traceInitIndent=-1},e.prototype.TRACE_INIT=function(e,n){if(!0===this.traceInitPerf){this.traceInitIndent++;var r=new Array(this.traceInitIndent+1).join("\t");this.traceInitIndent<this.traceInitMaxIdent&&console.log(r+"--\x3e <"+e+">");var i=t.timer(n),o=i.time,a=i.value,s=o>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&s(r+"<-- <"+e+"> time: "+o+"ms"),this.traceInitIndent--,a}return n()},e}();e.PerformanceTracer=r}),jc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.applyMixins=void 0,e.applyMixins=function(e,t){t.forEach(function(t){var n=t.prototype;Object.getOwnPropertyNames(n).forEach(function(r){if("constructor"!==r){var i=Object.getOwnPropertyDescriptor(n,r);i&&(i.get||i.set)?Object.defineProperty(e.prototype,r,i):e.prototype[r]=t.prototype[r]}})})}}),Fc=$s(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.EmbeddedActionsParser=e.CstParser=e.Parser=e.EMPTY_ALT=e.ParserDefinitionErrorType=e.DEFAULT_RULE_CONFIG=e.DEFAULT_PARSER_CONFIG=e.END_OF_FILE=void 0;var r=ec(),i=mc(),o=cc(),a=gc(),s=wc(),c=Tc(),l=Cc(),u=Rc(),h=Mc(),d=Ic(),p=Pc(),f=_c(),m=Nc(),g=Lc(),b=Dc(),y=jc();e.END_OF_FILE=o.createTokenInstance(o.EOF,"",NaN,NaN,NaN,NaN,NaN,NaN),Object.freeze(e.END_OF_FILE),e.DEFAULT_PARSER_CONFIG=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:a.defaultParserErrorProvider,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),e.DEFAULT_RULE_CONFIG=Object.freeze({recoveryValueFunc:function(){},resyncEnabled:!0}),function(e){e[e.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",e[e.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",e[e.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",e[e.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",e[e.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",e[e.LEFT_RECURSION=5]="LEFT_RECURSION",e[e.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",e[e.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",e[e.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",e[e.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",e[e.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",e[e.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",e[e.TOO_MANY_ALTS=12]="TOO_MANY_ALTS"}(e.ParserDefinitionErrorType||(e.ParserDefinitionErrorType={})),e.EMPTY_ALT=function(e){return void 0===e&&(e=void 0),function(){return e}};var v=function(){function t(t,n){this.definitionErrors=[],this.selfAnalysisDone=!1;var i=this;if(i.initErrorHandler(n),i.initLexerAdapter(),i.initLooksAhead(n),i.initRecognizerEngine(t,n),i.initRecoverable(n),i.initTreeBuilder(n),i.initContentAssist(),i.initGastRecorder(n),i.initPerformanceTracer(n),r.has(n,"ignoredIssues"))throw new Error("The <ignoredIssues> IParserConfig property has been deprecated.\n\tPlease use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.\n\tSee: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES\n\tFor further details.");this.skipValidations=r.has(n,"skipValidations")?n.skipValidations:e.DEFAULT_PARSER_CONFIG.skipValidations}return t.performSelfAnalysis=function(e){throw Error("The **static** `performSelfAnalysis` method has been deprecated.\t\nUse the **instance** method with the same name instead.")},t.prototype.performSelfAnalysis=function(){var e=this;this.TRACE_INIT("performSelfAnalysis",function(){var n;e.selfAnalysisDone=!0;var o=e.className;e.TRACE_INIT("toFastProps",function(){r.toFastProperties(e)}),e.TRACE_INIT("Grammar Recording",function(){try{e.enableRecording(),r.forEach(e.definedRulesNames,function(t){var n=e[t].originalGrammarAction,r=void 0;e.TRACE_INIT(t+" Rule",function(){r=e.topLevelRuleRecord(t,n)}),e.gastProductionsCache[t]=r})}finally{e.disableRecording()}});var c=[];if(e.TRACE_INIT("Grammar Resolving",function(){c=s.resolveGrammar({rules:r.values(e.gastProductionsCache)}),e.definitionErrors=e.definitionErrors.concat(c)}),e.TRACE_INIT("Grammar Validations",function(){if(r.isEmpty(c)&&!1===e.skipValidations){var t=s.validateGrammar({rules:r.values(e.gastProductionsCache),maxLookahead:e.maxLookahead,tokenTypes:r.values(e.tokensMap),errMsgProvider:a.defaultGrammarValidatorErrorProvider,grammarName:o});e.definitionErrors=e.definitionErrors.concat(t)}}),r.isEmpty(e.definitionErrors)&&(e.recoveryEnabled&&e.TRACE_INIT("computeAllProdsFollows",function(){var t=i.computeAllProdsFollows(r.values(e.gastProductionsCache));e.resyncFollows=t}),e.TRACE_INIT("ComputeLookaheadFunctions",function(){e.preComputeLookaheadFunctions(r.values(e.gastProductionsCache))})),!t.DEFER_DEFINITION_ERRORS_HANDLING&&!r.isEmpty(e.definitionErrors))throw n=r.map(e.definitionErrors,function(e){return e.message}),new Error("Parser Definition Errors detected:\n "+n.join("\n-------------------------------\n"))})},t.DEFER_DEFINITION_ERRORS_HANDLING=!1,t}();e.Parser=v,y.applyMixins(v,[c.Recoverable,l.LooksAhead,u.TreeBuilder,h.LexerAdapter,p.RecognizerEngine,d.RecognizerApi,f.ErrorHandler,m.ContentAssist,g.GastRecorder,b.PerformanceTracer]);var x=function(t){function i(n,i){void 0===i&&(i=e.DEFAULT_PARSER_CONFIG);var o=r.cloneObj(i);return o.outputCst=!0,t.call(this,n,o)||this}return n(i,t),i}(v);e.CstParser=x;var w=function(t){function i(n,i){void 0===i&&(i=e.DEFAULT_PARSER_CONFIG);var o=r.cloneObj(i);return o.outputCst=!1,t.call(this,n,o)||this}return n(i,t),i}(v);e.EmbeddedActionsParser=w}),Uc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createSyntaxDiagramsCode=void 0;var t=Js();e.createSyntaxDiagramsCode=function(e,n){var r=void 0===n?{}:n,i=r.resourceBase,o=void 0===i?"https://unpkg.com/chevrotain@"+t.VERSION+"/diagrams/":i,a=r.css;return'\n\x3c!-- This is a generated file --\x3e\n<!DOCTYPE html>\n<meta charset="utf-8">\n<style>\n body {\n background-color: hsl(30, 20%, 95%)\n }\n</style>\n\n'+("\n<link rel='stylesheet' href='"+(void 0===a?"https://unpkg.com/chevrotain@"+t.VERSION+"/diagrams/diagrams.css":a)+"'>\n")+("\n<script src='"+o+"vendor/railroad-diagrams.js'><\/script>\n<script src='"+o+"src/diagrams_builder.js'><\/script>\n<script src='"+o+"src/diagrams_behavior.js'><\/script>\n<script src='"+o+"src/main.js'><\/script>\n")+'\n<div id="diagrams" align="center"></div>\n'+("\n<script>\n window.serializedGrammar = "+JSON.stringify(e,null," ")+";\n<\/script>\n")+'\n<script>\n var diagramsDiv = document.getElementById("diagrams");\n main.drawDiagramsFromSerializedGrammar(serializedGrammar, diagramsDiv);\n<\/script>\n'}}),Bc=$s(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Parser=e.createSyntaxDiagramsCode=e.clearCache=e.GAstVisitor=e.serializeProduction=e.serializeGrammar=e.Terminal=e.Rule=e.RepetitionWithSeparator=e.RepetitionMandatoryWithSeparator=e.RepetitionMandatory=e.Repetition=e.Option=e.NonTerminal=e.Alternative=e.Alternation=e.defaultLexerErrorProvider=e.NoViableAltException=e.NotAllInputParsedException=e.MismatchedTokenException=e.isRecognitionException=e.EarlyExitException=e.defaultParserErrorProvider=e.tokenName=e.tokenMatcher=e.tokenLabel=e.EOF=e.createTokenInstance=e.createToken=e.LexerDefinitionErrorType=e.Lexer=e.EMPTY_ALT=e.ParserDefinitionErrorType=e.EmbeddedActionsParser=e.CstParser=e.VERSION=void 0;var t=Js();Object.defineProperty(e,"VERSION",{enumerable:!0,get:function(){return t.VERSION}});var n=Fc();Object.defineProperty(e,"CstParser",{enumerable:!0,get:function(){return n.CstParser}}),Object.defineProperty(e,"EmbeddedActionsParser",{enumerable:!0,get:function(){return n.EmbeddedActionsParser}}),Object.defineProperty(e,"ParserDefinitionErrorType",{enumerable:!0,get:function(){return n.ParserDefinitionErrorType}}),Object.defineProperty(e,"EMPTY_ALT",{enumerable:!0,get:function(){return n.EMPTY_ALT}});var r=sc();Object.defineProperty(e,"Lexer",{enumerable:!0,get:function(){return r.Lexer}}),Object.defineProperty(e,"LexerDefinitionErrorType",{enumerable:!0,get:function(){return r.LexerDefinitionErrorType}});var i=cc();Object.defineProperty(e,"createToken",{enumerable:!0,get:function(){return i.createToken}}),Object.defineProperty(e,"createTokenInstance",{enumerable:!0,get:function(){return i.createTokenInstance}}),Object.defineProperty(e,"EOF",{enumerable:!0,get:function(){return i.EOF}}),Object.defineProperty(e,"tokenLabel",{enumerable:!0,get:function(){return i.tokenLabel}}),Object.defineProperty(e,"tokenMatcher",{enumerable:!0,get:function(){return i.tokenMatcher}}),Object.defineProperty(e,"tokenName",{enumerable:!0,get:function(){return i.tokenName}});var o=gc();Object.defineProperty(e,"defaultParserErrorProvider",{enumerable:!0,get:function(){return o.defaultParserErrorProvider}});var a=Ec();Object.defineProperty(e,"EarlyExitException",{enumerable:!0,get:function(){return a.EarlyExitException}}),Object.defineProperty(e,"isRecognitionException",{enumerable:!0,get:function(){return a.isRecognitionException}}),Object.defineProperty(e,"MismatchedTokenException",{enumerable:!0,get:function(){return a.MismatchedTokenException}}),Object.defineProperty(e,"NotAllInputParsedException",{enumerable:!0,get:function(){return a.NotAllInputParsedException}}),Object.defineProperty(e,"NoViableAltException",{enumerable:!0,get:function(){return a.NoViableAltException}});var s=ac();Object.defineProperty(e,"defaultLexerErrorProvider",{enumerable:!0,get:function(){return s.defaultLexerErrorProvider}});var c=lc();Object.defineProperty(e,"Alternation",{enumerable:!0,get:function(){return c.Alternation}}),Object.defineProperty(e,"Alternative",{enumerable:!0,get:function(){return c.Alternative}}),Object.defineProperty(e,"NonTerminal",{enumerable:!0,get:function(){return c.NonTerminal}}),Object.defineProperty(e,"Option",{enumerable:!0,get:function(){return c.Option}}),Object.defineProperty(e,"Repetition",{enumerable:!0,get:function(){return c.Repetition}}),Object.defineProperty(e,"RepetitionMandatory",{enumerable:!0,get:function(){return c.RepetitionMandatory}}),Object.defineProperty(e,"RepetitionMandatoryWithSeparator",{enumerable:!0,get:function(){return c.RepetitionMandatoryWithSeparator}}),Object.defineProperty(e,"RepetitionWithSeparator",{enumerable:!0,get:function(){return c.RepetitionWithSeparator}}),Object.defineProperty(e,"Rule",{enumerable:!0,get:function(){return c.Rule}}),Object.defineProperty(e,"Terminal",{enumerable:!0,get:function(){return c.Terminal}});var l=lc();Object.defineProperty(e,"serializeGrammar",{enumerable:!0,get:function(){return l.serializeGrammar}}),Object.defineProperty(e,"serializeProduction",{enumerable:!0,get:function(){return l.serializeProduction}});var u=hc();Object.defineProperty(e,"GAstVisitor",{enumerable:!0,get:function(){return u.GAstVisitor}}),e.clearCache=function(){console.warn("The clearCache function was 'soft' removed from the Chevrotain API.\n\t It performs no action other than printing this message.\n\t Please avoid using it as it will be completely removed in the future")};var h=Uc();Object.defineProperty(e,"createSyntaxDiagramsCode",{enumerable:!0,get:function(){return h.createSyntaxDiagramsCode}});var d=function(){throw new Error("The Parser class has been deprecated, use CstParser or EmbeddedActionsParser instead.\nSee: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_7-0-0")};e.Parser=d})();class zc extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=""===i.path?J.extractUrlBase(e):i.path,a=new q(i.manager);a.setPath(i.path),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e,t){const n={};function r(e){e.DEF&&(n[e.DEF]=e);const t=e.fields;for(let e=0,n=t.length;e<n;e++){const n=t[e];if("node"===n.type){const e=n.values;for(let t=0,n=e.length;t<n;t++)r(e[t])}}}function i(e){return e.USE?function(e){const t=n[e],r=i(t);return r.isObject3D||r.isMaterial?r.clone():r}(e.USE):(void 0!==e.build||(e.build=function(e){const t=e.name;let n;switch(t){case"Anchor":case"Group":case"Transform":case"Collision":n=function(e){const t=new Oe,n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;switch(i){case"bboxCenter":case"bboxSize":case"center":case"description":case"collide":case"parameter":case"scaleOrientation":case"proxy":case"url":break;case"children":s(o,t);break;case"rotation":const e=new f(o[0],o[1],o[2]),n=o[3];t.quaternion.setFromAxisAngle(e,n);break;case"scale":t.scale.set(o[0],o[1],o[2]);break;case"translation":t.position.set(o[0],o[1],o[2]);break;default:console.warn("THREE.VRMLLoader: Unknown field:",i)}}return t}(e);break;case"Background":n=function(e){const t=new Oe;let n,r,i,o;const a=e.fields;for(let e=0,t=a.length;e<t;e++){const t=a[e],s=t.name,c=t.values;switch(s){case"groundAngle":n=c;break;case"groundColor":r=c;break;case"backUrl":case"bottomUrl":case"frontUrl":case"leftUrl":case"rightUrl":case"topUrl":break;case"skyAngle":i=c;break;case"skyColor":o=c;break;default:console.warn("THREE.VRMLLoader: Unknown field:",s)}}const s=1e4;if(o){const e=new P(s,32,16),n=new E({fog:!1,side:H,depthWrite:!1,depthTest:!1});o.length>3?(W(e,s,i,z(o),!0),n.vertexColors=!0):(n.color.setRGB(o[0],o[1],o[2]),n.color.convertSRGBToLinear());const r=new S(e,n);t.add(r)}if(r&&r.length>0){const e=new P(s,32,16,0,2*Math.PI,.5*Math.PI,1.5*Math.PI),i=new E({fog:!1,side:H,vertexColors:!0,depthWrite:!1,depthTest:!1});W(e,s,n,z(r),!1);const o=new S(e,i);t.add(o)}return t.renderOrder=-1/0,t}(e);break;case"Shape":n=function(e){const t=e.fields;let n,r,o=new E({name:X.DEFAULT_MATERIAL_NAME,color:0});for(let e=0,r=t.length;e<r;e++){const r=t[e],a=r.name,s=r.values;switch(a){case"appearance":null!==s[0]&&(o=i(s[0]));break;case"geometry":null!==s[0]&&(n=i(s[0]));break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}if(n&&n.attributes.position){const e=n._type;if("points"===e){const e=new ye({name:X.DEFAULT_MATERIAL_NAME,color:16777215,opacity:o.opacity,transparent:o.transparent});void 0!==n.attributes.color?e.vertexColors=!0:o.isMeshPhongMaterial&&e.color.copy(o.emissive),r=new Ce(n,e)}else if("line"===e){const e=new T({name:X.DEFAULT_MATERIAL_NAME,color:16777215,opacity:o.opacity,transparent:o.transparent});void 0!==n.attributes.color?e.vertexColors=!0:o.isMeshPhongMaterial&&e.color.copy(o.emissive),r=new Te(n,e)}else void 0!==n._solid&&(o.side=n._solid?G:D),void 0!==n.attributes.color&&(o.vertexColors=!0),r=new S(n,o)}else r=new x,r.visible=!1;return r}(e);break;case"Appearance":n=function(e){let t,n=new Be;const r=e.fields;for(let e=0,o=r.length;e<o;e++){const o=r[e],a=o.name,s=o.values;switch(a){case"material":if(null!==s[0]){const e=i(s[0]);e.diffuseColor&&n.color.copy(e.diffuseColor),e.emissiveColor&&n.emissive.copy(e.emissiveColor),e.shininess&&(n.shininess=e.shininess),e.specularColor&&n.specular.copy(e.specularColor),e.transparency&&(n.opacity=1-e.transparency),e.transparency>0&&(n.transparent=!0)}else n=new E({name:X.DEFAULT_MATERIAL_NAME,color:0});break;case"texture":const e=s[0];null!==e&&("ImageTexture"!==e.name&&"PixelTexture"!==e.name||(n.map=i(e)));break;case"textureTransform":null!==s[0]&&(t=i(s[0]));break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}if(n.map){if(n.map.__type){switch(n.map.__type){case Xc.INTENSITY_ALPHA:n.opacity=1;break;case Xc.RGB:n.color.set(16777215);break;case Xc.RGBA:n.color.set(16777215),n.opacity=1}delete n.map.__type}t&&(n.map.center.copy(t.center),n.map.rotation=t.rotation,n.map.repeat.copy(t.scale),n.map.offset.copy(t.translation))}return n}(e);break;case"Material":n=function(e){const t={},n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;switch(i){case"ambientIntensity":break;case"diffuseColor":t.diffuseColor=new K(o[0],o[1],o[2]),t.diffuseColor.convertSRGBToLinear();break;case"emissiveColor":t.emissiveColor=new K(o[0],o[1],o[2]),t.emissiveColor.convertSRGBToLinear();break;case"shininess":t.shininess=o[0];break;case"specularColor":t.specularColor=new K(o[0],o[1],o[2]),t.specularColor.convertSRGBToLinear();break;case"transparency":t.transparency=o[0];break;default:console.warn("THREE.VRMLLoader: Unknown field:",i)}}return t}(e);break;case"ImageTexture":n=function(e){let t,n=me,r=me;const i=e.fields;for(let e=0,o=i.length;e<o;e++){const o=i[e],a=o.name,s=o.values;switch(a){case"url":const e=s[0];e&&(t=q.load(e));break;case"repeatS":!1===s[0]&&(n=be);break;case"repeatT":!1===s[0]&&(r=be);break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}t&&(t.wrapS=n,t.wrapT=r,t.colorSpace=Y);return t}(e);break;case"PixelTexture":n=function(e){let t,n=me,r=me;const i=e.fields;for(let e=0,s=i.length;e<s;e++){const s=i[e],c=s.name,l=s.values;switch(c){case"image":const e=l[0],i=l[1],s=a(l[2]),u=new Uint8Array(4*e*i),h={r:0,g:0,b:0,a:0};for(let e=3,t=0,n=l.length;e<n;e++,t++){o(l[e],s,h);const n=4*t;u[n+0]=h.r,u[n+1]=h.g,u[n+2]=h.b,u[n+3]=h.a}t=new nt(u,e,i),t.colorSpace=Y,t.needsUpdate=!0,t.__type=s;break;case"repeatS":!1===l[0]&&(n=be);break;case"repeatT":!1===l[0]&&(r=be);break;default:console.warn("THREE.VRMLLoader: Unknown field:",c)}}t&&(t.wrapS=n,t.wrapT=r);return t}(e);break;case"TextureTransform":n=function(e){const t={center:new v,rotation:new v,scale:new v,translation:new v},n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;switch(i){case"center":t.center.set(o[0],o[1]);break;case"rotation":t.rotation=o[0];break;case"scale":t.scale.set(o[0],o[1]);break;case"translation":t.translation.set(o[0],o[1]);break;default:console.warn("THREE.VRMLLoader: Unknown field:",i)}}return t}(e);break;case"IndexedFaceSet":n=function(e){let t,n,r,o,a,s,h,d,p=!0,f=!0,m=0,g=!0,b=!0;const y=e.fields;for(let e=0,c=y.length;e<c;e++){const c=y[e],l=c.name,u=c.values;switch(l){case"color":const e=u[0];null!==e&&(t=i(e));break;case"coord":const c=u[0];null!==c&&(n=i(c));break;case"normal":const y=u[0];null!==y&&(r=i(y));break;case"texCoord":const v=u[0];null!==v&&(o=i(v));break;case"ccw":p=u[0];break;case"colorIndex":a=u;break;case"colorPerVertex":g=u[0];break;case"convex":break;case"coordIndex":s=u;break;case"creaseAngle":m=u[0];break;case"normalIndex":h=u;break;case"normalPerVertex":b=u[0];break;case"solid":f=u[0];break;case"texCoordIndex":d=u;break;default:console.warn("THREE.VRMLLoader: Unknown field:",l)}}if(void 0===s)return console.warn("THREE.VRMLLoader: Missing coordIndex."),new O;const v=c(s,p);let x,w,E;if(t){if(!0===g)if(a&&a.length>0){x=M(v,c(a,p),t,3)}else x=N(v,new k(t,3));else if(a&&a.length>0){x=I(v,l(u(t,a),s))}else{x=I(v,l(t,s))}V(x)}if(r)if(!0===b)if(h&&h.length>0){w=M(v,c(h,p),r,3)}else w=N(v,new k(r,3));else if(h&&h.length>0){w=I(v,l(u(r,h),s))}else{w=I(v,l(r,s))}else w=U(v,n,m);if(o)if(d&&d.length>0){E=M(v,c(d,p),o,2)}else E=N(v,new k(o,2));const T=new O,A=N(v,new k(n,3));T.setAttribute("position",A),T.setAttribute("normal",w),x&&T.setAttribute("color",x);E&&T.setAttribute("uv",E);return T._solid=f,T._type="mesh",T}(e);break;case"IndexedLineSet":n=function(e){let t,n,r,o,a=!0;const s=e.fields;for(let e=0,c=s.length;e<c;e++){const c=s[e],l=c.name,u=c.values;switch(l){case"color":const e=u[0];null!==e&&(t=i(e));break;case"coord":const s=u[0];null!==s&&(n=i(s));break;case"colorIndex":r=u;break;case"colorPerVertex":a=u[0];break;case"coordIndex":o=u;break;default:console.warn("THREE.VRMLLoader: Unknown field:",l)}}let c;const l=h(o);if(t){if(!0===a)if(r.length>0){c=M(l,h(r),t,3)}else c=N(l,new k(t,3));else if(r.length>0){c=_(l,d(u(t,r),o))}else{c=_(l,d(t,o))}V(c)}const p=new O,f=N(l,new k(n,3));p.setAttribute("position",f),c&&p.setAttribute("color",c);return p._type="line",p}(e);break;case"PointSet":n=function(e){let t,n;const r=e.fields;for(let e=0,o=r.length;e<o;e++){const o=r[e],a=o.name,s=o.values;switch(a){case"color":const e=s[0];null!==e&&(t=i(e));break;case"coord":const r=s[0];null!==r&&(n=i(r));break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}const o=new O;if(o.setAttribute("position",new k(n,3)),t){const e=new k(t,3);V(e),o.setAttribute("color",e)}return o._type="points",o}(e);break;case"Box":n=function(e){const t=new f(2,2,2),n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;if("size"===i)t.x=o[0],t.y=o[1],t.z=o[2];else console.warn("THREE.VRMLLoader: Unknown field:",i)}return new C(t.x,t.y,t.z)}(e);break;case"Cone":n=function(e){let t=1,n=2,r=!1;const i=e.fields;for(let e=0,o=i.length;e<o;e++){const o=i[e],a=o.name,s=o.values;switch(a){case"bottom":r=!s[0];break;case"bottomRadius":t=s[0];break;case"height":n=s[0];break;case"side":break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}return new rt(t,n,16,1,r)}(e);break;case"Cylinder":n=function(e){let t=1,n=2;const r=e.fields;for(let e=0,i=r.length;e<i;e++){const i=r[e],o=i.name,a=i.values;switch(o){case"bottom":case"side":case"top":break;case"radius":t=a[0];break;case"height":n=a[0];break;default:console.warn("THREE.VRMLLoader: Unknown field:",o)}}return new A(t,t,n,16,1)}(e);break;case"Sphere":n=function(e){let t=1;const n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;if("radius"===i)t=o[0];else console.warn("THREE.VRMLLoader: Unknown field:",i)}return new P(t,16,16)}(e);break;case"ElevationGrid":n=function(e){let t,n,r,o,a=!0,s=!0,c=!0,l=!0,u=0,h=2,d=2,p=1,f=1;const m=e.fields;for(let e=0,g=m.length;e<g;e++){const g=m[e],b=g.name,y=g.values;switch(b){case"color":const e=y[0];null!==e&&(t=i(e));break;case"normal":const m=y[0];null!==m&&(n=i(m));break;case"texCoord":const g=y[0];null!==g&&(r=i(g));break;case"height":o=y;break;case"ccw":l=y[0];break;case"colorPerVertex":a=y[0];break;case"creaseAngle":u=y[0];break;case"normalPerVertex":s=y[0];break;case"solid":c=y[0];break;case"xDimension":h=y[0];break;case"xSpacing":p=y[0];break;case"zDimension":d=y[0];break;case"zSpacing":f=y[0];break;default:console.warn("THREE.VRMLLoader: Unknown field:",b)}}const g=[],b=[],y=[],v=[];for(let e=0;e<d;e++)for(let i=0;i<h;i++){const c=e*h+i,l=p*e,u=o[c],m=f*i;if(g.push(l,u,m),t&&!0===a){const e=t[3*c+0],n=t[3*c+1],r=t[3*c+2];y.push(e,n,r)}if(n&&!0===s){const e=n[3*c+0],t=n[3*c+1],r=n[3*c+2];b.push(e,t,r)}if(r){const e=r[2*c+0],t=r[2*c+1];v.push(e,t)}else v.push(e/(h-1),i/(d-1))}const x=[];for(let e=0;e<h-1;e++)for(let t=0;t<d-1;t++){const n=e+t*h,r=e+(t+1)*h,i=e+1+(t+1)*h,o=e+1+t*h;!0===l?(x.push(n,i,r),x.push(i,n,o)):(x.push(n,r,i),x.push(i,o,n))}const w=N(x,new k(g,3)),E=N(x,new k(v,2));let T,A;if(t){if(!1===a){for(let e=0;e<h-1;e++)for(let n=0;n<d-1;n++){const r=e+n*(h-1),i=t[3*r+0],o=t[3*r+1],a=t[3*r+2];y.push(i,o,a),y.push(i,o,a),y.push(i,o,a),y.push(i,o,a),y.push(i,o,a),y.push(i,o,a)}T=new k(y,3)}else T=N(x,new k(y,3));V(T)}if(n)if(!1===s){for(let e=0;e<h-1;e++)for(let t=0;t<d-1;t++){const r=e+t*(h-1),i=n[3*r+0],o=n[3*r+1],a=n[3*r+2];b.push(i,o,a),b.push(i,o,a),b.push(i,o,a),b.push(i,o,a),b.push(i,o,a),b.push(i,o,a)}A=new k(b,3)}else A=N(x,new k(b,3));else A=U(x,g,u);const C=new O;C.setAttribute("position",w),C.setAttribute("normal",A),C.setAttribute("uv",E),T&&C.setAttribute("color",T);return C._solid=c,C._type="mesh",C}(e);break;case"Extrusion":n=function(e){let t,n,r=[1,1,1,-1,-1,-1,-1,1,1,1],i=[0,0,0,0,1,0],o=!0,a=!0,s=0,c=!0,l=!0;const u=e.fields;for(let e=0,h=u.length;e<h;e++){const h=u[e],d=h.name,p=h.values;switch(d){case"beginCap":o=p[0];break;case"ccw":a=p[0];break;case"convex":break;case"creaseAngle":s=p[0];break;case"crossSection":r=p;break;case"endCap":c=p[0];break;case"orientation":n=p;break;case"scale":t=p;break;case"solid":l=p[0];break;case"spine":i=p;break;default:console.warn("THREE.VRMLLoader: Unknown field:",d)}}const h=r[0]===r[r.length-2]&&r[1]===r[r.length-1],d=[],p=new f,m=new f,g=new f,b=new f,x=new y;for(let e=0,o=0,a=0,s=i.length;e<s;e+=3,o+=2,a+=4){p.fromArray(i,e),m.x=t?t[o+0]:1,m.y=1,m.z=t?t[o+1]:1,g.x=n?n[a+0]:0,g.y=n?n[a+1]:0,g.z=n?n[a+2]:1;const s=n?n[a+3]:0;for(let e=0,t=r.length;e<t;e+=2)b.x=r[e+0],b.y=0,b.z=r[e+1],b.multiply(m),x.setFromAxisAngle(g,s),b.applyQuaternion(x),b.add(p),d.push(b.x,b.y,b.z)}const w=[],E=i.length/3,T=r.length/2;for(let e=0;e<E-1;e++)for(let t=0;t<T-1;t++){const n=t+e*T;let r=t+1+e*T;const i=t+(e+1)*T;let o=t+1+(e+1)*T;t===T-2&&!0===h&&(r=e*T,o=(e+1)*T),!0===a?(w.push(n,r,i),w.push(i,r,o)):(w.push(n,i,r),w.push(i,o,r))}if(!0===o||!0===c){const e=[];for(let t=0,n=r.length;t<n;t+=2)e.push(new v(r[t],r[t+1]));const t=Ke.triangulateShape(e,[]),n=[];for(let e=0,r=t.length;e<r;e++){const r=t[e];n.push(r[0],r[1],r[2])}if(!0===o)for(let e=0,t=n.length;e<t;e+=3)!0===a?w.push(n[e+0],n[e+1],n[e+2]):w.push(n[e+0],n[e+2],n[e+1]);if(!0===c){const e=T*(E-1);for(let t=0,r=n.length;t<r;t+=3)!0===a?w.push(e+n[t+0],e+n[t+2],e+n[t+1]):w.push(e+n[t+0],e+n[t+1],e+n[t+2])}}const A=N(w,new k(d,3)),C=U(w,d,s),S=new O;return S.setAttribute("position",A),S.setAttribute("normal",C),S._solid=l,S._type="mesh",S}(e);break;case"Color":case"Coordinate":case"Normal":case"TextureCoordinate":n=function(e){return e.fields[0].values}(e);break;case"WorldInfo":n=function(e){const t={},n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;switch(i){case"title":t.title=o[0];break;case"info":t.info=o;break;default:console.warn("THREE.VRMLLoader: Unknown field:",i)}}return t}(e);break;case"Billboard":case"Inline":case"LOD":case"Switch":case"AudioClip":case"DirectionalLight":case"PointLight":case"Script":case"Sound":case"SpotLight":case"CylinderSensor":case"PlaneSensor":case"ProximitySensor":case"SphereSensor":case"TimeSensor":case"TouchSensor":case"VisibilitySensor":case"Text":case"FontStyle":case"MovieTexture":case"ColorInterpolator":case"CoordinateInterpolator":case"NormalInterpolator":case"OrientationInterpolator":case"PositionInterpolator":case"ScalarInterpolator":case"Fog":case"NavigationInfo":case"Viewpoint":break;default:console.warn("THREE.VRMLLoader: Unknown node:",t)}void 0!==n&&void 0!==e.DEF&&!0===n.hasOwnProperty("name")&&(n.name=e.DEF);return n}(e)),e.build)}function o(e,t,n){let r;switch(t){case Xc.INTENSITY:r=parseInt(e),n.r=r,n.g=r,n.b=r,n.a=1;break;case Xc.INTENSITY_ALPHA:r=parseInt("0x"+e.substring(2,4)),n.r=r,n.g=r,n.b=r,n.a=parseInt("0x"+e.substring(4,6));break;case Xc.RGB:n.r=parseInt("0x"+e.substring(2,4)),n.g=parseInt("0x"+e.substring(4,6)),n.b=parseInt("0x"+e.substring(6,8)),n.a=1;break;case Xc.RGBA:n.r=parseInt("0x"+e.substring(2,4)),n.g=parseInt("0x"+e.substring(4,6)),n.b=parseInt("0x"+e.substring(6,8)),n.a=parseInt("0x"+e.substring(8,10))}}function a(e){let t;switch(e){case 1:t=Xc.INTENSITY;break;case 2:t=Xc.INTENSITY_ALPHA;break;case 3:t=Xc.RGB;break;case 4:t=Xc.RGBA}return t}function s(e,t){for(let n=0,r=e.length;n<r;n++){const r=i(e[n]);r instanceof x&&t.add(r)}}function c(e,t){const n=[];let r=0;for(let i=0,o=e.length;i<o;i++){const a=e[r],s=e[i+(t?1:2)],c=e[i+(t?2:1)];n.push(a,s,c),(-1===e[i+3]||i+3>=o)&&(i+=3,r=i+1)}return n}function l(e,t){const n=[];let r=0;for(let i=0,o=t.length;i<o;i++){const a=3*r,s=e[a],c=e[a+1],l=e[a+2];n.push(s,c,l),(-1===t[i+3]||i+3>=o)&&(i+=3,r++)}return n}function u(e,t){const n=[];for(let r=0,i=t.length;r<i;r++){const i=3*t[r],o=e[i],a=e[i+1],s=e[i+2];n.push(o,a,s)}return n}function h(e){const t=[];for(let n=0,r=e.length;n<r;n++){const i=e[n],o=e[n+1];t.push(i,o),(-1===e[n+2]||n+2>=r)&&(n+=2)}return t}function d(e,t){const n=[];let r=0;for(let i=0,o=t.length;i<o;i++){const a=3*r,s=e[a],c=e[a+1],l=e[a+2];n.push(s,c,l),(-1===t[i+2]||i+2>=o)&&(i+=2,r++)}return n}const p=new f,m=new f,g=new f,b=new v,w=new v,R=new v;function M(e,t,n,r){const i=[];for(let o=0,a=e.length;o<a;o+=3){const e=t[o],a=t[o+1],s=t[o+2];2===r?(b.fromArray(n,e*r),w.fromArray(n,a*r),R.fromArray(n,s*r),i.push(b.x,b.y),i.push(w.x,w.y),i.push(R.x,R.y)):(p.fromArray(n,e*r),m.fromArray(n,a*r),g.fromArray(n,s*r),i.push(p.x,p.y,p.z),i.push(m.x,m.y,m.z),i.push(g.x,g.y,g.z))}return new k(i,r)}function I(e,t){const n=[];for(let r=0,i=0,o=e.length;r<o;r+=3,i++)p.fromArray(t,3*i),n.push(p.x,p.y,p.z),n.push(p.x,p.y,p.z),n.push(p.x,p.y,p.z);return new k(n,3)}function _(e,t){const n=[];for(let r=0,i=0,o=e.length;r<o;r+=2,i++)p.fromArray(t,3*i),n.push(p.x,p.y,p.z),n.push(p.x,p.y,p.z);return new k(n,3)}function N(e,t){const n=t.array,r=t.itemSize,i=new n.constructor(e.length*r);let o=0,a=0;for(let t=0,s=e.length;t<s;t++){o=e[t]*r;for(let e=0;e<r;e++)i[a++]=n[o++]}return new k(i,r)}const L=new f,F=new f;function U(e,t,n){const r=[],i={};for(let n=0,o=e.length;n<o;n+=3){const o=e[n],a=e[n+1],s=e[n+2],c=new Wc(o,a,s);p.fromArray(t,3*o),m.fromArray(t,3*a),g.fromArray(t,3*s),F.subVectors(g,m),L.subVectors(p,m),F.cross(L),F.normalize(),c.normal.copy(F),void 0===i[o]&&(i[o]=[]),void 0===i[a]&&(i[a]=[]),void 0===i[s]&&(i[s]=[]),i[o].push(c.normal),i[a].push(c.normal),i[s].push(c.normal),r.push(c)}const o=[];for(let e=0,a=r.length;e<a;e++){const a=r[e],s=B(i[a.a],a.normal,n),c=B(i[a.b],a.normal,n),l=B(i[a.c],a.normal,n);p.fromArray(t,3*a.a),m.fromArray(t,3*a.b),g.fromArray(t,3*a.c),o.push(s.x,s.y,s.z),o.push(c.x,c.y,c.z),o.push(l.x,l.y,l.z)}return new k(o,3)}function B(e,t,n){const r=new f;if(0===n)r.copy(t);else for(let i=0,o=e.length;i<o;i++)e[i].angleTo(t)<n&&r.add(e[i]);return r.normalize()}function z(e){const t=[];for(let n=0,r=e.length;n<r;n+=3)t.push(new K(e[n],e[n+1],e[n+2]));return t}function V(e){const t=new K;for(let n=0;n<e.count;n++)t.fromBufferAttribute(e,n),t.convertSRGBToLinear(),e.setXYZ(n,t.r,t.g,t.b)}function W(e,t,n,r,i){const o=[],a=!0===i?0:Math.PI;for(let e=0,s=r.length;e<s;e++){let r=0===e?0:n[e-1];r=!0===i?r:a-r;const s=new f;s.setFromSphericalCoords(t,r,0),o.push(s)}const s=e.index,c=e.attributes.position,l=new j(new Float32Array(3*e.attributes.position.count),3),u=new f,h=new K;for(let e=0;e<s.count;e++){const t=s.getX(e);let n,a;u.fromBufferAttribute(c,t);let d=1;for(let e=1;e<o.length;e++){n=e-1,a=e;const t=o[n],r=o[a];if(!0===i){if(u.y<=t.y&&u.y>r.y){d=Math.abs(t.y-u.y)/Math.abs(t.y-r.y);break}}else if(u.y>=t.y&&u.y<r.y){d=Math.abs(t.y-u.y)/Math.abs(t.y-r.y);break}}const p=r[n],f=r[a];h.copy(p).lerp(f,d).convertSRGBToLinear(),l.setXYZ(t,h.r,h.g,h.b)}e.setAttribute("color",l)}const q=new ae(this.manager);if(q.setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin),-1===e.indexOf("#VRML V2.0"))throw Error("THREE.VRMLLexer: Version of VRML asset not supported.");const Q=function(e){const t=function(){const e=Bc.createToken,t=e({name:"RouteIdentifier",pattern:/[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*[\.][^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/}),n=e({name:"Identifier",pattern:/[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]([^\0-\x20\x22\x27\x23\x2b\x2c\x2e\x5b\x5d\x5c\x7b\x7d])*/,longer_alt:t}),r=["Anchor","Billboard","Collision","Group","Transform","Inline","LOD","Switch","AudioClip","DirectionalLight","PointLight","Script","Shape","Sound","SpotLight","WorldInfo","CylinderSensor","PlaneSensor","ProximitySensor","SphereSensor","TimeSensor","TouchSensor","VisibilitySensor","Box","Cone","Cylinder","ElevationGrid","Extrusion","IndexedFaceSet","IndexedLineSet","PointSet","Sphere","Color","Coordinate","Normal","TextureCoordinate","Appearance","FontStyle","ImageTexture","Material","MovieTexture","PixelTexture","TextureTransform","ColorInterpolator","CoordinateInterpolator","NormalInterpolator","OrientationInterpolator","PositionInterpolator","ScalarInterpolator","Background","Fog","NavigationInfo","Viewpoint","Text"],i=e({name:"Version",pattern:/#VRML.*/,longer_alt:n}),o=e({name:"NodeName",pattern:new RegExp(r.join("|")),longer_alt:n}),a=e({name:"DEF",pattern:/DEF/,longer_alt:n}),s=e({name:"USE",pattern:/USE/,longer_alt:n}),c=e({name:"ROUTE",pattern:/ROUTE/,longer_alt:n}),l=e({name:"TO",pattern:/TO/,longer_alt:n}),u=e({name:"StringLiteral",pattern:/"(?:[^\\"\n\r]|\\[bfnrtv"\\/]|\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])*"/}),h=e({name:"HexLiteral",pattern:/0[xX][0-9a-fA-F]+/}),d=e({name:"NumberLiteral",pattern:/[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/}),p=e({name:"TrueLiteral",pattern:/TRUE/}),f=e({name:"FalseLiteral",pattern:/FALSE/}),m=e({name:"NullLiteral",pattern:/NULL/}),g=e({name:"LSquare",pattern:/\[/}),b=e({name:"RSquare",pattern:/]/}),y=e({name:"LCurly",pattern:/{/}),v=e({name:"RCurly",pattern:/}/}),x=e({name:"Comment",pattern:/#.*/,group:Bc.Lexer.SKIPPED}),w=[e({name:"WhiteSpace",pattern:/[ ,\s]/,group:Bc.Lexer.SKIPPED}),o,a,s,c,l,p,f,m,i,n,t,u,h,d,g,b,y,v,x],E={};for(let e=0,t=w.length;e<t;e++){const t=w[e];E[t.name]=t}return{tokens:w,tokenVocabulary:E}}(),n=new Hc(t.tokens),r=new Gc(t.tokenVocabulary),i=function(e){class t extends e{constructor(){super(),this.validateVisitor()}vrml(e){const t={version:this.visit(e.version),nodes:[],routes:[]};for(let n=0,r=e.node.length;n<r;n++){const r=e.node[n];t.nodes.push(this.visit(r))}if(e.route)for(let n=0,r=e.route.length;n<r;n++){const r=e.route[n];t.routes.push(this.visit(r))}return t}version(e){return e.Version[0].image}node(e){const t={name:e.NodeName[0].image,fields:[]};if(e.field)for(let n=0,r=e.field.length;n<r;n++){const r=e.field[n];t.fields.push(this.visit(r))}return e.def&&(t.DEF=this.visit(e.def[0])),t}field(e){const t={name:e.Identifier[0].image,type:null,values:null};let n;return e.singleFieldValue&&(n=this.visit(e.singleFieldValue[0])),e.multiFieldValue&&(n=this.visit(e.multiFieldValue[0])),t.type=n.type,t.values=n.values,t}def(e){return(e.Identifier||e.NodeName)[0].image}use(e){return{USE:(e.Identifier||e.NodeName)[0].image}}singleFieldValue(e){return n(this,e)}multiFieldValue(e){return n(this,e)}route(e){return{FROM:e.RouteIdentifier[0].image,TO:e.RouteIdentifier[1].image}}}function n(e,t){const n={type:null,values:[]};if(t.node){n.type="node";for(let r=0,i=t.node.length;r<i;r++){const i=t.node[r];n.values.push(e.visit(i))}}if(t.use){n.type="use";for(let r=0,i=t.use.length;r<i;r++){const i=t.use[r];n.values.push(e.visit(i))}}if(t.StringLiteral){n.type="string";for(let e=0,r=t.StringLiteral.length;e<r;e++){const r=t.StringLiteral[e];n.values.push(r.image.replace(/'|"/g,""))}}if(t.NumberLiteral){n.type="number";for(let e=0,r=t.NumberLiteral.length;e<r;e++){const r=t.NumberLiteral[e];n.values.push(parseFloat(r.image))}}if(t.HexLiteral){n.type="hex";for(let e=0,r=t.HexLiteral.length;e<r;e++){const r=t.HexLiteral[e];n.values.push(r.image)}}if(t.TrueLiteral){n.type="boolean";for(let e=0,r=t.TrueLiteral.length;e<r;e++){"TRUE"===t.TrueLiteral[e].image&&n.values.push(!0)}}if(t.FalseLiteral){n.type="boolean";for(let e=0,r=t.FalseLiteral.length;e<r;e++){"FALSE"===t.FalseLiteral[e].image&&n.values.push(!1)}}return t.NullLiteral&&(n.type="null",t.NullLiteral.forEach(function(){n.values.push(null)})),n}return new t}(r.getBaseCstVisitorConstructor()),o=n.lex(e);r.input=o.tokens;const a=r.vrml();if(r.errors.length>0)throw console.error(r.errors),Error("THREE.VRMLLoader: Parsing errors detected.");return i.visit(a)}(e),Z=function(e){const t=e.nodes,n=new Qe;for(let e=0,n=t.length;e<n;e++){r(t[e])}for(let e=0,r=t.length;e<r;e++){const r=t[e],o=i(r);o instanceof x&&n.add(o),"WorldInfo"===r.name&&(n.userData.worldInfo=o)}return n}(Q);return Z}}class Hc{constructor(e){this.lexer=new Bc.Lexer(e)}lex(e){const t=this.lexer.tokenize(e);if(t.errors.length>0)throw console.error(t.errors),Error("THREE.VRMLLexer: Lexing errors detected.");return t}}const Vc=Bc.CstParser;class Gc extends Vc{constructor(e){super(e);const t=this,n=e.Version,r=e.LCurly,i=e.RCurly,o=e.LSquare,a=e.RSquare,s=e.Identifier,c=e.RouteIdentifier,l=e.StringLiteral,u=e.HexLiteral,h=e.NumberLiteral,d=e.TrueLiteral,p=e.FalseLiteral,f=e.NullLiteral,m=e.DEF,g=e.USE,b=e.ROUTE,y=e.TO,v=e.NodeName;t.RULE("vrml",function(){t.SUBRULE(t.version),t.AT_LEAST_ONE(function(){t.SUBRULE(t.node)}),t.MANY(function(){t.SUBRULE(t.route)})}),t.RULE("version",function(){t.CONSUME(n)}),t.RULE("node",function(){t.OPTION(function(){t.SUBRULE(t.def)}),t.CONSUME(v),t.CONSUME(r),t.MANY(function(){t.SUBRULE(t.field)}),t.CONSUME(i)}),t.RULE("field",function(){t.CONSUME(s),t.OR2([{ALT:function(){t.SUBRULE(t.singleFieldValue)}},{ALT:function(){t.SUBRULE(t.multiFieldValue)}}])}),t.RULE("def",function(){t.CONSUME(m),t.OR([{ALT:function(){t.CONSUME(s)}},{ALT:function(){t.CONSUME(v)}}])}),t.RULE("use",function(){t.CONSUME(g),t.OR([{ALT:function(){t.CONSUME(s)}},{ALT:function(){t.CONSUME(v)}}])}),t.RULE("singleFieldValue",function(){t.AT_LEAST_ONE(function(){t.OR([{ALT:function(){t.SUBRULE(t.node)}},{ALT:function(){t.SUBRULE(t.use)}},{ALT:function(){t.CONSUME(l)}},{ALT:function(){t.CONSUME(u)}},{ALT:function(){t.CONSUME(h)}},{ALT:function(){t.CONSUME(d)}},{ALT:function(){t.CONSUME(p)}},{ALT:function(){t.CONSUME(f)}}])})}),t.RULE("multiFieldValue",function(){t.CONSUME(o),t.MANY(function(){t.OR([{ALT:function(){t.SUBRULE(t.node)}},{ALT:function(){t.SUBRULE(t.use)}},{ALT:function(){t.CONSUME(l)}},{ALT:function(){t.CONSUME(u)}},{ALT:function(){t.CONSUME(h)}},{ALT:function(){t.CONSUME(f)}}])}),t.CONSUME(a)}),t.RULE("route",function(){t.CONSUME(b),t.CONSUME(c),t.CONSUME(y),t.CONSUME2(c)}),this.performSelfAnalysis()}}class Wc{constructor(e,t,n){this.a=e,this.b=t,this.c=n,this.normal=new f}}const Xc={INTENSITY:1,INTENSITY_ALPHA:2,RGB:3,RGBA:4};class qc extends X{constructor(e){super(e),this.littleEndian=!0}load(e,t,n,r){const i=this,o=new q(i.manager);o.setPath(i.path),o.setResponseType("arraybuffer"),o.setRequestHeader(i.requestHeader),o.setWithCredentials(i.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){const t=(new TextDecoder).decode(e),n=function(e){const t={},n=e.search(/[\r\n]DATA\s(\S*)\s/i),r=/[\r\n]DATA\s(\S*)\s/i.exec(e.slice(n-1));if(t.data=r[1],t.headerLen=r[0].length+n,t.str=e.slice(0,t.headerLen),t.str=t.str.replace(/#.*/gi,""),t.version=/VERSION (.*)/i.exec(t.str),t.fields=/FIELDS (.*)/i.exec(t.str),t.size=/SIZE (.*)/i.exec(t.str),t.type=/TYPE (.*)/i.exec(t.str),t.count=/COUNT (.*)/i.exec(t.str),t.width=/WIDTH (.*)/i.exec(t.str),t.height=/HEIGHT (.*)/i.exec(t.str),t.viewpoint=/VIEWPOINT (.*)/i.exec(t.str),t.points=/POINTS (.*)/i.exec(t.str),null!==t.version&&(t.version=parseFloat(t.version[1])),t.fields=null!==t.fields?t.fields[1].split(" "):[],null!==t.type&&(t.type=t.type[1].split(" ")),null!==t.width&&(t.width=parseInt(t.width[1])),null!==t.height&&(t.height=parseInt(t.height[1])),null!==t.viewpoint&&(t.viewpoint=t.viewpoint[1]),null!==t.points&&(t.points=parseInt(t.points[1],10)),null===t.points&&(t.points=t.width*t.height),null!==t.size&&(t.size=t.size[1].split(" ").map(function(e){return parseInt(e,10)})),null!==t.count)t.count=t.count[1].split(" ").map(function(e){return parseInt(e,10)});else{t.count=[];for(let e=0,n=t.fields.length;e<n;e++)t.count.push(1)}t.offset={};let i=0;for(let e=0,n=t.fields.length;e<n;e++)"ascii"===t.data?t.offset[t.fields[e]]=e:(t.offset[t.fields[e]]=i,i+=t.size[e]*t.count[e]);return t.rowSize=i,t}(t),r=[],i=[],o=[],a=[],s=[],c=new K;if("ascii"===n.data){const e=n.offset,l=t.slice(n.headerLen).split("\n");for(let t=0,u=l.length;t<u;t++){if(""===l[t])continue;const u=l[t].split(" ");if(void 0!==e.x&&(r.push(parseFloat(u[e.x])),r.push(parseFloat(u[e.y])),r.push(parseFloat(u[e.z]))),void 0!==e.rgb){const t=n.fields.findIndex(e=>"rgb"===e),r=n.type[t],i=parseFloat(u[e.rgb]);let a=i;if("F"===r){const e=new Float32Array(1);e[0]=i,a=new Int32Array(e.buffer)[0]}const s=(a>>16&255)/255,l=(a>>8&255)/255,h=(255&a)/255;c.set(s,l,h).convertSRGBToLinear(),o.push(c.r,c.g,c.b)}void 0!==e.normal_x&&(i.push(parseFloat(u[e.normal_x])),i.push(parseFloat(u[e.normal_y])),i.push(parseFloat(u[e.normal_z]))),void 0!==e.intensity&&a.push(parseFloat(u[e.intensity])),void 0!==e.label&&s.push(parseInt(u[e.label]))}}if("binary_compressed"===n.data){const t=new Uint32Array(e.slice(n.headerLen,n.headerLen+8)),l=t[0],u=t[1],h=function(e,t){const n=e.length,r=new Uint8Array(t);let i,o,a,s=0,c=0;do{if(i=e[s++],i<32){if(i++,c+i>t)throw new Error("Output buffer is not large enough");if(s+i>n)throw new Error("Invalid compressed data");do{r[c++]=e[s++]}while(--i)}else{if(o=i>>5,a=c-((31&i)<<8)-1,s>=n)throw new Error("Invalid compressed data");if(7===o&&(o+=e[s++],s>=n))throw new Error("Invalid compressed data");if(a-=e[s++],c+o+2>t)throw new Error("Output buffer is not large enough");if(a<0)throw new Error("Invalid compressed data");if(a>=c)throw new Error("Invalid compressed data");do{r[c++]=r[a++]}while(2+--o)}}while(s<n);return r}(new Uint8Array(e,n.headerLen+8,l),u),d=new DataView(h.buffer),p=n.offset;for(let e=0;e<n.points;e++){if(void 0!==p.x){const t=n.fields.indexOf("x"),i=n.fields.indexOf("y"),o=n.fields.indexOf("z");r.push(d.getFloat32(n.points*p.x+n.size[t]*e,this.littleEndian)),r.push(d.getFloat32(n.points*p.y+n.size[i]*e,this.littleEndian)),r.push(d.getFloat32(n.points*p.z+n.size[o]*e,this.littleEndian))}if(void 0!==p.rgb){const t=n.fields.indexOf("rgb"),r=d.getUint8(n.points*p.rgb+n.size[t]*e+2)/255,i=d.getUint8(n.points*p.rgb+n.size[t]*e+1)/255,a=d.getUint8(n.points*p.rgb+n.size[t]*e+0)/255;c.set(r,i,a).convertSRGBToLinear(),o.push(c.r,c.g,c.b)}if(void 0!==p.normal_x){const t=n.fields.indexOf("normal_x"),r=n.fields.indexOf("normal_y"),o=n.fields.indexOf("normal_z");i.push(d.getFloat32(n.points*p.normal_x+n.size[t]*e,this.littleEndian)),i.push(d.getFloat32(n.points*p.normal_y+n.size[r]*e,this.littleEndian)),i.push(d.getFloat32(n.points*p.normal_z+n.size[o]*e,this.littleEndian))}if(void 0!==p.intensity){const t=n.fields.indexOf("intensity");a.push(d.getFloat32(n.points*p.intensity+n.size[t]*e,this.littleEndian))}if(void 0!==p.label){const t=n.fields.indexOf("label");s.push(d.getInt32(n.points*p.label+n.size[t]*e,this.littleEndian))}}}if("binary"===n.data){const t=new DataView(e,n.headerLen),l=n.offset;for(let e=0,u=0;e<n.points;e++,u+=n.rowSize){if(void 0!==l.x&&(r.push(t.getFloat32(u+l.x,this.littleEndian)),r.push(t.getFloat32(u+l.y,this.littleEndian)),r.push(t.getFloat32(u+l.z,this.littleEndian))),void 0!==l.rgb){const e=t.getUint8(u+l.rgb+2)/255,n=t.getUint8(u+l.rgb+1)/255,r=t.getUint8(u+l.rgb+0)/255;c.set(e,n,r).convertSRGBToLinear(),o.push(c.r,c.g,c.b)}void 0!==l.normal_x&&(i.push(t.getFloat32(u+l.normal_x,this.littleEndian)),i.push(t.getFloat32(u+l.normal_y,this.littleEndian)),i.push(t.getFloat32(u+l.normal_z,this.littleEndian))),void 0!==l.intensity&&a.push(t.getFloat32(u+l.intensity,this.littleEndian)),void 0!==l.label&&s.push(t.getInt32(u+l.label,this.littleEndian))}}const l=new O;r.length>0&&l.setAttribute("position",new k(r,3)),i.length>0&&l.setAttribute("normal",new k(i,3)),o.length>0&&l.setAttribute("color",new k(o,3)),a.length>0&&l.setAttribute("intensity",new k(a,1)),s.length>0&&l.setAttribute("label",new it(s,1)),l.computeBoundingSphere();const u=new ye({size:.005});return o.length>0&&(u.vertexColors=!0),new Ce(l,u)}}class Yc extends X{constructor(e){super(e),this.animateBonePositions=!0,this.animateBoneRotations=!0}load(e,t,n,r){const i=this,o=new q(i.manager);o.setPath(i.path),o.setRequestHeader(i.requestHeader),o.setWithCredentials(i.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){function t(e,n,r){if("ENDSITE"===r.type)return;const i={time:n,position:new f,rotation:new y};r.frames.push(i);const o=new y,a=new f(1,0,0),s=new f(0,1,0),c=new f(0,0,1);for(let t=0;t<r.channels.length;t++)switch(r.channels[t]){case"Xposition":i.position.x=parseFloat(e.shift().trim());break;case"Yposition":i.position.y=parseFloat(e.shift().trim());break;case"Zposition":i.position.z=parseFloat(e.shift().trim());break;case"Xrotation":o.setFromAxisAngle(a,parseFloat(e.shift().trim())*Math.PI/180),i.rotation.multiply(o);break;case"Yrotation":o.setFromAxisAngle(s,parseFloat(e.shift().trim())*Math.PI/180),i.rotation.multiply(o);break;case"Zrotation":o.setFromAxisAngle(c,parseFloat(e.shift().trim())*Math.PI/180),i.rotation.multiply(o);break;default:console.warn("THREE.BVHLoader: Invalid channel type.")}for(let i=0;i<r.children.length;i++)t(e,n,r.children[i])}function n(e,t,i){const o={name:"",type:"",frames:[]};i.push(o);let a=t.split(/[\s]+/);"END"===a[0].toUpperCase()&&"SITE"===a[1].toUpperCase()?(o.type="ENDSITE",o.name="ENDSITE"):(o.name=a[1],o.type=a[0].toUpperCase()),"{"!==r(e)&&console.error("THREE.BVHLoader: Expected opening { after type & name"),a=r(e).split(/[\s]+/),"OFFSET"!==a[0]&&console.error("THREE.BVHLoader: Expected OFFSET but got: "+a[0]),4!==a.length&&console.error("THREE.BVHLoader: Invalid number of values for OFFSET.");const s=new f(parseFloat(a[1]),parseFloat(a[2]),parseFloat(a[3]));if((isNaN(s.x)||isNaN(s.y)||isNaN(s.z))&&console.error("THREE.BVHLoader: Invalid values of OFFSET."),o.offset=s,"ENDSITE"!==o.type){a=r(e).split(/[\s]+/),"CHANNELS"!==a[0]&&console.error("THREE.BVHLoader: Expected CHANNELS definition.");const t=parseInt(a[1]);o.channels=a.splice(2,t),o.children=[]}for(;;){const t=r(e);if("}"===t)return o;o.children.push(n(e,t,i))}}function r(e){let t;for(;0===(t=e.shift().trim()).length;);return t}const i=this,o=function(e){"HIERARCHY"!==r(e)&&console.error("THREE.BVHLoader: HIERARCHY expected.");const i=[],o=n(e,r(e),i);"MOTION"!==r(e)&&console.error("THREE.BVHLoader: MOTION expected.");let a=r(e).split(/[\s]+/);const s=parseInt(a[1]);isNaN(s)&&console.error("THREE.BVHLoader: Failed to read number of frames."),a=r(e).split(/[\s]+/);const c=parseFloat(a[2]);isNaN(c)&&console.error("THREE.BVHLoader: Failed to read frame time.");for(let n=0;n<s;n++)a=r(e).split(/[\s]+/),t(a,n*c,o);return i}(e.split(/[\r\n]+/g)),a=[];!function e(t,n){const r=new Ie;if(n.push(r),r.position.add(t.offset),r.name=t.name,"ENDSITE"!==t.type)for(let i=0;i<t.children.length;i++)r.add(e(t.children[i],n));return r}(o[0],a);const s=function(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if("ENDSITE"===r.type)continue;const o=[],a=[],s=[];for(let e=0;e<r.frames.length;e++){const t=r.frames[e];o.push(t.time),a.push(t.position.x+r.offset.x),a.push(t.position.y+r.offset.y),a.push(t.position.z+r.offset.z),s.push(t.rotation.x),s.push(t.rotation.y),s.push(t.rotation.z),s.push(t.rotation.w)}i.animateBonePositions&&t.push(new Le(r.name+".position",o,a)),i.animateBoneRotations&&t.push(new je(r.name+".quaternion",o,s))}return new Me("animation",-1,t)}(o);return{skeleton:new Re(a),clip:s}}}const Kc=[[-.525731,0,.850651],[-.442863,.238856,.864188],[-.295242,0,.955423],[-.309017,.5,.809017],[-.16246,.262866,.951056],[0,0,1],[0,.850651,.525731],[-.147621,.716567,.681718],[.147621,.716567,.681718],[0,.525731,.850651],[.309017,.5,.809017],[.525731,0,.850651],[.295242,0,.955423],[.442863,.238856,.864188],[.16246,.262866,.951056],[-.681718,.147621,.716567],[-.809017,.309017,.5],[-.587785,.425325,.688191],[-.850651,.525731,0],[-.864188,.442863,.238856],[-.716567,.681718,.147621],[-.688191,.587785,.425325],[-.5,.809017,.309017],[-.238856,.864188,.442863],[-.425325,.688191,.587785],[-.716567,.681718,-.147621],[-.5,.809017,-.309017],[-.525731,.850651,0],[0,.850651,-.525731],[-.238856,.864188,-.442863],[0,.955423,-.295242],[-.262866,.951056,-.16246],[0,1,0],[0,.955423,.295242],[-.262866,.951056,.16246],[.238856,.864188,.442863],[.262866,.951056,.16246],[.5,.809017,.309017],[.238856,.864188,-.442863],[.262866,.951056,-.16246],[.5,.809017,-.309017],[.850651,.525731,0],[.716567,.681718,.147621],[.716567,.681718,-.147621],[.525731,.850651,0],[.425325,.688191,.587785],[.864188,.442863,.238856],[.688191,.587785,.425325],[.809017,.309017,.5],[.681718,.147621,.716567],[.587785,.425325,.688191],[.955423,.295242,0],[1,0,0],[.951056,.16246,.262866],[.850651,-.525731,0],[.955423,-.295242,0],[.864188,-.442863,.238856],[.951056,-.16246,.262866],[.809017,-.309017,.5],[.681718,-.147621,.716567],[.850651,0,.525731],[.864188,.442863,-.238856],[.809017,.309017,-.5],[.951056,.16246,-.262866],[.525731,0,-.850651],[.681718,.147621,-.716567],[.681718,-.147621,-.716567],[.850651,0,-.525731],[.809017,-.309017,-.5],[.864188,-.442863,-.238856],[.951056,-.16246,-.262866],[.147621,.716567,-.681718],[.309017,.5,-.809017],[.425325,.688191,-.587785],[.442863,.238856,-.864188],[.587785,.425325,-.688191],[.688191,.587785,-.425325],[-.147621,.716567,-.681718],[-.309017,.5,-.809017],[0,.525731,-.850651],[-.525731,0,-.850651],[-.442863,.238856,-.864188],[-.295242,0,-.955423],[-.16246,.262866,-.951056],[0,0,-1],[.295242,0,-.955423],[.16246,.262866,-.951056],[-.442863,-.238856,-.864188],[-.309017,-.5,-.809017],[-.16246,-.262866,-.951056],[0,-.850651,-.525731],[-.147621,-.716567,-.681718],[.147621,-.716567,-.681718],[0,-.525731,-.850651],[.309017,-.5,-.809017],[.442863,-.238856,-.864188],[.16246,-.262866,-.951056],[.238856,-.864188,-.442863],[.5,-.809017,-.309017],[.425325,-.688191,-.587785],[.716567,-.681718,-.147621],[.688191,-.587785,-.425325],[.587785,-.425325,-.688191],[0,-.955423,-.295242],[0,-1,0],[.262866,-.951056,-.16246],[0,-.850651,.525731],[0,-.955423,.295242],[.238856,-.864188,.442863],[.262866,-.951056,.16246],[.5,-.809017,.309017],[.716567,-.681718,.147621],[.525731,-.850651,0],[-.238856,-.864188,-.442863],[-.5,-.809017,-.309017],[-.262866,-.951056,-.16246],[-.850651,-.525731,0],[-.716567,-.681718,-.147621],[-.716567,-.681718,.147621],[-.525731,-.850651,0],[-.5,-.809017,.309017],[-.238856,-.864188,.442863],[-.262866,-.951056,.16246],[-.864188,-.442863,.238856],[-.809017,-.309017,.5],[-.688191,-.587785,.425325],[-.681718,-.147621,.716567],[-.442863,-.238856,.864188],[-.587785,-.425325,.688191],[-.309017,-.5,.809017],[-.147621,-.716567,.681718],[-.425325,-.688191,.587785],[-.16246,-.262866,.951056],[.442863,-.238856,.864188],[.16246,-.262866,.951056],[.309017,-.5,.809017],[.147621,-.716567,.681718],[0,-.525731,.850651],[.425325,-.688191,.587785],[.587785,-.425325,.688191],[.688191,-.587785,.425325],[-.955423,.295242,0],[-.951056,.16246,.262866],[-1,0,0],[-.850651,0,.525731],[-.955423,-.295242,0],[-.951056,-.16246,.262866],[-.864188,.442863,-.238856],[-.951056,.16246,-.262866],[-.809017,.309017,-.5],[-.864188,-.442863,-.238856],[-.951056,-.16246,-.262866],[-.809017,-.309017,-.5],[-.681718,.147621,-.716567],[-.681718,-.147621,-.716567],[-.850651,0,-.525731],[-.688191,.587785,-.425325],[-.587785,.425325,-.688191],[-.425325,.688191,-.587785],[-.425325,-.688191,-.587785],[-.587785,-.425325,-.688191],[-.688191,-.587785,-.425325]];class Qc extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=new q(i.manager);o.setPath(i.path),o.setResponseType("arraybuffer"),o.setRequestHeader(i.requestHeader),o.setWithCredentials(i.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){const t=new DataView(e),n={},r=["ident","version","skinwidth","skinheight","framesize","num_skins","num_vertices","num_st","num_tris","num_glcmds","num_frames","offset_skins","offset_st","offset_tris","offset_frames","offset_glcmds","offset_end"];for(let e=0;e<r.length;e++)n[r[e]]=t.getInt32(4*e,!0);if(844121161!==n.ident||8!==n.version)return void console.error("Not a valid MD2 file");if(n.offset_end!==t.byteLength)return void console.error("Corrupted MD2 file");const i=new O,o=[];let a=n.offset_st;for(let e=0,r=n.num_st;e<r;e++){const e=t.getInt16(a+0,!0),r=t.getInt16(a+2,!0);o.push(e/n.skinwidth,1-r/n.skinheight),a+=4}a=n.offset_tris;const s=[],c=[];for(let e=0,r=n.num_tris;e<r;e++)s.push(t.getUint16(a+0,!0),t.getUint16(a+2,!0),t.getUint16(a+4,!0)),c.push(t.getUint16(a+6,!0),t.getUint16(a+8,!0),t.getUint16(a+10,!0)),a+=12;const l=new f,u=new f,h=[];a=n.offset_frames;for(let e=0,r=n.num_frames;e<r;e++){u.set(t.getFloat32(a+0,!0),t.getFloat32(a+4,!0),t.getFloat32(a+8,!0)),l.set(t.getFloat32(a+12,!0),t.getFloat32(a+16,!0),t.getFloat32(a+20,!0)),a+=24;const e=[];for(let n=0;n<16;n++){const r=t.getUint8(a+n);if(0===r)break;e[n]=r}const r={name:String.fromCharCode.apply(null,e),vertices:[],normals:[]};a+=16;for(let e=0;e<n.num_vertices;e++){let e=t.getUint8(a++),n=t.getUint8(a++),i=t.getUint8(a++);const o=Kc[t.getUint8(a++)];e=e*u.x+l.x,n=n*u.y+l.y,i=i*u.z+l.z,r.vertices.push(e,i,n),r.normals.push(o[0],o[2],o[1])}h.push(r)}const d=[],p=[],m=[],g=h[0].vertices,b=h[0].normals;for(let e=0,t=s.length;e<t;e++){let t=3*s[e];const n=g[t],r=g[t+1],i=g[t+2];d.push(n,r,i);const a=b[t],l=b[t+1],u=b[t+2];p.push(a,l,u);t=2*c[e];const h=o[t],f=o[t+1];m.push(h,f)}i.setAttribute("position",new k(d,3)),i.setAttribute("normal",new k(p,3)),i.setAttribute("uv",new k(m,2));const y=[],v=[];for(let e=0,t=h.length;e<t;e++){const t=h[e],n=t.name;if(t.vertices.length>0){const e=[];for(let n=0,r=s.length;n<r;n++){const r=3*s[n],i=t.vertices[r],o=t.vertices[r+1],a=t.vertices[r+2];e.push(i,o,a)}const r=new k(e,3);r.name=n,y.push(r)}if(t.normals.length>0){const e=[];for(let n=0,r=s.length;n<r;n++){const r=3*s[n],i=t.normals[r],o=t.normals[r+1],a=t.normals[r+2];e.push(i,o,a)}const r=new k(e,3);r.name=n,v.push(r)}}return i.morphAttributes.position=y,i.morphAttributes.normal=v,i.morphTargetsRelative=!1,i.animations=Me.CreateClipsFromMorphTargetSequences(h,10),i}}const Zc=new f,$c=new f;class Jc{modify(e,t){delete(e=e.clone()).morphAttributes.position,delete e.morphAttributes.normal;const n=e.attributes;for(const t in n)"position"!==t&&"uv"!==t&&"normal"!==t&&"tangent"!==t&&"color"!==t&&e.deleteAttribute(t);e=function(e,t=1e-4){t=Math.max(t,Number.EPSILON);const n={},r=e.getIndex(),i=e.getAttribute("position"),o=r?r.count:i.count;let a=0;const s=Object.keys(e.attributes),c={},l={},u=[],h=["getX","getY","getZ","getW"],d=["setX","setY","setZ","setW"];for(let t=0,n=s.length;t<n;t++){const n=s[t],r=e.attributes[n];c[n]=new j(new r.array.constructor(r.count*r.itemSize),r.itemSize,r.normalized);const i=e.morphAttributes[n];i&&(l[n]=new j(new i.array.constructor(i.count*i.itemSize),i.itemSize,i.normalized))}const p=.5*t,f=Math.log10(1/t),m=Math.pow(10,f),g=p*m;for(let t=0;t<o;t++){const i=r?r.getX(t):t;let o="";for(let t=0,n=s.length;t<n;t++){const n=s[t],r=e.getAttribute(n),a=r.itemSize;for(let e=0;e<a;e++)o+=~~(r[h[e]](i)*m+g)+","}if(o in n)u.push(n[o]);else{for(let t=0,n=s.length;t<n;t++){const n=s[t],r=e.getAttribute(n),o=e.morphAttributes[n],u=r.itemSize,p=c[n],f=l[n];for(let e=0;e<u;e++){const t=h[e],n=d[e];if(p[n](a,r[t](i)),o)for(let e=0,r=o.length;e<r;e++)f[e][n](a,o[e][t](i))}}n[o]=a,u.push(a),a++}}const b=e.clone();for(const t in e.attributes){const e=c[t];if(b.setAttribute(t,new j(e.array.slice(0,a*e.itemSize),e.itemSize,e.normalized)),t in l)for(let e=0;e<l[t].length;e++){const n=l[t][e];b.morphAttributes[t][e]=new j(n.array.slice(0,a*n.itemSize),n.itemSize,n.normalized)}}return b.setIndex(u),b}(e);const r=[],i=[],o=e.getAttribute("position"),a=e.getAttribute("uv"),s=e.getAttribute("normal"),c=e.getAttribute("tangent"),l=e.getAttribute("color");let u=null,h=null,d=null,p=null;for(let e=0;e<o.count;e++){const t=(new f).fromBufferAttribute(o,e);a&&(h=(new v).fromBufferAttribute(a,e)),s&&(d=(new f).fromBufferAttribute(s,e)),c&&(u=(new He).fromBufferAttribute(c,e)),l&&(p=(new THREE.Color).fromBufferAttribute(l,e));const n=new cl(t,h,d,u,p);r.push(n)}let m,g=e.getIndex();if(null!==g)for(let e=0;e<g.count;e+=3){const t=g.getX(e),n=g.getX(e+1),o=g.getX(e+2),a=new sl(r[t],r[n],r[o],t,n,o);i.push(a)}else for(let e=0;e<o.count;e+=3){const t=e,n=e+1,o=e+2,a=new sl(r[t],r[n],r[o],t,n,o);i.push(a)}for(let e=0,t=r.length;e<t;e++)nl(r[e]);let b=t;for(;b--;){if(m=al(r),!m){console.log("THREE.SimplifyModifier: No next vertex");break}ol(r,i,m,m.collapseNeighbor)}const y=new O,x=[],w=[],E=[],T=[],A=[];g=[];for(let e=0;e<r.length;e++){const t=r[e];x.push(t.position.x,t.position.y,t.position.z),t.uv&&w.push(t.uv.x,t.uv.y),t.normal&&E.push(t.normal.x,t.normal.y,t.normal.z),t.tangent&&T.push(t.tangent.x,t.tangent.y,t.tangent.z,t.tangent.w),t.color&&A.push(t.color.r,t.color.g,t.color.b),t.id=e}for(let e=0;e<i.length;e++){const t=i[e];g.push(t.v1.id,t.v2.id,t.v3.id)}return y.setAttribute("position",new k(x,3)),w.length>0&&y.setAttribute("uv",new k(w,2)),E.length>0&&y.setAttribute("normal",new k(E,3)),T.length>0&&y.setAttribute("tangent",new k(T,4)),A.length>0&&y.setAttribute("color",new k(A,3)),y.setIndex(g),y}}function el(e,t){const n=e.indexOf(t);n>-1&&e.splice(n,1)}function tl(e,t){const n=t.position.distanceTo(e.position);let r=0;const i=[];for(let n=0,r=e.faces.length;n<r;n++){const r=e.faces[n];r.hasVertex(t)&&i.push(r)}for(let t=0,n=e.faces.length;t<n;t++){let n=1;const o=e.faces[t];for(let e=0;e<i.length;e++){const t=i[e],r=o.normal.dot(t.normal);n=Math.min(n,(1.001-r)/2)}r=Math.max(r,n)}i.length<2&&(r=1);return n*r+0}function nl(e){if(0===e.neighbors.length)return e.collapseNeighbor=null,void(e.collapseCost=-.01);e.collapseCost=1e5,e.collapseNeighbor=null;for(let t=0;t<e.neighbors.length;t++){const n=tl(e,e.neighbors[t]);e.collapseNeighbor||(e.collapseNeighbor=e.neighbors[t],e.collapseCost=n,e.minCost=n,e.totalCost=0,e.costCount=0),e.costCount++,e.totalCost+=n,n<e.minCost&&(e.collapseNeighbor=e.neighbors[t],e.minCost=n)}e.collapseCost=e.totalCost/e.costCount}function rl(e,t){for(console.assert(0===e.faces.length);e.neighbors.length;){el(e.neighbors.pop().neighbors,e)}el(t,e)}function il(e,t){el(t,e),e.v1&&el(e.v1.faces,e),e.v2&&el(e.v2.faces,e),e.v3&&el(e.v3.faces,e);const n=[e.v1,e.v2,e.v3];for(let e=0;e<3;e++){const t=n[e],r=n[(e+1)%3];t&&r&&(t.removeIfNonNeighbor(r),r.removeIfNonNeighbor(t))}}function ol(e,t,n,r){if(!r)return void rl(n,e);r.uv&&n.uv.copy(r.uv),r.normal&&r.normal.add(n.normal).normalize(),r.tangent&&r.tangent.add(n.tangent).normalize();const i=[];for(let e=0;e<n.neighbors.length;e++)i.push(n.neighbors[e]);for(let e=n.faces.length-1;e>=0;e--)n.faces[e]&&n.faces[e].hasVertex(r)&&il(n.faces[e],t);for(let e=n.faces.length-1;e>=0;e--)n.faces[e].replaceVertex(n,r);rl(n,e);for(let e=0;e<i.length;e++)nl(i[e])}function al(e){let t=e[0];for(let n=0;n<e.length;n++)e[n].collapseCost<t.collapseCost&&(t=e[n]);return t}class sl{constructor(e,t,n,r,i,o){this.a=r,this.b=i,this.c=o,this.v1=e,this.v2=t,this.v3=n,this.normal=new f,this.computeNormal(),e.faces.push(this),e.addUniqueNeighbor(t),e.addUniqueNeighbor(n),t.faces.push(this),t.addUniqueNeighbor(e),t.addUniqueNeighbor(n),n.faces.push(this),n.addUniqueNeighbor(e),n.addUniqueNeighbor(t)}computeNormal(){const e=this.v1.position,t=this.v2.position,n=this.v3.position;Zc.subVectors(n,t),$c.subVectors(e,t),Zc.cross($c).normalize(),this.normal.copy(Zc)}hasVertex(e){return e===this.v1||e===this.v2||e===this.v3}replaceVertex(e,t){e===this.v1?this.v1=t:e===this.v2?this.v2=t:e===this.v3&&(this.v3=t),el(e.faces,this),t.faces.push(this),e.removeIfNonNeighbor(this.v1),this.v1.removeIfNonNeighbor(e),e.removeIfNonNeighbor(this.v2),this.v2.removeIfNonNeighbor(e),e.removeIfNonNeighbor(this.v3),this.v3.removeIfNonNeighbor(e),this.v1.addUniqueNeighbor(this.v2),this.v1.addUniqueNeighbor(this.v3),this.v2.addUniqueNeighbor(this.v1),this.v2.addUniqueNeighbor(this.v3),this.v3.addUniqueNeighbor(this.v1),this.v3.addUniqueNeighbor(this.v2),this.computeNormal()}}class cl{constructor(e,t,n,r,i){this.position=e,this.uv=t,this.normal=n,this.tangent=r,this.color=i,this.id=-1,this.faces=[],this.neighbors=[],this.collapseCost=0,this.collapseNeighbor=null}addUniqueNeighbor(e){var t,n;t=this.neighbors,n=e,-1===t.indexOf(n)&&t.push(n)}removeIfNonNeighbor(e){const t=this.neighbors,n=this.faces,r=t.indexOf(e);if(-1!==r){for(let t=0;t<n.length;t++)if(n[t].hasVertex(e))return;t.splice(r,1)}}}const ll={maxSize:null,maxWidth:null,maxHeight:null,autoResize:!0,quality:.8};function ul(e={}){const t={...ll};return Object.keys(e).forEach(n=>{null!==e[n]&&void 0!==e[n]&&(t[n]=e[n])}),t}function hl(e,t={}){console.log(e);const n=ul(t);return new Promise(async(t,r)=>{try{e.preventDefault();const i=e.dataTransfer.getData("application/x-gallery-image"),o=e.dataTransfer.getData("application/json"),a=e.dataTransfer.getData("text/plain"),s=e.dataTransfer.files;if(i){const e=JSON.parse(i);if(e.picUrl){return void t(await dl(e.picUrl,n))}}if(s&&s.length>0){const e=s[0];if(e.type.startsWith("image/")){const r=await function(e,t={}){const n=ul(t);return new Promise(async(t,r)=>{try{if(!e.type.startsWith("image/"))return void r(new Error("请选择图片文件"));if(n.maxSize&&e.size>n.maxSize)return void r(new Error(`文件大小不能超过 ${(n.maxSize/1024/1024).toFixed(1)}MB`));const i=await function(e,t){return new Promise((n,r)=>{const i=new Image,o=document.createElement("canvas"),a=o.getContext("2d");i.onload=()=>{const{naturalWidth:s,naturalHeight:c}=i;if(t.maxWidth&&s>t.maxWidth||t.maxHeight&&c>t.maxHeight){if(!t.autoResize)return void r(new Error(`图片尺寸不能超过 ${t.maxWidth||"∞"}x${t.maxHeight||"∞"} 像素,当前尺寸:${s}x${c}`));let l=1;if(t.maxWidth&&t.maxHeight){const e=t.maxWidth/s,n=t.maxHeight/c;l=Math.min(e,n)}else t.maxWidth?l=t.maxWidth/s:t.maxHeight&&(l=t.maxHeight/c);const u=Math.floor(s*l),h=Math.floor(c*l);o.width=u,o.height=h,a.drawImage(i,0,0,u,h),o.toBlob(t=>{if(t){const r=new File([t],e.name,{type:e.type,lastModified:Date.now()});n(r)}else r(new Error("图片处理失败"))},e.type,t.quality)}else n(e)},i.onerror=()=>{r(new Error("图片格式不支持或文件损坏"))},i.src=URL.createObjectURL(e)})}(e,n),o=URL.createObjectURL(i);t({file:i,url:o,originalFile:e,isResized:i!==e})}catch(e){r(new Error(e.message||"文件处理失败"))}})}(e,n);return void t(r)}}if(o){const e=JSON.parse(o);if(e.picUrl){return void t(await dl(e.picUrl,n))}}if(a&&a.startsWith("http")){return void t(await dl(a,n))}r(new Error("未找到有效的图片数据"))}catch(e){r(new Error(e.message||"拖拽处理失败"))}})}function dl(e,t={}){const n=ul(t);return new Promise(async(t,r)=>{try{if(!e||!e.startsWith("http"))return void r(new Error("无效的图片URL"));const i=new Image;i.crossOrigin="anonymous",await new Promise((t,n)=>{i.onload=t,i.onerror=()=>n(new Error("图片加载失败")),i.src=e});if(n.maxWidth&&i.naturalWidth>n.maxWidth||n.maxHeight&&i.naturalHeight>n.maxHeight){if(!n.autoResize)return void r(new Error(`图片尺寸不能超过 ${n.maxWidth||"∞"}x${n.maxHeight||"∞"} 像素,当前尺寸:${i.naturalWidth}x${i.naturalHeight}`));const o=await function(e,t){return new Promise((n,r)=>{const i=document.createElement("canvas"),o=i.getContext("2d");let a=1;if(t.maxWidth&&t.maxHeight){const n=t.maxWidth/e.naturalWidth,r=t.maxHeight/e.naturalHeight;a=Math.min(n,r)}else t.maxWidth?a=t.maxWidth/e.naturalWidth:t.maxHeight&&(a=t.maxHeight/e.naturalHeight);const s=Math.floor(e.naturalWidth*a),c=Math.floor(e.naturalHeight*a);i.width=s,i.height=c,o.drawImage(e,0,0,s,c),i.toBlob(e=>{e?n(e):r(new Error("图片处理失败"))},"image/png",t.quality)})}(i,n),a=URL.createObjectURL(o);t({file:o,url:a,originalUrl:e,isResized:!0})}else{t({file:null,url:e,originalUrl:e,isResized:!1})}}catch(e){r(new Error(`图片加载失败: ${e.message}`))}})}class pl{constructor(t,n,r,i){if(this.addObjects=i,this.canvas=t,this.models=[],this.loadingManager=new e.LoadingManager,this.textureLoader=new e.TextureLoader(this.loadingManager),this.scene=r,this.simplifyModifier=new Jc,this.clock=new e.Clock,this.mixers=[],this.animations=new Map,n)this.camera=n;else{const n=t.clientWidth/t.clientHeight;this.camera=new e.PerspectiveCamera(75,n,.1,1e3),this.camera.position.z=5}this.loadingManager.onError=e=>{console.warn(`Failed to load resource: ${e}`)},this.initDragDrop()}initDragDrop(){this.canvas.addEventListener("dragover",e=>{e.preventDefault(),e.stopPropagation(),this.canvas.style.border="2px dashed #646cff"}),this.canvas.addEventListener("dragleave",e=>{e.preventDefault(),e.stopPropagation(),this.canvas.style.border=""}),this.canvas.addEventListener("drop",async e=>{e.preventDefault(),e.stopPropagation(),this.canvas.style.border="";try{const t=await hl(e);return console.log(t),void this.loadFile(t.originalUrl||t.file)}catch(e){}const t=e.dataTransfer.files;t.length>0&&this.loadFile(t[0])})}getLoaderForExtension(e){switch(e.toLowerCase()){case"gltf":case"glb":const t=new yo(this.loadingManager),n=new mo;return n.setDecoderPath("https://www.gstatic.com/draco/v1/decoders/"),t.setDRACOLoader(n),t.setMeshoptDecoder(ma),t;case"obj":return new Sa(this.loadingManager);case"mtl":return new Ra(this.loadingManager);case"fbx":return new Fa(this.loadingManager);case"dae":return new rs(this.loadingManager);case"ply":return new os(this.loadingManager);case"stl":return new ss(this.loadingManager);case"svg":return new ls(this.loadingManager);case"3ds":return new us(this.loadingManager);case"wrl":return new zc(this.loadingManager);case"pcd":return new qc(this.loadingManager);case"prwm":return new PRWMLoader(this.loadingManager);case"bvh":return new Yc(this.loadingManager);case"md2":return new Qc(this.loadingManager);case"ttf":return new TTFLoader(this.loadingManager);case"ktx2":return new KTX2Loader(this.loadingManager);case"basis":return new BasisTextureLoader(this.loadingManager);case"hdr":case"rgbe":return new RGBELoader(this.loadingManager);case"exr":return new EXRLoader(this.loadingManager);case"tga":return new TGALoader(this.loadingManager);case"ldr":case"mpd":return new LDrawLoader(this.loadingManager);case"nrrd":return new NRRDLoader(this.loadingManager);case"vox":return new VOXLoader(this.loadingManager);case"gcode":return new GCodeLoader(this.loadingManager);case"jpg":case"jpeg":case"png":case"gif":case"bmp":case"webp":return this.textureLoader;default:throw new Error(`Unsupported file format: ${e}`)}}async loadFile(t,n={}){let r,i;if(t instanceof File)r=t.name,i=URL.createObjectURL(t);else{r=t.split("/").pop(),i=t;(i.startsWith("http")||i.startsWith("//"))&&(this.loadingManager.setURLModifier(e=>{if(!e.startsWith("http")&&!e.startsWith("//")){return i.substring(0,i.lastIndexOf("/")+1)+e}return e}),this.textureLoader.setCrossOrigin("anonymous"))}const o=r.split(".").pop().toLowerCase();try{const t=this.getLoaderForExtension(o);"function"==typeof t.setCrossOrigin&&t.setCrossOrigin("anonymous");const r=await this.loadWithLoader(t,i,o);("fbx"===o||"gltf"===o||"glb"===o)&&r.animations&&r.animations.length>0&&this.setupAnimation(r),this.createSkeletonHelper(r),(n.simplifyRatio||n.maxFaces)&&this.optimizeModel(r,n);const a=(new e.Box3).setFromObject(r).getSize(new e.Vector3);let s=1;const c=5,l=Math.max(a.x,a.y,a.z);return l>0&&(s=c/l),r.scale.set(s,s,s),r.rotation.set(0,0,0),r.children.forEach(e=>{e.rotation.set(0,0,0)}),r.castShadow=!0,r.receiveShadow=!0,this.scene&&this.scene.add(r),this.addObjects(r),n.position&&r.position.copy(n.position),n.scale&&r.scale.copy(n.scale),this.models.push(r),r}catch(e){return null}finally{t instanceof File&&URL.revokeObjectURL(i)}}setupAnimation(t){if(t.animations&&t.animations.length>0){const n=new e.AnimationMixer(t);this.mixers.push(n),this.animations.set(t,{mixer:n,clips:t.animations});n.clipAction(t.animations[0]).play()}}createSkeletonHelper(t){const n=new e.SkeletonHelper(t);n.material.linewidth=2,n.name="skeletonHelper",this.scene&&this.scene.add(n),t.userData.skeletonHelpers||(t.userData.skeletonHelpers=[]),t.userData.skeletonHelpers.push(n),console.log("已创建骨骼辅助线")}toggleSkeletonHelper(e,t=!0){e.userData.skeletonHelpers&&e.userData.skeletonHelpers.forEach(e=>{e.visible=t})}removeSkeletonHelper(e){e.userData.skeletonHelpers&&(e.userData.skeletonHelpers.forEach(e=>{this.scene&&this.scene.remove(e),e.dispose()}),e.userData.skeletonHelpers=[])}playAnimation(e,t=0){const n=this.animations.get(e);if(!n)return void console.warn("模型没有动画数据");let r=null;if("number"==typeof t?r=n.clips[t]:"string"==typeof t&&(r=n.clips.find(e=>e.name===t)),!r)return void console.warn("未找到指定的动画");n.mixer.stopAllAction();n.mixer.clipAction(r).play()}updateAnimations(){const e=this.clock.getDelta();this.mixers.forEach(t=>{t.update(e)})}optimizeModel(e,t={}){const{simplifyRatio:n=.5,maxFaces:r}=t;e.traverse(e=>{if(e.isMesh&&e.geometry){if(e.isSkinnedMesh)return void console.log("检测到骨骼网格,跳过减面优化以保持动画质量");const t=e.geometry,i=t.index?t.index.count/3:t.attributes.position.count/3;let o=Math.floor(i*(1-n));if(r&&i>r&&(o=Math.min(o,r)),o<i&&o>0)try{t.index||(t=t.toNonIndexed());const n=1-o/i,r=this.simplifyModifier.modify(t,Math.floor(i*n));r&&r.attributes.position&&(t.dispose(),e.geometry=r,e.geometry.computeVertexNormals(),e.geometry.computeBoundingBox(),e.geometry.computeBoundingSphere(),console.log(`模型减面:${i} -> ${o} 面`))}catch(e){console.warn("模型减面失败:",e)}}})}optimizeAllModels(e={}){this.models.forEach(t=>{this.optimizeModel(t,e)})}loadWithLoader(t,n,r){return new Promise((i,o)=>{switch(r){case"gltf":case"glb":t.load(n,e=>{i(e.scene)},e=>{if(this.loadingElement&&e.loaded&&e.total){const t=Math.round(e.loaded/e.total*100);!isNaN(t)&&t>=0&&t<=100&&(this.loadingElement.textContent=`正在加载模型... ${t}%`)}},e=>{console.warn("GLTF加载失败"),o(new Error("模型文件加载失败"))});break;case"obj":t.load(n,e=>{i(e)},void 0,e=>{console.warn("OBJ加载失败"),o(new Error("模型文件加载失败"))});break;case"fbx":t.load(n,e=>{i(e)},void 0,e=>{console.warn("FBX加载失败"),o(new Error("模型文件加载失败"))});break;case"dae":t.load(n,e=>{i(e.scene)},void 0,e=>{console.warn("DAE加载失败"),o(new Error("模型文件加载失败"))});break;case"mtl":t.load(n,e=>{e.preload();new Sa(this.loadingManager).setMaterials(e),o(new Error("MTL文件需要配合OBJ文件使用"))},void 0,o);break;default:t instanceof e.TextureLoader?t.load(n,t=>{const n=new e.Mesh(new e.PlaneGeometry,new e.MeshBasicMaterial({map:t}));i(n)},void 0,e=>{console.warn("纹理加载失败"),o(new Error("文件加载失败"))}):t.load(n,e=>{i(e)},void 0,e=>{console.warn("文件加载失败:",e.message),o(e)})}})}showLoadingMessage(e){this.removeLoadingMessage();const t=document.createElement("div");t.style.position="absolute",t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)",t.style.background="rgba(0, 0, 0, 0.7)",t.style.color="white",t.style.padding="20px",t.style.borderRadius="5px",t.style.zIndex="1000",t.id="model-loading-message",t.textContent=e||"正在加载模型...",document.body.appendChild(t),this.loadingElement=t}removeLoadingMessage(){const e=document.getElementById("model-loading-message");e&&document.body.removeChild(e),this.loadingElement&&this.loadingElement.parentNode&&this.loadingElement.parentNode.removeChild(this.loadingElement),this.loadingElement=null}clearModels(){this.scene?(this.models.forEach(e=>{if(this.removeSkeletonHelper(e),this.animations.has(e)){const t=this.animations.get(e);if(t.mixer){t.mixer.stopAllAction();const e=this.mixers.indexOf(t.mixer);-1!==e&&this.mixers.splice(e,1)}this.animations.delete(e)}this.scene.remove(e),e.traverse&&e.traverse(e=>{e.material&&(Array.isArray(e.material)?e.material.forEach(e=>{e.map&&e.map.dispose(),e.dispose()}):(e.material.map&&e.material.map.dispose(),e.material.dispose())),e.geometry&&e.geometry.dispose()})}),this.models=[],this.mixers=[],this.animations.clear()):console.warn("场景未初始化,无法清除模型")}handleLoadingError(e){console.warn("模型加载失败"),this.removeLoadingMessage()}}function fl(t,n,r,i,o){const a=t/2,s=t/n,c=new e.BufferGeometry,l=new e.LineBasicMaterial({vertexColors:!0}),u=[],h=[],d=new e.Color(r),p=new e.Color(i),f=new e.Color(o);u.push(-a,0,0,a,0,0),h.push(d.r,d.g,d.b,d.r,d.g,d.b),u.push(0,0,-a,0,0,a),h.push(p.r,p.g,p.b,p.r,p.g,p.b);for(let e=-a;e<=a;e+=s)0!==e&&(u.push(e,0,-a,e,0,a),h.push(f.r,f.g,f.b,f.r,f.g,f.b),u.push(-a,0,e,a,0,e),h.push(f.r,f.g,f.b,f.r,f.g,f.b));return c.setAttribute("position",new e.Float32BufferAttribute(u,3)),c.setAttribute("color",new e.Float32BufferAttribute(h,3)),l.transparent=!0,l.vertexColors=!0,new e.LineSegments(c,l)}class ml{constructor(){this._events={}}on(e,t){return this._events[e]||(this._events[e]=[]),this._events[e].push(t),this}once(e,t){const n=(...r)=>{this.off(e,n),t.apply(this,r)};return n.listener=t,this.on(e,n),this}emit(e,...t){if(!this._events[e])return!1;return[...this._events[e]].forEach(e=>{e.apply(this,t)}),!0}off(e,t){if(!this._events[e])return this;if(!t)return delete this._events[e],this;const n=this._events[e].findIndex(e=>e===t||e.listener&&e.listener===t);return-1!==n&&(this._events[e].splice(n,1),0===this._events[e].length&&delete this._events[e]),this}removeAllListeners(e){return e?delete this._events[e]:this._events={},this}}class gl extends ml{constructor(e={}){super(),this.options=Object.assign({target:window,enabledDefault:!0},e),this.shortcuts=new Map,this.enabled=!0,this.pressedKeys=new Set,this._init(),this.options.enabledDefault&&this._setupDefaultShortcuts()}_init(){const e=this.options.target;this._onKeyDown=this._handleKeyDown.bind(this),this._onKeyUp=this._handleKeyUp.bind(this),e.addEventListener("keydown",this._onKeyDown),e.addEventListener("keyup",this._onKeyUp),e.addEventListener("blur",()=>this.pressedKeys.clear())}_setupDefaultShortcuts(){this.register("ctrl+z",()=>this.emit("undo")),this.register("ctrl+y",()=>this.emit("redo")),this.register("ctrl+shift+z",()=>this.emit("redo")),this.register("delete",()=>this.emit("delete")),this.register("backspace",()=>this.emit("delete")),this.register("ctrl+c",()=>this.emit("copy")),this.register("ctrl+v",()=>this.emit("paste")),this.register("ctrl+x",()=>this.emit("cut")),this.register("ctrl+a",e=>{console.log(22),e.preventDefault(),this.emit("selectAll")}),this.register("ctrl+s",e=>{e.preventDefault(),this.emit("save")}),this.register("escape",()=>this.emit("cancel"))}_handleKeyDown(e){if("INPUT"===document.activeElement.tagName||"TEXTAREA"===document.activeElement.tagName||"SELECT"===document.activeElement.tagName||document.activeElement.isContentEditable)return;if(!this.enabled)return;const t=e.key.toLowerCase();this.pressedKeys.add(t);const n=this._buildShortcutKey();if(this.shortcuts.has(n)){e.preventDefault();this.shortcuts.get(n)(e),this.emit("shortcutTriggered",{shortcut:n,event:e})}}_handleKeyUp(e){const t=e.key.toLowerCase();this.pressedKeys.delete(t)}_buildShortcutKey(){const e=[];return(this.pressedKeys.has("control")||this.pressedKeys.has("ctrl"))&&e.push("ctrl"),this.pressedKeys.has("shift")&&e.push("shift"),this.pressedKeys.has("alt")&&e.push("alt"),(this.pressedKeys.has("meta")||this.pressedKeys.has("command"))&&e.push("meta"),this.pressedKeys.forEach(t=>{["control","ctrl","shift","alt","meta","command"].includes(t)||e.push(t)}),e.sort().join("+")}register(e,t){const n=this._normalizeShortcut(e);return this.shortcuts.set(n,t),this.emit("shortcutRegistered",{shortcut:n,original:e}),this}unregister(e){const t=this._normalizeShortcut(e),n=this.shortcuts.delete(t);return n&&this.emit("shortcutUnregistered",{shortcut:t,original:e}),n}_normalizeShortcut(e){const t=e.toLowerCase().split("+").map(e=>{switch(e.trim()){case"command":case"cmd":return"meta";case"control":return"ctrl";case"space":case"spacebar":return" ";case"esc":return"escape";case"ins":return"insert";case"del":return"delete";default:return e.trim()}}),n=[],r=[];t.forEach(e=>{["ctrl","shift","alt","meta"].includes(e)?n.push(e):r.push(e)});const i=[];return["ctrl","shift","alt","meta"].forEach(e=>{n.includes(e)&&i.push(e)}),[...i,...r].join("+")}enable(){this.enabled=!0,this.emit("enabled")}disable(){this.enabled=!1,this.emit("disabled")}isRegistered(e){return this.shortcuts.has(this._normalizeShortcut(e))}getRegisteredShortcuts(){return Array.from(this.shortcuts.keys())}clearAll(){this.shortcuts.clear(),this.emit("allShortcutsCleared")}dispose(){const e=this.options.target;e.removeEventListener("keydown",this._onKeyDown),e.removeEventListener("keyup",this._onKeyUp),this.clearAll(),this.removeAllListeners()}}var bl="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function yl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function vl(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}),n}var xl,wl,El=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,i,o;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(i=r;0!==i--;)if(!e(t[i],n[i]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(o=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(i=r;0!==i--;)if(!Object.prototype.hasOwnProperty.call(n,o[i]))return!1;for(i=r;0!==i--;){var a=o[i];if(!e(t[a],n[a]))return!1}return!0}return t!=t&&n!=n},Tl=yl(El),Al=Object.prototype.toString,Cl=function(e){var t=Al.call(e),n="[object Arguments]"===t;return n||(n="[object Array]"!==t&&null!==e&&"object"==typeof e&&"number"==typeof e.length&&e.length>=0&&"[object Function]"===Al.call(e.callee)),n};var Ol=Array.prototype.slice,kl=Cl,Sl=Object.keys,Rl=Sl?function(e){return Sl(e)}:function(){if(wl)return xl;var e;if(wl=1,!Object.keys){var t=Object.prototype.hasOwnProperty,n=Object.prototype.toString,r=Cl,i=Object.prototype.propertyIsEnumerable,o=!i.call({toString:null},"toString"),a=i.call(function(){},"prototype"),s=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],c=function(e){var t=e.constructor;return t&&t.prototype===e},l={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},u=function(){if("undefined"==typeof window)return!1;for(var e in window)try{if(!l["$"+e]&&t.call(window,e)&&null!==window[e]&&"object"==typeof window[e])try{c(window[e])}catch(e){return!0}}catch(e){return!0}return!1}();e=function(e){var i=null!==e&&"object"==typeof e,l="[object Function]"===n.call(e),h=r(e),d=i&&"[object String]"===n.call(e),p=[];if(!i&&!l&&!h)throw new TypeError("Object.keys called on a non-object");var f=a&&l;if(d&&e.length>0&&!t.call(e,0))for(var m=0;m<e.length;++m)p.push(String(m));if(h&&e.length>0)for(var g=0;g<e.length;++g)p.push(String(g));else for(var b in e)f&&"prototype"===b||!t.call(e,b)||p.push(String(b));if(o)for(var y=function(e){if("undefined"==typeof window||!u)return c(e);try{return c(e)}catch(e){return!1}}(e),v=0;v<s.length;++v)y&&"constructor"===s[v]||!t.call(e,s[v])||p.push(s[v]);return p}}return xl=e}(),Ml=Object.keys;Rl.shim=function(){if(Object.keys){var e=function(){var e=Object.keys(arguments);return e&&e.length===arguments.length}(1,2);e||(Object.keys=function(e){return kl(e)?Ml(Ol.call(e)):Ml(e)})}else Object.keys=Rl;return Object.keys||Rl};var Il=Rl,Pl=Object.defineProperty||!1;if(Pl)try{Pl({},"a",{value:1})}catch(e){Pl=!1}var _l=Pl,Nl=SyntaxError,Ll=TypeError,Dl=Object.getOwnPropertyDescriptor;if(Dl)try{Dl([],"length")}catch(e){Dl=null}var jl=_l,Fl=Nl,Ul=Ll,Bl=Dl,zl=_l,Hl=function(){return!!zl};Hl.hasArrayLengthDefineBug=function(){if(!zl)return null;try{return 1!==zl([],"length",{value:1}).length}catch(e){return!0}};var Vl=Hl,Gl=Il,Wl="function"==typeof Symbol&&"symbol"==typeof Symbol("foo"),Xl=Object.prototype.toString,ql=Array.prototype.concat,Yl=function(e,t,n){if(!e||"object"!=typeof e&&"function"!=typeof e)throw new Ul("`obj` must be an object or a function`");if("string"!=typeof t&&"symbol"!=typeof t)throw new Ul("`property` must be a string or a symbol`");if(arguments.length>3&&"boolean"!=typeof arguments[3]&&null!==arguments[3])throw new Ul("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&"boolean"!=typeof arguments[4]&&null!==arguments[4])throw new Ul("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&"boolean"!=typeof arguments[5]&&null!==arguments[5])throw new Ul("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&"boolean"!=typeof arguments[6])throw new Ul("`loose`, if provided, must be a boolean");var r=arguments.length>3?arguments[3]:null,i=arguments.length>4?arguments[4]:null,o=arguments.length>5?arguments[5]:null,a=arguments.length>6&&arguments[6],s=!!Bl&&Bl(e,t);if(jl)jl(e,t,{configurable:null===o&&s?s.configurable:!o,enumerable:null===r&&s?s.enumerable:!r,value:n,writable:null===i&&s?s.writable:!i});else{if(!a&&(r||i||o))throw new Fl("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.");e[t]=n}},Kl=Vl(),Ql=function(e,t,n,r){if(t in e)if(!0===r){if(e[t]===n)return}else if("function"!=typeof(i=r)||"[object Function]"!==Xl.call(i)||!r())return;var i;Kl?Yl(e,t,n,!0):Yl(e,t,n)},Zl=function(e,t){var n=arguments.length>2?arguments[2]:{},r=Gl(t);Wl&&(r=ql.call(r,Object.getOwnPropertySymbols(t)));for(var i=0;i<r.length;i+=1)Ql(e,r[i],t[r[i]],n[r[i]])};Zl.supportsDescriptors=!!Kl;var $l=Zl,Jl={exports:{}};"undefined"!=typeof self?Jl.exports=self:"undefined"!=typeof window?Jl.exports=window:Jl.exports=Function("return this")();var eu=Jl.exports,tu=eu,nu=function(){return"object"==typeof bl&&bl&&bl.Math===Math&&bl.Array===Array?bl:tu},ru=$l,iu=nu,ou=$l,au=eu,su=nu,cu=function(){var e=iu();if(ru.supportsDescriptors){var t=Object.getOwnPropertyDescriptor(e,"globalThis");t&&(!t.configurable||!t.enumerable&&t.writable&&globalThis===e)||Object.defineProperty(e,"globalThis",{configurable:!0,enumerable:!1,value:e,writable:!0})}else"object"==typeof globalThis&&globalThis===e||(e.globalThis=e);return e},lu=su(),uu=function(){return lu};ou(uu,{getPolyfill:su,implementation:au,shim:cu});const hu=yl(uu)(),du={vtkObject:()=>null};function pu(e){if(null==e)return e;if(e.isA)return e;if(!e.vtkClass)return hu.console&&hu.console.error&&hu.console.error("Invalid VTK object"),null;const t=du[e.vtkClass];if(!t)return hu.console&&hu.console.error&&hu.console.error(`No vtk class found for Object of type ${e.vtkClass}`),null;const n={...e};Object.keys(n).forEach(e=>{n[e]&&"object"==typeof n[e]&&n[e].vtkClass&&(n[e]=pu(n[e]))});const r=t(n);return r&&r.modified&&r.modified(),r}pu.register=function(e,t){du[e]=t};class fu extends Array{push(){for(let e=0;e<arguments.length;e++)this.includes(arguments[e])||super.push(arguments[e]);return this.length}}let mu=0;const gu=e=>{throw new Error(`Named parameter '${e}' is missing`)},bu=Symbol("void");const yu={};function vu(){}["log","debug","info","warn","error","time","timeEnd","group","groupEnd"].forEach(e=>{yu[e]=vu}),hu.console=console.hasOwnProperty("log")?console:yu;const xu={debug:vu,error:hu.console.error||vu,info:hu.console.info||vu,log:hu.console.log||vu,warn:hu.console.warn||vu};function wu(e,t){xu[e]&&(xu[e]=t||vu)}function Eu(){xu.log(...arguments)}function Tu(){xu.info(...arguments)}function Au(){xu.debug(...arguments)}function Cu(){xu.error(...arguments)}function Ou(){xu.warn(...arguments)}const ku={};function Su(e){ku[e]||(xu.error(e),ku[e]=!0)}const Ru=Object.create(null);Ru.Float32Array=Float32Array,Ru.Float64Array=Float64Array,Ru.Uint8Array=Uint8Array,Ru.Int8Array=Int8Array,Ru.Uint16Array=Uint16Array,Ru.Int16Array=Int16Array,Ru.Uint32Array=Uint32Array,Ru.Int32Array=Int32Array,Ru.Uint8ClampedArray=Uint8ClampedArray;try{Ru.BigInt64Array=BigInt64Array,Ru.BigUint64Array=BigUint64Array}catch{}function Mu(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return new(Ru[e]||Float64Array)(...n)}function Iu(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return(Ru[e]||Float64Array).from(...n)}function Pu(e){return e.charAt(0).toUpperCase()+e.slice(1)}function _u(e){return Pu("_"===e[0]?e.slice(1):e)}function Nu(e){return e.charAt(0).toLowerCase()+e.slice(1)}function Lu(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e3;const r=["TB","GB","MB","KB"];let i=Number(e),o="B";for(;i>n;)i/=n,o=r.pop();return`${i.toFixed(t)} ${o}`}function Du(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:" ";const n=[];let r=e;for(;r>1e3;)n.push(("000"+r%1e3).slice(-3)),r=Math.floor(r/1e3);return r>0&&n.push(r),n.reverse(),n.join(t)}function ju(e){Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=[].concat(e[t]))})}function Fu(e){return e&&e.isA?e.getState():e}function Uu(e){setTimeout(e,0)}function Bu(e,t){const n=performance.now();e.finally(()=>{const e=performance.now()-n;t(e)})}function zu(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ju(t);const n=[];if(Number.isInteger(t.mtime)||(t.mtime=++mu),"classHierarchy"in t){if(!(t.classHierarchy instanceof fu)){const e=new fu;for(let n=0;n<t.classHierarchy.length;n++)e.push(t.classHierarchy[n]);t.classHierarchy=e}}else t.classHierarchy=new fu("vtkObject");function r(e){n[e]=null}return e.isDeleted=()=>!!t.deleted,e.modified=r=>{t.deleted?Cu("instance deleted - cannot call any method"):r&&r<e.getMTime()||(t.mtime=++mu,n.forEach(t=>t&&t(e)))},e.onModified=e=>{if(t.deleted)return Cu("instance deleted - cannot call any method"),null;const i=n.length;return n.push(e),function(e){return Object.freeze({unsubscribe:function(){r(e)}})}(i)},e.getMTime=()=>t.mtime,e.isA=e=>{let n=t.classHierarchy.length;for(;n--;)if(t.classHierarchy[n]===e)return!0;return!1},e.getClassName=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return t.classHierarchy[t.classHierarchy.length-1-e]},e.set=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=!1;return Object.keys(n).forEach(a=>{const s=i?null:e[`set${Pu(a)}`];s&&Array.isArray(n[a])&&s.length>1?o=s(...n[a])||o:s?o=s(n[a])||o:(-1!==["mtime"].indexOf(a)||r||Ou(`Warning: Set value to model directly ${a}, ${n[a]}`),o=t[a]!==n[a]||o,t[a]=n[a])}),o},e.get=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];if(!n.length)return t;const i={};return n.forEach(e=>{i[e]=t[e]}),i},e.getReferenceByName=e=>t[e],e.delete=()=>{Object.keys(t).forEach(e=>delete t[e]),n.forEach((e,t)=>r(t)),t.deleted=!0},e.getState=()=>{if(t.deleted)return null;const n={...t,vtkClass:e.getClassName()};Object.keys(n).forEach(e=>{var t;null===n[e]||void 0===n[e]||"_"===e[0]?delete n[e]:n[e].isA?n[e]=n[e].getState():Array.isArray(n[e])?n[e]=n[e].map(Fu):(t=n[e],Object.values(Ru).some(e=>t instanceof e)&&(n[e]=Array.from(n[e])))});const r={};return Object.keys(n).sort().forEach(e=>{r[e]=n[e]}),r.mtime&&delete r.mtime,r},e.shallowCopy=function(n){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(n.getClassName()!==e.getClassName())throw new Error(`Cannot ShallowCopy ${n.getClassName()} into ${e.getClassName()}`);const i=n.get(),o=Object.keys(t).sort();Object.keys(i).sort().forEach(e=>{const n=o.indexOf(e);-1===n?r&&Au(`add ${e} in shallowCopy`):o.splice(n,1),t[e]=i[e]}),o.length&&r&&Au(`Untouched keys: ${o.join(", ")}`),e.modified()},e.toJSON=function(){return e.getState()},e}const Hu={object:(e,t,n)=>function(){return{...t[n.name]}}};function Vu(e,t,n){n.forEach(n=>{if("object"==typeof n){const r=Hu[n.type];e[`get${_u(n.name)}`]=r?r(e,t,n):()=>t[n.name]}else e[`get${_u(n)}`]=()=>t[n]})}const Gu={enum(e,t,n){const r=`_on${_u(n.name)}Changed`;return i=>{if("string"==typeof i){if(void 0!==n.enum[i])return t[n.name]!==n.enum[i]&&(t[n.name]=n.enum[i],e.modified(),!0);throw Cu(`Set Enum with invalid argument ${n}, ${i}`),new RangeError("Set Enum with invalid string argument")}if("number"==typeof i){if(t[n.name]!==i){if(-1!==Object.keys(n.enum).map(e=>n.enum[e]).indexOf(i)){const o=t[n.name];return t[n.name]=i,t[r]?.(e,t,i,o),e.modified(),!0}throw Cu(`Set Enum outside numeric range ${n}, ${i}`),new RangeError("Set Enum outside numeric range")}return!1}throw Cu(`Set Enum with invalid argument (String/Number) ${n}, ${i}`),new TypeError("Set Enum with invalid argument (String/Number)")}},object(e,t,n){1===n.params?.length&&Ou('Setter of type "object" with a single "param" field is not supported');const r=`_on${_u(n.name)}Changed`;return function(){for(var i=arguments.length,o=new Array(i),a=0;a<i;a++)o[a]=arguments[a];let s;if(s=o.length>1&&n.params?.length?n.params.reduce((e,t,n)=>Object.assign(e,{[t]:o[n]}),{}):o[0],!Tl(t[n.name],s)){const i=t[n.name];return t[n.name]=s,t[r]?.(e,t,s,i),e.modified(),!0}return!1}}};function Wu(e){if("object"==typeof e){const t=Gu[e.type];if(t)return(n,r)=>t(n,r,e);throw Cu(`No setter for field ${e}`),new TypeError("No setter for field")}return function(t,n){const r=`_on${_u(e)}Changed`;return function(i){if(n.deleted)return Cu("instance deleted - cannot call any method"),!1;if(n[e]!==i){const o=n[e.name];return n[e]=i,n[r]?.(t,n,i,o),t.modified(),!0}return!1}}}function Xu(e,t,n){n.forEach(n=>{"object"==typeof n?e[`set${_u(n.name)}`]=Wu(n)(e,t):e[`set${_u(n)}`]=Wu(n)(e,t)})}function qu(e,t,n){Vu(e,t,n),Xu(e,t,n)}function Yu(e,t,n){n.forEach(n=>{e[`get${_u(n)}`]=()=>t[n]?Array.from(t[n]):t[n],e[`get${_u(n)}ByReference`]=()=>t[n]})}function Ku(e,t,n,r){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;n.forEach(n=>{if(t[n]&&r&&t[n].length!==r)throw new RangeError(`Invalid initial number of values for array (${n})`);const o=`_on${_u(n)}Changed`;e[`set${_u(n)}`]=function(){if(t.deleted)return Cu("instance deleted - cannot call any method"),!1;for(var a=arguments.length,s=new Array(a),c=0;c<a;c++)s[c]=arguments[c];let l,u=s,h=!1;if(1===u.length&&(null==u[0]||u[0].length>=0)&&(u=u[0],h=!0),null==u)l=t[n]!==u;else{if(r&&u.length!==r){if(!(u.length<r&&void 0!==i))throw new RangeError(`Invalid number of values for array setter (${n})`);for(u=Array.from(u),h=!1;u.length<r;)u.push(i)}l=null==t[n]||t[n].length!==u.length;for(let e=0;!l&&e<u.length;++e)l=t[n][e]!==u[e];l&&h&&(u=Array.from(u))}if(l){const r=t[n.name];t[n]=u,t[o]?.(e,t,u,r),e.modified()}return l},e[`set${_u(n)}From`]=e=>{const r=t[n];e.forEach((e,t)=>{r[t]=e})}})}function Qu(e,t,n,r){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;Yu(e,t,n),Ku(e,t,n,r,i)}function Zu(e,t,n){for(let e=0;e<n.length;e++){const r=n[e];void 0!==t[r]&&(t[`_${r}`]=t[r],delete t[r])}}function $u(e,t,n,r){function i(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;t.deleted?Cu("instance deleted - cannot call any method"):r>=t.numberOfInputs?Cu(`algorithm ${e.getClassName()} only has ${t.numberOfInputs} input ports. To add more input ports, use addInputData()`):(t.inputData[r]!==n||t.inputConnection[r])&&(t.inputData[r]=n,t.inputConnection[r]=null,e.modified&&e.modified())}function o(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(t.deleted)Cu("instance deleted - cannot call any method");else{if(r>=t.numberOfInputs){let n=`algorithm ${e.getClassName()} only has `;return n+=`${t.numberOfInputs}`,n+=" input ports. To add more input ports, use addInputConnection()",void Cu(n)}t.inputData[r]=null,t.inputConnection[r]=n}}function a(){let e=t.numberOfInputs;for(;e&&!t.inputData[e-1]&&!t.inputConnection[e-1];)e--;return e===t.numberOfInputs&&t.numberOfInputs++,e}function s(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return t.deleted?(Cu("instance deleted - cannot call any method"),null):(e.shouldUpdate()&&e.update(),t.output[n])}if(t.inputData?t.inputData=t.inputData.map(pu):t.inputData=[],t.inputConnection?t.inputConnection=t.inputConnection.map(pu):t.inputConnection=[],t.output?t.output=t.output.map(pu):t.output=[],t.inputArrayToProcess?t.inputArrayToProcess=t.inputArrayToProcess.map(pu):t.inputArrayToProcess=[],t.numberOfInputs=n,e.shouldUpdate=()=>{const n=e.getMTime();let i=1/0,o=r;for(;o--;){if(!t.output[o]||t.output[o].isDeleted())return!0;const e=t.output[o].getMTime();if(e<n)return!0;e<i&&(i=e)}for(o=t.numberOfInputs;o--;)if(t.inputConnection[o]?.filter.shouldUpdate()||e.getInputData(o)?.getMTime()>i)return!0;return!1},t.numberOfInputs){let n=t.numberOfInputs;for(;n--;)t.inputData.push(null),t.inputConnection.push(null);e.setInputData=i,e.setInputConnection=o,e.addInputData=function(e){t.deleted?Cu("instance deleted - cannot call any method"):i(e,a())},e.addInputConnection=function(e){t.deleted?Cu("instance deleted - cannot call any method"):o(e,a())},e.getInputData=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return t.inputConnection[e]&&(t.inputData[e]=t.inputConnection[e]()),t.inputData[e]},e.getInputConnection=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return t.inputConnection[e]}}r&&(e.getOutputData=s,e.getOutputPort=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;const n=()=>s(t);return n.filter=e,n}),e.update=()=>{const n=[];if(t.numberOfInputs){let r=0;for(;r<t.numberOfInputs;)n[r]=e.getInputData(r),r++}e.requestData&&e.shouldUpdate()&&e.requestData(n,t.output)},e.getNumberOfInputPorts=()=>t.numberOfInputs,e.getNumberOfOutputPorts=()=>r||t.output.length,e.getInputArrayToProcess=e=>{const n=t.inputArrayToProcess[e],r=t.inputData[e];return n&&r?r[`get${n.fieldAssociation}`]().getArray(n.arrayName):null},e.setInputArrayToProcess=function(e,n,r){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"Scalars";for(;t.inputArrayToProcess.length<e;)t.inputArrayToProcess.push(null);t.inputArrayToProcess[e]={arrayName:n,fieldAssociation:r,attributeType:i}}}const Ju=Symbol("Event abort");function eh(e,t,n){const r=[],i=e.delete;let o=1;function a(e){for(let t=0;t<r.length;++t){const[n]=r[t];if(n===e)return void r.splice(t,1)}}e[`invoke${_u(n)}`]=function(){if(t.deleted)return void Cu("instance deleted - cannot call any method");const n=r.slice();for(let t=0;t<n.length;++t){const[,r,i]=n[t];if(r)if(i<0)setTimeout(()=>r.apply(e,arguments),1-i);else{if(r.apply(e,arguments)===Ju)break}}},e[`on${_u(n)}`]=function(e){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!e.apply)return console.error(`Invalid callback for event ${n}`),null;if(t.deleted)return Cu("instance deleted - cannot call any method"),null;const s=o++;return r.push([s,e,i]),r.sort((e,t)=>t[2]-e[2]),function(e){return Object.freeze({unsubscribe:function(){a(e)}})}(s)},e.delete=()=>{i(),r.forEach(e=>{let[t]=e;return a(t)})}}function th(e,t){const n=function(){const t={};return e(t,{},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),Object.freeze(t)};return t&&pu.register(t,n),n}function nh(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return t.filter(e=>!!e).map(e=>e(...n))}}function rh(e){return e&&e.isA&&e.isA("vtkObject")}function ih(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];if(rh(e)){if(r.indexOf(e)>=0)return n;r.push(e);const i=t(e);void 0!==i&&n.push(i);const o=e.get();Object.keys(o).forEach(e=>{const i=o[e];Array.isArray(i)?i.forEach(e=>{ih(e,t,n,r)}):ih(i,t,n,r)})}return n}function oh(e,t,n){var r=this;let i;const o=function(){for(var o=arguments.length,a=new Array(o),s=0;s<o;s++)a[s]=arguments[s];const c=r,l=n&&!i;clearTimeout(i),i=setTimeout(()=>{i=null,n||e.apply(c,a)},t),l&&e.apply(c,a)};return o.cancel=()=>clearTimeout(i),o}function ah(e,t){let n=!1,r=null;function i(){n=!1,null!==r&&(o(...r),r=null)}function o(){for(var o=arguments.length,a=new Array(o),s=0;s<o;s++)a[s]=arguments[s];n?r=a:(n=!0,e(...a),setTimeout(i,t))}return o}function sh(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};t.keystore=Object.assign(t.keystore||{},n),e.setKey=(e,n)=>{t.keystore[e]=n},e.getKey=e=>t.keystore[e],e.getAllKeys=()=>Object.keys(t.keystore),e.deleteKey=e=>delete t.keystore[e],e.clearKeystore=()=>e.getAllKeys().forEach(e=>delete t.keystore[e])}let ch=1;const lh="__root__";function uh(e,t){sh(e,t);const n=e.delete;t.proxyId=""+ch++,t.ui=JSON.parse(JSON.stringify(t.ui||[])),Vu(e,t,["proxyId","proxyGroup","proxyName"]),qu(e,t,["proxyManager"]);const r={},i={};function o(e,t){i[t]||(i[t]=[]);const n=i[t];for(let t=0;t<e.length;t++)n.push(e[t].name),r[e[t].name]=e[t],e[t].children&&e[t].children.length&&o(e[t].children,e[t].name)}function a(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:lh;const r=[],o=t.proxyId,s=function(){return i[arguments.length>0&&void 0!==arguments[0]?arguments[0]:lh]}(n)||[];for(let t=0;t<s.length;t++){const n=s[t],i=e[`get${_u(n)}`],c={id:o,name:n,value:i?i():void 0},l=a(n);l.length&&(c.children=l),r.push(c)}return r}o(t.ui,lh),e.updateUI=n=>{t.ui=JSON.parse(JSON.stringify(n||[])),Object.keys(r).forEach(e=>delete r[e]),Object.keys(i).forEach(e=>delete i[e]),o(t.ui,lh),e.modified()},e.updateProxyProperty=(e,t)=>{const n=r[e];n?Object.assign(n,t):r[e]={...t}},e.activate=()=>{if(t.proxyManager){const n=`setActive${_u(e.getProxyGroup().slice(0,-1))}`;t.proxyManager[n]&&t.proxyManager[n](e)}},t.propertyLinkSubscribers={},e.registerPropertyLinkForGC=(e,n)=>{n in t.propertyLinkSubscribers||(t.propertyLinkSubscribers[n]=[]),t.propertyLinkSubscribers[n].push(e)},e.gcPropertyLinks=n=>{const r=t.propertyLinkSubscribers[n]||[];for(;r.length;)r.pop().unbind(e)},t.propertyLinkMap={},e.getPropertyLink=function(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t.propertyLinkMap[e])return t.propertyLinkMap[e];let r=null;const i=[];let o=0,a=!1;function s(n){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(a)return null;const c=[];let l=null;for(o=i.length;o--;){const e=i[o];e.instance===n?l=e:c.push(e)}if(!l)return null;const u=l.instance[`get${_u(l.propertyName)}`]();if(!function(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}return!1}(u,r)||s){for(r=u,a=!0;c.length;){const e=c.pop();e.instance.set({[e.propertyName]:r})}a=!1}return t.propertyLinkMap[e].persistent&&(t.propertyLinkMap[e].value=u),u}function c(e,t){const n=[];for(o=i.length;o--;){const r=i[o];r.instance!==e||r.propertyName!==t&&void 0!==t||(r.subscription.unsubscribe(),n.push(o))}for(;n.length;)i.splice(n.pop(),1)}const l={bind:function(n,r){let o=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const a=n.onModified(s),l=i[0];return i.push({instance:n,propertyName:r,subscription:a}),o&&(t.propertyLinkMap[e].persistent&&void 0!==t.propertyLinkMap[e].value?n.set({[r]:t.propertyLinkMap[e].value}):l&&s(l.instance,!0)),{unsubscribe:()=>c(n,r)}},unbind:c,unsubscribe:function(){for(;i.length;)i.pop().subscription.unsubscribe()},persistent:n};return t.propertyLinkMap[e]=l,l},e.listPropertyNames=()=>a().map(e=>e.name),e.getPropertyByName=e=>a().find(t=>t.name===e),e.getPropertyDomainByName=e=>(r[e]||{}).domain,e.getProxySection=()=>({id:t.proxyId,name:t.proxyGroup,ui:t.ui,properties:a()}),e.delete=()=>{const r=Object.keys(t.propertyLinkMap);let i=r.length;for(;i--;)t.propertyLinkMap[r[i]].unsubscribe();Object.keys(t.propertyLinkSubscribers).forEach(e.gcPropertyLinks),n()},e.getState=()=>null,Uu(function(){if(t.links)for(let n=0;n<t.links.length;n++){const{link:r,property:i,persistent:o,updateOnBind:a,type:s}=t.links[n];if("application"===s){const n=t.proxyManager.getPropertyLink(r,o);e.registerPropertyLinkForGC(n,"application"),n.bind(e,i,a)}}})}function hh(e,t,n){const r=e.delete,i=[],o=Object.keys(n);let a=o.length;for(;a--;){const r=o[a],{modelKey:s,property:c,modified:l=!0}=n[r],u=_u(c),h=_u(r);e[`get${h}`]=t[s][`get${u}`],e[`set${h}`]=t[s][`set${u}`],l&&i.push(t[s].onModified(e.modified))}e.delete=()=>{for(;i.length;)i.pop().unsubscribe();r()}}function dh(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};function i(e){const n=Object.keys(e);let r=n.length;for(;r--;){const i=n[r];t[i].set(e[i])}}t.this=e;const o=Object.keys(r);let a=o.length;for(;a--;){const s=o[a];t[s]=r[s];const c=n[s];e[`set${_u(s)}`]=n=>{if(n!==t[s]){t[s]=n;i(c[n]),e.modified()}}}o.length&&Vu(e,t,o)}function ph(e){let t=0,n=0,r=0,i=0;return"detail"in e&&(n=e.detail),"wheelDelta"in e&&(n=-e.wheelDelta/120),"wheelDeltaY"in e&&(n=-e.wheelDeltaY/120),"wheelDeltaX"in e&&(t=-e.wheelDeltaX/120),"axis"in e&&e.axis===e.HORIZONTAL_AXIS&&(t=n,n=0),r=10*t,i=10*n,"deltaY"in e&&(i=e.deltaY),"deltaX"in e&&(r=e.deltaX),(r||i)&&e.deltaMode&&(1===e.deltaMode?(r*=40,i*=40):(r*=800,i*=800)),r&&!t&&(t=r<1?-1:1),i&&!n&&(n=i<1?-1:1),{spinX:t,spinY:n||t,pixelX:r,pixelY:i||r}}var fh={algo:$u,capitalize:Pu,chain:nh,debounce:oh,enumToString:function(e,t){return Object.keys(e).find(n=>e[n]===t)},event:eh,EVENT_ABORT:Ju,formatBytesToProperUnit:Lu,formatNumbersWithThousandSeparator:Du,get:Vu,getArray:Yu,getCurrentGlobalMTime:function(){return mu},getStateArrayMapFunc:Fu,isVtkObject:rh,keystore:sh,measurePromiseExecution:Bu,moveToProtected:Zu,newInstance:th,newTypedArray:Mu,newTypedArrayFrom:Iu,normalizeWheel:ph,obj:zu,proxy:uh,proxyPropertyMapping:hh,proxyPropertyState:dh,safeArrays:ju,set:Xu,setArray:Ku,setGet:qu,setGetArray:Qu,setImmediate:Uu,setLoggerFunction:wu,throttle:ah,traverseInstanceTree:ih,TYPED_ARRAYS:Ru,uncapitalize:Nu,VOID:bu,vtkDebugMacro:Au,vtkErrorMacro:Cu,vtkInfoMacro:Tu,vtkLogMacro:Eu,vtkOnceErrorMacro:Su,vtkWarningMacro:Ou,objectSetterMap:Gu,requiredParam:gu},mh=Object.freeze({__proto__:null,requiredParam:gu,VOID:bu,setLoggerFunction:wu,vtkLogMacro:Eu,vtkInfoMacro:Tu,vtkDebugMacro:Au,vtkErrorMacro:Cu,vtkWarningMacro:Ou,vtkOnceErrorMacro:Su,TYPED_ARRAYS:Ru,newTypedArray:Mu,newTypedArrayFrom:Iu,capitalize:Pu,_capitalize:_u,uncapitalize:Nu,formatBytesToProperUnit:Lu,formatNumbersWithThousandSeparator:Du,setImmediateVTK:Uu,measurePromiseExecution:Bu,obj:zu,get:Vu,set:Xu,setGet:qu,getArray:Yu,setArray:Ku,setGetArray:Qu,moveToProtected:Zu,algo:$u,EVENT_ABORT:Ju,event:eh,newInstance:th,chain:nh,isVtkObject:rh,traverseInstanceTree:ih,debounce:oh,throttle:ah,keystore:sh,proxy:uh,proxyPropertyMapping:hh,proxyPropertyState:dh,normalizeWheel:ph,default:fh});const gh={VOID:"",CHAR:"Int8Array",SIGNED_CHAR:"Int8Array",UNSIGNED_CHAR:"Uint8Array",UNSIGNED_CHAR_CLAMPED:"Uint8ClampedArray",SHORT:"Int16Array",UNSIGNED_SHORT:"Uint16Array",INT:"Int32Array",UNSIGNED_INT:"Uint32Array",FLOAT:"Float32Array",DOUBLE:"Float64Array"};var bh={DefaultDataType:gh.FLOAT,DataTypeByteSize:{Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},VtkDataTypes:gh},yh={exports:{}};!function(e,t){function n(e){var t=this,n=function(){var e=4022871197,t=function(t){t=String(t);for(var n=0;n<t.length;n++){var r=.02519603282416938*(e+=t.charCodeAt(n));r-=e=r>>>0,e=(r*=e)>>>0,e+=4294967296*(r-=e)}return 2.3283064365386963e-10*(e>>>0)};return t}();t.next=function(){var e=2091639*t.s0+2.3283064365386963e-10*t.c;return t.s0=t.s1,t.s1=t.s2,t.s2=e-(t.c=0|e)},t.c=1,t.s0=n(" "),t.s1=n(" "),t.s2=n(" "),t.s0-=n(e),t.s0<0&&(t.s0+=1),t.s1-=n(e),t.s1<0&&(t.s1+=1),t.s2-=n(e),t.s2<0&&(t.s2+=1),n=null}function r(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function i(e,t){var i=new n(e),o=t&&t.state,a=i.next;return a.int32=function(){return 4294967296*i.next()|0},a.double=function(){return a()+11102230246251565e-32*(2097152*a()|0)},a.quick=a,o&&("object"==typeof o&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.alea=i}(0,yh);var vh=yh.exports,xh={exports:{}};!function(e,t){function n(e){var t=this,n="";t.x=0,t.y=0,t.z=0,t.w=0,t.next=function(){var e=t.x^t.x<<11;return t.x=t.y,t.y=t.z,t.z=t.w,t.w^=t.w>>>19^e^e>>>8},e===(0|e)?t.x=e:n+=e;for(var r=0;r<n.length+64;r++)t.x^=0|n.charCodeAt(r),t.next()}function r(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t}function i(e,t){var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&("object"==typeof o&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.xor128=i}(0,xh);var wh=xh.exports,Eh={exports:{}};!function(e,t){function n(e){var t=this,n="";t.next=function(){var e=t.x^t.x>>>2;return t.x=t.y,t.y=t.z,t.z=t.w,t.w=t.v,(t.d=t.d+362437|0)+(t.v=t.v^t.v<<4^e^e<<1)|0},t.x=0,t.y=0,t.z=0,t.w=0,t.v=0,e===(0|e)?t.x=e:n+=e;for(var r=0;r<n.length+64;r++)t.x^=0|n.charCodeAt(r),r==n.length&&(t.d=t.x<<10^t.x>>>4),t.next()}function r(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t.v=e.v,t.d=e.d,t}function i(e,t){var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&("object"==typeof o&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.xorwow=i}(0,Eh);var Th=Eh.exports,Ah={exports:{}};!function(e,t){function n(e){var t=this;t.next=function(){var e,n,r=t.x,i=t.i;return e=r[i],n=(e^=e>>>7)^e<<24,n^=(e=r[i+1&7])^e>>>10,n^=(e=r[i+3&7])^e>>>3,n^=(e=r[i+4&7])^e<<7,e=r[i+7&7],n^=(e^=e<<13)^e<<9,r[i]=n,t.i=i+1&7,n},function(e,t){var n,r=[];if(t===(0|t))r[0]=t;else for(t=""+t,n=0;n<t.length;++n)r[7&n]=r[7&n]<<15^t.charCodeAt(n)+r[n+1&7]<<13;for(;r.length<8;)r.push(0);for(n=0;n<8&&0===r[n];++n);for(8==n?r[7]=-1:r[n],e.x=r,e.i=0,n=256;n>0;--n)e.next()}(t,e)}function r(e,t){return t.x=e.x.slice(),t.i=e.i,t}function i(e,t){null==e&&(e=+new Date);var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&(o.x&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.xorshift7=i}(0,Ah);var Ch=Ah.exports,Oh={exports:{}};!function(e,t){function n(e){var t=this;t.next=function(){var e,n,r=t.w,i=t.X,o=t.i;return t.w=r=r+1640531527|0,n=i[o+34&127],e=i[o=o+1&127],n^=n<<13,e^=e<<17,n^=n>>>15,e^=e>>>12,n=i[o]=n^e,t.i=o,n+(r^r>>>16)|0},function(e,t){var n,r,i,o,a,s=[],c=128;for(t===(0|t)?(r=t,t=null):(t+="\0",r=0,c=Math.max(c,t.length)),i=0,o=-32;o<c;++o)t&&(r^=t.charCodeAt((o+32)%t.length)),0===o&&(a=r),r^=r<<10,r^=r>>>15,r^=r<<4,r^=r>>>13,o>=0&&(a=a+1640531527|0,i=0==(n=s[127&o]^=r+a)?i+1:0);for(i>=128&&(s[127&(t&&t.length||0)]=-1),i=127,o=512;o>0;--o)r=s[i+34&127],n=s[i=i+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[i]=r^n;e.w=a,e.X=s,e.i=i}(t,e)}function r(e,t){return t.i=e.i,t.w=e.w,t.X=e.X.slice(),t}function i(e,t){null==e&&(e=+new Date);var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&(o.X&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.xor4096=i}(0,Oh);var kh=Oh.exports,Sh={exports:{}};!function(e,t){function n(e){var t=this,n="";t.next=function(){var e=t.b,n=t.c,r=t.d,i=t.a;return e=e<<25^e>>>7^n,n=n-r|0,r=r<<24^r>>>8^i,i=i-e|0,t.b=e=e<<20^e>>>12^n,t.c=n=n-r|0,t.d=r<<16^n>>>16^i,t.a=i-e|0},t.a=0,t.b=0,t.c=-1640531527,t.d=1367130551,e===Math.floor(e)?(t.a=e/4294967296|0,t.b=0|e):n+=e;for(var r=0;r<n.length+20;r++)t.b^=0|n.charCodeAt(r),t.next()}function r(e,t){return t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t}function i(e,t){var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&("object"==typeof o&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.tychei=i}(0,Sh);var Rh,Mh=Sh.exports,Ih={exports:{}},Ph=vl(Object.freeze({__proto__:null,default:{}}));Rh=Ih,function(e,t,n){var r,i=256,o="random",a=n.pow(i,6),s=n.pow(2,52),c=2*s,l=255;function u(l,u,g){var b=[],y=f(p((u=1==u?{entropy:!0}:u||{}).entropy?[l,m(t)]:null==l?function(){try{var n;return r&&(n=r.randomBytes)?n=n(i):(n=new Uint8Array(i),(e.crypto||e.msCrypto).getRandomValues(n)),m(n)}catch(n){var o=e.navigator,a=o&&o.plugins;return[+new Date,e,a,e.screen,m(t)]}}():l,3),b),v=new h(b),x=function(){for(var e=v.g(6),t=a,n=0;e<s;)e=(e+n)*i,t*=i,n=v.g(1);for(;e>=c;)e/=2,t/=2,n>>>=1;return(e+n)/t};return x.int32=function(){return 0|v.g(4)},x.quick=function(){return v.g(4)/4294967296},x.double=x,f(m(v.S),t),(u.pass||g||function(e,t,r,i){return i&&(i.S&&d(i,v),e.state=function(){return d(v,{})}),r?(n[o]=e,t):e})(x,y,"global"in u?u.global:this==n,u.state)}function h(e){var t,n=e.length,r=this,o=0,a=r.i=r.j=0,s=r.S=[];for(n||(e=[n++]);o<i;)s[o]=o++;for(o=0;o<i;o++)s[o]=s[a=l&a+e[o%n]+(t=s[o])],s[a]=t;(r.g=function(e){for(var t,n=0,o=r.i,a=r.j,s=r.S;e--;)t=s[o=l&o+1],n=n*i+s[l&(s[o]=s[a=l&a+t])+(s[a]=t)];return r.i=o,r.j=a,n})(i)}function d(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function p(e,t){var n,r=[],i=typeof e;if(t&&"object"==i)for(n in e)try{r.push(p(e[n],t-1))}catch(e){}return r.length?r:"string"==i?e:e+"\0"}function f(e,t){for(var n,r=e+"",i=0;i<r.length;)t[l&i]=l&(n^=19*t[l&i])+r.charCodeAt(i++);return m(t)}function m(e){return String.fromCharCode.apply(0,e)}if(f(n.random(),t),Rh.exports){Rh.exports=u;try{r=Ph}catch(e){}}else n["seed"+o]=u}("undefined"!=typeof self?self:bl,[],Math);var _h=vh,Nh=wh,Lh=Th,Dh=Ch,jh=kh,Fh=Mh,Uh=Ih.exports;Uh.alea=_h,Uh.xor128=Nh,Uh.xorwow=Lh,Uh.xorshift7=Dh,Uh.xor4096=jh,Uh.tychei=Fh;const{vtkErrorMacro:Bh,vtkWarningMacro:zh}=fh;function Hh(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3;const t=Array(e);for(let n=0;n<e;++n)t[n]=0;return t}function Vh(e,t,n){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n}function Gh(e,t,n,r){return r[0]=e[0]+t[0]*n,r[1]=e[1]+t[1]*n,r[2]=e[2]+t[2]*n,r}function Wh(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Xh(e,t,n){const r=e[1]*t[2]-e[2]*t[1],i=e[2]*t[0]-e[0]*t[2],o=e[0]*t[1]-e[1]*t[0];return n[0]=r,n[1]=i,n[2]=o,n}function qh(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3;switch(t){case 1:return Math.abs(e);case 2:return Math.sqrt(e[0]*e[0]+e[1]*e[1]);case 3:return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);default:{let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}}}function Yh(e,t){return(e[0]-t[0])*(e[0]-t[0])+(e[1]-t[1])*(e[1]-t[1])+(e[2]-t[2])*(e[2]-t[2])}function Kh(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 2===t.length?t[0][0]*t[1][1]-t[1][0]*t[0][1]:4===t.length?t[0]*t[3]-t[1]*t[2]:Number.NaN}function Qh(e,t,n){if(2===n){const n=Hh(2),r=Kh(e[0],e[1],e[2],e[3]);return 0===r?0:(n[0]=(e[3]*t[0]-e[1]*t[1])/r,n[1]=(-e[2]*t[0]+e[0]*t[1])/r,t[0]=n[0],t[1]=n[1],1)}if(1===n)return 0===e[0]?0:(t[0]/=e[0],1);const r=Hh(n);return 0===function(e,t,n){let r,i,o,a,s,c,l,u=0;const h=Hh(n);for(r=0;r<n;r++){for(a=0,i=0;i<n;i++)(l=Math.abs(e[r*n+i]))>a&&(a=l);if(0===a)return zh("Unable to factor linear system"),0;h[r]=1/a}for(i=0;i<n;i++){for(r=0;r<i;r++){for(s=e[r*n+i],o=0;o<r;o++)s-=e[r*n+o]*e[o*n+i];e[r*n+i]=s}for(a=0,r=i;r<n;r++){for(s=e[r*n+i],o=0;o<i;o++)s-=e[r*n+o]*e[o*n+i];e[r*n+i]=s,(c=h[r]*Math.abs(s))>=a&&(a=c,u=r)}if(i!==u){for(o=0;o<n;o++)c=e[u*n+o],e[u*n+o]=e[i*n+o],e[i*n+o]=c;h[u]=h[i]}if(t[i]=u,Math.abs(e[i*n+i])<=1e-12)return zh("Unable to factor linear system"),0;if(i!==n-1)for(c=1/e[i*n+i],r=i+1;r<n;r++)e[r*n+i]*=c}return 1}(e,r,n)?0:(function(e,t,n,r){let i,o,a,s,c;for(a=-1,i=0;i<r;i++){if(s=t[i],c=n[s],n[s]=n[i],a>=0)for(o=a;o<=i-1;o++)c-=e[i*r+o]*n[o];else 0!==c&&(a=i);n[i]=c}for(i=r-1;i>=0;i--){for(c=n[i],o=i+1;o<r;o++)c-=e[i*r+o]*n[o];n[i]=c/e[i*r+i]}}(e,r,t,n),1)}const{vtkErrorMacro:Zh}=mh,{DefaultDataType:$h}=bh;function Jh(e,t,n){const r=e.length;let i,o,a=Number.MAX_VALUE,s=-Number.MAX_VALUE;for(o=t;o<r;o+=n)if(!Number.isNaN(e[o])){a=e[o],s=a;break}for(;o<r;o+=n)i=e[o],i<a?a=i:i>s&&(s=i);return{min:a,max:s}}function ed(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;if(t<0&&n>1){const t=e.length/n,r=new Float64Array(t);for(let i=0,o=0;i<t;++i){for(let t=o+n;o<t;++o)r[i]+=e[o]*e[o];r[i]**=.5}return Jh(r,0,1)}return Jh(e,t<0?0:t,n)}function td(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;const n=e||[];for(;n.length<=t;)n.push(null);return n}function nd(e){return Object.prototype.toString.call(e).slice(8,-1)}const rd={computeRange:ed,createRangeHelper:function(){let e=Number.MAX_VALUE,t=-Number.MAX_VALUE,n=0,r=0;return{add(i){e>i&&(e=i),t<i&&(t=i),n++,r+=i},get:()=>({min:e,max:t,count:n,sum:r,mean:r/n}),getRange:()=>({min:e,max:t})}},fastComputeRange:Jh,getDataType:nd,getMaxNorm:function(e){const t=e.getNumberOfComponents();let n=0;const r=new Array(t);for(let i=0;i<e.getNumberOfTuples();++i){e.getTuple(i,r);const o=qh(r,t);o>n&&(n=o)}return n}};const id={name:"",numberOfComponents:1,dataType:$h,rangeTuple:[0,0]};function od(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(Object.assign(t,id,n),Array.isArray(n.values)&&void 0===n.dataType&&console.warn("vtkDataArray.newInstance: no dataType provided, converting to Float32Array"),!t.empty&&!t.values&&!t.size)throw new TypeError("Cannot create vtkDataArray object without: size > 0, values");if(t.values?Array.isArray(t.values)&&(t.values=Iu(t.dataType,t.values)):t.values=Mu(t.dataType,t.size),t.values&&(t.size=t.size??t.values.length,t.dataType=nd(t.values)),zu(e,t),Xu(e,t,["name","numberOfComponents"]),t.size%t.numberOfComponents!==0)throw new RangeError("model.size is not a multiple of model.numberOfComponents");!function(e,t){function n(n){if(n<0)return!1;const r=e.getNumberOfComponents(),i=t.values.length/(r>0?r:1);if(n===i)return!0;if(n>i){const e=t.values;return t.values=Mu(t.dataType,(n+i)*r),t.values.set(e),!0}return t.size>n*r&&(t.size=n*r,e.dataChange()),!0}t.classHierarchy.push("vtkDataArray"),e.dataChange=()=>{t.ranges=null,e.modified()},e.resize=r=>{n(r);const i=r*e.getNumberOfComponents();return t.size!==i&&(t.size=i,e.dataChange(),!0)},e.initialize=()=>{e.resize(0)},e.getElementComponentSize=()=>t.values.BYTES_PER_ELEMENT,e.getComponent=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return t.values[e*t.numberOfComponents+n]},e.setComponent=(n,r,i)=>{i!==t.values[n*t.numberOfComponents+r]&&(t.values[n*t.numberOfComponents+r]=i,e.dataChange())},e.getValue=n=>{const r=n/t.numberOfComponents,i=n%t.numberOfComponents;return e.getComponent(r,i)},e.setValue=(n,r)=>{const i=n/t.numberOfComponents,o=n%t.numberOfComponents;e.setComponent(i,o,r)},e.getData=()=>t.size===t.values.length?t.values:t.values.subarray(0,t.size),e.getRange=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1,r=n;r<0&&(r=1===t.numberOfComponents?0:t.numberOfComponents);let i=null;return t.ranges||(t.ranges=td(t.ranges,t.numberOfComponents)),i=t.ranges[r],i?(t.rangeTuple[0]=i.min,t.rangeTuple[1]=i.max,t.rangeTuple):(i=ed(e.getData(),n,t.numberOfComponents),t.ranges[r]=i,t.rangeTuple[0]=i.min,t.rangeTuple[1]=i.max,t.rangeTuple)},e.setRange=(e,n)=>{t.ranges||(t.ranges=td(t.ranges,t.numberOfComponents));const r={min:e.min,max:e.max};return t.ranges[n]=r,t.rangeTuple[0]=r.min,t.rangeTuple[1]=r.max,t.rangeTuple},e.getRanges=function(){if(arguments.length>0&&void 0!==arguments[0]&&!arguments[0])return structuredClone(t.ranges);const n=[];for(let r=0;r<t.numberOfComponents;r++){const[t,i]=e.getRange(r),o={min:t,max:i};n.push(o)}if(t.numberOfComponents>1){const[t,r]=e.getRange(-1),i={min:t,max:r};n.push(i)}return n},e.setTuple=(e,n)=>{const r=e*t.numberOfComponents;for(let e=0;e<t.numberOfComponents;e++)t.values[r+e]=n[e]},e.setTuples=(e,n)=>{let r=e*t.numberOfComponents;const i=Math.min(n.length,t.size-r);for(let e=0;e<i;)t.values[r++]=n[e++]},e.insertTuple=(r,i)=>(t.size<=r*t.numberOfComponents&&(t.size=(r+1)*t.numberOfComponents,n(r+1)),e.setTuple(r,i),r),e.insertTuples=(r,i)=>{const o=r+i.length/t.numberOfComponents;return t.size<o*t.numberOfComponents&&(t.size=o*t.numberOfComponents,n(o)),e.setTuples(r,i),o},e.insertNextTuple=n=>{const r=t.size/t.numberOfComponents;return e.insertTuple(r,n)},e.insertNextTuples=n=>{const r=t.size/t.numberOfComponents;return e.insertTuples(r,n)},e.findTuple=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-6;for(let r=0;r<t.size;r+=t.numberOfComponents)if(Math.abs(e[0]-t.values[r])<=n){let i=!0;for(let o=1;o<t.numberOfComponents;++o)if(Math.abs(e[o]-t.values[r+o])>n){i=!1;break}if(i)return r/t.numberOfComponents}return-1},e.getTuple=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];const r=t.numberOfComponents||1,i=e*r;switch(r){case 4:n[3]=t.values[i+3];case 3:n[2]=t.values[i+2];case 2:n[1]=t.values[i+1];case 1:n[0]=t.values[i];break;default:for(let e=r-1;e>=0;--e)n[e]=t.values[i+e]}return n},e.getTuples=(n,r)=>{const i=(n??0)*t.numberOfComponents,o=(r??e.getNumberOfTuples())*t.numberOfComponents,a=e.getData().subarray(i,o);return a.length>0?a:null},e.getTupleLocation=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:1)*t.numberOfComponents},e.getNumberOfComponents=()=>t.numberOfComponents,e.getNumberOfValues=()=>t.size,e.getNumberOfTuples=()=>t.size/t.numberOfComponents,e.getDataType=()=>t.dataType,e.newClone=()=>ad({empty:!0,name:t.name,dataType:t.dataType,numberOfComponents:t.numberOfComponents}),e.getName=()=>(t.name||(e.modified(),t.name=`vtkDataArray${e.getMTime()}`),t.name),e.setData=(n,r)=>{t.values=n,t.size=n.length,t.dataType=nd(n),r&&(t.numberOfComponents=r),t.size%t.numberOfComponents!==0&&(t.numberOfComponents=1),e.dataChange()},e.getState=()=>{if(t.deleted)return null;const n={...t,vtkClass:e.getClassName()};n.values=Array.from(n.values),delete n.buffer,Object.keys(n).forEach(e=>{n[e]||delete n[e]});const r={};return Object.keys(n).sort().forEach(e=>{r[e]=n[e]}),r.mtime&&delete r.mtime,r},e.deepCopy=n=>{const r=e.getDataType(),i=t.values;e.shallowCopy(n),t.ranges=structuredClone(n.getRanges()),i?.length>=n.getNumberOfValues()&&r===n.getDataType()?(i.set(n.getData()),t.values=i,e.dataChange()):e.setData(n.getData().slice())},e.interpolateTuple=(n,r,i,o,a,s)=>{const c=t.numberOfComponents||1;c===r.getNumberOfComponents()&&c===o.getNumberOfComponents()||Zh("numberOfComponents must match");const l=r.getTuple(i),u=o.getTuple(a),h=[];switch(h.length=c,c){case 4:h[3]=l[3]+(u[3]-l[3])*s;case 3:h[2]=l[2]+(u[2]-l[2])*s;case 2:h[1]=l[1]+(u[1]-l[1])*s;case 1:h[0]=l[0]+(u[0]-l[0])*s;break;default:for(let e=0;e<c;e++)h[e]=l[e]+(u[e]-l[e])*s}return e.insertTuple(n,h)}}(e,t)}const ad=th(od,"vtkDataArray");var sd={newInstance:ad,extend:od,...rd,...bh};const{vtkErrorMacro:cd}=fh,ld=[1,-1,1,-1,1,-1];const ud={empty:!0,numberOfComponents:3,dataType:gh.FLOAT,bounds:[1,-1,1,-1,1,-1]};function hd(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,ud,n),sd.extend(e,t,n),function(e,t){t.classHierarchy.push("vtkPoints"),e.getNumberOfPoints=e.getNumberOfTuples,e.setNumberOfPoints=function(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3;e.getNumberOfPoints()!==n&&(t.size=n*r,t.values=fh.newTypedArray(t.dataType,t.size),e.setNumberOfComponents(r),e.modified())},e.setPoint=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];e.setTuple(t,r)},e.getPoint=e.getTuple,e.findPoint=e.findTuple,e.insertNextPoint=(t,n,r)=>e.insertNextTuple([t,n,r]),e.getBounds=()=>{if(3===e.getNumberOfComponents()){const n=e.getRange(0);t.bounds[0]=n[0],t.bounds[1]=n[1];const r=e.getRange(1);t.bounds[2]=r[0],t.bounds[3]=r[1];const i=e.getRange(2);return t.bounds[4]=i[0],t.bounds[5]=i[1],t.bounds}if(2!==e.getNumberOfComponents())return cd(`getBounds called on an array with components of\n ${e.getNumberOfComponents()}`),ld;const n=e.getRange(0);t.bounds[0]=n[0],t.bounds[1]=n[1];const r=e.getRange(1);return t.bounds[2]=r[0],t.bounds[3]=r[1],t.bounds[4]=0,t.bounds[5]=0,t.bounds},e.computeBounds=e.getBounds,e.setNumberOfComponents(t.numberOfComponents<2?3:t.numberOfComponents)}(e,t)}var dd={newInstance:fh.newInstance(hd,"vtkPoints"),extend:hd};function pd(e){let t=0;return e.filter((e,n)=>n===t&&(t+=e+1,!0))}function fd(e){let t=0;for(let n=0;n<e.length;)n+=e[n]+1,t++;return t}const md={extractCellSizes:pd,getNumberOfCells:fd};function gd(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};sd.extend(e,t,function(e){return{empty:!0,numberOfComponents:1,dataType:gh.UNSIGNED_INT,...e}}(n)),function(e,t){t.classHierarchy.push("vtkCellArray");const n={...e};e.getNumberOfCells=n=>void 0===t.numberOfCells||n?(t.cellSizes?t.numberOfCells=t.cellSizes.length:t.numberOfCells=fd(e.getData()),t.numberOfCells):t.numberOfCells,e.getCellSizes=n=>void 0===t.cellSizes||n?(t.cellSizes=pd(e.getData()),t.cellSizes):t.cellSizes,e.resize=r=>{const i=e.getNumberOfTuples();n.resize(r);const o=e.getNumberOfTuples();o<i&&(0===o?(t.numberOfCells=0,t.cellSizes=[]):(t.numberOfCells=void 0,t.cellSizes=void 0))},e.setData=e=>{n.setData(e,1),t.numberOfCells=void 0,t.cellSizes=void 0},e.getCell=e=>{let n=e;const r=t.values[n++];return t.values.subarray(n,n+r)},e.insertNextCell=n=>{const r=e.getNumberOfCells();return e.insertNextTuples([n.length,...n]),++t.numberOfCells,null!=t.cellSizes&&t.cellSizes.push(n.length),r}}(e,t)}var bd={newInstance:fh.newInstance(gd,"vtkCellArray"),extend:gd,...md};const yd={bounds:[-1,-1,-1,-1,-1,-1],pointsIds:[]};function vd(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,yd,n),fh.obj(e,t),t.points||(t.points=dd.newInstance()),fh.get(e,t,["points","pointsIds"]),function(e,t){t.classHierarchy.push("vtkCell"),e.initialize=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(n){t.pointsIds=n;let r=t.points.getData();r.length!==3*t.pointsIds.length&&(r=fh.newTypedArray(e.getDataType(),3*t.pointsIds.length));const i=e.getData();t.pointsIds.forEach((e,t)=>{let n=3*e,o=3*t;r[o]=i[n],r[++o]=i[++n],r[++o]=i[++n]}),t.points.setData(r)}else{t.points=e,t.pointsIds=new Array(e.getNumberOfPoints());for(let n=e.getNumberOfPoints()-1;n>=0;--n)t.pointsIds[n]=n}},e.getBounds=()=>{const e=t.points.getNumberOfPoints(),n=[];if(e){t.points.getPoint(0,n),t.bounds[0]=n[0],t.bounds[1]=n[0],t.bounds[2]=n[1],t.bounds[3]=n[1],t.bounds[4]=n[2],t.bounds[5]=n[2];for(let r=1;r<e;r++)t.points.getPoint(r,n),t.bounds[0]=n[0]<t.bounds[0]?n[0]:t.bounds[0],t.bounds[1]=n[0]>t.bounds[1]?n[0]:t.bounds[1],t.bounds[2]=n[1]<t.bounds[2]?n[1]:t.bounds[2],t.bounds[3]=n[1]>t.bounds[3]?n[1]:t.bounds[3],t.bounds[4]=n[2]<t.bounds[4]?n[2]:t.bounds[4],t.bounds[5]=n[2]>t.bounds[5]?n[2]:t.bounds[5]}else(r=t.bounds)[0]=1,r[1]=-1,r[2]=1,r[3]=-1,r[4]=1,r[5]=-1;var r;return t.bounds},e.getLength2=()=>{e.getBounds();let n=0,r=0;for(let e=0;e<3;e++)r=t.bounds[2*e+1]-t.bounds[2*e],n+=r*r;return n},e.getParametricDistance=e=>{let t,n=0;for(let r=0;r<3;r++)t=e[r]<0?-e[r]:e[r]>1?e[r]-1:0,t>n&&(n=t);return n},e.getNumberOfPoints=()=>t.points.getNumberOfPoints(),e.deepCopy=e=>{e.initialize(t.points,t.pointsIds)},e.getCellDimension=()=>{},e.intersectWithLine=(e,t,n,r,i,o,a)=>{},e.evaluatePosition=(e,t,n,r,i,o)=>{fh.vtkErrorMacro("vtkCell.evaluatePosition is not implemented.")}}(e,t)}var xd={newInstance:fh.newInstance(vd,"vtkCell"),extend:vd};const wd={array:null,maxId:0,extend:0};function Ed(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,wd,n),fh.obj(e,t),function(e,t){t.classHierarchy.push("vtkCellLinks"),e.buildLinks=n=>{const r=n.getPoints().getNumberOfPoints(),i=n.getNumberOfCells(),o=new Uint32Array(r);if(n.isA("vtkPolyData")){for(let t=0;t<i;++t){const{cellPointIds:r}=n.getCellPoints(t);r.forEach(t=>{e.incrementLinkCount(t)})}e.allocateLinks(r),t.maxId=r-1;for(let t=0;t<i;++t){const{cellPointIds:r}=n.getCellPoints(t);r.forEach(n=>{e.insertCellReference(n,o[n]++,t)})}}else{for(let t=0;t<i;t++)xd.newInstance().getPointsIds().forEach(t=>{e.incrementLinkCount(t)});e.allocateLinks(r),t.maxId=r-1;for(let t=0;t<i;++t)xd.newInstance().getPointsIds().forEach(n=>{e.insertCellReference(n,o[n]++,t)})}},e.allocate=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3;t.array=Array(e).fill().map(()=>({ncells:0,cells:null})),t.extend=n,t.maxId=-1},e.initialize=()=>{t.array=null},e.getLink=e=>t.array[e],e.getNcells=e=>t.array[e].ncells,e.getCells=e=>t.array[e].cells,e.insertNextPoint=e=>{t.array.push({ncells:e,cells:Array(e)}),++t.maxId},e.insertNextCellReference=(e,n)=>{t.array[e].cells[t.array[e].ncells++]=n},e.deletePoint=e=>{t.array[e].ncells=0,t.array[e].cells=null},e.removeCellReference=(e,n)=>{t.array[n].cells=t.array[n].cells.filter(t=>t!==e),t.array[n].ncells=t.array[n].cells.length},e.addCellReference=(e,n)=>{t.array[n].cells[t.array[n].ncells++]=e},e.resizeCellList=(e,n)=>{t.array[e].cells.length=n},e.squeeze=()=>{!function(e,t){let n=t;for(t>=e.array.length&&(n+=e.array.length);n>e.array.length;)e.array.push({ncells:0,cells:null});e.array.length=n}(t,t.maxId+1)},e.reset=()=>{t.maxId=-1},e.deepCopy=e=>{t.array=[...e.array],t.extend=e.extend,t.maxId=e.maxId},e.incrementLinkCount=e=>{++t.array[e].ncells},e.allocateLinks=e=>{for(let n=0;n<e;++n)t.array[n].cells=new Array(t.array[n].ncells)},e.insertCellReference=(e,n,r)=>{t.array[e].cells[n]=r}}(e,t)}var Td={newInstance:fh.newInstance(Ed,"vtkCellLinks"),extend:Ed};const Ad=0,Cd=1,Od=2,kd=3,Sd=4,Rd=5,Md=6,Id=7,Pd=9,_d=21,Nd=41,Ld=42,Dd=["vtkEmptyCell","vtkVertex","vtkPolyVertex","vtkLine","vtkPolyLine","vtkTriangle","vtkTriangleStrip","vtkPolygon","vtkPixel","vtkQuad","vtkTetra","vtkVoxel","vtkHexahedron","vtkWedge","vtkPyramid","vtkPentagonalPrism","vtkHexagonalPrism","UnknownClass","UnknownClass","UnknownClass","UnknownClass","vtkQuadraticEdge","vtkQuadraticTriangle","vtkQuadraticQuad","vtkQuadraticTetra","vtkQuadraticHexahedron","vtkQuadraticWedge","vtkQuadraticPyramid","vtkBiQuadraticQuad","vtkTriQuadraticHexahedron","vtkQuadraticLinearQuad","vtkQuadraticLinearWedge","vtkBiQuadraticQuadraticWedge","vtkBiQuadraticQuadraticHexahedron","vtkBiQuadraticTriangle","vtkCubicLine","vtkQuadraticPolygon","UnknownClass","UnknownClass","UnknownClass","UnknownClass","vtkConvexPointSet","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","vtkParametricCurve","vtkParametricSurface","vtkParametricTriSurface","vtkParametricQuadSurface","vtkParametricTetraRegion","vtkParametricHexRegion","UnknownClass","UnknownClass","UnknownClass","vtkHigherOrderEdge","vtkHigherOrderTriangle","vtkHigherOrderQuad","vtkHigherOrderPolygon","vtkHigherOrderTetrahedron","vtkHigherOrderWedge","vtkHigherOrderPyramid","vtkHigherOrderHexahedron"];const jd={getClassNameFromTypeId:function(e){return e<Dd.length?Dd[e]:"UnknownClass"},getTypeIdFromClassName:function(e){return Dd.findIndex(e)},isLinear:function(e){return e<_d||e===Nd||e===Ld},hasSubCells:function(e){return e===Md||e===Sd||e===Od}};const Fd={size:0,maxId:-1,extend:1e3};function Ud(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Fd,n),fh.obj(e,t),fh.get(e,t,["size","maxId","extend"]),fh.getArray(e,t,["typeArray","locationArray"]),function(e,t){t.classHierarchy.push("vtkCellTypes"),e.allocate=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:512,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3;t.size=e>0?e:1,t.extend=n>0?n:1,t.maxId=-1,t.typeArray=new Uint8Array(e),t.locationArray=new Uint32Array(e)},e.insertCell=(e,n,r)=>{t.typeArray[e]=n,t.locationArray[e]=r,e>t.maxId&&(t.maxId=e)},e.insertNextCell=(n,r)=>(e.insertCell(++t.maxId,n,r),t.maxId),e.setCellTypes=(e,n,r)=>{t.size=e,t.typeArray=n,t.locationArray=r,t.maxId=e-1},e.getCellLocation=e=>t.locationArray[e],e.deleteCell=e=>{t.typeArray[e]=Ad},e.getNumberOfTypes=()=>t.maxId+1,e.isType=t=>{const n=e.getNumberOfTypes();for(let r=0;r<n;++r)if(t===e.getCellType(r))return!0;return!1},e.insertNextType=t=>e.insertNextCell(t,-1),e.getCellType=e=>t.typeArray[e],e.reset=()=>{t.maxId=-1},e.deepCopy=n=>{e.allocate(n.getSize(),n.getExtend()),t.typeArray.set(n.getTypeArray()),t.locationArray.set(n.getLocationArray()),t.maxId=n.getMaxId()}}(e,t)}var Bd={newInstance:fh.newInstance(Ud,"vtkCellTypes"),extend:Ud,...jd};var zd={IntersectionState:{NO_INTERSECTION:0,YES_INTERSECTION:1,ON_LINE:2}},Hd="undefined"!=typeof Float32Array?Float32Array:Array;function Vd(){var e=new Hd(3);return Hd!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Gd(e,t,n){var r=new Hd(3);return r[0]=e,r[1]=t,r[2]=n,r}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function Wd(){var e=new Hd(4);return Hd!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function Xd(e,t,n,r){var i,o,a,s,c,l=t[0],u=t[1],h=t[2],d=t[3],p=n[0],f=n[1],m=n[2],g=n[3];return(o=l*p+u*f+h*m+d*g)<0&&(o=-o,p=-p,f=-f,m=-m,g=-g),1-o>1e-6?(i=Math.acos(o),a=Math.sin(i),s=Math.sin((1-r)*i)/a,c=Math.sin(r*i)/a):(s=1-r,c=r),e[0]=s*l+c*p,e[1]=s*u+c*f,e[2]=s*h+c*m,e[3]=s*d+c*g,e}Vd(),function(){var e,t=(e=new Hd(4),Hd!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var qd;Vd(),Gd(1,0,0),Gd(0,1,0),function(){var e=Wd(),t=Wd()}(),qd=new Hd(9),Hd!=Float32Array&&(qd[1]=0,qd[2]=0,qd[3]=0,qd[5]=0,qd[6]=0,qd[7]=0),qd[0]=1,qd[4]=1,qd[8]=1;const{IntersectionState:Yd}=zd;function Kd(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;const i={t:Number.MIN_VALUE,distance:0},o=[];let a;o[0]=n[0]-t[0],o[1]=n[1]-t[1],o[2]=n[2]-t[2];const s=o[0]*(e[0]-t[0])+o[1]*(e[1]-t[1])+o[2]*(e[2]-t[2]),c=Wh(o,o);let l=1e-5*s;return 0!==c&&(i.t=s/c),l<0&&(l=-l),-l<c&&c<l||c<=0||i.t<0?a=t:i.t>1?a=n:(a=o,o[0]=t[0]+i.t*o[0],o[1]=t[1]+i.t*o[1],o[2]=t[2]+i.t*o[2]),r&&(r[0]=a[0],r[1]=a[1],r[2]=a[2]),i.distance=Yh(a,e),i}function Qd(e,t,n,r,i,o){const a=[],s=[],c=[];i[0]=0,o[0]=0,Vh(t,e,a),Vh(r,n,s),Vh(n,e,c);const l=[Wh(a,a),-Wh(a,s),-Wh(a,s),Wh(s,s)],u=[];if(u[0]=Wh(a,c),u[1]=-Wh(s,c),0===Qh(l,u,2)){let a=Number.MAX_VALUE;const s=[e,t,n,r],c=[n,n,e,e],l=[r,r,t,t];let u;o[0],o[0],i[0],i[0],i[0],i[0],o[0],o[0];for(let e=0;e<4;e++)u=Kd(s[e],c[e],l[e]),u.distance<a&&(a=u.distance,u.t);return Yd.ON_LINE}return i[0]=u[0],o[0]=u[1],i[0]>=0&&i[0]<=1&&o[0]>=0&&o[0]<=1?Yd.YES_INTERSECTION:Yd.NO_INTERSECTION}const Zd={distanceToLine:Kd,intersection:Qd};const $d={orientations:null};function Jd(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,$d,n),xd.extend(e,t,n),fh.setGet(e,t,["orientations"]),function(e,t){t.classHierarchy.push("vtkLine"),e.getCellDimension=()=>1,e.intersectWithLine=(e,n,r,i,o)=>{const a={intersect:0,t:Number.MAX_VALUE,subId:0,betweenPoints:null};o[1]=0,o[2]=0;const s=[],c=[],l=[];t.points.getPoint(0,c),t.points.getPoint(1,l);const u=[],h=[],d=Qd(e,n,c,l,u,h);var p;if(a.t=u[0],a.betweenPoints=(p=a.t)>=0&&p<=1,o[0]=h[0],d===Yd.YES_INTERSECTION){for(let t=0;t<3;t++)i[t]=c[t]+o[0]*(l[t]-c[t]),s[t]=e[t]+a.t*(n[t]-e[t]);if(Yh(i,s)<=r*r)return a.intersect=1,a}else{let t;if(a.t<0)return t=Kd(e,c,l,i),t.distance<=r*r?(a.t=0,a.intersect=1,a.betweenPoints=!0,a):a;if(a.t>1)return t=Kd(n,c,l,i),t.distance<=r*r?(a.t=1,a.intersect=1,a.betweenPoints=!0,a):a;if(o[0]<0)return o[0]=0,t=Kd(c,e,n,i),a.t=t.t,t.distance<=r*r?(a.intersect=1,a):a;if(o[0]>1)return o[0]=1,t=Kd(l,e,n,i),a.t=t.t,t.distance<=r*r?(a.intersect=1,a):a}return a},e.evaluateLocation=(e,n,r)=>{const i=[],o=[];t.points.getPoint(0,i),t.points.getPoint(1,o);for(let t=0;t<3;t++)n[t]=i[t]+e[0]*(o[t]-i[t]);r[0]=1-e[0],r[1]=e[0]},e.evaluateOrientation=(e,n,r)=>!!t.orientations&&(Xd(n,t.orientations[0],t.orientations[1],e[0]),r[0]=1-e[0],r[1]=e[0],!0)}(e,t)}var ep={newInstance:fh.newInstance(Jd,"vtkLine"),extend:Jd,...Zd,...zd};const{vtkErrorMacro:tp,vtkWarningMacro:np}=fh;const rp={arrays:[],copyFieldFlags:[],doCopyAllOn:!0,doCopyAllOff:!1};function ip(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,rp,n),fh.obj(e,t),function(e,t){t.classHierarchy.push("vtkFieldData");const n=e.getState;t.arrays&&(t.arrays=t.arrays.map(e=>({data:pu(e.data)}))),e.initialize=()=>{e.initializeFields(),e.copyAllOn(),e.clearFieldFlags()},e.initializeFields=()=>{t.arrays=[],t.copyFieldFlags={},e.modified()},e.copyStructure=n=>{e.initializeFields(),t.copyFieldFlags=n.getCopyFieldFlags().map(e=>e),t.arrays=n.arrays().map(e=>({array:e}))},e.getNumberOfArrays=()=>t.arrays.length,e.getNumberOfActiveArrays=()=>t.arrays.length,e.addArray=n=>{const r=n.getName(),{array:i,index:o}=e.getArrayWithIndex(r);return null!=i?(t.arrays[o]={data:n},o):(t.arrays=[].concat(t.arrays,{data:n}),t.arrays.length-1)},e.removeAllArrays=()=>{t.arrays=[]},e.removeArray=n=>{const r=t.arrays.findIndex(e=>e.data.getName()===n);return e.removeArrayByIndex(r)},e.removeArrayByIndex=e=>-1!==e&&e<t.arrays.length&&(t.arrays.splice(e,1),!0),e.getArrays=()=>t.arrays.map(e=>e.data),e.getArray=t=>"number"==typeof t?e.getArrayByIndex(t):e.getArrayByName(t),e.getArrayByName=e=>t.arrays.reduce((t,n,r)=>n.data.getName()===e?n.data:t,null),e.getArrayWithIndex=e=>{const n=t.arrays.findIndex(t=>t.data.getName()===e);return{array:-1!==n?t.arrays[n].data:null,index:n}},e.getArrayByIndex=e=>e>=0&&e<t.arrays.length?t.arrays[e].data:null,e.hasArray=t=>e.getArrayWithIndex(t).index>=0,e.getArrayName=e=>{const n=t.arrays[e];return n?n.data.getName():""},e.getCopyFieldFlags=()=>t.copyFieldFlags,e.getFlag=e=>t.copyFieldFlags[e],e.passData=function(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1;n.getArrays().forEach(o=>{const a=e.getFlag(o.getName());if(!1!==a&&(!t.doCopyAllOff||!0===a)&&o){let t=e.getArrayByName(o.getName());if(t)if(o.getNumberOfComponents()===t.getNumberOfComponents())if(r>-1&&r<o.getNumberOfTuples()){const e=i>-1?i:r;t.insertTuple(e,o.getTuple(r))}else t.insertTuples(0,o.getTuples());else tp("Unhandled case in passData");else if(r<0||r>o.getNumberOfTuples())e.addArray(o),n.getAttributes(o).forEach(t=>{e.setAttribute(o,t)});else{const a=o.getNumberOfComponents();let s=o.getNumberOfValues();const c=i>-1?i:r;s<=c*a&&(s=(c+1)*a),t=sd.newInstance({name:o.getName(),dataType:o.getDataType(),numberOfComponents:a,values:fh.newTypedArray(o.getDataType(),s),size:0}),t.insertTuple(c,o.getTuple(r)),e.addArray(t),n.getAttributes(o).forEach(n=>{e.setAttribute(t,n)})}}})},e.interpolateData=function(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:-1,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:.5;n.getArrays().forEach(s=>{const c=e.getFlag(s.getName());if(!1!==c&&(!t.doCopyAllOff||!0===c)&&s){let t=e.getArrayByName(s.getName());if(t)if(s.getNumberOfComponents()===t.getNumberOfComponents())if(r>-1&&r<s.getNumberOfTuples()){const e=o>-1?o:r;t.interpolateTuple(e,s,r,s,i,a),np("Unexpected case in interpolateData")}else t.insertTuples(s.getTuples());else tp("Unhandled case in interpolateData");else if(r<0||i<0||r>s.getNumberOfTuples())e.addArray(s),n.getAttributes(s).forEach(t=>{e.setAttribute(s,t)});else{const c=s.getNumberOfComponents();let l=s.getNumberOfValues();const u=o>-1?o:r;l<=u*c&&(l=(u+1)*c),t=sd.newInstance({name:s.getName(),dataType:s.getDataType(),numberOfComponents:c,values:fh.newTypedArray(s.getDataType(),l),size:0}),t.interpolateTuple(u,s,r,s,i,a),e.addArray(t),n.getAttributes(s).forEach(n=>{e.setAttribute(t,n)})}}})},e.copyFieldOn=e=>{t.copyFieldFlags[e]=!0},e.copyFieldOff=e=>{t.copyFieldFlags[e]=!1},e.copyAllOn=()=>{t.doCopyAllOn&&!t.doCopyAllOff||(t.doCopyAllOn=!0,t.doCopyAllOff=!1,e.modified())},e.copyAllOff=()=>{!t.doCopyAllOn&&t.doCopyAllOff||(t.doCopyAllOn=!1,t.doCopyAllOff=!0,e.modified())},e.clearFieldFlags=()=>{t.copyFieldFlags={}},e.deepCopy=e=>{t.arrays=e.getArrays().map(e=>{const t=e.newClone();return t.deepCopy(e),{data:t}})},e.copyFlags=e=>e.getCopyFieldFlags().map(e=>e),e.reset=()=>t.arrays.forEach(e=>e.data.reset()),e.getMTime=()=>t.arrays.reduce((e,t)=>t.data.getMTime()>e?t.data.getMTime():e,t.mtime),e.getNumberOfComponents=()=>t.arrays.reduce((e,t)=>e+t.data.getNumberOfComponents(),0),e.getNumberOfTuples=()=>t.arrays.length>0?t.arrays[0].getNumberOfTuples():0,e.getState=()=>{const e=n();return e&&(e.arrays=t.arrays.map(e=>({data:e.data.getState()}))),e}}(e,t)}var op={newInstance:fh.newInstance(ip,"vtkFieldData"),extend:ip};var ap={AttributeCopyOperations:{COPYTUPLE:0,INTERPOLATE:1,PASSDATA:2,ALLCOPY:3},AttributeLimitTypes:{MAX:0,EXACT:1,NOLIMIT:2},AttributeTypes:{SCALARS:0,VECTORS:1,NORMALS:2,TCOORDS:3,TENSORS:4,GLOBALIDS:5,PEDIGREEIDS:6,EDGEFLAG:7,NUM_ATTRIBUTES:8},CellGhostTypes:{DUPLICATECELL:1,HIGHCONNECTIVITYCELL:2,LOWCONNECTIVITYCELL:4,REFINEDCELL:8,EXTERIORCELL:16,HIDDENCELL:32},DesiredOutputPrecision:{DEFAULT:0,SINGLE:1,DOUBLE:2},PointGhostTypes:{DUPLICATEPOINT:1,HIDDENPOINT:2},ghostArrayName:"vtkGhostType"};const{AttributeTypes:sp,AttributeCopyOperations:cp}=ap,{vtkWarningMacro:lp}=fh;const up={activeScalars:-1,activeVectors:-1,activeTensors:-1,activeNormals:-1,activeTCoords:-1,activeGlobalIds:-1,activePedigreeIds:-1};function hp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,up,n),op.extend(e,t,n),fh.setGet(e,t,["activeScalars","activeNormals","activeTCoords","activeVectors","activeTensors","activeGlobalIds","activePedigreeIds"]),t.arrays||(t.arrays={}),function(e,t){const n=["Scalars","Vectors","Normals","TCoords","Tensors","GlobalIds","PedigreeIds"];function r(e){let t=n.find(t=>sp[t.toUpperCase()]===e||"number"!=typeof e&&t.toLowerCase()===e.toLowerCase());return void 0===t&&(t=null),t}t.classHierarchy.push("vtkDataSetAttributes");const i={...e};e.checkNumberOfComponents=e=>!0,e.setAttribute=(n,i)=>{const o=r(i);if(n&&"PEDIGREEIDS"===o.toUpperCase()&&!n.isA("vtkDataArray"))return lp(`Cannot set attribute ${o}. The attribute must be a vtkDataArray.`),-1;if(n&&!e.checkNumberOfComponents(n,o))return lp(`Cannot set attribute ${o}. Incorrect number of components.`),-1;let a=t[`active${o}`];if(a>=0&&a<t.arrays.length){if(t.arrays[a]===n)return a;e.removeArrayByIndex(a)}return n?(a=e.addArray(n),t[`active${o}`]=a):t[`active${o}`]=-1,e.modified(),t[`active${o}`]},e.getAttributes=t=>n.filter(n=>e[`get${n}`]()===t),e.setActiveAttributeByName=(t,n)=>e.setActiveAttributeByIndex(e.getArrayWithIndex(t).index,n),e.setActiveAttributeByIndex=(n,i)=>{const o=r(i);if(n>=0&&n<t.arrays.length){if("PEDIGREEIDS"!==o.toUpperCase()){const t=e.getArrayByIndex(n);if(!t.isA("vtkDataArray"))return lp(`Cannot set attribute ${o}. Only vtkDataArray subclasses can be set as active attributes.`),-1;if(!e.checkNumberOfComponents(t,o))return lp(`Cannot set attribute ${o}. Incorrect number of components.`),-1}return t[`active${o}`]=n,e.modified(),n}return-1===n&&(t[`active${o}`]=n,e.modified()),-1},e.getActiveAttribute=t=>{const n=r(t);return e[`get${n}`]()},e.removeAllArrays=()=>{n.forEach(e=>{t[`active${e}`]=-1}),i.removeAllArrays()},e.removeArrayByIndex=e=>(-1!==e&&n.forEach(n=>{e===t[`active${n}`]?t[`active${n}`]=-1:e<t[`active${n}`]&&(t[`active${n}`]-=1)}),i.removeArrayByIndex(e)),n.forEach(n=>{const r=`active${n}`;e[`get${n}`]=()=>e.getArrayByIndex(t[r]),e[`set${n}`]=t=>e.setAttribute(t,n),e[`setActive${n}`]=t=>e.setActiveAttributeByIndex(e.getArrayWithIndex(t).index,n),e[`copy${n}Off`]=()=>{const e=n.toUpperCase();t.copyAttributeFlags[cp.PASSDATA][sp[e]]=!1},e[`copy${n}On`]=()=>{const e=n.toUpperCase();t.copyAttributeFlags[cp.PASSDATA][sp[e]]=!0}}),e.initializeAttributeCopyFlags=()=>{t.copyAttributeFlags=[],Object.keys(cp).filter(e=>"ALLCOPY"!==e).forEach(e=>{t.copyAttributeFlags[cp[e]]=Object.keys(sp).filter(e=>"NUM_ATTRIBUTES"!==e).reduce((e,t)=>(e[sp[t]]=!0,e),[])}),t.copyAttributeFlags[cp.COPYTUPLE][sp.GLOBALIDS]=!1,t.copyAttributeFlags[cp.INTERPOLATE][sp.GLOBALIDS]=!1,t.copyAttributeFlags[cp.COPYTUPLE][sp.PEDIGREEIDS]=!1},e.initialize=fh.chain(e.initialize,e.initializeAttributeCopyFlags),t.dataArrays&&Object.keys(t.dataArrays).length&&Object.keys(t.dataArrays).forEach(n=>{t.dataArrays[n].ref||"vtkDataArray"!==t.dataArrays[n].type||e.addArray(sd.newInstance(t.dataArrays[n]))});const o=e.shallowCopy;e.shallowCopy=(e,n)=>{o(e,n),t.arrays=e.getArrays().map(e=>{const t=e.newClone();return t.shallowCopy(e,n),{data:t}})},e.initializeAttributeCopyFlags()}(e,t)}var dp={newInstance:fh.newInstance(hp,"vtkDataSetAttributes"),extend:hp,...ap};var pp={FieldDataTypes:{UNIFORM:0,DATA_OBJECT_FIELD:0,COORDINATE:1,POINT_DATA:1,POINT:2,POINT_FIELD_DATA:2,CELL:3,CELL_FIELD_DATA:3,VERTEX:4,VERTEX_FIELD_DATA:4,EDGE:5,EDGE_FIELD_DATA:5,ROW:6,ROW_DATA:6},FieldAssociations:{FIELD_ASSOCIATION_POINTS:0,FIELD_ASSOCIATION_CELLS:1,FIELD_ASSOCIATION_NONE:2,FIELD_ASSOCIATION_POINTS_THEN_CELLS:3,FIELD_ASSOCIATION_VERTICES:4,FIELD_ASSOCIATION_EDGES:5,FIELD_ASSOCIATION_ROWS:6,NUMBER_OF_ASSOCIATIONS:7}};const fp=["pointData","cellData","fieldData"];const mp={};function gp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,mp,n),fh.obj(e,t),fh.setGet(e,t,fp),function(e,t){t.classHierarchy.push("vtkDataSet"),fp.forEach(e=>{t[e]?t[e]=pu(t[e]):t[e]=dp.newInstance()});const n=e.shallowCopy;e.shallowCopy=function(e){n(e,arguments.length>1&&void 0!==arguments[1]&&arguments[1]),fp.forEach(n=>{t[n]=dp.newInstance(),t[n].shallowCopy(e.getReferenceByName(n))})}}(e,t)}var bp={newInstance:fh.newInstance(gp,"vtkDataSet"),extend:gp,...pp};const yp={};function vp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,yp,n),bp.extend(e,t,n),fh.setGet(e,t,["points"]),function(e,t){t.classHierarchy.push("vtkPointSet"),t.points?t.points=pu(t.points):t.points=dd.newInstance(),e.getNumberOfPoints=()=>t.points.getNumberOfPoints(),e.getBounds=()=>t.points.getBounds(),e.computeBounds=()=>{e.getBounds()};const n=e.shallowCopy;e.shallowCopy=function(e){n(e,arguments.length>1&&void 0!==arguments[1]&&arguments[1]),t.points=dd.newInstance(),t.points.shallowCopy(e.getPoints())}}(e,t)}var xp={newInstance:fh.newInstance(vp,"vtkPointSet"),extend:vp};const wp={};function Ep(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,wp,n),fh.obj(e,t),fh.setGet(e,t,["transform"]),function(e,t){t.classHierarchy.push("vtkImplicitFunction"),e.functionValue=n=>{if(!t.transform)return e.evaluateFunction(n);const r=[];return t.transform.transformPoint(n,r),e.evaluateFunction(r)},e.evaluateFunction=e=>{fh.vtkErrorMacro("not implemented")}}(e,t)}var Tp={newInstance:fh.newInstance(Ep,"vtkImplicitFunction"),extend:Ep};const Ap=1e-6,Cp="coincide",Op="disjoint";function kp(e,t,n){const r=n[0]*(e[0]-t[0])+n[1]*(e[1]-t[1])+n[2]*(e[2]-t[2]);return Math.abs(r)}function Sp(e,t,n,r){const i=[];Vh(e,t,i);const o=Wh(n,i);r[0]=e[0]-o*n[0],r[1]=e[1]-o*n[1],r[2]=e[2]-o*n[2]}function Rp(e,t,n){const r=Wh(e,t);let i=Wh(t,t);return 0===i&&(i=1),n[0]=e[0]-r*t[0]/i,n[1]=e[1]-r*t[1]/i,n[2]=e[2]-r*t[2]/i,n}function Mp(e,t,n,r){const i=[];Vh(e,t,i);const o=Wh(n,i),a=Wh(n,n);0!==a?(r[0]=e[0]-o*n[0]/a,r[1]=e[1]-o*n[1]/a,r[2]=e[2]-o*n[2]/a):(r[0]=e[0],r[1]=e[1],r[2]=e[2])}function Ip(e,t,n,r){const i={intersection:!1,betweenPoints:!1,t:Number.MAX_VALUE,x:[]},o=[],a=[];Vh(t,e,o),Vh(n,e,a);const s=Wh(r,a),c=Wh(r,o);let l,u;return l=c<0?-c:c,u=s<0?-s*Ap:s*Ap,l<=u||(i.t=s/c,i.x[0]=e[0]+i.t*o[0],i.x[1]=e[1]+i.t*o[1],i.x[2]=e[2]+i.t*o[2],i.intersection=!0,i.betweenPoints=i.t>=0&&i.t<=1),i}function Pp(e,t,n,r){const i={intersection:!1,l0:[],l1:[],error:null},o=[];Xh(t,r,o);const a=o.map(e=>Math.abs(e));if(a[0]+a[1]+a[2]<Ap){const r=[];return Vh(e,n,r),0===Wh(t,r)?i.error=Cp:i.error=Op,i}let s;s=a[0]>a[1]&&a[0]>a[2]?"x":a[1]>a[2]?"y":"z";const c=[],l=-Wh(t,e),u=-Wh(r,n);switch(s){case"x":c[0]=0,c[1]=(u*t[2]-l*r[2])/o[0],c[2]=(l*r[1]-u*t[1])/o[0];break;case"y":c[0]=(l*r[2]-u*t[2])/o[1],c[1]=0,c[2]=(u*t[0]-l*r[0])/o[1];break;case"z":c[0]=(u*t[1]-l*r[1])/o[2],c[1]=(l*r[0]-u*t[0])/o[2],c[2]=0}return i.l0=c,function(e,t,n){n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2]}(c,o,i.l1),i.intersection=!0,i}const _p={evaluate:function(e,t,n){return e[0]*(n[0]-t[0])+e[1]*(n[1]-t[1])+e[2]*(n[2]-t[2])},distanceToPlane:kp,projectPoint:Sp,projectVector:Rp,generalizedProjectPoint:Mp,intersectWithLine:Ip,intersectWithPlane:Pp,DISJOINT:Op,COINCIDE:Cp};const Np={normal:[0,0,1],origin:[0,0,0]};function Lp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Np,n),Tp.extend(e,t,n),fh.setGetArray(e,t,["normal","origin"],3),function(e,t){t.classHierarchy.push("vtkPlane"),e.distanceToPlane=e=>kp(e,t.origin,t.normal),e.projectPoint=(e,n)=>{Sp(e,t.origin,t.normal,n)},e.projectVector=(e,n)=>Rp(e,t.normal,n),e.push=e=>{if(0!==e)for(let n=0;n<3;n++)t.origin[n]+=e*t.normal[n]},e.generalizedProjectPoint=(e,n)=>{Mp(e,t.origin,t.normal,n)},e.evaluateFunction=(e,n,r)=>Array.isArray(e)?t.normal[0]*(e[0]-t.origin[0])+t.normal[1]*(e[1]-t.origin[1])+t.normal[2]*(e[2]-t.origin[2]):t.normal[0]*(e-t.origin[0])+t.normal[1]*(n-t.origin[1])+t.normal[2]*(r-t.origin[2]),e.evaluateGradient=e=>[t.normal[0],t.normal[1],t.normal[2]],e.intersectWithLine=(e,n)=>Ip(e,n,t.origin,t.normal),e.intersectWithPlane=(e,n)=>Pp(e,n,t.origin,t.normal)}(e,t)}var Dp={newInstance:fh.newInstance(Lp,"vtkPlane"),extend:Lp,..._p};function jp(e,t,n,r){const i=n[0]-t[0],o=n[1]-t[1],a=n[2]-t[2],s=e[0]-t[0],c=e[1]-t[1],l=e[2]-t[2];r[0]=o*l-a*c,r[1]=a*s-i*l,r[2]=i*c-o*s}function Fp(e,t,n,r){jp(e,t,n,r);const i=Math.sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]);0!==i&&(r[0]/=i,r[1]/=i,r[2]/=i)}const Up={computeNormalDirection:jp,computeNormal:Fp,intersectWithTriangle:function(e,t,n,r,i,o){let a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:1e-6,s=!1;const c=[],l=[],u=[],h=[],d=[];Fp(e,t,n,h),Fp(r,i,o,d);const p=-Wh(h,e),f=-Wh(d,r),m=[Wh(d,e)+f,Wh(d,t)+f,Wh(d,n)+f];if(m[0]*m[1]>a&&m[0]*m[2]>a)return{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};const g=[Wh(h,r)+p,Wh(h,i)+p,Wh(h,o)+p];if(g[0]*g[1]>a&&g[0]*g[2]>a)return{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};if(Math.abs(h[0]-d[0])<1e-9&&Math.abs(h[1]-d[1])<1e-9&&Math.abs(h[2]-d[2])<1e-9&&Math.abs(p-f)<1e-9)return s=!0,{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};const b=[e,t,n],y=[r,i,o],v=Wh(h,d),x=(p-f*v)/(v*v-1),w=(f-p*v)/(v*v-1),E=[x*h[0]+w*d[0],x*h[1]+w*d[1],x*h[2]+w*d[2]],T=Xh(h,d,[]);!function(e){const t=qh(e);0!==t&&(e[0]/=t,e[1]/=t,e[2]/=t)}(T);let A=0,C=0;const O=[],k=[];let S,R,M=50,I=50;for(let t=0;t<3;t++){const n=t,i=(t+1)%3,o=Dp.intersectWithLine(b[n],b[i],r,d);o.intersection&&o.t>0-a&&o.t<1+a&&(o.t<1+a&&o.t>1-a&&(M=A),O[A++]=Wh(o.x,T)-Wh(E,T));const s=Dp.intersectWithLine(y[n],y[i],e,h);s.intersection&&s.t>0-a&&s.t<1+a&&(s.t<1+a&&s.t>1-a&&(I=C),k[C++]=Wh(s.x,T)-Wh(E,T))}if(A>2){A--;const e=O[2];O[2]=O[M],O[M]=e}if(C>2){C--;const e=k[2];k[2]=k[I],k[I]=e}if(2!==A||2!==C)return{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};if(Number.isNaN(O[0])||Number.isNaN(O[1])||Number.isNaN(k[0])||Number.isNaN(k[1]))return{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};if(O[0]>O[1]){const e=O[1];O[1]=O[0],O[0]=e}if(k[0]>k[1]){const e=k[1];k[1]=k[0],k[0]=e}return O[1]<k[0]||k[1]<O[0]?{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u}:(O[0]<k[0]?O[1]<k[1]?(u[0]=2,u[1]=1,S=k[0],R=O[1]):(u[0]=2,u[1]=2,S=k[0],R=k[1]):O[1]<k[1]?(u[0]=1,u[1]=1,S=O[0],R=O[1]):(u[0]=1,u[1]=2,S=O[0],R=k[1]),Gh(E,T,S,c),Gh(E,T,R,l),{intersect:!0,coplanar:s,pt1:c,pt2:l,surfaceId:u})}};const Bp={};function zp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Bp,n),xd.extend(e,t,n),function(e,t){t.classHierarchy.push("vtkTriangle"),e.getCellDimension=()=>2,e.intersectWithLine=(n,r,i,o,a)=>{const s={subId:0,t:Number.MAX_VALUE,intersect:0,betweenPoints:!1};a[2]=0;const c=[],l=i*i,u=[],h=[],d=[];t.points.getPoint(0,u),t.points.getPoint(1,h),t.points.getPoint(2,d);const p=[],f=[];if(Fp(u,h,d,p),0!==p[0]||0!==p[1]||0!==p[2]){const t=Dp.intersectWithLine(n,r,u,p);if(s.betweenPoints=t.betweenPoints,s.t=t.t,o[0]=t.x[0],o[1]=t.x[1],o[2]=t.x[2],!t.intersection)return a[0]=0,a[1]=0,s.intersect=0,s;const i=e.evaluatePosition(o,c,a,f);if(i.evaluation>=0)return i.dist2<=l?(s.intersect=1,s):(s.intersect=i.evaluation,s)}const m=Yh(u,h),g=Yh(h,d),b=Yh(d,u);t.line||(t.line=ep.newInstance()),m>g&&m>b?(t.line.getPoints().setPoint(0,u),t.line.getPoints().setPoint(1,h)):g>b&&g>m?(t.line.getPoints().setPoint(0,h),t.line.getPoints().setPoint(1,d)):(t.line.getPoints().setPoint(0,d),t.line.getPoints().setPoint(1,u));const y=t.line.intersectWithLine(n,r,i,o,a);if(s.betweenPoints=y.betweenPoints,s.t=y.t,y.intersect){const e=[],t=[],n=[];for(let r=0;r<3;r++)e[r]=u[r]-d[r],t[r]=h[r]-d[r],n[r]=o[r]-d[r];return a[0]=Wh(n,e)/b,a[1]=Wh(n,t)/g,s.intersect=1,s}return a[0]=0,a[1]=0,s.intersect=0,s},e.evaluatePosition=(e,n,r,i)=>{const o={subId:0,dist2:0,evaluation:-1};let a,s;const c=[],l=[],u=[],h=[];let d;const p=[],f=[],m=[];let g=0,b=0;const y=[];let v,x,w,E=[];const T=[],A=[],C=[];o.subId=0,r[2]=0,t.points.getPoint(1,c),t.points.getPoint(2,l),t.points.getPoint(0,u),jp(c,l,u,h),Dp.generalizedProjectPoint(e,c,h,C);let O=0;for(a=0;a<3;a++)d=h[a]<0?-h[a]:h[a],d>O&&(O=d,b=a);for(s=0,a=0;a<3;a++)a!==b&&(y[s++]=a);for(a=0;a<2;a++)p[a]=C[y[a]]-u[y[a]],f[a]=c[y[a]]-u[y[a]],m[a]=l[y[a]]-u[y[a]];if(g=Kh(f,m),0===g)return r[0]=0,r[1]=0,o.evaluation=-1,o;if(r[0]=Kh(p,m)/g,r[1]=Kh(f,p)/g,i[0]=1-(r[0]+r[1]),i[1]=r[0],i[2]=r[1],i[0]>=0&&i[0]<=1&&i[1]>=0&&i[1]<=1&&i[2]>=0&&i[2]<=1)n&&(o.dist2=Yh(C,e),n[0]=C[0],n[1]=C[1],n[2]=C[2]),o.evaluation=1;else{let t;if(n)if(i[1]<0&&i[2]<0)for(v=Yh(e,u),x=ep.distanceToLine(e,c,u,t,T),w=ep.distanceToLine(e,u,l,t,A),v<x?(o.dist2=v,E=u):(o.dist2=x,E=T),w<o.dist2&&(o.dist2=w,E=A),a=0;a<3;a++)n[a]=E[a];else if(i[2]<0&&i[0]<0)for(v=Yh(e,c),x=ep.distanceToLine(e,c,u,t,T),w=ep.distanceToLine(e,c,l,t,A),v<x?(o.dist2=v,E=c):(o.dist2=x,E=T),w<o.dist2&&(o.dist2=w,E=A),a=0;a<3;a++)n[a]=E[a];else if(i[1]<0&&i[0]<0)for(v=Yh(e,l),x=ep.distanceToLine(e,l,u,t,T),w=ep.distanceToLine(e,c,l,t,A),v<x?(o.dist2=v,E=l):(o.dist2=x,E=T),w<o.dist2&&(o.dist2=w,E=A),a=0;a<3;a++)n[a]=E[a];else if(i[0]<0){const t=ep.distanceToLine(e,c,l,n);o.dist2=t.distance}else if(i[1]<0){const t=ep.distanceToLine(e,l,u,n);o.dist2=t.distance}else if(i[2]<0){const t=ep.distanceToLine(e,c,u,n);o.dist2=t.distance}o.evaluation=0}return o},e.evaluateLocation=(e,n,r)=>{const i=[],o=[],a=[];t.points.getPoint(0,i),t.points.getPoint(1,o),t.points.getPoint(2,a);const s=1-e[0]-e[1];for(let t=0;t<3;t++)n[t]=i[t]*s+o[t]*e[0]+a[t]*e[1];r[0]=s,r[1]=e[0],r[2]=e[1]},e.getParametricDistance=e=>{let t,n=0;const r=[];r[0]=e[0],r[1]=e[1],r[2]=1-e[0]-e[1];for(let e=0;e<3;e++)t=r[e]<0?-r[e]:r[e]>1?r[e]-1:0,t>n&&(n=t);return n}}(e,t)}var Hp={newInstance:fh.newInstance(zp,"vtkTriangle"),extend:zp,...Up};const Vp=["verts","lines","polys","strips"],{vtkWarningMacro:Gp}=fh,Wp={[kd]:ep,[Sd]:ep,[Rd]:Hp};const Xp={};function qp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Xp,n),xp.extend(e,t,n),fh.get(e,t,["cells","links"]),fh.setGet(e,t,["verts","lines","polys","strips"]),function(e,t){t.classHierarchy.push("vtkPolyData"),Vp.forEach(n=>{var r;e[`getNumberOf${r=n,r.replace(/(?:^\w|[A-Z]|\b\w)/g,e=>e.toUpperCase()).replace(/\s+/g,"")}`]=()=>t[n].getNumberOfCells(),t[n]?t[n]=pu(t[n]):t[n]=bd.newInstance()}),e.getNumberOfCells=()=>Vp.reduce((e,n)=>e+t[n].getNumberOfCells(),0);const n=e.shallowCopy;e.shallowCopy=function(e){n(e,arguments.length>1&&void 0!==arguments[1]&&arguments[1]),Vp.forEach(n=>{t[n]=bd.newInstance(),t[n].shallowCopy(e.getReferenceByName(n))})},e.buildCells=()=>{const n=e.getNumberOfVerts(),r=e.getNumberOfLines(),i=e.getNumberOfPolys(),o=e.getNumberOfStrips(),a=n+r+i+o,s=new Uint8Array(a);let c=s;const l=new Uint32Array(a);let u=l;if(n){let e=0;t.verts.getCellSizes().forEach((t,n)=>{u[n]=e,c[n]=t>1?Od:Cd,e+=t+1}),u=u.subarray(n),c=c.subarray(n)}if(r){let e=0;t.lines.getCellSizes().forEach((t,n)=>{u[n]=e,c[n]=t>2?Sd:kd,1===t&&Gp("Building VTK_LINE ",n," with only one point, but VTK_LINE needs at least two points. Check the input."),e+=t+1}),u=u.subarray(r),c=c.subarray(r)}if(i){let e=0;t.polys.getCellSizes().forEach((t,n)=>{switch(u[n]=e,t){case 3:c[n]=Rd;break;case 4:c[n]=Pd;break;default:c[n]=Id}t<3&&Gp("Building VTK_TRIANGLE ",n," with less than three points, but VTK_TRIANGLE needs at least three points. Check the input."),e+=t+1}),u+=u.subarray(i),c+=c.subarray(i)}if(o){let e=0;c.fill(Md,0,o),t.strips.getCellSizes().forEach((t,n)=>{u[n]=e,e+=t+1})}t.cells=Bd.newInstance(),t.cells.setCellTypes(a,s,l)},e.buildLinks=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;void 0===t.cells&&e.buildCells(),t.links=Td.newInstance(),n>0?t.links.allocate(n):t.links.allocate(e.getPoints().getNumberOfPoints()),t.links.buildLinks(e)},e.getCellType=e=>t.cells.getCellType(e),e.getCellPoints=n=>{const r=e.getCellType(n);let i=null;switch(r){case Cd:case Od:i=t.verts;break;case kd:case Sd:i=t.lines;break;case Rd:case Pd:case Id:i=t.polys;break;case Md:i=t.strips;break;default:return i=null,{type:0,cellPointIds:null}}const o=t.cells.getCellLocation(n);return{cellType:r,cellPointIds:i.getCell(o)}},e.getPointCells=e=>t.links.getCells(e),e.getCellEdgeNeighbors=(e,n,r)=>{const i=t.links.getLink(n),o=t.links.getLink(r);return i.cells.filter(t=>t!==e&&-1!==o.cells.indexOf(t))},e.getCell=function(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=e.getCellPoints(t),i=n||Wp[r.cellType].newInstance();return i.initialize(e.getPoints(),r.cellPointIds),i}}(e,t)}var Yp={newInstance:fh.newInstance(qp,"vtkPolyData"),extend:qp};e.BufferGeometry.prototype.computeBoundsTree=oo,e.BufferGeometry.prototype.disposeBoundsTree=ao,e.Mesh.prototype.raycast=no;const Kp={COLORS:{POINT_DEFAULT:1973790,POINT_SELECTED:16750950,EDGE_DEFAULT:1973790,EDGE_SELECTED:16106818,CENTER_HELPER:16750950},SIZES:{POINT:.03,CENTER_HELPER:.015,TRANSFORM_CONTROL:.5},GEOMETRY:{POINT_SEGMENTS:8,HELPER_SEGMENTS:8},PERFORMANCE:{USE_VTK_INTERPOLATION:!0,BATCH_SIZE:1e3,WORKER_ENABLED:"undefined"!=typeof Worker}};class Qp{constructor(e,t,n){this.scene=e,this.camera=t,this.renderer=n,this.padding=1.1,this._bvhCache=new Map,this._vtkInterpolator=null,this._workerPool=[],this._animationFrame=null,this._batchUpdateQueue=[],this._initGeometryPool(),this._initDataStructures(),this._initInteraction(),this._initTransformControls(),this._initPerformanceOptimizations()}_initGeometryPool(){this._geometryPool={sphere:new e.SphereGeometry(Kp.SIZES.POINT,Kp.GEOMETRY.POINT_SEGMENTS,Kp.GEOMETRY.POINT_SEGMENTS),helperSphere:new e.SphereGeometry(Kp.SIZES.CENTER_HELPER,Kp.GEOMETRY.HELPER_SEGMENTS,Kp.GEOMETRY.HELPER_SEGMENTS)},this._materialPool={pointDefault:new e.MeshBasicMaterial({color:Kp.COLORS.POINT_DEFAULT}),pointSelected:new e.MeshBasicMaterial({color:Kp.COLORS.POINT_SELECTED}),edgeDefault:new e.LineBasicMaterial({color:Kp.COLORS.EDGE_DEFAULT}),edgeSelected:new e.LineBasicMaterial({color:Kp.COLORS.EDGE_SELECTED}),centerHelper:new e.MeshBasicMaterial({color:Kp.COLORS.CENTER_HELPER,transparent:!0,opacity:.7})}}_initDataStructures(){this.vertices=[],this.spheres=[],this.lines=[],this.edgesToVertex={},this.targetObjects=[],this.originalGeometries=new Map,this.cachedVertexPositions=[],this.gridConfig={size:4,xCount:3,yCount:3,zCount:3},this.visible=!0,this.needsDeformationUpdate=!1,this.lastUpdateTime=0,this.onDeformationUpdate=null}_initInteraction(){this.raycaster=new e.Raycaster,this.mouse=new e.Vector2,this.selection={vertices:[],transformActive:!1,previousCenter:null,centerHelper:null,isBoxSelecting:!1,boxElement:this._createBoxElement(),boxPosition:{startX:0,startY:0,endX:0,endY:0}},this._bindEventHandlers()}_createBoxElement(){const e=document.createElement("div");return Object.assign(e.style,{position:"absolute",border:"2px dashed #646cff",backgroundColor:"rgba(75, 160, 255, 0.1)",display:"none",pointerEvents:"none",zIndex:"1000"}),e}_bindEventHandlers(){this._handlers={mouseDown:this._onMouseDown.bind(this),mouseMove:this._onMouseMove.bind(this),mouseUp:this._onMouseUp.bind(this),transformDragging:this._onTransformDragging.bind(this),transformChanged:this._onTransformChanged.bind(this)}}_initTransformControls(){this.transformControls=new Jt(this.camera,this.renderer.domElement),this.transformControls.setSize(Kp.SIZES.TRANSFORM_CONTROL),this.transformControls.setMode("translate"),this.scene.add(this.transformControls),this._attachTransformControlsEvents()}_attachTransformControlsEvents(){this.transformControls.addEventListener("dragging-changed",this._handlers.transformDragging),this.transformControls.addEventListener("objectChange",this._handlers.transformChanged)}_detachTransformControlsEvents(){this.transformControls.removeEventListener("dragging-changed",this._handlers.transformDragging),this.transformControls.removeEventListener("objectChange",this._handlers.transformChanged)}_initPerformanceOptimizations(){this._bvhCache=new Map,Kp.PERFORMANCE.USE_VTK_INTERPOLATION&&this._initVTKInterpolator(),Kp.PERFORMANCE.WORKER_ENABLED&&this._initWorkerPool()}_initVTKInterpolator(){try{this._vtkPoints=dd.newInstance(),this._vtkPolyData=Yp.newInstance(),console.log("VTK插值器初始化成功")}catch(e){console.warn("VTK插值器初始化失败:",e),Kp.PERFORMANCE.USE_VTK_INTERPOLATION=!1}}_initWorkerPool(){const e=Math.min(4,navigator.hardwareConcurrency||2);for(let t=0;t<e;t++)try{const e=new Worker(URL.createObjectURL(new Blob(["\n self.onmessage = function(e) {\n const { vertices, weights, type } = e.data;\n \n if (type === 'interpolate') {\n const result = new Float32Array(3);\n \n for (let i = 0; i < vertices.length; i++) {\n const vertex = vertices[i];\n const weight = weights[i];\n result[0] += vertex[0] * weight;\n result[1] += vertex[1] * weight;\n result[2] += vertex[2] * weight;\n }\n \n self.postMessage({ result, id: e.data.id });\n }\n };\n "],{type:"application/javascript"})));this._workerPool.push(e)}catch(e){console.warn("Worker创建失败:",e),Kp.PERFORMANCE.WORKER_ENABLED=!1;break}this._workerPool.length>0&&console.log(`初始化了 ${this._workerPool.length} 个Worker`)}setGridConfig(e){return Object.assign(this.gridConfig,e),this}setTargetObject(e=[]){return Array.isArray(e)?this.setTargetObjects(e):this.setTargetObjects([e])}setTargetObjects(e){console.log(e,"objects"),this._cleanupPreviousTargets();const t=this._extractMeshObjects(e.filter(e=>null!=e));return this.targetObjects=t,this.originalGeometries.clear(),this.targetObjects.forEach(e=>{e.userData.isLatticeMode=!0,e?.geometry&&(e.geometry.computeBoundingBox(),e.geometry&&this._buildBVHForGeometry(e.geometry),this.originalGeometries.set(e.uuid,e.geometry.clone()))}),this}_extractMeshObjects(e){const t=[],n=e=>{e&&(e.isMesh&&e.geometry?t.push(e):e.isGroup||e.isObject3D?e.children&&e.children.length>0&&e.children.forEach(e=>n(e)):e.geometry&&t.push(e))};return e.forEach(e=>n(e)),0===t.length?console.warn("未找到任何有效的几何体对象,无法创建晶格"):console.log(`从 ${e.length} 个输入对象中提取到 ${t.length} 个Mesh对象`),t}_buildBVHForGeometry(e){try{e.boundsTree||(e.computeBoundsTree(),console.log("为几何体构建BVH,顶点数:",e.attributes.position.count)),this._bvhCache.set(e.uuid,e.boundsTree)}catch(e){console.warn("BVH构建失败:",e)}}_cleanupPreviousTargets(){this.targetObjects.forEach(e=>{e?._createdByLattice&&(this.scene.remove(e),e.geometry?.dispose(),Array.isArray(e.material)?e.material.forEach(e=>e.dispose()):e.material?.dispose())}),this.targetObjects=[],this.originalGeometries.clear()}createLattice(){return this.clearLattice(),this.targetObjects.length?(this.targetObjects.forEach(e=>{e?.geometry&&(e.geometry.computeBoundingBox(),e.updateMatrixWorld(!0))}),this._createLatticeStructure(),this.setVisible(!0),this.initEvents(),this.clearSelection(),this.targetObjects.length&&this.vertices.length&&(console.log("开始初始化变形信息,控制点数:",this.gridConfig.xCount*this.gridConfig.yCount*this.gridConfig.zCount),this.initializeCache(),this.deformationInfo?console.log("变形信息初始化成功"):console.warn("变形信息初始化失败,请检查目标对象和几何体数据")),this):(console.error("没有设置目标对象,无法创建晶格"),this)}_createLatticeStructure(){const t=this._calculateTotalBoundingBox(),n=new e.Vector3,r=new e.Vector3;if(t.getSize(n),t.getCenter(r),0===n.x||0===n.y||0===n.z)return void console.error("目标对象的尺寸为零,无法创建有效晶格");const i=n.clone().multiplyScalar(this.padding),{xCount:o,yCount:a,zCount:s}=this.gridConfig;this._createVertexGrid(i,r,o,a,s),this._createEdges()}_calculateTotalBoundingBox(){const t=new e.Box3;return t.makeEmpty(),0===this.targetObjects.length?(console.warn("没有目标对象可计算边界盒"),t):(this.targetObjects.forEach(n=>{if(!n)return;n.updateMatrixWorld(!0);const r=(new e.Box3).setFromObject(n);r.isEmpty()||t.union(r)}),t.isEmpty()&&(console.warn("所有对象的边界盒都为空,使用默认边界盒"),t.setFromCenterAndSize(new e.Vector3(0,0,0),new e.Vector3(2,2,2))),t)}_createVertexGrid(t,n,r,i,o){const a=t.x/(r-1),s=t.y/(i-1),c=t.z/(o-1);for(let l=0;l<r;l++){this.vertices[l]=[];for(let u=0;u<i;u++){this.vertices[l][u]=[];for(let h=0;h<o;h++){const d=new e.Vector3(-t.x/2+l*a+n.x,-t.y/2+u*s+n.y,-t.z/2+h*c+n.z);this.vertices[l][u][h]=d,this._isOnSurface(l,u,h,r,i,o)&&this._createVertexSphere(d,l,u,h)}}}this.spheres.forEach(e=>this.scene.add(e))}_isOnSurface(e,t,n,r,i,o){return 0===e||e===r-1||0===t||t===i-1||0===n||n===o-1}_createVertexSphere(t,n,r,i){const o=new e.Mesh(this._geometryPool.sphere,this._materialPool.pointDefault);return o.position.copy(t),o.userData={x:n,y:r,z:i},this.spheres.push(o),o}_createEdges(){const{xCount:t,yCount:n,zCount:r}=this.gridConfig;this.edgesToVertex={};const i=(t,n,r,i,o,a,s,c)=>{const l=(new e.BufferGeometry).setFromPoints([t,n]),u=new e.Line(l,this._materialPool.edgeDefault);this.lines.push(u),this.scene.add(u),[`${r},${i},${o}`,`${a},${s},${c}`].forEach(e=>{this.edgesToVertex[e]||(this.edgesToVertex[e]=[]),this.edgesToVertex[e].push(u)})};for(let e=0;e<t;e++)for(let o=0;o<n;o++)for(let a=0;a<r;a++)this._isOnSurface(e,o,a,t,n,r)&&(e<t-1&&(0===o||o===n-1||0===a||a===r-1)&&i(this.vertices[e][o][a],this.vertices[e+1][o][a],e,o,a,e+1,o,a),o<n-1&&(0===e||e===t-1||0===a||a===r-1)&&i(this.vertices[e][o][a],this.vertices[e][o+1][a],e,o,a,e,o+1,a),a<r-1&&(0===e||e===t-1||0===o||o===n-1)&&i(this.vertices[e][o][a],this.vertices[e][o][a+1],e,o,a,e,o,a+1))}initEvents(){return this.container=this.renderer.domElement,this.selection.boxElement&&!this.selection.boxElement.parentNode&&this.container.parentElement&&this.container.parentElement.appendChild(this.selection.boxElement),this.container&&(this.container.addEventListener("mousedown",this._handlers.mouseDown),document.addEventListener("mousemove",this._handlers.mouseMove),document.addEventListener("mouseup",this._handlers.mouseUp)),this}removeEvents(){return this.container&&this.container.removeEventListener("mousedown",this._handlers.mouseDown),document.removeEventListener("mousemove",this._handlers.mouseMove),document.removeEventListener("mouseup",this._handlers.mouseUp),this.selection?.boxElement?.parentNode&&this.selection.boxElement.parentNode.removeChild(this.selection.boxElement),this}_onMouseDown(e){if(0!==e.button||this.transformControls.object&&this.transformControls.axis)return;e.preventDefault(),this._updateMousePosition(e),this.raycaster.setFromCamera(this.mouse,this.camera);const t=this.raycaster.intersectObjects(this.spheres),n=e.ctrlKey||e.metaKey;t.length>0?(n||this.clearSelection(),this.toggleVertexSelection(t[0].object)):this._startBoxSelection(e,n)}_onMouseMove(e){this.selection.isBoxSelecting&&(e.preventDefault(),this._updateBoxSelection(e))}_onMouseUp(e){this.selection.isBoxSelecting&&this._endBoxSelection()}_updateMousePosition(e){const t=this.renderer.domElement.getBoundingClientRect();this.mouse.x=(e.clientX-t.left)/t.width*2-1,this.mouse.y=-(e.clientY-t.top)/t.height*2+1}_startBoxSelection(e,t){this.selection.isBoxSelecting=!0;const n=this.container.getBoundingClientRect(),r=e.clientX-n.left,i=e.clientY-n.top;this.selection.boxPosition={startX:r,startY:i,endX:r,endY:i},Object.assign(this.selection.boxElement.style,{left:`${r}px`,top:`${i}px`,width:"0px",height:"0px",display:"block"}),t||this.clearSelection()}_updateBoxSelection(e){const t=this.container.getBoundingClientRect();this.selection.boxPosition.endX=e.clientX-t.left,this.selection.boxPosition.endY=e.clientY-t.top,this._updateBoxDisplay()}_updateBoxDisplay(){const{startX:e,startY:t,endX:n,endY:r}=this.selection.boxPosition,i=Math.min(e,n),o=Math.max(e,n),a=Math.min(t,r),s=Math.max(t,r);Object.assign(this.selection.boxElement.style,{left:`${i}px`,top:`${a}px`,width:o-i+"px",height:s-a+"px"})}_endBoxSelection(){this.selection.isBoxSelecting=!1,this.selection.boxElement.style.display="none";const{startX:e,startY:t,endX:n,endY:r}=this.selection.boxPosition,i=Math.min(e,n),o=Math.max(e,n),a=Math.min(t,r),s=Math.max(t,r);o-i>=5&&s-a>=5&&this._processBoxSelection(i,o,a,s)}_processBoxSelection(t,n,r,i){const o=this.container.getBoundingClientRect(),a=new e.Vector3;this.spheres.forEach(e=>{a.copy(e.position).project(this.camera);const s=(a.x+1)/2*o.width,c=(1-a.y)/2*o.height;s>=t&&s<=n&&c>=r&&c<=i&&this.toggleVertexSelection(e,!0)})}_onTransformDragging(e){if(this.selection.transformActive=e.value,!e.value&&this.targetObjects.length>0){if(this.deformationInfo||(console.log("变换结束时发现变形信息为空,重新初始化..."),this.initializeCache()),console.log("松开鼠标,开始更新模型对象"),this.updateTargetObjectDeformation(),this.needsDeformationUpdate=!1,this._deformationStartSnapshot){if(this.scene.userData.sceneManager){const e=this.createDeformationHistoryAction(this._deformationStartSnapshot);this.scene.userData.sceneManager.addActionToHistory(e)}this._deformationStartSnapshot=null}}else e.value&&!this._deformationStartSnapshot&&(this._deformationStartSnapshot=this.getFullStateSnapshot())}_onTransformChanged(){const{vertices:e}=this.selection;e?.length&&(1===e.length?this._updateSingleVertex(e[0]):this._updateMultipleVertices(),this.needsDeformationUpdate=!0)}_updateSingleVertex(e){const{x:t,y:n,z:r}=e.userData;this.vertices[t][n][r].copy(e.position),this.updateEdgesForVertex(t,n,r),this.selection.transformActive||this._markForDeformationUpdate()}_updateMultipleVertices(){const{previousCenter:t,centerHelper:n,vertices:r}=this.selection;if(!t)return void(this.selection.previousCenter=n.position.clone());const i=(new e.Vector3).subVectors(n.position,t);r.forEach(e=>{e.position.add(i);const{x:t,y:n,z:r}=e.userData;this.vertices[t][n][r].copy(e.position),this.updateEdgesForVertex(t,n,r)}),this.selection.previousCenter.copy(n.position),this.selection.transformActive||this._markForDeformationUpdate()}toggleVertexSelection(e,t=!1){const n=this.selection.vertices.indexOf(e),{x:r,y:i,z:o}=e.userData,a=`${r},${i},${o}`;return-1===n||t?(-1===n&&this.selection.vertices.push(e),this._setVertexColor(e,Kp.COLORS.POINT_SELECTED),this._setConnectedEdgeColor(a,Kp.COLORS.EDGE_SELECTED)):t||(this.selection.vertices.splice(n,1),this._setVertexColor(e,Kp.COLORS.POINT_DEFAULT),this._updateConnectedEdgeColors(e,a)),this.updateTransformControls(),this}_setVertexColor(e,t){const n=t===Kp.COLORS.POINT_SELECTED?this._materialPool.pointSelected:this._materialPool.pointDefault;e.material=n}_setConnectedEdgeColor(e,t){const n=t===Kp.COLORS.EDGE_SELECTED?this._materialPool.edgeSelected:this._materialPool.edgeDefault;this.edgesToVertex[e]?.forEach(e=>{e.material=n})}_updateConnectedEdgeColors(e,t){this.edgesToVertex[t]?.forEach(e=>{this.selection.vertices.some(t=>{const n=`${t.userData.x},${t.userData.y},${t.userData.z}`;return this.edgesToVertex[n]?.includes(e)})||e.material.color.set(Kp.COLORS.EDGE_DEFAULT)})}clearSelection(){return this.selection.vertices.forEach(e=>{this._setVertexColor(e,Kp.COLORS.POINT_DEFAULT),this._resetVertexConnectedEdges(e)}),this.selection.vertices=[],this.transformControls.detach(),this.selection.centerHelper&&(this.selection.centerHelper.visible=!1),this.selection.previousCenter=null,this}_resetVertexConnectedEdges(e){const{x:t,y:n,z:r}=e.userData,i=`${t},${n},${r}`;this._setConnectedEdgeColor(i,Kp.COLORS.EDGE_DEFAULT)}updateTransformControls(){const{vertices:e}=this.selection;return this.transformControls?(0===e.length?(this.transformControls.detach(),this.selection.centerHelper&&(this.selection.centerHelper.visible=!1)):1===e.length?(this.selection.centerHelper&&(this.selection.centerHelper.visible=!1),this.transformControls.detach(),this.transformControls.attach(e[0]),this.transformControls.setMode("translate"),this.transformControls.visible=!0,this.selection.previousCenter=null):this._setupMultiSelectionTransform(),this):this}_setupMultiSelectionTransform(){const{vertices:t}=this.selection;if(!t?.length)return;const n=this._calculateSelectionCenter(t);n&&(this.selection.centerHelper||(this.selection.centerHelper=new e.Mesh(this._geometryPool.helperSphere,this._materialPool.centerHelper.clone()),this.selection.centerHelper.userData={isLatticeHelper:!0,type:"centerHelper"},this.scene.add(this.selection.centerHelper)),this.selection.centerHelper.position.copy(n),this.selection.centerHelper.visible=!0,this.transformControls.detach(),this.transformControls.attach(this.selection.centerHelper),this.transformControls.setMode("translate"),this.transformControls.visible=!0,this.selection.previousCenter=n.clone())}_calculateSelectionCenter(t){const n=new e.Vector3;let r=0;for(const e of t)e?.position&&(n.add(e.position),r++);return r>0?n.divideScalar(r):null}initializeCache(){if(!this.targetObjects.length||!this.vertices.length)return void console.warn("无法初始化缓存: 没有目标对象或顶点数据");const{xCount:t,yCount:n,zCount:r}=this.gridConfig;this.cachedVertexPositions=[];const i=this._calculateTotalBoundingBox(),o=new e.Vector3,a=new e.Vector3;i.getSize(o),i.getCenter(a);const s=o.clone().multiplyScalar(this.padding);s.x<=0||s.y<=0||s.z<=0?console.error("无效的包围盒尺寸:",s):(this.deformationInfo={totalBBox:i,paddedSize:s,center:a,gridConfig:{xCount:t,yCount:n,zCount:r},originalVertices:this._getOriginalVerticesSnapshot()},console.log(`已初始化晶格变形信息,覆盖 ${this.targetObjects.length} 个对象`))}_getOriginalVerticesSnapshot(){const e=new Map;return this.targetObjects.forEach(t=>{if(!t?.geometry)return;const n=this.originalGeometries.get(t.uuid);if(!n){const n=t.geometry;return void(n&&(this.originalGeometries.set(t.uuid,n.clone()),e.set(t.uuid,{geometry:n.clone(),worldMatrix:t.matrixWorld.clone()})))}e.set(t.uuid,{geometry:n.clone(),worldMatrix:t.matrixWorld.clone()})}),e}_normalizePosition(t,n,r){return t&&n&&r?0===r.x||0===r.y||0===r.z?(console.warn("填充尺寸为零,无法归一化"),null):new e.Vector3((t.x-n.x+r.x/2)/r.x,(t.y-n.y+r.y/2)/r.y,(t.z-n.z+r.z/2)/r.z):(console.warn("归一化位置时参数无效"),null)}_calculateGridPosition(e,t,n,r){return!e||t<=1||n<=1||r<=1?(console.warn("网格位置计算参数无效"),null):{x:Math.max(0,Math.min(t-1,e.x*(t-1))),y:Math.max(0,Math.min(n-1,e.y*(n-1))),z:Math.max(0,Math.min(r-1,e.z*(r-1)))}}_calculateWeights(e){if(!e||"number"!=typeof e.x||"number"!=typeof e.y||"number"!=typeof e.z)return console.warn("无效的网格位置:",e),null;const t=e.x-Math.floor(e.x),n=e.y-Math.floor(e.y),r=e.z-Math.floor(e.z),i=Math.floor(e.x),o=Math.min(i+1,this.gridConfig.xCount-1),a=Math.floor(e.y),s=Math.min(a+1,this.gridConfig.yCount-1),c=Math.floor(e.z),l=Math.min(c+1,this.gridConfig.zCount-1);return i<0||o>=this.gridConfig.xCount||a<0||s>=this.gridConfig.yCount||c<0||l>=this.gridConfig.zCount?(console.warn("网格索引超出范围:",{x0:i,x1:o,y0:a,y1:s,z0:c,z1:l},"网格配置:",this.gridConfig),null):{w000:(1-t)*(1-n)*(1-r),w001:(1-t)*(1-n)*r,w010:(1-t)*n*(1-r),w011:(1-t)*n*r,w100:t*(1-n)*(1-r),w101:t*(1-n)*r,w110:t*n*(1-r),w111:t*n*r,gridIndices:{x0:i,x1:o,y0:a,y1:s,z0:c,z1:l}}}updateTargetObjectDeformation(){if(!this.targetObjects.length)return void console.warn("无法更新变形: 没有目标对象");if(!this.vertices.length)return void console.warn("无法更新变形: 没有顶点数据");if(!this.deformationInfo&&(console.log("变形信息为空,尝试重新初始化..."),this.initializeCache(),!this.deformationInfo))return void console.warn("无法更新变形: 初始化变形信息失败");const{paddedSize:e,center:t,gridConfig:n,originalVertices:r}=this.deformationInfo,{xCount:i,yCount:o,zCount:a}=n;Promise.all(this.targetObjects.map(i=>this._updateSingleObjectDeformation(i,r,e,t,n))).then(()=>{this.onDeformationUpdate&&this.onDeformationUpdate(this.targetObjects)}).catch(e=>{console.error("并行更新变形失败:",e)})}async _updateSingleObjectDeformation(e,t,n,r,i){if(!e?.geometry)return void console.warn("找不到对象或几何体:",e.uuid);const o=t.get(e.uuid);if(!o?.geometry)return void console.warn("找不到原始几何体数据:",e.uuid);const a=o.geometry.attributes.position,s=e.geometry.attributes.position;if(!a||!s)return void console.warn("对象缺少位置属性:",e.uuid);const c=a.count,l=e.matrixWorld,u=l.clone().invert();let h=0,d=0;for(let e=0;e<c;e+=Kp.PERFORMANCE.BATCH_SIZE){const t=Math.min(e+Kp.PERFORMANCE.BATCH_SIZE,c);if(Kp.PERFORMANCE.USE_VTK_INTERPOLATION&&this._vtkInterpolator){const o=await this._performVTKInterpolation(a,l,u,n,r,i,e,t);o?(this._applyBatchResult(s,o,e),h+=o.count):d+=t-e}else{const o=this._processBatchTraditional(a,l,u,n,r,i,e,t);this._applyBatchResult(s,o,e),h+=o.count,d+=o.errors}e+Kp.PERFORMANCE.BATCH_SIZE<c&&await new Promise(e=>setTimeout(e,0))}if(d>0&&console.warn(`对象 ${e.uuid} 有 ${d} 个顶点更新失败`),h>0){s.needsUpdate=!0;try{e.geometry.computeBoundingBox(),e.geometry.computeBoundingSphere()}catch(e){console.warn("更新几何体边界失败:",e)}if(e.geometry.boundsTree)try{e.geometry.disposeBoundsTree(),e.geometry.computeBoundsTree(),this._bvhCache.set(e.geometry.uuid,e.geometry.boundsTree)}catch(e){console.warn("BVH重建失败:",e)}}}async _performVTKInterpolation(t,n,r,i,o,a,s,c){if(!this._vtkPoints||!this._vtkPolyData)return null;try{const l=[],u=[];for(let r=s;r<c;r++){const a=new e.Vector3(t.getX(r),t.getY(r),t.getZ(r)).clone().applyMatrix4(n),c=this._normalizePosition(a,o,i);c&&(l.push([c.x,c.y,c.z]),u.push(r-s))}if(0===l.length)return null;this._vtkPoints.setData(new Float32Array(l.flat())),this._vtkPolyData.setPoints(this._vtkPoints);const h=new Float32Array(3*(c-s));let d=0;for(let t=0;t<u.length;t++){const n=u[t],i=new e.Vector3(...l[t]),o=this._calculateGridPosition(i,a.xCount,a.yCount,a.zCount);if(!o)continue;const s=this._calculateWeights(o);if(!s)continue;const c=this._calculateDeformedWorldPosition(s);if(!c)continue;const p=c.applyMatrix4(r);h[3*n]=p.x,h[3*n+1]=p.y,h[3*n+2]=p.z,d++}return{results:h,count:d}}catch(e){return console.warn("VTK插值失败,回退到传统方法:",e),null}}_processBatchTraditional(t,n,r,i,o,a,s,c){const l=new Float32Array(3*(c-s));let u=0,h=0;for(let d=s;d<c;d++)try{const c=new e.Vector3(t.getX(d),t.getY(d),t.getZ(d)).clone().applyMatrix4(n),p=this._normalizePosition(c,o,i);if(!p){h++;continue}const f=this._calculateGridPosition(p,a.xCount,a.yCount,a.zCount);if(!f){h++;continue}const m=this._calculateWeights(f);if(!m){h++;continue}const g=this._calculateDeformedWorldPosition(m);if(!g){h++;continue}const b=g.applyMatrix4(r);if(isNaN(b.x)||isNaN(b.y)||isNaN(b.z)){h++;continue}const y=3*(d-s);l[y]=b.x,l[y+1]=b.y,l[y+2]=b.z,u++}catch(e){console.warn("更新顶点失败:",e,"顶点索引:",d),h++}return{results:l,count:u,errors:h}}_applyBatchResult(e,t,n){const{results:r,count:i}=t;for(let t=0;t<i;t++){const i=n+Math.floor(3*t/3),o=3*t;i<e.count&&o+2<r.length&&e.setXYZ(i,r[o],r[o+1],r[o+2])}}_calculateDeformedWorldPosition(t){if(!t||!t.gridIndices)return console.warn("无效的权重数据"),null;const{gridIndices:n}=t,{x0:r,x1:i,y0:o,y1:a,z0:s,z1:c}=n;if(!(this.vertices&&this.vertices[r]&&this.vertices[r][o]&&this.vertices[i]&&this.vertices[i][a]))return console.warn("顶点数组结构无效"),null;if([this.vertices[r]?.[o]?.[s],this.vertices[r]?.[o]?.[c],this.vertices[r]?.[a]?.[s],this.vertices[r]?.[a]?.[c],this.vertices[i]?.[o]?.[s],this.vertices[i]?.[o]?.[c],this.vertices[i]?.[a]?.[s],this.vertices[i]?.[a]?.[c]].some(t=>!(t&&t instanceof e.Vector3)))return console.warn("某些顶点不存在或无效"),null;const l=new e.Vector3;try{if(l.add(this.vertices[r][o][s].clone().multiplyScalar(t.w000||0)),l.add(this.vertices[r][o][c].clone().multiplyScalar(t.w001||0)),l.add(this.vertices[r][a][s].clone().multiplyScalar(t.w010||0)),l.add(this.vertices[r][a][c].clone().multiplyScalar(t.w011||0)),l.add(this.vertices[i][o][s].clone().multiplyScalar(t.w100||0)),l.add(this.vertices[i][o][c].clone().multiplyScalar(t.w101||0)),l.add(this.vertices[i][a][s].clone().multiplyScalar(t.w110||0)),l.add(this.vertices[i][a][c].clone().multiplyScalar(t.w111||0)),isNaN(l.x)||isNaN(l.y)||isNaN(l.z))return console.warn("计算结果包含NaN值"),null}catch(e){return console.error("三线性插值计算失败:",e),null}return l}_calculateDeformedPosition(t){if(!t||!t.weights||!t.weights.gridIndices)return console.warn("无效的缓存数据,无法计算变形位置"),t?.originalVertex?.clone()||new e.Vector3;const{weights:n}=t,{gridIndices:r}=n,{x0:i=0,x1:o=0,y0:a=0,y1:s=0,z0:c=0,z1:l=0}=r;if(!(this.vertices&&Array.isArray(this.vertices)&&this.vertices[i]&&Array.isArray(this.vertices[i])&&this.vertices[i][a]&&Array.isArray(this.vertices[i][a])&&this.vertices[o]&&Array.isArray(this.vertices[o])&&this.vertices[o][s]&&Array.isArray(this.vertices[o][s])))return console.warn("顶点数组结构无效:",{x0:i,x1:o,y0:a,y1:s,z0:c,z1:l}),t.originalVertex?.clone()||new e.Vector3;if([this.vertices[i]?.[a]?.[c],this.vertices[i]?.[a]?.[l],this.vertices[i]?.[s]?.[c],this.vertices[i]?.[s]?.[l],this.vertices[o]?.[a]?.[c],this.vertices[o]?.[a]?.[l],this.vertices[o]?.[s]?.[c],this.vertices[o]?.[s]?.[l]].some(t=>!(t&&t instanceof e.Vector3)))return console.warn("某些顶点不存在或无效,使用原始位置"),t.originalVertex?.clone()||new e.Vector3;const u=new e.Vector3;try{if(u.add(this.vertices[i][a][c].clone().multiplyScalar(n.w000||0)),u.add(this.vertices[i][a][l].clone().multiplyScalar(n.w001||0)),u.add(this.vertices[i][s][c].clone().multiplyScalar(n.w010||0)),u.add(this.vertices[i][s][l].clone().multiplyScalar(n.w011||0)),u.add(this.vertices[o][a][c].clone().multiplyScalar(n.w100||0)),u.add(this.vertices[o][a][l].clone().multiplyScalar(n.w101||0)),u.add(this.vertices[o][s][c].clone().multiplyScalar(n.w110||0)),u.add(this.vertices[o][s][l].clone().multiplyScalar(n.w111||0)),isNaN(u.x)||isNaN(u.y)||isNaN(u.z))return console.warn("计算结果包含NaN值,使用原始位置"),t.originalVertex?.clone()||new e.Vector3}catch(n){return console.error("三线性插值计算失败:",n),t.originalVertex?.clone()||new e.Vector3}return u}updateEdgesForVertex(e,t,n){const r=`${e},${t},${n}`,i=this.edgesToVertex[r];if(!i)return;const o=this.vertices[e]?.[t]?.[n];o&&i.forEach(e=>{Object.keys(this.edgesToVertex).filter(t=>this.edgesToVertex[t].includes(e)).forEach((t,n)=>{if(n>=2)return;const[i,o,a]=t.split(",").map(Number),s=this.vertices[i]?.[o]?.[a];if(s){const n=e.geometry.attributes.position,i=t===r?0:1;n.setXYZ(i,s.x,s.y,s.z)}}),e.geometry.attributes.position.needsUpdate=!0})}_markForDeformationUpdate(){this.targetObjects.length&&(this.needsDeformationUpdate=!0)}checkPointSelection(e){return e.intersectObjects(this.spheres)}setVisible(e){return this.visible=e,this.spheres&&Array.isArray(this.spheres)&&this.spheres.forEach(t=>{t&&"object"==typeof t&&"visible"in t&&(t.visible=e)}),this.lines&&Array.isArray(this.lines)&&this.lines.forEach(t=>{t&&"object"==typeof t&&"visible"in t&&(t.visible=e)}),this}clearLattice(){return this.spheres&&Array.isArray(this.spheres)&&this.spheres.forEach(e=>{e&&(this.scene.remove(e),e.material!==this._materialPool.pointDefault&&e.material!==this._materialPool.pointSelected&&e.material?.dispose())}),this.lines&&Array.isArray(this.lines)&&this.lines.forEach(e=>{e&&(this.scene.remove(e),e.geometry?.dispose(),e.material!==this._materialPool.edgeDefault&&e.material!==this._materialPool.edgeSelected&&e.material?.dispose())}),this.spheres=[],this.lines=[],this.vertices=[],this.edgesToVertex={},this.clearSelection(),this}getLatticeGrid(){return this.vertices.length>0&&this.spheres.length>0}exitLatticeGrid(){this.clearLattice(),this.removeEvents(),this.targetObjects.forEach(e=>{e?.userData&&(e.userData.isLatticeMode=!1)});const e=[...this.targetObjects];return this.targetObjects=[],this.originalGeometries.clear(),e}getTargetObject(){return this.targetObjects[0]||null}getTargetObjects(){return this.targetObjects}getPerformanceStats(){return{sphereCount:this.spheres.length,lineCount:this.lines.length,targetObjectCount:this.targetObjects.length,gridDimensions:`${this.gridConfig.xCount}×${this.gridConfig.yCount}×${this.gridConfig.zCount}`}}dispose(){this._workerPool&&this._workerPool.length>0&&(this._workerPool.forEach(e=>{try{e.terminate()}catch(e){console.warn("Worker终止失败:",e)}}),this._workerPool=[]),this._vtkPoints&&(this._vtkPoints.delete(),this._vtkPoints=null),this._vtkPolyData&&(this._vtkPolyData.delete(),this._vtkPolyData=null),this._bvhCache&&(this._bvhCache.clear(),this._bvhCache=null),this._animationFrame&&(cancelAnimationFrame(this._animationFrame),this._animationFrame=null),this._detachTransformControlsEvents(),this.transformControls&&(this.transformControls.detach(),this.transformControls.dispose(),this.scene.remove(this.transformControls)),this.removeEvents(),this.clearLattice(),this.selection?.centerHelper&&(this.scene.remove(this.selection.centerHelper),this.selection.centerHelper.geometry?.dispose(),this.selection.centerHelper.material?.dispose()),Object.values(this._geometryPool||{}).forEach(e=>e?.dispose()),Object.values(this._materialPool||{}).forEach(e=>e?.dispose()),this._geometryPool=null,this._materialPool=null,this.vertices=null,this.spheres=null,this.lines=null,this.edgesToVertex=null,this.targetObjects=null,this.originalGeometries=null,this.cachedVertexPositions=null,this.selection=null,this.transformControls=null}static isObjectInLatticeMode(e){return e&&e.userData&&!0===e.userData.isLatticeMode}static areObjectsInLatticeMode(e){return!(!Array.isArray(e)||0===e.length)&&e.every(e=>this.isObjectInLatticeMode(e))}getLatticeConfig(){return{xCount:this.gridConfig.xCount,yCount:this.gridConfig.yCount,zCount:this.gridConfig.zCount,padding:this.padding}}getLatticeVerticesSnapshot(){if(!this.vertices||!this.vertices.length)return null;const e=[],{xCount:t,yCount:n,zCount:r}=this.gridConfig;for(let i=0;i<t;i++){e[i]=[];for(let t=0;t<n;t++){e[i][t]=[];for(let n=0;n<r;n++)this.vertices[i]&&this.vertices[i][t]&&this.vertices[i][t][n]&&(e[i][t][n]=this.vertices[i][t][n].clone())}}return e}restoreLatticeVerticesSnapshot(e){if(!e||!this.vertices)return!1;const{xCount:t,yCount:n,zCount:r}=this.gridConfig;try{for(let i=0;i<t;i++)for(let o=0;o<n;o++)for(let a=0;a<r;a++)if(e[i]&&e[i][o]&&e[i][o][a]&&this.vertices[i]&&this.vertices[i][o]&&this.vertices[i][o][a]){if(this.vertices[i][o][a].copy(e[i][o][a]),this._isOnSurface(i,o,a,t,n,r)){const t=this.spheres.find(e=>e.userData.x===i&&e.userData.y===o&&e.userData.z===a);t&&t.position.copy(e[i][o][a])}this.updateEdgesForVertex(i,o,a)}return this.updateTargetObjectDeformation(),!0}catch(e){return console.error("恢复晶格顶点状态失败:",e),!1}}getFullStateSnapshot(){return{vertices:this.getLatticeVerticesSnapshot(),hasLattice:this.getLatticeGrid()}}createDeformationHistoryAction(e){const t=this.getFullStateSnapshot();return{type:"LATTICE_DEFORMATION",data:{beforeSnapshot:e,afterSnapshot:t},undo:()=>{e.vertices&&this.restoreLatticeVerticesSnapshot(e.vertices)},redo:()=>{t.vertices&&this.restoreLatticeVerticesSnapshot(t.vertices)}}}setPadding(e){return"number"==typeof e&&e>0?(this.padding=e,this):(console.warn("无效的填充值:",e),this)}getPadding(){return this.padding}updateLatticeConfig(e){if(Object.assign(this.gridConfig,e),this.getLatticeGrid()&&this.targetObjects.length>0){const e=[...this.targetObjects];this.clearLattice(),this.setTargetObjects(e).createLattice()}return this}preserveCurrentDeformation(){if(!this.targetObjects.length)return console.warn("没有目标对象,无法保存当前形变状态"),!1;let e=0;return this.targetObjects.forEach(t=>{if(t&&t.geometry)try{const n=t.geometry.clone();this.originalGeometries.set(t.uuid,n),e++,console.log(`已保存对象 ${t.uuid} 的当前形变状态`)}catch(e){console.error(`保存对象 ${t.uuid} 的形变状态失败:`,e)}}),e>0?(console.log(`成功保存了 ${e} 个对象的形变状态`),this.initializeCache(),!0):(console.warn("没有成功保存任何对象的形变状态"),!1)}}class Zp extends x{constructor(e,t){super(),this.isViewHelper=!0,this.animating=!1,this.center=new f;const n={left:0,bottom:0},r=new K("#ff4466"),i=new K("#88ff44"),o=new K("#4488ff"),a=new K("#000000"),s={},c=[],l=new w,u=new v,h=new x,d=new Se(-2,2,2,-2,0,4);d.position.set(0,0,2);const p=new A(.04,.04,.8,5).rotateZ(-Math.PI/2).translate(.4,0,0),m=new S(p,W(r)),g=new S(p,W(i)),b=new S(p,W(o));g.rotation.z=Math.PI/2,b.rotation.y=-Math.PI/2,this.add(m),this.add(b),this.add(g);const T=X(r,"X"),C=X(i,"Y"),O=X(o,"Z"),k=X(a),R=new ot(T),M=new ot(C),I=new ot(O),P=new ot(k),N=new ot(k),L=new ot(k);R.position.x=1,M.position.y=1,I.position.z=1,P.position.x=-1,N.position.y=-1,L.position.z=-1,P.material.opacity=.2,N.material.opacity=.2,L.material.opacity=.2,R.userData.type="posX",M.userData.type="posY",I.userData.type="posZ",P.userData.type="negX",N.userData.type="negY",L.userData.type="negZ",this.add(R),this.add(M),this.add(I),this.add(P),this.add(N),this.add(L),c.push(R),c.push(M),c.push(I),c.push(P),c.push(N),c.push(L);const D=new f,j=128,F=2*Math.PI;this.render=function(t){this.quaternion.copy(e.quaternion).invert(),this.updateMatrixWorld(),D.set(0,0,1),D.applyQuaternion(e.quaternion);const r=n.left,i=n.bottom;t.clearDepth(),t.getViewport(V),t.setViewport(r,i,j,j),t.render(this,d),t.setViewport(V.x,V.y,V.z,V.w)},this.setOffset=function(e,t){n.left=e,n.bottom=t};const U=new f,B=new y,z=new y,H=new y,V=new He;let G=0;function W(e){return new E({color:e,toneMapped:!1})}function X(e,t){const{font:n="20px Arial",color:r="#000000",radius:i=14}=s,o=document.createElement("canvas");o.width=64,o.height=64;const a=o.getContext("2d");a.beginPath(),a.arc(32,32,i,0,2*Math.PI),a.closePath(),a.fillStyle=e.getStyle(),a.fill(),t&&(a.font=n,a.textAlign="center",a.fillStyle=r,a.fillText(t,32,41));const c=new at(o);return c.colorSpace=Y,new st({map:c,toneMapped:!1})}function q(){R.material.map.dispose(),M.material.map.dispose(),I.material.map.dispose(),R.material.dispose(),M.material.dispose(),I.material.dispose(),R.material=X(r,s.labelX),M.material=X(i,s.labelY),I.material=X(o,s.labelZ)}this.handleClick=function(r){if(!0===this.animating)return!1;const i=t.getBoundingClientRect(),o=i.left+n.left,a=i.top,s=r.clientX,p=r.clientY;if(s<o||s>o+j||p<a||p>a+j)return!1;u.x=(s-o)/j*2-1,u.y=-(p-a)/j*2+1,l.setFromCamera(u,d);const f=l.intersectObjects(c);if(f.length>0){return function(t,n){switch(t.userData.type){case"posX":U.set(1,0,0),B.setFromEuler(new _(0,.5*Math.PI,0));break;case"posY":U.set(0,1,0),B.setFromEuler(new _(.5*-Math.PI,0,0));break;case"posZ":U.set(0,0,1),B.setFromEuler(new _);break;case"negX":U.set(-1,0,0),B.setFromEuler(new _(0,.5*-Math.PI,0));break;case"negY":U.set(0,-1,0),B.setFromEuler(new _(.5*Math.PI,0,0));break;case"negZ":U.set(0,0,-1),B.setFromEuler(new _(0,Math.PI,0));break;default:console.error("ViewHelper: Invalid axis.")}G=e.position.distanceTo(n),U.multiplyScalar(G).add(n),h.position.copy(n),h.lookAt(e.position),z.copy(h.quaternion),h.lookAt(U),H.copy(h.quaternion)}(f[0].object,this.center),this.animating=!0,!0}return!1},this.setLabels=function(e,t,n){s.labelX=e,s.labelY=t,s.labelZ=n,q()},this.setLabelStyle=function(e,t,n){s.font=e,s.color=t,s.radius=n,q()},this.update=function(t){const n=t*F;z.rotateTowards(H,n),e.position.set(0,0,1).applyQuaternion(z).multiplyScalar(G).add(this.center),e.quaternion.rotateTowards(B,n),0===z.angleTo(H)&&(this.animating=!1)},this.dispose=function(){p.dispose(),m.material.dispose(),g.material.dispose(),b.material.dispose(),R.material.map.dispose(),M.material.map.dispose(),I.material.map.dispose(),P.material.map.dispose(),N.material.map.dispose(),L.material.map.dispose(),R.material.dispose(),M.material.dispose(),I.material.dispose(),P.material.dispose(),N.material.dispose(),L.material.dispose()}}}class $p{constructor(e,t,n,r){this.scene=e,this.camera=t,this.renderer=n,this.mainControls=r,this.transformControl=r?.transformControl||null,this.isFourView=!1,this.container=this.renderer.domElement.parentElement,this.width=this.container.clientWidth,this.height=this.container.clientHeight,this.originalCamera=null,this.dividers=null,this.viewConfig=[{name:"前视图",id:"front-view",position:"leftTop",cameraType:"front"},{name:"顶视图",id:"top-view",position:"leftBottom",cameraType:"top"},{name:"右视图",id:"right-view",position:"rightTop",cameraType:"right"},{name:"透视图",id:"perspective-view",position:"rightBottom",cameraType:"perspective"}],this.views=null,this._animationId=null,this.activeViewIndex=-1,this.currentLayout=null}setFourView(){this.setCustomView([{x:0,y:0,width:.5,height:.5},{x:0,y:.5,width:.5,height:.5},{x:.5,y:0,width:.5,height:.5},{x:.5,y:.5,width:.5,height:.5}])}setCustomView(e){if(this.scene&&this.camera&&this.renderer){if(this.isFourView||0===e.length){if(this._isSameLayout(e)||e[0].mainScene)return void this.exitFourView();this._removeViews()}this.originalCamera={position:this.camera.position.clone(),target:this.mainControls.target.clone(),up:this.camera.up.clone(),zoom:this.camera.zoom,fov:this.camera.fov},this.transformControl&&this.transformControl.parent&&this.transformControl.parent.remove(this.transformControl),this.renderer.domElement.style.display="none",this.currentLayout=[...e],this._createCustomViews(e),this.isFourView=!0,this._startRenderLoop(),this._handleResize=this.onWindowResize.bind(this),window.addEventListener("resize",this._handleResize)}}getSelectableObjects(){let t=[];return this.mainControls&&"function"==typeof this.mainControls.getSelectableObjects?t=this.mainControls.getSelectableObjects():this.scene&&this.scene.traverse(n=>{n instanceof e.Camera||n instanceof e.Light||n instanceof e.Scene||n instanceof e.Object3D&&0===n.children.length&&!n.geometry||!n.userData.selectable||t.push(n)}),t}_handleObjectSelection(e,t){if(console.log(e,t),this.activeViewIndex!==t&&-1!==this.activeViewIndex){this.views[this.activeViewIndex].control.clearSelection()}this.activeViewIndex=t,this.transformControl&&this.transformControl.parent&&this.transformControl.parent.remove(this.transformControl),this.views.forEach(e=>{e.index!==t&&e.control.clearSelection()}),e&&e.length>0&&(this.transformControl&&!this.transformControl.parent&&this.scene.add(this.transformControl),this.transformControl&&this.transformControl.attach(e[0]))}_activateView(e){if(!(e<0||e>=this.views.length)){if(this.activeViewIndex!==e&&-1!==this.activeViewIndex){this.views[this.activeViewIndex].control.clearSelection(),this.transformControl&&this.transformControl.parent&&this.transformControl.parent.remove(this.transformControl)}this.activeViewIndex=e}}_isSameLayout(e){if(!this.currentLayout||this.currentLayout.length!==e.length)return!1;for(let t=0;t<this.currentLayout.length;t++){const n=this.currentLayout[t],r=e[t];if(n.x!==r.x||n.y!==r.y||n.width!==r.width||n.height!==r.height)return!1}return!0}_createCustomViews(t){this._removeViews(),this.views=[];const n=this.getSelectableObjects(),r=this._getCameraTypesForLayout(t);t.forEach((i,o)=>{const a=Math.floor(this.width*i.x),s=Math.floor(this.height*i.y),c=Math.floor(this.width*i.width),l=Math.floor(this.height*i.height),u=r[o].type,h=r[o].name,d=document.createElement("div");d.id=`view-${o}`,d.style.cssText=`\n position: absolute;\n left: ${a}px;\n top: ${s}px;\n width: ${c}px;\n height: ${l}px;\n overflow: hidden;\n box-sizing: border-box;\n border: 1px solid rgba(60, 60, 60, 0.8);\n background-color: rgba(42, 42, 42, 1);\n box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);\n `;const p=new e.WebGLRenderer({antialias:!0,alpha:!0});p.setSize(c,l),p.setClearColor(2763306),p.setPixelRatio(window.devicePixelRatio),d.appendChild(p.domElement);const f=document.createElement("div");f.textContent=h,f.style.cssText="\n position: absolute;\n left: 10px;\n top: 10px;\n color: white;\n background-color: rgba(0, 0, 0, 0.5);\n padding: 4px 8px;\n border-radius: 4px;\n font-size: 12px;\n pointer-events: none;\n z-index: 101;\n ",t.length>1&&d.appendChild(f),this.container.appendChild(d);const m=c/l,g=new e.PerspectiveCamera(20,m,.1,1e3);switch(u){case"top":g.position.set(0,0,20),g.lookAt(0,0,0),g.up.set(0,1,0);break;case"front":g.position.set(0,-20,0),g.lookAt(0,0,0),g.up.set(0,0,1);break;case"right":g.position.set(20,0,0),g.lookAt(0,0,0),g.up.set(0,0,1);break;case"left":g.position.set(-20,0,0),g.lookAt(0,0,0),g.up.set(0,0,1);break;case"back":g.position.set(0,20,0),g.lookAt(0,0,0),g.up.set(0,0,1);break;case"bottom":g.position.set(0,0,-20),g.lookAt(0,0,0),g.up.set(0,-1,0);break;default:g.position.set(-15,-15,15),g.lookAt(0,0,0),g.up.set(0,0,1)}const b=new po(this.scene,g,p.domElement,()=>{},e=>this._handleObjectSelection(e,o));b.enableDamping=!1,b.orbitControls.screenSpacePanning=!0,b.orbitControls.target.set(0,0,0),"perspective"!==u&&(b.orbitControls.enableRotate=!1),b.addObjects(n),b.update(),this.views.push({config:{name:h,cameraType:u,layout:i},container:d,renderer:p,camera:g,control:b,label:f,index:o})}),this.views.length>0&&(this.activeViewIndex=0,this._activateView(this.activeViewIndex))}_getCameraTypesForLayout(e){let t=[];if(1===e.length)t.push({type:"perspective",name:"透视图"});else if(2===e.length)t.push({type:"perspective",name:"透视图"}),t.push({type:"top",name:"顶视图"});else if(3===e.length)t.push({type:"front",name:"前视图"}),t.push({type:"top",name:"顶视图"}),t.push({type:"perspective",name:"透视图"});else if(4===e.length)t.push({type:"front",name:"前视图"}),t.push({type:"top",name:"顶视图"}),t.push({type:"right",name:"右视图"}),t.push({type:"perspective",name:"透视图"});else{const n=["left","back","bottom"];let r=0;for(let i=0;i<e.length;i++)if(0===i)t.push({type:"front",name:"前视图"});else if(1===i)t.push({type:"top",name:"顶视图"});else if(2===i)t.push({type:"right",name:"右视图"});else if(i===e.length-1)t.push({type:"perspective",name:"透视图"});else{const e=n[r%n.length];let o;switch(e){case"left":o="左视图";break;case"back":o="后视图";break;case"bottom":o="底视图";break;default:o=`视图 ${i+1}`}t.push({type:e,name:o}),r++}}return t}_startRenderLoop(){this._animationId&&(cancelAnimationFrame(this._animationId),this._animationId=null);const e=()=>{this._animationId=requestAnimationFrame(e),this.isFourView&&this.views.forEach(e=>{e.control.update(),e.renderer.render(this.scene,e.camera)})};e()}_removeViews(){this.views&&(this.views.forEach(e=>{if(e.renderer){e.renderer.renderTarget&&e.renderer.renderTarget.dispose();const t=e.renderer.getContext();if(t){const e=t.getExtension("WEBGL_lose_context");e&&e.loseContext()}e.renderer.domElement&&(e.renderer.domElement.width=1,e.renderer.domElement.height=1),e.renderer.dispose(),e.renderer=null}if(e.control&&(e.control.dispose(),e.control=null),e.container&&e.container.parentNode){for(;e.container.firstChild;)e.container.removeChild(e.container.firstChild);e.container.parentNode.removeChild(e.container)}}),this.views=null),this._handleResize&&(window.removeEventListener("resize",this._handleResize),this._handleResize=null)}exitFourView(){this.isFourView&&(this.transformControl&&this.transformControl.parent&&this.transformControl.parent.remove(this.transformControl),this.originalCamera&&(this.camera.position.copy(this.originalCamera.position),this.mainControls.target.copy(this.originalCamera.target),this.originalCamera.up&&this.camera.up.copy(this.originalCamera.up),this.originalCamera.zoom&&(this.camera.zoom=this.originalCamera.zoom),this.originalCamera.fov&&(this.camera.fov=this.originalCamera.fov),this.camera.updateProjectionMatrix(),this.mainControls.update(),this.originalCamera=null),this._animationId&&(cancelAnimationFrame(this._animationId),this._animationId=null),this.renderer.domElement.style.display="block",this._removeViews(),window.gc&&window.gc(),this.isFourView=!1,this.transformControl&&!this.transformControl.parent&&this.scene.add(this.transformControl),this.renderer.render(this.scene,this.camera),this.activeViewIndex=-1)}onWindowResize(){this.width=this.container.clientWidth,this.height=this.container.clientHeight,this.isFourView&&this.views&&this.views.forEach(e=>{const t=e.config.layout,n=Math.floor(this.width*t.x),r=Math.floor(this.height*t.y),i=Math.floor(this.width*t.width),o=Math.floor(this.height*t.height);e.container.style.left=`${n}px`,e.container.style.top=`${r}px`,e.container.style.width=`${i}px`,e.container.style.height=`${o}px`,e.renderer.setSize(i,o);const a=i/o;e.camera.aspect=a,e.camera.updateProjectionMatrix()})}}class Jp{constructor(e=50){this.history=[],this.redoStack=[],this.currentIndex=-1,this.maxHistorySteps=e,this.isPerformingAction=!1}addAction(e){this.isPerformingAction||(this.currentIndex<this.history.length-1&&(this.history.splice(this.currentIndex+1),this.redoStack=[]),this.history.push(e),this.currentIndex=this.history.length-1,this.history.length>this.maxHistorySteps&&(this.history.shift(),this.currentIndex--))}undo(){if(this.currentIndex<0)return!1;try{this.isPerformingAction=!0;const e=this.history[this.currentIndex];return e&&"function"==typeof e.undo?(e.undo(),this.redoStack.push(e),this.currentIndex--,this.isPerformingAction=!1,!0):(console.warn("撤销操作无效: 操作不存在或undo不是函数"),this.history.splice(this.currentIndex,1),this.currentIndex--,this.isPerformingAction=!1,this.undo())}catch(e){return console.error("撤销操作失败:",e),this.history.splice(this.currentIndex,1),this.currentIndex--,this.isPerformingAction=!1,!1}}redo(){if(0===this.redoStack.length)return!1;try{this.isPerformingAction=!0;const e=this.redoStack.pop();return e&&"function"==typeof e.redo?(e.redo(),this.currentIndex++,this.isPerformingAction=!1,!0):(console.warn("重做操作无效: 操作不存在或redo不是函数"),this.isPerformingAction=!1,this.redo())}catch(e){return console.error("重做操作失败:",e),this.isPerformingAction=!1,!1}}clear(){this.history=[],this.redoStack=[],this.currentIndex=-1}canUndo(){return this.currentIndex>=0}canRedo(){return this.redoStack.length>0}getState(){return{canUndo:this.canUndo(),canRedo:this.canRedo(),historyLength:this.history.length,redoLength:this.redoStack.length,currentIndex:this.currentIndex}}}class ef{constructor(e,t={}){this.options={clearColor:"#3F3F3F",backgroundColor:"#3F3F3F",showGrid:!0,showAxes:!0,showGround:!0,showLattice:!0,enableShadow:!0,maxHistorySteps:50,gridSize:1200,gridDivisions:800,gridColors:{x:10370122,z:6457640,grid:5592405},renderMode:"normal",renderModeOptions:{color:16777215,wireframeColor:0,opacity:1},storagePrefix:"iat3d-",exr:{enabled:!1,path:null,intensity:1,backgroundIntensity:1},...t},this.container=e,this.scene=null,this.camera=null,this.renderer=null,this.animationFrameId=null,this.lights={},this.currentRenderMode="normal",this.originalMaterials=new Map,this.exrTexture=null,this.exrLoader=null,this.initScene(),this.initCamera(),this.initRenderer(),this.initLights(),this.initEXRLoader(),this.historyManager=new Jp(this.options.maxHistorySteps),this.objectManager=new po(this.scene,this.camera,this.renderer.domElement,e=>{this.options.onObjectsChanged&&this.options.onObjectsChanged(e)},e=>{this.options.onObjectSelected&&this.options.onObjectSelected(e)},e=>{this.options.onTransformModeChanged&&this.options.onTransformModeChanged(e)}),this.objectManager.setSceneManager(this),this.initModelImporter(),this.addViewHelper(),this.options.showGrid&&this.addGrid(),this.options.showAxes&&this.addAxes(),this.options.showGround&&this.addGround(),this.fourView=new $p(this.scene,this.camera,this.renderer,this.objectManager.orbitControls),this.keyboardManager=new gl,this.LatticeController=new Qp(this.scene,this.camera,this.renderer),this.LatticeController.onDeformationUpdate=e=>{this._handleDeformationUpdate(e)},window.addEventListener("resize",this.onWindowResize.bind(this)),this.animate(),this.registerHistoryShortcuts(),this.loadSavedRenderMode(),this.activeCamera=null,this.mainCamera=null,this.isUsingActiveCamera=!1,this.mainCamera=this.camera}registerHistoryShortcuts(){this.keyboardManager&&(this.keyboardManager.register("ctrl+z",()=>(this.undo(),!0)),this.keyboardManager.register("ctrl+y",()=>(this.redo(),!0)))}undo(){const e=this.historyManager.undo();return e&&this.options.onHistoryChanged&&this.options.onHistoryChanged(this.getHistoryState()),e}redo(){const e=this.historyManager.redo();return e&&this.options.onHistoryChanged&&this.options.onHistoryChanged(this.getHistoryState()),e}addActionToHistory(e){this.historyManager.addAction(e),this.options.onHistoryChanged&&this.options.onHistoryChanged(this.getHistoryState())}getHistoryState(){return this.historyManager.getState()}clearHistory(){this.historyManager.clear(),this.options.onHistoryChanged&&this.options.onHistoryChanged(this.getHistoryState())}initScene(){this.scene=new e.Scene,this.scene.background=new e.Color(this.options.backgroundColor),this.scene.fog=new e.FogExp2(this.options.backgroundColor,.005),this.scene.userData.sceneManager=this}initCamera(){const t=this.container.clientWidth,n=this.container.clientHeight;this.camera=new e.PerspectiveCamera(20,t/n,.1,1e3),this.camera.position.set(-15,-15,15),this.camera.lookAt(0,0,0),this.camera.up.set(0,0,1)}initRenderer(){this.renderer=new e.WebGLRenderer({antialias:!0,alpha:!0}),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.renderer.setClearColor(this.options.backgroundColor),this.renderer.setPixelRatio(window.devicePixelRatio),this.options.enableShadow&&(this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=e.PCFSoftShadowMap),this.container.appendChild(this.renderer.domElement)}initLights(){this.lights.ambient=new e.AmbientLight(16777215,1),this.scene.add(this.lights.ambient),this.lights.directional=new e.DirectionalLight(16777215,1),this.lights.directional.position.set(5,-5,7.5),this.lights.directional.castShadow=!0,this.lights.directional.shadow.mapSize.width=2048,this.lights.directional.shadow.mapSize.height=2048,this.lights.directional.shadow.camera.near=.5,this.lights.directional.shadow.camera.far=50,this.lights.directional.shadow.camera.left=-20,this.lights.directional.shadow.camera.right=20,this.lights.directional.shadow.camera.top=20,this.lights.directional.shadow.camera.bottom=-20,this.scene.add(this.lights.directional),this.lights.hemisphere=new e.HemisphereLight(14544639,2105376,1),this.scene.add(this.lights.hemisphere)}initEXRLoader(){this.exrLoader||(this.exrLoader=new Dt,console.log("[ThreeSceneManager] EXR加载器已初始化"),this.loadEXR("/forest.exr",{intensity:1.5,backgroundIntensity:.8,showBackground:!1}))}async loadEXR(t,n={}){if(!t)return console.warn("[ThreeSceneManager] 请提供EXR文件路径"),!1;try{return this.initEXRLoader(),console.log("[ThreeSceneManager] 开始加载EXR文件:",t),new Promise((r,i)=>{this.exrLoader.load(t,i=>{i.mapping=e.EquirectangularReflectionMapping,this.exrTexture=i,this.applyEXRToScene(i,n),this.options.exr={enabled:!0,path:t,intensity:n.intensity||1,backgroundIntensity:n.backgroundIntensity||1,...n},console.log("[ThreeSceneManager] EXR环境贴图加载成功"),this.options.onEXRLoaded&&this.options.onEXRLoaded(i,this.options.exr),r(i)},e=>{this.options.onEXRLoadProgress&&this.options.onEXRLoadProgress(e)},e=>{console.error("[ThreeSceneManager] EXR加载失败:",e),this.options.onEXRLoadError&&this.options.onEXRLoadError(e),i(e)})})}catch(e){return console.error("[ThreeSceneManager] EXR加载出错:",e),!1}}applyEXRToScene(e,t={}){if(!e||!this.scene)return;const n={intensity:1,backgroundIntensity:1,showBackground:!1,...t};this.scene.environment=e,this.scene.environmentIntensity=n.intensity,n.showBackground&&(this.scene.background=e,this.scene.backgroundIntensity=n.backgroundIntensity),console.log("[ThreeSceneManager] EXR环境贴图已应用到场景")}setEXRIntensity(e,t=null){return this.scene&&this.exrTexture?(void 0!==e&&e>=0&&(this.scene.environmentIntensity=e,this.options.exr.intensity=e),null!==t&&t>=0&&(this.scene.backgroundIntensity=t,this.options.exr.backgroundIntensity=t),console.log(`[ThreeSceneManager] EXR强度已更新: 环境=${e}, 背景=${t}`),!0):(console.warn("[ThreeSceneManager] 没有可用的EXR纹理"),!1)}setEXRBackgroundVisible(t){return this.scene&&this.exrTexture?(this.scene.background=t?this.exrTexture:new e.Color(this.options.backgroundColor),console.log("[ThreeSceneManager] EXR背景显示已"+(t?"启用":"禁用")),!0):(console.warn("[ThreeSceneManager] 没有可用的EXR纹理"),!1)}removeEXR(){this.scene&&(this.scene.environment=null,this.scene.background=new e.Color(this.options.backgroundColor),this.scene.environmentIntensity=1,this.scene.backgroundIntensity=1),this.exrTexture&&(this.exrTexture.dispose(),this.exrTexture=null),this.options.exr.enabled=!1,this.options.exr.path=null,console.log("[ThreeSceneManager] EXR环境贴图已移除"),this.options.onEXRRemoved&&this.options.onEXRRemoved()}getEXRStatus(){return{enabled:this.options.exr.enabled,hasTexture:!!this.exrTexture,path:this.options.exr.path,intensity:this.options.exr.intensity,backgroundIntensity:this.options.exr.backgroundIntensity,backgroundVisible:this.scene&&this.scene.background===this.exrTexture}}initModelImporter(){this.modelImporter=new pl(this.renderer.domElement,this.camera,this.scene,this.addObjects.bind(this))}addAxes(){const t=new e.AxesHelper(50);t.name="axesHelper",t.userData.selectable=!1,t.visible=!1,this.scene.add(t)}addGrid(){const{gridSize:e,gridDivisions:t,gridColors:n}=this.options,r=fl(e,t,n.x,n.z,n.grid);r.name="gridHelper",r.userData.selectable=!1,r.rotation.x=-Math.PI/2,this.scene.add(r)}addGround(){const t=new e.PlaneGeometry(2e3,2e3),n=new e.ShadowMaterial({opacity:.5}),r=new e.Mesh(t,n);r.name="shadowPlane",r.receiveShadow=!0,r.userData.selectable=!1,this.scene.add(r)}addViewHelper(){this.viewHelper=new Zp(this.camera,this.renderer.domElement),this.renderer.autoClear=!1,this.viewHelper.setOffset(210,40)}getSceneObjects(){return this.objectManager.selectableObjects}focusSelectedObject(){const t=this.objectManager.selectedObjects;if(!(t&&t.length&&this.camera&&this.objectManager.orbitControls))return console.warn("没有选中对象或场景组件未完全初始化"),!1;try{const n=(new e.Box3).setFromObject(t[0]),r=n.getSize(new e.Vector3).length(),i=n.getCenter(new e.Vector3);return this.camera.position.copy(i),this.camera.position.x+=1.5*r,this.camera.position.y+=1.5*r,this.camera.position.z+=1.5*r,this.camera.lookAt(i),this.objectManager.orbitControls.target.copy(i),this.objectManager.orbitControls.update(),!0}catch(e){return console.error("聚焦对象时出错:",e),!1}}setCameraDirectly(e,t){if(!(this.camera&&this.objectManager.orbitControls&&this.renderer&&this.scene))return!1;try{return this.camera.position.copy(e),this.objectManager.orbitControls.target.copy(t),this.camera.lookAt(t),this.objectManager.orbitControls.update(),this.renderer.render(this.scene,this.camera),!0}catch(e){return console.error("设置摄像机位置出错:",e),!1}}deleteSelectedObjects(){const e=[...this.objectManager.selectedObjects];if(!e||0===e.length)return console.warn("没有选中对象"),!1;const t=e.map(e=>({object:e,parent:e.parent,index:e.parent?Array.from(e.parent.children).indexOf(e):-1,relatedCamera:e.userData?.isCameraHelper?e.userData.parentCamera:null}));return this.objectManager.removeSelectableObjects(e),this.addActionToHistory({type:"DELETE_OBJECTS",data:{objectsData:t},undo:()=>{t.forEach(e=>{e.object&&e.parent&&(e.index>=0&&e.index<e.parent.children.length?e.parent.children.splice(e.index,0,e.object):e.parent.add(e.object),e.relatedCamera&&!e.relatedCamera.parent&&this.scene.add(e.relatedCamera),this.objectManager.addObjects(e.object))})},redo:()=>{this.objectManager.removeSelectableObjects(t.map(e=>e.object))}}),!0}createLattice(e,t={}){const n=Array.isArray(e)?e:[e];if(!n.length)return console.warn("没有提供目标对象,无法创建晶格"),!1;const r=n.filter(e=>e&&e.visible);if(!r.length)return console.warn("没有有效的目标对象,无法创建晶格"),!1;console.log(`为 ${r.length} 个对象创建统一晶格`);const i={objects:r.map(e=>({object:e,originalGeometry:e.geometry?e.geometry.clone():null,isLatticeMode:e.userData.isLatticeMode||!1})),objectManagerEnabled:this.objectManager.enabled,objectManagerBanned:this.objectManager.isBaned,transformControlsAttached:null!==this.objectManager.transformControls.object,selectedObjects:[...this.objectManager.selectedObjects],latticeConfig:{xCount:t.xCount||3,yCount:t.yCount||3,zCount:t.zCount||3,padding:void 0!==t.padding?t.padding:1}};return this.objectManager.outlineManager.removeAllHighlights(),(t.xCount||t.yCount||t.zCount)&&this.LatticeController.setGridConfig({xCount:t.xCount||3,yCount:t.yCount||3,zCount:t.zCount||3}),void 0!==t.padding&&this.LatticeController.setPadding(t.padding),this.LatticeController.setTargetObjects(r).createLattice(),this.objectManager.enabled=!1,this.objectManager.isBaned=!0,this.objectManager.transformControls.detach(),this.addActionToHistory({type:"CREATE_LATTICE",data:{beforeState:i,targetObjects:r,latticeConfig:i.latticeConfig},undo:()=>{this.LatticeController.getLatticeGrid()&&this.exitLatticeGrid(),i.objects.forEach(({object:e,originalGeometry:t,isLatticeMode:n})=>{e&&t&&(e.geometry&&e.geometry.dispose(),e.geometry=t),e&&e.userData&&(e.userData.isLatticeMode=n)}),this.objectManager.enabled=i.objectManagerEnabled,this.objectManager.isBaned=i.objectManagerBanned,this.objectManager.clearSelection(),i.selectedObjects.forEach(e=>{e&&e.parent&&(this.objectManager.selectedObjects.push(e),this.objectManager.outlineManager.addHighlight(e))}),i.transformControlsAttached&&i.selectedObjects.length>0&&this.objectManager.transformControls.attach(i.selectedObjects[0])},redo:()=>{}}),!0}exitLatticeGrid(){if(!this.LatticeController.getLatticeGrid())return console.warn("当前没有活动的晶格"),[];this.LatticeController.getTargetObjects(),this.LatticeController.getLatticeConfig(),this.LatticeController.getLatticeVerticesSnapshot(),this.LatticeController.getTargetObjects().map(e=>({object:e,geometry:e.geometry?e.geometry.clone():null})),this.objectManager.enabled,this.objectManager.isBaned;const e=this.LatticeController.exitLatticeGrid();return this.objectManager.enabled=!0,this.objectManager.isBaned=!1,e}addCube(t={}){const n={size:1,color:10790568,position:{x:0,y:.5,z:0},castShadow:!0,receiveShadow:!0,...t},r=new e.BoxGeometry(n.size,n.size,n.size,10,10,10),i=new e.MeshStandardMaterial({color:n.color}),o=new e.Mesh(r,i);return o.position.set(n.position.x,n.position.y,n.position.z),o.castShadow=n.castShadow,o.receiveShadow=n.receiveShadow,this.scene.add(o),this.addObjects(o),o}addObjects(e){const t=Array.isArray(e)?e:[e];return t.forEach(e=>{e&&!e.userData&&(e.userData={}),e&&void 0===e.userData.selectable&&(e.userData.selectable=!0),e&&e.userData.isHelper&&(e.userData.selectable=!0)}),this.objectManager.addObjects(e),this.updateObjectRenderMode(t),t.length>0&&t[0]&&t[0].userData&&!t[0].userData.skipHistory&&this.addActionToHistory({type:"ADD_OBJECTS",data:{objects:t},undo:()=>{t&&t.length>0&&this.objectManager.removeSelectableObjects(t)},redo:()=>{t&&t.length>0&&(t.forEach(e=>{if(e){(e.parent||this.scene).add(e)}}),this.objectManager.addObjects(t))}}),e}getObjectManager(){return this.objectManager}getObjectById(e){let t=null;return this.scene.traverse(n=>{n.userData&&n.userData.id===e&&(t=n)}),t}selectObject(e){e&&(this.objectManager.clearSelection(),this.objectManager.selectedObjects.push(e),this.objectManager.outlineManager.addHighlight(e),this.objectManager.transformControls.attach(e))}setTransformMode(e){this.objectManager.setTransformMode(e)}getRenderModeOptions(){const e={wireframe:"线框",solid:"实体",material:"材质预览",rendered:"渲染"};return["wireframe","solid","material","rendered"].map(t=>({value:t,label:e[t]||t}))}setRenderMode(e,t={}){if(this.currentRenderMode==e)return!1;const n=this.getModelObjects(),r={...this.options.renderModeOptions,...t};return this.currentRenderMode=e,n.forEach(t=>{this._applyRenderModeToObject(t,e,r)}),this.saveToLocalStorage("topBar-shadingMode",e),this.options.onRenderModeChanged&&this.options.onRenderModeChanged(e),!0}getCurrentRenderMode(){return this.currentRenderMode}_applyRenderModeToObject(t,n,r){if("normal"===n.toLowerCase()){const e=this.originalMaterials.get(t.uuid);return void(e&&(t.material=e,this.originalMaterials.delete(t.uuid)))}!this.originalMaterials.has(t.uuid)&&t.material&&this.originalMaterials.set(t.uuid,t.material);const i={wireframe:()=>new e.MeshBasicMaterial({color:r.wireframeColor,wireframe:!0,transparent:r.opacity<1,opacity:r.opacity}),material:()=>new e.MeshNormalMaterial({transparent:r.opacity<1,opacity:r.opacity}),rendered:()=>new e.MeshPhongMaterial({color:r.color,transparent:r.opacity<1,opacity:r.opacity,shininess:100,specular:1118481})}[n.toLowerCase()];i&&(t.material=i())}getModelObjects(){const e=this.getSceneObjects()||[],t=[],n=["gridHelper","shadowPlane","axesHelper"];return e.forEach(e=>{n.includes(e.name)||e.userData&&(e.userData.isHelper||e.userData.isHidden)||e.traverse(e=>{!e.isMesh&&e.userData.isHidden||n.includes(e.name)||t.push(e)})}),t}updateObjectRenderMode(e){if("normal"===this.currentRenderMode)return;const t=Array.isArray(e)?e:[e],n=this.options.renderModeOptions;t.forEach(e=>{e.traverse(e=>{e.isMesh&&this._applyRenderModeToObject(e,this.currentRenderMode,n)})})}onWindowResize(){if(!this.container)return;const e=this.container.clientWidth,t=this.container.clientHeight;if(this.camera){if(this.camera.isPerspectiveCamera)this.camera.aspect=e/t;else if(this.camera.isOrthographicCamera){const n=e/t,r=5;this.camera.left=-r*n,this.camera.right=r*n,this.camera.top=r,this.camera.bottom=-r}this.camera.updateProjectionMatrix()}this.savedMainCameraState&&this.mainCamera&&this.mainCamera.isPerspectiveCamera&&(this.savedMainCameraState.aspect=e/t),this.renderer&&this.renderer.setSize(e,t)}animate(){this.animationFrameId=requestAnimationFrame(this.animate.bind(this)),this.objectManager&&this.objectManager.update(),this.options.onUpdate&&this.options.onUpdate(),this.renderer.render(this.scene,this.camera),this.viewHelper&&this.viewHelper.render(this.renderer)}registerShortcut(e,t){this.keyboardManager.register(e,t)}dispose(){this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),window.removeEventListener("resize",this.onWindowResize),this.objectManager&&this.objectManager.dispose(),this.historyManager.clear(),this.exrTexture&&(this.exrTexture.dispose(),this.exrTexture=null),this.renderer&&(this.renderer.dispose(),this.container&&this.container.removeChild(this.renderer.domElement)),this.scene=null,this.camera=null,this.renderer=null,this.lights={},this.objectManager=null,this.historyManager=null,this.keyboardManager&&this.keyboardManager.dispose(),this.originalMaterials.clear(),this.originalMaterials=null}setActiveCamera(e){if(!e||!e.isCamera)return console.warn("提供的对象不是有效的相机"),!1;const t=this.isUsingActiveCamera;return this.activeCamera=e,console.log("活动相机已设置:",e.userData.cameraType||"unknown"),t&&e&&setTimeout(()=>{this.switchToActiveCameraView()},10),this.options.onActiveCameraChanged&&this.options.onActiveCameraChanged(e),!0}isInActiveCameraView(){return this.isUsingActiveCamera}clearActiveCamera(){this.isUsingActiveCamera&&this.switchToMainCameraView(),this.activeCamera=null,this.savedMainCameraState=null,this.savedOrbitControlsState=null,this.options.onActiveCameraChanged&&this.options.onActiveCameraChanged(null),console.log("活动相机已清除")}getActiveCamera(){return this.activeCamera}getSceneCameras(){const e=[];return this.scene.traverse(t=>{t.userData&&t.userData.isCameraHelper&&t.userData.parentCamera&&e.push({helper:t,camera:t.userData.parentCamera,name:t.userData.parentCamera.name||`相机_${t.userData.parentCamera.uuid.substring(0,8)}`,type:t.userData.parentCamera.isPerspectiveCamera?"perspective":"orthographic"})}),e}updateCameraDependencies(){this.viewHelper&&(this.viewHelper.camera=this.camera),this.objectManager&&(this.objectManager.camera=this.camera,this.objectManager.transformControls&&(this.objectManager.transformControls.camera=this.camera),this.objectManager.orbitControls&&(this.objectManager.orbitControls.object=this.camera,this.objectManager.orbitControls.update())),this.fourView&&(this.fourView.camera=this.camera),this.LatticeController&&(this.LatticeController.camera=this.camera)}switchToActiveCameraView(){if(!this.activeCamera)return console.warn("没有设置活动相机"),!1;try{this.isUsingActiveCamera||(this.saveMainCameraState(),console.log("已保存主相机状态")),this.objectManager&&(this.objectManager.clearSelection(),this.objectManager.outlineManager.removeAllHighlights()),this.objectManager.transformControls.detach(),this.disableActiveCameraHelper(),console.log(this.activeCamera,"活动相机");const t=this.container.clientWidth,n=this.container.clientHeight;if(this.activeCamera.isPerspectiveCamera)this.activeCamera.aspect=t/n;else if(this.activeCamera.isOrthographicCamera){const e=t/n,r=5;this.activeCamera.left=-r*e,this.activeCamera.right=r*e,this.activeCamera.top=r,this.activeCamera.bottom=-r}this.activeCamera.updateProjectionMatrix(),this.camera=this.activeCamera,this.isUsingActiveCamera=!0,this.updateCameraDependencies();const r=new e.Vector3(0,0,-1);r.applyQuaternion(this.activeCamera.quaternion);const i=10,o=this.activeCamera.position.clone().add(r.multiplyScalar(i));return this.objectManager.orbitControls&&(this.objectManager.orbitControls.object=this.activeCamera,this.objectManager.orbitControls.target.copy(o),this.objectManager.orbitControls.update()),console.log("已固定到活动相机视角"),this.options.onCameraViewChanged&&this.options.onCameraViewChanged(this.activeCamera,!0),!0}catch(e){return console.error("切换到活动相机视角失败:",e),!1}}saveMainCameraState(){this.mainCamera&&(this.savedMainCameraState?console.log("主相机状态已存在,跳过保存"):(this.savedMainCameraState={position:this.mainCamera.position.clone(),rotation:this.mainCamera.rotation.clone(),quaternion:this.mainCamera.quaternion.clone(),fov:this.mainCamera.fov,aspect:this.mainCamera.aspect,near:this.mainCamera.near,far:this.mainCamera.far,left:this.mainCamera.left,right:this.mainCamera.right,top:this.mainCamera.top,bottom:this.mainCamera.bottom},this.objectManager.orbitControls&&(this.savedOrbitControlsState={target:this.objectManager.orbitControls.target.clone(),position0:this.objectManager.orbitControls.position0.clone(),target0:this.objectManager.orbitControls.target0.clone(),zoom0:this.objectManager.orbitControls.zoom0,enableDamping:this.objectManager.orbitControls.enableDamping,dampingFactor:this.objectManager.orbitControls.dampingFactor,enabled:this.objectManager.orbitControls.enabled,autoRotate:this.objectManager.orbitControls.autoRotate,spherical:{radius:this.objectManager.orbitControls.getDistance(),phi:this.objectManager.orbitControls.getPolarAngle(),theta:this.objectManager.orbitControls.getAzimuthalAngle()}}),console.log("主相机状态已首次保存")))}switchToMainCameraView(){if(!this.isUsingActiveCamera||!this.mainCamera)return console.warn("当前未使用活动相机视角"),!1;try{if(this.enableActiveCameraHelper(),this.camera=this.mainCamera,this.isUsingActiveCamera=!1,this.savedMainCameraState)this.restoreMainCameraState();else{const e=this.container.clientWidth,t=this.container.clientHeight;this.camera.isPerspectiveCamera&&(this.camera.aspect=e/t,this.camera.updateProjectionMatrix())}return this.updateCameraDependencies(),this.objectManager.orbitControls&&this.restoreOrbitControlsState(),console.log("已返回主相机视角"),this.options.onCameraViewChanged&&this.options.onCameraViewChanged(this.camera,!1),!0}catch(e){return console.error("返回主相机视角失败:",e),!1}}restoreMainCameraState(){if(this.savedMainCameraState&&this.mainCamera)try{this.mainCamera.position.copy(this.savedMainCameraState.position),this.mainCamera.rotation.copy(this.savedMainCameraState.rotation),this.mainCamera.quaternion.copy(this.savedMainCameraState.quaternion),this.mainCamera.isPerspectiveCamera?(this.mainCamera.fov=this.savedMainCameraState.fov,this.mainCamera.aspect=this.savedMainCameraState.aspect,this.mainCamera.near=this.savedMainCameraState.near,this.mainCamera.far=this.savedMainCameraState.far):this.mainCamera.isOrthographicCamera&&(this.mainCamera.left=this.savedMainCameraState.left,this.mainCamera.right=this.savedMainCameraState.right,this.mainCamera.top=this.savedMainCameraState.top,this.mainCamera.bottom=this.savedMainCameraState.bottom,this.mainCamera.near=this.savedMainCameraState.near,this.mainCamera.far=this.savedMainCameraState.far),this.mainCamera.updateProjectionMatrix(),console.log("主相机状态已恢复")}catch(e){console.error("恢复主相机状态失败:",e)}}restoreOrbitControlsState(){if(!this.objectManager.orbitControls||!this.savedOrbitControlsState)return;const t=this.objectManager.orbitControls,n=this.savedOrbitControlsState;try{if(t.enabled=!1,t.object=this.camera,t.target.copy(n.target),n.position0&&t.position0.copy(n.position0),n.target0&&t.target0.copy(n.target0),void 0!==n.zoom0&&(t.zoom0=n.zoom0),n.spherical){const t=n.spherical,r=new e.Vector3;r.setFromSphericalCoords(t.radius,t.phi,t.theta),this.camera.position.copy(n.target).add(r)}t.enableDamping=n.enableDamping,t.dampingFactor=n.dampingFactor,t.autoRotate=n.autoRotate,this.camera.updateMatrixWorld(!0),t.update(),setTimeout(()=>{t&&void 0!==n.enabled&&(t.enabled=n.enabled)},100),console.log("轨道控制器状态已恢复")}catch(e){console.error("恢复轨道控制器状态失败:",e),t.enabled=!0}}syncCameraFOV(e){!e||e<=0||e>=180||(this.scene.traverse(t=>{if(t.userData&&t.userData.isCameraHelper&&t.userData.parentCamera){const n=t.userData.parentCamera;n.isPerspectiveCamera&&n!==this.mainCamera&&(n.fov=e,n.updateProjectionMatrix(),t.update&&"function"==typeof t.update&&t.update())}}),console.log("已同步场景中的透视相机FOV(不包括主相机)"))}syncOrthographicCameraParams(e){e&&(this.scene.traverse(t=>{if(t.userData&&t.userData.isCameraHelper&&t.userData.parentCamera){const n=t.userData.parentCamera;n.isOrthographicCamera&&n!==this.mainCamera&&(void 0!==e.left&&(n.left=e.left),void 0!==e.right&&(n.right=e.right),void 0!==e.top&&(n.top=e.top),void 0!==e.bottom&&(n.bottom=e.bottom),n.updateProjectionMatrix(),t.update&&"function"==typeof t.update&&t.update())}}),console.log("已同步场景中的正交相机参数(不包括主相机)"))}disableActiveCameraHelper(){this.activeCamera&&this.scene.traverse(e=>{if(e.userData&&e.userData.isCameraHelper&&e.userData.parentCamera===this.activeCamera){if(e.userData.selectable=!1,this.objectManager&&this.objectManager.selectedObjects.includes(e)){const t=this.objectManager.selectedObjects.indexOf(e);-1!==t&&this.objectManager.selectedObjects.splice(t,1),this.objectManager.outlineManager.removeHighlight(e),0===this.objectManager.selectedObjects.length?this.objectManager.transformControls.detach():this.objectManager._attachTransformToMultipleObjects(this.objectManager.selectedObjects),this.objectManager.onSelectionChange&&this.objectManager.onSelectionChange(this.objectManager.selectedObjects)}const t=this.objectManager.selectableObjects.indexOf(e);-1!==t&&(e.userData.originalSelectableIndex=t,this.objectManager.selectableObjects.splice(t,1)),console.log("已禁用活动相机辅助器的选择功能")}})}enableActiveCameraHelper(){this.activeCamera&&this.scene.traverse(e=>{if(e.userData&&e.userData.isCameraHelper&&e.userData.parentCamera===this.activeCamera){if(e.userData.selectable=!0,!this.objectManager.selectableObjects.includes(e)){const t=e.userData.originalSelectableIndex;void 0!==t&&t>=0&&t<=this.objectManager.selectableObjects.length?this.objectManager.selectableObjects.splice(t,0,e):this.objectManager.selectableObjects.push(e),delete e.userData.originalSelectableIndex}console.log("已启用活动相机辅助器的选择功能")}})}handleCameraParamSync(e,t){this.isUsingActiveCamera&&this.activeCamera&&("fov"===e&&this.activeCamera.isPerspectiveCamera&&this.syncCameraFOV(t),this.activeCamera.isOrthographicCamera&&["left","right","top","bottom"].includes(e)&&this.syncOrthographicParamsToOtherCameras())}syncOrthographicParamsToOtherCameras(){if(!this.activeCamera||!this.activeCamera.isOrthographicCamera)return;this.activeCamera.left,this.activeCamera.right;const e=(this.activeCamera.top-this.activeCamera.bottom)/2;this.scene.traverse(t=>{if(t.userData&&t.userData.isCameraHelper&&t.userData.parentCamera){const n=t.userData.parentCamera;if(n.isOrthographicCamera&&n!==this.activeCamera&&n!==this.mainCamera){const r=this.container.clientWidth/this.container.clientHeight;n.left=-e*r,n.right=e*r,n.top=e,n.bottom=-e,n.updateProjectionMatrix(),t.update&&"function"==typeof t.update&&t.update()}}})}_handleDeformationUpdate(e){e&&0!==e.length&&this.objectManager.updateDeformedObjects(e)}saveToLocalStorage(e,t){try{const n=`${this.options.storagePrefix}${e}`,r="object"==typeof t?JSON.stringify(t):t.toString();localStorage.setItem(n,r)}catch(t){console.warn(`[ThreeSceneManager] 无法保存 ${e} 到本地存储:`,t)}}getFromLocalStorage(e,t=null){try{const n=`${this.options.storagePrefix}${e}`,r=localStorage.getItem(n);if(null===r)return t;try{return JSON.parse(r)}catch{return r}}catch(n){return console.warn(`[ThreeSceneManager] 无法从本地存储获取 ${e}:`,n),t}}loadSavedRenderMode(){try{const e=this.getFromLocalStorage("topBar-shadingMode","normal");["wireframe","normal","material","rendered"].includes(e)&&"normal"!==e&&(this.currentRenderMode=e,setTimeout(()=>{this.setRenderMode(e)},100))}catch(e){console.error("[ThreeSceneManager] 加载保存的着色模式失败:",e)}}convertToPBRMaterial(t,n={}){if(!t||!t.material)return console.warn("对象没有材质,无法转换为PBR材质"),!1;const r=t.material;if(r.isMeshStandardMaterial||r.isMeshPhysicalMaterial)return console.log("材质已经是PBR材质"),!0;const i=new e.MeshStandardMaterial({color:r.color?r.color.clone():new e.Color(16777215),map:r.map||null,transparent:r.transparent||!1,opacity:void 0!==r.opacity?r.opacity:1,side:void 0!==r.side?r.side:e.FrontSide,wireframe:r.wireframe||!1,metalness:void 0!==n.metalness?n.metalness:.5,roughness:void 0!==n.roughness?n.roughness:.5,normalMap:r.normalMap||null,bumpMap:r.bumpMap||null,envMap:r.envMap||null});return t.material=i,r.dispose&&r.dispose(),console.log("材质已转换为PBR材质"),!0}}class tf extends e.LineSegments{constructor(t){const n=new e.BufferGeometry,r=new e.LineBasicMaterial({color:16777215,vertexColors:!0,toneMapped:!1,transparent:!0,opacity:.8}),i=[],o=[],a={};function s(e,t){c(e),c(t)}function c(e){i.push(0,0,0),o.push(0,0,0),void 0===a[e]&&(a[e]=[]),a[e].push(i.length/3-1)}s("p","n1"),s("p","n2"),s("p","n3"),s("p","n4"),s("n1","n2"),s("n2","n4"),s("n4","n3"),s("n3","n1"),n.setAttribute("position",new e.Float32BufferAttribute(i,3)),n.setAttribute("color",new e.Float32BufferAttribute(o,3)),super(n,r),this.type="OptimizedCameraHelper",this.camera=t,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=a,this.update();const l=new e.Color(16711680),u=new e.Color(16755200);this.setColors(l,u)}setColors(e,t){const n=this.geometry.getAttribute("color");let r=0;for(let t=0;t<8;t++)n.setXYZ(r++,e.r,e.g,e.b);for(let e=0;e<8;e++)n.setXYZ(r++,t.r,t.g,t.b);n.needsUpdate=!0}update(){const t=this.geometry,n=this.pointMap,r=new e.Vector3,i=new e.Camera;i.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse),this.setPoint("p",n,t,i,0,0,-1.4,r),this.setPoint("n1",n,t,i,-3,-3,-1,r),this.setPoint("n2",n,t,i,3,-3,-1,r),this.setPoint("n3",n,t,i,-3,3,-1,r),this.setPoint("n4",n,t,i,3,3,-1,r),t.getAttribute("position").needsUpdate=!0}setPoint(e,t,n,r,i,o,a,s){s.set(i,o,a).unproject(r);const c=t[e];if(void 0!==c){const e=n.getAttribute("position");for(let t=0,n=c.length;t<n;t++)e.setXYZ(c[t],s.x,s.y,s.z)}}dispose(){this.geometry.dispose(),this.material.dispose()}}export{tf as CameraHelper,lo as ContextMenu,ml as EventEmitter,$p as FourView,fl as GridHelper,Jp as HistoryManager,gl as KeyboardManager,Qp as LatticeController,pl as ModelImporter,po as ObjectManager,co as OutlineManager,ef as ThreeSceneManager,Zp as ViewHelper,hl as handleDrop};
10
- //# sourceMappingURL=index.esm.js.map
9
+ var Zs=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Js=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.VERSION=void 0,e.VERSION="9.0.1"}),ec=Zs((e,t)=>{var n=e&&e.__spreadArray||function(e,t){for(var n=0,r=t.length,i=e.length;n<r;n++,i++)e[i]=t[n];return e};function r(e){return e&&0===e.length}function i(e){return null==e?[]:Object.keys(e)}function o(e){for(var t=[],n=Object.keys(e),r=0;r<n.length;r++)t.push(e[n[r]]);return t}function a(e,t){if(Array.isArray(e))for(var n=0;n<e.length;n++)t.call(null,e[n],n);else{if(!m(e))throw Error("non exhaustive match");var r=i(e);for(n=0;n<r.length;n++){var o=r[n],a=e[o];t.call(null,a,o)}}}function s(e,t){var n=[];if(Array.isArray(e))for(var r=0;r<e.length;r++){var i=e[r];t.call(null,i)&&n.push(i)}return n}function c(e,t){return s(e,function(e){return!t(e)})}function l(e,t){return!!m(e)&&e.hasOwnProperty(t)}function u(e,t){return void 0!==p(e,function(e){return e===t})}function h(e){for(var t=[],n=0;n<e.length;n++)t.push(e[n]);return t}function d(e){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}function p(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(t.call(null,r))return r}}function f(e,t,n){for(var r=Array.isArray(e),a=r?e:o(e),s=r?[]:i(e),c=n,l=0;l<a.length;l++)c=t.call(null,c,a[l],r?l:s[l]);return c}function m(e){return e instanceof Object}function g(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=0;r<t.length;r++)for(var o=t[r],a=i(o),s=0;s<a.length;s++){var c=a[s];l(e,c)||(e[c]=o[c])}return e}Object.defineProperty(e,"__esModule",{value:!0}),e.toFastProperties=e.timer=e.peek=e.isES2015MapSupported=e.PRINT_WARNING=e.PRINT_ERROR=e.packArray=e.IDENTITY=e.NOOP=e.merge=e.groupBy=e.defaults=e.assignNoOverwrite=e.assign=e.zipObject=e.sortBy=e.indexOf=e.some=e.difference=e.every=e.isObject=e.isRegExp=e.isArray=e.partial=e.uniq=e.compact=e.reduce=e.findAll=e.find=e.cloneObj=e.cloneArr=e.contains=e.has=e.pick=e.reject=e.filter=e.dropRight=e.drop=e.isFunction=e.isUndefined=e.isString=e.forEach=e.last=e.first=e.flatten=e.map=e.mapValues=e.values=e.keys=e.isEmpty=void 0,e.isEmpty=r,e.keys=i,e.values=o,e.mapValues=function(e,t){for(var n=[],r=i(e),o=0;o<r.length;o++){var a=r[o];n.push(t.call(null,e[a],a))}return n},e.map=function(e,t){for(var n=[],r=0;r<e.length;r++)n.push(t.call(null,e[r],r));return n},e.flatten=function e(t){for(var n=[],r=0;r<t.length;r++){var i=t[r];Array.isArray(i)?n=n.concat(e(i)):n.push(i)}return n},e.first=function(e){return r(e)?void 0:e[0]},e.last=function(e){var t=e&&e.length;return t?e[t-1]:void 0},e.forEach=a,e.isString=function(e){return"string"==typeof e},e.isUndefined=function(e){return void 0===e},e.isFunction=function(e){return e instanceof Function},e.drop=function(e,t){return void 0===t&&(t=1),e.slice(t,e.length)},e.dropRight=function(e,t){return void 0===t&&(t=1),e.slice(0,e.length-t)},e.filter=s,e.reject=c,e.pick=function(e,t){for(var n=Object.keys(e),r={},i=0;i<n.length;i++){var o=n[i],a=e[o];t(a)&&(r[o]=a)}return r},e.has=l,e.contains=u,e.cloneArr=h,e.cloneObj=d,e.find=p,e.findAll=function(e,t){for(var n=[],r=0;r<e.length;r++){var i=e[r];t.call(null,i)&&n.push(i)}return n},e.reduce=f,e.compact=function(e){return c(e,function(e){return null==e})},e.uniq=function(e,t){void 0===t&&(t=function(e){return e});var n=[];return f(e,function(e,r){var i=t(r);return u(n,i)?e:(n.push(i),e.concat(r))},[])},e.partial=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=[null].concat(t);return Function.bind.apply(e,r)},e.isArray=function(e){return Array.isArray(e)},e.isRegExp=function(e){return e instanceof RegExp},e.isObject=m,e.every=function(e,t){for(var n=0;n<e.length;n++)if(!t(e[n],n))return!1;return!0},e.difference=function(e,t){return c(e,function(e){return u(t,e)})},e.some=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n]))return!0;return!1},e.indexOf=function(e,t){for(var n=0;n<e.length;n++)if(e[n]===t)return n;return-1},e.sortBy=function(e,t){var n=h(e);return n.sort(function(e,n){return t(e)-t(n)}),n},e.zipObject=function(e,t){if(e.length!==t.length)throw Error("can't zipObject with different number of keys and values!");for(var n={},r=0;r<e.length;r++)n[e[r]]=t[r];return n},e.assign=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=0;r<t.length;r++)for(var o=t[r],a=i(o),s=0;s<a.length;s++){var c=a[s];e[c]=o[c]}return e},e.assignNoOverwrite=g,e.defaults=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return g.apply(void 0,n([{}],e))},e.groupBy=function(e,t){var n={};return a(e,function(e){var r=t(e),i=n[r];i?i.push(e):n[r]=[e]}),n},e.merge=function(e,t){for(var n=d(e),r=i(t),o=0;o<r.length;o++){var a=r[o],s=t[a];n[a]=s}return n},e.NOOP=function(){},e.IDENTITY=function(e){return e},e.packArray=function(e){for(var t=[],n=0;n<e.length;n++){var r=e[n];t.push(void 0!==r?r:void 0)}return t},e.PRINT_ERROR=function(e){console&&console.error&&console.error("Error: "+e)},e.PRINT_WARNING=function(e){console&&console.warn&&console.warn("Warning: "+e)},e.isES2015MapSupported=function(){return"function"==typeof Map},e.peek=function(e){return e[e.length-1]},e.timer=function(e){var t=(new Date).getTime(),n=e();return{time:(new Date).getTime()-t,value:n}},e.toFastProperties=function(e){function t(){}t.prototype=e;var n=new t;function r(){return typeof n.bar}return r(),r(),e}}),tc=Zs((e,t)=>{var n,r;n="undefined"!=typeof self?self:e,r=function(){function e(){}e.prototype.saveState=function(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}},e.prototype.restoreState=function(e){this.idx=e.idx,this.input=e.input,this.groupIdx=e.groupIdx},e.prototype.pattern=function(e){this.idx=0,this.input=e,this.groupIdx=0,this.consumeChar("/");var t=this.disjunction();this.consumeChar("/");for(var n={type:"Flags",loc:{begin:this.idx,end:e.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};this.isRegExpFlag();)switch(this.popChar()){case"g":a(n,"global");break;case"i":a(n,"ignoreCase");break;case"m":a(n,"multiLine");break;case"u":a(n,"unicode");break;case"y":a(n,"sticky")}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:n,value:t,loc:this.loc(0)}},e.prototype.disjunction=function(){var e=[],t=this.idx;for(e.push(this.alternative());"|"===this.peekChar();)this.consumeChar("|"),e.push(this.alternative());return{type:"Disjunction",value:e,loc:this.loc(t)}},e.prototype.alternative=function(){for(var e=[],t=this.idx;this.isTerm();)e.push(this.term());return{type:"Alternative",value:e,loc:this.loc(t)}},e.prototype.term=function(){return this.isAssertion()?this.assertion():this.atom()},e.prototype.assertion=function(){var e=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(e)};case"$":return{type:"EndAnchor",loc:this.loc(e)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(e)};case"B":return{type:"NonWordBoundary",loc:this.loc(e)}}throw Error("Invalid Assertion Escape");case"(":var t;switch(this.consumeChar("?"),this.popChar()){case"=":t="Lookahead";break;case"!":t="NegativeLookahead"}s(t);var n=this.disjunction();return this.consumeChar(")"),{type:t,value:n,loc:this.loc(e)}}!function(){throw Error("Internal Error - Should never get here!")}()},e.prototype.quantifier=function(e){var t,n=this.idx;switch(this.popChar()){case"*":t={atLeast:0,atMost:1/0};break;case"+":t={atLeast:1,atMost:1/0};break;case"?":t={atLeast:0,atMost:1};break;case"{":var r=this.integerIncludingZero();switch(this.popChar()){case"}":t={atLeast:r,atMost:r};break;case",":t=this.isDigit()?{atLeast:r,atMost:this.integerIncludingZero()}:{atLeast:r,atMost:1/0},this.consumeChar("}")}if(!0===e&&void 0===t)return;s(t)}if(!0!==e||void 0!==t)return s(t),"?"===this.peekChar(0)?(this.consumeChar("?"),t.greedy=!1):t.greedy=!0,t.type="Quantifier",t.loc=this.loc(n),t},e.prototype.atom=function(){var e,t=this.idx;switch(this.peekChar()){case".":e=this.dotAll();break;case"\\":e=this.atomEscape();break;case"[":e=this.characterClass();break;case"(":e=this.group()}return void 0===e&&this.isPatternCharacter()&&(e=this.patternCharacter()),s(e),e.loc=this.loc(t),this.isQuantifier()&&(e.quantifier=this.quantifier()),e},e.prototype.dotAll=function(){return this.consumeChar("."),{type:"Set",complement:!0,value:[i("\n"),i("\r"),i("\u2028"),i("\u2029")]}},e.prototype.atomEscape=function(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}},e.prototype.decimalEscapeAtom=function(){return{type:"GroupBackReference",value:this.positiveInteger()}},e.prototype.characterClassEscape=function(){var e,t=!1;switch(this.popChar()){case"d":e=l;break;case"D":e=l,t=!0;break;case"s":e=h;break;case"S":e=h,t=!0;break;case"w":e=u;break;case"W":e=u,t=!0}return s(e),{type:"Set",value:e,complement:t}},e.prototype.controlEscapeAtom=function(){var e;switch(this.popChar()){case"f":e=i("\f");break;case"n":e=i("\n");break;case"r":e=i("\r");break;case"t":e=i("\t");break;case"v":e=i("\v")}return s(e),{type:"Character",value:e}},e.prototype.controlLetterEscapeAtom=function(){this.consumeChar("c");var e=this.popChar();if(!1===/[a-zA-Z]/.test(e))throw Error("Invalid ");return{type:"Character",value:e.toUpperCase().charCodeAt(0)-64}},e.prototype.nulCharacterAtom=function(){return this.consumeChar("0"),{type:"Character",value:i("\0")}},e.prototype.hexEscapeSequenceAtom=function(){return this.consumeChar("x"),this.parseHexDigits(2)},e.prototype.regExpUnicodeEscapeSequenceAtom=function(){return this.consumeChar("u"),this.parseHexDigits(4)},e.prototype.identityEscapeAtom=function(){return{type:"Character",value:i(this.popChar())}},e.prototype.classPatternCharacterAtom=function(){switch(this.peekChar()){case"\n":case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:return{type:"Character",value:i(this.popChar())}}},e.prototype.characterClass=function(){var e=[],t=!1;for(this.consumeChar("["),"^"===this.peekChar(0)&&(this.consumeChar("^"),t=!0);this.isClassAtom();){var n=this.classAtom();if("Character"===n.type&&this.isRangeDash()){this.consumeChar("-");var r=this.classAtom();if("Character"===r.type){if(r.value<n.value)throw Error("Range out of order in character class");e.push({from:n.value,to:r.value})}else o(n.value,e),e.push(i("-")),o(r.value,e)}else o(n.value,e)}return this.consumeChar("]"),{type:"Set",complement:t,value:e}},e.prototype.classAtom=function(){switch(this.peekChar()){case"]":case"\n":case"\r":case"\u2028":case"\u2029":throw Error("TBD");case"\\":return this.classEscape();default:return this.classPatternCharacterAtom()}},e.prototype.classEscape=function(){switch(this.consumeChar("\\"),this.peekChar()){case"b":return this.consumeChar("b"),{type:"Character",value:i("\b")};case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}},e.prototype.group=function(){var e=!0;"?"===(this.consumeChar("("),this.peekChar(0))?(this.consumeChar("?"),this.consumeChar(":"),e=!1):this.groupIdx++;var t=this.disjunction();this.consumeChar(")");var n={type:"Group",capturing:e,value:t};return e&&(n.idx=this.groupIdx),n},e.prototype.positiveInteger=function(){var e=this.popChar();if(!1===r.test(e))throw Error("Expecting a positive integer");for(;n.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)},e.prototype.integerIncludingZero=function(){var e=this.popChar();if(!1===n.test(e))throw Error("Expecting an integer");for(;n.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)},e.prototype.patternCharacter=function(){var e=this.popChar();switch(e){case"\n":case"\r":case"\u2028":case"\u2029":case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":throw Error("TBD");default:return{type:"Character",value:i(e)}}},e.prototype.isRegExpFlag=function(){switch(this.peekChar(0)){case"g":case"i":case"m":case"u":case"y":return!0;default:return!1}},e.prototype.isRangeDash=function(){return"-"===this.peekChar()&&this.isClassAtom(1)},e.prototype.isDigit=function(){return n.test(this.peekChar(0))},e.prototype.isClassAtom=function(e){switch(void 0===e&&(e=0),this.peekChar(e)){case"]":case"\n":case"\r":case"\u2028":case"\u2029":return!1;default:return!0}},e.prototype.isTerm=function(){return this.isAtom()||this.isAssertion()},e.prototype.isAtom=function(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case".":case"\\":case"[":case"(":return!0;default:return!1}},e.prototype.isAssertion=function(){switch(this.peekChar(0)){case"^":case"$":return!0;case"\\":switch(this.peekChar(1)){case"b":case"B":return!0;default:return!1}case"(":return"?"===this.peekChar(1)&&("="===this.peekChar(2)||"!"===this.peekChar(2));default:return!1}},e.prototype.isQuantifier=function(){var e=this.saveState();try{return void 0!==this.quantifier(!0)}catch(e){return!1}finally{this.restoreState(e)}},e.prototype.isPatternCharacter=function(){switch(this.peekChar()){case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":case"/":case"\n":case"\r":case"\u2028":case"\u2029":return!1;default:return!0}},e.prototype.parseHexDigits=function(e){for(var n="",r=0;r<e;r++){var i=this.popChar();if(!1===t.test(i))throw Error("Expecting a HexDecimal digits");n+=i}return{type:"Character",value:parseInt(n,16)}},e.prototype.peekChar=function(e){return void 0===e&&(e=0),this.input[this.idx+e]},e.prototype.popChar=function(){var e=this.peekChar(0);return this.consumeChar(),e},e.prototype.consumeChar=function(e){if(void 0!==e&&this.input[this.idx]!==e)throw Error("Expected: '"+e+"' but found: '"+this.input[this.idx]+"' at offset: "+this.idx);if(this.idx>=this.input.length)throw Error("Unexpected end of input");this.idx++},e.prototype.loc=function(e){return{begin:e,end:this.idx}};var t=/[0-9a-fA-F]/,n=/[0-9]/,r=/[1-9]/;function i(e){return e.charCodeAt(0)}function o(e,t){void 0!==e.length?e.forEach(function(e){t.push(e)}):t.push(e)}function a(e,t){if(!0===e[t])throw"duplicate flag "+t;e[t]=!0}function s(e){if(void 0===e)throw Error("Internal Error - Should never get here!")}var c,l=[];for(c=i("0");c<=i("9");c++)l.push(c);var u=[i("_")].concat(l);for(c=i("a");c<=i("z");c++)u.push(c);for(c=i("A");c<=i("Z");c++)u.push(c);var h=[i(" "),i("\f"),i("\n"),i("\r"),i("\t"),i("\v"),i("\t"),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i(" "),i("\u2028"),i("\u2029"),i(" "),i(" "),i(" "),i("\ufeff")];function d(){}return d.prototype.visitChildren=function(e){for(var t in e){var n=e[t];e.hasOwnProperty(t)&&(void 0!==n.type?this.visit(n):Array.isArray(n)&&n.forEach(function(e){this.visit(e)},this))}},d.prototype.visit=function(e){switch(e.type){case"Pattern":this.visitPattern(e);break;case"Flags":this.visitFlags(e);break;case"Disjunction":this.visitDisjunction(e);break;case"Alternative":this.visitAlternative(e);break;case"StartAnchor":this.visitStartAnchor(e);break;case"EndAnchor":this.visitEndAnchor(e);break;case"WordBoundary":this.visitWordBoundary(e);break;case"NonWordBoundary":this.visitNonWordBoundary(e);break;case"Lookahead":this.visitLookahead(e);break;case"NegativeLookahead":this.visitNegativeLookahead(e);break;case"Character":this.visitCharacter(e);break;case"Set":this.visitSet(e);break;case"Group":this.visitGroup(e);break;case"GroupBackReference":this.visitGroupBackReference(e);break;case"Quantifier":this.visitQuantifier(e)}this.visitChildren(e)},d.prototype.visitPattern=function(e){},d.prototype.visitFlags=function(e){},d.prototype.visitDisjunction=function(e){},d.prototype.visitAlternative=function(e){},d.prototype.visitStartAnchor=function(e){},d.prototype.visitEndAnchor=function(e){},d.prototype.visitWordBoundary=function(e){},d.prototype.visitNonWordBoundary=function(e){},d.prototype.visitLookahead=function(e){},d.prototype.visitNegativeLookahead=function(e){},d.prototype.visitCharacter=function(e){},d.prototype.visitSet=function(e){},d.prototype.visitGroup=function(e){},d.prototype.visitGroupBackReference=function(e){},d.prototype.visitQuantifier=function(e){},{RegExpParser:e,BaseRegExpVisitor:d,VERSION:"0.5.0"}},"function"==typeof define&&define.amd?define([],r):"object"==typeof t&&t.exports?t.exports=r():n.regexpToAst=r()}),nc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.clearRegExpParserCache=e.getRegExpAst=void 0;var t=tc(),n={},r=new t.RegExpParser;e.getRegExpAst=function(e){var t=e.toString();if(n.hasOwnProperty(t))return n[t];var i=r.pattern(t);return n[t]=i,i},e.clearRegExpParserCache=function(){n={}}}),rc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.canMatchCharCode=e.firstCharOptimizedIndices=e.getOptimizedStartCodesIndices=e.failedOptimizationPrefixMsg=void 0;var r=tc(),i=ec(),o=nc(),a=ic(),s="Complement Sets are not supported for first char optimization";function c(e,t,n){switch(e.type){case"Disjunction":for(var r=0;r<e.value.length;r++)c(e.value[r],t,n);break;case"Alternative":var o=e.value;for(r=0;r<o.length;r++){var u=o[r];switch(u.type){case"EndAnchor":case"GroupBackReference":case"Lookahead":case"NegativeLookahead":case"StartAnchor":case"WordBoundary":case"NonWordBoundary":continue}var d=u;switch(d.type){case"Character":l(d.value,t,n);break;case"Set":if(!0===d.complement)throw Error(s);i.forEach(d.value,function(e){if("number"==typeof e)l(e,t,n);else{var r=e;if(!0===n)for(var i=r.from;i<=r.to;i++)l(i,t,n);else{for(i=r.from;i<=r.to&&i<a.minOptimizationVal;i++)l(i,t,n);if(r.to>=a.minOptimizationVal)for(var o=r.from>=a.minOptimizationVal?r.from:a.minOptimizationVal,s=r.to,c=a.charCodeToOptimizedIndex(o),u=a.charCodeToOptimizedIndex(s),h=c;h<=u;h++)t[h]=h}}});break;case"Group":c(d.value,t,n);break;default:throw Error("Non Exhaustive Match")}var p=void 0!==d.quantifier&&0===d.quantifier.atLeast;if("Group"===d.type&&!1===h(d)||"Group"!==d.type&&!1===p)break}break;default:throw Error("non exhaustive match!")}return i.values(t)}function l(e,t,n){var r=a.charCodeToOptimizedIndex(e);t[r]=r,!0===n&&function(e,t){var n=String.fromCharCode(e),r=n.toUpperCase();if(r!==n){t[i=a.charCodeToOptimizedIndex(r.charCodeAt(0))]=i}else{var i,o=n.toLowerCase();if(o!==n)t[i=a.charCodeToOptimizedIndex(o.charCodeAt(0))]=i}}(e,t)}function u(e,t){return i.find(e.value,function(e){if("number"==typeof e)return i.contains(t,e);var n=e;return void 0!==i.find(t,function(e){return n.from<=e&&e<=n.to})})}function h(e){return!(!e.quantifier||0!==e.quantifier.atLeast)||!!e.value&&(i.isArray(e.value)?i.every(e.value,h):h(e.value))}e.failedOptimizationPrefixMsg='Unable to use "first char" lexer optimizations:\n',e.getOptimizedStartCodesIndices=function(t,n){void 0===n&&(n=!1);try{var a=o.getRegExpAst(t);return c(a.value,{},a.flags.ignoreCase)}catch(o){if(o.message===s)n&&i.PRINT_WARNING(e.failedOptimizationPrefixMsg+"\tUnable to optimize: < "+t.toString()+" >\n\tComplement Sets cannot be automatically optimized.\n\tThis will disable the lexer's first char optimizations.\n\tSee: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.");else{var l="";n&&(l="\n\tThis will disable the lexer's first char optimizations.\n\tSee: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details."),i.PRINT_ERROR(e.failedOptimizationPrefixMsg+"\n\tFailed parsing: < "+t.toString()+" >\n\tUsing the regexp-to-ast library version: "+r.VERSION+"\n\tPlease open an issue at: https://github.com/bd82/regexp-to-ast/issues"+l)}}return[]},e.firstCharOptimizedIndices=c;var d=function(e){function t(t){var n=e.call(this)||this;return n.targetCharCodes=t,n.found=!1,n}return n(t,e),t.prototype.visitChildren=function(t){if(!0!==this.found){switch(t.type){case"Lookahead":return void this.visitLookahead(t);case"NegativeLookahead":return void this.visitNegativeLookahead(t)}e.prototype.visitChildren.call(this,t)}},t.prototype.visitCharacter=function(e){i.contains(this.targetCharCodes,e.value)&&(this.found=!0)},t.prototype.visitSet=function(e){e.complement?void 0===u(e,this.targetCharCodes)&&(this.found=!0):void 0!==u(e,this.targetCharCodes)&&(this.found=!0)},t}(r.BaseRegExpVisitor);e.canMatchCharCode=function(e,t){if(t instanceof RegExp){var n=o.getRegExpAst(t),r=new d(e);return r.visit(n),r.found}return void 0!==i.find(t,function(t){return i.contains(e,t.charCodeAt(0))})}}),ic=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.charCodeToOptimizedIndex=e.minOptimizationVal=e.buildLineBreakIssueMessage=e.LineTerminatorOptimizedTester=e.isShortPattern=e.isCustomPattern=e.cloneEmptyGroups=e.performWarningRuntimeChecks=e.performRuntimeChecks=e.addStickyFlag=e.addStartOfInput=e.findUnreachablePatterns=e.findModesThatDoNotExist=e.findInvalidGroupType=e.findDuplicatePatterns=e.findUnsupportedFlags=e.findStartOfInputAnchor=e.findEmptyMatchRegExps=e.findEndOfInputAnchor=e.findInvalidPatterns=e.findMissingPatterns=e.validatePatterns=e.analyzeTokenTypes=e.enableSticky=e.disableSticky=e.SUPPORT_STICKY=e.MODES=e.DEFAULT_MODE=void 0;var r=tc(),i=sc(),o=ec(),a=rc(),s=nc(),c="PATTERN";function l(e){var t=o.filter(e,function(e){return!o.has(e,c)}),n=o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- missing static 'PATTERN' property",type:i.LexerDefinitionErrorType.MISSING_PATTERN,tokenTypes:[e]}});return{errors:n,valid:o.difference(e,t)}}function u(e){var t=o.filter(e,function(e){var t=e[c];return!(o.isRegExp(t)||o.isFunction(t)||o.has(t,"exec")||o.isString(t))}),n=o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.",type:i.LexerDefinitionErrorType.INVALID_PATTERN,tokenTypes:[e]}});return{errors:n,valid:o.difference(e,t)}}e.DEFAULT_MODE="defaultMode",e.MODES="modes",e.SUPPORT_STICKY="boolean"==typeof new RegExp("(?:)").sticky,e.disableSticky=function(){e.SUPPORT_STICKY=!1},e.enableSticky=function(){e.SUPPORT_STICKY=!0},e.analyzeTokenTypes=function(t,n){var r,s=(n=o.defaults(n,{useSticky:e.SUPPORT_STICKY,debug:!1,safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r","\n"],tracer:function(e,t){return t()}})).tracer;s("initCharCodeToOptimizedIndexMap",function(){!function(){if(o.isEmpty(M)){M=new Array(65536);for(var e=0;e<65536;e++)M[e]=e>255?255+~~(e/255):e}}()}),s("Reject Lexer.NA",function(){r=o.reject(t,function(e){return e[c]===i.Lexer.NA})});var l,u,h,d,p,f,m,g,b,y,v,x=!1;s("Transform Patterns",function(){x=!1,l=o.map(r,function(e){var t=e[c];if(o.isRegExp(t)){var r=t.source;return 1!==r.length||"^"===r||"$"===r||"."===r||t.ignoreCase?2!==r.length||"\\"!==r[0]||o.contains(["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"],r[1])?n.useSticky?E(t):w(t):r[1]:r}if(o.isFunction(t))return x=!0,{exec:t};if(o.has(t,"exec"))return x=!0,t;if("string"==typeof t){if(1===t.length)return t;var i=t.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),a=new RegExp(i);return n.useSticky?E(a):w(a)}throw Error("non exhaustive match")})}),s("misc mapping",function(){u=o.map(r,function(e){return e.tokenTypeIdx}),h=o.map(r,function(e){var t=e.GROUP;if(t!==i.Lexer.SKIPPED){if(o.isString(t))return t;if(o.isUndefined(t))return!1;throw Error("non exhaustive match")}}),d=o.map(r,function(e){var t=e.LONGER_ALT;if(t)return o.indexOf(r,t)}),p=o.map(r,function(e){return e.PUSH_MODE}),f=o.map(r,function(e){return o.has(e,"POP_MODE")})}),s("Line Terminator Handling",function(){var e=k(n.lineTerminatorCharacters);m=o.map(r,function(e){return!1}),"onlyOffset"!==n.positionTracking&&(m=o.map(r,function(t){return o.has(t,"LINE_BREAKS")?t.LINE_BREAKS:!1===C(t,e)?a.canMatchCharCode(e,t.PATTERN):void 0}))}),s("Misc Mapping #2",function(){g=o.map(r,T),b=o.map(l,A),y=o.reduce(r,function(e,t){var n=t.GROUP;return o.isString(n)&&n!==i.Lexer.SKIPPED&&(e[n]=[]),e},{}),v=o.map(l,function(e,t){return{pattern:l[t],longerAlt:d[t],canLineTerminator:m[t],isCustom:g[t],short:b[t],group:h[t],push:p[t],pop:f[t],tokenTypeIdx:u[t],tokenType:r[t]}})});var O=!0,I=[];return n.safeMode||s("First Char Optimization",function(){I=o.reduce(r,function(e,t,r){if("string"==typeof t.PATTERN){var i=R(t.PATTERN.charCodeAt(0));S(e,i,v[r])}else if(o.isArray(t.START_CHARS_HINT)){var s;o.forEach(t.START_CHARS_HINT,function(t){var n=R("string"==typeof t?t.charCodeAt(0):t);s!==n&&(s=n,S(e,n,v[r]))})}else if(o.isRegExp(t.PATTERN))if(t.PATTERN.unicode)O=!1,n.ensureOptimizations&&o.PRINT_ERROR(a.failedOptimizationPrefixMsg+"\tUnable to analyze < "+t.PATTERN.toString()+" > pattern.\n\tThe regexp unicode flag is not currently supported by the regexp-to-ast library.\n\tThis will disable the lexer's first char optimizations.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE");else{var c=a.getOptimizedStartCodesIndices(t.PATTERN,n.ensureOptimizations);o.isEmpty(c)&&(O=!1),o.forEach(c,function(t){S(e,t,v[r])})}else n.ensureOptimizations&&o.PRINT_ERROR(a.failedOptimizationPrefixMsg+"\tTokenType: <"+t.name+"> is using a custom token pattern without providing <start_chars_hint> parameter.\n\tThis will disable the lexer's first char optimizations.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE"),O=!1;return e},[])}),s("ArrayPacking",function(){I=o.packArray(I)}),{emptyGroups:y,patternIdxToConfig:v,charCodeToPatternIdxToConfig:I,hasCustom:x,canBeOptimized:O}},e.validatePatterns=function(e,t){var n=[],r=l(e);n=n.concat(r.errors);var i=u(r.valid),a=i.valid;return n=(n=n.concat(i.errors)).concat(function(e){var t=[],n=o.filter(e,function(e){return o.isRegExp(e[c])});return t=t.concat(d(n)),t=t.concat(m(n)),t=t.concat(g(n)),t=t.concat(b(n)),t=t.concat(p(n)),t}(a)),n=(n=(n=n.concat(y(a))).concat(v(a,t))).concat(x(a))},e.findMissingPatterns=l,e.findInvalidPatterns=u;var h=/[^\\][\$]/;function d(e){var t=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.found=!1,t}return n(t,e),t.prototype.visitEndAnchor=function(e){this.found=!0},t}(r.BaseRegExpVisitor),a=o.filter(e,function(e){var n=e[c];try{var r=s.getRegExpAst(n),i=new t;return i.visit(r),i.found}catch(e){return h.test(n.source)}}),l=o.map(a,function(e){return{message:"Unexpected RegExp Anchor Error:\n\tToken Type: ->"+e.name+"<- static 'PATTERN' cannot contain end of input anchor '$'\n\tSee chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS\tfor details.",type:i.LexerDefinitionErrorType.EOI_ANCHOR_FOUND,tokenTypes:[e]}});return l}function p(e){var t=o.filter(e,function(e){return e[c].test("")});return o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- static 'PATTERN' must not match an empty string",type:i.LexerDefinitionErrorType.EMPTY_MATCH_PATTERN,tokenTypes:[e]}})}e.findEndOfInputAnchor=d,e.findEmptyMatchRegExps=p;var f=/[^\\[][\^]|^\^/;function m(e){var t=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.found=!1,t}return n(t,e),t.prototype.visitStartAnchor=function(e){this.found=!0},t}(r.BaseRegExpVisitor),a=o.filter(e,function(e){var n=e[c];try{var r=s.getRegExpAst(n),i=new t;return i.visit(r),i.found}catch(e){return f.test(n.source)}}),l=o.map(a,function(e){return{message:"Unexpected RegExp Anchor Error:\n\tToken Type: ->"+e.name+"<- static 'PATTERN' cannot contain start of input anchor '^'\n\tSee https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS\tfor details.",type:i.LexerDefinitionErrorType.SOI_ANCHOR_FOUND,tokenTypes:[e]}});return l}function g(e){var t=o.filter(e,function(e){var t=e[c];return t instanceof RegExp&&(t.multiline||t.global)});return o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:i.LexerDefinitionErrorType.UNSUPPORTED_FLAGS_FOUND,tokenTypes:[e]}})}function b(e){var t=[],n=o.map(e,function(n){return o.reduce(e,function(e,r){return n.PATTERN.source===r.PATTERN.source&&!o.contains(t,r)&&r.PATTERN!==i.Lexer.NA&&(t.push(r),e.push(r)),e},[])});n=o.compact(n);var r=o.filter(n,function(e){return e.length>1});return o.map(r,function(e){var t=o.map(e,function(e){return e.name});return{message:"The same RegExp pattern ->"+o.first(e).PATTERN+"<-has been used in all of the following Token Types: "+t.join(", ")+" <-",type:i.LexerDefinitionErrorType.DUPLICATE_PATTERNS_FOUND,tokenTypes:e}})}function y(e){var t=o.filter(e,function(e){if(!o.has(e,"GROUP"))return!1;var t=e.GROUP;return t!==i.Lexer.SKIPPED&&t!==i.Lexer.NA&&!o.isString(t)});return o.map(t,function(e){return{message:"Token Type: ->"+e.name+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:i.LexerDefinitionErrorType.INVALID_GROUP_TYPE_FOUND,tokenTypes:[e]}})}function v(e,t){var n=o.filter(e,function(e){return void 0!==e.PUSH_MODE&&!o.contains(t,e.PUSH_MODE)}),r=o.map(n,function(e){return{message:"Token Type: ->"+e.name+"<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->"+e.PUSH_MODE+"<-which does not exist",type:i.LexerDefinitionErrorType.PUSH_MODE_DOES_NOT_EXIST,tokenTypes:[e]}});return r}function x(e){var t=[],n=o.reduce(e,function(e,t,n){var r=t.PATTERN;return r===i.Lexer.NA||(o.isString(r)?e.push({str:r,idx:n,tokenType:t}):o.isRegExp(r)&&function(e){var t=[".","\\","[","]","|","^","$","(",")","?","*","+","{"];return void 0===o.find(t,function(t){return-1!==e.source.indexOf(t)})}(r)&&e.push({str:r.source,idx:n,tokenType:t})),e},[]);return o.forEach(e,function(e,r){o.forEach(n,function(n){var a=n.str,s=n.idx,c=n.tokenType;if(r<s&&function(e,t){if(o.isRegExp(t)){var n=t.exec(e);return null!==n&&0===n.index}if(o.isFunction(t))return t(e,0,[],{});if(o.has(t,"exec"))return t.exec(e,0,[],{});if("string"==typeof t)return t===e;throw Error("non exhaustive match")}(a,e.PATTERN)){var l="Token: ->"+c.name+"<- can never be matched.\nBecause it appears AFTER the Token Type ->"+e.name+"<-in the lexer's definition.\nSee https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE";t.push({message:l,type:i.LexerDefinitionErrorType.UNREACHABLE_PATTERN,tokenTypes:[e,c]})}})}),t}function w(e){var t=e.ignoreCase?"i":"";return new RegExp("^(?:"+e.source+")",t)}function E(e){var t=e.ignoreCase?"iy":"y";return new RegExp(""+e.source,t)}function T(e){var t=e.PATTERN;if(o.isRegExp(t))return!1;if(o.isFunction(t))return!0;if(o.has(t,"exec"))return!0;if(o.isString(t))return!1;throw Error("non exhaustive match")}function A(e){return!(!o.isString(e)||1!==e.length)&&e.charCodeAt(0)}function C(e,t){if(o.has(e,"LINE_BREAKS"))return!1;if(o.isRegExp(e.PATTERN)){try{a.canMatchCharCode(t,e.PATTERN)}catch(e){return{issue:i.LexerDefinitionErrorType.IDENTIFY_TERMINATOR,errMsg:e.message}}return!1}if(o.isString(e.PATTERN))return!1;if(T(e))return{issue:i.LexerDefinitionErrorType.CUSTOM_LINE_BREAK};throw Error("non exhaustive match")}function O(e,t){if(t.issue===i.LexerDefinitionErrorType.IDENTIFY_TERMINATOR)return"Warning: unable to identify line terminator usage in pattern.\n\tThe problem is in the <"+e.name+"> Token Type\n\t Root cause: "+t.errMsg+".\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR";if(t.issue===i.LexerDefinitionErrorType.CUSTOM_LINE_BREAK)return"Warning: A Custom Token Pattern should specify the <line_breaks> option.\n\tThe problem is in the <"+e.name+"> Token Type\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK";throw Error("non exhaustive match")}function k(e){return o.map(e,function(e){return o.isString(e)&&e.length>0?e.charCodeAt(0):e})}function S(e,t,n){void 0===e[t]?e[t]=[n]:e[t].push(n)}e.findStartOfInputAnchor=m,e.findUnsupportedFlags=g,e.findDuplicatePatterns=b,e.findInvalidGroupType=y,e.findModesThatDoNotExist=v,e.findUnreachablePatterns=x,e.addStartOfInput=w,e.addStickyFlag=E,e.performRuntimeChecks=function(t,n,r){var a=[];return o.has(t,e.DEFAULT_MODE)||a.push({message:"A MultiMode Lexer cannot be initialized without a <"+e.DEFAULT_MODE+"> property in its definition\n",type:i.LexerDefinitionErrorType.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE}),o.has(t,e.MODES)||a.push({message:"A MultiMode Lexer cannot be initialized without a <"+e.MODES+"> property in its definition\n",type:i.LexerDefinitionErrorType.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY}),o.has(t,e.MODES)&&o.has(t,e.DEFAULT_MODE)&&!o.has(t.modes,t.defaultMode)&&a.push({message:"A MultiMode Lexer cannot be initialized with a "+e.DEFAULT_MODE+": <"+t.defaultMode+">which does not exist\n",type:i.LexerDefinitionErrorType.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST}),o.has(t,e.MODES)&&o.forEach(t.modes,function(e,t){o.forEach(e,function(e,n){o.isUndefined(e)&&a.push({message:"A Lexer cannot be initialized using an undefined Token Type. Mode:<"+t+"> at index: <"+n+">\n",type:i.LexerDefinitionErrorType.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED})})}),a},e.performWarningRuntimeChecks=function(e,t,n){var r=[],s=!1,l=o.compact(o.flatten(o.mapValues(e.modes,function(e){return e}))),u=o.reject(l,function(e){return e[c]===i.Lexer.NA}),h=k(n);return t&&o.forEach(u,function(e){var t=C(e,h);if(!1!==t){var n={message:O(e,t),type:t.issue,tokenType:e};r.push(n)}else o.has(e,"LINE_BREAKS")?!0===e.LINE_BREAKS&&(s=!0):a.canMatchCharCode(h,e.PATTERN)&&(s=!0)}),t&&!s&&r.push({message:"Warning: No LINE_BREAKS Found.\n\tThis Lexer has been defined to track line and column information,\n\tBut none of the Token Types can be identified as matching a line terminator.\n\tSee https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS\n\tfor details.",type:i.LexerDefinitionErrorType.NO_LINE_BREAKS_FLAGS}),r},e.cloneEmptyGroups=function(e){var t={},n=o.keys(e);return o.forEach(n,function(n){var r=e[n];if(!o.isArray(r))throw Error("non exhaustive match");t[n]=[]}),t},e.isCustomPattern=T,e.isShortPattern=A,e.LineTerminatorOptimizedTester={test:function(e){for(var t=e.length,n=this.lastIndex;n<t;n++){var r=e.charCodeAt(n);if(10===r)return this.lastIndex=n+1,!0;if(13===r)return 10===e.charCodeAt(n+1)?this.lastIndex=n+2:this.lastIndex=n+1,!0}return!1},lastIndex:0},e.buildLineBreakIssueMessage=O,e.minOptimizationVal=256;var M=[];function R(t){return t<e.minOptimizationVal?t:M[t]}e.charCodeToOptimizedIndex=R}),oc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.isTokenType=e.hasExtendingTokensTypesMapProperty=e.hasExtendingTokensTypesProperty=e.hasCategoriesProperty=e.hasShortKeyProperty=e.singleAssignCategoriesToksMap=e.assignCategoriesMapProp=e.assignCategoriesTokensProp=e.assignTokenDefaultProps=e.expandCategories=e.augmentTokenTypes=e.tokenIdxToClass=e.tokenShortNameIdx=e.tokenStructuredMatcherNoCategories=e.tokenStructuredMatcher=void 0;var t=ec();function n(e){for(var n=t.cloneArr(e),r=e,i=!0;i;){r=t.compact(t.flatten(t.map(r,function(e){return e.CATEGORIES})));var o=t.difference(r,n);n=n.concat(o),t.isEmpty(o)?i=!1:r=o}return n}function r(n){t.forEach(n,function(n){s(n)||(e.tokenIdxToClass[e.tokenShortNameIdx]=n,n.tokenTypeIdx=e.tokenShortNameIdx++),c(n)&&!t.isArray(n.CATEGORIES)&&(n.CATEGORIES=[n.CATEGORIES]),c(n)||(n.CATEGORIES=[]),l(n)||(n.categoryMatches=[]),u(n)||(n.categoryMatchesMap={})})}function i(n){t.forEach(n,function(n){n.categoryMatches=[],t.forEach(n.categoryMatchesMap,function(t,r){n.categoryMatches.push(e.tokenIdxToClass[r].tokenTypeIdx)})})}function o(e){t.forEach(e,function(e){a([],e)})}function a(e,n){t.forEach(e,function(e){n.categoryMatchesMap[e.tokenTypeIdx]=!0}),t.forEach(n.CATEGORIES,function(r){var i=e.concat(n);t.contains(i,r)||a(i,r)})}function s(e){return t.has(e,"tokenTypeIdx")}function c(e){return t.has(e,"CATEGORIES")}function l(e){return t.has(e,"categoryMatches")}function u(e){return t.has(e,"categoryMatchesMap")}e.tokenStructuredMatcher=function(e,t){var n=e.tokenTypeIdx;return n===t.tokenTypeIdx||!0===t.isParent&&!0===t.categoryMatchesMap[n]},e.tokenStructuredMatcherNoCategories=function(e,t){return e.tokenTypeIdx===t.tokenTypeIdx},e.tokenShortNameIdx=1,e.tokenIdxToClass={},e.augmentTokenTypes=function(e){var a=n(e);r(a),o(a),i(a),t.forEach(a,function(e){e.isParent=e.categoryMatches.length>0})},e.expandCategories=n,e.assignTokenDefaultProps=r,e.assignCategoriesTokensProp=i,e.assignCategoriesMapProp=o,e.singleAssignCategoriesToksMap=a,e.hasShortKeyProperty=s,e.hasCategoriesProperty=c,e.hasExtendingTokensTypesProperty=l,e.hasExtendingTokensTypesMapProperty=u,e.isTokenType=function(e){return t.has(e,"tokenTypeIdx")}}),ac=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defaultLexerErrorProvider=void 0,e.defaultLexerErrorProvider={buildUnableToPopLexerModeMessage:function(e){return"Unable to pop Lexer Mode after encountering Token ->"+e.image+"<- The Mode Stack is empty"},buildUnexpectedCharactersMessage:function(e,t,n,r,i){return"unexpected character: ->"+e.charAt(t)+"<- at offset: "+t+", skipped "+n+" characters."}}}),sc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Lexer=e.LexerDefinitionErrorType=void 0;var t,n=ic(),r=ec(),i=oc(),o=ac(),a=nc();(t=e.LexerDefinitionErrorType||(e.LexerDefinitionErrorType={}))[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",t[t.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",t[t.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",t[t.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",t[t.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",t[t.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",t[t.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",t[t.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK";var s={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:["\n","\r"],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:o.defaultLexerErrorProvider,traceInitPerf:!1,skipValidations:!1};Object.freeze(s);var c=function(){function e(e,t){var o=this;if(void 0===t&&(t=s),this.lexerDefinition=e,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.config=void 0,this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},"boolean"==typeof t)throw Error("The second argument to the Lexer constructor is now an ILexerConfig Object.\na boolean 2nd argument is no longer supported");this.config=r.merge(s,t);var c=this.config.traceInitPerf;!0===c?(this.traceInitMaxIdent=1/0,this.traceInitPerf=!0):"number"==typeof c&&(this.traceInitMaxIdent=c,this.traceInitPerf=!0),this.traceInitIndent=-1,this.TRACE_INIT("Lexer Constructor",function(){var c,l=!0;o.TRACE_INIT("Lexer Config handling",function(){if(o.config.lineTerminatorsPattern===s.lineTerminatorsPattern)o.config.lineTerminatorsPattern=n.LineTerminatorOptimizedTester;else if(o.config.lineTerminatorCharacters===s.lineTerminatorCharacters)throw Error("Error: Missing <lineTerminatorCharacters> property on the Lexer config.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS");if(t.safeMode&&t.ensureOptimizations)throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');o.trackStartLines=/full|onlyStart/i.test(o.config.positionTracking),o.trackEndLines=/full/i.test(o.config.positionTracking),r.isArray(e)?((c={modes:{}}).modes[n.DEFAULT_MODE]=r.cloneArr(e),c[n.DEFAULT_MODE]=n.DEFAULT_MODE):(l=!1,c=r.cloneObj(e))}),!1===o.config.skipValidations&&(o.TRACE_INIT("performRuntimeChecks",function(){o.lexerDefinitionErrors=o.lexerDefinitionErrors.concat(n.performRuntimeChecks(c,o.trackStartLines,o.config.lineTerminatorCharacters))}),o.TRACE_INIT("performWarningRuntimeChecks",function(){o.lexerDefinitionWarning=o.lexerDefinitionWarning.concat(n.performWarningRuntimeChecks(c,o.trackStartLines,o.config.lineTerminatorCharacters))})),c.modes=c.modes?c.modes:{},r.forEach(c.modes,function(e,t){c.modes[t]=r.reject(e,function(e){return r.isUndefined(e)})});var u=r.keys(c.modes);if(r.forEach(c.modes,function(e,a){o.TRACE_INIT("Mode: <"+a+"> processing",function(){var s;(o.modes.push(a),!1===o.config.skipValidations&&o.TRACE_INIT("validatePatterns",function(){o.lexerDefinitionErrors=o.lexerDefinitionErrors.concat(n.validatePatterns(e,u))}),r.isEmpty(o.lexerDefinitionErrors))&&(i.augmentTokenTypes(e),o.TRACE_INIT("analyzeTokenTypes",function(){s=n.analyzeTokenTypes(e,{lineTerminatorCharacters:o.config.lineTerminatorCharacters,positionTracking:t.positionTracking,ensureOptimizations:t.ensureOptimizations,safeMode:t.safeMode,tracer:o.TRACE_INIT.bind(o)})}),o.patternIdxToConfig[a]=s.patternIdxToConfig,o.charCodeToPatternIdxToConfig[a]=s.charCodeToPatternIdxToConfig,o.emptyGroups=r.merge(o.emptyGroups,s.emptyGroups),o.hasCustom=s.hasCustom||o.hasCustom,o.canModeBeOptimized[a]=s.canBeOptimized)})}),o.defaultMode=c.defaultMode,!r.isEmpty(o.lexerDefinitionErrors)&&!o.config.deferDefinitionErrorsHandling){var h=r.map(o.lexerDefinitionErrors,function(e){return e.message}).join("-----------------------\n");throw new Error("Errors detected in definition of Lexer:\n"+h)}r.forEach(o.lexerDefinitionWarning,function(e){r.PRINT_WARNING(e.message)}),o.TRACE_INIT("Choosing sub-methods implementations",function(){if(n.SUPPORT_STICKY?(o.chopInput=r.IDENTITY,o.match=o.matchWithTest):(o.updateLastIndex=r.NOOP,o.match=o.matchWithExec),l&&(o.handleModes=r.NOOP),!1===o.trackStartLines&&(o.computeNewColumn=r.IDENTITY),!1===o.trackEndLines&&(o.updateTokenEndLineColumnLocation=r.NOOP),/full/i.test(o.config.positionTracking))o.createTokenInstance=o.createFullToken;else if(/onlyStart/i.test(o.config.positionTracking))o.createTokenInstance=o.createStartOnlyToken;else{if(!/onlyOffset/i.test(o.config.positionTracking))throw Error('Invalid <positionTracking> config option: "'+o.config.positionTracking+'"');o.createTokenInstance=o.createOffsetOnlyToken}o.hasCustom?(o.addToken=o.addTokenUsingPush,o.handlePayload=o.handlePayloadWithCustom):(o.addToken=o.addTokenUsingMemberAccess,o.handlePayload=o.handlePayloadNoCustom)}),o.TRACE_INIT("Failed Optimization Warnings",function(){var e=r.reduce(o.canModeBeOptimized,function(e,t,n){return!1===t&&e.push(n),e},[]);if(t.ensureOptimizations&&!r.isEmpty(e))throw Error("Lexer Modes: < "+e.join(", ")+' > cannot be optimized.\n\t Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode.\n\t Or inspect the console log for details on how to resolve these issues.')}),o.TRACE_INIT("clearRegExpParserCache",function(){a.clearRegExpParserCache()}),o.TRACE_INIT("toFastProperties",function(){r.toFastProperties(o)})})}return e.prototype.tokenize=function(e,t){if(void 0===t&&(t=this.defaultMode),!r.isEmpty(this.lexerDefinitionErrors)){var n=r.map(this.lexerDefinitionErrors,function(e){return e.message}).join("-----------------------\n");throw new Error("Unable to Tokenize because Errors detected in definition of Lexer:\n"+n)}return this.tokenizeInternal(e,t)},e.prototype.tokenizeInternal=function(e,t){var i,o,a,s,c,l,u,h,d,p,f,m,g,b,y=this,v=e,x=v.length,w=0,E=0,T=this.hasCustom?0:Math.floor(e.length/10),A=new Array(T),C=[],O=this.trackStartLines?1:void 0,k=this.trackStartLines?1:void 0,S=n.cloneEmptyGroups(this.emptyGroups),M=this.trackStartLines,R=this.config.lineTerminatorsPattern,I=0,P=[],_=[],N=[],L=[];Object.freeze(L);var D=void 0;function j(){return P}function F(e){var t=n.charCodeToOptimizedIndex(e),r=_[t];return void 0===r?L:r}var U,B=function(e){if(1===N.length&&void 0===e.tokenType.PUSH_MODE){var t=y.config.errorMessageProvider.buildUnableToPopLexerModeMessage(e);C.push({offset:e.startOffset,line:void 0!==e.startLine?e.startLine:void 0,column:void 0!==e.startColumn?e.startColumn:void 0,length:e.image.length,message:t})}else{N.pop();var n=r.last(N);P=y.patternIdxToConfig[n],_=y.charCodeToPatternIdxToConfig[n],I=P.length;var i=y.canModeBeOptimized[n]&&!1===y.config.safeMode;D=_&&i?F:j}};function z(e){N.push(e),_=this.charCodeToPatternIdxToConfig[e],P=this.patternIdxToConfig[e],I=P.length,I=P.length;var t=this.canModeBeOptimized[e]&&!1===this.config.safeMode;D=_&&t?F:j}for(z.call(this,t);w<x;){c=null;var H=v.charCodeAt(w),V=D(H),G=V.length;for(i=0;i<G;i++){var W=(U=V[i]).pattern;if(l=null,!1!==(te=U.short)?H===te&&(c=W):!0===U.isCustom?null!==(b=W.exec(v,w,A,S))?(c=b[0],void 0!==b.payload&&(l=b.payload)):c=null:(this.updateLastIndex(W,w),c=this.match(W,e,w)),null!==c){if(void 0!==(s=U.longerAlt)){var X=P[s],q=X.pattern;u=null,!0===X.isCustom?null!==(b=q.exec(v,w,A,S))?(a=b[0],void 0!==b.payload&&(u=b.payload)):a=null:(this.updateLastIndex(q,w),a=this.match(q,e,w)),a&&a.length>c.length&&(c=a,l=u,U=X)}break}}if(null!==c){if(h=c.length,void 0!==(d=U.group)&&(p=U.tokenTypeIdx,f=this.createTokenInstance(c,w,p,U.tokenType,O,k,h),this.handlePayload(f,l),!1===d?E=this.addToken(A,E,f):S[d].push(f)),e=this.chopInput(e,h),w+=h,k=this.computeNewColumn(k,h),!0===M&&!0===U.canLineTerminator){var Y=0,K=void 0,Q=void 0;R.lastIndex=0;do{!0===(K=R.test(c))&&(Q=R.lastIndex-1,Y++)}while(!0===K);0!==Y&&(O+=Y,k=h-Q,this.updateTokenEndLineColumnLocation(f,d,Q,Y,O,k,h))}this.handleModes(U,B,z,f)}else{for(var $=w,Z=O,J=k,ee=!1;!ee&&w<x;)for(v.charCodeAt(w),e=this.chopInput(e,1),w++,o=0;o<I;o++){var te,ne=P[o];W=ne.pattern;if(!1!==(te=ne.short)?v.charCodeAt(w)===te&&(ee=!0):!0===ne.isCustom?ee=null!==W.exec(v,w,A,S):(this.updateLastIndex(W,w),ee=null!==W.exec(e)),!0===ee)break}m=w-$,g=this.config.errorMessageProvider.buildUnexpectedCharactersMessage(v,$,m,Z,J),C.push({offset:$,line:Z,column:J,length:m,message:g})}}return this.hasCustom||(A.length=E),{tokens:A,groups:S,errors:C}},e.prototype.handleModes=function(e,t,n,r){if(!0===e.pop){var i=e.push;t(r),void 0!==i&&n.call(this,i)}else void 0!==e.push&&n.call(this,e.push)},e.prototype.chopInput=function(e,t){return e.substring(t)},e.prototype.updateLastIndex=function(e,t){e.lastIndex=t},e.prototype.updateTokenEndLineColumnLocation=function(e,t,n,r,i,o,a){var s,c;void 0!==t&&(c=(s=n===a-1)?-1:0,1===r&&!0===s||(e.endLine=i+c,e.endColumn=o-1-c))},e.prototype.computeNewColumn=function(e,t){return e+t},e.prototype.createTokenInstance=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return null},e.prototype.createOffsetOnlyToken=function(e,t,n,r){return{image:e,startOffset:t,tokenTypeIdx:n,tokenType:r}},e.prototype.createStartOnlyToken=function(e,t,n,r,i,o){return{image:e,startOffset:t,startLine:i,startColumn:o,tokenTypeIdx:n,tokenType:r}},e.prototype.createFullToken=function(e,t,n,r,i,o,a){return{image:e,startOffset:t,endOffset:t+a-1,startLine:i,endLine:i,startColumn:o,endColumn:o+a-1,tokenTypeIdx:n,tokenType:r}},e.prototype.addToken=function(e,t,n){return 666},e.prototype.addTokenUsingPush=function(e,t,n){return e.push(n),t},e.prototype.addTokenUsingMemberAccess=function(e,t,n){return e[t]=n,++t},e.prototype.handlePayload=function(e,t){},e.prototype.handlePayloadNoCustom=function(e,t){},e.prototype.handlePayloadWithCustom=function(e,t){null!==t&&(e.payload=t)},e.prototype.match=function(e,t,n){return null},e.prototype.matchWithTest=function(e,t,n){return!0===e.test(t)?t.substring(n,e.lastIndex):null},e.prototype.matchWithExec=function(e,t){var n=e.exec(t);return null!==n?n[0]:n},e.prototype.TRACE_INIT=function(e,t){if(!0===this.traceInitPerf){this.traceInitIndent++;var n=new Array(this.traceInitIndent+1).join("\t");this.traceInitIndent<this.traceInitMaxIdent&&console.log(n+"--\x3e <"+e+">");var i=r.timer(t),o=i.time,a=i.value,s=o>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&s(n+"<-- <"+e+"> time: "+o+"ms"),this.traceInitIndent--,a}return t()},e.SKIPPED="This marks a skipped Token pattern, this means each token identified by it willbe consumed and then thrown into oblivion, this can be used to for example to completely ignore whitespace.",e.NA=/NOT_APPLICABLE/,e}();e.Lexer=c}),cc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.tokenMatcher=e.createTokenInstance=e.EOF=e.createToken=e.hasTokenLabel=e.tokenName=e.tokenLabel=void 0;var t=ec(),n=sc(),r=oc();function i(e){return t.isString(e.LABEL)&&""!==e.LABEL}e.tokenLabel=function(e){return i(e)?e.LABEL:e.name},e.tokenName=function(e){return e.name},e.hasTokenLabel=i;var o="parent",a="categories",s="label",c="group",l="push_mode",u="pop_mode",h="longer_alt",d="line_breaks",p="start_chars_hint";function f(e){return function(e){var n=e.pattern,i={};if(i.name=e.name,t.isUndefined(n)||(i.PATTERN=n),t.has(e,o))throw"The parent property is no longer supported.\nSee: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.";return t.has(e,a)&&(i.CATEGORIES=e[a]),r.augmentTokenTypes([i]),t.has(e,s)&&(i.LABEL=e[s]),t.has(e,c)&&(i.GROUP=e[c]),t.has(e,u)&&(i.POP_MODE=e[u]),t.has(e,l)&&(i.PUSH_MODE=e[l]),t.has(e,h)&&(i.LONGER_ALT=e[h]),t.has(e,d)&&(i.LINE_BREAKS=e[d]),t.has(e,p)&&(i.START_CHARS_HINT=e[p]),i}(e)}e.createToken=f,e.EOF=f({name:"EOF",pattern:n.Lexer.NA}),r.augmentTokenTypes([e.EOF]),e.createTokenInstance=function(e,t,n,r,i,o,a,s){return{image:t,startOffset:n,endOffset:r,startLine:i,endLine:o,startColumn:a,endColumn:s,tokenTypeIdx:e.tokenTypeIdx,tokenType:e}},e.tokenMatcher=function(e,t){return r.tokenStructuredMatcher(e,t)}}),lc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.serializeProduction=e.serializeGrammar=e.Terminal=e.Alternation=e.RepetitionWithSeparator=e.Repetition=e.RepetitionMandatoryWithSeparator=e.RepetitionMandatory=e.Option=e.Alternative=e.Rule=e.NonTerminal=e.AbstractProduction=void 0;var r=ec(),i=cc(),o=function(){function e(e){this._definition=e}return Object.defineProperty(e.prototype,"definition",{get:function(){return this._definition},set:function(e){this._definition=e},enumerable:!1,configurable:!0}),e.prototype.accept=function(e){e.visit(this),r.forEach(this.definition,function(t){t.accept(e)})},e}();e.AbstractProduction=o;var a=function(e){function t(t){var n=e.call(this,[])||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),Object.defineProperty(t.prototype,"definition",{get:function(){return void 0!==this.referencedRule?this.referencedRule.definition:[]},set:function(e){},enumerable:!1,configurable:!0}),t.prototype.accept=function(e){e.visit(this)},t}(o);e.NonTerminal=a;var s=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.orgText="",r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.Rule=s;var c=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.ignoreAmbiguities=!1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.Alternative=c;var l=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.Option=l;var u=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.RepetitionMandatory=u;var h=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.RepetitionMandatoryWithSeparator=h;var d=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.Repetition=d;var p=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),t}(o);e.RepetitionWithSeparator=p;var f=function(e){function t(t){var n=e.call(this,t.definition)||this;return n.idx=1,n.ignoreAmbiguities=!1,n.hasPredicates=!1,r.assign(n,r.pick(t,function(e){return void 0!==e})),n}return n(t,e),Object.defineProperty(t.prototype,"definition",{get:function(){return this._definition},set:function(e){this._definition=e},enumerable:!1,configurable:!0}),t}(o);e.Alternation=f;var m=function(){function e(e){this.idx=1,r.assign(this,r.pick(e,function(e){return void 0!==e}))}return e.prototype.accept=function(e){e.visit(this)},e}();function g(e){function t(e){return r.map(e,g)}if(e instanceof a)return{type:"NonTerminal",name:e.nonTerminalName,idx:e.idx};if(e instanceof c)return{type:"Alternative",definition:t(e.definition)};if(e instanceof l)return{type:"Option",idx:e.idx,definition:t(e.definition)};if(e instanceof u)return{type:"RepetitionMandatory",idx:e.idx,definition:t(e.definition)};if(e instanceof h)return{type:"RepetitionMandatoryWithSeparator",idx:e.idx,separator:g(new m({terminalType:e.separator})),definition:t(e.definition)};if(e instanceof p)return{type:"RepetitionWithSeparator",idx:e.idx,separator:g(new m({terminalType:e.separator})),definition:t(e.definition)};if(e instanceof d)return{type:"Repetition",idx:e.idx,definition:t(e.definition)};if(e instanceof f)return{type:"Alternation",idx:e.idx,definition:t(e.definition)};if(e instanceof m){var n={type:"Terminal",name:e.terminalType.name,label:i.tokenLabel(e.terminalType),idx:e.idx},o=e.terminalType.PATTERN;return e.terminalType.PATTERN&&(n.pattern=r.isRegExp(o)?o.source:o),n}if(e instanceof s)return{type:"Rule",name:e.name,orgText:e.orgText,definition:t(e.definition)};throw Error("non exhaustive match")}e.Terminal=m,e.serializeGrammar=function(e){return r.map(e,g)},e.serializeProduction=g}),uc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RestWalker=void 0;var t=ec(),n=lc(),r=function(){function e(){}return e.prototype.walk=function(e,r){var i=this;void 0===r&&(r=[]),t.forEach(e.definition,function(o,a){var s=t.drop(e.definition,a+1);if(o instanceof n.NonTerminal)i.walkProdRef(o,s,r);else if(o instanceof n.Terminal)i.walkTerminal(o,s,r);else if(o instanceof n.Alternative)i.walkFlat(o,s,r);else if(o instanceof n.Option)i.walkOption(o,s,r);else if(o instanceof n.RepetitionMandatory)i.walkAtLeastOne(o,s,r);else if(o instanceof n.RepetitionMandatoryWithSeparator)i.walkAtLeastOneSep(o,s,r);else if(o instanceof n.RepetitionWithSeparator)i.walkManySep(o,s,r);else if(o instanceof n.Repetition)i.walkMany(o,s,r);else{if(!(o instanceof n.Alternation))throw Error("non exhaustive match");i.walkOr(o,s,r)}})},e.prototype.walkTerminal=function(e,t,n){},e.prototype.walkProdRef=function(e,t,n){},e.prototype.walkFlat=function(e,t,n){var r=t.concat(n);this.walk(e,r)},e.prototype.walkOption=function(e,t,n){var r=t.concat(n);this.walk(e,r)},e.prototype.walkAtLeastOne=function(e,t,r){var i=[new n.Option({definition:e.definition})].concat(t,r);this.walk(e,i)},e.prototype.walkAtLeastOneSep=function(e,t,n){var r=i(e,t,n);this.walk(e,r)},e.prototype.walkMany=function(e,t,r){var i=[new n.Option({definition:e.definition})].concat(t,r);this.walk(e,i)},e.prototype.walkManySep=function(e,t,n){var r=i(e,t,n);this.walk(e,r)},e.prototype.walkOr=function(e,r,i){var o=this,a=r.concat(i);t.forEach(e.definition,function(e){var t=new n.Alternative({definition:[e]});o.walk(t,a)})},e}();function i(e,t,r){return[new n.Option({definition:[new n.Terminal({terminalType:e.separator})].concat(e.definition)})].concat(t,r)}e.RestWalker=r}),hc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.GAstVisitor=void 0;var t=lc(),n=function(){function e(){}return e.prototype.visit=function(e){var n=e;switch(n.constructor){case t.NonTerminal:return this.visitNonTerminal(n);case t.Alternative:return this.visitAlternative(n);case t.Option:return this.visitOption(n);case t.RepetitionMandatory:return this.visitRepetitionMandatory(n);case t.RepetitionMandatoryWithSeparator:return this.visitRepetitionMandatoryWithSeparator(n);case t.RepetitionWithSeparator:return this.visitRepetitionWithSeparator(n);case t.Repetition:return this.visitRepetition(n);case t.Alternation:return this.visitAlternation(n);case t.Terminal:return this.visitTerminal(n);case t.Rule:return this.visitRule(n);default:throw Error("non exhaustive match")}},e.prototype.visitNonTerminal=function(e){},e.prototype.visitAlternative=function(e){},e.prototype.visitOption=function(e){},e.prototype.visitRepetition=function(e){},e.prototype.visitRepetitionMandatory=function(e){},e.prototype.visitRepetitionMandatoryWithSeparator=function(e){},e.prototype.visitRepetitionWithSeparator=function(e){},e.prototype.visitAlternation=function(e){},e.prototype.visitTerminal=function(e){},e.prototype.visitRule=function(e){},e}();e.GAstVisitor=n}),dc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.collectMethods=e.DslMethodsCollectorVisitor=e.getProductionDslName=e.isBranchingProd=e.isOptionalProd=e.isSequenceProd=void 0;var r=ec(),i=lc(),o=hc();e.isSequenceProd=function(e){return e instanceof i.Alternative||e instanceof i.Option||e instanceof i.Repetition||e instanceof i.RepetitionMandatory||e instanceof i.RepetitionMandatoryWithSeparator||e instanceof i.RepetitionWithSeparator||e instanceof i.Terminal||e instanceof i.Rule},e.isOptionalProd=function e(t,n){return void 0===n&&(n=[]),!!(t instanceof i.Option||t instanceof i.Repetition||t instanceof i.RepetitionWithSeparator)||(t instanceof i.Alternation?r.some(t.definition,function(t){return e(t,n)}):!(t instanceof i.NonTerminal&&r.contains(n,t))&&(t instanceof i.AbstractProduction&&(t instanceof i.NonTerminal&&n.push(t),r.every(t.definition,function(t){return e(t,n)}))))},e.isBranchingProd=function(e){return e instanceof i.Alternation},e.getProductionDslName=function(e){if(e instanceof i.NonTerminal)return"SUBRULE";if(e instanceof i.Option)return"OPTION";if(e instanceof i.Alternation)return"OR";if(e instanceof i.RepetitionMandatory)return"AT_LEAST_ONE";if(e instanceof i.RepetitionMandatoryWithSeparator)return"AT_LEAST_ONE_SEP";if(e instanceof i.RepetitionWithSeparator)return"MANY_SEP";if(e instanceof i.Repetition)return"MANY";if(e instanceof i.Terminal)return"CONSUME";throw Error("non exhaustive match")};var a=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.separator="-",t.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]},t}return n(t,e),t.prototype.reset=function(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}},t.prototype.visitTerminal=function(e){var t=e.terminalType.name+this.separator+"Terminal";r.has(this.dslMethods,t)||(this.dslMethods[t]=[]),this.dslMethods[t].push(e)},t.prototype.visitNonTerminal=function(e){var t=e.nonTerminalName+this.separator+"Terminal";r.has(this.dslMethods,t)||(this.dslMethods[t]=[]),this.dslMethods[t].push(e)},t.prototype.visitOption=function(e){this.dslMethods.option.push(e)},t.prototype.visitRepetitionWithSeparator=function(e){this.dslMethods.repetitionWithSeparator.push(e)},t.prototype.visitRepetitionMandatory=function(e){this.dslMethods.repetitionMandatory.push(e)},t.prototype.visitRepetitionMandatoryWithSeparator=function(e){this.dslMethods.repetitionMandatoryWithSeparator.push(e)},t.prototype.visitRepetition=function(e){this.dslMethods.repetition.push(e)},t.prototype.visitAlternation=function(e){this.dslMethods.alternation.push(e)},t}(o.GAstVisitor);e.DslMethodsCollectorVisitor=a;var s=new a;e.collectMethods=function(e){s.reset(),e.accept(s);var t=s.dslMethods;return s.reset(),t}}),pc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.firstForTerminal=e.firstForBranching=e.firstForSequence=e.first=void 0;var t=ec(),n=lc(),r=dc();function i(e){if(e instanceof n.NonTerminal)return i(e.referencedRule);if(e instanceof n.Terminal)return s(e);if(r.isSequenceProd(e))return o(e);if(r.isBranchingProd(e))return a(e);throw Error("non exhaustive match")}function o(e){for(var n,o=[],a=e.definition,s=0,c=a.length>s,l=!0;c&&l;)n=a[s],l=r.isOptionalProd(n),o=o.concat(i(n)),s+=1,c=a.length>s;return t.uniq(o)}function a(e){var n=t.map(e.definition,function(e){return i(e)});return t.uniq(t.flatten(n))}function s(e){return[e.terminalType]}e.first=i,e.firstForSequence=o,e.firstForBranching=a,e.firstForTerminal=s}),fc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.IN=void 0,e.IN="_~IN~_"}),mc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.buildInProdFollowPrefix=e.buildBetweenProdsFollowPrefix=e.computeAllProdsFollows=e.ResyncFollowsWalker=void 0;var r=uc(),i=pc(),o=ec(),a=fc(),s=lc(),c=function(e){function t(t){var n=e.call(this)||this;return n.topProd=t,n.follows={},n}return n(t,e),t.prototype.startWalking=function(){return this.walk(this.topProd),this.follows},t.prototype.walkTerminal=function(e,t,n){},t.prototype.walkProdRef=function(e,t,n){var r=l(e.referencedRule,e.idx)+this.topProd.name,o=t.concat(n),a=new s.Alternative({definition:o}),c=i.first(a);this.follows[r]=c},t}(r.RestWalker);function l(e,t){return e.name+t+a.IN}e.ResyncFollowsWalker=c,e.computeAllProdsFollows=function(e){var t={};return o.forEach(e,function(e){var n=new c(e).startWalking();o.assign(t,n)}),t},e.buildBetweenProdsFollowPrefix=l,e.buildInProdFollowPrefix=function(e){return e.terminalType.name+e.idx+a.IN}}),gc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defaultGrammarValidatorErrorProvider=e.defaultGrammarResolverErrorProvider=e.defaultParserErrorProvider=void 0;var t=cc(),n=ec(),r=ec(),i=lc(),o=dc();e.defaultParserErrorProvider={buildMismatchTokenMessage:function(e){var n=e.expected,r=e.actual;return e.previous,e.ruleName,"Expecting "+(t.hasTokenLabel(n)?"--\x3e "+t.tokenLabel(n)+" <--":"token of type --\x3e "+n.name+" <--")+" but found --\x3e '"+r.image+"' <--"},buildNotAllInputParsedMessage:function(e){var t=e.firstRedundant;return e.ruleName,"Redundant input, expecting EOF but found: "+t.image},buildNoViableAltMessage:function(e){var n=e.expectedPathsPerAlt,i=e.actual;e.previous;var o=e.customUserDescription;e.ruleName;var a="Expecting: ",s="\nbut found: '"+r.first(i).image+"'";if(o)return a+o+s;var c=r.reduce(n,function(e,t){return e.concat(t)},[]),l=r.map(c,function(e){return"["+r.map(e,function(e){return t.tokenLabel(e)}).join(", ")+"]"});return a+("one of these possible Token sequences:\n"+r.map(l,function(e,t){return" "+(t+1)+". "+e}).join("\n"))+s},buildEarlyExitMessage:function(e){var n=e.expectedIterationPaths,i=e.actual,o=e.customUserDescription;e.ruleName;var a="Expecting: ",s="\nbut found: '"+r.first(i).image+"'";return o?a+o+s:a+("expecting at least one iteration which starts with one of these possible Token sequences::\n <"+r.map(n,function(e){return"["+r.map(e,function(e){return t.tokenLabel(e)}).join(",")+"]"}).join(" ,")+">")+s}},Object.freeze(e.defaultParserErrorProvider),e.defaultGrammarResolverErrorProvider={buildRuleNotFoundError:function(e,t){return"Invalid grammar, reference to a rule which is not defined: ->"+t.nonTerminalName+"<-\ninside top level rule: ->"+e.name+"<-"}},e.defaultGrammarValidatorErrorProvider={buildDuplicateFoundError:function(e,t){var n,a=e.name,s=r.first(t),c=s.idx,l=o.getProductionDslName(s),u=(n=s)instanceof i.Terminal?n.terminalType.name:n instanceof i.NonTerminal?n.nonTerminalName:"",h="->"+l+(c>0?c:"")+"<- "+(u?"with argument: ->"+u+"<-":"")+"\n appears more than once ("+t.length+" times) in the top level rule: ->"+a+"<-.\n For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES\n ";return h=(h=h.replace(/[ \t]+/g," ")).replace(/\s\s+/g,"\n")},buildNamespaceConflictError:function(e){return"Namespace conflict found in grammar.\nThe grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <"+e.name+">.\nTo resolve this make sure each Terminal and Non-Terminal names are unique\nThis is easy to accomplish by using the convention that Terminal names start with an uppercase letter\nand Non-Terminal names start with a lower case letter."},buildAlternationPrefixAmbiguityError:function(e){var n=r.map(e.prefixPath,function(e){return t.tokenLabel(e)}).join(", "),i=0===e.alternation.idx?"":e.alternation.idx;return"Ambiguous alternatives: <"+e.ambiguityIndices.join(" ,")+"> due to common lookahead prefix\nin <OR"+i+"> inside <"+e.topLevelRule.name+"> Rule,\n<"+n+"> may appears as a prefix path in all these alternatives.\nSee: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX\nFor Further details."},buildAlternationAmbiguityError:function(e){var n=r.map(e.prefixPath,function(e){return t.tokenLabel(e)}).join(", "),i=0===e.alternation.idx?"":e.alternation.idx,o="Ambiguous Alternatives Detected: <"+e.ambiguityIndices.join(" ,")+"> in <OR"+i+"> inside <"+e.topLevelRule.name+"> Rule,\n<"+n+"> may appears as a prefix path in all these alternatives.\n";return o+="See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES\nFor Further details."},buildEmptyRepetitionError:function(e){var t=o.getProductionDslName(e.repetition);return 0!==e.repetition.idx&&(t+=e.repetition.idx),"The repetition <"+t+"> within Rule <"+e.topLevelRule.name+"> can never consume any tokens.\nThis could lead to an infinite loop."},buildTokenNameError:function(e){return"deprecated"},buildEmptyAlternationError:function(e){return"Ambiguous empty alternative: <"+(e.emptyChoiceIdx+1)+"> in <OR"+e.alternation.idx+"> inside <"+e.topLevelRule.name+"> Rule.\nOnly the last alternative may be an empty alternative."},buildTooManyAlternativesError:function(e){return"An Alternation cannot have more than 256 alternatives:\n<OR"+e.alternation.idx+"> inside <"+e.topLevelRule.name+"> Rule.\n has "+(e.alternation.definition.length+1)+" alternatives."},buildLeftRecursionError:function(e){var t=e.topLevelRule.name;return"Left Recursion found in grammar.\nrule: <"+t+"> can be invoked from itself (directly or indirectly)\nwithout consuming any Tokens. The grammar path that causes this is:\n "+(t+" --\x3e "+n.map(e.leftRecursionPath,function(e){return e.name}).concat([t]).join(" --\x3e "))+"\n To fix this refactor your grammar to remove the left recursion.\nsee: https://en.wikipedia.org/wiki/LL_parser#Left_Factoring."},buildInvalidRuleNameError:function(e){return"deprecated"},buildDuplicateRuleNameError:function(e){return"Duplicate definition, rule: ->"+(e.topLevelRule instanceof i.Rule?e.topLevelRule.name:e.topLevelRule)+"<- is already defined in the grammar: ->"+e.grammarName+"<-"}}}),bc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.GastRefResolverVisitor=e.resolveGrammar=void 0;var r=Fc(),i=ec(),o=hc();e.resolveGrammar=function(e,t){var n=new a(e,t);return n.resolveRefs(),n.errors};var a=function(e){function t(t,n){var r=e.call(this)||this;return r.nameToTopRule=t,r.errMsgProvider=n,r.errors=[],r}return n(t,e),t.prototype.resolveRefs=function(){var e=this;i.forEach(i.values(this.nameToTopRule),function(t){e.currTopLevel=t,t.accept(e)})},t.prototype.visitNonTerminal=function(e){var t=this.nameToTopRule[e.nonTerminalName];if(t)e.referencedRule=t;else{var n=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,e);this.errors.push({message:n,type:r.ParserDefinitionErrorType.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:e.nonTerminalName})}},t}(o.GAstVisitor);e.GastRefResolverVisitor=a}),yc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.nextPossibleTokensAfter=e.possiblePathsFrom=e.NextTerminalAfterAtLeastOneSepWalker=e.NextTerminalAfterAtLeastOneWalker=e.NextTerminalAfterManySepWalker=e.NextTerminalAfterManyWalker=e.AbstractNextTerminalAfterProductionWalker=e.NextAfterTokenWalker=e.AbstractNextPossibleTokensWalker=void 0;var r=uc(),i=ec(),o=pc(),a=lc(),s=function(e){function t(t,n){var r=e.call(this)||this;return r.topProd=t,r.path=n,r.possibleTokTypes=[],r.nextProductionName="",r.nextProductionOccurrence=0,r.found=!1,r.isAtEndOfPath=!1,r}return n(t,e),t.prototype.startWalking=function(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=i.cloneArr(this.path.ruleStack).reverse(),this.occurrenceStack=i.cloneArr(this.path.occurrenceStack).reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes},t.prototype.walk=function(t,n){void 0===n&&(n=[]),this.found||e.prototype.walk.call(this,t,n)},t.prototype.walkProdRef=function(e,t,n){if(e.referencedRule.name===this.nextProductionName&&e.idx===this.nextProductionOccurrence){var r=t.concat(n);this.updateExpectedNext(),this.walk(e.referencedRule,r)}},t.prototype.updateExpectedNext=function(){i.isEmpty(this.ruleStack)?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())},t}(r.RestWalker);e.AbstractNextPossibleTokensWalker=s;var c=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.path=n,r.nextTerminalName="",r.nextTerminalOccurrence=0,r.nextTerminalName=r.path.lastTok.name,r.nextTerminalOccurrence=r.path.lastTokOccurrence,r}return n(t,e),t.prototype.walkTerminal=function(e,t,n){if(this.isAtEndOfPath&&e.terminalType.name===this.nextTerminalName&&e.idx===this.nextTerminalOccurrence&&!this.found){var r=t.concat(n),i=new a.Alternative({definition:r});this.possibleTokTypes=o.first(i),this.found=!0}},t}(s);e.NextAfterTokenWalker=c;var l=function(e){function t(t,n){var r=e.call(this)||this;return r.topRule=t,r.occurrence=n,r.result={token:void 0,occurrence:void 0,isEndOfRule:void 0},r}return n(t,e),t.prototype.startWalking=function(){return this.walk(this.topRule),this.result},t}(r.RestWalker);e.AbstractNextTerminalAfterProductionWalker=l;var u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.walkMany=function(t,n,r){if(t.idx===this.occurrence){var o=i.first(n.concat(r));this.result.isEndOfRule=void 0===o,o instanceof a.Terminal&&(this.result.token=o.terminalType,this.result.occurrence=o.idx)}else e.prototype.walkMany.call(this,t,n,r)},t}(l);e.NextTerminalAfterManyWalker=u;var h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.walkManySep=function(t,n,r){if(t.idx===this.occurrence){var o=i.first(n.concat(r));this.result.isEndOfRule=void 0===o,o instanceof a.Terminal&&(this.result.token=o.terminalType,this.result.occurrence=o.idx)}else e.prototype.walkManySep.call(this,t,n,r)},t}(l);e.NextTerminalAfterManySepWalker=h;var d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.walkAtLeastOne=function(t,n,r){if(t.idx===this.occurrence){var o=i.first(n.concat(r));this.result.isEndOfRule=void 0===o,o instanceof a.Terminal&&(this.result.token=o.terminalType,this.result.occurrence=o.idx)}else e.prototype.walkAtLeastOne.call(this,t,n,r)},t}(l);e.NextTerminalAfterAtLeastOneWalker=d;var p=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.walkAtLeastOneSep=function(t,n,r){if(t.idx===this.occurrence){var o=i.first(n.concat(r));this.result.isEndOfRule=void 0===o,o instanceof a.Terminal&&(this.result.token=o.terminalType,this.result.occurrence=o.idx)}else e.prototype.walkAtLeastOneSep.call(this,t,n,r)},t}(l);function f(e,t,n,r){var o=i.cloneArr(n);o.push(e.name);var a=i.cloneArr(r);return a.push(1),{idx:t,def:e.definition,ruleStack:o,occurrenceStack:a}}e.NextTerminalAfterAtLeastOneSepWalker=p,e.possiblePathsFrom=function e(t,n,r){void 0===r&&(r=[]),r=i.cloneArr(r);var o=[],s=0;function c(a){var c=e(function(e){return e.concat(i.drop(t,s+1))}(a),n,r);return o.concat(c)}for(;r.length<n&&s<t.length;){var l=t[s];if(l instanceof a.Alternative)return c(l.definition);if(l instanceof a.NonTerminal)return c(l.definition);if(l instanceof a.Option)o=c(l.definition);else{if(l instanceof a.RepetitionMandatory)return c(u=l.definition.concat([new a.Repetition({definition:l.definition})]));if(l instanceof a.RepetitionMandatoryWithSeparator)return c(u=[new a.Alternative({definition:l.definition}),new a.Repetition({definition:[new a.Terminal({terminalType:l.separator})].concat(l.definition)})]);if(l instanceof a.RepetitionWithSeparator){var u=l.definition.concat([new a.Repetition({definition:[new a.Terminal({terminalType:l.separator})].concat(l.definition)})]);o=c(u)}else if(l instanceof a.Repetition){u=l.definition.concat([new a.Repetition({definition:l.definition})]);o=c(u)}else{if(l instanceof a.Alternation)return i.forEach(l.definition,function(e){!1===i.isEmpty(e.definition)&&(o=c(e.definition))}),o;if(!(l instanceof a.Terminal))throw Error("non exhaustive match");r.push(l.terminalType)}}s++}return o.push({partialPath:r,suffixDef:i.drop(t,s)}),o},e.nextPossibleTokensAfter=function(e,t,n,r){var o="EXIT_NONE_TERMINAL",s=[o],c="EXIT_ALTERNATIVE",l=!1,u=t.length,h=u-r-1,d=[],p=[];for(p.push({idx:-1,def:e,ruleStack:[],occurrenceStack:[]});!i.isEmpty(p);){var m=p.pop();if(m!==c){var g=m.def,b=m.idx,y=m.ruleStack,v=m.occurrenceStack;if(!i.isEmpty(g)){var x=g[0];if(x===o){var w={idx:b,def:i.drop(g),ruleStack:i.dropRight(y),occurrenceStack:i.dropRight(v)};p.push(w)}else if(x instanceof a.Terminal)if(b<u-1){var E=b+1;if(n(t[E],x.terminalType)){w={idx:E,def:i.drop(g),ruleStack:y,occurrenceStack:v};p.push(w)}}else{if(b!==u-1)throw Error("non exhaustive match");d.push({nextTokenType:x.terminalType,nextTokenOccurrence:x.idx,ruleStack:y,occurrenceStack:v}),l=!0}else if(x instanceof a.NonTerminal){var T=i.cloneArr(y);T.push(x.nonTerminalName);var A=i.cloneArr(v);A.push(x.idx);w={idx:b,def:x.definition.concat(s,i.drop(g)),ruleStack:T,occurrenceStack:A};p.push(w)}else if(x instanceof a.Option){var C={idx:b,def:i.drop(g),ruleStack:y,occurrenceStack:v};p.push(C),p.push(c);var O={idx:b,def:x.definition.concat(i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(O)}else if(x instanceof a.RepetitionMandatory){var k=new a.Repetition({definition:x.definition,idx:x.idx});w={idx:b,def:x.definition.concat([k],i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(w)}else if(x instanceof a.RepetitionMandatoryWithSeparator){var S=new a.Terminal({terminalType:x.separator});k=new a.Repetition({definition:[S].concat(x.definition),idx:x.idx}),w={idx:b,def:x.definition.concat([k],i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(w)}else if(x instanceof a.RepetitionWithSeparator){C={idx:b,def:i.drop(g),ruleStack:y,occurrenceStack:v};p.push(C),p.push(c);S=new a.Terminal({terminalType:x.separator});var M=new a.Repetition({definition:[S].concat(x.definition),idx:x.idx});O={idx:b,def:x.definition.concat([M],i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(O)}else if(x instanceof a.Repetition){C={idx:b,def:i.drop(g),ruleStack:y,occurrenceStack:v};p.push(C),p.push(c);M=new a.Repetition({definition:x.definition,idx:x.idx}),O={idx:b,def:x.definition.concat([M],i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(O)}else if(x instanceof a.Alternation)for(var R=x.definition.length-1;R>=0;R--){var I={idx:b,def:x.definition[R].definition.concat(i.drop(g)),ruleStack:y,occurrenceStack:v};p.push(I),p.push(c)}else if(x instanceof a.Alternative)p.push({idx:b,def:x.definition.concat(i.drop(g)),ruleStack:y,occurrenceStack:v});else{if(!(x instanceof a.Rule))throw Error("non exhaustive match");p.push(f(x,b,y,v))}}}else l&&i.last(p).idx<=h&&p.pop()}return d}}),vc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.areTokenCategoriesNotUsed=e.isStrictPrefixOfPath=e.containsPath=e.getLookaheadPathsForOptionalProd=e.getLookaheadPathsForOr=e.lookAheadSequenceFromAlternatives=e.buildSingleAlternativeLookaheadFunction=e.buildAlternativesLookAheadFunc=e.buildLookaheadFuncForOptionalProd=e.buildLookaheadFuncForOr=e.getProdType=e.PROD_TYPE=void 0;var r,i=ec(),o=yc(),a=uc(),s=oc(),c=lc(),l=hc();!function(e){e[e.OPTION=0]="OPTION",e[e.REPETITION=1]="REPETITION",e[e.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",e[e.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",e[e.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",e[e.ALTERNATION=5]="ALTERNATION"}(r=e.PROD_TYPE||(e.PROD_TYPE={})),e.getProdType=function(e){if(e instanceof c.Option)return r.OPTION;if(e instanceof c.Repetition)return r.REPETITION;if(e instanceof c.RepetitionMandatory)return r.REPETITION_MANDATORY;if(e instanceof c.RepetitionMandatoryWithSeparator)return r.REPETITION_MANDATORY_WITH_SEPARATOR;if(e instanceof c.RepetitionWithSeparator)return r.REPETITION_WITH_SEPARATOR;if(e instanceof c.Alternation)return r.ALTERNATION;throw Error("non exhaustive match")},e.buildLookaheadFuncForOr=function(e,t,n,r,i,o){var a=g(e,t,n);return o(a,r,v(a)?s.tokenStructuredMatcherNoCategories:s.tokenStructuredMatcher,i)},e.buildLookaheadFuncForOptionalProd=function(e,t,n,r,i,o){var a=b(e,t,i,n),c=v(a)?s.tokenStructuredMatcherNoCategories:s.tokenStructuredMatcher;return o(a[0],c,r)},e.buildAlternativesLookAheadFunc=function(e,t,n,r){var o=e.length,a=i.every(e,function(e){return i.every(e,function(e){return 1===e.length})});if(t)return function(t){for(var r=i.map(t,function(e){return e.GATE}),a=0;a<o;a++){var s=e[a],c=s.length,l=r[a];if(void 0===l||!1!==l.call(this))e:for(var u=0;u<c;u++){for(var h=s[u],d=h.length,p=0;p<d;p++){var f=this.LA(p+1);if(!1===n(f,h[p]))continue e}return a}}};if(a&&!r){var s=i.map(e,function(e){return i.flatten(e)}),c=i.reduce(s,function(e,t,n){return i.forEach(t,function(t){i.has(e,t.tokenTypeIdx)||(e[t.tokenTypeIdx]=n),i.forEach(t.categoryMatches,function(t){i.has(e,t)||(e[t]=n)})}),e},[]);return function(){var e=this.LA(1);return c[e.tokenTypeIdx]}}return function(){for(var t=0;t<o;t++){var r=e[t],i=r.length;e:for(var a=0;a<i;a++){for(var s=r[a],c=s.length,l=0;l<c;l++){var u=this.LA(l+1);if(!1===n(u,s[l]))continue e}return t}}}},e.buildSingleAlternativeLookaheadFunction=function(e,t,n){var r=i.every(e,function(e){return 1===e.length}),o=e.length;if(r&&!n){var a=i.flatten(e);if(1===a.length&&i.isEmpty(a[0].categoryMatches)){var s=a[0].tokenTypeIdx;return function(){return this.LA(1).tokenTypeIdx===s}}var c=i.reduce(a,function(e,t,n){return e[t.tokenTypeIdx]=!0,i.forEach(t.categoryMatches,function(t){e[t]=!0}),e},[]);return function(){var e=this.LA(1);return!0===c[e.tokenTypeIdx]}}return function(){e:for(var n=0;n<o;n++){for(var r=e[n],i=r.length,a=0;a<i;a++){var s=this.LA(a+1);if(!1===t(s,r[a]))continue e}return!0}return!1}};var u=function(e){function t(t,n,r){var i=e.call(this)||this;return i.topProd=t,i.targetOccurrence=n,i.targetProdType=r,i}return n(t,e),t.prototype.startWalking=function(){return this.walk(this.topProd),this.restDef},t.prototype.checkIsTarget=function(e,t,n,r){return e.idx===this.targetOccurrence&&this.targetProdType===t&&(this.restDef=n.concat(r),!0)},t.prototype.walkOption=function(t,n,i){this.checkIsTarget(t,r.OPTION,n,i)||e.prototype.walkOption.call(this,t,n,i)},t.prototype.walkAtLeastOne=function(t,n,i){this.checkIsTarget(t,r.REPETITION_MANDATORY,n,i)||e.prototype.walkOption.call(this,t,n,i)},t.prototype.walkAtLeastOneSep=function(t,n,i){this.checkIsTarget(t,r.REPETITION_MANDATORY_WITH_SEPARATOR,n,i)||e.prototype.walkOption.call(this,t,n,i)},t.prototype.walkMany=function(t,n,i){this.checkIsTarget(t,r.REPETITION,n,i)||e.prototype.walkOption.call(this,t,n,i)},t.prototype.walkManySep=function(t,n,i){this.checkIsTarget(t,r.REPETITION_WITH_SEPARATOR,n,i)||e.prototype.walkOption.call(this,t,n,i)},t}(a.RestWalker),h=function(e){function t(t,n,r){var i=e.call(this)||this;return i.targetOccurrence=t,i.targetProdType=n,i.targetRef=r,i.result=[],i}return n(t,e),t.prototype.checkIsTarget=function(e,t){e.idx===this.targetOccurrence&&this.targetProdType===t&&(void 0===this.targetRef||e===this.targetRef)&&(this.result=e.definition)},t.prototype.visitOption=function(e){this.checkIsTarget(e,r.OPTION)},t.prototype.visitRepetition=function(e){this.checkIsTarget(e,r.REPETITION)},t.prototype.visitRepetitionMandatory=function(e){this.checkIsTarget(e,r.REPETITION_MANDATORY)},t.prototype.visitRepetitionMandatoryWithSeparator=function(e){this.checkIsTarget(e,r.REPETITION_MANDATORY_WITH_SEPARATOR)},t.prototype.visitRepetitionWithSeparator=function(e){this.checkIsTarget(e,r.REPETITION_WITH_SEPARATOR)},t.prototype.visitAlternation=function(e){this.checkIsTarget(e,r.ALTERNATION)},t}(l.GAstVisitor);function d(e){for(var t=new Array(e),n=0;n<e;n++)t[n]=[];return t}function p(e){for(var t=[""],n=0;n<e.length;n++){for(var r=e[n],i=[],o=0;o<t.length;o++){var a=t[o];i.push(a+"_"+r.tokenTypeIdx);for(var s=0;s<r.categoryMatches.length;s++){var c="_"+r.categoryMatches[s];i.push(a+c)}}t=i}return t}function f(e,t,n){for(var r=0;r<e.length;r++)if(r!==n)for(var i=e[r],o=0;o<t.length;o++){if(!0===i[t[o]])return!1}return!0}function m(e,t){for(var n=i.map(e,function(e){return o.possiblePathsFrom([e],1)}),r=d(n.length),a=i.map(n,function(e){var t={};return i.forEach(e,function(e){var n=p(e.partialPath);i.forEach(n,function(e){t[e]=!0})}),t}),s=n,c=1;c<=t;c++){var l=s;s=d(l.length);for(var u=function(e){for(var n=l[e],u=0;u<n.length;u++){var h=n[u].partialPath,d=n[u].suffixDef,m=p(h);if(f(a,m,e)||i.isEmpty(d)||h.length===t){var g=r[e];if(!1===y(g,h)){g.push(h);for(var b=0;b<m.length;b++){var v=m[b];a[e][v]=!0}}}else{var x=o.possiblePathsFrom(d,c+1,h);s[e]=s[e].concat(x),i.forEach(x,function(t){var n=p(t.partialPath);i.forEach(n,function(t){a[e][t]=!0})})}}},h=0;h<l.length;h++)u(h)}return r}function g(e,t,n,i){var o=new h(e,r.ALTERNATION,i);return t.accept(o),m(o.result,n)}function b(e,t,n,r){var i=new h(e,n);t.accept(i);var o=i.result,a=new u(t,e,n).startWalking();return m([new c.Alternative({definition:o}),new c.Alternative({definition:a})],r)}function y(e,t){e:for(var n=0;n<e.length;n++){var r=e[n];if(r.length===t.length){for(var i=0;i<r.length;i++){var o=t[i],a=r[i];if(!1===(o===a||void 0!==a.categoryMatchesMap[o.tokenTypeIdx]))continue e}return!0}}return!1}function v(e){return i.every(e,function(e){return i.every(e,function(e){return i.every(e,function(e){return i.isEmpty(e.categoryMatches)})})})}e.lookAheadSequenceFromAlternatives=m,e.getLookaheadPathsForOr=g,e.getLookaheadPathsForOptionalProd=b,e.containsPath=y,e.isStrictPrefixOfPath=function(e,t){return e.length<t.length&&i.every(e,function(e,n){var r=t[n];return e===r||r.categoryMatchesMap[e.tokenTypeIdx]})},e.areTokenCategoriesNotUsed=v}),xc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.checkPrefixAlternativesAmbiguities=e.validateSomeNonEmptyLookaheadPath=e.validateTooManyAlts=e.RepetionCollector=e.validateAmbiguousAlternationAlternatives=e.validateEmptyOrAlternative=e.getFirstNoneTerminal=e.validateNoLeftRecursion=e.validateRuleIsOverridden=e.validateRuleDoesNotAlreadyExist=e.OccurrenceValidationCollector=e.identifyProductionForDuplicates=e.validateGrammar=void 0;var r=ec(),i=ec(),o=Fc(),a=dc(),s=vc(),c=yc(),l=lc(),u=hc();function h(e){return a.getProductionDslName(e)+"_#_"+e.idx+"_#_"+d(e)}function d(e){return e instanceof l.Terminal?e.terminalType.name:e instanceof l.NonTerminal?e.nonTerminalName:""}e.validateGrammar=function(e,t,n,s,c){var l=r.map(e,function(e){return function(e,t){var n=new p;e.accept(n);var i=n.allProductions,s=r.groupBy(i,h),c=r.pick(s,function(e){return e.length>1}),l=r.map(r.values(c),function(n){var i=r.first(n),s=t.buildDuplicateFoundError(e,n),c=a.getProductionDslName(i),l={message:s,type:o.ParserDefinitionErrorType.DUPLICATE_PRODUCTIONS,ruleName:e.name,dslName:c,occurrence:i.idx},u=d(i);return u&&(l.parameter=u),l});return l}(e,s)}),u=r.map(e,function(e){return m(e,e,s)}),g=[],b=[],x=[];i.every(u,i.isEmpty)&&(g=i.map(e,function(e){return y(e,s)}),b=i.map(e,function(e){return v(e,t,s)}),x=E(e,t,s));var T=function(e,t,n){var r=[],a=i.map(t,function(e){return e.name});return i.forEach(e,function(e){var t=e.name;if(i.contains(a,t)){var s=n.buildNamespaceConflictError(e);r.push({message:s,type:o.ParserDefinitionErrorType.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:t})}}),r}(e,n,s),A=i.map(e,function(e){return w(e,s)}),C=i.map(e,function(t){return f(t,e,c,s)});return r.flatten(l.concat(x,u,g,b,T,A,C))},e.identifyProductionForDuplicates=h;var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.allProductions=[],t}return n(t,e),t.prototype.visitNonTerminal=function(e){this.allProductions.push(e)},t.prototype.visitOption=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionWithSeparator=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionMandatory=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionMandatoryWithSeparator=function(e){this.allProductions.push(e)},t.prototype.visitRepetition=function(e){this.allProductions.push(e)},t.prototype.visitAlternation=function(e){this.allProductions.push(e)},t.prototype.visitTerminal=function(e){this.allProductions.push(e)},t}(u.GAstVisitor);function f(e,t,n,r){var a=[];if(i.reduce(t,function(t,n){return n.name===e.name?t+1:t},0)>1){var s=r.buildDuplicateRuleNameError({topLevelRule:e,grammarName:n});a.push({message:s,type:o.ParserDefinitionErrorType.DUPLICATE_RULE_NAME,ruleName:e.name})}return a}function m(e,t,n,i){void 0===i&&(i=[]);var a=[],s=g(t.definition);if(r.isEmpty(s))return[];var c=e.name;r.contains(s,e)&&a.push({message:n.buildLeftRecursionError({topLevelRule:e,leftRecursionPath:i}),type:o.ParserDefinitionErrorType.LEFT_RECURSION,ruleName:c});var l=r.difference(s,i.concat([e])),u=r.map(l,function(t){var o=r.cloneArr(i);return o.push(t),m(e,t,n,o)});return a.concat(r.flatten(u))}function g(e){var t=[];if(r.isEmpty(e))return t;var n=r.first(e);if(n instanceof l.NonTerminal)t.push(n.referencedRule);else if(n instanceof l.Alternative||n instanceof l.Option||n instanceof l.RepetitionMandatory||n instanceof l.RepetitionMandatoryWithSeparator||n instanceof l.RepetitionWithSeparator||n instanceof l.Repetition)t=t.concat(g(n.definition));else if(n instanceof l.Alternation)t=r.flatten(r.map(n.definition,function(e){return g(e.definition)}));else if(!(n instanceof l.Terminal))throw Error("non exhaustive match");var i=a.isOptionalProd(n),o=e.length>1;if(i&&o){var s=r.drop(e);return t.concat(g(s))}return t}e.OccurrenceValidationCollector=p,e.validateRuleDoesNotAlreadyExist=f,e.validateRuleIsOverridden=function(e,t,n){var i,a=[];return r.contains(t,e)||(i="Invalid rule override, rule: ->"+e+"<- cannot be overridden in the grammar: ->"+n+"<-as it is not defined in any of the super grammars ",a.push({message:i,type:o.ParserDefinitionErrorType.INVALID_RULE_OVERRIDE,ruleName:e})),a},e.validateNoLeftRecursion=m,e.getFirstNoneTerminal=g;var b=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.alternations=[],t}return n(t,e),t.prototype.visitAlternation=function(e){this.alternations.push(e)},t}(u.GAstVisitor);function y(e,t){var n=new b;e.accept(n);var i=n.alternations;return r.reduce(i,function(n,i){var a=r.dropRight(i.definition),s=r.map(a,function(n,a){var s=c.nextPossibleTokensAfter([n],[],null,1);return r.isEmpty(s)?{message:t.buildEmptyAlternationError({topLevelRule:e,alternation:i,emptyChoiceIdx:a}),type:o.ParserDefinitionErrorType.NONE_LAST_EMPTY_ALT,ruleName:e.name,occurrence:i.idx,alternative:a+1}:null});return n.concat(r.compact(s))},[])}function v(e,t,n){var a=new b;e.accept(a);var c=a.alternations;c=i.reject(c,function(e){return!0===e.ignoreAmbiguities});var l=r.reduce(c,function(a,c){var l=c.idx,u=c.maxLookahead||t,h=s.getLookaheadPathsForOr(l,e,u,c),d=function(e,t,n,a){var c=[],l=i.reduce(e,function(n,r,o){return!0===t.definition[o].ignoreAmbiguities||i.forEach(r,function(r){var a=[o];i.forEach(e,function(e,n){o!==n&&s.containsPath(e,r)&&!0!==t.definition[n].ignoreAmbiguities&&a.push(n)}),a.length>1&&!s.containsPath(c,r)&&(c.push(r),n.push({alts:a,path:r}))}),n},[]),u=r.map(l,function(e){var r=i.map(e.alts,function(e){return e+1});return{message:a.buildAlternationAmbiguityError({topLevelRule:n,alternation:t,ambiguityIndices:r,prefixPath:e.path}),type:o.ParserDefinitionErrorType.AMBIGUOUS_ALTS,ruleName:n.name,occurrence:t.idx,alternatives:[e.alts]}});return u}(h,c,e,n),p=T(h,c,e,n);return a.concat(d,p)},[]);return l}e.validateEmptyOrAlternative=y,e.validateAmbiguousAlternationAlternatives=v;var x=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.allProductions=[],t}return n(t,e),t.prototype.visitRepetitionWithSeparator=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionMandatory=function(e){this.allProductions.push(e)},t.prototype.visitRepetitionMandatoryWithSeparator=function(e){this.allProductions.push(e)},t.prototype.visitRepetition=function(e){this.allProductions.push(e)},t}(u.GAstVisitor);function w(e,t){var n=new b;e.accept(n);var i=n.alternations;return r.reduce(i,function(n,r){return r.definition.length>255&&n.push({message:t.buildTooManyAlternativesError({topLevelRule:e,alternation:r}),type:o.ParserDefinitionErrorType.TOO_MANY_ALTS,ruleName:e.name,occurrence:r.idx}),n},[])}function E(e,t,n){var r=[];return i.forEach(e,function(e){var a=new x;e.accept(a);var c=a.allProductions;i.forEach(c,function(a){var c=s.getProdType(a),l=a.maxLookahead||t,u=a.idx,h=s.getLookaheadPathsForOptionalProd(u,e,c,l)[0];if(i.isEmpty(i.flatten(h))){var d=n.buildEmptyRepetitionError({topLevelRule:e,repetition:a});r.push({message:d,type:o.ParserDefinitionErrorType.NO_NON_EMPTY_LOOKAHEAD,ruleName:e.name})}})}),r}function T(e,t,n,r){var a=[],c=i.reduce(e,function(e,t,n){var r=i.map(t,function(e){return{idx:n,path:e}});return e.concat(r)},[]);return i.forEach(c,function(e){if(!0!==t.definition[e.idx].ignoreAmbiguities){var l=e.idx,u=e.path,h=i.findAll(c,function(e){return!0!==t.definition[e.idx].ignoreAmbiguities&&e.idx<l&&s.isStrictPrefixOfPath(e.path,u)}),d=i.map(h,function(e){var i=[e.idx+1,l+1],a=0===t.idx?"":t.idx;return{message:r.buildAlternationPrefixAmbiguityError({topLevelRule:n,alternation:t,ambiguityIndices:i,prefixPath:e.path}),type:o.ParserDefinitionErrorType.AMBIGUOUS_PREFIX_ALTS,ruleName:n.name,occurrence:a,alternatives:i}});a=a.concat(d)}}),a}e.RepetionCollector=x,e.validateTooManyAlts=w,e.validateSomeNonEmptyLookaheadPath=E,e.checkPrefixAlternativesAmbiguities=T}),wc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.validateGrammar=e.resolveGrammar=void 0;var t=ec(),n=bc(),r=xc(),i=gc();e.resolveGrammar=function(e){e=t.defaults(e,{errMsgProvider:i.defaultGrammarResolverErrorProvider});var r={};return t.forEach(e.rules,function(e){r[e.name]=e}),n.resolveGrammar(r,e.errMsgProvider)},e.validateGrammar=function(e){return e=t.defaults(e,{errMsgProvider:i.defaultGrammarValidatorErrorProvider}),r.validateGrammar(e.rules,e.maxLookahead,e.tokenTypes,e.errMsgProvider,e.grammarName)}}),Ec=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.EarlyExitException=e.NotAllInputParsedException=e.NoViableAltException=e.MismatchedTokenException=e.isRecognitionException=void 0;var r=ec(),i="MismatchedTokenException",o="NoViableAltException",a="EarlyExitException",s="NotAllInputParsedException",c=[i,o,a,s];Object.freeze(c),e.isRecognitionException=function(e){return r.contains(c,e.name)};var l=function(e){function t(t,n){var r=this.constructor,i=e.call(this,t)||this;return i.token=n,i.resyncedTokens=[],Object.setPrototypeOf(i,r.prototype),Error.captureStackTrace&&Error.captureStackTrace(i,i.constructor),i}return n(t,e),t}(Error),u=function(e){function t(t,n,r){var o=e.call(this,t,n)||this;return o.previousToken=r,o.name=i,o}return n(t,e),t}(l);e.MismatchedTokenException=u;var h=function(e){function t(t,n,r){var i=e.call(this,t,n)||this;return i.previousToken=r,i.name=o,i}return n(t,e),t}(l);e.NoViableAltException=h;var d=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.name=s,r}return n(t,e),t}(l);e.NotAllInputParsedException=d;var p=function(e){function t(t,n,r){var i=e.call(this,t,n)||this;return i.previousToken=r,i.name=a,i}return n(t,e),t}(l);e.EarlyExitException=p}),Tc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.attemptInRepetitionRecovery=e.Recoverable=e.InRuleRecoveryException=e.IN_RULE_RECOVERY_EXCEPTION=e.EOF_FOLLOW_KEY=void 0;var t=cc(),n=ec(),r=Ec(),i=fc(),o=Fc();function a(t){this.name=e.IN_RULE_RECOVERY_EXCEPTION,this.message=t}e.EOF_FOLLOW_KEY={},e.IN_RULE_RECOVERY_EXCEPTION="InRuleRecoveryException",e.InRuleRecoveryException=a,a.prototype=Error.prototype;var s=function(){function s(){}return s.prototype.initRecoverable=function(e){this.firstAfterRepMap={},this.resyncFollows={},this.recoveryEnabled=n.has(e,"recoveryEnabled")?e.recoveryEnabled:o.DEFAULT_PARSER_CONFIG.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=c)},s.prototype.getTokenToInsert=function(e){var n=t.createTokenInstance(e,"",NaN,NaN,NaN,NaN,NaN,NaN);return n.isInsertedInRecovery=!0,n},s.prototype.canTokenTypeBeInsertedInRecovery=function(e){return!0},s.prototype.tryInRepetitionRecovery=function(e,t,i,o){for(var a=this,s=this.findReSyncTokenType(),c=this.exportLexerState(),l=[],u=!1,h=this.LA(1),d=this.LA(1),p=function(){var e=a.LA(0),t=a.errorMessageProvider.buildMismatchTokenMessage({expected:o,actual:h,previous:e,ruleName:a.getCurrRuleFullName()}),i=new r.MismatchedTokenException(t,h,a.LA(0));i.resyncedTokens=n.dropRight(l),a.SAVE_ERROR(i)};!u;){if(this.tokenMatcher(d,o))return void p();if(i.call(this))return p(),void e.apply(this,t);this.tokenMatcher(d,s)?u=!0:(d=this.SKIP_TOKEN(),this.addToResyncTokens(d,l))}this.importLexerState(c)},s.prototype.shouldInRepetitionRecoveryBeTried=function(e,t,n){return!(!1===n||void 0===e||void 0===t||this.tokenMatcher(this.LA(1),e)||this.isBackTracking()||this.canPerformInRuleRecovery(e,this.getFollowsForInRuleRecovery(e,t)))},s.prototype.getFollowsForInRuleRecovery=function(e,t){var n=this.getCurrentGrammarPath(e,t);return this.getNextPossibleTokenTypes(n)},s.prototype.tryInRuleRecovery=function(e,t){if(this.canRecoverWithSingleTokenInsertion(e,t))return this.getTokenToInsert(e);if(this.canRecoverWithSingleTokenDeletion(e)){var n=this.SKIP_TOKEN();return this.consumeToken(),n}throw new a("sad sad panda")},s.prototype.canPerformInRuleRecovery=function(e,t){return this.canRecoverWithSingleTokenInsertion(e,t)||this.canRecoverWithSingleTokenDeletion(e)},s.prototype.canRecoverWithSingleTokenInsertion=function(e,t){var r=this;if(!this.canTokenTypeBeInsertedInRecovery(e)||n.isEmpty(t))return!1;var i=this.LA(1);return void 0!==n.find(t,function(e){return r.tokenMatcher(i,e)})},s.prototype.canRecoverWithSingleTokenDeletion=function(e){return this.tokenMatcher(this.LA(2),e)},s.prototype.isInCurrentRuleReSyncSet=function(e){var t=this.getCurrFollowKey(),r=this.getFollowSetFromFollowKey(t);return n.contains(r,e)},s.prototype.findReSyncTokenType=function(){for(var e=this.flattenFollowSet(),t=this.LA(1),r=2;;){var i=t.tokenType;if(n.contains(e,i))return i;t=this.LA(r),r++}},s.prototype.getCurrFollowKey=function(){if(1===this.RULE_STACK.length)return e.EOF_FOLLOW_KEY;var t=this.getLastExplicitRuleShortName(),n=this.getLastExplicitRuleOccurrenceIndex(),r=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(t),idxInCallingRule:n,inRule:this.shortRuleNameToFullName(r)}},s.prototype.buildFullFollowKeyStack=function(){var t=this,r=this.RULE_STACK,i=this.RULE_OCCURRENCE_STACK;return n.map(r,function(n,o){return 0===o?e.EOF_FOLLOW_KEY:{ruleName:t.shortRuleNameToFullName(n),idxInCallingRule:i[o],inRule:t.shortRuleNameToFullName(r[o-1])}})},s.prototype.flattenFollowSet=function(){var e=this,t=n.map(this.buildFullFollowKeyStack(),function(t){return e.getFollowSetFromFollowKey(t)});return n.flatten(t)},s.prototype.getFollowSetFromFollowKey=function(n){if(n===e.EOF_FOLLOW_KEY)return[t.EOF];var r=n.ruleName+n.idxInCallingRule+i.IN+n.inRule;return this.resyncFollows[r]},s.prototype.addToResyncTokens=function(e,n){return this.tokenMatcher(e,t.EOF)||n.push(e),n},s.prototype.reSyncTo=function(e){for(var t=[],r=this.LA(1);!1===this.tokenMatcher(r,e);)r=this.SKIP_TOKEN(),this.addToResyncTokens(r,t);return n.dropRight(t)},s.prototype.attemptInRepetitionRecovery=function(e,t,n,r,i,o,a){},s.prototype.getCurrentGrammarPath=function(e,t){return{ruleStack:this.getHumanReadableRuleStack(),occurrenceStack:n.cloneArr(this.RULE_OCCURRENCE_STACK),lastTok:e,lastTokOccurrence:t}},s.prototype.getHumanReadableRuleStack=function(){var e=this;return n.map(this.RULE_STACK,function(t){return e.shortRuleNameToFullName(t)})},s}();function c(e,n,r,i,o,a,s){var c=this.getKeyForAutomaticLookahead(i,o),l=this.firstAfterRepMap[c];if(void 0===l){var u=this.getCurrRuleFullName();l=new a(this.getGAstProductions()[u],o).startWalking(),this.firstAfterRepMap[c]=l}var h=l.token,d=l.occurrence,p=l.isEndOfRule;1===this.RULE_STACK.length&&p&&void 0===h&&(h=t.EOF,d=1),this.shouldInRepetitionRecoveryBeTried(h,d,s)&&this.tryInRepetitionRecovery(e,n,r,h)}e.Recoverable=s,e.attemptInRepetitionRecovery=c}),Ac=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getKeyForAutomaticLookahead=e.AT_LEAST_ONE_SEP_IDX=e.MANY_SEP_IDX=e.AT_LEAST_ONE_IDX=e.MANY_IDX=e.OPTION_IDX=e.OR_IDX=e.BITS_FOR_ALT_IDX=e.BITS_FOR_RULE_IDX=e.BITS_FOR_OCCURRENCE_IDX=e.BITS_FOR_METHOD_TYPE=void 0,e.BITS_FOR_METHOD_TYPE=4,e.BITS_FOR_OCCURRENCE_IDX=8,e.BITS_FOR_RULE_IDX=12,e.BITS_FOR_ALT_IDX=8,e.OR_IDX=1<<e.BITS_FOR_OCCURRENCE_IDX,e.OPTION_IDX=2<<e.BITS_FOR_OCCURRENCE_IDX,e.MANY_IDX=3<<e.BITS_FOR_OCCURRENCE_IDX,e.AT_LEAST_ONE_IDX=4<<e.BITS_FOR_OCCURRENCE_IDX,e.MANY_SEP_IDX=5<<e.BITS_FOR_OCCURRENCE_IDX,e.AT_LEAST_ONE_SEP_IDX=6<<e.BITS_FOR_OCCURRENCE_IDX,e.getKeyForAutomaticLookahead=function(e,t,n){return n|t|e},e.BITS_FOR_ALT_IDX}),Cc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.LooksAhead=void 0;var t=vc(),n=ec(),r=Fc(),i=Ac(),o=dc(),a=function(){function e(){}return e.prototype.initLooksAhead=function(e){this.dynamicTokensEnabled=n.has(e,"dynamicTokensEnabled")?e.dynamicTokensEnabled:r.DEFAULT_PARSER_CONFIG.dynamicTokensEnabled,this.maxLookahead=n.has(e,"maxLookahead")?e.maxLookahead:r.DEFAULT_PARSER_CONFIG.maxLookahead,this.lookAheadFuncsCache=n.isES2015MapSupported()?new Map:[],n.isES2015MapSupported()?(this.getLaFuncFromCache=this.getLaFuncFromMap,this.setLaFuncCache=this.setLaFuncCacheUsingMap):(this.getLaFuncFromCache=this.getLaFuncFromObj,this.setLaFuncCache=this.setLaFuncUsingObj)},e.prototype.preComputeLookaheadFunctions=function(e){var r=this;n.forEach(e,function(e){r.TRACE_INIT(e.name+" Rule Lookahead",function(){var a=o.collectMethods(e),s=a.alternation,c=a.repetition,l=a.option,u=a.repetitionMandatory,h=a.repetitionMandatoryWithSeparator,d=a.repetitionWithSeparator;n.forEach(s,function(n){var a=0===n.idx?"":n.idx;r.TRACE_INIT(""+o.getProductionDslName(n)+a,function(){var o=t.buildLookaheadFuncForOr(n.idx,e,n.maxLookahead||r.maxLookahead,n.hasPredicates,r.dynamicTokensEnabled,r.lookAheadBuilderForAlternatives),a=i.getKeyForAutomaticLookahead(r.fullRuleNameToShort[e.name],i.OR_IDX,n.idx);r.setLaFuncCache(a,o)})}),n.forEach(c,function(n){r.computeLookaheadFunc(e,n.idx,i.MANY_IDX,t.PROD_TYPE.REPETITION,n.maxLookahead,o.getProductionDslName(n))}),n.forEach(l,function(n){r.computeLookaheadFunc(e,n.idx,i.OPTION_IDX,t.PROD_TYPE.OPTION,n.maxLookahead,o.getProductionDslName(n))}),n.forEach(u,function(n){r.computeLookaheadFunc(e,n.idx,i.AT_LEAST_ONE_IDX,t.PROD_TYPE.REPETITION_MANDATORY,n.maxLookahead,o.getProductionDslName(n))}),n.forEach(h,function(n){r.computeLookaheadFunc(e,n.idx,i.AT_LEAST_ONE_SEP_IDX,t.PROD_TYPE.REPETITION_MANDATORY_WITH_SEPARATOR,n.maxLookahead,o.getProductionDslName(n))}),n.forEach(d,function(n){r.computeLookaheadFunc(e,n.idx,i.MANY_SEP_IDX,t.PROD_TYPE.REPETITION_WITH_SEPARATOR,n.maxLookahead,o.getProductionDslName(n))})})})},e.prototype.computeLookaheadFunc=function(e,n,r,o,a,s){var c=this;this.TRACE_INIT(""+s+(0===n?"":n),function(){var s=t.buildLookaheadFuncForOptionalProd(n,e,a||c.maxLookahead,c.dynamicTokensEnabled,o,c.lookAheadBuilderForOptional),l=i.getKeyForAutomaticLookahead(c.fullRuleNameToShort[e.name],r,n);c.setLaFuncCache(l,s)})},e.prototype.lookAheadBuilderForOptional=function(e,n,r){return t.buildSingleAlternativeLookaheadFunction(e,n,r)},e.prototype.lookAheadBuilderForAlternatives=function(e,n,r,i){return t.buildAlternativesLookAheadFunc(e,n,r,i)},e.prototype.getKeyForAutomaticLookahead=function(e,t){var n=this.getLastExplicitRuleShortName();return i.getKeyForAutomaticLookahead(n,e,t)},e.prototype.getLaFuncFromCache=function(e){},e.prototype.getLaFuncFromMap=function(e){return this.lookAheadFuncsCache.get(e)},e.prototype.getLaFuncFromObj=function(e){return this.lookAheadFuncsCache[e]},e.prototype.setLaFuncCache=function(e,t){},e.prototype.setLaFuncCacheUsingMap=function(e,t){this.lookAheadFuncsCache.set(e,t)},e.prototype.setLaFuncUsingObj=function(e,t){this.lookAheadFuncsCache[e]=t},e}();e.LooksAhead=a}),Oc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.addNoneTerminalToCst=e.addTerminalToCst=e.setNodeLocationFull=e.setNodeLocationOnlyOffset=void 0,e.setNodeLocationOnlyOffset=function(e,t){!0===isNaN(e.startOffset)?(e.startOffset=t.startOffset,e.endOffset=t.endOffset):e.endOffset<t.endOffset&&(e.endOffset=t.endOffset)},e.setNodeLocationFull=function(e,t){!0===isNaN(e.startOffset)?(e.startOffset=t.startOffset,e.startColumn=t.startColumn,e.startLine=t.startLine,e.endOffset=t.endOffset,e.endColumn=t.endColumn,e.endLine=t.endLine):e.endOffset<t.endOffset&&(e.endOffset=t.endOffset,e.endColumn=t.endColumn,e.endLine=t.endLine)},e.addTerminalToCst=function(e,t,n){void 0===e.children[n]?e.children[n]=[t]:e.children[n].push(t)},e.addNoneTerminalToCst=function(e,t,n){void 0===e.children[t]?e.children[t]=[n]:e.children[t].push(n)}}),kc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defineNameProp=e.functionName=e.classNameFromInstance=void 0;var t=ec();e.classNameFromInstance=function(e){return r(e.constructor)};var n="name";function r(e){return e.name||"anonymous"}e.functionName=r,e.defineNameProp=function(e,r){var i=Object.getOwnPropertyDescriptor(e,n);return!(!t.isUndefined(i)&&!i.configurable)&&(Object.defineProperty(e,n,{enumerable:!1,configurable:!0,writable:!1,value:r}),!0)}}),Sc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.validateRedundantMethods=e.validateMissingCstMethods=e.validateVisitor=e.CstVisitorDefinitionError=e.createBaseVisitorConstructorWithDefaults=e.createBaseSemanticVisitorConstructor=e.defaultVisit=void 0;var t,n,r=ec(),i=kc();function o(e,t){for(var n=r.keys(e),i=n.length,o=0;o<i;o++)for(var a=e[n[o]],s=a.length,c=0;c<s;c++){var l=a[c];void 0===l.tokenTypeIdx&&this[l.name](l.children,t)}}function a(e,t){var n=s(e,t),r=l(e,t);return n.concat(r)}function s(e,n){var o=r.map(n,function(n){if(!r.isFunction(e[n]))return{msg:"Missing visitor method: <"+n+"> on "+i.functionName(e.constructor)+" CST Visitor.",type:t.MISSING_METHOD,methodName:n}});return r.compact(o)}e.defaultVisit=o,e.createBaseSemanticVisitorConstructor=function(e,t){var n=function(){};i.defineNameProp(n,e+"BaseSemantics");var o={visit:function(e,t){if(r.isArray(e)&&(e=e[0]),!r.isUndefined(e))return this[e.name](e.children,t)},validateVisitor:function(){var e=a(this,t);if(!r.isEmpty(e)){var n=r.map(e,function(e){return e.msg});throw Error("Errors Detected in CST Visitor <"+i.functionName(this.constructor)+">:\n\t"+n.join("\n\n").replace(/\n/g,"\n\t"))}}};return(n.prototype=o).constructor=n,n._RULE_NAMES=t,n},e.createBaseVisitorConstructorWithDefaults=function(e,t,n){var a=function(){};i.defineNameProp(a,e+"BaseSemanticsWithDefaults");var s=Object.create(n.prototype);return r.forEach(t,function(e){s[e]=o}),(a.prototype=s).constructor=a,a},(n=t=e.CstVisitorDefinitionError||(e.CstVisitorDefinitionError={}))[n.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",n[n.MISSING_METHOD=1]="MISSING_METHOD",e.validateVisitor=a,e.validateMissingCstMethods=s;var c=["constructor","visit","validateVisitor"];function l(e,n){var o=[];for(var a in e)r.isFunction(e[a])&&!r.contains(c,a)&&!r.contains(n,a)&&o.push({msg:"Redundant visitor method: <"+a+"> on "+i.functionName(e.constructor)+" CST Visitor\nThere is no Grammar Rule corresponding to this method's name.\n",type:t.REDUNDANT_METHOD,methodName:a});return o}e.validateRedundantMethods=l}),Mc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeBuilder=void 0;var t=Oc(),n=ec(),r=Sc(),i=Fc(),o=function(){function e(){}return e.prototype.initTreeBuilder=function(e){if(this.CST_STACK=[],this.outputCst=e.outputCst,this.nodeLocationTracking=n.has(e,"nodeLocationTracking")?e.nodeLocationTracking:i.DEFAULT_PARSER_CONFIG.nodeLocationTracking,this.outputCst)if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=t.setNodeLocationFull,this.setNodeLocationFromNode=t.setNodeLocationFull,this.cstPostRule=n.NOOP,this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=n.NOOP,this.setNodeLocationFromNode=n.NOOP,this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=t.setNodeLocationOnlyOffset,this.setNodeLocationFromNode=t.setNodeLocationOnlyOffset,this.cstPostRule=n.NOOP,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=n.NOOP,this.setNodeLocationFromNode=n.NOOP,this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else{if(!/none/i.test(this.nodeLocationTracking))throw Error('Invalid <nodeLocationTracking> config option: "'+e.nodeLocationTracking+'"');this.setNodeLocationFromToken=n.NOOP,this.setNodeLocationFromNode=n.NOOP,this.cstPostRule=n.NOOP,this.setInitialNodeLocation=n.NOOP}else this.cstInvocationStateUpdate=n.NOOP,this.cstFinallyStateUpdate=n.NOOP,this.cstPostTerminal=n.NOOP,this.cstPostNonTerminal=n.NOOP,this.cstPostRule=n.NOOP},e.prototype.setInitialNodeLocationOnlyOffsetRecovery=function(e){e.location={startOffset:NaN,endOffset:NaN}},e.prototype.setInitialNodeLocationOnlyOffsetRegular=function(e){e.location={startOffset:this.LA(1).startOffset,endOffset:NaN}},e.prototype.setInitialNodeLocationFullRecovery=function(e){e.location={startOffset:NaN,startLine:NaN,startColumn:NaN,endOffset:NaN,endLine:NaN,endColumn:NaN}},e.prototype.setInitialNodeLocationFullRegular=function(e){var t=this.LA(1);e.location={startOffset:t.startOffset,startLine:t.startLine,startColumn:t.startColumn,endOffset:NaN,endLine:NaN,endColumn:NaN}},e.prototype.cstInvocationStateUpdate=function(e,t){var n={name:e,children:{}};this.setInitialNodeLocation(n),this.CST_STACK.push(n)},e.prototype.cstFinallyStateUpdate=function(){this.CST_STACK.pop()},e.prototype.cstPostRuleFull=function(e){var t=this.LA(0),n=e.location;n.startOffset<=t.startOffset?(n.endOffset=t.endOffset,n.endLine=t.endLine,n.endColumn=t.endColumn):(n.startOffset=NaN,n.startLine=NaN,n.startColumn=NaN)},e.prototype.cstPostRuleOnlyOffset=function(e){var t=this.LA(0),n=e.location;n.startOffset<=t.startOffset?n.endOffset=t.endOffset:n.startOffset=NaN},e.prototype.cstPostTerminal=function(e,n){var r=this.CST_STACK[this.CST_STACK.length-1];t.addTerminalToCst(r,n,e),this.setNodeLocationFromToken(r.location,n)},e.prototype.cstPostNonTerminal=function(e,n){var r=this.CST_STACK[this.CST_STACK.length-1];t.addNoneTerminalToCst(r,n,e),this.setNodeLocationFromNode(r.location,e.location)},e.prototype.getBaseCstVisitorConstructor=function(){if(n.isUndefined(this.baseCstVisitorConstructor)){var e=r.createBaseSemanticVisitorConstructor(this.className,n.keys(this.gastProductionsCache));return this.baseCstVisitorConstructor=e,e}return this.baseCstVisitorConstructor},e.prototype.getBaseCstVisitorConstructorWithDefaults=function(){if(n.isUndefined(this.baseCstVisitorWithDefaultsConstructor)){var e=r.createBaseVisitorConstructorWithDefaults(this.className,n.keys(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=e,e}return this.baseCstVisitorWithDefaultsConstructor},e.prototype.getLastExplicitRuleShortName=function(){var e=this.RULE_STACK;return e[e.length-1]},e.prototype.getPreviousExplicitRuleShortName=function(){var e=this.RULE_STACK;return e[e.length-2]},e.prototype.getLastExplicitRuleOccurrenceIndex=function(){var e=this.RULE_OCCURRENCE_STACK;return e[e.length-1]},e}();e.TreeBuilder=o}),Rc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.LexerAdapter=void 0;var t=Fc(),n=function(){function e(){}return e.prototype.initLexerAdapter=function(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1},Object.defineProperty(e.prototype,"input",{get:function(){return this.tokVector},set:function(e){if(!0!==this.selfAnalysisDone)throw Error("Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=e,this.tokVectorLength=e.length},enumerable:!1,configurable:!0}),e.prototype.SKIP_TOKEN=function(){return this.currIdx<=this.tokVector.length-2?(this.consumeToken(),this.LA(1)):t.END_OF_FILE},e.prototype.LA=function(e){var n=this.currIdx+e;return n<0||this.tokVectorLength<=n?t.END_OF_FILE:this.tokVector[n]},e.prototype.consumeToken=function(){this.currIdx++},e.prototype.exportLexerState=function(){return this.currIdx},e.prototype.importLexerState=function(e){this.currIdx=e},e.prototype.resetLexerState=function(){this.currIdx=-1},e.prototype.moveToTerminatedState=function(){this.currIdx=this.tokVector.length-1},e.prototype.getLexerPosition=function(){return this.exportLexerState()},e}();e.LexerAdapter=n}),Ic=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RecognizerApi=void 0;var t=ec(),n=Ec(),r=Fc(),i=gc(),o=xc(),a=lc(),s=function(){function e(){}return e.prototype.ACTION=function(e){return e.call(this)},e.prototype.consume=function(e,t,n){return this.consumeInternal(t,e,n)},e.prototype.subrule=function(e,t,n){return this.subruleInternal(t,e,n)},e.prototype.option=function(e,t){return this.optionInternal(t,e)},e.prototype.or=function(e,t){return this.orInternal(t,e)},e.prototype.many=function(e,t){return this.manyInternal(e,t)},e.prototype.atLeastOne=function(e,t){return this.atLeastOneInternal(e,t)},e.prototype.CONSUME=function(e,t){return this.consumeInternal(e,0,t)},e.prototype.CONSUME1=function(e,t){return this.consumeInternal(e,1,t)},e.prototype.CONSUME2=function(e,t){return this.consumeInternal(e,2,t)},e.prototype.CONSUME3=function(e,t){return this.consumeInternal(e,3,t)},e.prototype.CONSUME4=function(e,t){return this.consumeInternal(e,4,t)},e.prototype.CONSUME5=function(e,t){return this.consumeInternal(e,5,t)},e.prototype.CONSUME6=function(e,t){return this.consumeInternal(e,6,t)},e.prototype.CONSUME7=function(e,t){return this.consumeInternal(e,7,t)},e.prototype.CONSUME8=function(e,t){return this.consumeInternal(e,8,t)},e.prototype.CONSUME9=function(e,t){return this.consumeInternal(e,9,t)},e.prototype.SUBRULE=function(e,t){return this.subruleInternal(e,0,t)},e.prototype.SUBRULE1=function(e,t){return this.subruleInternal(e,1,t)},e.prototype.SUBRULE2=function(e,t){return this.subruleInternal(e,2,t)},e.prototype.SUBRULE3=function(e,t){return this.subruleInternal(e,3,t)},e.prototype.SUBRULE4=function(e,t){return this.subruleInternal(e,4,t)},e.prototype.SUBRULE5=function(e,t){return this.subruleInternal(e,5,t)},e.prototype.SUBRULE6=function(e,t){return this.subruleInternal(e,6,t)},e.prototype.SUBRULE7=function(e,t){return this.subruleInternal(e,7,t)},e.prototype.SUBRULE8=function(e,t){return this.subruleInternal(e,8,t)},e.prototype.SUBRULE9=function(e,t){return this.subruleInternal(e,9,t)},e.prototype.OPTION=function(e){return this.optionInternal(e,0)},e.prototype.OPTION1=function(e){return this.optionInternal(e,1)},e.prototype.OPTION2=function(e){return this.optionInternal(e,2)},e.prototype.OPTION3=function(e){return this.optionInternal(e,3)},e.prototype.OPTION4=function(e){return this.optionInternal(e,4)},e.prototype.OPTION5=function(e){return this.optionInternal(e,5)},e.prototype.OPTION6=function(e){return this.optionInternal(e,6)},e.prototype.OPTION7=function(e){return this.optionInternal(e,7)},e.prototype.OPTION8=function(e){return this.optionInternal(e,8)},e.prototype.OPTION9=function(e){return this.optionInternal(e,9)},e.prototype.OR=function(e){return this.orInternal(e,0)},e.prototype.OR1=function(e){return this.orInternal(e,1)},e.prototype.OR2=function(e){return this.orInternal(e,2)},e.prototype.OR3=function(e){return this.orInternal(e,3)},e.prototype.OR4=function(e){return this.orInternal(e,4)},e.prototype.OR5=function(e){return this.orInternal(e,5)},e.prototype.OR6=function(e){return this.orInternal(e,6)},e.prototype.OR7=function(e){return this.orInternal(e,7)},e.prototype.OR8=function(e){return this.orInternal(e,8)},e.prototype.OR9=function(e){return this.orInternal(e,9)},e.prototype.MANY=function(e){this.manyInternal(0,e)},e.prototype.MANY1=function(e){this.manyInternal(1,e)},e.prototype.MANY2=function(e){this.manyInternal(2,e)},e.prototype.MANY3=function(e){this.manyInternal(3,e)},e.prototype.MANY4=function(e){this.manyInternal(4,e)},e.prototype.MANY5=function(e){this.manyInternal(5,e)},e.prototype.MANY6=function(e){this.manyInternal(6,e)},e.prototype.MANY7=function(e){this.manyInternal(7,e)},e.prototype.MANY8=function(e){this.manyInternal(8,e)},e.prototype.MANY9=function(e){this.manyInternal(9,e)},e.prototype.MANY_SEP=function(e){this.manySepFirstInternal(0,e)},e.prototype.MANY_SEP1=function(e){this.manySepFirstInternal(1,e)},e.prototype.MANY_SEP2=function(e){this.manySepFirstInternal(2,e)},e.prototype.MANY_SEP3=function(e){this.manySepFirstInternal(3,e)},e.prototype.MANY_SEP4=function(e){this.manySepFirstInternal(4,e)},e.prototype.MANY_SEP5=function(e){this.manySepFirstInternal(5,e)},e.prototype.MANY_SEP6=function(e){this.manySepFirstInternal(6,e)},e.prototype.MANY_SEP7=function(e){this.manySepFirstInternal(7,e)},e.prototype.MANY_SEP8=function(e){this.manySepFirstInternal(8,e)},e.prototype.MANY_SEP9=function(e){this.manySepFirstInternal(9,e)},e.prototype.AT_LEAST_ONE=function(e){this.atLeastOneInternal(0,e)},e.prototype.AT_LEAST_ONE1=function(e){return this.atLeastOneInternal(1,e)},e.prototype.AT_LEAST_ONE2=function(e){this.atLeastOneInternal(2,e)},e.prototype.AT_LEAST_ONE3=function(e){this.atLeastOneInternal(3,e)},e.prototype.AT_LEAST_ONE4=function(e){this.atLeastOneInternal(4,e)},e.prototype.AT_LEAST_ONE5=function(e){this.atLeastOneInternal(5,e)},e.prototype.AT_LEAST_ONE6=function(e){this.atLeastOneInternal(6,e)},e.prototype.AT_LEAST_ONE7=function(e){this.atLeastOneInternal(7,e)},e.prototype.AT_LEAST_ONE8=function(e){this.atLeastOneInternal(8,e)},e.prototype.AT_LEAST_ONE9=function(e){this.atLeastOneInternal(9,e)},e.prototype.AT_LEAST_ONE_SEP=function(e){this.atLeastOneSepFirstInternal(0,e)},e.prototype.AT_LEAST_ONE_SEP1=function(e){this.atLeastOneSepFirstInternal(1,e)},e.prototype.AT_LEAST_ONE_SEP2=function(e){this.atLeastOneSepFirstInternal(2,e)},e.prototype.AT_LEAST_ONE_SEP3=function(e){this.atLeastOneSepFirstInternal(3,e)},e.prototype.AT_LEAST_ONE_SEP4=function(e){this.atLeastOneSepFirstInternal(4,e)},e.prototype.AT_LEAST_ONE_SEP5=function(e){this.atLeastOneSepFirstInternal(5,e)},e.prototype.AT_LEAST_ONE_SEP6=function(e){this.atLeastOneSepFirstInternal(6,e)},e.prototype.AT_LEAST_ONE_SEP7=function(e){this.atLeastOneSepFirstInternal(7,e)},e.prototype.AT_LEAST_ONE_SEP8=function(e){this.atLeastOneSepFirstInternal(8,e)},e.prototype.AT_LEAST_ONE_SEP9=function(e){this.atLeastOneSepFirstInternal(9,e)},e.prototype.RULE=function(e,n,o){if(void 0===o&&(o=r.DEFAULT_RULE_CONFIG),t.contains(this.definedRulesNames,e)){var a={message:i.defaultGrammarValidatorErrorProvider.buildDuplicateRuleNameError({topLevelRule:e,grammarName:this.className}),type:r.ParserDefinitionErrorType.DUPLICATE_RULE_NAME,ruleName:e};this.definitionErrors.push(a)}this.definedRulesNames.push(e);var s=this.defineRule(e,n,o);return this[e]=s,s},e.prototype.OVERRIDE_RULE=function(e,t,n){void 0===n&&(n=r.DEFAULT_RULE_CONFIG);var i=[];i=i.concat(o.validateRuleIsOverridden(e,this.definedRulesNames,this.className)),this.definitionErrors=this.definitionErrors.concat(i);var a=this.defineRule(e,t,n);return this[e]=a,a},e.prototype.BACKTRACK=function(e,t){return function(){this.isBackTrackingStack.push(1);var r=this.saveRecogState();try{return e.apply(this,t),!0}catch(e){if(n.isRecognitionException(e))return!1;throw e}finally{this.reloadRecogState(r),this.isBackTrackingStack.pop()}}},e.prototype.getGAstProductions=function(){return this.gastProductionsCache},e.prototype.getSerializedGastProductions=function(){return a.serializeGrammar(t.values(this.gastProductionsCache))},e}();e.RecognizerApi=s}),Pc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RecognizerEngine=void 0;var t=ec(),n=Ac(),r=Ec(),i=vc(),o=yc(),a=Fc(),s=Tc(),c=cc(),l=oc(),u=kc(),h=function(){function e(){}return e.prototype.initRecognizerEngine=function(e,n){if(this.className=u.classNameFromInstance(this),this.shortRuleNameToFull={},this.fullRuleNameToShort={},this.ruleShortNameIdx=256,this.tokenMatcher=l.tokenStructuredMatcherNoCategories,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[],this.gastProductionsCache={},t.has(n,"serializedGrammar"))throw Error("The Parser's configuration can no longer contain a <serializedGrammar> property.\n\tSee: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0\n\tFor Further details.");if(t.isArray(e)){if(t.isEmpty(e))throw Error("A Token Vocabulary cannot be empty.\n\tNote that the first argument for the parser constructor\n\tis no longer a Token vector (since v4.0).");if("number"==typeof e[0].startOffset)throw Error("The Parser constructor no longer accepts a token vector as the first argument.\n\tSee: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0\n\tFor Further details.")}if(t.isArray(e))this.tokensMap=t.reduce(e,function(e,t){return e[t.name]=t,e},{});else if(t.has(e,"modes")&&t.every(t.flatten(t.values(e.modes)),l.isTokenType)){var r=t.flatten(t.values(e.modes)),i=t.uniq(r);this.tokensMap=t.reduce(i,function(e,t){return e[t.name]=t,e},{})}else{if(!t.isObject(e))throw new Error("<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap=t.cloneObj(e)}this.tokensMap.EOF=c.EOF;var o=t.every(t.values(e),function(e){return t.isEmpty(e.categoryMatches)});this.tokenMatcher=o?l.tokenStructuredMatcherNoCategories:l.tokenStructuredMatcher,l.augmentTokenTypes(t.values(this.tokensMap))},e.prototype.defineRule=function(e,r,i){if(this.selfAnalysisDone)throw Error("Grammar rule <"+e+"> may not be defined after the 'performSelfAnalysis' method has been called'\nMake sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.");var o=t.has(i,"resyncEnabled")?i.resyncEnabled:a.DEFAULT_RULE_CONFIG.resyncEnabled,s=t.has(i,"recoveryValueFunc")?i.recoveryValueFunc:a.DEFAULT_RULE_CONFIG.recoveryValueFunc,c=this.ruleShortNameIdx<<n.BITS_FOR_METHOD_TYPE+n.BITS_FOR_OCCURRENCE_IDX;function l(e){try{if(!0===this.outputCst){r.apply(this,e);var t=this.CST_STACK[this.CST_STACK.length-1];return this.cstPostRule(t),t}return r.apply(this,e)}catch(e){return this.invokeRuleCatch(e,o,s)}finally{this.ruleFinallyStateUpdate()}}this.ruleShortNameIdx++,this.shortRuleNameToFull[c]=e,this.fullRuleNameToShort[e]=c;var u=function(t,n){return void 0===t&&(t=0),this.ruleInvocationStateUpdate(c,e,t),l.call(this,n)};return u.ruleName=e,u.originalGrammarAction=r,u},e.prototype.invokeRuleCatch=function(e,t,n){var i=1===this.RULE_STACK.length,o=t&&!this.isBackTracking()&&this.recoveryEnabled;if(r.isRecognitionException(e)){var a=e;if(o){var s,c=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(c))return a.resyncedTokens=this.reSyncTo(c),this.outputCst?((s=this.CST_STACK[this.CST_STACK.length-1]).recoveredNode=!0,s):n();throw this.outputCst&&((s=this.CST_STACK[this.CST_STACK.length-1]).recoveredNode=!0,a.partialCstResult=s),a}if(i)return this.moveToTerminatedState(),n();throw a}throw e},e.prototype.optionInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.OPTION_IDX,t);return this.optionInternalLogic(e,t,r)},e.prototype.optionInternalLogic=function(e,t,n){var r,i,o=this,a=this.getLaFuncFromCache(n);if(void 0!==e.DEF){if(r=e.DEF,void 0!==(i=e.GATE)){var s=a;a=function(){return i.call(o)&&s.call(o)}}}else r=e;if(!0===a.call(this))return r.call(this)},e.prototype.atLeastOneInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.AT_LEAST_ONE_IDX,e);return this.atLeastOneInternalLogic(e,t,r)},e.prototype.atLeastOneInternalLogic=function(e,t,r){var a,s,c=this,l=this.getLaFuncFromCache(r);if(void 0!==t.DEF){if(a=t.DEF,void 0!==(s=t.GATE)){var u=l;l=function(){return s.call(c)&&u.call(c)}}}else a=t;if(!0!==l.call(this))throw this.raiseEarlyExitException(e,i.PROD_TYPE.REPETITION_MANDATORY,t.ERR_MSG);for(var h=this.doSingleRepetition(a);!0===l.call(this)&&!0===h;)h=this.doSingleRepetition(a);this.attemptInRepetitionRecovery(this.atLeastOneInternal,[e,t],l,n.AT_LEAST_ONE_IDX,e,o.NextTerminalAfterAtLeastOneWalker)},e.prototype.atLeastOneSepFirstInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.AT_LEAST_ONE_SEP_IDX,e);this.atLeastOneSepFirstInternalLogic(e,t,r)},e.prototype.atLeastOneSepFirstInternalLogic=function(e,t,r){var a=this,s=t.DEF,c=t.SEP;if(!0!==this.getLaFuncFromCache(r).call(this))throw this.raiseEarlyExitException(e,i.PROD_TYPE.REPETITION_MANDATORY_WITH_SEPARATOR,t.ERR_MSG);s.call(this);for(var l=function(){return a.tokenMatcher(a.LA(1),c)};!0===this.tokenMatcher(this.LA(1),c);)this.CONSUME(c),s.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,c,l,s,o.NextTerminalAfterAtLeastOneSepWalker],l,n.AT_LEAST_ONE_SEP_IDX,e,o.NextTerminalAfterAtLeastOneSepWalker)},e.prototype.manyInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.MANY_IDX,e);return this.manyInternalLogic(e,t,r)},e.prototype.manyInternalLogic=function(e,t,r){var i,a,s=this,c=this.getLaFuncFromCache(r);if(void 0!==t.DEF){if(i=t.DEF,void 0!==(a=t.GATE)){var l=c;c=function(){return a.call(s)&&l.call(s)}}}else i=t;for(var u=!0;!0===c.call(this)&&!0===u;)u=this.doSingleRepetition(i);this.attemptInRepetitionRecovery(this.manyInternal,[e,t],c,n.MANY_IDX,e,o.NextTerminalAfterManyWalker,u)},e.prototype.manySepFirstInternal=function(e,t){var r=this.getKeyForAutomaticLookahead(n.MANY_SEP_IDX,e);this.manySepFirstInternalLogic(e,t,r)},e.prototype.manySepFirstInternalLogic=function(e,t,r){var i=this,a=t.DEF,s=t.SEP;if(!0===this.getLaFuncFromCache(r).call(this)){a.call(this);for(var c=function(){return i.tokenMatcher(i.LA(1),s)};!0===this.tokenMatcher(this.LA(1),s);)this.CONSUME(s),a.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,s,c,a,o.NextTerminalAfterManySepWalker],c,n.MANY_SEP_IDX,e,o.NextTerminalAfterManySepWalker)}},e.prototype.repetitionSepSecondInternal=function(e,t,r,i,o){for(;r();)this.CONSUME(t),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,t,r,i,o],r,n.AT_LEAST_ONE_SEP_IDX,e,o)},e.prototype.doSingleRepetition=function(e){var t=this.getLexerPosition();return e.call(this),this.getLexerPosition()>t},e.prototype.orInternal=function(e,r){var i=this.getKeyForAutomaticLookahead(n.OR_IDX,r),o=t.isArray(e)?e:e.DEF,a=this.getLaFuncFromCache(i).call(this,o);if(void 0!==a)return o[a].ALT.call(this);this.raiseNoAltException(r,e.ERR_MSG)},e.prototype.ruleFinallyStateUpdate=function(){if(this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop(),this.cstFinallyStateUpdate(),0===this.RULE_STACK.length&&!1===this.isAtEndOfInput()){var e=this.LA(1),t=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:e,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new r.NotAllInputParsedException(t,e))}},e.prototype.subruleInternal=function(e,t,n){var r;try{var i=void 0!==n?n.ARGS:void 0;return r=e.call(this,t,i),this.cstPostNonTerminal(r,void 0!==n&&void 0!==n.LABEL?n.LABEL:e.ruleName),r}catch(t){this.subruleInternalError(t,n,e.ruleName)}},e.prototype.subruleInternalError=function(e,t,n){throw r.isRecognitionException(e)&&void 0!==e.partialCstResult&&(this.cstPostNonTerminal(e.partialCstResult,void 0!==t&&void 0!==t.LABEL?t.LABEL:n),delete e.partialCstResult),e},e.prototype.consumeInternal=function(e,t,n){var r;try{var i=this.LA(1);!0===this.tokenMatcher(i,e)?(this.consumeToken(),r=i):this.consumeInternalError(e,i,n)}catch(n){r=this.consumeInternalRecovery(e,t,n)}return this.cstPostTerminal(void 0!==n&&void 0!==n.LABEL?n.LABEL:e.name,r),r},e.prototype.consumeInternalError=function(e,t,n){var i,o=this.LA(0);throw i=void 0!==n&&n.ERR_MSG?n.ERR_MSG:this.errorMessageProvider.buildMismatchTokenMessage({expected:e,actual:t,previous:o,ruleName:this.getCurrRuleFullName()}),this.SAVE_ERROR(new r.MismatchedTokenException(i,t,o))},e.prototype.consumeInternalRecovery=function(e,t,n){if(!this.recoveryEnabled||"MismatchedTokenException"!==n.name||this.isBackTracking())throw n;var r=this.getFollowsForInRuleRecovery(e,t);try{return this.tryInRuleRecovery(e,r)}catch(e){throw e.name===s.IN_RULE_RECOVERY_EXCEPTION?n:e}},e.prototype.saveRecogState=function(){var e=this.errors,n=t.cloneArr(this.RULE_STACK);return{errors:e,lexerState:this.exportLexerState(),RULE_STACK:n,CST_STACK:this.CST_STACK}},e.prototype.reloadRecogState=function(e){this.errors=e.errors,this.importLexerState(e.lexerState),this.RULE_STACK=e.RULE_STACK},e.prototype.ruleInvocationStateUpdate=function(e,t,n){this.RULE_OCCURRENCE_STACK.push(n),this.RULE_STACK.push(e),this.cstInvocationStateUpdate(t,e)},e.prototype.isBackTracking=function(){return 0!==this.isBackTrackingStack.length},e.prototype.getCurrRuleFullName=function(){var e=this.getLastExplicitRuleShortName();return this.shortRuleNameToFull[e]},e.prototype.shortRuleNameToFullName=function(e){return this.shortRuleNameToFull[e]},e.prototype.isAtEndOfInput=function(){return this.tokenMatcher(this.LA(1),c.EOF)},e.prototype.reset=function(){this.resetLexerState(),this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK=[],this.CST_STACK=[],this.RULE_OCCURRENCE_STACK=[]},e}();e.RecognizerEngine=h}),_c=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ErrorHandler=void 0;var t=Ec(),n=ec(),r=vc(),i=Fc(),o=function(){function e(){}return e.prototype.initErrorHandler=function(e){this._errors=[],this.errorMessageProvider=n.has(e,"errorMessageProvider")?e.errorMessageProvider:i.DEFAULT_PARSER_CONFIG.errorMessageProvider},e.prototype.SAVE_ERROR=function(e){if(t.isRecognitionException(e))return e.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:n.cloneArr(this.RULE_OCCURRENCE_STACK)},this._errors.push(e),e;throw Error("Trying to save an Error which is not a RecognitionException")},Object.defineProperty(e.prototype,"errors",{get:function(){return n.cloneArr(this._errors)},set:function(e){this._errors=e},enumerable:!1,configurable:!0}),e.prototype.raiseEarlyExitException=function(e,n,i){for(var o=this.getCurrRuleFullName(),a=this.getGAstProductions()[o],s=r.getLookaheadPathsForOptionalProd(e,a,n,this.maxLookahead)[0],c=[],l=1;l<=this.maxLookahead;l++)c.push(this.LA(l));var u=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:s,actual:c,previous:this.LA(0),customUserDescription:i,ruleName:o});throw this.SAVE_ERROR(new t.EarlyExitException(u,this.LA(1),this.LA(0)))},e.prototype.raiseNoAltException=function(e,n){for(var i=this.getCurrRuleFullName(),o=this.getGAstProductions()[i],a=r.getLookaheadPathsForOr(e,o,this.maxLookahead),s=[],c=1;c<=this.maxLookahead;c++)s.push(this.LA(c));var l=this.LA(0),u=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:a,actual:s,previous:l,customUserDescription:n,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new t.NoViableAltException(u,this.LA(1),l))},e}();e.ErrorHandler=o}),Nc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ContentAssist=void 0;var t=yc(),n=ec(),r=function(){function e(){}return e.prototype.initContentAssist=function(){},e.prototype.computeContentAssist=function(e,r){var i=this.gastProductionsCache[e];if(n.isUndefined(i))throw Error("Rule ->"+e+"<- does not exist in this grammar.");return t.nextPossibleTokensAfter([i],r,this.tokenMatcher,this.maxLookahead)},e.prototype.getNextPossibleTokenTypes=function(e){var r=n.first(e.ruleStack),i=this.getGAstProductions()[r];return new t.NextAfterTokenWalker(i,e).startWalking()},e}();e.ContentAssist=r}),Lc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.GastRecorder=void 0;var t=ec(),n=lc(),r=sc(),i=oc(),o=cc(),a=Fc(),s=Ac(),c={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(c);var l=!0,u=Math.pow(2,s.BITS_FOR_OCCURRENCE_IDX)-1,h=o.createToken({name:"RECORDING_PHASE_TOKEN",pattern:r.Lexer.NA});i.augmentTokenTypes([h]);var d=o.createTokenInstance(h,"This IToken indicates the Parser is in Recording Phase\n\tSee: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details",-1,-1,-1,-1,-1,-1);Object.freeze(d);var p={name:"This CSTNode indicates the Parser is in Recording Phase\n\tSee: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details",children:{}},f=function(){function e(){}return e.prototype.initGastRecorder=function(e){this.recordingProdStack=[],this.RECORDING_PHASE=!1},e.prototype.enableRecording=function(){var e=this;this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",function(){for(var t=function(t){var n=t>0?t:"";e["CONSUME"+n]=function(e,n){return this.consumeInternalRecord(e,t,n)},e["SUBRULE"+n]=function(e,n){return this.subruleInternalRecord(e,t,n)},e["OPTION"+n]=function(e){return this.optionInternalRecord(e,t)},e["OR"+n]=function(e){return this.orInternalRecord(e,t)},e["MANY"+n]=function(e){this.manyInternalRecord(t,e)},e["MANY_SEP"+n]=function(e){this.manySepFirstInternalRecord(t,e)},e["AT_LEAST_ONE"+n]=function(e){this.atLeastOneInternalRecord(t,e)},e["AT_LEAST_ONE_SEP"+n]=function(e){this.atLeastOneSepFirstInternalRecord(t,e)}},n=0;n<10;n++)t(n);e.consume=function(e,t,n){return this.consumeInternalRecord(t,e,n)},e.subrule=function(e,t,n){return this.subruleInternalRecord(t,e,n)},e.option=function(e,t){return this.optionInternalRecord(t,e)},e.or=function(e,t){return this.orInternalRecord(t,e)},e.many=function(e,t){this.manyInternalRecord(e,t)},e.atLeastOne=function(e,t){this.atLeastOneInternalRecord(e,t)},e.ACTION=e.ACTION_RECORD,e.BACKTRACK=e.BACKTRACK_RECORD,e.LA=e.LA_RECORD})},e.prototype.disableRecording=function(){var e=this;this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",function(){for(var t=0;t<10;t++){var n=t>0?t:"";delete e["CONSUME"+n],delete e["SUBRULE"+n],delete e["OPTION"+n],delete e["OR"+n],delete e["MANY"+n],delete e["MANY_SEP"+n],delete e["AT_LEAST_ONE"+n],delete e["AT_LEAST_ONE_SEP"+n]}delete e.consume,delete e.subrule,delete e.option,delete e.or,delete e.many,delete e.atLeastOne,delete e.ACTION,delete e.BACKTRACK,delete e.LA})},e.prototype.ACTION_RECORD=function(e){},e.prototype.BACKTRACK_RECORD=function(e,t){return function(){return!0}},e.prototype.LA_RECORD=function(e){return a.END_OF_FILE},e.prototype.topLevelRuleRecord=function(e,t){try{var r=new n.Rule({definition:[],name:e});return r.name=e,this.recordingProdStack.push(r),t.call(this),this.recordingProdStack.pop(),r}catch(e){if(!0!==e.KNOWN_RECORDER_ERROR)try{e.message=e.message+'\n\t This error was thrown during the "grammar recording phase" For more info see:\n\thttps://chevrotain.io/docs/guide/internals.html#grammar-recording'}catch(t){throw e}throw e}},e.prototype.optionInternalRecord=function(e,t){return m.call(this,n.Option,e,t)},e.prototype.atLeastOneInternalRecord=function(e,t){m.call(this,n.RepetitionMandatory,t,e)},e.prototype.atLeastOneSepFirstInternalRecord=function(e,t){m.call(this,n.RepetitionMandatoryWithSeparator,t,e,l)},e.prototype.manyInternalRecord=function(e,t){m.call(this,n.Repetition,t,e)},e.prototype.manySepFirstInternalRecord=function(e,t){m.call(this,n.RepetitionWithSeparator,t,e,l)},e.prototype.orInternalRecord=function(e,t){return g.call(this,e,t)},e.prototype.subruleInternalRecord=function(e,r,i){if(y(r),!e||!1===t.has(e,"ruleName")){var o=new Error("<SUBRULE"+b(r)+"> argument is invalid expecting a Parser method reference but got: <"+JSON.stringify(e)+">\n inside top level rule: <"+this.recordingProdStack[0].name+">");throw o.KNOWN_RECORDER_ERROR=!0,o}var a=t.peek(this.recordingProdStack),s=e.ruleName,l=new n.NonTerminal({idx:r,nonTerminalName:s,referencedRule:void 0});return a.definition.push(l),this.outputCst?p:c},e.prototype.consumeInternalRecord=function(e,r,o){if(y(r),!i.hasShortKeyProperty(e)){var a=new Error("<CONSUME"+b(r)+"> argument is invalid expecting a TokenType reference but got: <"+JSON.stringify(e)+">\n inside top level rule: <"+this.recordingProdStack[0].name+">");throw a.KNOWN_RECORDER_ERROR=!0,a}var s=t.peek(this.recordingProdStack),c=new n.Terminal({idx:r,terminalType:e});return s.definition.push(c),d},e}();function m(e,n,r,i){void 0===i&&(i=!1),y(r);var o=t.peek(this.recordingProdStack),a=t.isFunction(n)?n:n.DEF,s=new e({definition:[],idx:r});return i&&(s.separator=n.SEP),t.has(n,"MAX_LOOKAHEAD")&&(s.maxLookahead=n.MAX_LOOKAHEAD),this.recordingProdStack.push(s),a.call(this),o.definition.push(s),this.recordingProdStack.pop(),c}function g(e,r){var i=this;y(r);var o=t.peek(this.recordingProdStack),a=!1===t.isArray(e),s=!1===a?e:e.DEF,l=new n.Alternation({definition:[],idx:r,ignoreAmbiguities:a&&!0===e.IGNORE_AMBIGUITIES});t.has(e,"MAX_LOOKAHEAD")&&(l.maxLookahead=e.MAX_LOOKAHEAD);var u=t.some(s,function(e){return t.isFunction(e.GATE)});return l.hasPredicates=u,o.definition.push(l),t.forEach(s,function(e){var r=new n.Alternative({definition:[]});l.definition.push(r),t.has(e,"IGNORE_AMBIGUITIES")?r.ignoreAmbiguities=e.IGNORE_AMBIGUITIES:t.has(e,"GATE")&&(r.ignoreAmbiguities=!0),i.recordingProdStack.push(r),e.ALT.call(i),i.recordingProdStack.pop()}),c}function b(e){return 0===e?"":""+e}function y(e){if(e<0||e>u){var t=new Error("Invalid DSL Method idx value: <"+e+">\n\tIdx value must be a none negative value smaller than "+(u+1));throw t.KNOWN_RECORDER_ERROR=!0,t}}e.GastRecorder=f}),Dc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.PerformanceTracer=void 0;var t=ec(),n=Fc(),r=function(){function e(){}return e.prototype.initPerformanceTracer=function(e){if(t.has(e,"traceInitPerf")){var r=e.traceInitPerf,i="number"==typeof r;this.traceInitMaxIdent=i?r:1/0,this.traceInitPerf=i?r>0:r}else this.traceInitMaxIdent=0,this.traceInitPerf=n.DEFAULT_PARSER_CONFIG.traceInitPerf;this.traceInitIndent=-1},e.prototype.TRACE_INIT=function(e,n){if(!0===this.traceInitPerf){this.traceInitIndent++;var r=new Array(this.traceInitIndent+1).join("\t");this.traceInitIndent<this.traceInitMaxIdent&&console.log(r+"--\x3e <"+e+">");var i=t.timer(n),o=i.time,a=i.value,s=o>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&s(r+"<-- <"+e+"> time: "+o+"ms"),this.traceInitIndent--,a}return n()},e}();e.PerformanceTracer=r}),jc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.applyMixins=void 0,e.applyMixins=function(e,t){t.forEach(function(t){var n=t.prototype;Object.getOwnPropertyNames(n).forEach(function(r){if("constructor"!==r){var i=Object.getOwnPropertyDescriptor(n,r);i&&(i.get||i.set)?Object.defineProperty(e.prototype,r,i):e.prototype[r]=t.prototype[r]}})})}}),Fc=Zs(e=>{var t,n=e&&e.__extends||(t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)},function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.EmbeddedActionsParser=e.CstParser=e.Parser=e.EMPTY_ALT=e.ParserDefinitionErrorType=e.DEFAULT_RULE_CONFIG=e.DEFAULT_PARSER_CONFIG=e.END_OF_FILE=void 0;var r=ec(),i=mc(),o=cc(),a=gc(),s=wc(),c=Tc(),l=Cc(),u=Mc(),h=Rc(),d=Ic(),p=Pc(),f=_c(),m=Nc(),g=Lc(),b=Dc(),y=jc();e.END_OF_FILE=o.createTokenInstance(o.EOF,"",NaN,NaN,NaN,NaN,NaN,NaN),Object.freeze(e.END_OF_FILE),e.DEFAULT_PARSER_CONFIG=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:a.defaultParserErrorProvider,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),e.DEFAULT_RULE_CONFIG=Object.freeze({recoveryValueFunc:function(){},resyncEnabled:!0}),function(e){e[e.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",e[e.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",e[e.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",e[e.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",e[e.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",e[e.LEFT_RECURSION=5]="LEFT_RECURSION",e[e.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",e[e.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",e[e.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",e[e.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",e[e.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",e[e.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",e[e.TOO_MANY_ALTS=12]="TOO_MANY_ALTS"}(e.ParserDefinitionErrorType||(e.ParserDefinitionErrorType={})),e.EMPTY_ALT=function(e){return void 0===e&&(e=void 0),function(){return e}};var v=function(){function t(t,n){this.definitionErrors=[],this.selfAnalysisDone=!1;var i=this;if(i.initErrorHandler(n),i.initLexerAdapter(),i.initLooksAhead(n),i.initRecognizerEngine(t,n),i.initRecoverable(n),i.initTreeBuilder(n),i.initContentAssist(),i.initGastRecorder(n),i.initPerformanceTracer(n),r.has(n,"ignoredIssues"))throw new Error("The <ignoredIssues> IParserConfig property has been deprecated.\n\tPlease use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.\n\tSee: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES\n\tFor further details.");this.skipValidations=r.has(n,"skipValidations")?n.skipValidations:e.DEFAULT_PARSER_CONFIG.skipValidations}return t.performSelfAnalysis=function(e){throw Error("The **static** `performSelfAnalysis` method has been deprecated.\t\nUse the **instance** method with the same name instead.")},t.prototype.performSelfAnalysis=function(){var e=this;this.TRACE_INIT("performSelfAnalysis",function(){var n;e.selfAnalysisDone=!0;var o=e.className;e.TRACE_INIT("toFastProps",function(){r.toFastProperties(e)}),e.TRACE_INIT("Grammar Recording",function(){try{e.enableRecording(),r.forEach(e.definedRulesNames,function(t){var n=e[t].originalGrammarAction,r=void 0;e.TRACE_INIT(t+" Rule",function(){r=e.topLevelRuleRecord(t,n)}),e.gastProductionsCache[t]=r})}finally{e.disableRecording()}});var c=[];if(e.TRACE_INIT("Grammar Resolving",function(){c=s.resolveGrammar({rules:r.values(e.gastProductionsCache)}),e.definitionErrors=e.definitionErrors.concat(c)}),e.TRACE_INIT("Grammar Validations",function(){if(r.isEmpty(c)&&!1===e.skipValidations){var t=s.validateGrammar({rules:r.values(e.gastProductionsCache),maxLookahead:e.maxLookahead,tokenTypes:r.values(e.tokensMap),errMsgProvider:a.defaultGrammarValidatorErrorProvider,grammarName:o});e.definitionErrors=e.definitionErrors.concat(t)}}),r.isEmpty(e.definitionErrors)&&(e.recoveryEnabled&&e.TRACE_INIT("computeAllProdsFollows",function(){var t=i.computeAllProdsFollows(r.values(e.gastProductionsCache));e.resyncFollows=t}),e.TRACE_INIT("ComputeLookaheadFunctions",function(){e.preComputeLookaheadFunctions(r.values(e.gastProductionsCache))})),!t.DEFER_DEFINITION_ERRORS_HANDLING&&!r.isEmpty(e.definitionErrors))throw n=r.map(e.definitionErrors,function(e){return e.message}),new Error("Parser Definition Errors detected:\n "+n.join("\n-------------------------------\n"))})},t.DEFER_DEFINITION_ERRORS_HANDLING=!1,t}();e.Parser=v,y.applyMixins(v,[c.Recoverable,l.LooksAhead,u.TreeBuilder,h.LexerAdapter,p.RecognizerEngine,d.RecognizerApi,f.ErrorHandler,m.ContentAssist,g.GastRecorder,b.PerformanceTracer]);var x=function(t){function i(n,i){void 0===i&&(i=e.DEFAULT_PARSER_CONFIG);var o=r.cloneObj(i);return o.outputCst=!0,t.call(this,n,o)||this}return n(i,t),i}(v);e.CstParser=x;var w=function(t){function i(n,i){void 0===i&&(i=e.DEFAULT_PARSER_CONFIG);var o=r.cloneObj(i);return o.outputCst=!1,t.call(this,n,o)||this}return n(i,t),i}(v);e.EmbeddedActionsParser=w}),Uc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createSyntaxDiagramsCode=void 0;var t=Js();e.createSyntaxDiagramsCode=function(e,n){var r=void 0===n?{}:n,i=r.resourceBase,o=void 0===i?"https://unpkg.com/chevrotain@"+t.VERSION+"/diagrams/":i,a=r.css;return'\n\x3c!-- This is a generated file --\x3e\n<!DOCTYPE html>\n<meta charset="utf-8">\n<style>\n body {\n background-color: hsl(30, 20%, 95%)\n }\n</style>\n\n'+("\n<link rel='stylesheet' href='"+(void 0===a?"https://unpkg.com/chevrotain@"+t.VERSION+"/diagrams/diagrams.css":a)+"'>\n")+("\n<script src='"+o+"vendor/railroad-diagrams.js'><\/script>\n<script src='"+o+"src/diagrams_builder.js'><\/script>\n<script src='"+o+"src/diagrams_behavior.js'><\/script>\n<script src='"+o+"src/main.js'><\/script>\n")+'\n<div id="diagrams" align="center"></div>\n'+("\n<script>\n window.serializedGrammar = "+JSON.stringify(e,null," ")+";\n<\/script>\n")+'\n<script>\n var diagramsDiv = document.getElementById("diagrams");\n main.drawDiagramsFromSerializedGrammar(serializedGrammar, diagramsDiv);\n<\/script>\n'}}),Bc=Zs(e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Parser=e.createSyntaxDiagramsCode=e.clearCache=e.GAstVisitor=e.serializeProduction=e.serializeGrammar=e.Terminal=e.Rule=e.RepetitionWithSeparator=e.RepetitionMandatoryWithSeparator=e.RepetitionMandatory=e.Repetition=e.Option=e.NonTerminal=e.Alternative=e.Alternation=e.defaultLexerErrorProvider=e.NoViableAltException=e.NotAllInputParsedException=e.MismatchedTokenException=e.isRecognitionException=e.EarlyExitException=e.defaultParserErrorProvider=e.tokenName=e.tokenMatcher=e.tokenLabel=e.EOF=e.createTokenInstance=e.createToken=e.LexerDefinitionErrorType=e.Lexer=e.EMPTY_ALT=e.ParserDefinitionErrorType=e.EmbeddedActionsParser=e.CstParser=e.VERSION=void 0;var t=Js();Object.defineProperty(e,"VERSION",{enumerable:!0,get:function(){return t.VERSION}});var n=Fc();Object.defineProperty(e,"CstParser",{enumerable:!0,get:function(){return n.CstParser}}),Object.defineProperty(e,"EmbeddedActionsParser",{enumerable:!0,get:function(){return n.EmbeddedActionsParser}}),Object.defineProperty(e,"ParserDefinitionErrorType",{enumerable:!0,get:function(){return n.ParserDefinitionErrorType}}),Object.defineProperty(e,"EMPTY_ALT",{enumerable:!0,get:function(){return n.EMPTY_ALT}});var r=sc();Object.defineProperty(e,"Lexer",{enumerable:!0,get:function(){return r.Lexer}}),Object.defineProperty(e,"LexerDefinitionErrorType",{enumerable:!0,get:function(){return r.LexerDefinitionErrorType}});var i=cc();Object.defineProperty(e,"createToken",{enumerable:!0,get:function(){return i.createToken}}),Object.defineProperty(e,"createTokenInstance",{enumerable:!0,get:function(){return i.createTokenInstance}}),Object.defineProperty(e,"EOF",{enumerable:!0,get:function(){return i.EOF}}),Object.defineProperty(e,"tokenLabel",{enumerable:!0,get:function(){return i.tokenLabel}}),Object.defineProperty(e,"tokenMatcher",{enumerable:!0,get:function(){return i.tokenMatcher}}),Object.defineProperty(e,"tokenName",{enumerable:!0,get:function(){return i.tokenName}});var o=gc();Object.defineProperty(e,"defaultParserErrorProvider",{enumerable:!0,get:function(){return o.defaultParserErrorProvider}});var a=Ec();Object.defineProperty(e,"EarlyExitException",{enumerable:!0,get:function(){return a.EarlyExitException}}),Object.defineProperty(e,"isRecognitionException",{enumerable:!0,get:function(){return a.isRecognitionException}}),Object.defineProperty(e,"MismatchedTokenException",{enumerable:!0,get:function(){return a.MismatchedTokenException}}),Object.defineProperty(e,"NotAllInputParsedException",{enumerable:!0,get:function(){return a.NotAllInputParsedException}}),Object.defineProperty(e,"NoViableAltException",{enumerable:!0,get:function(){return a.NoViableAltException}});var s=ac();Object.defineProperty(e,"defaultLexerErrorProvider",{enumerable:!0,get:function(){return s.defaultLexerErrorProvider}});var c=lc();Object.defineProperty(e,"Alternation",{enumerable:!0,get:function(){return c.Alternation}}),Object.defineProperty(e,"Alternative",{enumerable:!0,get:function(){return c.Alternative}}),Object.defineProperty(e,"NonTerminal",{enumerable:!0,get:function(){return c.NonTerminal}}),Object.defineProperty(e,"Option",{enumerable:!0,get:function(){return c.Option}}),Object.defineProperty(e,"Repetition",{enumerable:!0,get:function(){return c.Repetition}}),Object.defineProperty(e,"RepetitionMandatory",{enumerable:!0,get:function(){return c.RepetitionMandatory}}),Object.defineProperty(e,"RepetitionMandatoryWithSeparator",{enumerable:!0,get:function(){return c.RepetitionMandatoryWithSeparator}}),Object.defineProperty(e,"RepetitionWithSeparator",{enumerable:!0,get:function(){return c.RepetitionWithSeparator}}),Object.defineProperty(e,"Rule",{enumerable:!0,get:function(){return c.Rule}}),Object.defineProperty(e,"Terminal",{enumerable:!0,get:function(){return c.Terminal}});var l=lc();Object.defineProperty(e,"serializeGrammar",{enumerable:!0,get:function(){return l.serializeGrammar}}),Object.defineProperty(e,"serializeProduction",{enumerable:!0,get:function(){return l.serializeProduction}});var u=hc();Object.defineProperty(e,"GAstVisitor",{enumerable:!0,get:function(){return u.GAstVisitor}}),e.clearCache=function(){console.warn("The clearCache function was 'soft' removed from the Chevrotain API.\n\t It performs no action other than printing this message.\n\t Please avoid using it as it will be completely removed in the future")};var h=Uc();Object.defineProperty(e,"createSyntaxDiagramsCode",{enumerable:!0,get:function(){return h.createSyntaxDiagramsCode}});var d=function(){throw new Error("The Parser class has been deprecated, use CstParser or EmbeddedActionsParser instead.\nSee: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_7-0-0")};e.Parser=d})();class zc extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=""===i.path?J.extractUrlBase(e):i.path,a=new q(i.manager);a.setPath(i.path),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials),a.load(e,function(n){try{t(i.parse(n,o))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e,t){const n={};function r(e){e.DEF&&(n[e.DEF]=e);const t=e.fields;for(let e=0,n=t.length;e<n;e++){const n=t[e];if("node"===n.type){const e=n.values;for(let t=0,n=e.length;t<n;t++)r(e[t])}}}function i(e){return e.USE?function(e){const t=n[e],r=i(t);return r.isObject3D||r.isMaterial?r.clone():r}(e.USE):(void 0!==e.build||(e.build=function(e){const t=e.name;let n;switch(t){case"Anchor":case"Group":case"Transform":case"Collision":n=function(e){const t=new Oe,n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;switch(i){case"bboxCenter":case"bboxSize":case"center":case"description":case"collide":case"parameter":case"scaleOrientation":case"proxy":case"url":break;case"children":s(o,t);break;case"rotation":const e=new f(o[0],o[1],o[2]),n=o[3];t.quaternion.setFromAxisAngle(e,n);break;case"scale":t.scale.set(o[0],o[1],o[2]);break;case"translation":t.position.set(o[0],o[1],o[2]);break;default:console.warn("THREE.VRMLLoader: Unknown field:",i)}}return t}(e);break;case"Background":n=function(e){const t=new Oe;let n,r,i,o;const a=e.fields;for(let e=0,t=a.length;e<t;e++){const t=a[e],s=t.name,c=t.values;switch(s){case"groundAngle":n=c;break;case"groundColor":r=c;break;case"backUrl":case"bottomUrl":case"frontUrl":case"leftUrl":case"rightUrl":case"topUrl":break;case"skyAngle":i=c;break;case"skyColor":o=c;break;default:console.warn("THREE.VRMLLoader: Unknown field:",s)}}const s=1e4;if(o){const e=new P(s,32,16),n=new E({fog:!1,side:H,depthWrite:!1,depthTest:!1});o.length>3?(W(e,s,i,z(o),!0),n.vertexColors=!0):(n.color.setRGB(o[0],o[1],o[2]),n.color.convertSRGBToLinear());const r=new S(e,n);t.add(r)}if(r&&r.length>0){const e=new P(s,32,16,0,2*Math.PI,.5*Math.PI,1.5*Math.PI),i=new E({fog:!1,side:H,vertexColors:!0,depthWrite:!1,depthTest:!1});W(e,s,n,z(r),!1);const o=new S(e,i);t.add(o)}return t.renderOrder=-1/0,t}(e);break;case"Shape":n=function(e){const t=e.fields;let n,r,o=new E({name:X.DEFAULT_MATERIAL_NAME,color:0});for(let e=0,r=t.length;e<r;e++){const r=t[e],a=r.name,s=r.values;switch(a){case"appearance":null!==s[0]&&(o=i(s[0]));break;case"geometry":null!==s[0]&&(n=i(s[0]));break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}if(n&&n.attributes.position){const e=n._type;if("points"===e){const e=new ye({name:X.DEFAULT_MATERIAL_NAME,color:16777215,opacity:o.opacity,transparent:o.transparent});void 0!==n.attributes.color?e.vertexColors=!0:o.isMeshPhongMaterial&&e.color.copy(o.emissive),r=new Ce(n,e)}else if("line"===e){const e=new T({name:X.DEFAULT_MATERIAL_NAME,color:16777215,opacity:o.opacity,transparent:o.transparent});void 0!==n.attributes.color?e.vertexColors=!0:o.isMeshPhongMaterial&&e.color.copy(o.emissive),r=new Te(n,e)}else void 0!==n._solid&&(o.side=n._solid?G:D),void 0!==n.attributes.color&&(o.vertexColors=!0),r=new S(n,o)}else r=new x,r.visible=!1;return r}(e);break;case"Appearance":n=function(e){let t,n=new Be;const r=e.fields;for(let e=0,o=r.length;e<o;e++){const o=r[e],a=o.name,s=o.values;switch(a){case"material":if(null!==s[0]){const e=i(s[0]);e.diffuseColor&&n.color.copy(e.diffuseColor),e.emissiveColor&&n.emissive.copy(e.emissiveColor),e.shininess&&(n.shininess=e.shininess),e.specularColor&&n.specular.copy(e.specularColor),e.transparency&&(n.opacity=1-e.transparency),e.transparency>0&&(n.transparent=!0)}else n=new E({name:X.DEFAULT_MATERIAL_NAME,color:0});break;case"texture":const e=s[0];null!==e&&("ImageTexture"!==e.name&&"PixelTexture"!==e.name||(n.map=i(e)));break;case"textureTransform":null!==s[0]&&(t=i(s[0]));break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}if(n.map){if(n.map.__type){switch(n.map.__type){case Xc.INTENSITY_ALPHA:n.opacity=1;break;case Xc.RGB:n.color.set(16777215);break;case Xc.RGBA:n.color.set(16777215),n.opacity=1}delete n.map.__type}t&&(n.map.center.copy(t.center),n.map.rotation=t.rotation,n.map.repeat.copy(t.scale),n.map.offset.copy(t.translation))}return n}(e);break;case"Material":n=function(e){const t={},n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;switch(i){case"ambientIntensity":break;case"diffuseColor":t.diffuseColor=new K(o[0],o[1],o[2]),t.diffuseColor.convertSRGBToLinear();break;case"emissiveColor":t.emissiveColor=new K(o[0],o[1],o[2]),t.emissiveColor.convertSRGBToLinear();break;case"shininess":t.shininess=o[0];break;case"specularColor":t.specularColor=new K(o[0],o[1],o[2]),t.specularColor.convertSRGBToLinear();break;case"transparency":t.transparency=o[0];break;default:console.warn("THREE.VRMLLoader: Unknown field:",i)}}return t}(e);break;case"ImageTexture":n=function(e){let t,n=me,r=me;const i=e.fields;for(let e=0,o=i.length;e<o;e++){const o=i[e],a=o.name,s=o.values;switch(a){case"url":const e=s[0];e&&(t=q.load(e));break;case"repeatS":!1===s[0]&&(n=be);break;case"repeatT":!1===s[0]&&(r=be);break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}t&&(t.wrapS=n,t.wrapT=r,t.colorSpace=Y);return t}(e);break;case"PixelTexture":n=function(e){let t,n=me,r=me;const i=e.fields;for(let e=0,s=i.length;e<s;e++){const s=i[e],c=s.name,l=s.values;switch(c){case"image":const e=l[0],i=l[1],s=a(l[2]),u=new Uint8Array(4*e*i),h={r:0,g:0,b:0,a:0};for(let e=3,t=0,n=l.length;e<n;e++,t++){o(l[e],s,h);const n=4*t;u[n+0]=h.r,u[n+1]=h.g,u[n+2]=h.b,u[n+3]=h.a}t=new nt(u,e,i),t.colorSpace=Y,t.needsUpdate=!0,t.__type=s;break;case"repeatS":!1===l[0]&&(n=be);break;case"repeatT":!1===l[0]&&(r=be);break;default:console.warn("THREE.VRMLLoader: Unknown field:",c)}}t&&(t.wrapS=n,t.wrapT=r);return t}(e);break;case"TextureTransform":n=function(e){const t={center:new v,rotation:new v,scale:new v,translation:new v},n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;switch(i){case"center":t.center.set(o[0],o[1]);break;case"rotation":t.rotation=o[0];break;case"scale":t.scale.set(o[0],o[1]);break;case"translation":t.translation.set(o[0],o[1]);break;default:console.warn("THREE.VRMLLoader: Unknown field:",i)}}return t}(e);break;case"IndexedFaceSet":n=function(e){let t,n,r,o,a,s,h,d,p=!0,f=!0,m=0,g=!0,b=!0;const y=e.fields;for(let e=0,c=y.length;e<c;e++){const c=y[e],l=c.name,u=c.values;switch(l){case"color":const e=u[0];null!==e&&(t=i(e));break;case"coord":const c=u[0];null!==c&&(n=i(c));break;case"normal":const y=u[0];null!==y&&(r=i(y));break;case"texCoord":const v=u[0];null!==v&&(o=i(v));break;case"ccw":p=u[0];break;case"colorIndex":a=u;break;case"colorPerVertex":g=u[0];break;case"convex":break;case"coordIndex":s=u;break;case"creaseAngle":m=u[0];break;case"normalIndex":h=u;break;case"normalPerVertex":b=u[0];break;case"solid":f=u[0];break;case"texCoordIndex":d=u;break;default:console.warn("THREE.VRMLLoader: Unknown field:",l)}}if(void 0===s)return console.warn("THREE.VRMLLoader: Missing coordIndex."),new O;const v=c(s,p);let x,w,E;if(t){if(!0===g)if(a&&a.length>0){x=R(v,c(a,p),t,3)}else x=N(v,new k(t,3));else if(a&&a.length>0){x=I(v,l(u(t,a),s))}else{x=I(v,l(t,s))}V(x)}if(r)if(!0===b)if(h&&h.length>0){w=R(v,c(h,p),r,3)}else w=N(v,new k(r,3));else if(h&&h.length>0){w=I(v,l(u(r,h),s))}else{w=I(v,l(r,s))}else w=U(v,n,m);if(o)if(d&&d.length>0){E=R(v,c(d,p),o,2)}else E=N(v,new k(o,2));const T=new O,A=N(v,new k(n,3));T.setAttribute("position",A),T.setAttribute("normal",w),x&&T.setAttribute("color",x);E&&T.setAttribute("uv",E);return T._solid=f,T._type="mesh",T}(e);break;case"IndexedLineSet":n=function(e){let t,n,r,o,a=!0;const s=e.fields;for(let e=0,c=s.length;e<c;e++){const c=s[e],l=c.name,u=c.values;switch(l){case"color":const e=u[0];null!==e&&(t=i(e));break;case"coord":const s=u[0];null!==s&&(n=i(s));break;case"colorIndex":r=u;break;case"colorPerVertex":a=u[0];break;case"coordIndex":o=u;break;default:console.warn("THREE.VRMLLoader: Unknown field:",l)}}let c;const l=h(o);if(t){if(!0===a)if(r.length>0){c=R(l,h(r),t,3)}else c=N(l,new k(t,3));else if(r.length>0){c=_(l,d(u(t,r),o))}else{c=_(l,d(t,o))}V(c)}const p=new O,f=N(l,new k(n,3));p.setAttribute("position",f),c&&p.setAttribute("color",c);return p._type="line",p}(e);break;case"PointSet":n=function(e){let t,n;const r=e.fields;for(let e=0,o=r.length;e<o;e++){const o=r[e],a=o.name,s=o.values;switch(a){case"color":const e=s[0];null!==e&&(t=i(e));break;case"coord":const r=s[0];null!==r&&(n=i(r));break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}const o=new O;if(o.setAttribute("position",new k(n,3)),t){const e=new k(t,3);V(e),o.setAttribute("color",e)}return o._type="points",o}(e);break;case"Box":n=function(e){const t=new f(2,2,2),n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;if("size"===i)t.x=o[0],t.y=o[1],t.z=o[2];else console.warn("THREE.VRMLLoader: Unknown field:",i)}return new C(t.x,t.y,t.z)}(e);break;case"Cone":n=function(e){let t=1,n=2,r=!1;const i=e.fields;for(let e=0,o=i.length;e<o;e++){const o=i[e],a=o.name,s=o.values;switch(a){case"bottom":r=!s[0];break;case"bottomRadius":t=s[0];break;case"height":n=s[0];break;case"side":break;default:console.warn("THREE.VRMLLoader: Unknown field:",a)}}return new rt(t,n,16,1,r)}(e);break;case"Cylinder":n=function(e){let t=1,n=2;const r=e.fields;for(let e=0,i=r.length;e<i;e++){const i=r[e],o=i.name,a=i.values;switch(o){case"bottom":case"side":case"top":break;case"radius":t=a[0];break;case"height":n=a[0];break;default:console.warn("THREE.VRMLLoader: Unknown field:",o)}}return new A(t,t,n,16,1)}(e);break;case"Sphere":n=function(e){let t=1;const n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;if("radius"===i)t=o[0];else console.warn("THREE.VRMLLoader: Unknown field:",i)}return new P(t,16,16)}(e);break;case"ElevationGrid":n=function(e){let t,n,r,o,a=!0,s=!0,c=!0,l=!0,u=0,h=2,d=2,p=1,f=1;const m=e.fields;for(let e=0,g=m.length;e<g;e++){const g=m[e],b=g.name,y=g.values;switch(b){case"color":const e=y[0];null!==e&&(t=i(e));break;case"normal":const m=y[0];null!==m&&(n=i(m));break;case"texCoord":const g=y[0];null!==g&&(r=i(g));break;case"height":o=y;break;case"ccw":l=y[0];break;case"colorPerVertex":a=y[0];break;case"creaseAngle":u=y[0];break;case"normalPerVertex":s=y[0];break;case"solid":c=y[0];break;case"xDimension":h=y[0];break;case"xSpacing":p=y[0];break;case"zDimension":d=y[0];break;case"zSpacing":f=y[0];break;default:console.warn("THREE.VRMLLoader: Unknown field:",b)}}const g=[],b=[],y=[],v=[];for(let e=0;e<d;e++)for(let i=0;i<h;i++){const c=e*h+i,l=p*e,u=o[c],m=f*i;if(g.push(l,u,m),t&&!0===a){const e=t[3*c+0],n=t[3*c+1],r=t[3*c+2];y.push(e,n,r)}if(n&&!0===s){const e=n[3*c+0],t=n[3*c+1],r=n[3*c+2];b.push(e,t,r)}if(r){const e=r[2*c+0],t=r[2*c+1];v.push(e,t)}else v.push(e/(h-1),i/(d-1))}const x=[];for(let e=0;e<h-1;e++)for(let t=0;t<d-1;t++){const n=e+t*h,r=e+(t+1)*h,i=e+1+(t+1)*h,o=e+1+t*h;!0===l?(x.push(n,i,r),x.push(i,n,o)):(x.push(n,r,i),x.push(i,o,n))}const w=N(x,new k(g,3)),E=N(x,new k(v,2));let T,A;if(t){if(!1===a){for(let e=0;e<h-1;e++)for(let n=0;n<d-1;n++){const r=e+n*(h-1),i=t[3*r+0],o=t[3*r+1],a=t[3*r+2];y.push(i,o,a),y.push(i,o,a),y.push(i,o,a),y.push(i,o,a),y.push(i,o,a),y.push(i,o,a)}T=new k(y,3)}else T=N(x,new k(y,3));V(T)}if(n)if(!1===s){for(let e=0;e<h-1;e++)for(let t=0;t<d-1;t++){const r=e+t*(h-1),i=n[3*r+0],o=n[3*r+1],a=n[3*r+2];b.push(i,o,a),b.push(i,o,a),b.push(i,o,a),b.push(i,o,a),b.push(i,o,a),b.push(i,o,a)}A=new k(b,3)}else A=N(x,new k(b,3));else A=U(x,g,u);const C=new O;C.setAttribute("position",w),C.setAttribute("normal",A),C.setAttribute("uv",E),T&&C.setAttribute("color",T);return C._solid=c,C._type="mesh",C}(e);break;case"Extrusion":n=function(e){let t,n,r=[1,1,1,-1,-1,-1,-1,1,1,1],i=[0,0,0,0,1,0],o=!0,a=!0,s=0,c=!0,l=!0;const u=e.fields;for(let e=0,h=u.length;e<h;e++){const h=u[e],d=h.name,p=h.values;switch(d){case"beginCap":o=p[0];break;case"ccw":a=p[0];break;case"convex":break;case"creaseAngle":s=p[0];break;case"crossSection":r=p;break;case"endCap":c=p[0];break;case"orientation":n=p;break;case"scale":t=p;break;case"solid":l=p[0];break;case"spine":i=p;break;default:console.warn("THREE.VRMLLoader: Unknown field:",d)}}const h=r[0]===r[r.length-2]&&r[1]===r[r.length-1],d=[],p=new f,m=new f,g=new f,b=new f,x=new y;for(let e=0,o=0,a=0,s=i.length;e<s;e+=3,o+=2,a+=4){p.fromArray(i,e),m.x=t?t[o+0]:1,m.y=1,m.z=t?t[o+1]:1,g.x=n?n[a+0]:0,g.y=n?n[a+1]:0,g.z=n?n[a+2]:1;const s=n?n[a+3]:0;for(let e=0,t=r.length;e<t;e+=2)b.x=r[e+0],b.y=0,b.z=r[e+1],b.multiply(m),x.setFromAxisAngle(g,s),b.applyQuaternion(x),b.add(p),d.push(b.x,b.y,b.z)}const w=[],E=i.length/3,T=r.length/2;for(let e=0;e<E-1;e++)for(let t=0;t<T-1;t++){const n=t+e*T;let r=t+1+e*T;const i=t+(e+1)*T;let o=t+1+(e+1)*T;t===T-2&&!0===h&&(r=e*T,o=(e+1)*T),!0===a?(w.push(n,r,i),w.push(i,r,o)):(w.push(n,i,r),w.push(i,o,r))}if(!0===o||!0===c){const e=[];for(let t=0,n=r.length;t<n;t+=2)e.push(new v(r[t],r[t+1]));const t=Ke.triangulateShape(e,[]),n=[];for(let e=0,r=t.length;e<r;e++){const r=t[e];n.push(r[0],r[1],r[2])}if(!0===o)for(let e=0,t=n.length;e<t;e+=3)!0===a?w.push(n[e+0],n[e+1],n[e+2]):w.push(n[e+0],n[e+2],n[e+1]);if(!0===c){const e=T*(E-1);for(let t=0,r=n.length;t<r;t+=3)!0===a?w.push(e+n[t+0],e+n[t+2],e+n[t+1]):w.push(e+n[t+0],e+n[t+1],e+n[t+2])}}const A=N(w,new k(d,3)),C=U(w,d,s),S=new O;return S.setAttribute("position",A),S.setAttribute("normal",C),S._solid=l,S._type="mesh",S}(e);break;case"Color":case"Coordinate":case"Normal":case"TextureCoordinate":n=function(e){return e.fields[0].values}(e);break;case"WorldInfo":n=function(e){const t={},n=e.fields;for(let e=0,r=n.length;e<r;e++){const r=n[e],i=r.name,o=r.values;switch(i){case"title":t.title=o[0];break;case"info":t.info=o;break;default:console.warn("THREE.VRMLLoader: Unknown field:",i)}}return t}(e);break;case"Billboard":case"Inline":case"LOD":case"Switch":case"AudioClip":case"DirectionalLight":case"PointLight":case"Script":case"Sound":case"SpotLight":case"CylinderSensor":case"PlaneSensor":case"ProximitySensor":case"SphereSensor":case"TimeSensor":case"TouchSensor":case"VisibilitySensor":case"Text":case"FontStyle":case"MovieTexture":case"ColorInterpolator":case"CoordinateInterpolator":case"NormalInterpolator":case"OrientationInterpolator":case"PositionInterpolator":case"ScalarInterpolator":case"Fog":case"NavigationInfo":case"Viewpoint":break;default:console.warn("THREE.VRMLLoader: Unknown node:",t)}void 0!==n&&void 0!==e.DEF&&!0===n.hasOwnProperty("name")&&(n.name=e.DEF);return n}(e)),e.build)}function o(e,t,n){let r;switch(t){case Xc.INTENSITY:r=parseInt(e),n.r=r,n.g=r,n.b=r,n.a=1;break;case Xc.INTENSITY_ALPHA:r=parseInt("0x"+e.substring(2,4)),n.r=r,n.g=r,n.b=r,n.a=parseInt("0x"+e.substring(4,6));break;case Xc.RGB:n.r=parseInt("0x"+e.substring(2,4)),n.g=parseInt("0x"+e.substring(4,6)),n.b=parseInt("0x"+e.substring(6,8)),n.a=1;break;case Xc.RGBA:n.r=parseInt("0x"+e.substring(2,4)),n.g=parseInt("0x"+e.substring(4,6)),n.b=parseInt("0x"+e.substring(6,8)),n.a=parseInt("0x"+e.substring(8,10))}}function a(e){let t;switch(e){case 1:t=Xc.INTENSITY;break;case 2:t=Xc.INTENSITY_ALPHA;break;case 3:t=Xc.RGB;break;case 4:t=Xc.RGBA}return t}function s(e,t){for(let n=0,r=e.length;n<r;n++){const r=i(e[n]);r instanceof x&&t.add(r)}}function c(e,t){const n=[];let r=0;for(let i=0,o=e.length;i<o;i++){const a=e[r],s=e[i+(t?1:2)],c=e[i+(t?2:1)];n.push(a,s,c),(-1===e[i+3]||i+3>=o)&&(i+=3,r=i+1)}return n}function l(e,t){const n=[];let r=0;for(let i=0,o=t.length;i<o;i++){const a=3*r,s=e[a],c=e[a+1],l=e[a+2];n.push(s,c,l),(-1===t[i+3]||i+3>=o)&&(i+=3,r++)}return n}function u(e,t){const n=[];for(let r=0,i=t.length;r<i;r++){const i=3*t[r],o=e[i],a=e[i+1],s=e[i+2];n.push(o,a,s)}return n}function h(e){const t=[];for(let n=0,r=e.length;n<r;n++){const i=e[n],o=e[n+1];t.push(i,o),(-1===e[n+2]||n+2>=r)&&(n+=2)}return t}function d(e,t){const n=[];let r=0;for(let i=0,o=t.length;i<o;i++){const a=3*r,s=e[a],c=e[a+1],l=e[a+2];n.push(s,c,l),(-1===t[i+2]||i+2>=o)&&(i+=2,r++)}return n}const p=new f,m=new f,g=new f,b=new v,w=new v,M=new v;function R(e,t,n,r){const i=[];for(let o=0,a=e.length;o<a;o+=3){const e=t[o],a=t[o+1],s=t[o+2];2===r?(b.fromArray(n,e*r),w.fromArray(n,a*r),M.fromArray(n,s*r),i.push(b.x,b.y),i.push(w.x,w.y),i.push(M.x,M.y)):(p.fromArray(n,e*r),m.fromArray(n,a*r),g.fromArray(n,s*r),i.push(p.x,p.y,p.z),i.push(m.x,m.y,m.z),i.push(g.x,g.y,g.z))}return new k(i,r)}function I(e,t){const n=[];for(let r=0,i=0,o=e.length;r<o;r+=3,i++)p.fromArray(t,3*i),n.push(p.x,p.y,p.z),n.push(p.x,p.y,p.z),n.push(p.x,p.y,p.z);return new k(n,3)}function _(e,t){const n=[];for(let r=0,i=0,o=e.length;r<o;r+=2,i++)p.fromArray(t,3*i),n.push(p.x,p.y,p.z),n.push(p.x,p.y,p.z);return new k(n,3)}function N(e,t){const n=t.array,r=t.itemSize,i=new n.constructor(e.length*r);let o=0,a=0;for(let t=0,s=e.length;t<s;t++){o=e[t]*r;for(let e=0;e<r;e++)i[a++]=n[o++]}return new k(i,r)}const L=new f,F=new f;function U(e,t,n){const r=[],i={};for(let n=0,o=e.length;n<o;n+=3){const o=e[n],a=e[n+1],s=e[n+2],c=new Wc(o,a,s);p.fromArray(t,3*o),m.fromArray(t,3*a),g.fromArray(t,3*s),F.subVectors(g,m),L.subVectors(p,m),F.cross(L),F.normalize(),c.normal.copy(F),void 0===i[o]&&(i[o]=[]),void 0===i[a]&&(i[a]=[]),void 0===i[s]&&(i[s]=[]),i[o].push(c.normal),i[a].push(c.normal),i[s].push(c.normal),r.push(c)}const o=[];for(let e=0,a=r.length;e<a;e++){const a=r[e],s=B(i[a.a],a.normal,n),c=B(i[a.b],a.normal,n),l=B(i[a.c],a.normal,n);p.fromArray(t,3*a.a),m.fromArray(t,3*a.b),g.fromArray(t,3*a.c),o.push(s.x,s.y,s.z),o.push(c.x,c.y,c.z),o.push(l.x,l.y,l.z)}return new k(o,3)}function B(e,t,n){const r=new f;if(0===n)r.copy(t);else for(let i=0,o=e.length;i<o;i++)e[i].angleTo(t)<n&&r.add(e[i]);return r.normalize()}function z(e){const t=[];for(let n=0,r=e.length;n<r;n+=3)t.push(new K(e[n],e[n+1],e[n+2]));return t}function V(e){const t=new K;for(let n=0;n<e.count;n++)t.fromBufferAttribute(e,n),t.convertSRGBToLinear(),e.setXYZ(n,t.r,t.g,t.b)}function W(e,t,n,r,i){const o=[],a=!0===i?0:Math.PI;for(let e=0,s=r.length;e<s;e++){let r=0===e?0:n[e-1];r=!0===i?r:a-r;const s=new f;s.setFromSphericalCoords(t,r,0),o.push(s)}const s=e.index,c=e.attributes.position,l=new j(new Float32Array(3*e.attributes.position.count),3),u=new f,h=new K;for(let e=0;e<s.count;e++){const t=s.getX(e);let n,a;u.fromBufferAttribute(c,t);let d=1;for(let e=1;e<o.length;e++){n=e-1,a=e;const t=o[n],r=o[a];if(!0===i){if(u.y<=t.y&&u.y>r.y){d=Math.abs(t.y-u.y)/Math.abs(t.y-r.y);break}}else if(u.y>=t.y&&u.y<r.y){d=Math.abs(t.y-u.y)/Math.abs(t.y-r.y);break}}const p=r[n],f=r[a];h.copy(p).lerp(f,d).convertSRGBToLinear(),l.setXYZ(t,h.r,h.g,h.b)}e.setAttribute("color",l)}const q=new ae(this.manager);if(q.setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin),-1===e.indexOf("#VRML V2.0"))throw Error("THREE.VRMLLexer: Version of VRML asset not supported.");const Q=function(e){const t=function(){const e=Bc.createToken,t=e({name:"RouteIdentifier",pattern:/[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*[\.][^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/}),n=e({name:"Identifier",pattern:/[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]([^\0-\x20\x22\x27\x23\x2b\x2c\x2e\x5b\x5d\x5c\x7b\x7d])*/,longer_alt:t}),r=["Anchor","Billboard","Collision","Group","Transform","Inline","LOD","Switch","AudioClip","DirectionalLight","PointLight","Script","Shape","Sound","SpotLight","WorldInfo","CylinderSensor","PlaneSensor","ProximitySensor","SphereSensor","TimeSensor","TouchSensor","VisibilitySensor","Box","Cone","Cylinder","ElevationGrid","Extrusion","IndexedFaceSet","IndexedLineSet","PointSet","Sphere","Color","Coordinate","Normal","TextureCoordinate","Appearance","FontStyle","ImageTexture","Material","MovieTexture","PixelTexture","TextureTransform","ColorInterpolator","CoordinateInterpolator","NormalInterpolator","OrientationInterpolator","PositionInterpolator","ScalarInterpolator","Background","Fog","NavigationInfo","Viewpoint","Text"],i=e({name:"Version",pattern:/#VRML.*/,longer_alt:n}),o=e({name:"NodeName",pattern:new RegExp(r.join("|")),longer_alt:n}),a=e({name:"DEF",pattern:/DEF/,longer_alt:n}),s=e({name:"USE",pattern:/USE/,longer_alt:n}),c=e({name:"ROUTE",pattern:/ROUTE/,longer_alt:n}),l=e({name:"TO",pattern:/TO/,longer_alt:n}),u=e({name:"StringLiteral",pattern:/"(?:[^\\"\n\r]|\\[bfnrtv"\\/]|\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])*"/}),h=e({name:"HexLiteral",pattern:/0[xX][0-9a-fA-F]+/}),d=e({name:"NumberLiteral",pattern:/[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/}),p=e({name:"TrueLiteral",pattern:/TRUE/}),f=e({name:"FalseLiteral",pattern:/FALSE/}),m=e({name:"NullLiteral",pattern:/NULL/}),g=e({name:"LSquare",pattern:/\[/}),b=e({name:"RSquare",pattern:/]/}),y=e({name:"LCurly",pattern:/{/}),v=e({name:"RCurly",pattern:/}/}),x=e({name:"Comment",pattern:/#.*/,group:Bc.Lexer.SKIPPED}),w=[e({name:"WhiteSpace",pattern:/[ ,\s]/,group:Bc.Lexer.SKIPPED}),o,a,s,c,l,p,f,m,i,n,t,u,h,d,g,b,y,v,x],E={};for(let e=0,t=w.length;e<t;e++){const t=w[e];E[t.name]=t}return{tokens:w,tokenVocabulary:E}}(),n=new Hc(t.tokens),r=new Gc(t.tokenVocabulary),i=function(e){class t extends e{constructor(){super(),this.validateVisitor()}vrml(e){const t={version:this.visit(e.version),nodes:[],routes:[]};for(let n=0,r=e.node.length;n<r;n++){const r=e.node[n];t.nodes.push(this.visit(r))}if(e.route)for(let n=0,r=e.route.length;n<r;n++){const r=e.route[n];t.routes.push(this.visit(r))}return t}version(e){return e.Version[0].image}node(e){const t={name:e.NodeName[0].image,fields:[]};if(e.field)for(let n=0,r=e.field.length;n<r;n++){const r=e.field[n];t.fields.push(this.visit(r))}return e.def&&(t.DEF=this.visit(e.def[0])),t}field(e){const t={name:e.Identifier[0].image,type:null,values:null};let n;return e.singleFieldValue&&(n=this.visit(e.singleFieldValue[0])),e.multiFieldValue&&(n=this.visit(e.multiFieldValue[0])),t.type=n.type,t.values=n.values,t}def(e){return(e.Identifier||e.NodeName)[0].image}use(e){return{USE:(e.Identifier||e.NodeName)[0].image}}singleFieldValue(e){return n(this,e)}multiFieldValue(e){return n(this,e)}route(e){return{FROM:e.RouteIdentifier[0].image,TO:e.RouteIdentifier[1].image}}}function n(e,t){const n={type:null,values:[]};if(t.node){n.type="node";for(let r=0,i=t.node.length;r<i;r++){const i=t.node[r];n.values.push(e.visit(i))}}if(t.use){n.type="use";for(let r=0,i=t.use.length;r<i;r++){const i=t.use[r];n.values.push(e.visit(i))}}if(t.StringLiteral){n.type="string";for(let e=0,r=t.StringLiteral.length;e<r;e++){const r=t.StringLiteral[e];n.values.push(r.image.replace(/'|"/g,""))}}if(t.NumberLiteral){n.type="number";for(let e=0,r=t.NumberLiteral.length;e<r;e++){const r=t.NumberLiteral[e];n.values.push(parseFloat(r.image))}}if(t.HexLiteral){n.type="hex";for(let e=0,r=t.HexLiteral.length;e<r;e++){const r=t.HexLiteral[e];n.values.push(r.image)}}if(t.TrueLiteral){n.type="boolean";for(let e=0,r=t.TrueLiteral.length;e<r;e++){"TRUE"===t.TrueLiteral[e].image&&n.values.push(!0)}}if(t.FalseLiteral){n.type="boolean";for(let e=0,r=t.FalseLiteral.length;e<r;e++){"FALSE"===t.FalseLiteral[e].image&&n.values.push(!1)}}return t.NullLiteral&&(n.type="null",t.NullLiteral.forEach(function(){n.values.push(null)})),n}return new t}(r.getBaseCstVisitorConstructor()),o=n.lex(e);r.input=o.tokens;const a=r.vrml();if(r.errors.length>0)throw console.error(r.errors),Error("THREE.VRMLLoader: Parsing errors detected.");return i.visit(a)}(e),$=function(e){const t=e.nodes,n=new Qe;for(let e=0,n=t.length;e<n;e++){r(t[e])}for(let e=0,r=t.length;e<r;e++){const r=t[e],o=i(r);o instanceof x&&n.add(o),"WorldInfo"===r.name&&(n.userData.worldInfo=o)}return n}(Q);return $}}class Hc{constructor(e){this.lexer=new Bc.Lexer(e)}lex(e){const t=this.lexer.tokenize(e);if(t.errors.length>0)throw console.error(t.errors),Error("THREE.VRMLLexer: Lexing errors detected.");return t}}const Vc=Bc.CstParser;class Gc extends Vc{constructor(e){super(e);const t=this,n=e.Version,r=e.LCurly,i=e.RCurly,o=e.LSquare,a=e.RSquare,s=e.Identifier,c=e.RouteIdentifier,l=e.StringLiteral,u=e.HexLiteral,h=e.NumberLiteral,d=e.TrueLiteral,p=e.FalseLiteral,f=e.NullLiteral,m=e.DEF,g=e.USE,b=e.ROUTE,y=e.TO,v=e.NodeName;t.RULE("vrml",function(){t.SUBRULE(t.version),t.AT_LEAST_ONE(function(){t.SUBRULE(t.node)}),t.MANY(function(){t.SUBRULE(t.route)})}),t.RULE("version",function(){t.CONSUME(n)}),t.RULE("node",function(){t.OPTION(function(){t.SUBRULE(t.def)}),t.CONSUME(v),t.CONSUME(r),t.MANY(function(){t.SUBRULE(t.field)}),t.CONSUME(i)}),t.RULE("field",function(){t.CONSUME(s),t.OR2([{ALT:function(){t.SUBRULE(t.singleFieldValue)}},{ALT:function(){t.SUBRULE(t.multiFieldValue)}}])}),t.RULE("def",function(){t.CONSUME(m),t.OR([{ALT:function(){t.CONSUME(s)}},{ALT:function(){t.CONSUME(v)}}])}),t.RULE("use",function(){t.CONSUME(g),t.OR([{ALT:function(){t.CONSUME(s)}},{ALT:function(){t.CONSUME(v)}}])}),t.RULE("singleFieldValue",function(){t.AT_LEAST_ONE(function(){t.OR([{ALT:function(){t.SUBRULE(t.node)}},{ALT:function(){t.SUBRULE(t.use)}},{ALT:function(){t.CONSUME(l)}},{ALT:function(){t.CONSUME(u)}},{ALT:function(){t.CONSUME(h)}},{ALT:function(){t.CONSUME(d)}},{ALT:function(){t.CONSUME(p)}},{ALT:function(){t.CONSUME(f)}}])})}),t.RULE("multiFieldValue",function(){t.CONSUME(o),t.MANY(function(){t.OR([{ALT:function(){t.SUBRULE(t.node)}},{ALT:function(){t.SUBRULE(t.use)}},{ALT:function(){t.CONSUME(l)}},{ALT:function(){t.CONSUME(u)}},{ALT:function(){t.CONSUME(h)}},{ALT:function(){t.CONSUME(f)}}])}),t.CONSUME(a)}),t.RULE("route",function(){t.CONSUME(b),t.CONSUME(c),t.CONSUME(y),t.CONSUME2(c)}),this.performSelfAnalysis()}}class Wc{constructor(e,t,n){this.a=e,this.b=t,this.c=n,this.normal=new f}}const Xc={INTENSITY:1,INTENSITY_ALPHA:2,RGB:3,RGBA:4};class qc extends X{constructor(e){super(e),this.littleEndian=!0}load(e,t,n,r){const i=this,o=new q(i.manager);o.setPath(i.path),o.setResponseType("arraybuffer"),o.setRequestHeader(i.requestHeader),o.setWithCredentials(i.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){const t=(new TextDecoder).decode(e),n=function(e){const t={},n=e.search(/[\r\n]DATA\s(\S*)\s/i),r=/[\r\n]DATA\s(\S*)\s/i.exec(e.slice(n-1));if(t.data=r[1],t.headerLen=r[0].length+n,t.str=e.slice(0,t.headerLen),t.str=t.str.replace(/#.*/gi,""),t.version=/VERSION (.*)/i.exec(t.str),t.fields=/FIELDS (.*)/i.exec(t.str),t.size=/SIZE (.*)/i.exec(t.str),t.type=/TYPE (.*)/i.exec(t.str),t.count=/COUNT (.*)/i.exec(t.str),t.width=/WIDTH (.*)/i.exec(t.str),t.height=/HEIGHT (.*)/i.exec(t.str),t.viewpoint=/VIEWPOINT (.*)/i.exec(t.str),t.points=/POINTS (.*)/i.exec(t.str),null!==t.version&&(t.version=parseFloat(t.version[1])),t.fields=null!==t.fields?t.fields[1].split(" "):[],null!==t.type&&(t.type=t.type[1].split(" ")),null!==t.width&&(t.width=parseInt(t.width[1])),null!==t.height&&(t.height=parseInt(t.height[1])),null!==t.viewpoint&&(t.viewpoint=t.viewpoint[1]),null!==t.points&&(t.points=parseInt(t.points[1],10)),null===t.points&&(t.points=t.width*t.height),null!==t.size&&(t.size=t.size[1].split(" ").map(function(e){return parseInt(e,10)})),null!==t.count)t.count=t.count[1].split(" ").map(function(e){return parseInt(e,10)});else{t.count=[];for(let e=0,n=t.fields.length;e<n;e++)t.count.push(1)}t.offset={};let i=0;for(let e=0,n=t.fields.length;e<n;e++)"ascii"===t.data?t.offset[t.fields[e]]=e:(t.offset[t.fields[e]]=i,i+=t.size[e]*t.count[e]);return t.rowSize=i,t}(t),r=[],i=[],o=[],a=[],s=[],c=new K;if("ascii"===n.data){const e=n.offset,l=t.slice(n.headerLen).split("\n");for(let t=0,u=l.length;t<u;t++){if(""===l[t])continue;const u=l[t].split(" ");if(void 0!==e.x&&(r.push(parseFloat(u[e.x])),r.push(parseFloat(u[e.y])),r.push(parseFloat(u[e.z]))),void 0!==e.rgb){const t=n.fields.findIndex(e=>"rgb"===e),r=n.type[t],i=parseFloat(u[e.rgb]);let a=i;if("F"===r){const e=new Float32Array(1);e[0]=i,a=new Int32Array(e.buffer)[0]}const s=(a>>16&255)/255,l=(a>>8&255)/255,h=(255&a)/255;c.set(s,l,h).convertSRGBToLinear(),o.push(c.r,c.g,c.b)}void 0!==e.normal_x&&(i.push(parseFloat(u[e.normal_x])),i.push(parseFloat(u[e.normal_y])),i.push(parseFloat(u[e.normal_z]))),void 0!==e.intensity&&a.push(parseFloat(u[e.intensity])),void 0!==e.label&&s.push(parseInt(u[e.label]))}}if("binary_compressed"===n.data){const t=new Uint32Array(e.slice(n.headerLen,n.headerLen+8)),l=t[0],u=t[1],h=function(e,t){const n=e.length,r=new Uint8Array(t);let i,o,a,s=0,c=0;do{if(i=e[s++],i<32){if(i++,c+i>t)throw new Error("Output buffer is not large enough");if(s+i>n)throw new Error("Invalid compressed data");do{r[c++]=e[s++]}while(--i)}else{if(o=i>>5,a=c-((31&i)<<8)-1,s>=n)throw new Error("Invalid compressed data");if(7===o&&(o+=e[s++],s>=n))throw new Error("Invalid compressed data");if(a-=e[s++],c+o+2>t)throw new Error("Output buffer is not large enough");if(a<0)throw new Error("Invalid compressed data");if(a>=c)throw new Error("Invalid compressed data");do{r[c++]=r[a++]}while(2+--o)}}while(s<n);return r}(new Uint8Array(e,n.headerLen+8,l),u),d=new DataView(h.buffer),p=n.offset;for(let e=0;e<n.points;e++){if(void 0!==p.x){const t=n.fields.indexOf("x"),i=n.fields.indexOf("y"),o=n.fields.indexOf("z");r.push(d.getFloat32(n.points*p.x+n.size[t]*e,this.littleEndian)),r.push(d.getFloat32(n.points*p.y+n.size[i]*e,this.littleEndian)),r.push(d.getFloat32(n.points*p.z+n.size[o]*e,this.littleEndian))}if(void 0!==p.rgb){const t=n.fields.indexOf("rgb"),r=d.getUint8(n.points*p.rgb+n.size[t]*e+2)/255,i=d.getUint8(n.points*p.rgb+n.size[t]*e+1)/255,a=d.getUint8(n.points*p.rgb+n.size[t]*e+0)/255;c.set(r,i,a).convertSRGBToLinear(),o.push(c.r,c.g,c.b)}if(void 0!==p.normal_x){const t=n.fields.indexOf("normal_x"),r=n.fields.indexOf("normal_y"),o=n.fields.indexOf("normal_z");i.push(d.getFloat32(n.points*p.normal_x+n.size[t]*e,this.littleEndian)),i.push(d.getFloat32(n.points*p.normal_y+n.size[r]*e,this.littleEndian)),i.push(d.getFloat32(n.points*p.normal_z+n.size[o]*e,this.littleEndian))}if(void 0!==p.intensity){const t=n.fields.indexOf("intensity");a.push(d.getFloat32(n.points*p.intensity+n.size[t]*e,this.littleEndian))}if(void 0!==p.label){const t=n.fields.indexOf("label");s.push(d.getInt32(n.points*p.label+n.size[t]*e,this.littleEndian))}}}if("binary"===n.data){const t=new DataView(e,n.headerLen),l=n.offset;for(let e=0,u=0;e<n.points;e++,u+=n.rowSize){if(void 0!==l.x&&(r.push(t.getFloat32(u+l.x,this.littleEndian)),r.push(t.getFloat32(u+l.y,this.littleEndian)),r.push(t.getFloat32(u+l.z,this.littleEndian))),void 0!==l.rgb){const e=t.getUint8(u+l.rgb+2)/255,n=t.getUint8(u+l.rgb+1)/255,r=t.getUint8(u+l.rgb+0)/255;c.set(e,n,r).convertSRGBToLinear(),o.push(c.r,c.g,c.b)}void 0!==l.normal_x&&(i.push(t.getFloat32(u+l.normal_x,this.littleEndian)),i.push(t.getFloat32(u+l.normal_y,this.littleEndian)),i.push(t.getFloat32(u+l.normal_z,this.littleEndian))),void 0!==l.intensity&&a.push(t.getFloat32(u+l.intensity,this.littleEndian)),void 0!==l.label&&s.push(t.getInt32(u+l.label,this.littleEndian))}}const l=new O;r.length>0&&l.setAttribute("position",new k(r,3)),i.length>0&&l.setAttribute("normal",new k(i,3)),o.length>0&&l.setAttribute("color",new k(o,3)),a.length>0&&l.setAttribute("intensity",new k(a,1)),s.length>0&&l.setAttribute("label",new it(s,1)),l.computeBoundingSphere();const u=new ye({size:.005});return o.length>0&&(u.vertexColors=!0),new Ce(l,u)}}class Yc extends X{constructor(e){super(e),this.animateBonePositions=!0,this.animateBoneRotations=!0}load(e,t,n,r){const i=this,o=new q(i.manager);o.setPath(i.path),o.setRequestHeader(i.requestHeader),o.setWithCredentials(i.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){function t(e,n,r){if("ENDSITE"===r.type)return;const i={time:n,position:new f,rotation:new y};r.frames.push(i);const o=new y,a=new f(1,0,0),s=new f(0,1,0),c=new f(0,0,1);for(let t=0;t<r.channels.length;t++)switch(r.channels[t]){case"Xposition":i.position.x=parseFloat(e.shift().trim());break;case"Yposition":i.position.y=parseFloat(e.shift().trim());break;case"Zposition":i.position.z=parseFloat(e.shift().trim());break;case"Xrotation":o.setFromAxisAngle(a,parseFloat(e.shift().trim())*Math.PI/180),i.rotation.multiply(o);break;case"Yrotation":o.setFromAxisAngle(s,parseFloat(e.shift().trim())*Math.PI/180),i.rotation.multiply(o);break;case"Zrotation":o.setFromAxisAngle(c,parseFloat(e.shift().trim())*Math.PI/180),i.rotation.multiply(o);break;default:console.warn("THREE.BVHLoader: Invalid channel type.")}for(let i=0;i<r.children.length;i++)t(e,n,r.children[i])}function n(e,t,i){const o={name:"",type:"",frames:[]};i.push(o);let a=t.split(/[\s]+/);"END"===a[0].toUpperCase()&&"SITE"===a[1].toUpperCase()?(o.type="ENDSITE",o.name="ENDSITE"):(o.name=a[1],o.type=a[0].toUpperCase()),"{"!==r(e)&&console.error("THREE.BVHLoader: Expected opening { after type & name"),a=r(e).split(/[\s]+/),"OFFSET"!==a[0]&&console.error("THREE.BVHLoader: Expected OFFSET but got: "+a[0]),4!==a.length&&console.error("THREE.BVHLoader: Invalid number of values for OFFSET.");const s=new f(parseFloat(a[1]),parseFloat(a[2]),parseFloat(a[3]));if((isNaN(s.x)||isNaN(s.y)||isNaN(s.z))&&console.error("THREE.BVHLoader: Invalid values of OFFSET."),o.offset=s,"ENDSITE"!==o.type){a=r(e).split(/[\s]+/),"CHANNELS"!==a[0]&&console.error("THREE.BVHLoader: Expected CHANNELS definition.");const t=parseInt(a[1]);o.channels=a.splice(2,t),o.children=[]}for(;;){const t=r(e);if("}"===t)return o;o.children.push(n(e,t,i))}}function r(e){let t;for(;0===(t=e.shift().trim()).length;);return t}const i=this,o=function(e){"HIERARCHY"!==r(e)&&console.error("THREE.BVHLoader: HIERARCHY expected.");const i=[],o=n(e,r(e),i);"MOTION"!==r(e)&&console.error("THREE.BVHLoader: MOTION expected.");let a=r(e).split(/[\s]+/);const s=parseInt(a[1]);isNaN(s)&&console.error("THREE.BVHLoader: Failed to read number of frames."),a=r(e).split(/[\s]+/);const c=parseFloat(a[2]);isNaN(c)&&console.error("THREE.BVHLoader: Failed to read frame time.");for(let n=0;n<s;n++)a=r(e).split(/[\s]+/),t(a,n*c,o);return i}(e.split(/[\r\n]+/g)),a=[];!function e(t,n){const r=new Ie;if(n.push(r),r.position.add(t.offset),r.name=t.name,"ENDSITE"!==t.type)for(let i=0;i<t.children.length;i++)r.add(e(t.children[i],n));return r}(o[0],a);const s=function(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if("ENDSITE"===r.type)continue;const o=[],a=[],s=[];for(let e=0;e<r.frames.length;e++){const t=r.frames[e];o.push(t.time),a.push(t.position.x+r.offset.x),a.push(t.position.y+r.offset.y),a.push(t.position.z+r.offset.z),s.push(t.rotation.x),s.push(t.rotation.y),s.push(t.rotation.z),s.push(t.rotation.w)}i.animateBonePositions&&t.push(new Le(r.name+".position",o,a)),i.animateBoneRotations&&t.push(new je(r.name+".quaternion",o,s))}return new Re("animation",-1,t)}(o);return{skeleton:new Me(a),clip:s}}}const Kc=[[-.525731,0,.850651],[-.442863,.238856,.864188],[-.295242,0,.955423],[-.309017,.5,.809017],[-.16246,.262866,.951056],[0,0,1],[0,.850651,.525731],[-.147621,.716567,.681718],[.147621,.716567,.681718],[0,.525731,.850651],[.309017,.5,.809017],[.525731,0,.850651],[.295242,0,.955423],[.442863,.238856,.864188],[.16246,.262866,.951056],[-.681718,.147621,.716567],[-.809017,.309017,.5],[-.587785,.425325,.688191],[-.850651,.525731,0],[-.864188,.442863,.238856],[-.716567,.681718,.147621],[-.688191,.587785,.425325],[-.5,.809017,.309017],[-.238856,.864188,.442863],[-.425325,.688191,.587785],[-.716567,.681718,-.147621],[-.5,.809017,-.309017],[-.525731,.850651,0],[0,.850651,-.525731],[-.238856,.864188,-.442863],[0,.955423,-.295242],[-.262866,.951056,-.16246],[0,1,0],[0,.955423,.295242],[-.262866,.951056,.16246],[.238856,.864188,.442863],[.262866,.951056,.16246],[.5,.809017,.309017],[.238856,.864188,-.442863],[.262866,.951056,-.16246],[.5,.809017,-.309017],[.850651,.525731,0],[.716567,.681718,.147621],[.716567,.681718,-.147621],[.525731,.850651,0],[.425325,.688191,.587785],[.864188,.442863,.238856],[.688191,.587785,.425325],[.809017,.309017,.5],[.681718,.147621,.716567],[.587785,.425325,.688191],[.955423,.295242,0],[1,0,0],[.951056,.16246,.262866],[.850651,-.525731,0],[.955423,-.295242,0],[.864188,-.442863,.238856],[.951056,-.16246,.262866],[.809017,-.309017,.5],[.681718,-.147621,.716567],[.850651,0,.525731],[.864188,.442863,-.238856],[.809017,.309017,-.5],[.951056,.16246,-.262866],[.525731,0,-.850651],[.681718,.147621,-.716567],[.681718,-.147621,-.716567],[.850651,0,-.525731],[.809017,-.309017,-.5],[.864188,-.442863,-.238856],[.951056,-.16246,-.262866],[.147621,.716567,-.681718],[.309017,.5,-.809017],[.425325,.688191,-.587785],[.442863,.238856,-.864188],[.587785,.425325,-.688191],[.688191,.587785,-.425325],[-.147621,.716567,-.681718],[-.309017,.5,-.809017],[0,.525731,-.850651],[-.525731,0,-.850651],[-.442863,.238856,-.864188],[-.295242,0,-.955423],[-.16246,.262866,-.951056],[0,0,-1],[.295242,0,-.955423],[.16246,.262866,-.951056],[-.442863,-.238856,-.864188],[-.309017,-.5,-.809017],[-.16246,-.262866,-.951056],[0,-.850651,-.525731],[-.147621,-.716567,-.681718],[.147621,-.716567,-.681718],[0,-.525731,-.850651],[.309017,-.5,-.809017],[.442863,-.238856,-.864188],[.16246,-.262866,-.951056],[.238856,-.864188,-.442863],[.5,-.809017,-.309017],[.425325,-.688191,-.587785],[.716567,-.681718,-.147621],[.688191,-.587785,-.425325],[.587785,-.425325,-.688191],[0,-.955423,-.295242],[0,-1,0],[.262866,-.951056,-.16246],[0,-.850651,.525731],[0,-.955423,.295242],[.238856,-.864188,.442863],[.262866,-.951056,.16246],[.5,-.809017,.309017],[.716567,-.681718,.147621],[.525731,-.850651,0],[-.238856,-.864188,-.442863],[-.5,-.809017,-.309017],[-.262866,-.951056,-.16246],[-.850651,-.525731,0],[-.716567,-.681718,-.147621],[-.716567,-.681718,.147621],[-.525731,-.850651,0],[-.5,-.809017,.309017],[-.238856,-.864188,.442863],[-.262866,-.951056,.16246],[-.864188,-.442863,.238856],[-.809017,-.309017,.5],[-.688191,-.587785,.425325],[-.681718,-.147621,.716567],[-.442863,-.238856,.864188],[-.587785,-.425325,.688191],[-.309017,-.5,.809017],[-.147621,-.716567,.681718],[-.425325,-.688191,.587785],[-.16246,-.262866,.951056],[.442863,-.238856,.864188],[.16246,-.262866,.951056],[.309017,-.5,.809017],[.147621,-.716567,.681718],[0,-.525731,.850651],[.425325,-.688191,.587785],[.587785,-.425325,.688191],[.688191,-.587785,.425325],[-.955423,.295242,0],[-.951056,.16246,.262866],[-1,0,0],[-.850651,0,.525731],[-.955423,-.295242,0],[-.951056,-.16246,.262866],[-.864188,.442863,-.238856],[-.951056,.16246,-.262866],[-.809017,.309017,-.5],[-.864188,-.442863,-.238856],[-.951056,-.16246,-.262866],[-.809017,-.309017,-.5],[-.681718,.147621,-.716567],[-.681718,-.147621,-.716567],[-.850651,0,-.525731],[-.688191,.587785,-.425325],[-.587785,.425325,-.688191],[-.425325,.688191,-.587785],[-.425325,-.688191,-.587785],[-.587785,-.425325,-.688191],[-.688191,-.587785,-.425325]];class Qc extends X{constructor(e){super(e)}load(e,t,n,r){const i=this,o=new q(i.manager);o.setPath(i.path),o.setResponseType("arraybuffer"),o.setRequestHeader(i.requestHeader),o.setWithCredentials(i.withCredentials),o.load(e,function(n){try{t(i.parse(n))}catch(t){r?r(t):console.error(t),i.manager.itemError(e)}},n,r)}parse(e){const t=new DataView(e),n={},r=["ident","version","skinwidth","skinheight","framesize","num_skins","num_vertices","num_st","num_tris","num_glcmds","num_frames","offset_skins","offset_st","offset_tris","offset_frames","offset_glcmds","offset_end"];for(let e=0;e<r.length;e++)n[r[e]]=t.getInt32(4*e,!0);if(844121161!==n.ident||8!==n.version)return void console.error("Not a valid MD2 file");if(n.offset_end!==t.byteLength)return void console.error("Corrupted MD2 file");const i=new O,o=[];let a=n.offset_st;for(let e=0,r=n.num_st;e<r;e++){const e=t.getInt16(a+0,!0),r=t.getInt16(a+2,!0);o.push(e/n.skinwidth,1-r/n.skinheight),a+=4}a=n.offset_tris;const s=[],c=[];for(let e=0,r=n.num_tris;e<r;e++)s.push(t.getUint16(a+0,!0),t.getUint16(a+2,!0),t.getUint16(a+4,!0)),c.push(t.getUint16(a+6,!0),t.getUint16(a+8,!0),t.getUint16(a+10,!0)),a+=12;const l=new f,u=new f,h=[];a=n.offset_frames;for(let e=0,r=n.num_frames;e<r;e++){u.set(t.getFloat32(a+0,!0),t.getFloat32(a+4,!0),t.getFloat32(a+8,!0)),l.set(t.getFloat32(a+12,!0),t.getFloat32(a+16,!0),t.getFloat32(a+20,!0)),a+=24;const e=[];for(let n=0;n<16;n++){const r=t.getUint8(a+n);if(0===r)break;e[n]=r}const r={name:String.fromCharCode.apply(null,e),vertices:[],normals:[]};a+=16;for(let e=0;e<n.num_vertices;e++){let e=t.getUint8(a++),n=t.getUint8(a++),i=t.getUint8(a++);const o=Kc[t.getUint8(a++)];e=e*u.x+l.x,n=n*u.y+l.y,i=i*u.z+l.z,r.vertices.push(e,i,n),r.normals.push(o[0],o[2],o[1])}h.push(r)}const d=[],p=[],m=[],g=h[0].vertices,b=h[0].normals;for(let e=0,t=s.length;e<t;e++){let t=3*s[e];const n=g[t],r=g[t+1],i=g[t+2];d.push(n,r,i);const a=b[t],l=b[t+1],u=b[t+2];p.push(a,l,u);t=2*c[e];const h=o[t],f=o[t+1];m.push(h,f)}i.setAttribute("position",new k(d,3)),i.setAttribute("normal",new k(p,3)),i.setAttribute("uv",new k(m,2));const y=[],v=[];for(let e=0,t=h.length;e<t;e++){const t=h[e],n=t.name;if(t.vertices.length>0){const e=[];for(let n=0,r=s.length;n<r;n++){const r=3*s[n],i=t.vertices[r],o=t.vertices[r+1],a=t.vertices[r+2];e.push(i,o,a)}const r=new k(e,3);r.name=n,y.push(r)}if(t.normals.length>0){const e=[];for(let n=0,r=s.length;n<r;n++){const r=3*s[n],i=t.normals[r],o=t.normals[r+1],a=t.normals[r+2];e.push(i,o,a)}const r=new k(e,3);r.name=n,v.push(r)}}return i.morphAttributes.position=y,i.morphAttributes.normal=v,i.morphTargetsRelative=!1,i.animations=Re.CreateClipsFromMorphTargetSequences(h,10),i}}const $c=new f,Zc=new f;class Jc{modify(e,t){delete(e=e.clone()).morphAttributes.position,delete e.morphAttributes.normal;const n=e.attributes;for(const t in n)"position"!==t&&"uv"!==t&&"normal"!==t&&"tangent"!==t&&"color"!==t&&e.deleteAttribute(t);e=function(e,t=1e-4){t=Math.max(t,Number.EPSILON);const n={},r=e.getIndex(),i=e.getAttribute("position"),o=r?r.count:i.count;let a=0;const s=Object.keys(e.attributes),c={},l={},u=[],h=["getX","getY","getZ","getW"],d=["setX","setY","setZ","setW"];for(let t=0,n=s.length;t<n;t++){const n=s[t],r=e.attributes[n];c[n]=new j(new r.array.constructor(r.count*r.itemSize),r.itemSize,r.normalized);const i=e.morphAttributes[n];i&&(l[n]=new j(new i.array.constructor(i.count*i.itemSize),i.itemSize,i.normalized))}const p=.5*t,f=Math.log10(1/t),m=Math.pow(10,f),g=p*m;for(let t=0;t<o;t++){const i=r?r.getX(t):t;let o="";for(let t=0,n=s.length;t<n;t++){const n=s[t],r=e.getAttribute(n),a=r.itemSize;for(let e=0;e<a;e++)o+=~~(r[h[e]](i)*m+g)+","}if(o in n)u.push(n[o]);else{for(let t=0,n=s.length;t<n;t++){const n=s[t],r=e.getAttribute(n),o=e.morphAttributes[n],u=r.itemSize,p=c[n],f=l[n];for(let e=0;e<u;e++){const t=h[e],n=d[e];if(p[n](a,r[t](i)),o)for(let e=0,r=o.length;e<r;e++)f[e][n](a,o[e][t](i))}}n[o]=a,u.push(a),a++}}const b=e.clone();for(const t in e.attributes){const e=c[t];if(b.setAttribute(t,new j(e.array.slice(0,a*e.itemSize),e.itemSize,e.normalized)),t in l)for(let e=0;e<l[t].length;e++){const n=l[t][e];b.morphAttributes[t][e]=new j(n.array.slice(0,a*n.itemSize),n.itemSize,n.normalized)}}return b.setIndex(u),b}(e);const r=[],i=[],o=e.getAttribute("position"),a=e.getAttribute("uv"),s=e.getAttribute("normal"),c=e.getAttribute("tangent"),l=e.getAttribute("color");let u=null,h=null,d=null,p=null;for(let e=0;e<o.count;e++){const t=(new f).fromBufferAttribute(o,e);a&&(h=(new v).fromBufferAttribute(a,e)),s&&(d=(new f).fromBufferAttribute(s,e)),c&&(u=(new He).fromBufferAttribute(c,e)),l&&(p=(new THREE.Color).fromBufferAttribute(l,e));const n=new cl(t,h,d,u,p);r.push(n)}let m,g=e.getIndex();if(null!==g)for(let e=0;e<g.count;e+=3){const t=g.getX(e),n=g.getX(e+1),o=g.getX(e+2),a=new sl(r[t],r[n],r[o],t,n,o);i.push(a)}else for(let e=0;e<o.count;e+=3){const t=e,n=e+1,o=e+2,a=new sl(r[t],r[n],r[o],t,n,o);i.push(a)}for(let e=0,t=r.length;e<t;e++)nl(r[e]);let b=t;for(;b--;){if(m=al(r),!m){console.log("THREE.SimplifyModifier: No next vertex");break}ol(r,i,m,m.collapseNeighbor)}const y=new O,x=[],w=[],E=[],T=[],A=[];g=[];for(let e=0;e<r.length;e++){const t=r[e];x.push(t.position.x,t.position.y,t.position.z),t.uv&&w.push(t.uv.x,t.uv.y),t.normal&&E.push(t.normal.x,t.normal.y,t.normal.z),t.tangent&&T.push(t.tangent.x,t.tangent.y,t.tangent.z,t.tangent.w),t.color&&A.push(t.color.r,t.color.g,t.color.b),t.id=e}for(let e=0;e<i.length;e++){const t=i[e];g.push(t.v1.id,t.v2.id,t.v3.id)}return y.setAttribute("position",new k(x,3)),w.length>0&&y.setAttribute("uv",new k(w,2)),E.length>0&&y.setAttribute("normal",new k(E,3)),T.length>0&&y.setAttribute("tangent",new k(T,4)),A.length>0&&y.setAttribute("color",new k(A,3)),y.setIndex(g),y}}function el(e,t){const n=e.indexOf(t);n>-1&&e.splice(n,1)}function tl(e,t){const n=t.position.distanceTo(e.position);let r=0;const i=[];for(let n=0,r=e.faces.length;n<r;n++){const r=e.faces[n];r.hasVertex(t)&&i.push(r)}for(let t=0,n=e.faces.length;t<n;t++){let n=1;const o=e.faces[t];for(let e=0;e<i.length;e++){const t=i[e],r=o.normal.dot(t.normal);n=Math.min(n,(1.001-r)/2)}r=Math.max(r,n)}i.length<2&&(r=1);return n*r+0}function nl(e){if(0===e.neighbors.length)return e.collapseNeighbor=null,void(e.collapseCost=-.01);e.collapseCost=1e5,e.collapseNeighbor=null;for(let t=0;t<e.neighbors.length;t++){const n=tl(e,e.neighbors[t]);e.collapseNeighbor||(e.collapseNeighbor=e.neighbors[t],e.collapseCost=n,e.minCost=n,e.totalCost=0,e.costCount=0),e.costCount++,e.totalCost+=n,n<e.minCost&&(e.collapseNeighbor=e.neighbors[t],e.minCost=n)}e.collapseCost=e.totalCost/e.costCount}function rl(e,t){for(console.assert(0===e.faces.length);e.neighbors.length;){el(e.neighbors.pop().neighbors,e)}el(t,e)}function il(e,t){el(t,e),e.v1&&el(e.v1.faces,e),e.v2&&el(e.v2.faces,e),e.v3&&el(e.v3.faces,e);const n=[e.v1,e.v2,e.v3];for(let e=0;e<3;e++){const t=n[e],r=n[(e+1)%3];t&&r&&(t.removeIfNonNeighbor(r),r.removeIfNonNeighbor(t))}}function ol(e,t,n,r){if(!r)return void rl(n,e);r.uv&&n.uv.copy(r.uv),r.normal&&r.normal.add(n.normal).normalize(),r.tangent&&r.tangent.add(n.tangent).normalize();const i=[];for(let e=0;e<n.neighbors.length;e++)i.push(n.neighbors[e]);for(let e=n.faces.length-1;e>=0;e--)n.faces[e]&&n.faces[e].hasVertex(r)&&il(n.faces[e],t);for(let e=n.faces.length-1;e>=0;e--)n.faces[e].replaceVertex(n,r);rl(n,e);for(let e=0;e<i.length;e++)nl(i[e])}function al(e){let t=e[0];for(let n=0;n<e.length;n++)e[n].collapseCost<t.collapseCost&&(t=e[n]);return t}class sl{constructor(e,t,n,r,i,o){this.a=r,this.b=i,this.c=o,this.v1=e,this.v2=t,this.v3=n,this.normal=new f,this.computeNormal(),e.faces.push(this),e.addUniqueNeighbor(t),e.addUniqueNeighbor(n),t.faces.push(this),t.addUniqueNeighbor(e),t.addUniqueNeighbor(n),n.faces.push(this),n.addUniqueNeighbor(e),n.addUniqueNeighbor(t)}computeNormal(){const e=this.v1.position,t=this.v2.position,n=this.v3.position;$c.subVectors(n,t),Zc.subVectors(e,t),$c.cross(Zc).normalize(),this.normal.copy($c)}hasVertex(e){return e===this.v1||e===this.v2||e===this.v3}replaceVertex(e,t){e===this.v1?this.v1=t:e===this.v2?this.v2=t:e===this.v3&&(this.v3=t),el(e.faces,this),t.faces.push(this),e.removeIfNonNeighbor(this.v1),this.v1.removeIfNonNeighbor(e),e.removeIfNonNeighbor(this.v2),this.v2.removeIfNonNeighbor(e),e.removeIfNonNeighbor(this.v3),this.v3.removeIfNonNeighbor(e),this.v1.addUniqueNeighbor(this.v2),this.v1.addUniqueNeighbor(this.v3),this.v2.addUniqueNeighbor(this.v1),this.v2.addUniqueNeighbor(this.v3),this.v3.addUniqueNeighbor(this.v1),this.v3.addUniqueNeighbor(this.v2),this.computeNormal()}}class cl{constructor(e,t,n,r,i){this.position=e,this.uv=t,this.normal=n,this.tangent=r,this.color=i,this.id=-1,this.faces=[],this.neighbors=[],this.collapseCost=0,this.collapseNeighbor=null}addUniqueNeighbor(e){var t,n;t=this.neighbors,n=e,-1===t.indexOf(n)&&t.push(n)}removeIfNonNeighbor(e){const t=this.neighbors,n=this.faces,r=t.indexOf(e);if(-1!==r){for(let t=0;t<n.length;t++)if(n[t].hasVertex(e))return;t.splice(r,1)}}}const ll={maxSize:null,maxWidth:null,maxHeight:null,autoResize:!0,quality:.8};function ul(e={}){const t={...ll};return Object.keys(e).forEach(n=>{null!==e[n]&&void 0!==e[n]&&(t[n]=e[n])}),t}function hl(e,t={}){console.log(e);const n=ul(t);return new Promise(async(t,r)=>{try{e.preventDefault();const i=e.dataTransfer.getData("application/x-gallery-image"),o=e.dataTransfer.getData("application/json"),a=e.dataTransfer.getData("text/plain"),s=e.dataTransfer.files;if(i){const e=JSON.parse(i);if(e.picUrl){return void t(await dl(e.picUrl,n))}}if(s&&s.length>0){const e=s[0];if(e.type.startsWith("image/")){const r=await function(e,t={}){const n=ul(t);return new Promise(async(t,r)=>{try{if(!e.type.startsWith("image/"))return void r(new Error("请选择图片文件"));if(n.maxSize&&e.size>n.maxSize)return void r(new Error(`文件大小不能超过 ${(n.maxSize/1024/1024).toFixed(1)}MB`));const i=await function(e,t){return new Promise((n,r)=>{const i=new Image,o=document.createElement("canvas"),a=o.getContext("2d");i.onload=()=>{const{naturalWidth:s,naturalHeight:c}=i;if(t.maxWidth&&s>t.maxWidth||t.maxHeight&&c>t.maxHeight){if(!t.autoResize)return void r(new Error(`图片尺寸不能超过 ${t.maxWidth||"∞"}x${t.maxHeight||"∞"} 像素,当前尺寸:${s}x${c}`));let l=1;if(t.maxWidth&&t.maxHeight){const e=t.maxWidth/s,n=t.maxHeight/c;l=Math.min(e,n)}else t.maxWidth?l=t.maxWidth/s:t.maxHeight&&(l=t.maxHeight/c);const u=Math.floor(s*l),h=Math.floor(c*l);o.width=u,o.height=h,a.drawImage(i,0,0,u,h),o.toBlob(t=>{if(t){const r=new File([t],e.name,{type:e.type,lastModified:Date.now()});n(r)}else r(new Error("图片处理失败"))},e.type,t.quality)}else n(e)},i.onerror=()=>{r(new Error("图片格式不支持或文件损坏"))},i.src=URL.createObjectURL(e)})}(e,n),o=URL.createObjectURL(i);t({file:i,url:o,originalFile:e,isResized:i!==e})}catch(e){r(new Error(e.message||"文件处理失败"))}})}(e,n);return void t(r)}}if(o){const e=JSON.parse(o);if(e.picUrl){return void t(await dl(e.picUrl,n))}}if(a&&a.startsWith("http")){return void t(await dl(a,n))}r(new Error("未找到有效的图片数据"))}catch(e){r(new Error(e.message||"拖拽处理失败"))}})}function dl(e,t={}){const n=ul(t);return new Promise(async(t,r)=>{try{if(!e||!e.startsWith("http"))return void r(new Error("无效的图片URL"));const i=new Image;i.crossOrigin="anonymous",await new Promise((t,n)=>{i.onload=t,i.onerror=()=>n(new Error("图片加载失败")),i.src=e});if(n.maxWidth&&i.naturalWidth>n.maxWidth||n.maxHeight&&i.naturalHeight>n.maxHeight){if(!n.autoResize)return void r(new Error(`图片尺寸不能超过 ${n.maxWidth||"∞"}x${n.maxHeight||"∞"} 像素,当前尺寸:${i.naturalWidth}x${i.naturalHeight}`));const o=await function(e,t){return new Promise((n,r)=>{const i=document.createElement("canvas"),o=i.getContext("2d");let a=1;if(t.maxWidth&&t.maxHeight){const n=t.maxWidth/e.naturalWidth,r=t.maxHeight/e.naturalHeight;a=Math.min(n,r)}else t.maxWidth?a=t.maxWidth/e.naturalWidth:t.maxHeight&&(a=t.maxHeight/e.naturalHeight);const s=Math.floor(e.naturalWidth*a),c=Math.floor(e.naturalHeight*a);i.width=s,i.height=c,o.drawImage(e,0,0,s,c),i.toBlob(e=>{e?n(e):r(new Error("图片处理失败"))},"image/png",t.quality)})}(i,n),a=URL.createObjectURL(o);t({file:o,url:a,originalUrl:e,isResized:!0})}else{t({file:null,url:e,originalUrl:e,isResized:!1})}}catch(e){r(new Error(`图片加载失败: ${e.message}`))}})}class pl{constructor(t,n,r,i){if(this.addObjects=i,this.canvas=t,this.models=[],this.loadingManager=new e.LoadingManager,this.textureLoader=new e.TextureLoader(this.loadingManager),this.scene=r,this.simplifyModifier=new Jc,this.clock=new e.Clock,this.mixers=[],this.animations=new Map,n)this.camera=n;else{const n=t.clientWidth/t.clientHeight;this.camera=new e.PerspectiveCamera(75,n,.1,1e3),this.camera.position.z=5}this.loadingManager.onError=e=>{console.warn(`Failed to load resource: ${e}`)},this.initDragDrop()}initDragDrop(){this.canvas.addEventListener("dragover",e=>{e.preventDefault(),e.stopPropagation(),this.canvas.style.border="2px dashed #646cff"}),this.canvas.addEventListener("dragleave",e=>{e.preventDefault(),e.stopPropagation(),this.canvas.style.border=""}),this.canvas.addEventListener("drop",async e=>{e.preventDefault(),e.stopPropagation(),this.canvas.style.border="";try{const t=await hl(e);return console.log(t),void this.loadFile(t.originalUrl||t.file)}catch(e){}const t=e.dataTransfer.files;t.length>0&&this.loadFile(t[0])})}getLoaderForExtension(e){switch(e.toLowerCase()){case"gltf":case"glb":const t=new yo(this.loadingManager),n=new mo;return n.setDecoderPath("https://www.gstatic.com/draco/v1/decoders/"),t.setDRACOLoader(n),t.setMeshoptDecoder(ma),t;case"obj":return new Sa(this.loadingManager);case"mtl":return new Ma(this.loadingManager);case"fbx":return new Fa(this.loadingManager);case"dae":return new rs(this.loadingManager);case"ply":return new os(this.loadingManager);case"stl":return new ss(this.loadingManager);case"svg":return new ls(this.loadingManager);case"3ds":return new us(this.loadingManager);case"wrl":return new zc(this.loadingManager);case"pcd":return new qc(this.loadingManager);case"prwm":return new PRWMLoader(this.loadingManager);case"bvh":return new Yc(this.loadingManager);case"md2":return new Qc(this.loadingManager);case"ttf":return new TTFLoader(this.loadingManager);case"ktx2":return new KTX2Loader(this.loadingManager);case"basis":return new BasisTextureLoader(this.loadingManager);case"hdr":case"rgbe":return new RGBELoader(this.loadingManager);case"exr":return new EXRLoader(this.loadingManager);case"tga":return new TGALoader(this.loadingManager);case"ldr":case"mpd":return new LDrawLoader(this.loadingManager);case"nrrd":return new NRRDLoader(this.loadingManager);case"vox":return new VOXLoader(this.loadingManager);case"gcode":return new GCodeLoader(this.loadingManager);case"jpg":case"jpeg":case"png":case"gif":case"bmp":case"webp":return this.textureLoader;default:throw new Error(`Unsupported file format: ${e}`)}}async loadFile(t,n={}){let r,i;if(t instanceof File)r=t.name,i=URL.createObjectURL(t);else{r=t.split("/").pop(),i=t;(i.startsWith("http")||i.startsWith("//"))&&(this.loadingManager.setURLModifier(e=>{if(!e.startsWith("http")&&!e.startsWith("//")){return i.substring(0,i.lastIndexOf("/")+1)+e}return e}),this.textureLoader.setCrossOrigin("anonymous"))}const o=r.split(".").pop().toLowerCase();try{const t=this.getLoaderForExtension(o);"function"==typeof t.setCrossOrigin&&t.setCrossOrigin("anonymous");const r=await this.loadWithLoader(t,i,o);("fbx"===o||"gltf"===o||"glb"===o)&&r.animations&&r.animations.length>0&&this.setupAnimation(r),this.createSkeletonHelper(r),(n.simplifyRatio||n.maxFaces)&&this.optimizeModel(r,n);const a=(new e.Box3).setFromObject(r).getSize(new e.Vector3);let s=1;const c=5,l=Math.max(a.x,a.y,a.z);return l>0&&(s=c/l),r.scale.set(s,s,s),r.rotation.set(0,0,0),r.children.forEach(e=>{e.rotation.set(0,0,0)}),r.castShadow=!0,r.receiveShadow=!0,this.scene&&this.scene.add(r),this.addObjects(r),n.position&&r.position.copy(n.position),n.scale&&r.scale.copy(n.scale),this.models.push(r),r}catch(e){return null}finally{t instanceof File&&URL.revokeObjectURL(i)}}setupAnimation(t){if(t.animations&&t.animations.length>0){const n=new e.AnimationMixer(t);this.mixers.push(n),this.animations.set(t,{mixer:n,clips:t.animations});n.clipAction(t.animations[0]).play()}}createSkeletonHelper(t){const n=new e.SkeletonHelper(t);n.material.linewidth=2,n.name="skeletonHelper",this.scene&&this.scene.add(n),t.userData.skeletonHelpers||(t.userData.skeletonHelpers=[]),t.userData.skeletonHelpers.push(n),console.log("已创建骨骼辅助线")}toggleSkeletonHelper(e,t=!0){e.userData.skeletonHelpers&&e.userData.skeletonHelpers.forEach(e=>{e.visible=t})}removeSkeletonHelper(e){e.userData.skeletonHelpers&&(e.userData.skeletonHelpers.forEach(e=>{this.scene&&this.scene.remove(e),e.dispose()}),e.userData.skeletonHelpers=[])}playAnimation(e,t=0){const n=this.animations.get(e);if(!n)return void console.warn("模型没有动画数据");let r=null;if("number"==typeof t?r=n.clips[t]:"string"==typeof t&&(r=n.clips.find(e=>e.name===t)),!r)return void console.warn("未找到指定的动画");n.mixer.stopAllAction();n.mixer.clipAction(r).play()}updateAnimations(){const e=this.clock.getDelta();this.mixers.forEach(t=>{t.update(e)})}optimizeModel(e,t={}){const{simplifyRatio:n=.5,maxFaces:r}=t;e.traverse(e=>{if(e.isMesh&&e.geometry){if(e.isSkinnedMesh)return void console.log("检测到骨骼网格,跳过减面优化以保持动画质量");const t=e.geometry,i=t.index?t.index.count/3:t.attributes.position.count/3;let o=Math.floor(i*(1-n));if(r&&i>r&&(o=Math.min(o,r)),o<i&&o>0)try{t.index||(t=t.toNonIndexed());const n=1-o/i,r=this.simplifyModifier.modify(t,Math.floor(i*n));r&&r.attributes.position&&(t.dispose(),e.geometry=r,e.geometry.computeVertexNormals(),e.geometry.computeBoundingBox(),e.geometry.computeBoundingSphere(),console.log(`模型减面:${i} -> ${o} 面`))}catch(e){console.warn("模型减面失败:",e)}}})}optimizeAllModels(e={}){this.models.forEach(t=>{this.optimizeModel(t,e)})}loadWithLoader(t,n,r){return new Promise((i,o)=>{switch(r){case"gltf":case"glb":t.load(n,e=>{i(e.scene)},e=>{if(this.loadingElement&&e.loaded&&e.total){const t=Math.round(e.loaded/e.total*100);!isNaN(t)&&t>=0&&t<=100&&(this.loadingElement.textContent=`正在加载模型... ${t}%`)}},e=>{console.warn("GLTF加载失败"),o(new Error("模型文件加载失败"))});break;case"obj":t.load(n,e=>{i(e)},void 0,e=>{console.warn("OBJ加载失败"),o(new Error("模型文件加载失败"))});break;case"fbx":t.load(n,e=>{i(e)},void 0,e=>{console.warn("FBX加载失败"),o(new Error("模型文件加载失败"))});break;case"dae":t.load(n,e=>{i(e.scene)},void 0,e=>{console.warn("DAE加载失败"),o(new Error("模型文件加载失败"))});break;case"mtl":t.load(n,e=>{e.preload();new Sa(this.loadingManager).setMaterials(e),o(new Error("MTL文件需要配合OBJ文件使用"))},void 0,o);break;default:t instanceof e.TextureLoader?t.load(n,t=>{const n=new e.Mesh(new e.PlaneGeometry,new e.MeshBasicMaterial({map:t}));i(n)},void 0,e=>{console.warn("纹理加载失败"),o(new Error("文件加载失败"))}):t.load(n,e=>{i(e)},void 0,e=>{console.warn("文件加载失败:",e.message),o(e)})}})}showLoadingMessage(e){this.removeLoadingMessage();const t=document.createElement("div");t.style.position="absolute",t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)",t.style.background="rgba(0, 0, 0, 0.7)",t.style.color="white",t.style.padding="20px",t.style.borderRadius="5px",t.style.zIndex="1000",t.id="model-loading-message",t.textContent=e||"正在加载模型...",document.body.appendChild(t),this.loadingElement=t}removeLoadingMessage(){const e=document.getElementById("model-loading-message");e&&document.body.removeChild(e),this.loadingElement&&this.loadingElement.parentNode&&this.loadingElement.parentNode.removeChild(this.loadingElement),this.loadingElement=null}clearModels(){this.scene?(this.models.forEach(e=>{if(this.removeSkeletonHelper(e),this.animations.has(e)){const t=this.animations.get(e);if(t.mixer){t.mixer.stopAllAction();const e=this.mixers.indexOf(t.mixer);-1!==e&&this.mixers.splice(e,1)}this.animations.delete(e)}this.scene.remove(e),e.traverse&&e.traverse(e=>{e.material&&(Array.isArray(e.material)?e.material.forEach(e=>{e.map&&e.map.dispose(),e.dispose()}):(e.material.map&&e.material.map.dispose(),e.material.dispose())),e.geometry&&e.geometry.dispose()})}),this.models=[],this.mixers=[],this.animations.clear()):console.warn("场景未初始化,无法清除模型")}handleLoadingError(e){console.warn("模型加载失败"),this.removeLoadingMessage()}}class fl extends e.Mesh{constructor(t=10,n=100,r=new e.Color("white"),i=8e3,o="xzy",a=null,s=null){const c=o.substring(0,2);super(new e.PlaneGeometry(2,2,1,1),new e.ShaderMaterial({side:e.DoubleSide,uniforms:{uSize1:{value:t},uSize2:{value:n},uColor:{value:r},uDistance:{value:i},uAlpha1:{value:1},uAlpha2:{value:0},uCenterLineColorX:{value:a?new e.Color(a):new e.Color("red")},uCenterLineColorY:{value:s?new e.Color(s):new e.Color("green")}},transparent:!0,depthWrite:!1,blending:e.NormalBlending,vertexShader:`\n varying vec3 worldPosition;\n uniform float uDistance;\n void main() {\n vec3 pos = position.${o} * uDistance;\n pos.${c} += cameraPosition.${c};\n worldPosition = pos;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n }\n `,fragmentShader:`\n varying vec3 worldPosition;\n uniform float uSize1;\n uniform float uSize2;\n uniform vec3 uColor;\n uniform float uDistance;\n uniform float uAlpha1;\n uniform float uAlpha2;\n uniform vec3 uCenterLineColorX;\n uniform vec3 uCenterLineColorY;\n float getGrid(float size) {\n vec2 r = worldPosition.${c} / size;\n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y);\n return 1.0 - min(line, 1.0);\n }\n void main() {\n float d = 1.0 - min(distance(cameraPosition.${c}, worldPosition.${c}) / uDistance, 1.0);\n float g1 = getGrid(uSize1);\n float g2 = getGrid(uSize2);\n float alpha = g1 * uAlpha1 + g2 * uAlpha2;\n vec3 color = uColor;\n float outAlpha = alpha * pow(d, 2.0);\n \n // 中心线抗锯齿\n float pxWidth = fwidth(worldPosition.${c}.x);\n float pyWidth = fwidth(worldPosition.${c}.y);\n float centerLineX = 1.0 - smoothstep(0.0, pxWidth, abs(worldPosition.${c}.x));\n float centerLineY = 1.0 - smoothstep(0.0, pyWidth, abs(worldPosition.${c}.y));\n \n if(centerLineX > 0.1) {\n color = uCenterLineColorX;\n outAlpha = max(outAlpha, centerLineX * 0.8);\n } else if(centerLineY > 0.1) {\n color = uCenterLineColorY;\n outAlpha = max(outAlpha, centerLineY * 0.8);\n }\n \n gl_FragColor = vec4(color.rgb, outAlpha);\n if (gl_FragColor.a <= 0.01) discard;\n }\n `,extensions:{derivatives:!0}})),this.frustumCulled=!1}}class ml{constructor({scene:t,camera:n,controls:r,options:i={}}){this.scene=t,this.camera=n,this.controls=r,this.grid=function(t={}){const{size1:n=10,size2:r=10,color:i="white",distance:o=8e3,axes:a="xzy",centerLineColorX:s="red",centerLineColorY:c="green"}=t;return new fl(n,r,new e.Color(i),o,a,s,c)}(i),this.lastCameraPosition=new e.Vector3,this.lastCameraTarget=new e.Vector3,this.actualZoomLevel=1e3,this.scene.add(this.grid)}update(){if(!this.controls||!this.controls.target)return;const e=this.camera.position.distanceTo(this.controls.target),t=this.camera.position.length(),n=this.controls.target.distanceTo(this.lastCameraTarget),r=Math.abs(t-(this.lastCameraPosition.length()||0)),i=Math.max(.05*t,.1),o=n>Math.max(.01*t,.5);r>i||0===this.lastCameraPosition.length()?(this.actualZoomLevel=e,this.lastCameraPosition.copy(this.camera.position),this.lastCameraTarget.copy(this.controls.target)):o&&this.lastCameraTarget.copy(this.controls.target),function(e,t){if(!e||!e.material||!e.material.uniforms)return;const n=t,r=Math.log10(n)-1,i=Math.floor(r),o=r-i,a=Math.pow(10,i),s=Math.pow(10,i+1);e.material.uniforms.uSize1.value=a,e.material.uniforms.uSize2.value=s,e.material.uniforms.uDistance.value=8*n,e.material.uniforms.uAlpha1.value=.5-o,e.material.uniforms.uAlpha2.value=o}(this.grid,this.actualZoomLevel)}dispose(){this.scene.remove(this.grid),this.grid.traverse(e=>{e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}}class gl{constructor(){this._events={}}on(e,t){return this._events[e]||(this._events[e]=[]),this._events[e].push(t),this}once(e,t){const n=(...r)=>{this.off(e,n),t.apply(this,r)};return n.listener=t,this.on(e,n),this}emit(e,...t){if(!this._events[e])return!1;return[...this._events[e]].forEach(e=>{e.apply(this,t)}),!0}off(e,t){if(!this._events[e])return this;if(!t)return delete this._events[e],this;const n=this._events[e].findIndex(e=>e===t||e.listener&&e.listener===t);return-1!==n&&(this._events[e].splice(n,1),0===this._events[e].length&&delete this._events[e]),this}removeAllListeners(e){return e?delete this._events[e]:this._events={},this}}class bl extends gl{constructor(e={}){super(),this.options=Object.assign({target:window,enabledDefault:!0},e),this.shortcuts=new Map,this.enabled=!0,this.pressedKeys=new Set,this._init(),this.options.enabledDefault&&this._setupDefaultShortcuts()}_init(){const e=this.options.target;this._onKeyDown=this._handleKeyDown.bind(this),this._onKeyUp=this._handleKeyUp.bind(this),e.addEventListener("keydown",this._onKeyDown),e.addEventListener("keyup",this._onKeyUp),e.addEventListener("blur",()=>this.pressedKeys.clear())}_setupDefaultShortcuts(){this.register("ctrl+z",()=>this.emit("undo")),this.register("ctrl+y",()=>this.emit("redo")),this.register("ctrl+shift+z",()=>this.emit("redo")),this.register("delete",()=>this.emit("delete")),this.register("backspace",()=>this.emit("delete")),this.register("ctrl+c",()=>this.emit("copy")),this.register("ctrl+v",()=>this.emit("paste")),this.register("ctrl+x",()=>this.emit("cut")),this.register("ctrl+a",e=>{console.log(22),e.preventDefault(),this.emit("selectAll")}),this.register("ctrl+s",e=>{e.preventDefault(),this.emit("save")}),this.register("escape",()=>this.emit("cancel"))}_handleKeyDown(e){if("INPUT"===document.activeElement.tagName||"TEXTAREA"===document.activeElement.tagName||"SELECT"===document.activeElement.tagName||document.activeElement.isContentEditable)return;if(!this.enabled)return;const t=e.key.toLowerCase();this.pressedKeys.add(t);const n=this._buildShortcutKey();if(this.shortcuts.has(n)){e.preventDefault();this.shortcuts.get(n)(e),this.emit("shortcutTriggered",{shortcut:n,event:e})}}_handleKeyUp(e){const t=e.key.toLowerCase();this.pressedKeys.delete(t)}_buildShortcutKey(){const e=[];return(this.pressedKeys.has("control")||this.pressedKeys.has("ctrl"))&&e.push("ctrl"),this.pressedKeys.has("shift")&&e.push("shift"),this.pressedKeys.has("alt")&&e.push("alt"),(this.pressedKeys.has("meta")||this.pressedKeys.has("command"))&&e.push("meta"),this.pressedKeys.forEach(t=>{["control","ctrl","shift","alt","meta","command"].includes(t)||e.push(t)}),e.sort().join("+")}register(e,t){const n=this._normalizeShortcut(e);return this.shortcuts.set(n,t),this.emit("shortcutRegistered",{shortcut:n,original:e}),this}unregister(e){const t=this._normalizeShortcut(e),n=this.shortcuts.delete(t);return n&&this.emit("shortcutUnregistered",{shortcut:t,original:e}),n}_normalizeShortcut(e){const t=e.toLowerCase().split("+").map(e=>{switch(e.trim()){case"command":case"cmd":return"meta";case"control":return"ctrl";case"space":case"spacebar":return" ";case"esc":return"escape";case"ins":return"insert";case"del":return"delete";default:return e.trim()}}),n=[],r=[];t.forEach(e=>{["ctrl","shift","alt","meta"].includes(e)?n.push(e):r.push(e)});const i=[];return["ctrl","shift","alt","meta"].forEach(e=>{n.includes(e)&&i.push(e)}),[...i,...r].join("+")}enable(){this.enabled=!0,this.emit("enabled")}disable(){this.enabled=!1,this.emit("disabled")}isRegistered(e){return this.shortcuts.has(this._normalizeShortcut(e))}getRegisteredShortcuts(){return Array.from(this.shortcuts.keys())}clearAll(){this.shortcuts.clear(),this.emit("allShortcutsCleared")}dispose(){const e=this.options.target;e.removeEventListener("keydown",this._onKeyDown),e.removeEventListener("keyup",this._onKeyUp),this.clearAll(),this.removeAllListeners()}}var yl="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function vl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function xl(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}),n}var wl,El,Tl=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,i,o;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(i=r;0!==i--;)if(!e(t[i],n[i]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(o=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(i=r;0!==i--;)if(!Object.prototype.hasOwnProperty.call(n,o[i]))return!1;for(i=r;0!==i--;){var a=o[i];if(!e(t[a],n[a]))return!1}return!0}return t!=t&&n!=n},Al=vl(Tl),Cl=Object.prototype.toString,Ol=function(e){var t=Cl.call(e),n="[object Arguments]"===t;return n||(n="[object Array]"!==t&&null!==e&&"object"==typeof e&&"number"==typeof e.length&&e.length>=0&&"[object Function]"===Cl.call(e.callee)),n};var kl=Array.prototype.slice,Sl=Ol,Ml=Object.keys,Rl=Ml?function(e){return Ml(e)}:function(){if(El)return wl;var e;if(El=1,!Object.keys){var t=Object.prototype.hasOwnProperty,n=Object.prototype.toString,r=Ol,i=Object.prototype.propertyIsEnumerable,o=!i.call({toString:null},"toString"),a=i.call(function(){},"prototype"),s=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],c=function(e){var t=e.constructor;return t&&t.prototype===e},l={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},u=function(){if("undefined"==typeof window)return!1;for(var e in window)try{if(!l["$"+e]&&t.call(window,e)&&null!==window[e]&&"object"==typeof window[e])try{c(window[e])}catch(e){return!0}}catch(e){return!0}return!1}();e=function(e){var i=null!==e&&"object"==typeof e,l="[object Function]"===n.call(e),h=r(e),d=i&&"[object String]"===n.call(e),p=[];if(!i&&!l&&!h)throw new TypeError("Object.keys called on a non-object");var f=a&&l;if(d&&e.length>0&&!t.call(e,0))for(var m=0;m<e.length;++m)p.push(String(m));if(h&&e.length>0)for(var g=0;g<e.length;++g)p.push(String(g));else for(var b in e)f&&"prototype"===b||!t.call(e,b)||p.push(String(b));if(o)for(var y=function(e){if("undefined"==typeof window||!u)return c(e);try{return c(e)}catch(e){return!1}}(e),v=0;v<s.length;++v)y&&"constructor"===s[v]||!t.call(e,s[v])||p.push(s[v]);return p}}return wl=e}(),Il=Object.keys;Rl.shim=function(){if(Object.keys){var e=function(){var e=Object.keys(arguments);return e&&e.length===arguments.length}(1,2);e||(Object.keys=function(e){return Sl(e)?Il(kl.call(e)):Il(e)})}else Object.keys=Rl;return Object.keys||Rl};var Pl=Rl,_l=Object.defineProperty||!1;if(_l)try{_l({},"a",{value:1})}catch(e){_l=!1}var Nl=_l,Ll=SyntaxError,Dl=TypeError,jl=Object.getOwnPropertyDescriptor;if(jl)try{jl([],"length")}catch(e){jl=null}var Fl=Nl,Ul=Ll,Bl=Dl,zl=jl,Hl=Nl,Vl=function(){return!!Hl};Vl.hasArrayLengthDefineBug=function(){if(!Hl)return null;try{return 1!==Hl([],"length",{value:1}).length}catch(e){return!0}};var Gl=Vl,Wl=Pl,Xl="function"==typeof Symbol&&"symbol"==typeof Symbol("foo"),ql=Object.prototype.toString,Yl=Array.prototype.concat,Kl=function(e,t,n){if(!e||"object"!=typeof e&&"function"!=typeof e)throw new Bl("`obj` must be an object or a function`");if("string"!=typeof t&&"symbol"!=typeof t)throw new Bl("`property` must be a string or a symbol`");if(arguments.length>3&&"boolean"!=typeof arguments[3]&&null!==arguments[3])throw new Bl("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&"boolean"!=typeof arguments[4]&&null!==arguments[4])throw new Bl("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&"boolean"!=typeof arguments[5]&&null!==arguments[5])throw new Bl("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&"boolean"!=typeof arguments[6])throw new Bl("`loose`, if provided, must be a boolean");var r=arguments.length>3?arguments[3]:null,i=arguments.length>4?arguments[4]:null,o=arguments.length>5?arguments[5]:null,a=arguments.length>6&&arguments[6],s=!!zl&&zl(e,t);if(Fl)Fl(e,t,{configurable:null===o&&s?s.configurable:!o,enumerable:null===r&&s?s.enumerable:!r,value:n,writable:null===i&&s?s.writable:!i});else{if(!a&&(r||i||o))throw new Ul("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.");e[t]=n}},Ql=Gl(),$l=function(e,t,n,r){if(t in e)if(!0===r){if(e[t]===n)return}else if("function"!=typeof(i=r)||"[object Function]"!==ql.call(i)||!r())return;var i;Ql?Kl(e,t,n,!0):Kl(e,t,n)},Zl=function(e,t){var n=arguments.length>2?arguments[2]:{},r=Wl(t);Xl&&(r=Yl.call(r,Object.getOwnPropertySymbols(t)));for(var i=0;i<r.length;i+=1)$l(e,r[i],t[r[i]],n[r[i]])};Zl.supportsDescriptors=!!Ql;var Jl=Zl,eu={exports:{}};"undefined"!=typeof self?eu.exports=self:"undefined"!=typeof window?eu.exports=window:eu.exports=Function("return this")();var tu=eu.exports,nu=tu,ru=function(){return"object"==typeof yl&&yl&&yl.Math===Math&&yl.Array===Array?yl:nu},iu=Jl,ou=ru,au=Jl,su=tu,cu=ru,lu=function(){var e=ou();if(iu.supportsDescriptors){var t=Object.getOwnPropertyDescriptor(e,"globalThis");t&&(!t.configurable||!t.enumerable&&t.writable&&globalThis===e)||Object.defineProperty(e,"globalThis",{configurable:!0,enumerable:!1,value:e,writable:!0})}else"object"==typeof globalThis&&globalThis===e||(e.globalThis=e);return e},uu=cu(),hu=function(){return uu};au(hu,{getPolyfill:cu,implementation:su,shim:lu});const du=vl(hu)(),pu={vtkObject:()=>null};function fu(e){if(null==e)return e;if(e.isA)return e;if(!e.vtkClass)return du.console&&du.console.error&&du.console.error("Invalid VTK object"),null;const t=pu[e.vtkClass];if(!t)return du.console&&du.console.error&&du.console.error(`No vtk class found for Object of type ${e.vtkClass}`),null;const n={...e};Object.keys(n).forEach(e=>{n[e]&&"object"==typeof n[e]&&n[e].vtkClass&&(n[e]=fu(n[e]))});const r=t(n);return r&&r.modified&&r.modified(),r}fu.register=function(e,t){pu[e]=t};class mu extends Array{push(){for(let e=0;e<arguments.length;e++)this.includes(arguments[e])||super.push(arguments[e]);return this.length}}let gu=0;const bu=e=>{throw new Error(`Named parameter '${e}' is missing`)},yu=Symbol("void");const vu={};function xu(){}["log","debug","info","warn","error","time","timeEnd","group","groupEnd"].forEach(e=>{vu[e]=xu}),du.console=console.hasOwnProperty("log")?console:vu;const wu={debug:xu,error:du.console.error||xu,info:du.console.info||xu,log:du.console.log||xu,warn:du.console.warn||xu};function Eu(e,t){wu[e]&&(wu[e]=t||xu)}function Tu(){wu.log(...arguments)}function Au(){wu.info(...arguments)}function Cu(){wu.debug(...arguments)}function Ou(){wu.error(...arguments)}function ku(){wu.warn(...arguments)}const Su={};function Mu(e){Su[e]||(wu.error(e),Su[e]=!0)}const Ru=Object.create(null);Ru.Float32Array=Float32Array,Ru.Float64Array=Float64Array,Ru.Uint8Array=Uint8Array,Ru.Int8Array=Int8Array,Ru.Uint16Array=Uint16Array,Ru.Int16Array=Int16Array,Ru.Uint32Array=Uint32Array,Ru.Int32Array=Int32Array,Ru.Uint8ClampedArray=Uint8ClampedArray;try{Ru.BigInt64Array=BigInt64Array,Ru.BigUint64Array=BigUint64Array}catch{}function Iu(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return new(Ru[e]||Float64Array)(...n)}function Pu(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return(Ru[e]||Float64Array).from(...n)}function _u(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Nu(e){return _u("_"===e[0]?e.slice(1):e)}function Lu(e){return e.charAt(0).toLowerCase()+e.slice(1)}function Du(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e3;const r=["TB","GB","MB","KB"];let i=Number(e),o="B";for(;i>n;)i/=n,o=r.pop();return`${i.toFixed(t)} ${o}`}function ju(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:" ";const n=[];let r=e;for(;r>1e3;)n.push(("000"+r%1e3).slice(-3)),r=Math.floor(r/1e3);return r>0&&n.push(r),n.reverse(),n.join(t)}function Fu(e){Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=[].concat(e[t]))})}function Uu(e){return e&&e.isA?e.getState():e}function Bu(e){setTimeout(e,0)}function zu(e,t){const n=performance.now();e.finally(()=>{const e=performance.now()-n;t(e)})}function Hu(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Fu(t);const n=[];if(Number.isInteger(t.mtime)||(t.mtime=++gu),"classHierarchy"in t){if(!(t.classHierarchy instanceof mu)){const e=new mu;for(let n=0;n<t.classHierarchy.length;n++)e.push(t.classHierarchy[n]);t.classHierarchy=e}}else t.classHierarchy=new mu("vtkObject");function r(e){n[e]=null}return e.isDeleted=()=>!!t.deleted,e.modified=r=>{t.deleted?Ou("instance deleted - cannot call any method"):r&&r<e.getMTime()||(t.mtime=++gu,n.forEach(t=>t&&t(e)))},e.onModified=e=>{if(t.deleted)return Ou("instance deleted - cannot call any method"),null;const i=n.length;return n.push(e),function(e){return Object.freeze({unsubscribe:function(){r(e)}})}(i)},e.getMTime=()=>t.mtime,e.isA=e=>{let n=t.classHierarchy.length;for(;n--;)if(t.classHierarchy[n]===e)return!0;return!1},e.getClassName=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return t.classHierarchy[t.classHierarchy.length-1-e]},e.set=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=!1;return Object.keys(n).forEach(a=>{const s=i?null:e[`set${_u(a)}`];s&&Array.isArray(n[a])&&s.length>1?o=s(...n[a])||o:s?o=s(n[a])||o:(-1!==["mtime"].indexOf(a)||r||ku(`Warning: Set value to model directly ${a}, ${n[a]}`),o=t[a]!==n[a]||o,t[a]=n[a])}),o},e.get=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];if(!n.length)return t;const i={};return n.forEach(e=>{i[e]=t[e]}),i},e.getReferenceByName=e=>t[e],e.delete=()=>{Object.keys(t).forEach(e=>delete t[e]),n.forEach((e,t)=>r(t)),t.deleted=!0},e.getState=()=>{if(t.deleted)return null;const n={...t,vtkClass:e.getClassName()};Object.keys(n).forEach(e=>{var t;null===n[e]||void 0===n[e]||"_"===e[0]?delete n[e]:n[e].isA?n[e]=n[e].getState():Array.isArray(n[e])?n[e]=n[e].map(Uu):(t=n[e],Object.values(Ru).some(e=>t instanceof e)&&(n[e]=Array.from(n[e])))});const r={};return Object.keys(n).sort().forEach(e=>{r[e]=n[e]}),r.mtime&&delete r.mtime,r},e.shallowCopy=function(n){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(n.getClassName()!==e.getClassName())throw new Error(`Cannot ShallowCopy ${n.getClassName()} into ${e.getClassName()}`);const i=n.get(),o=Object.keys(t).sort();Object.keys(i).sort().forEach(e=>{const n=o.indexOf(e);-1===n?r&&Cu(`add ${e} in shallowCopy`):o.splice(n,1),t[e]=i[e]}),o.length&&r&&Cu(`Untouched keys: ${o.join(", ")}`),e.modified()},e.toJSON=function(){return e.getState()},e}const Vu={object:(e,t,n)=>function(){return{...t[n.name]}}};function Gu(e,t,n){n.forEach(n=>{if("object"==typeof n){const r=Vu[n.type];e[`get${Nu(n.name)}`]=r?r(e,t,n):()=>t[n.name]}else e[`get${Nu(n)}`]=()=>t[n]})}const Wu={enum(e,t,n){const r=`_on${Nu(n.name)}Changed`;return i=>{if("string"==typeof i){if(void 0!==n.enum[i])return t[n.name]!==n.enum[i]&&(t[n.name]=n.enum[i],e.modified(),!0);throw Ou(`Set Enum with invalid argument ${n}, ${i}`),new RangeError("Set Enum with invalid string argument")}if("number"==typeof i){if(t[n.name]!==i){if(-1!==Object.keys(n.enum).map(e=>n.enum[e]).indexOf(i)){const o=t[n.name];return t[n.name]=i,t[r]?.(e,t,i,o),e.modified(),!0}throw Ou(`Set Enum outside numeric range ${n}, ${i}`),new RangeError("Set Enum outside numeric range")}return!1}throw Ou(`Set Enum with invalid argument (String/Number) ${n}, ${i}`),new TypeError("Set Enum with invalid argument (String/Number)")}},object(e,t,n){1===n.params?.length&&ku('Setter of type "object" with a single "param" field is not supported');const r=`_on${Nu(n.name)}Changed`;return function(){for(var i=arguments.length,o=new Array(i),a=0;a<i;a++)o[a]=arguments[a];let s;if(s=o.length>1&&n.params?.length?n.params.reduce((e,t,n)=>Object.assign(e,{[t]:o[n]}),{}):o[0],!Al(t[n.name],s)){const i=t[n.name];return t[n.name]=s,t[r]?.(e,t,s,i),e.modified(),!0}return!1}}};function Xu(e){if("object"==typeof e){const t=Wu[e.type];if(t)return(n,r)=>t(n,r,e);throw Ou(`No setter for field ${e}`),new TypeError("No setter for field")}return function(t,n){const r=`_on${Nu(e)}Changed`;return function(i){if(n.deleted)return Ou("instance deleted - cannot call any method"),!1;if(n[e]!==i){const o=n[e.name];return n[e]=i,n[r]?.(t,n,i,o),t.modified(),!0}return!1}}}function qu(e,t,n){n.forEach(n=>{"object"==typeof n?e[`set${Nu(n.name)}`]=Xu(n)(e,t):e[`set${Nu(n)}`]=Xu(n)(e,t)})}function Yu(e,t,n){Gu(e,t,n),qu(e,t,n)}function Ku(e,t,n){n.forEach(n=>{e[`get${Nu(n)}`]=()=>t[n]?Array.from(t[n]):t[n],e[`get${Nu(n)}ByReference`]=()=>t[n]})}function Qu(e,t,n,r){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;n.forEach(n=>{if(t[n]&&r&&t[n].length!==r)throw new RangeError(`Invalid initial number of values for array (${n})`);const o=`_on${Nu(n)}Changed`;e[`set${Nu(n)}`]=function(){if(t.deleted)return Ou("instance deleted - cannot call any method"),!1;for(var a=arguments.length,s=new Array(a),c=0;c<a;c++)s[c]=arguments[c];let l,u=s,h=!1;if(1===u.length&&(null==u[0]||u[0].length>=0)&&(u=u[0],h=!0),null==u)l=t[n]!==u;else{if(r&&u.length!==r){if(!(u.length<r&&void 0!==i))throw new RangeError(`Invalid number of values for array setter (${n})`);for(u=Array.from(u),h=!1;u.length<r;)u.push(i)}l=null==t[n]||t[n].length!==u.length;for(let e=0;!l&&e<u.length;++e)l=t[n][e]!==u[e];l&&h&&(u=Array.from(u))}if(l){const r=t[n.name];t[n]=u,t[o]?.(e,t,u,r),e.modified()}return l},e[`set${Nu(n)}From`]=e=>{const r=t[n];e.forEach((e,t)=>{r[t]=e})}})}function $u(e,t,n,r){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;Ku(e,t,n),Qu(e,t,n,r,i)}function Zu(e,t,n){for(let e=0;e<n.length;e++){const r=n[e];void 0!==t[r]&&(t[`_${r}`]=t[r],delete t[r])}}function Ju(e,t,n,r){function i(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;t.deleted?Ou("instance deleted - cannot call any method"):r>=t.numberOfInputs?Ou(`algorithm ${e.getClassName()} only has ${t.numberOfInputs} input ports. To add more input ports, use addInputData()`):(t.inputData[r]!==n||t.inputConnection[r])&&(t.inputData[r]=n,t.inputConnection[r]=null,e.modified&&e.modified())}function o(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(t.deleted)Ou("instance deleted - cannot call any method");else{if(r>=t.numberOfInputs){let n=`algorithm ${e.getClassName()} only has `;return n+=`${t.numberOfInputs}`,n+=" input ports. To add more input ports, use addInputConnection()",void Ou(n)}t.inputData[r]=null,t.inputConnection[r]=n}}function a(){let e=t.numberOfInputs;for(;e&&!t.inputData[e-1]&&!t.inputConnection[e-1];)e--;return e===t.numberOfInputs&&t.numberOfInputs++,e}function s(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return t.deleted?(Ou("instance deleted - cannot call any method"),null):(e.shouldUpdate()&&e.update(),t.output[n])}if(t.inputData?t.inputData=t.inputData.map(fu):t.inputData=[],t.inputConnection?t.inputConnection=t.inputConnection.map(fu):t.inputConnection=[],t.output?t.output=t.output.map(fu):t.output=[],t.inputArrayToProcess?t.inputArrayToProcess=t.inputArrayToProcess.map(fu):t.inputArrayToProcess=[],t.numberOfInputs=n,e.shouldUpdate=()=>{const n=e.getMTime();let i=1/0,o=r;for(;o--;){if(!t.output[o]||t.output[o].isDeleted())return!0;const e=t.output[o].getMTime();if(e<n)return!0;e<i&&(i=e)}for(o=t.numberOfInputs;o--;)if(t.inputConnection[o]?.filter.shouldUpdate()||e.getInputData(o)?.getMTime()>i)return!0;return!1},t.numberOfInputs){let n=t.numberOfInputs;for(;n--;)t.inputData.push(null),t.inputConnection.push(null);e.setInputData=i,e.setInputConnection=o,e.addInputData=function(e){t.deleted?Ou("instance deleted - cannot call any method"):i(e,a())},e.addInputConnection=function(e){t.deleted?Ou("instance deleted - cannot call any method"):o(e,a())},e.getInputData=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return t.inputConnection[e]&&(t.inputData[e]=t.inputConnection[e]()),t.inputData[e]},e.getInputConnection=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return t.inputConnection[e]}}r&&(e.getOutputData=s,e.getOutputPort=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;const n=()=>s(t);return n.filter=e,n}),e.update=()=>{const n=[];if(t.numberOfInputs){let r=0;for(;r<t.numberOfInputs;)n[r]=e.getInputData(r),r++}e.requestData&&e.shouldUpdate()&&e.requestData(n,t.output)},e.getNumberOfInputPorts=()=>t.numberOfInputs,e.getNumberOfOutputPorts=()=>r||t.output.length,e.getInputArrayToProcess=e=>{const n=t.inputArrayToProcess[e],r=t.inputData[e];return n&&r?r[`get${n.fieldAssociation}`]().getArray(n.arrayName):null},e.setInputArrayToProcess=function(e,n,r){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"Scalars";for(;t.inputArrayToProcess.length<e;)t.inputArrayToProcess.push(null);t.inputArrayToProcess[e]={arrayName:n,fieldAssociation:r,attributeType:i}}}const eh=Symbol("Event abort");function th(e,t,n){const r=[],i=e.delete;let o=1;function a(e){for(let t=0;t<r.length;++t){const[n]=r[t];if(n===e)return void r.splice(t,1)}}e[`invoke${Nu(n)}`]=function(){if(t.deleted)return void Ou("instance deleted - cannot call any method");const n=r.slice();for(let t=0;t<n.length;++t){const[,r,i]=n[t];if(r)if(i<0)setTimeout(()=>r.apply(e,arguments),1-i);else{if(r.apply(e,arguments)===eh)break}}},e[`on${Nu(n)}`]=function(e){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!e.apply)return console.error(`Invalid callback for event ${n}`),null;if(t.deleted)return Ou("instance deleted - cannot call any method"),null;const s=o++;return r.push([s,e,i]),r.sort((e,t)=>t[2]-e[2]),function(e){return Object.freeze({unsubscribe:function(){a(e)}})}(s)},e.delete=()=>{i(),r.forEach(e=>{let[t]=e;return a(t)})}}function nh(e,t){const n=function(){const t={};return e(t,{},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),Object.freeze(t)};return t&&fu.register(t,n),n}function rh(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return t.filter(e=>!!e).map(e=>e(...n))}}function ih(e){return e&&e.isA&&e.isA("vtkObject")}function oh(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];if(ih(e)){if(r.indexOf(e)>=0)return n;r.push(e);const i=t(e);void 0!==i&&n.push(i);const o=e.get();Object.keys(o).forEach(e=>{const i=o[e];Array.isArray(i)?i.forEach(e=>{oh(e,t,n,r)}):oh(i,t,n,r)})}return n}function ah(e,t,n){var r=this;let i;const o=function(){for(var o=arguments.length,a=new Array(o),s=0;s<o;s++)a[s]=arguments[s];const c=r,l=n&&!i;clearTimeout(i),i=setTimeout(()=>{i=null,n||e.apply(c,a)},t),l&&e.apply(c,a)};return o.cancel=()=>clearTimeout(i),o}function sh(e,t){let n=!1,r=null;function i(){n=!1,null!==r&&(o(...r),r=null)}function o(){for(var o=arguments.length,a=new Array(o),s=0;s<o;s++)a[s]=arguments[s];n?r=a:(n=!0,e(...a),setTimeout(i,t))}return o}function ch(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};t.keystore=Object.assign(t.keystore||{},n),e.setKey=(e,n)=>{t.keystore[e]=n},e.getKey=e=>t.keystore[e],e.getAllKeys=()=>Object.keys(t.keystore),e.deleteKey=e=>delete t.keystore[e],e.clearKeystore=()=>e.getAllKeys().forEach(e=>delete t.keystore[e])}let lh=1;const uh="__root__";function hh(e,t){ch(e,t);const n=e.delete;t.proxyId=""+lh++,t.ui=JSON.parse(JSON.stringify(t.ui||[])),Gu(e,t,["proxyId","proxyGroup","proxyName"]),Yu(e,t,["proxyManager"]);const r={},i={};function o(e,t){i[t]||(i[t]=[]);const n=i[t];for(let t=0;t<e.length;t++)n.push(e[t].name),r[e[t].name]=e[t],e[t].children&&e[t].children.length&&o(e[t].children,e[t].name)}function a(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:uh;const r=[],o=t.proxyId,s=function(){return i[arguments.length>0&&void 0!==arguments[0]?arguments[0]:uh]}(n)||[];for(let t=0;t<s.length;t++){const n=s[t],i=e[`get${Nu(n)}`],c={id:o,name:n,value:i?i():void 0},l=a(n);l.length&&(c.children=l),r.push(c)}return r}o(t.ui,uh),e.updateUI=n=>{t.ui=JSON.parse(JSON.stringify(n||[])),Object.keys(r).forEach(e=>delete r[e]),Object.keys(i).forEach(e=>delete i[e]),o(t.ui,uh),e.modified()},e.updateProxyProperty=(e,t)=>{const n=r[e];n?Object.assign(n,t):r[e]={...t}},e.activate=()=>{if(t.proxyManager){const n=`setActive${Nu(e.getProxyGroup().slice(0,-1))}`;t.proxyManager[n]&&t.proxyManager[n](e)}},t.propertyLinkSubscribers={},e.registerPropertyLinkForGC=(e,n)=>{n in t.propertyLinkSubscribers||(t.propertyLinkSubscribers[n]=[]),t.propertyLinkSubscribers[n].push(e)},e.gcPropertyLinks=n=>{const r=t.propertyLinkSubscribers[n]||[];for(;r.length;)r.pop().unbind(e)},t.propertyLinkMap={},e.getPropertyLink=function(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t.propertyLinkMap[e])return t.propertyLinkMap[e];let r=null;const i=[];let o=0,a=!1;function s(n){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(a)return null;const c=[];let l=null;for(o=i.length;o--;){const e=i[o];e.instance===n?l=e:c.push(e)}if(!l)return null;const u=l.instance[`get${Nu(l.propertyName)}`]();if(!function(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}return!1}(u,r)||s){for(r=u,a=!0;c.length;){const e=c.pop();e.instance.set({[e.propertyName]:r})}a=!1}return t.propertyLinkMap[e].persistent&&(t.propertyLinkMap[e].value=u),u}function c(e,t){const n=[];for(o=i.length;o--;){const r=i[o];r.instance!==e||r.propertyName!==t&&void 0!==t||(r.subscription.unsubscribe(),n.push(o))}for(;n.length;)i.splice(n.pop(),1)}const l={bind:function(n,r){let o=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const a=n.onModified(s),l=i[0];return i.push({instance:n,propertyName:r,subscription:a}),o&&(t.propertyLinkMap[e].persistent&&void 0!==t.propertyLinkMap[e].value?n.set({[r]:t.propertyLinkMap[e].value}):l&&s(l.instance,!0)),{unsubscribe:()=>c(n,r)}},unbind:c,unsubscribe:function(){for(;i.length;)i.pop().subscription.unsubscribe()},persistent:n};return t.propertyLinkMap[e]=l,l},e.listPropertyNames=()=>a().map(e=>e.name),e.getPropertyByName=e=>a().find(t=>t.name===e),e.getPropertyDomainByName=e=>(r[e]||{}).domain,e.getProxySection=()=>({id:t.proxyId,name:t.proxyGroup,ui:t.ui,properties:a()}),e.delete=()=>{const r=Object.keys(t.propertyLinkMap);let i=r.length;for(;i--;)t.propertyLinkMap[r[i]].unsubscribe();Object.keys(t.propertyLinkSubscribers).forEach(e.gcPropertyLinks),n()},e.getState=()=>null,Bu(function(){if(t.links)for(let n=0;n<t.links.length;n++){const{link:r,property:i,persistent:o,updateOnBind:a,type:s}=t.links[n];if("application"===s){const n=t.proxyManager.getPropertyLink(r,o);e.registerPropertyLinkForGC(n,"application"),n.bind(e,i,a)}}})}function dh(e,t,n){const r=e.delete,i=[],o=Object.keys(n);let a=o.length;for(;a--;){const r=o[a],{modelKey:s,property:c,modified:l=!0}=n[r],u=Nu(c),h=Nu(r);e[`get${h}`]=t[s][`get${u}`],e[`set${h}`]=t[s][`set${u}`],l&&i.push(t[s].onModified(e.modified))}e.delete=()=>{for(;i.length;)i.pop().unsubscribe();r()}}function ph(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};function i(e){const n=Object.keys(e);let r=n.length;for(;r--;){const i=n[r];t[i].set(e[i])}}t.this=e;const o=Object.keys(r);let a=o.length;for(;a--;){const s=o[a];t[s]=r[s];const c=n[s];e[`set${Nu(s)}`]=n=>{if(n!==t[s]){t[s]=n;i(c[n]),e.modified()}}}o.length&&Gu(e,t,o)}function fh(e){let t=0,n=0,r=0,i=0;return"detail"in e&&(n=e.detail),"wheelDelta"in e&&(n=-e.wheelDelta/120),"wheelDeltaY"in e&&(n=-e.wheelDeltaY/120),"wheelDeltaX"in e&&(t=-e.wheelDeltaX/120),"axis"in e&&e.axis===e.HORIZONTAL_AXIS&&(t=n,n=0),r=10*t,i=10*n,"deltaY"in e&&(i=e.deltaY),"deltaX"in e&&(r=e.deltaX),(r||i)&&e.deltaMode&&(1===e.deltaMode?(r*=40,i*=40):(r*=800,i*=800)),r&&!t&&(t=r<1?-1:1),i&&!n&&(n=i<1?-1:1),{spinX:t,spinY:n||t,pixelX:r,pixelY:i||r}}var mh={algo:Ju,capitalize:_u,chain:rh,debounce:ah,enumToString:function(e,t){return Object.keys(e).find(n=>e[n]===t)},event:th,EVENT_ABORT:eh,formatBytesToProperUnit:Du,formatNumbersWithThousandSeparator:ju,get:Gu,getArray:Ku,getCurrentGlobalMTime:function(){return gu},getStateArrayMapFunc:Uu,isVtkObject:ih,keystore:ch,measurePromiseExecution:zu,moveToProtected:Zu,newInstance:nh,newTypedArray:Iu,newTypedArrayFrom:Pu,normalizeWheel:fh,obj:Hu,proxy:hh,proxyPropertyMapping:dh,proxyPropertyState:ph,safeArrays:Fu,set:qu,setArray:Qu,setGet:Yu,setGetArray:$u,setImmediate:Bu,setLoggerFunction:Eu,throttle:sh,traverseInstanceTree:oh,TYPED_ARRAYS:Ru,uncapitalize:Lu,VOID:yu,vtkDebugMacro:Cu,vtkErrorMacro:Ou,vtkInfoMacro:Au,vtkLogMacro:Tu,vtkOnceErrorMacro:Mu,vtkWarningMacro:ku,objectSetterMap:Wu,requiredParam:bu},gh=Object.freeze({__proto__:null,requiredParam:bu,VOID:yu,setLoggerFunction:Eu,vtkLogMacro:Tu,vtkInfoMacro:Au,vtkDebugMacro:Cu,vtkErrorMacro:Ou,vtkWarningMacro:ku,vtkOnceErrorMacro:Mu,TYPED_ARRAYS:Ru,newTypedArray:Iu,newTypedArrayFrom:Pu,capitalize:_u,_capitalize:Nu,uncapitalize:Lu,formatBytesToProperUnit:Du,formatNumbersWithThousandSeparator:ju,setImmediateVTK:Bu,measurePromiseExecution:zu,obj:Hu,get:Gu,set:qu,setGet:Yu,getArray:Ku,setArray:Qu,setGetArray:$u,moveToProtected:Zu,algo:Ju,EVENT_ABORT:eh,event:th,newInstance:nh,chain:rh,isVtkObject:ih,traverseInstanceTree:oh,debounce:ah,throttle:sh,keystore:ch,proxy:hh,proxyPropertyMapping:dh,proxyPropertyState:ph,normalizeWheel:fh,default:mh});const bh={VOID:"",CHAR:"Int8Array",SIGNED_CHAR:"Int8Array",UNSIGNED_CHAR:"Uint8Array",UNSIGNED_CHAR_CLAMPED:"Uint8ClampedArray",SHORT:"Int16Array",UNSIGNED_SHORT:"Uint16Array",INT:"Int32Array",UNSIGNED_INT:"Uint32Array",FLOAT:"Float32Array",DOUBLE:"Float64Array"};var yh={DefaultDataType:bh.FLOAT,DataTypeByteSize:{Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},VtkDataTypes:bh},vh={exports:{}};!function(e,t){function n(e){var t=this,n=function(){var e=4022871197,t=function(t){t=String(t);for(var n=0;n<t.length;n++){var r=.02519603282416938*(e+=t.charCodeAt(n));r-=e=r>>>0,e=(r*=e)>>>0,e+=4294967296*(r-=e)}return 2.3283064365386963e-10*(e>>>0)};return t}();t.next=function(){var e=2091639*t.s0+2.3283064365386963e-10*t.c;return t.s0=t.s1,t.s1=t.s2,t.s2=e-(t.c=0|e)},t.c=1,t.s0=n(" "),t.s1=n(" "),t.s2=n(" "),t.s0-=n(e),t.s0<0&&(t.s0+=1),t.s1-=n(e),t.s1<0&&(t.s1+=1),t.s2-=n(e),t.s2<0&&(t.s2+=1),n=null}function r(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function i(e,t){var i=new n(e),o=t&&t.state,a=i.next;return a.int32=function(){return 4294967296*i.next()|0},a.double=function(){return a()+11102230246251565e-32*(2097152*a()|0)},a.quick=a,o&&("object"==typeof o&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.alea=i}(0,vh);var xh=vh.exports,wh={exports:{}};!function(e,t){function n(e){var t=this,n="";t.x=0,t.y=0,t.z=0,t.w=0,t.next=function(){var e=t.x^t.x<<11;return t.x=t.y,t.y=t.z,t.z=t.w,t.w^=t.w>>>19^e^e>>>8},e===(0|e)?t.x=e:n+=e;for(var r=0;r<n.length+64;r++)t.x^=0|n.charCodeAt(r),t.next()}function r(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t}function i(e,t){var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&("object"==typeof o&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.xor128=i}(0,wh);var Eh=wh.exports,Th={exports:{}};!function(e,t){function n(e){var t=this,n="";t.next=function(){var e=t.x^t.x>>>2;return t.x=t.y,t.y=t.z,t.z=t.w,t.w=t.v,(t.d=t.d+362437|0)+(t.v=t.v^t.v<<4^e^e<<1)|0},t.x=0,t.y=0,t.z=0,t.w=0,t.v=0,e===(0|e)?t.x=e:n+=e;for(var r=0;r<n.length+64;r++)t.x^=0|n.charCodeAt(r),r==n.length&&(t.d=t.x<<10^t.x>>>4),t.next()}function r(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t.v=e.v,t.d=e.d,t}function i(e,t){var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&("object"==typeof o&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.xorwow=i}(0,Th);var Ah=Th.exports,Ch={exports:{}};!function(e,t){function n(e){var t=this;t.next=function(){var e,n,r=t.x,i=t.i;return e=r[i],n=(e^=e>>>7)^e<<24,n^=(e=r[i+1&7])^e>>>10,n^=(e=r[i+3&7])^e>>>3,n^=(e=r[i+4&7])^e<<7,e=r[i+7&7],n^=(e^=e<<13)^e<<9,r[i]=n,t.i=i+1&7,n},function(e,t){var n,r=[];if(t===(0|t))r[0]=t;else for(t=""+t,n=0;n<t.length;++n)r[7&n]=r[7&n]<<15^t.charCodeAt(n)+r[n+1&7]<<13;for(;r.length<8;)r.push(0);for(n=0;n<8&&0===r[n];++n);for(8==n?r[7]=-1:r[n],e.x=r,e.i=0,n=256;n>0;--n)e.next()}(t,e)}function r(e,t){return t.x=e.x.slice(),t.i=e.i,t}function i(e,t){null==e&&(e=+new Date);var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&(o.x&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.xorshift7=i}(0,Ch);var Oh=Ch.exports,kh={exports:{}};!function(e,t){function n(e){var t=this;t.next=function(){var e,n,r=t.w,i=t.X,o=t.i;return t.w=r=r+1640531527|0,n=i[o+34&127],e=i[o=o+1&127],n^=n<<13,e^=e<<17,n^=n>>>15,e^=e>>>12,n=i[o]=n^e,t.i=o,n+(r^r>>>16)|0},function(e,t){var n,r,i,o,a,s=[],c=128;for(t===(0|t)?(r=t,t=null):(t+="\0",r=0,c=Math.max(c,t.length)),i=0,o=-32;o<c;++o)t&&(r^=t.charCodeAt((o+32)%t.length)),0===o&&(a=r),r^=r<<10,r^=r>>>15,r^=r<<4,r^=r>>>13,o>=0&&(a=a+1640531527|0,i=0==(n=s[127&o]^=r+a)?i+1:0);for(i>=128&&(s[127&(t&&t.length||0)]=-1),i=127,o=512;o>0;--o)r=s[i+34&127],n=s[i=i+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[i]=r^n;e.w=a,e.X=s,e.i=i}(t,e)}function r(e,t){return t.i=e.i,t.w=e.w,t.X=e.X.slice(),t}function i(e,t){null==e&&(e=+new Date);var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&(o.X&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.xor4096=i}(0,kh);var Sh=kh.exports,Mh={exports:{}};!function(e,t){function n(e){var t=this,n="";t.next=function(){var e=t.b,n=t.c,r=t.d,i=t.a;return e=e<<25^e>>>7^n,n=n-r|0,r=r<<24^r>>>8^i,i=i-e|0,t.b=e=e<<20^e>>>12^n,t.c=n=n-r|0,t.d=r<<16^n>>>16^i,t.a=i-e|0},t.a=0,t.b=0,t.c=-1640531527,t.d=1367130551,e===Math.floor(e)?(t.a=e/4294967296|0,t.b=0|e):n+=e;for(var r=0;r<n.length+20;r++)t.b^=0|n.charCodeAt(r),t.next()}function r(e,t){return t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t}function i(e,t){var i=new n(e),o=t&&t.state,a=function(){return(i.next()>>>0)/4294967296};return a.double=function(){do{var e=((i.next()>>>11)+(i.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},a.int32=i.next,a.quick=a,o&&("object"==typeof o&&r(o,i),a.state=function(){return r(i,{})}),a}t&&t.exports?t.exports=i:this.tychei=i}(0,Mh);var Rh,Ih=Mh.exports,Ph={exports:{}},_h=xl(Object.freeze({__proto__:null,default:{}}));Rh=Ph,function(e,t,n){var r,i=256,o="random",a=n.pow(i,6),s=n.pow(2,52),c=2*s,l=255;function u(l,u,g){var b=[],y=f(p((u=1==u?{entropy:!0}:u||{}).entropy?[l,m(t)]:null==l?function(){try{var n;return r&&(n=r.randomBytes)?n=n(i):(n=new Uint8Array(i),(e.crypto||e.msCrypto).getRandomValues(n)),m(n)}catch(n){var o=e.navigator,a=o&&o.plugins;return[+new Date,e,a,e.screen,m(t)]}}():l,3),b),v=new h(b),x=function(){for(var e=v.g(6),t=a,n=0;e<s;)e=(e+n)*i,t*=i,n=v.g(1);for(;e>=c;)e/=2,t/=2,n>>>=1;return(e+n)/t};return x.int32=function(){return 0|v.g(4)},x.quick=function(){return v.g(4)/4294967296},x.double=x,f(m(v.S),t),(u.pass||g||function(e,t,r,i){return i&&(i.S&&d(i,v),e.state=function(){return d(v,{})}),r?(n[o]=e,t):e})(x,y,"global"in u?u.global:this==n,u.state)}function h(e){var t,n=e.length,r=this,o=0,a=r.i=r.j=0,s=r.S=[];for(n||(e=[n++]);o<i;)s[o]=o++;for(o=0;o<i;o++)s[o]=s[a=l&a+e[o%n]+(t=s[o])],s[a]=t;(r.g=function(e){for(var t,n=0,o=r.i,a=r.j,s=r.S;e--;)t=s[o=l&o+1],n=n*i+s[l&(s[o]=s[a=l&a+t])+(s[a]=t)];return r.i=o,r.j=a,n})(i)}function d(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function p(e,t){var n,r=[],i=typeof e;if(t&&"object"==i)for(n in e)try{r.push(p(e[n],t-1))}catch(e){}return r.length?r:"string"==i?e:e+"\0"}function f(e,t){for(var n,r=e+"",i=0;i<r.length;)t[l&i]=l&(n^=19*t[l&i])+r.charCodeAt(i++);return m(t)}function m(e){return String.fromCharCode.apply(0,e)}if(f(n.random(),t),Rh.exports){Rh.exports=u;try{r=_h}catch(e){}}else n["seed"+o]=u}("undefined"!=typeof self?self:yl,[],Math);var Nh=xh,Lh=Eh,Dh=Ah,jh=Oh,Fh=Sh,Uh=Ih,Bh=Ph.exports;Bh.alea=Nh,Bh.xor128=Lh,Bh.xorwow=Dh,Bh.xorshift7=jh,Bh.xor4096=Fh,Bh.tychei=Uh;const{vtkErrorMacro:zh,vtkWarningMacro:Hh}=mh;function Vh(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3;const t=Array(e);for(let n=0;n<e;++n)t[n]=0;return t}function Gh(e,t,n){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n}function Wh(e,t,n,r){return r[0]=e[0]+t[0]*n,r[1]=e[1]+t[1]*n,r[2]=e[2]+t[2]*n,r}function Xh(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function qh(e,t,n){const r=e[1]*t[2]-e[2]*t[1],i=e[2]*t[0]-e[0]*t[2],o=e[0]*t[1]-e[1]*t[0];return n[0]=r,n[1]=i,n[2]=o,n}function Yh(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3;switch(t){case 1:return Math.abs(e);case 2:return Math.sqrt(e[0]*e[0]+e[1]*e[1]);case 3:return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);default:{let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}}}function Kh(e,t){return(e[0]-t[0])*(e[0]-t[0])+(e[1]-t[1])*(e[1]-t[1])+(e[2]-t[2])*(e[2]-t[2])}function Qh(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 2===t.length?t[0][0]*t[1][1]-t[1][0]*t[0][1]:4===t.length?t[0]*t[3]-t[1]*t[2]:Number.NaN}function $h(e,t,n){if(2===n){const n=Vh(2),r=Qh(e[0],e[1],e[2],e[3]);return 0===r?0:(n[0]=(e[3]*t[0]-e[1]*t[1])/r,n[1]=(-e[2]*t[0]+e[0]*t[1])/r,t[0]=n[0],t[1]=n[1],1)}if(1===n)return 0===e[0]?0:(t[0]/=e[0],1);const r=Vh(n);return 0===function(e,t,n){let r,i,o,a,s,c,l,u=0;const h=Vh(n);for(r=0;r<n;r++){for(a=0,i=0;i<n;i++)(l=Math.abs(e[r*n+i]))>a&&(a=l);if(0===a)return Hh("Unable to factor linear system"),0;h[r]=1/a}for(i=0;i<n;i++){for(r=0;r<i;r++){for(s=e[r*n+i],o=0;o<r;o++)s-=e[r*n+o]*e[o*n+i];e[r*n+i]=s}for(a=0,r=i;r<n;r++){for(s=e[r*n+i],o=0;o<i;o++)s-=e[r*n+o]*e[o*n+i];e[r*n+i]=s,(c=h[r]*Math.abs(s))>=a&&(a=c,u=r)}if(i!==u){for(o=0;o<n;o++)c=e[u*n+o],e[u*n+o]=e[i*n+o],e[i*n+o]=c;h[u]=h[i]}if(t[i]=u,Math.abs(e[i*n+i])<=1e-12)return Hh("Unable to factor linear system"),0;if(i!==n-1)for(c=1/e[i*n+i],r=i+1;r<n;r++)e[r*n+i]*=c}return 1}(e,r,n)?0:(function(e,t,n,r){let i,o,a,s,c;for(a=-1,i=0;i<r;i++){if(s=t[i],c=n[s],n[s]=n[i],a>=0)for(o=a;o<=i-1;o++)c-=e[i*r+o]*n[o];else 0!==c&&(a=i);n[i]=c}for(i=r-1;i>=0;i--){for(c=n[i],o=i+1;o<r;o++)c-=e[i*r+o]*n[o];n[i]=c/e[i*r+i]}}(e,r,t,n),1)}const{vtkErrorMacro:Zh}=gh,{DefaultDataType:Jh}=yh;function ed(e,t,n){const r=e.length;let i,o,a=Number.MAX_VALUE,s=-Number.MAX_VALUE;for(o=t;o<r;o+=n)if(!Number.isNaN(e[o])){a=e[o],s=a;break}for(;o<r;o+=n)i=e[o],i<a?a=i:i>s&&(s=i);return{min:a,max:s}}function td(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;if(t<0&&n>1){const t=e.length/n,r=new Float64Array(t);for(let i=0,o=0;i<t;++i){for(let t=o+n;o<t;++o)r[i]+=e[o]*e[o];r[i]**=.5}return ed(r,0,1)}return ed(e,t<0?0:t,n)}function nd(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;const n=e||[];for(;n.length<=t;)n.push(null);return n}function rd(e){return Object.prototype.toString.call(e).slice(8,-1)}const id={computeRange:td,createRangeHelper:function(){let e=Number.MAX_VALUE,t=-Number.MAX_VALUE,n=0,r=0;return{add(i){e>i&&(e=i),t<i&&(t=i),n++,r+=i},get:()=>({min:e,max:t,count:n,sum:r,mean:r/n}),getRange:()=>({min:e,max:t})}},fastComputeRange:ed,getDataType:rd,getMaxNorm:function(e){const t=e.getNumberOfComponents();let n=0;const r=new Array(t);for(let i=0;i<e.getNumberOfTuples();++i){e.getTuple(i,r);const o=Yh(r,t);o>n&&(n=o)}return n}};const od={name:"",numberOfComponents:1,dataType:Jh,rangeTuple:[0,0]};function ad(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(Object.assign(t,od,n),Array.isArray(n.values)&&void 0===n.dataType&&console.warn("vtkDataArray.newInstance: no dataType provided, converting to Float32Array"),!t.empty&&!t.values&&!t.size)throw new TypeError("Cannot create vtkDataArray object without: size > 0, values");if(t.values?Array.isArray(t.values)&&(t.values=Pu(t.dataType,t.values)):t.values=Iu(t.dataType,t.size),t.values&&(t.size=t.size??t.values.length,t.dataType=rd(t.values)),Hu(e,t),qu(e,t,["name","numberOfComponents"]),t.size%t.numberOfComponents!==0)throw new RangeError("model.size is not a multiple of model.numberOfComponents");!function(e,t){function n(n){if(n<0)return!1;const r=e.getNumberOfComponents(),i=t.values.length/(r>0?r:1);if(n===i)return!0;if(n>i){const e=t.values;return t.values=Iu(t.dataType,(n+i)*r),t.values.set(e),!0}return t.size>n*r&&(t.size=n*r,e.dataChange()),!0}t.classHierarchy.push("vtkDataArray"),e.dataChange=()=>{t.ranges=null,e.modified()},e.resize=r=>{n(r);const i=r*e.getNumberOfComponents();return t.size!==i&&(t.size=i,e.dataChange(),!0)},e.initialize=()=>{e.resize(0)},e.getElementComponentSize=()=>t.values.BYTES_PER_ELEMENT,e.getComponent=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return t.values[e*t.numberOfComponents+n]},e.setComponent=(n,r,i)=>{i!==t.values[n*t.numberOfComponents+r]&&(t.values[n*t.numberOfComponents+r]=i,e.dataChange())},e.getValue=n=>{const r=n/t.numberOfComponents,i=n%t.numberOfComponents;return e.getComponent(r,i)},e.setValue=(n,r)=>{const i=n/t.numberOfComponents,o=n%t.numberOfComponents;e.setComponent(i,o,r)},e.getData=()=>t.size===t.values.length?t.values:t.values.subarray(0,t.size),e.getRange=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1,r=n;r<0&&(r=1===t.numberOfComponents?0:t.numberOfComponents);let i=null;return t.ranges||(t.ranges=nd(t.ranges,t.numberOfComponents)),i=t.ranges[r],i?(t.rangeTuple[0]=i.min,t.rangeTuple[1]=i.max,t.rangeTuple):(i=td(e.getData(),n,t.numberOfComponents),t.ranges[r]=i,t.rangeTuple[0]=i.min,t.rangeTuple[1]=i.max,t.rangeTuple)},e.setRange=(e,n)=>{t.ranges||(t.ranges=nd(t.ranges,t.numberOfComponents));const r={min:e.min,max:e.max};return t.ranges[n]=r,t.rangeTuple[0]=r.min,t.rangeTuple[1]=r.max,t.rangeTuple},e.getRanges=function(){if(arguments.length>0&&void 0!==arguments[0]&&!arguments[0])return structuredClone(t.ranges);const n=[];for(let r=0;r<t.numberOfComponents;r++){const[t,i]=e.getRange(r),o={min:t,max:i};n.push(o)}if(t.numberOfComponents>1){const[t,r]=e.getRange(-1),i={min:t,max:r};n.push(i)}return n},e.setTuple=(e,n)=>{const r=e*t.numberOfComponents;for(let e=0;e<t.numberOfComponents;e++)t.values[r+e]=n[e]},e.setTuples=(e,n)=>{let r=e*t.numberOfComponents;const i=Math.min(n.length,t.size-r);for(let e=0;e<i;)t.values[r++]=n[e++]},e.insertTuple=(r,i)=>(t.size<=r*t.numberOfComponents&&(t.size=(r+1)*t.numberOfComponents,n(r+1)),e.setTuple(r,i),r),e.insertTuples=(r,i)=>{const o=r+i.length/t.numberOfComponents;return t.size<o*t.numberOfComponents&&(t.size=o*t.numberOfComponents,n(o)),e.setTuples(r,i),o},e.insertNextTuple=n=>{const r=t.size/t.numberOfComponents;return e.insertTuple(r,n)},e.insertNextTuples=n=>{const r=t.size/t.numberOfComponents;return e.insertTuples(r,n)},e.findTuple=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-6;for(let r=0;r<t.size;r+=t.numberOfComponents)if(Math.abs(e[0]-t.values[r])<=n){let i=!0;for(let o=1;o<t.numberOfComponents;++o)if(Math.abs(e[o]-t.values[r+o])>n){i=!1;break}if(i)return r/t.numberOfComponents}return-1},e.getTuple=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];const r=t.numberOfComponents||1,i=e*r;switch(r){case 4:n[3]=t.values[i+3];case 3:n[2]=t.values[i+2];case 2:n[1]=t.values[i+1];case 1:n[0]=t.values[i];break;default:for(let e=r-1;e>=0;--e)n[e]=t.values[i+e]}return n},e.getTuples=(n,r)=>{const i=(n??0)*t.numberOfComponents,o=(r??e.getNumberOfTuples())*t.numberOfComponents,a=e.getData().subarray(i,o);return a.length>0?a:null},e.getTupleLocation=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:1)*t.numberOfComponents},e.getNumberOfComponents=()=>t.numberOfComponents,e.getNumberOfValues=()=>t.size,e.getNumberOfTuples=()=>t.size/t.numberOfComponents,e.getDataType=()=>t.dataType,e.newClone=()=>sd({empty:!0,name:t.name,dataType:t.dataType,numberOfComponents:t.numberOfComponents}),e.getName=()=>(t.name||(e.modified(),t.name=`vtkDataArray${e.getMTime()}`),t.name),e.setData=(n,r)=>{t.values=n,t.size=n.length,t.dataType=rd(n),r&&(t.numberOfComponents=r),t.size%t.numberOfComponents!==0&&(t.numberOfComponents=1),e.dataChange()},e.getState=()=>{if(t.deleted)return null;const n={...t,vtkClass:e.getClassName()};n.values=Array.from(n.values),delete n.buffer,Object.keys(n).forEach(e=>{n[e]||delete n[e]});const r={};return Object.keys(n).sort().forEach(e=>{r[e]=n[e]}),r.mtime&&delete r.mtime,r},e.deepCopy=n=>{const r=e.getDataType(),i=t.values;e.shallowCopy(n),t.ranges=structuredClone(n.getRanges()),i?.length>=n.getNumberOfValues()&&r===n.getDataType()?(i.set(n.getData()),t.values=i,e.dataChange()):e.setData(n.getData().slice())},e.interpolateTuple=(n,r,i,o,a,s)=>{const c=t.numberOfComponents||1;c===r.getNumberOfComponents()&&c===o.getNumberOfComponents()||Zh("numberOfComponents must match");const l=r.getTuple(i),u=o.getTuple(a),h=[];switch(h.length=c,c){case 4:h[3]=l[3]+(u[3]-l[3])*s;case 3:h[2]=l[2]+(u[2]-l[2])*s;case 2:h[1]=l[1]+(u[1]-l[1])*s;case 1:h[0]=l[0]+(u[0]-l[0])*s;break;default:for(let e=0;e<c;e++)h[e]=l[e]+(u[e]-l[e])*s}return e.insertTuple(n,h)}}(e,t)}const sd=nh(ad,"vtkDataArray");var cd={newInstance:sd,extend:ad,...id,...yh};const{vtkErrorMacro:ld}=mh,ud=[1,-1,1,-1,1,-1];const hd={empty:!0,numberOfComponents:3,dataType:bh.FLOAT,bounds:[1,-1,1,-1,1,-1]};function dd(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,hd,n),cd.extend(e,t,n),function(e,t){t.classHierarchy.push("vtkPoints"),e.getNumberOfPoints=e.getNumberOfTuples,e.setNumberOfPoints=function(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3;e.getNumberOfPoints()!==n&&(t.size=n*r,t.values=mh.newTypedArray(t.dataType,t.size),e.setNumberOfComponents(r),e.modified())},e.setPoint=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];e.setTuple(t,r)},e.getPoint=e.getTuple,e.findPoint=e.findTuple,e.insertNextPoint=(t,n,r)=>e.insertNextTuple([t,n,r]),e.getBounds=()=>{if(3===e.getNumberOfComponents()){const n=e.getRange(0);t.bounds[0]=n[0],t.bounds[1]=n[1];const r=e.getRange(1);t.bounds[2]=r[0],t.bounds[3]=r[1];const i=e.getRange(2);return t.bounds[4]=i[0],t.bounds[5]=i[1],t.bounds}if(2!==e.getNumberOfComponents())return ld(`getBounds called on an array with components of\n ${e.getNumberOfComponents()}`),ud;const n=e.getRange(0);t.bounds[0]=n[0],t.bounds[1]=n[1];const r=e.getRange(1);return t.bounds[2]=r[0],t.bounds[3]=r[1],t.bounds[4]=0,t.bounds[5]=0,t.bounds},e.computeBounds=e.getBounds,e.setNumberOfComponents(t.numberOfComponents<2?3:t.numberOfComponents)}(e,t)}var pd={newInstance:mh.newInstance(dd,"vtkPoints"),extend:dd};function fd(e){let t=0;return e.filter((e,n)=>n===t&&(t+=e+1,!0))}function md(e){let t=0;for(let n=0;n<e.length;)n+=e[n]+1,t++;return t}const gd={extractCellSizes:fd,getNumberOfCells:md};function bd(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};cd.extend(e,t,function(e){return{empty:!0,numberOfComponents:1,dataType:bh.UNSIGNED_INT,...e}}(n)),function(e,t){t.classHierarchy.push("vtkCellArray");const n={...e};e.getNumberOfCells=n=>void 0===t.numberOfCells||n?(t.cellSizes?t.numberOfCells=t.cellSizes.length:t.numberOfCells=md(e.getData()),t.numberOfCells):t.numberOfCells,e.getCellSizes=n=>void 0===t.cellSizes||n?(t.cellSizes=fd(e.getData()),t.cellSizes):t.cellSizes,e.resize=r=>{const i=e.getNumberOfTuples();n.resize(r);const o=e.getNumberOfTuples();o<i&&(0===o?(t.numberOfCells=0,t.cellSizes=[]):(t.numberOfCells=void 0,t.cellSizes=void 0))},e.setData=e=>{n.setData(e,1),t.numberOfCells=void 0,t.cellSizes=void 0},e.getCell=e=>{let n=e;const r=t.values[n++];return t.values.subarray(n,n+r)},e.insertNextCell=n=>{const r=e.getNumberOfCells();return e.insertNextTuples([n.length,...n]),++t.numberOfCells,null!=t.cellSizes&&t.cellSizes.push(n.length),r}}(e,t)}var yd={newInstance:mh.newInstance(bd,"vtkCellArray"),extend:bd,...gd};const vd={bounds:[-1,-1,-1,-1,-1,-1],pointsIds:[]};function xd(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,vd,n),mh.obj(e,t),t.points||(t.points=pd.newInstance()),mh.get(e,t,["points","pointsIds"]),function(e,t){t.classHierarchy.push("vtkCell"),e.initialize=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(n){t.pointsIds=n;let r=t.points.getData();r.length!==3*t.pointsIds.length&&(r=mh.newTypedArray(e.getDataType(),3*t.pointsIds.length));const i=e.getData();t.pointsIds.forEach((e,t)=>{let n=3*e,o=3*t;r[o]=i[n],r[++o]=i[++n],r[++o]=i[++n]}),t.points.setData(r)}else{t.points=e,t.pointsIds=new Array(e.getNumberOfPoints());for(let n=e.getNumberOfPoints()-1;n>=0;--n)t.pointsIds[n]=n}},e.getBounds=()=>{const e=t.points.getNumberOfPoints(),n=[];if(e){t.points.getPoint(0,n),t.bounds[0]=n[0],t.bounds[1]=n[0],t.bounds[2]=n[1],t.bounds[3]=n[1],t.bounds[4]=n[2],t.bounds[5]=n[2];for(let r=1;r<e;r++)t.points.getPoint(r,n),t.bounds[0]=n[0]<t.bounds[0]?n[0]:t.bounds[0],t.bounds[1]=n[0]>t.bounds[1]?n[0]:t.bounds[1],t.bounds[2]=n[1]<t.bounds[2]?n[1]:t.bounds[2],t.bounds[3]=n[1]>t.bounds[3]?n[1]:t.bounds[3],t.bounds[4]=n[2]<t.bounds[4]?n[2]:t.bounds[4],t.bounds[5]=n[2]>t.bounds[5]?n[2]:t.bounds[5]}else(r=t.bounds)[0]=1,r[1]=-1,r[2]=1,r[3]=-1,r[4]=1,r[5]=-1;var r;return t.bounds},e.getLength2=()=>{e.getBounds();let n=0,r=0;for(let e=0;e<3;e++)r=t.bounds[2*e+1]-t.bounds[2*e],n+=r*r;return n},e.getParametricDistance=e=>{let t,n=0;for(let r=0;r<3;r++)t=e[r]<0?-e[r]:e[r]>1?e[r]-1:0,t>n&&(n=t);return n},e.getNumberOfPoints=()=>t.points.getNumberOfPoints(),e.deepCopy=e=>{e.initialize(t.points,t.pointsIds)},e.getCellDimension=()=>{},e.intersectWithLine=(e,t,n,r,i,o,a)=>{},e.evaluatePosition=(e,t,n,r,i,o)=>{mh.vtkErrorMacro("vtkCell.evaluatePosition is not implemented.")}}(e,t)}var wd={newInstance:mh.newInstance(xd,"vtkCell"),extend:xd};const Ed={array:null,maxId:0,extend:0};function Td(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Ed,n),mh.obj(e,t),function(e,t){t.classHierarchy.push("vtkCellLinks"),e.buildLinks=n=>{const r=n.getPoints().getNumberOfPoints(),i=n.getNumberOfCells(),o=new Uint32Array(r);if(n.isA("vtkPolyData")){for(let t=0;t<i;++t){const{cellPointIds:r}=n.getCellPoints(t);r.forEach(t=>{e.incrementLinkCount(t)})}e.allocateLinks(r),t.maxId=r-1;for(let t=0;t<i;++t){const{cellPointIds:r}=n.getCellPoints(t);r.forEach(n=>{e.insertCellReference(n,o[n]++,t)})}}else{for(let t=0;t<i;t++)wd.newInstance().getPointsIds().forEach(t=>{e.incrementLinkCount(t)});e.allocateLinks(r),t.maxId=r-1;for(let t=0;t<i;++t)wd.newInstance().getPointsIds().forEach(n=>{e.insertCellReference(n,o[n]++,t)})}},e.allocate=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3;t.array=Array(e).fill().map(()=>({ncells:0,cells:null})),t.extend=n,t.maxId=-1},e.initialize=()=>{t.array=null},e.getLink=e=>t.array[e],e.getNcells=e=>t.array[e].ncells,e.getCells=e=>t.array[e].cells,e.insertNextPoint=e=>{t.array.push({ncells:e,cells:Array(e)}),++t.maxId},e.insertNextCellReference=(e,n)=>{t.array[e].cells[t.array[e].ncells++]=n},e.deletePoint=e=>{t.array[e].ncells=0,t.array[e].cells=null},e.removeCellReference=(e,n)=>{t.array[n].cells=t.array[n].cells.filter(t=>t!==e),t.array[n].ncells=t.array[n].cells.length},e.addCellReference=(e,n)=>{t.array[n].cells[t.array[n].ncells++]=e},e.resizeCellList=(e,n)=>{t.array[e].cells.length=n},e.squeeze=()=>{!function(e,t){let n=t;for(t>=e.array.length&&(n+=e.array.length);n>e.array.length;)e.array.push({ncells:0,cells:null});e.array.length=n}(t,t.maxId+1)},e.reset=()=>{t.maxId=-1},e.deepCopy=e=>{t.array=[...e.array],t.extend=e.extend,t.maxId=e.maxId},e.incrementLinkCount=e=>{++t.array[e].ncells},e.allocateLinks=e=>{for(let n=0;n<e;++n)t.array[n].cells=new Array(t.array[n].ncells)},e.insertCellReference=(e,n,r)=>{t.array[e].cells[n]=r}}(e,t)}var Ad={newInstance:mh.newInstance(Td,"vtkCellLinks"),extend:Td};const Cd=0,Od=1,kd=2,Sd=3,Md=4,Rd=5,Id=6,Pd=7,_d=9,Nd=21,Ld=41,Dd=42,jd=["vtkEmptyCell","vtkVertex","vtkPolyVertex","vtkLine","vtkPolyLine","vtkTriangle","vtkTriangleStrip","vtkPolygon","vtkPixel","vtkQuad","vtkTetra","vtkVoxel","vtkHexahedron","vtkWedge","vtkPyramid","vtkPentagonalPrism","vtkHexagonalPrism","UnknownClass","UnknownClass","UnknownClass","UnknownClass","vtkQuadraticEdge","vtkQuadraticTriangle","vtkQuadraticQuad","vtkQuadraticTetra","vtkQuadraticHexahedron","vtkQuadraticWedge","vtkQuadraticPyramid","vtkBiQuadraticQuad","vtkTriQuadraticHexahedron","vtkQuadraticLinearQuad","vtkQuadraticLinearWedge","vtkBiQuadraticQuadraticWedge","vtkBiQuadraticQuadraticHexahedron","vtkBiQuadraticTriangle","vtkCubicLine","vtkQuadraticPolygon","UnknownClass","UnknownClass","UnknownClass","UnknownClass","vtkConvexPointSet","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","UnknownClass","vtkParametricCurve","vtkParametricSurface","vtkParametricTriSurface","vtkParametricQuadSurface","vtkParametricTetraRegion","vtkParametricHexRegion","UnknownClass","UnknownClass","UnknownClass","vtkHigherOrderEdge","vtkHigherOrderTriangle","vtkHigherOrderQuad","vtkHigherOrderPolygon","vtkHigherOrderTetrahedron","vtkHigherOrderWedge","vtkHigherOrderPyramid","vtkHigherOrderHexahedron"];const Fd={getClassNameFromTypeId:function(e){return e<jd.length?jd[e]:"UnknownClass"},getTypeIdFromClassName:function(e){return jd.findIndex(e)},isLinear:function(e){return e<Nd||e===Ld||e===Dd},hasSubCells:function(e){return e===Id||e===Md||e===kd}};const Ud={size:0,maxId:-1,extend:1e3};function Bd(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Ud,n),mh.obj(e,t),mh.get(e,t,["size","maxId","extend"]),mh.getArray(e,t,["typeArray","locationArray"]),function(e,t){t.classHierarchy.push("vtkCellTypes"),e.allocate=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:512,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3;t.size=e>0?e:1,t.extend=n>0?n:1,t.maxId=-1,t.typeArray=new Uint8Array(e),t.locationArray=new Uint32Array(e)},e.insertCell=(e,n,r)=>{t.typeArray[e]=n,t.locationArray[e]=r,e>t.maxId&&(t.maxId=e)},e.insertNextCell=(n,r)=>(e.insertCell(++t.maxId,n,r),t.maxId),e.setCellTypes=(e,n,r)=>{t.size=e,t.typeArray=n,t.locationArray=r,t.maxId=e-1},e.getCellLocation=e=>t.locationArray[e],e.deleteCell=e=>{t.typeArray[e]=Cd},e.getNumberOfTypes=()=>t.maxId+1,e.isType=t=>{const n=e.getNumberOfTypes();for(let r=0;r<n;++r)if(t===e.getCellType(r))return!0;return!1},e.insertNextType=t=>e.insertNextCell(t,-1),e.getCellType=e=>t.typeArray[e],e.reset=()=>{t.maxId=-1},e.deepCopy=n=>{e.allocate(n.getSize(),n.getExtend()),t.typeArray.set(n.getTypeArray()),t.locationArray.set(n.getLocationArray()),t.maxId=n.getMaxId()}}(e,t)}var zd={newInstance:mh.newInstance(Bd,"vtkCellTypes"),extend:Bd,...Fd};var Hd={IntersectionState:{NO_INTERSECTION:0,YES_INTERSECTION:1,ON_LINE:2}},Vd="undefined"!=typeof Float32Array?Float32Array:Array;function Gd(){var e=new Vd(3);return Vd!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Wd(e,t,n){var r=new Vd(3);return r[0]=e,r[1]=t,r[2]=n,r}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function Xd(){var e=new Vd(4);return Vd!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function qd(e,t,n,r){var i,o,a,s,c,l=t[0],u=t[1],h=t[2],d=t[3],p=n[0],f=n[1],m=n[2],g=n[3];return(o=l*p+u*f+h*m+d*g)<0&&(o=-o,p=-p,f=-f,m=-m,g=-g),1-o>1e-6?(i=Math.acos(o),a=Math.sin(i),s=Math.sin((1-r)*i)/a,c=Math.sin(r*i)/a):(s=1-r,c=r),e[0]=s*l+c*p,e[1]=s*u+c*f,e[2]=s*h+c*m,e[3]=s*d+c*g,e}Gd(),function(){var e,t=(e=new Vd(4),Vd!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var Yd;Gd(),Wd(1,0,0),Wd(0,1,0),function(){var e=Xd(),t=Xd()}(),Yd=new Vd(9),Vd!=Float32Array&&(Yd[1]=0,Yd[2]=0,Yd[3]=0,Yd[5]=0,Yd[6]=0,Yd[7]=0),Yd[0]=1,Yd[4]=1,Yd[8]=1;const{IntersectionState:Kd}=Hd;function Qd(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;const i={t:Number.MIN_VALUE,distance:0},o=[];let a;o[0]=n[0]-t[0],o[1]=n[1]-t[1],o[2]=n[2]-t[2];const s=o[0]*(e[0]-t[0])+o[1]*(e[1]-t[1])+o[2]*(e[2]-t[2]),c=Xh(o,o);let l=1e-5*s;return 0!==c&&(i.t=s/c),l<0&&(l=-l),-l<c&&c<l||c<=0||i.t<0?a=t:i.t>1?a=n:(a=o,o[0]=t[0]+i.t*o[0],o[1]=t[1]+i.t*o[1],o[2]=t[2]+i.t*o[2]),r&&(r[0]=a[0],r[1]=a[1],r[2]=a[2]),i.distance=Kh(a,e),i}function $d(e,t,n,r,i,o){const a=[],s=[],c=[];i[0]=0,o[0]=0,Gh(t,e,a),Gh(r,n,s),Gh(n,e,c);const l=[Xh(a,a),-Xh(a,s),-Xh(a,s),Xh(s,s)],u=[];if(u[0]=Xh(a,c),u[1]=-Xh(s,c),0===$h(l,u,2)){let a=Number.MAX_VALUE;const s=[e,t,n,r],c=[n,n,e,e],l=[r,r,t,t];let u;o[0],o[0],i[0],i[0],i[0],i[0],o[0],o[0];for(let e=0;e<4;e++)u=Qd(s[e],c[e],l[e]),u.distance<a&&(a=u.distance,u.t);return Kd.ON_LINE}return i[0]=u[0],o[0]=u[1],i[0]>=0&&i[0]<=1&&o[0]>=0&&o[0]<=1?Kd.YES_INTERSECTION:Kd.NO_INTERSECTION}const Zd={distanceToLine:Qd,intersection:$d};const Jd={orientations:null};function ep(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Jd,n),wd.extend(e,t,n),mh.setGet(e,t,["orientations"]),function(e,t){t.classHierarchy.push("vtkLine"),e.getCellDimension=()=>1,e.intersectWithLine=(e,n,r,i,o)=>{const a={intersect:0,t:Number.MAX_VALUE,subId:0,betweenPoints:null};o[1]=0,o[2]=0;const s=[],c=[],l=[];t.points.getPoint(0,c),t.points.getPoint(1,l);const u=[],h=[],d=$d(e,n,c,l,u,h);var p;if(a.t=u[0],a.betweenPoints=(p=a.t)>=0&&p<=1,o[0]=h[0],d===Kd.YES_INTERSECTION){for(let t=0;t<3;t++)i[t]=c[t]+o[0]*(l[t]-c[t]),s[t]=e[t]+a.t*(n[t]-e[t]);if(Kh(i,s)<=r*r)return a.intersect=1,a}else{let t;if(a.t<0)return t=Qd(e,c,l,i),t.distance<=r*r?(a.t=0,a.intersect=1,a.betweenPoints=!0,a):a;if(a.t>1)return t=Qd(n,c,l,i),t.distance<=r*r?(a.t=1,a.intersect=1,a.betweenPoints=!0,a):a;if(o[0]<0)return o[0]=0,t=Qd(c,e,n,i),a.t=t.t,t.distance<=r*r?(a.intersect=1,a):a;if(o[0]>1)return o[0]=1,t=Qd(l,e,n,i),a.t=t.t,t.distance<=r*r?(a.intersect=1,a):a}return a},e.evaluateLocation=(e,n,r)=>{const i=[],o=[];t.points.getPoint(0,i),t.points.getPoint(1,o);for(let t=0;t<3;t++)n[t]=i[t]+e[0]*(o[t]-i[t]);r[0]=1-e[0],r[1]=e[0]},e.evaluateOrientation=(e,n,r)=>!!t.orientations&&(qd(n,t.orientations[0],t.orientations[1],e[0]),r[0]=1-e[0],r[1]=e[0],!0)}(e,t)}var tp={newInstance:mh.newInstance(ep,"vtkLine"),extend:ep,...Zd,...Hd};const{vtkErrorMacro:np,vtkWarningMacro:rp}=mh;const ip={arrays:[],copyFieldFlags:[],doCopyAllOn:!0,doCopyAllOff:!1};function op(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,ip,n),mh.obj(e,t),function(e,t){t.classHierarchy.push("vtkFieldData");const n=e.getState;t.arrays&&(t.arrays=t.arrays.map(e=>({data:fu(e.data)}))),e.initialize=()=>{e.initializeFields(),e.copyAllOn(),e.clearFieldFlags()},e.initializeFields=()=>{t.arrays=[],t.copyFieldFlags={},e.modified()},e.copyStructure=n=>{e.initializeFields(),t.copyFieldFlags=n.getCopyFieldFlags().map(e=>e),t.arrays=n.arrays().map(e=>({array:e}))},e.getNumberOfArrays=()=>t.arrays.length,e.getNumberOfActiveArrays=()=>t.arrays.length,e.addArray=n=>{const r=n.getName(),{array:i,index:o}=e.getArrayWithIndex(r);return null!=i?(t.arrays[o]={data:n},o):(t.arrays=[].concat(t.arrays,{data:n}),t.arrays.length-1)},e.removeAllArrays=()=>{t.arrays=[]},e.removeArray=n=>{const r=t.arrays.findIndex(e=>e.data.getName()===n);return e.removeArrayByIndex(r)},e.removeArrayByIndex=e=>-1!==e&&e<t.arrays.length&&(t.arrays.splice(e,1),!0),e.getArrays=()=>t.arrays.map(e=>e.data),e.getArray=t=>"number"==typeof t?e.getArrayByIndex(t):e.getArrayByName(t),e.getArrayByName=e=>t.arrays.reduce((t,n,r)=>n.data.getName()===e?n.data:t,null),e.getArrayWithIndex=e=>{const n=t.arrays.findIndex(t=>t.data.getName()===e);return{array:-1!==n?t.arrays[n].data:null,index:n}},e.getArrayByIndex=e=>e>=0&&e<t.arrays.length?t.arrays[e].data:null,e.hasArray=t=>e.getArrayWithIndex(t).index>=0,e.getArrayName=e=>{const n=t.arrays[e];return n?n.data.getName():""},e.getCopyFieldFlags=()=>t.copyFieldFlags,e.getFlag=e=>t.copyFieldFlags[e],e.passData=function(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1;n.getArrays().forEach(o=>{const a=e.getFlag(o.getName());if(!1!==a&&(!t.doCopyAllOff||!0===a)&&o){let t=e.getArrayByName(o.getName());if(t)if(o.getNumberOfComponents()===t.getNumberOfComponents())if(r>-1&&r<o.getNumberOfTuples()){const e=i>-1?i:r;t.insertTuple(e,o.getTuple(r))}else t.insertTuples(0,o.getTuples());else np("Unhandled case in passData");else if(r<0||r>o.getNumberOfTuples())e.addArray(o),n.getAttributes(o).forEach(t=>{e.setAttribute(o,t)});else{const a=o.getNumberOfComponents();let s=o.getNumberOfValues();const c=i>-1?i:r;s<=c*a&&(s=(c+1)*a),t=cd.newInstance({name:o.getName(),dataType:o.getDataType(),numberOfComponents:a,values:mh.newTypedArray(o.getDataType(),s),size:0}),t.insertTuple(c,o.getTuple(r)),e.addArray(t),n.getAttributes(o).forEach(n=>{e.setAttribute(t,n)})}}})},e.interpolateData=function(n){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:-1,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:.5;n.getArrays().forEach(s=>{const c=e.getFlag(s.getName());if(!1!==c&&(!t.doCopyAllOff||!0===c)&&s){let t=e.getArrayByName(s.getName());if(t)if(s.getNumberOfComponents()===t.getNumberOfComponents())if(r>-1&&r<s.getNumberOfTuples()){const e=o>-1?o:r;t.interpolateTuple(e,s,r,s,i,a),rp("Unexpected case in interpolateData")}else t.insertTuples(s.getTuples());else np("Unhandled case in interpolateData");else if(r<0||i<0||r>s.getNumberOfTuples())e.addArray(s),n.getAttributes(s).forEach(t=>{e.setAttribute(s,t)});else{const c=s.getNumberOfComponents();let l=s.getNumberOfValues();const u=o>-1?o:r;l<=u*c&&(l=(u+1)*c),t=cd.newInstance({name:s.getName(),dataType:s.getDataType(),numberOfComponents:c,values:mh.newTypedArray(s.getDataType(),l),size:0}),t.interpolateTuple(u,s,r,s,i,a),e.addArray(t),n.getAttributes(s).forEach(n=>{e.setAttribute(t,n)})}}})},e.copyFieldOn=e=>{t.copyFieldFlags[e]=!0},e.copyFieldOff=e=>{t.copyFieldFlags[e]=!1},e.copyAllOn=()=>{t.doCopyAllOn&&!t.doCopyAllOff||(t.doCopyAllOn=!0,t.doCopyAllOff=!1,e.modified())},e.copyAllOff=()=>{!t.doCopyAllOn&&t.doCopyAllOff||(t.doCopyAllOn=!1,t.doCopyAllOff=!0,e.modified())},e.clearFieldFlags=()=>{t.copyFieldFlags={}},e.deepCopy=e=>{t.arrays=e.getArrays().map(e=>{const t=e.newClone();return t.deepCopy(e),{data:t}})},e.copyFlags=e=>e.getCopyFieldFlags().map(e=>e),e.reset=()=>t.arrays.forEach(e=>e.data.reset()),e.getMTime=()=>t.arrays.reduce((e,t)=>t.data.getMTime()>e?t.data.getMTime():e,t.mtime),e.getNumberOfComponents=()=>t.arrays.reduce((e,t)=>e+t.data.getNumberOfComponents(),0),e.getNumberOfTuples=()=>t.arrays.length>0?t.arrays[0].getNumberOfTuples():0,e.getState=()=>{const e=n();return e&&(e.arrays=t.arrays.map(e=>({data:e.data.getState()}))),e}}(e,t)}var ap={newInstance:mh.newInstance(op,"vtkFieldData"),extend:op};var sp={AttributeCopyOperations:{COPYTUPLE:0,INTERPOLATE:1,PASSDATA:2,ALLCOPY:3},AttributeLimitTypes:{MAX:0,EXACT:1,NOLIMIT:2},AttributeTypes:{SCALARS:0,VECTORS:1,NORMALS:2,TCOORDS:3,TENSORS:4,GLOBALIDS:5,PEDIGREEIDS:6,EDGEFLAG:7,NUM_ATTRIBUTES:8},CellGhostTypes:{DUPLICATECELL:1,HIGHCONNECTIVITYCELL:2,LOWCONNECTIVITYCELL:4,REFINEDCELL:8,EXTERIORCELL:16,HIDDENCELL:32},DesiredOutputPrecision:{DEFAULT:0,SINGLE:1,DOUBLE:2},PointGhostTypes:{DUPLICATEPOINT:1,HIDDENPOINT:2},ghostArrayName:"vtkGhostType"};const{AttributeTypes:cp,AttributeCopyOperations:lp}=sp,{vtkWarningMacro:up}=mh;const hp={activeScalars:-1,activeVectors:-1,activeTensors:-1,activeNormals:-1,activeTCoords:-1,activeGlobalIds:-1,activePedigreeIds:-1};function dp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,hp,n),ap.extend(e,t,n),mh.setGet(e,t,["activeScalars","activeNormals","activeTCoords","activeVectors","activeTensors","activeGlobalIds","activePedigreeIds"]),t.arrays||(t.arrays={}),function(e,t){const n=["Scalars","Vectors","Normals","TCoords","Tensors","GlobalIds","PedigreeIds"];function r(e){let t=n.find(t=>cp[t.toUpperCase()]===e||"number"!=typeof e&&t.toLowerCase()===e.toLowerCase());return void 0===t&&(t=null),t}t.classHierarchy.push("vtkDataSetAttributes");const i={...e};e.checkNumberOfComponents=e=>!0,e.setAttribute=(n,i)=>{const o=r(i);if(n&&"PEDIGREEIDS"===o.toUpperCase()&&!n.isA("vtkDataArray"))return up(`Cannot set attribute ${o}. The attribute must be a vtkDataArray.`),-1;if(n&&!e.checkNumberOfComponents(n,o))return up(`Cannot set attribute ${o}. Incorrect number of components.`),-1;let a=t[`active${o}`];if(a>=0&&a<t.arrays.length){if(t.arrays[a]===n)return a;e.removeArrayByIndex(a)}return n?(a=e.addArray(n),t[`active${o}`]=a):t[`active${o}`]=-1,e.modified(),t[`active${o}`]},e.getAttributes=t=>n.filter(n=>e[`get${n}`]()===t),e.setActiveAttributeByName=(t,n)=>e.setActiveAttributeByIndex(e.getArrayWithIndex(t).index,n),e.setActiveAttributeByIndex=(n,i)=>{const o=r(i);if(n>=0&&n<t.arrays.length){if("PEDIGREEIDS"!==o.toUpperCase()){const t=e.getArrayByIndex(n);if(!t.isA("vtkDataArray"))return up(`Cannot set attribute ${o}. Only vtkDataArray subclasses can be set as active attributes.`),-1;if(!e.checkNumberOfComponents(t,o))return up(`Cannot set attribute ${o}. Incorrect number of components.`),-1}return t[`active${o}`]=n,e.modified(),n}return-1===n&&(t[`active${o}`]=n,e.modified()),-1},e.getActiveAttribute=t=>{const n=r(t);return e[`get${n}`]()},e.removeAllArrays=()=>{n.forEach(e=>{t[`active${e}`]=-1}),i.removeAllArrays()},e.removeArrayByIndex=e=>(-1!==e&&n.forEach(n=>{e===t[`active${n}`]?t[`active${n}`]=-1:e<t[`active${n}`]&&(t[`active${n}`]-=1)}),i.removeArrayByIndex(e)),n.forEach(n=>{const r=`active${n}`;e[`get${n}`]=()=>e.getArrayByIndex(t[r]),e[`set${n}`]=t=>e.setAttribute(t,n),e[`setActive${n}`]=t=>e.setActiveAttributeByIndex(e.getArrayWithIndex(t).index,n),e[`copy${n}Off`]=()=>{const e=n.toUpperCase();t.copyAttributeFlags[lp.PASSDATA][cp[e]]=!1},e[`copy${n}On`]=()=>{const e=n.toUpperCase();t.copyAttributeFlags[lp.PASSDATA][cp[e]]=!0}}),e.initializeAttributeCopyFlags=()=>{t.copyAttributeFlags=[],Object.keys(lp).filter(e=>"ALLCOPY"!==e).forEach(e=>{t.copyAttributeFlags[lp[e]]=Object.keys(cp).filter(e=>"NUM_ATTRIBUTES"!==e).reduce((e,t)=>(e[cp[t]]=!0,e),[])}),t.copyAttributeFlags[lp.COPYTUPLE][cp.GLOBALIDS]=!1,t.copyAttributeFlags[lp.INTERPOLATE][cp.GLOBALIDS]=!1,t.copyAttributeFlags[lp.COPYTUPLE][cp.PEDIGREEIDS]=!1},e.initialize=mh.chain(e.initialize,e.initializeAttributeCopyFlags),t.dataArrays&&Object.keys(t.dataArrays).length&&Object.keys(t.dataArrays).forEach(n=>{t.dataArrays[n].ref||"vtkDataArray"!==t.dataArrays[n].type||e.addArray(cd.newInstance(t.dataArrays[n]))});const o=e.shallowCopy;e.shallowCopy=(e,n)=>{o(e,n),t.arrays=e.getArrays().map(e=>{const t=e.newClone();return t.shallowCopy(e,n),{data:t}})},e.initializeAttributeCopyFlags()}(e,t)}var pp={newInstance:mh.newInstance(dp,"vtkDataSetAttributes"),extend:dp,...sp};var fp={FieldDataTypes:{UNIFORM:0,DATA_OBJECT_FIELD:0,COORDINATE:1,POINT_DATA:1,POINT:2,POINT_FIELD_DATA:2,CELL:3,CELL_FIELD_DATA:3,VERTEX:4,VERTEX_FIELD_DATA:4,EDGE:5,EDGE_FIELD_DATA:5,ROW:6,ROW_DATA:6},FieldAssociations:{FIELD_ASSOCIATION_POINTS:0,FIELD_ASSOCIATION_CELLS:1,FIELD_ASSOCIATION_NONE:2,FIELD_ASSOCIATION_POINTS_THEN_CELLS:3,FIELD_ASSOCIATION_VERTICES:4,FIELD_ASSOCIATION_EDGES:5,FIELD_ASSOCIATION_ROWS:6,NUMBER_OF_ASSOCIATIONS:7}};const mp=["pointData","cellData","fieldData"];const gp={};function bp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,gp,n),mh.obj(e,t),mh.setGet(e,t,mp),function(e,t){t.classHierarchy.push("vtkDataSet"),mp.forEach(e=>{t[e]?t[e]=fu(t[e]):t[e]=pp.newInstance()});const n=e.shallowCopy;e.shallowCopy=function(e){n(e,arguments.length>1&&void 0!==arguments[1]&&arguments[1]),mp.forEach(n=>{t[n]=pp.newInstance(),t[n].shallowCopy(e.getReferenceByName(n))})}}(e,t)}var yp={newInstance:mh.newInstance(bp,"vtkDataSet"),extend:bp,...fp};const vp={};function xp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,vp,n),yp.extend(e,t,n),mh.setGet(e,t,["points"]),function(e,t){t.classHierarchy.push("vtkPointSet"),t.points?t.points=fu(t.points):t.points=pd.newInstance(),e.getNumberOfPoints=()=>t.points.getNumberOfPoints(),e.getBounds=()=>t.points.getBounds(),e.computeBounds=()=>{e.getBounds()};const n=e.shallowCopy;e.shallowCopy=function(e){n(e,arguments.length>1&&void 0!==arguments[1]&&arguments[1]),t.points=pd.newInstance(),t.points.shallowCopy(e.getPoints())}}(e,t)}var wp={newInstance:mh.newInstance(xp,"vtkPointSet"),extend:xp};const Ep={};function Tp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Ep,n),mh.obj(e,t),mh.setGet(e,t,["transform"]),function(e,t){t.classHierarchy.push("vtkImplicitFunction"),e.functionValue=n=>{if(!t.transform)return e.evaluateFunction(n);const r=[];return t.transform.transformPoint(n,r),e.evaluateFunction(r)},e.evaluateFunction=e=>{mh.vtkErrorMacro("not implemented")}}(e,t)}var Ap={newInstance:mh.newInstance(Tp,"vtkImplicitFunction"),extend:Tp};const Cp=1e-6,Op="coincide",kp="disjoint";function Sp(e,t,n){const r=n[0]*(e[0]-t[0])+n[1]*(e[1]-t[1])+n[2]*(e[2]-t[2]);return Math.abs(r)}function Mp(e,t,n,r){const i=[];Gh(e,t,i);const o=Xh(n,i);r[0]=e[0]-o*n[0],r[1]=e[1]-o*n[1],r[2]=e[2]-o*n[2]}function Rp(e,t,n){const r=Xh(e,t);let i=Xh(t,t);return 0===i&&(i=1),n[0]=e[0]-r*t[0]/i,n[1]=e[1]-r*t[1]/i,n[2]=e[2]-r*t[2]/i,n}function Ip(e,t,n,r){const i=[];Gh(e,t,i);const o=Xh(n,i),a=Xh(n,n);0!==a?(r[0]=e[0]-o*n[0]/a,r[1]=e[1]-o*n[1]/a,r[2]=e[2]-o*n[2]/a):(r[0]=e[0],r[1]=e[1],r[2]=e[2])}function Pp(e,t,n,r){const i={intersection:!1,betweenPoints:!1,t:Number.MAX_VALUE,x:[]},o=[],a=[];Gh(t,e,o),Gh(n,e,a);const s=Xh(r,a),c=Xh(r,o);let l,u;return l=c<0?-c:c,u=s<0?-s*Cp:s*Cp,l<=u||(i.t=s/c,i.x[0]=e[0]+i.t*o[0],i.x[1]=e[1]+i.t*o[1],i.x[2]=e[2]+i.t*o[2],i.intersection=!0,i.betweenPoints=i.t>=0&&i.t<=1),i}function _p(e,t,n,r){const i={intersection:!1,l0:[],l1:[],error:null},o=[];qh(t,r,o);const a=o.map(e=>Math.abs(e));if(a[0]+a[1]+a[2]<Cp){const r=[];return Gh(e,n,r),0===Xh(t,r)?i.error=Op:i.error=kp,i}let s;s=a[0]>a[1]&&a[0]>a[2]?"x":a[1]>a[2]?"y":"z";const c=[],l=-Xh(t,e),u=-Xh(r,n);switch(s){case"x":c[0]=0,c[1]=(u*t[2]-l*r[2])/o[0],c[2]=(l*r[1]-u*t[1])/o[0];break;case"y":c[0]=(l*r[2]-u*t[2])/o[1],c[1]=0,c[2]=(u*t[0]-l*r[0])/o[1];break;case"z":c[0]=(u*t[1]-l*r[1])/o[2],c[1]=(l*r[0]-u*t[0])/o[2],c[2]=0}return i.l0=c,function(e,t,n){n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2]}(c,o,i.l1),i.intersection=!0,i}const Np={evaluate:function(e,t,n){return e[0]*(n[0]-t[0])+e[1]*(n[1]-t[1])+e[2]*(n[2]-t[2])},distanceToPlane:Sp,projectPoint:Mp,projectVector:Rp,generalizedProjectPoint:Ip,intersectWithLine:Pp,intersectWithPlane:_p,DISJOINT:kp,COINCIDE:Op};const Lp={normal:[0,0,1],origin:[0,0,0]};function Dp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,Lp,n),Ap.extend(e,t,n),mh.setGetArray(e,t,["normal","origin"],3),function(e,t){t.classHierarchy.push("vtkPlane"),e.distanceToPlane=e=>Sp(e,t.origin,t.normal),e.projectPoint=(e,n)=>{Mp(e,t.origin,t.normal,n)},e.projectVector=(e,n)=>Rp(e,t.normal,n),e.push=e=>{if(0!==e)for(let n=0;n<3;n++)t.origin[n]+=e*t.normal[n]},e.generalizedProjectPoint=(e,n)=>{Ip(e,t.origin,t.normal,n)},e.evaluateFunction=(e,n,r)=>Array.isArray(e)?t.normal[0]*(e[0]-t.origin[0])+t.normal[1]*(e[1]-t.origin[1])+t.normal[2]*(e[2]-t.origin[2]):t.normal[0]*(e-t.origin[0])+t.normal[1]*(n-t.origin[1])+t.normal[2]*(r-t.origin[2]),e.evaluateGradient=e=>[t.normal[0],t.normal[1],t.normal[2]],e.intersectWithLine=(e,n)=>Pp(e,n,t.origin,t.normal),e.intersectWithPlane=(e,n)=>_p(e,n,t.origin,t.normal)}(e,t)}var jp={newInstance:mh.newInstance(Dp,"vtkPlane"),extend:Dp,...Np};function Fp(e,t,n,r){const i=n[0]-t[0],o=n[1]-t[1],a=n[2]-t[2],s=e[0]-t[0],c=e[1]-t[1],l=e[2]-t[2];r[0]=o*l-a*c,r[1]=a*s-i*l,r[2]=i*c-o*s}function Up(e,t,n,r){Fp(e,t,n,r);const i=Math.sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]);0!==i&&(r[0]/=i,r[1]/=i,r[2]/=i)}const Bp={computeNormalDirection:Fp,computeNormal:Up,intersectWithTriangle:function(e,t,n,r,i,o){let a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:1e-6,s=!1;const c=[],l=[],u=[],h=[],d=[];Up(e,t,n,h),Up(r,i,o,d);const p=-Xh(h,e),f=-Xh(d,r),m=[Xh(d,e)+f,Xh(d,t)+f,Xh(d,n)+f];if(m[0]*m[1]>a&&m[0]*m[2]>a)return{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};const g=[Xh(h,r)+p,Xh(h,i)+p,Xh(h,o)+p];if(g[0]*g[1]>a&&g[0]*g[2]>a)return{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};if(Math.abs(h[0]-d[0])<1e-9&&Math.abs(h[1]-d[1])<1e-9&&Math.abs(h[2]-d[2])<1e-9&&Math.abs(p-f)<1e-9)return s=!0,{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};const b=[e,t,n],y=[r,i,o],v=Xh(h,d),x=(p-f*v)/(v*v-1),w=(f-p*v)/(v*v-1),E=[x*h[0]+w*d[0],x*h[1]+w*d[1],x*h[2]+w*d[2]],T=qh(h,d,[]);!function(e){const t=Yh(e);0!==t&&(e[0]/=t,e[1]/=t,e[2]/=t)}(T);let A=0,C=0;const O=[],k=[];let S,M,R=50,I=50;for(let t=0;t<3;t++){const n=t,i=(t+1)%3,o=jp.intersectWithLine(b[n],b[i],r,d);o.intersection&&o.t>0-a&&o.t<1+a&&(o.t<1+a&&o.t>1-a&&(R=A),O[A++]=Xh(o.x,T)-Xh(E,T));const s=jp.intersectWithLine(y[n],y[i],e,h);s.intersection&&s.t>0-a&&s.t<1+a&&(s.t<1+a&&s.t>1-a&&(I=C),k[C++]=Xh(s.x,T)-Xh(E,T))}if(A>2){A--;const e=O[2];O[2]=O[R],O[R]=e}if(C>2){C--;const e=k[2];k[2]=k[I],k[I]=e}if(2!==A||2!==C)return{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};if(Number.isNaN(O[0])||Number.isNaN(O[1])||Number.isNaN(k[0])||Number.isNaN(k[1]))return{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u};if(O[0]>O[1]){const e=O[1];O[1]=O[0],O[0]=e}if(k[0]>k[1]){const e=k[1];k[1]=k[0],k[0]=e}return O[1]<k[0]||k[1]<O[0]?{intersect:!1,coplanar:s,pt1:c,pt2:l,surfaceId:u}:(O[0]<k[0]?O[1]<k[1]?(u[0]=2,u[1]=1,S=k[0],M=O[1]):(u[0]=2,u[1]=2,S=k[0],M=k[1]):O[1]<k[1]?(u[0]=1,u[1]=1,S=O[0],M=O[1]):(u[0]=1,u[1]=2,S=O[0],M=k[1]),Wh(E,T,S,c),Wh(E,T,M,l),{intersect:!0,coplanar:s,pt1:c,pt2:l,surfaceId:u})}};const zp={};function Hp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,zp,n),wd.extend(e,t,n),function(e,t){t.classHierarchy.push("vtkTriangle"),e.getCellDimension=()=>2,e.intersectWithLine=(n,r,i,o,a)=>{const s={subId:0,t:Number.MAX_VALUE,intersect:0,betweenPoints:!1};a[2]=0;const c=[],l=i*i,u=[],h=[],d=[];t.points.getPoint(0,u),t.points.getPoint(1,h),t.points.getPoint(2,d);const p=[],f=[];if(Up(u,h,d,p),0!==p[0]||0!==p[1]||0!==p[2]){const t=jp.intersectWithLine(n,r,u,p);if(s.betweenPoints=t.betweenPoints,s.t=t.t,o[0]=t.x[0],o[1]=t.x[1],o[2]=t.x[2],!t.intersection)return a[0]=0,a[1]=0,s.intersect=0,s;const i=e.evaluatePosition(o,c,a,f);if(i.evaluation>=0)return i.dist2<=l?(s.intersect=1,s):(s.intersect=i.evaluation,s)}const m=Kh(u,h),g=Kh(h,d),b=Kh(d,u);t.line||(t.line=tp.newInstance()),m>g&&m>b?(t.line.getPoints().setPoint(0,u),t.line.getPoints().setPoint(1,h)):g>b&&g>m?(t.line.getPoints().setPoint(0,h),t.line.getPoints().setPoint(1,d)):(t.line.getPoints().setPoint(0,d),t.line.getPoints().setPoint(1,u));const y=t.line.intersectWithLine(n,r,i,o,a);if(s.betweenPoints=y.betweenPoints,s.t=y.t,y.intersect){const e=[],t=[],n=[];for(let r=0;r<3;r++)e[r]=u[r]-d[r],t[r]=h[r]-d[r],n[r]=o[r]-d[r];return a[0]=Xh(n,e)/b,a[1]=Xh(n,t)/g,s.intersect=1,s}return a[0]=0,a[1]=0,s.intersect=0,s},e.evaluatePosition=(e,n,r,i)=>{const o={subId:0,dist2:0,evaluation:-1};let a,s;const c=[],l=[],u=[],h=[];let d;const p=[],f=[],m=[];let g=0,b=0;const y=[];let v,x,w,E=[];const T=[],A=[],C=[];o.subId=0,r[2]=0,t.points.getPoint(1,c),t.points.getPoint(2,l),t.points.getPoint(0,u),Fp(c,l,u,h),jp.generalizedProjectPoint(e,c,h,C);let O=0;for(a=0;a<3;a++)d=h[a]<0?-h[a]:h[a],d>O&&(O=d,b=a);for(s=0,a=0;a<3;a++)a!==b&&(y[s++]=a);for(a=0;a<2;a++)p[a]=C[y[a]]-u[y[a]],f[a]=c[y[a]]-u[y[a]],m[a]=l[y[a]]-u[y[a]];if(g=Qh(f,m),0===g)return r[0]=0,r[1]=0,o.evaluation=-1,o;if(r[0]=Qh(p,m)/g,r[1]=Qh(f,p)/g,i[0]=1-(r[0]+r[1]),i[1]=r[0],i[2]=r[1],i[0]>=0&&i[0]<=1&&i[1]>=0&&i[1]<=1&&i[2]>=0&&i[2]<=1)n&&(o.dist2=Kh(C,e),n[0]=C[0],n[1]=C[1],n[2]=C[2]),o.evaluation=1;else{let t;if(n)if(i[1]<0&&i[2]<0)for(v=Kh(e,u),x=tp.distanceToLine(e,c,u,t,T),w=tp.distanceToLine(e,u,l,t,A),v<x?(o.dist2=v,E=u):(o.dist2=x,E=T),w<o.dist2&&(o.dist2=w,E=A),a=0;a<3;a++)n[a]=E[a];else if(i[2]<0&&i[0]<0)for(v=Kh(e,c),x=tp.distanceToLine(e,c,u,t,T),w=tp.distanceToLine(e,c,l,t,A),v<x?(o.dist2=v,E=c):(o.dist2=x,E=T),w<o.dist2&&(o.dist2=w,E=A),a=0;a<3;a++)n[a]=E[a];else if(i[1]<0&&i[0]<0)for(v=Kh(e,l),x=tp.distanceToLine(e,l,u,t,T),w=tp.distanceToLine(e,c,l,t,A),v<x?(o.dist2=v,E=l):(o.dist2=x,E=T),w<o.dist2&&(o.dist2=w,E=A),a=0;a<3;a++)n[a]=E[a];else if(i[0]<0){const t=tp.distanceToLine(e,c,l,n);o.dist2=t.distance}else if(i[1]<0){const t=tp.distanceToLine(e,l,u,n);o.dist2=t.distance}else if(i[2]<0){const t=tp.distanceToLine(e,c,u,n);o.dist2=t.distance}o.evaluation=0}return o},e.evaluateLocation=(e,n,r)=>{const i=[],o=[],a=[];t.points.getPoint(0,i),t.points.getPoint(1,o),t.points.getPoint(2,a);const s=1-e[0]-e[1];for(let t=0;t<3;t++)n[t]=i[t]*s+o[t]*e[0]+a[t]*e[1];r[0]=s,r[1]=e[0],r[2]=e[1]},e.getParametricDistance=e=>{let t,n=0;const r=[];r[0]=e[0],r[1]=e[1],r[2]=1-e[0]-e[1];for(let e=0;e<3;e++)t=r[e]<0?-r[e]:r[e]>1?r[e]-1:0,t>n&&(n=t);return n}}(e,t)}var Vp={newInstance:mh.newInstance(Hp,"vtkTriangle"),extend:Hp,...Bp};const Gp=["verts","lines","polys","strips"],{vtkWarningMacro:Wp}=mh,Xp={[Sd]:tp,[Md]:tp,[Rd]:Vp};const qp={};function Yp(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};Object.assign(t,qp,n),wp.extend(e,t,n),mh.get(e,t,["cells","links"]),mh.setGet(e,t,["verts","lines","polys","strips"]),function(e,t){t.classHierarchy.push("vtkPolyData"),Gp.forEach(n=>{var r;e[`getNumberOf${r=n,r.replace(/(?:^\w|[A-Z]|\b\w)/g,e=>e.toUpperCase()).replace(/\s+/g,"")}`]=()=>t[n].getNumberOfCells(),t[n]?t[n]=fu(t[n]):t[n]=yd.newInstance()}),e.getNumberOfCells=()=>Gp.reduce((e,n)=>e+t[n].getNumberOfCells(),0);const n=e.shallowCopy;e.shallowCopy=function(e){n(e,arguments.length>1&&void 0!==arguments[1]&&arguments[1]),Gp.forEach(n=>{t[n]=yd.newInstance(),t[n].shallowCopy(e.getReferenceByName(n))})},e.buildCells=()=>{const n=e.getNumberOfVerts(),r=e.getNumberOfLines(),i=e.getNumberOfPolys(),o=e.getNumberOfStrips(),a=n+r+i+o,s=new Uint8Array(a);let c=s;const l=new Uint32Array(a);let u=l;if(n){let e=0;t.verts.getCellSizes().forEach((t,n)=>{u[n]=e,c[n]=t>1?kd:Od,e+=t+1}),u=u.subarray(n),c=c.subarray(n)}if(r){let e=0;t.lines.getCellSizes().forEach((t,n)=>{u[n]=e,c[n]=t>2?Md:Sd,1===t&&Wp("Building VTK_LINE ",n," with only one point, but VTK_LINE needs at least two points. Check the input."),e+=t+1}),u=u.subarray(r),c=c.subarray(r)}if(i){let e=0;t.polys.getCellSizes().forEach((t,n)=>{switch(u[n]=e,t){case 3:c[n]=Rd;break;case 4:c[n]=_d;break;default:c[n]=Pd}t<3&&Wp("Building VTK_TRIANGLE ",n," with less than three points, but VTK_TRIANGLE needs at least three points. Check the input."),e+=t+1}),u+=u.subarray(i),c+=c.subarray(i)}if(o){let e=0;c.fill(Id,0,o),t.strips.getCellSizes().forEach((t,n)=>{u[n]=e,e+=t+1})}t.cells=zd.newInstance(),t.cells.setCellTypes(a,s,l)},e.buildLinks=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;void 0===t.cells&&e.buildCells(),t.links=Ad.newInstance(),n>0?t.links.allocate(n):t.links.allocate(e.getPoints().getNumberOfPoints()),t.links.buildLinks(e)},e.getCellType=e=>t.cells.getCellType(e),e.getCellPoints=n=>{const r=e.getCellType(n);let i=null;switch(r){case Od:case kd:i=t.verts;break;case Sd:case Md:i=t.lines;break;case Rd:case _d:case Pd:i=t.polys;break;case Id:i=t.strips;break;default:return i=null,{type:0,cellPointIds:null}}const o=t.cells.getCellLocation(n);return{cellType:r,cellPointIds:i.getCell(o)}},e.getPointCells=e=>t.links.getCells(e),e.getCellEdgeNeighbors=(e,n,r)=>{const i=t.links.getLink(n),o=t.links.getLink(r);return i.cells.filter(t=>t!==e&&-1!==o.cells.indexOf(t))},e.getCell=function(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=e.getCellPoints(t),i=n||Xp[r.cellType].newInstance();return i.initialize(e.getPoints(),r.cellPointIds),i}}(e,t)}var Kp={newInstance:mh.newInstance(Yp,"vtkPolyData"),extend:Yp};e.BufferGeometry.prototype.computeBoundsTree=oo,e.BufferGeometry.prototype.disposeBoundsTree=ao,e.Mesh.prototype.raycast=no;const Qp={COLORS:{POINT_DEFAULT:1973790,POINT_SELECTED:16750950,EDGE_DEFAULT:1973790,EDGE_SELECTED:16106818,CENTER_HELPER:16750950},SIZES:{POINT:.03,CENTER_HELPER:.015,TRANSFORM_CONTROL:.5},GEOMETRY:{POINT_SEGMENTS:8,HELPER_SEGMENTS:8},PERFORMANCE:{USE_VTK_INTERPOLATION:!0,BATCH_SIZE:1e3,WORKER_ENABLED:"undefined"!=typeof Worker}};class $p{constructor(e,t,n){this.scene=e,this.camera=t,this.renderer=n,this.padding=1.1,this._bvhCache=new Map,this._vtkInterpolator=null,this._workerPool=[],this._animationFrame=null,this._batchUpdateQueue=[],this._initGeometryPool(),this._initDataStructures(),this._initInteraction(),this._initTransformControls(),this._initPerformanceOptimizations()}_initGeometryPool(){this._geometryPool={sphere:new e.SphereGeometry(Qp.SIZES.POINT,Qp.GEOMETRY.POINT_SEGMENTS,Qp.GEOMETRY.POINT_SEGMENTS),helperSphere:new e.SphereGeometry(Qp.SIZES.CENTER_HELPER,Qp.GEOMETRY.HELPER_SEGMENTS,Qp.GEOMETRY.HELPER_SEGMENTS)},this._materialPool={pointDefault:new e.MeshBasicMaterial({color:Qp.COLORS.POINT_DEFAULT}),pointSelected:new e.MeshBasicMaterial({color:Qp.COLORS.POINT_SELECTED}),edgeDefault:new e.LineBasicMaterial({color:Qp.COLORS.EDGE_DEFAULT}),edgeSelected:new e.LineBasicMaterial({color:Qp.COLORS.EDGE_SELECTED}),centerHelper:new e.MeshBasicMaterial({color:Qp.COLORS.CENTER_HELPER,transparent:!0,opacity:.7})}}_initDataStructures(){this.vertices=[],this.spheres=[],this.lines=[],this.edgesToVertex={},this.targetObjects=[],this.originalGeometries=new Map,this.cachedVertexPositions=[],this.gridConfig={size:4,xCount:3,yCount:3,zCount:3},this.visible=!0,this.needsDeformationUpdate=!1,this.lastUpdateTime=0,this.onDeformationUpdate=null}_initInteraction(){this.raycaster=new e.Raycaster,this.mouse=new e.Vector2,this.selection={vertices:[],transformActive:!1,previousCenter:null,centerHelper:null,isBoxSelecting:!1,boxElement:this._createBoxElement(),boxPosition:{startX:0,startY:0,endX:0,endY:0}},this._bindEventHandlers()}_createBoxElement(){const e=document.createElement("div");return Object.assign(e.style,{position:"absolute",border:"2px dashed #646cff",backgroundColor:"rgba(75, 160, 255, 0.1)",display:"none",pointerEvents:"none",zIndex:"1"}),e}_bindEventHandlers(){this._handlers={mouseDown:this._onMouseDown.bind(this),mouseMove:this._onMouseMove.bind(this),mouseUp:this._onMouseUp.bind(this),transformDragging:this._onTransformDragging.bind(this),transformChanged:this._onTransformChanged.bind(this)}}_initTransformControls(){this.transformControls=new Jt(this.camera,this.renderer.domElement),this.transformControls.setSize(Qp.SIZES.TRANSFORM_CONTROL),this.transformControls.setMode("translate"),this.scene.add(this.transformControls),this._attachTransformControlsEvents()}_attachTransformControlsEvents(){this.transformControls.addEventListener("dragging-changed",this._handlers.transformDragging),this.transformControls.addEventListener("objectChange",this._handlers.transformChanged)}_detachTransformControlsEvents(){this.transformControls.removeEventListener("dragging-changed",this._handlers.transformDragging),this.transformControls.removeEventListener("objectChange",this._handlers.transformChanged)}_initPerformanceOptimizations(){this._bvhCache=new Map,Qp.PERFORMANCE.USE_VTK_INTERPOLATION&&this._initVTKInterpolator(),Qp.PERFORMANCE.WORKER_ENABLED&&this._initWorkerPool()}_initVTKInterpolator(){try{this._vtkPoints=pd.newInstance(),this._vtkPolyData=Kp.newInstance(),console.log("VTK插值器初始化成功")}catch(e){console.warn("VTK插值器初始化失败:",e),Qp.PERFORMANCE.USE_VTK_INTERPOLATION=!1}}_initWorkerPool(){const e=Math.min(4,navigator.hardwareConcurrency||2);for(let t=0;t<e;t++)try{const e=new Worker(URL.createObjectURL(new Blob(["\n self.onmessage = function(e) {\n const { vertices, weights, type } = e.data;\n \n if (type === 'interpolate') {\n const result = new Float32Array(3);\n \n for (let i = 0; i < vertices.length; i++) {\n const vertex = vertices[i];\n const weight = weights[i];\n result[0] += vertex[0] * weight;\n result[1] += vertex[1] * weight;\n result[2] += vertex[2] * weight;\n }\n \n self.postMessage({ result, id: e.data.id });\n }\n };\n "],{type:"application/javascript"})));this._workerPool.push(e)}catch(e){console.warn("Worker创建失败:",e),Qp.PERFORMANCE.WORKER_ENABLED=!1;break}this._workerPool.length>0&&console.log(`初始化了 ${this._workerPool.length} 个Worker`)}setGridConfig(e){return Object.assign(this.gridConfig,e),this}setTargetObject(e=[]){return Array.isArray(e)?this.setTargetObjects(e):this.setTargetObjects([e])}setTargetObjects(e){console.log(e,"objects"),this._cleanupPreviousTargets();const t=this._extractMeshObjects(e.filter(e=>null!=e));return this.targetObjects=t,this.originalGeometries.clear(),this.targetObjects.forEach(e=>{e.userData.isLatticeMode=!0,e?.geometry&&(e.geometry.computeBoundingBox(),e.geometry&&this._buildBVHForGeometry(e.geometry),this.originalGeometries.set(e.uuid,e.geometry.clone()))}),this}_extractMeshObjects(e){const t=[],n=e=>{e&&(e.isMesh&&e.geometry?t.push(e):e.isGroup||e.isObject3D?e.children&&e.children.length>0&&e.children.forEach(e=>n(e)):e.geometry&&t.push(e))};return e.forEach(e=>n(e)),0===t.length?console.warn("未找到任何有效的几何体对象,无法创建晶格"):console.log(`从 ${e.length} 个输入对象中提取到 ${t.length} 个Mesh对象`),t}_buildBVHForGeometry(e){try{e.boundsTree||(e.computeBoundsTree(),console.log("为几何体构建BVH,顶点数:",e.attributes.position.count)),this._bvhCache.set(e.uuid,e.boundsTree)}catch(e){console.warn("BVH构建失败:",e)}}_cleanupPreviousTargets(){this.targetObjects.forEach(e=>{e?._createdByLattice&&(this.scene.remove(e),e.geometry?.dispose(),Array.isArray(e.material)?e.material.forEach(e=>e.dispose()):e.material?.dispose())}),this.targetObjects=[],this.originalGeometries.clear()}createLattice(){return this.clearLattice(),this.targetObjects.length?(this.targetObjects.forEach(e=>{e?.geometry&&(e.geometry.computeBoundingBox(),e.updateMatrixWorld(!0))}),this._createLatticeStructure(),this.setVisible(!0),this.initEvents(),this.clearSelection(),this.targetObjects.length&&this.vertices.length&&(console.log("开始初始化变形信息,控制点数:",this.gridConfig.xCount*this.gridConfig.yCount*this.gridConfig.zCount),this.initializeCache(),this.deformationInfo?console.log("变形信息初始化成功"):console.warn("变形信息初始化失败,请检查目标对象和几何体数据")),this):(console.error("没有设置目标对象,无法创建晶格"),this)}_createLatticeStructure(){const t=this._calculateTotalBoundingBox(),n=new e.Vector3,r=new e.Vector3;if(t.getSize(n),t.getCenter(r),0===n.x||0===n.y||0===n.z)return void console.error("目标对象的尺寸为零,无法创建有效晶格");const i=n.clone().multiplyScalar(this.padding),{xCount:o,yCount:a,zCount:s}=this.gridConfig;this._createVertexGrid(i,r,o,a,s),this._createEdges()}_calculateTotalBoundingBox(){const t=new e.Box3;return t.makeEmpty(),0===this.targetObjects.length?(console.warn("没有目标对象可计算边界盒"),t):(this.targetObjects.forEach(n=>{if(!n)return;n.updateMatrixWorld(!0);const r=(new e.Box3).setFromObject(n);r.isEmpty()||t.union(r)}),t.isEmpty()&&(console.warn("所有对象的边界盒都为空,使用默认边界盒"),t.setFromCenterAndSize(new e.Vector3(0,0,0),new e.Vector3(2,2,2))),t)}_createVertexGrid(t,n,r,i,o){const a=t.x/(r-1),s=t.y/(i-1),c=t.z/(o-1);for(let l=0;l<r;l++){this.vertices[l]=[];for(let u=0;u<i;u++){this.vertices[l][u]=[];for(let h=0;h<o;h++){const d=new e.Vector3(-t.x/2+l*a+n.x,-t.y/2+u*s+n.y,-t.z/2+h*c+n.z);this.vertices[l][u][h]=d,this._isOnSurface(l,u,h,r,i,o)&&this._createVertexSphere(d,l,u,h)}}}this.spheres.forEach(e=>this.scene.add(e))}_isOnSurface(e,t,n,r,i,o){return 0===e||e===r-1||0===t||t===i-1||0===n||n===o-1}_createVertexSphere(t,n,r,i){const o=new e.Mesh(this._geometryPool.sphere,this._materialPool.pointDefault);return o.position.copy(t),o.userData={x:n,y:r,z:i},this.spheres.push(o),o}_createEdges(){const{xCount:t,yCount:n,zCount:r}=this.gridConfig;this.edgesToVertex={};const i=(t,n,r,i,o,a,s,c)=>{const l=(new e.BufferGeometry).setFromPoints([t,n]),u=new e.Line(l,this._materialPool.edgeDefault);this.lines.push(u),this.scene.add(u),[`${r},${i},${o}`,`${a},${s},${c}`].forEach(e=>{this.edgesToVertex[e]||(this.edgesToVertex[e]=[]),this.edgesToVertex[e].push(u)})};for(let e=0;e<t;e++)for(let o=0;o<n;o++)for(let a=0;a<r;a++)this._isOnSurface(e,o,a,t,n,r)&&(e<t-1&&(0===o||o===n-1||0===a||a===r-1)&&i(this.vertices[e][o][a],this.vertices[e+1][o][a],e,o,a,e+1,o,a),o<n-1&&(0===e||e===t-1||0===a||a===r-1)&&i(this.vertices[e][o][a],this.vertices[e][o+1][a],e,o,a,e,o+1,a),a<r-1&&(0===e||e===t-1||0===o||o===n-1)&&i(this.vertices[e][o][a],this.vertices[e][o][a+1],e,o,a,e,o,a+1))}initEvents(){return this.container=this.renderer.domElement,this.selection.boxElement&&!this.selection.boxElement.parentNode&&this.container.parentElement&&this.container.parentElement.appendChild(this.selection.boxElement),this.container&&(this.container.addEventListener("mousedown",this._handlers.mouseDown),document.addEventListener("mousemove",this._handlers.mouseMove),document.addEventListener("mouseup",this._handlers.mouseUp)),this}removeEvents(){return this.container&&this.container.removeEventListener("mousedown",this._handlers.mouseDown),document.removeEventListener("mousemove",this._handlers.mouseMove),document.removeEventListener("mouseup",this._handlers.mouseUp),this.selection?.boxElement?.parentNode&&this.selection.boxElement.parentNode.removeChild(this.selection.boxElement),this}_onMouseDown(e){if(0!==e.button||this.transformControls.object&&this.transformControls.axis)return;e.preventDefault(),this._updateMousePosition(e),this.raycaster.setFromCamera(this.mouse,this.camera);const t=this.raycaster.intersectObjects(this.spheres),n=e.ctrlKey||e.metaKey;t.length>0?(n||this.clearSelection(),this.toggleVertexSelection(t[0].object)):this._startBoxSelection(e,n)}_onMouseMove(e){this.selection.isBoxSelecting&&(e.preventDefault(),this._updateBoxSelection(e))}_onMouseUp(e){this.selection.isBoxSelecting&&this._endBoxSelection()}_updateMousePosition(e){const t=this.renderer.domElement.getBoundingClientRect();this.mouse.x=(e.clientX-t.left)/t.width*2-1,this.mouse.y=-(e.clientY-t.top)/t.height*2+1}_startBoxSelection(e,t){this.selection.isBoxSelecting=!0;const n=this.container.getBoundingClientRect(),r=e.clientX-n.left,i=e.clientY-n.top;this.selection.boxPosition={startX:r,startY:i,endX:r,endY:i},Object.assign(this.selection.boxElement.style,{left:`${r}px`,top:`${i}px`,width:"0px",height:"0px",display:"block"}),t||this.clearSelection()}_updateBoxSelection(e){const t=this.container.getBoundingClientRect();this.selection.boxPosition.endX=e.clientX-t.left,this.selection.boxPosition.endY=e.clientY-t.top,this._updateBoxDisplay()}_updateBoxDisplay(){const{startX:e,startY:t,endX:n,endY:r}=this.selection.boxPosition,i=Math.min(e,n),o=Math.max(e,n),a=Math.min(t,r),s=Math.max(t,r);Object.assign(this.selection.boxElement.style,{left:`${i}px`,top:`${a}px`,width:o-i+"px",height:s-a+"px"})}_endBoxSelection(){this.selection.isBoxSelecting=!1,this.selection.boxElement.style.display="none";const{startX:e,startY:t,endX:n,endY:r}=this.selection.boxPosition,i=Math.min(e,n),o=Math.max(e,n),a=Math.min(t,r),s=Math.max(t,r);o-i>=5&&s-a>=5&&this._processBoxSelection(i,o,a,s)}_processBoxSelection(t,n,r,i){const o=this.container.getBoundingClientRect(),a=new e.Vector3;this.spheres.forEach(e=>{a.copy(e.position).project(this.camera);const s=(a.x+1)/2*o.width,c=(1-a.y)/2*o.height;s>=t&&s<=n&&c>=r&&c<=i&&this.toggleVertexSelection(e,!0)})}_onTransformDragging(e){if(this.selection.transformActive=e.value,!e.value&&this.targetObjects.length>0){if(this.deformationInfo||(console.log("变换结束时发现变形信息为空,重新初始化..."),this.initializeCache()),console.log("松开鼠标,开始更新模型对象"),this.updateTargetObjectDeformation(),this.needsDeformationUpdate=!1,this._deformationStartSnapshot){if(this.scene.userData.sceneManager){const e=this.createDeformationHistoryAction(this._deformationStartSnapshot);this.scene.userData.sceneManager.addActionToHistory(e)}this._deformationStartSnapshot=null}}else e.value&&!this._deformationStartSnapshot&&(this._deformationStartSnapshot=this.getFullStateSnapshot())}_onTransformChanged(){const{vertices:e}=this.selection;e?.length&&(1===e.length?this._updateSingleVertex(e[0]):this._updateMultipleVertices(),this.needsDeformationUpdate=!0)}_updateSingleVertex(e){const{x:t,y:n,z:r}=e.userData;this.vertices[t][n][r].copy(e.position),this.updateEdgesForVertex(t,n,r),this.selection.transformActive||this._markForDeformationUpdate()}_updateMultipleVertices(){const{previousCenter:t,centerHelper:n,vertices:r}=this.selection;if(!t)return void(this.selection.previousCenter=n.position.clone());const i=(new e.Vector3).subVectors(n.position,t);r.forEach(e=>{e.position.add(i);const{x:t,y:n,z:r}=e.userData;this.vertices[t][n][r].copy(e.position),this.updateEdgesForVertex(t,n,r)}),this.selection.previousCenter.copy(n.position),this.selection.transformActive||this._markForDeformationUpdate()}toggleVertexSelection(e,t=!1){const n=this.selection.vertices.indexOf(e),{x:r,y:i,z:o}=e.userData,a=`${r},${i},${o}`;return-1===n||t?(-1===n&&this.selection.vertices.push(e),this._setVertexColor(e,Qp.COLORS.POINT_SELECTED),this._setConnectedEdgeColor(a,Qp.COLORS.EDGE_SELECTED)):t||(this.selection.vertices.splice(n,1),this._setVertexColor(e,Qp.COLORS.POINT_DEFAULT),this._updateConnectedEdgeColors(e,a)),this.updateTransformControls(),this}_setVertexColor(e,t){const n=t===Qp.COLORS.POINT_SELECTED?this._materialPool.pointSelected:this._materialPool.pointDefault;e.material=n}_setConnectedEdgeColor(e,t){const n=t===Qp.COLORS.EDGE_SELECTED?this._materialPool.edgeSelected:this._materialPool.edgeDefault;this.edgesToVertex[e]?.forEach(e=>{e.material=n})}_updateConnectedEdgeColors(e,t){this.edgesToVertex[t]?.forEach(e=>{this.selection.vertices.some(t=>{const n=`${t.userData.x},${t.userData.y},${t.userData.z}`;return this.edgesToVertex[n]?.includes(e)})||e.material.color.set(Qp.COLORS.EDGE_DEFAULT)})}clearSelection(){return this.selection.vertices.forEach(e=>{this._setVertexColor(e,Qp.COLORS.POINT_DEFAULT),this._resetVertexConnectedEdges(e)}),this.selection.vertices=[],this.transformControls.detach(),this.selection.centerHelper&&(this.selection.centerHelper.visible=!1),this.selection.previousCenter=null,this}_resetVertexConnectedEdges(e){const{x:t,y:n,z:r}=e.userData,i=`${t},${n},${r}`;this._setConnectedEdgeColor(i,Qp.COLORS.EDGE_DEFAULT)}updateTransformControls(){const{vertices:e}=this.selection;return this.transformControls?(0===e.length?(this.transformControls.detach(),this.selection.centerHelper&&(this.selection.centerHelper.visible=!1)):1===e.length?(this.selection.centerHelper&&(this.selection.centerHelper.visible=!1),this.transformControls.detach(),this.transformControls.attach(e[0]),this.transformControls.setMode("translate"),this.transformControls.visible=!0,this.selection.previousCenter=null):this._setupMultiSelectionTransform(),this):this}_setupMultiSelectionTransform(){const{vertices:t}=this.selection;if(!t?.length)return;const n=this._calculateSelectionCenter(t);n&&(this.selection.centerHelper||(this.selection.centerHelper=new e.Mesh(this._geometryPool.helperSphere,this._materialPool.centerHelper.clone()),this.selection.centerHelper.userData={isLatticeHelper:!0,type:"centerHelper"},this.scene.add(this.selection.centerHelper)),this.selection.centerHelper.position.copy(n),this.selection.centerHelper.visible=!0,this.transformControls.detach(),this.transformControls.attach(this.selection.centerHelper),this.transformControls.setMode("translate"),this.transformControls.visible=!0,this.selection.previousCenter=n.clone())}_calculateSelectionCenter(t){const n=new e.Vector3;let r=0;for(const e of t)e?.position&&(n.add(e.position),r++);return r>0?n.divideScalar(r):null}initializeCache(){if(!this.targetObjects.length||!this.vertices.length)return void console.warn("无法初始化缓存: 没有目标对象或顶点数据");const{xCount:t,yCount:n,zCount:r}=this.gridConfig;this.cachedVertexPositions=[];const i=this._calculateTotalBoundingBox(),o=new e.Vector3,a=new e.Vector3;i.getSize(o),i.getCenter(a);const s=o.clone().multiplyScalar(this.padding);s.x<=0||s.y<=0||s.z<=0?console.error("无效的包围盒尺寸:",s):(this.deformationInfo={totalBBox:i,paddedSize:s,center:a,gridConfig:{xCount:t,yCount:n,zCount:r},originalVertices:this._getOriginalVerticesSnapshot()},console.log(`已初始化晶格变形信息,覆盖 ${this.targetObjects.length} 个对象`))}_getOriginalVerticesSnapshot(){const e=new Map;return this.targetObjects.forEach(t=>{if(!t?.geometry)return;const n=this.originalGeometries.get(t.uuid);if(!n){const n=t.geometry;return void(n&&(this.originalGeometries.set(t.uuid,n.clone()),e.set(t.uuid,{geometry:n.clone(),worldMatrix:t.matrixWorld.clone()})))}e.set(t.uuid,{geometry:n.clone(),worldMatrix:t.matrixWorld.clone()})}),e}_normalizePosition(t,n,r){return t&&n&&r?0===r.x||0===r.y||0===r.z?(console.warn("填充尺寸为零,无法归一化"),null):new e.Vector3((t.x-n.x+r.x/2)/r.x,(t.y-n.y+r.y/2)/r.y,(t.z-n.z+r.z/2)/r.z):(console.warn("归一化位置时参数无效"),null)}_calculateGridPosition(e,t,n,r){return!e||t<=1||n<=1||r<=1?(console.warn("网格位置计算参数无效"),null):{x:Math.max(0,Math.min(t-1,e.x*(t-1))),y:Math.max(0,Math.min(n-1,e.y*(n-1))),z:Math.max(0,Math.min(r-1,e.z*(r-1)))}}_calculateWeights(e){if(!e||"number"!=typeof e.x||"number"!=typeof e.y||"number"!=typeof e.z)return console.warn("无效的网格位置:",e),null;const t=e.x-Math.floor(e.x),n=e.y-Math.floor(e.y),r=e.z-Math.floor(e.z),i=Math.floor(e.x),o=Math.min(i+1,this.gridConfig.xCount-1),a=Math.floor(e.y),s=Math.min(a+1,this.gridConfig.yCount-1),c=Math.floor(e.z),l=Math.min(c+1,this.gridConfig.zCount-1);return i<0||o>=this.gridConfig.xCount||a<0||s>=this.gridConfig.yCount||c<0||l>=this.gridConfig.zCount?(console.warn("网格索引超出范围:",{x0:i,x1:o,y0:a,y1:s,z0:c,z1:l},"网格配置:",this.gridConfig),null):{w000:(1-t)*(1-n)*(1-r),w001:(1-t)*(1-n)*r,w010:(1-t)*n*(1-r),w011:(1-t)*n*r,w100:t*(1-n)*(1-r),w101:t*(1-n)*r,w110:t*n*(1-r),w111:t*n*r,gridIndices:{x0:i,x1:o,y0:a,y1:s,z0:c,z1:l}}}updateTargetObjectDeformation(){if(!this.targetObjects.length)return void console.warn("无法更新变形: 没有目标对象");if(!this.vertices.length)return void console.warn("无法更新变形: 没有顶点数据");if(!this.deformationInfo&&(console.log("变形信息为空,尝试重新初始化..."),this.initializeCache(),!this.deformationInfo))return void console.warn("无法更新变形: 初始化变形信息失败");const{paddedSize:e,center:t,gridConfig:n,originalVertices:r}=this.deformationInfo,{xCount:i,yCount:o,zCount:a}=n;Promise.all(this.targetObjects.map(i=>this._updateSingleObjectDeformation(i,r,e,t,n))).then(()=>{this.onDeformationUpdate&&this.onDeformationUpdate(this.targetObjects)}).catch(e=>{console.error("并行更新变形失败:",e)})}async _updateSingleObjectDeformation(e,t,n,r,i){if(!e?.geometry)return void console.warn("找不到对象或几何体:",e.uuid);const o=t.get(e.uuid);if(!o?.geometry)return void console.warn("找不到原始几何体数据:",e.uuid);const a=o.geometry.attributes.position,s=e.geometry.attributes.position;if(!a||!s)return void console.warn("对象缺少位置属性:",e.uuid);const c=a.count,l=e.matrixWorld,u=l.clone().invert();let h=0,d=0;for(let e=0;e<c;e+=Qp.PERFORMANCE.BATCH_SIZE){const t=Math.min(e+Qp.PERFORMANCE.BATCH_SIZE,c);if(Qp.PERFORMANCE.USE_VTK_INTERPOLATION&&this._vtkInterpolator){const o=await this._performVTKInterpolation(a,l,u,n,r,i,e,t);o?(this._applyBatchResult(s,o,e),h+=o.count):d+=t-e}else{const o=this._processBatchTraditional(a,l,u,n,r,i,e,t);this._applyBatchResult(s,o,e),h+=o.count,d+=o.errors}e+Qp.PERFORMANCE.BATCH_SIZE<c&&await new Promise(e=>setTimeout(e,0))}if(d>0&&console.warn(`对象 ${e.uuid} 有 ${d} 个顶点更新失败`),h>0){s.needsUpdate=!0;try{e.geometry.computeBoundingBox(),e.geometry.computeBoundingSphere()}catch(e){console.warn("更新几何体边界失败:",e)}if(e.geometry.boundsTree)try{e.geometry.disposeBoundsTree(),e.geometry.computeBoundsTree(),this._bvhCache.set(e.geometry.uuid,e.geometry.boundsTree)}catch(e){console.warn("BVH重建失败:",e)}}}async _performVTKInterpolation(t,n,r,i,o,a,s,c){if(!this._vtkPoints||!this._vtkPolyData)return null;try{const l=[],u=[];for(let r=s;r<c;r++){const a=new e.Vector3(t.getX(r),t.getY(r),t.getZ(r)).clone().applyMatrix4(n),c=this._normalizePosition(a,o,i);c&&(l.push([c.x,c.y,c.z]),u.push(r-s))}if(0===l.length)return null;this._vtkPoints.setData(new Float32Array(l.flat())),this._vtkPolyData.setPoints(this._vtkPoints);const h=new Float32Array(3*(c-s));let d=0;for(let t=0;t<u.length;t++){const n=u[t],i=new e.Vector3(...l[t]),o=this._calculateGridPosition(i,a.xCount,a.yCount,a.zCount);if(!o)continue;const s=this._calculateWeights(o);if(!s)continue;const c=this._calculateDeformedWorldPosition(s);if(!c)continue;const p=c.applyMatrix4(r);h[3*n]=p.x,h[3*n+1]=p.y,h[3*n+2]=p.z,d++}return{results:h,count:d}}catch(e){return console.warn("VTK插值失败,回退到传统方法:",e),null}}_processBatchTraditional(t,n,r,i,o,a,s,c){const l=new Float32Array(3*(c-s));let u=0,h=0;for(let d=s;d<c;d++)try{const c=new e.Vector3(t.getX(d),t.getY(d),t.getZ(d)).clone().applyMatrix4(n),p=this._normalizePosition(c,o,i);if(!p){h++;continue}const f=this._calculateGridPosition(p,a.xCount,a.yCount,a.zCount);if(!f){h++;continue}const m=this._calculateWeights(f);if(!m){h++;continue}const g=this._calculateDeformedWorldPosition(m);if(!g){h++;continue}const b=g.applyMatrix4(r);if(isNaN(b.x)||isNaN(b.y)||isNaN(b.z)){h++;continue}const y=3*(d-s);l[y]=b.x,l[y+1]=b.y,l[y+2]=b.z,u++}catch(e){console.warn("更新顶点失败:",e,"顶点索引:",d),h++}return{results:l,count:u,errors:h}}_applyBatchResult(e,t,n){const{results:r,count:i}=t;for(let t=0;t<i;t++){const i=n+Math.floor(3*t/3),o=3*t;i<e.count&&o+2<r.length&&e.setXYZ(i,r[o],r[o+1],r[o+2])}}_calculateDeformedWorldPosition(t){if(!t||!t.gridIndices)return console.warn("无效的权重数据"),null;const{gridIndices:n}=t,{x0:r,x1:i,y0:o,y1:a,z0:s,z1:c}=n;if(!(this.vertices&&this.vertices[r]&&this.vertices[r][o]&&this.vertices[i]&&this.vertices[i][a]))return console.warn("顶点数组结构无效"),null;if([this.vertices[r]?.[o]?.[s],this.vertices[r]?.[o]?.[c],this.vertices[r]?.[a]?.[s],this.vertices[r]?.[a]?.[c],this.vertices[i]?.[o]?.[s],this.vertices[i]?.[o]?.[c],this.vertices[i]?.[a]?.[s],this.vertices[i]?.[a]?.[c]].some(t=>!(t&&t instanceof e.Vector3)))return console.warn("某些顶点不存在或无效"),null;const l=new e.Vector3;try{if(l.add(this.vertices[r][o][s].clone().multiplyScalar(t.w000||0)),l.add(this.vertices[r][o][c].clone().multiplyScalar(t.w001||0)),l.add(this.vertices[r][a][s].clone().multiplyScalar(t.w010||0)),l.add(this.vertices[r][a][c].clone().multiplyScalar(t.w011||0)),l.add(this.vertices[i][o][s].clone().multiplyScalar(t.w100||0)),l.add(this.vertices[i][o][c].clone().multiplyScalar(t.w101||0)),l.add(this.vertices[i][a][s].clone().multiplyScalar(t.w110||0)),l.add(this.vertices[i][a][c].clone().multiplyScalar(t.w111||0)),isNaN(l.x)||isNaN(l.y)||isNaN(l.z))return console.warn("计算结果包含NaN值"),null}catch(e){return console.error("三线性插值计算失败:",e),null}return l}_calculateDeformedPosition(t){if(!t||!t.weights||!t.weights.gridIndices)return console.warn("无效的缓存数据,无法计算变形位置"),t?.originalVertex?.clone()||new e.Vector3;const{weights:n}=t,{gridIndices:r}=n,{x0:i=0,x1:o=0,y0:a=0,y1:s=0,z0:c=0,z1:l=0}=r;if(!(this.vertices&&Array.isArray(this.vertices)&&this.vertices[i]&&Array.isArray(this.vertices[i])&&this.vertices[i][a]&&Array.isArray(this.vertices[i][a])&&this.vertices[o]&&Array.isArray(this.vertices[o])&&this.vertices[o][s]&&Array.isArray(this.vertices[o][s])))return console.warn("顶点数组结构无效:",{x0:i,x1:o,y0:a,y1:s,z0:c,z1:l}),t.originalVertex?.clone()||new e.Vector3;if([this.vertices[i]?.[a]?.[c],this.vertices[i]?.[a]?.[l],this.vertices[i]?.[s]?.[c],this.vertices[i]?.[s]?.[l],this.vertices[o]?.[a]?.[c],this.vertices[o]?.[a]?.[l],this.vertices[o]?.[s]?.[c],this.vertices[o]?.[s]?.[l]].some(t=>!(t&&t instanceof e.Vector3)))return console.warn("某些顶点不存在或无效,使用原始位置"),t.originalVertex?.clone()||new e.Vector3;const u=new e.Vector3;try{if(u.add(this.vertices[i][a][c].clone().multiplyScalar(n.w000||0)),u.add(this.vertices[i][a][l].clone().multiplyScalar(n.w001||0)),u.add(this.vertices[i][s][c].clone().multiplyScalar(n.w010||0)),u.add(this.vertices[i][s][l].clone().multiplyScalar(n.w011||0)),u.add(this.vertices[o][a][c].clone().multiplyScalar(n.w100||0)),u.add(this.vertices[o][a][l].clone().multiplyScalar(n.w101||0)),u.add(this.vertices[o][s][c].clone().multiplyScalar(n.w110||0)),u.add(this.vertices[o][s][l].clone().multiplyScalar(n.w111||0)),isNaN(u.x)||isNaN(u.y)||isNaN(u.z))return console.warn("计算结果包含NaN值,使用原始位置"),t.originalVertex?.clone()||new e.Vector3}catch(n){return console.error("三线性插值计算失败:",n),t.originalVertex?.clone()||new e.Vector3}return u}updateEdgesForVertex(e,t,n){const r=`${e},${t},${n}`,i=this.edgesToVertex[r];if(!i)return;const o=this.vertices[e]?.[t]?.[n];o&&i.forEach(e=>{Object.keys(this.edgesToVertex).filter(t=>this.edgesToVertex[t].includes(e)).forEach((t,n)=>{if(n>=2)return;const[i,o,a]=t.split(",").map(Number),s=this.vertices[i]?.[o]?.[a];if(s){const n=e.geometry.attributes.position,i=t===r?0:1;n.setXYZ(i,s.x,s.y,s.z)}}),e.geometry.attributes.position.needsUpdate=!0})}_markForDeformationUpdate(){this.targetObjects.length&&(this.needsDeformationUpdate=!0)}checkPointSelection(e){return e.intersectObjects(this.spheres)}setVisible(e){return this.visible=e,this.spheres&&Array.isArray(this.spheres)&&this.spheres.forEach(t=>{t&&"object"==typeof t&&"visible"in t&&(t.visible=e)}),this.lines&&Array.isArray(this.lines)&&this.lines.forEach(t=>{t&&"object"==typeof t&&"visible"in t&&(t.visible=e)}),this}clearLattice(){return this.spheres&&Array.isArray(this.spheres)&&this.spheres.forEach(e=>{e&&(this.scene.remove(e),e.material!==this._materialPool.pointDefault&&e.material!==this._materialPool.pointSelected&&e.material?.dispose())}),this.lines&&Array.isArray(this.lines)&&this.lines.forEach(e=>{e&&(this.scene.remove(e),e.geometry?.dispose(),e.material!==this._materialPool.edgeDefault&&e.material!==this._materialPool.edgeSelected&&e.material?.dispose())}),this.spheres=[],this.lines=[],this.vertices=[],this.edgesToVertex={},this.clearSelection(),this}getLatticeGrid(){return this.vertices.length>0&&this.spheres.length>0}exitLatticeGrid(){this.clearLattice(),this.removeEvents(),this.targetObjects.forEach(e=>{e?.userData&&(e.userData.isLatticeMode=!1)});const e=[...this.targetObjects];return this.targetObjects=[],this.originalGeometries.clear(),e}getTargetObject(){return this.targetObjects[0]||null}getTargetObjects(){return this.targetObjects}getPerformanceStats(){return{sphereCount:this.spheres.length,lineCount:this.lines.length,targetObjectCount:this.targetObjects.length,gridDimensions:`${this.gridConfig.xCount}×${this.gridConfig.yCount}×${this.gridConfig.zCount}`}}dispose(){this._workerPool&&this._workerPool.length>0&&(this._workerPool.forEach(e=>{try{e.terminate()}catch(e){console.warn("Worker终止失败:",e)}}),this._workerPool=[]),this._vtkPoints&&(this._vtkPoints.delete(),this._vtkPoints=null),this._vtkPolyData&&(this._vtkPolyData.delete(),this._vtkPolyData=null),this._bvhCache&&(this._bvhCache.clear(),this._bvhCache=null),this._animationFrame&&(cancelAnimationFrame(this._animationFrame),this._animationFrame=null),this._detachTransformControlsEvents(),this.transformControls&&(this.transformControls.detach(),this.transformControls.dispose(),this.scene.remove(this.transformControls)),this.removeEvents(),this.clearLattice(),this.selection?.centerHelper&&(this.scene.remove(this.selection.centerHelper),this.selection.centerHelper.geometry?.dispose(),this.selection.centerHelper.material?.dispose()),Object.values(this._geometryPool||{}).forEach(e=>e?.dispose()),Object.values(this._materialPool||{}).forEach(e=>e?.dispose()),this._geometryPool=null,this._materialPool=null,this.vertices=null,this.spheres=null,this.lines=null,this.edgesToVertex=null,this.targetObjects=null,this.originalGeometries=null,this.cachedVertexPositions=null,this.selection=null,this.transformControls=null}static isObjectInLatticeMode(e){return e&&e.userData&&!0===e.userData.isLatticeMode}static areObjectsInLatticeMode(e){return!(!Array.isArray(e)||0===e.length)&&e.every(e=>this.isObjectInLatticeMode(e))}getLatticeConfig(){return{xCount:this.gridConfig.xCount,yCount:this.gridConfig.yCount,zCount:this.gridConfig.zCount,padding:this.padding}}getLatticeVerticesSnapshot(){if(!this.vertices||!this.vertices.length)return null;const e=[],{xCount:t,yCount:n,zCount:r}=this.gridConfig;for(let i=0;i<t;i++){e[i]=[];for(let t=0;t<n;t++){e[i][t]=[];for(let n=0;n<r;n++)this.vertices[i]&&this.vertices[i][t]&&this.vertices[i][t][n]&&(e[i][t][n]=this.vertices[i][t][n].clone())}}return e}restoreLatticeVerticesSnapshot(e){if(!e||!this.vertices)return!1;const{xCount:t,yCount:n,zCount:r}=this.gridConfig;try{for(let i=0;i<t;i++)for(let o=0;o<n;o++)for(let a=0;a<r;a++)if(e[i]&&e[i][o]&&e[i][o][a]&&this.vertices[i]&&this.vertices[i][o]&&this.vertices[i][o][a]){if(this.vertices[i][o][a].copy(e[i][o][a]),this._isOnSurface(i,o,a,t,n,r)){const t=this.spheres.find(e=>e.userData.x===i&&e.userData.y===o&&e.userData.z===a);t&&t.position.copy(e[i][o][a])}this.updateEdgesForVertex(i,o,a)}return this.updateTargetObjectDeformation(),!0}catch(e){return console.error("恢复晶格顶点状态失败:",e),!1}}getFullStateSnapshot(){return{vertices:this.getLatticeVerticesSnapshot(),hasLattice:this.getLatticeGrid()}}createDeformationHistoryAction(e){const t=this.getFullStateSnapshot();return{type:"LATTICE_DEFORMATION",data:{beforeSnapshot:e,afterSnapshot:t},undo:()=>{e.vertices&&this.restoreLatticeVerticesSnapshot(e.vertices)},redo:()=>{t.vertices&&this.restoreLatticeVerticesSnapshot(t.vertices)}}}setPadding(e){return"number"==typeof e&&e>0?(this.padding=e,this):(console.warn("无效的填充值:",e),this)}getPadding(){return this.padding}updateLatticeConfig(e){if(Object.assign(this.gridConfig,e),this.getLatticeGrid()&&this.targetObjects.length>0){const e=[...this.targetObjects];this.clearLattice(),this.setTargetObjects(e).createLattice()}return this}preserveCurrentDeformation(){if(!this.targetObjects.length)return console.warn("没有目标对象,无法保存当前形变状态"),!1;let e=0;return this.targetObjects.forEach(t=>{if(t&&t.geometry)try{const n=t.geometry.clone();this.originalGeometries.set(t.uuid,n),e++,console.log(`已保存对象 ${t.uuid} 的当前形变状态`)}catch(e){console.error(`保存对象 ${t.uuid} 的形变状态失败:`,e)}}),e>0?(console.log(`成功保存了 ${e} 个对象的形变状态`),this.initializeCache(),!0):(console.warn("没有成功保存任何对象的形变状态"),!1)}}class Zp extends x{constructor(e,t){super(),this.isViewHelper=!0,this.animating=!1,this.center=new f;const n={left:0,bottom:0},r=new K("#ff4466"),i=new K("#88ff44"),o=new K("#4488ff"),a=new K("#000000"),s={},c=[],l=new w,u=new v,h=new x,d=new Se(-2,2,2,-2,0,4);d.position.set(0,0,2);const p=new A(.04,.04,.8,5).rotateZ(-Math.PI/2).translate(.4,0,0),m=new S(p,W(r)),g=new S(p,W(i)),b=new S(p,W(o));g.rotation.z=Math.PI/2,b.rotation.y=-Math.PI/2,this.add(m),this.add(b),this.add(g);const T=X(r,"X"),C=X(i,"Y"),O=X(o,"Z"),k=X(a),M=new ot(T),R=new ot(C),I=new ot(O),P=new ot(k),N=new ot(k),L=new ot(k);M.position.x=1,R.position.y=1,I.position.z=1,P.position.x=-1,N.position.y=-1,L.position.z=-1,P.material.opacity=.2,N.material.opacity=.2,L.material.opacity=.2,M.userData.type="posX",R.userData.type="posY",I.userData.type="posZ",P.userData.type="negX",N.userData.type="negY",L.userData.type="negZ",this.add(M),this.add(R),this.add(I),this.add(P),this.add(N),this.add(L),c.push(M),c.push(R),c.push(I),c.push(P),c.push(N),c.push(L);const D=new f,j=128,F=2*Math.PI;this.render=function(t){this.quaternion.copy(e.quaternion).invert(),this.updateMatrixWorld(),D.set(0,0,1),D.applyQuaternion(e.quaternion);const r=n.left,i=n.bottom;t.clearDepth(),t.getViewport(V),t.setViewport(r,i,j,j),t.render(this,d),t.setViewport(V.x,V.y,V.z,V.w)},this.setOffset=function(e,t){n.left=e,n.bottom=t};const U=new f,B=new y,z=new y,H=new y,V=new He;let G=0;function W(e){return new E({color:e,toneMapped:!1})}function X(e,t){const{font:n="20px Arial",color:r="#000000",radius:i=14}=s,o=document.createElement("canvas");o.width=64,o.height=64;const a=o.getContext("2d");a.beginPath(),a.arc(32,32,i,0,2*Math.PI),a.closePath(),a.fillStyle=e.getStyle(),a.fill(),t&&(a.font=n,a.textAlign="center",a.fillStyle=r,a.fillText(t,32,41));const c=new at(o);return c.colorSpace=Y,new st({map:c,toneMapped:!1})}function q(){M.material.map.dispose(),R.material.map.dispose(),I.material.map.dispose(),M.material.dispose(),R.material.dispose(),I.material.dispose(),M.material=X(r,s.labelX),R.material=X(i,s.labelY),I.material=X(o,s.labelZ)}this.handleClick=function(r){if(!0===this.animating)return!1;const i=t.getBoundingClientRect(),o=i.left+n.left,a=i.top,s=r.clientX,p=r.clientY;if(s<o||s>o+j||p<a||p>a+j)return!1;u.x=(s-o)/j*2-1,u.y=-(p-a)/j*2+1,l.setFromCamera(u,d);const f=l.intersectObjects(c);if(f.length>0){return function(t,n){switch(t.userData.type){case"posX":U.set(1,0,0),B.setFromEuler(new _(0,.5*Math.PI,0));break;case"posY":U.set(0,1,0),B.setFromEuler(new _(.5*-Math.PI,0,0));break;case"posZ":U.set(0,0,1),B.setFromEuler(new _);break;case"negX":U.set(-1,0,0),B.setFromEuler(new _(0,.5*-Math.PI,0));break;case"negY":U.set(0,-1,0),B.setFromEuler(new _(.5*Math.PI,0,0));break;case"negZ":U.set(0,0,-1),B.setFromEuler(new _(0,Math.PI,0));break;default:console.error("ViewHelper: Invalid axis.")}G=e.position.distanceTo(n),U.multiplyScalar(G).add(n),h.position.copy(n),h.lookAt(e.position),z.copy(h.quaternion),h.lookAt(U),H.copy(h.quaternion)}(f[0].object,this.center),this.animating=!0,!0}return!1},this.setLabels=function(e,t,n){s.labelX=e,s.labelY=t,s.labelZ=n,q()},this.setLabelStyle=function(e,t,n){s.font=e,s.color=t,s.radius=n,q()},this.update=function(t){const n=t*F;z.rotateTowards(H,n),e.position.set(0,0,1).applyQuaternion(z).multiplyScalar(G).add(this.center),e.quaternion.rotateTowards(B,n),0===z.angleTo(H)&&(this.animating=!1)},this.dispose=function(){p.dispose(),m.material.dispose(),g.material.dispose(),b.material.dispose(),M.material.map.dispose(),R.material.map.dispose(),I.material.map.dispose(),P.material.map.dispose(),N.material.map.dispose(),L.material.map.dispose(),M.material.dispose(),R.material.dispose(),I.material.dispose(),P.material.dispose(),N.material.dispose(),L.material.dispose()}}}class Jp{constructor(e,t,n,r){this.scene=e,this.camera=t,this.renderer=n,this.mainControls=r,this.transformControl=r?.transformControl||null,this.isFourView=!1,this.container=this.renderer.domElement.parentElement,this.width=this.container.clientWidth,this.height=this.container.clientHeight,this.originalCamera=null,this.dividers=null,this.viewConfig=[{name:"前视图",id:"front-view",position:"leftTop",cameraType:"front"},{name:"顶视图",id:"top-view",position:"leftBottom",cameraType:"top"},{name:"右视图",id:"right-view",position:"rightTop",cameraType:"right"},{name:"透视图",id:"perspective-view",position:"rightBottom",cameraType:"perspective"}],this.views=null,this._animationId=null,this.activeViewIndex=-1,this.currentLayout=null}setFourView(){this.setCustomView([{x:0,y:0,width:.5,height:.5},{x:0,y:.5,width:.5,height:.5},{x:.5,y:0,width:.5,height:.5},{x:.5,y:.5,width:.5,height:.5}])}setCustomView(e){if(this.scene&&this.camera&&this.renderer){if(this.isFourView||0===e.length){if(this._isSameLayout(e)||e[0].mainScene)return void this.exitFourView();this._removeViews()}this.originalCamera={position:this.camera.position.clone(),target:this.mainControls.target.clone(),up:this.camera.up.clone(),zoom:this.camera.zoom,fov:this.camera.fov},this.transformControl&&this.transformControl.parent&&this.transformControl.parent.remove(this.transformControl),this.renderer.domElement.style.display="none",this.currentLayout=[...e],this._createCustomViews(e),this.isFourView=!0,this._startRenderLoop(),this._handleResize=this.onWindowResize.bind(this),window.addEventListener("resize",this._handleResize)}}getSelectableObjects(){let t=[];return this.mainControls&&"function"==typeof this.mainControls.getSelectableObjects?t=this.mainControls.getSelectableObjects():this.scene&&this.scene.traverse(n=>{n instanceof e.Camera||n instanceof e.Light||n instanceof e.Scene||n instanceof e.Object3D&&0===n.children.length&&!n.geometry||!n.userData.selectable||t.push(n)}),t}_handleObjectSelection(e,t){if(console.log(e,t),this.activeViewIndex!==t&&-1!==this.activeViewIndex){this.views[this.activeViewIndex].control.clearSelection()}this.activeViewIndex=t,this.transformControl&&this.transformControl.parent&&this.transformControl.parent.remove(this.transformControl),this.views.forEach(e=>{e.index!==t&&e.control.clearSelection()}),e&&e.length>0&&(this.transformControl&&!this.transformControl.parent&&this.scene.add(this.transformControl),this.transformControl&&this.transformControl.attach(e[0]))}_activateView(e){if(!(e<0||e>=this.views.length)){if(this.activeViewIndex!==e&&-1!==this.activeViewIndex){this.views[this.activeViewIndex].control.clearSelection(),this.transformControl&&this.transformControl.parent&&this.transformControl.parent.remove(this.transformControl)}this.activeViewIndex=e}}_isSameLayout(e){if(!this.currentLayout||this.currentLayout.length!==e.length)return!1;for(let t=0;t<this.currentLayout.length;t++){const n=this.currentLayout[t],r=e[t];if(n.x!==r.x||n.y!==r.y||n.width!==r.width||n.height!==r.height)return!1}return!0}_createCustomViews(t){this._removeViews(),this.views=[];const n=this.getSelectableObjects(),r=this._getCameraTypesForLayout(t);t.forEach((i,o)=>{const a=Math.floor(this.width*i.x),s=Math.floor(this.height*i.y),c=Math.floor(this.width*i.width),l=Math.floor(this.height*i.height),u=r[o].type,h=r[o].name,d=document.createElement("div");d.id=`view-${o}`,d.style.cssText=`\n position: absolute;\n left: ${a}px;\n top: ${s}px;\n width: ${c}px;\n height: ${l}px;\n overflow: hidden;\n box-sizing: border-box;\n border: 1px solid rgba(60, 60, 60, 0.8);\n background-color: rgba(42, 42, 42, 1);\n box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);\n `;const p=new e.WebGLRenderer({antialias:!0,alpha:!0});p.setSize(c,l),p.setClearColor(2763306),p.setPixelRatio(window.devicePixelRatio),d.appendChild(p.domElement);const f=document.createElement("div");f.textContent=h,f.style.cssText="\n position: absolute;\n left: 10px;\n top: 10px;\n color: white;\n background-color: rgba(0, 0, 0, 0.5);\n padding: 4px 8px;\n border-radius: 4px;\n font-size: 12px;\n pointer-events: none;\n z-index: 101;\n ",t.length>1&&d.appendChild(f),this.container.appendChild(d);const m=c/l,g=new e.PerspectiveCamera(20,m,.1,1e3);switch(u){case"top":g.position.set(0,0,20),g.lookAt(0,0,0),g.up.set(0,1,0);break;case"front":g.position.set(0,-20,0),g.lookAt(0,0,0),g.up.set(0,0,1);break;case"right":g.position.set(20,0,0),g.lookAt(0,0,0),g.up.set(0,0,1);break;case"left":g.position.set(-20,0,0),g.lookAt(0,0,0),g.up.set(0,0,1);break;case"back":g.position.set(0,20,0),g.lookAt(0,0,0),g.up.set(0,0,1);break;case"bottom":g.position.set(0,0,-20),g.lookAt(0,0,0),g.up.set(0,-1,0);break;default:g.position.set(-15,-15,15),g.lookAt(0,0,0),g.up.set(0,0,1)}const b=new po(this.scene,g,p.domElement,()=>{},e=>this._handleObjectSelection(e,o));b.enableDamping=!1,b.orbitControls.screenSpacePanning=!0,b.orbitControls.target.set(0,0,0),"perspective"!==u&&(b.orbitControls.enableRotate=!1),b.addObjects(n),b.update(),this.views.push({config:{name:h,cameraType:u,layout:i},container:d,renderer:p,camera:g,control:b,label:f,index:o})}),this.views.length>0&&(this.activeViewIndex=0,this._activateView(this.activeViewIndex))}_getCameraTypesForLayout(e){let t=[];if(1===e.length)t.push({type:"perspective",name:"透视图"});else if(2===e.length)t.push({type:"perspective",name:"透视图"}),t.push({type:"top",name:"顶视图"});else if(3===e.length)t.push({type:"front",name:"前视图"}),t.push({type:"top",name:"顶视图"}),t.push({type:"perspective",name:"透视图"});else if(4===e.length)t.push({type:"front",name:"前视图"}),t.push({type:"top",name:"顶视图"}),t.push({type:"right",name:"右视图"}),t.push({type:"perspective",name:"透视图"});else{const n=["left","back","bottom"];let r=0;for(let i=0;i<e.length;i++)if(0===i)t.push({type:"front",name:"前视图"});else if(1===i)t.push({type:"top",name:"顶视图"});else if(2===i)t.push({type:"right",name:"右视图"});else if(i===e.length-1)t.push({type:"perspective",name:"透视图"});else{const e=n[r%n.length];let o;switch(e){case"left":o="左视图";break;case"back":o="后视图";break;case"bottom":o="底视图";break;default:o=`视图 ${i+1}`}t.push({type:e,name:o}),r++}}return t}_startRenderLoop(){this._animationId&&(cancelAnimationFrame(this._animationId),this._animationId=null);const e=()=>{this._animationId=requestAnimationFrame(e),this.isFourView&&this.views.forEach(e=>{e.control.update(),e.renderer.render(this.scene,e.camera)})};e()}_removeViews(){this.views&&(this.views.forEach(e=>{if(e.renderer){e.renderer.renderTarget&&e.renderer.renderTarget.dispose();const t=e.renderer.getContext();if(t){const e=t.getExtension("WEBGL_lose_context");e&&e.loseContext()}e.renderer.domElement&&(e.renderer.domElement.width=1,e.renderer.domElement.height=1),e.renderer.dispose(),e.renderer=null}if(e.control&&(e.control.dispose(),e.control=null),e.container&&e.container.parentNode){for(;e.container.firstChild;)e.container.removeChild(e.container.firstChild);e.container.parentNode.removeChild(e.container)}}),this.views=null),this._handleResize&&(window.removeEventListener("resize",this._handleResize),this._handleResize=null)}exitFourView(){this.isFourView&&(this.transformControl&&this.transformControl.parent&&this.transformControl.parent.remove(this.transformControl),this.originalCamera&&(this.camera.position.copy(this.originalCamera.position),this.mainControls.target.copy(this.originalCamera.target),this.originalCamera.up&&this.camera.up.copy(this.originalCamera.up),this.originalCamera.zoom&&(this.camera.zoom=this.originalCamera.zoom),this.originalCamera.fov&&(this.camera.fov=this.originalCamera.fov),this.camera.updateProjectionMatrix(),this.mainControls.update(),this.originalCamera=null),this._animationId&&(cancelAnimationFrame(this._animationId),this._animationId=null),this.renderer.domElement.style.display="block",this._removeViews(),window.gc&&window.gc(),this.isFourView=!1,this.transformControl&&!this.transformControl.parent&&this.scene.add(this.transformControl),this.renderer.render(this.scene,this.camera),this.activeViewIndex=-1)}onWindowResize(){this.width=this.container.clientWidth,this.height=this.container.clientHeight,this.isFourView&&this.views&&this.views.forEach(e=>{const t=e.config.layout,n=Math.floor(this.width*t.x),r=Math.floor(this.height*t.y),i=Math.floor(this.width*t.width),o=Math.floor(this.height*t.height);e.container.style.left=`${n}px`,e.container.style.top=`${r}px`,e.container.style.width=`${i}px`,e.container.style.height=`${o}px`,e.renderer.setSize(i,o);const a=i/o;e.camera.aspect=a,e.camera.updateProjectionMatrix()})}}class ef{constructor(e=50){this.history=[],this.redoStack=[],this.currentIndex=-1,this.maxHistorySteps=e,this.isPerformingAction=!1}addAction(e){this.isPerformingAction||(this.currentIndex<this.history.length-1&&(this.history.splice(this.currentIndex+1),this.redoStack=[]),this.history.push(e),this.currentIndex=this.history.length-1,this.history.length>this.maxHistorySteps&&(this.history.shift(),this.currentIndex--))}undo(){if(this.currentIndex<0)return!1;try{this.isPerformingAction=!0;const e=this.history[this.currentIndex];return e&&"function"==typeof e.undo?(e.undo(),this.redoStack.push(e),this.currentIndex--,this.isPerformingAction=!1,!0):(console.warn("撤销操作无效: 操作不存在或undo不是函数"),this.history.splice(this.currentIndex,1),this.currentIndex--,this.isPerformingAction=!1,this.undo())}catch(e){return console.error("撤销操作失败:",e),this.history.splice(this.currentIndex,1),this.currentIndex--,this.isPerformingAction=!1,!1}}redo(){if(0===this.redoStack.length)return!1;try{this.isPerformingAction=!0;const e=this.redoStack.pop();return e&&"function"==typeof e.redo?(e.redo(),this.currentIndex++,this.isPerformingAction=!1,!0):(console.warn("重做操作无效: 操作不存在或redo不是函数"),this.isPerformingAction=!1,this.redo())}catch(e){return console.error("重做操作失败:",e),this.isPerformingAction=!1,!1}}clear(){this.history=[],this.redoStack=[],this.currentIndex=-1}canUndo(){return this.currentIndex>=0}canRedo(){return this.redoStack.length>0}getState(){return{canUndo:this.canUndo(),canRedo:this.canRedo(),historyLength:this.history.length,redoLength:this.redoStack.length,currentIndex:this.currentIndex}}}class tf{constructor(e,t={}){this.options={clearColor:"#3F3F3F",backgroundColor:"#3F3F3F",showGrid:!0,showAxes:!0,showGround:!0,showLattice:!0,enableShadow:!0,maxHistorySteps:50,gridSize:1200,gridDivisions:800,gridColors:{x:16098229,z:11988135,grid:10790052},renderMode:"normal",renderModeOptions:{color:16777215,wireframeColor:0,opacity:1},storagePrefix:"iat3d-",exr:{enabled:!1,path:null,intensity:1,backgroundIntensity:1},...t},this.container=e,this.gridHelper=null,this.scene=null,this.camera=null,this.renderer=null,this.animationFrameId=null,this.lights={},this.currentRenderMode="normal",this.originalMaterials=new Map,this.exrTexture=null,this.exrLoader=null,this.initScene(),this.initCamera(),this.initRenderer(),this.initLights(),this.initEXRLoader(),this.historyManager=new ef(this.options.maxHistorySteps),this.objectManager=new po(this.scene,this.camera,this.renderer.domElement,e=>{this.options.onObjectsChanged&&this.options.onObjectsChanged(e)},e=>{this.options.onObjectSelected&&this.options.onObjectSelected(e)},e=>{this.options.onTransformModeChanged&&this.options.onTransformModeChanged(e)}),this.objectManager.setSceneManager(this),this.initModelImporter(),this.addViewHelper(),this.options.showGrid&&this.addGrid(),this.options.showAxes&&this.addAxes(),this.options.showGround&&this.addGround(),this.fourView=new Jp(this.scene,this.camera,this.renderer,this.objectManager.orbitControls),this.keyboardManager=new bl,this.LatticeController=new $p(this.scene,this.camera,this.renderer),this.LatticeController.onDeformationUpdate=e=>{this._handleDeformationUpdate(e)},window.addEventListener("resize",this.onWindowResize.bind(this)),this.animate(),this.registerHistoryShortcuts(),this.loadSavedRenderMode(),this.activeCamera=null,this.mainCamera=null,this.isUsingActiveCamera=!1,this.mainCamera=this.camera}registerHistoryShortcuts(){this.keyboardManager&&(this.keyboardManager.register("ctrl+z",()=>(this.undo(),!0)),this.keyboardManager.register("ctrl+y",()=>(this.redo(),!0)))}undo(){const e=this.historyManager.undo();return e&&this.options.onHistoryChanged&&this.options.onHistoryChanged(this.getHistoryState()),e}redo(){const e=this.historyManager.redo();return e&&this.options.onHistoryChanged&&this.options.onHistoryChanged(this.getHistoryState()),e}addActionToHistory(e){this.historyManager.addAction(e),this.options.onHistoryChanged&&this.options.onHistoryChanged(this.getHistoryState())}getHistoryState(){return this.historyManager.getState()}clearHistory(){this.historyManager.clear(),this.options.onHistoryChanged&&this.options.onHistoryChanged(this.getHistoryState())}initScene(){this.scene=new e.Scene,this.scene.background=new e.Color(this.options.backgroundColor),this.scene.fog=new e.FogExp2(this.options.backgroundColor,.005),this.scene.userData.sceneManager=this}initCamera(){const t=this.container.clientWidth,n=this.container.clientHeight;this.camera=new e.PerspectiveCamera(20,t/n,.1,1e3),this.camera.position.set(-15,-15,15),this.camera.lookAt(0,0,0),this.camera.up.set(0,0,1)}initRenderer(){this.renderer=new e.WebGLRenderer({antialias:!0,alpha:!0}),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.renderer.setClearColor(this.options.backgroundColor),this.renderer.setPixelRatio(window.devicePixelRatio),this.options.enableShadow&&(this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=e.PCFSoftShadowMap),this.container.appendChild(this.renderer.domElement)}initLights(){this.lights.ambient=new e.AmbientLight(16777215,1),this.scene.add(this.lights.ambient),this.lights.directional=new e.DirectionalLight(16777215,1),this.lights.directional.position.set(5,-5,7.5),this.lights.directional.castShadow=!0,this.lights.directional.shadow.mapSize.width=2048,this.lights.directional.shadow.mapSize.height=2048,this.lights.directional.shadow.camera.near=.5,this.lights.directional.shadow.camera.far=50,this.lights.directional.shadow.camera.left=-20,this.lights.directional.shadow.camera.right=20,this.lights.directional.shadow.camera.top=20,this.lights.directional.shadow.camera.bottom=-20,this.scene.add(this.lights.directional),this.lights.hemisphere=new e.HemisphereLight(14544639,2105376,1),this.scene.add(this.lights.hemisphere)}initEXRLoader(){this.exrLoader||(this.exrLoader=new Dt,console.log("[ThreeSceneManager] EXR加载器已初始化"),this.loadEXR("/forest.exr",{intensity:1.5,backgroundIntensity:.8,showBackground:!1}))}async loadEXR(t,n={}){if(!t)return console.warn("[ThreeSceneManager] 请提供EXR文件路径"),!1;try{return this.initEXRLoader(),console.log("[ThreeSceneManager] 开始加载EXR文件:",t),new Promise((r,i)=>{this.exrLoader.load(t,i=>{i.mapping=e.EquirectangularReflectionMapping,this.exrTexture=i,this.applyEXRToScene(i,n),this.options.exr={enabled:!0,path:t,intensity:n.intensity||1,backgroundIntensity:n.backgroundIntensity||1,...n},console.log("[ThreeSceneManager] EXR环境贴图加载成功"),this.options.onEXRLoaded&&this.options.onEXRLoaded(i,this.options.exr),r(i)},e=>{this.options.onEXRLoadProgress&&this.options.onEXRLoadProgress(e)},e=>{console.error("[ThreeSceneManager] EXR加载失败:",e),this.options.onEXRLoadError&&this.options.onEXRLoadError(e),i(e)})})}catch(e){return console.error("[ThreeSceneManager] EXR加载出错:",e),!1}}applyEXRToScene(e,t={}){if(!e||!this.scene)return;const n={intensity:1,backgroundIntensity:1,showBackground:!1,...t};this.scene.environment=e,this.scene.environmentIntensity=n.intensity,n.showBackground&&(this.scene.background=e,this.scene.backgroundIntensity=n.backgroundIntensity),console.log("[ThreeSceneManager] EXR环境贴图已应用到场景")}setEXRIntensity(e,t=null){return this.scene&&this.exrTexture?(void 0!==e&&e>=0&&(this.scene.environmentIntensity=e,this.options.exr.intensity=e),null!==t&&t>=0&&(this.scene.backgroundIntensity=t,this.options.exr.backgroundIntensity=t),console.log(`[ThreeSceneManager] EXR强度已更新: 环境=${e}, 背景=${t}`),!0):(console.warn("[ThreeSceneManager] 没有可用的EXR纹理"),!1)}setEXRBackgroundVisible(t){return this.scene&&this.exrTexture?(this.scene.background=t?this.exrTexture:new e.Color(this.options.backgroundColor),console.log("[ThreeSceneManager] EXR背景显示已"+(t?"启用":"禁用")),!0):(console.warn("[ThreeSceneManager] 没有可用的EXR纹理"),!1)}removeEXR(){this.scene&&(this.scene.environment=null,this.scene.background=new e.Color(this.options.backgroundColor),this.scene.environmentIntensity=1,this.scene.backgroundIntensity=1),this.exrTexture&&(this.exrTexture.dispose(),this.exrTexture=null),this.options.exr.enabled=!1,this.options.exr.path=null,console.log("[ThreeSceneManager] EXR环境贴图已移除"),this.options.onEXRRemoved&&this.options.onEXRRemoved()}getEXRStatus(){return{enabled:this.options.exr.enabled,hasTexture:!!this.exrTexture,path:this.options.exr.path,intensity:this.options.exr.intensity,backgroundIntensity:this.options.exr.backgroundIntensity,backgroundVisible:this.scene&&this.scene.background===this.exrTexture}}initModelImporter(){this.modelImporter=new pl(this.renderer.domElement,this.camera,this.scene,this.addObjects.bind(this))}addAxes(){const t=new e.AxesHelper(50);t.name="axesHelper",t.userData.selectable=!1,t.visible=!1,this.scene.add(t)}addGrid(){this.gridHelper=new ml({scene:this.scene,camera:this.camera,controls:this.objectManager.orbitControls,options:{size1:this.options.gridSize,size2:this.options.gridDivisions,color:this.options.gridColors.grid,axes:"xzy",centerLineColorX:this.options.gridColors.x,centerLineColorY:this.options.gridColors.z,distance:8e3}}),this.gridHelper.grid.name="gridHelper",this.gridHelper.grid.userData.selectable=!1,this.gridHelper.grid.rotation.x=-Math.PI/2,this.scene.add(this.gridHelper.grid)}addGround(){const t=new e.PlaneGeometry(2e3,2e3),n=new e.ShadowMaterial({opacity:.5}),r=new e.Mesh(t,n);r.name="shadowPlane",r.receiveShadow=!0,r.userData.selectable=!1,this.scene.add(r)}addViewHelper(){this.viewHelper=new Zp(this.camera,this.renderer.domElement),this.renderer.autoClear=!1,this.viewHelper.setOffset(210,40)}getSceneObjects(){return this.objectManager.selectableObjects}focusSelectedObject(){const t=this.objectManager.selectedObjects;if(!(t&&t.length&&this.camera&&this.objectManager.orbitControls))return console.warn("没有选中对象或场景组件未完全初始化"),!1;try{const n=(new e.Box3).setFromObject(t[0]),r=n.getSize(new e.Vector3).length(),i=n.getCenter(new e.Vector3);return this.camera.position.copy(i),this.camera.position.x+=1.5*r,this.camera.position.y+=1.5*r,this.camera.position.z+=1.5*r,this.camera.lookAt(i),this.objectManager.orbitControls.target.copy(i),this.objectManager.orbitControls.update(),!0}catch(e){return console.error("聚焦对象时出错:",e),!1}}setCameraDirectly(e,t){if(!(this.camera&&this.objectManager.orbitControls&&this.renderer&&this.scene))return!1;try{return this.camera.position.copy(e),this.objectManager.orbitControls.target.copy(t),this.camera.lookAt(t),this.objectManager.orbitControls.update(),this.renderer.render(this.scene,this.camera),!0}catch(e){return console.error("设置摄像机位置出错:",e),!1}}deleteSelectedObjects(){const e=[...this.objectManager.selectedObjects];if(!e||0===e.length)return console.warn("没有选中对象"),!1;const t=e.map(e=>({object:e,parent:e.parent,index:e.parent?Array.from(e.parent.children).indexOf(e):-1,relatedCamera:e.userData?.isCameraHelper?e.userData.parentCamera:null}));return this.objectManager.removeSelectableObjects(e),this.addActionToHistory({type:"DELETE_OBJECTS",data:{objectsData:t},undo:()=>{t.forEach(e=>{e.object&&e.parent&&(e.index>=0&&e.index<e.parent.children.length?e.parent.children.splice(e.index,0,e.object):e.parent.add(e.object),e.relatedCamera&&!e.relatedCamera.parent&&this.scene.add(e.relatedCamera),this.objectManager.addObjects(e.object))})},redo:()=>{this.objectManager.removeSelectableObjects(t.map(e=>e.object))}}),!0}createLattice(e,t={}){const n=Array.isArray(e)?e:[e];if(!n.length)return console.warn("没有提供目标对象,无法创建晶格"),!1;const r=n.filter(e=>e&&e.visible);if(!r.length)return console.warn("没有有效的目标对象,无法创建晶格"),!1;console.log(`为 ${r.length} 个对象创建统一晶格`);const i={objects:r.map(e=>({object:e,originalGeometry:e.geometry?e.geometry.clone():null,isLatticeMode:e.userData.isLatticeMode||!1})),objectManagerEnabled:this.objectManager.enabled,objectManagerBanned:this.objectManager.isBaned,transformControlsAttached:null!==this.objectManager.transformControls.object,selectedObjects:[...this.objectManager.selectedObjects],latticeConfig:{xCount:t.xCount||3,yCount:t.yCount||3,zCount:t.zCount||3,padding:void 0!==t.padding?t.padding:1}};return this.objectManager.outlineManager.removeAllHighlights(),(t.xCount||t.yCount||t.zCount)&&this.LatticeController.setGridConfig({xCount:t.xCount||3,yCount:t.yCount||3,zCount:t.zCount||3}),void 0!==t.padding&&this.LatticeController.setPadding(t.padding),this.LatticeController.setTargetObjects(r).createLattice(),this.objectManager.enabled=!1,this.objectManager.isBaned=!0,this.objectManager.transformControls.detach(),this.addActionToHistory({type:"CREATE_LATTICE",data:{beforeState:i,targetObjects:r,latticeConfig:i.latticeConfig},undo:()=>{this.LatticeController.getLatticeGrid()&&this.exitLatticeGrid(),i.objects.forEach(({object:e,originalGeometry:t,isLatticeMode:n})=>{e&&t&&(e.geometry&&e.geometry.dispose(),e.geometry=t),e&&e.userData&&(e.userData.isLatticeMode=n)}),this.objectManager.enabled=i.objectManagerEnabled,this.objectManager.isBaned=i.objectManagerBanned,this.objectManager.clearSelection(),i.selectedObjects.forEach(e=>{e&&e.parent&&(this.objectManager.selectedObjects.push(e),this.objectManager.outlineManager.addHighlight(e))}),i.transformControlsAttached&&i.selectedObjects.length>0&&this.objectManager.transformControls.attach(i.selectedObjects[0])},redo:()=>{}}),!0}exitLatticeGrid(){if(!this.LatticeController.getLatticeGrid())return console.warn("当前没有活动的晶格"),[];this.LatticeController.getTargetObjects(),this.LatticeController.getLatticeConfig(),this.LatticeController.getLatticeVerticesSnapshot(),this.LatticeController.getTargetObjects().map(e=>({object:e,geometry:e.geometry?e.geometry.clone():null})),this.objectManager.enabled,this.objectManager.isBaned;const e=this.LatticeController.exitLatticeGrid();return this.objectManager.enabled=!0,this.objectManager.isBaned=!1,e}addCube(t={}){const n={size:1,color:10790568,position:{x:0,y:.5,z:0},castShadow:!0,receiveShadow:!0,...t},r=new e.BoxGeometry(n.size,n.size,n.size,10,10,10),i=new e.MeshStandardMaterial({color:n.color}),o=new e.Mesh(r,i);return o.position.set(n.position.x,n.position.y,n.position.z),o.castShadow=n.castShadow,o.receiveShadow=n.receiveShadow,this.scene.add(o),this.addObjects(o),o}addObjects(e){const t=Array.isArray(e)?e:[e];return t.forEach(e=>{e&&!e.userData&&(e.userData={}),e&&void 0===e.userData.selectable&&(e.userData.selectable=!0),e&&e.userData.isHelper&&(e.userData.selectable=!0)}),this.objectManager.addObjects(e),this.updateObjectRenderMode(t),t.length>0&&t[0]&&t[0].userData&&!t[0].userData.skipHistory&&this.addActionToHistory({type:"ADD_OBJECTS",data:{objects:t},undo:()=>{t&&t.length>0&&this.objectManager.removeSelectableObjects(t)},redo:()=>{t&&t.length>0&&(t.forEach(e=>{if(e){(e.parent||this.scene).add(e)}}),this.objectManager.addObjects(t))}}),e}getObjectManager(){return this.objectManager}getObjectById(e){let t=null;return this.scene.traverse(n=>{n.userData&&n.userData.id===e&&(t=n)}),t}selectObject(e){e&&(this.objectManager.clearSelection(),this.objectManager.selectedObjects.push(e),this.objectManager.outlineManager.addHighlight(e),this.objectManager.transformControls.attach(e))}setTransformMode(e){this.objectManager.setTransformMode(e)}getRenderModeOptions(){const e={wireframe:"线框",solid:"实体",material:"材质预览",rendered:"渲染"};return["wireframe","solid","material","rendered"].map(t=>({value:t,label:e[t]||t}))}setRenderMode(e,t={}){if(this.currentRenderMode==e)return!1;const n=this.getModelObjects(),r={...this.options.renderModeOptions,...t};return this.currentRenderMode=e,n.forEach(t=>{this._applyRenderModeToObject(t,e,r)}),this.saveToLocalStorage("topBar-shadingMode",e),this.options.onRenderModeChanged&&this.options.onRenderModeChanged(e),!0}getCurrentRenderMode(){return this.currentRenderMode}_applyRenderModeToObject(t,n,r){if("normal"===n.toLowerCase()){const e=this.originalMaterials.get(t.uuid);return void(e&&(t.material=e,this.originalMaterials.delete(t.uuid)))}!this.originalMaterials.has(t.uuid)&&t.material&&this.originalMaterials.set(t.uuid,t.material);const i={wireframe:()=>new e.MeshBasicMaterial({color:r.wireframeColor,wireframe:!0,transparent:r.opacity<1,opacity:r.opacity}),material:()=>new e.MeshNormalMaterial({transparent:r.opacity<1,opacity:r.opacity}),rendered:()=>new e.MeshPhongMaterial({color:r.color,transparent:r.opacity<1,opacity:r.opacity,shininess:100,specular:1118481})}[n.toLowerCase()];i&&(t.material=i())}getModelObjects(){const e=this.getSceneObjects()||[],t=[],n=["gridHelper","shadowPlane","axesHelper"];return e.forEach(e=>{n.includes(e.name)||e.userData&&(e.userData.isHelper||e.userData.isHidden)||e.traverse(e=>{!e.isMesh&&e.userData.isHidden||n.includes(e.name)||t.push(e)})}),t}updateObjectRenderMode(e){if("normal"===this.currentRenderMode)return;const t=Array.isArray(e)?e:[e],n=this.options.renderModeOptions;t.forEach(e=>{e.traverse(e=>{e.isMesh&&this._applyRenderModeToObject(e,this.currentRenderMode,n)})})}onWindowResize(){if(!this.container)return;const e=this.container.clientWidth,t=this.container.clientHeight;if(this.camera){if(this.camera.isPerspectiveCamera)this.camera.aspect=e/t;else if(this.camera.isOrthographicCamera){const n=e/t,r=5;this.camera.left=-r*n,this.camera.right=r*n,this.camera.top=r,this.camera.bottom=-r}this.camera.updateProjectionMatrix()}this.savedMainCameraState&&this.mainCamera&&this.mainCamera.isPerspectiveCamera&&(this.savedMainCameraState.aspect=e/t),this.renderer&&this.renderer.setSize(e,t)}animate(){this.animationFrameId=requestAnimationFrame(this.animate.bind(this)),this.gridHelper.update(),this.objectManager&&this.objectManager.update(),this.options.onUpdate&&this.options.onUpdate(),this.renderer.render(this.scene,this.camera),this.viewHelper&&this.viewHelper.render(this.renderer)}registerShortcut(e,t){this.keyboardManager.register(e,t)}dispose(){this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),window.removeEventListener("resize",this.onWindowResize),this.objectManager&&this.objectManager.dispose(),this.historyManager.clear(),this.exrTexture&&(this.exrTexture.dispose(),this.exrTexture=null),this.renderer&&(this.renderer.dispose(),this.container&&this.container.removeChild(this.renderer.domElement)),this.scene=null,this.camera=null,this.renderer=null,this.lights={},this.objectManager=null,this.historyManager=null,this.keyboardManager&&this.keyboardManager.dispose(),this.originalMaterials.clear(),this.originalMaterials=null}setActiveCamera(e){if(!e||!e.isCamera)return console.warn("提供的对象不是有效的相机"),!1;const t=this.isUsingActiveCamera;return this.activeCamera=e,console.log("活动相机已设置:",e.userData.cameraType||"unknown"),t&&e&&setTimeout(()=>{this.switchToActiveCameraView()},10),this.options.onActiveCameraChanged&&this.options.onActiveCameraChanged(e),!0}isInActiveCameraView(){return this.isUsingActiveCamera}clearActiveCamera(){this.isUsingActiveCamera&&this.switchToMainCameraView(),this.activeCamera=null,this.savedMainCameraState=null,this.savedOrbitControlsState=null,this.options.onActiveCameraChanged&&this.options.onActiveCameraChanged(null),console.log("活动相机已清除")}getActiveCamera(){return this.activeCamera}getSceneCameras(){const e=[];return this.scene.traverse(t=>{t.userData&&t.userData.isCameraHelper&&t.userData.parentCamera&&e.push({helper:t,camera:t.userData.parentCamera,name:t.userData.parentCamera.name||`相机_${t.userData.parentCamera.uuid.substring(0,8)}`,type:t.userData.parentCamera.isPerspectiveCamera?"perspective":"orthographic"})}),e}updateCameraDependencies(){this.viewHelper&&(this.viewHelper.camera=this.camera),this.objectManager&&(this.objectManager.camera=this.camera,this.objectManager.transformControls&&(this.objectManager.transformControls.camera=this.camera),this.objectManager.orbitControls&&(this.objectManager.orbitControls.object=this.camera,this.objectManager.orbitControls.update())),this.fourView&&(this.fourView.camera=this.camera),this.LatticeController&&(this.LatticeController.camera=this.camera)}switchToActiveCameraView(){if(!this.activeCamera)return console.warn("没有设置活动相机"),!1;try{this.isUsingActiveCamera||(this.saveMainCameraState(),console.log("已保存主相机状态")),this.objectManager&&(this.objectManager.clearSelection(),this.objectManager.outlineManager.removeAllHighlights()),this.objectManager.transformControls.detach(),this.disableActiveCameraHelper(),console.log(this.activeCamera,"活动相机");const t=this.container.clientWidth,n=this.container.clientHeight;if(this.activeCamera.isPerspectiveCamera)this.activeCamera.aspect=t/n;else if(this.activeCamera.isOrthographicCamera){const e=t/n,r=5;this.activeCamera.left=-r*e,this.activeCamera.right=r*e,this.activeCamera.top=r,this.activeCamera.bottom=-r}this.activeCamera.updateProjectionMatrix(),this.camera=this.activeCamera,this.isUsingActiveCamera=!0,this.updateCameraDependencies();const r=new e.Vector3(0,0,-1);r.applyQuaternion(this.activeCamera.quaternion);const i=10,o=this.activeCamera.position.clone().add(r.multiplyScalar(i));return this.objectManager.orbitControls&&(this.objectManager.orbitControls.object=this.activeCamera,this.objectManager.orbitControls.target.copy(o),this.objectManager.orbitControls.update()),console.log("已固定到活动相机视角"),this.options.onCameraViewChanged&&this.options.onCameraViewChanged(this.activeCamera,!0),!0}catch(e){return console.error("切换到活动相机视角失败:",e),!1}}saveMainCameraState(){this.mainCamera&&(this.savedMainCameraState?console.log("主相机状态已存在,跳过保存"):(this.savedMainCameraState={position:this.mainCamera.position.clone(),rotation:this.mainCamera.rotation.clone(),quaternion:this.mainCamera.quaternion.clone(),fov:this.mainCamera.fov,aspect:this.mainCamera.aspect,near:this.mainCamera.near,far:this.mainCamera.far,left:this.mainCamera.left,right:this.mainCamera.right,top:this.mainCamera.top,bottom:this.mainCamera.bottom},this.objectManager.orbitControls&&(this.savedOrbitControlsState={target:this.objectManager.orbitControls.target.clone(),position0:this.objectManager.orbitControls.position0.clone(),target0:this.objectManager.orbitControls.target0.clone(),zoom0:this.objectManager.orbitControls.zoom0,enableDamping:this.objectManager.orbitControls.enableDamping,dampingFactor:this.objectManager.orbitControls.dampingFactor,enabled:this.objectManager.orbitControls.enabled,autoRotate:this.objectManager.orbitControls.autoRotate,spherical:{radius:this.objectManager.orbitControls.getDistance(),phi:this.objectManager.orbitControls.getPolarAngle(),theta:this.objectManager.orbitControls.getAzimuthalAngle()}}),console.log("主相机状态已首次保存")))}switchToMainCameraView(){if(!this.isUsingActiveCamera||!this.mainCamera)return console.warn("当前未使用活动相机视角"),!1;try{if(this.enableActiveCameraHelper(),this.camera=this.mainCamera,this.isUsingActiveCamera=!1,this.savedMainCameraState)this.restoreMainCameraState();else{const e=this.container.clientWidth,t=this.container.clientHeight;this.camera.isPerspectiveCamera&&(this.camera.aspect=e/t,this.camera.updateProjectionMatrix())}return this.updateCameraDependencies(),this.objectManager.orbitControls&&this.restoreOrbitControlsState(),console.log("已返回主相机视角"),this.options.onCameraViewChanged&&this.options.onCameraViewChanged(this.camera,!1),!0}catch(e){return console.error("返回主相机视角失败:",e),!1}}restoreMainCameraState(){if(this.savedMainCameraState&&this.mainCamera)try{this.mainCamera.position.copy(this.savedMainCameraState.position),this.mainCamera.rotation.copy(this.savedMainCameraState.rotation),this.mainCamera.quaternion.copy(this.savedMainCameraState.quaternion),this.mainCamera.isPerspectiveCamera?(this.mainCamera.fov=this.savedMainCameraState.fov,this.mainCamera.aspect=this.savedMainCameraState.aspect,this.mainCamera.near=this.savedMainCameraState.near,this.mainCamera.far=this.savedMainCameraState.far):this.mainCamera.isOrthographicCamera&&(this.mainCamera.left=this.savedMainCameraState.left,this.mainCamera.right=this.savedMainCameraState.right,this.mainCamera.top=this.savedMainCameraState.top,this.mainCamera.bottom=this.savedMainCameraState.bottom,this.mainCamera.near=this.savedMainCameraState.near,this.mainCamera.far=this.savedMainCameraState.far),this.mainCamera.updateProjectionMatrix(),console.log("主相机状态已恢复")}catch(e){console.error("恢复主相机状态失败:",e)}}restoreOrbitControlsState(){if(!this.objectManager.orbitControls||!this.savedOrbitControlsState)return;const t=this.objectManager.orbitControls,n=this.savedOrbitControlsState;try{if(t.enabled=!1,t.object=this.camera,t.target.copy(n.target),n.position0&&t.position0.copy(n.position0),n.target0&&t.target0.copy(n.target0),void 0!==n.zoom0&&(t.zoom0=n.zoom0),n.spherical){const t=n.spherical,r=new e.Vector3;r.setFromSphericalCoords(t.radius,t.phi,t.theta),this.camera.position.copy(n.target).add(r)}t.enableDamping=n.enableDamping,t.dampingFactor=n.dampingFactor,t.autoRotate=n.autoRotate,this.camera.updateMatrixWorld(!0),t.update(),setTimeout(()=>{t&&void 0!==n.enabled&&(t.enabled=n.enabled)},100),console.log("轨道控制器状态已恢复")}catch(e){console.error("恢复轨道控制器状态失败:",e),t.enabled=!0}}syncCameraFOV(e){!e||e<=0||e>=180||(this.scene.traverse(t=>{if(t.userData&&t.userData.isCameraHelper&&t.userData.parentCamera){const n=t.userData.parentCamera;n.isPerspectiveCamera&&n!==this.mainCamera&&(n.fov=e,n.updateProjectionMatrix(),t.update&&"function"==typeof t.update&&t.update())}}),console.log("已同步场景中的透视相机FOV(不包括主相机)"))}syncOrthographicCameraParams(e){e&&(this.scene.traverse(t=>{if(t.userData&&t.userData.isCameraHelper&&t.userData.parentCamera){const n=t.userData.parentCamera;n.isOrthographicCamera&&n!==this.mainCamera&&(void 0!==e.left&&(n.left=e.left),void 0!==e.right&&(n.right=e.right),void 0!==e.top&&(n.top=e.top),void 0!==e.bottom&&(n.bottom=e.bottom),n.updateProjectionMatrix(),t.update&&"function"==typeof t.update&&t.update())}}),console.log("已同步场景中的正交相机参数(不包括主相机)"))}disableActiveCameraHelper(){this.activeCamera&&this.scene.traverse(e=>{if(e.userData&&e.userData.isCameraHelper&&e.userData.parentCamera===this.activeCamera){if(e.userData.selectable=!1,this.objectManager&&this.objectManager.selectedObjects.includes(e)){const t=this.objectManager.selectedObjects.indexOf(e);-1!==t&&this.objectManager.selectedObjects.splice(t,1),this.objectManager.outlineManager.removeHighlight(e),0===this.objectManager.selectedObjects.length?this.objectManager.transformControls.detach():this.objectManager._attachTransformToMultipleObjects(this.objectManager.selectedObjects),this.objectManager.onSelectionChange&&this.objectManager.onSelectionChange(this.objectManager.selectedObjects)}const t=this.objectManager.selectableObjects.indexOf(e);-1!==t&&(e.userData.originalSelectableIndex=t,this.objectManager.selectableObjects.splice(t,1)),console.log("已禁用活动相机辅助器的选择功能")}})}enableActiveCameraHelper(){this.activeCamera&&this.scene.traverse(e=>{if(e.userData&&e.userData.isCameraHelper&&e.userData.parentCamera===this.activeCamera){if(e.userData.selectable=!0,!this.objectManager.selectableObjects.includes(e)){const t=e.userData.originalSelectableIndex;void 0!==t&&t>=0&&t<=this.objectManager.selectableObjects.length?this.objectManager.selectableObjects.splice(t,0,e):this.objectManager.selectableObjects.push(e),delete e.userData.originalSelectableIndex}console.log("已启用活动相机辅助器的选择功能")}})}handleCameraParamSync(e,t){this.isUsingActiveCamera&&this.activeCamera&&("fov"===e&&this.activeCamera.isPerspectiveCamera&&this.syncCameraFOV(t),this.activeCamera.isOrthographicCamera&&["left","right","top","bottom"].includes(e)&&this.syncOrthographicParamsToOtherCameras())}syncOrthographicParamsToOtherCameras(){if(!this.activeCamera||!this.activeCamera.isOrthographicCamera)return;this.activeCamera.left,this.activeCamera.right;const e=(this.activeCamera.top-this.activeCamera.bottom)/2;this.scene.traverse(t=>{if(t.userData&&t.userData.isCameraHelper&&t.userData.parentCamera){const n=t.userData.parentCamera;if(n.isOrthographicCamera&&n!==this.activeCamera&&n!==this.mainCamera){const r=this.container.clientWidth/this.container.clientHeight;n.left=-e*r,n.right=e*r,n.top=e,n.bottom=-e,n.updateProjectionMatrix(),t.update&&"function"==typeof t.update&&t.update()}}})}_handleDeformationUpdate(e){e&&0!==e.length&&this.objectManager.updateDeformedObjects(e)}saveToLocalStorage(e,t){try{const n=`${this.options.storagePrefix}${e}`,r="object"==typeof t?JSON.stringify(t):t.toString();localStorage.setItem(n,r)}catch(t){console.warn(`[ThreeSceneManager] 无法保存 ${e} 到本地存储:`,t)}}getFromLocalStorage(e,t=null){try{const n=`${this.options.storagePrefix}${e}`,r=localStorage.getItem(n);if(null===r)return t;try{return JSON.parse(r)}catch{return r}}catch(n){return console.warn(`[ThreeSceneManager] 无法从本地存储获取 ${e}:`,n),t}}loadSavedRenderMode(){try{const e=this.getFromLocalStorage("topBar-shadingMode","normal");["wireframe","normal","material","rendered"].includes(e)&&"normal"!==e&&(this.currentRenderMode=e,setTimeout(()=>{this.setRenderMode(e)},100))}catch(e){console.error("[ThreeSceneManager] 加载保存的着色模式失败:",e)}}convertToPBRMaterial(t,n={}){if(!t||!t.material)return console.warn("对象没有材质,无法转换为PBR材质"),!1;const r=t.material;if(r.isMeshStandardMaterial||r.isMeshPhysicalMaterial)return console.log("材质已经是PBR材质"),!0;const i=new e.MeshStandardMaterial({color:r.color?r.color.clone():new e.Color(16777215),map:r.map||null,transparent:r.transparent||!1,opacity:void 0!==r.opacity?r.opacity:1,side:void 0!==r.side?r.side:e.FrontSide,wireframe:r.wireframe||!1,metalness:void 0!==n.metalness?n.metalness:.5,roughness:void 0!==n.roughness?n.roughness:.5,normalMap:r.normalMap||null,bumpMap:r.bumpMap||null,envMap:r.envMap||null});return t.material=i,r.dispose&&r.dispose(),console.log("材质已转换为PBR材质"),!0}}class nf extends e.LineSegments{constructor(t){const n=new e.BufferGeometry,r=new e.LineBasicMaterial({color:16777215,vertexColors:!0,toneMapped:!1,transparent:!0,opacity:.8}),i=[],o=[],a={};function s(e,t){c(e),c(t)}function c(e){i.push(0,0,0),o.push(0,0,0),void 0===a[e]&&(a[e]=[]),a[e].push(i.length/3-1)}s("p","n1"),s("p","n2"),s("p","n3"),s("p","n4"),s("n1","n2"),s("n2","n4"),s("n4","n3"),s("n3","n1"),n.setAttribute("position",new e.Float32BufferAttribute(i,3)),n.setAttribute("color",new e.Float32BufferAttribute(o,3)),super(n,r),this.type="OptimizedCameraHelper",this.camera=t,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=a,this.update();const l=new e.Color(16711680),u=new e.Color(16755200);this.setColors(l,u)}setColors(e,t){const n=this.geometry.getAttribute("color");let r=0;for(let t=0;t<8;t++)n.setXYZ(r++,e.r,e.g,e.b);for(let e=0;e<8;e++)n.setXYZ(r++,t.r,t.g,t.b);n.needsUpdate=!0}update(){const t=this.geometry,n=this.pointMap,r=new e.Vector3,i=new e.Camera;i.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse),this.setPoint("p",n,t,i,0,0,-1.4,r),this.setPoint("n1",n,t,i,-3,-3,-1,r),this.setPoint("n2",n,t,i,3,-3,-1,r),this.setPoint("n3",n,t,i,-3,3,-1,r),this.setPoint("n4",n,t,i,3,3,-1,r),t.getAttribute("position").needsUpdate=!0}setPoint(e,t,n,r,i,o,a,s){s.set(i,o,a).unproject(r);const c=t[e];if(void 0!==c){const e=n.getAttribute("position");for(let t=0,n=c.length;t<n;t++)e.setXYZ(c[t],s.x,s.y,s.z)}}dispose(){this.geometry.dispose(),this.material.dispose()}}export{nf as CameraHelper,lo as ContextMenu,gl as EventEmitter,Jp as FourView,ml as GridHelper,ef as HistoryManager,bl as KeyboardManager,$p as LatticeController,pl as ModelImporter,po as ObjectManager,co as OutlineManager,tf as ThreeSceneManager,Zp as ViewHelper,hl as handleDrop};