stack3js 0.0.0-stage → 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 (97) hide show
  1. package/COMMAND.md +145 -0
  2. package/LICENSE +21 -0
  3. package/README.md +304 -2
  4. package/THIRD-PARTY-LICENSES.md +100 -0
  5. package/bin/stack3.mjs +5437 -0
  6. package/blender/import_stack.py +89 -0
  7. package/examples/future-tank.stack3.json +1 -0
  8. package/examples/traffic-cone-4view.png +0 -0
  9. package/meshing/blocks.py +82 -0
  10. package/meshing/branches.py +62 -0
  11. package/meshing/dexel.py +67 -0
  12. package/meshing/field_data.py +19 -0
  13. package/meshing/finish_blender.py +203 -0
  14. package/meshing/finishing.py +155 -0
  15. package/meshing/geometry.py +71 -0
  16. package/meshing/guided.py +150 -0
  17. package/meshing/implicit.py +178 -0
  18. package/meshing/intersection.py +33 -0
  19. package/meshing/material.py +115 -0
  20. package/meshing/mesh.py +103 -0
  21. package/meshing/network.py +136 -0
  22. package/meshing/regularization.py +213 -0
  23. package/meshing/sections.py +165 -0
  24. package/meshing/signed_distance.py +93 -0
  25. package/package.json +32 -4
  26. package/references/hard-surface/README.md +40 -0
  27. package/references/hard-surface/atlas/concrete-barrier-4view.png +0 -0
  28. package/references/hard-surface/atlas/preview.pipeline.yaml +14 -0
  29. package/references/hard-surface/case-studies/benchmark/README.md +22 -0
  30. package/references/hard-surface/case-studies/benchmark/lod-bevel.pipeline.yaml +258 -0
  31. package/references/hard-surface/finishing/exports.yaml +10 -0
  32. package/references/hard-surface/finishing/finish-lod.pipeline.yaml +33 -0
  33. package/references/hard-surface/finishing/inputs/stack/stack.json +1 -0
  34. package/references/hard-surface/finishing/inputs/stack/stack.png +0 -0
  35. package/references/hard-surface/finishing/regularize.pipeline.yaml +46 -0
  36. package/references/hard-surface/measured-depth/sdf/compare.pipeline.yaml +12 -0
  37. package/references/hard-surface/measured-depth/sdf/inputs/field.npy +0 -0
  38. package/references/hard-surface/measured-depth/sdf/inputs/stack/stack.json +1 -0
  39. package/references/hard-surface/measured-depth/sdf/inputs/stack/stack.png +0 -0
  40. package/references/hard-surface/measured-depth/sdf/inputs/truth.json +1 -0
  41. package/references/hard-surface/measured-depth/sdf/sdf.guide.json +3 -0
  42. package/references/hard-surface/measured-depth/triple-dexel/compare.pipeline.yaml +12 -0
  43. package/references/hard-surface/measured-depth/triple-dexel/dexel.guide.json +3 -0
  44. package/references/hard-surface/measured-depth/triple-dexel/inputs/fixture.json +22 -0
  45. package/references/hard-surface/measured-depth/triple-dexel/inputs/stack/stack.json +22 -0
  46. package/references/hard-surface/measured-depth/triple-dexel/inputs/stack/stack.png +0 -0
  47. package/references/hard-surface/measured-depth/triple-dexel/inputs/triple-dexel.npz +0 -0
  48. package/references/hard-surface/schema/pipeline-fragment.schema.json +5 -0
  49. package/references/hard-surface/schema/pipeline.schema.json +181 -0
  50. package/schema/pipeline-fragment.schema.json +5 -0
  51. package/schema/pipeline.schema.json +181 -0
  52. package/verification/assembly.py +96 -0
  53. package/verification/landmarks.py +53 -0
  54. package/verification/panels.py +137 -0
  55. package/verification/projections.py +135 -0
  56. package/verification/verify.py +108 -0
  57. package/viewer/dist/THIRD-PARTY-LICENSES.md +174 -0
  58. package/viewer/dist/assets/GLTFExporter-xdVCArY-.js +1 -0
  59. package/viewer/dist/assets/ant-mech-angled-leg-4view-BO2qt1_k.png +0 -0
  60. package/viewer/dist/assets/ant-mech-body-4view-D9xVPpbc.png +0 -0
  61. package/viewer/dist/assets/ant-mech-center-leg-4view-BcphjF_G.png +0 -0
  62. package/viewer/dist/assets/compare-B6DWTZS9.css +1 -0
  63. package/viewer/dist/assets/compare-Du4RoRQO.js +6 -0
  64. package/viewer/dist/assets/compare.worker-CgJq-znx.js +21 -0
  65. package/viewer/dist/assets/concrete-barrier-4view-7PsO3Ftq.png +0 -0
  66. package/viewer/dist/assets/emscripten-module-uFzwHH0Y.wasm +0 -0
  67. package/viewer/dist/assets/emscripten-module.browser-BcR5qphc.js +1 -0
  68. package/viewer/dist/assets/ffi-Boa1QuFa.js +1 -0
  69. package/viewer/dist/assets/fillet-rover-body-4-view-Chk8Mx4R.png +0 -0
  70. package/viewer/dist/assets/fillet-rover-wheel-4-view-B-F8flOC.png +0 -0
  71. package/viewer/dist/assets/hull-4view-BPPqJYUz.png +0 -0
  72. package/viewer/dist/assets/hull-base-color-4view-DrQmdT3h.png +0 -0
  73. package/viewer/dist/assets/hull-clay-4view-3Cu-4Hvr.png +0 -0
  74. package/viewer/dist/assets/hull-depth-4view-DCOdT5ev.png +0 -0
  75. package/viewer/dist/assets/hull-normal-4view-CvLaFITy.png +0 -0
  76. package/viewer/dist/assets/inspection-robot-body-4-view-CLMaHFYm.png +0 -0
  77. package/viewer/dist/assets/inspection-robot-wheel-4-view-27wRsxcs.png +0 -0
  78. package/viewer/dist/assets/plastic-barrier-4view-DQkTBW_i.png +0 -0
  79. package/viewer/dist/assets/presets-jXE0t1fU.js +1 -0
  80. package/viewer/dist/assets/preview-cache-BKV0EZl9.js +1 -0
  81. package/viewer/dist/assets/project-BzR9Ensg.css +1 -0
  82. package/viewer/dist/assets/project-DtHHhfo-.js +17 -0
  83. package/viewer/dist/assets/reconstruct.worker-ONc9GyFO.js +21 -0
  84. package/viewer/dist/assets/script-engine-Bs3azDYZ.js +6 -0
  85. package/viewer/dist/assets/style-CMUT8CmM.css +1 -0
  86. package/viewer/dist/assets/style-D6eZHs3D.js +4004 -0
  87. package/viewer/dist/assets/tank-hull-4view-B4sMMkP5.png +0 -0
  88. package/viewer/dist/assets/tank-track-4view-DAIiMTy3.png +0 -0
  89. package/viewer/dist/assets/tank-turret-4view-Cx0FuNFu.png +0 -0
  90. package/viewer/dist/assets/traffic-cone-4view-DG-TkITx.png +0 -0
  91. package/viewer/dist/assets/viewer-DIjS0No7.js +2 -0
  92. package/viewer/dist/assets/wet-floor-sign-4view-CWJDyeTX.png +0 -0
  93. package/viewer/dist/compare.html +47 -0
  94. package/viewer/dist/examples/traffic-cone-4view.png +0 -0
  95. package/viewer/dist/index.html +148 -0
  96. package/viewer/dist/playground/index.html +3342 -0
  97. package/viewer/dist/project.html +83 -0
@@ -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)}))}}})();
@@ -0,0 +1,6 @@
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
+ ${this._constructorStack}
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
+ 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}
5
+ ${r.stack}Host: ${l}`),Object.assign(a,o),a}throw new R(r)}return e.value}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { ctx: ${this.ctx.value} rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getFunction(e){let t=this.runtime.hostRefs.get(e);if(typeof t!="function")throw new Error(`Host reference ${e} is not a function`);return t}errorToHandle(e){return e instanceof c?e:this.newError(e)}encodeBinaryJSON(e){let t=this.ffi.QTS_bjson_encode(this.ctx.value,e.value);return this.memory.heapValueHandle(t)}decodeBinaryJSON(e){let t=this.ffi.QTS_bjson_decode(this.ctx.value,e.value);return this.memory.heapValueHandle(t)}success(e){return _.success(e)}fail(e){return _.fail(e,t=>this.unwrapResult(t))}},Ee=class extends w{constructor(e){super(),this.scope=new d,this.contextMap=new Map,this.hostRefs=new xe,this._debugMode=!1,this.cToHostCallbacks={freeHostRef:(t,r)=>{if(t!==this.rt.value)throw new Error("Runtime pointer mismatch");this.hostRefs.delete(r)},shouldInterrupt:t=>{if(t!==this.rt.value)throw new Error("QuickJSContext instance received C -> JS interrupt with mismatched rt");let r=this.interruptHandler;if(!r)throw new Error("QuickJSContext had no interrupt handler");return r(this)?1:0},loadModuleSource:B(this,function*(t,r,i,s){let n=this.moduleLoader;if(!n)throw new Error("Runtime has no module loader");if(r!==this.rt.value)throw new Error("Runtime pointer mismatch");let o=this.contextMap.get(i)??this.newContext({contextPointer:i});try{let a=yield*t(n(s,o));if(typeof a=="object"&&"error"in a&&a.error)throw this.debugLog("cToHostLoadModule: loader returned error",a.error),a.error;let l=typeof a=="string"?a:"value"in a?a.value:a;return this.memory.newHeapCharPointer(l).value.ptr}catch(a){return this.debugLog("cToHostLoadModule: caught error",a),o.throw(a),0}}),normalizeModule:B(this,function*(t,r,i,s,n){let o=this.moduleNormalizer;if(!o)throw new Error("Runtime has no module normalizer");if(r!==this.rt.value)throw new Error("Runtime pointer mismatch");let a=this.contextMap.get(i)??this.newContext({contextPointer:i});try{let l=yield*t(o(s,n,a));if(typeof l=="object"&&"error"in l&&l.error)throw this.debugLog("cToHostNormalizeModule: normalizer returned error",l.error),l.error;let f=typeof l=="string"?l:l.value;return a.getMemory(this.rt.value).newHeapCharPointer(f).value.ptr}catch(l){return this.debugLog("normalizeModule: caught error",l),a.throw(l),0}})},e.ownedLifetimes?.forEach(t=>this.scope.manage(t)),this.module=e.module,this.memory=new se(this.module),this.ffi=e.ffi,this.rt=e.rt,this.callbacks=e.callbacks,this.scope.manage(this.rt),this.callbacks.setRuntimeCallbacks(this.rt.value,this.cToHostCallbacks),this.executePendingJobs=this.executePendingJobs.bind(this)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}newContext(e={}){let t=ve(e.intrinsics),r=new c(e.contextPointer||this.ffi.QTS_NewContext(this.rt.value,t),void 0,s=>{this.contextMap.delete(s),this.callbacks.deleteContext(s),this.ffi.QTS_FreeContext(s)}),i=new Me({module:this.module,ctx:r,ffi:this.ffi,rt:this.rt,ownedLifetimes:e.ownedLifetimes,runtime:this,callbacks:this.callbacks});return this.contextMap.set(r.value,i),i}setModuleLoader(e,t){this.moduleLoader=e,this.moduleNormalizer=t,this.ffi.QTS_RuntimeEnableModuleLoader(this.rt.value,this.moduleNormalizer?1:0)}removeModuleLoader(){this.moduleLoader=void 0,this.ffi.QTS_RuntimeDisableModuleLoader(this.rt.value)}hasPendingJob(){return!!this.ffi.QTS_IsJobPending(this.rt.value)}setInterruptHandler(e){let t=this.interruptHandler;this.interruptHandler=e,t||this.ffi.QTS_RuntimeEnableInterruptHandler(this.rt.value)}removeInterruptHandler(){this.interruptHandler&&(this.ffi.QTS_RuntimeDisableInterruptHandler(this.rt.value),this.interruptHandler=void 0)}executePendingJobs(e=-1){let t=this.memory.newMutablePointerArray(1),r=this.ffi.QTS_ExecutePendingJob(this.rt.value,e??-1,t.value.ptr),i=t.value.typedArray[0];if(t.dispose(),i===0)return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value,r),_.success(0);let s=this.contextMap.get(i)??this.newContext({contextPointer:i}),n=s.getMemory(this.rt.value).heapValueHandle(r);if(s.typeof(n)==="number"){let o=s.getNumber(n);return n.dispose(),_.success(o)}else{let o=Object.assign(n,{context:s});return _.fail(o,a=>s.unwrapResult(a))}}setMemoryLimit(e){if(e<0&&e!==-1)throw new Error("Cannot set memory limit to negative number. To unset, pass -1");this.ffi.QTS_RuntimeSetMemoryLimit(this.rt.value,e)}computeMemoryUsage(){let e=this.getSystemContext().getMemory(this.rt.value);return e.heapValueHandle(this.ffi.QTS_RuntimeComputeMemoryUsage(this.rt.value,e.ctx.value))}dumpMemoryUsage(){return this.memory.consumeHeapCharPointer(this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value))}setMaxStackSize(e){if(e<0)throw new Error("Cannot set memory limit to negative number. To unset, pass 0.");this.ffi.QTS_RuntimeSetMaxStackSize(this.rt.value,e)}assertOwned(e){if(e.owner&&e.owner.rt!==this.rt)throw new W(`Handle is not owned by this runtime: ${e.owner.rt.value} != ${this.rt.value}`)}setDebugMode(e){this._debugMode=e,this.ffi.DEBUG&&this.rt.alive&&this.ffi.QTS_SetDebugLogEnabled(this.rt.value,e?1:0)}isDebugMode(){return this._debugMode}debugLog(...e){this._debugMode&&console.log("quickjs-emscripten:",...e)}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getSystemContext(){return this.context||(this.context=this.scope.manage(this.newContext())),this.context}},Ae=class{constructor(e){this.freeHostRef=e.freeHostRef,this.callFunction=e.callFunction,this.shouldInterrupt=e.shouldInterrupt,this.loadModuleSource=e.loadModuleSource,this.normalizeModule=e.normalizeModule}},ne=class{constructor(e){this.contextCallbacks=new Map,this.runtimeCallbacks=new Map,this.suspendedCount=0,this.cToHostCallbacks=new Ae({freeHostRef:(t,r,i)=>{let s=this.runtimeCallbacks.get(r);if(!s)throw new Error(`QuickJSRuntime(rt = ${r}) not found when trying to free HostRef(id = ${i})`);s.freeHostRef(r,i)},callFunction:(t,r,i,s,n,o)=>this.handleAsyncify(t,()=>{try{let a=this.contextCallbacks.get(r);if(!a)throw new Error(`QuickJSContext(ctx = ${r}) not found for C function call "${o}"`);return a.callFunction(r,i,s,n,o)}catch(a){return console.error("[C to host error: returning null]",a),0}}),shouldInterrupt:(t,r)=>this.handleAsyncify(t,()=>{try{let i=this.runtimeCallbacks.get(r);if(!i)throw new Error(`QuickJSRuntime(rt = ${r}) not found for C interrupt`);return i.shouldInterrupt(r)}catch(i){return console.error("[C to host interrupt: returning error]",i),1}}),loadModuleSource:(t,r,i,s)=>this.handleAsyncify(t,()=>{try{let n=this.runtimeCallbacks.get(r);if(!n)throw new Error(`QuickJSRuntime(rt = ${r}) not found for C module loader`);let o=n.loadModuleSource;if(!o)throw new Error(`QuickJSRuntime(rt = ${r}) does not support module loading`);return o(r,i,s)}catch(n){return console.error("[C to host module loader error: returning null]",n),0}}),normalizeModule:(t,r,i,s,n)=>this.handleAsyncify(t,()=>{try{let o=this.runtimeCallbacks.get(r);if(!o)throw new Error(`QuickJSRuntime(rt = ${r}) not found for C module loader`);let a=o.normalizeModule;if(!a)throw new Error(`QuickJSRuntime(rt = ${r}) does not support module loading`);return a(r,i,s,n)}catch(o){return console.error("[C to host module loader error: returning null]",o),0}})}),this.module=e,this.module.callbacks=this.cToHostCallbacks}setRuntimeCallbacks(e,t){this.runtimeCallbacks.set(e,t)}deleteRuntime(e){this.runtimeCallbacks.delete(e)}setContextCallbacks(e,t){this.contextCallbacks.set(e,t)}deleteContext(e){this.contextCallbacks.delete(e)}handleAsyncify(e,t){if(e)return e.handleSleep(i=>{try{let s=t();if(!(s instanceof Promise)){b("asyncify.handleSleep: not suspending:",s),i(s);return}if(this.suspended)throw new q(`Already suspended at: ${this.suspended.stack}
6
+ Attempted to suspend at:`);this.suspended=new K(`(${this.suspendedCount++})`),b("asyncify.handleSleep: suspending:",this.suspended),s.then(n=>{this.suspended=void 0,b("asyncify.handleSleep: resolved:",n),i(n)},n=>{b("asyncify.handleSleep: rejected:",n),console.error("QuickJS: cannot handle error in suspended function",n),this.suspended=void 0})}catch(s){throw this.suspended=void 0,s}});let r=t();if(r instanceof Promise)throw new Error("Promise return value not supported in non-asyncify context.");return r}};function oe(e,t){t.interruptHandler&&e.setInterruptHandler(t.interruptHandler),t.maxStackSizeBytes!==void 0&&e.setMaxStackSize(t.maxStackSizeBytes),t.memoryLimitBytes!==void 0&&e.setMemoryLimit(t.memoryLimitBytes)}function ae(e,t){t.moduleLoader&&e.setModuleLoader(t.moduleLoader),t.shouldInterrupt&&e.setInterruptHandler(t.shouldInterrupt),t.memoryLimitBytes!==void 0&&e.setMemoryLimit(t.memoryLimitBytes),t.maxStackSizeBytes!==void 0&&e.setMaxStackSize(t.maxStackSizeBytes)}var Te=class{constructor(e,t){this.module=e,this.ffi=t,this.callbacks=new ne(e)}newRuntime(e={}){let t=new c(this.ffi.QTS_NewRuntime(),void 0,i=>{this.ffi.QTS_FreeRuntime(i),this.callbacks.deleteRuntime(i)}),r=new Ee({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:t});return oe(r,e),e.moduleLoader&&r.setModuleLoader(e.moduleLoader),r}newContext(e={}){let t=this.newRuntime(),r=t.newContext({...e,ownedLifetimes:_e(t,e.ownedLifetimes)});return t.context=r,r}evalCode(e,t={}){return d.withScope(r=>{let i=r.manage(this.newContext());ae(i.runtime,t);let s=i.evalCode(e,"eval.js");if(t.memoryLimitBytes!==void 0&&i.runtime.setMemoryLimit(-1),s.error)throw i.dump(r.manage(s.error));return i.dump(r.manage(s.value))})}getWasmMemory(){let e=this.module.quickjsEmscriptenInit?.(()=>{})?.getWasmMemory?.();if(!e)throw new Error("Variant does not support getting WebAssembly.Memory");return e}getFFI(){return this.ffi}};async function Qe(e){let t=E(await e),[r,i,{QuickJSWASMModule:s}]=await Promise.all([t.importModuleLoader().then(E),t.importFFI(),k(()=>Promise.resolve().then(()=>Ce),void 0,import.meta.url).then(E)]),n=await r();n.type="sync";let o=new i(n);return new s(n,o)}function E(e){return e&&"default"in e&&e.default?e.default&&"default"in e.default&&e.default.default?e.default.default:e.default:e}function He(e,t){return{...e,async importModuleLoader(){let r=E(await e.importModuleLoader());return async function(){let i=t.emscriptenModule?{...t.emscriptenModule}:{},s=t.log??((...u)=>b("newVariant moduleLoader:",...u)),n=(u,h)=>(s(...u,h),h),o=u=>typeof u=="function"?u():u;(t.wasmLocation||t.wasmSourceMapLocation||t.locateFile)&&(i.locateFile=(u,h)=>{let p={fileName:u,relativeTo:h};if(u.endsWith(".wasm")&&t.wasmLocation!==void 0)return n(["locateFile .wasm: provide wasmLocation",p],t.wasmLocation);if(u.endsWith(".map")){if(t.wasmSourceMapLocation!==void 0)return n(["locateFile .map: provide wasmSourceMapLocation",p],t.wasmSourceMapLocation);if(t.wasmLocation&&!t.locateFile)return n(["locateFile .map: infer from wasmLocation",p],t.wasmLocation+".map")}return t.locateFile?n(["locateFile: use provided fn",p],t.locateFile(u,h)):n(["locateFile: unhandled, passthrough",p],u)}),t.wasmBinary&&(i.wasmBinary=await o(t.wasmBinary)),t.wasmMemory&&(i.wasmMemory=await o(t.wasmMemory));let a=t.wasmModule,l;a&&(i.instantiateWasm=async(u,h)=>{l??(l=Promise.resolve(o(a)));let p=await l;if(!p)throw new L(`options.wasmModule returned ${String(p)}`);let N=await WebAssembly.instantiate(p,u);return h(N),N.exports}),i.monitorRunDependencies=u=>{s("monitorRunDependencies:",u)},i.quickjsEmscriptenInit=()=>ke(s);let f=r(i),m=i.quickjsEmscriptenInit?.(s);if(a&&m?.receiveWasmOffsetConverter&&!m.existingWasmOffsetConverter){let u=await o(t.wasmBinary)??new ArrayBuffer(0);l??(l=Promise.resolve(o(a)));let h=await l;if(!h)throw new L(`options.wasmModule returned ${String(h)}`);m.receiveWasmOffsetConverter(u,h)}if(m?.receiveSourceMapJSON){let u=await o(t.wasmSourceMapData);typeof u=="string"?m.receiveSourceMapJSON(JSON.parse(u)):u?m.receiveSourceMapJSON(u):m.receiveSourceMapJSON({version:3,names:[],sources:[],mappings:""})}return f}}}}function ke(e){let t="mock called, emscripten module may not be initialized yet";return{mock:!0,removeRunDependency(r){e(`${t}: removeRunDependency called:`,r)},receiveSourceMapJSON(r){e(`${t}: receiveSourceMapJSON called:`,r)},WasmOffsetConverter:void 0,receiveWasmOffsetConverter(r,i){e(`${t}: receiveWasmOffsetConverter called:`,r,i)}}}var Re={type:"sync",importFFI:()=>k(()=>import("./ffi-Boa1QuFa.js"),[],import.meta.url).then(e=>e.QuickJSFFI),importModuleLoader:()=>k(()=>import("./emscripten-module.browser-BcR5qphc.js"),[],import.meta.url).then(e=>e.default)},Je=Re;const Le=""+new URL("emscripten-module-uFzwHH0Y.wasm",import.meta.url).href,Fe=()=>Qe(He(Je,{wasmLocation:Le})),Ce=Object.freeze(Object.defineProperty({__proto__:null,QuickJSModuleCallbacks:ne,QuickJSWASMModule:Te,applyBaseRuntimeOptions:oe,applyModuleEvalRuntimeOptions:ae},Symbol.toStringTag,{value:"Module"}));export{Fe as createScriptEngine};
@@ -0,0 +1 @@
1
+ :root{color-scheme:dark;font:14px/1.45 system-ui,sans-serif;color:#e6edf4;background:#151b22;--surface: #1c252f;--border: #344354;--muted: #a5b4c4;--accent: #d1e95c}*{box-sizing:border-box}body{margin:0}[hidden]{display:none!important}.topbar{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:12px;padding:14px clamp(15px,3vw,34px);border-bottom:1px solid var(--border)}h1{margin:0;letter-spacing:-.04em;font-size:25px;font-weight:750}h1 span{color:var(--accent)}.toolbar,.viewer-toolbar,.viewer-status{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap}button,.button{font:inherit;font-weight:630;color:inherit;border:1px solid var(--border);background:#25313e;border-radius:5px;padding:7px 11px;min-height:36px;cursor:pointer}.button{text-decoration:none}button:focus-visible,input:focus-visible,select:focus-visible,.button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}button:disabled{opacity:.42;cursor:default}.primary,button[aria-pressed=true]{background:var(--accent);color:#202719;border-color:var(--accent)}main{max-width:1470px;margin:auto;padding:17px clamp(12px,3vw,34px);display:grid;grid-template-columns:minmax(238px,292px) minmax(0,1fr);gap:14px;align-items:start}aside{background:var(--surface);border:1px solid var(--border);border-radius:7px}aside section{padding:14px}aside section+section{border-top:1px solid var(--border)}h2{font-size:15px;margin:0 0 9px}.segmented,.split{display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-bottom:8px}label:not(.button){display:flex;justify-content:space-between;gap:4px;margin:7px 0 3px;font-size:12px;font-weight:630}output{color:var(--accent);font-variant-numeric:tabular-nums}input,select{min-width:0;width:100%;font:inherit}input[type=range]{accent-color:var(--accent);margin:0}input[type=text],input[type=number],select{color:inherit;background:#161f28;border:1px solid var(--border);border-radius:4px;padding:6px}#sourceImage{width:100%;max-height:120px;object-fit:contain;margin-top:8px;background:#f5f5f5;border-radius:4px}ul{list-style:none;padding:0;margin:5px 0 0}#mappedViews{display:flex;flex-wrap:wrap;gap:3px 9px;color:var(--muted);font-size:11px}#atlasFields>.toolbar{margin-top:8px}#assemblyEditor{margin-top:8px}#assemblyEditor summary{cursor:pointer}#partMounts fieldset{border:1px solid var(--border);margin:6px 0 0;padding:4px 6px 6px}#partMounts fieldset>div{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:4px}#partMounts label{min-width:0;display:block}#partMounts input{padding:3px}#partMounts button{min-height:28px;margin-top:4px;padding:3px 7px}.viewer{overflow:hidden;border:1px solid var(--border);border-radius:7px;background:var(--surface)}.viewer-toolbar,.viewer-status{padding:8px 12px;color:var(--muted)}.viewer-toolbar{border-bottom:1px solid var(--border)}#viewport{min-height:340px;height:min(69vh,740px);background:#121923;position:relative;touch-action:none}#viewport canvas{display:block;width:100%;height:100%}.viewer-status{font-size:12px}#warnings{color:#f3c778;font-size:12px;padding:0 12px}#warnings:empty{display:none}#warnings li:last-child{padding-bottom:8px}@media(max-width:700px){main{grid-template-columns:1fr}.viewer{grid-row:1}#viewport{height:48vh}}