ldr 0.34.12 → 0.34.13

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/cli.js CHANGED
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/cli.ts
3
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/cli.ts
4
4
  import fs4 from "node:fs";
5
5
  import zlib from "node:zlib";
6
6
 
7
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/build-pack.ts
7
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/build-pack.ts
8
8
  import fs3 from "node:fs";
9
9
  import path3 from "node:path";
10
10
 
11
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/resolver.ts
11
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/resolver.ts
12
12
  import fs from "node:fs";
13
13
  import path from "node:path";
14
14
 
15
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/spec.ts
15
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/spec.ts
16
16
  var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
17
17
  var COLOUR_ID_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
18
18
  var namedCodes = new Map;
@@ -848,7 +848,7 @@ function fileStepViews(f) {
848
848
  return out;
849
849
  }
850
850
 
851
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/model.ts
851
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/model.ts
852
852
  class ModelLimitError extends Error {
853
853
  limit;
854
854
  code = "ldr-model-limit";
@@ -898,6 +898,15 @@ function flatten(doc, opts = {}) {
898
898
  const loose = opts.looseGeometry !== false, tx = !!opts.textures, co = !!opts.callouts;
899
899
  const src = new Map;
900
900
  let subs = 0;
901
+ const stepSingles = [];
902
+ const stepPathOf = (path, s) => {
903
+ if (path.length)
904
+ return [...path, s];
905
+ let a = stepSingles[s];
906
+ if (!a)
907
+ stepSingles[s] = a = [s];
908
+ return a;
909
+ };
901
910
  const open = new Set;
902
911
  const maxN = opts.maxInstances ?? 2000000;
903
912
  let work = 0;
@@ -977,7 +986,7 @@ function flatten(doc, opts = {}) {
977
986
  const flushLoose = (upTo) => {
978
987
  while (li < ls.length && ls[li] <= upTo) {
979
988
  const k = ls[li++];
980
- emit(loosePartName(f.name, k), color, m, [...stepPath, k], k, false, null, colour, scope0).source = lazy(f, k);
989
+ emit(loosePartName(f.name, k), color, m, stepPathOf(stepPath, k), k, false, null, colour, scope0).source = lazy(f, k);
981
990
  }
982
991
  };
983
992
  for (const c0 of f.cmds) {
@@ -1008,10 +1017,10 @@ function flatten(doc, opts = {}) {
1008
1017
  continue;
1009
1018
  if (tx && c.fallback)
1010
1019
  continue;
1011
- const mm = mul(m, c.m);
1020
+ const mm = m === I ? c.m : mul(m, c.m);
1012
1021
  if (!inRange12(mm))
1013
1022
  continue;
1014
- const col = c.color === 16 ? color : c.color, cd = c.color === 16 ? colour : scope?.get(c.color), sp = [...stepPath, s];
1023
+ const col = c.color === 16 ? color : c.color, cd = c.color === 16 ? colour : scope?.get(c.color), sp = stepPathOf(stepPath, s);
1015
1024
  const tex = tx ? c.tex ?? texIn : null;
1016
1025
  const local = tex ? invert(c.m) : null;
1017
1026
  const lt = tex && local ? transformTexMap(tex, local) : null;
@@ -1290,7 +1299,7 @@ function blendedColourHex(code) {
1290
1299
  return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
1291
1300
  }
1292
1301
 
1293
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/resolver.ts
1302
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/resolver.ts
1294
1303
  var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
1295
1304
  var UNDER_STUD_RE = /^(stud3|stud3a|stud4.*|stud12|stud16.*|stud18a)\.dat$/i;
1296
1305
  var norm2 = (ref) => ref.trim().replace(/\\/g, "/").toLowerCase();
@@ -1617,11 +1626,11 @@ function collectDeps(lib, refs) {
1617
1626
  return out;
1618
1627
  }
1619
1628
 
1620
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/compile.ts
1629
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/compile.ts
1621
1630
  import fs2 from "node:fs";
1622
1631
  import path2 from "node:path";
1623
1632
 
1624
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/lod.ts
1633
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/lod.ts
1625
1634
  import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
1626
1635
  await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
1627
1636
  function reorderMesh(P, N, C, I) {
@@ -1927,7 +1936,7 @@ function levelLines(P, I, E, err, always, tol = 0.01) {
1927
1936
  return out;
1928
1937
  }
1929
1938
 
1930
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/compile.ts
1939
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/compile.ts
1931
1940
  class BfcState {
1932
1941
  accum;
1933
1942
  ccw = true;
@@ -2888,7 +2897,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
2888
2897
  return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
2889
2898
  }
2890
2899
 
2891
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/build-pack.ts
2900
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/build-pack.ts
2892
2901
  function packCompilerOpts(o) {
2893
2902
  return { studs: o.studs ?? "low", prims: o.primitives ?? "full", weld: o.weld ?? true, separateStuds: true, cond: !!o.cond, tex: !!o.textures, ...o.partWorkLimit ? { workLimit: o.partWorkLimit } : {} };
2894
2903
  }
@@ -2961,7 +2970,7 @@ function buildPack(o) {
2961
2970
  return { data: encodePack(parts, kinds, comp.opts.weld, extra, { texture, lod: o.lod !== false, reorder: !!o.reorder }), parts: parts.size, studKinds: kinds.size, missing: [...missing], ...warnings.length ? { warnings } : {} };
2962
2971
  }
2963
2972
 
2964
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/cli.ts
2973
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/cli.ts
2965
2974
  var HELP = `ldr pack — build a parts pack for the ldr three.js renderer
2966
2975
 
2967
2976
  Usage:
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/spec.ts
1
+ // ../../../../../../../tmp/ldr-build-s89ZOB/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;
@@ -809,7 +809,7 @@ function fileStepViews(f) {
809
809
  viewMemo.set(f, out);
810
810
  return out;
811
811
  }
812
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/model.ts
812
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/model.ts
813
813
  class ModelLimitError extends Error {
814
814
  limit;
815
815
  code = "ldr-model-limit";
@@ -859,6 +859,15 @@ function flatten(doc, opts = {}) {
859
859
  const loose = opts.looseGeometry !== false, tx = !!opts.textures, co = !!opts.callouts;
860
860
  const src = new Map;
861
861
  let subs = 0;
862
+ const stepSingles = [];
863
+ const stepPathOf = (path, s) => {
864
+ if (path.length)
865
+ return [...path, s];
866
+ let a = stepSingles[s];
867
+ if (!a)
868
+ stepSingles[s] = a = [s];
869
+ return a;
870
+ };
862
871
  const open = new Set;
863
872
  const maxN = opts.maxInstances ?? 2000000;
864
873
  let work = 0;
@@ -938,7 +947,7 @@ function flatten(doc, opts = {}) {
938
947
  const flushLoose = (upTo) => {
939
948
  while (li < ls.length && ls[li] <= upTo) {
940
949
  const k = ls[li++];
941
- emit(loosePartName(f.name, k), color, m, [...stepPath, k], k, false, null, colour, scope0).source = lazy(f, k);
950
+ emit(loosePartName(f.name, k), color, m, stepPathOf(stepPath, k), k, false, null, colour, scope0).source = lazy(f, k);
942
951
  }
943
952
  };
944
953
  for (const c0 of f.cmds) {
@@ -969,10 +978,10 @@ function flatten(doc, opts = {}) {
969
978
  continue;
970
979
  if (tx && c.fallback)
971
980
  continue;
972
- const mm = mul(m, c.m);
981
+ const mm = m === I ? c.m : mul(m, c.m);
973
982
  if (!inRange12(mm))
974
983
  continue;
975
- const col = c.color === 16 ? color : c.color, cd = c.color === 16 ? colour : scope?.get(c.color), sp = [...stepPath, s];
984
+ const col = c.color === 16 ? color : c.color, cd = c.color === 16 ? colour : scope?.get(c.color), sp = stepPathOf(stepPath, s);
976
985
  const tex = tx ? c.tex ?? texIn : null;
977
986
  const local = tex ? invert(c.m) : null;
978
987
  const lt = tex && local ? transformTexMap(tex, local) : null;
@@ -1250,7 +1259,7 @@ function blendedColourHex(code) {
1250
1259
  const a = LDRAW_EXE_16[code - 256 >> 4], b = LDRAW_EXE_16[code - 256 & 15];
1251
1260
  return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
1252
1261
  }
1253
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/instructions.ts
1262
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/instructions.ts
1254
1263
  var MIN_VIS = 0.5;
1255
1264
  var REORIENT = 0.35;
1256
1265
  var deg = Math.PI / 180;
@@ -1618,10 +1627,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
1618
1627
  }
1619
1628
  };
1620
1629
  }
1621
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/render.ts
1630
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/render.ts
1622
1631
  import * as THREE2 from "three";
1623
1632
 
1624
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/pack-io.ts
1633
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/pack-io.ts
1625
1634
  import { decompress } from "fzstd";
1626
1635
  async function decompressPack(data) {
1627
1636
  const u = data instanceof Uint8Array ? data : new Uint8Array(data);
@@ -1644,7 +1653,7 @@ function decodePack(buf) {
1644
1653
  return { header, arr, bytes: buf.byteLength, buffer: buf };
1645
1654
  }
1646
1655
 
1647
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/stud-decal.ts
1656
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/stud-decal.ts
1648
1657
  import * as THREE from "three";
1649
1658
  function studDecalUniforms(near = 0) {
1650
1659
  return { center: { value: new THREE.Vector3 }, near: { value: near } };
@@ -1743,7 +1752,7 @@ roughnessFactor = clamp(roughnessFactor * mix(1.0, sdTop > 0.5 ? 0.85 : 1.1, sdK
1743
1752
  return d;
1744
1753
  }
1745
1754
 
1746
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/cull.ts
1755
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/cull.ts
1747
1756
  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;
1748
1757
  var prepCache = new WeakMap;
1749
1758
  var lastH = null;
@@ -2325,7 +2334,7 @@ function precomputeCull(instances, H, useTex = true) {
2325
2334
  return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
2326
2335
  }
2327
2336
 
2328
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/render.ts
2337
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/render.ts
2329
2338
  async function loadPack(url) {
2330
2339
  const res = await fetch(url);
2331
2340
  if (!res.ok)
@@ -4863,7 +4872,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
4863
4872
  await new Promise((r) => setTimeout(r, 0));
4864
4873
  }
4865
4874
  }
4866
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/scene.ts
4875
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/scene.ts
4867
4876
  import * as THREE3 from "three";
4868
4877
  var _box = new THREE3.Box3;
4869
4878
  var _m4 = new THREE3.Matrix4;
@@ -5267,10 +5276,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
5267
5276
  return finish();
5268
5277
  })();
5269
5278
  }
5270
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/parts-cdn.ts
5279
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/parts-cdn.ts
5271
5280
  import { decompress as decompress2 } from "fzstd";
5272
5281
 
5273
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/embedded.ts
5282
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/embedded.ts
5274
5283
  function splitFiles(text, fallback) {
5275
5284
  const files = new Map;
5276
5285
  let cur = null, saw = false, skip = false;
@@ -5348,7 +5357,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
5348
5357
  return out;
5349
5358
  }
5350
5359
 
5351
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/parts-cdn.ts
5360
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/parts-cdn.ts
5352
5361
  var DEFAULT_PARTS_CDN = "https://ldr-parts-cdn.baconbrix.workers.dev/v1/";
5353
5362
  var indexCache = new Map;
5354
5363
  var shardCache = new Map;
@@ -5609,10 +5618,10 @@ async function prepareModel(source, o = {}) {
5609
5618
  return { insts, pack, tier, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
5610
5619
  }
5611
5620
 
5612
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/load-worker.gen.ts
5613
- var load_worker_gen_default = 'var sn=ArrayBuffer,H=Uint8Array,$e=Uint16Array,on=Int16Array;var je=Int32Array,Ye=function(e,t,n){if(H.prototype.slice)return H.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 H(n-t);return r.set(e.subarray(t,n)),r},Be=function(e,t,n,r){if(H.prototype.fill)return H.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},an=function(e,t,n,r){if(H.prototype.copyWithin)return H.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 ln=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],Z=function(e,t,n){var r=Error(t||ln[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Z);if(!n)throw r;return r},yt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},cn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},un=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,c=r>>6;if(r&8)Z(0);var a=6-s,u=i==3?4:i,l=yt(e,a,u);a+=u;var f=c?1<<c:s,h=yt(e,a,f)+(c==1&&256),g=h;if(!s){var p=1<<10+(e[5]>>3);g=p+(p>>3)*(e[5]&7)}if(g>2145386496)Z(1);var m=new H((t==1?h||g:t?0:g)+12);return m[0]=1,m[4]=4,m[8]=8,{b:a+f,y:0,l:0,d:l,w:t&&t!=1?t:m.subarray(12),e:g,o:new je(m.buffer,0,3),u:h,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return cn(e,4)+8;Z(0)},Se=function(e){var t=0;for(;1<<t<=e;++t);return t-1},De=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Z(3);var o=1<<s,i=o,c=-1,a=-1,u=-1,l=o,f=new sn(512+(o<<2)),h=new on(f,0,256),g=new $e(f,0,256),p=new $e(f,512,o),m=512+(o<<1),A=new H(f,m,o),b=new H(f,m+o);while(c<255&&i>0){var d=Se(i+1),x=r>>3,w=(1<<d+1)-1,v=(e[x]|e[x+1]<<8|e[x+2]<<16)>>(r&7)&w,M=(1<<d)-1,U=w-i-1,S=v&M;if(S<U)r+=d,v=S;else if(r+=d+1,v>M)v-=U;if(h[++c]=--v,v==-1)i+=v,A[--l]=c;else i-=v;if(!v)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)Z(0);var y=0,R=(o>>1)+(o>>3)+3,C=o-1;for(var F=0;F<=c;++F){var B=h[F];if(B<1){g[F]=-B;continue}for(u=0;u<B;++u){A[y]=F;do y=y+R&C;while(y>=l)}}if(y)Z(0);for(u=0;u<o;++u){var L=g[A[u]]++,V=b[u]=s-Se(L);p[u]=(L<<V)-o}return[r+7>>3,{b:s,s:A,n:b,t:p}]},fn=function(e,t){var n=0,r=-1,s=new H(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),a=new $e(s.buffer,268);if(o<128){var u=De(e,t+1,6),l=u[0],f=u[1];t+=o;var h=l<<3,g=e[t];if(!g)Z(0);var p=0,m=0,A=f.b,b=A,d=(++t<<3)-8+Se(g);for(;;){if(d-=A,d<h)break;var x=d>>3;if(p+=(e[x]|e[x+1]<<8)>>(d&7)&(1<<A)-1,i[++r]=f.s[p],d-=b,d<h)break;x=d>>3,m+=(e[x]|e[x+1]<<8)>>(d&7)&(1<<b)-1,i[++r]=f.s[m],A=f.n[p],p=f.t[p],b=f.n[m],m=f.t[m]}if(++r>255)Z(0)}else{r=o-127;for(;n<r;n+=2){var w=e[++t];i[n]=w>>4,i[n+1]=w&15}++t}var v=0;for(n=0;n<r;++n){var M=i[n];if(M>11)Z(0);v+=M&&1<<M-1}var U=Se(v)+1,S=1<<U,D=S-v;if(D&D-1)Z(0);i[r++]=Se(D)+1;for(n=0;n<r;++n){var M=i[n];++c[i[n]=M&&U+1-M]}var y=new H(S<<1),R=y.subarray(0,S),C=y.subarray(S);a[U]=0;for(n=U;n>0;--n){var F=a[n];Be(C,n,F,a[n-1]=F+c[n]*(1<<U-n))}if(a[0]!=S)Z(0);for(n=0;n<r;++n){var B=i[n];if(B){var L=a[B];Be(R,n,L,a[B]=L+(1<<U-B))}}return[t,{n:C,b:U,s:R}]},pn=De(new H([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],mn=De(new H([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],hn=De(new H([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],xt=function(e,t){var n=e.length,r=new je(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Je=new H(new je([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),gn=xt(Je,0),Qe=new H(new je([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),dn=xt(Qe,3),Re=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)Z(0);var a=0,u=n.b,l=(r<<3)-8+Se(o)-u,f=-1;for(;l>c&&f<s;){var h=l>>3,g=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(l&7);a=(a<<u|g)&i,t[++f]=n.s[a],l-=u=n.n[a]}if(l!=c||f+1!=s)Z(0)},bn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;Re(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Re(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Re(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),Re(e.subarray(r),t.subarray(c),n)},yn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Be(n,e[s],t.y,t.y+=c),n;return Be(new H(c),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=c,n;return Ye(e,s,a)}if(i==2){var u=e[s],l=u&3,f=u>>2&3,h=u>>4,g=0,p=0;if(l<2)if(f&1)h|=e[++s]<<4|(f&2&&e[++s]<<12);else h=u>>3;else if(p=f,f<2)h|=(e[++s]&63)<<4,g=e[s]>>6|e[++s]<<2;else if(f==2)h|=e[++s]<<4|(e[++s]&3)<<12,g=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,g=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var m=n?n.subarray(t.y,t.y+t.m):new H(t.m),A=m.length-h;if(l==0)m.set(e.subarray(s,s+=h),A);else if(l==1)Be(m,e[s++],A);else{var b=t.h;if(l==2){var d=fn(e,s);g+=s-(s=d[0]),t.h=b=d[1]}else if(!b)Z(0);(p?bn:Re)(e.subarray(s,s+=g),m.subarray(A),b)}var x=e[s++];if(x){if(x==255)x=(e[s++]|e[s++]<<8)+32512;else if(x>127)x=x-128<<8|e[s++];var w=e[s++];if(w&3)Z(0);var v=[mn,hn,pn];for(var M=2;M>-1;--M){var U=w>>(M<<1)+2&3;if(U==1){var S=new H([0,0,e[s++]]);v[M]={s:S.subarray(2,3),n:S.subarray(0,1),t:new $e(S.buffer,0,1),b:0}}else if(U==2)r=De(e,s,9-(M&1)),s=r[0],v[M]=r[1];else if(U==3){if(!t.t)Z(0);v[M]=t.t[M]}}var D=t.t=v,y=D[0],R=D[1],C=D[2],F=e[a-1];if(!F)Z(0);var B=(a<<3)-8+Se(F)-C.b,L=B>>3,V=0,me=(e[L]|e[L+1]<<8)>>(B&7)&(1<<C.b)-1;L=(B-=R.b)>>3;var be=(e[L]|e[L+1]<<8)>>(B&7)&(1<<R.b)-1;L=(B-=y.b)>>3;var ye=(e[L]|e[L+1]<<8)>>(B&7)&(1<<y.b)-1;for(++x;--x;){var ue=C.s[me],Pe=C.n[me],xe=y.s[ye],Ce=y.n[ye],ke=R.s[be],he=R.n[be];L=(B-=ke)>>3;var O=1<<ke,k=O+((e[L]|e[L+1]<<8|e[L+2]<<16|e[L+3]<<24)>>>(B&7)&O-1);L=(B-=Qe[xe])>>3;var J=dn[xe]+((e[L]|e[L+1]<<8|e[L+2]<<16)>>(B&7)&(1<<Qe[xe])-1);L=(B-=Je[ue])>>3;var _=gn[ue]+((e[L]|e[L+1]<<8|e[L+2]<<16)>>(B&7)&(1<<Je[ue])-1);if(L=(B-=Pe)>>3,me=C.t[me]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<Pe)-1),L=(B-=Ce)>>3,ye=y.t[ye]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<Ce)-1),L=(B-=he)>>3,be=R.t[be]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<he)-1),k>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=k-=3;else{var W=k-(_!=0);if(W){if(k=W==3?t.o[0]-1:t.o[W],W>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=k}else k=t.o[0]}for(var M=0;M<_;++M)m[V+M]=m[A+M];V+=_,A+=_;var ne=V-k;if(ne<0){var q=-ne,le=t.e+ne;if(q>J)q=J;for(var M=0;M<q;++M)m[V+M]=t.w[le+M];V+=q,J-=q,ne=0}for(var M=0;M<J;++M)m[V+M]=m[ne+M];V+=J}if(V!=A)while(A<m.length)m[V++]=m[A++];else V=m.length;if(n)t.y+=V;else m=Ye(m,0,V)}else if(n){if(t.y+=h,A)for(var M=0;M<h;++M)m[M]=m[A+M]}else if(A)m=Ye(m,A);return t.b=a,m}Z(2)},xn=function(e,t){if(e.length==1)return e[0];var n=new H(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 Ve(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=un(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 c=yn(e,i,t);if(!c)Z(5);if(t)i.e=i.y;else n.push(c),o+=c.length,an(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return xn(n,o)}async function wn(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(Ve(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 wt(e){return new TextDecoder().decode(await wn(e))}var At=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function _e(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 Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),et=/^[A-Za-z][A-Za-z0-9_]*$/,qe=new Map;function tt(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(!qe.has(r))qe.set(r,t);return r}function nt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&et.test(e))return tt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,An=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Mn=new Set(["FILE","NOFILE","!DATA"]),Pt=1000000000000000,It=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),vn=new Set(["model","submodel","configuration"]),Cn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function vt(e){let t=Cn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return It.has(n)||vn.has(n)?n:void 0}function kn(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 Tn(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((f)=>Number.isFinite(f)&&Math.abs(f)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let f=0;f<s;f++)c=c.replace(/^\\S+\\s*/,"");let a=kn(c);if(!a.length)return null;let u={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)u.a=i[9];if(s===11)u.b=i[10];let l=a.findIndex((f,h)=>h>0&&f.toUpperCase()==="GLOSSMAP");if(l>0&&a[l+1])u.glossmap=a[l+1];if(t)u.next=!0;return u}var Ln=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let 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 Sn(e,t){let n=e.length,r=1,s=(p)=>p===32||p===9,o=()=>{while(r<n&&s(e.charCodeAt(r)))r++;let p=r,m=e.charCodeAt(r),A=m===45;if(A)m=e.charCodeAt(++r);let b=0,d=0;while(m>=48&&m<=57)b=b*10+(m-48),d++,m=e.charCodeAt(++r);if(d>0&&d<=15&&(r>=n||s(m)))return A?-b:b;while(r<n&&!s(e.charCodeAt(r)))r++;return p<r?+e.slice(p,r):NaN};while(r<n&&s(e.charCodeAt(r)))r++;let i=r;if(r>=n)return null;let c=e.charCodeAt(r),a=c===45,u=0,l=0;if(a)c=e.charCodeAt(++r);while(c>=48&&c<=57)u=u*10+(c-48),l++,c=e.charCodeAt(++r);if(l>0&&l<=15&&(r>=n||s(c))){if(a)u=-u}else{while(r<n&&!s(e.charCodeAt(r)))r++;u=nt(e.slice(i,r))}let f=Array(12);for(let p=0;p<12;p++){let m=o();if(!Number.isFinite(m))return null;f[p]=m}while(r<n&&s(e.charCodeAt(r)))r++;if(r>=n)return null;let h=e.slice(r),g=t.get(h);if(g===void 0)g=Y(/[ \\t]{2,}|\\t/.test(h)?h.split(/\\s+/).join(" "):h),t.set(h,g);if(!Number.isFinite(u))return null;return{t:1,color:u,m:f,file:g}}var En=[0,12,6,9,12,12];function Ct(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=nt(e[1]),r=En[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Y(e.slice(14).join(" "));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Ft(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,a=null,u=[],l=null,f=()=>{if(!a)return;let x=Ln(a.chunks.join("")),w=x[0]===137&&x[1]===80&&x[2]===78&&x[3]===71;(c??=new Map).set(Y(a.name),{name:a.name,bytes:x,...w?{mime:"image/png"}:{}}),a=null},h=new Map,g=!0,p=(x)=>{if(f(),o={name:Y(x),cmds:[]},s.set(o.name,o),!i)i=o.name;u=[],l=null,g=!0},m=!1,A=!1,b=()=>{if(A)return;A=!0,s.clear(),o=null,i=""},d=(x,w)=>{if(l){x.tex=l,l=null;return}let v=u[u.length-1];if(!v)return;if(v.fallback){if(!w)x.fallback=!0}else x.tex=v.map};for(let x of e.split(`\n`)){let w=x.trim();if(!w)continue;if(r&&w.charCodeAt(0)>=50&&w.charCodeAt(0)<=53&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)){if(a||m)continue;if(!o)p(t);let S=w.slice(2).trimStart(),D=S.search(/\\s/),y={t:w.charCodeAt(0)-48,color:nt(D<0?S:S.slice(0,D)),p:[],src:w};d(y,!1),o.cmds.push(y),g=!1;continue}if(w.charCodeAt(0)===48&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)){let S=2;while(w.charCodeAt(S)===32||w.charCodeAt(S)===9)S++;let D=S;while(D<w.length&&w.charCodeAt(D)!==32&&w.charCodeAt(D)!==9)D++;let y=w.slice(S,D),R=/[^\\x21-\\x7e]/.test(y)?w.slice(S).trim().split(/\\s+/)[0]:y;if(!An.has(R)&&!(R.length>=4&&R.length<=6&&Mn.has(R.toUpperCase()))){if(m||a)continue;if(!o)p(t);let C=w.slice(S),F={t:0,text:C};if(y.charCodeAt(0)===33)F.meta=y;if(l=null,g&&!o.org){let L=vt(C);if(L)o.org=L}let B=C.match(Mt);if(B&&!o.movedTo){let L=B[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(L))L+=".dat";o.movedTo=Y(L)}o.cmds.push(F);continue}}if(w.charCodeAt(0)===49&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)&&!a&&!m){let S=Sn(w,h);if(S){if(!o)p(t);d(S,!1),o.cmds.push(S),g=!1;continue}}let v=w.split(/\\s+/);if(+v[0]===0){let S=w.slice(1).trim(),D=v.length>1&&v[1].length>=4&&v[1].length<=6?v[1].toUpperCase():v[1];if(D==="FILE"){let C=S.slice(5).trimStart().split("\\r")[0].trim();if(C){b(),m=!1,p(C);continue}}if(D==="NOFILE"){f(),o=null,m=!0;continue}if(D==="!DATA"){b(),f(),o=null,m=!1,a={name:S.slice(5).trim(),chunks:[]};continue}if(m)continue;if(a){if(v[1]==="!:")a.chunks.push(v.slice(2).join(""));continue}if(!o)p(t);let y={t:0,text:S};if(v[1]==="STEP")y.step=!0,u=[],l=null;else if(v[1]==="BFC")y.bfc=v.slice(2).join(" ");else if(v[1]==="ROTSTEP")if(y.meta="ROTSTEP",y.step=!0,u=[],l=null,(v[2]??"").toUpperCase()==="END")y.rotstep={x:0,y:0,z:0,mode:"END"};else{let C=(v[5]??"REL").toUpperCase(),F=(B)=>{let L=Number(B);return Number.isFinite(L)?L:0};y.rotstep={x:F(v[2]),y:F(v[3]),z:F(v[4]),mode:["REL","ABS","ADD"].includes(C)?C:"REL"}}else if(v[1]==="BUFEXCHG"){y.meta="BUFEXCHG";let C=(v[2]??"").toUpperCase();y.bufexchg={op:C==="RETRIEVE"?"RETRIEVE":"STORE",buf:v[3]??"A"}}else if(v[1]?.startsWith("!"))y.meta=v[1];if(g&&!o.org){let C=vt(S);if(C)o.org=C}if(v[1]==="!TEXMAP"){let C=(v[2]??"").toUpperCase();if(l=null,C==="START"||C==="NEXT"){let F=Tn(S.replace(/^!TEXMAP\\s+\\S+/i,""),C==="NEXT");if(y.texmap={op:C,...F?{map:F}:{}},F)if((o.texmaps??=[]).push(F),C==="START")u.push({map:F,fallback:!1});else l=F}else if(C==="FALLBACK"){y.texmap={op:C};let F=u[u.length-1];if(F)F.fallback=!0}else if(C==="END")y.texmap={op:C},u.pop()}else if(v[1]==="!:"){l=null;let C=Ct(v.slice(2));if(C)d(C,!0),y.geom=C}else l=null;let R=S.match(Mt);if(R&&!o.movedTo){let C=R[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Y(C)}o.cmds.push(y);continue}if(a||m)continue;if(!o)p(t);let U=Ct(v);if(!U){if(/^[2-5][ \\t]/.test(w))g=!1;continue}d(U,!1),o.cmds.push(U),g=!1}return f(),c?{main:i,files:s,data:c}:{main:i,files:s}}var sr=Math.PI/180;function Rt(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 Bt(e,t){let[n,r,s,o,i,c,a,u,l,f,h,g]=e,[p,m,A,b,d,x,w,v,M,U,S,D]=t;return[o*p+i*m+c*A+n,a*p+u*m+l*A+r,f*p+h*m+g*A+s,o*b+i*w+c*U,o*d+i*v+c*S,o*x+i*M+c*D,a*b+u*w+l*U,a*d+u*v+l*S,a*x+u*M+l*D,f*b+h*w+g*U,f*d+h*v+g*S,f*x+h*M+g*D]}var rt=[0,0,0,1,0,0,0,1,0,0,0,1];var kt=new WeakMap,Pn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=kt.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&&Pn.test(s.file))?"part":"model";return kt.set(n,r),r}var Tt=new WeakMap;function Dt(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 Lt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?qe.get(e)??String(e):String(e),In=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Lt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Lt(e.color)} ${e.p.join(" ")}`,ot=(e,t)=>`${Y(e)}#${t}`;function Fn(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:ot(e.name,t),cmds:n}}function Ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Fn(e,t).cmds.map(In)].join(`\n`)+`\n`}function it(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 Nt(e){let[t,n,r,s,o,i,c,a,u,l,f,h]=e,g=a*h-u*f,p=-(c*h-u*l),m=c*f-a*l,A=s*g+o*p+i*m;if(!Number.isFinite(A)||Math.abs(A)<0.000000000001)return null;let b=1/A,d=[g*b,-(o*h-i*f)*b,(o*u-i*a)*b,p*b,(s*h-i*l)*b,-(s*u-i*c)*b,m*b,-(s*f-o*l)*b,(s*a-o*c)*b];return[-(d[0]*t+d[1]*n+d[2]*r),-(d[3]*t+d[4]*n+d[5]*r),-(d[6]*t+d[7]*n+d[8]*r),...d]}var Rn=(e)=>String(+e.toFixed(6)||0),St=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Ot(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Rn).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 ${Y(e)}\n0 !TEXMAP END\n`;return{name:`${Y(e)}#tex-${it(r)}`,source:r}}var Bn=(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 Dn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),u=Math.cos(n*r);return[c*u,-c*a,i,o*a+s*i*u,o*u-s*i*a,-s*c,s*a-o*i*u,s*u+o*i*a,o*c]}var Et=new WeakMap;function zt(e){let t=Et.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=Dn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Bn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Et.set(e,n),n}class at extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var Un=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=Pt))return!1;return!0},$t=999999,_t=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Gt=new WeakMap,jt=new WeakMap;function Nn(e,t){let n=jt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Gt.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},jt.set(t,n);let r=n.parts.get(e);if(!r){let s=Y(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-${it(o)}`,source:o},n.parts.set(e,r)}return r}function On(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,a=0,u=new Set,l=t.maxInstances??2000000,f=0,h=(p,m)=>{let A=p.name+"#"+m,b=c.get(A);if(!b){let d;b=Object.assign(()=>d??=Ut(p,m),{file:p,step:m}),c.set(A,b)}return b},g=(p,m,A,b,d,x,w,v,M=null,U=[],S=[],D=void 0,y=null)=>{let R=p.files.get(m);if(!R||w>r||u.has(R))return;if(++f>l)throw new at("model",l);u.add(R);let C=y,F=0,B=w>0?++a:0,L=i&&B?[...U,B]:U,V=i&&B?[...S,A]:S,me=i&&!M?new Map:null,be=-1,ye=0,ue=(O,k,J,_,W,ne,q)=>{if(be!==F)be=F,ye=0;let le=me?.get(F+"|"+k);if(le)return le.n++,g(O,O===p?k:O.main,J,_,d+"/"+k,[...W,$t],w+1,ne,[...W,$t],L,V,q,C);let T=[...W,ye++],P=n.length;g(O,O===p?k:O.main,J,_,d+"/"+k,T,w+1,ne,M,L,V,q,C),me?.set(F+"|"+k,{n:1,from:P,to:n.length})},Pe=zt(R),xe=s?Dt(R):[],Ce=0,ke=(O,k,J,_,W,ne,q,le,T)=>{if(M)_=M;if(++f>l)throw new at("model",l);let P={part:O,color:k,m:J,step:_[0],steps:_,localStep:W,path:d};if(le)P.colour=le;if(B){if(P.sub=B,i)P.subPath=L,P.subMats=V}if(ne)P.embedded=!0;if(q){let N=Ot(O,q);P.texPart=N.name,P.texSource=N.source}else if(T){let N=Nn(O,T);P.colPart=N.name,P.colSource=N.source}let E=Pe[W];if(E)P.view=E;return n.push(P),P},he=(O)=>{while(Ce<xe.length&&xe[Ce]<=O){let k=xe[Ce++];ke(ot(R.name,k),b,A,[...x,k],k,!1,null,D,y).source=h(R,k)}};for(let O of R.cmds){if(O.t===0&&O.step){F++;continue}let k=O;if(k.t>=2||k.t===0&&k.geom&&k.geom.t>=2){he(F);continue}if(k.t===0){if(k.meta==="!COLOUR"){let E=$n(k.text);if(E&&E.code!==16&&E.code!==24)Gt.set(E,k.text),(C=new Map(C??[])).set(E.code,E);continue}if(o&&k.geom?.t===1)k=k.geom;else continue}if(k.t!==1)continue;if(o&&k.fallback)continue;let J=Bt(A,k.m);if(!Un(J))continue;let _=k.color===16?b:k.color,W=k.color===16?D:C?.get(k.color),ne=[...x,F],q=o?k.tex??v:null,le=q?Nt(k.m):null,T=q&&le?Rt(q,le):null;if(p.files.has(k.file)){if(st(p,k.file)==="model"){ue(p,k.file,J,_,ne,T,W);continue}ke(k.file,_,J,ne,F,!0,T,W,C);continue}let P=t.resolveModel?.(k.file);if(P){ue(P,k.file,J,_,ne,T,W);continue}ke(k.file,_,J,ne,F,!1,T,W,C)}if(he(1/0),u.delete(R),me){for(let O of me.values())if(O.n>1)for(let k=O.from;k<O.to;k++)n[k].mult??=O.n}};if(st(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...rt],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,rt,16,e.main,[],0,null),n}function Ht(e,t="main.ldr",n){return On(Ft(e,t,{geometryText:!0}),n)}var zn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function lt(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 Vt(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=lt(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 $n(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",c=255,a=0,u={type:"default"},l=1;while(l<n.length){let f=n[l].toUpperCase(),h=n[l+1];if(f==="CODE")s=h!==void 0&&et.test(h)?tt(h):h!==void 0&&/^\\d+$/.test(h)?+h:NaN,l+=2;else if(f==="VALUE"){let g=lt(h);if(g)o=g;l+=2}else if(f==="EDGE")i=lt(h)??h,l+=2;else if(f==="ALPHA")c=+h,l+=2;else if(f==="LUMINANCE")a=+h,l+=2;else if(f==="CHROME")u={type:"chrome"},l+=1;else if(f==="PEARLESCENT")u={type:"pearlescent"},l+=1;else if(f==="RUBBER")u={type:"rubber"},l+=1;else if(f==="MATTE_METALLIC")u={type:"matte_metallic"},l+=1;else if(f==="METAL")u={type:"metal"},l+=1;else if(f==="MATERIAL"){let g=(n[l+1]||"").toUpperCase();if(g==="GLITTER"){let{grain:p,next:m}=Vt(n,l+2);u={type:"glitter",material:p},l=m}else if(g==="SPECKLE"){let{grain:p,next:m}=Vt(n,l+2);u={type:"speckle",material:p},l=m}else if(g==="FABRIC"){let p=(n[l+2]||"").toUpperCase(),m=["VELVET","CANVAS","STRING","FUR"].includes(p)?p.toLowerCase():void 0;u={type:"fabric",kind:m},l+=m?3:2}else l=n.length}else if(zn.has(f))l+=1;else l+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(a)?a:0,finish:u}}function jn(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,c=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:c,finish:"glitter"}}case"speckle":{let i=e.finish.material,c=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:c,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 ct(e){let t=jn(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 Vn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Y(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Y(t),r)}let a=i.trim().replace(/\\s+/g," ");if(a)r.push(a)}return n}var _n=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function Gn(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 Wt(e,t,n="main.ldr"){let r=[...t],s=new Map;if(!r.length)return s;let o=Vn(e,n);for(let i of r){let c=Y(i);if(!o.has(c)||s.has(c))continue;let a=new Set([c]),u=[c];while(u.length)for(let f of o.get(u.pop())){let h=_n(f);if(h&&o.has(h)&&!a.has(h))a.add(h),u.push(h)}let l=[c,...[...a].filter((f)=>f!==c).sort()].map((f)=>"0 FILE "+(f===c?"":f)+`\n`+o.get(f).join(`\n`)).join(`\n`);s.set(c,`emb/${Gn(l)}.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,Kt=new WeakMap,ut=null,ft="",pt=null;function Hn(e,t){if(e===ut&&t===ft)return pt;let n=Kt.get(e);if(!n)Kt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return ut=e,ft=t,pt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],a=[];s.studs.forEach((g,p)=>{c.push(g[0]),a.push(g[1]);for(let m=0;m<12;m++)i[p*12+m]=g[2+m]});let u=null,l=0,f=0;if(s.mask){l=s.mask[0],f=s.mask[1];let g=s.mask[2];u=new Uint8Array(g.length);for(let p=0;p<g.length;p++)u[p]=g.charCodeAt(p)===49?1:0}let h=!!u;if(u){for(let g=0;g<u.length;g++)if(u[g]!==1){h=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:a,mask:u,nx:l,nz:f,full:h}),ut=e,ft=t,pt=r,r}var Ie=1073741824;class Ee{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=Ee.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let a=s[c];if(a===0)return-1;if(a===r){let u=c<<2;if(o[u]===e&&o[u+1]===t&&o[u+2]===n)return o[u+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=Ee.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,a=this.slot(e,t,n);for(;;){let u=o[a],l=a<<2;if(u===0)return o[a]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(u===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let f=i[l+3];return i[l+3]=r,f}a=a+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Yt{grp=new Ee(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],a=[];for(let f=0;f<r;f++){let h=e[f],g=t[f],p=n[f],m=(h%20+20)%20,A=(p%20+20)%20,b=this.group(g,m,A);if(b<0)b=s.length,this.grp.put(g,m,A,b),this.lg=b,s.push(0),o.push(h),i.push(h),c.push(p),a.push(p);if(s[b]++,h<o[b])o[b]=h;else if(h>i[b])i[b]=h;if(p<c[b])c[b]=p;else if(p>a[b])a[b]=p}let u=0,l=0;for(let f=0;f<s.length;f++){let h=(i[f]-o[f])/20+1,g=(a[f]-c[f])/20+1,p=h*g;if(this.gX0.push(o[f]),this.gZ0.push(c[f]),this.gNx.push(h),this.gNz.push(g),p<=64*s[f]+1024&&u+p<2147483648)this.gBits.push(u),u+=p;else this.gBits.push(-1),l+=s[f]}this.bits=new Uint8Array(Math.ceil(u/8)),this.rest=new Ee(l);for(let f=0;f<r;f++){let h=e[f],g=t[f],p=n[f],m=this.group(g,(h%20+20)%20,(p%20+20)%20),A=this.gBits[m];if(A<0){this.rest.put(h,g,p,1);continue}let b=A+(h-this.gX0[m])/20*this.gNz[m]+(p-this.gZ0[m])/20;this.bits[b>>>3]|=1<<(b&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Wn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Fe=(e,t,n)=>e>-Ie&&e<Ie&&t>-Ie&&t<Ie&&n>-Ie&&n<Ie,Ue=2147483647;function Xn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function mt(e,t,n){return Zt(e,t,n,-1)??Zt(e,t,n,Jt)}var Jt=0;function Zt(e,t,n,r){let o=new Map,i=(T)=>{let P=o.get(T);if(P===void 0)o.set(T,P=Xn(t,T));return P},c=e.length,a=0,u=0,l=0,f=Array(c);for(let T=0;T<c;T++){let P=f[T]=Hn(t,e[T].part);if(P){if(l+=P.nStuds,P.mask)a++}}let h=new Float64Array(a),g=new Float64Array(a),p=new Float64Array(a),m=new Float64Array(a),A=new Int32Array(a),b=new Int32Array(a),d=new Float64Array(a),x=new Float64Array(a),w=[],v=new Int32Array(a),M=new Float64Array(a*9),U=new Uint8Array(a);if(r<0)r=a*4+64;let S=new Ee(e.length*2),D=new Int32Array(r),y=new Int32Array(r),R=0,C=0;for(let T=0;T<e.length;T++){let P=e[T],E=P.m,N=t.parts[P.part];if(!N||!N.mask||!Xt(E)||i(P.color))continue;let I=N.bbox,z=1/0,j=-1/0,ee=1/0,X=-1/0;for(let K=0;K<2;K++)for(let ae=0;ae<2;ae++){let te=K?I[3]:I[0],Le=ae?I[5]:I[2],ve=E[0]+E[3]*te+E[5]*Le,de=E[2]+E[9]*te+E[11]*Le;if(ve<z)z=ve;if(ve>j)j=ve;if(de<ee)ee=de;if(de>X)X=de}let G=Math.round((E[1]+I[4])*2),Q=f[T],ce=Math.floor(z/40),we=Math.floor(j/40),Ae=Math.floor(ee/40),Me=Math.floor(X/40);if(!((we-ce+1)*(Me-Ae+1)<=65536)||!Fe(G,ce,Ae)||!Fe(G,we,Me))continue;let ge=Math.floor((z+5)/40),re=Math.floor((j-5)/40),se=Math.floor((ee+5)/40),oe=Math.floor((X-5)/40),Te=ge<=re&&se<=oe?(re-ge+1)*(oe-se+1):0;C+=Te;let fe=-1;for(let K=ge<=re&&se<=oe?S.get(G,ge,se):-1,ae=0;K>=0&&ae<8;K=D[K],ae++){let te=y[K];if(h[te]!==z||g[te]!==j||p[te]!==ee||m[te]!==X||w[te]!==Q)continue;let Le=e[A[te]].m,ve=!0;for(let de=0;de<12;de++)if(Le[de]!==E[de]){ve=!1;break}if(ve){fe=te;break}}if(fe>=0){let K=n?n[T]:0;if(n&&K<n[A[fe]])b[fe]=A[fe],A[fe]=T;else if(b[fe]<0||n&&K<n[b[fe]])b[fe]=T;continue}let ie=u++;h[ie]=z,g[ie]=j,p[ie]=ee,m[ie]=X,A[ie]=T,b[ie]=-1,w.push(Q),d[ie]=I[0],x[ie]=I[2],v[ie]=G;let pe=ie*9;if(M[pe]=E[0],M[pe+1]=E[1],M[pe+2]=E[2],M[pe+3]=E[3],M[pe+4]=E[6],M[pe+5]=E[9],M[pe+6]=E[5],M[pe+7]=E[8],M[pe+8]=E[11],U[ie]=Q.full&&I[3]-I[0]<=20*Q.nx&&I[5]-I[2]<=20*Q.nz&&E[4]===0&&E[6]===0&&E[8]===0&&E[10]===0&&Wn(E[3],E[5],E[9],E[11])?1:0,R+Te>r){R=r+1;continue}for(let K=ge;K<=re;K++)for(let ae=se;ae<=oe;ae++){if(!Fe(G,K,ae))continue;let te=R++;y[te]=ie,D[te]=S.put(G,K,ae,te)}}if(R>r)return Jt=C,null;let F=[0,5,-5,5,-5],B=[0,5,5,-5,-5],L=(T,P,E,N)=>{if(!(P-6>=h[T]-0.5&&P+6<=g[T]+0.5&&N-6>=p[T]-0.5&&N+6<=m[T]+0.5))return!1;if(U[T]===1)return!0;let I=T*9,z=w[T],j=d[T],ee=x[T],X=P-M[I],G=E-M[I+1],Q=N-M[I+2],ce=M[I+3]*X+M[I+4]*G+M[I+5]*Q,we=M[I+6]*X+M[I+7]*G+M[I+8]*Q,{nx:Ae,nz:Me,mask:ge}=z;for(let re=0;re<5;re++){let se=Math.floor((ce+F[re]-j)/20),oe=Math.floor((we+B[re]-ee)/20);if(se<0||oe<0||se>=Ae||oe>=Me||ge[se*Me+oe]!==1)return!1}return!0},V=NaN,me=NaN,be=NaN,ye=-1,ue=-1,Pe=(T,P,E,N)=>{let I=Math.round(P*2),z=Math.floor(T/40),j=Math.floor(E/40);if(!Fe(I,z,j))return Ue;let ee=Ue;if(!n&&ue>=0&&v[ue]===I&&(A[ue]!==N||b[ue]>=0)&&L(ue,T,P,E))return 0;if(I!==V||z!==me||j!==be)V=I,me=z,be=j,ye=S.get(I,z,j);for(let X=ye;X>=0;X=D[X]){let G=y[X],Q=A[G];if(Q===N&&(Q=b[G])<0)continue;if(!L(G,T,P,E))continue;if(!n)return ue=G,0;let ce=n[Q];if(ce<ee)ee=ce}return ee},xe=new Uint8Array(l),Ce=new Uint8Array(l),ke=0,he=n?new Ee(l,4):null,O=n?null:new Int32Array(l),k=n?null:new Int32Array(l),J=n?null:new Int32Array(l),_=0,W=n?new Int32Array(l).fill(Ue):void 0;for(let T=0,P=0;T<e.length;T++){let E=e[T],N=f[T];if(!N)continue;let I=E.m,z=N.studM,j=I[0],ee=I[1],X=I[2],G=I[3],Q=I[4],ce=I[5],we=I[6],Ae=I[7],Me=I[8],ge=I[9],re=I[10],se=I[11];for(let oe=0;oe<N.nStuds;oe++,P++){let Te=oe*12,fe=z[Te+4],ie=z[Te+7],pe=z[Te+10];if(!(Math.abs(we*fe+Ae*ie+Me*pe-1)<0.001&&Math.abs(G*fe+Q*ie+ce*pe)<0.001&&Math.abs(ge*fe+re*ie+se*pe)<0.001))continue;Ce[P]=1;let K=z[Te],ae=z[Te+1],te=z[Te+2],Le=j+G*K+Q*ae+ce*te,ve=ee+we*K+Ae*ae+Me*te,de=X+ge*K+re*ae+se*te,gt=Pe(Le,ve,de,T);if(gt!==Ue){if(xe[P]=1,ke++,W)W[P]=gt}let Ne=Math.round(Le),Oe=Math.round(ve),ze=Math.round(de);if(!Fe(Ne,Oe,ze))continue;if(!he){O[_]=Ne,k[_]=Oe,J[_++]=ze;continue}let dt=n[T],bt=he.get(Ne,Oe,ze);if(bt<0||dt<bt)he.put(Ne,Oe,ze,dt)}}let ne=he?null:new Yt(O,k,J,_),q=new Uint8Array(e.length),le=n?new Int32Array(e.length).fill(Ue):void 0;for(let T=0;T<e.length;T++){let P=e[T],E=t.parts[P.part];if(!E||!E.under||!Xt(P.m)||i(P.color))continue;let N=E.bbox,I=Math.round((N[3]-N[0])/20),z=Math.round((N[5]-N[2])/20);if(!I||!z||I*z>4096)continue;let j=P.m,ee=Math.round(j[1]+N[4]),X=!0,G=0;for(let Q=0;Q<I&&X;Q++)for(let ce=0;ce<z;ce++){let we=N[0]+10+20*Q,Ae=N[2]+10+20*ce,Me=j[0]+j[3]*we+j[5]*Ae,ge=j[2]+j[9]*we+j[11]*Ae,re=Math.round(Me),se=Math.round(ge),oe=!Fe(re,ee,se)?-1:he?he.get(re,ee,se):ne.has(re,ee,se)?1:-1;if(oe<0){X=!1;break}if(oe>G)G=oe}if(X){if(q[T]=1,le)le[T]=G}}return{nStuds:l,studHidden:xe,studUp:Ce,underHidden:q,studsHidden:ke,studHideStep:W,underHideStep:le}}function ht(e,t,n){let r=(l)=>l.colPart&&t.parts[l.colPart]?l.colPart:n&&l.texPart&&t.parts[l.texPart]?l.texPart:l.part,s=new Map,o=new Map,i=(l)=>{let f=l.colour;if(!f)return String(l.color);let h=o.get(f);if(h!==void 0)return h;let g=t.colorTable?.[l.color],p=g?.hex??t.colors?.[l.color],m=g?ct({alpha:g.alpha??255,luminance:g.luminance??0,finish:g.finish??{type:"default"}}):"default:op",A=ct(f);if(h=p&&p.toUpperCase()===f.hex.toUpperCase()&&m===A?String(l.color):f.hex.toUpperCase()+"/"+A,h!==String(l.color))s.set(h,f);return o.set(f,h),h},c=e.map((l)=>({part:r(l),color:i(l),m:l.m,steps:l.steps})),{stepOf:a,nSteps:u}=Kn(c);return{all:c,stepOf:a,nSteps:u,localColours:s}}function Kn(e){let t=!0;for(let o=0;o<e.length;o++){let i=e[o].steps;if(i.length!==1){t=!1;break}let c=i[0];if(!(Number.isInteger(c)&&c>=0&&c<1e6)){t=!1;break}}if(t){let o=new Set;for(let a=0;a<e.length;a++)o.add(e[a].steps[0]);let i=[...o].sort((a,u)=>a-u),c=new Map(i.map((a,u)=>[a,u]));return{stepOf:e.map((a)=>c.get(a.steps[0])),nSteps:i.length}}let n=e.map((o)=>_t(o.steps)),r=[...new Set(n)].sort(),s=new Map(r.map((o,i)=>[o,i]));return{stepOf:n.map((o)=>s.get(o)),nSteps:r.length}}function Qt(e,t,n=!0){let r=ht(e,t,n);return mt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ke="https://ldr-parts-cdn.baconbrix.workers.dev/v1/",He=new Map,Ge=new Map;function We(e=Ke,t=fetch){let n=He.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(()=>He.delete(e)),He.set(e,n);return n}var Zn=(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"),Xe=(e,t)=>Zn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Xe(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Xe(r,t)])):e;function Yn(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let g=h.buffer;if(!g)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let p=new DataView(g).getUint32(0,!0),m=new Uint8Array(g,4+p),A=r;n.push(m),r+=m.byteLength;let b=(4-r%4)%4;if(b)n.push(new Uint8Array(b)),r+=b;for(let[d,x]of Object.entries(h.header.parts??{}))if(!(d in s))s[d]=Xe(x,A);for(let[d,x]of Object.entries(h.header.studKinds??{}))if(!(d in o))o[d]=Xe(x,A)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+c.length)%4)%4,u=4+c.length+a,l=new Uint8Array(u+r);new DataView(l.buffer).setUint32(0,c.length+a,!0),l.set(c,4),l.fill(32,4+c.length,u);let f=u;for(let h of n)l.set(h,f),f+=h.byteLength;return _e(l.buffer)}async function Jn(e,t={}){e=[...e];try{return await qt(e,t)}catch(n){let r=t.cdn??Ke,s=t.fetch??fetch;He.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await qt(e,{...t,fetch:o})}catch{throw n}}}async function qt(e,t){let n=t.cdn??Ke,r=t.fetch??fetch,s=t.gap??16384,o=await We(n,r),i=[...new Set([...new Set(e)].map(Y))],c=[],a=[];for(let d of i){if(Ge.has(n+d))continue;let x=o.parts[d];if(x)a.push({name:d,off:x[0],len:x[1],file:x[2]??0});else c.push(d)}a.sort((d,x)=>d.file-x.file||d.off-x.off);let u=[];for(let d of a){let x=u[u.length-1];if(x&&x.file===d.file&&d.off-x.end<=s)x.end=Math.max(x.end,d.off+d.len),x.items.push(d);else u.push({file:d.file,start:d.off,end:d.off+d.len,items:[d]})}let l=0,f=0,h=0,g=new Map,p=async()=>{while(h<u.length){let d=u[h++],x=g.get(d.file);if(x)x=x.subarray(d.start,d.end);else{let w=await r(new URL(o.archives[d.file],n).href,{headers:{Range:`bytes=${d.start}-${d.end-1}`,"Accept-Encoding":"identity"}});if(!w.ok)throw Error(`ldr: parts CDN ${w.status}`);if(f++,x=new Uint8Array(await w.arrayBuffer()),l+=x.byteLength,w.status===200)g.set(d.file,x),x=x.subarray(d.start,d.end)}for(let w of d.items){let v=Ve(x.subarray(w.off-d.start,w.off-d.start+w.len)),M=v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength);Ge.set(n+w.name,_e(M))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,u.length)},p));let m=i.filter((d)=>Ge.has(n+d)).map((d)=>Ge.get(n+d)),A={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:m.length?Yn(m,A):_e(Qn(A)),missing:c,requests:f,bytes:l}}function Qn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...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 qn(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 en(e,t,n){let r=0,s=0,o=!1,i=new Set,c=new Map;for(let a of e){let u;if(a.embedded)u=t.get(a.part);else if(u=c.get(a.part),u===void 0)c.set(a.part,u=Y(a.part));let l=u?n.parts[u]:void 0;if(!l)continue;if(l[3]!=null)o=!0,r+=l[3];if(!i.has(u))i.add(u),s+=l[1]}return{bodyTris:r,packBytes:s,known:o}}class Ze 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 tn(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=We(t.cdn??Ke,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(y)=>{if(!y.ok)throw Error(`ldr: ${y.status} fetching ${e}`);return wt(await y.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":At(e)),a=Ht(o,c,{looseGeometry:!1,callouts:t.callouts}),u=performance.now();t.onParsed?.(a),await s;let l=Wt(o,new Set(a.filter((y)=>y.embedded).map((y)=>y.part)),c),f=(y,R)=>t.maxBodyTris!=null&&y>t.maxBodyTris||t.maxPackBytes!=null&&R>t.maxPackBytes,h=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(y)=>new Ze({...y,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),p="full";if(h){let y=en(a,l,await s);if(f(y.known?y.bodyTris:0,y.packBytes)){if(!t.lowCdn)throw g(y);let R=await We(t.lowCdn,r).catch(()=>null);if(!R)throw g(y);let C=en(a,l,R);if(f(C.known?C.bodyTris:0,C.packBytes))throw g(C);p="low"}}let m=[...a.filter((y)=>!y.embedded).map((y)=>y.part),...l.values()],A=async()=>{let y=await Jn(m,p==="low"?{...t,cdn:t.lowCdn}:t);for(let[R,C]of l){let F=y.pack.header.parts[C];if(F)y.pack.header.parts[R]=F}return{...y,packBytes:y.pack.buffer?.byteLength??y.pack.bytes??0,bodyTris:qn(a,y.pack)}},b=await A();if(h&&f(b.bodyTris,b.packBytes)&&p==="full"&&t.lowCdn&&await We(t.lowCdn,r).then(()=>!0,()=>!1)){p="low";let y=b;b=await A(),b.requests+=y.requests,b.bytes+=y.bytes}if(h&&f(b.bodyTris,b.packBytes))throw g(b);let{pack:d,missing:x,requests:w,bytes:v}=b,M=new Map([...l].map(([y,R])=>[R,y])),U=x.map((y)=>M.get(y)??y),S=performance.now(),D=t.cull?Qt(a,d.header,t.textures!==!1):void 0;return{insts:a,pack:d,tier:p,missing:U,requests:w,bytes:v,cull:D,timings:{fetchModel:i-n,parse:u-i,parts:S-u,...D?{cull:performance.now()-S}:{}}}}var er=new Set(["part","color","m","step","steps","localStep","path"]);function nn(e){let t=e.length,n=0;for(let p of e){if(typeof p.part!=="string"||typeof p.path!=="string"||typeof p.color!=="number"||typeof p.step!=="number"||typeof p.localStep!=="number"||!Array.isArray(p.m)||p.m.length!==12||!Array.isArray(p.steps))return null;n+=p.steps.length}let r=[],s=new Map,o=(p)=>{let m=s.get(p);if(m===void 0)s.set(p,m=r.length),r.push(p);return m},i=new Uint32Array(t),c=new Uint32Array(t),a=new Float64Array(t*3),u=new Float64Array(t*12),l=new Uint32Array(t+1),f=new Float64Array(n),h=[],g=0;for(let p=0;p<t;p++){let m=e[p];i[p]=o(m.part),c[p]=o(m.path),a[p*3]=m.color,a[p*3+1]=m.step,a[p*3+2]=m.localStep;let A=m.m,b=p*12;for(let w=0;w<12;w++)u[b+w]=A[w];let d=m.steps;for(let w=0;w<d.length;w++)f[g++]=d[w];l[p+1]=g;let x=null;for(let w in m)if(!er.has(w))(x??={})[w]=m[w];if(x)h.push([p,x])}return{n:t,strs:r,part:i,path:c,num:a,m:u,so:l,steps:f,extra:h}}var rn=(e)=>[e.part.buffer,e.path.buffer,e.num.buffer,e.m.buffer,e.so.buffer,e.steps.buffer];self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await tn(n,{...r,cull:!1,onParsed:(f)=>{let h=nn(f);if(h)self.postMessage({id:t,packed:h},rn(h));else 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(),c=ht(s.insts,s.pack.header,r.textures!==!1),a=mt(c.all,s.pack.header,r.stepCull&&c.nSteps>1?c.stepOf:void 0),u=performance.now()-i,l=[];for(let f of[a.studHidden,a.studUp,a.underHidden,a.studHideStep,a.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:a,ms:u},l)}catch(s){if(s instanceof Ze||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';
5621
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/load-worker.gen.ts
5622
+ var load_worker_gen_default = 'var sn=ArrayBuffer,G=Uint8Array,$e=Uint16Array,on=Int16Array;var je=Int32Array,Je=function(e,t,n){if(G.prototype.slice)return G.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 G(n-t);return r.set(e.subarray(t,n)),r},Be=function(e,t,n,r){if(G.prototype.fill)return G.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},an=function(e,t,n,r){if(G.prototype.copyWithin)return G.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 ln=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],K=function(e,t,n){var r=Error(t||ln[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},yt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},cn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},un=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,c=r>>6;if(r&8)K(0);var a=6-s,u=i==3?4:i,l=yt(e,a,u);a+=u;var f=c?1<<c:s,p=yt(e,a,f)+(c==1&&256),d=p;if(!s){var h=1<<10+(e[5]>>3);d=h+(h>>3)*(e[5]&7)}if(d>2145386496)K(1);var m=new G((t==1?p||d:t?0:d)+12);return m[0]=1,m[4]=4,m[8]=8,{b:a+f,y:0,l:0,d:l,w:t&&t!=1?t:m.subarray(12),e:d,o:new je(m.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return cn(e,4)+8;K(0)},Ee=function(e){var t=0;for(;1<<t<=e;++t);return t-1},De=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,c=-1,a=-1,u=-1,l=o,f=new sn(512+(o<<2)),p=new on(f,0,256),d=new $e(f,0,256),h=new $e(f,512,o),m=512+(o<<1),w=new G(f,m,o),b=new G(f,m+o);while(c<255&&i>0){var g=Ee(i+1),y=r>>3,A=(1<<g+1)-1,v=(e[y]|e[y+1]<<8|e[y+2]<<16)>>(r&7)&A,M=(1<<g)-1,z=A-i-1,E=v&M;if(E<z)r+=g,v=E;else if(r+=g+1,v>M)v-=z;if(p[++c]=--v,v==-1)i+=v,w[--l]=c;else i-=v;if(!v)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)K(0);var x=0,U=(o>>1)+(o>>3)+3,k=o-1;for(var I=0;I<=c;++I){var F=p[I];if(F<1){d[I]=-F;continue}for(u=0;u<F;++u){w[x]=I;do x=x+U&k;while(x>=l)}}if(x)K(0);for(u=0;u<o;++u){var C=d[w[u]]++,j=b[u]=s-Ee(C);h[u]=(C<<j)-o}return[r+7>>3,{b:s,s:w,n:b,t:h}]},fn=function(e,t){var n=0,r=-1,s=new G(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),a=new $e(s.buffer,268);if(o<128){var u=De(e,t+1,6),l=u[0],f=u[1];t+=o;var p=l<<3,d=e[t];if(!d)K(0);var h=0,m=0,w=f.b,b=w,g=(++t<<3)-8+Ee(d);for(;;){if(g-=w,g<p)break;var y=g>>3;if(h+=(e[y]|e[y+1]<<8)>>(g&7)&(1<<w)-1,i[++r]=f.s[h],g-=b,g<p)break;y=g>>3,m+=(e[y]|e[y+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=f.s[m],w=f.n[h],h=f.t[h],b=f.n[m],m=f.t[m]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var A=e[++t];i[n]=A>>4,i[n+1]=A&15}++t}var v=0;for(n=0;n<r;++n){var M=i[n];if(M>11)K(0);v+=M&&1<<M-1}var z=Ee(v)+1,E=1<<z,D=E-v;if(D&D-1)K(0);i[r++]=Ee(D)+1;for(n=0;n<r;++n){var M=i[n];++c[i[n]=M&&z+1-M]}var x=new G(E<<1),U=x.subarray(0,E),k=x.subarray(E);a[z]=0;for(n=z;n>0;--n){var I=a[n];Be(k,n,I,a[n-1]=I+c[n]*(1<<z-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var F=i[n];if(F){var C=a[F];Be(U,n,C,a[F]=C+(1<<z-F))}}return[t,{n:k,b:z,s:U}]},pn=De(new G([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],mn=De(new G([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],hn=De(new G([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],xt=function(e,t){var n=e.length,r=new je(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Qe=new G(new je([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),gn=xt(Qe,0),qe=new G(new je([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),dn=xt(qe,3),Re=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)K(0);var a=0,u=n.b,l=(r<<3)-8+Ee(o)-u,f=-1;for(;l>c&&f<s;){var p=l>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(l&7);a=(a<<u|d)&i,t[++f]=n.s[a],l-=u=n.n[a]}if(l!=c||f+1!=s)K(0)},bn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;Re(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Re(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Re(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),Re(e.subarray(r),t.subarray(c),n)},yn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Be(n,e[s],t.y,t.y+=c),n;return Be(new G(c),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=c,n;return Je(e,s,a)}if(i==2){var u=e[s],l=u&3,f=u>>2&3,p=u>>4,d=0,h=0;if(l<2)if(f&1)p|=e[++s]<<4|(f&2&&e[++s]<<12);else p=u>>3;else if(h=f,f<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(f==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 m=n?n.subarray(t.y,t.y+t.m):new G(t.m),w=m.length-p;if(l==0)m.set(e.subarray(s,s+=p),w);else if(l==1)Be(m,e[s++],w);else{var b=t.h;if(l==2){var g=fn(e,s);d+=s-(s=g[0]),t.h=b=g[1]}else if(!b)K(0);(h?bn:Re)(e.subarray(s,s+=d),m.subarray(w),b)}var y=e[s++];if(y){if(y==255)y=(e[s++]|e[s++]<<8)+32512;else if(y>127)y=y-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var v=[mn,hn,pn];for(var M=2;M>-1;--M){var z=A>>(M<<1)+2&3;if(z==1){var E=new G([0,0,e[s++]]);v[M]={s:E.subarray(2,3),n:E.subarray(0,1),t:new $e(E.buffer,0,1),b:0}}else if(z==2)r=De(e,s,9-(M&1)),s=r[0],v[M]=r[1];else if(z==3){if(!t.t)K(0);v[M]=t.t[M]}}var D=t.t=v,x=D[0],U=D[1],k=D[2],I=e[a-1];if(!I)K(0);var F=(a<<3)-8+Ee(I)-k.b,C=F>>3,j=0,de=(e[C]|e[C+1]<<8)>>(F&7)&(1<<k.b)-1;C=(F-=U.b)>>3;var be=(e[C]|e[C+1]<<8)>>(F&7)&(1<<U.b)-1;C=(F-=x.b)>>3;var me=(e[C]|e[C+1]<<8)>>(F&7)&(1<<x.b)-1;for(++y;--y;){var le=k.s[de],Te=k.n[de],Me=x.s[me],Le=x.n[me],ve=U.s[be],ce=U.n[be];C=(F-=ve)>>3;var Ce=1<<ve,ue=Ce+((e[C]|e[C+1]<<8|e[C+2]<<16|e[C+3]<<24)>>>(F&7)&Ce-1);C=(F-=qe[Me])>>3;var O=dn[Me]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<qe[Me])-1);C=(F-=Qe[le])>>3;var T=gn[le]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<Qe[le])-1);if(C=(F-=Te)>>3,de=k.t[de]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Te)-1),C=(F-=Le)>>3,me=x.t[me]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Le)-1),C=(F-=ce)>>3,be=U.t[be]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<ce)-1),ue>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=ue-=3;else{var Y=ue-(T!=0);if(Y){if(ue=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=ue}else ue=t.o[0]}for(var M=0;M<T;++M)m[j+M]=m[w+M];j+=T,w+=T;var J=j-ue;if(J<0){var H=-J,oe=t.e+J;if(H>O)H=O;for(var M=0;M<H;++M)m[j+M]=t.w[oe+M];j+=H,O-=H,J=0}for(var M=0;M<O;++M)m[j+M]=m[J+M];j+=O}if(j!=w)while(w<m.length)m[j++]=m[w++];else j=m.length;if(n)t.y+=j;else m=Je(m,0,j)}else if(n){if(t.y+=p,w)for(var M=0;M<p;++M)m[M]=m[w+M]}else if(w)m=Je(m,w);return t.b=a,m}K(2)},xn=function(e,t){if(e.length==1)return e[0];var n=new G(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 Ve(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=un(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 c=yn(e,i,t);if(!c)K(5);if(t)i.e=i.y;else n.push(c),o+=c.length,an(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return xn(n,o)}async function wn(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(Ve(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 wt(e){return new TextDecoder().decode(await wn(e))}var At=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function _e(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 Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),tt=/^[A-Za-z][A-Za-z0-9_]*$/,et=new Map;function nt(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(!et.has(r))et.set(r,t);return r}function rt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&tt.test(e))return nt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,An=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Mn=new Set(["FILE","NOFILE","!DATA"]),Pt=1000000000000000,It=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),vn=new Set(["model","submodel","configuration"]),Cn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function vt(e){let t=Cn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return It.has(n)||vn.has(n)?n:void 0}function kn(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 Tn(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((f)=>Number.isFinite(f)&&Math.abs(f)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let f=0;f<s;f++)c=c.replace(/^\\S+\\s*/,"");let a=kn(c);if(!a.length)return null;let u={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)u.a=i[9];if(s===11)u.b=i[10];let l=a.findIndex((f,p)=>p>0&&f.toUpperCase()==="GLOSSMAP");if(l>0&&a[l+1])u.glossmap=a[l+1];if(t)u.next=!0;return u}var Ln=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let 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 Sn(e,t){let n=e.length,r=1,s=(h)=>h===32||h===9,o=()=>{while(r<n&&s(e.charCodeAt(r)))r++;let h=r,m=e.charCodeAt(r),w=m===45;if(w)m=e.charCodeAt(++r);let b=0,g=0;while(m>=48&&m<=57)b=b*10+(m-48),g++,m=e.charCodeAt(++r);if(g>0&&g<=15&&(r>=n||s(m)))return w?-b:b;while(r<n&&!s(e.charCodeAt(r)))r++;return h<r?+e.slice(h,r):NaN};while(r<n&&s(e.charCodeAt(r)))r++;let i=r;if(r>=n)return null;let c=e.charCodeAt(r),a=c===45,u=0,l=0;if(a)c=e.charCodeAt(++r);while(c>=48&&c<=57)u=u*10+(c-48),l++,c=e.charCodeAt(++r);if(l>0&&l<=15&&(r>=n||s(c))){if(a)u=-u}else{while(r<n&&!s(e.charCodeAt(r)))r++;u=rt(e.slice(i,r))}let f=Array(12);for(let h=0;h<12;h++){let m=o();if(!Number.isFinite(m))return null;f[h]=m}while(r<n&&s(e.charCodeAt(r)))r++;if(r>=n)return null;let p=e.slice(r),d=t.get(p);if(d===void 0)d=Z(/[ \\t]{2,}|\\t/.test(p)?p.split(/\\s+/).join(" "):p),t.set(p,d);if(!Number.isFinite(u))return null;return{t:1,color:u,m:f,file:d}}var En=[0,12,6,9,12,12];function Ct(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=rt(e[1]),r=En[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Z(e.slice(14).join(" "));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Ft(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,a=null,u=[],l=null,f=()=>{if(!a)return;let y=Ln(a.chunks.join("")),A=y[0]===137&&y[1]===80&&y[2]===78&&y[3]===71;(c??=new Map).set(Z(a.name),{name:a.name,bytes:y,...A?{mime:"image/png"}:{}}),a=null},p=new Map,d=!0,h=(y)=>{if(f(),o={name:Z(y),cmds:[]},s.set(o.name,o),!i)i=o.name;u=[],l=null,d=!0},m=!1,w=!1,b=()=>{if(w)return;w=!0,s.clear(),o=null,i=""},g=(y,A)=>{if(l){y.tex=l,l=null;return}let v=u[u.length-1];if(!v)return;if(v.fallback){if(!A)y.fallback=!0}else y.tex=v.map};for(let y of e.split(`\n`)){let A=y.trim();if(!A)continue;if(r&&A.charCodeAt(0)>=50&&A.charCodeAt(0)<=53&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)){if(a||m)continue;if(!o)h(t);let E=A.slice(2).trimStart(),D=E.search(/\\s/),x={t:A.charCodeAt(0)-48,color:rt(D<0?E:E.slice(0,D)),p:[],src:A};g(x,!1),o.cmds.push(x),d=!1;continue}if(A.charCodeAt(0)===48&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)){let E=2;while(A.charCodeAt(E)===32||A.charCodeAt(E)===9)E++;let D=E;while(D<A.length&&A.charCodeAt(D)!==32&&A.charCodeAt(D)!==9)D++;let x=A.slice(E,D),U=/[^\\x21-\\x7e]/.test(x)?A.slice(E).trim().split(/\\s+/)[0]:x;if(!An.has(U)&&!(U.length>=4&&U.length<=6&&Mn.has(U.toUpperCase()))){if(m||a)continue;if(!o)h(t);let k=A.slice(E),I={t:0,text:k};if(x.charCodeAt(0)===33)I.meta=x;if(l=null,d&&!o.org){let C=vt(k);if(C)o.org=C}let F=k.match(Mt);if(F&&!o.movedTo){let C=F[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Z(C)}o.cmds.push(I);continue}}if(A.charCodeAt(0)===49&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)&&!a&&!m){let E=Sn(A,p);if(E){if(!o)h(t);g(E,!1),o.cmds.push(E),d=!1;continue}}let v=A.split(/\\s+/);if(+v[0]===0){let E=A.slice(1).trim(),D=v.length>1&&v[1].length>=4&&v[1].length<=6?v[1].toUpperCase():v[1];if(D==="FILE"){let k=E.slice(5).trimStart().split("\\r")[0].trim();if(k){b(),m=!1,h(k);continue}}if(D==="NOFILE"){f(),o=null,m=!0;continue}if(D==="!DATA"){b(),f(),o=null,m=!1,a={name:E.slice(5).trim(),chunks:[]};continue}if(m)continue;if(a){if(v[1]==="!:")a.chunks.push(v.slice(2).join(""));continue}if(!o)h(t);let x={t:0,text:E};if(v[1]==="STEP")x.step=!0,u=[],l=null;else if(v[1]==="BFC")x.bfc=v.slice(2).join(" ");else if(v[1]==="ROTSTEP")if(x.meta="ROTSTEP",x.step=!0,u=[],l=null,(v[2]??"").toUpperCase()==="END")x.rotstep={x:0,y:0,z:0,mode:"END"};else{let k=(v[5]??"REL").toUpperCase(),I=(F)=>{let C=Number(F);return Number.isFinite(C)?C:0};x.rotstep={x:I(v[2]),y:I(v[3]),z:I(v[4]),mode:["REL","ABS","ADD"].includes(k)?k:"REL"}}else if(v[1]==="BUFEXCHG"){x.meta="BUFEXCHG";let k=(v[2]??"").toUpperCase();x.bufexchg={op:k==="RETRIEVE"?"RETRIEVE":"STORE",buf:v[3]??"A"}}else if(v[1]?.startsWith("!"))x.meta=v[1];if(d&&!o.org){let k=vt(E);if(k)o.org=k}if(v[1]==="!TEXMAP"){let k=(v[2]??"").toUpperCase();if(l=null,k==="START"||k==="NEXT"){let I=Tn(E.replace(/^!TEXMAP\\s+\\S+/i,""),k==="NEXT");if(x.texmap={op:k,...I?{map:I}:{}},I)if((o.texmaps??=[]).push(I),k==="START")u.push({map:I,fallback:!1});else l=I}else if(k==="FALLBACK"){x.texmap={op:k};let I=u[u.length-1];if(I)I.fallback=!0}else if(k==="END")x.texmap={op:k},u.pop()}else if(v[1]==="!:"){l=null;let k=Ct(v.slice(2));if(k)g(k,!0),x.geom=k}else l=null;let U=E.match(Mt);if(U&&!o.movedTo){let k=U[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(k))k+=".dat";o.movedTo=Z(k)}o.cmds.push(x);continue}if(a||m)continue;if(!o)h(t);let z=Ct(v);if(!z){if(/^[2-5][ \\t]/.test(A))d=!1;continue}g(z,!1),o.cmds.push(z),d=!1}return f(),c?{main:i,files:s,data:c}:{main:i,files:s}}var sr=Math.PI/180;function Rt(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 Bt(e,t){let[n,r,s,o,i,c,a,u,l,f,p,d]=e,[h,m,w,b,g,y,A,v,M,z,E,D]=t;return[o*h+i*m+c*w+n,a*h+u*m+l*w+r,f*h+p*m+d*w+s,o*b+i*A+c*z,o*g+i*v+c*E,o*y+i*M+c*D,a*b+u*A+l*z,a*g+u*v+l*E,a*y+u*M+l*D,f*b+p*A+d*z,f*g+p*v+d*E,f*y+p*M+d*D]}var Ge=[0,0,0,1,0,0,0,1,0,0,0,1];var kt=new WeakMap,Pn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Z(t));if(!n)return"part";let r=kt.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&&Pn.test(s.file))?"part":"model";return kt.set(n,r),r}var Tt=new WeakMap;function Dt(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 Lt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?et.get(e)??String(e):String(e),In=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Lt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Lt(e.color)} ${e.p.join(" ")}`,ot=(e,t)=>`${Z(e)}#${t}`;function Fn(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:ot(e.name,t),cmds:n}}function Ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Fn(e,t).cmds.map(In)].join(`\n`)+`\n`}function it(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 Nt(e){let[t,n,r,s,o,i,c,a,u,l,f,p]=e,d=a*p-u*f,h=-(c*p-u*l),m=c*f-a*l,w=s*d+o*h+i*m;if(!Number.isFinite(w)||Math.abs(w)<0.000000000001)return null;let b=1/w,g=[d*b,-(o*p-i*f)*b,(o*u-i*a)*b,h*b,(s*p-i*l)*b,-(s*u-i*c)*b,m*b,-(s*f-o*l)*b,(s*a-o*c)*b];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 Rn=(e)=>String(+e.toFixed(6)||0),St=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Ot(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Rn).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 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${it(r)}`,source:r}}var Bn=(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 Dn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),u=Math.cos(n*r);return[c*u,-c*a,i,o*a+s*i*u,o*u-s*i*a,-s*c,s*a-o*i*u,s*u+o*i*a,o*c]}var Et=new WeakMap;function zt(e){let t=Et.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=Dn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Bn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Et.set(e,n),n}class at extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var Un=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=Pt))return!1;return!0},$t=999999,_t=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Gt=new WeakMap,jt=new WeakMap;function Nn(e,t){let n=jt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Gt.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},jt.set(t,n);let r=n.parts.get(e);if(!r){let s=Z(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-${it(o)}`,source:o},n.parts.set(e,r)}return r}function On(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,a=0,u=[],l=(w,b)=>{if(w.length)return[...w,b];let g=u[b];if(!g)u[b]=g=[b];return g},f=new Set,p=t.maxInstances??2000000,d=0,h=(w,b)=>{let g=w.name+"#"+b,y=c.get(g);if(!y){let A;y=Object.assign(()=>A??=Ut(w,b),{file:w,step:b}),c.set(g,y)}return y},m=(w,b,g,y,A,v,M,z,E=null,D=[],x=[],U=void 0,k=null)=>{let I=w.files.get(b);if(!I||M>r||f.has(I))return;if(++d>p)throw new at("model",p);f.add(I);let F=k,C=0,j=M>0?++a:0,de=i&&j?[...D,j]:D,be=i&&j?[...x,g]:x,me=i&&!E?new Map:null,le=-1,Te=0,Me=(O,T,Y,J,H,oe,L)=>{if(le!==C)le=C,Te=0;let B=me?.get(C+"|"+T);if(B)return B.n++,m(O,O===w?T:O.main,Y,J,A+"/"+T,[...H,$t],M+1,oe,[...H,$t],de,be,L,F);let P=[...H,Te++],R=n.length;m(O,O===w?T:O.main,Y,J,A+"/"+T,P,M+1,oe,E,de,be,L,F),me?.set(C+"|"+T,{n:1,from:R,to:n.length})},Le=zt(I),ve=s?Dt(I):[],ce=0,Ce=(O,T,Y,J,H,oe,L,B,P)=>{if(E)J=E;if(++d>p)throw new at("model",p);let R={part:O,color:T,m:Y,step:J[0],steps:J,localStep:H,path:A};if(B)R.colour=B;if(j){if(R.sub=j,i)R.subPath=de,R.subMats=be}if(oe)R.embedded=!0;if(L){let N=Ot(O,L);R.texPart=N.name,R.texSource=N.source}else if(P){let N=Nn(O,P);R.colPart=N.name,R.colSource=N.source}let S=Le[H];if(S)R.view=S;return n.push(R),R},ue=(O)=>{while(ce<ve.length&&ve[ce]<=O){let T=ve[ce++];Ce(ot(I.name,T),y,g,l(v,T),T,!1,null,U,k).source=h(I,T)}};for(let O of I.cmds){if(O.t===0&&O.step){C++;continue}let T=O;if(T.t>=2||T.t===0&&T.geom&&T.geom.t>=2){ue(C);continue}if(T.t===0){if(T.meta==="!COLOUR"){let S=$n(T.text);if(S&&S.code!==16&&S.code!==24)Gt.set(S,T.text),(F=new Map(F??[])).set(S.code,S);continue}if(o&&T.geom?.t===1)T=T.geom;else continue}if(T.t!==1)continue;if(o&&T.fallback)continue;let Y=g===Ge?T.m:Bt(g,T.m);if(!Un(Y))continue;let J=T.color===16?y:T.color,H=T.color===16?U:F?.get(T.color),oe=l(v,C),L=o?T.tex??z:null,B=L?Nt(T.m):null,P=L&&B?Rt(L,B):null;if(w.files.has(T.file)){if(st(w,T.file)==="model"){Me(w,T.file,Y,J,oe,P,H);continue}Ce(T.file,J,Y,oe,C,!0,P,H,F);continue}let R=t.resolveModel?.(T.file);if(R){Me(R,T.file,Y,J,oe,P,H);continue}Ce(T.file,J,Y,oe,C,!1,P,H,F)}if(ue(1/0),f.delete(I),me){for(let O of me.values())if(O.n>1)for(let T=O.from;T<O.to;T++)n[T].mult??=O.n}};if(st(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Ge],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return m(e,e.main,Ge,16,e.main,[],0,null),n}function Ht(e,t="main.ldr",n){return On(Ft(e,t,{geometryText:!0}),n)}var zn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function lt(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 Vt(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=lt(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 $n(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",c=255,a=0,u={type:"default"},l=1;while(l<n.length){let f=n[l].toUpperCase(),p=n[l+1];if(f==="CODE")s=p!==void 0&&tt.test(p)?nt(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,l+=2;else if(f==="VALUE"){let d=lt(p);if(d)o=d;l+=2}else if(f==="EDGE")i=lt(p)??p,l+=2;else if(f==="ALPHA")c=+p,l+=2;else if(f==="LUMINANCE")a=+p,l+=2;else if(f==="CHROME")u={type:"chrome"},l+=1;else if(f==="PEARLESCENT")u={type:"pearlescent"},l+=1;else if(f==="RUBBER")u={type:"rubber"},l+=1;else if(f==="MATTE_METALLIC")u={type:"matte_metallic"},l+=1;else if(f==="METAL")u={type:"metal"},l+=1;else if(f==="MATERIAL"){let d=(n[l+1]||"").toUpperCase();if(d==="GLITTER"){let{grain:h,next:m}=Vt(n,l+2);u={type:"glitter",material:h},l=m}else if(d==="SPECKLE"){let{grain:h,next:m}=Vt(n,l+2);u={type:"speckle",material:h},l=m}else if(d==="FABRIC"){let h=(n[l+2]||"").toUpperCase(),m=["VELVET","CANVAS","STRING","FUR"].includes(h)?h.toLowerCase():void 0;u={type:"fabric",kind:m},l+=m?3:2}else l=n.length}else if(zn.has(f))l+=1;else l+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(a)?a:0,finish:u}}function jn(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,c=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:c,finish:"glitter"}}case"speckle":{let i=e.finish.material,c=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:c,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 ct(e){let t=jn(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 Vn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Z(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Z(t),r)}let a=i.trim().replace(/\\s+/g," ");if(a)r.push(a)}return n}var _n=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Z(t.slice(14).join(" ")):null};function Gn(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 Wt(e,t,n="main.ldr"){let r=[...t],s=new Map;if(!r.length)return s;let o=Vn(e,n);for(let i of r){let c=Z(i);if(!o.has(c)||s.has(c))continue;let a=new Set([c]),u=[c];while(u.length)for(let f of o.get(u.pop())){let p=_n(f);if(p&&o.has(p)&&!a.has(p))a.add(p),u.push(p)}let l=[c,...[...a].filter((f)=>f!==c).sort()].map((f)=>"0 FILE "+(f===c?"":f)+`\n`+o.get(f).join(`\n`)).join(`\n`);s.set(c,`emb/${Gn(l)}.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,Kt=new WeakMap,ut=null,ft="",pt=null;function Hn(e,t){if(e===ut&&t===ft)return pt;let n=Kt.get(e);if(!n)Kt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return ut=e,ft=t,pt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],a=[];s.studs.forEach((d,h)=>{c.push(d[0]),a.push(d[1]);for(let m=0;m<12;m++)i[h*12+m]=d[2+m]});let u=null,l=0,f=0;if(s.mask){l=s.mask[0],f=s.mask[1];let d=s.mask[2];u=new Uint8Array(d.length);for(let h=0;h<d.length;h++)u[h]=d.charCodeAt(h)===49?1:0}let p=!!u;if(u){for(let d=0;d<u.length;d++)if(u[d]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:a,mask:u,nx:l,nz:f,full:p}),ut=e,ft=t,pt=r,r}var Ie=1073741824;class Pe{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=Pe.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let a=s[c];if(a===0)return-1;if(a===r){let u=c<<2;if(o[u]===e&&o[u+1]===t&&o[u+2]===n)return o[u+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=Pe.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,a=this.slot(e,t,n);for(;;){let u=o[a],l=a<<2;if(u===0)return o[a]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(u===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let f=i[l+3];return i[l+3]=r,f}a=a+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Yt{grp=new Pe(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],a=[];for(let f=0;f<r;f++){let p=e[f],d=t[f],h=n[f],m=(p%20+20)%20,w=(h%20+20)%20,b=this.group(d,m,w);if(b<0)b=s.length,this.grp.put(d,m,w,b),this.lg=b,s.push(0),o.push(p),i.push(p),c.push(h),a.push(h);if(s[b]++,p<o[b])o[b]=p;else if(p>i[b])i[b]=p;if(h<c[b])c[b]=h;else if(h>a[b])a[b]=h}let u=0,l=0;for(let f=0;f<s.length;f++){let p=(i[f]-o[f])/20+1,d=(a[f]-c[f])/20+1,h=p*d;if(this.gX0.push(o[f]),this.gZ0.push(c[f]),this.gNx.push(p),this.gNz.push(d),h<=64*s[f]+1024&&u+h<2147483648)this.gBits.push(u),u+=h;else this.gBits.push(-1),l+=s[f]}this.bits=new Uint8Array(Math.ceil(u/8)),this.rest=new Pe(l);for(let f=0;f<r;f++){let p=e[f],d=t[f],h=n[f],m=this.group(d,(p%20+20)%20,(h%20+20)%20),w=this.gBits[m];if(w<0){this.rest.put(p,d,h,1);continue}let b=w+(p-this.gX0[m])/20*this.gNz[m]+(h-this.gZ0[m])/20;this.bits[b>>>3]|=1<<(b&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Wn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Fe=(e,t,n)=>e>-Ie&&e<Ie&&t>-Ie&&t<Ie&&n>-Ie&&n<Ie,Ue=2147483647;function Xn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function mt(e,t,n){return Zt(e,t,n,-1)??Zt(e,t,n,Jt)}var Jt=0;function Zt(e,t,n,r){let o=new Map,i=(L)=>{let B=o.get(L);if(B===void 0)o.set(L,B=Xn(t,L));return B},c=e.length,a=0,u=0,l=0,f=Array(c);for(let L=0;L<c;L++){let B=f[L]=Hn(t,e[L].part);if(B){if(l+=B.nStuds,B.mask)a++}}let p=new Float64Array(a),d=new Float64Array(a),h=new Float64Array(a),m=new Float64Array(a),w=new Int32Array(a),b=new Int32Array(a),g=new Float64Array(a),y=new Float64Array(a),A=[],v=new Int32Array(a),M=new Float64Array(a*9),z=new Uint8Array(a);if(r<0)r=a*4+64;let E=new Pe(e.length*2),D=new Int32Array(r),x=new Int32Array(r),U=0,k=0;for(let L=0;L<e.length;L++){let B=e[L],P=B.m,R=t.parts[B.part];if(!R||!R.mask||!Xt(P)||i(B.color))continue;let S=R.bbox,N=1/0,V=-1/0,q=1/0,W=-1/0;for(let X=0;X<2;X++)for(let ie=0;ie<2;ie++){let ee=X?S[3]:S[0],Se=ie?S[5]:S[2],Ae=P[0]+P[3]*ee+P[5]*Se,ge=P[2]+P[9]*ee+P[11]*Se;if(Ae<N)N=Ae;if(Ae>V)V=Ae;if(ge<q)q=ge;if(ge>W)W=ge}let _=Math.round((P[1]+S[4])*2),Q=f[L],ae=Math.floor(N/40),ye=Math.floor(V/40),xe=Math.floor(q/40),we=Math.floor(W/40);if(!((ye-ae+1)*(we-xe+1)<=65536)||!Fe(_,ae,xe)||!Fe(_,ye,we))continue;let he=Math.floor((N+5)/40),te=Math.floor((V-5)/40),ne=Math.floor((q+5)/40),re=Math.floor((W-5)/40),ke=he<=te&&ne<=re?(te-he+1)*(re-ne+1):0;k+=ke;let fe=-1;for(let X=he<=te&&ne<=re?E.get(_,he,ne):-1,ie=0;X>=0&&ie<8;X=D[X],ie++){let ee=x[X];if(p[ee]!==N||d[ee]!==V||h[ee]!==q||m[ee]!==W||A[ee]!==Q)continue;let Se=e[w[ee]].m,Ae=!0;for(let ge=0;ge<12;ge++)if(Se[ge]!==P[ge]){Ae=!1;break}if(Ae){fe=ee;break}}if(fe>=0){let X=n?n[L]:0;if(n&&X<n[w[fe]])b[fe]=w[fe],w[fe]=L;else if(b[fe]<0||n&&X<n[b[fe]])b[fe]=L;continue}let se=u++;p[se]=N,d[se]=V,h[se]=q,m[se]=W,w[se]=L,b[se]=-1,A.push(Q),g[se]=S[0],y[se]=S[2],v[se]=_;let pe=se*9;if(M[pe]=P[0],M[pe+1]=P[1],M[pe+2]=P[2],M[pe+3]=P[3],M[pe+4]=P[6],M[pe+5]=P[9],M[pe+6]=P[5],M[pe+7]=P[8],M[pe+8]=P[11],z[se]=Q.full&&S[3]-S[0]<=20*Q.nx&&S[5]-S[2]<=20*Q.nz&&P[4]===0&&P[6]===0&&P[8]===0&&P[10]===0&&Wn(P[3],P[5],P[9],P[11])?1:0,U+ke>r){U=r+1;continue}for(let X=he;X<=te;X++)for(let ie=ne;ie<=re;ie++){if(!Fe(_,X,ie))continue;let ee=U++;x[ee]=se,D[ee]=E.put(_,X,ie,ee)}}if(U>r)return Jt=k,null;let I=[0,5,-5,5,-5],F=[0,5,5,-5,-5],C=(L,B,P,R)=>{if(!(B-6>=p[L]-0.5&&B+6<=d[L]+0.5&&R-6>=h[L]-0.5&&R+6<=m[L]+0.5))return!1;if(z[L]===1)return!0;let S=L*9,N=A[L],V=g[L],q=y[L],W=B-M[S],_=P-M[S+1],Q=R-M[S+2],ae=M[S+3]*W+M[S+4]*_+M[S+5]*Q,ye=M[S+6]*W+M[S+7]*_+M[S+8]*Q,{nx:xe,nz:we,mask:he}=N;for(let te=0;te<5;te++){let ne=Math.floor((ae+I[te]-V)/20),re=Math.floor((ye+F[te]-q)/20);if(ne<0||re<0||ne>=xe||re>=we||he[ne*we+re]!==1)return!1}return!0},j=NaN,de=NaN,be=NaN,me=-1,le=-1,Te=(L,B,P,R)=>{let S=Math.round(B*2),N=Math.floor(L/40),V=Math.floor(P/40);if(!Fe(S,N,V))return Ue;let q=Ue;if(!n&&le>=0&&v[le]===S&&(w[le]!==R||b[le]>=0)&&C(le,L,B,P))return 0;if(S!==j||N!==de||V!==be)j=S,de=N,be=V,me=E.get(S,N,V);for(let W=me;W>=0;W=D[W]){let _=x[W],Q=w[_];if(Q===R&&(Q=b[_])<0)continue;if(!C(_,L,B,P))continue;if(!n)return le=_,0;let ae=n[Q];if(ae<q)q=ae}return q},Me=new Uint8Array(l),Le=new Uint8Array(l),ve=0,ce=n?new Pe(l,4):null,Ce=n?null:new Int32Array(l),ue=n?null:new Int32Array(l),O=n?null:new Int32Array(l),T=0,Y=n?new Int32Array(l).fill(Ue):void 0;for(let L=0,B=0;L<e.length;L++){let P=e[L],R=f[L];if(!R)continue;let S=P.m,N=R.studM,V=S[0],q=S[1],W=S[2],_=S[3],Q=S[4],ae=S[5],ye=S[6],xe=S[7],we=S[8],he=S[9],te=S[10],ne=S[11];for(let re=0;re<R.nStuds;re++,B++){let ke=re*12,fe=N[ke+4],se=N[ke+7],pe=N[ke+10];if(!(Math.abs(ye*fe+xe*se+we*pe-1)<0.001&&Math.abs(_*fe+Q*se+ae*pe)<0.001&&Math.abs(he*fe+te*se+ne*pe)<0.001))continue;Le[B]=1;let X=N[ke],ie=N[ke+1],ee=N[ke+2],Se=V+_*X+Q*ie+ae*ee,Ae=q+ye*X+xe*ie+we*ee,ge=W+he*X+te*ie+ne*ee,gt=Te(Se,Ae,ge,L);if(gt!==Ue){if(Me[B]=1,ve++,Y)Y[B]=gt}let Ne=Math.round(Se),Oe=Math.round(Ae),ze=Math.round(ge);if(!Fe(Ne,Oe,ze))continue;if(!ce){Ce[T]=Ne,ue[T]=Oe,O[T++]=ze;continue}let dt=n[L],bt=ce.get(Ne,Oe,ze);if(bt<0||dt<bt)ce.put(Ne,Oe,ze,dt)}}let J=ce?null:new Yt(Ce,ue,O,T),H=new Uint8Array(e.length),oe=n?new Int32Array(e.length).fill(Ue):void 0;for(let L=0;L<e.length;L++){let B=e[L],P=t.parts[B.part];if(!P||!P.under||!Xt(B.m)||i(B.color))continue;let R=P.bbox,S=Math.round((R[3]-R[0])/20),N=Math.round((R[5]-R[2])/20);if(!S||!N||S*N>4096)continue;let V=B.m,q=Math.round(V[1]+R[4]),W=!0,_=0;for(let Q=0;Q<S&&W;Q++)for(let ae=0;ae<N;ae++){let ye=R[0]+10+20*Q,xe=R[2]+10+20*ae,we=V[0]+V[3]*ye+V[5]*xe,he=V[2]+V[9]*ye+V[11]*xe,te=Math.round(we),ne=Math.round(he),re=!Fe(te,q,ne)?-1:ce?ce.get(te,q,ne):J.has(te,q,ne)?1:-1;if(re<0){W=!1;break}if(re>_)_=re}if(W){if(H[L]=1,oe)oe[L]=_}}return{nStuds:l,studHidden:Me,studUp:Le,underHidden:H,studsHidden:ve,studHideStep:Y,underHideStep:oe}}function ht(e,t,n){let r=(l)=>l.colPart&&t.parts[l.colPart]?l.colPart:n&&l.texPart&&t.parts[l.texPart]?l.texPart:l.part,s=new Map,o=new Map,i=(l)=>{let f=l.colour;if(!f)return String(l.color);let p=o.get(f);if(p!==void 0)return p;let d=t.colorTable?.[l.color],h=d?.hex??t.colors?.[l.color],m=d?ct({alpha:d.alpha??255,luminance:d.luminance??0,finish:d.finish??{type:"default"}}):"default:op",w=ct(f);if(p=h&&h.toUpperCase()===f.hex.toUpperCase()&&m===w?String(l.color):f.hex.toUpperCase()+"/"+w,p!==String(l.color))s.set(p,f);return o.set(f,p),p},c=e.map((l)=>({part:r(l),color:i(l),m:l.m,steps:l.steps})),{stepOf:a,nSteps:u}=Kn(c);return{all:c,stepOf:a,nSteps:u,localColours:s}}function Kn(e){let t=!0;for(let o=0;o<e.length;o++){let i=e[o].steps;if(i.length!==1){t=!1;break}let c=i[0];if(!(Number.isInteger(c)&&c>=0&&c<1e6)){t=!1;break}}if(t){let o=new Set;for(let a=0;a<e.length;a++)o.add(e[a].steps[0]);let i=[...o].sort((a,u)=>a-u),c=new Map(i.map((a,u)=>[a,u]));return{stepOf:e.map((a)=>c.get(a.steps[0])),nSteps:i.length}}let n=e.map((o)=>_t(o.steps)),r=[...new Set(n)].sort(),s=new Map(r.map((o,i)=>[o,i]));return{stepOf:n.map((o)=>s.get(o)),nSteps:r.length}}function Qt(e,t,n=!0){let r=ht(e,t,n);return mt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ze="https://ldr-parts-cdn.baconbrix.workers.dev/v1/",We=new Map,He=new Map;function Xe(e=Ze,t=fetch){let n=We.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(()=>We.delete(e)),We.set(e,n);return n}var Zn=(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"),Ke=(e,t)=>Zn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ke(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ke(r,t)])):e;function Yn(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 h=new DataView(d).getUint32(0,!0),m=new Uint8Array(d,4+h),w=r;n.push(m),r+=m.byteLength;let b=(4-r%4)%4;if(b)n.push(new Uint8Array(b)),r+=b;for(let[g,y]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ke(y,w);for(let[g,y]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ke(y,w)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+c.length)%4)%4,u=4+c.length+a,l=new Uint8Array(u+r);new DataView(l.buffer).setUint32(0,c.length+a,!0),l.set(c,4),l.fill(32,4+c.length,u);let f=u;for(let p of n)l.set(p,f),f+=p.byteLength;return _e(l.buffer)}async function Jn(e,t={}){e=[...e];try{return await qt(e,t)}catch(n){let r=t.cdn??Ze,s=t.fetch??fetch;We.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await qt(e,{...t,fetch:o})}catch{throw n}}}async function qt(e,t){let n=t.cdn??Ze,r=t.fetch??fetch,s=t.gap??16384,o=await Xe(n,r),i=[...new Set([...new Set(e)].map(Z))],c=[],a=[];for(let g of i){if(He.has(n+g))continue;let y=o.parts[g];if(y)a.push({name:g,off:y[0],len:y[1],file:y[2]??0});else c.push(g)}a.sort((g,y)=>g.file-y.file||g.off-y.off);let u=[];for(let g of a){let y=u[u.length-1];if(y&&y.file===g.file&&g.off-y.end<=s)y.end=Math.max(y.end,g.off+g.len),y.items.push(g);else u.push({file:g.file,start:g.off,end:g.off+g.len,items:[g]})}let l=0,f=0,p=0,d=new Map,h=async()=>{while(p<u.length){let g=u[p++],y=d.get(g.file);if(y)y=y.subarray(g.start,g.end);else{let A=await r(new URL(o.archives[g.file],n).href,{headers:{Range:`bytes=${g.start}-${g.end-1}`,"Accept-Encoding":"identity"}});if(!A.ok)throw Error(`ldr: parts CDN ${A.status}`);if(f++,y=new Uint8Array(await A.arrayBuffer()),l+=y.byteLength,A.status===200)d.set(g.file,y),y=y.subarray(g.start,g.end)}for(let A of g.items){let v=Ve(y.subarray(A.off-g.start,A.off-g.start+A.len)),M=v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength);He.set(n+A.name,_e(M))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,u.length)},h));let m=i.filter((g)=>He.has(n+g)).map((g)=>He.get(n+g)),w={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:m.length?Yn(m,w):_e(Qn(w)),missing:c,requests:f,bytes:l}}function Qn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...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 qn(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 en(e,t,n){let r=0,s=0,o=!1,i=new Set,c=new Map;for(let a of e){let u;if(a.embedded)u=t.get(a.part);else if(u=c.get(a.part),u===void 0)c.set(a.part,u=Z(a.part));let l=u?n.parts[u]:void 0;if(!l)continue;if(l[3]!=null)o=!0,r+=l[3];if(!i.has(u))i.add(u),s+=l[1]}return{bodyTris:r,packBytes:s,known:o}}class Ye 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 tn(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Xe(t.cdn??Ze,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(x)=>{if(!x.ok)throw Error(`ldr: ${x.status} fetching ${e}`);return wt(await x.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":At(e)),a=Ht(o,c,{looseGeometry:!1,callouts:t.callouts}),u=performance.now();t.onParsed?.(a),await s;let l=Wt(o,new Set(a.filter((x)=>x.embedded).map((x)=>x.part)),c),f=(x,U)=>t.maxBodyTris!=null&&x>t.maxBodyTris||t.maxPackBytes!=null&&U>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(x)=>new Ye({...x,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),h="full";if(p){let x=en(a,l,await s);if(f(x.known?x.bodyTris:0,x.packBytes)){if(!t.lowCdn)throw d(x);let U=await Xe(t.lowCdn,r).catch(()=>null);if(!U)throw d(x);let k=en(a,l,U);if(f(k.known?k.bodyTris:0,k.packBytes))throw d(k);h="low"}}let m=[...a.filter((x)=>!x.embedded).map((x)=>x.part),...l.values()],w=async()=>{let x=await Jn(m,h==="low"?{...t,cdn:t.lowCdn}:t);for(let[U,k]of l){let I=x.pack.header.parts[k];if(I)x.pack.header.parts[U]=I}return{...x,packBytes:x.pack.buffer?.byteLength??x.pack.bytes??0,bodyTris:qn(a,x.pack)}},b=await w();if(p&&f(b.bodyTris,b.packBytes)&&h==="full"&&t.lowCdn&&await Xe(t.lowCdn,r).then(()=>!0,()=>!1)){h="low";let x=b;b=await w(),b.requests+=x.requests,b.bytes+=x.bytes}if(p&&f(b.bodyTris,b.packBytes))throw d(b);let{pack:g,missing:y,requests:A,bytes:v}=b,M=new Map([...l].map(([x,U])=>[U,x])),z=y.map((x)=>M.get(x)??x),E=performance.now(),D=t.cull?Qt(a,g.header,t.textures!==!1):void 0;return{insts:a,pack:g,tier:h,missing:z,requests:A,bytes:v,cull:D,timings:{fetchModel:i-n,parse:u-i,parts:E-u,...D?{cull:performance.now()-E}:{}}}}var er=new Set(["part","color","m","step","steps","localStep","path"]);function nn(e){let t=e.length,n=0;for(let h of e){if(typeof h.part!=="string"||typeof h.path!=="string"||typeof h.color!=="number"||typeof h.step!=="number"||typeof h.localStep!=="number"||!Array.isArray(h.m)||h.m.length!==12||!Array.isArray(h.steps))return null;n+=h.steps.length}let r=[],s=new Map,o=(h)=>{let m=s.get(h);if(m===void 0)s.set(h,m=r.length),r.push(h);return m},i=new Uint32Array(t),c=new Uint32Array(t),a=new Float64Array(t*3),u=new Float64Array(t*12),l=new Uint32Array(t+1),f=new Float64Array(n),p=[],d=0;for(let h=0;h<t;h++){let m=e[h];i[h]=o(m.part),c[h]=o(m.path),a[h*3]=m.color,a[h*3+1]=m.step,a[h*3+2]=m.localStep;let w=m.m,b=h*12;for(let A=0;A<12;A++)u[b+A]=w[A];let g=m.steps;for(let A=0;A<g.length;A++)f[d++]=g[A];l[h+1]=d;let y=null;for(let A in m)if(!er.has(A))(y??={})[A]=m[A];if(y)p.push([h,y])}return{n:t,strs:r,part:i,path:c,num:a,m:u,so:l,steps:f,extra:p}}var rn=(e)=>[e.part.buffer,e.path.buffer,e.num.buffer,e.m.buffer,e.so.buffer,e.steps.buffer];self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await tn(n,{...r,cull:!1,onParsed:(f)=>{let p=nn(f);if(p)self.postMessage({id:t,packed:p},rn(p));else 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(),c=ht(s.insts,s.pack.header,r.textures!==!1),a=mt(c.all,s.pack.header,r.stepCull&&c.nSteps>1?c.stepOf:void 0),u=performance.now()-i,l=[];for(let f of[a.studHidden,a.studUp,a.underHidden,a.studHideStep,a.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:a,ms:u},l)}catch(s){if(s instanceof Ye||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';
5614
5623
 
5615
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/inst-io.ts
5624
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/inst-io.ts
5616
5625
  var CORE = new Set(["part", "color", "m", "step", "steps", "localStep", "path"]);
5617
5626
  function unpackInstances(p) {
5618
5627
  const { n, strs, part, path, num, m, so, steps, extra } = p;
@@ -5637,7 +5646,7 @@ function unpackInstances(p) {
5637
5646
  return out;
5638
5647
  }
5639
5648
 
5640
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/cdn.ts
5649
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/cdn.ts
5641
5650
  var worker;
5642
5651
  var seq = 0;
5643
5652
  var pending = new Map;
@@ -5753,7 +5762,7 @@ async function loadModel(source, o = {}) {
5753
5762
  timings: { ...prep.timings, parts: t3 - t0 - prep.timings.fetchModel - prep.timings.parse, build: t4 - t3, total: t4 - t0 }
5754
5763
  });
5755
5764
  }
5756
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/usdz.ts
5765
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/usdz.ts
5757
5766
  var IDENT = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1];
5758
5767
  var MAX_ERR = 8;
5759
5768
  var REL_ERR = 0.1;
@@ -1,2 +1,2 @@
1
- declare const _default: "var sn=ArrayBuffer,H=Uint8Array,$e=Uint16Array,on=Int16Array;var je=Int32Array,Ye=function(e,t,n){if(H.prototype.slice)return H.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 H(n-t);return r.set(e.subarray(t,n)),r},Be=function(e,t,n,r){if(H.prototype.fill)return H.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},an=function(e,t,n,r){if(H.prototype.copyWithin)return H.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 ln=[\"invalid zstd data\",\"window size too large (>2046MB)\",\"invalid block type\",\"FSE accuracy too high\",\"match distance too far back\",\"unexpected EOF\"],Z=function(e,t,n){var r=Error(t||ln[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Z);if(!n)throw r;return r},yt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},cn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},un=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,c=r>>6;if(r&8)Z(0);var a=6-s,u=i==3?4:i,l=yt(e,a,u);a+=u;var f=c?1<<c:s,h=yt(e,a,f)+(c==1&&256),g=h;if(!s){var p=1<<10+(e[5]>>3);g=p+(p>>3)*(e[5]&7)}if(g>2145386496)Z(1);var m=new H((t==1?h||g:t?0:g)+12);return m[0]=1,m[4]=4,m[8]=8,{b:a+f,y:0,l:0,d:l,w:t&&t!=1?t:m.subarray(12),e:g,o:new je(m.buffer,0,3),u:h,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return cn(e,4)+8;Z(0)},Se=function(e){var t=0;for(;1<<t<=e;++t);return t-1},De=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Z(3);var o=1<<s,i=o,c=-1,a=-1,u=-1,l=o,f=new sn(512+(o<<2)),h=new on(f,0,256),g=new $e(f,0,256),p=new $e(f,512,o),m=512+(o<<1),A=new H(f,m,o),b=new H(f,m+o);while(c<255&&i>0){var d=Se(i+1),x=r>>3,w=(1<<d+1)-1,v=(e[x]|e[x+1]<<8|e[x+2]<<16)>>(r&7)&w,M=(1<<d)-1,U=w-i-1,S=v&M;if(S<U)r+=d,v=S;else if(r+=d+1,v>M)v-=U;if(h[++c]=--v,v==-1)i+=v,A[--l]=c;else i-=v;if(!v)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)Z(0);var y=0,R=(o>>1)+(o>>3)+3,C=o-1;for(var F=0;F<=c;++F){var B=h[F];if(B<1){g[F]=-B;continue}for(u=0;u<B;++u){A[y]=F;do y=y+R&C;while(y>=l)}}if(y)Z(0);for(u=0;u<o;++u){var L=g[A[u]]++,V=b[u]=s-Se(L);p[u]=(L<<V)-o}return[r+7>>3,{b:s,s:A,n:b,t:p}]},fn=function(e,t){var n=0,r=-1,s=new H(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),a=new $e(s.buffer,268);if(o<128){var u=De(e,t+1,6),l=u[0],f=u[1];t+=o;var h=l<<3,g=e[t];if(!g)Z(0);var p=0,m=0,A=f.b,b=A,d=(++t<<3)-8+Se(g);for(;;){if(d-=A,d<h)break;var x=d>>3;if(p+=(e[x]|e[x+1]<<8)>>(d&7)&(1<<A)-1,i[++r]=f.s[p],d-=b,d<h)break;x=d>>3,m+=(e[x]|e[x+1]<<8)>>(d&7)&(1<<b)-1,i[++r]=f.s[m],A=f.n[p],p=f.t[p],b=f.n[m],m=f.t[m]}if(++r>255)Z(0)}else{r=o-127;for(;n<r;n+=2){var w=e[++t];i[n]=w>>4,i[n+1]=w&15}++t}var v=0;for(n=0;n<r;++n){var M=i[n];if(M>11)Z(0);v+=M&&1<<M-1}var U=Se(v)+1,S=1<<U,D=S-v;if(D&D-1)Z(0);i[r++]=Se(D)+1;for(n=0;n<r;++n){var M=i[n];++c[i[n]=M&&U+1-M]}var y=new H(S<<1),R=y.subarray(0,S),C=y.subarray(S);a[U]=0;for(n=U;n>0;--n){var F=a[n];Be(C,n,F,a[n-1]=F+c[n]*(1<<U-n))}if(a[0]!=S)Z(0);for(n=0;n<r;++n){var B=i[n];if(B){var L=a[B];Be(R,n,L,a[B]=L+(1<<U-B))}}return[t,{n:C,b:U,s:R}]},pn=De(new H([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],mn=De(new H([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],hn=De(new H([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],xt=function(e,t){var n=e.length,r=new je(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Je=new H(new je([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),gn=xt(Je,0),Qe=new H(new je([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),dn=xt(Qe,3),Re=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)Z(0);var a=0,u=n.b,l=(r<<3)-8+Se(o)-u,f=-1;for(;l>c&&f<s;){var h=l>>3,g=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(l&7);a=(a<<u|g)&i,t[++f]=n.s[a],l-=u=n.n[a]}if(l!=c||f+1!=s)Z(0)},bn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;Re(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Re(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Re(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),Re(e.subarray(r),t.subarray(c),n)},yn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Be(n,e[s],t.y,t.y+=c),n;return Be(new H(c),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=c,n;return Ye(e,s,a)}if(i==2){var u=e[s],l=u&3,f=u>>2&3,h=u>>4,g=0,p=0;if(l<2)if(f&1)h|=e[++s]<<4|(f&2&&e[++s]<<12);else h=u>>3;else if(p=f,f<2)h|=(e[++s]&63)<<4,g=e[s]>>6|e[++s]<<2;else if(f==2)h|=e[++s]<<4|(e[++s]&3)<<12,g=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,g=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var m=n?n.subarray(t.y,t.y+t.m):new H(t.m),A=m.length-h;if(l==0)m.set(e.subarray(s,s+=h),A);else if(l==1)Be(m,e[s++],A);else{var b=t.h;if(l==2){var d=fn(e,s);g+=s-(s=d[0]),t.h=b=d[1]}else if(!b)Z(0);(p?bn:Re)(e.subarray(s,s+=g),m.subarray(A),b)}var x=e[s++];if(x){if(x==255)x=(e[s++]|e[s++]<<8)+32512;else if(x>127)x=x-128<<8|e[s++];var w=e[s++];if(w&3)Z(0);var v=[mn,hn,pn];for(var M=2;M>-1;--M){var U=w>>(M<<1)+2&3;if(U==1){var S=new H([0,0,e[s++]]);v[M]={s:S.subarray(2,3),n:S.subarray(0,1),t:new $e(S.buffer,0,1),b:0}}else if(U==2)r=De(e,s,9-(M&1)),s=r[0],v[M]=r[1];else if(U==3){if(!t.t)Z(0);v[M]=t.t[M]}}var D=t.t=v,y=D[0],R=D[1],C=D[2],F=e[a-1];if(!F)Z(0);var B=(a<<3)-8+Se(F)-C.b,L=B>>3,V=0,me=(e[L]|e[L+1]<<8)>>(B&7)&(1<<C.b)-1;L=(B-=R.b)>>3;var be=(e[L]|e[L+1]<<8)>>(B&7)&(1<<R.b)-1;L=(B-=y.b)>>3;var ye=(e[L]|e[L+1]<<8)>>(B&7)&(1<<y.b)-1;for(++x;--x;){var ue=C.s[me],Pe=C.n[me],xe=y.s[ye],Ce=y.n[ye],ke=R.s[be],he=R.n[be];L=(B-=ke)>>3;var O=1<<ke,k=O+((e[L]|e[L+1]<<8|e[L+2]<<16|e[L+3]<<24)>>>(B&7)&O-1);L=(B-=Qe[xe])>>3;var J=dn[xe]+((e[L]|e[L+1]<<8|e[L+2]<<16)>>(B&7)&(1<<Qe[xe])-1);L=(B-=Je[ue])>>3;var _=gn[ue]+((e[L]|e[L+1]<<8|e[L+2]<<16)>>(B&7)&(1<<Je[ue])-1);if(L=(B-=Pe)>>3,me=C.t[me]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<Pe)-1),L=(B-=Ce)>>3,ye=y.t[ye]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<Ce)-1),L=(B-=he)>>3,be=R.t[be]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<he)-1),k>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=k-=3;else{var W=k-(_!=0);if(W){if(k=W==3?t.o[0]-1:t.o[W],W>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=k}else k=t.o[0]}for(var M=0;M<_;++M)m[V+M]=m[A+M];V+=_,A+=_;var ne=V-k;if(ne<0){var q=-ne,le=t.e+ne;if(q>J)q=J;for(var M=0;M<q;++M)m[V+M]=t.w[le+M];V+=q,J-=q,ne=0}for(var M=0;M<J;++M)m[V+M]=m[ne+M];V+=J}if(V!=A)while(A<m.length)m[V++]=m[A++];else V=m.length;if(n)t.y+=V;else m=Ye(m,0,V)}else if(n){if(t.y+=h,A)for(var M=0;M<h;++M)m[M]=m[A+M]}else if(A)m=Ye(m,A);return t.b=a,m}Z(2)},xn=function(e,t){if(e.length==1)return e[0];var n=new H(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 Ve(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=un(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 c=yn(e,i,t);if(!c)Z(5);if(t)i.e=i.y;else n.push(c),o+=c.length,an(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return xn(n,o)}async function wn(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(Ve(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 wt(e){return new TextDecoder().decode(await wn(e))}var At=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\").replace(/\\.(zst|gz)$/i,\"\")||\"main.ldr\";function _e(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 Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\"),et=/^[A-Za-z][A-Za-z0-9_]*$/,qe=new Map;function tt(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(!qe.has(r))qe.set(r,t);return r}function nt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&et.test(e))return tt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,An=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),Mn=new Set([\"FILE\",\"NOFILE\",\"!DATA\"]),Pt=1000000000000000,It=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),vn=new Set([\"model\",\"submodel\",\"configuration\"]),Cn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function vt(e){let t=Cn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return It.has(n)||vn.has(n)?n:void 0}function kn(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 Tn(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((f)=>Number.isFinite(f)&&Math.abs(f)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let f=0;f<s;f++)c=c.replace(/^\\S+\\s*/,\"\");let a=kn(c);if(!a.length)return null;let u={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)u.a=i[9];if(s===11)u.b=i[10];let l=a.findIndex((f,h)=>h>0&&f.toUpperCase()===\"GLOSSMAP\");if(l>0&&a[l+1])u.glossmap=a[l+1];if(t)u.next=!0;return u}var Ln=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\");if(t.length%4===1)t=t.slice(0,-1);let 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 Sn(e,t){let n=e.length,r=1,s=(p)=>p===32||p===9,o=()=>{while(r<n&&s(e.charCodeAt(r)))r++;let p=r,m=e.charCodeAt(r),A=m===45;if(A)m=e.charCodeAt(++r);let b=0,d=0;while(m>=48&&m<=57)b=b*10+(m-48),d++,m=e.charCodeAt(++r);if(d>0&&d<=15&&(r>=n||s(m)))return A?-b:b;while(r<n&&!s(e.charCodeAt(r)))r++;return p<r?+e.slice(p,r):NaN};while(r<n&&s(e.charCodeAt(r)))r++;let i=r;if(r>=n)return null;let c=e.charCodeAt(r),a=c===45,u=0,l=0;if(a)c=e.charCodeAt(++r);while(c>=48&&c<=57)u=u*10+(c-48),l++,c=e.charCodeAt(++r);if(l>0&&l<=15&&(r>=n||s(c))){if(a)u=-u}else{while(r<n&&!s(e.charCodeAt(r)))r++;u=nt(e.slice(i,r))}let f=Array(12);for(let p=0;p<12;p++){let m=o();if(!Number.isFinite(m))return null;f[p]=m}while(r<n&&s(e.charCodeAt(r)))r++;if(r>=n)return null;let h=e.slice(r),g=t.get(h);if(g===void 0)g=Y(/[ \\t]{2,}|\\t/.test(h)?h.split(/\\s+/).join(\" \"):h),t.set(h,g);if(!Number.isFinite(u))return null;return{t:1,color:u,m:f,file:g}}var En=[0,12,6,9,12,12];function Ct(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=nt(e[1]),r=En[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Y(e.slice(14).join(\" \"));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Ft(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,s=new Map,o=null,i=\"\",c,a=null,u=[],l=null,f=()=>{if(!a)return;let x=Ln(a.chunks.join(\"\")),w=x[0]===137&&x[1]===80&&x[2]===78&&x[3]===71;(c??=new Map).set(Y(a.name),{name:a.name,bytes:x,...w?{mime:\"image/png\"}:{}}),a=null},h=new Map,g=!0,p=(x)=>{if(f(),o={name:Y(x),cmds:[]},s.set(o.name,o),!i)i=o.name;u=[],l=null,g=!0},m=!1,A=!1,b=()=>{if(A)return;A=!0,s.clear(),o=null,i=\"\"},d=(x,w)=>{if(l){x.tex=l,l=null;return}let v=u[u.length-1];if(!v)return;if(v.fallback){if(!w)x.fallback=!0}else x.tex=v.map};for(let x of e.split(`\n`)){let w=x.trim();if(!w)continue;if(r&&w.charCodeAt(0)>=50&&w.charCodeAt(0)<=53&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)){if(a||m)continue;if(!o)p(t);let S=w.slice(2).trimStart(),D=S.search(/\\s/),y={t:w.charCodeAt(0)-48,color:nt(D<0?S:S.slice(0,D)),p:[],src:w};d(y,!1),o.cmds.push(y),g=!1;continue}if(w.charCodeAt(0)===48&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)){let S=2;while(w.charCodeAt(S)===32||w.charCodeAt(S)===9)S++;let D=S;while(D<w.length&&w.charCodeAt(D)!==32&&w.charCodeAt(D)!==9)D++;let y=w.slice(S,D),R=/[^\\x21-\\x7e]/.test(y)?w.slice(S).trim().split(/\\s+/)[0]:y;if(!An.has(R)&&!(R.length>=4&&R.length<=6&&Mn.has(R.toUpperCase()))){if(m||a)continue;if(!o)p(t);let C=w.slice(S),F={t:0,text:C};if(y.charCodeAt(0)===33)F.meta=y;if(l=null,g&&!o.org){let L=vt(C);if(L)o.org=L}let B=C.match(Mt);if(B&&!o.movedTo){let L=B[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(L))L+=\".dat\";o.movedTo=Y(L)}o.cmds.push(F);continue}}if(w.charCodeAt(0)===49&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)&&!a&&!m){let S=Sn(w,h);if(S){if(!o)p(t);d(S,!1),o.cmds.push(S),g=!1;continue}}let v=w.split(/\\s+/);if(+v[0]===0){let S=w.slice(1).trim(),D=v.length>1&&v[1].length>=4&&v[1].length<=6?v[1].toUpperCase():v[1];if(D===\"FILE\"){let C=S.slice(5).trimStart().split(\"\\r\")[0].trim();if(C){b(),m=!1,p(C);continue}}if(D===\"NOFILE\"){f(),o=null,m=!0;continue}if(D===\"!DATA\"){b(),f(),o=null,m=!1,a={name:S.slice(5).trim(),chunks:[]};continue}if(m)continue;if(a){if(v[1]===\"!:\")a.chunks.push(v.slice(2).join(\"\"));continue}if(!o)p(t);let y={t:0,text:S};if(v[1]===\"STEP\")y.step=!0,u=[],l=null;else if(v[1]===\"BFC\")y.bfc=v.slice(2).join(\" \");else if(v[1]===\"ROTSTEP\")if(y.meta=\"ROTSTEP\",y.step=!0,u=[],l=null,(v[2]??\"\").toUpperCase()===\"END\")y.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let C=(v[5]??\"REL\").toUpperCase(),F=(B)=>{let L=Number(B);return Number.isFinite(L)?L:0};y.rotstep={x:F(v[2]),y:F(v[3]),z:F(v[4]),mode:[\"REL\",\"ABS\",\"ADD\"].includes(C)?C:\"REL\"}}else if(v[1]===\"BUFEXCHG\"){y.meta=\"BUFEXCHG\";let C=(v[2]??\"\").toUpperCase();y.bufexchg={op:C===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:v[3]??\"A\"}}else if(v[1]?.startsWith(\"!\"))y.meta=v[1];if(g&&!o.org){let C=vt(S);if(C)o.org=C}if(v[1]===\"!TEXMAP\"){let C=(v[2]??\"\").toUpperCase();if(l=null,C===\"START\"||C===\"NEXT\"){let F=Tn(S.replace(/^!TEXMAP\\s+\\S+/i,\"\"),C===\"NEXT\");if(y.texmap={op:C,...F?{map:F}:{}},F)if((o.texmaps??=[]).push(F),C===\"START\")u.push({map:F,fallback:!1});else l=F}else if(C===\"FALLBACK\"){y.texmap={op:C};let F=u[u.length-1];if(F)F.fallback=!0}else if(C===\"END\")y.texmap={op:C},u.pop()}else if(v[1]===\"!:\"){l=null;let C=Ct(v.slice(2));if(C)d(C,!0),y.geom=C}else l=null;let R=S.match(Mt);if(R&&!o.movedTo){let C=R[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=\".dat\";o.movedTo=Y(C)}o.cmds.push(y);continue}if(a||m)continue;if(!o)p(t);let U=Ct(v);if(!U){if(/^[2-5][ \\t]/.test(w))g=!1;continue}d(U,!1),o.cmds.push(U),g=!1}return f(),c?{main:i,files:s,data:c}:{main:i,files:s}}var sr=Math.PI/180;function Rt(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 Bt(e,t){let[n,r,s,o,i,c,a,u,l,f,h,g]=e,[p,m,A,b,d,x,w,v,M,U,S,D]=t;return[o*p+i*m+c*A+n,a*p+u*m+l*A+r,f*p+h*m+g*A+s,o*b+i*w+c*U,o*d+i*v+c*S,o*x+i*M+c*D,a*b+u*w+l*U,a*d+u*v+l*S,a*x+u*M+l*D,f*b+h*w+g*U,f*d+h*v+g*S,f*x+h*M+g*D]}var rt=[0,0,0,1,0,0,0,1,0,0,0,1];var kt=new WeakMap,Pn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Y(t));if(!n)return\"part\";let r=kt.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&&Pn.test(s.file))?\"part\":\"model\";return kt.set(n,r),r}var Tt=new WeakMap;function Dt(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 Lt=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():e<0?qe.get(e)??String(e):String(e),In=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${Lt(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${Lt(e.color)} ${e.p.join(\" \")}`,ot=(e,t)=>`${Y(e)}#${t}`;function Fn(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:ot(e.name,t),cmds:n}}function Ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Fn(e,t).cmds.map(In)].join(`\n`)+`\n`}function it(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 Nt(e){let[t,n,r,s,o,i,c,a,u,l,f,h]=e,g=a*h-u*f,p=-(c*h-u*l),m=c*f-a*l,A=s*g+o*p+i*m;if(!Number.isFinite(A)||Math.abs(A)<0.000000000001)return null;let b=1/A,d=[g*b,-(o*h-i*f)*b,(o*u-i*a)*b,p*b,(s*h-i*l)*b,-(s*u-i*c)*b,m*b,-(s*f-o*l)*b,(s*a-o*c)*b];return[-(d[0]*t+d[1]*n+d[2]*r),-(d[3]*t+d[4]*n+d[5]*r),-(d[6]*t+d[7]*n+d[8]*r),...d]}var Rn=(e)=>String(+e.toFixed(6)||0),St=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function Ot(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map(Rn).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 ${Y(e)}\n0 !TEXMAP END\n`;return{name:`${Y(e)}#tex-${it(r)}`,source:r}}var Bn=(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 Dn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),u=Math.cos(n*r);return[c*u,-c*a,i,o*a+s*i*u,o*u-s*i*a,-s*c,s*a-o*i*u,s*u+o*i*a,o*c]}var Et=new WeakMap;function zt(e){let t=Et.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=Dn(o.x,o.y,o.z);r=o.mode===\"ABS\"?{abs:!0,m:i,rotstep:o}:o.mode===\"ADD\"&&r?{abs:r.abs,m:Bn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Et.set(e,n),n}class at extends Error{limit;code=\"ldr-model-limit\";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString(\"en-US\")} (see maxInstances)`);this.limit=t;this.name=\"ModelLimitError\"}}var Un=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=Pt))return!1;return!0},$t=999999,_t=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\",Gt=new WeakMap,jt=new WeakMap;function Nn(e,t){let n=jt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Gt.get(o)??\"\",c=i.indexOf(\"!COLOUR\");return c<0?\"\":\"0 \"+i.slice(c).trim().replace(/\\s+/g,\" \")}).filter(Boolean).join(`\n`),parts:new Map},jt.set(t,n);let r=n.parts.get(e);if(!r){let s=Y(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-${it(o)}`,source:o},n.parts.set(e,r)}return r}function On(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,a=0,u=new Set,l=t.maxInstances??2000000,f=0,h=(p,m)=>{let A=p.name+\"#\"+m,b=c.get(A);if(!b){let d;b=Object.assign(()=>d??=Ut(p,m),{file:p,step:m}),c.set(A,b)}return b},g=(p,m,A,b,d,x,w,v,M=null,U=[],S=[],D=void 0,y=null)=>{let R=p.files.get(m);if(!R||w>r||u.has(R))return;if(++f>l)throw new at(\"model\",l);u.add(R);let C=y,F=0,B=w>0?++a:0,L=i&&B?[...U,B]:U,V=i&&B?[...S,A]:S,me=i&&!M?new Map:null,be=-1,ye=0,ue=(O,k,J,_,W,ne,q)=>{if(be!==F)be=F,ye=0;let le=me?.get(F+\"|\"+k);if(le)return le.n++,g(O,O===p?k:O.main,J,_,d+\"/\"+k,[...W,$t],w+1,ne,[...W,$t],L,V,q,C);let T=[...W,ye++],P=n.length;g(O,O===p?k:O.main,J,_,d+\"/\"+k,T,w+1,ne,M,L,V,q,C),me?.set(F+\"|\"+k,{n:1,from:P,to:n.length})},Pe=zt(R),xe=s?Dt(R):[],Ce=0,ke=(O,k,J,_,W,ne,q,le,T)=>{if(M)_=M;if(++f>l)throw new at(\"model\",l);let P={part:O,color:k,m:J,step:_[0],steps:_,localStep:W,path:d};if(le)P.colour=le;if(B){if(P.sub=B,i)P.subPath=L,P.subMats=V}if(ne)P.embedded=!0;if(q){let N=Ot(O,q);P.texPart=N.name,P.texSource=N.source}else if(T){let N=Nn(O,T);P.colPart=N.name,P.colSource=N.source}let E=Pe[W];if(E)P.view=E;return n.push(P),P},he=(O)=>{while(Ce<xe.length&&xe[Ce]<=O){let k=xe[Ce++];ke(ot(R.name,k),b,A,[...x,k],k,!1,null,D,y).source=h(R,k)}};for(let O of R.cmds){if(O.t===0&&O.step){F++;continue}let k=O;if(k.t>=2||k.t===0&&k.geom&&k.geom.t>=2){he(F);continue}if(k.t===0){if(k.meta===\"!COLOUR\"){let E=$n(k.text);if(E&&E.code!==16&&E.code!==24)Gt.set(E,k.text),(C=new Map(C??[])).set(E.code,E);continue}if(o&&k.geom?.t===1)k=k.geom;else continue}if(k.t!==1)continue;if(o&&k.fallback)continue;let J=Bt(A,k.m);if(!Un(J))continue;let _=k.color===16?b:k.color,W=k.color===16?D:C?.get(k.color),ne=[...x,F],q=o?k.tex??v:null,le=q?Nt(k.m):null,T=q&&le?Rt(q,le):null;if(p.files.has(k.file)){if(st(p,k.file)===\"model\"){ue(p,k.file,J,_,ne,T,W);continue}ke(k.file,_,J,ne,F,!0,T,W,C);continue}let P=t.resolveModel?.(k.file);if(P){ue(P,k.file,J,_,ne,T,W);continue}ke(k.file,_,J,ne,F,!1,T,W,C)}if(he(1/0),u.delete(R),me){for(let O of me.values())if(O.n>1)for(let k=O.from;k<O.to;k++)n[k].mult??=O.n}};if(st(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...rt],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,rt,16,e.main,[],0,null),n}function Ht(e,t=\"main.ldr\",n){return On(Ft(e,t,{geometryText:!0}),n)}var zn=new Set([\"CHROME\",\"PEARLESCENT\",\"RUBBER\",\"MATTE_METALLIC\",\"METAL\",\"MATERIAL\"]);function lt(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 Vt(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=lt(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 $n(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\",c=255,a=0,u={type:\"default\"},l=1;while(l<n.length){let f=n[l].toUpperCase(),h=n[l+1];if(f===\"CODE\")s=h!==void 0&&et.test(h)?tt(h):h!==void 0&&/^\\d+$/.test(h)?+h:NaN,l+=2;else if(f===\"VALUE\"){let g=lt(h);if(g)o=g;l+=2}else if(f===\"EDGE\")i=lt(h)??h,l+=2;else if(f===\"ALPHA\")c=+h,l+=2;else if(f===\"LUMINANCE\")a=+h,l+=2;else if(f===\"CHROME\")u={type:\"chrome\"},l+=1;else if(f===\"PEARLESCENT\")u={type:\"pearlescent\"},l+=1;else if(f===\"RUBBER\")u={type:\"rubber\"},l+=1;else if(f===\"MATTE_METALLIC\")u={type:\"matte_metallic\"},l+=1;else if(f===\"METAL\")u={type:\"metal\"},l+=1;else if(f===\"MATERIAL\"){let g=(n[l+1]||\"\").toUpperCase();if(g===\"GLITTER\"){let{grain:p,next:m}=Vt(n,l+2);u={type:\"glitter\",material:p},l=m}else if(g===\"SPECKLE\"){let{grain:p,next:m}=Vt(n,l+2);u={type:\"speckle\",material:p},l=m}else if(g===\"FABRIC\"){let p=(n[l+2]||\"\").toUpperCase(),m=[\"VELVET\",\"CANVAS\",\"STRING\",\"FUR\"].includes(p)?p.toLowerCase():void 0;u={type:\"fabric\",kind:m},l+=m?3:2}else l=n.length}else if(zn.has(f))l+=1;else l+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(a)?a:0,finish:u}}function jn(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,c=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:c,finish:\"glitter\"}}case\"speckle\":{let i=e.finish.material,c=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:c,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 ct(e){let t=jn(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 Vn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Y(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Y(t),r)}let a=i.trim().replace(/\\s+/g,\" \");if(a)r.push(a)}return n}var _n=(e)=>{if(!e.startsWith(\"1 \"))return null;let t=e.split(\" \");return t.length>=15?Y(t.slice(14).join(\" \")):null};function Gn(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 Wt(e,t,n=\"main.ldr\"){let r=[...t],s=new Map;if(!r.length)return s;let o=Vn(e,n);for(let i of r){let c=Y(i);if(!o.has(c)||s.has(c))continue;let a=new Set([c]),u=[c];while(u.length)for(let f of o.get(u.pop())){let h=_n(f);if(h&&o.has(h)&&!a.has(h))a.add(h),u.push(h)}let l=[c,...[...a].filter((f)=>f!==c).sort()].map((f)=>\"0 FILE \"+(f===c?\"\":f)+`\n`+o.get(f).join(`\n`)).join(`\n`);s.set(c,`emb/${Gn(l)}.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,Kt=new WeakMap,ut=null,ft=\"\",pt=null;function Hn(e,t){if(e===ut&&t===ft)return pt;let n=Kt.get(e);if(!n)Kt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return ut=e,ft=t,pt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],a=[];s.studs.forEach((g,p)=>{c.push(g[0]),a.push(g[1]);for(let m=0;m<12;m++)i[p*12+m]=g[2+m]});let u=null,l=0,f=0;if(s.mask){l=s.mask[0],f=s.mask[1];let g=s.mask[2];u=new Uint8Array(g.length);for(let p=0;p<g.length;p++)u[p]=g.charCodeAt(p)===49?1:0}let h=!!u;if(u){for(let g=0;g<u.length;g++)if(u[g]!==1){h=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:a,mask:u,nx:l,nz:f,full:h}),ut=e,ft=t,pt=r,r}var Ie=1073741824;class Ee{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=Ee.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let a=s[c];if(a===0)return-1;if(a===r){let u=c<<2;if(o[u]===e&&o[u+1]===t&&o[u+2]===n)return o[u+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=Ee.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,a=this.slot(e,t,n);for(;;){let u=o[a],l=a<<2;if(u===0)return o[a]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(u===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let f=i[l+3];return i[l+3]=r,f}a=a+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Yt{grp=new Ee(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],a=[];for(let f=0;f<r;f++){let h=e[f],g=t[f],p=n[f],m=(h%20+20)%20,A=(p%20+20)%20,b=this.group(g,m,A);if(b<0)b=s.length,this.grp.put(g,m,A,b),this.lg=b,s.push(0),o.push(h),i.push(h),c.push(p),a.push(p);if(s[b]++,h<o[b])o[b]=h;else if(h>i[b])i[b]=h;if(p<c[b])c[b]=p;else if(p>a[b])a[b]=p}let u=0,l=0;for(let f=0;f<s.length;f++){let h=(i[f]-o[f])/20+1,g=(a[f]-c[f])/20+1,p=h*g;if(this.gX0.push(o[f]),this.gZ0.push(c[f]),this.gNx.push(h),this.gNz.push(g),p<=64*s[f]+1024&&u+p<2147483648)this.gBits.push(u),u+=p;else this.gBits.push(-1),l+=s[f]}this.bits=new Uint8Array(Math.ceil(u/8)),this.rest=new Ee(l);for(let f=0;f<r;f++){let h=e[f],g=t[f],p=n[f],m=this.group(g,(h%20+20)%20,(p%20+20)%20),A=this.gBits[m];if(A<0){this.rest.put(h,g,p,1);continue}let b=A+(h-this.gX0[m])/20*this.gNz[m]+(p-this.gZ0[m])/20;this.bits[b>>>3]|=1<<(b&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Wn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Fe=(e,t,n)=>e>-Ie&&e<Ie&&t>-Ie&&t<Ie&&n>-Ie&&n<Ie,Ue=2147483647;function Xn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function mt(e,t,n){return Zt(e,t,n,-1)??Zt(e,t,n,Jt)}var Jt=0;function Zt(e,t,n,r){let o=new Map,i=(T)=>{let P=o.get(T);if(P===void 0)o.set(T,P=Xn(t,T));return P},c=e.length,a=0,u=0,l=0,f=Array(c);for(let T=0;T<c;T++){let P=f[T]=Hn(t,e[T].part);if(P){if(l+=P.nStuds,P.mask)a++}}let h=new Float64Array(a),g=new Float64Array(a),p=new Float64Array(a),m=new Float64Array(a),A=new Int32Array(a),b=new Int32Array(a),d=new Float64Array(a),x=new Float64Array(a),w=[],v=new Int32Array(a),M=new Float64Array(a*9),U=new Uint8Array(a);if(r<0)r=a*4+64;let S=new Ee(e.length*2),D=new Int32Array(r),y=new Int32Array(r),R=0,C=0;for(let T=0;T<e.length;T++){let P=e[T],E=P.m,N=t.parts[P.part];if(!N||!N.mask||!Xt(E)||i(P.color))continue;let I=N.bbox,z=1/0,j=-1/0,ee=1/0,X=-1/0;for(let K=0;K<2;K++)for(let ae=0;ae<2;ae++){let te=K?I[3]:I[0],Le=ae?I[5]:I[2],ve=E[0]+E[3]*te+E[5]*Le,de=E[2]+E[9]*te+E[11]*Le;if(ve<z)z=ve;if(ve>j)j=ve;if(de<ee)ee=de;if(de>X)X=de}let G=Math.round((E[1]+I[4])*2),Q=f[T],ce=Math.floor(z/40),we=Math.floor(j/40),Ae=Math.floor(ee/40),Me=Math.floor(X/40);if(!((we-ce+1)*(Me-Ae+1)<=65536)||!Fe(G,ce,Ae)||!Fe(G,we,Me))continue;let ge=Math.floor((z+5)/40),re=Math.floor((j-5)/40),se=Math.floor((ee+5)/40),oe=Math.floor((X-5)/40),Te=ge<=re&&se<=oe?(re-ge+1)*(oe-se+1):0;C+=Te;let fe=-1;for(let K=ge<=re&&se<=oe?S.get(G,ge,se):-1,ae=0;K>=0&&ae<8;K=D[K],ae++){let te=y[K];if(h[te]!==z||g[te]!==j||p[te]!==ee||m[te]!==X||w[te]!==Q)continue;let Le=e[A[te]].m,ve=!0;for(let de=0;de<12;de++)if(Le[de]!==E[de]){ve=!1;break}if(ve){fe=te;break}}if(fe>=0){let K=n?n[T]:0;if(n&&K<n[A[fe]])b[fe]=A[fe],A[fe]=T;else if(b[fe]<0||n&&K<n[b[fe]])b[fe]=T;continue}let ie=u++;h[ie]=z,g[ie]=j,p[ie]=ee,m[ie]=X,A[ie]=T,b[ie]=-1,w.push(Q),d[ie]=I[0],x[ie]=I[2],v[ie]=G;let pe=ie*9;if(M[pe]=E[0],M[pe+1]=E[1],M[pe+2]=E[2],M[pe+3]=E[3],M[pe+4]=E[6],M[pe+5]=E[9],M[pe+6]=E[5],M[pe+7]=E[8],M[pe+8]=E[11],U[ie]=Q.full&&I[3]-I[0]<=20*Q.nx&&I[5]-I[2]<=20*Q.nz&&E[4]===0&&E[6]===0&&E[8]===0&&E[10]===0&&Wn(E[3],E[5],E[9],E[11])?1:0,R+Te>r){R=r+1;continue}for(let K=ge;K<=re;K++)for(let ae=se;ae<=oe;ae++){if(!Fe(G,K,ae))continue;let te=R++;y[te]=ie,D[te]=S.put(G,K,ae,te)}}if(R>r)return Jt=C,null;let F=[0,5,-5,5,-5],B=[0,5,5,-5,-5],L=(T,P,E,N)=>{if(!(P-6>=h[T]-0.5&&P+6<=g[T]+0.5&&N-6>=p[T]-0.5&&N+6<=m[T]+0.5))return!1;if(U[T]===1)return!0;let I=T*9,z=w[T],j=d[T],ee=x[T],X=P-M[I],G=E-M[I+1],Q=N-M[I+2],ce=M[I+3]*X+M[I+4]*G+M[I+5]*Q,we=M[I+6]*X+M[I+7]*G+M[I+8]*Q,{nx:Ae,nz:Me,mask:ge}=z;for(let re=0;re<5;re++){let se=Math.floor((ce+F[re]-j)/20),oe=Math.floor((we+B[re]-ee)/20);if(se<0||oe<0||se>=Ae||oe>=Me||ge[se*Me+oe]!==1)return!1}return!0},V=NaN,me=NaN,be=NaN,ye=-1,ue=-1,Pe=(T,P,E,N)=>{let I=Math.round(P*2),z=Math.floor(T/40),j=Math.floor(E/40);if(!Fe(I,z,j))return Ue;let ee=Ue;if(!n&&ue>=0&&v[ue]===I&&(A[ue]!==N||b[ue]>=0)&&L(ue,T,P,E))return 0;if(I!==V||z!==me||j!==be)V=I,me=z,be=j,ye=S.get(I,z,j);for(let X=ye;X>=0;X=D[X]){let G=y[X],Q=A[G];if(Q===N&&(Q=b[G])<0)continue;if(!L(G,T,P,E))continue;if(!n)return ue=G,0;let ce=n[Q];if(ce<ee)ee=ce}return ee},xe=new Uint8Array(l),Ce=new Uint8Array(l),ke=0,he=n?new Ee(l,4):null,O=n?null:new Int32Array(l),k=n?null:new Int32Array(l),J=n?null:new Int32Array(l),_=0,W=n?new Int32Array(l).fill(Ue):void 0;for(let T=0,P=0;T<e.length;T++){let E=e[T],N=f[T];if(!N)continue;let I=E.m,z=N.studM,j=I[0],ee=I[1],X=I[2],G=I[3],Q=I[4],ce=I[5],we=I[6],Ae=I[7],Me=I[8],ge=I[9],re=I[10],se=I[11];for(let oe=0;oe<N.nStuds;oe++,P++){let Te=oe*12,fe=z[Te+4],ie=z[Te+7],pe=z[Te+10];if(!(Math.abs(we*fe+Ae*ie+Me*pe-1)<0.001&&Math.abs(G*fe+Q*ie+ce*pe)<0.001&&Math.abs(ge*fe+re*ie+se*pe)<0.001))continue;Ce[P]=1;let K=z[Te],ae=z[Te+1],te=z[Te+2],Le=j+G*K+Q*ae+ce*te,ve=ee+we*K+Ae*ae+Me*te,de=X+ge*K+re*ae+se*te,gt=Pe(Le,ve,de,T);if(gt!==Ue){if(xe[P]=1,ke++,W)W[P]=gt}let Ne=Math.round(Le),Oe=Math.round(ve),ze=Math.round(de);if(!Fe(Ne,Oe,ze))continue;if(!he){O[_]=Ne,k[_]=Oe,J[_++]=ze;continue}let dt=n[T],bt=he.get(Ne,Oe,ze);if(bt<0||dt<bt)he.put(Ne,Oe,ze,dt)}}let ne=he?null:new Yt(O,k,J,_),q=new Uint8Array(e.length),le=n?new Int32Array(e.length).fill(Ue):void 0;for(let T=0;T<e.length;T++){let P=e[T],E=t.parts[P.part];if(!E||!E.under||!Xt(P.m)||i(P.color))continue;let N=E.bbox,I=Math.round((N[3]-N[0])/20),z=Math.round((N[5]-N[2])/20);if(!I||!z||I*z>4096)continue;let j=P.m,ee=Math.round(j[1]+N[4]),X=!0,G=0;for(let Q=0;Q<I&&X;Q++)for(let ce=0;ce<z;ce++){let we=N[0]+10+20*Q,Ae=N[2]+10+20*ce,Me=j[0]+j[3]*we+j[5]*Ae,ge=j[2]+j[9]*we+j[11]*Ae,re=Math.round(Me),se=Math.round(ge),oe=!Fe(re,ee,se)?-1:he?he.get(re,ee,se):ne.has(re,ee,se)?1:-1;if(oe<0){X=!1;break}if(oe>G)G=oe}if(X){if(q[T]=1,le)le[T]=G}}return{nStuds:l,studHidden:xe,studUp:Ce,underHidden:q,studsHidden:ke,studHideStep:W,underHideStep:le}}function ht(e,t,n){let r=(l)=>l.colPart&&t.parts[l.colPart]?l.colPart:n&&l.texPart&&t.parts[l.texPart]?l.texPart:l.part,s=new Map,o=new Map,i=(l)=>{let f=l.colour;if(!f)return String(l.color);let h=o.get(f);if(h!==void 0)return h;let g=t.colorTable?.[l.color],p=g?.hex??t.colors?.[l.color],m=g?ct({alpha:g.alpha??255,luminance:g.luminance??0,finish:g.finish??{type:\"default\"}}):\"default:op\",A=ct(f);if(h=p&&p.toUpperCase()===f.hex.toUpperCase()&&m===A?String(l.color):f.hex.toUpperCase()+\"/\"+A,h!==String(l.color))s.set(h,f);return o.set(f,h),h},c=e.map((l)=>({part:r(l),color:i(l),m:l.m,steps:l.steps})),{stepOf:a,nSteps:u}=Kn(c);return{all:c,stepOf:a,nSteps:u,localColours:s}}function Kn(e){let t=!0;for(let o=0;o<e.length;o++){let i=e[o].steps;if(i.length!==1){t=!1;break}let c=i[0];if(!(Number.isInteger(c)&&c>=0&&c<1e6)){t=!1;break}}if(t){let o=new Set;for(let a=0;a<e.length;a++)o.add(e[a].steps[0]);let i=[...o].sort((a,u)=>a-u),c=new Map(i.map((a,u)=>[a,u]));return{stepOf:e.map((a)=>c.get(a.steps[0])),nSteps:i.length}}let n=e.map((o)=>_t(o.steps)),r=[...new Set(n)].sort(),s=new Map(r.map((o,i)=>[o,i]));return{stepOf:n.map((o)=>s.get(o)),nSteps:r.length}}function Qt(e,t,n=!0){let r=ht(e,t,n);return mt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ke=\"https://ldr-parts-cdn.baconbrix.workers.dev/v1/\",He=new Map,Ge=new Map;function We(e=Ke,t=fetch){let n=He.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(()=>He.delete(e)),He.set(e,n);return n}var Zn=(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\"),Xe=(e,t)=>Zn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Xe(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Xe(r,t)])):e;function Yn(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let g=h.buffer;if(!g)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let p=new DataView(g).getUint32(0,!0),m=new Uint8Array(g,4+p),A=r;n.push(m),r+=m.byteLength;let b=(4-r%4)%4;if(b)n.push(new Uint8Array(b)),r+=b;for(let[d,x]of Object.entries(h.header.parts??{}))if(!(d in s))s[d]=Xe(x,A);for(let[d,x]of Object.entries(h.header.studKinds??{}))if(!(d in o))o[d]=Xe(x,A)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+c.length)%4)%4,u=4+c.length+a,l=new Uint8Array(u+r);new DataView(l.buffer).setUint32(0,c.length+a,!0),l.set(c,4),l.fill(32,4+c.length,u);let f=u;for(let h of n)l.set(h,f),f+=h.byteLength;return _e(l.buffer)}async function Jn(e,t={}){e=[...e];try{return await qt(e,t)}catch(n){let r=t.cdn??Ke,s=t.fetch??fetch;He.delete(r);let o=(i,c)=>s(i,{...c,cache:\"reload\"});try{return await qt(e,{...t,fetch:o})}catch{throw n}}}async function qt(e,t){let n=t.cdn??Ke,r=t.fetch??fetch,s=t.gap??16384,o=await We(n,r),i=[...new Set([...new Set(e)].map(Y))],c=[],a=[];for(let d of i){if(Ge.has(n+d))continue;let x=o.parts[d];if(x)a.push({name:d,off:x[0],len:x[1],file:x[2]??0});else c.push(d)}a.sort((d,x)=>d.file-x.file||d.off-x.off);let u=[];for(let d of a){let x=u[u.length-1];if(x&&x.file===d.file&&d.off-x.end<=s)x.end=Math.max(x.end,d.off+d.len),x.items.push(d);else u.push({file:d.file,start:d.off,end:d.off+d.len,items:[d]})}let l=0,f=0,h=0,g=new Map,p=async()=>{while(h<u.length){let d=u[h++],x=g.get(d.file);if(x)x=x.subarray(d.start,d.end);else{let w=await r(new URL(o.archives[d.file],n).href,{headers:{Range:`bytes=${d.start}-${d.end-1}`,\"Accept-Encoding\":\"identity\"}});if(!w.ok)throw Error(`ldr: parts CDN ${w.status}`);if(f++,x=new Uint8Array(await w.arrayBuffer()),l+=x.byteLength,w.status===200)g.set(d.file,x),x=x.subarray(d.start,d.end)}for(let w of d.items){let v=Ve(x.subarray(w.off-d.start,w.off-d.start+w.len)),M=v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength);Ge.set(n+w.name,_e(M))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,u.length)},p));let m=i.filter((d)=>Ge.has(n+d)).map((d)=>Ge.get(n+d)),A={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:m.length?Yn(m,A):_e(Qn(A)),missing:c,requests:f,bytes:l}}function Qn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...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 qn(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 en(e,t,n){let r=0,s=0,o=!1,i=new Set,c=new Map;for(let a of e){let u;if(a.embedded)u=t.get(a.part);else if(u=c.get(a.part),u===void 0)c.set(a.part,u=Y(a.part));let l=u?n.parts[u]:void 0;if(!l)continue;if(l[3]!=null)o=!0,r+=l[3];if(!i.has(u))i.add(u),s+=l[1]}return{bodyTris:r,packBytes:s,known:o}}class Ze 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 tn(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=We(t.cdn??Ke,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(y)=>{if(!y.ok)throw Error(`ldr: ${y.status} fetching ${e}`);return wt(await y.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?\"main.ldr\":At(e)),a=Ht(o,c,{looseGeometry:!1,callouts:t.callouts}),u=performance.now();t.onParsed?.(a),await s;let l=Wt(o,new Set(a.filter((y)=>y.embedded).map((y)=>y.part)),c),f=(y,R)=>t.maxBodyTris!=null&&y>t.maxBodyTris||t.maxPackBytes!=null&&R>t.maxPackBytes,h=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(y)=>new Ze({...y,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),p=\"full\";if(h){let y=en(a,l,await s);if(f(y.known?y.bodyTris:0,y.packBytes)){if(!t.lowCdn)throw g(y);let R=await We(t.lowCdn,r).catch(()=>null);if(!R)throw g(y);let C=en(a,l,R);if(f(C.known?C.bodyTris:0,C.packBytes))throw g(C);p=\"low\"}}let m=[...a.filter((y)=>!y.embedded).map((y)=>y.part),...l.values()],A=async()=>{let y=await Jn(m,p===\"low\"?{...t,cdn:t.lowCdn}:t);for(let[R,C]of l){let F=y.pack.header.parts[C];if(F)y.pack.header.parts[R]=F}return{...y,packBytes:y.pack.buffer?.byteLength??y.pack.bytes??0,bodyTris:qn(a,y.pack)}},b=await A();if(h&&f(b.bodyTris,b.packBytes)&&p===\"full\"&&t.lowCdn&&await We(t.lowCdn,r).then(()=>!0,()=>!1)){p=\"low\";let y=b;b=await A(),b.requests+=y.requests,b.bytes+=y.bytes}if(h&&f(b.bodyTris,b.packBytes))throw g(b);let{pack:d,missing:x,requests:w,bytes:v}=b,M=new Map([...l].map(([y,R])=>[R,y])),U=x.map((y)=>M.get(y)??y),S=performance.now(),D=t.cull?Qt(a,d.header,t.textures!==!1):void 0;return{insts:a,pack:d,tier:p,missing:U,requests:w,bytes:v,cull:D,timings:{fetchModel:i-n,parse:u-i,parts:S-u,...D?{cull:performance.now()-S}:{}}}}var er=new Set([\"part\",\"color\",\"m\",\"step\",\"steps\",\"localStep\",\"path\"]);function nn(e){let t=e.length,n=0;for(let p of e){if(typeof p.part!==\"string\"||typeof p.path!==\"string\"||typeof p.color!==\"number\"||typeof p.step!==\"number\"||typeof p.localStep!==\"number\"||!Array.isArray(p.m)||p.m.length!==12||!Array.isArray(p.steps))return null;n+=p.steps.length}let r=[],s=new Map,o=(p)=>{let m=s.get(p);if(m===void 0)s.set(p,m=r.length),r.push(p);return m},i=new Uint32Array(t),c=new Uint32Array(t),a=new Float64Array(t*3),u=new Float64Array(t*12),l=new Uint32Array(t+1),f=new Float64Array(n),h=[],g=0;for(let p=0;p<t;p++){let m=e[p];i[p]=o(m.part),c[p]=o(m.path),a[p*3]=m.color,a[p*3+1]=m.step,a[p*3+2]=m.localStep;let A=m.m,b=p*12;for(let w=0;w<12;w++)u[b+w]=A[w];let d=m.steps;for(let w=0;w<d.length;w++)f[g++]=d[w];l[p+1]=g;let x=null;for(let w in m)if(!er.has(w))(x??={})[w]=m[w];if(x)h.push([p,x])}return{n:t,strs:r,part:i,path:c,num:a,m:u,so:l,steps:f,extra:h}}var rn=(e)=>[e.part.buffer,e.path.buffer,e.num.buffer,e.m.buffer,e.so.buffer,e.steps.buffer];self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await tn(n,{...r,cull:!1,onParsed:(f)=>{let h=nn(f);if(h)self.postMessage({id:t,packed:h},rn(h));else 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(),c=ht(s.insts,s.pack.header,r.textures!==!1),a=mt(c.all,s.pack.header,r.stepCull&&c.nSteps>1?c.stepOf:void 0),u=performance.now()-i,l=[];for(let f of[a.studHidden,a.studUp,a.underHidden,a.studHideStep,a.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:a,ms:u},l)}catch(s){if(s instanceof Ze||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 sn=ArrayBuffer,G=Uint8Array,$e=Uint16Array,on=Int16Array;var je=Int32Array,Je=function(e,t,n){if(G.prototype.slice)return G.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 G(n-t);return r.set(e.subarray(t,n)),r},Be=function(e,t,n,r){if(G.prototype.fill)return G.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},an=function(e,t,n,r){if(G.prototype.copyWithin)return G.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 ln=[\"invalid zstd data\",\"window size too large (>2046MB)\",\"invalid block type\",\"FSE accuracy too high\",\"match distance too far back\",\"unexpected EOF\"],K=function(e,t,n){var r=Error(t||ln[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},yt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},cn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},un=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,c=r>>6;if(r&8)K(0);var a=6-s,u=i==3?4:i,l=yt(e,a,u);a+=u;var f=c?1<<c:s,p=yt(e,a,f)+(c==1&&256),d=p;if(!s){var h=1<<10+(e[5]>>3);d=h+(h>>3)*(e[5]&7)}if(d>2145386496)K(1);var m=new G((t==1?p||d:t?0:d)+12);return m[0]=1,m[4]=4,m[8]=8,{b:a+f,y:0,l:0,d:l,w:t&&t!=1?t:m.subarray(12),e:d,o:new je(m.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return cn(e,4)+8;K(0)},Ee=function(e){var t=0;for(;1<<t<=e;++t);return t-1},De=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,c=-1,a=-1,u=-1,l=o,f=new sn(512+(o<<2)),p=new on(f,0,256),d=new $e(f,0,256),h=new $e(f,512,o),m=512+(o<<1),w=new G(f,m,o),b=new G(f,m+o);while(c<255&&i>0){var g=Ee(i+1),y=r>>3,A=(1<<g+1)-1,v=(e[y]|e[y+1]<<8|e[y+2]<<16)>>(r&7)&A,M=(1<<g)-1,z=A-i-1,E=v&M;if(E<z)r+=g,v=E;else if(r+=g+1,v>M)v-=z;if(p[++c]=--v,v==-1)i+=v,w[--l]=c;else i-=v;if(!v)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)K(0);var x=0,U=(o>>1)+(o>>3)+3,k=o-1;for(var I=0;I<=c;++I){var F=p[I];if(F<1){d[I]=-F;continue}for(u=0;u<F;++u){w[x]=I;do x=x+U&k;while(x>=l)}}if(x)K(0);for(u=0;u<o;++u){var C=d[w[u]]++,j=b[u]=s-Ee(C);h[u]=(C<<j)-o}return[r+7>>3,{b:s,s:w,n:b,t:h}]},fn=function(e,t){var n=0,r=-1,s=new G(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),a=new $e(s.buffer,268);if(o<128){var u=De(e,t+1,6),l=u[0],f=u[1];t+=o;var p=l<<3,d=e[t];if(!d)K(0);var h=0,m=0,w=f.b,b=w,g=(++t<<3)-8+Ee(d);for(;;){if(g-=w,g<p)break;var y=g>>3;if(h+=(e[y]|e[y+1]<<8)>>(g&7)&(1<<w)-1,i[++r]=f.s[h],g-=b,g<p)break;y=g>>3,m+=(e[y]|e[y+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=f.s[m],w=f.n[h],h=f.t[h],b=f.n[m],m=f.t[m]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var A=e[++t];i[n]=A>>4,i[n+1]=A&15}++t}var v=0;for(n=0;n<r;++n){var M=i[n];if(M>11)K(0);v+=M&&1<<M-1}var z=Ee(v)+1,E=1<<z,D=E-v;if(D&D-1)K(0);i[r++]=Ee(D)+1;for(n=0;n<r;++n){var M=i[n];++c[i[n]=M&&z+1-M]}var x=new G(E<<1),U=x.subarray(0,E),k=x.subarray(E);a[z]=0;for(n=z;n>0;--n){var I=a[n];Be(k,n,I,a[n-1]=I+c[n]*(1<<z-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var F=i[n];if(F){var C=a[F];Be(U,n,C,a[F]=C+(1<<z-F))}}return[t,{n:k,b:z,s:U}]},pn=De(new G([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],mn=De(new G([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],hn=De(new G([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],xt=function(e,t){var n=e.length,r=new je(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Qe=new G(new je([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),gn=xt(Qe,0),qe=new G(new je([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),dn=xt(qe,3),Re=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)K(0);var a=0,u=n.b,l=(r<<3)-8+Ee(o)-u,f=-1;for(;l>c&&f<s;){var p=l>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(l&7);a=(a<<u|d)&i,t[++f]=n.s[a],l-=u=n.n[a]}if(l!=c||f+1!=s)K(0)},bn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;Re(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Re(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Re(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),Re(e.subarray(r),t.subarray(c),n)},yn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Be(n,e[s],t.y,t.y+=c),n;return Be(new G(c),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=c,n;return Je(e,s,a)}if(i==2){var u=e[s],l=u&3,f=u>>2&3,p=u>>4,d=0,h=0;if(l<2)if(f&1)p|=e[++s]<<4|(f&2&&e[++s]<<12);else p=u>>3;else if(h=f,f<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(f==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 m=n?n.subarray(t.y,t.y+t.m):new G(t.m),w=m.length-p;if(l==0)m.set(e.subarray(s,s+=p),w);else if(l==1)Be(m,e[s++],w);else{var b=t.h;if(l==2){var g=fn(e,s);d+=s-(s=g[0]),t.h=b=g[1]}else if(!b)K(0);(h?bn:Re)(e.subarray(s,s+=d),m.subarray(w),b)}var y=e[s++];if(y){if(y==255)y=(e[s++]|e[s++]<<8)+32512;else if(y>127)y=y-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var v=[mn,hn,pn];for(var M=2;M>-1;--M){var z=A>>(M<<1)+2&3;if(z==1){var E=new G([0,0,e[s++]]);v[M]={s:E.subarray(2,3),n:E.subarray(0,1),t:new $e(E.buffer,0,1),b:0}}else if(z==2)r=De(e,s,9-(M&1)),s=r[0],v[M]=r[1];else if(z==3){if(!t.t)K(0);v[M]=t.t[M]}}var D=t.t=v,x=D[0],U=D[1],k=D[2],I=e[a-1];if(!I)K(0);var F=(a<<3)-8+Ee(I)-k.b,C=F>>3,j=0,de=(e[C]|e[C+1]<<8)>>(F&7)&(1<<k.b)-1;C=(F-=U.b)>>3;var be=(e[C]|e[C+1]<<8)>>(F&7)&(1<<U.b)-1;C=(F-=x.b)>>3;var me=(e[C]|e[C+1]<<8)>>(F&7)&(1<<x.b)-1;for(++y;--y;){var le=k.s[de],Te=k.n[de],Me=x.s[me],Le=x.n[me],ve=U.s[be],ce=U.n[be];C=(F-=ve)>>3;var Ce=1<<ve,ue=Ce+((e[C]|e[C+1]<<8|e[C+2]<<16|e[C+3]<<24)>>>(F&7)&Ce-1);C=(F-=qe[Me])>>3;var O=dn[Me]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<qe[Me])-1);C=(F-=Qe[le])>>3;var T=gn[le]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<Qe[le])-1);if(C=(F-=Te)>>3,de=k.t[de]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Te)-1),C=(F-=Le)>>3,me=x.t[me]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Le)-1),C=(F-=ce)>>3,be=U.t[be]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<ce)-1),ue>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=ue-=3;else{var Y=ue-(T!=0);if(Y){if(ue=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=ue}else ue=t.o[0]}for(var M=0;M<T;++M)m[j+M]=m[w+M];j+=T,w+=T;var J=j-ue;if(J<0){var H=-J,oe=t.e+J;if(H>O)H=O;for(var M=0;M<H;++M)m[j+M]=t.w[oe+M];j+=H,O-=H,J=0}for(var M=0;M<O;++M)m[j+M]=m[J+M];j+=O}if(j!=w)while(w<m.length)m[j++]=m[w++];else j=m.length;if(n)t.y+=j;else m=Je(m,0,j)}else if(n){if(t.y+=p,w)for(var M=0;M<p;++M)m[M]=m[w+M]}else if(w)m=Je(m,w);return t.b=a,m}K(2)},xn=function(e,t){if(e.length==1)return e[0];var n=new G(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 Ve(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=un(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 c=yn(e,i,t);if(!c)K(5);if(t)i.e=i.y;else n.push(c),o+=c.length,an(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return xn(n,o)}async function wn(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(Ve(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 wt(e){return new TextDecoder().decode(await wn(e))}var At=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\").replace(/\\.(zst|gz)$/i,\"\")||\"main.ldr\";function _e(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 Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\"),tt=/^[A-Za-z][A-Za-z0-9_]*$/,et=new Map;function nt(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(!et.has(r))et.set(r,t);return r}function rt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&tt.test(e))return nt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,An=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),Mn=new Set([\"FILE\",\"NOFILE\",\"!DATA\"]),Pt=1000000000000000,It=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),vn=new Set([\"model\",\"submodel\",\"configuration\"]),Cn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function vt(e){let t=Cn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return It.has(n)||vn.has(n)?n:void 0}function kn(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 Tn(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((f)=>Number.isFinite(f)&&Math.abs(f)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let f=0;f<s;f++)c=c.replace(/^\\S+\\s*/,\"\");let a=kn(c);if(!a.length)return null;let u={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)u.a=i[9];if(s===11)u.b=i[10];let l=a.findIndex((f,p)=>p>0&&f.toUpperCase()===\"GLOSSMAP\");if(l>0&&a[l+1])u.glossmap=a[l+1];if(t)u.next=!0;return u}var Ln=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\");if(t.length%4===1)t=t.slice(0,-1);let 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 Sn(e,t){let n=e.length,r=1,s=(h)=>h===32||h===9,o=()=>{while(r<n&&s(e.charCodeAt(r)))r++;let h=r,m=e.charCodeAt(r),w=m===45;if(w)m=e.charCodeAt(++r);let b=0,g=0;while(m>=48&&m<=57)b=b*10+(m-48),g++,m=e.charCodeAt(++r);if(g>0&&g<=15&&(r>=n||s(m)))return w?-b:b;while(r<n&&!s(e.charCodeAt(r)))r++;return h<r?+e.slice(h,r):NaN};while(r<n&&s(e.charCodeAt(r)))r++;let i=r;if(r>=n)return null;let c=e.charCodeAt(r),a=c===45,u=0,l=0;if(a)c=e.charCodeAt(++r);while(c>=48&&c<=57)u=u*10+(c-48),l++,c=e.charCodeAt(++r);if(l>0&&l<=15&&(r>=n||s(c))){if(a)u=-u}else{while(r<n&&!s(e.charCodeAt(r)))r++;u=rt(e.slice(i,r))}let f=Array(12);for(let h=0;h<12;h++){let m=o();if(!Number.isFinite(m))return null;f[h]=m}while(r<n&&s(e.charCodeAt(r)))r++;if(r>=n)return null;let p=e.slice(r),d=t.get(p);if(d===void 0)d=Z(/[ \\t]{2,}|\\t/.test(p)?p.split(/\\s+/).join(\" \"):p),t.set(p,d);if(!Number.isFinite(u))return null;return{t:1,color:u,m:f,file:d}}var En=[0,12,6,9,12,12];function Ct(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=rt(e[1]),r=En[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Z(e.slice(14).join(\" \"));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Ft(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,s=new Map,o=null,i=\"\",c,a=null,u=[],l=null,f=()=>{if(!a)return;let y=Ln(a.chunks.join(\"\")),A=y[0]===137&&y[1]===80&&y[2]===78&&y[3]===71;(c??=new Map).set(Z(a.name),{name:a.name,bytes:y,...A?{mime:\"image/png\"}:{}}),a=null},p=new Map,d=!0,h=(y)=>{if(f(),o={name:Z(y),cmds:[]},s.set(o.name,o),!i)i=o.name;u=[],l=null,d=!0},m=!1,w=!1,b=()=>{if(w)return;w=!0,s.clear(),o=null,i=\"\"},g=(y,A)=>{if(l){y.tex=l,l=null;return}let v=u[u.length-1];if(!v)return;if(v.fallback){if(!A)y.fallback=!0}else y.tex=v.map};for(let y of e.split(`\n`)){let A=y.trim();if(!A)continue;if(r&&A.charCodeAt(0)>=50&&A.charCodeAt(0)<=53&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)){if(a||m)continue;if(!o)h(t);let E=A.slice(2).trimStart(),D=E.search(/\\s/),x={t:A.charCodeAt(0)-48,color:rt(D<0?E:E.slice(0,D)),p:[],src:A};g(x,!1),o.cmds.push(x),d=!1;continue}if(A.charCodeAt(0)===48&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)){let E=2;while(A.charCodeAt(E)===32||A.charCodeAt(E)===9)E++;let D=E;while(D<A.length&&A.charCodeAt(D)!==32&&A.charCodeAt(D)!==9)D++;let x=A.slice(E,D),U=/[^\\x21-\\x7e]/.test(x)?A.slice(E).trim().split(/\\s+/)[0]:x;if(!An.has(U)&&!(U.length>=4&&U.length<=6&&Mn.has(U.toUpperCase()))){if(m||a)continue;if(!o)h(t);let k=A.slice(E),I={t:0,text:k};if(x.charCodeAt(0)===33)I.meta=x;if(l=null,d&&!o.org){let C=vt(k);if(C)o.org=C}let F=k.match(Mt);if(F&&!o.movedTo){let C=F[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=\".dat\";o.movedTo=Z(C)}o.cmds.push(I);continue}}if(A.charCodeAt(0)===49&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)&&!a&&!m){let E=Sn(A,p);if(E){if(!o)h(t);g(E,!1),o.cmds.push(E),d=!1;continue}}let v=A.split(/\\s+/);if(+v[0]===0){let E=A.slice(1).trim(),D=v.length>1&&v[1].length>=4&&v[1].length<=6?v[1].toUpperCase():v[1];if(D===\"FILE\"){let k=E.slice(5).trimStart().split(\"\\r\")[0].trim();if(k){b(),m=!1,h(k);continue}}if(D===\"NOFILE\"){f(),o=null,m=!0;continue}if(D===\"!DATA\"){b(),f(),o=null,m=!1,a={name:E.slice(5).trim(),chunks:[]};continue}if(m)continue;if(a){if(v[1]===\"!:\")a.chunks.push(v.slice(2).join(\"\"));continue}if(!o)h(t);let x={t:0,text:E};if(v[1]===\"STEP\")x.step=!0,u=[],l=null;else if(v[1]===\"BFC\")x.bfc=v.slice(2).join(\" \");else if(v[1]===\"ROTSTEP\")if(x.meta=\"ROTSTEP\",x.step=!0,u=[],l=null,(v[2]??\"\").toUpperCase()===\"END\")x.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let k=(v[5]??\"REL\").toUpperCase(),I=(F)=>{let C=Number(F);return Number.isFinite(C)?C:0};x.rotstep={x:I(v[2]),y:I(v[3]),z:I(v[4]),mode:[\"REL\",\"ABS\",\"ADD\"].includes(k)?k:\"REL\"}}else if(v[1]===\"BUFEXCHG\"){x.meta=\"BUFEXCHG\";let k=(v[2]??\"\").toUpperCase();x.bufexchg={op:k===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:v[3]??\"A\"}}else if(v[1]?.startsWith(\"!\"))x.meta=v[1];if(d&&!o.org){let k=vt(E);if(k)o.org=k}if(v[1]===\"!TEXMAP\"){let k=(v[2]??\"\").toUpperCase();if(l=null,k===\"START\"||k===\"NEXT\"){let I=Tn(E.replace(/^!TEXMAP\\s+\\S+/i,\"\"),k===\"NEXT\");if(x.texmap={op:k,...I?{map:I}:{}},I)if((o.texmaps??=[]).push(I),k===\"START\")u.push({map:I,fallback:!1});else l=I}else if(k===\"FALLBACK\"){x.texmap={op:k};let I=u[u.length-1];if(I)I.fallback=!0}else if(k===\"END\")x.texmap={op:k},u.pop()}else if(v[1]===\"!:\"){l=null;let k=Ct(v.slice(2));if(k)g(k,!0),x.geom=k}else l=null;let U=E.match(Mt);if(U&&!o.movedTo){let k=U[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(k))k+=\".dat\";o.movedTo=Z(k)}o.cmds.push(x);continue}if(a||m)continue;if(!o)h(t);let z=Ct(v);if(!z){if(/^[2-5][ \\t]/.test(A))d=!1;continue}g(z,!1),o.cmds.push(z),d=!1}return f(),c?{main:i,files:s,data:c}:{main:i,files:s}}var sr=Math.PI/180;function Rt(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 Bt(e,t){let[n,r,s,o,i,c,a,u,l,f,p,d]=e,[h,m,w,b,g,y,A,v,M,z,E,D]=t;return[o*h+i*m+c*w+n,a*h+u*m+l*w+r,f*h+p*m+d*w+s,o*b+i*A+c*z,o*g+i*v+c*E,o*y+i*M+c*D,a*b+u*A+l*z,a*g+u*v+l*E,a*y+u*M+l*D,f*b+p*A+d*z,f*g+p*v+d*E,f*y+p*M+d*D]}var Ge=[0,0,0,1,0,0,0,1,0,0,0,1];var kt=new WeakMap,Pn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Z(t));if(!n)return\"part\";let r=kt.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&&Pn.test(s.file))?\"part\":\"model\";return kt.set(n,r),r}var Tt=new WeakMap;function Dt(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 Lt=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():e<0?et.get(e)??String(e):String(e),In=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${Lt(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${Lt(e.color)} ${e.p.join(\" \")}`,ot=(e,t)=>`${Z(e)}#${t}`;function Fn(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:ot(e.name,t),cmds:n}}function Ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Fn(e,t).cmds.map(In)].join(`\n`)+`\n`}function it(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 Nt(e){let[t,n,r,s,o,i,c,a,u,l,f,p]=e,d=a*p-u*f,h=-(c*p-u*l),m=c*f-a*l,w=s*d+o*h+i*m;if(!Number.isFinite(w)||Math.abs(w)<0.000000000001)return null;let b=1/w,g=[d*b,-(o*p-i*f)*b,(o*u-i*a)*b,h*b,(s*p-i*l)*b,-(s*u-i*c)*b,m*b,-(s*f-o*l)*b,(s*a-o*c)*b];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 Rn=(e)=>String(+e.toFixed(6)||0),St=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function Ot(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map(Rn).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 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${it(r)}`,source:r}}var Bn=(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 Dn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),u=Math.cos(n*r);return[c*u,-c*a,i,o*a+s*i*u,o*u-s*i*a,-s*c,s*a-o*i*u,s*u+o*i*a,o*c]}var Et=new WeakMap;function zt(e){let t=Et.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=Dn(o.x,o.y,o.z);r=o.mode===\"ABS\"?{abs:!0,m:i,rotstep:o}:o.mode===\"ADD\"&&r?{abs:r.abs,m:Bn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Et.set(e,n),n}class at extends Error{limit;code=\"ldr-model-limit\";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString(\"en-US\")} (see maxInstances)`);this.limit=t;this.name=\"ModelLimitError\"}}var Un=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=Pt))return!1;return!0},$t=999999,_t=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\",Gt=new WeakMap,jt=new WeakMap;function Nn(e,t){let n=jt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Gt.get(o)??\"\",c=i.indexOf(\"!COLOUR\");return c<0?\"\":\"0 \"+i.slice(c).trim().replace(/\\s+/g,\" \")}).filter(Boolean).join(`\n`),parts:new Map},jt.set(t,n);let r=n.parts.get(e);if(!r){let s=Z(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-${it(o)}`,source:o},n.parts.set(e,r)}return r}function On(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,a=0,u=[],l=(w,b)=>{if(w.length)return[...w,b];let g=u[b];if(!g)u[b]=g=[b];return g},f=new Set,p=t.maxInstances??2000000,d=0,h=(w,b)=>{let g=w.name+\"#\"+b,y=c.get(g);if(!y){let A;y=Object.assign(()=>A??=Ut(w,b),{file:w,step:b}),c.set(g,y)}return y},m=(w,b,g,y,A,v,M,z,E=null,D=[],x=[],U=void 0,k=null)=>{let I=w.files.get(b);if(!I||M>r||f.has(I))return;if(++d>p)throw new at(\"model\",p);f.add(I);let F=k,C=0,j=M>0?++a:0,de=i&&j?[...D,j]:D,be=i&&j?[...x,g]:x,me=i&&!E?new Map:null,le=-1,Te=0,Me=(O,T,Y,J,H,oe,L)=>{if(le!==C)le=C,Te=0;let B=me?.get(C+\"|\"+T);if(B)return B.n++,m(O,O===w?T:O.main,Y,J,A+\"/\"+T,[...H,$t],M+1,oe,[...H,$t],de,be,L,F);let P=[...H,Te++],R=n.length;m(O,O===w?T:O.main,Y,J,A+\"/\"+T,P,M+1,oe,E,de,be,L,F),me?.set(C+\"|\"+T,{n:1,from:R,to:n.length})},Le=zt(I),ve=s?Dt(I):[],ce=0,Ce=(O,T,Y,J,H,oe,L,B,P)=>{if(E)J=E;if(++d>p)throw new at(\"model\",p);let R={part:O,color:T,m:Y,step:J[0],steps:J,localStep:H,path:A};if(B)R.colour=B;if(j){if(R.sub=j,i)R.subPath=de,R.subMats=be}if(oe)R.embedded=!0;if(L){let N=Ot(O,L);R.texPart=N.name,R.texSource=N.source}else if(P){let N=Nn(O,P);R.colPart=N.name,R.colSource=N.source}let S=Le[H];if(S)R.view=S;return n.push(R),R},ue=(O)=>{while(ce<ve.length&&ve[ce]<=O){let T=ve[ce++];Ce(ot(I.name,T),y,g,l(v,T),T,!1,null,U,k).source=h(I,T)}};for(let O of I.cmds){if(O.t===0&&O.step){C++;continue}let T=O;if(T.t>=2||T.t===0&&T.geom&&T.geom.t>=2){ue(C);continue}if(T.t===0){if(T.meta===\"!COLOUR\"){let S=$n(T.text);if(S&&S.code!==16&&S.code!==24)Gt.set(S,T.text),(F=new Map(F??[])).set(S.code,S);continue}if(o&&T.geom?.t===1)T=T.geom;else continue}if(T.t!==1)continue;if(o&&T.fallback)continue;let Y=g===Ge?T.m:Bt(g,T.m);if(!Un(Y))continue;let J=T.color===16?y:T.color,H=T.color===16?U:F?.get(T.color),oe=l(v,C),L=o?T.tex??z:null,B=L?Nt(T.m):null,P=L&&B?Rt(L,B):null;if(w.files.has(T.file)){if(st(w,T.file)===\"model\"){Me(w,T.file,Y,J,oe,P,H);continue}Ce(T.file,J,Y,oe,C,!0,P,H,F);continue}let R=t.resolveModel?.(T.file);if(R){Me(R,T.file,Y,J,oe,P,H);continue}Ce(T.file,J,Y,oe,C,!1,P,H,F)}if(ue(1/0),f.delete(I),me){for(let O of me.values())if(O.n>1)for(let T=O.from;T<O.to;T++)n[T].mult??=O.n}};if(st(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Ge],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return m(e,e.main,Ge,16,e.main,[],0,null),n}function Ht(e,t=\"main.ldr\",n){return On(Ft(e,t,{geometryText:!0}),n)}var zn=new Set([\"CHROME\",\"PEARLESCENT\",\"RUBBER\",\"MATTE_METALLIC\",\"METAL\",\"MATERIAL\"]);function lt(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 Vt(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=lt(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 $n(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\",c=255,a=0,u={type:\"default\"},l=1;while(l<n.length){let f=n[l].toUpperCase(),p=n[l+1];if(f===\"CODE\")s=p!==void 0&&tt.test(p)?nt(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,l+=2;else if(f===\"VALUE\"){let d=lt(p);if(d)o=d;l+=2}else if(f===\"EDGE\")i=lt(p)??p,l+=2;else if(f===\"ALPHA\")c=+p,l+=2;else if(f===\"LUMINANCE\")a=+p,l+=2;else if(f===\"CHROME\")u={type:\"chrome\"},l+=1;else if(f===\"PEARLESCENT\")u={type:\"pearlescent\"},l+=1;else if(f===\"RUBBER\")u={type:\"rubber\"},l+=1;else if(f===\"MATTE_METALLIC\")u={type:\"matte_metallic\"},l+=1;else if(f===\"METAL\")u={type:\"metal\"},l+=1;else if(f===\"MATERIAL\"){let d=(n[l+1]||\"\").toUpperCase();if(d===\"GLITTER\"){let{grain:h,next:m}=Vt(n,l+2);u={type:\"glitter\",material:h},l=m}else if(d===\"SPECKLE\"){let{grain:h,next:m}=Vt(n,l+2);u={type:\"speckle\",material:h},l=m}else if(d===\"FABRIC\"){let h=(n[l+2]||\"\").toUpperCase(),m=[\"VELVET\",\"CANVAS\",\"STRING\",\"FUR\"].includes(h)?h.toLowerCase():void 0;u={type:\"fabric\",kind:m},l+=m?3:2}else l=n.length}else if(zn.has(f))l+=1;else l+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(a)?a:0,finish:u}}function jn(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,c=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:c,finish:\"glitter\"}}case\"speckle\":{let i=e.finish.material,c=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:c,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 ct(e){let t=jn(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 Vn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Z(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Z(t),r)}let a=i.trim().replace(/\\s+/g,\" \");if(a)r.push(a)}return n}var _n=(e)=>{if(!e.startsWith(\"1 \"))return null;let t=e.split(\" \");return t.length>=15?Z(t.slice(14).join(\" \")):null};function Gn(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 Wt(e,t,n=\"main.ldr\"){let r=[...t],s=new Map;if(!r.length)return s;let o=Vn(e,n);for(let i of r){let c=Z(i);if(!o.has(c)||s.has(c))continue;let a=new Set([c]),u=[c];while(u.length)for(let f of o.get(u.pop())){let p=_n(f);if(p&&o.has(p)&&!a.has(p))a.add(p),u.push(p)}let l=[c,...[...a].filter((f)=>f!==c).sort()].map((f)=>\"0 FILE \"+(f===c?\"\":f)+`\n`+o.get(f).join(`\n`)).join(`\n`);s.set(c,`emb/${Gn(l)}.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,Kt=new WeakMap,ut=null,ft=\"\",pt=null;function Hn(e,t){if(e===ut&&t===ft)return pt;let n=Kt.get(e);if(!n)Kt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return ut=e,ft=t,pt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],a=[];s.studs.forEach((d,h)=>{c.push(d[0]),a.push(d[1]);for(let m=0;m<12;m++)i[h*12+m]=d[2+m]});let u=null,l=0,f=0;if(s.mask){l=s.mask[0],f=s.mask[1];let d=s.mask[2];u=new Uint8Array(d.length);for(let h=0;h<d.length;h++)u[h]=d.charCodeAt(h)===49?1:0}let p=!!u;if(u){for(let d=0;d<u.length;d++)if(u[d]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:a,mask:u,nx:l,nz:f,full:p}),ut=e,ft=t,pt=r,r}var Ie=1073741824;class Pe{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=Pe.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let a=s[c];if(a===0)return-1;if(a===r){let u=c<<2;if(o[u]===e&&o[u+1]===t&&o[u+2]===n)return o[u+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=Pe.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,a=this.slot(e,t,n);for(;;){let u=o[a],l=a<<2;if(u===0)return o[a]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(u===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let f=i[l+3];return i[l+3]=r,f}a=a+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Yt{grp=new Pe(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],a=[];for(let f=0;f<r;f++){let p=e[f],d=t[f],h=n[f],m=(p%20+20)%20,w=(h%20+20)%20,b=this.group(d,m,w);if(b<0)b=s.length,this.grp.put(d,m,w,b),this.lg=b,s.push(0),o.push(p),i.push(p),c.push(h),a.push(h);if(s[b]++,p<o[b])o[b]=p;else if(p>i[b])i[b]=p;if(h<c[b])c[b]=h;else if(h>a[b])a[b]=h}let u=0,l=0;for(let f=0;f<s.length;f++){let p=(i[f]-o[f])/20+1,d=(a[f]-c[f])/20+1,h=p*d;if(this.gX0.push(o[f]),this.gZ0.push(c[f]),this.gNx.push(p),this.gNz.push(d),h<=64*s[f]+1024&&u+h<2147483648)this.gBits.push(u),u+=h;else this.gBits.push(-1),l+=s[f]}this.bits=new Uint8Array(Math.ceil(u/8)),this.rest=new Pe(l);for(let f=0;f<r;f++){let p=e[f],d=t[f],h=n[f],m=this.group(d,(p%20+20)%20,(h%20+20)%20),w=this.gBits[m];if(w<0){this.rest.put(p,d,h,1);continue}let b=w+(p-this.gX0[m])/20*this.gNz[m]+(h-this.gZ0[m])/20;this.bits[b>>>3]|=1<<(b&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Wn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Fe=(e,t,n)=>e>-Ie&&e<Ie&&t>-Ie&&t<Ie&&n>-Ie&&n<Ie,Ue=2147483647;function Xn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function mt(e,t,n){return Zt(e,t,n,-1)??Zt(e,t,n,Jt)}var Jt=0;function Zt(e,t,n,r){let o=new Map,i=(L)=>{let B=o.get(L);if(B===void 0)o.set(L,B=Xn(t,L));return B},c=e.length,a=0,u=0,l=0,f=Array(c);for(let L=0;L<c;L++){let B=f[L]=Hn(t,e[L].part);if(B){if(l+=B.nStuds,B.mask)a++}}let p=new Float64Array(a),d=new Float64Array(a),h=new Float64Array(a),m=new Float64Array(a),w=new Int32Array(a),b=new Int32Array(a),g=new Float64Array(a),y=new Float64Array(a),A=[],v=new Int32Array(a),M=new Float64Array(a*9),z=new Uint8Array(a);if(r<0)r=a*4+64;let E=new Pe(e.length*2),D=new Int32Array(r),x=new Int32Array(r),U=0,k=0;for(let L=0;L<e.length;L++){let B=e[L],P=B.m,R=t.parts[B.part];if(!R||!R.mask||!Xt(P)||i(B.color))continue;let S=R.bbox,N=1/0,V=-1/0,q=1/0,W=-1/0;for(let X=0;X<2;X++)for(let ie=0;ie<2;ie++){let ee=X?S[3]:S[0],Se=ie?S[5]:S[2],Ae=P[0]+P[3]*ee+P[5]*Se,ge=P[2]+P[9]*ee+P[11]*Se;if(Ae<N)N=Ae;if(Ae>V)V=Ae;if(ge<q)q=ge;if(ge>W)W=ge}let _=Math.round((P[1]+S[4])*2),Q=f[L],ae=Math.floor(N/40),ye=Math.floor(V/40),xe=Math.floor(q/40),we=Math.floor(W/40);if(!((ye-ae+1)*(we-xe+1)<=65536)||!Fe(_,ae,xe)||!Fe(_,ye,we))continue;let he=Math.floor((N+5)/40),te=Math.floor((V-5)/40),ne=Math.floor((q+5)/40),re=Math.floor((W-5)/40),ke=he<=te&&ne<=re?(te-he+1)*(re-ne+1):0;k+=ke;let fe=-1;for(let X=he<=te&&ne<=re?E.get(_,he,ne):-1,ie=0;X>=0&&ie<8;X=D[X],ie++){let ee=x[X];if(p[ee]!==N||d[ee]!==V||h[ee]!==q||m[ee]!==W||A[ee]!==Q)continue;let Se=e[w[ee]].m,Ae=!0;for(let ge=0;ge<12;ge++)if(Se[ge]!==P[ge]){Ae=!1;break}if(Ae){fe=ee;break}}if(fe>=0){let X=n?n[L]:0;if(n&&X<n[w[fe]])b[fe]=w[fe],w[fe]=L;else if(b[fe]<0||n&&X<n[b[fe]])b[fe]=L;continue}let se=u++;p[se]=N,d[se]=V,h[se]=q,m[se]=W,w[se]=L,b[se]=-1,A.push(Q),g[se]=S[0],y[se]=S[2],v[se]=_;let pe=se*9;if(M[pe]=P[0],M[pe+1]=P[1],M[pe+2]=P[2],M[pe+3]=P[3],M[pe+4]=P[6],M[pe+5]=P[9],M[pe+6]=P[5],M[pe+7]=P[8],M[pe+8]=P[11],z[se]=Q.full&&S[3]-S[0]<=20*Q.nx&&S[5]-S[2]<=20*Q.nz&&P[4]===0&&P[6]===0&&P[8]===0&&P[10]===0&&Wn(P[3],P[5],P[9],P[11])?1:0,U+ke>r){U=r+1;continue}for(let X=he;X<=te;X++)for(let ie=ne;ie<=re;ie++){if(!Fe(_,X,ie))continue;let ee=U++;x[ee]=se,D[ee]=E.put(_,X,ie,ee)}}if(U>r)return Jt=k,null;let I=[0,5,-5,5,-5],F=[0,5,5,-5,-5],C=(L,B,P,R)=>{if(!(B-6>=p[L]-0.5&&B+6<=d[L]+0.5&&R-6>=h[L]-0.5&&R+6<=m[L]+0.5))return!1;if(z[L]===1)return!0;let S=L*9,N=A[L],V=g[L],q=y[L],W=B-M[S],_=P-M[S+1],Q=R-M[S+2],ae=M[S+3]*W+M[S+4]*_+M[S+5]*Q,ye=M[S+6]*W+M[S+7]*_+M[S+8]*Q,{nx:xe,nz:we,mask:he}=N;for(let te=0;te<5;te++){let ne=Math.floor((ae+I[te]-V)/20),re=Math.floor((ye+F[te]-q)/20);if(ne<0||re<0||ne>=xe||re>=we||he[ne*we+re]!==1)return!1}return!0},j=NaN,de=NaN,be=NaN,me=-1,le=-1,Te=(L,B,P,R)=>{let S=Math.round(B*2),N=Math.floor(L/40),V=Math.floor(P/40);if(!Fe(S,N,V))return Ue;let q=Ue;if(!n&&le>=0&&v[le]===S&&(w[le]!==R||b[le]>=0)&&C(le,L,B,P))return 0;if(S!==j||N!==de||V!==be)j=S,de=N,be=V,me=E.get(S,N,V);for(let W=me;W>=0;W=D[W]){let _=x[W],Q=w[_];if(Q===R&&(Q=b[_])<0)continue;if(!C(_,L,B,P))continue;if(!n)return le=_,0;let ae=n[Q];if(ae<q)q=ae}return q},Me=new Uint8Array(l),Le=new Uint8Array(l),ve=0,ce=n?new Pe(l,4):null,Ce=n?null:new Int32Array(l),ue=n?null:new Int32Array(l),O=n?null:new Int32Array(l),T=0,Y=n?new Int32Array(l).fill(Ue):void 0;for(let L=0,B=0;L<e.length;L++){let P=e[L],R=f[L];if(!R)continue;let S=P.m,N=R.studM,V=S[0],q=S[1],W=S[2],_=S[3],Q=S[4],ae=S[5],ye=S[6],xe=S[7],we=S[8],he=S[9],te=S[10],ne=S[11];for(let re=0;re<R.nStuds;re++,B++){let ke=re*12,fe=N[ke+4],se=N[ke+7],pe=N[ke+10];if(!(Math.abs(ye*fe+xe*se+we*pe-1)<0.001&&Math.abs(_*fe+Q*se+ae*pe)<0.001&&Math.abs(he*fe+te*se+ne*pe)<0.001))continue;Le[B]=1;let X=N[ke],ie=N[ke+1],ee=N[ke+2],Se=V+_*X+Q*ie+ae*ee,Ae=q+ye*X+xe*ie+we*ee,ge=W+he*X+te*ie+ne*ee,gt=Te(Se,Ae,ge,L);if(gt!==Ue){if(Me[B]=1,ve++,Y)Y[B]=gt}let Ne=Math.round(Se),Oe=Math.round(Ae),ze=Math.round(ge);if(!Fe(Ne,Oe,ze))continue;if(!ce){Ce[T]=Ne,ue[T]=Oe,O[T++]=ze;continue}let dt=n[L],bt=ce.get(Ne,Oe,ze);if(bt<0||dt<bt)ce.put(Ne,Oe,ze,dt)}}let J=ce?null:new Yt(Ce,ue,O,T),H=new Uint8Array(e.length),oe=n?new Int32Array(e.length).fill(Ue):void 0;for(let L=0;L<e.length;L++){let B=e[L],P=t.parts[B.part];if(!P||!P.under||!Xt(B.m)||i(B.color))continue;let R=P.bbox,S=Math.round((R[3]-R[0])/20),N=Math.round((R[5]-R[2])/20);if(!S||!N||S*N>4096)continue;let V=B.m,q=Math.round(V[1]+R[4]),W=!0,_=0;for(let Q=0;Q<S&&W;Q++)for(let ae=0;ae<N;ae++){let ye=R[0]+10+20*Q,xe=R[2]+10+20*ae,we=V[0]+V[3]*ye+V[5]*xe,he=V[2]+V[9]*ye+V[11]*xe,te=Math.round(we),ne=Math.round(he),re=!Fe(te,q,ne)?-1:ce?ce.get(te,q,ne):J.has(te,q,ne)?1:-1;if(re<0){W=!1;break}if(re>_)_=re}if(W){if(H[L]=1,oe)oe[L]=_}}return{nStuds:l,studHidden:Me,studUp:Le,underHidden:H,studsHidden:ve,studHideStep:Y,underHideStep:oe}}function ht(e,t,n){let r=(l)=>l.colPart&&t.parts[l.colPart]?l.colPart:n&&l.texPart&&t.parts[l.texPart]?l.texPart:l.part,s=new Map,o=new Map,i=(l)=>{let f=l.colour;if(!f)return String(l.color);let p=o.get(f);if(p!==void 0)return p;let d=t.colorTable?.[l.color],h=d?.hex??t.colors?.[l.color],m=d?ct({alpha:d.alpha??255,luminance:d.luminance??0,finish:d.finish??{type:\"default\"}}):\"default:op\",w=ct(f);if(p=h&&h.toUpperCase()===f.hex.toUpperCase()&&m===w?String(l.color):f.hex.toUpperCase()+\"/\"+w,p!==String(l.color))s.set(p,f);return o.set(f,p),p},c=e.map((l)=>({part:r(l),color:i(l),m:l.m,steps:l.steps})),{stepOf:a,nSteps:u}=Kn(c);return{all:c,stepOf:a,nSteps:u,localColours:s}}function Kn(e){let t=!0;for(let o=0;o<e.length;o++){let i=e[o].steps;if(i.length!==1){t=!1;break}let c=i[0];if(!(Number.isInteger(c)&&c>=0&&c<1e6)){t=!1;break}}if(t){let o=new Set;for(let a=0;a<e.length;a++)o.add(e[a].steps[0]);let i=[...o].sort((a,u)=>a-u),c=new Map(i.map((a,u)=>[a,u]));return{stepOf:e.map((a)=>c.get(a.steps[0])),nSteps:i.length}}let n=e.map((o)=>_t(o.steps)),r=[...new Set(n)].sort(),s=new Map(r.map((o,i)=>[o,i]));return{stepOf:n.map((o)=>s.get(o)),nSteps:r.length}}function Qt(e,t,n=!0){let r=ht(e,t,n);return mt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ze=\"https://ldr-parts-cdn.baconbrix.workers.dev/v1/\",We=new Map,He=new Map;function Xe(e=Ze,t=fetch){let n=We.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(()=>We.delete(e)),We.set(e,n);return n}var Zn=(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\"),Ke=(e,t)=>Zn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ke(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ke(r,t)])):e;function Yn(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 h=new DataView(d).getUint32(0,!0),m=new Uint8Array(d,4+h),w=r;n.push(m),r+=m.byteLength;let b=(4-r%4)%4;if(b)n.push(new Uint8Array(b)),r+=b;for(let[g,y]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ke(y,w);for(let[g,y]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ke(y,w)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+c.length)%4)%4,u=4+c.length+a,l=new Uint8Array(u+r);new DataView(l.buffer).setUint32(0,c.length+a,!0),l.set(c,4),l.fill(32,4+c.length,u);let f=u;for(let p of n)l.set(p,f),f+=p.byteLength;return _e(l.buffer)}async function Jn(e,t={}){e=[...e];try{return await qt(e,t)}catch(n){let r=t.cdn??Ze,s=t.fetch??fetch;We.delete(r);let o=(i,c)=>s(i,{...c,cache:\"reload\"});try{return await qt(e,{...t,fetch:o})}catch{throw n}}}async function qt(e,t){let n=t.cdn??Ze,r=t.fetch??fetch,s=t.gap??16384,o=await Xe(n,r),i=[...new Set([...new Set(e)].map(Z))],c=[],a=[];for(let g of i){if(He.has(n+g))continue;let y=o.parts[g];if(y)a.push({name:g,off:y[0],len:y[1],file:y[2]??0});else c.push(g)}a.sort((g,y)=>g.file-y.file||g.off-y.off);let u=[];for(let g of a){let y=u[u.length-1];if(y&&y.file===g.file&&g.off-y.end<=s)y.end=Math.max(y.end,g.off+g.len),y.items.push(g);else u.push({file:g.file,start:g.off,end:g.off+g.len,items:[g]})}let l=0,f=0,p=0,d=new Map,h=async()=>{while(p<u.length){let g=u[p++],y=d.get(g.file);if(y)y=y.subarray(g.start,g.end);else{let A=await r(new URL(o.archives[g.file],n).href,{headers:{Range:`bytes=${g.start}-${g.end-1}`,\"Accept-Encoding\":\"identity\"}});if(!A.ok)throw Error(`ldr: parts CDN ${A.status}`);if(f++,y=new Uint8Array(await A.arrayBuffer()),l+=y.byteLength,A.status===200)d.set(g.file,y),y=y.subarray(g.start,g.end)}for(let A of g.items){let v=Ve(y.subarray(A.off-g.start,A.off-g.start+A.len)),M=v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength);He.set(n+A.name,_e(M))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,u.length)},h));let m=i.filter((g)=>He.has(n+g)).map((g)=>He.get(n+g)),w={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:m.length?Yn(m,w):_e(Qn(w)),missing:c,requests:f,bytes:l}}function Qn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...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 qn(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 en(e,t,n){let r=0,s=0,o=!1,i=new Set,c=new Map;for(let a of e){let u;if(a.embedded)u=t.get(a.part);else if(u=c.get(a.part),u===void 0)c.set(a.part,u=Z(a.part));let l=u?n.parts[u]:void 0;if(!l)continue;if(l[3]!=null)o=!0,r+=l[3];if(!i.has(u))i.add(u),s+=l[1]}return{bodyTris:r,packBytes:s,known:o}}class Ye 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 tn(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Xe(t.cdn??Ze,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(x)=>{if(!x.ok)throw Error(`ldr: ${x.status} fetching ${e}`);return wt(await x.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?\"main.ldr\":At(e)),a=Ht(o,c,{looseGeometry:!1,callouts:t.callouts}),u=performance.now();t.onParsed?.(a),await s;let l=Wt(o,new Set(a.filter((x)=>x.embedded).map((x)=>x.part)),c),f=(x,U)=>t.maxBodyTris!=null&&x>t.maxBodyTris||t.maxPackBytes!=null&&U>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(x)=>new Ye({...x,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),h=\"full\";if(p){let x=en(a,l,await s);if(f(x.known?x.bodyTris:0,x.packBytes)){if(!t.lowCdn)throw d(x);let U=await Xe(t.lowCdn,r).catch(()=>null);if(!U)throw d(x);let k=en(a,l,U);if(f(k.known?k.bodyTris:0,k.packBytes))throw d(k);h=\"low\"}}let m=[...a.filter((x)=>!x.embedded).map((x)=>x.part),...l.values()],w=async()=>{let x=await Jn(m,h===\"low\"?{...t,cdn:t.lowCdn}:t);for(let[U,k]of l){let I=x.pack.header.parts[k];if(I)x.pack.header.parts[U]=I}return{...x,packBytes:x.pack.buffer?.byteLength??x.pack.bytes??0,bodyTris:qn(a,x.pack)}},b=await w();if(p&&f(b.bodyTris,b.packBytes)&&h===\"full\"&&t.lowCdn&&await Xe(t.lowCdn,r).then(()=>!0,()=>!1)){h=\"low\";let x=b;b=await w(),b.requests+=x.requests,b.bytes+=x.bytes}if(p&&f(b.bodyTris,b.packBytes))throw d(b);let{pack:g,missing:y,requests:A,bytes:v}=b,M=new Map([...l].map(([x,U])=>[U,x])),z=y.map((x)=>M.get(x)??x),E=performance.now(),D=t.cull?Qt(a,g.header,t.textures!==!1):void 0;return{insts:a,pack:g,tier:h,missing:z,requests:A,bytes:v,cull:D,timings:{fetchModel:i-n,parse:u-i,parts:E-u,...D?{cull:performance.now()-E}:{}}}}var er=new Set([\"part\",\"color\",\"m\",\"step\",\"steps\",\"localStep\",\"path\"]);function nn(e){let t=e.length,n=0;for(let h of e){if(typeof h.part!==\"string\"||typeof h.path!==\"string\"||typeof h.color!==\"number\"||typeof h.step!==\"number\"||typeof h.localStep!==\"number\"||!Array.isArray(h.m)||h.m.length!==12||!Array.isArray(h.steps))return null;n+=h.steps.length}let r=[],s=new Map,o=(h)=>{let m=s.get(h);if(m===void 0)s.set(h,m=r.length),r.push(h);return m},i=new Uint32Array(t),c=new Uint32Array(t),a=new Float64Array(t*3),u=new Float64Array(t*12),l=new Uint32Array(t+1),f=new Float64Array(n),p=[],d=0;for(let h=0;h<t;h++){let m=e[h];i[h]=o(m.part),c[h]=o(m.path),a[h*3]=m.color,a[h*3+1]=m.step,a[h*3+2]=m.localStep;let w=m.m,b=h*12;for(let A=0;A<12;A++)u[b+A]=w[A];let g=m.steps;for(let A=0;A<g.length;A++)f[d++]=g[A];l[h+1]=d;let y=null;for(let A in m)if(!er.has(A))(y??={})[A]=m[A];if(y)p.push([h,y])}return{n:t,strs:r,part:i,path:c,num:a,m:u,so:l,steps:f,extra:p}}var rn=(e)=>[e.part.buffer,e.path.buffer,e.num.buffer,e.m.buffer,e.so.buffer,e.steps.buffer];self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await tn(n,{...r,cull:!1,onParsed:(f)=>{let p=nn(f);if(p)self.postMessage({id:t,packed:p},rn(p));else 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(),c=ht(s.insts,s.pack.header,r.textures!==!1),a=mt(c.all,s.pack.header,r.stepCull&&c.nSteps>1?c.stepOf:void 0),u=performance.now()-i,l=[];for(let f of[a.studHidden,a.studUp,a.underHidden,a.studHideStep,a.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:a,ms:u},l)}catch(s){if(s instanceof Ye||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;
@@ -1,4 +1,4 @@
1
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/spec.ts
1
+ // ../../../../../../../tmp/ldr-build-s89ZOB/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;
@@ -833,7 +833,7 @@ function fileStepViews(f) {
833
833
  viewMemo.set(f, out);
834
834
  return out;
835
835
  }
836
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/model.ts
836
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/model.ts
837
837
  class ModelLimitError extends Error {
838
838
  limit;
839
839
  code = "ldr-model-limit";
@@ -883,6 +883,15 @@ function flatten(doc, opts = {}) {
883
883
  const loose = opts.looseGeometry !== false, tx = !!opts.textures, co = !!opts.callouts;
884
884
  const src = new Map;
885
885
  let subs = 0;
886
+ const stepSingles = [];
887
+ const stepPathOf = (path, s) => {
888
+ if (path.length)
889
+ return [...path, s];
890
+ let a = stepSingles[s];
891
+ if (!a)
892
+ stepSingles[s] = a = [s];
893
+ return a;
894
+ };
886
895
  const open = new Set;
887
896
  const maxN = opts.maxInstances ?? 2000000;
888
897
  let work = 0;
@@ -962,7 +971,7 @@ function flatten(doc, opts = {}) {
962
971
  const flushLoose = (upTo) => {
963
972
  while (li < ls.length && ls[li] <= upTo) {
964
973
  const k = ls[li++];
965
- emit(loosePartName(f.name, k), color, m, [...stepPath, k], k, false, null, colour, scope0).source = lazy(f, k);
974
+ emit(loosePartName(f.name, k), color, m, stepPathOf(stepPath, k), k, false, null, colour, scope0).source = lazy(f, k);
966
975
  }
967
976
  };
968
977
  for (const c0 of f.cmds) {
@@ -993,10 +1002,10 @@ function flatten(doc, opts = {}) {
993
1002
  continue;
994
1003
  if (tx && c.fallback)
995
1004
  continue;
996
- const mm = mul(m, c.m);
1005
+ const mm = m === I ? c.m : mul(m, c.m);
997
1006
  if (!inRange12(mm))
998
1007
  continue;
999
- const col = c.color === 16 ? color : c.color, cd = c.color === 16 ? colour : scope?.get(c.color), sp = [...stepPath, s];
1008
+ const col = c.color === 16 ? color : c.color, cd = c.color === 16 ? colour : scope?.get(c.color), sp = stepPathOf(stepPath, s);
1000
1009
  const tex = tx ? c.tex ?? texIn : null;
1001
1010
  const local = tex ? invert(c.m) : null;
1002
1011
  const lt = tex && local ? transformTexMap(tex, local) : null;
@@ -1274,7 +1283,7 @@ function blendedColourHex(code) {
1274
1283
  const a = LDRAW_EXE_16[code - 256 >> 4], b = LDRAW_EXE_16[code - 256 & 15];
1275
1284
  return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
1276
1285
  }
1277
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/instructions.ts
1286
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/instructions.ts
1278
1287
  var MIN_VIS = 0.5;
1279
1288
  var REORIENT = 0.35;
1280
1289
  var deg = Math.PI / 180;
@@ -1642,10 +1651,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
1642
1651
  }
1643
1652
  };
1644
1653
  }
1645
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/render.ts
1654
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/render.ts
1646
1655
  import * as THREE2 from "three";
1647
1656
 
1648
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/pack-io.ts
1657
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/pack-io.ts
1649
1658
  import { decompress } from "fzstd";
1650
1659
  async function decompressPack(data) {
1651
1660
  const u = data instanceof Uint8Array ? data : new Uint8Array(data);
@@ -1668,7 +1677,7 @@ function decodePack(buf) {
1668
1677
  return { header, arr, bytes: buf.byteLength, buffer: buf };
1669
1678
  }
1670
1679
 
1671
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/stud-decal.ts
1680
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/stud-decal.ts
1672
1681
  import * as THREE from "three";
1673
1682
  function studDecalUniforms(near = 0) {
1674
1683
  return { center: { value: new THREE.Vector3 }, near: { value: near } };
@@ -1767,7 +1776,7 @@ roughnessFactor = clamp(roughnessFactor * mix(1.0, sdTop > 0.5 ? 0.85 : 1.1, sdK
1767
1776
  return d;
1768
1777
  }
1769
1778
 
1770
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/cull.ts
1779
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/cull.ts
1771
1780
  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;
1772
1781
  var prepCache = new WeakMap;
1773
1782
  var lastH = null;
@@ -2349,7 +2358,7 @@ function precomputeCull(instances, H, useTex = true) {
2349
2358
  return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
2350
2359
  }
2351
2360
 
2352
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/render.ts
2361
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/render.ts
2353
2362
  async function loadPack(url) {
2354
2363
  const res = await fetch(url);
2355
2364
  if (!res.ok)
@@ -4887,7 +4896,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
4887
4896
  await new Promise((r) => setTimeout(r, 0));
4888
4897
  }
4889
4898
  }
4890
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/scene.ts
4899
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/scene.ts
4891
4900
  import * as THREE3 from "three";
4892
4901
  var _box = new THREE3.Box3;
4893
4902
  var _m4 = new THREE3.Matrix4;
@@ -5291,10 +5300,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
5291
5300
  return finish();
5292
5301
  })();
5293
5302
  }
5294
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/parts-cdn.ts
5303
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/parts-cdn.ts
5295
5304
  import { decompress as decompress2 } from "fzstd";
5296
5305
 
5297
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/embedded.ts
5306
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/embedded.ts
5298
5307
  function splitFiles(text, fallback) {
5299
5308
  const files = new Map;
5300
5309
  let cur = null, saw = false, skip = false;
@@ -5372,7 +5381,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
5372
5381
  return out;
5373
5382
  }
5374
5383
 
5375
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/parts-cdn.ts
5384
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/parts-cdn.ts
5376
5385
  var DEFAULT_PARTS_CDN = "https://ldr-parts-cdn.baconbrix.workers.dev/v1/";
5377
5386
  var indexCache = new Map;
5378
5387
  var shardCache = new Map;
@@ -5633,10 +5642,10 @@ async function prepareModel(source, o = {}) {
5633
5642
  return { insts, pack, tier, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
5634
5643
  }
5635
5644
 
5636
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/load-worker.gen.ts
5637
- var load_worker_gen_default = 'var sn=ArrayBuffer,H=Uint8Array,$e=Uint16Array,on=Int16Array;var je=Int32Array,Ye=function(e,t,n){if(H.prototype.slice)return H.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 H(n-t);return r.set(e.subarray(t,n)),r},Be=function(e,t,n,r){if(H.prototype.fill)return H.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},an=function(e,t,n,r){if(H.prototype.copyWithin)return H.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 ln=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],Z=function(e,t,n){var r=Error(t||ln[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Z);if(!n)throw r;return r},yt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},cn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},un=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,c=r>>6;if(r&8)Z(0);var a=6-s,u=i==3?4:i,l=yt(e,a,u);a+=u;var f=c?1<<c:s,h=yt(e,a,f)+(c==1&&256),g=h;if(!s){var p=1<<10+(e[5]>>3);g=p+(p>>3)*(e[5]&7)}if(g>2145386496)Z(1);var m=new H((t==1?h||g:t?0:g)+12);return m[0]=1,m[4]=4,m[8]=8,{b:a+f,y:0,l:0,d:l,w:t&&t!=1?t:m.subarray(12),e:g,o:new je(m.buffer,0,3),u:h,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return cn(e,4)+8;Z(0)},Se=function(e){var t=0;for(;1<<t<=e;++t);return t-1},De=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Z(3);var o=1<<s,i=o,c=-1,a=-1,u=-1,l=o,f=new sn(512+(o<<2)),h=new on(f,0,256),g=new $e(f,0,256),p=new $e(f,512,o),m=512+(o<<1),A=new H(f,m,o),b=new H(f,m+o);while(c<255&&i>0){var d=Se(i+1),x=r>>3,w=(1<<d+1)-1,v=(e[x]|e[x+1]<<8|e[x+2]<<16)>>(r&7)&w,M=(1<<d)-1,U=w-i-1,S=v&M;if(S<U)r+=d,v=S;else if(r+=d+1,v>M)v-=U;if(h[++c]=--v,v==-1)i+=v,A[--l]=c;else i-=v;if(!v)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)Z(0);var y=0,R=(o>>1)+(o>>3)+3,C=o-1;for(var F=0;F<=c;++F){var B=h[F];if(B<1){g[F]=-B;continue}for(u=0;u<B;++u){A[y]=F;do y=y+R&C;while(y>=l)}}if(y)Z(0);for(u=0;u<o;++u){var L=g[A[u]]++,V=b[u]=s-Se(L);p[u]=(L<<V)-o}return[r+7>>3,{b:s,s:A,n:b,t:p}]},fn=function(e,t){var n=0,r=-1,s=new H(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),a=new $e(s.buffer,268);if(o<128){var u=De(e,t+1,6),l=u[0],f=u[1];t+=o;var h=l<<3,g=e[t];if(!g)Z(0);var p=0,m=0,A=f.b,b=A,d=(++t<<3)-8+Se(g);for(;;){if(d-=A,d<h)break;var x=d>>3;if(p+=(e[x]|e[x+1]<<8)>>(d&7)&(1<<A)-1,i[++r]=f.s[p],d-=b,d<h)break;x=d>>3,m+=(e[x]|e[x+1]<<8)>>(d&7)&(1<<b)-1,i[++r]=f.s[m],A=f.n[p],p=f.t[p],b=f.n[m],m=f.t[m]}if(++r>255)Z(0)}else{r=o-127;for(;n<r;n+=2){var w=e[++t];i[n]=w>>4,i[n+1]=w&15}++t}var v=0;for(n=0;n<r;++n){var M=i[n];if(M>11)Z(0);v+=M&&1<<M-1}var U=Se(v)+1,S=1<<U,D=S-v;if(D&D-1)Z(0);i[r++]=Se(D)+1;for(n=0;n<r;++n){var M=i[n];++c[i[n]=M&&U+1-M]}var y=new H(S<<1),R=y.subarray(0,S),C=y.subarray(S);a[U]=0;for(n=U;n>0;--n){var F=a[n];Be(C,n,F,a[n-1]=F+c[n]*(1<<U-n))}if(a[0]!=S)Z(0);for(n=0;n<r;++n){var B=i[n];if(B){var L=a[B];Be(R,n,L,a[B]=L+(1<<U-B))}}return[t,{n:C,b:U,s:R}]},pn=De(new H([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],mn=De(new H([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],hn=De(new H([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],xt=function(e,t){var n=e.length,r=new je(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Je=new H(new je([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),gn=xt(Je,0),Qe=new H(new je([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),dn=xt(Qe,3),Re=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)Z(0);var a=0,u=n.b,l=(r<<3)-8+Se(o)-u,f=-1;for(;l>c&&f<s;){var h=l>>3,g=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(l&7);a=(a<<u|g)&i,t[++f]=n.s[a],l-=u=n.n[a]}if(l!=c||f+1!=s)Z(0)},bn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;Re(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Re(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Re(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),Re(e.subarray(r),t.subarray(c),n)},yn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Be(n,e[s],t.y,t.y+=c),n;return Be(new H(c),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=c,n;return Ye(e,s,a)}if(i==2){var u=e[s],l=u&3,f=u>>2&3,h=u>>4,g=0,p=0;if(l<2)if(f&1)h|=e[++s]<<4|(f&2&&e[++s]<<12);else h=u>>3;else if(p=f,f<2)h|=(e[++s]&63)<<4,g=e[s]>>6|e[++s]<<2;else if(f==2)h|=e[++s]<<4|(e[++s]&3)<<12,g=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,g=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var m=n?n.subarray(t.y,t.y+t.m):new H(t.m),A=m.length-h;if(l==0)m.set(e.subarray(s,s+=h),A);else if(l==1)Be(m,e[s++],A);else{var b=t.h;if(l==2){var d=fn(e,s);g+=s-(s=d[0]),t.h=b=d[1]}else if(!b)Z(0);(p?bn:Re)(e.subarray(s,s+=g),m.subarray(A),b)}var x=e[s++];if(x){if(x==255)x=(e[s++]|e[s++]<<8)+32512;else if(x>127)x=x-128<<8|e[s++];var w=e[s++];if(w&3)Z(0);var v=[mn,hn,pn];for(var M=2;M>-1;--M){var U=w>>(M<<1)+2&3;if(U==1){var S=new H([0,0,e[s++]]);v[M]={s:S.subarray(2,3),n:S.subarray(0,1),t:new $e(S.buffer,0,1),b:0}}else if(U==2)r=De(e,s,9-(M&1)),s=r[0],v[M]=r[1];else if(U==3){if(!t.t)Z(0);v[M]=t.t[M]}}var D=t.t=v,y=D[0],R=D[1],C=D[2],F=e[a-1];if(!F)Z(0);var B=(a<<3)-8+Se(F)-C.b,L=B>>3,V=0,me=(e[L]|e[L+1]<<8)>>(B&7)&(1<<C.b)-1;L=(B-=R.b)>>3;var be=(e[L]|e[L+1]<<8)>>(B&7)&(1<<R.b)-1;L=(B-=y.b)>>3;var ye=(e[L]|e[L+1]<<8)>>(B&7)&(1<<y.b)-1;for(++x;--x;){var ue=C.s[me],Pe=C.n[me],xe=y.s[ye],Ce=y.n[ye],ke=R.s[be],he=R.n[be];L=(B-=ke)>>3;var O=1<<ke,k=O+((e[L]|e[L+1]<<8|e[L+2]<<16|e[L+3]<<24)>>>(B&7)&O-1);L=(B-=Qe[xe])>>3;var J=dn[xe]+((e[L]|e[L+1]<<8|e[L+2]<<16)>>(B&7)&(1<<Qe[xe])-1);L=(B-=Je[ue])>>3;var _=gn[ue]+((e[L]|e[L+1]<<8|e[L+2]<<16)>>(B&7)&(1<<Je[ue])-1);if(L=(B-=Pe)>>3,me=C.t[me]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<Pe)-1),L=(B-=Ce)>>3,ye=y.t[ye]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<Ce)-1),L=(B-=he)>>3,be=R.t[be]+((e[L]|e[L+1]<<8)>>(B&7)&(1<<he)-1),k>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=k-=3;else{var W=k-(_!=0);if(W){if(k=W==3?t.o[0]-1:t.o[W],W>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=k}else k=t.o[0]}for(var M=0;M<_;++M)m[V+M]=m[A+M];V+=_,A+=_;var ne=V-k;if(ne<0){var q=-ne,le=t.e+ne;if(q>J)q=J;for(var M=0;M<q;++M)m[V+M]=t.w[le+M];V+=q,J-=q,ne=0}for(var M=0;M<J;++M)m[V+M]=m[ne+M];V+=J}if(V!=A)while(A<m.length)m[V++]=m[A++];else V=m.length;if(n)t.y+=V;else m=Ye(m,0,V)}else if(n){if(t.y+=h,A)for(var M=0;M<h;++M)m[M]=m[A+M]}else if(A)m=Ye(m,A);return t.b=a,m}Z(2)},xn=function(e,t){if(e.length==1)return e[0];var n=new H(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 Ve(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=un(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 c=yn(e,i,t);if(!c)Z(5);if(t)i.e=i.y;else n.push(c),o+=c.length,an(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return xn(n,o)}async function wn(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(Ve(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 wt(e){return new TextDecoder().decode(await wn(e))}var At=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function _e(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 Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),et=/^[A-Za-z][A-Za-z0-9_]*$/,qe=new Map;function tt(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(!qe.has(r))qe.set(r,t);return r}function nt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&et.test(e))return tt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,An=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Mn=new Set(["FILE","NOFILE","!DATA"]),Pt=1000000000000000,It=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),vn=new Set(["model","submodel","configuration"]),Cn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function vt(e){let t=Cn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return It.has(n)||vn.has(n)?n:void 0}function kn(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 Tn(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((f)=>Number.isFinite(f)&&Math.abs(f)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let f=0;f<s;f++)c=c.replace(/^\\S+\\s*/,"");let a=kn(c);if(!a.length)return null;let u={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)u.a=i[9];if(s===11)u.b=i[10];let l=a.findIndex((f,h)=>h>0&&f.toUpperCase()==="GLOSSMAP");if(l>0&&a[l+1])u.glossmap=a[l+1];if(t)u.next=!0;return u}var Ln=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let 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 Sn(e,t){let n=e.length,r=1,s=(p)=>p===32||p===9,o=()=>{while(r<n&&s(e.charCodeAt(r)))r++;let p=r,m=e.charCodeAt(r),A=m===45;if(A)m=e.charCodeAt(++r);let b=0,d=0;while(m>=48&&m<=57)b=b*10+(m-48),d++,m=e.charCodeAt(++r);if(d>0&&d<=15&&(r>=n||s(m)))return A?-b:b;while(r<n&&!s(e.charCodeAt(r)))r++;return p<r?+e.slice(p,r):NaN};while(r<n&&s(e.charCodeAt(r)))r++;let i=r;if(r>=n)return null;let c=e.charCodeAt(r),a=c===45,u=0,l=0;if(a)c=e.charCodeAt(++r);while(c>=48&&c<=57)u=u*10+(c-48),l++,c=e.charCodeAt(++r);if(l>0&&l<=15&&(r>=n||s(c))){if(a)u=-u}else{while(r<n&&!s(e.charCodeAt(r)))r++;u=nt(e.slice(i,r))}let f=Array(12);for(let p=0;p<12;p++){let m=o();if(!Number.isFinite(m))return null;f[p]=m}while(r<n&&s(e.charCodeAt(r)))r++;if(r>=n)return null;let h=e.slice(r),g=t.get(h);if(g===void 0)g=Y(/[ \\t]{2,}|\\t/.test(h)?h.split(/\\s+/).join(" "):h),t.set(h,g);if(!Number.isFinite(u))return null;return{t:1,color:u,m:f,file:g}}var En=[0,12,6,9,12,12];function Ct(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=nt(e[1]),r=En[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Y(e.slice(14).join(" "));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Ft(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,a=null,u=[],l=null,f=()=>{if(!a)return;let x=Ln(a.chunks.join("")),w=x[0]===137&&x[1]===80&&x[2]===78&&x[3]===71;(c??=new Map).set(Y(a.name),{name:a.name,bytes:x,...w?{mime:"image/png"}:{}}),a=null},h=new Map,g=!0,p=(x)=>{if(f(),o={name:Y(x),cmds:[]},s.set(o.name,o),!i)i=o.name;u=[],l=null,g=!0},m=!1,A=!1,b=()=>{if(A)return;A=!0,s.clear(),o=null,i=""},d=(x,w)=>{if(l){x.tex=l,l=null;return}let v=u[u.length-1];if(!v)return;if(v.fallback){if(!w)x.fallback=!0}else x.tex=v.map};for(let x of e.split(`\n`)){let w=x.trim();if(!w)continue;if(r&&w.charCodeAt(0)>=50&&w.charCodeAt(0)<=53&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)){if(a||m)continue;if(!o)p(t);let S=w.slice(2).trimStart(),D=S.search(/\\s/),y={t:w.charCodeAt(0)-48,color:nt(D<0?S:S.slice(0,D)),p:[],src:w};d(y,!1),o.cmds.push(y),g=!1;continue}if(w.charCodeAt(0)===48&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)){let S=2;while(w.charCodeAt(S)===32||w.charCodeAt(S)===9)S++;let D=S;while(D<w.length&&w.charCodeAt(D)!==32&&w.charCodeAt(D)!==9)D++;let y=w.slice(S,D),R=/[^\\x21-\\x7e]/.test(y)?w.slice(S).trim().split(/\\s+/)[0]:y;if(!An.has(R)&&!(R.length>=4&&R.length<=6&&Mn.has(R.toUpperCase()))){if(m||a)continue;if(!o)p(t);let C=w.slice(S),F={t:0,text:C};if(y.charCodeAt(0)===33)F.meta=y;if(l=null,g&&!o.org){let L=vt(C);if(L)o.org=L}let B=C.match(Mt);if(B&&!o.movedTo){let L=B[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(L))L+=".dat";o.movedTo=Y(L)}o.cmds.push(F);continue}}if(w.charCodeAt(0)===49&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)&&!a&&!m){let S=Sn(w,h);if(S){if(!o)p(t);d(S,!1),o.cmds.push(S),g=!1;continue}}let v=w.split(/\\s+/);if(+v[0]===0){let S=w.slice(1).trim(),D=v.length>1&&v[1].length>=4&&v[1].length<=6?v[1].toUpperCase():v[1];if(D==="FILE"){let C=S.slice(5).trimStart().split("\\r")[0].trim();if(C){b(),m=!1,p(C);continue}}if(D==="NOFILE"){f(),o=null,m=!0;continue}if(D==="!DATA"){b(),f(),o=null,m=!1,a={name:S.slice(5).trim(),chunks:[]};continue}if(m)continue;if(a){if(v[1]==="!:")a.chunks.push(v.slice(2).join(""));continue}if(!o)p(t);let y={t:0,text:S};if(v[1]==="STEP")y.step=!0,u=[],l=null;else if(v[1]==="BFC")y.bfc=v.slice(2).join(" ");else if(v[1]==="ROTSTEP")if(y.meta="ROTSTEP",y.step=!0,u=[],l=null,(v[2]??"").toUpperCase()==="END")y.rotstep={x:0,y:0,z:0,mode:"END"};else{let C=(v[5]??"REL").toUpperCase(),F=(B)=>{let L=Number(B);return Number.isFinite(L)?L:0};y.rotstep={x:F(v[2]),y:F(v[3]),z:F(v[4]),mode:["REL","ABS","ADD"].includes(C)?C:"REL"}}else if(v[1]==="BUFEXCHG"){y.meta="BUFEXCHG";let C=(v[2]??"").toUpperCase();y.bufexchg={op:C==="RETRIEVE"?"RETRIEVE":"STORE",buf:v[3]??"A"}}else if(v[1]?.startsWith("!"))y.meta=v[1];if(g&&!o.org){let C=vt(S);if(C)o.org=C}if(v[1]==="!TEXMAP"){let C=(v[2]??"").toUpperCase();if(l=null,C==="START"||C==="NEXT"){let F=Tn(S.replace(/^!TEXMAP\\s+\\S+/i,""),C==="NEXT");if(y.texmap={op:C,...F?{map:F}:{}},F)if((o.texmaps??=[]).push(F),C==="START")u.push({map:F,fallback:!1});else l=F}else if(C==="FALLBACK"){y.texmap={op:C};let F=u[u.length-1];if(F)F.fallback=!0}else if(C==="END")y.texmap={op:C},u.pop()}else if(v[1]==="!:"){l=null;let C=Ct(v.slice(2));if(C)d(C,!0),y.geom=C}else l=null;let R=S.match(Mt);if(R&&!o.movedTo){let C=R[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Y(C)}o.cmds.push(y);continue}if(a||m)continue;if(!o)p(t);let U=Ct(v);if(!U){if(/^[2-5][ \\t]/.test(w))g=!1;continue}d(U,!1),o.cmds.push(U),g=!1}return f(),c?{main:i,files:s,data:c}:{main:i,files:s}}var sr=Math.PI/180;function Rt(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 Bt(e,t){let[n,r,s,o,i,c,a,u,l,f,h,g]=e,[p,m,A,b,d,x,w,v,M,U,S,D]=t;return[o*p+i*m+c*A+n,a*p+u*m+l*A+r,f*p+h*m+g*A+s,o*b+i*w+c*U,o*d+i*v+c*S,o*x+i*M+c*D,a*b+u*w+l*U,a*d+u*v+l*S,a*x+u*M+l*D,f*b+h*w+g*U,f*d+h*v+g*S,f*x+h*M+g*D]}var rt=[0,0,0,1,0,0,0,1,0,0,0,1];var kt=new WeakMap,Pn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=kt.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&&Pn.test(s.file))?"part":"model";return kt.set(n,r),r}var Tt=new WeakMap;function Dt(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 Lt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?qe.get(e)??String(e):String(e),In=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Lt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Lt(e.color)} ${e.p.join(" ")}`,ot=(e,t)=>`${Y(e)}#${t}`;function Fn(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:ot(e.name,t),cmds:n}}function Ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Fn(e,t).cmds.map(In)].join(`\n`)+`\n`}function it(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 Nt(e){let[t,n,r,s,o,i,c,a,u,l,f,h]=e,g=a*h-u*f,p=-(c*h-u*l),m=c*f-a*l,A=s*g+o*p+i*m;if(!Number.isFinite(A)||Math.abs(A)<0.000000000001)return null;let b=1/A,d=[g*b,-(o*h-i*f)*b,(o*u-i*a)*b,p*b,(s*h-i*l)*b,-(s*u-i*c)*b,m*b,-(s*f-o*l)*b,(s*a-o*c)*b];return[-(d[0]*t+d[1]*n+d[2]*r),-(d[3]*t+d[4]*n+d[5]*r),-(d[6]*t+d[7]*n+d[8]*r),...d]}var Rn=(e)=>String(+e.toFixed(6)||0),St=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Ot(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Rn).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 ${Y(e)}\n0 !TEXMAP END\n`;return{name:`${Y(e)}#tex-${it(r)}`,source:r}}var Bn=(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 Dn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),u=Math.cos(n*r);return[c*u,-c*a,i,o*a+s*i*u,o*u-s*i*a,-s*c,s*a-o*i*u,s*u+o*i*a,o*c]}var Et=new WeakMap;function zt(e){let t=Et.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=Dn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Bn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Et.set(e,n),n}class at extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var Un=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=Pt))return!1;return!0},$t=999999,_t=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Gt=new WeakMap,jt=new WeakMap;function Nn(e,t){let n=jt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Gt.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},jt.set(t,n);let r=n.parts.get(e);if(!r){let s=Y(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-${it(o)}`,source:o},n.parts.set(e,r)}return r}function On(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,a=0,u=new Set,l=t.maxInstances??2000000,f=0,h=(p,m)=>{let A=p.name+"#"+m,b=c.get(A);if(!b){let d;b=Object.assign(()=>d??=Ut(p,m),{file:p,step:m}),c.set(A,b)}return b},g=(p,m,A,b,d,x,w,v,M=null,U=[],S=[],D=void 0,y=null)=>{let R=p.files.get(m);if(!R||w>r||u.has(R))return;if(++f>l)throw new at("model",l);u.add(R);let C=y,F=0,B=w>0?++a:0,L=i&&B?[...U,B]:U,V=i&&B?[...S,A]:S,me=i&&!M?new Map:null,be=-1,ye=0,ue=(O,k,J,_,W,ne,q)=>{if(be!==F)be=F,ye=0;let le=me?.get(F+"|"+k);if(le)return le.n++,g(O,O===p?k:O.main,J,_,d+"/"+k,[...W,$t],w+1,ne,[...W,$t],L,V,q,C);let T=[...W,ye++],P=n.length;g(O,O===p?k:O.main,J,_,d+"/"+k,T,w+1,ne,M,L,V,q,C),me?.set(F+"|"+k,{n:1,from:P,to:n.length})},Pe=zt(R),xe=s?Dt(R):[],Ce=0,ke=(O,k,J,_,W,ne,q,le,T)=>{if(M)_=M;if(++f>l)throw new at("model",l);let P={part:O,color:k,m:J,step:_[0],steps:_,localStep:W,path:d};if(le)P.colour=le;if(B){if(P.sub=B,i)P.subPath=L,P.subMats=V}if(ne)P.embedded=!0;if(q){let N=Ot(O,q);P.texPart=N.name,P.texSource=N.source}else if(T){let N=Nn(O,T);P.colPart=N.name,P.colSource=N.source}let E=Pe[W];if(E)P.view=E;return n.push(P),P},he=(O)=>{while(Ce<xe.length&&xe[Ce]<=O){let k=xe[Ce++];ke(ot(R.name,k),b,A,[...x,k],k,!1,null,D,y).source=h(R,k)}};for(let O of R.cmds){if(O.t===0&&O.step){F++;continue}let k=O;if(k.t>=2||k.t===0&&k.geom&&k.geom.t>=2){he(F);continue}if(k.t===0){if(k.meta==="!COLOUR"){let E=$n(k.text);if(E&&E.code!==16&&E.code!==24)Gt.set(E,k.text),(C=new Map(C??[])).set(E.code,E);continue}if(o&&k.geom?.t===1)k=k.geom;else continue}if(k.t!==1)continue;if(o&&k.fallback)continue;let J=Bt(A,k.m);if(!Un(J))continue;let _=k.color===16?b:k.color,W=k.color===16?D:C?.get(k.color),ne=[...x,F],q=o?k.tex??v:null,le=q?Nt(k.m):null,T=q&&le?Rt(q,le):null;if(p.files.has(k.file)){if(st(p,k.file)==="model"){ue(p,k.file,J,_,ne,T,W);continue}ke(k.file,_,J,ne,F,!0,T,W,C);continue}let P=t.resolveModel?.(k.file);if(P){ue(P,k.file,J,_,ne,T,W);continue}ke(k.file,_,J,ne,F,!1,T,W,C)}if(he(1/0),u.delete(R),me){for(let O of me.values())if(O.n>1)for(let k=O.from;k<O.to;k++)n[k].mult??=O.n}};if(st(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...rt],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,rt,16,e.main,[],0,null),n}function Ht(e,t="main.ldr",n){return On(Ft(e,t,{geometryText:!0}),n)}var zn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function lt(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 Vt(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=lt(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 $n(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",c=255,a=0,u={type:"default"},l=1;while(l<n.length){let f=n[l].toUpperCase(),h=n[l+1];if(f==="CODE")s=h!==void 0&&et.test(h)?tt(h):h!==void 0&&/^\\d+$/.test(h)?+h:NaN,l+=2;else if(f==="VALUE"){let g=lt(h);if(g)o=g;l+=2}else if(f==="EDGE")i=lt(h)??h,l+=2;else if(f==="ALPHA")c=+h,l+=2;else if(f==="LUMINANCE")a=+h,l+=2;else if(f==="CHROME")u={type:"chrome"},l+=1;else if(f==="PEARLESCENT")u={type:"pearlescent"},l+=1;else if(f==="RUBBER")u={type:"rubber"},l+=1;else if(f==="MATTE_METALLIC")u={type:"matte_metallic"},l+=1;else if(f==="METAL")u={type:"metal"},l+=1;else if(f==="MATERIAL"){let g=(n[l+1]||"").toUpperCase();if(g==="GLITTER"){let{grain:p,next:m}=Vt(n,l+2);u={type:"glitter",material:p},l=m}else if(g==="SPECKLE"){let{grain:p,next:m}=Vt(n,l+2);u={type:"speckle",material:p},l=m}else if(g==="FABRIC"){let p=(n[l+2]||"").toUpperCase(),m=["VELVET","CANVAS","STRING","FUR"].includes(p)?p.toLowerCase():void 0;u={type:"fabric",kind:m},l+=m?3:2}else l=n.length}else if(zn.has(f))l+=1;else l+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(a)?a:0,finish:u}}function jn(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,c=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:c,finish:"glitter"}}case"speckle":{let i=e.finish.material,c=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:c,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 ct(e){let t=jn(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 Vn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Y(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Y(t),r)}let a=i.trim().replace(/\\s+/g," ");if(a)r.push(a)}return n}var _n=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function Gn(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 Wt(e,t,n="main.ldr"){let r=[...t],s=new Map;if(!r.length)return s;let o=Vn(e,n);for(let i of r){let c=Y(i);if(!o.has(c)||s.has(c))continue;let a=new Set([c]),u=[c];while(u.length)for(let f of o.get(u.pop())){let h=_n(f);if(h&&o.has(h)&&!a.has(h))a.add(h),u.push(h)}let l=[c,...[...a].filter((f)=>f!==c).sort()].map((f)=>"0 FILE "+(f===c?"":f)+`\n`+o.get(f).join(`\n`)).join(`\n`);s.set(c,`emb/${Gn(l)}.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,Kt=new WeakMap,ut=null,ft="",pt=null;function Hn(e,t){if(e===ut&&t===ft)return pt;let n=Kt.get(e);if(!n)Kt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return ut=e,ft=t,pt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],a=[];s.studs.forEach((g,p)=>{c.push(g[0]),a.push(g[1]);for(let m=0;m<12;m++)i[p*12+m]=g[2+m]});let u=null,l=0,f=0;if(s.mask){l=s.mask[0],f=s.mask[1];let g=s.mask[2];u=new Uint8Array(g.length);for(let p=0;p<g.length;p++)u[p]=g.charCodeAt(p)===49?1:0}let h=!!u;if(u){for(let g=0;g<u.length;g++)if(u[g]!==1){h=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:a,mask:u,nx:l,nz:f,full:h}),ut=e,ft=t,pt=r,r}var Ie=1073741824;class Ee{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=Ee.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let a=s[c];if(a===0)return-1;if(a===r){let u=c<<2;if(o[u]===e&&o[u+1]===t&&o[u+2]===n)return o[u+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=Ee.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,a=this.slot(e,t,n);for(;;){let u=o[a],l=a<<2;if(u===0)return o[a]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(u===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let f=i[l+3];return i[l+3]=r,f}a=a+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Yt{grp=new Ee(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],a=[];for(let f=0;f<r;f++){let h=e[f],g=t[f],p=n[f],m=(h%20+20)%20,A=(p%20+20)%20,b=this.group(g,m,A);if(b<0)b=s.length,this.grp.put(g,m,A,b),this.lg=b,s.push(0),o.push(h),i.push(h),c.push(p),a.push(p);if(s[b]++,h<o[b])o[b]=h;else if(h>i[b])i[b]=h;if(p<c[b])c[b]=p;else if(p>a[b])a[b]=p}let u=0,l=0;for(let f=0;f<s.length;f++){let h=(i[f]-o[f])/20+1,g=(a[f]-c[f])/20+1,p=h*g;if(this.gX0.push(o[f]),this.gZ0.push(c[f]),this.gNx.push(h),this.gNz.push(g),p<=64*s[f]+1024&&u+p<2147483648)this.gBits.push(u),u+=p;else this.gBits.push(-1),l+=s[f]}this.bits=new Uint8Array(Math.ceil(u/8)),this.rest=new Ee(l);for(let f=0;f<r;f++){let h=e[f],g=t[f],p=n[f],m=this.group(g,(h%20+20)%20,(p%20+20)%20),A=this.gBits[m];if(A<0){this.rest.put(h,g,p,1);continue}let b=A+(h-this.gX0[m])/20*this.gNz[m]+(p-this.gZ0[m])/20;this.bits[b>>>3]|=1<<(b&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Wn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Fe=(e,t,n)=>e>-Ie&&e<Ie&&t>-Ie&&t<Ie&&n>-Ie&&n<Ie,Ue=2147483647;function Xn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function mt(e,t,n){return Zt(e,t,n,-1)??Zt(e,t,n,Jt)}var Jt=0;function Zt(e,t,n,r){let o=new Map,i=(T)=>{let P=o.get(T);if(P===void 0)o.set(T,P=Xn(t,T));return P},c=e.length,a=0,u=0,l=0,f=Array(c);for(let T=0;T<c;T++){let P=f[T]=Hn(t,e[T].part);if(P){if(l+=P.nStuds,P.mask)a++}}let h=new Float64Array(a),g=new Float64Array(a),p=new Float64Array(a),m=new Float64Array(a),A=new Int32Array(a),b=new Int32Array(a),d=new Float64Array(a),x=new Float64Array(a),w=[],v=new Int32Array(a),M=new Float64Array(a*9),U=new Uint8Array(a);if(r<0)r=a*4+64;let S=new Ee(e.length*2),D=new Int32Array(r),y=new Int32Array(r),R=0,C=0;for(let T=0;T<e.length;T++){let P=e[T],E=P.m,N=t.parts[P.part];if(!N||!N.mask||!Xt(E)||i(P.color))continue;let I=N.bbox,z=1/0,j=-1/0,ee=1/0,X=-1/0;for(let K=0;K<2;K++)for(let ae=0;ae<2;ae++){let te=K?I[3]:I[0],Le=ae?I[5]:I[2],ve=E[0]+E[3]*te+E[5]*Le,de=E[2]+E[9]*te+E[11]*Le;if(ve<z)z=ve;if(ve>j)j=ve;if(de<ee)ee=de;if(de>X)X=de}let G=Math.round((E[1]+I[4])*2),Q=f[T],ce=Math.floor(z/40),we=Math.floor(j/40),Ae=Math.floor(ee/40),Me=Math.floor(X/40);if(!((we-ce+1)*(Me-Ae+1)<=65536)||!Fe(G,ce,Ae)||!Fe(G,we,Me))continue;let ge=Math.floor((z+5)/40),re=Math.floor((j-5)/40),se=Math.floor((ee+5)/40),oe=Math.floor((X-5)/40),Te=ge<=re&&se<=oe?(re-ge+1)*(oe-se+1):0;C+=Te;let fe=-1;for(let K=ge<=re&&se<=oe?S.get(G,ge,se):-1,ae=0;K>=0&&ae<8;K=D[K],ae++){let te=y[K];if(h[te]!==z||g[te]!==j||p[te]!==ee||m[te]!==X||w[te]!==Q)continue;let Le=e[A[te]].m,ve=!0;for(let de=0;de<12;de++)if(Le[de]!==E[de]){ve=!1;break}if(ve){fe=te;break}}if(fe>=0){let K=n?n[T]:0;if(n&&K<n[A[fe]])b[fe]=A[fe],A[fe]=T;else if(b[fe]<0||n&&K<n[b[fe]])b[fe]=T;continue}let ie=u++;h[ie]=z,g[ie]=j,p[ie]=ee,m[ie]=X,A[ie]=T,b[ie]=-1,w.push(Q),d[ie]=I[0],x[ie]=I[2],v[ie]=G;let pe=ie*9;if(M[pe]=E[0],M[pe+1]=E[1],M[pe+2]=E[2],M[pe+3]=E[3],M[pe+4]=E[6],M[pe+5]=E[9],M[pe+6]=E[5],M[pe+7]=E[8],M[pe+8]=E[11],U[ie]=Q.full&&I[3]-I[0]<=20*Q.nx&&I[5]-I[2]<=20*Q.nz&&E[4]===0&&E[6]===0&&E[8]===0&&E[10]===0&&Wn(E[3],E[5],E[9],E[11])?1:0,R+Te>r){R=r+1;continue}for(let K=ge;K<=re;K++)for(let ae=se;ae<=oe;ae++){if(!Fe(G,K,ae))continue;let te=R++;y[te]=ie,D[te]=S.put(G,K,ae,te)}}if(R>r)return Jt=C,null;let F=[0,5,-5,5,-5],B=[0,5,5,-5,-5],L=(T,P,E,N)=>{if(!(P-6>=h[T]-0.5&&P+6<=g[T]+0.5&&N-6>=p[T]-0.5&&N+6<=m[T]+0.5))return!1;if(U[T]===1)return!0;let I=T*9,z=w[T],j=d[T],ee=x[T],X=P-M[I],G=E-M[I+1],Q=N-M[I+2],ce=M[I+3]*X+M[I+4]*G+M[I+5]*Q,we=M[I+6]*X+M[I+7]*G+M[I+8]*Q,{nx:Ae,nz:Me,mask:ge}=z;for(let re=0;re<5;re++){let se=Math.floor((ce+F[re]-j)/20),oe=Math.floor((we+B[re]-ee)/20);if(se<0||oe<0||se>=Ae||oe>=Me||ge[se*Me+oe]!==1)return!1}return!0},V=NaN,me=NaN,be=NaN,ye=-1,ue=-1,Pe=(T,P,E,N)=>{let I=Math.round(P*2),z=Math.floor(T/40),j=Math.floor(E/40);if(!Fe(I,z,j))return Ue;let ee=Ue;if(!n&&ue>=0&&v[ue]===I&&(A[ue]!==N||b[ue]>=0)&&L(ue,T,P,E))return 0;if(I!==V||z!==me||j!==be)V=I,me=z,be=j,ye=S.get(I,z,j);for(let X=ye;X>=0;X=D[X]){let G=y[X],Q=A[G];if(Q===N&&(Q=b[G])<0)continue;if(!L(G,T,P,E))continue;if(!n)return ue=G,0;let ce=n[Q];if(ce<ee)ee=ce}return ee},xe=new Uint8Array(l),Ce=new Uint8Array(l),ke=0,he=n?new Ee(l,4):null,O=n?null:new Int32Array(l),k=n?null:new Int32Array(l),J=n?null:new Int32Array(l),_=0,W=n?new Int32Array(l).fill(Ue):void 0;for(let T=0,P=0;T<e.length;T++){let E=e[T],N=f[T];if(!N)continue;let I=E.m,z=N.studM,j=I[0],ee=I[1],X=I[2],G=I[3],Q=I[4],ce=I[5],we=I[6],Ae=I[7],Me=I[8],ge=I[9],re=I[10],se=I[11];for(let oe=0;oe<N.nStuds;oe++,P++){let Te=oe*12,fe=z[Te+4],ie=z[Te+7],pe=z[Te+10];if(!(Math.abs(we*fe+Ae*ie+Me*pe-1)<0.001&&Math.abs(G*fe+Q*ie+ce*pe)<0.001&&Math.abs(ge*fe+re*ie+se*pe)<0.001))continue;Ce[P]=1;let K=z[Te],ae=z[Te+1],te=z[Te+2],Le=j+G*K+Q*ae+ce*te,ve=ee+we*K+Ae*ae+Me*te,de=X+ge*K+re*ae+se*te,gt=Pe(Le,ve,de,T);if(gt!==Ue){if(xe[P]=1,ke++,W)W[P]=gt}let Ne=Math.round(Le),Oe=Math.round(ve),ze=Math.round(de);if(!Fe(Ne,Oe,ze))continue;if(!he){O[_]=Ne,k[_]=Oe,J[_++]=ze;continue}let dt=n[T],bt=he.get(Ne,Oe,ze);if(bt<0||dt<bt)he.put(Ne,Oe,ze,dt)}}let ne=he?null:new Yt(O,k,J,_),q=new Uint8Array(e.length),le=n?new Int32Array(e.length).fill(Ue):void 0;for(let T=0;T<e.length;T++){let P=e[T],E=t.parts[P.part];if(!E||!E.under||!Xt(P.m)||i(P.color))continue;let N=E.bbox,I=Math.round((N[3]-N[0])/20),z=Math.round((N[5]-N[2])/20);if(!I||!z||I*z>4096)continue;let j=P.m,ee=Math.round(j[1]+N[4]),X=!0,G=0;for(let Q=0;Q<I&&X;Q++)for(let ce=0;ce<z;ce++){let we=N[0]+10+20*Q,Ae=N[2]+10+20*ce,Me=j[0]+j[3]*we+j[5]*Ae,ge=j[2]+j[9]*we+j[11]*Ae,re=Math.round(Me),se=Math.round(ge),oe=!Fe(re,ee,se)?-1:he?he.get(re,ee,se):ne.has(re,ee,se)?1:-1;if(oe<0){X=!1;break}if(oe>G)G=oe}if(X){if(q[T]=1,le)le[T]=G}}return{nStuds:l,studHidden:xe,studUp:Ce,underHidden:q,studsHidden:ke,studHideStep:W,underHideStep:le}}function ht(e,t,n){let r=(l)=>l.colPart&&t.parts[l.colPart]?l.colPart:n&&l.texPart&&t.parts[l.texPart]?l.texPart:l.part,s=new Map,o=new Map,i=(l)=>{let f=l.colour;if(!f)return String(l.color);let h=o.get(f);if(h!==void 0)return h;let g=t.colorTable?.[l.color],p=g?.hex??t.colors?.[l.color],m=g?ct({alpha:g.alpha??255,luminance:g.luminance??0,finish:g.finish??{type:"default"}}):"default:op",A=ct(f);if(h=p&&p.toUpperCase()===f.hex.toUpperCase()&&m===A?String(l.color):f.hex.toUpperCase()+"/"+A,h!==String(l.color))s.set(h,f);return o.set(f,h),h},c=e.map((l)=>({part:r(l),color:i(l),m:l.m,steps:l.steps})),{stepOf:a,nSteps:u}=Kn(c);return{all:c,stepOf:a,nSteps:u,localColours:s}}function Kn(e){let t=!0;for(let o=0;o<e.length;o++){let i=e[o].steps;if(i.length!==1){t=!1;break}let c=i[0];if(!(Number.isInteger(c)&&c>=0&&c<1e6)){t=!1;break}}if(t){let o=new Set;for(let a=0;a<e.length;a++)o.add(e[a].steps[0]);let i=[...o].sort((a,u)=>a-u),c=new Map(i.map((a,u)=>[a,u]));return{stepOf:e.map((a)=>c.get(a.steps[0])),nSteps:i.length}}let n=e.map((o)=>_t(o.steps)),r=[...new Set(n)].sort(),s=new Map(r.map((o,i)=>[o,i]));return{stepOf:n.map((o)=>s.get(o)),nSteps:r.length}}function Qt(e,t,n=!0){let r=ht(e,t,n);return mt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ke="https://ldr-parts-cdn.baconbrix.workers.dev/v1/",He=new Map,Ge=new Map;function We(e=Ke,t=fetch){let n=He.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(()=>He.delete(e)),He.set(e,n);return n}var Zn=(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"),Xe=(e,t)=>Zn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Xe(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Xe(r,t)])):e;function Yn(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let g=h.buffer;if(!g)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let p=new DataView(g).getUint32(0,!0),m=new Uint8Array(g,4+p),A=r;n.push(m),r+=m.byteLength;let b=(4-r%4)%4;if(b)n.push(new Uint8Array(b)),r+=b;for(let[d,x]of Object.entries(h.header.parts??{}))if(!(d in s))s[d]=Xe(x,A);for(let[d,x]of Object.entries(h.header.studKinds??{}))if(!(d in o))o[d]=Xe(x,A)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+c.length)%4)%4,u=4+c.length+a,l=new Uint8Array(u+r);new DataView(l.buffer).setUint32(0,c.length+a,!0),l.set(c,4),l.fill(32,4+c.length,u);let f=u;for(let h of n)l.set(h,f),f+=h.byteLength;return _e(l.buffer)}async function Jn(e,t={}){e=[...e];try{return await qt(e,t)}catch(n){let r=t.cdn??Ke,s=t.fetch??fetch;He.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await qt(e,{...t,fetch:o})}catch{throw n}}}async function qt(e,t){let n=t.cdn??Ke,r=t.fetch??fetch,s=t.gap??16384,o=await We(n,r),i=[...new Set([...new Set(e)].map(Y))],c=[],a=[];for(let d of i){if(Ge.has(n+d))continue;let x=o.parts[d];if(x)a.push({name:d,off:x[0],len:x[1],file:x[2]??0});else c.push(d)}a.sort((d,x)=>d.file-x.file||d.off-x.off);let u=[];for(let d of a){let x=u[u.length-1];if(x&&x.file===d.file&&d.off-x.end<=s)x.end=Math.max(x.end,d.off+d.len),x.items.push(d);else u.push({file:d.file,start:d.off,end:d.off+d.len,items:[d]})}let l=0,f=0,h=0,g=new Map,p=async()=>{while(h<u.length){let d=u[h++],x=g.get(d.file);if(x)x=x.subarray(d.start,d.end);else{let w=await r(new URL(o.archives[d.file],n).href,{headers:{Range:`bytes=${d.start}-${d.end-1}`,"Accept-Encoding":"identity"}});if(!w.ok)throw Error(`ldr: parts CDN ${w.status}`);if(f++,x=new Uint8Array(await w.arrayBuffer()),l+=x.byteLength,w.status===200)g.set(d.file,x),x=x.subarray(d.start,d.end)}for(let w of d.items){let v=Ve(x.subarray(w.off-d.start,w.off-d.start+w.len)),M=v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength);Ge.set(n+w.name,_e(M))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,u.length)},p));let m=i.filter((d)=>Ge.has(n+d)).map((d)=>Ge.get(n+d)),A={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:m.length?Yn(m,A):_e(Qn(A)),missing:c,requests:f,bytes:l}}function Qn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...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 qn(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 en(e,t,n){let r=0,s=0,o=!1,i=new Set,c=new Map;for(let a of e){let u;if(a.embedded)u=t.get(a.part);else if(u=c.get(a.part),u===void 0)c.set(a.part,u=Y(a.part));let l=u?n.parts[u]:void 0;if(!l)continue;if(l[3]!=null)o=!0,r+=l[3];if(!i.has(u))i.add(u),s+=l[1]}return{bodyTris:r,packBytes:s,known:o}}class Ze 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 tn(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=We(t.cdn??Ke,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(y)=>{if(!y.ok)throw Error(`ldr: ${y.status} fetching ${e}`);return wt(await y.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":At(e)),a=Ht(o,c,{looseGeometry:!1,callouts:t.callouts}),u=performance.now();t.onParsed?.(a),await s;let l=Wt(o,new Set(a.filter((y)=>y.embedded).map((y)=>y.part)),c),f=(y,R)=>t.maxBodyTris!=null&&y>t.maxBodyTris||t.maxPackBytes!=null&&R>t.maxPackBytes,h=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(y)=>new Ze({...y,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),p="full";if(h){let y=en(a,l,await s);if(f(y.known?y.bodyTris:0,y.packBytes)){if(!t.lowCdn)throw g(y);let R=await We(t.lowCdn,r).catch(()=>null);if(!R)throw g(y);let C=en(a,l,R);if(f(C.known?C.bodyTris:0,C.packBytes))throw g(C);p="low"}}let m=[...a.filter((y)=>!y.embedded).map((y)=>y.part),...l.values()],A=async()=>{let y=await Jn(m,p==="low"?{...t,cdn:t.lowCdn}:t);for(let[R,C]of l){let F=y.pack.header.parts[C];if(F)y.pack.header.parts[R]=F}return{...y,packBytes:y.pack.buffer?.byteLength??y.pack.bytes??0,bodyTris:qn(a,y.pack)}},b=await A();if(h&&f(b.bodyTris,b.packBytes)&&p==="full"&&t.lowCdn&&await We(t.lowCdn,r).then(()=>!0,()=>!1)){p="low";let y=b;b=await A(),b.requests+=y.requests,b.bytes+=y.bytes}if(h&&f(b.bodyTris,b.packBytes))throw g(b);let{pack:d,missing:x,requests:w,bytes:v}=b,M=new Map([...l].map(([y,R])=>[R,y])),U=x.map((y)=>M.get(y)??y),S=performance.now(),D=t.cull?Qt(a,d.header,t.textures!==!1):void 0;return{insts:a,pack:d,tier:p,missing:U,requests:w,bytes:v,cull:D,timings:{fetchModel:i-n,parse:u-i,parts:S-u,...D?{cull:performance.now()-S}:{}}}}var er=new Set(["part","color","m","step","steps","localStep","path"]);function nn(e){let t=e.length,n=0;for(let p of e){if(typeof p.part!=="string"||typeof p.path!=="string"||typeof p.color!=="number"||typeof p.step!=="number"||typeof p.localStep!=="number"||!Array.isArray(p.m)||p.m.length!==12||!Array.isArray(p.steps))return null;n+=p.steps.length}let r=[],s=new Map,o=(p)=>{let m=s.get(p);if(m===void 0)s.set(p,m=r.length),r.push(p);return m},i=new Uint32Array(t),c=new Uint32Array(t),a=new Float64Array(t*3),u=new Float64Array(t*12),l=new Uint32Array(t+1),f=new Float64Array(n),h=[],g=0;for(let p=0;p<t;p++){let m=e[p];i[p]=o(m.part),c[p]=o(m.path),a[p*3]=m.color,a[p*3+1]=m.step,a[p*3+2]=m.localStep;let A=m.m,b=p*12;for(let w=0;w<12;w++)u[b+w]=A[w];let d=m.steps;for(let w=0;w<d.length;w++)f[g++]=d[w];l[p+1]=g;let x=null;for(let w in m)if(!er.has(w))(x??={})[w]=m[w];if(x)h.push([p,x])}return{n:t,strs:r,part:i,path:c,num:a,m:u,so:l,steps:f,extra:h}}var rn=(e)=>[e.part.buffer,e.path.buffer,e.num.buffer,e.m.buffer,e.so.buffer,e.steps.buffer];self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await tn(n,{...r,cull:!1,onParsed:(f)=>{let h=nn(f);if(h)self.postMessage({id:t,packed:h},rn(h));else 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(),c=ht(s.insts,s.pack.header,r.textures!==!1),a=mt(c.all,s.pack.header,r.stepCull&&c.nSteps>1?c.stepOf:void 0),u=performance.now()-i,l=[];for(let f of[a.studHidden,a.studUp,a.underHidden,a.studHideStep,a.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:a,ms:u},l)}catch(s){if(s instanceof Ze||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';
5645
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/load-worker.gen.ts
5646
+ var load_worker_gen_default = 'var sn=ArrayBuffer,G=Uint8Array,$e=Uint16Array,on=Int16Array;var je=Int32Array,Je=function(e,t,n){if(G.prototype.slice)return G.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 G(n-t);return r.set(e.subarray(t,n)),r},Be=function(e,t,n,r){if(G.prototype.fill)return G.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},an=function(e,t,n,r){if(G.prototype.copyWithin)return G.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 ln=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],K=function(e,t,n){var r=Error(t||ln[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},yt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},cn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},un=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,c=r>>6;if(r&8)K(0);var a=6-s,u=i==3?4:i,l=yt(e,a,u);a+=u;var f=c?1<<c:s,p=yt(e,a,f)+(c==1&&256),d=p;if(!s){var h=1<<10+(e[5]>>3);d=h+(h>>3)*(e[5]&7)}if(d>2145386496)K(1);var m=new G((t==1?p||d:t?0:d)+12);return m[0]=1,m[4]=4,m[8]=8,{b:a+f,y:0,l:0,d:l,w:t&&t!=1?t:m.subarray(12),e:d,o:new je(m.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return cn(e,4)+8;K(0)},Ee=function(e){var t=0;for(;1<<t<=e;++t);return t-1},De=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,c=-1,a=-1,u=-1,l=o,f=new sn(512+(o<<2)),p=new on(f,0,256),d=new $e(f,0,256),h=new $e(f,512,o),m=512+(o<<1),w=new G(f,m,o),b=new G(f,m+o);while(c<255&&i>0){var g=Ee(i+1),y=r>>3,A=(1<<g+1)-1,v=(e[y]|e[y+1]<<8|e[y+2]<<16)>>(r&7)&A,M=(1<<g)-1,z=A-i-1,E=v&M;if(E<z)r+=g,v=E;else if(r+=g+1,v>M)v-=z;if(p[++c]=--v,v==-1)i+=v,w[--l]=c;else i-=v;if(!v)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)K(0);var x=0,U=(o>>1)+(o>>3)+3,k=o-1;for(var I=0;I<=c;++I){var F=p[I];if(F<1){d[I]=-F;continue}for(u=0;u<F;++u){w[x]=I;do x=x+U&k;while(x>=l)}}if(x)K(0);for(u=0;u<o;++u){var C=d[w[u]]++,j=b[u]=s-Ee(C);h[u]=(C<<j)-o}return[r+7>>3,{b:s,s:w,n:b,t:h}]},fn=function(e,t){var n=0,r=-1,s=new G(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),a=new $e(s.buffer,268);if(o<128){var u=De(e,t+1,6),l=u[0],f=u[1];t+=o;var p=l<<3,d=e[t];if(!d)K(0);var h=0,m=0,w=f.b,b=w,g=(++t<<3)-8+Ee(d);for(;;){if(g-=w,g<p)break;var y=g>>3;if(h+=(e[y]|e[y+1]<<8)>>(g&7)&(1<<w)-1,i[++r]=f.s[h],g-=b,g<p)break;y=g>>3,m+=(e[y]|e[y+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=f.s[m],w=f.n[h],h=f.t[h],b=f.n[m],m=f.t[m]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var A=e[++t];i[n]=A>>4,i[n+1]=A&15}++t}var v=0;for(n=0;n<r;++n){var M=i[n];if(M>11)K(0);v+=M&&1<<M-1}var z=Ee(v)+1,E=1<<z,D=E-v;if(D&D-1)K(0);i[r++]=Ee(D)+1;for(n=0;n<r;++n){var M=i[n];++c[i[n]=M&&z+1-M]}var x=new G(E<<1),U=x.subarray(0,E),k=x.subarray(E);a[z]=0;for(n=z;n>0;--n){var I=a[n];Be(k,n,I,a[n-1]=I+c[n]*(1<<z-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var F=i[n];if(F){var C=a[F];Be(U,n,C,a[F]=C+(1<<z-F))}}return[t,{n:k,b:z,s:U}]},pn=De(new G([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],mn=De(new G([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],hn=De(new G([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],xt=function(e,t){var n=e.length,r=new je(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Qe=new G(new je([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),gn=xt(Qe,0),qe=new G(new je([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),dn=xt(qe,3),Re=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)K(0);var a=0,u=n.b,l=(r<<3)-8+Ee(o)-u,f=-1;for(;l>c&&f<s;){var p=l>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(l&7);a=(a<<u|d)&i,t[++f]=n.s[a],l-=u=n.n[a]}if(l!=c||f+1!=s)K(0)},bn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;Re(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Re(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Re(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),Re(e.subarray(r),t.subarray(c),n)},yn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Be(n,e[s],t.y,t.y+=c),n;return Be(new G(c),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=c,n;return Je(e,s,a)}if(i==2){var u=e[s],l=u&3,f=u>>2&3,p=u>>4,d=0,h=0;if(l<2)if(f&1)p|=e[++s]<<4|(f&2&&e[++s]<<12);else p=u>>3;else if(h=f,f<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(f==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 m=n?n.subarray(t.y,t.y+t.m):new G(t.m),w=m.length-p;if(l==0)m.set(e.subarray(s,s+=p),w);else if(l==1)Be(m,e[s++],w);else{var b=t.h;if(l==2){var g=fn(e,s);d+=s-(s=g[0]),t.h=b=g[1]}else if(!b)K(0);(h?bn:Re)(e.subarray(s,s+=d),m.subarray(w),b)}var y=e[s++];if(y){if(y==255)y=(e[s++]|e[s++]<<8)+32512;else if(y>127)y=y-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var v=[mn,hn,pn];for(var M=2;M>-1;--M){var z=A>>(M<<1)+2&3;if(z==1){var E=new G([0,0,e[s++]]);v[M]={s:E.subarray(2,3),n:E.subarray(0,1),t:new $e(E.buffer,0,1),b:0}}else if(z==2)r=De(e,s,9-(M&1)),s=r[0],v[M]=r[1];else if(z==3){if(!t.t)K(0);v[M]=t.t[M]}}var D=t.t=v,x=D[0],U=D[1],k=D[2],I=e[a-1];if(!I)K(0);var F=(a<<3)-8+Ee(I)-k.b,C=F>>3,j=0,de=(e[C]|e[C+1]<<8)>>(F&7)&(1<<k.b)-1;C=(F-=U.b)>>3;var be=(e[C]|e[C+1]<<8)>>(F&7)&(1<<U.b)-1;C=(F-=x.b)>>3;var me=(e[C]|e[C+1]<<8)>>(F&7)&(1<<x.b)-1;for(++y;--y;){var le=k.s[de],Te=k.n[de],Me=x.s[me],Le=x.n[me],ve=U.s[be],ce=U.n[be];C=(F-=ve)>>3;var Ce=1<<ve,ue=Ce+((e[C]|e[C+1]<<8|e[C+2]<<16|e[C+3]<<24)>>>(F&7)&Ce-1);C=(F-=qe[Me])>>3;var O=dn[Me]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<qe[Me])-1);C=(F-=Qe[le])>>3;var T=gn[le]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<Qe[le])-1);if(C=(F-=Te)>>3,de=k.t[de]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Te)-1),C=(F-=Le)>>3,me=x.t[me]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Le)-1),C=(F-=ce)>>3,be=U.t[be]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<ce)-1),ue>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=ue-=3;else{var Y=ue-(T!=0);if(Y){if(ue=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=ue}else ue=t.o[0]}for(var M=0;M<T;++M)m[j+M]=m[w+M];j+=T,w+=T;var J=j-ue;if(J<0){var H=-J,oe=t.e+J;if(H>O)H=O;for(var M=0;M<H;++M)m[j+M]=t.w[oe+M];j+=H,O-=H,J=0}for(var M=0;M<O;++M)m[j+M]=m[J+M];j+=O}if(j!=w)while(w<m.length)m[j++]=m[w++];else j=m.length;if(n)t.y+=j;else m=Je(m,0,j)}else if(n){if(t.y+=p,w)for(var M=0;M<p;++M)m[M]=m[w+M]}else if(w)m=Je(m,w);return t.b=a,m}K(2)},xn=function(e,t){if(e.length==1)return e[0];var n=new G(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 Ve(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=un(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 c=yn(e,i,t);if(!c)K(5);if(t)i.e=i.y;else n.push(c),o+=c.length,an(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return xn(n,o)}async function wn(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(Ve(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 wt(e){return new TextDecoder().decode(await wn(e))}var At=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function _e(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 Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),tt=/^[A-Za-z][A-Za-z0-9_]*$/,et=new Map;function nt(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(!et.has(r))et.set(r,t);return r}function rt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&tt.test(e))return nt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,An=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Mn=new Set(["FILE","NOFILE","!DATA"]),Pt=1000000000000000,It=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),vn=new Set(["model","submodel","configuration"]),Cn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function vt(e){let t=Cn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return It.has(n)||vn.has(n)?n:void 0}function kn(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 Tn(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((f)=>Number.isFinite(f)&&Math.abs(f)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let f=0;f<s;f++)c=c.replace(/^\\S+\\s*/,"");let a=kn(c);if(!a.length)return null;let u={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)u.a=i[9];if(s===11)u.b=i[10];let l=a.findIndex((f,p)=>p>0&&f.toUpperCase()==="GLOSSMAP");if(l>0&&a[l+1])u.glossmap=a[l+1];if(t)u.next=!0;return u}var Ln=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let 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 Sn(e,t){let n=e.length,r=1,s=(h)=>h===32||h===9,o=()=>{while(r<n&&s(e.charCodeAt(r)))r++;let h=r,m=e.charCodeAt(r),w=m===45;if(w)m=e.charCodeAt(++r);let b=0,g=0;while(m>=48&&m<=57)b=b*10+(m-48),g++,m=e.charCodeAt(++r);if(g>0&&g<=15&&(r>=n||s(m)))return w?-b:b;while(r<n&&!s(e.charCodeAt(r)))r++;return h<r?+e.slice(h,r):NaN};while(r<n&&s(e.charCodeAt(r)))r++;let i=r;if(r>=n)return null;let c=e.charCodeAt(r),a=c===45,u=0,l=0;if(a)c=e.charCodeAt(++r);while(c>=48&&c<=57)u=u*10+(c-48),l++,c=e.charCodeAt(++r);if(l>0&&l<=15&&(r>=n||s(c))){if(a)u=-u}else{while(r<n&&!s(e.charCodeAt(r)))r++;u=rt(e.slice(i,r))}let f=Array(12);for(let h=0;h<12;h++){let m=o();if(!Number.isFinite(m))return null;f[h]=m}while(r<n&&s(e.charCodeAt(r)))r++;if(r>=n)return null;let p=e.slice(r),d=t.get(p);if(d===void 0)d=Z(/[ \\t]{2,}|\\t/.test(p)?p.split(/\\s+/).join(" "):p),t.set(p,d);if(!Number.isFinite(u))return null;return{t:1,color:u,m:f,file:d}}var En=[0,12,6,9,12,12];function Ct(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=rt(e[1]),r=En[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Z(e.slice(14).join(" "));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Ft(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,a=null,u=[],l=null,f=()=>{if(!a)return;let y=Ln(a.chunks.join("")),A=y[0]===137&&y[1]===80&&y[2]===78&&y[3]===71;(c??=new Map).set(Z(a.name),{name:a.name,bytes:y,...A?{mime:"image/png"}:{}}),a=null},p=new Map,d=!0,h=(y)=>{if(f(),o={name:Z(y),cmds:[]},s.set(o.name,o),!i)i=o.name;u=[],l=null,d=!0},m=!1,w=!1,b=()=>{if(w)return;w=!0,s.clear(),o=null,i=""},g=(y,A)=>{if(l){y.tex=l,l=null;return}let v=u[u.length-1];if(!v)return;if(v.fallback){if(!A)y.fallback=!0}else y.tex=v.map};for(let y of e.split(`\n`)){let A=y.trim();if(!A)continue;if(r&&A.charCodeAt(0)>=50&&A.charCodeAt(0)<=53&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)){if(a||m)continue;if(!o)h(t);let E=A.slice(2).trimStart(),D=E.search(/\\s/),x={t:A.charCodeAt(0)-48,color:rt(D<0?E:E.slice(0,D)),p:[],src:A};g(x,!1),o.cmds.push(x),d=!1;continue}if(A.charCodeAt(0)===48&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)){let E=2;while(A.charCodeAt(E)===32||A.charCodeAt(E)===9)E++;let D=E;while(D<A.length&&A.charCodeAt(D)!==32&&A.charCodeAt(D)!==9)D++;let x=A.slice(E,D),U=/[^\\x21-\\x7e]/.test(x)?A.slice(E).trim().split(/\\s+/)[0]:x;if(!An.has(U)&&!(U.length>=4&&U.length<=6&&Mn.has(U.toUpperCase()))){if(m||a)continue;if(!o)h(t);let k=A.slice(E),I={t:0,text:k};if(x.charCodeAt(0)===33)I.meta=x;if(l=null,d&&!o.org){let C=vt(k);if(C)o.org=C}let F=k.match(Mt);if(F&&!o.movedTo){let C=F[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Z(C)}o.cmds.push(I);continue}}if(A.charCodeAt(0)===49&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)&&!a&&!m){let E=Sn(A,p);if(E){if(!o)h(t);g(E,!1),o.cmds.push(E),d=!1;continue}}let v=A.split(/\\s+/);if(+v[0]===0){let E=A.slice(1).trim(),D=v.length>1&&v[1].length>=4&&v[1].length<=6?v[1].toUpperCase():v[1];if(D==="FILE"){let k=E.slice(5).trimStart().split("\\r")[0].trim();if(k){b(),m=!1,h(k);continue}}if(D==="NOFILE"){f(),o=null,m=!0;continue}if(D==="!DATA"){b(),f(),o=null,m=!1,a={name:E.slice(5).trim(),chunks:[]};continue}if(m)continue;if(a){if(v[1]==="!:")a.chunks.push(v.slice(2).join(""));continue}if(!o)h(t);let x={t:0,text:E};if(v[1]==="STEP")x.step=!0,u=[],l=null;else if(v[1]==="BFC")x.bfc=v.slice(2).join(" ");else if(v[1]==="ROTSTEP")if(x.meta="ROTSTEP",x.step=!0,u=[],l=null,(v[2]??"").toUpperCase()==="END")x.rotstep={x:0,y:0,z:0,mode:"END"};else{let k=(v[5]??"REL").toUpperCase(),I=(F)=>{let C=Number(F);return Number.isFinite(C)?C:0};x.rotstep={x:I(v[2]),y:I(v[3]),z:I(v[4]),mode:["REL","ABS","ADD"].includes(k)?k:"REL"}}else if(v[1]==="BUFEXCHG"){x.meta="BUFEXCHG";let k=(v[2]??"").toUpperCase();x.bufexchg={op:k==="RETRIEVE"?"RETRIEVE":"STORE",buf:v[3]??"A"}}else if(v[1]?.startsWith("!"))x.meta=v[1];if(d&&!o.org){let k=vt(E);if(k)o.org=k}if(v[1]==="!TEXMAP"){let k=(v[2]??"").toUpperCase();if(l=null,k==="START"||k==="NEXT"){let I=Tn(E.replace(/^!TEXMAP\\s+\\S+/i,""),k==="NEXT");if(x.texmap={op:k,...I?{map:I}:{}},I)if((o.texmaps??=[]).push(I),k==="START")u.push({map:I,fallback:!1});else l=I}else if(k==="FALLBACK"){x.texmap={op:k};let I=u[u.length-1];if(I)I.fallback=!0}else if(k==="END")x.texmap={op:k},u.pop()}else if(v[1]==="!:"){l=null;let k=Ct(v.slice(2));if(k)g(k,!0),x.geom=k}else l=null;let U=E.match(Mt);if(U&&!o.movedTo){let k=U[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(k))k+=".dat";o.movedTo=Z(k)}o.cmds.push(x);continue}if(a||m)continue;if(!o)h(t);let z=Ct(v);if(!z){if(/^[2-5][ \\t]/.test(A))d=!1;continue}g(z,!1),o.cmds.push(z),d=!1}return f(),c?{main:i,files:s,data:c}:{main:i,files:s}}var sr=Math.PI/180;function Rt(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 Bt(e,t){let[n,r,s,o,i,c,a,u,l,f,p,d]=e,[h,m,w,b,g,y,A,v,M,z,E,D]=t;return[o*h+i*m+c*w+n,a*h+u*m+l*w+r,f*h+p*m+d*w+s,o*b+i*A+c*z,o*g+i*v+c*E,o*y+i*M+c*D,a*b+u*A+l*z,a*g+u*v+l*E,a*y+u*M+l*D,f*b+p*A+d*z,f*g+p*v+d*E,f*y+p*M+d*D]}var Ge=[0,0,0,1,0,0,0,1,0,0,0,1];var kt=new WeakMap,Pn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Z(t));if(!n)return"part";let r=kt.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&&Pn.test(s.file))?"part":"model";return kt.set(n,r),r}var Tt=new WeakMap;function Dt(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 Lt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?et.get(e)??String(e):String(e),In=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Lt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Lt(e.color)} ${e.p.join(" ")}`,ot=(e,t)=>`${Z(e)}#${t}`;function Fn(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:ot(e.name,t),cmds:n}}function Ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Fn(e,t).cmds.map(In)].join(`\n`)+`\n`}function it(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 Nt(e){let[t,n,r,s,o,i,c,a,u,l,f,p]=e,d=a*p-u*f,h=-(c*p-u*l),m=c*f-a*l,w=s*d+o*h+i*m;if(!Number.isFinite(w)||Math.abs(w)<0.000000000001)return null;let b=1/w,g=[d*b,-(o*p-i*f)*b,(o*u-i*a)*b,h*b,(s*p-i*l)*b,-(s*u-i*c)*b,m*b,-(s*f-o*l)*b,(s*a-o*c)*b];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 Rn=(e)=>String(+e.toFixed(6)||0),St=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Ot(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Rn).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 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${it(r)}`,source:r}}var Bn=(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 Dn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),u=Math.cos(n*r);return[c*u,-c*a,i,o*a+s*i*u,o*u-s*i*a,-s*c,s*a-o*i*u,s*u+o*i*a,o*c]}var Et=new WeakMap;function zt(e){let t=Et.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=Dn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Bn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Et.set(e,n),n}class at extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var Un=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=Pt))return!1;return!0},$t=999999,_t=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Gt=new WeakMap,jt=new WeakMap;function Nn(e,t){let n=jt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Gt.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},jt.set(t,n);let r=n.parts.get(e);if(!r){let s=Z(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-${it(o)}`,source:o},n.parts.set(e,r)}return r}function On(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,a=0,u=[],l=(w,b)=>{if(w.length)return[...w,b];let g=u[b];if(!g)u[b]=g=[b];return g},f=new Set,p=t.maxInstances??2000000,d=0,h=(w,b)=>{let g=w.name+"#"+b,y=c.get(g);if(!y){let A;y=Object.assign(()=>A??=Ut(w,b),{file:w,step:b}),c.set(g,y)}return y},m=(w,b,g,y,A,v,M,z,E=null,D=[],x=[],U=void 0,k=null)=>{let I=w.files.get(b);if(!I||M>r||f.has(I))return;if(++d>p)throw new at("model",p);f.add(I);let F=k,C=0,j=M>0?++a:0,de=i&&j?[...D,j]:D,be=i&&j?[...x,g]:x,me=i&&!E?new Map:null,le=-1,Te=0,Me=(O,T,Y,J,H,oe,L)=>{if(le!==C)le=C,Te=0;let B=me?.get(C+"|"+T);if(B)return B.n++,m(O,O===w?T:O.main,Y,J,A+"/"+T,[...H,$t],M+1,oe,[...H,$t],de,be,L,F);let P=[...H,Te++],R=n.length;m(O,O===w?T:O.main,Y,J,A+"/"+T,P,M+1,oe,E,de,be,L,F),me?.set(C+"|"+T,{n:1,from:R,to:n.length})},Le=zt(I),ve=s?Dt(I):[],ce=0,Ce=(O,T,Y,J,H,oe,L,B,P)=>{if(E)J=E;if(++d>p)throw new at("model",p);let R={part:O,color:T,m:Y,step:J[0],steps:J,localStep:H,path:A};if(B)R.colour=B;if(j){if(R.sub=j,i)R.subPath=de,R.subMats=be}if(oe)R.embedded=!0;if(L){let N=Ot(O,L);R.texPart=N.name,R.texSource=N.source}else if(P){let N=Nn(O,P);R.colPart=N.name,R.colSource=N.source}let S=Le[H];if(S)R.view=S;return n.push(R),R},ue=(O)=>{while(ce<ve.length&&ve[ce]<=O){let T=ve[ce++];Ce(ot(I.name,T),y,g,l(v,T),T,!1,null,U,k).source=h(I,T)}};for(let O of I.cmds){if(O.t===0&&O.step){C++;continue}let T=O;if(T.t>=2||T.t===0&&T.geom&&T.geom.t>=2){ue(C);continue}if(T.t===0){if(T.meta==="!COLOUR"){let S=$n(T.text);if(S&&S.code!==16&&S.code!==24)Gt.set(S,T.text),(F=new Map(F??[])).set(S.code,S);continue}if(o&&T.geom?.t===1)T=T.geom;else continue}if(T.t!==1)continue;if(o&&T.fallback)continue;let Y=g===Ge?T.m:Bt(g,T.m);if(!Un(Y))continue;let J=T.color===16?y:T.color,H=T.color===16?U:F?.get(T.color),oe=l(v,C),L=o?T.tex??z:null,B=L?Nt(T.m):null,P=L&&B?Rt(L,B):null;if(w.files.has(T.file)){if(st(w,T.file)==="model"){Me(w,T.file,Y,J,oe,P,H);continue}Ce(T.file,J,Y,oe,C,!0,P,H,F);continue}let R=t.resolveModel?.(T.file);if(R){Me(R,T.file,Y,J,oe,P,H);continue}Ce(T.file,J,Y,oe,C,!1,P,H,F)}if(ue(1/0),f.delete(I),me){for(let O of me.values())if(O.n>1)for(let T=O.from;T<O.to;T++)n[T].mult??=O.n}};if(st(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Ge],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return m(e,e.main,Ge,16,e.main,[],0,null),n}function Ht(e,t="main.ldr",n){return On(Ft(e,t,{geometryText:!0}),n)}var zn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function lt(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 Vt(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=lt(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 $n(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",c=255,a=0,u={type:"default"},l=1;while(l<n.length){let f=n[l].toUpperCase(),p=n[l+1];if(f==="CODE")s=p!==void 0&&tt.test(p)?nt(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,l+=2;else if(f==="VALUE"){let d=lt(p);if(d)o=d;l+=2}else if(f==="EDGE")i=lt(p)??p,l+=2;else if(f==="ALPHA")c=+p,l+=2;else if(f==="LUMINANCE")a=+p,l+=2;else if(f==="CHROME")u={type:"chrome"},l+=1;else if(f==="PEARLESCENT")u={type:"pearlescent"},l+=1;else if(f==="RUBBER")u={type:"rubber"},l+=1;else if(f==="MATTE_METALLIC")u={type:"matte_metallic"},l+=1;else if(f==="METAL")u={type:"metal"},l+=1;else if(f==="MATERIAL"){let d=(n[l+1]||"").toUpperCase();if(d==="GLITTER"){let{grain:h,next:m}=Vt(n,l+2);u={type:"glitter",material:h},l=m}else if(d==="SPECKLE"){let{grain:h,next:m}=Vt(n,l+2);u={type:"speckle",material:h},l=m}else if(d==="FABRIC"){let h=(n[l+2]||"").toUpperCase(),m=["VELVET","CANVAS","STRING","FUR"].includes(h)?h.toLowerCase():void 0;u={type:"fabric",kind:m},l+=m?3:2}else l=n.length}else if(zn.has(f))l+=1;else l+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(a)?a:0,finish:u}}function jn(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,c=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:c,finish:"glitter"}}case"speckle":{let i=e.finish.material,c=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:c,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 ct(e){let t=jn(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 Vn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Z(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Z(t),r)}let a=i.trim().replace(/\\s+/g," ");if(a)r.push(a)}return n}var _n=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Z(t.slice(14).join(" ")):null};function Gn(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 Wt(e,t,n="main.ldr"){let r=[...t],s=new Map;if(!r.length)return s;let o=Vn(e,n);for(let i of r){let c=Z(i);if(!o.has(c)||s.has(c))continue;let a=new Set([c]),u=[c];while(u.length)for(let f of o.get(u.pop())){let p=_n(f);if(p&&o.has(p)&&!a.has(p))a.add(p),u.push(p)}let l=[c,...[...a].filter((f)=>f!==c).sort()].map((f)=>"0 FILE "+(f===c?"":f)+`\n`+o.get(f).join(`\n`)).join(`\n`);s.set(c,`emb/${Gn(l)}.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,Kt=new WeakMap,ut=null,ft="",pt=null;function Hn(e,t){if(e===ut&&t===ft)return pt;let n=Kt.get(e);if(!n)Kt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return ut=e,ft=t,pt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],a=[];s.studs.forEach((d,h)=>{c.push(d[0]),a.push(d[1]);for(let m=0;m<12;m++)i[h*12+m]=d[2+m]});let u=null,l=0,f=0;if(s.mask){l=s.mask[0],f=s.mask[1];let d=s.mask[2];u=new Uint8Array(d.length);for(let h=0;h<d.length;h++)u[h]=d.charCodeAt(h)===49?1:0}let p=!!u;if(u){for(let d=0;d<u.length;d++)if(u[d]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:a,mask:u,nx:l,nz:f,full:p}),ut=e,ft=t,pt=r,r}var Ie=1073741824;class Pe{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=Pe.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let a=s[c];if(a===0)return-1;if(a===r){let u=c<<2;if(o[u]===e&&o[u+1]===t&&o[u+2]===n)return o[u+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=Pe.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,a=this.slot(e,t,n);for(;;){let u=o[a],l=a<<2;if(u===0)return o[a]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(u===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let f=i[l+3];return i[l+3]=r,f}a=a+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Yt{grp=new Pe(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],a=[];for(let f=0;f<r;f++){let p=e[f],d=t[f],h=n[f],m=(p%20+20)%20,w=(h%20+20)%20,b=this.group(d,m,w);if(b<0)b=s.length,this.grp.put(d,m,w,b),this.lg=b,s.push(0),o.push(p),i.push(p),c.push(h),a.push(h);if(s[b]++,p<o[b])o[b]=p;else if(p>i[b])i[b]=p;if(h<c[b])c[b]=h;else if(h>a[b])a[b]=h}let u=0,l=0;for(let f=0;f<s.length;f++){let p=(i[f]-o[f])/20+1,d=(a[f]-c[f])/20+1,h=p*d;if(this.gX0.push(o[f]),this.gZ0.push(c[f]),this.gNx.push(p),this.gNz.push(d),h<=64*s[f]+1024&&u+h<2147483648)this.gBits.push(u),u+=h;else this.gBits.push(-1),l+=s[f]}this.bits=new Uint8Array(Math.ceil(u/8)),this.rest=new Pe(l);for(let f=0;f<r;f++){let p=e[f],d=t[f],h=n[f],m=this.group(d,(p%20+20)%20,(h%20+20)%20),w=this.gBits[m];if(w<0){this.rest.put(p,d,h,1);continue}let b=w+(p-this.gX0[m])/20*this.gNz[m]+(h-this.gZ0[m])/20;this.bits[b>>>3]|=1<<(b&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Wn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Fe=(e,t,n)=>e>-Ie&&e<Ie&&t>-Ie&&t<Ie&&n>-Ie&&n<Ie,Ue=2147483647;function Xn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function mt(e,t,n){return Zt(e,t,n,-1)??Zt(e,t,n,Jt)}var Jt=0;function Zt(e,t,n,r){let o=new Map,i=(L)=>{let B=o.get(L);if(B===void 0)o.set(L,B=Xn(t,L));return B},c=e.length,a=0,u=0,l=0,f=Array(c);for(let L=0;L<c;L++){let B=f[L]=Hn(t,e[L].part);if(B){if(l+=B.nStuds,B.mask)a++}}let p=new Float64Array(a),d=new Float64Array(a),h=new Float64Array(a),m=new Float64Array(a),w=new Int32Array(a),b=new Int32Array(a),g=new Float64Array(a),y=new Float64Array(a),A=[],v=new Int32Array(a),M=new Float64Array(a*9),z=new Uint8Array(a);if(r<0)r=a*4+64;let E=new Pe(e.length*2),D=new Int32Array(r),x=new Int32Array(r),U=0,k=0;for(let L=0;L<e.length;L++){let B=e[L],P=B.m,R=t.parts[B.part];if(!R||!R.mask||!Xt(P)||i(B.color))continue;let S=R.bbox,N=1/0,V=-1/0,q=1/0,W=-1/0;for(let X=0;X<2;X++)for(let ie=0;ie<2;ie++){let ee=X?S[3]:S[0],Se=ie?S[5]:S[2],Ae=P[0]+P[3]*ee+P[5]*Se,ge=P[2]+P[9]*ee+P[11]*Se;if(Ae<N)N=Ae;if(Ae>V)V=Ae;if(ge<q)q=ge;if(ge>W)W=ge}let _=Math.round((P[1]+S[4])*2),Q=f[L],ae=Math.floor(N/40),ye=Math.floor(V/40),xe=Math.floor(q/40),we=Math.floor(W/40);if(!((ye-ae+1)*(we-xe+1)<=65536)||!Fe(_,ae,xe)||!Fe(_,ye,we))continue;let he=Math.floor((N+5)/40),te=Math.floor((V-5)/40),ne=Math.floor((q+5)/40),re=Math.floor((W-5)/40),ke=he<=te&&ne<=re?(te-he+1)*(re-ne+1):0;k+=ke;let fe=-1;for(let X=he<=te&&ne<=re?E.get(_,he,ne):-1,ie=0;X>=0&&ie<8;X=D[X],ie++){let ee=x[X];if(p[ee]!==N||d[ee]!==V||h[ee]!==q||m[ee]!==W||A[ee]!==Q)continue;let Se=e[w[ee]].m,Ae=!0;for(let ge=0;ge<12;ge++)if(Se[ge]!==P[ge]){Ae=!1;break}if(Ae){fe=ee;break}}if(fe>=0){let X=n?n[L]:0;if(n&&X<n[w[fe]])b[fe]=w[fe],w[fe]=L;else if(b[fe]<0||n&&X<n[b[fe]])b[fe]=L;continue}let se=u++;p[se]=N,d[se]=V,h[se]=q,m[se]=W,w[se]=L,b[se]=-1,A.push(Q),g[se]=S[0],y[se]=S[2],v[se]=_;let pe=se*9;if(M[pe]=P[0],M[pe+1]=P[1],M[pe+2]=P[2],M[pe+3]=P[3],M[pe+4]=P[6],M[pe+5]=P[9],M[pe+6]=P[5],M[pe+7]=P[8],M[pe+8]=P[11],z[se]=Q.full&&S[3]-S[0]<=20*Q.nx&&S[5]-S[2]<=20*Q.nz&&P[4]===0&&P[6]===0&&P[8]===0&&P[10]===0&&Wn(P[3],P[5],P[9],P[11])?1:0,U+ke>r){U=r+1;continue}for(let X=he;X<=te;X++)for(let ie=ne;ie<=re;ie++){if(!Fe(_,X,ie))continue;let ee=U++;x[ee]=se,D[ee]=E.put(_,X,ie,ee)}}if(U>r)return Jt=k,null;let I=[0,5,-5,5,-5],F=[0,5,5,-5,-5],C=(L,B,P,R)=>{if(!(B-6>=p[L]-0.5&&B+6<=d[L]+0.5&&R-6>=h[L]-0.5&&R+6<=m[L]+0.5))return!1;if(z[L]===1)return!0;let S=L*9,N=A[L],V=g[L],q=y[L],W=B-M[S],_=P-M[S+1],Q=R-M[S+2],ae=M[S+3]*W+M[S+4]*_+M[S+5]*Q,ye=M[S+6]*W+M[S+7]*_+M[S+8]*Q,{nx:xe,nz:we,mask:he}=N;for(let te=0;te<5;te++){let ne=Math.floor((ae+I[te]-V)/20),re=Math.floor((ye+F[te]-q)/20);if(ne<0||re<0||ne>=xe||re>=we||he[ne*we+re]!==1)return!1}return!0},j=NaN,de=NaN,be=NaN,me=-1,le=-1,Te=(L,B,P,R)=>{let S=Math.round(B*2),N=Math.floor(L/40),V=Math.floor(P/40);if(!Fe(S,N,V))return Ue;let q=Ue;if(!n&&le>=0&&v[le]===S&&(w[le]!==R||b[le]>=0)&&C(le,L,B,P))return 0;if(S!==j||N!==de||V!==be)j=S,de=N,be=V,me=E.get(S,N,V);for(let W=me;W>=0;W=D[W]){let _=x[W],Q=w[_];if(Q===R&&(Q=b[_])<0)continue;if(!C(_,L,B,P))continue;if(!n)return le=_,0;let ae=n[Q];if(ae<q)q=ae}return q},Me=new Uint8Array(l),Le=new Uint8Array(l),ve=0,ce=n?new Pe(l,4):null,Ce=n?null:new Int32Array(l),ue=n?null:new Int32Array(l),O=n?null:new Int32Array(l),T=0,Y=n?new Int32Array(l).fill(Ue):void 0;for(let L=0,B=0;L<e.length;L++){let P=e[L],R=f[L];if(!R)continue;let S=P.m,N=R.studM,V=S[0],q=S[1],W=S[2],_=S[3],Q=S[4],ae=S[5],ye=S[6],xe=S[7],we=S[8],he=S[9],te=S[10],ne=S[11];for(let re=0;re<R.nStuds;re++,B++){let ke=re*12,fe=N[ke+4],se=N[ke+7],pe=N[ke+10];if(!(Math.abs(ye*fe+xe*se+we*pe-1)<0.001&&Math.abs(_*fe+Q*se+ae*pe)<0.001&&Math.abs(he*fe+te*se+ne*pe)<0.001))continue;Le[B]=1;let X=N[ke],ie=N[ke+1],ee=N[ke+2],Se=V+_*X+Q*ie+ae*ee,Ae=q+ye*X+xe*ie+we*ee,ge=W+he*X+te*ie+ne*ee,gt=Te(Se,Ae,ge,L);if(gt!==Ue){if(Me[B]=1,ve++,Y)Y[B]=gt}let Ne=Math.round(Se),Oe=Math.round(Ae),ze=Math.round(ge);if(!Fe(Ne,Oe,ze))continue;if(!ce){Ce[T]=Ne,ue[T]=Oe,O[T++]=ze;continue}let dt=n[L],bt=ce.get(Ne,Oe,ze);if(bt<0||dt<bt)ce.put(Ne,Oe,ze,dt)}}let J=ce?null:new Yt(Ce,ue,O,T),H=new Uint8Array(e.length),oe=n?new Int32Array(e.length).fill(Ue):void 0;for(let L=0;L<e.length;L++){let B=e[L],P=t.parts[B.part];if(!P||!P.under||!Xt(B.m)||i(B.color))continue;let R=P.bbox,S=Math.round((R[3]-R[0])/20),N=Math.round((R[5]-R[2])/20);if(!S||!N||S*N>4096)continue;let V=B.m,q=Math.round(V[1]+R[4]),W=!0,_=0;for(let Q=0;Q<S&&W;Q++)for(let ae=0;ae<N;ae++){let ye=R[0]+10+20*Q,xe=R[2]+10+20*ae,we=V[0]+V[3]*ye+V[5]*xe,he=V[2]+V[9]*ye+V[11]*xe,te=Math.round(we),ne=Math.round(he),re=!Fe(te,q,ne)?-1:ce?ce.get(te,q,ne):J.has(te,q,ne)?1:-1;if(re<0){W=!1;break}if(re>_)_=re}if(W){if(H[L]=1,oe)oe[L]=_}}return{nStuds:l,studHidden:Me,studUp:Le,underHidden:H,studsHidden:ve,studHideStep:Y,underHideStep:oe}}function ht(e,t,n){let r=(l)=>l.colPart&&t.parts[l.colPart]?l.colPart:n&&l.texPart&&t.parts[l.texPart]?l.texPart:l.part,s=new Map,o=new Map,i=(l)=>{let f=l.colour;if(!f)return String(l.color);let p=o.get(f);if(p!==void 0)return p;let d=t.colorTable?.[l.color],h=d?.hex??t.colors?.[l.color],m=d?ct({alpha:d.alpha??255,luminance:d.luminance??0,finish:d.finish??{type:"default"}}):"default:op",w=ct(f);if(p=h&&h.toUpperCase()===f.hex.toUpperCase()&&m===w?String(l.color):f.hex.toUpperCase()+"/"+w,p!==String(l.color))s.set(p,f);return o.set(f,p),p},c=e.map((l)=>({part:r(l),color:i(l),m:l.m,steps:l.steps})),{stepOf:a,nSteps:u}=Kn(c);return{all:c,stepOf:a,nSteps:u,localColours:s}}function Kn(e){let t=!0;for(let o=0;o<e.length;o++){let i=e[o].steps;if(i.length!==1){t=!1;break}let c=i[0];if(!(Number.isInteger(c)&&c>=0&&c<1e6)){t=!1;break}}if(t){let o=new Set;for(let a=0;a<e.length;a++)o.add(e[a].steps[0]);let i=[...o].sort((a,u)=>a-u),c=new Map(i.map((a,u)=>[a,u]));return{stepOf:e.map((a)=>c.get(a.steps[0])),nSteps:i.length}}let n=e.map((o)=>_t(o.steps)),r=[...new Set(n)].sort(),s=new Map(r.map((o,i)=>[o,i]));return{stepOf:n.map((o)=>s.get(o)),nSteps:r.length}}function Qt(e,t,n=!0){let r=ht(e,t,n);return mt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ze="https://ldr-parts-cdn.baconbrix.workers.dev/v1/",We=new Map,He=new Map;function Xe(e=Ze,t=fetch){let n=We.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(()=>We.delete(e)),We.set(e,n);return n}var Zn=(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"),Ke=(e,t)=>Zn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ke(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ke(r,t)])):e;function Yn(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 h=new DataView(d).getUint32(0,!0),m=new Uint8Array(d,4+h),w=r;n.push(m),r+=m.byteLength;let b=(4-r%4)%4;if(b)n.push(new Uint8Array(b)),r+=b;for(let[g,y]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ke(y,w);for(let[g,y]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ke(y,w)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+c.length)%4)%4,u=4+c.length+a,l=new Uint8Array(u+r);new DataView(l.buffer).setUint32(0,c.length+a,!0),l.set(c,4),l.fill(32,4+c.length,u);let f=u;for(let p of n)l.set(p,f),f+=p.byteLength;return _e(l.buffer)}async function Jn(e,t={}){e=[...e];try{return await qt(e,t)}catch(n){let r=t.cdn??Ze,s=t.fetch??fetch;We.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await qt(e,{...t,fetch:o})}catch{throw n}}}async function qt(e,t){let n=t.cdn??Ze,r=t.fetch??fetch,s=t.gap??16384,o=await Xe(n,r),i=[...new Set([...new Set(e)].map(Z))],c=[],a=[];for(let g of i){if(He.has(n+g))continue;let y=o.parts[g];if(y)a.push({name:g,off:y[0],len:y[1],file:y[2]??0});else c.push(g)}a.sort((g,y)=>g.file-y.file||g.off-y.off);let u=[];for(let g of a){let y=u[u.length-1];if(y&&y.file===g.file&&g.off-y.end<=s)y.end=Math.max(y.end,g.off+g.len),y.items.push(g);else u.push({file:g.file,start:g.off,end:g.off+g.len,items:[g]})}let l=0,f=0,p=0,d=new Map,h=async()=>{while(p<u.length){let g=u[p++],y=d.get(g.file);if(y)y=y.subarray(g.start,g.end);else{let A=await r(new URL(o.archives[g.file],n).href,{headers:{Range:`bytes=${g.start}-${g.end-1}`,"Accept-Encoding":"identity"}});if(!A.ok)throw Error(`ldr: parts CDN ${A.status}`);if(f++,y=new Uint8Array(await A.arrayBuffer()),l+=y.byteLength,A.status===200)d.set(g.file,y),y=y.subarray(g.start,g.end)}for(let A of g.items){let v=Ve(y.subarray(A.off-g.start,A.off-g.start+A.len)),M=v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength);He.set(n+A.name,_e(M))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,u.length)},h));let m=i.filter((g)=>He.has(n+g)).map((g)=>He.get(n+g)),w={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:m.length?Yn(m,w):_e(Qn(w)),missing:c,requests:f,bytes:l}}function Qn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...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 qn(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 en(e,t,n){let r=0,s=0,o=!1,i=new Set,c=new Map;for(let a of e){let u;if(a.embedded)u=t.get(a.part);else if(u=c.get(a.part),u===void 0)c.set(a.part,u=Z(a.part));let l=u?n.parts[u]:void 0;if(!l)continue;if(l[3]!=null)o=!0,r+=l[3];if(!i.has(u))i.add(u),s+=l[1]}return{bodyTris:r,packBytes:s,known:o}}class Ye 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 tn(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Xe(t.cdn??Ze,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(x)=>{if(!x.ok)throw Error(`ldr: ${x.status} fetching ${e}`);return wt(await x.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":At(e)),a=Ht(o,c,{looseGeometry:!1,callouts:t.callouts}),u=performance.now();t.onParsed?.(a),await s;let l=Wt(o,new Set(a.filter((x)=>x.embedded).map((x)=>x.part)),c),f=(x,U)=>t.maxBodyTris!=null&&x>t.maxBodyTris||t.maxPackBytes!=null&&U>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(x)=>new Ye({...x,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),h="full";if(p){let x=en(a,l,await s);if(f(x.known?x.bodyTris:0,x.packBytes)){if(!t.lowCdn)throw d(x);let U=await Xe(t.lowCdn,r).catch(()=>null);if(!U)throw d(x);let k=en(a,l,U);if(f(k.known?k.bodyTris:0,k.packBytes))throw d(k);h="low"}}let m=[...a.filter((x)=>!x.embedded).map((x)=>x.part),...l.values()],w=async()=>{let x=await Jn(m,h==="low"?{...t,cdn:t.lowCdn}:t);for(let[U,k]of l){let I=x.pack.header.parts[k];if(I)x.pack.header.parts[U]=I}return{...x,packBytes:x.pack.buffer?.byteLength??x.pack.bytes??0,bodyTris:qn(a,x.pack)}},b=await w();if(p&&f(b.bodyTris,b.packBytes)&&h==="full"&&t.lowCdn&&await Xe(t.lowCdn,r).then(()=>!0,()=>!1)){h="low";let x=b;b=await w(),b.requests+=x.requests,b.bytes+=x.bytes}if(p&&f(b.bodyTris,b.packBytes))throw d(b);let{pack:g,missing:y,requests:A,bytes:v}=b,M=new Map([...l].map(([x,U])=>[U,x])),z=y.map((x)=>M.get(x)??x),E=performance.now(),D=t.cull?Qt(a,g.header,t.textures!==!1):void 0;return{insts:a,pack:g,tier:h,missing:z,requests:A,bytes:v,cull:D,timings:{fetchModel:i-n,parse:u-i,parts:E-u,...D?{cull:performance.now()-E}:{}}}}var er=new Set(["part","color","m","step","steps","localStep","path"]);function nn(e){let t=e.length,n=0;for(let h of e){if(typeof h.part!=="string"||typeof h.path!=="string"||typeof h.color!=="number"||typeof h.step!=="number"||typeof h.localStep!=="number"||!Array.isArray(h.m)||h.m.length!==12||!Array.isArray(h.steps))return null;n+=h.steps.length}let r=[],s=new Map,o=(h)=>{let m=s.get(h);if(m===void 0)s.set(h,m=r.length),r.push(h);return m},i=new Uint32Array(t),c=new Uint32Array(t),a=new Float64Array(t*3),u=new Float64Array(t*12),l=new Uint32Array(t+1),f=new Float64Array(n),p=[],d=0;for(let h=0;h<t;h++){let m=e[h];i[h]=o(m.part),c[h]=o(m.path),a[h*3]=m.color,a[h*3+1]=m.step,a[h*3+2]=m.localStep;let w=m.m,b=h*12;for(let A=0;A<12;A++)u[b+A]=w[A];let g=m.steps;for(let A=0;A<g.length;A++)f[d++]=g[A];l[h+1]=d;let y=null;for(let A in m)if(!er.has(A))(y??={})[A]=m[A];if(y)p.push([h,y])}return{n:t,strs:r,part:i,path:c,num:a,m:u,so:l,steps:f,extra:p}}var rn=(e)=>[e.part.buffer,e.path.buffer,e.num.buffer,e.m.buffer,e.so.buffer,e.steps.buffer];self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await tn(n,{...r,cull:!1,onParsed:(f)=>{let p=nn(f);if(p)self.postMessage({id:t,packed:p},rn(p));else 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(),c=ht(s.insts,s.pack.header,r.textures!==!1),a=mt(c.all,s.pack.header,r.stepCull&&c.nSteps>1?c.stepOf:void 0),u=performance.now()-i,l=[];for(let f of[a.studHidden,a.studUp,a.underHidden,a.studHideStep,a.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:a,ms:u},l)}catch(s){if(s instanceof Ye||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';
5638
5647
 
5639
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/inst-io.ts
5648
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/inst-io.ts
5640
5649
  var CORE = new Set(["part", "color", "m", "step", "steps", "localStep", "path"]);
5641
5650
  function unpackInstances(p) {
5642
5651
  const { n, strs, part, path, num, m, so, steps, extra } = p;
@@ -5661,7 +5670,7 @@ function unpackInstances(p) {
5661
5670
  return out;
5662
5671
  }
5663
5672
 
5664
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/cdn.ts
5673
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/cdn.ts
5665
5674
  var worker;
5666
5675
  var seq = 0;
5667
5676
  var pending = new Map;
@@ -5777,7 +5786,7 @@ async function loadModel(source, o = {}) {
5777
5786
  timings: { ...prep.timings, parts: t3 - t0 - prep.timings.fetchModel - prep.timings.parse, build: t4 - t3, total: t4 - t0 }
5778
5787
  });
5779
5788
  }
5780
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/usdz.ts
5789
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/usdz.ts
5781
5790
  var IDENT = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1];
5782
5791
  var MAX_ERR = 8;
5783
5792
  var REL_ERR = 0.1;
@@ -6409,7 +6418,7 @@ function hiddenInstances(n, items, geo, clear, RES = 512) {
6409
6418
  hidden[k] = seen[k] ? 0 : 1;
6410
6419
  return hidden;
6411
6420
  }
6412
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/library.ts
6421
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/library.ts
6413
6422
  import { existsSync, readFileSync, statSync } from "fs";
6414
6423
  import { join } from "path";
6415
6424
  var xf = (m, x, y, z) => [m[3] * x + m[4] * y + m[5] * z + m[0], m[6] * x + m[7] * y + m[8] * z + m[1], m[9] * x + m[10] * y + m[11] * z + m[2]];
@@ -6759,11 +6768,11 @@ class Library {
6759
6768
  return insts;
6760
6769
  }
6761
6770
  }
6762
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/build-pack.ts
6771
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/build-pack.ts
6763
6772
  import fs3 from "node:fs";
6764
6773
  import path3 from "node:path";
6765
6774
 
6766
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/resolver.ts
6775
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/resolver.ts
6767
6776
  import fs from "node:fs";
6768
6777
  import path from "node:path";
6769
6778
  var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
@@ -7092,11 +7101,11 @@ function collectDeps(lib, refs) {
7092
7101
  return out;
7093
7102
  }
7094
7103
 
7095
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/compile.ts
7104
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/compile.ts
7096
7105
  import fs2 from "node:fs";
7097
7106
  import path2 from "node:path";
7098
7107
 
7099
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/lod.ts
7108
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/lod.ts
7100
7109
  import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
7101
7110
  await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
7102
7111
  function reorderMesh(P, N, C, I) {
@@ -7402,7 +7411,7 @@ function levelLines(P, I, E, err, always, tol = 0.01) {
7402
7411
  return out;
7403
7412
  }
7404
7413
 
7405
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/compile.ts
7414
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/compile.ts
7406
7415
  class BfcState {
7407
7416
  accum;
7408
7417
  ccw = true;
@@ -8363,7 +8372,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
8363
8372
  return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
8364
8373
  }
8365
8374
 
8366
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/build-pack.ts
8375
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/build-pack.ts
8367
8376
  function packCompilerOpts(o) {
8368
8377
  return { studs: o.studs ?? "low", prims: o.primitives ?? "full", weld: o.weld ?? true, separateStuds: true, cond: !!o.cond, tex: !!o.textures, ...o.partWorkLimit ? { workLimit: o.partWorkLimit } : {} };
8369
8378
  }
@@ -8435,7 +8444,7 @@ function buildPack(o) {
8435
8444
  const warnings = [...lib.conflicts].map((n) => `${n}: defined differently by two models; the first definition is used`);
8436
8445
  return { data: encodePack(parts, kinds, comp.opts.weld, extra, { texture, lod: o.lod !== false, reorder: !!o.reorder }), parts: parts.size, studKinds: kinds.size, missing: [...missing], ...warnings.length ? { warnings } : {} };
8437
8446
  }
8438
- // ../../../../../../../tmp/ldr-build-vpoU1w/src/node/promote.ts
8447
+ // ../../../../../../../tmp/ldr-build-s89ZOB/src/node/promote.ts
8439
8448
  var GEOM = /^\s*[2-5]\s/;
8440
8449
  var REF = /^\s*1\s/;
8441
8450
  var FILE = /^\s*0\s+FILE\s+(\S.*?)\s*$/i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldr",
3
- "version": "0.34.12",
3
+ "version": "0.34.13",
4
4
  "description": "High-performance LEGO (LDraw) rendering for three.js: instanced parts packs, hidden stud/tube culling, low-detail studs, indexed edges, build steps.",
5
5
  "license": "MIT",
6
6
  "author": "Evan Bacon",