filens-preview 0.3.1 → 0.3.2

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.
@@ -1,3 +1,3 @@
1
- var K=Object.defineProperty;var Q=(t,e,r)=>e in t?K(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var v=(t,e,r)=>Q(t,typeof e!="symbol"?e+"":e,r);import{o as ee,i as W,j as te,c as re,a as se,d as ne,k as ie,g as oe,l as ae}from"./core-BLayEJn5.js";import{f as le}from"./vendor-CBCxJuSg.js";function he(t,e){var b,p;if(t.includes("<!")||(b=e.fontStyles)!=null&&b.length&&/<cols\b/.test(t))return;const r=/<sheetData\s*>/.exec(t);if(!r)return;const s=r.index+r[0].length,n=t.indexOf("</sheetData>",s);if(n<0)return;const i=t.slice(s,n);if(/<(?:f|is)\b/.test(i))return;const o=[],a=/\s*<row\b([^<>]*?)(?:\/>|>([\s\S]*?)<\/row\s*>)/gy,d=/\s*<c\b([^<>]*?)(?:\/>|>([\s\S]*?)<\/c\s*>)/gy;let u=0,f=0,m=0;for(;u<i.length;){a.lastIndex=u;const l=a.exec(i);if(!l){if(i.slice(u).trim())return;break}const g=Z(l[1]);if(!g)return;const c=Number(g.r??o.length+1);if(!Number.isInteger(c)||c<1)return;const w=[],S=l[2]??"";let y=0;for(;y<S.length;){d.lastIndex=y;const A=d.exec(S);if(!A){if(S.slice(y).trim())return;break}const C=Z(A[1]);if(!C)return;const I=A[2]??"",N=/^\s*(?:<v\s*>([\s\S]*?)<\/v\s*>|<v\s*\/>)?\s*$/.exec(I);if(!N)return;const E=N[1]??"";if(E.trim()&&!/^[\s]*[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\s*$/.test(E)&&!/^\s*(?:true|false)\s*$/.test(E)||C.t&&!["n","s","b"].includes(C.t))return;if(C.r){const $=/^([A-Z]+)([1-9]\d*)$/i.exec(C.r);if(!$)return;let T=0;for(const Y of $[1].toUpperCase())T=T*26+Y.charCodeAt(0)-64;const L=C.t==="s"?e.sharedStrings[Number(E)]??"":C.t==="b"?E.trim()==="1"||E.trim()==="true"?"TRUE":"FALSE":E,R={ref:C.r,row:Number($[2]),column:T,value:L},J=["1","true"].includes(g.customFormat)?g.s:void 0,D=(p=e.fontStyles)==null?void 0:p[Number(C.s??J??0)];D&&(R.font=D),w.push(R),m=Math.max(m,T)}y=d.lastIndex}o.push({index:c,cells:w}),f=Math.max(f,c),u=a.lastIndex}return{id:e.id,name:e.name,rows:o,columnCount:m,rowCount:f}}function Z(t){const e=Object.create(null),r=/\s+([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"<>&]*)"|'([^'<>&]*)')/gy;let s=0;for(;s<t.length;){r.lastIndex=s;const n=r.exec(t);if(!n)return t.slice(s).trim()?void 0:e;e[n[1]]=n[2]??n[3],s=r.lastIndex}return e}const ce=1e5,M=new le.XMLParser({ignoreAttributes:false,attributeNamePrefix:"",textNodeName:"#text",parseTagValue:false,parseAttributeValue:false,trimValues:false,processEntities:{enabled:true,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:ce,maxExpandedLength:1e5,maxEntityCount:100}});async function fe(t,e){var l,g;if(k(e==null?void 0:e.signal),Ne(((l=e==null?void 0:e.route)==null?void 0:l.sourceFormat)??(e==null?void 0:e.descriptor.extension))==="csv")return de(t,e);const s=await ue(t,e);k(e==null?void 0:e.signal);const n=await ee(s);k(e==null?void 0:e.signal);const i=[],o=await _(n,"xl/workbook.xml",e==null?void 0:e.signal),a=await _(n,"xl/_rels/workbook.xml.rels",e==null?void 0:e.signal),d=await pe(n,e==null?void 0:e.signal);k(e==null?void 0:e.signal);const u=M.parse(o),f=be(a),m=await ve(n,f,e==null?void 0:e.signal),b=ye(u),p=[];for(const c of b){k(e==null?void 0:e.signal);const w=f.find(A=>A.id===c.relationshipId);if(!w){i.push(`Missing relationship for sheet ${c.name}.`);continue}const S=O(w.target),y=await((g=n.get(S))==null?void 0:g.text());if(k(e==null?void 0:e.signal),!y){i.push(`Missing worksheet file for sheet ${c.name}.`);continue}p.push(ke(y,{id:c.sheetId,name:c.name,sharedStrings:d,fontStyles:m.styles}))}return{sheets:p,warnings:i,fonts:m.fonts}}async function de(t,e){k(e==null?void 0:e.signal);const r=await me(t,e);k(e==null?void 0:e.signal);const{rows:s,columnCount:n}=we(r);return{sheets:[{id:"csv",name:Te(e==null?void 0:e.descriptor.name),rows:s,columnCount:n,rowCount:s.length}],warnings:[]}}async function ue(t,e){if(typeof t=="string"){const r=await fetch(t,{signal:e==null?void 0:e.signal});if(!r.ok)throw new Error(`Failed to load XLSX source: ${r.status} ${r.statusText}`.trim());return new Uint8Array(await r.arrayBuffer())}return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t instanceof ArrayBuffer?new Uint8Array(t):t instanceof Blob?new Uint8Array(await t.arrayBuffer()):new Uint8Array}async function me(t,e){if(typeof t=="string"){if(t.trimStart().toLowerCase().startsWith("data:"))return ge(t);const r=await fetch(t,{signal:e==null?void 0:e.signal});if(!r.ok)throw new Error(`Failed to load CSV source: ${r.status} ${r.statusText}`.trim());return r.text()}return t instanceof Blob?t.text():ArrayBuffer.isView(t)?new TextDecoder().decode(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)):t instanceof ArrayBuffer?new TextDecoder().decode(t):String(t)}function ge(t){const e=t.indexOf(",");if(e<0)return t;const r=t.slice(0,e).toLowerCase(),s=t.slice(e+1);return r.endsWith(";base64")?new TextDecoder().decode(Uint8Array.from(atob(s),n=>n.charCodeAt(0))):decodeURIComponent(s)}function we(t){t=t.replace(/^\uFEFF/,"");const e=[],r=[],s=f=>{for(;r.length<f.length;)r.push(q(r.length+1));const m=e.length+1,b=String(m),p=new Array(f.length);for(let l=0;l<f.length;l++)p[l]={ref:r[l]+b,row:m,column:l+1,value:f[l]};e.push({index:m,cells:p})};if(!t.includes('"')){const f=t.split(/\r\n|\r|\n/);t.length&&/[\r\n]$/.test(t)&&f.pop();for(const m of f)s(m.split(","));return{rows:e,columnCount:r.length}}let n=[],i="",o=0,a=0,d=0,u=false;for(;o<t.length;){if(u){const m=t.indexOf('"',o);if(m<0){i+=t.slice(o),a=o=t.length;break}i+=t.slice(o,m),o=m+1,t[o]==='"'?(i+='"',o++):u=false,a=o;continue}const f=t[o];if(f==='"'&&i.length===0&&o===a){u=true,a=++o;continue}if(f===","){n.push(i+t.slice(a,o)),i="",a=++o;continue}if(f==="\r"||f===`
1
+ var K=Object.defineProperty;var Q=(t,e,r)=>e in t?K(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var v=(t,e,r)=>Q(t,typeof e!="symbol"?e+"":e,r);import{o as ee,i as W,j as te,c as re,a as se,d as ne,k as ie,g as oe,l as ae}from"./core-EjELrtsP.js";import{f as le}from"./vendor-C1aIdQ-w.js";function he(t,e){var b,p;if(t.includes("<!")||(b=e.fontStyles)!=null&&b.length&&/<cols\b/.test(t))return;const r=/<sheetData\s*>/.exec(t);if(!r)return;const s=r.index+r[0].length,n=t.indexOf("</sheetData>",s);if(n<0)return;const i=t.slice(s,n);if(/<(?:f|is)\b/.test(i))return;const o=[],a=/\s*<row\b([^<>]*?)(?:\/>|>([\s\S]*?)<\/row\s*>)/gy,d=/\s*<c\b([^<>]*?)(?:\/>|>([\s\S]*?)<\/c\s*>)/gy;let u=0,f=0,m=0;for(;u<i.length;){a.lastIndex=u;const l=a.exec(i);if(!l){if(i.slice(u).trim())return;break}const g=Z(l[1]);if(!g)return;const c=Number(g.r??o.length+1);if(!Number.isInteger(c)||c<1)return;const w=[],S=l[2]??"";let y=0;for(;y<S.length;){d.lastIndex=y;const A=d.exec(S);if(!A){if(S.slice(y).trim())return;break}const C=Z(A[1]);if(!C)return;const I=A[2]??"",N=/^\s*(?:<v\s*>([\s\S]*?)<\/v\s*>|<v\s*\/>)?\s*$/.exec(I);if(!N)return;const E=N[1]??"";if(E.trim()&&!/^[\s]*[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\s*$/.test(E)&&!/^\s*(?:true|false)\s*$/.test(E)||C.t&&!["n","s","b"].includes(C.t))return;if(C.r){const $=/^([A-Z]+)([1-9]\d*)$/i.exec(C.r);if(!$)return;let T=0;for(const Y of $[1].toUpperCase())T=T*26+Y.charCodeAt(0)-64;const L=C.t==="s"?e.sharedStrings[Number(E)]??"":C.t==="b"?E.trim()==="1"||E.trim()==="true"?"TRUE":"FALSE":E,R={ref:C.r,row:Number($[2]),column:T,value:L},J=["1","true"].includes(g.customFormat)?g.s:void 0,D=(p=e.fontStyles)==null?void 0:p[Number(C.s??J??0)];D&&(R.font=D),w.push(R),m=Math.max(m,T)}y=d.lastIndex}o.push({index:c,cells:w}),f=Math.max(f,c),u=a.lastIndex}return{id:e.id,name:e.name,rows:o,columnCount:m,rowCount:f}}function Z(t){const e=Object.create(null),r=/\s+([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"<>&]*)"|'([^'<>&]*)')/gy;let s=0;for(;s<t.length;){r.lastIndex=s;const n=r.exec(t);if(!n)return t.slice(s).trim()?void 0:e;e[n[1]]=n[2]??n[3],s=r.lastIndex}return e}const ce=1e5,M=new le.XMLParser({ignoreAttributes:false,attributeNamePrefix:"",textNodeName:"#text",parseTagValue:false,parseAttributeValue:false,trimValues:false,processEntities:{enabled:true,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:ce,maxExpandedLength:1e5,maxEntityCount:100}});async function fe(t,e){var l,g;if(k(e==null?void 0:e.signal),Ne(((l=e==null?void 0:e.route)==null?void 0:l.sourceFormat)??(e==null?void 0:e.descriptor.extension))==="csv")return de(t,e);const s=await ue(t,e);k(e==null?void 0:e.signal);const n=await ee(s);k(e==null?void 0:e.signal);const i=[],o=await _(n,"xl/workbook.xml",e==null?void 0:e.signal),a=await _(n,"xl/_rels/workbook.xml.rels",e==null?void 0:e.signal),d=await pe(n,e==null?void 0:e.signal);k(e==null?void 0:e.signal);const u=M.parse(o),f=be(a),m=await ve(n,f,e==null?void 0:e.signal),b=ye(u),p=[];for(const c of b){k(e==null?void 0:e.signal);const w=f.find(A=>A.id===c.relationshipId);if(!w){i.push(`Missing relationship for sheet ${c.name}.`);continue}const S=O(w.target),y=await((g=n.get(S))==null?void 0:g.text());if(k(e==null?void 0:e.signal),!y){i.push(`Missing worksheet file for sheet ${c.name}.`);continue}p.push(ke(y,{id:c.sheetId,name:c.name,sharedStrings:d,fontStyles:m.styles}))}return{sheets:p,warnings:i,fonts:m.fonts}}async function de(t,e){k(e==null?void 0:e.signal);const r=await me(t,e);k(e==null?void 0:e.signal);const{rows:s,columnCount:n}=we(r);return{sheets:[{id:"csv",name:Te(e==null?void 0:e.descriptor.name),rows:s,columnCount:n,rowCount:s.length}],warnings:[]}}async function ue(t,e){if(typeof t=="string"){const r=await fetch(t,{signal:e==null?void 0:e.signal});if(!r.ok)throw new Error(`Failed to load XLSX source: ${r.status} ${r.statusText}`.trim());return new Uint8Array(await r.arrayBuffer())}return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t instanceof ArrayBuffer?new Uint8Array(t):t instanceof Blob?new Uint8Array(await t.arrayBuffer()):new Uint8Array}async function me(t,e){if(typeof t=="string"){if(t.trimStart().toLowerCase().startsWith("data:"))return ge(t);const r=await fetch(t,{signal:e==null?void 0:e.signal});if(!r.ok)throw new Error(`Failed to load CSV source: ${r.status} ${r.statusText}`.trim());return r.text()}return t instanceof Blob?t.text():ArrayBuffer.isView(t)?new TextDecoder().decode(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)):t instanceof ArrayBuffer?new TextDecoder().decode(t):String(t)}function ge(t){const e=t.indexOf(",");if(e<0)return t;const r=t.slice(0,e).toLowerCase(),s=t.slice(e+1);return r.endsWith(";base64")?new TextDecoder().decode(Uint8Array.from(atob(s),n=>n.charCodeAt(0))):decodeURIComponent(s)}function we(t){t=t.replace(/^\uFEFF/,"");const e=[],r=[],s=f=>{for(;r.length<f.length;)r.push(q(r.length+1));const m=e.length+1,b=String(m),p=new Array(f.length);for(let l=0;l<f.length;l++)p[l]={ref:r[l]+b,row:m,column:l+1,value:f[l]};e.push({index:m,cells:p})};if(!t.includes('"')){const f=t.split(/\r\n|\r|\n/);t.length&&/[\r\n]$/.test(t)&&f.pop();for(const m of f)s(m.split(","));return{rows:e,columnCount:r.length}}let n=[],i="",o=0,a=0,d=0,u=false;for(;o<t.length;){if(u){const m=t.indexOf('"',o);if(m<0){i+=t.slice(o),a=o=t.length;break}i+=t.slice(o,m),o=m+1,t[o]==='"'?(i+='"',o++):u=false,a=o;continue}const f=t[o];if(f==='"'&&i.length===0&&o===a){u=true,a=++o;continue}if(f===","){n.push(i+t.slice(a,o)),i="",a=++o;continue}if(f==="\r"||f===`
2
2
  `){n.push(i+t.slice(a,o)),s(n),n=[],i="",f==="\r"&&t[o+1]===`
3
3
  `?o+=2:o+=1,d=a=o;continue}o+=1}return(d<t.length||t.length===0)&&(n.push(i+t.slice(a,o)),s(n)),{rows:e,columnCount:r.length}}function k(t){if(t!=null&&t.aborted)throw new DOMException("Workbook preview aborted.","AbortError")}async function _(t,e,r){k(r);const s=t.get(e);if(!s)throw new Error(`Invalid XLSX file: missing ${e}.`);const n=await s.text();return k(r),n}async function pe(t,e){k(e);const r=t.get("xl/sharedStrings.xml");if(!r)return[];const s=await r.text();k(e);const n=M.parse(s);return F(h(n,["sst","si"])).map(V)}function V(t){const e=h(t,["t"]);if(e!=null)return B(e);const r=F(h(t,["r"]));return r.length?r.map(s=>B(h(s,["t"]))).join(""):""}function B(t){if(typeof t=="string")return t;const e=h(t,["#text"]);return typeof e=="string"?e:""}function be(t){const e=M.parse(t);return F(h(e,["Relationships","Relationship"])).map(r=>({id:String(h(r,["Id"])??""),target:String(h(r,["Target"])??""),type:String(h(r,["Type"])??"")})).filter(r=>r.id&&r.target)}function ye(t){return F(h(t,["workbook","sheets","sheet"])).map(e=>({name:String(h(e,["name"])??"Sheet"),sheetId:String(h(e,["sheetId"])??h(e,["name"])??"sheet"),relationshipId:String(h(e,["r:id"])??"")})).filter(e=>e.relationshipId)}async function ve(t,e,r){var b,p,l,g;const s=O(((b=e.find(c=>{var w;return(w=c.type)==null?void 0:w.endsWith("/styles")}))==null?void 0:b.target)??"styles.xml"),n=await((p=t.get(s))==null?void 0:p.text());if(k(r),!n)return{fonts:[],styles:[]};const i=M.parse(n),o=O(((l=e.find(c=>{var w;return(w=c.type)==null?void 0:w.endsWith("/theme")}))==null?void 0:l.target)??"theme/theme1.xml"),a=await((g=t.get(o))==null?void 0:g.text());k(r);const d=a?M.parse(a):void 0,u=F(h(i,["styleSheet","fonts","font"])).map(c=>{const w=h(c,["scheme","val"]),S=w==="major"||w==="minor"?U(d,["theme","themeElements","fontScheme",`${w}Font`,"latin"]):void 0,y=U(S,["typeface"]),A=typeof y=="string"&&y.trim()?y:void 0,C=String(A??h(c,["name","val"])??"").trim(),I=Number(U(S,["pitchFamily"])),N=Number.isInteger(I)&&I>=0&&I<=255,E=N&&(I&3)===1?"fixed":N&&(I&3)===2?"variable":void 0,$=N?W(I>>4):{},T=U(S,["panose"]),L=h(c,["b"]),R=L!==void 0&&!["0","false"].includes(String(h(L,["val"])??L))?700:400;return{fontFamily:C||void 0,traits:{...A?{...$,...te(typeof T=="string"?T:void 0),...W(void 0,E)}:W(h(c,["family","val"])),weight:R}}}),f=F(h(i,["styleSheet","cellStyleXfs","xf"])),m=F(h(i,["styleSheet","cellXfs","xf"]));return{fonts:u,styles:m.map(c=>{const w=f[Number(h(c,["xfId"])??0)],y=["0","false"].includes(String(h(c,["applyFont"])))?h(w,["fontId"]):h(c,["fontId"])??h(w,["fontId"]);return u[Number(y??0)]})}}function U(t,e){for(const r of e){if(!t||typeof t!="object")return;const s=t,n=Object.keys(s).find(i=>i.split(":").pop()===r);t=n?s[n]:void 0}return t}function ke(t,e){const r=he(t,e);if(r)return r;const s=M.parse(t),n=F(h(s,["worksheet","sheetData","row"])),i=[],o=F(h(s,["worksheet","cols","col"]));let a=0,d=0;for(const u of n){const f=Number(h(u,["r"])??i.length+1);d=Math.max(d,f);const m=["1","true"].includes(String(h(u,["customFormat"])))?h(u,["s"]):void 0,b=F(h(u,["c"])).map(p=>{var S;const l=Se(p,e.sharedStrings);if(!l)return null;const g=o.find(y=>l.column>=Number(h(y,["min"]))&&l.column<=Number(h(y,["max"]))),c=h(p,["s"])??m??h(g,["style"])??0,w=(S=e.fontStyles)==null?void 0:S[Number(c)];return w&&(l.font=w),l}).filter(p=>p!=null);for(const p of b)a=Math.max(a,p.column);i.push({index:f,cells:b})}return{id:e.id,name:e.name,rows:i,columnCount:a,rowCount:d}}function Se(t,e){const r=String(h(t,["r"])??"");if(!r)return null;const s=P(r),n=String(h(t,["t"])??""),i=Ce(t),o=xe(t);let a=i??"";if(n==="s")a=e[Number(i??"")]??"";else if(n==="b"){const d=i==null?void 0:i.trim();a=d==="1"||d==="true"?"TRUE":"FALSE"}else n==="inlineStr"&&(a=V(h(t,["is"])));return{ref:r,row:s.row,column:s.column,value:a,...o?{formula:o,needsCalculation:i==null}:{}}}function Ce(t){const e=h(t,["v"]);return e==null?null:String(e)}function xe(t){const e=h(t,["f"]);if(typeof e=="string")return e;const r=h(e,["#text"]);return typeof r=="string"?r:""}function j(t,e,r=new Set){if(!e.formula||!e.needsCalculation)return e.value;if(r.has(e.ref))return`=${e.formula}`;r.add(e.ref);try{const s=new Ee(e.formula,n=>Fe(t,n,r)).read();e.value=String(s)}catch{e.value=`=${e.formula}`}finally{r.delete(e.ref),e.needsCalculation=false}return e.value}const z=new WeakMap;function Fe(t,e,r){const s=P(e.replace(/\$/g,""));let n=z.get(t);if(!n){n=new Map;for(const d of t.rows)for(const u of d.cells)n.set(`${d.index}:${u.column}`,u);z.set(t,n)}const i=n.get(`${s.row}:${s.column}`);if(!i)return 0;const o=j(t,i,r).trim();if(o==="")return 0;if(o.toUpperCase()==="TRUE")return 1;if(o.toUpperCase()==="FALSE")return 0;const a=Number(o);if(!Number.isFinite(a))throw new Error(`Formula reference ${e} is not numeric.`);return a}class Ee{constructor(e,r){v(this,"tokens");v(this,"index",0);this.readCell=r,this.tokens=Ae(e.replace(/^=/,"").trim())}read(){const e=this.readExpression();if(this.index!==this.tokens.length||Array.isArray(e)||!Number.isFinite(e))throw new Error("Unsupported formula.");return e}readExpression(){let e=this.readTerm();for(;this.peek()==="+"||this.peek()==="-";){const r=this.take(),s=this.readTerm();e=r==="+"?x(e)+x(s):x(e)-x(s)}return e}readTerm(){let e=this.readPower();for(;this.peek()==="*"||this.peek()==="/";){const r=this.take(),s=this.readPower();e=r==="*"?x(e)*x(s):x(e)/x(s)}return e}readPower(){let e=this.readUnary();return this.peek()==="^"&&(this.take(),e=x(e)**x(this.readPower())),e}readUnary(){return this.peek()==="+"||this.peek()==="-"?(this.take()==="-"?-1:1)*x(this.readUnary()):this.readPrimary()}readPrimary(){const e=this.take();if(e==="("){const r=this.readExpression();return this.expect(")"),r}if(/^(?:\d+(?:\.\d*)?|\.\d+)(?:E[+-]?\d+)?$/i.test(e))return Number(e);if(/^\$?[A-Z]+\$?\d+$/i.test(e))return this.peek()!==":"?this.readCell(e):(this.take(),this.readRange(e,this.take()));if(/^[A-Z][A-Z0-9_.]*$/i.test(e)){if(e.toUpperCase()==="TRUE")return 1;if(e.toUpperCase()==="FALSE")return 0;if(e.toUpperCase()!=="SUM")throw new Error("Unsupported function.");this.expect("(");const r=[];if(this.peek()!==")")do{const s=this.readExpression();r.push(...Array.isArray(s)?s:[s])}while(this.peek()===","&&this.take());return this.expect(")"),r.reduce((s,n)=>s+n,0)}throw new Error("Unsupported formula token.")}readRange(e,r){if(!/^\$?[A-Z]+\$?\d+$/i.test(r))throw new Error("Invalid range.");const s=P(e.replace(/\$/g,"")),n=P(r.replace(/\$/g,"")),i=[];for(let o=Math.min(s.row,n.row);o<=Math.max(s.row,n.row);o+=1)for(let a=Math.min(s.column,n.column);a<=Math.max(s.column,n.column);a+=1)i.push(this.readCell(`${q(a)}${o}`));return i}peek(){return this.tokens[this.index]??""}take(){const e=this.tokens[this.index];if(!e)throw new Error("Unexpected end of formula.");return this.index+=1,e}expect(e){if(this.take()!==e)throw new Error(`Expected ${e}.`)}}function x(t){if(Array.isArray(t))throw new Error("Range cannot be used as a scalar.");return t}function Ae(t){const e=[],r=/\s*((?:\d+(?:\.\d*)?|\.\d+)(?:E[+-]?\d+)?|\$?[A-Z]+\$?\d+|[A-Z][A-Z0-9_.]*|[()+\-*/^,:])/iy;let s=0;for(;s<t.length;){r.lastIndex=s;const n=r.exec(t);if(!n)throw new Error("Unsupported formula token.");e.push(n[1]??""),s=r.lastIndex}return e}function P(t){const e=/^([A-Z]+)(\d+)$/i.exec(t);return e?{column:Ie(e[1]??"A"),row:Number(e[2]??1)}:{row:1,column:1}}function Ie(t){let e=0;for(const r of t.toUpperCase())e=e*26+r.charCodeAt(0)-64;return e}function q(t){let e=t,r="";for(;e>0;){const s=(e-1)%26;r=String.fromCharCode(65+s)+r,e=Math.floor((e-1)/26)}return r||"A"}function Te(t){var r;return(((r=String(t??"").split(/[?#]/,1)[0])==null?void 0:r.split(/[\\/]/).pop())??"").replace(/\.[^.]+$/,"")||"CSV"}function Ne(t){return String(t??"").trim().replace(/^\./,"").toLowerCase()}function O(t){const e=t.replace(/\\/g,"/").replace(/^\//,"");return e.startsWith("xl/")?e:`xl/${e}`}function h(t,e){let r=t;for(const s of e){if(!r||typeof r!="object")return;r=r[s]}return r}function F(t){return t==null?[]:Array.isArray(t)?t:[t]}const X=100,Me=[{extensions:["xlsx"],family:"workbook",driverId:"xlsx",targetFormat:"xlsx"},{extensions:["csv"],family:"workbook",driverId:"xlsx",targetFormat:"csv",contentTypes:["text/csv","application/csv"]}];class $e{constructor(e,r={}){v(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});v(this,"root");v(this,"tabs");v(this,"grid");v(this,"workbook",null);v(this,"loadGeneration",0);v(this,"loadController");v(this,"removeAbortListener");v(this,"state");v(this,"fontLoading");v(this,"fontReferences",[]);v(this,"allFontReferences",[]);v(this,"handleGridScroll",()=>{var i;const e2=(i=this.workbook)==null?void 0:i.sheets[this.state.activeSheetIndex],r2=this.grid.querySelector("tbody");if(!e2||!r2||this.grid.scrollHeight-this.grid.scrollTop-this.grid.clientHeight>this.grid.clientHeight*2)return;const s=r2.rows.length,n=Math.max(e2.rowCount,1);s>=n||H(r2,e2,s+1,Math.min(s+X,n))});this.host=e,this.root=document.createElement("div"),this.root.className="xlsxv-preview",this.tabs=document.createElement("div"),this.tabs.className="xlsxv-sheet-tabs",this.grid=document.createElement("div"),this.grid.className="xlsxv-grid",this.root.replaceChildren(this.tabs,this.grid),this.host.replaceChildren(this.root),this.grid.addEventListener("scroll",this.handleGridScroll,{passive:true}),this.state={loading:false,error:null,family:"workbook",warnings:[],capabilities:{workbook:true,sheets:true,search:true,download:true},activeSheetIndex:0,sheets:[],scale:r.initialScale??1},this.fontLoading=se(this,e.ownerDocument,r)}async load(e,r){var a,d,u;this.fontLoading.reset(r.signal,((a=r.route)==null?void 0:a.targetFormat)??r.descriptor.extension??"xlsx");const s=++this.loadGeneration;(d=this.loadController)==null||d.abort(),(u=this.removeAbortListener)==null||u.call(this),this.releaseWorkbook();const n=new AbortController;this.loadController=n;const i=r.signal,o=()=>{n.abort(),s===this.loadGeneration&&(this.releaseWorkbook(),this.state.loading=false,this.emit("statechange",this.state))};i==null||i.addEventListener("abort",o,{once:true}),this.removeAbortListener=()=>i==null?void 0:i.removeEventListener("abort",o),this.state={...this.state,loading:true,error:null,title:r.descriptor.name,warnings:[]},this.emit("loading",this.state),this.emit("statechange",this.state);try{i!=null&&i.aborted&&o();const f=await fe(e,{...r,signal:n.signal});if(s!==this.loadGeneration)return;if(n.signal.aborted)throw new DOMException("Workbook preview aborted.","AbortError");this.workbook=f;const m=new Set;for(const l of f.sheets)for(const g of l.rows)for(const c of g.cells)c.font&&m.add(c.font);this.allFontReferences=(f.fonts??[]).map(l=>({...l})),this.fontReferences=this.allFontReferences.filter((l,g)=>m.has(f.fonts[g]));const b=ne(f.fonts??[],this.host.ownerDocument,{substitute:true}),p=new Map(b.fonts.map(l=>[JSON.stringify([l.fontFamily,l.classification]),l.resolvedFontFamily]));for(const l of f.fonts??[]){const g=p.get(JSON.stringify([l.fontFamily,ie(l.fontFamily??"",l.traits)]));g&&(l.resolvedFontFamily=g)}this.state={...this.state,loading:false,error:null,warnings:[...new Set([...this.workbook.warnings,...b.warnings])],fonts:b.fonts,activeSheetIndex:0,sheets:this.workbook.sheets.map((l,g)=>({id:l.id||String(g+1),name:l.name}))},this.render(),this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(f){if(s!==this.loadGeneration)return;if(this.releaseWorkbook(),this.state.loading=false,n.signal.aborted)throw new DOMException("Workbook preview aborted.","AbortError");const m=f instanceof Error?f:new Error(String(f));throw this.state.error=m.message,this.emit("error",m),this.emit("statechange",this.state),m}}destroy(){var e,r;this.fontLoading.destroy(),this.loadGeneration++,(e=this.loadController)==null||e.abort(),(r=this.removeAbortListener)==null||r.call(this),this.releaseWorkbook(),this.state.loading=false,this.grid.removeEventListener("scroll",this.handleGridScroll),this.root.replaceChildren(),this.root.parentElement===this.host&&this.host.replaceChildren();for(const s of Object.values(this.listeners))s.clear()}getState(){var e;return{...this.state,warnings:this.state.warnings.slice(),fonts:(e=this.state.fonts)==null?void 0:e.map(r=>({...r,classification:r.classification?{...r.classification}:void 0})),sheets:this.state.sheets.slice()}}getFontReferences(){return this.fontReferences}refreshFonts(e){var s,n;if(!this.workbook||(s=this.loadController)!=null&&s.signal.aborted)return;this.fontReferences=e.references,this.allFontReferences=this.allFontReferences.map(i=>e.references.find(o=>{var a,d;return o.fontFamily===i.fontFamily&&((a=o.traits)==null?void 0:a.weight)===((d=i.traits)==null?void 0:d.weight)})??i);const r=oe({...e,references:this.allFontReferences},this.host.ownerDocument);for(const i of this.workbook.fonts??[]){const o=e.references.find(a=>{var d,u;return a.fontFamily===i.fontFamily&&((d=a.traits)==null?void 0:d.weight)===((u=i.traits)==null?void 0:u.weight)});o!=null&&o.resolvedFontFamily&&(i.resolvedFontFamily=o.resolvedFontFamily)}if(this.state.fonts=r.fonts,this.state.warnings=[...new Set([...this.workbook.warnings,...r.warnings])],e.loaded.length||e.relayout){const i=this.workbook.sheets[this.state.activeSheetIndex],o=this.grid.scrollTop,a=this.grid.scrollLeft,d=((n=this.grid.querySelector("tbody"))==null?void 0:n.rows.length)??X;i&&this.grid.replaceChildren(G(i,d)),this.grid.scrollTop=o,this.grid.scrollLeft=a}this.emit("warnings",this.state.warnings),this.emit("rendered",this.getState()),this.emit("statechange",this.getState())}on(e,r){return this.listeners[e].add(r),()=>{this.listeners[e].delete(r)}}goToPage(e){this.goToSheet(e)}next(){this.goToSheet(Math.min(this.state.activeSheetIndex+1,Math.max(this.state.sheets.length-1,0)))}prev(){this.goToSheet(Math.max(this.state.activeSheetIndex-1,0))}goToSheet(e){if(!Number.isInteger(e)||!this.workbook)return;const r=Math.max(0,Math.min(e,Math.max(this.state.sheets.length-1,0)));r!==this.state.activeSheetIndex&&(this.state.activeSheetIndex=r,this.render(),this.emit("statechange",this.state))}render(){this.renderTabs(),this.renderActiveSheet()}renderTabs(){this.tabs.replaceChildren();for(const[e,r]of this.state.sheets.entries()){const s=document.createElement("button");s.type="button",s.className="xlsxv-sheet-tab",s.classList.toggle("is-active",e===this.state.activeSheetIndex),s.textContent=r.name,s.addEventListener("click",()=>this.goToSheet(e)),this.tabs.appendChild(s)}}renderActiveSheet(){var r;const e=(r=this.workbook)==null?void 0:r.sheets[this.state.activeSheetIndex];this.grid.replaceChildren(),this.grid.scrollTop=this.grid.scrollLeft=0,e&&this.grid.appendChild(G(e,Math.min(Math.max(e.rowCount,1),X)))}releaseWorkbook(){this.fontReferences=[],this.allFontReferences=[],this.workbook=null,this.tabs.replaceChildren(),this.grid.replaceChildren(),this.grid.scrollTop=this.grid.scrollLeft=0,this.state.activeSheetIndex=0,this.state.sheets=[],this.state.fonts=[]}emit(e,r){for(const s of this.listeners[e])s(r)}}function Xe(){return{id:"xlsx",family:"workbook",supports:t=>["xlsx","csv"].includes(Le(t)),createSession:(t,e)=>new $e(t,e)}}function Oe(t=re()){return[...Me,...t.filter(e=>!e.extensions.some(r=>{var s;return r==="xlsx"||r==="csv"&&!((s=e.conversion)!=null&&s.required)}))]}function G(t,e=Math.max(t.rowCount,1)){const r=document.createElement("table");r.className="xlsxv-table";const s=document.createElement("thead"),n=document.createElement("tr"),i=document.createElement("th");i.className="xlsxv-corner",n.appendChild(i);for(let a=1;a<=Math.max(t.columnCount,1);a+=1){const d=document.createElement("th");d.className="xlsxv-col-header",d.textContent=Re(a),n.appendChild(d)}s.appendChild(n),r.appendChild(s);const o=document.createElement("tbody");return H(o,t,1,e),r.appendChild(o),r}function H(t,e,r,s){var a,d;if(r>s)return;const n=new Map,i=new Map;for(const u of e.rows)u.index>=r&&u.index<=s&&i.set(u.index,u);const o=document.createDocumentFragment();for(let u=r;u<=s;u+=1){const f=i.get(u),m=document.createElement("tr"),b=document.createElement("th");b.className="xlsxv-row-header",b.textContent=String(u),m.appendChild(b);const p=new Map((f==null?void 0:f.cells.map(l=>[l.column,l]))??[]);for(let l=1;l<=Math.max(e.columnCount,1);l+=1){const g=document.createElement("td");g.className="xlsxv-cell";const c=p.get(l);if(g.textContent=c?j(e,c):"",(a=c==null?void 0:c.font)!=null&&a.fontFamily){let w=n.get(c.font);w||(w=ae(c.font.fontFamily,c.font.traits,c.font.resolvedFontFamily?[c.font.resolvedFontFamily]:[]),n.set(c.font,w)),g.style.fontFamily=w,(d=c.font.traits)!=null&&d.weight&&(g.style.fontWeight=String(c.font.traits.weight))}m.appendChild(g)}o.appendChild(m)}t.appendChild(o)}function Le(t){return t.trim().replace(/^\./,"").toLowerCase()}function Re(t){let e=t,r="";for(;e>0;){const s=(e-1)%26;r=String.fromCharCode(65+s)+r,e=Math.floor((e-1)/26)}return r||"A"}export{X as R,H as a,Xe as b,G as c,Oe as d};
@@ -1,2 +1,2 @@
1
1
  if(typeof document!=="undefined"){const s=document.createElement("style");s.textContent=".archivev-preview{--archivev-summary-height: 44px;box-sizing:border-box;width:100%;height:100%;min-height:320px;overflow:auto;background:#f7f9fc;color:#1f2937;font-family:system-ui,sans-serif}.archivev-summary{position:sticky;top:0;z-index:1;display:flex;align-items:center;gap:16px;box-sizing:border-box;height:var(--archivev-summary-height);padding:12px 16px;border-bottom:1px solid #d7dee8;background:#fff;color:#5b6b81;font:700 12px/1 system-ui,sans-serif}.archivev-breadcrumbs{display:flex;flex:1 1 auto;align-items:center;gap:4px;min-width:0;overflow-x:auto;overflow-y:hidden;white-space:nowrap;scrollbar-width:thin}.archivev-breadcrumb{-webkit-appearance:none;-moz-appearance:none;appearance:none;flex:0 0 auto;min-width:0;max-width:min(280px,45vw);overflow:hidden;border:0;padding:2px 4px;background:transparent;color:#2563eb;font:700 12px/1.2 system-ui,sans-serif;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}.archivev-breadcrumb:disabled{color:#5b6b81;cursor:default}.archivev-breadcrumb-separator{flex:0 0 auto;color:#9aa8b8;-webkit-user-select:none;user-select:none}.archivev-breadcrumb-current{flex:0 0 auto;max-width:min(320px,50vw);overflow:hidden;color:#1f2937;text-overflow:ellipsis}.archivev-item-count{flex:0 0 auto;color:#7a8798;white-space:nowrap}.archivev-toolbar{position:sticky;top:var(--archivev-summary-height);z-index:1;display:flex;gap:8px;padding:10px 16px;border-bottom:1px solid #e5ebf2;background:#fff}.archivev-button{-webkit-appearance:none;-moz-appearance:none;appearance:none;border:1px solid #d7dee8;background:#f8fafc;color:#1f2937;font:600 12px/1 system-ui,sans-serif;padding:7px 10px;cursor:pointer}.archivev-button:disabled{cursor:default;opacity:.6}.archivev-table{width:100%;border-collapse:collapse;table-layout:fixed;background:#fff}.archivev-table th,.archivev-table td{padding:10px 14px;border-bottom:1px solid #e5ebf2;text-align:left;vertical-align:middle;font-size:13px}.archivev-table th{background:#f1f5f9;color:#5b6b81;font-size:12px;font-weight:700}.archivev-row{cursor:pointer}.archivev-row:focus-visible{outline:2px solid rgba(37,99,235,.35);outline-offset:-2px}.archivev-row:hover td{background:#f8fafc}.archivev-entry-preview{box-sizing:border-box;min-height:320px;height:calc(100% - 96px);overflow:auto;background:#fff}.archivev-entry-image{display:block;max-width:100%;max-height:70vh;margin:24px auto;object-fit:contain}.archivev-entry-frame{display:block;width:100%;height:70vh;border:0}.archivev-entry-media{display:block;width:min(100%,720px);margin:32px auto}.archivev-entry-text{box-sizing:border-box;min-height:320px;margin:0;padding:24px;overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;color:#1f2937;font:13px/1.6 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}.archivev-name{width:52%;overflow-wrap:anywhere;font-weight:600}.archivev-name:before{content:\"\";display:inline-block;width:9px;height:9px;margin-right:8px;border-radius:2px;background:#9db3d1}.archivev-name[data-type=directory]:before{background:#2d8f6f}.archivev-type,.archivev-size,.archivev-modified{width:16%;color:#5b6b81;white-space:nowrap}.pptxv-shell{--pptxv-panel: #ffffff;--pptxv-border: #d7dee8;--pptxv-border-strong: #9db3d1;--pptxv-text: #1f2937;--pptxv-muted: #5b6b81;--pptxv-accent: #2563eb;--pptxv-surface: #f3f6fa;display:flex;flex-direction:column;width:100%;height:var(--pptxv-height, clamp(520px, 78vh, 960px));min-height:480px;max-height:100%;color:var(--pptxv-text);background:var(--pptxv-panel);border:1px solid var(--pptxv-border);border-radius:0;overflow:hidden;font-family:system-ui,sans-serif}.pptxv-password-form{display:grid;gap:12px;width:min(340px,calc(100% - 40px));padding:24px;box-sizing:border-box;background:var(--pptxv-panel);border:1px solid var(--pptxv-border);color:var(--pptxv-text);text-align:left}.pptxv-password-form h2{margin:0;font-size:20px}.pptxv-password-form p{margin:0;font-size:14px}.pptxv-password-filename{overflow-wrap:anywhere}.pptxv-password-form label{font-size:14px}.pptxv-password-form input{min-width:0;padding:10px;border:1px solid var(--pptxv-border-strong);border-radius:4px;font:inherit}.pptxv-password-form input:focus-visible{outline:2px solid var(--pptxv-accent);outline-offset:2px}.pptxv-password-error{color:#b91c1c}.pptxv-password-actions{display:flex;justify-content:flex-end;gap:10px}.pptxv-shell:focus-visible{outline:2px solid rgba(37,99,235,.3);outline-offset:0}.pptxv-toolbar{display:flex;align-items:center;gap:12px;padding:10px 16px;border-bottom:1px solid var(--pptxv-border);background:#fff}.pptxv-toolbar-group{display:flex;align-items:center;gap:8px;flex:0 0 auto;min-width:0}.pptxv-toolbar-group+.pptxv-toolbar-group{flex:1 1 auto;justify-content:flex-end;overflow-x:auto;overscroll-behavior-x:contain;scrollbar-width:thin;scrollbar-gutter:stable}.pptxv-pill--hidden{visibility:hidden}.pptxv-layout{display:flex;min-height:0;flex:1;overflow:hidden}.pptxv-model-tools{display:flex;flex:0 0 auto;min-height:0}.pptxv-button.pptxv-model-tools-toggle{position:absolute;top:12px;left:12px;z-index:2;display:grid;place-items:center;width:34px;height:34px;padding:0}.pptxv-model-tools-toggle svg{width:20px;height:20px}.pptxv-sidebar{width:204px;flex:0 0 204px;padding:12px;overflow:auto;scrollbar-gutter:stable;scroll-behavior:smooth;scroll-snap-type:y proximity;border-right:1px solid var(--pptxv-border);background:#f6f8fb}.pptxv-meta-sidebar{width:240px;flex:0 0 240px}.pptxv-tree-sidebar{width:260px;flex:0 0 260px}.pptxv-meta-panel{display:grid;gap:10px}.pptxv-meta-heading{color:var(--pptxv-text);font:700 12px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-meta-muted{padding:10px;border:1px dashed var(--pptxv-border);color:var(--pptxv-muted);font:600 12px/1.35 system-ui,sans-serif}.pptxv-meta-list{display:grid;gap:8px;margin:0}.pptxv-material-list{display:grid;gap:8px}.pptxv-material-card{display:grid;gap:8px;padding:10px;border:1px solid var(--pptxv-border);background:#fff}.pptxv-material-card.is-active{border-color:var(--pptxv-accent);background:#eff6ff}.pptxv-material-title-copy{display:grid;gap:2px;min-width:0}.pptxv-material-title{display:flex;justify-content:space-between;gap:10px;align-items:flex-start}.pptxv-material-title strong,.pptxv-material-title span{min-width:0;overflow-wrap:anywhere}.pptxv-material-title strong{color:var(--pptxv-text);font:700 12px/1.35 system-ui,sans-serif}.pptxv-material-title span{color:var(--pptxv-muted);font:700 10px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-material-swatches{display:flex;gap:6px;flex-wrap:wrap;justify-content:flex-end}.pptxv-material-swatch{width:16px;min-width:16px;height:16px;border:1px solid rgba(15,23,42,.16);box-shadow:inset 0 0 0 1px #ffffff59}.pptxv-material-actions{display:flex;justify-content:flex-start}.pptxv-material-action,.pptxv-material-clear{min-width:96px}.pptxv-material-detail-list{display:grid;gap:6px;margin:0}.pptxv-material-detail-row{display:grid;gap:2px}.pptxv-material-detail-row dt{margin:0;color:var(--pptxv-muted);font:700 10px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-material-detail-row dd{margin:0;color:var(--pptxv-text);font:600 12px/1.35 system-ui,sans-serif;overflow-wrap:anywhere}.pptxv-meta-row{display:grid;gap:4px;padding:8px 10px;border:1px solid var(--pptxv-border);background:#fff}.pptxv-meta-row dt{margin:0;color:var(--pptxv-muted);font:700 11px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-meta-row dd{margin:0;color:var(--pptxv-text);font:600 12px/1.4 system-ui,sans-serif;overflow-wrap:anywhere}.pptxv-tree-reset{flex:1}.pptxv-tree-actions{display:flex;gap:8px}.pptxv-tree-search{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;align-items:center}.pptxv-tree-search-input{width:100%;min-width:0;height:32px;padding:0 10px;border:1px solid var(--pptxv-border);background:#fff;color:var(--pptxv-text);font:600 12px/1 system-ui,sans-serif}.pptxv-tree-search-clear{min-width:64px}.pptxv-tree-search-status{color:var(--pptxv-muted);font:700 11px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-tree-explode{display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:8px;align-items:center}.pptxv-tree-explode-label{color:var(--pptxv-muted);font:700 11px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-tree-explode-slider{width:100%;min-width:0;margin:0}.pptxv-tree-explode-value{min-width:58px;padding-inline:8px}.pptxv-tree-summary{display:flex;justify-content:space-between;gap:10px;padding:8px 10px;border:1px solid var(--pptxv-border);background:#f8fafc;color:var(--pptxv-text);font:600 12px/1.35 system-ui,sans-serif}.pptxv-tree-summary span,.pptxv-tree-summary strong{min-width:0;overflow-wrap:anywhere}.pptxv-tree-detail-list{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin:0}.pptxv-tree-empty{padding:10px;border:1px dashed var(--pptxv-border);color:var(--pptxv-muted);background:#fff;font:600 12px/1.35 system-ui,sans-serif}.pptxv-tree-detail-row{display:grid;gap:4px;padding:8px 10px;border:1px solid var(--pptxv-border);background:#fff}.pptxv-tree-detail-row dt{margin:0;color:var(--pptxv-muted);font:700 11px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-tree-detail-row dd{margin:0;color:var(--pptxv-text);font:600 12px/1.35 system-ui,sans-serif;overflow-wrap:anywhere}.pptxv-tree-list{display:grid;gap:6px}.pptxv-tree-row{display:grid;grid-template-columns:20px 16px minmax(0,1fr);gap:6px;align-items:stretch}.pptxv-tree-toggle,.pptxv-tree-spacer{width:20px;min-width:20px;height:100%}.pptxv-tree-toggle{border:1px solid var(--pptxv-border);background:#fff;color:var(--pptxv-muted);font:700 11px/1 system-ui,sans-serif;cursor:pointer}.pptxv-tree-spacer{display:block}.pptxv-tree-visibility{width:16px;height:16px;align-self:center;margin:0}.pptxv-tree-button{display:grid;gap:2px;width:100%;min-width:0;padding:8px 10px;border:1px solid var(--pptxv-border);background:#fff;color:var(--pptxv-text);text-align:left;cursor:pointer}.pptxv-tree-button.is-active{border-color:var(--pptxv-accent);background:#eff6ff}.pptxv-tree-button.is-hidden{opacity:.62}.pptxv-tree-topline{display:grid;grid-template-columns:20px minmax(0,1fr) auto;gap:8px;align-items:center}.pptxv-tree-badge{display:inline-flex;align-items:center;justify-content:center;min-width:20px;height:20px;border:1px solid var(--pptxv-border);background:#f8fafc;color:var(--pptxv-muted);font:700 10px/1 system-ui,sans-serif}.pptxv-tree-count{color:var(--pptxv-muted);font:700 11px/1 system-ui,sans-serif}.pptxv-tree-kind{color:var(--pptxv-muted);font:700 10px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-tree-label{color:var(--pptxv-text);font:600 12px/1.35 system-ui,sans-serif;overflow-wrap:anywhere}.pptxv-meta-heading-split{display:flex;justify-content:space-between;gap:10px;align-items:center}.pptxv-meta-heading-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px}.pptxv-meta-count{color:var(--pptxv-muted);font:700 11px/1 system-ui,sans-serif}.pptxv-measurement-controls{display:grid;gap:8px}.pptxv-measurement-group{display:grid;gap:6px}.pptxv-measurement-label{color:var(--pptxv-muted);font:700 11px/1 system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}.pptxv-measurement-buttons{display:flex;gap:6px;flex-wrap:wrap}.pptxv-section-header{display:flex;align-items:center;justify-content:space-between;gap:8px}.pptxv-section-value{color:var(--pptxv-text);font:700 12px/1 system-ui,sans-serif}.pptxv-section-slider{width:100%}.pptxv-section-range{display:flex;align-items:center;justify-content:space-between;gap:8px;color:var(--pptxv-muted);font:600 11px/1 system-ui,sans-serif;font-variant-numeric:tabular-nums}.pptxv-section-box{display:grid;gap:10px}.pptxv-main{flex:1;min-width:0;min-height:0;padding:0;overflow:hidden;background:var(--pptxv-surface);contain:layout paint}.pptxv-main-stage{position:relative;width:100%;height:100%;overflow:hidden}.pptxv-main-stage:after,.pptxv-main-view:fullscreen:after,.pptxv-main-view :fullscreen:after{content:\"FiLens © IceWhale\";position:absolute;right:12px;bottom:12px;z-index:10;padding:3px 6px;color:#33415599;background:#ffffff8c;border-radius:3px;font:500 12px/1.4 system-ui,sans-serif;white-space:nowrap;pointer-events:none;-webkit-user-select:none;user-select:none}.pptxv-main-view:fullscreen:after,.pptxv-main-view :fullscreen:after{position:fixed}.pptxv-main-view{width:100%;height:100%;min-height:420px;overflow:hidden}.pptxv-main-view.iworkv-root{overflow:auto}.pptxv-button{flex:0 0 auto;min-height:28px;border:1px solid var(--pptxv-border);border-radius:4px;padding:6px 12px;background:#fff;color:var(--pptxv-text);font:600 12px/1 system-ui,sans-serif;cursor:pointer;transition:border-color .12s ease,background-color .12s ease,color .12s ease}.pptxv-button.is-active{border-color:var(--pptxv-accent);background:#eff6ff;color:#1d4ed8}.pptxv-button:hover{border-color:var(--pptxv-border-strong);background:#f8fbff}.pptxv-button:disabled{cursor:not-allowed;opacity:.46}.pptxv-status{flex:0 0 96px;max-width:96px;text-align:center;font:600 12px/1 system-ui,sans-serif;color:var(--pptxv-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-variant-numeric:tabular-nums}.pptxv-pill{display:inline-flex;align-items:center;justify-content:center;min-height:26px;flex:0 0 92px;max-width:92px;padding:0 10px;border:1px solid #ead8a2;border-radius:4px;background:#fff9e8;color:#8a5b00;font:600 11px/1 system-ui,sans-serif;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-variant-numeric:tabular-nums}.pptxv-layer-menu{position:relative}.pptxv-layer-menu--hidden{visibility:hidden;pointer-events:none}.pptxv-layer-menu[open] .pptxv-layer-summary{border-color:var(--pptxv-accent);background:#f4f8ff}.pptxv-layer-summary{display:inline-flex;align-items:center;justify-content:center;width:132px;min-height:28px;list-style:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-variant-numeric:tabular-nums}.pptxv-layer-summary::-webkit-details-marker{display:none}.pptxv-layer-popover{position:absolute;z-index:20;top:calc(100% + 8px);left:0;width:min(260px,72vw);max-height:320px;overflow:auto;padding:8px;border:1px solid var(--pptxv-border);background:#fff;box-shadow:0 12px 28px #1f293724}.pptxv-layer-actions{display:flex;gap:6px;padding:0 0 8px;border-bottom:1px solid var(--pptxv-border);margin-bottom:6px}.pptxv-layer-action{min-height:26px;padding:0 10px;border:1px solid var(--pptxv-border);border-radius:4px;background:#fff;color:var(--pptxv-text);font:600 11px/1 system-ui,sans-serif;cursor:pointer}.pptxv-layer-row{display:grid;grid-template-columns:16px 14px minmax(0,1fr);align-items:center;gap:8px;min-height:30px;padding:3px 4px;color:var(--pptxv-text);font:600 12px/1.25 system-ui,sans-serif}.pptxv-layer-row input{width:14px;height:14px;margin:0}.pptxv-layer-color{width:12px;height:12px;border:1px solid rgba(31,41,55,.2)}.pptxv-layer-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.pptxv-thumb-button{display:flex;flex-direction:column;width:100%;margin-bottom:8px;padding:8px;border:1px solid var(--pptxv-border);border-radius:0;background:#fff;cursor:pointer;scroll-snap-align:start;content-visibility:auto;contain-intrinsic-size:0 220px;transition:border-color .12s ease,background-color .12s ease}.pptxv-thumb-button:hover{border-color:var(--pptxv-border-strong);background:#fbfdff}.pptxv-thumb-button.is-active{border-color:var(--pptxv-accent);box-shadow:inset 0 0 0 1px #2563eb1f}.pptxv-thumb-host{width:100%;border-radius:0}.pptxv-thumb-host.is-placeholder{position:relative;overflow:hidden;background:linear-gradient(90deg,#eef3f8,#fff,#eef3f8);background-size:200% 100%;animation:pptxv-thumb-shimmer 1.6s linear infinite}.pptxv-thumb-stage{overflow:hidden;border-radius:0;box-shadow:none}.pptxv-thumb-label{margin-top:6px;text-align:center;color:var(--pptxv-muted);font:600 12px/1 system-ui,sans-serif}.pptxv-overlay{position:absolute;top:12px;right:12px;bottom:12px;left:12px;display:flex;align-items:center;justify-content:center;padding:18px;border:1px solid var(--pptxv-border);border-radius:0;background:#fffffff5;color:var(--pptxv-text);text-align:center;font:600 14px/1.45 system-ui,sans-serif}.pptxv-overlay.is-error{border-color:#c436362e;background:#fff4f4eb;color:#8a1f1f}.pptxv-tabs{display:flex;gap:8px;padding:10px 16px;border-bottom:1px solid var(--pptxv-border);background:#fbfcfe;overflow:auto}.pptxv-tab{min-height:34px;padding:0 12px;border:1px solid var(--pptxv-border);background:#fff;color:var(--pptxv-text);font:600 12px/1 system-ui,sans-serif;white-space:nowrap;cursor:pointer}.pptxv-tab.is-active{border-color:var(--pptxv-accent);box-shadow:inset 0 0 0 1px #2563eb1f}@keyframes pptxv-thumb-shimmer{0%{background-position:200% 0}to{background-position:-200% 0}}@media (max-width: 900px){.pptxv-toolbar{flex-wrap:wrap}.pptxv-toolbar-group+.pptxv-toolbar-group{flex:0 1 100%;justify-content:flex-start}.pptxv-layout{flex-direction:column}.pptxv-model-tools{flex-direction:column;flex:0 1 auto;max-height:min(40vh,320px);overflow:auto}.pptxv-model-tools .pptxv-sidebar{box-sizing:border-box}.pptxv-sidebar{width:100%;flex:none;display:flex;gap:12px;overflow:auto;scrollbar-gutter:stable both-edges;scroll-snap-type:x proximity;border-right:0;border-bottom:1px solid var(--pptxv-border)}.pptxv-thumb-button{min-width:176px;margin-bottom:0}}.cadv-preview{box-sizing:border-box;width:100%;height:100%;min-height:320px;overflow:auto;background:linear-gradient(#eef3f8 1px,transparent 1px),linear-gradient(90deg,#eef3f8 1px,transparent 1px),#f8fafc;background-size:24px 24px;color:#223245}.cadv-stage{box-sizing:border-box;height:100%;min-width:100%;min-height:100%;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr);place-items:center;padding:32px}.cadv-canvas{width:100%;height:100%;max-width:min(100%,1200px);max-height:100%;overflow:visible;transform-origin:center center;filter:drop-shadow(0 8px 22px rgba(34,50,69,.12))}.cadv-canvas text{paint-order:stroke;stroke:#f8fafc;stroke-width:2px}.cadv-empty{padding:24px;border:1px solid #cfd8e3;background:#fff;font-weight:700}.diagramv-preview{box-sizing:border-box;width:100%;height:100%;min-height:0;overflow:auto;background:#f6f8fb;color:#1f2937;font-family:system-ui,sans-serif}.diagramv-summary{position:sticky;top:0;z-index:1;padding:12px 16px;border-bottom:1px solid #d7dee8;background:#fff;color:#5b6b81;font:700 12px/1 system-ui,sans-serif}.diagramv-canvas-wrap{margin:0}.diagramv-canvas{display:block;width:100%;height:100%}.diagramv-edge,.diagramv-node{cursor:pointer;outline:none}.diagramv-edge polyline{fill:none}.diagramv-edge text,.diagramv-node text{font:600 13px/1 system-ui,sans-serif;text-anchor:middle;pointer-events:none}.diagramv-edge text{text-anchor:start}.diagramv-edge:hover polyline,.diagramv-edge:focus-visible polyline{stroke:#2563eb}.diagramv-node:hover rect,.diagramv-node:hover ellipse,.diagramv-node:hover polygon,.diagramv-node:focus-visible rect{stroke:#2563eb}.diagramv-node:focus-visible ellipse,.diagramv-node:focus-visible polygon{stroke:#2563eb}.diagramv-edge.is-selected polyline{stroke:#2d8f6f;stroke-width:3}.diagramv-node.is-selected rect{fill:#ecfdf5;stroke:#2d8f6f;stroke-width:2}.diagramv-node.is-selected ellipse,.diagramv-node.is-selected polygon{fill:#ecfdf5;stroke:#2d8f6f;stroke-width:2}.mindmapv-preview{box-sizing:border-box;width:100%;height:100%;min-height:0;overflow:auto;background:#f6f8fb;color:#1f2937;font-family:system-ui,sans-serif}.mindmapv-summary{position:sticky;top:0;z-index:1;padding:12px 16px;border-bottom:1px solid #d7dee8;background:#fff;color:#5b6b81;font:700 12px/1 system-ui,sans-serif}.mindmapv-canvas-wrap{margin:0}.mindmapv-canvas{display:block;width:100%;height:100%}.mindmapv-links path{fill:none;stroke:#9db3d1;stroke-width:2}.mindmapv-node{cursor:pointer;outline:none}.mindmapv-node rect{fill:#fff;stroke:#9db3d1;stroke-width:1.4}.mindmapv-node text{fill:#1f2937;font:600 13px/1 system-ui,sans-serif;pointer-events:none}.mindmapv-node:hover rect,.mindmapv-node:focus-visible rect{stroke:#2563eb}.mindmapv-node.is-selected rect{fill:#ecfdf5;stroke:#2d8f6f;stroke-width:2}.model3dv-preview{width:100%;height:100%;min-height:420px;position:relative;overflow:hidden;background:#111827}.model3dv-stage{width:100%;height:100%;min-height:inherit;cursor:grab;touch-action:none}.model3dv-stage:active{cursor:grabbing}.model3dv-canvas{display:block;width:100%;height:100%}.model3dv-hint{position:absolute;left:14px;bottom:14px;padding:7px 10px;border:1px solid rgba(255,255,255,.16);background:#111827b8;color:#e5edf8;font:600 12px/1 system-ui,sans-serif;pointer-events:none}.panoramav-preview{position:relative;box-sizing:border-box;width:100%;height:100%;min-height:360px;overflow:hidden;background:#111827;color:#f8fafc;font-family:system-ui,sans-serif}.panoramav-stage{width:100%;height:100%;min-height:inherit;overflow:hidden}.panoramav-canvas{display:block;width:100%;height:100%;touch-action:none;cursor:grab}.panoramav-canvas:active{cursor:grabbing}.panoramav-hint{position:absolute;left:14px;bottom:14px;padding:7px 10px;border:1px solid rgba(255,255,255,.18);background:#111827b8;color:#f8fafc;font-size:12px;font-weight:700;pointer-events:none}.panoramav-notice{position:absolute;top:14px;right:14px;left:14px;z-index:2;padding:9px 12px;border:1px solid rgba(251,191,36,.5);background:#451a03e0;color:#fef3c7;font-size:12px;line-height:1.45}.panoramav-view-controls{position:absolute;top:14px;right:12px;z-index:2;display:flex;gap:2px;padding:5px;border:1px solid rgba(255,255,255,.16);border-radius:24px;background:#141821db;-webkit-backdrop-filter:blur(16px);backdrop-filter:blur(16px)}.panoramav-preview.pptxv-has-video-controls .panoramav-hint{bottom:114px;border-radius:8px;font-weight:400}.panoramav-preview.pptxv-has-video-controls .panoramav-notice{top:76px}.panoramav-video-source{display:none}@container (max-width: 420px){.panoramav-preview.pptxv-has-video-controls .panoramav-hint{display:none}}.docxv-preview{box-sizing:border-box;width:100%;height:100%;min-height:360px;overflow:auto;padding:24px;background:#eef2f7}.docxv-document{box-sizing:border-box;min-height:100%}.docxv-document .docx-wrapper{background:transparent;padding:0}.docxv-document .docx{margin:0 auto 16px;box-shadow:0 1px 4px #0f172a2e;content-visibility:auto;contain-intrinsic-size:816px 1056px}.xlsxv-preview{box-sizing:border-box;width:100%;height:100%;min-height:360px;overflow:hidden;background:#f8fafc;color:#172033;font-family:system-ui,sans-serif}.xlsxv-sheet-tabs{display:flex;gap:4px;min-height:36px;padding:6px 8px;overflow-x:auto;border-bottom:1px solid #d8dee8;background:#eef2f7}.xlsxv-sheet-tab{min-width:64px;height:24px;border:1px solid #c9d2df;border-radius:4px;background:#fff;color:#2f3b52;font:600 12px/1 system-ui,sans-serif;cursor:pointer}.xlsxv-sheet-tab.is-active{border-color:#2f6bff;color:#1d4fd7}.xlsxv-grid{height:calc(100% - 36px);overflow:auto}.xlsxv-table{border-collapse:collapse;min-width:100%;background:#fff;table-layout:fixed}.xlsxv-corner,.xlsxv-row-header,.xlsxv-col-header,.xlsxv-cell{box-sizing:border-box;height:26px;border:1px solid #d8dee8;padding:4px 8px;font-size:12px;line-height:1.3}.xlsxv-corner,.xlsxv-row-header,.xlsxv-col-header{position:sticky;z-index:2;background:#eef2f7;color:#526070;font-weight:600;text-align:center}.xlsxv-corner,.xlsxv-row-header{left:0;min-width:48px}.xlsxv-corner,.xlsxv-col-header{top:0}.xlsxv-corner{z-index:3}.xlsxv-cell{min-width:96px;max-width:240px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;vertical-align:top}.iworkv-root{position:relative;width:100%;height:100%;overflow:auto;background:#dde3ea;color:#1f2937}.iworkv-root.is-loading:before,.iworkv-root.is-error:before{position:absolute;top:0;right:0;bottom:0;left:0;display:grid;place-items:center;background:#dde3eab8;z-index:10;font:600 14px/1.4 system-ui,sans-serif;content:attr(data-status)}.iworkv-stage{min-height:100%;padding:16px;box-sizing:border-box}.iworkv-stage.iworkv-numbers-stage{height:100%;padding:0}.iworkv-numbers-tables{display:grid;gap:24px;padding:16px}.iworkv-numbers-table-title{margin:0 0 8px;color:#526070;font:600 12px/1.3 system-ui,sans-serif}.iworkv-numbers-table{content-visibility:auto}.iworkv-cell-image{display:block;width:100%;max-height:180px;margin-bottom:4px;object-fit:contain}.iworkv-numbers-objects{overflow:auto}.iworkv-numbers-objects .iworkv-page-shell{box-shadow:none}.iworkv-pages{display:grid;gap:18px;justify-content:center}.iworkv-page-shell{position:relative;background:#fff;box-shadow:0 10px 40px #0f172a24}.iworkv-sheet-shell{position:relative;background:linear-gradient(180deg,#f7fafc,#edf2f7);border:1px solid #d6dee8}.pdfv-preview{position:relative;box-sizing:border-box;display:grid;grid-template-columns:minmax(0,1fr);justify-items:center;align-content:start;gap:16px;width:100%;height:100%;min-height:360px;background:#fff;overflow:auto}.pdfv-page-slot{justify-self:start;margin-inline:auto}.pdfv-page{box-sizing:border-box;display:block;border:1px solid #d7dee8;background:#fff}.pptxv-viewer{position:relative;display:flex;width:100%;height:100%;min-height:320px;background:#e6e9ef;overflow:hidden}.pptxv-scroll-area{flex:1;overflow:auto;padding:12px;scroll-behavior:smooth;scroll-padding:12px;scroll-snap-type:y proximity}.pptxv-loading{display:flex;align-items:center;justify-content:center;min-height:240px;color:#395170;font:600 15px/1.4 system-ui,sans-serif}.pptxv-loading--error{color:#8a1f1f}.pptxv-slide-shell{position:relative;contain:layout style;margin:0 auto 18px;scroll-snap-align:start}.pptxv-slide-stage{position:relative;border-radius:0;box-shadow:none;overflow:hidden}.pptxv-slide{position:relative;overflow:hidden;font-family:system-ui,sans-serif}.pptxv-slide--thumbnail{box-shadow:none}.pptxv-item{box-sizing:border-box}.pptxv-item--table,.pptxv-item--chart,.pptxv-item--unsupported{overflow:hidden}.pptxv-item--shape,.pptxv-item--media{overflow:visible}.pptxv-shape-svg{display:block;overflow:visible}.pptxv-text-frame{display:flex;flex-direction:column;width:100%;height:100%;box-sizing:border-box}.pptxv-shape-text{display:block;width:auto;height:auto;box-sizing:border-box}.pptxv-paragraph{margin:0;line-height:1;word-break:normal;overflow-wrap:break-word}.pptxv-run{white-space:pre-wrap}.pptxv-run--tab{display:inline-block;white-space:pre;min-width:4px}.pptxv-run--link{color:inherit;text-decoration-line:underline;text-decoration-color:currentcolor;text-underline-offset:.08em}.pptxv-item-link{cursor:pointer}.pptxv-item-link:focus-visible{outline:none;box-shadow:inset 0 0 0 2px #2f6bffd1,inset 0 0 0 4px #ffffffc2}.pptxv-run--bullet{display:inline-block;min-width:1.2em}.pptxv-run--bullet-auto{min-width:2.4em}.pptxv-image{display:block;-webkit-user-select:none;user-select:none}.pptxv-media-stage{position:absolute;top:0;right:0;bottom:0;left:0;overflow:hidden;background:transparent}.pptxv-media-poster-frame{position:absolute}.pptxv-media-poster,.pptxv-media-player{display:block}.pptxv-media-poster{-webkit-user-select:none;user-select:none;pointer-events:none}.pptxv-media-player--video{background:transparent}.pptxv-media-player--audio{min-width:220px}.pptxv-table{width:100%;height:100%;border-collapse:collapse;table-layout:fixed;background:transparent}.pptxv-table-cell{border:0 solid transparent;vertical-align:top;padding:0}.pptxv-chart-svg{display:block;width:100%;height:100%;overflow:hidden;font-family:Aptos,Calibri,Segoe UI,sans-serif}.pptxv-chart-title,.pptxv-chart-axis-label,.pptxv-chart-category-label,.pptxv-chart-legend{fill:#595959;font-weight:400}.pptxv-chart-gridline{stroke:#bfbfbf;stroke-width:1}.pptxv-chart-axis{stroke:#000;stroke-width:1.25}.pptxv-item--unsupported{display:flex;align-items:center;justify-content:center;border:1px dashed rgba(57,81,112,.35);background:#ffffffb8;color:#395170;font:600 12px/1.3 system-ui,sans-serif}.pptxv-native-preview{box-sizing:border-box;width:100%;height:100%;min-height:280px;font-family:system-ui,sans-serif}.pptxv-native-preview--image,.pptxv-native-preview--video,.pptxv-native-preview--audio{display:flex;align-items:center;justify-content:center;overflow:auto;padding:16px;background:#151923}.pptxv-native-preview--image{cursor:grab;touch-action:none}.pptxv-native-preview--image.is-panning{cursor:grabbing}.pptxv-native-preview--audio{background:radial-gradient(ellipse at 12% 10%,#e3eadd,transparent 65%),#f2f0eb;flex-direction:column;padding:clamp(16px,4%,48px);justify-content:safe center;container-type:inline-size}.pptxv-native-image{display:block;width:auto;height:auto;transform-origin:center center;-webkit-user-select:none;user-select:none}.pptxv-native-media{display:block;max-width:100%}.pptxv-native-media--video{max-height:100%;background:#000}.pptxv-has-video-controls{position:relative;container-type:inline-size;outline:none}.pptxv-native-preview--video.pptxv-has-video-controls{overflow:hidden;padding:0 0 110px;background:#11151c}.pptxv-has-video-controls:fullscreen{width:100%;height:100%}.pptxv-video-controls{position:absolute;right:12px;bottom:max(12px,env(safe-area-inset-bottom));left:12px;z-index:3;box-sizing:border-box;max-width:880px;margin:0 auto;padding:10px 14px 8px;border:1px solid rgba(255,255,255,.18);border-radius:20px;background:#141821e0;color:#f8fafc;font:13px/1.4 system-ui,sans-serif;-webkit-backdrop-filter:blur(16px);backdrop-filter:blur(16px);box-shadow:0 6px 24px #0003}.pptxv-video-control-row{display:flex;align-items:center;gap:4px;min-width:0}.pptxv-video-controls button,.panoramav-view-controls button{display:inline-flex;align-items:center;justify-content:center;flex:0 0 36px;box-sizing:border-box;width:36px;height:36px;padding:7px;border:0;border-radius:50%;background:transparent;color:#f8fafc;cursor:pointer;touch-action:manipulation}.pptxv-video-controls button:hover,.panoramav-view-controls button:hover{background:#ffffff24}.pptxv-video-controls button:disabled,.panoramav-view-controls button:disabled{opacity:.4;cursor:default}.pptxv-video-controls :focus-visible,.panoramav-view-controls button:focus-visible,.pptxv-has-video-controls:focus-visible{outline:2px solid #9ec5ff;outline-offset:2px}.pptxv-video-time{flex-shrink:0;margin-left:5px;color:#e5e7eb;font:inherit;font-variant-numeric:tabular-nums;white-space:nowrap}.pptxv-video-control-spacer{flex:1}.pptxv-video-controls input[type=range]{min-width:0;padding:0;border:0;border-radius:2px;accent-color:#f8fafc;cursor:pointer;touch-action:pan-y}.pptxv-video-controls .pptxv-video-timeline{display:block;width:100%;height:18px;margin:0 0 4px;-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent}.pptxv-video-timeline::-webkit-slider-runnable-track{height:4px;border-radius:2px;background:linear-gradient(to right,#f8fafc var(--pptxv-video-progress, 0%),#ffffff40 var(--pptxv-video-progress, 0%))}.pptxv-video-timeline::-webkit-slider-thumb{width:12px;height:12px;margin-top:-4px;border-radius:50%;background:#fff;-webkit-appearance:none;-moz-appearance:none;appearance:none}.pptxv-video-timeline::-moz-range-track{height:4px;border-radius:2px;background:#ffffff40}.pptxv-video-timeline::-moz-range-progress{height:4px;background:#f8fafc}.pptxv-video-timeline::-moz-range-thumb{width:12px;height:12px;border:0;border-radius:50%;background:#fff}.pptxv-video-volume{display:flex;align-items:center;gap:4px}.pptxv-video-volume input{width:68px}.pptxv-video-rate{height:36px;padding:0 4px;border:0;border-radius:8px;background:transparent;color:#f8fafc;font:inherit;cursor:pointer}.pptxv-video-rate option{background:#202632;color:#f8fafc}.pptxv-video-captions{max-width:84px}.pptxv-video-controls [hidden]{display:none}@container (max-width: 540px){.pptxv-video-volume input{display:none}}@container (max-width: 420px){.pptxv-video-controls{right:8px;left:8px;padding:8px;border-radius:16px}.pptxv-video-controls .pptxv-video-skip,.pptxv-video-controls .pptxv-video-pip{display:none}.pptxv-video-captions{max-width:44px}.pptxv-video-control-row{gap:2px}.pptxv-video-time{margin-left:0;font-size:11px}}.pptxv-native-media--audio{width:min(640px,100%)}.pptxv-native-audio-cover{display:block;position:absolute;top:0;right:0;bottom:0;left:0;z-index:1;width:100%;height:100%;object-fit:cover;border-radius:inherit}.pptxv-audio-player{--audio-accent: #40634c;box-sizing:border-box;width:min(880px,100%);flex-shrink:0;margin:auto;color:#283c32;background:#fffefa;border:1px solid #d7dbd0;border-radius:22px;box-shadow:0 16px 56px #243b2c0c;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;overflow:hidden}.pptxv-audio-player button,.pptxv-audio-player select{font:inherit;cursor:pointer;color:inherit}.pptxv-audio-player button:focus-visible,.pptxv-audio-player select:focus-visible,.pptxv-audio-lyrics:focus-visible{outline:2px solid var(--audio-accent);outline-offset:3px}.pptxv-audio-body{display:grid;grid-template-columns:minmax(0,.85fr) minmax(0,1.15fr);gap:clamp(24px,5%,56px);padding:clamp(24px,5%,44px)}.pptxv-audio-album{min-width:0}.pptxv-audio-artwork{position:relative;aspect-ratio:1;width:100%;max-width:280px;margin-bottom:26px;border-radius:14px;background:#45644e;box-shadow:0 10px 24px #223b3026;isolation:isolate}.pptxv-audio-placeholder{display:grid;place-items:center;height:100%;overflow:hidden;border-radius:inherit;background:radial-gradient(circle at 25% 15%,#9cab7c,transparent 50%),linear-gradient(145deg,#526c53,#1f3c37)}.pptxv-audio-placeholder span{display:grid;place-items:center;width:66%;aspect-ratio:1;border:1px solid #ffffff30;border-radius:50%;box-shadow:0 0 0 15px #ffffff06,0 0 0 30px #ffffff06;color:#e8e8cd;font-size:52px}.pptxv-audio-play{position:absolute;z-index:2;right:14px;bottom:14px;display:grid;place-items:center;width:48px;height:48px;padding:0;border:1px solid #ffffffa0;border-radius:50%;color:#293f32!important;background:#fffef4ee;box-shadow:0 4px 16px #0002}.pptxv-audio-play:hover{background:#fff;transform:scale(1.04)}.pptxv-audio-eyebrow{margin:0 0 10px;color:#697c63;font-size:10px;letter-spacing:.16em}.pptxv-audio-eyebrow:before{content:\"\";display:inline-block;width:6px;height:6px;margin-right:7px;border-radius:50%;background:#a7b19b}.is-playing .pptxv-audio-eyebrow:before{background:#52835b;box-shadow:0 0 0 4px #52835b18}.pptxv-audio-title{margin:0 0 8px;font-size:clamp(19px,2.4cqw,25px);font-weight:600;line-height:1.4;overflow-wrap:anywhere}.pptxv-audio-details{margin:0 0 18px;color:#6c756b;font-size:12px;line-height:1.6;overflow-wrap:anywhere}.pptxv-audio-import{padding:6px 10px;border:1px solid #dce0d4;border-radius:6px;background:transparent;font-size:11px!important}.pptxv-audio-import:hover{border-color:#95a48c;background:#f3f5ed}.pptxv-audio-lyric-panel{min-width:0;display:flex;flex-direction:column}.pptxv-audio-lyric-header{display:flex;justify-content:space-between;align-items:center;gap:12px;padding-bottom:14px;border-bottom:1px solid #e8e9e1}.pptxv-audio-lyric-header h3{margin:0;color:#6c756b;font-size:12px;font-weight:500;letter-spacing:.06em}.pptxv-audio-lyrics{position:relative;flex:1 0 auto;height:280px;max-height:340px;overflow:auto;overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:#cbd1c3 transparent;margin-top:12px;padding:40px 0;box-sizing:border-box}.pptxv-audio-lyrics.is-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;color:#7b8375;gap:12px}.pptxv-audio-empty-icon{font-size:42px;color:#a0ae93}.pptxv-audio-lyrics.is-empty p{margin:0;font-size:14px}.pptxv-audio-lyrics.is-empty small{color:#7b8375;font-size:11px;line-height:1.7}.pptxv-audio-lyric{display:block;width:100%;padding:12px 10px;margin:0;border:0;border-left:2px solid transparent;border-radius:0 6px 6px 0;background:transparent;color:#7c8378!important;text-align:left;font-size:14px!important;line-height:1.8;white-space:pre-line;overflow-wrap:anywhere;transition:color .18s,background .18s}.pptxv-audio-lyric:hover{color:#40634c!important;background:#f4f5ee}.pptxv-audio-lyric.is-active{border-left-color:var(--audio-accent);color:#304e39!important;background:#eff3e9;font-weight:600}.pptxv-audio-timing{display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:12px;color:#6c756b;font-size:10px}.pptxv-audio-timing[hidden]{display:none}.pptxv-audio-timing button{padding:4px 7px;border:1px solid #e0e3d8;border-radius:4px;background:transparent}.pptxv-audio-timing output{min-width:38px;text-align:center;font-variant-numeric:tabular-nums}.pptxv-audio-status{margin:10px 0 0;color:#707969;font-size:11px;line-height:1.6}.pptxv-audio-status:empty{display:none}.pptxv-audio-footer{display:flex;align-items:center;gap:14px;padding:16px 24px;background:#f3f5ee;border-top:1px solid #e2e6d9}.pptxv-audio-footer audio{width:100%;min-width:0;height:44px;flex:1}.pptxv-audio-extras{display:flex;align-items:center;gap:10px}.pptxv-audio-repeat{width:30px;height:30px;border:1px solid transparent;border-radius:50%;background:transparent;font-size:22px!important}.pptxv-audio-repeat[aria-pressed=true]{color:#355d3e;border-color:#cad7bf;background:#e1ead7}.pptxv-audio-speed{max-width:68px;padding:4px;border:0;border-radius:4px;background:transparent;font-size:12px!important}@container (max-width: 560px){.pptxv-audio-body{grid-template-columns:minmax(0,1fr);gap:24px;padding:24px}.pptxv-audio-album{display:grid;grid-template-columns:112px minmax(0,1fr);column-gap:18px;align-content:center}.pptxv-audio-artwork{width:112px;grid-row:span 4;margin:0}.pptxv-audio-eyebrow{margin-bottom:6px;font-size:9px}.pptxv-audio-title{font-size:18px}.pptxv-audio-details{margin-bottom:10px;font-size:11px}.pptxv-audio-play{width:36px;height:36px;right:8px;bottom:8px}.pptxv-audio-placeholder span{font-size:28px}.pptxv-audio-lyrics{flex:none;height:230px}.pptxv-audio-footer{flex-wrap:wrap;gap:6px;padding:12px}.pptxv-audio-footer audio{flex-basis:100%}.pptxv-audio-extras{margin-left:auto}}@media (prefers-reduced-motion: reduce){.pptxv-audio-player *{transition:none!important}}.pptxv-native-preview--text{overflow:auto;background:#f8fafc}.pptxv-native-preview--html{overflow:hidden;background:#fff}.pptxv-native-html-frame{display:block;width:100%;height:100%;min-height:inherit;border:0;background:#fff}.pptxv-native-text-shell{box-sizing:border-box;min-width:100%;min-height:100%;padding:18px}.pptxv-native-text-body{display:grid;grid-template-columns:auto minmax(0,1fr);align-items:start;min-width:max-content}.pptxv-native-text-gutter{box-sizing:border-box;position:sticky;left:0;z-index:1;white-space:pre;min-width:3.25rem;padding-right:14px;color:#64748b;background:#f8fafc;border-right:1px solid rgba(100,116,139,.2);font:13px/1.55 Consolas,SFMono-Regular,Liberation Mono,Menlo,monospace;text-align:right;-webkit-user-select:none;user-select:none}.pptxv-native-text{box-sizing:border-box;min-width:100%;margin:0;padding-left:14px;color:#1f2937;font:13px/1.55 Consolas,SFMono-Regular,Liberation Mono,Menlo,monospace;-moz-tab-size:2;tab-size:2;white-space:pre-wrap;overflow-wrap:anywhere}.pptxv-native-text[data-wrap=false]{white-space:pre;overflow-wrap:normal}.pptxv-native-text-shell[data-family=code]{color-scheme:dark;background:#0b1220}.pptxv-native-text-shell[data-family=code] .pptxv-native-text-gutter{color:#607089;background:#0b1220;border-right-color:#94a3b82e}.pptxv-native-text[data-family=code]{color:#d7e0ec}.pptxv-token--comment{color:#6f8f72;font-style:italic}.pptxv-token--keyword{color:#f08fc5}.pptxv-token--literal{color:#79b8ff}.pptxv-token--string{color:#e7a873}.pptxv-token--number{color:#a8d58d}.pptxv-token--property{color:#8bd5ff}.pptxv-token--tag,.pptxv-token--type{color:#67d4c0}.pptxv-token--function{color:#e8d17a}.pptxv-token--operator{color:#b9c5d6}.filens-attachments-shell,.filens-attachment-panel{display:flex;flex-direction:column;width:100%;height:100%;min-height:0;overflow:hidden}.filens-attachments-document,.filens-attachment-preview{flex:1;min-height:0;overflow:hidden}.filens-attachments-shell [hidden]{display:none!important}.filens-attachments,.filens-attachment-navigation{flex-shrink:0;box-sizing:border-box;padding:10px 14px;border-bottom:1px solid #d7dee8;background:#f8fafc;color:#1f2937;font:14px/1.4 system-ui,sans-serif}.filens-attachments summary{cursor:pointer}.filens-attachments ul{max-height:180px;overflow:auto;margin:8px 0 0;padding:0;list-style:none}.filens-attachments li,.filens-attachment-navigation{display:flex;gap:10px;align-items:center;flex-wrap:wrap}.filens-attachment-navigation span{overflow-wrap:anywhere;flex:1}.filens-attachments button,.filens-attachment-navigation button{font:inherit;color:inherit;padding:5px 10px;border:1px solid #cbd5e1;border-radius:4px;background:#fff;cursor:pointer}.filens-attachments li button:first-child{text-align:left;overflow-wrap:anywhere}.filens-attachment-status{margin:12px 16px;font:14px/1.5 system-ui,sans-serif}.filens-attachment-status[role=alert]{color:#b91c1c}.ebookv-preview{box-sizing:border-box;display:grid;grid-template-columns:220px minmax(0,1fr);width:100%;height:100%;min-height:360px;overflow:hidden;background:#f5f7fb;color:#1f2937;font-family:system-ui,sans-serif}.ebookv-chapters{overflow:auto;border-right:1px solid #d7dee8;background:#fff}.ebookv-chapter-tab{display:block;width:100%;min-height:38px;padding:10px 12px;border:0;border-bottom:1px solid #e5ebf2;background:transparent;color:#39485c;text-align:left;font:600 12px/1.35 system-ui,sans-serif;cursor:pointer}.ebookv-chapter-tab:hover{background:#f6f9fd}.ebookv-chapter-tab.is-active{background:#eaf2ff;color:#1f4f94}.ebookv-stage{min-width:0;min-height:0;overflow:hidden;background:#fff}.ebookv-frame{display:block;width:100%;height:100%;min-height:inherit;border:0;background:#fff}@media (max-width: 760px){.ebookv-preview{grid-template-columns:1fr;grid-template-rows:auto minmax(0,1fr)}.ebookv-chapters{display:flex;gap:0;overflow-x:auto;border-right:0;border-bottom:1px solid #d7dee8}.ebookv-chapter-tab{width:auto;min-width:160px;border-right:1px solid #e5ebf2}}\n";document.head.append(s);}
2
- import"./chunks/vendor-CBCxJuSg.js";import{c as s}from"./chunks/index-DI_GyFX1.js";import"./chunks/panorama-CIdiLIwD.js";import{u as t,s as a}from"./chunks/core-BLayEJn5.js";export{s as createPreview,t as isArchiveVolumeName,a as selectArchiveVolumes};
2
+ import"./chunks/vendor-C1aIdQ-w.js";import{c as s}from"./chunks/index-C4jdVbDq.js";import"./chunks/panorama-ChsqnvWC.js";import{u as t,s as a}from"./chunks/core-EjELrtsP.js";export{s as createPreview,t as isArchiveVolumeName,a as selectArchiveVolumes};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "filens-preview",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Browser-local document and media previews, as split modules or one main JS with an optional external archive engine.",
@@ -1,55 +0,0 @@
1
- var Gn=Object.defineProperty;var Un=(n,e,t)=>e in n?Gn(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var M=(n,e,t)=>Un(n,typeof e!="symbol"?e+"":e,t);import{c as _n,o as Vn}from"./core-BLayEJn5.js";import{L as Ne,M as V,b as ne,F as et,S as $n,C as de,V as E,d as ee,e as en,R as tn,B as Y,g as ie,h as Q,j as $,k as Wn,l as at,P as we,m as yt,E as vt,A as xt,D as Oe,n as te,o as Mt,O as Kn,p as Z,q as _e,r as Pe,t as me,v as Yn,w as Ve,x as Te,y as Ee,z as St,H as fe,I as Xn,K as Zn,N as nn,Q as qn,T as Jn,W as Qn,X as er,Y as tr,Z as nr,_ as rr,$ as sr,a0 as ir,a1 as ar,a2 as or,a3 as lr,a4 as cr,a5 as ur,a6 as dr,a7 as hr,a8 as mr,J as fr,a9 as pr,aa as gr,ab as wr}from"./vendor-CBCxJuSg.js";import{c as br}from"./panorama-CIdiLIwD.js";const Ct=0,Pt=1,Lt=2,Et=3,Ft=4,At=5,$e=0,yr=1,vr=2,xr=3,Mr=4,Sr=5,Dt=6,ae="16",ve="24",ke=$n,He=new E,je=new E;class Cr extends Q{constructor(e,t){super(e,t),this.isConditionalLine=true}}function Pr(n){for(let e=0,t=n.length;e<t;e++){const r=n[e],s=r.vertices,i=s[0],a=s[1],o=s[2];He.subVectors(a,i),je.subVectors(o,a),r.faceNormal=new E().crossVectors(He,je).normalize()}}const Nt=new tn;function Lr(n,e,t=false){const r=100.00000001000001;function s(f){const m=~~(f.x*r),g=~~(f.y*r),w=~~(f.z*r);return`${m},${g},${w}`}function i(f,m){return`${s(f)}_${s(m)}`}function a(f,m,g){g.direction.subVectors(m,f).normalize();const w=f.dot(g.direction);return g.origin.copy(f).addScaledVector(g.direction,-w),g}function o(f){return i(f.origin,f.direction)}const u=new Set,l=new Map,c=new Map,d=[];for(let f=0,m=e.length;f<m;f++){const w=e[f].vertices,p=w[0],b=w[1];if(u.add(i(p,b)),u.add(i(b,p)),t){const y=a(p,b,new tn),C=o(y);if(!l.has(C)){a(b,p,y);const k=o(y),D={ray:y,distances:[]};l.set(C,D),l.set(k,D)}const P=l.get(C);let S=P.ray.direction.dot(p),L=P.ray.direction.dot(b);S>L&&([S,L]=[L,S]),P.distances.push(S,L)}}for(let f=0,m=n.length;f<m;f++){const g=n[f],w=g.vertices,p=w.length;for(let b=0;b<p;b++){const y=b,C=(b+1)%p,P=w[y],S=w[C],L=i(P,S);if(u.has(L))continue;if(t){a(P,S,Nt);const D=o(Nt);if(l.has(D)){const N=l.get(D),{ray:v,distances:O}=N;let A=v.direction.dot(P),x=v.direction.dot(S);A>x&&([A,x]=[x,A]);let z=false;for(let H=0,U=O.length;H<U;H+=2)if(A>=O[H]&&x<=O[H+1]){z=true;break}if(z)continue}}const k={index:y,tri:g};c.set(L,k)}}const h=c.values();for(;;){const f=h.next().value;if(f===void 0)break;const m=[f];for(;m.length>0;){const g=m.pop().tri,w=g.vertices,p=g.normals,b=g.faceNormal,y=w.length;for(let C=0;C<y;C++){const P=C,S=(C+1)%y,L=w[P],k=w[S],D=i(L,k);c.delete(D);const N=i(k,L),v=c.get(N);if(v){const O=v.tri,A=v.index,x=O.normals,z=x.length,H=O.faceNormal;if(Math.abs(O.faceNormal.dot(g.faceNormal))<.25)continue;c.has(N)&&(m.push(v),c.delete(N));const U=(A+1)%z;p[P]&&x[U]&&p[P]!==x[U]&&(x[U].norm.add(p[P].norm),p[P].norm=x[U].norm);let I=p[P]||x[U];I===null&&(I={norm:new E},d.push(I.norm)),p[P]===null&&(p[P]=I,I.norm.add(b)),x[U]===null&&(x[U]=I,I.norm.add(H)),p[S]&&x[A]&&p[S]!==x[A]&&(x[A].norm.add(p[S].norm),p[S].norm=x[A].norm);let B=p[S]||x[A];B===null&&(B={norm:new E},d.push(B.norm)),p[S]===null&&(p[S]=B,B.norm.add(b)),x[A]===null&&(x[A]=B,B.norm.add(H))}}}}for(let f=0,m=d.length;f<m;f++)d[f].normalize()}function Ot(n){return n==="Part"||n==="Unofficial_Part"}function Er(n){return/primitive/i.test(n)||n==="Subpart"}class Se{constructor(e,t){this.line=e,this.lineLength=e.length,this.currentCharIndex=0,this.currentChar=" ",this.lineNumber=t}seekNonSpace(){for(;this.currentCharIndex<this.lineLength;){if(this.currentChar=this.line.charAt(this.currentCharIndex),this.currentChar!==" "&&this.currentChar!==" ")return;this.currentCharIndex++}}getToken(){const e=this.currentCharIndex++;for(;this.currentCharIndex<this.lineLength&&(this.currentChar=this.line.charAt(this.currentCharIndex),!(this.currentChar===" "||this.currentChar===" "));)this.currentCharIndex++;const t=this.currentCharIndex;return this.seekNonSpace(),this.line.substring(e,t)}getVector(){return new E(parseFloat(this.getToken()),parseFloat(this.getToken()),parseFloat(this.getToken()))}getRemainingString(){return this.line.substring(this.currentCharIndex,this.lineLength)}isAtTheEnd(){return this.currentCharIndex>=this.lineLength}setToEnd(){this.currentCharIndex=this.lineLength}getLineNumberString(){return this.lineNumber>=0?" at line "+this.lineNumber:""}}class Fr{constructor(e){this.loader=e,this._cache={}}cloneResult(e){const t={};return t.faces=e.faces.map(r=>({colorCode:r.colorCode,material:r.material,vertices:r.vertices.map(s=>s.clone()),normals:r.normals.map(()=>null),faceNormal:null})),t.conditionalSegments=e.conditionalSegments.map(r=>({colorCode:r.colorCode,material:r.material,vertices:r.vertices.map(s=>s.clone()),controlPoints:r.controlPoints.map(s=>s.clone())})),t.lineSegments=e.lineSegments.map(r=>({colorCode:r.colorCode,material:r.material,vertices:r.vertices.map(s=>s.clone())})),t.type=e.type,t.category=e.category,t.keywords=e.keywords,t.author=e.author,t.subobjects=e.subobjects,t.fileName=e.fileName,t.totalFaces=e.totalFaces,t.startingBuildingStep=e.startingBuildingStep,t.materials=e.materials,t.group=null,t}async fetchData(e){let t=false,r=$e;for(;r!==Dt;){let s=e;switch(r){case xr:r=r+1;break;case $e:s="parts/"+s,r=r+1;break;case yr:s="p/"+s,r=r+1;break;case vr:s="models/"+s,r=r+1;break;case Mr:s=e.substring(0,e.lastIndexOf("/")+1)+s,r=r+1;break;case Sr:t?r=Dt:(e=e.toLowerCase(),s=e,t=true,r=$e);break}const i=this.loader,a=new et(i.manager);a.setPath(i.partsLibraryPath),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials);try{return await a.loadAsync(s)}catch{continue}}throw new Error('LDrawLoader: Subobject "'+e+'" could not be loaded.')}parse(e,t=null){const r=this.loader,s=[],i=[],a=[],o=[],u={},l=D=>u[D]||null;let c="Model",d=null,h=null,f=null,m=0;e.indexOf(`\r
2
- `)!==-1&&(e=e.replace(/\r\n/g,`
3
- `));const g=e.split(`
4
- `),w=g.length;let p=false,b=null,y=null,C=false,P=true,S=false,L=true,k=false;for(let D=0;D<w;D++){const N=g[D];if(N.length===0)continue;if(p){N.startsWith("0 FILE ")?(this.setData(b,y),b=N.substring(7),y=""):y+=N+`
5
- `;continue}const v=new Se(N,D+1);if(v.seekNonSpace(),v.isAtTheEnd())continue;const O=v.getToken();let A,x,z,H,U,I,B,se,De,pt,gt;switch(O){case"0":const wt=v.getToken();if(wt)switch(wt){case"!LDRAW_ORG":c=v.getToken();break;case"!COLOUR":A=r.parseColorMetaDirective(v),A?u[A.userData.code]=A:console.warn("LDrawLoader: Error parsing material"+v.getLineNumberString());break;case"!CATEGORY":d=v.getToken();break;case"!KEYWORDS":const bt=v.getRemainingString().split(",");bt.length>0&&(h||(h=[]),bt.forEach(function(ce){h.push(ce.trim())}));break;case"FILE":D>0&&(p=true,b=v.getRemainingString(),y="",C=false,P=true);break;case"BFC":for(;!v.isAtTheEnd();){const ce=v.getToken();switch(ce){case"CERTIFY":case"NOCERTIFY":C=ce==="CERTIFY",P=true;break;case"CW":case"CCW":P=ce==="CCW";break;case"INVERTNEXT":S=true;break;case"CLIP":case"NOCLIP":L=ce==="CLIP";break;default:console.warn('THREE.LDrawLoader: BFC directive "'+ce+'" is unknown.');break}}break;case"STEP":k=true;break;case"Author:":f=v.getToken();break}break;case"1":x=v.getToken(),A=l(x);const Fn=parseFloat(v.getToken()),An=parseFloat(v.getToken()),Dn=parseFloat(v.getToken()),Nn=parseFloat(v.getToken()),On=parseFloat(v.getToken()),kn=parseFloat(v.getToken()),Rn=parseFloat(v.getToken()),Tn=parseFloat(v.getToken()),In=parseFloat(v.getToken()),Bn=parseFloat(v.getToken()),zn=parseFloat(v.getToken()),Hn=parseFloat(v.getToken()),jn=new en().set(Nn,On,kn,Fn,Rn,Tn,In,An,Bn,zn,Hn,Dn,0,0,0,1);let J=v.getRemainingString().trim().replace(/\\/g,"/");r.fileMap[J]?J=r.fileMap[J]:J.startsWith("s/")?J="parts/"+J:J.startsWith("48/")&&(J="p/"+J),o.push({material:A,colorCode:x,matrix:jn,fileName:J,inverted:S,startingBuildingStep:k}),k=false,S=false;break;case"2":x=v.getToken(),A=l(x),I=v.getVector(),B=v.getVector(),z={material:A,colorCode:x,vertices:[I,B]},i.push(z);break;case"5":x=v.getToken(),A=l(x),I=v.getVector(),B=v.getVector(),pt=v.getVector(),gt=v.getVector(),z={material:A,colorCode:x,vertices:[I,B],controlPoints:[pt,gt]},a.push(z);break;case"3":x=v.getToken(),A=l(x),H=P,U=!C||!L,H===true?(I=v.getVector(),B=v.getVector(),se=v.getVector()):(se=v.getVector(),B=v.getVector(),I=v.getVector()),s.push({material:A,colorCode:x,faceNormal:null,vertices:[I,B,se],normals:[null,null,null]}),m++,U===true&&(s.push({material:A,colorCode:x,faceNormal:null,vertices:[se,B,I],normals:[null,null,null]}),m++);break;case"4":x=v.getToken(),A=l(x),H=P,U=!C||!L,H===true?(I=v.getVector(),B=v.getVector(),se=v.getVector(),De=v.getVector()):(De=v.getVector(),se=v.getVector(),B=v.getVector(),I=v.getVector()),s.push({material:A,colorCode:x,faceNormal:null,vertices:[I,B,se,De],normals:[null,null,null,null]}),m+=2,U===true&&(s.push({material:A,colorCode:x,faceNormal:null,vertices:[De,se,B,I],normals:[null,null,null,null]}),m+=2);break;default:throw new Error('LDrawLoader: Unknown line type "'+O+'"'+v.getLineNumberString()+".")}}return p&&this.setData(b,y),{faces:s,conditionalSegments:a,lineSegments:i,type:c,category:d,keywords:h,author:f,subobjects:o,totalFaces:m,startingBuildingStep:k,materials:u,fileName:t,group:null}}getData(e,t=true){const r=e.toLowerCase(),s=this._cache[r];return s===null||s instanceof Promise?null:t?this.cloneResult(s):s}async ensureDataLoaded(e){const t=e.toLowerCase();t in this._cache||(this._cache[t]=this.fetchData(e).then(r=>{const s=this.parse(r,e);return this._cache[t]=s,s})),await this._cache[t]}setData(e,t){const r=e.toLowerCase();this._cache[r]=this.parse(t,e)}}function We(n,e,t,r){return(!r&&n===ae||r&&n===ve)&&(n=e),t[n]||null}class Ar{constructor(e){this.loader=e,this.parseCache=new Fr(e),this._cache={}}async processIntoMesh(e){const t=this.loader,r=this.parseCache,s=new Set,i=async(o,u=null)=>{const l=o.subobjects,c=[];for(let f=0,m=l.length;f<m;f++){const g=l[f],w=r.ensureDataLoaded(g.fileName).then(()=>{const p=r.getData(g.fileName,false);return Er(p.type)?i(r.getData(g.fileName),g):this.loadModel(g.fileName).catch(b=>(console.warn(b),null))});c.push(w)}const d=new ee;d.userData.category=o.category,d.userData.keywords=o.keywords,d.userData.author=o.author,d.userData.type=o.type,d.userData.fileName=o.fileName,o.group=d;const h=await Promise.all(c);for(let f=0,m=h.length;f<m;f++){const g=o.subobjects[f],w=h[f];if(w===null)continue;if(w.isGroup){const O=w;g.matrix.decompose(O.position,O.quaternion,O.scale),O.userData.startingBuildingStep=g.startingBuildingStep,O.name=g.fileName,t.applyMaterialsToMesh(O,g.colorCode,o.materials),O.userData.colorCode=g.colorCode,d.add(O);continue}w.group.children.length&&d.add(w.group);const p=o.lineSegments,b=o.conditionalSegments,y=o.faces,C=w.lineSegments,P=w.conditionalSegments,S=w.faces,L=g.matrix,k=g.inverted,D=L.determinant()<0,N=g.colorCode,v=N===ae?ve:N;for(let O=0,A=C.length;O<A;O++){const x=C[O],z=x.vertices;z[0].applyMatrix4(L),z[1].applyMatrix4(L),x.colorCode=x.colorCode===ve?v:x.colorCode,x.material=x.material||We(x.colorCode,x.colorCode,o.materials,true),p.push(x)}for(let O=0,A=P.length;O<A;O++){const x=P[O],z=x.vertices,H=x.controlPoints;z[0].applyMatrix4(L),z[1].applyMatrix4(L),H[0].applyMatrix4(L),H[1].applyMatrix4(L),x.colorCode=x.colorCode===ve?v:x.colorCode,x.material=x.material||We(x.colorCode,x.colorCode,o.materials,true),b.push(x)}for(let O=0,A=S.length;O<A;O++){const x=S[O],z=x.vertices;for(let H=0,U=z.length;H<U;H++)z[H].applyMatrix4(L);x.colorCode=x.colorCode===ae?N:x.colorCode,x.material=x.material||We(x.colorCode,N,o.materials,false),s.add(x.colorCode),D!==k&&z.reverse(),y.push(x)}o.totalFaces+=w.totalFaces}return u&&(t.applyMaterialsToMesh(d,u.colorCode,o.materials),d.userData.colorCode=u.colorCode),o};for(let o=0,u=e.faces;o<u;o++)s.add(e.faces[o].colorCode);if(await i(e),t.smoothNormals){const o=s.size>1;Pr(e.faces),Lr(e.faces,e.lineSegments,o)}const a=e.group;return e.faces.length>0&&a.add(Ke(this.loader,e.faces,3,false,e.totalFaces)),e.lineSegments.length>0&&a.add(Ke(this.loader,e.lineSegments,2)),e.conditionalSegments.length>0&&a.add(Ke(this.loader,e.conditionalSegments,2,true)),a}hasCachedModel(e){return e!==null&&e.toLowerCase()in this._cache}async getCachedModel(e){if(e!==null&&this.hasCachedModel(e)){const t=e.toLowerCase();return(await this._cache[t]).clone()}else return null}async loadModel(e){const t=this.parseCache,r=e.toLowerCase();if(this.hasCachedModel(e))return this.getCachedModel(e);{await t.ensureDataLoaded(e);const s=t.getData(e),i=this.processIntoMesh(s);return this.hasCachedModel(e)?this.getCachedModel(e):(Ot(s.type)&&(this._cache[r]=i),(await i).clone())}}async parseModel(e){const r=this.parseCache.parse(e);return Ot(r.type)&&this.hasCachedModel(r.fileName)?this.getCachedModel(r.fileName):this.processIntoMesh(r)}}function Dr(n,e){return n.colorCode===e.colorCode?0:n.colorCode<e.colorCode?-1:1}function Ke(n,e,t,r=false,s=null){e.sort(Dr),s===null&&(s=e.length);const i=new Float32Array(t*s*3),a=t===3?new Float32Array(t*s*3):null,o=[],u=new Array(6),l=new Y;let c=null,d=0,h=0,f=0;for(let g=0,w=e.length;g<w;g++){const p=e[g];let b=p.vertices;b.length===4&&(u[0]=b[0],u[1]=b[1],u[2]=b[2],u[3]=b[0],u[4]=b[2],u[5]=b[3],b=u);for(let y=0,C=b.length;y<C;y++){const P=b[y],S=f+y*3;i[S+0]=P.x,i[S+1]=P.y,i[S+2]=P.z}if(t===3){if(!p.faceNormal){const C=b[0],P=b[1],S=b[2];He.subVectors(P,C),je.subVectors(S,P),p.faceNormal=new E().crossVectors(He,je).normalize()}let y=p.normals;y.length===4&&(u[0]=y[0],u[1]=y[1],u[2]=y[2],u[3]=y[0],u[4]=y[2],u[5]=y[3],y=u);for(let C=0,P=y.length;C<P;C++){let S=p.faceNormal;y[C]&&(S=y[C].norm);const L=f+C*3;a[L+0]=S.x,a[L+1]=S.y,a[L+2]=S.z}}if(c!==p.colorCode){c!==null&&l.addGroup(d,h,o.length-1);const y=p.material;if(y!==null){if(t===3)o.push(y);else if(t===2)if(r){const C=n.edgeMaterialCache.get(y);o.push(n.conditionalEdgeMaterialCache.get(C))}else o.push(n.edgeMaterialCache.get(y))}else o.push(p.colorCode);c=p.colorCode,d=f/3,h=b.length}else h+=b.length;f+=3*b.length}h>0&&l.addGroup(d,1/0,o.length-1),l.setAttribute("position",new ie(i,3)),a!==null&&l.setAttribute("normal",new ie(a,3));let m=null;if(t===2?r?m=new Cr(l,o.length===1?o[0]:o):m=new Q(l,o.length===1?o[0]:o):t===3&&(m=new $(l,o.length===1?o[0]:o)),r){m.isConditionalLine=true;const g=new Float32Array(e.length*3*2),w=new Float32Array(e.length*3*2),p=new Float32Array(e.length*3*2);for(let b=0,y=e.length;b<y;b++){const C=e[b],P=C.vertices,S=C.controlPoints,L=S[0],k=S[1],D=P[0],N=P[1],v=b*3*2;g[v+0]=L.x,g[v+1]=L.y,g[v+2]=L.z,g[v+3]=L.x,g[v+4]=L.y,g[v+5]=L.z,w[v+0]=k.x,w[v+1]=k.y,w[v+2]=k.z,w[v+3]=k.x,w[v+4]=k.y,w[v+5]=k.z,p[v+0]=N.x-D.x,p[v+1]=N.y-D.y,p[v+2]=N.z-D.z,p[v+3]=N.x-D.x,p[v+4]=N.y-D.y,p[v+5]=N.z-D.z}l.setAttribute("control0",new ie(g,3,false)),l.setAttribute("control1",new ie(w,3,false)),l.setAttribute("direction",new ie(p,3,false))}return m}class Nr extends Ne{constructor(e){super(e),this.materials=[],this.materialLibrary={},this.edgeMaterialCache=new WeakMap,this.conditionalEdgeMaterialCache=new WeakMap,this.partsCache=new Ar(this),this.fileMap={},this.smoothNormals=true,this.partsLibraryPath="",this.ConditionalLineMaterial=null,this.missingColorMaterial=new V({name:Ne.DEFAULT_MATERIAL_NAME,color:16711935,roughness:.3,metalness:0}),this.missingEdgeColorMaterial=new ne({name:Ne.DEFAULT_MATERIAL_NAME,color:16711935}),this.missingConditionalEdgeColorMaterial=null,this.edgeMaterialCache.set(this.missingColorMaterial,this.missingEdgeColorMaterial),this.conditionalEdgeMaterialCache.set(this.missingEdgeColorMaterial,this.missingConditionalEdgeColorMaterial)}setPartsLibraryPath(e){return this.partsLibraryPath=e,this}setConditionalLineMaterial(e){return this.ConditionalLineMaterial=e,this.missingConditionalEdgeColorMaterial=new this.ConditionalLineMaterial({name:Ne.DEFAULT_MATERIAL_NAME,fog:true,color:16711935}),this}async preloadMaterials(e){const t=new et(this.manager);t.setPath(this.path),t.setRequestHeader(this.requestHeader),t.setWithCredentials(this.withCredentials);const r=await t.loadAsync(e),s=/^0 !COLOUR/,i=r.split(/[\n\r]/g),a=[];for(let o=0,u=i.length;o<u;o++){const l=i[o];if(s.test(l)){const c=l.replace(s,""),d=this.parseColorMetaDirective(new Se(c));a.push(d)}}this.setMaterials(a)}load(e,t,r,s){const i=new et(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,a=>{this.setMaterials([]),this.partsCache.parseModel(a).then(o=>{this.applyMaterialsToMesh(o,ae,this.materialLibrary,true),this.computeBuildingSteps(o),o.userData.fileName=e,t(o)}).catch(s)},r,s)}parse(e,t,r){this.partsCache.parseModel(e).then(s=>{this.applyMaterialsToMesh(s,ae,this.materialLibrary,true),this.computeBuildingSteps(s),s.userData.fileName="",t(s)}).catch(r)}setMaterials(e){this.materialLibrary={},this.materials=[];for(let t=0,r=e.length;t<r;t++)this.addMaterial(e[t]);return this.addMaterial(this.parseColorMetaDirective(new Se("Main_Colour CODE 16 VALUE #FF8080 EDGE #333333"))),this.addMaterial(this.parseColorMetaDirective(new Se("Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333"))),this}setFileMap(e){return this.fileMap=e,this}addMaterial(e){const t=this.materialLibrary;return t[e.userData.code]||(this.materials.push(e),t[e.userData.code]=e),this}getMaterial(e){if(e.startsWith("0x2")){const t=e.substring(3);return this.parseColorMetaDirective(new Se("Direct_Color_"+t+" CODE -1 VALUE #"+t+" EDGE #"+t))}return this.materialLibrary[e]||null}applyMaterialsToMesh(e,t,r,s=false){const i=this,a=t===ae;e.traverse(u=>{if(u.isMesh||u.isLineSegments)if(Array.isArray(u.material))for(let l=0,c=u.material.length;l<c;l++)u.material[l].isMaterial||(u.material[l]=o(u,u.material[l]));else u.material.isMaterial||(u.material=o(u,u.material))});function o(u,l){if(a&&!(l in r)&&!s)return l;const c=u.isLineSegments||u.isConditionalLine;(!c&&l===ae||c&&l===ve)&&(l=t);let h=null;if(l in r)h=r[l];else if(s)h=i.getMaterial(l),h===null&&(console.warn(`LDrawLoader: Material properties for code ${l} not available.`),h=i.missingColorMaterial);else return l;return u.isLineSegments&&(h=i.edgeMaterialCache.get(h),u.isConditionalLine&&(h=i.conditionalEdgeMaterialCache.get(h))),h}}getMainMaterial(){return this.getMaterial(ae)}getMainEdgeMaterial(){const e=this.getMaterial(ve);return e?this.edgeMaterialCache.get(e):null}parseColorMetaDirective(e){let t=null,r="#FF00FF",s="#FF00FF",i=1,a=false,o=0,u=Ct,l=null;const c=e.getToken();if(!c)throw new Error('LDrawLoader: Material name was expected after "!COLOUR tag'+e.getLineNumberString()+".");let d=null;for(;d=e.getToken(),!!d;)if(!f(d))switch(d.toUpperCase()){case"CODE":t=e.getToken();break;case"VALUE":if(r=e.getToken(),r.startsWith("0x"))r="#"+r.substring(2);else if(!r.startsWith("#"))throw new Error("LDrawLoader: Invalid color while parsing material"+e.getLineNumberString()+".");break;case"EDGE":if(s=e.getToken(),s.startsWith("0x"))s="#"+s.substring(2);else if(!s.startsWith("#")){if(l=this.getMaterial(s),!l)throw new Error("LDrawLoader: Invalid edge color while parsing material"+e.getLineNumberString()+".");l=this.edgeMaterialCache.get(l)}break;case"ALPHA":if(i=parseInt(e.getToken()),isNaN(i))throw new Error("LDrawLoader: Invalid alpha value in material definition"+e.getLineNumberString()+".");i=Math.max(0,Math.min(1,i/255)),i<1&&(a=true);break;case"LUMINANCE":if(!f(e.getToken()))throw new Error("LDrawLoader: Invalid luminance value in material definition"+e.getLineNumberString()+".");break;case"CHROME":u=Pt;break;case"PEARLESCENT":u=Lt;break;case"RUBBER":u=Et;break;case"MATTE_METALLIC":u=Ft;break;case"METAL":u=At;break;case"MATERIAL":e.setToEnd();break;default:throw new Error('LDrawLoader: Unknown token "'+d+'" while parsing material'+e.getLineNumberString()+".")}let h=null;switch(u){case Ct:h=new V({roughness:.3,metalness:0});break;case Lt:h=new V({roughness:.3,metalness:.25});break;case Pt:h=new V({roughness:0,metalness:1});break;case Et:h=new V({roughness:.9,metalness:0});break;case Ft:h=new V({roughness:.8,metalness:.4});break;case At:h=new V({roughness:.2,metalness:.85});break}if(h.color.setStyle(r,ke),h.transparent=a,h.premultipliedAlpha=true,h.opacity=i,h.depthWrite=!a,h.polygonOffset=true,h.polygonOffsetFactor=1,o!==0&&h.emissive.setStyle(r,ke).multiplyScalar(o),!l){if(l=new ne({color:new de().setStyle(s,ke),transparent:a,opacity:i,depthWrite:!a}),l.color,l.userData.code=t,l.name=c+" - Edge",this.ConditionalLineMaterial===null)throw new Error("THREE.LDrawLoader: ConditionalLineMaterial type must be specified via .setConditionalLineMaterial().");const m=new this.ConditionalLineMaterial({fog:true,transparent:a,depthWrite:!a,color:new de().setStyle(s,ke),opacity:i});m.userData.code=t,m.name=c+" - Conditional Edge",this.conditionalEdgeMaterialCache.set(l,m)}return h.userData.code=t,h.name=c,this.edgeMaterialCache.set(h,l),this.addMaterial(h),h;function f(m){let g;return m.startsWith("LUMINANCE")?g=parseInt(m.substring(9)):g=parseInt(m),isNaN(g)?false:(o=Math.max(0,Math.min(1,g/255)),true)}}computeBuildingSteps(e){let t=0;e.traverse(r=>{r.isGroup&&(r.userData.startingBuildingStep&&t++,r.userData.buildingStep=t)}),e.userData.numBuildingSteps=t+1}}const ot=new Set(["step","stp","stl","obj","ply","gltf","glb","3mf","amf","dae","fbx","3ds","usdz","gcode","gco","nc","wrl","vrml","pcd","xyz","vtk","vox","ldr","mpd","kmz","md2","lwo","bvh","pdb","nrrd","nhdr"]),kt=250,tt=12e3,Or=24,Rt=33;let Me=null;const kr=[{extensions:["step","stp","stl","obj","ply","gltf","glb","3mf","amf","dae","fbx","3ds","usdz","gcode","gco","nc","wrl","vrml","pcd","xyz","vtk","vox","ldr","mpd","kmz","md2","lwo","bvh","pdb","nrrd","nhdr"],family:"model3d",driverId:"model3d",targetFormat:"model3d",contentTypes:["model/stl","model/step","application/step","application/x-step","model/x.stl-ascii","model/x.stl-binary","application/vnd.ms-pki.stl","model/obj","model/ply","application/ply","model/gltf+json","model/gltf-binary","model/3mf","model/amf","application/x-amf","model/vnd.collada+xml","application/vnd.collada+xml","model/fbx","model/3ds","model/vnd.usdz+zip","model/usd","text/x-gcode","model/vrml","x-world/x-vrml","application/vnd.pointcloud","model/vtk","application/vnd.vtk","model/vox","application/x-magica-voxel","model/vnd.ldraw","text/vnd.ldraw","application/x-ldraw","application/vnd.google-earth.kmz","application/vnd.google-earth.kmz+xml","model/md2","application/x-md2","model/lwo","application/x-lwo","application/x-lightwave-object","application/bvh","application/x-bvh","chemical/x-pdb","chemical/pdb","application/nrrd","application/x-nrrd","application/vnd.ms-package.3dmanufacturing-3dmodel+xml"]}];class Rr{constructor(e,t={}){M(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});M(this,"root");M(this,"stage");M(this,"hint");M(this,"renderer",null);M(this,"scene",null);M(this,"camera",null);M(this,"modelGroup",null);M(this,"geometry",null);M(this,"edgeGeometry",null);M(this,"material",null);M(this,"edgeMaterial",null);M(this,"resizeObserver",null);M(this,"animationFrame",0);M(this,"yaw",-35);M(this,"pitch",24);M(this,"distance",140);M(this,"modelRadius",60);M(this,"baseDistance",140);M(this,"baseModelRadius",60);M(this,"baseModelGroupPosition",new E);M(this,"explodeTargets",[]);M(this,"maxExplodeOffset",0);M(this,"materialRuntimeState",new WeakMap);M(this,"sectionSourceGeometry",null);M(this,"raycaster",new Wn);M(this,"pointerNdc",new at);M(this,"measurementLineGeometry",null);M(this,"measurementLineMaterial",null);M(this,"measurementLine",null);M(this,"measurementPointsGeometry",null);M(this,"measurementPointsMaterial",null);M(this,"measurementPoints",null);M(this,"sectionHelperGroup",null);M(this,"sectionPlaneHelper",null);M(this,"sectionPlaneHelperGeometry",null);M(this,"sectionPlaneHelperMaterial",null);M(this,"sectionPlaneOutlineGeometry",null);M(this,"sectionPlaneOutlineMaterial",null);M(this,"sectionPlaneOutline",null);M(this,"sectionPlaneFillGeometry",null);M(this,"sectionPlaneFillMaterial",null);M(this,"sectionPlaneFill",null);M(this,"sectionBoxFillGeometry",null);M(this,"sectionBoxFillMaterial",null);M(this,"sectionBoxFill",null);M(this,"sectionBoxHelperGeometry",null);M(this,"sectionBoxHelperMaterial",null);M(this,"sectionBoxHelper",null);M(this,"sectionPlanes",[new we(new E(1,0,0),0),new we(new E(-1,0,0),0),new we(new E(0,1,0),0),new we(new E(0,-1,0),0),new we(new E(0,0,1),0),new we(new E(0,0,-1),0)]);M(this,"sectionHelperCache",new Map);M(this,"appliedSectionClippingKey",null);M(this,"appliedSectionHelperKey",null);M(this,"lastSectionHelperUpdateAt",Number.NEGATIVE_INFINITY);M(this,"sectionBounds",Ge());M(this,"measurementHoverClientX",null);M(this,"measurementHoverClientY",null);M(this,"projectionMode","perspective");M(this,"viewPreset","isometric");M(this,"displayMode","solid-edge");M(this,"snapshotBackground","scene");M(this,"state");M(this,"loadController",null);M(this,"interactionController",null);M(this,"resize",()=>{if(!this.renderer||!this.camera)return;const e2=this.stage.getBoundingClientRect(),t2=Math.max(1,Math.floor(e2.width||this.stage.clientWidth||1)),r2=Math.max(1,Math.floor(e2.height||this.stage.clientHeight||1));if(this.camera instanceof Mt)this.camera.aspect=t2/r2,this.camera.updateProjectionMatrix();else{const s=t2/r2,i=Math.max(this.modelRadius,1)*1.35/this.state.scale,a=i*s;this.camera.left=-a,this.camera.right=a,this.camera.top=i,this.camera.bottom=-i,this.camera.updateProjectionMatrix()}this.renderer.setSize(t2,r2,false)});this.host=e,this.options=t;const r=this.options.initialScale??1;this.root=document.createElement("div"),this.root.className="model3dv-preview",this.stage=document.createElement("div"),this.stage.className="model3dv-stage",this.hint=document.createElement("div"),this.hint.className="model3dv-hint",this.hint.textContent="Drag to orbit \xB7 Pinch or scroll to zoom",this.root.replaceChildren(this.stage,this.hint),this.host.replaceChildren(this.root),this.state={loading:false,error:null,family:"model3d",warnings:[],capabilities:{zoom:true,fit:true,pan:true,orbit:true,fullscreen:true,download:true,modelTree:true,metadata:true,measure:false,section:false,explode:false,materialFilter:false},scale:Number.isFinite(r)?_(r,.2,4):1,explode:0,displayMode:this.displayMode,snapshotBackground:this.snapshotBackground,measurement:{active:false,status:"idle",snapMode:"surface",axisLock:"free"},section:ue(),camera:{position:[0,0,this.distance],target:[0,0,0],projection:this.projectionMode,viewPreset:this.viewPreset}}}async load(e,t){var a,o,u,l;this.stopLoad();const r=new AbortController;this.loadController=r;const s=r.signal,i=()=>r.abort();s.addEventListener("abort",()=>{var c;(c=t.signal)==null||c.removeEventListener("abort",i),this.loadController===r&&(this.loadController=null,this.disposeScene(),this.state.loading=false,this.emit("statechange",this.state))},{once:true}),(a=t.signal)==null||a.addEventListener("abort",i,{once:true}),this.state={...this.state,loading:true,error:null,title:t.descriptor.name,warnings:[],explode:0,modelTree:void 0,selectedNodeId:void 0,isolatedMaterialKey:void 0,displayMode:this.displayMode,snapshotBackground:this.snapshotBackground,measurement:{active:false,status:"idle",snapMode:"surface",axisLock:"free"},section:ue(),metadata:void 0},this.projectionMode="perspective",this.viewPreset="isometric",this.yaw=-35,this.pitch=24,this.emit("loading",this.state),this.emit("statechange",this.state);try{(o=t.signal)!=null&&o.aborted&&r.abort(),F(s);const c=Sn(((u=t.route)==null?void 0:u.sourceFormat)??t.descriptor.extension);if(!ot.has(c))throw new Error(`3D preview currently supports browser-WASM STEP/STP plus browser-native STL, OBJ, PLY, glTF, GLB, 3MF, AMF, DAE, FBX, 3DS, USDA-backed USDZ, G-code, VRML, PCD, XYZ, VTK, VOX, LDraw, KMZ, MD2, LWO, BVH, PDB, NRRD, and NHDR files, got ${c||"unknown"}.`);const d=await ut(e,s);if(F(s),c==="step"||c==="stp"){const m=await os(d,{signal:s});this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:m.userData.previewWarnings??[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="glb"||c==="gltf"){const m=c==="gltf"?await gs(d,{resourcePath:Cn(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s}):{object:await Gr(d,{signal:s}),warnings:[]};this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="obj"){const m=new TextDecoder().decode(d);let g=[],w;if(this.options.resourceResolver&&rn(m).length){const p=await Br(m,{resourceBasePath:t.descriptor.name,resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});g=p.warnings,w=T(p.object,c),this.createObjectScene(p.object,s)}else{const p=Ir(m);w=jt(p,c),this.createScene(p,s)}this.state={...this.state,loading:false,error:null,warnings:g,metadata:w,camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="amf"){const m=Ur(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="dae"){const m=_r(new TextDecoder().decode(d),{resourceBasePath:t.descriptor.name,resourcePath:Vi(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="fbx"){const m=ss(d,{resourceBasePath:t.descriptor.name,resourcePath:Ce(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="3ds"){const m=is(d,{resourceBasePath:t.descriptor.name,resourcePath:Ce(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="usdz"){const m=await as(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="gcode"||c==="gco"||c==="nc"){const m=ls(new TextDecoder().decode(d));this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="wrl"||c==="vrml"){const m=cs(new TextDecoder().decode(d),{resourceBasePath:t.descriptor.name,resourcePath:Ce(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="pcd"){const m=us(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="xyz"){const m=ds(new TextDecoder().decode(d));this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="vtk"){const m=hs(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="vox"){const m=fs(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="ldr"||c==="mpd"){const m=await ps(new TextDecoder().decode(d),{resourceBasePath:t.descriptor.name,resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="kmz"){const m=await Vr(d,{signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="md2"){const m=Jr(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="lwo"){const m=Qr(d,{resourceBasePath:t.descriptor.name,resourcePath:Ce(e),modelName:$i(t.descriptor.name),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="bvh"){const m=es(new TextDecoder().decode(d));this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="pdb"){const m=ts(new TextDecoder().decode(d));this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="nrrd"||c==="nhdr"){const m=c==="nhdr"?await rs(new TextDecoder().decode(d),{resourceBasePath:t.descriptor.name,resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s}):d;F(s);const g=ns(m);this.createObjectScene(g,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(g,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}const h=c==="3mf"?await jr(d,{signal:s}):{geometry:c==="ply"?Hr(d):Tr(d),warnings:[]},f=h.geometry;this.createScene(f,s),this.state={...this.state,loading:false,error:null,warnings:h.warnings,metadata:jt(h.geometry,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(c){if(s.aborted){(l=t.signal)!=null&&l.aborted&&F(s);return}this.stopLoad();const d=c instanceof Error?c:new Error(String(c));throw this.state.loading=false,this.state.error=d.message,this.emit("error",d),this.emit("statechange",this.state),d}}destroy(){this.stopLoad(),this.state.loading=false,this.stage.replaceChildren(),this.root.replaceChildren(),this.root.parentElement===this.host&&this.host.replaceChildren();for(const e of Object.values(this.listeners))e.clear()}stopLoad(){const e=this.loadController;this.loadController=null,e==null||e.abort(),this.disposeScene()}getState(){return{...this.state,warnings:[...this.state.warnings],modelTree:this.state.modelTree?fn(this.state.modelTree):void 0,layers:[...this.state.layers??[]],activeLayerIds:[...this.state.activeLayerIds??[]],metadata:this.state.metadata?{...this.state.metadata,materialNames:[...this.state.metadata.materialNames??[]],materialDetails:yn(this.state.metadata.materialDetails),bounds:this.state.metadata.bounds?{...this.state.metadata.bounds,min:[...this.state.metadata.bounds.min],max:[...this.state.metadata.bounds.max],size:[...this.state.metadata.bounds.size]}:void 0}:void 0,isolatedMaterialKey:this.state.isolatedMaterialKey,displayMode:this.state.displayMode,snapshotBackground:this.state.snapshotBackground,measurement:_t(this.state.measurement),section:ii(this.state.section),camera:this.state.camera?{...this.state.camera}:void 0}}on(e,t){return this.listeners[e].add(t),()=>{this.listeners[e].delete(t)}}setScale(e){if(!Number.isFinite(e))return;const t=Math.max(.2,Math.min(e,4));this.state.scale!==t&&(this.state.scale=t,this.distance=Math.max(this.modelRadius*1.25,this.modelRadius*2.6/this.state.scale),this.updateCamera(),this.emit("statechange",this.state))}fit(){this.setScale(1)}pan(e,t){!Number.isFinite(e)||!Number.isFinite(t)||(this.yaw+=e*.35,this.pitch=_(this.pitch+t*.25,-80,80),this.viewPreset="free",this.updateCamera(),this.emit("statechange",this.state))}selectNode(e){this.state.selectedNodeId!==e&&(this.state.selectedNodeId=e,this.applyAppearanceState(),this.focusNode(e),this.emit("statechange",this.state))}setNodeVisibility(e,t){this.toggleNodeVisibility(e,t)}toggleNodeVisibility(e,t){var i;if(!this.modelGroup||!((i=this.state.modelTree)!=null&&i.length))return;const r=this.findNodeObject(e);if(!r)return;const s=typeof t=="boolean"?t:!(r.userData.previewOriginalVisible??r.visible);if(!!(r.userData.previewOriginalVisible??r.visible)!==s){if(this.applyNodeVisibility(r,s),this.state.modelTree=pn(this.state.modelTree,e,s),this.state.selectedNodeId){const a=wn(this.state.modelTree,this.state.selectedNodeId);a!=null&&a.visible?this.applyAppearanceState():(this.state.selectedNodeId=void 0,this.applyAppearanceState(),this.focusNode(void 0))}else this.applyAppearanceState();this.clearSectionHelperCache(),this.emit("statechange",this.state)}}setExplode(e){if(!Number.isFinite(e))return;if(!this.explodeTargets.length){this.state.explode=0;return}const t=_(e,0,1);(this.state.explode??0)!==t&&(this.state.explode=t,this.applyExplode(this.state.explode),this.focusNode(this.state.selectedNodeId),this.emit("statechange",this.state))}setActiveMaterial(e){const t=e||void 0;this.state.isolatedMaterialKey!==t&&(this.state.isolatedMaterialKey=t,this.applyAppearanceState(),this.clearSectionHelperCache(),this.focusNode(this.state.selectedNodeId),this.emit("statechange",this.state))}setMeasurementActive(e){const t=_t(this.state.measurement)??{active:false,status:"idle",snapMode:"surface",axisLock:"free"},r={...t,active:e,status:e?t.start?t.end?"complete":"pick-end":"pick-start":t.start&&t.end?"complete":t.start?"pick-end":"idle"};e||(r.previewPoint=void 0,r.previewDelta=void 0,r.previewDistance=void 0),!Vt(this.state.measurement,r)&&(this.state.measurement=r,this.updateMeasurementHelpers(),this.emit("statechange",this.state))}clearMeasurement(){var t,r;const e={active:false,status:"idle",snapMode:((t=this.state.measurement)==null?void 0:t.snapMode)??"surface",axisLock:((r=this.state.measurement)==null?void 0:r.axisLock)??"free",previewPoint:void 0,previewDelta:void 0,previewDistance:void 0};Vt(this.state.measurement,e)||(this.state.measurement=e,this.updateMeasurementHelpers(),this.emit("statechange",this.state))}ensureSectionState(){const e=this.state.section;return e?Je(e,this.sectionBounds):ue(this.sectionBounds)}setMeasurementSnapMode(e){const t=this.state.measurement??{active:false,status:"idle",snapMode:"surface",axisLock:"free"};(t.snapMode??"surface")!==e&&(t.snapMode=e,this.state.measurement=t,this.refreshMeasurementHover(),this.updateMeasurementHelpers(),this.emit("statechange",this.state))}setMeasurementAxisLock(e){const t=this.state.measurement??{active:false,status:"idle",snapMode:"surface",axisLock:"free"};(t.axisLock??"free")!==e&&(t.axisLock=e,this.state.measurement=t,this.refreshMeasurementHover(),this.updateMeasurementHelpers(),this.emit("statechange",this.state))}setSectionActive(e){const t=this.ensureSectionState();t.active!==e&&(t.active=e,this.state.section=t,this.updateSectionPlanes(),this.emit("statechange",this.state))}setSectionMode(e){const t=this.ensureSectionState();(t.mode??"single")!==e&&(t.mode=e,this.state.section=Je(t,this.sectionBounds),this.updateSectionPlanes(),this.emit("statechange",this.state))}setSectionAxis(e){const t=this.ensureSectionState();if(t.axis===e)return;const[r,s]=this.sectionBounds[e];t.axis=e,t.min=R(r),t.max=R(s),t.offset=_(t.offset,t.min,t.max),this.state.section=t,this.updateSectionPlanes(),this.emit("statechange",this.state)}setSectionOffset(e){if(!Number.isFinite(e))return;const t=this.ensureSectionState(),r=R(_(e,t.min,t.max));t.offset!==r&&(t.offset=r,this.state.section=t,this.updateSectionPlanes(),this.emit("statechange",this.state))}setSectionRange(e,t,r){var c;if(!Number.isFinite(t)||!Number.isFinite(r))return;const s=this.ensureSectionState(),i=this.sectionBounds[e],a=_(Math.min(t,r),i[0],i[1]),o=_(Math.max(t,r),i[0],i[1]),u=[R(a),R(o)],l=(c=s.range)==null?void 0:c[e];l&&l[0]===u[0]&&l[1]===u[1]||(s.range={...s.range??xe(this.sectionBounds),[e]:u},this.state.section=Je(s,this.sectionBounds),this.updateSectionPlanes(),this.emit("statechange",this.state))}clearSection(){const e=ue(this.sectionBounds);ai(this.state.section,e)||(this.state.section=e,this.updateSectionPlanes(),this.emit("statechange",this.state))}setCameraProjection(e){this.projectionMode!==e&&(this.projectionMode=e,this.replaceCamera(),this.updateCamera(),this.emit("statechange",this.state))}setCameraViewPreset(e){if(this.viewPreset===e)return;this.viewPreset=e;const t=Js(e);t&&(this.yaw=t.yaw,this.pitch=t.pitch),this.updateCamera(),this.emit("statechange",this.state)}setDisplayMode(e){this.displayMode!==e&&(this.displayMode=e,this.state.displayMode=e,this.applyAppearanceState(),this.emit("statechange",this.state))}setSnapshotBackground(e){this.snapshotBackground!==e&&(this.snapshotBackground=e,this.state.snapshotBackground=e,this.emit("statechange",this.state))}downloadSnapshot(e,t){if(typeof document>"u")return;const r=this.renderer,s=r==null?void 0:r.domElement,i=this.scene,a=this.camera;if(!s||!r||!i||!a)return;const o=this.applySceneBackground(t??this.snapshotBackground);r.render(i,a);const u=s.toDataURL("image/png");o(),r.render(i,a);const l=document.createElement("a");l.href=u,l.download=Qs(e??this.state.title),l.rel="noopener",l.click()}async fullscreen(){var e,t;await((t=(e=this.root).requestFullscreen)==null?void 0:t.call(e))}createScene(e,t){F(t);const r=Qt({antialias:true,alpha:false,preserveDrawingBuffer:true});this.renderer=r,r.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),r.setClearColor(1120295,1),r.localClippingEnabled=true,r.clippingPlanes=[],r.domElement.className="model3dv-canvas",this.stage.replaceChildren(r.domElement);const s=new yt;s.background=new de(1120295);const i=this.createCamera(),a=new ee;this.modelGroup=a,this.scene=s,this.camera=i;const o=new Y;this.geometry=o,o.setAttribute("position",new ie(e.positions,3)),o.setAttribute("normal",new ie(e.normals,3)),e.colors&&o.setAttribute("color",new ie(e.colors,3)),o.computeBoundingSphere();const u=zi(e.bounds),l=Hi(e.bounds);this.modelRadius=Math.max(l.x,l.y,l.z,1)*.72,this.baseModelRadius=this.modelRadius,this.distance=this.modelRadius*2.6,this.baseDistance=this.distance,a.position.set(-u.x,-u.y,-u.z),this.baseModelGroupPosition.copy(a.position);const c=new V({color:e.colors?16777215:8246268,roughness:.55,metalness:.08,vertexColors:!!e.colors});this.material=c;const d=new $(o,c);a.add(d);const h=new vt(o,35),f=new ne({color:14412542,transparent:true,opacity:.22});this.edgeGeometry=h,this.edgeMaterial=f;const m=new Q(h,f),g=m;g.userData.previewEdgeHelper=true,g.userData.previewEdgeSourceId=d.id,g.userData.previewOriginalVisible=true,a.add(m),s.add(new xt(16777215,.48));const w=new Oe(16777215,1.4);w.position.set(1,1.6,1.3),s.add(w);const p=new Oe(9684477,.8);p.position.set(-1.5,.8,-1),s.add(p),s.add(a),this.renderer=r,this.scene=s,this.camera=i,this.modelGroup=a,this.geometry=o,this.edgeGeometry=h,this.material=c,this.edgeMaterial=f,this.clearSectionHelperCache(),this.sectionSourceGeometry={positions:ki(e.positions,tt)},this.explodeTargets=[],this.maxExplodeOffset=0,this.sectionBounds=ji(e.bounds,u),this.state.modelTree=void 0,this.state.selectedNodeId=void 0,this.state.isolatedMaterialKey=void 0,this.state.explode=0,this.state.displayMode=this.displayMode,this.state.snapshotBackground=this.snapshotBackground,this.state.measurement={active:false,status:"idle",snapMode:"surface",axisLock:"free"},this.state.section=ue(this.sectionBounds),this.state.capabilities.measure=true,this.state.capabilities.section=true,this.state.capabilities.explode=false,this.state.capabilities.materialFilter=false,this.state.capabilities.displayMode=true,this.captureMaterialRuntimeState(a),this.applyAppearanceState(),this.setupMeasurementHelpers(a),this.bindInteractions(r.domElement),this.observeResize(),this.resize(),this.updateSectionPlanes(),this.updateCamera(),this.startAnimation()}createObjectScene(e,t){t.aborted&&(he(e),F(t));const r=Qt({antialias:true,alpha:false,preserveDrawingBuffer:true});this.renderer=r,r.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),r.setClearColor(1120295,1),r.localClippingEnabled=true,r.clippingPlanes=[],r.domElement.className="model3dv-canvas",this.stage.replaceChildren(r.domElement);const s=new yt;s.background=new de(1120295);const i=this.createCamera(),a=new ee;this.modelGroup=a,this.scene=s,this.camera=i,a.add(e),s.add(new xt(16777215,.62));const o=new Oe(16777215,1.45);o.position.set(1,1.6,1.3),s.add(o);const u=new Oe(9684477,.7);u.position.set(-1.5,.8,-1),s.add(u),s.add(a);const l=new te().setFromObject(e),c=l.getCenter(new E),d=l.getSize(new E);this.modelRadius=Math.max(d.x,d.y,d.z,1)*.72,this.baseModelRadius=this.modelRadius,this.distance=this.modelRadius*2.6,this.baseDistance=this.distance,e.position.sub(c),this.sectionBounds=Gi(e),this.baseModelGroupPosition.copy(a.position),this.explodeTargets=ei(e,this.baseModelRadius),this.maxExplodeOffset=this.explodeTargets.reduce((h,f)=>Math.max(h,f.distance),0),this.state.modelTree=Ks(e),this.state.selectedNodeId=void 0,this.state.isolatedMaterialKey=void 0,this.state.explode=0,this.state.displayMode=this.displayMode,this.state.snapshotBackground=this.snapshotBackground,this.state.measurement={active:false,status:"idle",snapMode:"surface",axisLock:"free"},this.state.section=ue(this.sectionBounds),this.state.capabilities.measure=true,this.state.capabilities.section=true,this.state.capabilities.explode=this.explodeTargets.length>1,this.state.capabilities.materialFilter=Ys(e),this.state.capabilities.displayMode=true,this.attachEdgeHelpers(e),this.captureMaterialRuntimeState(e),this.applyExplode(0),this.applyAppearanceState(),this.setupMeasurementHelpers(a),this.renderer=r,this.scene=s,this.camera=i,this.modelGroup=a,this.clearSectionHelperCache(),this.sectionSourceGeometry={positions:new Float32Array,objects:Di(e,tt)},this.bindInteractions(r.domElement),this.observeResize(),this.resize(),this.updateSectionPlanes(),this.updateCamera(),this.startAnimation()}bindInteractions(e){var u;(u=this.interactionController)==null||u.abort(),this.interactionController=new AbortController;const t=this.interactionController.signal,r=new Map;let s=null;const i=()=>{const[l,c]=r.values();return l&&c?Math.hypot(c.x-l.x,c.y-l.y):0},a=l=>{e.hasPointerCapture(l)&&e.releasePointerCapture(l)};e.style.touchAction="none",t.addEventListener("abort",()=>{for(const l of r.keys())a(l);r.clear(),s=null},{once:true}),e.addEventListener("pointerdown",l=>{const c={x:l.clientX,y:l.clientY};r.set(l.pointerId,c),s=r.size===1?{...c}:null,e.setPointerCapture(l.pointerId)},{signal:t}),e.addEventListener("pointermove",l=>{var m;const c=r.get(l.pointerId);if(!c){(((m=this.state.measurement)==null?void 0:m.active)??false)&&r.size===0&&(this.measurementHoverClientX=l.clientX,this.measurementHoverClientY=l.clientY,this.updateMeasurementHover(l.clientX,l.clientY));return}s&&Math.hypot(l.clientX-s.x,l.clientY-s.y)>4&&(s=null);const d=i(),h=l.clientX-c.x,f=l.clientY-c.y;if(c.x=l.clientX,c.y=l.clientY,r.size===1)(h!==0||f!==0)&&this.pan(h,f);else{const g=i();d>0&&g>0&&this.setScale(this.state.scale*g/d)}},{signal:t}),e.addEventListener("pointerup",l=>{var d;if(!r.delete(l.pointerId))return;const c=s&&Math.hypot(l.clientX-s.x,l.clientY-s.y)<=4;s=null,a(l.pointerId),(((d=this.state.measurement)==null?void 0:d.active)??false)&&c&&this.pickMeasurementPoint(l.clientX,l.clientY)},{signal:t});const o=l=>{r.delete(l.pointerId)&&(s=null,a(l.pointerId))};e.addEventListener("pointercancel",o,{signal:t}),e.addEventListener("lostpointercapture",o,{signal:t}),e.addEventListener("pointerleave",()=>{this.measurementHoverClientX=null,this.measurementHoverClientY=null,this.clearMeasurementHover()},{signal:t}),e.addEventListener("wheel",l=>{l.preventDefault(),this.setScale(this.state.scale+(l.deltaY>0?-.08:.08))},{passive:false,signal:t})}observeResize(){var e;if((e=this.resizeObserver)==null||e.disconnect(),typeof ResizeObserver<"u"){this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this.stage);return}window.addEventListener("resize",this.resize)}startAnimation(){const e=()=>{this.animationFrame=requestAnimationFrame(e),this.renderFrame()};e()}renderFrame(){!this.renderer||!this.scene||!this.camera||!this.modelGroup||(this.updateSectionPlanes(),this.renderer.render(this.scene,this.camera))}createCamera(){return this.projectionMode==="orthographic"?new Kn(-100,100,100,-100,.1,1e5):new Mt(45,1,.1,1e5)}replaceCamera(){var t;const e=((t=this.camera)==null?void 0:t.position.clone())??new E(0,0,this.distance);this.camera=this.createCamera(),this.camera.position.copy(e),this.resize()}updateCamera(){if(!this.camera)return;const e=Jt(this.yaw),t=Jt(this.pitch);this.camera.position.set(this.distance*Math.cos(t)*Math.sin(e),this.distance*Math.sin(t),this.distance*Math.cos(t)*Math.cos(e)),this.camera.lookAt(0,0,0),this.resize(),this.state.camera=this.currentCameraState()}currentCameraState(){var t;const e=((t=this.camera)==null?void 0:t.position)??new E(0,0,this.distance);return{position:[e.x,e.y,e.z],target:[0,0,0],projection:this.projectionMode,viewPreset:this.viewPreset}}applyExplode(e){this.explodeTargets.length&&this.clearSectionHelperCache();for(const t of this.explodeTargets)t.object.position.copy(t.basePosition).addScaledVector(t.direction,t.distance*e)}setupMeasurementHelpers(e){const t=new Y;t.setAttribute("position",new Z([0,0,0,0,0,0],3));const r=new ne({color:16096779,transparent:true,opacity:.95}),s=new _e(t,r);s.visible=false,s.userData.previewMeasurementHelper=true;const i=new Y;i.setAttribute("position",new Z([0,0,0,0,0,0],3));const a=new Pe({color:16498468,size:Math.max(this.baseModelRadius*.045,.8),sizeAttenuation:true}),o=new me(i,a);o.visible=false,o.userData.previewMeasurementHelper=true,e.add(s),e.add(o),this.measurementLineGeometry=t,this.measurementLineMaterial=r,this.measurementLine=s,this.measurementPointsGeometry=i,this.measurementPointsMaterial=a,this.measurementPoints=o,this.updateMeasurementHelpers()}pickMeasurementPoint(e,t){this.measurementHoverClientX=e,this.measurementHoverClientY=t;const r=this.resolveMeasurementPoint(e,t);r&&this.applyMeasurementPoint(r)}updateMeasurementHover(e,t){const r=this.state.measurement;if(!(r!=null&&r.active))return;const s=this.resolveMeasurementPoint(e,t);if(!s){this.clearMeasurementHover();return}this.applyMeasurementPreviewPoint(s)}applyMeasurementPreviewPoint(e){const t=this.state.measurement;if(t!=null&&t.active){if(t.start){const r=new E(...t.start),s=Gt(e,r,t.axisLock??"free"),i=s.clone().sub(r),a=ye(s),o=ye(i),u=R(i.length());if(oe(t.previewPoint,a)&&oe(t.previewDelta,o)&&t.previewDistance===u&&t.status==="pick-end")return;t.previewPoint=a,t.previewDelta=o,t.previewDistance=u,t.status="pick-end"}else{const r=ye(e);if(oe(t.previewPoint,r)&&t.previewDelta==null&&t.previewDistance==null&&t.status==="pick-start")return;t.previewPoint=r,t.previewDelta=void 0,t.previewDistance=void 0,t.status="pick-start"}this.updateMeasurementHelpers(),this.emit("statechange",this.state)}}refreshMeasurementHover(){this.measurementHoverClientX==null||this.measurementHoverClientY==null||this.updateMeasurementHover(this.measurementHoverClientX,this.measurementHoverClientY)}clearMeasurementHover(){const e=this.state.measurement;if(!e)return;const t=e.active?e.start?"pick-end":"pick-start":e.status;e.previewPoint==null&&e.previewDelta==null&&e.previewDistance==null&&e.status===t||(e.previewPoint=void 0,e.previewDelta=void 0,e.previewDistance=void 0,e.active&&(e.status=t),this.updateMeasurementHelpers(),this.emit("statechange",this.state))}resolveMeasurementPoint(e,t){var c;if(!this.renderer||!this.camera||!this.modelGroup)return;const r=this.renderer.domElement.getBoundingClientRect(),s=r.width||1,i=r.height||1;this.pointerNdc.set((e-r.left)/s*2-1,-((t-r.top)/i*2-1)),this.raycaster.setFromCamera(this.pointerNdc,this.camera);const o=this.raycaster.intersectObject(this.modelGroup,true).find(d=>{const h=d.object;return!h.userData.previewMeasurementHelper&&h.visible});if(!o)return;const l=(((c=this.state.measurement)==null?void 0:c.snapMode)??"surface")==="vertex"?Zs(o)??o.point:o.point;return this.modelGroup.worldToLocal(l.clone())}applyMeasurementPoint(e){const t=this.state.measurement??{active:false,status:"idle",snapMode:"surface",axisLock:"free"},r=t.start?new E(...t.start):void 0;if(!r||t.end)t.start=ye(e),t.end=void 0,t.delta=void 0,t.distance=void 0,t.previewPoint=void 0,t.previewDelta=void 0,t.previewDistance=void 0,t.status="pick-end";else{const s=Gt(e,r,t.axisLock??"free"),i=s.clone().sub(r);t.end=ye(s),t.delta=ye(i),t.distance=R(i.length()),t.previewPoint=void 0,t.previewDelta=void 0,t.previewDistance=void 0,t.status="complete",t.active=false}this.state.measurement=t,this.updateMeasurementHelpers(),this.emit("statechange",this.state)}updateMeasurementHelpers(){var r,s,i,a;const e=(r=this.state.measurement)!=null&&r.start?new E(...this.state.measurement.start):void 0,t=(s=this.state.measurement)!=null&&s.end?new E(...this.state.measurement.end):(i=this.state.measurement)!=null&&i.previewPoint?new E(...this.state.measurement.previewPoint):void 0;if(this.measurementLineGeometry&&this.measurementLine){const o=this.measurementLineGeometry.getAttribute("position");e&&t?(o.setXYZ(0,e.x,e.y,e.z),o.setXYZ(1,t.x,t.y,t.z),o.needsUpdate=true,this.measurementLineGeometry.computeBoundingSphere(),this.measurementLine.visible=true):this.measurementLine.visible=false}if(this.measurementPointsGeometry&&this.measurementPoints){const o=this.measurementPointsGeometry.getAttribute("position"),u=e??((a=this.state.measurement)!=null&&a.previewPoint?new E(...this.state.measurement.previewPoint):void 0);if(u){o.setXYZ(0,u.x,u.y,u.z);const l=t??u;o.setXYZ(1,l.x,l.y,l.z),o.needsUpdate=true,this.measurementPointsGeometry.computeBoundingSphere(),this.measurementPoints.visible=true}else this.measurementPoints.visible=false}}updateSectionPlanes(){var s,i;if(!this.renderer||!this.modelGroup)return;const e=this.state.section;if(!(e!=null&&e.active)){this.appliedSectionClippingKey!=="inactive"&&(this.renderer.clippingPlanes=[],this.appliedSectionClippingKey="inactive"),this.appliedSectionHelperKey!=="inactive"&&(this.updateSectionHelpers(void 0),this.appliedSectionHelperKey="inactive");return}this.modelGroup.updateMatrixWorld(true);const t=ui(e,this.modelGroup);if(t!==this.appliedSectionClippingKey){const a=e.mode==="box"?this.resolveBoxSectionPlanes(e):this.resolveSingleSectionPlanes(e);this.renderer.clippingPlanes=a,this.appliedSectionClippingKey=t}const r=ci(e);if(e.mode==="box"){r!==this.appliedSectionHelperKey&&this.appliedSectionHelperKey!==null&&this.appliedSectionHelperKey!=="inactive"&&this.appliedSectionHelperKey.startsWith("box:")&&((s=this.sectionBoxFill)==null?void 0:s.visible)&&((i=this.sectionBoxHelper)==null?void 0:i.visible)&&Re()-this.lastSectionHelperUpdateAt<Rt?this.markBoxSectionHelperPending():r!==this.appliedSectionHelperKey&&(this.updateSectionHelpers(e),this.appliedSectionHelperKey=r,this.lastSectionHelperUpdateAt=Re());return}this.prepareSingleSectionHelper(e),r!==this.appliedSectionHelperKey&&(this.shouldRefreshSingleSectionHelper(e)?(this.updateSectionPlaneDetail(e),this.appliedSectionHelperKey=r,this.lastSectionHelperUpdateAt=Re()):this.markSingleSectionHelperPending())}markBoxSectionHelperPending(){!this.sectionPlaneHelper||!this.sectionPlaneOutline||!this.sectionPlaneFill||!this.sectionBoxFill||!this.sectionBoxHelper||(this.sectionPlaneHelper.visible=false,this.sectionPlaneOutline.visible=false,this.sectionPlaneFill.visible=false,this.sectionBoxFill.visible=false,this.sectionBoxHelper.visible=false)}shouldRefreshSingleSectionHelper(e){return this.appliedSectionHelperKey===null||this.appliedSectionHelperKey==="inactive"||this.sectionHelperCache.has(Ue(e))?true:Re()-this.lastSectionHelperUpdateAt>=Rt}prepareSingleSectionHelper(e){this.ensureSectionHelpers(),!(!this.sectionPlaneHelper||!this.sectionPlaneOutline||!this.sectionPlaneFill||!this.sectionBoxFill||!this.sectionBoxHelper)&&(this.updateSectionPlaneMesh(e),this.sectionBoxFill.visible=false,this.sectionBoxHelper.visible=false,this.sectionPlaneHelper.visible=true,this.sectionPlaneOutline.visible=true)}markSingleSectionHelperPending(){!this.sectionPlaneOutline||!this.sectionPlaneFill||(this.sectionPlaneOutline.visible=false,this.sectionPlaneFill.visible=false)}resolveSingleSectionPlanes(e){const t=Ut(e.axis),r=this.sectionPlanes[0];return r.set(t,-e.offset),r.applyMatrix4(this.modelGroup.matrixWorld),[r]}resolveBoxSectionPlanes(e){const t=e.range??xe(this.sectionBounds),r=[],s=[{axis:"x",positive:this.sectionPlanes[0],negative:this.sectionPlanes[1]},{axis:"y",positive:this.sectionPlanes[2],negative:this.sectionPlanes[3]},{axis:"z",positive:this.sectionPlanes[4],negative:this.sectionPlanes[5]}];for(const{axis:i,positive:a,negative:o}of s){const u=this.sectionBounds[i],[l,c]=t[i];l>u[0]+5e-4&&(a.set(Ut(i),-l),a.applyMatrix4(this.modelGroup.matrixWorld),r.push(a)),c<u[1]-5e-4&&(o.set(qs(i),c),o.applyMatrix4(this.modelGroup.matrixWorld),r.push(o))}return r}ensureSectionHelpers(){if(!this.modelGroup||this.sectionHelperGroup)return;const e=new ee;e.userData.previewMeasurementHelper=true;const t=new Yn(1,1),r=new Ve({color:3718648,transparent:true,opacity:.14,side:Te,depthWrite:false}),s=new $(t,r);s.visible=false,s.renderOrder=3,s.userData.previewMeasurementHelper=true,e.add(s);const i=new Y;i.setAttribute("position",new Z(new Array(24).fill(0),3));const a=new ne({color:8246268,transparent:true,opacity:.95,depthWrite:false}),o=new Q(i,a);o.visible=false,o.renderOrder=4,o.userData.previewMeasurementHelper=true,e.add(o);const u=new Y,l=new Ve({color:3718648,transparent:true,opacity:.22,side:Te,depthWrite:false}),c=new $(u,l);c.visible=false,c.renderOrder=3.5,c.userData.previewMeasurementHelper=true,e.add(c);const d=new Y,h=new Ve({color:3718648,transparent:true,opacity:.1,side:Te,depthWrite:false}),f=new $(d,h);f.visible=false,f.renderOrder=2.8,f.userData.previewMeasurementHelper=true,e.add(f);const m=new Y;m.setAttribute("position",new Z(new Array(72).fill(0),3));const g=new ne({color:3718648,transparent:true,opacity:.7,depthWrite:false}),w=new Q(m,g);w.visible=false,w.renderOrder=3,w.userData.previewMeasurementHelper=true,e.add(w),this.modelGroup.add(e),this.sectionHelperGroup=e,this.sectionPlaneHelperGeometry=t,this.sectionPlaneHelperMaterial=r,this.sectionPlaneHelper=s,this.sectionPlaneOutlineGeometry=i,this.sectionPlaneOutlineMaterial=a,this.sectionPlaneOutline=o,this.sectionPlaneFillGeometry=u,this.sectionPlaneFillMaterial=l,this.sectionPlaneFill=c,this.sectionBoxFillGeometry=d,this.sectionBoxFillMaterial=h,this.sectionBoxFill=f,this.sectionBoxHelperGeometry=m,this.sectionBoxHelperMaterial=g,this.sectionBoxHelper=w}updateSectionHelpers(e){if(this.ensureSectionHelpers(),!(!this.sectionPlaneHelper||!this.sectionPlaneOutline||!this.sectionPlaneFill||!this.sectionBoxFill||!this.sectionBoxHelper||!this.modelGroup)){if(!(e!=null&&e.active)){this.sectionPlaneHelper.visible=false,this.sectionPlaneOutline.visible=false,this.sectionPlaneFill.visible=false,this.sectionBoxFill.visible=false,this.sectionBoxHelper.visible=false;return}if(e.mode==="box"){this.sectionPlaneHelper.visible=false,this.sectionPlaneOutline.visible=false,this.sectionPlaneFill.visible=false,this.updateSectionBoxHelper(e),this.updateSectionBoxFill(e),this.sectionBoxHelper.visible=true;return}}}updateSectionPlaneMesh(e){if(!this.sectionPlaneHelper)return;const t=di(e,this.sectionBounds),r=Math.max(t.width,.001)*1.02,s=Math.max(t.height,.001)*1.02;switch(this.sectionPlaneHelper.position.set(0,0,0),this.sectionPlaneHelper.rotation.set(0,0,0),e.axis){case"x":this.sectionPlaneHelper.position.x=e.offset,this.sectionPlaneHelper.rotation.y=Math.PI/2;break;case"y":this.sectionPlaneHelper.position.y=e.offset,this.sectionPlaneHelper.rotation.x=Math.PI/2;break;case"z":default:this.sectionPlaneHelper.position.z=e.offset;break}this.sectionPlaneHelper.scale.set(r,s,1)}updateSectionPlaneDetail(e){if(!this.sectionPlaneOutlineGeometry||!this.sectionPlaneOutline||!this.sectionPlaneFill||!this.modelGroup)return;const t=this.resolveSectionHelperCacheEntry(e),r=t!=null&&t.outlinePoints.length?t.outlinePoints:hi(e,this.sectionBounds),s=this.sectionPlaneOutlineGeometry.getAttribute("position"),i=r.length/3;if(s.count!==i)this.sectionPlaneOutlineGeometry.setAttribute("position",new Z(r,3)),this.sectionPlaneOutlineGeometry.computeBoundingSphere();else{for(let o=0;o<r.length;o+=3)s.setXYZ(o/3,r[o],r[o+1],r[o+2]);s.needsUpdate=true,this.sectionPlaneOutlineGeometry.computeBoundingSphere()}this.sectionPlaneOutline.visible=true;const a=t!=null&&t.fillData?yi(t.fillData):void 0;if(!a){this.sectionPlaneFill.visible=false;return}this.replaceSectionPlaneFillGeometry(a),this.sectionPlaneFill.visible=true}resolveSectionHelperCacheEntry(e){const t=Ue(e),r=this.sectionHelperCache.get(t);if(r)return this.sectionHelperCache.delete(t),this.sectionHelperCache.set(t,r),r;const s=Ai(e,this.sectionSourceGeometry,this.modelGroup);if(!s.length)return;const i=fi(e.axis,s),a={outlinePoints:i.loops.length||i.chains.length?[...i.loops.flatMap(o=>Be(o)),...i.chains.flatMap(o=>mi(o))]:s,fillData:i.loops.length?bi(e.axis,i.loops):void 0};for(this.sectionHelperCache.set(t,a);this.sectionHelperCache.size>Or;){const o=this.sectionHelperCache.keys().next().value;if(typeof o!="string")break;this.sectionHelperCache.delete(o)}return a}clearSectionHelperCache(){this.sectionHelperCache.clear(),this.appliedSectionHelperKey=null,this.appliedSectionClippingKey=null,this.lastSectionHelperUpdateAt=Number.NEGATIVE_INFINITY}replaceSectionPlaneFillGeometry(e){if(!this.sectionPlaneFill){e.dispose();return}const t=this.sectionPlaneFillGeometry;this.sectionPlaneFill.geometry=e,this.sectionPlaneFillGeometry=e,t==null||t.dispose()}replaceSectionBoxFillGeometry(e){if(!this.sectionBoxFill){e.dispose();return}const t=this.sectionBoxFillGeometry;this.sectionBoxFill.geometry=e,this.sectionBoxFillGeometry=e,t==null||t.dispose()}updateSectionBoxFill(e){if(!this.sectionBoxFill)return;const t=vi(e,this.sectionBounds);if(!t){this.sectionBoxFill.visible=false;return}this.replaceSectionBoxFillGeometry(t),this.sectionBoxFill.visible=true}updateSectionBoxHelper(e){if(!this.sectionBoxHelperGeometry)return;const t=e.range??xe(this.sectionBounds),[r,s]=t.x,[i,a]=t.y,[o,u]=t.z,l=[[r,i,o],[s,i,o],[s,a,o],[r,a,o],[r,i,u],[s,i,u],[s,a,u],[r,a,u]],c=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],d=[];for(const[f,m]of c)d.push(...l[f],...l[m]);const h=this.sectionBoxHelperGeometry.getAttribute("position");for(let f=0;f<d.length;f+=3)h.setXYZ(f/3,d[f],d[f+1],d[f+2]);h.needsUpdate=true,this.sectionBoxHelperGeometry.computeBoundingSphere()}findNodeObject(e){var r;let t;return(r=this.modelGroup)==null||r.traverse(s=>{const i=s;i.userData.previewNodeId===e&&(t=i)}),t}applyNodeVisibility(e,t){e.traverse(r=>{const s=r;s.userData.previewOriginalVisible=t,r.visible=t})}focusNode(e){if(!this.modelGroup)return;if(!e){if(this.state.isolatedMaterialKey){const o=Xs(this.modelGroup);if(!o.isEmpty()){const u=o.getCenter(new E),l=o.getSize(new E);this.modelRadius=Math.max(l.x,l.y,l.z,1)*.72,this.distance=Math.max(this.modelRadius*2.6,this.baseDistance*.24),this.modelGroup.position.copy(this.baseModelGroupPosition).sub(u),this.updateCamera();return}}const a=this.state.explode??0;this.modelRadius=this.baseModelRadius+this.maxExplodeOffset*a,this.distance=Math.max(this.modelRadius*1.25,this.modelRadius*2.6/this.state.scale),this.modelGroup.position.copy(this.baseModelGroupPosition),this.updateCamera();return}let t;if(this.modelGroup.traverse(a=>{a.userData.previewNodeId===e&&(t=a)}),!t)return;const r=new te().setFromObject(t);if(r.isEmpty())return;const s=r.getCenter(new E),i=r.getSize(new E);this.modelRadius=Math.max(i.x,i.y,i.z,1)*.72,this.distance=Math.max(this.modelRadius*2.6,this.baseDistance*.24),this.modelGroup.position.copy(this.baseModelGroupPosition).sub(s),this.updateCamera()}applyAppearanceState(){var e;(e=this.modelGroup)==null||e.traverse(t=>{const r=t;if(typeof r.userData.previewOriginalVisible!="boolean"&&(r.userData.previewOriginalVisible=t.visible),r.userData.previewMeasurementHelper)return;if(r.userData.previewEdgeHelper){const a=this.findObjectById(r.userData.previewEdgeSourceId),o=a?!!a.userData.previewOriginalVisible&&this.matchesActiveMaterialFilter(a):true;t.visible=r.userData.previewOriginalVisible&&o&&this.displayMode!=="shaded",this.applySelectionMaterialState(t,{emphasized:false,dimmed:!!(this.state.selectedNodeId&&a&&a.userData.previewNodeId!==this.state.selectedNodeId)});return}const s=!!(this.state.selectedNodeId&&r.userData.previewNodeId===this.state.selectedNodeId),i=!!(this.state.selectedNodeId&&r.userData.previewNodeId&&r.userData.previewNodeId!==this.state.selectedNodeId);t.visible=r.userData.previewOriginalVisible&&this.matchesActiveMaterialFilter(t),this.applySelectionMaterialState(t,{emphasized:s&&t.visible,dimmed:i&&t.visible})})}matchesActiveMaterialFilter(e){const t=this.state.isolatedMaterialKey;if(!t)return true;const r=ht(e);return r.length?r.includes(t):true}captureMaterialRuntimeState(e){e.traverse(t=>{const r=t,s=Array.isArray(r.material)?r.material:r.material?[r.material]:[];for(const i of s)this.materialRuntimeState.has(i)||this.materialRuntimeState.set(i,{opacity:i.opacity,transparent:i.transparent,wireframe:"wireframe"in i?!!i.wireframe:void 0,depthWrite:i.depthWrite,...i instanceof V?{emissiveHex:i.emissive.getHex(),emissiveIntensity:i.emissiveIntensity}:{}})})}applySelectionMaterialState(e,t){const r=e,s=Array.isArray(r.material)?r.material:r.material?[r.material]:[];for(const i of s){const a=this.materialRuntimeState.get(i)??{opacity:i.opacity,transparent:i.transparent,wireframe:"wireframe"in i?!!i.wireframe:void 0,depthWrite:i.depthWrite},o=this.displayMode==="xray"?Math.min(a.opacity,.26):a.opacity,u=a.transparent||o<1,l=this.displayMode==="xray"?false:a.depthWrite??true;if(i instanceof V){i.wireframe=this.displayMode==="wireframe",i.emissive.setHex(t.emphasized?1920728:a.emissiveHex??0),i.emissiveIntensity=t.emphasized?Math.max(a.emissiveIntensity??0,.42):a.emissiveIntensity??0,i.opacity=t.dimmed?Math.min(o,.28):o,i.transparent=u||i.opacity<1,i.depthWrite=l,i.needsUpdate=true;continue}(i instanceof ne||i instanceof Pe)&&(i.opacity=t.dimmed?Math.min(o,.24):o,i.transparent=u||i.opacity<1,i.depthWrite=l,i.needsUpdate=true)}}attachEdgeHelpers(e){e.traverse(t=>{if(!(t instanceof $||t instanceof Ee))return;const r=t.geometry;if(!r||!r.getAttribute("position"))return;const s=new vt(r,35),i=new ne({color:14412542,transparent:true,opacity:.22,depthWrite:false}),a=new Q(s,i);a.renderOrder=2,a.userData.previewEdgeHelper=true,a.userData.previewEdgeSourceId=t.id,a.userData.previewOriginalVisible=t.visible,t.add(a)})}findObjectById(e){if(!this.modelGroup||typeof e!="number")return;let t;return this.modelGroup.traverse(r=>{!t&&r.id===e&&(t=r)}),t}applySceneBackground(e){const t=this.renderer,r=this.scene;if(!t||!r)return()=>{};const s=r.background;switch(e){case"white":r.background=new de(16777215),t.setClearColor(16777215,1);break;case"transparent":r.background=null,t.setClearColor(0,0);break;default:r.background=new de(1120295),t.setClearColor(1120295,1);break}return()=>{r.background=s,t.setClearColor(1120295,1)}}disposeScene(){var e,t,r,s,i;this.animationFrame&&(cancelAnimationFrame(this.animationFrame),this.animationFrame=0),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,window.removeEventListener("resize",this.resize),(t=this.interactionController)==null||t.abort(),this.interactionController=null,he(this.modelGroup,[this.geometry,this.edgeGeometry,this.measurementLineGeometry,this.measurementPointsGeometry,this.sectionPlaneHelperGeometry,this.sectionPlaneOutlineGeometry,this.sectionPlaneFillGeometry,this.sectionBoxFillGeometry,this.sectionBoxHelperGeometry],[this.material,this.edgeMaterial,this.measurementLineMaterial,this.measurementPointsMaterial,this.sectionPlaneHelperMaterial,this.sectionPlaneOutlineMaterial,this.sectionPlaneFillMaterial,this.sectionBoxFillMaterial,this.sectionBoxHelperMaterial]),this.renderer&&(this.renderer.clippingPlanes=[],this.renderer.localClippingEnabled=false),(r=this.renderer)==null||r.dispose(),this.stage.replaceChildren(),this.renderer=null,this.scene=null,this.camera=null,this.modelGroup=null,this.geometry=null,this.edgeGeometry=null,this.material=null,this.edgeMaterial=null,this.measurementLineGeometry=null,this.measurementLineMaterial=null,this.measurementLine=null,this.measurementPointsGeometry=null,this.measurementPointsMaterial=null,this.measurementPoints=null,this.sectionHelperGroup=null,this.sectionPlaneHelper=null,this.sectionPlaneHelperGeometry=null,this.sectionPlaneHelperMaterial=null,this.sectionPlaneOutlineGeometry=null,this.sectionPlaneOutlineMaterial=null,this.sectionPlaneOutline=null,this.sectionPlaneFillGeometry=null,this.sectionPlaneFillMaterial=null,this.sectionPlaneFill=null,this.sectionBoxFillGeometry=null,this.sectionBoxFillMaterial=null,this.sectionBoxFill=null,this.sectionBoxHelperGeometry=null,this.sectionBoxHelperMaterial=null,this.sectionBoxHelper=null,this.measurementHoverClientX=null,this.measurementHoverClientY=null,this.clearSectionHelperCache(),this.sectionBounds=Ge(),this.explodeTargets=[],this.maxExplodeOffset=0,this.materialRuntimeState=new WeakMap,this.state.modelTree=void 0,this.state.selectedNodeId=void 0,this.state.isolatedMaterialKey=void 0,this.state.measurement={active:false,status:"idle",snapMode:((s=this.state.measurement)==null?void 0:s.snapMode)??"surface",axisLock:((i=this.state.measurement)==null?void 0:i.axisLock)??"free"},this.state.section=ue(),this.state.capabilities.measure=false,this.state.capabilities.section=false,this.state.capabilities.explode=false,this.state.capabilities.materialFilter=false}emit(e,t){for(const r of this.listeners[e])r(t)}}function F(n){if(n!=null&&n.aborted)throw new DOMException("3D preview aborted.","AbortError")}function j(n,e,t){return e?new Promise((r,s)=>{let i=false;const a=()=>{i||(i=true,e.removeEventListener("abort",a),s(new DOMException("3D preview aborted.","AbortError")))};e.addEventListener("abort",a,{once:true}),e.aborted&&a(),n.then(o=>{if(i){t==null||t(o);return}i=true,e.removeEventListener("abort",a),r(o)},o=>{i||(i=true,e.removeEventListener("abort",a),s(o))}).catch(()=>{})}):n}function he(n,e=[],t=[]){const r=new Set(e.filter(l=>!!l)),s=new Set(t.filter(l=>!!l)),i=new Set,a=new Set,o=new Set;for(const l of Array.isArray(n)?n:n?[n]:[])l.traverse(c=>{const d=c;d.geometry&&r.add(d.geometry);for(const h of Array.isArray(d.material)?d.material:d.material?[d.material]:[])s.add(h);if(d.skeleton&&a.add(d.skeleton),Array.isArray(c.userData.previewObjectUrls)){for(const h of c.userData.previewObjectUrls)typeof h=="string"&&h.startsWith("blob:")&&o.add(h);delete c.userData.previewObjectUrls}});const u=l=>{l&&typeof l=="object"&&l.isTexture?i.add(l):Array.isArray(l)&&l.forEach(u)};for(const l of s){Object.values(l).forEach(u);const c=l.uniforms;if(c)for(const d of Object.values(c))u(d.value)}for(const l of a)l.boneTexture&&i.delete(l.boneTexture),l.dispose();for(const l of r)l.dispose();for(const l of s)l.dispose();for(const l of i)l.dispose();for(const l of o)URL.revokeObjectURL(l)}function ta(){return{id:"model3d",family:"model3d",supports:n=>ot.has(Sn(n)),createSession:(n,e)=>new Rr(n,e)}}function na(n=_n()){return[...kr,...n.filter(e=>!e.extensions.some(t=>ot.has(t)))]}function Tr(n){const e=new Uint8Array(n);return Bi(e)?Ts(e):Rs(new TextDecoder().decode(e))}function Ir(n){const e=[],t=[],r=[],s=[],i=[],a=[];for(const o of n.split(/\r?\n/)){const u=o.trim();if(!u||u.startsWith("#"))continue;const l=u.split(/\s+/);if(l[0]==="v"){e.push([G(l[1]),G(l[2]),G(l[3])]),t.push(js(l));continue}if(l[0]==="vn"){r.push(ln([G(l[1]),G(l[2]),G(l[3])]));continue}if(l[0]!=="f"||l.length<4)continue;const c=l.slice(1).map(d=>zs(d,e.length,r.length)).filter(Boolean);if(!(c.length<3))for(let d=1;d<c.length-1;d+=1)Hs(c[0],c[d],c[d+1],e,t,r,s,i,a)}if(!s.length)throw new Error("No OBJ triangles found.");return Fe(s,i,a.length===s.length?a:void 0)}async function Br(n,e={}){F(e.signal);const t=rn(n);if(!t.length||!e.resourceResolver)return{object:new St().parse(n),warnings:[]};const r=[],s=[],i=[];let a=null,o;try{for(const l of t){const c=Ae(await ct(e.resourceResolver,{source:K(X(e.resourceBasePath??""),l),fallbackSource:l,relation:"material",sourceFormat:e.sourceFormat??"obj"},e.signal));if(F(e.signal),s.push(...c.warnings),!c.source){s.push(`OBJ material library "${l}" could not be resolved; materials were skipped.`);continue}const d=await Pn(c.source,e.signal);F(e.signal);const h=await ys(d,l,e,i);s.push(...h.warnings),r.push(h.text)}F(e.signal);const u=new St;if(r.length){const l=new fe,c=new Promise(d=>{l.onLoad=d});l.onError=()=>{s.push("An OBJ texture failed to load; the preview may be incomplete.")},l.itemStart("filens:obj-parse");try{o=new Xn(l).parse(r.join(`
6
- `),""),u.setMaterials(o),a=u.parse(n)}finally{l.itemEnd("filens:obj-parse")}await j(c,e.signal),F(e.signal),zr(a,Object.values(o.materials))}else a=u.parse(n);return{object:a,warnings:s}}catch(u){throw he(a,[],Object.values((o==null?void 0:o.materials)??{})),u}finally{for(const u of i)URL.revokeObjectURL(u)}}function zr(n,e){const t=new Set,r=new Set;n.traverse(s=>{const i=s.material;for(const a of Array.isArray(i)?i:i?[i]:[])t.add(a)});for(const s of t)for(const i of Object.values(s))i!=null&&i.isTexture&&r.add(i);for(const s of e)if(!t.has(s)){for(const i of Object.values(s))i!=null&&i.isTexture&&!r.has(i)&&(r.add(i),i.dispose());s.dispose()}}function rn(n){const e=[];for(const t of n.split(/\r?\n/)){const r=t.trim();if(!r||r.startsWith("#"))continue;const s=/^mtllib\s+(.+)$/i.exec(r);if(s!=null&&s[1])for(const i of s[1].trim().split(/\s+/))i&&e.push(i)}return[...new Set(e)]}function Hr(n){const e=new Uint8Array(n),t=Gs(e);if(t.format==="ascii")return Us(new TextDecoder().decode(e.slice(t.dataOffset)),t);if(t.format==="binary_little_endian")return _s(e,t);throw new Error(`Unsupported PLY format "${t.format}".`)}async function jr(n,e={}){F(e.signal);const t=await j(fr.loadAsync(n),e.signal);F(e.signal);const r=t.file("3D/3dmodel.model")??t.file(/(^|\/)3dmodel\.model$/i)[0];if(!r)throw new Error("3MF package is missing 3D/3dmodel.model.");const s=[r,...Object.values(t.files).filter(p=>!p.dir&&/\.model$/i.test(p.name)&&p.name!==r.name)],i=[];for(const p of s){const b=await j(p.async("text"),e.signal);F(e.signal);const y=new DOMParser().parseFromString(b,"application/xml");if(y.getElementsByTagName("parsererror")[0]){if(p===r)throw new Error("3MF model XML is invalid.");continue}i.push(y)}const a=new Map,o=new Set;for(const p of i){for(const[b,y]of Is(p))a.has(b)||a.set(b,y);for(const b of Bs(p))o.add(b)}const u=new Set,l=new Map,c=new Map;for(const p of i)for(const b of W(p,"object")){const y=b.getAttribute("id");if(!y)continue;const C=W(b,"mesh")[0],P=c.has(y);if(C){const S=W(C,"vertex").map(N=>[G(N.getAttribute("x")??void 0),G(N.getAttribute("y")??void 0),G(N.getAttribute("z")??void 0)]),L=[],k=[],D=Bt(b.getAttribute("pid"),b.getAttribute("pindex"),a);It(b.getAttribute("pid"),a,u);for(const N of W(C,"triangle")){const v=["v1","v2","v3"].map(x=>Number(N.getAttribute(x))).filter(x=>Number.isInteger(x)&&x>=0&&x<S.length);if(v.length!==3)continue;const O=N.getAttribute("pid")??b.getAttribute("pid");It(O,a,u);const A=["p1","p2","p3"].map(x=>Bt(O,N.getAttribute(x)??N.getAttribute("pindex")??b.getAttribute("pindex"),a)??D??[.49,.83,.99]);L.push(S[v[0]],S[v[1]],S[v[2]]),k.push(...A)}L.length&&!P&&c.set(y,{positions:L,colors:k})}(!l.has(y)||!P&&c.has(y))&&l.set(y,b)}for(const p of l.keys())an(p,l,c,new Set);const d=i[0],h=[],f=[],m=[],g=W(d,"item"),w=g.length?g:[...c.keys()].map(p=>({objectId:p}));for(const p of w){const b=p instanceof Element?p.getAttribute("objectid"):p.objectId,y=b?c.get(b):void 0;if(!(y!=null&&y.positions.length))continue;const C=p instanceof Element?on(p.getAttribute("transform")):rt;for(let P=0;P<y.positions.length;P+=3){const S=Ie(y.positions[P],C),L=Ie(y.positions[P+1],C),k=Ie(y.positions[P+2],C),D=dt(S,L,k),N=[y.colors[P]??[.49,.83,.99],y.colors[P+1]??[.49,.83,.99],y.colors[P+2]??[.49,.83,.99]];for(const v of[S,L,k])h.push(...v),f.push(...D);for(const v of N)m.push(...v)}}if(!h.length)throw new Error("No 3MF mesh triangles found.");for(const p of Array.from(u).map(b=>`3MF material resource "${b}" is not a supported color palette; fallback vertex colors were used.`))o.add(p);return{geometry:Fe(h,f,m),warnings:[...o]}}async function Gr(n,e={}){return sn(n,"",e.signal)}async function sn(n,e,t){F(t);const r=new wr,s=a=>{var o;return he((o=a.scenes)!=null&&o.length?a.scenes:[a.scene])},i=await j(r.parseAsync(n,e),t,s);return t!=null&&t.aborted&&(s(i),F(t)),i.scene}function Ur(n){return new Zn().parse(n)}function _r(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(a=>Fs(a,e,r,t));const i=new nn(s).parse(n,e.resourcePath??"").scene;return t.length&&(i.userData.previewObjectUrls=t),{object:i,warnings:r}}async function Vr(n,e={}){var h,f;F(e.signal);const t=await j(Vn(new Uint8Array(n)),e.signal);F(e.signal);const r=Kr([...t.values()].filter(m=>!m.directory).map(m=>m.name)),s=Yr(r),i=s?await j(t.get(s).text(),e.signal):void 0;F(e.signal);const a=[],o=Xr(r,s,i,a),u=await j(t.get(o).text(),e.signal);F(e.signal);const l=new DOMParser().parseFromString(u,"application/xml");if(l.getElementsByTagName("parsererror").length)throw new Error("KMZ Collada XML is invalid.");const c=new Map;for(const m of Array.from(l.getElementsByTagName("*"))){if(m.localName!=="image")continue;const g=(f=(h=Array.from(m.children).find(p=>p.localName==="init_from"))==null?void 0:h.textContent)==null?void 0:f.trim();if(!g)continue;const w=lt(r,g,o);w&&!c.has(w)&&(c.set(w,await j(t.get(w).bytes(),e.signal)),F(e.signal))}const d=$r(u,o,r,m=>c.get(m),a,e.signal);try{return await j(d.ready,e.signal),F(e.signal),{object:d.object,warnings:a}}catch(m){throw d.release(),he(d.object),m}finally{d.release()}}function $r(n,e,t,r,s,i){F(i);const a=new fe,o=[],u=new Map;let l;const c=()=>{for(const h of o.splice(0))URL.revokeObjectURL(h);(l==null?void 0:l.userData.previewObjectUrls)===o&&delete l.userData.previewObjectUrls},d=new Promise(h=>{a.onLoad=()=>{c(),h()}});a.onError=()=>{s.push("A KMZ texture failed to load; the preview may be incomplete.")},a.setURLModifier(h=>{F(i);const f=lt(t,h,e),m=u.get(f??h);if(m)return m;const g=f?r(f):void 0;if(g){const w=new Uint8Array(g.byteLength);w.set(g);const p=URL.createObjectURL(new Blob([w.buffer],{type:qr(f)}));return u.set(f,p),o.push(p),p}return/^[a-z][a-z\d+.-]*:/i.test(h)&&!/^file:/i.test(h)?h:(s.push(`KMZ texture "${h}" could not be resolved; dependent appearance may be missing.`),'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="1" height="1"%3E%3Cpath fill="white" d="M0 0h1v1H0z"/%3E%3C/svg%3E')}),a.itemStart("filens:kmz-parse");try{l=new nn(a).parse(n,"").scene,o.length&&(l.userData.previewObjectUrls=o),Wr(l)||s.push("KMZ Collada model contains no renderable geometry.")}catch(h){throw c(),h}finally{a.itemEnd("filens:kmz-parse")}return{object:l,ready:d,release:c}}function Wr(n){let e=false;return n.traverse(t=>{var r,s;(s=(r=t.geometry)==null?void 0:r.getAttribute("position"))!=null&&s.count&&(e=true)}),e}function nt(n){const e=[];for(const t of n.replace(/\\/g,"/").split("/"))!t||t==="."||(t===".."?e.pop():e.push(t));return e.join("/")}function Kr(n){return new Map(n.map(e=>[nt(e),e]))}function lt(n,e,t=""){let r=e.trim().replace(/\\/g,"/").split(/[?#]/,1)[0]??"";if(/^[a-z][a-z\d+.-]*:/i.test(r))return;try{r=decodeURIComponent(r)}catch{}const s=t.slice(0,t.lastIndexOf("/")+1),i=[...new Set([...r.startsWith("/")?[]:[nt(s+r)],nt(r)])];for(const u of i){const l=n.get(u);if(l)return l}for(const u of i){const l=[...n].filter(([c])=>c.toLowerCase()===u.toLowerCase());if(l.length===1)return l[0][1]}const a=i[i.length-1].toLowerCase(),o=[...n].filter(([u])=>u.toLowerCase().endsWith("/"+a));return o.length===1?o[0][1]:void 0}function Yr(n){return n.get("doc.kml")??[...n.values()].find(e=>/^doc\.kml$/i.test(e))??[...n.values()].find(e=>/(^|\/)doc\.kml$/i.test(e))??[...n.values()].find(e=>/\.kml$/i.test(e))}function Xr(n,e,t,r){const s=t?Zr(t):void 0,i=s?lt(n,s,e):void 0,a=[...n.values()].find(u=>/\.dae$/i.test(u));s&&!i&&a&&r.push(`KMZ model "${s}" could not be resolved; using "${a}".`);const o=i??a;if(!o)throw new Error("KMZ archive does not contain a Collada (.dae) model.");return o}function Zr(n){var t,r,s;const e=new DOMParser().parseFromString(n,"application/xml");if(!e.getElementsByTagName("parsererror").length)for(const i of Array.from(e.getElementsByTagName("*"))){if(((t=i.localName)==null?void 0:t.toLowerCase())!=="model")continue;const a=Array.from(i.children).find(u=>u.localName.toLowerCase()==="link"),o=a&&((s=(r=Array.from(a.children).find(u=>u.localName.toLowerCase()==="href"))==null?void 0:r.textContent)==null?void 0:s.trim());if(o&&/\.dae(?:[?#].*)?$/i.test(o))return o}}function qr(n){var t;switch((t=n.split(".").pop())==null?void 0:t.toLowerCase()){case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"webp":return"image/webp";case"bmp":return"image/bmp";case"tga":return"image/x-tga";case"dds":return"image/vnd-ms.dds";default:return"application/octet-stream"}}function Jr(n){const e=new lr().parse(n);if(!e)throw new Error("Invalid MD2 model data.");return e.hasAttribute("normal")||e.computeVertexNormals(),new $(e,new V({color:8246268,roughness:.58,metalness:.04}))}function Qr(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(u=>Ls(u,e,r,t));const a=new cr(s).parse(n,e.resourcePath??"",e.modelName??"model"),o=new ee;for(const u of a.meshes??[])o.add(u);if(!o.children.length){for(const u of t)URL.revokeObjectURL(u);throw new Error("No LWO meshes found.")}return t.length&&(o.userData.previewObjectUrls=t),{object:o,warnings:r}}function es(n){const t=new ur().parse(n).skeleton.bones[0];if(!t)throw new Error("No BVH skeleton bones found.");const r=new ee;r.add(t);const s=new dr(t),i=s.material;for(const a of Array.isArray(i)?i:[i])a.color.set(8246268);return r.add(s),r}function ts(n){var r,s;const e=new hr().parse(n),t=new ee;if((r=e.geometryAtoms.getAttribute("position"))!=null&&r.count&&t.add(new me(e.geometryAtoms,new Pe({size:.6,color:16777215,vertexColors:true}))),(s=e.geometryBonds.getAttribute("position"))!=null&&s.count&&t.add(new Q(e.geometryBonds,new ne({color:14412542,transparent:true,opacity:.72}))),!t.children.length)throw new Error("No PDB atoms found.");return t}function ns(n){const e=Ps(n),t=new mr().parse(e.buffer),r=t.xLength*t.yLength*t.zLength;if(!Number.isSafeInteger(r)||r<1||t.data.length!==r)throw new Error("NRRD voxel data length does not match its dimensions.");if((e.encoding==="raw"||e.encoding==="gz"||e.encoding==="gzip")&&e.endian){const m=new Uint8Array(new Uint16Array([1]).buffer)[0]===1?"little":"big";if(e.endian!==m){const g=new Uint8Array(t.data.buffer,t.data.byteOffset,t.data.byteLength),w=t.data.BYTES_PER_ELEMENT;for(let p=0;p<g.length;p+=w)for(let b=p,y=p+w-1;b<y;b++,y--){const C=g[b];g[b]=g[y],g[y]=C}}}const[s,i]=t.computeMinMax(),a=i-s,o=s<=0&&i>0?0:a>0?s+a*.5:s,l=Math.max(1,Math.ceil(r/6e4)),c=t.spacing.length>=3?t.spacing:[1,1,1],d=[],h=[];for(let m=0;m<r;m+=l){const g=Number(t.data[m]);if(!Number.isFinite(g)||g<o)continue;const w=m%t.xLength,p=Math.floor(m/t.xLength),b=p%t.yLength,y=Math.floor(p/t.yLength);d.push(w*c[0],b*c[1],y*c[2]);const C=a>0?_((g-s)/a,0,1):1;h.push(.22+C*.64,.3+C*.55,.4+C*.52)}if(!d.length)throw new Error("No NRRD voxels passed the preview threshold.");const f=new Y;return f.setAttribute("position",new Z(d,3)),f.setAttribute("color",new Z(h,3)),new me(f,new Pe({size:Math.max(Math.min(...c.filter(m=>m>0)),1)*.75,vertexColors:true}))}async function rs(n,e={}){F(e.signal);const t=Ss(n);if(!t)return new TextEncoder().encode(n).buffer;const r=e.resourceResolver;if(!r)throw new Error(`NHDR references external data file "${t}" but no resourceResolver was provided.`);const s=X(e.resourceBasePath??""),i=Ae(await ct(r,{source:K(s,t),fallbackSource:t,relation:"volume",sourceFormat:e.sourceFormat??"nhdr"},e.signal));if(!i.source)throw new Error(`NHDR external data file "${t}" could not be resolved.`);const a=await ut(i.source,e.signal);return F(e.signal),Cs(n,a)}function ss(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(a=>As(a,e,r,t));const i=new qn(s).parse(n,e.resourcePath??"");return t.length&&(i.userData.previewObjectUrls=t),{object:i,warnings:r}}function is(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(a=>Ds(a,e,r,t));const i=new Jn(s).parse(n,e.resourcePath??"");return t.length&&(i.userData.previewObjectUrls=t),{object:i,warnings:r}}async function as(n){return new Qn().parse(n)}async function os(n,e={}){var a;if(F(e.signal),!Me){const o=Promise.resolve().then(()=>Zi).then(({createRustStepImporter:u})=>u());Me=o,o.catch(()=>{Me===o&&(Me=null)})}const t=await j(Me,e.signal);F(e.signal);const r=t.ReadStepFile(new Uint8Array(n),{linearUnit:"millimeter"},e.signal),s=await j(Promise.resolve(r),e.signal);if(F(e.signal),!s.success||!s.root||!((a=s.meshes)!=null&&a.length))throw new Error("Rust STEP could not read this STEP file.");const i=new ee;i.userData.stepEngine="rust",i.userData.previewWarnings=s.warnings??[];for(const o of s.root.meshes){const u=s.meshes[o];if(!u)continue;const l=new Y;l.setAttribute("position",new Z(u.attributes.position.array,3)),u.attributes.normal?l.setAttribute("normal",new Z(u.attributes.normal.array,3)):l.computeVertexNormals(),u.index&&l.setIndex(u.index.array),i.add(new $(l,new V({color:new de(.72,.76,.82),side:Te})))}return i}function ls(n){return new er().parse(n)}function cs(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(a=>Es(a,e,r,t));const i=new tr(s).parse(n,e.resourcePath??"");return t.length&&(i.userData.previewObjectUrls=t),{object:i,warnings:r}}function us(n){return new nr().parse(n)}function ds(n){const e=new rr().parse(n),t=e.hasAttribute("color");return new me(e,new Pe({size:.08,color:t?16777215:8246268,vertexColors:t}))}function hs(n){const e=new sr().parse(ms(n),"");return e.hasAttribute("normal")||e.computeVertexNormals(),new $(e,new V({color:e.hasAttribute("color")?16777215:8246268,roughness:.58,metalness:.04,vertexColors:e.hasAttribute("color")}))}function ms(n){const e=typeof n=="string"?new TextEncoder().encode(n):new Uint8Array(n);if(e.byteLength>=kt)return typeof n=="string"?e.buffer:n;const t=new Uint8Array(kt);return t.fill(32),t.set(e),t[t.length-1]=10,t.buffer}function fs(n){const e=new ir().parse(n),t=new ee;for(const r of e??[])r&&t.add(new ar(r));return t}async function ps(n,e={}){var r;F(e.signal);const t=[];try{const s=await xs(n,e,t);F(e.signal);const i=new Nr;i.setConditionalLineMaterial(or),i.setMaterials([]);const a=new Promise((u,l)=>{i.parse(s,c=>u(c),c=>l(c))}),o=await j(a,e.signal,he);return(r=e.signal)!=null&&r.aborted&&(he(o),F(e.signal)),{object:o,warnings:t}}catch(s){throw t.length&&!(s&&typeof s=="object"&&"name"in s&&s.name==="AbortError")?new Error(`${s instanceof Error?s.message:String(s)} Warnings: ${t.join(" ")}`):s}}async function gs(n,e={}){F(e.signal);const t=[];try{const r=typeof n=="string"?n:new TextDecoder().decode(n),s=Ui(r),i=ws(s),a=i.length&&e.resourceResolver?await bs(s,i,e,t):{json:s,warnings:[],unresolvedResources:i},o=a.unresolvedResources;if(o.length&&!e.resourcePath)throw new Error(`glTF references external resources that are not bundled with this preview: ${o.join(", ")}.`);return F(e.signal),{object:await sn(JSON.stringify(a.json),e.resourcePath??"",e.signal),warnings:a.warnings}}finally{for(const r of t)URL.revokeObjectURL(r)}}function ws(n){if(!n||typeof n!="object")return[];const e=n,t=[...(e.buffers??[]).map(r=>r.uri),...(e.images??[]).filter(r=>r.bufferView==null).map(r=>r.uri)];return[...new Set(t.filter(r=>typeof r=="string"&&r.trim().length>0).map(r=>r.trim()).filter(r=>!_i(r)))]}async function bs(n,e,t,r){var u;const s=Ns(n),i=[],a=new Map,o=[];for(const l of e){F(t.signal);const c=await j(Promise.resolve((u=t.resourceResolver)==null?void 0:u.call(t,{family:"model3d",sourceFormat:t.sourceFormat??"gltf",source:l,relation:ks(s,l),name:l.split(/[\\/]/).pop()??l})),t.signal);F(t.signal);const d=pe(c,Ln(l),r);i.push(...d.warnings),d.source?a.set(l,d.source):o.push(l)}return Os(s,a),{json:s,warnings:i,unresolvedResources:o}}async function ys(n,e,t,r){var o;const s=X(K(X(t.resourceBasePath??""),e)),i=[],a=[];for(const u of n.split(/\r?\n/)){const l=Ms(u);if(!l||!t.resourceResolver){i.push(u);continue}if((o=t.signal)!=null&&o.aborted)throw new DOMException("3D preview aborted.","AbortError");const c=await ct(t.resourceResolver,{source:K(s,l.path),fallbackSource:l.path,relation:"texture",sourceFormat:t.sourceFormat??"obj"},t.signal);F(t.signal);const d=pe(c,q(l.path),r);if(a.push(...d.warnings),!d.source){a.push(`OBJ texture "${l.path}" could not be resolved; the material map was left unchanged.`),i.push(u);continue}i.push(`${l.prefix}${d.source}`)}return{text:i.join(`
7
- `),warnings:a}}async function ct(n,e,t){F(t);const r=await j(Promise.resolve(n({family:"model3d",sourceFormat:e.sourceFormat,source:e.source,relation:e.relation,name:e.source.split(/[\\/]/).pop()??e.source})),t);return F(t),Ae(r).source||e.fallbackSource===e.source?r:j(Promise.resolve(n({family:"model3d",sourceFormat:e.sourceFormat,source:e.fallbackSource,relation:e.relation,name:e.fallbackSource.split(/[\\/]/).pop()??e.fallbackSource})),t)}function vs(n,e){const t=[];let r=e,s=[],i=false,a=false;for(const o of n.replace(/^\uFEFF/,"").replace(/\r\n?/g,`
8
- `).split(`
9
- `)){const u=/^\s*0\s+FILE\s+(.+?)\s*$/i.exec(o);u?(i&&(t.push({name:r,text:s.join(`
10
- `)+`
11
- `}),s=[]),r=u[1],i=true,a=false):/^\s*0\s+NOFILE\s*$/i.test(o)?a=true:a||s.push(o)}return t.push({name:r,text:s.join(`
12
- `)+`
13
- `}),t}async function xs(n,e,t){const r=X(e.resourceBasePath??""),s=new Map,i=new Map,a=new Map,o=f=>r&&f.startsWith(`${r}/`)?f.slice(r.length+1):f,u=(f,m,g,w)=>{const p=vs(f,g??"__filens_main__.ldr"),b=new Map;let y;for(let C=0;C<p.length;C++){const P=p[C],S=Ye(P.name),L=C===0&&w?o(w):Ye(g?o(K(m,S)):S),k=L.toLowerCase();let D=s.get(k);D||(D={name:L,text:P.text,directory:C===0&&g?m:X(K(m,S)),definitions:b},s.set(k,D)),b.set(S.toLowerCase(),D),C===0&&(y=D,g&&b.set(g.toLowerCase(),D))}return y},l=u(n,r),c=new Set,d=new Set,h=async f=>{if(F(e.signal),c.has(f))throw new Error(`Cyclic LDraw part reference: "${f.name}".`);if(d.has(f))return;c.add(f);const m=f.text.split(`
14
- `);for(let g=0;g<m.length;g++){const w=/^(\s*1\s+(?:\S+\s+){13})(.+?)\s*$/.exec(m[g]);if(!w)continue;const p=Ye(w[2]),b=p.toLowerCase();let y=f.definitions.get(b)??l.definitions.get(b);if(!y&&e.resourceResolver){const C=/^(?:parts\/s|p\/48)\//i.test(p),P=[...new Set([K(C?r:f.directory,p),K(r,p),p])],S=P[0].toLowerCase();y=a.get(S);for(const L of P){if(y||(y=i.get(L.toLowerCase()),y))break;const k=Ae(await j(Promise.resolve(e.resourceResolver({family:"model3d",sourceFormat:e.sourceFormat??"ldr",source:L,relation:"part",name:L.split("/").pop()??L})),e.signal));if(F(e.signal),t.push(...k.warnings),!k.source)continue;const D=await Pn(k.source,e.signal);F(e.signal),y=u(D,X(L),p,L),i.set(L.toLowerCase(),y);break}y||(t.push(`LDraw part "${w[2]}" could not be resolved; dependent geometry may be missing.`),y=u(`0 !LDRAW_ORG Subpart
15
- `,f.directory,p,P[0])),a.set(S,y)}y&&(m[g]=`${w[1]}${y.name}`,await h(y))}f.text=m.join(`
16
- `),c.delete(f),d.add(f)};return await h(l),F(e.signal),[...new Set(s.values())].map(f=>`0 FILE ${f.name}
17
- ${f.text}`).join(`
18
- `)}function Ms(n){const e=/^(\s*(?:map_\S+|bump|norm|disp)\s+)(.+?)\s*$/i.exec(n);if(!(e!=null&&e[1])||!e[2])return;let t=e[1],r=e[2];const s={"-bm":1,"-mm":2,"-s":3,"-o":3};for(;;){const i=/^(\S+)\s+/.exec(r),a=i&&s[i[1]];if(!a)break;const o=new RegExp(`^\\S+(?:\\s+\\S+){${a}}\\s+`).exec(r);if(!o)break;t+=o[0],r=r.slice(o[0].length)}return r?{prefix:t,path:r}:void 0}function Ss(n){for(const e of n.split(/\r?\n/)){const t=e.trim();if(!t||t.startsWith("#"))continue;const r=/^data\s*file\s*:\s*(.+)$/i.exec(t)??/^datafile\s*:\s*(.+)$/i.exec(t);if(!(r!=null&&r[1]))continue;const s=r[1].trim();if(!s||/[\s%]/.test(s))throw new Error(`NHDR data file reference "${s}" is not supported for direct preview yet.`);return s}}function Cs(n,e){const t=n.split(/\r?\n/),r=[];let s=false,i=false;for(const c of t){if(!c.trim())break;if(/^\s*data\s*file\s*:/i.test(c)||/^\s*datafile\s*:/i.test(c)){s=true;continue}/^\s*encoding\s*:/i.test(c)&&(i=true),r.push(c)}if(!s)return new TextEncoder().encode(n).buffer;i||r.push("encoding: raw");const a=r.join(`
19
- `).replace(/\s+$/,""),o=new TextEncoder().encode(`${a}
20
- #
21
-
22
- `),u=new Uint8Array(e),l=new Uint8Array(o.byteLength+u.byteLength);return l.set(o,0),l.set(u,o.byteLength),l.buffer}function Ps(n){const e=new Uint8Array(n);let t=0;for(let r=0;r<e.length;r++){if(e[r]!==10)continue;if((e[r-1]===13?r-1:r)!==t){t=r+1;continue}const i=new TextDecoder().decode(e.subarray(0,t)),a=new Map(i.split(/\r?\n/).flatMap(d=>{const h=/^([^:#]+):\s*(.*)$/.exec(d);return h?[[h[1].trim().toLowerCase(),h[2].trim().toLowerCase()]]:[]}));for(const d of["line skip","byte skip"])if(a.has(d)&&a.get(d)!=="0")throw new Error(`NRRD ${d} is not supported for preview.`);if(a.get("dimension")!=="3")throw new Error("NRRD preview requires three scalar dimensions.");const o=a.get("encoding");if(!["raw","gz","gzip","ascii","text","txt","hex"].includes(o??""))throw new Error(`NRRD encoding "${o??""}" is not supported for preview.`);const u=a.get("endian");if(u&&u!=="little"&&u!=="big")throw new Error(`Unsupported NRRD endian "${u}".`);if(!i.includes("\r")&&/\n#[^\n]*\n$/.test(i))return{buffer:n,encoding:o,endian:u};const l=new TextEncoder().encode(`${i.replace(/\r\n/g,`
23
- `).trimEnd()}
24
- #
25
-
26
- `),c=new Uint8Array(l.length+e.length-r-1);return c.set(l),c.set(e.subarray(r+1),l.length),{buffer:c.buffer,encoding:o,endian:u}}return{buffer:n}}function Ls(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"lwo",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`LWO texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`LWO texture "${a}" could not be resolved; default loader lookup was used.`),n}function Es(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"vrml",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`VRML texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`VRML texture "${a}" could not be resolved; default loader lookup was used.`),n}function Fs(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"dae",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`Collada texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`Collada texture "${a}" could not be resolved; default loader lookup was used.`),n}function As(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"fbx",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`FBX texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`FBX texture "${a}" could not be resolved; default loader lookup was used.`),n}function Ds(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"3ds",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`3DS texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`3DS texture "${a}" could not be resolved; default loader lookup was used.`),n}function Ye(n){const e=n.replace(/\\/g,"/").replace(/^\.\//,"");return/^s\//i.test(e)?`parts/${e}`:/^48\//i.test(e)?`p/${e}`:e}function Ns(n){return JSON.parse(JSON.stringify(n))}function Os(n,e){if(!n||typeof n!="object")return;const t=n;for(const r of t.buffers??[]){const s=typeof r.uri=="string"?e.get(r.uri.trim()):void 0;s!==void 0&&(r.uri=s)}for(const r of t.images??[]){const s=typeof r.uri=="string"?e.get(r.uri.trim()):void 0;r.bufferView==null&&s!==void 0&&(r.uri=s)}}function ks(n,e){if(!n||typeof n!="object")return"resource";const t=n;return(t.buffers??[]).some(r=>r.uri===e)?"buffer":(t.images??[]).some(r=>r.bufferView==null&&r.uri===e)?"image":"resource"}async function ut(n,e){if(F(e),typeof n=="string"){const t=s=>{var i;(i=s.body)==null||i.cancel().catch(()=>{})},r=await j(fetch(n,{signal:e}),e,t);try{if(F(e),!r.ok)throw new Error(`Failed to load 3D source: ${r.status} ${r.statusText}`.trim());return await j(r.arrayBuffer(),e)}catch(s){throw t(r),s}}if(n instanceof Blob)return j(n.arrayBuffer(),e);if(ArrayBuffer.isView(n)){const t=new Uint8Array(n.byteLength);return t.set(new Uint8Array(n.buffer,n.byteOffset,n.byteLength)),t.buffer}if(n instanceof ArrayBuffer)return n.slice(0);throw new Error("Unsupported 3D source type.")}function Rs(n){const e=[],t=[];let r=[0,0,1];const s=[];for(const i of n.split(/\r?\n/)){const a=i.trim().split(/\s+/);if(a[0]==="facet"&&a[1]==="normal"){r=[G(a[2]),G(a[3]),G(a[4])];continue}if(a[0]==="vertex"&&(s.push([G(a[1]),G(a[2]),G(a[3])]),s.length===3))for(const o of s.splice(0,3))e.push(...o),t.push(...r)}if(!e.length)throw new Error("No STL triangles found.");return Fe(e,t)}function Ts(n){if(n.byteLength<84)throw new Error("Binary STL is too small.");const e=new DataView(n.buffer,n.byteOffset,n.byteLength),t=e.getUint32(80,true);if(84+t*50>n.byteLength)throw new Error("Binary STL triangle data is truncated.");if(!t)throw new Error("No STL triangles found.");const s=new Float32Array(t*9),i=new Float32Array(t*9);let a=84;for(let o=0;o<t;o+=1){const u=e.getFloat32(a,true),l=e.getFloat32(a+4,true),c=e.getFloat32(a+8,true);a+=12;for(let d=0;d<3;d+=1){const h=o*9+d*3;s[h]=e.getFloat32(a,true),s[h+1]=e.getFloat32(a+4,true),s[h+2]=e.getFloat32(a+8,true),i[h]=u,i[h+1]=l,i[h+2]=c,a+=12}a+=2}return{positions:s,normals:i,triangleCount:t,bounds:hn(s)}}const rt=[1,0,0,0,1,0,0,0,1,0,0,0];function W(n,e){return Array.from(n.querySelectorAll("*")).filter(t=>t.localName===e)}function Tt(n,e){return Array.from(n.children).filter(t=>t.localName===e)}function an(n,e,t,r){const s=t.get(n);if(s)return s;if(r.has(n))return;const i=e.get(n);if(!i)return;r.add(n);const a=Tt(i,"components")[0];if(!a){r.delete(n);return}const o=[],u=[];for(const c of Tt(a,"component")){const d=c.getAttribute("objectid"),h=d?an(d,e,t,r):void 0;if(!(h!=null&&h.positions.length))continue;const f=on(c.getAttribute("transform"));for(let m=0;m<h.positions.length;m+=1)o.push(Ie(h.positions[m],f)),u.push(h.colors[m]??[.49,.83,.99])}if(r.delete(n),!o.length)return;const l={positions:o,colors:u};return t.set(n,l),l}function Is(n){const e=new Map;for(const t of W(n,"basematerials")){const r=t.getAttribute("id");r&&e.set(r,W(t,"base").map(s=>zt(s.getAttribute("displaycolor"))))}for(const t of W(n,"colorgroup")){const r=t.getAttribute("id");r&&e.set(r,W(t,"color").map(s=>zt(s.getAttribute("color"))))}return e}function Bs(n){return[...W(n,"texture2d").map(t=>["texture2d",t.getAttribute("id")]),...W(n,"texture2dgroup").map(t=>["texture2dgroup",t.getAttribute("id")]),...W(n,"compositematerials").map(t=>["composite materials",t.getAttribute("id")]),...W(n,"multiproperties").map(t=>["multi properties",t.getAttribute("id")])].filter(([,t])=>!!t).map(([t,r])=>`3MF ${t} resource "${r}" is not rendered directly yet; base-material colors remain supported.`)}function It(n,e,t){n&&!e.has(n)&&t.add(n)}function Bt(n,e,t){if(!n)return;const r=t.get(n);if(!(r!=null&&r.length))return;const s=Number(e??0);return Number.isInteger(s)&&s>=0&&s<r.length?r[s]:r[0]}function zt(n){const e=String(n??"").trim(),t=/^#?([0-9a-f]{6})(?:[0-9a-f]{2})?$/i.exec(e);if(!(t!=null&&t[1]))return[.49,.83,.99];const r=t[1];return[Number.parseInt(r.slice(0,2),16)/255,Number.parseInt(r.slice(2,4),16)/255,Number.parseInt(r.slice(4,6),16)/255]}function on(n){if(!n)return rt;const e=n.trim().split(/\s+/).map(Number);return e.length!==12||e.some(t=>!Number.isFinite(t))?rt:e}function Ie(n,e){return[n[0]*e[0]+n[1]*e[1]+n[2]*e[2]+e[9],n[0]*e[3]+n[1]*e[4]+n[2]*e[5]+e[10],n[0]*e[6]+n[1]*e[7]+n[2]*e[8]+e[11]]}function zs(n,e,t){const[r,,s]=n.split("/"),i=Ht(Number(r),e);if(i==null)return;const a=s?Ht(Number(s),t):void 0;return{vertexIndex:i,normalIndex:a}}function Hs(n,e,t,r,s,i,a,o,u){const l=[n,e,t],c=dt(r[n.vertexIndex],r[e.vertexIndex],r[t.vertexIndex]);for(const d of l){a.push(...r[d.vertexIndex]),o.push(...d.normalIndex!=null?i[d.normalIndex]??c:c);const h=s[d.vertexIndex];h&&u.push(...h)}}function js(n){if(n.length<7)return;const e=[Number(n[4]),Number(n[5]),Number(n[6])];if(!e.some(t=>!Number.isFinite(t)))return e.map(t=>_(t>1?t/255:t,0,1))}function Ht(n,e){if(!Number.isInteger(n)||n===0||e<=0)return;const t=n>0?n-1:e+n;return t>=0&&t<e?t:void 0}function dt(n,e,t){const r=e[0]-n[0],s=e[1]-n[1],i=e[2]-n[2],a=t[0]-n[0],o=t[1]-n[1],u=t[2]-n[2];return ln([s*u-i*o,i*a-r*u,r*o-s*a])}function ln(n){const e=Math.hypot(n[0],n[1],n[2]);return e?[n[0]/e,n[1]/e,n[2]/e]:[0,0,1]}function Gs(n){const e=$s(n);if(!e)throw new Error("PLY header is missing end_header.");const r=new TextDecoder().decode(n.slice(0,e.headerEnd)).replace(/\r/g,"").split(`
27
- `).map(c=>c.trim()).filter(Boolean);if(r[0]!=="ply")throw new Error("Invalid PLY header.");let s="",i=0,a=0,o;const u=[];let l;for(const c of r.slice(1)){const d=c.split(/\s+/);if(d[0]==="format"){s=d[1]??"";continue}if(d[0]==="element"){o=d[1]==="vertex"||d[1]==="face"?d[1]:void 0,d[1]==="vertex"&&(i=Number(d[2])||0),d[1]==="face"&&(a=Number(d[2])||0);continue}if(d[0]==="property"){if(o==="vertex"&&d.length>=3&&d[1]!=="list"){u.push({type:d[1],name:d[2]});continue}o==="face"&&d[1]==="list"&&d.length>=5&&!l&&(l={countType:d[2],itemType:d[3],name:d[4]})}}if(!s||!i||!a||!u.length||!l)throw new Error("PLY header does not define supported vertex and face data.");return{format:s,dataOffset:e.dataOffset,vertexCount:i,faceCount:a,vertexProperties:u,faceListProperty:l}}function Us(n,e){const t=n.replace(/\r/g,"").split(`
28
- `).map(f=>f.trim()).filter(Boolean),r=[],s=[];let i=0;const a=e.vertexProperties.findIndex(f=>f.name==="x"),o=e.vertexProperties.findIndex(f=>f.name==="y"),u=e.vertexProperties.findIndex(f=>f.name==="z"),l=un(e.vertexProperties);if(a<0||o<0||u<0)throw new Error("PLY vertex properties must include x, y, and z.");for(;i<e.vertexCount&&i<t.length;i+=1){const f=t[i].split(/\s+/);r.push([G(f[a]),G(f[o]),G(f[u])]),s.push(dn(f.map(Number),e.vertexProperties,l))}const c=[],d=[],h=[];for(let f=0;f<e.faceCount&&i<t.length;f+=1,i+=1){const m=t[i].split(/\s+/).map(Number),g=m[0]??0,w=m.slice(1,1+g).filter(p=>Number.isInteger(p));cn(w,r,s,c,d,h)}if(!c.length)throw new Error("No PLY triangles found.");return Fe(c,d,h.length===c.length?h:void 0)}function _s(n,e){const t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=[],s=[];let i=e.dataOffset;const a=e.vertexProperties.findIndex(f=>f.name==="x"),o=e.vertexProperties.findIndex(f=>f.name==="y"),u=e.vertexProperties.findIndex(f=>f.name==="z"),l=un(e.vertexProperties);if(a<0||o<0||u<0)throw new Error("PLY vertex properties must include x, y, and z.");for(let f=0;f<e.vertexCount;f+=1){const m=[];for(const g of e.vertexProperties){const w=Ze(t,i,g.type,true);m.push(w.value),i=w.nextOffset}r.push([m[a]??0,m[o]??0,m[u]??0]),s.push(dn(m,e.vertexProperties,l))}const c=[],d=[],h=[];for(let f=0;f<e.faceCount;f+=1){const m=Ze(t,i,e.faceListProperty.countType,true);i=m.nextOffset;const g=[];for(let w=0;w<m.value;w+=1){const p=Ze(t,i,e.faceListProperty.itemType,true);g.push(p.value),i=p.nextOffset}cn(g,r,s,c,d,h)}if(!c.length)throw new Error("No PLY triangles found.");return Fe(c,d,h.length===c.length?h:void 0)}function cn(n,e,t,r,s,i){const a=n.filter(o=>Number.isInteger(o)&&o>=0&&o<e.length);if(!(a.length<3))for(let o=1;o<a.length-1;o+=1){const u=e[a[0]],l=e[a[o]],c=e[a[o+1]],d=dt(u,l,c),h=[a[0],a[o],a[o+1]];for(const f of[u,l,c])r.push(...f),s.push(...d);for(const f of h){const m=t[f];m&&i.push(...m)}}}function un(n){const e=Xe(n,["red","diffuse_red","r"]),t=Xe(n,["green","diffuse_green","g"]),r=Xe(n,["blue","diffuse_blue","b"]);return e>=0&&t>=0&&r>=0?[e,t,r]:void 0}function Xe(n,e){return n.findIndex(t=>e.includes(t.name.toLowerCase()))}function dn(n,e,t){if(!t)return;const r=t.map(s=>n[s]??Number.NaN);if(!r.some(s=>!Number.isFinite(s)))return r.map((s,i)=>Vs(s,e[t[i]].type))}function Vs(n,e){return _(e==="float"||e==="float32"||e==="double"||e==="float64"?n>1?n/255:n:n/255,0,1)}function $s(n){const e=[new TextEncoder().encode(`end_header
29
- `),new TextEncoder().encode(`end_header\r
30
- `)];for(let t=0;t<n.length;t+=1)for(const r of e)if(Ws(n,r,t))return{headerEnd:t+10,dataOffset:t+r.length}}function Ws(n,e,t){if(t+e.length>n.length)return false;for(let r=0;r<e.length;r+=1)if(n[t+r]!==e[r])return false;return true}function Ze(n,e,t,r){switch(t){case"char":case"int8":return{value:n.getInt8(e),nextOffset:e+1};case"uchar":case"uint8":return{value:n.getUint8(e),nextOffset:e+1};case"short":case"int16":return{value:n.getInt16(e,r),nextOffset:e+2};case"ushort":case"uint16":return{value:n.getUint16(e,r),nextOffset:e+2};case"int":case"int32":return{value:n.getInt32(e,r),nextOffset:e+4};case"uint":case"uint32":return{value:n.getUint32(e,r),nextOffset:e+4};case"float":case"float32":return{value:n.getFloat32(e,r),nextOffset:e+4};case"double":case"float64":return{value:n.getFloat64(e,r),nextOffset:e+8};default:throw new Error(`Unsupported PLY scalar type "${t}".`)}}function Fe(n,e,t){const r=hn(n);return{positions:new Float32Array(n),normals:new Float32Array(e),...t!=null&&t.length?{colors:new Float32Array(t)}:{},triangleCount:n.length/9,bounds:r}}function hn(n){let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(let o=0;o<n.length;o+=3){const u=n[o],l=n[o+1],c=n[o+2];e=Math.min(e,u),t=Math.min(t,l),r=Math.min(r,c),s=Math.max(s,u),i=Math.max(i,l),a=Math.max(a,c)}return{min:[e,t,r],max:[s,i,a]}}function jt(n,e){var t;return{format:e,triangleCount:n.triangleCount,vertexCount:n.positions.length/3,hasVertexColors:!!((t=n.colors)!=null&&t.length),bounds:{min:[...n.bounds.min],max:[...n.bounds.max],size:[n.bounds.max[0]-n.bounds.min[0],n.bounds.max[1]-n.bounds.min[1],n.bounds.max[2]-n.bounds.min[2]]}}}function Ks(n){return n.children.map((e,t)=>mn(e,`node-${t+1}`))}function mn(n,e){const t=n;return t.userData.previewNodeId=e,t.userData.previewOriginalVisible=n.visible,t.userData.previewMaterialKeys=ht(n),{id:e,label:ni(n,e),kind:ri(n),visible:n.visible,metadata:si(n),children:n.children.map((r,s)=>mn(r,`${e}.${s+1}`))}}function ht(n){const e=n;if(e.userData.previewEdgeHelper||e.userData.previewMeasurementHelper)return[];const t=n;return(Array.isArray(t.material)?t.material:t.material?[t.material]:[]).map(s=>Mn(s))}function Ys(n){let e=false;return n.traverse(t=>{const r=t;r.userData.previewEdgeHelper||r.userData.previewMeasurementHelper||!e&&ht(t).length&&(e=true)}),e}function Xs(n){const e=new te,t=new te;let r=false;return n.traverse(s=>{const i=s;if(!(!s.visible||!i.geometry)&&(t.setFromObject(s),!t.isEmpty())){if(!r){e.copy(t),r=true;return}e.union(t)}}),e}function Zs(n){const e=n.object.geometry;if(!e||!n.face)return;const t=e.getAttribute("position");if(!t||t.itemSize<3)return;const r=[qe(n.object,t,e.index,n.face.a),qe(n.object,t,e.index,n.face.b),qe(n.object,t,e.index,n.face.c)].filter(a=>!!a);if(!r.length)return;let s=r[0],i=s.distanceToSquared(n.point);for(let a=1;a<r.length;a+=1){const o=r[a],u=o.distanceToSquared(n.point);u<i&&(s=o,i=u)}return s}function qe(n,e,t,r){const s=t?t.getX(r):r;if(!Number.isFinite(s))return;const i=new E(e.getX(s),e.getY(s),e.getZ(s));return n.localToWorld(i)}function Gt(n,e,t){switch(t){case"x":return new E(n.x,e.y,e.z);case"y":return new E(e.x,n.y,e.z);case"z":return new E(e.x,e.y,n.z);default:return n}}function Ut(n){switch(n){case"y":return new E(0,1,0);case"z":return new E(0,0,1);default:return new E(1,0,0)}}function qs(n){switch(n){case"y":return new E(0,-1,0);case"z":return new E(0,0,-1);default:return new E(-1,0,0)}}function Js(n){switch(n){case"front":return{yaw:0,pitch:0};case"back":return{yaw:180,pitch:0};case"left":return{yaw:-90,pitch:0};case"right":return{yaw:90,pitch:0};case"top":return{yaw:0,pitch:90};case"bottom":return{yaw:0,pitch:-90};case"isometric":return{yaw:-35,pitch:24};default:return}}function Qs(n){return`${String(n??"model-preview").replace(/\.[^.]+$/,"").replace(/[<>:"/\\|?*\u0000-\u001F]+/g,"-").trim()||"model-preview"}.png`}function fn(n){return n.map(e=>({...e,metadata:e.metadata?{...e.metadata,materialNames:[...e.metadata.materialNames??[]],materialDetails:yn(e.metadata.materialDetails),bounds:e.metadata.bounds?{...e.metadata.bounds,min:[...e.metadata.bounds.min],max:[...e.metadata.bounds.max],size:[...e.metadata.bounds.size]}:void 0}:void 0,children:fn(e.children)}))}function pn(n,e,t){return n.map(r=>r.id===e?gn(r,t):{...r,children:pn(r.children,e,t)})}function gn(n,e){return{...n,visible:e,children:n.children.map(t=>gn(t,e))}}function wn(n,e){for(const t of n){if(t.id===e)return t;const r=wn(t.children,e);if(r)return r}}function ei(n,e){const t=ti(n),r=t.children.filter(a=>!new te().setFromObject(a).isEmpty());if(r.length<2)return[];const i=new te().setFromObject(t).getCenter(new E);return r.map((a,o)=>{const u=new te().setFromObject(a),l=u.getCenter(new E),c=u.getSize(new E),d=l.sub(i);if(d.lengthSq()<=1e-6){const h=o/r.length*Math.PI*2;d.set(Math.cos(h),0,Math.sin(h))}else d.normalize();return{object:a,basePosition:a.position.clone(),direction:d,distance:Math.max(c.length()*.45,e*.22)}})}function ti(n){let e=n;for(;e.children.length===1;){const t=e.children[0];if(!t||t.children.length<2)break;e=t}return e}function ni(n,e){var r;const t=(r=n.name)==null?void 0:r.trim();return t||(n.type&&n.type!=="Object3D"?n.type:e)}function ri(n){return n instanceof $||n instanceof Ee?"mesh":n instanceof me?"points":n instanceof _e||n instanceof Q||n.type==="LineLoop"?"lines":n.type==="Bone"?"bone":n.type.endsWith("Light")?"light":n.type.endsWith("Camera")?"camera":n instanceof ee?"group":"object"}function T(n,e){var g;let t=0,r=0,s=0,i=0,a=0,o=0,u=false,l=Array.isArray(n.animations)?((g=n.animations)==null?void 0:g.length)??0:0;const c=new Set,d=new Set,h=new Map;n.traverse(w=>{var P;const p=w;if(p.userData.previewEdgeHelper||p.userData.previewMeasurementHelper)return;t+=1,"animations"in w&&Array.isArray(w.animations)&&(l+=((P=w.animations)==null?void 0:P.length)??0);const b=w,y=b.geometry;if(y){const S=y.getAttribute("position");S&&(a+=S.count),y.getAttribute("color")&&(u=true),o+=mt(y)}w instanceof $||w instanceof Ee?r+=1:w instanceof me?i+=1:(w instanceof _e||w instanceof Q||w.type==="LineLoop")&&(s+=1);const C=Array.isArray(b.material)?b.material:b.material?[b.material]:[];for(const S of C)d.add(S),S.name&&c.add(S.name),h.set(S.id,bn(S))});const f=new te().setFromObject(n),m=f.isEmpty()?void 0:(()=>{const w=f.min,p=f.max,b=f.getSize(new E);return{min:[w.x,w.y,w.z],max:[p.x,p.y,p.z],size:[b.x,b.y,b.z]}})();return{format:e,objectCount:t,meshCount:r,lineCount:s,pointCount:i,materialCount:d.size,materialNames:[...c].sort((w,p)=>w.localeCompare(p)),materialDetails:[...h.values()].sort(xn),animationCount:l,bounds:m,triangleCount:o,vertexCount:a,hasVertexColors:u}}function si(n){let e=0,t=0,r=0,s=0,i=0,a=false;const o=new Set,u=new Set,l=new Map;n.traverse(h=>{const f=h;if(f.userData.previewEdgeHelper||f.userData.previewMeasurementHelper)return;const m=h,g=m.geometry;if(g){const p=g.getAttribute("position");p&&(s+=p.count),g.getAttribute("color")&&(a=true),i+=mt(g)}h instanceof $||h instanceof Ee?e+=1:h instanceof me?r+=1:(h instanceof _e||h instanceof Q||h.type==="LineLoop")&&(t+=1);const w=Array.isArray(m.material)?m.material:m.material?[m.material]:[];for(const p of w)u.add(p),p.name&&o.add(p.name),l.set(p.id,bn(p))});const c=new te().setFromObject(n),d=c.isEmpty()?void 0:(()=>{const h=c.min,f=c.max,m=c.getSize(new E);return{min:[h.x,h.y,h.z],max:[f.x,f.y,f.z],size:[m.x,m.y,m.z]}})();return{meshCount:e,lineCount:t,pointCount:r,materialCount:u.size,materialNames:[...o].sort((h,f)=>h.localeCompare(f)),materialDetails:[...l.values()].sort(xn),triangleCount:i,vertexCount:s,hasVertexColors:a,bounds:d}}function mt(n){const e=n.getAttribute("position");return e?n.index?Math.floor(n.index.count/3):Math.floor(e.count/3):0}function bn(n){const e=n,t=[e.map?"base":void 0,e.alphaMap?"alpha":void 0,e.aoMap?"ao":void 0,e.bumpMap?"bump":void 0,e.displacementMap?"displacement":void 0,e.emissiveMap?"emissive":void 0,e.envMap?"environment":void 0,e.lightMap?"light":void 0,e.metalnessMap?"metalness":void 0,e.normalMap?"normal":void 0,e.roughnessMap?"roughness":void 0,e.specularMap?"specular":void 0].filter(r=>!!r);return{key:Mn(n),...n.name?{name:n.name}:{},type:n.type||n.constructor.name||"Material",...e.color?{color:qt(e.color)}:{},...e.emissive?{emissiveColor:qt(e.emissive)}:{},...Number.isFinite(n.opacity)?{opacity:R(n.opacity)}:{},...Number.isFinite(n.alphaTest)?{alphaTest:R(n.alphaTest)}:{},transparent:n.transparent,...typeof e.wireframe=="boolean"?{wireframe:e.wireframe}:{},...typeof e.vertexColors=="boolean"?{vertexColors:e.vertexColors}:{},...typeof e.vertexColors=="number"?{vertexColors:e.vertexColors>0}:{},...typeof e.flatShading=="boolean"?{flatShading:e.flatShading}:{},...typeof e.depthWrite=="boolean"?{depthWrite:e.depthWrite}:{},...typeof e.depthTest=="boolean"?{depthTest:e.depthTest}:{},...n.side===1?{side:"back"}:n.side===2?{side:"double"}:{side:"front"},...Number.isFinite(e.roughness)?{roughness:R(e.roughness)}:{},...Number.isFinite(e.metalness)?{metalness:R(e.metalness)}:{},...Number.isFinite(e.shininess)?{shininess:R(e.shininess)}:{},...Number.isFinite(e.size)?{size:R(e.size)}:{},...t.length?{mapKinds:t}:{}}}function yn(n){return n==null?void 0:n.map(e=>({...e,mapKinds:e.mapKinds?[...e.mapKinds]:void 0}))}function _t(n){return n?{...n,snapMode:n.snapMode??"surface",axisLock:n.axisLock??"free",start:n.start?[...n.start]:void 0,end:n.end?[...n.end]:void 0,delta:n.delta?[...n.delta]:void 0,previewPoint:n.previewPoint?[...n.previewPoint]:void 0,previewDelta:n.previewDelta?[...n.previewDelta]:void 0,previewDistance:n.previewDistance}:void 0}function Vt(n,e){return!n||!e?n===e:n.active===e.active&&n.status===e.status&&(n.snapMode??"surface")===(e.snapMode??"surface")&&(n.axisLock??"free")===(e.axisLock??"free")&&oe(n.start,e.start)&&oe(n.end,e.end)&&oe(n.delta,e.delta)&&oe(n.previewPoint,e.previewPoint)&&oe(n.previewDelta,e.previewDelta)&&n.distance===e.distance&&n.previewDistance===e.previewDistance}function oe(n,e){return!n||!e?n===e:n[0]===e[0]&&n[1]===e[1]&&n[2]===e[2]}function ue(n){const e="x",[t,r]=(n==null?void 0:n[e])??[-1,1];return{active:false,mode:"single",axis:e,offset:_(0,t,r),min:R(t),max:R(r),bounds:Le(n??Ge()),range:xe(n??Ge())}}function ii(n){return n?{...n,mode:n.mode??"single",offset:R(n.offset),min:R(n.min),max:R(n.max),bounds:n.bounds?Le(n.bounds):void 0,range:n.range?Le(n.range):void 0}:void 0}function Je(n,e){const t=n.axis??"x",[r,s]=e[t];return{active:n.active,mode:n.mode??"single",axis:t,offset:R(_(n.offset,r,s)),min:R(r),max:R(s),bounds:Le(e),range:li(n.range,e)}}function ai(n,e){return!n||!e?n===e:n.active===e.active&&(n.mode??"single")===(e.mode??"single")&&n.axis===e.axis&&n.offset===e.offset&&n.min===e.min&&n.max===e.max&&oi(n.range,e.range)}function oi(n,e){return!n||!e?n===e:n.x[0]===e.x[0]&&n.x[1]===e.x[1]&&n.y[0]===e.y[0]&&n.y[1]===e.y[1]&&n.z[0]===e.z[0]&&n.z[1]===e.z[1]}function li(n,e){const t=xe(e);return{x:Qe(n==null?void 0:n.x,e.x,t.x),y:Qe(n==null?void 0:n.y,e.y,t.y),z:Qe(n==null?void 0:n.z,e.z,t.z)}}function Qe(n,e,t){if(!n)return[...t];const r=_(Math.min(n[0],n[1]),e[0],e[1]),s=_(Math.max(n[0],n[1]),e[0],e[1]);return[R(r),R(s)]}function Ge(){return{x:[-1,1],y:[-1,1],z:[-1,1]}}function Le(n){return{x:[...n.x],y:[...n.y],z:[...n.z]}}function xe(n){return Le(n)}function Ue(n){return`${n.axis}:${n.offset.toFixed(5)}`}function ci(n){if(n.mode==="box"){const e=n.range;return e?`box:${e.x[0].toFixed(5)}:${e.x[1].toFixed(5)}:${e.y[0].toFixed(5)}:${e.y[1].toFixed(5)}:${e.z[0].toFixed(5)}:${e.z[1].toFixed(5)}`:"box"}return`single:${Ue(n)}`}function ui(n,e){const t=`${e.position.x.toFixed(5)}:${e.position.y.toFixed(5)}:${e.position.z.toFixed(5)}`;if(n.mode==="box"){const r=n.range;return r?`box:${t}:${r.x[0].toFixed(5)}:${r.x[1].toFixed(5)}:${r.y[0].toFixed(5)}:${r.y[1].toFixed(5)}:${r.z[0].toFixed(5)}:${r.z[1].toFixed(5)}`:`box:${t}`}return`single:${t}:${Ue(n)}`}function di(n,e){switch(n.axis){case"x":return{width:Math.max(e.z[1]-e.z[0],0),height:Math.max(e.y[1]-e.y[0],0)};case"y":return{width:Math.max(e.x[1]-e.x[0],0),height:Math.max(e.z[1]-e.z[0],0)};case"z":default:return{width:Math.max(e.x[1]-e.x[0],0),height:Math.max(e.y[1]-e.y[0],0)}}}function hi(n,e){switch(n.axis){case"x":return Be([[n.offset,e.y[0],e.z[0]],[n.offset,e.y[1],e.z[0]],[n.offset,e.y[1],e.z[1]],[n.offset,e.y[0],e.z[1]]]);case"y":return Be([[e.x[0],n.offset,e.z[0]],[e.x[1],n.offset,e.z[0]],[e.x[1],n.offset,e.z[1]],[e.x[0],n.offset,e.z[1]]]);case"z":default:return Be([[e.x[0],e.y[0],n.offset],[e.x[1],e.y[0],n.offset],[e.x[1],e.y[1],n.offset],[e.x[0],e.y[1],n.offset]])}}function Be(n){const e=[];for(let t=0;t<n.length;t+=1){const r=n[t],s=n[(t+1)%n.length];e.push(...r,...s)}return e}function mi(n){const e=[];for(let t=0;t<n.length-1;t+=1)e.push(...n[t],...n[t+1]);return e}function fi(n,e,t=1e-4){const r=[],s=[],i=new Map,a=new Set,o=(c,d,h)=>{const[f,m]=re(n,[c,d,h]),g=`${Math.round(f/t)}:${Math.round(m/t)}`,w=i.get(g);if(typeof w=="number"){const b=r[w];return b.x+=c,b.y+=d,b.z+=h,b.count+=1,w}const p=r.length;return r.push({x:c,y:d,z:h,count:1,edges:[]}),i.set(g,p),p};for(let c=0;c<e.length;c+=6){const d=o(e[c],e[c+1],e[c+2]),h=o(e[c+3],e[c+4],e[c+5]);if(d===h)continue;const f=d<h?`${d}:${h}`:`${h}:${d}`;if(a.has(f))continue;a.add(f);const m=s.length;s.push({a:d,b:h,visited:false}),r[d].edges.push(m),r[h].edges.push(m)}const u=[],l=[];for(let c=0;c<r.length;c+=1)if(r[c].edges.length!==2)for(;;){const d=r[c].edges.find(f=>!s[f].visited);if(typeof d!="number")break;const h=$t(n,r,s,c,d);Wt(n,r,h,u,l,t)}for(let c=0;c<r.length;c+=1)for(;;){const d=r[c].edges.find(f=>!s[f].visited);if(typeof d!="number")break;const h=$t(n,r,s,c,d);Wt(n,r,h,u,l,t)}return{loops:Mi(n,u,t).filter(c=>c.length>=3),chains:Si(n,l,t).filter(c=>c.length>=2)}}function pi(n,e,t,r,s,i){const a=e[r].edges.filter(f=>!t[f].visited&&f!==i);if(!a.length)return;if(typeof s!="number")return a[0];const o=ze(e[r]),u=ze(e[s]),l=st(n,u,o),c=Math.hypot(l.x,l.y);if(c<=1e-10)return a[0];let d=a[0],h=Number.NEGATIVE_INFINITY;for(const f of a){const m=t[f],g=m.a===r?m.b:m.a,w=ze(e[g]),p=st(n,o,w),b=Math.hypot(p.x,p.y);if(b<=1e-10)continue;const y=(l.x*p.x+l.y*p.y)/(c*b);y>h&&(h=y,d=f)}return d}function $t(n,e,t,r,s){const i=t[s];i.visited=true;const a=i.a===r?i.b:i.a,o=[r,a];let u=r,l=a,c=s;for(;l!==r;){const d=pi(n,e,t,l,u,c);if(typeof d!="number")break;const h=t[d];h.visited=true;const f=h.a===l?h.b:h.a;o.push(f),u=l,c=d,l=f}return o}function Wt(n,e,t,r,s,i=1e-4){if(t.length<2)return;const a=t.length>=4&&t[0]===t[t.length-1],o=t.slice(0,a?-1:t.length).map(l=>ze(e[l])),u=gi(n,o,a,i);if(a){const l=Math.abs(ft(u.map(c=>{const[d,h]=re(n,c);return new at(d,h)})));u.length>=3&&l>i*i&&r.push(u);return}u.length>=2&&wi(n,u)>i&&s.push(u)}function gi(n,e,t,r=1e-5){if(e.length<=(t?3:2))return e;const s=[];for(let i=0;i<e.length;i+=1){if(!t&&(i===0||i===e.length-1)){s.push(e[i]);continue}const a=e[(i-1+e.length)%e.length],o=e[i],u=e[(i+1)%e.length],[l,c]=re(n,a),[d,h]=re(n,o),[f,m]=re(n,u),g=(d-l)*(m-c)-(h-c)*(f-l);Math.abs(g)>r&&s.push(o)}return s.length>=(t?3:2)?s:e}function wi(n,e){let t=0;for(let r=0;r<e.length-1;r+=1){const s=st(n,e[r],e[r+1]);t+=Math.hypot(s.x,s.y)}return t}function ze(n){return[n.x/n.count,n.y/n.count,n.z/n.count]}function st(n,e,t){const[r,s]=re(n,e),[i,a]=re(n,t);return{x:i-r,y:a-s}}function bi(n,e){if(!e.length)return;const t=xi(n,e),r=[],s=[];let i=0;for(let a=0;a<t.length;a+=1){const o=t[a];if(o.depth%2!==0)continue;const u=Yt(o.loop,o.points2d,"ccw"),l=o.children.map(h=>t[h]).filter(h=>h.depth===o.depth+1).map(h=>Yt(h.loop,h.points2d,"cw")),c=gr.triangulateShape(u.points2d,l.map(h=>h.points2d));if(!c.length)continue;const d=[u,...l];r.push(...d.flatMap(h=>h.loop.flat())),s.push(...c.flat().map(h=>h+i)),i+=d.reduce((h,f)=>h+f.loop.length,0)}if(!(!r.length||!s.length))return{positions:r,indices:s}}function yi(n){const e=new Y;return e.setAttribute("position",new Z(n.positions,3)),e.setIndex(n.indices),e.computeVertexNormals(),e.computeBoundingSphere(),e}function vi(n,e,t=5e-4){const r=n.range??xe(e),[s,i]=r.x,[a,o]=r.y,[u,l]=r.z,c=[];if(s>e.x[0]+t&&be(c,[[s,a,u],[s,o,u],[s,o,l],[s,a,l]]),i<e.x[1]-t&&be(c,[[i,a,u],[i,a,l],[i,o,l],[i,o,u]]),a>e.y[0]+t&&be(c,[[s,a,u],[s,a,l],[i,a,l],[i,a,u]]),o<e.y[1]-t&&be(c,[[s,o,u],[i,o,u],[i,o,l],[s,o,l]]),u>e.z[0]+t&&be(c,[[s,a,u],[i,a,u],[i,o,u],[s,o,u]]),l<e.z[1]-t&&be(c,[[s,a,l],[s,o,l],[i,o,l],[i,a,l]]),!c.length)return;const d=new Y;return d.setAttribute("position",new Z(c,3)),d.computeVertexNormals(),d.computeBoundingSphere(),d}function be(n,e){n.push(...e[0],...e[1],...e[2],...e[0],...e[2],...e[3])}function re(n,e){switch(n){case"x":return[e[1],e[2]];case"y":return[e[0],e[2]];case"z":default:return[e[0],e[1]]}}function xi(n,e){const t=e.filter(r=>r.length>=3).map(r=>{const s=r.map(a=>{const[o,u]=re(n,a);return new at(o,u)}),i=ft(s);return{loop:r,points2d:s,signedArea:i,absoluteArea:Math.abs(i),children:[],depth:0}}).sort((r,s)=>s.absoluteArea-r.absoluteArea);for(let r=0;r<t.length;r+=1){const s=t[r];let i=-1,a=Number.POSITIVE_INFINITY;for(let o=0;o<r;o+=1){const u=t[o];u.absoluteArea>=s.absoluteArea&&Ei(s.points2d[0],u.points2d)&&u.absoluteArea<a&&(a=u.absoluteArea,i=o)}i>=0&&(t[i].children.push(r),s.depth=t[i].depth+1)}return t}function Mi(n,e,t=1e-4){const r=new Set,s=[];for(const i of e){const a=Ci(n,i,t);!a||r.has(a)||(r.add(a),s.push(i))}return s}function Si(n,e,t=1e-4){const r=new Set,s=[];for(const i of e){const a=Pi(n,i,t);!a||r.has(a)||(r.add(a),s.push(i))}return s}function Ci(n,e,t=1e-4){if(e.length<3)return;const r=e.map(o=>it(n,o,t)),s=[...r].reverse(),i=Kt(r),a=Kt(s);return i<a?i:a}function Pi(n,e,t=1e-4){if(e.length<2)return;const r=e.map(i=>it(n,i,t)).join("|"),s=[...e].reverse().map(i=>it(n,i,t)).join("|");return r<s?r:s}function it(n,e,t=1e-4){const[r,s]=re(n,e);return`${Math.round(r/t)}:${Math.round(s/t)}`}function Kt(n){if(!n.length)return"";let e=0;for(let r=1;r<n.length;r+=1)Li(n,r,e)<0&&(e=r);const t=[];for(let r=0;r<n.length;r+=1)t.push(n[(e+r)%n.length]);return t.join("|")}function Li(n,e,t){for(let r=0;r<n.length;r+=1){const s=n[(e+r)%n.length],i=n[(t+r)%n.length],a=s.localeCompare(i);if(a!==0)return a}return 0}function Yt(n,e,t){const r=ft(e);return(t==="ccw"?r<0:r>0)?{loop:[...n].reverse(),points2d:[...e].reverse().map(i=>i.clone())}:{loop:[...n],points2d:e.map(i=>i.clone())}}function Ei(n,e,t=1e-7){let r=false;for(let s=0,i=e.length-1;s<e.length;i=s,s+=1){const a=e[s],o=e[i];if(Fi(n,o,a,t))return true;a.y>n.y!=o.y>n.y&&n.x<(o.x-a.x)*(n.y-a.y)/(o.y-a.y||t)+a.x&&(r=!r)}return r}function Fi(n,e,t,r=1e-7){const s=(n.y-e.y)*(t.x-e.x)-(n.x-e.x)*(t.y-e.y);if(Math.abs(s)>r)return false;const i=(n.x-e.x)*(t.x-e.x)+(n.y-e.y)*(t.y-e.y);if(i<-r)return false;const a=(t.x-e.x)**2+(t.y-e.y)**2;return i<=a+r}function ft(n){let e=0;for(let t=0;t<n.length;t+=1){const r=n[t],s=n[(t+1)%n.length];e+=r.x*s.y-s.x*r.y}return e/2}function Xt(n,e){const t=[];for(let r=0;r<e.length;r+=9){const s=new E(e[r],e[r+1],e[r+2]),i=new E(e[r+3],e[r+4],e[r+5]),a=new E(e[r+6],e[r+7],e[r+8]),o=Ti(n.axis,n.offset,s,i,a);o.length===2&&t.push(o[0].x,o[0].y,o[0].z,o[1].x,o[1].y,o[1].z)}return t}function Ai(n,e,t){var r;if(!e)return[];if((r=e.objects)!=null&&r.length&&t){const s=[];for(const i of e.objects){if(!i.object.visible)continue;const a=Ri(i.positions,i.object,t);s.push(...Xt(n,a))}return s}return e.positions.length?Xt(n,e.positions):[]}function Di(n,e=tt){const t=[];if(n.traverse(i=>{if(!(i instanceof $||i instanceof Ee))return;const a=i.geometry,o=a==null?void 0:a.getAttribute("position");if(!a||!o||o.itemSize<3)return;const u=mt(a);u&&t.push({object:i,geometry:a,position:o,triangleCount:u})}),!t.length)return[];const r=Oi(t.map(i=>i.triangleCount),e),s=[];for(let i=0;i<t.length;i+=1){const a=t[i],o=Ni(a.geometry,a.position,r[i]);o.length&&s.push({object:a.object,positions:o})}return s}function Ni(n,e,t){const r=n.index?Math.floor(n.index.count/3):Math.floor(e.count/3);if(!r)return new Float32Array;const s=vn(r,t),i=new Float32Array(s.length*9);let a=0;if(n.index){for(const o of s)for(let u=0;u<3;u+=1){const l=n.index.getX(o*3+u);i[a]=e.getX(l),i[a+1]=e.getY(l),i[a+2]=e.getZ(l),a+=3}return i}for(const o of s){const u=o*3;for(let l=0;l<3;l+=1){const c=u+l;i[a]=e.getX(c),i[a+1]=e.getY(c),i[a+2]=e.getZ(c),a+=3}}return i}function Oi(n,e){if(!n.length||e<=0)return n.map(()=>0);const t=n.reduce((a,o)=>a+o,0);if(t<=e)return[...n];const r=n.map(a=>Math.floor(a/t*e));let s=r.reduce((a,o)=>a+o,0);const i=n.map((a,o)=>({index:o,remainder:a/t*e-r[o],available:a-r[o]})).sort((a,o)=>o.remainder-a.remainder||o.available-a.available);for(const a of i){if(s>=e)break;a.available<=0||(r[a.index]=r[a.index]+1,s+=1)}return r}function ki(n,e){const t=Math.floor(n.length/9);if(!t||t<=e)return n;const r=vn(t,e),s=new Float32Array(r.length*9);let i=0;for(const a of r){const o=a*9;s.set(n.subarray(o,o+9),i),i+=9}return s}function vn(n,e){if(!n)return[];if(typeof e!="number"||e<=0||n<=e)return Array.from({length:n},(s,i)=>i);const t=[],r=n-1;for(let s=0;s<e;s+=1){const i=Math.min(r,Math.floor((s+.5)*n/e));t.push(i)}return t}function Ri(n,e,t){e.updateMatrixWorld(true),t.updateMatrixWorld(true);const r=new en().copy(t.matrixWorld).invert().multiply(e.matrixWorld),s=new Float32Array(n.length),i=new E;for(let a=0;a<n.length;a+=3)i.set(n[a],n[a+1],n[a+2]).applyMatrix4(r),s[a]=i.x,s[a+1]=i.y,s[a+2]=i.z;return s}function Ti(n,e,t,r,s){const i=[t,r,s],a=[],o=[[i[0],i[1]],[i[1],i[2]],[i[2],i[0]]];for(const[u,l]of o){const c=Ii(n,e,u,l);c&&!a.some(d=>d.distanceToSquared(c)<1e-10)&&a.push(c)}return a}function Ii(n,e,t,r){const s=Zt(t,n)-e,i=Zt(r,n)-e;if(Math.abs(s)<=1e-7&&Math.abs(i)<=1e-7||s>0&&i>0||s<0&&i<0)return;const a=i-s;if(Math.abs(a)<=1e-7)return;const o=-s/a;if(!(o<-1e-7||o>1+1e-7))return t.clone().lerp(r,_(o,0,1))}function Zt(n,e){switch(e){case"y":return n.y;case"z":return n.z;default:return n.x}}function Re(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function xn(n,e){const t=`${n.name??""}\0${n.type}\0${n.key}`,r=`${e.name??""}\0${e.type}\0${e.key}`;return t.localeCompare(r)}function Mn(n){return`${n.type||n.constructor.name||"Material"}:${n.name||"unnamed"}:${n.id}`}function qt(n){return`#${n.getHexString().toUpperCase()}`}function R(n){return Math.round(n*1e3)/1e3}function ye(n){return[R(n.x),R(n.y),R(n.z)]}function Bi(n){return n.byteLength<84?false:84+new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(80,true)*50===n.byteLength}function zi(n){return new E((n.min[0]+n.max[0])/2,(n.min[1]+n.max[1])/2,(n.min[2]+n.max[2])/2)}function Hi(n){return new E(n.max[0]-n.min[0],n.max[1]-n.min[1],n.max[2]-n.min[2])}function ji(n,e){return{x:[n.min[0]-e.x,n.max[0]-e.x],y:[n.min[1]-e.y,n.max[1]-e.y],z:[n.min[2]-e.z,n.max[2]-e.z]}}function Gi(n){const e=new te().setFromObject(n);return e.isEmpty()?{x:[-1,1],y:[-1,1],z:[-1,1]}:{x:[e.min.x,e.max.x],y:[e.min.y,e.max.y],z:[e.min.z,e.max.z]}}function G(n){const e=Number(n);return Number.isFinite(e)?e:0}function Jt(n){return n*Math.PI/180}function _(n,e,t){return Math.max(e,Math.min(t,n))}function Qt(n){var e,t;try{const r=new pr(n);if(!((e=r.getContext)==null?void 0:e.call(r)))throw(t=r.dispose)==null||t.call(r),new Error("WebGL unavailable");return r}catch{const r=document.createElement("canvas");return r.width=1,r.height=1,{domElement:r,setPixelRatio:()=>{},setClearColor:()=>{},setSize:(s,i)=>{const a=Math.max(1,Math.floor(s)),o=Math.max(1,Math.floor(i));r.width=a,r.height=o},render:()=>{},dispose:()=>{}}}}function Sn(n){return String(n??"").trim().replace(/^\./,"").toLowerCase()}function Ui(n){try{return JSON.parse(n)}catch{throw new Error("glTF JSON is invalid.")}}function _i(n){const e=n.trim().toLowerCase();return e.startsWith("data:")||e.startsWith("blob:")}function Cn(n){var t;if(typeof n!="string")return;const e=n.trim();if(!(!e||e.toLowerCase().startsWith("data:")||e.toLowerCase().startsWith("blob:")))try{const r=new URL(e,((t=globalThis.location)==null?void 0:t.href)??"http://localhost/");return new URL(".",r).href}catch{return}}function Ce(n){return Cn(n)??""}function Vi(n){return Ce(n)}function $i(n){return(String(n??"model").split(/[\\/]/).pop()??"model").replace(/\.[^.]+$/,"")||"model"}function pe(n,e,t){const r=Ae(n);return{source:ge(r.source,e,t),warnings:r.warnings}}function Ae(n){if(!n)return{warnings:[]};const e=t=>typeof t=="string"||t instanceof Blob||ArrayBuffer.isView(t)||t instanceof ArrayBuffer;return e(n)?{source:n,warnings:[]}:{source:e(n.source)?n.source:void 0,warnings:n.warnings??[]}}function ge(n,e,t){if(n){if(typeof n=="string")return n;if(n instanceof Blob){const r=URL.createObjectURL(n);return t==null||t.push(r),r}if(ArrayBuffer.isView(n)||n instanceof ArrayBuffer){const r=ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n);if(!t)return Wi(r,e);const s=r.buffer instanceof ArrayBuffer?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r);return ge(new Blob([s],{type:e}),e,t)}}}async function Pn(n,e){return new TextDecoder().decode(await ut(n,e))}function Ln(n){var t;const e=((t=n.split("?")[0])==null?void 0:t.toLowerCase())??n.toLowerCase();return e.endsWith(".png")?"image/png":e.endsWith(".jpg")||e.endsWith(".jpeg")?"image/jpeg":e.endsWith(".webp")?"image/webp":e.endsWith(".ktx2")?"image/ktx2":"application/octet-stream"}function q(n){var t;return(((t=n.split("?")[0])==null?void 0:t.toLowerCase())??n.toLowerCase()).endsWith(".mtl")?"text/plain":Ln(n)}function X(n){const e=n.replace(/\\/g,"/").split(/[?#]/)[0]??"",t=e.lastIndexOf("/");return t>=0?e.slice(0,t):""}function K(n,e){if(!n||/^[a-z]+:\/\//i.test(e)||/^[a-z]:[\\/]/i.test(e)||e.startsWith("/"))return e.replace(/\\/g,"/");const t=[];for(const r of`${n}/${e}`.replace(/\\/g,"/").split("/"))if(!(!r||r===".")){if(r===".."){t.pop();continue}t.push(r)}return t.join("/")}function Wi(n,e){let t="";for(const r of n)t+=String.fromCharCode(r);return`data:${e};base64,${btoa(t)}`}const Ki=new URL("../filens-step.wasm",import.meta.url).href;class le extends Error{constructor(e,t){super(t),this.code=e,this.name="StepReadError"}}function En(n={}){const e=br({wasm:n.wasm??Ki,fetch:n.fetch});return{async read(t,{tolerance:r=.1,signal:s}={}){if(s!=null&&s.aborted)throw Object.assign(new Error("STEP loading was aborted."),{name:"AbortError"});if(!Number.isFinite(r)||r<=0)throw new RangeError("STEP tolerance must be positive and finite (millimetres).");const i=typeof t=="string"?new TextEncoder().encode(t):ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t);if(i.byteLength>64<<20)throw new RangeError("STEP input exceeds 64 MiB.");const a=await e({args:["filens-step","/work/input.step","/work/mesh.bin",String(r),"--reviewed","--binary"],files:{"/work/input.step":i},readFiles:["/work/mesh.bin"],signal:s,captureStdio:true}),o=(a.stdout??"").trim().split(`
31
- `);let u;try{u=JSON.parse(o[o.length-1])}catch{throw new le("invalid_step","Rust STEP could not read this file.")}if(a.exitCode||u.error)throw new le("invalid_step",u.error||"Rust STEP could not read this file.");if(!u.success)throw new le("empty_geometry","STEP contains no displayable geometry; external assemblies require their referenced part files.");if(u.missingFaces>0)throw new le("incomplete_mesh",`STEP tessellation left ${u.missingFaces} faces without geometry.`);const l=a.files["/work/mesh.bin"];if(!l)throw new le("invalid_mesh","Rust STEP did not produce a mesh.");const{positions:c,normals:d}=Yi(l),h=["STEP preview omits source colors, names and the assembly tree."];return u.shellFallback&&h.push("Shells were imported without a resolved assembly hierarchy; instance placement may be incomplete."),{positions:c,normals:d,triangleCount:c.length/9,metadata:u,warnings:h}}}}function Yi(n){if(n.byteLength<16||new TextDecoder().decode(n.subarray(0,8))!=="FLNSMESH")throw new le("invalid_mesh","Invalid STEP mesh header.");const e=new DataView(n.buffer,n.byteOffset,n.byteLength),t=e.getUint32(12,true),r=t*3;if(e.getUint32(8,true)!==1||!t||t%3||n.byteLength!==16+r*8)throw new le("invalid_mesh","Invalid STEP mesh version or triangle count.");const s=new Float32Array(r),i=new Float32Array(r);for(let a=0;a<r;a++){const o=e.getFloat32(16+a*4,true),u=e.getFloat32(16+(r+a)*4,true);if(!Number.isFinite(o)||!Number.isFinite(u))throw new le("invalid_mesh","Nonfinite STEP coordinate or normal.");s[a]=o,i[a]=u}return{positions:s,normals:i}}En();async function Xi(){const n=En();return{async ReadStepFile(e,t,r){const s=await n.read(e,{signal:r});return{success:true,root:{meshes:[0]},warnings:s.warnings,meshes:[{attributes:{position:{array:s.positions},normal:{array:s.normals}}}]}}}}const Zi=Object.freeze(Object.defineProperty({__proto__:null,createRustStepImporter:Xi},Symbol.toStringTag,{value:"Module"}));export{na as a,ta as c};
32
- /*!
33
- * @license
34
- * The MIT License
35
- *
36
- * Copyright © 2010-2025 three.js authors
37
- *
38
- * Permission is hereby granted, free of charge, to any person obtaining a copy
39
- * of this software and associated documentation files (the "Software"), to deal
40
- * in the Software without restriction, including without limitation the rights
41
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
42
- * copies of the Software, and to permit persons to whom the Software is
43
- * furnished to do so, subject to the following conditions:
44
- *
45
- * The above copyright notice and this permission notice shall be included in
46
- * all copies or substantial portions of the Software.
47
- *
48
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
50
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
51
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
52
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
53
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
54
- * THE SOFTWARE.
55
- */