@series-inc/stowkit-packer-gui 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4062,5 +4062,5 @@ void main() {
4062
4062
  ${V}
4063
4063
 
4064
4064
  This cannot be undone.`)&&(t({type:"REMOVE_ASSET",id:V}),H5(V))},[]),C=N.useRef(new Set),T=N.useCallback(async V=>{const W=i.current.assets.find(te=>te.id===V);if(!(!W||W.status!=="ready")&&!C.current.has(V)){C.current.add(V);try{const te={};if(W.type===at.Audio)te.previewUrl=Z0(V);else if(W.type===at.Texture2D){const ne=await fetch(Z0(V));if(!ne.ok)throw new Error(`Failed to fetch processed texture: ${ne.status}`);const k=new Uint8Array(await ne.arrayBuffer());wn.setProcessed(V,k),K5(V),te.previewUrl=await U5(k)}else if((W.type===at.StaticMesh||W.type===at.SkinnedMesh||W.type===at.AnimationClip)&&!wn.getSource(V)){const ne=await fetch(q5(V));if(!ne.ok)throw new Error(`Failed to fetch source: ${ne.status}`);wn.setSource(V,new Uint8Array(await ne.arrayBuffer()))}t({type:"UPDATE_ASSET",id:V,updates:te})}catch(te){console.error(`[ensureSourceLoaded] ${V}:`,te)}finally{C.current.delete(V)}}},[]),B=e.selectedAssetIds[0]??null,L=B?e.assets.find(V=>V.id===B):null,O=L?.status??null,R=L?.settings.targetMeshId??null;N.useEffect(()=>{if(O!=="ready")return;const V=requestAnimationFrame(()=>{B&&T(B),R&&T(R)});return()=>cancelAnimationFrame(V)},[B,O,R,T]);const F=N.useCallback(V=>{X5(V)},[]),j=N.useCallback(()=>{pC(void 0,!0),tr.success("Reprocessing all assets...")},[]);return b.jsx(JI.Provider,{value:{state:e,dispatch:t,importFiles:l,updateAssetSettings:u,changeAssetType:f,createMaterial:h,createFolder:p,duplicateMaterial:A,buildPack:m,openProject:g,openRecentProject:x,refreshProject:E,renameAsset:S,renameFolder:y,moveAsset:I,deleteAsset:M,ensureSourceLoaded:T,updatePackConfig:F,reimportAll:j},children:n})}const mC=n=>typeof n=="boolean"?`${n}`:n===0?"0":n,gC=fM,ZI=(n,e)=>t=>{var i;if(e?.variants==null)return gC(n,t?.class,t?.className);const{variants:a,defaultVariants:o}=e,l=Object.keys(a).map(h=>{const A=t?.[h],p=o?.[h];if(A===null)return null;const m=mC(A)||mC(p);return a[h][m]}),u=t&&Object.entries(t).reduce((h,A)=>{let[p,m]=A;return m===void 0||(h[p]=m),h},{}),f=e==null||(i=e.compoundVariants)===null||i===void 0?void 0:i.reduce((h,A)=>{let{class:p,className:m,...g}=A;return Object.entries(g).every(x=>{let[E,S]=x;return Array.isArray(S)?S.includes({...o,...u}[E]):{...o,...u}[E]===S})?[...h,p,m]:h},[]);return gC(n,l,f,t?.class,t?.className)},$5=ZI("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function Ei({className:n,variant:e="default",size:t="default",asChild:i=!1,...a}){const o=i?cw:"button";return b.jsx(o,{"data-slot":"button","data-variant":e,"data-size":t,className:nn($5({variant:e,size:t,className:n})),...a})}function gc({className:n,orientation:e="horizontal",decorative:t=!0,...i}){return b.jsx(EL,{"data-slot":"separator",decorative:t,orientation:e,className:nn("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",n),...i})}const eH=ZI("inline-flex items-center justify-center rounded-full border border-transparent px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",ghost:"[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",link:"text-primary underline-offset-4 [a&]:hover:underline"}},defaultVariants:{variant:"default"}});function Ef({className:n,variant:e="default",asChild:t=!1,...i}){const a=t?cw:"span";return b.jsx(a,{"data-slot":"badge","data-variant":e,className:nn(eH({variant:e}),n),...i})}function Po({className:n,type:e,...t}){return b.jsx("input",{type:e,"data-slot":"input",className:nn("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",n),...t})}function tH({open:n,onClose:e}){const{state:t,updatePackConfig:i}=yn(),a=t.projectDir?.config,[o,l]=N.useState(a?.packs??[{name:"default"}]);if(N.useEffect(()=>{a&&l(a.packs??[{name:"default"}])},[a,n]),!n||!t.projectDir)return null;const u=a?.cdnAssetsPath||"cdn-assets";function f(m,g){const x=o[m].name,E=o.map((S,y)=>y===m?{name:g}:S);l(E),i({packs:E,renamedPack:{oldName:x,newName:g}})}function h(){let m="new-pack",g=1;const x=new Set(o.map(S=>S.name));for(;x.has(m);)m=`new-pack-${g++}`;const E=[...o,{name:m}];l(E),i({packs:E})}function A(m){if(o.length<=1)return;const g=o.filter((x,E)=>E!==m);l(g),i({packs:g})}const p=new Map;for(const m of t.assets){const g=m.settings.pack??"default";p.set(g,(p.get(g)??0)+1)}return b.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:b.jsxs("div",{className:"w-[460px] rounded-xl border border-border bg-card p-6 shadow-2xl flex flex-col gap-5",children:[b.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Pack Settings"}),b.jsxs("div",{className:"space-y-1",children:[b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Output Path"}),b.jsxs("p",{className:"font-mono text-xs text-foreground",children:[u,"/"]})]}),b.jsxs("div",{className:"space-y-1.5",children:[b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Packs"}),b.jsx("div",{className:"space-y-1.5 max-h-[200px] overflow-y-auto",children:o.map((m,g)=>{const x=p.get(m.name)??0;return b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx(Po,{className:"h-7 flex-1 text-xs font-mono",value:m.name,onChange:E=>f(g,E.target.value),spellCheck:!1}),b.jsx("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap min-w-[3ch] text-right",children:x}),b.jsx("button",{className:"shrink-0 rounded p-1 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",disabled:o.length<=1,onClick:()=>A(g),title:"Delete pack",children:b.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:b.jsx("path",{d:"M3.5 3.5l7 7M10.5 3.5l-7 7",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})})})]},g)})}),b.jsx(Ei,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:h,children:"+ Add Pack"})]}),b.jsx("div",{className:"flex justify-end",children:b.jsx(Ei,{size:"sm",onClick:e,children:"Close"})})]})})}function nH(){const{buildPack:n,openProject:e,refreshProject:t,reimportAll:i,state:a}=yn(),[o,l]=N.useState(!1);if(!(a.projectDir!==null||a.assets.length>0))return null;const f=a.assets.filter(A=>A.status==="ready").length,h=a.assets.length;return b.jsxs("header",{className:"flex h-13 items-center gap-3 border-b border-border bg-card px-4",children:[b.jsx("h1",{className:"text-sm font-bold tracking-tight select-none whitespace-nowrap",children:"StowKit"}),b.jsx(gc,{orientation:"vertical",className:"h-5!"}),b.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-48 select-none",children:a.projectName}),b.jsxs(Ef,{variant:"secondary",className:"whitespace-nowrap text-[10px]",children:[h," asset",h!==1?"s":"",f>0&&` / ${f} ready`]}),b.jsx("div",{className:"flex-1"}),b.jsxs(Wl,{children:[b.jsx(Xl,{asChild:!0,children:b.jsx(Ei,{variant:"ghost",size:"sm",onClick:e,children:"Open Project"})}),b.jsx(ql,{children:"Open a project directory"})]}),b.jsxs(Wl,{children:[b.jsx(Xl,{asChild:!0,children:b.jsx(Ei,{variant:"ghost",size:"sm",onClick:t,children:"Refresh"})}),b.jsx(ql,{children:"Re-scan project directory for changes"})]}),b.jsxs(Wl,{children:[b.jsx(Xl,{asChild:!0,children:b.jsx(Ei,{variant:"ghost",size:"sm",onClick:i,children:"Reimport All"})}),b.jsx(ql,{children:"Force reprocess all assets"})]}),b.jsx(gc,{orientation:"vertical",className:"h-5!"}),b.jsxs(Wl,{children:[b.jsx(Xl,{asChild:!0,children:b.jsx(Ei,{variant:"ghost",size:"sm",className:"px-2",onClick:()=>l(!0),children:b.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:"text-foreground",children:[b.jsx("path",{d:"M6.7 1.6a1.3 1.3 0 0 1 2.6 0v.47a.65.65 0 0 0 .93.58l.4-.23a1.3 1.3 0 0 1 1.3 2.25l-.4.23a.65.65 0 0 0 0 1.13l.4.23a1.3 1.3 0 0 1-1.3 2.25l-.4-.23a.65.65 0 0 0-.93.58v.47a1.3 1.3 0 0 1-2.6 0v-.47a.65.65 0 0 0-.93-.58l-.4.23a1.3 1.3 0 1 1-1.3-2.25l.4-.23a.65.65 0 0 0 0-1.13l-.4-.23a1.3 1.3 0 1 1 1.3-2.25l.4.23a.65.65 0 0 0 .93-.58V1.6z",stroke:"currentColor",strokeWidth:"1.2",transform:"translate(0 2.5)"}),b.jsx("circle",{cx:"8",cy:"8",r:"2",stroke:"currentColor",strokeWidth:"1.2"})]})})}),b.jsx(ql,{children:"Pack settings"})]}),b.jsx(Ei,{size:"sm",disabled:f===0,onClick:n,children:"Build Pack"}),b.jsx(tH,{open:o,onClose:()=>l(!1)})]})}function iH({left:n,center:e,right:t,leftDefaultWidth:i=450,leftMinWidth:a=180,leftMaxWidth:o=650,rightDefaultWidth:l=450,rightMinWidth:u=220,rightMaxWidth:f=650}){const[h,A]=N.useState(i),[p,m]=N.useState(l),g=N.useRef(!1),x=N.useRef(!1),E=N.useRef(null),S=N.useCallback(I=>{I.preventDefault(),g.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),y=N.useCallback(I=>{I.preventDefault(),x.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return N.useEffect(()=>{const I=C=>{if(g.current&&A(Math.min(o,Math.max(a,C.clientX))),x.current&&E.current){const B=E.current.getBoundingClientRect().right-C.clientX;m(Math.min(f,Math.max(u,B)))}},M=()=>{(g.current||x.current)&&(g.current=!1,x.current=!1,document.body.style.cursor="",document.body.style.userSelect="")};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",M),()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",M)}},[a,o,u,f]),b.jsxs("div",{ref:E,className:"flex h-full min-h-0",children:[b.jsx("div",{className:"shrink-0 overflow-hidden",style:{width:h},children:n}),b.jsx(vC,{onMouseDown:S}),b.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:e}),b.jsx(vC,{onMouseDown:y}),b.jsx("div",{className:"shrink-0 overflow-hidden",style:{width:p},children:t})]})}function vC({onMouseDown:n}){return b.jsx("div",{onMouseDown:n,className:nn("relative shrink-0 w-px cursor-col-resize bg-border","after:absolute after:inset-y-0 after:left-1/2 after:w-3 after:-translate-x-1/2","hover:bg-ring transition-colors","flex items-center justify-center"),children:b.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:b.jsx(WU,{className:"size-2.5 text-muted-foreground"})})})}const ev="stowkit:";let px=!1;function Hu(){return px}function rH(n,e){n.dataTransfer.setData("text/plain",`${ev}${e.kind}:${e.id}`),n.dataTransfer.effectAllowed="move",px=!0}function $I(n){const e=n.dataTransfer.getData("text/plain");if(!e.startsWith(ev))return null;const t=e.slice(ev.length),i=t.indexOf(":");if(i===-1)return null;const a=t.slice(0,i),o=t.slice(i+1);return a==="asset"&&o?{kind:a,id:o}:null}function Ax(){px=!1}function aH(n,e,t){const i=new Map;function a(l){const u=i.get(l);if(u)return u;const f=l.split("/"),A={kind:"folder",name:f[f.length-1],path:l,collapsed:t.has(l),children:[]};if(i.set(l,A),f.length>1){const p=f.slice(0,-1).join("/");a(p).children.push(A)}return A}for(const l of e)l&&a(l);for(const l of n){const u=l.id.lastIndexOf("/");if(u===-1)continue;const f=l.id.substring(0,u);a(f).children.push({kind:"asset",asset:l})}const o=[];for(const[l,u]of i)l.includes("/")||o.push(u);for(const l of n)l.id.includes("/")||o.push({kind:"asset",asset:l});return tT(o),o}function eT(n){const e=[];for(const t of n)if(t.kind==="asset")e.push(t);else{const i=eT(t.children);i.length>0&&e.push({...t,children:i})}return e}function tT(n){n.sort((e,t)=>{if(e.kind!==t.kind)return e.kind==="folder"?-1:1;const i=e.kind==="folder"?e.name:e.asset.fileName,a=t.kind==="folder"?t.name:t.asset.fileName;return i.localeCompare(a)});for(const e of n)e.kind==="folder"&&tT(e.children)}function mx({...n}){return b.jsx(Y3,{"data-slot":"context-menu",...n})}function gx({...n}){return b.jsx(K3,{"data-slot":"context-menu-trigger",...n})}function sH({...n}){return b.jsx(tL,{"data-slot":"context-menu-sub",...n})}function oH({className:n,inset:e,children:t,...i}){return b.jsxs(nL,{"data-slot":"context-menu-sub-trigger","data-inset":e,className:nn("focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),...i,children:[t,b.jsx(GU,{className:"ml-auto"})]})}function lH({className:n,...e}){return b.jsx(iL,{"data-slot":"context-menu-sub-content",className:nn("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",n),...e})}function vx({className:n,...e}){return b.jsx(J3,{children:b.jsx(Z3,{"data-slot":"context-menu-content",className:nn("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",n),...e})})}function Fr({className:n,inset:e,variant:t="default",...i}){return b.jsx($3,{"data-slot":"context-menu-item","data-inset":e,"data-variant":t,className:nn("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),...i})}function tv({className:n,...e}){return b.jsx(eL,{"data-slot":"context-menu-separator",className:nn("bg-border -mx-1 my-1 h-px",n),...e})}const xC={[at.Unknown]:{text:"RAW",color:"text-zinc-400"},[at.Texture2D]:{text:"TEX",color:"text-blue-400"},[at.Audio]:{text:"AUD",color:"text-emerald-400"},[at.StaticMesh]:{text:"MSH",color:"text-orange-400"},[at.SkinnedMesh]:{text:"SKN",color:"text-purple-400"},[at.AnimationClip]:{text:"ANM",color:"text-pink-400"},[at.MaterialSchema]:{text:"MAT",color:"text-amber-400"}},cH={loading:"bg-zinc-500 animate-pulse",pending:"bg-zinc-500",processing:"bg-amber-400 animate-pulse",ready:"bg-emerald-400",error:"bg-red-400"},nT=N.createContext({anchorRef:{current:null},flatIds:[]});function iT(n){const e=[];for(const t of n)t.kind==="asset"?e.push(t.asset.id):t.collapsed||e.push(...iT(t.children));return e}function uH({collapsed:n}){return b.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",className:nn("shrink-0 text-muted-foreground transition-transform duration-150",!n&&"rotate-90"),children:b.jsx("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function fH({open:n}){return b.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",className:"shrink-0 text-primary",children:n?b.jsx("path",{d:"M1.5 4a1 1 0 011-1h2.8l1.2 1h4a1 1 0 011 1v.5H4.3a1 1 0 00-.95.7L1.5 11V4z M3.35 6.2a1 1 0 01.95-.7h8.2l-1.8 5.5H2.5l1.8-5.5z",fill:"currentColor",opacity:"0.35",stroke:"currentColor",strokeWidth:"0.8",strokeLinejoin:"round"}):b.jsx("path",{d:"M1.5 3.5a1 1 0 011-1h3l1 1h4.5a1 1 0 011 1v6a1 1 0 01-1 1h-8.5a1 1 0 01-1-1v-7z",fill:"currentColor",opacity:"0.35",stroke:"currentColor",strokeWidth:"0.8"})})}function dH(){return b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:b.jsx("path",{d:"M3 3l6 6M9 3l-6 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}function rT({asset:n,depth:e}){const{state:t,dispatch:i,renameAsset:a,duplicateMaterial:o,deleteAsset:l}=yn(),{anchorRef:u,flatIds:f}=N.useContext(nT),h=t.selectedAssetIds.includes(n.id),A=xC[n.type]??xC[at.Unknown],[p,m]=N.useState(!1),[g,x]=N.useState(n.fileName),E=N.useRef(null);function S(){const M=g.trim();M&&M!==n.fileName?a(n.id,M):x(n.fileName),m(!1)}function y(M){if(!M.target.closest('[role="button"], input')&&!p&&M.button===0){if(M.shiftKey&&u.current&&u.current!==n.id){const C=f.indexOf(u.current),T=f.indexOf(n.id);if(C>=0&&T>=0){const B=Math.min(C,T),L=Math.max(C,T);i({type:"SELECT_ASSETS",ids:f.slice(B,L+1)});return}}if(M.ctrlKey){i({type:"TOGGLE_SELECT_ASSET",id:n.id}),u.current=n.id;return}i({type:"SELECT_ASSET",id:n.id}),u.current=n.id}}function I(M){M.target.closest('[role="button"], input')||(x(n.fileName),m(!0),requestAnimationFrame(()=>E.current?.select()))}return b.jsxs(mx,{children:[b.jsx(gx,{asChild:!0,children:b.jsxs("button",{className:nn("group flex w-full items-center gap-2 rounded-md py-1.5 text-left text-sm transition-colors",h?"bg-accent text-accent-foreground":"hover:bg-muted text-foreground"),style:{paddingLeft:`${e*16+10}px`,paddingRight:10},draggable:!p,onDragStart:M=>{if(p){M.preventDefault();return}rH(M,{kind:"asset",id:n.id})},onDragEnd:()=>Ax(),onPointerDown:y,onDoubleClick:I,children:[b.jsx("span",{className:nn("h-1.5 w-1.5 shrink-0 rounded-full",cH[n.status])}),b.jsx("span",{className:nn("shrink-0 font-mono text-[10px] font-bold leading-none",A.color),children:A.text}),p?b.jsx("input",{ref:E,value:g,onChange:M=>x(M.target.value),onBlur:S,onKeyDown:M=>{M.key==="Enter"&&S(),M.key==="Escape"&&(x(n.fileName),m(!1))},className:"flex-1 rounded border border-border bg-background px-1 text-xs outline-none",autoFocus:!0,onClick:M=>M.stopPropagation()}):b.jsx("span",{className:"flex-1 truncate text-xs",children:n.fileName}),b.jsxs(Wl,{children:[b.jsx(Xl,{asChild:!0,children:b.jsx("span",{role:"button",tabIndex:-1,className:"hidden shrink-0 rounded p-0.5 text-muted-foreground hover:bg-destructive hover:text-destructive-foreground group-hover:inline-flex",onClick:M=>{M.stopPropagation(),l(n.id)},children:b.jsx(dH,{})})}),b.jsx(ql,{side:"right",children:"Remove"})]})]})}),b.jsxs(vx,{children:[n.type===at.MaterialSchema&&b.jsx(Fr,{onSelect:()=>o(n.id),children:"Duplicate"}),b.jsx(Fr,{onSelect:()=>{x(n.fileName),m(!0),requestAnimationFrame(()=>E.current?.select())},children:"Rename"}),b.jsx(tv,{}),b.jsx(Fr,{variant:"destructive",onSelect:()=>l(n.id),children:"Delete from Disk"})]})]})}function aT({node:n,depth:e}){const{state:t,dispatch:i,importFiles:a,moveAsset:o,createMaterial:l,createFolder:u,updateAssetSettings:f,renameFolder:h}=yn(),[A,p]=N.useState(!1),[m,g]=N.useState(n.name),[x,E]=N.useState(!1),S=N.useRef(null),y=N.useRef(null);function I(){const C=m.trim();C&&C!==n.name&&h(n.path,C),g(n.name),p(!1)}function M(){g(n.name),p(!0),requestAnimationFrame(()=>S.current?.select())}return b.jsxs("div",{children:[b.jsx("input",{ref:y,type:"file",multiple:!0,accept:"image/*,audio/*,.fbx,.obj,.gltf,.glb",className:"hidden",onChange:C=>{C.target.files&&a(C.target.files,n.path),C.target.value=""}}),b.jsxs(mx,{children:[b.jsx(gx,{asChild:!0,children:b.jsxs("div",{className:nn("group flex w-full cursor-pointer items-center gap-1.5 rounded-md py-1.5 text-sm transition-colors hover:bg-muted",x&&"ring-2 ring-primary/60 bg-primary/10"),style:{paddingLeft:`${e*16+6}px`,paddingRight:8},onPointerDown:C=>{C.button===0&&(A||i({type:"TOGGLE_FOLDER",path:n.path}))},onDragOver:C=>{(Hu()||C.dataTransfer.types.includes("Files"))&&(C.preventDefault(),C.stopPropagation(),C.dataTransfer.dropEffect=Hu()?"move":"copy",E(!0))},onDragEnter:C=>{(Hu()||C.dataTransfer.types.includes("Files"))&&(C.preventDefault(),C.stopPropagation(),E(!0))},onDragLeave:C=>{C.currentTarget.contains(C.relatedTarget)||E(!1)},onDrop:C=>{C.preventDefault(),C.stopPropagation(),E(!1);const T=$I(C);if(T){Ax(),o(T.id,n.path);return}C.dataTransfer.files.length>0&&a(C.dataTransfer.files,n.path)},children:[b.jsx(uH,{collapsed:n.collapsed}),b.jsx(fH,{open:!n.collapsed}),A?b.jsx("input",{ref:S,value:m,onChange:C=>g(C.target.value),onBlur:I,onKeyDown:C=>{C.key==="Enter"&&I(),C.key==="Escape"&&(g(n.name),p(!1))},onPointerDown:C=>C.stopPropagation(),className:"flex-1 border-b border-primary bg-transparent px-0.5 text-xs outline-none",autoFocus:!0}):b.jsx("span",{className:"flex-1 truncate text-xs font-medium",children:n.name})]})}),b.jsxs(vx,{children:[b.jsx(Fr,{onSelect:()=>y.current?.click(),children:"Import Here"}),b.jsx(Fr,{onSelect:()=>l(n.path),children:"New Material"}),b.jsx(Fr,{onSelect:()=>u(n.path),children:"New Folder"}),b.jsx(tv,{}),(t.projectDir?.config.packs??[{name:"default"}]).length>0&&b.jsxs(sH,{children:[b.jsx(oH,{children:"Assign to Pack"}),b.jsx(lH,{children:(t.projectDir?.config.packs??[{name:"default"}]).map(C=>b.jsx(Fr,{onSelect:()=>{const T=n.path+"/";for(const B of t.assets)(B.id.startsWith(T)||B.id===n.path)&&B.settings.pack!==C.name&&f(B.id,{pack:C.name})},children:C.name},C.name))})]}),b.jsx(tv,{}),b.jsx(Fr,{onSelect:M,children:"Rename"})]})]}),!n.collapsed&&n.children.length>0&&b.jsx("div",{children:n.children.map(C=>C.kind==="folder"?b.jsx(aT,{node:C,depth:e+1},C.path):b.jsx(rT,{asset:C.asset,depth:e+1},C.asset.id))})]})}function hH({searchQuery:n=""}){const{state:e}=yn(),t=N.useRef(null),i=n.trim().toLowerCase(),a=N.useMemo(()=>i?e.assets.filter(f=>f.fileName.toLowerCase().includes(i)||f.stringId.toLowerCase().includes(i)):e.assets,[e.assets,i]),o=N.useMemo(()=>{const f=aH(a,e.folders,i?new Set:e.collapsedFolders);return i?eT(f):f},[a,e.folders,e.collapsedFolders,i]),l=N.useMemo(()=>iT(o),[o]),u=N.useMemo(()=>({anchorRef:t,flatIds:l}),[l]);return o.length===0?i?b.jsxs("div",{className:"px-4 py-8 text-center text-xs text-muted-foreground",children:["No assets matching “",n.trim(),"”"]}):null:b.jsx(nT.Provider,{value:u,children:b.jsx("div",{className:"space-y-0.5 p-1.5",children:o.map(f=>f.kind==="folder"?b.jsx(aT,{node:f,depth:0},f.path):b.jsx(rT,{asset:f.asset,depth:0},f.asset.id))})})}function xx({className:n,children:e,...t}){return b.jsxs(mL,{"data-slot":"scroll-area",className:nn("relative",n),...t,children:[b.jsx(gL,{"data-slot":"scroll-area-viewport",className:"focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1 [&>div]:!min-w-full",children:e}),b.jsx(pH,{}),b.jsx(vL,{})]})}function pH({className:n,orientation:e="vertical",...t}){return b.jsx(j1,{"data-slot":"scroll-area-scrollbar",orientation:e,className:nn("flex touch-none p-px transition-colors select-none",e==="vertical"&&"h-full w-2.5 border-l border-l-transparent",e==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent",n),...t,children:b.jsx(Y1,{"data-slot":"scroll-area-thumb",className:"bg-border relative flex-1 rounded-full"})})}function AH(){const{state:n,importFiles:e,moveAsset:t,createMaterial:i,createFolder:a}=yn(),o=N.useRef(null),[l,u]=N.useState(""),[f,h]=N.useState("");N.useEffect(()=>{if(l===""){h("");return}const x=setTimeout(()=>h(l),150);return()=>clearTimeout(x)},[l]);const A=l!==f;function p(x){(Hu()||x.dataTransfer.types.includes("Files"))&&(x.preventDefault(),x.dataTransfer.dropEffect=Hu()?"move":"copy")}function m(x){x.preventDefault();const E=$I(x);if(E){Ax(),t(E.id,"");return}if(x.dataTransfer.files.length>0){e(x.dataTransfer.files);return}}const g=n.assets.length===0&&n.folders.size===0;return b.jsxs("div",{className:"flex h-full flex-col bg-card",onDragOver:p,onDrop:m,children:[b.jsxs("div",{className:"flex h-9 items-center justify-between border-b border-border px-4",children:[b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Assets"}),b.jsx("div",{className:"flex items-center gap-0.5",children:b.jsxs(Wl,{children:[b.jsx(Xl,{asChild:!0,children:b.jsx("button",{className:"rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>i(),children:b.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:[b.jsx("circle",{cx:"7",cy:"7",r:"5",stroke:"currentColor",strokeWidth:"1.2"}),b.jsx("ellipse",{cx:"5.5",cy:"5.5",rx:"2",ry:"1.5",stroke:"currentColor",strokeWidth:"0.8",opacity:"0.5"})]})})}),b.jsx(ql,{side:"right",children:"New Material"})]})})]}),!g&&b.jsx("div",{className:"border-b border-border px-2 py-1.5",children:b.jsxs("div",{className:"relative",children:[b.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",className:"pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground",children:[b.jsx("circle",{cx:"6",cy:"6",r:"3.5",stroke:"currentColor",strokeWidth:"1.3"}),b.jsx("path",{d:"M8.5 8.5L11.5 11.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})]}),b.jsx("input",{type:"text",placeholder:"Search assets…",value:l,onChange:x=>u(x.target.value),className:"h-7 w-full rounded-md border border-border bg-background pl-7 pr-7 text-xs outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]"}),l&&(A?b.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"absolute right-2 top-1/2 -translate-y-1/2 animate-spin text-muted-foreground",children:[b.jsx("circle",{cx:"6",cy:"6",r:"4.5",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.25"}),b.jsx("path",{d:"M6 1.5a4.5 4.5 0 0 1 4.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):b.jsx("button",{className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-0.5 text-muted-foreground hover:text-foreground",onClick:()=>u(""),children:b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:b.jsx("path",{d:"M3 3l6 6M9 3l-6 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}))]})}),b.jsxs(mx,{children:[b.jsx(gx,{asChild:!0,children:b.jsx("div",{className:"flex-1 overflow-hidden",children:b.jsx(xx,{className:"h-full",children:g?b.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-center text-xs text-muted-foreground",children:[b.jsx("p",{children:"Open a project directory or drop files here"}),b.jsx(Ef,{variant:"outline",className:"text-[10px]",children:"PNG, JPG, WAV, OGG, MP3, FBX"})]}):b.jsx(hH,{searchQuery:f})})})}),b.jsxs(vx,{children:[b.jsx(Fr,{onSelect:()=>o.current?.click(),children:"Import"}),b.jsx(Fr,{onSelect:()=>i(),children:"New Material"}),b.jsx(Fr,{onSelect:()=>a(),children:"New Folder"})]})]}),b.jsxs("div",{className:"border-t border-border px-2 py-2",children:[b.jsx("input",{ref:o,type:"file",multiple:!0,accept:"image/*,audio/*,.fbx,.obj,.gltf,.glb",className:"hidden",onChange:x=>{x.target.files&&e(x.target.files),x.target.value=""}}),b.jsx(Ei,{variant:"outline",size:"sm",className:"w-full",onClick:()=>o.current?.click(),children:"Import Assets"})]})]})}const _C={type:"change"},_x={type:"start"},sT={type:"end"},vh=new Sp,yC=new Ds,mH=Math.cos(70*wi.DEG2RAD),ti=new he,Vi=2*Math.PI,xn={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},jg=1e-6;class oT extends bk{constructor(e,t=null){super(e,t),this.state=xn.NONE,this.target=new he,this.cursor=new he,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:tc.ROTATE,MIDDLE:tc.DOLLY,RIGHT:tc.PAN},this.touches={ONE:Yl.ROTATE,TWO:Yl.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new he,this._lastQuaternion=new Rn,this._lastTargetPosition=new he,this._quat=new Rn().setFromUnitVectors(e.up,new he(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new OS,this._sphericalDelta=new OS,this._scale=1,this._panOffset=new he,this._rotateStart=new Tt,this._rotateEnd=new Tt,this._rotateDelta=new Tt,this._panStart=new Tt,this._panEnd=new Tt,this._panDelta=new Tt,this._dollyStart=new Tt,this._dollyEnd=new Tt,this._dollyDelta=new Tt,this._dollyDirection=new he,this._mouse=new Tt,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=vH.bind(this),this._onPointerDown=gH.bind(this),this._onPointerUp=xH.bind(this),this._onContextMenu=wH.bind(this),this._onMouseWheel=EH.bind(this),this._onKeyDown=bH.bind(this),this._onTouchStart=SH.bind(this),this._onTouchMove=CH.bind(this),this._onMouseDown=_H.bind(this),this._onMouseMove=yH.bind(this),this._interceptControlDown=MH.bind(this),this._interceptControlUp=IH.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(_C),this.update(),this.state=xn.NONE}update(e=null){const t=this.object.position;ti.copy(t).sub(this.target),ti.applyQuaternion(this._quat),this._spherical.setFromVector3(ti),this.autoRotate&&this.state===xn.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let i=this.minAzimuthAngle,a=this.maxAzimuthAngle;isFinite(i)&&isFinite(a)&&(i<-Math.PI?i+=Vi:i>Math.PI&&(i-=Vi),a<-Math.PI?a+=Vi:a>Math.PI&&(a-=Vi),i<=a?this._spherical.theta=Math.max(i,Math.min(a,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(i+a)/2?Math.max(i,this._spherical.theta):Math.min(a,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let o=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const l=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),o=l!=this._spherical.radius}if(ti.setFromSpherical(this._spherical),ti.applyQuaternion(this._quatInverse),t.copy(this.target).add(ti),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let l=null;if(this.object.isPerspectiveCamera){const u=ti.length();l=this._clampDistance(u*this._scale);const f=u-l;this.object.position.addScaledVector(this._dollyDirection,f),this.object.updateMatrixWorld(),o=!!f}else if(this.object.isOrthographicCamera){const u=new he(this._mouse.x,this._mouse.y,0);u.unproject(this.object);const f=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),o=f!==this.object.zoom;const h=new he(this._mouse.x,this._mouse.y,0);h.unproject(this.object),this.object.position.sub(h).add(u),this.object.updateMatrixWorld(),l=ti.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;l!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(l).add(this.object.position):(vh.origin.copy(this.object.position),vh.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(vh.direction))<mH?this.object.lookAt(this.target):(yC.setFromNormalAndCoplanarPoint(this.object.up,this.target),vh.intersectPlane(yC,this.target))))}else if(this.object.isOrthographicCamera){const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),l!==this.object.zoom&&(this.object.updateProjectionMatrix(),o=!0)}return this._scale=1,this._performCursorZoom=!1,o||this._lastPosition.distanceToSquared(this.object.position)>jg||8*(1-this._lastQuaternion.dot(this.object.quaternion))>jg||this._lastTargetPosition.distanceToSquared(this.target)>jg?(this.dispatchEvent(_C),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?Vi/60*this.autoRotateSpeed*e:Vi/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){ti.setFromMatrixColumn(t,0),ti.multiplyScalar(-e),this._panOffset.add(ti)}_panUp(e,t){this.screenSpacePanning===!0?ti.setFromMatrixColumn(t,1):(ti.setFromMatrixColumn(t,0),ti.crossVectors(this.object.up,ti)),ti.multiplyScalar(e),this._panOffset.add(ti)}_pan(e,t){const i=this.domElement;if(this.object.isPerspectiveCamera){const a=this.object.position;ti.copy(a).sub(this.target);let o=ti.length();o*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*o/i.clientHeight,this.object.matrix),this._panUp(2*t*o/i.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/i.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/i.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const i=this.domElement.getBoundingClientRect(),a=e-i.left,o=t-i.top,l=i.width,u=i.height;this._mouse.x=a/l*2-1,this._mouse.y=-(o/u)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(Vi*this._rotateDelta.x/t.clientHeight),this._rotateUp(Vi*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(Vi*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-Vi*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(Vi*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-Vi*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),i=.5*(e.pageX+t.x),a=.5*(e.pageY+t.y);this._rotateStart.set(i,a)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),i=.5*(e.pageX+t.x),a=.5*(e.pageY+t.y);this._panStart.set(i,a)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),i=e.pageX-t.x,a=e.pageY-t.y,o=Math.sqrt(i*i+a*a);this._dollyStart.set(0,o)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const i=this._getSecondPointerPosition(e),a=.5*(e.pageX+i.x),o=.5*(e.pageY+i.y);this._rotateEnd.set(a,o)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(Vi*this._rotateDelta.x/t.clientHeight),this._rotateUp(Vi*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),i=.5*(e.pageX+t.x),a=.5*(e.pageY+t.y);this._panEnd.set(i,a)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),i=e.pageX-t.x,a=e.pageY-t.y,o=Math.sqrt(i*i+a*a);this._dollyEnd.set(0,o),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const l=(e.pageX+t.x)*.5,u=(e.pageY+t.y)*.5;this._updateZoomParameters(l,u)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new Tt,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,i={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:i.deltaY*=16;break;case 2:i.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(i.deltaY*=10),i}}function gH(n){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(n.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(n)&&(this._addPointer(n),n.pointerType==="touch"?this._onTouchStart(n):this._onMouseDown(n)))}function vH(n){this.enabled!==!1&&(n.pointerType==="touch"?this._onTouchMove(n):this._onMouseMove(n))}function xH(n){switch(this._removePointer(n),this._pointers.length){case 0:this.domElement.releasePointerCapture(n.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(sT),this.state=xn.NONE;break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function _H(n){let e;switch(n.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case tc.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(n),this.state=xn.DOLLY;break;case tc.ROTATE:if(n.ctrlKey||n.metaKey||n.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(n),this.state=xn.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(n),this.state=xn.ROTATE}break;case tc.PAN:if(n.ctrlKey||n.metaKey||n.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(n),this.state=xn.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(n),this.state=xn.PAN}break;default:this.state=xn.NONE}this.state!==xn.NONE&&this.dispatchEvent(_x)}function yH(n){switch(this.state){case xn.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(n);break;case xn.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(n);break;case xn.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(n);break}}function EH(n){this.enabled===!1||this.enableZoom===!1||this.state!==xn.NONE||(n.preventDefault(),this.dispatchEvent(_x),this._handleMouseWheel(this._customWheelEvent(n)),this.dispatchEvent(sT))}function bH(n){this.enabled!==!1&&this._handleKeyDown(n)}function SH(n){switch(this._trackPointer(n),this._pointers.length){case 1:switch(this.touches.ONE){case Yl.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(n),this.state=xn.TOUCH_ROTATE;break;case Yl.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(n),this.state=xn.TOUCH_PAN;break;default:this.state=xn.NONE}break;case 2:switch(this.touches.TWO){case Yl.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(n),this.state=xn.TOUCH_DOLLY_PAN;break;case Yl.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(n),this.state=xn.TOUCH_DOLLY_ROTATE;break;default:this.state=xn.NONE}break;default:this.state=xn.NONE}this.state!==xn.NONE&&this.dispatchEvent(_x)}function CH(n){switch(this._trackPointer(n),this.state){case xn.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(n),this.update();break;case xn.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(n),this.update();break;case xn.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(n),this.update();break;case xn.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(n),this.update();break;default:this.state=xn.NONE}}function wH(n){this.enabled!==!1&&n.preventDefault()}function MH(n){n.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function IH(n){n.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}var vr=Uint8Array,Zl=Uint16Array,TH=Int32Array,lT=new vr([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),cT=new vr([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),BH=new vr([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),uT=function(n,e){for(var t=new Zl(31),i=0;i<31;++i)t[i]=e+=1<<n[i-1];for(var a=new TH(t[30]),i=1;i<30;++i)for(var o=t[i];o<t[i+1];++o)a[o]=o-t[i]<<5|i;return{b:t,r:a}},fT=uT(lT,2),dT=fT.b,RH=fT.r;dT[28]=258,RH[258]=28;var DH=uT(cT,0),NH=DH.b,nv=new Zl(32768);for(var Mn=0;Mn<32768;++Mn){var Bs=(Mn&43690)>>1|(Mn&21845)<<1;Bs=(Bs&52428)>>2|(Bs&13107)<<2,Bs=(Bs&61680)>>4|(Bs&3855)<<4,nv[Mn]=((Bs&65280)>>8|(Bs&255)<<8)>>1}var Vu=(function(n,e,t){for(var i=n.length,a=0,o=new Zl(e);a<i;++a)n[a]&&++o[n[a]-1];var l=new Zl(e);for(a=1;a<e;++a)l[a]=l[a-1]+o[a-1]<<1;var u;if(t){u=new Zl(1<<e);var f=15-e;for(a=0;a<i;++a)if(n[a])for(var h=a<<4|n[a],A=e-n[a],p=l[n[a]-1]++<<A,m=p|(1<<A)-1;p<=m;++p)u[nv[p]>>f]=h}else for(u=new Zl(i),a=0;a<i;++a)n[a]&&(u[a]=nv[l[n[a]-1]++]>>15-n[a]);return u}),bf=new vr(288);for(var Mn=0;Mn<144;++Mn)bf[Mn]=8;for(var Mn=144;Mn<256;++Mn)bf[Mn]=9;for(var Mn=256;Mn<280;++Mn)bf[Mn]=7;for(var Mn=280;Mn<288;++Mn)bf[Mn]=8;var hT=new vr(32);for(var Mn=0;Mn<32;++Mn)hT[Mn]=5;var LH=Vu(bf,9,1),UH=Vu(hT,5,1),Wg=function(n){for(var e=n[0],t=1;t<n.length;++t)n[t]>e&&(e=n[t]);return e},Rr=function(n,e,t){var i=e/8|0;return(n[i]|n[i+1]<<8)>>(e&7)&t},Xg=function(n,e){var t=e/8|0;return(n[t]|n[t+1]<<8|n[t+2]<<16)>>(e&7)},PH=function(n){return(n+7)/8|0},FH=function(n,e,t){return(t==null||t>n.length)&&(t=n.length),new vr(n.subarray(e,t))},OH=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Lr=function(n,e,t){var i=new Error(e||OH[n]);if(i.code=n,Error.captureStackTrace&&Error.captureStackTrace(i,Lr),!t)throw i;return i},kH=function(n,e,t,i){var a=n.length,o=0;if(!a||e.f&&!e.l)return t||new vr(0);var l=!t,u=l||e.i!=2,f=e.i;l&&(t=new vr(a*3));var h=function(Je){var pt=t.length;if(Je>pt){var ct=new vr(Math.max(pt*2,Je));ct.set(t),t=ct}},A=e.f||0,p=e.p||0,m=e.b||0,g=e.l,x=e.d,E=e.m,S=e.n,y=a*8;do{if(!g){A=Rr(n,p,1);var I=Rr(n,p+1,3);if(p+=3,I)if(I==1)g=LH,x=UH,E=9,S=5;else if(I==2){var B=Rr(n,p,31)+257,L=Rr(n,p+10,15)+4,O=B+Rr(n,p+5,31)+1;p+=14;for(var R=new vr(O),F=new vr(19),j=0;j<L;++j)F[BH[j]]=Rr(n,p+j*3,7);p+=L*3;for(var V=Wg(F),W=(1<<V)-1,te=Vu(F,V,1),j=0;j<O;){var ne=te[Rr(n,p,W)];p+=ne&15;var M=ne>>4;if(M<16)R[j++]=M;else{var k=0,X=0;for(M==16?(X=3+Rr(n,p,3),p+=2,k=R[j-1]):M==17?(X=3+Rr(n,p,7),p+=3):M==18&&(X=11+Rr(n,p,127),p+=7);X--;)R[j++]=k}}var Y=R.subarray(0,B),ee=R.subarray(B);E=Wg(Y),S=Wg(ee),g=Vu(Y,E,1),x=Vu(ee,S,1)}else Lr(1);else{var M=PH(p)+4,C=n[M-4]|n[M-3]<<8,T=M+C;if(T>a){f&&Lr(0);break}u&&h(m+C),t.set(n.subarray(M,T),m),e.b=m+=C,e.p=p=T*8,e.f=A;continue}if(p>y){f&&Lr(0);break}}u&&h(m+131072);for(var q=(1<<E)-1,Q=(1<<S)-1,re=p;;re=p){var k=g[Xg(n,p)&q],ue=k>>4;if(p+=k&15,p>y){f&&Lr(0);break}if(k||Lr(2),ue<256)t[m++]=ue;else if(ue==256){re=p,g=null;break}else{var xe=ue-254;if(ue>264){var j=ue-257,Me=lT[j];xe=Rr(n,p,(1<<Me)-1)+dT[j],p+=Me}var se=x[Xg(n,p)&Q],Ae=se>>4;se||Lr(3),p+=se&15;var ee=NH[Ae];if(Ae>3){var Me=cT[Ae];ee+=Xg(n,p)&(1<<Me)-1,p+=Me}if(p>y){f&&Lr(0);break}u&&h(m+131072);var Qe=m+xe;if(m<ee){var We=o-ee,qe=Math.min(ee,Qe);for(We+m<0&&Lr(3);m<qe;++m)t[m]=i[We+m]}for(;m<Qe;++m)t[m]=t[m-ee]}}e.l=g,e.p=re,e.b=m,e.f=A,g&&(A=1,e.m=E,e.d=x,e.n=S)}while(!A);return m!=t.length&&l?FH(t,0,m):t.subarray(0,m)},QH=new vr(0),zH=function(n,e){return((n[0]&15)!=8||n[0]>>4>7||(n[0]<<8|n[1])%31)&&Lr(6,"invalid zlib data"),(n[1]>>5&1)==1&&Lr(6,"invalid zlib data: "+(n[1]&32?"need":"unexpected")+" dictionary"),(n[1]>>3&4)+2};function GH(n,e){return kH(n.subarray(zH(n),-4),{i:2},e,e)}var HH=typeof TextDecoder<"u"&&new TextDecoder,VH=0;try{HH.decode(QH,{stream:!0}),VH=1}catch{}function pT(n,e,t){const i=t.length-n-1;if(e>=t[i])return i-1;if(e<=t[n])return n;let a=n,o=i,l=Math.floor((a+o)/2);for(;e<t[l]||e>=t[l+1];)e<t[l]?o=l:a=l,l=Math.floor((a+o)/2);return l}function jH(n,e,t,i){const a=[],o=[],l=[];a[0]=1;for(let u=1;u<=t;++u){o[u]=e-i[n+1-u],l[u]=i[n+u]-e;let f=0;for(let h=0;h<u;++h){const A=l[h+1],p=o[u-h],m=a[h]/(A+p);a[h]=f+A*m,f=p*m}a[u]=f}return a}function WH(n,e,t,i){const a=pT(n,i,e),o=jH(a,i,n,e),l=new un(0,0,0,0);for(let u=0;u<=n;++u){const f=t[a-n+u],h=o[u],A=f.w*h;l.x+=f.x*A,l.y+=f.y*A,l.z+=f.z*A,l.w+=f.w*h}return l}function XH(n,e,t,i,a){const o=[];for(let p=0;p<=t;++p)o[p]=0;const l=[];for(let p=0;p<=i;++p)l[p]=o.slice(0);const u=[];for(let p=0;p<=t;++p)u[p]=o.slice(0);u[0][0]=1;const f=o.slice(0),h=o.slice(0);for(let p=1;p<=t;++p){f[p]=e-a[n+1-p],h[p]=a[n+p]-e;let m=0;for(let g=0;g<p;++g){const x=h[g+1],E=f[p-g];u[p][g]=x+E;const S=u[g][p-1]/u[p][g];u[g][p]=m+x*S,m=E*S}u[p][p]=m}for(let p=0;p<=t;++p)l[0][p]=u[p][t];for(let p=0;p<=t;++p){let m=0,g=1;const x=[];for(let E=0;E<=t;++E)x[E]=o.slice(0);x[0][0]=1;for(let E=1;E<=i;++E){let S=0;const y=p-E,I=t-E;p>=E&&(x[g][0]=x[m][0]/u[I+1][y],S=x[g][0]*u[y][I]);const M=y>=-1?1:-y,C=p-1<=I?E-1:t-p;for(let B=M;B<=C;++B)x[g][B]=(x[m][B]-x[m][B-1])/u[I+1][y+B],S+=x[g][B]*u[y+B][I];p<=I&&(x[g][E]=-x[m][E-1]/u[I+1][p],S+=x[g][E]*u[p][I]),l[E][p]=S;const T=m;m=g,g=T}}let A=t;for(let p=1;p<=i;++p){for(let m=0;m<=t;++m)l[p][m]*=A;A*=t-p}return l}function qH(n,e,t,i,a){const o=a<n?a:n,l=[],u=pT(n,i,e),f=XH(u,i,n,o,e),h=[];for(let A=0;A<t.length;++A){const p=t[A].clone(),m=p.w;p.x*=m,p.y*=m,p.z*=m,h[A]=p}for(let A=0;A<=o;++A){const p=h[u-n].clone().multiplyScalar(f[A][0]);for(let m=1;m<=n;++m)p.add(h[u-n+m].clone().multiplyScalar(f[A][m]));l[A]=p}for(let A=o+1;A<=a+1;++A)l[A]=new un(0,0,0);return l}function YH(n,e){let t=1;for(let a=2;a<=n;++a)t*=a;let i=1;for(let a=2;a<=e;++a)i*=a;for(let a=2;a<=n-e;++a)i*=a;return t/i}function KH(n){const e=n.length,t=[],i=[];for(let o=0;o<e;++o){const l=n[o];t[o]=new he(l.x,l.y,l.z),i[o]=l.w}const a=[];for(let o=0;o<e;++o){const l=t[o].clone();for(let u=1;u<=o;++u)l.sub(a[o-u].clone().multiplyScalar(YH(o,u)*i[u]));a[o]=l.divideScalar(i[0])}return a}function JH(n,e,t,i,a){const o=qH(n,e,t,i,a);return KH(o)}class ZH extends bO{constructor(e,t,i,a,o){super();const l=t?t.length-1:0,u=i?i.length:0;this.degree=e,this.knots=t,this.controlPoints=[],this.startKnot=a||0,this.endKnot=o||l;for(let f=0;f<u;++f){const h=i[f];this.controlPoints[f]=new un(h.x,h.y,h.z,h.w)}}getPoint(e,t=new he){const i=t,a=this.knots[this.startKnot]+e*(this.knots[this.endKnot]-this.knots[this.startKnot]),o=WH(this.degree,this.knots,this.controlPoints,a);return o.w!==1&&o.divideScalar(o.w),i.set(o.x,o.y,o.z)}getTangent(e,t=new he){const i=t,a=this.knots[0]+e*(this.knots[this.knots.length-1]-this.knots[0]),o=JH(this.degree,this.knots,this.controlPoints,a,1);return i.copy(o[1]).normalize(),i}toJSON(){const e=super.toJSON();return e.degree=this.degree,e.knots=[...this.knots],e.controlPoints=this.controlPoints.map(t=>t.toArray()),e.startKnot=this.startKnot,e.endKnot=this.endKnot,e}fromJSON(e){return super.fromJSON(e),this.degree=e.degree,this.knots=[...e.knots],this.controlPoints=e.controlPoints.map(t=>new un(t[0],t[1],t[2],t[3])),this.startKnot=e.startKnot,this.endKnot=e.endKnot,this}}let Gt,kn,yi;class $H extends Qs{constructor(e){super(e)}load(e,t,i,a){const o=this,l=o.path===""?ok.extractUrlBase(e):o.path,u=new Mh(this.manager);u.setPath(o.path),u.setResponseType("arraybuffer"),u.setRequestHeader(o.requestHeader),u.setWithCredentials(o.withCredentials),u.load(e,function(f){try{t(o.parse(f,l))}catch(h){a?a(h):console.error(h),o.manager.itemError(e)}},i,a)}parse(e,t){if(a8(e))Gt=new r8().parse(e);else{const a=gT(e);if(!s8(a))throw new Error("THREE.FBXLoader: Unknown format.");if(bC(a)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+bC(a));Gt=new i8().parse(a)}const i=new nk(this.manager).setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin);return new e8(i,this.manager).parse(Gt)}}class e8{constructor(e,t){this.textureLoader=e,this.manager=t}parse(){kn=this.parseConnections();const e=this.parseImages(),t=this.parseTextures(e),i=this.parseMaterials(t),a=this.parseDeformers(),o=new t8().parse(a);return this.parseScene(a,o,i),yi.__fbxTree=Gt,yi.__fbxConnections=kn,yi}parseConnections(){class e extends Map{get(a){return this.has(a)||this.set(a,{parents:[],children:[]}),super.get(a)}}const t=new e;return"Connections"in Gt&&Gt.Connections.connections.forEach(function(a){const o=a[0],l=a[1],u=a[2];t.has(o)||t.set(o,{parents:[],children:[]});const f={ID:l,relationship:u};t.get(o).parents.push(f),t.has(l)||t.set(l,{parents:[],children:[]});const h={ID:o,relationship:u};t.get(l).children.push(h)}),t}parseImages(){const e={},t={};if("Video"in Gt.Objects){const i=Gt.Objects.Video;for(const a in i){const o=i[a],l=parseInt(a);if(e[l]=o.RelativeFilename||o.Filename,"Content"in o){const u=o.Content instanceof ArrayBuffer&&o.Content.byteLength>0,f=typeof o.Content=="string"&&o.Content!=="";if(u||f){const h=this.parseImage(i[a]);t[o.RelativeFilename||o.Filename]=h}}}}for(const i in e){const a=e[i];t[a]!==void 0?e[i]=t[a]:e[i]=e[i].split("\\").pop()}return e}parseImage(e){const t=e.Content,i=e.RelativeFilename||e.Filename,a=i.slice(i.lastIndexOf(".")+1).toLowerCase();let o;switch(a){case"bmp":o="image/bmp";break;case"jpg":case"jpeg":o="image/jpeg";break;case"png":o="image/png";break;case"tif":o="image/tiff";break;case"tga":this.manager.getHandler(".tga")===null&&console.warn("FBXLoader: TGA loader not found, skipping ",i),o="image/tga";break;case"webp":o="image/webp";break;default:console.warn('FBXLoader: Image type "'+a+'" is not supported.');return}if(typeof t=="string")return"data:"+o+";base64,"+t;{const l=new Uint8Array(t);return window.URL.createObjectURL(new Blob([l],{type:o}))}}parseTextures(e){const t=new Map;if("Texture"in Gt.Objects){const i=Gt.Objects.Texture;for(const a in i){const o=this.parseTexture(i[a],e);t.set(parseInt(a),o)}}return t}parseTexture(e,t){const i=this.loadTexture(e,t);i.ID=e.id,i.name=e.attrName;const a=e.WrapModeU,o=e.WrapModeV,l=a!==void 0?a.value:0,u=o!==void 0?o.value:0;if(i.wrapS=l===0?No:xr,i.wrapT=u===0?No:xr,"Scaling"in e){const f=e.Scaling.value;i.repeat.x=f[0],i.repeat.y=f[1]}if("Translation"in e){const f=e.Translation.value;i.offset.x=f[0],i.offset.y=f[1]}return i}loadTexture(e,t){const i=e.FileName.split(".").pop().toLowerCase();let a=this.manager.getHandler(`.${i}`);a===null&&(a=this.textureLoader);const o=a.path;o||a.setPath(this.textureLoader.path);const l=kn.get(e.id).children;let u;if(l!==void 0&&l.length>0&&t[l[0].ID]!==void 0&&(u=t[l[0].ID],(u.indexOf("blob:")===0||u.indexOf("data:")===0)&&a.setPath(void 0)),u===void 0)return console.warn("FBXLoader: Undefined filename, creating placeholder texture."),new ui;const f=a.load(u);return a.setPath(o),f}parseMaterials(e){const t=new Map;if("Material"in Gt.Objects){const i=Gt.Objects.Material;for(const a in i){const o=this.parseMaterial(i[a],e);o!==null&&t.set(parseInt(a),o)}}return t}parseMaterial(e,t){const i=e.id,a=e.attrName;let o=e.ShadingModel;if(typeof o=="object"&&(o=o.value),!kn.has(i))return null;const l=this.parseParameters(e,t,i);let u;switch(o.toLowerCase()){case"phong":u=new hh;break;case"lambert":u=new HO;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',o),u=new hh;break}return u.setValues(l),u.name=a,u}parseParameters(e,t,i){const a={};e.BumpFactor&&(a.bumpScale=e.BumpFactor.value),e.Diffuse?a.color=kt.colorSpaceToWorking(new Ct().fromArray(e.Diffuse.value),vn):e.DiffuseColor&&(e.DiffuseColor.type==="Color"||e.DiffuseColor.type==="ColorRGB")&&(a.color=kt.colorSpaceToWorking(new Ct().fromArray(e.DiffuseColor.value),vn)),e.DisplacementFactor&&(a.displacementScale=e.DisplacementFactor.value),e.Emissive?a.emissive=kt.colorSpaceToWorking(new Ct().fromArray(e.Emissive.value),vn):e.EmissiveColor&&(e.EmissiveColor.type==="Color"||e.EmissiveColor.type==="ColorRGB")&&(a.emissive=kt.colorSpaceToWorking(new Ct().fromArray(e.EmissiveColor.value),vn)),e.EmissiveFactor&&(a.emissiveIntensity=parseFloat(e.EmissiveFactor.value)),a.opacity=1-(e.TransparencyFactor?parseFloat(e.TransparencyFactor.value):0),(a.opacity===1||a.opacity===0)&&(a.opacity=e.Opacity?parseFloat(e.Opacity.value):null,a.opacity===null&&(a.opacity=1-(e.TransparentColor?parseFloat(e.TransparentColor.value[0]):0))),a.opacity<1&&(a.transparent=!0),e.ReflectionFactor&&(a.reflectivity=e.ReflectionFactor.value),e.Shininess&&(a.shininess=e.Shininess.value),e.Specular?a.specular=kt.colorSpaceToWorking(new Ct().fromArray(e.Specular.value),vn):e.SpecularColor&&e.SpecularColor.type==="Color"&&(a.specular=kt.colorSpaceToWorking(new Ct().fromArray(e.SpecularColor.value),vn));const o=this;return kn.get(i).children.forEach(function(l){const u=l.relationship;switch(u){case"Bump":a.bumpMap=o.getTexture(t,l.ID);break;case"Maya|TEX_ao_map":a.aoMap=o.getTexture(t,l.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":a.map=o.getTexture(t,l.ID),a.map!==void 0&&(a.map.colorSpace=vn);break;case"DisplacementColor":a.displacementMap=o.getTexture(t,l.ID);break;case"EmissiveColor":a.emissiveMap=o.getTexture(t,l.ID),a.emissiveMap!==void 0&&(a.emissiveMap.colorSpace=vn);break;case"NormalMap":case"Maya|TEX_normal_map":a.normalMap=o.getTexture(t,l.ID);break;case"ReflectionColor":a.envMap=o.getTexture(t,l.ID),a.envMap!==void 0&&(a.envMap.mapping=kh,a.envMap.colorSpace=vn);break;case"SpecularColor":a.specularMap=o.getTexture(t,l.ID),a.specularMap!==void 0&&(a.specularMap.colorSpace=vn);break;case"TransparentColor":case"TransparencyFactor":a.alphaMap=o.getTexture(t,l.ID),a.transparent=!0;break;default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",u);break}}),a}getTexture(e,t){return"LayeredTexture"in Gt.Objects&&t in Gt.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=kn.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in Gt.Objects){const i=Gt.Objects.Deformer;for(const a in i){const o=i[a],l=kn.get(parseInt(a));if(o.attrType==="Skin"){const u=this.parseSkeleton(l,i);u.ID=a,l.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),u.geometryID=l.parents[0].ID,e[a]=u}else if(o.attrType==="BlendShape"){const u={id:a};u.rawTargets=this.parseMorphTargets(l,i),u.id=a,l.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[a]=u}}}return{skeletons:e,morphTargets:t}}parseSkeleton(e,t){const i=[];return e.children.forEach(function(a){const o=t[a.ID];if(o.attrType!=="Cluster")return;const l={ID:a.ID,indices:[],weights:[],transformLink:new vt().fromArray(o.TransformLink.a)};"Indexes"in o&&(l.indices=o.Indexes.a,l.weights=o.Weights.a),i.push(l)}),{rawBones:i,bones:[]}}parseMorphTargets(e,t){const i=[];for(let a=0;a<e.children.length;a++){const o=e.children[a],l=t[o.ID],u={name:l.attrName,initialWeight:l.DeformPercent,id:l.id,fullWeights:l.FullWeights.a};if(l.attrType!=="BlendShapeChannel")return;u.geoID=kn.get(parseInt(o.ID)).children.filter(function(f){return f.relationship===void 0})[0].ID,i.push(u)}return i}parseScene(e,t,i){yi=new Qa;const a=this.parseModels(e.skeletons,t,i),o=Gt.Objects.Model,l=this;a.forEach(function(f){const h=o[f.ID];l.setLookAtProperties(f,h),kn.get(f.ID).parents.forEach(function(p){const m=a.get(p.ID);m!==void 0&&m.add(f)}),f.parent===null&&yi.add(f)}),this.bindSkeleton(e.skeletons,t,a),this.addGlobalSceneSettings(),yi.traverse(function(f){if(f.userData.transformData){f.parent&&(f.userData.transformData.parentMatrix=f.parent.matrix,f.userData.transformData.parentMatrixWorld=f.parent.matrixWorld);const h=mT(f.userData.transformData);f.applyMatrix4(h),f.updateWorldMatrix()}});const u=new n8().parse();yi.children.length===1&&yi.children[0].isGroup&&(yi.children[0].animations=u,yi=yi.children[0]),yi.animations=u}parseModels(e,t,i){const a=new Map,o=Gt.Objects.Model;for(const l in o){const u=parseInt(l),f=o[l],h=kn.get(u);let A=this.buildSkeleton(h,e,u,f.attrName);if(!A){switch(f.attrType){case"Camera":A=this.createCamera(h);break;case"Light":A=this.createLight(h);break;case"Mesh":A=this.createMesh(h,t,i);break;case"NurbsCurve":A=this.createCurve(h,t);break;case"LimbNode":case"Root":A=new tp;break;default:A=new Qa;break}A.name=f.attrName?Kt.sanitizeNodeName(f.attrName):"",A.userData.originalName=f.attrName,A.ID=u}this.getTransformData(A,f),a.set(u,A)}return a}buildSkeleton(e,t,i,a){let o=null;return e.parents.forEach(function(l){for(const u in t){const f=t[u];f.rawBones.forEach(function(h,A){if(h.ID===l.ID){const p=o;o=new tp,o.matrixWorld.copy(h.transformLink),o.name=a?Kt.sanitizeNodeName(a):"",o.userData.originalName=a,o.ID=i,f.bones[A]=o,p!==null&&o.add(p)}})}}),o}createCamera(e){let t,i;if(e.children.forEach(function(a){const o=Gt.Objects.NodeAttribute[a.ID];o!==void 0&&(i=o)}),i===void 0)t=new Dn;else{let a=0;i.CameraProjectionType!==void 0&&i.CameraProjectionType.value===1&&(a=1);let o=1;i.NearPlane!==void 0&&(o=i.NearPlane.value/1e3);let l=1e3;i.FarPlane!==void 0&&(l=i.FarPlane.value/1e3);let u=window.innerWidth,f=window.innerHeight;i.AspectWidth!==void 0&&i.AspectHeight!==void 0&&(u=i.AspectWidth.value,f=i.AspectHeight.value);const h=u/f;let A=45;i.FieldOfView!==void 0&&(A=i.FieldOfView.value);const p=i.FocalLength?i.FocalLength.value:null;switch(a){case 0:t=new Mi(A,h,o,l),p!==null&&t.setFocalLength(p);break;case 1:console.warn("THREE.FBXLoader: Orthographic cameras not supported yet."),t=new Dn;break;default:console.warn("THREE.FBXLoader: Unknown camera type "+a+"."),t=new Dn;break}}return t}createLight(e){let t,i;if(e.children.forEach(function(a){const o=Gt.Objects.NodeAttribute[a.ID];o!==void 0&&(i=o)}),i===void 0)t=new Dn;else{let a;i.LightType===void 0?a=0:a=i.LightType.value;let o=16777215;i.Color!==void 0&&(o=kt.colorSpaceToWorking(new Ct().fromArray(i.Color.value),vn));let l=i.Intensity===void 0?1:i.Intensity.value/100;i.CastLightOnObject!==void 0&&i.CastLightOnObject.value===0&&(l=0);let u=0;i.FarAttenuationEnd!==void 0&&(i.EnableFarAttenuation!==void 0&&i.EnableFarAttenuation.value===0?u=0:u=i.FarAttenuationEnd.value);const f=1;switch(a){case 0:t=new FS(o,l,u,f);break;case 1:t=new uf(o,l);break;case 2:let h=Math.PI/3;i.InnerAngle!==void 0&&(h=wi.degToRad(i.InnerAngle.value));let A=0;i.OuterAngle!==void 0&&(A=wi.degToRad(i.OuterAngle.value),A=Math.max(A,1)),t=new rk(o,l,u,h,A,f);break;default:console.warn("THREE.FBXLoader: Unknown light type "+i.LightType.value+", defaulting to a PointLight."),t=new FS(o,l);break}i.CastShadows!==void 0&&i.CastShadows.value===1&&(t.castShadow=!0)}return t}createMesh(e,t,i){let a,o=null,l=null;const u=[];if(e.children.forEach(function(f){t.has(f.ID)&&(o=t.get(f.ID)),i.has(f.ID)&&u.push(i.get(f.ID))}),u.length>1?l=u:u.length>0?l=u[0]:(l=new hh({name:Qs.DEFAULT_MATERIAL_NAME,color:13421772}),u.push(l)),"color"in o.attributes&&u.forEach(function(f){f.vertexColors=!0}),o.groups.length>0){let f=!1;for(let h=0,A=o.groups.length;h<A;h++){const p=o.groups[h];(p.materialIndex<0||p.materialIndex>=u.length)&&(p.materialIndex=u.length,f=!0)}if(f){const h=new hh;u.push(h)}}return o.FBX_Deformer?(a=new qM(o,l),a.normalizeSkinWeights()):a=new Nn(o,l),a}createCurve(e,t){const i=e.children.reduce(function(o,l){return t.has(l.ID)&&(o=t.get(l.ID)),o},null),a=new rx({name:Qs.DEFAULT_MATERIAL_NAME,color:3342591,linewidth:1});return new Ip(i,a)}getTransformData(e,t){const i={};"InheritType"in t&&(i.inheritType=parseInt(t.InheritType.value)),"RotationOrder"in t?i.eulerOrder=ff(t.RotationOrder.value):i.eulerOrder=ff(0),"Lcl_Translation"in t&&(i.translation=t.Lcl_Translation.value),"PreRotation"in t&&(i.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(i.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(i.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(i.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(i.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(i.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(i.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(i.rotationPivot=t.RotationPivot.value),e.userData.transformData=i}setLookAtProperties(e,t){"LookAtProperty"in t&&kn.get(e.ID).children.forEach(function(a){if(a.relationship==="LookAtProperty"){const o=Gt.Objects.Model[a.ID];if("Lcl_Translation"in o){const l=o.Lcl_Translation.value;e.target!==void 0?(e.target.position.fromArray(l),yi.add(e.target)):e.lookAt(new he().fromArray(l))}}})}bindSkeleton(e,t,i){const a=this.parsePoseNodes();for(const o in e){const l=e[o];kn.get(parseInt(l.ID)).parents.forEach(function(f){if(t.has(f.ID)){const h=f.ID;kn.get(h).parents.forEach(function(p){i.has(p.ID)&&i.get(p.ID).bind(new Mp(l.bones),a[p.ID])})}})}}parsePoseNodes(){const e={};if("Pose"in Gt.Objects){const t=Gt.Objects.Pose;for(const i in t)if(t[i].attrType==="BindPose"&&t[i].NbPoseNodes>0){const a=t[i].PoseNode;Array.isArray(a)?a.forEach(function(o){e[o.Node]=new vt().fromArray(o.Matrix.a)}):e[a.Node]=new vt().fromArray(a.Matrix.a)}}return e}addGlobalSceneSettings(){if("GlobalSettings"in Gt){if("AmbientColor"in Gt.GlobalSettings){const e=Gt.GlobalSettings.AmbientColor.value,t=e[0],i=e[1],a=e[2];if(t!==0||i!==0||a!==0){const o=new Ct().setRGB(t,i,a,vn);yi.add(new cx(o,1))}}"UnitScaleFactor"in Gt.GlobalSettings&&(yi.userData.unitScaleFactor=Gt.GlobalSettings.UnitScaleFactor.value)}}}class t8{constructor(){this.negativeMaterialIndices=!1}parse(e){const t=new Map;if("Geometry"in Gt.Objects){const i=Gt.Objects.Geometry;for(const a in i){const o=kn.get(parseInt(a)),l=this.parseGeometry(o,i[a],e);t.set(parseInt(a),l)}}return this.negativeMaterialIndices===!0&&console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."),t}parseGeometry(e,t,i){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,i);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,i){const a=i.skeletons,o=[],l=e.parents.map(function(p){return Gt.Objects.Model[p.ID]});if(l.length===0)return;const u=e.children.reduce(function(p,m){return a[m.ID]!==void 0&&(p=a[m.ID]),p},null);e.children.forEach(function(p){i.morphTargets[p.ID]!==void 0&&o.push(i.morphTargets[p.ID])});const f=l[0],h={};"RotationOrder"in f&&(h.eulerOrder=ff(f.RotationOrder.value)),"InheritType"in f&&(h.inheritType=parseInt(f.InheritType.value)),"GeometricTranslation"in f&&(h.translation=f.GeometricTranslation.value),"GeometricRotation"in f&&(h.rotation=f.GeometricRotation.value),"GeometricScaling"in f&&(h.scale=f.GeometricScaling.value);const A=mT(h);return this.genGeometry(t,u,o,A)}genGeometry(e,t,i,a){const o=new fi;e.attrName&&(o.name=e.attrName);const l=this.parseGeoNode(e,t),u=this.genBuffers(l),f=new _n(u.vertex,3);if(f.applyMatrix4(a),o.setAttribute("position",f),u.colors.length>0&&o.setAttribute("color",new _n(u.colors,3)),t&&(o.setAttribute("skinIndex",new wp(u.weightsIndices,4)),o.setAttribute("skinWeight",new _n(u.vertexWeights,4)),o.FBX_Deformer=t),u.normal.length>0){const h=new Ot().getNormalMatrix(a),A=new _n(u.normal,3);A.applyNormalMatrix(h),o.setAttribute("normal",A)}if(u.uvs.forEach(function(h,A){const p=A===0?"uv":`uv${A}`;o.setAttribute(p,new _n(u.uvs[A],2))}),l.material&&l.material.mappingType!=="AllSame"){let h=u.materialIndex[0],A=0;if(u.materialIndex.forEach(function(p,m){p!==h&&(o.addGroup(A,m-A,h),h=p,A=m)}),o.groups.length>0){const p=o.groups[o.groups.length-1],m=p.start+p.count;m!==u.materialIndex.length&&o.addGroup(m,u.materialIndex.length-m,h)}o.groups.length===0&&o.addGroup(0,u.materialIndex.length,u.materialIndex[0])}return this.addMorphTargets(o,e,i,a),o}parseGeoNode(e,t){const i={};if(i.vertexPositions=e.Vertices!==void 0?e.Vertices.a:[],i.vertexIndices=e.PolygonVertexIndex!==void 0?e.PolygonVertexIndex.a:[],e.LayerElementColor&&e.LayerElementColor[0].Colors&&(i.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(i.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(i.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){i.uv=[];let a=0;for(;e.LayerElementUV[a];)e.LayerElementUV[a].UV&&i.uv.push(this.parseUVs(e.LayerElementUV[a])),a++}return i.weightTable={},t!==null&&(i.skeleton=t,t.rawBones.forEach(function(a,o){a.indices.forEach(function(l,u){i.weightTable[l]===void 0&&(i.weightTable[l]=[]),i.weightTable[l].push({id:o,weight:a.weights[u]})})})),i}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let i=0,a=0,o=!1,l=[],u=[],f=[],h=[],A=[],p=[];const m=this;return e.vertexIndices.forEach(function(g,x){let E,S=!1;g<0&&(g=g^-1,S=!0);let y=[],I=[];if(l.push(g*3,g*3+1,g*3+2),e.color){const M=xh(x,i,g,e.color);f.push(M[0],M[1],M[2])}if(e.skeleton){if(e.weightTable[g]!==void 0&&e.weightTable[g].forEach(function(M){I.push(M.weight),y.push(M.id)}),I.length>4){o||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),o=!0);const M=[0,0,0,0],C=[0,0,0,0];I.forEach(function(T,B){let L=T,O=y[B];C.forEach(function(R,F,j){if(L>R){j[F]=L,L=R;const V=M[F];M[F]=O,O=V}})}),y=M,I=C}for(;I.length<4;)I.push(0),y.push(0);for(let M=0;M<4;++M)A.push(I[M]),p.push(y[M])}if(e.normal){const M=xh(x,i,g,e.normal);u.push(M[0],M[1],M[2])}e.material&&e.material.mappingType!=="AllSame"&&(E=xh(x,i,g,e.material)[0],E<0&&(m.negativeMaterialIndices=!0,E=0)),e.uv&&e.uv.forEach(function(M,C){const T=xh(x,i,g,M);h[C]===void 0&&(h[C]=[]),h[C].push(T[0]),h[C].push(T[1])}),a++,S&&(m.genFace(t,e,l,E,u,f,h,A,p,a),i++,a=0,l=[],u=[],f=[],h=[],A=[],p=[])}),t}getNormalNewell(e){const t=new he(0,0,0);for(let i=0;i<e.length;i++){const a=e[i],o=e[(i+1)%e.length];t.x+=(a.y-o.y)*(a.z+o.z),t.y+=(a.z-o.z)*(a.x+o.x),t.z+=(a.x-o.x)*(a.y+o.y)}return t.normalize(),t}getNormalTangentAndBitangent(e){const t=this.getNormalNewell(e),a=(Math.abs(t.z)>.5?new he(0,1,0):new he(0,0,1)).cross(t).normalize(),o=t.clone().cross(a).normalize();return{normal:t,tangent:a,bitangent:o}}flattenVertex(e,t,i){return new Tt(e.dot(t),e.dot(i))}genFace(e,t,i,a,o,l,u,f,h,A){let p;if(A>3){const m=[],g=t.baseVertexPositions||t.vertexPositions;for(let y=0;y<i.length;y+=3)m.push(new he(g[i[y]],g[i[y+1]],g[i[y+2]]));const{tangent:x,bitangent:E}=this.getNormalTangentAndBitangent(m),S=[];for(const y of m)S.push(this.flattenVertex(y,x,E));p=sx.triangulateShape(S,[])}else p=[[0,1,2]];for(const[m,g,x]of p)e.vertex.push(t.vertexPositions[i[m*3]]),e.vertex.push(t.vertexPositions[i[m*3+1]]),e.vertex.push(t.vertexPositions[i[m*3+2]]),e.vertex.push(t.vertexPositions[i[g*3]]),e.vertex.push(t.vertexPositions[i[g*3+1]]),e.vertex.push(t.vertexPositions[i[g*3+2]]),e.vertex.push(t.vertexPositions[i[x*3]]),e.vertex.push(t.vertexPositions[i[x*3+1]]),e.vertex.push(t.vertexPositions[i[x*3+2]]),t.skeleton&&(e.vertexWeights.push(f[m*4]),e.vertexWeights.push(f[m*4+1]),e.vertexWeights.push(f[m*4+2]),e.vertexWeights.push(f[m*4+3]),e.vertexWeights.push(f[g*4]),e.vertexWeights.push(f[g*4+1]),e.vertexWeights.push(f[g*4+2]),e.vertexWeights.push(f[g*4+3]),e.vertexWeights.push(f[x*4]),e.vertexWeights.push(f[x*4+1]),e.vertexWeights.push(f[x*4+2]),e.vertexWeights.push(f[x*4+3]),e.weightsIndices.push(h[m*4]),e.weightsIndices.push(h[m*4+1]),e.weightsIndices.push(h[m*4+2]),e.weightsIndices.push(h[m*4+3]),e.weightsIndices.push(h[g*4]),e.weightsIndices.push(h[g*4+1]),e.weightsIndices.push(h[g*4+2]),e.weightsIndices.push(h[g*4+3]),e.weightsIndices.push(h[x*4]),e.weightsIndices.push(h[x*4+1]),e.weightsIndices.push(h[x*4+2]),e.weightsIndices.push(h[x*4+3])),t.color&&(e.colors.push(l[m*3]),e.colors.push(l[m*3+1]),e.colors.push(l[m*3+2]),e.colors.push(l[g*3]),e.colors.push(l[g*3+1]),e.colors.push(l[g*3+2]),e.colors.push(l[x*3]),e.colors.push(l[x*3+1]),e.colors.push(l[x*3+2])),t.material&&t.material.mappingType!=="AllSame"&&(e.materialIndex.push(a),e.materialIndex.push(a),e.materialIndex.push(a)),t.normal&&(e.normal.push(o[m*3]),e.normal.push(o[m*3+1]),e.normal.push(o[m*3+2]),e.normal.push(o[g*3]),e.normal.push(o[g*3+1]),e.normal.push(o[g*3+2]),e.normal.push(o[x*3]),e.normal.push(o[x*3+1]),e.normal.push(o[x*3+2])),t.uv&&t.uv.forEach(function(E,S){e.uvs[S]===void 0&&(e.uvs[S]=[]),e.uvs[S].push(u[S][m*2]),e.uvs[S].push(u[S][m*2+1]),e.uvs[S].push(u[S][g*2]),e.uvs[S].push(u[S][g*2+1]),e.uvs[S].push(u[S][x*2]),e.uvs[S].push(u[S][x*2+1])})}addMorphTargets(e,t,i,a){if(i.length===0)return;e.morphTargetsRelative=!0,e.morphAttributes.position=[];const o=this;i.forEach(function(l){l.rawTargets.forEach(function(u){const f=Gt.Objects.Geometry[u.geoID];f!==void 0&&o.genMorphGeometry(e,t,f,a,u.name)})})}genMorphGeometry(e,t,i,a,o){const l=t.Vertices!==void 0?t.Vertices.a:[],u=t.PolygonVertexIndex!==void 0?t.PolygonVertexIndex.a:[],f=i.Vertices!==void 0?i.Vertices.a:[],h=i.Indexes!==void 0?i.Indexes.a:[],A=e.attributes.position.count*3,p=new Float32Array(A);for(let E=0;E<h.length;E++){const S=h[E]*3;p[S]=f[E*3],p[S+1]=f[E*3+1],p[S+2]=f[E*3+2]}const m={vertexIndices:u,vertexPositions:p,baseVertexPositions:l},g=this.genBuffers(m),x=new _n(g.vertex,3);x.name=o||i.attrName,x.applyMatrix4(a),e.morphAttributes.position.push(x)}parseNormals(e){const t=e.MappingInformationType,i=e.ReferenceInformationType,a=e.Normals.a;let o=[];return i==="IndexToDirect"&&("NormalIndex"in e?o=e.NormalIndex.a:"NormalsIndex"in e&&(o=e.NormalsIndex.a)),{dataSize:3,buffer:a,indices:o,mappingType:t,referenceType:i}}parseUVs(e){const t=e.MappingInformationType,i=e.ReferenceInformationType,a=e.UV.a;let o=[];return i==="IndexToDirect"&&(o=e.UVIndex.a),{dataSize:2,buffer:a,indices:o,mappingType:t,referenceType:i}}parseVertexColors(e){const t=e.MappingInformationType,i=e.ReferenceInformationType,a=e.Colors.a;let o=[];i==="IndexToDirect"&&(o=e.ColorIndex.a);for(let l=0,u=new Ct;l<a.length;l+=4)u.fromArray(a,l),kt.colorSpaceToWorking(u,vn),u.toArray(a,l);return{dataSize:4,buffer:a,indices:o,mappingType:t,referenceType:i}}parseMaterialIndices(e){const t=e.MappingInformationType,i=e.ReferenceInformationType;if(t==="NoMappingInformation")return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:i};const a=e.Materials.a,o=[];for(let l=0;l<a.length;++l)o.push(l);return{dataSize:1,buffer:a,indices:o,mappingType:t,referenceType:i}}parseNurbsGeometry(e){const t=parseInt(e.Order);if(isNaN(t))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",e.Order,e.id),new fi;const i=t-1,a=e.KnotVector.a,o=[],l=e.Points.a;for(let p=0,m=l.length;p<m;p+=4)o.push(new un().fromArray(l,p));let u,f;if(e.Form==="Closed")o.push(o[0]);else if(e.Form==="Periodic"){u=i,f=a.length-1-u;for(let p=0;p<i;++p)o.push(o[p])}const A=new ZH(i,a,o,u,f).getPoints(o.length*12);return new fi().setFromPoints(A)}}class n8{parse(){const e=[],t=this.parseClips();if(t!==void 0)for(const i in t){const a=t[i],o=this.addClip(a);e.push(o)}return e}parseClips(){if(Gt.Objects.AnimationCurve===void 0)return;const e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);const t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}parseAnimationCurveNodes(){const e=Gt.Objects.AnimationCurveNode,t=new Map;for(const i in e){const a=e[i];if(a.attrName.match(/S|R|T|DeformPercent/)!==null){const o={id:a.id,attr:a.attrName,curves:{}};t.set(o.id,o)}}return t}parseAnimationCurves(e){const t=Gt.Objects.AnimationCurve;for(const i in t){const a={id:t[i].id,times:t[i].KeyTime.a.map(o8),values:t[i].KeyValueFloat.a},o=kn.get(a.id);if(o!==void 0){const l=o.parents[0].ID,u=o.parents[0].relationship;u.match(/X/)?e.get(l).curves.x=a:u.match(/Y/)?e.get(l).curves.y=a:u.match(/Z/)?e.get(l).curves.z=a:u.match(/DeformPercent/)&&e.has(l)&&(e.get(l).curves.morph=a)}}}parseAnimationLayers(e){const t=Gt.Objects.AnimationLayer,i=new Map;for(const a in t){const o=[],l=kn.get(parseInt(a));l!==void 0&&(l.children.forEach(function(f,h){if(e.has(f.ID)){const A=e.get(f.ID);if(A.curves.x!==void 0||A.curves.y!==void 0||A.curves.z!==void 0){if(o[h]===void 0){const p=kn.get(f.ID).parents.filter(function(g){return g.relationship!==void 0});if(p.length===0)return;const m=p[0].ID;if(m!==void 0){const g=Gt.Objects.Model[m.toString()];if(g===void 0){console.warn("THREE.FBXLoader: Encountered a unused curve.",f);return}const x={modelName:g.attrName?Kt.sanitizeNodeName(g.attrName):"",ID:g.id,initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1]};yi.traverse(function(E){E.ID===g.id&&(x.transform=E.matrix,E.userData.transformData&&(x.eulerOrder=E.userData.transformData.eulerOrder))}),x.transform||(x.transform=new vt),"PreRotation"in g&&(x.preRotation=g.PreRotation.value),"PostRotation"in g&&(x.postRotation=g.PostRotation.value),o[h]=x}}o[h]&&(o[h][A.attr]=A)}else if(A.curves.morph!==void 0){if(o[h]===void 0){const p=kn.get(f.ID).parents.filter(function(T){return T.relationship!==void 0});if(p.length===0)return;const m=p[0].ID,g=kn.get(m).parents;if(g.length===0)return;const x=g[0].ID,E=kn.get(x).parents;if(E.length===0)return;const S=E[0].ID,y=kn.get(S).parents;if(y.length===0)return;const I=y[0].ID,M=Gt.Objects.Model[I],C={modelName:M.attrName?Kt.sanitizeNodeName(M.attrName):"",morphName:Gt.Objects.Deformer[m].attrName};o[h]=C}o[h][A.attr]=A}}}),i.set(parseInt(a),o))}return i}parseAnimStacks(e){const t=Gt.Objects.AnimationStack,i={};for(const a in t){const o=kn.get(parseInt(a)).children;if(o.length===0)continue;o.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const l=e.get(o[0].ID);i[a]={name:t[a].attrName,layer:l}}return i}addClip(e){let t=[];const i=this;return e.layer.forEach(function(a){t=t.concat(i.generateTracks(a))}),new Uo(e.name,-1,t)}generateTracks(e){const t=[];let i=new he,a=new he;if(e.transform&&e.transform.decompose(i,new Rn,a),i=i.toArray(),a=a.toArray(),e.T!==void 0&&Object.keys(e.T.curves).length>0){const o=this.generateVectorTrack(e.modelName,e.T.curves,i,"position");o!==void 0&&t.push(o)}if(e.R!==void 0&&Object.keys(e.R.curves).length>0){const o=this.generateRotationTrack(e.modelName,e.R.curves,e.preRotation,e.postRotation,e.eulerOrder);o!==void 0&&t.push(o)}if(e.S!==void 0&&Object.keys(e.S.curves).length>0){const o=this.generateVectorTrack(e.modelName,e.S.curves,a,"scale");o!==void 0&&t.push(o)}if(e.DeformPercent!==void 0){const o=this.generateMorphTrack(e);o!==void 0&&t.push(o)}return t}generateVectorTrack(e,t,i,a){const o=this.getTimesForAllAxes(t),l=this.getKeyframeTrackValues(o,t,i);return new ks(e+"."+a,o,l)}generateRotationTrack(e,t,i,a,o){let l,u;if(t.x!==void 0&&t.y!==void 0&&t.z!==void 0){const m=this.interpolateRotations(t.x,t.y,t.z,o);l=m[0],u=m[1]}const f=ff(0);i!==void 0&&(i=i.map(wi.degToRad),i.push(f),i=new zn().fromArray(i),i=new Rn().setFromEuler(i)),a!==void 0&&(a=a.map(wi.degToRad),a.push(f),a=new zn().fromArray(a),a=new Rn().setFromEuler(a).invert());const h=new Rn,A=new zn,p=[];if(!u||!l)return new aa(e+".quaternion",[0],[0]);for(let m=0;m<u.length;m+=3)A.set(u[m],u[m+1],u[m+2],o),h.setFromEuler(A),i!==void 0&&h.premultiply(i),a!==void 0&&h.multiply(a),m>2&&new Rn().fromArray(p,(m-3)/3*4).dot(h)<0&&h.set(-h.x,-h.y,-h.z,-h.w),h.toArray(p,m/3*4);return new aa(e+".quaternion",l,p)}generateMorphTrack(e){const t=e.DeformPercent.curves.morph,i=t.values.map(function(o){return o/100}),a=yi.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new cf(e.modelName+".morphTargetInfluences["+a+"]",t.times,i)}getTimesForAllAxes(e){let t=[];if(e.x!==void 0&&(t=t.concat(e.x.times)),e.y!==void 0&&(t=t.concat(e.y.times)),e.z!==void 0&&(t=t.concat(e.z.times)),t=t.sort(function(i,a){return i-a}),t.length>1){let i=1,a=t[0];for(let o=1;o<t.length;o++){const l=t[o];l!==a&&(t[i]=l,a=l,i++)}t=t.slice(0,i)}return t}getKeyframeTrackValues(e,t,i){const a=i,o=[];let l=-1,u=-1,f=-1;return e.forEach(function(h){if(t.x&&(l=t.x.times.indexOf(h)),t.y&&(u=t.y.times.indexOf(h)),t.z&&(f=t.z.times.indexOf(h)),l!==-1){const A=t.x.values[l];o.push(A),a[0]=A}else o.push(a[0]);if(u!==-1){const A=t.y.values[u];o.push(A),a[1]=A}else o.push(a[1]);if(f!==-1){const A=t.z.values[f];o.push(A),a[2]=A}else o.push(a[2])}),o}interpolateRotations(e,t,i,a){const o=[],l=[];o.push(e.times[0]),l.push(wi.degToRad(e.values[0])),l.push(wi.degToRad(t.values[0])),l.push(wi.degToRad(i.values[0]));for(let u=1;u<e.values.length;u++){const f=[e.values[u-1],t.values[u-1],i.values[u-1]];if(isNaN(f[0])||isNaN(f[1])||isNaN(f[2]))continue;const h=f.map(wi.degToRad),A=[e.values[u],t.values[u],i.values[u]];if(isNaN(A[0])||isNaN(A[1])||isNaN(A[2]))continue;const p=A.map(wi.degToRad),m=[A[0]-f[0],A[1]-f[1],A[2]-f[2]],g=[Math.abs(m[0]),Math.abs(m[1]),Math.abs(m[2])];if(g[0]>=180||g[1]>=180||g[2]>=180){const E=Math.max(...g)/180,S=new zn(...h,a),y=new zn(...p,a),I=new Rn().setFromEuler(S),M=new Rn().setFromEuler(y);I.dot(M)&&M.set(-M.x,-M.y,-M.z,-M.w);const C=e.times[u-1],T=e.times[u]-C,B=new Rn,L=new zn;for(let O=0;O<1;O+=1/E)B.copy(I.clone().slerp(M.clone(),O)),o.push(C+O*T),L.setFromQuaternion(B,a),l.push(L.x),l.push(L.y),l.push(L.z)}else o.push(e.times[u]),l.push(wi.degToRad(e.values[u])),l.push(wi.degToRad(t.values[u])),l.push(wi.degToRad(i.values[u]))}return[o,l]}}class i8{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new AT,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,i=e.split(/[\r\n]+/);return i.forEach(function(a,o){const l=a.match(/^[\s\t]*;/),u=a.match(/^[\s\t]*$/);if(l||u)return;const f=a.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),h=a.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),A=a.match("^\\t{"+(t.currentIndent-1)+"}}");f?t.parseNodeBegin(a,f):h?t.parseNodeProperty(a,h,i[++o]):A?t.popStack():a.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(a)}),this.allNodes}parseNodeBegin(e,t){const i=t[1].trim().replace(/^"/,"").replace(/"$/,""),a=t[2].split(",").map(function(f){return f.trim().replace(/^"/,"").replace(/"$/,"")}),o={name:i},l=this.parseNodeAttr(a),u=this.getCurrentNode();this.currentIndent===0?this.allNodes.add(i,o):i in u?(i==="PoseNode"?u.PoseNode.push(o):u[i].id!==void 0&&(u[i]={},u[i][u[i].id]=u[i]),l.id!==""&&(u[i][l.id]=o)):typeof l.id=="number"?(u[i]={},u[i][l.id]=o):i!=="Properties70"&&(i==="PoseNode"?u[i]=[o]:u[i]=o),typeof l.id=="number"&&(o.id=l.id),l.name!==""&&(o.attrName=l.name),l.type!==""&&(o.attrType=l.type),this.pushStack(o)}parseNodeAttr(e){let t=e[0];e[0]!==""&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let i="",a="";return e.length>1&&(i=e[1].replace(/^(\w+)::/,""),a=e[2]),{id:t,name:i,type:a}}parseNodeProperty(e,t,i){let a=t[1].replace(/^"/,"").replace(/"$/,"").trim(),o=t[2].replace(/^"/,"").replace(/"$/,"").trim();a==="Content"&&o===","&&(o=i.replace(/"/g,"").replace(/,$/,"").trim());const l=this.getCurrentNode();if(l.name==="Properties70"){this.parseNodeSpecialProperty(e,a,o);return}if(a==="C"){const f=o.split(",").slice(1),h=parseInt(f[0]),A=parseInt(f[1]);let p=o.split(",").slice(3);p=p.map(function(m){return m.trim().replace(/^"/,"")}),a="connections",o=[h,A],c8(o,p),l[a]===void 0&&(l[a]=[])}a==="Node"&&(l.id=o),a in l&&Array.isArray(l[a])?l[a].push(o):a!=="a"?l[a]=o:l.a=o,this.setCurrentProp(l,a),a==="a"&&o.slice(-1)!==","&&(l.a=Yg(o))}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,e.slice(-1)!==","&&(t.a=Yg(t.a))}parseNodeSpecialProperty(e,t,i){const a=i.split('",').map(function(A){return A.trim().replace(/^\"/,"").replace(/\s/,"_")}),o=a[0],l=a[1],u=a[2],f=a[3];let h=a[4];switch(l){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":h=parseFloat(h);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":h=Yg(h);break}this.getPrevNode()[o]={type:l,type2:u,flag:f,value:h},this.setCurrentProp(this.getPrevNode(),o)}}class r8{parse(e){const t=new EC(e);t.skip(23);const i=t.getUint32();if(i<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+i);const a=new AT;for(;!this.endOfContent(t);){const o=this.parseNode(t,i);o!==null&&a.add(o.name,o)}return a}endOfContent(e){return e.size()%16===0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const i={},a=t>=7500?e.getUint64():e.getUint32(),o=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const l=e.getUint8(),u=e.getString(l);if(a===0)return null;const f=[];for(let m=0;m<o;m++)f.push(this.parseProperty(e));const h=f.length>0?f[0]:"",A=f.length>1?f[1]:"",p=f.length>2?f[2]:"";for(i.singleProperty=o===1&&e.getOffset()===a;a>e.getOffset();){const m=this.parseNode(e,t);m!==null&&this.parseSubNode(u,i,m)}return i.propertyList=f,typeof h=="number"&&(i.id=h),A!==""&&(i.attrName=A),p!==""&&(i.attrType=p),u!==""&&(i.name=u),i}parseSubNode(e,t,i){if(i.singleProperty===!0){const a=i.propertyList[0];Array.isArray(a)?(t[i.name]=i,i.a=a):t[i.name]=a}else if(e==="Connections"&&i.name==="C"){const a=[];i.propertyList.forEach(function(o,l){l!==0&&a.push(o)}),t.connections===void 0&&(t.connections=[]),t.connections.push(a)}else if(i.name==="Properties70")Object.keys(i).forEach(function(o){t[o]=i[o]});else if(e==="Properties70"&&i.name==="P"){let a=i.propertyList[0],o=i.propertyList[1];const l=i.propertyList[2],u=i.propertyList[3];let f;a.indexOf("Lcl ")===0&&(a=a.replace("Lcl ","Lcl_")),o.indexOf("Lcl ")===0&&(o=o.replace("Lcl ","Lcl_")),o==="Color"||o==="ColorRGB"||o==="Vector"||o==="Vector3D"||o.indexOf("Lcl_")===0?f=[i.propertyList[4],i.propertyList[5],i.propertyList[6]]:f=i.propertyList[4],t[a]={type:o,type2:l,flag:u,value:f}}else t[i.name]===void 0?typeof i.id=="number"?(t[i.name]={},t[i.name][i.id]=i):t[i.name]=i:i.name==="PoseNode"?(Array.isArray(t[i.name])||(t[i.name]=[t[i.name]]),t[i.name].push(i)):t[i.name][i.id]===void 0&&(t[i.name][i.id]=i)}parseProperty(e){const t=e.getString(1);let i;switch(t){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return i=e.getUint32(),e.getArrayBuffer(i);case"S":return i=e.getUint32(),e.getString(i);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const a=e.getUint32(),o=e.getUint32(),l=e.getUint32();if(o===0)switch(t){case"b":case"c":return e.getBooleanArray(a);case"d":return e.getFloat64Array(a);case"f":return e.getFloat32Array(a);case"i":return e.getInt32Array(a);case"l":return e.getInt64Array(a)}const u=GH(new Uint8Array(e.getArrayBuffer(l))),f=new EC(u.buffer);switch(t){case"b":case"c":return f.getBooleanArray(a);case"d":return f.getFloat64Array(a);case"f":return f.getFloat32Array(a);case"i":return f.getInt32Array(a);case"l":return f.getInt64Array(a)}break;default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}}let EC=class{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=t!==void 0?t:!0,this._textDecoder=new TextDecoder}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return(this.getUint8()&1)===1}getBooleanArray(e){const t=[];for(let i=0;i<e;i++)t.push(this.getBoolean());return t}getUint8(){const e=this.dv.getUint8(this.offset);return this.offset+=1,e}getInt16(){const e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}getInt32(){const e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}getInt32Array(e){const t=[];for(let i=0;i<e;i++)t.push(this.getInt32());return t}getUint32(){const e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}getInt64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),t&2147483648?(t=~t&4294967295,e=~e&4294967295,e===4294967295&&(t=t+1&4294967295),e=e+1&4294967295,-(t*4294967296+e)):t*4294967296+e}getInt64Array(e){const t=[];for(let i=0;i<e;i++)t.push(this.getInt64());return t}getUint64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),t*4294967296+e}getFloat32(){const e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}getFloat32Array(e){const t=[];for(let i=0;i<e;i++)t.push(this.getFloat32());return t}getFloat64(){const e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}getFloat64Array(e){const t=[];for(let i=0;i<e;i++)t.push(this.getFloat64());return t}getArrayBuffer(e){const t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}getString(e){const t=this.offset;let i=new Uint8Array(this.dv.buffer,t,e);this.skip(e);const a=i.indexOf(0);return a>=0&&(i=new Uint8Array(this.dv.buffer,t,a)),this._textDecoder.decode(i)}};class AT{add(e,t){this[e]=t}}function a8(n){const e="Kaydara FBX Binary \0";return n.byteLength>=e.length&&e===gT(n,0,e.length)}function s8(n){const e=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let t=0;function i(a){const o=n[a-1];return n=n.slice(t+a),t++,o}for(let a=0;a<e.length;++a)if(i(1)===e[a])return!1;return!0}function bC(n){const e=/FBXVersion: (\d+)/,t=n.match(e);if(t)return parseInt(t[1]);throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function o8(n){return n/46186158e3}const l8=[];function xh(n,e,t,i){let a;switch(i.mappingType){case"ByPolygonVertex":a=n;break;case"ByPolygon":a=e;break;case"ByVertice":a=t;break;case"AllSame":a=i.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+i.mappingType)}i.referenceType==="IndexToDirect"&&(a=i.indices[a]);const o=a*i.dataSize,l=o+i.dataSize;return u8(l8,i.buffer,o,l)}const qg=new zn,zl=new he;function mT(n){const e=new vt,t=new vt,i=new vt,a=new vt,o=new vt,l=new vt,u=new vt,f=new vt,h=new vt,A=new vt,p=new vt,m=new vt,g=n.inheritType?n.inheritType:0;n.translation&&e.setPosition(zl.fromArray(n.translation));const x=ff(0);if(n.preRotation){const j=n.preRotation.map(wi.degToRad);j.push(x),t.makeRotationFromEuler(qg.fromArray(j))}if(n.rotation){const j=n.rotation.map(wi.degToRad);j.push(n.eulerOrder||x),i.makeRotationFromEuler(qg.fromArray(j))}if(n.postRotation){const j=n.postRotation.map(wi.degToRad);j.push(x),a.makeRotationFromEuler(qg.fromArray(j)),a.invert()}n.scale&&o.scale(zl.fromArray(n.scale)),n.scalingOffset&&u.setPosition(zl.fromArray(n.scalingOffset)),n.scalingPivot&&l.setPosition(zl.fromArray(n.scalingPivot)),n.rotationOffset&&f.setPosition(zl.fromArray(n.rotationOffset)),n.rotationPivot&&h.setPosition(zl.fromArray(n.rotationPivot)),n.parentMatrixWorld&&(p.copy(n.parentMatrix),A.copy(n.parentMatrixWorld));const E=t.clone().multiply(i).multiply(a),S=new vt;S.extractRotation(A);const y=new vt;y.copyPosition(A);const I=y.clone().invert().multiply(A),M=S.clone().invert().multiply(I),C=o,T=new vt;if(g===0)T.copy(S).multiply(E).multiply(M).multiply(C);else if(g===1)T.copy(S).multiply(M).multiply(E).multiply(C);else{const V=new vt().scale(new he().setFromMatrixScale(p)).clone().invert(),W=M.clone().multiply(V);T.copy(S).multiply(E).multiply(W).multiply(C)}const B=h.clone().invert(),L=l.clone().invert();let O=e.clone().multiply(f).multiply(h).multiply(t).multiply(i).multiply(a).multiply(B).multiply(u).multiply(l).multiply(o).multiply(L);const R=new vt().copyPosition(O),F=A.clone().multiply(R);return m.copyPosition(F),O=m.clone().multiply(T),O.premultiply(A.invert()),O}function ff(n){n=n||0;const e=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return n===6?(console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),e[0]):e[n]}function Yg(n){return n.split(",").map(function(t){return parseFloat(t)})}function gT(n,e,t){return e===void 0&&(e=0),t===void 0&&(t=n.byteLength),new TextDecoder().decode(new Uint8Array(n,e,t))}function c8(n,e){for(let t=0,i=n.length,a=e.length;t<a;t++,i++)n[i]=e[t]}function u8(n,e,t,i){for(let a=t,o=0;a<i;a++,o++)n[o]=e[a];return n}var Kg={},Mu={},Iu={},SC;function f8(){if(SC)return Iu;SC=1,Object.defineProperty(Iu,"__esModule",{value:!0}),Iu.BinaryReader=void 0;class n{constructor(t){this.offset=0,this.binary=t}readUint8(){return this.binary[this.offset++].valueOf()}readUint8AsString(){return String.fromCharCode(this.binary[this.offset++].valueOf())}readUint8AsBool(){return this.binary[this.offset++].valueOf()!==0}readUint16(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,2).getUint16(0,!0);return this.offset+=2,t}readUint32(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,4).getUint32(0,!0);return this.offset+=4,t}readUint64(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,8).getBigUint64(0,!0);return this.offset+=8,t}readInt8(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,1).getInt8(0);return this.offset+=1,t}readInt16(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,2).getInt16(0,!0);return this.offset+=2,t}readInt32(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,4).getInt32(0,!0);return this.offset+=4,t}readInt64(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,8).getBigInt64(0,!0);return this.offset+=8,t}readFloat32(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,4).getFloat32(0,!0);return this.offset+=4,t}readFloat64(){const t=new DataView(this.binary.buffer,this.binary.byteOffset+this.offset,8).getFloat64(0,!0);return this.offset+=8,t}readUint8Array(t){return this.binary.subarray(this.offset,this.offset+=t)}readArrayAsString(t){return String.fromCharCode.apply(null,this.binary.subarray(this.offset,this.offset+=t))}}return Iu.BinaryReader=n,Iu}var Dr={},xo={},Nr={},_o={},CC;function d8(){if(CC)return _o;CC=1;const n=4,e=0,t=1,i=2;function a(z){let pe=z.length;for(;--pe>=0;)z[pe]=0}const o=0,l=1,u=2,f=3,h=258,A=29,p=256,m=p+1+A,g=30,x=19,E=2*m+1,S=15,y=16,I=7,M=256,C=16,T=17,B=18,L=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),O=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),R=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),F=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),j=512,V=new Array((m+2)*2);a(V);const W=new Array(g*2);a(W);const te=new Array(j);a(te);const ne=new Array(h-f+1);a(ne);const k=new Array(A);a(k);const X=new Array(g);a(X);function Y(z,pe,Ie,ze,Ce){this.static_tree=z,this.extra_bits=pe,this.extra_base=Ie,this.elems=ze,this.max_length=Ce,this.has_stree=z&&z.length}let ee,q,Q;function re(z,pe){this.dyn_tree=z,this.max_code=0,this.stat_desc=pe}const ue=z=>z<256?te[z]:te[256+(z>>>7)],xe=(z,pe)=>{z.pending_buf[z.pending++]=pe&255,z.pending_buf[z.pending++]=pe>>>8&255},Me=(z,pe,Ie)=>{z.bi_valid>y-Ie?(z.bi_buf|=pe<<z.bi_valid&65535,xe(z,z.bi_buf),z.bi_buf=pe>>y-z.bi_valid,z.bi_valid+=Ie-y):(z.bi_buf|=pe<<z.bi_valid&65535,z.bi_valid+=Ie)},se=(z,pe,Ie)=>{Me(z,Ie[pe*2],Ie[pe*2+1])},Ae=(z,pe)=>{let Ie=0;do Ie|=z&1,z>>>=1,Ie<<=1;while(--pe>0);return Ie>>>1},Qe=z=>{z.bi_valid===16?(xe(z,z.bi_buf),z.bi_buf=0,z.bi_valid=0):z.bi_valid>=8&&(z.pending_buf[z.pending++]=z.bi_buf&255,z.bi_buf>>=8,z.bi_valid-=8)},We=(z,pe)=>{const Ie=pe.dyn_tree,ze=pe.max_code,Ce=pe.stat_desc.static_tree,De=pe.stat_desc.has_stree,$=pe.stat_desc.extra_bits,de=pe.stat_desc.extra_base,U=pe.stat_desc.max_length;let Fe,ie,be,Oe,Re,ke,Z=0;for(Oe=0;Oe<=S;Oe++)z.bl_count[Oe]=0;for(Ie[z.heap[z.heap_max]*2+1]=0,Fe=z.heap_max+1;Fe<E;Fe++)ie=z.heap[Fe],Oe=Ie[Ie[ie*2+1]*2+1]+1,Oe>U&&(Oe=U,Z++),Ie[ie*2+1]=Oe,!(ie>ze)&&(z.bl_count[Oe]++,Re=0,ie>=de&&(Re=$[ie-de]),ke=Ie[ie*2],z.opt_len+=ke*(Oe+Re),De&&(z.static_len+=ke*(Ce[ie*2+1]+Re)));if(Z!==0){do{for(Oe=U-1;z.bl_count[Oe]===0;)Oe--;z.bl_count[Oe]--,z.bl_count[Oe+1]+=2,z.bl_count[U]--,Z-=2}while(Z>0);for(Oe=U;Oe!==0;Oe--)for(ie=z.bl_count[Oe];ie!==0;)be=z.heap[--Fe],!(be>ze)&&(Ie[be*2+1]!==Oe&&(z.opt_len+=(Oe-Ie[be*2+1])*Ie[be*2],Ie[be*2+1]=Oe),ie--)}},qe=(z,pe,Ie)=>{const ze=new Array(S+1);let Ce=0,De,$;for(De=1;De<=S;De++)Ce=Ce+Ie[De-1]<<1,ze[De]=Ce;for($=0;$<=pe;$++){let de=z[$*2+1];de!==0&&(z[$*2]=Ae(ze[de]++,de))}},Je=()=>{let z,pe,Ie,ze,Ce;const De=new Array(S+1);for(Ie=0,ze=0;ze<A-1;ze++)for(k[ze]=Ie,z=0;z<1<<L[ze];z++)ne[Ie++]=ze;for(ne[Ie-1]=ze,Ce=0,ze=0;ze<16;ze++)for(X[ze]=Ce,z=0;z<1<<O[ze];z++)te[Ce++]=ze;for(Ce>>=7;ze<g;ze++)for(X[ze]=Ce<<7,z=0;z<1<<O[ze]-7;z++)te[256+Ce++]=ze;for(pe=0;pe<=S;pe++)De[pe]=0;for(z=0;z<=143;)V[z*2+1]=8,z++,De[8]++;for(;z<=255;)V[z*2+1]=9,z++,De[9]++;for(;z<=279;)V[z*2+1]=7,z++,De[7]++;for(;z<=287;)V[z*2+1]=8,z++,De[8]++;for(qe(V,m+1,De),z=0;z<g;z++)W[z*2+1]=5,W[z*2]=Ae(z,5);ee=new Y(V,L,p+1,m,S),q=new Y(W,O,0,g,S),Q=new Y(new Array(0),R,0,x,I)},pt=z=>{let pe;for(pe=0;pe<m;pe++)z.dyn_ltree[pe*2]=0;for(pe=0;pe<g;pe++)z.dyn_dtree[pe*2]=0;for(pe=0;pe<x;pe++)z.bl_tree[pe*2]=0;z.dyn_ltree[M*2]=1,z.opt_len=z.static_len=0,z.sym_next=z.matches=0},ct=z=>{z.bi_valid>8?xe(z,z.bi_buf):z.bi_valid>0&&(z.pending_buf[z.pending++]=z.bi_buf),z.bi_buf=0,z.bi_valid=0},mt=(z,pe,Ie,ze)=>{const Ce=pe*2,De=Ie*2;return z[Ce]<z[De]||z[Ce]===z[De]&&ze[pe]<=ze[Ie]},Rt=(z,pe,Ie)=>{const ze=z.heap[Ie];let Ce=Ie<<1;for(;Ce<=z.heap_len&&(Ce<z.heap_len&&mt(pe,z.heap[Ce+1],z.heap[Ce],z.depth)&&Ce++,!mt(pe,ze,z.heap[Ce],z.depth));)z.heap[Ie]=z.heap[Ce],Ie=Ce,Ce<<=1;z.heap[Ie]=ze},Et=(z,pe,Ie)=>{let ze,Ce,De=0,$,de;if(z.sym_next!==0)do ze=z.pending_buf[z.sym_buf+De++]&255,ze+=(z.pending_buf[z.sym_buf+De++]&255)<<8,Ce=z.pending_buf[z.sym_buf+De++],ze===0?se(z,Ce,pe):($=ne[Ce],se(z,$+p+1,pe),de=L[$],de!==0&&(Ce-=k[$],Me(z,Ce,de)),ze--,$=ue(ze),se(z,$,Ie),de=O[$],de!==0&&(ze-=X[$],Me(z,ze,de)));while(De<z.sym_next);se(z,M,pe)},Pt=(z,pe)=>{const Ie=pe.dyn_tree,ze=pe.stat_desc.static_tree,Ce=pe.stat_desc.has_stree,De=pe.stat_desc.elems;let $,de,U=-1,Fe;for(z.heap_len=0,z.heap_max=E,$=0;$<De;$++)Ie[$*2]!==0?(z.heap[++z.heap_len]=U=$,z.depth[$]=0):Ie[$*2+1]=0;for(;z.heap_len<2;)Fe=z.heap[++z.heap_len]=U<2?++U:0,Ie[Fe*2]=1,z.depth[Fe]=0,z.opt_len--,Ce&&(z.static_len-=ze[Fe*2+1]);for(pe.max_code=U,$=z.heap_len>>1;$>=1;$--)Rt(z,Ie,$);Fe=De;do $=z.heap[1],z.heap[1]=z.heap[z.heap_len--],Rt(z,Ie,1),de=z.heap[1],z.heap[--z.heap_max]=$,z.heap[--z.heap_max]=de,Ie[Fe*2]=Ie[$*2]+Ie[de*2],z.depth[Fe]=(z.depth[$]>=z.depth[de]?z.depth[$]:z.depth[de])+1,Ie[$*2+1]=Ie[de*2+1]=Fe,z.heap[1]=Fe++,Rt(z,Ie,1);while(z.heap_len>=2);z.heap[--z.heap_max]=z.heap[1],We(z,pe),qe(Ie,U,z.bl_count)},le=(z,pe,Ie)=>{let ze,Ce=-1,De,$=pe[1],de=0,U=7,Fe=4;for($===0&&(U=138,Fe=3),pe[(Ie+1)*2+1]=65535,ze=0;ze<=Ie;ze++)De=$,$=pe[(ze+1)*2+1],!(++de<U&&De===$)&&(de<Fe?z.bl_tree[De*2]+=de:De!==0?(De!==Ce&&z.bl_tree[De*2]++,z.bl_tree[C*2]++):de<=10?z.bl_tree[T*2]++:z.bl_tree[B*2]++,de=0,Ce=De,$===0?(U=138,Fe=3):De===$?(U=6,Fe=3):(U=7,Fe=4))},wt=(z,pe,Ie)=>{let ze,Ce=-1,De,$=pe[1],de=0,U=7,Fe=4;for($===0&&(U=138,Fe=3),ze=0;ze<=Ie;ze++)if(De=$,$=pe[(ze+1)*2+1],!(++de<U&&De===$)){if(de<Fe)do se(z,De,z.bl_tree);while(--de!==0);else De!==0?(De!==Ce&&(se(z,De,z.bl_tree),de--),se(z,C,z.bl_tree),Me(z,de-3,2)):de<=10?(se(z,T,z.bl_tree),Me(z,de-3,3)):(se(z,B,z.bl_tree),Me(z,de-11,7));de=0,Ce=De,$===0?(U=138,Fe=3):De===$?(U=6,Fe=3):(U=7,Fe=4)}},Mt=z=>{let pe;for(le(z,z.dyn_ltree,z.l_desc.max_code),le(z,z.dyn_dtree,z.d_desc.max_code),Pt(z,z.bl_desc),pe=x-1;pe>=3&&z.bl_tree[F[pe]*2+1]===0;pe--);return z.opt_len+=3*(pe+1)+5+5+4,pe},Xt=(z,pe,Ie,ze)=>{let Ce;for(Me(z,pe-257,5),Me(z,Ie-1,5),Me(z,ze-4,4),Ce=0;Ce<ze;Ce++)Me(z,z.bl_tree[F[Ce]*2+1],3);wt(z,z.dyn_ltree,pe-1),wt(z,z.dyn_dtree,Ie-1)},Ye=z=>{let pe=4093624447,Ie;for(Ie=0;Ie<=31;Ie++,pe>>>=1)if(pe&1&&z.dyn_ltree[Ie*2]!==0)return e;if(z.dyn_ltree[18]!==0||z.dyn_ltree[20]!==0||z.dyn_ltree[26]!==0)return t;for(Ie=32;Ie<p;Ie++)if(z.dyn_ltree[Ie*2]!==0)return t;return e};let K=!1;const P=z=>{K||(Je(),K=!0),z.l_desc=new re(z.dyn_ltree,ee),z.d_desc=new re(z.dyn_dtree,q),z.bl_desc=new re(z.bl_tree,Q),z.bi_buf=0,z.bi_valid=0,pt(z)},oe=(z,pe,Ie,ze)=>{Me(z,(o<<1)+(ze?1:0),3),ct(z),xe(z,Ie),xe(z,~Ie),Ie&&z.pending_buf.set(z.window.subarray(pe,pe+Ie),z.pending),z.pending+=Ie},Pe=z=>{Me(z,l<<1,3),se(z,M,V),Qe(z)},He=(z,pe,Ie,ze)=>{let Ce,De,$=0;z.level>0?(z.strm.data_type===i&&(z.strm.data_type=Ye(z)),Pt(z,z.l_desc),Pt(z,z.d_desc),$=Mt(z),Ce=z.opt_len+3+7>>>3,De=z.static_len+3+7>>>3,De<=Ce&&(Ce=De)):Ce=De=Ie+5,Ie+4<=Ce&&pe!==-1?oe(z,pe,Ie,ze):z.strategy===n||De===Ce?(Me(z,(l<<1)+(ze?1:0),3),Et(z,V,W)):(Me(z,(u<<1)+(ze?1:0),3),Xt(z,z.l_desc.max_code+1,z.d_desc.max_code+1,$+1),Et(z,z.dyn_ltree,z.dyn_dtree)),pt(z),ze&&ct(z)},Ne=(z,pe,Ie)=>(z.pending_buf[z.sym_buf+z.sym_next++]=pe,z.pending_buf[z.sym_buf+z.sym_next++]=pe>>8,z.pending_buf[z.sym_buf+z.sym_next++]=Ie,pe===0?z.dyn_ltree[Ie*2]++:(z.matches++,pe--,z.dyn_ltree[(ne[Ie]+p+1)*2]++,z.dyn_dtree[ue(pe)*2]++),z.sym_next===z.sym_end);return _o._tr_init=P,_o._tr_stored_block=oe,_o._tr_flush_block=He,_o._tr_tally=Ne,_o._tr_align=Pe,_o}var Jg,wC;function vT(){return wC||(wC=1,Jg=(e,t,i,a)=>{let o=e&65535|0,l=e>>>16&65535|0,u=0;for(;i!==0;){u=i>2e3?2e3:i,i-=u;do o=o+t[a++]|0,l=l+o|0;while(--u);o%=65521,l%=65521}return o|l<<16|0}),Jg}var Zg,MC;function xT(){if(MC)return Zg;MC=1;const n=()=>{let i,a=[];for(var o=0;o<256;o++){i=o;for(var l=0;l<8;l++)i=i&1?3988292384^i>>>1:i>>>1;a[o]=i}return a},e=new Uint32Array(n());return Zg=(i,a,o,l)=>{const u=e,f=l+o;i^=-1;for(let h=l;h<f;h++)i=i>>>8^u[(i^a[h])&255];return i^-1},Zg}var $g,IC;function yx(){return IC||(IC=1,$g={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}),$g}var e0,TC;function Fo(){return TC||(TC=1,e0={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}),e0}var BC;function h8(){if(BC)return Nr;BC=1;const{_tr_init:n,_tr_stored_block:e,_tr_flush_block:t,_tr_tally:i,_tr_align:a}=d8(),o=vT(),l=xT(),u=yx(),{Z_NO_FLUSH:f,Z_PARTIAL_FLUSH:h,Z_FULL_FLUSH:A,Z_FINISH:p,Z_BLOCK:m,Z_OK:g,Z_STREAM_END:x,Z_STREAM_ERROR:E,Z_DATA_ERROR:S,Z_BUF_ERROR:y,Z_DEFAULT_COMPRESSION:I,Z_FILTERED:M,Z_HUFFMAN_ONLY:C,Z_RLE:T,Z_FIXED:B,Z_DEFAULT_STRATEGY:L,Z_UNKNOWN:O,Z_DEFLATED:R}=Fo(),F=9,j=15,V=8,ne=256+1+29,k=30,X=19,Y=2*ne+1,ee=15,q=3,Q=258,re=Q+q+1,ue=32,xe=42,Me=57,se=69,Ae=73,Qe=91,We=103,qe=113,Je=666,pt=1,ct=2,mt=3,Rt=4,Et=3,Pt=(w,_e)=>(w.msg=u[_e],_e),le=w=>w*2-(w>4?9:0),wt=w=>{let _e=w.length;for(;--_e>=0;)w[_e]=0},Mt=w=>{let _e,J,ye,ve=w.w_size;_e=w.hash_size,ye=_e;do J=w.head[--ye],w.head[ye]=J>=ve?J-ve:0;while(--_e);_e=ve,ye=_e;do J=w.prev[--ye],w.prev[ye]=J>=ve?J-ve:0;while(--_e)};let Ye=(w,_e,J)=>(_e<<w.hash_shift^J)&w.hash_mask;const K=w=>{const _e=w.state;let J=_e.pending;J>w.avail_out&&(J=w.avail_out),J!==0&&(w.output.set(_e.pending_buf.subarray(_e.pending_out,_e.pending_out+J),w.next_out),w.next_out+=J,_e.pending_out+=J,w.total_out+=J,w.avail_out-=J,_e.pending-=J,_e.pending===0&&(_e.pending_out=0))},P=(w,_e)=>{t(w,w.block_start>=0?w.block_start:-1,w.strstart-w.block_start,_e),w.block_start=w.strstart,K(w.strm)},oe=(w,_e)=>{w.pending_buf[w.pending++]=_e},Pe=(w,_e)=>{w.pending_buf[w.pending++]=_e>>>8&255,w.pending_buf[w.pending++]=_e&255},He=(w,_e,J,ye)=>{let ve=w.avail_in;return ve>ye&&(ve=ye),ve===0?0:(w.avail_in-=ve,_e.set(w.input.subarray(w.next_in,w.next_in+ve),J),w.state.wrap===1?w.adler=o(w.adler,_e,ve,J):w.state.wrap===2&&(w.adler=l(w.adler,_e,ve,J)),w.next_in+=ve,w.total_in+=ve,ve)},Ne=(w,_e)=>{let J=w.max_chain_length,ye=w.strstart,ve,Xe,ut=w.prev_length,Ze=w.nice_match;const Pn=w.strstart>w.w_size-re?w.strstart-(w.w_size-re):0,Lt=w.window,$t=w.w_mask,en=w.prev,jt=w.strstart+Q;let In=Lt[ye+ut-1],jn=Lt[ye+ut];w.prev_length>=w.good_match&&(J>>=2),Ze>w.lookahead&&(Ze=w.lookahead);do if(ve=_e,!(Lt[ve+ut]!==jn||Lt[ve+ut-1]!==In||Lt[ve]!==Lt[ye]||Lt[++ve]!==Lt[ye+1])){ye+=2,ve++;do;while(Lt[++ye]===Lt[++ve]&&Lt[++ye]===Lt[++ve]&&Lt[++ye]===Lt[++ve]&&Lt[++ye]===Lt[++ve]&&Lt[++ye]===Lt[++ve]&&Lt[++ye]===Lt[++ve]&&Lt[++ye]===Lt[++ve]&&Lt[++ye]===Lt[++ve]&&ye<jt);if(Xe=Q-(jt-ye),ye=jt-Q,Xe>ut){if(w.match_start=_e,ut=Xe,Xe>=Ze)break;In=Lt[ye+ut-1],jn=Lt[ye+ut]}}while((_e=en[_e&$t])>Pn&&--J!==0);return ut<=w.lookahead?ut:w.lookahead},z=w=>{const _e=w.w_size;let J,ye,ve;do{if(ye=w.window_size-w.lookahead-w.strstart,w.strstart>=_e+(_e-re)&&(w.window.set(w.window.subarray(_e,_e+_e-ye),0),w.match_start-=_e,w.strstart-=_e,w.block_start-=_e,w.insert>w.strstart&&(w.insert=w.strstart),Mt(w),ye+=_e),w.strm.avail_in===0)break;if(J=He(w.strm,w.window,w.strstart+w.lookahead,ye),w.lookahead+=J,w.lookahead+w.insert>=q)for(ve=w.strstart-w.insert,w.ins_h=w.window[ve],w.ins_h=Ye(w,w.ins_h,w.window[ve+1]);w.insert&&(w.ins_h=Ye(w,w.ins_h,w.window[ve+q-1]),w.prev[ve&w.w_mask]=w.head[w.ins_h],w.head[w.ins_h]=ve,ve++,w.insert--,!(w.lookahead+w.insert<q)););}while(w.lookahead<re&&w.strm.avail_in!==0)},pe=(w,_e)=>{let J=w.pending_buf_size-5>w.w_size?w.w_size:w.pending_buf_size-5,ye,ve,Xe,ut=0,Ze=w.strm.avail_in;do{if(ye=65535,Xe=w.bi_valid+42>>3,w.strm.avail_out<Xe||(Xe=w.strm.avail_out-Xe,ve=w.strstart-w.block_start,ye>ve+w.strm.avail_in&&(ye=ve+w.strm.avail_in),ye>Xe&&(ye=Xe),ye<J&&(ye===0&&_e!==p||_e===f||ye!==ve+w.strm.avail_in)))break;ut=_e===p&&ye===ve+w.strm.avail_in?1:0,e(w,0,0,ut),w.pending_buf[w.pending-4]=ye,w.pending_buf[w.pending-3]=ye>>8,w.pending_buf[w.pending-2]=~ye,w.pending_buf[w.pending-1]=~ye>>8,K(w.strm),ve&&(ve>ye&&(ve=ye),w.strm.output.set(w.window.subarray(w.block_start,w.block_start+ve),w.strm.next_out),w.strm.next_out+=ve,w.strm.avail_out-=ve,w.strm.total_out+=ve,w.block_start+=ve,ye-=ve),ye&&(He(w.strm,w.strm.output,w.strm.next_out,ye),w.strm.next_out+=ye,w.strm.avail_out-=ye,w.strm.total_out+=ye)}while(ut===0);return Ze-=w.strm.avail_in,Ze&&(Ze>=w.w_size?(w.matches=2,w.window.set(w.strm.input.subarray(w.strm.next_in-w.w_size,w.strm.next_in),0),w.strstart=w.w_size,w.insert=w.strstart):(w.window_size-w.strstart<=Ze&&(w.strstart-=w.w_size,w.window.set(w.window.subarray(w.w_size,w.w_size+w.strstart),0),w.matches<2&&w.matches++,w.insert>w.strstart&&(w.insert=w.strstart)),w.window.set(w.strm.input.subarray(w.strm.next_in-Ze,w.strm.next_in),w.strstart),w.strstart+=Ze,w.insert+=Ze>w.w_size-w.insert?w.w_size-w.insert:Ze),w.block_start=w.strstart),w.high_water<w.strstart&&(w.high_water=w.strstart),ut?Rt:_e!==f&&_e!==p&&w.strm.avail_in===0&&w.strstart===w.block_start?ct:(Xe=w.window_size-w.strstart,w.strm.avail_in>Xe&&w.block_start>=w.w_size&&(w.block_start-=w.w_size,w.strstart-=w.w_size,w.window.set(w.window.subarray(w.w_size,w.w_size+w.strstart),0),w.matches<2&&w.matches++,Xe+=w.w_size,w.insert>w.strstart&&(w.insert=w.strstart)),Xe>w.strm.avail_in&&(Xe=w.strm.avail_in),Xe&&(He(w.strm,w.window,w.strstart,Xe),w.strstart+=Xe,w.insert+=Xe>w.w_size-w.insert?w.w_size-w.insert:Xe),w.high_water<w.strstart&&(w.high_water=w.strstart),Xe=w.bi_valid+42>>3,Xe=w.pending_buf_size-Xe>65535?65535:w.pending_buf_size-Xe,J=Xe>w.w_size?w.w_size:Xe,ve=w.strstart-w.block_start,(ve>=J||(ve||_e===p)&&_e!==f&&w.strm.avail_in===0&&ve<=Xe)&&(ye=ve>Xe?Xe:ve,ut=_e===p&&w.strm.avail_in===0&&ye===ve?1:0,e(w,w.block_start,ye,ut),w.block_start+=ye,K(w.strm)),ut?mt:pt)},Ie=(w,_e)=>{let J,ye;for(;;){if(w.lookahead<re){if(z(w),w.lookahead<re&&_e===f)return pt;if(w.lookahead===0)break}if(J=0,w.lookahead>=q&&(w.ins_h=Ye(w,w.ins_h,w.window[w.strstart+q-1]),J=w.prev[w.strstart&w.w_mask]=w.head[w.ins_h],w.head[w.ins_h]=w.strstart),J!==0&&w.strstart-J<=w.w_size-re&&(w.match_length=Ne(w,J)),w.match_length>=q)if(ye=i(w,w.strstart-w.match_start,w.match_length-q),w.lookahead-=w.match_length,w.match_length<=w.max_lazy_match&&w.lookahead>=q){w.match_length--;do w.strstart++,w.ins_h=Ye(w,w.ins_h,w.window[w.strstart+q-1]),J=w.prev[w.strstart&w.w_mask]=w.head[w.ins_h],w.head[w.ins_h]=w.strstart;while(--w.match_length!==0);w.strstart++}else w.strstart+=w.match_length,w.match_length=0,w.ins_h=w.window[w.strstart],w.ins_h=Ye(w,w.ins_h,w.window[w.strstart+1]);else ye=i(w,0,w.window[w.strstart]),w.lookahead--,w.strstart++;if(ye&&(P(w,!1),w.strm.avail_out===0))return pt}return w.insert=w.strstart<q-1?w.strstart:q-1,_e===p?(P(w,!0),w.strm.avail_out===0?mt:Rt):w.sym_next&&(P(w,!1),w.strm.avail_out===0)?pt:ct},ze=(w,_e)=>{let J,ye,ve;for(;;){if(w.lookahead<re){if(z(w),w.lookahead<re&&_e===f)return pt;if(w.lookahead===0)break}if(J=0,w.lookahead>=q&&(w.ins_h=Ye(w,w.ins_h,w.window[w.strstart+q-1]),J=w.prev[w.strstart&w.w_mask]=w.head[w.ins_h],w.head[w.ins_h]=w.strstart),w.prev_length=w.match_length,w.prev_match=w.match_start,w.match_length=q-1,J!==0&&w.prev_length<w.max_lazy_match&&w.strstart-J<=w.w_size-re&&(w.match_length=Ne(w,J),w.match_length<=5&&(w.strategy===M||w.match_length===q&&w.strstart-w.match_start>4096)&&(w.match_length=q-1)),w.prev_length>=q&&w.match_length<=w.prev_length){ve=w.strstart+w.lookahead-q,ye=i(w,w.strstart-1-w.prev_match,w.prev_length-q),w.lookahead-=w.prev_length-1,w.prev_length-=2;do++w.strstart<=ve&&(w.ins_h=Ye(w,w.ins_h,w.window[w.strstart+q-1]),J=w.prev[w.strstart&w.w_mask]=w.head[w.ins_h],w.head[w.ins_h]=w.strstart);while(--w.prev_length!==0);if(w.match_available=0,w.match_length=q-1,w.strstart++,ye&&(P(w,!1),w.strm.avail_out===0))return pt}else if(w.match_available){if(ye=i(w,0,w.window[w.strstart-1]),ye&&P(w,!1),w.strstart++,w.lookahead--,w.strm.avail_out===0)return pt}else w.match_available=1,w.strstart++,w.lookahead--}return w.match_available&&(ye=i(w,0,w.window[w.strstart-1]),w.match_available=0),w.insert=w.strstart<q-1?w.strstart:q-1,_e===p?(P(w,!0),w.strm.avail_out===0?mt:Rt):w.sym_next&&(P(w,!1),w.strm.avail_out===0)?pt:ct},Ce=(w,_e)=>{let J,ye,ve,Xe;const ut=w.window;for(;;){if(w.lookahead<=Q){if(z(w),w.lookahead<=Q&&_e===f)return pt;if(w.lookahead===0)break}if(w.match_length=0,w.lookahead>=q&&w.strstart>0&&(ve=w.strstart-1,ye=ut[ve],ye===ut[++ve]&&ye===ut[++ve]&&ye===ut[++ve])){Xe=w.strstart+Q;do;while(ye===ut[++ve]&&ye===ut[++ve]&&ye===ut[++ve]&&ye===ut[++ve]&&ye===ut[++ve]&&ye===ut[++ve]&&ye===ut[++ve]&&ye===ut[++ve]&&ve<Xe);w.match_length=Q-(Xe-ve),w.match_length>w.lookahead&&(w.match_length=w.lookahead)}if(w.match_length>=q?(J=i(w,1,w.match_length-q),w.lookahead-=w.match_length,w.strstart+=w.match_length,w.match_length=0):(J=i(w,0,w.window[w.strstart]),w.lookahead--,w.strstart++),J&&(P(w,!1),w.strm.avail_out===0))return pt}return w.insert=0,_e===p?(P(w,!0),w.strm.avail_out===0?mt:Rt):w.sym_next&&(P(w,!1),w.strm.avail_out===0)?pt:ct},De=(w,_e)=>{let J;for(;;){if(w.lookahead===0&&(z(w),w.lookahead===0)){if(_e===f)return pt;break}if(w.match_length=0,J=i(w,0,w.window[w.strstart]),w.lookahead--,w.strstart++,J&&(P(w,!1),w.strm.avail_out===0))return pt}return w.insert=0,_e===p?(P(w,!0),w.strm.avail_out===0?mt:Rt):w.sym_next&&(P(w,!1),w.strm.avail_out===0)?pt:ct};function $(w,_e,J,ye,ve){this.good_length=w,this.max_lazy=_e,this.nice_length=J,this.max_chain=ye,this.func=ve}const de=[new $(0,0,0,0,pe),new $(4,4,8,4,Ie),new $(4,5,16,8,Ie),new $(4,6,32,32,Ie),new $(4,4,16,16,ze),new $(8,16,32,32,ze),new $(8,16,128,128,ze),new $(8,32,128,256,ze),new $(32,128,258,1024,ze),new $(32,258,258,4096,ze)],U=w=>{w.window_size=2*w.w_size,wt(w.head),w.max_lazy_match=de[w.level].max_lazy,w.good_match=de[w.level].good_length,w.nice_match=de[w.level].nice_length,w.max_chain_length=de[w.level].max_chain,w.strstart=0,w.block_start=0,w.lookahead=0,w.insert=0,w.match_length=w.prev_length=q-1,w.match_available=0,w.ins_h=0};function Fe(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=R,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(Y*2),this.dyn_dtree=new Uint16Array((2*k+1)*2),this.bl_tree=new Uint16Array((2*X+1)*2),wt(this.dyn_ltree),wt(this.dyn_dtree),wt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(ee+1),this.heap=new Uint16Array(2*ne+1),wt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*ne+1),wt(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const ie=w=>{if(!w)return 1;const _e=w.state;return!_e||_e.strm!==w||_e.status!==xe&&_e.status!==Me&&_e.status!==se&&_e.status!==Ae&&_e.status!==Qe&&_e.status!==We&&_e.status!==qe&&_e.status!==Je?1:0},be=w=>{if(ie(w))return Pt(w,E);w.total_in=w.total_out=0,w.data_type=O;const _e=w.state;return _e.pending=0,_e.pending_out=0,_e.wrap<0&&(_e.wrap=-_e.wrap),_e.status=_e.wrap===2?Me:_e.wrap?xe:qe,w.adler=_e.wrap===2?0:1,_e.last_flush=-2,n(_e),g},Oe=w=>{const _e=be(w);return _e===g&&U(w.state),_e},Re=(w,_e)=>ie(w)||w.state.wrap!==2?E:(w.state.gzhead=_e,g),ke=(w,_e,J,ye,ve,Xe)=>{if(!w)return E;let ut=1;if(_e===I&&(_e=6),ye<0?(ut=0,ye=-ye):ye>15&&(ut=2,ye-=16),ve<1||ve>F||J!==R||ye<8||ye>15||_e<0||_e>9||Xe<0||Xe>B||ye===8&&ut!==1)return Pt(w,E);ye===8&&(ye=9);const Ze=new Fe;return w.state=Ze,Ze.strm=w,Ze.status=xe,Ze.wrap=ut,Ze.gzhead=null,Ze.w_bits=ye,Ze.w_size=1<<Ze.w_bits,Ze.w_mask=Ze.w_size-1,Ze.hash_bits=ve+7,Ze.hash_size=1<<Ze.hash_bits,Ze.hash_mask=Ze.hash_size-1,Ze.hash_shift=~~((Ze.hash_bits+q-1)/q),Ze.window=new Uint8Array(Ze.w_size*2),Ze.head=new Uint16Array(Ze.hash_size),Ze.prev=new Uint16Array(Ze.w_size),Ze.lit_bufsize=1<<ve+6,Ze.pending_buf_size=Ze.lit_bufsize*4,Ze.pending_buf=new Uint8Array(Ze.pending_buf_size),Ze.sym_buf=Ze.lit_bufsize,Ze.sym_end=(Ze.lit_bufsize-1)*3,Ze.level=_e,Ze.strategy=Xe,Ze.method=J,Oe(w)},Z=(w,_e)=>ke(w,_e,R,j,V,L),ce=(w,_e)=>{if(ie(w)||_e>m||_e<0)return w?Pt(w,E):E;const J=w.state;if(!w.output||w.avail_in!==0&&!w.input||J.status===Je&&_e!==p)return Pt(w,w.avail_out===0?y:E);const ye=J.last_flush;if(J.last_flush=_e,J.pending!==0){if(K(w),w.avail_out===0)return J.last_flush=-1,g}else if(w.avail_in===0&&le(_e)<=le(ye)&&_e!==p)return Pt(w,y);if(J.status===Je&&w.avail_in!==0)return Pt(w,y);if(J.status===xe&&J.wrap===0&&(J.status=qe),J.status===xe){let ve=R+(J.w_bits-8<<4)<<8,Xe=-1;if(J.strategy>=C||J.level<2?Xe=0:J.level<6?Xe=1:J.level===6?Xe=2:Xe=3,ve|=Xe<<6,J.strstart!==0&&(ve|=ue),ve+=31-ve%31,Pe(J,ve),J.strstart!==0&&(Pe(J,w.adler>>>16),Pe(J,w.adler&65535)),w.adler=1,J.status=qe,K(w),J.pending!==0)return J.last_flush=-1,g}if(J.status===Me){if(w.adler=0,oe(J,31),oe(J,139),oe(J,8),J.gzhead)oe(J,(J.gzhead.text?1:0)+(J.gzhead.hcrc?2:0)+(J.gzhead.extra?4:0)+(J.gzhead.name?8:0)+(J.gzhead.comment?16:0)),oe(J,J.gzhead.time&255),oe(J,J.gzhead.time>>8&255),oe(J,J.gzhead.time>>16&255),oe(J,J.gzhead.time>>24&255),oe(J,J.level===9?2:J.strategy>=C||J.level<2?4:0),oe(J,J.gzhead.os&255),J.gzhead.extra&&J.gzhead.extra.length&&(oe(J,J.gzhead.extra.length&255),oe(J,J.gzhead.extra.length>>8&255)),J.gzhead.hcrc&&(w.adler=l(w.adler,J.pending_buf,J.pending,0)),J.gzindex=0,J.status=se;else if(oe(J,0),oe(J,0),oe(J,0),oe(J,0),oe(J,0),oe(J,J.level===9?2:J.strategy>=C||J.level<2?4:0),oe(J,Et),J.status=qe,K(w),J.pending!==0)return J.last_flush=-1,g}if(J.status===se){if(J.gzhead.extra){let ve=J.pending,Xe=(J.gzhead.extra.length&65535)-J.gzindex;for(;J.pending+Xe>J.pending_buf_size;){let Ze=J.pending_buf_size-J.pending;if(J.pending_buf.set(J.gzhead.extra.subarray(J.gzindex,J.gzindex+Ze),J.pending),J.pending=J.pending_buf_size,J.gzhead.hcrc&&J.pending>ve&&(w.adler=l(w.adler,J.pending_buf,J.pending-ve,ve)),J.gzindex+=Ze,K(w),J.pending!==0)return J.last_flush=-1,g;ve=0,Xe-=Ze}let ut=new Uint8Array(J.gzhead.extra);J.pending_buf.set(ut.subarray(J.gzindex,J.gzindex+Xe),J.pending),J.pending+=Xe,J.gzhead.hcrc&&J.pending>ve&&(w.adler=l(w.adler,J.pending_buf,J.pending-ve,ve)),J.gzindex=0}J.status=Ae}if(J.status===Ae){if(J.gzhead.name){let ve=J.pending,Xe;do{if(J.pending===J.pending_buf_size){if(J.gzhead.hcrc&&J.pending>ve&&(w.adler=l(w.adler,J.pending_buf,J.pending-ve,ve)),K(w),J.pending!==0)return J.last_flush=-1,g;ve=0}J.gzindex<J.gzhead.name.length?Xe=J.gzhead.name.charCodeAt(J.gzindex++)&255:Xe=0,oe(J,Xe)}while(Xe!==0);J.gzhead.hcrc&&J.pending>ve&&(w.adler=l(w.adler,J.pending_buf,J.pending-ve,ve)),J.gzindex=0}J.status=Qe}if(J.status===Qe){if(J.gzhead.comment){let ve=J.pending,Xe;do{if(J.pending===J.pending_buf_size){if(J.gzhead.hcrc&&J.pending>ve&&(w.adler=l(w.adler,J.pending_buf,J.pending-ve,ve)),K(w),J.pending!==0)return J.last_flush=-1,g;ve=0}J.gzindex<J.gzhead.comment.length?Xe=J.gzhead.comment.charCodeAt(J.gzindex++)&255:Xe=0,oe(J,Xe)}while(Xe!==0);J.gzhead.hcrc&&J.pending>ve&&(w.adler=l(w.adler,J.pending_buf,J.pending-ve,ve))}J.status=We}if(J.status===We){if(J.gzhead.hcrc){if(J.pending+2>J.pending_buf_size&&(K(w),J.pending!==0))return J.last_flush=-1,g;oe(J,w.adler&255),oe(J,w.adler>>8&255),w.adler=0}if(J.status=qe,K(w),J.pending!==0)return J.last_flush=-1,g}if(w.avail_in!==0||J.lookahead!==0||_e!==f&&J.status!==Je){let ve=J.level===0?pe(J,_e):J.strategy===C?De(J,_e):J.strategy===T?Ce(J,_e):de[J.level].func(J,_e);if((ve===mt||ve===Rt)&&(J.status=Je),ve===pt||ve===mt)return w.avail_out===0&&(J.last_flush=-1),g;if(ve===ct&&(_e===h?a(J):_e!==m&&(e(J,0,0,!1),_e===A&&(wt(J.head),J.lookahead===0&&(J.strstart=0,J.block_start=0,J.insert=0))),K(w),w.avail_out===0))return J.last_flush=-1,g}return _e!==p?g:J.wrap<=0?x:(J.wrap===2?(oe(J,w.adler&255),oe(J,w.adler>>8&255),oe(J,w.adler>>16&255),oe(J,w.adler>>24&255),oe(J,w.total_in&255),oe(J,w.total_in>>8&255),oe(J,w.total_in>>16&255),oe(J,w.total_in>>24&255)):(Pe(J,w.adler>>>16),Pe(J,w.adler&65535)),K(w),J.wrap>0&&(J.wrap=-J.wrap),J.pending!==0?g:x)},nt=w=>{if(ie(w))return E;const _e=w.state.status;return w.state=null,_e===qe?Pt(w,S):g},it=(w,_e)=>{let J=_e.length;if(ie(w))return E;const ye=w.state,ve=ye.wrap;if(ve===2||ve===1&&ye.status!==xe||ye.lookahead)return E;if(ve===1&&(w.adler=o(w.adler,_e,J,0)),ye.wrap=0,J>=ye.w_size){ve===0&&(wt(ye.head),ye.strstart=0,ye.block_start=0,ye.insert=0);let Pn=new Uint8Array(ye.w_size);Pn.set(_e.subarray(J-ye.w_size,J),0),_e=Pn,J=ye.w_size}const Xe=w.avail_in,ut=w.next_in,Ze=w.input;for(w.avail_in=J,w.next_in=0,w.input=_e,z(ye);ye.lookahead>=q;){let Pn=ye.strstart,Lt=ye.lookahead-(q-1);do ye.ins_h=Ye(ye,ye.ins_h,ye.window[Pn+q-1]),ye.prev[Pn&ye.w_mask]=ye.head[ye.ins_h],ye.head[ye.ins_h]=Pn,Pn++;while(--Lt);ye.strstart=Pn,ye.lookahead=q-1,z(ye)}return ye.strstart+=ye.lookahead,ye.block_start=ye.strstart,ye.insert=ye.lookahead,ye.lookahead=0,ye.match_length=ye.prev_length=q-1,ye.match_available=0,w.next_in=ut,w.input=Ze,w.avail_in=Xe,ye.wrap=ve,g};return Nr.deflateInit=Z,Nr.deflateInit2=ke,Nr.deflateReset=Oe,Nr.deflateResetKeep=be,Nr.deflateSetHeader=Re,Nr.deflate=ce,Nr.deflateEnd=nt,Nr.deflateSetDictionary=it,Nr.deflateInfo="pako deflate (from Nodeca project)",Nr}var _h={},RC;function _T(){if(RC)return _h;RC=1;const n=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);return _h.assign=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const i=t.shift();if(i){if(typeof i!="object")throw new TypeError(i+"must be non-object");for(const a in i)n(i,a)&&(e[a]=i[a])}}return e},_h.flattenChunks=e=>{let t=0;for(let a=0,o=e.length;a<o;a++)t+=e[a].length;const i=new Uint8Array(t);for(let a=0,o=0,l=e.length;a<l;a++){let u=e[a];i.set(u,o),o+=u.length}return i},_h}var Tu={},DC;function yT(){if(DC)return Tu;DC=1;let n=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{n=!1}const e=new Uint8Array(256);for(let i=0;i<256;i++)e[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;e[254]=e[254]=1,Tu.string2buf=i=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(i);let a,o,l,u,f,h=i.length,A=0;for(u=0;u<h;u++)o=i.charCodeAt(u),(o&64512)===55296&&u+1<h&&(l=i.charCodeAt(u+1),(l&64512)===56320&&(o=65536+(o-55296<<10)+(l-56320),u++)),A+=o<128?1:o<2048?2:o<65536?3:4;for(a=new Uint8Array(A),f=0,u=0;f<A;u++)o=i.charCodeAt(u),(o&64512)===55296&&u+1<h&&(l=i.charCodeAt(u+1),(l&64512)===56320&&(o=65536+(o-55296<<10)+(l-56320),u++)),o<128?a[f++]=o:o<2048?(a[f++]=192|o>>>6,a[f++]=128|o&63):o<65536?(a[f++]=224|o>>>12,a[f++]=128|o>>>6&63,a[f++]=128|o&63):(a[f++]=240|o>>>18,a[f++]=128|o>>>12&63,a[f++]=128|o>>>6&63,a[f++]=128|o&63);return a};const t=(i,a)=>{if(a<65534&&i.subarray&&n)return String.fromCharCode.apply(null,i.length===a?i:i.subarray(0,a));let o="";for(let l=0;l<a;l++)o+=String.fromCharCode(i[l]);return o};return Tu.buf2string=(i,a)=>{const o=a||i.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(i.subarray(0,a));let l,u;const f=new Array(o*2);for(u=0,l=0;l<o;){let h=i[l++];if(h<128){f[u++]=h;continue}let A=e[h];if(A>4){f[u++]=65533,l+=A-1;continue}for(h&=A===2?31:A===3?15:7;A>1&&l<o;)h=h<<6|i[l++]&63,A--;if(A>1){f[u++]=65533;continue}h<65536?f[u++]=h:(h-=65536,f[u++]=55296|h>>10&1023,f[u++]=56320|h&1023)}return t(f,u)},Tu.utf8border=(i,a)=>{a=a||i.length,a>i.length&&(a=i.length);let o=a-1;for(;o>=0&&(i[o]&192)===128;)o--;return o<0||o===0?a:o+e[i[o]]>a?o:a},Tu}var t0,NC;function ET(){if(NC)return t0;NC=1;function n(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}return t0=n,t0}var LC;function p8(){if(LC)return xo;LC=1;const n=h8(),e=_T(),t=yT(),i=yx(),a=ET(),o=Object.prototype.toString,{Z_NO_FLUSH:l,Z_SYNC_FLUSH:u,Z_FULL_FLUSH:f,Z_FINISH:h,Z_OK:A,Z_STREAM_END:p,Z_DEFAULT_COMPRESSION:m,Z_DEFAULT_STRATEGY:g,Z_DEFLATED:x}=Fo();function E(M){this.options=e.assign({level:m,method:x,chunkSize:16384,windowBits:15,memLevel:8,strategy:g},M||{});let C=this.options;C.raw&&C.windowBits>0?C.windowBits=-C.windowBits:C.gzip&&C.windowBits>0&&C.windowBits<16&&(C.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new a,this.strm.avail_out=0;let T=n.deflateInit2(this.strm,C.level,C.method,C.windowBits,C.memLevel,C.strategy);if(T!==A)throw new Error(i[T]);if(C.header&&n.deflateSetHeader(this.strm,C.header),C.dictionary){let B;if(typeof C.dictionary=="string"?B=t.string2buf(C.dictionary):o.call(C.dictionary)==="[object ArrayBuffer]"?B=new Uint8Array(C.dictionary):B=C.dictionary,T=n.deflateSetDictionary(this.strm,B),T!==A)throw new Error(i[T]);this._dict_set=!0}}E.prototype.push=function(M,C){const T=this.strm,B=this.options.chunkSize;let L,O;if(this.ended)return!1;for(C===~~C?O=C:O=C===!0?h:l,typeof M=="string"?T.input=t.string2buf(M):o.call(M)==="[object ArrayBuffer]"?T.input=new Uint8Array(M):T.input=M,T.next_in=0,T.avail_in=T.input.length;;){if(T.avail_out===0&&(T.output=new Uint8Array(B),T.next_out=0,T.avail_out=B),(O===u||O===f)&&T.avail_out<=6){this.onData(T.output.subarray(0,T.next_out)),T.avail_out=0;continue}if(L=n.deflate(T,O),L===p)return T.next_out>0&&this.onData(T.output.subarray(0,T.next_out)),L=n.deflateEnd(this.strm),this.onEnd(L),this.ended=!0,L===A;if(T.avail_out===0){this.onData(T.output);continue}if(O>0&&T.next_out>0){this.onData(T.output.subarray(0,T.next_out)),T.avail_out=0;continue}if(T.avail_in===0)break}return!0},E.prototype.onData=function(M){this.chunks.push(M)},E.prototype.onEnd=function(M){M===A&&(this.result=e.flattenChunks(this.chunks)),this.chunks=[],this.err=M,this.msg=this.strm.msg};function S(M,C){const T=new E(C);if(T.push(M,!0),T.err)throw T.msg||i[T.err];return T.result}function y(M,C){return C=C||{},C.raw=!0,S(M,C)}function I(M,C){return C=C||{},C.gzip=!0,S(M,C)}return xo.Deflate=E,xo.deflate=S,xo.deflateRaw=y,xo.gzip=I,xo.constants=Fo(),xo}var yo={},mr={},n0,UC;function A8(){if(UC)return n0;UC=1;const n=16209,e=16191;return n0=function(i,a){let o,l,u,f,h,A,p,m,g,x,E,S,y,I,M,C,T,B,L,O,R,F,j,V;const W=i.state;o=i.next_in,j=i.input,l=o+(i.avail_in-5),u=i.next_out,V=i.output,f=u-(a-i.avail_out),h=u+(i.avail_out-257),A=W.dmax,p=W.wsize,m=W.whave,g=W.wnext,x=W.window,E=W.hold,S=W.bits,y=W.lencode,I=W.distcode,M=(1<<W.lenbits)-1,C=(1<<W.distbits)-1;e:do{S<15&&(E+=j[o++]<<S,S+=8,E+=j[o++]<<S,S+=8),T=y[E&M];t:for(;;){if(B=T>>>24,E>>>=B,S-=B,B=T>>>16&255,B===0)V[u++]=T&65535;else if(B&16){L=T&65535,B&=15,B&&(S<B&&(E+=j[o++]<<S,S+=8),L+=E&(1<<B)-1,E>>>=B,S-=B),S<15&&(E+=j[o++]<<S,S+=8,E+=j[o++]<<S,S+=8),T=I[E&C];n:for(;;){if(B=T>>>24,E>>>=B,S-=B,B=T>>>16&255,B&16){if(O=T&65535,B&=15,S<B&&(E+=j[o++]<<S,S+=8,S<B&&(E+=j[o++]<<S,S+=8)),O+=E&(1<<B)-1,O>A){i.msg="invalid distance too far back",W.mode=n;break e}if(E>>>=B,S-=B,B=u-f,O>B){if(B=O-B,B>m&&W.sane){i.msg="invalid distance too far back",W.mode=n;break e}if(R=0,F=x,g===0){if(R+=p-B,B<L){L-=B;do V[u++]=x[R++];while(--B);R=u-O,F=V}}else if(g<B){if(R+=p+g-B,B-=g,B<L){L-=B;do V[u++]=x[R++];while(--B);if(R=0,g<L){B=g,L-=B;do V[u++]=x[R++];while(--B);R=u-O,F=V}}}else if(R+=g-B,B<L){L-=B;do V[u++]=x[R++];while(--B);R=u-O,F=V}for(;L>2;)V[u++]=F[R++],V[u++]=F[R++],V[u++]=F[R++],L-=3;L&&(V[u++]=F[R++],L>1&&(V[u++]=F[R++]))}else{R=u-O;do V[u++]=V[R++],V[u++]=V[R++],V[u++]=V[R++],L-=3;while(L>2);L&&(V[u++]=V[R++],L>1&&(V[u++]=V[R++]))}}else if((B&64)===0){T=I[(T&65535)+(E&(1<<B)-1)];continue n}else{i.msg="invalid distance code",W.mode=n;break e}break}}else if((B&64)===0){T=y[(T&65535)+(E&(1<<B)-1)];continue t}else if(B&32){W.mode=e;break e}else{i.msg="invalid literal/length code",W.mode=n;break e}break}}while(o<l&&u<h);L=S>>3,o-=L,S-=L<<3,E&=(1<<S)-1,i.next_in=o,i.next_out=u,i.avail_in=o<l?5+(l-o):5-(o-l),i.avail_out=u<h?257+(h-u):257-(u-h),W.hold=E,W.bits=S},n0}var i0,PC;function m8(){if(PC)return i0;PC=1;const n=15,e=852,t=592,i=0,a=1,o=2,l=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),u=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),f=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),h=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);return i0=(p,m,g,x,E,S,y,I)=>{const M=I.bits;let C=0,T=0,B=0,L=0,O=0,R=0,F=0,j=0,V=0,W=0,te,ne,k,X,Y,ee=null,q;const Q=new Uint16Array(n+1),re=new Uint16Array(n+1);let ue=null,xe,Me,se;for(C=0;C<=n;C++)Q[C]=0;for(T=0;T<x;T++)Q[m[g+T]]++;for(O=M,L=n;L>=1&&Q[L]===0;L--);if(O>L&&(O=L),L===0)return E[S++]=1<<24|64<<16|0,E[S++]=1<<24|64<<16|0,I.bits=1,0;for(B=1;B<L&&Q[B]===0;B++);for(O<B&&(O=B),j=1,C=1;C<=n;C++)if(j<<=1,j-=Q[C],j<0)return-1;if(j>0&&(p===i||L!==1))return-1;for(re[1]=0,C=1;C<n;C++)re[C+1]=re[C]+Q[C];for(T=0;T<x;T++)m[g+T]!==0&&(y[re[m[g+T]]++]=T);if(p===i?(ee=ue=y,q=20):p===a?(ee=l,ue=u,q=257):(ee=f,ue=h,q=0),W=0,T=0,C=B,Y=S,R=O,F=0,k=-1,V=1<<O,X=V-1,p===a&&V>e||p===o&&V>t)return 1;for(;;){xe=C-F,y[T]+1<q?(Me=0,se=y[T]):y[T]>=q?(Me=ue[y[T]-q],se=ee[y[T]-q]):(Me=96,se=0),te=1<<C-F,ne=1<<R,B=ne;do ne-=te,E[Y+(W>>F)+ne]=xe<<24|Me<<16|se|0;while(ne!==0);for(te=1<<C-1;W&te;)te>>=1;if(te!==0?(W&=te-1,W+=te):W=0,T++,--Q[C]===0){if(C===L)break;C=m[g+y[T]]}if(C>O&&(W&X)!==k){for(F===0&&(F=O),Y+=B,R=C-F,j=1<<R;R+F<L&&(j-=Q[R+F],!(j<=0));)R++,j<<=1;if(V+=1<<R,p===a&&V>e||p===o&&V>t)return 1;k=W&X,E[k]=O<<24|R<<16|Y-S|0}}return W!==0&&(E[Y+W]=C-F<<24|64<<16|0),I.bits=O,0},i0}var FC;function g8(){if(FC)return mr;FC=1;const n=vT(),e=xT(),t=A8(),i=m8(),a=0,o=1,l=2,{Z_FINISH:u,Z_BLOCK:f,Z_TREES:h,Z_OK:A,Z_STREAM_END:p,Z_NEED_DICT:m,Z_STREAM_ERROR:g,Z_DATA_ERROR:x,Z_MEM_ERROR:E,Z_BUF_ERROR:S,Z_DEFLATED:y}=Fo(),I=16180,M=16181,C=16182,T=16183,B=16184,L=16185,O=16186,R=16187,F=16188,j=16189,V=16190,W=16191,te=16192,ne=16193,k=16194,X=16195,Y=16196,ee=16197,q=16198,Q=16199,re=16200,ue=16201,xe=16202,Me=16203,se=16204,Ae=16205,Qe=16206,We=16207,qe=16208,Je=16209,pt=16210,ct=16211,mt=852,Rt=592,Pt=15,le=$=>($>>>24&255)+($>>>8&65280)+(($&65280)<<8)+(($&255)<<24);function wt(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Mt=$=>{if(!$)return 1;const de=$.state;return!de||de.strm!==$||de.mode<I||de.mode>ct?1:0},Xt=$=>{if(Mt($))return g;const de=$.state;return $.total_in=$.total_out=de.total=0,$.msg="",de.wrap&&($.adler=de.wrap&1),de.mode=I,de.last=0,de.havedict=0,de.flags=-1,de.dmax=32768,de.head=null,de.hold=0,de.bits=0,de.lencode=de.lendyn=new Int32Array(mt),de.distcode=de.distdyn=new Int32Array(Rt),de.sane=1,de.back=-1,A},Ye=$=>{if(Mt($))return g;const de=$.state;return de.wsize=0,de.whave=0,de.wnext=0,Xt($)},K=($,de)=>{let U;if(Mt($))return g;const Fe=$.state;return de<0?(U=0,de=-de):(U=(de>>4)+5,de<48&&(de&=15)),de&&(de<8||de>15)?g:(Fe.window!==null&&Fe.wbits!==de&&(Fe.window=null),Fe.wrap=U,Fe.wbits=de,Ye($))},P=($,de)=>{if(!$)return g;const U=new wt;$.state=U,U.strm=$,U.window=null,U.mode=I;const Fe=K($,de);return Fe!==A&&($.state=null),Fe},oe=$=>P($,Pt);let Pe=!0,He,Ne;const z=$=>{if(Pe){He=new Int32Array(512),Ne=new Int32Array(32);let de=0;for(;de<144;)$.lens[de++]=8;for(;de<256;)$.lens[de++]=9;for(;de<280;)$.lens[de++]=7;for(;de<288;)$.lens[de++]=8;for(i(o,$.lens,0,288,He,0,$.work,{bits:9}),de=0;de<32;)$.lens[de++]=5;i(l,$.lens,0,32,Ne,0,$.work,{bits:5}),Pe=!1}$.lencode=He,$.lenbits=9,$.distcode=Ne,$.distbits=5},pe=($,de,U,Fe)=>{let ie;const be=$.state;return be.window===null&&(be.wsize=1<<be.wbits,be.wnext=0,be.whave=0,be.window=new Uint8Array(be.wsize)),Fe>=be.wsize?(be.window.set(de.subarray(U-be.wsize,U),0),be.wnext=0,be.whave=be.wsize):(ie=be.wsize-be.wnext,ie>Fe&&(ie=Fe),be.window.set(de.subarray(U-Fe,U-Fe+ie),be.wnext),Fe-=ie,Fe?(be.window.set(de.subarray(U-Fe,U),0),be.wnext=Fe,be.whave=be.wsize):(be.wnext+=ie,be.wnext===be.wsize&&(be.wnext=0),be.whave<be.wsize&&(be.whave+=ie))),0},Ie=($,de)=>{let U,Fe,ie,be,Oe,Re,ke,Z,ce,nt,it,w,_e,J,ye=0,ve,Xe,ut,Ze,Pn,Lt,$t,en;const jt=new Uint8Array(4);let In,jn;const ua=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Mt($)||!$.output||!$.input&&$.avail_in!==0)return g;U=$.state,U.mode===W&&(U.mode=te),Oe=$.next_out,ie=$.output,ke=$.avail_out,be=$.next_in,Fe=$.input,Re=$.avail_in,Z=U.hold,ce=U.bits,nt=Re,it=ke,en=A;e:for(;;)switch(U.mode){case I:if(U.wrap===0){U.mode=te;break}for(;ce<16;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if(U.wrap&2&&Z===35615){U.wbits===0&&(U.wbits=15),U.check=0,jt[0]=Z&255,jt[1]=Z>>>8&255,U.check=e(U.check,jt,2,0),Z=0,ce=0,U.mode=M;break}if(U.head&&(U.head.done=!1),!(U.wrap&1)||(((Z&255)<<8)+(Z>>8))%31){$.msg="incorrect header check",U.mode=Je;break}if((Z&15)!==y){$.msg="unknown compression method",U.mode=Je;break}if(Z>>>=4,ce-=4,$t=(Z&15)+8,U.wbits===0&&(U.wbits=$t),$t>15||$t>U.wbits){$.msg="invalid window size",U.mode=Je;break}U.dmax=1<<U.wbits,U.flags=0,$.adler=U.check=1,U.mode=Z&512?j:W,Z=0,ce=0;break;case M:for(;ce<16;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if(U.flags=Z,(U.flags&255)!==y){$.msg="unknown compression method",U.mode=Je;break}if(U.flags&57344){$.msg="unknown header flags set",U.mode=Je;break}U.head&&(U.head.text=Z>>8&1),U.flags&512&&U.wrap&4&&(jt[0]=Z&255,jt[1]=Z>>>8&255,U.check=e(U.check,jt,2,0)),Z=0,ce=0,U.mode=C;case C:for(;ce<32;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}U.head&&(U.head.time=Z),U.flags&512&&U.wrap&4&&(jt[0]=Z&255,jt[1]=Z>>>8&255,jt[2]=Z>>>16&255,jt[3]=Z>>>24&255,U.check=e(U.check,jt,4,0)),Z=0,ce=0,U.mode=T;case T:for(;ce<16;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}U.head&&(U.head.xflags=Z&255,U.head.os=Z>>8),U.flags&512&&U.wrap&4&&(jt[0]=Z&255,jt[1]=Z>>>8&255,U.check=e(U.check,jt,2,0)),Z=0,ce=0,U.mode=B;case B:if(U.flags&1024){for(;ce<16;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}U.length=Z,U.head&&(U.head.extra_len=Z),U.flags&512&&U.wrap&4&&(jt[0]=Z&255,jt[1]=Z>>>8&255,U.check=e(U.check,jt,2,0)),Z=0,ce=0}else U.head&&(U.head.extra=null);U.mode=L;case L:if(U.flags&1024&&(w=U.length,w>Re&&(w=Re),w&&(U.head&&($t=U.head.extra_len-U.length,U.head.extra||(U.head.extra=new Uint8Array(U.head.extra_len)),U.head.extra.set(Fe.subarray(be,be+w),$t)),U.flags&512&&U.wrap&4&&(U.check=e(U.check,Fe,w,be)),Re-=w,be+=w,U.length-=w),U.length))break e;U.length=0,U.mode=O;case O:if(U.flags&2048){if(Re===0)break e;w=0;do $t=Fe[be+w++],U.head&&$t&&U.length<65536&&(U.head.name+=String.fromCharCode($t));while($t&&w<Re);if(U.flags&512&&U.wrap&4&&(U.check=e(U.check,Fe,w,be)),Re-=w,be+=w,$t)break e}else U.head&&(U.head.name=null);U.length=0,U.mode=R;case R:if(U.flags&4096){if(Re===0)break e;w=0;do $t=Fe[be+w++],U.head&&$t&&U.length<65536&&(U.head.comment+=String.fromCharCode($t));while($t&&w<Re);if(U.flags&512&&U.wrap&4&&(U.check=e(U.check,Fe,w,be)),Re-=w,be+=w,$t)break e}else U.head&&(U.head.comment=null);U.mode=F;case F:if(U.flags&512){for(;ce<16;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if(U.wrap&4&&Z!==(U.check&65535)){$.msg="header crc mismatch",U.mode=Je;break}Z=0,ce=0}U.head&&(U.head.hcrc=U.flags>>9&1,U.head.done=!0),$.adler=U.check=0,U.mode=W;break;case j:for(;ce<32;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}$.adler=U.check=le(Z),Z=0,ce=0,U.mode=V;case V:if(U.havedict===0)return $.next_out=Oe,$.avail_out=ke,$.next_in=be,$.avail_in=Re,U.hold=Z,U.bits=ce,m;$.adler=U.check=1,U.mode=W;case W:if(de===f||de===h)break e;case te:if(U.last){Z>>>=ce&7,ce-=ce&7,U.mode=Qe;break}for(;ce<3;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}switch(U.last=Z&1,Z>>>=1,ce-=1,Z&3){case 0:U.mode=ne;break;case 1:if(z(U),U.mode=Q,de===h){Z>>>=2,ce-=2;break e}break;case 2:U.mode=Y;break;case 3:$.msg="invalid block type",U.mode=Je}Z>>>=2,ce-=2;break;case ne:for(Z>>>=ce&7,ce-=ce&7;ce<32;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if((Z&65535)!==(Z>>>16^65535)){$.msg="invalid stored block lengths",U.mode=Je;break}if(U.length=Z&65535,Z=0,ce=0,U.mode=k,de===h)break e;case k:U.mode=X;case X:if(w=U.length,w){if(w>Re&&(w=Re),w>ke&&(w=ke),w===0)break e;ie.set(Fe.subarray(be,be+w),Oe),Re-=w,be+=w,ke-=w,Oe+=w,U.length-=w;break}U.mode=W;break;case Y:for(;ce<14;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if(U.nlen=(Z&31)+257,Z>>>=5,ce-=5,U.ndist=(Z&31)+1,Z>>>=5,ce-=5,U.ncode=(Z&15)+4,Z>>>=4,ce-=4,U.nlen>286||U.ndist>30){$.msg="too many length or distance symbols",U.mode=Je;break}U.have=0,U.mode=ee;case ee:for(;U.have<U.ncode;){for(;ce<3;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}U.lens[ua[U.have++]]=Z&7,Z>>>=3,ce-=3}for(;U.have<19;)U.lens[ua[U.have++]]=0;if(U.lencode=U.lendyn,U.lenbits=7,In={bits:U.lenbits},en=i(a,U.lens,0,19,U.lencode,0,U.work,In),U.lenbits=In.bits,en){$.msg="invalid code lengths set",U.mode=Je;break}U.have=0,U.mode=q;case q:for(;U.have<U.nlen+U.ndist;){for(;ye=U.lencode[Z&(1<<U.lenbits)-1],ve=ye>>>24,Xe=ye>>>16&255,ut=ye&65535,!(ve<=ce);){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if(ut<16)Z>>>=ve,ce-=ve,U.lens[U.have++]=ut;else{if(ut===16){for(jn=ve+2;ce<jn;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if(Z>>>=ve,ce-=ve,U.have===0){$.msg="invalid bit length repeat",U.mode=Je;break}$t=U.lens[U.have-1],w=3+(Z&3),Z>>>=2,ce-=2}else if(ut===17){for(jn=ve+3;ce<jn;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}Z>>>=ve,ce-=ve,$t=0,w=3+(Z&7),Z>>>=3,ce-=3}else{for(jn=ve+7;ce<jn;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}Z>>>=ve,ce-=ve,$t=0,w=11+(Z&127),Z>>>=7,ce-=7}if(U.have+w>U.nlen+U.ndist){$.msg="invalid bit length repeat",U.mode=Je;break}for(;w--;)U.lens[U.have++]=$t}}if(U.mode===Je)break;if(U.lens[256]===0){$.msg="invalid code -- missing end-of-block",U.mode=Je;break}if(U.lenbits=9,In={bits:U.lenbits},en=i(o,U.lens,0,U.nlen,U.lencode,0,U.work,In),U.lenbits=In.bits,en){$.msg="invalid literal/lengths set",U.mode=Je;break}if(U.distbits=6,U.distcode=U.distdyn,In={bits:U.distbits},en=i(l,U.lens,U.nlen,U.ndist,U.distcode,0,U.work,In),U.distbits=In.bits,en){$.msg="invalid distances set",U.mode=Je;break}if(U.mode=Q,de===h)break e;case Q:U.mode=re;case re:if(Re>=6&&ke>=258){$.next_out=Oe,$.avail_out=ke,$.next_in=be,$.avail_in=Re,U.hold=Z,U.bits=ce,t($,it),Oe=$.next_out,ie=$.output,ke=$.avail_out,be=$.next_in,Fe=$.input,Re=$.avail_in,Z=U.hold,ce=U.bits,U.mode===W&&(U.back=-1);break}for(U.back=0;ye=U.lencode[Z&(1<<U.lenbits)-1],ve=ye>>>24,Xe=ye>>>16&255,ut=ye&65535,!(ve<=ce);){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if(Xe&&(Xe&240)===0){for(Ze=ve,Pn=Xe,Lt=ut;ye=U.lencode[Lt+((Z&(1<<Ze+Pn)-1)>>Ze)],ve=ye>>>24,Xe=ye>>>16&255,ut=ye&65535,!(Ze+ve<=ce);){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}Z>>>=Ze,ce-=Ze,U.back+=Ze}if(Z>>>=ve,ce-=ve,U.back+=ve,U.length=ut,Xe===0){U.mode=Ae;break}if(Xe&32){U.back=-1,U.mode=W;break}if(Xe&64){$.msg="invalid literal/length code",U.mode=Je;break}U.extra=Xe&15,U.mode=ue;case ue:if(U.extra){for(jn=U.extra;ce<jn;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}U.length+=Z&(1<<U.extra)-1,Z>>>=U.extra,ce-=U.extra,U.back+=U.extra}U.was=U.length,U.mode=xe;case xe:for(;ye=U.distcode[Z&(1<<U.distbits)-1],ve=ye>>>24,Xe=ye>>>16&255,ut=ye&65535,!(ve<=ce);){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if((Xe&240)===0){for(Ze=ve,Pn=Xe,Lt=ut;ye=U.distcode[Lt+((Z&(1<<Ze+Pn)-1)>>Ze)],ve=ye>>>24,Xe=ye>>>16&255,ut=ye&65535,!(Ze+ve<=ce);){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}Z>>>=Ze,ce-=Ze,U.back+=Ze}if(Z>>>=ve,ce-=ve,U.back+=ve,Xe&64){$.msg="invalid distance code",U.mode=Je;break}U.offset=ut,U.extra=Xe&15,U.mode=Me;case Me:if(U.extra){for(jn=U.extra;ce<jn;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}U.offset+=Z&(1<<U.extra)-1,Z>>>=U.extra,ce-=U.extra,U.back+=U.extra}if(U.offset>U.dmax){$.msg="invalid distance too far back",U.mode=Je;break}U.mode=se;case se:if(ke===0)break e;if(w=it-ke,U.offset>w){if(w=U.offset-w,w>U.whave&&U.sane){$.msg="invalid distance too far back",U.mode=Je;break}w>U.wnext?(w-=U.wnext,_e=U.wsize-w):_e=U.wnext-w,w>U.length&&(w=U.length),J=U.window}else J=ie,_e=Oe-U.offset,w=U.length;w>ke&&(w=ke),ke-=w,U.length-=w;do ie[Oe++]=J[_e++];while(--w);U.length===0&&(U.mode=re);break;case Ae:if(ke===0)break e;ie[Oe++]=U.length,ke--,U.mode=re;break;case Qe:if(U.wrap){for(;ce<32;){if(Re===0)break e;Re--,Z|=Fe[be++]<<ce,ce+=8}if(it-=ke,$.total_out+=it,U.total+=it,U.wrap&4&&it&&($.adler=U.check=U.flags?e(U.check,ie,it,Oe-it):n(U.check,ie,it,Oe-it)),it=ke,U.wrap&4&&(U.flags?Z:le(Z))!==U.check){$.msg="incorrect data check",U.mode=Je;break}Z=0,ce=0}U.mode=We;case We:if(U.wrap&&U.flags){for(;ce<32;){if(Re===0)break e;Re--,Z+=Fe[be++]<<ce,ce+=8}if(U.wrap&4&&Z!==(U.total&4294967295)){$.msg="incorrect length check",U.mode=Je;break}Z=0,ce=0}U.mode=qe;case qe:en=p;break e;case Je:en=x;break e;case pt:return E;case ct:default:return g}return $.next_out=Oe,$.avail_out=ke,$.next_in=be,$.avail_in=Re,U.hold=Z,U.bits=ce,(U.wsize||it!==$.avail_out&&U.mode<Je&&(U.mode<Qe||de!==u))&&pe($,$.output,$.next_out,it-$.avail_out),nt-=$.avail_in,it-=$.avail_out,$.total_in+=nt,$.total_out+=it,U.total+=it,U.wrap&4&&it&&($.adler=U.check=U.flags?e(U.check,ie,it,$.next_out-it):n(U.check,ie,it,$.next_out-it)),$.data_type=U.bits+(U.last?64:0)+(U.mode===W?128:0)+(U.mode===Q||U.mode===k?256:0),(nt===0&&it===0||de===u)&&en===A&&(en=S),en},ze=$=>{if(Mt($))return g;let de=$.state;return de.window&&(de.window=null),$.state=null,A},Ce=($,de)=>{if(Mt($))return g;const U=$.state;return(U.wrap&2)===0?g:(U.head=de,de.done=!1,A)},De=($,de)=>{const U=de.length;let Fe,ie,be;return Mt($)||(Fe=$.state,Fe.wrap!==0&&Fe.mode!==V)?g:Fe.mode===V&&(ie=1,ie=n(ie,de,U,0),ie!==Fe.check)?x:(be=pe($,de,U,U),be?(Fe.mode=pt,E):(Fe.havedict=1,A))};return mr.inflateReset=Ye,mr.inflateReset2=K,mr.inflateResetKeep=Xt,mr.inflateInit=oe,mr.inflateInit2=P,mr.inflate=Ie,mr.inflateEnd=ze,mr.inflateGetHeader=Ce,mr.inflateSetDictionary=De,mr.inflateInfo="pako inflate (from Nodeca project)",mr}var r0,OC;function v8(){if(OC)return r0;OC=1;function n(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}return r0=n,r0}var kC;function x8(){if(kC)return yo;kC=1;const n=g8(),e=_T(),t=yT(),i=yx(),a=ET(),o=v8(),l=Object.prototype.toString,{Z_NO_FLUSH:u,Z_FINISH:f,Z_OK:h,Z_STREAM_END:A,Z_NEED_DICT:p,Z_STREAM_ERROR:m,Z_DATA_ERROR:g,Z_MEM_ERROR:x}=Fo();function E(I){this.options=e.assign({chunkSize:1024*64,windowBits:15,to:""},I||{});const M=this.options;M.raw&&M.windowBits>=0&&M.windowBits<16&&(M.windowBits=-M.windowBits,M.windowBits===0&&(M.windowBits=-15)),M.windowBits>=0&&M.windowBits<16&&!(I&&I.windowBits)&&(M.windowBits+=32),M.windowBits>15&&M.windowBits<48&&(M.windowBits&15)===0&&(M.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new a,this.strm.avail_out=0;let C=n.inflateInit2(this.strm,M.windowBits);if(C!==h)throw new Error(i[C]);if(this.header=new o,n.inflateGetHeader(this.strm,this.header),M.dictionary&&(typeof M.dictionary=="string"?M.dictionary=t.string2buf(M.dictionary):l.call(M.dictionary)==="[object ArrayBuffer]"&&(M.dictionary=new Uint8Array(M.dictionary)),M.raw&&(C=n.inflateSetDictionary(this.strm,M.dictionary),C!==h)))throw new Error(i[C])}E.prototype.push=function(I,M){const C=this.strm,T=this.options.chunkSize,B=this.options.dictionary;let L,O,R;if(this.ended)return!1;for(M===~~M?O=M:O=M===!0?f:u,l.call(I)==="[object ArrayBuffer]"?C.input=new Uint8Array(I):C.input=I,C.next_in=0,C.avail_in=C.input.length;;){for(C.avail_out===0&&(C.output=new Uint8Array(T),C.next_out=0,C.avail_out=T),L=n.inflate(C,O),L===p&&B&&(L=n.inflateSetDictionary(C,B),L===h?L=n.inflate(C,O):L===g&&(L=p));C.avail_in>0&&L===A&&C.state.wrap>0&&I[C.next_in]!==0;)n.inflateReset(C),L=n.inflate(C,O);switch(L){case m:case g:case p:case x:return this.onEnd(L),this.ended=!0,!1}if(R=C.avail_out,C.next_out&&(C.avail_out===0||L===A))if(this.options.to==="string"){let F=t.utf8border(C.output,C.next_out),j=C.next_out-F,V=t.buf2string(C.output,F);C.next_out=j,C.avail_out=T-j,j&&C.output.set(C.output.subarray(F,F+j),0),this.onData(V)}else this.onData(C.output.length===C.next_out?C.output:C.output.subarray(0,C.next_out));if(!(L===h&&R===0)){if(L===A)return L=n.inflateEnd(this.strm),this.onEnd(L),this.ended=!0,!0;if(C.avail_in===0)break}}return!0},E.prototype.onData=function(I){this.chunks.push(I)},E.prototype.onEnd=function(I){I===h&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=e.flattenChunks(this.chunks)),this.chunks=[],this.err=I,this.msg=this.strm.msg};function S(I,M){const C=new E(M);if(C.push(I),C.err)throw C.msg||i[C.err];return C.result}function y(I,M){return M=M||{},M.raw=!0,S(I,M)}return yo.Inflate=E,yo.inflate=S,yo.inflateRaw=y,yo.ungzip=S,yo.constants=Fo(),yo}var QC;function _8(){if(QC)return Dr;QC=1;const{Deflate:n,deflate:e,deflateRaw:t,gzip:i}=p8(),{Inflate:a,inflate:o,inflateRaw:l,ungzip:u}=x8(),f=Fo();return Dr.Deflate=n,Dr.deflate=e,Dr.deflateRaw=t,Dr.gzip=i,Dr.Inflate=a,Dr.inflate=o,Dr.inflateRaw=l,Dr.ungzip=u,Dr.constants=f,Dr}var zC;function y8(){if(zC)return Mu;zC=1,Object.defineProperty(Mu,"__esModule",{value:!0}),Mu.parseBinary=void 0;var n=f8(),e=_8(),t=Uint8Array.from("Kaydara FBX Binary \0\0".split(""),function(u){return u.charCodeAt(0)});function i(u){if(u.length<t.length)throw"Not a binary FBX file";var f=new n.BinaryReader(u),h=f.readUint8Array(t.length).every(function(x,E){return x===t[E]});if(!h)throw"Not a binary FBX file";for(var A=f.readUint32(),p=A>=7500,m=[];;){var g=a(f,p);if(g===null)break;m.push(g)}return m}Mu.parseBinary=i;function a(u,f){var h=f?Number(u.readUint64()):u.readUint32();if(h===0)return null;var A=f?Number(u.readUint64()):u.readUint32();f?Number(u.readUint64()):u.readUint32();for(var p=u.readUint8(),m=u.readArrayAsString(p),g={name:m,props:[],nodes:[]},x=0;x<A;++x)g.props.push(o(u));for(;h-u.offset>13;){var E=a(u,f);E!==null&&g.nodes.push(E)}return u.offset=h,g}function o(u){var f=u.readUint8AsString(),h={Y:function(){return u.readInt16()},C:function(){return u.readUint8AsBool()},I:function(){return u.readInt32()},F:function(){return u.readFloat32()},D:function(){return u.readFloat64()},L:function(){return u.readInt64()},f:function(){return l(u,function(g){return g.readFloat32()})},d:function(){return l(u,function(g){return g.readFloat64()})},l:function(){return l(u,function(g){return g.readInt64()})},i:function(){return l(u,function(g){return g.readInt32()})},b:function(){return l(u,function(g){return g.readUint8AsBool()})},S:function(){return u.readArrayAsString(u.readUint32())},R:function(){return Array.from(u.readUint8Array(u.readUint32()))}};if(typeof h[f]>"u")throw"Unknown Property Type "+f.charCodeAt(0);var A=h[f](),p=function(g){return A<Number.MIN_SAFE_INTEGER||g>Number.MAX_SAFE_INTEGER?g:Number(g)};if(f==="L")A=p(A);else if(f==="l")for(var m=0;m<A.length;++m)A[m]=p(A[m]);return f==="S"&&A.indexOf("\0")!=-1&&(A=A.split("\0").reverse().join("::")),A}function l(u,f){var h=u.readUint32(),A=u.readUint32(),p=u.readUint32(),m=new n.BinaryReader(u.readUint8Array(p));A==1&&(m=new n.BinaryReader(e.inflate(m.binary)));for(var g=[],x=0;x<h;++x)g.push(f(m));return g}return Mu}var Bu={},GC;function E8(){if(GC)return Bu;GC=1,Object.defineProperty(Bu,"__esModule",{value:!0}),Bu.parseText=void 0;function n(t){for(var i=t.split(`
4065
- `),a={name:"",props:[],nodes:[]},o=a,l=[o],u=0,f=0,h=i;f<h.length;f++){var A=h[f];if(A=A.trim(),A.length!==0&&A[0]!==";"){if(u===0)if(A[0]==="}"){if(l.length===1)throw"FBX syntax error";l.pop(),o=l[l.length-1]}else{var p=A.indexOf(":"),m=A.substring(0,p);m=m.trim();for(var g=A[A.length-1]==="{",x=A.substring(p+1,A.length-(g?1:0)),E=x.split(","),S=[],y=0,I=E;y<I.length;y++){var M=I[y],C=M.trim();if(C!==""){var T=e(C);typeof T>"u"||S.push(T)}}E[E.length-1]===""&&(u=1);var B={name:m,props:S,nodes:[]};o.nodes.push(B),(g||u===1)&&(l.push(B),o=B)}else if(u===1){for(var g=A[A.length-1]==="{",x=A.substring(0,A.length-(g?1:0)),E=x.split(","),S=[],L=0,O=E;L<O.length;L++){var R=O[L],C=R.trim();if(!(C===""||C==="}")){var T=e(C);typeof T>"u"||S.push(T)}}o.props=o.props.concat(S),E[E.length-1]!==""&&(u=0),!g&&u===0&&(l.pop(),o=l[l.length-1])}}}function F(j){if(j.nodes.length===1&&j.props.length===0&&j.nodes[0].name==="a")j.props=[j.nodes[0].props],j.nodes=[];else for(var V=0,W=j.nodes;V<W.length;V++){var te=W[V];F(te)}}return F(a),a.nodes}Bu.parseText=n;function e(t){if(t[0]!="*"){if(t[0]=='"')return t.substr(1,t.length-2);if(t=="T")return!0;if(t=="F")return!1;if(t=="Y")return!0;if(t=="N")return!1;if(t.indexOf(".")!=-1)return parseFloat(t);var i=BigInt(t);return i<Number.MIN_SAFE_INTEGER||i>Number.MAX_SAFE_INTEGER?i:Number(i)}}return Bu}var Pa={},HC;function b8(){if(HC)return Pa;HC=1;var n=Pa&&Pa.__extends||(function(){var i=function(a,o){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,u){l.__proto__=u}||function(l,u){for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&(l[f]=u[f])},i(a,o)};return function(a,o){i(a,o);function l(){this.constructor=a}a.prototype=o===null?Object.create(o):(l.prototype=o.prototype,new l)}})();Object.defineProperty(Pa,"__esModule",{value:!0}),Pa.FBXReader=Pa.FBXReaderNode=void 0;var e=(function(){function i(a){this.fbxNode=a}return i.prototype.nodeFilter=function(a,o){var l=void 0,u=void 0;typeof a=="string"?(l=a,typeof o<"u"&&(u=o)):u=a;var f;if(typeof u<"u"){var h=function(A){for(var p in u){var m=parseInt(p);if(A.props[m]!==u[m])return!1}return!0};typeof l<"u"?f=function(A){return A.name===l&&h(A)}:f=h}else f=function(A){return A.name===l};return f},i.prototype.node=function(a,o){var l=this.fbxNode.nodes.find(this.nodeFilter(a,o));if(!(typeof l>"u"))return new i(l)},i.prototype.nodes=function(a,o){var l=this.fbxNode.nodes.filter(this.nodeFilter(a,o)).map(function(u){return new i(u)});return l},i.prototype.prop=function(a,o){var l=this.fbxNode.props[a];if(typeof o>"u")return l;if(o==="boolean")return typeof l=="boolean"?l:void 0;if(o==="number")return typeof l=="number"?l:void 0;if(o==="bigint")return typeof l=="bigint"?l:void 0;if(o==="string")return typeof l=="string"?l:void 0;if(Array.isArray(l)){if(l.length==0)return l;if(o==="boolean[]")return typeof l[0]=="boolean"?l:void 0;if(o==="number[]")return typeof l[0]=="number"?l:void 0;if(o==="bigint[]")return typeof l[0]=="bigint"?l:void 0}},i})();Pa.FBXReaderNode=e;var t=(function(i){n(a,i);function a(o){var l=this,u={name:"",props:[],nodes:o};return l=i.call(this,u)||this,l.fbx=o,l}return a})(e);return Pa.FBXReader=t,Pa}var VC;function S8(){return VC||(VC=1,(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.FBXReaderNode=n.FBXReader=n.parseText=n.parseBinary=void 0;var e=y8();Object.defineProperty(n,"parseBinary",{enumerable:!0,get:function(){return e.parseBinary}});var t=E8();Object.defineProperty(n,"parseText",{enumerable:!0,get:function(){return t.parseText}});var i=b8();Object.defineProperty(n,"FBXReader",{enumerable:!0,get:function(){return i.FBXReader}}),Object.defineProperty(n,"FBXReaderNode",{enumerable:!0,get:function(){return i.FBXReaderNode}})})(Kg)),Kg}var a0=S8();function C8(n){const e=M8(n);if(e.length===0)return[];const t=[];for(const i of e){const a=[];for(const o of i.tracks)o.name.endsWith(".scale")||(o.name.endsWith(".quaternion")?a.push(new aa(o.name,Array.from(o.times),Array.from(o.values))):a.push(new ks(o.name,Array.from(o.times),Array.from(o.values))));a.length>0&&t.push(new Uo(i.name,i.duration,a))}return t}function w8(n,e){const t=new Set;return e.traverse(i=>{i.isBone&&t.add(i.name)}),t.size===0?n:n.map(i=>{const a=new Map;for(const l of i.tracks){const u=l.name.split(".")[0];if(!t.has(u))for(const f of t){const h=Kt.sanitizeNodeName(u),A=Kt.sanitizeNodeName(f);if(h===A||h.endsWith(A)||A.endsWith(h)){a.set(u,f);break}}}if(a.size===0)return i;const o=i.tracks.map(l=>{const u=l.name.split("."),h=`${a.get(u[0])??u[0]}.${u.slice(1).join(".")}`;return l instanceof aa?new aa(h,Array.from(l.times),Array.from(l.values)):new ks(h,Array.from(l.times),Array.from(l.values))});return new Uo(i.name,i.duration,o)})}const jC=46186158e3,Fa=Math.PI/180;function WC(n){return Array.isArray(n)||ArrayBuffer.isView(n)}function M8(n){let e;try{e=a0.parseBinary(n)}catch{try{e=a0.parseText(new TextDecoder().decode(n))}catch{return[]}}const t=new a0.FBXReader(e),i=t.node("Objects"),a=t.node("Connections");if(!i||!a)return[];let o=.01;const l=t.node("GlobalSettings");if(l){const I=l.fbxNode.nodes.find(M=>M.name==="Properties70");if(I){const M=I.nodes.find(C=>C.name==="P"&&String(C.props[0])==="UnitScaleFactor");if(M){const C=Number(M.props[4]);C>0&&(o=C/100)}}}const u=new Map;function f(I){let M=u.get(I);return M||(M={parents:[],children:[]},u.set(I,M)),M}for(const I of a.fbxNode.nodes){if(I.name!=="C")continue;const M=I.props[1],C=I.props[2],T=I.props.length>3?String(I.props[3]):void 0;f(M).parents.push({id:C,rel:T}),f(C).children.push({id:M,rel:T})}const h=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"],A=new Map,p=new Map;for(const I of i.fbxNode.nodes){if(I.name!=="Model")continue;const M=I.props[0],C=String(I.props[1]??""),T=C.includes("\0")?C.split("\0")[0]:C.replace(/^Model::/,"");if(!T)continue;A.set(M,T);let B,L,O="ZYX";const R=I.nodes.find(F=>F.name==="Properties70");if(R)for(const F of R.nodes){if(F.name!=="P")continue;const j=String(F.props[0]);if(j==="PreRotation")B=[Number(F.props[4]),Number(F.props[5]),Number(F.props[6])];else if(j==="PostRotation")L=[Number(F.props[4]),Number(F.props[5]),Number(F.props[6])];else if(j==="RotationOrder"){const V=Number(F.props[4]);V>=0&&V<h.length&&(O=h[V])}}p.set(M,{preRotation:B,postRotation:L,eulerOrder:O})}const m=new Map;for(const I of i.fbxNode.nodes){if(I.name!=="AnimationCurveNode")continue;const M=I.props[0],C=String(I.props[1]??""),T=C.includes("\0")?C.split("\0")[0]:C;let B=null;T==="T"||T==="Lcl Translation"||T.endsWith("::T")?B="T":T==="R"||T==="Lcl Rotation"||T.endsWith("::R")?B="R":(T==="S"||T==="Lcl Scaling"||T.endsWith("::S"))&&(B="S"),B&&m.set(M,{id:M,attr:B,curves:{}})}if(m.size===0)return[];for(const I of i.fbxNode.nodes){if(I.name!=="AnimationCurve")continue;const M=I.props[0],C=I.nodes.find(V=>V.name==="KeyTime"),T=I.nodes.find(V=>V.name==="KeyValueFloat");if(!C||!T)continue;const B=C.props[0],L=T.props[0];if(!WC(B)||!WC(L))continue;const R=Array.from(B).map(V=>Number(V)/jC),F=Array.isArray(L)?L:Array.from(L),j=u.get(M);if(j)for(const V of j.parents){const W=m.get(V.id);if(!W)continue;const te=V.rel??"",ne={times:R,values:F};te.includes("d|X")?W.curves.x=ne:te.includes("d|Y")?W.curves.y=ne:te.includes("d|Z")&&(W.curves.z=ne)}}const g=[];for(const[,I]of m){if(!I.curves.x&&!I.curves.y&&!I.curves.z)continue;const M=u.get(I.id);if(M)for(const C of M.parents){const T=A.get(C.id);if(T){g.push({modelName:T,modelId:C.id,attr:I.attr,curves:I.curves});break}}}if(g.length===0)return[];let x="default",E=0;for(const I of i.fbxNode.nodes){if(I.name!=="AnimationStack")continue;const M=String(I.props[1]??"default");x=M.includes("\0")?M.split("\0")[0]:M;const C=I.nodes.find(T=>T.name==="Properties70");if(C){const T=C.nodes.find(B=>B.name==="P"&&String(B.props[0])==="LocalStop");if(T){const B=T.props[4],L=Number(B);L>0&&(E=L/jC)}}break}const S="ZYX",y=[];for(const I of g){const M=I.curves.x||I.curves.y||I.curves.z;if(!M)continue;const C=M.times.length,T=new Float32Array(M.times),B=p.get(I.modelId),L=Kt.sanitizeNodeName(I.modelName);if(I.attr==="T"){const O=new Float32Array(C*3);for(let R=0;R<C;R++)O[R*3]=(I.curves.x?.values[R]??0)*o,O[R*3+1]=(I.curves.y?.values[R]??0)*o,O[R*3+2]=(I.curves.z?.values[R]??0)*o;y.push({name:`${L}.position`,times:T,values:O,valuesPerKey:3}),E===0&&C>0&&(E=Math.max(E,T[C-1]))}else if(I.attr==="R"){const O=B?.eulerOrder??S;let R=null;if(B?.preRotation){const ne=B.preRotation;R=new Rn().setFromEuler(new zn(ne[0]*Fa,ne[1]*Fa,ne[2]*Fa,S))}let F=null;if(B?.postRotation){const ne=B.postRotation;F=new Rn().setFromEuler(new zn(ne[0]*Fa,ne[1]*Fa,ne[2]*Fa,S)).invert()}const j=new Float32Array(C*4),V=new zn,W=new Rn,te=new Rn;for(let ne=0;ne<C;ne++)V.set((I.curves.x?.values[ne]??0)*Fa,(I.curves.y?.values[ne]??0)*Fa,(I.curves.z?.values[ne]??0)*Fa,O),W.setFromEuler(V),R&&W.premultiply(R),F&&W.multiply(F),ne>0&&W.dot(te)<0&&(W.x=-W.x,W.y=-W.y,W.z=-W.z,W.w=-W.w),j[ne*4]=W.x,j[ne*4+1]=W.y,j[ne*4+2]=W.z,j[ne*4+3]=W.w,te.copy(W);y.push({name:`${L}.quaternion`,times:T,values:j,valuesPerKey:4}),E===0&&C>0&&(E=Math.max(E,T[C-1]))}else if(I.attr==="S"){const O=new Float32Array(C*3);for(let R=0;R<C;R++)O[R*3]=I.curves.x?.values[R]??1,O[R*3+1]=I.curves.y?.values[R]??1,O[R*3+2]=I.curves.z?.values[R]??1;y.push({name:`${L}.scale`,times:T,values:O,valuesPerKey:3})}}return y.length===0?[]:[{name:x,duration:E,tracks:y}]}const Ex={color:856343},Fu={antialias:!0,maxPixelRatio:2,toneMapping:"ACESFilmic",toneMappingExposure:2.5},Eo={fov:45,near:.01,far:1e3,position:{x:2,y:1.5,z:2}},iv={enableDamping:!0,dampingFactor:.08},bo={distanceMultiplier:1.5,offsetX:.7,offsetY:.5,offsetZ:.7,nearFraction:.01,farMultiplier:10},ji={ambient:{color:16777215,intensity:.5},key:{color:16777215,intensity:2.5,position:{x:5,y:8,z:5},castShadow:!1,shadowMapSize:1024},fill:{color:16777215,intensity:1.5,position:{x:-3,y:4,z:-5},castShadow:!1}},Ls={enabled:!0,unitSize:1,size:10,colorCenter:3159613,colorGrid:2172461},bT={color:8947865},I8=JSON.stringify([Ex,Fu,Eo,iv,bo,ji,Ls,bT]),T8={None:yr,Linear:kv,Reinhard:Qv,Cineon:zv,ACESFilmic:vf,AgX:Gv,Neutral:Hv},ap=N.forwardRef(function({sourceData:e,fileName:t,previewGroup:i,animationClips:a,animationSourceData:o,animationFileName:l,materialOverrides:u,className:f,onAnimationTick:h,onAnimationInfo:A,gridUnitSize:p=Ls.unitSize,showHumanScale:m=!1},g){const x=N.useRef(null),[E,S]=N.useState(!0),y=N.useRef(null);return N.useImperativeHandle(g,()=>({play(){const I=y.current;I?.action&&(I.action.paused=!1,I.playing=!0,I.clock.start())},pause(){const I=y.current;I?.action&&(I.action.paused=!0,I.playing=!1)},stop(){const I=y.current;I?.action&&(I.action.stop(),I.action.play(),I.action.paused=!0,I.action.time=0,I.playing=!1,I.mixer&&I.mixer.update(0))},setTime(I){const M=y.current;!M?.action||!M.mixer||(M.action.time=I,M.mixer.update(0))},setLoop(I){const M=y.current;M?.action&&(M.action.loop=I?FM:PM,M.action.clampWhenFinished=!I)},getTime(){return y.current?.action?.time??0},getDuration(){return y.current?.action?.getClip().duration??0},isPlaying(){return y.current?.playing??!1},getClipNames(){return y.current?.clips.map(I=>I.name)??[]},setClip(I){const M=y.current;if(!M?.mixer)return;const C=M.clips.find(T=>T.name===I);C&&(M.action&&M.action.stop(),M.action=M.mixer.clipAction(C),M.action.play(),M.action.paused=!M.playing,A?.(M.clips.map(T=>T.name),C.duration))}})),N.useEffect(()=>{const I=x.current;if(!I)return;S(!0);const M=I.clientWidth,C=I.clientHeight,T=new dx({antialias:Fu.antialias,alpha:!0});T.setSize(M,C),T.setPixelRatio(Math.min(window.devicePixelRatio,Fu.maxPixelRatio)),T.setClearColor(Ex.color,1),T.toneMapping=T8[Fu.toneMapping]??vf,T.toneMappingExposure=Fu.toneMappingExposure,T.shadowMap.enabled=!0,T.shadowMap.type=TM,I.appendChild(T.domElement);const B=new tx,L=new Mi(Eo.fov,M/C,Eo.near,Eo.far);L.position.set(Eo.position.x,Eo.position.y,Eo.position.z);const O=new oT(L,T.domElement);O.enableDamping=iv.enableDamping,O.dampingFactor=iv.dampingFactor,B.add(new cx(ji.ambient.color,ji.ambient.intensity));const R=new uf(ji.key.color,ji.key.intensity);R.position.set(ji.key.position.x,ji.key.position.y,ji.key.position.z),R.castShadow=ji.key.castShadow,B.add(R);const F=new uf(ji.fill.color,ji.fill.intensity);F.position.set(ji.fill.position.x,ji.fill.position.y,ji.fill.position.z),B.add(F);const j=Ls.enabled?qC(p):null;j&&B.add(j);const V=m?YC(p):null;V&&B.add(V);const W=new ck;y.current={renderer:T,scene:B,camera:L,controls:O,mixer:null,clock:W,action:null,clips:[],gridHelper:j,humanScaleRef:V,frameId:0,playing:!1};function te(){y.current.frameId=requestAnimationFrame(te);const ee=y.current,q=ee.clock.getDelta();ee.mixer&&ee.playing&&ee.mixer.update(q),O.update(),T.render(B,L),ee.action&&h&&h(ee.action.time,ee.action.getClip().duration)}te();const ne=new ResizeObserver(ee=>{for(const q of ee){const{width:Q,height:re}=q.contentRect;Q===0||re===0||(L.aspect=Q/re,L.updateProjectionMatrix(),T.setSize(Q,re))}});ne.observe(I);let k=!1,X=null;const Y=requestAnimationFrame(()=>{X=window.setTimeout(()=>{const ee=y.current;if(!(!ee||k))try{let q=null;if(i){if(q=i,B.add(q),XC(L,O,q),u&&u.length>0){const Q=[];q.traverse(re=>{re instanceof Nn&&Q.push(re)});for(const re of u){const ue=Q[0];if(!ue)continue;const xe=Array.isArray(ue.material)?ue.material:[ue.material],Me=re.subMeshIndex;if(Me<xe.length){const se=new Ro({color:16777215,roughness:.5,metalness:0});$0(se,re.properties);const Ae=xe[Me];xe[Me]=se,Array.isArray(ue.material)?ue.material=xe:ue.material=se,Ae.dispose()}}}}else if(e&&t){const Q=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);if(t.split(".").pop()?.toLowerCase()==="fbx"&&(q=new $H().parse(Q,""),q.traverse(xe=>{xe instanceof Nn&&(xe.castShadow=!0,xe.receiveShadow=!0,(!xe.material||Array.isArray(xe.material)&&xe.material.length===0)&&(xe.material=new Ro({color:bT.color})))}),B.add(q),XC(L,O,q),u&&u.length>0)){const xe=[];q.traverse(Me=>{Me instanceof Nn&&xe.push(Me)});for(const Me of u){const se=xe[Me.subMeshIndex];if(!se)continue;const Ae=new Ro({color:16777215,roughness:.5,metalness:0});$0(Ae,Me.properties);const Qe=se.material;se.material=Ae,Array.isArray(Qe)?Qe.forEach(We=>We.dispose()):Qe.dispose()}}}if(q){let Q=[];if(a&&a.length>0?Q=i?a:w8(a,q):i||(Q=q.animations??[]),Q.length>0){const re=new Set;q.traverse(xe=>{xe.name&&re.add(xe.name)});const ue=Q.map(xe=>{const Me=xe.tracks.filter(se=>{const Ae=se.name.split(".")[0];return re.has(Ae)});return new Uo(xe.name,xe.duration,Me)}).filter(xe=>xe.tracks.length>0);ue.length>0&&(ee.clips=ue,ee.mixer=new Ek(q),ee.action=ee.mixer.clipAction(ue[0]),ee.action.play(),ee.playing=!0,ee.clock.start(),A?.(ue.map(xe=>xe.name),ue[0].duration))}}}catch(q){console.error("Failed to load model for preview:",q)}finally{k||S(!1)}},0)});return()=>{const ee=performance.now();k=!0,cancelAnimationFrame(Y),X!==null&&clearTimeout(X),ne.disconnect(),cancelAnimationFrame(y.current?.frameId??0),O.dispose(),y.current?.mixer?.stopAllAction(),y.current?.gridHelper&&(B.remove(y.current.gridHelper),yh(y.current.gridHelper),y.current.gridHelper=null),y.current?.humanScaleRef&&(B.remove(y.current.humanScaleRef),yh(y.current.humanScaleRef),y.current.humanScaleRef=null),T.dispose(),B.traverse(q=>{(q instanceof Nn||q instanceof Ip||q instanceof ax)&&(q.geometry.dispose(),Array.isArray(q.material)?q.material.forEach(Q=>Q.dispose()):q.material.dispose())}),I.contains(T.domElement)&&I.removeChild(T.domElement),y.current=null,console.log(`[MeshViewport] cleanup: ${(performance.now()-ee).toFixed(1)}ms`)}},[e,t,i,a,o,l,u,I8]),N.useEffect(()=>{const I=y.current;I&&(Ls.enabled&&(I.gridHelper&&(I.scene.remove(I.gridHelper),yh(I.gridHelper)),I.gridHelper=qC(p),I.scene.add(I.gridHelper)),m?I.humanScaleRef?CT(I.humanScaleRef,p):(I.humanScaleRef=YC(p),I.scene.add(I.humanScaleRef)):I.humanScaleRef&&(I.scene.remove(I.humanScaleRef),yh(I.humanScaleRef),I.humanScaleRef=null))},[p,m]),b.jsx("div",{ref:x,className:`relative ${f??""}`,style:{minHeight:300},children:E&&b.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-background/70",children:b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-card px-4 py-2 shadow-lg",children:[b.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border-2 border-primary border-t-transparent"}),b.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading mesh preview..."})]})})})});function XC(n,e,t){const i=new Go().setFromObject(t),a=i.getSize(new he),o=i.getCenter(new he),l=Math.max(a.x,a.y,a.z),u=n.fov*(Math.PI/180),f=l/2/Math.tan(u/2)*bo.distanceMultiplier;n.position.set(o.x+f*bo.offsetX,o.y+f*bo.offsetY,o.z+f*bo.offsetZ),e.target.copy(o),n.near=f*bo.nearFraction,n.far=f*bo.farMultiplier,n.updateProjectionMatrix(),e.update()}function ST(n){return typeof n!="number"||!Number.isFinite(n)||n<=0?Ls.unitSize:Math.max(.05,n)}function qC(n){const e=ST(n),t=Math.max(e,Ls.size*.5),a=Math.max(1,Math.ceil(t/e))*2,o=a*e;return new iI(o,a,Ls.colorCenter,Ls.colorGrid)}function YC(n){const e=new Qa;e.name="human-scale-reference";const t=new Ro({color:8316807,roughness:.55,metalness:.05}),i=new Cp({color:8316807,transparent:!0,opacity:.35,side:Ur}),a=new Nn(new zu(.07,.08,.9,10),t);a.position.set(-.1,.45,0),e.add(a);const o=new Nn(new zu(.07,.08,.9,10),t);o.position.set(.1,.45,0),e.add(o);const l=new Nn(new zu(.16,.18,.75,12),t);l.position.set(0,1.275,0),e.add(l);const u=new Nn(new Bp(.175,16,12),t);u.position.set(0,1.825,0),e.add(u);const f=new Nn(new ox(.2,.27,24),i);return f.rotation.x=-Math.PI*.5,f.position.y=.01,e.add(f),CT(e,n),e}function CT(n,e){const t=ST(e);n.position.set(Math.max(1,t*1.5),0,0)}function yh(n){const e=new Set;n.traverse(t=>{if(t instanceof Nn||t instanceof Ip||t instanceof ax){t.geometry.dispose();const i=Array.isArray(t.material)?t.material:[t.material];for(const a of i)e.has(a)||(a.dispose(),e.add(a))}})}function sp({viewportRef:n,className:e}){const[t,i]=N.useState(!0),[a,o]=N.useState(!0),[l,u]=N.useState(0),[f,h]=N.useState(0),[A,p]=N.useState([]),[m,g]=N.useState("");N.useEffect(()=>{let C=0;function T(){const B=n.current;if(B){u(B.getTime());const L=B.getDuration();L>0&&L!==f&&h(L)}C=requestAnimationFrame(T)}return T(),()=>cancelAnimationFrame(C)},[n,f]),N.useEffect(()=>{const C=n.current;if(!C)return;const T=C.getClipNames();T.length>0&&(p(T),g(T[0]),h(C.getDuration()))},[n]);const x=N.useCallback(()=>{const C=n.current;C&&(t?(C.pause(),i(!1)):(C.play(),i(!0)))},[n,t]),E=N.useCallback(()=>{n.current?.stop(),i(!1),u(0)},[n]),S=N.useCallback(()=>{const C=!a;n.current?.setLoop(C),o(C)},[n,a]),y=N.useCallback(C=>{const T=parseFloat(C.target.value);n.current?.setTime(T),u(T)},[n]),I=N.useCallback(C=>{const T=C.target.value;n.current?.setClip(T),g(T),i(!0)},[n]);if(A.length===0)return null;const M=C=>C.toFixed(2);return b.jsxs("div",{className:nn("flex items-center gap-2 border-t border-border bg-card px-2 h-[52px] w-full rounded-xl",e),children:[b.jsx(Ei,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:x,children:t?b.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:[b.jsx("rect",{x:"3",y:"2",width:"3",height:"10",rx:"0.5"}),b.jsx("rect",{x:"8",y:"2",width:"3",height:"10",rx:"0.5"})]}):b.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:b.jsx("path",{d:"M3 1.5v11l9-5.5z"})})}),b.jsx(Ei,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:E,children:b.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:b.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"})})}),b.jsx(Ei,{variant:"ghost",size:"sm",className:nn("h-7 w-7 p-0",a&&"text-blue-400"),onClick:S,children:b.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[b.jsx("path",{d:"M2 7a5 5 0 0 1 9-3m1 3a5 5 0 0 1-9 3"}),b.jsx("path",{d:"M11 2v3h-3M3 12V9h3"})]})}),b.jsxs("span",{className:"min-w-[80px] text-center font-mono text-[11px] text-muted-foreground",children:[M(l)," / ",M(f)]}),b.jsx("input",{type:"range",min:0,max:f,step:.01,value:l,onChange:y,className:"h-1 flex-1 cursor-pointer accent-blue-400"}),A.length>1&&b.jsx("select",{value:m,onChange:I,className:"h-7 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:A.map(C=>b.jsx("option",{value:C,children:C},C))})]})}const rv=128,B8=64,R8=64,D8=128,KC=64,N8=64,JC=32,ZC=32,L8=64;class wT{view;pos;constructor(e,t=0){e instanceof Uint8Array?this.view=new DataView(e.buffer,e.byteOffset,e.byteLength):this.view=new DataView(e),this.pos=t}readUint32(){const e=this.view.getUint32(this.pos,!0);return this.pos+=4,e}readInt32(){const e=this.view.getInt32(this.pos,!0);return this.pos+=4,e}readUint64(){const e=this.view.getBigUint64(this.pos,!0);return this.pos+=8,e}readUint64AsNumber(){return Number(this.readUint64())}readFloat32(){const e=this.view.getFloat32(this.pos,!0);return this.pos+=4,e}readFixedString(e){const t=new Uint8Array(this.view.buffer,this.view.byteOffset+this.pos,e);this.pos+=e;const i=t.indexOf(0);return new TextDecoder().decode(t.subarray(0,i>=0?i:e))}readBytes(e){const t=new Uint8Array(this.view.buffer,this.view.byteOffset+this.pos,e);return this.pos+=e,t.slice()}seek(e){this.pos=e}tell(){return this.pos}get remaining(){return this.view.byteLength-this.pos}}function U8(n){return{name:n.readFixedString(B8),parentIndex:n.readInt32(),position:[n.readFloat32(),n.readFloat32(),n.readFloat32()],rotation:[n.readFloat32(),n.readFloat32(),n.readFloat32(),n.readFloat32()],scale:[n.readFloat32(),n.readFloat32(),n.readFloat32()],meshCount:n.readUint32(),firstMeshIndex:n.readUint32()}}function P8(n){return{fieldName:n.readFixedString(KC),value:[n.readFloat32(),n.readFloat32(),n.readFloat32(),n.readFloat32()],textureId:n.readFixedString(KC)}}function F8(n){return{name:n.readFixedString(R8),schemaId:n.readFixedString(D8),propertyCount:n.readUint32(),properties:[]}}function O8(n){return{trackName:n.readFixedString(L8),keyframeCount:n.readUint32(),valuesPerKey:n.readUint32(),timesOffset:n.readUint64AsNumber(),valuesOffset:n.readUint64AsNumber()}}function k8(n){const e=new wT(n),t=e.readFixedString(rv),i=e.readFixedString(rv),a=e.readUint32(),o=e.readFloat32(),l=e.readUint32(),u=[];for(let f=0;f<l;f++)u.push(O8(e));return{stringId:t,targetMeshId:i,metadataVersion:a,duration:o,trackCount:l,tracks:u}}function Q8(n){return{vertexCount:n.readUint32(),indexCount:n.readUint32(),hasNormals:n.readUint32(),hasUvs:n.readUint32(),vertexBufferOffset:n.readUint64AsNumber(),vertexBufferSize:n.readUint64AsNumber(),indexBufferOffset:n.readUint64AsNumber(),indexBufferSize:n.readUint64AsNumber(),weightsOffset:n.readUint64AsNumber(),weightsSize:n.readUint64AsNumber(),materialIndex:n.readUint32(),_padding:n.readUint32()}}function z8(n){const e=n.readFixedString(N8),t=n.readInt32(),i=[];for(let a=0;a<16;a++)i.push(n.readFloat32());return{name:e,parentIndex:t,offsetMatrix:i}}function G8(n){const e=new wT(n),t=e.readUint32(),i=e.readUint32(),a=e.readUint32(),o=e.readUint32(),l=e.readFixedString(rv),u=[];for(let g=0;g<t;g++)u.push(Q8(e));const f=[];for(let g=0;g<i;g++)f.push(F8(e));const h=[];for(let g=0;g<a;g++)h.push(U8(e));const A=h.reduce((g,x)=>g+x.meshCount,0),p=[];for(let g=0;g<A;g++)p.push(e.readUint32());for(const g of f)for(let x=0;x<g.propertyCount;x++)g.properties.push(P8(e));const m=[];for(let g=0;g<o;g++)m.push(z8(e));return{meshGeometryCount:t,materialCount:i,nodeCount:a,boneCount:o,stringId:l,geometries:u,materials:f,nodes:h,meshIndices:p,bones:m}}function MT(n,e){const t=G8(e),i=new DataView(n.buffer,n.byteOffset,n.byteLength),a=n.byteLength,o=t.geometries.slice().filter(Y=>{if(Y.vertexCount===0)return!1;const ee=Y.vertexBufferOffset+Y.vertexCount*ZC,q=Y.indexBufferOffset+Y.indexCount*4,Q=Y.weightsOffset+Y.vertexCount*JC;return ee>a||q>a||Q>a?(console.warn(`[skinned-preview] Geometry out of bounds (data=${a}, vertEnd=${ee}, idxEnd=${q}, wEnd=${Q}), skipping`),!1):!0}).sort((Y,ee)=>Y.vertexBufferOffset-ee.vertexBufferOffset),l=o.reduce((Y,ee)=>Y+ee.vertexCount,0),u=o.reduce((Y,ee)=>Y+ee.indexCount,0),f=new Float32Array(l*3),h=new Float32Array(l*3),A=new Float32Array(l*2),p=new Uint16Array(l*4),m=new Float32Array(l*4),g=new Uint32Array(u);let x=0,E=0;const S=ZC/4,y=JC/4;for(const Y of o){for(let ee=0;ee<Y.vertexCount;ee++){const q=Y.vertexBufferOffset+ee*S*4,Q=x+ee;f[Q*3]=i.getFloat32(q,!0),f[Q*3+1]=i.getFloat32(q+4,!0),f[Q*3+2]=i.getFloat32(q+8,!0),h[Q*3]=i.getFloat32(q+12,!0),h[Q*3+1]=i.getFloat32(q+16,!0),h[Q*3+2]=i.getFloat32(q+20,!0),A[Q*2]=i.getFloat32(q+24,!0),A[Q*2+1]=i.getFloat32(q+28,!0);const re=Y.weightsOffset+ee*y*4;for(let ue=0;ue<4;ue++)p[Q*4+ue]=i.getUint32(re+ue*4,!0),m[Q*4+ue]=i.getFloat32(re+16+ue*4,!0)}for(let ee=0;ee<Y.indexCount;ee++)g[E+ee]=i.getUint32(Y.indexBufferOffset+ee*4,!0)+x;x+=Y.vertexCount,E+=Y.indexCount}const I=new fi;I.setAttribute("position",new Pi(f,3)),I.setAttribute("normal",new Pi(h,3)),I.setAttribute("uv",new Pi(A,2)),I.setAttribute("skinIndex",new wp(p,4)),I.setAttribute("skinWeight",new Pi(m,4)),I.setIndex(new Pi(g,1));let M=0;for(const Y of o)I.addGroup(M,Y.indexCount,Math.min(Y.materialIndex,Math.max(t.materialCount-1,0))),M+=Y.indexCount;let C=!1;for(let Y=0;Y<f.length;Y++)Number.isFinite(f[Y])||(C=!0,f[Y]=0);C&&console.warn("[skinned-preview] NaN values in position data — replaced with 0"),I.computeBoundingBox(),I.computeBoundingSphere();const T=[];for(let Y=0;Y<t.materialCount;Y++){const ee=t.materials[Y],q=new Ro({side:Ur,name:ee.name||`Material_${Y}`,color:new Ct(.8,.8,.8),metalness:0,roughness:1});for(const Q of ee.properties){const re=Q.fieldName.toLowerCase();re.includes("color")||re.includes("tint")?q.color.setRGB(Q.value[0],Q.value[1],Q.value[2]):re==="metallic"?q.metalness=Q.value[0]:re==="roughness"?q.roughness=Q.value[0]:re==="alphatest"&&Q.value[0]>0&&(q.alphaTest=.5,q.transparent=!0)}T.push(q)}T.length===0&&T.push(new Ro({color:13421772,roughness:1}));const B=[],L=[],O=[],R=[];for(const Y of t.bones){const ee=new vt;ee.fromArray(Y.offsetMatrix);const q=new tp;q.name=Kt.sanitizeNodeName(Y.name),B.push(q),L.push(Y.parentIndex),O.push(ee),R.push(ee.clone().invert())}for(let Y=0;Y<B.length;Y++){const ee=L[Y];ee>=0&&ee<B.length&&ee!==Y&&B[ee].add(B[Y])}const F=new he,j=new Rn,V=new he;for(let Y=0;Y<B.length;Y++){const ee=R[Y],q=L[Y];if(q<0||q>=R.length)ee.decompose(F,j,V);else{const Q=new vt().copy(R[q]).invert();new vt().multiplyMatrices(Q,ee).decompose(F,j,V)}B[Y].position.copy(F),B[Y].quaternion.copy(j),B[Y].scale.set(1,1,1),B[Y].updateMatrix()}const W=B.filter((Y,ee)=>L[ee]<0),te=new Mp(B,O),ne=new qM(I,T);ne.frustumCulled=!1,ne.castShadow=!0,ne.receiveShadow=!0;const k=new Qa;k.name="BoneContainer",W.forEach(Y=>k.add(Y));const X=new Qa;return X.name=t.stringId||"SkinnedMesh",X.add(k),X.add(ne),X.updateMatrixWorld(!0),te.calculateInverses(),ne.bind(te,ne.matrixWorld),ne.normalizeSkinWeights(),X}function av(n,e){const t=k8(e),i=new DataView(n.buffer,n.byteOffset,n.byteLength),a=[];for(const o of t.tracks){if(o.trackName.endsWith(".scale"))continue;const l=new Float32Array(o.keyframeCount);for(let h=0;h<o.keyframeCount;h++)l[h]=i.getFloat32(o.timesOffset+h*4,!0);const u=o.keyframeCount*o.valuesPerKey,f=new Float32Array(u);for(let h=0;h<u;h++)f[h]=i.getFloat32(o.valuesOffset+h*4,!0);o.trackName.endsWith(".quaternion")?a.push(new aa(o.trackName,Array.from(l),Array.from(f))):a.push(new ks(o.trackName,Array.from(l),Array.from(f)))}return new Uo(t.stringId||"default",t.duration,a)}function H8({asset:n}){return b.jsx("div",{className:"flex h-full w-full items-center justify-center overflow-hidden p-6",children:n.previewUrl&&b.jsx("img",{className:"checkerboard h-full w-full rounded-lg border border-border object-contain",src:n.previewUrl,alt:n.fileName})})}function $C(n){if(!isFinite(n))return"0:00";const e=Math.floor(n/60),t=Math.floor(n%60);return`${e}:${t.toString().padStart(2,"0")}`}function V8({volume:n,muted:e}){return e||n===0?b.jsx(pP,{className:"size-4"}):n<.5?b.jsx(uP,{className:"size-4"}):b.jsx(dP,{className:"size-4"})}function ew(n,e){const t=N.useRef(!1),i=N.useCallback(u=>{const f=n.current?.getBoundingClientRect();return!f||f.width===0?0:Math.max(0,Math.min(1,(u.clientX-f.left)/f.width))},[n]),a=N.useCallback(u=>{u.currentTarget.setPointerCapture(u.pointerId),t.current=!0,e(i(u))},[i,e]),o=N.useCallback(u=>{t.current&&e(i(u))},[i,e]),l=N.useCallback(()=>{t.current=!1},[]);return{onPointerDown:a,onPointerMove:o,onPointerUp:l}}let s0=1,Eh=!1;const j8=[.25,.5,1,2];let tw=1,nw=!1;function W8(n){return`${n} ${n===1?"meter":"meters"}`}function IT(){const[n,e]=N.useState(tw),[t,i]=N.useState(nw),a=N.useCallback(l=>{!Number.isFinite(l)||l<=0||(tw=l,e(l))},[]),o=N.useCallback(l=>{nw=l,i(l)},[]);return{gridUnitSize:n,setGridUnitSize:a,showHumanScale:t,setShowHumanScale:o}}function op({gridUnitSize:n,onGridUnitSizeChange:e,showHumanScale:t,onShowHumanScaleChange:i}){return b.jsxs("div",{className:"absolute left-3 top-3 z-20 flex items-center gap-2 rounded-md border border-border/70 bg-background/85 p-2 shadow-sm backdrop-blur-sm",children:[b.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Scale (meters)"}),b.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[b.jsx("span",{children:"Grid"}),b.jsx("select",{className:"h-7 rounded-md border border-input bg-background px-2 text-xs text-foreground outline-none focus-visible:border-ring",value:String(n),onChange:a=>e(Number(a.target.value)),children:j8.map(a=>b.jsx("option",{value:a,children:W8(a)},a))})]}),b.jsxs(Ei,{variant:t?"default":"outline",size:"xs",className:"h-7 min-w-[118px] justify-between",onClick:()=>i(!t),"aria-pressed":t,children:[b.jsx("span",{children:"2m Human"}),b.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wide",children:[b.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${t?"bg-emerald-300":"bg-muted-foreground/50"}`}),t?"On":"Off"]})]})]})}function X8({asset:n}){const e=N.useRef(null),t=N.useRef(null),i=N.useRef(null),a=N.useRef(0),[o,l]=N.useState(!1),[u,f]=N.useState(0),[h,A]=N.useState(0),[p,m]=N.useState(s0),[g,x]=N.useState(Eh);N.useEffect(()=>{l(!1),f(0),A(0);const B=e.current;B&&(B.volume=s0,B.muted=Eh)},[n.previewUrl]),N.useEffect(()=>{if(!o)return;const B=()=>{const L=e.current;L&&f(L.currentTime),a.current=requestAnimationFrame(B)};return a.current=requestAnimationFrame(B),()=>cancelAnimationFrame(a.current)},[o]);const E=N.useCallback(()=>{const B=e.current;B&&(B.paused?(B.play().catch(L=>{console.warn("[AudioPreview] play failed:",L),l(!1)}),l(!0)):(B.pause(),l(!1)))},[]),S=N.useCallback(()=>{const B=e.current;B&&(B.muted=!B.muted,Eh=B.muted,x(B.muted))},[]),y=N.useCallback(B=>{const L=e.current;!L||!isFinite(L.duration)||(L.currentTime=B*L.duration,f(L.currentTime))},[]),I=N.useCallback(B=>{const L=e.current;L&&(L.volume=B,s0=B,m(B),B>0&&L.muted&&(L.muted=!1,Eh=!1,x(!1)))},[]),M=ew(t,y),C=ew(i,I),T=h>0?u/h*100:0;return b.jsxs("div",{className:"flex h-full items-center justify-center p-6",children:[b.jsx("audio",{ref:e,src:n.previewUrl,preload:"auto",onLoadedMetadata:()=>A(e.current?.duration??0),onEnded:()=>l(!1)},n.previewUrl),b.jsxs("div",{className:"flex w-full max-w-lg items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 shadow-sm",children:[b.jsx(Ei,{variant:"ghost",size:"icon-sm",className:"shrink-0",onClick:E,children:o?b.jsx(nP,{className:"size-4"}):b.jsx(rP,{className:"size-4"})}),b.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:$C(u)}),b.jsx("div",{ref:t,className:"relative flex-1 cursor-pointer py-2 select-none",...M,children:b.jsx("div",{className:"h-1 overflow-hidden rounded-full bg-muted",children:b.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${T}%`}})})}),b.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:$C(h)}),b.jsx(Ei,{variant:"ghost",size:"icon-sm",className:"shrink-0",onClick:S,children:b.jsx(V8,{volume:p,muted:g})}),b.jsx("div",{ref:i,className:"relative w-16 shrink-0 cursor-pointer py-2 select-none",...C,children:b.jsx("div",{className:"h-1 overflow-hidden rounded-full bg-muted",children:b.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${(g?0:p)*100}%`}})})})]})]})}function q8({asset:n}){const{state:e}=yn(),t=wn.getSource(n.id),i=N.useRef(null),[a,o]=N.useState(!1),{gridUnitSize:l,setGridUnitSize:u,showHumanScale:f,setShowHumanScale:h}=IT(),A=N.useMemo(()=>YI(n,e.assets),[n.settings.materialOverrides,e.assets]),p=n.type===at.SkinnedMesh,m=N.useMemo(()=>{if(!p)return null;const x=wn.getProcessed(n.id),E=wn.getProcessed(`${n.id}:skinnedMeta`);if(!x||!E)return null;try{return MT(x,E)}catch(S){return console.error("[MeshPreview] Failed to build skinned mesh from processed data:",S),null}},[p,n.id,n.status]),g=N.useMemo(()=>{if(!p)return;const x=[],E=wn.getProcessed(`${n.id}:animCount`),S=E?E[0]:0;for(let y=0;y<S;y++){const I=wn.getProcessed(`${n.id}:anim:${y}`),M=wn.getProcessed(`${n.id}:animMeta:${y}`);if(!(!I||!M))try{x.push(av(I,M))}catch{}}return x.length>0?x:void 0},[p,n.id,n.status]);return p?m?b.jsxs("div",{className:"relative h-full",children:[b.jsx(op,{gridUnitSize:l,onGridUnitSizeChange:u,showHumanScale:f,onShowHumanScaleChange:h}),b.jsx(ap,{ref:i,previewGroup:m,animationClips:g,materialOverrides:A.length>0?A:void 0,gridUnitSize:l,showHumanScale:f,className:"h-full w-full",onAnimationInfo:x=>{o(x.length>0)}}),a&&b.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 pb-3",children:b.jsx(sp,{viewportRef:i})})]}):null:t?b.jsxs("div",{className:"relative h-full",children:[b.jsx(op,{gridUnitSize:l,onGridUnitSizeChange:u,showHumanScale:f,onShowHumanScaleChange:h}),b.jsx(ap,{ref:i,sourceData:t,fileName:n.fileName,materialOverrides:A.length>0?A:void 0,gridUnitSize:l,showHumanScale:f,className:"h-full w-full",onAnimationInfo:x=>{o(x.length>0)}}),a&&b.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 pb-3",children:b.jsx(sp,{viewportRef:i})})]}):null}function Y8({asset:n}){const{state:e}=yn(),t=N.useRef(null),[i,a]=N.useState(!1),{gridUnitSize:o,setGridUnitSize:l,showHumanScale:u,setShowHumanScale:f}=IT(),h=wn.getSource(n.id),A=n.settings.targetMeshId,p=A?e.assets.find(C=>C.id===A):null,m=p?.type===at.SkinnedMesh,g=N.useMemo(()=>{if(!m||!p)return null;const C=wn.getProcessed(p.id),T=wn.getProcessed(`${p.id}:skinnedMeta`);if(!C||!T)return null;try{return MT(C,T)}catch(B){return console.error("[AnimationClipPreview] Failed to build skinned mesh from processed data:",B),null}},[m,p?.id,p?.status]),x=N.useMemo(()=>{const C=[],T=wn.getProcessed(n.id),B=wn.getProcessed(`${n.id}:animMeta`);if(T&&B)try{C.push(av(T,B))}catch{}const L=wn.getProcessed(`${n.id}:animCount`),O=L?L[0]:1;for(let R=1;R<O;R++){const F=wn.getProcessed(`${n.id}:anim:${R}`),j=wn.getProcessed(`${n.id}:animMeta:${R}`);if(!(!F||!j))try{C.push(av(F,j))}catch{}}return C},[n.id,n.status]),E=N.useMemo(()=>x.length>0?x:h?C8(h):[],[x,h]),S=N.useMemo(()=>p?YI(p,e.assets):[],[p,e.assets]);if(E.length===0)return null;if(g)return b.jsxs("div",{className:"relative h-full",children:[b.jsx(op,{gridUnitSize:o,onGridUnitSizeChange:l,showHumanScale:u,onShowHumanScaleChange:f}),b.jsx(ap,{ref:t,previewGroup:g,animationClips:E,materialOverrides:S.length>0?S:void 0,gridUnitSize:o,showHumanScale:u,className:"h-full w-full",onAnimationInfo:C=>{a(C.length>0)}}),i&&b.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 pb-3",children:b.jsx(sp,{viewportRef:t})})]});const I=(p?wn.getSource(p.id):null)??h,M=p?p.fileName:n.fileName;return I?b.jsxs("div",{className:"relative h-full",children:[b.jsx(op,{gridUnitSize:o,onGridUnitSizeChange:l,showHumanScale:u,onShowHumanScaleChange:f}),b.jsx(ap,{ref:t,sourceData:I,fileName:M,animationClips:E,materialOverrides:S.length>0?S:void 0,gridUnitSize:o,showHumanScale:u,className:"h-full w-full",onAnimationInfo:C=>{a(C.length>0)}}),i&&b.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 pb-3",children:b.jsx(sp,{viewportRef:t})})]}):null}let Io=null;function K8(){if(Io)return Io;const n=new dx({antialias:!0,alpha:!0});n.setPixelRatio(Math.min(window.devicePixelRatio,2)),n.setClearColor(Ex.color,1),n.toneMapping=vf,n.toneMappingExposure=1;const e=new tx;e.add(new cx(16777215,.4));const t=new uf(16777215,1.2);t.position.set(3,4,5),e.add(t);const i=new uf(16777215,.3);i.position.set(-2,1,-3),e.add(i);const a=new Ro({color:16777215,roughness:.5,metalness:0});e.add(new Nn(new Bp(1,64,64),a)),e.add(new iI(6,10,3355443,2236962));const o=new Mi(45,1,.1,100);return o.position.set(0,0,3),Io={renderer:n,scene:e,camera:o,material:a},Io}function J8({asset:n}){const e=N.useRef(null),t=N.useRef(0),i=n.settings.materialConfig,a=N.useMemo(()=>JSON.stringify(i.properties.map(o=>[o.previewFlag,o.value,o.textureAssetId])),[i.properties]);return N.useEffect(()=>{const o=performance.now(),l=e.current;if(!l)return;const{renderer:u,scene:f,camera:h}=K8();console.log(`[MatPreview] ensureScene: ${(performance.now()-o).toFixed(1)}ms (cached: ${Io!==null})`);const A=performance.now(),p=l.clientWidth,m=l.clientHeight;u.setSize(p,m),h.aspect=p/m,h.updateProjectionMatrix(),l.appendChild(u.domElement),console.log(`[MatPreview] attach+resize: ${(performance.now()-A).toFixed(1)}ms`);const g=performance.now(),x=new oT(h,u.domElement);x.enableDamping=!0,console.log(`[MatPreview] controls: ${(performance.now()-g).toFixed(1)}ms`);function E(){t.current=requestAnimationFrame(E),x.update(),u.render(f,h)}E();const S=new ResizeObserver(y=>{for(const I of y){const{width:M,height:C}=I.contentRect;M===0||C===0||(h.aspect=M/C,h.updateProjectionMatrix(),u.setSize(M,C))}});return S.observe(l),console.log(`[MatPreview] mount total: ${(performance.now()-o).toFixed(1)}ms`),()=>{S.disconnect(),cancelAnimationFrame(t.current),x.dispose(),l.contains(u.domElement)&&l.removeChild(u.domElement)}},[]),N.useEffect(()=>{const o=performance.now();if(!Io)return;const l=Io.material;l.color.set(16777215),l.map=null,l.alphaTest=0,l.transparent=!1,l.opacity=1,$0(l,i.properties),console.log(`[MatPreview] applyProperties: ${(performance.now()-o).toFixed(1)}ms`)},[a]),b.jsx("div",{ref:e,className:"h-full w-full",style:{minHeight:200}})}function Z8(){const{state:n}=yn(),e=n.selectedAssetIds.length>1,t=e?void 0:n.assets.find(o=>o.id===IM(n)),i=t&&t.status==="ready"&&t.type!==at.MaterialSchema,a=i?t.type===at.Texture2D||t.type===at.Audio?!!t.previewUrl:!!wn.getSource(t.id):!0;return b.jsxs("section",{className:"flex h-full flex-col bg-background",children:[b.jsxs("div",{className:"flex h-9 items-center gap-2 border-b border-border px-4",children:[b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Preview"}),t&&b.jsxs(b.Fragment,{children:[b.jsx(gc,{orientation:"vertical",className:"h-3.5!"}),b.jsx("span",{className:"truncate text-xs text-foreground",children:t.fileName}),b.jsx(Ef,{variant:t.status==="ready"?"default":"secondary",className:"text-[10px]",children:t.status})]})]}),b.jsxs("div",{className:"relative flex-1 min-h-0 overflow-hidden",children:[!t&&!e&&b.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select an asset to preview"}),e&&b.jsxs("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:[n.selectedAssetIds.length," assets selected"]}),t?.status==="error"&&!t.previewUrl&&b.jsx("div",{className:"flex h-full items-center justify-center px-6",children:b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:t.error})}),t&&t.status==="ready"&&t.type===at.Texture2D&&t.previewUrl&&b.jsx(H8,{asset:t}),t&&t.status==="ready"&&t.type===at.Audio&&t.previewUrl&&b.jsx(X8,{asset:t}),t&&t.status==="ready"&&(t.type===at.StaticMesh||t.type===at.SkinnedMesh)&&wn.getSource(t.id)&&b.jsx(q8,{asset:t}),t&&t.status==="ready"&&t.type===at.AnimationClip&&wn.getSource(t.id)&&b.jsx(Y8,{asset:t}),t&&t.type===at.MaterialSchema&&b.jsx(J8,{asset:t}),i&&!a&&b.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80",children:b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-card px-4 py-2 shadow-lg",children:[b.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border-2 border-primary border-t-transparent"}),b.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),(t?.status==="pending"||t?.status==="processing"||t?.status==="loading")&&b.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/60",children:b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-card px-4 py-2 shadow-lg",children:[b.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border-2 border-amber-400 border-t-transparent"}),b.jsx("span",{className:"text-sm text-amber-400",children:t.status==="pending"?"Queued...":t.status==="loading"?"Loading...":"Processing..."})]})})]})]})}const $8="modulepreload",e6=function(n){return"/"+n},iw={},t6=function(e,t,i){let a=Promise.resolve();if(t&&t.length>0){let f=function(h){return Promise.all(h.map(A=>Promise.resolve(A).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),u=l?.nonce||l?.getAttribute("nonce");a=f(t.map(h=>{if(h=e6(h),h in iw)return;iw[h]=!0;const A=h.endsWith(".css"),p=A?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${h}"]${p}`))return;const m=document.createElement("link");if(m.rel=A?"stylesheet":$8,A||(m.as="script"),m.crossOrigin="",m.href=h,u&&m.setAttribute("nonce",u),document.head.appendChild(m),A)return new Promise((g,x)=>{m.addEventListener("load",g),m.addEventListener("error",()=>x(new Error(`Unable to preload CSS for ${h}`)))})}))}function o(l){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=l,window.dispatchEvent(u),!u.defaultPrevented)throw l}return a.then(l=>{for(const u of l||[])u.status==="rejected"&&o(u.reason);return e().catch(o)})};function la({className:n,...e}){return b.jsx("div",{"data-slot":"card",className:nn("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",n),...e})}function ca({className:n,...e}){return b.jsx("div",{"data-slot":"card-content",className:nn("px-6",n),...e})}function n6({open:n,textures:e,materialPack:t,selectedId:i,onSelect:a,onClose:o}){const[l,u]=N.useState(""),f=N.useRef(null);N.useEffect(()=>{n&&(u(""),requestAnimationFrame(()=>f.current?.focus()))},[n]),N.useEffect(()=>{if(!n)return;function p(m){m.key==="Escape"&&o()}return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[n,o]);const h=N.useMemo(()=>{const p=l.toLowerCase();return e.filter(g=>p?g.fileName.toLowerCase().includes(p)||g.stringId.toLowerCase().includes(p):!0).sort((g,x)=>{const E=g.settings.pack===t?0:1,S=x.settings.pack===t?0:1;return E!==S?E-S:g.settings.pack!==x.settings.pack?g.settings.pack.localeCompare(x.settings.pack):g.fileName.localeCompare(x.fileName)})},[e,t,l]);if(!n)return null;function A(p){a(p),o()}return b.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onMouseDown:p=>{p.target===p.currentTarget&&o()},children:b.jsxs("div",{className:"flex w-[560px] max-h-[80vh] flex-col overflow-hidden rounded-xl border border-border bg-card shadow-2xl",children:[b.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[b.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Select Texture"}),b.jsx("button",{onClick:o,className:"rounded p-1 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:b.jsx(jb,{className:"size-4"})})]}),b.jsx("div",{className:"border-b border-border px-4 py-2",children:b.jsxs("div",{className:"relative",children:[b.jsx(sP,{className:"absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),b.jsx("input",{ref:f,type:"text",value:l,onChange:p=>u(p.target.value),placeholder:"Search textures…",className:"h-7 w-full rounded-md border border-border bg-background pl-7 pr-7 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),l&&b.jsx("button",{onClick:()=>u(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:b.jsx(jb,{className:"size-3.5"})})]})}),b.jsxs(xx,{className:"flex-1 min-h-0",children:[b.jsxs("div",{className:"grid grid-cols-4 gap-2 p-4",children:[b.jsxs("button",{onClick:()=>A(null),className:nn("group flex flex-col items-center gap-1.5 rounded-lg border p-2 transition-colors hover:bg-accent/50",i===null?"border-ring ring-1 ring-ring bg-accent/30":"border-border"),children:[b.jsx("div",{className:"flex aspect-square w-full items-center justify-center rounded-md bg-muted",children:b.jsx(QU,{className:"size-8 text-muted-foreground"})}),b.jsx("span",{className:"text-[10px] text-muted-foreground leading-tight",children:"No texture"})]}),h.map(p=>{const m=p.metadata,g=p.settings.pack===t,x=p.id===i;return b.jsxs("button",{onClick:()=>A(p.id),className:nn("group flex flex-col items-center gap-1.5 rounded-lg border p-2 transition-colors hover:bg-accent/50",x?"border-ring ring-1 ring-ring bg-accent/30":"border-border"),children:[b.jsxs("div",{className:"relative aspect-square w-full overflow-hidden rounded-md",children:[p.previewUrl?b.jsx("img",{src:p.previewUrl,alt:p.fileName,className:"checkerboard h-full w-full object-contain"}):b.jsx("div",{className:"flex h-full w-full items-center justify-center bg-muted text-[10px] text-muted-foreground",children:"No preview"}),b.jsx(Ef,{variant:g?"secondary":"outline",className:nn("absolute bottom-1 right-1 text-[9px] px-1 py-0 leading-tight max-w-[calc(100%-8px)] truncate",!g&&"border-amber-500/60 text-amber-600 dark:text-amber-400"),children:p.settings.pack})]}),b.jsxs("div",{className:"w-full min-w-0 text-center",children:[b.jsx("p",{className:"truncate text-[10px] leading-tight text-foreground",title:p.fileName,children:p.fileName}),m&&b.jsxs("p",{className:"text-[9px] text-muted-foreground",children:[m.width,"×",m.height]})]})]},p.id)})]}),h.length===0&&l&&b.jsxs("div",{className:"px-4 pb-4 text-center text-xs text-muted-foreground",children:['No textures matching "',l,'"']})]})]})})}function Oo(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function Vt({label:n,value:e}){return b.jsxs("div",{className:"flex items-center justify-between py-1",children:[b.jsx("span",{className:"text-xs text-muted-foreground",children:n}),b.jsx("span",{className:"font-mono text-xs text-foreground",children:e})]})}function qa({options:n,value:e,onChange:t}){return b.jsx("div",{className:"flex rounded-md border border-border overflow-hidden",children:n.map((i,a)=>b.jsx("button",{className:nn("flex-1 px-2 py-1 text-[11px] font-medium transition-colors",a>0&&"border-l border-border",i.value===e?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),onClick:()=>t(i.value),children:i.label},i.value))})}const Pp=[{label:"Static Mesh",value:at.StaticMesh},{label:"Skinned Mesh",value:at.SkinnedMesh},{label:"Animation",value:at.AnimationClip}];function o0(n){return n===at.StaticMesh||n===at.SkinnedMesh||n===at.AnimationClip}function i6({asset:n}){const{changeAssetType:e}=yn();return b.jsx(ai,{label:"Asset Type",children:b.jsx(qa,{options:Pp,value:n.type,onChange:t=>e(n.id,t)})})}function r6({asset:n}){const{state:e,updateAssetSettings:t}=yn(),i=e.assets.filter(a=>a.type===at.SkinnedMesh&&a.id!==n.id);return b.jsx(ai,{label:"Preview Mesh",children:i.length===0?b.jsx("p",{className:"text-[11px] text-muted-foreground",children:"No skinned meshes in project. Import one to preview this animation."}):b.jsxs("select",{value:n.settings.targetMeshId??"",onChange:a=>t(n.id,{targetMeshId:a.target.value||null}),className:"h-7 w-full rounded-md border border-border bg-background px-2 text-xs text-foreground",children:[b.jsx("option",{value:"",children:"None (skeleton only)"}),i.map(a=>b.jsx("option",{value:a.id,children:a.fileName},a.id))]})})}function a6({asset:n}){const{state:e,updateAssetSettings:t}=yn(),i=e.projectDir?.config.packs??[{name:"default"}],a=i.map(u=>u.name),o=n.settings.pack,l=a.includes(o)?o:a[0]??o;return N.useEffect(()=>{l!==o&&t(n.id,{pack:l})},[l,o,n.id,t]),b.jsx(ai,{label:"Pack",children:b.jsx("select",{className:"h-7 w-full rounded-md border border-border bg-background px-2 text-xs",value:l,onChange:u=>t(n.id,{pack:u.target.value}),children:i.map(u=>b.jsx("option",{value:u.name,children:u.name},u.name))})})}function s6({assets:n}){const{state:e,updateAssetSettings:t}=yn(),i=e.projectDir?.config.packs??[{name:"default"}],o=new Set(n.map(f=>f.settings.pack??"default")).size>1,l=o?"":n[0]?.settings.pack??"default";if(n.length===0)return null;function u(f){for(const h of n)h.settings.pack!==f&&t(h.id,{pack:f})}return b.jsx(ai,{label:"Pack",children:b.jsxs("select",{className:"h-7 w-full rounded-md border border-border bg-background px-2 text-xs",value:l,onChange:f=>u(f.target.value),children:[o&&b.jsx("option",{value:"",disabled:!0,children:"Mixed"}),i.map(f=>b.jsx("option",{value:f.name,children:f.name},f.name))]})})}function ai({label:n,children:e}){return b.jsxs("div",{className:"space-y-1.5",children:[b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:n}),e]})}function o6({asset:n}){const{state:e,dispatch:t}=yn(),[i,a]=N.useState(!1),[o,l]=N.useState(n.stringId),[u,f]=N.useState(""),h=N.useRef(null);N.useEffect(()=>{l(n.stringId),a(!1),f("")},[n.id,n.stringId]);function A(m){return e.assets.some(g=>g.id!==n.id&&g.stringId.toLowerCase()===m.toLowerCase())}function p(){const m=o.trim();if(m&&m!==n.stringId){if(A(m)){f(`"${m}" is already used by another asset`);return}t({type:"UPDATE_ASSET",id:n.id,updates:{stringId:m}}),e.projectDir&&t6(async()=>{const{assetSettingsToStowmeta:g,writeStowmeta:x}=await import("./stowmeta-io-DnPx8pX9.js");return{assetSettingsToStowmeta:g,writeStowmeta:x}},[]).then(({assetSettingsToStowmeta:g,writeStowmeta:x})=>{const E={...n,stringId:m},S=g(E);x(e.projectDir.srcArtDir,n.id,S)})}else l(n.stringId);a(!1),f("")}return b.jsx(ai,{label:"String ID",children:i?b.jsxs(b.Fragment,{children:[b.jsx(Po,{ref:h,value:o,onChange:m=>{l(m.target.value),f("")},onBlur:p,onKeyDown:m=>{m.key==="Enter"&&p(),m.key==="Escape"&&(l(n.stringId),a(!1),f(""))},className:nn("h-7 text-xs font-mono",u&&"border-red-500"),autoFocus:!0}),u&&b.jsx("p",{className:"mt-1 text-xs text-red-500",children:u})]}):b.jsxs("button",{className:"flex w-full items-center rounded-md border border-border bg-muted/50 px-2.5 py-1 text-left font-mono text-xs text-foreground transition-colors hover:bg-muted",onClick:()=>{a(!0)},children:[b.jsx("span",{className:"flex-1 truncate",children:n.stringId}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"shrink-0 text-muted-foreground",children:b.jsx("path",{d:"M8.5 1.5l2 2-7 7H1.5V8.5l7-7z",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]})})}const l6=[{label:"Full",value:Du.Full},{label:"Half",value:Du.Half},{label:"Quarter",value:Du.Quarter},{label:"Eighth",value:Du.Eighth}],c6=[{label:"Fastest",value:Gl.Fastest},{label:"Fast",value:Gl.Fast},{label:"Normal",value:Gl.Normal},{label:"High",value:Gl.High},{label:"Best",value:Gl.Best}];function u6({asset:n}){const{updateAssetSettings:e}=yn();return b.jsxs(b.Fragment,{children:[b.jsx(ai,{label:"Resize",children:b.jsx(qa,{options:l6,value:n.settings.resize,onChange:t=>e(n.id,{resize:t})})}),b.jsx(ai,{label:"KTX2 Quality",children:b.jsx(qa,{options:c6,value:n.settings.quality,onChange:t=>e(n.id,{quality:t})})})]})}const f6=[{label:"Fast",value:Nu.Fast},{label:"Balanced",value:Nu.Balanced},{label:"High",value:Nu.HighQuality},{label:"Maximum",value:Nu.MaximumQuality}];function d6({asset:n}){const{updateAssetSettings:e}=yn();return b.jsx(ai,{label:"Compression Quality",children:b.jsx(qa,{options:f6,value:n.settings.dracoQuality,onChange:t=>e(n.id,{dracoQuality:t})})})}const h6=[{label:"Lowest",value:Hl.Lowest},{label:"Low",value:Hl.Low},{label:"Medium",value:Hl.Medium},{label:"High",value:Hl.High},{label:"Best",value:Hl.Best}],p6=[{label:"Auto",value:Vl.Auto},{label:"48 kHz",value:Vl.Hz48000},{label:"44.1 kHz",value:Vl.Hz44100},{label:"22 kHz",value:Vl.Hz22050},{label:"11 kHz",value:Vl.Hz11025}];function A6({asset:n}){const{updateAssetSettings:e}=yn();return b.jsxs(b.Fragment,{children:[b.jsx(ai,{label:"AAC Quality",children:b.jsx(qa,{options:h6,value:n.settings.aacQuality,onChange:t=>e(n.id,{aacQuality:t})})}),b.jsx(ai,{label:"Sample Rate",children:b.jsx(qa,{options:p6,value:n.settings.audioSampleRate,onChange:t=>e(n.id,{audioSampleRate:t})})})]})}function m6({asset:n}){const{updateAssetSettings:e}=yn(),[t,i]=N.useState("");function a(){const l=t.trim().toLowerCase();if(!l||n.settings.tags.includes(l)){i("");return}e(n.id,{tags:[...n.settings.tags,l]}),i("")}function o(l){e(n.id,{tags:n.settings.tags.filter(u=>u!==l)})}return b.jsxs(ai,{label:"Tags",children:[n.settings.tags.length>0&&b.jsx("div",{className:"flex flex-wrap gap-1",children:n.settings.tags.map(l=>b.jsxs(Ef,{variant:"secondary",className:"gap-1 pr-1 text-[10px]",children:[l,b.jsx("button",{className:"rounded-full p-0.5 hover:bg-destructive hover:text-destructive-foreground transition-colors",onClick:()=>o(l),children:b.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",children:b.jsx("path",{d:"M2 2l4 4M6 2l-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]},l))}),b.jsxs("div",{className:"flex gap-1.5",children:[b.jsx(Po,{value:t,onChange:l=>i(l.target.value),onKeyDown:l=>{l.key==="Enter"&&a()},placeholder:"Add tag...",className:"h-7 flex-1 text-xs"}),b.jsx(Ei,{variant:"outline",size:"sm",className:"h-7 w-7 shrink-0 p-0",onClick:a,disabled:!t.trim(),children:b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:b.jsx("path",{d:"M6 2v8M2 6h8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}function g6({asset:n}){const e=n.metadata;return e?b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Dimensions",value:`${e.width} x ${e.height}`}),b.jsx(Vt,{label:"Channels",value:String(e.channels)}),b.jsx(Vt,{label:"Format",value:"RGBA (KTX2)"}),b.jsx(Vt,{label:"Source",value:Oo(n.sourceSize)}),n.processedSize>0&&b.jsx(Vt,{label:"Compressed",value:Oo(n.processedSize)})]})}):null}function v6({asset:n}){const e=n.metadata;return e?b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Sample Rate",value:`${e.sampleRate.toLocaleString()} Hz`}),b.jsx(Vt,{label:"Channels",value:String(e.channels)}),b.jsx(Vt,{label:"Duration",value:`${(e.durationMs/1e3).toFixed(2)}s`}),b.jsx(Vt,{label:"Source",value:Oo(n.sourceSize)}),n.processedSize>0&&b.jsx(Vt,{label:"Compressed",value:Oo(n.processedSize)})]})}):null}function x6({asset:n}){const e=n.metadata;if(!e)return null;const t=e.geometries.reduce((a,o)=>a+o.vertexCount,0),i=e.geometries.reduce((a,o)=>a+o.indexCount/3,0);return b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Sub-meshes",value:String(e.meshGeometryCount)}),b.jsx(Vt,{label:"Vertices",value:t.toLocaleString()}),b.jsx(Vt,{label:"Triangles",value:Math.floor(i).toLocaleString()}),b.jsx(Vt,{label:"Materials",value:String(e.materialCount)}),b.jsx(Vt,{label:"Source",value:Oo(n.sourceSize)}),n.processedSize>0&&b.jsx(Vt,{label:"Compressed",value:Oo(n.processedSize)})]})})}function _6(n,e){const t=n.map((a,o)=>({name:a.name,index:o,parentIndex:a.parentIndex,children:[],hasTrack:e?e.has(a.name):void 0})),i=[];for(let a=0;a<n.length;a++){const o=n[a].parentIndex;o<0||o>=n.length?i.push(t[a]):t[o].children.push(t[a])}return i}function TT({node:n,depth:e,expanded:t,onToggle:i}){const a=n.children.length>0,o=t.has(n.index),l=n.parentIndex<0,u=n.children.length===0,f=[`Index: ${n.index}`,`Parent: ${l?"None (root)":n.parentIndex}`,`Children: ${n.children.length}`,`Depth: ${e}`,n.hasTrack===!0?"Has animation tracks":n.hasTrack===!1?"No animation tracks":""].filter(Boolean).join(`
4066
- `);return b.jsxs(b.Fragment,{children:[b.jsxs("div",{className:"group flex items-center gap-1 py-0.5 hover:bg-muted/50 rounded-sm cursor-default select-none",style:{paddingLeft:e*14+4},title:f,children:[a?b.jsx("button",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground",onClick:()=>i(n.index),children:b.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:o?b.jsx("path",{d:"M2 4l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}):b.jsx("path",{d:"M4 2l3 3-3 3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}):b.jsx("span",{className:"h-4 w-4 shrink-0"}),b.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("shrink-0",l?"text-blue-400":"text-muted-foreground"),children:[b.jsx("circle",{cx:"3",cy:"3",r:"1.5",stroke:"currentColor",strokeWidth:"1"}),b.jsx("circle",{cx:"9",cy:"9",r:"1.5",stroke:"currentColor",strokeWidth:"1"}),b.jsx("line",{x1:"4.2",y1:"4.2",x2:"7.8",y2:"7.8",stroke:"currentColor",strokeWidth:"1"})]}),b.jsx("span",{className:nn("text-[11px] truncate flex-1",n.hasTrack===!0&&"text-green-400 font-medium",n.hasTrack===!1&&"text-muted-foreground",n.hasTrack===void 0&&"text-foreground"),children:n.name}),b.jsxs("span",{className:"text-[9px] font-mono text-muted-foreground/50 opacity-0 group-hover:opacity-100 transition-opacity shrink-0 mr-1",children:["#",n.index,a&&!u&&` (${n.children.length})`]})]}),a&&o&&n.children.map(h=>b.jsx(TT,{node:h,depth:e+1,expanded:t,onToggle:i},h.index))]})}function Fp(n){return n!==null&&typeof n=="object"&&"trackCount"in n}function y6({asset:n}){const[e,t]=N.useState(new Set),[i,a]=N.useState(!0),o=n.metadata,l=o?Fp(o):!1,u=o&&!l&&"bones"in o?o.bones:[],f=N.useMemo(()=>{if(n.type!==at.AnimationClip||l||u.length===0)return;const g=o;if(!g.bones)return;const x=new Set;for(const E of g.bones)x.add(E.name);return x},[n.type,o,l,u.length]),h=N.useMemo(()=>u.length>0?_6(u,f):[],[u,f]);if(!o||l||u.length===0)return null;function A(g){t(x=>{const E=new Set(x);return E.has(g)?E.delete(g):E.add(g),E})}function p(){const g=new Set;for(let x=0;x<u.length;x++)g.add(x);t(g)}function m(){t(new Set)}return b.jsxs("div",{className:"space-y-1.5",children:[b.jsxs("button",{className:"flex w-full items-center justify-between",onClick:()=>a(g=>!g),children:[b.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Bone Hierarchy (",u.length,")"]}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("text-muted-foreground transition-transform",!i&&"rotate-180"),children:b.jsx("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!i&&b.jsx(la,{children:b.jsxs(ca,{className:"p-2",children:[b.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[b.jsx("button",{className:"text-[10px] text-muted-foreground hover:text-foreground transition-colors",onClick:p,children:"Expand All"}),b.jsx("span",{className:"text-muted-foreground text-[10px]",children:"|"}),b.jsx("button",{className:"text-[10px] text-muted-foreground hover:text-foreground transition-colors",onClick:m,children:"Collapse All"}),b.jsx("span",{className:"text-muted-foreground text-[10px]",children:"|"}),b.jsx("span",{className:"text-[10px] text-blue-400",children:"● root"}),n.type===at.AnimationClip&&b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"text-muted-foreground text-[10px]",children:"|"}),b.jsx("span",{className:"text-[10px] text-green-400",children:"● animated"})]})]}),b.jsx("div",{className:"max-h-64 overflow-y-auto",children:h.map(g=>b.jsx(TT,{node:g,depth:0,expanded:e,onToggle:A},g.index))})]})})]})}function E6({asset:n}){const[e,t]=N.useState(!0),i=n.metadata;if(!i||!i.bones||i.bones.length===0)return null;const a=i.geometries.reduce((m,g)=>m+g.vertexCount,0),o=i.geometries.reduce((m,g)=>m+g.indexCount,0),l=i.bones.filter(m=>m.parentIndex<0),u=i.bones.filter((m,g)=>!i.bones.some(x=>x.parentIndex===g)),f=N.useMemo(()=>{const m=new Map;for(let g=0;g<i.bones.length;g++){let x=0,E=g;for(;i.bones[E].parentIndex>=0;)x++,E=i.bones[E].parentIndex;m.set(g,x)}return m},[i.bones]),h=Math.max(0,...f.values()),A=[];l.length>1&&A.push(`Multiple root bones (${l.length}): ${l.map(m=>m.name).join(", ")}`),l.length===0&&A.push("No root bone found — broken hierarchy");for(let m=0;m<i.bones.length;m++){const g=i.bones[m];g.parentIndex>=0&&g.parentIndex>=i.bones.length&&A.push(`Bone "${g.name}" [${m}] references out-of-range parent ${g.parentIndex}`),g.parentIndex===m&&A.push(`Bone "${g.name}" [${m}] is its own parent (cycle)`)}const p=N.useMemo(()=>{const m=new Map;for(const g of i.bones)m.set(g.name,(m.get(g.name)??0)+1);return Array.from(m.entries()).filter(([,g])=>g>1).map(([g,x])=>`"${g}" (x${x})`)},[i.bones]);return p.length>0&&A.push(`Duplicate bone names: ${p.join(", ")}`),b.jsxs("div",{className:"space-y-1.5",children:[b.jsxs("button",{className:"flex w-full items-center justify-between",onClick:()=>t(m=>!m),children:[b.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Skeleton Debug",A.length>0&&b.jsxs("span",{className:"ml-1.5 text-amber-400",children:["(",A.length," warning",A.length!==1?"s":"",")"]})]}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("text-muted-foreground transition-transform",!e&&"rotate-180"),children:b.jsx("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!e&&b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Bones",value:String(i.boneCount)}),b.jsx(Vt,{label:"Root Bones",value:l.map(m=>m.name).join(", ")||"None"}),b.jsx(Vt,{label:"Leaf Bones",value:String(u.length)}),b.jsx(Vt,{label:"Max Depth",value:String(h)}),b.jsx(Vt,{label:"Sub-meshes",value:String(i.meshGeometryCount)}),b.jsx(Vt,{label:"Total Vertices",value:a.toLocaleString()}),b.jsx(Vt,{label:"Total Triangles",value:Math.floor(o/3).toLocaleString()}),i.geometries.length>1&&b.jsx(b.Fragment,{children:i.geometries.map((m,g)=>b.jsx(Vt,{label:` Sub-mesh ${g}`,value:`${m.vertexCount.toLocaleString()} verts, ${Math.floor(m.indexCount/3).toLocaleString()} tris`},g))}),A.length>0&&b.jsx("div",{className:"pt-2 space-y-1",children:A.map((m,g)=>b.jsxs("div",{className:"flex items-start gap-1.5",children:[b.jsx("span",{className:"mt-0.5 h-2 w-2 shrink-0 rounded-full bg-amber-400"}),b.jsx("span",{className:"text-[11px] text-amber-400 break-all",children:m})]},g))})]})})]})}function b6({asset:n}){const{state:e}=yn(),[t,i]=N.useState(!0),a=n.metadata;if(!a||!Fp(a))return null;const o=a,l=o.tracks.filter(y=>y.trackName.endsWith(".position")),u=o.tracks.filter(y=>y.trackName.endsWith(".quaternion")),f=o.tracks.filter(y=>y.trackName.endsWith(".scale")),h=o.tracks.reduce((y,I)=>y+I.keyframeCount,0),A=N.useMemo(()=>{const y=new Set;for(const I of o.tracks){const M=I.trackName.lastIndexOf(".");M>0&&y.add(I.trackName.slice(0,M))}return y},[o.tracks]),p=o.duration>0?(h/o.tracks.length/o.duration).toFixed(1):"0",g=(n.settings.targetMeshId?e.assets.find(y=>y.id===n.settings.targetMeshId):void 0)?.metadata,x=N.useMemo(()=>{if(!g?.bones)return null;const y=new Set(g.bones.map(T=>T.name)),I=[...A].filter(T=>y.has(T)),M=[...A].filter(T=>!y.has(T)),C=g.bones.map(T=>T.name).filter(T=>!A.has(T));return{matched:I,missingInMesh:M,unanimated:C,meshBoneCount:g.bones.length}},[g,A]),E=[];o.duration<=0&&E.push("Duration is 0 or negative"),o.tracks.length===0&&E.push("No animation tracks"),x&&x.missingInMesh.length>0&&E.push(`${x.missingInMesh.length} animated bone${x.missingInMesh.length!==1?"s":""} not found in target mesh`);const S=o.tracks.filter(y=>y.keyframeCount<=1);return S.length>0&&E.push(`${S.length} track${S.length!==1?"s":""} with <= 1 keyframe (static)`),b.jsxs("div",{className:"space-y-1.5",children:[b.jsxs("button",{className:"flex w-full items-center justify-between",onClick:()=>i(y=>!y),children:[b.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Animation Debug",E.length>0&&b.jsxs("span",{className:"ml-1.5 text-amber-400",children:["(",E.length," warning",E.length!==1?"s":"",")"]})]}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("text-muted-foreground transition-transform",!t&&"rotate-180"),children:b.jsx("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!t&&b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Duration",value:`${o.duration.toFixed(3)}s`}),b.jsx(Vt,{label:"Animated Bones",value:String(A.size)}),b.jsx(Vt,{label:"Position Tracks",value:String(l.length)}),b.jsx(Vt,{label:"Rotation Tracks",value:String(u.length)}),b.jsx(Vt,{label:"Scale Tracks",value:String(f.length)}),b.jsx(Vt,{label:"Total Keyframes",value:h.toLocaleString()}),b.jsx(Vt,{label:"Avg Keys/sec/track",value:p}),x&&b.jsxs(b.Fragment,{children:[b.jsx(gc,{className:"my-1"}),b.jsx(Vt,{label:"Target Mesh Bones",value:String(x.meshBoneCount)}),b.jsx(Vt,{label:"Matched Bones",value:String(x.matched.length)}),x.missingInMesh.length>0&&b.jsxs("div",{className:"pt-1.5 space-y-0.5",children:[b.jsxs("span",{className:"text-[10px] font-medium text-amber-400",children:["Missing in mesh (",x.missingInMesh.length,"):"]}),b.jsx("div",{className:"max-h-24 overflow-y-auto",children:x.missingInMesh.map(y=>b.jsx("div",{className:"text-[10px] font-mono text-amber-400/80 pl-2 py-0.5 truncate",title:y,children:y},y))})]}),x.unanimated.length>0&&b.jsxs("div",{className:"pt-1.5 space-y-0.5",children:[b.jsxs("span",{className:"text-[10px] font-medium text-muted-foreground",children:["Unanimated mesh bones (",x.unanimated.length,"):"]}),b.jsx("div",{className:"max-h-24 overflow-y-auto",children:x.unanimated.map(y=>b.jsx("div",{className:"text-[10px] font-mono text-muted-foreground/60 pl-2 py-0.5 truncate",title:y,children:y},y))})]})]}),E.length>0&&b.jsx("div",{className:"pt-2 space-y-1",children:E.map((y,I)=>b.jsxs("div",{className:"flex items-start gap-1.5",children:[b.jsx("span",{className:"mt-0.5 h-2 w-2 shrink-0 rounded-full bg-amber-400"}),b.jsx("span",{className:"text-[11px] text-amber-400 break-all",children:y})]},I))})]})})]})}function S6({asset:n}){const[e,t]=N.useState(!0),i=n.metadata;if(!i||!Fp(i))return null;const a=i;return b.jsxs("div",{className:"space-y-1.5",children:[b.jsxs("button",{className:"flex w-full items-center justify-between",onClick:()=>t(o=>!o),children:[b.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Tracks (",a.trackCount,")"]}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("text-muted-foreground transition-transform",!e&&"rotate-180"),children:b.jsx("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!e&&b.jsx(la,{children:b.jsxs(ca,{className:"p-2",children:[b.jsx(Vt,{label:"Duration",value:`${a.duration.toFixed(3)}s`}),b.jsx(Vt,{label:"Format",value:"v2 (Three.js native)"}),b.jsx(gc,{className:"my-1.5"}),b.jsx("div",{className:"max-h-64 overflow-y-auto space-y-0.5",children:a.tracks.map((o,l)=>b.jsxs("div",{className:"flex items-center justify-between py-0.5 hover:bg-muted/50 rounded-sm px-1",children:[b.jsx("span",{className:"text-[11px] font-mono truncate flex-1",title:o.trackName,children:o.trackName}),b.jsxs("span",{className:"text-[10px] text-muted-foreground ml-2 shrink-0",children:[o.keyframeCount,"k"]})]},l))})]})})]})}function C6({asset:n}){const e=n.metadata;if(!e||!Fp(e))return null;const t=e.tracks.reduce((i,a)=>i+a.keyframeCount,0);return b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Duration",value:`${e.duration.toFixed(3)}s`}),b.jsx(Vt,{label:"Tracks",value:String(e.trackCount)}),b.jsx(Vt,{label:"Total Keyframes",value:t.toLocaleString()}),e.targetMeshId&&b.jsx(Vt,{label:"Target Mesh",value:e.targetMeshId}),n.processedSize>0&&b.jsx(Vt,{label:"Data Size",value:Oo(n.processedSize)})]})})}const w6=[{label:"Texture",value:Qn.Texture},{label:"Color",value:Qn.Color},{label:"Float",value:Qn.Float},{label:"Vec2",value:Qn.Vec2},{label:"Vec3",value:Qn.Vec3},{label:"Vec4",value:Qn.Vec4},{label:"Int",value:Qn.Int}],M6=[{label:"None",value:Fi.None},{label:"MainTex",value:Fi.MainTex},{label:"Tint",value:Fi.Tint},{label:"AlphaTest",value:Fi.AlphaTest}];function rw(n,e){return e===Fi.None?!0:e===Fi.MainTex?n===Qn.Texture:e===Fi.Tint?n===Qn.Color:e===Fi.AlphaTest?n===Qn.Int:!1}function Kr({value:n,onChange:e,label:t}){return b.jsxs("div",{className:"flex items-center gap-1",children:[t&&b.jsx("span",{className:"text-[10px] text-muted-foreground w-3",children:t}),b.jsx(Po,{type:"number",step:"0.01",value:n,onChange:i=>e(parseFloat(i.target.value)||0),className:"h-5 flex-1 text-[10px] font-mono px-1"})]})}function I6({prop:n,index:e,textures:t,materialPack:i,allProps:a,onChange:o,onRemove:l}){const[u,f]=N.useState(!1),h=t.find(x=>x.id===n.textureAssetId),A=x=>{const E=Math.round(Math.min(1,Math.max(0,x[0]))*255),S=Math.round(Math.min(1,Math.max(0,x[1]))*255),y=Math.round(Math.min(1,Math.max(0,x[2]))*255);return`#${E.toString(16).padStart(2,"0")}${S.toString(16).padStart(2,"0")}${y.toString(16).padStart(2,"0")}`},p=x=>{const E=parseInt(x.slice(1,3),16)/255,S=parseInt(x.slice(3,5),16)/255,y=parseInt(x.slice(5,7),16)/255;return[E,S,y,n.value[3]]};function m(x,E){const S=[...n.value];S[x]=E,o(e,{...n,value:S})}const g=new Set(a.filter((x,E)=>E!==e).map(x=>x.previewFlag).filter(x=>x!==Fi.None));return b.jsx(la,{children:b.jsxs(ca,{className:"p-2 space-y-1.5",children:[b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(Po,{value:n.fieldName,onChange:x=>o(e,{...n,fieldName:x.target.value}),placeholder:"Field name...",className:"h-6 flex-1 text-[11px] font-mono"}),b.jsx("button",{className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors",onClick:()=>l(e),title:"Remove property",children:b.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:b.jsx("path",{d:"M2 2l6 6M8 2l-6 6",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})})})]}),b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx("select",{value:n.fieldType,onChange:x=>{const E=Number(x.target.value),S=rw(E,n.previewFlag)?n.previewFlag:Fi.None;o(e,{...n,fieldType:E,previewFlag:S})},className:"h-6 flex-1 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:w6.map(x=>b.jsx("option",{value:x.value,children:x.label},x.value))}),b.jsx("select",{value:n.previewFlag,onChange:x=>o(e,{...n,previewFlag:Number(x.target.value)}),className:"h-6 w-24 shrink-0 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:M6.filter(x=>rw(n.fieldType,x.value)&&(!g.has(x.value)||x.value===n.previewFlag)).map(x=>b.jsx("option",{value:x.value,children:x.label},x.value))})]}),n.fieldType===Qn.Texture&&b.jsxs(b.Fragment,{children:[b.jsxs("button",{onClick:()=>f(!0),className:"flex h-7 w-full items-center gap-2 rounded border border-border bg-background px-2 text-[11px] text-foreground hover:bg-accent/50 transition-colors",children:[h?.previewUrl?b.jsx("img",{src:h.previewUrl,alt:h.fileName,className:"checkerboard size-5 shrink-0 rounded object-contain"}):b.jsx(qU,{className:"size-4 shrink-0 text-muted-foreground"}),b.jsx("span",{className:"flex-1 truncate text-left",children:h?.fileName??"No texture"})]}),b.jsx(n6,{open:u,textures:t,materialPack:i,selectedId:n.textureAssetId,onSelect:x=>o(e,{...n,textureAssetId:x}),onClose:()=>f(!1)})]}),n.fieldType===Qn.Color&&b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("input",{type:"color",value:A(n.value),onChange:x=>o(e,{...n,value:p(x.target.value)}),className:"h-6 w-8 cursor-pointer rounded border border-border bg-transparent p-0"}),b.jsxs("div",{className:"flex flex-1 items-center gap-1",children:[b.jsx("span",{className:"text-[10px] text-muted-foreground",children:"A"}),b.jsx("input",{type:"range",min:"0",max:"1",step:"0.01",value:n.value[3],onChange:x=>m(3,parseFloat(x.target.value)),className:"h-1 flex-1"}),b.jsx("span",{className:"w-6 text-right text-[10px] font-mono text-muted-foreground",children:n.value[3].toFixed(2)})]})]}),n.fieldType===Qn.Float&&b.jsx(Kr,{value:n.value[0],onChange:x=>m(0,x)}),n.fieldType===Qn.Int&&b.jsx(Po,{type:"number",step:"1",value:Math.round(n.value[0]),onChange:x=>m(0,parseInt(x.target.value)||0),className:"h-6 text-[11px] font-mono"}),n.fieldType===Qn.Vec2&&b.jsxs("div",{className:"flex gap-1",children:[b.jsx(Kr,{value:n.value[0],onChange:x=>m(0,x),label:"X"}),b.jsx(Kr,{value:n.value[1],onChange:x=>m(1,x),label:"Y"})]}),n.fieldType===Qn.Vec3&&b.jsxs("div",{className:"flex gap-1",children:[b.jsx(Kr,{value:n.value[0],onChange:x=>m(0,x),label:"X"}),b.jsx(Kr,{value:n.value[1],onChange:x=>m(1,x),label:"Y"}),b.jsx(Kr,{value:n.value[2],onChange:x=>m(2,x),label:"Z"})]}),n.fieldType===Qn.Vec4&&b.jsxs("div",{className:"flex gap-1",children:[b.jsx(Kr,{value:n.value[0],onChange:x=>m(0,x),label:"X"}),b.jsx(Kr,{value:n.value[1],onChange:x=>m(1,x),label:"Y"}),b.jsx(Kr,{value:n.value[2],onChange:x=>m(2,x),label:"Z"}),b.jsx(Kr,{value:n.value[3],onChange:x=>m(3,x),label:"W"})]})]})})}function T6({asset:n}){const{state:e,updateAssetSettings:t}=yn(),i=n.settings.materialConfig,a=e.assets.filter(h=>h.type===at.Texture2D);function o(h){t(n.id,{materialConfig:{...i,schemaId:h}})}function l(h,A){const p=[...i.properties];p[h]=A,t(n.id,{materialConfig:{...i,properties:p}})}function u(h){const A=i.properties.filter((p,m)=>m!==h);t(n.id,{materialConfig:{...i,properties:A}})}function f(){const h=[...i.properties,{fieldName:"",fieldType:Qn.Color,previewFlag:Fi.None,value:[1,1,1,1],textureAssetId:null}];t(n.id,{materialConfig:{...i,properties:h}})}return b.jsxs(b.Fragment,{children:[b.jsx(ai,{label:"Schema ID",children:b.jsx(Po,{value:i.schemaId,onChange:h=>o(h.target.value),placeholder:"e.g. StandardShader",className:"h-7 text-xs font-mono"})}),b.jsxs(ai,{label:`Properties (${i.properties.length})`,children:[b.jsx("div",{className:"space-y-1.5",children:i.properties.map((h,A)=>b.jsx(I6,{prop:h,index:A,textures:a,materialPack:n.settings.pack,allProps:i.properties,onChange:l,onRemove:u},A))}),b.jsx(Ei,{variant:"outline",size:"sm",className:"mt-1.5 h-7 w-full text-[11px]",onClick:f,children:"+ Add Property"})]})]})}function B6({asset:n}){const{state:e,updateAssetSettings:t}=yn(),i=n.metadata;if(!i||!i.materials||i.materials.length===0)return null;const a=e.assets.filter(f=>f.type===at.MaterialSchema),o=n.settings.materialOverrides;function l(f){if(o[f]!==void 0)return o[f]??"";const h=i.materials[f]?.name??"";if(h){const A=a.find(p=>p.stringId.toLowerCase()===h.toLowerCase());if(A)return A.id}return""}function u(f,h){const A={...o,[f]:h||null};t(n.id,{materialOverrides:A})}return b.jsxs(ai,{label:"Material Assignments",children:[b.jsx("div",{className:"space-y-1.5",children:i.materials.map((f,h)=>b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] text-muted-foreground",title:f.name,children:f.name||`Sub-mesh ${h}`}),b.jsxs("select",{value:l(h),onChange:A=>u(h,A.target.value),className:"h-6 w-36 shrink-0 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:[b.jsx("option",{value:"",children:"Default (FBX)"}),a.map(A=>b.jsx("option",{value:A.id,children:A.fileName},A.id))]})]},h))}),a.length===0&&b.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Create a material to assign it here."})]})}function R6(n,e,t){const i=n.settings.materialOverrides;if(i[e]!==void 0)return i[e]??"";const o=n.metadata?.materials?.[e]?.name??"";if(o){const l=t.find(u=>u.stringId.toLowerCase()===o.toLowerCase());if(l)return l.id}return""}function D6({meshAssets:n}){const{state:e,dispatch:t,updateAssetSettings:i,changeAssetType:a}=yn(),o=e.assets.filter(p=>p.type===at.MaterialSchema),l=n.every(p=>p.type===n[0].type)?n[0].type:null;function u(p){const m=n.filter(g=>g.type!==p);if(m.length!==0){m.length>1&&t({type:"START_BATCH_PROCESSING",total:m.length});for(const g of m)a(g.id,p)}}const f=N.useMemo(()=>{const p=new Map;for(const m of n){const g=m.metadata;if(g?.materials)for(let x=0;x<g.materials.length;x++){const E=g.materials[x]?.name||`Sub-mesh ${x}`;let S=p.get(E);S||(S={name:E,entries:[]},p.set(E,S)),S.entries.push({asset:m,subMeshIndex:x})}}return Array.from(p.values())},[n]);function h(p){const m=p.entries.map(x=>R6(x.asset,x.subMeshIndex,o)),g=m[0];return m.every(x=>x===g)?g:"__mixed__"}function A(p,m){for(const{asset:g,subMeshIndex:x}of p.entries){const E={...g.settings.materialOverrides,[x]:m||null};i(g.id,{materialOverrides:E})}}return b.jsxs("div",{className:"flex flex-col gap-4",children:[b.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:[n.length," meshes selected"]}),b.jsx(ai,{label:"Asset Type",children:b.jsx(qa,{options:Pp,value:l??-1,onChange:p=>u(p)})}),b.jsxs(ai,{label:"Material Assignments",children:[b.jsx("div",{className:"space-y-1.5",children:f.map(p=>{const m=h(p);return b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsxs("span",{className:"min-w-0 flex-1 truncate text-[11px] text-muted-foreground",title:p.name,children:[p.name,p.entries.length>1&&b.jsxs("span",{className:"ml-1 text-[10px] opacity-60",children:["(",p.entries.length,")"]})]}),b.jsxs("select",{value:m==="__mixed__"?"__mixed__":m,onChange:g=>{g.target.value!=="__mixed__"&&A(p,g.target.value)},className:"h-6 w-36 shrink-0 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:[m==="__mixed__"&&b.jsx("option",{value:"__mixed__",children:"Mixed"}),b.jsx("option",{value:"",children:"Default (FBX)"}),o.map(g=>b.jsx("option",{value:g.id,children:g.fileName},g.id))]})]},p.name)})}),f.length===0&&b.jsx("p",{className:"text-[10px] text-muted-foreground",children:"No material slots on selected meshes."})]})]})}function N6({animAssets:n}){const{state:e,dispatch:t,updateAssetSettings:i,changeAssetType:a}=yn(),o=e.assets.filter(A=>A.type===at.SkinnedMesh),l=n.every(A=>A.type===n[0].type)?n[0].type:null;function u(A){const p=n.filter(m=>m.type!==A);if(p.length!==0){p.length>1&&t({type:"START_BATCH_PROCESSING",total:p.length});for(const m of p)a(m.id,A)}}const f=n.every(A=>A.settings.targetMeshId===n[0].settings.targetMeshId)?n[0].settings.targetMeshId??"":"__mixed__";function h(A){for(const p of n)i(p.id,{targetMeshId:A||null})}return b.jsxs("div",{className:"flex flex-col gap-4",children:[b.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:[n.length," animations selected"]}),b.jsx(ai,{label:"Asset Type",children:b.jsx(qa,{options:Pp,value:l??-1,onChange:A=>u(A)})}),b.jsx(ai,{label:"Preview Mesh",children:o.length===0?b.jsx("p",{className:"text-[11px] text-muted-foreground",children:"No skinned meshes in project."}):b.jsxs("select",{value:f,onChange:A=>{A.target.value!=="__mixed__"&&h(A.target.value)},className:"h-7 w-full rounded-md border border-border bg-background px-2 text-xs text-foreground",children:[f==="__mixed__"&&b.jsx("option",{value:"__mixed__",children:"Mixed"}),b.jsx("option",{value:"",children:"None (skeleton only)"}),o.map(A=>b.jsx("option",{value:A.id,children:A.fileName},A.id))]})})]})}function L6({assets:n}){const{dispatch:e,changeAssetType:t}=yn(),i=n.every(o=>o.type===n[0].type)?n[0].type:null;function a(o){const l=n.filter(u=>u.type!==o);if(l.length!==0){l.length>1&&e({type:"START_BATCH_PROCESSING",total:l.length});for(const u of l)t(u.id,o)}}return b.jsxs("div",{className:"flex flex-col gap-4",children:[b.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:[n.length," assets selected"]}),b.jsx(ai,{label:"Asset Type",children:b.jsx(qa,{options:Pp,value:i??-1,onChange:o=>a(o)})})]})}function U6({asset:n}){const{dispatch:e}=yn();return b.jsx(la,{className:"border-red-500/30",children:b.jsxs(ca,{className:"p-3 space-y-2",children:[b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("span",{className:"h-2 w-2 rounded-full bg-red-400 shrink-0"}),b.jsx("span",{className:"text-xs font-medium text-red-400",children:"Processing Error"})]}),n.error&&b.jsx("p",{className:"text-[11px] text-muted-foreground break-all",children:n.error}),b.jsx(Ei,{variant:"outline",size:"sm",className:"w-full h-7 text-[11px]",onClick:()=>e({type:"UPDATE_ASSET",id:n.id,updates:{status:"pending",error:void 0}}),children:"Retry Processing"})]})})}function P6(){const{state:n}=yn(),e=n.selectedAssetIds.length>1,t=e?void 0:n.assets.find(f=>f.id===IM(n)),i=N.useMemo(()=>e?n.selectedAssetIds.map(f=>n.assets.find(h=>h.id===f)).filter(f=>!!f):[],[e,n.selectedAssetIds,n.assets]),a=i.length>0&&i.every(f=>f.type===at.StaticMesh||f.type===at.SkinnedMesh),o=i.length>0&&i.every(f=>f.type===at.Texture2D||o0(f.type)),l=i.length>0&&i.every(f=>f.type===at.AnimationClip),u=i.length>0&&i.every(f=>o0(f.type));return b.jsxs("section",{className:"flex h-full flex-col bg-card",children:[b.jsx("div",{className:"flex h-9 items-center gap-2 border-b border-border px-4",children:b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Details"})}),b.jsx(xx,{className:"flex-1 min-h-0",children:b.jsxs("div",{className:"w-full p-4",children:[!t&&!e&&b.jsx("div",{className:"flex h-48 items-center justify-center text-xs text-muted-foreground",children:"Select an asset"}),e&&a&&b.jsx(D6,{meshAssets:i}),e&&o&&b.jsx(s6,{assets:i}),e&&l&&b.jsx(N6,{animAssets:i}),e&&u&&!a&&!l&&b.jsx(L6,{assets:i}),e&&!u&&b.jsxs("div",{className:"text-xs text-muted-foreground",children:[i.length," assets selected"]}),t&&b.jsxs("div",{className:"flex flex-col gap-4",children:[t.status==="error"&&b.jsx(U6,{asset:t}),o0(t.type)&&b.jsx(i6,{asset:t}),t.type!==at.MaterialSchema&&b.jsx(o6,{asset:t}),b.jsx(a6,{asset:t}),t.type===at.Texture2D&&b.jsx(u6,{asset:t}),t.type===at.StaticMesh&&b.jsx(d6,{asset:t}),t.type===at.Audio&&b.jsx(A6,{asset:t}),t.type===at.AnimationClip&&b.jsx(r6,{asset:t}),t.type===at.MaterialSchema&&b.jsx(T6,{asset:t}),b.jsx(m6,{asset:t}),t.metadata&&b.jsxs(b.Fragment,{children:[b.jsx(gc,{}),t.type===at.Texture2D&&b.jsx(g6,{asset:t}),t.type===at.Audio&&b.jsx(v6,{asset:t}),(t.type===at.StaticMesh||t.type===at.SkinnedMesh)&&b.jsx(x6,{asset:t}),t.type===at.AnimationClip&&b.jsx(C6,{asset:t})]}),(t.type===at.StaticMesh||t.type===at.SkinnedMesh)&&t.metadata&&b.jsx(B6,{asset:t}),t.type===at.AnimationClip&&t.metadata&&b.jsx(S6,{asset:t}),(t.type===at.SkinnedMesh||t.type===at.AnimationClip)&&t.metadata&&b.jsx(y6,{asset:t}),t.type===at.SkinnedMesh&&t.metadata&&b.jsx(E6,{asset:t}),t.type===at.AnimationClip&&t.metadata&&b.jsx(b6,{asset:t})]})]})})]})}function F6(){const{state:n}=yn();if(!n.initialProcessing)return null;const e=n.initialProcessingTotal,t=n.assets.filter(m=>m.status==="loading").length,i=n.assets.filter(m=>m.status==="pending").length,a=n.assets.filter(m=>m.status==="processing").length,o=n.assets.filter(m=>m.status==="error").length,l=t+i+a,u=e-l,f=e>0?Math.round(u/e*100):0,h=n.assets.filter(m=>m.status==="processing").map(m=>m.fileName).slice(0,3);let A="";t>0&&a===0?A="Reading files and checking cache...":a>0&&(A=h.join(", "),a>3&&(A+=` +${a-3} more`));let p="";return i>0&&(p=`${i} queued`),o>0&&(p+=`${p?" · ":""}${o} failed`),b.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:b.jsxs("div",{className:"w-[420px] h-[200px] rounded-xl border border-border bg-card p-6 shadow-2xl flex flex-col",children:[b.jsx("div",{className:"flex items-center gap-3 mb-4",children:b.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Processing Assets"})}),b.jsxs("div",{className:"mb-3",children:[b.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[b.jsxs("span",{className:"text-xs text-muted-foreground",children:[u," of ",e," complete"]}),b.jsxs("span",{className:"text-xs font-mono text-muted-foreground",children:[f,"%"]})]}),b.jsx("div",{className:"h-2 w-full rounded-full bg-muted overflow-hidden",children:b.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-300 ease-out",style:{width:`${f}%`}})})]}),b.jsxs("div",{className:"flex-1 flex flex-col justify-between min-h-0",children:[b.jsxs("div",{children:[b.jsx("p",{className:"text-[11px] text-muted-foreground truncate h-4",children:A}),b.jsx("p",{className:"text-[11px] text-muted-foreground/60 h-4",children:p})]}),b.jsx("p",{className:"text-[10px] text-muted-foreground/40",children:"Results are cached for next time."})]})]})})}const BT=N.forwardRef((n,e)=>{const{importFiles:t}=yn();return N.useImperativeHandle(e,()=>({importFiles:(i,a)=>t(i,a)}),[t]),b.jsxs("div",{className:"flex h-full flex-col bg-background text-foreground overflow-hidden",children:[b.jsx(nH,{}),b.jsx(iH,{left:b.jsx(AH,{}),center:b.jsx(Z8,{}),right:b.jsx(P6,{})})]})});BT.displayName="PackerInner";const RT=N.forwardRef(({apiBase:n="/api",className:e},t)=>{const i=N.useRef(null);return N.useEffect(()=>{P5(n)},[n]),N.useImperativeHandle(t,()=>({importFiles:(a,o)=>i.current?.importFiles(a,o)??Promise.resolve()}),[]),b.jsx("div",{className:e,children:b.jsx(Z5,{children:b.jsxs(NU,{delayDuration:300,children:[b.jsx(BT,{ref:i}),b.jsx(F6,{}),b.jsx(XP,{richColors:!0,position:"bottom-right"})]})})})});RT.displayName="StowKitPacker";function O6(){return b.jsx(RT,{className:"h-screen"})}jR.createRoot(document.getElementById("root")).render(b.jsx(N.StrictMode,{children:b.jsx(O6,{})}));export{at as A};
4065
+ `),a={name:"",props:[],nodes:[]},o=a,l=[o],u=0,f=0,h=i;f<h.length;f++){var A=h[f];if(A=A.trim(),A.length!==0&&A[0]!==";"){if(u===0)if(A[0]==="}"){if(l.length===1)throw"FBX syntax error";l.pop(),o=l[l.length-1]}else{var p=A.indexOf(":"),m=A.substring(0,p);m=m.trim();for(var g=A[A.length-1]==="{",x=A.substring(p+1,A.length-(g?1:0)),E=x.split(","),S=[],y=0,I=E;y<I.length;y++){var M=I[y],C=M.trim();if(C!==""){var T=e(C);typeof T>"u"||S.push(T)}}E[E.length-1]===""&&(u=1);var B={name:m,props:S,nodes:[]};o.nodes.push(B),(g||u===1)&&(l.push(B),o=B)}else if(u===1){for(var g=A[A.length-1]==="{",x=A.substring(0,A.length-(g?1:0)),E=x.split(","),S=[],L=0,O=E;L<O.length;L++){var R=O[L],C=R.trim();if(!(C===""||C==="}")){var T=e(C);typeof T>"u"||S.push(T)}}o.props=o.props.concat(S),E[E.length-1]!==""&&(u=0),!g&&u===0&&(l.pop(),o=l[l.length-1])}}}function F(j){if(j.nodes.length===1&&j.props.length===0&&j.nodes[0].name==="a")j.props=[j.nodes[0].props],j.nodes=[];else for(var V=0,W=j.nodes;V<W.length;V++){var te=W[V];F(te)}}return F(a),a.nodes}Bu.parseText=n;function e(t){if(t[0]!="*"){if(t[0]=='"')return t.substr(1,t.length-2);if(t=="T")return!0;if(t=="F")return!1;if(t=="Y")return!0;if(t=="N")return!1;if(t.indexOf(".")!=-1)return parseFloat(t);var i=BigInt(t);return i<Number.MIN_SAFE_INTEGER||i>Number.MAX_SAFE_INTEGER?i:Number(i)}}return Bu}var Pa={},HC;function b8(){if(HC)return Pa;HC=1;var n=Pa&&Pa.__extends||(function(){var i=function(a,o){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,u){l.__proto__=u}||function(l,u){for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&(l[f]=u[f])},i(a,o)};return function(a,o){i(a,o);function l(){this.constructor=a}a.prototype=o===null?Object.create(o):(l.prototype=o.prototype,new l)}})();Object.defineProperty(Pa,"__esModule",{value:!0}),Pa.FBXReader=Pa.FBXReaderNode=void 0;var e=(function(){function i(a){this.fbxNode=a}return i.prototype.nodeFilter=function(a,o){var l=void 0,u=void 0;typeof a=="string"?(l=a,typeof o<"u"&&(u=o)):u=a;var f;if(typeof u<"u"){var h=function(A){for(var p in u){var m=parseInt(p);if(A.props[m]!==u[m])return!1}return!0};typeof l<"u"?f=function(A){return A.name===l&&h(A)}:f=h}else f=function(A){return A.name===l};return f},i.prototype.node=function(a,o){var l=this.fbxNode.nodes.find(this.nodeFilter(a,o));if(!(typeof l>"u"))return new i(l)},i.prototype.nodes=function(a,o){var l=this.fbxNode.nodes.filter(this.nodeFilter(a,o)).map(function(u){return new i(u)});return l},i.prototype.prop=function(a,o){var l=this.fbxNode.props[a];if(typeof o>"u")return l;if(o==="boolean")return typeof l=="boolean"?l:void 0;if(o==="number")return typeof l=="number"?l:void 0;if(o==="bigint")return typeof l=="bigint"?l:void 0;if(o==="string")return typeof l=="string"?l:void 0;if(Array.isArray(l)){if(l.length==0)return l;if(o==="boolean[]")return typeof l[0]=="boolean"?l:void 0;if(o==="number[]")return typeof l[0]=="number"?l:void 0;if(o==="bigint[]")return typeof l[0]=="bigint"?l:void 0}},i})();Pa.FBXReaderNode=e;var t=(function(i){n(a,i);function a(o){var l=this,u={name:"",props:[],nodes:o};return l=i.call(this,u)||this,l.fbx=o,l}return a})(e);return Pa.FBXReader=t,Pa}var VC;function S8(){return VC||(VC=1,(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.FBXReaderNode=n.FBXReader=n.parseText=n.parseBinary=void 0;var e=y8();Object.defineProperty(n,"parseBinary",{enumerable:!0,get:function(){return e.parseBinary}});var t=E8();Object.defineProperty(n,"parseText",{enumerable:!0,get:function(){return t.parseText}});var i=b8();Object.defineProperty(n,"FBXReader",{enumerable:!0,get:function(){return i.FBXReader}}),Object.defineProperty(n,"FBXReaderNode",{enumerable:!0,get:function(){return i.FBXReaderNode}})})(Kg)),Kg}var a0=S8();function C8(n){const e=M8(n);if(e.length===0)return[];const t=[];for(const i of e){const a=[];for(const o of i.tracks)o.name.endsWith(".scale")||(o.name.endsWith(".quaternion")?a.push(new aa(o.name,Array.from(o.times),Array.from(o.values))):a.push(new ks(o.name,Array.from(o.times),Array.from(o.values))));a.length>0&&t.push(new Uo(i.name,i.duration,a))}return t}function w8(n,e){const t=new Set;return e.traverse(i=>{i.isBone&&t.add(i.name)}),t.size===0?n:n.map(i=>{const a=new Map;for(const l of i.tracks){const u=l.name.split(".")[0];if(!t.has(u))for(const f of t){const h=Kt.sanitizeNodeName(u),A=Kt.sanitizeNodeName(f);if(h===A||h.endsWith(A)||A.endsWith(h)){a.set(u,f);break}}}if(a.size===0)return i;const o=i.tracks.map(l=>{const u=l.name.split("."),h=`${a.get(u[0])??u[0]}.${u.slice(1).join(".")}`;return l instanceof aa?new aa(h,Array.from(l.times),Array.from(l.values)):new ks(h,Array.from(l.times),Array.from(l.values))});return new Uo(i.name,i.duration,o)})}const jC=46186158e3,Fa=Math.PI/180;function WC(n){return Array.isArray(n)||ArrayBuffer.isView(n)}function M8(n){let e;try{e=a0.parseBinary(n)}catch{try{e=a0.parseText(new TextDecoder().decode(n))}catch{return[]}}const t=new a0.FBXReader(e),i=t.node("Objects"),a=t.node("Connections");if(!i||!a)return[];let o=.01;const l=t.node("GlobalSettings");if(l){const I=l.fbxNode.nodes.find(M=>M.name==="Properties70");if(I){const M=I.nodes.find(C=>C.name==="P"&&String(C.props[0])==="UnitScaleFactor");if(M){const C=Number(M.props[4]);C>0&&(o=C/100)}}}const u=new Map;function f(I){let M=u.get(I);return M||(M={parents:[],children:[]},u.set(I,M)),M}for(const I of a.fbxNode.nodes){if(I.name!=="C")continue;const M=I.props[1],C=I.props[2],T=I.props.length>3?String(I.props[3]):void 0;f(M).parents.push({id:C,rel:T}),f(C).children.push({id:M,rel:T})}const h=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"],A=new Map,p=new Map;for(const I of i.fbxNode.nodes){if(I.name!=="Model")continue;const M=I.props[0],C=String(I.props[1]??""),T=C.includes("\0")?C.split("\0")[0]:C.replace(/^Model::/,"");if(!T)continue;A.set(M,T);let B,L,O="ZYX";const R=I.nodes.find(F=>F.name==="Properties70");if(R)for(const F of R.nodes){if(F.name!=="P")continue;const j=String(F.props[0]);if(j==="PreRotation")B=[Number(F.props[4]),Number(F.props[5]),Number(F.props[6])];else if(j==="PostRotation")L=[Number(F.props[4]),Number(F.props[5]),Number(F.props[6])];else if(j==="RotationOrder"){const V=Number(F.props[4]);V>=0&&V<h.length&&(O=h[V])}}p.set(M,{preRotation:B,postRotation:L,eulerOrder:O})}const m=new Map;for(const I of i.fbxNode.nodes){if(I.name!=="AnimationCurveNode")continue;const M=I.props[0],C=String(I.props[1]??""),T=C.includes("\0")?C.split("\0")[0]:C;let B=null;T==="T"||T==="Lcl Translation"||T.endsWith("::T")?B="T":T==="R"||T==="Lcl Rotation"||T.endsWith("::R")?B="R":(T==="S"||T==="Lcl Scaling"||T.endsWith("::S"))&&(B="S"),B&&m.set(M,{id:M,attr:B,curves:{}})}if(m.size===0)return[];for(const I of i.fbxNode.nodes){if(I.name!=="AnimationCurve")continue;const M=I.props[0],C=I.nodes.find(V=>V.name==="KeyTime"),T=I.nodes.find(V=>V.name==="KeyValueFloat");if(!C||!T)continue;const B=C.props[0],L=T.props[0];if(!WC(B)||!WC(L))continue;const R=Array.from(B).map(V=>Number(V)/jC),F=Array.isArray(L)?L:Array.from(L),j=u.get(M);if(j)for(const V of j.parents){const W=m.get(V.id);if(!W)continue;const te=V.rel??"",ne={times:R,values:F};te.includes("d|X")?W.curves.x=ne:te.includes("d|Y")?W.curves.y=ne:te.includes("d|Z")&&(W.curves.z=ne)}}const g=[];for(const[,I]of m){if(!I.curves.x&&!I.curves.y&&!I.curves.z)continue;const M=u.get(I.id);if(M)for(const C of M.parents){const T=A.get(C.id);if(T){g.push({modelName:T,modelId:C.id,attr:I.attr,curves:I.curves});break}}}if(g.length===0)return[];let x="default",E=0;for(const I of i.fbxNode.nodes){if(I.name!=="AnimationStack")continue;const M=String(I.props[1]??"default");x=M.includes("\0")?M.split("\0")[0]:M;const C=I.nodes.find(T=>T.name==="Properties70");if(C){const T=C.nodes.find(B=>B.name==="P"&&String(B.props[0])==="LocalStop");if(T){const B=T.props[4],L=Number(B);L>0&&(E=L/jC)}}break}const S="ZYX",y=[];for(const I of g){const M=I.curves.x||I.curves.y||I.curves.z;if(!M)continue;const C=M.times.length,T=new Float32Array(M.times),B=p.get(I.modelId),L=Kt.sanitizeNodeName(I.modelName);if(I.attr==="T"){const O=new Float32Array(C*3);for(let R=0;R<C;R++)O[R*3]=(I.curves.x?.values[R]??0)*o,O[R*3+1]=(I.curves.y?.values[R]??0)*o,O[R*3+2]=(I.curves.z?.values[R]??0)*o;y.push({name:`${L}.position`,times:T,values:O,valuesPerKey:3}),E===0&&C>0&&(E=Math.max(E,T[C-1]))}else if(I.attr==="R"){const O=B?.eulerOrder??S;let R=null;if(B?.preRotation){const ne=B.preRotation;R=new Rn().setFromEuler(new zn(ne[0]*Fa,ne[1]*Fa,ne[2]*Fa,S))}let F=null;if(B?.postRotation){const ne=B.postRotation;F=new Rn().setFromEuler(new zn(ne[0]*Fa,ne[1]*Fa,ne[2]*Fa,S)).invert()}const j=new Float32Array(C*4),V=new zn,W=new Rn,te=new Rn;for(let ne=0;ne<C;ne++)V.set((I.curves.x?.values[ne]??0)*Fa,(I.curves.y?.values[ne]??0)*Fa,(I.curves.z?.values[ne]??0)*Fa,O),W.setFromEuler(V),R&&W.premultiply(R),F&&W.multiply(F),ne>0&&W.dot(te)<0&&(W.x=-W.x,W.y=-W.y,W.z=-W.z,W.w=-W.w),j[ne*4]=W.x,j[ne*4+1]=W.y,j[ne*4+2]=W.z,j[ne*4+3]=W.w,te.copy(W);y.push({name:`${L}.quaternion`,times:T,values:j,valuesPerKey:4}),E===0&&C>0&&(E=Math.max(E,T[C-1]))}else if(I.attr==="S"){const O=new Float32Array(C*3);for(let R=0;R<C;R++)O[R*3]=I.curves.x?.values[R]??1,O[R*3+1]=I.curves.y?.values[R]??1,O[R*3+2]=I.curves.z?.values[R]??1;y.push({name:`${L}.scale`,times:T,values:O,valuesPerKey:3})}}return y.length===0?[]:[{name:x,duration:E,tracks:y}]}const Ex={color:856343},Fu={antialias:!0,maxPixelRatio:2,toneMapping:"ACESFilmic",toneMappingExposure:2.5},Eo={fov:45,near:.01,far:1e3,position:{x:2,y:1.5,z:2}},iv={enableDamping:!0,dampingFactor:.08},bo={distanceMultiplier:1.5,offsetX:.7,offsetY:.5,offsetZ:.7,nearFraction:.01,farMultiplier:10},ji={ambient:{color:16777215,intensity:.5},key:{color:16777215,intensity:2.5,position:{x:5,y:8,z:5},castShadow:!1,shadowMapSize:1024},fill:{color:16777215,intensity:1.5,position:{x:-3,y:4,z:-5},castShadow:!1}},Ls={enabled:!0,unitSize:1,size:10,colorCenter:3159613,colorGrid:2172461},bT={color:8947865},I8=JSON.stringify([Ex,Fu,Eo,iv,bo,ji,Ls,bT]),T8={None:yr,Linear:kv,Reinhard:Qv,Cineon:zv,ACESFilmic:vf,AgX:Gv,Neutral:Hv},ap=N.forwardRef(function({sourceData:e,fileName:t,previewGroup:i,animationClips:a,animationSourceData:o,animationFileName:l,materialOverrides:u,className:f,onAnimationTick:h,onAnimationInfo:A,gridUnitSize:p=Ls.unitSize,showHumanScale:m=!1},g){const x=N.useRef(null),[E,S]=N.useState(!0),y=N.useRef(null);return N.useImperativeHandle(g,()=>({play(){const I=y.current;I?.action&&(I.action.paused=!1,I.playing=!0,I.clock.start())},pause(){const I=y.current;I?.action&&(I.action.paused=!0,I.playing=!1)},stop(){const I=y.current;I?.action&&(I.action.stop(),I.action.play(),I.action.paused=!0,I.action.time=0,I.playing=!1,I.mixer&&I.mixer.update(0))},setTime(I){const M=y.current;!M?.action||!M.mixer||(M.action.time=I,M.mixer.update(0))},setLoop(I){const M=y.current;M?.action&&(M.action.loop=I?FM:PM,M.action.clampWhenFinished=!I)},getTime(){return y.current?.action?.time??0},getDuration(){return y.current?.action?.getClip().duration??0},isPlaying(){return y.current?.playing??!1},getClipNames(){return y.current?.clips.map(I=>I.name)??[]},setClip(I){const M=y.current;if(!M?.mixer)return;const C=M.clips.find(T=>T.name===I);C&&(M.action&&M.action.stop(),M.action=M.mixer.clipAction(C),M.action.play(),M.action.paused=!M.playing,A?.(M.clips.map(T=>T.name),C.duration))}})),N.useEffect(()=>{const I=x.current;if(!I)return;S(!0);const M=I.clientWidth,C=I.clientHeight,T=new dx({antialias:Fu.antialias,alpha:!0});T.setSize(M,C),T.setPixelRatio(Math.min(window.devicePixelRatio,Fu.maxPixelRatio)),T.setClearColor(Ex.color,1),T.toneMapping=T8[Fu.toneMapping]??vf,T.toneMappingExposure=Fu.toneMappingExposure,T.shadowMap.enabled=!0,T.shadowMap.type=TM,I.appendChild(T.domElement);const B=new tx,L=new Mi(Eo.fov,M/C,Eo.near,Eo.far);L.position.set(Eo.position.x,Eo.position.y,Eo.position.z);const O=new oT(L,T.domElement);O.enableDamping=iv.enableDamping,O.dampingFactor=iv.dampingFactor,B.add(new cx(ji.ambient.color,ji.ambient.intensity));const R=new uf(ji.key.color,ji.key.intensity);R.position.set(ji.key.position.x,ji.key.position.y,ji.key.position.z),R.castShadow=ji.key.castShadow,B.add(R);const F=new uf(ji.fill.color,ji.fill.intensity);F.position.set(ji.fill.position.x,ji.fill.position.y,ji.fill.position.z),B.add(F);const j=Ls.enabled?qC(p):null;j&&B.add(j);const V=m?YC(p):null;V&&B.add(V);const W=new ck;y.current={renderer:T,scene:B,camera:L,controls:O,mixer:null,clock:W,action:null,clips:[],gridHelper:j,humanScaleRef:V,frameId:0,playing:!1};function te(){y.current.frameId=requestAnimationFrame(te);const ee=y.current,q=ee.clock.getDelta();ee.mixer&&ee.playing&&ee.mixer.update(q),O.update(),T.render(B,L),ee.action&&h&&h(ee.action.time,ee.action.getClip().duration)}te();const ne=new ResizeObserver(ee=>{for(const q of ee){const{width:Q,height:re}=q.contentRect;Q===0||re===0||(L.aspect=Q/re,L.updateProjectionMatrix(),T.setSize(Q,re))}});ne.observe(I);let k=!1,X=null;const Y=requestAnimationFrame(()=>{X=window.setTimeout(()=>{const ee=y.current;if(!(!ee||k))try{let q=null;if(i){if(q=i,B.add(q),XC(L,O,q),u&&u.length>0){const Q=[];q.traverse(re=>{re instanceof Nn&&Q.push(re)});for(const re of u){const ue=Q[0];if(!ue)continue;const xe=Array.isArray(ue.material)?ue.material:[ue.material],Me=re.subMeshIndex;if(Me<xe.length){const se=new Ro({color:16777215,roughness:.5,metalness:0});$0(se,re.properties);const Ae=xe[Me];xe[Me]=se,Array.isArray(ue.material)?ue.material=xe:ue.material=se,Ae.dispose()}}}}else if(e&&t){const Q=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);if(t.split(".").pop()?.toLowerCase()==="fbx"&&(q=new $H().parse(Q,""),q.traverse(xe=>{xe instanceof Nn&&(xe.castShadow=!0,xe.receiveShadow=!0,(!xe.material||Array.isArray(xe.material)&&xe.material.length===0)&&(xe.material=new Ro({color:bT.color})))}),B.add(q),XC(L,O,q),u&&u.length>0)){const xe=[];q.traverse(Me=>{Me instanceof Nn&&xe.push(Me)});for(const Me of u){const se=xe[Me.subMeshIndex];if(!se)continue;const Ae=new Ro({color:16777215,roughness:.5,metalness:0});$0(Ae,Me.properties);const Qe=se.material;se.material=Ae,Array.isArray(Qe)?Qe.forEach(We=>We.dispose()):Qe.dispose()}}}if(q){let Q=[];if(a&&a.length>0?Q=i?a:w8(a,q):i||(Q=q.animations??[]),Q.length>0){const re=new Set;q.traverse(xe=>{xe.name&&re.add(xe.name)});const ue=Q.map(xe=>{const Me=xe.tracks.filter(se=>{const Ae=se.name.split(".")[0];return re.has(Ae)});return new Uo(xe.name,xe.duration,Me)}).filter(xe=>xe.tracks.length>0);ue.length>0&&(ee.clips=ue,ee.mixer=new Ek(q),ee.action=ee.mixer.clipAction(ue[0]),ee.action.play(),ee.playing=!0,ee.clock.start(),A?.(ue.map(xe=>xe.name),ue[0].duration))}}}catch(q){console.error("Failed to load model for preview:",q)}finally{k||S(!1)}},0)});return()=>{const ee=performance.now();k=!0,cancelAnimationFrame(Y),X!==null&&clearTimeout(X),ne.disconnect(),cancelAnimationFrame(y.current?.frameId??0),O.dispose(),y.current?.mixer?.stopAllAction(),y.current?.gridHelper&&(B.remove(y.current.gridHelper),yh(y.current.gridHelper),y.current.gridHelper=null),y.current?.humanScaleRef&&(B.remove(y.current.humanScaleRef),yh(y.current.humanScaleRef),y.current.humanScaleRef=null),T.dispose(),B.traverse(q=>{(q instanceof Nn||q instanceof Ip||q instanceof ax)&&(q.geometry.dispose(),Array.isArray(q.material)?q.material.forEach(Q=>Q.dispose()):q.material.dispose())}),I.contains(T.domElement)&&I.removeChild(T.domElement),y.current=null,console.log(`[MeshViewport] cleanup: ${(performance.now()-ee).toFixed(1)}ms`)}},[e,t,i,a,o,l,u,I8]),N.useEffect(()=>{const I=y.current;I&&(Ls.enabled&&(I.gridHelper&&(I.scene.remove(I.gridHelper),yh(I.gridHelper)),I.gridHelper=qC(p),I.scene.add(I.gridHelper)),m?I.humanScaleRef?CT(I.humanScaleRef,p):(I.humanScaleRef=YC(p),I.scene.add(I.humanScaleRef)):I.humanScaleRef&&(I.scene.remove(I.humanScaleRef),yh(I.humanScaleRef),I.humanScaleRef=null))},[p,m]),b.jsx("div",{ref:x,className:`relative ${f??""}`,style:{minHeight:300},children:E&&b.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-background/70",children:b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-card px-4 py-2 shadow-lg",children:[b.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border-2 border-primary border-t-transparent"}),b.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading mesh preview..."})]})})})});function XC(n,e,t){const i=new Go().setFromObject(t),a=i.getSize(new he),o=i.getCenter(new he),l=Math.max(a.x,a.y,a.z),u=n.fov*(Math.PI/180),f=l/2/Math.tan(u/2)*bo.distanceMultiplier;n.position.set(o.x+f*bo.offsetX,o.y+f*bo.offsetY,o.z+f*bo.offsetZ),e.target.copy(o),n.near=f*bo.nearFraction,n.far=f*bo.farMultiplier,n.updateProjectionMatrix(),e.update()}function ST(n){return typeof n!="number"||!Number.isFinite(n)||n<=0?Ls.unitSize:Math.max(.05,n)}function qC(n){const e=ST(n),t=Math.max(e,Ls.size*.5),a=Math.max(1,Math.ceil(t/e))*2,o=a*e;return new iI(o,a,Ls.colorCenter,Ls.colorGrid)}function YC(n){const e=new Qa;e.name="human-scale-reference";const t=new Ro({color:8316807,roughness:.55,metalness:.05}),i=new Cp({color:8316807,transparent:!0,opacity:.35,side:Ur}),a=new Nn(new zu(.07,.08,.9,10),t);a.position.set(-.1,.45,0),e.add(a);const o=new Nn(new zu(.07,.08,.9,10),t);o.position.set(.1,.45,0),e.add(o);const l=new Nn(new zu(.16,.18,.75,12),t);l.position.set(0,1.275,0),e.add(l);const u=new Nn(new Bp(.175,16,12),t);u.position.set(0,1.825,0),e.add(u);const f=new Nn(new ox(.2,.27,24),i);return f.rotation.x=-Math.PI*.5,f.position.y=.01,e.add(f),CT(e,n),e}function CT(n,e){const t=ST(e);n.position.set(Math.max(1,t*1.5),0,0)}function yh(n){const e=new Set;n.traverse(t=>{if(t instanceof Nn||t instanceof Ip||t instanceof ax){t.geometry.dispose();const i=Array.isArray(t.material)?t.material:[t.material];for(const a of i)e.has(a)||(a.dispose(),e.add(a))}})}function sp({viewportRef:n,className:e}){const[t,i]=N.useState(!0),[a,o]=N.useState(!0),[l,u]=N.useState(0),[f,h]=N.useState(0),[A,p]=N.useState([]),[m,g]=N.useState("");N.useEffect(()=>{let C=0;function T(){const B=n.current;if(B){u(B.getTime());const L=B.getDuration();L>0&&L!==f&&h(L)}C=requestAnimationFrame(T)}return T(),()=>cancelAnimationFrame(C)},[n,f]),N.useEffect(()=>{const C=n.current;if(!C)return;const T=C.getClipNames();T.length>0&&(p(T),g(T[0]),h(C.getDuration()))},[n]);const x=N.useCallback(()=>{const C=n.current;C&&(t?(C.pause(),i(!1)):(C.play(),i(!0)))},[n,t]),E=N.useCallback(()=>{n.current?.stop(),i(!1),u(0)},[n]),S=N.useCallback(()=>{const C=!a;n.current?.setLoop(C),o(C)},[n,a]),y=N.useCallback(C=>{const T=parseFloat(C.target.value);n.current?.setTime(T),u(T)},[n]),I=N.useCallback(C=>{const T=C.target.value;n.current?.setClip(T),g(T),i(!0)},[n]);if(A.length===0)return null;const M=C=>C.toFixed(2);return b.jsxs("div",{className:nn("flex items-center gap-2 border-t border-border bg-card px-2 h-[52px] w-full rounded-xl",e),children:[b.jsx(Ei,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:x,children:t?b.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:[b.jsx("rect",{x:"3",y:"2",width:"3",height:"10",rx:"0.5"}),b.jsx("rect",{x:"8",y:"2",width:"3",height:"10",rx:"0.5"})]}):b.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:b.jsx("path",{d:"M3 1.5v11l9-5.5z"})})}),b.jsx(Ei,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:E,children:b.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:b.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"})})}),b.jsx(Ei,{variant:"ghost",size:"sm",className:nn("h-7 w-7 p-0",a&&"text-blue-400"),onClick:S,children:b.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[b.jsx("path",{d:"M2 7a5 5 0 0 1 9-3m1 3a5 5 0 0 1-9 3"}),b.jsx("path",{d:"M11 2v3h-3M3 12V9h3"})]})}),b.jsxs("span",{className:"min-w-[80px] text-center font-mono text-[11px] text-muted-foreground",children:[M(l)," / ",M(f)]}),b.jsx("input",{type:"range",min:0,max:f,step:.01,value:l,onChange:y,className:"h-1 flex-1 cursor-pointer accent-blue-400"}),A.length>1&&b.jsx("select",{value:m,onChange:I,className:"h-7 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:A.map(C=>b.jsx("option",{value:C,children:C},C))})]})}const rv=128,B8=64,R8=64,D8=128,KC=64,N8=64,JC=32,ZC=32,L8=64;class wT{view;pos;constructor(e,t=0){e instanceof Uint8Array?this.view=new DataView(e.buffer,e.byteOffset,e.byteLength):this.view=new DataView(e),this.pos=t}readUint32(){const e=this.view.getUint32(this.pos,!0);return this.pos+=4,e}readInt32(){const e=this.view.getInt32(this.pos,!0);return this.pos+=4,e}readUint64(){const e=this.view.getBigUint64(this.pos,!0);return this.pos+=8,e}readUint64AsNumber(){return Number(this.readUint64())}readFloat32(){const e=this.view.getFloat32(this.pos,!0);return this.pos+=4,e}readFixedString(e){const t=new Uint8Array(this.view.buffer,this.view.byteOffset+this.pos,e);this.pos+=e;const i=t.indexOf(0);return new TextDecoder().decode(t.subarray(0,i>=0?i:e))}readBytes(e){const t=new Uint8Array(this.view.buffer,this.view.byteOffset+this.pos,e);return this.pos+=e,t.slice()}seek(e){this.pos=e}tell(){return this.pos}get remaining(){return this.view.byteLength-this.pos}}function U8(n){return{name:n.readFixedString(B8),parentIndex:n.readInt32(),position:[n.readFloat32(),n.readFloat32(),n.readFloat32()],rotation:[n.readFloat32(),n.readFloat32(),n.readFloat32(),n.readFloat32()],scale:[n.readFloat32(),n.readFloat32(),n.readFloat32()],meshCount:n.readUint32(),firstMeshIndex:n.readUint32()}}function P8(n){return{fieldName:n.readFixedString(KC),value:[n.readFloat32(),n.readFloat32(),n.readFloat32(),n.readFloat32()],textureId:n.readFixedString(KC)}}function F8(n){return{name:n.readFixedString(R8),schemaId:n.readFixedString(D8),propertyCount:n.readUint32(),properties:[]}}function O8(n){return{trackName:n.readFixedString(L8),keyframeCount:n.readUint32(),valuesPerKey:n.readUint32(),timesOffset:n.readUint64AsNumber(),valuesOffset:n.readUint64AsNumber()}}function k8(n){const e=new wT(n),t=e.readFixedString(rv),i=e.readFixedString(rv),a=e.readUint32(),o=e.readFloat32(),l=e.readUint32(),u=[];for(let f=0;f<l;f++)u.push(O8(e));return{stringId:t,targetMeshId:i,metadataVersion:a,duration:o,trackCount:l,tracks:u}}function Q8(n){return{vertexCount:n.readUint32(),indexCount:n.readUint32(),hasNormals:n.readUint32(),hasUvs:n.readUint32(),vertexBufferOffset:n.readUint64AsNumber(),vertexBufferSize:n.readUint64AsNumber(),indexBufferOffset:n.readUint64AsNumber(),indexBufferSize:n.readUint64AsNumber(),weightsOffset:n.readUint64AsNumber(),weightsSize:n.readUint64AsNumber(),materialIndex:n.readUint32(),_padding:n.readUint32()}}function z8(n){const e=n.readFixedString(N8),t=n.readInt32(),i=[];for(let a=0;a<16;a++)i.push(n.readFloat32());return{name:e,parentIndex:t,offsetMatrix:i}}function G8(n){const e=new wT(n),t=e.readUint32(),i=e.readUint32(),a=e.readUint32(),o=e.readUint32(),l=e.readFixedString(rv),u=[];for(let g=0;g<t;g++)u.push(Q8(e));const f=[];for(let g=0;g<i;g++)f.push(F8(e));const h=[];for(let g=0;g<a;g++)h.push(U8(e));const A=h.reduce((g,x)=>g+x.meshCount,0),p=[];for(let g=0;g<A;g++)p.push(e.readUint32());for(const g of f)for(let x=0;x<g.propertyCount;x++)g.properties.push(P8(e));const m=[];for(let g=0;g<o;g++)m.push(z8(e));return{meshGeometryCount:t,materialCount:i,nodeCount:a,boneCount:o,stringId:l,geometries:u,materials:f,nodes:h,meshIndices:p,bones:m}}function MT(n,e){const t=G8(e),i=new DataView(n.buffer,n.byteOffset,n.byteLength),a=n.byteLength,o=t.geometries.slice().filter(Y=>{if(Y.vertexCount===0)return!1;const ee=Y.vertexBufferOffset+Y.vertexCount*ZC,q=Y.indexBufferOffset+Y.indexCount*4,Q=Y.weightsOffset+Y.vertexCount*JC;return ee>a||q>a||Q>a?(console.warn(`[skinned-preview] Geometry out of bounds (data=${a}, vertEnd=${ee}, idxEnd=${q}, wEnd=${Q}), skipping`),!1):!0}).sort((Y,ee)=>Y.vertexBufferOffset-ee.vertexBufferOffset),l=o.reduce((Y,ee)=>Y+ee.vertexCount,0),u=o.reduce((Y,ee)=>Y+ee.indexCount,0),f=new Float32Array(l*3),h=new Float32Array(l*3),A=new Float32Array(l*2),p=new Uint16Array(l*4),m=new Float32Array(l*4),g=new Uint32Array(u);let x=0,E=0;const S=ZC/4,y=JC/4;for(const Y of o){for(let ee=0;ee<Y.vertexCount;ee++){const q=Y.vertexBufferOffset+ee*S*4,Q=x+ee;f[Q*3]=i.getFloat32(q,!0),f[Q*3+1]=i.getFloat32(q+4,!0),f[Q*3+2]=i.getFloat32(q+8,!0),h[Q*3]=i.getFloat32(q+12,!0),h[Q*3+1]=i.getFloat32(q+16,!0),h[Q*3+2]=i.getFloat32(q+20,!0),A[Q*2]=i.getFloat32(q+24,!0),A[Q*2+1]=i.getFloat32(q+28,!0);const re=Y.weightsOffset+ee*y*4;for(let ue=0;ue<4;ue++)p[Q*4+ue]=i.getUint32(re+ue*4,!0),m[Q*4+ue]=i.getFloat32(re+16+ue*4,!0)}for(let ee=0;ee<Y.indexCount;ee++)g[E+ee]=i.getUint32(Y.indexBufferOffset+ee*4,!0)+x;x+=Y.vertexCount,E+=Y.indexCount}const I=new fi;I.setAttribute("position",new Pi(f,3)),I.setAttribute("normal",new Pi(h,3)),I.setAttribute("uv",new Pi(A,2)),I.setAttribute("skinIndex",new wp(p,4)),I.setAttribute("skinWeight",new Pi(m,4)),I.setIndex(new Pi(g,1));let M=0;for(const Y of o)I.addGroup(M,Y.indexCount,Math.min(Y.materialIndex,Math.max(t.materialCount-1,0))),M+=Y.indexCount;let C=!1;for(let Y=0;Y<f.length;Y++)Number.isFinite(f[Y])||(C=!0,f[Y]=0);C&&console.warn("[skinned-preview] NaN values in position data — replaced with 0"),I.computeBoundingBox(),I.computeBoundingSphere();const T=[];for(let Y=0;Y<t.materialCount;Y++){const ee=t.materials[Y],q=new Ro({side:Ur,name:ee.name||`Material_${Y}`,color:new Ct(.8,.8,.8),metalness:0,roughness:1});for(const Q of ee.properties){const re=Q.fieldName.toLowerCase();re.includes("color")||re.includes("tint")?q.color.setRGB(Q.value[0],Q.value[1],Q.value[2]):re==="metallic"?q.metalness=Q.value[0]:re==="roughness"?q.roughness=Q.value[0]:re==="alphatest"&&Q.value[0]>0&&(q.alphaTest=.5,q.transparent=!0)}T.push(q)}T.length===0&&T.push(new Ro({color:13421772,roughness:1}));const B=[],L=[],O=[],R=[];for(const Y of t.bones){const ee=new vt;ee.fromArray(Y.offsetMatrix);const q=new tp;q.name=Kt.sanitizeNodeName(Y.name),B.push(q),L.push(Y.parentIndex),O.push(ee),R.push(ee.clone().invert())}for(let Y=0;Y<B.length;Y++){const ee=L[Y];ee>=0&&ee<B.length&&ee!==Y&&B[ee].add(B[Y])}const F=new he,j=new Rn,V=new he;for(let Y=0;Y<B.length;Y++){const ee=R[Y],q=L[Y];if(q<0||q>=R.length)ee.decompose(F,j,V);else{const Q=new vt().copy(R[q]).invert();new vt().multiplyMatrices(Q,ee).decompose(F,j,V)}B[Y].position.copy(F),B[Y].quaternion.copy(j),B[Y].scale.set(1,1,1),B[Y].updateMatrix()}const W=B.filter((Y,ee)=>L[ee]<0),te=new Mp(B,O),ne=new qM(I,T);ne.frustumCulled=!1,ne.castShadow=!0,ne.receiveShadow=!0;const k=new Qa;k.name="BoneContainer",W.forEach(Y=>k.add(Y));const X=new Qa;return X.name=t.stringId||"SkinnedMesh",X.add(k),X.add(ne),X.updateMatrixWorld(!0),te.calculateInverses(),ne.bind(te,ne.matrixWorld),ne.normalizeSkinWeights(),X}function av(n,e){const t=k8(e),i=new DataView(n.buffer,n.byteOffset,n.byteLength),a=[];for(const o of t.tracks){if(o.trackName.endsWith(".scale"))continue;const l=new Float32Array(o.keyframeCount);for(let h=0;h<o.keyframeCount;h++)l[h]=i.getFloat32(o.timesOffset+h*4,!0);const u=o.keyframeCount*o.valuesPerKey,f=new Float32Array(u);for(let h=0;h<u;h++)f[h]=i.getFloat32(o.valuesOffset+h*4,!0);o.trackName.endsWith(".quaternion")?a.push(new aa(o.trackName,Array.from(l),Array.from(f))):a.push(new ks(o.trackName,Array.from(l),Array.from(f)))}return new Uo(t.stringId||"default",t.duration,a)}function H8({asset:n}){return b.jsx("div",{className:"flex h-full w-full items-center justify-center overflow-hidden p-6",children:n.previewUrl&&b.jsx("img",{className:"checkerboard h-full w-full rounded-lg border border-border object-contain",src:n.previewUrl,alt:n.fileName})})}function $C(n){if(!isFinite(n))return"0:00";const e=Math.floor(n/60),t=Math.floor(n%60);return`${e}:${t.toString().padStart(2,"0")}`}function V8({volume:n,muted:e}){return e||n===0?b.jsx(pP,{className:"size-4"}):n<.5?b.jsx(uP,{className:"size-4"}):b.jsx(dP,{className:"size-4"})}function ew(n,e){const t=N.useRef(!1),i=N.useCallback(u=>{const f=n.current?.getBoundingClientRect();return!f||f.width===0?0:Math.max(0,Math.min(1,(u.clientX-f.left)/f.width))},[n]),a=N.useCallback(u=>{u.currentTarget.setPointerCapture(u.pointerId),t.current=!0,e(i(u))},[i,e]),o=N.useCallback(u=>{t.current&&e(i(u))},[i,e]),l=N.useCallback(()=>{t.current=!1},[]);return{onPointerDown:a,onPointerMove:o,onPointerUp:l}}let s0=1,Eh=!1;const j8=[.25,.5,1,2];let tw=1,nw=!1;function W8(n){return`${n} ${n===1?"meter":"meters"}`}function IT(){const[n,e]=N.useState(tw),[t,i]=N.useState(nw),a=N.useCallback(l=>{!Number.isFinite(l)||l<=0||(tw=l,e(l))},[]),o=N.useCallback(l=>{nw=l,i(l)},[]);return{gridUnitSize:n,setGridUnitSize:a,showHumanScale:t,setShowHumanScale:o}}function op({gridUnitSize:n,onGridUnitSizeChange:e,showHumanScale:t,onShowHumanScaleChange:i}){return b.jsxs("div",{className:"absolute left-3 top-3 z-20 flex items-center gap-2 rounded-md border border-border/70 bg-background/85 p-2 shadow-sm backdrop-blur-sm",children:[b.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Scale (meters)"}),b.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[b.jsx("span",{children:"Grid"}),b.jsx("select",{className:"h-7 rounded-md border border-input bg-background px-2 text-xs text-foreground outline-none focus-visible:border-ring",value:String(n),onChange:a=>e(Number(a.target.value)),children:j8.map(a=>b.jsx("option",{value:a,children:W8(a)},a))})]}),b.jsxs(Ei,{variant:t?"default":"outline",size:"xs",className:"h-7 min-w-[118px] justify-between",onClick:()=>i(!t),"aria-pressed":t,children:[b.jsx("span",{children:"2m Human"}),b.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wide",children:[b.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${t?"bg-emerald-300":"bg-muted-foreground/50"}`}),t?"On":"Off"]})]})]})}function X8({asset:n}){const e=N.useRef(null),t=N.useRef(null),i=N.useRef(null),a=N.useRef(0),[o,l]=N.useState(!1),[u,f]=N.useState(0),[h,A]=N.useState(0),[p,m]=N.useState(s0),[g,x]=N.useState(Eh);N.useEffect(()=>{l(!1),f(0),A(0);const B=e.current;B&&(B.volume=s0,B.muted=Eh)},[n.previewUrl]),N.useEffect(()=>{if(!o)return;const B=()=>{const L=e.current;L&&f(L.currentTime),a.current=requestAnimationFrame(B)};return a.current=requestAnimationFrame(B),()=>cancelAnimationFrame(a.current)},[o]);const E=N.useCallback(()=>{const B=e.current;B&&(B.paused?(B.play().catch(L=>{console.warn("[AudioPreview] play failed:",L),l(!1)}),l(!0)):(B.pause(),l(!1)))},[]),S=N.useCallback(()=>{const B=e.current;B&&(B.muted=!B.muted,Eh=B.muted,x(B.muted))},[]),y=N.useCallback(B=>{const L=e.current;!L||!isFinite(L.duration)||(L.currentTime=B*L.duration,f(L.currentTime))},[]),I=N.useCallback(B=>{const L=e.current;L&&(L.volume=B,s0=B,m(B),B>0&&L.muted&&(L.muted=!1,Eh=!1,x(!1)))},[]),M=ew(t,y),C=ew(i,I),T=h>0?u/h*100:0;return b.jsxs("div",{className:"flex h-full items-center justify-center p-6",children:[b.jsx("audio",{ref:e,src:n.previewUrl,preload:"auto",onLoadedMetadata:()=>A(e.current?.duration??0),onEnded:()=>l(!1)},n.previewUrl),b.jsxs("div",{className:"flex w-full max-w-lg items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 shadow-sm",children:[b.jsx(Ei,{variant:"ghost",size:"icon-sm",className:"shrink-0",onClick:E,children:o?b.jsx(nP,{className:"size-4"}):b.jsx(rP,{className:"size-4"})}),b.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:$C(u)}),b.jsx("div",{ref:t,className:"relative flex-1 cursor-pointer py-2 select-none",...M,children:b.jsx("div",{className:"h-1 overflow-hidden rounded-full bg-muted",children:b.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${T}%`}})})}),b.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:$C(h)}),b.jsx(Ei,{variant:"ghost",size:"icon-sm",className:"shrink-0",onClick:S,children:b.jsx(V8,{volume:p,muted:g})}),b.jsx("div",{ref:i,className:"relative w-16 shrink-0 cursor-pointer py-2 select-none",...C,children:b.jsx("div",{className:"h-1 overflow-hidden rounded-full bg-muted",children:b.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${(g?0:p)*100}%`}})})})]})]})}function q8({asset:n}){const{state:e}=yn(),t=wn.getSource(n.id),i=N.useRef(null),[a,o]=N.useState(!1),{gridUnitSize:l,setGridUnitSize:u,showHumanScale:f,setShowHumanScale:h}=IT(),A=N.useMemo(()=>YI(n,e.assets),[n.settings.materialOverrides,e.assets]),p=n.type===at.SkinnedMesh,m=N.useMemo(()=>{if(!p)return null;const x=wn.getProcessed(n.id),E=wn.getProcessed(`${n.id}:skinnedMeta`);if(!x||!E)return null;try{return MT(x,E)}catch(S){return console.error("[MeshPreview] Failed to build skinned mesh from processed data:",S),null}},[p,n.id,n.status]),g=N.useMemo(()=>{if(!p)return;const x=[],E=wn.getProcessed(`${n.id}:animCount`),S=E?E[0]:0;for(let y=0;y<S;y++){const I=wn.getProcessed(`${n.id}:anim:${y}`),M=wn.getProcessed(`${n.id}:animMeta:${y}`);if(!(!I||!M))try{x.push(av(I,M))}catch{}}return x.length>0?x:void 0},[p,n.id,n.status]);return p?m?b.jsxs("div",{className:"relative h-full",children:[b.jsx(op,{gridUnitSize:l,onGridUnitSizeChange:u,showHumanScale:f,onShowHumanScaleChange:h}),b.jsx(ap,{ref:i,previewGroup:m,animationClips:g,materialOverrides:A.length>0?A:void 0,gridUnitSize:l,showHumanScale:f,className:"h-full w-full",onAnimationInfo:x=>{o(x.length>0)}}),a&&b.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 pb-3",children:b.jsx(sp,{viewportRef:i})})]}):null:t?b.jsxs("div",{className:"relative h-full",children:[b.jsx(op,{gridUnitSize:l,onGridUnitSizeChange:u,showHumanScale:f,onShowHumanScaleChange:h}),b.jsx(ap,{ref:i,sourceData:t,fileName:n.fileName,materialOverrides:A.length>0?A:void 0,gridUnitSize:l,showHumanScale:f,className:"h-full w-full",onAnimationInfo:x=>{o(x.length>0)}}),a&&b.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 pb-3",children:b.jsx(sp,{viewportRef:i})})]}):null}function Y8({asset:n}){const{state:e}=yn(),t=N.useRef(null),[i,a]=N.useState(!1),{gridUnitSize:o,setGridUnitSize:l,showHumanScale:u,setShowHumanScale:f}=IT(),h=wn.getSource(n.id),A=n.settings.targetMeshId,p=A?e.assets.find(C=>C.id===A):null,m=p?.type===at.SkinnedMesh,g=N.useMemo(()=>{if(!m||!p)return null;const C=wn.getProcessed(p.id),T=wn.getProcessed(`${p.id}:skinnedMeta`);if(!C||!T)return null;try{return MT(C,T)}catch(B){return console.error("[AnimationClipPreview] Failed to build skinned mesh from processed data:",B),null}},[m,p?.id,p?.status]),x=N.useMemo(()=>{const C=[],T=wn.getProcessed(n.id),B=wn.getProcessed(`${n.id}:animMeta`);if(T&&B)try{C.push(av(T,B))}catch{}const L=wn.getProcessed(`${n.id}:animCount`),O=L?L[0]:1;for(let R=1;R<O;R++){const F=wn.getProcessed(`${n.id}:anim:${R}`),j=wn.getProcessed(`${n.id}:animMeta:${R}`);if(!(!F||!j))try{C.push(av(F,j))}catch{}}return C},[n.id,n.status]),E=N.useMemo(()=>x.length>0?x:h?C8(h):[],[x,h]),S=N.useMemo(()=>p?YI(p,e.assets):[],[p,e.assets]);if(E.length===0)return null;if(g)return b.jsxs("div",{className:"relative h-full",children:[b.jsx(op,{gridUnitSize:o,onGridUnitSizeChange:l,showHumanScale:u,onShowHumanScaleChange:f}),b.jsx(ap,{ref:t,previewGroup:g,animationClips:E,materialOverrides:S.length>0?S:void 0,gridUnitSize:o,showHumanScale:u,className:"h-full w-full",onAnimationInfo:C=>{a(C.length>0)}}),i&&b.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 pb-3",children:b.jsx(sp,{viewportRef:t})})]});const I=(p?wn.getSource(p.id):null)??h,M=p?p.fileName:n.fileName;return I?b.jsxs("div",{className:"relative h-full",children:[b.jsx(op,{gridUnitSize:o,onGridUnitSizeChange:l,showHumanScale:u,onShowHumanScaleChange:f}),b.jsx(ap,{ref:t,sourceData:I,fileName:M,animationClips:E,materialOverrides:S.length>0?S:void 0,gridUnitSize:o,showHumanScale:u,className:"h-full w-full",onAnimationInfo:C=>{a(C.length>0)}}),i&&b.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 pb-3",children:b.jsx(sp,{viewportRef:t})})]}):null}let Io=null;function K8(){if(Io)return Io;const n=new dx({antialias:!0,alpha:!0});n.setPixelRatio(Math.min(window.devicePixelRatio,2)),n.setClearColor(Ex.color,1),n.toneMapping=vf,n.toneMappingExposure=1;const e=new tx;e.add(new cx(16777215,.4));const t=new uf(16777215,1.2);t.position.set(3,4,5),e.add(t);const i=new uf(16777215,.3);i.position.set(-2,1,-3),e.add(i);const a=new Ro({color:16777215,roughness:.5,metalness:0});e.add(new Nn(new Bp(1,64,64),a)),e.add(new iI(6,10,3355443,2236962));const o=new Mi(45,1,.1,100);return o.position.set(0,0,3),Io={renderer:n,scene:e,camera:o,material:a},Io}function J8({asset:n}){const e=N.useRef(null),t=N.useRef(0),i=n.settings.materialConfig,a=N.useMemo(()=>JSON.stringify(i.properties.map(o=>[o.previewFlag,o.value,o.textureAssetId])),[i.properties]);return N.useEffect(()=>{const o=performance.now(),l=e.current;if(!l)return;const{renderer:u,scene:f,camera:h}=K8();console.log(`[MatPreview] ensureScene: ${(performance.now()-o).toFixed(1)}ms (cached: ${Io!==null})`);const A=performance.now(),p=l.clientWidth,m=l.clientHeight;u.setSize(p,m),h.aspect=p/m,h.updateProjectionMatrix(),l.appendChild(u.domElement),console.log(`[MatPreview] attach+resize: ${(performance.now()-A).toFixed(1)}ms`);const g=performance.now(),x=new oT(h,u.domElement);x.enableDamping=!0,console.log(`[MatPreview] controls: ${(performance.now()-g).toFixed(1)}ms`);function E(){t.current=requestAnimationFrame(E),x.update(),u.render(f,h)}E();const S=new ResizeObserver(y=>{for(const I of y){const{width:M,height:C}=I.contentRect;M===0||C===0||(h.aspect=M/C,h.updateProjectionMatrix(),u.setSize(M,C))}});return S.observe(l),console.log(`[MatPreview] mount total: ${(performance.now()-o).toFixed(1)}ms`),()=>{S.disconnect(),cancelAnimationFrame(t.current),x.dispose(),l.contains(u.domElement)&&l.removeChild(u.domElement)}},[]),N.useEffect(()=>{const o=performance.now();if(!Io)return;const l=Io.material;l.color.set(16777215),l.map=null,l.alphaTest=0,l.transparent=!1,l.opacity=1,$0(l,i.properties),console.log(`[MatPreview] applyProperties: ${(performance.now()-o).toFixed(1)}ms`)},[a]),b.jsx("div",{ref:e,className:"h-full w-full",style:{minHeight:200}})}function Z8(){const{state:n}=yn(),e=n.selectedAssetIds.length>1,t=e?void 0:n.assets.find(o=>o.id===IM(n)),i=t&&t.status==="ready"&&t.type!==at.MaterialSchema,a=i?t.type===at.Texture2D||t.type===at.Audio?!!t.previewUrl:!!wn.getSource(t.id):!0;return b.jsxs("section",{className:"flex h-full flex-col bg-background",children:[b.jsxs("div",{className:"flex h-9 items-center gap-2 border-b border-border px-4",children:[b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Preview"}),t&&b.jsxs(b.Fragment,{children:[b.jsx(gc,{orientation:"vertical",className:"h-3.5!"}),b.jsx("span",{className:"truncate text-xs text-foreground",children:t.fileName}),b.jsx(Ef,{variant:t.status==="ready"?"default":"secondary",className:"text-[10px]",children:t.status})]})]}),b.jsxs("div",{className:"relative flex-1 min-h-0 overflow-hidden",children:[!t&&!e&&b.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select an asset to preview"}),e&&b.jsxs("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:[n.selectedAssetIds.length," assets selected"]}),t?.status==="error"&&!t.previewUrl&&b.jsx("div",{className:"flex h-full items-center justify-center px-6",children:b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:t.error})}),t&&t.status==="ready"&&t.type===at.Texture2D&&t.previewUrl&&b.jsx(H8,{asset:t}),t&&t.status==="ready"&&t.type===at.Audio&&t.previewUrl&&b.jsx(X8,{asset:t}),t&&t.status==="ready"&&(t.type===at.StaticMesh||t.type===at.SkinnedMesh)&&wn.getSource(t.id)&&b.jsx(q8,{asset:t}),t&&t.status==="ready"&&t.type===at.AnimationClip&&wn.getSource(t.id)&&b.jsx(Y8,{asset:t}),t&&t.type===at.MaterialSchema&&b.jsx(J8,{asset:t}),i&&!a&&b.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80",children:b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-card px-4 py-2 shadow-lg",children:[b.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border-2 border-primary border-t-transparent"}),b.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),(t?.status==="pending"||t?.status==="processing"||t?.status==="loading")&&b.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/60",children:b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-card px-4 py-2 shadow-lg",children:[b.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border-2 border-amber-400 border-t-transparent"}),b.jsx("span",{className:"text-sm text-amber-400",children:t.status==="pending"?"Queued...":t.status==="loading"?"Loading...":"Processing..."})]})})]})]})}const $8="modulepreload",e6=function(n){return"/"+n},iw={},t6=function(e,t,i){let a=Promise.resolve();if(t&&t.length>0){let f=function(h){return Promise.all(h.map(A=>Promise.resolve(A).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),u=l?.nonce||l?.getAttribute("nonce");a=f(t.map(h=>{if(h=e6(h),h in iw)return;iw[h]=!0;const A=h.endsWith(".css"),p=A?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${h}"]${p}`))return;const m=document.createElement("link");if(m.rel=A?"stylesheet":$8,A||(m.as="script"),m.crossOrigin="",m.href=h,u&&m.setAttribute("nonce",u),document.head.appendChild(m),A)return new Promise((g,x)=>{m.addEventListener("load",g),m.addEventListener("error",()=>x(new Error(`Unable to preload CSS for ${h}`)))})}))}function o(l){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=l,window.dispatchEvent(u),!u.defaultPrevented)throw l}return a.then(l=>{for(const u of l||[])u.status==="rejected"&&o(u.reason);return e().catch(o)})};function la({className:n,...e}){return b.jsx("div",{"data-slot":"card",className:nn("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",n),...e})}function ca({className:n,...e}){return b.jsx("div",{"data-slot":"card-content",className:nn("px-6",n),...e})}function n6({open:n,textures:e,materialPack:t,selectedId:i,onSelect:a,onClose:o}){const[l,u]=N.useState(""),f=N.useRef(null);N.useEffect(()=>{n&&(u(""),requestAnimationFrame(()=>f.current?.focus()))},[n]),N.useEffect(()=>{if(!n)return;function p(m){m.key==="Escape"&&o()}return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[n,o]);const h=N.useMemo(()=>{const p=l.toLowerCase();return e.filter(g=>p?g.fileName.toLowerCase().includes(p)||g.stringId.toLowerCase().includes(p):!0).sort((g,x)=>{const E=g.settings.pack===t?0:1,S=x.settings.pack===t?0:1;return E!==S?E-S:g.settings.pack!==x.settings.pack?g.settings.pack.localeCompare(x.settings.pack):g.fileName.localeCompare(x.fileName)})},[e,t,l]);if(!n)return null;function A(p){a(p),o()}return b.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onMouseDown:p=>{p.target===p.currentTarget&&o()},children:b.jsxs("div",{className:"flex w-[560px] max-h-[80vh] flex-col overflow-hidden rounded-xl border border-border bg-card shadow-2xl",children:[b.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[b.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Select Texture"}),b.jsx("button",{onClick:o,className:"rounded p-1 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:b.jsx(jb,{className:"size-4"})})]}),b.jsx("div",{className:"border-b border-border px-4 py-2",children:b.jsxs("div",{className:"relative",children:[b.jsx(sP,{className:"absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),b.jsx("input",{ref:f,type:"text",value:l,onChange:p=>u(p.target.value),placeholder:"Search textures…",className:"h-7 w-full rounded-md border border-border bg-background pl-7 pr-7 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),l&&b.jsx("button",{onClick:()=>u(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:b.jsx(jb,{className:"size-3.5"})})]})}),b.jsxs(xx,{className:"flex-1 min-h-0",children:[b.jsxs("div",{className:"grid grid-cols-4 gap-2 p-4",children:[b.jsxs("button",{onClick:()=>A(null),className:nn("group flex flex-col items-center gap-1.5 rounded-lg border p-2 transition-colors hover:bg-accent/50",i===null?"border-ring ring-1 ring-ring bg-accent/30":"border-border"),children:[b.jsx("div",{className:"flex aspect-square w-full items-center justify-center rounded-md bg-muted",children:b.jsx(QU,{className:"size-8 text-muted-foreground"})}),b.jsx("span",{className:"text-[10px] text-muted-foreground leading-tight",children:"No texture"})]}),h.map(p=>{const m=p.metadata,g=p.settings.pack===t,x=p.id===i;return b.jsxs("button",{onClick:()=>A(p.id),className:nn("group flex flex-col items-center gap-1.5 rounded-lg border p-2 transition-colors hover:bg-accent/50",x?"border-ring ring-1 ring-ring bg-accent/30":"border-border"),children:[b.jsxs("div",{className:"relative aspect-square w-full overflow-hidden rounded-md",children:[p.previewUrl?b.jsx("img",{src:p.previewUrl,alt:p.fileName,className:"checkerboard h-full w-full object-contain"}):b.jsx("div",{className:"flex h-full w-full items-center justify-center bg-muted text-[10px] text-muted-foreground",children:"No preview"}),b.jsx(Ef,{variant:g?"secondary":"outline",className:nn("absolute bottom-1 right-1 text-[9px] px-1 py-0 leading-tight max-w-[calc(100%-8px)] truncate",!g&&"border-amber-500/60 text-amber-600 dark:text-amber-400"),children:p.settings.pack})]}),b.jsxs("div",{className:"w-full min-w-0 text-center",children:[b.jsx("p",{className:"truncate text-[10px] leading-tight text-foreground",title:p.fileName,children:p.fileName}),m&&b.jsxs("p",{className:"text-[9px] text-muted-foreground",children:[m.width,"×",m.height]})]})]},p.id)})]}),h.length===0&&l&&b.jsxs("div",{className:"px-4 pb-4 text-center text-xs text-muted-foreground",children:['No textures matching "',l,'"']})]})]})})}function Oo(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function Vt({label:n,value:e}){return b.jsxs("div",{className:"flex items-center justify-between py-1",children:[b.jsx("span",{className:"text-xs text-muted-foreground",children:n}),b.jsx("span",{className:"font-mono text-xs text-foreground",children:e})]})}function qa({options:n,value:e,onChange:t}){return b.jsx("div",{className:"flex rounded-md border border-border overflow-hidden",children:n.map((i,a)=>b.jsx("button",{className:nn("flex-1 px-2 py-1 text-[11px] font-medium transition-colors",a>0&&"border-l border-border",i.value===e?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),onClick:()=>t(i.value),children:i.label},i.value))})}const Pp=[{label:"Static Mesh",value:at.StaticMesh},{label:"Skinned Mesh",value:at.SkinnedMesh},{label:"Animation",value:at.AnimationClip}];function o0(n){return n===at.StaticMesh||n===at.SkinnedMesh||n===at.AnimationClip}function i6({asset:n}){const{changeAssetType:e}=yn();return b.jsx(ai,{label:"Asset Type",children:b.jsx(qa,{options:Pp,value:n.type,onChange:t=>e(n.id,t)})})}function r6({asset:n}){const{state:e,updateAssetSettings:t}=yn(),i=e.assets.filter(a=>a.type===at.SkinnedMesh&&a.id!==n.id);return b.jsx(ai,{label:"Preview Mesh",children:i.length===0?b.jsx("p",{className:"text-[11px] text-muted-foreground",children:"No skinned meshes in project. Import one to preview this animation."}):b.jsxs("select",{value:n.settings.targetMeshId??"",onChange:a=>t(n.id,{targetMeshId:a.target.value||null}),className:"h-7 w-full rounded-md border border-border bg-background px-2 text-xs text-foreground",children:[b.jsx("option",{value:"",children:"None (skeleton only)"}),i.map(a=>b.jsx("option",{value:a.id,children:a.fileName},a.id))]})})}function a6({asset:n}){const{state:e,updateAssetSettings:t}=yn(),i=e.projectDir?.config.packs??[{name:"default"}],a=i.map(u=>u.name),o=n.settings.pack,l=a.includes(o)?o:a[0]??o;return N.useEffect(()=>{l!==o&&t(n.id,{pack:l})},[l,o,n.id,t]),b.jsx(ai,{label:"Pack",children:b.jsx("select",{className:"h-7 w-full rounded-md border border-border bg-background px-2 text-xs",value:l,onChange:u=>t(n.id,{pack:u.target.value}),children:i.map(u=>b.jsx("option",{value:u.name,children:u.name},u.name))})})}function s6({assets:n}){const{state:e,updateAssetSettings:t}=yn(),i=e.projectDir?.config.packs??[{name:"default"}],o=new Set(n.map(f=>f.settings.pack??"default")).size>1,l=o?"":n[0]?.settings.pack??"default";if(n.length===0)return null;function u(f){for(const h of n)h.settings.pack!==f&&t(h.id,{pack:f})}return b.jsx(ai,{label:"Pack",children:b.jsxs("select",{className:"h-7 w-full rounded-md border border-border bg-background px-2 text-xs",value:l,onChange:f=>u(f.target.value),children:[o&&b.jsx("option",{value:"",disabled:!0,children:"Mixed"}),i.map(f=>b.jsx("option",{value:f.name,children:f.name},f.name))]})})}function ai({label:n,children:e}){return b.jsxs("div",{className:"space-y-1.5",children:[b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:n}),e]})}function o6({asset:n}){const{state:e,dispatch:t}=yn(),[i,a]=N.useState(!1),[o,l]=N.useState(n.stringId),[u,f]=N.useState(""),h=N.useRef(null);N.useEffect(()=>{l(n.stringId),a(!1),f("")},[n.id,n.stringId]);function A(m){return e.assets.some(g=>g.id!==n.id&&g.stringId.toLowerCase()===m.toLowerCase())}function p(){const m=o.trim();if(m&&m!==n.stringId){if(A(m)){f(`"${m}" is already used by another asset`);return}t({type:"UPDATE_ASSET",id:n.id,updates:{stringId:m}}),e.projectDir&&t6(async()=>{const{assetSettingsToStowmeta:g,writeStowmeta:x}=await import("./stowmeta-io-DW71DbFo.js");return{assetSettingsToStowmeta:g,writeStowmeta:x}},[]).then(({assetSettingsToStowmeta:g,writeStowmeta:x})=>{const E={...n,stringId:m},S=g(E);x(e.projectDir.srcArtDir,n.id,S)})}else l(n.stringId);a(!1),f("")}return b.jsx(ai,{label:"String ID",children:i?b.jsxs(b.Fragment,{children:[b.jsx(Po,{ref:h,value:o,onChange:m=>{l(m.target.value),f("")},onBlur:p,onKeyDown:m=>{m.key==="Enter"&&p(),m.key==="Escape"&&(l(n.stringId),a(!1),f(""))},className:nn("h-7 text-xs font-mono",u&&"border-red-500"),autoFocus:!0}),u&&b.jsx("p",{className:"mt-1 text-xs text-red-500",children:u})]}):b.jsxs("button",{className:"flex w-full items-center rounded-md border border-border bg-muted/50 px-2.5 py-1 text-left font-mono text-xs text-foreground transition-colors hover:bg-muted",onClick:()=>{a(!0)},children:[b.jsx("span",{className:"flex-1 truncate",children:n.stringId}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"shrink-0 text-muted-foreground",children:b.jsx("path",{d:"M8.5 1.5l2 2-7 7H1.5V8.5l7-7z",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]})})}const l6=[{label:"Full",value:Du.Full},{label:"Half",value:Du.Half},{label:"Quarter",value:Du.Quarter},{label:"Eighth",value:Du.Eighth}],c6=[{label:"Fastest",value:Gl.Fastest},{label:"Fast",value:Gl.Fast},{label:"Normal",value:Gl.Normal},{label:"High",value:Gl.High},{label:"Best",value:Gl.Best}];function u6({asset:n}){const{updateAssetSettings:e}=yn();return b.jsxs(b.Fragment,{children:[b.jsx(ai,{label:"Resize",children:b.jsx(qa,{options:l6,value:n.settings.resize,onChange:t=>e(n.id,{resize:t})})}),b.jsx(ai,{label:"KTX2 Quality",children:b.jsx(qa,{options:c6,value:n.settings.quality,onChange:t=>e(n.id,{quality:t})})})]})}const f6=[{label:"Fast",value:Nu.Fast},{label:"Balanced",value:Nu.Balanced},{label:"High",value:Nu.HighQuality},{label:"Maximum",value:Nu.MaximumQuality}];function d6({asset:n}){const{updateAssetSettings:e}=yn();return b.jsx(ai,{label:"Compression Quality",children:b.jsx(qa,{options:f6,value:n.settings.dracoQuality,onChange:t=>e(n.id,{dracoQuality:t})})})}const h6=[{label:"Lowest",value:Hl.Lowest},{label:"Low",value:Hl.Low},{label:"Medium",value:Hl.Medium},{label:"High",value:Hl.High},{label:"Best",value:Hl.Best}],p6=[{label:"Auto",value:Vl.Auto},{label:"48 kHz",value:Vl.Hz48000},{label:"44.1 kHz",value:Vl.Hz44100},{label:"22 kHz",value:Vl.Hz22050},{label:"11 kHz",value:Vl.Hz11025}];function A6({asset:n}){const{updateAssetSettings:e}=yn();return b.jsxs(b.Fragment,{children:[b.jsx(ai,{label:"AAC Quality",children:b.jsx(qa,{options:h6,value:n.settings.aacQuality,onChange:t=>e(n.id,{aacQuality:t})})}),b.jsx(ai,{label:"Sample Rate",children:b.jsx(qa,{options:p6,value:n.settings.audioSampleRate,onChange:t=>e(n.id,{audioSampleRate:t})})})]})}function m6({asset:n}){const{updateAssetSettings:e}=yn(),[t,i]=N.useState("");function a(){const l=t.trim().toLowerCase();if(!l||n.settings.tags.includes(l)){i("");return}e(n.id,{tags:[...n.settings.tags,l]}),i("")}function o(l){e(n.id,{tags:n.settings.tags.filter(u=>u!==l)})}return b.jsxs(ai,{label:"Tags",children:[n.settings.tags.length>0&&b.jsx("div",{className:"flex flex-wrap gap-1",children:n.settings.tags.map(l=>b.jsxs(Ef,{variant:"secondary",className:"gap-1 pr-1 text-[10px]",children:[l,b.jsx("button",{className:"rounded-full p-0.5 hover:bg-destructive hover:text-destructive-foreground transition-colors",onClick:()=>o(l),children:b.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",children:b.jsx("path",{d:"M2 2l4 4M6 2l-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]},l))}),b.jsxs("div",{className:"flex gap-1.5",children:[b.jsx(Po,{value:t,onChange:l=>i(l.target.value),onKeyDown:l=>{l.key==="Enter"&&a()},placeholder:"Add tag...",className:"h-7 flex-1 text-xs"}),b.jsx(Ei,{variant:"outline",size:"sm",className:"h-7 w-7 shrink-0 p-0",onClick:a,disabled:!t.trim(),children:b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:b.jsx("path",{d:"M6 2v8M2 6h8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}function g6({asset:n}){const e=n.metadata;return e?b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Dimensions",value:`${e.width} x ${e.height}`}),b.jsx(Vt,{label:"Channels",value:String(e.channels)}),b.jsx(Vt,{label:"Format",value:"RGBA (KTX2)"}),b.jsx(Vt,{label:"Source",value:Oo(n.sourceSize)}),n.processedSize>0&&b.jsx(Vt,{label:"Compressed",value:Oo(n.processedSize)})]})}):null}function v6({asset:n}){const e=n.metadata;return e?b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Sample Rate",value:`${e.sampleRate.toLocaleString()} Hz`}),b.jsx(Vt,{label:"Channels",value:String(e.channels)}),b.jsx(Vt,{label:"Duration",value:`${(e.durationMs/1e3).toFixed(2)}s`}),b.jsx(Vt,{label:"Source",value:Oo(n.sourceSize)}),n.processedSize>0&&b.jsx(Vt,{label:"Compressed",value:Oo(n.processedSize)})]})}):null}function x6({asset:n}){const e=n.metadata;if(!e)return null;const t=e.geometries.reduce((a,o)=>a+o.vertexCount,0),i=e.geometries.reduce((a,o)=>a+o.indexCount/3,0);return b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Sub-meshes",value:String(e.meshGeometryCount)}),b.jsx(Vt,{label:"Vertices",value:t.toLocaleString()}),b.jsx(Vt,{label:"Triangles",value:Math.floor(i).toLocaleString()}),b.jsx(Vt,{label:"Materials",value:String(e.materialCount)}),b.jsx(Vt,{label:"Source",value:Oo(n.sourceSize)}),n.processedSize>0&&b.jsx(Vt,{label:"Compressed",value:Oo(n.processedSize)})]})})}function _6(n,e){const t=n.map((a,o)=>({name:a.name,index:o,parentIndex:a.parentIndex,children:[],hasTrack:e?e.has(a.name):void 0})),i=[];for(let a=0;a<n.length;a++){const o=n[a].parentIndex;o<0||o>=n.length?i.push(t[a]):t[o].children.push(t[a])}return i}function TT({node:n,depth:e,expanded:t,onToggle:i}){const a=n.children.length>0,o=t.has(n.index),l=n.parentIndex<0,u=n.children.length===0,f=[`Index: ${n.index}`,`Parent: ${l?"None (root)":n.parentIndex}`,`Children: ${n.children.length}`,`Depth: ${e}`,n.hasTrack===!0?"Has animation tracks":n.hasTrack===!1?"No animation tracks":""].filter(Boolean).join(`
4066
+ `);return b.jsxs(b.Fragment,{children:[b.jsxs("div",{className:"group flex items-center gap-1 py-0.5 hover:bg-muted/50 rounded-sm cursor-default select-none",style:{paddingLeft:e*14+4},title:f,children:[a?b.jsx("button",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground",onClick:()=>i(n.index),children:b.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:o?b.jsx("path",{d:"M2 4l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}):b.jsx("path",{d:"M4 2l3 3-3 3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}):b.jsx("span",{className:"h-4 w-4 shrink-0"}),b.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("shrink-0",l?"text-blue-400":"text-muted-foreground"),children:[b.jsx("circle",{cx:"3",cy:"3",r:"1.5",stroke:"currentColor",strokeWidth:"1"}),b.jsx("circle",{cx:"9",cy:"9",r:"1.5",stroke:"currentColor",strokeWidth:"1"}),b.jsx("line",{x1:"4.2",y1:"4.2",x2:"7.8",y2:"7.8",stroke:"currentColor",strokeWidth:"1"})]}),b.jsx("span",{className:nn("text-[11px] truncate flex-1",n.hasTrack===!0&&"text-green-400 font-medium",n.hasTrack===!1&&"text-muted-foreground",n.hasTrack===void 0&&"text-foreground"),children:n.name}),b.jsxs("span",{className:"text-[9px] font-mono text-muted-foreground/50 opacity-0 group-hover:opacity-100 transition-opacity shrink-0 mr-1",children:["#",n.index,a&&!u&&` (${n.children.length})`]})]}),a&&o&&n.children.map(h=>b.jsx(TT,{node:h,depth:e+1,expanded:t,onToggle:i},h.index))]})}function Fp(n){return n!==null&&typeof n=="object"&&"trackCount"in n}function y6({asset:n}){const[e,t]=N.useState(new Set),[i,a]=N.useState(!0),o=n.metadata,l=o?Fp(o):!1,u=o&&!l&&"bones"in o?o.bones:[],f=N.useMemo(()=>{if(n.type!==at.AnimationClip||l||u.length===0)return;const g=o;if(!g.bones)return;const x=new Set;for(const E of g.bones)x.add(E.name);return x},[n.type,o,l,u.length]),h=N.useMemo(()=>u.length>0?_6(u,f):[],[u,f]);if(!o||l||u.length===0)return null;function A(g){t(x=>{const E=new Set(x);return E.has(g)?E.delete(g):E.add(g),E})}function p(){const g=new Set;for(let x=0;x<u.length;x++)g.add(x);t(g)}function m(){t(new Set)}return b.jsxs("div",{className:"space-y-1.5",children:[b.jsxs("button",{className:"flex w-full items-center justify-between",onClick:()=>a(g=>!g),children:[b.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Bone Hierarchy (",u.length,")"]}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("text-muted-foreground transition-transform",!i&&"rotate-180"),children:b.jsx("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!i&&b.jsx(la,{children:b.jsxs(ca,{className:"p-2",children:[b.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[b.jsx("button",{className:"text-[10px] text-muted-foreground hover:text-foreground transition-colors",onClick:p,children:"Expand All"}),b.jsx("span",{className:"text-muted-foreground text-[10px]",children:"|"}),b.jsx("button",{className:"text-[10px] text-muted-foreground hover:text-foreground transition-colors",onClick:m,children:"Collapse All"}),b.jsx("span",{className:"text-muted-foreground text-[10px]",children:"|"}),b.jsx("span",{className:"text-[10px] text-blue-400",children:"● root"}),n.type===at.AnimationClip&&b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"text-muted-foreground text-[10px]",children:"|"}),b.jsx("span",{className:"text-[10px] text-green-400",children:"● animated"})]})]}),b.jsx("div",{className:"max-h-64 overflow-y-auto",children:h.map(g=>b.jsx(TT,{node:g,depth:0,expanded:e,onToggle:A},g.index))})]})})]})}function E6({asset:n}){const[e,t]=N.useState(!0),i=n.metadata;if(!i||!i.bones||i.bones.length===0)return null;const a=i.geometries.reduce((m,g)=>m+g.vertexCount,0),o=i.geometries.reduce((m,g)=>m+g.indexCount,0),l=i.bones.filter(m=>m.parentIndex<0),u=i.bones.filter((m,g)=>!i.bones.some(x=>x.parentIndex===g)),f=N.useMemo(()=>{const m=new Map;for(let g=0;g<i.bones.length;g++){let x=0,E=g;for(;i.bones[E].parentIndex>=0;)x++,E=i.bones[E].parentIndex;m.set(g,x)}return m},[i.bones]),h=Math.max(0,...f.values()),A=[];l.length>1&&A.push(`Multiple root bones (${l.length}): ${l.map(m=>m.name).join(", ")}`),l.length===0&&A.push("No root bone found — broken hierarchy");for(let m=0;m<i.bones.length;m++){const g=i.bones[m];g.parentIndex>=0&&g.parentIndex>=i.bones.length&&A.push(`Bone "${g.name}" [${m}] references out-of-range parent ${g.parentIndex}`),g.parentIndex===m&&A.push(`Bone "${g.name}" [${m}] is its own parent (cycle)`)}const p=N.useMemo(()=>{const m=new Map;for(const g of i.bones)m.set(g.name,(m.get(g.name)??0)+1);return Array.from(m.entries()).filter(([,g])=>g>1).map(([g,x])=>`"${g}" (x${x})`)},[i.bones]);return p.length>0&&A.push(`Duplicate bone names: ${p.join(", ")}`),b.jsxs("div",{className:"space-y-1.5",children:[b.jsxs("button",{className:"flex w-full items-center justify-between",onClick:()=>t(m=>!m),children:[b.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Skeleton Debug",A.length>0&&b.jsxs("span",{className:"ml-1.5 text-amber-400",children:["(",A.length," warning",A.length!==1?"s":"",")"]})]}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("text-muted-foreground transition-transform",!e&&"rotate-180"),children:b.jsx("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!e&&b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Bones",value:String(i.boneCount)}),b.jsx(Vt,{label:"Root Bones",value:l.map(m=>m.name).join(", ")||"None"}),b.jsx(Vt,{label:"Leaf Bones",value:String(u.length)}),b.jsx(Vt,{label:"Max Depth",value:String(h)}),b.jsx(Vt,{label:"Sub-meshes",value:String(i.meshGeometryCount)}),b.jsx(Vt,{label:"Total Vertices",value:a.toLocaleString()}),b.jsx(Vt,{label:"Total Triangles",value:Math.floor(o/3).toLocaleString()}),i.geometries.length>1&&b.jsx(b.Fragment,{children:i.geometries.map((m,g)=>b.jsx(Vt,{label:` Sub-mesh ${g}`,value:`${m.vertexCount.toLocaleString()} verts, ${Math.floor(m.indexCount/3).toLocaleString()} tris`},g))}),A.length>0&&b.jsx("div",{className:"pt-2 space-y-1",children:A.map((m,g)=>b.jsxs("div",{className:"flex items-start gap-1.5",children:[b.jsx("span",{className:"mt-0.5 h-2 w-2 shrink-0 rounded-full bg-amber-400"}),b.jsx("span",{className:"text-[11px] text-amber-400 break-all",children:m})]},g))})]})})]})}function b6({asset:n}){const{state:e}=yn(),[t,i]=N.useState(!0),a=n.metadata;if(!a||!Fp(a))return null;const o=a,l=o.tracks.filter(y=>y.trackName.endsWith(".position")),u=o.tracks.filter(y=>y.trackName.endsWith(".quaternion")),f=o.tracks.filter(y=>y.trackName.endsWith(".scale")),h=o.tracks.reduce((y,I)=>y+I.keyframeCount,0),A=N.useMemo(()=>{const y=new Set;for(const I of o.tracks){const M=I.trackName.lastIndexOf(".");M>0&&y.add(I.trackName.slice(0,M))}return y},[o.tracks]),p=o.duration>0?(h/o.tracks.length/o.duration).toFixed(1):"0",g=(n.settings.targetMeshId?e.assets.find(y=>y.id===n.settings.targetMeshId):void 0)?.metadata,x=N.useMemo(()=>{if(!g?.bones)return null;const y=new Set(g.bones.map(T=>T.name)),I=[...A].filter(T=>y.has(T)),M=[...A].filter(T=>!y.has(T)),C=g.bones.map(T=>T.name).filter(T=>!A.has(T));return{matched:I,missingInMesh:M,unanimated:C,meshBoneCount:g.bones.length}},[g,A]),E=[];o.duration<=0&&E.push("Duration is 0 or negative"),o.tracks.length===0&&E.push("No animation tracks"),x&&x.missingInMesh.length>0&&E.push(`${x.missingInMesh.length} animated bone${x.missingInMesh.length!==1?"s":""} not found in target mesh`);const S=o.tracks.filter(y=>y.keyframeCount<=1);return S.length>0&&E.push(`${S.length} track${S.length!==1?"s":""} with <= 1 keyframe (static)`),b.jsxs("div",{className:"space-y-1.5",children:[b.jsxs("button",{className:"flex w-full items-center justify-between",onClick:()=>i(y=>!y),children:[b.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Animation Debug",E.length>0&&b.jsxs("span",{className:"ml-1.5 text-amber-400",children:["(",E.length," warning",E.length!==1?"s":"",")"]})]}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("text-muted-foreground transition-transform",!t&&"rotate-180"),children:b.jsx("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!t&&b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Duration",value:`${o.duration.toFixed(3)}s`}),b.jsx(Vt,{label:"Animated Bones",value:String(A.size)}),b.jsx(Vt,{label:"Position Tracks",value:String(l.length)}),b.jsx(Vt,{label:"Rotation Tracks",value:String(u.length)}),b.jsx(Vt,{label:"Scale Tracks",value:String(f.length)}),b.jsx(Vt,{label:"Total Keyframes",value:h.toLocaleString()}),b.jsx(Vt,{label:"Avg Keys/sec/track",value:p}),x&&b.jsxs(b.Fragment,{children:[b.jsx(gc,{className:"my-1"}),b.jsx(Vt,{label:"Target Mesh Bones",value:String(x.meshBoneCount)}),b.jsx(Vt,{label:"Matched Bones",value:String(x.matched.length)}),x.missingInMesh.length>0&&b.jsxs("div",{className:"pt-1.5 space-y-0.5",children:[b.jsxs("span",{className:"text-[10px] font-medium text-amber-400",children:["Missing in mesh (",x.missingInMesh.length,"):"]}),b.jsx("div",{className:"max-h-24 overflow-y-auto",children:x.missingInMesh.map(y=>b.jsx("div",{className:"text-[10px] font-mono text-amber-400/80 pl-2 py-0.5 truncate",title:y,children:y},y))})]}),x.unanimated.length>0&&b.jsxs("div",{className:"pt-1.5 space-y-0.5",children:[b.jsxs("span",{className:"text-[10px] font-medium text-muted-foreground",children:["Unanimated mesh bones (",x.unanimated.length,"):"]}),b.jsx("div",{className:"max-h-24 overflow-y-auto",children:x.unanimated.map(y=>b.jsx("div",{className:"text-[10px] font-mono text-muted-foreground/60 pl-2 py-0.5 truncate",title:y,children:y},y))})]})]}),E.length>0&&b.jsx("div",{className:"pt-2 space-y-1",children:E.map((y,I)=>b.jsxs("div",{className:"flex items-start gap-1.5",children:[b.jsx("span",{className:"mt-0.5 h-2 w-2 shrink-0 rounded-full bg-amber-400"}),b.jsx("span",{className:"text-[11px] text-amber-400 break-all",children:y})]},I))})]})})]})}function S6({asset:n}){const[e,t]=N.useState(!0),i=n.metadata;if(!i||!Fp(i))return null;const a=i;return b.jsxs("div",{className:"space-y-1.5",children:[b.jsxs("button",{className:"flex w-full items-center justify-between",onClick:()=>t(o=>!o),children:[b.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Tracks (",a.trackCount,")"]}),b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:nn("text-muted-foreground transition-transform",!e&&"rotate-180"),children:b.jsx("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!e&&b.jsx(la,{children:b.jsxs(ca,{className:"p-2",children:[b.jsx(Vt,{label:"Duration",value:`${a.duration.toFixed(3)}s`}),b.jsx(Vt,{label:"Format",value:"v2 (Three.js native)"}),b.jsx(gc,{className:"my-1.5"}),b.jsx("div",{className:"max-h-64 overflow-y-auto space-y-0.5",children:a.tracks.map((o,l)=>b.jsxs("div",{className:"flex items-center justify-between py-0.5 hover:bg-muted/50 rounded-sm px-1",children:[b.jsx("span",{className:"text-[11px] font-mono truncate flex-1",title:o.trackName,children:o.trackName}),b.jsxs("span",{className:"text-[10px] text-muted-foreground ml-2 shrink-0",children:[o.keyframeCount,"k"]})]},l))})]})})]})}function C6({asset:n}){const e=n.metadata;if(!e||!Fp(e))return null;const t=e.tracks.reduce((i,a)=>i+a.keyframeCount,0);return b.jsx(la,{children:b.jsxs(ca,{className:"space-y-0 divide-y divide-border p-3",children:[b.jsx(Vt,{label:"Duration",value:`${e.duration.toFixed(3)}s`}),b.jsx(Vt,{label:"Tracks",value:String(e.trackCount)}),b.jsx(Vt,{label:"Total Keyframes",value:t.toLocaleString()}),e.targetMeshId&&b.jsx(Vt,{label:"Target Mesh",value:e.targetMeshId}),n.processedSize>0&&b.jsx(Vt,{label:"Data Size",value:Oo(n.processedSize)})]})})}const w6=[{label:"Texture",value:Qn.Texture},{label:"Color",value:Qn.Color},{label:"Float",value:Qn.Float},{label:"Vec2",value:Qn.Vec2},{label:"Vec3",value:Qn.Vec3},{label:"Vec4",value:Qn.Vec4},{label:"Int",value:Qn.Int}],M6=[{label:"None",value:Fi.None},{label:"MainTex",value:Fi.MainTex},{label:"Tint",value:Fi.Tint},{label:"AlphaTest",value:Fi.AlphaTest}];function rw(n,e){return e===Fi.None?!0:e===Fi.MainTex?n===Qn.Texture:e===Fi.Tint?n===Qn.Color:e===Fi.AlphaTest?n===Qn.Int:!1}function Kr({value:n,onChange:e,label:t}){return b.jsxs("div",{className:"flex items-center gap-1",children:[t&&b.jsx("span",{className:"text-[10px] text-muted-foreground w-3",children:t}),b.jsx(Po,{type:"number",step:"0.01",value:n,onChange:i=>e(parseFloat(i.target.value)||0),className:"h-5 flex-1 text-[10px] font-mono px-1"})]})}function I6({prop:n,index:e,textures:t,materialPack:i,allProps:a,onChange:o,onRemove:l}){const[u,f]=N.useState(!1),h=t.find(x=>x.id===n.textureAssetId),A=x=>{const E=Math.round(Math.min(1,Math.max(0,x[0]))*255),S=Math.round(Math.min(1,Math.max(0,x[1]))*255),y=Math.round(Math.min(1,Math.max(0,x[2]))*255);return`#${E.toString(16).padStart(2,"0")}${S.toString(16).padStart(2,"0")}${y.toString(16).padStart(2,"0")}`},p=x=>{const E=parseInt(x.slice(1,3),16)/255,S=parseInt(x.slice(3,5),16)/255,y=parseInt(x.slice(5,7),16)/255;return[E,S,y,n.value[3]]};function m(x,E){const S=[...n.value];S[x]=E,o(e,{...n,value:S})}const g=new Set(a.filter((x,E)=>E!==e).map(x=>x.previewFlag).filter(x=>x!==Fi.None));return b.jsx(la,{children:b.jsxs(ca,{className:"p-2 space-y-1.5",children:[b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(Po,{value:n.fieldName,onChange:x=>o(e,{...n,fieldName:x.target.value}),placeholder:"Field name...",className:"h-6 flex-1 text-[11px] font-mono"}),b.jsx("button",{className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors",onClick:()=>l(e),title:"Remove property",children:b.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:b.jsx("path",{d:"M2 2l6 6M8 2l-6 6",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})})})]}),b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx("select",{value:n.fieldType,onChange:x=>{const E=Number(x.target.value),S=rw(E,n.previewFlag)?n.previewFlag:Fi.None;o(e,{...n,fieldType:E,previewFlag:S})},className:"h-6 flex-1 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:w6.map(x=>b.jsx("option",{value:x.value,children:x.label},x.value))}),b.jsx("select",{value:n.previewFlag,onChange:x=>o(e,{...n,previewFlag:Number(x.target.value)}),className:"h-6 w-24 shrink-0 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:M6.filter(x=>rw(n.fieldType,x.value)&&(!g.has(x.value)||x.value===n.previewFlag)).map(x=>b.jsx("option",{value:x.value,children:x.label},x.value))})]}),n.fieldType===Qn.Texture&&b.jsxs(b.Fragment,{children:[b.jsxs("button",{onClick:()=>f(!0),className:"flex h-7 w-full items-center gap-2 rounded border border-border bg-background px-2 text-[11px] text-foreground hover:bg-accent/50 transition-colors",children:[h?.previewUrl?b.jsx("img",{src:h.previewUrl,alt:h.fileName,className:"checkerboard size-5 shrink-0 rounded object-contain"}):b.jsx(qU,{className:"size-4 shrink-0 text-muted-foreground"}),b.jsx("span",{className:"flex-1 truncate text-left",children:h?.fileName??"No texture"})]}),b.jsx(n6,{open:u,textures:t,materialPack:i,selectedId:n.textureAssetId,onSelect:x=>o(e,{...n,textureAssetId:x}),onClose:()=>f(!1)})]}),n.fieldType===Qn.Color&&b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("input",{type:"color",value:A(n.value),onChange:x=>o(e,{...n,value:p(x.target.value)}),className:"h-6 w-8 cursor-pointer rounded border border-border bg-transparent p-0"}),b.jsxs("div",{className:"flex flex-1 items-center gap-1",children:[b.jsx("span",{className:"text-[10px] text-muted-foreground",children:"A"}),b.jsx("input",{type:"range",min:"0",max:"1",step:"0.01",value:n.value[3],onChange:x=>m(3,parseFloat(x.target.value)),className:"h-1 flex-1"}),b.jsx("span",{className:"w-6 text-right text-[10px] font-mono text-muted-foreground",children:n.value[3].toFixed(2)})]})]}),n.fieldType===Qn.Float&&b.jsx(Kr,{value:n.value[0],onChange:x=>m(0,x)}),n.fieldType===Qn.Int&&b.jsx(Po,{type:"number",step:"1",value:Math.round(n.value[0]),onChange:x=>m(0,parseInt(x.target.value)||0),className:"h-6 text-[11px] font-mono"}),n.fieldType===Qn.Vec2&&b.jsxs("div",{className:"flex gap-1",children:[b.jsx(Kr,{value:n.value[0],onChange:x=>m(0,x),label:"X"}),b.jsx(Kr,{value:n.value[1],onChange:x=>m(1,x),label:"Y"})]}),n.fieldType===Qn.Vec3&&b.jsxs("div",{className:"flex gap-1",children:[b.jsx(Kr,{value:n.value[0],onChange:x=>m(0,x),label:"X"}),b.jsx(Kr,{value:n.value[1],onChange:x=>m(1,x),label:"Y"}),b.jsx(Kr,{value:n.value[2],onChange:x=>m(2,x),label:"Z"})]}),n.fieldType===Qn.Vec4&&b.jsxs("div",{className:"flex gap-1",children:[b.jsx(Kr,{value:n.value[0],onChange:x=>m(0,x),label:"X"}),b.jsx(Kr,{value:n.value[1],onChange:x=>m(1,x),label:"Y"}),b.jsx(Kr,{value:n.value[2],onChange:x=>m(2,x),label:"Z"}),b.jsx(Kr,{value:n.value[3],onChange:x=>m(3,x),label:"W"})]})]})})}function T6({asset:n}){const{state:e,updateAssetSettings:t}=yn(),i=n.settings.materialConfig,a=e.assets.filter(h=>h.type===at.Texture2D);function o(h){t(n.id,{materialConfig:{...i,schemaId:h}})}function l(h,A){const p=[...i.properties];p[h]=A,t(n.id,{materialConfig:{...i,properties:p}})}function u(h){const A=i.properties.filter((p,m)=>m!==h);t(n.id,{materialConfig:{...i,properties:A}})}function f(){const h=[...i.properties,{fieldName:"",fieldType:Qn.Color,previewFlag:Fi.None,value:[1,1,1,1],textureAssetId:null}];t(n.id,{materialConfig:{...i,properties:h}})}return b.jsxs(b.Fragment,{children:[b.jsx(ai,{label:"Schema ID",children:b.jsx(Po,{value:i.schemaId,onChange:h=>o(h.target.value),placeholder:"e.g. StandardShader",className:"h-7 text-xs font-mono"})}),b.jsxs(ai,{label:`Properties (${i.properties.length})`,children:[b.jsx("div",{className:"space-y-1.5",children:i.properties.map((h,A)=>b.jsx(I6,{prop:h,index:A,textures:a,materialPack:n.settings.pack,allProps:i.properties,onChange:l,onRemove:u},A))}),b.jsx(Ei,{variant:"outline",size:"sm",className:"mt-1.5 h-7 w-full text-[11px]",onClick:f,children:"+ Add Property"})]})]})}function B6({asset:n}){const{state:e,updateAssetSettings:t}=yn(),i=n.metadata;if(!i||!i.materials||i.materials.length===0)return null;const a=e.assets.filter(f=>f.type===at.MaterialSchema),o=n.settings.materialOverrides;function l(f){if(o[f]!==void 0)return o[f]??"";const h=i.materials[f]?.name??"";if(h){const A=a.find(p=>p.stringId.toLowerCase()===h.toLowerCase());if(A)return A.id}return""}function u(f,h){const A={...o,[f]:h||null};t(n.id,{materialOverrides:A})}return b.jsxs(ai,{label:"Material Assignments",children:[b.jsx("div",{className:"space-y-1.5",children:i.materials.map((f,h)=>b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] text-muted-foreground",title:f.name,children:f.name||`Sub-mesh ${h}`}),b.jsxs("select",{value:l(h),onChange:A=>u(h,A.target.value),className:"h-6 w-36 shrink-0 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:[b.jsx("option",{value:"",children:"Default (FBX)"}),a.map(A=>b.jsx("option",{value:A.id,children:A.fileName},A.id))]})]},h))}),a.length===0&&b.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Create a material to assign it here."})]})}function R6(n,e,t){const i=n.settings.materialOverrides;if(i[e]!==void 0)return i[e]??"";const o=n.metadata?.materials?.[e]?.name??"";if(o){const l=t.find(u=>u.stringId.toLowerCase()===o.toLowerCase());if(l)return l.id}return""}function D6({meshAssets:n}){const{state:e,dispatch:t,updateAssetSettings:i,changeAssetType:a}=yn(),o=e.assets.filter(p=>p.type===at.MaterialSchema),l=n.every(p=>p.type===n[0].type)?n[0].type:null;function u(p){const m=n.filter(g=>g.type!==p);if(m.length!==0){m.length>1&&t({type:"START_BATCH_PROCESSING",total:m.length});for(const g of m)a(g.id,p)}}const f=N.useMemo(()=>{const p=new Map;for(const m of n){const g=m.metadata;if(g?.materials)for(let x=0;x<g.materials.length;x++){const E=g.materials[x]?.name||`Sub-mesh ${x}`;let S=p.get(E);S||(S={name:E,entries:[]},p.set(E,S)),S.entries.push({asset:m,subMeshIndex:x})}}return Array.from(p.values())},[n]);function h(p){const m=p.entries.map(x=>R6(x.asset,x.subMeshIndex,o)),g=m[0];return m.every(x=>x===g)?g:"__mixed__"}function A(p,m){for(const{asset:g,subMeshIndex:x}of p.entries){const E={...g.settings.materialOverrides,[x]:m||null};i(g.id,{materialOverrides:E})}}return b.jsxs("div",{className:"flex flex-col gap-4",children:[b.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:[n.length," meshes selected"]}),b.jsx(ai,{label:"Asset Type",children:b.jsx(qa,{options:Pp,value:l??-1,onChange:p=>u(p)})}),b.jsxs(ai,{label:"Material Assignments",children:[b.jsx("div",{className:"space-y-1.5",children:f.map(p=>{const m=h(p);return b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsxs("span",{className:"min-w-0 flex-1 truncate text-[11px] text-muted-foreground",title:p.name,children:[p.name,p.entries.length>1&&b.jsxs("span",{className:"ml-1 text-[10px] opacity-60",children:["(",p.entries.length,")"]})]}),b.jsxs("select",{value:m==="__mixed__"?"__mixed__":m,onChange:g=>{g.target.value!=="__mixed__"&&A(p,g.target.value)},className:"h-6 w-36 shrink-0 rounded border border-border bg-background px-1.5 text-[11px] text-foreground",children:[m==="__mixed__"&&b.jsx("option",{value:"__mixed__",children:"Mixed"}),b.jsx("option",{value:"",children:"Default (FBX)"}),o.map(g=>b.jsx("option",{value:g.id,children:g.fileName},g.id))]})]},p.name)})}),f.length===0&&b.jsx("p",{className:"text-[10px] text-muted-foreground",children:"No material slots on selected meshes."})]})]})}function N6({animAssets:n}){const{state:e,dispatch:t,updateAssetSettings:i,changeAssetType:a}=yn(),o=e.assets.filter(A=>A.type===at.SkinnedMesh),l=n.every(A=>A.type===n[0].type)?n[0].type:null;function u(A){const p=n.filter(m=>m.type!==A);if(p.length!==0){p.length>1&&t({type:"START_BATCH_PROCESSING",total:p.length});for(const m of p)a(m.id,A)}}const f=n.every(A=>A.settings.targetMeshId===n[0].settings.targetMeshId)?n[0].settings.targetMeshId??"":"__mixed__";function h(A){for(const p of n)i(p.id,{targetMeshId:A||null})}return b.jsxs("div",{className:"flex flex-col gap-4",children:[b.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:[n.length," animations selected"]}),b.jsx(ai,{label:"Asset Type",children:b.jsx(qa,{options:Pp,value:l??-1,onChange:A=>u(A)})}),b.jsx(ai,{label:"Preview Mesh",children:o.length===0?b.jsx("p",{className:"text-[11px] text-muted-foreground",children:"No skinned meshes in project."}):b.jsxs("select",{value:f,onChange:A=>{A.target.value!=="__mixed__"&&h(A.target.value)},className:"h-7 w-full rounded-md border border-border bg-background px-2 text-xs text-foreground",children:[f==="__mixed__"&&b.jsx("option",{value:"__mixed__",children:"Mixed"}),b.jsx("option",{value:"",children:"None (skeleton only)"}),o.map(A=>b.jsx("option",{value:A.id,children:A.fileName},A.id))]})})]})}function L6({assets:n}){const{dispatch:e,changeAssetType:t}=yn(),i=n.every(o=>o.type===n[0].type)?n[0].type:null;function a(o){const l=n.filter(u=>u.type!==o);if(l.length!==0){l.length>1&&e({type:"START_BATCH_PROCESSING",total:l.length});for(const u of l)t(u.id,o)}}return b.jsxs("div",{className:"flex flex-col gap-4",children:[b.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:[n.length," assets selected"]}),b.jsx(ai,{label:"Asset Type",children:b.jsx(qa,{options:Pp,value:i??-1,onChange:o=>a(o)})})]})}function U6({asset:n}){const{dispatch:e}=yn();return b.jsx(la,{className:"border-red-500/30",children:b.jsxs(ca,{className:"p-3 space-y-2",children:[b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("span",{className:"h-2 w-2 rounded-full bg-red-400 shrink-0"}),b.jsx("span",{className:"text-xs font-medium text-red-400",children:"Processing Error"})]}),n.error&&b.jsx("p",{className:"text-[11px] text-muted-foreground break-all",children:n.error}),b.jsx(Ei,{variant:"outline",size:"sm",className:"w-full h-7 text-[11px]",onClick:()=>e({type:"UPDATE_ASSET",id:n.id,updates:{status:"pending",error:void 0}}),children:"Retry Processing"})]})})}function P6(){const{state:n}=yn(),e=n.selectedAssetIds.length>1,t=e?void 0:n.assets.find(f=>f.id===IM(n)),i=N.useMemo(()=>e?n.selectedAssetIds.map(f=>n.assets.find(h=>h.id===f)).filter(f=>!!f):[],[e,n.selectedAssetIds,n.assets]),a=i.length>0&&i.every(f=>f.type===at.StaticMesh||f.type===at.SkinnedMesh),o=i.length>0&&i.every(f=>f.type===at.Texture2D||o0(f.type)),l=i.length>0&&i.every(f=>f.type===at.AnimationClip),u=i.length>0&&i.every(f=>o0(f.type));return b.jsxs("section",{className:"flex h-full flex-col bg-card",children:[b.jsx("div",{className:"flex h-9 items-center gap-2 border-b border-border px-4",children:b.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Details"})}),b.jsx(xx,{className:"flex-1 min-h-0",children:b.jsxs("div",{className:"w-full p-4",children:[!t&&!e&&b.jsx("div",{className:"flex h-48 items-center justify-center text-xs text-muted-foreground",children:"Select an asset"}),e&&a&&b.jsx(D6,{meshAssets:i}),e&&o&&b.jsx(s6,{assets:i}),e&&l&&b.jsx(N6,{animAssets:i}),e&&u&&!a&&!l&&b.jsx(L6,{assets:i}),e&&!u&&b.jsxs("div",{className:"text-xs text-muted-foreground",children:[i.length," assets selected"]}),t&&b.jsxs("div",{className:"flex flex-col gap-4",children:[t.status==="error"&&b.jsx(U6,{asset:t}),o0(t.type)&&b.jsx(i6,{asset:t}),t.type!==at.MaterialSchema&&b.jsx(o6,{asset:t}),b.jsx(a6,{asset:t}),t.type===at.Texture2D&&b.jsx(u6,{asset:t}),t.type===at.StaticMesh&&b.jsx(d6,{asset:t}),t.type===at.Audio&&b.jsx(A6,{asset:t}),t.type===at.AnimationClip&&b.jsx(r6,{asset:t}),t.type===at.MaterialSchema&&b.jsx(T6,{asset:t}),b.jsx(m6,{asset:t}),t.metadata&&b.jsxs(b.Fragment,{children:[b.jsx(gc,{}),t.type===at.Texture2D&&b.jsx(g6,{asset:t}),t.type===at.Audio&&b.jsx(v6,{asset:t}),(t.type===at.StaticMesh||t.type===at.SkinnedMesh)&&b.jsx(x6,{asset:t}),t.type===at.AnimationClip&&b.jsx(C6,{asset:t})]}),(t.type===at.StaticMesh||t.type===at.SkinnedMesh)&&t.metadata&&b.jsx(B6,{asset:t}),t.type===at.AnimationClip&&t.metadata&&b.jsx(S6,{asset:t}),(t.type===at.SkinnedMesh||t.type===at.AnimationClip)&&t.metadata&&b.jsx(y6,{asset:t}),t.type===at.SkinnedMesh&&t.metadata&&b.jsx(E6,{asset:t}),t.type===at.AnimationClip&&t.metadata&&b.jsx(b6,{asset:t})]})]})})]})}function F6(){const{state:n}=yn();if(!n.initialProcessing)return null;const e=n.initialProcessingTotal,t=n.assets.filter(m=>m.status==="loading").length,i=n.assets.filter(m=>m.status==="pending").length,a=n.assets.filter(m=>m.status==="processing").length,o=n.assets.filter(m=>m.status==="error").length,l=t+i+a,u=e-l,f=e>0?Math.round(u/e*100):0,h=n.assets.filter(m=>m.status==="processing").map(m=>m.fileName).slice(0,3);let A="";t>0&&a===0?A="Reading files and checking cache...":a>0&&(A=h.join(", "),a>3&&(A+=` +${a-3} more`));let p="";return i>0&&(p=`${i} queued`),o>0&&(p+=`${p?" · ":""}${o} failed`),b.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:b.jsxs("div",{className:"w-[420px] h-[200px] rounded-xl border border-border bg-card p-6 shadow-2xl flex flex-col",children:[b.jsx("div",{className:"flex items-center gap-3 mb-4",children:b.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Processing Assets"})}),b.jsxs("div",{className:"mb-3",children:[b.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[b.jsxs("span",{className:"text-xs text-muted-foreground",children:[u," of ",e," complete"]}),b.jsxs("span",{className:"text-xs font-mono text-muted-foreground",children:[f,"%"]})]}),b.jsx("div",{className:"h-2 w-full rounded-full bg-muted overflow-hidden",children:b.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-300 ease-out",style:{width:`${f}%`}})})]}),b.jsxs("div",{className:"flex-1 flex flex-col justify-between min-h-0",children:[b.jsxs("div",{children:[b.jsx("p",{className:"text-[11px] text-muted-foreground truncate h-4",children:A}),b.jsx("p",{className:"text-[11px] text-muted-foreground/60 h-4",children:p})]}),b.jsx("p",{className:"text-[10px] text-muted-foreground/40",children:"Results are cached for next time."})]})]})})}const BT=N.forwardRef((n,e)=>{const{importFiles:t}=yn();return N.useImperativeHandle(e,()=>({importFiles:(i,a)=>t(i,a)}),[t]),b.jsxs("div",{className:"flex h-full flex-col bg-background text-foreground overflow-hidden",children:[b.jsx(nH,{}),b.jsx(iH,{left:b.jsx(AH,{}),center:b.jsx(Z8,{}),right:b.jsx(P6,{})})]})});BT.displayName="PackerInner";const RT=N.forwardRef(({apiBase:n="/api",className:e},t)=>{const i=N.useRef(null);return P5(n),N.useImperativeHandle(t,()=>({importFiles:(a,o)=>i.current?.importFiles(a,o)??Promise.resolve()}),[]),b.jsx("div",{className:`stowkit-packer ${e??""}`,children:b.jsx(Z5,{children:b.jsxs(NU,{delayDuration:300,children:[b.jsx(BT,{ref:i}),b.jsx(F6,{}),b.jsx(XP,{richColors:!0,position:"bottom-right"})]})})})});RT.displayName="StowKitPacker";function O6(){return b.jsx(RT,{className:"h-screen"})}jR.createRoot(document.getElementById("root")).render(b.jsx(N.StrictMode,{children:b.jsx(O6,{})}));export{at as A};