@glyphcss/core 0.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ var jr="cubic";function gt(e){let n=e.replace("#","");if(n.length===3){let r=parseInt(n[0]+n[0],16),t=parseInt(n[1]+n[1],16),o=parseInt(n[2]+n[2],16);return Number.isNaN(r)||Number.isNaN(t)||Number.isNaN(o)?null:{rgb:[r,t,o],alpha:1}}if(n.length===6){let r=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16);return Number.isNaN(r)||Number.isNaN(t)||Number.isNaN(o)?null:{rgb:[r,t,o],alpha:1}}return null}function pt(e){let n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/i);return n?{rgb:[Number(n[1]),Number(n[2]),Number(n[3])],alpha:n[4]?Number(n[4]):1}:null}function Tn(e){if(!e)return null;let n=e.trim(),r=gt(n);return r||pt(n)}function Me(e){return Math.max(0,Math.min(255,Math.round(e)))}function Ke(e){let[n,r,t]=e.rgb.map(Me);return e.alpha<1?`rgba(${n}, ${r}, ${t}, ${e.alpha})`:`rgb(${n}, ${r}, ${t})`}var In={rgb:[204,204,204],alpha:1},dt=new Map;function Ie(e){if(!e)return null;let n=e.trim(),r=dt.get(n);if(r)return r;let t=Tn(n);return t?(dt.set(n,t),t):null}function Xr(e,n){let r=Ie(e)??In,t=[Me(r.rgb[0]+n),Me(r.rgb[1]+n),Me(r.rgb[2]+n)];return Ke({rgb:t,alpha:r.alpha})}var wn={direction:[0,0,-1],color:"#ffffff",intensity:1},xt={color:"#ffffff",intensity:.4};function ht(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-12?[0,0,0]:[e[0]/n,e[1]/n,e[2]/n]}function yt(e,n,r){let t=Ie(n)??In;return e*(t.rgb[r]/255)}function Yr(e,n,r,t){let o=Ie(n)??In,s=ht(r?.direction??wn.direction),i=r?.color??wn.color,l=Math.max(0,r?.intensity??wn.intensity),c=t?.color??xt.color,a=Math.max(0,t?.intensity??xt.intensity),u=ht(e),f=Math.max(0,-(u[0]*s[0]+u[1]*s[1]+u[2]*s[2])),g=l*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let d=o.rgb[p],y=yt(d,c,p)*a,b=yt(d,i,p)*g;m[p]=Me(y+b)}return Ke({rgb:m,alpha:o.alpha})}var bt="#cccccc",We=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Pt=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],Mt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Ze=e=>Math.hypot(e[0],e[1],e[2]);function Hr(e){let n=1/0,r=1/0,t=1/0,o=-1/0,s=-1/0,i=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>o&&(o=u[0]),u[1]<r&&(r=u[1]),u[1]>s&&(s=u[1]),u[2]<t&&(t=u[2]),u[2]>i&&(i=u[2]);let l=o-n,c=s-r,a=i-t;return Math.hypot(l,c,a)}function Kr(){let e=globalThis;if(e.__POLYCSS_DEV__===!0)return!0;if(e.__POLYCSS_DEV__===!1)return!1;let n=e.process?.env?.NODE_ENV;return typeof n=="string"?n!=="production":!1}function En(e){let n=[],r=[];if(!e||e.length===0)return{polygons:n,warnings:r};for(let t=0;t<e.length;t++){let o=e[t];if(!o||!Array.isArray(o.vertices)){r.push(`Polygon ${t}: missing vertices, dropped`);continue}let s=o.vertices;if(s.length<3){r.push(`Polygon ${t}: ${s.length} vertices (need >= 3), dropped`);continue}let i=We(s[1],s[0]),l=We(s[2],s[0]),c=Pt(i,l),a=Ze(c);if(s.length===3){if(a<1e-12){Ze(i)<1e-12||Ze(l)<1e-12?r.push(`Polygon ${t}: zero-area triangle (coincident vertices), dropped`):r.push(`Polygon ${t}: vertices collinear, dropped`);continue}}else if(a<1e-12){r.push(`Polygon ${t}: first 3 vertices collinear, dropped`);continue}let u=[{...o,vertices:s.slice()}];if(s.length>=4){let f=[c[0]/a,c[1]/a,c[2]/a],g=Mt(f,s[0]),m=Hr(s),p=Math.max(1e-6,m*.001),d=0;for(let y=3;y<s.length;y++){let b=Math.abs(Mt(f,s[y])-g);b>d&&(d=b)}if(d>p){let y=[],b=o.uvs&&o.uvs.length===s.length?o.uvs:void 0;for(let M=1;M<s.length-1;M++){let v=[s[0].slice(),s[M].slice(),s[M+1].slice()],P=Pt(We(v[1],v[0]),We(v[2],v[0]));if(Ze(P)<1e-12)continue;let x={...o,vertices:v};b&&(x.uvs=[b[0].slice(),b[M].slice(),b[M+1].slice()]),y.push(x)}if(y.length===0){r.push(`Polygon ${t}: ${s.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}r.push(`Polygon ${t}: ${s.length} non-coplanar vertices, fan-triangulated to ${y.length} triangles`),u=y}}for(let f of u){let g=Wr(f,t,r);g&&n.push(g)}}return{polygons:n,warnings:r}}function Wr(e,n,r){let t={vertices:e.vertices},o=e.texture;if(typeof o=="string"&&o===""&&(o=void 0),e.color!==void 0&&o!==void 0&&Kr()&&r.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Ie(e.color)?t.color=e.color:(r.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${bt}`),t.color=bt)),o!==void 0&&(t.texture=o),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?r.push(`Polygon ${n}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):t.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let s={},i=!1;for(let l of Object.keys(e.data)){let c=e.data[l];typeof c=="string"||typeof c=="number"||typeof c=="boolean"?s[l]=c:(i=!0,r.push(`Polygon ${n}: data["${l}"] has non-primitive value, key dropped`))}Object.keys(s).length>0&&(t.data=s)}return t}function vt(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,r=1/0,t=1/0,o=-1/0,s=-1/0,i=-1/0,l=!1;for(let c of e)if(c?.vertices)for(let a of c.vertices)a&&(l=!0,a[0]<n&&(n=a[0]),a[0]>o&&(o=a[0]),a[1]<r&&(r=a[1]),a[1]>s&&(s=a[1]),a[2]<t&&(t=a[2]),a[2]>i&&(i=a[2]));return l?{min:[n,r,t],max:[o,s,i]}:{min:[0,0,0],max:[0,0,0]}}function Zr(e){let n=e.polygons??[],r,t;if(e.skipNormalize)r=n,t=[];else{let l=En(n);r=l.polygons,t=l.warnings}let o=vt(r),s=[o.max[0]-o.min[0],o.max[1]-o.min[1],o.max[2]-o.min[2]];return{context:{polygons:r,sceneBbox:o,warnings:t},dimensions:{sceneBbox:o,size:s},warnings:t}}function Qr(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function Qe(e,n,r,t){let o=n*Math.PI/180,s=r*Math.PI/180,i=t*Math.PI/180,[l,c,a]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[l,c]=[l*u-c*f,l*f+c*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[l,a]=[l*u+a*f,-l*f+a*u]}if(o!==0){let u=Math.cos(o),f=Math.sin(o);[c,a]=[c*u-a*f,c*f+a*u]}return[l,c,a]}function qr(e,n){let r=-n[0]*Math.PI/180,t=-n[1]*Math.PI/180,o=-n[2]*Math.PI/180,[s,i,l]=e;if(r!==0){let c=Math.cos(r),a=Math.sin(r);[i,l]=[i*c-l*a,i*a+l*c]}if(t!==0){let c=Math.cos(t),a=Math.sin(t);[s,l]=[s*c+l*a,-s*a+l*c]}if(o!==0){let c=Math.cos(o),a=Math.sin(o);[s,i]=[s*c-i*a,s*a+i*c]}return[s,i,l]}var On=Math.PI/180,Ge=180/Math.PI,Jr=[1,0,0,0];function eo(e,n){let[r,t,o,s]=e,[i,l,c,a]=n;return[r*i-t*l-o*c-s*a,r*l+t*i+o*a-s*c,r*c-t*a+o*i+s*l,r*a+t*c-o*l+s*i]}function no(e,n){let r=n*.5,t=Math.sin(r);return[Math.cos(r),e[0]*t,e[1]*t,e[2]*t]}function to(e){let n=e[0]*On,r=e[1]*On,t=e[2]*On,o=Math.cos(n*.5),s=Math.sin(n*.5),i=Math.cos(r*.5),l=Math.sin(r*.5),c=Math.cos(t*.5),a=Math.sin(t*.5);return[o*i*c-s*l*a,s*i*c+o*l*a,o*l*c-s*i*a,o*i*a+s*l*c]}function ro(e){let[n,r,t,o]=e,s=2*(r*o+n*t),i=2*(t*o-n*r),l=1-2*(r*r+t*t),c=2*(r*t-n*o),a=1-2*(t*t+o*o),u=Math.max(-1,Math.min(1,s)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-i,l)*Ge,f*Ge,Math.atan2(-c,a)*Ge]:[Math.atan2(2*(t*o+n*r),1-2*(r*r+o*o))*Ge,f*Ge,0]}var oo=50;function so(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Oe={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},At=100,Ct=1e4,Ee=e=>Math.round(e*At)/At,io=e=>Math.round(e*Ct)/Ct;function co(e={}){let n={target:e.target??[...Oe.target],rotX:e.rotX??Oe.rotX,rotY:e.rotY??Oe.rotY,zoom:e.zoom??Oe.zoom,distance:e.distance??Oe.distance};function r(o){o.target!==void 0&&(n.target=[Ee(o.target[0]),Ee(o.target[1]),Ee(o.target[2])]),o.rotX!==void 0&&(n.rotX=Ee(o.rotX)),o.rotY!==void 0&&(n.rotY=Ee(o.rotY)),o.zoom!==void 0&&(n.zoom=io(o.zoom)),o.distance!==void 0&&(n.distance=Ee(o.distance))}function t(o={}){let i=(o.cols??0)*50,l=(o.rows??0)*50,[c,a,u]=n.target,f=a*50,g=c*50,m=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-f}px, ${-g}px, ${-m}px)`,width:`${i}px`,height:`${l}px`}}return{state:n,update:r,getStyle:t}}var he=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],qe=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],De=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Rn=e=>Math.hypot(e[0],e[1],e[2]),xe=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function ao(e,n){let r=`${e[0]},${e[1]},${e[2]}`,t=`${n[0]},${n[1]},${n[2]}`;return r<t?`${r}|${t}`:`${t}|${r}`}function St(e){if(e.length<3)return null;let n=he(e[1],e[0]),r=he(e[2],e[0]),t=qe(n,r),o=Rn(t);if(o<1e-12)return null;let s=[t[0]/o,t[1]/o,t[2]/o],i=De(s,e[0]);return{normal:s,d:i}}function lo(e,n){return De(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function uo(e,n){return De(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function fo(e,n,r,t){let o=e.vertices.findIndex(V=>xe(V,r)),s=e.vertices.findIndex(V=>xe(V,t)),i=n.vertices.findIndex(V=>xe(V,r)),l=n.vertices.findIndex(V=>xe(V,t));if(o<0||s<0||i<0||l<0)return null;let c=e.vertices.length,a=n.vertices.length,u=(o+1)%c===s,f=(i+1)%a===l;if(u===f)return null;let g=u?s:o,m=u?o:s,p=f?l:i,d=f?i:l,y=!!(e.uvs&&n.uvs),b=[],M=y?[]:void 0,v=g;for(;b.push(e.vertices[v]),M&&M.push(e.uvs[v]),v!==m;)v=(v+1)%c;for(v=p;b.push(n.vertices[v]),M&&M.push(n.uvs[v]),v!==d;)v=(v+1)%a;let P=[],x=M?[]:void 0;for(let V=0;V<b.length;V++)(P.length===0||!xe(b[V],P[P.length-1]))&&(P.push(b[V]),x&&M&&x.push(M[V]));if(P.length>1&&xe(P[0],P[P.length-1])&&(P.pop(),x?.pop()),y)return Vt(P,x);let A=[],T=x?[]:void 0;for(let V=0;V<P.length;V++){let w=P[(V-1+P.length)%P.length],O=P[V],L=P[(V+1)%P.length],U=qe(he(O,w),he(L,w));Rn(U)>1e-9&&(A.push(O),T&&x&&T.push(x[V]))}return A.length<3?null:Vt(A,T)}function mo(e,n){let r=e.length,t=0;for(let o=0;o<r;o++){let s=e[o],i=e[(o+1)%r],l=e[(o+2)%r],c=he(i,s),a=he(l,i),u=De(qe(c,a),n);if(Math.abs(u)<1e-9)continue;let f=u>0?1:-1;if(t===0)t=f;else if(f!==t)return!1}return!0}function go(e,n){if(e.length<3)return!1;let r=St(e);if(!r)return!1;for(let t of e)if(Math.abs(De(r.normal,t)-r.d)>n)return!1;return!0}function po(e){return e.map(n=>({vertices:n.vertices.map(r=>[...r]),uvs:n.uvs.map(r=>[...r])}))}function xo(e,n){let r=[];for(let t=1;t<e.length-1;t++)r.push({vertices:[[...e[0]],[...e[t]],[...e[t+1]]],uvs:[[...n[0]],[...n[t]],[...n[t+1]]]});return r}function Vt(e,n){for(let r=0;r<e.length;r++){let t=e[r],o=e[(r+1)%e.length],s=e[(r+2)%e.length];if(!(Rn(qe(he(o,t),he(s,t)))<=1e-9))return r===0?{vertices:e,uvs:n}:{vertices:[...e.slice(r),...e.slice(0,r)],uvs:n?[...n.slice(r),...n.slice(0,r)]:void 0}}return{vertices:e,uvs:n}}function ce(e){let n=[],r=[];for(let o of e??[]){if(!o||!o.vertices||o.vertices.length<3){o&&n.push(o);continue}let s=o.vertices.map(a=>[a[0],a[1],a[2]]),i=St(s);if(!i){n.push(o);continue}let l=o.texture&&o.uvs&&o.uvs.length===s.length?o.uvs.map(a=>[a[0],a[1]]):void 0,c=o.texture&&l?o.textureTriangles?.length?po(o.textureTriangles):xo(s,l):void 0;r.push({vertices:s,uvs:l,color:o.color??"#cccccc",texture:o.texture,textureTriangles:c,normal:i.normal,d:i.d,alive:!0,data:o.data})}let t=()=>{let o=new Map;for(let l=0;l<r.length;l++){let c=r[l];if(!c.alive)continue;let a=c.vertices.length;for(let u=0;u<a;u++){let f=c.vertices[u],g=c.vertices[(u+1)%a],m=ao(f,g),p=o.get(m);p||(p=[],o.set(m,p)),p.push(l)}}let s=!1,i=(l,c)=>{for(let a=0;a<l.vertices.length;a++){let u=l.vertices[a],f=l.vertices[(a+1)%l.vertices.length];for(let g=0;g<c.vertices.length;g++){let m=c.vertices[g],p=c.vertices[(g+1)%c.vertices.length];if(xe(u,p)&&xe(f,m))return[u,f]}}return null};for(let[,l]of o){if(l.length<2)continue;let[c,a]=l;if(c===a)continue;let u=r[c],f=r[a];if(!u.alive||!f.alive||u.color!==f.color||u.texture!==f.texture)continue;let g=!!(u.texture||f.texture);if(g&&(!u.textureTriangles||!f.textureTriangles)||!!u.uvs!=!!f.uvs||(g?!uo(u,f):!lo(u,f)))continue;let m=i(u,f);if(!m)continue;let[p,d]=m,y=fo(u,f,p,d);y&&go(y.vertices,.001)&&mo(y.vertices,u.normal)&&(u.vertices=y.vertices,u.uvs=y.uvs,u.textureTriangles=g?[...u.textureTriangles??[],...f.textureTriangles??[]]:void 0,f.alive=!1,s=!0)}return s};for(;t(););for(let o of r){if(!o.alive)continue;let s={vertices:o.vertices,color:o.color};o.texture&&(s.texture=o.texture),o.uvs&&(s.uvs=o.uvs),o.textureTriangles?.length&&(s.textureTriangles=o.textureTriangles),o.data&&(s.data=o.data),n.push(s)}return n}var ho=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],yo=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],fe=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function bo(e,n){let r=e.vertices;if(!r||r.length<3)return null;let t=0,o=0,s=0;for(let d=0;d<r.length;d++){let y=r[d],b=r[(d+1)%r.length];t+=(y[1]-b[1])*(y[2]+b[2]),o+=(y[2]-b[2])*(y[0]+b[0]),s+=(y[0]-b[0])*(y[1]+b[1])}let i=Math.hypot(t,o,s);if(i<1e-12)return null;let l=[t/i,o/i,s/i],c=0,a=0,u=0;for(let d of r)c+=d[0],a+=d[1],u+=d[2];let f=1/r.length,g=[c*f,a*f,u*f],m=fe(l,g),p=i*.5;return{index:n,polygon:e,normal:l,d:m,centroid:g,area:p,local2D:null,bbox2D:null,basis:null}}function Po(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],r=n[0]-e[0]*fe(n,e),t=n[1]-e[1]*fe(n,e),o=n[2]-e[2]*fe(n,e),s=Math.hypot(r,t,o);r/=s,t/=s,o/=s;let i=[r,t,o],l=yo(e,i);return{u:i,v:l}}function Mo(e){if(e.local2D)return;let n=Po(e.normal),r=[],t=1/0,o=1/0,s=-1/0,i=-1/0;for(let l of e.polygon.vertices){let c=fe(l,n.u),a=fe(l,n.v);r.push([c,a]),c<t&&(t=c),c>s&&(s=c),a<o&&(o=a),a>i&&(i=a)}e.local2D=r,e.bbox2D={min:[t,o],max:[s,i]},e.basis=n}function vo(e,n){let r=[],t=1/0,o=1/0,s=-1/0,i=-1/0;for(let l of e.vertices){let c=fe(l,n.u),a=fe(l,n.v);r.push([c,a]),c<t&&(t=c),c>s&&(s=c),a<o&&(o=a),a>i&&(i=a)}return{local2D:r,bbox2D:{min:[t,o],max:[s,i]}}}function Ao(e,n){return e.max[0]>=n.min[0]&&e.min[0]<=n.max[0]&&e.max[1]>=n.min[1]&&e.min[1]<=n.max[1]}function Tt(e,n){let r=!1;for(let t=0,o=n.length-1;t<n.length;o=t++){let s=n[t],i=n[o];s[1]>e[1]!=i[1]>e[1]&&e[0]<(i[0]-s[0])*(e[1]-s[1])/(i[1]-s[1]+1e-30)+s[0]&&(r=!r)}return r}function wt(e){let n=0,r=0;for(let t of e)n+=t[0],r+=t[1];return[n/e.length,r/e.length]}function Co(e,n){let r=wt(e),t=wt(n),o=1e-4,s=0;for(let a of e){let u=[a[0]+(r[0]-a[0])*o,a[1]+(r[1]-a[1])*o];Tt(u,n)&&s++}let i=0;for(let a of n){let u=[a[0]+(t[0]-a[0])*o,a[1]+(t[1]-a[1])*o];Tt(u,e)&&i++}let l=s/e.length,c=i/n.length;return Math.max(l,c)}function Vo(e,n){let r=e.normal[0],t=e.normal[1],o=e.normal[2],s=Math.abs(r),i=Math.abs(t),l=Math.abs(o),c=r;i>s&&i>l?c=t:l>s&&l>i&&(c=o),c<0&&(r=-r,t=-t,o=-o);let a=Math.round(r/.05),u=Math.round(t/.05),f=Math.round(o/.05),g=e.d*(e.normal[0]===r&&e.normal[1]===t&&e.normal[2]===o?1:-1),m=Math.round(g/(n*2));return`${a},${u},${f}|${m}`}function So(e,n,r,t){let o=fe(e.normal,n.normal);if(Math.abs(o)<1-r)return!1;let s=o>0?1:-1;return Math.abs(e.d-s*n.d)<t}function It(e,n){let r=ho(n,e.centroid);return fe(e.normal,r)>0}function Et(e,n){if(!e||e.length<2)return new Set;let r=n?.normalTolerance??.001,t=n?.distanceTolerance??.05,o=n?.overlapFraction??.7,s=[];for(let m=0;m<e.length;m++){let p=bo(e[m],m);p&&s.push(p)}if(s.length<2)return new Set;let i=0,l=0,c=0,a=0;for(let m of s)i+=m.centroid[0]*m.area,l+=m.centroid[1]*m.area,c+=m.centroid[2]*m.area,a+=m.area;let u=a>0?[i/a,l/a,c/a]:[0,0,0],f=new Map;for(let m of s){let p=Vo(m,t),d=f.get(p);d||(d=[],f.set(p,d)),d.push(m)}let g=new Set;for(let m of f.values())if(!(m.length<2))for(let p=0;p<m.length;p++){let d=m[p];if(!g.has(d.index))for(let y=p+1;y<m.length;y++){let b=m[y];if(g.has(b.index)||!So(d,b,r,t))continue;Mo(d);let M=vo(b.polygon,d.basis);if(!Ao(d.bbox2D,M.bbox2D)||Co(d.local2D,M.local2D)<o)continue;let P=It(d,u),x=It(b,u),A;if(P&&!x?A=d:x&&!P?A=b:A=d.area<b.area?d:b,g.add(A.index),A===d)break}}return g}function Ln(e,n){if(!e||e.length<2)return e??[];let r=Et(e,n);if(r.size===0)return e;let t=[];for(let o=0;o<e.length;o++)r.has(o)||t.push(e[o]);return t}var To=4,wo=8,Io=.001,Eo=1e-9,Oo=1e6,Ro=1e6,ve=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Nn=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],Fe=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],Ae=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],_t=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],Nt=e=>Math.hypot(e[0],e[1],e[2]);function $e(e){let n=Nt(e);return n<=Eo?null:[e[0]/n,e[1]/n,e[2]/n]}function Ue(e,n){return Math.round(e*n)/n}function le(e){return Ue(e,Oo)}function kn(e){return Ue(e,Ro)}function _n(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function ge(e){return`${le(e[0])},${le(e[1])}`}function Lo(e){let n=ge(e.a),r=ge(e.b);return n<r?`${n}|${r}`:`${r}|${n}`}function Re(e){return`${e[0]},${e[1]},${e[2]}`}function Gt(e,n){let r=Re(e),t=Re(n);return r<t?`${r}|${t}`:`${t}|${r}`}function Gn(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Ot(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",Gn(e.data)].join("|")}function Dt(e){let n=e.vertices;if(!n||n.length<3)return null;let r=n[0],t=[0,0,0];for(let s=1;s<n.length-1;s++)t=Nn(t,_t(ve(n[s],r),ve(n[s+1],r)));let o=$e(t);return o?{normal:o,d:Ae(o,r)}:null}function ko(e,n,r){return Ae(e.normal,n.normal)>1-r&&Math.abs(e.d-n.d)<=r}function _o(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function No(e,n){let r=n[e[0]]?.data,t=Gn(r);for(let o of e)if(Gn(n[o].data)!==t)return;return r?{...r}:void 0}function Go(e,n){let r=e.map(c=>_o(c)?Dt(c):null),t=r.map(Boolean),o=new Map;for(let c=0;c<e.length;c++){if(!r[c])continue;let a=e[c].vertices;for(let u=0;u<a.length;u++){let f=Gt(a[u],a[(u+1)%a.length]),g=o.get(f),m={polygon:c,edge:u};g?g.push(m):o.set(f,[m])}}let s=e.map(()=>new Set);for(let c of o.values())if(!(c.length<2))for(let a=0;a<c.length;a++)for(let u=a+1;u<c.length;u++){let f=c[a].polygon,g=c[u].polygon,m=r[f],p=r[g];!m||!p||Ot(e[f])===Ot(e[g])&&ko(m,p,n)&&(s[f].add(g),s[g].add(f))}let i=new Set,l=[];for(let c=0;c<e.length;c++){if(!t[c]||i.has(c))continue;let a=[],u=[c];for(i.add(c);u.length>0;){let f=u.shift();a.push(f);for(let g of s[f])i.has(g)||(i.add(g),u.push(g))}l.push(a)}return{groups:l}}function Do(e,n){let r=new Set(e),t=new Map;for(let s of e){let i=n[s].vertices;for(let l=0;l<i.length;l++){let c=Gt(i[l],i[(l+1)%i.length]),a=t.get(c),u={polygon:s,edge:l};a?a.push(u):t.set(c,[u])}}let o=[];for(let s of t.values()){let i=s.filter(l=>r.has(l.polygon));if(i.length===1){let l=i[0],c=n[l.polygon].vertices;o.push({a:c[l.edge],b:c[(l.edge+1)%c.length]})}else if(i.length!==2)return null}return o}function zo(e){let n=new Map;for(let r of e)n.set(Re(r.a),(n.get(Re(r.a))??0)+1),n.set(Re(r.b),(n.get(Re(r.b))??0)+1);for(let r of n.values())if(r%2!==0)return!1;return!0}function zt(e){let n=[e[0],e[1],e[2]],r=Math.abs(n[0])>=Math.abs(n[1])&&Math.abs(n[0])>=Math.abs(n[2])?0:Math.abs(n[1])>=Math.abs(n[2])?1:2;return n[r]<0?[-n[0],-n[1],-n[2]]:n}function Uo(e){let n=zt(e);return`${Ue(n[0],1e3)},${Ue(n[1],1e3)},${Ue(n[2],1e3)}`}function Fo(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],r=ve(n,Fe(e,Ae(n,e)));return $e(r)??[1,0,0]}function $o(e,n,r){let t=new Map;for(let s of e){let i=ve(s.b,s.a),l=ve(i,Fe(n,Ae(i,n))),c=$e(l);if(!c)continue;let a=zt(c),u=Uo(a),f=Nt(l),g=t.get(u);g?g.weight+=f:t.set(u,{axis:a,weight:f})}let o=[...t.values()].sort((s,i)=>i.weight-s.weight).slice(0,r).map(s=>s.axis);return o.length===0&&o.push(Fo(n)),o}function Rt(e,n,r,t){let o=ve(e,n);return[le(Ae(o,r)),le(Ae(o,t))]}function Bo(e){let n=[...e].sort((t,o)=>t-o),r=[];for(let t of n)(r.length===0||Math.abs(t-r[r.length-1])>1e-7)&&r.push(t);return r}function ze(e,n){let[r,t]=e.a,[o,s]=e.b,i=(n-r)/(o-r);return le(t+(s-t)*i)}function Dn(e){let n=[];for(let t of e)(n.length===0||Math.abs(t[0]-n[n.length-1][0])>1e-7||Math.abs(t[1]-n[n.length-1][1])>1e-7)&&n.push(t);n.length>1&&Math.abs(n[0][0]-n[n.length-1][0])<=1e-7&&Math.abs(n[0][1]-n[n.length-1][1])<=1e-7&&n.pop();let r=[];for(let t=0;t<n.length;t++){let o=n[(t-1+n.length)%n.length],s=n[t],i=n[(t+1)%n.length],l=(s[0]-o[0])*(i[1]-s[1])-(s[1]-o[1])*(i[0]-s[0]);Math.abs(l)>1e-8&&r.push(s)}return r}function en(e){let n=0;for(let r=0;r<e.length;r++){let t=e[r],o=e[(r+1)%e.length];n+=t[0]*o[1]-o[0]*t[1]}return n/2}function Lt(e){let n=1/0,r=1/0,t=-1/0,o=-1/0;for(let[s,i]of e)n=Math.min(n,s),r=Math.min(r,i),t=Math.max(t,s),o=Math.max(o,i);return{minX:n,minY:r,maxX:t,maxY:o}}function jo(e,n){let r=Lt(e),t=Lt(n);return!(r.maxX<t.minX-1e-7||t.maxX<r.minX-1e-7||r.maxY<t.minY-1e-7||t.maxY<r.minY-1e-7)}function Je(e){return Math.abs(en(e))}function Xo(e){if(e.length<3)return!1;let n=0;for(let r=0;r<e.length;r++){let t=e[r],o=e[(r+1)%e.length],s=e[(r+2)%e.length],i=(o[0]-t[0])*(s[1]-o[1])-(o[1]-t[1])*(s[0]-o[0]);if(Math.abs(i)<=1e-8)continue;let l=i>0?1:-1;if(n===0)n=l;else if(n!==l)return!1}return!0}function Yo(e,n,r){let t=r[0]-n[0],o=r[1]-n[1],s=e[0]-n[0],i=e[1]-n[1],l=t*i-o*s,c=Math.hypot(t,o);if(c<=1e-9||Math.abs(l)>Math.max(1e-8,c*1e-8))return!1;let a=s*t+i*o;return a>=-1e-8&&a<=t*t+o*o+1e-8}function Ho(e,n,r){let t=r[0]-n[0],o=r[1]-n[1],s=t*t+o*o;return s<=1e-12?0:((e[0]-n[0])*t+(e[1]-n[1])*o)/s}function kt(e,n){let r=[];for(let t=0;t<e.length;t++){let o=e[t],s=e[(t+1)%e.length],i=[{t:0,point:o},{t:1,point:s}];for(let c of n)_n(c,o)||_n(c,s)||Yo(c,o,s)&&i.push({t:Ho(c,o,s),point:c});i.sort((c,a)=>c.t-a.t);let l=[];for(let c of i)l.some(a=>Math.abs(a.t-c.t)<=1e-8||_n(a.point,c.point))||l.push(c);for(let c=0;c<l.length-1;c++){let a=l[c].point,u=l[c+1].point;Math.hypot(u[0]-a[0],u[1]-a[1])<=1e-8||r.push({a:[le(a[0]),le(a[1])],b:[le(u[0]),le(u[1])]})}}return r}function Ko(e,n){if(!jo(e,n))return null;let r=[...kt(e,n),...kt(n,e)],t=new Map;for(let d of r){let y=Lo(d),b=t.get(y);b?b.push(d):t.set(y,[d])}let o=!1,s=[];for(let d of t.values()){if(d.length===1){s.push(d[0]);continue}o=!0;let y=d.filter(M=>ge(M.a)<ge(M.b)).length,b=d.length-y;if(y!==b)return null}if(!o||s.length<3)return null;let i=new Map;for(let d of s){let y=ge(d.a);if(i.has(y))return null;i.set(y,d)}let l=s[0],c=ge(l.a),a=[],u=new Set,f=c;for(let d=0;d<=s.length;d++){let y=i.get(f);if(!y)return null;let b=`${ge(y.a)}>${ge(y.b)}`;if(u.has(b))return null;if(u.add(b),a.push(y.a),f=ge(y.b),f===c)break}if(f!==c||u.size!==s.length)return null;let g=Dn(a);if(g.length<3||!Xo(g))return null;let m=Je(g),p=Je(e)+Je(n);return Math.abs(m-p)>Math.max(1e-5,p*1e-5)?null:en(g)>=0?g:[...g].reverse()}function Wo(e){let n=e.map(Dn).filter(t=>t.length>=3&&Je(t)>1e-8),r=!0;for(;r;){r=!1;for(let t=0;t<n.length;t++){for(let o=t+1;o<n.length;o++){let s=Ko(n[t],n[o]);if(s){n[t]=s,n.splice(o,1),r=!0;break}}if(r)break}}return n}function Zo(e,n,r){let t=new Map;return o=>{let s=le(o[0]),i=le(o[1]),l=`${s},${i}`,c=t.get(l);if(c)return[c[0],c[1],c[2]];let a=Nn(e,Nn(Fe(n,s),Fe(r,i))),u=[kn(a[0]),kn(a[1]),kn(a[2])];return t.set(l,u),[u[0],u[1],u[2]]}}function Qo(e,n,r,t,o){let s=r[0]?.a;if(!s)return null;let i=$e(ve(o,Fe(t,Ae(o,t))));if(!i)return null;let l=$e(_t(t,i));if(!l)return null;let c=[],a=[];for(let y of r){let b=Rt(y.a,s,i,l),M=Rt(y.b,s,i,l);Math.hypot(b[0]-M[0],b[1]-M[1])<=1e-7||(c.push({a:b,b:M}),a.push(b[0],M[0]))}let u=Bo(a);if(c.length<3||u.length<2)return null;let f=n[e[0]].color,g=No(e,n),m=[];for(let y=0;y<u.length-1;y++){let b=u[y],M=u[y+1];if(M-b<=1e-7)continue;let v=(b+M)/2,P=c.filter(x=>{let A=Math.min(x.a[0],x.b[0]),T=Math.max(x.a[0],x.b[0]);return A<v&&v<T&&Math.abs(x.a[0]-x.b[0])>1e-7}).map(x=>({segment:x,yMid:ze(x,v)})).sort((x,A)=>x.yMid-A.yMid);if(P.length!==0){if(P.length%2!==0)return null;for(let x=0;x<P.length;x+=2){let A=P[x].segment,T=P[x+1].segment,V=ze(A,b),w=ze(A,M),O=ze(T,b),L=ze(T,M),U=Dn([[b,V],[M,w],[M,L],[b,O]]);if(U.length<3||Math.abs(en(U))<=1e-8)continue;let R=en(U)>0?U:[...U].reverse();m.push(R)}}}if(m.length===0)return null;let p=Zo(s,i,l),d=Wo(m).map(y=>({vertices:y.map(p),...f?{color:f}:{},...g?{data:g}:{}}));return ce(d)}function qo(e,n,r){let t=Do(e,n);if(!t||t.length<3||!zo(t))return null;let o=Dt(n[e[0]]);if(!o)return null;let s=null;for(let i of $o(t,o.normal,r)){let l=Qo(e,n,t,o.normal,i);l&&(!s||l.length<s.length)&&(s=l)}return!s||s.length>=e.length?null:s}function zn(e,n={}){let r=n.minGroupPolygons??To,t=n.maxCandidateAxes??wo,o=n.planeEpsilon??Io,s=e??[];if(s.length<r)return s;let{groups:i}=Go(s,o);if(i.length===0)return s;let l=new Map,c=new Set;for(let u of i){if(u.length<r)continue;let f=qo(u,s,t);if(f){l.set(u[0],f);for(let g of u)c.add(g)}}if(l.size===0)return s;let a=[];for(let u=0;u<s.length;u++){let f=l.get(u);if(f){a.push(...f);continue}c.has(u)||a.push(s[u])}return a}function Jo(e){let n=e.vertices;if(!n||n.length<3)return null;let r=0,t=0,o=0;for(let[R,D,k]of n)r+=R,t+=D,o+=k;let s=1/n.length;r*=s,t*=s,o*=s;let i=n[0],l=n[1],c=n[2],a=l[0]-i[0],u=l[1]-i[1],f=l[2]-i[2],g=c[0]-i[0],m=c[1]-i[1],p=c[2]-i[2],d=u*p-f*m,y=f*g-a*p,b=a*m-u*g,M=Math.hypot(d,y,b);if(M<1e-9)return null;d/=M,y/=M,b/=M;let v=n.length-2,P=new Float64Array(v*9),x=0;for(let R=1;R<n.length-1;R++){let D=n[0],k=n[R],_=n[R+1];P[x++]=D[0],P[x++]=D[1],P[x++]=D[2],P[x++]=k[0],P[x++]=k[1],P[x++]=k[2],P[x++]=_[0],P[x++]=_[1],P[x++]=_[2]}let A=0,T=1/0,V=1/0,w=1/0,O=-1/0,L=-1/0,U=-1/0;for(let[R,D,k]of n){let _=R-r,E=D-t,C=k-o,h=_*_+E*E+C*C;h>A&&(A=h),R<T&&(T=R),R>O&&(O=R),D<V&&(V=D),D>L&&(L=D),k<w&&(w=k),k>U&&(U=k)}return{centroid:[r,t,o],normal:[d,y,b],vertices:n,triFlat:P,bcx:r,bcy:t,bcz:o,br2:A,minX:T,minY:V,minZ:w,maxX:O,maxY:L,maxZ:U}}function es(e,n,r,t,o,s,i,l){let c=i[l],a=i[l+1],u=i[l+2],f=i[l+3]-c,g=i[l+4]-a,m=i[l+5]-u,p=i[l+6]-c,d=i[l+7]-a,y=i[l+8]-u,b=o*y-s*d,M=s*p-t*y,v=t*d-o*p,P=f*b+g*M+m*v;if(P>-1e-9&&P<1e-9)return!1;let x=1/P,A=e-c,T=n-a,V=r-u,w=x*(A*b+T*M+V*v);if(w<0||w>1)return!1;let O=T*m-V*g,L=V*f-A*m,U=A*g-T*f,R=x*(t*O+o*L+s*U);return R<0||w+R>1?!1:x*(p*O+d*L+y*U)>.001}function ns(e,n,r,t,o,s,i){let l=i.bcx-e,c=i.bcy-n,a=i.bcz-r,u=l*t+c*o+a*s,f=l-u*t,g=c-u*o,m=a-u*s;if(f*f+g*g+m*m>i.br2)return!1;let p=i.triFlat,d=p.length;for(let y=0;y<d;y+=9)if(es(e,n,r,t,o,s,p,y))return!0;return!1}var Be=9,ts=6,ne=12;function Un(e,n,r,t,o,s){let i=t-e,l=o-n,c=s-r;return i*l+l*c+c*i}function rs(e){let n=[];for(let A=0;A<e.length;A++)e[A]&&n.push(A);let r=n.length,t=new Int32Array(r);for(let A=0;A<r;A++)t[A]=n[A];let o=new Float64Array(r),s=new Float64Array(r),i=new Float64Array(r);for(let A=0;A<r;A++){let T=e[t[A]];o[A]=(T.minX+T.maxX)*.5,s[A]=(T.minY+T.maxY)*.5,i[A]=(T.minZ+T.maxZ)*.5}let l=2*Math.max(1,r)+1,c=new Float64Array(l*Be),a=0,u=new Float64Array(ne),f=new Float64Array(ne),g=new Float64Array(ne),m=new Float64Array(ne),p=new Float64Array(ne),d=new Float64Array(ne),y=new Int32Array(ne),b=new Float64Array(ne-1),M=new Int32Array(ne-1),v=new Float64Array(ne-1),P=new Int32Array(ne-1);function x(A,T){let V=a++,w=V*Be,O=T-A,L=1/0,U=1/0,R=1/0,D=-1/0,k=-1/0,_=-1/0;for(let $=A;$<T;$++){let Y=e[t[$]];Y.minX<L&&(L=Y.minX),Y.maxX>D&&(D=Y.maxX),Y.minY<U&&(U=Y.minY),Y.maxY>k&&(k=Y.maxY),Y.minZ<R&&(R=Y.minZ),Y.maxZ>_&&(_=Y.maxZ)}if(c[w]=L,c[w+1]=U,c[w+2]=R,c[w+3]=D,c[w+4]=k,c[w+5]=_,O<=ts)return c[w+6]=1,c[w+7]=A,c[w+8]=T,V;let E=1/0,C=1/0,h=1/0,S=-1/0,I=-1/0,G=-1/0;for(let $=A;$<T;$++)o[$]<E&&(E=o[$]),o[$]>S&&(S=o[$]),s[$]<C&&(C=s[$]),s[$]>I&&(I=s[$]),i[$]<h&&(h=i[$]),i[$]>G&&(G=i[$]);let N=S-E,F=I-C,z=G-h;if(N===0&&F===0&&z===0)return c[w+6]=1,c[w+7]=A,c[w+8]=T,V;let X=Un(L,U,R,D,k,_),H=X>0?1/X:0,K=O+1,Z=0,J=0;for(let $=0;$<3;$++){let Y=$===0?E:$===1?C:h,se=$===0?N:$===1?F:z;if(se===0)continue;let de=$===0?o:$===1?s:i,Pe=ne/se;u.fill(1/0),f.fill(1/0),g.fill(1/0),m.fill(-1/0),p.fill(-1/0),d.fill(-1/0),y.fill(0);for(let B=A;B<T;B++){let j=(de[B]-Y)*Pe|0;j>=ne&&(j=ne-1);let ie=e[t[B]];ie.minX<u[j]&&(u[j]=ie.minX),ie.maxX>m[j]&&(m[j]=ie.maxX),ie.minY<f[j]&&(f[j]=ie.minY),ie.maxY>p[j]&&(p[j]=ie.maxY),ie.minZ<g[j]&&(g[j]=ie.minZ),ie.maxZ>d[j]&&(d[j]=ie.maxZ),y[j]++}let Te=1/0,we=1/0,hn=1/0,yn=-1/0,bn=-1/0,Pn=-1/0,ft=0;for(let B=0;B<ne-1;B++)u[B]<Te&&(Te=u[B]),m[B]>yn&&(yn=m[B]),f[B]<we&&(we=f[B]),p[B]>bn&&(bn=p[B]),g[B]<hn&&(hn=g[B]),d[B]>Pn&&(Pn=d[B]),ft+=y[B],b[B]=Un(Te,we,hn,yn,bn,Pn),M[B]=ft;let Mn=1/0,vn=1/0,An=1/0,Cn=-1/0,Vn=-1/0,Sn=-1/0,mt=0;for(let B=ne-2;B>=0;B--){let j=B+1;u[j]<Mn&&(Mn=u[j]),m[j]>Cn&&(Cn=m[j]),f[j]<vn&&(vn=f[j]),p[j]>Vn&&(Vn=p[j]),g[j]<An&&(An=g[j]),d[j]>Sn&&(Sn=d[j]),mt+=y[j],v[B]=Un(Mn,vn,An,Cn,Vn,Sn),P[B]=mt}for(let B=0;B<ne-1;B++){if(M[B]===0||P[B]===0)continue;let j=.125+(b[B]*M[B]+v[B]*P[B])*H;j<K&&(K=j,Z=$,J=Y+(B+1)/Pe)}}let oe=Z===0?o:Z===1?s:i,Q=A,q=T-1;for(;Q<=q;)if(oe[Q]<J)Q++;else{let $=t[Q];t[Q]=t[q],t[q]=$;let Y=o[Q];o[Q]=o[q],o[q]=Y;let se=s[Q];s[Q]=s[q],s[q]=se;let de=i[Q];i[Q]=i[q],i[q]=de,q--}let ae=Q;(ae===A||ae===T)&&(ae=A+T>>1),c[w+6]=0;let re=x(A,ae),W=x(ae,T);return c[V*Be+7]=re,c[V*Be+8]=W,V}return r>0&&x(0,r),{data:c,nodeCount:a,polyIndices:t,meta:e}}function Ut(e,n,r,t,o,s,i,l,c){if(l.nodeCount===0)return!1;let{data:a,polyIndices:u,meta:f}=l,g=t!==0?1/t:t>=0?1/0:-1/0,m=o!==0?1/o:o>=0?1/0:-1/0,p=s!==0?1/s:s>=0?1/0:-1/0,d=0;for(c[d++]=0;d>0;){let b=c[--d]*Be,M=(a[b]-e)*g,v=(a[b+3]-e)*g,P=M<v?M:v,x=M<v?v:M,A=(a[b+1]-n)*m,T=(a[b+4]-n)*m,V=A<T?A:T,w=A<T?T:A;if(P>w||V>x)continue;V>P&&(P=V),w<x&&(x=w);let O=(a[b+2]-r)*p,L=(a[b+5]-r)*p,U=O<L?O:L,R=O<L?L:O;if(!(P>R||U>x)&&(R<x&&(x=R),!(x<.001)))if(a[b+6]===1){let D=a[b+7]|0,k=a[b+8]|0;for(let _=D;_<k;_++){let E=u[_];if(E===i)continue;let C=f[E];if(C&&ns(e,n,r,t,o,s,C))return!0}}else c[d++]=a[b+7]|0,c[d++]=a[b+8]|0}return!1}function os(e){let n=(1+Math.sqrt(5))/2,r=new Float64Array(e*3);for(let t=0;t<e;t++){let o=(t+.5)/e,s=Math.sqrt(Math.max(0,1-o*o)),i=2*Math.PI*(t/n);r[t*3]=s*Math.cos(i),r[t*3+1]=s*Math.sin(i),r[t*3+2]=o}return r}function ss(e){let n=Math.abs(e[0])>.9?0:1,r=Math.abs(e[0])>.9?1:0,t=r*e[2],o=-n*e[2],s=n*e[1]-r*e[0],i=Math.hypot(t,o,s);t/=i,o/=i,s/=i;let l=e[1]*s-e[2]*o,c=e[2]*t-e[0]*s,a=e[0]*o-e[1]*t;return{ux:t,uy:o,uz:s,vx:l,vy:c,vz:a}}function Ce(e,n){let r=n?.samples??8;if(e.length<4||r<1)return e;let t=e.map(Jo),o=os(r),s=[],i=rs(t),l=new Int32Array(Math.max(64,i.nodeCount)),c=192,a=new Float64Array(c);for(let u=0;u<e.length;u++){let f=t[u];if(!f){s.push(e[u]);continue}let g=f.normal[0],m=f.normal[1],p=f.normal[2],d=.001*g,y=.001*m,b=.001*p;{let k=f.centroid[0]+d,_=f.centroid[1]+y,E=f.centroid[2]+b;if(!Ut(k,_,E,g,m,p,u,i,l)){s.push(e[u]);continue}}let{ux:M,uy:v,uz:P,vx:x,vy:A,vz:T}=ss(f.normal),V=f.centroid[0],w=f.centroid[1],O=f.centroid[2],L=f.vertices,U=L.length,R=0;a[R++]=V+d,a[R++]=w+y,a[R++]=O+b;for(let k=0;k<U;k++){let _=L[k];a[R++]=_[0]+(V-_[0])*.08+d,a[R++]=_[1]+(w-_[1])*.08+y,a[R++]=_[2]+(O-_[2])*.08+b}for(let k=0;k<U;k++){let _=L[k],E=L[(k+1)%U],C=(_[0]+E[0])*.5,h=(_[1]+E[1])*.5,S=(_[2]+E[2])*.5;a[R++]=C+(V-C)*.08+d,a[R++]=h+(w-h)*.08+y,a[R++]=S+(O-S)*.08+b}let D=!1;e:for(let k=0;k<o.length;k+=3){let _=o[k],E=o[k+1],C=o[k+2],h=_*M+E*x+C*g,S=_*v+E*A+C*m,I=_*P+E*T+C*p;for(let G=0;G<R;G+=3){let N=a[G],F=a[G+1],z=a[G+2];if(!Ut(N,F,z,h,S,I,u,i,l)){D=!0;break e}}}D&&s.push(e[u])}return s}var is=3,cs=.03,as=.02,je={maxAngleDeg:is,maxPlaneDisplacement:cs,maxBoundaryDisplacement:as,isolatedPairs:!1},Le={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725,isolatedPairs:!0},tn=[{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.02},{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725},{maxAngleDeg:45,maxPlaneDisplacement:1,maxBoundaryDisplacement:.0725}],ls=[2,4,6,8,12],us=300,fs=.3,ms=300,gs=16,ps=.015,Ft=2.6,ds=3,xs=96,Ve={minGroupPolygons:2,maxCandidateAxes:24},hs={maxGap:0,internalBoundaryLength:0,excessBoundaryLength:0};function Xn(e,n={}){let r=n.meshResolution??"lossy",t=Fn(e,!1),o={baseline:t},s=t,i=te(t),l=(a,u=te(a))=>u>=i?!1:(s=a,i=u,!0),c=nn(t,n.rectCover);if(c!==t&&l(c),r==="lossy"&&n.approximateMerge!==!1){let a=Is(e),u=[],f=me(a,s,Le.maxBoundaryDisplacement).metrics,g=n.approximateMerge===void 0||n.approximateMerge===!0,m=(M,v=!0)=>!Ts(a,M.metrics,M.tolerance,v?f:null),p=(M,v)=>{l(M,v)},d=(M,v,P=Le.maxBoundaryDisplacement)=>{!g||v>i+Yt(i)||u.push({polygons:M,cost:v,maxBoundaryDisplacement:P})},y=$t(n.approximateMerge,g?t:void 0);for(let M=0;M<y.length;M++){let v=y[M],P=Fn(e,v,o),x=te(P),A=null,T=()=>(A??(A=me(a,P,v.maxBoundaryDisplacement)),A),V=!0;if(g||v.guard){let R=T();V=m(R,!!v.allowReferenceCracks)}if(!V&&x<i)continue;V&&(p(P,x),d(P,x,v.maxBoundaryDisplacement));let w=nn(P,n.rectCover),O=te(w),L=null,U=()=>(L??(L=me(a,w,v.maxBoundaryDisplacement)),L);if(w!==P&&O<i){let R=!0;(g||v.guard)&&(R=m(U(),!!v.allowReferenceCracks)),R&&(p(w,O),d(w,O,v.maxBoundaryDisplacement))}}if(g)for(let M of ys(e)){let v={baseline:ce(Ce(M))},P=te(v.baseline),x=!0,A=null,T=()=>(A??(A=me(a,v.baseline,Le.maxBoundaryDisplacement)),A);P<i&&(x=m(T())),x&&(p(v.baseline,P),d(v.baseline,P));let V=nn(v.baseline,n.rectCover);if(V!==v.baseline){let w=te(V);(w>=i||m(me(a,V,Le.maxBoundaryDisplacement)))&&(p(V,w),d(V,w))}for(let w of $t(n.approximateMerge,v.baseline)){let O=Fn(M,w,v),L=te(O),U=null,R=()=>(U??(U=me(a,O,w.maxBoundaryDisplacement)),U),D=!0;if(g||w.guard){let h=R();D=m(h,!!w.allowReferenceCracks)}if(!D&&L<i)continue;D&&(p(O,L),d(O,L,w.maxBoundaryDisplacement));let k=nn(O,n.rectCover),_=te(k),E=null,C=()=>(E??(E=me(a,k,w.maxBoundaryDisplacement)),E);if(k!==O&&_<i){let h=!0;(g||w.guard)&&(h=m(C(),!!w.allowReferenceCracks)),h&&(p(k,_),d(k,_,w.maxBoundaryDisplacement))}}}if(g)for(let M of tn){let v=qt({...M,isolatedPairs:!0}),P=$s(s,v);if(P===s)continue;let x=te(P);if(x>=i)continue;let A=me(a,P,v.maxBoundaryDisplacement);m(A)&&(p(P,x),d(P,x,v.maxBoundaryDisplacement))}let b=Cs(u,s,i,M=>(M.metrics??(M.metrics=me(a,M.polygons,M.maxBoundaryDisplacement).metrics),M.metrics),()=>me(a,s,Le.maxBoundaryDisplacement).metrics);b&&(s=b.polygons,i=b.cost)}return s}function ys(e){let n=bs(e);if(n.eligiblePolygons<24||n.colorCount<8)return[];let r=[],t=new Set;for(let o of ls){let s=Ps(e,o,n.colorCount);if(!s)continue;let i=vs(s);t.has(i)||(t.add(i),r.push(s))}return r}function bs(e){let n=new Set,r=0;for(let t of e)t.texture||t.material?.texture||t.uvs||t.textureTriangles?.length||Xt(t.color)&&(r+=1,n.add(t.color??"#cccccc"));return{eligiblePolygons:r,colorCount:n.size}}function Ps(e,n,r){let t=!1,o=new Set,s=e.map(i=>{if(i.texture||i.material?.texture||i.uvs||i.textureTriangles?.length)return i;let l=Xt(i.color);if(!l)return i;let c=Ms([Math.round(l[0]/n)*n,Math.round(l[1]/n)*n,Math.round(l[2]/n)*n]);return o.add(c),c===i.color?i:(t=!0,{...i,color:c})});return!t||o.size>=r?null:s}function Xt(e){let n=e??"#cccccc",r=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(n);if(r)return[parseInt(r[1]+r[1],16),parseInt(r[2]+r[2],16),parseInt(r[3]+r[3],16)];let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(n);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:null}function Ms(e){return`#${e.map(n=>Math.max(0,Math.min(255,Math.round(n))).toString(16).padStart(2,"0")).join("")}`}function vs(e){return e.map(n=>n.color??"").join("|")}function $t(e,n){if(e&&e!==!0)return typeof e.isolatedPairs=="boolean"?[{...e,guard:e.isolatedPairs===!1}]:[{...e,isolatedPairs:!0,guard:!1},{...e,isolatedPairs:!1,guard:!0}];if(n&&As(n))return[{...tn[0],isolatedPairs:!0,guard:!1,allowReferenceCracks:!0}];let r=[],t=new Set,o=n&&n.length>ms?[!0]:[!0,!1];for(let s=0;s<tn.length;s++){let i=tn[s];for(let l of o){let c={...i,isolatedPairs:l,guard:s>0||l===!1,allowReferenceCracks:!0},a=[c.maxAngleDeg,c.maxPlaneDisplacement,c.maxBoundaryDisplacement,c.isolatedPairs].join("|");t.has(a)||(t.add(a),r.push(c))}}return r.length===0?[{...Le,guard:!1}]:r}function As(e){return e.length<us?!1:Zt(e)/e.length<=fs}function te(e){let n=0;for(let r of e){let t=r.vertices.length,o=t<=4?0:Math.min(4,t-4)*.12,s=r.texture||r.material?.texture||r.textureTriangles?.length?.15:0;n+=1+o+s}return n}function Yt(e){return Math.max(gs,e*ps)}function Cs(e,n,r,t,o){if(e.length===0)return null;let s=Yt(r),i=e.find(u=>u.polygons===n),l=null,c=null,a=null;for(let u of e){if(u.polygons===n||u.cost>r+s)continue;let f=t(u);l??(l=i?t(i):o()),Ss(f,l)&&(!c||!a||Vs(u,f,c,a)<0)&&(c=u,a=f)}return c}function Vs(e,n,r,t){return n.maxGap-t.maxGap||n.internalBoundaryLength-t.internalBoundaryLength||n.excessBoundaryLength-t.excessBoundaryLength||e.cost-r.cost}function Ss(e,n){let r=Math.max(5e-4,n.maxGap*.02);if(e.maxGap<n.maxGap-r)return!0;if(e.maxGap>n.maxGap+r)return!1;let t=Math.max(8,n.internalBoundaryLength*.01);if(e.internalBoundaryLength<n.internalBoundaryLength-t)return!0;if(e.internalBoundaryLength>n.internalBoundaryLength+t)return!1;let o=Math.max(8,n.excessBoundaryLength*.01);return e.excessBoundaryLength<n.excessBoundaryLength-o}function Ts(e,n,r,t=null){if(!t)return n.internalBoundaryLength>0||n.excessBoundaryLength>r;let o=Math.max(r*.1,1e-6),s=t.maxGap+o,i=r<=.08?Math.max(s,Math.min(r*.75,.04)):s,l=Math.max(r*2,t.internalBoundaryLength*.15),c=Math.max(r*2,t.excessBoundaryLength*.15);return n.maxGap>i||n.internalBoundaryLength>t.internalBoundaryLength+l||n.excessBoundaryLength>t.excessBoundaryLength+c}function ws(e,n,r=0,t=Bn(e,r)){let o=e.edges,s=Ht(n),i=Bn(e,r),l=t>0?Os(e,t):null,c={...hs,excessBoundaryLength:Math.max(0,s.boundaryLength-o.boundaryLength)};for(let a of s.boundarySegments){let u=ke(a.a,a.b);if(o.boundaryKeys.has(u))continue;if(o.internalKeys.has(u)){c.internalBoundaryLength+=pe(a.a,a.b);continue}let f=l?ks(a,l,t):null;f!==null&&(c.maxGap=Math.max(c.maxGap,f),c.internalBoundaryLength+=pe(a.a,a.b))}return{metrics:c,tolerance:i}}function me(e,n,r=0){return ws(e,n,r,Es(e,r))}function Is(e){let n=Rs(e),r=n>0?Math.min(.08,Math.max(.001,n*.001)):0;return{edges:Ht(e),baseTolerance:r,polygonCount:e.length,indexes:new Map}}function Bn(e,n=0){return Math.max(e.baseTolerance,n*1.05)}function Es(e,n=0){return Math.max(Bn(e,n),e.baseTolerance*Ft,n*Ft)}function Os(e,n){let r=n.toFixed(6),t=e.indexes.get(r);if(t)return t;let o=Ls(e.edges.internalSegments,n);return e.indexes.set(r,o),o}function Ht(e){let n=new Map;for(let l of e)for(let c=0;c<l.vertices.length;c++){let a=l.vertices[c],u=l.vertices[(c+1)%l.vertices.length],f=ke(a,u),g=n.get(f);g?g.count+=1:n.set(f,{count:1,a,b:u})}let r=new Set,t=new Set,o=[],s=[],i=0;for(let[l,c]of n){let a={a:c.a,b:c.b};c.count===1?(r.add(l),o.push(a),i+=pe(a.a,a.b)):(t.add(l),s.push(a))}return{boundaryKeys:r,internalKeys:t,boundarySegments:o,internalSegments:s,boundaryLength:i}}function Rs(e){let n=1/0,r=1/0,t=1/0,o=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let[c,a,u]of l.vertices)n=Math.min(n,c),r=Math.min(r,a),t=Math.min(t,u),o=Math.max(o,c),s=Math.max(s,a),i=Math.max(i,u);return Number.isFinite(n)?Math.hypot(o-n,s-r,i-t):0}function Ls(e,n){let r=Math.max(n*2,1e-6),t=new Map;for(let o of e){let[s,i,l]=Kt(o,r),c=Wt(s,i,l),a=t.get(c);a?a.push(o):t.set(c,[o])}return{cellSize:r,cells:t}}function ks(e,n,r){let[t,o,s]=Kt(e,n.cellSize),i=null;for(let l=-1;l<=1;l++)for(let c=-1;c<=1;c++)for(let a=-1;a<=1;a++){let u=n.cells.get(Wt(t+l,o+c,s+a));if(u)for(let f of u){let g=_s(e,f);g<=r&&(i=i===null?g:Math.min(i,g))}}return i}function Kt(e,n){return[Math.floor((e.a[0]+e.b[0])/2/n),Math.floor((e.a[1]+e.b[1])/2/n),Math.floor((e.a[2]+e.b[2])/2/n)]}function Wt(e,n,r){return`${e},${n},${r}`}function _s(e,n){return Math.min(Math.max(pe(e.a,n.a),pe(e.b,n.b)),Math.max(pe(e.a,n.b),pe(e.b,n.a)))}function nn(e,n){if(n===!1)return e;let r=Ns(e,n);if(!r)return e;let t=zn(e,r);return t.length<e.length?t:e}function Ns(e,n){if(n&&n!==!0)return n;let r=e.length;return r>2200?null:r>1200?{...Ve,maxCandidateAxes:Math.min(Ve.maxCandidateAxes??24,2)}:r>300&&Zt(e)<=xs?{...Ve,maxCandidateAxes:Math.min(Ve.maxCandidateAxes??24,2)}:r>900?{...Ve,maxCandidateAxes:Math.min(Ve.maxCandidateAxes??24,4)}:Ve}function Zt(e){let n=0;for(let r of e)r.vertices.length===3&&(n+=1);return n}function Fn(e,n,r){let t=Ln(e),o=r?.baseline??ce(Ce(t));if(!n)return o;let s=n===!0?je:qt(n);if(s.isolatedPairs){let l=Ds(Gs(t,r),s),c=ce(l);return c.length<o.length?c:o}let i=ce(Ce(qs(t,s,r)));return i.length<o.length?i:o}function Qt(e,n){return n?(n.snapped||(n.snapped=on(e)),n.snapped):on(e)}function Gs(e,n){return n?(n.snappedInterior||(n.snappedInterior=Ce(Qt(e,n))),n.snappedInterior):Ce(on(e))}function qt(e){return{maxAngleDeg:e.maxAngleDeg??je.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??je.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??je.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??je.isolatedPairs}}function Ds(e,n){let r=e.map(f=>{let g=Ye(f);return g?{polygon:f,normal:g.normal,area:g.area,materialKey:Hn(f)}:null}),t=new Map;for(let f=0;f<e.length;f++){let g=e[f];if(!(g.vertices.length!==3||!r[f]))for(let m=0;m<g.vertices.length;m++){let p=ke(g.vertices[m],g.vertices[(m+1)%g.vertices.length]),d=t.get(p);d?d.push(f):t.set(p,[f])}}let o=[];for(let f of t.values()){if(f.length!==2)continue;let[g,m]=f,p=Qs(g,m,e,r,n);p&&o.push(p)}let s=new Set,i=new Map,l=new Set,c=zs(o),a=an(c.flatMap(f=>f.vertexMoves));for(let f of c){s.add(f.a),s.add(f.b);let g=Math.min(f.a,f.b);i.set(g,f.polygon),l.add(Math.max(f.a,f.b))}let u=[];for(let f=0;f<e.length;f++){let g=i.get(f);if(g){u.push(g);continue}l.has(f)||u.push(e[f])}return a.size>0?ln(u,a):u}function zs(e){return e.length>3e3?Us(e):Fs(e)}function Us(e){let n=new Map;for(let s of e)n.set(s.a,(n.get(s.a)??0)+1),n.set(s.b,(n.get(s.b)??0)+1);let r=[...e].sort((s,i)=>{let l=(n.get(s.a)??0)+(n.get(s.b)??0),c=(n.get(i.a)??0)+(n.get(i.b)??0);return l-c||s.score-i.score}),t=new Set,o=[];for(let s of r)t.has(s.a)||t.has(s.b)||(t.add(s.a),t.add(s.b),o.push(s));return o}function Fs(e){let n=new Map;for(let a=0;a<e.length;a++){let u=e[a],f=n.get(u.a);f?f.push(a):n.set(u.a,[a]);let g=n.get(u.b);g?g.push(a):n.set(u.b,[a])}let r=[],t=new Array(e.length).fill(!0),o=new Map,s=new jn;for(let[a,u]of n)o.set(a,u.length);let i=a=>(o.get(a.a)??0)+(o.get(a.b)??0),l=a=>{let u=e[a];s.push({degree:i(u),score:u.score,index:a})},c=(a,u)=>{if(!t[a])return;t[a]=!1;let f=e[a];for(let g of[f.a,f.b])o.set(g,(o.get(g)??0)-1),u.add(g)};for(let a=0;a<e.length;a++)l(a);for(;s.size()>0;){let a=s.pop();if(!t[a.index])continue;let u=e[a.index];if(i(u)!==a.degree){l(a.index);continue}r.push(u);let g=new Set;for(let m of[u.a,u.b])for(let p of n.get(m)??[])c(p,g);for(let m of g)for(let p of n.get(m)??[])t[p]&&l(p)}return r}var jn=class{constructor(){this.items=[]}size(){return this.items.length}push(n){this.items.push(n);let r=this.items.length-1;for(;r>0;){let t=r-1>>1;if($n(this.items[t],this.items[r])<=0)break;[this.items[t],this.items[r]]=[this.items[r],this.items[t]],r=t}}pop(){if(this.items.length===0)return null;let n=this.items[0],r=this.items.pop();if(this.items.length>0){this.items[0]=r;let t=0;for(;;){let o=t*2+1,s=o+1,i=t;if(o<this.items.length&&$n(this.items[o],this.items[i])<0&&(i=o),s<this.items.length&&$n(this.items[s],this.items[i])<0&&(i=s),i===t)break;[this.items[t],this.items[i]]=[this.items[i],this.items[t]],t=i}}return n}};function $n(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function $s(e,n){let r=e,t=te(r),o=Ys(r);for(let s=0;s<ds;s++){let i=Bs(r,n,o);if(!i)break;let l=te(i.polygons);if(l>=t)break;r=i.polygons,t=l,o=i.origins}return r===e?e:r}function Bs(e,n,r){let t=e.map(g=>{let m=Ye(g);return m?{polygon:g,normal:m.normal,area:m.area,materialKey:Hn(g)}:null}),o=new Map;for(let g=0;g<e.length;g++){let m=e[g];if(!(!t[g]||m.vertices.length<3))for(let p=0;p<m.vertices.length;p++){let d=ke(m.vertices[p],m.vertices[(p+1)%m.vertices.length]),y=o.get(d);y?y.push({polygon:g,edge:p}):o.set(d,[{polygon:g,edge:p}])}}let s=[];for(let g of o.values()){if(g.length!==2)continue;let[m,p]=g,d=js(m.polygon,m.edge,p.polygon,p.edge,e,t,n);d&&s.push(d)}if(s.length===0)return null;s.sort((g,m)=>m.score-g.score);let i=new Set,l=[];for(let g of s)i.has(g.a)||i.has(g.b)||(i.add(g.a),i.add(g.b),l.push(g));if(l.length===0)return null;let c=an(l.flatMap(g=>g.vertexMoves));if(!Xs(c,r,n.maxBoundaryDisplacement))return null;let a=ln(e,c),u=Hs(e,c,r),f=ce(a);return te(f)<te(e)?{polygons:f,origins:Ks(f,u)}:null}function js(e,n,r,t,o,s,i){let l=o[e],c=o[r],a=s[e],u=s[r];if(!a||!u||l.vertices.length===3&&c.vertices.length===3||!sr(l,c,a,u))return null;let f=Math.abs(ue(a.normal,u.normal)),g=Math.cos(i.maxAngleDeg*Math.PI/180);if(f<g)return null;let m=Bt(l,c,n)??Bt(c,l,t);if(!m||m.length<4||m.length>10)return null;let p=er(m);if(!p)return null;let d=0,y=0;for(let V of m){let w=Math.abs(un(V,p));d=Math.max(d,w),y+=w*w}if(d>Math.min(i.maxPlaneDisplacement,i.maxBoundaryDisplacement))return null;let b=m.map(V=>fn(V,p));if(!nr(b,p.normal))return null;let M=Ye({vertices:b});if(!M||ue(M.normal,a.normal)<.2||ue(M.normal,u.normal)<.2)return null;let v=[...m.map((V,w)=>({key:ee(V),target:b[w]})),...Jt([l,c],p)],P=ln([l,c],an(v)),x=te([l,c]),A=te(ce(P));if(A>=x)return null;let T=x-A-(y/m.length+d*.25+(1-f)*.1);return T<=0?null:{a:e,b:r,vertexMoves:v,score:T}}function Bt(e,n,r){let t=e.vertices,o=n.vertices,s=t[r],i=t[(r+1)%t.length],l=-1;for(let u=0;u<o.length;u++)if(ye(o[u],i)&&ye(o[(u+1)%o.length],s)){l=u;break}if(l<0)return null;let c=[],a=(r+1)%t.length;for(c.push(t[a]);a!==r;)a=(a+1)%t.length,c.push(t[a]);for(a=(l+2)%o.length;a!==l;){let u=o[a];ye(u,c[c.length-1])||c.push(u),a=(a+1)%o.length}return c.length>1&&ye(c[0],c[c.length-1])&&c.pop(),c}function Xs(e,n,r){for(let[t,o]of e){let s=Ws(t),i=n.get(t)??(s?[s]:[]);if(i.length===0)return!1;for(let l of i)if(pe(l,o)>r+1e-6)return!1}return!0}function Ys(e){let n=new Map;for(let r of e){for(let t of r.vertices)rn(n,ee(t),t);for(let t of r.textureTriangles??[])for(let o of t.vertices)rn(n,ee(o),o)}return n}function Hs(e,n,r){let t=new Map;for(let o of e){let s=[...o.vertices,...(o.textureTriangles??[]).flatMap(i=>i.vertices)];for(let i of s){let l=ee(i),c=n.get(l)??i,a=ee(c);for(let u of r.get(l)??[i])rn(t,a,u)}}return t}function Ks(e,n){let r=new Map;for(let t of e){let o=[...t.vertices,...(t.textureTriangles??[]).flatMap(s=>s.vertices)];for(let s of o){let i=ee(s);for(let l of n.get(i)??[s])rn(r,i,l)}}return r}function rn(e,n,r){let t=e.get(n);if(!t){e.set(n,[r]);return}let o=ee(r);t.some(s=>ee(s)===o)||t.push(r)}function Ws(e){let n=e.split(",").map(Number);return n.length===3&&n.every(Number.isFinite)?[n[0],n[1],n[2]]:null}function an(e){let n=new Map;for(let t of e){let o=n.get(t.key);o?(o.x+=t.target[0],o.y+=t.target[1],o.z+=t.target[2],o.count+=1):n.set(t.key,{x:t.target[0],y:t.target[1],z:t.target[2],count:1})}let r=new Map;for(let[t,o]of n)r.set(t,[o.x/o.count,o.y/o.count,o.z/o.count]);return r}function Zs(e,n){let r=[];for(let t=0;t<e.length;t++){let o=e[t].vertices,s=n[t]?.vertices;if(!s||s.length!==o.length)continue;for(let c=0;c<o.length;c++)r.push({key:ee(o[c]),target:s[c]});let i=e[t].textureTriangles??[],l=n[t]?.textureTriangles??[];for(let c=0;c<i.length;c++){let a=l[c];if(a)for(let u=0;u<i[c].vertices.length;u++)r.push({key:ee(i[c].vertices[u]),target:a.vertices[u]})}}return r}function Jt(e,n){let r=[];for(let t of e)for(let o of t.textureTriangles??[])for(let s of o.vertices)r.push({key:ee(s),target:fn(s,n)});return r}function ln(e,n){return e.map(r=>{let t=!1,o=l=>{let c=n.get(ee(l));return c?(t=!0,c):l},s=r.vertices.map(o),i=Yn(r.textureTriangles,o);return t?{...r,vertices:s,...i?{textureTriangles:i}:{}}:r})}function Qs(e,n,r,t,o){let s=r[e],i=r[n],l=t[e],c=t[n];if(!l||!c||s.vertices.length!==3||i.vertices.length!==3||!sr(s,i,l,c))return null;let a=Wn(s,i);if(!a)return null;let[u,f,g,m]=a;if((g+1)%i.vertices.length===m)return null;let d=Math.abs(ue(l.normal,c.normal)),y=Math.cos(o.maxAngleDeg*Math.PI/180);if(d<y)return null;let b=(f+1)%s.vertices.length,M=3-g-m,v=[s.vertices[f],s.vertices[b],s.vertices[u],i.vertices[M]],P=er(v);if(!P)return null;let x=0,A=0;for(let O of v){let L=Math.abs(un(O,P));x=Math.max(x,L),A+=L*L}if(x>Math.min(o.maxPlaneDisplacement,o.maxBoundaryDisplacement))return null;let T=v.map(O=>fn(O,P));if(!nr(T,P.normal))return null;let V=Ye({vertices:T});if(!V||ue(V.normal,l.normal)<.2||ue(V.normal,c.normal)<.2)return null;let w={vertices:v,color:s.color,...s.data?{data:{...s.data}}:{}};if(Kn(s,i)&&s.uvs&&i.uvs&&s.texture){w.texture=s.texture,w.uvs=[[...s.uvs[f]],[...s.uvs[b]],[...s.uvs[u]],[...i.uvs[M]]];let O=Js([s,i]);O?.length&&(w.textureTriangles=O)}return{a:e,b:n,polygon:w,vertexMoves:[...v.map((O,L)=>({key:ee(O),target:T[L]})),...Jt([s,i],P)],score:A/v.length+x*.25+(1-d)*.1}}function er(e){if(e.length<3)return null;let n=0,r=0,t=0,o=0,s=0,i=0;for(let c=0;c<e.length;c++){let a=e[c],u=e[(c+1)%e.length];n+=(a[1]-u[1])*(a[2]+u[2]),r+=(a[2]-u[2])*(a[0]+u[0]),t+=(a[0]-u[0])*(a[1]+u[1]),o+=a[0],s+=a[1],i+=a[2]}let l=ur([n,r,t]);return l?{normal:l,point:[o/e.length,s/e.length,i/e.length]}:null}function nr(e,n){let r=0;for(let t=0;t<e.length;t++){let o=e[t],s=e[(t+1)%e.length],i=e[(t+2)%e.length],l=ue(lr(Xe(s,o),Xe(i,s)),n);if(Math.abs(l)<=1e-9)continue;let c=l>0?1:-1;if(r===0)r=c;else if(r!==c)return!1}return!0}function qs(e,n,r){let t=Qt(e,r),o=si(t,n);if(o<=0)return t;let s=t.map(m=>{let p=Ye(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Hn(m)}:null}),i=ai(t,s),l=new Set,c=Array(t.length),a=[],u=(m,p)=>{c[m]=p};for(let m=0;m<t.length;m++){let p=s[m];if(l.has(m))continue;if(!p){u(m,t[m]);continue}let d=ui(m,s,i,l,o,n);for(let b of d)l.add(b);if(d.length<2){u(m,t[m]);continue}let y=ti(d,t,s,i,o,n);a.push(...y.vertexMoves);for(let b of d)u(b,y.polygons.get(b)??t[b])}let f=c.flatMap(m=>m?[m]:[]),g=a.length>0?ln(f,an(a)):f;return on(g)}function on(e){let n=or(e),r=1e-4;if(n<=0)return e;let t=ii(n),o=ci(r);return e.map(s=>{let i=f=>t.snap(f),l=s.vertices.map(i),c=s.uvs&&s.uvs.length===s.vertices.length?s.uvs.map(f=>o.snap(f)):void 0,a=Yn(s.textureTriangles,i),u={...s,vertices:l,...c?{uvs:c}:{},...a?{textureTriangles:a}:{}};return{...u,...u.texture?{textureTriangles:tr(u)}:{}}})}function tr(e){if(e.texture){if(e.textureTriangles?.length)return ni(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return ei(e.vertices,e.uvs)}}function Js(e){let n=e.flatMap(r=>tr(r)??[]);return n.length>0?n:void 0}function ei(e,n){let r=[];for(let t=1;t<e.length-1;t++)r.push({vertices:[[...e[0]],[...e[t]],[...e[t+1]]],uvs:[[...n[0]],[...n[t]],[...n[t+1]]]});return r}function ni(e){return e.map(n=>({vertices:n.vertices.map(r=>[...r]),uvs:n.uvs.map(r=>[...r])}))}function Yn(e,n){if(e?.length)return e.map(r=>({vertices:r.vertices.map(n),uvs:r.uvs.map(t=>[...t])}))}function ti(e,n,r,t,o,s){let i=rr(e,n,r,o,s);return i?oi(i):ri(e,n,r,t,o,s)}function ri(e,n,r,t,o,s){let i=new Set(e),l=[];for(let f of e)for(let g of t.get(f)??[]){if(f>=g||!i.has(g))continue;let m=rr([f,g],n,r,o,s);m&&l.push(m)}l.sort((f,g)=>g.score-f.score);let c=new Set,a=new Map,u=[];for(let f of l)if(!f.indices.some(g=>c.has(g))){u.push(...f.vertexMoves);for(let g=0;g<f.indices.length;g++){let m=f.indices[g];c.add(m),a.set(m,n[m])}}return{polygons:a,vertexMoves:u}}function oi(e){let n=new Map;for(let r=0;r<e.indices.length;r++)n.set(e.indices[r],e.source[r]);return{polygons:n,vertexMoves:e.vertexMoves}}function rr(e,n,r,t,o){let s=ir(e,r);if(!s||!cr(e,r,s,t,o))return null;let i=e.map(u=>n[u]),l=i.map(u=>gi(u,s)),c=te(ce(i)),a=te(ce(l));return a>=c?null:{indices:e,source:i,projected:l,vertexMoves:Zs(i,l),score:c-a}}function si(e,n){return or(e)<=0?0:n.maxPlaneDisplacement}function or(e){let n=1/0,r=1/0,t=1/0,o=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let[a,u,f]of c.vertices)n=Math.min(n,a),r=Math.min(r,u),t=Math.min(t,f),o=Math.max(o,a),s=Math.max(s,u),i=Math.max(i,f);if(!Number.isFinite(n))return 0;let l=Math.hypot(o-n,s-r,i-t);return l<=0?0:Math.min(.025,Math.max(1e-4,l*25e-5))}function ii(e){let n=new Map,r=o=>Math.floor(o/e),t=(o,s,i)=>`${o},${s},${i}`;return{snap(o){let s=r(o[0]),i=r(o[1]),l=r(o[2]);for(let f=-1;f<=1;f++)for(let g=-1;g<=1;g++)for(let m=-1;m<=1;m++){let p=n.get(t(s+f,i+g,l+m));if(p){for(let d of p)if(pe(o,d)<=e)return[d[0],d[1],d[2]]}}let c=[o[0],o[1],o[2]],a=t(s,i,l),u=n.get(a);return u?u.push(c):n.set(a,[c]),c}}}function ci(e){let n=new Map,r=o=>Math.floor(o/e),t=(o,s)=>`${o},${s}`;return{snap(o){let s=r(o[0]),i=r(o[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let g=n.get(t(s+u,i+f));if(g){for(let m of g)if(Math.hypot(o[0]-m[0],o[1]-m[1])<=e)return[m[0],m[1]]}}let l=[o[0],o[1]],c=t(s,i),a=n.get(c);return a?a.push(l):n.set(c,[l]),l}}}function Hn(e){return`${e.color??"#cccccc"}|${e.texture??""}|${e.uvs?"uv":"plain"}`}function Ye(e){let n=e.vertices;if(!n||n.length<3)return null;let r=0,t=0,o=0,s=n[0];for(let l=1;l<n.length-1;l++){let c=Xe(n[l],s),a=Xe(n[l+1],s),u=lr(c,a);r+=u[0],t+=u[1],o+=u[2]}let i=Math.hypot(r,t,o);return i<=1e-10?null:{normal:[r/i,t/i,o/i],area:i/2}}function ai(e,n){let r=new Map,t=new Map;for(let o=0;o<e.length;o++){let s=e[o];if(!(!n[o]||s.vertices.length<3))for(let i=0;i<s.vertices.length;i++){let l=ke(s.vertices[i],s.vertices[(i+1)%s.vertices.length]),c=r.get(l);c?c.push(o):r.set(l,[o])}}for(let o of r.values())for(let s=0;s<o.length;s++)for(let i=s+1;i<o.length;i++){let l=o[s],c=o[i];li(e[l],e[c],n[l],n[c])&&(jt(t,l,c),jt(t,c,l))}return t}function li(e,n,r,t){if(!r||!t||r.materialKey!==t.materialKey||!!e.uvs!=!!n.uvs)return!1;if(sn(e)||sn(n))return Kn(e,n);if(!e.uvs||!n.uvs)return!0;let o=Wn(e,n);if(!o)return!1;let[s,i,l,c]=o;return cn(e.uvs[s],n.uvs[l])&&cn(e.uvs[i],n.uvs[c])}function sr(e,n,r,t){return r.materialKey!==t.materialKey?!1:sn(e)||sn(n)?Kn(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function sn(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Kn(e,n){if(!e.texture||!n.texture||e.texture!==n.texture||e.material?.texture||n.material?.texture||!e.uvs||!n.uvs||e.uvs.length!==e.vertices.length||n.uvs.length!==n.vertices.length)return!1;let r=Wn(e,n);if(!r)return!1;let[t,o,s,i]=r;return cn(e.uvs[t],n.uvs[s])&&cn(e.uvs[o],n.uvs[i])}function jt(e,n,r){let t=e.get(n);t?t.add(r):e.set(n,new Set([r]))}function ui(e,n,r,t,o,s){let i=[e],l=new Set([e]),c=[e];for(;c.length>0;){let a=c.shift();for(let u of r.get(a)??[]){if(t.has(u)||l.has(u))continue;let f=n[u],g=n[e];!f||!g||f.materialKey===g.materialKey&&fi([...i,u],n,o,s)&&(i.push(u),l.add(u),c.push(u))}}return i}function fi(e,n,r,t){let o=ir(e,n);return!!o&&cr(e,n,o,r,t)}function ir(e,n){let r=n[e[0]];if(!r)return null;let t=0,o=0,s=0,i=0,l=0,c=0,a=0;for(let m of e){let p=n[m];if(!p)return null;let d=ue(r.normal,p.normal)<0?-1:1,y=Math.max(p.area,1e-6);t+=p.normal[0]*d*y,o+=p.normal[1]*d*y,s+=p.normal[2]*d*y;for(let b of p.polygon.vertices)i+=b[0],l+=b[1],c+=b[2],a+=1}let u=ur([t,o,s]);if(!u||a===0)return null;let f=ar(e,n),g=mi(e,n,u,f);if(g){let m=(g.min+g.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m]}}return{normal:u,point:[i/a,l/a,c/a]}}function mi(e,n,r,t){let o=1/0,s=-1/0;for(let i of e){let l=n[i];if(l)for(let c of l.polygon.vertices){if(!t.has(ee(c)))continue;let a=ue(c,r);o=Math.min(o,a),s=Math.max(s,a)}}return Number.isFinite(o)&&Number.isFinite(s)?{min:o,max:s}:null}function cr(e,n,r,t,o){let s=Math.cos(o.maxAngleDeg*Math.PI/180),i=ar(e,n);for(let l of e){let c=n[l];if(!c||Math.abs(ue(c.normal,r.normal))<s)return!1;for(let a of c.polygon.vertices){let u=i.has(ee(a))?o.maxBoundaryDisplacement:t;if(Math.abs(un(a,r))>u)return!1}}return!0}function ar(e,n){let r=new Map;for(let o of e){let s=n[o];if(!s)continue;let i=s.polygon.vertices;for(let l=0;l<i.length;l++){let c=i[l],a=i[(l+1)%i.length],u=ke(c,a),f=r.get(u);f?f.count+=1:r.set(u,{count:1,a:c,b:a})}}let t=new Set;for(let o of r.values())o.count===1&&(t.add(ee(o.a)),t.add(ee(o.b)));return t}function gi(e,n){let r=o=>fn(o,n),t=Yn(e.textureTriangles,r);return{...e,vertices:e.vertices.map(r),...t?{textureTriangles:t}:{}}}function Wn(e,n){for(let r=0;r<e.vertices.length;r++){let t=(r+1)%e.vertices.length;for(let o=0;o<n.vertices.length;o++){let s=(o+1)%n.vertices.length;if(ye(e.vertices[r],n.vertices[o])&&ye(e.vertices[t],n.vertices[s]))return[r,t,o,s];if(ye(e.vertices[r],n.vertices[s])&&ye(e.vertices[t],n.vertices[o]))return[r,t,s,o]}}return null}function ke(e,n){let r=ee(e),t=ee(n);return r<t?`${r}|${t}`:`${t}|${r}`}function ee(e){return`${e[0]},${e[1]},${e[2]}`}function ye(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function cn(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function Xe(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function lr(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function ue(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function pe(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function ur(e){let n=Math.hypot(e[0],e[1],e[2]);return n<=1e-10?null:[e[0]/n,e[1]/n,e[2]/n]}function un(e,n){return ue(Xe(e,n.point),n.normal)}function fn(e,n){let r=un(e,n);return[e[0]-n.normal[0]*r,e[1]-n.normal[1]*r,e[2]-n.normal[2]*r]}var mn=1e-5,fr=.001,mr=6;function Zn(e){let n=e.vertices;if(n.length<3)return null;let r=n[0],t=0,o=0,s=0;for(let l=1;l+1<n.length;l++){let c=n[l],a=n[l+1],u=c[1]-r[1],f=c[0]-r[0],g=c[2]-r[2],m=a[1]-r[1],p=a[0]-r[0],d=a[2]-r[2];t-=f*d-g*p,o-=g*m-u*d,s-=u*p-f*m}let i=Math.hypot(t,o,s);return i<1e-9?null:[t/i,o/i,s/i]}function gr(e,n){let r=n.meshRotation,t=r?Qe(e,r[0]??0,r[1]??0,r[2]??0):e;return Qe(t,n.rotX,0,n.rotY)[2]}function Qn(e,n,r=mn){return gr(e,n)>r}function pi(e,n,r=mn){let t=Zn(e);return t===null||Qn(t,n,r)}function pr(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function dr(e){let n=new Map;for(let r of e){if(!r)continue;let t=pr(r);n.has(t)||n.set(t,r)}return Array.from(n,([r,t])=>({key:r,normal:t}))}function di(e){return dr(e.map(Zn))}function xr(e,n=fr){let r=Math.abs(e[0]),t=Math.abs(e[1]),o=Math.abs(e[2]),s=Math.max(r,t,o);return s>1-n&&r+t+o-s<n}function xi(e){return e.length<=mr&&e.every(({normal:n})=>xr(n))}function hi(e,n,r=mn){let t=[];for(let{key:o,normal:s}of e)Qn(s,n,r)&&t.push(o);return t.sort(),t.join("|")}function qn(e,n,r,t,o){let s=(p,d,y)=>{let b=[0,0,0];return b[e]=p,b[(e+1)%3]=d,b[(e+2)%3]=y,b},i=s(n,-t,-t),l=s(n,t,-t),c=s(n,t,t),a=s(n,-t,t),u=s(r,-t,-t),f=s(r,t,-t),g=s(r,t,t),m=s(r,-t,t);return[{vertices:[i,l,c,a],color:o},{vertices:[u,f,g,m],color:o},{vertices:[i,l,f,u],color:o},{vertices:[l,c,g,f],color:o},{vertices:[c,a,m,g],color:o},{vertices:[a,i,u,m],color:o}]}function hr(e={}){let n=e.size??5,r=e.thickness??.025,t=e.negative??!1,o=e.xColor??"#ff3a3a",s=e.yColor??"#3aff3a",i=e.zColor??"#3a8aff",l=n*r/2,c=t?-n:0;return[...qn(0,c,n,l,o),...qn(1,c,n,l,s),...qn(2,c,n,l,i)]}function yr(e,n,r,t){let o=[0,0,0];return o[e]=n,o[(e+1)%3]=r,o[(e+2)%3]=t,o}function yi(e,n,r,t,o){let s=(p,d,y)=>yr(e,p,d,y),i=s(n,-t,-t),l=s(n,t,-t),c=s(n,t,t),a=s(n,-t,t),u=s(r,-t,-t),f=s(r,t,-t),g=s(r,t,t),m=s(r,-t,t);return[{vertices:[i,l,c,a],color:o},{vertices:[u,f,g,m],color:o},{vertices:[i,l,f,u],color:o},{vertices:[l,c,g,f],color:o},{vertices:[c,a,m,g],color:o},{vertices:[a,i,u,m],color:o}]}function bi(e,n,r,t,o){let s=(f,g,m)=>yr(e,f,g,m),i=s(n,-t,-t),l=s(n,t,-t),c=s(n,t,t),a=s(n,-t,t),u=s(r,0,0);return[{vertices:[i,l,c,a],color:o},{vertices:[i,l,u],color:o},{vertices:[l,c,u],color:o},{vertices:[c,a,u],color:o},{vertices:[a,i,u],color:o}]}function Pi(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function br(e){let n=e.axis,r=e.sign??1,t=e.shaftLength??4,o=e.shaftHalfThickness??.05,s=e.headLength??.8,i=e.headHalfThickness??.2,l=e.color??"#ffffff",c=e.shaft??!0,a=t*r,u=Math.min(0,a),f=Math.max(0,a),g=a,m=(t+s)*r,p=bi(n,g,m,i,l),d=r===-1?Pi(p):p;return c?[...yi(n,u,f,o,l),...d]:d}function gn(e,n,r){let t=[0,0,0],o=(e+1)%3,s=(e+2)%3;return t[o]=Math.cos(r)*n,t[s]=Math.sin(r)*n,t}function Pr(e){let n=e.axis,r=e.radius,t=e.halfThickness??Math.max(.05,r*.04),o=e.segments??32,s=e.color??"#ffffff",i=r-t,l=r+t,c=[];for(let a=0;a<o;a++){let u=a/o*Math.PI*2,f=(a+1)/o*Math.PI*2,g=gn(n,i,u),m=gn(n,i,f),p=gn(n,l,u),d=gn(n,l,f);c.push({vertices:[g,p,d,m],color:s})}return c}function Mr(e){let n=e.axis,r=e.outerRadius,t=e.color??"#ffffff",o=(n+1)%3,s=(n+2)%3,i=(l,c)=>{let a=[0,0,0];return a[n]=0,a[o]=l,a[s]=c,a};return[{vertices:[i(-r,-r),i(r,-r),i(r,r),i(-r,r)],color:t}]}function vr(e){let n=e.axis,r=e.size??.4,t=e.offset??r*2,o=typeof t=="number"?t:t[0],s=typeof t=="number"?t:t[1],i=e.along??0,l=e.color??"#ffffff",c=(n+1)%3,a=(n+2)%3,u=(f,g)=>{let m=[0,0,0];return m[n]=i,m[c]=o+f,m[a]=s+g,m};return[{vertices:[u(-r,-r),u(r,-r),u(r,r),u(-r,r)],color:l}]}function Ar(e){let{center:n,size:r,color:t="#ffffff"}=e,[o,s,i]=n,l=[[o+r,s,i],[o-r,s,i],[o,s+r,i],[o,s-r,i],[o,s,i+r],[o,s,i-r]];return[[0,2,4],[2,1,4],[1,3,4],[3,0,4],[2,0,5],[1,2,5],[3,1,5],[0,3,5]].map(a=>({vertices:[l[a[0]],l[a[1]],l[a[2]]],color:t}))}var Mi=2200,vi=2201,Ai=2202;function Ci(e,n){let r=0,t=1,o=1,s=2201,i=1/0,l=0,c=!1,a=null,u=!0,f=!1,g={clampWhenFinished:!1,get timeScale(){return o},set timeScale(m){o=m},get weight(){return t},set weight(m){t=m},get time(){return r},set time(m){r=m},get isRunning(){return c},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return c=!0,g},stop(){return c=!1,r=0,l=0,a=null,g},reset(){return r=0,l=0,g},fadeIn(m){return a={from:0,to:1,elapsed:0,duration:m},t=0,g},fadeOut(m){return a={from:t,to:0,elapsed:0,duration:m},g},crossFadeTo(m,p){return g.fadeOut(p),m.fadeIn(p),g},crossFadeFrom(m,p){return m.fadeOut(p),g.fadeIn(p),g},setLoop(m,p){return s=m,i=p,g},setEffectiveTimeScale(m){return o=m,g},setEffectiveWeight(m){return t=m,g}};return g._internal={get clip(){return e},get time(){return r},get weight(){return t},get enabled(){return u},get paused(){return f},get running(){return c},get loopMode(){return s},get repetitions(){return i},get completedReps(){return l},set completedReps(m){l=m},get clampWhenFinished(){return g.clampWhenFinished},get timeScale(){return o},get fade(){return a},advance(m){if(!c)return;if(a){a.elapsed+=m;let d=a.duration>0?Math.min(a.elapsed/a.duration,1):1;if(t=a.from+(a.to-a.from)*d,d>=1&&(t=a.to,a=null,t<=0)){c=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(r+=m*o,s===2200)r>=p&&(r=g.clampWhenFinished?p:0,c=!1);else if(s===2201){if(r>=p){let d=r%p,y=Math.floor(r/p);l+=y,r=d,i!==1/0&&l>=i&&(r=g.clampWhenFinished?p:0,c=!1)}}else if(p>0){let d=p*2,y=r%d;if(r>=d){let b=Math.floor(r/d);l+=b,i!==1/0&&l>=i?(r=g.clampWhenFinished?p:0,c=!1):r=y}}}},sampleTime(){if(s===2202){let m=e.duration,p=m*2,d=r%p;return d<=m?d:p-d}return r}},g}function Vi(e){return e._internal}function Jn(e,n){return typeof n=="number"?e[n]:e.find(r=>r.name===n)}function Si(e,n){let r=new Map;function t(a){let u=Jn(n.clips,a);if(!u)throw new Error(`GlyphcssAnimationMixer: no clip found for key "${a}". Available: ${n.clips.map(g=>g.name).join(", ")}`);let f=r.get(u.index);return f||(f=Ci(u,n),r.set(u.index,f)),f}function o(a){let u=Jn(n.clips,a);return u?r.get(u.index)??null:null}function s(a){let u=[];for(let d of r.values()){let y=Vi(d);y.advance(a),y.running&&y.enabled&&u.push({internal:y,clip:y.clip})}if(u.length===0)return;if(u.length===1){let{internal:d,clip:y}=u[0],b=n.sample(y.name,d.sampleTime());e.setPolygons(b);return}let f=0;for(let{internal:d}of u)f+=d.weight;if(f<=0)return;let g=u.map(({internal:d,clip:y})=>({polygons:n.sample(y.name,d.sampleTime()),weight:d.weight/f})),m=g[0].polygons;if(m.length===0)return;let p=m.map((d,y)=>{let b=d.vertices.map((M,v)=>{let P=0,x=0,A=0;for(let{polygons:T,weight:V}of g){let w=T[y];if(!w)continue;let O=w.vertices[v];O&&(P+=O[0]*V,x+=O[1]*V,A+=O[2]*V)}return[P,x,A]});return{...d,vertices:b}});e.setPolygons(p)}function i(){for(let a of r.values())a.stop()}function l(a){let u=Jn(n.clips,a);u&&r.delete(u.index)}function c(){r.clear()}return{clipAction:t,existingAction:o,update:s,stopAllAction:i,uncacheClip:l,uncacheRoot:c}}var Ti=/^[0-9A-Fa-f]{6}$/,wi=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function et(e,n){let r=n?.targetSize??60,t=n?.gridShift??1,o=n?.defaultColor??"#888888",s=n?.palette??wi,i=n?.materialColors??{},l=n?.materialTextures??{},c=[],a=[],u=[],f=[],g=new Map,m=o,p,d=n?.includeObjects?new Set(n.includeObjects):null,y=n?.excludeObjects?new Set(n.excludeObjects):null,b=null,M=()=>b===null?d===null:!(d&&!d.has(b)||y&&y.has(b)),v=E=>E in i?i[E]:Ti.test(E)?`#${E}`:(g.has(E)||(g.set(E,s[f.length%s.length]),f.push(E)),g.get(E)),P=e.split(`
2
+ `);for(let E of P)if(!(E.length===0||E.charCodeAt(0)===35)){if(E.startsWith("v ")){let C=E.trim().split(/\s+/);c.push([parseFloat(C[1]),parseFloat(C[2]),parseFloat(C[3])])}else if(E.startsWith("vt ")){let C=E.trim().split(/\s+/);a.push([parseFloat(C[1]),parseFloat(C[2])])}else if(E.startsWith("o "))b=E.trim().slice(2).trim();else if(E.startsWith("usemtl ")){let C=E.trim().split(/\s+/)[1];m=v(C),p=l[C]}else if(E.startsWith("f ")){if(!M())continue;let C=E.trim().split(/\s+/).slice(1),h=[],S=[];for(let I of C){let G=I.split("/");h.push(parseInt(G[0],10)-1);let N=G[1];if(N&&N.length>0){let F=parseInt(N,10)-1;S.push(Number.isFinite(F)?F:null)}else S.push(null)}u.push({idx:h,uvIdx:S,color:m,texture:p})}}if(c.length===0||u.length===0)return Ii(f,e.length);let x=new Set;for(let E of u)for(let C of E.idx)x.add(C);let A=1/0,T=1/0,V=1/0,w=-1/0,O=-1/0,L=-1/0;for(let E of x){let C=c[E];C&&(C[0]<A&&(A=C[0]),C[0]>w&&(w=C[0]),C[1]<T&&(T=C[1]),C[1]>O&&(O=C[1]),C[2]<V&&(V=C[2]),C[2]>L&&(L=C[2]))}let U=Math.max(w-A,O-T,L-V),R=U>0?r/U:1,D=E=>Math.round(E*1e3)/1e3,k=c.map(([E,C,h])=>[D((h-V)*R+t),D((E-A)*R+t),D((C-T)*R+t)]),_=[];for(let{idx:E,uvIdx:C,color:h,texture:S}of u)for(let I=1;I<E.length-1;I++){let G=E[0],N=E[I],F=E[I+1],z=k[G],X=k[N],H=k[F];if(!z||!X||!H||z[0]===X[0]&&z[1]===X[1]&&z[2]===X[2]||z[0]===H[0]&&z[1]===H[1]&&z[2]===H[2]||X[0]===H[0]&&X[1]===H[1]&&X[2]===H[2])continue;let K;if(S){let J=C[0],oe=C[I],Q=C[I+1];if(J!=null&&oe!=null&&Q!=null){let q=a[J],ae=a[oe],re=a[Q];q&&ae&&re&&(K=[q,ae,re])}}let Z={vertices:[z,X,H],color:h};S&&(Z.texture=S),K&&(Z.uvs=K),_.push(Z)}return{polygons:_,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:_.length,materials:f,sourceBytes:e.length}}}function Ii(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var nt=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function tt(e){let n={},r={},t=null;for(let o of e.split(`
3
+ `)){let s=o.trim();if(!(s.length===0||s.charCodeAt(0)===35)){if(s.startsWith("newmtl ")){t=s.slice(7).trim();continue}if(t){if(s.startsWith("Kd ")){let i=s.split(/\s+/),l=parseFloat(i[1]),c=parseFloat(i[2]),a=parseFloat(i[3]);Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(a)&&(n[t]=`#${nt(l)}${nt(c)}${nt(a)}`)}else if(s.startsWith("map_Kd ")){let i=s.split(/\s+/),l=i[i.length-1]?.replace(/\\+/g,"/");l&&l!=="map_Kd"&&(r[t]=l)}}}}return{colors:n,textures:r}}var wr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Ir={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Er(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Ei(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let r=e.slice(5,n),t=e.slice(n+1);if(!r.includes(";base64")){let i=decodeURIComponent(t),l=new Uint8Array(i.length);for(let c=0;c<i.length;c++)l[c]=i.charCodeAt(c)&255;return l}let o=globalThis.atob(t),s=new Uint8Array(o.length);for(let i=0;i<o.length;i++)s[i]=o.charCodeAt(i);return s}function Oi(e,n){let r=e.buffers?.[0];if(!r)throw new Error("parseGltf: JSON doc has no buffers[0]");let t=r.uri;if(!t)throw new Error("parseGltf: JSON doc buffer has no uri (and there's no GLB BIN chunk)");if(t.startsWith("data:"))return Ei(t);if(n){let o=n(t);if(o instanceof Uint8Array)return o;throw new Error("parseGltf: resolveBuffer returned a Promise; use parseGltf via async if your buffers are external")}throw new Error(`parseGltf: external buffer URI "${t}" \u2014 provide options.resolveBuffer`)}function Ri(e){let n=new DataView(e);if(n.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let r=n.getUint32(4,!0);if(r!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${r})`);let t=12,o=null,s=null;for(;t<e.byteLength;){let i=n.getUint32(t,!0),l=n.getUint32(t+4,!0),c=t+8;if(l===1313821514){let a=new Uint8Array(e,c,i);o=JSON.parse(Er(a))}else l===5130562&&(s=new Uint8Array(e,c,i));t=c+i}if(!o)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:o,bin:s}}function rt(e,n,r){let t=e.accessors?.[r],o=e.bufferViews?.[t?.bufferView??-1];if(!t||!o)throw new Error(`parseGltf: bad accessor/bufferView ${r}`);let s=wr[t.componentType],i=Ir[t.type];if(!s||!i)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let l=(o.byteOffset??0)+(t.byteOffset??0),c=t.count*i,a=n.buffer.slice(n.byteOffset+l,n.byteOffset+l+c*s),u;switch(t.componentType){case 5126:u=new Float32Array(a);break;case 5123:u=new Uint16Array(a);break;case 5125:u=new Uint32Array(a);break;case 5121:u=new Uint8Array(a);break;default:throw new Error(`parseGltf: unhandled componentType ${t.componentType}`)}return{array:u,count:t.count,componentCount:i}}function Li(e,n,r){switch(r){case 5120:return e.getInt8(n);case 5121:return e.getUint8(n);case 5122:return e.getInt16(n,!0);case 5123:return e.getUint16(n,!0);case 5125:return e.getUint32(n,!0);case 5126:return e.getFloat32(n,!0);default:throw new Error(`parseGltf: unhandled componentType ${r}`)}}function ki(e,n){switch(n){case 5120:return Math.max(e/127,-1);case 5121:return e/255;case 5122:return Math.max(e/32767,-1);case 5123:return e/65535;default:return e}}function xn(e,n,r){let t=e.accessors?.[r],o=e.bufferViews?.[t?.bufferView??-1];if(!t||!o)throw new Error(`parseGltf: bad accessor/bufferView ${r}`);let s=wr[t.componentType],i=Ir[t.type];if(!s||!i)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let l=n.byteOffset+(o.byteOffset??0)+(t.byteOffset??0),c=o.byteStride??s*i,a=new DataView(n.buffer),u=new Array(t.count*i),f=0;for(let g=0;g<t.count;g++){let m=l+g*c;for(let p=0;p<i;p++){let d=Li(a,m+p*s,t.componentType);u[f++]=t.normalized?ki(d,t.componentType):d}}return{values:u,count:t.count,componentCount:i}}function _i(e,n,r){let t=[],o=[],s=globalThis;for(let i of e.images??[]){if(i.uri){if(r&&!i.uri.startsWith("data:"))try{t.push(new s.URL(i.uri,r).href)}catch{t.push(i.uri)}else t.push(i.uri);continue}if(i.bufferView!==void 0){let l=e.bufferViews?.[i.bufferView];if(!l){t.push("");continue}let c=l.byteOffset??0,a=n.subarray(c,c+l.byteLength),u=i.mimeType??"image/png",f=new s.Blob([a],{type:u}),g=s.URL.createObjectURL(f);t.push(g),o.push(g)}else t.push("")}return{urls:t,objectUrls:o}}function Ni(e,n){let r=new Map,t=e.materials??[];for(let o=0;o<t.length;o++){let s=t[o].pbrMetallicRoughness?.baseColorTexture?.index;if(s===void 0)continue;let i=e.textures?.[s]?.source;if(i===void 0)continue;let l=n[i];l&&r.set(o,l)}return r}function Gi(e,n){let r=e?.pbrMetallicRoughness?.baseColorFactor;if(!r||r.length<3)return n;let t=l=>Math.max(0,Math.min(1,l)),o=l=>Math.round(t(l)*255).toString(16).padStart(2,"0"),s=l=>Math.round(t(l)*255),i=t(r[3]??1);return i<1?`rgba(${s(r[0])}, ${s(r[1])}, ${s(r[2])}, ${Math.round(i*1e3)/1e3})`:`#${o(r[0])}${o(r[1])}${o(r[2])}`}var _e=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function ot(e,n){let r=new Array(16);for(let t=0;t<4;t++)for(let o=0;o<4;o++)r[o*4+t]=e[0+t]*n[o*4+0]+e[4+t]*n[o*4+1]+e[8+t]*n[o*4+2]+e[12+t]*n[o*4+3];return r}function dn(e,n){return[e[0]*n[0]+e[4]*n[1]+e[8]*n[2]+e[12],e[1]*n[0]+e[5]*n[1]+e[9]*n[2]+e[13],e[2]*n[0]+e[6]*n[1]+e[10]*n[2]+e[14]]}function Or(e,n,r){let t=e?.[0]??0,o=e?.[1]??0,s=e?.[2]??0,i=n?.[0]??0,l=n?.[1]??0,c=n?.[2]??0,a=n?.[3]??1,u=r?.[0]??1,f=r?.[1]??1,g=r?.[2]??1,m=i+i,p=l+l,d=c+c,y=i*m,b=i*p,M=i*d,v=l*p,P=l*d,x=c*d,A=a*m,T=a*p,V=a*d;return[(1-(v+x))*u,(b+V)*u,(M-T)*u,0,(b-V)*f,(1-(y+x))*f,(P+A)*f,0,(M+T)*g,(P-A)*g,(1-(y+v))*g,0,t,o,s,1]}function Di(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():Or(e.translation,e.rotation,e.scale)}function zi(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function Cr(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function Rr(e,n,r){let t=new Array(Math.min(e.length,n.length));for(let o=0;o<t.length;o++)t[o]=e[o]+(n[o]-e[o])*r;return t}function He(e){let n=Math.hypot(e[0]??0,e[1]??0,e[2]??0,e[3]??1)||1;return[(e[0]??0)/n,(e[1]??0)/n,(e[2]??0)/n,(e[3]??1)/n]}function Ui(e,n,r){let t=He(e),o=He(n),s=t[0]*o[0]+t[1]*o[1]+t[2]*o[2]+t[3]*o[3];if(s<0&&(s=-s,o=[-o[0],-o[1],-o[2],-o[3]]),s>.9995)return He(Rr(t,o,r));let i=Math.acos(Math.max(-1,Math.min(1,s))),l=Math.sin(i),c=Math.sin((1-r)*i)/l,a=Math.sin(r*i)/l;return He([t[0]*c+o[0]*a,t[1]*c+o[1]*a,t[2]*c+o[2]*a,t[3]*c+o[3]*a])}function Fi(e){return{translation:e?.translation?.slice()??[0,0,0],rotation:e?.rotation?.slice()??[0,0,0,1],scale:e?.scale?.slice()??[1,1,1],matrix:e?.matrix&&e.matrix.length===16?e.matrix.slice():void 0}}function Vr(e){return e.matrix?e.matrix.slice():Or(e.translation,e.rotation,e.scale)}function $i(e){let n=e.scene??0,r=e.scenes?.[n]?.nodes;return r&&r.length>0?r:[]}function Sr(e,n){let r=e.nodes??[],t=new Array(r.length),o=new Set,s=(l,c)=>{if(l<0||l>=r.length)return;let a=ot(c,n[l]??_e);t[l]=a,o.add(l);for(let u of r[l].children??[])s(u,a)},i=$i(e);if(i.length>0)for(let l of i)s(l,_e);for(let l=0;l<r.length;l++)o.has(l)||s(l,_e);return t}function Tr(e,n,r,t,o){if(r===void 0)return;let{values:s,count:i,componentCount:l}=xn(e,n,r);if(i!==o||l<1)return;let c=[];for(let a=0;a<i;a++){let u=[];for(let f=0;f<t;f++)u.push(s[a*l+f]??0);c.push(u)}return c}function Bi(e,n,r,t){if(r===void 0)return Array.from({length:t},()=>_e.slice());let{values:o,componentCount:s,count:i}=xn(e,n,r);if(s!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${r} is not MAT4`);let l=[];for(let c=0;c<t;c++){let a=Math.min(c,i-1);l.push(o.slice(a*16,a*16+16))}return l}function pn(e,n){let r=e.componentCount,t=e.interpolation==="CUBICSPLINE"?(n*3+1)*r:n*r;return e.output.slice(t,t+r)}function ji(e,n,r){let t=e.input;if(t.length===0)return[];if(t.length===1||n<=t[0])return pn(e,0);let o=t.length-1;if(n>=t[o])return pn(e,o);let s=0,i=o;for(;s+1<i;){let g=s+i>>1;t[g]<=n?s=g:i=g}let l=t[s],c=t[s+1],a=c>l?(n-l)/(c-l):0,u=pn(e,s),f=pn(e,s+1);return e.interpolation==="STEP"?u:r==="rotation"?Ui(u,f,a):Rr(u,f,a)}function Xi(e,n,r,t){let o=e.animations??[];if(o.length===0||r.length===0)return;let s=(e.nodes??[]).map(m=>Fi(m)),i=s.map(Vr),l=Sr(e,i),c=(e.skins??[]).map(m=>({joints:m.joints??[],inverseBindMatrices:Bi(e,n,m.inverseBindMatrices,m.joints?.length??0)})),a=[];for(let m=0;m<o.length;m++){let p=o[m],d=(p.samplers??[]).map(M=>{let v=xn(e,n,M.input),P=xn(e,n,M.output);return{input:v.values,output:P.values,componentCount:P.componentCount,interpolation:M.interpolation??"LINEAR"}}),y=[];for(let M of p.channels??[]){let v=M.target.node,P=M.target.path,x=d[M.sampler];v===void 0||!P||!x||P==="weights"||y.push({sampler:x,targetNode:v,path:P})}let b=y.reduce((M,v)=>{let P=v.sampler.input;return Math.max(M,P[P.length-1]??0)},0);a.push({info:{index:m,name:p.name??`animation_${m}`,duration:b,channelCount:y.length},channels:y})}let u=a.map(m=>m.info);if(u.length===0)return;let f=(m,p,d,y,b,M)=>{let v=t(m),P=t(p),x=t(d);if(v[0]===P[0]&&v[1]===P[1]&&v[2]===P[2]||v[0]===x[0]&&v[1]===x[1]&&v[2]===x[2]||P[0]===x[0]&&P[1]===x[1]&&P[2]===x[2])return null;let A={vertices:[v,P,x],color:y};return b&&(A.texture=b),M&&(A.uvs=M),A};return{clips:u,sample:(m,p)=>{let d=typeof m=="number"?a[m]:a.find(x=>x.info.name===m);if(!d)return[];let y=d.info.duration,b=y>0?(p%y+y)%y:Math.max(0,p),M=s.map(x=>({translation:x.translation.slice(),rotation:x.rotation.slice(),scale:x.scale.slice(),matrix:x.matrix?x.matrix.slice():void 0}));for(let x of d.channels){let A=M[x.targetNode];if(!A)continue;let T=ji(x.sampler,b,x.path);A.matrix=void 0,x.path==="translation"?A.translation=T.slice(0,3):x.path==="rotation"?A.rotation=He(T.slice(0,4)):x.path==="scale"&&(A.scale=T.slice(0,3))}let v=Sr(e,M.map(Vr)),P=[];for(let x of r){let A=[];if(x.skinIndex!==void 0&&x.joints&&x.weights&&c[x.skinIndex]){let T=c[x.skinIndex];for(let V=0;V<x.positions.length;V++){let w=x.positions[V],O=[0,0,0],L=0,U=x.joints[V]??[],R=x.weights[V]??[];for(let D=0;D<4;D++){let k=R[D]??0;if(k<=0)continue;let _=Math.round(U[D]??0),E=T.joints[_],C=v[E],h=T.inverseBindMatrices[_];if(!C||!h)continue;let S=ot(C,h);O=zi(O,Cr(dn(S,w),k)),L+=k}A.push(L>0?Cr(O,1/L):dn(x.meshBindWorld,w))}}else{let T=x.meshNode!==null?v[x.meshNode]??x.meshBindWorld:x.meshBindWorld;for(let V of x.positions)A.push(dn(T,V))}for(let T=0;T+2<x.indices.length;T+=3){let V=x.indices[T],w=x.indices[T+1],O=x.indices[T+2],L=A[V],U=A[w],R=A[O];if(!L||!U||!R)continue;let D;if(x.uvs&&x.texture){let _=x.uvs[V],E=x.uvs[w],C=x.uvs[O];_&&E&&C&&(D=[_,E,C])}let k=f(L,U,R,x.color,x.texture,D);k&&P.push(k)}}return P}}}function st(e,n){let r=n?.targetSize??60,t=n?.gridShift??1,o=n?.defaultColor??"#888888",s=n?.materialColors??{},i=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,l=i.byteLength,c,a;if(i.byteLength>=4&&new DataView(i).getUint32(0,!0)===1179937895){let h=Ri(i);if(c=h.doc,!h.bin)throw new Error("parseGltf: GLB has no binary chunk");a=h.bin}else c=JSON.parse(Er(new Uint8Array(i))),a=Oi(c,n?.resolveBuffer);let{urls:u,objectUrls:f}=_i(c,a,n?.baseUrl),g=Ni(c,u),m=[],p=[],d=(c.meshes??[]).map((h,S)=>h.name??`mesh_${S}`),y=(c.materials??[]).map((h,S)=>h.name??`material_${S}`);function b(h,S,I){let G=c.meshes?.[h];if(G)for(let N of G.primitives){if((N.mode??4)!==4)continue;let z=N.material!==void 0?c.materials?.[N.material]?.name:void 0,H=(z?s[z]:void 0)??Gi(N.material!==void 0?c.materials?.[N.material]:void 0,o),K=N.material!==void 0?g.get(N.material):void 0,{array:Z,count:J}=rt(c,a,N.attributes.POSITION);if(!(Z instanceof Float32Array))continue;let oe=[],Q=[];for(let W=0;W<J;W++){let $=[Z[W*3],Z[W*3+1],Z[W*3+2]];oe.push($),Q.push(dn(S,$))}let q=null,ae=N.attributes.TEXCOORD_0;if(K&&ae!==void 0){let{array:W,count:$}=rt(c,a,ae);q=[];let Y=1;W instanceof Uint8Array?Y=1/255:W instanceof Uint16Array&&(Y=1/65535);for(let se=0;se<$;se++){let de=W[se*2]*Y,Pe=W[se*2+1]*Y;q.push([de,1-Pe])}}let re;if(N.indices!==void 0){let{array:W,count:$}=rt(c,a,N.indices);re=[];for(let Y=0;Y<$;Y++)re.push(Number(W[Y]))}else re=Q.map((W,$)=>$);if((c.animations?.length??0)>0){let W=Tr(c,a,N.attributes.JOINTS_0,4,J),$=Tr(c,a,N.attributes.WEIGHTS_0,4,J);p.push({meshNode:I,meshBindWorld:S,skinIndex:I!==null?c.nodes?.[I]?.skin:void 0,positions:oe,indices:re,color:H,texture:K,uvs:q??void 0,joints:W,weights:$})}for(let W=0;W+2<re.length;W+=3){let $=Q[re[W]],Y=Q[re[W+1]],se=Q[re[W+2]];if(!$||!Y||!se)continue;let de;if(q&&K){let Pe=q[re[W]],Te=q[re[W+1]],we=q[re[W+2]];Pe&&Te&&we&&(de=[Pe,Te,we])}m.push({v0:$,v1:Y,v2:se,color:H,texture:K,uvs:de})}}}function M(h,S){let I=c.nodes?.[h];if(!I)return;let G=ot(S,Di(I));typeof I.mesh=="number"&&b(I.mesh,G,h);for(let N of I.children??[])M(N,G)}let v=c.scene??0,P=c.scenes?.[v]?.nodes;if(P&&P.length>0)for(let h of P)M(h,_e);else for(let h=0;h<(c.meshes?.length??0);h++)b(h,_e,null);let x=Yi(f);if(m.length===0)return{polygons:[],objectUrls:f,dispose:x,warnings:[],metadata:{triangleCount:0,meshes:d,materials:y,sourceBytes:l}};let A=1/0,T=1/0,V=1/0,w=-1/0,O=-1/0,L=-1/0;for(let h of m)for(let S of[h.v0,h.v1,h.v2])S[0]<A&&(A=S[0]),S[0]>w&&(w=S[0]),S[1]<T&&(T=S[1]),S[1]>O&&(O=S[1]),S[2]<V&&(V=S[2]),S[2]>L&&(L=S[2]);let U=Math.max(w-A,O-T,L-V),R=U>0?r/U:1,D=h=>Math.round(h*1e3)/1e3,_=(n?.upAxis??"y")==="z"?([h,S,I])=>[D((h-A)*R+t),D((S-T)*R+t),D((I-V)*R+t)]:([h,S,I])=>[D((I-V)*R+t),D((h-A)*R+t),D((S-T)*R+t)],E=Xi(c,a,p,_),C=[];for(let h of m){let S=_(h.v0),I=_(h.v1),G=_(h.v2);if(S[0]===I[0]&&S[1]===I[1]&&S[2]===I[2]||S[0]===G[0]&&S[1]===G[1]&&S[2]===G[2]||I[0]===G[0]&&I[1]===G[1]&&I[2]===G[2])continue;let N={vertices:[S,I,G],color:h.color};h.texture&&(N.texture=h.texture),h.uvs&&(N.uvs=h.uvs),C.push(N)}return{polygons:C,animation:E,objectUrls:f,dispose:x,warnings:[],metadata:{triangleCount:C.length,meshes:d,materials:y,animations:E?.clips,sourceBytes:l}}}function Yi(e){let n=!1;return()=>{if(n)return;n=!0;let r=globalThis.URL;if(r?.revokeObjectURL)for(let t of e)try{r.revokeObjectURL(t)}catch{}}}function it(e){return e.material?.texture??e.texture}function Hi(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function Ki(e,n){return new Promise((r,t)=>{let o=new n,s=!1,i=l=>{s||(s=!0,l())};o.decoding="async",o.onload=()=>i(()=>r(o)),o.onerror=()=>i(()=>t(new Error(`texture load failed: ${e}`))),o.src=e,typeof o.decode=="function"&&o.decode().then(()=>i(()=>r(o)),()=>{})})}async function Wi(e,n,r){try{let t=await Ki(e,n.Image),o=Math.max(0,Math.floor(t.naturalWidth||t.width||0)),s=Math.max(0,Math.floor(t.naturalHeight||t.height||0));if(o<=0||s<=0||o*s>r)return null;let i=n.createCanvas();i.width=o,i.height=s;let l=i.getContext("2d",{willReadFrequently:!0});if(!l)return null;l.drawImage(t,0,0,o,s);let c=l.getImageData(0,0,o,s).data;return{width:o,height:s,data:c,lowDetail:Zi(o,s,c)}}catch{return null}}function Lr(e,n,r,t,o,s){let i=(t*n+r)*4,l=(s*n+o)*4;return Math.max(Math.abs((e[i]??0)-(e[l]??0)),Math.abs((e[i+1]??0)-(e[l+1]??0)),Math.abs((e[i+2]??0)-(e[l+2]??0)))}function Zi(e,n,r){let t=Math.max(1,Math.floor(Math.max(e,n)/128)),o=0,s=0,i=0;for(let l=0;l<n;l+=t)for(let c=0;c<e;c+=t){if(c+t<e){let a=Lr(r,e,c,l,c+t,l);i+=a,o++,a>32&&s++}if(l+t<n){let a=Lr(r,e,c,l,c,l+t);i+=a,o++,a>32&&s++}}return o>0&&s/o<=.045&&i/o<=10}function kr(e,n,r){return Math.max(n,Math.min(r,e))}function Qi(e,n){let r=n[0],t=1-n[1];if(!Number.isFinite(r)||!Number.isFinite(t))return null;let o=kr(Math.floor(r*e.width),0,e.width-1),i=(kr(Math.floor(t*e.height),0,e.height-1)*e.width+o)*4;return{r:e.data[i]??0,g:e.data[i+1]??0,b:e.data[i+2]??0,a:e.data[i+3]??255}}function be(e,n,r,t,o,s){return[e[0]*t+n[0]*o+r[0]*s,e[1]*t+n[1]*o+r[1]*s]}function qi(e){let[n,r,t]=e;return[be(n,r,t,1/3,1/3,1/3),be(n,r,t,.8,.1,.1),be(n,r,t,.1,.8,.1),be(n,r,t,.1,.1,.8),be(n,r,t,.45,.45,.1),be(n,r,t,.45,.1,.45),be(n,r,t,.1,.45,.45)]}function Ji(e){let[n,r,t]=e,o=qi(e);for(let s=1;s<6;s++)for(let i=1;i<6-s;i++){let l=6-s-i;l<=0||o.push(be(n,r,t,s/6,i/6,l/6))}return o}function Dr(e){if(e.textureTriangles?.length)return e.textureTriangles;let n=e.uvs;if(!n||n.length!==e.vertices.length||n.length<3)return[];let r=[];for(let t=1;t+1<n.length;t++)r.push({uvs:[n[0],n[t],n[t+1]]});return r}function _r(e,n,r){return Math.abs(e.r-n.r)<=r&&Math.abs(e.g-n.g)<=r&&Math.abs(e.b-n.b)<=r&&Math.abs(e.a-n.a)<=r}function Nr(e){let n=t=>Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0");if(e.a>=255)return`#${n(e.r)}${n(e.g)}${n(e.b)}`;let r=Math.round(Math.max(0,Math.min(255,e.a))/255*1e3)/1e3;return`rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${r})`}function ec(){return{min:{r:255,g:255,b:255,a:255},max:{r:0,g:0,b:0,a:0},sum:{r:0,g:0,b:0,a:0},count:0}}function nc(e,n){e.min.r=Math.min(e.min.r,n.r),e.min.g=Math.min(e.min.g,n.g),e.min.b=Math.min(e.min.b,n.b),e.min.a=Math.min(e.min.a,n.a),e.max.r=Math.max(e.max.r,n.r),e.max.g=Math.max(e.max.g,n.g),e.max.b=Math.max(e.max.b,n.b),e.max.a=Math.max(e.max.a,n.a),e.sum.r+=n.r,e.sum.g+=n.g,e.sum.b+=n.b,e.sum.a+=n.a,e.count++}function Gr(e){return{r:e.sum.r/e.count,g:e.sum.g/e.count,b:e.sum.b/e.count,a:e.sum.a/e.count}}function tc(e,n,r,t){let o=Dr(e);if(o.length===0||!t&&!n.lowDetail)return null;let s=ec();for(let i of o)for(let l of Ji(i.uvs)){let c=Qi(n,l);if(!c)return null;nc(s,c)}return s.count===0?null:_r(s.min,s.max,r)?Nr(Gr(s)):t||!_r(s.min,s.max,32)?null:Nr(Gr(s))}function rc(e,n){let{texture:r,material:t,uvs:o,textureTriangles:s,...i}=e;return{...i,color:n}}async function zr(e,n={}){if(n.enabled===!1)return null;let r=Hi();if(!r)return null;let t=e.filter(c=>it(c)&&Dr(c).length>0);if(t.length===0)return null;let o=n.maxTexturePixels??16777216,s=new Map;await Promise.all(Array.from(new Set(t.map(c=>it(c)))).map(async c=>{s.set(c,await Wi(c,r,o))}));let i=n.colorTolerance??2,l=n.colorTolerance!==void 0;return{bake(c){let a=!1,u=c.map(f=>{let g=it(f);if(!g)return f;let m=s.get(g);if(!m)return f;let p=tc(f,m,i,l);return p?(a=!0,rc(f,p)):f});return{polygons:a?u:c,changed:a}}}}async function oc(e,n={}){let r=await zr(e,n);return r?r.bake(e).polygons:e}async function ct(e,n={}){let r=await zr(e.polygons,n);if(!r)return e;let t=r.bake(e.polygons);return!t.changed&&!e.animation?e:{...e,polygons:t.polygons,animation:e.animation?{...e.animation,sample(o,s){return r.bake(e.animation.sample(o,s)).polygons}}:e.animation}}var sc=[0,4294967295,4291624959,4288282623,4284940287,4281597951,4278255615,4294954239,4291611903,4288269567,4284927231,4281584895,4278242559,4294941183,4291598847,4288256511,4284914175,4281571839,4278229503,4294928127,4291585791,4288243455,4284901119,4281558783,4278216447,4294915071,4291572735,4288230399,4284888063,4281545727,4278203391,4294902015,4291559679,4288217343,4284875007,4281532671,4278190335,4294967244,4291624908,4288282572,4284940236,4281597900,4278255564,4294954188,4291611852,4288269516,4284927180,4281584844,4278242508,4294941132,4291598796,4288256460,4284914124,4281571788,4278229452,4294928076,4291585740,4288243404,4284901068,4281558732,4278216396,4294915020,4291572684,4288230348,4284888012,4281545676,4278203340,4294901964,4291559628,4288217292,4284874956,4281532620,4278190284,4294967193,4291624857,4288282521,4284940185,4281597849,4278255513,4294954137,4291611801,4288269465,4284927129,4281584793,4278242457,4294941081,4291598745,4288256409,4284914073,4281571737,4278229401,4294928025,4291585689,4288243353,4284901017,4281558681,4278216345,4294914969,4291572633,4288230297,4284887961,4281545625,4278203289,4294901913,4291559577,4288217241,4284874905,4281532569,4278190233,4294967142,4291624806,4288282470,4284940134,4281597798,4278255462,4294954086,4291611750,4288269414,4284927078,4281584742,4278242406,4294941030,4291598694,4288256358,4284914022,4281571686,4278229350,4294927974,4291585638,4288243302,4284900966,4281558630,4278216294,4294914918,4291572582,4288230246,4284887910,4281545574,4278203238,4294901862,4291559526,4288217190,4284874854,4281532518,4278190182,4294967091,4291624755,4288282419,4284940083,4281597747,4278255411,4294954035,4291611699,4288269363,4284927027,4281584691,4278242355,4294940979,4291598643,4288256307,4284913971,4281571635,4278229299,4294927923,4291585587,4288243251,4284900915,4281558579,4278216243,4294914867,4291572531,4288230195,4284887859,4281545523,4278203187,4294901811,4291559475,4288217139,4284874803,4281532467,4278190131,4294967040,4291624704,4288282368,4284940032,4281597696,4278255360,4294953984,4291611648,4288269312,4284926976,4281584640,4278242304,4294940928,4291598592,4288256256,4284913920,4281571584,4278229248,4294927872,4291585536,4288243200,4284900864,4281558528,4278216192,4294914816,4291572480,4288230144,4284887808,4281545472,4278203136,4294901760,4291559424,4288217088,4284874752,4281532416,4278190318,4278190301,4278190267,4278190250,4278190216,4278190199,4278190165,4278190148,4278190114,4278190097,4278251008,4278246656,4278237952,4278233600,4278224896,4278220544,4278211840,4278207488,4278198784,4278194432,4293787648,4292673536,4290445312,4289331200,4287102976,4285988864,4283760640,4282646528,4280418304,4279304192,4293848814,4292730333,4290493371,4289374890,4287137928,4286019447,4283782485,4282664004,4280427042,4279308561];function ic(e){let n=e>>0&255,r=e>>8&255,t=e>>16&255;return[n,r,t]}function at(e){return(e&255).toString(16).padStart(2,"0")}function Fr(e,n,r){return`#${at(e)}${at(n)}${at(r)}`}function cc(e,n,r,t){if(t>=255)return Fr(e,n,r);let o=Math.round(Math.max(0,Math.min(255,t))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${r}, ${o})`}var ac=542658390;function lt(e,n){let r=n?.targetSize??60,t=n?.gridShift??0,o=e.byteLength;if(e.byteLength<8)return Ne(o,["parseVox: buffer too small to be a valid .vox file"]);let s=new DataView(e);if(s.getUint32(0,!0)!==ac)return Ne(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return Ne(o,["parseVox: buffer too small for MAIN chunk"]);if(Ur(s,8)!=="MAIN")return Ne(o,["parseVox: expected MAIN chunk at offset 8"]);let a=20+s.getUint32(12,!0),u=a+s.getUint32(16,!0),f=[],g=[],m=null;for(;a<u&&a+12<=e.byteLength;){let C=Ur(s,a),h=s.getUint32(a+4,!0),S=s.getUint32(a+8,!0),I=a+12,G=I+h+S;if(C==="SIZE"){if(h>=12&&I+12<=e.byteLength){let N=s.getUint32(I,!0),F=s.getUint32(I+4,!0),z=s.getUint32(I+8,!0);f.push({sx:N,sy:F,sz:z})}}else if(C==="XYZI"){if(h>=4&&I+4<=e.byteLength){let N=s.getUint32(I,!0),F=[],z=Math.min(N,Math.floor((h-4)/4));for(let X=0;X<z;X++){let H=I+4+X*4;F.push({x:s.getUint8(H),y:s.getUint8(H+1),z:s.getUint8(H+2),colorIndex:s.getUint8(H+3)})}g.push(F)}}else if(C==="RGBA"&&h>=1024&&I+1024<=e.byteLength){m=[];for(let N=0;N<256;N++){let F=I+N*4,z=s.getUint8(F),X=s.getUint8(F+1),H=s.getUint8(F+2),K=s.getUint8(F+3);m.push(cc(z,X,H,K))}}a=G}let p=[],d=new Set;for(let C of g)for(let h of C){if(h.colorIndex===0)continue;let S=`${h.x},${h.y},${h.z}`;d.has(S)||(d.add(S),p.push(h))}if(p.length===0)return Ne(o,[]);let y=C=>{let h=C-1;if(m!==null)return m[h]??"#888888";let S=sc[C]??0,[I,G,N]=ic(S);return Fr(I,G,N)},b=(C,h,S)=>d.has(`${C},${h},${S}`),M=new Map,v=(C,h,S,I,G)=>{let N=`${C}:${h}:${G}`,F=M.get(N);F||(F=new Set,M.set(N,F)),F.add(`${S},${I}`)};for(let C of p){let{x:h,y:S,z:I}=C,G=y(C.colorIndex);b(h+1,S,I)||v(0,h+1,S,I,G),b(h-1,S,I)||v(1,h,S,I,G),b(h,S+1,I)||v(2,S+1,h,I,G),b(h,S-1,I)||v(3,S,h,I,G),b(h,S,I+1)||v(4,I+1,h,S,G),b(h,S,I-1)||v(5,I,h,S,G)}function P(C){let h=new Set,S=[],I=1/0,G=-1/0,N=1/0,F=-1/0;for(let z of C){let[X,H]=z.split(","),K=+X,Z=+H;K<I&&(I=K),K>G&&(G=K),Z<N&&(N=Z),Z>F&&(F=Z)}for(let z=N;z<=F;z++)for(let X=I;X<=G;X++){let H=`${X},${z}`;if(!C.has(H)||h.has(H))continue;let K=1;for(;X+K<=G;){let J=`${X+K},${z}`;if(!C.has(J)||h.has(J))break;K++}let Z=1;e:for(;z+Z<=F;){for(let J=0;J<K;J++){let oe=`${X+J},${z+Z}`;if(!C.has(oe)||h.has(oe))break e}Z++}for(let J=0;J<Z;J++)for(let oe=0;oe<K;oe++)h.add(`${X+oe},${z+J}`);S.push({u:X,v:z,w:K,h:Z})}return S}let x=(C,h,S,I,G,N)=>{let F=S+G,z=I+N;switch(C){case 0:return[[h,S,I],[h,F,I],[h,F,z],[h,S,z]];case 1:return[[h,F,I],[h,S,I],[h,S,z],[h,F,z]];case 2:return[[S,h,I],[S,h,z],[F,h,z],[F,h,I]];case 3:return[[F,h,I],[F,h,z],[S,h,z],[S,h,I]];case 4:return[[S,I,h],[F,I,h],[F,z,h],[S,z,h]];default:return[[S,z,h],[F,z,h],[F,I,h],[S,I,h]]}},A=[];for(let[C,h]of M){let S=C.indexOf(":"),I=C.indexOf(":",S+1),G=+C.slice(0,S),N=+C.slice(S+1,I),F=C.slice(I+1);for(let{u:z,v:X,w:H,h:K}of P(h))A.push({vertices:x(G,N,z,X,H,K),color:F})}if(A.length===0)return Ne(o,[]);let T=1/0,V=1/0,w=1/0,O=-1/0,L=-1/0,U=-1/0;for(let C of A)for(let h of C.vertices)h[0]<T&&(T=h[0]),h[0]>O&&(O=h[0]),h[1]<V&&(V=h[1]),h[1]>L&&(L=h[1]),h[2]<w&&(w=h[2]),h[2]>U&&(U=h[2]);let R=Math.max(O-T,L-V,U-w),D=R>0?r/R:1,k=C=>Math.round(C*1e3)/1e3,_=C=>[k((C[0]-T)*D+t),k((C[1]-V)*D+t),k((C[2]-w)*D+t)],E=A.map(({vertices:C,color:h})=>({vertices:C.map(_),color:h}));return{polygons:E,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:E.length,sourceBytes:o,voxelCount:p.length}}}function Ur(e,n){return String.fromCharCode(e.getUint8(n))+String.fromCharCode(e.getUint8(n+1))+String.fromCharCode(e.getUint8(n+2))+String.fromCharCode(e.getUint8(n+3))}function Ne(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var Se="loadMesh";function ut(e,n){let r=Xn(e.polygons,{meshResolution:n?.meshResolution});return r.length===e.polygons.length?e:{...e,polygons:r}}async function $r(e,n){let r=n?.solidTextureSamples;return r===!1?e:ct(e,typeof r=="object"?r:void 0)}function lc(e){let n=e.split("?")[0].split("#")[0],r=n.lastIndexOf(".");return r<0?"":n.slice(r+1).toLowerCase()}async function uc(e,n){let r=lc(e);if(r==="mtl")throw new Error(`${Se}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let t=globalThis.fetch;if(!t)throw new Error(`${Se}: no fetch() in this environment`);let o=n?.baseUrl??e;if(r==="obj"){let s=await t(e);if(!s.ok)throw new Error(`${Se}: ${e} \u2192 ${s.status}`);let i=await s.text(),l=n?.objOptions;if(n?.mtlUrl){let a=await t(n.mtlUrl);if(!a.ok)throw new Error(`${Se}: ${n.mtlUrl} \u2192 ${a.status}`);let u=await a.text(),{colors:f,textures:g}=tt(u),m={},p=globalThis.URL,d=globalThis.document?.baseURI,y=n.mtlUrl;if(p&&d)try{y=new p(n.mtlUrl,d).toString()}catch{}for(let[b,M]of Object.entries(g)){if(p)try{m[b]=new p(M,y).toString();continue}catch{}let v=n.mtlUrl.lastIndexOf("/"),P=v>=0?n.mtlUrl.slice(0,v+1):"";m[b]=M.startsWith("/")||/^https?:\/\//.test(M)?M:P+M}l={...l??{},materialColors:{...f,...l?.materialColors??{}},materialTextures:{...m,...l?.materialTextures??{}}}}let c=et(i,l);return ut(await $r(c,n),n)}if(r==="glb"||r==="gltf"){let s=await t(e);if(!s.ok)throw new Error(`${Se}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer(),l=st(i,{baseUrl:o,...n?.gltfOptions??{}});return ut(await $r(l,n),n)}if(r==="vox"){let s=await t(e);if(!s.ok)throw new Error(`${Se}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return ut(lt(i,n?.voxOptions),n)}throw new Error(`${Se}: unsupported extension ".${r}" (supported: obj, glb, gltf, vox)`)}function fc(e,n,r,t,o=.5,s=.5,i=.4){let l=4/(e[2]+3),c=Math.min(n,r)*i,a=n*o+e[0]*c*t*l,u=r*s-e[1]*c*l;return[a,u,e[2]]}function mc(e){let[n,r,t]=[e.vertices[0],e.vertices[1],e.vertices[2]],o=r[0]-n[0],s=r[1]-n[1],i=r[2]-n[2],l=t[0]-n[0],c=t[1]-n[1],a=t[2]-n[2];return[s*a-i*c,i*l-o*a,o*c-s*l]}function gc(e,n){let r=Math.hypot(e[0],e[1],e[2]),t=Math.hypot(n[0],n[1],n[2]);return r===0||t===0?1:(e[0]*n[0]+e[1]*n[1]+e[2]*n[2])/(r*t)}function Br(e,n){let r=`${e[0]},${e[1]},${e[2]}`,t=`${n[0]},${n[1]},${n[2]}`;return r<t?`${r}|${t}`:`${t}|${r}`}function pc(e,n=0){if(n<=0){let i=new Set,l=[];for(let c of e){let a=[[0,1],[1,2],[2,0]];for(let[u,f]of a){let g=c.vertices[u],m=c.vertices[f],p=Br(g,m);if(i.has(p))continue;i.add(p);let d={from:g,to:m,weight:2};c.color&&(d.color=c.color),l.push(d)}}return l}let r=Math.cos(n*Math.PI/180),t=new Map,o=[[0,1],[1,2],[2,0]];for(let i of e){let l=mc(i);for(let[c,a]of o){let u=i.vertices[c],f=i.vertices[a],g=Br(u,f),m=t.get(g);m?m.normals.push(l):t.set(g,{normals:[l],from:u,to:f,color:i.color})}}let s=[];for(let{normals:i,from:l,to:c,color:a}of t.values()){if(i.length<2){let f={from:l,to:c,weight:2};a&&(f.color=a),s.push(f);continue}let u=!1;e:for(let f=0;f<i.length;f++)for(let g=f+1;g<i.length;g++)if(gc(i[f],i[g])<r){u=!0;break e}if(u){let f={from:l,to:c,weight:2};a&&(f.color=a),s.push(f)}}return s}function dc(e,n=0){return pc(e,n)}export{oo as BASE_TILE,mn as CAMERA_BACKFACE_CULL_EPS,Oe as DEFAULT_CAMERA_STATE,jr as DEFAULT_PROJECTION,Mi as LoopOnce,Ai as LoopPingPong,vi as LoopRepeat,Jr as QUAT_IDENTITY,fr as VOXEL_CAMERA_CULL_AXIS_EPS,mr as VOXEL_CAMERA_CULL_NORMAL_LIMIT,br as arrowPolygons,hr as axesHelperPolygons,oc as bakeSolidTextureSampledPolygons,ct as bakeSolidTextureSamples,Zr as buildSceneContext,dr as cameraCullNormalGroups,di as cameraCullNormalGroupsFromPolygons,pr as cameraCullNormalKey,hi as cameraCullVisibleSignature,gr as cameraFacingDepth,Me as clampChannel,vt as computeSceneBbox,Yr as computeShapeLighting,zn as coverPlanarPolygons,Si as createGlyphcssAnimationMixer,co as createIsometricCamera,Ce as cullInteriorPolygons,Ln as dedupeOverlappingPolygons,ro as eulerXYZFromQuat,Et as findOverlappingPolygonDuplicates,Ke as formatColor,qr as inverseRotateVec3,xr as isAxisAlignedSurfaceNormal,xi as isVoxelCameraCullableNormalGroups,uc as loadMesh,ce as mergePolygons,Qn as normalFacesCamera,so as normalizeInvertMultiplier,En as normalizePolygons,Ar as octahedronPolygons,Xn as optimizeMeshPolygons,Ie as parseColor,st as parseGltf,gt as parseHexColor,tt as parseMtl,et as parseObj,Tn as parsePureColor,pt as parseRgbColor,lt as parseVox,vr as planePolygons,Zn as polygonCssSurfaceNormal,Qr as polygonFaces,pi as polygonFacesCamera,fc as project,no as quatFromAxisAngle,to as quatFromEulerXYZ,eo as quatMultiply,Pr as ringPolygons,Mr as ringQuadPolygons,Qe as rotateVec3,Xr as shadeColor,dc as trianglesToFeatureEdges};
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@glyphcss/core",
3
+ "version": "0.0.1",
4
+ "description": "Pure math engine for ASCII polygon mesh rendering. Zero browser globals.",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "keywords": [
10
+ "glyphcss",
11
+ "ascii",
12
+ "polygon",
13
+ "mesh",
14
+ "3d",
15
+ "dom",
16
+ "rendering"
17
+ ],
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/apresmoi/glyphcss.git",
22
+ "directory": "packages/core"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/apresmoi/glyphcss/issues"
26
+ },
27
+ "homepage": "https://github.com/apresmoi/glyphcss#readme",
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js",
35
+ "require": "./dist/index.cjs"
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "devDependencies": {
42
+ "tsup": "^8.0.1",
43
+ "typescript": "^5.3.3",
44
+ "vitest": "^3.1.1",
45
+ "@vitest/coverage-v8": "^3.1.1"
46
+ },
47
+ "scripts": {
48
+ "build": "tsup",
49
+ "test": "vitest run --passWithNoTests",
50
+ "test:coverage": "vitest run --coverage --passWithNoTests"
51
+ }
52
+ }