stack3js 0.2.0 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/COMMAND.md +145 -0
  2. package/README.md +167 -4
  3. package/bin/stack3.mjs +1386 -186
  4. package/blender/import_stack.py +89 -0
  5. package/meshing/blocks.py +82 -0
  6. package/meshing/branches.py +62 -0
  7. package/meshing/dexel.py +67 -0
  8. package/meshing/field_data.py +19 -0
  9. package/meshing/finish_blender.py +203 -0
  10. package/meshing/finishing.py +155 -0
  11. package/meshing/geometry.py +71 -0
  12. package/meshing/guided.py +150 -0
  13. package/meshing/implicit.py +178 -0
  14. package/meshing/intersection.py +33 -0
  15. package/meshing/material.py +115 -0
  16. package/meshing/mesh.py +103 -0
  17. package/meshing/network.py +136 -0
  18. package/meshing/regularization.py +213 -0
  19. package/meshing/sections.py +165 -0
  20. package/meshing/signed_distance.py +93 -0
  21. package/package.json +9 -2
  22. package/references/hard-surface/README.md +40 -0
  23. package/references/hard-surface/atlas/concrete-barrier-4view.png +0 -0
  24. package/references/hard-surface/atlas/preview.pipeline.yaml +14 -0
  25. package/references/hard-surface/case-studies/benchmark/README.md +22 -0
  26. package/references/hard-surface/case-studies/benchmark/lod-bevel.pipeline.yaml +258 -0
  27. package/references/hard-surface/finishing/exports.yaml +10 -0
  28. package/references/hard-surface/finishing/finish-lod.pipeline.yaml +33 -0
  29. package/references/hard-surface/finishing/inputs/stack/stack.json +1 -0
  30. package/references/hard-surface/finishing/inputs/stack/stack.png +0 -0
  31. package/references/hard-surface/finishing/regularize.pipeline.yaml +46 -0
  32. package/references/hard-surface/measured-depth/sdf/compare.pipeline.yaml +12 -0
  33. package/references/hard-surface/measured-depth/sdf/inputs/field.npy +0 -0
  34. package/references/hard-surface/measured-depth/sdf/inputs/stack/stack.json +1 -0
  35. package/references/hard-surface/measured-depth/sdf/inputs/stack/stack.png +0 -0
  36. package/references/hard-surface/measured-depth/sdf/inputs/truth.json +1 -0
  37. package/references/hard-surface/measured-depth/sdf/sdf.guide.json +3 -0
  38. package/references/hard-surface/measured-depth/triple-dexel/compare.pipeline.yaml +12 -0
  39. package/references/hard-surface/measured-depth/triple-dexel/dexel.guide.json +3 -0
  40. package/references/hard-surface/measured-depth/triple-dexel/inputs/fixture.json +22 -0
  41. package/references/hard-surface/measured-depth/triple-dexel/inputs/stack/stack.json +22 -0
  42. package/references/hard-surface/measured-depth/triple-dexel/inputs/stack/stack.png +0 -0
  43. package/references/hard-surface/measured-depth/triple-dexel/inputs/triple-dexel.npz +0 -0
  44. package/references/hard-surface/schema/pipeline-fragment.schema.json +5 -0
  45. package/references/hard-surface/schema/pipeline.schema.json +181 -0
  46. package/schema/pipeline-fragment.schema.json +5 -0
  47. package/schema/pipeline.schema.json +181 -0
  48. package/verification/assembly.py +96 -0
  49. package/verification/landmarks.py +53 -0
  50. package/verification/panels.py +137 -0
  51. package/verification/projections.py +135 -0
  52. package/verification/verify.py +108 -0
  53. package/viewer/dist/assets/{GLTFExporter--hziUXc8.js → GLTFExporter-xdVCArY-.js} +1 -1
  54. package/viewer/dist/assets/compare-Du4RoRQO.js +6 -0
  55. package/viewer/dist/assets/compare.worker-CgJq-znx.js +21 -0
  56. package/viewer/dist/assets/presets-jXE0t1fU.js +1 -0
  57. package/viewer/dist/assets/preview-cache-BKV0EZl9.js +1 -0
  58. package/viewer/dist/assets/project-DtHHhfo-.js +17 -0
  59. package/viewer/dist/assets/reconstruct.worker-ONc9GyFO.js +21 -0
  60. package/viewer/dist/assets/{script-engine-CLj7QMLe.js → script-engine-Bs3azDYZ.js} +1 -1
  61. package/viewer/dist/assets/style-D6eZHs3D.js +4004 -0
  62. package/viewer/dist/assets/viewer-DIjS0No7.js +2 -0
  63. package/viewer/dist/compare.html +4 -4
  64. package/viewer/dist/index.html +9 -8
  65. package/viewer/dist/project.html +3 -3
  66. package/viewer/dist/assets/compare-DJ8rV3Rn.js +0 -6
  67. package/viewer/dist/assets/compare.worker-DK2lJl0n.js +0 -21
  68. package/viewer/dist/assets/presets-DwdZVYhs.js +0 -1
  69. package/viewer/dist/assets/preview-cache-DRF_H5pq.js +0 -58
  70. package/viewer/dist/assets/project-D8tR6U-_.js +0 -17
  71. package/viewer/dist/assets/reconstruct.worker-Cf8iZwT3.js +0 -21
  72. package/viewer/dist/assets/style-CWGgpweN.js +0 -3947
  73. package/viewer/dist/assets/viewer-CyGodHLY.js +0 -2
@@ -0,0 +1,21 @@
1
+ (function(){"use strict";const ct=["top","left","front","rear","right","bottom"];function fn(n){const t=[137,80,78,71,13,10,26,10];if(n.length<33||t.some((c,l)=>n[l]!==c)||String.fromCharCode(...n.subarray(12,16))!=="IHDR")throw new Error("Expected a PNG image.");const e=new DataView(n.buffer,n.byteOffset,n.byteLength),s=e.getUint32(16),o=e.getUint32(20);if(!s||!o||!Number.isSafeInteger(s*o*4))throw new Error("Invalid PNG dimensions.");return{width:s,height:o}}function Ht(n){const{width:t,height:e}=fn(n);if(t>8192||e>8192||t*e>16e6)throw new Error("PNG dimensions exceed the 8192 px or 16 MP input limit.");return{width:t,height:e}}function bt(n){const t=n.split(",").map(e=>e.trim());if(t.some(e=>!ct.includes(e)))throw new Error("Use directions top, left, front, rear, right, and bottom.");if(t.length!==4&&t.length!==6||new Set(t).size!==t.length||ct.slice(0,t.length).some(e=>!t.includes(e)))throw new Error("A layout needs the four required directions or all six, with no duplicates.");return t}function Kt(n,t){const{width:e,height:s}=n,o=new Uint8Array(n.data),c=e*s;for(let r=3;r<o.length;r+=4)if(o[r]<128)return{width:e,height:s,data:o};const l=new Uint8Array(c),a=new Uint32Array(c);let i=0,g=0;function f(r){if(l[r])return;l[r]=1;const h=r*4;Math.min(o[h],o[h+1],o[h+2])>=t&&(a[g++]=r)}for(let r=0;r<e;r++)f(r),f((s-1)*e+r);for(let r=1;r<s-1;r++)f(r*e),f(r*e+e-1);for(;i<g;){const r=a[i++];o[r*4+3]=0;const h=r%e;h&&f(r-1),h+1<e&&f(r+1),r>=e&&f(r-e),r+e<c&&f(r+e)}return{width:e,height:s,data:o}}function Jt(n,t){const{left:e,top:s,width:o,height:c}=t,l=new Uint8Array(o*c*4);for(let a=0;a<c;a++){const i=((s+a)*n.width+e)*4;l.set(n.data.subarray(i,i+o*4),a*o*4)}return{width:o,height:c,data:l}}function Yt(n,t){const{left:e,top:s,width:o,height:c}=t;let l=e+o,a=-1,i=s+c,g=-1;for(let f=s;f<s+c;f++)for(let r=e;r<e+o;r++)n.data[(f*n.width+r)*4+3]<128||(l=Math.min(l,r),a=Math.max(a,r),i=Math.min(i,f),g=Math.max(g,f));return a<0?null:{left:l,top:i,width:a-l+1,height:g-i+1}}function Pt(n){const t=[];let e=-1;for(let s=0;s<=n.length;s++)n[s]?e<0&&(e=s):e>=0&&(t.push([e,s]),e=-1);return t}function St(n,t,e){const s=new Uint8Array(n.width);for(let o=t;o<e;o++)for(let c=0;c<n.width;c++)n.data[(o*n.width+c)*4+3]>=128&&(s[c]=1);return Pt(s)}function An(n,t){bt(t.join(","));let e=St(n,0,n.height).map(([s,o])=>({left:s,top:0,width:o-s,height:n.height}));if(e.length!==t.length){const s=new Uint8Array(n.height);for(let o=0;o<n.height;o++)for(let c=0;c<n.width;c++)if(n.data[(o*n.width+c)*4+3]>=128){s[o]=1;break}e=Pt(s).flatMap(([o,c])=>St(n,o,c).map(([l,a])=>({left:l,top:o,width:a-l,height:c-o})))}if(e.length!==t.length)throw new Error(`Expected ${t.length} separated views, found ${e.length}. Use clear gutters or individual PNGs.`);return e.map(s=>Yt(n,s))}function hn(n,t,e=238){const s=Kt(n,e);return Object.fromEntries(An(s,t).map((o,c)=>{const l=Jt(s,o),a=l.width+2,i=l.height+2,g=new Uint8Array(a*i*4);for(let f=0;f<l.height;f++)g.set(l.data.subarray(f*l.width*4,(f+1)*l.width*4),((f+1)*a+1)*4);return[t[c],{width:a,height:i,data:g}]}))}function Nt(n,t=238){bt(Object.keys(n).join(","));const e=Object.entries(n);return Object.fromEntries(e.map(([s,o])=>{const c=Kt(o,t),l=Yt(c,{left:0,top:0,width:c.width,height:c.height});if(!l)throw new Error(`The ${s} view has an empty silhouette.`);return[s,Jt(c,l)]}))}function ln(n){const{top:t,left:e,front:s,rear:o}=n,c=e.width/e.height*t.width/t.height,l=s.width/s.height,a=[];Math.abs(c/l-1)>.2&&a.push("Top, left, and front proportions differ by more than 20%. Check alignment."),Math.abs(o.width/o.height/l-1)>.2&&a.push("Front and rear proportions differ by more than 20%.");const i=Object.entries(n).map(([f,r])=>({direction:f,width:r.width,height:r.height})),g={x:Math.max(t.width,s.width,o.width,n.bottom?.width??0),y:Math.max(t.height,e.width,n.right?.width??0,n.bottom?.height??0),z:Math.max(e.height,s.height,o.height,n.right?.height??0)};return{views:i,nativeSamples:g,warnings:a}}const zt=128;function Tt(n,t,e,s){if(!Number.isSafeInteger(s)||s<8)throw new Error("Layers must be a safe integer of at least 8.");if(!Number.isSafeInteger(e)||e<16)throw new Error("Resolution must be a safe integer of at least 16.");const o=Math.max(n,t),c=Math.max(2,Math.round(n/o*e)),l=Math.max(2,Math.round(t/o*e));if(!Number.isSafeInteger(c*l*s*4))throw new Error("Requested grid is too large to address its RGBA samples.");return{width:c,depth:l,layers:s}}var Ut={exports:{}},Ot;function gn(){return Ot||(Ot=1,(function(n){(function(){function t(a,i){var g=a.x-i.x,f=a.y-i.y;return g*g+f*f}function e(a,i,g){var f=i.x,r=i.y,h=g.x-f,u=g.y-r;if(h!==0||u!==0){var C=((a.x-f)*h+(a.y-r)*u)/(h*h+u*u);C>1?(f=g.x,r=g.y):C>0&&(f+=h*C,r+=u*C)}return h=a.x-f,u=a.y-r,h*h+u*u}function s(a,i){for(var g=a[0],f=[g],r,h=1,u=a.length;h<u;h++)r=a[h],t(r,g)>i&&(f.push(r),g=r);return g!==r&&f.push(r),f}function o(a,i,g,f,r){for(var h=f,u,C=i+1;C<g;C++){var p=e(a[C],a[i],a[g]);p>h&&(u=C,h=p)}h>f&&(u-i>1&&o(a,i,u,f,r),r.push(a[u]),g-u>1&&o(a,u,g,f,r))}function c(a,i){var g=a.length-1,f=[a[0]];return o(a,0,g,i,f),f.push(a[g]),f}function l(a,i,g){if(a.length<=2)return a;var f=i!==void 0?i*i:1;return a=g?a:s(a,f),a=c(a,f),a}n.exports=l,n.exports.default=l})()})(Ut)),Ut.exports}gn();function wn(n){const{width:t,height:e}=n,s=n.data.slice(),o=new Int32Array(t*e);let c=0,l=0;for(let i=0;i<o.length;i++)s[i*4+3]>=128&&(o[l++]=i);function a(i,g){s[g*4+3]>=128||(s.set(s.subarray(i*4,i*4+3),g*4),s[g*4+3]=255,o[l++]=g)}for(;c<l;){const i=o[c++],g=i%t;g&&a(i,i-1),g+1<t&&a(i,i+1),i>=t&&a(i,i-t),i+t<o.length&&a(i,i+t)}return{width:t,height:e,data:s}}const jt={top:[2,!0],bottom:[2,!1],left:[0,!1],right:[0,!0],front:[1,!0],rear:[1,!1]},un=[0,1,2];function dn(n,t){const e=n[t],s=n[t+1],o=n[t+2];return n[t+3]<128?0:e>145&&e-o>70&&s-o>20&&e-s>22?1:s>95&&o>105&&Math.min(s,o)-e>46&&o-s>-20?2:0}function Cn(n){const t={},e={},s=new Map,o=new Map;for(const[c,l]of Object.entries(n)){let a=function(A,w){!r[w]||h[w]>=0||(h[w]=h[A]+1,C.set(C.subarray(A*4,A*4+3),w*4),u[d++]=w)};const{width:i,height:g,data:f}=l,r=new Uint8Array(i*g),h=new Int32Array(r.length).fill(-1),u=new Int32Array(r.length),C=new Uint8Array(f),p=[0,0,0];for(let A=0;A<r.length;A++){const w=r[A]=dn(f,A*4);w&&p[w]++}const B=r.slice();for(let A=0;A<B.length;A++){const w=B[A];if(!w)continue;const m=A%i,Q=Math.floor(A/i);for(let M=-3;M<=3;M++)for(let x=-3;x<=3;x++){if(x*x+M*M>9||m+x<0||m+x>=i||Q+M<0||Q+M>=g)continue;const y=A+M*i+x,I=y*4;if(r[y]||f[I+3]<128)continue;const U=f[I],F=f[I+1],v=f[I+2];(w===1?U-v>12&&F-v>5&&U>=F-8:Math.min(F,v)-U>12)&&(r[y]=w)}}let d=0;for(let A=0;A<r.length;A++)r[A]||f[A*4+3]<128||(h[A]=0,u[d++]=A);for(let A=0;A<d;A++){const w=u[A],m=w%i;m>0&&a(w,w-1),m+1<i&&a(w,w+1),w>=i&&a(w,w-i),w+i<r.length&&a(w,w+i)}for(const A of[1,2]){const w=p[A]/(i*g)*(c==="front"?1.35:1);w<=(o.get(A)??0)||(o.set(A,w),s.set(A,c))}e[c]=r,t[c]={width:i,height:g,data:C}}return{clean:t,masks:e,owner:s}}function Bn(n,t,e){const s={};for(const a of e){const[i,g]=jt[a],f=un.filter(p=>p!==i),r=t[f[0]],h=t[f[1]],u=new Int32Array(r*h).fill(-1),C=[0,0,0];for(let p=0;p<h;p++)for(let B=0;B<r;B++){C[f[0]]=B,C[f[1]]=p;for(let d=0;d<t[i];d++)if(C[i]=g?t[i]-1-d:d,!!n[(C[2]*t[1]+C[1])*t[0]+C[0]]){u[p*r+B]=C[i]+Number(g);break}}s[a]={axis:i,axes:f,width:r,height:h,values:u}}function o(a,i){return[Math.max(0,Math.min(a.width-1,Math.floor(i[a.axes[0]]))),Math.max(0,Math.min(a.height-1,Math.floor(i[a.axes[1]])))]}function c(a,i){const g=s[a];if(!g)return-1;const[f,r]=o(g,i);return g.values[r*g.width+f]}function l(a,i,g=1.5){const f=c(a,i);return f>=0&&Math.abs(f-i[jt[a][0]])<=g}return{visible:l,firstHit:c}}function pn(n,t,e,s,o,c){const{width:l,height:a,data:i}=n,g=new Uint8Array(t.length),f=new Uint8Array(t.length),r=new Uint8Array(i.length),h=[],u=[],C=[],p=[];for(let d=0;d<t.length;d++){if(t[d]!==1||f[d])continue;const A=[d],w=new Map;let m=l,Q=0,M=a,x=0;f[d]=1;for(const I of A){const U=I%l,F=Math.floor(I/l);m=Math.min(m,U),Q=Math.max(Q,U),M=Math.min(M,F),x=Math.max(x,F);const v=w.get(F)??[U,U];w.set(F,[Math.min(v[0],U),Math.max(v[1],U)]);for(const b of[U>0?I-1:-1,U+1<l?I+1:-1,I-l,I+l])t[b]!==1||f[b]||(f[b]=1,A.push(b))}if(A.length<5||Q-m>l/4||x-M>a/4)continue;const y=new Map;for(const[I,[U,F]]of w){let v=-1;for(let b=U;b<=F;b++){const D=[(b+.5)/l*e[0],0,(1-(I+.5)/a)*e[2]];v=Math.max(v,c("front",D))}v>=0&&y.set(I,v)}if(!(y.size<2)){for(const I of A)y.has(Math.floor(I/l))&&(g[I]=1,r.set(i.subarray(I*4,I*4+4),I*4));for(const[I,U]of y){const[F,v]=w.get(I),b=F/l,D=(v+1)/l,H=I/a,k=(I+1)/a,G=(b-.5)*s[0],N=(D-.5)*s[0],J=(1-H)*s[2]-o[2],j=(1-k)*s[2]-o[2],_=(.5-(U+.65)/e[1])*s[1],S=h.length/3;h.push(G,J,_,N,J,_,N,j,_,G,j,_),u.push(0,0,-1,0,0,-1,0,0,-1,0,0,-1),C.push(S,S+1,S+2,S,S+2,S+3),p.push(b,H,D,H,D,k,b,k)}}}return{mesh:C.length?{target:"mesh",size:s,pivot:o,texture:{width:l,height:a,data:r},positions:Float32Array.from(h),normals:Float32Array.from(u),indices:Uint32Array.from(C),uvs:Float32Array.from(p)}:void 0,marked:g}}const Rt=Int8Array.from(atob("/////////////////////wAIA/////////////////8AAQn/////////////////AQgDCQgB/////////////wECCv////////////////8ACAMBAgr/////////////CQIKAAIJ/////////////wIIAwIKCAoJCP////////8DCwL/////////////////AAsCCAsA/////////////wEJAAIDC/////////////8BCwIBCQsJCAv/////////AwoBCwoD/////////////wAKAQAICggLCv////////8DCQADCwkLCgn/////////CQgKCggL/////////////wQHCP////////////////8EAwAHAwT/////////////AAEJCAQH/////////////wQBCQQHAQcDAf////////8BAgoIBAf/////////////AwQHAwAEAQIK/////////wkCCgkAAggEB/////////8CCgkCCQcCBwMHCQT/////CAQHAwsC/////////////wsEBwsCBAIABP////////8JAAEIBAcCAwv/////////BAcLCQQLCQsCCQIB/////wMKAQMLCgcIBP////////8BCwoBBAsBAAQHCwT/////BAcICQALCQsKCwAD/////wQHCwQLCQkLCv////////8JBQT/////////////////CQUEAAgD/////////////wAFBAEFAP////////////8IBQQIAwUDAQX/////////AQIKCQUE/////////////wMACAECCgQJBf////////8FAgoFBAIEAAL/////////AgoFAwIFAwUEAwQI/////wkFBAIDC/////////////8ACwIACAsECQX/////////AAUEAAEFAgML/////////wIBBQIFCAIICwQIBf////8KAwsKAQMJBQT/////////BAkFAAgBCAoBCAsK/////wUEAAUACwULCgsAA/////8FBAgFCAoKCAv/////////CQcIBQcJ/////////////wkDAAkFAwUHA/////////8ABwgAAQcBBQf/////////AQUDAwUH/////////////wkHCAkFBwoBAv////////8KAQIJBQAFAwAFBwP/////CAACCAIFCAUHCgUC/////wIKBQIFAwMFB/////////8HCQUHCAkDCwL/////////CQUHCQcCCQIAAgcL/////wIDCwABCAEHCAEFB/////8LAgELAQcHAQX/////////CQUICAUHCgEDCgML/////wUHAAUACQcLAAEACgsKAP8LCgALAAMKBQAIAAcFBwD/CwoFBwsF/////////////woGBf////////////////8ACAMFCgb/////////////CQABBQoG/////////////wEIAwEJCAUKBv////////8BBgUCBgH/////////////AQYFAQIGAwAI/////////wkGBQkABgACBv////////8FCQgFCAIFAgYDAgj/////AgMLCgYF/////////////wsACAsCAAoGBf////////8AAQkCAwsFCgb/////////BQoGAQkCCQsCCQgL/////wYDCwYFAwUBA/////////8ACAsACwUABQEFCwb/////AwsGAAMGAAYFAAUJ/////wYFCQYJCwsJCP////////8FCgYEBwj/////////////BAMABAcDBgUK/////////wEJAAUKBggEB/////////8KBgUBCQcBBwMHCQT/////BgECBgUBBAcI/////////wECBQUCBgMABAMEB/////8IBAcJAAUABgUAAgb/////BwMJBwkEAwIJBQkGAgYJ/wMLAgcIBAoGBf////////8FCgYEBwIEAgACBwv/////AAEJBAcIAgMLBQoG/////wkCAQkLAgkECwcLBAUKBv8IBAcDCwUDBQEFCwb/////BQELBQsGAQALBwsEAAQL/wAFCQAGBQADBgsGAwgEB/8GBQkGCQsEBwkHCwn/////CgQJBgQK/////////////wQKBgQJCgAIA/////////8KAAEKBgAGBAD/////////CAMBCAEGCAYEBgEK/////wEECQECBAIGBP////////8DAAgBAgkCBAkCBgT/////AAIEBAIG/////////////wgDAggCBAQCBv////////8KBAkKBgQLAgP/////////AAgCAggLBAkKBAoG/////wMLAgABBgAGBAYBCv////8GBAEGAQoECAECAQsICwH/CQYECQMGCQEDCwYD/////wgLAQgBAAsGAQkBBAYEAf8DCwYDBgAABgT/////////BgQICwYI/////////////wcKBgcICggJCv////////8ABwMACgcACQoGBwr/////CgYHAQoHAQcIAQgA/////woGBwoHAQEHA/////////8BAgYBBggBCAkIBgf/////AgYJAgkBBgcJAAkDBwMJ/wcIAAcABgYAAv////////8HAwIGBwL/////////////AgMLCgYICggJCAYH/////wIABwIHCwAJBwYHCgkKB/8BCAABBwgBCgcGBwoCAwv/CwIBCwEHCgYBBgcB/////wgJBggGBwkBBgsGAwEDBv8ACQELBgf/////////////BwgABwAGAwsACwYA/////wcLBv////////////////8HBgv/////////////////AwAICwcG/////////////wABCQsHBv////////////8IAQkIAwELBwb/////////CgECBgsH/////////////wECCgMACAYLB/////////8CCQACCgkGCwf/////////BgsHAgoDCggDCgkI/////wcCAwYCB/////////////8HAAgHBgAGAgD/////////AgcGAgMHAAEJ/////////wEGAgEIBgEJCAgHBv////8KBwYKAQcBAwf/////////CgcGAQcKAQgHAQAI/////wADBwAHCgAKCQYKB/////8HBgoHCggICgn/////////BggECwgG/////////////wMGCwMABgAEBv////////8IBgsIBAYJAAH/////////CQQGCQYDCQMBCwMG/////wYIBAYLCAIKAf////////8BAgoDAAsABgsABAb/////BAsIBAYLAAIJAgoJ/////woJAwoDAgkEAwsDBgQGA/8IAgMIBAIEBgL/////////AAQCBAYC/////////////wEJAAIDBAIEBgQDCP////8BCQQBBAICBAb/////////CAEDCAYBCAQGBgoB/////woBAAoABgYABP////////8EBgMEAwgGCgMAAwkKCQP/CgkEBgoE/////////////wQJBQcGC/////////////8ACAMECQULBwb/////////BQABBQQABwYL/////////wsHBggDBAMFBAMBBf////8JBQQKAQIHBgv/////////BgsHAQIKAAgDBAkF/////wcGCwUECgQCCgQAAv////8DBAgDBQQDAgUKBQILBwb/BwIDBwYCBQQJ/////////wkFBAAIBgAGAgYIB/////8DBgIDBwYBBQAFBAD/////BgIIBggHAgEIBAgFAQUI/wkFBAoBBgEHBgEDB/////8BBgoBBwYBAAcIBwAJBQT/BAAKBAoFAAMKBgoHAwcK/wcGCgcKCAUECgQICv////8GCQUGCwkLCAn/////////AwYLAAYDAAUGAAkF/////wALCAAFCwABBQUGC/////8GCwMGAwUFAwH/////////AQIKCQULCQsICwUG/////wALAwAGCwAJBgUGCQECCv8LCAULBQYIAAUKBQIAAgX/BgsDBgMFAgoDCgUD/////wUICQUCCAUGAgMIAv////8JBQYJBgAABgL/////////AQUIAQgABQYIAwgCBgII/wEFBgIBBv////////////8BAwYBBgoDCAYFBgkICQb/CgEACgAGCQUABQYA/////wADCAUGCv////////////8KBQb/////////////////CwUKBwUL/////////////wsFCgsHBQgDAP////////8FCwcFCgsBCQD/////////CgcFCgsHCQgBCAMB/////wsBAgsHAQcFAf////////8ACAMBAgcBBwUHAgv/////CQcFCQIHCQACAgsH/////wcFAgcCCwUJAgMCCAkIAv8CBQoCAwUDBwX/////////CAIACAUCCAcFCgIF/////wkAAQUKAwUDBwMKAv////8JCAIJAgEIBwIKAgUHBQL/AQMFAwcF/////////////wAIBwAHAQEHBf////////8JAAMJAwUFAwf/////////CQgHBQkH/////////////wUIBAUKCAoLCP////////8FAAQFCwAFCgsLAwD/////AAEJCAQKCAoLCgQF/////woLBAoEBQsDBAkEAQMBBP8CBQECCAUCCwgEBQj/////AAQLAAsDBAULAgsBBQEL/wACBQAFCQILBQQFCAsIBf8JBAUCCwP/////////////AgUKAwUCAwQFAwgE/////wUKAgUCBAQCAP////////8DCgIDBQoDCAUEBQgAAQn/BQoCBQIEAQkCCQQC/////wgEBQgFAwMFAf////////8ABAUBAAX/////////////CAQFCAUDCQAFAAMF/////wkEBf////////////////8ECwcECQsJCgv/////////AAgDBAkHCQsHCQoL/////wEKCwELBAEEAAcEC/////8DAQQDBAgBCgQHBAsKCwT/BAsHCQsECQILCQEC/////wkHBAkLBwkBCwILAQAIA/8LBwQLBAICBAD/////////CwcECwQCCAMEAwIE/////wIJCgIHCQIDBwcECf////8JCgcJBwQKAgcIBwACAAf/AwcKAwoCBwQKAQoABAAK/wEKAggHBP////////////8ECQEEAQcHAQP/////////BAkBBAEHAAgBCAcB/////wQAAwcEA/////////////8ECAf/////////////////CQoICgsI/////////////wMACQMJCwsJCv////////8AAQoACggICgv/////////AwEKCwMK/////////////wECCwELCQkLCP////////8DAAkDCQsBAgkCCwn/////AAILCAAL/////////////wMCC/////////////////8CAwgCCAoKCAn/////////CQoCAAkC/////////////wIDCAIICgABCAEKCP////8BCgL/////////////////AQMICQEI/////////////wAJAf////////////////8AAwj//////////////////////////////////////w=="),n=>n.charCodeAt(0)),ht=[[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]],Vt=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]];function mn(n,t,e){const s=Math.min(e[2]*(t[2]-2)*.042,Math.max(e[0],e[1])*1.65),o=[1,t[0],t[0]*t[1]];let c=Float32Array.from(n),l=new Float32Array(c.length);for(let a=0;a<t.length;a++){const i=Math.max(.6,Math.min(5,s/e[a])),g=Math.ceil(i*2.5),f=Array.from({length:g+1},(p,B)=>Math.exp(-B*B/(2*i*i))),r=f[0]+2*f.slice(1).reduce((p,B)=>p+B,0),h=o[a],u=t[a],C=h*u;for(let p=0;p<c.length;p+=C)for(let B=0;B<h;B++)for(let d=0;d<u;d++){const A=p+B+d*h;let w=f[0]*c[A];for(let m=1;m<=g;m++)d>=m&&(w+=f[m]*c[A-m*h]),d+m<u&&(w+=f[m]*c[A+m*h]);l[A]=w/r}[c,l]=[l,c]}return c}function qt(n,t,e,s){const o=t+2,c=e+2,l=s+2,a=o*c,i=a*l,g=new Uint8Array(i);for(let f=0;f<s;f++)for(let r=0;r<e;r++){const h=(f*e+r)*t;g.set(n.subarray(h,h+t),(f+1)*a+(r+1)*o+1)}return{nx:o,ny:c,nz:l,plane:a,count:i,occupancy:g}}function Ft(n,t,e,s,o){const{nx:c,ny:l,nz:a,plane:i,count:g,occupancy:f}=qt(n,t,e,s),r=o?mn(f,[c,l,a],[o[0]/t,o[1]/e,o[2]/s]):new Float32Array(g);for(let w=0;w<a;w++)for(let m=0;m<l;m++)for(let Q=0;Q<c;Q++){const M=w*i+m*c+Q,x=(Q>0?f[M-1]:0)+(Q+1<c?f[M+1]:0)+(m>0?f[M-c]:0)+(m+1<l?f[M+c]:0)+(w>0?f[M-i]:0)+(w+1<a?f[M+i]:0),y=f[M]*.64+x*.06;r[M]=o?r[M]*.92+y*.08:y}const h=[0,1,c+1,c,i,i+1,i+c+1,i+c],u=new Int32Array(g*3).fill(-1),C=[],p=[],B=[];function d(w,m){return(r[w-m]??0)-(r[w+m]??0)}function A(w,m,Q,M,x){const[y,I]=Vt[x],U=ht[y],F=ht[I],v=M+h[y],b=M+h[I],D=U[0]!==F[0]?0:U[1]!==F[1]?1:2,H=Math.min(v,b)*3+D;if(u[H]>=0)return u[H];const k=C.length/3,G=(.5-r[v])/(r[b]-r[v]);return C.push(w-.5+U[0]+(F[0]-U[0])*G,m-.5+U[1]+(F[1]-U[1])*G,Q-.5+U[2]+(F[2]-U[2])*G),p.push(...[1,c,i].map(N=>d(v,N)*(1-G)+d(b,N)*G)),u[H]=k,k}for(let w=0;w<a-1;w++)for(let m=0;m<l-1;m++)for(let Q=0;Q<c-1;Q++){const M=w*i+m*c+Q;let x=0;for(let y=0;y<8;y++)r[M+h[y]]<.5&&(x|=1<<y);if(!(x===0||x===255))for(let y=x*16;Rt[y]>=0;y++)B.push(A(Q,m,w,M,Rt[y]))}return{positions:C,gradients:p,indices:B}}function Xt(n,t,e,s){const o=[t,e,s],c=[1,t,t*e],l=[],a=[],i=[],g=[[0,0],[1,0],[1,1],[0,1]];for(let f=0;f<s;f++)for(let r=0;r<e;r++)for(let h=0;h<t;h++){const u=(f*e+r)*t+h;if(!n[u])continue;const C=[h,r,f];for(let p=0;p<3;p++){const B=(p+1)%3,d=(p+2)%3;for(const A of[-1,1]){const w=C[p]+A;if(w>=0&&w<o[p]&&n[u+A*c[p]])continue;const m=[0,0,0];m[p]=A;const Q=l.length/3;for(const[U,F]of g){const v=[...C];v[p]+=+(A>0),v[B]+=U,v[d]+=F,l.push(...v),a.push(...m)}const M=Q,x=Q+1,y=Q+2,I=Q+3;A>0?i.push(M,x,y,M,y,I):i.push(M,y,x,M,I,y)}}}return{positions:l,gradients:a,indices:i}}function Qn(n,t,e,s){const{nx:o,ny:c,nz:l,plane:a,count:i,occupancy:g}=qt(n,t,e,s),f=[1,o,a],r=ht.map(([A,w,m])=>A+o*w+a*m),h=new Int32Array(i),u=[],C=[],p=[];function B(A,w,m){const Q=u[w*3]-u[A*3],M=u[w*3+1]-u[A*3+1],x=u[w*3+2]-u[A*3+2],y=u[m*3]-u[A*3],I=u[m*3+1]-u[A*3+1],U=u[m*3+2]-u[A*3+2];return[M*U-x*I,x*y-Q*U,Q*I-M*y]}function d(A,w,m){p.push(A,w,m);const[Q,M,x]=B(A,w,m);for(const y of[A,w,m])C[y*3]+=Q,C[y*3+1]+=M,C[y*3+2]+=x}for(let A=0;A<l-1;A++)for(let w=0;w<c-1;w++)for(let m=0;m<o-1;m++){const Q=A*a+w*o+m;let M=0;for(let v=0;v<8;v++)M|=g[Q+r[v]]<<v;if(M===0||M===255)continue;let x=0,y=0,I=0,U=0;for(const[v,b]of Vt)(M>>v&1)!==(M>>b&1)&&(x+=(ht[v][0]+ht[b][0])/2,y+=(ht[v][1]+ht[b][1])/2,I+=(ht[v][2]+ht[b][2])/2,U++);const F=u.length/3;h[Q]=F,u.push(m-.5+x/U,w-.5+y/U,A-.5+I/U),C.push(0,0,0);for(let v=0;v<3;v++){if(g[Q]===g[Q+f[v]])continue;const b=f[(v+1)%3],D=f[(v+2)%3],H=h[Q-b],k=h[Q-b-D],G=h[Q-D];g[Q]?(d(F,H,k),d(F,k,G)):(d(F,G,k),d(F,k,H))}}for(let A=0;A<p.length;A++){const w=p[A]*3;if(Math.abs(C[w])+Math.abs(C[w+1])+Math.abs(C[w+2])>1e-10)continue;const m=A-A%3;[C[w],C[w+1],C[w+2]]=B(p[m],p[m+1],p[m+2])}return{positions:u,gradients:C,indices:p}}const gt=(n,t,e)=>Math.min(e,Math.max(t,n));function mt(n,t,e,s){switch(n){case"top":return[t,e];case"bottom":return[t,1-e];case"left":return[1-e,1-s];case"right":return[e,1-s];case"front":return[t,1-s];case"rear":return[1-t,1-s]}}function Qt(n,t,e){return(gt(Math.floor(e*n.height),0,n.height-1)*n.width+gt(Math.floor(t*n.width),0,n.width-1))*4}function _t(n,t,e){if(n.width===t&&n.height===e)return n;const s=new Uint8Array(t*e*4);for(let o=0;o<e;o++)for(let c=0;c<t;c++){const l=Qt(n,(c+.5)/t,(o+.5)/e),a=(o*t+c)*4;for(let i=0;i<4;i++)s[a+i]=n.data[l+i]}return{width:t,height:e,data:s}}function Mt(n,t,e,s){const o=[Math.max(0,s),Math.max(0,-t),Math.max(0,e),Math.max(0,-e),Math.max(0,t),Math.max(0,-s)];return n.right||(o[1]=Math.abs(t)),n.bottom||(o[0]=Math.abs(s)),[...ct].filter(c=>n[c]).sort((c,l)=>o[ct.indexOf(l)]-o[ct.indexOf(c)])}function Mn(n,t){const e=n.top,s=n.front,o=n.left,c=t.layers??zt,l=t.resolution??96,a=t.height??1;if(!Number.isFinite(a)||a<=0)throw new Error("Height must be positive.");if(t.pivot&&t.pivot!=="center"&&t.pivot!=="ground")throw new Error("Pivot must be ground or center.");const i=o.width/o.height*a,[g,f,r]=t.size??[(s.width/s.height*a+i*e.width/e.height)/2,i,a];if(![g,f,r].every(B=>Number.isFinite(B)&&B>0))throw new Error("Part dimensions must be positive.");const{width:h,depth:u}=Tt(g,f,l,c),C=[g,f,r],p=[0,0,t.pivot==="center"?r/2:0];return{width:h,depth:u,layers:c,size:C,pivot:p}}function $t(n,t,e){const{width:s,depth:o,layers:c,size:l,pivot:a}=Mn(n,t),i={};for(const C of ct){const p=n[C];if(!p)continue;const B=C!=="top"&&C!=="bottom";i[C]=_t(p,C==="left"||C==="right"?o:s,B?c:o)}const g=Object.entries(i),f=(C,p,B,d,A)=>p.data[Qt(p,...mt(C,B,d,A))+3]>=128,r=new Uint8Array(s*o*c);let h=0;const u=t.profile==="round"||t.profile==="round-base";for(let C=0;C<c;C++)for(let p=0;p<o;p++)for(let B=0;B<s;B++){const d=(B+.5)/s,A=(p+.5)/o,w=(C+.5)/c;(n.right?g.every(([Q,M])=>f(Q,M,d,A,w)):f("top",i.top,d,A,w)&&f("left",i.left,d,A,w)&&(f("front",i.front,d,A,w)||f("rear",i.rear,d,A,w)))&&(r[(C*o+p)*s+B]=1,h++)}if(u){const C=s*o;for(let p=0;p<c;p++){if(t.profile==="round-base"&&(p+.5)/c<.03)continue;let B=s,d=-1,A=o,w=-1;const m=p*C;for(let Q=0;Q<o;Q++)for(let M=0;M<s;M++)r[m+Q*s+M]&&(B=Math.min(B,M),d=Math.max(d,M),A=Math.min(A,Q),w=Math.max(w,Q));if(!(d<B))for(let Q=A;Q<=w;Q++)for(let M=B;M<=d;M++){if(((2*M-B-d)/(d-B+1))**2+((2*Q-A-w)/(w-A+1))**2<=1)continue;const x=m+Q*s+M;h-=r[x],r[x]=0}}}if(!h){if(e)return e;throw new Error("The aligned views have no common volume.")}return{width:s,depth:o,layers:c,size:l,pivot:a,volume:r,aligned:i}}function vn(n,t={},e=!1){const s=new Map,o=new Map(s);let c=0,l=0;for(const[i,g]of[[n,s],[t,o]])for(const f of ct){const r=i[f];if(!r)continue;const h=Math.min(1,512/Math.max(r.width,r.height)),u=_t(r,Math.max(1,Math.round(r.width*h)),Math.max(1,Math.round(r.height*h)));g.set(f,{image:e?wn(u):u,left:c+1}),c+=u.width+2,l=Math.max(l,u.height+2)}const a=new Uint8Array(c*l*4).fill(255);for(const{image:i,left:g}of[...s.values(),...o.values()])for(let f=-1;f<=i.height;f++)for(let r=-1;r<=i.width;r++){const h=(gt(f,0,i.height-1)*i.width+gt(r,0,i.width-1))*4,u=((f+1)*c+g+r)*4;for(let C=0;C<3;C++)a[u+C]=i.data[h+3]>=128?i.data[h+C]:137}return{tiles:s,accents:o,texture:{width:c,height:l,data:a}}}function Wt(n,t,e="rgb",s="marching-cubes"){const{width:o,depth:c,layers:l,size:a,pivot:i,volume:g}=n,f={"marching-cubes":Ft,"surface-nets":Qn,voxel:Xt}[s],r=f(g,o,c,l,e==="depth"?a:void 0);if(!r.indices.length&&e==="depth")return Wt(n,t,"id");const h=new Int32Array(o*c).fill(-1),u=new Int32Array(o*c).fill(l),C=o*c;for(let v=0;v<l;v++)for(let b=0;b<C;b++)g[v*C+b]&&(h[b]=v,u[b]=Math.min(u[b],v));function p(v,b,D,H){const k=gt(Math.floor(b*o),0,o-1),G=gt(Math.floor(D*c),0,c-1),N=v[G*o+k];if(Math.abs(N+.5-H*l)>2)return!1;let J=0;for(const[j,_]of[[2,0],[-2,0],[0,2],[0,-2]]){const S=k+j,$=G+_;if(!(S<0||S>=o||$<0||$>=c)){if(Math.abs(v[$*o+S]-N)>(t.bottom?2:1))return!1;J++}}return J>=(t.bottom?2:3)}const B=e==="rgb"?void 0:Cn(t),d={};for(const v of B?.owner.values()??[])d[v]=t[v];const A=B?Bn(g,[o,c,l],ct):void 0,w=B?.owner.get(1)==="front"&&A&&t.front&&B.masks.front?pn(t.front,B.masks.front,[o,c,l],a,i,A.firstHit):void 0,{texture:m,tiles:Q,accents:M}=vn(B?.clean??t,d),x=[],y=[],I=[],U=[],F=new Map;for(let v=0;v<r.indices.length;v+=3){const b=r.indices.slice(v,v+3),D=[0,1,2].map(R=>b.reduce((V,E)=>V+r.gradients[E*3+R],0)),H=[0,1,2].map(R=>b.reduce((V,E)=>V+r.positions[E*3+R],0)),k=[H[0]/(3*o),H[1]/(3*c),H[2]/(3*l)];let G=Mt(t,D[0],D[1],D[2]);const N=D[2]<0&&t.bottom?"bottom":"top",J=D[2]<0?u:h,j=e==="depth"&&A&&Math.abs(D[2])*l/a[2]>1.55*Math.max(Math.abs(D[0])*o/a[0],Math.abs(D[1])*c/a[1])&&A.visible(N,H.map(R=>R/3),3);if(!j&&!p(J,k[0],k[1],k[2])){const R=D[0],V=D[1];G=Math.hypot(R,V)>.1?Mt(t,R,V,0):Mt(t,k[0]-.5,k[1]-.5,0),G=[...G.filter(E=>E!=="top"&&E!=="bottom"),N]}const _=R=>{const V=t[R];return V.data[Qt(V,...mt(R,...k))+3]>=128};let S=j&&_(N)?N:G.find(_)??G[0],$=!1;if(B&&A){const R=H.map(K=>K/3),V=e==="depth"?3:1.5,E=Mt(t,D[0],D[1],D[2]),L=[Math.max(0,D[2]),Math.max(0,-D[0]),Math.max(0,D[1]),Math.max(0,-D[1]),Math.max(0,D[0]),Math.max(0,-D[2])],P=Math.max(...L);for(const K of E){if(!d[K]||L[ct.indexOf(K)]<=P*.45||!A.visible(K,R,V))continue;const Y=d[K],O=Qt(Y,...mt(K,...k))/4,q=B.masks[K][O];if(!(B.owner.get(q)!==K||K==="front"&&w?.marked[O])){S=K,$=!0;break}}}const{image:lt,left:ft}=($?M:Q).get(S);for(const R of b){const V=R*12+ct.indexOf(S)+($?6:0);let E=F.get(V);if(E===void 0){E=x.length/3,F.set(V,E);const L=R*3,P=r.positions[L]/o,K=r.positions[L+1]/c,Y=r.positions[L+2]/l;x.push((P-.5)*a[0]-i[0],Y*a[2]-i[2],(.5-K)*a[1]+i[1]);const O=r.gradients[L]*o/a[0],q=r.gradients[L+1]*c/a[1],X=r.gradients[L+2]*l/a[2],T=Math.hypot(O,q,X)||1;y.push(O/T,X/T,-q/T);const[W,st]=mt(S,P,K,Y);U.push((ft+.5+gt(W,0,1)*(lt.width-1))/m.width,(1.5+gt(st,0,1)*(lt.height-1))/m.height)}I.push(E)}}return{target:"mesh",size:a,pivot:i,texture:m,positions:Float32Array.from(x),normals:Float32Array.from(y),indices:Uint32Array.from(I),uvs:Float32Array.from(U),...w?.mesh&&{frontAccents:w.mesh}}}function xn(n,t){const{width:e,depth:s,layers:o,size:c,pivot:l,volume:a}=n,i=Math.min(o,Math.max(1,Math.floor(4096/e))),g=e*i,f=s*Math.ceil(o/i),r=new Uint8Array(g*f*4),h=(B,d,A)=>+(B>=0&&B<e&&d>=0&&d<s&&A>=0&&A<o&&a[(A*s+d)*e+B]>0),u=new Int32Array(e*s).fill(-1);for(let B=0;B<o;B++)for(let d=0;d<u.length;d++)a[B*u.length+d]&&(u[d]=B);const C=Array.from({length:27},(B,d)=>Mt(t,d%3-1,Math.floor(d/3)%3-1,Math.floor(d/9)-1)),p=(B,d,A)=>B<0||B>=e||d<0||d>=s||Math.abs(u[d*e+B]-A)<=1;for(let B=0;B<o;B++)for(let d=0;d<s;d++)for(let A=0;A<e;A++){if(!h(A,d,B))continue;const w=h(A-1,d,B)-h(A+1,d,B),m=h(A,d-1,B)-h(A,d+1,B),Q=h(A,d,B-1)-h(A,d,B+1),M=w+1+(m+1)*3+(Q+1)*9,x=((Math.floor(B/i)*s+d)*g+B%i*e+A)*4,y=u[d*e+A],I=B===y&&p(A-2,d,B)&&p(A+2,d,B)&&p(A,d-2,B)&&p(A,d+2,B),U=C[M],F=I||Q<0&&t.bottom?U:C[M-Q*9];let v=0,b=0,D=0,H=0;for(const k of F){if(!I&&k==="top")continue;const G=t[k],N=Qt(G,...mt(k,(A+.5)/e,(d+.5)/s,(B+.5)/o));if(G.data[N+3]<128)continue;const J=G.data[N],j=G.data[N+1],_=G.data[N+2];if(v&&Math.max(Math.abs(J-b/v),Math.abs(j-D/v),Math.abs(_-H/v))>66)continue;const S=k==="front"||k==="rear"?.1+Math.abs(m):k==="left"||k==="right"?.1+Math.abs(w):.1+Math.abs(Q);b+=J*S,D+=j*S,H+=_*S,v+=S}v&&(r[x]=Math.round(b/v),r[x+1]=Math.round(D/v),r[x+2]=Math.round(H/v),r[x+3]=255)}return{target:"stack",size:c,pivot:l,width:e,depth:s,layers:o,columns:i,spacing:c[2]/o,texture:{width:g,height:f,data:r}}}function yn(n,t){return["rgb","id","depth"].map(e=>Wt(t,n,e))}function Zt(n,t){const{size:e,pivot:s,width:o,depth:c,layers:l}=n,a=new Float32Array(t.positions.length),i=new Float32Array(a.length);for(let g=0;g<a.length;g+=3){a[g]=(t.positions[g]/o-.5)*e[0],a[g+1]=t.positions[g+2]/l*e[2]-s[2],a[g+2]=(.5-t.positions[g+1]/c)*e[1];const f=t.gradients[g]*o/e[0],r=t.gradients[g+2]*l/e[2],h=-t.gradients[g+1]*c/e[1],u=Math.hypot(f,r,h)||1;i.set([f/u,r/u,h/u],g)}return{target:"mesh",size:e,pivot:s,positions:a,normals:i,indices:Uint32Array.from(t.indices),uvs:new Float32Array(a.length/3*2),texture:{width:1,height:1,data:Uint8Array.of(255,255,255,255)}}}function En(n,t={}){const e=Nt(n,t.threshold),s=$t(e,t),o=$t(e,{...t,size:s.size,resolution:Math.max(16,Math.min(48,Math.floor((t.resolution??96)/2))),layers:Math.max(8,Math.min(32,Math.floor(s.layers/2)))},s),{volume:c,width:l,depth:a,layers:i}=o,g=Zt(o,Xt(c,l,a,i)),f=Zt(o,Ft(c,l,a,i)),r=h=>[h.width,h.depth,h.layers];return{voxel:g,marching:f,meshes:yn(e,s),stack:xn(s,s.aligned),coarseGrid:r(o),fullGrid:r(s)}}var ot=Uint8Array,Bt=Uint16Array,In=Int32Array,tn=new ot([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),nn=new ot([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),bn=new ot([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),en=function(n,t){for(var e=new Bt(31),s=0;s<31;++s)e[s]=t+=1<<n[s-1];for(var o=new In(e[30]),s=1;s<30;++s)for(var c=e[s];c<e[s+1];++c)o[c]=c-e[s]<<5|s;return{b:e,r:o}},on=en(tn,2),rn=on.b,Un=on.r;rn[28]=258,Un[258]=28;for(var Fn=en(nn,0),kn=Fn.b,kt=new Bt(32768),z=0;z<32768;++z){var wt=(z&43690)>>1|(z&21845)<<1;wt=(wt&52428)>>2|(wt&13107)<<2,wt=(wt&61680)>>4|(wt&3855)<<4,kt[z]=((wt&65280)>>8|(wt&255)<<8)>>1}for(var vt=(function(n,t,e){for(var s=n.length,o=0,c=new Bt(t);o<s;++o)n[o]&&++c[n[o]-1];var l=new Bt(t);for(o=1;o<t;++o)l[o]=l[o-1]+c[o-1]<<1;var a;if(e){a=new Bt(1<<t);var i=15-t;for(o=0;o<s;++o)if(n[o])for(var g=o<<4|n[o],f=t-n[o],r=l[n[o]-1]++<<f,h=r|(1<<f)-1;r<=h;++r)a[kt[r]>>i]=g}else for(a=new Bt(s),o=0;o<s;++o)n[o]&&(a[o]=kt[l[n[o]-1]++]>>15-n[o]);return a}),xt=new ot(288),z=0;z<144;++z)xt[z]=8;for(var z=144;z<256;++z)xt[z]=9;for(var z=256;z<280;++z)xt[z]=7;for(var z=280;z<288;++z)xt[z]=8;for(var sn=new ot(32),z=0;z<32;++z)sn[z]=5;var Dn=vt(xt,9,1),Ln=vt(sn,5,1),Dt=function(n){for(var t=n[0],e=1;e<n.length;++e)n[e]>t&&(t=n[e]);return t},rt=function(n,t,e){var s=t/8|0;return(n[s]|n[s+1]<<8)>>(t&7)&e},Lt=function(n,t){var e=t/8|0;return(n[e]|n[e+1]<<8|n[e+2]<<16)>>(t&7)},Gn=function(n){return(n+7)/8|0},Hn=function(n,t,e){return(e==null||e>n.length)&&(e=n.length),new ot(n.subarray(t,e))},Kn=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],it=function(n,t,e){var s=new Error(t||Kn[n]);if(s.code=n,Error.captureStackTrace&&Error.captureStackTrace(s,it),!e)throw s;return s},Jn=function(n,t,e,s){var o=n.length,c=s?s.length:0;if(!o||t.f&&!t.l)return e||new ot(0);var l=!e,a=l||t.i!=2,i=t.i;l&&(e=new ot(o*3));var g=function(K){var Y=e.length;if(K>Y){var O=new ot(Math.max(Y*2,K));O.set(e),e=O}},f=t.f||0,r=t.p||0,h=t.b||0,u=t.l,C=t.d,p=t.m,B=t.n,d=o*8;do{if(!u){f=rt(n,r,1);var A=rt(n,r+1,3);if(r+=3,A)if(A==1)u=Dn,C=Ln,p=9,B=5;else if(A==2){var M=rt(n,r,31)+257,x=rt(n,r+10,15)+4,y=M+rt(n,r+5,31)+1;r+=14;for(var I=new ot(y),U=new ot(19),F=0;F<x;++F)U[bn[F]]=rt(n,r+F*3,7);r+=x*3;for(var v=Dt(U),b=(1<<v)-1,D=vt(U,v,1),F=0;F<y;){var H=D[rt(n,r,b)];r+=H&15;var w=H>>4;if(w<16)I[F++]=w;else{var k=0,G=0;for(w==16?(G=3+rt(n,r,3),r+=2,k=I[F-1]):w==17?(G=3+rt(n,r,7),r+=3):w==18&&(G=11+rt(n,r,127),r+=7);G--;)I[F++]=k}}var N=I.subarray(0,M),J=I.subarray(M);p=Dt(N),B=Dt(J),u=vt(N,p,1),C=vt(J,B,1)}else it(1);else{var w=Gn(r)+4,m=n[w-4]|n[w-3]<<8,Q=w+m;if(Q>o){i&&it(0);break}a&&g(h+m),e.set(n.subarray(w,Q),h),t.b=h+=m,t.p=r=Q*8,t.f=f;continue}if(r>d){i&&it(0);break}}a&&g(h+131072);for(var j=(1<<p)-1,_=(1<<B)-1,S=r;;S=r){var k=u[Lt(n,r)&j],$=k>>4;if(r+=k&15,r>d){i&&it(0);break}if(k||it(2),$<256)e[h++]=$;else if($==256){S=r,u=null;break}else{var lt=$-254;if($>264){var F=$-257,ft=tn[F];lt=rt(n,r,(1<<ft)-1)+rn[F],r+=ft}var R=C[Lt(n,r)&_],V=R>>4;R||it(3),r+=R&15;var J=kn[V];if(V>3){var ft=nn[V];J+=Lt(n,r)&(1<<ft)-1,r+=ft}if(r>d){i&&it(0);break}a&&g(h+131072);var E=h+lt;if(h<J){var L=c-J,P=Math.min(J,E);for(L+h<0&&it(3);h<P;++h)e[h]=s[L+h]}for(;h<E;++h)e[h]=e[h-J]}}t.l=u,t.p=S,t.b=h,t.f=f,u&&(f=1,t.m=p,t.d=C,t.n=B)}while(!f);return h!=e.length&&l?Hn(e,0,h):e.subarray(0,h)},Yn=new ot(0),Pn=function(n,t){return((n[0]&15)!=8||n[0]>>4>7||(n[0]<<8|n[1])%31)&&it(6,"invalid zlib data"),(n[1]>>5&1)==+!t&&it(6,"invalid zlib data: "+(n[1]&32?"need":"unexpected")+" dictionary"),(n[1]>>3&4)+2};function Sn(n,t){return Jn(n.subarray(Pn(n,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}var Nn=typeof TextDecoder<"u"&&new TextDecoder,zn=0;try{Nn.decode(Yn,{stream:!0}),zn=1}catch{}new TextEncoder,Uint32Array.from({length:256},(n,t)=>{let e=t;for(let s=0;s<8;s++)e=e>>>1^(e&1?3988292384:0);return e});function Tn(n){return`function update({ dt, keys, fields, state, rotation }) {
2
+ const tracks = ${JSON.stringify(n)};
3
+ const held = (...codes) => codes.some(code => keys.includes(code));
4
+ const throttle = Number(held('KeyW', 'ArrowUp')) - Number(held('KeyS', 'ArrowDown'));
5
+ const direction = Number(held('KeyA', 'ArrowLeft')) - Number(held('KeyD', 'ArrowRight'));
6
+ const target = throttle * (throttle < 0 ? fields.reverseSpeed : fields.forwardSpeed);
7
+ const oldSpeed = state.speed ?? 0;
8
+ const speed = oldSpeed + (target - oldSpeed) * (1 - Math.exp(-fields.response * dt));
9
+ const distance = (oldSpeed + speed) * .5 * dt;
10
+ const turn = direction * fields.turnRate * dt;
11
+ const radians = Math.PI / 180;
12
+ const previous = state.yaw ?? 0;
13
+ const heading = (rotation[1] + previous + turn * .5) * radians;
14
+ const yaw = (previous + turn) % 360;
15
+ const x = (state.x ?? 0) - Math.sin(heading) * distance;
16
+ const z = (state.z ?? 0) - Math.cos(heading) * distance;
17
+ const travel = tracks.map((track, i) => (state.travel?.[i] ?? 0) + distance + turn * radians * track[1]);
18
+ return { translation: [x, 0, z], rotation: [0, yaw, 0],
19
+ childTrackTravel: Object.fromEntries(tracks.map((track, i) => [track[0], travel[i]])),
20
+ state: { speed, yaw, x, z, travel } };
21
+ }`}Tn([]);const On=(n,t,e="number")=>({type:e,minimum:n,maximum:t}),Ct=(...n)=>({...On(...n),type:"array"});Ct(-1e4,1e4),Ct(-360,360),Ct(.01,100),Ct(-100,100),Ct(-720,720),Ct(-100,100),Ct(-360,360);function jn(n){const{width:t,height:e}=Ht(n);if(n[24]!==16||n[25]!==0||n[26]||n[27]||n[28])throw new Error("Depth maps must be non-interlaced 16-bit grayscale PNGs.");const s=new DataView(n.buffer,n.byteOffset,n.byteLength),o=[];let c=0;for(let C=8;C+12<=n.length;){const p=s.getUint32(C),B=s.getUint32(C+4),d=C+12+p;if(d>n.length)throw new Error("Truncated depth PNG.");if(B===1229209940&&(o.push(n.subarray(C+8,C+8+p)),c+=p),B===1229278788)break;C=d}if(!c)throw new Error("Depth PNG is missing image data.");const l=new Uint8Array(c);let a=0;for(const C of o)l.set(C,a),a+=C.length;const i=t*2,g=(i+1)*e,f=Sn(l,{out:new Uint8Array(g+1)});if(f.length!==g)throw new Error("Invalid depth PNG scanline length.");const r=new Uint16Array(t*e);let h=new Uint8Array(i),u=new Uint8Array(i);for(let C=0;C<e;C++){const p=C*(i+1),B=f[p];if(B>4)throw new Error("Invalid depth PNG filter.");for(let d=0;d<i;d++){const A=d>=2?h[d-2]:0,w=u[d],m=d>=2?u[d-2]:0;let Q=0;switch(B){case 1:Q=A;break;case 2:Q=w;break;case 3:Q=A+w>>1;break;case 4:{const M=A+w-m,x=Math.abs(M-A),y=Math.abs(M-w),I=Math.abs(M-m);Q=x<=y&&x<=I?A:y<=I?w:m;break}}h[d]=f[p+1+d]+Q}for(let d=0;d<t;d++)r[C*t+d]=h[d*2]*256+h[d*2+1];[h,u]=[u,h]}return{width:t,height:e,data:r}}function an(n,t,e){return t+(e-t)*(65535-n)/65534}function cn(n,t,e){const[s,o,c,l]=t.rect,a=new Float32Array(n.positions.length),i=n.positions,g=(u,C)=>i[u]*C[0]+i[u+1]*C[1]+i[u+2]*C[2],f=t.origin.reduce((u,C,p)=>u+C*t.forward[p],0);for(let u=0;u<i.length;u+=3)a[u]=t.anchor[0]-s+g(u,t.right)*e,a[u+1]=t.anchor[1]-o-g(u,t.up)*e,a[u+2]=g(u,t.forward)-f;const r=new Float32Array(c*l).fill(1/0),h=n.indices;for(let u=0;u<h.length;u+=3){const C=h[u]*3,p=h[u+1]*3,B=h[u+2]*3,d=a[C],A=a[C+1],w=a[p],m=a[p+1],Q=a[B],M=a[B+1],x=(w-d)*(M-A)-(m-A)*(Q-d);if(Math.abs(x)<1e-8)continue;const y=Math.max(0,Math.ceil(Math.min(d,w,Q)-.5)),I=Math.min(c-1,Math.floor(Math.max(d,w,Q)-.5)),U=Math.max(0,Math.ceil(Math.min(A,m,M)-.5)),F=Math.min(l-1,Math.floor(Math.max(A,m,M)-.5));for(let v=U;v<=F;v++)for(let b=y;b<=I;b++){const D=b+.5,H=v+.5,k=((w-D)*(M-H)-(m-H)*(Q-D))/x,G=((Q-D)*(A-H)-(M-H)*(d-D))/x,N=1-k-G;if(Math.min(k,G,N)<-1e-6)continue;const J=k*a[C+2]+G*a[p+2]+N*a[B+2],j=v*c+b;J>=t.near&&J<=t.far&&J<r[j]&&(r[j]=J)}}return r}function Rn(n,t,e,s){let o=0,c=0,l=0,a=0;const i=Object.entries(s.views).map(([g,f])=>{const r=cn(n,f,s.pixelsPerUnit),h=cn(t,f,s.pixelsPerUnit),[u,C,p,B]=f.rect;let d=0,A=0,w=0,m=0;for(let Q=0;Q<B;Q++)for(let M=0;M<p;M++){const x=e.data[(Q+C)*e.width+M+u];if(!x)continue;d++;const y=Q*p+M;if(!Number.isFinite(r[y])||!Number.isFinite(h[y]))continue;const I=an(x,f.near,f.far);w+=Math.abs(r[y]-I),m+=Math.abs(h[y]-I),A++}return l+=w,a+=m,o+=d,c+=A,{view:g,sharedPixels:A,referencePixels:d,baselineMae:A?w/A:null,carvedMae:A?m/A:null}});return{referencePixels:o,sharedPixels:c,byView:i,baselineMae:c?l/c:null,carvedMae:c?a/c:null}}const Vn=["top","left","front","rear"],ut=(n,t,e,s)=>n*s[0]+t*s[1]+e*s[2],Gt=n=>Math.max(0,Math.min(255,Math.round(127.5*(1+n))));function qn({calibration:n,depth:t,clay:e,baseColor:s,normal:o},c={}){const{size:l,pixelsPerUnit:a,views:i}=n,[g,f]=n.dimensions;if(![t,e,s,o].every(E=>E.width===g&&E.height===f)||!l.every(E=>Number.isFinite(E)&&E>0)||!Number.isFinite(a)||a<=0)throw new Error("Material passes must match the calibrated atlas dimensions.");const[r,h,u]=l,{width:C,depth:p,layers:B}=Tt(r,h,c.resolution??144,c.layers??zt),d=Math.max(r/C,h/p,u/B)*.75+1/a,A=[0,0,c.pivot==="center"?u/2:0],w=Vn.map(E=>i[E]),m=w.map(E=>ut(...E.origin,E.forward)),Q=w.length,M=[...w,i.left],x=g+i.left.rect[2]+1,y=new Uint8Array(x*f*4),I=new Uint8Array(y.length);for(let E=0;E<y.length;E+=4)y.set([146,149,154,255],E);function U(E,L,P,K){const Y=E.anchor[0]+ut(L,P,K,E.right)*a,O=E.anchor[1]-ut(L,P,K,E.up)*a,[q,X,T,W]=E.rect;return Y<q||Y>=q+T||O<X||O>=X+W?-1:Math.floor(O)*g+Math.floor(Y)}function F(E,L){return an(t.data[L],E.near,E.far)}function v(E,L){const[P,K,Y,O]=E.rect;for(let q=K;q<K+O;q++)for(let X=P;X<P+Y;X++){const T=(q*g+X)*4;if(s.data[T+3]<128)continue;const W=(q*x+(L?g+X-P:X))*4;if(y.set(s.data.subarray(T,T+4),W),o.data[T+3]<128)continue;const st=o.data[T]/127.5-1,Z=o.data[T+1]/127.5-1,nt=o.data[T+2]/127.5-1,tt=E.right.map((at,dt)=>st*at+Z*E.up[dt]-nt*E.forward[dt]),et=Math.hypot(...tt)||1;I.set([Gt(tt[0]*(L?-1:1)/et),Gt(tt[1]/et),Gt(tt[2]/et),255],W)}}for(const E of w)v(E,!1);v(i.left,!0);const b=new Uint8Array(C*p*B),D=new Uint8Array(b.length);for(let E=0;E<B;E++)for(let L=0;L<p;L++)for(let P=0;P<C;P++){const K=((P+.5)/C-.5)*r,Y=(E+.5)/B*u,O=(.5-(L+.5)/p)*h;let q=!0,X=!0;for(const[T,W]of w.entries()){const st=U(W,K,Y,O);if(st<0||e.data[st*4+3]<128){q=!1;break}const Z=ut(K,Y,O,W.forward)-m[T];(!t.data[st]||Z+d<F(W,st))&&(X=!1)}if(q){const T=(E*p+L)*C+P;D[T]=1,X&&(b[T]=1)}}function H(E){const L=Ft(E,C,p,B);if(!L.indices.length)throw new Error("The calibrated views have no common surface.");const P=new Float32Array(L.positions.length),K=new Float32Array(L.positions.length);for(let Y=0;Y<P.length;Y+=3){P.set([(L.positions[Y]/C-.5)*r,L.positions[Y+2]/B*u,(.5-L.positions[Y+1]/p)*h],Y);const O=L.gradients[Y]*C/r,q=L.gradients[Y+2]*B/u,X=-L.gradients[Y+1]*p/h,T=Math.hypot(O,q,X)||1;K.set([O/T,q/T,X/T],Y)}return{positions:P,normals:K,indices:L.indices}}const k=H(D),G=H(b),N=Rn(k,G,t,n),{positions:J,normals:j}=G,_=new Map,S=[],$=[],lt=[],ft=[];for(let E=0;E<G.indices.length;E+=3){const L=G.indices.slice(E,E+3),P=(Z,nt)=>(Z[L[0]*3+nt]+Z[L[1]*3+nt]+Z[L[2]*3+nt])/3,K=P(J,0),Y=P(J,1),O=P(J,2),q=P(j,0),X=P(j,1),T=P(j,2);let W=-1,st=0;for(const[Z,nt]of M.entries()){const tt=Z===Q?-1:1,et=-ut(q*tt,X,T,nt.forward);if(et<=.04)continue;const at=U(nt,K*tt,Y,O);if(at<0||!t.data[at])continue;const dt=F(nt,at),Et=ut(K*tt,Y,O,nt.forward)-m[tt===-1?1:Z],At=Math.abs(Et-dt)/d;if(At>3.5)continue;const pt=et/(1+At*At);pt>st&&(W=Z,st=pt)}for(const Z of L){const nt=Z*(M.length+1)+W+1;let tt=_.get(nt);if(tt===void 0){tt=S.length/3,_.set(nt,tt);const et=Z*3,at=J[et],dt=J[et+1],Et=J[et+2];S.push(at,dt-A[2],Et),$.push(j[et],j[et+1],j[et+2]);const At=M[W];if(!At)lt.push((x-.5)/x,.5/f);else{const pt=W===Q,Xn=At.anchor[0]+a*ut(pt?-at:at,dt,Et,At.right),_n=At.anchor[1]-a*ut(pt?-at:at,dt,Et,At.up);lt.push((Xn+(pt?g-At.rect[0]:0))/x,_n/f)}}ft.push(tt)}}const R={target:"mesh",size:l,pivot:A,positions:Float32Array.from(S),normals:Float32Array.from($),uvs:Float32Array.from(lt),indices:Uint32Array.from(ft),texture:{width:x,height:f,data:y}},V={target:"mesh",size:l,pivot:A,positions:k.positions.map((E,L)=>L%3===1?E-A[2]:E),normals:k.normals,indices:Uint32Array.from(k.indices),uvs:new Float32Array(k.positions.length/3*2),texture:{width:1,height:1,data:Uint8Array.of(255,255,255,255)}};return{mesh:R,silhouetteMesh:V,fit:N,normalMap:{width:x,height:f,data:I},grid:[C,p,B]}}async function It(n,t=!1,e){const s=new Uint8Array(await n.slice(0,33).arrayBuffer());Ht(s);const o=await createImageBitmap(n,{colorSpaceConversion:t?"none":"default"});try{const c=new OffscreenCanvas(o.width,o.height),l=c.getContext("2d",{willReadFrequently:!0});if(!l)throw new Error("Could not decode the PNG.");l.drawImage(o,0,0);const a=l.getImageData(0,0,c.width,c.height);return{width:c.width,height:c.height,data:new Uint8Array(a.data.buffer)}}finally{o.close()}}function yt(n){return[n.positions,n.normals,n.indices,n.uvs,n.texture.data].map(t=>t.buffer)}self.onmessage=async({data:n})=>{try{const t=i=>({...i,name:"",mounts:[{name:"",position:[0,0,0]}]}),e="parts"in n?n.parts:[t(n)],s=[];async function o({file:i,layout:g,settings:f,name:r,mounts:h,maps:u}){const C=hn(await It(i),bt(g),f.threshold),p=En(C,f),B=ln(Nt(C,f.threshold));s.push(...B.warnings.map(A=>r?r+" · "+A:A));let d;if(u){const[A,w,m,Q]=await Promise.all([It(u.clay),u.depth.arrayBuffer(),It(u.baseColor),It(u.normal,!0)]);d=qn({calibration:u.calibration,clay:A,depth:jn(new Uint8Array(w)),baseColor:m,normal:Q},f)}return{...p,name:r,mounts:h,mapped:d}}const c=[];for(const i of e)c.push(await o(i));const a=c.flatMap(i=>[i.voxel,i.marching,...i.meshes]).flatMap(i=>i.frontAccents?[...yt(i),...yt(i.frontAccents)]:yt(i));for(const i of c)a.push(i.stack.texture.data.buffer),i.mapped&&a.push(...yt(i.mapped.mesh),...yt(i.mapped.silhouetteMesh),i.mapped.normalMap.data.buffer);self.postMessage({parts:c,warnings:s},a)}catch(t){self.postMessage({error:t instanceof Error?t.message:String(t)})}}})();
@@ -0,0 +1 @@
1
+ import{G as q,s as G}from"./style-D6eZHs3D.js";const H=128;function Q(e,n){return n.flatMap((l,i)=>l.mounts.map(w=>({...w,asset:e[i]})))}function V(e){const n=new q;for(const{asset:l,name:i,position:[w,c,f],scale:m=1,mirrorX:p,mirrorY:h}of e){const u=G(l);u.name=i,u.position.set(w,f,-c),u.scale.set(p?-m:m,m,h?-m:m),n.add(u)}return n}function K(e){if(e.length===0||e.some(({asset:r})=>r.target!=="stack"))throw new Error("A stack assembly needs reconstructed stack parts.");const n=e,l=n.map(({asset:r,position:[t,y,B],scale:R=1})=>{const[U,L,v]=r.size.map(s=>s*R),d=B-r.pivot[2]*R;return{min:[t-U/2,y-L/2,d],max:[t+U/2,y+L/2,d+v]}}),i=[0,1,2].map(r=>Math.min(...l.map(({min:t})=>t[r]))),c=[0,1,2].map(r=>Math.max(...l.map(({max:t})=>t[r]))).map((r,t)=>r-i[t]),f=Math.max(...n.map(({asset:r,scale:t=1})=>Math.max(r.width/r.size[0],r.depth/r.size[1])/t)),m=Math.max(1,Math.round(c[0]*f)),p=Math.max(1,Math.round(c[1]*f)),h=Math.min(...n.map(({asset:r,scale:t=1})=>r.spacing*t)),u=Math.max(1,Math.ceil(c[2]/h)),g=[c[0]/m,c[1]/p,c[2]/u],M=Math.min(u,Math.max(1,Math.floor(4096/m))),A=m*M,T=p*Math.ceil(u/M),C=new Uint8Array(4*A*T);for(const[r,{asset:t,mirrorX:y,mirrorY:B}]of n.entries()){const{min:R,max:U}=l[r],L=R.map((s,o)=>Math.ceil((s-i[o])/g[o]-.5)),v=U.map((s,o)=>Math.ceil((s-i[o])/g[o]-.5)),d=(s,o,k)=>Math.max(0,Math.min(k-1,Math.floor((i[o]+(s+.5)*g[o]-R[o])*k/(U[o]-R[o]))));for(let s=L[2];s<v[2];s++)for(let o=L[1];o<v[1];o++){const k=d(s,2,t.layers),D=d(o,1,t.depth),P=(Math.floor(k/t.columns)*t.depth+(B?t.depth-1-D:D))*t.texture.width,Y=(Math.floor(s/M)*p+o)*A;for(let b=L[0];b<v[0];b++){const F=d(b,0,t.width),X=4*(P+k%t.columns*t.width+(y?t.width-1-F:F));if(t.texture.data[X+3]<128)continue;const j=4*(Y+s%M*m+b);for(let x=0;x<4;x++)C[j+x]=t.texture.data[X+x]}}}return{target:"stack",width:m,depth:p,layers:u,columns:M,spacing:g[2],size:c,pivot:[0,0,-i[2]],texture:{width:A,height:T,data:C}}}const z={cone:new URL(""+new URL("traffic-cone-4view-DG-TkITx.png",import.meta.url).href,import.meta.url),rover:new URL(""+new URL("fillet-rover-body-4-view-Chk8Mx4R.png",import.meta.url).href,import.meta.url),inspection:new URL(""+new URL("inspection-robot-body-4-view-CLMaHFYm.png",import.meta.url).href,import.meta.url),ant:new URL(""+new URL("ant-mech-body-4view-D9xVPpbc.png",import.meta.url).href,import.meta.url),tank:new URL(""+new URL("tank-hull-4view-B4sMMkP5.png",import.meta.url).href,import.meta.url),sign:new URL(""+new URL("wet-floor-sign-4view-CWJDyeTX.png",import.meta.url).href,import.meta.url),barrier:new URL(""+new URL("plastic-barrier-4view-DQkTBW_i.png",import.meta.url).href,import.meta.url),concrete:new URL(""+new URL("concrete-barrier-4view-7PsO3Ftq.png",import.meta.url).href,import.meta.url)},Z={standard:{layers:H,resolution:96},draft:{layers:24,resolution:72},balanced:{layers:48,resolution:96},detail:{layers:90,resolution:144}},W=new URL(""+new URL("fillet-rover-wheel-4-view-B-F8flOC.png",import.meta.url).href,import.meta.url),_=new URL(""+new URL("inspection-robot-wheel-4-view-27wRsxcs.png",import.meta.url).href,import.meta.url),E=new URL(""+new URL("ant-mech-center-leg-4view-BcphjF_G.png",import.meta.url).href,import.meta.url),I=new URL(""+new URL("ant-mech-angled-leg-4view-BO2qt1_k.png",import.meta.url).href,import.meta.url),S=new URL(""+new URL("tank-turret-4view-Cx0FuNFu.png",import.meta.url).href,import.meta.url),J=new URL(""+new URL("tank-track-4view-DAIiMTy3.png",import.meta.url).href,import.meta.url),a=(e,n,l,i)=>[e/i,n/i,l/i];function O(e,n,l,i,w,c,f,m){const p=l[2];return[{name:"Body",url:e,size:a(...l,p),mounts:[{name:"Body",position:a(0,0,w,p)}]},{name:"Wheel",url:n,size:a(...i,p),mounts:[-1,1].flatMap(h=>[c,f].map((u,g)=>({name:(h<0?"Left ":"Right ")+(g?"rear wheel":"front wheel"),position:a(h*m,u,0,p),mirrorX:h<0})))}]}const $={rover:O(z.rover,W,[80,188,90],[20,44,44],13,48.5,-56.5,36.5),inspection:O(z.inspection,_,[92,194,150],[30,74,74],14,45,-63,46.5),ant:[{name:"Body",url:z.ant,size:a(50,114,56,56),mounts:[{name:"Body",position:a(0,0,26,56)}]},{name:"Center leg",url:E,size:a(23,17,41,56),mounts:[-1,1].map(e=>({name:e<0?"Left center leg":"Right center leg",position:a(e*27,0,0,56),mirrorX:e<0}))},{name:"Angled leg",url:I,size:a(23,30,41,56),mounts:[-1,1].flatMap(e=>[-1,1].map(n=>({name:(e<0?"Left ":"Right ")+(n<0?"rear leg":"front leg"),position:a(e*27,n*42,0,56),mirrorX:e<0,mirrorY:n<0})))}],tank:[{name:"Hull",url:z.tank,size:a(86,166,49,49),mounts:[{name:"Hull",position:a(0,0,13,49)}]},{name:"Turret",url:S,size:a(60,120,33,49),mounts:[{name:"Turret",position:a(0,15,60,49)}]},{name:"Track",url:J,size:a(23,163,34,49),mounts:[-1,1].map(e=>({name:e<0?"Left track":"Right track",position:a(e*45,0,0,49),mirrorX:e<0}))}]};export{H as D,K as b,V as c,Q as i,$ as m,Z as q,z as s};
@@ -0,0 +1 @@
1
+ import{aA as he,V as P,aB as Q,aC as G,Q as Yt,ax as Nt,E as N,aD as re,aE as le,b as ce,aF as It,aG as Ft,M as ue,aH as de,a6 as pe,aI as me,g as fe,al as _e,au as zt,ar as ge}from"./style-D6eZHs3D.js";const ye="modulepreload",be=function(o,t){return new URL(o,t).href},Xt={},Xe=function(t,e,s){let i=Promise.resolve();if(e&&e.length>0){let u=function(h){return Promise.all(h.map(f=>Promise.resolve(f).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};const n=document.getElementsByTagName("link"),l=document.querySelector("meta[property=csp-nonce]"),r=l?.nonce||l?.getAttribute("nonce");i=u(e.map(h=>{if(h=be(h,s),h in Xt)return;Xt[h]=!0;const f=h.endsWith(".css"),p=f?'[rel="stylesheet"]':"";if(s)for(let y=n.length-1;y>=0;y--){const b=n[y];if(b.href===h&&(!f||b.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${h}"]${p}`))return;const g=document.createElement("link");if(g.rel=f?"stylesheet":ye,f||(g.as="script"),g.crossOrigin="",g.href=h,r&&g.setAttribute("nonce",r),document.head.appendChild(g),f)return new Promise((y,b)=>{g.addEventListener("load",y),g.addEventListener("error",()=>b(new Error(`Unable to preload CSS for ${h}`)))})}))}function a(n){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=n,window.dispatchEvent(l),!l.defaultPrevented)throw n}return i.then(n=>{for(const l of n||[])l.status==="rejected"&&a(l.reason);return t().catch(a)})},Ut={type:"change"},Pt={type:"start"},Vt={type:"end"},ct=new re,Zt=new le,Me=Math.cos(70*ce.DEG2RAD),S=new P,C=2*Math.PI,w={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},Mt=1e-6;class Ue extends he{constructor(t,e=null){super(t,e),this.state=w.NONE,this.target=new P,this.cursor=new P,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:Q.ROTATE,MIDDLE:Q.DOLLY,RIGHT:Q.PAN},this.touches={ONE:G.ROTATE,TWO:G.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new P,this._lastQuaternion=new Yt,this._lastTargetPosition=new P,this._quat=new Yt().setFromUnitVectors(t.up,new P(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Nt,this._sphericalDelta=new Nt,this._scale=1,this._panOffset=new P,this._rotateStart=new N,this._rotateEnd=new N,this._rotateDelta=new N,this._panStart=new N,this._panEnd=new N,this._panDelta=new N,this._dollyStart=new N,this._dollyEnd=new N,this._dollyDelta=new N,this._dollyDirection=new P,this._mouse=new N,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=xe.bind(this),this._onPointerDown=we.bind(this),this._onPointerUp=Ee.bind(this),this._onContextMenu=Oe.bind(this),this._onMouseWheel=De.bind(this),this._onKeyDown=Te.bind(this),this._onTouchStart=Ae.bind(this),this._onTouchMove=ve.bind(this),this._onMouseDown=Pe.bind(this),this._onMouseMove=Se.bind(this),this._interceptControlDown=Ce.bind(this),this._interceptControlUp=Re.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(t){t.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=t}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(Ut),this.update(),this.state=w.NONE}update(t=null){const e=this.object.position;S.copy(e).sub(this.target),S.applyQuaternion(this._quat),this._spherical.setFromVector3(S),this.autoRotate&&this.state===w.NONE&&this._rotateLeft(this._getAutoRotationAngle(t)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let s=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(s)&&isFinite(i)&&(s<-Math.PI?s+=C:s>Math.PI&&(s-=C),i<-Math.PI?i+=C:i>Math.PI&&(i-=C),s<=i?this._spherical.theta=Math.max(s,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(s+i)/2?Math.max(s,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let a=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const n=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),a=n!=this._spherical.radius}if(S.setFromSpherical(this._spherical),S.applyQuaternion(this._quatInverse),e.copy(this.target).add(S),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let n=null;if(this.object.isPerspectiveCamera){const l=S.length();n=this._clampDistance(l*this._scale);const r=l-n;this.object.position.addScaledVector(this._dollyDirection,r),this.object.updateMatrixWorld(),a=!!r}else if(this.object.isOrthographicCamera){const l=new P(this._mouse.x,this._mouse.y,0);l.unproject(this.object);const r=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),a=r!==this.object.zoom;const u=new P(this._mouse.x,this._mouse.y,0);u.unproject(this.object),this.object.position.sub(u).add(l),this.object.updateMatrixWorld(),n=S.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;n!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(n).add(this.object.position):(ct.origin.copy(this.object.position),ct.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(ct.direction))<Me?this.object.lookAt(this.target):(Zt.setFromNormalAndCoplanarPoint(this.object.up,this.target),ct.intersectPlane(Zt,this.target))))}else if(this.object.isOrthographicCamera){const n=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),n!==this.object.zoom&&(this.object.updateProjectionMatrix(),a=!0)}return this._scale=1,this._performCursorZoom=!1,a||this._lastPosition.distanceToSquared(this.object.position)>Mt||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Mt||this._lastTargetPosition.distanceToSquared(this.target)>Mt?(this.dispatchEvent(Ut),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(t){return t!==null?C/60*this.autoRotateSpeed*t:C/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(t*.01);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){S.setFromMatrixColumn(e,0),S.multiplyScalar(-t),this._panOffset.add(S)}_panUp(t,e){this.screenSpacePanning===!0?S.setFromMatrixColumn(e,1):(S.setFromMatrixColumn(e,0),S.crossVectors(this.object.up,S)),S.multiplyScalar(t),this._panOffset.add(S)}_pan(t,e){const s=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;S.copy(i).sub(this.target);let a=S.length();a*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*a/s.clientHeight,this.object.matrix),this._panUp(2*e*a/s.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/s.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/s.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const s=this.domElement.getBoundingClientRect(),i=t-s.left,a=e-s.top,n=s.width,l=s.height;this._mouse.x=i/n*2-1,this._mouse.y=-(a/l)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(C*this._rotateDelta.x/e.clientHeight),this._rotateUp(C*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(t){this._panEnd.set(t.clientX,t.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(C*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(-C*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(C*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(-C*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),e=!0;break}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(this._pointers.length===1)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._rotateStart.set(s,i)}}_handleTouchStartPan(t){if(this._pointers.length===1)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._panStart.set(s,i)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),s=t.pageX-e.x,i=t.pageY-e.y,a=Math.sqrt(s*s+i*i);this._dollyStart.set(0,a)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(this._pointers.length==1)this._rotateEnd.set(t.pageX,t.pageY);else{const s=this._getSecondPointerPosition(t),i=.5*(t.pageX+s.x),a=.5*(t.pageY+s.y);this._rotateEnd.set(i,a)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(C*this._rotateDelta.x/e.clientHeight),this._rotateUp(C*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(this._pointers.length===1)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._panEnd.set(s,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),s=t.pageX-e.x,i=t.pageY-e.y,a=Math.sqrt(s*s+i*i);this._dollyEnd.set(0,a),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const n=(t.pageX+e.x)*.5,l=(t.pageY+e.y)*.5;this._updateZoomParameters(n,l)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId){this._pointers.splice(e,1);return}}_isTrackingPointer(t){for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return!0;return!1}_trackPointer(t){let e=this._pointerPositions[t.pointerId];e===void 0&&(e=new N,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[e]}_customWheelEvent(t){const e=t.deltaMode,s={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(e){case 1:s.deltaY*=16;break;case 2:s.deltaY*=100;break}return t.ctrlKey&&!this._controlActive&&(s.deltaY*=10),s}}function we(o){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(o.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(o)&&(this._addPointer(o),o.pointerType==="touch"?this._onTouchStart(o):this._onMouseDown(o)))}function xe(o){this.enabled!==!1&&(o.pointerType==="touch"?this._onTouchMove(o):this._onMouseMove(o))}function Ee(o){switch(this._removePointer(o),this._pointers.length){case 0:this.domElement.releasePointerCapture(o.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Vt),this.state=w.NONE;break;case 1:const t=this._pointers[0],e=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:e.x,pageY:e.y});break}}function Pe(o){let t;switch(o.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=-1}switch(t){case Q.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(o),this.state=w.DOLLY;break;case Q.ROTATE:if(o.ctrlKey||o.metaKey||o.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(o),this.state=w.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(o),this.state=w.ROTATE}break;case Q.PAN:if(o.ctrlKey||o.metaKey||o.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(o),this.state=w.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(o),this.state=w.PAN}break;default:this.state=w.NONE}this.state!==w.NONE&&this.dispatchEvent(Pt)}function Se(o){switch(this.state){case w.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(o);break;case w.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(o);break;case w.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(o);break}}function De(o){this.enabled===!1||this.enableZoom===!1||this.state!==w.NONE||(o.preventDefault(),this.dispatchEvent(Pt),this._handleMouseWheel(this._customWheelEvent(o)),this.dispatchEvent(Vt))}function Te(o){this.enabled!==!1&&this._handleKeyDown(o)}function Ae(o){switch(this._trackPointer(o),this._pointers.length){case 1:switch(this.touches.ONE){case G.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(o),this.state=w.TOUCH_ROTATE;break;case G.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(o),this.state=w.TOUCH_PAN;break;default:this.state=w.NONE}break;case 2:switch(this.touches.TWO){case G.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(o),this.state=w.TOUCH_DOLLY_PAN;break;case G.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(o),this.state=w.TOUCH_DOLLY_ROTATE;break;default:this.state=w.NONE}break;default:this.state=w.NONE}this.state!==w.NONE&&this.dispatchEvent(Pt)}function ve(o){switch(this._trackPointer(o),this.state){case w.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(o),this.update();break;case w.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(o),this.update();break;case w.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(o),this.update();break;case w.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(o),this.update();break;default:this.state=w.NONE}}function Oe(o){this.enabled!==!1&&o.preventDefault()}function Ce(o){o.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function Re(o){o.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}const Ht=new WeakMap;function ke(o){const t=Ht.get(o);if(t)return t;const{width:e,depth:s,layers:i,texture:a,columns:n,size:l}=o,r=e*s,u=r*i,h=new Uint8Array(u),f=new Int8Array(u*3),p=new Uint8Array(u);for(let d=0;d<i;d++){const _=d%n*e,m=Math.floor(d/n)*s;for(let c=0;c<s;c++)for(let x=0;x<e;x++)h[d*r+c*e+x]=+(a.data[((m+c)*a.width+_+x)*4+3]>=128)}const g=(d,_,m,c)=>{const x=m>0?h[d-_]:0,A=m+1<c?h[d+_]:0,v=m>1?h[d-_*2]:0,k=m+2<c?h[d+_*2]:0;return 2*(x-A)+v-k};for(let d=0;d<i;d++)for(let _=0;_<s;_++)for(let m=0;m<e;m++){const c=d*r+_*e+m;if(!h[c]||m>0&&m+1<e&&_>0&&_+1<s&&d>0&&d+1<i&&h[c-1]&&h[c+1]&&h[c-e]&&h[c+e]&&h[c-r]&&h[c+r])continue;const x=g(c,1,m,e)*e/l[0],A=g(c,r,d,i)*i/l[2],v=-g(c,e,_,s)*s/l[1],k=127/(Math.hypot(x,A,v)||1);f[c*3]=Math.round(x*k),f[c*3+1]=Math.round(A*k),f[c*3+2]=Math.round(v*k)}const y=new Int32Array(6);for(let d=0;d<i;d++)for(let _=0;_<s;_++)for(let m=0;m<e;m++){const c=d*r+_*e+m,x=c*3,A=f[x],v=f[x+1],k=f[x+2];if(!(A||v||k))continue;y[0]=m>0?c-1:-1,y[1]=m+1<e?c+1:-1,y[2]=_>0?c-e:-1,y[3]=_+1<s?c+e:-1,y[4]=d>0?c-r:-1,y[5]=d+1<i?c+r:-1;let D=0,L=0;for(const B of y){if(B<0)continue;const K=B*3,M=(A*f[K]+v*f[K+1]+k*f[K+2])/16129;M<.18||(D+=Math.max(0,1-M),L++)}p[c]=L?Math.min(255,Math.round(D/L*680)):0}const b={normals:f,variance:p};return Ht.set(o,b),b}const Kt=new P(.45,.7,.5).normalize();function je(o,t,e){const s=Math.min(1,o**4+e),i=t*t*(s-1)+1;return Math.min(2.4/(1+4*e),s/(i*i)*.63)}class Le{normalMatrix=new It;worldMatrix=new It;half=new P;n=new P;tangent=new P;bitangent=new P;uEdge=new P;vEdge=new P;normal=new P;normals=new Float32Array(0);variance=0;detail=!1;specularAA=!1;minX=0;minY=0;maxX=0;maxY=0;slice;camera(t){t.getWorldDirection(this.half).negate().add(Kt).normalize()}mesh(t,e,s,i,a){this.detail=!!a.detailNormals,this.specularAA=!!a.specularAA;const n=Ft(t);this.slice=n?{width:n.stack.width,row:n.layer*n.stack.depth,roll:n.roll,spacing:t.parent?.scale.y??1,lighting:ke(n.roll?.source??n.stack)}:void 0,this.normals.length<e.count*3&&(this.normals=new Float32Array(e.count*3)),this.normalMatrix.getNormalMatrix(t.matrixWorld),this.worldMatrix.setFromMatrix4(t.matrixWorld);for(let u=0;u<e.count;u++)this.n.fromBufferAttribute(e,u).applyNormalMatrix(this.normalMatrix).toArray(this.normals,u*3);this.minX=Math.max(0,Math.round(s.offset.x*i.width-.5)),this.maxX=Math.min(i.width-1,Math.round((s.offset.x+s.repeat.x)*i.width-.5));const l=s.offset.y,r=l+s.repeat.y;this.minY=Math.max(0,Math.round((s.flipY?1-r:l)*i.height-.5)),this.maxY=Math.min(i.height-1,Math.round((s.flipY?1-l:r)*i.height-.5))}triangle(t,e,s,i,a,n,l){if(this.detail){const r=e.getX(i)-e.getX(s),u=e.getY(i)-e.getY(s),h=e.getX(a)-e.getX(s),f=e.getY(a)-e.getY(s),p=r*f-h*u;this.tangent.set(0,0,0),this.bitangent.set(0,0,0),Math.abs(p)>1e-12&&(this.n.fromBufferAttribute(t,s),this.uEdge.fromBufferAttribute(t,i).sub(this.n).applyMatrix3(this.worldMatrix),this.vEdge.fromBufferAttribute(t,a).sub(this.n).applyMatrix3(this.worldMatrix),this.tangent.copy(this.uEdge).multiplyScalar(f/p).addScaledVector(this.vEdge,-u/p).normalize(),this.bitangent.copy(this.uEdge).multiplyScalar(-h/p).addScaledVector(this.vEdge,r/p).normalize().multiplyScalar(l?-1:1))}if(this.variance=0,this.specularAA&&!this.slice){const r=this.normals,u=s*3,h=i*3,f=a*3,p=(g,y)=>r[g]*r[y]+r[g+1]*r[y+1]+r[g+2]*r[y+2];this.variance=Math.min(.14,Math.max(0,3-p(u,h)-p(h,f)-p(f,u))/Math.max(3,Math.sqrt(Math.abs(n))*3))}}shade(t,e,s,i,a,n,l,r,u,h,f){const p=a*3,g=n*3,y=l*3,b=this.normals,d=this.normal.set(b[p]*r+b[g]*u+b[y]*h,b[p+1]*r+b[g+1]*u+b[y+1]*h,b[p+2]*r+b[g+2]*u+b[y+2]*h).normalize();f&&d.negate();const _=(t[0]*.2126+t[1]*.7152+t[2]*.0722)/255;let m=this.variance;if(this.detail||this.slice){const D=Math.min(this.maxX,Math.max(this.minX,Math.floor(s*e.width))),L=Math.min(this.maxY,Math.max(this.minY,Math.floor(i*e.height)));if(this.slice){const{row:B,width:K,roll:M,spacing:T,lighting:E}=this.slice,I=B+L-this.minY,j=M?M.rows[I]:I;if(j>=0){const O=j*K+D-this.minX,R=E.normals[O*3],Y=E.normals[O*3+1],U=E.normals[O*3+2];(R||Y||U)&&(d.set(R,Y,U),M&&d.set(R,Y*M.cos-U*M.sin*T,Y*M.sin/T+U*M.cos),d.applyNormalMatrix(this.normalMatrix)),this.specularAA&&(m=E.variance[O]/255*.24)}}this.detail&&(m=this.perturb(d,e,D,L,_,m))}const c=Math.max(0,d.dot(Kt)),x=.38+.23*(1-_),A=je(x,Math.max(0,d.dot(this.half)),m)*c,v=.68+.31*c+.06*Math.max(0,d.y),k=(12+22*_)*A;for(let D=0;D<3;D++){const L=t[D]*v;t[D]=L+k*(1-L/340)}}perturb(t,e,s,i,a,n){const l=this.luma(e,s,i,a),r=this.luma(e,s-1,i,l),u=this.luma(e,s+1,i,l),h=this.luma(e,s,i-1,l),f=this.luma(e,s,i+1,l),p=.76*(u-r)+.12*(this.luma(e,s+2,i,u)-this.luma(e,s-2,i,r)),g=.76*(f-h)+.12*(this.luma(e,s,i+2,f)-this.luma(e,s,i-2,h)),y=Math.min(1.7,.38/Math.max(.001,Math.hypot(p,g)));if(this.n.copy(this.tangent).multiplyScalar(p).addScaledVector(this.bitangent,g),this.n.addScaledVector(t,-this.n.dot(t)),t.addScaledVector(this.n,-y).normalize(),!this.specularAA)return n;const b=r+u-2*l,d=h+f-2*l;return Math.min(.24,n+.45*(b*b+d*d))}luma(t,e,s,i){if(e<this.minX||e>this.maxX||s<this.minY||s>this.maxY)return i;const a=(s*t.width+e)*4,n=t.data;return n[a+3]>=128?(n[a]*.2126+n[a+1]*.7152+n[a+2]*.0722)/255:i}}const wt=(o,t,e,s,i,a)=>(e-o)*(a-t)-(s-t)*(i-o);class Ze{canvas=document.createElement("canvas");ctx=this.canvas.getContext("2d");textures=new WeakMap;transform=new ue;vertex=new de;lighting=new Le;frame;sampleColors=new Uint8ClampedArray(0);depth=new Float32Array(0);pixels(t){const e=t.image;if(!e?.width||!e.height)return;if("data"in e)return e;const s=this.textures.get(e);if(s)return s;try{const a=new OffscreenCanvas(e.width,e.height).getContext("2d");a.drawImage(e,0,0);const n=a.getImageData(0,0,e.width,e.height);return this.textures.set(e,n),n}catch{return}}render(t,e,s,i,a,n,l){const r=Math.min(1,512/Math.max(this.canvas.clientWidth,this.canvas.clientHeight,1))*(s?2:1),u=Math.max(1,Math.round(this.canvas.clientWidth*r)),h=Math.max(1,Math.round(this.canvas.clientHeight*r));(!this.frame||this.frame.width!==u||this.frame.height!==h)&&(this.canvas.width=u,this.canvas.height=h,this.frame=this.ctx.createImageData(u,h));const{data:f}=this.frame,p=l?.subpixelAA?4:1,g=u*h*p;this.depth.length!==g&&(this.depth=new Float32Array(g));const y=p===4?g*4:0;this.sampleColors.length!==y&&(this.sampleColors=new Uint8ClampedArray(y));const b=p===4?this.sampleColors:f;b.fill(0),this.depth.fill(1/0),e.updateMatrixWorld(),l&&this.lighting.camera(e),t?.updateMatrixWorld(!0);const d=[],_=e.matrixWorldInverse.elements;t?.traverseVisible(m=>{if(!(m instanceof pe)||!m.visible||Array.isArray(m.material))return;const c=m.material;if(!c.map)return;const x=m.matrixWorld.elements,A=_[2]*x[12]+_[6]*x[13]+_[10]*x[14];d.push({mesh:m,material:c,viewZ:A})}),l&&d.sort((m,c)=>c.viewZ-m.viewZ);for(const{mesh:m,material:c}of d)this.draw(m,c,e,u,h,b,n||c instanceof me,p,l);p===4&&this.resolveSubpixels(f),this.ctx.putImageData(this.frame,0,0),this.ctx.save(),this.ctx.globalCompositeOperation="destination-over",i&&t&&this.drawGrid(e,u,h,a),this.ctx.fillStyle="#121923",this.ctx.fillRect(0,0,u,h),this.ctx.restore()}resolveSubpixels(t){const e=this.sampleColors;for(let s=0,i=0;s<t.length;s+=4,i+=16){const a=e[i+3],n=e[i+7],l=e[i+11],r=e[i+15],u=a+n+l+r;if(t[s+3]=u*.25,!u){t[s]=t[s+1]=t[s+2]=0;continue}for(let h=0;h<3;h++)t[s+h]=(e[i+h]*a+e[i+4+h]*n+e[i+8+h]*l+e[i+12+h]*r)/u}}drawGrid(t,e,s,i){const a=new P,n=new P;this.ctx.strokeStyle="#29394b",this.ctx.beginPath();for(let l=-12;l<=12;l++)for(let r=0;r<2;r++){const u=l*.25;a.set(r?u:-3,i,r?-3:u).project(t),n.set(r?u:3,i,r?3:u).project(t),!(a.z<-1||a.z>1||n.z<-1||n.z>1)&&(this.ctx.moveTo((a.x+1)*e/2,(1-a.y)*s/2),this.ctx.lineTo((n.x+1)*e/2,(1-n.y)*s/2))}this.ctx.stroke()}draw(t,e,s,i,a,n,l,r,u){const h=e.map,f=this.pixels(h),p=t.geometry.getAttribute("position"),g=t.geometry.getAttribute("uv");if(!f||!p||!g)return;this.transform.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(t.matrixWorld);const y=u&&Ft(t);let b=0,d=i-1,_=0,m=a-1;if(y){if(!y.bounds)return;const[M,T,E,I]=y.bounds;let j=1/0,O=-1/0,R=1/0,Y=-1/0;for(const U of[M,E])for(const it of[T,I]){const z=this.vertex.set((U-.5)*y.stack.size[0],0,(.5-it)*y.stack.size[1],1).applyMatrix4(this.transform),Z=(1+z.x/z.w)*i*.5,H=(1-z.y/z.w)*a*.5;j=Math.min(j,Z),O=Math.max(O,Z),R=Math.min(R,H),Y=Math.max(Y,H)}if(b=Math.max(b,Math.floor(j)),d=Math.min(d,Math.ceil(O)),_=Math.max(_,Math.floor(R)),m=Math.min(m,Math.ceil(Y)),b>d||_>m)return}const c=new Float32Array(p.count*4);for(let M=0;M<p.count;M++){const T=M*4,E=this.vertex.set(p.getX(M),p.getY(M),p.getZ(M),1).applyMatrix4(this.transform);c[T]=(1+E.x/E.w)*i*.5,c[T+1]=(1-E.y/E.w)*a*.5,c[T+2]=E.z/E.w,c[T+3]=E.w>0?1/E.w:0}const x=t.geometry.getAttribute("normal"),A=!!(l&&x&&u);l&&x&&u&&this.lighting.mesh(t,x,h,f,u);const v=t.geometry.index,k=v?.count??p.count,D=new Float32Array(4),L=h.magFilter===fe,B=t.matrixWorld.determinant()<0,K=Math.max(1,e.alphaTest*255);for(let M=0;M<k;M+=3){const T=v?.getX(M)??M,E=v?.getX(M+1)??M+1,I=v?.getX(M+2)??M+2,j=T*4,O=E*4,R=I*4,Y=c[j+2],U=c[O+2],it=c[R+2];if(!c[j+3]||!c[O+3]||!c[R+3]||Math.min(Y,U,it)>1)continue;const z=c[j],Z=c[j+1],H=c[O],$=c[O+1],W=c[R],F=c[R+1],X=wt(z,Z,H,$,W,F),Dt=B?X<0:X>0;if(!X||Dt&&e.side===_e)continue;const Bt=Math.max(b,Math.floor(Math.min(z,H,W))),qt=Math.min(d,Math.ceil(Math.max(z,H,W))),Gt=Math.max(_,Math.floor(Math.min(Z,$,F))),Qt=Math.min(m,Math.ceil(Math.max(Z,$,F))),ut=l&&x&&!A?.65+.35*Math.max(0,x.getY(T)*.7+x.getZ(T)*.5+x.getX(T)*.45):1;A&&this.lighting.triangle(p,g,T,E,I,X,h.flipY);const dt=($-F)/X,pt=(W-H)/X,mt=(F-Z)/X,ft=(z-W)/X,_t=r===4?.25:0,$t=(Math.abs(dt)+Math.abs(pt))*_t,Jt=(Math.abs(mt)+Math.abs(ft))*_t,te=(Math.abs(dt+mt)+Math.abs(pt+ft))*_t,ee=g.getX(T),se=g.getX(E),ie=g.getX(I),oe=g.getY(T),ne=g.getY(E),ae=g.getY(I);for(let J=Gt;J<=Qt;J++)for(let tt=Bt;tt<=qt;tt++){const gt=wt(H,$,W,F,tt+.5,J+.5)/X,yt=wt(W,F,z,Z,tt+.5,J+.5)/X;if(gt<-$t||yt<-Jt||1-gt-yt<-te)continue;let Tt=!1,At=0,vt=0,Ot=0;for(let et=0;et<r;et++){const Ct=r===1?0:et&1?.25:-.25,Rt=r===1?0:et&2?.25:-.25,ot=gt+Ct*dt+Rt*pt,nt=yt+Ct*mt+Rt*ft,bt=1-ot-nt;if(ot<0||nt<0||bt<0)continue;const at=ot*Y+nt*U+bt*it,q=(J*i+tt)*r+et;if(at<-1||at>1||at>=this.depth[q])continue;const ht=ot*c[j+3],rt=nt*c[O+3],lt=bt*c[R+3],st=1/(ht+rt+lt),kt=(ee*ht+se*rt+ie*lt)*st*h.repeat.x+h.offset.x,jt=(oe*ht+ne*rt+ae*lt)*st*h.repeat.y+h.offset.y,Lt=h.flipY?1-jt:jt;this.sample(f,kt,Lt,L,D),!(D[3]<K)&&(Tt||(A&&this.lighting.shade(D,f,kt,Lt,T,E,I,ht*st,rt*st,lt*st,Dt),At=D[0]*ut,vt=D[1]*ut,Ot=D[2]*ut,Tt=!0),this.depth[q]=at,n[q*4]=At,n[q*4+1]=vt,n[q*4+2]=Ot,n[q*4+3]=e.alphaToCoverage?D[3]:255)}}}}sample(t,e,s,i,a){const{width:n,height:l,data:r}=t,u=Math.min(n-1,Math.max(0,e*n-.5)),h=Math.min(l-1,Math.max(0,s*l-.5));if(i){const _=(Math.round(h)*n+Math.round(u))*4;for(let m=0;m<4;m++)a[m]=r[_+m];return}const f=Math.floor(u),p=Math.floor(h),g=Math.min(n-1,f+1),y=Math.min(l-1,p+1),b=u-f,d=h-p;for(let _=0;_<4;_++)a[_]=(r[(p*n+f)*4+_]*(1-b)+r[(p*n+g)*4+_]*b)*(1-d)+(r[(y*n+f)*4+_]*(1-b)+r[(y*n+g)*4+_]*b)*d}}const Ye="stack3-preview-5",Wt=new WeakMap;let Ne=0;function xt(o){let t=Wt.get(o);return t||(t=crypto.subtle?o.arrayBuffer().then(e=>crypto.subtle.digest("SHA-256",e)).then(e=>Array.from(new Uint8Array(e),s=>s.toString(16).padStart(2,"0")).join("")):Promise.resolve("session:"+Ne++),Wt.set(o,t),t)}async function He(o){return"parts"in o?JSON.stringify(await Promise.all(o.parts.map(async t=>[zt(t.layout),t.size??null,await xt(t.atlas)]))):"atlas"in o?JSON.stringify([zt(o.layout),await xt(o.atlas)]):JSON.stringify(await Promise.all(ge.map(t=>{const e=o.files[t];return e?xt(e):null})))}const V=new Map;let Ie;function St(){return Ie??=new Promise(o=>{try{const t=indexedDB.open(Ye,1);t.onupgradeneeded=()=>t.result.createObjectStore("results",{keyPath:"key"}).createIndex("savedAt","savedAt"),t.onsuccess=()=>o(t.result),t.onerror=t.onblocked=()=>o(null)}catch{o(null)}})}function Et(o,t){V.delete(o),V.set(o,t),V.size>4&&V.delete(V.keys().next().value)}async function Ke(o,t){const e=V.get(o);if(e)return Et(o,e),{value:e,origin:"Memory cache"};if(!t||!crypto.subtle)return null;const s=await St();return s?new Promise(i=>{const a=s.transaction("results").objectStore("results").get(o);a.onsuccess=()=>{const n=a.result;n&&Et(o,n.value),i(n?{value:n.value,origin:"Disk cache"}:null)},a.onerror=()=>i(null)}).catch(()=>null):null}async function We(o,t,e){if(Et(o,t),!e||!crypto.subtle)return;const s=await St();if(s)try{const a=s.transaction("results","readwrite").objectStore("results");a.put({key:o,value:t,savedAt:Date.now()});let n=0;const l=a.index("savedAt").openKeyCursor(null,"prev");l.onsuccess=()=>{const r=l.result;r&&(++n>12&&a.delete(r.primaryKey),r.continue())}}catch{}}async function Fe(){V.clear();const o=await St();o&&await new Promise((t,e)=>{const s=o.transaction("results","readwrite");s.objectStore("results").clear(),s.oncomplete=()=>t(),s.onabort=()=>e(s.error)})}export{Ze as C,Ue as O,Xe as _,We as a,Fe as c,Ke as f,He as s};
@@ -0,0 +1,17 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./script-engine-Bs3azDYZ.js","./preview-cache-BKV0EZl9.js","./style-D6eZHs3D.js","./style-CMUT8CmM.css"])))=>i.map(i=>d[i]);
2
+ import{aJ as ze,aK as Je,aL as Ce,aM as He,aN as Me,V as ke,e as Ve,G as Le,aq as je,A as _e,r as Ze,O as Qe,ax as Te,aO as Xe,aP as $e,aQ as Ye,Q as et,aR as tt,as as Oe,s as nt,aw as ot,at as st,p as it,a6 as rt,an as at,W as ct,aS as lt,aT as dt,au as ut}from"./style-D6eZHs3D.js";import{_ as pt,O as ft,C as mt,f as ht,a as gt}from"./preview-cache-BKV0EZl9.js";function vt(t,l,d){const o=new Set(t.atlases.map(A=>A.id)),g=t.nodes.filter(A=>A.parentId===l.id&&A.atlasId&&o.has(A.atlasId)),y=g.filter(A=>/wheel|tire|tyre|바퀴|타이어/i.test(A.name+" "+A.id)),c=new Map;for(const A of g){const i=c.get(A.atlasId)??[];i.push(A),c.set(A.atlasId,i)}const p=[...c.values()].filter(A=>A.length===4&&y.every(i=>A.includes(i))),N=y.length===4?y:g.length===4?g:p.length===1?p[0]:null;if(!N)throw new Error("Cannot identify four wheels under "+l.id+". Supply --wheels <front-left,front-right,rear-left,rear-right>.");const U=[...N].sort((A,i)=>A.position[2]-i.position[2]),D=(A,i)=>A.position[0]-i.position[0];return[...U.slice(0,2).sort(D),...U.slice(2).sort(D)]}function ve(t,l,d,o){const g=(l.scripts??[]).filter(c=>c.id===d||c.name===o.name||(d==="wasd-vehicle"?Ce(c.source):c.source===o.source));if(g.length>1)throw new Error("Multiple "+o.name+" components on node "+l.id+".");const y=g[0];if(!y)return t.push({action:"script.set",nodeId:l.id,id:d,patch:o}),d;if(y.source!==o.source){if(!(d==="wasd-vehicle"&&Ce(y.source)||d==="tracked-drive"&&He(y.source)))throw new Error("Cannot replace customized "+o.name+" source on node "+l.id+".");t.push({action:"script.set",nodeId:l.id,id:y.id,patch:{source:o.source}})}return y.id}function wt(t,l,d){const o=t.nodes.find(w=>w.id===l);if(!o)throw new Error("Unknown vehicle root: "+l);const g=vt(t,o),[y,c,p,N]=g;if(Math.max(y.position[2],c.position[2])>=Math.min(p.position[2],N.position[2])||Math.max(y.position[0],p.position[0])>=Math.min(c.position[0],N.position[0]))throw new Error("Wheel positions must form two axles facing local −Z, with left wheels at smaller local X.");const U=(p.position[2]+N.position[2]-(y.position[2]+c.position[2]))/2*o.scale[2],D=g.reduce((w,h)=>{const{format:I,height:R,spacing:b}=h.settings;return w+R*h.scale[1]*(I==="stack"?b:1)/2},0)/4*o.scale[1];if(![U,D].every(w=>w>0&&w<=1e5))throw new Error("Vehicle wheelbase and radius must be positive and at most 100000 scene units.");const A=[],i=ve(A,o,"wasd-vehicle",ze(g.map(w=>w.id),U,D)),P=g.map((w,h)=>({role:["front-left","front-right","rear-left","rear-right"][h],node:w.id,component:ve(A,w,"sprite-stack-wheel",Me["sprite-stack-wheel"].script)}));return{actions:A,root:o.id,component:i,wheels:P}}function yt(t,l){const d=t.nodes.find(i=>i.id===l);if(!d)throw new Error("Unknown tank root: "+l);const o=t.nodes.filter(i=>i.parentId===d.id),g=new Map(t.atlases.map(i=>[i.id,i])),y=i=>i.atlasId?g.get(i.atlasId):void 0,c=o.filter(i=>{const P=y(i);return P&&/track|tread|트랙|궤도/i.test([i.name,i.id,P.name].join(" "))}).sort((i,P)=>i.position[0]-P.position[0]);if(c.length!==2||c[0].position[0]>=0||c[1].position[0]<=0)throw new Error("Provide two atlas-backed track children with track or tread in their names, one on each side of the root.");const p=o.filter(i=>{const P=y(i);return/turret|포탑/i.test([i.name,i.id,P?.name].join(" "))?P||t.nodes.some(w=>w.parentId===i.id&&y(w)):!1});if(p.length!==1)throw new Error("Provide one turret child or a named turret pivot with an atlas-backed child.");const N=[],U=ve(N,d,"tracked-drive",Je(c.map(i=>i.id),c.map(i=>i.position[0]*d.scale[0]))),D=ve(N,p[0],"turret-control",Me["turret-control"].script),A=c.map((i,P)=>{if(i.settings.format!=="stack")throw new Error(i.name+" must use Sprite stack to animate its belt.");return{role:P===0?"left":"right",node:i.id,component:ve(N,i,"track-belt",Me["track-belt"].script)}});return{actions:N,root:d.id,component:U,turret:{node:p[0].id,component:D},tracks:A}}const bt=[0,0,0],Se=(t,l)=>t+"/"+l;function kt(t,l){const d=t.newRuntime();d.setMemoryLimit(4*1024*1024),d.setMaxStackSize(256*1024);let o=performance.now()+30;d.setInterruptHandler(()=>performance.now()>=o);const g=d.newContext();try{const y=g.unwrapResult(g.evalCode(`(() => {
3
+ "use strict";
4
+ const parse = JSON.parse, stringify = JSON.stringify;
5
+ const callback = (() => {
6
+ ${l}
7
+ if (typeof update !== 'function') throw new Error('Define function update(input).');
8
+ return update;
9
+ })();
10
+ return json => {
11
+ const output = stringify(callback(parse(json)) ?? {});
12
+ if (!output || output.length > 16384) throw new Error('Script output must be JSON of 16 KB or less.');
13
+ return output;
14
+ };
15
+ })()`,"component.js"));return{runtime:d,context:g,update:y,limit:c=>{o=c}}}catch(y){throw g.dispose(),d.dispose(),y}}function Re(t){t&&(t.update.dispose(),t.context.dispose(),t.runtime.dispose())}function Ae(t){return Array.isArray(t)&&t.length===3&&t.every(l=>typeof l=="number"&&Number.isFinite(l)&&Math.abs(l)<=1e4)}function Et(t){if(!t||typeof t!="object")return!1;const{rollScale:l,steeringScale:d}=t;return[l,d].every(o=>Number.isFinite(o)&&Math.abs(o)<=4)}function De(t,l){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(l)}function St(t,l,d){t.limit(d);const{context:o,update:g}=t,y=o.newString(l);try{const p=o.unwrapResult(o.callFunction(g,o.undefined,y)).consume(N=>JSON.parse(o.getString(N)));if(!p||typeof p!="object"||Array.isArray(p)||p.translation!==void 0&&!Ae(p.translation)||p.rotation!==void 0&&!Ae(p.rotation)||p.stackWheel!==void 0&&!Et(p.stackWheel)||p.childRotations!==void 0&&!De(p.childRotations,Ae)||p.trackBelt!==void 0&&(!Number.isFinite(p.trackBelt)||Math.abs(p.trackBelt)>4)||p.childTrackTravel!==void 0&&!De(p.childTrackTravel,N=>typeof N=="number"&&Number.isFinite(N)&&Math.abs(N)<=1e9))throw new Error("Return valid finite transform, wheel, and track outputs.");return p}finally{y.dispose()}}function At(t){const l=new Set,d=new Map,o=new Map,g=new Map;let y,c,p;function N(i,P){const{node:w,script:h}=i;g.set(Se(w.id,h.id),P),t(w.id,h.id,P)}function U(i){const P=c&&c.play.resetCount!==i.play.resetCount;c=i;const w=new Set;for(const h of i.nodes)for(const I of h.scripts??[]){const R=Se(h.id,I.id);if(!I.enabled)continue;w.add(R);const b=d.get(R);if(!P&&b&&b.script.source===I.source){b.node=h,b.script=I;continue}Re(b?.vm);const q={node:h,script:I};d.set(R,q),N(q,"Loading script…"),y??=pt(()=>import("./script-engine-Bs3azDYZ.js"),__vite__mapDeps([0,1,2,3]),import.meta.url).then(L=>L.createScriptEngine()).catch(L=>{throw y=void 0,L}),y.then(L=>{d.get(R)===q&&(q.vm=kt(L,I.source),N(q,"Ready"))}).catch(L=>{d.get(R)===q&&(q.failed=!0,N(q,String(L).slice(0,500)))})}for(const[h,I]of d)w.has(h)||(Re(I.vm),d.delete(h),g.delete(h));(P||!d.size)&&(l.clear(),o.clear(),p=void 0)}function D(i,P,w){if(!w)return;const h=o.get(i)??{},I=h[P]??bt;h[P]=[I[0]+w[0],I[1]+w[1],I[2]+w[2]],o.set(i,h)}function A(i){const P=p===void 0?0:Math.min(.05,Math.max(0,i-p));if(p=i,!c||!d.size)return o;o.clear();const w=c.play.startedAt!==null&&P>0&&!document.hidden,h=performance.now()+8;for(const I of d.values()){const{node:R,script:b,vm:q}=I;if(!q||I.failed)continue;const L=c.nodes.filter(B=>B.parentId===R.id);if(w&&performance.now()<h)try{I.output=St(q,JSON.stringify({dt:P,time:i,keys:[...l],fields:Object.fromEntries(b.fields.map(B=>[B.name,B.value])),state:I.output?.state??{},position:R.position,rotation:R.rotation,children:L.map(({id:B,name:_,position:oe})=>({id:B,name:_,position:oe}))}),Math.min(h,performance.now()+4))}catch(B){I.failed=!0,N(I,String(B).slice(0,500))}const K=I.output;if(K){if(D(R.id,"translation",K.translation),D(R.id,"rotation",K.rotation),K.stackWheel||K.trackBelt!==void 0){const B=o.get(R.id)??{};K.stackWheel&&(B.stackWheel=K.stackWheel),K.trackBelt!==void 0&&(B.trackBelt=K.trackBelt),o.set(R.id,B)}for(const B of L)if(K.childRotations&&Object.hasOwn(K.childRotations,B.id)&&D(B.id,"wheelRotation",K.childRotations[B.id]),K.childTrackTravel&&Object.hasOwn(K.childTrackTravel,B.id)){const _=o.get(B.id)??{};_.trackTravel=(_.trackTravel??0)+K.childTrackTravel[B.id],o.set(B.id,_)}}}return o}return{sync:U,tick:A,hasScripts:()=>d.size>0,keyDown:i=>l.add(i),keyUp:i=>l.delete(i),clearKeys:()=>l.clear(),status:(i,P)=>g.get(Se(i,P))??""}}const Be=new ke;function It(t,l,d){const o=d*t.scale.y;t.position.add(Be.set(0,o,0).applyQuaternion(t.quaternion)),t.quaternion.multiply(l),t.position.sub(Be.set(0,o,0).applyQuaternion(t.quaternion))}const me=Math.PI/180;function Mt(t,l,d,o,g){const y=new Ve,c=new Le,p=o?At(g):void 0,N=new tt(0,0,0,"YXZ"),U=new et;let D=null;const A=new ke,i=new ke,P=new je(24,48,5334392,3227985);y.add(c,P,new _e(16777215,.85));const w=new Ze(16777215,1.5);w.position.set(2,3,2),y.add(w);const h=new Qe(-2,2,2,-2,.01,1e4);h.position.set(3,3,4);const I=new ft(h,t);I.enablePan=!1,I.minZoom=.1,I.maxZoom=10,I.maxPolarAngle=Math.acos(.2);const R=new mt;t.append(R.canvas);let b,q=!1,L,K,B=new Map,_=2,oe=6,e=0,n=!1,r="";const s=new Map,u=new Map,T=new Map,F=new Map,f=new Worker(new URL(""+new URL("reconstruct.worker-ONc9GyFO.js",import.meta.url).href,import.meta.url),{type:"module"});let W=Promise.resolve(),J=0;function M(){const a=t.clientWidth,S=t.clientHeight;if(!a||!S)return;const O=a/S;if(h.left=-_*Math.max(1,O),h.right=-h.left,h.bottom=-_*Math.max(1,1/O),h.top=-h.bottom,h.updateProjectionMatrix(),!b)return;const G=Math.min(window.devicePixelRatio||1,2)*(L?.view.supersampling?2:1);e!==G&&(e=G,b.setPixelRatio(G)),b.setSize(a,S,!1)}function m(){const a=L?.view.backend==="gpu"&&!q;if(a&&!b)try{b=new ct({antialias:!0}),b.setClearColor(1186083),b.domElement.addEventListener("webglcontextlost",O=>{O.preventDefault(),q=!0,m(),z()}),b.domElement.addEventListener("webglcontextrestored",()=>{q=!1,m(),z()}),t.append(b.domElement)}catch{q=!0}const S=a&&!q&&!!b;R.canvas.hidden=S,b&&(b.domElement.hidden=!S),t.dataset.backend=S?"gpu":"cpu",M()}function E(){const a=L?.view;if(!a)return;const S=Math.acos(Math.min(.99999,a.squash)),O=new ke().setFromSpherical(new Te(oe,S,a.yaw*me));h.position.copy(I.target).add(O),h.zoom=a.scale,h.updateProjectionMatrix(),I.update()}I.addEventListener("end",()=>{const a=new Te().setFromVector3(h.position.clone().sub(I.target));l({yaw:a.theta/me,squash:Math.max(.2,Math.min(1,Math.cos(a.phi))),scale:h.zoom})}),new ResizeObserver(M).observe(t);function ee(){const a=new it;if(c.updateMatrixWorld(!0),c.traverseVisible(O=>{O instanceof rt&&a.expandByObject(O)}),a.isEmpty())return;const S=a.getBoundingSphere(new at);_=Math.max(.05,S.radius)*1.12,oe=Math.max(6,_*3),I.target.copy(S.center),M(),E()}function z(){const a=L?.nodes.filter(k=>k.atlasId)??[],S=a.filter(k=>Q(k.id)).length,O=[...u.values()][0],G=S<a.length?`${S}/${a.length} assets ready`:`${S} assets ready`;d(O||(q&&L?.view.backend==="gpu"?"WebGL unavailable · CPU preview":G),S)}function Q(a){const S=s.get(a);return!!S?.content&&S.key===S.renderedKey}function j(a){const S=a.fingerprint??a.id;let O=T.get(S);if(!O){const G=t.dataset.endpoint+"/atlas/"+a.id+(a.fingerprint?"?fingerprint="+a.fingerprint:"");O=fetch(G).then(k=>{if(!k.ok)throw new Error("Could not read the embedded atlas.");return k.blob()}).catch(k=>{throw T.delete(S),k}),T.set(S,O)}return O}function de(a,S,O,G){const k=F.get(a);if(k)return k;const v=W.then(async()=>{const x=await ht(a,!0);if(x)return x.value;const H={atlas:await j(S),layout:S.layout},te=++J,V=await new Promise((re,ae)=>{f.onmessage=({data:ne})=>{ne.id===te&&("error"in ne?ae(new Error(ne.error)):ne.preview||re(ne))},f.onerror=()=>ae(new Error("Failed to run the reconstruction worker.")),f.postMessage({id:te,sourceKey:"project:"+(S.fingerprint??S.id),source:H,target:G,settings:O,keepTop:G==="stack"})});return gt(a,V,!0),V});return F.set(a,v),W=v.then(()=>{},()=>{}),v.then(()=>F.delete(a),()=>F.delete(a)),v}function fe(a,S){if(!a.content)return;const{spacing:O,pixelArt:G,smoothEdges:k,lighting:v,format:x}=S.settings,H=JSON.stringify([O,G,k,v,x]);a.display!==H&&(a.display=H,a.content.scale.y=x==="stack"?O:1,ot(a.content,v),x==="stack"&&st(a.content,G,k))}function Ee(a,S){a.content&&(a.group.remove(a.content),Oe(a.content)),a.content=S,a.display=void 0,a.group.add(S)}function Ue(a){const S=!L||a.view.backend!==L.view.backend||a.view.supersampling!==L.view.supersampling;n||=!L||a.view.frame!==L.view.frame,L=a,p?.sync(a),K=void 0,B=new Map(a.play.offsets?.map(k=>[k.id,k]));const O=new Map(a.nodes.map(k=>[k.id,k]));for(const[k,v]of s)O.has(k)||(v.group.removeFromParent(),v.content&&Oe(v.content),u.delete(k),s.delete(k));for(const k of a.nodes)s.has(k.id)||s.set(k.id,{group:new Le});for(const k of a.nodes){const v=s.get(k.id),x=k.parentId?s.get(k.parentId)?.group??c:c;v.group.parent!==x&&x.add(v.group),v.group.name=k.name,v.group.visible=k.visible,v.group.scale.set(...k.scale);const H=a.atlases.find($=>$.id===k.atlasId);if(!H)continue;const{format:te,layers:V,resolution:re,threshold:ae,height:ne,pivot:he,profile:ue}=k.settings,X={layers:V,resolution:re,threshold:ae,height:ne,pivot:he,profile:ue,textureProjection:k.settings.textureProjection,meshMethod:k.settings.meshMethod,contourHub:k.settings.contourHub},ce=JSON.stringify(["project-v2",H.fingerprint??H.id,H.layout,te,X]);fe(v,k),v.key!==ce&&(v.key=ce,u.delete(k.id),de(ce,H,X,te==="glb"?"mesh":"stack").then(({result:$,top:we})=>{if(s.get(k.id)!==v||v.key!==ce)return;v.asset=$,v.top=we,v.rolling=void 0,v.belt=void 0,Ee(v,nt($)),v.centerY=$.size[2]*.5-$.pivot[2],v.renderedKey=ce;const xe=L?.nodes.find(Ge=>Ge.id===k.id);xe&&fe(v,xe),n||=!c.userData.framed,z()}).catch($=>{s.get(k.id)!==v||v.key!==ce||(u.set(k.id,k.name+" · "+$.message),z())}))}S&&m();const G=JSON.stringify([a.view.yaw,a.view.squash,a.view.scale]);G!==r&&(r=G,E()),P.visible=a.view.grid,z()}const We=document.getElementById("playTime");function qe(a,S){const O={id:a,patch:S};return K=O,()=>{K===O&&(K=void 0)}}let Ne="";function Pe(){if(requestAnimationFrame(Pe),!L)return;const a=Xe(L.play),S=p?.tick(a),O=a.toFixed(1)+" s";O!==Ne&&(We.value=O,Ne=O);for(const v of L.nodes){const x=s.get(v.id),{group:H}=x,te=B.get(v.id),V=S?.get(v.id),re=V?.stackWheel,ae=V?.trackBelt;if(x.asset?.target==="stack"&&(ae!==void 0&&x.top?x.belt||(x.belt=$e(x.asset,x.top),x.rolling=void 0,Ee(x,x.belt.object),fe(x,v)):re&&!x.rolling&&(x.rolling=Ye(x.asset),x.belt=void 0,Ee(x,x.rolling.object),fe(x,v)),x.belt)){const ue=ae!==void 0&&V?.trackTravel!==void 0?ae*V.trackTravel:void 0,X=H.parent?.scale;x.belt.setTravel(ue,x.asset.size[1]*v.scale[2]*(X?.z??1),x.asset.size[2]*v.settings.spacing*v.scale[1]*(X?.y??1))}const ne=K?.id===v.id?K.patch:void 0,he=ne?.position??v.position;if(H.position.set(he[0]+a*v.velocity[0]+(te?.translation[0]??0)+(V?.translation?.[0]??0),he[1]+a*v.velocity[1]+(te?.translation[1]??0)+(V?.translation?.[1]??0),he[2]+a*v.velocity[2]+(te?.translation[2]??0)+(V?.translation?.[2]??0)),H.rotation.set(...(ne?.rotation??v.rotation).map((ue,X)=>(ue+a*v.angularVelocity[X]+(te?.rotation[X]??0)+(V?.rotation?.[X]??0))*me)),V?.wheelRotation){const[ue,X,ce]=V.wheelRotation,$=ue*(re?.rollScale??1),we=!!(re&&x.rolling);x.rolling?.setRoll(we?$:0,v.settings.spacing),U.setFromEuler(N.set(we?0:$*me,X*(re?.steeringScale??1)*me,ce*me)),It(H,U,(x.centerY??0)*(x.content?.scale.y??1))}else x.rolling?.setRoll(0,v.settings.spacing)}const G=o?L.view.follow??null:null,k=G&&s.get(G)?.group;k&&(k.getWorldPosition(i),G===D?(i.sub(A),I.target.add(i),h.position.add(i),A.add(i)):A.copy(i)),D=G,n&&L.nodes.every(v=>!v.atlasId||Q(v.id)||u.has(v.id))&&(ee(),n=!1,c.userData.framed=!0),t.dataset.backend==="gpu"?b?.render(y,h):R.render(c,h,L.view.supersampling,L.view.grid,0,!1,L.view)}return requestAnimationFrame(Pe),{sync:Ue,previewTransform:qe,scripts:p}}function C(t){return document.getElementById(t)}const Ke=new URLSearchParams(location.search),Ie=Ke.get("session"),pe=Ke.get("playground")==="1";Ie&&/^[a-f0-9-]{36}$/.test(Ie)?Nt(Ie):(pe&&C("openInstruction").append(" --playground"),C("disconnected").hidden=!1);function Nt(t){const l=new URL("./__stack3_project/"+t,location.href).pathname,d=C("viewport");d.dataset.endpoint=l;const o=C("status"),g=C("editorMode"),y=C("playMode");C("compareMode").href="./compare.html?session="+t,g.href="./project.html?session="+t,y.href=g.href+"&playground=1",g.hidden=y.hidden=!1,(pe?y:g).setAttribute("aria-current","page"),C("workspace").hidden=!1,C("stageTitle").textContent=pe?"Playground":"Scene",o.value="Connecting…";let c,p="",N="",U="",D,A=Promise.resolve();const i=Mt(d,e=>b([{action:"view.set",patch:e}]),(e,n)=>{C("buildStatus").value=e,d.dataset.readyCount=String(n)},pe,(e,n,r)=>{const s=document.getElementById(Fe(e,n));s&&(s.textContent=r)}),P=[C("objectTab"),C("renderingTab")];function w(e){for(const[r,s]of P.entries())s.setAttribute("aria-selected",String(r===e)),s.tabIndex=r===e?0:-1,C(s.getAttribute("aria-controls")).hidden=r!==e;const n=e===1?"#rendering":"";g.hash=n,y.hash=n}w(location.hash==="#rendering"?1:0);for(const[e,n]of P.entries())n.addEventListener("click",()=>w(e)),n.addEventListener("keydown",r=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(r.key))return;r.preventDefault(),r.stopPropagation();const s=r.key==="Home"?0:r.key==="End"?P.length-1:(e+1)%P.length;w(s),P[s].focus()});function h(e){const n=e.nodes.filter(f=>f.atlasId),r=n.find(f=>f.id===D)??n[0];D=r?.id;const s=JSON.stringify([r?.id,r?.settings,n.map(({id:f,name:W})=>[f,W])]);if(s===N)return;N=s;const u=C("assetProperties"),T=u.querySelector("details")?.open,F=u.contains(document.activeElement)?document.activeElement?.id:void 0;if(!r){u.replaceChildren(ye("Import an atlas to configure asset rendering."));return}u.replaceChildren(le("Part",r.id,n.map(({id:f,name:W})=>[f,W]),f=>{D=f,c&&h(c)}),...K(r)),T&&(u.querySelector("details").open=!0),F&&document.getElementById(F)?.focus({preventScroll:!0})}function I(e){if(c&&e.revision<=c.revision)return;c?.view.selected!==e.view.selected&&e.nodes.some(M=>M.id===e.view.selected&&M.atlasId)&&(D=e.view.selected),c=e,document.documentElement.dataset.revision=String(e.revision),i.sync(e),C("projectName").textContent=e.name,document.title=e.name+" · "+(pe?"Playground":"Scene editor")+" · stack3.js",C("emptyStage").hidden=e.nodes.some(M=>M.atlasId),C("hierarchy").replaceChildren(q(e,null)),C("atlasLibrary").replaceChildren(...e.atlases.map(M=>{const m=document.createElement("div");m.className="atlas-row";const E=document.createElement("span");E.textContent=M.name;const ee=Z("Instance",()=>{const z=crypto.randomUUID();b([{action:"node.add",id:z,name:M.name,atlasId:M.id,parentId:c?.view.selected??null},{action:"view.set",patch:{selected:z}},{action:"view.frame"}])});return m.append(E,ee),e.nodes.some(z=>z.atlasId===M.id)||m.append(Z("Remove atlas",()=>b([{action:"atlas.remove",id:M.id}]))),m}));const n=e.nodes.find(M=>M.id===e.view.selected),r=i.scripts?.hasScripts();C("playTarget").textContent=r?e.play.startedAt===null?"Press Play to run script components.":"Script components running. Keyboard input is active.":n?n.name+" · Nudge with WASD":"Select an object to nudge it with WASD.",C("moveButtons").hidden=!!r;for(const M of C("moveButtons").querySelectorAll("button"))M.disabled=!n;const s=C("properties"),u=document.activeElement,T=u instanceof HTMLInputElement&&u.dataset.transformNode===n?.id?u.id:"",F=JSON.stringify([n,e.nodes.map(({id:M,name:m,parentId:E})=>[M,m,E])]);if(F!==p){const M=new Set(Array.from(s.querySelectorAll("details[open]")).map(m=>m.dataset.scriptEditor));p=F,s.replaceChildren(...n?L(n,e):[ye("Select an object to edit its properties.")]);for(const m of s.querySelectorAll("details[data-script-editor]"))m.open=M.has(m.dataset.scriptEditor);T&&document.getElementById(T)?.focus({preventScroll:!0})}h(e);const f=C("viewProperties"),W=JSON.stringify([e.view,e.nodes.filter(M=>M.scripts?.length).map(({id:M,name:m})=>[M,m])]);if(U!==W){U=W;const M=f.contains(document.activeElement)?document.activeElement?.id:void 0;f.replaceChildren(..._(e)),M&&document.getElementById(M)?.focus({preventScroll:!0})}const J=C("togglePlay");J.textContent=e.play.startedAt===null?"Play":"Pause",J.setAttribute("aria-pressed",String(e.play.startedAt!==null))}async function R(){try{const e=c?"?after="+c.revision:"",n=await fetch(l+"/state"+e);if(!n.ok)throw new Error("The live project server is unavailable.");n.status!==204&&(I(await n.json()),o.value="")}catch(e){o.value=e.message}}function b(e){return A=A.then(async()=>{if(c)try{const n=typeof e=="function"?e(c):e;if(!n.length){o.value="";return}const r=await fetch(l+"/actions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({revision:c.revision,actions:n})}),s=await r.json();if(r.status===409&&await R(),!r.ok)throw new Error(s.error||"Could not apply the edit.");I(s),o.value=""}catch(n){o.value=n.message}}),A}function q(e,n){const r=document.createElement("ul");r.className="scene-tree";for(const s of e.nodes.filter(u=>u.parentId===n)){const u=document.createElement("li"),T=Z(s.name,()=>b([{action:"view.set",patch:{selected:s.id}}])),F=document.createElement("small");F.textContent=s.atlasId?s.settings.format==="glb"?"3D":"2D":"Group",T.prepend(F),T.dataset.node=s.id,T.setAttribute("aria-pressed",String(s.id===e.view.selected)),u.append(T,q(e,s.id)),r.append(u)}return r}function L(e,n){const r=m=>b([{action:"node.set",id:e.id,patch:m}]),s=new Map(n.nodes.map(m=>[m.id,m.parentId])),u=n.nodes.filter(m=>{for(let E=m.id;E;E=s.get(E))if(E===e.id)return!1;return!0}),T=!e.parentId&&!e.atlasId,F=(m,E)=>{if(!T)return be(m,e[E],z=>r({[E]:z}));const ee=(z,Q,j)=>{const de=[...z];return de[Q]=j,de};return Ct(m,e.id,e[E],E==="position",(z,Q)=>i.previewTransform(e.id,{[E]:ee(e[E],z,Q)}),(z,Q)=>b(j=>{const de=j.nodes.find(fe=>fe.id===e.id);return de?[{action:"node.set",id:e.id,patch:{[E]:ee(de[E],z,Q)}}]:[]}))},f=[xt("Name",e.name,m=>r({name:m})),le("Parent",e.parentId??"",[["","Scene root"],...u.map(m=>[m.id,m.name])],m=>b([{action:"node.move",id:e.id,parentId:m||null}])),Y("Visible",e.visible,m=>r({visible:m})),F("Position","position"),F("Rotation (degrees)","rotation"),be("Scale",e.scale,m=>r({scale:m}))];if(T||n.nodes.some(m=>m.parentId===e.id)){const m=document.createElement("div");m.className="toolbar",m.append(Z("Apply Four-wheel",()=>b(E=>wt(E,e.id).actions)),Z("Apply Tracked Tank",()=>b(E=>yt(E,e.id).actions))),f.push(ge("Presets"),m)}f.push(ge("Motion"),be("Velocity (units/s)",e.velocity,m=>r({velocity:m})),be("Angular velocity (degrees/s)",e.angularVelocity,m=>r({angularVelocity:m}))),f.push(ge("Script components"));for(const m of e.scripts??[])f.push(B(e,m));const W=(m,E=crypto.randomUUID())=>b([{action:"script.set",nodeId:e.id,id:E,patch:m}]),J=document.createElement("div");J.className="toolbar",J.append(Z("Add script",()=>W({name:"Script",enabled:!1,fields:[],source:`function update({ dt, time, keys, fields, state, position, rotation, children }) {
16
+ return {};
17
+ }`})),Z("Add WASD vehicle",()=>W(lt))),e.atlasId&&!e.scripts?.some(m=>m.id==="sprite-stack-wheel")&&J.append(Z("Add Sprite Stack Wheel",()=>W(dt,"sprite-stack-wheel"))),f.push(J);const M=Z("Remove subtree",()=>b([{action:"node.remove",id:e.id}]));return M.className="danger",f.push(M),f}function K(e){const n=e.settings,r=f=>b([{action:"node.set",id:e.id,patch:{settings:f}}]),s=n.format==="stack",u=!s&&n.meshMethod==="contour",T=document.createElement("details"),F=document.createElement("summary");return F.textContent="Reconstruction settings",T.append(F,...u?[]:[se("Layers",n.layers,8,Number.MAX_SAFE_INTEGER,1,f=>r({layers:f}))],...!u||n.contourHub?[se(u?"Hub segments":"Texture resolution",n.resolution,16,Number.MAX_SAFE_INTEGER,1,f=>r({resolution:f}))]:[],...s?[se("Spacing",n.spacing,.05,20,.05,f=>r({spacing:f}))]:[],se("Height",n.height,.01,100,.01,f=>r({height:f})),se("Background threshold",n.threshold,0,255,1,f=>r({threshold:f})),le("Pivot",n.pivot,[["ground","Ground"],["center","Center"]],f=>r({pivot:f})),...u?[]:[le("Cross-section",n.profile,[["silhouette","From silhouettes"],["round","Round"],["round-base","Round above square base"]],f=>r({profile:f}))]),[le("Asset type",u?"contour":n.format,[["stack","Sprite stack"],["glb","Marching Cubes (3D mesh)"],["contour","Contour extrusion (3D mesh)"]],f=>r({format:f==="stack"?"stack":"glb",meshMethod:f==="contour"?"contour":"marching-cubes"})),...s?[]:[le("Texture projection",n.textureProjection??"auto",[["auto","Automatic (multi-view)"],["top-contour","Upper contour from TOP"]],f=>r({textureProjection:f}))],...u?[Y("Centered round hub",n.contourHub??!1,f=>r({contourHub:f}))]:[],ye(s?"Multi-view texturing blends colors from the atlas views.":"Multi-view texturing projects atlas views onto the mesh."),Y("Material lighting",n.lighting,f=>r({lighting:f})),...s?[Y("Pixel art",n.pixelArt,f=>r({pixelArt:f})),Y("Smooth edges",n.smoothEdges,f=>r({smoothEdges:f}))]:[],T]}function B(e,n){const r=document.createElement("section");r.className="script-component";const s=E=>b([{action:"script.set",nodeId:e.id,id:n.id,patch:E}]),u=document.createElement("output");u.id=Fe(e.id,n.id);const T=u.id;u.textContent=n.enabled&&i.scripts?.status(e.id,n.id)||"",r.append(ge(n.name),Y("Enabled",n.enabled,E=>s({enabled:E}),T+"-enabled"),u);for(const E of n.fields)r.append(se(E.label,E.value,E.min,E.max,E.step,ee=>{ee<E.min||ee>E.max||b(z=>{const Q=z.nodes.find(j=>j.id===e.id)?.scripts?.find(j=>j.id===n.id);return Q?[{action:"script.set",nodeId:e.id,id:n.id,patch:{fields:Q.fields.map(j=>j.name===E.name?{...j,value:ee}:j)}}]:[]})},T+"-field-"+E.name));const F=document.createElement("details");F.dataset.scriptEditor=T;const f=document.createElement("summary");f.textContent="Edit script";const W=document.createElement("input");W.type="text",W.value=n.name;const J=document.createElement("textarea");J.value=n.source,J.rows=9,J.spellcheck=!1;const M=document.createElement("textarea");M.value=JSON.stringify(n.fields,null,2),M.rows=6,M.spellcheck=!1,W.id=T+"-name",J.id=T+"-source",M.id=T+"-fields";const m=document.createElement("output");return m.setAttribute("role","status"),F.append(f,ie("Name",W),ie("JavaScript",J),ie("Inspector fields (JSON)",M),m,Z("Save script",()=>{try{const E=JSON.parse(M.value);if(!Array.isArray(E))throw new Error("Use a JSON array for inspector fields.");s({name:W.value,source:J.value,fields:E}),m.textContent=""}catch(E){m.textContent=E.message}})),r.append(F,Z("Remove script",()=>b([{action:"script.remove",nodeId:e.id,id:n.id}]))),r}function _(e){const n=e.view,r=u=>b([{action:"view.set",patch:u}]),s=e.nodes.filter(u=>u.scripts?.length||u.id===n.follow);return[le("Renderer",n.backend,[["cpu","CPU"],["gpu","GPU"]],u=>r({backend:u})),Y("Grid",n.grid,u=>r({grid:u})),Y("Supersampling",n.supersampling,u=>r({supersampling:u})),ge("CPU rendering"),Y("Detail Normals",!!n.detailNormals,u=>r({detailNormals:u,backend:"cpu"})),Y("Subpixel AA",!!n.subpixelAA,u=>r({subpixelAA:u,backend:"cpu"})),Y("Specular AA",!!n.specularAA,u=>r({specularAA:u,backend:"cpu"})),ye("Detail Normals and Specular AA use each part’s Material lighting setting."),...pe&&s.length?[le("Follow object",n.follow??"",[["","None"],...s.map(u=>[u.id,u.name])],u=>r({follow:u||null}))]:[],se("Squash",n.squash,.2,1,.01,u=>r({squash:u})),se("Zoom",n.scale,.1,10,.05,u=>r({scale:u})),se("Heading",n.yaw,-360,360,1,u=>r({yaw:u}))]}if(C("newGroup").addEventListener("click",()=>{const e=crypto.randomUUID();b([{action:"node.add",id:e,name:"Group",parentId:c?.view.selected??null},{action:"view.set",patch:{selected:e}}])}),C("frameScene").addEventListener("click",()=>b([{action:"view.frame"}])),C("stepTime").addEventListener("click",()=>b([{action:"play.step",seconds:1}])),C("resetTime").addEventListener("click",()=>b([{action:"play.reset"}])),C("togglePlay").addEventListener("click",()=>{b([{action:c?.play.startedAt===null?"play.start":"play.pause"}])}),pe){C("playControls").hidden=!1;const e={KeyA:[-.25,0,0],KeyD:[.25,0,0],KeyW:[0,0,-.25],KeyS:[0,0,.25]},n=s=>{const u=c?.view.selected;u&&e[s]&&b([{action:"play.nudge",id:u,translation:e[s]}])};for(const[s,u]of[["KeyA","Left"],["KeyW","Forward"],["KeyS","Back"],["KeyD","Right"]])C("moveButtons").append(Z(u,()=>n(s)));const r=s=>s instanceof Element&&!!s.closest('input:not([type="checkbox"]),select,textarea,[contenteditable]');document.addEventListener("keydown",s=>{if(!(s.altKey||s.ctrlKey||s.metaKey||r(s.target))&&!(s.code==="Space"&&s.target instanceof HTMLInputElement&&s.target.type==="checkbox")){if(i.scripts?.hasScripts()){if(c?.play.startedAt==null)return;(Object.hasOwn(e,s.code)||s.code.startsWith("Arrow")||s.code==="Space")&&s.preventDefault(),i.scripts.keyDown(s.code);return}s.repeat||!Object.hasOwn(e,s.code)||(s.preventDefault(),n(s.code))}}),document.addEventListener("keyup",s=>i.scripts?.keyUp(s.code)),document.addEventListener("focusin",s=>{r(s.target)&&i.scripts?.clearKeys()}),window.addEventListener("blur",()=>i.scripts?.clearKeys()),document.addEventListener("visibilitychange",()=>i.scripts?.clearKeys())}const oe=C("atlasFiles");C("importAtlases").addEventListener("click",()=>oe.click()),oe.addEventListener("change",async()=>{const e=[...oe.files??[]];if(oe.value="",!e.length||!c)return;const n=c.view.selected;try{const r=ut(C("importLayout").value).join(","),s=[];let u;for(const T of e){if(T.size>16*1024*1024)throw new Error("Use PNGs of up to 16 MB per file.");const{png:F,hash:f}=await Pt(T,r),W=crypto.randomUUID(),J=T.name.replace(/\.png$/i,"");s.push({action:"atlas.embed",id:f,name:J,png:F,layout:r},{action:"node.add",id:W,name:J,parentId:n,atlasId:f}),u=W}s.push({action:"view.set",patch:{selected:u}},{action:"view.frame"}),b(s)}catch(r){o.value=r.message}}),R(),window.setInterval(()=>{R()},650)}function Fe(t,l){return"script-status-"+t+":"+l}async function Pt(t,l){const d=new Uint8Array(await t.arrayBuffer()),o=new TextEncoder().encode(l),g=new Uint8Array(o.length+d.length);g.set(o),g.set(d,o.length);const y=Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256",g)),p=>p.toString(16).padStart(2,"0")).join("");let c="";for(let p=0;p<d.length;p+=8192)c+=String.fromCharCode(...d.subarray(p,p+8192));return{hash:y,png:btoa(c)}}function Z(t,l){const d=document.createElement("button");return d.type="button",d.textContent=t,d.addEventListener("click",l),d}function ge(t){const l=document.createElement("h3");return l.textContent=t,l}function ye(t){const l=document.createElement("p");return l.className="muted",l.textContent=t,l}function ie(t,l){const d=document.createElement("div");d.className="field";const o=document.createElement("label");return o.append(t),l.id||="field-"+t.toLowerCase().replaceAll(/[^a-z0-9]/g,"-"),l.tagName==="DIV"?o.id=l.id+"-label":o.htmlFor=l.id,d.append(o,l),d}function xt(t,l,d){const o=document.createElement("input");return o.type="text",o.value=l,o.addEventListener("change",()=>d(o.value)),ie(t,o)}function se(t,l,d,o,g,y,c=""){const p=document.createElement("input");return p.type="number",p.value=String(Number(l.toFixed(4))),p.min=String(d),p.max=String(o),p.step=String(g),p.id=c,p.addEventListener("change",()=>{Number.isFinite(p.valueAsNumber)&&y(p.valueAsNumber)}),ie(t,p)}function Y(t,l,d,o=""){const g=document.createElement("input");return g.type="checkbox",g.checked=l,g.id=o,g.addEventListener("change",()=>d(g.checked)),ie(t,g)}function le(t,l,d,o){const g=document.createElement("select");for(const[y,c]of d)g.add(new Option(c,y,!1,y===l));return g.addEventListener("change",()=>o(g.value)),ie(t,g)}function Ct(t,l,d,o,g,y){const c=document.createElement("div");c.className="transform-sliders",c.setAttribute("role","group");const p=ie(t,c);c.setAttribute("aria-labelledby",c.id+"-label");const N=o?1e4:360;return d.forEach((U,D)=>{const A=["X","Y","Z"][D],i=document.createElement("div"),P=document.createElement("label"),w=document.createElement("input"),h=document.createElement("input"),I=o?Math.max(5,Math.ceil(Math.abs(U))):N;P.textContent=A,w.type="range",w.id=c.id+"-"+D,P.htmlFor=w.id,w.dataset.transformNode=l,w.setAttribute("aria-label",t+" "+A+" slider"),w.min=String(-I),w.max=String(I),w.step=o?"0.01":"1",w.value=String(U),h.type="number",h.setAttribute("aria-label",t+" "+A),h.min=String(-N),h.max=String(N),h.step="any",h.value=String(U);let R;w.addEventListener("input",()=>{h.value=w.value,R=g(D,w.valueAsNumber)}),w.addEventListener("change",()=>{const b=R;R=void 0,y(D,w.valueAsNumber).finally(b)}),w.addEventListener("pointercancel",()=>{R?.(),R=void 0,w.value=h.value=String(U)}),h.addEventListener("change",()=>{h.validity.valid&&Number.isFinite(h.valueAsNumber)&&y(D,h.valueAsNumber)}),i.append(P,w,h),c.append(i)}),p}function be(t,l,d){const o=document.createElement("div");o.className="field-vector",o.setAttribute("role","group");const g=l.map((c,p)=>{const N=document.createElement("input");return N.type="number",N.step="any",N.value=String(c),N.setAttribute("aria-label",t+" "+["X","Y","Z"][p]),N.addEventListener("change",()=>{const U=g.map(D=>D.valueAsNumber);U.every(Number.isFinite)&&d(U)}),N});o.append(...g);const y=ie(t,o);return o.setAttribute("aria-labelledby",o.id+"-label"),y}
@@ -0,0 +1,21 @@
1
+ (function(){"use strict";const V=["top","left","front","rear","right","bottom"];function wn(t){const e=[137,80,78,71,13,10,26,10];if(t.length<33||e.some((i,a)=>t[a]!==i)||String.fromCharCode(...t.subarray(12,16))!=="IHDR")throw new Error("Expected a PNG image.");const n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(16),o=n.getUint32(20);if(!r||!o||!Number.isSafeInteger(r*o*4))throw new Error("Invalid PNG dimensions.");return{width:r,height:o}}function dn(t){const{width:e,height:n}=wn(t);if(e>8192||n>8192||e*n>16e6)throw new Error("PNG dimensions exceed the 8192 px or 16 MP input limit.");return{width:e,height:n}}function dt(t){const e=t.split(",").map(n=>n.trim());if(e.some(n=>!V.includes(n)))throw new Error("Use directions top, left, front, rear, right, and bottom.");if(e.length!==4&&e.length!==6||new Set(e).size!==e.length||V.slice(0,e.length).some(n=>!e.includes(n)))throw new Error("A layout needs the four required directions or all six, with no duplicates.");return e}function Nt(t,e){const{width:n,height:r}=t,o=new Uint8Array(t.data),i=n*r;for(let h=3;h<o.length;h+=4)if(o[h]<128)return{width:n,height:r,data:o};const a=new Uint8Array(i),s=new Uint32Array(i);let c=0,f=0;function l(h){if(a[h])return;a[h]=1;const u=h*4;Math.min(o[u],o[u+1],o[u+2])>=e&&(s[f++]=h)}for(let h=0;h<n;h++)l(h),l((r-1)*n+h);for(let h=1;h<r-1;h++)l(h*n),l(h*n+n-1);for(;c<f;){const h=s[c++];o[h*4+3]=0;const u=h%n;u&&l(h-1),u+1<n&&l(h+1),h>=n&&l(h-n),h+n<i&&l(h+n)}return{width:n,height:r,data:o}}function zt(t,e){const{left:n,top:r,width:o,height:i}=e,a=new Uint8Array(o*i*4);for(let s=0;s<i;s++){const c=((r+s)*t.width+n)*4;a.set(t.data.subarray(c,c+o*4),s*o*4)}return{width:o,height:i,data:a}}function St(t,e){const{left:n,top:r,width:o,height:i}=e;let a=n+o,s=-1,c=r+i,f=-1;for(let l=r;l<r+i;l++)for(let h=n;h<n+o;h++)t.data[(l*t.width+h)*4+3]<128||(a=Math.min(a,h),s=Math.max(s,h),c=Math.min(c,l),f=Math.max(f,l));return s<0?null:{left:a,top:c,width:s-a+1,height:f-c+1}}function Ot(t){const e=[];let n=-1;for(let r=0;r<=t.length;r++)t[r]?n<0&&(n=r):n>=0&&(e.push([n,r]),n=-1);return e}function jt(t,e,n){const r=new Uint8Array(t.width);for(let o=e;o<n;o++)for(let i=0;i<t.width;i++)t.data[(o*t.width+i)*4+3]>=128&&(r[i]=1);return Ot(r)}function xn(t,e){dt(e.join(","));let n=jt(t,0,t.height).map(([r,o])=>({left:r,top:0,width:o-r,height:t.height}));if(n.length!==e.length){const r=new Uint8Array(t.height);for(let o=0;o<t.height;o++)for(let i=0;i<t.width;i++)if(t.data[(o*t.width+i)*4+3]>=128){r[o]=1;break}n=Ot(r).flatMap(([o,i])=>jt(t,o,i).map(([a,s])=>({left:a,top:o,width:s-a,height:i-o})))}if(n.length!==e.length)throw new Error(`Expected ${e.length} separated views, found ${n.length}. Use clear gutters or individual PNGs.`);return n.map(r=>St(t,r))}function Cn(t,e,n=238){const r=Nt(t,n);return Object.fromEntries(xn(r,e).map((o,i)=>{const a=zt(r,o),s=a.width+2,c=a.height+2,f=new Uint8Array(s*c*4);for(let l=0;l<a.height;l++)f.set(a.data.subarray(l*a.width*4,(l+1)*a.width*4),((l+1)*s+1)*4);return[e[i],{width:s,height:c,data:f}]}))}function Bn(t,e=238){dt(Object.keys(t).join(","));const n=Object.entries(t);return Object.fromEntries(n.map(([r,o])=>{const i=Nt(o,e),a=St(i,{left:0,top:0,width:i.width,height:i.height});if(!a)throw new Error(`The ${r} view has an empty silhouette.`);return[r,zt(i,a)]}))}function mn(t){const{top:e,left:n,front:r,rear:o}=t,i=n.width/n.height*e.width/e.height,a=r.width/r.height,s=[];Math.abs(i/a-1)>.2&&s.push("Top, left, and front proportions differ by more than 20%. Check alignment."),Math.abs(o.width/o.height/a-1)>.2&&s.push("Front and rear proportions differ by more than 20%.");const c=Object.entries(t).map(([l,h])=>({direction:l,width:h.width,height:h.height})),f={x:Math.max(e.width,r.width,o.width,t.bottom?.width??0),y:Math.max(e.height,n.width,t.right?.width??0,t.bottom?.height??0),z:Math.max(n.height,r.height,o.height,t.right?.height??0)};return{views:c,nativeSamples:f,warnings:s}}const bt=128;function Mn(t,e,n,r){if(!Number.isSafeInteger(r)||r<8)throw new Error("Layers must be a safe integer of at least 8.");if(!Number.isSafeInteger(n)||n<16)throw new Error("Resolution must be a safe integer of at least 16.");const o=Math.max(t,e),i=Math.max(2,Math.round(t/o*n)),a=Math.max(2,Math.round(e/o*n));if(!Number.isSafeInteger(i*a*r*4))throw new Error("Requested grid is too large to address its RGBA samples.");return{width:i,depth:a,layers:r}}const rt=t=>Math.max(0,Math.min(1,t));function yn(t,e){const{positions:n,indices:r,size:o}=t,i=Math.max(o[0],o[1]),a=Math.max(1,Math.round(e*o[0]/i)),s=Math.max(1,Math.round(e*o[1]/i)),c=u=>Math.min(a-1,Math.floor(rt(u/o[0]+.5)*a)),f=u=>Math.min(s-1,Math.floor(rt(u/o[1]+.5)*s)),l=Array.from({length:a*s},()=>[]),h=new Uint8Array(r.length/3);for(let u=0;u<r.length;u+=3){const g=r[u]*3,A=r[u+1]*3,x=r[u+2]*3;if((n[A+2]-n[g+2])*(n[x]-n[g])-(n[A]-n[g])*(n[x+2]-n[g+2])<=0)continue;h[u/3]=1;const C=c(Math.min(n[g],n[A],n[x])),w=c(Math.max(n[g],n[A],n[x])),d=f(Math.min(n[g+2],n[A+2],n[x+2])),m=f(Math.max(n[g+2],n[A+2],n[x+2]));for(let E=d;E<=m;E++)for(let I=C;I<=w;I++)l[E*a+I].push(u)}for(let u=0;u<r.length;u+=3){if(!h[u/3])continue;const g=r[u]*3,A=r[u+1]*3,x=r[u+2]*3,B=(n[g]+n[A]+n[x])/3,C=(n[g+2]+n[A+2]+n[x+2])/3,w=(n[g+1]+n[A+1]+n[x+1])/3;for(const d of l[f(C)*a+c(B)]){if(d===u)continue;const m=r[d]*3,E=r[d+1]*3,I=r[d+2]*3,Q=n[E]-n[m],M=n[E+2]-n[m+2],v=n[I]-n[m],y=n[I+2]-n[m+2],F=Q*y-M*v,p=((B-n[m])*y-(C-n[m+2])*v)/F,b=(Q*(C-n[m+2])-M*(B-n[m]))/F;if(p<0||b<0||p+b>1)continue;if(n[m+1]+p*(n[E+1]-n[m+1])+b*(n[I+1]-n[m+1])>w+o[2]*1e-6){h[u/3]=0;break}}}return h}function pn(t,e,n,r){const{positions:o,normals:i,uvs:a,indices:s,texture:c,size:f}=t;n=Math.max(1,Math.min(Math.max(e.width,e.height),Math.round(n)||96));const l=yn(t,n),h=f[1]>=f[0]?2:0,u=h===2?f[1]:f[0],g=M=>Math.min(n-1,Math.floor(rt(M/u+.5)*n)),A=new Float32Array(n).fill(-1/0);for(let M=0;M<o.length;M+=3){const v=g(o[M+h]);A[v]=Math.max(A[v],o[M+1])}const x=f[2]*Math.max(.1,1.5/r),B=new Map;let C=0;for(let M=0;M<s.length;M+=3){const v=s[M]*3,y=s[M+1]*3,F=s[M+2]*3,p=(o[v+h]+o[y+h]+o[F+h])/3,b=(o[v+1]+o[y+1]+o[F+1])/3>=A[g(p)]-x,k=o[y]-o[v],U=o[y+1]-o[v+1],D=o[y+2]-o[v+2],L=o[F]-o[v],K=o[F+1]-o[v+1],z=o[F+2]-o[v+2],S=D*L-k*z,P=Math.abs(U*z-D*K),H=Math.abs(k*K-U*L),J=b&&S===0&&Math.abs(p)<u*.46&&(h===2?H>P:P>H);if(!(!l[M/3]&&!J)){C++;for(let N=M;N<M+3;N++){const gt=s[N];B.has(gt)||B.set(gt,o.length/3+B.size),s[N]=B.get(gt)}}}if(!C)return 0;const w=Math.min(1,512/Math.max(e.width,e.height)),d=Math.max(1,Math.round(e.width*w)),m=Math.max(1,Math.round(e.height*w));for(let M=-1;M<=m;M++){const v=Math.min(m-1,Math.max(0,M)),y=Math.floor((v+.5)*e.height/m)*e.width,F=k=>(y+Math.floor((k+.5)*e.width/d))*4;let p=0,b=d-1;for(;p<=b&&e.data[F(p)+3]<128;)p++;for(;b>=p&&e.data[F(b)+3]<128;)b--;if(!(p>b))for(let k=-1;k<=d;k++){if(k>=p&&k<=b)continue;const U=F(k<p?p:b);c.data.set(e.data.subarray(U,U+3),((M+1)*c.width+k+1)*4)}}const E=new Float32Array(o.length+B.size*3),I=new Float32Array(E.length),Q=new Float32Array(a.length+B.size*2);E.set(o),I.set(i),Q.set(a);for(const[M,v]of B)E.set(o.subarray(M*3,M*3+3),v*3),I.set(i.subarray(M*3,M*3+3),v*3),Q[v*2]=(1.5+rt(o[M*3]/f[0]+.5)*(d-1))/c.width,Q[v*2+1]=(1.5+rt(.5-o[M*3+2]/f[1])*(m-1))/c.height;return Object.assign(t,{positions:E,normals:I,uvs:Q}),C}function xt(t,e){return t==null||e==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function Qn(t,e){return t==null||e==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Tt(t){let e,n,r;t.length!==2?(e=xt,n=(s,c)=>xt(t(s),c),r=(s,c)=>t(s)-c):(e=t===xt||t===Qn?t:vn,n=t,r=t);function o(s,c,f=0,l=s.length){if(f<l){if(e(c,c)!==0)return l;do{const h=f+l>>>1;n(s[h],c)<0?f=h+1:l=h}while(f<l)}return f}function i(s,c,f=0,l=s.length){if(f<l){if(e(c,c)!==0)return l;do{const h=f+l>>>1;n(s[h],c)<=0?f=h+1:l=h}while(f<l)}return f}function a(s,c,f=0,l=s.length){const h=o(s,c,f,l-1);return h>f&&r(s[h-1],c)>-r(s[h],c)?h-1:h}return{left:o,center:a,right:i}}function vn(){return 0}function En(t){return t===null?NaN:+t}Tt(xt),Tt(En).center;function In(t,e){let n=0;for(let r of t)r!=null&&(r=+r)>=r&&++n;return n}function bn(t,e){let n,r;if(e===void 0)for(const o of t)o!=null&&(n===void 0?o>=o&&(n=r=o):(n>o&&(n=o),r<o&&(r=o)));else{let o=-1;for(let i of t)(i=e(i,++o,t))!=null&&(n===void 0?i>=i&&(n=r=i):(n>i&&(n=i),r<i&&(r=i)))}return[n,r]}const Fn=Math.sqrt(50),kn=Math.sqrt(10),Un=Math.sqrt(2);function Ct(t,e,n){const r=(e-t)/Math.max(0,n),o=Math.floor(Math.log10(r)),i=r/Math.pow(10,o),a=i>=Fn?10:i>=kn?5:i>=Un?2:1;let s,c,f;return o<0?(f=Math.pow(10,-o)/a,s=Math.round(t*f),c=Math.round(e*f),s/f<t&&++s,c/f>e&&--c,f=-f):(f=Math.pow(10,o)*a,s=Math.round(t/f),c=Math.round(e/f),s*f<t&&++s,c*f>e&&--c),c<s&&.5<=n&&n<2?Ct(t,e,n*2):[s,c,f]}function Dn(t,e,n){if(e=+e,t=+t,n=+n,!(n>0))return[];if(t===e)return[t];const r=e<t,[o,i,a]=r?Ct(e,t,n):Ct(t,e,n);if(!(i>=o))return[];const s=i-o+1,c=new Array(s);if(r)if(a<0)for(let f=0;f<s;++f)c[f]=(i-f)/-a;else for(let f=0;f<s;++f)c[f]=(i-f)*a;else if(a<0)for(let f=0;f<s;++f)c[f]=(o+f)/-a;else for(let f=0;f<s;++f)c[f]=(o+f)*a;return c}function Ln(t,e,n){return e=+e,t=+t,n=+n,Ct(t,e,n)[2]}function Hn(t,e,n){let r;for(;;){const o=Ln(t,e,n);if(o===r||o===0||!isFinite(o))return[t,e];if(o>0){const i=Math.ceil(t/o),a=Math.floor(e/o);t=(i-(i*o>t))*o,e=(a+(a*o<e))*o}else if(o<0){const i=-o,a=Math.ceil(t*i),s=Math.floor(e*i);t=(a-(a/i>t))/i,e=(s+(s/i<e))/i}r=o}}function Kn(t){return Math.max(1,Math.ceil(Math.log(In(t))/Math.LN2)+1)}var Gn=Array.prototype,Yn=Gn.slice;function Jn(t,e){return t-e}function Pn(t){for(var e=0,n=t.length,r=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];++e<n;)r+=t[e-1][1]*t[e][0]-t[e-1][0]*t[e][1];return r}var Zt=t=>()=>t;function Nn(t,e){for(var n=-1,r=e.length,o;++n<r;)if(o=zn(t,e[n]))return o;return 0}function zn(t,e){for(var n=e[0],r=e[1],o=-1,i=0,a=t.length,s=a-1;i<a;s=i++){var c=t[i],f=c[0],l=c[1],h=t[s],u=h[0],g=h[1];if(Sn(c,h,e))return 0;l>r!=g>r&&n<(u-f)*(r-l)/(g-l)+f&&(o=-o)}return o}function Sn(t,e,n){var r;return On(t,e,n)&&jn(t[r=+(t[0]===e[0])],n[r],e[r])}function On(t,e,n){return(e[0]-t[0])*(n[1]-t[1])===(n[0]-t[0])*(e[1]-t[1])}function jn(t,e,n){return t<=e&&e<=n||n<=e&&e<=t}function Tn(){}var X=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function Zn(){var t=1,e=1,n=Kn,r=c;function o(f){var l=n(f);if(Array.isArray(l))l=l.slice().sort(Jn);else{const h=bn(f,Rn);for(l=Dn(...Hn(h[0],h[1],l),l);l[l.length-1]>=h[1];)l.pop();for(;l[1]<h[0];)l.shift()}return l.map(h=>i(f,h))}function i(f,l){const h=l==null?NaN:+l;if(isNaN(h))throw new Error(`invalid value: ${l}`);var u=[],g=[];return a(f,h,function(A){r(A,f,h),Pn(A)>0?u.push([A]):g.push(A)}),g.forEach(function(A){for(var x=0,B=u.length,C;x<B;++x)if(Nn((C=u[x])[0],A)!==-1){C.push(A);return}}),{type:"MultiPolygon",value:l,coordinates:u}}function a(f,l,h){var u=new Array,g=new Array,A,x,B,C,w,d;for(A=x=-1,C=q(f[0],l),X[C<<1].forEach(m);++A<t-1;)B=C,C=q(f[A+1],l),X[B|C<<1].forEach(m);for(X[C<<0].forEach(m);++x<e-1;){for(A=-1,C=q(f[x*t+t],l),w=q(f[x*t],l),X[C<<1|w<<2].forEach(m);++A<t-1;)B=C,C=q(f[x*t+t+A+1],l),d=w,w=q(f[x*t+A+1],l),X[B|C<<1|w<<2|d<<3].forEach(m);X[C|w<<3].forEach(m)}for(A=-1,w=f[x*t]>=l,X[w<<2].forEach(m);++A<t-1;)d=w,w=q(f[x*t+A+1],l),X[w<<2|d<<3].forEach(m);X[w<<3].forEach(m);function m(E){var I=[E[0][0]+A,E[0][1]+x],Q=[E[1][0]+A,E[1][1]+x],M=s(I),v=s(Q),y,F;(y=g[M])?(F=u[v])?(delete g[y.end],delete u[F.start],y===F?(y.ring.push(Q),h(y.ring)):u[y.start]=g[F.end]={start:y.start,end:F.end,ring:y.ring.concat(F.ring)}):(delete g[y.end],y.ring.push(Q),g[y.end=v]=y):(y=u[v])?(F=g[M])?(delete u[y.start],delete g[F.end],y===F?(y.ring.push(Q),h(y.ring)):u[F.start]=g[y.end]={start:F.start,end:y.end,ring:F.ring.concat(y.ring)}):(delete u[y.start],y.ring.unshift(I),u[y.start=M]=y):u[M]=g[v]={start:M,end:v,ring:[I,Q]}}}function s(f){return f[0]*2+f[1]*(t+1)*4}function c(f,l,h){f.forEach(function(u){var g=u[0],A=u[1],x=g|0,B=A|0,C=Ft(l[B*t+x]);g>0&&g<t&&x===g&&(u[0]=Rt(g,Ft(l[B*t+x-1]),C,h)),A>0&&A<e&&B===A&&(u[1]=Rt(A,Ft(l[(B-1)*t+x]),C,h))})}return o.contour=i,o.size=function(f){if(!arguments.length)return[t,e];var l=Math.floor(f[0]),h=Math.floor(f[1]);if(!(l>=0&&h>=0))throw new Error("invalid size");return t=l,e=h,o},o.thresholds=function(f){return arguments.length?(n=typeof f=="function"?f:Array.isArray(f)?Zt(Yn.call(f)):Zt(f),o):n},o.smooth=function(f){return arguments.length?(r=f?c:Tn,o):r===c},o}function Rn(t){return isFinite(t)?t:NaN}function q(t,e){return t==null?!1:+t>=e}function Ft(t){return t==null||isNaN(t=+t)?-1/0:t}function Rt(t,e,n,r){const o=r-e,i=n-e,a=isFinite(o)||isFinite(i)?o/i:Math.sign(o)/Math.sign(i);return isNaN(a)?t:t+a-.5}const it=new Set;let kt=!1;function Vn(t,e,n=2){const r=e&&e.length,o=r?e[0]*n:t.length;it.size&&it.clear();let i=Vt(t,0,o,n,!0);const a=[];if(!i||i.next===i.prev)return a;let s=0,c=0,f=0;if(r&&(i=qn(t,e,i,n)),t.length>80*n){s=t[0],c=t[1];let l=s,h=c;for(let u=n;u<o;u+=n){const g=t[u],A=t[u+1];g<s&&(s=g),A<c&&(c=A),g>l&&(l=g),A>h&&(h=A)}f=Math.max(l-s,h-c),f=f!==0?32767/f:0}return Ut(i,a,s,c,f),a}function Vt(t,e,n,r,o){let i=null;if(o===ue(t,e,n,r)>0)for(let a=e;a<n;a+=r)i=nn(a/r|0,t[a],t[a+1],i);else for(let a=n-r;a>=e;a-=r)i=nn(a/r|0,t[a],t[a+1],i);return i&&at(i,i.next)&&(ht(i),i=i.next),i}function tt(t,e=t){const n=e===t;let r=t,o;do o=!1,r!==r.next&&(it.size===0||!it.has(r))&&(at(r,r.next)||Y(r.prev,r,r.next)===0)?((n||r===e)&&(e=r.prev),kt=!0,ht(r),r=r.prev,o=!0):(n||r!==e)&&(r=r.next,o=!n);while(o||r!==e);return e}function Ut(t,e,n,r,o){o&&se(t,n,r,o);let i=t,a=!1;for(;t.prev!==t.next;){const s=t.prev,c=t.next;if(Y(s,t,c)<0&&(o?$n(t,n,r,o):Xn(t))){e.push(s.i,t.i,c.i),ht(t),t=c,i=c;continue}if(t=c,t===i){if(kt=!1,t=tt(t),kt){i=t;continue}if(!a){t=_n(t,e),i=t,a=!0;continue}Wn(t,e,n,r,o);break}}}function Xn(t){const e=t.prev,n=t,r=t.next,o=e.x,i=n.x,a=r.x,s=e.y,c=n.y,f=r.y,l=Math.min(o,i,a),h=Math.min(s,c,f),u=Math.max(o,i,a),g=Math.max(s,c,f);let A=r.next;for(;A!==e;){if(A.x>=l&&A.x<=u&&A.y>=h&&A.y<=g&&!(o===A.x&&s===A.y)&&Mt(o,s,i,c,a,f,A.x,A.y)&&Y(A.prev,A,A.next)>=0)return!1;A=A.next}return!0}function $n(t,e,n,r){const o=t.prev,i=t,a=t.next,s=o.x,c=i.x,f=a.x,l=o.y,h=i.y,u=a.y,g=Math.min(s,c,f),A=Math.min(l,h,u),x=Math.max(s,c,f),B=Math.max(l,h,u),C=Kt(g,A,e,n,r),w=Kt(x,B,e,n,r);let d=t.prevZ;for(;d&&d.z>=C;){if(d.x>=g&&d.x<=x&&d.y>=A&&d.y<=B&&d!==a&&!(s===d.x&&l===d.y)&&Mt(s,l,c,h,f,u,d.x,d.y)&&Y(d.prev,d,d.next)>=0)return!1;d=d.prevZ}let m=t.nextZ;for(;m&&m.z<=w;){if(m.x>=g&&m.x<=x&&m.y>=A&&m.y<=B&&m!==a&&!(s===m.x&&l===m.y)&&Mt(s,l,c,h,f,u,m.x,m.y)&&Y(m.prev,m,m.next)>=0)return!1;m=m.nextZ}return!0}function _n(t,e){let n=t,r=!1;do{const o=n.prev,i=n.next.next;qt(o,n,n.next,i,!1)&&ft(o,i)&&ft(i,o)&&(e.push(o.i,n.i,i.i),ht(n),ht(n.next),n=t=i,r=!0),n=n.next}while(n!==t);return r?tt(n):n}function Wn(t,e,n,r,o){let i=t;do{let a=i.next.next;for(;a!==i.prev;){if(i.i!==a.i&&fe(i,a)){let s=tn(i,a);i=tt(i,i.next),s=tt(s,s.next),Ut(i,e,n,r,o),Ut(s,e,n,r,o);return}a=a.next}i=i.next}while(i!==t)}let Dt=!1;function qn(t,e,n,r){const o=[];for(let i=0,a=e.length;i<a;i++){const s=e[i]*r,c=i<a-1?e[i+1]*r:t.length,f=Vt(t,s,c,r,!1);f===f.next&&it.add(f),o.push(ae(f))}o.sort(te),ee(t.length/r,e.length),$t(n,n),Dt=!0;for(let i=0;i<o.length;i++)n=ne(o[i],n);return Dt=!1,tt(n)}function te(t,e){return t.x-e.x||t.y-e.y||(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}function ne(t,e){const n=re(t,e);if(!n)return e;const r=tn(n,t),o=r.next;return $t(n,o.next),tt(r,r.next),tt(n,n.next)}const Xt=16;let G=new Float64Array(0),Bt=0;const Lt=[],Ht=[];function ee(t,e){const n=Math.ceil((t+2*e)/Xt)+e+2;G.length<n*4&&(G=new Float64Array(n*4)),Bt=0}function $t(t,e){let n=t;do{const r=Bt++;Lt[r]=n;let o=n.x,i=n.y,a=n.x,s=n.y,c=0;do{const l=n.next;n.z=r,l.x<o&&(o=l.x),l.x>a&&(a=l.x),l.y<i&&(i=l.y),l.y>s&&(s=l.y),n=l}while(++c<Xt&&n!==e);Ht[r]=n;const f=r*4;G[f]=o,G[f+1]=i,G[f+2]=a,G[f+3]=s}while(n!==e)}function oe(t,e){const n=t.z*4;e.x<G[n]&&(G[n]=e.x),e.y<G[n+1]&&(G[n+1]=e.y),e.x>G[n+2]&&(G[n+2]=e.x),e.y>G[n+3]&&(G[n+3]=e.y)}function _t(t){let e=Ht[t];for(;e.prev.next!==e;)e=e.next;return Ht[t]=e,e}function Wt(t){let e=Lt[t];for(;e.prev.next!==e;)e=e.next;return Lt[t]=e,e}function re(t,e){let n=e;const r=t.x,o=t.y;let i=-1/0,a;if(at(t,n))return n;for(let u=0,g=0;u<Bt;u++,g+=4){if(o<G[g+1]||o>G[g+3]||G[g]>r||G[g+2]<=i)continue;const A=_t(u);n=Wt(u);do{if(n.prev.next===n){if(at(t,n.next))return n.next;if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){const x=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(x<=r&&x>i&&(i=x,a=n.x<n.next.x?n:n.next,x===r))return a}}n=n.next}while(n!==A)}if(!a)return null;const s=a.x,c=a.y,f=Math.min(o,c),l=Math.max(o,c);let h=1/0;for(let u=0,g=0;u<Bt;u++,g+=4){if(G[g+2]<s||G[g]>r||G[g+3]<f||G[g+1]>l)continue;const A=_t(u);n=Wt(u);do{if(n.prev.next===n&&r>=n.x&&n.x>=s&&r!==n.x&&Mt(o<c?r:i,o,s,c,o<c?i:r,o,n.x,n.y)){const x=Math.abs(o-n.y)/(r-n.x);(ft(n,t)||n.y===o&&n.next.y===o&&n.next.x>r)&&(x<h||x===h&&(n.x>a.x||n.x===a.x&&ie(a,n)))&&(a=n,h=x)}n=n.next}while(n!==A)}return a}function ie(t,e){return Y(t.prev,t,e.prev)<0&&Y(e.next,t,t.next)<0}const Z=[];let ot=[],nt=new Uint32Array(0),st=new Uint32Array(0);const ct=new Uint32Array(256);function se(t,e,n,r){let o=t,i=0;do o.z=Kt(o.x,o.y,e,n,r),Z[i++]=o,o=o.next;while(o!==t);ce(i);let a=null;for(let s=0;s<i;s++){const c=Z[s];c.prevZ=a,a&&(a.nextZ=c),a=c}a.nextZ=null,Z.fill(null,0,i),ot.fill(null,0,i)}function ce(t){if(t<=32){for(let e=1;e<t;e++){const n=Z[e],r=n.z;let o=e-1;for(;o>=0&&Z[o].z>r;)Z[o+1]=Z[o],o--;Z[o+1]=n}return}nt.length<t&&(nt=new Uint32Array(t),st=new Uint32Array(t),ot=new Array(t));for(let e=0;e<t;e++)nt[e]=Z[e].z;mt(t,Z,nt,ot,st,0),mt(t,ot,st,Z,nt,8),mt(t,Z,nt,ot,st,16),mt(t,ot,st,Z,nt,24)}function mt(t,e,n,r,o,i){ct.fill(0);for(let s=0;s<t;s++)ct[n[s]>>>i&255]++;let a=0;for(let s=0;s<256;s++){const c=ct[s];ct[s]=a,a+=c}for(let s=0;s<t;s++){const c=n[s],f=ct[c>>>i&255]++;r[f]=e[s],o[f]=c}}function Kt(t,e,n,r,o){return t=(t-n)*o|0,e=(e-r)*o|0,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t|e<<1}function ae(t){let e=t,n=t;do(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next;while(e!==t);return n}function Mt(t,e,n,r,o,i,a,s){return(o-a)*(e-s)>=(t-a)*(i-s)&&(t-a)*(r-s)>=(n-a)*(e-s)&&(n-a)*(i-s)>=(o-a)*(r-s)}function fe(t,e){const n=at(t,e)&&Y(t.prev,t,t.next)>0&&Y(e.prev,e,e.next)>0;return t.next.i!==e.i&&(n||ft(t,e)&&ft(e,t)&&(Y(t.prev,t,e.prev)!==0||Y(t,e.prev,e)!==0))&&!he(t,e)&&(n||le(t,e))}function Y(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function at(t,e){return t.x===e.x&&t.y===e.y}function qt(t,e,n,r,o=!0){const i=Y(t,e,n),a=Y(t,e,r),s=Y(n,r,t),c=Y(n,r,e);return(i>0&&a<0||i<0&&a>0)&&(s>0&&c<0||s<0&&c>0)?!0:o?!!(i===0&&yt(t,n,e)||a===0&&yt(t,r,e)||s===0&&yt(n,t,r)||c===0&&yt(n,e,r)):!1}function yt(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function he(t,e){const n=Math.min(t.x,e.x),r=Math.max(t.x,e.x),o=Math.min(t.y,e.y),i=Math.max(t.y,e.y);let a=t;do{const s=a.next;if(a.x>r&&s.x>r||a.x<n&&s.x<n||a.y>i&&s.y>i||a.y<o&&s.y<o){a=s;continue}if(a.i!==t.i&&s.i!==t.i&&a.i!==e.i&&s.i!==e.i&&qt(a,s,t,e))return!0;a=s}while(a!==t);return!1}function ft(t,e){return Y(t.prev,t,t.next)<0?Y(t,e,t.next)>=0&&Y(t,t.prev,e)>=0:Y(t,e,t.prev)<0||Y(t,t.next,e)<0}function le(t,e){let n=t,r=!1;const o=(t.x+e.x)/2,i=(t.y+e.y)/2;do{const a=n.next;n.y>i!=a.y>i&&o<(a.x-n.x)*(i-n.y)/(a.y-n.y)+n.x&&(r=!r),n=a}while(n!==t);return r}function tn(t,e){const n=Gt(t.i,t.x,t.y),r=Gt(e.i,e.x,e.y),o=t.next,i=e.prev;return t.next=e,e.prev=t,n.next=o,o.prev=n,r.next=n,n.prev=r,i.next=r,r.prev=i,r}function nn(t,e,n,r){const o=Gt(t,e,n);return r?(o.next=r.next,o.prev=r,r.next.prev=o,r.next=o):(o.prev=o,o.next=o),o}function ht(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ),Dt&&oe(t.prev,t.next)}function Gt(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function ue(t,e,n,r){let o=0;for(let i=e,a=n-r;i<n;i+=r)o+=(t[a]-t[i])*(t[i+1]+t[a+1]),a=i;return o}function Ae(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Yt={exports:{}},en;function ge(){return en||(en=1,(function(t){(function(){function e(s,c){var f=s.x-c.x,l=s.y-c.y;return f*f+l*l}function n(s,c,f){var l=c.x,h=c.y,u=f.x-l,g=f.y-h;if(u!==0||g!==0){var A=((s.x-l)*u+(s.y-h)*g)/(u*u+g*g);A>1?(l=f.x,h=f.y):A>0&&(l+=u*A,h+=g*A)}return u=s.x-l,g=s.y-h,u*u+g*g}function r(s,c){for(var f=s[0],l=[f],h,u=1,g=s.length;u<g;u++)h=s[u],e(h,f)>c&&(l.push(h),f=h);return f!==h&&l.push(h),l}function o(s,c,f,l,h){for(var u=l,g,A=c+1;A<f;A++){var x=n(s[A],s[c],s[f]);x>u&&(g=A,u=x)}u>l&&(g-c>1&&o(s,c,g,l,h),h.push(s[g]),f-g>1&&o(s,g,f,l,h))}function i(s,c){var f=s.length-1,l=[s[0]];return o(s,0,f,c,l),l.push(s[f]),l}function a(s,c,f){if(s.length<=2)return s;var l=c!==void 0?c*c:1;return s=f?s:r(s,l),s=i(s,l),s}t.exports=a,t.exports.default=a})()})(Yt)),Yt.exports}var we=ge(),de=Ae(we);function xe(t){const{width:e,height:n}=t,r=t.data.slice(),o=new Int32Array(e*n);let i=0,a=0;for(let c=0;c<o.length;c++)r[c*4+3]>=128&&(o[a++]=c);function s(c,f){r[f*4+3]>=128||(r.set(r.subarray(c*4,c*4+3),f*4),r[f*4+3]=255,o[a++]=f)}for(;i<a;){const c=o[i++],f=c%e;f&&s(c,c-1),f+1<e&&s(c,c+1),c>=e&&s(c,c-e),c+e<o.length&&s(c,c+e)}return{width:e,height:n,data:r}}function Ce(t){const{width:e,height:n,data:r}=t,o=new Array(e*n);for(let i=0;i<o.length;i++)o[i]=r[i*4+3];return Zn().size([e,n]).contour(o,127.5).coordinates.map(i=>i.map((a,s)=>{const c=a.map(([u,g])=>({x:u,y:g})),f=de(c,.75,!0),l=(f.length>=4?f:c).slice(0,-1);return l.reduce((u,g,A)=>{const x=l[(A+1)%l.length];return u+g.x*x.y-x.x*g.y},0)>0!=(s===0)&&l.reverse(),l.map(u=>({x:u.x/e,y:u.y/n}))}))}function on(t){let e=!1;for(let n=0;n<t.length;n++){const r=t[n],o=t[(n+1)%t.length];r.y>.5!=o.y>.5&&.5<r.x+(.5-r.y)*(o.x-r.x)/(o.y-r.y)&&(e=!e)}return e}function rn(t,e){let n=t.height,r=-1;for(let o=0;o<t.height;o++)t.data[4*(o*t.width+e)+3]>=128&&(n=Math.min(n,o),r=o);if(r>=n)return[n/t.height,(r+1)/t.height]}function Be(t,e,[n,,r]){const o=t.top,i=t.left,a=[];for(let h=0;h<o.width;h++){const u=rn(o,h);u&&a.push(u[1]-u[0])}a.sort((h,u)=>h-u);const s=a[Math.floor(a.length/2)];if(!(s>0&&s<1))throw new Error("Contour hub needs a projecting axle in TOP.");let c=1/0;for(const h of e)for(let u=0;u<h.length;u++){const g=h[u],A=h[(u+1)%h.length],x=(g.x-.5)*n,B=(g.y-.5)*r,C=(A.x-g.x)*n,w=(A.y-g.y)*r,d=Math.max(0,Math.min(1,-(x*C+B*w)/(C*C+w*w||1)));c=Math.min(c,Math.hypot(x+d*C,B+d*w))}const f=[.12,.88].map(h=>rn(i,Math.floor(h*i.width)));if(f.some(h=>!h))throw new Error("Contour hub needs a centered collar in LEFT.");const l=f.map(h=>Math.min((h[1]-h[0])*r/2,c*.95));return{plate:s,radii:l}}function me(t,e,n,r,o,i,a,s){const[c,f,l]=e,h=Ce(r);if(!h.length)throw new Error("Empty FRONT contour.");const u=a?h.find(Q=>on(Q[0])&&!Q.slice(1).some(on)):void 0;if(a&&!u)throw new Error("Contour hub needs solid material at the center of FRONT.");const g=u&&Be(t,u,e),A=f*(g?.plate??1)/2,x=[],B=[],C=[],w=[];function d(Q,M,v,y){const F=x.length/3;x.push((Q.x-.5)*c,(1-Q.y)*l-n[2],M),B.push(...v);const p=M/f+.5;let b=Q.x,k=Q.y;y==="rear"&&(b=1-b),y==="top"&&(k=1-p),y==="bottom"&&(k=p),y==="left"&&(b=p),y==="right"&&(b=1-p);const U=o.get(y);return C.push((U.left+.5+b*(U.image.width-1))/i.width,(1.5+k*(U.image.height-1))/i.height),F}function m(Q){return Array.from({length:s},(M,v)=>{const y=-2*Math.PI*v/s;return{x:.5+Q*Math.cos(y)/c,y:.5+Q*Math.sin(y)/l}})}function E(Q,M,v){const y=[],F=[],p=x.length/3;for(const[k,U]of Q.entries()){k&&y.push(F.length/2);for(const D of U)F.push(D.x,D.y),d(D,M,[0,0,v],v<0?"front":"rear")}const b=Vn(F,y);for(let k=0;k<b.length;k+=3){const U=p+b[k],D=p+b[k+1],L=p+b[k+2];v<0?w.push(U,D,L):w.push(U,L,D)}}function I(Q,M,v){const y=f/2-A,F=[[0,1],[.38,1],[.44,.93],[.87,.93],[1,.82]];let p=v;for(let b=1;b<F.length;b++){const[k,U]=F[b],[D,L]=F[b-1],K=m(Q*U),z=(L-U)*Q/((k-D)*y),S=Math.hypot(1,z),P=x.length/3;for(let H=0;H<s;H++){const J=-2*Math.PI*H/s,N=[Math.cos(J)/S,-Math.sin(J)/S,M*z/S];d(p[H],M*(A+D*y),N,"left"),d(K[H],M*(A+k*y),N,"left")}for(let H=0;H<s;H++){const J=P+H*2,N=P+(H+1)%s*2;M>0?w.push(J,N,N+1,J,N+1,J+1):w.push(J,N+1,N,J,J+1,N+1)}p=K}E([p],M*f/2,M)}for(const Q of h){for(const M of[-1,1])if(Q===u&&g){const v=g.radii[M<0?0:1],y=m(v);E([...Q,y],M*A,M),I(v,M,y)}else E(Q,M*A,M);for(const M of Q)for(let v=0;v<M.length;v++){const y=M[v],F=M[(v+1)%M.length],p=(F.x-y.x)*c,b=(F.y-y.y)*l,k=Math.hypot(p,b);if(!k)continue;const U=[b/k,p/k,0],D=Math.abs(U[1])>=Math.abs(U[0])?U[1]<0&&t.bottom?"bottom":"top":U[0]>0&&t.right?"right":"left",L=d(y,-A,U,D);d(F,-A,U,D),d(F,A,U,D),d(y,A,U,D),w.push(L,L+2,L+1,L,L+3,L+2)}}return{target:"mesh",positions:Float32Array.from(x),normals:Float32Array.from(B),indices:Uint32Array.from(w),uvs:Float32Array.from(C),texture:i,size:e,pivot:n}}const sn={top:[2,!0],bottom:[2,!1],left:[0,!1],right:[0,!0],front:[1,!0],rear:[1,!1]},Me=[0,1,2];function ye(t,e){const n=t[e],r=t[e+1],o=t[e+2];return t[e+3]<128?0:n>145&&n-o>70&&r-o>20&&n-r>22?1:r>95&&o>105&&Math.min(r,o)-n>46&&o-r>-20?2:0}function pe(t){const e={},n={},r=new Map,o=new Map;for(const[i,a]of Object.entries(t)){let s=function(w,d){!h[d]||u[d]>=0||(u[d]=u[w]+1,A.set(A.subarray(w*4,w*4+3),d*4),g[C++]=d)};const{width:c,height:f,data:l}=a,h=new Uint8Array(c*f),u=new Int32Array(h.length).fill(-1),g=new Int32Array(h.length),A=new Uint8Array(l),x=[0,0,0];for(let w=0;w<h.length;w++){const d=h[w]=ye(l,w*4);d&&x[d]++}const B=h.slice();for(let w=0;w<B.length;w++){const d=B[w];if(!d)continue;const m=w%c,E=Math.floor(w/c);for(let I=-3;I<=3;I++)for(let Q=-3;Q<=3;Q++){if(Q*Q+I*I>9||m+Q<0||m+Q>=c||E+I<0||E+I>=f)continue;const M=w+I*c+Q,v=M*4;if(h[M]||l[v+3]<128)continue;const y=l[v],F=l[v+1],p=l[v+2];(d===1?y-p>12&&F-p>5&&y>=F-8:Math.min(F,p)-y>12)&&(h[M]=d)}}let C=0;for(let w=0;w<h.length;w++)h[w]||l[w*4+3]<128||(u[w]=0,g[C++]=w);for(let w=0;w<C;w++){const d=g[w],m=d%c;m>0&&s(d,d-1),m+1<c&&s(d,d+1),d>=c&&s(d,d-c),d+c<h.length&&s(d,d+c)}for(const w of[1,2]){const d=x[w]/(c*f)*(i==="front"?1.35:1);d<=(o.get(w)??0)||(o.set(w,d),r.set(w,i))}n[i]=h,e[i]={width:c,height:f,data:A}}return{clean:e,masks:n,owner:r}}function Qe(t,e,n){const r={};for(const s of n){const[c,f]=sn[s],l=Me.filter(x=>x!==c),h=e[l[0]],u=e[l[1]],g=new Int32Array(h*u).fill(-1),A=[0,0,0];for(let x=0;x<u;x++)for(let B=0;B<h;B++){A[l[0]]=B,A[l[1]]=x;for(let C=0;C<e[c];C++)if(A[c]=f?e[c]-1-C:C,!!t[(A[2]*e[1]+A[1])*e[0]+A[0]]){g[x*h+B]=A[c]+Number(f);break}}r[s]={axis:c,axes:l,width:h,height:u,values:g}}function o(s,c){return[Math.max(0,Math.min(s.width-1,Math.floor(c[s.axes[0]]))),Math.max(0,Math.min(s.height-1,Math.floor(c[s.axes[1]])))]}function i(s,c){const f=r[s];if(!f)return-1;const[l,h]=o(f,c);return f.values[h*f.width+l]}function a(s,c,f=1.5){const l=i(s,c);return l>=0&&Math.abs(l-c[sn[s][0]])<=f}return{visible:a,firstHit:i}}function ve(t,e,n,r,o,i){const{width:a,height:s,data:c}=t,f=new Uint8Array(e.length),l=new Uint8Array(e.length),h=new Uint8Array(c.length),u=[],g=[],A=[],x=[];for(let C=0;C<e.length;C++){if(e[C]!==1||l[C])continue;const w=[C],d=new Map;let m=a,E=0,I=s,Q=0;l[C]=1;for(const v of w){const y=v%a,F=Math.floor(v/a);m=Math.min(m,y),E=Math.max(E,y),I=Math.min(I,F),Q=Math.max(Q,F);const p=d.get(F)??[y,y];d.set(F,[Math.min(p[0],y),Math.max(p[1],y)]);for(const b of[y>0?v-1:-1,y+1<a?v+1:-1,v-a,v+a])e[b]!==1||l[b]||(l[b]=1,w.push(b))}if(w.length<5||E-m>a/4||Q-I>s/4)continue;const M=new Map;for(const[v,[y,F]]of d){let p=-1;for(let b=y;b<=F;b++){const k=[(b+.5)/a*n[0],0,(1-(v+.5)/s)*n[2]];p=Math.max(p,i("front",k))}p>=0&&M.set(v,p)}if(!(M.size<2)){for(const v of w)M.has(Math.floor(v/a))&&(f[v]=1,h.set(c.subarray(v*4,v*4+4),v*4));for(const[v,y]of M){const[F,p]=d.get(v),b=F/a,k=(p+1)/a,U=v/s,D=(v+1)/s,L=(b-.5)*r[0],K=(k-.5)*r[0],z=(1-U)*r[2]-o[2],S=(1-D)*r[2]-o[2],P=(.5-(y+.65)/n[1])*r[1],H=u.length/3;u.push(L,z,P,K,z,P,K,S,P,L,S,P),g.push(0,0,-1,0,0,-1,0,0,-1,0,0,-1),A.push(H,H+1,H+2,H,H+2,H+3),x.push(b,U,k,U,k,D,b,D)}}}return{mesh:A.length?{target:"mesh",size:r,pivot:o,texture:{width:a,height:s,data:h},positions:Float32Array.from(u),normals:Float32Array.from(g),indices:Uint32Array.from(A),uvs:Float32Array.from(x)}:void 0,marked:f}}const cn=Int8Array.from(atob("/////////////////////wAIA/////////////////8AAQn/////////////////AQgDCQgB/////////////wECCv////////////////8ACAMBAgr/////////////CQIKAAIJ/////////////wIIAwIKCAoJCP////////8DCwL/////////////////AAsCCAsA/////////////wEJAAIDC/////////////8BCwIBCQsJCAv/////////AwoBCwoD/////////////wAKAQAICggLCv////////8DCQADCwkLCgn/////////CQgKCggL/////////////wQHCP////////////////8EAwAHAwT/////////////AAEJCAQH/////////////wQBCQQHAQcDAf////////8BAgoIBAf/////////////AwQHAwAEAQIK/////////wkCCgkAAggEB/////////8CCgkCCQcCBwMHCQT/////CAQHAwsC/////////////wsEBwsCBAIABP////////8JAAEIBAcCAwv/////////BAcLCQQLCQsCCQIB/////wMKAQMLCgcIBP////////8BCwoBBAsBAAQHCwT/////BAcICQALCQsKCwAD/////wQHCwQLCQkLCv////////8JBQT/////////////////CQUEAAgD/////////////wAFBAEFAP////////////8IBQQIAwUDAQX/////////AQIKCQUE/////////////wMACAECCgQJBf////////8FAgoFBAIEAAL/////////AgoFAwIFAwUEAwQI/////wkFBAIDC/////////////8ACwIACAsECQX/////////AAUEAAEFAgML/////////wIBBQIFCAIICwQIBf////8KAwsKAQMJBQT/////////BAkFAAgBCAoBCAsK/////wUEAAUACwULCgsAA/////8FBAgFCAoKCAv/////////CQcIBQcJ/////////////wkDAAkFAwUHA/////////8ABwgAAQcBBQf/////////AQUDAwUH/////////////wkHCAkFBwoBAv////////8KAQIJBQAFAwAFBwP/////CAACCAIFCAUHCgUC/////wIKBQIFAwMFB/////////8HCQUHCAkDCwL/////////CQUHCQcCCQIAAgcL/////wIDCwABCAEHCAEFB/////8LAgELAQcHAQX/////////CQUICAUHCgEDCgML/////wUHAAUACQcLAAEACgsKAP8LCgALAAMKBQAIAAcFBwD/CwoFBwsF/////////////woGBf////////////////8ACAMFCgb/////////////CQABBQoG/////////////wEIAwEJCAUKBv////////8BBgUCBgH/////////////AQYFAQIGAwAI/////////wkGBQkABgACBv////////8FCQgFCAIFAgYDAgj/////AgMLCgYF/////////////wsACAsCAAoGBf////////8AAQkCAwsFCgb/////////BQoGAQkCCQsCCQgL/////wYDCwYFAwUBA/////////8ACAsACwUABQEFCwb/////AwsGAAMGAAYFAAUJ/////wYFCQYJCwsJCP////////8FCgYEBwj/////////////BAMABAcDBgUK/////////wEJAAUKBggEB/////////8KBgUBCQcBBwMHCQT/////BgECBgUBBAcI/////////wECBQUCBgMABAMEB/////8IBAcJAAUABgUAAgb/////BwMJBwkEAwIJBQkGAgYJ/wMLAgcIBAoGBf////////8FCgYEBwIEAgACBwv/////AAEJBAcIAgMLBQoG/////wkCAQkLAgkECwcLBAUKBv8IBAcDCwUDBQEFCwb/////BQELBQsGAQALBwsEAAQL/wAFCQAGBQADBgsGAwgEB/8GBQkGCQsEBwkHCwn/////CgQJBgQK/////////////wQKBgQJCgAIA/////////8KAAEKBgAGBAD/////////CAMBCAEGCAYEBgEK/////wEECQECBAIGBP////////8DAAgBAgkCBAkCBgT/////AAIEBAIG/////////////wgDAggCBAQCBv////////8KBAkKBgQLAgP/////////AAgCAggLBAkKBAoG/////wMLAgABBgAGBAYBCv////8GBAEGAQoECAECAQsICwH/CQYECQMGCQEDCwYD/////wgLAQgBAAsGAQkBBAYEAf8DCwYDBgAABgT/////////BgQICwYI/////////////wcKBgcICggJCv////////8ABwMACgcACQoGBwr/////CgYHAQoHAQcIAQgA/////woGBwoHAQEHA/////////8BAgYBBggBCAkIBgf/////AgYJAgkBBgcJAAkDBwMJ/wcIAAcABgYAAv////////8HAwIGBwL/////////////AgMLCgYICggJCAYH/////wIABwIHCwAJBwYHCgkKB/8BCAABBwgBCgcGBwoCAwv/CwIBCwEHCgYBBgcB/////wgJBggGBwkBBgsGAwEDBv8ACQELBgf/////////////BwgABwAGAwsACwYA/////wcLBv////////////////8HBgv/////////////////AwAICwcG/////////////wABCQsHBv////////////8IAQkIAwELBwb/////////CgECBgsH/////////////wECCgMACAYLB/////////8CCQACCgkGCwf/////////BgsHAgoDCggDCgkI/////wcCAwYCB/////////////8HAAgHBgAGAgD/////////AgcGAgMHAAEJ/////////wEGAgEIBgEJCAgHBv////8KBwYKAQcBAwf/////////CgcGAQcKAQgHAQAI/////wADBwAHCgAKCQYKB/////8HBgoHCggICgn/////////BggECwgG/////////////wMGCwMABgAEBv////////8IBgsIBAYJAAH/////////CQQGCQYDCQMBCwMG/////wYIBAYLCAIKAf////////8BAgoDAAsABgsABAb/////BAsIBAYLAAIJAgoJ/////woJAwoDAgkEAwsDBgQGA/8IAgMIBAIEBgL/////////AAQCBAYC/////////////wEJAAIDBAIEBgQDCP////8BCQQBBAICBAb/////////CAEDCAYBCAQGBgoB/////woBAAoABgYABP////////8EBgMEAwgGCgMAAwkKCQP/CgkEBgoE/////////////wQJBQcGC/////////////8ACAMECQULBwb/////////BQABBQQABwYL/////////wsHBggDBAMFBAMBBf////8JBQQKAQIHBgv/////////BgsHAQIKAAgDBAkF/////wcGCwUECgQCCgQAAv////8DBAgDBQQDAgUKBQILBwb/BwIDBwYCBQQJ/////////wkFBAAIBgAGAgYIB/////8DBgIDBwYBBQAFBAD/////BgIIBggHAgEIBAgFAQUI/wkFBAoBBgEHBgEDB/////8BBgoBBwYBAAcIBwAJBQT/BAAKBAoFAAMKBgoHAwcK/wcGCgcKCAUECgQICv////8GCQUGCwkLCAn/////////AwYLAAYDAAUGAAkF/////wALCAAFCwABBQUGC/////8GCwMGAwUFAwH/////////AQIKCQULCQsICwUG/////wALAwAGCwAJBgUGCQECCv8LCAULBQYIAAUKBQIAAgX/BgsDBgMFAgoDCgUD/////wUICQUCCAUGAgMIAv////8JBQYJBgAABgL/////////AQUIAQgABQYIAwgCBgII/wEFBgIBBv////////////8BAwYBBgoDCAYFBgkICQb/CgEACgAGCQUABQYA/////wADCAUGCv////////////8KBQb/////////////////CwUKBwUL/////////////wsFCgsHBQgDAP////////8FCwcFCgsBCQD/////////CgcFCgsHCQgBCAMB/////wsBAgsHAQcFAf////////8ACAMBAgcBBwUHAgv/////CQcFCQIHCQACAgsH/////wcFAgcCCwUJAgMCCAkIAv8CBQoCAwUDBwX/////////CAIACAUCCAcFCgIF/////wkAAQUKAwUDBwMKAv////8JCAIJAgEIBwIKAgUHBQL/AQMFAwcF/////////////wAIBwAHAQEHBf////////8JAAMJAwUFAwf/////////CQgHBQkH/////////////wUIBAUKCAoLCP////////8FAAQFCwAFCgsLAwD/////AAEJCAQKCAoLCgQF/////woLBAoEBQsDBAkEAQMBBP8CBQECCAUCCwgEBQj/////AAQLAAsDBAULAgsBBQEL/wACBQAFCQILBQQFCAsIBf8JBAUCCwP/////////////AgUKAwUCAwQFAwgE/////wUKAgUCBAQCAP////////8DCgIDBQoDCAUEBQgAAQn/BQoCBQIEAQkCCQQC/////wgEBQgFAwMFAf////////8ABAUBAAX/////////////CAQFCAUDCQAFAAMF/////wkEBf////////////////8ECwcECQsJCgv/////////AAgDBAkHCQsHCQoL/////wEKCwELBAEEAAcEC/////8DAQQDBAgBCgQHBAsKCwT/BAsHCQsECQILCQEC/////wkHBAkLBwkBCwILAQAIA/8LBwQLBAICBAD/////////CwcECwQCCAMEAwIE/////wIJCgIHCQIDBwcECf////8JCgcJBwQKAgcIBwACAAf/AwcKAwoCBwQKAQoABAAK/wEKAggHBP////////////8ECQEEAQcHAQP/////////BAkBBAEHAAgBCAcB/////wQAAwcEA/////////////8ECAf/////////////////CQoICgsI/////////////wMACQMJCwsJCv////////8AAQoACggICgv/////////AwEKCwMK/////////////wECCwELCQkLCP////////8DAAkDCQsBAgkCCwn/////AAILCAAL/////////////wMCC/////////////////8CAwgCCAoKCAn/////////CQoCAAkC/////////////wIDCAIICgABCAEKCP////8BCgL/////////////////AQMICQEI/////////////wAJAf////////////////8AAwj//////////////////////////////////////w=="),t=>t.charCodeAt(0)),$=[[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]],an=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]];function Ee(t,e,n){const r=Math.min(n[2]*(e[2]-2)*.042,Math.max(n[0],n[1])*1.65),o=[1,e[0],e[0]*e[1]];let i=Float32Array.from(t),a=new Float32Array(i.length);for(let s=0;s<e.length;s++){const c=Math.max(.6,Math.min(5,r/n[s])),f=Math.ceil(c*2.5),l=Array.from({length:f+1},(x,B)=>Math.exp(-B*B/(2*c*c))),h=l[0]+2*l.slice(1).reduce((x,B)=>x+B,0),u=o[s],g=e[s],A=u*g;for(let x=0;x<i.length;x+=A)for(let B=0;B<u;B++)for(let C=0;C<g;C++){const w=x+B+C*u;let d=l[0]*i[w];for(let m=1;m<=f;m++)C>=m&&(d+=l[m]*i[w-m*u]),C+m<g&&(d+=l[m]*i[w+m*u]);a[w]=d/h}[i,a]=[a,i]}return i}function fn(t,e,n,r){const o=e+2,i=n+2,a=r+2,s=o*i,c=s*a,f=new Uint8Array(c);for(let l=0;l<r;l++)for(let h=0;h<n;h++){const u=(l*n+h)*e;f.set(t.subarray(u,u+e),(l+1)*s+(h+1)*o+1)}return{nx:o,ny:i,nz:a,plane:s,count:c,occupancy:f}}function Ie(t,e,n,r,o){const{nx:i,ny:a,nz:s,plane:c,count:f,occupancy:l}=fn(t,e,n,r),h=o?Ee(l,[i,a,s],[o[0]/e,o[1]/n,o[2]/r]):new Float32Array(f);for(let d=0;d<s;d++)for(let m=0;m<a;m++)for(let E=0;E<i;E++){const I=d*c+m*i+E,Q=(E>0?l[I-1]:0)+(E+1<i?l[I+1]:0)+(m>0?l[I-i]:0)+(m+1<a?l[I+i]:0)+(d>0?l[I-c]:0)+(d+1<s?l[I+c]:0),M=l[I]*.64+Q*.06;h[I]=o?h[I]*.92+M*.08:M}const u=[0,1,i+1,i,c,c+1,c+i+1,c+i],g=new Int32Array(f*3).fill(-1),A=[],x=[],B=[];function C(d,m){return(h[d-m]??0)-(h[d+m]??0)}function w(d,m,E,I,Q){const[M,v]=an[Q],y=$[M],F=$[v],p=I+u[M],b=I+u[v],k=y[0]!==F[0]?0:y[1]!==F[1]?1:2,U=Math.min(p,b)*3+k;if(g[U]>=0)return g[U];const D=A.length/3,L=(.5-h[p])/(h[b]-h[p]);return A.push(d-.5+y[0]+(F[0]-y[0])*L,m-.5+y[1]+(F[1]-y[1])*L,E-.5+y[2]+(F[2]-y[2])*L),x.push(...[1,i,c].map(K=>C(p,K)*(1-L)+C(b,K)*L)),g[U]=D,D}for(let d=0;d<s-1;d++)for(let m=0;m<a-1;m++)for(let E=0;E<i-1;E++){const I=d*c+m*i+E;let Q=0;for(let M=0;M<8;M++)h[I+u[M]]<.5&&(Q|=1<<M);if(!(Q===0||Q===255))for(let M=Q*16;cn[M]>=0;M++)B.push(w(E,m,d,I,cn[M]))}return{positions:A,gradients:x,indices:B}}function be(t,e,n,r){const o=[e,n,r],i=[1,e,e*n],a=[],s=[],c=[],f=[[0,0],[1,0],[1,1],[0,1]];for(let l=0;l<r;l++)for(let h=0;h<n;h++)for(let u=0;u<e;u++){const g=(l*n+h)*e+u;if(!t[g])continue;const A=[u,h,l];for(let x=0;x<3;x++){const B=(x+1)%3,C=(x+2)%3;for(const w of[-1,1]){const d=A[x]+w;if(d>=0&&d<o[x]&&t[g+w*i[x]])continue;const m=[0,0,0];m[x]=w;const E=a.length/3;for(const[y,F]of f){const p=[...A];p[x]+=+(w>0),p[B]+=y,p[C]+=F,a.push(...p),s.push(...m)}const I=E,Q=E+1,M=E+2,v=E+3;w>0?c.push(I,Q,M,I,M,v):c.push(I,M,Q,I,v,M)}}}return{positions:a,gradients:s,indices:c}}function Fe(t,e,n,r){const{nx:o,ny:i,nz:a,plane:s,count:c,occupancy:f}=fn(t,e,n,r),l=[1,o,s],h=$.map(([w,d,m])=>w+o*d+s*m),u=new Int32Array(c),g=[],A=[],x=[];function B(w,d,m){const E=g[d*3]-g[w*3],I=g[d*3+1]-g[w*3+1],Q=g[d*3+2]-g[w*3+2],M=g[m*3]-g[w*3],v=g[m*3+1]-g[w*3+1],y=g[m*3+2]-g[w*3+2];return[I*y-Q*v,Q*M-E*y,E*v-I*M]}function C(w,d,m){x.push(w,d,m);const[E,I,Q]=B(w,d,m);for(const M of[w,d,m])A[M*3]+=E,A[M*3+1]+=I,A[M*3+2]+=Q}for(let w=0;w<a-1;w++)for(let d=0;d<i-1;d++)for(let m=0;m<o-1;m++){const E=w*s+d*o+m;let I=0;for(let p=0;p<8;p++)I|=f[E+h[p]]<<p;if(I===0||I===255)continue;let Q=0,M=0,v=0,y=0;for(const[p,b]of an)(I>>p&1)!==(I>>b&1)&&(Q+=($[p][0]+$[b][0])/2,M+=($[p][1]+$[b][1])/2,v+=($[p][2]+$[b][2])/2,y++);const F=g.length/3;u[E]=F,g.push(m-.5+Q/y,d-.5+M/y,w-.5+v/y),A.push(0,0,0);for(let p=0;p<3;p++){if(f[E]===f[E+l[p]])continue;const b=l[(p+1)%3],k=l[(p+2)%3],U=u[E-b],D=u[E-b-k],L=u[E-k];f[E]?(C(F,U,D),C(F,D,L)):(C(F,L,D),C(F,D,U))}}for(let w=0;w<x.length;w++){const d=x[w]*3;if(Math.abs(A[d])+Math.abs(A[d+1])+Math.abs(A[d+2])>1e-10)continue;const m=w-w%3;[A[d],A[d+1],A[d+2]]=B(x[m],x[m+1],x[m+2])}return{positions:g,gradients:A,indices:x}}const W=(t,e,n)=>Math.min(n,Math.max(e,t));function lt(t,e,n,r){switch(t){case"top":return[e,n];case"bottom":return[e,1-n];case"left":return[1-n,1-r];case"right":return[n,1-r];case"front":return[e,1-r];case"rear":return[1-e,1-r]}}function ut(t,e,n){return(W(Math.floor(n*t.height),0,t.height-1)*t.width+W(Math.floor(e*t.width),0,t.width-1))*4}function Jt(t,e,n){if(t.width===e&&t.height===n)return t;const r=new Uint8Array(e*n*4);for(let o=0;o<n;o++)for(let i=0;i<e;i++){const a=ut(t,(i+.5)/e,(o+.5)/n),s=(o*e+i)*4;for(let c=0;c<4;c++)r[s+c]=t.data[a+c]}return{width:e,height:n,data:r}}function At(t,e,n,r){const o=[Math.max(0,r),Math.max(0,-e),Math.max(0,n),Math.max(0,-n),Math.max(0,e),Math.max(0,-r)];return t.right||(o[1]=Math.abs(e)),t.bottom||(o[0]=Math.abs(r)),[...V].filter(i=>t[i]).sort((i,a)=>o[V.indexOf(a)]-o[V.indexOf(i)])}function hn(t,e){const n=t.top,r=t.front,o=t.left,i=e.layers??bt,a=e.resolution??96,s=e.height??1;if(!Number.isFinite(s)||s<=0)throw new Error("Height must be positive.");if(e.pivot&&e.pivot!=="center"&&e.pivot!=="ground")throw new Error("Pivot must be ground or center.");const c=o.width/o.height*s,[f,l,h]=e.size??[(r.width/r.height*s+c*n.width/n.height)/2,c,s];if(![f,l,h].every(B=>Number.isFinite(B)&&B>0))throw new Error("Part dimensions must be positive.");const{width:u,depth:g}=Mn(f,l,a,i),A=[f,l,h],x=[0,0,e.pivot==="center"?h/2:0];return{width:u,depth:g,layers:i,size:A,pivot:x}}function ke(t,e,n){const{width:r,depth:o,layers:i,size:a,pivot:s}=hn(t,e),c={};for(const A of V){const x=t[A];if(!x)continue;const B=A!=="top"&&A!=="bottom";c[A]=Jt(x,A==="left"||A==="right"?o:r,B?i:o)}const f=Object.entries(c),l=(A,x,B,C,w)=>x.data[ut(x,...lt(A,B,C,w))+3]>=128,h=new Uint8Array(r*o*i);let u=0;const g=e.profile==="round"||e.profile==="round-base";for(let A=0;A<i;A++)for(let x=0;x<o;x++)for(let B=0;B<r;B++){const C=(B+.5)/r,w=(x+.5)/o,d=(A+.5)/i;(t.right?f.every(([E,I])=>l(E,I,C,w,d)):l("top",c.top,C,w,d)&&l("left",c.left,C,w,d)&&(l("front",c.front,C,w,d)||l("rear",c.rear,C,w,d)))&&(h[(A*o+x)*r+B]=1,u++)}if(g){const A=r*o;for(let x=0;x<i;x++){if(e.profile==="round-base"&&(x+.5)/i<.03)continue;let B=r,C=-1,w=o,d=-1;const m=x*A;for(let E=0;E<o;E++)for(let I=0;I<r;I++)h[m+E*r+I]&&(B=Math.min(B,I),C=Math.max(C,I),w=Math.min(w,E),d=Math.max(d,E));if(!(C<B))for(let E=w;E<=d;E++)for(let I=B;I<=C;I++){if(((2*I-B-C)/(C-B+1))**2+((2*E-w-d)/(d-w+1))**2<=1)continue;const Q=m+E*r+I;u-=h[Q],h[Q]=0}}}if(!u)throw new Error("The aligned views have no common volume.");return{width:r,depth:o,layers:i,size:a,pivot:s,volume:h,aligned:c}}function ln(t,e={},n=!1){const r=new Map,o=new Map(r);let i=0,a=0;for(const[c,f]of[[t,r],[e,o]])for(const l of V){const h=c[l];if(!h)continue;const u=Math.min(1,512/Math.max(h.width,h.height)),g=Jt(h,Math.max(1,Math.round(h.width*u)),Math.max(1,Math.round(h.height*u)));f.set(l,{image:n?xe(g):g,left:i+1}),i+=g.width+2,a=Math.max(a,g.height+2)}const s=new Uint8Array(i*a*4).fill(255);for(const{image:c,left:f}of[...r.values(),...o.values()])for(let l=-1;l<=c.height;l++)for(let h=-1;h<=c.width;h++){const u=(W(l,0,c.height-1)*c.width+W(h,0,c.width-1))*4,g=((l+1)*i+f+h)*4;for(let A=0;A<3;A++)s[g+A]=c.data[u+3]>=128?c.data[u+A]:137}return{tiles:r,accents:o,texture:{width:i,height:a,data:s}}}function un(t,e,n="rgb",r="marching-cubes"){const{width:o,depth:i,layers:a,size:s,pivot:c,volume:f}=t,l={"marching-cubes":Ie,"surface-nets":Fe,voxel:be}[r],h=l(f,o,i,a,n==="depth"?s:void 0);if(!h.indices.length&&n==="depth")return un(t,e,"id");const u=new Int32Array(o*i).fill(-1),g=new Int32Array(o*i).fill(a),A=o*i;for(let p=0;p<a;p++)for(let b=0;b<A;b++)f[p*A+b]&&(u[b]=p,g[b]=Math.min(g[b],p));function x(p,b,k,U){const D=W(Math.floor(b*o),0,o-1),L=W(Math.floor(k*i),0,i-1),K=p[L*o+D];if(Math.abs(K+.5-U*a)>2)return!1;let z=0;for(const[S,P]of[[2,0],[-2,0],[0,2],[0,-2]]){const H=D+S,J=L+P;if(!(H<0||H>=o||J<0||J>=i)){if(Math.abs(p[J*o+H]-K)>(e.bottom?2:1))return!1;z++}}return z>=(e.bottom?2:3)}const B=n==="rgb"?void 0:pe(e),C={};for(const p of B?.owner.values()??[])C[p]=e[p];const w=B?Qe(f,[o,i,a],V):void 0,d=B?.owner.get(1)==="front"&&w&&e.front&&B.masks.front?ve(e.front,B.masks.front,[o,i,a],s,c,w.firstHit):void 0,{texture:m,tiles:E,accents:I}=ln(B?.clean??e,C),Q=[],M=[],v=[],y=[],F=new Map;for(let p=0;p<h.indices.length;p+=3){const b=h.indices.slice(p,p+3),k=[0,1,2].map(O=>b.reduce((j,R)=>j+h.gradients[R*3+O],0)),U=[0,1,2].map(O=>b.reduce((j,R)=>j+h.positions[R*3+O],0)),D=[U[0]/(3*o),U[1]/(3*i),U[2]/(3*a)];let L=At(e,k[0],k[1],k[2]);const K=k[2]<0&&e.bottom?"bottom":"top",z=k[2]<0?g:u,S=n==="depth"&&w&&Math.abs(k[2])*a/s[2]>1.55*Math.max(Math.abs(k[0])*o/s[0],Math.abs(k[1])*i/s[1])&&w.visible(K,U.map(O=>O/3),3);if(!S&&!x(z,D[0],D[1],D[2])){const O=k[0],j=k[1];L=Math.hypot(O,j)>.1?At(e,O,j,0):At(e,D[0]-.5,D[1]-.5,0),L=[...L.filter(R=>R!=="top"&&R!=="bottom"),K]}const P=O=>{const j=e[O];return j.data[ut(j,...lt(O,...D))+3]>=128};let H=S&&P(K)?K:L.find(P)??L[0],J=!1;if(B&&w){const O=U.map(T=>T/3),j=n==="depth"?3:1.5,R=At(e,k[0],k[1],k[2]),_=[Math.max(0,k[2]),Math.max(0,-k[0]),Math.max(0,k[1]),Math.max(0,-k[1]),Math.max(0,k[0]),Math.max(0,-k[2])],vt=Math.max(..._);for(const T of R){if(!C[T]||_[V.indexOf(T)]<=vt*.45||!w.visible(T,O,j))continue;const Et=C[T],wt=ut(Et,...lt(T,...D))/4,It=B.masks[T][wt];if(!(B.owner.get(It)!==T||T==="front"&&d?.marked[wt])){H=T,J=!0;break}}}const{image:N,left:gt}=(J?I:E).get(H);for(const O of b){const j=O*12+V.indexOf(H)+(J?6:0);let R=F.get(j);if(R===void 0){R=Q.length/3,F.set(j,R);const _=O*3,vt=h.positions[_]/o,T=h.positions[_+1]/i,Et=h.positions[_+2]/a;Q.push((vt-.5)*s[0]-c[0],Et*s[2]-c[2],(.5-T)*s[1]+c[1]);const wt=h.gradients[_]*o/s[0],It=h.gradients[_+1]*i/s[1],gn=h.gradients[_+2]*a/s[2],Pt=Math.hypot(wt,It,gn)||1;M.push(wt/Pt,gn/Pt,-It/Pt);const[Ye,Je]=lt(H,vt,T,Et);y.push((gt+.5+W(Ye,0,1)*(N.width-1))/m.width,(1.5+W(Je,0,1)*(N.height-1))/m.height)}v.push(R)}}return{target:"mesh",size:s,pivot:c,texture:m,positions:Float32Array.from(Q),normals:Float32Array.from(M),indices:Uint32Array.from(v),uvs:Float32Array.from(y),...d?.mesh&&{frontAccents:d.mesh}}}function Ue(t,e){const{width:n,depth:r,layers:o,size:i,pivot:a,volume:s}=t,c=Math.min(o,Math.max(1,Math.floor(4096/n))),f=n*c,l=r*Math.ceil(o/c),h=new Uint8Array(f*l*4),u=(B,C,w)=>+(B>=0&&B<n&&C>=0&&C<r&&w>=0&&w<o&&s[(w*r+C)*n+B]>0),g=new Int32Array(n*r).fill(-1);for(let B=0;B<o;B++)for(let C=0;C<g.length;C++)s[B*g.length+C]&&(g[C]=B);const A=Array.from({length:27},(B,C)=>At(e,C%3-1,Math.floor(C/3)%3-1,Math.floor(C/9)-1)),x=(B,C,w)=>B<0||B>=n||C<0||C>=r||Math.abs(g[C*n+B]-w)<=1;for(let B=0;B<o;B++)for(let C=0;C<r;C++)for(let w=0;w<n;w++){if(!u(w,C,B))continue;const d=u(w-1,C,B)-u(w+1,C,B),m=u(w,C-1,B)-u(w,C+1,B),E=u(w,C,B-1)-u(w,C,B+1),I=d+1+(m+1)*3+(E+1)*9,Q=((Math.floor(B/c)*r+C)*f+B%c*n+w)*4,M=g[C*n+w],v=B===M&&x(w-2,C,B)&&x(w+2,C,B)&&x(w,C-2,B)&&x(w,C+2,B),y=A[I],F=v||E<0&&e.bottom?y:A[I-E*9];let p=0,b=0,k=0,U=0;for(const D of F){if(!v&&D==="top")continue;const L=e[D],K=ut(L,...lt(D,(w+.5)/n,(C+.5)/r,(B+.5)/o));if(L.data[K+3]<128)continue;const z=L.data[K],S=L.data[K+1],P=L.data[K+2];if(p&&Math.max(Math.abs(z-b/p),Math.abs(S-k/p),Math.abs(P-U/p))>66)continue;const H=D==="front"||D==="rear"?.1+Math.abs(m):D==="left"||D==="right"?.1+Math.abs(d):.1+Math.abs(E);b+=z*H,k+=S*H,U+=P*H,p+=H}p&&(h[Q]=Math.round(b/p),h[Q+1]=Math.round(k/p),h[Q+2]=Math.round(U/p),h[Q+3]=255)}return{target:"stack",size:i,pivot:a,width:n,depth:r,layers:o,columns:c,spacing:i[2]/o,texture:{width:f,height:l,data:h}}}function De(t,e,n){let r;if(e==="mesh"&&n.meshMethod==="contour"){const{size:o,pivot:i}=hn(t,n),{tiles:a,texture:s}=ln(t,{},!0),c=t.front,f=Math.min(1,1024/Math.max(c.width,c.height)),l=Jt(c,Math.max(1,Math.round(c.width*f)),Math.max(1,Math.round(c.height*f)));r=me(t,o,i,l,a,s,n.contourHub??!1,n.resolution??96)}else{const o=ke(t,n);if(e==="stack")return Ue(o,o.aligned);r=un(o,t)}return n.textureProjection==="top-contour"&&pn(r,t.top,n.resolution??96,n.layers??bt),r}new TextEncoder,Uint32Array.from({length:256},(t,e)=>{let n=e;for(let r=0;r<8;r++)n=n>>>1^(n&1?3988292384:0);return n});function Le(t){return`function update({ dt, keys, fields, state, rotation }) {
2
+ const tracks = ${JSON.stringify(t)};
3
+ const held = (...codes) => codes.some(code => keys.includes(code));
4
+ const throttle = Number(held('KeyW', 'ArrowUp')) - Number(held('KeyS', 'ArrowDown'));
5
+ const direction = Number(held('KeyA', 'ArrowLeft')) - Number(held('KeyD', 'ArrowRight'));
6
+ const target = throttle * (throttle < 0 ? fields.reverseSpeed : fields.forwardSpeed);
7
+ const oldSpeed = state.speed ?? 0;
8
+ const speed = oldSpeed + (target - oldSpeed) * (1 - Math.exp(-fields.response * dt));
9
+ const distance = (oldSpeed + speed) * .5 * dt;
10
+ const turn = direction * fields.turnRate * dt;
11
+ const radians = Math.PI / 180;
12
+ const previous = state.yaw ?? 0;
13
+ const heading = (rotation[1] + previous + turn * .5) * radians;
14
+ const yaw = (previous + turn) % 360;
15
+ const x = (state.x ?? 0) - Math.sin(heading) * distance;
16
+ const z = (state.z ?? 0) - Math.cos(heading) * distance;
17
+ const travel = tracks.map((track, i) => (state.travel?.[i] ?? 0) + distance + turn * radians * track[1]);
18
+ return { translation: [x, 0, z], rotation: [0, yaw, 0],
19
+ childTrackTravel: Object.fromEntries(tracks.map((track, i) => [track[0], travel[i]])),
20
+ state: { speed, yaw, x, z, travel } };
21
+ }`}Le([]);const He=(t,e,n="number")=>({type:n,minimum:t,maximum:e}),et=(...t)=>({...He(...t),type:"array"});et(-1e4,1e4),et(-360,360),et(.01,100),et(-100,100),et(-720,720),et(-100,100),et(-360,360);async function An(t,e=!1,n){const r=new Uint8Array(await t.slice(0,33).arrayBuffer());dn(r);const o=await createImageBitmap(t,{colorSpaceConversion:e?"none":"default"});try{const i=new OffscreenCanvas(o.width,o.height),a=i.getContext("2d",{willReadFrequently:!0});if(!a)throw new Error("Could not decode the PNG.");a.drawImage(o,0,0);const s=a.getImageData(0,0,i.width,i.height);return{width:i.width,height:i.height,data:new Uint8Array(s.data.buffer)}}finally{o.close()}}let pt,Qt=0;async function Ke(t,e){if("atlas"in t)return Cn(await An(t.atlas),dt(t.layout),e);const n=Object.entries(t.files);return dt(n.map(([r])=>r).join(",")),Object.fromEntries(await Promise.all(n.map(async([r,o])=>[r,await An(o)])))}function Ge(t){const e=Math.min(1,256/Math.max(t.width,t.height)),n=Math.max(1,Math.round(t.width*e)),r=Math.max(1,Math.round(t.height*e)),o=new Uint8Array(n*r*4);for(let i=0;i<r;i++)for(let a=0;a<n;a++){const s=(Math.floor((i+.5)*t.height/r)*t.width+Math.floor((a+.5)*t.width/n))*4;o.set(t.data.subarray(s,s+4),(i*n+a)*4)}return{width:n,height:r,data:o}}self.onmessage=async({data:t})=>{Qt=t.id;const e=performance.now();try{let n=function(g,A){const x="parts"in i?i.parts:void 0,B=x?.map(Q=>Q.size),C=Math.max(1,...(B??[]).map(Q=>Q?.[2]??1)),w=Math.max(1,...(B??[]).map(Q=>Q?Math.max(Q[0],Q[1]):1)),d=l.map((Q,M)=>{const v=B?.[M];return De(Q,a,v?{...g,size:v,pivot:"ground",layers:Math.max(8,Math.round((g.layers??bt)*v[2]/C)),resolution:Math.max(16,Math.round((g.resolution??96)*Math.max(v[0],v[1])/w))}:g)}),m=d.flatMap(Q=>(Q.target==="mesh"?[Q.texture.data,Q.positions,Q.normals,Q.indices,Q.uvs]:[Q.texture.data]).map(M=>M.buffer)),E=t.keepTop&&l[0].top?Ge(l[0].top):void 0;E&&m.push(E.data.buffer);const I={id:r,result:d[0],parts:x?d:void 0,top:E,inspection:u,preview:A,elapsed:performance.now()-e};self.postMessage(I,m)};const{id:r,sourceKey:o,source:i,target:a,settings:s,preview:c}=t,f=JSON.stringify([o,s.threshold]);if(pt?.key!==f){const g="parts"in i?i.parts:[i],A=Promise.all(g.map(async x=>Bn(await Ke(x,s.threshold),s.threshold)));pt={key:f,views:A}}const l=await pt.views;if(r!==Qt)return;const h=l.map(mn),u={...h[0],warnings:[...new Set(h.flatMap(g=>g.warnings))]};if(c){try{n(c,!0)}catch{}await new Promise(g=>setTimeout(g,0))}r===Qt&&n(s,!1)}catch(n){t.id===Qt&&(pt=void 0,self.postMessage({id:t.id,error:n instanceof Error?n.message:String(n)}))}}})();
@@ -1,4 +1,4 @@
1
- import{_ as k}from"./preview-cache-DRF_H5pq.js";import"./style-CWGgpweN.js";var S={JS_EVAL_TYPE_GLOBAL:0,JS_EVAL_TYPE_MODULE:1,JS_EVAL_FLAG_STRICT:8,JS_EVAL_FLAG_STRIP:16,JS_EVAL_FLAG_COMPILE_ONLY:32,JS_EVAL_FLAG_BACKTRACE_BARRIER:64},V={BaseObjects:1,Date:2,Eval:4,StringNormalize:8,RegExp:16,RegExpCompiler:32,JSON:64,Proxy:128,MapSet:256,TypedArrays:512,Promise:1024,BigInt:2048,BigFloat:4096,BigDecimal:8192,OperatorOverloading:16384,BignumExt:32768},T={Pending:0,Fulfilled:1,Rejected:2},g={JS_GPN_STRING_MASK:1,JS_GPN_SYMBOL_MASK:2,JS_GPN_PRIVATE_MASK:4,JS_GPN_ENUM_ONLY:16,QTS_GPN_NUMBER_MASK:64,QTS_STANDARD_COMPLIANT_NUMBER:128},x={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2},ue=Object.defineProperty,le=(e,t)=>{for(var r in t)ue(e,r,{get:t[r],enumerable:!0})};function b(...e){}var he={};le(he,{QuickJSAsyncifyError:()=>q,QuickJSAsyncifySuspended:()=>K,QuickJSEmptyGetOwnPropertyNames:()=>X,QuickJSEmscriptenModuleError:()=>L,QuickJSHostRefInvalid:()=>y,QuickJSHostRefRangeExceeded:()=>ee,QuickJSMemoryLeakDetected:()=>ce,QuickJSNotImplemented:()=>z,QuickJSPromisePending:()=>Z,QuickJSUnknownIntrinsic:()=>Y,QuickJSUnwrapError:()=>R,QuickJSUseAfterFree:()=>J,QuickJSWrongOwner:()=>W});var R=class extends Error{constructor(e,t){let r=typeof e=="object"&&e&&"message"in e?String(e.message):String(e);super(r),this.cause=e,this.context=t,this.name="QuickJSUnwrapError"}},W=class extends Error{constructor(){super(...arguments),this.name="QuickJSWrongOwner"}},J=class extends Error{constructor(){super(...arguments),this.name="QuickJSUseAfterFree"}},z=class extends Error{constructor(){super(...arguments),this.name="QuickJSNotImplemented"}},q=class extends Error{constructor(){super(...arguments),this.name="QuickJSAsyncifyError"}},K=class extends Error{constructor(){super(...arguments),this.name="QuickJSAsyncifySuspended"}},ce=class extends Error{constructor(){super(...arguments),this.name="QuickJSMemoryLeakDetected"}},L=class extends Error{constructor(){super(...arguments),this.name="QuickJSEmscriptenModuleError"}},Y=class extends TypeError{constructor(){super(...arguments),this.name="QuickJSUnknownIntrinsic"}},Z=class extends Error{constructor(){super(...arguments),this.name="QuickJSPromisePending"}},X=class extends Error{constructor(){super(...arguments),this.name="QuickJSEmptyGetOwnPropertyNames"}},ee=class extends Error{constructor(){super(...arguments),this.name="QuickJSHostRefRangeExceeded"}},y=class extends Error{constructor(){super(...arguments),this.name="QuickJSHostRefInvalid"}};function*te(e){return yield e}function me(e){return te(O(e))}var I=te;I.of=me;function B(e,t){return(...r)=>{let i=t.call(e,I,...r);return O(i)}}function de(e,t){let r=t.call(e,I);return O(r)}function O(e){function t(r){return r.done?r.value:r.value instanceof Promise?r.value.then(i=>t(e.next(i)),i=>t(e.throw(i))):t(e.next(r.value))}return t(e.next())}var w=class{[Symbol.dispose](){return this.dispose()}},C=Symbol.dispose??Symbol.for("Symbol.dispose"),j=w.prototype;j[C]||(j[C]=function(){return this.dispose()});var c=class re extends w{constructor(t,r,i,s){super(),this._value=t,this.copier=r,this.disposer=i,this._owner=s,this._alive=!0,this._constructorStack=void 0}get alive(){return this._alive}get value(){return this.assertAlive(),this._value}get owner(){return this._owner}get dupable(){return!!this.copier}dup(){if(this.assertAlive(),!this.copier)throw new Error("Non-dupable lifetime");return new re(this.copier(this._value),this.copier,this.disposer,this._owner)}consume(t){this.assertAlive();let r=t(this);return this.dispose(),r}map(t){return this.assertAlive(),t(this)}tap(t){return t(this),this}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new J(`Lifetime not alive
1
+ import{_ as k}from"./preview-cache-BKV0EZl9.js";import"./style-D6eZHs3D.js";var S={JS_EVAL_TYPE_GLOBAL:0,JS_EVAL_TYPE_MODULE:1,JS_EVAL_FLAG_STRICT:8,JS_EVAL_FLAG_STRIP:16,JS_EVAL_FLAG_COMPILE_ONLY:32,JS_EVAL_FLAG_BACKTRACE_BARRIER:64},V={BaseObjects:1,Date:2,Eval:4,StringNormalize:8,RegExp:16,RegExpCompiler:32,JSON:64,Proxy:128,MapSet:256,TypedArrays:512,Promise:1024,BigInt:2048,BigFloat:4096,BigDecimal:8192,OperatorOverloading:16384,BignumExt:32768},T={Pending:0,Fulfilled:1,Rejected:2},g={JS_GPN_STRING_MASK:1,JS_GPN_SYMBOL_MASK:2,JS_GPN_PRIVATE_MASK:4,JS_GPN_ENUM_ONLY:16,QTS_GPN_NUMBER_MASK:64,QTS_STANDARD_COMPLIANT_NUMBER:128},x={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2},ue=Object.defineProperty,le=(e,t)=>{for(var r in t)ue(e,r,{get:t[r],enumerable:!0})};function b(...e){}var he={};le(he,{QuickJSAsyncifyError:()=>q,QuickJSAsyncifySuspended:()=>K,QuickJSEmptyGetOwnPropertyNames:()=>X,QuickJSEmscriptenModuleError:()=>L,QuickJSHostRefInvalid:()=>y,QuickJSHostRefRangeExceeded:()=>ee,QuickJSMemoryLeakDetected:()=>ce,QuickJSNotImplemented:()=>z,QuickJSPromisePending:()=>Z,QuickJSUnknownIntrinsic:()=>Y,QuickJSUnwrapError:()=>R,QuickJSUseAfterFree:()=>J,QuickJSWrongOwner:()=>W});var R=class extends Error{constructor(e,t){let r=typeof e=="object"&&e&&"message"in e?String(e.message):String(e);super(r),this.cause=e,this.context=t,this.name="QuickJSUnwrapError"}},W=class extends Error{constructor(){super(...arguments),this.name="QuickJSWrongOwner"}},J=class extends Error{constructor(){super(...arguments),this.name="QuickJSUseAfterFree"}},z=class extends Error{constructor(){super(...arguments),this.name="QuickJSNotImplemented"}},q=class extends Error{constructor(){super(...arguments),this.name="QuickJSAsyncifyError"}},K=class extends Error{constructor(){super(...arguments),this.name="QuickJSAsyncifySuspended"}},ce=class extends Error{constructor(){super(...arguments),this.name="QuickJSMemoryLeakDetected"}},L=class extends Error{constructor(){super(...arguments),this.name="QuickJSEmscriptenModuleError"}},Y=class extends TypeError{constructor(){super(...arguments),this.name="QuickJSUnknownIntrinsic"}},Z=class extends Error{constructor(){super(...arguments),this.name="QuickJSPromisePending"}},X=class extends Error{constructor(){super(...arguments),this.name="QuickJSEmptyGetOwnPropertyNames"}},ee=class extends Error{constructor(){super(...arguments),this.name="QuickJSHostRefRangeExceeded"}},y=class extends Error{constructor(){super(...arguments),this.name="QuickJSHostRefInvalid"}};function*te(e){return yield e}function me(e){return te(O(e))}var I=te;I.of=me;function B(e,t){return(...r)=>{let i=t.call(e,I,...r);return O(i)}}function de(e,t){let r=t.call(e,I);return O(r)}function O(e){function t(r){return r.done?r.value:r.value instanceof Promise?r.value.then(i=>t(e.next(i)),i=>t(e.throw(i))):t(e.next(r.value))}return t(e.next())}var w=class{[Symbol.dispose](){return this.dispose()}},C=Symbol.dispose??Symbol.for("Symbol.dispose"),j=w.prototype;j[C]||(j[C]=function(){return this.dispose()});var c=class re extends w{constructor(t,r,i,s){super(),this._value=t,this.copier=r,this.disposer=i,this._owner=s,this._alive=!0,this._constructorStack=void 0}get alive(){return this._alive}get value(){return this.assertAlive(),this._value}get owner(){return this._owner}get dupable(){return!!this.copier}dup(){if(this.assertAlive(),!this.copier)throw new Error("Non-dupable lifetime");return new re(this.copier(this._value),this.copier,this.disposer,this._owner)}consume(t){this.assertAlive();let r=t(this);return this.dispose(),r}map(t){return this.assertAlive(),t(this)}tap(t){return t(this),this}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new J(`Lifetime not alive
2
2
  ${this._constructorStack}
3
3
  Lifetime used`):new J("Lifetime not alive")}},v=class extends c{constructor(e,t){super(e,void 0,void 0,t)}get dupable(){return!0}dup(){return this}dispose(){}},G=class extends c{constructor(e,t,r,i){super(e,t,r,i)}dispose(){this._alive=!1}};function Q(e,t){let r;try{e.dispose()}catch(i){r=i}if(t&&r)throw Object.assign(t,{message:`${t.message}
4
4
  Then, failed to dispose scope: ${r.message}`,disposeError:r}),t;if(t||r)throw t||r}var d=class P extends w{constructor(){super(...arguments),this._disposables=new c(new Set),this.manage=t=>(this._disposables.value.add(t),t)}static withScope(t){let r=new P,i;try{return t(r)}catch(s){throw i=s,s}finally{Q(r,i)}}static withScopeMaybeAsync(t,r){return de(void 0,function*(i){let s=new P,n;try{return yield*i.of(r.call(t,i,s))}catch(o){throw n=o,o}finally{Q(s,n)}})}static async withScopeAsync(t){let r=new P,i;try{return await t(r)}catch(s){throw i=s,s}finally{Q(r,i)}}get alive(){return this._disposables.alive}dispose(){let t=Array.from(this._disposables.value.values()).reverse();for(let r of t)r.alive&&r.dispose();this._disposables.dispose()}};function fe(e){let t=e?Array.from(e):[];function r(){return t.forEach(s=>s.alive?s.dispose():void 0)}function i(){return t.some(s=>s.alive)}return Object.defineProperty(t,C,{configurable:!0,enumerable:!1,value:r}),Object.defineProperty(t,"dispose",{configurable:!0,enumerable:!1,value:r}),Object.defineProperty(t,"alive",{configurable:!0,enumerable:!1,get:i}),t}function A(e){return!!(e&&(typeof e=="object"||typeof e=="function")&&"alive"in e&&typeof e.alive=="boolean"&&"dispose"in e&&typeof e.dispose=="function")}var F=class ie extends w{static success(t){return new pe(t)}static fail(t,r){return new we(t,r)}static is(t){return t instanceof ie}},pe=class extends F{constructor(e){super(),this.value=e}get alive(){return A(this.value)?this.value.alive:!0}dispose(){A(this.value)&&this.value.dispose()}unwrap(){return this.value}unwrapOr(e){return this.value}},we=class extends F{constructor(e,t){super(),this.error=e,this.onUnwrap=t}get alive(){return A(this.error)?this.error.alive:!0}dispose(){A(this.error)&&this.error.dispose()}unwrap(){throw this.onUnwrap(this),this.error}unwrapOr(e){return e}},_=F,ye=class extends w{constructor(e){super(),this.resolve=t=>{this.resolveHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.resolveHandle,this.context.undefined,t||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.reject=t=>{this.rejectHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.rejectHandle,this.context.undefined,t||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.dispose=()=>{this.handle.alive&&this.handle.dispose(),this.disposeResolvers()},this.context=e.context,this.owner=e.context.runtime,this.handle=e.promiseHandle,this.settled=new Promise(t=>{this.onSettled=t}),this.resolveHandle=e.resolveHandle,this.rejectHandle=e.rejectHandle}get alive(){return this.handle.alive||this.resolveHandle.alive||this.rejectHandle.alive}disposeResolvers(){this.resolveHandle.alive&&this.resolveHandle.dispose(),this.rejectHandle.alive&&this.rejectHandle.dispose()}},se=class{constructor(e){this.module=e}toPointerArray(e){let t=new Int32Array(e.map(s=>s.value)),r=t.length*t.BYTES_PER_ELEMENT,i=this.module._malloc(r);return new Uint8Array(this.module.HEAPU8.buffer,i,r).set(new Uint8Array(t.buffer)),new c(i,void 0,s=>this.module._free(s))}newTypedArray(e,t){let r=new e(new Array(t).fill(0)),i=r.length*r.BYTES_PER_ELEMENT,s=this.module._malloc(i),n=new e(this.module.HEAPU8.buffer,s,t);return n.set(r),new c({typedArray:n,ptr:s},void 0,o=>this.module._free(o.ptr))}newMutablePointerArray(e){return this.newTypedArray(Int32Array,e)}newHeapCharPointer(e){let t=this.module.lengthBytesUTF8(e),r=t+1,i=this.module._malloc(r);return this.module.stringToUTF8(e,i,r),new c({ptr:i,strlen:t},void 0,s=>this.module._free(s.ptr))}newHeapBufferPointer(e){let t=e.byteLength,r=this.module._malloc(t);return this.module.HEAPU8.set(e,r),new c({pointer:r,numBytes:t},void 0,i=>this.module._free(i.pointer))}consumeHeapCharPointer(e){let t=this.module.UTF8ToString(e);return this.module._free(e),t}};function ve(e){if(!e)return 0;let t=0;for(let[r,i]of Object.entries(e)){if(!(r in V))throw new Y(r);i&&(t|=V[r])}return t}function Se(e){if(typeof e=="number")return e;if(e===void 0)return 0;let{type:t,strict:r,strip:i,compileOnly:s,backtraceBarrier:n}=e,o=0;return t==="global"&&(o|=S.JS_EVAL_TYPE_GLOBAL),t==="module"&&(o|=S.JS_EVAL_TYPE_MODULE),r&&(o|=S.JS_EVAL_FLAG_STRICT),i&&(o|=S.JS_EVAL_FLAG_STRIP),s&&(o|=S.JS_EVAL_FLAG_COMPILE_ONLY),n&&(o|=S.JS_EVAL_FLAG_BACKTRACE_BARRIER),o}function ge(e){if(typeof e=="number")return e;if(e===void 0)return 0;let{strings:t,symbols:r,quickjsPrivate:i,onlyEnumerable:s,numbers:n,numbersAsStrings:o}=e,a=0;return t&&(a|=g.JS_GPN_STRING_MASK),r&&(a|=g.JS_GPN_SYMBOL_MASK),i&&(a|=g.JS_GPN_PRIVATE_MASK),s&&(a|=g.JS_GPN_ENUM_ONLY),n&&(a|=g.QTS_GPN_NUMBER_MASK),o&&(a|=g.QTS_STANDARD_COMPLIANT_NUMBER),a}function _e(...e){let t=[];for(let r of e)r!==void 0&&(t=t.concat(r));return t}var be=class extends w{constructor(e,t){super(),this.handle=e,this.context=t,this._isDone=!1,this.owner=t.runtime}[Symbol.iterator](){return this}next(e){if(!this.alive||this._isDone)return{done:!0,value:void 0};let t=this._next??(this._next=this.context.getProp(this.handle,"next"));return this.callIteratorMethod(t,e)}return(e){if(!this.alive)return{done:!0,value:void 0};let t=this.context.getProp(this.handle,"return");if(t===this.context.undefined&&e===void 0)return this.dispose(),{done:!0,value:void 0};let r=this.callIteratorMethod(t,e);return t.dispose(),this.dispose(),r}throw(e){if(!this.alive)return{done:!0,value:void 0};let t=e instanceof c?e:this.context.newError(e),r=this.context.getProp(this.handle,"throw"),i=this.callIteratorMethod(r,e);return t.alive&&t.dispose(),r.dispose(),this.dispose(),i}get alive(){return this.handle.alive}dispose(){this._isDone=!0,this.handle.dispose(),this._next?.dispose()}callIteratorMethod(e,t){let r=t?this.context.callFunction(e,this.handle,t):this.context.callFunction(e,this.handle);if(r.error)return this.dispose(),{value:r};let i=this.context.getProp(r.value,"done").consume(n=>this.context.dump(n)),s=this.context.getProp(r.value,"value");return r.value.dispose(),i&&this.dispose(),{value:_.success(s),done:i}}},D=-2147483648,U=2147483647,M=0;function H(e){return e>>8}var xe=class{constructor(){this.nextId=D,this.freelist=[],this.groups=new Map}put(e){let t=this.allocateId(),r=H(t),i=this.groups.get(r);return i||(i=new Map,this.groups.set(r,i)),i.set(t,e),t}get(e){if(e===M)throw new y("no host reference id defined");let t=H(e),r=this.groups.get(t);if(!r)throw new y(`host reference id ${e} is not defined`);let i=r.get(e);if(!i)throw new y(`host reference id ${e} is not defined`);return i}delete(e){if(e===M)throw new y("no host reference id defined");let t=H(e),r=this.groups.get(t);if(!r)throw new y(`host reference id ${e} is not defined`);r.delete(e),r.size===0&&this.groups.delete(t),this.freelist.push(e)}allocateId(){if(this.freelist.length>0)return this.freelist.shift();if(this.nextId===M&&this.nextId++,this.nextId>U)throw new ee(`HostRefMap: too many host refs created without disposing. Max simultaneous host refs: ${U-D}`);return this.nextId++}},$=class extends w{constructor(e,t,r){if(r===M)throw new y("cannot create HostRef with undefined id");super(),this.runtime=e,this.handle=t,this.id=r}get alive(){return this.handle.alive}dispose(){this.handle.dispose()}get value(){return this.runtime.hostRefs.get(this.id)}},Pe=class extends se{constructor(e){super(e.module),this.scope=new d,this.copyJSValue=t=>this.ffi.QTS_DupValuePointer(this.ctx.value,t),this.freeJSValue=t=>{this.ffi.QTS_FreeValuePointer(this.ctx.value,t)},e.ownedLifetimes?.forEach(t=>this.scope.manage(t)),this.owner=e.owner,this.module=e.module,this.ffi=e.ffi,this.rt=e.rt,this.ctx=this.scope.manage(e.ctx)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}[Symbol.dispose](){return this.dispose()}manage(e){return this.scope.manage(e)}consumeJSCharPointer(e){let t=this.module.UTF8ToString(e);return this.ffi.QTS_FreeCString(this.ctx.value,e),t}heapValueHandle(e,t){let r=t?i=>{t(),this.freeJSValue(i)}:this.freeJSValue;return new c(e,this.copyJSValue,r,this.owner)}staticHeapValueHandle(e){return this.manage(this.heapValueHandle(e)),new v(e,this.owner)}},Me=class extends w{constructor(e){super(),this._undefined=void 0,this._null=void 0,this._false=void 0,this._true=void 0,this._global=void 0,this._BigInt=void 0,this._Symbol=void 0,this._SymbolIterator=void 0,this._SymbolAsyncIterator=void 0,this.cToHostCallbacks={callFunction:(t,r,i,s,n)=>{if(t!==this.ctx.value)throw new Error("QuickJSContext instance received C -> JS call with mismatched ctx");let o=this.getFunction(n);return d.withScopeMaybeAsync(this,function*(a,l){let f=l.manage(new G(r,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime)),m=new Array(i);for(let u=0;u<i;u++){let h=this.ffi.QTS_ArgvGetJSValueConstPointer(s,u);m[u]=l.manage(new G(h,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime))}try{let u=yield*a(o.apply(f,m));if(u){if("error"in u&&u.error)throw this.runtime.debugLog("throw error",u.error),u.error;let h=l.manage(u instanceof c?u:u.value);return this.ffi.QTS_DupValuePointer(this.ctx.value,h.value)}return 0}catch(u){return this.errorToHandle(u).consume(h=>this.ffi.QTS_Throw(this.ctx.value,h.value))}})}},this.runtime=e.runtime,this.module=e.module,this.ffi=e.ffi,this.rt=e.rt,this.ctx=e.ctx,this.memory=new Pe({...e,owner:this.runtime}),e.callbacks.setContextCallbacks(this.ctx.value,this.cToHostCallbacks),this.dump=this.dump.bind(this),this.getString=this.getString.bind(this),this.getNumber=this.getNumber.bind(this),this.resolvePromise=this.resolvePromise.bind(this),this.uint32Out=this.memory.manage(this.memory.newTypedArray(Uint32Array,1))}get alive(){return this.memory.alive}dispose(){this.memory.dispose()}get undefined(){if(this._undefined)return this._undefined;let e=this.ffi.QTS_GetUndefined();return this._undefined=new v(e)}get null(){if(this._null)return this._null;let e=this.ffi.QTS_GetNull();return this._null=new v(e)}get true(){if(this._true)return this._true;let e=this.ffi.QTS_GetTrue();return this._true=new v(e)}get false(){if(this._false)return this._false;let e=this.ffi.QTS_GetFalse();return this._false=new v(e)}get global(){if(this._global)return this._global;let e=this.ffi.QTS_GetGlobalObject(this.ctx.value);return this._global=this.memory.staticHeapValueHandle(e),this._global}newNumber(e){return this.memory.heapValueHandle(this.ffi.QTS_NewFloat64(this.ctx.value,e))}newString(e){let t=this.memory.newHeapCharPointer(e).consume(r=>this.ffi.QTS_NewString(this.ctx.value,r.value.ptr));return this.memory.heapValueHandle(t)}newUniqueSymbol(e){let t=(typeof e=="symbol"?e.description:e)??"",r=this.memory.newHeapCharPointer(t).consume(i=>this.ffi.QTS_NewSymbol(this.ctx.value,i.value.ptr,0));return this.memory.heapValueHandle(r)}newSymbolFor(e){let t=(typeof e=="symbol"?e.description:e)??"",r=this.memory.newHeapCharPointer(t).consume(i=>this.ffi.QTS_NewSymbol(this.ctx.value,i.value.ptr,1));return this.memory.heapValueHandle(r)}getWellKnownSymbol(e){return this._Symbol??(this._Symbol=this.memory.manage(this.getProp(this.global,"Symbol"))),this.getProp(this._Symbol,e)}newBigInt(e){if(!this._BigInt){let i=this.getProp(this.global,"BigInt");this.memory.manage(i),this._BigInt=new v(i.value,this.runtime)}let t=this._BigInt,r=String(e);return this.newString(r).consume(i=>this.unwrapResult(this.callFunction(t,this.undefined,i)))}newObject(e){e&&this.runtime.assertOwned(e);let t=e?this.ffi.QTS_NewObjectProto(this.ctx.value,e.value):this.ffi.QTS_NewObject(this.ctx.value);return this.memory.heapValueHandle(t)}newArray(){let e=this.ffi.QTS_NewArray(this.ctx.value);return this.memory.heapValueHandle(e)}newArrayBuffer(e){let t=new Uint8Array(e),r=this.memory.newHeapBufferPointer(t),i=this.ffi.QTS_NewArrayBuffer(this.ctx.value,r.value.pointer,t.length);return this.memory.heapValueHandle(i)}newPromise(e){let t=d.withScope(r=>{let i=r.manage(this.memory.newMutablePointerArray(2)),s=this.ffi.QTS_NewPromiseCapability(this.ctx.value,i.value.ptr),n=this.memory.heapValueHandle(s),[o,a]=Array.from(i.value.typedArray).map(l=>this.memory.heapValueHandle(l));return new ye({context:this,promiseHandle:n,resolveHandle:o,rejectHandle:a})});return e&&typeof e=="function"&&(e=new Promise(e)),e&&Promise.resolve(e).then(t.resolve,r=>r instanceof c?t.reject(r):this.newError(r).consume(t.reject)),t}newFunction(e,t){let r=typeof e=="function"?e:t;if(!r)throw new TypeError("Expected a function");return this.newFunctionWithOptions({name:typeof e=="string"?e:void 0,length:r.length,isConstructor:!1,fn:r})}newConstructorFunction(e,t){let r=typeof e=="function"?e:t;if(!r)throw new TypeError("Expected a function");return this.newFunctionWithOptions({name:typeof e=="string"?e:void 0,length:r.length,isConstructor:!0,fn:r})}newFunctionWithOptions(e){let{name:t,length:r,isConstructor:i,fn:s}=e,n=this.runtime.hostRefs.put(s);try{return this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value,t??"",r,i,n))}catch(o){throw this.runtime.hostRefs.delete(n),o}}newError(e){let t=this.memory.heapValueHandle(this.ffi.QTS_NewError(this.ctx.value));return e&&typeof e=="object"?(e.name!==void 0&&this.newString(e.name).consume(r=>this.setProp(t,"name",r)),e.message!==void 0&&this.newString(e.message).consume(r=>this.setProp(t,"message",r))):typeof e=="string"?this.newString(e).consume(r=>this.setProp(t,"message",r)):e!==void 0&&this.newString(String(e)).consume(r=>this.setProp(t,"message",r)),t}newHostRef(e){let t=this.runtime.hostRefs.put(e);try{let r=this.memory.heapValueHandle(this.ffi.QTS_NewHostRef(this.ctx.value,t));return new $(this.runtime,r,t)}catch(r){throw this.runtime.hostRefs.delete(t),r}}toHostRef(e){let t=this.ffi.QTS_GetHostRefId(e.value);if(t!==0)return this.runtime.hostRefs.get(t),new $(this.runtime,e.dup(),t)}unwrapHostRef(e){let t=this.ffi.QTS_GetHostRefId(e.value);if(t===0)throw new y("handle is not a HostRef");return this.runtime.hostRefs.get(t)}typeof(e){return this.runtime.assertOwned(e),this.memory.consumeHeapCharPointer(this.ffi.QTS_Typeof(this.ctx.value,e.value))}getNumber(e){return this.runtime.assertOwned(e),this.ffi.QTS_GetFloat64(this.ctx.value,e.value)}getString(e){return this.runtime.assertOwned(e),this.memory.consumeJSCharPointer(this.ffi.QTS_GetString(this.ctx.value,e.value))}getSymbol(e){this.runtime.assertOwned(e);let t=this.memory.consumeJSCharPointer(this.ffi.QTS_GetSymbolDescriptionOrKey(this.ctx.value,e.value));return this.ffi.QTS_IsGlobalSymbol(this.ctx.value,e.value)?Symbol.for(t):Symbol(t)}getBigInt(e){this.runtime.assertOwned(e);let t=this.getString(e);return BigInt(t)}getArrayBuffer(e){this.runtime.assertOwned(e);let t=this.ffi.QTS_GetArrayBufferLength(this.ctx.value,e.value),r=this.ffi.QTS_GetArrayBuffer(this.ctx.value,e.value);if(!r)throw new Error("Couldn't allocate memory to get ArrayBuffer");return new c(this.module.HEAPU8.subarray(r,r+t),void 0,()=>this.module._free(r))}getPromiseState(e){this.runtime.assertOwned(e);let t=this.ffi.QTS_PromiseState(this.ctx.value,e.value);if(t<0)return{type:"fulfilled",value:e,notAPromise:!0};if(t===T.Pending)return{type:"pending",get error(){return new Z("Cannot unwrap a pending promise")}};let r=this.ffi.QTS_PromiseResult(this.ctx.value,e.value),i=this.memory.heapValueHandle(r);if(t===T.Fulfilled)return{type:"fulfilled",value:i};if(t===T.Rejected)return{type:"rejected",error:i};throw i.dispose(),new Error(`Unknown JSPromiseStateEnum: ${t}`)}resolvePromise(e){this.runtime.assertOwned(e);let t=d.withScope(r=>{let i=r.manage(this.getProp(this.global,"Promise")),s=r.manage(this.getProp(i,"resolve"));return this.callFunction(s,i,e)});return t.error?Promise.resolve(t):new Promise(r=>{d.withScope(i=>{let s=i.manage(this.newFunction("resolve",l=>{r(this.success(l&&l.dup()))})),n=i.manage(this.newFunction("reject",l=>{r(this.fail(l&&l.dup()))})),o=i.manage(t.value),a=i.manage(this.getProp(o,"then"));this.callFunction(a,o,s,n).unwrap().dispose()})})}isEqual(e,t,r=x.IsStrictlyEqual){if(e===t)return!0;this.runtime.assertOwned(e),this.runtime.assertOwned(t);let i=this.ffi.QTS_IsEqual(this.ctx.value,e.value,t.value,r);if(i===-1)throw new z("WASM variant does not expose equality");return!!i}eq(e,t){return this.isEqual(e,t,x.IsStrictlyEqual)}sameValue(e,t){return this.isEqual(e,t,x.IsSameValue)}sameValueZero(e,t){return this.isEqual(e,t,x.IsSameValueZero)}getProp(e,t){this.runtime.assertOwned(e);let r;return typeof t=="number"&&t>=0?r=this.ffi.QTS_GetPropNumber(this.ctx.value,e.value,t):r=this.borrowPropertyKey(t).consume(i=>this.ffi.QTS_GetProp(this.ctx.value,e.value,i.value)),this.memory.heapValueHandle(r)}getLength(e){if(this.runtime.assertOwned(e),!(this.ffi.QTS_GetLength(this.ctx.value,this.uint32Out.value.ptr,e.value)<0))return this.uint32Out.value.typedArray[0]}getOwnPropertyNames(e,t={strings:!0,numbersAsStrings:!0}){this.runtime.assertOwned(e),e.value;let r=ge(t);if(r===0)throw new X("No options set, will return an empty array");return d.withScope(i=>{let s=i.manage(this.memory.newMutablePointerArray(1)),n=this.ffi.QTS_GetOwnPropertyNames(this.ctx.value,s.value.ptr,this.uint32Out.value.ptr,e.value,r);if(n)return this.fail(this.memory.heapValueHandle(n));let o=this.uint32Out.value.typedArray[0],a=s.value.typedArray[0],l=new Uint32Array(this.module.HEAP8.buffer,a,o),f=Array.from(l).map(m=>this.memory.heapValueHandle(m));return this.ffi.QTS_FreeVoidPointer(this.ctx.value,a),this.success(fe(f))})}getIterator(e){let t=this._SymbolIterator??(this._SymbolIterator=this.memory.manage(this.getWellKnownSymbol("iterator")));return d.withScope(r=>{let i=r.manage(this.getProp(e,t)),s=this.callFunction(i,e);return s.error?s:this.success(new be(s.value,this))})}setProp(e,t,r){this.runtime.assertOwned(e),this.borrowPropertyKey(t).consume(i=>this.ffi.QTS_SetProp(this.ctx.value,e.value,i.value,r.value))}defineProp(e,t,r){this.runtime.assertOwned(e),d.withScope(i=>{let s=i.manage(this.borrowPropertyKey(t)),n=r.value||this.undefined,o=!!r.configurable,a=!!r.enumerable,l=!!r.value,f=r.get?i.manage(this.newFunction(r.get.name,r.get)):this.undefined,m=r.set?i.manage(this.newFunction(r.set.name,r.set)):this.undefined;this.ffi.QTS_DefineProp(this.ctx.value,e.value,s.value,n.value,f.value,m.value,o,a,l)})}callFunction(e,t,...r){this.runtime.assertOwned(e);let i,s=r[0];s===void 0||Array.isArray(s)?i=s??[]:i=r;let n=this.memory.toPointerArray(i).consume(a=>this.ffi.QTS_Call(this.ctx.value,e.value,t.value,i.length,a.value)),o=this.ffi.QTS_ResolveException(this.ctx.value,n);return o?(this.ffi.QTS_FreeValuePointer(this.ctx.value,n),this.fail(this.memory.heapValueHandle(o))):this.success(this.memory.heapValueHandle(n))}callMethod(e,t,r=[]){return this.getProp(e,t).consume(i=>this.callFunction(i,e,r))}evalCode(e,t="eval.js",r){let i=r===void 0?1:0,s=Se(r),n=this.memory.newHeapCharPointer(e).consume(a=>this.ffi.QTS_Eval(this.ctx.value,a.value.ptr,a.value.strlen,t,i,s)),o=this.ffi.QTS_ResolveException(this.ctx.value,n);return o?(this.ffi.QTS_FreeValuePointer(this.ctx.value,n),this.fail(this.memory.heapValueHandle(o))):this.success(this.memory.heapValueHandle(n))}throw(e){return this.errorToHandle(e).consume(t=>this.ffi.QTS_Throw(this.ctx.value,t.value))}borrowPropertyKey(e){return typeof e=="number"?this.newNumber(e):typeof e=="string"?this.newString(e):new v(e.value,this.runtime)}getMemory(e){if(e===this.rt.value)return this.memory;throw new Error("Private API. Cannot get memory from a different runtime")}dump(e){this.runtime.assertOwned(e);let t=this.typeof(e);if(t==="string")return this.getString(e);if(t==="number")return this.getNumber(e);if(t==="bigint")return this.getBigInt(e);if(t==="undefined")return;if(t==="symbol")return this.getSymbol(e);let r=this.getPromiseState(e);if(r.type==="fulfilled"&&!r.notAPromise)return e.dispose(),{type:r.type,value:r.value.consume(this.dump)};if(r.type==="pending")return e.dispose(),{type:r.type};if(r.type==="rejected")return e.dispose(),{type:r.type,error:r.error.consume(this.dump)};let i=this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value,e.value));try{return JSON.parse(i)}catch{return i}}unwrapResult(e){if(e.error){let t="context"in e.error?e.error.context:this,r=e.error.consume(i=>this.dump(i));if(r&&typeof r=="object"&&typeof r.message=="string"){let{message:i,name:s,stack:n,...o}=r,a=new R(r,t);typeof s=="string"&&(a.name=r.name),a.message=i;let l=a.stack;throw typeof n=="string"&&(a.stack=`${s}: ${i}