@mulmoclaude/shapescript-plugin 2.5.0 → 2.5.1

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.
@@ -20,5 +20,5 @@ This License becomes null and void to the extent applicable to Fonts or Font Sof
20
20
  The Font Software may be sold as part of a larger software package but no copy of one or more of the Font Software typefaces may be sold by itself. \r
21
21
  \r
22
22
  THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL MAGENTA OR PERSONS OR BODIES IN CHARGE OF ADMINISTRATION AND MAINTENANCE OF THE FONT SOFTWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.`,manufacturer_name:`Μagenta ltd`,font_sub_family_name:`Regular`},descender:-334,familyName:`Helvetiker`,lineHeight:1522,underlineThickness:50}.glyphs,fl=.718/1013,pl=1,ml=`?`,hl=2e3,gl=1e-12;function _l(e,t){if(!e.o)return[];let n=new xs,r=e.o.split(` `),i=0,a=()=>Number(r[i++]);for(;i<r.length;)switch(r[i++]){case`m`:n.moveTo(a(),a());break;case`l`:n.lineTo(a(),a());break;case`q`:{let[e,t,r,i]=[a(),a(),a(),a()];n.quadraticCurveTo(r,i,e,t);break}case`b`:{let[e,t,r,i,o,s]=[a(),a(),a(),a(),a(),a()];n.bezierCurveTo(r,i,o,s,e,t);break}}return n.subPaths.map(e=>vl(e.getPoints(t)))}function vl(e){let t=e[e.length-1];return e.length>1&&t&&t.equals(e[0])?e.slice(0,-1):e}function yl(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n],i=e[(n+1)%e.length];t+=r.x*i.y-i.x*r.y}return t/2}function bl(e,t){let n=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){let a=e[r],o=e[i];a.y>t.y!=o.y>t.y&&t.x<(o.x-a.x)*(t.y-a.y)/(o.y-a.y)+a.x&&(n=!n)}return n}function xl(e){let t=e.filter(e=>e.length>=3&&Math.abs(yl(e))>gl),n=t.map((e,n)=>t.flatMap((t,r)=>r!==n&&bl(t,e[0])?[r]:[])),r=new Map;return n.forEach((e,n)=>{e.length%2==0&&r.set(n,new ua(t[n]))}),n.forEach((e,i)=>{if(e.length%2==0)return;let a=e.find(t=>n[t].length===e.length-1);a!==void 0&&r.get(a)?.holes.push(new la(t[i]))}),[...r.values()]}var Sl=e=>dl[e];function Cl(e){let t=0;for(let n of e)t+=(Sl(n)??Sl(ml)).ha*fl;return t}function wl(e,t){let n=[],r=``;for(let i of e.split(` `)){let e=r?`${r} ${i}`:i;r&&Cl(e)>t?(n.push(r),r=i):r=e}return n.push(r),n}function Tl(e,t,n){return e.map(e=>new q(e.x*fl+t,e.y*fl+n))}function El(e,t){let n=new Map,r={shapes:[],rings:[],missing:[]};return e.split(`
23
- `).flatMap(e=>t.wrapWidth===void 0?[e]:wl(e,t.wrapWidth)).forEach((e,i)=>{let a=-i*(pl+t.lineSpacing),o=0;for(let i of e){let e=Sl(i);e||=(r.missing.push(i),Sl(ml));let s=e===Sl(i)?i:ml,c=n.get(s)??_l(e,t.curveSegments);n.set(s,c);let l=c.map(e=>Tl(e,o,a));r.rings.push(...l),r.shapes.push(...xl(l)),o+=e.ha*fl}}),r}function Dl(e,t){let n=``,r=!1;for(let i of e)typeof i==`string`?(n+=i,r=!1):(r&&(n+=` `),n+=t(i),r=!0);return n}var Ol=1.25,kl=65535,Al=2**-24,jl=Symbol(`SKIP_GENERATION`),Ml={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[jl]:!1};function Nl(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 Pl(e){let t=-1,n=-1/0;for(let r=0;r<3;r++){let i=e[r+3]-e[r];i>n&&(n=i,t=r)}return t}function Fl(e,t){t.set(e)}function Il(e,t,n){let r,i;for(let a=0;a<3;a++){let o=a+3;r=e[a],i=t[a],n[a]=r<i?r:i,r=e[o],i=t[o],n[o]=r>i?r:i}}function Ll(e,t,n){for(let r=0;r<3;r++){let i=t[e+2*r],a=t[e+2*r+1],o=i-a,s=i+a;o<n[r]&&(n[r]=o),s>n[r+3]&&(n[r+3]=s)}}function Rl(e){let t=e[3]-e[0],n=e[4]-e[1],r=e[5]-e[2];return 2*(t*n+n*r+r*t)}function zl(e,t){return t[e+15]===kl}function Bl(e,t){return t[e+6]}function Vl(e,t){return t[e+14]}function Hl(e){return e+8}function Ul(e,t){return e+t[e+6]*8}function Wl(e,t){return t[e+7]}function Gl(e){return e}function Kl(e,t,n,r,i){let a=1/0,o=1/0,s=1/0,c=-1/0,l=-1/0,u=-1/0,d=1/0,f=1/0,p=1/0,m=-1/0,h=-1/0,g=-1/0,_=e.offset||0;for(let r=(t-_)*6,i=(t+n-_)*6;r<i;r+=6){let t=e[r+0],n=e[r+1],i=t-n,_=t+n;i<a&&(a=i),_>c&&(c=_),t<d&&(d=t),t>m&&(m=t);let v=e[r+2],y=e[r+3],b=v-y,x=v+y;b<o&&(o=b),x>l&&(l=x),v<f&&(f=v),v>h&&(h=v);let S=e[r+4],C=e[r+5],w=S-C,T=S+C;w<s&&(s=w),T>u&&(u=T),S<p&&(p=S),S>g&&(g=S)}r[0]=a,r[1]=o,r[2]=s,r[3]=c,r[4]=l,r[5]=u,i[0]=d,i[1]=f,i[2]=p,i[3]=m,i[4]=h,i[5]=g}var ql=32,Jl=(e,t)=>e.candidate-t.candidate,Yl=Array(ql).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Xl=new Float32Array(6);function Zl(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=Pl(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=Pl(e),o!==-1&&(s=Ql(n,r,i,o));else if(a===2){let a=Rl(e),c=Ol*i,l=n.offset||0,u=(r-l)*6,d=(r+i-l)*6;for(let e=0;e<3;e++){let r=t[e],l=(t[e+3]-r)/ql;if(i<ql/4){let t=[...Yl];t.length=i;let r=0;for(let i=u;i<d;i+=6,r++){let a=t[r];a.candidate=n[i+2*e],a.count=0;let{bounds:o,leftCacheBounds:s,rightCacheBounds:c}=a;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,o[e]=1/0,o[e+3]=-1/0;Ll(i,n,o)}t.sort(Jl);let l=i;for(let e=0;e<l;e++){let n=t[e];for(;e+1<l&&t[e+1].candidate===n.candidate;)t.splice(e+1,1),l--}for(let r=u;r<d;r+=6){let i=n[r+2*e];for(let e=0;e<l;e++){let a=t[e];i>=a.candidate?Ll(r,n,a.rightCacheBounds):(Ll(r,n,a.leftCacheBounds),a.count++)}}for(let n=0;n<l;n++){let r=t[n],l=r.count,u=i-r.count,d=r.leftCacheBounds,f=r.rightCacheBounds,p=0;l!==0&&(p=Rl(d)/a);let m=0;u!==0&&(m=Rl(f)/a);let h=1+Ol*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<ql;e++){let t=Yl[e];t.count=0,t.candidate=r+l+e*l;let n=t.bounds;for(let e=0;e<3;e++)n[e]=1/0,n[e+3]=-1/0}for(let t=u;t<d;t+=6){let i=~~((n[t+2*e]-r)/l);i>=ql&&(i=31);let a=Yl[i];a.count++,Ll(t,n,a.bounds)}let t=Yl[31];Fl(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){let t=Yl[e],n=Yl[e+1];Il(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<31;t++){let n=Yl[t],r=n.count,l=n.bounds,u=Yl[t+1].rightCacheBounds;r!==0&&(f===0?Fl(l,Xl):Il(l,Xl,Xl)),f+=r;let d=0,p=0;f!==0&&(d=Rl(Xl)/a);let m=i-f;m!==0&&(p=Rl(u)/a);let h=1+Ol*(d*f+p*m);h<c&&(o=e,c=h,s=n.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${a} used.`);return{axis:o,pos:s}}function Ql(e,t,n,r){let i=0,a=e.offset;for(let o=t,s=t+n;o<s;o++)i+=e[(o-a)*6+r*2];return i/n}var $l=class{constructor(){this.boundingData=new Float32Array(6)}};function eu(e,t,n,r,i,a){let o=r,s=r+i-1,c=a.pos,l=a.axis*2,u=n.offset||0;for(;;){for(;o<=s&&n[(o-u)*6+l]<c;)o++;for(;o<=s&&n[(s-u)*6+l]>=c;)s--;if(o<s){for(let n=0;n<t;n++){let r=e[o*t+n];e[o*t+n]=e[s*t+n],e[s*t+n]=r}for(let e=0;e<6;e++){let t=o-u,r=s-u,i=n[t*6+e];n[t*6+e]=n[r*6+e],n[r*6+e]=i}o++,s--}else return o}}var tu,nu,ru,iu,au=2**32;function ou(e){return`count`in e?1:1+ou(e.left)+ou(e.right)}function su(e,t,n){return tu=new Float32Array(n),nu=new Uint32Array(n),ru=new Uint16Array(n),iu=new Uint8Array(n),cu(e,t)}function cu(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)tu[n+e]=a[e];if(i)return t.buffer?(iu.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(nu[n+6]=t.offset,ru[r+14]=t.count,ru[r+15]=kl,e+32);{let{left:r,right:i,splitAxis:a}=t,o=cu(e+32,r),s=e/32,c=o/32-s;if(c>au)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return nu[n+6]=c,nu[n+7]=a,cu(o,i)}}function lu(e,t,n,r,i,a){let{maxDepth:o,verbose:s,targetLeafSize:c,_strictLeafSize:l=1/0,strategy:u,onProgress:d}=i,f=e.primitiveBuffer,p=e.primitiveBufferStride,m=new Float32Array(6),h=!1,g=new $l;return Kl(t,n,r,g.boundingData,m),v(g,n,r,m),g;function _(e){d&&d((e-a.offset)/a.count)}function v(e,n,r,i=null,a=0){!h&&a>=o&&(h=!0,s&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));let d=r>l;if(r<=c&&!d||a>=o)return _(n+r),e.offset=n,e.count=r,e;let g=Zl(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:eu(f,p,t,n,r,g);if(g.axis===-1||y===n||y===n+r){if(!d)return _(n+r),e.offset=n,e.count=r,e;g.axis=Math.max(0,Pl(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new $l,x=n,S=y-n;e.left=b,Kl(t,x,S,b.boundingData,m),v(b,x,S,m,a+1);let C=new $l,w=y,T=r-S;return e.right=C,Kl(t,w,T,C.boundingData,m),v(C,w,T,m,a+1),e}}function uu(e,t){let n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=e.getRootRanges(t.range),i=r[0],a=r[r.length-1],o={offset:i.offset,count:a.offset+a.count-i.offset},s=new Float32Array(6*o.count);s.offset=o.offset,e.computePrimitiveBounds(o.offset,o.count,s),e._roots=r.map(r=>{let i=lu(e,s,r.offset,r.count,t,o),a=ou(i),c=new n(32*a);return su(0,i,c),c})}var du=class{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){let e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}},$=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let e=[],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,e.length!==0&&this.setBuffer(e.pop())}}},fu,pu,mu=[],hu=new du(()=>new er);function gu(e,t,n,r,i,a){fu=hu.getPrimitive(),pu=hu.getPrimitive(),mu.push(fu,pu),$.setBuffer(e._roots[t]);let o=_u(0,e.geometry,n,r,i,a);$.clearBuffer(),hu.releasePrimitive(fu),hu.releasePrimitive(pu),mu.pop(),mu.pop();let s=mu.length;return s>0&&(pu=mu[s-1],fu=mu[s-2]),o}function _u(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=$,u=e*2;if(zl(u,c)){let t=Bl(e,l),n=Vl(u,c);return Nl(Gl(e),s,fu),r(t,n,!1,o,a+e/8,fu)}{let u=Hl(e),p=Ul(e,l),m=u,h=p,g,_,v,y;if(i&&(v=fu,y=pu,Nl(Gl(m),s,v),Nl(Gl(h),s,y),g=i(v),_=i(y),_<g)){m=p,h=u;let e=g;g=_,_=e,v=y}v||(v=fu,Nl(Gl(m),s,v));let b=zl(m*2,c),x=n(v,b,g,o+1,a+m/8),S;if(x===2){let e=d(m);S=r(e,f(m)-e,!0,o+1,a+m/8,v)}else S=x&&_u(m,t,n,r,i,a,o+1);if(S)return!0;y=pu,Nl(Gl(h),s,y);let C=zl(h*2,c),w=n(y,C,_,o+1,a+h/8),T;if(w===2){let e=d(h);T=r(e,f(h)-e,!0,o+1,a+h/8,y)}else T=w&&_u(h,t,n,r,i,a,o+1);if(T)return!0;return!1;function d(e){let{uint16Array:t,uint32Array:n}=$,r=e*2;for(;!zl(r,t);)e=Hl(e),r=e*2;return Bl(e,n)}function f(e){let{uint16Array:t,uint32Array:n}=$,r=e*2;for(;!zl(r,t);)e=Ul(e,n),r=e*2;return Bl(e,n)+Vl(r,t)}}}var vu=new $.constructor,yu=new $.constructor,bu=new du(()=>new er),xu=new er,Su=new er,Cu=new er,wu=new er,Tu=!1;function Eu(e,t,n,r){if(Tu)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);Tu=!0;let i=e._roots,a=t._roots,o,s=0,c=0,l=new Y().copy(n).invert();for(let e=0,t=i.length;e<t;e++){vu.setBuffer(i[e]),c=0;let t=bu.getPrimitive();Nl(Gl(0),vu.float32Array,t),t.applyMatrix4(l);for(let e=0,i=a.length;e<i&&(yu.setBuffer(a[e]),o=Du(0,0,n,l,r,s,c,0,0,t),yu.clearBuffer(),c+=a[e].byteLength/32,!o);e++);if(bu.releasePrimitive(t),vu.clearBuffer(),s+=i[e].byteLength/32,o)break}return Tu=!1,o}function Du(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=yu,f=vu):(d=vu,f=yu);let p=d.float32Array,m=d.uint32Array,h=d.uint16Array,g=f.float32Array,_=f.uint32Array,v=f.uint16Array,y=e*2,b=t*2,x=zl(y,h),S=zl(b,v),C=!1;if(S&&x)C=u?i(Bl(t,_),Vl(t*2,v),Bl(e,m),Vl(e*2,h),c,o+t/8,s,a+e/8):i(Bl(e,m),Vl(e*2,h),Bl(t,_),Vl(t*2,v),s,a+e/8,c,o+t/8);else if(S){let l=bu.getPrimitive();Nl(Gl(t),g,l),l.applyMatrix4(n);let d=Hl(e),f=Ul(e,m);Nl(Gl(d),p,xu),Nl(Gl(f),p,Su);let h=l.intersectsBox(xu),_=l.intersectsBox(Su);C=h&&Du(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&Du(t,f,r,n,i,o,a,c,s+1,l,!u),bu.releasePrimitive(l)}else{let d=Hl(t),f=Ul(t,_);Nl(Gl(d),g,Cu),Nl(Gl(f),g,wu);let h=l.intersectsBox(Cu),v=l.intersectsBox(wu);if(h&&v)C=Du(e,d,n,r,i,a,o,s,c+1,l,u)||Du(e,f,n,r,i,a,o,s,c+1,l,u);else if(h){if(x)C=Du(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=bu.getPrimitive();t.copy(Cu).applyMatrix4(n);let l=Hl(e),f=Ul(e,m);Nl(Gl(l),p,xu),Nl(Gl(f),p,Su);let h=t.intersectsBox(xu),g=t.intersectsBox(Su);C=h&&Du(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&Du(d,f,r,n,i,o,a,c,s+1,t,!u),bu.releasePrimitive(t)}}else if(v){if(x)C=Du(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=bu.getPrimitive();t.copy(wu).applyMatrix4(n);let l=Hl(e),d=Ul(e,m);Nl(Gl(l),p,xu),Nl(Gl(d),p,Su);let h=t.intersectsBox(xu),g=t.intersectsBox(Su);C=h&&Du(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&Du(f,d,r,n,i,o,a,c,s+1,t,!u),bu.releasePrimitive(t)}}}return C}var Ou=new class{constructor(){let e=null,t=null,n=null,r=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(i,a)=>{if(r)throw Error(`BVHTraversalHelper: cannot call setBVH during an active traversal.`);this.root=a,this.buffer=e=i._roots[a],this.uint16Array=n=new Uint16Array(e),this.uint32Array=t=new Uint32Array(e)},this.reset=()=>{this.root=null,this.buffer=e=null,this.uint16Array=n=null,this.uint32Array=t=null},this.getRangeStart=e=>{let r=e*2;for(;!zl(r,n);)e=Hl(e),r=e*2;return Bl(e,t)},this.getRangeEnd=e=>{let r=e*2;for(;!zl(r,n);)e=Ul(e,t),r=e*2;return Bl(e,t)+Vl(r,n)};let i=(e,r,a)=>{let o=zl(r*2,n);if(!e(a,o,r)&&!o){let n=Hl(r),o=Ul(r,t);i(e,n,a+1),i(e,o,a+1)}};this.traverseBuffer=e=>{if(r)throw Error(`BVHTraversalHelper: cannot start a traversal during an active traversal.`);r=!0;try{i(e,0,0)}finally{r=!1}},this.traverse=r=>{this.traverseBuffer((i,a,o)=>{if(a){let s=o*2,c=t[o+6],l=n[s+14];return r(i,a,new Float32Array(e,o*4,6),c,l)}{let n=Wl(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},ku=new er,Au=new Float32Array(6),ju=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Ml,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),uu(this,e)}getRootRanges(){throw Error(`BVH: getRootRanges() not implemented`)}writePrimitiveBounds(){throw Error(`BVH: writePrimitiveBounds() not implemented`)}writePrimitiveRangeBounds(e,t,n,r){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let n=e,r=e+t;n<r;n++){this.writePrimitiveBounds(n,Au,0);let[e,t,r,u,d,f]=Au;e<i&&(i=e),u>s&&(s=u),t<a&&(a=t),d>c&&(c=d),r<o&&(o=r),f>l&&(l=f)}return n[r+0]=i,n[r+1]=a,n[r+2]=o,n[r+3]=s,n[r+4]=c,n[r+5]=l,n}computePrimitiveBounds(e,t,n){let r=n.offset||0;for(let i=e,a=e+t;i<a;i++){this.writePrimitiveBounds(i,Au,0);let[e,t,a,o,s,c]=Au,l=(e+o)/2,u=(t+s)/2,d=(a+c)/2,f=(o-e)/2,p=(s-t)/2,m=(c-a)/2,h=(i-r)*6;n[h+0]=l,n[h+1]=f+(Math.abs(l)+f)*Al,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*Al,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*Al}return n}shiftPrimitiveOffsets(e){let t=this._indirectBuffer;if(t)for(let n=0,r=t.length;n<r;n++)t[n]+=e;else{let t=this._roots;for(let n=0;n<t.length;n++){let r=t[n],i=new Uint32Array(r),a=new Uint16Array(r),o=r.byteLength/32;for(let t=0;t<o;t++){let n=8*t;zl(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){Ou.setBVH(this,t),Ou.traverse(e),Ou.reset()}refit(){let e=this._roots;for(let t=0,n=e.length;t<n;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n),a=new Float32Array(n),o=n.byteLength/32;for(let e=o-1;e>=0;e--){let t=e*8,n=t*2;if(zl(n,i)){let e=Bl(t,r),o=Vl(n,i);this.writePrimitiveRangeBounds(e,o,Au,0),a.set(Au,t)}else{let e=Hl(t),n=Ul(t,r);for(let r=0;r<3;r++){let i=a[e+r],o=a[e+r+3],s=a[n+r],c=a[n+r+3];a[t+r]=i<s?i:s,a[t+r+3]=o>c?o:c}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Nl(0,new Float32Array(t),ku),e.union(ku)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:r,intersectsPrimitive:i,scratchPrimitive:a,iterate:o}=e;if(r&&i){let e=r;r=(t,n,r,s,c)=>e(t,n,r,s,c)?!0:o(t,n,this,i,r,s,a)}else r||=i?(e,t,n,r)=>o(e,t,this,i,n,r,a):(e,t,n)=>n;let s=!1,c=0,l=this._roots;for(let e=0,i=l.length;e<i;e++){let i=l[e];if(s=gu(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Eu(this,e,t,r)}};function Mu(){return typeof SharedArrayBuffer<`u`}function Nu(e){return e.index?e.index.count:e.attributes.position.count}function Pu(e){return Nu(e)/3}function Fu(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function Iu(e,t){if(!e.index){let n=e.attributes.position.count,r=Fu(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new vr(r,1));for(let e=0;e<n;e++)r[e]=e}}function Lu(e,t,n){let r=Nu(e)/n,i=t||e.drawRange,a=i.start/n,o=(i.start+i.count)/n,s=Math.max(0,a),c=Math.min(r,o)-s;return{offset:Math.floor(s),count:Math.floor(c)}}function Ru(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function zu(e,t,n){let r=Lu(e,t,n),i=Ru(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Nu(e)/n,l=[];for(let e of i){let{offset:t,count:n}=e,r=t,i=t+(isFinite(n)?n:c-t);r<s&&i>o&&(l.push({pos:Math.max(o,r),isStart:!0}),l.push({pos:Math.min(s,i),isStart:!1}))}l.sort((e,t)=>e.pos===t.pos?e.type===`end`?-1:1:e.pos-t.pos);let u=0,d=null;for(let e of l){let t=e.pos;u!==0&&t!==d&&a.push({offset:d,count:t-d}),u+=e.isStart?1:-1,d=t}return a}function Bu(e,t){let n=e[e.length-1],r=n.offset+n.count>2**16,i=e.reduce((e,t)=>e+t.count,0),a=r?4:2,o=t?new SharedArrayBuffer(i*a):new ArrayBuffer(i*a),s=r?new Uint32Array(o):new Uint16Array(o),c=0;for(let t=0;t<e.length;t++){let{offset:n,count:r}=e[t];for(let e=0;e<r;e++)s[c+e]=n+e;c+=r}return s}var Vu=class extends ju{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(!e.isBufferGeometry)throw Error(`BVH: Only BufferGeometries are supported.`);if(e.index&&e.index.isInterleavedBufferAttribute)throw Error(`BVH: InterleavedBufferAttribute is not supported for the index attribute.`);if(t.useSharedArrayBuffer&&!Mu())throw Error(`BVH: SharedArrayBuffer is not available.`);super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?e=>this._indirectBuffer[e]:e=>e,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...Ml,...t},t[jl]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=Bu(zu(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else Iu(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new er))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:zu(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},Hu=class{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,r=-1/0;for(let i=0,a=e.length;i<a;i++){let a=e[i][t];n=a<n?a:n,r=a>r?a:r}this.min=n,this.max=r}setFromPoints(e,t){let n=1/0,r=-1/0;for(let i=0,a=t.length;i<a;i++){let a=t[i],o=e.dot(a);n=o<n?o:n,r=o>r?o:r}this.min=n,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}};Hu.prototype.setFromBox=(function(){let e=new J;return function(t,n){let r=n.min,i=n.max,a=1/0,o=-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);let l=t.dot(e);a=Math.min(l,a),o=Math.max(l,o)}this.min=a,this.max=o}})();var Uu=(function(){let e=new J,t=new J,n=new J;return function(r,i,a){let o=r.start,s=e,c=i.start,l=t;n.subVectors(o,c),e.subVectors(r.end,r.start),t.subVectors(i.end,i.start);let u=n.dot(l),d=l.dot(s),f=l.dot(l),p=n.dot(s),m=s.dot(s)*f-d*d,h,g;h=m===0?0:(u*d-p*f)/m,g=(u+h*d)/f,a.x=h,a.y=g}})(),Wu=(function(){let e=new q,t=new J,n=new J;return function(r,i,a,o){Uu(r,i,e);let s=e.x,c=e.y;if(s>=0&&s<=1&&c>=0&&c<=1){r.at(s,a),i.at(c,o);return}if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}if(c>=0&&c<=1){s<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}{let e;e=s<0?r.start:r.end;let l;l=c<0?i.start:i.end;let u=t,d=n;if(r.closestPointToPoint(l,!0,t),i.closestPointToPoint(e,!0,n),u.distanceToSquared(l)<=d.distanceToSquared(e)){a.copy(u),o.copy(l);return}a.copy(e),o.copy(d);return}}})(),Gu=(function(){let e=new J,t=new J,n=new ci,r=new ys;return function(i,a){let{radius:o,center:s}=i,{a:c,b:l,c:u}=a;if(r.start=c,r.end=l,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o||(r.start=c,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o)||(r.start=l,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o))return!0;let d=a.getPlane(n);if(Math.abs(d.distanceToPoint(s))<=o){let e=d.projectPoint(s,t);if(a.containsPoint(e))return!0}return!1}})(),Ku=[`x`,`y`,`z`],qu=1e-15,Ju=qu*qu;function Yu(e){return Math.abs(e)<qu}var Xu=class extends $n{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new J),this.satBounds=[,,,,].fill().map(()=>new Hu),this.points=[this.a,this.b,this.c],this.plane=new ci,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new ys,this.needsUpdate=!0}intersectsSphere(e){return Gu(e,this)}update(){let e=this.a,t=this.b,n=this.c,r=this.points,i=this.satAxes,a=this.satBounds,o=i[0],s=a[0];this.getNormal(o),s.setFromPoints(o,r);let c=i[1],l=a[1];c.subVectors(e,t),l.setFromPoints(c,r);let u=i[2],d=a[2];u.subVectors(t,n),d.setFromPoints(u,r);let f=i[3],p=a[3];f.subVectors(n,e),p.setFromPoints(f,r);let m=c.length(),h=u.length(),g=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<qu?h<qu||g<qu?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<qu?g<qu?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<qu&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};Xu.prototype.closestPointToSegment=(function(){let e=new J,t=new J,n=new ys;return function(r,i=null,a=null){let{start:o,end:s}=r,c=this.points,l,u=1/0;for(let o=0;o<3;o++){let s=(o+1)%3;n.start.copy(c[o]),n.end.copy(c[s]),Wu(n,r,e,t),l=e.distanceToSquared(t),l<u&&(u=l,i&&i.copy(e),a&&a.copy(t))}return this.closestPointToPoint(o,e),l=o.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(o)),this.closestPointToPoint(s,e),l=s.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(s)),Math.sqrt(u)}})(),Xu.prototype.intersectsTriangle=(function(){let e=new Xu,t=new Hu,n=new Hu,r=new J,i=new J,a=new J,o=new J,s=new ys,c=new ys,l=new J,u=new q,d=new q;function f(e,i,a,s){let c=r;!e.isDegenerateIntoPoint&&!e.isDegenerateIntoSegment?c.copy(e.plane.normal):c.copy(i.plane.normal);let l=e.satBounds,u=e.satAxes;for(let r=1;r<4;r++){let a=l[r],s=u[r];if(t.setFromPoints(s,i.points),a.isSeparated(t)||(o.copy(c).cross(s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}let d=i.satBounds,f=i.satAxes;for(let r=1;r<4;r++){let a=d[r],s=f[r];if(t.setFromPoints(s,e.points),a.isSeparated(t)||(o.crossVectors(c,s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}return a&&(s||console.warn(`ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0.`),a.start.set(0,0,0),a.end.set(0,0,0)),!0}function p(e,t,n,r,i,a,o,s,c,l,u){let d=o/(o-s);l.x=r+(i-r)*d,u.start.subVectors(t,e).multiplyScalar(d).add(e),d=o/(o-c),l.y=r+(a-r)*d,u.end.subVectors(n,e).multiplyScalar(d).add(e)}function m(e,t,n,r,i,a,o,s,c,l,u){if(i>0)p(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else if(a>0)p(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(s*c>0||o!=0)p(e.a,e.b,e.c,t,n,r,o,s,c,l,u);else if(s!=0)p(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(c!=0)p(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else return!0;return!1}function h(e,t,n,i){let a=t.degenerateSegment,o=e.plane.distanceToPoint(a.start),s=e.plane.distanceToPoint(a.end);return Yu(o)?Yu(s)?f(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):Yu(s)?(n&&(n.start.copy(a.end),n.end.copy(a.end)),e.containsPoint(a.end)):e.plane.intersectLine(a,r)!=null&&(n&&(n.start.copy(r),n.end.copy(r)),e.containsPoint(r))}function g(e,t,n){let r=t.a;return Yu(e.plane.distanceToPoint(r))&&e.containsPoint(r)?(n&&(n.start.copy(r),n.end.copy(r)),!0):!1}function _(e,t,n){let i=e.degenerateSegment,a=t.a;return i.closestPointToPoint(a,!0,r),a.distanceToSquared(r)<Ju&&(n&&(n.start.copy(a),n.end.copy(a)),!0)}function v(e,t,n,o){if(e.isDegenerateIntoSegment){if(t.isDegenerateIntoSegment){let o=e.degenerateSegment,s=t.degenerateSegment,c=i,l=a;o.delta(c),s.delta(l);let u=r.subVectors(s.start,o.start),d=c.x*l.y-c.y*l.x;if(Yu(d))return!1;let f=(u.x*l.y-u.y*l.x)/d,p=-(c.x*u.y-c.y*u.x)/d;return f<0||f>1||p<0||p>1?!1:Yu(o.start.z+c.z*f-(s.start.z+l.z*p))?(n&&(n.start.copy(o.start).addScaledVector(c,f),n.end.copy(o.start).addScaledVector(c,f)),!0):!1}return t.isDegenerateIntoPoint?_(e,t,n):h(t,e,n,o)}if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<Ju&&(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):t.isDegenerateIntoSegment?_(t,e,n):g(t,e,n);if(t.isDegenerateIntoPoint)return g(e,t,n);if(t.isDegenerateIntoSegment)return h(e,t,n,o)}return function(t,n=null,r=!1){this.needsUpdate&&this.update(),t.isExtendedTriangle?t.needsUpdate&&t.update():(e.copy(t),e.update(),t=e);let o=v(this,t,n,r);if(o!==void 0)return o;let p=this.plane,h=t.plane,g=h.distanceToPoint(this.a),_=h.distanceToPoint(this.b),y=h.distanceToPoint(this.c);Yu(g)&&(g=0),Yu(_)&&(_=0),Yu(y)&&(y=0);let b=g*_,x=g*y;if(b>0&&x>0)return!1;let S=p.distanceToPoint(t.a),C=p.distanceToPoint(t.b),w=p.distanceToPoint(t.c);Yu(S)&&(S=0),Yu(C)&&(C=0),Yu(w)&&(w=0);let T=S*C,E=S*w;if(T>0&&E>0)return!1;i.copy(p.normal),a.copy(h.normal);let D=i.cross(a),O=0,k=Math.abs(D.x),A=Math.abs(D.y);A>k&&(k=A,O=1),Math.abs(D.z)>k&&(O=2);let j=Ku[O],M=this.a[j],N=this.b[j],ee=this.c[j],P=t.a[j],F=t.b[j],I=t.c[j];if(m(this,M,N,ee,b,x,g,_,y,u,s)||m(t,P,F,I,T,E,S,C,w,d,c))return f(this,t,n,r);if(u.y<u.x){let e=u.y;u.y=u.x,u.x=e,l.copy(s.start),s.start.copy(s.end),s.end.copy(l)}if(d.y<d.x){let e=d.y;d.y=d.x,d.x=e,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<d.x||d.y<u.x?!1:(n&&(d.x>u.x?n.start.copy(c.start):n.start.copy(s.start),d.y<u.y?n.end.copy(c.end):n.end.copy(s.end)),!0)}})(),Xu.prototype.distanceToPoint=(function(){let e=new J;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),Xu.prototype.distanceToTriangle=(function(){let e=new J,t=new J,n=[`a`,`b`,`c`],r=new ys,i=new ys;return function(a,o=null,s=null){let c=o||s?r:null;if(this.intersectsTriangle(a,c,!0))return(o||s)&&(o&&c.getCenter(o),s&&c.getCenter(s)),0;let l=1/0;for(let t=0;t<3;t++){let r,i=n[t],c=a[i];this.closestPointToPoint(c,e),r=c.distanceToSquared(e),r<l&&(l=r,o&&o.copy(e),s&&s.copy(c));let u=this[i];a.closestPointToPoint(u,e),r=u.distanceToSquared(e),r<l&&(l=r,o&&o.copy(u),s&&s.copy(e))}for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];r.set(this[u],this[d]);for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];i.set(a[u],a[d]),Wu(r,i,e,t);let f=e.distanceToSquared(t);f<l&&(l=f,o&&o.copy(e),s&&s.copy(t))}}return Math.sqrt(l)}})();var Zu=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new J,this.max=new J,this.matrix=new Y,this.invMatrix=new Y,this.points=Array(8).fill().map(()=>new J),this.satAxes=[,,,].fill().map(()=>new J),this.satBounds=[,,,].fill().map(()=>new Hu),this.alignedSatBounds=[,,,].fill().map(()=>new Hu),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}};Zu.prototype.update=(function(){return function(){let e=this.matrix,t=this.min,n=this.max,r=this.points;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let o=0;o<=1;o++){let s=r[1*i|2*a|4*o];s.x=i?n.x:t.x,s.y=a?n.y:t.y,s.z=o?n.z:t.z,s.applyMatrix4(e)}let i=this.satBounds,a=this.satAxes,o=r[0];for(let e=0;e<3;e++){let t=a[e],n=i[e],s=r[1<<e];t.subVectors(o,s),n.setFromPoints(t,r)}let 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}})(),Zu.prototype.intersectsBox=(function(){let e=new Hu;return function(t){this.needsUpdate&&this.update();let n=t.min,r=t.max,i=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(e.min=n.x,e.max=r.x,o[0].isSeparated(e)||(e.min=n.y,e.max=r.y,o[1].isSeparated(e))||(e.min=n.z,e.max=r.z,o[2].isSeparated(e)))return!1;for(let n=0;n<3;n++){let r=a[n],o=i[n];if(e.setFromBox(r,t),o.isSeparated(e))return!1}return!0}})(),Zu.prototype.intersectsTriangle=(function(){let e=new Xu,t=[,,,],n=new Hu,r=new Hu,i=new J;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(e.copy(a),e.update(),a=e);let o=this.satBounds,s=this.satAxes;t[0]=a.a,t[1]=a.b,t[2]=a.c;for(let e=0;e<3;e++){let r=o[e],i=s[e];if(n.setFromPoints(i,t),r.isSeparated(n))return!1}let c=a.satBounds,l=a.satAxes,u=this.points;for(let e=0;e<3;e++){let t=c[e],r=l[e];if(n.setFromPoints(r,u),t.isSeparated(n))return!1}for(let e=0;e<3;e++){let a=s[e];for(let e=0;e<4;e++){let o=l[e];if(i.crossVectors(a,o),n.setFromPoints(i,t),r.setFromPoints(i,u),n.isSeparated(r))return!1}}return!0}})(),Zu.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})(),Zu.prototype.distanceToPoint=(function(){let e=new J;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),Zu.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new ys),n=Array(12).fill().map(()=>new ys),r=new J,i=new J;return function(a,o=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(s||c)&&(a.getCenter(i),this.closestPointToPoint(i,r),a.closestPointToPoint(r,i),s&&s.copy(r),c&&c.copy(i)),0;let l=o*o,u=a.min,d=a.max,f=this.points,p=1/0;for(let e=0;e<8;e++){let t=f[e];i.copy(t).clamp(u,d);let n=t.distanceToSquared(i);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(i),n<l))return Math.sqrt(n)}let m=0;for(let r=0;r<3;r++)for(let i=0;i<=1;i++)for(let a=0;a<=1;a++){let o=(r+1)%3,s=(r+2)%3,c=i<<o|a<<s,l=1<<r|i<<o|a<<s,p=f[c],h=f[l];t[m].set(p,h);let g=e[r],_=e[o],v=e[s],y=n[m],b=y.start,x=y.end;b[g]=u[g],b[_]=i?u[_]:d[_],b[v]=a?u[v]:d[_],x[g]=d[g],x[_]=i?u[_]:d[_],x[v]=a?u[v]:d[_],m++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let n=0;n<=1;n++){i.x=e?d.x:u.x,i.y=t?d.y:u.y,i.z=n?d.z:u.z,this.closestPointToPoint(i,r);let a=i.distanceToSquared(r);if(a<p&&(p=a,s&&s.copy(r),c&&c.copy(i),a<l))return Math.sqrt(a)}for(let e=0;e<12;e++){let a=t[e];for(let e=0;e<12;e++){let t=n[e];Wu(a,t,r,i);let o=r.distanceToSquared(i);if(o<p&&(p=o,s&&s.copy(r),c&&c.copy(i),o<l))return Math.sqrt(o)}}return Math.sqrt(p)}})();var Qu=new class extends du{constructor(){super(()=>new Xu)}},$u=new J,ed=new J;function td(e,t,n={},r=0,i=1/0){let a=r*r,o=i*i,s=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>($u.copy(t).clamp(e.min,e.max),$u.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,$u);let r=t.distanceToSquared($u);return r<s&&(ed.copy($u),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(ed):n.point=ed.clone(),n.distance=l,n.faceIndex=c,n}var nd=!0,rd=new J,id=new J,ad=new J,od=new q,sd=new q,cd=new q,ld=new J,ud=new J,dd=new J,fd=new J;function pd(e,t,n,r,i,a,o,s){let c;if(c=a===1?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==2,i),c===null)return null;let l=e.origin.distanceTo(i);return l<o||l>s?null:{distance:l,point:i.clone()}}function md(e,t,n,r,i,a,o,s,c,l,u){rd.fromBufferAttribute(t,a),id.fromBufferAttribute(t,o),ad.fromBufferAttribute(t,s);let d=pd(e,rd,id,ad,fd,c,l,u);if(d){if(r){od.fromBufferAttribute(r,a),sd.fromBufferAttribute(r,o),cd.fromBufferAttribute(r,s),d.uv=new q;let e=$n.getInterpolation(fd,rd,id,ad,od,sd,cd,d.uv);nd||(d.uv=e)}if(i){od.fromBufferAttribute(i,a),sd.fromBufferAttribute(i,o),cd.fromBufferAttribute(i,s),d.uv1=new q;let e=$n.getInterpolation(fd,rd,id,ad,od,sd,cd,d.uv1);nd||(d.uv1=e)}if(n){ld.fromBufferAttribute(n,a),ud.fromBufferAttribute(n,o),dd.fromBufferAttribute(n,s),d.normal=new J;let t=$n.getInterpolation(fd,rd,id,ad,ld,ud,dd,d.normal);d.normal.dot(e.direction)>0&&d.normal.multiplyScalar(-1),nd||(d.normal=t)}let t={a,b:o,c:s,normal:new J,materialIndex:0};if($n.getNormal(rd,id,ad,t.normal),d.face=t,d.faceIndex=a,nd){let e=new J;$n.getBarycoord(fd,rd,id,ad,e),d.barycoord=e}}return d}function hd(e){return e&&e.isMaterial?e.side:e}function gd(e,t,n,r,i,a,o){let s=r*3,c=s+0,l=s+1,u=s+2,{index:d,groups:f}=e;e.index&&(c=d.getX(c),l=d.getX(l),u=d.getX(u));let{position:p,normal:m,uv:h,uv1:g}=e.attributes;if(Array.isArray(t)){let e=r*3;for(let s=0,d=f.length;s<d;s++){let{start:d,count:_,materialIndex:v}=f[s];if(e>=d&&e<d+_){let e=hd(t[v]),s=md(n,p,m,h,g,c,l,u,e,a,o);if(s){if(s.faceIndex=r,s.face.materialIndex=v,i)i.push(s);else return s}}}}else{let e=hd(t),s=md(n,p,m,h,g,c,l,u,e,a,o);if(s){if(s.faceIndex=r,s.face.materialIndex=0,i)i.push(s);else return s}}return null}function _d(e,t,n,r){let i=e.a,a=e.b,o=e.c,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),a.x=r.getX(c),a.y=r.getY(c),a.z=r.getZ(c),o.x=r.getX(l),o.y=r.getY(l),o.z=r.getZ(l)}function vd(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)gd(c,t,n,e,a,o,s)}function yd(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,c=r+i;e<c;e++){let r;r=gd(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function bd(e,t,n,r,i,a,o){let{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,_d(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function xd(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(e,n,a=!1){let l=e*2;if(zl(l,s)){let t=Bl(e,o),n=Vl(l,s),a=1/0,u=1/0,d=1/0,f=-1/0,p=-1/0,m=-1/0;for(let e=3*t,o=3*(t+n);e<o;e++){let t=r[e],n=i.getX(t),o=i.getY(t),s=i.getZ(t);n<a&&(a=n),n>f&&(f=n),o<u&&(u=o),o>p&&(p=o),s<d&&(d=s),s>m&&(m=s)}return c[e+0]!==a||c[e+1]!==u||c[e+2]!==d||c[e+3]!==f||c[e+4]!==p||c[e+5]!==m?(c[e+0]=a,c[e+1]=u,c[e+2]=d,c[e+3]=f,c[e+4]=p,c[e+5]=m,!0):!1}{let r=Hl(e),i=Ul(e,o),s=a,l=!1,u=!1;if(t){if(!s){let e=r/8+n/32,a=i/8+n/32;l=t.has(e),u=t.has(a),s=!l&&!u}}else l=!0,u=!0;let f=s||l,p=s||u,m=!1;f&&(m=d(r,n,s));let h=!1;p&&(h=d(i,n,s));let g=m||h;if(g)for(let t=0;t<3;t++){let n=r+t,a=i+t,o=c[n],s=c[n+3],l=c[a],u=c[a+3];c[e+t]=o<l?o:l,c[e+t+3]=s>u?s:u}return g}}}function Sd(e,t,n,r,i){let a,o,s,c,l,u,d=1/n.direction.x,f=1/n.direction.y,p=1/n.direction.z,m=n.origin.x,h=n.origin.y,g=n.origin.z,_=t[e],v=t[e+3],y=t[e+1],b=t[e+3+1],x=t[e+2],S=t[e+3+2];return d>=0?(a=(_-m)*d,o=(v-m)*d):(a=(v-m)*d,o=(_-m)*d),f>=0?(s=(y-h)*f,c=(b-h)*f):(s=(b-h)*f,c=(y-h)*f),a>c||s>o||((s>a||isNaN(a))&&(a=s),(c<o||isNaN(o))&&(o=c),p>=0?(l=(x-g)*p,u=(S-g)*p):(l=(S-g)*p,u=(x-g)*p),a>u||l>o)?!1:((l>a||a!==a)&&(a=l),(u<o||o!==o)&&(o=u),a<=i&&o>=r)}function Cd(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)gd(c,t,n,l?l[e]:e,a,o,s)}function wd(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,d=r+i;e<d;e++){let r;r=gd(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Td(e,t,n,r,i,a,o){let{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),_d(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Ed(e,t,n,r,i,a,o){$.setBuffer(e._roots[t]),Dd(0,e,n,r,i,a,o),$.clearBuffer()}function Dd(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=$,u=e*2;if(zl(u,c))vd(t,n,r,Bl(e,l),Vl(u,c),i,a,o);else{let c=Hl(e);Sd(c,s,r,a,o)&&Dd(c,t,n,r,i,a,o);let u=Ul(e,l);Sd(u,s,r,a,o)&&Dd(u,t,n,r,i,a,o)}}var Od=[`x`,`y`,`z`];function kd(e,t,n,r,i,a){$.setBuffer(e._roots[t]);let o=Ad(0,e,n,r,i,a);return $.clearBuffer(),o}function Ad(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=$,l=e*2;if(zl(l,s))return yd(t,n,r,Bl(e,c),Vl(l,s),i,a);{let s=Wl(e,c),l=Od[s],u=r.direction[l]>=0,d,f;u?(d=Hl(e),f=Ul(e,c)):(d=Ul(e,c),f=Hl(e));let p=Sd(d,o,r,i,a)?Ad(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=Sd(f,o,r,i,a)?Ad(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var jd=new er,Md=new Xu,Nd=new Xu,Pd=new Y,Fd=new Zu,Id=new Zu;function Ld(e,t,n,r){$.setBuffer(e._roots[t]);let i=Rd(0,e,n,r);return $.clearBuffer(),i}function Rd(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=$,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Fd.set(n.boundingBox.min,n.boundingBox.max,r),i=Fd),zl(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=Bl(e,s),m=Vl(c,o);if(Pd.copy(r).invert(),n.boundsTree)return Nl(Gl(e),a,Id),Id.matrix.copy(Pd),Id.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>Id.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let t=p*3,n=(m+p)*3;t<n;t+=3)if(_d(Nd,t,l,u),Nd.needsUpdate=!0,e.intersectsTriangle(Nd))return!0;return!1}});{let e=Pu(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){_d(Md,t,l,u),Md.a.applyMatrix4(Pd),Md.b.applyMatrix4(Pd),Md.c.applyMatrix4(Pd),Md.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(_d(Nd,t,d,f),Nd.needsUpdate=!0,Md.intersectsTriangle(Nd))return!0}}}else{let o=Hl(e),c=Ul(e,s);return Nl(Gl(o),a,jd),!!(i.intersectsBox(jd)&&Rd(o,t,n,r,i)||(Nl(Gl(c),a,jd),i.intersectsBox(jd)&&Rd(c,t,n,r,i)))}}var zd=new Y,Bd=new Zu,Vd=new Zu,Hd=new J,Ud=new J,Wd=new J,Gd=new J;function Kd(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Bd.set(t.boundingBox.min,t.boundingBox.max,n),Bd.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=Qu.getPrimitive(),p=Qu.getPrimitive(),m=Hd,h=Ud,g=null,_=null;i&&(g=Wd,_=Gd);let v=1/0,y=null,b=null;return zd.copy(n).invert(),Vd.matrix.copy(zd),e.shapecast({boundsTraverseOrder:e=>Bd.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(Vd.min.copy(e.min),Vd.max.copy(e.max),Vd.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>Vd.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){_d(p,3*o,d,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++){_d(f,3*t,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=t,b=o),e<a)return!0}}}});{let i=Pu(t);for(let t=0,o=i;t<o;t++){_d(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=e,i=e+r;n<i;n++){_d(f,3*n,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=n,b=t),e<a)return!0}}}}}),Qu.releasePrimitive(f),Qu.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(zd),h.applyMatrix4(zd),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function qd(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(n,a,l=!1){let u=n*2;if(zl(u,s)){let t=Bl(n,o),a=Vl(u,s),l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,h=-1/0;for(let n=t,o=t+a;n<o;n++){let t=3*e.resolveTriangleIndex(n);for(let e=0;e<3;e++){let n=t+e;n=r?r[n]:n;let a=i.getX(n),o=i.getY(n),s=i.getZ(n);a<l&&(l=a),a>p&&(p=a),o<d&&(d=o),o>m&&(m=o),s<f&&(f=s),s>h&&(h=s)}}return c[n+0]!==l||c[n+1]!==d||c[n+2]!==f||c[n+3]!==p||c[n+4]!==m||c[n+5]!==h?(c[n+0]=l,c[n+1]=d,c[n+2]=f,c[n+3]=p,c[n+4]=m,c[n+5]=h,!0):!1}{let e=Hl(n),r=Ul(n,o),i=l,s=!1,u=!1;if(t){if(!i){let n=e/8+a/32,o=r/8+a/32;s=t.has(n),u=t.has(o),i=!s&&!u}}else s=!0,u=!0;let f=i||s,p=i||u,m=!1;f&&(m=d(e,a,i));let h=!1;p&&(h=d(r,a,i));let g=m||h;if(g)for(let t=0;t<3;t++){let i=e+t,a=r+t,o=c[i],s=c[i+3],l=c[a],u=c[a+3];c[n+t]=o<l?o:l,c[n+t+3]=s>u?s:u}return g}}}function Jd(e,t,n,r,i,a,o){$.setBuffer(e._roots[t]),Yd(0,e,n,r,i,a,o),$.clearBuffer()}function Yd(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=$,u=e*2;if(zl(u,c))Cd(t,n,r,Bl(e,l),Vl(u,c),i,a,o);else{let c=Hl(e);Sd(c,s,r,a,o)&&Yd(c,t,n,r,i,a,o);let u=Ul(e,l);Sd(u,s,r,a,o)&&Yd(u,t,n,r,i,a,o)}}var Xd=[`x`,`y`,`z`];function Zd(e,t,n,r,i,a){$.setBuffer(e._roots[t]);let o=Qd(0,e,n,r,i,a);return $.clearBuffer(),o}function Qd(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=$,l=e*2;if(zl(l,s))return wd(t,n,r,Bl(e,c),Vl(l,s),i,a);{let s=Wl(e,c),l=Xd[s],u=r.direction[l]>=0,d,f;u?(d=Hl(e),f=Ul(e,c)):(d=Ul(e,c),f=Hl(e));let p=Sd(d,o,r,i,a)?Qd(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=Sd(f,o,r,i,a)?Qd(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var $d=new er,ef=new Xu,tf=new Xu,nf=new Y,rf=new Zu,af=new Zu;function of(e,t,n,r){$.setBuffer(e._roots[t]);let i=sf(0,e,n,r);return $.clearBuffer(),i}function sf(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=$,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),rf.set(n.boundingBox.min,n.boundingBox.max,r),i=rf),zl(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=Bl(e,s),m=Vl(c,o);if(nf.copy(r).invert(),n.boundsTree)return Nl(Gl(e),a,af),af.matrix.copy(nf),af.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>af.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let n=p,r=m+p;n<r;n++)if(_d(tf,3*t.resolveTriangleIndex(n),l,u),tf.needsUpdate=!0,e.intersectsTriangle(tf))return!0;return!1}});{let e=Pu(n);for(let n=p,r=m+p;n<r;n++){_d(ef,3*t.resolveTriangleIndex(n),l,u),ef.a.applyMatrix4(nf),ef.b.applyMatrix4(nf),ef.c.applyMatrix4(nf),ef.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(_d(tf,t,d,f),tf.needsUpdate=!0,ef.intersectsTriangle(tf))return!0}}}else{let o=Hl(e),c=Ul(e,s);return Nl(Gl(o),a,$d),!!(i.intersectsBox($d)&&sf(o,t,n,r,i)||(Nl(Gl(c),a,$d),i.intersectsBox($d)&&sf(c,t,n,r,i)))}}var cf=new Y,lf=new Zu,uf=new Zu,df=new J,ff=new J,pf=new J,mf=new J;function hf(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),lf.set(t.boundingBox.min,t.boundingBox.max,n),lf.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=Qu.getPrimitive(),p=Qu.getPrimitive(),m=df,h=ff,g=null,_=null;i&&(g=pf,_=mf);let v=1/0,y=null,b=null;return cf.copy(n).invert(),uf.matrix.copy(cf),e.shapecast({boundsTraverseOrder:e=>lf.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(uf.min.copy(e.min),uf.max.copy(e.max),uf.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>uf.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,o)=>{for(let x=t,S=t+o;x<S;x++){let t=s.resolveTriangleIndex(x);_d(p,3*t,d,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++){let n=e.resolveTriangleIndex(t);_d(f,3*n,l,c),f.needsUpdate=!0;let r=f.distanceToTriangle(p,m,g);if(r<v&&(h.copy(m),_&&_.copy(g),v=r,y=t,b=x),r<a)return!0}}}})}{let o=Pu(t);for(let t=0,s=o;t<s;t++){_d(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=r,o=r+i;n<o;n++){let r=e.resolveTriangleIndex(n);_d(f,3*r,l,c),f.needsUpdate=!0;let i=f.distanceToTriangle(p,m,g);if(i<v&&(h.copy(m),_&&_.copy(g),v=i,y=n,b=t),i<a)return!0}}}}}),Qu.releasePrimitive(f),Qu.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(cf),h.applyMatrix4(cf),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function gf(e,t,n){return e===null?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(n.ray.origin),e.object=t,e)}var _f=new Zu,vf=new Hr,yf=new J,bf=new Y,xf=new J,Sf=[`getX`,`getY`,`getZ`],Cf=class e extends Vu{static serialize(e,t={}){t={cloneBuffers:!0,...t};let n=e.geometry,r=e._roots,i=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=r.map(e=>e.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=i?i.slice():null):(o.roots=r,o.index=a?a.array:null,o.indirectBuffer=i),o}static deserialize(t,n,r={}){r={setIndex:!0,indirect:!!t.indirectBuffer,...r};let{index:i,roots:a,indirectBuffer:o}=t;t.version||(console.warn(`MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data.`),c(a));let s=new e(n,{...r,[jl]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new vr(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function c(e){for(let t=0;t<e.length;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n);for(let e=0,t=n.byteLength/32;e<t;e++){let t=8*e;zl(2*t,i)||(r[t+6]=r[t+6]/8-e)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn(`MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.`),t={...t,targetLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=(i?i[e]:e)*3,c=s+0,l=s+1,u=s+2;o&&(c=o[c],l=o[l],u=o[u]);for(let e=0;e<3;e++){let r=a[Sf[e]](c),i=a[Sf[e]](l),o=a[Sf[e]](u),s=r;i<s&&(s=i),o<s&&(s=o);let d=r;i>d&&(d=i),o>d&&(d=o),t[n+e]=s,t[n+e+3]=d}return t}computePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw Error(`MeshBVH: compute triangle bounds range is invalid.`);let c=a.array,l=a.offset||0,u=3;a.isInterleavedBufferAttribute&&(u=a.data.stride);let d=[`getX`,`getY`,`getZ`],f=n.offset;for(let r=e,p=e+t;r<p;r++){let e=(i?i[r]:r)*3,t=(r-f)*6,p=e+0,m=e+1,h=e+2;o&&(p=o[p],m=o[m],h=o[h]),s||(p=p*u+l,m=m*u+l,h=h*u+l);for(let e=0;e<3;e++){let r,i,o;s?(r=a[d[e]](p),i=a[d[e]](m),o=a[d[e]](h)):(r=c[p+e],i=c[m+e],o=c[h+e]);let l=r;i<l&&(l=i),o<l&&(l=o);let u=r;i>u&&(u=i),o>u&&(u=o);let f=(u-l)/2,g=e*2;n[t+g+0]=l+f,n[t+g+1]=f+(Math.abs(l)+f)*Al}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;bf.copy(e.matrixWorld).invert(),vf.copy(t.ray).applyMatrix4(bf),xf.setFromMatrixScale(e.matrixWorld),yf.copy(vf.direction).multiply(xf);let i=yf.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(vf,r,a,o);i=gf(i,e,t),i&&n.push(i)}else{let i=this.raycast(vf,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=gf(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?qd:xd)(this,e)}raycast(e,t=0,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?Jd:Ed;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=0,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?Zd:kd;for(let s=0,c=i.length;s<c;s++){let i=o(this,s,t,e,n,r);i!=null&&(a==null||i.distance<a.distance)&&(a=i)}return a}intersectsGeometry(e,t){let n=!1,r=this._roots,i=this.indirect?of:Ld;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=Qu.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Td:bd});return Qu.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=Qu.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);_d(o,t*3,s,c)}:e=>{_d(o,e*3,s,c)},u=Qu.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);_d(u,n*3,d,f)}:e=>{_d(u,e*3,d,f)};if(a){if(!(t instanceof e))throw Error(`MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.`);let r=(e,t,r,i,s,c,d,f)=>{for(let m=r,h=r+i;m<h;m++){p(m),u.a.applyMatrix4(n),u.b.applyMatrix4(n),u.c.applyMatrix4(n),u.needsUpdate=!0;for(let n=e,r=e+t;n<r;n++)if(l(n),o.needsUpdate=!0,a(o,u,n,m,s,c,d,f))return!0}return!1};if(i){let e=i;i=function(t,n,i,a,o,s,c,l){return e(t,n,i,a,o,s,c,l)?!0:r(t,n,i,a,o,s,c,l)}}else i=r}return super.bvhcast(t,n,{intersectsRanges:i})}intersectsBox(e,t){return _f.set(e.min,e.max,t),_f.needsUpdate=!0,this.shapecast({intersectsBounds:e=>_f.intersectsBox(e),intersectsTriangle:e=>_f.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},r={},i=0,a=1/0){return(this.indirect?hf:Kd)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return td(this,e,t,n,r)}},wf=1e-6,Tf=wf*.5,Ef=10**-Math.log10(wf),Df=Tf*Ef;function Of(e){return~~(e*Ef+Df)}function kf(e){return`${Of(e.x)},${Of(e.y)}`}function Af(e){return`${Of(e.x)},${Of(e.y)},${Of(e.z)}`}function jf(e){return`${Of(e.x)},${Of(e.y)},${Of(e.z)},${Of(e.w)}`}function Mf(e,t,n){n.direction.subVectors(t,e).normalize();let r=e.dot(n.direction);return n.origin.copy(e).addScaledVector(n.direction,-r),n}function Nf(){return typeof SharedArrayBuffer<`u`}function Pf(e){if(e.buffer instanceof SharedArrayBuffer)return e;let t=e.constructor,n=e.buffer,r=new SharedArrayBuffer(n.byteLength),i=new Uint8Array(n);return new Uint8Array(r).set(i,0),new t(r)}function Ff(e){return e.index?e.index.count:e.attributes.position.count}function If(e){return Ff(e)/3}var Lf=1e-8,Rf=new J;function zf(e){return~~(e/3)}function Bf(e){return e%3}function Vf(e,t){return e.start-t.start}function Hf(e,t){return Rf.subVectors(t,e.origin).dot(e.direction)}function Uf(e,t,n,r=Lf){e.sort(Vf),t.sort(Vf);for(let r=0;r<e.length;r++){let i=e[r];for(let s=0;s<t.length;s++){let c=t[s];if(!(c.start>i.end)){if(i.end<c.start||c.end<i.start)continue;if(i.start<=c.start&&i.end>=c.end)a(c.end,i.end)||e.splice(r+1,0,{start:c.end,end:i.end,index:i.index}),i.end=c.start,c.start=0,c.end=0;else if(i.start>=c.start&&i.end<=c.end)a(i.end,c.end)||t.splice(s+1,0,{start:i.end,end:c.end,index:c.index}),c.end=i.start,i.start=0,i.end=0;else if(i.start<=c.start&&i.end<=c.end){let e=i.end;i.end=c.start,c.start=e}else if(i.start>=c.start&&i.end>=c.end){let e=c.end;c.end=i.start,i.start=e}else throw Error()}if(n.has(i.index)||n.set(i.index,[]),n.has(c.index)||n.set(c.index,[]),n.get(i.index).push(c.index),n.get(c.index).push(i.index),o(c)&&(t.splice(s,1),s--),o(i)){e.splice(r,1),r--;break}}}i(e),i(t);function i(e){for(let t=0;t<e.length;t++)o(e[t])&&(e.splice(t,1),t--)}function a(e,t){return Math.abs(t-e)<r}function o(e){return Math.abs(e.end-e.start)<r}}var Wf=1e-5,Gf=1e-4,Kf=class{constructor(){this._rays=[]}addRay(e){this._rays.push(e)}findClosestRay(e){let t=this._rays,n=e.clone();n.direction.multiplyScalar(-1);let r=1/0,i=null;for(let s=0,c=t.length;s<c;s++){let c=t[s];if(a(c,e)&&a(c,n))continue;let l=o(c,e),u=o(c,n),d=Math.min(l,u);d<r&&(r=d,i=c)}return i;function a(e,t){let n=e.origin.distanceTo(t.origin)>Wf;return e.direction.angleTo(t.direction)>Gf||n}function o(e,t){let n=e.origin.distanceTo(t.origin),r=e.direction.angleTo(t.direction);return n/Wf+r/Gf}}},qf=new J,Jf=new J,Yf=new Hr;function Xf(e,t,n){let r=e.attributes,i=e.index,a=r.position,o=new Map,s=new Map,c=Array.from(t),l=new Kf;for(let e=0,t=c.length;e<t;e++){let t=c[e],n=zf(t),r=Bf(t),o=3*n+r,u=3*n+(r+1)%3;i&&(o=i.getX(o),u=i.getX(u)),qf.fromBufferAttribute(a,o),Jf.fromBufferAttribute(a,u),Mf(qf,Jf,Yf);let d,f=l.findClosestRay(Yf);f===null&&(f=Yf.clone(),l.addRay(f)),s.has(f)||s.set(f,{forward:[],reverse:[],ray:f}),d=s.get(f);let p=Hf(f,qf),m=Hf(f,Jf);p>m&&([p,m]=[m,p]),Yf.direction.dot(f.direction)<0?d.reverse.push({start:p,end:m,index:t}):d.forward.push({start:p,end:m,index:t})}return s.forEach(({forward:e,reverse:t},r)=>{Uf(e,t,o,n),e.length===0&&t.length===0&&s.delete(r)}),{disjointConnectivityMap:o,fragmentMap:s}}var Zf=new q,Qf=new J,$f=new Zt,ep=[``,``,``],tp=class{constructor(){this.data=null,this.disjointConnections=null,this.unmatchedDisjointEdges=null,this.unmatchedEdges=-1,this.matchedEdges=-1,this.useDrawRange=!0,this.useAllAttributes=!1,this.matchDisjointEdges=!1,this.degenerateEpsilon=1e-8}getSiblingTriangleIndex(e,t){let n=this.data[e*3+t];return n===-1?-1:~~(n/3)}getSiblingEdgeIndex(e,t){let n=this.data[e*3+t];return n===-1?-1:n%3}getDisjointSiblingTriangleIndices(e,t){let n=e*3+t,r=this.disjointConnections.get(n);return r?r.map(e=>~~(e/3)):[]}getDisjointSiblingEdgeIndices(e,t){let n=e*3+t,r=this.disjointConnections.get(n);return r?r.map(e=>e%3):[]}isFullyConnected(){return this.unmatchedEdges===0}updateFrom(e){let{useAllAttributes:t,useDrawRange:n,matchDisjointEdges:r,degenerateEpsilon:i}=this,a=t?v:_,o=new Map,{attributes:s}=e,c=t?Object.keys(s):null,l=e.index,u=s.position,d=If(e),f=d,p=0;n&&(p=e.drawRange.start,e.drawRange.count!==1/0&&(d=~~(e.drawRange.count/3)));let m=this.data;(!m||m.length<3*f)&&(m=new Int32Array(3*f)),m.fill(-1);let h=0,g=new Set;for(let e=p,t=d*3+p;e<t;e+=3){let t=e;for(let e=0;e<3;e++){let n=t+e;l&&(n=l.getX(n)),ep[e]=a(n)}for(let e=0;e<3;e++){let n=(e+1)%3,r=ep[e],i=ep[n],a=`${i}_${r}`;if(o.has(a)){let n=t+e,r=o.get(a);m[n]=r,m[r]=n,o.delete(a),h+=2,g.delete(r)}else{let n=`${r}_${i}`,a=t+e;o.set(n,a),g.add(a)}}}if(r){let{fragmentMap:t,disjointConnectivityMap:n}=Xf(e,g,i);g.clear(),t.forEach(({forward:e,reverse:t})=>{e.forEach(({index:e})=>g.add(e)),t.forEach(({index:e})=>g.add(e))}),this.unmatchedDisjointEdges=t,this.disjointConnections=n,h=d*3-g.size}this.matchedEdges=h,this.unmatchedEdges=g.size,this.data=m;function _(e){return Qf.fromBufferAttribute(u,e),Af(Qf)}function v(e){let t=``;for(let n=0,r=c.length;n<r;n++){let r=s[c[n]],i;switch(r.itemSize){case 1:i=Of(r.getX(e));break;case 2:i=kf(Zf.fromBufferAttribute(r,e));break;case 3:i=Af(Qf.fromBufferAttribute(r,e));break;case 4:i=jf($f.fromBufferAttribute(r,e))}t!==``&&(t+=`|`),t+=i}return t}}},np=class extends ti{constructor(...e){super(...e),this.isBrush=!0,this._previousMatrix=new Y,this._previousMatrix.elements.fill(0),this._halfEdges=null,this._boundsTree=null,this._groupIndices=null,this._hash=null}markUpdated(){this._previousMatrix.copy(this.matrix)}isDirty(){let{matrix:e,_previousMatrix:t}=this,n=e.elements,r=t.elements;for(let e=0;e<16;e++)if(n[e]!==r[e])return!0;return!1}prepareGeometry(){let e=this.geometry,t=e.attributes,n=Nf(),r=e.index,i=e.attributes.position,a=r?`${r.uuid}_${r.count}_${r.version}`:`-1_-1_-1`,o=`${i.uuid}_${i.count}_${i.version}`,s=`${e.uuid}_${a}_${o}`;if(this._hash===s)return;if(this._hash=s,n)for(let e in t){let n=t[e];if(n.isInterleavedBufferAttribute)throw Error(`Brush: InterleavedBufferAttributes are not supported.`);n.array=Pf(n.array)}e.boundsTree=new Cf(e,{maxLeafSize:3,indirect:!0,useSharedArrayBuffer:n}),e.halfEdges||=new tp,e.halfEdges.updateFrom(e);let c=If(e);(!e.groupIndices||e.groupIndices.length!==c)&&(e.groupIndices=new Uint16Array(c));let l=e.groupIndices,u=e.groups;for(let e=0,t=u.length;e<t;e++){let{start:t,count:n}=u[e];for(let r=t/3,i=(t+n)/3;r<i;r++)l[r]=e}}disposeCacheData(){let{geometry:e}=this;e.halfEdges=null,e.boundsTree=null,e.groupIndices=null}},rp=Object.getOwnPropertyNames,ip=(e,t)=>function(){return t||(0,e[rp(e)[0]])((t={exports:{}}).exports,t),t.exports},ap=ip({"node_modules/binary-search-bounds/search-bounds.js"(e,t){"use strict";function n(e,t,n,r,i){for(var a=i+1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))>=0?(a=o,i=o-1):r=o+1}return a}function r(e,t,n,r,i){for(var a=i+1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))>0?(a=o,i=o-1):r=o+1}return a}function i(e,t,n,r,i){for(var a=r-1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))<0?(a=o,r=o+1):i=o-1}return a}function a(e,t,n,r,i){for(var a=r-1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))<=0?(a=o,r=o+1):i=o-1}return a}function o(e,t,n,r,i){for(;r<=i;){var a=r+i>>>1,o=e[a],s=n===void 0?o-t:n(o,t);if(s===0)return a;s<=0?r=a+1:i=a-1}return-1}function s(e,t,n,r,i,a){return typeof n==`function`?a(e,t,n,r===void 0?0:r|0,i===void 0?e.length-1:i|0):a(e,t,void 0,n===void 0?0:n|0,r===void 0?e.length-1:r|0)}t.exports={ge:function(e,t,r,i,a){return s(e,t,r,i,a,n)},gt:function(e,t,n,i,a){return s(e,t,n,i,a,r)},lt:function(e,t,n,r,a){return s(e,t,n,r,a,i)},le:function(e,t,n,r,i){return s(e,t,n,r,i,a)},eq:function(e,t,n,r,i){return s(e,t,n,r,i,o)}}}}),op=ip({"node_modules/two-product/two-product.js"(e,t){"use strict";t.exports=r;var n=+(2**27+1);function r(e,t,r){var i=e*t,a=n*e,o=a-(a-e),s=e-o,c=n*t,l=c-(c-t),u=t-l,d=i-o*l-s*l-o*u,f=s*u-d;return r?(r[0]=f,r[1]=i,r):[f,i]}}}),sp=ip({"node_modules/robust-sum/robust-sum.js"(e,t){"use strict";t.exports=r;function n(e,t){var n=e+t,r=n-e,i=n-r,a=t-r,o=e-i+a;return o?[o,n]:[n]}function r(e,t){var r=e.length|0,i=t.length|0;if(r===1&&i===1)return n(e[0],t[0]);var a=r+i,o=Array(a),s=0,c=0,l=0,u=Math.abs,d=e[c],f=u(d),p=t[l],m=u(p),h,g;f<m?(g=d,c+=1,c<r&&(d=e[c],f=u(d))):(g=p,l+=1,l<i&&(p=t[l],m=u(p))),c<r&&f<m||l>=i?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=t[l],m=u(p)));for(var _=h+g,v=_-h,y=g-v,b=y,x=_,S,C,w,T,E;c<r&&l<i;)f<m?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=t[l],m=u(p))),g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S;for(;c<r;)h=d,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,c+=1,c<r&&(d=e[c]);for(;l<i;)h=p,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,l+=1,l<i&&(p=t[l]);return b&&(o[s++]=b),x&&(o[s++]=x),s||(o[s++]=0),o.length=s,o}}}),cp=ip({"node_modules/two-sum/two-sum.js"(e,t){"use strict";t.exports=n;function n(e,t,n){var r=e+t,i=r-e,a=r-i,o=t-i,s=e-a;return n?(n[0]=s+o,n[1]=r,n):[s+o,r]}}}),lp=ip({"node_modules/robust-scale/robust-scale.js"(e,t){"use strict";var n=op(),r=cp();t.exports=i;function i(e,t){var i=e.length;if(i===1){var a=n(e[0],t);return a[0]?a:[a[1]]}var o=Array(2*i),s=[.1,.1],c=[.1,.1],l=0;n(e[0],t,s),s[0]&&(o[l++]=s[0]);for(var u=1;u<i;++u){n(e[u],t,c);var d=s[1];r(d,c[0],s),s[0]&&(o[l++]=s[0]);var f=c[1],p=s[1],m=f+p,h=p-(m-f);s[1]=m,h&&(o[l++]=h)}return s[1]&&(o[l++]=s[1]),l===0&&(o[l++]=0),o.length=l,o}}}),up=ip({"node_modules/robust-subtract/robust-diff.js"(e,t){"use strict";t.exports=r;function n(e,t){var n=e+t,r=n-e,i=n-r,a=t-r,o=e-i+a;return o?[o,n]:[n]}function r(e,t){var r=e.length|0,i=t.length|0;if(r===1&&i===1)return n(e[0],-t[0]);var a=r+i,o=Array(a),s=0,c=0,l=0,u=Math.abs,d=e[c],f=u(d),p=-t[l],m=u(p),h,g;f<m?(g=d,c+=1,c<r&&(d=e[c],f=u(d))):(g=p,l+=1,l<i&&(p=-t[l],m=u(p))),c<r&&f<m||l>=i?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=-t[l],m=u(p)));for(var _=h+g,v=_-h,y=g-v,b=y,x=_,S,C,w,T,E;c<r&&l<i;)f<m?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=-t[l],m=u(p))),g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S;for(;c<r;)h=d,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,c+=1,c<r&&(d=e[c]);for(;l<i;)h=p,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,l+=1,l<i&&(p=-t[l]);return b&&(o[s++]=b),x&&(o[s++]=x),s||(o[s++]=0),o.length=s,o}}}),dp=ip({"node_modules/robust-orientation/orientation.js"(e,t){"use strict";var n=op(),r=sp(),i=lp(),a=up(),o=5,s=11102230246251565e-32,c=(3+16*s)*s,l=(7+56*s)*s;function u(e,t,n,r){return function(n,i,a){var o=r(e(e(t(i[1],a[0]),t(-a[1],i[0])),e(t(n[1],i[0]),t(-i[1],n[0]))),e(t(n[1],a[0]),t(-a[1],n[0])));return o[o.length-1]}}function d(e,t,n,r){return function(i,a,o,s){var c=r(e(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2])))),e(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2])))));return c[c.length-1]}}function f(e,t,n,r){return function(i,a,o,s,c){var l=r(e(e(e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),a[3]),e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-s[2]),n(e(t(a[1],s[0]),t(-s[1],a[0])),c[2]))),-o[3]),n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),c[2]))),s[3]))),e(n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),-c[3]),e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-s[2]),n(e(t(a[1],s[0]),t(-s[1],a[0])),c[2]))),i[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-s[2]),n(e(t(i[1],s[0]),t(-s[1],i[0])),c[2]))),-a[3])))),e(e(n(e(n(e(t(a[1],c[0]),t(-c[1],a[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),c[2]))),s[3]),e(n(e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),-c[3]),n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),i[3]))),e(n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),-a[3]),e(n(e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),o[3]),n(e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2]))),-s[3]))))),e(e(e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),i[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-s[2]),n(e(t(i[1],s[0]),t(-s[1],i[0])),c[2]))),-o[3])),e(n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),c[2]))),s[3]),n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),-c[3]))),e(e(n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),c[2]))),i[3]),n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),c[2]))),-a[3])),e(n(e(n(e(t(a[1],c[0]),t(-c[1],a[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),c[2]))),o[3]),n(e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2]))),-c[3])))));return l[l.length-1]}}function p(e){return(e===3?u:e===4?d:f)(r,n,i,a)}var m=p(3),h=p(4),g=[function(){return 0},function(){return 0},function(e,t){return t[0]-e[0]},function(e,t,n){var r=(e[1]-n[1])*(t[0]-n[0]),i=(e[0]-n[0])*(t[1]-n[1]),a=r-i,o;if(r>0){if(i<=0)return a;o=r+i}else if(r<0){if(i>=0)return a;o=-(r+i)}else return a;var s=c*o;return a>=s||a<=-s?a:m(e,t,n)},function(e,t,n,r){var i=e[0]-r[0],a=t[0]-r[0],o=n[0]-r[0],s=e[1]-r[1],c=t[1]-r[1],u=n[1]-r[1],d=e[2]-r[2],f=t[2]-r[2],p=n[2]-r[2],m=a*u,g=o*c,_=o*s,v=i*u,y=i*c,b=a*s,x=d*(m-g)+f*(_-v)+p*(y-b),S=l*((Math.abs(m)+Math.abs(g))*Math.abs(d)+(Math.abs(_)+Math.abs(v))*Math.abs(f)+(Math.abs(y)+Math.abs(b))*Math.abs(p));return x>S||-x>S?x:h(e,t,n,r)}];function _(e){var t=g[e.length];return t||=g[e.length]=p(e.length),t.apply(void 0,e)}function v(e,t,n,r,i,a,o){return function(t,n,s,c,l){switch(arguments.length){case 0:case 1:return 0;case 2:return r(t,n);case 3:return i(t,n,s);case 4:return a(t,n,s,c);case 5:return o(t,n,s,c,l)}for(var u=Array(arguments.length),d=0;d<arguments.length;++d)u[d]=arguments[d];return e(u)}}function y(){for(;g.length<=o;)g.push(p(g.length));t.exports=v.apply(void 0,[_].concat(g));for(var e=0;e<=o;++e)t.exports[e]=g[e]}y()}}),fp=ip({"node_modules/cdt2d/lib/monotone.js"(e,t){"use strict";var n=ap(),r=dp()[3],i=0,a=1,o=2;t.exports=h;function s(e,t,n,r,i){this.a=e,this.b=t,this.idx=n,this.lowerIds=r,this.upperIds=i}function c(e,t,n,r){this.a=e,this.b=t,this.type=n,this.idx=r}function l(e,t){var n=e.a[0]-t.a[0]||e.a[1]-t.a[1]||e.type-t.type;return n||e.type!==i&&(n=r(e.a,e.b,t.b),n)?n:e.idx-t.idx}function u(e,t){return r(e.a,e.b,t)}function d(e,t,i,a,o){for(var s=n.lt(t,a,u),c=n.gt(t,a,u),l=s;l<c;++l){for(var d=t[l],f=d.lowerIds,p=f.length;p>1&&r(i[f[p-2]],i[f[p-1]],a)>0;)e.push([f[p-1],f[p-2],o]),--p;f.length=p,f.push(o);for(var m=d.upperIds,p=m.length;p>1&&r(i[m[p-2]],i[m[p-1]],a)<0;)e.push([m[p-2],m[p-1],o]),--p;m.length=p,m.push(o)}}function f(e,t){var n=e.a[0]<t.a[0]?r(e.a,e.b,t.a):r(t.b,t.a,e.a);return n||(n=t.b[0]<e.b[0]?r(e.a,e.b,t.b):r(t.b,t.a,e.b),n||e.idx-t.idx)}function p(e,t,r){var i=n.le(e,r,f),a=e[i],o=a.upperIds,c=o[o.length-1];a.upperIds=[c],e.splice(i+1,0,new s(r.a,r.b,r.idx,[c],o))}function m(e,t,r){var i=r.a;r.a=r.b,r.b=i;var a=n.eq(e,r,f),o=e[a],s=e[a-1];s.upperIds=o.upperIds,e.splice(a,1)}function h(e,t){for(var n=e.length,r=t.length,u=[],f=0;f<n;++f)u.push(new c(e[f],null,i,f));for(var f=0;f<r;++f){var h=t[f],g=e[h[0]],_=e[h[1]];g[0]<_[0]?u.push(new c(g,_,o,f),new c(_,g,a,f)):g[0]>_[0]&&u.push(new c(_,g,o,f),new c(g,_,a,f))}u.sort(l);for(var v=u[0].a[0]-(1+Math.abs(u[0].a[0]))*2**-52,y=[new s([v,1],[v,0],-1,[],[],[],[])],b=[],f=0,x=u.length;f<x;++f){var S=u[f],C=S.type;C===i?d(b,y,e,S.a,S.idx):C===o?p(y,e,S):m(y,e,S)}return b}}}),pp=ip({"node_modules/cdt2d/lib/triangulation.js"(e,t){"use strict";var n=ap();t.exports=o;function r(e,t){this.stars=e,this.edges=t}var i=r.prototype;function a(e,t,n){for(var r=1,i=e.length;r<i;r+=2)if(e[r-1]===t&&e[r]===n){e[r-1]=e[i-2],e[r]=e[i-1],e.length=i-2;return}}i.isConstraint=(function(){var e=[0,0];function t(e,t){return e[0]-t[0]||e[1]-t[1]}return function(r,i){return e[0]=Math.min(r,i),e[1]=Math.max(r,i),n.eq(this.edges,e,t)>=0}})(),i.removeTriangle=function(e,t,n){var r=this.stars;a(r[e],t,n),a(r[t],n,e),a(r[n],e,t)},i.addTriangle=function(e,t,n){var r=this.stars;r[e].push(t,n),r[t].push(n,e),r[n].push(e,t)},i.opposite=function(e,t){for(var n=this.stars[t],r=1,i=n.length;r<i;r+=2)if(n[r]===e)return n[r-1];return-1},i.flip=function(e,t){var n=this.opposite(e,t),r=this.opposite(t,e);this.removeTriangle(e,t,n),this.removeTriangle(t,e,r),this.addTriangle(e,r,n),this.addTriangle(t,n,r)},i.edges=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],a=0,o=i.length;a<o;a+=2)t.push([i[a],i[a+1]]);return t},i.cells=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],a=0,o=i.length;a<o;a+=2){var s=i[a],c=i[a+1];n<Math.min(s,c)&&t.push([n,s,c])}return t};function o(e,t){for(var n=Array(e),i=0;i<e;++i)n[i]=[];return new r(n,t)}}}),mp=ip({"node_modules/robust-in-sphere/in-sphere.js"(e,t){"use strict";var n=op(),r=sp(),i=up(),a=lp(),o=6;function s(e){return(e===3?d:e===4?f:e===5?p:m)(r,i,n,a)}function c(){return 0}function l(){return 0}function u(){return 0}function d(e,t,n,r){function i(i,a,o){var s=n(i[0],i[0]),c=r(s,a[0]),l=r(s,o[0]),u=n(a[0],a[0]),d=r(u,i[0]),f=r(u,o[0]),p=n(o[0],o[0]),m=r(p,i[0]),h=t(e(t(r(p,a[0]),f),t(d,c)),t(m,l));return h[h.length-1]}return i}function f(e,t,n,r){function i(i,a,o,s){var c=e(n(i[0],i[0]),n(i[1],i[1])),l=r(c,a[0]),u=r(c,o[0]),d=r(c,s[0]),f=e(n(a[0],a[0]),n(a[1],a[1])),p=r(f,i[0]),m=r(f,o[0]),h=r(f,s[0]),g=e(n(o[0],o[0]),n(o[1],o[1])),_=r(g,i[0]),v=r(g,a[0]),y=r(g,s[0]),b=e(n(s[0],s[0]),n(s[1],s[1])),x=r(b,i[0]),S=r(b,a[0]),C=r(b,o[0]),w=t(e(e(r(t(C,y),a[1]),e(r(t(S,h),-o[1]),r(t(v,m),s[1]))),e(r(t(S,h),i[1]),e(r(t(x,d),-a[1]),r(t(p,l),s[1])))),e(e(r(t(C,y),i[1]),e(r(t(x,d),-o[1]),r(t(_,u),s[1]))),e(r(t(v,m),i[1]),e(r(t(_,u),-a[1]),r(t(p,l),o[1])))));return w[w.length-1]}return i}function p(e,t,n,r){function i(i,a,o,s,c){var l=e(n(i[0],i[0]),e(n(i[1],i[1]),n(i[2],i[2]))),u=r(l,a[0]),d=r(l,o[0]),f=r(l,s[0]),p=r(l,c[0]),m=e(n(a[0],a[0]),e(n(a[1],a[1]),n(a[2],a[2]))),h=r(m,i[0]),g=r(m,o[0]),_=r(m,s[0]),v=r(m,c[0]),y=e(n(o[0],o[0]),e(n(o[1],o[1]),n(o[2],o[2]))),b=r(y,i[0]),x=r(y,a[0]),S=r(y,s[0]),C=r(y,c[0]),w=e(n(s[0],s[0]),e(n(s[1],s[1]),n(s[2],s[2]))),T=r(w,i[0]),E=r(w,a[0]),D=r(w,o[0]),O=r(w,c[0]),k=e(n(c[0],c[0]),e(n(c[1],c[1]),n(c[2],c[2]))),A=r(k,i[0]),j=r(k,a[0]),M=r(k,o[0]),N=r(k,s[0]),ee=t(e(e(e(r(e(r(t(N,O),o[1]),e(r(t(M,C),-s[1]),r(t(D,S),c[1]))),a[2]),e(r(e(r(t(N,O),a[1]),e(r(t(j,v),-s[1]),r(t(E,_),c[1]))),-o[2]),r(e(r(t(M,C),a[1]),e(r(t(j,v),-o[1]),r(t(x,g),c[1]))),s[2]))),e(r(e(r(t(D,S),a[1]),e(r(t(E,_),-o[1]),r(t(x,g),s[1]))),-c[2]),e(r(e(r(t(N,O),a[1]),e(r(t(j,v),-s[1]),r(t(E,_),c[1]))),i[2]),r(e(r(t(N,O),i[1]),e(r(t(A,p),-s[1]),r(t(T,f),c[1]))),-a[2])))),e(e(r(e(r(t(j,v),i[1]),e(r(t(A,p),-a[1]),r(t(h,u),c[1]))),s[2]),e(r(e(r(t(E,_),i[1]),e(r(t(T,f),-a[1]),r(t(h,u),s[1]))),-c[2]),r(e(r(t(D,S),a[1]),e(r(t(E,_),-o[1]),r(t(x,g),s[1]))),i[2]))),e(r(e(r(t(D,S),i[1]),e(r(t(T,f),-o[1]),r(t(b,d),s[1]))),-a[2]),e(r(e(r(t(E,_),i[1]),e(r(t(T,f),-a[1]),r(t(h,u),s[1]))),o[2]),r(e(r(t(x,g),i[1]),e(r(t(b,d),-a[1]),r(t(h,u),o[1]))),-s[2]))))),e(e(e(r(e(r(t(N,O),o[1]),e(r(t(M,C),-s[1]),r(t(D,S),c[1]))),i[2]),r(e(r(t(N,O),i[1]),e(r(t(A,p),-s[1]),r(t(T,f),c[1]))),-o[2])),e(r(e(r(t(M,C),i[1]),e(r(t(A,p),-o[1]),r(t(b,d),c[1]))),s[2]),r(e(r(t(D,S),i[1]),e(r(t(T,f),-o[1]),r(t(b,d),s[1]))),-c[2]))),e(e(r(e(r(t(M,C),a[1]),e(r(t(j,v),-o[1]),r(t(x,g),c[1]))),i[2]),r(e(r(t(M,C),i[1]),e(r(t(A,p),-o[1]),r(t(b,d),c[1]))),-a[2])),e(r(e(r(t(j,v),i[1]),e(r(t(A,p),-a[1]),r(t(h,u),c[1]))),o[2]),r(e(r(t(x,g),i[1]),e(r(t(b,d),-a[1]),r(t(h,u),o[1]))),-c[2])))));return ee[ee.length-1]}return i}function m(e,t,n,r){function i(i,a,o,s,c,l){var u=e(e(n(i[0],i[0]),n(i[1],i[1])),e(n(i[2],i[2]),n(i[3],i[3]))),d=r(u,a[0]),f=r(u,o[0]),p=r(u,s[0]),m=r(u,c[0]),h=r(u,l[0]),g=e(e(n(a[0],a[0]),n(a[1],a[1])),e(n(a[2],a[2]),n(a[3],a[3]))),_=r(g,i[0]),v=r(g,o[0]),y=r(g,s[0]),b=r(g,c[0]),x=r(g,l[0]),S=e(e(n(o[0],o[0]),n(o[1],o[1])),e(n(o[2],o[2]),n(o[3],o[3]))),C=r(S,i[0]),w=r(S,a[0]),T=r(S,s[0]),E=r(S,c[0]),D=r(S,l[0]),O=e(e(n(s[0],s[0]),n(s[1],s[1])),e(n(s[2],s[2]),n(s[3],s[3]))),k=r(O,i[0]),A=r(O,a[0]),j=r(O,o[0]),M=r(O,c[0]),N=r(O,l[0]),ee=e(e(n(c[0],c[0]),n(c[1],c[1])),e(n(c[2],c[2]),n(c[3],c[3]))),P=r(ee,i[0]),F=r(ee,a[0]),I=r(ee,o[0]),L=r(ee,s[0]),R=r(ee,l[0]),te=e(e(n(l[0],l[0]),n(l[1],l[1])),e(n(l[2],l[2]),n(l[3],l[3]))),z=r(te,i[0]),B=r(te,a[0]),V=r(te,o[0]),H=r(te,s[0]),U=r(te,c[0]),ne=t(e(e(e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),o[2]),r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),-s[2])),e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),c[2]),r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),-l[2]))),a[3]),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-s[2])),e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),c[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-l[2]))),-o[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),c[2]),r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),-l[2]))),s[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),a[2]),r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-l[2]))),-c[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),a[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-o[2])),e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-c[2]))),l[3])),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-s[2])),e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),c[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-l[2]))),i[3]),r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-s[2])),e(r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),c[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-l[2]))),-a[3])))),e(e(e(r(e(e(r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),c[2]),r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),-l[2]))),s[3]),r(e(e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-l[2]))),-c[3])),e(r(e(e(r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-c[2]))),l[3]),r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),a[2]),r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-l[2]))),i[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-l[2]))),-a[3]),r(e(e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-l[2]))),o[3])),e(r(e(e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),i[2]),r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-l[2]))),-s[3]),r(e(e(r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),i[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-a[2])),e(r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-s[2]))),l[3]))))),e(e(e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),o[2]),r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),-s[2])),e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),c[2]),r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),-l[2]))),i[3]),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-s[2])),e(r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),c[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-l[2]))),-o[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),c[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-l[2]))),s[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-l[2]))),-c[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-o[2])),e(r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-c[2]))),l[3])),e(r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),c[2]),r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),-l[2]))),i[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),c[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-l[2]))),-a[3])))),e(e(e(r(e(e(r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),c[2]),r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),-l[2]))),o[3]),r(e(e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),i[2]),r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-l[2]))),-c[3])),e(r(e(e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),i[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-c[2]))),l[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),a[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-o[2])),e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-c[2]))),i[3]))),e(e(r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-o[2])),e(r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-c[2]))),-a[3]),r(e(e(r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-c[2]))),o[3])),e(r(e(e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),i[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-c[2]))),-s[3]),r(e(e(r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),i[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-a[2])),e(r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-s[2]))),c[3]))))));return ne[ne.length-1]}return i}var h=[c,l,u];function g(e){var t=h[e.length];return t||=h[e.length]=s(e.length),t.apply(void 0,e)}function _(e,t,n,r,i,a,o,s){function c(t,n,c,l,u,d){switch(arguments.length){case 0:case 1:return 0;case 2:return r(t,n);case 3:return i(t,n,c);case 4:return a(t,n,c,l);case 5:return o(t,n,c,l,u);case 6:return s(t,n,c,l,u,d)}for(var f=Array(arguments.length),p=0;p<arguments.length;++p)f[p]=arguments[p];return e(f)}return c}function v(){for(;h.length<=o;)h.push(s(h.length));t.exports=_.apply(void 0,[g].concat(h));for(var e=0;e<=o;++e)t.exports[e]=h[e]}v()}}),hp=ip({"node_modules/cdt2d/lib/delaunay.js"(e,t){"use strict";var n=mp()[4];ap(),t.exports=i;function r(e,t,r,i,a,o){var s=t.opposite(i,a);if(!(s<0)){if(a<i){var c=i;i=a,a=c,c=o,o=s,s=c}t.isConstraint(i,a)||n(e[i],e[a],e[o],e[s])<0&&r.push(i,a)}}function i(e,t){for(var i=[],a=e.length,o=t.stars,s=0;s<a;++s)for(var c=o[s],l=1;l<c.length;l+=2){var u=c[l];if(!(u<s)&&!t.isConstraint(s,u)){for(var d=c[l-1],f=-1,p=1;p<c.length;p+=2)if(c[p-1]===u){f=c[p];break}f<0||n(e[s],e[u],e[d],e[f])<0&&i.push(s,u)}}for(;i.length>0;){for(var u=i.pop(),s=i.pop(),d=-1,f=-1,c=o[s],m=1;m<c.length;m+=2){var h=c[m-1],g=c[m];h===u?f=g:g===u&&(d=h)}d<0||f<0||n(e[s],e[u],e[d],e[f])>=0||(t.flip(s,u),r(e,t,i,d,s,f),r(e,t,i,s,f,d),r(e,t,i,f,u,d),r(e,t,i,u,d,f))}}}}),gp=ip({"node_modules/cdt2d/lib/filter.js"(e,t){"use strict";var n=ap();t.exports=c;function r(e,t,n,r,i,a,o){this.cells=e,this.neighbor=t,this.flags=r,this.constraint=n,this.active=i,this.next=a,this.boundary=o}var i=r.prototype;function a(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}i.locate=(function(){var e=[0,0,0];return function(t,r,i){var o=t,s=r,c=i;return r<i?r<t&&(o=r,s=i,c=t):i<t&&(o=i,s=t,c=r),o<0?-1:(e[0]=o,e[1]=s,e[2]=c,n.eq(this.cells,e,a))}})();function o(e,t){for(var n=e.cells(),i=n.length,o=0;o<i;++o){var s=n[o],c=s[0],l=s[1],u=s[2];l<u?l<c&&(s[0]=l,s[1]=u,s[2]=c):u<c&&(s[0]=u,s[1]=c,s[2]=l)}n.sort(a);for(var d=Array(i),o=0;o<d.length;++o)d[o]=0;var f=[],p=[],m=Array(3*i),h=Array(3*i),g=null;t&&(g=[]);for(var _=new r(n,m,h,d,f,p,g),o=0;o<i;++o)for(var s=n[o],v=0;v<3;++v){var c=s[v],l=s[(v+1)%3],y=m[3*o+v]=_.locate(l,c,e.opposite(l,c)),b=h[3*o+v]=e.isConstraint(c,l);y<0&&(b?p.push(o):(f.push(o),d[o]=1),t&&g.push([l,c,-1]))}return _}function s(e,t,n){for(var r=0,i=0;i<e.length;++i)t[i]===n&&(e[r++]=e[i]);return e.length=r,e}function c(e,t,n){var r=o(e,n);if(t===0)return n?r.cells.concat(r.boundary):r.cells;for(var i=1,a=r.active,c=r.next,l=r.flags,u=r.cells,d=r.constraint,f=r.neighbor;a.length>0||c.length>0;){for(;a.length>0;){var p=a.pop();if(l[p]!==-i){l[p]=i,u[p];for(var m=0;m<3;++m){var h=f[3*p+m];h>=0&&l[h]===0&&(d[3*p+m]?c.push(h):(a.push(h),l[h]=i))}}}var g=c;c=a,a=g,c.length=0,i=-i}var _=s(u,l,t);return n?_.concat(r.boundary):_}}}),_p=ip({"node_modules/cdt2d/cdt2d.js"(e,t){var n=fp(),r=pp(),i=hp(),a=gp();t.exports=u;function o(e){return[Math.min(e[0],e[1]),Math.max(e[0],e[1])]}function s(e,t){return e[0]-t[0]||e[1]-t[1]}function c(e){return e.map(o).sort(s)}function l(e,t,n){return t in e?e[t]:n}function u(e,t,o){Array.isArray(t)?(o||={},t||=[]):(o=t||{},t=[]);var s=!!l(o,`delaunay`,!0),u=!!l(o,`interior`,!0),d=!!l(o,`exterior`,!0),f=!!l(o,`infinity`,!1);if(!u&&!d||e.length===0)return[];var p=n(e,t);if(s||u!==d||f){for(var m=r(e.length,c(t)),h=0;h<p.length;++h){var g=p[h];m.addTriangle(g[0],g[1],g[2])}return s&&i(e,m),d?u?f?a(m,0,f):m.cells():a(m,1,f):a(m,-1)}return p}}})(),vp=class{constructor(e){this.createFn=e,this._pool=[],this._index=0}getInstance(){return this._index>=this._pool.length&&this._pool.push(this.createFn()),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}},yp=1e-16,bp=1e-16,xp=new J,Sp=new J,Cp=new vp(()=>({param:0,index:0})),wp=new vp(()=>new J);function Tp(e,t,n,r){Cp.clear(),t.length=0,n.length=0;for(let t=0,n=e.length;t<n;t++){let n=e[t];c(n.start),c(n.end)}for(let t=0,n=e.length;t<n;t++){let i=e[t];for(let a=t+1;a<n;a++){let t=e[a];i.distanceSqToLine3(t,xp,Sp)<yp*r&&c(Sp)}}let i=[];for(let a=0,o=e.length;a<o;a++){i.length=0;let o=e[a];for(let e=0,n=t.length;e<n;e++){let n=t[e],a=o.closestPointToPointParameter(n,!0);if(o.at(a,xp),n.distanceToSquared(xp)<yp*r){let t=Cp.getInstance();t.param=a,t.index=e,i.push(t)}}i.sort(s);for(let e=0,t=i.length-1;e<t;e++){let t=i[e].index,r=i[e+1].index;t!==r&&n.push([t,r])}}let a=new Set,o=0;for(let e=0,t=n.length;e<t;e++){let t=n[e],r=Math.min(t[0],t[1]),i=Math.max(t[0],t[1]),s=r+`,`+i;a.has(s)||(a.add(s),n[o++]=t)}n.length=o;function s(e,t){return e.param-t.param}function c(e){for(let n=0;n<t.length;n++){let i=t[n];if(e===i||e.distanceToSquared(i)<bp*r)return n}return t.push(wp.getInstance().copy(e)),t.length-1}}var Ep=class{constructor(){this.trianglePool=new vp(()=>new Xu),this.linePool=new vp(()=>new ys),this.triangles=[],this.triangleIndices=[],this.constrainedEdges=[],this.triangleConnectivity=[],this.normal=new J,this.projOrigin=new J,this.projU=new J,this.projV=new J,this.baseTri=new Xu,this.baseIndices=[,,,]}initialize(e,t=null,n=null,r=null){this.reset();let{normal:i,baseTri:a,projU:o,projV:s,projOrigin:c,constrainedEdges:l,linePool:u,baseIndices:d}=this;e.getNormal(i),a.copy(e),a.update(),d[0]=t,d[1]=n,d[2]=r,l.length=0;let f=u.getInstance();f.start.copy(a.a),f.end.copy(a.b);let p=u.getInstance();p.start.copy(a.b),p.end.copy(a.c);let m=u.getInstance();m.start.copy(a.c),m.end.copy(a.a),l.push(f,p,m),c.copy(a.a),o.subVectors(a.b,a.a).normalize(),s.crossVectors(i,o).normalize()}addConstraintEdge(e){let{constrainedEdges:t,linePool:n}=this,r=n.getInstance().copy(e);t.push(r)}_to2D(e,t){let{projOrigin:n,projU:r,projV:i}=this;return xp.subVectors(e,n),t.set(xp.dot(r),xp.dot(i),0)}_from2D(e,t,n){let{projOrigin:r,projU:i,projV:a}=this;return n.copy(r).addScaledVector(i,e).addScaledVector(a,t),n}triangulate(){let{triangles:e,trianglePool:t,triangleConnectivity:n,triangleIndices:r,linePool:i,baseTri:a,constrainedEdges:o,baseIndices:s}=this;e.length=0,t.clear();let c=[];for(let e=0,t=o.length;e<t;e++){let t=o[e],n=i.getInstance();this._to2D(t.start,n.start),this._to2D(t.end,n.end),c.push(n)}let l=0;for(let e=0;e<3;e++){let t=this._to2D(a.points[e],xp);l=Math.max(l,Math.abs(t.x),Math.abs(t.y))}let u=[],d=[];Tp(c,u,d,l);let f=[];for(let e=0,t=u.length;e<t;e++){let t=u[e];f.push([t.x,t.y])}let p=_p(f,d,{exterior:!1}),m=new Map;for(let e=0,t=d.length;e<t;e++){let t=d[e];m.set(`${t[0]}_${t[1]}`,-1),m.set(`${t[1]}_${t[0]}`,-1)}let h=`${s[0]}_${s[1]}_${s[2]}_`;for(let i=0,a=p.length;i<a;i++){let a=p[i],[o,c,l]=a,u=t.getInstance();this._from2D(f[o][0],f[o][1],u.a),this._from2D(f[c][0],f[c][1],u.b),this._from2D(f[l][0],f[l][1],u.c),e.push(u);let d=[];n.push(d);let g=[];r.push(g);for(let e=0;e<3;e++){let t=a[e];g.push(t<3?s[t]:h+t);let r=a[(e+1)%3],o=`${t}_${r}`;if(m.has(o)){let e=m.get(o);e!==-1&&(d.push(e),n[e].push(i))}else{let e=`${r}_${t}`;m.set(e,i)}}}}reset(){this.trianglePool.clear(),this.linePool.clear(),this.triangles.length=0,this.triangleIndices.length=0,this.triangleConnectivity.length=0,this.constrainedEdges.length=0}},Dp=1e-14,Op=new J,kp=new J,Ap=new J;function jp(e,t=Dp){Op.subVectors(e.b,e.a),kp.subVectors(e.c,e.a),Ap.subVectors(e.b,e.c);let n=Op.angleTo(kp),r=Op.angleTo(Ap),i=Math.PI-n-r;return Math.abs(n)<t||Math.abs(r)<t||Math.abs(i)<t||e.a.distanceToSquared(e.b)<t||e.a.distanceToSquared(e.c)<t||e.b.distanceToSquared(e.c)<t}var Mp=1e-10,Np=1e-10,Pp=new ys,Fp=new ys,Ip=new J,Lp=new J,Rp=new J,zp=new ci,Bp=new Xu,Vp=class{constructor(){this.trianglePool=new vp(()=>new $n),this.triangles=[],this.normal=new J}initialize(e){this.reset();let{triangles:t,trianglePool:n,normal:r}=this;if(Array.isArray(e))for(let i=0,a=e.length;i<a;i++){let a=e[i];if(i===0)a.getNormal(r);else if(Math.abs(1-a.getNormal(Ip).dot(r))>Mp)throw Error(`Triangle Splitter: Cannot initialize with triangles that have different normals.`);let o=n.getInstance();o.copy(a),t.push(o)}else{e.getNormal(r);let i=n.getInstance();i.copy(e),t.push(i)}}splitByTriangle(e,t){let{triangles:n}=this;if(t){for(let e=0,t=n.length;e<t;e++){let t=n[e];t.coplanarCount=0}let t=[e.a,e.b,e.c];for(let n=0;n<3;n++){let r=(n+1)%3,i=t[n],a=t[r];e.getNormal(Lp).normalize(),Ip.subVectors(a,i).normalize(),Rp.crossVectors(Lp,Ip),zp.setFromNormalAndCoplanarPoint(Rp,i),this.splitByPlane(zp,e)}}else e.getPlane(zp),this.splitByPlane(zp,e)}splitByPlane(e,t){let{triangles:n,trianglePool:r}=this;Bp.copy(t),Bp.needsUpdate=!0;for(let t=0,i=n.length;t<i;t++){let a=n[t];if(!Bp.intersectsTriangle(a,Pp,!0))continue;let{a:o,b:s,c}=a,l=0,u=-1,d=!1,f=[],p=[],m=[o,s,c];for(let t=0;t<3;t++){let n=(t+1)%3;Pp.start.copy(m[t]),Pp.end.copy(m[n]);let r=e.distanceToPoint(Pp.start),i=e.distanceToPoint(Pp.end);if(Math.abs(r)<Np&&Math.abs(i)<Np){d=!0;break}if(r>0?f.push(t):p.push(t),Math.abs(r)<Np)continue;let a=!!e.intersectLine(Pp,Ip);!a&&Math.abs(i)<Np&&(Ip.copy(Pp.end),a=!0),a&&!(Ip.distanceTo(Pp.start)<Mp)&&(Ip.distanceTo(Pp.end)<Mp&&(u=t),l===0?Fp.start.copy(Ip):Fp.end.copy(Ip),l++)}if(!d&&l===2&&Fp.distance()>Np){if(u!==-1){u=(u+1)%3;let e=0;e===u&&(e=(e+1)%3);let o=e+1;o===u&&(o=(o+1)%3);let s=r.getInstance();s.a.copy(m[o]),s.b.copy(Fp.end),s.c.copy(Fp.start),jp(s)||n.push(s),a.a.copy(m[e]),a.b.copy(Fp.start),a.c.copy(Fp.end),jp(a)&&(n.splice(t,1),t--,i--)}else{let e=f.length>=2?p[0]:f[0];if(e===0){let e=Fp.start;Fp.start=Fp.end,Fp.end=e}let o=(e+1)%3,s=(e+2)%3,c=r.getInstance(),l=r.getInstance();m[o].distanceToSquared(Fp.start)<m[s].distanceToSquared(Fp.end)?(c.a.copy(m[o]),c.b.copy(Fp.start),c.c.copy(Fp.end),l.a.copy(m[o]),l.b.copy(m[s]),l.c.copy(Fp.start)):(c.a.copy(m[s]),c.b.copy(Fp.start),c.c.copy(Fp.end),l.a.copy(m[o]),l.b.copy(m[s]),l.c.copy(Fp.end)),a.a.copy(m[e]),a.b.copy(Fp.end),a.c.copy(Fp.start),jp(c)||n.push(c),jp(l)||n.push(l),jp(a)&&(n.splice(t,1),t--,i--)}}else l===3&&console.warn(`TriangleClipper: Coplanar clip not handled`)}}reset(){this.triangles.length=0,this.trianglePool.clear()}},Hp=class{constructor(){this.coplanarSet=new Map,this.intersectionSet=new Map,this.edgeSet=new Map,this.ids=[]}add(e,t,n=!1){let{intersectionSet:r,coplanarSet:i,ids:a}=this;r.has(e)||(r.set(e,[]),a.push(e)),r.get(e).push(t),n&&(i.has(e)||i.set(e,new Set),i.get(e).add(t))}addIntersectionEdge(e,t){let{edgeSet:n}=this;n.has(e)||n.set(e,new Set),n.get(e).add(t)}getIntersectionEdges(e){return this.edgeSet.get(e)||null}},Up=1e-10,Wp=1e-15,Gp=1e-10,Kp=1e-10,qp=new ys,Jp=new ys,Yp=new J,Xp=new J,Zp=new J,Qp=new ci,$p=new J,em=new J;function tm(e,t){e.getNormal($p),t.getNormal(em);let n=$p.dot(em);if(Math.abs(1-Math.abs(n))>=Gp)return!1;let r=$p.dot(e.a),i=$p.dot(t.a);return Math.abs(r-i)<Kp}function nm(e,t,n,r){let i=0,a=1;e.delta(Yp);let o=[t.a,t.b,t.c];for(let t=0;t<3;t++){let r=o[t],s=o[(t+1)%3];Xp.subVectors(s,r),Zp.crossVectors(n,Xp),Qp.setFromNormalAndCoplanarPoint(Zp,r);let c=Qp.distanceToPoint(e.start),l=Qp.normal.dot(Yp);if(Math.abs(l)<Wp){if(c<-1e-10)return null;continue}let u=-c/l;if(l>0?i=Math.max(i,u):a=Math.min(a,u),i>a+Up)return null}return a-i<Up?null:(e.at(i,r.start),e.at(a,r.end),r)}function rm(e,t,n){let r=0;e.getNormal($p),t.getNormal(em);let i=[t.a,t.b,t.c];for(let t=0;t<3;t++){Jp.start.copy(i[t]),Jp.end.copy(i[(t+1)%3]);let a=nm(Jp,e,$p,qp);a!==null&&(r>=n.length&&n.push(new ys),n[r].copy(a),r++)}let a=[e.a,e.b,e.c];for(let e=0;e<3;e++){Jp.start.copy(a[e]),Jp.end.copy(a[(e+1)%3]);let i=nm(Jp,t,em,qp);i!==null&&(r>=n.length&&n.push(new ys),n[r].copy(i),r++)}return r}var im=new Hr,am=new Y,om=new ys,sm=[],cm=new vp(()=>new ys),lm=null;function um(e){lm=e}function dm(e,t,n=null){e.getMidpoint(im.origin),e.getNormal(im.direction),n&&(im.origin.applyMatrix4(n),im.direction.transformDirection(n));let r=t.raycastFirst(im,2);return r&&im.direction.dot(r.face.normal)>0?-1:1}function fm(e,t){let n=new Hp,r=new Hp;return cm.clear(),am.copy(e.matrixWorld).invert().multiply(t.matrixWorld),e.geometry.boundsTree.bvhcast(t.geometry.boundsTree,am,{intersectsTriangles(i,a,o,s){if(!jp(i)&&!jp(a)){let c=(tm(i,a)?rm(i,a,sm):0)>2;if(c||i.intersectsTriangle(a,om,!0)){let l=e.geometry.boundsTree.resolveTriangleIndex(o),u=t.geometry.boundsTree.resolveTriangleIndex(s);if(n.add(l,u,c),r.add(u,l,c),c){let e=rm(i,a,sm);for(let t=0;t<e;t++){let e=cm.getInstance().copy(sm[t]);n.addIntersectionEdge(l,e),r.addIntersectionEdge(u,e)}}else{let e=cm.getInstance().copy(om),t=cm.getInstance().copy(om);n.addIntersectionEdge(l,e),r.addIntersectionEdge(u,t)}lm&&(lm.addEdge(om),lm.addIntersectingTriangles(o,i,s,a))}}return!1}}),{aIntersections:n,bIntersections:r}}function pm(e,t,n=!1){switch(e){case 0:if(t===1||t===2&&!n)return 1;break;case 1:if(n){if(t===-1)return 0}else if(t===1||t===-2)return 1;break;case 2:if(n){if(t===1||t===-2)return 1}else if(t===-1)return 0;break;case 4:if(t===-1)return 0;if(t===1)return 1;break;case 3:if(t===-1||t===2&&!n)return 1;break;case 5:if(!n&&(t===1||t===-2))return 1;break;case 6:if(!n&&(t===-1||t===2))return 1;break;default:throw Error(`Unrecognized CSG operation enum "${e}".`)}return 2}var mm=class{constructor(e){this.triangle=new $n().copy(e),this.intersects={}}addTriangle(e,t){this.intersects[e]=new $n().copy(t)}getIntersectArray(){let e=[],{intersects:t}=this;for(let n in t)e.push(t[n]);return e}},hm=class{constructor(){this.data={}}addTriangleIntersection(e,t,n,r){let{data:i}=this;i[e]||(i[e]=new mm(t)),i[e].addTriangle(n,r)}getTrianglesAsArray(e=null){let{data:t}=this,n=[];if(e!==null)e in t&&n.push(t[e].triangle);else for(let e in t)n.push(t[e].triangle);return n}getTriangleIndices(){return Object.keys(this.data).map(e=>parseInt(e))}getIntersectionIndices(e){let{data:t}=this;return t[e]?Object.keys(t[e].intersects).map(e=>parseInt(e)):[]}getIntersectionsAsArray(e=null,t=null){let{data:n}=this,r=new Set,i=[],a=e=>{if(n[e]){if(t!==null)n[e].intersects[t]&&i.push(n[e].intersects[t]);else{let t=n[e].intersects;for(let e in t)r.has(e)||(r.add(e),i.push(t[e]))}}};if(e!==null)a(e);else for(let e in n)a(e);return i}reset(){this.data={}}},gm=class{constructor(){this.enabled=!1,this.triangleIntersectsA=new hm,this.triangleIntersectsB=new hm,this.intersectionEdges=[]}addIntersectingTriangles(e,t,n,r){let{triangleIntersectsA:i,triangleIntersectsB:a}=this;i.addTriangleIntersection(e,t,n,r),a.addTriangleIntersection(n,r,e,t)}addEdge(e){this.intersectionEdges.push(e.clone())}reset(){this.triangleIntersectsA.reset(),this.triangleIntersectsB.reset(),this.intersectionEdges=[]}init(){this.enabled&&(this.reset(),um(this))}complete(){this.enabled&&um(null)}},_m=new Y,vm=new Y,ym=new Y,bm=new Ft,xm=new $n,Sm=new $n,Cm=new $n,wm=new $n,Tm=[],Em=[],Dm=new Set,Om=new J,km=new J,Am=new vp(()=>new $n),jm=new J,Mm=[];function Nm(e,t,n,r,i,a={}){let{useGroups:o=!0}=a,{aIntersections:s,bIntersections:c}=fm(e,t),l=[],u;return u=o?0:-1,Fm(e,t,s,n,!1,i,u),Pm(e,t,s,n,!1,r,i,u),n.findIndex(e=>e!==6&&e!==5)!==-1&&(i.forEach(e=>e.clearIndexMap()),u=o?e.geometry.groups.length||1:-1,Fm(t,e,c,n,!0,i,u),Pm(t,e,c,n,!0,r,i,u)),i.forEach(e=>e.clearIndexMap()),Tm.length=0,{groups:l,materials:null}}function Pm(e,t,n,r,i,a,o,s=0){_m.copy(t.matrixWorld).invert().multiply(e.matrixWorld),vm.copy(_m).invert(),i?ym.copy(_m):ym.identity();let c=ym.determinant()<0;bm.getNormalMatrix(ym).multiplyScalar(c?-1:1);let l=e.geometry.groupIndices,u=e.geometry.index,d=e.geometry.attributes.position,f=t.geometry.boundsTree,p=t.geometry.index,m=t.geometry.attributes.position,h=n.ids;for(let t=0,g=h.length;t<g;t++){let g=h[t],_=s===-1?0:l[g]+s,v=3*g,y=v+0,b=v+1,x=v+2;u&&(y=u.getX(y),b=u.getX(b),x=u.getX(x)),xm.a.fromBufferAttribute(d,y),xm.b.fromBufferAttribute(d,b),xm.c.fromBufferAttribute(d,x),i&&(xm.a.applyMatrix4(_m),xm.b.applyMatrix4(_m),xm.c.applyMatrix4(_m)),a.reset(),a.initialize(xm,y,b,x),Mm.length=0,Am.clear(),xm.getNormal(km);let S=n.coplanarSet.get(g);if(S)for(let e of S){let t=3*e,n=t+0,r=t+1,a=t+2;p&&(n=p.getX(n),r=p.getX(r),a=p.getX(a));let o=Am.getInstance();o.a.fromBufferAttribute(m,n),o.b.fromBufferAttribute(m,r),o.c.fromBufferAttribute(m,a),i||(o.a.applyMatrix4(vm),o.b.applyMatrix4(vm),o.c.applyMatrix4(vm)),Mm.push(o)}if(a.addConstraintEdge){let e=n.getIntersectionEdges(g);if(e)for(let t of e)a.addConstraintEdge(t);a.triangulate()}else{let e=n.intersectionSet.get(g);for(let t=0,n=e.length;t<n;t++){let n=e[t],r=S&&S.has(n),o=3*n,s=o+0,c=o+1,l=o+2;p&&(s=p.getX(s),c=p.getX(c),l=p.getX(l)),Sm.a.fromBufferAttribute(m,s),Sm.b.fromBufferAttribute(m,c),Sm.c.fromBufferAttribute(m,l),i||(Sm.a.applyMatrix4(vm),Sm.b.applyMatrix4(vm),Sm.c.applyMatrix4(vm)),a.splitByTriangle(Sm,r)}}let{triangles:C,triangleIndices:w=[],triangleConnectivity:T=[]}=a;for(let t=0,n=o.length;t<n;t++)o[t].initInterpolatedAttributeData(e.geometry,ym,bm,y,b,x);Dm.clear();for(let e=0,t=C.length;e<t;e++){if(Dm.has(e))continue;let t=C[e],n=i?null:_m,a=null;t.getMidpoint(Om);for(let e=0,t=Mm.length;e<t;e++){let t=Mm[e];if(t.containsPoint(Om)){t.getNormal(jm),a=km.dot(jm)>0?2:-2;break}}a===null&&(a=dm(t,f,n)),Tm.length=0,Em.length=0;for(let e=0,t=r.length;e<t;e++){let t=pm(r[e],a,i);t!==2&&(Tm.push(t),Em.push(o[e]))}if(Em.length!==0){let t=[e];for(;t.length>0;){let e=t.pop();if(Dm.has(e))continue;Dm.add(e);let n=w[e],r=null,i=null,a=null;n&&(r=n[0],i=n[1],a=n[2]);let o=C[e];xm.getBarycoord(o.a,wm.a),xm.getBarycoord(o.b,wm.b),xm.getBarycoord(o.c,wm.c);for(let e=0,t=Em.length;e<t;e++){let t=Em[e],n=c!==(Tm[e]===0);t.appendInterpolatedAttributeData(_,wm.a,r,n),n?(t.appendInterpolatedAttributeData(_,wm.c,a,n),t.appendInterpolatedAttributeData(_,wm.b,i,n)):(t.appendInterpolatedAttributeData(_,wm.b,i,n),t.appendInterpolatedAttributeData(_,wm.c,a,n))}}}}}return h.length}function Fm(e,t,n,r,i,a,o=0){_m.copy(t.matrixWorld).invert().multiply(e.matrixWorld),i?ym.copy(_m):ym.identity();let s=ym.determinant()<0;bm.getNormalMatrix(ym).multiplyScalar(s?-1:1);let c=t.geometry.boundsTree,l=e.geometry.groupIndices,u=e.geometry.index,d=e.geometry.attributes.position,f=[],p=e.geometry.halfEdges,m=new Set(n.ids),h=If(e.geometry);for(let t=0;t<h&&m.size!==h;t++){if(m.has(t))continue;m.add(t),f.push(t);let n=3*t,h=n+0,g=n+1,_=n+2;u&&(h=u.getX(h),g=u.getX(g),_=u.getX(_)),Cm.a.fromBufferAttribute(d,h),Cm.b.fromBufferAttribute(d,g),Cm.c.fromBufferAttribute(d,_),i&&(Cm.a.applyMatrix4(_m),Cm.b.applyMatrix4(_m),Cm.c.applyMatrix4(_m));let v=dm(Cm,c,i?null:_m);Tm.length=0,Em.length=0;for(let e=0,t=r.length;e<t;e++){let t=pm(r[e],v,i);t!==2&&(Tm.push(t),Em.push(a[e]))}for(;f.length>0;){let t=f.pop();for(let e=0;e<3;e++){let n=p.getSiblingTriangleIndex(t,e);n!==-1&&!m.has(n)&&(f.push(n),m.add(n))}if(Em.length!==0){let n=3*t,r=n+0,i=n+1,a=n+2;u&&(r=u.getX(r),i=u.getX(i),a=u.getX(a));let c=o===-1?0:l[t]+o;if(Cm.a.fromBufferAttribute(d,r),Cm.b.fromBufferAttribute(d,i),Cm.c.fromBufferAttribute(d,a),!jp(Cm))for(let t=0,n=Em.length;t<n;t++){let n=Em[t],o=Tm[t]===0!==s;n.appendIndexFromGeometry(e.geometry,ym,bm,c,r,o),o?(n.appendIndexFromGeometry(e.geometry,ym,bm,c,a,o),n.appendIndexFromGeometry(e.geometry,ym,bm,c,i,o)):(n.appendIndexFromGeometry(e.geometry,ym,bm,c,i,o),n.appendIndexFromGeometry(e.geometry,ym,bm,c,a,o))}}}}}function Im(e){return e=~~e,e+4-e%4}var Lm=class{constructor(e,t=500){this.expansionFactor=1.5,this.type=e,this.length=0,this.array=null,this.setSize(t)}setType(e){if(e===this.type)return;if(this.length!==0)throw Error(`TypeBackedArray: Cannot change the type while there is used data in the buffer.`);let t=this.array.buffer;this.array=new e(t),this.type=e}setSize(e){if(this.array&&e===this.array.length)return;let t=this.type,n=new t(new(Nf()?SharedArrayBuffer:ArrayBuffer)(Im(e*t.BYTES_PER_ELEMENT)));this.array&&n.set(this.array,0),this.array=n}expand(){let{array:e,expansionFactor:t}=this;this.setSize(e.length*t)}push(...e){let{array:t,length:n}=this;n+e.length>t.length&&(this.expand(),t=this.array);for(let r=0,i=e.length;r<i;r++)t[n+r]=e[r];this.length+=e.length}clear(){this.length=0}},Rm=new J,zm=new J,Bm=new J,Vm=new J,Hm=new Zt,Um=new Zt,Wm=new Zt,Gm=new Zt;function Km(e,t,n,r,i,a=!1,o=!1){return i.set(0,0,0,0).addScaledVector(e,r.x).addScaledVector(t,r.y).addScaledVector(n,r.z),a&&i.normalize(),o&&i.multiplyScalar(-1),i}function qm(e,t,n){switch(t){case 1:n.push(e.x);break;case 2:n.push(e.x,e.y);break;case 3:n.push(e.x,e.y,e.z);break;case 4:n.push(e.x,e.y,e.z,e.w)}}var Jm=class extends Lm{get count(){return this.length/this.itemSize}constructor(...e){super(...e),this.itemSize=1,this.normalized=!1}},Ym=class{constructor(){this.attributeData={},this.groupIndices=[],this.forwardIndexMap=new Map,this.invertedIndexMap=new Map,this.interpolatedFields={}}initFromGeometry(e,t){this.clear();let{attributeData:n}=this,r=e.attributes;for(let e=0,i=t.length;e<i;e++){let i=t[e],a=r[i],o=a.array.constructor;n[i]||(n[i]=new Jm(o)),n[i].setType(o),n[i].itemSize=a.itemSize,n[i].normalized=a.normalized}for(let e in n.attributes)t.includes(e)||n.delete(e)}initInterpolatedAttributeData(e,t,n,r,i,a){let{attributeData:o,interpolatedFields:s}=this,{attributes:c}=e;for(let e in o){let o=c[e];if(!o)throw Error(`CSG Operations: Attribute ${e} not available on geometry.`);let l,u,d;if(e===`position`?(l=zm.fromBufferAttribute(o,r).applyMatrix4(t),u=Bm.fromBufferAttribute(o,i).applyMatrix4(t),d=Vm.fromBufferAttribute(o,a).applyMatrix4(t)):e===`normal`?(l=zm.fromBufferAttribute(o,r).applyNormalMatrix(n),u=Bm.fromBufferAttribute(o,i).applyNormalMatrix(n),d=Vm.fromBufferAttribute(o,a).applyNormalMatrix(n)):e===`tangent`?(l=zm.fromBufferAttribute(o,r).transformDirection(t),u=Bm.fromBufferAttribute(o,i).transformDirection(t),d=Vm.fromBufferAttribute(o,a).transformDirection(t)):(l=Um.fromBufferAttribute(o,r),u=Wm.fromBufferAttribute(o,i),d=Gm.fromBufferAttribute(o,a)),!s[e])s[e]=[l.clone(),u.clone(),d.clone()];else{let t=s[e];t[0].copy(l),t[1].copy(u),t[2].copy(d)}}}appendInterpolatedAttributeData(e,t,n=null,r=!1){let{groupIndices:i,attributeData:a,interpolatedFields:o,forwardIndexMap:s,invertedIndexMap:c}=this;for(;i.length<=e;)i.push(new Jm(Uint32Array));let l=r?c:s,u=i[e];if(n!==null&&l.has(n))u.push(l.get(n));else{l.set(n,a.position.count),u.push(a.position.count);for(let e in o){let n=a[e],i=e===`normal`||e===`tangent`,s=r&&i,c=n.itemSize,[l,u,d]=o[e];Km(l,u,d,t,Hm,i,s),qm(Hm,c,n)}}}appendIndexFromGeometry(e,t,n,r,i,a=!1){let{groupIndices:o,attributeData:s,forwardIndexMap:c,invertedIndexMap:l}=this;for(;o.length<=r;)o.push(new Jm(Uint32Array));let u=a?l:c,d=o[r];if(i!==null&&u.has(i))d.push(u.get(i));else{u.set(i,s.position.count),d.push(s.position.count);let{attributes:r}=e;for(let e in s){let o=s[e],c=r[e];if(!c)throw Error(`CSG Operations: Attribute ${e} not available on geometry.`);let l=c.itemSize;e===`position`?(Rm.fromBufferAttribute(c,i).applyMatrix4(t),o.push(Rm.x,Rm.y,Rm.z)):e===`normal`?(Rm.fromBufferAttribute(c,i).applyNormalMatrix(n),a&&Rm.multiplyScalar(-1),o.push(Rm.x,Rm.y,Rm.z)):e===`tangent`?(Rm.fromBufferAttribute(c,i).transformDirection(t),a&&Rm.multiplyScalar(-1),o.push(Rm.x,Rm.y,Rm.z)):(Hm.fromBufferAttribute(c,i),qm(Hm,l,o))}}}buildGeometry(e,t){let n=!1,{groupIndices:r,attributeData:i}=this,{attributes:a,index:o}=e;for(let t in i){let r=i[t],{type:o,itemSize:s,normalized:c,length:l,count:u}=r,d=r.array.buffer,f=a[t];(!f||f.count<u||f.array.type!==o)&&(f=new vr(new o(l),s,c),e.setAttribute(t,f),n=!0),f.array.set(new o(d,0,l),0),f.needsUpdate=!0}let s=r.reduce((e,t)=>t.count+e,0);(!e.index||o.count<s||o.array.type!==Uint32Array)&&(e.setIndex(new vr(new Uint32Array(s),1)),n=!0),e.clearGroups();let c=0;for(let n=0,i=Math.min(t.length,r.length);n<i;n++){let{index:i,materialIndex:a}=t[n],{count:o}=r[i],s=r[i].array.buffer;o!==0&&(e.index.array.set(new Uint32Array(s,0,o),c),e.addGroup(c,o,a),c+=o)}e.setDrawRange(0,c),e.boundsTree=null,e.boundingBox=null,e.boundingSphere=null,n&&e.dispose()}clearIndexMap(){this.forwardIndexMap.clear(),this.invertedIndexMap.clear()}clear(){let{groupIndices:e,attributeData:t}=this;this.interpolatedFields={};for(let e in t)t[e].clear();e.forEach(e=>{e.clear()}),this.clearIndexMap()}};function Xm(e,t){for(let n in e.attributes)t.includes(n)||(e.deleteAttribute(n),e.dispose());return e}function Zm(e,t){let n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=t[i.materialIndex];n.push({...i,materialIndex:t.indexOf(a)})}return n}function Qm(e,t){let n=[],r=new Map;for(let i=0,a=e.length;i<a;i++){let a=e[i];r.has(a.materialIndex)||(r.set(a.materialIndex,n.length),n.push(t[a.materialIndex])),a.materialIndex=r.get(a.materialIndex)}return n}function $m(e){for(let t=0;t<e.length-1;t++){let n=e[t],r=e[t+1];if(n.materialIndex===r.materialIndex){let i=n.start,a=r.start+r.count;r.start=i,r.count=a-i,e.splice(t,1),t--}}}function eh(e,t){let n=t;return Array.isArray(t)||(n=[],e.forEach(e=>{n[e.materialIndex]=t})),n}var th=class{get useCDTClipping(){return this.triangleSplitter instanceof Ep}set useCDTClipping(e){e!==this.useCDTClipping&&(this.triangleSplitter=e?new Ep:new Vp)}constructor(){this.triangleSplitter=new Vp,this.geometryBuilders=[],this.attributes=[`position`,`uv`,`normal`],this.useGroups=!0,this.consolidateGroups=!0,this.removeUnusedMaterials=!0,this.debug=new gm}getGroupRanges(e){return!this.useGroups||e.groups.length===0?[{start:0,count:1/0,materialIndex:0}]:e.groups.map(e=>({...e}))}evaluate(e,t,n,r=new np){let i=!0;if(Array.isArray(n)||(n=[n]),Array.isArray(r)||(r=[r],i=!1),r.length!==n.length)throw Error(`Evaluator: operations and target array passed as different sizes.`);e.prepareGeometry(),t.prepareGeometry();let{triangleSplitter:a,geometryBuilders:o,attributes:s,useGroups:c,consolidateGroups:l,removeUnusedMaterials:u,debug:d}=this;for(;o.length<r.length;)o.push(new Ym);r.forEach((t,n)=>{o[n].initFromGeometry(e.geometry,s),Xm(t.geometry,s)}),d.init(),Nm(e,t,n,a,o,{useGroups:c}),d.complete();let f=this.getGroupRanges(e.geometry),p=eh(f,e.material),m=this.getGroupRanges(t.geometry),h=eh(m,t.material);m.forEach(e=>e.materialIndex+=p.length);let g=[...p,...h],_=[...f,...m].map((e,t)=>({...e,index:t}));return c?c&&l&&(_=Zm(_,g),_.sort((e,t)=>e.materialIndex-t.materialIndex)):_=[{start:0,count:1/0,index:0,materialIndex:0}],r.forEach((t,n)=>{let r=t.geometry;o[n].buildGeometry(r,_),e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.updateMatrix(),t.matrixWorld.copy(e.matrixWorld),c?(t.material=g,l&&$m(r.groups),u&&(t.material=Qm(r.groups,g))):t.material=g[0]}),i?r:r[0]}evaluateHierarchy(e,t=new np){e.updateMatrixWorld(!0);let n=(e,t)=>{let r=e.children;for(let e=0,i=r.length;e<i;e++){let i=r[e];i.isOperationGroup?n(i,t):t(i)}},r=e=>{let t=e.children,i=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];i=r(n)||i}let a=e.isDirty();if(a&&e.markUpdated(),i&&!e.isOperationGroup){let t;return n(e,n=>{t=t?this.evaluate(t,n,n.operation):this.evaluate(e,n,n.operation)}),e._cachedGeometry=t.geometry,e._cachedMaterials=t.material,!0}return i||a};return r(e),t.geometry=e._cachedGeometry,t.material=e._cachedMaterials,t}reset(){this.triangleSplitter.reset()}};function nh(){return{geometries:new Set,materials:new Set,textures:new Set}}function rh(e){let{material:t}=e;return Array.isArray(t)?t:t?.isMaterial?[t]:[]}function ih(e,t){return e.traverse(e=>{let n=e;n.geometry?.isBufferGeometry&&t.geometries.add(n.geometry);for(let e of rh(n)){t.materials.add(e);for(let n of Object.values(e))n&&n.isTexture&&t.textures.add(n)}}),t}function ah(e,t){for(let n of e.geometries)t.geometries.has(n)||n.dispose();for(let n of e.textures)t.textures.has(n)||n.dispose();for(let n of e.materials)t.materials.has(n)||n.dispose()}function oh(e){ah(ih(e,nh()),nh())}function sh(e,t){let n=ih(t,nh()),r=nh();for(let n of e)n!==t&&ih(n,r);ah(r,n)}function ch(e,t){t&&(e?.remove(t),oh(t))}function lh(e){let t=e.userData;return{...t.background?{background:t.background}:{},warnings:t.warnings??[],logs:t.logs??[]}}var uh=1e-9,dh=34e37;function fh(e,t){return Math.abs(e.x-t.x)<uh&&Math.abs(e.y-t.y)<uh}function ph(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2,curved:!1}}function mh(e){let t=e[0],n=e[e.length-1];return e.length>2&&t!==void 0&&n!==void 0&&fh(t,n)}function hh(e){e.updateWorldMatrix(!0,!1);let t=e.geometry.getAttribute(`position`),n=[];for(let r=0;r<t.count;r++){let i=new J().fromBufferAttribute(t,r).applyMatrix4(e.matrixWorld),a=n[n.length-1];(a===void 0||a.distanceToSquared(i)>uh**2)&&n.push(i)}return n}var gh=3e4,_h=8,vh=12,yh=4,bh=1e-9,xh=class extends Error{constructor(e){super(e),this.name=`ShapeScriptLimitError`}};function Sh(e){return{...e,color:e.color?.clone(),glow:e.glow?.clone()}}var Ch=200,wh=200;function Th(e){let t=e.getAttribute(`position`),n=e.getIndex(),r=n?.count??t.count,i=new J,a=new J,o=new J,s=0;for(let e=0;e<r;e+=3)i.fromBufferAttribute(t,n?n.getX(e):e),a.fromBufferAttribute(t,n?n.getX(e+1):e+1),o.fromBufferAttribute(t,n?n.getX(e+2):e+2),s+=i.dot(a.cross(o));return s/6}function Eh(e){if(Th(e)>=0)return e;let t=e.getIndex();if(t){for(let e=0;e<t.count;e+=3){let n=t.getX(e+1);t.setX(e+1,t.getX(e+2)),t.setX(e+2,n)}t.needsUpdate=!0}let n=e.getAttribute(`normal`);if(n){for(let e=0;e<n.count;e++)n.setXYZ(e,-n.getX(e),-n.getY(e),-n.getZ(e));n.needsUpdate=!0}return e}function Dh(e){return Math.max(0,Math.round(Math.log2(Math.max(4,e)))-2)}var Oh=class{options;evaluator;symbols;pathCommandCount=0;detailLevel=32;nodeCount=0;vertexCount=0;startedAt=Date.now();transformStack=[];operandDepth=0;warnings=[];warningSet=new Set;logs=[];background;sceneDepth=0;valueSink=null;retained=[];constructor(e={}){this.options=e,this.symbols=new bc,this.evaluator=new Rc(this.symbols,e.randomSeed),this.symbols.set(`detail`,this.detailLevel),this.evaluator.hooks={shape:e=>this.shapeValue(e),call:(e,t)=>this.callShapeFunction(e,t),retain:e=>this.chargeRetained(e)},this.evaluator.maxLoopIterations=this.maxLoopIterations,this.pushTransform()}convert(e){let t=new An;try{this.addChildren(t,e),t.userData={warnings:this.warnings,logs:this.logs,...this.background?{background:this.background}:{}}}catch(e){throw oh(t),e}finally{this.retained.forEach(e=>e.dispose()),this.retained=[]}return t}get maxNodes(){return this.options.maxNodes??1e5}get maxLoopIterations(){return this.options.maxLoopIterations??1e5}get maxVertices(){return this.options.maxVertices??5e6}get maxDurationMs(){return this.options.maxDurationMs??3e4}chargePathEstimate(e,t,n=1){let r=Math.max(1,e.curves.length)*Math.max(1,t);this.chargeEstimate(r*n)}chargeEstimate(e){if(this.vertexCount+e>this.maxVertices)throw new xh(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or simplify the path`)}makeMesh(e,t){if(this.vertexCount+=e.getAttribute(`position`)?.count??0,this.vertexCount>this.maxVertices)throw e.dispose(),t.dispose(),new xh(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or use fewer shapes`);return new ti(e,t)}convertNode(e){if(this.nodeCount+=1,this.nodeCount>this.maxNodes)throw new xh(`ShapeScript produced more than ${this.maxNodes} objects — reduce the loop counts or the nesting`);if(Date.now()-this.startedAt>this.maxDurationMs)throw new xh(`ShapeScript took longer than ${this.maxDurationMs}ms to build — simplify the model or use fewer boolean operations`);switch(e.type){case`shape`:return this.convertShape(e);case`csg`:return this.convertCSG(e);case`block`:return this.convertBlock(e);case`for`:return this.convertForLoop(e);case`if`:return this.convertIf(e);case`switch`:return this.convertSwitch(e);case`define`:return this.handleDefine(e),null;case`extrude`:return this.convertExtrude(e);case`loft`:return this.convertLoft(e);case`lathe`:return this.convertLathe(e);case`fill`:return this.convertFill(e);case`hull`:return this.convertHull(e);case`minkowski`:return this.convertMinkowski(e);case`text`:return this.convertText(e);case`group`:return this.convertBlock(e);case`detail`:return this.handleDetail(e),null;case`seed`:return this.evaluator.reseed(this.evaluateNumber(e.value)),null;case`color`:return this.handleColorCommand(e),null;case`material`:return this.handleMaterialCommand(e),null;case`smoothing`:return this.currentTransform().material.smoothing=this.evaluateNumber(e.value),null;case`background`:return this.handleBackground(e.value),null;case`print`:return this.logs.length<Ch&&this.logs.push(Fh(this.evaluator.evaluate(e.value))),null;case`assert`:if(!this.evaluator.evaluateToBoolean(e.value))throw Error(`Assertion failed`);return null;case`ignored`:return this.warn(`\`${e.command}\` is not rendered by this viewer and was skipped`),null;case`expression`:return this.convertExpressionStatement(e);case`mesh`:return this.convertMesh(e);case`rotate`:return this.handleRotateCommand(e),null;case`orientation`:return this.handleOrientationCommand(e),null;case`translate`:return this.handleTranslateCommand(e),null;case`scale`:return this.handleScaleCommand(e),null;case`customShape`:return this.convertCustomShape(e);case`path`:return this.operandDepth>0?this.convertPathProfile(e):this.convertPathLine(e);default:throw Error(`Unsupported command: ${e.type}`)}}convertPathProfile(e){return this.withPathDetail(()=>{let t=this.collectPathPoints(e),n=this.shapeFromPathPoints(t);if(!mh(t))return this.lineFromPath(e,n);this.chargePathEstimate(n,vh),this.requireEnclosedArea(n,`path`);let r=this.makeMesh(this.placePath(new Qa(n),e),this.createMaterial({properties:{}}));return this.applyCurrentTransform(r),r})}withPathDetail(e){return this.withShapeOptions({},e)}convertPathLine(e){return this.withPathDetail(()=>this.lineFromPath(e,this.buildPath(e)))}lineFromPath(e,t){let n=this.finitePoints(t.getPoints(Math.max(1,Math.floor(this.detailLevel/4))));if(n.length<2)throw Error("`path` needs at least two points");this.chargeEstimate(n.length),this.vertexCount+=n.length;let r=this.placePath(new Mr().setFromPoints(n),e),i=this.currentTransform().material,a=Math.min(1,Math.max(0,i.alpha*i.opacity)),o=new xi(r,new pi({color:i.color?.clone()??new Ln(.8,.8,.8),opacity:a,transparent:a<1}));return this.applyCurrentTransform(o),o}warn(e){this.warningSet.has(e)||this.warnings.length>=wh||(this.warningSet.add(e),this.warnings.push(e))}handleBackground(e){if(this.sceneDepth>0)throw Error("`background` can only be used at the root of the script");let t=this.evaluator.evaluate(e);if(typeof t==`string`){this.warn(`background image "${t}" is not supported — the scene keeps its default background`);return}this.background=this.requireFiniteColor(zc(t))}inScope(e,t){return this.inFrame(()=>{try{t()}catch(t){throw oh(e),t}return e})}inFrame(e){this.symbols.pushScope(),this.pushTransform(),this.sceneDepth++;try{return e()}finally{this.sceneDepth--,this.popTransform(),this.symbols.popScope()}}addChildren(e,t){for(let n of t){let t=this.convertNode(n);t&&e.add(t)}}convertBlock(e){let t=new An;return this.inScope(t,()=>this.addChildren(t,e.children))}inSymbolScope(e,t){this.symbols.pushScope();try{return t(),e}catch(t){throw oh(e),t}finally{this.symbols.popScope()}}finishMesh(e,t,n=!0,r){let i;try{return i=this.makeMesh(e,this.createMaterial(t,r,e.hasAttribute(`color`))),this.applyExplicitTransforms(i,t.properties,n),this.applyCurrentTransform(i),i}catch(t){throw i?oh(i):e.dispose(),t}}withShapeOptions(e,t){let n=this.detailLevel,r=this.currentTransform().material.smoothing;try{return e.detail!==void 0&&this.handleDetail({type:`detail`,value:e.detail}),e.smoothing!==void 0&&(this.currentTransform().material.smoothing=this.evaluateNumber(e.smoothing)),t()}finally{this.detailLevel=n,this.symbols.set(`detail`,n),this.currentTransform().material.smoothing=r}}convertShape(e){return e.points===void 0?this.withShapeOptions(e.properties,()=>this.finishMesh(this.createGeometry(e),e,!1)):this.placeValue(this.polygonValue(e))}captureValues(e,t){let n=this.valueSink;this.valueSink=e;try{return t()}finally{this.valueSink=n}}placeValue(e){if(this.valueSink)return this.valueSink.push(this.transformedForCapture(e)),null;if(_c(e)&&e.kind===`mesh`)return this.placeMesh(e);if(_c(e)&&e.kind===`polygon`)return this.placePolygons([e]);if(Array.isArray(e)&&e.length>0&&e.every(e=>_c(e)&&(e.kind===`mesh`||e.kind===`polygon`))){let t=e.filter(e=>_c(e)&&e.kind===`mesh`),n=e.filter(e=>_c(e)&&e.kind===`polygon`),r=n.length?Ms(n,n.some(e=>e.colors)):void 0,i=Ph([...t.map(e=>e.geometry),...r?[r]:[]]);r?.dispose();let a=this.placeMesh({kind:`mesh`,geometry:i});return i.dispose(),a}throw Error("Unused value — a statement that is not a shape does nothing here; use `define` or `print`")}transformedForCapture(e){let t=this.currentTransform().matrix,n=t.equals(new Y);if(Array.isArray(e))return n?e:e.map(e=>this.transformedForCapture(e));if(!jh(e)||n)return e;if(e.kind===`polygon`)return{...e,points:e.points.map(e=>new J(...e).applyMatrix4(t).toArray())};let r=e.geometry.clone().applyMatrix4(t);try{this.chargeRetained(r)}catch(e){throw r.dispose(),e}return{...e,geometry:r,...e.polygons?{polygons:e.polygons.map(e=>this.transformedForCapture(e))}:{}}}convertExpressionStatement(e){return this.placeValue(this.evaluator.evaluate(e.value))}placeMesh(e){let t=e.geometry.clone(),n=this.makeMesh(t,this.createMaterial({properties:{}},void 0,t.hasAttribute(`color`)));return e.name!==void 0&&(n.name=e.name),this.applyCurrentTransform(n),n}placePolygons(e){let t=e.some(e=>e.colors!==void 0),n=Ms(e,t);this.chargeEstimate(n.getAttribute(`position`).count);let r=this.makeMesh(n,this.createMaterial({properties:{}},void 0,t));return this.applyCurrentTransform(r),r}chargeRetained(e){let t=e.getAttribute(`position`).count;this.chargeEstimate(t),this.vertexCount+=t,this.retained.push(e)}buildScratch(e,t){let n=new An,r=[],i=this.vertexCount,a=this.retained.length;try{this.captureValues(r,()=>this.inScope(n,()=>{this.currentTransform().matrix.identity(),this.addChildren(n,e),t?.(r)}));let i=this.meshesIn(n),a=i.map(e=>Mh(e).applyMatrix4(e.matrixWorld)),o=i.length===1?i[0]:void 0,s=o?.geometry.userData.polygons,c=o&&s?s.map(e=>({...e,points:e.points.map(e=>new J(...e).applyMatrix4(o.matrixWorld).toArray())})):void 0;return{captured:r,geometries:a,name:o?.name||void 0,polygons:c}}finally{oh(n),this.vertexCount=i,this.vertexCount+=this.retained.slice(a).reduce((e,t)=>e+t.getAttribute(`position`).count,0)}}convertMesh(e){let{captured:t,geometries:n}=this.buildScratch(e.children),r=Ah(t).filter(e=>e.kind===`polygon`),i=Ah(t).filter(e=>e.kind===`mesh`),a=r.some(e=>e.colors!==void 0),o=[...r.length?[Ms(r,a)]:[],...n],s=[...o,...i.map(e=>e.geometry)];if(s.length===0)throw Error("`mesh` needs at least one polygon");let c=Ph(s);o.forEach(e=>e.dispose()),i.length===0&&n.length===0&&(c.userData={polygons:r});let l=this.makeMesh(c,this.createMaterial({properties:{}},void 0,c.hasAttribute(`color`)));return this.applyCurrentTransform(l),l}polygonValue(e){let t=[],n=[],r=e.properties.color===void 0?void 0:this.evaluateRGBA(e.properties.color),i=r!==void 0,a=e=>{if(++this.pathCommandCount>this.maxLoopIterations)throw new xh(`ShapeScript polygon exceeds ${this.maxLoopIterations} commands`);switch(e.type){case`define`:this.handleDefine(e);break;case`color`:r=this.evaluateRGBA(e.value),i=!0;break;case`point`:case`curve`:t.push(this.pointCoordinates(e)),n.push(r??[.8,.8,.8,1]);break;case`for`:this.runPathLoop(e,a);break;case`detail`:break;default:throw Error(`\`${e.type}\` is not supported inside a polygon — list its points`)}};this.symbols.pushScope();try{for(let t of e.points??[])a(t)}finally{this.symbols.popScope()}if(t.length<3)throw Error("`polygon` needs at least three points");let{position:o,orientation:s,rotation:c,size:l}=e.properties;if(o||s||c||l){let n=new Y;this.applyPlacement(n,e.properties);for(let e of t)new J(...e).applyMatrix4(n).toArray(e)}return{kind:`polygon`,points:t,...i?{colors:n}:{}}}pointCoordinates(e){let t=typeof e.x==`number`?e.x:this.evaluator.evaluate(e.x),[n=0,r=0,i=0]=Array.isArray(t)?t.map(e=>typeof e==`number`?e:NaN):[typeof t==`number`?t:NaN,this.evaluateNumber(e.y),e.z===void 0?0:this.evaluateNumber(e.z)];if(![n,r,i].every(Number.isFinite))throw Error(`Expected finite point coordinates`);return[n,r,i]}meshesIn(e){e.updateMatrixWorld(!0);let t=[];return e.traverse(e=>{e.isMesh&&t.push(e)}),t}shapeValue(e){let{captured:t,geometries:n,name:r,polygons:i}=this.buildScratch([e]);if(n.length===0){if(t.length===1)return t[0];if(t.length>1)return t;throw Error(`The shape used as a value produced nothing`)}let a=Ph(n);return n.forEach(e=>e.dispose()),this.chargeRetained(a),{kind:`mesh`,geometry:a,...r===void 0?{}:{name:r},...i===void 0?{}:{polygons:i}}}callShapeFunction(e,t){let{params:n=[],body:r=[],value:i,name:a}=e.definition;return this.evaluator.withArguments(n,t,()=>{let{captured:e,geometries:t}=this.buildScratch(r,e=>{i!==void 0&&e.push(this.transformedForCapture(this.evaluator.evaluate(i)))});for(let n of t)this.chargeRetained(n),e.push({kind:`mesh`,geometry:n});if(e.length===0)throw Error(`Function \`${a}\` produced no value`);return e.length===1?e[0]:e})}requireExtent(e,t){if(t.some(e=>!e))throw Error(`\`${e}\` needs a nonzero size in every dimension — this one encloses nothing`)}createGeometry(e){let t=this.evaluateSize(e.properties.size);switch(e.primitive){case`cube`:return this.requireExtent(`cube`,t),new Ai(t[0],t[1],t[2]);case`sphere`:return this.requireExtent(`sphere`,t),new eo(.5,this.detailLevel,this.detailLevel).scale(...t);case`icosphere`:return this.requireExtent(`icosphere`,t),js(.5,Dh(this.detailLevel)).geometry.scale(...t);case`cylinder`:{let n=e.properties.radiusTop?this.evaluateNumber(e.properties.radiusTop):t[0]/2,r=e.properties.radiusBottom?this.evaluateNumber(e.properties.radiusBottom):t[0]/2,i=e.properties.height?this.evaluateNumber(e.properties.height):t[1];return this.requireExtent(`cylinder`,[n||r,i]),new Mi(n,r,i,this.detailLevel)}case`cone`:{let n=t[0]/2,r=e.properties.height?this.evaluateNumber(e.properties.height):t[1];return this.requireExtent(`cone`,[n,r]),new Ni(n,r,this.detailLevel)}case`torus`:return this.createTorus(e,t);case`circle`:return new ji((t[0]||1)/2,this.detailLevel);case`square`:{let e=t[0]||1;return new Za(e,t[1]||e)}case`roundrect`:return this.createRoundrect(e,t);case`polygon`:{let n=(t[0]||1)/2,r=e.properties.sides===void 0?6:this.evaluateNumber(e.properties.sides);if(!Number.isInteger(r)||r<3||r>256)throw Error(`Polygon sides must be an integer from 3 to 256`);return new ji(n,r)}default:throw Error(`Unknown primitive: ${e.primitive}`)}}createRoundrect(e,t){let n=t[0]||1,r=t[1]||n,i=e.properties.radius===void 0?.25:this.evaluateNumber(e.properties.radius),a=Math.min(Math.max(0,i)*Math.min(n,r),n/2,r/2),o=new ua,s=n/2,c=r/2;o.moveTo(-s+a,-c),o.lineTo(s-a,-c),o.absarc(s-a,-c+a,a,-Math.PI/2,0,!1),o.lineTo(s,c-a),o.absarc(s-a,c-a,a,0,Math.PI/2,!1),o.lineTo(-s+a,c),o.absarc(-s+a,c-a,a,Math.PI/2,Math.PI,!1),o.lineTo(-s,-c+a),o.absarc(-s+a,-c+a,a,Math.PI,Math.PI*1.5,!1),o.closePath();let l=Math.max(1,Math.floor(this.detailLevel/4));return this.chargePathEstimate(o,l),new Qa(o,l)}createTorus(e,t){let n=t[0]/2,r=e.properties.innerRadius?this.evaluateNumber(e.properties.innerRadius):void 0,i=(e.properties.outerRadius?this.evaluateNumber(e.properties.outerRadius):void 0)??(r===void 0?n/1.4:n-r),a=r??i*.4;if(i<=0)throw Error("`torus` tube is as wide as the whole shape — its ring has no radius left");return this.requireExtent(`torus`,[i,a]),new to(i,a,Math.max(3,Math.floor(this.detailLevel/2)),this.detailLevel)}materialFor(e,t){let n=Sh(t);return e.material!==void 0&&this.applyMaterialValue(n,this.evaluator.evaluate(e.material)),e.color!==void 0&&this.applyColor(n,this.evaluateRGBA(e.color)),e.opacity!==void 0&&(n.opacity*=this.evaluateNumber(e.opacity)),e.metallicity!==void 0&&(n.metallicity=this.evaluateNumber(e.metallicity)),e.roughness!==void 0&&(n.roughness=this.evaluateNumber(e.roughness)),e.glow!==void 0&&(n.glow=this.glowColor(this.evaluator.evaluate(e.glow))),e.texture!==void 0&&this.warnTexture(this.evaluator.evaluate(e.texture)),n}applyColor(e,[t,n,r,i]){e.color=new Ln(t,n,r),e.alpha=i}glowColor(e){let[t,n,r]=this.requireFiniteColor(zc(e));return new Ln(t,n,r)}warnTexture(e){e!==``&&this.warn(`texture "${String(e)}" is not supported — the shape is drawn with its colour instead`)}applyMaterialValue(e,t){if(typeof t!=`object`||Array.isArray(t)||t.kind!==`material`)throw Error("`material` needs a value made with `material { … }`");let n=t;n.color&&this.applyColor(e,this.requireFiniteColor(n.color)),n.opacity!==void 0&&(e.opacity*=n.opacity),n.metallicity!==void 0&&(e.metallicity=n.metallicity),n.roughness!==void 0&&(e.roughness=n.roughness),n.glow&&(e.glow=this.glowColor(n.glow)),n.texture!==void 0&&this.warnTexture(n.texture)}createMaterial(e,t,n=!1){let r=this.materialFor(e.properties,t??this.currentTransform().material),i=Math.max(0,r.alpha*r.opacity);return new po({color:n?new Ln(1,1,1):r.color?.clone()??new Ln(.8,.8,.8),vertexColors:n,opacity:Math.min(1,i),transparent:i<1,...r.metallicity===void 0?{}:{metalness:Math.min(1,Math.max(0,r.metallicity))},...r.roughness===void 0?{}:{roughness:Math.min(1,Math.max(0,r.roughness))},...r.glow===void 0?{}:{emissive:r.glow.clone()},flatShading:r.smoothing!==void 0&&r.smoothing<=0,wireframe:this.options.wireframe??!1,userData:{colored:n||r.color!==void 0}})}convertCSG(e){if(e.children.length===0)return new An;let t=this.currentTransform().matrix.clone(),n=[];try{let r=new th;this.symbols.pushScope(),this.pushTransform(),this.currentTransform().matrix.identity();let i=[];try{for(let t of e.children){if(t.type===`path`)throw Error("A `path` has no volume and cannot be a CSG operand — wrap it in `extrude`, `lathe` or `fill`");let e=this.captureValues(null,()=>this.convertNode(t));if(e){if(n.push(e),e.isMesh){let t=e.clone();t.updateMatrixWorld(!0),i.push(t)}else e.isGroup&&(e.updateMatrixWorld(!0),e.traverse(e=>{if(e.isMesh){let t=e.clone();e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),i.push(t)}}))}}}finally{this.popTransform(),this.symbols.popScope()}if(i.length===0)return new An;n.push(...i);let a=i.map(e=>{let t=new np(e.geometry,e.material);return t.position.copy(e.position),t.rotation.copy(e.rotation),t.scale.copy(e.scale),t.updateMatrixWorld(!0),t});n.push(...a);let o=a[0];if(o===void 0)throw Error(`CSG operation needs at least one child shape`);let s=o;for(let t=1;t<a.length;t++){let i=a[t];if(i===void 0)continue;let o=(e,t,i)=>{n.push(e,t);let a=r.evaluate(e,t,i);return n.push(a),this.chargeEstimate(a.geometry.getAttribute(`position`)?.count??0),this.vertexCount+=a.geometry.getAttribute(`position`)?.count??0,a};switch(e.operation){case`union`:s=o(s,i,0);break;case`difference`:s=o(s,i,1);break;case`intersection`:s=o(s,i,3);break;case`xor`:s=o(o(s.clone(),i.clone(),1),o(i.clone(),s.clone(),1),0);break;case`stencil`:{let e=o(s,i,5),t=o(s,i,6);t.material=Array.isArray(i.material)?i.material[0]:i.material,t.geometry.clearGroups(),t.geometry.addGroup(0,t.geometry.index?.count??t.geometry.getAttribute(`position`).count,0);let r=[e,t],a=r.map(e=>e.geometry.clone().applyMatrix4(e.matrixWorld));try{let e=Ks(a);if(!e)throw Error(`Could not combine stencil surfaces`);let t=[],i=0;for(let n of r){for(let r of n.geometry.groups)e.addGroup(i+r.start,r.count,t.length+(r.materialIndex??0));t.push(...Array.isArray(n.material)?n.material:[n.material]),i+=n.geometry.index?.count??n.geometry.getAttribute(`position`).count}s=new np(e,t),n.push(s),this.chargeEstimate(e.getAttribute(`position`).count),this.vertexCount+=e.getAttribute(`position`).count}finally{a.forEach(e=>e.dispose())}break}}}return s.material||(s.material=o.material),s.applyMatrix4(t),s.updateMatrixWorld(!0),sh(n,s),s}catch(e){throw sh(n,new An),e}}convertForLoop(e){let t=new An;return this.inSymbolScope(t,()=>{for(let n of this.iterations(e.iterable))this.symbols.set(e.variable,n),this.addChildren(t,e.body)})}iterations(e){return Fc(this.evaluator.evaluate(e),this.maxLoopIterations,()=>new xh(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`))}convertIf(e){let t=new An,n=this.evaluator.evaluateToBoolean(e.condition);return this.inSymbolScope(t,()=>this.addChildren(t,n?e.thenBody:e.elseBody??[]))}convertSwitch(e){let t=new An,n=this.evaluator.evaluate(e.value);return this.inSymbolScope(t,()=>{let r=e.cases.find(e=>e.values.some(e=>Pc(n,this.evaluator.evaluate(e))));this.addChildren(t,r?r.body:e.defaultCase??[])})}handleDefine(e){this.evaluator.define(e)||(e.body!==void 0||e.options!==void 0)&&this.symbols.set(e.name,e)}convertCustomShape(e){let t=this.symbols.get(e.name);if(t!==void 0&&jh(t)){let n=new An;return this.inScope(n,()=>{this.applyPlacement(this.currentTransform().matrix,e.properties);let r=this.placeValue(t);r&&n.add(r)})}if(t===void 0)throw Error(`Unknown shape: ${e.name}`);if(typeof t!=`object`||Array.isArray(t)||!(`type`in t))return this.placeValue(t);let n=t;if(!n.body)throw Error(`Custom shape '${e.name}' has no body`);let r=new An,i=n.body,{position:a,orientation:o,rotation:s,size:c,name:l,...u}=e.properties;return this.inScope(r,()=>{this.applyPlacement(this.currentTransform().matrix,{position:a,orientation:o,rotation:s,size:c}),this.currentTransform().material=this.materialFor(u,this.currentTransform().material);for(let e of n.options??[])this.symbols.set(e.name,this.evaluator.evaluate(e.defaultValue));for(let[e,t]of Object.entries(u))e in kh||this.symbols.set(e,this.evaluator.evaluate(t));l!==void 0&&(r.name=String(this.evaluator.evaluate(l))),this.withShapeOptions(u,()=>this.addChildren(r,i))})}applyPlacement(e,t){let n=t.position?new J(...this.evaluateVector3(t.position)):new J,r=t.orientation??t.rotation,i=r?this.rotationOf(r):new Mt,a=t.size?new J(...this.evaluateSize(t.size)):new J(1,1,1);e.multiply(new Y().compose(n,i,a))}pushTransform(){let e=this.currentTransform();this.transformStack.push({matrix:e.matrix.clone(),material:Sh(e.material)})}popTransform(){this.transformStack.length>1&&this.transformStack.pop()}currentTransform(){return this.transformStack[this.transformStack.length-1]??{matrix:new Y,material:{color:void 0,alpha:1,opacity:1,metallicity:void 0,roughness:void 0,glow:void 0,smoothing:void 0}}}applyCurrentTransform(e){let t=this.currentTransform();e.applyMatrix4(t.matrix)}applyExplicitTransforms(e,t,n=!1){if(t.position){let n=this.evaluateVector3(t.position);e.position.set(...n)}let r=t.orientation??t.rotation;r&&e.quaternion.copy(this.rotationOf(r)),n&&t.size&&e.scale.set(...this.evaluateSize(t.size)),t.name!==void 0&&(e.name=String(this.evaluator.evaluate(t.name)))}rotationOf(e){let t=this.rotationComponents(e);if(t.length===4){let[e=0,n=0,r=0,i=0]=t,a=Math.max(Math.abs(n),Math.abs(r),Math.abs(i));if(a===0)throw Error(`Rotation axis must not be zero`);let o=new J(n/a,r/a,i/a).normalize();return new Mt().setFromAxisAngle(o,-e*Math.PI)}let[n=0,r=0,i=0]=t;return new Mt().setFromEuler(new fn(-i*Math.PI,-r*Math.PI,-n*Math.PI,`ZYX`))}rotationComponents(e){let t=Array.isArray(e)&&typeof e[0]==`number`?e:this.evaluator.evaluate(e),n=(Array.isArray(t)?t:[t]).map(e=>typeof e==`number`?e:NaN);if(n.length===0||n.length>4||!n.every(Number.isFinite))throw Error(`Expected a rotation of 1 to 3 half-turn components (roll yaw pitch) or an angle and an axis (angle x y z)`);return n}handleDetail(e){let t=this.evaluateNumber(e.value);this.detailLevel=Number.isFinite(t)?Math.min(256,Math.max(3,Math.floor(t))):3,this.symbols.set(`detail`,this.detailLevel)}handleColorCommand(e){this.applyColor(this.currentTransform().material,this.evaluateRGBA(e.value))}handleMaterialCommand(e){let t=this.currentTransform().material;switch(e.property){case`opacity`:t.opacity*=this.evaluateNumber(e.value);break;case`metallicity`:t.metallicity=this.evaluateNumber(e.value);break;case`roughness`:t.roughness=this.evaluateNumber(e.value);break;case`glow`:t.glow=this.glowColor(this.evaluator.evaluate(e.value));break;case`texture`:this.warnTexture(this.evaluator.evaluate(e.value));break;case`material`:this.applyMaterialValue(t,this.evaluator.evaluate(e.value))}}handleRotateCommand(e){this.currentTransform().matrix.multiply(new Y().makeRotationFromQuaternion(this.rotationOf(e.value)))}handleOrientationCommand(e){let t=this.currentTransform(),n=new J,r=new J;t.matrix.decompose(n,new Mt,r),t.matrix.compose(n,this.rotationOf(e.value),r)}handleTranslateCommand(e){let t=this.currentTransform(),[n,r,i]=this.evaluateTranslateVector(e.value);if(![n,r,i].every(Number.isFinite))throw Error(`Expected finite translation components`);let a=new Y().makeTranslation(n,r,i);t.matrix.multiply(a)}handleScaleCommand(e){let t=this.evaluateSize(e.value),n=this.currentTransform(),r=new Y().makeScale(t[0],t[1],t[2]);n.matrix.multiply(r)}requireEnclosedArea(e,t){let n=e.getPoints(vh),r=Wa.area(n);if(!Number.isFinite(r))throw Error(`\`${t}\` needs finite path coordinates — these overflow`);if(n.length<3||Math.abs(r)<bh)throw Error(`\`${t}\` needs a path that encloses an area — this one has fewer than three distinct points, or they are collinear`);return e}extrudeProperties(e){let t=e.properties.size?this.evaluateSize(e.properties.size):[1,1,1];return{depth:t[2]||1,properties:{...e.properties,size:[t[0]??1,t[1]??1,1]}}}convertExtrude(e){return this.withShapeOptions(e.properties,()=>{if(e.along)return this.convertExtrudeAlong(e,e.along);let{depth:t,properties:n}=this.extrudeProperties(e);return e.path?this.withPathDetail(()=>{let r=e.path,i=this.collectPathPoints(r),a=this.shapeFromPathPoints(i),o=Math.max(1,Math.floor(this.detailLevel/4));this.chargePathEstimate(a,o,yh);let s=mh(i)?new qa(this.requireEnclosedArea(a,`extrude`),{depth:t,bevelEnabled:!1,curveSegments:o}).translate(0,0,-t/2):ul(this.finitePoints(a.getPoints(o)),t);return this.finishMesh(this.placePath(s,r),{properties:n})}):this.buildFromChildren({children:e.children??[],properties:n},(e,n)=>{let r=e.flatMap(e=>this.planarShapes(e));if(!r.length&&!n.length)throw Error(`Extrude requires a path or planar shape`);for(let e of r)this.chargePathEstimate(e,1,12);let i=r.length?[new qa(r,{depth:t,bevelEnabled:!1,curveSegments:1}).translate(0,0,-t/2)]:[],a=n.map(e=>ul(hh(e),t)),o=[...i,...a];for(let e of o)this.chargeEstimate(e.getAttribute(`position`).count);let s=o.length===1?o[0]:Ph(o);return o.length>1&&o.forEach(e=>e.dispose()),s})})}finitePoints(e){let t=e=>Number.isFinite(e)&&Math.abs(e)<=dh;if(!e.every(e=>t(e.x)&&t(e.y)))throw Error("`path` needs finite path coordinates — these overflow");return e.map(e=>new J(e.x,e.y,0))}convertExtrudeAlong(e,t){return this.buildFromChildren({children:e.children??[],properties:e.properties},e=>{let n=e.map(e=>this.sectionOf(e));if(!n.length)throw Error("`extrude … along` needs a planar section to sweep");let{points:r,closed:i}=this.sweepPathOf(t);this.chargeEstimate(n.reduce((e,t)=>e+t.length*r.length,0));let a=n.map(e=>al(ol(e,r,i),i)),o=a.length===1?a[0]:Ph(a);return a.length>1&&a.forEach(e=>e.dispose()),o})}sectionOf(e){let t=tl(e);if(t.some(e=>Math.abs(e.z)>1e-5))throw Error("`extrude … along` sections must lie in the XY plane");return Wa.isClockWise(t.map(e=>new q(e.x,e.y)))?t.reverse():t}sweepPathOf(e){let t=new An,n=this.vertexCount;try{let{meshes:n,lines:r}=this.buildOperands(t,[e]);if(n.length+r.length!==1)throw Error("`along` needs exactly one path");let i=r[0],a=i?hh(i):tl(n[0]);if(a.length<2)throw Error("`along` needs a path with at least two points");return{points:a,closed:i===void 0}}finally{oh(t),this.vertexCount=n}}buildPath(e){return this.shapeFromPathPoints(this.collectPathPoints(e))}placePath(e,t){let n=t.properties;if(!n)return e;let r=new Y;return this.applyPlacement(r,n),e.applyMatrix4(r)}collectPathPoints(e){let t=new Y,n=[],r=!1,i=e=>{if(e.z!==void 0&&Math.abs(this.evaluateNumber(e.z))>uh)throw Error("Paths here are planar — a `point` / `curve` may not have a nonzero third coordinate");this.placePathPoint(t,n,this.evaluateNumber(e.x),this.evaluateNumber(e.y),e.type===`curve`&&!r)},a=e=>{if(t.multiply(e),!t.elements.every(Number.isFinite))throw Error("Path transform overflowed to a non-finite value — `translate`, `rotate` and `scale` accumulate inside a path")},o=e=>{if(++this.pathCommandCount>this.maxLoopIterations)throw new xh(`ShapeScript path exceeds ${this.maxLoopIterations} commands`);switch(e.type){case`define`:this.handleDefine(e);break;case`detail`:{let t=this.evaluateNumber(e.value);r=t<1,this.handleDetail({type:`detail`,value:{type:`number`,value:t}});break}case`point`:case`curve`:i(e);break;case`arc`:this.placeArc(t,n,e);break;case`rotate`:a(new Y().makeRotationZ(-this.evaluateNumber(e.angle)*Math.PI));break;case`translate`:a(new Y().makeTranslation(this.evaluateNumber(e.x),this.evaluateNumber(e.y),0));break;case`scale`:{let t=this.evaluateNumber(e.x);a(new Y().makeScale(t,e.y===void 0?t:this.evaluateNumber(e.y),1));break}case`for`:this.runPathLoop(e,o);break;case`color`:this.evaluateRGBA(e.value)}};for(let t of e.commands)o(t);return n}placePathPoint(e,t,n,r,i){let a=new J(n,r,0).applyMatrix4(e);if(!Number.isFinite(a.x)||!Number.isFinite(a.y))throw Error(`Path coordinates overflowed to a non-finite value`);t.push({x:a.x,y:a.y,curved:i})}placeArc(e,t,n){let r=n.angle===void 0?1:this.evaluateNumber(n.angle),i=Math.min(2,Math.abs(r));if(i===0)throw Error("`arc` needs a nonzero angle");let a=Math.max(i<.5?1:i<1?2:3,Math.ceil(i/2*this.detailLevel)),o=(n.size===void 0?1:this.evaluateSize(n.size)[0])/2,s=new Y;this.applyPlacement(s,{...n.position?{position:n.position}:{},...n.orientation?{orientation:n.orientation}:{}});let c=e.clone().multiply(s),l=Math.sign(r);for(let e=0;e<=a;e++){let n=l*i*e/a*Math.PI;this.placePathPoint(c,t,Math.sin(n)*o,Math.cos(n)*o,!1)}}runPathLoop(e,t){this.symbols.pushScope();try{for(let n of this.iterations(e.iterable)){this.symbols.set(e.variable,n);for(let n of e.commands)t(n)}}finally{this.symbols.popScope()}}shapeFromPathPoints(e){let t=new ua,n=e[0];if(n===void 0)return t;let r=mh(e),i=r?e.slice(0,-1):e,a=e=>i[(e+i.length)%i.length],o=r&&n.curved?((e,t)=>e.curved?ph(e,t):e)(a(-1),n):n;t.moveTo(o.x,o.y);let s=!1;for(let e=+!r;e<i.length;e++){let n=a(e),o=r||e<i.length-1?a(e+1):void 0;if(!n.curved||o===void 0){s||t.lineTo(n.x,n.y),s=!1;continue}let c=o.curved?ph(n,o):o;t.quadraticCurveTo(n.x,n.y,c.x,c.y),s=!o.curved}return r&&!s&&!fh(a(-1),o)&&t.lineTo(o.x,o.y),t}convertLathe(e){return this.inFrame(()=>this.buildLathe(e))}requireLatheProfile(e){if(!e.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)))throw Error("`lathe` profile has non-finite coordinates — a curve control point or a path command overflowed");let t=Math.max(...e.map(e=>Math.abs(e.x))),n=Math.max(...e.map(e=>e.y))-Math.min(...e.map(e=>e.y));if(t<bh||n<bh)throw Error("`lathe` needs a profile with both radius and height — one on the axis of rotation sweeps nothing")}buildLathe(e){let t=null;for(let n of e.children)if(n.type===`path`){if(t)throw Error("`lathe` takes one profile path");t=n}else{let e=this.convertNode(n);if(e)throw oh(e),Error("`lathe` takes a path, not a shape — give it `path { … }`")}if(!t)throw Error(`Lathe requires a path child`);if(t.properties)throw Error("`lathe` does not support position/orientation/size on its profile path — place the lathe itself instead");return this.withShapeOptions(e.properties,()=>{let n=this.buildPath(t);this.chargePathEstimate(n,this.detailLevel,this.detailLevel+1);let r=n.getPoints(this.detailLevel);if(r.length<2)throw Error(`Lathe path must have at least 2 points`);if(this.requireLatheProfile(r),r.every(e=>e.x<=uh))for(let e of r)e.x=-e.x;this.chargeEstimate(r.length*(this.detailLevel+1));let i=Eh(new Xa(r,this.detailLevel));return this.finishMesh(i,e,!0,this.currentTransform().material)})}buildOperands(e,t){let n=this.currentTransform().material;this.operandDepth++;try{this.captureValues(null,()=>this.inScope(e,()=>{this.currentTransform().matrix.identity(),this.addChildren(e,t),n=Sh(this.currentTransform().material)}))}finally{this.operandDepth--}e.updateMatrixWorld(!0);let r=[],i=[];return e.traverse(e=>{e.isMesh?r.push(e):e.isLine&&i.push(e)}),{meshes:r,lines:i,material:n}}buildFromChildren(e,t){let n=new An,r=this.vertexCount,i,a;try{let r=this.buildOperands(n,e.children);a=r.material,i=t(r.meshes,r.lines)}finally{oh(n),this.vertexCount=r}return this.finishMesh(i,e,!0,a)}convertLoft(e){return this.withShapeOptions(e.properties,()=>this.buildLoft(e))}buildLoft(e){return this.buildFromChildren(e,e=>{let t=e.map(tl),n=t.length*Math.max(0,...t.map(e=>e.length));return this.chargeEstimate(n),al(t)})}planarShapes(e){let t=el(e);if(t.some(e=>e.some(e=>Math.abs(e.z)>1e-5)))throw Error(`Fill/extrude profiles must lie in the XY plane`);return xl(t.map(e=>e.map(e=>new q(e.x,e.y))))}convertText(e){return this.withShapeOptions(e.properties,()=>{e.font!==void 0&&this.warn("`font` is not rendered by this viewer and was skipped");let t=El(this.textOf(e),{...e.wrapWidth===void 0?{}:{wrapWidth:this.textWrapWidth(e.wrapWidth)},lineSpacing:e.lineSpacing===void 0?0:this.evaluateNumber(e.lineSpacing),curveSegments:Math.max(1,Math.floor(this.detailLevel/_h))});t.missing.length&&this.warn(`The built-in font has no glyph for ${[...new Set(t.missing)].map(e=>`"${e}"`).join(` `)} — drawn as "?"`);let n=t.rings.reduce((e,t)=>e+t.length,0);return t.shapes.length===0?null:this.operandDepth>0||this.valueSink!==null?(this.chargeEstimate(n),this.finishMesh(new Qa(t.shapes,1),e,!0)):this.textOutline(e,t,n)})}textWrapWidth(e){let t=this.evaluateNumber(e);if(!(t>0))throw Error("`wrapwidth` must be a positive number");return t}textOf(e){let t=e.lines.map(e=>{let t=this.evaluator.evaluate(e);return Dl(Array.isArray(t)?t:[t],e=>Fh(e))}).join(`
24
- `);if(t.length>2e3)throw Error(`\`text\` is limited to ${hl} characters`);return t}textOutline(e,t,n){this.chargeEstimate(n*2);let r=new Float32Array(n*6),i=0;for(let e of t.rings)e.forEach((t,n)=>{let a=e[(n+1)%e.length];r.set([t.x,t.y,0,a.x,a.y,0],i),i+=6});this.vertexCount+=n*2;let a=new Mr().setAttribute(`position`,new X(r,3)),o=this.materialFor(e.properties,this.currentTransform().material),s=Math.min(1,Math.max(0,o.alpha*o.opacity)),c=new Ti(a,new pi({color:o.color?.clone()??new Ln(.8,.8,.8),opacity:s,transparent:s<1}));return this.applyExplicitTransforms(c,e.properties,!0),this.applyCurrentTransform(c),c}convertFill(e){return this.inFrame(()=>{let t=e.children.length===1?e.children.find(e=>e.type===`path`):void 0;if(!t)return this.buildFromChildren(e,e=>{let t=e.flatMap(e=>this.planarShapes(e));if(!t.length)throw Error(`Fill requires a path or planar shape`);for(let e of t)this.chargePathEstimate(e,1,3);return new Qa(t,1)});let n=this.buildPath(t);this.chargePathEstimate(n,vh),this.requireEnclosedArea(n,`fill`);let r=this.placePath(new Qa(n),t);return this.finishMesh(r,e)})}convertMinkowski(e){return this.buildFromChildren(e,e=>{if(e.length<2)throw Error("`minkowski` needs at least two shapes");let[t,...n]=e,r=t.geometry.clone().applyMatrix4(t.matrixWorld),i=new Y;try{for(let e of n){this.chargeEstimate(r.getAttribute(`position`).count*e.geometry.getAttribute(`position`).count);let t=sc({geometry:r,matrix:i},{geometry:e.geometry,matrix:e.matrixWorld});r.dispose(),r=t}}catch(e){throw r.dispose(),e}this.chargeEstimate(r.getAttribute(`position`).count);let a=Nh(t);return a&&r.setAttribute(`color`,new X(new Float32Array(r.getAttribute(`position`).count*3).map((e,t)=>a[t%3]),3)),r})}convertHull(e){return this.buildFromChildren(e,e=>{let t=[];for(let n of e){let e=n.geometry.getAttribute(`position`);for(let r=0;r<e.count;r++)t.push(new J().fromBufferAttribute(e,r).applyMatrix4(n.matrixWorld))}if(t.length<4)throw Error(`Hull requires at least four non-coplanar points`);this.chargeEstimate(t.length*6);let n=new Gs(t);if(!n.getAttribute(`position`).count)throw n.dispose(),Error(`Hull points must enclose a volume`);return n.setAttribute(`uv`,new X(new Float32Array(n.getAttribute(`position`).count*2),2)),n})}evaluateNumber(e){if(e===void 0)return 0;if(typeof e==`number`)return e;let t=this.evaluator.evaluateToNumber(e);if(!Number.isFinite(t))throw Error(`Expected a finite number`);return t}evaluateVector3(e){if(e===void 0)return[0,0,0];if(Array.isArray(e)&&typeof e[0]==`number`)return e;let t=this.evaluateTranslateVector(e);if(!t.every(Number.isFinite))throw Error(`Expected finite vector components`);return t}evaluateSize(e){if(e===void 0)return[1,1,1];let t=Array.isArray(e)&&typeof e[0]==`number`?e:this.evaluator.evaluate(e),[n=1,r=n,i=n]=(Array.isArray(t)?t:[t]).map(e=>{if(typeof e!=`number`||!Number.isFinite(e))throw Error(`Expected finite size components`);return e});return[n,r,i]}evaluateRGBA(e){return this.requireFiniteColor(this.evaluator.evaluateToRGBA(e))}evaluateTranslateVector(e){let t=this.evaluator.evaluate(e);return typeof t==`number`?[t,0,0]:Array.isArray(t)?[t.length>0&&typeof t[0]==`number`?t[0]:0,t.length>1&&typeof t[1]==`number`?t[1]:0,t.length>2&&typeof t[2]==`number`?t[2]:0]:[0,0,0]}requireFiniteColor(e){if(!e.every(Number.isFinite))throw Error(`Expected finite color channels`);return e}},kh={position:!0,orientation:!0,rotation:!0,size:!0,color:!0,opacity:!0,material:!0,metallicity:!0,roughness:!0,glow:!0,texture:!0,detail:!0,smoothing:!0};function Ah(e){let t=[];for(let n of e)Array.isArray(n)?t.push(...Ah(n)):jh(n)&&t.push(n);return t}function jh(e){return _c(e)&&(e.kind===`mesh`||e.kind===`polygon`)}function Mh(e){let t=e.geometry.clone(),n=Nh(e);if(n&&!t.hasAttribute(`color`)){let e=t.getAttribute(`position`).count;t.setAttribute(`color`,new X(new Float32Array(e*3).map((e,t)=>n[t%3]),3))}return t}function Nh(e){let t=Array.isArray(e.material)?e.material[0]:e.material,n=e.geometry.getAttribute(`color`);if(n&&n.count>0){let e=[n.getX(0),n.getY(0),n.getZ(0)];for(let t=1;t<n.count;t++)if(Math.abs(n.getX(t)-e[0])>1e-6||Math.abs(n.getY(t)-e[1])>1e-6||Math.abs(n.getZ(t)-e[2])>1e-6)return;return e}if(t?.userData?.colored&&t.color)return[t.color.r,t.color.g,t.color.b]}function Ph(e){let t=e.some(e=>e.hasAttribute(`color`)),n=e.map(e=>{let n=e.index?e.toNonIndexed():e.clone();n.hasAttribute(`normal`)||n.computeVertexNormals();let r=n.getAttribute(`position`).count;n.hasAttribute(`uv`)||n.setAttribute(`uv`,new X(new Float32Array(r*2),2)),t&&!n.hasAttribute(`color`)&&n.setAttribute(`color`,new X(new Float32Array(r*3).fill(.8),3));for(let e of Object.keys(n.attributes))[`position`,`normal`,`uv`,`color`].includes(e)||n.deleteAttribute(e);return n.clearGroups(),n}),r=n.length===1?n[0]:Ks(n);if(!r)throw Error(`Could not combine the shapes into one mesh`);return n.length>1&&n.forEach(e=>e.dispose()),r}function Fh(e){return Array.isArray(e)?e.map(e=>Array.isArray(e)?`(${Fh(e)})`:Fh(e)).join(` `):typeof e==`object`?e.kind===`range`?`${e.from} to ${e.to} step ${e.step}`:`<${e.kind}>`:String(e)}function Ih(e,t={}){return new Oh(t).convert(e)}Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"$t",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return ki}}),Object.defineProperty(exports,"An",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"At",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"Bn",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"Bt",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return en}}),Object.defineProperty(exports,"Cn",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"Ct",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return Di}}),Object.defineProperty(exports,"Dn",{enumerable:!0,get:function(){return Mn}}),Object.defineProperty(exports,"Dt",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"En",{enumerable:!0,get:function(){return $t}}),Object.defineProperty(exports,"Et",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return bs}}),Object.defineProperty(exports,"Fn",{enumerable:!0,get:function(){return ro}}),Object.defineProperty(exports,"Ft",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"Gt",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"Hn",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"Ht",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return An}}),Object.defineProperty(exports,"In",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"It",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"Jt",{enumerable:!0,get:function(){return Hr}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return jt}}),Object.defineProperty(exports,"Kt",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"Ln",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"Lt",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"Mn",{enumerable:!0,get:function(){return Cs}}),Object.defineProperty(exports,"Mt",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return fi}}),Object.defineProperty(exports,"Nn",{enumerable:!0,get:function(){return oo}}),Object.defineProperty(exports,"Nt",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Go}}),Object.defineProperty(exports,"On",{enumerable:!0,get:function(){return no}}),Object.defineProperty(exports,"Ot",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(exports,"Pn",{enumerable:!0,get:function(){return et}}),Object.defineProperty(exports,"Pt",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return ho}}),Object.defineProperty(exports,"Qt",{enumerable:!0,get:function(){return it}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"Rn",{enumerable:!0,get:function(){return nt}}),Object.defineProperty(exports,"Rt",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return tn}}),Object.defineProperty(exports,"Sn",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"St",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"Tn",{enumerable:!0,get:function(){return Je}}),Object.defineProperty(exports,"Tt",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return He}}),Object.defineProperty(exports,"Un",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"Ut",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"Vn",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"Vt",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return Ue}}),Object.defineProperty(exports,"Wt",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return Ur}}),Object.defineProperty(exports,"Xt",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return ti}}),Object.defineProperty(exports,"Yt",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return mo}}),Object.defineProperty(exports,"Zt",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Bt}}),Object.defineProperty(exports,"_n",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"_t",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return oh}}),Object.defineProperty(exports,"an",{enumerable:!0,get:function(){return zn}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return ci}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return Oi}}),Object.defineProperty(exports,"bn",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"bt",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"cn",{enumerable:!0,get:function(){return ls}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return Mt}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Ai}}),Object.defineProperty(exports,"dn",{enumerable:!0,get:function(){return yr}}),Object.defineProperty(exports,"dt",{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,"en",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return vr}}),Object.defineProperty(exports,"fn",{enumerable:!0,get:function(){return br}}),Object.defineProperty(exports,"ft",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Ln}}),Object.defineProperty(exports,"gn",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"gt",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"hn",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"ht",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return lh}}),Object.defineProperty(exports,"in",{enumerable:!0,get:function(){return We}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return Ho}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"jn",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"jt",{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return at}}),Object.defineProperty(exports,"kn",{enumerable:!0,get:function(){return Qe}}),Object.defineProperty(exports,"kt",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Ko}}),Object.defineProperty(exports,"ln",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"mn",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"mt",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return xh}}),Object.defineProperty(exports,"nn",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return ch}}),Object.defineProperty(exports,"on",{enumerable:!0,get:function(){return uo}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return Za}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Mr}}),Object.defineProperty(exports,"pn",{enumerable:!0,get:function(){return so}}),Object.defineProperty(exports,"pt",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return Ft}}),Object.defineProperty(exports,"qt",{enumerable:!0,get:function(){return fo}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Ih}}),Object.defineProperty(exports,"rn",{enumerable:!0,get:function(){return Ve}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return Uo}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return $c}}),Object.defineProperty(exports,"sn",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return cs}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return gh}}),Object.defineProperty(exports,"tn",{enumerable:!0,get:function(){return Ae}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Xo}}),Object.defineProperty(exports,"un",{enumerable:!0,get:function(){return Xt}}),Object.defineProperty(exports,"ut",{enumerable:!0,get:function(){return lt}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Ss}}),Object.defineProperty(exports,"vn",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"vt",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return ii}}),Object.defineProperty(exports,"wn",{enumerable:!0,get:function(){return Zt}}),Object.defineProperty(exports,"wt",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return Ei}}),Object.defineProperty(exports,"xn",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"xt",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Yo}}),Object.defineProperty(exports,"yn",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"yt",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return pn}}),Object.defineProperty(exports,"zn",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"zt",{enumerable:!0,get:function(){return Oe}});
23
+ `).flatMap(e=>t.wrapWidth===void 0?[e]:wl(e,t.wrapWidth)).forEach((e,i)=>{let a=-i*(pl+t.lineSpacing),o=0;for(let i of e){let e=Sl(i);e||=(r.missing.push(i),Sl(ml));let s=e===Sl(i)?i:ml,c=n.get(s)??_l(e,t.curveSegments);n.set(s,c);let l=c.map(e=>Tl(e,o,a));r.rings.push(...l),r.shapes.push(...xl(l)),o+=e.ha*fl}}),r}function Dl(e,t){let n=``,r=!1;for(let i of e)typeof i==`string`?(n+=i,r=!1):(r&&(n+=` `),n+=t(i),r=!0);return n}var Ol=1.25,kl=65535,Al=2**-24,jl=Symbol(`SKIP_GENERATION`),Ml={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[jl]:!1};function Nl(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 Pl(e){let t=-1,n=-1/0;for(let r=0;r<3;r++){let i=e[r+3]-e[r];i>n&&(n=i,t=r)}return t}function Fl(e,t){t.set(e)}function Il(e,t,n){let r,i;for(let a=0;a<3;a++){let o=a+3;r=e[a],i=t[a],n[a]=r<i?r:i,r=e[o],i=t[o],n[o]=r>i?r:i}}function Ll(e,t,n){for(let r=0;r<3;r++){let i=t[e+2*r],a=t[e+2*r+1],o=i-a,s=i+a;o<n[r]&&(n[r]=o),s>n[r+3]&&(n[r+3]=s)}}function Rl(e){let t=e[3]-e[0],n=e[4]-e[1],r=e[5]-e[2];return 2*(t*n+n*r+r*t)}function zl(e,t){return t[e+15]===kl}function Bl(e,t){return t[e+6]}function Vl(e,t){return t[e+14]}function Hl(e){return e+8}function Ul(e,t){return e+t[e+6]*8}function Wl(e,t){return t[e+7]}function Gl(e){return e}function Kl(e,t,n,r,i){let a=1/0,o=1/0,s=1/0,c=-1/0,l=-1/0,u=-1/0,d=1/0,f=1/0,p=1/0,m=-1/0,h=-1/0,g=-1/0,_=e.offset||0;for(let r=(t-_)*6,i=(t+n-_)*6;r<i;r+=6){let t=e[r+0],n=e[r+1],i=t-n,_=t+n;i<a&&(a=i),_>c&&(c=_),t<d&&(d=t),t>m&&(m=t);let v=e[r+2],y=e[r+3],b=v-y,x=v+y;b<o&&(o=b),x>l&&(l=x),v<f&&(f=v),v>h&&(h=v);let S=e[r+4],C=e[r+5],w=S-C,T=S+C;w<s&&(s=w),T>u&&(u=T),S<p&&(p=S),S>g&&(g=S)}r[0]=a,r[1]=o,r[2]=s,r[3]=c,r[4]=l,r[5]=u,i[0]=d,i[1]=f,i[2]=p,i[3]=m,i[4]=h,i[5]=g}var ql=32,Jl=(e,t)=>e.candidate-t.candidate,Yl=Array(ql).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Xl=new Float32Array(6);function Zl(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=Pl(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=Pl(e),o!==-1&&(s=Ql(n,r,i,o));else if(a===2){let a=Rl(e),c=Ol*i,l=n.offset||0,u=(r-l)*6,d=(r+i-l)*6;for(let e=0;e<3;e++){let r=t[e],l=(t[e+3]-r)/ql;if(i<ql/4){let t=[...Yl];t.length=i;let r=0;for(let i=u;i<d;i+=6,r++){let a=t[r];a.candidate=n[i+2*e],a.count=0;let{bounds:o,leftCacheBounds:s,rightCacheBounds:c}=a;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,o[e]=1/0,o[e+3]=-1/0;Ll(i,n,o)}t.sort(Jl);let l=i;for(let e=0;e<l;e++){let n=t[e];for(;e+1<l&&t[e+1].candidate===n.candidate;)t.splice(e+1,1),l--}for(let r=u;r<d;r+=6){let i=n[r+2*e];for(let e=0;e<l;e++){let a=t[e];i>=a.candidate?Ll(r,n,a.rightCacheBounds):(Ll(r,n,a.leftCacheBounds),a.count++)}}for(let n=0;n<l;n++){let r=t[n],l=r.count,u=i-r.count,d=r.leftCacheBounds,f=r.rightCacheBounds,p=0;l!==0&&(p=Rl(d)/a);let m=0;u!==0&&(m=Rl(f)/a);let h=1+Ol*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<ql;e++){let t=Yl[e];t.count=0,t.candidate=r+l+e*l;let n=t.bounds;for(let e=0;e<3;e++)n[e]=1/0,n[e+3]=-1/0}for(let t=u;t<d;t+=6){let i=~~((n[t+2*e]-r)/l);i>=ql&&(i=31);let a=Yl[i];a.count++,Ll(t,n,a.bounds)}let t=Yl[31];Fl(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){let t=Yl[e],n=Yl[e+1];Il(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<31;t++){let n=Yl[t],r=n.count,l=n.bounds,u=Yl[t+1].rightCacheBounds;r!==0&&(f===0?Fl(l,Xl):Il(l,Xl,Xl)),f+=r;let d=0,p=0;f!==0&&(d=Rl(Xl)/a);let m=i-f;m!==0&&(p=Rl(u)/a);let h=1+Ol*(d*f+p*m);h<c&&(o=e,c=h,s=n.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${a} used.`);return{axis:o,pos:s}}function Ql(e,t,n,r){let i=0,a=e.offset;for(let o=t,s=t+n;o<s;o++)i+=e[(o-a)*6+r*2];return i/n}var $l=class{constructor(){this.boundingData=new Float32Array(6)}};function eu(e,t,n,r,i,a){let o=r,s=r+i-1,c=a.pos,l=a.axis*2,u=n.offset||0;for(;;){for(;o<=s&&n[(o-u)*6+l]<c;)o++;for(;o<=s&&n[(s-u)*6+l]>=c;)s--;if(o<s){for(let n=0;n<t;n++){let r=e[o*t+n];e[o*t+n]=e[s*t+n],e[s*t+n]=r}for(let e=0;e<6;e++){let t=o-u,r=s-u,i=n[t*6+e];n[t*6+e]=n[r*6+e],n[r*6+e]=i}o++,s--}else return o}}var tu,nu,ru,iu,au=2**32;function ou(e){return`count`in e?1:1+ou(e.left)+ou(e.right)}function su(e,t,n){return tu=new Float32Array(n),nu=new Uint32Array(n),ru=new Uint16Array(n),iu=new Uint8Array(n),cu(e,t)}function cu(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)tu[n+e]=a[e];if(i)return t.buffer?(iu.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(nu[n+6]=t.offset,ru[r+14]=t.count,ru[r+15]=kl,e+32);{let{left:r,right:i,splitAxis:a}=t,o=cu(e+32,r),s=e/32,c=o/32-s;if(c>au)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return nu[n+6]=c,nu[n+7]=a,cu(o,i)}}function lu(e,t,n,r,i,a){let{maxDepth:o,verbose:s,targetLeafSize:c,_strictLeafSize:l=1/0,strategy:u,onProgress:d}=i,f=e.primitiveBuffer,p=e.primitiveBufferStride,m=new Float32Array(6),h=!1,g=new $l;return Kl(t,n,r,g.boundingData,m),v(g,n,r,m),g;function _(e){d&&d((e-a.offset)/a.count)}function v(e,n,r,i=null,a=0){!h&&a>=o&&(h=!0,s&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));let d=r>l;if(r<=c&&!d||a>=o)return _(n+r),e.offset=n,e.count=r,e;let g=Zl(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:eu(f,p,t,n,r,g);if(g.axis===-1||y===n||y===n+r){if(!d)return _(n+r),e.offset=n,e.count=r,e;g.axis=Math.max(0,Pl(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new $l,x=n,S=y-n;e.left=b,Kl(t,x,S,b.boundingData,m),v(b,x,S,m,a+1);let C=new $l,w=y,T=r-S;return e.right=C,Kl(t,w,T,C.boundingData,m),v(C,w,T,m,a+1),e}}function uu(e,t){let n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=e.getRootRanges(t.range),i=r[0],a=r[r.length-1],o={offset:i.offset,count:a.offset+a.count-i.offset},s=new Float32Array(6*o.count);s.offset=o.offset,e.computePrimitiveBounds(o.offset,o.count,s),e._roots=r.map(r=>{let i=lu(e,s,r.offset,r.count,t,o),a=ou(i),c=new n(32*a);return su(0,i,c),c})}var du=class{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){let e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}},$=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let e=[],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,e.length!==0&&this.setBuffer(e.pop())}}},fu,pu,mu=[],hu=new du(()=>new er);function gu(e,t,n,r,i,a){fu=hu.getPrimitive(),pu=hu.getPrimitive(),mu.push(fu,pu),$.setBuffer(e._roots[t]);let o=_u(0,e.geometry,n,r,i,a);$.clearBuffer(),hu.releasePrimitive(fu),hu.releasePrimitive(pu),mu.pop(),mu.pop();let s=mu.length;return s>0&&(pu=mu[s-1],fu=mu[s-2]),o}function _u(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=$,u=e*2;if(zl(u,c)){let t=Bl(e,l),n=Vl(u,c);return Nl(Gl(e),s,fu),r(t,n,!1,o,a+e/8,fu)}{let u=Hl(e),p=Ul(e,l),m=u,h=p,g,_,v,y;if(i&&(v=fu,y=pu,Nl(Gl(m),s,v),Nl(Gl(h),s,y),g=i(v),_=i(y),_<g)){m=p,h=u;let e=g;g=_,_=e,v=y}v||(v=fu,Nl(Gl(m),s,v));let b=zl(m*2,c),x=n(v,b,g,o+1,a+m/8),S;if(x===2){let e=d(m);S=r(e,f(m)-e,!0,o+1,a+m/8,v)}else S=x&&_u(m,t,n,r,i,a,o+1);if(S)return!0;y=pu,Nl(Gl(h),s,y);let C=zl(h*2,c),w=n(y,C,_,o+1,a+h/8),T;if(w===2){let e=d(h);T=r(e,f(h)-e,!0,o+1,a+h/8,y)}else T=w&&_u(h,t,n,r,i,a,o+1);if(T)return!0;return!1;function d(e){let{uint16Array:t,uint32Array:n}=$,r=e*2;for(;!zl(r,t);)e=Hl(e),r=e*2;return Bl(e,n)}function f(e){let{uint16Array:t,uint32Array:n}=$,r=e*2;for(;!zl(r,t);)e=Ul(e,n),r=e*2;return Bl(e,n)+Vl(r,t)}}}var vu=new $.constructor,yu=new $.constructor,bu=new du(()=>new er),xu=new er,Su=new er,Cu=new er,wu=new er,Tu=!1;function Eu(e,t,n,r){if(Tu)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);Tu=!0;let i=e._roots,a=t._roots,o,s=0,c=0,l=new Y().copy(n).invert();for(let e=0,t=i.length;e<t;e++){vu.setBuffer(i[e]),c=0;let t=bu.getPrimitive();Nl(Gl(0),vu.float32Array,t),t.applyMatrix4(l);for(let e=0,i=a.length;e<i&&(yu.setBuffer(a[e]),o=Du(0,0,n,l,r,s,c,0,0,t),yu.clearBuffer(),c+=a[e].byteLength/32,!o);e++);if(bu.releasePrimitive(t),vu.clearBuffer(),s+=i[e].byteLength/32,o)break}return Tu=!1,o}function Du(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=yu,f=vu):(d=vu,f=yu);let p=d.float32Array,m=d.uint32Array,h=d.uint16Array,g=f.float32Array,_=f.uint32Array,v=f.uint16Array,y=e*2,b=t*2,x=zl(y,h),S=zl(b,v),C=!1;if(S&&x)C=u?i(Bl(t,_),Vl(t*2,v),Bl(e,m),Vl(e*2,h),c,o+t/8,s,a+e/8):i(Bl(e,m),Vl(e*2,h),Bl(t,_),Vl(t*2,v),s,a+e/8,c,o+t/8);else if(S){let l=bu.getPrimitive();Nl(Gl(t),g,l),l.applyMatrix4(n);let d=Hl(e),f=Ul(e,m);Nl(Gl(d),p,xu),Nl(Gl(f),p,Su);let h=l.intersectsBox(xu),_=l.intersectsBox(Su);C=h&&Du(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&Du(t,f,r,n,i,o,a,c,s+1,l,!u),bu.releasePrimitive(l)}else{let d=Hl(t),f=Ul(t,_);Nl(Gl(d),g,Cu),Nl(Gl(f),g,wu);let h=l.intersectsBox(Cu),v=l.intersectsBox(wu);if(h&&v)C=Du(e,d,n,r,i,a,o,s,c+1,l,u)||Du(e,f,n,r,i,a,o,s,c+1,l,u);else if(h){if(x)C=Du(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=bu.getPrimitive();t.copy(Cu).applyMatrix4(n);let l=Hl(e),f=Ul(e,m);Nl(Gl(l),p,xu),Nl(Gl(f),p,Su);let h=t.intersectsBox(xu),g=t.intersectsBox(Su);C=h&&Du(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&Du(d,f,r,n,i,o,a,c,s+1,t,!u),bu.releasePrimitive(t)}}else if(v){if(x)C=Du(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=bu.getPrimitive();t.copy(wu).applyMatrix4(n);let l=Hl(e),d=Ul(e,m);Nl(Gl(l),p,xu),Nl(Gl(d),p,Su);let h=t.intersectsBox(xu),g=t.intersectsBox(Su);C=h&&Du(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&Du(f,d,r,n,i,o,a,c,s+1,t,!u),bu.releasePrimitive(t)}}}return C}var Ou=new class{constructor(){let e=null,t=null,n=null,r=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(i,a)=>{if(r)throw Error(`BVHTraversalHelper: cannot call setBVH during an active traversal.`);this.root=a,this.buffer=e=i._roots[a],this.uint16Array=n=new Uint16Array(e),this.uint32Array=t=new Uint32Array(e)},this.reset=()=>{this.root=null,this.buffer=e=null,this.uint16Array=n=null,this.uint32Array=t=null},this.getRangeStart=e=>{let r=e*2;for(;!zl(r,n);)e=Hl(e),r=e*2;return Bl(e,t)},this.getRangeEnd=e=>{let r=e*2;for(;!zl(r,n);)e=Ul(e,t),r=e*2;return Bl(e,t)+Vl(r,n)};let i=(e,r,a)=>{let o=zl(r*2,n);if(!e(a,o,r)&&!o){let n=Hl(r),o=Ul(r,t);i(e,n,a+1),i(e,o,a+1)}};this.traverseBuffer=e=>{if(r)throw Error(`BVHTraversalHelper: cannot start a traversal during an active traversal.`);r=!0;try{i(e,0,0)}finally{r=!1}},this.traverse=r=>{this.traverseBuffer((i,a,o)=>{if(a){let s=o*2,c=t[o+6],l=n[s+14];return r(i,a,new Float32Array(e,o*4,6),c,l)}{let n=Wl(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},ku=new er,Au=new Float32Array(6),ju=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Ml,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),uu(this,e)}getRootRanges(){throw Error(`BVH: getRootRanges() not implemented`)}writePrimitiveBounds(){throw Error(`BVH: writePrimitiveBounds() not implemented`)}writePrimitiveRangeBounds(e,t,n,r){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let n=e,r=e+t;n<r;n++){this.writePrimitiveBounds(n,Au,0);let[e,t,r,u,d,f]=Au;e<i&&(i=e),u>s&&(s=u),t<a&&(a=t),d>c&&(c=d),r<o&&(o=r),f>l&&(l=f)}return n[r+0]=i,n[r+1]=a,n[r+2]=o,n[r+3]=s,n[r+4]=c,n[r+5]=l,n}computePrimitiveBounds(e,t,n){let r=n.offset||0;for(let i=e,a=e+t;i<a;i++){this.writePrimitiveBounds(i,Au,0);let[e,t,a,o,s,c]=Au,l=(e+o)/2,u=(t+s)/2,d=(a+c)/2,f=(o-e)/2,p=(s-t)/2,m=(c-a)/2,h=(i-r)*6;n[h+0]=l,n[h+1]=f+(Math.abs(l)+f)*Al,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*Al,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*Al}return n}shiftPrimitiveOffsets(e){let t=this._indirectBuffer;if(t)for(let n=0,r=t.length;n<r;n++)t[n]+=e;else{let t=this._roots;for(let n=0;n<t.length;n++){let r=t[n],i=new Uint32Array(r),a=new Uint16Array(r),o=r.byteLength/32;for(let t=0;t<o;t++){let n=8*t;zl(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){Ou.setBVH(this,t),Ou.traverse(e),Ou.reset()}refit(){let e=this._roots;for(let t=0,n=e.length;t<n;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n),a=new Float32Array(n),o=n.byteLength/32;for(let e=o-1;e>=0;e--){let t=e*8,n=t*2;if(zl(n,i)){let e=Bl(t,r),o=Vl(n,i);this.writePrimitiveRangeBounds(e,o,Au,0),a.set(Au,t)}else{let e=Hl(t),n=Ul(t,r);for(let r=0;r<3;r++){let i=a[e+r],o=a[e+r+3],s=a[n+r],c=a[n+r+3];a[t+r]=i<s?i:s,a[t+r+3]=o>c?o:c}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Nl(0,new Float32Array(t),ku),e.union(ku)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:r,intersectsPrimitive:i,scratchPrimitive:a,iterate:o}=e;if(r&&i){let e=r;r=(t,n,r,s,c)=>e(t,n,r,s,c)?!0:o(t,n,this,i,r,s,a)}else r||=i?(e,t,n,r)=>o(e,t,this,i,n,r,a):(e,t,n)=>n;let s=!1,c=0,l=this._roots;for(let e=0,i=l.length;e<i;e++){let i=l[e];if(s=gu(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Eu(this,e,t,r)}};function Mu(){return typeof SharedArrayBuffer<`u`}function Nu(e){return e.index?e.index.count:e.attributes.position.count}function Pu(e){return Nu(e)/3}function Fu(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function Iu(e,t){if(!e.index){let n=e.attributes.position.count,r=Fu(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new vr(r,1));for(let e=0;e<n;e++)r[e]=e}}function Lu(e,t,n){let r=Nu(e)/n,i=t||e.drawRange,a=i.start/n,o=(i.start+i.count)/n,s=Math.max(0,a),c=Math.min(r,o)-s;return{offset:Math.floor(s),count:Math.floor(c)}}function Ru(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function zu(e,t,n){let r=Lu(e,t,n),i=Ru(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Nu(e)/n,l=[];for(let e of i){let{offset:t,count:n}=e,r=t,i=t+(isFinite(n)?n:c-t);r<s&&i>o&&(l.push({pos:Math.max(o,r),isStart:!0}),l.push({pos:Math.min(s,i),isStart:!1}))}l.sort((e,t)=>e.pos===t.pos?e.type===`end`?-1:1:e.pos-t.pos);let u=0,d=null;for(let e of l){let t=e.pos;u!==0&&t!==d&&a.push({offset:d,count:t-d}),u+=e.isStart?1:-1,d=t}return a}function Bu(e,t){let n=e[e.length-1],r=n.offset+n.count>2**16,i=e.reduce((e,t)=>e+t.count,0),a=r?4:2,o=t?new SharedArrayBuffer(i*a):new ArrayBuffer(i*a),s=r?new Uint32Array(o):new Uint16Array(o),c=0;for(let t=0;t<e.length;t++){let{offset:n,count:r}=e[t];for(let e=0;e<r;e++)s[c+e]=n+e;c+=r}return s}var Vu=class extends ju{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(!e.isBufferGeometry)throw Error(`BVH: Only BufferGeometries are supported.`);if(e.index&&e.index.isInterleavedBufferAttribute)throw Error(`BVH: InterleavedBufferAttribute is not supported for the index attribute.`);if(t.useSharedArrayBuffer&&!Mu())throw Error(`BVH: SharedArrayBuffer is not available.`);super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?e=>this._indirectBuffer[e]:e=>e,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...Ml,...t},t[jl]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=Bu(zu(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else Iu(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new er))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:zu(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},Hu=class{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,r=-1/0;for(let i=0,a=e.length;i<a;i++){let a=e[i][t];n=a<n?a:n,r=a>r?a:r}this.min=n,this.max=r}setFromPoints(e,t){let n=1/0,r=-1/0;for(let i=0,a=t.length;i<a;i++){let a=t[i],o=e.dot(a);n=o<n?o:n,r=o>r?o:r}this.min=n,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}};Hu.prototype.setFromBox=(function(){let e=new J;return function(t,n){let r=n.min,i=n.max,a=1/0,o=-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);let l=t.dot(e);a=Math.min(l,a),o=Math.max(l,o)}this.min=a,this.max=o}})();var Uu=(function(){let e=new J,t=new J,n=new J;return function(r,i,a){let o=r.start,s=e,c=i.start,l=t;n.subVectors(o,c),e.subVectors(r.end,r.start),t.subVectors(i.end,i.start);let u=n.dot(l),d=l.dot(s),f=l.dot(l),p=n.dot(s),m=s.dot(s)*f-d*d,h,g;h=m===0?0:(u*d-p*f)/m,g=(u+h*d)/f,a.x=h,a.y=g}})(),Wu=(function(){let e=new q,t=new J,n=new J;return function(r,i,a,o){Uu(r,i,e);let s=e.x,c=e.y;if(s>=0&&s<=1&&c>=0&&c<=1){r.at(s,a),i.at(c,o);return}if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}if(c>=0&&c<=1){s<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}{let e;e=s<0?r.start:r.end;let l;l=c<0?i.start:i.end;let u=t,d=n;if(r.closestPointToPoint(l,!0,t),i.closestPointToPoint(e,!0,n),u.distanceToSquared(l)<=d.distanceToSquared(e)){a.copy(u),o.copy(l);return}a.copy(e),o.copy(d);return}}})(),Gu=(function(){let e=new J,t=new J,n=new ci,r=new ys;return function(i,a){let{radius:o,center:s}=i,{a:c,b:l,c:u}=a;if(r.start=c,r.end=l,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o||(r.start=c,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o)||(r.start=l,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o))return!0;let d=a.getPlane(n);if(Math.abs(d.distanceToPoint(s))<=o){let e=d.projectPoint(s,t);if(a.containsPoint(e))return!0}return!1}})(),Ku=[`x`,`y`,`z`],qu=1e-15,Ju=qu*qu;function Yu(e){return Math.abs(e)<qu}var Xu=class extends $n{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new J),this.satBounds=[,,,,].fill().map(()=>new Hu),this.points=[this.a,this.b,this.c],this.plane=new ci,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new ys,this.needsUpdate=!0}intersectsSphere(e){return Gu(e,this)}update(){let e=this.a,t=this.b,n=this.c,r=this.points,i=this.satAxes,a=this.satBounds,o=i[0],s=a[0];this.getNormal(o),s.setFromPoints(o,r);let c=i[1],l=a[1];c.subVectors(e,t),l.setFromPoints(c,r);let u=i[2],d=a[2];u.subVectors(t,n),d.setFromPoints(u,r);let f=i[3],p=a[3];f.subVectors(n,e),p.setFromPoints(f,r);let m=c.length(),h=u.length(),g=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<qu?h<qu||g<qu?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<qu?g<qu?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<qu&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};Xu.prototype.closestPointToSegment=(function(){let e=new J,t=new J,n=new ys;return function(r,i=null,a=null){let{start:o,end:s}=r,c=this.points,l,u=1/0;for(let o=0;o<3;o++){let s=(o+1)%3;n.start.copy(c[o]),n.end.copy(c[s]),Wu(n,r,e,t),l=e.distanceToSquared(t),l<u&&(u=l,i&&i.copy(e),a&&a.copy(t))}return this.closestPointToPoint(o,e),l=o.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(o)),this.closestPointToPoint(s,e),l=s.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(s)),Math.sqrt(u)}})(),Xu.prototype.intersectsTriangle=(function(){let e=new Xu,t=new Hu,n=new Hu,r=new J,i=new J,a=new J,o=new J,s=new ys,c=new ys,l=new J,u=new q,d=new q;function f(e,i,a,s){let c=r;!e.isDegenerateIntoPoint&&!e.isDegenerateIntoSegment?c.copy(e.plane.normal):c.copy(i.plane.normal);let l=e.satBounds,u=e.satAxes;for(let r=1;r<4;r++){let a=l[r],s=u[r];if(t.setFromPoints(s,i.points),a.isSeparated(t)||(o.copy(c).cross(s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}let d=i.satBounds,f=i.satAxes;for(let r=1;r<4;r++){let a=d[r],s=f[r];if(t.setFromPoints(s,e.points),a.isSeparated(t)||(o.crossVectors(c,s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}return a&&(s||console.warn(`ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0.`),a.start.set(0,0,0),a.end.set(0,0,0)),!0}function p(e,t,n,r,i,a,o,s,c,l,u){let d=o/(o-s);l.x=r+(i-r)*d,u.start.subVectors(t,e).multiplyScalar(d).add(e),d=o/(o-c),l.y=r+(a-r)*d,u.end.subVectors(n,e).multiplyScalar(d).add(e)}function m(e,t,n,r,i,a,o,s,c,l,u){if(i>0)p(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else if(a>0)p(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(s*c>0||o!=0)p(e.a,e.b,e.c,t,n,r,o,s,c,l,u);else if(s!=0)p(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(c!=0)p(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else return!0;return!1}function h(e,t,n,i){let a=t.degenerateSegment,o=e.plane.distanceToPoint(a.start),s=e.plane.distanceToPoint(a.end);return Yu(o)?Yu(s)?f(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):Yu(s)?(n&&(n.start.copy(a.end),n.end.copy(a.end)),e.containsPoint(a.end)):e.plane.intersectLine(a,r)!=null&&(n&&(n.start.copy(r),n.end.copy(r)),e.containsPoint(r))}function g(e,t,n){let r=t.a;return Yu(e.plane.distanceToPoint(r))&&e.containsPoint(r)?(n&&(n.start.copy(r),n.end.copy(r)),!0):!1}function _(e,t,n){let i=e.degenerateSegment,a=t.a;return i.closestPointToPoint(a,!0,r),a.distanceToSquared(r)<Ju&&(n&&(n.start.copy(a),n.end.copy(a)),!0)}function v(e,t,n,o){if(e.isDegenerateIntoSegment){if(t.isDegenerateIntoSegment){let o=e.degenerateSegment,s=t.degenerateSegment,c=i,l=a;o.delta(c),s.delta(l);let u=r.subVectors(s.start,o.start),d=c.x*l.y-c.y*l.x;if(Yu(d))return!1;let f=(u.x*l.y-u.y*l.x)/d,p=-(c.x*u.y-c.y*u.x)/d;return f<0||f>1||p<0||p>1?!1:Yu(o.start.z+c.z*f-(s.start.z+l.z*p))?(n&&(n.start.copy(o.start).addScaledVector(c,f),n.end.copy(o.start).addScaledVector(c,f)),!0):!1}return t.isDegenerateIntoPoint?_(e,t,n):h(t,e,n,o)}if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<Ju&&(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):t.isDegenerateIntoSegment?_(t,e,n):g(t,e,n);if(t.isDegenerateIntoPoint)return g(e,t,n);if(t.isDegenerateIntoSegment)return h(e,t,n,o)}return function(t,n=null,r=!1){this.needsUpdate&&this.update(),t.isExtendedTriangle?t.needsUpdate&&t.update():(e.copy(t),e.update(),t=e);let o=v(this,t,n,r);if(o!==void 0)return o;let p=this.plane,h=t.plane,g=h.distanceToPoint(this.a),_=h.distanceToPoint(this.b),y=h.distanceToPoint(this.c);Yu(g)&&(g=0),Yu(_)&&(_=0),Yu(y)&&(y=0);let b=g*_,x=g*y;if(b>0&&x>0)return!1;let S=p.distanceToPoint(t.a),C=p.distanceToPoint(t.b),w=p.distanceToPoint(t.c);Yu(S)&&(S=0),Yu(C)&&(C=0),Yu(w)&&(w=0);let T=S*C,E=S*w;if(T>0&&E>0)return!1;i.copy(p.normal),a.copy(h.normal);let D=i.cross(a),O=0,k=Math.abs(D.x),A=Math.abs(D.y);A>k&&(k=A,O=1),Math.abs(D.z)>k&&(O=2);let j=Ku[O],M=this.a[j],N=this.b[j],ee=this.c[j],P=t.a[j],F=t.b[j],I=t.c[j];if(m(this,M,N,ee,b,x,g,_,y,u,s)||m(t,P,F,I,T,E,S,C,w,d,c))return f(this,t,n,r);if(u.y<u.x){let e=u.y;u.y=u.x,u.x=e,l.copy(s.start),s.start.copy(s.end),s.end.copy(l)}if(d.y<d.x){let e=d.y;d.y=d.x,d.x=e,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<d.x||d.y<u.x?!1:(n&&(d.x>u.x?n.start.copy(c.start):n.start.copy(s.start),d.y<u.y?n.end.copy(c.end):n.end.copy(s.end)),!0)}})(),Xu.prototype.distanceToPoint=(function(){let e=new J;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),Xu.prototype.distanceToTriangle=(function(){let e=new J,t=new J,n=[`a`,`b`,`c`],r=new ys,i=new ys;return function(a,o=null,s=null){let c=o||s?r:null;if(this.intersectsTriangle(a,c,!0))return(o||s)&&(o&&c.getCenter(o),s&&c.getCenter(s)),0;let l=1/0;for(let t=0;t<3;t++){let r,i=n[t],c=a[i];this.closestPointToPoint(c,e),r=c.distanceToSquared(e),r<l&&(l=r,o&&o.copy(e),s&&s.copy(c));let u=this[i];a.closestPointToPoint(u,e),r=u.distanceToSquared(e),r<l&&(l=r,o&&o.copy(u),s&&s.copy(e))}for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];r.set(this[u],this[d]);for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];i.set(a[u],a[d]),Wu(r,i,e,t);let f=e.distanceToSquared(t);f<l&&(l=f,o&&o.copy(e),s&&s.copy(t))}}return Math.sqrt(l)}})();var Zu=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new J,this.max=new J,this.matrix=new Y,this.invMatrix=new Y,this.points=Array(8).fill().map(()=>new J),this.satAxes=[,,,].fill().map(()=>new J),this.satBounds=[,,,].fill().map(()=>new Hu),this.alignedSatBounds=[,,,].fill().map(()=>new Hu),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}};Zu.prototype.update=(function(){return function(){let e=this.matrix,t=this.min,n=this.max,r=this.points;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let o=0;o<=1;o++){let s=r[1*i|2*a|4*o];s.x=i?n.x:t.x,s.y=a?n.y:t.y,s.z=o?n.z:t.z,s.applyMatrix4(e)}let i=this.satBounds,a=this.satAxes,o=r[0];for(let e=0;e<3;e++){let t=a[e],n=i[e],s=r[1<<e];t.subVectors(o,s),n.setFromPoints(t,r)}let 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}})(),Zu.prototype.intersectsBox=(function(){let e=new Hu;return function(t){this.needsUpdate&&this.update();let n=t.min,r=t.max,i=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(e.min=n.x,e.max=r.x,o[0].isSeparated(e)||(e.min=n.y,e.max=r.y,o[1].isSeparated(e))||(e.min=n.z,e.max=r.z,o[2].isSeparated(e)))return!1;for(let n=0;n<3;n++){let r=a[n],o=i[n];if(e.setFromBox(r,t),o.isSeparated(e))return!1}return!0}})(),Zu.prototype.intersectsTriangle=(function(){let e=new Xu,t=[,,,],n=new Hu,r=new Hu,i=new J;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(e.copy(a),e.update(),a=e);let o=this.satBounds,s=this.satAxes;t[0]=a.a,t[1]=a.b,t[2]=a.c;for(let e=0;e<3;e++){let r=o[e],i=s[e];if(n.setFromPoints(i,t),r.isSeparated(n))return!1}let c=a.satBounds,l=a.satAxes,u=this.points;for(let e=0;e<3;e++){let t=c[e],r=l[e];if(n.setFromPoints(r,u),t.isSeparated(n))return!1}for(let e=0;e<3;e++){let a=s[e];for(let e=0;e<4;e++){let o=l[e];if(i.crossVectors(a,o),n.setFromPoints(i,t),r.setFromPoints(i,u),n.isSeparated(r))return!1}}return!0}})(),Zu.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})(),Zu.prototype.distanceToPoint=(function(){let e=new J;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),Zu.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new ys),n=Array(12).fill().map(()=>new ys),r=new J,i=new J;return function(a,o=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(s||c)&&(a.getCenter(i),this.closestPointToPoint(i,r),a.closestPointToPoint(r,i),s&&s.copy(r),c&&c.copy(i)),0;let l=o*o,u=a.min,d=a.max,f=this.points,p=1/0;for(let e=0;e<8;e++){let t=f[e];i.copy(t).clamp(u,d);let n=t.distanceToSquared(i);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(i),n<l))return Math.sqrt(n)}let m=0;for(let r=0;r<3;r++)for(let i=0;i<=1;i++)for(let a=0;a<=1;a++){let o=(r+1)%3,s=(r+2)%3,c=i<<o|a<<s,l=1<<r|i<<o|a<<s,p=f[c],h=f[l];t[m].set(p,h);let g=e[r],_=e[o],v=e[s],y=n[m],b=y.start,x=y.end;b[g]=u[g],b[_]=i?u[_]:d[_],b[v]=a?u[v]:d[_],x[g]=d[g],x[_]=i?u[_]:d[_],x[v]=a?u[v]:d[_],m++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let n=0;n<=1;n++){i.x=e?d.x:u.x,i.y=t?d.y:u.y,i.z=n?d.z:u.z,this.closestPointToPoint(i,r);let a=i.distanceToSquared(r);if(a<p&&(p=a,s&&s.copy(r),c&&c.copy(i),a<l))return Math.sqrt(a)}for(let e=0;e<12;e++){let a=t[e];for(let e=0;e<12;e++){let t=n[e];Wu(a,t,r,i);let o=r.distanceToSquared(i);if(o<p&&(p=o,s&&s.copy(r),c&&c.copy(i),o<l))return Math.sqrt(o)}}return Math.sqrt(p)}})();var Qu=new class extends du{constructor(){super(()=>new Xu)}},$u=new J,ed=new J;function td(e,t,n={},r=0,i=1/0){let a=r*r,o=i*i,s=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>($u.copy(t).clamp(e.min,e.max),$u.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,$u);let r=t.distanceToSquared($u);return r<s&&(ed.copy($u),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(ed):n.point=ed.clone(),n.distance=l,n.faceIndex=c,n}var nd=!0,rd=new J,id=new J,ad=new J,od=new q,sd=new q,cd=new q,ld=new J,ud=new J,dd=new J,fd=new J;function pd(e,t,n,r,i,a,o,s){let c;if(c=a===1?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==2,i),c===null)return null;let l=e.origin.distanceTo(i);return l<o||l>s?null:{distance:l,point:i.clone()}}function md(e,t,n,r,i,a,o,s,c,l,u){rd.fromBufferAttribute(t,a),id.fromBufferAttribute(t,o),ad.fromBufferAttribute(t,s);let d=pd(e,rd,id,ad,fd,c,l,u);if(d){if(r){od.fromBufferAttribute(r,a),sd.fromBufferAttribute(r,o),cd.fromBufferAttribute(r,s),d.uv=new q;let e=$n.getInterpolation(fd,rd,id,ad,od,sd,cd,d.uv);nd||(d.uv=e)}if(i){od.fromBufferAttribute(i,a),sd.fromBufferAttribute(i,o),cd.fromBufferAttribute(i,s),d.uv1=new q;let e=$n.getInterpolation(fd,rd,id,ad,od,sd,cd,d.uv1);nd||(d.uv1=e)}if(n){ld.fromBufferAttribute(n,a),ud.fromBufferAttribute(n,o),dd.fromBufferAttribute(n,s),d.normal=new J;let t=$n.getInterpolation(fd,rd,id,ad,ld,ud,dd,d.normal);d.normal.dot(e.direction)>0&&d.normal.multiplyScalar(-1),nd||(d.normal=t)}let t={a,b:o,c:s,normal:new J,materialIndex:0};if($n.getNormal(rd,id,ad,t.normal),d.face=t,d.faceIndex=a,nd){let e=new J;$n.getBarycoord(fd,rd,id,ad,e),d.barycoord=e}}return d}function hd(e){return e&&e.isMaterial?e.side:e}function gd(e,t,n,r,i,a,o){let s=r*3,c=s+0,l=s+1,u=s+2,{index:d,groups:f}=e;e.index&&(c=d.getX(c),l=d.getX(l),u=d.getX(u));let{position:p,normal:m,uv:h,uv1:g}=e.attributes;if(Array.isArray(t)){let e=r*3;for(let s=0,d=f.length;s<d;s++){let{start:d,count:_,materialIndex:v}=f[s];if(e>=d&&e<d+_){let e=hd(t[v]),s=md(n,p,m,h,g,c,l,u,e,a,o);if(s){if(s.faceIndex=r,s.face.materialIndex=v,i)i.push(s);else return s}}}}else{let e=hd(t),s=md(n,p,m,h,g,c,l,u,e,a,o);if(s){if(s.faceIndex=r,s.face.materialIndex=0,i)i.push(s);else return s}}return null}function _d(e,t,n,r){let i=e.a,a=e.b,o=e.c,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),a.x=r.getX(c),a.y=r.getY(c),a.z=r.getZ(c),o.x=r.getX(l),o.y=r.getY(l),o.z=r.getZ(l)}function vd(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)gd(c,t,n,e,a,o,s)}function yd(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,c=r+i;e<c;e++){let r;r=gd(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function bd(e,t,n,r,i,a,o){let{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,_d(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function xd(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(e,n,a=!1){let l=e*2;if(zl(l,s)){let t=Bl(e,o),n=Vl(l,s),a=1/0,u=1/0,d=1/0,f=-1/0,p=-1/0,m=-1/0;for(let e=3*t,o=3*(t+n);e<o;e++){let t=r[e],n=i.getX(t),o=i.getY(t),s=i.getZ(t);n<a&&(a=n),n>f&&(f=n),o<u&&(u=o),o>p&&(p=o),s<d&&(d=s),s>m&&(m=s)}return c[e+0]!==a||c[e+1]!==u||c[e+2]!==d||c[e+3]!==f||c[e+4]!==p||c[e+5]!==m?(c[e+0]=a,c[e+1]=u,c[e+2]=d,c[e+3]=f,c[e+4]=p,c[e+5]=m,!0):!1}{let r=Hl(e),i=Ul(e,o),s=a,l=!1,u=!1;if(t){if(!s){let e=r/8+n/32,a=i/8+n/32;l=t.has(e),u=t.has(a),s=!l&&!u}}else l=!0,u=!0;let f=s||l,p=s||u,m=!1;f&&(m=d(r,n,s));let h=!1;p&&(h=d(i,n,s));let g=m||h;if(g)for(let t=0;t<3;t++){let n=r+t,a=i+t,o=c[n],s=c[n+3],l=c[a],u=c[a+3];c[e+t]=o<l?o:l,c[e+t+3]=s>u?s:u}return g}}}function Sd(e,t,n,r,i){let a,o,s,c,l,u,d=1/n.direction.x,f=1/n.direction.y,p=1/n.direction.z,m=n.origin.x,h=n.origin.y,g=n.origin.z,_=t[e],v=t[e+3],y=t[e+1],b=t[e+3+1],x=t[e+2],S=t[e+3+2];return d>=0?(a=(_-m)*d,o=(v-m)*d):(a=(v-m)*d,o=(_-m)*d),f>=0?(s=(y-h)*f,c=(b-h)*f):(s=(b-h)*f,c=(y-h)*f),a>c||s>o||((s>a||isNaN(a))&&(a=s),(c<o||isNaN(o))&&(o=c),p>=0?(l=(x-g)*p,u=(S-g)*p):(l=(S-g)*p,u=(x-g)*p),a>u||l>o)?!1:((l>a||a!==a)&&(a=l),(u<o||o!==o)&&(o=u),a<=i&&o>=r)}function Cd(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)gd(c,t,n,l?l[e]:e,a,o,s)}function wd(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,d=r+i;e<d;e++){let r;r=gd(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Td(e,t,n,r,i,a,o){let{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),_d(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Ed(e,t,n,r,i,a,o){$.setBuffer(e._roots[t]),Dd(0,e,n,r,i,a,o),$.clearBuffer()}function Dd(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=$,u=e*2;if(zl(u,c))vd(t,n,r,Bl(e,l),Vl(u,c),i,a,o);else{let c=Hl(e);Sd(c,s,r,a,o)&&Dd(c,t,n,r,i,a,o);let u=Ul(e,l);Sd(u,s,r,a,o)&&Dd(u,t,n,r,i,a,o)}}var Od=[`x`,`y`,`z`];function kd(e,t,n,r,i,a){$.setBuffer(e._roots[t]);let o=Ad(0,e,n,r,i,a);return $.clearBuffer(),o}function Ad(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=$,l=e*2;if(zl(l,s))return yd(t,n,r,Bl(e,c),Vl(l,s),i,a);{let s=Wl(e,c),l=Od[s],u=r.direction[l]>=0,d,f;u?(d=Hl(e),f=Ul(e,c)):(d=Ul(e,c),f=Hl(e));let p=Sd(d,o,r,i,a)?Ad(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=Sd(f,o,r,i,a)?Ad(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var jd=new er,Md=new Xu,Nd=new Xu,Pd=new Y,Fd=new Zu,Id=new Zu;function Ld(e,t,n,r){$.setBuffer(e._roots[t]);let i=Rd(0,e,n,r);return $.clearBuffer(),i}function Rd(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=$,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Fd.set(n.boundingBox.min,n.boundingBox.max,r),i=Fd),zl(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=Bl(e,s),m=Vl(c,o);if(Pd.copy(r).invert(),n.boundsTree)return Nl(Gl(e),a,Id),Id.matrix.copy(Pd),Id.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>Id.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let t=p*3,n=(m+p)*3;t<n;t+=3)if(_d(Nd,t,l,u),Nd.needsUpdate=!0,e.intersectsTriangle(Nd))return!0;return!1}});{let e=Pu(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){_d(Md,t,l,u),Md.a.applyMatrix4(Pd),Md.b.applyMatrix4(Pd),Md.c.applyMatrix4(Pd),Md.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(_d(Nd,t,d,f),Nd.needsUpdate=!0,Md.intersectsTriangle(Nd))return!0}}}else{let o=Hl(e),c=Ul(e,s);return Nl(Gl(o),a,jd),!!(i.intersectsBox(jd)&&Rd(o,t,n,r,i)||(Nl(Gl(c),a,jd),i.intersectsBox(jd)&&Rd(c,t,n,r,i)))}}var zd=new Y,Bd=new Zu,Vd=new Zu,Hd=new J,Ud=new J,Wd=new J,Gd=new J;function Kd(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Bd.set(t.boundingBox.min,t.boundingBox.max,n),Bd.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=Qu.getPrimitive(),p=Qu.getPrimitive(),m=Hd,h=Ud,g=null,_=null;i&&(g=Wd,_=Gd);let v=1/0,y=null,b=null;return zd.copy(n).invert(),Vd.matrix.copy(zd),e.shapecast({boundsTraverseOrder:e=>Bd.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(Vd.min.copy(e.min),Vd.max.copy(e.max),Vd.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>Vd.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){_d(p,3*o,d,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++){_d(f,3*t,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=t,b=o),e<a)return!0}}}});{let i=Pu(t);for(let t=0,o=i;t<o;t++){_d(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=e,i=e+r;n<i;n++){_d(f,3*n,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=n,b=t),e<a)return!0}}}}}),Qu.releasePrimitive(f),Qu.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(zd),h.applyMatrix4(zd),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function qd(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(n,a,l=!1){let u=n*2;if(zl(u,s)){let t=Bl(n,o),a=Vl(u,s),l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,h=-1/0;for(let n=t,o=t+a;n<o;n++){let t=3*e.resolveTriangleIndex(n);for(let e=0;e<3;e++){let n=t+e;n=r?r[n]:n;let a=i.getX(n),o=i.getY(n),s=i.getZ(n);a<l&&(l=a),a>p&&(p=a),o<d&&(d=o),o>m&&(m=o),s<f&&(f=s),s>h&&(h=s)}}return c[n+0]!==l||c[n+1]!==d||c[n+2]!==f||c[n+3]!==p||c[n+4]!==m||c[n+5]!==h?(c[n+0]=l,c[n+1]=d,c[n+2]=f,c[n+3]=p,c[n+4]=m,c[n+5]=h,!0):!1}{let e=Hl(n),r=Ul(n,o),i=l,s=!1,u=!1;if(t){if(!i){let n=e/8+a/32,o=r/8+a/32;s=t.has(n),u=t.has(o),i=!s&&!u}}else s=!0,u=!0;let f=i||s,p=i||u,m=!1;f&&(m=d(e,a,i));let h=!1;p&&(h=d(r,a,i));let g=m||h;if(g)for(let t=0;t<3;t++){let i=e+t,a=r+t,o=c[i],s=c[i+3],l=c[a],u=c[a+3];c[n+t]=o<l?o:l,c[n+t+3]=s>u?s:u}return g}}}function Jd(e,t,n,r,i,a,o){$.setBuffer(e._roots[t]),Yd(0,e,n,r,i,a,o),$.clearBuffer()}function Yd(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=$,u=e*2;if(zl(u,c))Cd(t,n,r,Bl(e,l),Vl(u,c),i,a,o);else{let c=Hl(e);Sd(c,s,r,a,o)&&Yd(c,t,n,r,i,a,o);let u=Ul(e,l);Sd(u,s,r,a,o)&&Yd(u,t,n,r,i,a,o)}}var Xd=[`x`,`y`,`z`];function Zd(e,t,n,r,i,a){$.setBuffer(e._roots[t]);let o=Qd(0,e,n,r,i,a);return $.clearBuffer(),o}function Qd(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=$,l=e*2;if(zl(l,s))return wd(t,n,r,Bl(e,c),Vl(l,s),i,a);{let s=Wl(e,c),l=Xd[s],u=r.direction[l]>=0,d,f;u?(d=Hl(e),f=Ul(e,c)):(d=Ul(e,c),f=Hl(e));let p=Sd(d,o,r,i,a)?Qd(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=Sd(f,o,r,i,a)?Qd(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var $d=new er,ef=new Xu,tf=new Xu,nf=new Y,rf=new Zu,af=new Zu;function of(e,t,n,r){$.setBuffer(e._roots[t]);let i=sf(0,e,n,r);return $.clearBuffer(),i}function sf(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=$,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),rf.set(n.boundingBox.min,n.boundingBox.max,r),i=rf),zl(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=Bl(e,s),m=Vl(c,o);if(nf.copy(r).invert(),n.boundsTree)return Nl(Gl(e),a,af),af.matrix.copy(nf),af.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>af.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let n=p,r=m+p;n<r;n++)if(_d(tf,3*t.resolveTriangleIndex(n),l,u),tf.needsUpdate=!0,e.intersectsTriangle(tf))return!0;return!1}});{let e=Pu(n);for(let n=p,r=m+p;n<r;n++){_d(ef,3*t.resolveTriangleIndex(n),l,u),ef.a.applyMatrix4(nf),ef.b.applyMatrix4(nf),ef.c.applyMatrix4(nf),ef.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(_d(tf,t,d,f),tf.needsUpdate=!0,ef.intersectsTriangle(tf))return!0}}}else{let o=Hl(e),c=Ul(e,s);return Nl(Gl(o),a,$d),!!(i.intersectsBox($d)&&sf(o,t,n,r,i)||(Nl(Gl(c),a,$d),i.intersectsBox($d)&&sf(c,t,n,r,i)))}}var cf=new Y,lf=new Zu,uf=new Zu,df=new J,ff=new J,pf=new J,mf=new J;function hf(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),lf.set(t.boundingBox.min,t.boundingBox.max,n),lf.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=Qu.getPrimitive(),p=Qu.getPrimitive(),m=df,h=ff,g=null,_=null;i&&(g=pf,_=mf);let v=1/0,y=null,b=null;return cf.copy(n).invert(),uf.matrix.copy(cf),e.shapecast({boundsTraverseOrder:e=>lf.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(uf.min.copy(e.min),uf.max.copy(e.max),uf.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>uf.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,o)=>{for(let x=t,S=t+o;x<S;x++){let t=s.resolveTriangleIndex(x);_d(p,3*t,d,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++){let n=e.resolveTriangleIndex(t);_d(f,3*n,l,c),f.needsUpdate=!0;let r=f.distanceToTriangle(p,m,g);if(r<v&&(h.copy(m),_&&_.copy(g),v=r,y=t,b=x),r<a)return!0}}}})}{let o=Pu(t);for(let t=0,s=o;t<s;t++){_d(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=r,o=r+i;n<o;n++){let r=e.resolveTriangleIndex(n);_d(f,3*r,l,c),f.needsUpdate=!0;let i=f.distanceToTriangle(p,m,g);if(i<v&&(h.copy(m),_&&_.copy(g),v=i,y=n,b=t),i<a)return!0}}}}}),Qu.releasePrimitive(f),Qu.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(cf),h.applyMatrix4(cf),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function gf(e,t,n){return e===null?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(n.ray.origin),e.object=t,e)}var _f=new Zu,vf=new Hr,yf=new J,bf=new Y,xf=new J,Sf=[`getX`,`getY`,`getZ`],Cf=class e extends Vu{static serialize(e,t={}){t={cloneBuffers:!0,...t};let n=e.geometry,r=e._roots,i=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=r.map(e=>e.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=i?i.slice():null):(o.roots=r,o.index=a?a.array:null,o.indirectBuffer=i),o}static deserialize(t,n,r={}){r={setIndex:!0,indirect:!!t.indirectBuffer,...r};let{index:i,roots:a,indirectBuffer:o}=t;t.version||(console.warn(`MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data.`),c(a));let s=new e(n,{...r,[jl]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new vr(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function c(e){for(let t=0;t<e.length;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n);for(let e=0,t=n.byteLength/32;e<t;e++){let t=8*e;zl(2*t,i)||(r[t+6]=r[t+6]/8-e)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn(`MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.`),t={...t,targetLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=(i?i[e]:e)*3,c=s+0,l=s+1,u=s+2;o&&(c=o[c],l=o[l],u=o[u]);for(let e=0;e<3;e++){let r=a[Sf[e]](c),i=a[Sf[e]](l),o=a[Sf[e]](u),s=r;i<s&&(s=i),o<s&&(s=o);let d=r;i>d&&(d=i),o>d&&(d=o),t[n+e]=s,t[n+e+3]=d}return t}computePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw Error(`MeshBVH: compute triangle bounds range is invalid.`);let c=a.array,l=a.offset||0,u=3;a.isInterleavedBufferAttribute&&(u=a.data.stride);let d=[`getX`,`getY`,`getZ`],f=n.offset;for(let r=e,p=e+t;r<p;r++){let e=(i?i[r]:r)*3,t=(r-f)*6,p=e+0,m=e+1,h=e+2;o&&(p=o[p],m=o[m],h=o[h]),s||(p=p*u+l,m=m*u+l,h=h*u+l);for(let e=0;e<3;e++){let r,i,o;s?(r=a[d[e]](p),i=a[d[e]](m),o=a[d[e]](h)):(r=c[p+e],i=c[m+e],o=c[h+e]);let l=r;i<l&&(l=i),o<l&&(l=o);let u=r;i>u&&(u=i),o>u&&(u=o);let f=(u-l)/2,g=e*2;n[t+g+0]=l+f,n[t+g+1]=f+(Math.abs(l)+f)*Al}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;bf.copy(e.matrixWorld).invert(),vf.copy(t.ray).applyMatrix4(bf),xf.setFromMatrixScale(e.matrixWorld),yf.copy(vf.direction).multiply(xf);let i=yf.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(vf,r,a,o);i=gf(i,e,t),i&&n.push(i)}else{let i=this.raycast(vf,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=gf(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?qd:xd)(this,e)}raycast(e,t=0,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?Jd:Ed;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=0,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?Zd:kd;for(let s=0,c=i.length;s<c;s++){let i=o(this,s,t,e,n,r);i!=null&&(a==null||i.distance<a.distance)&&(a=i)}return a}intersectsGeometry(e,t){let n=!1,r=this._roots,i=this.indirect?of:Ld;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=Qu.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Td:bd});return Qu.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=Qu.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);_d(o,t*3,s,c)}:e=>{_d(o,e*3,s,c)},u=Qu.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);_d(u,n*3,d,f)}:e=>{_d(u,e*3,d,f)};if(a){if(!(t instanceof e))throw Error(`MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.`);let r=(e,t,r,i,s,c,d,f)=>{for(let m=r,h=r+i;m<h;m++){p(m),u.a.applyMatrix4(n),u.b.applyMatrix4(n),u.c.applyMatrix4(n),u.needsUpdate=!0;for(let n=e,r=e+t;n<r;n++)if(l(n),o.needsUpdate=!0,a(o,u,n,m,s,c,d,f))return!0}return!1};if(i){let e=i;i=function(t,n,i,a,o,s,c,l){return e(t,n,i,a,o,s,c,l)?!0:r(t,n,i,a,o,s,c,l)}}else i=r}return super.bvhcast(t,n,{intersectsRanges:i})}intersectsBox(e,t){return _f.set(e.min,e.max,t),_f.needsUpdate=!0,this.shapecast({intersectsBounds:e=>_f.intersectsBox(e),intersectsTriangle:e=>_f.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},r={},i=0,a=1/0){return(this.indirect?hf:Kd)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return td(this,e,t,n,r)}},wf=1e-6,Tf=wf*.5,Ef=10**-Math.log10(wf),Df=Tf*Ef;function Of(e){return~~(e*Ef+Df)}function kf(e){return`${Of(e.x)},${Of(e.y)}`}function Af(e){return`${Of(e.x)},${Of(e.y)},${Of(e.z)}`}function jf(e){return`${Of(e.x)},${Of(e.y)},${Of(e.z)},${Of(e.w)}`}function Mf(e,t,n){n.direction.subVectors(t,e).normalize();let r=e.dot(n.direction);return n.origin.copy(e).addScaledVector(n.direction,-r),n}function Nf(){return typeof SharedArrayBuffer<`u`}function Pf(e){if(e.buffer instanceof SharedArrayBuffer)return e;let t=e.constructor,n=e.buffer,r=new SharedArrayBuffer(n.byteLength),i=new Uint8Array(n);return new Uint8Array(r).set(i,0),new t(r)}function Ff(e){return e.index?e.index.count:e.attributes.position.count}function If(e){return Ff(e)/3}var Lf=1e-8,Rf=new J;function zf(e){return~~(e/3)}function Bf(e){return e%3}function Vf(e,t){return e.start-t.start}function Hf(e,t){return Rf.subVectors(t,e.origin).dot(e.direction)}function Uf(e,t,n,r=Lf){e.sort(Vf),t.sort(Vf);for(let r=0;r<e.length;r++){let i=e[r];for(let s=0;s<t.length;s++){let c=t[s];if(!(c.start>i.end)){if(i.end<c.start||c.end<i.start)continue;if(i.start<=c.start&&i.end>=c.end)a(c.end,i.end)||e.splice(r+1,0,{start:c.end,end:i.end,index:i.index}),i.end=c.start,c.start=0,c.end=0;else if(i.start>=c.start&&i.end<=c.end)a(i.end,c.end)||t.splice(s+1,0,{start:i.end,end:c.end,index:c.index}),c.end=i.start,i.start=0,i.end=0;else if(i.start<=c.start&&i.end<=c.end){let e=i.end;i.end=c.start,c.start=e}else if(i.start>=c.start&&i.end>=c.end){let e=c.end;c.end=i.start,i.start=e}else throw Error()}if(n.has(i.index)||n.set(i.index,[]),n.has(c.index)||n.set(c.index,[]),n.get(i.index).push(c.index),n.get(c.index).push(i.index),o(c)&&(t.splice(s,1),s--),o(i)){e.splice(r,1),r--;break}}}i(e),i(t);function i(e){for(let t=0;t<e.length;t++)o(e[t])&&(e.splice(t,1),t--)}function a(e,t){return Math.abs(t-e)<r}function o(e){return Math.abs(e.end-e.start)<r}}var Wf=1e-5,Gf=1e-4,Kf=class{constructor(){this._rays=[]}addRay(e){this._rays.push(e)}findClosestRay(e){let t=this._rays,n=e.clone();n.direction.multiplyScalar(-1);let r=1/0,i=null;for(let s=0,c=t.length;s<c;s++){let c=t[s];if(a(c,e)&&a(c,n))continue;let l=o(c,e),u=o(c,n),d=Math.min(l,u);d<r&&(r=d,i=c)}return i;function a(e,t){let n=e.origin.distanceTo(t.origin)>Wf;return e.direction.angleTo(t.direction)>Gf||n}function o(e,t){let n=e.origin.distanceTo(t.origin),r=e.direction.angleTo(t.direction);return n/Wf+r/Gf}}},qf=new J,Jf=new J,Yf=new Hr;function Xf(e,t,n){let r=e.attributes,i=e.index,a=r.position,o=new Map,s=new Map,c=Array.from(t),l=new Kf;for(let e=0,t=c.length;e<t;e++){let t=c[e],n=zf(t),r=Bf(t),o=3*n+r,u=3*n+(r+1)%3;i&&(o=i.getX(o),u=i.getX(u)),qf.fromBufferAttribute(a,o),Jf.fromBufferAttribute(a,u),Mf(qf,Jf,Yf);let d,f=l.findClosestRay(Yf);f===null&&(f=Yf.clone(),l.addRay(f)),s.has(f)||s.set(f,{forward:[],reverse:[],ray:f}),d=s.get(f);let p=Hf(f,qf),m=Hf(f,Jf);p>m&&([p,m]=[m,p]),Yf.direction.dot(f.direction)<0?d.reverse.push({start:p,end:m,index:t}):d.forward.push({start:p,end:m,index:t})}return s.forEach(({forward:e,reverse:t},r)=>{Uf(e,t,o,n),e.length===0&&t.length===0&&s.delete(r)}),{disjointConnectivityMap:o,fragmentMap:s}}var Zf=new q,Qf=new J,$f=new Zt,ep=[``,``,``],tp=class{constructor(){this.data=null,this.disjointConnections=null,this.unmatchedDisjointEdges=null,this.unmatchedEdges=-1,this.matchedEdges=-1,this.useDrawRange=!0,this.useAllAttributes=!1,this.matchDisjointEdges=!1,this.degenerateEpsilon=1e-8}getSiblingTriangleIndex(e,t){let n=this.data[e*3+t];return n===-1?-1:~~(n/3)}getSiblingEdgeIndex(e,t){let n=this.data[e*3+t];return n===-1?-1:n%3}getDisjointSiblingTriangleIndices(e,t){let n=e*3+t,r=this.disjointConnections.get(n);return r?r.map(e=>~~(e/3)):[]}getDisjointSiblingEdgeIndices(e,t){let n=e*3+t,r=this.disjointConnections.get(n);return r?r.map(e=>e%3):[]}isFullyConnected(){return this.unmatchedEdges===0}updateFrom(e){let{useAllAttributes:t,useDrawRange:n,matchDisjointEdges:r,degenerateEpsilon:i}=this,a=t?v:_,o=new Map,{attributes:s}=e,c=t?Object.keys(s):null,l=e.index,u=s.position,d=If(e),f=d,p=0;n&&(p=e.drawRange.start,e.drawRange.count!==1/0&&(d=~~(e.drawRange.count/3)));let m=this.data;(!m||m.length<3*f)&&(m=new Int32Array(3*f)),m.fill(-1);let h=0,g=new Set;for(let e=p,t=d*3+p;e<t;e+=3){let t=e;for(let e=0;e<3;e++){let n=t+e;l&&(n=l.getX(n)),ep[e]=a(n)}for(let e=0;e<3;e++){let n=(e+1)%3,r=ep[e],i=ep[n],a=`${i}_${r}`;if(o.has(a)){let n=t+e,r=o.get(a);m[n]=r,m[r]=n,o.delete(a),h+=2,g.delete(r)}else{let n=`${r}_${i}`,a=t+e;o.set(n,a),g.add(a)}}}if(r){let{fragmentMap:t,disjointConnectivityMap:n}=Xf(e,g,i);g.clear(),t.forEach(({forward:e,reverse:t})=>{e.forEach(({index:e})=>g.add(e)),t.forEach(({index:e})=>g.add(e))}),this.unmatchedDisjointEdges=t,this.disjointConnections=n,h=d*3-g.size}this.matchedEdges=h,this.unmatchedEdges=g.size,this.data=m;function _(e){return Qf.fromBufferAttribute(u,e),Af(Qf)}function v(e){let t=``;for(let n=0,r=c.length;n<r;n++){let r=s[c[n]],i;switch(r.itemSize){case 1:i=Of(r.getX(e));break;case 2:i=kf(Zf.fromBufferAttribute(r,e));break;case 3:i=Af(Qf.fromBufferAttribute(r,e));break;case 4:i=jf($f.fromBufferAttribute(r,e))}t!==``&&(t+=`|`),t+=i}return t}}},np=class extends ti{constructor(...e){super(...e),this.isBrush=!0,this._previousMatrix=new Y,this._previousMatrix.elements.fill(0),this._halfEdges=null,this._boundsTree=null,this._groupIndices=null,this._hash=null}markUpdated(){this._previousMatrix.copy(this.matrix)}isDirty(){let{matrix:e,_previousMatrix:t}=this,n=e.elements,r=t.elements;for(let e=0;e<16;e++)if(n[e]!==r[e])return!0;return!1}prepareGeometry(){let e=this.geometry,t=e.attributes,n=Nf(),r=e.index,i=e.attributes.position,a=r?`${r.uuid}_${r.count}_${r.version}`:`-1_-1_-1`,o=`${i.uuid}_${i.count}_${i.version}`,s=`${e.uuid}_${a}_${o}`;if(this._hash===s)return;if(this._hash=s,n)for(let e in t){let n=t[e];if(n.isInterleavedBufferAttribute)throw Error(`Brush: InterleavedBufferAttributes are not supported.`);n.array=Pf(n.array)}e.boundsTree=new Cf(e,{maxLeafSize:3,indirect:!0,useSharedArrayBuffer:n}),e.halfEdges||=new tp,e.halfEdges.updateFrom(e);let c=If(e);(!e.groupIndices||e.groupIndices.length!==c)&&(e.groupIndices=new Uint16Array(c));let l=e.groupIndices,u=e.groups;for(let e=0,t=u.length;e<t;e++){let{start:t,count:n}=u[e];for(let r=t/3,i=(t+n)/3;r<i;r++)l[r]=e}}disposeCacheData(){let{geometry:e}=this;e.halfEdges=null,e.boundsTree=null,e.groupIndices=null}},rp=Object.getOwnPropertyNames,ip=(e,t)=>function(){return t||(0,e[rp(e)[0]])((t={exports:{}}).exports,t),t.exports},ap=ip({"node_modules/binary-search-bounds/search-bounds.js"(e,t){"use strict";function n(e,t,n,r,i){for(var a=i+1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))>=0?(a=o,i=o-1):r=o+1}return a}function r(e,t,n,r,i){for(var a=i+1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))>0?(a=o,i=o-1):r=o+1}return a}function i(e,t,n,r,i){for(var a=r-1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))<0?(a=o,r=o+1):i=o-1}return a}function a(e,t,n,r,i){for(var a=r-1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))<=0?(a=o,r=o+1):i=o-1}return a}function o(e,t,n,r,i){for(;r<=i;){var a=r+i>>>1,o=e[a],s=n===void 0?o-t:n(o,t);if(s===0)return a;s<=0?r=a+1:i=a-1}return-1}function s(e,t,n,r,i,a){return typeof n==`function`?a(e,t,n,r===void 0?0:r|0,i===void 0?e.length-1:i|0):a(e,t,void 0,n===void 0?0:n|0,r===void 0?e.length-1:r|0)}t.exports={ge:function(e,t,r,i,a){return s(e,t,r,i,a,n)},gt:function(e,t,n,i,a){return s(e,t,n,i,a,r)},lt:function(e,t,n,r,a){return s(e,t,n,r,a,i)},le:function(e,t,n,r,i){return s(e,t,n,r,i,a)},eq:function(e,t,n,r,i){return s(e,t,n,r,i,o)}}}}),op=ip({"node_modules/two-product/two-product.js"(e,t){"use strict";t.exports=r;var n=+(2**27+1);function r(e,t,r){var i=e*t,a=n*e,o=a-(a-e),s=e-o,c=n*t,l=c-(c-t),u=t-l,d=i-o*l-s*l-o*u,f=s*u-d;return r?(r[0]=f,r[1]=i,r):[f,i]}}}),sp=ip({"node_modules/robust-sum/robust-sum.js"(e,t){"use strict";t.exports=r;function n(e,t){var n=e+t,r=n-e,i=n-r,a=t-r,o=e-i+a;return o?[o,n]:[n]}function r(e,t){var r=e.length|0,i=t.length|0;if(r===1&&i===1)return n(e[0],t[0]);var a=r+i,o=Array(a),s=0,c=0,l=0,u=Math.abs,d=e[c],f=u(d),p=t[l],m=u(p),h,g;f<m?(g=d,c+=1,c<r&&(d=e[c],f=u(d))):(g=p,l+=1,l<i&&(p=t[l],m=u(p))),c<r&&f<m||l>=i?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=t[l],m=u(p)));for(var _=h+g,v=_-h,y=g-v,b=y,x=_,S,C,w,T,E;c<r&&l<i;)f<m?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=t[l],m=u(p))),g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S;for(;c<r;)h=d,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,c+=1,c<r&&(d=e[c]);for(;l<i;)h=p,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,l+=1,l<i&&(p=t[l]);return b&&(o[s++]=b),x&&(o[s++]=x),s||(o[s++]=0),o.length=s,o}}}),cp=ip({"node_modules/two-sum/two-sum.js"(e,t){"use strict";t.exports=n;function n(e,t,n){var r=e+t,i=r-e,a=r-i,o=t-i,s=e-a;return n?(n[0]=s+o,n[1]=r,n):[s+o,r]}}}),lp=ip({"node_modules/robust-scale/robust-scale.js"(e,t){"use strict";var n=op(),r=cp();t.exports=i;function i(e,t){var i=e.length;if(i===1){var a=n(e[0],t);return a[0]?a:[a[1]]}var o=Array(2*i),s=[.1,.1],c=[.1,.1],l=0;n(e[0],t,s),s[0]&&(o[l++]=s[0]);for(var u=1;u<i;++u){n(e[u],t,c);var d=s[1];r(d,c[0],s),s[0]&&(o[l++]=s[0]);var f=c[1],p=s[1],m=f+p,h=p-(m-f);s[1]=m,h&&(o[l++]=h)}return s[1]&&(o[l++]=s[1]),l===0&&(o[l++]=0),o.length=l,o}}}),up=ip({"node_modules/robust-subtract/robust-diff.js"(e,t){"use strict";t.exports=r;function n(e,t){var n=e+t,r=n-e,i=n-r,a=t-r,o=e-i+a;return o?[o,n]:[n]}function r(e,t){var r=e.length|0,i=t.length|0;if(r===1&&i===1)return n(e[0],-t[0]);var a=r+i,o=Array(a),s=0,c=0,l=0,u=Math.abs,d=e[c],f=u(d),p=-t[l],m=u(p),h,g;f<m?(g=d,c+=1,c<r&&(d=e[c],f=u(d))):(g=p,l+=1,l<i&&(p=-t[l],m=u(p))),c<r&&f<m||l>=i?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=-t[l],m=u(p)));for(var _=h+g,v=_-h,y=g-v,b=y,x=_,S,C,w,T,E;c<r&&l<i;)f<m?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=-t[l],m=u(p))),g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S;for(;c<r;)h=d,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,c+=1,c<r&&(d=e[c]);for(;l<i;)h=p,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,l+=1,l<i&&(p=-t[l]);return b&&(o[s++]=b),x&&(o[s++]=x),s||(o[s++]=0),o.length=s,o}}}),dp=ip({"node_modules/robust-orientation/orientation.js"(e,t){"use strict";var n=op(),r=sp(),i=lp(),a=up(),o=5,s=11102230246251565e-32,c=(3+16*s)*s,l=(7+56*s)*s;function u(e,t,n,r){return function(n,i,a){var o=r(e(e(t(i[1],a[0]),t(-a[1],i[0])),e(t(n[1],i[0]),t(-i[1],n[0]))),e(t(n[1],a[0]),t(-a[1],n[0])));return o[o.length-1]}}function d(e,t,n,r){return function(i,a,o,s){var c=r(e(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2])))),e(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2])))));return c[c.length-1]}}function f(e,t,n,r){return function(i,a,o,s,c){var l=r(e(e(e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),a[3]),e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-s[2]),n(e(t(a[1],s[0]),t(-s[1],a[0])),c[2]))),-o[3]),n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),c[2]))),s[3]))),e(n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),-c[3]),e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-s[2]),n(e(t(a[1],s[0]),t(-s[1],a[0])),c[2]))),i[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-s[2]),n(e(t(i[1],s[0]),t(-s[1],i[0])),c[2]))),-a[3])))),e(e(n(e(n(e(t(a[1],c[0]),t(-c[1],a[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),c[2]))),s[3]),e(n(e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),-c[3]),n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),i[3]))),e(n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),-a[3]),e(n(e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),o[3]),n(e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2]))),-s[3]))))),e(e(e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),i[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-s[2]),n(e(t(i[1],s[0]),t(-s[1],i[0])),c[2]))),-o[3])),e(n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),c[2]))),s[3]),n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),-c[3]))),e(e(n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),c[2]))),i[3]),n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),c[2]))),-a[3])),e(n(e(n(e(t(a[1],c[0]),t(-c[1],a[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),c[2]))),o[3]),n(e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2]))),-c[3])))));return l[l.length-1]}}function p(e){return(e===3?u:e===4?d:f)(r,n,i,a)}var m=p(3),h=p(4),g=[function(){return 0},function(){return 0},function(e,t){return t[0]-e[0]},function(e,t,n){var r=(e[1]-n[1])*(t[0]-n[0]),i=(e[0]-n[0])*(t[1]-n[1]),a=r-i,o;if(r>0){if(i<=0)return a;o=r+i}else if(r<0){if(i>=0)return a;o=-(r+i)}else return a;var s=c*o;return a>=s||a<=-s?a:m(e,t,n)},function(e,t,n,r){var i=e[0]-r[0],a=t[0]-r[0],o=n[0]-r[0],s=e[1]-r[1],c=t[1]-r[1],u=n[1]-r[1],d=e[2]-r[2],f=t[2]-r[2],p=n[2]-r[2],m=a*u,g=o*c,_=o*s,v=i*u,y=i*c,b=a*s,x=d*(m-g)+f*(_-v)+p*(y-b),S=l*((Math.abs(m)+Math.abs(g))*Math.abs(d)+(Math.abs(_)+Math.abs(v))*Math.abs(f)+(Math.abs(y)+Math.abs(b))*Math.abs(p));return x>S||-x>S?x:h(e,t,n,r)}];function _(e){var t=g[e.length];return t||=g[e.length]=p(e.length),t.apply(void 0,e)}function v(e,t,n,r,i,a,o){return function(t,n,s,c,l){switch(arguments.length){case 0:case 1:return 0;case 2:return r(t,n);case 3:return i(t,n,s);case 4:return a(t,n,s,c);case 5:return o(t,n,s,c,l)}for(var u=Array(arguments.length),d=0;d<arguments.length;++d)u[d]=arguments[d];return e(u)}}function y(){for(;g.length<=o;)g.push(p(g.length));t.exports=v.apply(void 0,[_].concat(g));for(var e=0;e<=o;++e)t.exports[e]=g[e]}y()}}),fp=ip({"node_modules/cdt2d/lib/monotone.js"(e,t){"use strict";var n=ap(),r=dp()[3],i=0,a=1,o=2;t.exports=h;function s(e,t,n,r,i){this.a=e,this.b=t,this.idx=n,this.lowerIds=r,this.upperIds=i}function c(e,t,n,r){this.a=e,this.b=t,this.type=n,this.idx=r}function l(e,t){var n=e.a[0]-t.a[0]||e.a[1]-t.a[1]||e.type-t.type;return n||e.type!==i&&(n=r(e.a,e.b,t.b),n)?n:e.idx-t.idx}function u(e,t){return r(e.a,e.b,t)}function d(e,t,i,a,o){for(var s=n.lt(t,a,u),c=n.gt(t,a,u),l=s;l<c;++l){for(var d=t[l],f=d.lowerIds,p=f.length;p>1&&r(i[f[p-2]],i[f[p-1]],a)>0;)e.push([f[p-1],f[p-2],o]),--p;f.length=p,f.push(o);for(var m=d.upperIds,p=m.length;p>1&&r(i[m[p-2]],i[m[p-1]],a)<0;)e.push([m[p-2],m[p-1],o]),--p;m.length=p,m.push(o)}}function f(e,t){var n=e.a[0]<t.a[0]?r(e.a,e.b,t.a):r(t.b,t.a,e.a);return n||(n=t.b[0]<e.b[0]?r(e.a,e.b,t.b):r(t.b,t.a,e.b),n||e.idx-t.idx)}function p(e,t,r){var i=n.le(e,r,f),a=e[i],o=a.upperIds,c=o[o.length-1];a.upperIds=[c],e.splice(i+1,0,new s(r.a,r.b,r.idx,[c],o))}function m(e,t,r){var i=r.a;r.a=r.b,r.b=i;var a=n.eq(e,r,f),o=e[a],s=e[a-1];s.upperIds=o.upperIds,e.splice(a,1)}function h(e,t){for(var n=e.length,r=t.length,u=[],f=0;f<n;++f)u.push(new c(e[f],null,i,f));for(var f=0;f<r;++f){var h=t[f],g=e[h[0]],_=e[h[1]];g[0]<_[0]?u.push(new c(g,_,o,f),new c(_,g,a,f)):g[0]>_[0]&&u.push(new c(_,g,o,f),new c(g,_,a,f))}u.sort(l);for(var v=u[0].a[0]-(1+Math.abs(u[0].a[0]))*2**-52,y=[new s([v,1],[v,0],-1,[],[],[],[])],b=[],f=0,x=u.length;f<x;++f){var S=u[f],C=S.type;C===i?d(b,y,e,S.a,S.idx):C===o?p(y,e,S):m(y,e,S)}return b}}}),pp=ip({"node_modules/cdt2d/lib/triangulation.js"(e,t){"use strict";var n=ap();t.exports=o;function r(e,t){this.stars=e,this.edges=t}var i=r.prototype;function a(e,t,n){for(var r=1,i=e.length;r<i;r+=2)if(e[r-1]===t&&e[r]===n){e[r-1]=e[i-2],e[r]=e[i-1],e.length=i-2;return}}i.isConstraint=(function(){var e=[0,0];function t(e,t){return e[0]-t[0]||e[1]-t[1]}return function(r,i){return e[0]=Math.min(r,i),e[1]=Math.max(r,i),n.eq(this.edges,e,t)>=0}})(),i.removeTriangle=function(e,t,n){var r=this.stars;a(r[e],t,n),a(r[t],n,e),a(r[n],e,t)},i.addTriangle=function(e,t,n){var r=this.stars;r[e].push(t,n),r[t].push(n,e),r[n].push(e,t)},i.opposite=function(e,t){for(var n=this.stars[t],r=1,i=n.length;r<i;r+=2)if(n[r]===e)return n[r-1];return-1},i.flip=function(e,t){var n=this.opposite(e,t),r=this.opposite(t,e);this.removeTriangle(e,t,n),this.removeTriangle(t,e,r),this.addTriangle(e,r,n),this.addTriangle(t,n,r)},i.edges=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],a=0,o=i.length;a<o;a+=2)t.push([i[a],i[a+1]]);return t},i.cells=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],a=0,o=i.length;a<o;a+=2){var s=i[a],c=i[a+1];n<Math.min(s,c)&&t.push([n,s,c])}return t};function o(e,t){for(var n=Array(e),i=0;i<e;++i)n[i]=[];return new r(n,t)}}}),mp=ip({"node_modules/robust-in-sphere/in-sphere.js"(e,t){"use strict";var n=op(),r=sp(),i=up(),a=lp(),o=6;function s(e){return(e===3?d:e===4?f:e===5?p:m)(r,i,n,a)}function c(){return 0}function l(){return 0}function u(){return 0}function d(e,t,n,r){function i(i,a,o){var s=n(i[0],i[0]),c=r(s,a[0]),l=r(s,o[0]),u=n(a[0],a[0]),d=r(u,i[0]),f=r(u,o[0]),p=n(o[0],o[0]),m=r(p,i[0]),h=t(e(t(r(p,a[0]),f),t(d,c)),t(m,l));return h[h.length-1]}return i}function f(e,t,n,r){function i(i,a,o,s){var c=e(n(i[0],i[0]),n(i[1],i[1])),l=r(c,a[0]),u=r(c,o[0]),d=r(c,s[0]),f=e(n(a[0],a[0]),n(a[1],a[1])),p=r(f,i[0]),m=r(f,o[0]),h=r(f,s[0]),g=e(n(o[0],o[0]),n(o[1],o[1])),_=r(g,i[0]),v=r(g,a[0]),y=r(g,s[0]),b=e(n(s[0],s[0]),n(s[1],s[1])),x=r(b,i[0]),S=r(b,a[0]),C=r(b,o[0]),w=t(e(e(r(t(C,y),a[1]),e(r(t(S,h),-o[1]),r(t(v,m),s[1]))),e(r(t(S,h),i[1]),e(r(t(x,d),-a[1]),r(t(p,l),s[1])))),e(e(r(t(C,y),i[1]),e(r(t(x,d),-o[1]),r(t(_,u),s[1]))),e(r(t(v,m),i[1]),e(r(t(_,u),-a[1]),r(t(p,l),o[1])))));return w[w.length-1]}return i}function p(e,t,n,r){function i(i,a,o,s,c){var l=e(n(i[0],i[0]),e(n(i[1],i[1]),n(i[2],i[2]))),u=r(l,a[0]),d=r(l,o[0]),f=r(l,s[0]),p=r(l,c[0]),m=e(n(a[0],a[0]),e(n(a[1],a[1]),n(a[2],a[2]))),h=r(m,i[0]),g=r(m,o[0]),_=r(m,s[0]),v=r(m,c[0]),y=e(n(o[0],o[0]),e(n(o[1],o[1]),n(o[2],o[2]))),b=r(y,i[0]),x=r(y,a[0]),S=r(y,s[0]),C=r(y,c[0]),w=e(n(s[0],s[0]),e(n(s[1],s[1]),n(s[2],s[2]))),T=r(w,i[0]),E=r(w,a[0]),D=r(w,o[0]),O=r(w,c[0]),k=e(n(c[0],c[0]),e(n(c[1],c[1]),n(c[2],c[2]))),A=r(k,i[0]),j=r(k,a[0]),M=r(k,o[0]),N=r(k,s[0]),ee=t(e(e(e(r(e(r(t(N,O),o[1]),e(r(t(M,C),-s[1]),r(t(D,S),c[1]))),a[2]),e(r(e(r(t(N,O),a[1]),e(r(t(j,v),-s[1]),r(t(E,_),c[1]))),-o[2]),r(e(r(t(M,C),a[1]),e(r(t(j,v),-o[1]),r(t(x,g),c[1]))),s[2]))),e(r(e(r(t(D,S),a[1]),e(r(t(E,_),-o[1]),r(t(x,g),s[1]))),-c[2]),e(r(e(r(t(N,O),a[1]),e(r(t(j,v),-s[1]),r(t(E,_),c[1]))),i[2]),r(e(r(t(N,O),i[1]),e(r(t(A,p),-s[1]),r(t(T,f),c[1]))),-a[2])))),e(e(r(e(r(t(j,v),i[1]),e(r(t(A,p),-a[1]),r(t(h,u),c[1]))),s[2]),e(r(e(r(t(E,_),i[1]),e(r(t(T,f),-a[1]),r(t(h,u),s[1]))),-c[2]),r(e(r(t(D,S),a[1]),e(r(t(E,_),-o[1]),r(t(x,g),s[1]))),i[2]))),e(r(e(r(t(D,S),i[1]),e(r(t(T,f),-o[1]),r(t(b,d),s[1]))),-a[2]),e(r(e(r(t(E,_),i[1]),e(r(t(T,f),-a[1]),r(t(h,u),s[1]))),o[2]),r(e(r(t(x,g),i[1]),e(r(t(b,d),-a[1]),r(t(h,u),o[1]))),-s[2]))))),e(e(e(r(e(r(t(N,O),o[1]),e(r(t(M,C),-s[1]),r(t(D,S),c[1]))),i[2]),r(e(r(t(N,O),i[1]),e(r(t(A,p),-s[1]),r(t(T,f),c[1]))),-o[2])),e(r(e(r(t(M,C),i[1]),e(r(t(A,p),-o[1]),r(t(b,d),c[1]))),s[2]),r(e(r(t(D,S),i[1]),e(r(t(T,f),-o[1]),r(t(b,d),s[1]))),-c[2]))),e(e(r(e(r(t(M,C),a[1]),e(r(t(j,v),-o[1]),r(t(x,g),c[1]))),i[2]),r(e(r(t(M,C),i[1]),e(r(t(A,p),-o[1]),r(t(b,d),c[1]))),-a[2])),e(r(e(r(t(j,v),i[1]),e(r(t(A,p),-a[1]),r(t(h,u),c[1]))),o[2]),r(e(r(t(x,g),i[1]),e(r(t(b,d),-a[1]),r(t(h,u),o[1]))),-c[2])))));return ee[ee.length-1]}return i}function m(e,t,n,r){function i(i,a,o,s,c,l){var u=e(e(n(i[0],i[0]),n(i[1],i[1])),e(n(i[2],i[2]),n(i[3],i[3]))),d=r(u,a[0]),f=r(u,o[0]),p=r(u,s[0]),m=r(u,c[0]),h=r(u,l[0]),g=e(e(n(a[0],a[0]),n(a[1],a[1])),e(n(a[2],a[2]),n(a[3],a[3]))),_=r(g,i[0]),v=r(g,o[0]),y=r(g,s[0]),b=r(g,c[0]),x=r(g,l[0]),S=e(e(n(o[0],o[0]),n(o[1],o[1])),e(n(o[2],o[2]),n(o[3],o[3]))),C=r(S,i[0]),w=r(S,a[0]),T=r(S,s[0]),E=r(S,c[0]),D=r(S,l[0]),O=e(e(n(s[0],s[0]),n(s[1],s[1])),e(n(s[2],s[2]),n(s[3],s[3]))),k=r(O,i[0]),A=r(O,a[0]),j=r(O,o[0]),M=r(O,c[0]),N=r(O,l[0]),ee=e(e(n(c[0],c[0]),n(c[1],c[1])),e(n(c[2],c[2]),n(c[3],c[3]))),P=r(ee,i[0]),F=r(ee,a[0]),I=r(ee,o[0]),L=r(ee,s[0]),R=r(ee,l[0]),te=e(e(n(l[0],l[0]),n(l[1],l[1])),e(n(l[2],l[2]),n(l[3],l[3]))),z=r(te,i[0]),B=r(te,a[0]),V=r(te,o[0]),H=r(te,s[0]),U=r(te,c[0]),ne=t(e(e(e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),o[2]),r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),-s[2])),e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),c[2]),r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),-l[2]))),a[3]),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-s[2])),e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),c[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-l[2]))),-o[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),c[2]),r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),-l[2]))),s[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),a[2]),r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-l[2]))),-c[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),a[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-o[2])),e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-c[2]))),l[3])),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-s[2])),e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),c[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-l[2]))),i[3]),r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-s[2])),e(r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),c[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-l[2]))),-a[3])))),e(e(e(r(e(e(r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),c[2]),r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),-l[2]))),s[3]),r(e(e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-l[2]))),-c[3])),e(r(e(e(r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-c[2]))),l[3]),r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),a[2]),r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-l[2]))),i[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-l[2]))),-a[3]),r(e(e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-l[2]))),o[3])),e(r(e(e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),i[2]),r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-l[2]))),-s[3]),r(e(e(r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),i[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-a[2])),e(r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-s[2]))),l[3]))))),e(e(e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),o[2]),r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),-s[2])),e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),c[2]),r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),-l[2]))),i[3]),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-s[2])),e(r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),c[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-l[2]))),-o[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),c[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-l[2]))),s[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-l[2]))),-c[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-o[2])),e(r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-c[2]))),l[3])),e(r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),c[2]),r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),-l[2]))),i[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),c[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-l[2]))),-a[3])))),e(e(e(r(e(e(r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),c[2]),r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),-l[2]))),o[3]),r(e(e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),i[2]),r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-l[2]))),-c[3])),e(r(e(e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),i[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-c[2]))),l[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),a[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-o[2])),e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-c[2]))),i[3]))),e(e(r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-o[2])),e(r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-c[2]))),-a[3]),r(e(e(r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-c[2]))),o[3])),e(r(e(e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),i[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-c[2]))),-s[3]),r(e(e(r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),i[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-a[2])),e(r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-s[2]))),c[3]))))));return ne[ne.length-1]}return i}var h=[c,l,u];function g(e){var t=h[e.length];return t||=h[e.length]=s(e.length),t.apply(void 0,e)}function _(e,t,n,r,i,a,o,s){function c(t,n,c,l,u,d){switch(arguments.length){case 0:case 1:return 0;case 2:return r(t,n);case 3:return i(t,n,c);case 4:return a(t,n,c,l);case 5:return o(t,n,c,l,u);case 6:return s(t,n,c,l,u,d)}for(var f=Array(arguments.length),p=0;p<arguments.length;++p)f[p]=arguments[p];return e(f)}return c}function v(){for(;h.length<=o;)h.push(s(h.length));t.exports=_.apply(void 0,[g].concat(h));for(var e=0;e<=o;++e)t.exports[e]=h[e]}v()}}),hp=ip({"node_modules/cdt2d/lib/delaunay.js"(e,t){"use strict";var n=mp()[4];ap(),t.exports=i;function r(e,t,r,i,a,o){var s=t.opposite(i,a);if(!(s<0)){if(a<i){var c=i;i=a,a=c,c=o,o=s,s=c}t.isConstraint(i,a)||n(e[i],e[a],e[o],e[s])<0&&r.push(i,a)}}function i(e,t){for(var i=[],a=e.length,o=t.stars,s=0;s<a;++s)for(var c=o[s],l=1;l<c.length;l+=2){var u=c[l];if(!(u<s)&&!t.isConstraint(s,u)){for(var d=c[l-1],f=-1,p=1;p<c.length;p+=2)if(c[p-1]===u){f=c[p];break}f<0||n(e[s],e[u],e[d],e[f])<0&&i.push(s,u)}}for(;i.length>0;){for(var u=i.pop(),s=i.pop(),d=-1,f=-1,c=o[s],m=1;m<c.length;m+=2){var h=c[m-1],g=c[m];h===u?f=g:g===u&&(d=h)}d<0||f<0||n(e[s],e[u],e[d],e[f])>=0||(t.flip(s,u),r(e,t,i,d,s,f),r(e,t,i,s,f,d),r(e,t,i,f,u,d),r(e,t,i,u,d,f))}}}}),gp=ip({"node_modules/cdt2d/lib/filter.js"(e,t){"use strict";var n=ap();t.exports=c;function r(e,t,n,r,i,a,o){this.cells=e,this.neighbor=t,this.flags=r,this.constraint=n,this.active=i,this.next=a,this.boundary=o}var i=r.prototype;function a(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}i.locate=(function(){var e=[0,0,0];return function(t,r,i){var o=t,s=r,c=i;return r<i?r<t&&(o=r,s=i,c=t):i<t&&(o=i,s=t,c=r),o<0?-1:(e[0]=o,e[1]=s,e[2]=c,n.eq(this.cells,e,a))}})();function o(e,t){for(var n=e.cells(),i=n.length,o=0;o<i;++o){var s=n[o],c=s[0],l=s[1],u=s[2];l<u?l<c&&(s[0]=l,s[1]=u,s[2]=c):u<c&&(s[0]=u,s[1]=c,s[2]=l)}n.sort(a);for(var d=Array(i),o=0;o<d.length;++o)d[o]=0;var f=[],p=[],m=Array(3*i),h=Array(3*i),g=null;t&&(g=[]);for(var _=new r(n,m,h,d,f,p,g),o=0;o<i;++o)for(var s=n[o],v=0;v<3;++v){var c=s[v],l=s[(v+1)%3],y=m[3*o+v]=_.locate(l,c,e.opposite(l,c)),b=h[3*o+v]=e.isConstraint(c,l);y<0&&(b?p.push(o):(f.push(o),d[o]=1),t&&g.push([l,c,-1]))}return _}function s(e,t,n){for(var r=0,i=0;i<e.length;++i)t[i]===n&&(e[r++]=e[i]);return e.length=r,e}function c(e,t,n){var r=o(e,n);if(t===0)return n?r.cells.concat(r.boundary):r.cells;for(var i=1,a=r.active,c=r.next,l=r.flags,u=r.cells,d=r.constraint,f=r.neighbor;a.length>0||c.length>0;){for(;a.length>0;){var p=a.pop();if(l[p]!==-i){l[p]=i,u[p];for(var m=0;m<3;++m){var h=f[3*p+m];h>=0&&l[h]===0&&(d[3*p+m]?c.push(h):(a.push(h),l[h]=i))}}}var g=c;c=a,a=g,c.length=0,i=-i}var _=s(u,l,t);return n?_.concat(r.boundary):_}}}),_p=ip({"node_modules/cdt2d/cdt2d.js"(e,t){var n=fp(),r=pp(),i=hp(),a=gp();t.exports=u;function o(e){return[Math.min(e[0],e[1]),Math.max(e[0],e[1])]}function s(e,t){return e[0]-t[0]||e[1]-t[1]}function c(e){return e.map(o).sort(s)}function l(e,t,n){return t in e?e[t]:n}function u(e,t,o){Array.isArray(t)?(o||={},t||=[]):(o=t||{},t=[]);var s=!!l(o,`delaunay`,!0),u=!!l(o,`interior`,!0),d=!!l(o,`exterior`,!0),f=!!l(o,`infinity`,!1);if(!u&&!d||e.length===0)return[];var p=n(e,t);if(s||u!==d||f){for(var m=r(e.length,c(t)),h=0;h<p.length;++h){var g=p[h];m.addTriangle(g[0],g[1],g[2])}return s&&i(e,m),d?u?f?a(m,0,f):m.cells():a(m,1,f):a(m,-1)}return p}}})(),vp=class{constructor(e){this.createFn=e,this._pool=[],this._index=0}getInstance(){return this._index>=this._pool.length&&this._pool.push(this.createFn()),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}},yp=1e-16,bp=1e-16,xp=new J,Sp=new J,Cp=new vp(()=>({param:0,index:0})),wp=new vp(()=>new J);function Tp(e,t,n,r){Cp.clear(),t.length=0,n.length=0;for(let t=0,n=e.length;t<n;t++){let n=e[t];c(n.start),c(n.end)}for(let t=0,n=e.length;t<n;t++){let i=e[t];for(let a=t+1;a<n;a++){let t=e[a];i.distanceSqToLine3(t,xp,Sp)<yp*r&&c(Sp)}}let i=[];for(let a=0,o=e.length;a<o;a++){i.length=0;let o=e[a];for(let e=0,n=t.length;e<n;e++){let n=t[e],a=o.closestPointToPointParameter(n,!0);if(o.at(a,xp),n.distanceToSquared(xp)<yp*r){let t=Cp.getInstance();t.param=a,t.index=e,i.push(t)}}i.sort(s);for(let e=0,t=i.length-1;e<t;e++){let t=i[e].index,r=i[e+1].index;t!==r&&n.push([t,r])}}let a=new Set,o=0;for(let e=0,t=n.length;e<t;e++){let t=n[e],r=Math.min(t[0],t[1]),i=Math.max(t[0],t[1]),s=r+`,`+i;a.has(s)||(a.add(s),n[o++]=t)}n.length=o;function s(e,t){return e.param-t.param}function c(e){for(let n=0;n<t.length;n++){let i=t[n];if(e===i||e.distanceToSquared(i)<bp*r)return n}return t.push(wp.getInstance().copy(e)),t.length-1}}var Ep=class{constructor(){this.trianglePool=new vp(()=>new Xu),this.linePool=new vp(()=>new ys),this.triangles=[],this.triangleIndices=[],this.constrainedEdges=[],this.triangleConnectivity=[],this.normal=new J,this.projOrigin=new J,this.projU=new J,this.projV=new J,this.baseTri=new Xu,this.baseIndices=[,,,]}initialize(e,t=null,n=null,r=null){this.reset();let{normal:i,baseTri:a,projU:o,projV:s,projOrigin:c,constrainedEdges:l,linePool:u,baseIndices:d}=this;e.getNormal(i),a.copy(e),a.update(),d[0]=t,d[1]=n,d[2]=r,l.length=0;let f=u.getInstance();f.start.copy(a.a),f.end.copy(a.b);let p=u.getInstance();p.start.copy(a.b),p.end.copy(a.c);let m=u.getInstance();m.start.copy(a.c),m.end.copy(a.a),l.push(f,p,m),c.copy(a.a),o.subVectors(a.b,a.a).normalize(),s.crossVectors(i,o).normalize()}addConstraintEdge(e){let{constrainedEdges:t,linePool:n}=this,r=n.getInstance().copy(e);t.push(r)}_to2D(e,t){let{projOrigin:n,projU:r,projV:i}=this;return xp.subVectors(e,n),t.set(xp.dot(r),xp.dot(i),0)}_from2D(e,t,n){let{projOrigin:r,projU:i,projV:a}=this;return n.copy(r).addScaledVector(i,e).addScaledVector(a,t),n}triangulate(){let{triangles:e,trianglePool:t,triangleConnectivity:n,triangleIndices:r,linePool:i,baseTri:a,constrainedEdges:o,baseIndices:s}=this;e.length=0,t.clear();let c=[];for(let e=0,t=o.length;e<t;e++){let t=o[e],n=i.getInstance();this._to2D(t.start,n.start),this._to2D(t.end,n.end),c.push(n)}let l=0;for(let e=0;e<3;e++){let t=this._to2D(a.points[e],xp);l=Math.max(l,Math.abs(t.x),Math.abs(t.y))}let u=[],d=[];Tp(c,u,d,l);let f=[];for(let e=0,t=u.length;e<t;e++){let t=u[e];f.push([t.x,t.y])}let p=_p(f,d,{exterior:!1}),m=new Map;for(let e=0,t=d.length;e<t;e++){let t=d[e];m.set(`${t[0]}_${t[1]}`,-1),m.set(`${t[1]}_${t[0]}`,-1)}let h=`${s[0]}_${s[1]}_${s[2]}_`;for(let i=0,a=p.length;i<a;i++){let a=p[i],[o,c,l]=a,u=t.getInstance();this._from2D(f[o][0],f[o][1],u.a),this._from2D(f[c][0],f[c][1],u.b),this._from2D(f[l][0],f[l][1],u.c),e.push(u);let d=[];n.push(d);let g=[];r.push(g);for(let e=0;e<3;e++){let t=a[e];g.push(t<3?s[t]:h+t);let r=a[(e+1)%3],o=`${t}_${r}`;if(m.has(o)){let e=m.get(o);e!==-1&&(d.push(e),n[e].push(i))}else{let e=`${r}_${t}`;m.set(e,i)}}}}reset(){this.trianglePool.clear(),this.linePool.clear(),this.triangles.length=0,this.triangleIndices.length=0,this.triangleConnectivity.length=0,this.constrainedEdges.length=0}},Dp=1e-14,Op=new J,kp=new J,Ap=new J;function jp(e,t=Dp){Op.subVectors(e.b,e.a),kp.subVectors(e.c,e.a),Ap.subVectors(e.b,e.c);let n=Op.angleTo(kp),r=Op.angleTo(Ap),i=Math.PI-n-r;return Math.abs(n)<t||Math.abs(r)<t||Math.abs(i)<t||e.a.distanceToSquared(e.b)<t||e.a.distanceToSquared(e.c)<t||e.b.distanceToSquared(e.c)<t}var Mp=1e-10,Np=1e-10,Pp=new ys,Fp=new ys,Ip=new J,Lp=new J,Rp=new J,zp=new ci,Bp=new Xu,Vp=class{constructor(){this.trianglePool=new vp(()=>new $n),this.triangles=[],this.normal=new J}initialize(e){this.reset();let{triangles:t,trianglePool:n,normal:r}=this;if(Array.isArray(e))for(let i=0,a=e.length;i<a;i++){let a=e[i];if(i===0)a.getNormal(r);else if(Math.abs(1-a.getNormal(Ip).dot(r))>Mp)throw Error(`Triangle Splitter: Cannot initialize with triangles that have different normals.`);let o=n.getInstance();o.copy(a),t.push(o)}else{e.getNormal(r);let i=n.getInstance();i.copy(e),t.push(i)}}splitByTriangle(e,t){let{triangles:n}=this;if(t){for(let e=0,t=n.length;e<t;e++){let t=n[e];t.coplanarCount=0}let t=[e.a,e.b,e.c];for(let n=0;n<3;n++){let r=(n+1)%3,i=t[n],a=t[r];e.getNormal(Lp).normalize(),Ip.subVectors(a,i).normalize(),Rp.crossVectors(Lp,Ip),zp.setFromNormalAndCoplanarPoint(Rp,i),this.splitByPlane(zp,e)}}else e.getPlane(zp),this.splitByPlane(zp,e)}splitByPlane(e,t){let{triangles:n,trianglePool:r}=this;Bp.copy(t),Bp.needsUpdate=!0;for(let t=0,i=n.length;t<i;t++){let a=n[t];if(!Bp.intersectsTriangle(a,Pp,!0))continue;let{a:o,b:s,c}=a,l=0,u=-1,d=!1,f=[],p=[],m=[o,s,c];for(let t=0;t<3;t++){let n=(t+1)%3;Pp.start.copy(m[t]),Pp.end.copy(m[n]);let r=e.distanceToPoint(Pp.start),i=e.distanceToPoint(Pp.end);if(Math.abs(r)<Np&&Math.abs(i)<Np){d=!0;break}if(r>0?f.push(t):p.push(t),Math.abs(r)<Np)continue;let a=!!e.intersectLine(Pp,Ip);!a&&Math.abs(i)<Np&&(Ip.copy(Pp.end),a=!0),a&&!(Ip.distanceTo(Pp.start)<Mp)&&(Ip.distanceTo(Pp.end)<Mp&&(u=t),l===0?Fp.start.copy(Ip):Fp.end.copy(Ip),l++)}if(!d&&l===2&&Fp.distance()>Np){if(u!==-1){u=(u+1)%3;let e=0;e===u&&(e=(e+1)%3);let o=e+1;o===u&&(o=(o+1)%3);let s=r.getInstance();s.a.copy(m[o]),s.b.copy(Fp.end),s.c.copy(Fp.start),jp(s)||n.push(s),a.a.copy(m[e]),a.b.copy(Fp.start),a.c.copy(Fp.end),jp(a)&&(n.splice(t,1),t--,i--)}else{let e=f.length>=2?p[0]:f[0];if(e===0){let e=Fp.start;Fp.start=Fp.end,Fp.end=e}let o=(e+1)%3,s=(e+2)%3,c=r.getInstance(),l=r.getInstance();m[o].distanceToSquared(Fp.start)<m[s].distanceToSquared(Fp.end)?(c.a.copy(m[o]),c.b.copy(Fp.start),c.c.copy(Fp.end),l.a.copy(m[o]),l.b.copy(m[s]),l.c.copy(Fp.start)):(c.a.copy(m[s]),c.b.copy(Fp.start),c.c.copy(Fp.end),l.a.copy(m[o]),l.b.copy(m[s]),l.c.copy(Fp.end)),a.a.copy(m[e]),a.b.copy(Fp.end),a.c.copy(Fp.start),jp(c)||n.push(c),jp(l)||n.push(l),jp(a)&&(n.splice(t,1),t--,i--)}}else l===3&&console.warn(`TriangleClipper: Coplanar clip not handled`)}}reset(){this.triangles.length=0,this.trianglePool.clear()}},Hp=class{constructor(){this.coplanarSet=new Map,this.intersectionSet=new Map,this.edgeSet=new Map,this.ids=[]}add(e,t,n=!1){let{intersectionSet:r,coplanarSet:i,ids:a}=this;r.has(e)||(r.set(e,[]),a.push(e)),r.get(e).push(t),n&&(i.has(e)||i.set(e,new Set),i.get(e).add(t))}addIntersectionEdge(e,t){let{edgeSet:n}=this;n.has(e)||n.set(e,new Set),n.get(e).add(t)}getIntersectionEdges(e){return this.edgeSet.get(e)||null}},Up=1e-10,Wp=1e-15,Gp=1e-10,Kp=1e-10,qp=new ys,Jp=new ys,Yp=new J,Xp=new J,Zp=new J,Qp=new ci,$p=new J,em=new J;function tm(e,t){e.getNormal($p),t.getNormal(em);let n=$p.dot(em);if(Math.abs(1-Math.abs(n))>=Gp)return!1;let r=$p.dot(e.a),i=$p.dot(t.a);return Math.abs(r-i)<Kp}function nm(e,t,n,r){let i=0,a=1;e.delta(Yp);let o=[t.a,t.b,t.c];for(let t=0;t<3;t++){let r=o[t],s=o[(t+1)%3];Xp.subVectors(s,r),Zp.crossVectors(n,Xp),Qp.setFromNormalAndCoplanarPoint(Zp,r);let c=Qp.distanceToPoint(e.start),l=Qp.normal.dot(Yp);if(Math.abs(l)<Wp){if(c<-1e-10)return null;continue}let u=-c/l;if(l>0?i=Math.max(i,u):a=Math.min(a,u),i>a+Up)return null}return a-i<Up?null:(e.at(i,r.start),e.at(a,r.end),r)}function rm(e,t,n){let r=0;e.getNormal($p),t.getNormal(em);let i=[t.a,t.b,t.c];for(let t=0;t<3;t++){Jp.start.copy(i[t]),Jp.end.copy(i[(t+1)%3]);let a=nm(Jp,e,$p,qp);a!==null&&(r>=n.length&&n.push(new ys),n[r].copy(a),r++)}let a=[e.a,e.b,e.c];for(let e=0;e<3;e++){Jp.start.copy(a[e]),Jp.end.copy(a[(e+1)%3]);let i=nm(Jp,t,em,qp);i!==null&&(r>=n.length&&n.push(new ys),n[r].copy(i),r++)}return r}var im=new Hr,am=new Y,om=new ys,sm=[],cm=new vp(()=>new ys),lm=null;function um(e){lm=e}function dm(e,t,n=null){e.getMidpoint(im.origin),e.getNormal(im.direction),n&&(im.origin.applyMatrix4(n),im.direction.transformDirection(n));let r=t.raycastFirst(im,2);return r&&im.direction.dot(r.face.normal)>0?-1:1}function fm(e,t){let n=new Hp,r=new Hp;return cm.clear(),am.copy(e.matrixWorld).invert().multiply(t.matrixWorld),e.geometry.boundsTree.bvhcast(t.geometry.boundsTree,am,{intersectsTriangles(i,a,o,s){if(!jp(i)&&!jp(a)){let c=(tm(i,a)?rm(i,a,sm):0)>2;if(c||i.intersectsTriangle(a,om,!0)){let l=e.geometry.boundsTree.resolveTriangleIndex(o),u=t.geometry.boundsTree.resolveTriangleIndex(s);if(n.add(l,u,c),r.add(u,l,c),c){let e=rm(i,a,sm);for(let t=0;t<e;t++){let e=cm.getInstance().copy(sm[t]);n.addIntersectionEdge(l,e),r.addIntersectionEdge(u,e)}}else{let e=cm.getInstance().copy(om),t=cm.getInstance().copy(om);n.addIntersectionEdge(l,e),r.addIntersectionEdge(u,t)}lm&&(lm.addEdge(om),lm.addIntersectingTriangles(o,i,s,a))}}return!1}}),{aIntersections:n,bIntersections:r}}function pm(e,t,n=!1){switch(e){case 0:if(t===1||t===2&&!n)return 1;break;case 1:if(n){if(t===-1)return 0}else if(t===1||t===-2)return 1;break;case 2:if(n){if(t===1||t===-2)return 1}else if(t===-1)return 0;break;case 4:if(t===-1)return 0;if(t===1)return 1;break;case 3:if(t===-1||t===2&&!n)return 1;break;case 5:if(!n&&(t===1||t===-2))return 1;break;case 6:if(!n&&(t===-1||t===2))return 1;break;default:throw Error(`Unrecognized CSG operation enum "${e}".`)}return 2}var mm=class{constructor(e){this.triangle=new $n().copy(e),this.intersects={}}addTriangle(e,t){this.intersects[e]=new $n().copy(t)}getIntersectArray(){let e=[],{intersects:t}=this;for(let n in t)e.push(t[n]);return e}},hm=class{constructor(){this.data={}}addTriangleIntersection(e,t,n,r){let{data:i}=this;i[e]||(i[e]=new mm(t)),i[e].addTriangle(n,r)}getTrianglesAsArray(e=null){let{data:t}=this,n=[];if(e!==null)e in t&&n.push(t[e].triangle);else for(let e in t)n.push(t[e].triangle);return n}getTriangleIndices(){return Object.keys(this.data).map(e=>parseInt(e))}getIntersectionIndices(e){let{data:t}=this;return t[e]?Object.keys(t[e].intersects).map(e=>parseInt(e)):[]}getIntersectionsAsArray(e=null,t=null){let{data:n}=this,r=new Set,i=[],a=e=>{if(n[e]){if(t!==null)n[e].intersects[t]&&i.push(n[e].intersects[t]);else{let t=n[e].intersects;for(let e in t)r.has(e)||(r.add(e),i.push(t[e]))}}};if(e!==null)a(e);else for(let e in n)a(e);return i}reset(){this.data={}}},gm=class{constructor(){this.enabled=!1,this.triangleIntersectsA=new hm,this.triangleIntersectsB=new hm,this.intersectionEdges=[]}addIntersectingTriangles(e,t,n,r){let{triangleIntersectsA:i,triangleIntersectsB:a}=this;i.addTriangleIntersection(e,t,n,r),a.addTriangleIntersection(n,r,e,t)}addEdge(e){this.intersectionEdges.push(e.clone())}reset(){this.triangleIntersectsA.reset(),this.triangleIntersectsB.reset(),this.intersectionEdges=[]}init(){this.enabled&&(this.reset(),um(this))}complete(){this.enabled&&um(null)}},_m=new Y,vm=new Y,ym=new Y,bm=new Ft,xm=new $n,Sm=new $n,Cm=new $n,wm=new $n,Tm=[],Em=[],Dm=new Set,Om=new J,km=new J,Am=new vp(()=>new $n),jm=new J,Mm=[];function Nm(e,t,n,r,i,a={}){let{useGroups:o=!0}=a,{aIntersections:s,bIntersections:c}=fm(e,t),l=[],u;return u=o?0:-1,Fm(e,t,s,n,!1,i,u),Pm(e,t,s,n,!1,r,i,u),n.findIndex(e=>e!==6&&e!==5)!==-1&&(i.forEach(e=>e.clearIndexMap()),u=o?e.geometry.groups.length||1:-1,Fm(t,e,c,n,!0,i,u),Pm(t,e,c,n,!0,r,i,u)),i.forEach(e=>e.clearIndexMap()),Tm.length=0,{groups:l,materials:null}}function Pm(e,t,n,r,i,a,o,s=0){_m.copy(t.matrixWorld).invert().multiply(e.matrixWorld),vm.copy(_m).invert(),i?ym.copy(_m):ym.identity();let c=ym.determinant()<0;bm.getNormalMatrix(ym).multiplyScalar(c?-1:1);let l=e.geometry.groupIndices,u=e.geometry.index,d=e.geometry.attributes.position,f=t.geometry.boundsTree,p=t.geometry.index,m=t.geometry.attributes.position,h=n.ids;for(let t=0,g=h.length;t<g;t++){let g=h[t],_=s===-1?0:l[g]+s,v=3*g,y=v+0,b=v+1,x=v+2;u&&(y=u.getX(y),b=u.getX(b),x=u.getX(x)),xm.a.fromBufferAttribute(d,y),xm.b.fromBufferAttribute(d,b),xm.c.fromBufferAttribute(d,x),i&&(xm.a.applyMatrix4(_m),xm.b.applyMatrix4(_m),xm.c.applyMatrix4(_m)),a.reset(),a.initialize(xm,y,b,x),Mm.length=0,Am.clear(),xm.getNormal(km);let S=n.coplanarSet.get(g);if(S)for(let e of S){let t=3*e,n=t+0,r=t+1,a=t+2;p&&(n=p.getX(n),r=p.getX(r),a=p.getX(a));let o=Am.getInstance();o.a.fromBufferAttribute(m,n),o.b.fromBufferAttribute(m,r),o.c.fromBufferAttribute(m,a),i||(o.a.applyMatrix4(vm),o.b.applyMatrix4(vm),o.c.applyMatrix4(vm)),Mm.push(o)}if(a.addConstraintEdge){let e=n.getIntersectionEdges(g);if(e)for(let t of e)a.addConstraintEdge(t);a.triangulate()}else{let e=n.intersectionSet.get(g);for(let t=0,n=e.length;t<n;t++){let n=e[t],r=S&&S.has(n),o=3*n,s=o+0,c=o+1,l=o+2;p&&(s=p.getX(s),c=p.getX(c),l=p.getX(l)),Sm.a.fromBufferAttribute(m,s),Sm.b.fromBufferAttribute(m,c),Sm.c.fromBufferAttribute(m,l),i||(Sm.a.applyMatrix4(vm),Sm.b.applyMatrix4(vm),Sm.c.applyMatrix4(vm)),a.splitByTriangle(Sm,r)}}let{triangles:C,triangleIndices:w=[],triangleConnectivity:T=[]}=a;for(let t=0,n=o.length;t<n;t++)o[t].initInterpolatedAttributeData(e.geometry,ym,bm,y,b,x);Dm.clear();for(let e=0,t=C.length;e<t;e++){if(Dm.has(e))continue;let t=C[e],n=i?null:_m,a=null;t.getMidpoint(Om);for(let e=0,t=Mm.length;e<t;e++){let t=Mm[e];if(t.containsPoint(Om)){t.getNormal(jm),a=km.dot(jm)>0?2:-2;break}}a===null&&(a=dm(t,f,n)),Tm.length=0,Em.length=0;for(let e=0,t=r.length;e<t;e++){let t=pm(r[e],a,i);t!==2&&(Tm.push(t),Em.push(o[e]))}if(Em.length!==0){let t=[e];for(;t.length>0;){let e=t.pop();if(Dm.has(e))continue;Dm.add(e);let n=w[e],r=null,i=null,a=null;n&&(r=n[0],i=n[1],a=n[2]);let o=C[e];xm.getBarycoord(o.a,wm.a),xm.getBarycoord(o.b,wm.b),xm.getBarycoord(o.c,wm.c);for(let e=0,t=Em.length;e<t;e++){let t=Em[e],n=c!==(Tm[e]===0);t.appendInterpolatedAttributeData(_,wm.a,r,n),n?(t.appendInterpolatedAttributeData(_,wm.c,a,n),t.appendInterpolatedAttributeData(_,wm.b,i,n)):(t.appendInterpolatedAttributeData(_,wm.b,i,n),t.appendInterpolatedAttributeData(_,wm.c,a,n))}}}}}return h.length}function Fm(e,t,n,r,i,a,o=0){_m.copy(t.matrixWorld).invert().multiply(e.matrixWorld),i?ym.copy(_m):ym.identity();let s=ym.determinant()<0;bm.getNormalMatrix(ym).multiplyScalar(s?-1:1);let c=t.geometry.boundsTree,l=e.geometry.groupIndices,u=e.geometry.index,d=e.geometry.attributes.position,f=[],p=e.geometry.halfEdges,m=new Set(n.ids),h=If(e.geometry);for(let t=0;t<h&&m.size!==h;t++){if(m.has(t))continue;m.add(t),f.push(t);let n=3*t,h=n+0,g=n+1,_=n+2;u&&(h=u.getX(h),g=u.getX(g),_=u.getX(_)),Cm.a.fromBufferAttribute(d,h),Cm.b.fromBufferAttribute(d,g),Cm.c.fromBufferAttribute(d,_),i&&(Cm.a.applyMatrix4(_m),Cm.b.applyMatrix4(_m),Cm.c.applyMatrix4(_m));let v=dm(Cm,c,i?null:_m);Tm.length=0,Em.length=0;for(let e=0,t=r.length;e<t;e++){let t=pm(r[e],v,i);t!==2&&(Tm.push(t),Em.push(a[e]))}for(;f.length>0;){let t=f.pop();for(let e=0;e<3;e++){let n=p.getSiblingTriangleIndex(t,e);n!==-1&&!m.has(n)&&(f.push(n),m.add(n))}if(Em.length!==0){let n=3*t,r=n+0,i=n+1,a=n+2;u&&(r=u.getX(r),i=u.getX(i),a=u.getX(a));let c=o===-1?0:l[t]+o;if(Cm.a.fromBufferAttribute(d,r),Cm.b.fromBufferAttribute(d,i),Cm.c.fromBufferAttribute(d,a),!jp(Cm))for(let t=0,n=Em.length;t<n;t++){let n=Em[t],o=Tm[t]===0!==s;n.appendIndexFromGeometry(e.geometry,ym,bm,c,r,o),o?(n.appendIndexFromGeometry(e.geometry,ym,bm,c,a,o),n.appendIndexFromGeometry(e.geometry,ym,bm,c,i,o)):(n.appendIndexFromGeometry(e.geometry,ym,bm,c,i,o),n.appendIndexFromGeometry(e.geometry,ym,bm,c,a,o))}}}}}function Im(e){return e=~~e,e+4-e%4}var Lm=class{constructor(e,t=500){this.expansionFactor=1.5,this.type=e,this.length=0,this.array=null,this.setSize(t)}setType(e){if(e===this.type)return;if(this.length!==0)throw Error(`TypeBackedArray: Cannot change the type while there is used data in the buffer.`);let t=this.array.buffer;this.array=new e(t),this.type=e}setSize(e){if(this.array&&e===this.array.length)return;let t=this.type,n=new t(new(Nf()?SharedArrayBuffer:ArrayBuffer)(Im(e*t.BYTES_PER_ELEMENT)));this.array&&n.set(this.array,0),this.array=n}expand(){let{array:e,expansionFactor:t}=this;this.setSize(e.length*t)}push(...e){let{array:t,length:n}=this;n+e.length>t.length&&(this.expand(),t=this.array);for(let r=0,i=e.length;r<i;r++)t[n+r]=e[r];this.length+=e.length}clear(){this.length=0}},Rm=new J,zm=new J,Bm=new J,Vm=new J,Hm=new Zt,Um=new Zt,Wm=new Zt,Gm=new Zt;function Km(e,t,n,r,i,a=!1,o=!1){return i.set(0,0,0,0).addScaledVector(e,r.x).addScaledVector(t,r.y).addScaledVector(n,r.z),a&&i.normalize(),o&&i.multiplyScalar(-1),i}function qm(e,t,n){switch(t){case 1:n.push(e.x);break;case 2:n.push(e.x,e.y);break;case 3:n.push(e.x,e.y,e.z);break;case 4:n.push(e.x,e.y,e.z,e.w)}}var Jm=class extends Lm{get count(){return this.length/this.itemSize}constructor(...e){super(...e),this.itemSize=1,this.normalized=!1}},Ym=class{constructor(){this.attributeData={},this.groupIndices=[],this.forwardIndexMap=new Map,this.invertedIndexMap=new Map,this.interpolatedFields={}}initFromGeometry(e,t){this.clear();let{attributeData:n}=this,r=e.attributes;for(let e=0,i=t.length;e<i;e++){let i=t[e],a=r[i],o=a.array.constructor;n[i]||(n[i]=new Jm(o)),n[i].setType(o),n[i].itemSize=a.itemSize,n[i].normalized=a.normalized}for(let e in n.attributes)t.includes(e)||n.delete(e)}initInterpolatedAttributeData(e,t,n,r,i,a){let{attributeData:o,interpolatedFields:s}=this,{attributes:c}=e;for(let e in o){let o=c[e];if(!o)throw Error(`CSG Operations: Attribute ${e} not available on geometry.`);let l,u,d;if(e===`position`?(l=zm.fromBufferAttribute(o,r).applyMatrix4(t),u=Bm.fromBufferAttribute(o,i).applyMatrix4(t),d=Vm.fromBufferAttribute(o,a).applyMatrix4(t)):e===`normal`?(l=zm.fromBufferAttribute(o,r).applyNormalMatrix(n),u=Bm.fromBufferAttribute(o,i).applyNormalMatrix(n),d=Vm.fromBufferAttribute(o,a).applyNormalMatrix(n)):e===`tangent`?(l=zm.fromBufferAttribute(o,r).transformDirection(t),u=Bm.fromBufferAttribute(o,i).transformDirection(t),d=Vm.fromBufferAttribute(o,a).transformDirection(t)):(l=Um.fromBufferAttribute(o,r),u=Wm.fromBufferAttribute(o,i),d=Gm.fromBufferAttribute(o,a)),!s[e])s[e]=[l.clone(),u.clone(),d.clone()];else{let t=s[e];t[0].copy(l),t[1].copy(u),t[2].copy(d)}}}appendInterpolatedAttributeData(e,t,n=null,r=!1){let{groupIndices:i,attributeData:a,interpolatedFields:o,forwardIndexMap:s,invertedIndexMap:c}=this;for(;i.length<=e;)i.push(new Jm(Uint32Array));let l=r?c:s,u=i[e];if(n!==null&&l.has(n))u.push(l.get(n));else{l.set(n,a.position.count),u.push(a.position.count);for(let e in o){let n=a[e],i=e===`normal`||e===`tangent`,s=r&&i,c=n.itemSize,[l,u,d]=o[e];Km(l,u,d,t,Hm,i,s),qm(Hm,c,n)}}}appendIndexFromGeometry(e,t,n,r,i,a=!1){let{groupIndices:o,attributeData:s,forwardIndexMap:c,invertedIndexMap:l}=this;for(;o.length<=r;)o.push(new Jm(Uint32Array));let u=a?l:c,d=o[r];if(i!==null&&u.has(i))d.push(u.get(i));else{u.set(i,s.position.count),d.push(s.position.count);let{attributes:r}=e;for(let e in s){let o=s[e],c=r[e];if(!c)throw Error(`CSG Operations: Attribute ${e} not available on geometry.`);let l=c.itemSize;e===`position`?(Rm.fromBufferAttribute(c,i).applyMatrix4(t),o.push(Rm.x,Rm.y,Rm.z)):e===`normal`?(Rm.fromBufferAttribute(c,i).applyNormalMatrix(n),a&&Rm.multiplyScalar(-1),o.push(Rm.x,Rm.y,Rm.z)):e===`tangent`?(Rm.fromBufferAttribute(c,i).transformDirection(t),a&&Rm.multiplyScalar(-1),o.push(Rm.x,Rm.y,Rm.z)):(Hm.fromBufferAttribute(c,i),qm(Hm,l,o))}}}buildGeometry(e,t){let n=!1,{groupIndices:r,attributeData:i}=this,{attributes:a,index:o}=e;for(let t in i){let r=i[t],{type:o,itemSize:s,normalized:c,length:l,count:u}=r,d=r.array.buffer,f=a[t];(!f||f.count<u||f.array.type!==o)&&(f=new vr(new o(l),s,c),e.setAttribute(t,f),n=!0),f.array.set(new o(d,0,l),0),f.needsUpdate=!0}let s=r.reduce((e,t)=>t.count+e,0);(!e.index||o.count<s||o.array.type!==Uint32Array)&&(e.setIndex(new vr(new Uint32Array(s),1)),n=!0),e.clearGroups();let c=0;for(let n=0,i=Math.min(t.length,r.length);n<i;n++){let{index:i,materialIndex:a}=t[n],{count:o}=r[i],s=r[i].array.buffer;o!==0&&(e.index.array.set(new Uint32Array(s,0,o),c),e.addGroup(c,o,a),c+=o)}e.setDrawRange(0,c),e.boundsTree=null,e.boundingBox=null,e.boundingSphere=null,n&&e.dispose()}clearIndexMap(){this.forwardIndexMap.clear(),this.invertedIndexMap.clear()}clear(){let{groupIndices:e,attributeData:t}=this;this.interpolatedFields={};for(let e in t)t[e].clear();e.forEach(e=>{e.clear()}),this.clearIndexMap()}};function Xm(e,t){for(let n in e.attributes)t.includes(n)||(e.deleteAttribute(n),e.dispose());return e}function Zm(e,t){let n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=t[i.materialIndex];n.push({...i,materialIndex:t.indexOf(a)})}return n}function Qm(e,t){let n=[],r=new Map;for(let i=0,a=e.length;i<a;i++){let a=e[i];r.has(a.materialIndex)||(r.set(a.materialIndex,n.length),n.push(t[a.materialIndex])),a.materialIndex=r.get(a.materialIndex)}return n}function $m(e){for(let t=0;t<e.length-1;t++){let n=e[t],r=e[t+1];if(n.materialIndex===r.materialIndex){let i=n.start,a=r.start+r.count;r.start=i,r.count=a-i,e.splice(t,1),t--}}}function eh(e,t){let n=t;return Array.isArray(t)||(n=[],e.forEach(e=>{n[e.materialIndex]=t})),n}var th=class{get useCDTClipping(){return this.triangleSplitter instanceof Ep}set useCDTClipping(e){e!==this.useCDTClipping&&(this.triangleSplitter=e?new Ep:new Vp)}constructor(){this.triangleSplitter=new Vp,this.geometryBuilders=[],this.attributes=[`position`,`uv`,`normal`],this.useGroups=!0,this.consolidateGroups=!0,this.removeUnusedMaterials=!0,this.debug=new gm}getGroupRanges(e){return!this.useGroups||e.groups.length===0?[{start:0,count:1/0,materialIndex:0}]:e.groups.map(e=>({...e}))}evaluate(e,t,n,r=new np){let i=!0;if(Array.isArray(n)||(n=[n]),Array.isArray(r)||(r=[r],i=!1),r.length!==n.length)throw Error(`Evaluator: operations and target array passed as different sizes.`);e.prepareGeometry(),t.prepareGeometry();let{triangleSplitter:a,geometryBuilders:o,attributes:s,useGroups:c,consolidateGroups:l,removeUnusedMaterials:u,debug:d}=this;for(;o.length<r.length;)o.push(new Ym);r.forEach((t,n)=>{o[n].initFromGeometry(e.geometry,s),Xm(t.geometry,s)}),d.init(),Nm(e,t,n,a,o,{useGroups:c}),d.complete();let f=this.getGroupRanges(e.geometry),p=eh(f,e.material),m=this.getGroupRanges(t.geometry),h=eh(m,t.material);m.forEach(e=>e.materialIndex+=p.length);let g=[...p,...h],_=[...f,...m].map((e,t)=>({...e,index:t}));return c?c&&l&&(_=Zm(_,g),_.sort((e,t)=>e.materialIndex-t.materialIndex)):_=[{start:0,count:1/0,index:0,materialIndex:0}],r.forEach((t,n)=>{let r=t.geometry;o[n].buildGeometry(r,_),e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.updateMatrix(),t.matrixWorld.copy(e.matrixWorld),c?(t.material=g,l&&$m(r.groups),u&&(t.material=Qm(r.groups,g))):t.material=g[0]}),i?r:r[0]}evaluateHierarchy(e,t=new np){e.updateMatrixWorld(!0);let n=(e,t)=>{let r=e.children;for(let e=0,i=r.length;e<i;e++){let i=r[e];i.isOperationGroup?n(i,t):t(i)}},r=e=>{let t=e.children,i=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];i=r(n)||i}let a=e.isDirty();if(a&&e.markUpdated(),i&&!e.isOperationGroup){let t;return n(e,n=>{t=t?this.evaluate(t,n,n.operation):this.evaluate(e,n,n.operation)}),e._cachedGeometry=t.geometry,e._cachedMaterials=t.material,!0}return i||a};return r(e),t.geometry=e._cachedGeometry,t.material=e._cachedMaterials,t}reset(){this.triangleSplitter.reset()}};function nh(){return{geometries:new Set,materials:new Set,textures:new Set}}function rh(e){let{material:t}=e;return Array.isArray(t)?t:t?.isMaterial?[t]:[]}function ih(e,t){return e.traverse(e=>{let n=e;n.geometry?.isBufferGeometry&&t.geometries.add(n.geometry);for(let e of rh(n)){t.materials.add(e);for(let n of Object.values(e))n&&n.isTexture&&t.textures.add(n)}}),t}function ah(e,t){for(let n of e.geometries)t.geometries.has(n)||n.dispose();for(let n of e.textures)t.textures.has(n)||n.dispose();for(let n of e.materials)t.materials.has(n)||n.dispose()}function oh(e){ah(ih(e,nh()),nh())}function sh(e,t){let n=ih(t,nh()),r=nh();for(let n of e)n!==t&&ih(n,r);ah(r,n)}function ch(e,t){t&&(e?.remove(t),oh(t))}function lh(e){let t=e.userData;return{...t.background?{background:t.background}:{},warnings:t.warnings??[],logs:t.logs??[]}}var uh=1e-9,dh=34e37;function fh(e,t){return Math.abs(e.x-t.x)<uh&&Math.abs(e.y-t.y)<uh}function ph(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2,curved:!1}}function mh(e){let t=e[0],n=e[e.length-1];return e.length>2&&t!==void 0&&n!==void 0&&fh(t,n)}function hh(e){e.updateWorldMatrix(!0,!1);let t=e.geometry.getAttribute(`position`),n=[];for(let r=0;r<t.count;r++){let i=new J().fromBufferAttribute(t,r).applyMatrix4(e.matrixWorld),a=n[n.length-1];(a===void 0||a.distanceToSquared(i)>uh**2)&&n.push(i)}return n}var gh=`pathValue`;function _h(e){return e.userData[gh]=!0,e}function vh(e){return e.userData[gh]===!0}var yh=new Set([`circle`,`square`,`roundrect`,`polygon`]);function bh(e){if(!vh(e))throw Error("`loft` expects `path` cross-sections, not meshes — pass the path itself rather than a `fill` of it");if(e.isMesh)return tl(e);let t=hh(e);if(t.length<3)throw Error("A `loft` cross-section needs at least three points");return t}var xh=3e4,Sh=8,Ch=12,wh=4,Th=1e-9,Eh=class extends Error{constructor(e){super(e),this.name=`ShapeScriptLimitError`}};function Dh(e){return{...e,color:e.color?.clone(),glow:e.glow?.clone()}}var Oh=200,kh=200;function Ah(e){let t=e.getAttribute(`position`),n=e.getIndex(),r=n?.count??t.count,i=new J,a=new J,o=new J,s=0;for(let e=0;e<r;e+=3)i.fromBufferAttribute(t,n?n.getX(e):e),a.fromBufferAttribute(t,n?n.getX(e+1):e+1),o.fromBufferAttribute(t,n?n.getX(e+2):e+2),s+=i.dot(a.cross(o));return s/6}function jh(e){if(Ah(e)>=0)return e;let t=e.getIndex();if(t){for(let e=0;e<t.count;e+=3){let n=t.getX(e+1);t.setX(e+1,t.getX(e+2)),t.setX(e+2,n)}t.needsUpdate=!0}let n=e.getAttribute(`normal`);if(n){for(let e=0;e<n.count;e++)n.setXYZ(e,-n.getX(e),-n.getY(e),-n.getZ(e));n.needsUpdate=!0}return e}function Mh(e){return Math.max(0,Math.round(Math.log2(Math.max(4,e)))-2)}var Nh=class{options;evaluator;symbols;pathCommandCount=0;detailLevel=32;nodeCount=0;vertexCount=0;startedAt=Date.now();transformStack=[];operandDepth=0;warnings=[];warningSet=new Set;logs=[];background;sceneDepth=0;valueSink=null;retained=[];constructor(e={}){this.options=e,this.symbols=new bc,this.evaluator=new Rc(this.symbols,e.randomSeed),this.symbols.set(`detail`,this.detailLevel),this.evaluator.hooks={shape:e=>this.shapeValue(e),call:(e,t)=>this.callShapeFunction(e,t),retain:e=>this.chargeRetained(e)},this.evaluator.maxLoopIterations=this.maxLoopIterations,this.pushTransform()}convert(e){let t=new An;try{this.addChildren(t,e),t.userData={warnings:this.warnings,logs:this.logs,...this.background?{background:this.background}:{}}}catch(e){throw oh(t),e}finally{this.retained.forEach(e=>e.dispose()),this.retained=[]}return t}get maxNodes(){return this.options.maxNodes??1e5}get maxLoopIterations(){return this.options.maxLoopIterations??1e5}get maxVertices(){return this.options.maxVertices??5e6}get maxDurationMs(){return this.options.maxDurationMs??3e4}chargePathEstimate(e,t,n=1){let r=Math.max(1,e.curves.length)*Math.max(1,t);this.chargeEstimate(r*n)}chargeEstimate(e){if(this.vertexCount+e>this.maxVertices)throw new Eh(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or simplify the path`)}makeMesh(e,t){if(this.vertexCount+=e.getAttribute(`position`)?.count??0,this.vertexCount>this.maxVertices)throw e.dispose(),t.dispose(),new Eh(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or use fewer shapes`);return new ti(e,t)}convertNode(e){if(this.nodeCount+=1,this.nodeCount>this.maxNodes)throw new Eh(`ShapeScript produced more than ${this.maxNodes} objects — reduce the loop counts or the nesting`);if(Date.now()-this.startedAt>this.maxDurationMs)throw new Eh(`ShapeScript took longer than ${this.maxDurationMs}ms to build — simplify the model or use fewer boolean operations`);switch(e.type){case`shape`:return this.convertShape(e);case`csg`:return this.convertCSG(e);case`block`:return this.convertBlock(e);case`for`:return this.convertForLoop(e);case`if`:return this.convertIf(e);case`switch`:return this.convertSwitch(e);case`define`:return this.handleDefine(e),null;case`extrude`:return this.convertExtrude(e);case`loft`:return this.convertLoft(e);case`lathe`:return this.convertLathe(e);case`fill`:return this.convertFill(e);case`hull`:return this.convertHull(e);case`minkowski`:return this.convertMinkowski(e);case`text`:return this.convertText(e);case`group`:return this.convertBlock(e);case`detail`:return this.handleDetail(e),null;case`seed`:return this.evaluator.reseed(this.evaluateNumber(e.value)),null;case`color`:return this.handleColorCommand(e),null;case`material`:return this.handleMaterialCommand(e),null;case`smoothing`:return this.currentTransform().material.smoothing=this.evaluateNumber(e.value),null;case`background`:return this.handleBackground(e.value),null;case`print`:return this.logs.length<Oh&&this.logs.push(Bh(this.evaluator.evaluate(e.value))),null;case`assert`:if(!this.evaluator.evaluateToBoolean(e.value))throw Error(`Assertion failed`);return null;case`ignored`:return this.warn(`\`${e.command}\` is not rendered by this viewer and was skipped`),null;case`expression`:return this.convertExpressionStatement(e);case`mesh`:return this.convertMesh(e);case`rotate`:return this.handleRotateCommand(e),null;case`orientation`:return this.handleOrientationCommand(e),null;case`translate`:return this.handleTranslateCommand(e),null;case`scale`:return this.handleScaleCommand(e),null;case`customShape`:return this.convertCustomShape(e);case`path`:return this.operandDepth>0?this.convertPathProfile(e):this.convertPathLine(e);default:throw Error(`Unsupported command: ${e.type}`)}}convertPathProfile(e){return this.withPathDetail(()=>{let t=this.collectPathPoints(e),n=this.shapeFromPathPoints(t);if(!mh(t))return _h(this.lineFromPath(e,n));this.chargePathEstimate(n,Ch),this.requireEnclosedArea(n,`path`);let r=this.makeMesh(this.placePath(new Qa(n),e),this.createMaterial({properties:{}}));return this.applyCurrentTransform(r),_h(r)})}withPathDetail(e){return this.withShapeOptions({},e)}convertPathLine(e){return this.withPathDetail(()=>this.lineFromPath(e,this.buildPath(e)))}lineFromPath(e,t){let n=this.finitePoints(t.getPoints(Math.max(1,Math.floor(this.detailLevel/4))));if(n.length<2)throw Error("`path` needs at least two points");this.chargeEstimate(n.length),this.vertexCount+=n.length;let r=this.placePath(new Mr().setFromPoints(n),e),i=this.currentTransform().material,a=Math.min(1,Math.max(0,i.alpha*i.opacity)),o=new xi(r,new pi({color:i.color?.clone()??new Ln(.8,.8,.8),opacity:a,transparent:a<1}));return this.applyCurrentTransform(o),o}warn(e){this.warningSet.has(e)||this.warnings.length>=kh||(this.warningSet.add(e),this.warnings.push(e))}handleBackground(e){if(this.sceneDepth>0)throw Error("`background` can only be used at the root of the script");let t=this.evaluator.evaluate(e);if(typeof t==`string`){this.warn(`background image "${t}" is not supported — the scene keeps its default background`);return}this.background=this.requireFiniteColor(zc(t))}inScope(e,t){return this.inFrame(()=>{try{t()}catch(t){throw oh(e),t}return e})}inFrame(e){this.symbols.pushScope(),this.pushTransform(),this.sceneDepth++;try{return e()}finally{this.sceneDepth--,this.popTransform(),this.symbols.popScope()}}addChildren(e,t){for(let n of t){let t=this.convertNode(n);t&&e.add(t)}}convertBlock(e){let t=new An;return this.inScope(t,()=>this.addChildren(t,e.children))}inSymbolScope(e,t){this.symbols.pushScope();try{return t(),e}catch(t){throw oh(e),t}finally{this.symbols.popScope()}}finishMesh(e,t,n=!0,r){let i;try{return i=this.makeMesh(e,this.createMaterial(t,r,e.hasAttribute(`color`))),this.applyExplicitTransforms(i,t.properties,n),this.applyCurrentTransform(i),i}catch(t){throw i?oh(i):e.dispose(),t}}withShapeOptions(e,t){let n=this.detailLevel,r=this.currentTransform().material.smoothing;try{return e.detail!==void 0&&this.handleDetail({type:`detail`,value:e.detail}),e.smoothing!==void 0&&(this.currentTransform().material.smoothing=this.evaluateNumber(e.smoothing)),t()}finally{this.detailLevel=n,this.symbols.set(`detail`,n),this.currentTransform().material.smoothing=r}}convertShape(e){return e.points===void 0?this.withShapeOptions(e.properties,()=>{let t=this.finishMesh(this.createGeometry(e),e,!1);return yh.has(e.primitive)?_h(t):t}):this.placeValue(this.polygonValue(e))}captureValues(e,t){let n=this.valueSink;this.valueSink=e;try{return t()}finally{this.valueSink=n}}placeValue(e){if(this.valueSink)return this.valueSink.push(this.transformedForCapture(e)),null;if(_c(e)&&e.kind===`mesh`)return this.placeMesh(e);if(_c(e)&&e.kind===`polygon`)return this.placePolygons([e]);if(Array.isArray(e)&&e.length>0&&e.every(e=>_c(e)&&(e.kind===`mesh`||e.kind===`polygon`))){let t=e.filter(e=>_c(e)&&e.kind===`mesh`),n=e.filter(e=>_c(e)&&e.kind===`polygon`),r=n.length?Ms(n,n.some(e=>e.colors)):void 0,i=zh([...t.map(e=>e.geometry),...r?[r]:[]]);r?.dispose();let a=n.length===0&&t.every(e=>e.path),o=this.placeMesh({kind:`mesh`,geometry:i,...a?{path:a}:{}});return i.dispose(),o}throw Error("Unused value — a statement that is not a shape does nothing here; use `define` or `print`")}transformedForCapture(e){let t=this.currentTransform().matrix,n=t.equals(new Y);if(Array.isArray(e))return n?e:e.map(e=>this.transformedForCapture(e));if(!Ih(e)||n)return e;if(e.kind===`polygon`)return{...e,points:e.points.map(e=>new J(...e).applyMatrix4(t).toArray())};let r=e.geometry.clone().applyMatrix4(t);try{this.chargeRetained(r)}catch(e){throw r.dispose(),e}return{...e,geometry:r,...e.polygons?{polygons:e.polygons.map(e=>this.transformedForCapture(e))}:{}}}convertExpressionStatement(e){return this.placeValue(this.evaluator.evaluate(e.value))}placeMesh(e){let t=e.geometry.clone(),n=this.makeMesh(t,this.createMaterial({properties:{}},void 0,t.hasAttribute(`color`)));return e.name!==void 0&&(n.name=e.name),e.path&&_h(n),this.applyCurrentTransform(n),n}placePolygons(e){let t=e.some(e=>e.colors!==void 0),n=Ms(e,t);this.chargeEstimate(n.getAttribute(`position`).count);let r=this.makeMesh(n,this.createMaterial({properties:{}},void 0,t));return this.applyCurrentTransform(r),r}chargeRetained(e){let t=e.getAttribute(`position`).count;this.chargeEstimate(t),this.vertexCount+=t,this.retained.push(e)}buildScratch(e,t){let n=new An,r=[],i=this.vertexCount,a=this.retained.length;try{this.captureValues(r,()=>this.inScope(n,()=>{this.currentTransform().matrix.identity(),this.addChildren(n,e),t?.(r)}));let i=this.meshesIn(n),a=i.map(e=>Lh(e).applyMatrix4(e.matrixWorld)),o=i.length===1?i[0]:void 0,s=o?.geometry.userData.polygons,c=o&&s?s.map(e=>({...e,points:e.points.map(e=>new J(...e).applyMatrix4(o.matrixWorld).toArray())})):void 0,l=i.length>0&&i.every(vh);return{captured:r,geometries:a,name:o?.name||void 0,polygons:c,path:l}}finally{oh(n),this.vertexCount=i,this.vertexCount+=this.retained.slice(a).reduce((e,t)=>e+t.getAttribute(`position`).count,0)}}convertMesh(e){let{captured:t,geometries:n}=this.buildScratch(e.children),r=Fh(t).filter(e=>e.kind===`polygon`),i=Fh(t).filter(e=>e.kind===`mesh`),a=r.some(e=>e.colors!==void 0),o=[...r.length?[Ms(r,a)]:[],...n],s=[...o,...i.map(e=>e.geometry)];if(s.length===0)throw Error("`mesh` needs at least one polygon");let c=zh(s);o.forEach(e=>e.dispose()),i.length===0&&n.length===0&&(c.userData={polygons:r});let l=this.makeMesh(c,this.createMaterial({properties:{}},void 0,c.hasAttribute(`color`)));return this.applyCurrentTransform(l),l}polygonValue(e){let t=[],n=[],r=e.properties.color===void 0?void 0:this.evaluateRGBA(e.properties.color),i=r!==void 0,a=e=>{if(++this.pathCommandCount>this.maxLoopIterations)throw new Eh(`ShapeScript polygon exceeds ${this.maxLoopIterations} commands`);switch(e.type){case`define`:this.handleDefine(e);break;case`color`:r=this.evaluateRGBA(e.value),i=!0;break;case`point`:case`curve`:t.push(this.pointCoordinates(e)),n.push(r??[.8,.8,.8,1]);break;case`for`:this.runPathLoop(e,a);break;case`detail`:break;default:throw Error(`\`${e.type}\` is not supported inside a polygon — list its points`)}};this.symbols.pushScope();try{for(let t of e.points??[])a(t)}finally{this.symbols.popScope()}if(t.length<3)throw Error("`polygon` needs at least three points");let{position:o,orientation:s,rotation:c,size:l}=e.properties;if(o||s||c||l){let n=new Y;this.applyPlacement(n,e.properties);for(let e of t)new J(...e).applyMatrix4(n).toArray(e)}return{kind:`polygon`,points:t,...i?{colors:n}:{}}}pointCoordinates(e){let t=typeof e.x==`number`?e.x:this.evaluator.evaluate(e.x),[n=0,r=0,i=0]=Array.isArray(t)?t.map(e=>typeof e==`number`?e:NaN):[typeof t==`number`?t:NaN,this.evaluateNumber(e.y),e.z===void 0?0:this.evaluateNumber(e.z)];if(![n,r,i].every(Number.isFinite))throw Error(`Expected finite point coordinates`);return[n,r,i]}meshesIn(e){e.updateMatrixWorld(!0);let t=[];return e.traverse(e=>{e.isMesh&&t.push(e)}),t}shapeValue(e){let{captured:t,geometries:n,name:r,polygons:i,path:a}=this.buildScratch([e]);if(n.length===0){if(t.length===1)return t[0];if(t.length>1)return t;throw Error(`The shape used as a value produced nothing`)}let o=zh(n);return n.forEach(e=>e.dispose()),this.chargeRetained(o),{kind:`mesh`,geometry:o,...r===void 0?{}:{name:r},...i===void 0?{}:{polygons:i},...a?{path:a}:{}}}callShapeFunction(e,t){let{params:n=[],body:r=[],value:i,name:a}=e.definition;return this.evaluator.withArguments(n,t,()=>{let{captured:e,geometries:t,path:n}=this.buildScratch(r,e=>{i!==void 0&&e.push(this.transformedForCapture(this.evaluator.evaluate(i)))});for(let r of t)this.chargeRetained(r),e.push({kind:`mesh`,geometry:r,...n?{path:n}:{}});if(e.length===0)throw Error(`Function \`${a}\` produced no value`);return e.length===1?e[0]:e})}requireExtent(e,t){if(t.some(e=>!e))throw Error(`\`${e}\` needs a nonzero size in every dimension — this one encloses nothing`)}createGeometry(e){let t=this.evaluateSize(e.properties.size);switch(e.primitive){case`cube`:return this.requireExtent(`cube`,t),new Ai(t[0],t[1],t[2]);case`sphere`:return this.requireExtent(`sphere`,t),new eo(.5,this.detailLevel,this.detailLevel).scale(...t);case`icosphere`:return this.requireExtent(`icosphere`,t),js(.5,Mh(this.detailLevel)).geometry.scale(...t);case`cylinder`:{let n=e.properties.radiusTop?this.evaluateNumber(e.properties.radiusTop):t[0]/2,r=e.properties.radiusBottom?this.evaluateNumber(e.properties.radiusBottom):t[0]/2,i=e.properties.height?this.evaluateNumber(e.properties.height):t[1];return this.requireExtent(`cylinder`,[n||r,i]),new Mi(n,r,i,this.detailLevel)}case`cone`:{let n=t[0]/2,r=e.properties.height?this.evaluateNumber(e.properties.height):t[1];return this.requireExtent(`cone`,[n,r]),new Ni(n,r,this.detailLevel)}case`torus`:return this.createTorus(e,t);case`circle`:return new ji((t[0]||1)/2,this.detailLevel);case`square`:{let e=t[0]||1;return new Za(e,t[1]||e)}case`roundrect`:return this.createRoundrect(e,t);case`polygon`:{let n=(t[0]||1)/2,r=e.properties.sides===void 0?6:this.evaluateNumber(e.properties.sides);if(!Number.isInteger(r)||r<3||r>256)throw Error(`Polygon sides must be an integer from 3 to 256`);return new ji(n,r)}default:throw Error(`Unknown primitive: ${e.primitive}`)}}createRoundrect(e,t){let n=t[0]||1,r=t[1]||n,i=e.properties.radius===void 0?.25:this.evaluateNumber(e.properties.radius),a=Math.min(Math.max(0,i)*Math.min(n,r),n/2,r/2),o=new ua,s=n/2,c=r/2;o.moveTo(-s+a,-c),o.lineTo(s-a,-c),o.absarc(s-a,-c+a,a,-Math.PI/2,0,!1),o.lineTo(s,c-a),o.absarc(s-a,c-a,a,0,Math.PI/2,!1),o.lineTo(-s+a,c),o.absarc(-s+a,c-a,a,Math.PI/2,Math.PI,!1),o.lineTo(-s,-c+a),o.absarc(-s+a,-c+a,a,Math.PI,Math.PI*1.5,!1),o.closePath();let l=Math.max(1,Math.floor(this.detailLevel/4));return this.chargePathEstimate(o,l),new Qa(o,l)}createTorus(e,t){let n=t[0]/2,r=e.properties.innerRadius?this.evaluateNumber(e.properties.innerRadius):void 0,i=(e.properties.outerRadius?this.evaluateNumber(e.properties.outerRadius):void 0)??(r===void 0?n/1.4:n-r),a=r??i*.4;if(i<=0)throw Error("`torus` tube is as wide as the whole shape — its ring has no radius left");return this.requireExtent(`torus`,[i,a]),new to(i,a,Math.max(3,Math.floor(this.detailLevel/2)),this.detailLevel)}materialFor(e,t){let n=Dh(t);return e.material!==void 0&&this.applyMaterialValue(n,this.evaluator.evaluate(e.material)),e.color!==void 0&&this.applyColor(n,this.evaluateRGBA(e.color)),e.opacity!==void 0&&(n.opacity*=this.evaluateNumber(e.opacity)),e.metallicity!==void 0&&(n.metallicity=this.evaluateNumber(e.metallicity)),e.roughness!==void 0&&(n.roughness=this.evaluateNumber(e.roughness)),e.glow!==void 0&&(n.glow=this.glowColor(this.evaluator.evaluate(e.glow))),e.texture!==void 0&&this.warnTexture(this.evaluator.evaluate(e.texture)),n}applyColor(e,[t,n,r,i]){e.color=new Ln(t,n,r),e.alpha=i}glowColor(e){let[t,n,r]=this.requireFiniteColor(zc(e));return new Ln(t,n,r)}warnTexture(e){e!==``&&this.warn(`texture "${String(e)}" is not supported — the shape is drawn with its colour instead`)}applyMaterialValue(e,t){if(typeof t!=`object`||Array.isArray(t)||t.kind!==`material`)throw Error("`material` needs a value made with `material { … }`");let n=t;n.color&&this.applyColor(e,this.requireFiniteColor(n.color)),n.opacity!==void 0&&(e.opacity*=n.opacity),n.metallicity!==void 0&&(e.metallicity=n.metallicity),n.roughness!==void 0&&(e.roughness=n.roughness),n.glow&&(e.glow=this.glowColor(n.glow)),n.texture!==void 0&&this.warnTexture(n.texture)}createMaterial(e,t,n=!1){let r=this.materialFor(e.properties,t??this.currentTransform().material),i=Math.max(0,r.alpha*r.opacity);return new po({color:n?new Ln(1,1,1):r.color?.clone()??new Ln(.8,.8,.8),vertexColors:n,opacity:Math.min(1,i),transparent:i<1,...r.metallicity===void 0?{}:{metalness:Math.min(1,Math.max(0,r.metallicity))},...r.roughness===void 0?{}:{roughness:Math.min(1,Math.max(0,r.roughness))},...r.glow===void 0?{}:{emissive:r.glow.clone()},flatShading:r.smoothing!==void 0&&r.smoothing<=0,wireframe:this.options.wireframe??!1,userData:{colored:n||r.color!==void 0}})}convertCSG(e){if(e.children.length===0)return new An;let t=this.currentTransform().matrix.clone(),n=[];try{let r=new th;this.symbols.pushScope(),this.pushTransform(),this.currentTransform().matrix.identity();let i=[];try{for(let t of e.children){if(t.type===`path`)throw Error("A `path` has no volume and cannot be a CSG operand — wrap it in `extrude`, `lathe` or `fill`");let e=this.captureValues(null,()=>this.convertNode(t));if(e){if(n.push(e),e.isMesh){let t=e.clone();t.updateMatrixWorld(!0),i.push(t)}else e.isGroup&&(e.updateMatrixWorld(!0),e.traverse(e=>{if(e.isMesh){let t=e.clone();e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),i.push(t)}}))}}}finally{this.popTransform(),this.symbols.popScope()}if(i.length===0)return new An;n.push(...i);let a=i.map(e=>{let t=new np(e.geometry,e.material);return t.position.copy(e.position),t.rotation.copy(e.rotation),t.scale.copy(e.scale),t.updateMatrixWorld(!0),t});n.push(...a);let o=a[0];if(o===void 0)throw Error(`CSG operation needs at least one child shape`);let s=o;for(let t=1;t<a.length;t++){let i=a[t];if(i===void 0)continue;let o=(e,t,i)=>{n.push(e,t);let a=r.evaluate(e,t,i);return n.push(a),this.chargeEstimate(a.geometry.getAttribute(`position`)?.count??0),this.vertexCount+=a.geometry.getAttribute(`position`)?.count??0,a};switch(e.operation){case`union`:s=o(s,i,0);break;case`difference`:s=o(s,i,1);break;case`intersection`:s=o(s,i,3);break;case`xor`:s=o(o(s.clone(),i.clone(),1),o(i.clone(),s.clone(),1),0);break;case`stencil`:{let e=o(s,i,5),t=o(s,i,6);t.material=Array.isArray(i.material)?i.material[0]:i.material,t.geometry.clearGroups(),t.geometry.addGroup(0,t.geometry.index?.count??t.geometry.getAttribute(`position`).count,0);let r=[e,t],a=r.map(e=>e.geometry.clone().applyMatrix4(e.matrixWorld));try{let e=Ks(a);if(!e)throw Error(`Could not combine stencil surfaces`);let t=[],i=0;for(let n of r){for(let r of n.geometry.groups)e.addGroup(i+r.start,r.count,t.length+(r.materialIndex??0));t.push(...Array.isArray(n.material)?n.material:[n.material]),i+=n.geometry.index?.count??n.geometry.getAttribute(`position`).count}s=new np(e,t),n.push(s),this.chargeEstimate(e.getAttribute(`position`).count),this.vertexCount+=e.getAttribute(`position`).count}finally{a.forEach(e=>e.dispose())}break}}}return s.material||(s.material=o.material),s.applyMatrix4(t),s.updateMatrixWorld(!0),sh(n,s),s}catch(e){throw sh(n,new An),e}}convertForLoop(e){let t=new An;return this.inSymbolScope(t,()=>{for(let n of this.iterations(e.iterable))this.symbols.set(e.variable,n),this.addChildren(t,e.body)})}iterations(e){return Fc(this.evaluator.evaluate(e),this.maxLoopIterations,()=>new Eh(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`))}convertIf(e){let t=new An,n=this.evaluator.evaluateToBoolean(e.condition);return this.inSymbolScope(t,()=>this.addChildren(t,n?e.thenBody:e.elseBody??[]))}convertSwitch(e){let t=new An,n=this.evaluator.evaluate(e.value);return this.inSymbolScope(t,()=>{let r=e.cases.find(e=>e.values.some(e=>Pc(n,this.evaluator.evaluate(e))));this.addChildren(t,r?r.body:e.defaultCase??[])})}handleDefine(e){this.evaluator.define(e)||(e.body!==void 0||e.options!==void 0)&&this.symbols.set(e.name,e)}convertCustomShape(e){let t=this.symbols.get(e.name);if(t!==void 0&&Ih(t)){let n=new An;return this.inScope(n,()=>{this.applyPlacement(this.currentTransform().matrix,e.properties);let r=this.placeValue(t);r&&n.add(r)})}if(t===void 0)throw Error(`Unknown shape: ${e.name}`);if(typeof t!=`object`||Array.isArray(t)||!(`type`in t))return this.placeValue(t);let n=t;if(!n.body)throw Error(`Custom shape '${e.name}' has no body`);let r=new An,i=n.body,{position:a,orientation:o,rotation:s,size:c,name:l,...u}=e.properties;return this.inScope(r,()=>{this.applyPlacement(this.currentTransform().matrix,{position:a,orientation:o,rotation:s,size:c}),this.currentTransform().material=this.materialFor(u,this.currentTransform().material);for(let e of n.options??[])this.symbols.set(e.name,this.evaluator.evaluate(e.defaultValue));for(let[e,t]of Object.entries(u))e in Ph||this.symbols.set(e,this.evaluator.evaluate(t));l!==void 0&&(r.name=String(this.evaluator.evaluate(l))),this.withShapeOptions(u,()=>this.addChildren(r,i))})}applyPlacement(e,t){let n=t.position?new J(...this.evaluateVector3(t.position)):new J,r=t.orientation??t.rotation,i=r?this.rotationOf(r):new Mt,a=t.size?new J(...this.evaluateSize(t.size)):new J(1,1,1);e.multiply(new Y().compose(n,i,a))}pushTransform(){let e=this.currentTransform();this.transformStack.push({matrix:e.matrix.clone(),material:Dh(e.material)})}popTransform(){this.transformStack.length>1&&this.transformStack.pop()}currentTransform(){return this.transformStack[this.transformStack.length-1]??{matrix:new Y,material:{color:void 0,alpha:1,opacity:1,metallicity:void 0,roughness:void 0,glow:void 0,smoothing:void 0}}}applyCurrentTransform(e){let t=this.currentTransform();e.applyMatrix4(t.matrix)}applyExplicitTransforms(e,t,n=!1){if(t.position){let n=this.evaluateVector3(t.position);e.position.set(...n)}let r=t.orientation??t.rotation;r&&e.quaternion.copy(this.rotationOf(r)),n&&t.size&&e.scale.set(...this.evaluateSize(t.size)),t.name!==void 0&&(e.name=String(this.evaluator.evaluate(t.name)))}rotationOf(e){let t=this.rotationComponents(e);if(t.length===4){let[e=0,n=0,r=0,i=0]=t,a=Math.max(Math.abs(n),Math.abs(r),Math.abs(i));if(a===0)throw Error(`Rotation axis must not be zero`);let o=new J(n/a,r/a,i/a).normalize();return new Mt().setFromAxisAngle(o,-e*Math.PI)}let[n=0,r=0,i=0]=t;return new Mt().setFromEuler(new fn(-i*Math.PI,-r*Math.PI,-n*Math.PI,`ZYX`))}rotationComponents(e){let t=Array.isArray(e)&&typeof e[0]==`number`?e:this.evaluator.evaluate(e),n=(Array.isArray(t)?t:[t]).map(e=>typeof e==`number`?e:NaN);if(n.length===0||n.length>4||!n.every(Number.isFinite))throw Error(`Expected a rotation of 1 to 3 half-turn components (roll yaw pitch) or an angle and an axis (angle x y z)`);return n}handleDetail(e){let t=this.evaluateNumber(e.value);this.detailLevel=Number.isFinite(t)?Math.min(256,Math.max(3,Math.floor(t))):3,this.symbols.set(`detail`,this.detailLevel)}handleColorCommand(e){this.applyColor(this.currentTransform().material,this.evaluateRGBA(e.value))}handleMaterialCommand(e){let t=this.currentTransform().material;switch(e.property){case`opacity`:t.opacity*=this.evaluateNumber(e.value);break;case`metallicity`:t.metallicity=this.evaluateNumber(e.value);break;case`roughness`:t.roughness=this.evaluateNumber(e.value);break;case`glow`:t.glow=this.glowColor(this.evaluator.evaluate(e.value));break;case`texture`:this.warnTexture(this.evaluator.evaluate(e.value));break;case`material`:this.applyMaterialValue(t,this.evaluator.evaluate(e.value))}}handleRotateCommand(e){this.currentTransform().matrix.multiply(new Y().makeRotationFromQuaternion(this.rotationOf(e.value)))}handleOrientationCommand(e){let t=this.currentTransform(),n=new J,r=new J;t.matrix.decompose(n,new Mt,r),t.matrix.compose(n,this.rotationOf(e.value),r)}handleTranslateCommand(e){let t=this.currentTransform(),[n,r,i]=this.evaluateTranslateVector(e.value);if(![n,r,i].every(Number.isFinite))throw Error(`Expected finite translation components`);let a=new Y().makeTranslation(n,r,i);t.matrix.multiply(a)}handleScaleCommand(e){let t=this.evaluateSize(e.value),n=this.currentTransform(),r=new Y().makeScale(t[0],t[1],t[2]);n.matrix.multiply(r)}requireEnclosedArea(e,t){let n=e.getPoints(Ch),r=Wa.area(n);if(!Number.isFinite(r))throw Error(`\`${t}\` needs finite path coordinates — these overflow`);if(n.length<3||Math.abs(r)<Th)throw Error(`\`${t}\` needs a path that encloses an area — this one has fewer than three distinct points, or they are collinear`);return e}extrudeProperties(e){let t=e.properties.size?this.evaluateSize(e.properties.size):[1,1,1];return{depth:t[2]||1,properties:{...e.properties,size:[t[0]??1,t[1]??1,1]}}}convertExtrude(e){return this.withShapeOptions(e.properties,()=>{if(e.along)return this.convertExtrudeAlong(e,e.along);let{depth:t,properties:n}=this.extrudeProperties(e);return e.path?this.withPathDetail(()=>{let r=e.path,i=this.collectPathPoints(r),a=this.shapeFromPathPoints(i),o=Math.max(1,Math.floor(this.detailLevel/4));this.chargePathEstimate(a,o,wh);let s=mh(i)?new qa(this.requireEnclosedArea(a,`extrude`),{depth:t,bevelEnabled:!1,curveSegments:o}).translate(0,0,-t/2):ul(this.finitePoints(a.getPoints(o)),t);return this.finishMesh(this.placePath(s,r),{properties:n})}):this.buildFromChildren({children:e.children??[],properties:n},(e,n)=>{let r=e.flatMap(e=>this.planarShapes(e));if(!r.length&&!n.length)throw Error(`Extrude requires a path or planar shape`);for(let e of r)this.chargePathEstimate(e,1,12);let i=r.length?[new qa(r,{depth:t,bevelEnabled:!1,curveSegments:1}).translate(0,0,-t/2)]:[],a=n.map(e=>ul(hh(e),t)),o=[...i,...a];for(let e of o)this.chargeEstimate(e.getAttribute(`position`).count);let s=o.length===1?o[0]:zh(o);return o.length>1&&o.forEach(e=>e.dispose()),s})})}finitePoints(e){let t=e=>Number.isFinite(e)&&Math.abs(e)<=dh;if(!e.every(e=>t(e.x)&&t(e.y)))throw Error("`path` needs finite path coordinates — these overflow");return e.map(e=>new J(e.x,e.y,0))}convertExtrudeAlong(e,t){return this.buildFromChildren({children:e.children??[],properties:e.properties},e=>{let n=e.map(e=>this.sectionOf(e));if(!n.length)throw Error("`extrude … along` needs a planar section to sweep");let{points:r,closed:i}=this.sweepPathOf(t);this.chargeEstimate(n.reduce((e,t)=>e+t.length*r.length,0));let a=n.map(e=>al(ol(e,r,i),i)),o=a.length===1?a[0]:zh(a);return a.length>1&&a.forEach(e=>e.dispose()),o})}sectionOf(e){let t=tl(e);if(t.some(e=>Math.abs(e.z)>1e-5))throw Error("`extrude … along` sections must lie in the XY plane");return Wa.isClockWise(t.map(e=>new q(e.x,e.y)))?t.reverse():t}sweepPathOf(e){let t=new An,n=this.vertexCount;try{let{meshes:n,lines:r}=this.buildOperands(t,[e]);if(n.length+r.length!==1)throw Error("`along` needs exactly one path");let i=r[0],a=i?hh(i):tl(n[0]);if(a.length<2)throw Error("`along` needs a path with at least two points");return{points:a,closed:i===void 0}}finally{oh(t),this.vertexCount=n}}buildPath(e){return this.shapeFromPathPoints(this.collectPathPoints(e))}placePath(e,t){let n=t.properties;if(!n)return e;let r=new Y;return this.applyPlacement(r,n),e.applyMatrix4(r)}collectPathPoints(e){let t=new Y,n=[],r=!1,i=e=>{if(e.z!==void 0&&Math.abs(this.evaluateNumber(e.z))>uh)throw Error("Paths here are planar — a `point` / `curve` may not have a nonzero third coordinate");this.placePathPoint(t,n,this.evaluateNumber(e.x),this.evaluateNumber(e.y),e.type===`curve`&&!r)},a=e=>{if(t.multiply(e),!t.elements.every(Number.isFinite))throw Error("Path transform overflowed to a non-finite value — `translate`, `rotate` and `scale` accumulate inside a path")},o=e=>{if(++this.pathCommandCount>this.maxLoopIterations)throw new Eh(`ShapeScript path exceeds ${this.maxLoopIterations} commands`);switch(e.type){case`define`:this.handleDefine(e);break;case`detail`:{let t=this.evaluateNumber(e.value);r=t<1,this.handleDetail({type:`detail`,value:{type:`number`,value:t}});break}case`point`:case`curve`:i(e);break;case`arc`:this.placeArc(t,n,e);break;case`rotate`:a(new Y().makeRotationZ(-this.evaluateNumber(e.angle)*Math.PI));break;case`translate`:a(new Y().makeTranslation(this.evaluateNumber(e.x),this.evaluateNumber(e.y),0));break;case`scale`:{let t=this.evaluateNumber(e.x);a(new Y().makeScale(t,e.y===void 0?t:this.evaluateNumber(e.y),1));break}case`for`:this.runPathLoop(e,o);break;case`color`:this.evaluateRGBA(e.value)}};for(let t of e.commands)o(t);return n}placePathPoint(e,t,n,r,i){let a=new J(n,r,0).applyMatrix4(e);if(!Number.isFinite(a.x)||!Number.isFinite(a.y))throw Error(`Path coordinates overflowed to a non-finite value`);t.push({x:a.x,y:a.y,curved:i})}placeArc(e,t,n){let r=n.angle===void 0?1:this.evaluateNumber(n.angle),i=Math.min(2,Math.abs(r));if(i===0)throw Error("`arc` needs a nonzero angle");let a=Math.max(i<.5?1:i<1?2:3,Math.ceil(i/2*this.detailLevel)),o=(n.size===void 0?1:this.evaluateSize(n.size)[0])/2,s=new Y;this.applyPlacement(s,{...n.position?{position:n.position}:{},...n.orientation?{orientation:n.orientation}:{}});let c=e.clone().multiply(s),l=Math.sign(r);for(let e=0;e<=a;e++){let n=l*i*e/a*Math.PI;this.placePathPoint(c,t,Math.sin(n)*o,Math.cos(n)*o,!1)}}runPathLoop(e,t){this.symbols.pushScope();try{for(let n of this.iterations(e.iterable)){this.symbols.set(e.variable,n);for(let n of e.commands)t(n)}}finally{this.symbols.popScope()}}shapeFromPathPoints(e){let t=new ua,n=e[0];if(n===void 0)return t;let r=mh(e),i=r?e.slice(0,-1):e,a=e=>i[(e+i.length)%i.length],o=r&&n.curved?((e,t)=>e.curved?ph(e,t):e)(a(-1),n):n;t.moveTo(o.x,o.y);let s=!1;for(let e=+!r;e<i.length;e++){let n=a(e),o=r||e<i.length-1?a(e+1):void 0;if(!n.curved||o===void 0){s||t.lineTo(n.x,n.y),s=!1;continue}let c=o.curved?ph(n,o):o;t.quadraticCurveTo(n.x,n.y,c.x,c.y),s=!o.curved}return r&&!s&&!fh(a(-1),o)&&t.lineTo(o.x,o.y),t}convertLathe(e){return this.inFrame(()=>this.buildLathe(e))}requireLatheProfile(e){if(!e.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)))throw Error("`lathe` profile has non-finite coordinates — a curve control point or a path command overflowed");let t=Math.max(...e.map(e=>Math.abs(e.x))),n=Math.max(...e.map(e=>e.y))-Math.min(...e.map(e=>e.y));if(t<Th||n<Th)throw Error("`lathe` needs a profile with both radius and height — one on the axis of rotation sweeps nothing")}buildLathe(e){let t=null;for(let n of e.children)if(n.type===`path`){if(t)throw Error("`lathe` takes one profile path");t=n}else{let e=this.convertNode(n);if(e)throw oh(e),Error("`lathe` takes a path, not a shape — give it `path { … }`")}if(!t)throw Error(`Lathe requires a path child`);if(t.properties)throw Error("`lathe` does not support position/orientation/size on its profile path — place the lathe itself instead");return this.withShapeOptions(e.properties,()=>{let n=this.buildPath(t);this.chargePathEstimate(n,this.detailLevel,this.detailLevel+1);let r=n.getPoints(this.detailLevel);if(r.length<2)throw Error(`Lathe path must have at least 2 points`);if(this.requireLatheProfile(r),r.every(e=>e.x<=uh))for(let e of r)e.x=-e.x;this.chargeEstimate(r.length*(this.detailLevel+1));let i=jh(new Xa(r,this.detailLevel));return this.finishMesh(i,e,!0,this.currentTransform().material)})}buildOperands(e,t){let n=this.currentTransform().material;this.operandDepth++;try{this.captureValues(null,()=>this.inScope(e,()=>{this.currentTransform().matrix.identity(),this.addChildren(e,t),n=Dh(this.currentTransform().material)}))}finally{this.operandDepth--}e.updateMatrixWorld(!0);let r=[],i=[],a=[];return e.traverse(e=>{if(e.isMesh)r.push(e);else if(e.isLine)i.push(e);else return;a.push(e)}),{meshes:r,lines:i,operands:a,material:n}}buildFromChildren(e,t){let n=new An,r=this.vertexCount,i,a;try{let r=this.buildOperands(n,e.children);a=r.material,i=t(r.meshes,r.lines,r.operands)}finally{oh(n),this.vertexCount=r}return this.finishMesh(i,e,!0,a)}convertLoft(e){return this.withShapeOptions(e.properties,()=>this.buildLoft(e))}buildLoft(e){return this.buildFromChildren(e,(e,t,n)=>{let r=n.map(bh),i=r.length*Math.max(0,...r.map(e=>e.length));return this.chargeEstimate(i),al(r)})}planarShapes(e){let t=el(e);if(t.some(e=>e.some(e=>Math.abs(e.z)>1e-5)))throw Error(`Fill/extrude profiles must lie in the XY plane`);return xl(t.map(e=>e.map(e=>new q(e.x,e.y))))}convertText(e){return this.withShapeOptions(e.properties,()=>{e.font!==void 0&&this.warn("`font` is not rendered by this viewer and was skipped");let t=El(this.textOf(e),{...e.wrapWidth===void 0?{}:{wrapWidth:this.textWrapWidth(e.wrapWidth)},lineSpacing:e.lineSpacing===void 0?0:this.evaluateNumber(e.lineSpacing),curveSegments:Math.max(1,Math.floor(this.detailLevel/Sh))});t.missing.length&&this.warn(`The built-in font has no glyph for ${[...new Set(t.missing)].map(e=>`"${e}"`).join(` `)} — drawn as "?"`);let n=t.rings.reduce((e,t)=>e+t.length,0);return t.shapes.length===0?null:this.operandDepth>0||this.valueSink!==null?(this.chargeEstimate(n),_h(this.finishMesh(new Qa(t.shapes,1),e,!0))):this.textOutline(e,t,n)})}textWrapWidth(e){let t=this.evaluateNumber(e);if(!(t>0))throw Error("`wrapwidth` must be a positive number");return t}textOf(e){let t=e.lines.map(e=>{let t=this.evaluator.evaluate(e);return Dl(Array.isArray(t)?t:[t],e=>Bh(e))}).join(`
24
+ `);if(t.length>2e3)throw Error(`\`text\` is limited to ${hl} characters`);return t}textOutline(e,t,n){this.chargeEstimate(n*2);let r=new Float32Array(n*6),i=0;for(let e of t.rings)e.forEach((t,n)=>{let a=e[(n+1)%e.length];r.set([t.x,t.y,0,a.x,a.y,0],i),i+=6});this.vertexCount+=n*2;let a=new Mr().setAttribute(`position`,new X(r,3)),o=this.materialFor(e.properties,this.currentTransform().material),s=Math.min(1,Math.max(0,o.alpha*o.opacity)),c=new Ti(a,new pi({color:o.color?.clone()??new Ln(.8,.8,.8),opacity:s,transparent:s<1}));return this.applyExplicitTransforms(c,e.properties,!0),this.applyCurrentTransform(c),c}convertFill(e){return this.inFrame(()=>{let t=e.children.length===1?e.children.find(e=>e.type===`path`):void 0;if(!t)return this.buildFromChildren(e,e=>{let t=e.flatMap(e=>this.planarShapes(e));if(!t.length)throw Error(`Fill requires a path or planar shape`);for(let e of t)this.chargePathEstimate(e,1,3);return new Qa(t,1)});let n=this.buildPath(t);this.chargePathEstimate(n,Ch),this.requireEnclosedArea(n,`fill`);let r=this.placePath(new Qa(n),t);return this.finishMesh(r,e)})}convertMinkowski(e){return this.buildFromChildren(e,e=>{if(e.length<2)throw Error("`minkowski` needs at least two shapes");let[t,...n]=e,r=t.geometry.clone().applyMatrix4(t.matrixWorld),i=new Y;try{for(let e of n){this.chargeEstimate(r.getAttribute(`position`).count*e.geometry.getAttribute(`position`).count);let t=sc({geometry:r,matrix:i},{geometry:e.geometry,matrix:e.matrixWorld});r.dispose(),r=t}}catch(e){throw r.dispose(),e}this.chargeEstimate(r.getAttribute(`position`).count);let a=Rh(t);return a&&r.setAttribute(`color`,new X(new Float32Array(r.getAttribute(`position`).count*3).map((e,t)=>a[t%3]),3)),r})}convertHull(e){return this.buildFromChildren(e,e=>{let t=[];for(let n of e){let e=n.geometry.getAttribute(`position`);for(let r=0;r<e.count;r++)t.push(new J().fromBufferAttribute(e,r).applyMatrix4(n.matrixWorld))}if(t.length<4)throw Error(`Hull requires at least four non-coplanar points`);this.chargeEstimate(t.length*6);let n=new Gs(t);if(!n.getAttribute(`position`).count)throw n.dispose(),Error(`Hull points must enclose a volume`);return n.setAttribute(`uv`,new X(new Float32Array(n.getAttribute(`position`).count*2),2)),n})}evaluateNumber(e){if(e===void 0)return 0;if(typeof e==`number`)return e;let t=this.evaluator.evaluateToNumber(e);if(!Number.isFinite(t))throw Error(`Expected a finite number`);return t}evaluateVector3(e){if(e===void 0)return[0,0,0];if(Array.isArray(e)&&typeof e[0]==`number`)return e;let t=this.evaluateTranslateVector(e);if(!t.every(Number.isFinite))throw Error(`Expected finite vector components`);return t}evaluateSize(e){if(e===void 0)return[1,1,1];let t=Array.isArray(e)&&typeof e[0]==`number`?e:this.evaluator.evaluate(e),[n=1,r=n,i=n]=(Array.isArray(t)?t:[t]).map(e=>{if(typeof e!=`number`||!Number.isFinite(e))throw Error(`Expected finite size components`);return e});return[n,r,i]}evaluateRGBA(e){return this.requireFiniteColor(this.evaluator.evaluateToRGBA(e))}evaluateTranslateVector(e){let t=this.evaluator.evaluate(e);return typeof t==`number`?[t,0,0]:Array.isArray(t)?[t.length>0&&typeof t[0]==`number`?t[0]:0,t.length>1&&typeof t[1]==`number`?t[1]:0,t.length>2&&typeof t[2]==`number`?t[2]:0]:[0,0,0]}requireFiniteColor(e){if(!e.every(Number.isFinite))throw Error(`Expected finite color channels`);return e}},Ph={position:!0,orientation:!0,rotation:!0,size:!0,color:!0,opacity:!0,material:!0,metallicity:!0,roughness:!0,glow:!0,texture:!0,detail:!0,smoothing:!0};function Fh(e){let t=[];for(let n of e)Array.isArray(n)?t.push(...Fh(n)):Ih(n)&&t.push(n);return t}function Ih(e){return _c(e)&&(e.kind===`mesh`||e.kind===`polygon`)}function Lh(e){let t=e.geometry.clone(),n=Rh(e);if(n&&!t.hasAttribute(`color`)){let e=t.getAttribute(`position`).count;t.setAttribute(`color`,new X(new Float32Array(e*3).map((e,t)=>n[t%3]),3))}return t}function Rh(e){let t=Array.isArray(e.material)?e.material[0]:e.material,n=e.geometry.getAttribute(`color`);if(n&&n.count>0){let e=[n.getX(0),n.getY(0),n.getZ(0)];for(let t=1;t<n.count;t++)if(Math.abs(n.getX(t)-e[0])>1e-6||Math.abs(n.getY(t)-e[1])>1e-6||Math.abs(n.getZ(t)-e[2])>1e-6)return;return e}if(t?.userData?.colored&&t.color)return[t.color.r,t.color.g,t.color.b]}function zh(e){let t=e.some(e=>e.hasAttribute(`color`)),n=e.map(e=>{let n=e.index?e.toNonIndexed():e.clone();n.hasAttribute(`normal`)||n.computeVertexNormals();let r=n.getAttribute(`position`).count;n.hasAttribute(`uv`)||n.setAttribute(`uv`,new X(new Float32Array(r*2),2)),t&&!n.hasAttribute(`color`)&&n.setAttribute(`color`,new X(new Float32Array(r*3).fill(.8),3));for(let e of Object.keys(n.attributes))[`position`,`normal`,`uv`,`color`].includes(e)||n.deleteAttribute(e);return n.clearGroups(),n}),r=n.length===1?n[0]:Ks(n);if(!r)throw Error(`Could not combine the shapes into one mesh`);return n.length>1&&n.forEach(e=>e.dispose()),r}function Bh(e){return Array.isArray(e)?e.map(e=>Array.isArray(e)?`(${Bh(e)})`:Bh(e)).join(` `):typeof e==`object`?e.kind===`range`?`${e.from} to ${e.to} step ${e.step}`:`<${e.kind}>`:String(e)}function Vh(e,t={}){return new Nh(t).convert(e)}Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"$t",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return ki}}),Object.defineProperty(exports,"An",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"At",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"Bn",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"Bt",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return en}}),Object.defineProperty(exports,"Cn",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"Ct",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return Di}}),Object.defineProperty(exports,"Dn",{enumerable:!0,get:function(){return Mn}}),Object.defineProperty(exports,"Dt",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"En",{enumerable:!0,get:function(){return $t}}),Object.defineProperty(exports,"Et",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return bs}}),Object.defineProperty(exports,"Fn",{enumerable:!0,get:function(){return ro}}),Object.defineProperty(exports,"Ft",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"Gt",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"Hn",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"Ht",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return An}}),Object.defineProperty(exports,"In",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"It",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"Jt",{enumerable:!0,get:function(){return Hr}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return jt}}),Object.defineProperty(exports,"Kt",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"Ln",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"Lt",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"Mn",{enumerable:!0,get:function(){return Cs}}),Object.defineProperty(exports,"Mt",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return fi}}),Object.defineProperty(exports,"Nn",{enumerable:!0,get:function(){return oo}}),Object.defineProperty(exports,"Nt",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Go}}),Object.defineProperty(exports,"On",{enumerable:!0,get:function(){return no}}),Object.defineProperty(exports,"Ot",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(exports,"Pn",{enumerable:!0,get:function(){return et}}),Object.defineProperty(exports,"Pt",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return ho}}),Object.defineProperty(exports,"Qt",{enumerable:!0,get:function(){return it}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"Rn",{enumerable:!0,get:function(){return nt}}),Object.defineProperty(exports,"Rt",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return tn}}),Object.defineProperty(exports,"Sn",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"St",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"Tn",{enumerable:!0,get:function(){return Je}}),Object.defineProperty(exports,"Tt",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return He}}),Object.defineProperty(exports,"Un",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"Ut",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"Vn",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"Vt",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return Ue}}),Object.defineProperty(exports,"Wt",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return Ur}}),Object.defineProperty(exports,"Xt",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return ti}}),Object.defineProperty(exports,"Yt",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return mo}}),Object.defineProperty(exports,"Zt",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Bt}}),Object.defineProperty(exports,"_n",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"_t",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return oh}}),Object.defineProperty(exports,"an",{enumerable:!0,get:function(){return zn}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return ci}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return Oi}}),Object.defineProperty(exports,"bn",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"bt",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"cn",{enumerable:!0,get:function(){return ls}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return Mt}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Ai}}),Object.defineProperty(exports,"dn",{enumerable:!0,get:function(){return yr}}),Object.defineProperty(exports,"dt",{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,"en",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return vr}}),Object.defineProperty(exports,"fn",{enumerable:!0,get:function(){return br}}),Object.defineProperty(exports,"ft",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Ln}}),Object.defineProperty(exports,"gn",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"gt",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"hn",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"ht",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return lh}}),Object.defineProperty(exports,"in",{enumerable:!0,get:function(){return We}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return Ho}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"jn",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"jt",{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return at}}),Object.defineProperty(exports,"kn",{enumerable:!0,get:function(){return Qe}}),Object.defineProperty(exports,"kt",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Ko}}),Object.defineProperty(exports,"ln",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"mn",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"mt",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Eh}}),Object.defineProperty(exports,"nn",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return ch}}),Object.defineProperty(exports,"on",{enumerable:!0,get:function(){return uo}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return Za}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Mr}}),Object.defineProperty(exports,"pn",{enumerable:!0,get:function(){return so}}),Object.defineProperty(exports,"pt",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return Ft}}),Object.defineProperty(exports,"qt",{enumerable:!0,get:function(){return fo}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Vh}}),Object.defineProperty(exports,"rn",{enumerable:!0,get:function(){return Ve}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return Uo}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return $c}}),Object.defineProperty(exports,"sn",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return cs}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return xh}}),Object.defineProperty(exports,"tn",{enumerable:!0,get:function(){return Ae}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Xo}}),Object.defineProperty(exports,"un",{enumerable:!0,get:function(){return Xt}}),Object.defineProperty(exports,"ut",{enumerable:!0,get:function(){return lt}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Ss}}),Object.defineProperty(exports,"vn",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"vt",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return ii}}),Object.defineProperty(exports,"wn",{enumerable:!0,get:function(){return Zt}}),Object.defineProperty(exports,"wt",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return Ei}}),Object.defineProperty(exports,"xn",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"xt",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Yo}}),Object.defineProperty(exports,"yn",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"yt",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return pn}}),Object.defineProperty(exports,"zn",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"zt",{enumerable:!0,get:function(){return Oe}});