ldr 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/spec.ts
1
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/spec.ts
2
2
  var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
3
3
  var COLOUR_ID_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
4
4
  var namedCodes = new Map;
@@ -707,9 +707,35 @@ function fileStepViews(f) {
707
707
  viewMemo.set(f, out);
708
708
  return out;
709
709
  }
710
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/model.ts
710
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/model.ts
711
711
  var CALLOUT_END = 999999;
712
712
  var stepKey = (steps) => steps.map((x) => String(x).padStart(6, "0")).join(".") + "~";
713
+ var defLine = new WeakMap;
714
+ var wrapMemo = new WeakMap;
715
+ function scopeWrapper(part, scope) {
716
+ let w = wrapMemo.get(scope);
717
+ if (!w) {
718
+ const lines = [...scope.values()].map((d) => {
719
+ const t = defLine.get(d) ?? "";
720
+ const k = t.indexOf("!COLOUR");
721
+ return k < 0 ? "" : "0 " + t.slice(k).trim().replace(/\s+/g, " ");
722
+ }).filter(Boolean);
723
+ w = { head: lines.join(`
724
+ `), parts: new Map };
725
+ wrapMemo.set(scope, w);
726
+ }
727
+ let r = w.parts.get(part);
728
+ if (!r) {
729
+ const n = norm(part), source = `0 ldr: ${n} placed in a model's !COLOUR scope
730
+ 0 BFC CERTIFY CCW
731
+ ${w.head}
732
+ 1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${n}
733
+ `;
734
+ r = { name: `${n}#col-${hash32(source)}`, source };
735
+ w.parts.set(part, r);
736
+ }
737
+ return r;
738
+ }
713
739
  function flatten(doc, opts = {}) {
714
740
  const out = [];
715
741
  const maxDepth = opts.maxDepth ?? 64;
@@ -754,7 +780,7 @@ function flatten(doc, opts = {}) {
754
780
  const views = fileStepViews(f);
755
781
  const ls = loose ? looseSteps(f) : [];
756
782
  let li = 0;
757
- const emit = (part, col, mm, sp, k, embedded, tex, cd) => {
783
+ const emit = (part, col, mm, sp, k, embedded, tex, cd, sc) => {
758
784
  if (fixed)
759
785
  sp = fixed;
760
786
  const i = { part, color: col, m: mm, step: sp[0], steps: sp, localStep: k, path };
@@ -773,6 +799,10 @@ function flatten(doc, opts = {}) {
773
799
  const w = texWrapper(part, tex);
774
800
  i.texPart = w.name;
775
801
  i.texSource = w.source;
802
+ } else if (sc) {
803
+ const w = scopeWrapper(part, sc);
804
+ i.colPart = w.name;
805
+ i.colSource = w.source;
776
806
  }
777
807
  const v = views[k];
778
808
  if (v)
@@ -783,7 +813,7 @@ function flatten(doc, opts = {}) {
783
813
  const flushLoose = (upTo) => {
784
814
  while (li < ls.length && ls[li] <= upTo) {
785
815
  const k = ls[li++];
786
- emit(loosePartName(f.name, k), color, m, [...stepPath, k], k, false, null, colour).source = lazy(f, k);
816
+ emit(loosePartName(f.name, k), color, m, [...stepPath, k], k, false, null, colour, scope0).source = lazy(f, k);
787
817
  }
788
818
  };
789
819
  for (const c0 of f.cmds) {
@@ -799,8 +829,10 @@ function flatten(doc, opts = {}) {
799
829
  if (c.t === 0) {
800
830
  if (c.meta === "!COLOUR") {
801
831
  const def = parseColourLine(c.text);
802
- if (def && def.code !== 16 && def.code !== 24)
832
+ if (def && def.code !== 16 && def.code !== 24) {
833
+ defLine.set(def, c.text);
803
834
  (scope = new Map(scope ?? [])).set(def.code, def);
835
+ }
804
836
  continue;
805
837
  }
806
838
  if (tx && c.geom?.t === 1)
@@ -821,7 +853,7 @@ function flatten(doc, opts = {}) {
821
853
  sub(d, c.file, mm, col, sp, lt, cd);
822
854
  continue;
823
855
  }
824
- emit(c.file, col, mm, sp, s, true, lt, cd);
856
+ emit(c.file, col, mm, sp, s, true, lt, cd, scope);
825
857
  continue;
826
858
  }
827
859
  const ext = opts.resolveModel?.(c.file);
@@ -829,7 +861,7 @@ function flatten(doc, opts = {}) {
829
861
  sub(ext, c.file, mm, col, sp, lt, cd);
830
862
  continue;
831
863
  }
832
- emit(c.file, col, mm, sp, s, false, lt, cd);
864
+ emit(c.file, col, mm, sp, s, false, lt, cd, scope);
833
865
  }
834
866
  flushLoose(Infinity);
835
867
  if (groups) {
@@ -1089,7 +1121,7 @@ function blendedColourHex(code) {
1089
1121
  const a = LDRAW_EXE_16[code - 256 >> 4], b = LDRAW_EXE_16[code - 256 & 15];
1090
1122
  return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
1091
1123
  }
1092
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/instructions.ts
1124
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/instructions.ts
1093
1125
  var MIN_VIS = 0.5;
1094
1126
  var REORIENT = 0.35;
1095
1127
  var deg = Math.PI / 180;
@@ -1457,10 +1489,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
1457
1489
  }
1458
1490
  };
1459
1491
  }
1460
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/render.ts
1492
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/render.ts
1461
1493
  import * as THREE from "three";
1462
1494
 
1463
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/pack-io.ts
1495
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/pack-io.ts
1464
1496
  import { decompress } from "fzstd";
1465
1497
  async function decompressPack(data) {
1466
1498
  const u = data instanceof Uint8Array ? data : new Uint8Array(data);
@@ -1483,7 +1515,7 @@ function decodePack(buf) {
1483
1515
  return { header, arr, bytes: buf.byteLength, buffer: buf };
1484
1516
  }
1485
1517
 
1486
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/cull.ts
1518
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/cull.ts
1487
1519
  var upright = (m, o = 0) => Math.abs(m[o + 7] - 1) < 0.001 && Math.abs(m[o + 4]) < 0.001 && Math.abs(m[o + 10]) < 0.001;
1488
1520
  var prepCache = new WeakMap;
1489
1521
  function prepPart(H, part) {
@@ -1788,7 +1820,7 @@ function cullCore(insts, H, steps) {
1788
1820
  return { nStuds, studHidden, studUp, underHidden, studsHidden, studHideStep, underHideStep };
1789
1821
  }
1790
1822
  function sceneInstances(instances, H, useTex) {
1791
- const pick = (i) => useTex && i.texPart && H.parts[i.texPart] ? i.texPart : i.part;
1823
+ const pick = (i) => i.colPart && H.parts[i.colPart] ? i.colPart : useTex && i.texPart && H.parts[i.texPart] ? i.texPart : i.part;
1792
1824
  const localColours = new Map;
1793
1825
  const same = new Map;
1794
1826
  const keyOf = (i) => {
@@ -1818,7 +1850,7 @@ function precomputeCull(instances, H, useTex = true) {
1818
1850
  return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
1819
1851
  }
1820
1852
 
1821
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/render.ts
1853
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/render.ts
1822
1854
  async function loadPack(url) {
1823
1855
  const res = await fetch(url);
1824
1856
  if (!res.ok)
@@ -3672,7 +3704,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
3672
3704
  await new Promise((r) => setTimeout(r, 0));
3673
3705
  }
3674
3706
  }
3675
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/scene.ts
3707
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/scene.ts
3676
3708
  import * as THREE2 from "three";
3677
3709
  function ghostMaterial(side, g) {
3678
3710
  const m = new THREE2.MeshStandardMaterial({ color: 16777215, roughness: 0.85, metalness: 0, side, transparent: false, depthWrite: true, opacity: g.opacity });
@@ -4016,10 +4048,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
4016
4048
  return finish();
4017
4049
  })();
4018
4050
  }
4019
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/parts-cdn.ts
4051
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/parts-cdn.ts
4020
4052
  import { decompress as decompress2 } from "fzstd";
4021
4053
 
4022
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/embedded.ts
4054
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/embedded.ts
4023
4055
  function splitFiles(text, fallback) {
4024
4056
  const files = new Map;
4025
4057
  let cur = null, saw = false;
@@ -4091,7 +4123,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
4091
4123
  return out;
4092
4124
  }
4093
4125
 
4094
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/parts-cdn.ts
4126
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/parts-cdn.ts
4095
4127
  var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
4096
4128
  var indexCache = new Map;
4097
4129
  var shardCache = new Map;
@@ -4344,10 +4376,10 @@ async function prepareModel(source, o = {}) {
4344
4376
  return { insts, pack, tier, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
4345
4377
  }
4346
4378
 
4347
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/load-worker.gen.ts
4348
- var load_worker_gen_default = 'var Ct=ArrayBuffer,q=Uint8Array,ge=Uint16Array,Tt=Int16Array;var de=Int32Array,Ee=function(e,t,n){if(q.prototype.slice)return q.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new q(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(q.prototype.fill)return q.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},Lt=function(e,t,n,r){if(q.prototype.copyWithin)return q.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var Et=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],Y=function(e,t,n){var r=Error(t||Et[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Y);if(!n)throw r;return r},We=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},St=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Pt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)Y(0);var u=6-s,c=i==3?4:i,f=We(e,u,c);u+=c;var a=l?1<<l:s,p=We(e,u,a)+(l==1&&256),d=p;if(!s){var x=1<<10+(e[5]>>3);d=x+(x>>3)*(e[5]&7)}if(d>2145386496)Y(1);var y=new q((t==1?p||d:t?0:d)+12);return y[0]=1,y[4]=4,y[8]=8,{b:u+a,y:0,l:0,d:f,w:t&&t!=1?t:y.subarray(12),e:d,o:new de(y.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return St(e,4)+8;Y(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Y(3);var o=1<<s,i=o,l=-1,u=-1,c=-1,f=o,a=new Ct(512+(o<<2)),p=new Tt(a,0,256),d=new ge(a,0,256),x=new ge(a,512,o),y=512+(o<<1),L=new q(a,y,o),h=new q(a,y+o);while(l<255&&i>0){var g=re(i+1),b=r>>3,C=(1<<g+1)-1,F=(e[b]|e[b+1]<<8|e[b+2]<<16)>>(r&7)&C,A=(1<<g)-1,E=C-i-1,T=F&A;if(T<E)r+=g,F=T;else if(r+=g+1,F>A)F-=E;if(p[++l]=--F,F==-1)i+=F,L[--f]=l;else i-=F;if(!F)do{var k=r>>3;u=(e[k]|e[k+1]<<8)>>(r&7)&3,r+=2,l+=u}while(u==3)}if(l>255||i)Y(0);var m=0,P=(o>>1)+(o>>3)+3,V=o-1;for(var N=0;N<=l;++N){var v=p[N];if(v<1){d[N]=-v;continue}for(c=0;c<v;++c){L[m]=N;do m=m+P&V;while(m>=f)}}if(m)Y(0);for(c=0;c<o;++c){var M=d[L[c]]++,I=h[c]=s-re(M);x[c]=(M<<I)-o}return[r+7>>3,{b:s,s:L,n:h,t:x}]},kt=function(e,t){var n=0,r=-1,s=new q(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),u=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],a=c[1];t+=o;var p=f<<3,d=e[t];if(!d)Y(0);var x=0,y=0,L=a.b,h=L,g=(++t<<3)-8+re(d);for(;;){if(g-=L,g<p)break;var b=g>>3;if(x+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<L)-1,i[++r]=a.s[x],g-=h,g<p)break;b=g>>3,y+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<h)-1,i[++r]=a.s[y],L=a.n[x],x=a.t[x],h=a.n[y],y=a.t[y]}if(++r>255)Y(0)}else{r=o-127;for(;n<r;n+=2){var C=e[++t];i[n]=C>>4,i[n+1]=C&15}++t}var F=0;for(n=0;n<r;++n){var A=i[n];if(A>11)Y(0);F+=A&&1<<A-1}var E=re(F)+1,T=1<<E,k=T-F;if(k&k-1)Y(0);i[r++]=re(k)+1;for(n=0;n<r;++n){var A=i[n];++l[i[n]=A&&E+1-A]}var m=new q(T<<1),P=m.subarray(0,T),V=m.subarray(T);u[E]=0;for(n=E;n>0;--n){var N=u[n];ce(V,n,N,u[n-1]=N+l[n]*(1<<E-n))}if(u[0]!=T)Y(0);for(n=0;n<r;++n){var v=i[n];if(v){var M=u[v];ce(P,n,M,u[v]=M+(1<<E-v))}}return[t,{n:V,b:E,s:P}]},It=ue(new q([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Bt=ue(new q([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Ft=ue(new q([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Xe=function(e,t){var n=e.length,r=new de(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new q(new de([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Rt=Xe(Se,0),Pe=new q(new de([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Dt=Xe(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)Y(0);var u=0,c=n.b,f=(r<<3)-8+re(o)-c,a=-1;for(;f>l&&a<s;){var p=f>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(f&7);u=(u<<c|d)&i,t[++a]=n.s[u],f-=c=n.n[u]}if(f!=l||a+1!=s)Y(0)},Ut=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},Ot=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,u=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new q(l),e[s])}if(u>e.length)return;if(i==0){if(t.b=u,n)return n.set(e.subarray(s,u),t.y),t.y+=l,n;return Ee(e,s,u)}if(i==2){var c=e[s],f=c&3,a=c>>2&3,p=c>>4,d=0,x=0;if(f<2)if(a&1)p|=e[++s]<<4|(a&2&&e[++s]<<12);else p=c>>3;else if(x=a,a<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var y=n?n.subarray(t.y,t.y+t.m):new q(t.m),L=y.length-p;if(f==0)y.set(e.subarray(s,s+=p),L);else if(f==1)ce(y,e[s++],L);else{var h=t.h;if(f==2){var g=kt(e,s);d+=s-(s=g[0]),t.h=h=g[1]}else if(!h)Y(0);(x?Ut:le)(e.subarray(s,s+=d),y.subarray(L),h)}var b=e[s++];if(b){if(b==255)b=(e[s++]|e[s++]<<8)+32512;else if(b>127)b=b-128<<8|e[s++];var C=e[s++];if(C&3)Y(0);var F=[Bt,Ft,It];for(var A=2;A>-1;--A){var E=C>>(A<<1)+2&3;if(E==1){var T=new q([0,0,e[s++]]);F[A]={s:T.subarray(2,3),n:T.subarray(0,1),t:new ge(T.buffer,0,1),b:0}}else if(E==2)r=ue(e,s,9-(A&1)),s=r[0],F[A]=r[1];else if(E==3){if(!t.t)Y(0);F[A]=t.t[A]}}var k=t.t=F,m=k[0],P=k[1],V=k[2],N=e[u-1];if(!N)Y(0);var v=(u<<3)-8+re(N)-V.b,M=v>>3,I=0,K=(e[M]|e[M+1]<<8)>>(v&7)&(1<<V.b)-1;M=(v-=P.b)>>3;var B=(e[M]|e[M+1]<<8)>>(v&7)&(1<<P.b)-1;M=(v-=m.b)>>3;var z=(e[M]|e[M+1]<<8)>>(v&7)&(1<<m.b)-1;for(++b;--b;){var _=V.s[K],Z=V.n[K],X=m.s[z],S=m.n[z],w=P.s[B],R=P.n[B];M=(v-=w)>>3;var D=1<<w,U=D+((e[M]|e[M+1]<<8|e[M+2]<<16|e[M+3]<<24)>>>(v&7)&D-1);M=(v-=Pe[X])>>3;var G=Dt[X]+((e[M]|e[M+1]<<8|e[M+2]<<16)>>(v&7)&(1<<Pe[X])-1);M=(v-=Se[_])>>3;var j=Rt[_]+((e[M]|e[M+1]<<8|e[M+2]<<16)>>(v&7)&(1<<Se[_])-1);if(M=(v-=Z)>>3,K=V.t[K]+((e[M]|e[M+1]<<8)>>(v&7)&(1<<Z)-1),M=(v-=S)>>3,z=m.t[z]+((e[M]|e[M+1]<<8)>>(v&7)&(1<<S)-1),M=(v-=R)>>3,B=P.t[B]+((e[M]|e[M+1]<<8)>>(v&7)&(1<<R)-1),U>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=U-=3;else{var H=U-(j!=0);if(H){if(U=H==3?t.o[0]-1:t.o[H],H>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=U}else U=t.o[0]}for(var A=0;A<j;++A)y[I+A]=y[L+A];I+=j,L+=j;var O=I-U;if(O<0){var W=-O,J=t.e+O;if(W>G)W=G;for(var A=0;A<W;++A)y[I+A]=t.w[J+A];I+=W,G-=W,O=0}for(var A=0;A<G;++A)y[I+A]=y[O+A];I+=G}if(I!=L)while(L<y.length)y[I++]=y[L++];else I=y.length;if(n)t.y+=I;else y=Ee(y,0,I)}else if(n){if(t.y+=p,L)for(var A=0;A<p;++A)y[A]=y[L+A]}else if(L)y=Ee(y,L);return t.b=u,y}Y(2)},Nt=function(e,t){if(e.length==1)return e[0];var n=new q(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function be(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Pt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=Ot(e,i,t);if(!l)Y(5);if(t)i.e=i.y;else n.push(l),o+=l.length,Lt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Nt(n,o)}async function zt(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(be(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function Ze(e){return new TextDecoder().decode(await zt(e))}var qe=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function ye(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Q=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),Ie=/^[A-Za-z][A-Za-z0-9_]*$/,ke=new Map;function Be(e){let t=e.toLowerCase(),n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619);let r=-1-(n>>>0&1073741823);if(!ke.has(r))ke.set(r,t);return r}function Fe(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&Ie.test(e))return Be(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ye=/^~?\\s*moved\\s+to\\s+(.+)$/i,$t=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),ot=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),jt=new Set(["model","submodel","configuration"]),Vt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function Je(e){let t=Vt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return ot.has(n)||jt.has(n)?n:void 0}function _t(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function Ht(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let a=0;a<s;a++)l=l.replace(/^\\S+\\s*/,"");let u=_t(l);if(!u.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:u[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=u.findIndex((a,p)=>p>0&&a.toUpperCase()==="GLOSSMAP");if(f>0&&u[f+1])c.glossmap=u[f+1];if(t)c.next=!0;return c}var Gt=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Kt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),u=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Fe(o),m:i,file:Q(u)}}function Qe(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Fe(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Q(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function it(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,u=null,c=[],f=null,a=()=>{if(!u)return;let g=Gt(u.chunks.join("")),b=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Q(u.name),{name:u.name,bytes:g,...b?{mime:"image/png"}:{}}),u=null},p=!0,d=(g)=>{if(a(),o={name:Q(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,p=!0},x=!1,y=!1,L=()=>{if(y)return;y=!0,s.clear(),o=null,i=""},h=(g,b)=>{if(f){g.tex=f,f=null;return}let C=c[c.length-1];if(!C)return;if(C.fallback){if(!b)g.fallback=!0}else g.tex=C.map};for(let g of e.split(`\n`)){let b=g.trim();if(!b)continue;if(r&&b.charCodeAt(0)>=50&&b.charCodeAt(0)<=53&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)){if(u||x)continue;if(!o)d(t);let E=b.slice(2).trimStart(),T=E.search(/\\s/),k={t:b.charCodeAt(0)-48,color:Fe(T<0?E:E.slice(0,T)),p:[],src:b};h(k,!1),o.cmds.push(k),p=!1;continue}if(b.charCodeAt(0)===48&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)){let E=2;while(b.charCodeAt(E)===32||b.charCodeAt(E)===9)E++;let T=E;while(T<b.length&&b.charCodeAt(T)!==32&&b.charCodeAt(T)!==9)T++;let k=b.slice(E,T);if(!$t.has(k)){if(x||u)continue;if(!o)d(t);let m=b.slice(E),P={t:0,text:m};if(k.charCodeAt(0)===33)P.meta=k;if(f=null,p&&!o.org){let N=Je(m);if(N)o.org=N}let V=m.match(Ye);if(V&&!o.movedTo){let N=V[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(N))N+=".dat";o.movedTo=Q(N)}o.cmds.push(P);continue}}if(b.charCodeAt(0)===49&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)&&!u&&!x){let E=Kt(b);if(E){if(!o)d(t);h(E,!1),o.cmds.push(E),p=!1;continue}}let C=b.split(/\\s+/);if(+C[0]===0){let E=b.slice(1).trim();if(C[1]==="FILE"){L(),x=!1,d(E.slice(5));continue}if(C[1]==="NOFILE"){a(),o=null,x=!0;continue}if(C[1]==="!DATA"){L(),a(),o=null,x=!1,u={name:E.slice(5).trim(),chunks:[]};continue}if(x)continue;if(u){if(C[1]==="!:")u.chunks.push(C.slice(2).join(""));continue}if(!o)d(t);let T={t:0,text:E};if(C[1]==="STEP")T.step=!0,c=[],f=null;else if(C[1]==="BFC")T.bfc=C.slice(2).join(" ");else if(C[1]==="ROTSTEP")if(T.meta="ROTSTEP",T.step=!0,c=[],f=null,(C[2]??"").toUpperCase()==="END")T.rotstep={x:0,y:0,z:0,mode:"END"};else{let m=(C[5]??"REL").toUpperCase();T.rotstep={x:+C[2]||0,y:+C[3]||0,z:+C[4]||0,mode:["REL","ABS","ADD"].includes(m)?m:"REL"}}else if(C[1]==="BUFEXCHG"){T.meta="BUFEXCHG";let m=(C[2]??"").toUpperCase();T.bufexchg={op:m==="RETRIEVE"?"RETRIEVE":"STORE",buf:C[3]??"A"}}else if(C[1]?.startsWith("!"))T.meta=C[1];if(p&&!o.org){let m=Je(E);if(m)o.org=m}if(C[1]==="!TEXMAP"){let m=(C[2]??"").toUpperCase();if(f=null,m==="START"||m==="NEXT"){let P=Ht(E.replace(/^!TEXMAP\\s+\\S+/i,""),m==="NEXT");if(T.texmap={op:m,...P?{map:P}:{}},P)if((o.texmaps??=[]).push(P),m==="START")c.push({map:P,fallback:!1});else f=P}else if(m==="FALLBACK"){T.texmap={op:m};let P=c[c.length-1];if(P)P.fallback=!0}else if(m==="END")T.texmap={op:m},c.pop()}else if(C[1]==="!:"){f=null;let m=Qe(C.slice(2));if(m)h(m,!0),T.geom=m}else f=null;let k=E.match(Ye);if(k&&!o.movedTo){let m=k[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(m))m+=".dat";o.movedTo=Q(m)}o.cmds.push(T);continue}if(u||x)continue;if(!o)d(t);let A=Qe(C);if(!A)continue;h(A,!1),o.cmds.push(A),p=!1}return a(),l?{main:i,files:s,data:l}:{main:i,files:s}}var yn=Math.PI/180;function at(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function lt(e,t){let[n,r,s,o,i,l,u,c,f,a,p,d]=e,[x,y,L,h,g,b,C,F,A,E,T,k]=t;return[o*x+i*y+l*L+n,u*x+c*y+f*L+r,a*x+p*y+d*L+s,o*h+i*C+l*E,o*g+i*F+l*T,o*b+i*A+l*k,u*h+c*C+f*E,u*g+c*F+f*T,u*b+c*A+f*k,a*h+p*C+d*E,a*g+p*F+d*T,a*b+p*A+d*k]}var Re=[0,0,0,1,0,0,0,1,0,0,0,1];var et=new WeakMap,Wt=/^(s|8|48)\\//;function De(e,t){let n=e.files.get(Q(t));if(!n)return"part";let r=et.get(n);if(r)return r;if(n.org)r=ot.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&Wt.test(s.file))?"part":"model";return et.set(n,r),r}var tt=new WeakMap;function ct(e){let t=tt.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return tt.set(e,t),t}var nt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?ke.get(e)??String(e):String(e),Xt=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${nt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${nt(e.color)} ${e.p.join(" ")}`,Ue=(e,t)=>`${Q(e)}#${t}`;function Zt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0||o.meta==="!COLOUR"){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ue(e.name,t),cmds:n}}function ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Zt(e,t).cmds.map(Xt)].join(`\n`)+`\n`}function qt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function ft(e){let[t,n,r,s,o,i,l,u,c,f,a,p]=e,d=u*p-c*a,x=-(l*p-c*f),y=l*a-u*f,L=s*d+o*x+i*y;if(!Number.isFinite(L)||Math.abs(L)<0.000000000001)return null;let h=1/L,g=[d*h,-(o*p-i*a)*h,(o*c-i*u)*h,x*h,(s*p-i*f)*h,-(s*c-i*l)*h,y*h,-(s*a-o*f)*h,(s*u-o*l)*h];return[-(g[0]*t+g[1]*n+g[2]*r),-(g[3]*t+g[4]*n+g[5]*r),-(g[6]*t+g[7]*n+g[8]*r),...g]}var Yt=(e)=>String(+e.toFixed(6)||0),rt=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function pt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Yt).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${rt(t.texture)}${t.glossmap?" GLOSSMAP "+rt(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Q(e)}\n0 !TEXMAP END\n`;return{name:`${Q(e)}#tex-${qt(r)}`,source:r}}var Jt=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Qt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),u=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*u,i,o*u+s*i*c,o*c-s*i*u,-s*l,s*u-o*i*c,s*c+o*i*u,o*l]}var st=new WeakMap;function mt(e){let t=st.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=Qt(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Jt(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),st.set(e,n),n}var ht=999999,dt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function en(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,u=0,c=(a,p)=>{let d=a.name+"#"+p,x=l.get(d);if(!x){let y;x=Object.assign(()=>y??=ut(a,p),{file:a,step:p}),l.set(d,x)}return x},f=(a,p,d,x,y,L,h,g,b=null,C=[],F=[],A=void 0,E=null)=>{let T=a.files.get(p);if(!T||h>r)return;let k=E,m=0,P=h>0?++u:0,V=i&&P?[...C,P]:C,N=i&&P?[...F,d]:F,v=i&&!b?new Map:null,M=-1,I=0,K=(S,w,R,D,U,G,j)=>{if(M!==m)M=m,I=0;let H=v?.get(m+"|"+w);if(H)return H.n++,f(S,S===a?w:S.main,R,D,y+"/"+w,[...U,ht],h+1,G,[...U,ht],V,N,j,k);let O=[...U,I++],W=n.length;f(S,S===a?w:S.main,R,D,y+"/"+w,O,h+1,G,b,V,N,j,k),v?.set(m+"|"+w,{n:1,from:W,to:n.length})},B=mt(T),z=s?ct(T):[],_=0,Z=(S,w,R,D,U,G,j,H)=>{if(b)D=b;let O={part:S,color:w,m:R,step:D[0],steps:D,localStep:U,path:y};if(H)O.colour=H;if(P){if(O.sub=P,i)O.subPath=V,O.subMats=N}if(G)O.embedded=!0;if(j){let J=pt(S,j);O.texPart=J.name,O.texSource=J.source}let W=B[U];if(W)O.view=W;return n.push(O),O},X=(S)=>{while(_<z.length&&z[_]<=S){let w=z[_++];Z(Ue(T.name,w),x,d,[...L,w],w,!1,null,A).source=c(T,w)}};for(let S of T.cmds){if(S.t===0&&S.step){m++;continue}let w=S;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){X(m);continue}if(w.t===0){if(w.meta==="!COLOUR"){let J=nn(w.text);if(J&&J.code!==16&&J.code!==24)(k=new Map(k??[])).set(J.code,J);continue}if(o&&w.geom?.t===1)w=w.geom;else continue}if(w.t!==1)continue;if(o&&w.fallback)continue;let R=w.color===16?x:w.color,D=w.color===16?A:k?.get(w.color),U=lt(d,w.m),G=[...L,m],j=o?w.tex??g:null,H=j?ft(w.m):null,O=j&&H?at(j,H):null;if(a.files.has(w.file)){if(De(a,w.file)==="model"){K(a,w.file,U,R,G,O,D);continue}Z(w.file,R,U,G,m,!0,O,D);continue}let W=t.resolveModel?.(w.file);if(W){K(W,w.file,U,R,G,O,D);continue}Z(w.file,R,U,G,m,!1,O,D)}if(X(1/0),v){for(let S of v.values())if(S.n>1)for(let w=S.from;w<S.to;w++)n[w].mult??=S.n}};if(De(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Re],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,Re,16,e.main,[],0,null),n}function bt(e,t="main.ldr",n){return en(it(e,t,{geometryText:!0}),n)}var tn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function Oe(e){if(!e)return null;if(e.startsWith("#")&&/^#[0-9A-Fa-f]{6}$/.test(e))return e.toUpperCase();if(/^0x[0-9A-Fa-f]{6}$/i.test(e))return("#"+e.slice(2)).toUpperCase();return null}function gt(e,t){let n={value:"#FFFFFF",fraction:0.5};while(t<e.length){let r=e[t].toUpperCase(),s=e[t+1];if(r==="VALUE"){let o=Oe(s);if(o)n.value=o;t+=2}else if(r==="ALPHA")n.alpha=+s,t+=2;else if(r==="LUMINANCE")n.luminance=+s,t+=2;else if(r==="FRACTION")n.fraction=+s,t+=2;else if(r==="VFRACTION")n.vfraction=+s,t+=2;else if(r==="SIZE")n.size=+s,t+=2;else if(r==="MINSIZE")n.minsize=+s,t+=2;else if(r==="MAXSIZE")n.maxsize=+s,t+=2;else break}return{grain:n,next:t}}function nn(e){let t=e.indexOf("!COLOUR");if(t<0)return null;let n=e.slice(t+7).trim().split(/\\s+/).filter(Boolean);if(n.length<2)return null;let r=n[0],s=NaN,o="#FF00FF",i="#333333",l=255,u=0,c={type:"default"},f=1;while(f<n.length){let a=n[f].toUpperCase(),p=n[f+1];if(a==="CODE")s=p!==void 0&&Ie.test(p)?Be(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,f+=2;else if(a==="VALUE"){let d=Oe(p);if(d)o=d;f+=2}else if(a==="EDGE")i=Oe(p)??p,f+=2;else if(a==="ALPHA")l=+p,f+=2;else if(a==="LUMINANCE")u=+p,f+=2;else if(a==="CHROME")c={type:"chrome"},f+=1;else if(a==="PEARLESCENT")c={type:"pearlescent"},f+=1;else if(a==="RUBBER")c={type:"rubber"},f+=1;else if(a==="MATTE_METALLIC")c={type:"matte_metallic"},f+=1;else if(a==="METAL")c={type:"metal"},f+=1;else if(a==="MATERIAL"){let d=(n[f+1]||"").toUpperCase();if(d==="GLITTER"){let{grain:x,next:y}=gt(n,f+2);c={type:"glitter",material:x},f=y}else if(d==="SPECKLE"){let{grain:x,next:y}=gt(n,f+2);c={type:"speckle",material:x},f=y}else if(d==="FABRIC"){let x=(n[f+2]||"").toUpperCase(),y=["VELVET","CANVAS","STRING","FUR"].includes(x)?x.toLowerCase():void 0;c={type:"fabric",kind:y},f+=y?3:2}else f=n.length}else if(tn.has(a))f+=1;else f+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(l)?l:255,luminance:Number.isFinite(u)?u:0,finish:c}}function rn(e){let t=Math.max(0,Math.min(1,(e.alpha??255)/255)),n=t<1,r=Math.max(0,Math.min(1,(e.luminance??0)/255)),s={opacity:t,transparent:n,depthWrite:!n,emissive:r,clearcoat:0,clearcoatRoughness:0,sheen:0,sheenRoughness:0};switch(e.finish?.type??"default"){case"chrome":return{...s,metalness:1,roughness:0,finish:"chrome"};case"pearlescent":return{...s,metalness:0.25,roughness:0.3,clearcoat:0.5,clearcoatRoughness:0.25,sheen:0.4,sheenRoughness:0.35,finish:"pearlescent"};case"rubber":return{...s,metalness:0,roughness:0.9,finish:"rubber"};case"matte_metallic":return{...s,metalness:0.4,roughness:0.8,finish:"matte_metallic"};case"metal":return{...s,metalness:0.85,roughness:0.2,finish:"metal"};case"glitter":{let i=e.finish.material,l=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.35,roughness:0.25,clearcoat:1,clearcoatRoughness:0.08,particleHex:i.value,particleFraction:i.fraction,particleSize:l,finish:"glitter"}}case"speckle":{let i=e.finish.material,l=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.2,roughness:0.55,particleHex:i.value,particleFraction:i.fraction,particleSize:l,finish:"speckle"}}case"fabric":return{...s,metalness:0,roughness:0.85,sheen:0.65,sheenRoughness:0.75,finish:"fabric"};default:return{...s,metalness:0,roughness:0.45,finish:"default"}}}function Ne(e){let t=rn(e),n=!t.transparent?"op":t.opacity>=0.75?"a200":t.opacity>=0.4?"a128":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:"",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function sn(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Q(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Q(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var on=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Q(t.slice(14).join(" ")):null};function an(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,"0")+(n>>>0).toString(16).padStart(8,"0")}function yt(e,t,n="main.ldr"){let r=sn(e,n),s=new Map;for(let o of t){let i=Q(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),u=[i];while(u.length)for(let f of r.get(u.pop())){let a=on(f);if(a&&r.has(a)&&!l.has(a))l.add(a),u.push(a)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>"0 FILE "+(f===i?"":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${an(c)}.dat`)}return s}var xt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,wt=new WeakMap;function ze(e,t){let n=wt.get(e);if(!n)wt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],u=[];s.studs.forEach((p,d)=>{l.push(p[0]),u.push(p[1]);for(let x=0;x<12;x++)i[d*12+x]=p[2+x]});let c=null,f=0,a=0;if(s.mask){f=s.mask[0],a=s.mask[1];let p=s.mask[2];c=new Uint8Array(p.length);for(let d=0;d<p.length;d++)c[d]=p.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:u,mask:c,nx:f,nz:a}),r}var ie=1073741824;class $e{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,u=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,u[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&u[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function ln(e,t,n){let s=[],o=[],i=[],l=[],u=[],c=[],f=[],a=[],p=new $e(e.length*2),d=[],x=[];for(let v=0;v<e.length;v++){let M=e[v],I=M.m,K=t.parts[M.part];if(!K||!K.mask||!xt(I))continue;let B=K.bbox,z=1/0,_=-1/0,Z=1/0,X=-1/0;for(let R=0;R<2;R++)for(let D=0;D<2;D++){let U=R?B[3]:B[0],G=D?B[5]:B[2],j=I[0]+I[3]*U+I[5]*G,H=I[2]+I[9]*U+I[11]*G;if(j<z)z=j;if(j>_)_=j;if(H<Z)Z=H;if(H>X)X=H}let S=u.length;s.push(z),o.push(_),i.push(Z),l.push(X),u.push(v),c.push(ze(t,M.part)),f.push(B[0]),a.push(B[2]);let w=Math.round((I[1]+B[4])*2);for(let R=Math.floor(z/40);R<=Math.floor(_/40);R++)for(let D=Math.floor(Z/40);D<=Math.floor(X/40);D++){if(!xe(w,R,D))continue;let U=x.length;x.push(S),d.push(p.put(w,R,D,U))}}let y=[0,5,-5,5,-5],L=[0,5,5,-5,-5],h=NaN,g=NaN,b=NaN,C=-1,F=(v,M,I,K)=>{let B=Math.round(M*2),z=Math.floor(v/40),_=Math.floor(I/40);if(!xe(B,z,_))return fe;let Z=fe;if(B!==h||z!==g||_!==b)h=B,g=z,b=_,C=p.get(B,z,_);for(let X=C;X>=0;X=d[X]){let S=x[X];if(u[S]===K||!(v-6>=s[S]-0.5&&v+6<=o[S]+0.5&&I-6>=i[S]-0.5&&I+6<=l[S]+0.5))continue;let w=e[u[S]].m,R=c[S],D=f[S],U=a[S],G=v-w[0],j=M-w[1],H=I-w[2],O=w[3]*G+w[6]*j+w[9]*H,W=w[5]*G+w[8]*j+w[11]*H,{nx:J,nz:se,mask:ae}=R,oe=!0;for(let ee=0;ee<5;ee++){let te=Math.floor((O+y[ee]-D)/20),ne=Math.floor((W+L[ee]-U)/20);if(te<0||ne<0||te>=J||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let ee=n[u[S]];if(ee<Z)Z=ee}}return Z},A=0;for(let v of e){let M=ze(t,v.part);if(M)A+=M.nStuds}let E=new Uint8Array(A),T=new Uint8Array(A),k=new $e(A),m=0,P=n?new Int32Array(A).fill(fe):void 0;for(let v=0,M=0;v<e.length;v++){let I=e[v],K=ze(t,I.part);if(!K)continue;let B=I.m,z=K.studM,_=B[0],Z=B[1],X=B[2],S=B[3],w=B[4],R=B[5],D=B[6],U=B[7],G=B[8],j=B[9],H=B[10],O=B[11];for(let W=0;W<K.nStuds;W++,M++){let J=W*12,se=z[J+4],ae=z[J+7],oe=z[J+10];if(!(Math.abs(D*se+U*ae+G*oe-1)<0.001&&Math.abs(S*se+w*ae+R*oe)<0.001&&Math.abs(j*se+H*ae+O*oe)<0.001))continue;T[M]=1;let ee=z[J],te=z[J+1],ne=z[J+2],je=_+S*ee+w*te+R*ne,Ve=Z+D*ee+U*te+G*ne,_e=X+j*ee+H*te+O*ne,He=F(je,Ve,_e,v);if(He!==fe){if(E[M]=1,m++,P)P[M]=He}let pe=Math.round(je),me=Math.round(Ve),he=Math.round(_e);if(!xe(pe,me,he))continue;if(!n){k.put(pe,me,he,1);continue}let Ge=n[v],Ke=k.get(pe,me,he);if(Ke<0||Ge<Ke)k.put(pe,me,he,Ge)}}let V=new Uint8Array(e.length),N=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let M=e[v],I=t.parts[M.part];if(!I||!I.under||!xt(M.m))continue;let K=I.bbox,B=Math.round((K[3]-K[0])/20),z=Math.round((K[5]-K[2])/20);if(!B||!z||B*z>4096)continue;let _=M.m,Z=!0,X=0;for(let S=0;S<B&&Z;S++)for(let w=0;w<z;w++){let R=K[0]+10+20*S,D=K[2]+10+20*w,U=_[0]+_[3]*R+_[5]*D,G=_[2]+_[9]*R+_[11]*D,j=Math.round(U),H=Math.round(_[1]+K[4]),O=Math.round(G),W=xe(j,H,O)?k.get(j,H,O):-1;if(W<0){Z=!1;break}if(W>X)X=W}if(Z){if(V[v]=1,N)N[v]=X}}return{nStuds:A,studHidden:E,studUp:T,underHidden:V,studsHidden:m,studHideStep:P,underHideStep:N}}function cn(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=new Map,o=new Map,i=(a)=>{let p=a.colour;if(!p)return String(a.color);let d=o.get(p);if(d!==void 0)return d;let x=t.colorTable?.[a.color],y=x?.hex??t.colors?.[a.color],L=x?Ne({alpha:x.alpha??255,luminance:x.luminance??0,finish:x.finish??{type:"default"}}):"default:op",h=Ne(p);if(d=y&&y.toUpperCase()===p.hex.toUpperCase()&&L===h?String(a.color):p.hex.toUpperCase()+"/"+h,d!==String(a.color))s.set(d,p);return o.set(p,d),d},l=e.map((a)=>({part:r(a),color:i(a),m:a.m,steps:a.steps})),u=l.map((a)=>dt(a.steps)),c=[...new Set(u)].sort(),f=new Map(c.map((a,p)=>[a,p]));return{all:l,stepOf:u.map((a)=>f.get(a)),nSteps:c.length,localColours:s}}function we(e,t,n=!0){let r=cn(e,t,n);return ln(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Te="https://ldr-demo.vercel.app/cdn/v1/",Me=new Map,Ae=new Map;function ve(e=Te,t=fetch){let n=Me.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>Me.delete(e)),Me.set(e,n);return n}var un=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),Ce=(e,t)=>un(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ce(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ce(r,t)])):e;function fn(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let d=p.buffer;if(!d)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let x=new DataView(d).getUint32(0,!0),y=new Uint8Array(d,4+x),L=r;n.push(y),r+=y.byteLength;let h=(4-r%4)%4;if(h)n.push(new Uint8Array(h)),r+=h;for(let[g,b]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ce(b,L);for(let[g,b]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ce(b,L)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),u=(4-(4+l.length)%4)%4,c=4+l.length+u,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+u,!0),f.set(l,4),f.fill(32,4+l.length,c);let a=c;for(let p of n)f.set(p,a),a+=p.byteLength;return ye(f.buffer)}async function pn(e,t={}){e=[...e];try{return await At(e,t)}catch(n){let r=t.cdn??Te,s=t.fetch??fetch;Me.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await At(e,{...t,fetch:o})}catch{throw n}}}async function At(e,t){let n=t.cdn??Te,r=t.fetch??fetch,s=t.gap??16384,o=await ve(n,r),i=[...new Set([...e].map(Q))],l=[],u=[];for(let h of i){if(Ae.has(n+h))continue;let g=o.parts[h];if(g)u.push({name:h,off:g[0],len:g[1],file:g[2]??0});else l.push(h)}u.sort((h,g)=>h.file-g.file||h.off-g.off);let c=[];for(let h of u){let g=c[c.length-1];if(g&&g.file===h.file&&h.off-g.end<=s)g.end=Math.max(g.end,h.off+h.len),g.items.push(h);else c.push({file:h.file,start:h.off,end:h.off+h.len,items:[h]})}let f=0,a=0,p=0,d=new Map,x=async()=>{while(p<c.length){let h=c[p++],g=d.get(h.file);if(g)g=g.subarray(h.start,h.end);else{let b=await r(new URL(o.archives[h.file],n).href,{headers:{Range:`bytes=${h.start}-${h.end-1}`,"Accept-Encoding":"identity"}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);if(a++,g=new Uint8Array(await b.arrayBuffer()),f+=g.byteLength,b.status===200)d.set(h.file,g),g=g.subarray(h.start,h.end)}for(let b of h.items){let C=be(g.subarray(b.off-h.start,b.off-h.start+b.len)),F=C.buffer.slice(C.byteOffset,C.byteOffset+C.byteLength);Ae.set(n+b.name,ye(F))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},x));let y=i.filter((h)=>Ae.has(n+h)).map((h)=>Ae.get(n+h));return{pack:y.length?fn(y,{colors:o.colors}):ye(mn(o.colors)),missing:l,requests:a,bytes:f}}function mn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function hn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function Mt(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let u=l.embedded?t.get(l.part):Q(l.part),c=u?n.parts[u]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(u))i.add(u),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class Le extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function vt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=ve(t.cdn??Te,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(m)=>{if(!m.ok)throw Error(`ldr: ${m.status} fetching ${e}`);return Ze(await m.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?"main.ldr":qe(e)),u=bt(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(u),await s;let f=yt(o,new Set(u.filter((m)=>m.embedded).map((m)=>m.part)),l),a=(m,P)=>t.maxBodyTris!=null&&m>t.maxBodyTris||t.maxPackBytes!=null&&P>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(m)=>new Le({...m,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),x="full";if(p){let m=Mt(u,f,await s);if(a(m.known?m.bodyTris:0,m.packBytes)){if(!t.lowCdn)throw d(m);let P=await ve(t.lowCdn,r).catch(()=>null);if(!P)throw d(m);let V=Mt(u,f,P);if(a(V.known?V.bodyTris:0,V.packBytes))throw d(V);x="low"}}let y=[...u.filter((m)=>!m.embedded).map((m)=>m.part),...f.values()],L=async()=>{let m=await pn(y,x==="low"?{...t,cdn:t.lowCdn}:t);for(let[P,V]of f){let N=m.pack.header.parts[V];if(N)m.pack.header.parts[P]=N}return{...m,packBytes:m.pack.buffer?.byteLength??m.pack.bytes??0,bodyTris:hn(u,m.pack)}},h=await L();if(p&&a(h.bodyTris,h.packBytes)&&x==="full"&&t.lowCdn&&await ve(t.lowCdn,r).then(()=>!0,()=>!1)){x="low";let m=h;h=await L(),h.requests+=m.requests,h.bytes+=m.bytes}if(p&&a(h.bodyTris,h.packBytes))throw d(h);let{pack:g,missing:b,requests:C,bytes:F}=h,A=new Map([...f].map(([m,P])=>[P,m])),E=b.map((m)=>A.get(m)??m),T=performance.now(),k=t.cull?we(u,g.header,t.textures!==!1):void 0;return{insts:u,pack:g,tier:x,missing:E,requests:C,bytes:F,cull:k,timings:{fetchModel:i-n,parse:c-i,parts:T-c,...k?{cull:performance.now()-T}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await vt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=we(s.insts,s.pack.header,r.textures!==!1),u=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:u},c)}catch(s){if(s instanceof Le||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
4379
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/load-worker.gen.ts
4380
+ var load_worker_gen_default = 'var St=ArrayBuffer,Y=Uint8Array,ge=Uint16Array,Et=Int16Array;var de=Int32Array,Se=function(e,t,n){if(Y.prototype.slice)return Y.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new Y(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(Y.prototype.fill)return Y.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},Pt=function(e,t,n,r){if(Y.prototype.copyWithin)return Y.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var kt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],J=function(e,t,n){var r=Error(t||kt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,J);if(!n)throw r;return r},Xe=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},It=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Bt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)J(0);var u=6-s,c=i==3?4:i,f=Xe(e,u,c);u+=c;var a=l?1<<l:s,p=Xe(e,u,a)+(l==1&&256),d=p;if(!s){var x=1<<10+(e[5]>>3);d=x+(x>>3)*(e[5]&7)}if(d>2145386496)J(1);var y=new Y((t==1?p||d:t?0:d)+12);return y[0]=1,y[4]=4,y[8]=8,{b:u+a,y:0,l:0,d:f,w:t&&t!=1?t:y.subarray(12),e:d,o:new de(y.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return It(e,4)+8;J(0)},se=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)J(3);var o=1<<s,i=o,l=-1,u=-1,c=-1,f=o,a=new St(512+(o<<2)),p=new Et(a,0,256),d=new ge(a,0,256),x=new ge(a,512,o),y=512+(o<<1),S=new Y(a,y,o),h=new Y(a,y+o);while(l<255&&i>0){var g=se(i+1),b=r>>3,C=(1<<g+1)-1,R=(e[b]|e[b+1]<<8|e[b+2]<<16)>>(r&7)&C,M=(1<<g)-1,L=C-i-1,T=R&M;if(T<L)r+=g,R=T;else if(r+=g+1,R>M)R-=L;if(p[++l]=--R,R==-1)i+=R,S[--f]=l;else i-=R;if(!R)do{var k=r>>3;u=(e[k]|e[k+1]<<8)>>(r&7)&3,r+=2,l+=u}while(u==3)}if(l>255||i)J(0);var m=0,P=(o>>1)+(o>>3)+3,V=o-1;for(var N=0;N<=l;++N){var v=p[N];if(v<1){d[N]=-v;continue}for(c=0;c<v;++c){S[m]=N;do m=m+P&V;while(m>=f)}}if(m)J(0);for(c=0;c<o;++c){var A=d[S[c]]++,I=h[c]=s-se(A);x[c]=(A<<I)-o}return[r+7>>3,{b:s,s:S,n:h,t:x}]},Ft=function(e,t){var n=0,r=-1,s=new Y(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),u=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],a=c[1];t+=o;var p=f<<3,d=e[t];if(!d)J(0);var x=0,y=0,S=a.b,h=S,g=(++t<<3)-8+se(d);for(;;){if(g-=S,g<p)break;var b=g>>3;if(x+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<S)-1,i[++r]=a.s[x],g-=h,g<p)break;b=g>>3,y+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<h)-1,i[++r]=a.s[y],S=a.n[x],x=a.t[x],h=a.n[y],y=a.t[y]}if(++r>255)J(0)}else{r=o-127;for(;n<r;n+=2){var C=e[++t];i[n]=C>>4,i[n+1]=C&15}++t}var R=0;for(n=0;n<r;++n){var M=i[n];if(M>11)J(0);R+=M&&1<<M-1}var L=se(R)+1,T=1<<L,k=T-R;if(k&k-1)J(0);i[r++]=se(k)+1;for(n=0;n<r;++n){var M=i[n];++l[i[n]=M&&L+1-M]}var m=new Y(T<<1),P=m.subarray(0,T),V=m.subarray(T);u[L]=0;for(n=L;n>0;--n){var N=u[n];ce(V,n,N,u[n-1]=N+l[n]*(1<<L-n))}if(u[0]!=T)J(0);for(n=0;n<r;++n){var v=i[n];if(v){var A=u[v];ce(P,n,A,u[v]=A+(1<<L-v))}}return[t,{n:V,b:L,s:P}]},Rt=ue(new Y([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Dt=ue(new Y([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Ut=ue(new Y([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Ze=function(e,t){var n=e.length,r=new de(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Ee=new Y(new de([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Ot=Ze(Ee,0),Pe=new Y(new de([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Nt=Ze(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)J(0);var u=0,c=n.b,f=(r<<3)-8+se(o)-c,a=-1;for(;f>l&&a<s;){var p=f>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(f&7);u=(u<<c|d)&i,t[++a]=n.s[u],f-=c=n.n[u]}if(f!=l||a+1!=s)J(0)},zt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},$t=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,u=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new Y(l),e[s])}if(u>e.length)return;if(i==0){if(t.b=u,n)return n.set(e.subarray(s,u),t.y),t.y+=l,n;return Se(e,s,u)}if(i==2){var c=e[s],f=c&3,a=c>>2&3,p=c>>4,d=0,x=0;if(f<2)if(a&1)p|=e[++s]<<4|(a&2&&e[++s]<<12);else p=c>>3;else if(x=a,a<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var y=n?n.subarray(t.y,t.y+t.m):new Y(t.m),S=y.length-p;if(f==0)y.set(e.subarray(s,s+=p),S);else if(f==1)ce(y,e[s++],S);else{var h=t.h;if(f==2){var g=Ft(e,s);d+=s-(s=g[0]),t.h=h=g[1]}else if(!h)J(0);(x?zt:le)(e.subarray(s,s+=d),y.subarray(S),h)}var b=e[s++];if(b){if(b==255)b=(e[s++]|e[s++]<<8)+32512;else if(b>127)b=b-128<<8|e[s++];var C=e[s++];if(C&3)J(0);var R=[Dt,Ut,Rt];for(var M=2;M>-1;--M){var L=C>>(M<<1)+2&3;if(L==1){var T=new Y([0,0,e[s++]]);R[M]={s:T.subarray(2,3),n:T.subarray(0,1),t:new ge(T.buffer,0,1),b:0}}else if(L==2)r=ue(e,s,9-(M&1)),s=r[0],R[M]=r[1];else if(L==3){if(!t.t)J(0);R[M]=t.t[M]}}var k=t.t=R,m=k[0],P=k[1],V=k[2],N=e[u-1];if(!N)J(0);var v=(u<<3)-8+se(N)-V.b,A=v>>3,I=0,W=(e[A]|e[A+1]<<8)>>(v&7)&(1<<V.b)-1;A=(v-=P.b)>>3;var B=(e[A]|e[A+1]<<8)>>(v&7)&(1<<P.b)-1;A=(v-=m.b)>>3;var z=(e[A]|e[A+1]<<8)>>(v&7)&(1<<m.b)-1;for(++b;--b;){var _=V.s[W],Z=V.n[W],X=m.s[z],E=m.n[z],w=P.s[B],D=P.n[B];A=(v-=w)>>3;var U=1<<w,O=U+((e[A]|e[A+1]<<8|e[A+2]<<16|e[A+3]<<24)>>>(v&7)&U-1);A=(v-=Pe[X])>>3;var G=Nt[X]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(v&7)&(1<<Pe[X])-1);A=(v-=Ee[_])>>3;var j=Ot[_]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(v&7)&(1<<Ee[_])-1);if(A=(v-=Z)>>3,W=V.t[W]+((e[A]|e[A+1]<<8)>>(v&7)&(1<<Z)-1),A=(v-=E)>>3,z=m.t[z]+((e[A]|e[A+1]<<8)>>(v&7)&(1<<E)-1),A=(v-=D)>>3,B=P.t[B]+((e[A]|e[A+1]<<8)>>(v&7)&(1<<D)-1),O>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=O-=3;else{var H=O-(j!=0);if(H){if(O=H==3?t.o[0]-1:t.o[H],H>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=O}else O=t.o[0]}for(var M=0;M<j;++M)y[I+M]=y[S+M];I+=j,S+=j;var K=I-O;if(K<0){var F=-K,q=t.e+K;if(F>G)F=G;for(var M=0;M<F;++M)y[I+M]=t.w[q+M];I+=F,G-=F,K=0}for(var M=0;M<G;++M)y[I+M]=y[K+M];I+=G}if(I!=S)while(S<y.length)y[I++]=y[S++];else I=y.length;if(n)t.y+=I;else y=Se(y,0,I)}else if(n){if(t.y+=p,S)for(var M=0;M<p;++M)y[M]=y[S+M]}else if(S)y=Se(y,S);return t.b=u,y}J(2)},jt=function(e,t){if(e.length==1)return e[0];var n=new Y(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function be(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Bt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=$t(e,i,t);if(!l)J(5);if(t)i.e=i.y;else n.push(l),o+=l.length,Pt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return jt(n,o)}async function Vt(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(be(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function Ye(e){return new TextDecoder().decode(await Vt(e))}var qe=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function ye(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Q=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),Ie=/^[A-Za-z][A-Za-z0-9_]*$/,ke=new Map;function Be(e){let t=e.toLowerCase(),n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619);let r=-1-(n>>>0&1073741823);if(!ke.has(r))ke.set(r,t);return r}function Fe(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&Ie.test(e))return Be(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Je=/^~?\\s*moved\\s+to\\s+(.+)$/i,_t=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),it=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),Ht=new Set(["model","submodel","configuration"]),Gt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function Qe(e){let t=Gt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return it.has(n)||Ht.has(n)?n:void 0}function Wt(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function Kt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let a=0;a<s;a++)l=l.replace(/^\\S+\\s*/,"");let u=Wt(l);if(!u.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:u[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=u.findIndex((a,p)=>p>0&&a.toUpperCase()==="GLOSSMAP");if(f>0&&u[f+1])c.glossmap=u[f+1];if(t)c.next=!0;return c}var Xt=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Zt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),u=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Fe(o),m:i,file:Q(u)}}function et(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Fe(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Q(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function at(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,u=null,c=[],f=null,a=()=>{if(!u)return;let g=Xt(u.chunks.join("")),b=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Q(u.name),{name:u.name,bytes:g,...b?{mime:"image/png"}:{}}),u=null},p=!0,d=(g)=>{if(a(),o={name:Q(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,p=!0},x=!1,y=!1,S=()=>{if(y)return;y=!0,s.clear(),o=null,i=""},h=(g,b)=>{if(f){g.tex=f,f=null;return}let C=c[c.length-1];if(!C)return;if(C.fallback){if(!b)g.fallback=!0}else g.tex=C.map};for(let g of e.split(`\n`)){let b=g.trim();if(!b)continue;if(r&&b.charCodeAt(0)>=50&&b.charCodeAt(0)<=53&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)){if(u||x)continue;if(!o)d(t);let L=b.slice(2).trimStart(),T=L.search(/\\s/),k={t:b.charCodeAt(0)-48,color:Fe(T<0?L:L.slice(0,T)),p:[],src:b};h(k,!1),o.cmds.push(k),p=!1;continue}if(b.charCodeAt(0)===48&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)){let L=2;while(b.charCodeAt(L)===32||b.charCodeAt(L)===9)L++;let T=L;while(T<b.length&&b.charCodeAt(T)!==32&&b.charCodeAt(T)!==9)T++;let k=b.slice(L,T);if(!_t.has(k)){if(x||u)continue;if(!o)d(t);let m=b.slice(L),P={t:0,text:m};if(k.charCodeAt(0)===33)P.meta=k;if(f=null,p&&!o.org){let N=Qe(m);if(N)o.org=N}let V=m.match(Je);if(V&&!o.movedTo){let N=V[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(N))N+=".dat";o.movedTo=Q(N)}o.cmds.push(P);continue}}if(b.charCodeAt(0)===49&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)&&!u&&!x){let L=Zt(b);if(L){if(!o)d(t);h(L,!1),o.cmds.push(L),p=!1;continue}}let C=b.split(/\\s+/);if(+C[0]===0){let L=b.slice(1).trim();if(C[1]==="FILE"){S(),x=!1,d(L.slice(5));continue}if(C[1]==="NOFILE"){a(),o=null,x=!0;continue}if(C[1]==="!DATA"){S(),a(),o=null,x=!1,u={name:L.slice(5).trim(),chunks:[]};continue}if(x)continue;if(u){if(C[1]==="!:")u.chunks.push(C.slice(2).join(""));continue}if(!o)d(t);let T={t:0,text:L};if(C[1]==="STEP")T.step=!0,c=[],f=null;else if(C[1]==="BFC")T.bfc=C.slice(2).join(" ");else if(C[1]==="ROTSTEP")if(T.meta="ROTSTEP",T.step=!0,c=[],f=null,(C[2]??"").toUpperCase()==="END")T.rotstep={x:0,y:0,z:0,mode:"END"};else{let m=(C[5]??"REL").toUpperCase();T.rotstep={x:+C[2]||0,y:+C[3]||0,z:+C[4]||0,mode:["REL","ABS","ADD"].includes(m)?m:"REL"}}else if(C[1]==="BUFEXCHG"){T.meta="BUFEXCHG";let m=(C[2]??"").toUpperCase();T.bufexchg={op:m==="RETRIEVE"?"RETRIEVE":"STORE",buf:C[3]??"A"}}else if(C[1]?.startsWith("!"))T.meta=C[1];if(p&&!o.org){let m=Qe(L);if(m)o.org=m}if(C[1]==="!TEXMAP"){let m=(C[2]??"").toUpperCase();if(f=null,m==="START"||m==="NEXT"){let P=Kt(L.replace(/^!TEXMAP\\s+\\S+/i,""),m==="NEXT");if(T.texmap={op:m,...P?{map:P}:{}},P)if((o.texmaps??=[]).push(P),m==="START")c.push({map:P,fallback:!1});else f=P}else if(m==="FALLBACK"){T.texmap={op:m};let P=c[c.length-1];if(P)P.fallback=!0}else if(m==="END")T.texmap={op:m},c.pop()}else if(C[1]==="!:"){f=null;let m=et(C.slice(2));if(m)h(m,!0),T.geom=m}else f=null;let k=L.match(Je);if(k&&!o.movedTo){let m=k[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(m))m+=".dat";o.movedTo=Q(m)}o.cmds.push(T);continue}if(u||x)continue;if(!o)d(t);let M=et(C);if(!M)continue;h(M,!1),o.cmds.push(M),p=!1}return a(),l?{main:i,files:s,data:l}:{main:i,files:s}}var Mn=Math.PI/180;function lt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function ct(e,t){let[n,r,s,o,i,l,u,c,f,a,p,d]=e,[x,y,S,h,g,b,C,R,M,L,T,k]=t;return[o*x+i*y+l*S+n,u*x+c*y+f*S+r,a*x+p*y+d*S+s,o*h+i*C+l*L,o*g+i*R+l*T,o*b+i*M+l*k,u*h+c*C+f*L,u*g+c*R+f*T,u*b+c*M+f*k,a*h+p*C+d*L,a*g+p*R+d*T,a*b+p*M+d*k]}var Re=[0,0,0,1,0,0,0,1,0,0,0,1];var tt=new WeakMap,Yt=/^(s|8|48)\\//;function De(e,t){let n=e.files.get(Q(t));if(!n)return"part";let r=tt.get(n);if(r)return r;if(n.org)r=it.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&Yt.test(s.file))?"part":"model";return tt.set(n,r),r}var nt=new WeakMap;function ut(e){let t=nt.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return nt.set(e,t),t}var rt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?ke.get(e)??String(e):String(e),qt=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${rt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${rt(e.color)} ${e.p.join(" ")}`,Ue=(e,t)=>`${Q(e)}#${t}`;function Jt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0||o.meta==="!COLOUR"){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ue(e.name,t),cmds:n}}function ft(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Jt(e,t).cmds.map(qt)].join(`\n`)+`\n`}function Oe(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function pt(e){let[t,n,r,s,o,i,l,u,c,f,a,p]=e,d=u*p-c*a,x=-(l*p-c*f),y=l*a-u*f,S=s*d+o*x+i*y;if(!Number.isFinite(S)||Math.abs(S)<0.000000000001)return null;let h=1/S,g=[d*h,-(o*p-i*a)*h,(o*c-i*u)*h,x*h,(s*p-i*f)*h,-(s*c-i*l)*h,y*h,-(s*a-o*f)*h,(s*u-o*l)*h];return[-(g[0]*t+g[1]*n+g[2]*r),-(g[3]*t+g[4]*n+g[5]*r),-(g[6]*t+g[7]*n+g[8]*r),...g]}var Qt=(e)=>String(+e.toFixed(6)||0),st=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function mt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Qt).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${st(t.texture)}${t.glossmap?" GLOSSMAP "+st(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Q(e)}\n0 !TEXMAP END\n`;return{name:`${Q(e)}#tex-${Oe(r)}`,source:r}}var en=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function tn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),u=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*u,i,o*u+s*i*c,o*c-s*i*u,-s*l,s*u-o*i*c,s*c+o*i*u,o*l]}var ot=new WeakMap;function ht(e){let t=ot.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=tn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:en(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),ot.set(e,n),n}var gt=999999,yt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",xt=new WeakMap,dt=new WeakMap;function nn(e,t){let n=dt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=xt.get(o)??"",l=i.indexOf("!COLOUR");return l<0?"":"0 "+i.slice(l).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},dt.set(t,n);let r=n.parts.get(e);if(!r){let s=Q(e),o=`0 ldr: ${s} placed in a model\'s !COLOUR scope\n0 BFC CERTIFY CCW\n${n.head}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${s}\n`;r={name:`${s}#col-${Oe(o)}`,source:o},n.parts.set(e,r)}return r}function rn(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,u=0,c=(a,p)=>{let d=a.name+"#"+p,x=l.get(d);if(!x){let y;x=Object.assign(()=>y??=ft(a,p),{file:a,step:p}),l.set(d,x)}return x},f=(a,p,d,x,y,S,h,g,b=null,C=[],R=[],M=void 0,L=null)=>{let T=a.files.get(p);if(!T||h>r)return;let k=L,m=0,P=h>0?++u:0,V=i&&P?[...C,P]:C,N=i&&P?[...R,d]:R,v=i&&!b?new Map:null,A=-1,I=0,W=(E,w,D,U,O,G,j)=>{if(A!==m)A=m,I=0;let H=v?.get(m+"|"+w);if(H)return H.n++,f(E,E===a?w:E.main,D,U,y+"/"+w,[...O,gt],h+1,G,[...O,gt],V,N,j,k);let K=[...O,I++],F=n.length;f(E,E===a?w:E.main,D,U,y+"/"+w,K,h+1,G,b,V,N,j,k),v?.set(m+"|"+w,{n:1,from:F,to:n.length})},B=ht(T),z=s?ut(T):[],_=0,Z=(E,w,D,U,O,G,j,H,K)=>{if(b)U=b;let F={part:E,color:w,m:D,step:U[0],steps:U,localStep:O,path:y};if(H)F.colour=H;if(P){if(F.sub=P,i)F.subPath=V,F.subMats=N}if(G)F.embedded=!0;if(j){let ee=mt(E,j);F.texPart=ee.name,F.texSource=ee.source}else if(K){let ee=nn(E,K);F.colPart=ee.name,F.colSource=ee.source}let q=B[O];if(q)F.view=q;return n.push(F),F},X=(E)=>{while(_<z.length&&z[_]<=E){let w=z[_++];Z(Ue(T.name,w),x,d,[...S,w],w,!1,null,M,L).source=c(T,w)}};for(let E of T.cmds){if(E.t===0&&E.step){m++;continue}let w=E;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){X(m);continue}if(w.t===0){if(w.meta==="!COLOUR"){let q=on(w.text);if(q&&q.code!==16&&q.code!==24)xt.set(q,w.text),(k=new Map(k??[])).set(q.code,q);continue}if(o&&w.geom?.t===1)w=w.geom;else continue}if(w.t!==1)continue;if(o&&w.fallback)continue;let D=w.color===16?x:w.color,U=w.color===16?M:k?.get(w.color),O=ct(d,w.m),G=[...S,m],j=o?w.tex??g:null,H=j?pt(w.m):null,K=j&&H?lt(j,H):null;if(a.files.has(w.file)){if(De(a,w.file)==="model"){W(a,w.file,O,D,G,K,U);continue}Z(w.file,D,O,G,m,!0,K,U,k);continue}let F=t.resolveModel?.(w.file);if(F){W(F,w.file,O,D,G,K,U);continue}Z(w.file,D,O,G,m,!1,K,U,k)}if(X(1/0),v){for(let E of v.values())if(E.n>1)for(let w=E.from;w<E.to;w++)n[w].mult??=E.n}};if(De(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Re],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,Re,16,e.main,[],0,null),n}function wt(e,t="main.ldr",n){return rn(at(e,t,{geometryText:!0}),n)}var sn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function Ne(e){if(!e)return null;if(e.startsWith("#")&&/^#[0-9A-Fa-f]{6}$/.test(e))return e.toUpperCase();if(/^0x[0-9A-Fa-f]{6}$/i.test(e))return("#"+e.slice(2)).toUpperCase();return null}function bt(e,t){let n={value:"#FFFFFF",fraction:0.5};while(t<e.length){let r=e[t].toUpperCase(),s=e[t+1];if(r==="VALUE"){let o=Ne(s);if(o)n.value=o;t+=2}else if(r==="ALPHA")n.alpha=+s,t+=2;else if(r==="LUMINANCE")n.luminance=+s,t+=2;else if(r==="FRACTION")n.fraction=+s,t+=2;else if(r==="VFRACTION")n.vfraction=+s,t+=2;else if(r==="SIZE")n.size=+s,t+=2;else if(r==="MINSIZE")n.minsize=+s,t+=2;else if(r==="MAXSIZE")n.maxsize=+s,t+=2;else break}return{grain:n,next:t}}function on(e){let t=e.indexOf("!COLOUR");if(t<0)return null;let n=e.slice(t+7).trim().split(/\\s+/).filter(Boolean);if(n.length<2)return null;let r=n[0],s=NaN,o="#FF00FF",i="#333333",l=255,u=0,c={type:"default"},f=1;while(f<n.length){let a=n[f].toUpperCase(),p=n[f+1];if(a==="CODE")s=p!==void 0&&Ie.test(p)?Be(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,f+=2;else if(a==="VALUE"){let d=Ne(p);if(d)o=d;f+=2}else if(a==="EDGE")i=Ne(p)??p,f+=2;else if(a==="ALPHA")l=+p,f+=2;else if(a==="LUMINANCE")u=+p,f+=2;else if(a==="CHROME")c={type:"chrome"},f+=1;else if(a==="PEARLESCENT")c={type:"pearlescent"},f+=1;else if(a==="RUBBER")c={type:"rubber"},f+=1;else if(a==="MATTE_METALLIC")c={type:"matte_metallic"},f+=1;else if(a==="METAL")c={type:"metal"},f+=1;else if(a==="MATERIAL"){let d=(n[f+1]||"").toUpperCase();if(d==="GLITTER"){let{grain:x,next:y}=bt(n,f+2);c={type:"glitter",material:x},f=y}else if(d==="SPECKLE"){let{grain:x,next:y}=bt(n,f+2);c={type:"speckle",material:x},f=y}else if(d==="FABRIC"){let x=(n[f+2]||"").toUpperCase(),y=["VELVET","CANVAS","STRING","FUR"].includes(x)?x.toLowerCase():void 0;c={type:"fabric",kind:y},f+=y?3:2}else f=n.length}else if(sn.has(a))f+=1;else f+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(l)?l:255,luminance:Number.isFinite(u)?u:0,finish:c}}function an(e){let t=Math.max(0,Math.min(1,(e.alpha??255)/255)),n=t<1,r=Math.max(0,Math.min(1,(e.luminance??0)/255)),s={opacity:t,transparent:n,depthWrite:!n,emissive:r,clearcoat:0,clearcoatRoughness:0,sheen:0,sheenRoughness:0};switch(e.finish?.type??"default"){case"chrome":return{...s,metalness:1,roughness:0,finish:"chrome"};case"pearlescent":return{...s,metalness:0.25,roughness:0.3,clearcoat:0.5,clearcoatRoughness:0.25,sheen:0.4,sheenRoughness:0.35,finish:"pearlescent"};case"rubber":return{...s,metalness:0,roughness:0.9,finish:"rubber"};case"matte_metallic":return{...s,metalness:0.4,roughness:0.8,finish:"matte_metallic"};case"metal":return{...s,metalness:0.85,roughness:0.2,finish:"metal"};case"glitter":{let i=e.finish.material,l=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.35,roughness:0.25,clearcoat:1,clearcoatRoughness:0.08,particleHex:i.value,particleFraction:i.fraction,particleSize:l,finish:"glitter"}}case"speckle":{let i=e.finish.material,l=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.2,roughness:0.55,particleHex:i.value,particleFraction:i.fraction,particleSize:l,finish:"speckle"}}case"fabric":return{...s,metalness:0,roughness:0.85,sheen:0.65,sheenRoughness:0.75,finish:"fabric"};default:return{...s,metalness:0,roughness:0.45,finish:"default"}}}function ze(e){let t=an(e),n=!t.transparent?"op":t.opacity>=0.75?"a200":t.opacity>=0.4?"a128":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:"",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function ln(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Q(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Q(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var cn=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Q(t.slice(14).join(" ")):null};function un(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,"0")+(n>>>0).toString(16).padStart(8,"0")}function Mt(e,t,n="main.ldr"){let r=ln(e,n),s=new Map;for(let o of t){let i=Q(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),u=[i];while(u.length)for(let f of r.get(u.pop())){let a=cn(f);if(a&&r.has(a)&&!l.has(a))l.add(a),u.push(a)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>"0 FILE "+(f===i?"":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${un(c)}.dat`)}return s}var At=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,vt=new WeakMap;function $e(e,t){let n=vt.get(e);if(!n)vt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],u=[];s.studs.forEach((p,d)=>{l.push(p[0]),u.push(p[1]);for(let x=0;x<12;x++)i[d*12+x]=p[2+x]});let c=null,f=0,a=0;if(s.mask){f=s.mask[0],a=s.mask[1];let p=s.mask[2];c=new Uint8Array(p.length);for(let d=0;d<p.length;d++)c[d]=p.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:u,mask:c,nx:f,nz:a}),r}var ie=1073741824;class je{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,u=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,u[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&u[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function fn(e,t,n){let s=[],o=[],i=[],l=[],u=[],c=[],f=[],a=[],p=new je(e.length*2),d=[],x=[];for(let v=0;v<e.length;v++){let A=e[v],I=A.m,W=t.parts[A.part];if(!W||!W.mask||!At(I))continue;let B=W.bbox,z=1/0,_=-1/0,Z=1/0,X=-1/0;for(let D=0;D<2;D++)for(let U=0;U<2;U++){let O=D?B[3]:B[0],G=U?B[5]:B[2],j=I[0]+I[3]*O+I[5]*G,H=I[2]+I[9]*O+I[11]*G;if(j<z)z=j;if(j>_)_=j;if(H<Z)Z=H;if(H>X)X=H}let E=u.length;s.push(z),o.push(_),i.push(Z),l.push(X),u.push(v),c.push($e(t,A.part)),f.push(B[0]),a.push(B[2]);let w=Math.round((I[1]+B[4])*2);for(let D=Math.floor(z/40);D<=Math.floor(_/40);D++)for(let U=Math.floor(Z/40);U<=Math.floor(X/40);U++){if(!xe(w,D,U))continue;let O=x.length;x.push(E),d.push(p.put(w,D,U,O))}}let y=[0,5,-5,5,-5],S=[0,5,5,-5,-5],h=NaN,g=NaN,b=NaN,C=-1,R=(v,A,I,W)=>{let B=Math.round(A*2),z=Math.floor(v/40),_=Math.floor(I/40);if(!xe(B,z,_))return fe;let Z=fe;if(B!==h||z!==g||_!==b)h=B,g=z,b=_,C=p.get(B,z,_);for(let X=C;X>=0;X=d[X]){let E=x[X];if(u[E]===W||!(v-6>=s[E]-0.5&&v+6<=o[E]+0.5&&I-6>=i[E]-0.5&&I+6<=l[E]+0.5))continue;let w=e[u[E]].m,D=c[E],U=f[E],O=a[E],G=v-w[0],j=A-w[1],H=I-w[2],K=w[3]*G+w[6]*j+w[9]*H,F=w[5]*G+w[8]*j+w[11]*H,{nx:q,nz:ee,mask:ae}=D,oe=!0;for(let te=0;te<5;te++){let ne=Math.floor((K+y[te]-U)/20),re=Math.floor((F+S[te]-O)/20);if(ne<0||re<0||ne>=q||re>=ee||ae[ne*ee+re]!==1){oe=!1;break}}if(oe){if(!n)return 0;let te=n[u[E]];if(te<Z)Z=te}}return Z},M=0;for(let v of e){let A=$e(t,v.part);if(A)M+=A.nStuds}let L=new Uint8Array(M),T=new Uint8Array(M),k=new je(M),m=0,P=n?new Int32Array(M).fill(fe):void 0;for(let v=0,A=0;v<e.length;v++){let I=e[v],W=$e(t,I.part);if(!W)continue;let B=I.m,z=W.studM,_=B[0],Z=B[1],X=B[2],E=B[3],w=B[4],D=B[5],U=B[6],O=B[7],G=B[8],j=B[9],H=B[10],K=B[11];for(let F=0;F<W.nStuds;F++,A++){let q=F*12,ee=z[q+4],ae=z[q+7],oe=z[q+10];if(!(Math.abs(U*ee+O*ae+G*oe-1)<0.001&&Math.abs(E*ee+w*ae+D*oe)<0.001&&Math.abs(j*ee+H*ae+K*oe)<0.001))continue;T[A]=1;let te=z[q],ne=z[q+1],re=z[q+2],Ve=_+E*te+w*ne+D*re,_e=Z+U*te+O*ne+G*re,He=X+j*te+H*ne+K*re,Ge=R(Ve,_e,He,v);if(Ge!==fe){if(L[A]=1,m++,P)P[A]=Ge}let pe=Math.round(Ve),me=Math.round(_e),he=Math.round(He);if(!xe(pe,me,he))continue;if(!n){k.put(pe,me,he,1);continue}let We=n[v],Ke=k.get(pe,me,he);if(Ke<0||We<Ke)k.put(pe,me,he,We)}}let V=new Uint8Array(e.length),N=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let A=e[v],I=t.parts[A.part];if(!I||!I.under||!At(A.m))continue;let W=I.bbox,B=Math.round((W[3]-W[0])/20),z=Math.round((W[5]-W[2])/20);if(!B||!z||B*z>4096)continue;let _=A.m,Z=!0,X=0;for(let E=0;E<B&&Z;E++)for(let w=0;w<z;w++){let D=W[0]+10+20*E,U=W[2]+10+20*w,O=_[0]+_[3]*D+_[5]*U,G=_[2]+_[9]*D+_[11]*U,j=Math.round(O),H=Math.round(_[1]+W[4]),K=Math.round(G),F=xe(j,H,K)?k.get(j,H,K):-1;if(F<0){Z=!1;break}if(F>X)X=F}if(Z){if(V[v]=1,N)N[v]=X}}return{nStuds:M,studHidden:L,studUp:T,underHidden:V,studsHidden:m,studHideStep:P,underHideStep:N}}function pn(e,t,n){let r=(a)=>a.colPart&&t.parts[a.colPart]?a.colPart:n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=new Map,o=new Map,i=(a)=>{let p=a.colour;if(!p)return String(a.color);let d=o.get(p);if(d!==void 0)return d;let x=t.colorTable?.[a.color],y=x?.hex??t.colors?.[a.color],S=x?ze({alpha:x.alpha??255,luminance:x.luminance??0,finish:x.finish??{type:"default"}}):"default:op",h=ze(p);if(d=y&&y.toUpperCase()===p.hex.toUpperCase()&&S===h?String(a.color):p.hex.toUpperCase()+"/"+h,d!==String(a.color))s.set(d,p);return o.set(p,d),d},l=e.map((a)=>({part:r(a),color:i(a),m:a.m,steps:a.steps})),u=l.map((a)=>yt(a.steps)),c=[...new Set(u)].sort(),f=new Map(c.map((a,p)=>[a,p]));return{all:l,stepOf:u.map((a)=>f.get(a)),nSteps:c.length,localColours:s}}function we(e,t,n=!0){let r=pn(e,t,n);return fn(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Te="https://ldr-demo.vercel.app/cdn/v1/",Ae=new Map,Me=new Map;function ve(e=Te,t=fetch){let n=Ae.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>Ae.delete(e)),Ae.set(e,n);return n}var mn=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),Ce=(e,t)=>mn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ce(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ce(r,t)])):e;function hn(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let d=p.buffer;if(!d)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let x=new DataView(d).getUint32(0,!0),y=new Uint8Array(d,4+x),S=r;n.push(y),r+=y.byteLength;let h=(4-r%4)%4;if(h)n.push(new Uint8Array(h)),r+=h;for(let[g,b]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ce(b,S);for(let[g,b]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ce(b,S)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),u=(4-(4+l.length)%4)%4,c=4+l.length+u,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+u,!0),f.set(l,4),f.fill(32,4+l.length,c);let a=c;for(let p of n)f.set(p,a),a+=p.byteLength;return ye(f.buffer)}async function gn(e,t={}){e=[...e];try{return await Ct(e,t)}catch(n){let r=t.cdn??Te,s=t.fetch??fetch;Ae.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await Ct(e,{...t,fetch:o})}catch{throw n}}}async function Ct(e,t){let n=t.cdn??Te,r=t.fetch??fetch,s=t.gap??16384,o=await ve(n,r),i=[...new Set([...e].map(Q))],l=[],u=[];for(let h of i){if(Me.has(n+h))continue;let g=o.parts[h];if(g)u.push({name:h,off:g[0],len:g[1],file:g[2]??0});else l.push(h)}u.sort((h,g)=>h.file-g.file||h.off-g.off);let c=[];for(let h of u){let g=c[c.length-1];if(g&&g.file===h.file&&h.off-g.end<=s)g.end=Math.max(g.end,h.off+h.len),g.items.push(h);else c.push({file:h.file,start:h.off,end:h.off+h.len,items:[h]})}let f=0,a=0,p=0,d=new Map,x=async()=>{while(p<c.length){let h=c[p++],g=d.get(h.file);if(g)g=g.subarray(h.start,h.end);else{let b=await r(new URL(o.archives[h.file],n).href,{headers:{Range:`bytes=${h.start}-${h.end-1}`,"Accept-Encoding":"identity"}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);if(a++,g=new Uint8Array(await b.arrayBuffer()),f+=g.byteLength,b.status===200)d.set(h.file,g),g=g.subarray(h.start,h.end)}for(let b of h.items){let C=be(g.subarray(b.off-h.start,b.off-h.start+b.len)),R=C.buffer.slice(C.byteOffset,C.byteOffset+C.byteLength);Me.set(n+b.name,ye(R))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},x));let y=i.filter((h)=>Me.has(n+h)).map((h)=>Me.get(n+h));return{pack:y.length?hn(y,{colors:o.colors}):ye(dn(o.colors)),missing:l,requests:a,bytes:f}}function dn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function bn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function Tt(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let u=l.embedded?t.get(l.part):Q(l.part),c=u?n.parts[u]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(u))i.add(u),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class Le extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function Lt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=ve(t.cdn??Te,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(m)=>{if(!m.ok)throw Error(`ldr: ${m.status} fetching ${e}`);return Ye(await m.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?"main.ldr":qe(e)),u=wt(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(u),await s;let f=Mt(o,new Set(u.filter((m)=>m.embedded).map((m)=>m.part)),l),a=(m,P)=>t.maxBodyTris!=null&&m>t.maxBodyTris||t.maxPackBytes!=null&&P>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(m)=>new Le({...m,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),x="full";if(p){let m=Tt(u,f,await s);if(a(m.known?m.bodyTris:0,m.packBytes)){if(!t.lowCdn)throw d(m);let P=await ve(t.lowCdn,r).catch(()=>null);if(!P)throw d(m);let V=Tt(u,f,P);if(a(V.known?V.bodyTris:0,V.packBytes))throw d(V);x="low"}}let y=[...u.filter((m)=>!m.embedded).map((m)=>m.part),...f.values()],S=async()=>{let m=await gn(y,x==="low"?{...t,cdn:t.lowCdn}:t);for(let[P,V]of f){let N=m.pack.header.parts[V];if(N)m.pack.header.parts[P]=N}return{...m,packBytes:m.pack.buffer?.byteLength??m.pack.bytes??0,bodyTris:bn(u,m.pack)}},h=await S();if(p&&a(h.bodyTris,h.packBytes)&&x==="full"&&t.lowCdn&&await ve(t.lowCdn,r).then(()=>!0,()=>!1)){x="low";let m=h;h=await S(),h.requests+=m.requests,h.bytes+=m.bytes}if(p&&a(h.bodyTris,h.packBytes))throw d(h);let{pack:g,missing:b,requests:C,bytes:R}=h,M=new Map([...f].map(([m,P])=>[P,m])),L=b.map((m)=>M.get(m)??m),T=performance.now(),k=t.cull?we(u,g.header,t.textures!==!1):void 0;return{insts:u,pack:g,tier:x,missing:L,requests:C,bytes:R,cull:k,timings:{fetchModel:i-n,parse:c-i,parts:T-c,...k?{cull:performance.now()-T}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await Lt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=we(s.insts,s.pack.header,r.textures!==!1),u=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:u},c)}catch(s){if(s instanceof Le||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
4349
4381
 
4350
- // ../../../../../../../tmp/ldr-build-JOxLfU/src/cdn.ts
4382
+ // ../../../../../../../tmp/ldr-build-P0dzRz/src/cdn.ts
4351
4383
  var worker;
4352
4384
  var seq = 0;
4353
4385
  var pending = new Map;
@@ -1,2 +1,2 @@
1
- declare const _default: "var Ct=ArrayBuffer,q=Uint8Array,ge=Uint16Array,Tt=Int16Array;var de=Int32Array,Ee=function(e,t,n){if(q.prototype.slice)return q.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new q(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(q.prototype.fill)return q.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},Lt=function(e,t,n,r){if(q.prototype.copyWithin)return q.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var Et=[\"invalid zstd data\",\"window size too large (>2046MB)\",\"invalid block type\",\"FSE accuracy too high\",\"match distance too far back\",\"unexpected EOF\"],Y=function(e,t,n){var r=Error(t||Et[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Y);if(!n)throw r;return r},We=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},St=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Pt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)Y(0);var u=6-s,c=i==3?4:i,f=We(e,u,c);u+=c;var a=l?1<<l:s,p=We(e,u,a)+(l==1&&256),d=p;if(!s){var x=1<<10+(e[5]>>3);d=x+(x>>3)*(e[5]&7)}if(d>2145386496)Y(1);var y=new q((t==1?p||d:t?0:d)+12);return y[0]=1,y[4]=4,y[8]=8,{b:u+a,y:0,l:0,d:f,w:t&&t!=1?t:y.subarray(12),e:d,o:new de(y.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return St(e,4)+8;Y(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Y(3);var o=1<<s,i=o,l=-1,u=-1,c=-1,f=o,a=new Ct(512+(o<<2)),p=new Tt(a,0,256),d=new ge(a,0,256),x=new ge(a,512,o),y=512+(o<<1),L=new q(a,y,o),h=new q(a,y+o);while(l<255&&i>0){var g=re(i+1),b=r>>3,C=(1<<g+1)-1,F=(e[b]|e[b+1]<<8|e[b+2]<<16)>>(r&7)&C,A=(1<<g)-1,E=C-i-1,T=F&A;if(T<E)r+=g,F=T;else if(r+=g+1,F>A)F-=E;if(p[++l]=--F,F==-1)i+=F,L[--f]=l;else i-=F;if(!F)do{var k=r>>3;u=(e[k]|e[k+1]<<8)>>(r&7)&3,r+=2,l+=u}while(u==3)}if(l>255||i)Y(0);var m=0,P=(o>>1)+(o>>3)+3,V=o-1;for(var N=0;N<=l;++N){var v=p[N];if(v<1){d[N]=-v;continue}for(c=0;c<v;++c){L[m]=N;do m=m+P&V;while(m>=f)}}if(m)Y(0);for(c=0;c<o;++c){var M=d[L[c]]++,I=h[c]=s-re(M);x[c]=(M<<I)-o}return[r+7>>3,{b:s,s:L,n:h,t:x}]},kt=function(e,t){var n=0,r=-1,s=new q(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),u=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],a=c[1];t+=o;var p=f<<3,d=e[t];if(!d)Y(0);var x=0,y=0,L=a.b,h=L,g=(++t<<3)-8+re(d);for(;;){if(g-=L,g<p)break;var b=g>>3;if(x+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<L)-1,i[++r]=a.s[x],g-=h,g<p)break;b=g>>3,y+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<h)-1,i[++r]=a.s[y],L=a.n[x],x=a.t[x],h=a.n[y],y=a.t[y]}if(++r>255)Y(0)}else{r=o-127;for(;n<r;n+=2){var C=e[++t];i[n]=C>>4,i[n+1]=C&15}++t}var F=0;for(n=0;n<r;++n){var A=i[n];if(A>11)Y(0);F+=A&&1<<A-1}var E=re(F)+1,T=1<<E,k=T-F;if(k&k-1)Y(0);i[r++]=re(k)+1;for(n=0;n<r;++n){var A=i[n];++l[i[n]=A&&E+1-A]}var m=new q(T<<1),P=m.subarray(0,T),V=m.subarray(T);u[E]=0;for(n=E;n>0;--n){var N=u[n];ce(V,n,N,u[n-1]=N+l[n]*(1<<E-n))}if(u[0]!=T)Y(0);for(n=0;n<r;++n){var v=i[n];if(v){var M=u[v];ce(P,n,M,u[v]=M+(1<<E-v))}}return[t,{n:V,b:E,s:P}]},It=ue(new q([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Bt=ue(new q([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Ft=ue(new q([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Xe=function(e,t){var n=e.length,r=new de(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new q(new de([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Rt=Xe(Se,0),Pe=new q(new de([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Dt=Xe(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)Y(0);var u=0,c=n.b,f=(r<<3)-8+re(o)-c,a=-1;for(;f>l&&a<s;){var p=f>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(f&7);u=(u<<c|d)&i,t[++a]=n.s[u],f-=c=n.n[u]}if(f!=l||a+1!=s)Y(0)},Ut=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},Ot=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,u=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new q(l),e[s])}if(u>e.length)return;if(i==0){if(t.b=u,n)return n.set(e.subarray(s,u),t.y),t.y+=l,n;return Ee(e,s,u)}if(i==2){var c=e[s],f=c&3,a=c>>2&3,p=c>>4,d=0,x=0;if(f<2)if(a&1)p|=e[++s]<<4|(a&2&&e[++s]<<12);else p=c>>3;else if(x=a,a<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var y=n?n.subarray(t.y,t.y+t.m):new q(t.m),L=y.length-p;if(f==0)y.set(e.subarray(s,s+=p),L);else if(f==1)ce(y,e[s++],L);else{var h=t.h;if(f==2){var g=kt(e,s);d+=s-(s=g[0]),t.h=h=g[1]}else if(!h)Y(0);(x?Ut:le)(e.subarray(s,s+=d),y.subarray(L),h)}var b=e[s++];if(b){if(b==255)b=(e[s++]|e[s++]<<8)+32512;else if(b>127)b=b-128<<8|e[s++];var C=e[s++];if(C&3)Y(0);var F=[Bt,Ft,It];for(var A=2;A>-1;--A){var E=C>>(A<<1)+2&3;if(E==1){var T=new q([0,0,e[s++]]);F[A]={s:T.subarray(2,3),n:T.subarray(0,1),t:new ge(T.buffer,0,1),b:0}}else if(E==2)r=ue(e,s,9-(A&1)),s=r[0],F[A]=r[1];else if(E==3){if(!t.t)Y(0);F[A]=t.t[A]}}var k=t.t=F,m=k[0],P=k[1],V=k[2],N=e[u-1];if(!N)Y(0);var v=(u<<3)-8+re(N)-V.b,M=v>>3,I=0,K=(e[M]|e[M+1]<<8)>>(v&7)&(1<<V.b)-1;M=(v-=P.b)>>3;var B=(e[M]|e[M+1]<<8)>>(v&7)&(1<<P.b)-1;M=(v-=m.b)>>3;var z=(e[M]|e[M+1]<<8)>>(v&7)&(1<<m.b)-1;for(++b;--b;){var _=V.s[K],Z=V.n[K],X=m.s[z],S=m.n[z],w=P.s[B],R=P.n[B];M=(v-=w)>>3;var D=1<<w,U=D+((e[M]|e[M+1]<<8|e[M+2]<<16|e[M+3]<<24)>>>(v&7)&D-1);M=(v-=Pe[X])>>3;var G=Dt[X]+((e[M]|e[M+1]<<8|e[M+2]<<16)>>(v&7)&(1<<Pe[X])-1);M=(v-=Se[_])>>3;var j=Rt[_]+((e[M]|e[M+1]<<8|e[M+2]<<16)>>(v&7)&(1<<Se[_])-1);if(M=(v-=Z)>>3,K=V.t[K]+((e[M]|e[M+1]<<8)>>(v&7)&(1<<Z)-1),M=(v-=S)>>3,z=m.t[z]+((e[M]|e[M+1]<<8)>>(v&7)&(1<<S)-1),M=(v-=R)>>3,B=P.t[B]+((e[M]|e[M+1]<<8)>>(v&7)&(1<<R)-1),U>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=U-=3;else{var H=U-(j!=0);if(H){if(U=H==3?t.o[0]-1:t.o[H],H>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=U}else U=t.o[0]}for(var A=0;A<j;++A)y[I+A]=y[L+A];I+=j,L+=j;var O=I-U;if(O<0){var W=-O,J=t.e+O;if(W>G)W=G;for(var A=0;A<W;++A)y[I+A]=t.w[J+A];I+=W,G-=W,O=0}for(var A=0;A<G;++A)y[I+A]=y[O+A];I+=G}if(I!=L)while(L<y.length)y[I++]=y[L++];else I=y.length;if(n)t.y+=I;else y=Ee(y,0,I)}else if(n){if(t.y+=p,L)for(var A=0;A<p;++A)y[A]=y[L+A]}else if(L)y=Ee(y,L);return t.b=u,y}Y(2)},Nt=function(e,t){if(e.length==1)return e[0];var n=new q(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function be(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Pt(e,r||t);if(typeof i==\"object\"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=Ot(e,i,t);if(!l)Y(5);if(t)i.e=i.y;else n.push(l),o+=l.length,Lt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Nt(n,o)}async function zt(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(be(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream(\"gzip\"))).arrayBuffer();return n(t)}async function Ze(e){return new TextDecoder().decode(await zt(e))}var qe=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\").replace(/\\.(zst|gz)$/i,\"\")||\"main.ldr\";function ye(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]===\"f32\"?new Float32Array(e,r+o[0],o[1]):o[2]===\"u16\"?new Uint16Array(e,r+o[0],o[1]):o[2]===\"u8\"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Q=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\"),Ie=/^[A-Za-z][A-Za-z0-9_]*$/,ke=new Map;function Be(e){let t=e.toLowerCase(),n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619);let r=-1-(n>>>0&1073741823);if(!ke.has(r))ke.set(r,t);return r}function Fe(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&Ie.test(e))return Be(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ye=/^~?\\s*moved\\s+to\\s+(.+)$/i,$t=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),ot=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),jt=new Set([\"model\",\"submodel\",\"configuration\"]),Vt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function Je(e){let t=Vt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return ot.has(n)||jt.has(n)?n:void 0}function _t(e){let t=[],n=0;while(n<e.length){while(e[n]===\" \"||e[n]===\"\\t\")n++;if(n>=e.length)break;if(e[n]==='\"'){let r=\"\";n++;while(n<e.length&&e[n]!=='\"'){if(e[n]===\"\\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==\" \"&&e[r]!==\"\\t\")r++;t.push(e.slice(n,r)),n=r}}return t}function Ht(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r===\"PLANAR\"?9:r===\"CYLINDRICAL\"?10:r===\"SPHERICAL\"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let a=0;a<s;a++)l=l.replace(/^\\S+\\s*/,\"\");let u=_t(l);if(!u.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:u[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=u.findIndex((a,p)=>p>0&&a.toUpperCase()===\"GLOSSMAP\");if(f>0&&u[f+1])c.glossmap=u[f+1];if(t)c.next=!0;return c}var Gt=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\"),n=t+\"=\".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Kt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),u=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(\" \"):l;return{t:1,color:Fe(o),m:i,file:Q(u)}}function Qe(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Fe(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Q(e.slice(14).join(\" \"))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function it(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,s=new Map,o=null,i=\"\",l,u=null,c=[],f=null,a=()=>{if(!u)return;let g=Gt(u.chunks.join(\"\")),b=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Q(u.name),{name:u.name,bytes:g,...b?{mime:\"image/png\"}:{}}),u=null},p=!0,d=(g)=>{if(a(),o={name:Q(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,p=!0},x=!1,y=!1,L=()=>{if(y)return;y=!0,s.clear(),o=null,i=\"\"},h=(g,b)=>{if(f){g.tex=f,f=null;return}let C=c[c.length-1];if(!C)return;if(C.fallback){if(!b)g.fallback=!0}else g.tex=C.map};for(let g of e.split(`\n`)){let b=g.trim();if(!b)continue;if(r&&b.charCodeAt(0)>=50&&b.charCodeAt(0)<=53&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)){if(u||x)continue;if(!o)d(t);let E=b.slice(2).trimStart(),T=E.search(/\\s/),k={t:b.charCodeAt(0)-48,color:Fe(T<0?E:E.slice(0,T)),p:[],src:b};h(k,!1),o.cmds.push(k),p=!1;continue}if(b.charCodeAt(0)===48&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)){let E=2;while(b.charCodeAt(E)===32||b.charCodeAt(E)===9)E++;let T=E;while(T<b.length&&b.charCodeAt(T)!==32&&b.charCodeAt(T)!==9)T++;let k=b.slice(E,T);if(!$t.has(k)){if(x||u)continue;if(!o)d(t);let m=b.slice(E),P={t:0,text:m};if(k.charCodeAt(0)===33)P.meta=k;if(f=null,p&&!o.org){let N=Je(m);if(N)o.org=N}let V=m.match(Ye);if(V&&!o.movedTo){let N=V[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(N))N+=\".dat\";o.movedTo=Q(N)}o.cmds.push(P);continue}}if(b.charCodeAt(0)===49&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)&&!u&&!x){let E=Kt(b);if(E){if(!o)d(t);h(E,!1),o.cmds.push(E),p=!1;continue}}let C=b.split(/\\s+/);if(+C[0]===0){let E=b.slice(1).trim();if(C[1]===\"FILE\"){L(),x=!1,d(E.slice(5));continue}if(C[1]===\"NOFILE\"){a(),o=null,x=!0;continue}if(C[1]===\"!DATA\"){L(),a(),o=null,x=!1,u={name:E.slice(5).trim(),chunks:[]};continue}if(x)continue;if(u){if(C[1]===\"!:\")u.chunks.push(C.slice(2).join(\"\"));continue}if(!o)d(t);let T={t:0,text:E};if(C[1]===\"STEP\")T.step=!0,c=[],f=null;else if(C[1]===\"BFC\")T.bfc=C.slice(2).join(\" \");else if(C[1]===\"ROTSTEP\")if(T.meta=\"ROTSTEP\",T.step=!0,c=[],f=null,(C[2]??\"\").toUpperCase()===\"END\")T.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let m=(C[5]??\"REL\").toUpperCase();T.rotstep={x:+C[2]||0,y:+C[3]||0,z:+C[4]||0,mode:[\"REL\",\"ABS\",\"ADD\"].includes(m)?m:\"REL\"}}else if(C[1]===\"BUFEXCHG\"){T.meta=\"BUFEXCHG\";let m=(C[2]??\"\").toUpperCase();T.bufexchg={op:m===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:C[3]??\"A\"}}else if(C[1]?.startsWith(\"!\"))T.meta=C[1];if(p&&!o.org){let m=Je(E);if(m)o.org=m}if(C[1]===\"!TEXMAP\"){let m=(C[2]??\"\").toUpperCase();if(f=null,m===\"START\"||m===\"NEXT\"){let P=Ht(E.replace(/^!TEXMAP\\s+\\S+/i,\"\"),m===\"NEXT\");if(T.texmap={op:m,...P?{map:P}:{}},P)if((o.texmaps??=[]).push(P),m===\"START\")c.push({map:P,fallback:!1});else f=P}else if(m===\"FALLBACK\"){T.texmap={op:m};let P=c[c.length-1];if(P)P.fallback=!0}else if(m===\"END\")T.texmap={op:m},c.pop()}else if(C[1]===\"!:\"){f=null;let m=Qe(C.slice(2));if(m)h(m,!0),T.geom=m}else f=null;let k=E.match(Ye);if(k&&!o.movedTo){let m=k[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(m))m+=\".dat\";o.movedTo=Q(m)}o.cmds.push(T);continue}if(u||x)continue;if(!o)d(t);let A=Qe(C);if(!A)continue;h(A,!1),o.cmds.push(A),p=!1}return a(),l?{main:i,files:s,data:l}:{main:i,files:s}}var yn=Math.PI/180;function at(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function lt(e,t){let[n,r,s,o,i,l,u,c,f,a,p,d]=e,[x,y,L,h,g,b,C,F,A,E,T,k]=t;return[o*x+i*y+l*L+n,u*x+c*y+f*L+r,a*x+p*y+d*L+s,o*h+i*C+l*E,o*g+i*F+l*T,o*b+i*A+l*k,u*h+c*C+f*E,u*g+c*F+f*T,u*b+c*A+f*k,a*h+p*C+d*E,a*g+p*F+d*T,a*b+p*A+d*k]}var Re=[0,0,0,1,0,0,0,1,0,0,0,1];var et=new WeakMap,Wt=/^(s|8|48)\\//;function De(e,t){let n=e.files.get(Q(t));if(!n)return\"part\";let r=et.get(n);if(r)return r;if(n.org)r=ot.has(n.org)?\"part\":\"model\";else if(n.name===e.main)r=\"model\";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&Wt.test(s.file))?\"part\":\"model\";return et.set(n,r),r}var tt=new WeakMap;function ct(e){let t=tt.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return tt.set(e,t),t}var nt=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():e<0?ke.get(e)??String(e):String(e),Xt=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${nt(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${nt(e.color)} ${e.p.join(\" \")}`,Ue=(e,t)=>`${Q(e)}#${t}`;function Zt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op===\"NEXT\";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0||o.meta===\"!COLOUR\"){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ue(e.name,t),cmds:n}}function ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Zt(e,t).cmds.map(Xt)].join(`\n`)+`\n`}function qt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,\"0\")}function ft(e){let[t,n,r,s,o,i,l,u,c,f,a,p]=e,d=u*p-c*a,x=-(l*p-c*f),y=l*a-u*f,L=s*d+o*x+i*y;if(!Number.isFinite(L)||Math.abs(L)<0.000000000001)return null;let h=1/L,g=[d*h,-(o*p-i*a)*h,(o*c-i*u)*h,x*h,(s*p-i*f)*h,-(s*c-i*l)*h,y*h,-(s*a-o*f)*h,(s*u-o*l)*h];return[-(g[0]*t+g[1]*n+g[2]*r),-(g[3]*t+g[4]*n+g[5]*r),-(g[6]*t+g[7]*n+g[8]*r),...g]}var Yt=(e)=>String(+e.toFixed(6)||0),rt=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function pt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map(Yt).join(\" \"),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${rt(t.texture)}${t.glossmap?\" GLOSSMAP \"+rt(t.glossmap):\"\"}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Q(e)}\n0 !TEXMAP END\n`;return{name:`${Q(e)}#tex-${qt(r)}`,source:r}}var Jt=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Qt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),u=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*u,i,o*u+s*i*c,o*c-s*i*u,-s*l,s*u-o*i*c,s*c+o*i*u,o*l]}var st=new WeakMap;function mt(e){let t=st.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode===\"END\")r=null;else{let i=Qt(o.x,o.y,o.z);r=o.mode===\"ABS\"?{abs:!0,m:i,rotstep:o}:o.mode===\"ADD\"&&r?{abs:r.abs,m:Jt(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),st.set(e,n),n}var ht=999999,dt=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\";function en(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,u=0,c=(a,p)=>{let d=a.name+\"#\"+p,x=l.get(d);if(!x){let y;x=Object.assign(()=>y??=ut(a,p),{file:a,step:p}),l.set(d,x)}return x},f=(a,p,d,x,y,L,h,g,b=null,C=[],F=[],A=void 0,E=null)=>{let T=a.files.get(p);if(!T||h>r)return;let k=E,m=0,P=h>0?++u:0,V=i&&P?[...C,P]:C,N=i&&P?[...F,d]:F,v=i&&!b?new Map:null,M=-1,I=0,K=(S,w,R,D,U,G,j)=>{if(M!==m)M=m,I=0;let H=v?.get(m+\"|\"+w);if(H)return H.n++,f(S,S===a?w:S.main,R,D,y+\"/\"+w,[...U,ht],h+1,G,[...U,ht],V,N,j,k);let O=[...U,I++],W=n.length;f(S,S===a?w:S.main,R,D,y+\"/\"+w,O,h+1,G,b,V,N,j,k),v?.set(m+\"|\"+w,{n:1,from:W,to:n.length})},B=mt(T),z=s?ct(T):[],_=0,Z=(S,w,R,D,U,G,j,H)=>{if(b)D=b;let O={part:S,color:w,m:R,step:D[0],steps:D,localStep:U,path:y};if(H)O.colour=H;if(P){if(O.sub=P,i)O.subPath=V,O.subMats=N}if(G)O.embedded=!0;if(j){let J=pt(S,j);O.texPart=J.name,O.texSource=J.source}let W=B[U];if(W)O.view=W;return n.push(O),O},X=(S)=>{while(_<z.length&&z[_]<=S){let w=z[_++];Z(Ue(T.name,w),x,d,[...L,w],w,!1,null,A).source=c(T,w)}};for(let S of T.cmds){if(S.t===0&&S.step){m++;continue}let w=S;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){X(m);continue}if(w.t===0){if(w.meta===\"!COLOUR\"){let J=nn(w.text);if(J&&J.code!==16&&J.code!==24)(k=new Map(k??[])).set(J.code,J);continue}if(o&&w.geom?.t===1)w=w.geom;else continue}if(w.t!==1)continue;if(o&&w.fallback)continue;let R=w.color===16?x:w.color,D=w.color===16?A:k?.get(w.color),U=lt(d,w.m),G=[...L,m],j=o?w.tex??g:null,H=j?ft(w.m):null,O=j&&H?at(j,H):null;if(a.files.has(w.file)){if(De(a,w.file)===\"model\"){K(a,w.file,U,R,G,O,D);continue}Z(w.file,R,U,G,m,!0,O,D);continue}let W=t.resolveModel?.(w.file);if(W){K(W,w.file,U,R,G,O,D);continue}Z(w.file,R,U,G,m,!1,O,D)}if(X(1/0),v){for(let S of v.values())if(S.n>1)for(let w=S.from;w<S.to;w++)n[w].mult??=S.n}};if(De(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Re],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,Re,16,e.main,[],0,null),n}function bt(e,t=\"main.ldr\",n){return en(it(e,t,{geometryText:!0}),n)}var tn=new Set([\"CHROME\",\"PEARLESCENT\",\"RUBBER\",\"MATTE_METALLIC\",\"METAL\",\"MATERIAL\"]);function Oe(e){if(!e)return null;if(e.startsWith(\"#\")&&/^#[0-9A-Fa-f]{6}$/.test(e))return e.toUpperCase();if(/^0x[0-9A-Fa-f]{6}$/i.test(e))return(\"#\"+e.slice(2)).toUpperCase();return null}function gt(e,t){let n={value:\"#FFFFFF\",fraction:0.5};while(t<e.length){let r=e[t].toUpperCase(),s=e[t+1];if(r===\"VALUE\"){let o=Oe(s);if(o)n.value=o;t+=2}else if(r===\"ALPHA\")n.alpha=+s,t+=2;else if(r===\"LUMINANCE\")n.luminance=+s,t+=2;else if(r===\"FRACTION\")n.fraction=+s,t+=2;else if(r===\"VFRACTION\")n.vfraction=+s,t+=2;else if(r===\"SIZE\")n.size=+s,t+=2;else if(r===\"MINSIZE\")n.minsize=+s,t+=2;else if(r===\"MAXSIZE\")n.maxsize=+s,t+=2;else break}return{grain:n,next:t}}function nn(e){let t=e.indexOf(\"!COLOUR\");if(t<0)return null;let n=e.slice(t+7).trim().split(/\\s+/).filter(Boolean);if(n.length<2)return null;let r=n[0],s=NaN,o=\"#FF00FF\",i=\"#333333\",l=255,u=0,c={type:\"default\"},f=1;while(f<n.length){let a=n[f].toUpperCase(),p=n[f+1];if(a===\"CODE\")s=p!==void 0&&Ie.test(p)?Be(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,f+=2;else if(a===\"VALUE\"){let d=Oe(p);if(d)o=d;f+=2}else if(a===\"EDGE\")i=Oe(p)??p,f+=2;else if(a===\"ALPHA\")l=+p,f+=2;else if(a===\"LUMINANCE\")u=+p,f+=2;else if(a===\"CHROME\")c={type:\"chrome\"},f+=1;else if(a===\"PEARLESCENT\")c={type:\"pearlescent\"},f+=1;else if(a===\"RUBBER\")c={type:\"rubber\"},f+=1;else if(a===\"MATTE_METALLIC\")c={type:\"matte_metallic\"},f+=1;else if(a===\"METAL\")c={type:\"metal\"},f+=1;else if(a===\"MATERIAL\"){let d=(n[f+1]||\"\").toUpperCase();if(d===\"GLITTER\"){let{grain:x,next:y}=gt(n,f+2);c={type:\"glitter\",material:x},f=y}else if(d===\"SPECKLE\"){let{grain:x,next:y}=gt(n,f+2);c={type:\"speckle\",material:x},f=y}else if(d===\"FABRIC\"){let x=(n[f+2]||\"\").toUpperCase(),y=[\"VELVET\",\"CANVAS\",\"STRING\",\"FUR\"].includes(x)?x.toLowerCase():void 0;c={type:\"fabric\",kind:y},f+=y?3:2}else f=n.length}else if(tn.has(a))f+=1;else f+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(l)?l:255,luminance:Number.isFinite(u)?u:0,finish:c}}function rn(e){let t=Math.max(0,Math.min(1,(e.alpha??255)/255)),n=t<1,r=Math.max(0,Math.min(1,(e.luminance??0)/255)),s={opacity:t,transparent:n,depthWrite:!n,emissive:r,clearcoat:0,clearcoatRoughness:0,sheen:0,sheenRoughness:0};switch(e.finish?.type??\"default\"){case\"chrome\":return{...s,metalness:1,roughness:0,finish:\"chrome\"};case\"pearlescent\":return{...s,metalness:0.25,roughness:0.3,clearcoat:0.5,clearcoatRoughness:0.25,sheen:0.4,sheenRoughness:0.35,finish:\"pearlescent\"};case\"rubber\":return{...s,metalness:0,roughness:0.9,finish:\"rubber\"};case\"matte_metallic\":return{...s,metalness:0.4,roughness:0.8,finish:\"matte_metallic\"};case\"metal\":return{...s,metalness:0.85,roughness:0.2,finish:\"metal\"};case\"glitter\":{let i=e.finish.material,l=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.35,roughness:0.25,clearcoat:1,clearcoatRoughness:0.08,particleHex:i.value,particleFraction:i.fraction,particleSize:l,finish:\"glitter\"}}case\"speckle\":{let i=e.finish.material,l=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.2,roughness:0.55,particleHex:i.value,particleFraction:i.fraction,particleSize:l,finish:\"speckle\"}}case\"fabric\":return{...s,metalness:0,roughness:0.85,sheen:0.65,sheenRoughness:0.75,finish:\"fabric\"};default:return{...s,metalness:0,roughness:0.45,finish:\"default\"}}}function Ne(e){let t=rn(e),n=!t.transparent?\"op\":t.opacity>=0.75?\"a200\":t.opacity>=0.4?\"a128\":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:\"\",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function sn(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Q(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Q(t),r)}let l=o.trim().replace(/\\s+/g,\" \");if(l)r.push(l)}return n}var on=(e)=>{if(!e.startsWith(\"1 \"))return null;let t=e.split(\" \");return t.length>=15?Q(t.slice(14).join(\" \")):null};function an(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,\"0\")+(n>>>0).toString(16).padStart(8,\"0\")}function yt(e,t,n=\"main.ldr\"){let r=sn(e,n),s=new Map;for(let o of t){let i=Q(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),u=[i];while(u.length)for(let f of r.get(u.pop())){let a=on(f);if(a&&r.has(a)&&!l.has(a))l.add(a),u.push(a)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>\"0 FILE \"+(f===i?\"\":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${an(c)}.dat`)}return s}var xt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,wt=new WeakMap;function ze(e,t){let n=wt.get(e);if(!n)wt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],u=[];s.studs.forEach((p,d)=>{l.push(p[0]),u.push(p[1]);for(let x=0;x<12;x++)i[d*12+x]=p[2+x]});let c=null,f=0,a=0;if(s.mask){f=s.mask[0],a=s.mask[1];let p=s.mask[2];c=new Uint8Array(p.length);for(let d=0;d<p.length;d++)c[d]=p.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:u,mask:c,nx:f,nz:a}),r}var ie=1073741824;class $e{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,u=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,u[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&u[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function ln(e,t,n){let s=[],o=[],i=[],l=[],u=[],c=[],f=[],a=[],p=new $e(e.length*2),d=[],x=[];for(let v=0;v<e.length;v++){let M=e[v],I=M.m,K=t.parts[M.part];if(!K||!K.mask||!xt(I))continue;let B=K.bbox,z=1/0,_=-1/0,Z=1/0,X=-1/0;for(let R=0;R<2;R++)for(let D=0;D<2;D++){let U=R?B[3]:B[0],G=D?B[5]:B[2],j=I[0]+I[3]*U+I[5]*G,H=I[2]+I[9]*U+I[11]*G;if(j<z)z=j;if(j>_)_=j;if(H<Z)Z=H;if(H>X)X=H}let S=u.length;s.push(z),o.push(_),i.push(Z),l.push(X),u.push(v),c.push(ze(t,M.part)),f.push(B[0]),a.push(B[2]);let w=Math.round((I[1]+B[4])*2);for(let R=Math.floor(z/40);R<=Math.floor(_/40);R++)for(let D=Math.floor(Z/40);D<=Math.floor(X/40);D++){if(!xe(w,R,D))continue;let U=x.length;x.push(S),d.push(p.put(w,R,D,U))}}let y=[0,5,-5,5,-5],L=[0,5,5,-5,-5],h=NaN,g=NaN,b=NaN,C=-1,F=(v,M,I,K)=>{let B=Math.round(M*2),z=Math.floor(v/40),_=Math.floor(I/40);if(!xe(B,z,_))return fe;let Z=fe;if(B!==h||z!==g||_!==b)h=B,g=z,b=_,C=p.get(B,z,_);for(let X=C;X>=0;X=d[X]){let S=x[X];if(u[S]===K||!(v-6>=s[S]-0.5&&v+6<=o[S]+0.5&&I-6>=i[S]-0.5&&I+6<=l[S]+0.5))continue;let w=e[u[S]].m,R=c[S],D=f[S],U=a[S],G=v-w[0],j=M-w[1],H=I-w[2],O=w[3]*G+w[6]*j+w[9]*H,W=w[5]*G+w[8]*j+w[11]*H,{nx:J,nz:se,mask:ae}=R,oe=!0;for(let ee=0;ee<5;ee++){let te=Math.floor((O+y[ee]-D)/20),ne=Math.floor((W+L[ee]-U)/20);if(te<0||ne<0||te>=J||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let ee=n[u[S]];if(ee<Z)Z=ee}}return Z},A=0;for(let v of e){let M=ze(t,v.part);if(M)A+=M.nStuds}let E=new Uint8Array(A),T=new Uint8Array(A),k=new $e(A),m=0,P=n?new Int32Array(A).fill(fe):void 0;for(let v=0,M=0;v<e.length;v++){let I=e[v],K=ze(t,I.part);if(!K)continue;let B=I.m,z=K.studM,_=B[0],Z=B[1],X=B[2],S=B[3],w=B[4],R=B[5],D=B[6],U=B[7],G=B[8],j=B[9],H=B[10],O=B[11];for(let W=0;W<K.nStuds;W++,M++){let J=W*12,se=z[J+4],ae=z[J+7],oe=z[J+10];if(!(Math.abs(D*se+U*ae+G*oe-1)<0.001&&Math.abs(S*se+w*ae+R*oe)<0.001&&Math.abs(j*se+H*ae+O*oe)<0.001))continue;T[M]=1;let ee=z[J],te=z[J+1],ne=z[J+2],je=_+S*ee+w*te+R*ne,Ve=Z+D*ee+U*te+G*ne,_e=X+j*ee+H*te+O*ne,He=F(je,Ve,_e,v);if(He!==fe){if(E[M]=1,m++,P)P[M]=He}let pe=Math.round(je),me=Math.round(Ve),he=Math.round(_e);if(!xe(pe,me,he))continue;if(!n){k.put(pe,me,he,1);continue}let Ge=n[v],Ke=k.get(pe,me,he);if(Ke<0||Ge<Ke)k.put(pe,me,he,Ge)}}let V=new Uint8Array(e.length),N=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let M=e[v],I=t.parts[M.part];if(!I||!I.under||!xt(M.m))continue;let K=I.bbox,B=Math.round((K[3]-K[0])/20),z=Math.round((K[5]-K[2])/20);if(!B||!z||B*z>4096)continue;let _=M.m,Z=!0,X=0;for(let S=0;S<B&&Z;S++)for(let w=0;w<z;w++){let R=K[0]+10+20*S,D=K[2]+10+20*w,U=_[0]+_[3]*R+_[5]*D,G=_[2]+_[9]*R+_[11]*D,j=Math.round(U),H=Math.round(_[1]+K[4]),O=Math.round(G),W=xe(j,H,O)?k.get(j,H,O):-1;if(W<0){Z=!1;break}if(W>X)X=W}if(Z){if(V[v]=1,N)N[v]=X}}return{nStuds:A,studHidden:E,studUp:T,underHidden:V,studsHidden:m,studHideStep:P,underHideStep:N}}function cn(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=new Map,o=new Map,i=(a)=>{let p=a.colour;if(!p)return String(a.color);let d=o.get(p);if(d!==void 0)return d;let x=t.colorTable?.[a.color],y=x?.hex??t.colors?.[a.color],L=x?Ne({alpha:x.alpha??255,luminance:x.luminance??0,finish:x.finish??{type:\"default\"}}):\"default:op\",h=Ne(p);if(d=y&&y.toUpperCase()===p.hex.toUpperCase()&&L===h?String(a.color):p.hex.toUpperCase()+\"/\"+h,d!==String(a.color))s.set(d,p);return o.set(p,d),d},l=e.map((a)=>({part:r(a),color:i(a),m:a.m,steps:a.steps})),u=l.map((a)=>dt(a.steps)),c=[...new Set(u)].sort(),f=new Map(c.map((a,p)=>[a,p]));return{all:l,stepOf:u.map((a)=>f.get(a)),nSteps:c.length,localColours:s}}function we(e,t,n=!0){let r=cn(e,t,n);return ln(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Te=\"https://ldr-demo.vercel.app/cdn/v1/\",Me=new Map,Ae=new Map;function ve(e=Te,t=fetch){let n=Me.get(e);if(!n)n=t(e+\"parts.json\").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>Me.delete(e)),Me.set(e,n);return n}var un=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]===\"number\"&&typeof e[1]===\"number\"&&(e[2]===\"f32\"||e[2]===\"u16\"||e[2]===\"u8\"||e[2]===\"u32\"),Ce=(e,t)=>un(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ce(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ce(r,t)])):e;function fn(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let d=p.buffer;if(!d)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let x=new DataView(d).getUint32(0,!0),y=new Uint8Array(d,4+x),L=r;n.push(y),r+=y.byteLength;let h=(4-r%4)%4;if(h)n.push(new Uint8Array(h)),r+=h;for(let[g,b]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ce(b,L);for(let[g,b]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ce(b,L)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),u=(4-(4+l.length)%4)%4,c=4+l.length+u,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+u,!0),f.set(l,4),f.fill(32,4+l.length,c);let a=c;for(let p of n)f.set(p,a),a+=p.byteLength;return ye(f.buffer)}async function pn(e,t={}){e=[...e];try{return await At(e,t)}catch(n){let r=t.cdn??Te,s=t.fetch??fetch;Me.delete(r);let o=(i,l)=>s(i,{...l,cache:\"reload\"});try{return await At(e,{...t,fetch:o})}catch{throw n}}}async function At(e,t){let n=t.cdn??Te,r=t.fetch??fetch,s=t.gap??16384,o=await ve(n,r),i=[...new Set([...e].map(Q))],l=[],u=[];for(let h of i){if(Ae.has(n+h))continue;let g=o.parts[h];if(g)u.push({name:h,off:g[0],len:g[1],file:g[2]??0});else l.push(h)}u.sort((h,g)=>h.file-g.file||h.off-g.off);let c=[];for(let h of u){let g=c[c.length-1];if(g&&g.file===h.file&&h.off-g.end<=s)g.end=Math.max(g.end,h.off+h.len),g.items.push(h);else c.push({file:h.file,start:h.off,end:h.off+h.len,items:[h]})}let f=0,a=0,p=0,d=new Map,x=async()=>{while(p<c.length){let h=c[p++],g=d.get(h.file);if(g)g=g.subarray(h.start,h.end);else{let b=await r(new URL(o.archives[h.file],n).href,{headers:{Range:`bytes=${h.start}-${h.end-1}`,\"Accept-Encoding\":\"identity\"}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);if(a++,g=new Uint8Array(await b.arrayBuffer()),f+=g.byteLength,b.status===200)d.set(h.file,g),g=g.subarray(h.start,h.end)}for(let b of h.items){let C=be(g.subarray(b.off-h.start,b.off-h.start+b.len)),F=C.buffer.slice(C.byteOffset,C.byteOffset+C.byteLength);Ae.set(n+b.name,ye(F))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},x));let y=i.filter((h)=>Ae.has(n+h)).map((h)=>Ae.get(n+h));return{pack:y.length?fn(y,{colors:o.colors}):ye(mn(o.colors)),missing:l,requests:a,bytes:f}}function mn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function hn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function Mt(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let u=l.embedded?t.get(l.part):Q(l.part),c=u?n.parts[u]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(u))i.add(u),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class Le extends Error{code=\"ldr-budget\";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:\"\",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:\"\"].filter(Boolean).join(\", \");super(`ldr: model exceeds device budget: ${t}`);this.name=\"BudgetError\",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function vt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=ve(t.cdn??Te,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(m)=>{if(!m.ok)throw Error(`ldr: ${m.status} fetching ${e}`);return Ze(await m.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?\"main.ldr\":qe(e)),u=bt(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(u),await s;let f=yt(o,new Set(u.filter((m)=>m.embedded).map((m)=>m.part)),l),a=(m,P)=>t.maxBodyTris!=null&&m>t.maxBodyTris||t.maxPackBytes!=null&&P>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(m)=>new Le({...m,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),x=\"full\";if(p){let m=Mt(u,f,await s);if(a(m.known?m.bodyTris:0,m.packBytes)){if(!t.lowCdn)throw d(m);let P=await ve(t.lowCdn,r).catch(()=>null);if(!P)throw d(m);let V=Mt(u,f,P);if(a(V.known?V.bodyTris:0,V.packBytes))throw d(V);x=\"low\"}}let y=[...u.filter((m)=>!m.embedded).map((m)=>m.part),...f.values()],L=async()=>{let m=await pn(y,x===\"low\"?{...t,cdn:t.lowCdn}:t);for(let[P,V]of f){let N=m.pack.header.parts[V];if(N)m.pack.header.parts[P]=N}return{...m,packBytes:m.pack.buffer?.byteLength??m.pack.bytes??0,bodyTris:hn(u,m.pack)}},h=await L();if(p&&a(h.bodyTris,h.packBytes)&&x===\"full\"&&t.lowCdn&&await ve(t.lowCdn,r).then(()=>!0,()=>!1)){x=\"low\";let m=h;h=await L(),h.requests+=m.requests,h.bytes+=m.bytes}if(p&&a(h.bodyTris,h.packBytes))throw d(h);let{pack:g,missing:b,requests:C,bytes:F}=h,A=new Map([...f].map(([m,P])=>[P,m])),E=b.map((m)=>A.get(m)??m),T=performance.now(),k=t.cull?we(u,g.header,t.textures!==!1):void 0;return{insts:u,pack:g,tier:x,missing:E,requests:C,bytes:F,cull:k,timings:{fetchModel:i-n,parse:c-i,parts:T-c,...k?{cull:performance.now()-T}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await vt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=we(s.insts,s.pack.header,r.textures!==!1),u=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:u},c)}catch(s){if(s instanceof Le||s?.code===\"ldr-budget\")self.postMessage({id:t,phase:\"error\",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:\"error\",error:String(s?.message??s)})}};\n";
1
+ declare const _default: "var St=ArrayBuffer,Y=Uint8Array,ge=Uint16Array,Et=Int16Array;var de=Int32Array,Se=function(e,t,n){if(Y.prototype.slice)return Y.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new Y(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(Y.prototype.fill)return Y.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},Pt=function(e,t,n,r){if(Y.prototype.copyWithin)return Y.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var kt=[\"invalid zstd data\",\"window size too large (>2046MB)\",\"invalid block type\",\"FSE accuracy too high\",\"match distance too far back\",\"unexpected EOF\"],J=function(e,t,n){var r=Error(t||kt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,J);if(!n)throw r;return r},Xe=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},It=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Bt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)J(0);var u=6-s,c=i==3?4:i,f=Xe(e,u,c);u+=c;var a=l?1<<l:s,p=Xe(e,u,a)+(l==1&&256),d=p;if(!s){var x=1<<10+(e[5]>>3);d=x+(x>>3)*(e[5]&7)}if(d>2145386496)J(1);var y=new Y((t==1?p||d:t?0:d)+12);return y[0]=1,y[4]=4,y[8]=8,{b:u+a,y:0,l:0,d:f,w:t&&t!=1?t:y.subarray(12),e:d,o:new de(y.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return It(e,4)+8;J(0)},se=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)J(3);var o=1<<s,i=o,l=-1,u=-1,c=-1,f=o,a=new St(512+(o<<2)),p=new Et(a,0,256),d=new ge(a,0,256),x=new ge(a,512,o),y=512+(o<<1),S=new Y(a,y,o),h=new Y(a,y+o);while(l<255&&i>0){var g=se(i+1),b=r>>3,C=(1<<g+1)-1,R=(e[b]|e[b+1]<<8|e[b+2]<<16)>>(r&7)&C,M=(1<<g)-1,L=C-i-1,T=R&M;if(T<L)r+=g,R=T;else if(r+=g+1,R>M)R-=L;if(p[++l]=--R,R==-1)i+=R,S[--f]=l;else i-=R;if(!R)do{var k=r>>3;u=(e[k]|e[k+1]<<8)>>(r&7)&3,r+=2,l+=u}while(u==3)}if(l>255||i)J(0);var m=0,P=(o>>1)+(o>>3)+3,V=o-1;for(var N=0;N<=l;++N){var v=p[N];if(v<1){d[N]=-v;continue}for(c=0;c<v;++c){S[m]=N;do m=m+P&V;while(m>=f)}}if(m)J(0);for(c=0;c<o;++c){var A=d[S[c]]++,I=h[c]=s-se(A);x[c]=(A<<I)-o}return[r+7>>3,{b:s,s:S,n:h,t:x}]},Ft=function(e,t){var n=0,r=-1,s=new Y(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),u=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],a=c[1];t+=o;var p=f<<3,d=e[t];if(!d)J(0);var x=0,y=0,S=a.b,h=S,g=(++t<<3)-8+se(d);for(;;){if(g-=S,g<p)break;var b=g>>3;if(x+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<S)-1,i[++r]=a.s[x],g-=h,g<p)break;b=g>>3,y+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<h)-1,i[++r]=a.s[y],S=a.n[x],x=a.t[x],h=a.n[y],y=a.t[y]}if(++r>255)J(0)}else{r=o-127;for(;n<r;n+=2){var C=e[++t];i[n]=C>>4,i[n+1]=C&15}++t}var R=0;for(n=0;n<r;++n){var M=i[n];if(M>11)J(0);R+=M&&1<<M-1}var L=se(R)+1,T=1<<L,k=T-R;if(k&k-1)J(0);i[r++]=se(k)+1;for(n=0;n<r;++n){var M=i[n];++l[i[n]=M&&L+1-M]}var m=new Y(T<<1),P=m.subarray(0,T),V=m.subarray(T);u[L]=0;for(n=L;n>0;--n){var N=u[n];ce(V,n,N,u[n-1]=N+l[n]*(1<<L-n))}if(u[0]!=T)J(0);for(n=0;n<r;++n){var v=i[n];if(v){var A=u[v];ce(P,n,A,u[v]=A+(1<<L-v))}}return[t,{n:V,b:L,s:P}]},Rt=ue(new Y([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Dt=ue(new Y([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Ut=ue(new Y([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Ze=function(e,t){var n=e.length,r=new de(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Ee=new Y(new de([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Ot=Ze(Ee,0),Pe=new Y(new de([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Nt=Ze(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)J(0);var u=0,c=n.b,f=(r<<3)-8+se(o)-c,a=-1;for(;f>l&&a<s;){var p=f>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(f&7);u=(u<<c|d)&i,t[++a]=n.s[u],f-=c=n.n[u]}if(f!=l||a+1!=s)J(0)},zt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},$t=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,u=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new Y(l),e[s])}if(u>e.length)return;if(i==0){if(t.b=u,n)return n.set(e.subarray(s,u),t.y),t.y+=l,n;return Se(e,s,u)}if(i==2){var c=e[s],f=c&3,a=c>>2&3,p=c>>4,d=0,x=0;if(f<2)if(a&1)p|=e[++s]<<4|(a&2&&e[++s]<<12);else p=c>>3;else if(x=a,a<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var y=n?n.subarray(t.y,t.y+t.m):new Y(t.m),S=y.length-p;if(f==0)y.set(e.subarray(s,s+=p),S);else if(f==1)ce(y,e[s++],S);else{var h=t.h;if(f==2){var g=Ft(e,s);d+=s-(s=g[0]),t.h=h=g[1]}else if(!h)J(0);(x?zt:le)(e.subarray(s,s+=d),y.subarray(S),h)}var b=e[s++];if(b){if(b==255)b=(e[s++]|e[s++]<<8)+32512;else if(b>127)b=b-128<<8|e[s++];var C=e[s++];if(C&3)J(0);var R=[Dt,Ut,Rt];for(var M=2;M>-1;--M){var L=C>>(M<<1)+2&3;if(L==1){var T=new Y([0,0,e[s++]]);R[M]={s:T.subarray(2,3),n:T.subarray(0,1),t:new ge(T.buffer,0,1),b:0}}else if(L==2)r=ue(e,s,9-(M&1)),s=r[0],R[M]=r[1];else if(L==3){if(!t.t)J(0);R[M]=t.t[M]}}var k=t.t=R,m=k[0],P=k[1],V=k[2],N=e[u-1];if(!N)J(0);var v=(u<<3)-8+se(N)-V.b,A=v>>3,I=0,W=(e[A]|e[A+1]<<8)>>(v&7)&(1<<V.b)-1;A=(v-=P.b)>>3;var B=(e[A]|e[A+1]<<8)>>(v&7)&(1<<P.b)-1;A=(v-=m.b)>>3;var z=(e[A]|e[A+1]<<8)>>(v&7)&(1<<m.b)-1;for(++b;--b;){var _=V.s[W],Z=V.n[W],X=m.s[z],E=m.n[z],w=P.s[B],D=P.n[B];A=(v-=w)>>3;var U=1<<w,O=U+((e[A]|e[A+1]<<8|e[A+2]<<16|e[A+3]<<24)>>>(v&7)&U-1);A=(v-=Pe[X])>>3;var G=Nt[X]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(v&7)&(1<<Pe[X])-1);A=(v-=Ee[_])>>3;var j=Ot[_]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(v&7)&(1<<Ee[_])-1);if(A=(v-=Z)>>3,W=V.t[W]+((e[A]|e[A+1]<<8)>>(v&7)&(1<<Z)-1),A=(v-=E)>>3,z=m.t[z]+((e[A]|e[A+1]<<8)>>(v&7)&(1<<E)-1),A=(v-=D)>>3,B=P.t[B]+((e[A]|e[A+1]<<8)>>(v&7)&(1<<D)-1),O>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=O-=3;else{var H=O-(j!=0);if(H){if(O=H==3?t.o[0]-1:t.o[H],H>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=O}else O=t.o[0]}for(var M=0;M<j;++M)y[I+M]=y[S+M];I+=j,S+=j;var K=I-O;if(K<0){var F=-K,q=t.e+K;if(F>G)F=G;for(var M=0;M<F;++M)y[I+M]=t.w[q+M];I+=F,G-=F,K=0}for(var M=0;M<G;++M)y[I+M]=y[K+M];I+=G}if(I!=S)while(S<y.length)y[I++]=y[S++];else I=y.length;if(n)t.y+=I;else y=Se(y,0,I)}else if(n){if(t.y+=p,S)for(var M=0;M<p;++M)y[M]=y[S+M]}else if(S)y=Se(y,S);return t.b=u,y}J(2)},jt=function(e,t){if(e.length==1)return e[0];var n=new Y(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function be(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Bt(e,r||t);if(typeof i==\"object\"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=$t(e,i,t);if(!l)J(5);if(t)i.e=i.y;else n.push(l),o+=l.length,Pt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return jt(n,o)}async function Vt(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(be(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream(\"gzip\"))).arrayBuffer();return n(t)}async function Ye(e){return new TextDecoder().decode(await Vt(e))}var qe=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\").replace(/\\.(zst|gz)$/i,\"\")||\"main.ldr\";function ye(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]===\"f32\"?new Float32Array(e,r+o[0],o[1]):o[2]===\"u16\"?new Uint16Array(e,r+o[0],o[1]):o[2]===\"u8\"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Q=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\"),Ie=/^[A-Za-z][A-Za-z0-9_]*$/,ke=new Map;function Be(e){let t=e.toLowerCase(),n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619);let r=-1-(n>>>0&1073741823);if(!ke.has(r))ke.set(r,t);return r}function Fe(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&Ie.test(e))return Be(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Je=/^~?\\s*moved\\s+to\\s+(.+)$/i,_t=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),it=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),Ht=new Set([\"model\",\"submodel\",\"configuration\"]),Gt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function Qe(e){let t=Gt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return it.has(n)||Ht.has(n)?n:void 0}function Wt(e){let t=[],n=0;while(n<e.length){while(e[n]===\" \"||e[n]===\"\\t\")n++;if(n>=e.length)break;if(e[n]==='\"'){let r=\"\";n++;while(n<e.length&&e[n]!=='\"'){if(e[n]===\"\\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==\" \"&&e[r]!==\"\\t\")r++;t.push(e.slice(n,r)),n=r}}return t}function Kt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r===\"PLANAR\"?9:r===\"CYLINDRICAL\"?10:r===\"SPHERICAL\"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let a=0;a<s;a++)l=l.replace(/^\\S+\\s*/,\"\");let u=Wt(l);if(!u.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:u[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=u.findIndex((a,p)=>p>0&&a.toUpperCase()===\"GLOSSMAP\");if(f>0&&u[f+1])c.glossmap=u[f+1];if(t)c.next=!0;return c}var Xt=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\"),n=t+\"=\".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Zt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),u=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(\" \"):l;return{t:1,color:Fe(o),m:i,file:Q(u)}}function et(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Fe(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Q(e.slice(14).join(\" \"))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function at(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,s=new Map,o=null,i=\"\",l,u=null,c=[],f=null,a=()=>{if(!u)return;let g=Xt(u.chunks.join(\"\")),b=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Q(u.name),{name:u.name,bytes:g,...b?{mime:\"image/png\"}:{}}),u=null},p=!0,d=(g)=>{if(a(),o={name:Q(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,p=!0},x=!1,y=!1,S=()=>{if(y)return;y=!0,s.clear(),o=null,i=\"\"},h=(g,b)=>{if(f){g.tex=f,f=null;return}let C=c[c.length-1];if(!C)return;if(C.fallback){if(!b)g.fallback=!0}else g.tex=C.map};for(let g of e.split(`\n`)){let b=g.trim();if(!b)continue;if(r&&b.charCodeAt(0)>=50&&b.charCodeAt(0)<=53&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)){if(u||x)continue;if(!o)d(t);let L=b.slice(2).trimStart(),T=L.search(/\\s/),k={t:b.charCodeAt(0)-48,color:Fe(T<0?L:L.slice(0,T)),p:[],src:b};h(k,!1),o.cmds.push(k),p=!1;continue}if(b.charCodeAt(0)===48&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)){let L=2;while(b.charCodeAt(L)===32||b.charCodeAt(L)===9)L++;let T=L;while(T<b.length&&b.charCodeAt(T)!==32&&b.charCodeAt(T)!==9)T++;let k=b.slice(L,T);if(!_t.has(k)){if(x||u)continue;if(!o)d(t);let m=b.slice(L),P={t:0,text:m};if(k.charCodeAt(0)===33)P.meta=k;if(f=null,p&&!o.org){let N=Qe(m);if(N)o.org=N}let V=m.match(Je);if(V&&!o.movedTo){let N=V[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(N))N+=\".dat\";o.movedTo=Q(N)}o.cmds.push(P);continue}}if(b.charCodeAt(0)===49&&(b.charCodeAt(1)===32||b.charCodeAt(1)===9)&&!u&&!x){let L=Zt(b);if(L){if(!o)d(t);h(L,!1),o.cmds.push(L),p=!1;continue}}let C=b.split(/\\s+/);if(+C[0]===0){let L=b.slice(1).trim();if(C[1]===\"FILE\"){S(),x=!1,d(L.slice(5));continue}if(C[1]===\"NOFILE\"){a(),o=null,x=!0;continue}if(C[1]===\"!DATA\"){S(),a(),o=null,x=!1,u={name:L.slice(5).trim(),chunks:[]};continue}if(x)continue;if(u){if(C[1]===\"!:\")u.chunks.push(C.slice(2).join(\"\"));continue}if(!o)d(t);let T={t:0,text:L};if(C[1]===\"STEP\")T.step=!0,c=[],f=null;else if(C[1]===\"BFC\")T.bfc=C.slice(2).join(\" \");else if(C[1]===\"ROTSTEP\")if(T.meta=\"ROTSTEP\",T.step=!0,c=[],f=null,(C[2]??\"\").toUpperCase()===\"END\")T.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let m=(C[5]??\"REL\").toUpperCase();T.rotstep={x:+C[2]||0,y:+C[3]||0,z:+C[4]||0,mode:[\"REL\",\"ABS\",\"ADD\"].includes(m)?m:\"REL\"}}else if(C[1]===\"BUFEXCHG\"){T.meta=\"BUFEXCHG\";let m=(C[2]??\"\").toUpperCase();T.bufexchg={op:m===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:C[3]??\"A\"}}else if(C[1]?.startsWith(\"!\"))T.meta=C[1];if(p&&!o.org){let m=Qe(L);if(m)o.org=m}if(C[1]===\"!TEXMAP\"){let m=(C[2]??\"\").toUpperCase();if(f=null,m===\"START\"||m===\"NEXT\"){let P=Kt(L.replace(/^!TEXMAP\\s+\\S+/i,\"\"),m===\"NEXT\");if(T.texmap={op:m,...P?{map:P}:{}},P)if((o.texmaps??=[]).push(P),m===\"START\")c.push({map:P,fallback:!1});else f=P}else if(m===\"FALLBACK\"){T.texmap={op:m};let P=c[c.length-1];if(P)P.fallback=!0}else if(m===\"END\")T.texmap={op:m},c.pop()}else if(C[1]===\"!:\"){f=null;let m=et(C.slice(2));if(m)h(m,!0),T.geom=m}else f=null;let k=L.match(Je);if(k&&!o.movedTo){let m=k[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(m))m+=\".dat\";o.movedTo=Q(m)}o.cmds.push(T);continue}if(u||x)continue;if(!o)d(t);let M=et(C);if(!M)continue;h(M,!1),o.cmds.push(M),p=!1}return a(),l?{main:i,files:s,data:l}:{main:i,files:s}}var Mn=Math.PI/180;function lt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function ct(e,t){let[n,r,s,o,i,l,u,c,f,a,p,d]=e,[x,y,S,h,g,b,C,R,M,L,T,k]=t;return[o*x+i*y+l*S+n,u*x+c*y+f*S+r,a*x+p*y+d*S+s,o*h+i*C+l*L,o*g+i*R+l*T,o*b+i*M+l*k,u*h+c*C+f*L,u*g+c*R+f*T,u*b+c*M+f*k,a*h+p*C+d*L,a*g+p*R+d*T,a*b+p*M+d*k]}var Re=[0,0,0,1,0,0,0,1,0,0,0,1];var tt=new WeakMap,Yt=/^(s|8|48)\\//;function De(e,t){let n=e.files.get(Q(t));if(!n)return\"part\";let r=tt.get(n);if(r)return r;if(n.org)r=it.has(n.org)?\"part\":\"model\";else if(n.name===e.main)r=\"model\";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&Yt.test(s.file))?\"part\":\"model\";return tt.set(n,r),r}var nt=new WeakMap;function ut(e){let t=nt.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return nt.set(e,t),t}var rt=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():e<0?ke.get(e)??String(e):String(e),qt=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${rt(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${rt(e.color)} ${e.p.join(\" \")}`,Ue=(e,t)=>`${Q(e)}#${t}`;function Jt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op===\"NEXT\";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0||o.meta===\"!COLOUR\"){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ue(e.name,t),cmds:n}}function ft(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Jt(e,t).cmds.map(qt)].join(`\n`)+`\n`}function Oe(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,\"0\")}function pt(e){let[t,n,r,s,o,i,l,u,c,f,a,p]=e,d=u*p-c*a,x=-(l*p-c*f),y=l*a-u*f,S=s*d+o*x+i*y;if(!Number.isFinite(S)||Math.abs(S)<0.000000000001)return null;let h=1/S,g=[d*h,-(o*p-i*a)*h,(o*c-i*u)*h,x*h,(s*p-i*f)*h,-(s*c-i*l)*h,y*h,-(s*a-o*f)*h,(s*u-o*l)*h];return[-(g[0]*t+g[1]*n+g[2]*r),-(g[3]*t+g[4]*n+g[5]*r),-(g[6]*t+g[7]*n+g[8]*r),...g]}var Qt=(e)=>String(+e.toFixed(6)||0),st=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function mt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map(Qt).join(\" \"),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${st(t.texture)}${t.glossmap?\" GLOSSMAP \"+st(t.glossmap):\"\"}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Q(e)}\n0 !TEXMAP END\n`;return{name:`${Q(e)}#tex-${Oe(r)}`,source:r}}var en=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function tn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),u=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*u,i,o*u+s*i*c,o*c-s*i*u,-s*l,s*u-o*i*c,s*c+o*i*u,o*l]}var ot=new WeakMap;function ht(e){let t=ot.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode===\"END\")r=null;else{let i=tn(o.x,o.y,o.z);r=o.mode===\"ABS\"?{abs:!0,m:i,rotstep:o}:o.mode===\"ADD\"&&r?{abs:r.abs,m:en(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),ot.set(e,n),n}var gt=999999,yt=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\",xt=new WeakMap,dt=new WeakMap;function nn(e,t){let n=dt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=xt.get(o)??\"\",l=i.indexOf(\"!COLOUR\");return l<0?\"\":\"0 \"+i.slice(l).trim().replace(/\\s+/g,\" \")}).filter(Boolean).join(`\n`),parts:new Map},dt.set(t,n);let r=n.parts.get(e);if(!r){let s=Q(e),o=`0 ldr: ${s} placed in a model's !COLOUR scope\n0 BFC CERTIFY CCW\n${n.head}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${s}\n`;r={name:`${s}#col-${Oe(o)}`,source:o},n.parts.set(e,r)}return r}function rn(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,u=0,c=(a,p)=>{let d=a.name+\"#\"+p,x=l.get(d);if(!x){let y;x=Object.assign(()=>y??=ft(a,p),{file:a,step:p}),l.set(d,x)}return x},f=(a,p,d,x,y,S,h,g,b=null,C=[],R=[],M=void 0,L=null)=>{let T=a.files.get(p);if(!T||h>r)return;let k=L,m=0,P=h>0?++u:0,V=i&&P?[...C,P]:C,N=i&&P?[...R,d]:R,v=i&&!b?new Map:null,A=-1,I=0,W=(E,w,D,U,O,G,j)=>{if(A!==m)A=m,I=0;let H=v?.get(m+\"|\"+w);if(H)return H.n++,f(E,E===a?w:E.main,D,U,y+\"/\"+w,[...O,gt],h+1,G,[...O,gt],V,N,j,k);let K=[...O,I++],F=n.length;f(E,E===a?w:E.main,D,U,y+\"/\"+w,K,h+1,G,b,V,N,j,k),v?.set(m+\"|\"+w,{n:1,from:F,to:n.length})},B=ht(T),z=s?ut(T):[],_=0,Z=(E,w,D,U,O,G,j,H,K)=>{if(b)U=b;let F={part:E,color:w,m:D,step:U[0],steps:U,localStep:O,path:y};if(H)F.colour=H;if(P){if(F.sub=P,i)F.subPath=V,F.subMats=N}if(G)F.embedded=!0;if(j){let ee=mt(E,j);F.texPart=ee.name,F.texSource=ee.source}else if(K){let ee=nn(E,K);F.colPart=ee.name,F.colSource=ee.source}let q=B[O];if(q)F.view=q;return n.push(F),F},X=(E)=>{while(_<z.length&&z[_]<=E){let w=z[_++];Z(Ue(T.name,w),x,d,[...S,w],w,!1,null,M,L).source=c(T,w)}};for(let E of T.cmds){if(E.t===0&&E.step){m++;continue}let w=E;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){X(m);continue}if(w.t===0){if(w.meta===\"!COLOUR\"){let q=on(w.text);if(q&&q.code!==16&&q.code!==24)xt.set(q,w.text),(k=new Map(k??[])).set(q.code,q);continue}if(o&&w.geom?.t===1)w=w.geom;else continue}if(w.t!==1)continue;if(o&&w.fallback)continue;let D=w.color===16?x:w.color,U=w.color===16?M:k?.get(w.color),O=ct(d,w.m),G=[...S,m],j=o?w.tex??g:null,H=j?pt(w.m):null,K=j&&H?lt(j,H):null;if(a.files.has(w.file)){if(De(a,w.file)===\"model\"){W(a,w.file,O,D,G,K,U);continue}Z(w.file,D,O,G,m,!0,K,U,k);continue}let F=t.resolveModel?.(w.file);if(F){W(F,w.file,O,D,G,K,U);continue}Z(w.file,D,O,G,m,!1,K,U,k)}if(X(1/0),v){for(let E of v.values())if(E.n>1)for(let w=E.from;w<E.to;w++)n[w].mult??=E.n}};if(De(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Re],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,Re,16,e.main,[],0,null),n}function wt(e,t=\"main.ldr\",n){return rn(at(e,t,{geometryText:!0}),n)}var sn=new Set([\"CHROME\",\"PEARLESCENT\",\"RUBBER\",\"MATTE_METALLIC\",\"METAL\",\"MATERIAL\"]);function Ne(e){if(!e)return null;if(e.startsWith(\"#\")&&/^#[0-9A-Fa-f]{6}$/.test(e))return e.toUpperCase();if(/^0x[0-9A-Fa-f]{6}$/i.test(e))return(\"#\"+e.slice(2)).toUpperCase();return null}function bt(e,t){let n={value:\"#FFFFFF\",fraction:0.5};while(t<e.length){let r=e[t].toUpperCase(),s=e[t+1];if(r===\"VALUE\"){let o=Ne(s);if(o)n.value=o;t+=2}else if(r===\"ALPHA\")n.alpha=+s,t+=2;else if(r===\"LUMINANCE\")n.luminance=+s,t+=2;else if(r===\"FRACTION\")n.fraction=+s,t+=2;else if(r===\"VFRACTION\")n.vfraction=+s,t+=2;else if(r===\"SIZE\")n.size=+s,t+=2;else if(r===\"MINSIZE\")n.minsize=+s,t+=2;else if(r===\"MAXSIZE\")n.maxsize=+s,t+=2;else break}return{grain:n,next:t}}function on(e){let t=e.indexOf(\"!COLOUR\");if(t<0)return null;let n=e.slice(t+7).trim().split(/\\s+/).filter(Boolean);if(n.length<2)return null;let r=n[0],s=NaN,o=\"#FF00FF\",i=\"#333333\",l=255,u=0,c={type:\"default\"},f=1;while(f<n.length){let a=n[f].toUpperCase(),p=n[f+1];if(a===\"CODE\")s=p!==void 0&&Ie.test(p)?Be(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,f+=2;else if(a===\"VALUE\"){let d=Ne(p);if(d)o=d;f+=2}else if(a===\"EDGE\")i=Ne(p)??p,f+=2;else if(a===\"ALPHA\")l=+p,f+=2;else if(a===\"LUMINANCE\")u=+p,f+=2;else if(a===\"CHROME\")c={type:\"chrome\"},f+=1;else if(a===\"PEARLESCENT\")c={type:\"pearlescent\"},f+=1;else if(a===\"RUBBER\")c={type:\"rubber\"},f+=1;else if(a===\"MATTE_METALLIC\")c={type:\"matte_metallic\"},f+=1;else if(a===\"METAL\")c={type:\"metal\"},f+=1;else if(a===\"MATERIAL\"){let d=(n[f+1]||\"\").toUpperCase();if(d===\"GLITTER\"){let{grain:x,next:y}=bt(n,f+2);c={type:\"glitter\",material:x},f=y}else if(d===\"SPECKLE\"){let{grain:x,next:y}=bt(n,f+2);c={type:\"speckle\",material:x},f=y}else if(d===\"FABRIC\"){let x=(n[f+2]||\"\").toUpperCase(),y=[\"VELVET\",\"CANVAS\",\"STRING\",\"FUR\"].includes(x)?x.toLowerCase():void 0;c={type:\"fabric\",kind:y},f+=y?3:2}else f=n.length}else if(sn.has(a))f+=1;else f+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(l)?l:255,luminance:Number.isFinite(u)?u:0,finish:c}}function an(e){let t=Math.max(0,Math.min(1,(e.alpha??255)/255)),n=t<1,r=Math.max(0,Math.min(1,(e.luminance??0)/255)),s={opacity:t,transparent:n,depthWrite:!n,emissive:r,clearcoat:0,clearcoatRoughness:0,sheen:0,sheenRoughness:0};switch(e.finish?.type??\"default\"){case\"chrome\":return{...s,metalness:1,roughness:0,finish:\"chrome\"};case\"pearlescent\":return{...s,metalness:0.25,roughness:0.3,clearcoat:0.5,clearcoatRoughness:0.25,sheen:0.4,sheenRoughness:0.35,finish:\"pearlescent\"};case\"rubber\":return{...s,metalness:0,roughness:0.9,finish:\"rubber\"};case\"matte_metallic\":return{...s,metalness:0.4,roughness:0.8,finish:\"matte_metallic\"};case\"metal\":return{...s,metalness:0.85,roughness:0.2,finish:\"metal\"};case\"glitter\":{let i=e.finish.material,l=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.35,roughness:0.25,clearcoat:1,clearcoatRoughness:0.08,particleHex:i.value,particleFraction:i.fraction,particleSize:l,finish:\"glitter\"}}case\"speckle\":{let i=e.finish.material,l=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.2,roughness:0.55,particleHex:i.value,particleFraction:i.fraction,particleSize:l,finish:\"speckle\"}}case\"fabric\":return{...s,metalness:0,roughness:0.85,sheen:0.65,sheenRoughness:0.75,finish:\"fabric\"};default:return{...s,metalness:0,roughness:0.45,finish:\"default\"}}}function ze(e){let t=an(e),n=!t.transparent?\"op\":t.opacity>=0.75?\"a200\":t.opacity>=0.4?\"a128\":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:\"\",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function ln(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Q(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Q(t),r)}let l=o.trim().replace(/\\s+/g,\" \");if(l)r.push(l)}return n}var cn=(e)=>{if(!e.startsWith(\"1 \"))return null;let t=e.split(\" \");return t.length>=15?Q(t.slice(14).join(\" \")):null};function un(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,\"0\")+(n>>>0).toString(16).padStart(8,\"0\")}function Mt(e,t,n=\"main.ldr\"){let r=ln(e,n),s=new Map;for(let o of t){let i=Q(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),u=[i];while(u.length)for(let f of r.get(u.pop())){let a=cn(f);if(a&&r.has(a)&&!l.has(a))l.add(a),u.push(a)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>\"0 FILE \"+(f===i?\"\":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${un(c)}.dat`)}return s}var At=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,vt=new WeakMap;function $e(e,t){let n=vt.get(e);if(!n)vt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],u=[];s.studs.forEach((p,d)=>{l.push(p[0]),u.push(p[1]);for(let x=0;x<12;x++)i[d*12+x]=p[2+x]});let c=null,f=0,a=0;if(s.mask){f=s.mask[0],a=s.mask[1];let p=s.mask[2];c=new Uint8Array(p.length);for(let d=0;d<p.length;d++)c[d]=p.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:u,mask:c,nx:f,nz:a}),r}var ie=1073741824;class je{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,u=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,u[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&u[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function fn(e,t,n){let s=[],o=[],i=[],l=[],u=[],c=[],f=[],a=[],p=new je(e.length*2),d=[],x=[];for(let v=0;v<e.length;v++){let A=e[v],I=A.m,W=t.parts[A.part];if(!W||!W.mask||!At(I))continue;let B=W.bbox,z=1/0,_=-1/0,Z=1/0,X=-1/0;for(let D=0;D<2;D++)for(let U=0;U<2;U++){let O=D?B[3]:B[0],G=U?B[5]:B[2],j=I[0]+I[3]*O+I[5]*G,H=I[2]+I[9]*O+I[11]*G;if(j<z)z=j;if(j>_)_=j;if(H<Z)Z=H;if(H>X)X=H}let E=u.length;s.push(z),o.push(_),i.push(Z),l.push(X),u.push(v),c.push($e(t,A.part)),f.push(B[0]),a.push(B[2]);let w=Math.round((I[1]+B[4])*2);for(let D=Math.floor(z/40);D<=Math.floor(_/40);D++)for(let U=Math.floor(Z/40);U<=Math.floor(X/40);U++){if(!xe(w,D,U))continue;let O=x.length;x.push(E),d.push(p.put(w,D,U,O))}}let y=[0,5,-5,5,-5],S=[0,5,5,-5,-5],h=NaN,g=NaN,b=NaN,C=-1,R=(v,A,I,W)=>{let B=Math.round(A*2),z=Math.floor(v/40),_=Math.floor(I/40);if(!xe(B,z,_))return fe;let Z=fe;if(B!==h||z!==g||_!==b)h=B,g=z,b=_,C=p.get(B,z,_);for(let X=C;X>=0;X=d[X]){let E=x[X];if(u[E]===W||!(v-6>=s[E]-0.5&&v+6<=o[E]+0.5&&I-6>=i[E]-0.5&&I+6<=l[E]+0.5))continue;let w=e[u[E]].m,D=c[E],U=f[E],O=a[E],G=v-w[0],j=A-w[1],H=I-w[2],K=w[3]*G+w[6]*j+w[9]*H,F=w[5]*G+w[8]*j+w[11]*H,{nx:q,nz:ee,mask:ae}=D,oe=!0;for(let te=0;te<5;te++){let ne=Math.floor((K+y[te]-U)/20),re=Math.floor((F+S[te]-O)/20);if(ne<0||re<0||ne>=q||re>=ee||ae[ne*ee+re]!==1){oe=!1;break}}if(oe){if(!n)return 0;let te=n[u[E]];if(te<Z)Z=te}}return Z},M=0;for(let v of e){let A=$e(t,v.part);if(A)M+=A.nStuds}let L=new Uint8Array(M),T=new Uint8Array(M),k=new je(M),m=0,P=n?new Int32Array(M).fill(fe):void 0;for(let v=0,A=0;v<e.length;v++){let I=e[v],W=$e(t,I.part);if(!W)continue;let B=I.m,z=W.studM,_=B[0],Z=B[1],X=B[2],E=B[3],w=B[4],D=B[5],U=B[6],O=B[7],G=B[8],j=B[9],H=B[10],K=B[11];for(let F=0;F<W.nStuds;F++,A++){let q=F*12,ee=z[q+4],ae=z[q+7],oe=z[q+10];if(!(Math.abs(U*ee+O*ae+G*oe-1)<0.001&&Math.abs(E*ee+w*ae+D*oe)<0.001&&Math.abs(j*ee+H*ae+K*oe)<0.001))continue;T[A]=1;let te=z[q],ne=z[q+1],re=z[q+2],Ve=_+E*te+w*ne+D*re,_e=Z+U*te+O*ne+G*re,He=X+j*te+H*ne+K*re,Ge=R(Ve,_e,He,v);if(Ge!==fe){if(L[A]=1,m++,P)P[A]=Ge}let pe=Math.round(Ve),me=Math.round(_e),he=Math.round(He);if(!xe(pe,me,he))continue;if(!n){k.put(pe,me,he,1);continue}let We=n[v],Ke=k.get(pe,me,he);if(Ke<0||We<Ke)k.put(pe,me,he,We)}}let V=new Uint8Array(e.length),N=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let A=e[v],I=t.parts[A.part];if(!I||!I.under||!At(A.m))continue;let W=I.bbox,B=Math.round((W[3]-W[0])/20),z=Math.round((W[5]-W[2])/20);if(!B||!z||B*z>4096)continue;let _=A.m,Z=!0,X=0;for(let E=0;E<B&&Z;E++)for(let w=0;w<z;w++){let D=W[0]+10+20*E,U=W[2]+10+20*w,O=_[0]+_[3]*D+_[5]*U,G=_[2]+_[9]*D+_[11]*U,j=Math.round(O),H=Math.round(_[1]+W[4]),K=Math.round(G),F=xe(j,H,K)?k.get(j,H,K):-1;if(F<0){Z=!1;break}if(F>X)X=F}if(Z){if(V[v]=1,N)N[v]=X}}return{nStuds:M,studHidden:L,studUp:T,underHidden:V,studsHidden:m,studHideStep:P,underHideStep:N}}function pn(e,t,n){let r=(a)=>a.colPart&&t.parts[a.colPart]?a.colPart:n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=new Map,o=new Map,i=(a)=>{let p=a.colour;if(!p)return String(a.color);let d=o.get(p);if(d!==void 0)return d;let x=t.colorTable?.[a.color],y=x?.hex??t.colors?.[a.color],S=x?ze({alpha:x.alpha??255,luminance:x.luminance??0,finish:x.finish??{type:\"default\"}}):\"default:op\",h=ze(p);if(d=y&&y.toUpperCase()===p.hex.toUpperCase()&&S===h?String(a.color):p.hex.toUpperCase()+\"/\"+h,d!==String(a.color))s.set(d,p);return o.set(p,d),d},l=e.map((a)=>({part:r(a),color:i(a),m:a.m,steps:a.steps})),u=l.map((a)=>yt(a.steps)),c=[...new Set(u)].sort(),f=new Map(c.map((a,p)=>[a,p]));return{all:l,stepOf:u.map((a)=>f.get(a)),nSteps:c.length,localColours:s}}function we(e,t,n=!0){let r=pn(e,t,n);return fn(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Te=\"https://ldr-demo.vercel.app/cdn/v1/\",Ae=new Map,Me=new Map;function ve(e=Te,t=fetch){let n=Ae.get(e);if(!n)n=t(e+\"parts.json\").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>Ae.delete(e)),Ae.set(e,n);return n}var mn=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]===\"number\"&&typeof e[1]===\"number\"&&(e[2]===\"f32\"||e[2]===\"u16\"||e[2]===\"u8\"||e[2]===\"u32\"),Ce=(e,t)=>mn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ce(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ce(r,t)])):e;function hn(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let d=p.buffer;if(!d)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let x=new DataView(d).getUint32(0,!0),y=new Uint8Array(d,4+x),S=r;n.push(y),r+=y.byteLength;let h=(4-r%4)%4;if(h)n.push(new Uint8Array(h)),r+=h;for(let[g,b]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ce(b,S);for(let[g,b]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ce(b,S)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),u=(4-(4+l.length)%4)%4,c=4+l.length+u,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+u,!0),f.set(l,4),f.fill(32,4+l.length,c);let a=c;for(let p of n)f.set(p,a),a+=p.byteLength;return ye(f.buffer)}async function gn(e,t={}){e=[...e];try{return await Ct(e,t)}catch(n){let r=t.cdn??Te,s=t.fetch??fetch;Ae.delete(r);let o=(i,l)=>s(i,{...l,cache:\"reload\"});try{return await Ct(e,{...t,fetch:o})}catch{throw n}}}async function Ct(e,t){let n=t.cdn??Te,r=t.fetch??fetch,s=t.gap??16384,o=await ve(n,r),i=[...new Set([...e].map(Q))],l=[],u=[];for(let h of i){if(Me.has(n+h))continue;let g=o.parts[h];if(g)u.push({name:h,off:g[0],len:g[1],file:g[2]??0});else l.push(h)}u.sort((h,g)=>h.file-g.file||h.off-g.off);let c=[];for(let h of u){let g=c[c.length-1];if(g&&g.file===h.file&&h.off-g.end<=s)g.end=Math.max(g.end,h.off+h.len),g.items.push(h);else c.push({file:h.file,start:h.off,end:h.off+h.len,items:[h]})}let f=0,a=0,p=0,d=new Map,x=async()=>{while(p<c.length){let h=c[p++],g=d.get(h.file);if(g)g=g.subarray(h.start,h.end);else{let b=await r(new URL(o.archives[h.file],n).href,{headers:{Range:`bytes=${h.start}-${h.end-1}`,\"Accept-Encoding\":\"identity\"}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);if(a++,g=new Uint8Array(await b.arrayBuffer()),f+=g.byteLength,b.status===200)d.set(h.file,g),g=g.subarray(h.start,h.end)}for(let b of h.items){let C=be(g.subarray(b.off-h.start,b.off-h.start+b.len)),R=C.buffer.slice(C.byteOffset,C.byteOffset+C.byteLength);Me.set(n+b.name,ye(R))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},x));let y=i.filter((h)=>Me.has(n+h)).map((h)=>Me.get(n+h));return{pack:y.length?hn(y,{colors:o.colors}):ye(dn(o.colors)),missing:l,requests:a,bytes:f}}function dn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function bn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function Tt(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let u=l.embedded?t.get(l.part):Q(l.part),c=u?n.parts[u]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(u))i.add(u),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class Le extends Error{code=\"ldr-budget\";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:\"\",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:\"\"].filter(Boolean).join(\", \");super(`ldr: model exceeds device budget: ${t}`);this.name=\"BudgetError\",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function Lt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=ve(t.cdn??Te,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(m)=>{if(!m.ok)throw Error(`ldr: ${m.status} fetching ${e}`);return Ye(await m.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?\"main.ldr\":qe(e)),u=wt(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(u),await s;let f=Mt(o,new Set(u.filter((m)=>m.embedded).map((m)=>m.part)),l),a=(m,P)=>t.maxBodyTris!=null&&m>t.maxBodyTris||t.maxPackBytes!=null&&P>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(m)=>new Le({...m,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),x=\"full\";if(p){let m=Tt(u,f,await s);if(a(m.known?m.bodyTris:0,m.packBytes)){if(!t.lowCdn)throw d(m);let P=await ve(t.lowCdn,r).catch(()=>null);if(!P)throw d(m);let V=Tt(u,f,P);if(a(V.known?V.bodyTris:0,V.packBytes))throw d(V);x=\"low\"}}let y=[...u.filter((m)=>!m.embedded).map((m)=>m.part),...f.values()],S=async()=>{let m=await gn(y,x===\"low\"?{...t,cdn:t.lowCdn}:t);for(let[P,V]of f){let N=m.pack.header.parts[V];if(N)m.pack.header.parts[P]=N}return{...m,packBytes:m.pack.buffer?.byteLength??m.pack.bytes??0,bodyTris:bn(u,m.pack)}},h=await S();if(p&&a(h.bodyTris,h.packBytes)&&x===\"full\"&&t.lowCdn&&await ve(t.lowCdn,r).then(()=>!0,()=>!1)){x=\"low\";let m=h;h=await S(),h.requests+=m.requests,h.bytes+=m.bytes}if(p&&a(h.bodyTris,h.packBytes))throw d(h);let{pack:g,missing:b,requests:C,bytes:R}=h,M=new Map([...f].map(([m,P])=>[P,m])),L=b.map((m)=>M.get(m)??m),T=performance.now(),k=t.cull?we(u,g.header,t.textures!==!1):void 0;return{insts:u,pack:g,tier:x,missing:L,requests:C,bytes:R,cull:k,timings:{fetchModel:i-n,parse:c-i,parts:T-c,...k?{cull:performance.now()-T}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await Lt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=we(s.insts,s.pack.header,r.textures!==!1),u=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:u},c)}catch(s){if(s instanceof Le||s?.code===\"ldr-budget\")self.postMessage({id:t,phase:\"error\",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:\"error\",error:String(s?.message??s)})}};\n";
2
2
  export default _default;
package/dist/model.d.ts CHANGED
@@ -41,6 +41,13 @@ export interface PartInstance {
41
41
  * passed to the files it references, per the !COLOUR spec), instead of the global table (LDConfig.ldr). Renderers use this colour
42
42
  * for the instance; `color` stays the code as written (after colour-16 inheritance). */
43
43
  colour?: LDrawColor;
44
+ /** Set when the model's `0 !COLOUR` definitions are in scope where this part is placed (article 299: definitions "will be passed
45
+ * to subfiles", so they also reach colours hard-coded inside the part). `colPart` names a synthetic part (`<part>#col-<hash>`)
46
+ * that applies those definitions and then places `part` in 16, and `colSource` is its LDraw source. A pack has an entry for it
47
+ * only when a definition changes a colour inside the part (see `buildPack`); renderers fall back to `part` otherwise. Not set for
48
+ * `texPart` instances. */
49
+ colPart?: string;
50
+ colSource?: string;
44
51
  }
45
52
  export interface FlattenOptions {
46
53
  /** Resolve an external reference that is not a submodel of this document (e.g. a model file you loaded separately). Return null to treat it as a part. */
@@ -64,6 +71,16 @@ export declare const CALLOUT_END = 999999;
64
71
  * step's own parts, which attach them: like a booklet, where callouts are built first and then added in the step that places them.
65
72
  */
66
73
  export declare const stepKey: (steps: number[]) => string;
74
+ /**
75
+ * The synthetic part that draws `part` inside a model's `0 !COLOUR` scope: the definitions in effect (one line per code, in the
76
+ * order they were made), then `part` placed in 16 at the origin. Compiled like any part, so the definitions reach the colours
77
+ * hard-coded inside `part` and its subfiles with the spec's scope (Round 56's part-level scope does the rest). Named
78
+ * `<part>#col-<hash of the source>`, so every placement under the same definitions shares one entry.
79
+ */
80
+ export declare function scopeWrapper(part: string, scope: Map<number, LDrawColor>): {
81
+ name: string;
82
+ source: string;
83
+ };
67
84
  /**
68
85
  * Flatten a parsed LDraw document into part instances. Model files (`0 FILE` blocks in an MPD that `fileKind` calls models) are
69
86
  * expanded; MPD-embedded parts and library references become instances. A model file's own geometry becomes synthetic parts.