ldr 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -103,7 +103,7 @@ Light the scene (or set `scene.environment`) as you would for any `MeshStandardM
103
103
  | `resolveModel(name)` | – | Resolves an external reference to a `Doc`, such as a model loaded separately. Return `null` to treat it as a part. |
104
104
  | `maxDepth` | `64` | Submodel nesting limit (cycle guard). |
105
105
 
106
- MPD-embedded parts, such as Studio/OMR unofficial parts or stickers, become part instances (`embedded: true`) and override library parts of the same name. `loadModel` asks the parts CDN for them by a hash of their definition (`embeddedKeys`), so a CDN built with `--embedded <model dir>` serves the embedded parts of those models (the demo CDN carries the ones in its 1,773 catalog models).
106
+ MPD-embedded parts, such as Studio/OMR unofficial parts or stickers, become part instances (`embedded: true`) and override library parts of the same name. `loadModel` asks the parts CDN for them by a hash of their definition (`embeddedKeys`), so a CDN built with `--embedded <model dir>` serves the embedded parts of those models (the demo CDN carries the ones in its 1,835 catalog models).
107
107
 
108
108
  **Packs and rendering**
109
109
 
@@ -111,6 +111,7 @@ MPD-embedded parts, such as Studio/OMR unofficial parts or stickers, become part
111
111
  |---|---|
112
112
  | `loadPack(url) → Promise<Pack>` | Fetches, decompresses and decodes a pack. zstd and gzip are detected automatically. |
113
113
  | `decompressPack(bytes)` / `decodePack(buffer)` | Same, from bytes you already have. |
114
+ | `decodeModelText(bytes) → Promise<string>` / `modelFileName(url)` | Model file bytes to LDraw text (zstd / gzip detected and inflated, then UTF-8), and the file name `loadModel` uses for a URL (`8466-1.mpd.zst` → `8466-1.mpd`). `loadModel` reads model URLs this way, so large models can be hosted as `.mpd.zst`. |
114
115
  | `createLdrObject(instances, pack, options?) → LdrObject` | High-level three.js object (see below). |
115
116
  | `createInstancedEdges(pos, instancedMesh, material?)` | Welded, indexed edge lines that share an `InstancedMesh`'s instance matrices. |
116
117
  | `conditionalLines(pack, entry, which?)` / `createInstancedConditionalEdges(cond, instancedMesh, material?)` / `conditionalLineVisible` | Type-5 conditional lines from a `cond` pack. A vertex shader keeps a segment only where both control points project to the same side of the line. |
package/dist/cli.js CHANGED
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/cli.ts
3
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/cli.ts
4
4
  import fs4 from "node:fs";
5
5
  import zlib from "node:zlib";
6
6
 
7
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/build-pack.ts
7
+ // ../../../../../../../tmp/ldr-build-t1RiNG/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-MHOtAg/src/node/resolver.ts
11
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/resolver.ts
12
12
  import fs from "node:fs";
13
13
  import path from "node:path";
14
14
 
15
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/spec.ts
15
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/spec.ts
16
16
  var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
17
17
  function parseColor(tok) {
18
18
  if (/^0x/i.test(tok))
@@ -705,7 +705,7 @@ function fileStepViews(f) {
705
705
  return out;
706
706
  }
707
707
 
708
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/model.ts
708
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/model.ts
709
709
  var CALLOUT_END = 999999;
710
710
  var stepKey = (steps) => steps.map((x) => String(x).padStart(6, "0")).join(".") + "~";
711
711
  function flatten(doc, opts = {}) {
@@ -1055,7 +1055,7 @@ function parseLDConfig(text) {
1055
1055
  return out;
1056
1056
  }
1057
1057
 
1058
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/resolver.ts
1058
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/resolver.ts
1059
1059
  var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
1060
1060
  var UNDER_STUD_RE = /^(stud3|stud3a|stud4.*|stud12|stud16.*|stud18a)\.dat$/i;
1061
1061
  var norm2 = (ref) => ref.trim().replace(/\\/g, "/").toLowerCase();
@@ -1325,11 +1325,11 @@ function collectDeps(lib, refs) {
1325
1325
  return out;
1326
1326
  }
1327
1327
 
1328
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/compile.ts
1328
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/compile.ts
1329
1329
  import fs2 from "node:fs";
1330
1330
  import path2 from "node:path";
1331
1331
 
1332
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/lod.ts
1332
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/lod.ts
1333
1333
  import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
1334
1334
  await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
1335
1335
  function reorderMesh(P, N, C, I) {
@@ -1521,7 +1521,7 @@ function lodChain(P, C, I) {
1521
1521
  return out;
1522
1522
  }
1523
1523
 
1524
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/compile.ts
1524
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/compile.ts
1525
1525
  function loadColors(root) {
1526
1526
  const map = new Map;
1527
1527
  for (const l of fs2.readFileSync(path2.join(root, "LDConfig.ldr"), "latin1").split(/\r?\n/)) {
@@ -2104,7 +2104,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
2104
2104
  return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
2105
2105
  }
2106
2106
 
2107
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/build-pack.ts
2107
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/build-pack.ts
2108
2108
  function buildPack(o) {
2109
2109
  const lib = new Library(o.ldrawRoot);
2110
2110
  const refs = new Map;
@@ -2172,7 +2172,7 @@ function buildPack(o) {
2172
2172
  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 } : {} };
2173
2173
  }
2174
2174
 
2175
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/cli.ts
2175
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/cli.ts
2176
2176
  var HELP = `ldr pack — build a parts pack for the ldr three.js renderer
2177
2177
 
2178
2178
  Usage:
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export { precomputeCull, sceneInstances } from "./cull.js";
9
9
  export type { Pack, LdrParams, Inst, CullResult, BuildLdrSceneAsyncOptions } from "./render.js";
10
10
  export { createLdrObject, createLdrObjectAsync } from "./scene.js";
11
11
  export type { LdrObject, LdrObjectOptions, LdrStats, ColorSource } from "./scene.js";
12
- export { decompressPack } from "./pack-io.js";
12
+ export { decompressPack, decodeModelText, modelFileName } from "./pack-io.js";
13
13
  export { loadModel, loadParts, loadPartsIndex, mergePacks, prepareModel, DEFAULT_PARTS_CDN } from "./cdn.js";
14
14
  export type { LoadModelOptions, LoadedModel, LoadPartsOptions, PartsCdnIndex, PrepareOptions, PreparedModel } from "./cdn.js";
15
15
  export { embeddedKeys } from "./embedded.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/spec.ts
1
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/spec.ts
2
2
  var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
3
3
  function parseColor(tok) {
4
4
  if (/^0x/i.test(tok))
@@ -689,7 +689,7 @@ function fileStepViews(f) {
689
689
  viewMemo.set(f, out);
690
690
  return out;
691
691
  }
692
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/model.ts
692
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/model.ts
693
693
  var CALLOUT_END = 999999;
694
694
  var stepKey = (steps) => steps.map((x) => String(x).padStart(6, "0")).join(".") + "~";
695
695
  function flatten(doc, opts = {}) {
@@ -1038,7 +1038,7 @@ function parseLDConfig(text) {
1038
1038
  }
1039
1039
  return out;
1040
1040
  }
1041
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/instructions.ts
1041
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/instructions.ts
1042
1042
  var MIN_VIS = 0.5;
1043
1043
  var REORIENT = 0.35;
1044
1044
  var deg = Math.PI / 180;
@@ -1406,10 +1406,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
1406
1406
  }
1407
1407
  };
1408
1408
  }
1409
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/render.ts
1409
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/render.ts
1410
1410
  import * as THREE from "three";
1411
1411
 
1412
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/pack-io.ts
1412
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/pack-io.ts
1413
1413
  import { decompress } from "fzstd";
1414
1414
  async function decompressPack(data) {
1415
1415
  const u = data instanceof Uint8Array ? data : new Uint8Array(data);
@@ -1420,6 +1420,10 @@ async function decompressPack(data) {
1420
1420
  return new Response(new Blob([u]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();
1421
1421
  return own(u);
1422
1422
  }
1423
+ async function decodeModelText(data) {
1424
+ return new TextDecoder().decode(await decompressPack(data));
1425
+ }
1426
+ var modelFileName = (url) => decodeURIComponent(url.split(/[?#]/)[0].split("/").pop() || "main.ldr").replace(/\.(zst|gz)$/i, "") || "main.ldr";
1423
1427
  function decodePack(buf) {
1424
1428
  const hl = new DataView(buf).getUint32(0, true);
1425
1429
  const header = JSON.parse(new TextDecoder().decode(new Uint8Array(buf, 4, hl)));
@@ -1428,7 +1432,7 @@ function decodePack(buf) {
1428
1432
  return { header, arr, bytes: buf.byteLength, buffer: buf };
1429
1433
  }
1430
1434
 
1431
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/cull.ts
1435
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/cull.ts
1432
1436
  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;
1433
1437
  var prepCache = new WeakMap;
1434
1438
  function prepPart(H, part) {
@@ -1745,7 +1749,7 @@ function precomputeCull(instances, H, useTex = true) {
1745
1749
  return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
1746
1750
  }
1747
1751
 
1748
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/render.ts
1752
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/render.ts
1749
1753
  async function loadPack(url) {
1750
1754
  const res = await fetch(url);
1751
1755
  if (!res.ok)
@@ -3303,8 +3307,21 @@ function buildLdrScene(insts, pack, P, color, mark) {
3303
3307
  r = g.next();
3304
3308
  return r.value;
3305
3309
  }
3310
+ function yieldToMain() {
3311
+ const s = globalThis.scheduler;
3312
+ if (s && typeof s.yield === "function")
3313
+ return s.yield();
3314
+ return new Promise((res) => {
3315
+ const c = new MessageChannel;
3316
+ c.port1.onmessage = () => res();
3317
+ c.port2.postMessage(null);
3318
+ });
3319
+ }
3306
3320
  async function buildLdrSceneAsync(insts, pack, P, color, mark, opts = {}) {
3307
3321
  const sliceMs = opts.sliceMs ?? 8;
3322
+ const postPaint = opts.postPaintSliceMs ?? Math.max(sliceMs, 24);
3323
+ let painting = typeof opts.onSlice === "function";
3324
+ let effective = painting ? sliceMs : postPaint;
3308
3325
  const g = buildLdrSceneGen(insts, pack, P, color, mark);
3309
3326
  let r = g.next();
3310
3327
  let sliceStart = performance.now();
@@ -3312,12 +3329,17 @@ async function buildLdrSceneAsync(insts, pack, P, color, mark, opts = {}) {
3312
3329
  let yields = 0;
3313
3330
  while (!r.done) {
3314
3331
  const now = performance.now();
3315
- if (now - sliceStart >= sliceMs) {
3332
+ if (now - sliceStart >= effective) {
3316
3333
  longestSliceMs = Math.max(longestSliceMs, now - sliceStart);
3317
3334
  yields++;
3318
- if (opts.onSlice)
3319
- await opts.onSlice(r.value);
3320
- await new Promise((res) => setTimeout(res, 0));
3335
+ if (painting && opts.onSlice) {
3336
+ const cont = await opts.onSlice(r.value);
3337
+ if (cont === false) {
3338
+ painting = false;
3339
+ effective = postPaint;
3340
+ }
3341
+ }
3342
+ await yieldToMain();
3321
3343
  sliceStart = performance.now();
3322
3344
  }
3323
3345
  r = g.next();
@@ -3349,7 +3371,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
3349
3371
  await new Promise((r) => setTimeout(r, 0));
3350
3372
  }
3351
3373
  }
3352
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/scene.ts
3374
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/scene.ts
3353
3375
  import * as THREE2 from "three";
3354
3376
  function colorFn(src, pack, fallback) {
3355
3377
  const table = new Map;
@@ -3555,20 +3577,21 @@ function createLdrObjectInner(instances, pack, options, progressive) {
3555
3577
  so.cull = cullCore(all, pack.header, so.steps);
3556
3578
  const built = await buildLdrSceneAsync(all, pack, so, color, () => {}, {
3557
3579
  sliceMs: o.sliceMs,
3558
- onSlice: async (root) => {
3580
+ postPaintSliceMs: o.postPaintSliceMs,
3581
+ onSlice: o.onSlice ? async (root) => {
3559
3582
  if (root.parent !== object)
3560
3583
  object.add(root);
3561
- await o.onSlice?.();
3562
- }
3584
+ return await o.onSlice();
3585
+ } : undefined
3563
3586
  });
3564
3587
  applyBuilt(built, t0);
3565
3588
  return finish();
3566
3589
  })();
3567
3590
  }
3568
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/parts-cdn.ts
3591
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/parts-cdn.ts
3569
3592
  import { decompress as decompress2 } from "fzstd";
3570
3593
 
3571
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/embedded.ts
3594
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/embedded.ts
3572
3595
  function splitFiles(text, fallback) {
3573
3596
  const files = new Map;
3574
3597
  let cur = null, saw = false;
@@ -3640,7 +3663,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
3640
3663
  return out;
3641
3664
  }
3642
3665
 
3643
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/parts-cdn.ts
3666
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/parts-cdn.ts
3644
3667
  var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
3645
3668
  var indexCache = new Map;
3646
3669
  var shardCache = new Map;
@@ -3776,13 +3799,13 @@ async function prepareModel(source, o = {}) {
3776
3799
  const f = o.fetch ?? fetch;
3777
3800
  const idxP = loadPartsIndex(o.cdn ?? DEFAULT_PARTS_CDN, f);
3778
3801
  idxP.catch(() => {});
3779
- const text = o.text ? source : await f(source).then((r) => {
3802
+ const text = o.text ? source : await f(source).then(async (r) => {
3780
3803
  if (!r.ok)
3781
3804
  throw new Error(`ldr: ${r.status} fetching ${source}`);
3782
- return r.text();
3805
+ return decodeModelText(await r.arrayBuffer());
3783
3806
  });
3784
3807
  const t1 = performance.now();
3785
- const name = o.name ?? (o.text ? "main.ldr" : decodeURIComponent(source.split(/[?#]/)[0].split("/").pop() || "main.ldr"));
3808
+ const name = o.name ?? (o.text ? "main.ldr" : modelFileName(source));
3786
3809
  const insts = parseModel(text, name, { looseGeometry: false, callouts: o.callouts });
3787
3810
  const t2 = performance.now();
3788
3811
  o.onParsed?.(insts);
@@ -3800,10 +3823,10 @@ async function prepareModel(source, o = {}) {
3800
3823
  return { insts, pack, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
3801
3824
  }
3802
3825
 
3803
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/load-worker.gen.ts
3804
- var load_worker_gen_default = 'var ht=ArrayBuffer,W=Uint8Array,ge=Uint16Array,gt=Int16Array;var be=Int32Array,Ce=function(e,t,n){if(W.prototype.slice)return W.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 W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.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},bt=function(e,t,n,r){if(W.prototype.copyWithin)return W.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 dt=["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||dt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},Be=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},xt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},yt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,p=Be(e,a,c);a+=c;var m=l?1<<l:s,h=Be(e,a,m)+(l==1&&256),d=h;if(!s){var C=1<<10+(e[5]>>3);d=C+(C>>3)*(e[5]&7)}if(d>2145386496)K(1);var u=new W((t==1?h||d:t?0:d)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:p,w:t&&t!=1?t:u.subarray(12),e:d,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return xt(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,p=o,m=new ht(512+(o<<2)),h=new gt(m,0,256),d=new ge(m,0,256),C=new ge(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var g=re(i+1),f=r>>3,A=(1<<g+1)-1,z=(e[f]|e[f+1]<<8|e[f+2]<<16)>>(r&7)&A,x=(1<<g)-1,M=A-i-1,L=z&x;if(L<M)r+=g,z=L;else if(r+=g+1,z>x)z-=M;if(h[++l]=--z,z==-1)i+=z,b[--p]=l;else i-=z;if(!z)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var E=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var v=h[H];if(v<1){d[H]=-v;continue}for(c=0;c<v;++c){b[E]=H;do E=E+U&X;while(E>=p)}}if(E)K(0);for(c=0;c<o;++c){var w=d[b[c]]++,P=S[c]=s-re(w);C[c]=(w<<P)-o}return[r+7>>3,{b:s,s:b,n:S,t:C}]},wt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),p=c[0],m=c[1];t+=o;var h=p<<3,d=e[t];if(!d)K(0);var C=0,u=0,b=m.b,S=b,g=(++t<<3)-8+re(d);for(;;){if(g-=b,g<h)break;var f=g>>3;if(C+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=m.s[C],g-=S,g<h)break;f=g>>3,u+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[C],C=m.t[C],S=m.n[u],u=m.t[u]}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 z=0;for(n=0;n<r;++n){var x=i[n];if(x>11)K(0);z+=x&&1<<x-1}var M=re(z)+1,L=1<<M,D=L-z;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var x=i[n];++l[i[n]=x&&M+1-x]}var E=new W(L<<1),U=E.subarray(0,L),X=E.subarray(L);a[M]=0;for(n=M;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<M-n))}if(a[0]!=L)K(0);for(n=0;n<r;++n){var v=i[n];if(v){var w=a[v];ce(U,n,w,a[v]=w+(1<<M-v))}}return[t,{n:X,b:M,s:U}]},At=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],vt=ue(new W([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],Mt=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],$e=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Ee=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Ct=$e(Ee,0),Se=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Et=$e(Se,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,p=(r<<3)-8+re(o)-c,m=-1;for(;p>l&&m<s;){var h=p>>3,d=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(p&7);a=(a<<c|d)&i,t[++m]=n.s[a],p-=c=n.n[a]}if(p!=l||m+1!=s)K(0)},St=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},Lt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),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+=l,n;return Ce(e,s,a)}if(i==2){var c=e[s],p=c&3,m=c>>2&3,h=c>>4,d=0,C=0;if(p<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(C=m,m<2)h|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(p==0)u.set(e.subarray(s,s+=h),b);else if(p==1)ce(u,e[s++],b);else{var S=t.h;if(p==2){var g=wt(e,s);d+=s-(s=g[0]),t.h=S=g[1]}else if(!S)K(0);(C?St:le)(e.subarray(s,s+=d),u.subarray(b),S)}var f=e[s++];if(f){if(f==255)f=(e[s++]|e[s++]<<8)+32512;else if(f>127)f=f-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var z=[vt,Mt,At];for(var x=2;x>-1;--x){var M=A>>(x<<1)+2&3;if(M==1){var L=new W([0,0,e[s++]]);z[x]={s:L.subarray(2,3),n:L.subarray(0,1),t:new ge(L.buffer,0,1),b:0}}else if(M==2)r=ue(e,s,9-(x&1)),s=r[0],z[x]=r[1];else if(M==3){if(!t.t)K(0);z[x]=t.t[x]}}var D=t.t=z,E=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var v=(a<<3)-8+re(H)-X.b,w=v>>3,P=0,V=(e[w]|e[w+1]<<8)>>(v&7)&(1<<X.b)-1;w=(v-=U.b)>>3;var I=(e[w]|e[w+1]<<8)>>(v&7)&(1<<U.b)-1;w=(v-=E.b)>>3;var B=(e[w]|e[w+1]<<8)>>(v&7)&(1<<E.b)-1;for(++f;--f;){var T=X.s[V],y=X.n[V],N=E.s[B],R=E.n[B],k=U.s[I],O=U.n[I];w=(v-=k)>>3;var j=1<<k,F=j+((e[w]|e[w+1]<<8|e[w+2]<<16|e[w+3]<<24)>>>(v&7)&j-1);w=(v-=Se[N])>>3;var G=Et[N]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Se[N])-1);w=(v-=Ee[T])>>3;var _=Ct[T]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Ee[T])-1);if(w=(v-=y)>>3,V=X.t[V]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<y)-1),w=(v-=R)>>3,B=E.t[B]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<R)-1),w=(v-=O)>>3,I=U.t[I]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<O)-1),F>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=F-=3;else{var Z=F-(_!=0);if(Z){if(F=Z==3?t.o[0]-1:t.o[Z],Z>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=F}else F=t.o[0]}for(var x=0;x<_;++x)u[P+x]=u[b+x];P+=_,b+=_;var q=P-F;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var x=0;x<J;++x)u[P+x]=t.w[ee+x];P+=J,G-=J,q=0}for(var x=0;x<G;++x)u[P+x]=u[q+x];P+=G}if(P!=b)while(b<u.length)u[P++]=u[b++];else P=u.length;if(n)t.y+=P;else u=Ce(u,0,P)}else if(n){if(t.y+=h,b)for(var x=0;x<h;++x)u[x]=u[b+x]}else if(b)u=Ce(u,b);return t.b=a,u}K(2)},Tt=function(e,t){if(e.length==1)return e[0];var n=new W(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 je(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=yt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=Lt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,bt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Tt(n,o)}function de(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,"/");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ve=/^~?\\s*moved\\s+to\\s+(.+)$/i,Pt=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Ye=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),It=new Set(["model","submodel","configuration"]),Ft=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function He(e){let t=Ft.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Ye.has(n)||It.has(n)?n:void 0}function Rt(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function kt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,"");let a=Rt(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let p=a.findIndex((m,h)=>h>0&&m.toUpperCase()==="GLOSSMAP");if(p>0&&a[p+1])c.glossmap=a[p+1];if(t)c.next=!0;return c}var Dt=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Ut(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let p=s();if(p===null)return null;i[c]=+p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Le(o),m:i,file:Y(a)}}function Ge(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Y(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function Je(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,a=null,c=[],p=null,m=()=>{if(!a)return;let g=Dt(a.chunks.join("")),f=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Y(a.name),{name:a.name,bytes:g,...f?{mime:"image/png"}:{}}),a=null},h=!0,d=(g)=>{if(m(),o={name:Y(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],p=null,h=!0},C=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=""},S=(g,f)=>{if(p){g.tex=p,p=null;return}let A=c[c.length-1];if(!A)return;if(A.fallback){if(!f)g.fallback=!0}else g.tex=A.map};for(let g of e.split(`\n`)){let f=g.trim();if(!f)continue;if(r&&f.charCodeAt(0)>=50&&f.charCodeAt(0)<=53&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){if(a||C)continue;if(!o)d(t);let M=f.slice(2).trimStart(),L=M.search(/\\s/),D={t:f.charCodeAt(0)-48,color:Le(L<0?M:M.slice(0,L)),p:[],src:f};S(D,!1),o.cmds.push(D),h=!1;continue}if(f.charCodeAt(0)===48&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){let M=2;while(f.charCodeAt(M)===32||f.charCodeAt(M)===9)M++;let L=M;while(L<f.length&&f.charCodeAt(L)!==32&&f.charCodeAt(L)!==9)L++;let D=f.slice(M,L);if(!Pt.has(D)){if(C||a)continue;if(!o)d(t);let E=f.slice(M),U={t:0,text:E};if(D.charCodeAt(0)===33)U.meta=D;if(p=null,h&&!o.org){let H=He(E);if(H)o.org=H}let X=E.match(Ve);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=".dat";o.movedTo=Y(H)}o.cmds.push(U);continue}}if(f.charCodeAt(0)===49&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)&&!a&&!C){let M=Ut(f);if(M){if(!o)d(t);S(M,!1),o.cmds.push(M),h=!1;continue}}let A=f.split(/\\s+/);if(+A[0]===0){let M=f.slice(1).trim();if(A[1]==="FILE"){b(),C=!1,d(M.slice(5));continue}if(A[1]==="NOFILE"){m(),o=null,C=!0;continue}if(A[1]==="!DATA"){b(),m(),o=null,C=!1,a={name:M.slice(5).trim(),chunks:[]};continue}if(C)continue;if(a){if(A[1]==="!:")a.chunks.push(A.slice(2).join(""));continue}if(!o)d(t);let L={t:0,text:M};if(A[1]==="STEP")L.step=!0,c=[],p=null;else if(A[1]==="BFC")L.bfc=A.slice(2).join(" ");else if(A[1]==="ROTSTEP")if(L.meta="ROTSTEP",L.step=!0,c=[],p=null,(A[2]??"").toUpperCase()==="END")L.rotstep={x:0,y:0,z:0,mode:"END"};else{let E=(A[5]??"REL").toUpperCase();L.rotstep={x:+A[2]||0,y:+A[3]||0,z:+A[4]||0,mode:["REL","ABS","ADD"].includes(E)?E:"REL"}}else if(A[1]==="BUFEXCHG"){L.meta="BUFEXCHG";let E=(A[2]??"").toUpperCase();L.bufexchg={op:E==="RETRIEVE"?"RETRIEVE":"STORE",buf:A[3]??"A"}}else if(A[1]?.startsWith("!"))L.meta=A[1];if(h&&!o.org){let E=He(M);if(E)o.org=E}if(A[1]==="!TEXMAP"){let E=(A[2]??"").toUpperCase();if(p=null,E==="START"||E==="NEXT"){let U=kt(M.replace(/^!TEXMAP\\s+\\S+/i,""),E==="NEXT");if(L.texmap={op:E,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),E==="START")c.push({map:U,fallback:!1});else p=U}else if(E==="FALLBACK"){L.texmap={op:E};let U=c[c.length-1];if(U)U.fallback=!0}else if(E==="END")L.texmap={op:E},c.pop()}else if(A[1]==="!:"){p=null;let E=Ge(A.slice(2));if(E)S(E,!0),L.geom=E}else p=null;let D=M.match(Ve);if(D&&!o.movedTo){let E=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(E))E+=".dat";o.movedTo=Y(E)}o.cmds.push(L);continue}if(a||C)continue;if(!o)d(t);let x=Ge(A);if(!x)continue;S(x,!1),o.cmds.push(x),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var tn=Math.PI/180;function qe(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 Qe(e,t){let[n,r,s,o,i,l,a,c,p,m,h,d]=e,[C,u,b,S,g,f,A,z,x,M,L,D]=t;return[o*C+i*u+l*b+n,a*C+c*u+p*b+r,m*C+h*u+d*b+s,o*S+i*A+l*M,o*g+i*z+l*L,o*f+i*x+l*D,a*S+c*A+p*M,a*g+c*z+p*L,a*f+c*x+p*D,m*S+h*A+d*M,m*g+h*z+d*L,m*f+h*x+d*D]}var Te=[0,0,0,1,0,0,0,1,0,0,0,1];var _e=new WeakMap,zt=/^(s|8|48)\\//;function Pe(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=_e.get(n);if(r)return r;if(n.org)r=Ye.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&&zt.test(s.file))?"part":"model";return _e.set(n,r),r}var We=new WeakMap;function et(e){let t=We.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 We.set(e,t),t}var Ke=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():String(e),Ot=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Ke(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Ke(e.color)} ${e.p.join(" ")}`,Ie=(e,t)=>`${Y(e)}#${t}`;function Nt(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){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:Ie(e.name,t),cmds:n}}function tt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Nt(e,t).cmds.map(Ot)].join(`\n`)+`\n`}function Bt(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,l,a,c,p,m,h]=e,d=a*h-c*m,C=-(l*h-c*p),u=l*m-a*p,b=s*d+o*C+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,g=[d*S,-(o*h-i*m)*S,(o*c-i*a)*S,C*S,(s*h-i*p)*S,-(s*c-i*l)*S,u*S,-(s*m-o*p)*S,(s*a-o*l)*S];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 $t=(e)=>String(+e.toFixed(6)||0),Xe=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function rt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map($t).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Xe(t.texture)}${t.glossmap?" GLOSSMAP "+Xe(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-${Bt(r)}`,source:r}}var jt=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Vt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var Ze=new WeakMap;function st(e){let t=Ze.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=Vt(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:jt(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Ze.set(e,n),n}var ot=999999,it=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function Ht(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let d=m.name+"#"+h,C=l.get(d);if(!C){let u;C=Object.assign(()=>u??=tt(m,h),{file:m,step:h}),l.set(d,C)}return C},p=(m,h,d,C,u,b,S,g,f=null,A=[],z=[])=>{let x=m.files.get(h);if(!x||S>r)return;let M=0,L=S>0?++a:0,D=i&&L?[...A,L]:A,E=i&&L?[...z,d]:z,U=i&&!f?new Map:null,X=-1,H=0,v=(T,y,N,R,k,O)=>{if(X!==M)X=M,H=0;let j=U?.get(M+"|"+y);if(j)return j.n++,p(T,T===m?y:T.main,N,R,u+"/"+y,[...k,ot],S+1,O,[...k,ot],D,E);let F=[...k,H++],G=n.length;p(T,T===m?y:T.main,N,R,u+"/"+y,F,S+1,O,f,D,E),U?.set(M+"|"+y,{n:1,from:G,to:n.length})},w=st(x),P=s?et(x):[],V=0,I=(T,y,N,R,k,O,j)=>{if(f)R=f;let F={part:T,color:y,m:N,step:R[0],steps:R,localStep:k,path:u};if(L){if(F.sub=L,i)F.subPath=D,F.subMats=E}if(O)F.embedded=!0;if(j){let _=rt(T,j);F.texPart=_.name,F.texSource=_.source}let G=w[k];if(G)F.view=G;return n.push(F),F},B=(T)=>{while(V<P.length&&P[V]<=T){let y=P[V++];I(Ie(x.name,y),C,d,[...b,y],y,!1,null).source=c(x,y)}};for(let T of x.cmds){if(T.t===0&&T.step){M++;continue}let y=T;if(y.t>=2||y.t===0&&y.geom&&y.geom.t>=2){B(M);continue}if(y.t===0)if(o&&y.geom?.t===1)y=y.geom;else continue;if(y.t!==1)continue;if(o&&y.fallback)continue;let N=y.color===16?C:y.color,R=Qe(d,y.m),k=[...b,M],O=o?y.tex??g:null,j=O?nt(y.m):null,F=O&&j?qe(O,j):null;if(m.files.has(y.file)){if(Pe(m,y.file)==="model"){v(m,y.file,R,N,k,F);continue}I(y.file,N,R,k,M,!0,F);continue}let G=t.resolveModel?.(y.file);if(G){v(G,y.file,R,N,k,F);continue}I(y.file,N,R,k,M,!1,F)}if(B(1/0),U){for(let T of U.values())if(T.n>1)for(let y=T.from;y<T.to;y++)n[y].mult??=T.n}};if(Pe(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Te],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return p(e,e.main,Te,16,e.main,[],0,null),n}function at(e,t="main.ldr",n){return Ht(Je(e,t,{geometryText:!0}),n)}function Gt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Y(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Y(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var _t=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function Wt(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 lt(e,t,n="main.ldr"){let r=Gt(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let p of r.get(a.pop())){let m=_t(p);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((p)=>p!==i).sort()].map((p)=>"0 FILE "+(p===i?"":p)+`\n`+r.get(p).join(`\n`)).join(`\n`);s.set(i,`emb/${Wt(c)}.dat`)}return s}var ct=(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,ut=new WeakMap;function Fe(e,t){let n=ut.get(e);if(!n)ut.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,d)=>{l.push(h[0]),a.push(h[1]);for(let C=0;C<12;C++)i[d*12+C]=h[2+C]});let c=null,p=0,m=0;if(s.mask){p=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let d=0;d<h.length;d++)c[d]=h.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:p,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Kt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],p=[],m=[],h=new Re(e.length*2),d=[],C=[];for(let v=0;v<e.length;v++){let w=e[v],P=w.m,V=t.parts[w.part];if(!V||!V.mask||!ct(P))continue;let I=V.bbox,B=1/0,T=-1/0,y=1/0,N=-1/0;for(let O=0;O<2;O++)for(let j=0;j<2;j++){let F=O?I[3]:I[0],G=j?I[5]:I[2],_=P[0]+P[3]*F+P[5]*G,Z=P[2]+P[9]*F+P[11]*G;if(_<B)B=_;if(_>T)T=_;if(Z<y)y=Z;if(Z>N)N=Z}let R=a.length;s.push(B),o.push(T),i.push(y),l.push(N),a.push(v),c.push(Fe(t,w.part)),p.push(I[0]),m.push(I[2]);let k=Math.round((P[1]+I[4])*2);for(let O=Math.floor(B/40);O<=Math.floor(T/40);O++)for(let j=Math.floor(y/40);j<=Math.floor(N/40);j++){if(!xe(k,O,j))continue;let F=C.length;C.push(R),d.push(h.put(k,O,j,F))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,g=NaN,f=NaN,A=-1,z=(v,w,P,V)=>{let I=Math.round(w*2),B=Math.floor(v/40),T=Math.floor(P/40);if(!xe(I,B,T))return fe;let y=fe;if(I!==S||B!==g||T!==f)S=I,g=B,f=T,A=h.get(I,B,T);for(let N=A;N>=0;N=d[N]){let R=C[N];if(a[R]===V||!(v-6>=s[R]-0.5&&v+6<=o[R]+0.5&&P-6>=i[R]-0.5&&P+6<=l[R]+0.5))continue;let k=e[a[R]].m,O=c[R],j=p[R],F=m[R],G=v-k[0],_=w-k[1],Z=P-k[2],q=k[3]*G+k[6]*_+k[9]*Z,J=k[5]*G+k[8]*_+k[11]*Z,{nx:ee,nz:se,mask:ae}=O,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-F)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[R]];if(Q<y)y=Q}}return y},x=0;for(let v of e){let w=Fe(t,v.part);if(w)x+=w.nStuds}let M=new Uint8Array(x),L=new Uint8Array(x),D=new Re(x),E=0,U=n?new Int32Array(x).fill(fe):void 0;for(let v=0,w=0;v<e.length;v++){let P=e[v],V=Fe(t,P.part);if(!V)continue;let I=P.m,B=V.studM,T=I[0],y=I[1],N=I[2],R=I[3],k=I[4],O=I[5],j=I[6],F=I[7],G=I[8],_=I[9],Z=I[10],q=I[11];for(let J=0;J<V.nStuds;J++,w++){let ee=J*12,se=B[ee+4],ae=B[ee+7],oe=B[ee+10];if(!(Math.abs(j*se+F*ae+G*oe-1)<0.001&&Math.abs(R*se+k*ae+O*oe)<0.001&&Math.abs(_*se+Z*ae+q*oe)<0.001))continue;L[w]=1;let Q=B[ee],te=B[ee+1],ne=B[ee+2],ke=T+R*Q+k*te+O*ne,De=y+j*Q+F*te+G*ne,Ue=N+_*Q+Z*te+q*ne,ze=z(ke,De,Ue,v);if(ze!==fe){if(M[w]=1,E++,U)U[w]=ze}let pe=Math.round(ke),me=Math.round(De),he=Math.round(Ue);if(!xe(pe,me,he))continue;if(!n){D.put(pe,me,he,1);continue}let Oe=n[v],Ne=D.get(pe,me,he);if(Ne<0||Oe<Ne)D.put(pe,me,he,Oe)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let w=e[v],P=t.parts[w.part];if(!P||!P.under||!ct(w.m))continue;let V=P.bbox,I=Math.round((V[3]-V[0])/20),B=Math.round((V[5]-V[2])/20);if(!I||!B||I*B>4096)continue;let T=w.m,y=!0,N=0;for(let R=0;R<I&&y;R++)for(let k=0;k<B;k++){let O=V[0]+10+20*R,j=V[2]+10+20*k,F=T[0]+T[3]*O+T[5]*j,G=T[2]+T[9]*O+T[11]*j,_=Math.round(F),Z=Math.round(T[1]+V[4]),q=Math.round(G),J=xe(_,Z,q)?D.get(_,Z,q):-1;if(J<0){y=!1;break}if(J>N)N=J}if(y){if(X[v]=1,H)H[v]=N}}return{nStuds:x,studHidden:M,studUp:L,underHidden:X,studsHidden:E,studHideStep:U,underHideStep:H}}function Xt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>it(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function ye(e,t,n=!0){let r=Xt(e,t,n);return Kt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Me="https://ldr-demo.vercel.app/cdn/v1/",Ae=new Map,we=new Map;function pt(e=Me,t=fetch){let n=Ae.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>Ae.delete(e)),Ae.set(e,n);return n}var Zt=(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"),ve=(e,t)=>Zt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>ve(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,ve(r,t)])):e;function Yt(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let d=h.buffer;if(!d)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let C=new DataView(d).getUint32(0,!0),u=new Uint8Array(d,4+C),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[g,f]of Object.entries(h.header.parts??{}))if(!(g in s))s[g]=ve(f,b);for(let[g,f]of Object.entries(h.header.studKinds??{}))if(!(g in o))o[g]=ve(f,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,p=new Uint8Array(c+r);new DataView(p.buffer).setUint32(0,l.length+a,!0),p.set(l,4),p.fill(32,4+l.length,c);let m=c;for(let h of n)p.set(h,m),m+=h.byteLength;return de(p.buffer)}async function Jt(e,t={}){e=[...e];try{return await ft(e,t)}catch(n){let r=t.cdn??Me,s=t.fetch??fetch;Ae.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await ft(e,{...t,fetch:o})}catch{throw n}}}async function ft(e,t){let n=t.cdn??Me,r=t.fetch??fetch,s=t.gap??16384,o=await pt(n,r),i=[...new Set([...e].map(Y))],l=[],a=[];for(let u of i){if(we.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let p=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);p+=S.byteLength;for(let g of u.items){let f=je(S.subarray(g.off-u.start,g.off-u.start+g.len)),A=f.buffer.slice(f.byteOffset,f.byteOffset+f.byteLength);we.set(n+g.name,de(A))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let d=i.filter((u)=>we.has(n+u)).map((u)=>we.get(n+u));return{pack:d.length?Yt(d,{colors:o.colors}):de(qt(o.colors)),missing:l,requests:c.length,bytes:p}}function qt(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}async function mt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=pt(t.cdn??Me,r);s.catch(()=>{});let o=t.text?e:await r(e).then((f)=>{if(!f.ok)throw Error(`ldr: ${f.status} fetching ${e}`);return f.text()}),i=performance.now(),l=t.name??(t.text?"main.ldr":decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr")),a=at(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let p=lt(o,new Set(a.filter((f)=>f.embedded).map((f)=>f.part)),l),{pack:m,missing:h,requests:d,bytes:C}=await Jt([...a.filter((f)=>!f.embedded).map((f)=>f.part),...p.values()],t),u=new Map([...p].map(([f,A])=>[A,f])),b=h.map((f)=>u.get(f)??f);for(let[f,A]of p){let z=m.header.parts[A];if(z)m.header.parts[f]=z}let S=performance.now(),g=t.cull?ye(a,m.header,t.textures!==!1):void 0;return{insts:a,pack:m,missing:b,requests:d,bytes:C,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:S-c,...g?{cull:performance.now()-S}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await mt(n,{...r,cull:!1,onParsed:(p)=>self.postMessage({id:t,insts:p})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=ye(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let p of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(p)c.push(p.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
3826
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/load-worker.gen.ts
3827
+ var load_worker_gen_default = 'var bt=ArrayBuffer,W=Uint8Array,ge=Uint16Array,dt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.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 W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.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},yt=function(e,t,n,r){if(W.prototype.copyWithin)return W.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 xt=["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||xt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},$e=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},wt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},At=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,p=$e(e,a,c);a+=c;var m=l?1<<l:s,h=$e(e,a,m)+(l==1&&256),d=h;if(!s){var C=1<<10+(e[5]>>3);d=C+(C>>3)*(e[5]&7)}if(d>2145386496)K(1);var u=new W((t==1?h||d:t?0:d)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:p,w:t&&t!=1?t:u.subarray(12),e:d,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return wt(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,p=o,m=new bt(512+(o<<2)),h=new dt(m,0,256),d=new ge(m,0,256),C=new ge(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var g=re(i+1),f=r>>3,A=(1<<g+1)-1,z=(e[f]|e[f+1]<<8|e[f+2]<<16)>>(r&7)&A,y=(1<<g)-1,M=A-i-1,L=z&y;if(L<M)r+=g,z=L;else if(r+=g+1,z>y)z-=M;if(h[++l]=--z,z==-1)i+=z,b[--p]=l;else i-=z;if(!z)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var E=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var v=h[H];if(v<1){d[H]=-v;continue}for(c=0;c<v;++c){b[E]=H;do E=E+U&X;while(E>=p)}}if(E)K(0);for(c=0;c<o;++c){var w=d[b[c]]++,P=S[c]=s-re(w);C[c]=(w<<P)-o}return[r+7>>3,{b:s,s:b,n:S,t:C}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),p=c[0],m=c[1];t+=o;var h=p<<3,d=e[t];if(!d)K(0);var C=0,u=0,b=m.b,S=b,g=(++t<<3)-8+re(d);for(;;){if(g-=b,g<h)break;var f=g>>3;if(C+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=m.s[C],g-=S,g<h)break;f=g>>3,u+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[C],C=m.t[C],S=m.n[u],u=m.t[u]}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 z=0;for(n=0;n<r;++n){var y=i[n];if(y>11)K(0);z+=y&&1<<y-1}var M=re(z)+1,L=1<<M,D=L-z;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var y=i[n];++l[i[n]=y&&M+1-y]}var E=new W(L<<1),U=E.subarray(0,L),X=E.subarray(L);a[M]=0;for(n=M;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<M-n))}if(a[0]!=L)K(0);for(n=0;n<r;++n){var v=i[n];if(v){var w=a[v];ce(U,n,w,a[v]=w+(1<<M-v))}}return[t,{n:X,b:M,s:U}]},Mt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([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],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],je=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=je(Se,0),Le=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Lt=je(Le,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,p=(r<<3)-8+re(o)-c,m=-1;for(;p>l&&m<s;){var h=p>>3,d=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(p&7);a=(a<<c|d)&i,t[++m]=n.s[a],p-=c=n.n[a]}if(p!=l||m+1!=s)K(0)},Tt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},Pt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),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+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],p=c&3,m=c>>2&3,h=c>>4,d=0,C=0;if(p<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(C=m,m<2)h|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(p==0)u.set(e.subarray(s,s+=h),b);else if(p==1)ce(u,e[s++],b);else{var S=t.h;if(p==2){var g=vt(e,s);d+=s-(s=g[0]),t.h=S=g[1]}else if(!S)K(0);(C?Tt:le)(e.subarray(s,s+=d),u.subarray(b),S)}var f=e[s++];if(f){if(f==255)f=(e[s++]|e[s++]<<8)+32512;else if(f>127)f=f-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var z=[Ct,Et,Mt];for(var y=2;y>-1;--y){var M=A>>(y<<1)+2&3;if(M==1){var L=new W([0,0,e[s++]]);z[y]={s:L.subarray(2,3),n:L.subarray(0,1),t:new ge(L.buffer,0,1),b:0}}else if(M==2)r=ue(e,s,9-(y&1)),s=r[0],z[y]=r[1];else if(M==3){if(!t.t)K(0);z[y]=t.t[y]}}var D=t.t=z,E=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var v=(a<<3)-8+re(H)-X.b,w=v>>3,P=0,V=(e[w]|e[w+1]<<8)>>(v&7)&(1<<X.b)-1;w=(v-=U.b)>>3;var I=(e[w]|e[w+1]<<8)>>(v&7)&(1<<U.b)-1;w=(v-=E.b)>>3;var B=(e[w]|e[w+1]<<8)>>(v&7)&(1<<E.b)-1;for(++f;--f;){var T=X.s[V],x=X.n[V],N=E.s[B],R=E.n[B],k=U.s[I],O=U.n[I];w=(v-=k)>>3;var j=1<<k,F=j+((e[w]|e[w+1]<<8|e[w+2]<<16|e[w+3]<<24)>>>(v&7)&j-1);w=(v-=Le[N])>>3;var G=Lt[N]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Le[N])-1);w=(v-=Se[T])>>3;var _=St[T]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Se[T])-1);if(w=(v-=x)>>3,V=X.t[V]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<x)-1),w=(v-=R)>>3,B=E.t[B]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<R)-1),w=(v-=O)>>3,I=U.t[I]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<O)-1),F>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=F-=3;else{var Z=F-(_!=0);if(Z){if(F=Z==3?t.o[0]-1:t.o[Z],Z>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=F}else F=t.o[0]}for(var y=0;y<_;++y)u[P+y]=u[b+y];P+=_,b+=_;var q=P-F;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var y=0;y<J;++y)u[P+y]=t.w[ee+y];P+=J,G-=J,q=0}for(var y=0;y<G;++y)u[P+y]=u[q+y];P+=G}if(P!=b)while(b<u.length)u[P++]=u[b++];else P=u.length;if(n)t.y+=P;else u=Ee(u,0,P)}else if(n){if(t.y+=h,b)for(var y=0;y<h;++y)u[y]=u[b+y]}else if(b)u=Ee(u,b);return t.b=a,u}K(2)},It=function(e,t){if(e.length==1)return e[0];var n=new W(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 de(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=At(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=Pt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,yt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return It(n,o)}async function Ft(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(de(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 Ve(e){return new TextDecoder().decode(await Ft(e))}var He=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function ye(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/");function Te(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ge=/^~?\\s*moved\\s+to\\s+(.+)$/i,Rt=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),qe=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),kt=new Set(["model","submodel","configuration"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function _e(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return qe.has(n)||kt.has(n)?n:void 0}function Ut(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 zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,"");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let p=a.findIndex((m,h)=>h>0&&m.toUpperCase()==="GLOSSMAP");if(p>0&&a[p+1])c.glossmap=a[p+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let p=s();if(p===null)return null;i[c]=+p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Te(o),m:i,file:Y(a)}}function We(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Te(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Y(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function Qe(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,a=null,c=[],p=null,m=()=>{if(!a)return;let g=Ot(a.chunks.join("")),f=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Y(a.name),{name:a.name,bytes:g,...f?{mime:"image/png"}:{}}),a=null},h=!0,d=(g)=>{if(m(),o={name:Y(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],p=null,h=!0},C=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=""},S=(g,f)=>{if(p){g.tex=p,p=null;return}let A=c[c.length-1];if(!A)return;if(A.fallback){if(!f)g.fallback=!0}else g.tex=A.map};for(let g of e.split(`\n`)){let f=g.trim();if(!f)continue;if(r&&f.charCodeAt(0)>=50&&f.charCodeAt(0)<=53&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){if(a||C)continue;if(!o)d(t);let M=f.slice(2).trimStart(),L=M.search(/\\s/),D={t:f.charCodeAt(0)-48,color:Te(L<0?M:M.slice(0,L)),p:[],src:f};S(D,!1),o.cmds.push(D),h=!1;continue}if(f.charCodeAt(0)===48&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){let M=2;while(f.charCodeAt(M)===32||f.charCodeAt(M)===9)M++;let L=M;while(L<f.length&&f.charCodeAt(L)!==32&&f.charCodeAt(L)!==9)L++;let D=f.slice(M,L);if(!Rt.has(D)){if(C||a)continue;if(!o)d(t);let E=f.slice(M),U={t:0,text:E};if(D.charCodeAt(0)===33)U.meta=D;if(p=null,h&&!o.org){let H=_e(E);if(H)o.org=H}let X=E.match(Ge);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=".dat";o.movedTo=Y(H)}o.cmds.push(U);continue}}if(f.charCodeAt(0)===49&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)&&!a&&!C){let M=Nt(f);if(M){if(!o)d(t);S(M,!1),o.cmds.push(M),h=!1;continue}}let A=f.split(/\\s+/);if(+A[0]===0){let M=f.slice(1).trim();if(A[1]==="FILE"){b(),C=!1,d(M.slice(5));continue}if(A[1]==="NOFILE"){m(),o=null,C=!0;continue}if(A[1]==="!DATA"){b(),m(),o=null,C=!1,a={name:M.slice(5).trim(),chunks:[]};continue}if(C)continue;if(a){if(A[1]==="!:")a.chunks.push(A.slice(2).join(""));continue}if(!o)d(t);let L={t:0,text:M};if(A[1]==="STEP")L.step=!0,c=[],p=null;else if(A[1]==="BFC")L.bfc=A.slice(2).join(" ");else if(A[1]==="ROTSTEP")if(L.meta="ROTSTEP",L.step=!0,c=[],p=null,(A[2]??"").toUpperCase()==="END")L.rotstep={x:0,y:0,z:0,mode:"END"};else{let E=(A[5]??"REL").toUpperCase();L.rotstep={x:+A[2]||0,y:+A[3]||0,z:+A[4]||0,mode:["REL","ABS","ADD"].includes(E)?E:"REL"}}else if(A[1]==="BUFEXCHG"){L.meta="BUFEXCHG";let E=(A[2]??"").toUpperCase();L.bufexchg={op:E==="RETRIEVE"?"RETRIEVE":"STORE",buf:A[3]??"A"}}else if(A[1]?.startsWith("!"))L.meta=A[1];if(h&&!o.org){let E=_e(M);if(E)o.org=E}if(A[1]==="!TEXMAP"){let E=(A[2]??"").toUpperCase();if(p=null,E==="START"||E==="NEXT"){let U=zt(M.replace(/^!TEXMAP\\s+\\S+/i,""),E==="NEXT");if(L.texmap={op:E,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),E==="START")c.push({map:U,fallback:!1});else p=U}else if(E==="FALLBACK"){L.texmap={op:E};let U=c[c.length-1];if(U)U.fallback=!0}else if(E==="END")L.texmap={op:E},c.pop()}else if(A[1]==="!:"){p=null;let E=We(A.slice(2));if(E)S(E,!0),L.geom=E}else p=null;let D=M.match(Ge);if(D&&!o.movedTo){let E=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(E))E+=".dat";o.movedTo=Y(E)}o.cmds.push(L);continue}if(a||C)continue;if(!o)d(t);let y=We(A);if(!y)continue;S(y,!1),o.cmds.push(y),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var on=Math.PI/180;function et(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 tt(e,t){let[n,r,s,o,i,l,a,c,p,m,h,d]=e,[C,u,b,S,g,f,A,z,y,M,L,D]=t;return[o*C+i*u+l*b+n,a*C+c*u+p*b+r,m*C+h*u+d*b+s,o*S+i*A+l*M,o*g+i*z+l*L,o*f+i*y+l*D,a*S+c*A+p*M,a*g+c*z+p*L,a*f+c*y+p*D,m*S+h*A+d*M,m*g+h*z+d*L,m*f+h*y+d*D]}var Pe=[0,0,0,1,0,0,0,1,0,0,0,1];var Ke=new WeakMap,Bt=/^(s|8|48)\\//;function Ie(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=Ke.get(n);if(r)return r;if(n.org)r=qe.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&&Bt.test(s.file))?"part":"model";return Ke.set(n,r),r}var Xe=new WeakMap;function nt(e){let t=Xe.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 Xe.set(e,t),t}var Ze=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():String(e),$t=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Ze(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Ze(e.color)} ${e.p.join(" ")}`,Fe=(e,t)=>`${Y(e)}#${t}`;function jt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){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:Fe(e.name,t),cmds:n}}function rt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...jt(e,t).cmds.map($t)].join(`\n`)+`\n`}function Vt(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 st(e){let[t,n,r,s,o,i,l,a,c,p,m,h]=e,d=a*h-c*m,C=-(l*h-c*p),u=l*m-a*p,b=s*d+o*C+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,g=[d*S,-(o*h-i*m)*S,(o*c-i*a)*S,C*S,(s*h-i*p)*S,-(s*c-i*l)*S,u*S,-(s*m-o*p)*S,(s*a-o*l)*S];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 Ht=(e)=>String(+e.toFixed(6)||0),Ye=(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(Ht).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Ye(t.texture)}${t.glossmap?" GLOSSMAP "+Ye(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-${Vt(r)}`,source:r}}var Gt=(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 _t(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var Je=new WeakMap;function it(e){let t=Je.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=_t(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Gt(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Je.set(e,n),n}var at=999999,lt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function Wt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let d=m.name+"#"+h,C=l.get(d);if(!C){let u;C=Object.assign(()=>u??=rt(m,h),{file:m,step:h}),l.set(d,C)}return C},p=(m,h,d,C,u,b,S,g,f=null,A=[],z=[])=>{let y=m.files.get(h);if(!y||S>r)return;let M=0,L=S>0?++a:0,D=i&&L?[...A,L]:A,E=i&&L?[...z,d]:z,U=i&&!f?new Map:null,X=-1,H=0,v=(T,x,N,R,k,O)=>{if(X!==M)X=M,H=0;let j=U?.get(M+"|"+x);if(j)return j.n++,p(T,T===m?x:T.main,N,R,u+"/"+x,[...k,at],S+1,O,[...k,at],D,E);let F=[...k,H++],G=n.length;p(T,T===m?x:T.main,N,R,u+"/"+x,F,S+1,O,f,D,E),U?.set(M+"|"+x,{n:1,from:G,to:n.length})},w=it(y),P=s?nt(y):[],V=0,I=(T,x,N,R,k,O,j)=>{if(f)R=f;let F={part:T,color:x,m:N,step:R[0],steps:R,localStep:k,path:u};if(L){if(F.sub=L,i)F.subPath=D,F.subMats=E}if(O)F.embedded=!0;if(j){let _=ot(T,j);F.texPart=_.name,F.texSource=_.source}let G=w[k];if(G)F.view=G;return n.push(F),F},B=(T)=>{while(V<P.length&&P[V]<=T){let x=P[V++];I(Fe(y.name,x),C,d,[...b,x],x,!1,null).source=c(y,x)}};for(let T of y.cmds){if(T.t===0&&T.step){M++;continue}let x=T;if(x.t>=2||x.t===0&&x.geom&&x.geom.t>=2){B(M);continue}if(x.t===0)if(o&&x.geom?.t===1)x=x.geom;else continue;if(x.t!==1)continue;if(o&&x.fallback)continue;let N=x.color===16?C:x.color,R=tt(d,x.m),k=[...b,M],O=o?x.tex??g:null,j=O?st(x.m):null,F=O&&j?et(O,j):null;if(m.files.has(x.file)){if(Ie(m,x.file)==="model"){v(m,x.file,R,N,k,F);continue}I(x.file,N,R,k,M,!0,F);continue}let G=t.resolveModel?.(x.file);if(G){v(G,x.file,R,N,k,F);continue}I(x.file,N,R,k,M,!1,F)}if(B(1/0),U){for(let T of U.values())if(T.n>1)for(let x=T.from;x<T.to;x++)n[x].mult??=T.n}};if(Ie(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Pe],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return p(e,e.main,Pe,16,e.main,[],0,null),n}function ct(e,t="main.ldr",n){return Wt(Qe(e,t,{geometryText:!0}),n)}function Kt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Y(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Y(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var Xt=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function Zt(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 ut(e,t,n="main.ldr"){let r=Kt(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let p of r.get(a.pop())){let m=Xt(p);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((p)=>p!==i).sort()].map((p)=>"0 FILE "+(p===i?"":p)+`\n`+r.get(p).join(`\n`)).join(`\n`);s.set(i,`emb/${Zt(c)}.dat`)}return s}var ft=(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,pt=new WeakMap;function Re(e,t){let n=pt.get(e);if(!n)pt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,d)=>{l.push(h[0]),a.push(h[1]);for(let C=0;C<12;C++)i[d*12+C]=h[2+C]});let c=null,p=0,m=0;if(s.mask){p=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let d=0;d<h.length;d++)c[d]=h.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:p,nz:m}),r}var ie=1073741824;class ke{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Yt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],p=[],m=[],h=new ke(e.length*2),d=[],C=[];for(let v=0;v<e.length;v++){let w=e[v],P=w.m,V=t.parts[w.part];if(!V||!V.mask||!ft(P))continue;let I=V.bbox,B=1/0,T=-1/0,x=1/0,N=-1/0;for(let O=0;O<2;O++)for(let j=0;j<2;j++){let F=O?I[3]:I[0],G=j?I[5]:I[2],_=P[0]+P[3]*F+P[5]*G,Z=P[2]+P[9]*F+P[11]*G;if(_<B)B=_;if(_>T)T=_;if(Z<x)x=Z;if(Z>N)N=Z}let R=a.length;s.push(B),o.push(T),i.push(x),l.push(N),a.push(v),c.push(Re(t,w.part)),p.push(I[0]),m.push(I[2]);let k=Math.round((P[1]+I[4])*2);for(let O=Math.floor(B/40);O<=Math.floor(T/40);O++)for(let j=Math.floor(x/40);j<=Math.floor(N/40);j++){if(!xe(k,O,j))continue;let F=C.length;C.push(R),d.push(h.put(k,O,j,F))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,g=NaN,f=NaN,A=-1,z=(v,w,P,V)=>{let I=Math.round(w*2),B=Math.floor(v/40),T=Math.floor(P/40);if(!xe(I,B,T))return fe;let x=fe;if(I!==S||B!==g||T!==f)S=I,g=B,f=T,A=h.get(I,B,T);for(let N=A;N>=0;N=d[N]){let R=C[N];if(a[R]===V||!(v-6>=s[R]-0.5&&v+6<=o[R]+0.5&&P-6>=i[R]-0.5&&P+6<=l[R]+0.5))continue;let k=e[a[R]].m,O=c[R],j=p[R],F=m[R],G=v-k[0],_=w-k[1],Z=P-k[2],q=k[3]*G+k[6]*_+k[9]*Z,J=k[5]*G+k[8]*_+k[11]*Z,{nx:ee,nz:se,mask:ae}=O,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-F)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[R]];if(Q<x)x=Q}}return x},y=0;for(let v of e){let w=Re(t,v.part);if(w)y+=w.nStuds}let M=new Uint8Array(y),L=new Uint8Array(y),D=new ke(y),E=0,U=n?new Int32Array(y).fill(fe):void 0;for(let v=0,w=0;v<e.length;v++){let P=e[v],V=Re(t,P.part);if(!V)continue;let I=P.m,B=V.studM,T=I[0],x=I[1],N=I[2],R=I[3],k=I[4],O=I[5],j=I[6],F=I[7],G=I[8],_=I[9],Z=I[10],q=I[11];for(let J=0;J<V.nStuds;J++,w++){let ee=J*12,se=B[ee+4],ae=B[ee+7],oe=B[ee+10];if(!(Math.abs(j*se+F*ae+G*oe-1)<0.001&&Math.abs(R*se+k*ae+O*oe)<0.001&&Math.abs(_*se+Z*ae+q*oe)<0.001))continue;L[w]=1;let Q=B[ee],te=B[ee+1],ne=B[ee+2],De=T+R*Q+k*te+O*ne,Ue=x+j*Q+F*te+G*ne,ze=N+_*Q+Z*te+q*ne,Oe=z(De,Ue,ze,v);if(Oe!==fe){if(M[w]=1,E++,U)U[w]=Oe}let pe=Math.round(De),me=Math.round(Ue),he=Math.round(ze);if(!xe(pe,me,he))continue;if(!n){D.put(pe,me,he,1);continue}let Ne=n[v],Be=D.get(pe,me,he);if(Be<0||Ne<Be)D.put(pe,me,he,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let w=e[v],P=t.parts[w.part];if(!P||!P.under||!ft(w.m))continue;let V=P.bbox,I=Math.round((V[3]-V[0])/20),B=Math.round((V[5]-V[2])/20);if(!I||!B||I*B>4096)continue;let T=w.m,x=!0,N=0;for(let R=0;R<I&&x;R++)for(let k=0;k<B;k++){let O=V[0]+10+20*R,j=V[2]+10+20*k,F=T[0]+T[3]*O+T[5]*j,G=T[2]+T[9]*O+T[11]*j,_=Math.round(F),Z=Math.round(T[1]+V[4]),q=Math.round(G),J=xe(_,Z,q)?D.get(_,Z,q):-1;if(J<0){x=!1;break}if(J>N)N=J}if(x){if(X[v]=1,H)H[v]=N}}return{nStuds:y,studHidden:M,studUp:L,underHidden:X,studsHidden:E,studHideStep:U,underHideStep:H}}function Jt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>lt(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function we(e,t,n=!0){let r=Jt(e,t,n);return Yt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce="https://ldr-demo.vercel.app/cdn/v1/",ve=new Map,Ae=new Map;function ht(e=Ce,t=fetch){let n=ve.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(()=>ve.delete(e)),ve.set(e,n);return n}var qt=(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"),Me=(e,t)=>qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Me(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Me(r,t)])):e;function Qt(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let d=h.buffer;if(!d)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let C=new DataView(d).getUint32(0,!0),u=new Uint8Array(d,4+C),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[g,f]of Object.entries(h.header.parts??{}))if(!(g in s))s[g]=Me(f,b);for(let[g,f]of Object.entries(h.header.studKinds??{}))if(!(g in o))o[g]=Me(f,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,p=new Uint8Array(c+r);new DataView(p.buffer).setUint32(0,l.length+a,!0),p.set(l,4),p.fill(32,4+l.length,c);let m=c;for(let h of n)p.set(h,m),m+=h.byteLength;return ye(p.buffer)}async function en(e,t={}){e=[...e];try{return await mt(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await mt(e,{...t,fetch:o})}catch{throw n}}}async function mt(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await ht(n,r),i=[...new Set([...e].map(Y))],l=[],a=[];for(let u of i){if(Ae.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let p=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);p+=S.byteLength;for(let g of u.items){let f=de(S.subarray(g.off-u.start,g.off-u.start+g.len)),A=f.buffer.slice(f.byteOffset,f.byteOffset+f.byteLength);Ae.set(n+g.name,ye(A))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let d=i.filter((u)=>Ae.has(n+u)).map((u)=>Ae.get(n+u));return{pack:d.length?Qt(d,{colors:o.colors}):ye(tn(o.colors)),missing:l,requests:c.length,bytes:p}}function tn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}async function gt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=ht(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(f)=>{if(!f.ok)throw Error(`ldr: ${f.status} fetching ${e}`);return Ve(await f.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?"main.ldr":He(e)),a=ct(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let p=ut(o,new Set(a.filter((f)=>f.embedded).map((f)=>f.part)),l),{pack:m,missing:h,requests:d,bytes:C}=await en([...a.filter((f)=>!f.embedded).map((f)=>f.part),...p.values()],t),u=new Map([...p].map(([f,A])=>[A,f])),b=h.map((f)=>u.get(f)??f);for(let[f,A]of p){let z=m.header.parts[A];if(z)m.header.parts[f]=z}let S=performance.now(),g=t.cull?we(a,m.header,t.textures!==!1):void 0;return{insts:a,pack:m,missing:b,requests:d,bytes:C,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:S-c,...g?{cull:performance.now()-S}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await gt(n,{...r,cull:!1,onParsed:(p)=>self.postMessage({id:t,insts:p})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=we(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let p of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(p)c.push(p.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
3805
3828
 
3806
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/cdn.ts
3829
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/cdn.ts
3807
3830
  var worker;
3808
3831
  var seq = 0;
3809
3832
  var pending = new Map;
@@ -3858,7 +3881,7 @@ var abs = (u) => {
3858
3881
  function prepareInWorker(w, source, o) {
3859
3882
  const id = ++seq;
3860
3883
  const opts = { cdn: abs(o.cdn ?? DEFAULT_PARTS_CDN), gap: o.gap, concurrency: o.concurrency, text: o.text, name: o.name, cull: true, textures: o.textures, callouts: o.callouts };
3861
- const name = o.name ?? (o.text ? undefined : decodeURIComponent(source.split(/[?#]/)[0].split("/").pop() || "main.ldr"));
3884
+ const name = o.name ?? (o.text ? undefined : modelFileName(source));
3862
3885
  let insts;
3863
3886
  pendingInsts.set(id, (v) => {
3864
3887
  insts = v;
@@ -3931,6 +3954,7 @@ export {
3931
3954
  createLdrObject,
3932
3955
  createLdrObjectAsync,
3933
3956
  cullCore,
3957
+ decodeModelText,
3934
3958
  decodePack,
3935
3959
  decompressPack,
3936
3960
  embeddedKeys,
@@ -3954,6 +3978,7 @@ export {
3954
3978
  makeFinishMaterial,
3955
3979
  makeMaterial,
3956
3980
  mergePacks,
3981
+ modelFileName,
3957
3982
  mul,
3958
3983
  norm,
3959
3984
  parse,
@@ -1,2 +1,2 @@
1
- declare const _default: "var ht=ArrayBuffer,W=Uint8Array,ge=Uint16Array,gt=Int16Array;var be=Int32Array,Ce=function(e,t,n){if(W.prototype.slice)return W.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 W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.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},bt=function(e,t,n,r){if(W.prototype.copyWithin)return W.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 dt=[\"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||dt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},Be=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},xt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},yt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,p=Be(e,a,c);a+=c;var m=l?1<<l:s,h=Be(e,a,m)+(l==1&&256),d=h;if(!s){var C=1<<10+(e[5]>>3);d=C+(C>>3)*(e[5]&7)}if(d>2145386496)K(1);var u=new W((t==1?h||d:t?0:d)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:p,w:t&&t!=1?t:u.subarray(12),e:d,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return xt(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,p=o,m=new ht(512+(o<<2)),h=new gt(m,0,256),d=new ge(m,0,256),C=new ge(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var g=re(i+1),f=r>>3,A=(1<<g+1)-1,z=(e[f]|e[f+1]<<8|e[f+2]<<16)>>(r&7)&A,x=(1<<g)-1,M=A-i-1,L=z&x;if(L<M)r+=g,z=L;else if(r+=g+1,z>x)z-=M;if(h[++l]=--z,z==-1)i+=z,b[--p]=l;else i-=z;if(!z)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var E=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var v=h[H];if(v<1){d[H]=-v;continue}for(c=0;c<v;++c){b[E]=H;do E=E+U&X;while(E>=p)}}if(E)K(0);for(c=0;c<o;++c){var w=d[b[c]]++,P=S[c]=s-re(w);C[c]=(w<<P)-o}return[r+7>>3,{b:s,s:b,n:S,t:C}]},wt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),p=c[0],m=c[1];t+=o;var h=p<<3,d=e[t];if(!d)K(0);var C=0,u=0,b=m.b,S=b,g=(++t<<3)-8+re(d);for(;;){if(g-=b,g<h)break;var f=g>>3;if(C+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=m.s[C],g-=S,g<h)break;f=g>>3,u+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[C],C=m.t[C],S=m.n[u],u=m.t[u]}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 z=0;for(n=0;n<r;++n){var x=i[n];if(x>11)K(0);z+=x&&1<<x-1}var M=re(z)+1,L=1<<M,D=L-z;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var x=i[n];++l[i[n]=x&&M+1-x]}var E=new W(L<<1),U=E.subarray(0,L),X=E.subarray(L);a[M]=0;for(n=M;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<M-n))}if(a[0]!=L)K(0);for(n=0;n<r;++n){var v=i[n];if(v){var w=a[v];ce(U,n,w,a[v]=w+(1<<M-v))}}return[t,{n:X,b:M,s:U}]},At=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],vt=ue(new W([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],Mt=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],$e=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Ee=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Ct=$e(Ee,0),Se=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Et=$e(Se,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,p=(r<<3)-8+re(o)-c,m=-1;for(;p>l&&m<s;){var h=p>>3,d=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(p&7);a=(a<<c|d)&i,t[++m]=n.s[a],p-=c=n.n[a]}if(p!=l||m+1!=s)K(0)},St=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},Lt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),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+=l,n;return Ce(e,s,a)}if(i==2){var c=e[s],p=c&3,m=c>>2&3,h=c>>4,d=0,C=0;if(p<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(C=m,m<2)h|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(p==0)u.set(e.subarray(s,s+=h),b);else if(p==1)ce(u,e[s++],b);else{var S=t.h;if(p==2){var g=wt(e,s);d+=s-(s=g[0]),t.h=S=g[1]}else if(!S)K(0);(C?St:le)(e.subarray(s,s+=d),u.subarray(b),S)}var f=e[s++];if(f){if(f==255)f=(e[s++]|e[s++]<<8)+32512;else if(f>127)f=f-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var z=[vt,Mt,At];for(var x=2;x>-1;--x){var M=A>>(x<<1)+2&3;if(M==1){var L=new W([0,0,e[s++]]);z[x]={s:L.subarray(2,3),n:L.subarray(0,1),t:new ge(L.buffer,0,1),b:0}}else if(M==2)r=ue(e,s,9-(x&1)),s=r[0],z[x]=r[1];else if(M==3){if(!t.t)K(0);z[x]=t.t[x]}}var D=t.t=z,E=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var v=(a<<3)-8+re(H)-X.b,w=v>>3,P=0,V=(e[w]|e[w+1]<<8)>>(v&7)&(1<<X.b)-1;w=(v-=U.b)>>3;var I=(e[w]|e[w+1]<<8)>>(v&7)&(1<<U.b)-1;w=(v-=E.b)>>3;var B=(e[w]|e[w+1]<<8)>>(v&7)&(1<<E.b)-1;for(++f;--f;){var T=X.s[V],y=X.n[V],N=E.s[B],R=E.n[B],k=U.s[I],O=U.n[I];w=(v-=k)>>3;var j=1<<k,F=j+((e[w]|e[w+1]<<8|e[w+2]<<16|e[w+3]<<24)>>>(v&7)&j-1);w=(v-=Se[N])>>3;var G=Et[N]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Se[N])-1);w=(v-=Ee[T])>>3;var _=Ct[T]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Ee[T])-1);if(w=(v-=y)>>3,V=X.t[V]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<y)-1),w=(v-=R)>>3,B=E.t[B]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<R)-1),w=(v-=O)>>3,I=U.t[I]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<O)-1),F>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=F-=3;else{var Z=F-(_!=0);if(Z){if(F=Z==3?t.o[0]-1:t.o[Z],Z>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=F}else F=t.o[0]}for(var x=0;x<_;++x)u[P+x]=u[b+x];P+=_,b+=_;var q=P-F;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var x=0;x<J;++x)u[P+x]=t.w[ee+x];P+=J,G-=J,q=0}for(var x=0;x<G;++x)u[P+x]=u[q+x];P+=G}if(P!=b)while(b<u.length)u[P++]=u[b++];else P=u.length;if(n)t.y+=P;else u=Ce(u,0,P)}else if(n){if(t.y+=h,b)for(var x=0;x<h;++x)u[x]=u[b+x]}else if(b)u=Ce(u,b);return t.b=a,u}K(2)},Tt=function(e,t){if(e.length==1)return e[0];var n=new W(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 je(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=yt(e,r||t);if(typeof i==\"object\"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=Lt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,bt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Tt(n,o)}function de(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,\"/\");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ve=/^~?\\s*moved\\s+to\\s+(.+)$/i,Pt=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),Ye=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),It=new Set([\"model\",\"submodel\",\"configuration\"]),Ft=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function He(e){let t=Ft.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return Ye.has(n)||It.has(n)?n:void 0}function Rt(e){let t=[],n=0;while(n<e.length){while(e[n]===\" \"||e[n]===\"\\t\")n++;if(n>=e.length)break;if(e[n]==='\"'){let r=\"\";n++;while(n<e.length&&e[n]!=='\"'){if(e[n]===\"\\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==\" \"&&e[r]!==\"\\t\")r++;t.push(e.slice(n,r)),n=r}}return t}function kt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r===\"PLANAR\"?9:r===\"CYLINDRICAL\"?10:r===\"SPHERICAL\"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,\"\");let a=Rt(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let p=a.findIndex((m,h)=>h>0&&m.toUpperCase()===\"GLOSSMAP\");if(p>0&&a[p+1])c.glossmap=a[p+1];if(t)c.next=!0;return c}var Dt=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\"),n=t+\"=\".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Ut(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let p=s();if(p===null)return null;i[c]=+p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(\" \"):l;return{t:1,color:Le(o),m:i,file:Y(a)}}function Ge(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Y(e.slice(14).join(\" \"))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function Je(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,s=new Map,o=null,i=\"\",l,a=null,c=[],p=null,m=()=>{if(!a)return;let g=Dt(a.chunks.join(\"\")),f=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Y(a.name),{name:a.name,bytes:g,...f?{mime:\"image/png\"}:{}}),a=null},h=!0,d=(g)=>{if(m(),o={name:Y(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],p=null,h=!0},C=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=\"\"},S=(g,f)=>{if(p){g.tex=p,p=null;return}let A=c[c.length-1];if(!A)return;if(A.fallback){if(!f)g.fallback=!0}else g.tex=A.map};for(let g of e.split(`\n`)){let f=g.trim();if(!f)continue;if(r&&f.charCodeAt(0)>=50&&f.charCodeAt(0)<=53&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){if(a||C)continue;if(!o)d(t);let M=f.slice(2).trimStart(),L=M.search(/\\s/),D={t:f.charCodeAt(0)-48,color:Le(L<0?M:M.slice(0,L)),p:[],src:f};S(D,!1),o.cmds.push(D),h=!1;continue}if(f.charCodeAt(0)===48&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){let M=2;while(f.charCodeAt(M)===32||f.charCodeAt(M)===9)M++;let L=M;while(L<f.length&&f.charCodeAt(L)!==32&&f.charCodeAt(L)!==9)L++;let D=f.slice(M,L);if(!Pt.has(D)){if(C||a)continue;if(!o)d(t);let E=f.slice(M),U={t:0,text:E};if(D.charCodeAt(0)===33)U.meta=D;if(p=null,h&&!o.org){let H=He(E);if(H)o.org=H}let X=E.match(Ve);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=\".dat\";o.movedTo=Y(H)}o.cmds.push(U);continue}}if(f.charCodeAt(0)===49&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)&&!a&&!C){let M=Ut(f);if(M){if(!o)d(t);S(M,!1),o.cmds.push(M),h=!1;continue}}let A=f.split(/\\s+/);if(+A[0]===0){let M=f.slice(1).trim();if(A[1]===\"FILE\"){b(),C=!1,d(M.slice(5));continue}if(A[1]===\"NOFILE\"){m(),o=null,C=!0;continue}if(A[1]===\"!DATA\"){b(),m(),o=null,C=!1,a={name:M.slice(5).trim(),chunks:[]};continue}if(C)continue;if(a){if(A[1]===\"!:\")a.chunks.push(A.slice(2).join(\"\"));continue}if(!o)d(t);let L={t:0,text:M};if(A[1]===\"STEP\")L.step=!0,c=[],p=null;else if(A[1]===\"BFC\")L.bfc=A.slice(2).join(\" \");else if(A[1]===\"ROTSTEP\")if(L.meta=\"ROTSTEP\",L.step=!0,c=[],p=null,(A[2]??\"\").toUpperCase()===\"END\")L.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let E=(A[5]??\"REL\").toUpperCase();L.rotstep={x:+A[2]||0,y:+A[3]||0,z:+A[4]||0,mode:[\"REL\",\"ABS\",\"ADD\"].includes(E)?E:\"REL\"}}else if(A[1]===\"BUFEXCHG\"){L.meta=\"BUFEXCHG\";let E=(A[2]??\"\").toUpperCase();L.bufexchg={op:E===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:A[3]??\"A\"}}else if(A[1]?.startsWith(\"!\"))L.meta=A[1];if(h&&!o.org){let E=He(M);if(E)o.org=E}if(A[1]===\"!TEXMAP\"){let E=(A[2]??\"\").toUpperCase();if(p=null,E===\"START\"||E===\"NEXT\"){let U=kt(M.replace(/^!TEXMAP\\s+\\S+/i,\"\"),E===\"NEXT\");if(L.texmap={op:E,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),E===\"START\")c.push({map:U,fallback:!1});else p=U}else if(E===\"FALLBACK\"){L.texmap={op:E};let U=c[c.length-1];if(U)U.fallback=!0}else if(E===\"END\")L.texmap={op:E},c.pop()}else if(A[1]===\"!:\"){p=null;let E=Ge(A.slice(2));if(E)S(E,!0),L.geom=E}else p=null;let D=M.match(Ve);if(D&&!o.movedTo){let E=D[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(E))E+=\".dat\";o.movedTo=Y(E)}o.cmds.push(L);continue}if(a||C)continue;if(!o)d(t);let x=Ge(A);if(!x)continue;S(x,!1),o.cmds.push(x),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var tn=Math.PI/180;function qe(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 Qe(e,t){let[n,r,s,o,i,l,a,c,p,m,h,d]=e,[C,u,b,S,g,f,A,z,x,M,L,D]=t;return[o*C+i*u+l*b+n,a*C+c*u+p*b+r,m*C+h*u+d*b+s,o*S+i*A+l*M,o*g+i*z+l*L,o*f+i*x+l*D,a*S+c*A+p*M,a*g+c*z+p*L,a*f+c*x+p*D,m*S+h*A+d*M,m*g+h*z+d*L,m*f+h*x+d*D]}var Te=[0,0,0,1,0,0,0,1,0,0,0,1];var _e=new WeakMap,zt=/^(s|8|48)\\//;function Pe(e,t){let n=e.files.get(Y(t));if(!n)return\"part\";let r=_e.get(n);if(r)return r;if(n.org)r=Ye.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&&zt.test(s.file))?\"part\":\"model\";return _e.set(n,r),r}var We=new WeakMap;function et(e){let t=We.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 We.set(e,t),t}var Ke=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():String(e),Ot=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${Ke(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${Ke(e.color)} ${e.p.join(\" \")}`,Ie=(e,t)=>`${Y(e)}#${t}`;function Nt(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){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:Ie(e.name,t),cmds:n}}function tt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Nt(e,t).cmds.map(Ot)].join(`\n`)+`\n`}function Bt(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,l,a,c,p,m,h]=e,d=a*h-c*m,C=-(l*h-c*p),u=l*m-a*p,b=s*d+o*C+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,g=[d*S,-(o*h-i*m)*S,(o*c-i*a)*S,C*S,(s*h-i*p)*S,-(s*c-i*l)*S,u*S,-(s*m-o*p)*S,(s*a-o*l)*S];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 $t=(e)=>String(+e.toFixed(6)||0),Xe=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function rt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map($t).join(\" \"),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Xe(t.texture)}${t.glossmap?\" GLOSSMAP \"+Xe(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-${Bt(r)}`,source:r}}var jt=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Vt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var Ze=new WeakMap;function st(e){let t=Ze.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=Vt(o.x,o.y,o.z);r=o.mode===\"ABS\"?{abs:!0,m:i,rotstep:o}:o.mode===\"ADD\"&&r?{abs:r.abs,m:jt(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Ze.set(e,n),n}var ot=999999,it=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\";function Ht(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let d=m.name+\"#\"+h,C=l.get(d);if(!C){let u;C=Object.assign(()=>u??=tt(m,h),{file:m,step:h}),l.set(d,C)}return C},p=(m,h,d,C,u,b,S,g,f=null,A=[],z=[])=>{let x=m.files.get(h);if(!x||S>r)return;let M=0,L=S>0?++a:0,D=i&&L?[...A,L]:A,E=i&&L?[...z,d]:z,U=i&&!f?new Map:null,X=-1,H=0,v=(T,y,N,R,k,O)=>{if(X!==M)X=M,H=0;let j=U?.get(M+\"|\"+y);if(j)return j.n++,p(T,T===m?y:T.main,N,R,u+\"/\"+y,[...k,ot],S+1,O,[...k,ot],D,E);let F=[...k,H++],G=n.length;p(T,T===m?y:T.main,N,R,u+\"/\"+y,F,S+1,O,f,D,E),U?.set(M+\"|\"+y,{n:1,from:G,to:n.length})},w=st(x),P=s?et(x):[],V=0,I=(T,y,N,R,k,O,j)=>{if(f)R=f;let F={part:T,color:y,m:N,step:R[0],steps:R,localStep:k,path:u};if(L){if(F.sub=L,i)F.subPath=D,F.subMats=E}if(O)F.embedded=!0;if(j){let _=rt(T,j);F.texPart=_.name,F.texSource=_.source}let G=w[k];if(G)F.view=G;return n.push(F),F},B=(T)=>{while(V<P.length&&P[V]<=T){let y=P[V++];I(Ie(x.name,y),C,d,[...b,y],y,!1,null).source=c(x,y)}};for(let T of x.cmds){if(T.t===0&&T.step){M++;continue}let y=T;if(y.t>=2||y.t===0&&y.geom&&y.geom.t>=2){B(M);continue}if(y.t===0)if(o&&y.geom?.t===1)y=y.geom;else continue;if(y.t!==1)continue;if(o&&y.fallback)continue;let N=y.color===16?C:y.color,R=Qe(d,y.m),k=[...b,M],O=o?y.tex??g:null,j=O?nt(y.m):null,F=O&&j?qe(O,j):null;if(m.files.has(y.file)){if(Pe(m,y.file)===\"model\"){v(m,y.file,R,N,k,F);continue}I(y.file,N,R,k,M,!0,F);continue}let G=t.resolveModel?.(y.file);if(G){v(G,y.file,R,N,k,F);continue}I(y.file,N,R,k,M,!1,F)}if(B(1/0),U){for(let T of U.values())if(T.n>1)for(let y=T.from;y<T.to;y++)n[y].mult??=T.n}};if(Pe(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Te],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return p(e,e.main,Te,16,e.main,[],0,null),n}function at(e,t=\"main.ldr\",n){return Ht(Je(e,t,{geometryText:!0}),n)}function Gt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Y(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Y(t),r)}let l=o.trim().replace(/\\s+/g,\" \");if(l)r.push(l)}return n}var _t=(e)=>{if(!e.startsWith(\"1 \"))return null;let t=e.split(\" \");return t.length>=15?Y(t.slice(14).join(\" \")):null};function Wt(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 lt(e,t,n=\"main.ldr\"){let r=Gt(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let p of r.get(a.pop())){let m=_t(p);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((p)=>p!==i).sort()].map((p)=>\"0 FILE \"+(p===i?\"\":p)+`\n`+r.get(p).join(`\n`)).join(`\n`);s.set(i,`emb/${Wt(c)}.dat`)}return s}var ct=(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,ut=new WeakMap;function Fe(e,t){let n=ut.get(e);if(!n)ut.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,d)=>{l.push(h[0]),a.push(h[1]);for(let C=0;C<12;C++)i[d*12+C]=h[2+C]});let c=null,p=0,m=0;if(s.mask){p=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let d=0;d<h.length;d++)c[d]=h.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:p,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Kt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],p=[],m=[],h=new Re(e.length*2),d=[],C=[];for(let v=0;v<e.length;v++){let w=e[v],P=w.m,V=t.parts[w.part];if(!V||!V.mask||!ct(P))continue;let I=V.bbox,B=1/0,T=-1/0,y=1/0,N=-1/0;for(let O=0;O<2;O++)for(let j=0;j<2;j++){let F=O?I[3]:I[0],G=j?I[5]:I[2],_=P[0]+P[3]*F+P[5]*G,Z=P[2]+P[9]*F+P[11]*G;if(_<B)B=_;if(_>T)T=_;if(Z<y)y=Z;if(Z>N)N=Z}let R=a.length;s.push(B),o.push(T),i.push(y),l.push(N),a.push(v),c.push(Fe(t,w.part)),p.push(I[0]),m.push(I[2]);let k=Math.round((P[1]+I[4])*2);for(let O=Math.floor(B/40);O<=Math.floor(T/40);O++)for(let j=Math.floor(y/40);j<=Math.floor(N/40);j++){if(!xe(k,O,j))continue;let F=C.length;C.push(R),d.push(h.put(k,O,j,F))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,g=NaN,f=NaN,A=-1,z=(v,w,P,V)=>{let I=Math.round(w*2),B=Math.floor(v/40),T=Math.floor(P/40);if(!xe(I,B,T))return fe;let y=fe;if(I!==S||B!==g||T!==f)S=I,g=B,f=T,A=h.get(I,B,T);for(let N=A;N>=0;N=d[N]){let R=C[N];if(a[R]===V||!(v-6>=s[R]-0.5&&v+6<=o[R]+0.5&&P-6>=i[R]-0.5&&P+6<=l[R]+0.5))continue;let k=e[a[R]].m,O=c[R],j=p[R],F=m[R],G=v-k[0],_=w-k[1],Z=P-k[2],q=k[3]*G+k[6]*_+k[9]*Z,J=k[5]*G+k[8]*_+k[11]*Z,{nx:ee,nz:se,mask:ae}=O,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-F)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[R]];if(Q<y)y=Q}}return y},x=0;for(let v of e){let w=Fe(t,v.part);if(w)x+=w.nStuds}let M=new Uint8Array(x),L=new Uint8Array(x),D=new Re(x),E=0,U=n?new Int32Array(x).fill(fe):void 0;for(let v=0,w=0;v<e.length;v++){let P=e[v],V=Fe(t,P.part);if(!V)continue;let I=P.m,B=V.studM,T=I[0],y=I[1],N=I[2],R=I[3],k=I[4],O=I[5],j=I[6],F=I[7],G=I[8],_=I[9],Z=I[10],q=I[11];for(let J=0;J<V.nStuds;J++,w++){let ee=J*12,se=B[ee+4],ae=B[ee+7],oe=B[ee+10];if(!(Math.abs(j*se+F*ae+G*oe-1)<0.001&&Math.abs(R*se+k*ae+O*oe)<0.001&&Math.abs(_*se+Z*ae+q*oe)<0.001))continue;L[w]=1;let Q=B[ee],te=B[ee+1],ne=B[ee+2],ke=T+R*Q+k*te+O*ne,De=y+j*Q+F*te+G*ne,Ue=N+_*Q+Z*te+q*ne,ze=z(ke,De,Ue,v);if(ze!==fe){if(M[w]=1,E++,U)U[w]=ze}let pe=Math.round(ke),me=Math.round(De),he=Math.round(Ue);if(!xe(pe,me,he))continue;if(!n){D.put(pe,me,he,1);continue}let Oe=n[v],Ne=D.get(pe,me,he);if(Ne<0||Oe<Ne)D.put(pe,me,he,Oe)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let w=e[v],P=t.parts[w.part];if(!P||!P.under||!ct(w.m))continue;let V=P.bbox,I=Math.round((V[3]-V[0])/20),B=Math.round((V[5]-V[2])/20);if(!I||!B||I*B>4096)continue;let T=w.m,y=!0,N=0;for(let R=0;R<I&&y;R++)for(let k=0;k<B;k++){let O=V[0]+10+20*R,j=V[2]+10+20*k,F=T[0]+T[3]*O+T[5]*j,G=T[2]+T[9]*O+T[11]*j,_=Math.round(F),Z=Math.round(T[1]+V[4]),q=Math.round(G),J=xe(_,Z,q)?D.get(_,Z,q):-1;if(J<0){y=!1;break}if(J>N)N=J}if(y){if(X[v]=1,H)H[v]=N}}return{nStuds:x,studHidden:M,studUp:L,underHidden:X,studsHidden:E,studHideStep:U,underHideStep:H}}function Xt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>it(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function ye(e,t,n=!0){let r=Xt(e,t,n);return Kt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Me=\"https://ldr-demo.vercel.app/cdn/v1/\",Ae=new Map,we=new Map;function pt(e=Me,t=fetch){let n=Ae.get(e);if(!n)n=t(e+\"parts.json\").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>Ae.delete(e)),Ae.set(e,n);return n}var Zt=(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\"),ve=(e,t)=>Zt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>ve(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,ve(r,t)])):e;function Yt(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let d=h.buffer;if(!d)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let C=new DataView(d).getUint32(0,!0),u=new Uint8Array(d,4+C),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[g,f]of Object.entries(h.header.parts??{}))if(!(g in s))s[g]=ve(f,b);for(let[g,f]of Object.entries(h.header.studKinds??{}))if(!(g in o))o[g]=ve(f,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,p=new Uint8Array(c+r);new DataView(p.buffer).setUint32(0,l.length+a,!0),p.set(l,4),p.fill(32,4+l.length,c);let m=c;for(let h of n)p.set(h,m),m+=h.byteLength;return de(p.buffer)}async function Jt(e,t={}){e=[...e];try{return await ft(e,t)}catch(n){let r=t.cdn??Me,s=t.fetch??fetch;Ae.delete(r);let o=(i,l)=>s(i,{...l,cache:\"reload\"});try{return await ft(e,{...t,fetch:o})}catch{throw n}}}async function ft(e,t){let n=t.cdn??Me,r=t.fetch??fetch,s=t.gap??16384,o=await pt(n,r),i=[...new Set([...e].map(Y))],l=[],a=[];for(let u of i){if(we.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let p=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);p+=S.byteLength;for(let g of u.items){let f=je(S.subarray(g.off-u.start,g.off-u.start+g.len)),A=f.buffer.slice(f.byteOffset,f.byteOffset+f.byteLength);we.set(n+g.name,de(A))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let d=i.filter((u)=>we.has(n+u)).map((u)=>we.get(n+u));return{pack:d.length?Yt(d,{colors:o.colors}):de(qt(o.colors)),missing:l,requests:c.length,bytes:p}}function qt(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}async function mt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=pt(t.cdn??Me,r);s.catch(()=>{});let o=t.text?e:await r(e).then((f)=>{if(!f.ok)throw Error(`ldr: ${f.status} fetching ${e}`);return f.text()}),i=performance.now(),l=t.name??(t.text?\"main.ldr\":decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\")),a=at(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let p=lt(o,new Set(a.filter((f)=>f.embedded).map((f)=>f.part)),l),{pack:m,missing:h,requests:d,bytes:C}=await Jt([...a.filter((f)=>!f.embedded).map((f)=>f.part),...p.values()],t),u=new Map([...p].map(([f,A])=>[A,f])),b=h.map((f)=>u.get(f)??f);for(let[f,A]of p){let z=m.header.parts[A];if(z)m.header.parts[f]=z}let S=performance.now(),g=t.cull?ye(a,m.header,t.textures!==!1):void 0;return{insts:a,pack:m,missing:b,requests:d,bytes:C,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:S-c,...g?{cull:performance.now()-S}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await mt(n,{...r,cull:!1,onParsed:(p)=>self.postMessage({id:t,insts:p})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=ye(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let p of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(p)c.push(p.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){self.postMessage({id:t,phase:\"error\",error:String(s?.message??s)})}};\n";
1
+ declare const _default: "var bt=ArrayBuffer,W=Uint8Array,ge=Uint16Array,dt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.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 W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.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},yt=function(e,t,n,r){if(W.prototype.copyWithin)return W.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 xt=[\"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||xt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},$e=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},wt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},At=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,p=$e(e,a,c);a+=c;var m=l?1<<l:s,h=$e(e,a,m)+(l==1&&256),d=h;if(!s){var C=1<<10+(e[5]>>3);d=C+(C>>3)*(e[5]&7)}if(d>2145386496)K(1);var u=new W((t==1?h||d:t?0:d)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:p,w:t&&t!=1?t:u.subarray(12),e:d,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return wt(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,p=o,m=new bt(512+(o<<2)),h=new dt(m,0,256),d=new ge(m,0,256),C=new ge(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var g=re(i+1),f=r>>3,A=(1<<g+1)-1,z=(e[f]|e[f+1]<<8|e[f+2]<<16)>>(r&7)&A,y=(1<<g)-1,M=A-i-1,L=z&y;if(L<M)r+=g,z=L;else if(r+=g+1,z>y)z-=M;if(h[++l]=--z,z==-1)i+=z,b[--p]=l;else i-=z;if(!z)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var E=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var v=h[H];if(v<1){d[H]=-v;continue}for(c=0;c<v;++c){b[E]=H;do E=E+U&X;while(E>=p)}}if(E)K(0);for(c=0;c<o;++c){var w=d[b[c]]++,P=S[c]=s-re(w);C[c]=(w<<P)-o}return[r+7>>3,{b:s,s:b,n:S,t:C}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),p=c[0],m=c[1];t+=o;var h=p<<3,d=e[t];if(!d)K(0);var C=0,u=0,b=m.b,S=b,g=(++t<<3)-8+re(d);for(;;){if(g-=b,g<h)break;var f=g>>3;if(C+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=m.s[C],g-=S,g<h)break;f=g>>3,u+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[C],C=m.t[C],S=m.n[u],u=m.t[u]}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 z=0;for(n=0;n<r;++n){var y=i[n];if(y>11)K(0);z+=y&&1<<y-1}var M=re(z)+1,L=1<<M,D=L-z;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var y=i[n];++l[i[n]=y&&M+1-y]}var E=new W(L<<1),U=E.subarray(0,L),X=E.subarray(L);a[M]=0;for(n=M;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<M-n))}if(a[0]!=L)K(0);for(n=0;n<r;++n){var v=i[n];if(v){var w=a[v];ce(U,n,w,a[v]=w+(1<<M-v))}}return[t,{n:X,b:M,s:U}]},Mt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([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],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],je=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=je(Se,0),Le=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Lt=je(Le,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,p=(r<<3)-8+re(o)-c,m=-1;for(;p>l&&m<s;){var h=p>>3,d=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(p&7);a=(a<<c|d)&i,t[++m]=n.s[a],p-=c=n.n[a]}if(p!=l||m+1!=s)K(0)},Tt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},Pt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),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+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],p=c&3,m=c>>2&3,h=c>>4,d=0,C=0;if(p<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(C=m,m<2)h|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(p==0)u.set(e.subarray(s,s+=h),b);else if(p==1)ce(u,e[s++],b);else{var S=t.h;if(p==2){var g=vt(e,s);d+=s-(s=g[0]),t.h=S=g[1]}else if(!S)K(0);(C?Tt:le)(e.subarray(s,s+=d),u.subarray(b),S)}var f=e[s++];if(f){if(f==255)f=(e[s++]|e[s++]<<8)+32512;else if(f>127)f=f-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var z=[Ct,Et,Mt];for(var y=2;y>-1;--y){var M=A>>(y<<1)+2&3;if(M==1){var L=new W([0,0,e[s++]]);z[y]={s:L.subarray(2,3),n:L.subarray(0,1),t:new ge(L.buffer,0,1),b:0}}else if(M==2)r=ue(e,s,9-(y&1)),s=r[0],z[y]=r[1];else if(M==3){if(!t.t)K(0);z[y]=t.t[y]}}var D=t.t=z,E=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var v=(a<<3)-8+re(H)-X.b,w=v>>3,P=0,V=(e[w]|e[w+1]<<8)>>(v&7)&(1<<X.b)-1;w=(v-=U.b)>>3;var I=(e[w]|e[w+1]<<8)>>(v&7)&(1<<U.b)-1;w=(v-=E.b)>>3;var B=(e[w]|e[w+1]<<8)>>(v&7)&(1<<E.b)-1;for(++f;--f;){var T=X.s[V],x=X.n[V],N=E.s[B],R=E.n[B],k=U.s[I],O=U.n[I];w=(v-=k)>>3;var j=1<<k,F=j+((e[w]|e[w+1]<<8|e[w+2]<<16|e[w+3]<<24)>>>(v&7)&j-1);w=(v-=Le[N])>>3;var G=Lt[N]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Le[N])-1);w=(v-=Se[T])>>3;var _=St[T]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Se[T])-1);if(w=(v-=x)>>3,V=X.t[V]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<x)-1),w=(v-=R)>>3,B=E.t[B]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<R)-1),w=(v-=O)>>3,I=U.t[I]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<O)-1),F>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=F-=3;else{var Z=F-(_!=0);if(Z){if(F=Z==3?t.o[0]-1:t.o[Z],Z>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=F}else F=t.o[0]}for(var y=0;y<_;++y)u[P+y]=u[b+y];P+=_,b+=_;var q=P-F;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var y=0;y<J;++y)u[P+y]=t.w[ee+y];P+=J,G-=J,q=0}for(var y=0;y<G;++y)u[P+y]=u[q+y];P+=G}if(P!=b)while(b<u.length)u[P++]=u[b++];else P=u.length;if(n)t.y+=P;else u=Ee(u,0,P)}else if(n){if(t.y+=h,b)for(var y=0;y<h;++y)u[y]=u[b+y]}else if(b)u=Ee(u,b);return t.b=a,u}K(2)},It=function(e,t){if(e.length==1)return e[0];var n=new W(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 de(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=At(e,r||t);if(typeof i==\"object\"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=Pt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,yt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return It(n,o)}async function Ft(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(de(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 Ve(e){return new TextDecoder().decode(await Ft(e))}var He=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\").replace(/\\.(zst|gz)$/i,\"\")||\"main.ldr\";function ye(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]===\"f32\"?new Float32Array(e,r+o[0],o[1]):o[2]===\"u16\"?new Uint16Array(e,r+o[0],o[1]):o[2]===\"u8\"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\");function Te(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ge=/^~?\\s*moved\\s+to\\s+(.+)$/i,Rt=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),qe=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),kt=new Set([\"model\",\"submodel\",\"configuration\"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function _e(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return qe.has(n)||kt.has(n)?n:void 0}function Ut(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 zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r===\"PLANAR\"?9:r===\"CYLINDRICAL\"?10:r===\"SPHERICAL\"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,\"\");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let p=a.findIndex((m,h)=>h>0&&m.toUpperCase()===\"GLOSSMAP\");if(p>0&&a[p+1])c.glossmap=a[p+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\"),n=t+\"=\".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let p=s();if(p===null)return null;i[c]=+p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(\" \"):l;return{t:1,color:Te(o),m:i,file:Y(a)}}function We(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Te(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Y(e.slice(14).join(\" \"))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function Qe(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,s=new Map,o=null,i=\"\",l,a=null,c=[],p=null,m=()=>{if(!a)return;let g=Ot(a.chunks.join(\"\")),f=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Y(a.name),{name:a.name,bytes:g,...f?{mime:\"image/png\"}:{}}),a=null},h=!0,d=(g)=>{if(m(),o={name:Y(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],p=null,h=!0},C=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=\"\"},S=(g,f)=>{if(p){g.tex=p,p=null;return}let A=c[c.length-1];if(!A)return;if(A.fallback){if(!f)g.fallback=!0}else g.tex=A.map};for(let g of e.split(`\n`)){let f=g.trim();if(!f)continue;if(r&&f.charCodeAt(0)>=50&&f.charCodeAt(0)<=53&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){if(a||C)continue;if(!o)d(t);let M=f.slice(2).trimStart(),L=M.search(/\\s/),D={t:f.charCodeAt(0)-48,color:Te(L<0?M:M.slice(0,L)),p:[],src:f};S(D,!1),o.cmds.push(D),h=!1;continue}if(f.charCodeAt(0)===48&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){let M=2;while(f.charCodeAt(M)===32||f.charCodeAt(M)===9)M++;let L=M;while(L<f.length&&f.charCodeAt(L)!==32&&f.charCodeAt(L)!==9)L++;let D=f.slice(M,L);if(!Rt.has(D)){if(C||a)continue;if(!o)d(t);let E=f.slice(M),U={t:0,text:E};if(D.charCodeAt(0)===33)U.meta=D;if(p=null,h&&!o.org){let H=_e(E);if(H)o.org=H}let X=E.match(Ge);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=\".dat\";o.movedTo=Y(H)}o.cmds.push(U);continue}}if(f.charCodeAt(0)===49&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)&&!a&&!C){let M=Nt(f);if(M){if(!o)d(t);S(M,!1),o.cmds.push(M),h=!1;continue}}let A=f.split(/\\s+/);if(+A[0]===0){let M=f.slice(1).trim();if(A[1]===\"FILE\"){b(),C=!1,d(M.slice(5));continue}if(A[1]===\"NOFILE\"){m(),o=null,C=!0;continue}if(A[1]===\"!DATA\"){b(),m(),o=null,C=!1,a={name:M.slice(5).trim(),chunks:[]};continue}if(C)continue;if(a){if(A[1]===\"!:\")a.chunks.push(A.slice(2).join(\"\"));continue}if(!o)d(t);let L={t:0,text:M};if(A[1]===\"STEP\")L.step=!0,c=[],p=null;else if(A[1]===\"BFC\")L.bfc=A.slice(2).join(\" \");else if(A[1]===\"ROTSTEP\")if(L.meta=\"ROTSTEP\",L.step=!0,c=[],p=null,(A[2]??\"\").toUpperCase()===\"END\")L.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let E=(A[5]??\"REL\").toUpperCase();L.rotstep={x:+A[2]||0,y:+A[3]||0,z:+A[4]||0,mode:[\"REL\",\"ABS\",\"ADD\"].includes(E)?E:\"REL\"}}else if(A[1]===\"BUFEXCHG\"){L.meta=\"BUFEXCHG\";let E=(A[2]??\"\").toUpperCase();L.bufexchg={op:E===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:A[3]??\"A\"}}else if(A[1]?.startsWith(\"!\"))L.meta=A[1];if(h&&!o.org){let E=_e(M);if(E)o.org=E}if(A[1]===\"!TEXMAP\"){let E=(A[2]??\"\").toUpperCase();if(p=null,E===\"START\"||E===\"NEXT\"){let U=zt(M.replace(/^!TEXMAP\\s+\\S+/i,\"\"),E===\"NEXT\");if(L.texmap={op:E,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),E===\"START\")c.push({map:U,fallback:!1});else p=U}else if(E===\"FALLBACK\"){L.texmap={op:E};let U=c[c.length-1];if(U)U.fallback=!0}else if(E===\"END\")L.texmap={op:E},c.pop()}else if(A[1]===\"!:\"){p=null;let E=We(A.slice(2));if(E)S(E,!0),L.geom=E}else p=null;let D=M.match(Ge);if(D&&!o.movedTo){let E=D[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(E))E+=\".dat\";o.movedTo=Y(E)}o.cmds.push(L);continue}if(a||C)continue;if(!o)d(t);let y=We(A);if(!y)continue;S(y,!1),o.cmds.push(y),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var on=Math.PI/180;function et(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 tt(e,t){let[n,r,s,o,i,l,a,c,p,m,h,d]=e,[C,u,b,S,g,f,A,z,y,M,L,D]=t;return[o*C+i*u+l*b+n,a*C+c*u+p*b+r,m*C+h*u+d*b+s,o*S+i*A+l*M,o*g+i*z+l*L,o*f+i*y+l*D,a*S+c*A+p*M,a*g+c*z+p*L,a*f+c*y+p*D,m*S+h*A+d*M,m*g+h*z+d*L,m*f+h*y+d*D]}var Pe=[0,0,0,1,0,0,0,1,0,0,0,1];var Ke=new WeakMap,Bt=/^(s|8|48)\\//;function Ie(e,t){let n=e.files.get(Y(t));if(!n)return\"part\";let r=Ke.get(n);if(r)return r;if(n.org)r=qe.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&&Bt.test(s.file))?\"part\":\"model\";return Ke.set(n,r),r}var Xe=new WeakMap;function nt(e){let t=Xe.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 Xe.set(e,t),t}var Ze=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():String(e),$t=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${Ze(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${Ze(e.color)} ${e.p.join(\" \")}`,Fe=(e,t)=>`${Y(e)}#${t}`;function jt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op===\"NEXT\";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){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:Fe(e.name,t),cmds:n}}function rt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...jt(e,t).cmds.map($t)].join(`\n`)+`\n`}function Vt(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 st(e){let[t,n,r,s,o,i,l,a,c,p,m,h]=e,d=a*h-c*m,C=-(l*h-c*p),u=l*m-a*p,b=s*d+o*C+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,g=[d*S,-(o*h-i*m)*S,(o*c-i*a)*S,C*S,(s*h-i*p)*S,-(s*c-i*l)*S,u*S,-(s*m-o*p)*S,(s*a-o*l)*S];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 Ht=(e)=>String(+e.toFixed(6)||0),Ye=(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(Ht).join(\" \"),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Ye(t.texture)}${t.glossmap?\" GLOSSMAP \"+Ye(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-${Vt(r)}`,source:r}}var Gt=(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 _t(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var Je=new WeakMap;function it(e){let t=Je.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=_t(o.x,o.y,o.z);r=o.mode===\"ABS\"?{abs:!0,m:i,rotstep:o}:o.mode===\"ADD\"&&r?{abs:r.abs,m:Gt(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Je.set(e,n),n}var at=999999,lt=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\";function Wt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let d=m.name+\"#\"+h,C=l.get(d);if(!C){let u;C=Object.assign(()=>u??=rt(m,h),{file:m,step:h}),l.set(d,C)}return C},p=(m,h,d,C,u,b,S,g,f=null,A=[],z=[])=>{let y=m.files.get(h);if(!y||S>r)return;let M=0,L=S>0?++a:0,D=i&&L?[...A,L]:A,E=i&&L?[...z,d]:z,U=i&&!f?new Map:null,X=-1,H=0,v=(T,x,N,R,k,O)=>{if(X!==M)X=M,H=0;let j=U?.get(M+\"|\"+x);if(j)return j.n++,p(T,T===m?x:T.main,N,R,u+\"/\"+x,[...k,at],S+1,O,[...k,at],D,E);let F=[...k,H++],G=n.length;p(T,T===m?x:T.main,N,R,u+\"/\"+x,F,S+1,O,f,D,E),U?.set(M+\"|\"+x,{n:1,from:G,to:n.length})},w=it(y),P=s?nt(y):[],V=0,I=(T,x,N,R,k,O,j)=>{if(f)R=f;let F={part:T,color:x,m:N,step:R[0],steps:R,localStep:k,path:u};if(L){if(F.sub=L,i)F.subPath=D,F.subMats=E}if(O)F.embedded=!0;if(j){let _=ot(T,j);F.texPart=_.name,F.texSource=_.source}let G=w[k];if(G)F.view=G;return n.push(F),F},B=(T)=>{while(V<P.length&&P[V]<=T){let x=P[V++];I(Fe(y.name,x),C,d,[...b,x],x,!1,null).source=c(y,x)}};for(let T of y.cmds){if(T.t===0&&T.step){M++;continue}let x=T;if(x.t>=2||x.t===0&&x.geom&&x.geom.t>=2){B(M);continue}if(x.t===0)if(o&&x.geom?.t===1)x=x.geom;else continue;if(x.t!==1)continue;if(o&&x.fallback)continue;let N=x.color===16?C:x.color,R=tt(d,x.m),k=[...b,M],O=o?x.tex??g:null,j=O?st(x.m):null,F=O&&j?et(O,j):null;if(m.files.has(x.file)){if(Ie(m,x.file)===\"model\"){v(m,x.file,R,N,k,F);continue}I(x.file,N,R,k,M,!0,F);continue}let G=t.resolveModel?.(x.file);if(G){v(G,x.file,R,N,k,F);continue}I(x.file,N,R,k,M,!1,F)}if(B(1/0),U){for(let T of U.values())if(T.n>1)for(let x=T.from;x<T.to;x++)n[x].mult??=T.n}};if(Ie(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Pe],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return p(e,e.main,Pe,16,e.main,[],0,null),n}function ct(e,t=\"main.ldr\",n){return Wt(Qe(e,t,{geometryText:!0}),n)}function Kt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Y(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Y(t),r)}let l=o.trim().replace(/\\s+/g,\" \");if(l)r.push(l)}return n}var Xt=(e)=>{if(!e.startsWith(\"1 \"))return null;let t=e.split(\" \");return t.length>=15?Y(t.slice(14).join(\" \")):null};function Zt(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 ut(e,t,n=\"main.ldr\"){let r=Kt(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let p of r.get(a.pop())){let m=Xt(p);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((p)=>p!==i).sort()].map((p)=>\"0 FILE \"+(p===i?\"\":p)+`\n`+r.get(p).join(`\n`)).join(`\n`);s.set(i,`emb/${Zt(c)}.dat`)}return s}var ft=(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,pt=new WeakMap;function Re(e,t){let n=pt.get(e);if(!n)pt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,d)=>{l.push(h[0]),a.push(h[1]);for(let C=0;C<12;C++)i[d*12+C]=h[2+C]});let c=null,p=0,m=0;if(s.mask){p=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let d=0;d<h.length;d++)c[d]=h.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:p,nz:m}),r}var ie=1073741824;class ke{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Yt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],p=[],m=[],h=new ke(e.length*2),d=[],C=[];for(let v=0;v<e.length;v++){let w=e[v],P=w.m,V=t.parts[w.part];if(!V||!V.mask||!ft(P))continue;let I=V.bbox,B=1/0,T=-1/0,x=1/0,N=-1/0;for(let O=0;O<2;O++)for(let j=0;j<2;j++){let F=O?I[3]:I[0],G=j?I[5]:I[2],_=P[0]+P[3]*F+P[5]*G,Z=P[2]+P[9]*F+P[11]*G;if(_<B)B=_;if(_>T)T=_;if(Z<x)x=Z;if(Z>N)N=Z}let R=a.length;s.push(B),o.push(T),i.push(x),l.push(N),a.push(v),c.push(Re(t,w.part)),p.push(I[0]),m.push(I[2]);let k=Math.round((P[1]+I[4])*2);for(let O=Math.floor(B/40);O<=Math.floor(T/40);O++)for(let j=Math.floor(x/40);j<=Math.floor(N/40);j++){if(!xe(k,O,j))continue;let F=C.length;C.push(R),d.push(h.put(k,O,j,F))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,g=NaN,f=NaN,A=-1,z=(v,w,P,V)=>{let I=Math.round(w*2),B=Math.floor(v/40),T=Math.floor(P/40);if(!xe(I,B,T))return fe;let x=fe;if(I!==S||B!==g||T!==f)S=I,g=B,f=T,A=h.get(I,B,T);for(let N=A;N>=0;N=d[N]){let R=C[N];if(a[R]===V||!(v-6>=s[R]-0.5&&v+6<=o[R]+0.5&&P-6>=i[R]-0.5&&P+6<=l[R]+0.5))continue;let k=e[a[R]].m,O=c[R],j=p[R],F=m[R],G=v-k[0],_=w-k[1],Z=P-k[2],q=k[3]*G+k[6]*_+k[9]*Z,J=k[5]*G+k[8]*_+k[11]*Z,{nx:ee,nz:se,mask:ae}=O,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-F)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[R]];if(Q<x)x=Q}}return x},y=0;for(let v of e){let w=Re(t,v.part);if(w)y+=w.nStuds}let M=new Uint8Array(y),L=new Uint8Array(y),D=new ke(y),E=0,U=n?new Int32Array(y).fill(fe):void 0;for(let v=0,w=0;v<e.length;v++){let P=e[v],V=Re(t,P.part);if(!V)continue;let I=P.m,B=V.studM,T=I[0],x=I[1],N=I[2],R=I[3],k=I[4],O=I[5],j=I[6],F=I[7],G=I[8],_=I[9],Z=I[10],q=I[11];for(let J=0;J<V.nStuds;J++,w++){let ee=J*12,se=B[ee+4],ae=B[ee+7],oe=B[ee+10];if(!(Math.abs(j*se+F*ae+G*oe-1)<0.001&&Math.abs(R*se+k*ae+O*oe)<0.001&&Math.abs(_*se+Z*ae+q*oe)<0.001))continue;L[w]=1;let Q=B[ee],te=B[ee+1],ne=B[ee+2],De=T+R*Q+k*te+O*ne,Ue=x+j*Q+F*te+G*ne,ze=N+_*Q+Z*te+q*ne,Oe=z(De,Ue,ze,v);if(Oe!==fe){if(M[w]=1,E++,U)U[w]=Oe}let pe=Math.round(De),me=Math.round(Ue),he=Math.round(ze);if(!xe(pe,me,he))continue;if(!n){D.put(pe,me,he,1);continue}let Ne=n[v],Be=D.get(pe,me,he);if(Be<0||Ne<Be)D.put(pe,me,he,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let w=e[v],P=t.parts[w.part];if(!P||!P.under||!ft(w.m))continue;let V=P.bbox,I=Math.round((V[3]-V[0])/20),B=Math.round((V[5]-V[2])/20);if(!I||!B||I*B>4096)continue;let T=w.m,x=!0,N=0;for(let R=0;R<I&&x;R++)for(let k=0;k<B;k++){let O=V[0]+10+20*R,j=V[2]+10+20*k,F=T[0]+T[3]*O+T[5]*j,G=T[2]+T[9]*O+T[11]*j,_=Math.round(F),Z=Math.round(T[1]+V[4]),q=Math.round(G),J=xe(_,Z,q)?D.get(_,Z,q):-1;if(J<0){x=!1;break}if(J>N)N=J}if(x){if(X[v]=1,H)H[v]=N}}return{nStuds:y,studHidden:M,studUp:L,underHidden:X,studsHidden:E,studHideStep:U,underHideStep:H}}function Jt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>lt(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function we(e,t,n=!0){let r=Jt(e,t,n);return Yt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce=\"https://ldr-demo.vercel.app/cdn/v1/\",ve=new Map,Ae=new Map;function ht(e=Ce,t=fetch){let n=ve.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(()=>ve.delete(e)),ve.set(e,n);return n}var qt=(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\"),Me=(e,t)=>qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Me(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Me(r,t)])):e;function Qt(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let d=h.buffer;if(!d)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let C=new DataView(d).getUint32(0,!0),u=new Uint8Array(d,4+C),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[g,f]of Object.entries(h.header.parts??{}))if(!(g in s))s[g]=Me(f,b);for(let[g,f]of Object.entries(h.header.studKinds??{}))if(!(g in o))o[g]=Me(f,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,p=new Uint8Array(c+r);new DataView(p.buffer).setUint32(0,l.length+a,!0),p.set(l,4),p.fill(32,4+l.length,c);let m=c;for(let h of n)p.set(h,m),m+=h.byteLength;return ye(p.buffer)}async function en(e,t={}){e=[...e];try{return await mt(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:\"reload\"});try{return await mt(e,{...t,fetch:o})}catch{throw n}}}async function mt(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await ht(n,r),i=[...new Set([...e].map(Y))],l=[],a=[];for(let u of i){if(Ae.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let p=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);p+=S.byteLength;for(let g of u.items){let f=de(S.subarray(g.off-u.start,g.off-u.start+g.len)),A=f.buffer.slice(f.byteOffset,f.byteOffset+f.byteLength);Ae.set(n+g.name,ye(A))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let d=i.filter((u)=>Ae.has(n+u)).map((u)=>Ae.get(n+u));return{pack:d.length?Qt(d,{colors:o.colors}):ye(tn(o.colors)),missing:l,requests:c.length,bytes:p}}function tn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}async function gt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=ht(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(f)=>{if(!f.ok)throw Error(`ldr: ${f.status} fetching ${e}`);return Ve(await f.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?\"main.ldr\":He(e)),a=ct(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let p=ut(o,new Set(a.filter((f)=>f.embedded).map((f)=>f.part)),l),{pack:m,missing:h,requests:d,bytes:C}=await en([...a.filter((f)=>!f.embedded).map((f)=>f.part),...p.values()],t),u=new Map([...p].map(([f,A])=>[A,f])),b=h.map((f)=>u.get(f)??f);for(let[f,A]of p){let z=m.header.parts[A];if(z)m.header.parts[f]=z}let S=performance.now(),g=t.cull?we(a,m.header,t.textures!==!1):void 0;return{insts:a,pack:m,missing:b,requests:d,bytes:C,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:S-c,...g?{cull:performance.now()-S}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await gt(n,{...r,cull:!1,onParsed:(p)=>self.postMessage({id:t,insts:p})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=we(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let p of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(p)c.push(p.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){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-MHOtAg/src/spec.ts
1
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/spec.ts
2
2
  var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
3
3
  function parseColor(tok) {
4
4
  if (/^0x/i.test(tok))
@@ -690,7 +690,7 @@ function fileStepViews(f) {
690
690
  viewMemo.set(f, out);
691
691
  return out;
692
692
  }
693
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/model.ts
693
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/model.ts
694
694
  var CALLOUT_END = 999999;
695
695
  var stepKey = (steps) => steps.map((x) => String(x).padStart(6, "0")).join(".") + "~";
696
696
  function flatten(doc, opts = {}) {
@@ -1039,7 +1039,7 @@ function parseLDConfig(text) {
1039
1039
  }
1040
1040
  return out;
1041
1041
  }
1042
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/instructions.ts
1042
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/instructions.ts
1043
1043
  var MIN_VIS = 0.5;
1044
1044
  var REORIENT = 0.35;
1045
1045
  var deg = Math.PI / 180;
@@ -1407,10 +1407,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
1407
1407
  }
1408
1408
  };
1409
1409
  }
1410
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/render.ts
1410
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/render.ts
1411
1411
  import * as THREE from "three";
1412
1412
 
1413
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/pack-io.ts
1413
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/pack-io.ts
1414
1414
  import { decompress } from "fzstd";
1415
1415
  async function decompressPack(data) {
1416
1416
  const u = data instanceof Uint8Array ? data : new Uint8Array(data);
@@ -1421,6 +1421,10 @@ async function decompressPack(data) {
1421
1421
  return new Response(new Blob([u]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();
1422
1422
  return own(u);
1423
1423
  }
1424
+ async function decodeModelText(data) {
1425
+ return new TextDecoder().decode(await decompressPack(data));
1426
+ }
1427
+ var modelFileName = (url) => decodeURIComponent(url.split(/[?#]/)[0].split("/").pop() || "main.ldr").replace(/\.(zst|gz)$/i, "") || "main.ldr";
1424
1428
  function decodePack(buf) {
1425
1429
  const hl = new DataView(buf).getUint32(0, true);
1426
1430
  const header = JSON.parse(new TextDecoder().decode(new Uint8Array(buf, 4, hl)));
@@ -1429,7 +1433,7 @@ function decodePack(buf) {
1429
1433
  return { header, arr, bytes: buf.byteLength, buffer: buf };
1430
1434
  }
1431
1435
 
1432
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/cull.ts
1436
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/cull.ts
1433
1437
  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;
1434
1438
  var prepCache = new WeakMap;
1435
1439
  function prepPart(H, part) {
@@ -1746,7 +1750,7 @@ function precomputeCull(instances, H, useTex = true) {
1746
1750
  return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
1747
1751
  }
1748
1752
 
1749
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/render.ts
1753
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/render.ts
1750
1754
  async function loadPack(url) {
1751
1755
  const res = await fetch(url);
1752
1756
  if (!res.ok)
@@ -3304,8 +3308,21 @@ function buildLdrScene(insts, pack, P, color, mark) {
3304
3308
  r = g.next();
3305
3309
  return r.value;
3306
3310
  }
3311
+ function yieldToMain() {
3312
+ const s = globalThis.scheduler;
3313
+ if (s && typeof s.yield === "function")
3314
+ return s.yield();
3315
+ return new Promise((res) => {
3316
+ const c = new MessageChannel;
3317
+ c.port1.onmessage = () => res();
3318
+ c.port2.postMessage(null);
3319
+ });
3320
+ }
3307
3321
  async function buildLdrSceneAsync(insts, pack, P, color, mark, opts = {}) {
3308
3322
  const sliceMs = opts.sliceMs ?? 8;
3323
+ const postPaint = opts.postPaintSliceMs ?? Math.max(sliceMs, 24);
3324
+ let painting = typeof opts.onSlice === "function";
3325
+ let effective = painting ? sliceMs : postPaint;
3309
3326
  const g = buildLdrSceneGen(insts, pack, P, color, mark);
3310
3327
  let r = g.next();
3311
3328
  let sliceStart = performance.now();
@@ -3313,12 +3330,17 @@ async function buildLdrSceneAsync(insts, pack, P, color, mark, opts = {}) {
3313
3330
  let yields = 0;
3314
3331
  while (!r.done) {
3315
3332
  const now = performance.now();
3316
- if (now - sliceStart >= sliceMs) {
3333
+ if (now - sliceStart >= effective) {
3317
3334
  longestSliceMs = Math.max(longestSliceMs, now - sliceStart);
3318
3335
  yields++;
3319
- if (opts.onSlice)
3320
- await opts.onSlice(r.value);
3321
- await new Promise((res) => setTimeout(res, 0));
3336
+ if (painting && opts.onSlice) {
3337
+ const cont = await opts.onSlice(r.value);
3338
+ if (cont === false) {
3339
+ painting = false;
3340
+ effective = postPaint;
3341
+ }
3342
+ }
3343
+ await yieldToMain();
3322
3344
  sliceStart = performance.now();
3323
3345
  }
3324
3346
  r = g.next();
@@ -3350,7 +3372,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
3350
3372
  await new Promise((r) => setTimeout(r, 0));
3351
3373
  }
3352
3374
  }
3353
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/scene.ts
3375
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/scene.ts
3354
3376
  import * as THREE2 from "three";
3355
3377
  function colorFn(src, pack, fallback) {
3356
3378
  const table = new Map;
@@ -3556,20 +3578,21 @@ function createLdrObjectInner(instances, pack, options, progressive) {
3556
3578
  so.cull = cullCore(all, pack.header, so.steps);
3557
3579
  const built = await buildLdrSceneAsync(all, pack, so, color, () => {}, {
3558
3580
  sliceMs: o.sliceMs,
3559
- onSlice: async (root) => {
3581
+ postPaintSliceMs: o.postPaintSliceMs,
3582
+ onSlice: o.onSlice ? async (root) => {
3560
3583
  if (root.parent !== object)
3561
3584
  object.add(root);
3562
- await o.onSlice?.();
3563
- }
3585
+ return await o.onSlice();
3586
+ } : undefined
3564
3587
  });
3565
3588
  applyBuilt(built, t0);
3566
3589
  return finish();
3567
3590
  })();
3568
3591
  }
3569
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/parts-cdn.ts
3592
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/parts-cdn.ts
3570
3593
  import { decompress as decompress2 } from "fzstd";
3571
3594
 
3572
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/embedded.ts
3595
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/embedded.ts
3573
3596
  function splitFiles(text, fallback) {
3574
3597
  const files = new Map;
3575
3598
  let cur = null, saw = false;
@@ -3641,7 +3664,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
3641
3664
  return out;
3642
3665
  }
3643
3666
 
3644
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/parts-cdn.ts
3667
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/parts-cdn.ts
3645
3668
  var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
3646
3669
  var indexCache = new Map;
3647
3670
  var shardCache = new Map;
@@ -3777,13 +3800,13 @@ async function prepareModel(source, o = {}) {
3777
3800
  const f = o.fetch ?? fetch;
3778
3801
  const idxP = loadPartsIndex(o.cdn ?? DEFAULT_PARTS_CDN, f);
3779
3802
  idxP.catch(() => {});
3780
- const text = o.text ? source : await f(source).then((r) => {
3803
+ const text = o.text ? source : await f(source).then(async (r) => {
3781
3804
  if (!r.ok)
3782
3805
  throw new Error(`ldr: ${r.status} fetching ${source}`);
3783
- return r.text();
3806
+ return decodeModelText(await r.arrayBuffer());
3784
3807
  });
3785
3808
  const t1 = performance.now();
3786
- const name = o.name ?? (o.text ? "main.ldr" : decodeURIComponent(source.split(/[?#]/)[0].split("/").pop() || "main.ldr"));
3809
+ const name = o.name ?? (o.text ? "main.ldr" : modelFileName(source));
3787
3810
  const insts = parseModel(text, name, { looseGeometry: false, callouts: o.callouts });
3788
3811
  const t2 = performance.now();
3789
3812
  o.onParsed?.(insts);
@@ -3801,10 +3824,10 @@ async function prepareModel(source, o = {}) {
3801
3824
  return { insts, pack, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
3802
3825
  }
3803
3826
 
3804
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/load-worker.gen.ts
3805
- var load_worker_gen_default = 'var ht=ArrayBuffer,W=Uint8Array,ge=Uint16Array,gt=Int16Array;var be=Int32Array,Ce=function(e,t,n){if(W.prototype.slice)return W.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 W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.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},bt=function(e,t,n,r){if(W.prototype.copyWithin)return W.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 dt=["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||dt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},Be=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},xt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},yt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,p=Be(e,a,c);a+=c;var m=l?1<<l:s,h=Be(e,a,m)+(l==1&&256),d=h;if(!s){var C=1<<10+(e[5]>>3);d=C+(C>>3)*(e[5]&7)}if(d>2145386496)K(1);var u=new W((t==1?h||d:t?0:d)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:p,w:t&&t!=1?t:u.subarray(12),e:d,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return xt(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,p=o,m=new ht(512+(o<<2)),h=new gt(m,0,256),d=new ge(m,0,256),C=new ge(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var g=re(i+1),f=r>>3,A=(1<<g+1)-1,z=(e[f]|e[f+1]<<8|e[f+2]<<16)>>(r&7)&A,x=(1<<g)-1,M=A-i-1,L=z&x;if(L<M)r+=g,z=L;else if(r+=g+1,z>x)z-=M;if(h[++l]=--z,z==-1)i+=z,b[--p]=l;else i-=z;if(!z)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var E=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var v=h[H];if(v<1){d[H]=-v;continue}for(c=0;c<v;++c){b[E]=H;do E=E+U&X;while(E>=p)}}if(E)K(0);for(c=0;c<o;++c){var w=d[b[c]]++,P=S[c]=s-re(w);C[c]=(w<<P)-o}return[r+7>>3,{b:s,s:b,n:S,t:C}]},wt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),p=c[0],m=c[1];t+=o;var h=p<<3,d=e[t];if(!d)K(0);var C=0,u=0,b=m.b,S=b,g=(++t<<3)-8+re(d);for(;;){if(g-=b,g<h)break;var f=g>>3;if(C+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=m.s[C],g-=S,g<h)break;f=g>>3,u+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[C],C=m.t[C],S=m.n[u],u=m.t[u]}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 z=0;for(n=0;n<r;++n){var x=i[n];if(x>11)K(0);z+=x&&1<<x-1}var M=re(z)+1,L=1<<M,D=L-z;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var x=i[n];++l[i[n]=x&&M+1-x]}var E=new W(L<<1),U=E.subarray(0,L),X=E.subarray(L);a[M]=0;for(n=M;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<M-n))}if(a[0]!=L)K(0);for(n=0;n<r;++n){var v=i[n];if(v){var w=a[v];ce(U,n,w,a[v]=w+(1<<M-v))}}return[t,{n:X,b:M,s:U}]},At=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],vt=ue(new W([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],Mt=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],$e=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Ee=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Ct=$e(Ee,0),Se=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Et=$e(Se,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,p=(r<<3)-8+re(o)-c,m=-1;for(;p>l&&m<s;){var h=p>>3,d=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(p&7);a=(a<<c|d)&i,t[++m]=n.s[a],p-=c=n.n[a]}if(p!=l||m+1!=s)K(0)},St=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},Lt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),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+=l,n;return Ce(e,s,a)}if(i==2){var c=e[s],p=c&3,m=c>>2&3,h=c>>4,d=0,C=0;if(p<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(C=m,m<2)h|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(p==0)u.set(e.subarray(s,s+=h),b);else if(p==1)ce(u,e[s++],b);else{var S=t.h;if(p==2){var g=wt(e,s);d+=s-(s=g[0]),t.h=S=g[1]}else if(!S)K(0);(C?St:le)(e.subarray(s,s+=d),u.subarray(b),S)}var f=e[s++];if(f){if(f==255)f=(e[s++]|e[s++]<<8)+32512;else if(f>127)f=f-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var z=[vt,Mt,At];for(var x=2;x>-1;--x){var M=A>>(x<<1)+2&3;if(M==1){var L=new W([0,0,e[s++]]);z[x]={s:L.subarray(2,3),n:L.subarray(0,1),t:new ge(L.buffer,0,1),b:0}}else if(M==2)r=ue(e,s,9-(x&1)),s=r[0],z[x]=r[1];else if(M==3){if(!t.t)K(0);z[x]=t.t[x]}}var D=t.t=z,E=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var v=(a<<3)-8+re(H)-X.b,w=v>>3,P=0,V=(e[w]|e[w+1]<<8)>>(v&7)&(1<<X.b)-1;w=(v-=U.b)>>3;var I=(e[w]|e[w+1]<<8)>>(v&7)&(1<<U.b)-1;w=(v-=E.b)>>3;var B=(e[w]|e[w+1]<<8)>>(v&7)&(1<<E.b)-1;for(++f;--f;){var T=X.s[V],y=X.n[V],N=E.s[B],R=E.n[B],k=U.s[I],O=U.n[I];w=(v-=k)>>3;var j=1<<k,F=j+((e[w]|e[w+1]<<8|e[w+2]<<16|e[w+3]<<24)>>>(v&7)&j-1);w=(v-=Se[N])>>3;var G=Et[N]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Se[N])-1);w=(v-=Ee[T])>>3;var _=Ct[T]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Ee[T])-1);if(w=(v-=y)>>3,V=X.t[V]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<y)-1),w=(v-=R)>>3,B=E.t[B]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<R)-1),w=(v-=O)>>3,I=U.t[I]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<O)-1),F>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=F-=3;else{var Z=F-(_!=0);if(Z){if(F=Z==3?t.o[0]-1:t.o[Z],Z>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=F}else F=t.o[0]}for(var x=0;x<_;++x)u[P+x]=u[b+x];P+=_,b+=_;var q=P-F;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var x=0;x<J;++x)u[P+x]=t.w[ee+x];P+=J,G-=J,q=0}for(var x=0;x<G;++x)u[P+x]=u[q+x];P+=G}if(P!=b)while(b<u.length)u[P++]=u[b++];else P=u.length;if(n)t.y+=P;else u=Ce(u,0,P)}else if(n){if(t.y+=h,b)for(var x=0;x<h;++x)u[x]=u[b+x]}else if(b)u=Ce(u,b);return t.b=a,u}K(2)},Tt=function(e,t){if(e.length==1)return e[0];var n=new W(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 je(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=yt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=Lt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,bt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Tt(n,o)}function de(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,"/");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ve=/^~?\\s*moved\\s+to\\s+(.+)$/i,Pt=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Ye=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),It=new Set(["model","submodel","configuration"]),Ft=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function He(e){let t=Ft.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Ye.has(n)||It.has(n)?n:void 0}function Rt(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function kt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,"");let a=Rt(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let p=a.findIndex((m,h)=>h>0&&m.toUpperCase()==="GLOSSMAP");if(p>0&&a[p+1])c.glossmap=a[p+1];if(t)c.next=!0;return c}var Dt=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Ut(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let p=s();if(p===null)return null;i[c]=+p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Le(o),m:i,file:Y(a)}}function Ge(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Y(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function Je(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,a=null,c=[],p=null,m=()=>{if(!a)return;let g=Dt(a.chunks.join("")),f=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Y(a.name),{name:a.name,bytes:g,...f?{mime:"image/png"}:{}}),a=null},h=!0,d=(g)=>{if(m(),o={name:Y(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],p=null,h=!0},C=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=""},S=(g,f)=>{if(p){g.tex=p,p=null;return}let A=c[c.length-1];if(!A)return;if(A.fallback){if(!f)g.fallback=!0}else g.tex=A.map};for(let g of e.split(`\n`)){let f=g.trim();if(!f)continue;if(r&&f.charCodeAt(0)>=50&&f.charCodeAt(0)<=53&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){if(a||C)continue;if(!o)d(t);let M=f.slice(2).trimStart(),L=M.search(/\\s/),D={t:f.charCodeAt(0)-48,color:Le(L<0?M:M.slice(0,L)),p:[],src:f};S(D,!1),o.cmds.push(D),h=!1;continue}if(f.charCodeAt(0)===48&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){let M=2;while(f.charCodeAt(M)===32||f.charCodeAt(M)===9)M++;let L=M;while(L<f.length&&f.charCodeAt(L)!==32&&f.charCodeAt(L)!==9)L++;let D=f.slice(M,L);if(!Pt.has(D)){if(C||a)continue;if(!o)d(t);let E=f.slice(M),U={t:0,text:E};if(D.charCodeAt(0)===33)U.meta=D;if(p=null,h&&!o.org){let H=He(E);if(H)o.org=H}let X=E.match(Ve);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=".dat";o.movedTo=Y(H)}o.cmds.push(U);continue}}if(f.charCodeAt(0)===49&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)&&!a&&!C){let M=Ut(f);if(M){if(!o)d(t);S(M,!1),o.cmds.push(M),h=!1;continue}}let A=f.split(/\\s+/);if(+A[0]===0){let M=f.slice(1).trim();if(A[1]==="FILE"){b(),C=!1,d(M.slice(5));continue}if(A[1]==="NOFILE"){m(),o=null,C=!0;continue}if(A[1]==="!DATA"){b(),m(),o=null,C=!1,a={name:M.slice(5).trim(),chunks:[]};continue}if(C)continue;if(a){if(A[1]==="!:")a.chunks.push(A.slice(2).join(""));continue}if(!o)d(t);let L={t:0,text:M};if(A[1]==="STEP")L.step=!0,c=[],p=null;else if(A[1]==="BFC")L.bfc=A.slice(2).join(" ");else if(A[1]==="ROTSTEP")if(L.meta="ROTSTEP",L.step=!0,c=[],p=null,(A[2]??"").toUpperCase()==="END")L.rotstep={x:0,y:0,z:0,mode:"END"};else{let E=(A[5]??"REL").toUpperCase();L.rotstep={x:+A[2]||0,y:+A[3]||0,z:+A[4]||0,mode:["REL","ABS","ADD"].includes(E)?E:"REL"}}else if(A[1]==="BUFEXCHG"){L.meta="BUFEXCHG";let E=(A[2]??"").toUpperCase();L.bufexchg={op:E==="RETRIEVE"?"RETRIEVE":"STORE",buf:A[3]??"A"}}else if(A[1]?.startsWith("!"))L.meta=A[1];if(h&&!o.org){let E=He(M);if(E)o.org=E}if(A[1]==="!TEXMAP"){let E=(A[2]??"").toUpperCase();if(p=null,E==="START"||E==="NEXT"){let U=kt(M.replace(/^!TEXMAP\\s+\\S+/i,""),E==="NEXT");if(L.texmap={op:E,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),E==="START")c.push({map:U,fallback:!1});else p=U}else if(E==="FALLBACK"){L.texmap={op:E};let U=c[c.length-1];if(U)U.fallback=!0}else if(E==="END")L.texmap={op:E},c.pop()}else if(A[1]==="!:"){p=null;let E=Ge(A.slice(2));if(E)S(E,!0),L.geom=E}else p=null;let D=M.match(Ve);if(D&&!o.movedTo){let E=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(E))E+=".dat";o.movedTo=Y(E)}o.cmds.push(L);continue}if(a||C)continue;if(!o)d(t);let x=Ge(A);if(!x)continue;S(x,!1),o.cmds.push(x),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var tn=Math.PI/180;function qe(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 Qe(e,t){let[n,r,s,o,i,l,a,c,p,m,h,d]=e,[C,u,b,S,g,f,A,z,x,M,L,D]=t;return[o*C+i*u+l*b+n,a*C+c*u+p*b+r,m*C+h*u+d*b+s,o*S+i*A+l*M,o*g+i*z+l*L,o*f+i*x+l*D,a*S+c*A+p*M,a*g+c*z+p*L,a*f+c*x+p*D,m*S+h*A+d*M,m*g+h*z+d*L,m*f+h*x+d*D]}var Te=[0,0,0,1,0,0,0,1,0,0,0,1];var _e=new WeakMap,zt=/^(s|8|48)\\//;function Pe(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=_e.get(n);if(r)return r;if(n.org)r=Ye.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&&zt.test(s.file))?"part":"model";return _e.set(n,r),r}var We=new WeakMap;function et(e){let t=We.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 We.set(e,t),t}var Ke=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():String(e),Ot=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Ke(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Ke(e.color)} ${e.p.join(" ")}`,Ie=(e,t)=>`${Y(e)}#${t}`;function Nt(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){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:Ie(e.name,t),cmds:n}}function tt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Nt(e,t).cmds.map(Ot)].join(`\n`)+`\n`}function Bt(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,l,a,c,p,m,h]=e,d=a*h-c*m,C=-(l*h-c*p),u=l*m-a*p,b=s*d+o*C+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,g=[d*S,-(o*h-i*m)*S,(o*c-i*a)*S,C*S,(s*h-i*p)*S,-(s*c-i*l)*S,u*S,-(s*m-o*p)*S,(s*a-o*l)*S];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 $t=(e)=>String(+e.toFixed(6)||0),Xe=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function rt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map($t).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Xe(t.texture)}${t.glossmap?" GLOSSMAP "+Xe(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-${Bt(r)}`,source:r}}var jt=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Vt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var Ze=new WeakMap;function st(e){let t=Ze.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=Vt(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:jt(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Ze.set(e,n),n}var ot=999999,it=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function Ht(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let d=m.name+"#"+h,C=l.get(d);if(!C){let u;C=Object.assign(()=>u??=tt(m,h),{file:m,step:h}),l.set(d,C)}return C},p=(m,h,d,C,u,b,S,g,f=null,A=[],z=[])=>{let x=m.files.get(h);if(!x||S>r)return;let M=0,L=S>0?++a:0,D=i&&L?[...A,L]:A,E=i&&L?[...z,d]:z,U=i&&!f?new Map:null,X=-1,H=0,v=(T,y,N,R,k,O)=>{if(X!==M)X=M,H=0;let j=U?.get(M+"|"+y);if(j)return j.n++,p(T,T===m?y:T.main,N,R,u+"/"+y,[...k,ot],S+1,O,[...k,ot],D,E);let F=[...k,H++],G=n.length;p(T,T===m?y:T.main,N,R,u+"/"+y,F,S+1,O,f,D,E),U?.set(M+"|"+y,{n:1,from:G,to:n.length})},w=st(x),P=s?et(x):[],V=0,I=(T,y,N,R,k,O,j)=>{if(f)R=f;let F={part:T,color:y,m:N,step:R[0],steps:R,localStep:k,path:u};if(L){if(F.sub=L,i)F.subPath=D,F.subMats=E}if(O)F.embedded=!0;if(j){let _=rt(T,j);F.texPart=_.name,F.texSource=_.source}let G=w[k];if(G)F.view=G;return n.push(F),F},B=(T)=>{while(V<P.length&&P[V]<=T){let y=P[V++];I(Ie(x.name,y),C,d,[...b,y],y,!1,null).source=c(x,y)}};for(let T of x.cmds){if(T.t===0&&T.step){M++;continue}let y=T;if(y.t>=2||y.t===0&&y.geom&&y.geom.t>=2){B(M);continue}if(y.t===0)if(o&&y.geom?.t===1)y=y.geom;else continue;if(y.t!==1)continue;if(o&&y.fallback)continue;let N=y.color===16?C:y.color,R=Qe(d,y.m),k=[...b,M],O=o?y.tex??g:null,j=O?nt(y.m):null,F=O&&j?qe(O,j):null;if(m.files.has(y.file)){if(Pe(m,y.file)==="model"){v(m,y.file,R,N,k,F);continue}I(y.file,N,R,k,M,!0,F);continue}let G=t.resolveModel?.(y.file);if(G){v(G,y.file,R,N,k,F);continue}I(y.file,N,R,k,M,!1,F)}if(B(1/0),U){for(let T of U.values())if(T.n>1)for(let y=T.from;y<T.to;y++)n[y].mult??=T.n}};if(Pe(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Te],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return p(e,e.main,Te,16,e.main,[],0,null),n}function at(e,t="main.ldr",n){return Ht(Je(e,t,{geometryText:!0}),n)}function Gt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Y(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Y(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var _t=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function Wt(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 lt(e,t,n="main.ldr"){let r=Gt(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let p of r.get(a.pop())){let m=_t(p);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((p)=>p!==i).sort()].map((p)=>"0 FILE "+(p===i?"":p)+`\n`+r.get(p).join(`\n`)).join(`\n`);s.set(i,`emb/${Wt(c)}.dat`)}return s}var ct=(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,ut=new WeakMap;function Fe(e,t){let n=ut.get(e);if(!n)ut.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,d)=>{l.push(h[0]),a.push(h[1]);for(let C=0;C<12;C++)i[d*12+C]=h[2+C]});let c=null,p=0,m=0;if(s.mask){p=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let d=0;d<h.length;d++)c[d]=h.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:p,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Kt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],p=[],m=[],h=new Re(e.length*2),d=[],C=[];for(let v=0;v<e.length;v++){let w=e[v],P=w.m,V=t.parts[w.part];if(!V||!V.mask||!ct(P))continue;let I=V.bbox,B=1/0,T=-1/0,y=1/0,N=-1/0;for(let O=0;O<2;O++)for(let j=0;j<2;j++){let F=O?I[3]:I[0],G=j?I[5]:I[2],_=P[0]+P[3]*F+P[5]*G,Z=P[2]+P[9]*F+P[11]*G;if(_<B)B=_;if(_>T)T=_;if(Z<y)y=Z;if(Z>N)N=Z}let R=a.length;s.push(B),o.push(T),i.push(y),l.push(N),a.push(v),c.push(Fe(t,w.part)),p.push(I[0]),m.push(I[2]);let k=Math.round((P[1]+I[4])*2);for(let O=Math.floor(B/40);O<=Math.floor(T/40);O++)for(let j=Math.floor(y/40);j<=Math.floor(N/40);j++){if(!xe(k,O,j))continue;let F=C.length;C.push(R),d.push(h.put(k,O,j,F))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,g=NaN,f=NaN,A=-1,z=(v,w,P,V)=>{let I=Math.round(w*2),B=Math.floor(v/40),T=Math.floor(P/40);if(!xe(I,B,T))return fe;let y=fe;if(I!==S||B!==g||T!==f)S=I,g=B,f=T,A=h.get(I,B,T);for(let N=A;N>=0;N=d[N]){let R=C[N];if(a[R]===V||!(v-6>=s[R]-0.5&&v+6<=o[R]+0.5&&P-6>=i[R]-0.5&&P+6<=l[R]+0.5))continue;let k=e[a[R]].m,O=c[R],j=p[R],F=m[R],G=v-k[0],_=w-k[1],Z=P-k[2],q=k[3]*G+k[6]*_+k[9]*Z,J=k[5]*G+k[8]*_+k[11]*Z,{nx:ee,nz:se,mask:ae}=O,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-F)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[R]];if(Q<y)y=Q}}return y},x=0;for(let v of e){let w=Fe(t,v.part);if(w)x+=w.nStuds}let M=new Uint8Array(x),L=new Uint8Array(x),D=new Re(x),E=0,U=n?new Int32Array(x).fill(fe):void 0;for(let v=0,w=0;v<e.length;v++){let P=e[v],V=Fe(t,P.part);if(!V)continue;let I=P.m,B=V.studM,T=I[0],y=I[1],N=I[2],R=I[3],k=I[4],O=I[5],j=I[6],F=I[7],G=I[8],_=I[9],Z=I[10],q=I[11];for(let J=0;J<V.nStuds;J++,w++){let ee=J*12,se=B[ee+4],ae=B[ee+7],oe=B[ee+10];if(!(Math.abs(j*se+F*ae+G*oe-1)<0.001&&Math.abs(R*se+k*ae+O*oe)<0.001&&Math.abs(_*se+Z*ae+q*oe)<0.001))continue;L[w]=1;let Q=B[ee],te=B[ee+1],ne=B[ee+2],ke=T+R*Q+k*te+O*ne,De=y+j*Q+F*te+G*ne,Ue=N+_*Q+Z*te+q*ne,ze=z(ke,De,Ue,v);if(ze!==fe){if(M[w]=1,E++,U)U[w]=ze}let pe=Math.round(ke),me=Math.round(De),he=Math.round(Ue);if(!xe(pe,me,he))continue;if(!n){D.put(pe,me,he,1);continue}let Oe=n[v],Ne=D.get(pe,me,he);if(Ne<0||Oe<Ne)D.put(pe,me,he,Oe)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let w=e[v],P=t.parts[w.part];if(!P||!P.under||!ct(w.m))continue;let V=P.bbox,I=Math.round((V[3]-V[0])/20),B=Math.round((V[5]-V[2])/20);if(!I||!B||I*B>4096)continue;let T=w.m,y=!0,N=0;for(let R=0;R<I&&y;R++)for(let k=0;k<B;k++){let O=V[0]+10+20*R,j=V[2]+10+20*k,F=T[0]+T[3]*O+T[5]*j,G=T[2]+T[9]*O+T[11]*j,_=Math.round(F),Z=Math.round(T[1]+V[4]),q=Math.round(G),J=xe(_,Z,q)?D.get(_,Z,q):-1;if(J<0){y=!1;break}if(J>N)N=J}if(y){if(X[v]=1,H)H[v]=N}}return{nStuds:x,studHidden:M,studUp:L,underHidden:X,studsHidden:E,studHideStep:U,underHideStep:H}}function Xt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>it(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function ye(e,t,n=!0){let r=Xt(e,t,n);return Kt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Me="https://ldr-demo.vercel.app/cdn/v1/",Ae=new Map,we=new Map;function pt(e=Me,t=fetch){let n=Ae.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>Ae.delete(e)),Ae.set(e,n);return n}var Zt=(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"),ve=(e,t)=>Zt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>ve(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,ve(r,t)])):e;function Yt(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let d=h.buffer;if(!d)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let C=new DataView(d).getUint32(0,!0),u=new Uint8Array(d,4+C),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[g,f]of Object.entries(h.header.parts??{}))if(!(g in s))s[g]=ve(f,b);for(let[g,f]of Object.entries(h.header.studKinds??{}))if(!(g in o))o[g]=ve(f,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,p=new Uint8Array(c+r);new DataView(p.buffer).setUint32(0,l.length+a,!0),p.set(l,4),p.fill(32,4+l.length,c);let m=c;for(let h of n)p.set(h,m),m+=h.byteLength;return de(p.buffer)}async function Jt(e,t={}){e=[...e];try{return await ft(e,t)}catch(n){let r=t.cdn??Me,s=t.fetch??fetch;Ae.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await ft(e,{...t,fetch:o})}catch{throw n}}}async function ft(e,t){let n=t.cdn??Me,r=t.fetch??fetch,s=t.gap??16384,o=await pt(n,r),i=[...new Set([...e].map(Y))],l=[],a=[];for(let u of i){if(we.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let p=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);p+=S.byteLength;for(let g of u.items){let f=je(S.subarray(g.off-u.start,g.off-u.start+g.len)),A=f.buffer.slice(f.byteOffset,f.byteOffset+f.byteLength);we.set(n+g.name,de(A))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let d=i.filter((u)=>we.has(n+u)).map((u)=>we.get(n+u));return{pack:d.length?Yt(d,{colors:o.colors}):de(qt(o.colors)),missing:l,requests:c.length,bytes:p}}function qt(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}async function mt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=pt(t.cdn??Me,r);s.catch(()=>{});let o=t.text?e:await r(e).then((f)=>{if(!f.ok)throw Error(`ldr: ${f.status} fetching ${e}`);return f.text()}),i=performance.now(),l=t.name??(t.text?"main.ldr":decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr")),a=at(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let p=lt(o,new Set(a.filter((f)=>f.embedded).map((f)=>f.part)),l),{pack:m,missing:h,requests:d,bytes:C}=await Jt([...a.filter((f)=>!f.embedded).map((f)=>f.part),...p.values()],t),u=new Map([...p].map(([f,A])=>[A,f])),b=h.map((f)=>u.get(f)??f);for(let[f,A]of p){let z=m.header.parts[A];if(z)m.header.parts[f]=z}let S=performance.now(),g=t.cull?ye(a,m.header,t.textures!==!1):void 0;return{insts:a,pack:m,missing:b,requests:d,bytes:C,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:S-c,...g?{cull:performance.now()-S}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await mt(n,{...r,cull:!1,onParsed:(p)=>self.postMessage({id:t,insts:p})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=ye(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let p of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(p)c.push(p.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
3827
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/load-worker.gen.ts
3828
+ var load_worker_gen_default = 'var bt=ArrayBuffer,W=Uint8Array,ge=Uint16Array,dt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.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 W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.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},yt=function(e,t,n,r){if(W.prototype.copyWithin)return W.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 xt=["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||xt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},$e=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},wt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},At=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,p=$e(e,a,c);a+=c;var m=l?1<<l:s,h=$e(e,a,m)+(l==1&&256),d=h;if(!s){var C=1<<10+(e[5]>>3);d=C+(C>>3)*(e[5]&7)}if(d>2145386496)K(1);var u=new W((t==1?h||d:t?0:d)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:p,w:t&&t!=1?t:u.subarray(12),e:d,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return wt(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,p=o,m=new bt(512+(o<<2)),h=new dt(m,0,256),d=new ge(m,0,256),C=new ge(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var g=re(i+1),f=r>>3,A=(1<<g+1)-1,z=(e[f]|e[f+1]<<8|e[f+2]<<16)>>(r&7)&A,y=(1<<g)-1,M=A-i-1,L=z&y;if(L<M)r+=g,z=L;else if(r+=g+1,z>y)z-=M;if(h[++l]=--z,z==-1)i+=z,b[--p]=l;else i-=z;if(!z)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var E=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var v=h[H];if(v<1){d[H]=-v;continue}for(c=0;c<v;++c){b[E]=H;do E=E+U&X;while(E>=p)}}if(E)K(0);for(c=0;c<o;++c){var w=d[b[c]]++,P=S[c]=s-re(w);C[c]=(w<<P)-o}return[r+7>>3,{b:s,s:b,n:S,t:C}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new ge(s.buffer,268);if(o<128){var c=ue(e,t+1,6),p=c[0],m=c[1];t+=o;var h=p<<3,d=e[t];if(!d)K(0);var C=0,u=0,b=m.b,S=b,g=(++t<<3)-8+re(d);for(;;){if(g-=b,g<h)break;var f=g>>3;if(C+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=m.s[C],g-=S,g<h)break;f=g>>3,u+=(e[f]|e[f+1]<<8)>>(g&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[C],C=m.t[C],S=m.n[u],u=m.t[u]}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 z=0;for(n=0;n<r;++n){var y=i[n];if(y>11)K(0);z+=y&&1<<y-1}var M=re(z)+1,L=1<<M,D=L-z;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var y=i[n];++l[i[n]=y&&M+1-y]}var E=new W(L<<1),U=E.subarray(0,L),X=E.subarray(L);a[M]=0;for(n=M;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<M-n))}if(a[0]!=L)K(0);for(n=0;n<r;++n){var v=i[n];if(v){var w=a[v];ce(U,n,w,a[v]=w+(1<<M-v))}}return[t,{n:X,b:M,s:U}]},Mt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([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],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],je=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=je(Se,0),Le=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Lt=je(Le,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,p=(r<<3)-8+re(o)-c,m=-1;for(;p>l&&m<s;){var h=p>>3,d=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(p&7);a=(a<<c|d)&i,t[++m]=n.s[a],p-=c=n.n[a]}if(p!=l||m+1!=s)K(0)},Tt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},Pt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),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+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],p=c&3,m=c>>2&3,h=c>>4,d=0,C=0;if(p<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(C=m,m<2)h|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(p==0)u.set(e.subarray(s,s+=h),b);else if(p==1)ce(u,e[s++],b);else{var S=t.h;if(p==2){var g=vt(e,s);d+=s-(s=g[0]),t.h=S=g[1]}else if(!S)K(0);(C?Tt:le)(e.subarray(s,s+=d),u.subarray(b),S)}var f=e[s++];if(f){if(f==255)f=(e[s++]|e[s++]<<8)+32512;else if(f>127)f=f-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var z=[Ct,Et,Mt];for(var y=2;y>-1;--y){var M=A>>(y<<1)+2&3;if(M==1){var L=new W([0,0,e[s++]]);z[y]={s:L.subarray(2,3),n:L.subarray(0,1),t:new ge(L.buffer,0,1),b:0}}else if(M==2)r=ue(e,s,9-(y&1)),s=r[0],z[y]=r[1];else if(M==3){if(!t.t)K(0);z[y]=t.t[y]}}var D=t.t=z,E=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var v=(a<<3)-8+re(H)-X.b,w=v>>3,P=0,V=(e[w]|e[w+1]<<8)>>(v&7)&(1<<X.b)-1;w=(v-=U.b)>>3;var I=(e[w]|e[w+1]<<8)>>(v&7)&(1<<U.b)-1;w=(v-=E.b)>>3;var B=(e[w]|e[w+1]<<8)>>(v&7)&(1<<E.b)-1;for(++f;--f;){var T=X.s[V],x=X.n[V],N=E.s[B],R=E.n[B],k=U.s[I],O=U.n[I];w=(v-=k)>>3;var j=1<<k,F=j+((e[w]|e[w+1]<<8|e[w+2]<<16|e[w+3]<<24)>>>(v&7)&j-1);w=(v-=Le[N])>>3;var G=Lt[N]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Le[N])-1);w=(v-=Se[T])>>3;var _=St[T]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Se[T])-1);if(w=(v-=x)>>3,V=X.t[V]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<x)-1),w=(v-=R)>>3,B=E.t[B]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<R)-1),w=(v-=O)>>3,I=U.t[I]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<O)-1),F>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=F-=3;else{var Z=F-(_!=0);if(Z){if(F=Z==3?t.o[0]-1:t.o[Z],Z>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=F}else F=t.o[0]}for(var y=0;y<_;++y)u[P+y]=u[b+y];P+=_,b+=_;var q=P-F;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var y=0;y<J;++y)u[P+y]=t.w[ee+y];P+=J,G-=J,q=0}for(var y=0;y<G;++y)u[P+y]=u[q+y];P+=G}if(P!=b)while(b<u.length)u[P++]=u[b++];else P=u.length;if(n)t.y+=P;else u=Ee(u,0,P)}else if(n){if(t.y+=h,b)for(var y=0;y<h;++y)u[y]=u[b+y]}else if(b)u=Ee(u,b);return t.b=a,u}K(2)},It=function(e,t){if(e.length==1)return e[0];var n=new W(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 de(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=At(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=Pt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,yt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return It(n,o)}async function Ft(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(de(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 Ve(e){return new TextDecoder().decode(await Ft(e))}var He=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function ye(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/");function Te(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ge=/^~?\\s*moved\\s+to\\s+(.+)$/i,Rt=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),qe=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),kt=new Set(["model","submodel","configuration"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function _e(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return qe.has(n)||kt.has(n)?n:void 0}function Ut(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 zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,"");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let p=a.findIndex((m,h)=>h>0&&m.toUpperCase()==="GLOSSMAP");if(p>0&&a[p+1])c.glossmap=a[p+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let p=s();if(p===null)return null;i[c]=+p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Te(o),m:i,file:Y(a)}}function We(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Te(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Y(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function Qe(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,a=null,c=[],p=null,m=()=>{if(!a)return;let g=Ot(a.chunks.join("")),f=g[0]===137&&g[1]===80&&g[2]===78&&g[3]===71;(l??=new Map).set(Y(a.name),{name:a.name,bytes:g,...f?{mime:"image/png"}:{}}),a=null},h=!0,d=(g)=>{if(m(),o={name:Y(g),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],p=null,h=!0},C=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=""},S=(g,f)=>{if(p){g.tex=p,p=null;return}let A=c[c.length-1];if(!A)return;if(A.fallback){if(!f)g.fallback=!0}else g.tex=A.map};for(let g of e.split(`\n`)){let f=g.trim();if(!f)continue;if(r&&f.charCodeAt(0)>=50&&f.charCodeAt(0)<=53&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){if(a||C)continue;if(!o)d(t);let M=f.slice(2).trimStart(),L=M.search(/\\s/),D={t:f.charCodeAt(0)-48,color:Te(L<0?M:M.slice(0,L)),p:[],src:f};S(D,!1),o.cmds.push(D),h=!1;continue}if(f.charCodeAt(0)===48&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)){let M=2;while(f.charCodeAt(M)===32||f.charCodeAt(M)===9)M++;let L=M;while(L<f.length&&f.charCodeAt(L)!==32&&f.charCodeAt(L)!==9)L++;let D=f.slice(M,L);if(!Rt.has(D)){if(C||a)continue;if(!o)d(t);let E=f.slice(M),U={t:0,text:E};if(D.charCodeAt(0)===33)U.meta=D;if(p=null,h&&!o.org){let H=_e(E);if(H)o.org=H}let X=E.match(Ge);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=".dat";o.movedTo=Y(H)}o.cmds.push(U);continue}}if(f.charCodeAt(0)===49&&(f.charCodeAt(1)===32||f.charCodeAt(1)===9)&&!a&&!C){let M=Nt(f);if(M){if(!o)d(t);S(M,!1),o.cmds.push(M),h=!1;continue}}let A=f.split(/\\s+/);if(+A[0]===0){let M=f.slice(1).trim();if(A[1]==="FILE"){b(),C=!1,d(M.slice(5));continue}if(A[1]==="NOFILE"){m(),o=null,C=!0;continue}if(A[1]==="!DATA"){b(),m(),o=null,C=!1,a={name:M.slice(5).trim(),chunks:[]};continue}if(C)continue;if(a){if(A[1]==="!:")a.chunks.push(A.slice(2).join(""));continue}if(!o)d(t);let L={t:0,text:M};if(A[1]==="STEP")L.step=!0,c=[],p=null;else if(A[1]==="BFC")L.bfc=A.slice(2).join(" ");else if(A[1]==="ROTSTEP")if(L.meta="ROTSTEP",L.step=!0,c=[],p=null,(A[2]??"").toUpperCase()==="END")L.rotstep={x:0,y:0,z:0,mode:"END"};else{let E=(A[5]??"REL").toUpperCase();L.rotstep={x:+A[2]||0,y:+A[3]||0,z:+A[4]||0,mode:["REL","ABS","ADD"].includes(E)?E:"REL"}}else if(A[1]==="BUFEXCHG"){L.meta="BUFEXCHG";let E=(A[2]??"").toUpperCase();L.bufexchg={op:E==="RETRIEVE"?"RETRIEVE":"STORE",buf:A[3]??"A"}}else if(A[1]?.startsWith("!"))L.meta=A[1];if(h&&!o.org){let E=_e(M);if(E)o.org=E}if(A[1]==="!TEXMAP"){let E=(A[2]??"").toUpperCase();if(p=null,E==="START"||E==="NEXT"){let U=zt(M.replace(/^!TEXMAP\\s+\\S+/i,""),E==="NEXT");if(L.texmap={op:E,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),E==="START")c.push({map:U,fallback:!1});else p=U}else if(E==="FALLBACK"){L.texmap={op:E};let U=c[c.length-1];if(U)U.fallback=!0}else if(E==="END")L.texmap={op:E},c.pop()}else if(A[1]==="!:"){p=null;let E=We(A.slice(2));if(E)S(E,!0),L.geom=E}else p=null;let D=M.match(Ge);if(D&&!o.movedTo){let E=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(E))E+=".dat";o.movedTo=Y(E)}o.cmds.push(L);continue}if(a||C)continue;if(!o)d(t);let y=We(A);if(!y)continue;S(y,!1),o.cmds.push(y),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var on=Math.PI/180;function et(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 tt(e,t){let[n,r,s,o,i,l,a,c,p,m,h,d]=e,[C,u,b,S,g,f,A,z,y,M,L,D]=t;return[o*C+i*u+l*b+n,a*C+c*u+p*b+r,m*C+h*u+d*b+s,o*S+i*A+l*M,o*g+i*z+l*L,o*f+i*y+l*D,a*S+c*A+p*M,a*g+c*z+p*L,a*f+c*y+p*D,m*S+h*A+d*M,m*g+h*z+d*L,m*f+h*y+d*D]}var Pe=[0,0,0,1,0,0,0,1,0,0,0,1];var Ke=new WeakMap,Bt=/^(s|8|48)\\//;function Ie(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=Ke.get(n);if(r)return r;if(n.org)r=qe.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&&Bt.test(s.file))?"part":"model";return Ke.set(n,r),r}var Xe=new WeakMap;function nt(e){let t=Xe.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 Xe.set(e,t),t}var Ze=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():String(e),$t=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Ze(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Ze(e.color)} ${e.p.join(" ")}`,Fe=(e,t)=>`${Y(e)}#${t}`;function jt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){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:Fe(e.name,t),cmds:n}}function rt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...jt(e,t).cmds.map($t)].join(`\n`)+`\n`}function Vt(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 st(e){let[t,n,r,s,o,i,l,a,c,p,m,h]=e,d=a*h-c*m,C=-(l*h-c*p),u=l*m-a*p,b=s*d+o*C+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,g=[d*S,-(o*h-i*m)*S,(o*c-i*a)*S,C*S,(s*h-i*p)*S,-(s*c-i*l)*S,u*S,-(s*m-o*p)*S,(s*a-o*l)*S];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 Ht=(e)=>String(+e.toFixed(6)||0),Ye=(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(Ht).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Ye(t.texture)}${t.glossmap?" GLOSSMAP "+Ye(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-${Vt(r)}`,source:r}}var Gt=(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 _t(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var Je=new WeakMap;function it(e){let t=Je.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=_t(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Gt(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Je.set(e,n),n}var at=999999,lt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function Wt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let d=m.name+"#"+h,C=l.get(d);if(!C){let u;C=Object.assign(()=>u??=rt(m,h),{file:m,step:h}),l.set(d,C)}return C},p=(m,h,d,C,u,b,S,g,f=null,A=[],z=[])=>{let y=m.files.get(h);if(!y||S>r)return;let M=0,L=S>0?++a:0,D=i&&L?[...A,L]:A,E=i&&L?[...z,d]:z,U=i&&!f?new Map:null,X=-1,H=0,v=(T,x,N,R,k,O)=>{if(X!==M)X=M,H=0;let j=U?.get(M+"|"+x);if(j)return j.n++,p(T,T===m?x:T.main,N,R,u+"/"+x,[...k,at],S+1,O,[...k,at],D,E);let F=[...k,H++],G=n.length;p(T,T===m?x:T.main,N,R,u+"/"+x,F,S+1,O,f,D,E),U?.set(M+"|"+x,{n:1,from:G,to:n.length})},w=it(y),P=s?nt(y):[],V=0,I=(T,x,N,R,k,O,j)=>{if(f)R=f;let F={part:T,color:x,m:N,step:R[0],steps:R,localStep:k,path:u};if(L){if(F.sub=L,i)F.subPath=D,F.subMats=E}if(O)F.embedded=!0;if(j){let _=ot(T,j);F.texPart=_.name,F.texSource=_.source}let G=w[k];if(G)F.view=G;return n.push(F),F},B=(T)=>{while(V<P.length&&P[V]<=T){let x=P[V++];I(Fe(y.name,x),C,d,[...b,x],x,!1,null).source=c(y,x)}};for(let T of y.cmds){if(T.t===0&&T.step){M++;continue}let x=T;if(x.t>=2||x.t===0&&x.geom&&x.geom.t>=2){B(M);continue}if(x.t===0)if(o&&x.geom?.t===1)x=x.geom;else continue;if(x.t!==1)continue;if(o&&x.fallback)continue;let N=x.color===16?C:x.color,R=tt(d,x.m),k=[...b,M],O=o?x.tex??g:null,j=O?st(x.m):null,F=O&&j?et(O,j):null;if(m.files.has(x.file)){if(Ie(m,x.file)==="model"){v(m,x.file,R,N,k,F);continue}I(x.file,N,R,k,M,!0,F);continue}let G=t.resolveModel?.(x.file);if(G){v(G,x.file,R,N,k,F);continue}I(x.file,N,R,k,M,!1,F)}if(B(1/0),U){for(let T of U.values())if(T.n>1)for(let x=T.from;x<T.to;x++)n[x].mult??=T.n}};if(Ie(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Pe],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return p(e,e.main,Pe,16,e.main,[],0,null),n}function ct(e,t="main.ldr",n){return Wt(Qe(e,t,{geometryText:!0}),n)}function Kt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Y(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Y(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var Xt=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function Zt(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 ut(e,t,n="main.ldr"){let r=Kt(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let p of r.get(a.pop())){let m=Xt(p);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((p)=>p!==i).sort()].map((p)=>"0 FILE "+(p===i?"":p)+`\n`+r.get(p).join(`\n`)).join(`\n`);s.set(i,`emb/${Zt(c)}.dat`)}return s}var ft=(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,pt=new WeakMap;function Re(e,t){let n=pt.get(e);if(!n)pt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,d)=>{l.push(h[0]),a.push(h[1]);for(let C=0;C<12;C++)i[d*12+C]=h[2+C]});let c=null,p=0,m=0;if(s.mask){p=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let d=0;d<h.length;d++)c[d]=h.charCodeAt(d)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:p,nz:m}),r}var ie=1073741824;class ke{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var xe=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Yt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],p=[],m=[],h=new ke(e.length*2),d=[],C=[];for(let v=0;v<e.length;v++){let w=e[v],P=w.m,V=t.parts[w.part];if(!V||!V.mask||!ft(P))continue;let I=V.bbox,B=1/0,T=-1/0,x=1/0,N=-1/0;for(let O=0;O<2;O++)for(let j=0;j<2;j++){let F=O?I[3]:I[0],G=j?I[5]:I[2],_=P[0]+P[3]*F+P[5]*G,Z=P[2]+P[9]*F+P[11]*G;if(_<B)B=_;if(_>T)T=_;if(Z<x)x=Z;if(Z>N)N=Z}let R=a.length;s.push(B),o.push(T),i.push(x),l.push(N),a.push(v),c.push(Re(t,w.part)),p.push(I[0]),m.push(I[2]);let k=Math.round((P[1]+I[4])*2);for(let O=Math.floor(B/40);O<=Math.floor(T/40);O++)for(let j=Math.floor(x/40);j<=Math.floor(N/40);j++){if(!xe(k,O,j))continue;let F=C.length;C.push(R),d.push(h.put(k,O,j,F))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,g=NaN,f=NaN,A=-1,z=(v,w,P,V)=>{let I=Math.round(w*2),B=Math.floor(v/40),T=Math.floor(P/40);if(!xe(I,B,T))return fe;let x=fe;if(I!==S||B!==g||T!==f)S=I,g=B,f=T,A=h.get(I,B,T);for(let N=A;N>=0;N=d[N]){let R=C[N];if(a[R]===V||!(v-6>=s[R]-0.5&&v+6<=o[R]+0.5&&P-6>=i[R]-0.5&&P+6<=l[R]+0.5))continue;let k=e[a[R]].m,O=c[R],j=p[R],F=m[R],G=v-k[0],_=w-k[1],Z=P-k[2],q=k[3]*G+k[6]*_+k[9]*Z,J=k[5]*G+k[8]*_+k[11]*Z,{nx:ee,nz:se,mask:ae}=O,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-F)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[R]];if(Q<x)x=Q}}return x},y=0;for(let v of e){let w=Re(t,v.part);if(w)y+=w.nStuds}let M=new Uint8Array(y),L=new Uint8Array(y),D=new ke(y),E=0,U=n?new Int32Array(y).fill(fe):void 0;for(let v=0,w=0;v<e.length;v++){let P=e[v],V=Re(t,P.part);if(!V)continue;let I=P.m,B=V.studM,T=I[0],x=I[1],N=I[2],R=I[3],k=I[4],O=I[5],j=I[6],F=I[7],G=I[8],_=I[9],Z=I[10],q=I[11];for(let J=0;J<V.nStuds;J++,w++){let ee=J*12,se=B[ee+4],ae=B[ee+7],oe=B[ee+10];if(!(Math.abs(j*se+F*ae+G*oe-1)<0.001&&Math.abs(R*se+k*ae+O*oe)<0.001&&Math.abs(_*se+Z*ae+q*oe)<0.001))continue;L[w]=1;let Q=B[ee],te=B[ee+1],ne=B[ee+2],De=T+R*Q+k*te+O*ne,Ue=x+j*Q+F*te+G*ne,ze=N+_*Q+Z*te+q*ne,Oe=z(De,Ue,ze,v);if(Oe!==fe){if(M[w]=1,E++,U)U[w]=Oe}let pe=Math.round(De),me=Math.round(Ue),he=Math.round(ze);if(!xe(pe,me,he))continue;if(!n){D.put(pe,me,he,1);continue}let Ne=n[v],Be=D.get(pe,me,he);if(Be<0||Ne<Be)D.put(pe,me,he,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let w=e[v],P=t.parts[w.part];if(!P||!P.under||!ft(w.m))continue;let V=P.bbox,I=Math.round((V[3]-V[0])/20),B=Math.round((V[5]-V[2])/20);if(!I||!B||I*B>4096)continue;let T=w.m,x=!0,N=0;for(let R=0;R<I&&x;R++)for(let k=0;k<B;k++){let O=V[0]+10+20*R,j=V[2]+10+20*k,F=T[0]+T[3]*O+T[5]*j,G=T[2]+T[9]*O+T[11]*j,_=Math.round(F),Z=Math.round(T[1]+V[4]),q=Math.round(G),J=xe(_,Z,q)?D.get(_,Z,q):-1;if(J<0){x=!1;break}if(J>N)N=J}if(x){if(X[v]=1,H)H[v]=N}}return{nStuds:y,studHidden:M,studUp:L,underHidden:X,studsHidden:E,studHideStep:U,underHideStep:H}}function Jt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>lt(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function we(e,t,n=!0){let r=Jt(e,t,n);return Yt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce="https://ldr-demo.vercel.app/cdn/v1/",ve=new Map,Ae=new Map;function ht(e=Ce,t=fetch){let n=ve.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(()=>ve.delete(e)),ve.set(e,n);return n}var qt=(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"),Me=(e,t)=>qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Me(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Me(r,t)])):e;function Qt(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let d=h.buffer;if(!d)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let C=new DataView(d).getUint32(0,!0),u=new Uint8Array(d,4+C),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[g,f]of Object.entries(h.header.parts??{}))if(!(g in s))s[g]=Me(f,b);for(let[g,f]of Object.entries(h.header.studKinds??{}))if(!(g in o))o[g]=Me(f,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,p=new Uint8Array(c+r);new DataView(p.buffer).setUint32(0,l.length+a,!0),p.set(l,4),p.fill(32,4+l.length,c);let m=c;for(let h of n)p.set(h,m),m+=h.byteLength;return ye(p.buffer)}async function en(e,t={}){e=[...e];try{return await mt(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await mt(e,{...t,fetch:o})}catch{throw n}}}async function mt(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await ht(n,r),i=[...new Set([...e].map(Y))],l=[],a=[];for(let u of i){if(Ae.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let p=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);p+=S.byteLength;for(let g of u.items){let f=de(S.subarray(g.off-u.start,g.off-u.start+g.len)),A=f.buffer.slice(f.byteOffset,f.byteOffset+f.byteLength);Ae.set(n+g.name,ye(A))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let d=i.filter((u)=>Ae.has(n+u)).map((u)=>Ae.get(n+u));return{pack:d.length?Qt(d,{colors:o.colors}):ye(tn(o.colors)),missing:l,requests:c.length,bytes:p}}function tn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}async function gt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=ht(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(f)=>{if(!f.ok)throw Error(`ldr: ${f.status} fetching ${e}`);return Ve(await f.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?"main.ldr":He(e)),a=ct(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let p=ut(o,new Set(a.filter((f)=>f.embedded).map((f)=>f.part)),l),{pack:m,missing:h,requests:d,bytes:C}=await en([...a.filter((f)=>!f.embedded).map((f)=>f.part),...p.values()],t),u=new Map([...p].map(([f,A])=>[A,f])),b=h.map((f)=>u.get(f)??f);for(let[f,A]of p){let z=m.header.parts[A];if(z)m.header.parts[f]=z}let S=performance.now(),g=t.cull?we(a,m.header,t.textures!==!1):void 0;return{insts:a,pack:m,missing:b,requests:d,bytes:C,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:S-c,...g?{cull:performance.now()-S}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await gt(n,{...r,cull:!1,onParsed:(p)=>self.postMessage({id:t,insts:p})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=we(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let p of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(p)c.push(p.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
3806
3829
 
3807
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/cdn.ts
3830
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/cdn.ts
3808
3831
  var worker;
3809
3832
  var seq = 0;
3810
3833
  var pending = new Map;
@@ -3859,7 +3882,7 @@ var abs = (u) => {
3859
3882
  function prepareInWorker(w, source, o) {
3860
3883
  const id = ++seq;
3861
3884
  const opts = { cdn: abs(o.cdn ?? DEFAULT_PARTS_CDN), gap: o.gap, concurrency: o.concurrency, text: o.text, name: o.name, cull: true, textures: o.textures, callouts: o.callouts };
3862
- const name = o.name ?? (o.text ? undefined : decodeURIComponent(source.split(/[?#]/)[0].split("/").pop() || "main.ldr"));
3885
+ const name = o.name ?? (o.text ? undefined : modelFileName(source));
3863
3886
  let insts;
3864
3887
  pendingInsts.set(id, (v) => {
3865
3888
  insts = v;
@@ -3913,7 +3936,7 @@ async function loadModel(source, o = {}) {
3913
3936
  timings: { ...prep.timings, parts: t3 - t0 - prep.timings.fetchModel - prep.timings.parse, build: t4 - t3, total: t4 - t0 }
3914
3937
  });
3915
3938
  }
3916
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/library.ts
3939
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/library.ts
3917
3940
  import { existsSync, readFileSync } from "fs";
3918
3941
  import { join } from "path";
3919
3942
  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]];
@@ -4164,11 +4187,11 @@ class Library {
4164
4187
  return insts;
4165
4188
  }
4166
4189
  }
4167
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/build-pack.ts
4190
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/build-pack.ts
4168
4191
  import fs3 from "node:fs";
4169
4192
  import path3 from "node:path";
4170
4193
 
4171
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/resolver.ts
4194
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/resolver.ts
4172
4195
  import fs from "node:fs";
4173
4196
  import path from "node:path";
4174
4197
  var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
@@ -4440,11 +4463,11 @@ function collectDeps(lib, refs) {
4440
4463
  return out;
4441
4464
  }
4442
4465
 
4443
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/compile.ts
4466
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/compile.ts
4444
4467
  import fs2 from "node:fs";
4445
4468
  import path2 from "node:path";
4446
4469
 
4447
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/lod.ts
4470
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/lod.ts
4448
4471
  import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
4449
4472
  await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
4450
4473
  function reorderMesh(P, N, C, I) {
@@ -4636,7 +4659,7 @@ function lodChain(P, C, I) {
4636
4659
  return out;
4637
4660
  }
4638
4661
 
4639
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/compile.ts
4662
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/compile.ts
4640
4663
  function loadColors(root) {
4641
4664
  const map = new Map;
4642
4665
  for (const l of fs2.readFileSync(path2.join(root, "LDConfig.ldr"), "latin1").split(/\r?\n/)) {
@@ -5219,7 +5242,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
5219
5242
  return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
5220
5243
  }
5221
5244
 
5222
- // ../../../../../../../tmp/ldr-build-MHOtAg/src/node/build-pack.ts
5245
+ // ../../../../../../../tmp/ldr-build-t1RiNG/src/node/build-pack.ts
5223
5246
  function buildPack(o) {
5224
5247
  const lib = new Library2(o.ldrawRoot);
5225
5248
  const refs = new Map;
@@ -5310,6 +5333,7 @@ export {
5310
5333
  createLdrObject,
5311
5334
  createLdrObjectAsync,
5312
5335
  cullCore,
5336
+ decodeModelText,
5313
5337
  decodePack,
5314
5338
  decompressPack,
5315
5339
  embeddedKeys,
@@ -5336,6 +5360,7 @@ export {
5336
5360
  makeFinishMaterial,
5337
5361
  makeMaterial,
5338
5362
  mergePacks,
5363
+ modelFileName,
5339
5364
  mul,
5340
5365
  norm,
5341
5366
  parse,
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Relabel the MPD-local model files that carry type 2-5 geometry (`!LDRAW_ORG Model` / `Submodel`, optionally `Unofficial_`) as
3
+ * `Unofficial_Part`. Left alone: the main (first) file, files without geometry, and geometry files that place a local submodel
4
+ * (a model file without geometry), which would otherwise be swallowed into one part. Library parts they place (hose end caps) become
5
+ * part of the compiled flex part. Everything else in the text (line endings included) is kept, so an unaffected file comes back
6
+ * byte-identical.
7
+ */
8
+ export declare function promoteFlexParts(text: string): {
9
+ text: string;
10
+ promoted: string[];
11
+ };
package/dist/pack-io.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  /** Detect gzip / zstd magic and return raw pack bytes (an ArrayBuffer you can hand to `decodePack`). */
2
2
  export declare function decompressPack(data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
3
+ /** Model file bytes -> LDraw text: zstd / gzip (hosted `.mpd.zst`, `.mpd.gz`) are inflated first, then decoded as UTF-8 like `Response.text()`. */
4
+ export declare function decodeModelText(data: ArrayBuffer | Uint8Array): Promise<string>;
5
+ /** Model file name from a URL (last path segment, decoded) without a `.zst` / `.gz` suffix: `/m/8466-1.mpd.zst` -> `8466-1.mpd`. */
6
+ export declare const modelFileName: (url: string) => string;
3
7
  /** A decoded parts pack. `buffer` is the raw (uncompressed) pack, used by `mergePacks`. */
4
8
  export type Pack = {
5
9
  header: any;
package/dist/render.d.ts CHANGED
@@ -77,14 +77,23 @@ export declare function computeCulling(insts: Inst[], H: any): {
77
77
  /** Drive buildLdrSceneGen to completion without yielding (same as pre-Round-33 sync build). */
78
78
  export declare function buildLdrScene(insts: Inst[], pack: Pack, P: LdrParams, color: (c: string) => THREE.Color, mark: (k: string) => void): any;
79
79
  export type BuildLdrSceneAsyncOptions = {
80
- /** Soft cap on contiguous main-thread work between yields (ms). Default 8. */
80
+ /** Soft cap on contiguous main-thread work between yields while mid-build paints are active (ms). Default 8. */
81
81
  sliceMs?: number;
82
- /** Called after each yield while the live root already holds finished batches (paint for TTFP). */
83
- onSlice?: (root: THREE.Object3D) => void | Promise<void>;
82
+ /**
83
+ * Soft cap after mid-build paints stop (onSlice returned false, or no onSlice). Default max(sliceMs, 24).
84
+ * Larger slices cut yield/timer overhead on the remaining build without changing the sync path.
85
+ */
86
+ postPaintSliceMs?: number;
87
+ /**
88
+ * Called after each yield while paints are enabled; live root already holds finished batches (paint for TTFP).
89
+ * Return `false` to stop further onSlice calls (keeps yielding with postPaintSliceMs) — use after first frame.
90
+ */
91
+ onSlice?: (root: THREE.Object3D) => void | boolean | Promise<void | boolean>;
84
92
  };
85
93
  /**
86
94
  * Same scene as buildLdrScene, but yields to the event loop about every sliceMs so the main thread stays responsive
87
95
  * and onSlice can render partial geometry for a fast time-to-first-pixel. Meshes are added to root as they are built.
96
+ * After onSlice returns false (TTFP done), slices coarsen to postPaintSliceMs and paints stop — cuts total loadMs.
88
97
  */
89
98
  export declare function buildLdrSceneAsync(insts: Inst[], pack: Pack, P: LdrParams, color: (c: string) => THREE.Color, mark: (k: string) => void, opts?: BuildLdrSceneAsyncOptions): Promise<any>;
90
99
  export declare function warmPackGeometry(pack: Pack, stop?: () => boolean, sliceMs?: number): Promise<void>;
package/dist/scene.d.ts CHANGED
@@ -51,10 +51,15 @@ export interface LdrObjectOptions {
51
51
  /** LOD: skip undersides that can't be seen: while the camera is behind every bottom face of a cluster's (same-orientation) parts and
52
52
  * studs are under 4 px, or where the body is drawn as its closed bounding box. Default true. */
53
53
  lodUnder?: boolean;
54
- /** Progressive build (createLdrObjectAsync / loadModel): soft cap on contiguous main-thread work between yields, ms. Default 8. */
54
+ /** Progressive build (createLdrObjectAsync / loadModel): soft cap while mid-build paints are active, ms. Default 8. */
55
55
  sliceMs?: number;
56
- /** Progressive build: called after each yield; the live object already holds finished batches — render for TTFP. */
57
- onSlice?: () => void | Promise<void>;
56
+ /** Progressive build: soft cap after paints stop (onSlice returned false / no onSlice). Default max(sliceMs, 24). */
57
+ postPaintSliceMs?: number;
58
+ /**
59
+ * Progressive build: called after each yield while paints are enabled; live object holds finished batches — render for TTFP.
60
+ * Return `false` to stop further onSlice calls (keeps yielding with postPaintSliceMs).
61
+ */
62
+ onSlice?: () => void | boolean | Promise<void | boolean>;
58
63
  }
59
64
  export interface LdrStats {
60
65
  instances: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldr",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
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",