agent-office-studio 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/xterm-C7kOH91j.js","assets/_commonjsHelpers-CqkleIqs.js","assets/addon-fit-BwprjgOP.js"])))=>i.map(i=>d[i]);
2
- var _p=Object.defineProperty;var xp=(i,t,e)=>t in i?_p(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var _e=(i,t,e)=>xp(i,typeof t!="symbol"?t+"":t,e);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const a of r.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function e(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(s){if(s.ep)return;s.ep=!0;const r=e(s);fetch(s.href,r)}})();"serviceWorker"in navigator&&addEventListener("load",()=>navigator.serviceWorker.register("/sw.js").catch(()=>{}));const Ud=[{id:"paper",name:"Paper"},{id:"ocean",name:"Ocean"},{id:"forest",name:"Forest"},{id:"sunset",name:"Sunset"},{id:"lavender",name:"Lavender"}],Vc=[{id:"light",name:"Light"},{id:"dark",name:"Dark"},{id:"auto",name:"Auto"}],Fo=document.documentElement,Od=matchMedia("(prefers-color-scheme: dark)"),Fd=(i,t,e)=>{try{const n=localStorage.getItem(i);return e.some(s=>s.id===n)?n:t}catch{return t}},Bh=(i,t)=>{try{localStorage.setItem(i,t)}catch{}};try{if(localStorage.getItem("office.appearance")===null){const i=localStorage.getItem("office.mode");Vc.some(t=>t.id===i)&&(localStorage.setItem("office.appearance",i),localStorage.removeItem("office.mode"))}}catch{}let zl=Fd("office.theme","paper",Ud),qr=Fd("office.appearance","auto",Vc);const Or=document.getElementById("themeBtn"),En=document.getElementById("themePop");function so(){const i=qr==="dark"||qr==="auto"&&Od.matches?"dark":"light";Fo.dataset.theme=zl,Fo.dataset.mode=i;const t=document.querySelector('meta[name="theme-color"]');t&&(t.content=getComputedStyle(Fo).getPropertyValue("--paper").trim()||t.content),yp()}function yp(){if(!En)return;En.replaceChildren();const i=e=>Object.assign(document.createElement("p"),{className:"theme-k",textContent:e}),t=(e,n,s,r)=>{const a=document.createElement("div");a.className=r,a.setAttribute("role","radiogroup");for(const o of e){const l=document.createElement("button");l.type="button",l.dataset.t=o.id,l.setAttribute("role","radio"),l.setAttribute("aria-checked",String(o.id===n)),l.innerHTML=r==="theme-swatches"?"<i></i><span></span>":"<span></span>",l.querySelector("span").textContent=o.name,l.addEventListener("click",()=>s(o.id)),a.appendChild(l)}return a};En.append(i("Theme"),t(Ud,zl,e=>{zl=e,Bh("office.theme",e),so()},"theme-swatches"),i("Mode"),t(Vc,qr,e=>{qr=e,Bh("office.appearance",e),so()},"theme-modes"))}function Gc(i){var t;En.hidden=!i,Or.setAttribute("aria-expanded",String(i)),i&&((t=En.querySelector('[aria-checked="true"]'))==null||t.focus())}Or==null||Or.addEventListener("click",i=>{i.stopPropagation(),Gc(En.hidden)});En==null||En.addEventListener("click",i=>i.stopPropagation());document.addEventListener("click",()=>{En&&!En.hidden&&Gc(!1)});document.addEventListener("keydown",i=>{i.key==="Escape"&&En&&!En.hidden&&(Gc(!1),Or.focus())});Od.addEventListener("change",()=>{qr==="auto"&&so()});so();const Qs=document.getElementById("acctBtn"),We=document.getElementById("acctPop"),Mp=[{id:"login",name:"Claude Code login"},{id:"apikey",name:"API key"}];let bn=null,ro=null,tr=!1,Ki="";const An=(i,t={})=>Object.assign(document.createElement(i),t);function lr(){if(!We)return;if(!bn){We.replaceChildren(An("p",{className:"theme-k",textContent:"Claude access"}),An("p",{className:"acct-note",textContent:Ki||"Checking…"}));return}const i=ro||bn.mode;We.replaceChildren();const t=An("div",{className:"theme-modes acct-modes"});t.setAttribute("role","radiogroup");for(const n of Mp){const s=An("button",{type:"button"});s.setAttribute("role","radio"),s.setAttribute("aria-checked",String(n.id===i)),s.append(An("span",{textContent:n.name})),s.addEventListener("click",()=>{ro=n.id,Ki="",n.id==="login"||bn.keySet?zo({mode:n.id}):lr()}),t.append(s)}We.append(An("p",{className:"theme-k",textContent:"Claude access"}),t);const e=(n,s="acct-note")=>We.append(An("p",{className:s,textContent:n}));if(i==="login")e("Jobs run on your Claude plan, using the login Claude Code keeps on this machine. If it isn’t signed in yet, run claude once in a terminal.");else{bn.keySet&&bn.mode==="apikey"?e(`Using the key ending ${bn.keyHint}${bn.keyFrom==="env"?", from ANTHROPIC_API_KEY":""}. Jobs are billed to that API account.`):e("Jobs are billed to the API account the key belongs to. It is kept on this machine only.");const n=An("form",{className:"acct-form"}),s=An("input",{type:"password",placeholder:bn.keySet?"Replace with another key":"sk-ant-…",autocomplete:"off",spellcheck:!1});s.setAttribute("aria-label","Anthropic API key");const r=An("button",{type:"submit",className:"primary small",textContent:tr?"Checking…":"Save",disabled:tr});if(n.append(s,r),n.addEventListener("submit",a=>{a.preventDefault(),s.value.trim()&&zo({mode:"apikey",key:s.value})}),We.append(n),bn.keyFrom==="office"){const a=An("button",{type:"button",className:"acct-forget",textContent:"Forget this key"});a.addEventListener("click",()=>zo(null)),We.append(a)}tr||queueMicrotask(()=>{bn.keySet||s.focus()})}Ki&&e(Ki,"acct-note acct-err"),We.append(An("p",{className:"acct-note acct-fine",textContent:"Jobs already running finish the way they started."}))}async function zo(i){tr=!0,Ki="",lr();try{const t=await fetch("/api/auth",i?{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i)}:{method:"DELETE"}),e=await t.json();if(!t.ok)throw new Error(e.error||"That didn’t save.");bn=e,ro=null}catch(t){Ki=t.message}tr=!1,lr()}function Bl(i){i&&(bn=i,tr||lr())}function Mo(i){var t;We.hidden=!i,Qs.setAttribute("aria-expanded",String(i)),i||(ro=null,Ki=""),lr(),i&&((t=We.querySelector('[aria-checked="true"]'))==null||t.focus()),i&&!bn&&fetch("/api/auth").then(e=>e.ok?e.json():Promise.reject()).then(Bl,()=>{Ki="Restart the office server to choose this.",lr()})}Qs==null||Qs.addEventListener("click",()=>Mo(We.hidden));var Id;(Id=document.getElementById("themeBtn"))==null||Id.addEventListener("click",()=>{We.hidden||Mo(!1)});document.addEventListener("click",i=>{We&&!We.hidden&&!We.contains(i.target)&&!Qs.contains(i.target)&&Mo(!1)});document.addEventListener("keydown",i=>{i.key==="Escape"&&We&&!We.hidden&&(Mo(!1),Qs.focus())});const er=document.getElementById("lbBtn"),Te=document.getElementById("lbPop"),zd=[{id:"jobs",name:"Jobs",value:i=>String(i.jobs)},{id:"tokens",name:"Tokens",value:i=>$c(i.tokens)},{id:"time",name:"Time",value:i=>Wc(i.seconds)}],bp=[{id:"week",name:"This week"},{id:"all",name:"All time"}];let jt=null,Hl="week",Fr="jobs",Wi=null,Vl=!1,Si=!1,Ln="",Gl="";const Kt=(i,t={})=>Object.assign(document.createElement(i),t);function $c(i){return i>=1e9?`${(i/1e9).toFixed(1)}B`:i>=1e6?`${(i/1e6).toFixed(1)}M`:i>=1e3?`${(i/1e3).toFixed(i>=1e5?0:1)}k`:String(i)}function Wc(i){const t=Math.round(i/60);return t<1?i>0?"<1m":"0m":t<60?`${t}m`:`${Math.floor(t/60)}h ${String(t%60).padStart(2,"0")}m`}function Bd(i){const t=Math.max(0,Math.round((Date.now()-i)/1e3));return t<90?"just now":t<5400?`${Math.round(t/60)} min ago`:t<129600?`${Math.round(t/3600)} h ago`:`${Math.round(t/86400)} days ago`}function Hh(i,t,e,n,s=""){const r=Kt("div",{className:`theme-modes lb-tabs ${s}`});r.setAttribute("role","radiogroup"),r.setAttribute("aria-label",e);for(const a of i){const o=Kt("button",{type:"button"});o.setAttribute("role","radio"),o.setAttribute("aria-checked",String(a.id===t)),o.append(Kt("span",{textContent:a.name})),o.addEventListener("click",()=>n(a.id)),r.append(o)}return r}function jn(){if(!Te)return;Te.replaceChildren(Kt("p",{className:"theme-k",textContent:"Leaderboard"}));const i=(t,e="acct-note")=>Te.append(Kt("p",{className:e,textContent:t}));if(!jt){i(Ln||"Checking…");return}if(!jt.configured){i("No leaderboard is set up for this office. Whoever hosts one gives you its address: set it as OFFICE_LEADERBOARD_URL and restart the office.");return}if(Vh())Sp();else if(jt.joined){const t=jt.week,e=Kt("p",{className:"lb-me"});Te.append(e),e.append(Kt("strong",{textContent:jt.handle}),Kt("span",{textContent:` · ${t.jobs} ${t.jobs===1?"job":"jobs"}, ${$c(t.tokens)} tokens, ${Wc(t.seconds)} this week`}));const n=jt.error?`Not shared yet: ${jt.error}`:jt.lastSync?`Shared ${Bd(jt.lastSync)}.`:"Sharing…";i(n,jt.error?"acct-note acct-err":"acct-note acct-fine")}else{i("Compete on jobs finished, tokens used and time your agents spend working. Joining shares exactly these counters per day, for the last two weeks and from now on, under the handle you claim. Never prompts, projects, files, chat or cost.");const t=Kt("form",{className:"acct-form"}),e=Kt("input",{type:"text",placeholder:"Pick a handle",autocomplete:"off",spellcheck:!1,maxLength:20});e.setAttribute("aria-label","Handle"),t.append(e,Kt("button",{type:"submit",className:"primary small",textContent:Si?"Joining…":"Join",disabled:Si})),t.addEventListener("submit",n=>{n.preventDefault(),e.value.trim()&&oo("POST",{handle:e.value})}),Te.append(t),Ln&&i(Ln,"acct-note acct-err")}if(Te.append(Hh(bp,Hl,"Period",t=>{Hl=t,ao()},"lb-period"),Hh(zd,Fr,"Ranked by",t=>{Fr=t,jn()},"lb-metric")),Te.append(wp()),jt.joined&&!Vh()){const t=Kt("button",{type:"button",className:"acct-forget",textContent:Si?"Working…":"Leave and delete my data",disabled:Si});t.addEventListener("click",()=>{confirm("Leave the leaderboard? Your handle is released and your counters are deleted from the service.")&&oo("DELETE")}),Te.append(t),Ln&&i(Ln,"acct-note acct-err")}}const Vh=()=>!!jt&&"sharing"in jt&&!!jt.handle;function Sp(){const i=(s,r="acct-note")=>Te.append(Kt("p",{className:r,textContent:s})),t=Kt("p",{className:"lb-me"});if(t.append(Kt("strong",{textContent:jt.handle})),jt.sharing&&jt.week){const s=jt.week;t.append(Kt("span",{textContent:` · ${s.jobs} ${s.jobs===1?"job":"jobs"}, ${$c(s.tokens)} tokens, ${Wc(s.seconds)} this week`}))}Te.append(t);const e=Kt("input",{type:"checkbox",checked:!!jt.sharing,disabled:Si});e.addEventListener("change",()=>{if(e.checked){oo("POST",{handle:jt.handle});return}confirm("Stop sharing? Your counters are deleted from the board. You keep your handle while you have linked offices; with none, the handle is released too.")?oo("DELETE"):e.checked=!0});const n=Kt("label",{className:"lb-share"});if(n.append(e,Kt("span",{textContent:"Share my counters on the board"})),Te.append(n),jt.sharing){const s=jt.error?`Not shared yet: ${jt.error}`:jt.lastSync?`Shared ${Bd(jt.lastSync)}.`:"Sharing…";i(s,jt.error?"acct-note acct-err":"acct-note acct-fine")}else i("Sharing sends jobs finished, tokens and agent time per day, for the last two weeks and from now on. Never prompts, projects, files, chat or cost.","acct-note acct-fine");Ln&&i(Ln,"acct-note acct-err")}function wp(){var r;const i=Kt("div",{className:"lb-board"});if(!Wi)return i.append(Kt("p",{className:"acct-note",textContent:Vl?"Loading…":Gl||"No board yet."})),i;const e=Wi[Fr==="time"?"time":Fr]||[];if(!e.length)return i.append(Kt("p",{className:"acct-note",textContent:"Nobody on the board yet."})),i;const n=zd.find(a=>a.id===Fr),s=Kt("ol",{className:"lb-list"});for(const a of e){const o=Kt("li",{className:a.handle.toLowerCase()===((r=jt.handle)==null?void 0:r.toLowerCase())?"lb-row lb-you":"lb-row"});o.append(Kt("span",{className:"lb-rank",textContent:String(a.rank)}),Kt("span",{className:"lb-name",textContent:a.handle}),Kt("span",{className:"lb-val",textContent:n.value(a)})),s.append(o)}return i.append(s),Wi.players>e.length&&i.append(Kt("p",{className:"acct-note acct-fine",textContent:`Top ${e.length} of ${Wi.players}.`})),Wi.since&&i.append(Kt("p",{className:"acct-note acct-fine",textContent:"Weeks start Monday, UTC."})),i}async function ao(){if(jt!=null&&jt.configured){Vl=!0,Gl="",jn();try{const i=await fetch(`/api/leaderboard/board?period=${Hl}`),t=await i.json();if(!i.ok)throw new Error(t.error||"Couldn’t load the board.");Wi=t}catch(i){Wi=null,Gl=i.message}Vl=!1,Te.hidden||jn()}}async function oo(i,t){Si=!0,Ln="",jn();try{const e=await fetch("/api/leaderboard",i==="POST"?{method:i,headers:{"content-type":"application/json"},body:JSON.stringify(t)}:{method:i}),n=await e.json();if(!e.ok)throw new Error(n.error||"That didn’t work.");Jr(n),Wi=null}catch(e){Ln=e.message}Si=!1,jn(),Ln||ao()}function Gh(i){i&&(Jr(i),!Si&&!Te.hidden&&jn())}function Jr(i){jt=i,document.dispatchEvent(new CustomEvent("office:leaderboard",{detail:i}))}document.addEventListener("office:leaderboard",i=>{i.detail!==jt&&(jt=i.detail,!Si&&Te&&!Te.hidden&&jn())});function bo(i){if(Te.hidden=!i,er.setAttribute("aria-expanded",String(i)),!i){Ln="";return}jn(),jt?ao():fetch("/api/leaderboard").then(t=>t.ok?t.json():Promise.reject()).then(t=>{Jr(t),jn(),ao()},()=>{Ln="Restart the office server to use this.",jn()})}er==null||er.addEventListener("click",()=>bo(Te.hidden));var kd;for(const i of["themeBtn","acctBtn"])(kd=document.getElementById(i))==null||kd.addEventListener("click",()=>{Te.hidden||bo(!1)});document.addEventListener("click",i=>{const t=i.composedPath();Te&&!Te.hidden&&!t.includes(Te)&&!t.includes(er)&&bo(!1)});document.addEventListener("keydown",i=>{i.key==="Escape"&&Te&&!Te.hidden&&(bo(!1),er.focus())});const $l="office.nameAsked",Ep="office.name",Tp=i=>i.trim().replace(/\s+/g,"_").replace(/[^A-Za-z0-9_-]/g,"").slice(0,20);function Ap(){const i=Kt("dialog",{className:"name-ask"}),t=Kt("form",{method:"dialog"}),e=Kt("input",{type:"text",placeholder:"Your name",autocomplete:"off",spellcheck:!1,maxLength:40});e.setAttribute("aria-label","Your name");const n=Kt("p",{className:"acct-note acct-err",hidden:!0}),s=Kt("button",{type:"submit",className:"primary small",textContent:"Continue"}),r=Kt("button",{type:"button",className:"acct-forget",textContent:"Not now"}),a=Kt("div",{className:"acct-form"});a.append(e,s),t.append(Kt("h2",{textContent:"Welcome to the office"}),Kt("p",{className:"acct-note",textContent:jt!=null&&jt.configured?"What should we call you? Your name becomes your handle on the leaderboard. Nothing is shared until you join it.":"What should we call you?"}),a,n,r),i.append(t);const o=()=>{try{localStorage.setItem($l,"1")}catch{}i.close(),i.remove()};r.addEventListener("click",o),i.addEventListener("cancel",o),t.addEventListener("submit",async l=>{l.preventDefault();const c=e.value.trim(),h=Tp(c);if(c){n.hidden=!0,s.disabled=!0;try{if(jt!=null&&jt.configured){if(h.length<3)throw new Error("Use at least 3 letters or numbers.");const u=await fetch("/api/leaderboard/handle",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({handle:h})}),d=await u.json();if(!u.ok)throw new Error(d.error||"That handle didn’t work.");Jr(d),Te.hidden||jn()}try{localStorage.setItem(Ep,c)}catch{}o()}catch(u){n.textContent=u.message,n.hidden=!1,s.disabled=!1,e.focus()}}}),document.body.append(i),i.showModal(),e.focus()}try{!localStorage.getItem($l)&&!new URLSearchParams(location.search).has("visit")&&fetch("/api/leaderboard").then(i=>i.ok?i.json():null).catch(()=>null).then(i=>{if(i&&Jr(i),i!=null&&i.handle){try{localStorage.setItem($l,"1")}catch{}return}Ap()})}catch{}const nr=document.getElementById("linkBtn"),Ie=document.getElementById("linkPop"),Bo=document.getElementById("app"),Xc=[{id:"plan",name:"Plan only"},{id:"edit",name:"Edit files"},{id:"auto",name:"Full autonomy"}],Yr={plan:0,edit:1,auto:2},Cp=2e6,Rp=/^[0-9A-HJKMNP-TV-Z]{8}$/;let qn=null,kr={},Ti=null,Zi=null,Ai=null,ir=null,an="",ci="",lo=!1;const Pt=(i,t={},...e)=>{const n=Object.assign(document.createElement(i),t);return n.append(...e.filter(s=>s!=null&&s!==!1)),n},Nn=(i,t="acct-note")=>Pt("p",{className:t,textContent:i});async function Ri(i,t,e){const n=t===void 0?{method:e||"GET"}:{method:e||"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)},s=await fetch(i,n),r=await s.json().catch(()=>({}));if(!s.ok)throw new Error(r.error||(s.status===404?"Restart the office server to use links.":"That didn’t work."));return r}function Pp(i){const t=String(i||"").toUpperCase().replace(/[\s-]+/g,"").replace(/[IL]/g,"1").replace(/O/g,"0");return Rp.test(t)?t:null}const Lp=i=>{const t=String(i).toUpperCase().replace(/-/g,"");return`${t.slice(0,4)}-${t.slice(4)}`};function Wl(i){return i>=1e6?`${+(i/1e6).toFixed(1)}M`:i>=1e3?`${Math.round(i/1e3)}k`:String(i)}function Dp(i){const t=typeof i=="number"?i:Date.parse(i);if(!t)return"";const e=t-Date.now();if(e<=0)return"Expired. Make a new one.";const n=Math.ceil(e/6e4),s=Math.floor(n/60),r=n%60,a=new Date(t).toLocaleString([],{weekday:"short",hour:"numeric",minute:"2-digit"});return`Works once. Expires in ${s?`${s} h ${r} min`:`${r} min`} (${a}).`}function Ip(i){var n,s;const t=((n=i.repos)==null?void 0:n.length)||0,e=((s=Xc.find(r=>r.id===i.clearance))==null?void 0:s.name)||i.clearance;return`${t===1?i.repos[0]:`${t} projects`} · ${e} · ${Wl(i.tokensPerDay||0)} tokens a day`}function kp(i){return i.kind!=="guest"?"Linked office":i.role==="guest"?"Guest · you visit them":"Guest · they visit you"}function Qe(){if(!Ie||Ie.hidden)return;const i=kr.handle||(Ti==null?void 0:Ti.handle);Ie.replaceChildren(Pt("p",{className:"theme-k",textContent:"Linked offices"})),i?(Ie.append(Pt("p",{className:"lb-me"},"This office is ",Pt("strong",{textContent:`@${i}`}))),Ie.append(Up()),Zi&&Ie.append(Op()),Ai&&Ie.append(zp())):Ie.append(...Np()),ci&&Ie.append(Nn(ci,"acct-note acct-err")),kr.error?Ie.append(Nn(`Link service: ${kr.error}`,"acct-note acct-err")):qn!=null&&qn.length&&kr.connected===!1&&Ie.append(Nn("Connecting to the link service…","acct-note acct-fine")),Ie.append(Bp())}function Np(){const i=[Nn("Linked offices see each other’s agents walk in as visitors, and a guest can run jobs here within the limits you set. First, pick a handle for this office.")];if(Ti&&!Ti.configured)return[...i,Nn("This office has no link service set up.","acct-note acct-err")];const t=Pt("form",{className:"acct-form"}),e=Pt("input",{type:"text",placeholder:"Pick a handle",autocomplete:"off",spellcheck:!1,maxLength:20});return e.setAttribute("aria-label","Handle"),t.append(e,Pt("button",{type:"submit",className:"primary small",textContent:an==="claim"?"Claiming…":"Claim",disabled:!!an})),t.addEventListener("submit",async n=>{n.preventDefault(),e.value.trim()&&await So("claim",async()=>{Vp(await Ri("/api/leaderboard/handle",{handle:e.value.trim()}),!0),cr(await Ri("/api/links"))})}),[...i,t,Nn("Claiming a handle doesn’t put you on the leaderboard. Sharing your counters there is a separate choice.","acct-note acct-fine")]}function Up(){const i=Pt("div",{className:"link-actions"}),t=Pt("button",{type:"button",className:"ghost small",textContent:an==="link"?"Making a code…":"Invite an office",disabled:!!an});t.addEventListener("click",()=>{Ai=null,Hd("link")});const e=Pt("button",{type:"button",className:"ghost small",textContent:"Invite a guest",disabled:!!an});e.setAttribute("aria-expanded",String(!!Ai)),e.addEventListener("click",Fp);const n=Pt("form",{className:"acct-form link-redeem"}),s=Pt("input",{type:"text",placeholder:"Enter a code, e.g. K7QX-M2PD",autocomplete:"off",spellcheck:!1,maxLength:12});return s.setAttribute("aria-label","Invite code"),n.append(s,Pt("button",{type:"submit",className:"primary small",textContent:an==="redeem"?"Linking…":"Link",disabled:!!an})),n.addEventListener("submit",r=>{r.preventDefault();const a=Pp(s.value);if(!a){ci="A code is 8 letters and numbers, like K7QX-M2PD.",Qe();return}So("redeem",async()=>{cr(await Ri("/api/links/redeem",{code:a})),Zi=null})}),i.append(Pt("div",{className:"link-row"},t,e),n),i}function Op(){const i=Pt("div",{className:"link-code"}),t=Lp(Zi.code),e=Pt("button",{type:"button",className:"ghost small",textContent:lo?"Copied":"Copy"});return e.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(t),lo=!0}catch{ci="Couldn’t copy. Select the code and copy it by hand."}Qe()}),i.append(Pt("p",{className:"theme-k",textContent:Zi.kind==="guest"?"Guest code":"Office code"}),Pt("div",{className:"link-code-row"},Pt("output",{className:"link-code-v",textContent:t}),e),Nn(`${Zi.kind==="guest"?"Give this to your guest. They enter it in their own office.":"Give this to the other office. They enter it under Linked offices."} ${Dp(Zi.expiresAt)}`,"acct-note acct-fine")),i}async function Fp(){if(Ai){Ai=null,Qe();return}if(Ai={repos:new Set,clearance:"edit",full:!1,tokensPerDay:Cp},Zi=null,Qe(),!ir){try{ir=(await Ri("/api/repos")).repos||[]}catch(i){ir=[],ci=i.message}Qe()}}function zp(){const i=Ai,t=Pt("form",{className:"link-guest"});t.append(Pt("p",{className:"theme-k",textContent:"Invite a guest"}),Nn("A guest can start jobs with your agents in the projects you pick, at or below the clearance you set. Their jobs run on your Claude account.","acct-note acct-fine"));const e=Pt("fieldset",{className:"link-repos"},Pt("legend",{textContent:`Projects they can use (${i.repos.size} picked)`}));ir?ir.length||e.append(Nn("No projects found.","acct-note acct-fine")):e.append(Nn("Loading…","acct-note acct-fine"));for(const c of ir||[]){const h=Pt("input",{type:"checkbox",checked:i.repos.has(c)});h.addEventListener("change",()=>{h.checked?i.repos.add(c):i.repos.delete(c),Qe()}),e.append(Pt("label",{},h,Pt("span",{textContent:c})))}const n=Pt("div",{className:"theme-modes acct-modes link-cap"});n.setAttribute("role","radiogroup"),n.setAttribute("aria-label","Clearance cap");for(const c of Xc.slice(0,2)){const h=Pt("button",{type:"button",textContent:c.name,disabled:i.full});h.setAttribute("role","radio"),h.setAttribute("aria-checked",String(!i.full&&i.clearance===c.id)),h.addEventListener("click",()=>{i.clearance=c.id,Qe()}),n.append(h)}const s=Pt("input",{type:"checkbox",checked:i.full});s.addEventListener("change",()=>{i.full=s.checked,Qe()});const r=Pt("div",{className:"link-warn"},Pt("p",{textContent:"Full autonomy lets the guest run any command on this machine, with your files and your logins. Only allow it for someone you’d hand your laptop to."}),Pt("label",{},s,Pt("span",{textContent:"Allow full autonomy anyway"}))),a=Pt("input",{type:"number",min:1e5,step:1e5,value:i.tokensPerDay,required:!0});a.setAttribute("aria-label","Tokens per day");const o=Pt("span",{className:"acct-fine",textContent:Wl(i.tokensPerDay)});a.addEventListener("input",()=>{i.tokensPerDay=Math.floor(Number(a.value))||0,o.textContent=Wl(i.tokensPerDay)});const l=i.repos.size>0&&!an;return t.append(e,Pt("p",{className:"link-k",textContent:"Clearance cap"}),n,r,Pt("label",{className:"link-k link-tokens"},Pt("span",{textContent:"Tokens per day"}),a,o),Pt("div",{className:"link-row"},Pt("button",{type:"submit",className:"primary small",textContent:an==="guest"?"Making a code…":"Make guest code",disabled:!l}),i.repos.size?null:Pt("span",{className:"acct-fine",textContent:"Pick at least one project."}))),t.addEventListener("submit",c=>{if(c.preventDefault(),!i.repos.size||i.tokensPerDay<1e5){ci=i.repos.size?"Allow at least 100,000 tokens a day.":"Pick at least one project.",Qe();return}Hd("guest",{repos:[...i.repos],clearance:i.full?"auto":i.clearance,tokensPerDay:i.tokensPerDay})}),t}function Bp(){const i=Pt("div",{className:"lb-board"});if(!qn)return i.append(Nn("Loading links…","acct-note acct-fine")),i;if(!qn.length)return i.append(Nn("No links yet.","acct-note acct-fine")),i;const t=Pt("ul",{className:"lb-list link-list"});for(const e of qn){const n=Pt("li",{className:"link-item"},Pt("span",{className:"link-who"},Pt("strong",{textContent:`@${e.peer}`}),Pt("span",{className:"acct-fine",textContent:kp(e)}),e.guest?Pt("span",{className:"acct-fine",textContent:Ip(e.guest)}):null)),s=Pt("span",{className:"link-row"});if(e.kind==="guest"&&e.role==="guest"){const a=Pt("button",{type:"button",className:"primary small",textContent:`Visit @${e.peer}`});a.addEventListener("click",()=>{location.search=`?visit=${encodeURIComponent(e.id)}`}),s.append(a)}const r=Pt("button",{type:"button",className:"acct-forget",textContent:an===e.id?"Unlinking…":"Unlink",disabled:!!an});r.addEventListener("click",()=>Hp(e)),s.append(r),n.append(s),t.append(n)}return i.append(t),i}async function So(i,t){an=i,ci="",Qe();try{await t()}catch(e){ci=e.message}an="",Qe()}function Hd(i,t){return lo=!1,So(i,async()=>{const e=await Ri("/api/links/invite",t?{kind:i,guest:t}:{kind:i});Zi={kind:e.kind||i,code:e.code,expiresAt:e.expiresAt},Ai=null})}function Hp(i){const t=i.kind!=="guest"?"You stop seeing each other’s agents.":i.role==="host"?"Their running jobs stop and they lose access right away.":"You can’t visit their office again without a new code.";confirm(`Unlink @${i.peer}? ${t}`)&&So(i.id,async()=>{cr(await Ri(`/api/links/${encodeURIComponent(i.id)}`,void 0,"DELETE"))})}function Vp(i,t=!1){Ti=i,t&&document.dispatchEvent(new CustomEvent("office:leaderboard",{detail:i}))}function cr(i){!i||!Array.isArray(i.links)||(qn=i.links,kr={handle:i.handle||null,connected:i.connected,error:i.error||null},Eo(),an||Qe())}document.addEventListener("office:leaderboard",i=>{Ti=i.detail,an||Qe()});function wo(i){if(Ie.hidden=!i,nr.setAttribute("aria-expanded",String(i)),!i){ci="",Ai=null,lo=!1;return}Qe(),Ri("/api/links").then(cr,t=>{qn||(qn=[]),ci=t.message,Qe()}),Ti||Ri("/api/leaderboard").then(t=>{Ti=t,Qe()},()=>{})}nr==null||nr.addEventListener("click",()=>wo(Ie.hidden));var Nd;for(const i of["themeBtn","acctBtn"])(Nd=document.getElementById(i))==null||Nd.addEventListener("click",()=>{Ie.hidden||wo(!1)});document.addEventListener("click",i=>{Ie&&!Ie.hidden&&i.target.isConnected&&!Ie.contains(i.target)&&!nr.contains(i.target)&&wo(!1)});document.addEventListener("keydown",i=>{i.key==="Escape"&&Ie&&!Ie.hidden&&(wo(!1),nr.focus())});const $t={on:!1,link:null,host:"",repos:null,clearance:"edit",tokensPerDay:0};{const i=new URLSearchParams(location.search).get("visit");i&&Object.assign($t,{on:!0,link:i})}function Gp(i){i&&(vs="",Object.assign($t,{on:!0,link:i.link??$t.link,host:i.host??$t.host,repos:Array.isArray(i.repos)?i.repos:$t.repos,clearance:Yr[i.clearance]!=null?i.clearance:$t.clearance,tokensPerDay:i.tokensPerDay??$t.tokensPerDay}),Eo())}function As(i,t=""){return i=encodeURIComponent(i),$t.on?`/api/visit/${encodeURIComponent($t.link)}/jobs/${i}${t}`:`/api/jobs/${i}${t}`}function Ho(i,t,e){return $t.on?{text:i,mode:t}:{message:i,mode:t,files:e}}const Vo=i=>`#${i.replace(/\s+/g,"-")}`.toLowerCase();async function $p({text:i,mode:t,model:e}){const n=(i.match(/(^|\s)#[\w.-]+/g)||[]).map(c=>c.trim().toLowerCase()),s=$t.repos||[],r=s.filter(c=>n.includes(Vo(c)));if(r.length!==1){const c=s.map(Vo).join(", ")||"none yet";throw new Error(r.length?"Name just one project per job.":`Name the project with a # tag. You can use: ${c}.`)}const a=r[0],o=i.replace(new RegExp(`(^|\\s)${Vo(a).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(?=\\s|$)`,"i")," ").replace(/\s+/g," ").trim();if(!o)throw new Error("Say what the job is, as well as the project.");const{job:l}=await Ri(`/api/visit/${encodeURIComponent($t.link)}/jobs`,{repo:a,prompt:o,mode:t,model:e});return l}function Wp(i){return!$t.on||!i?i:Object.fromEntries(Object.entries(i).filter(([t])=>(Yr[t]??9)<=Yr[$t.clearance]))}function $h(i){return!$t.on||!Array.isArray(i)?i:i.filter(t=>{var e;return(e=$t.repos)==null?void 0:e.includes(t)})}let vs="",Wa=!1;function Xp(i){if(!$t.on)return null;if(i===4404)vs="The host ended this link. You can’t visit any more.";else if(i===4502)vs="Can’t reach the host’s office right now. Trying again…";else return vs="",null;return Wa=i===4404,Eo(),i===4404?0:1e4}function Eo(){var r,a,o,l;if(!$t.on)return;const i=$t.host||((r=qn==null?void 0:qn.find(c=>c.id===$t.link))==null?void 0:r.peer)||"";i&&($t.host=i),Bo.classList.add("visiting"),Bo.dataset.visiting=i,Bo.classList.toggle("visit-ended",!!Wa);const t=document.getElementById("input");if(t){t.placeholder=Wa?"This link has ended.":`Start a job${i?` at @${i}`:""} · #project`;for(const c of document.querySelectorAll("#composer textarea, #composer select, #composer button"))c.disabled=!!Wa}const e=document.getElementById("mode");if(e){for(const c of e.options)c.hidden=c.disabled=Yr[c.value]>Yr[$t.clearance];(a=e.selectedOptions[0])!=null&&a.disabled&&(e.value=$t.clearance)}let n=document.getElementById("visitBar");n||(n=Pt("div",{className:"visit-bar",id:"visitBar"}),n.setAttribute("role","status"),(o=document.querySelector(".brand"))==null||o.after(n));const s=Pt("a",{href:location.pathname,textContent:"Back to my office"});n.replaceChildren(Pt("span",{},"Visiting ",Pt("strong",{textContent:i?`@${i}`:"a linked office"}),$t.repos?` · ${$t.repos.length} ${$t.repos.length===1?"project":"projects"}, up to ${(l=Xc.find(c=>c.id===$t.clearance))==null?void 0:l.name.toLowerCase()}`:""),s),n.classList.toggle("visit-off",!!vs),vs&&n.append(Pt("p",{className:"visit-note",textContent:vs}))}Eo();/**
2
+ var Vp=Object.defineProperty;var Gp=(i,t,e)=>t in i?Vp(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var _e=(i,t,e)=>Gp(i,typeof t!="symbol"?t+"":t,e);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const a of r.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function e(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(s){if(s.ep)return;s.ep=!0;const r=e(s);fetch(s.href,r)}})();"serviceWorker"in navigator&&addEventListener("load",()=>navigator.serviceWorker.register("/sw.js").catch(()=>{}));const ef=[{id:"paper",name:"Paper"},{id:"ocean",name:"Ocean"},{id:"forest",name:"Forest"},{id:"sunset",name:"Sunset"},{id:"lavender",name:"Lavender"}],nh=[{id:"light",name:"Light"},{id:"dark",name:"Dark"},{id:"auto",name:"Auto"}],qo=document.documentElement,nf=matchMedia("(prefers-color-scheme: dark)"),sf=(i,t,e)=>{try{const n=localStorage.getItem(i);return e.some(s=>s.id===n)?n:t}catch{return t}},nu=(i,t)=>{try{localStorage.setItem(i,t)}catch{}};try{if(localStorage.getItem("office.appearance")===null){const i=localStorage.getItem("office.mode");nh.some(t=>t.id===i)&&(localStorage.setItem("office.appearance",i),localStorage.removeItem("office.mode"))}}catch{}let Zl=sf("office.theme","paper",ef),ia=sf("office.appearance","auto",nh);const Xr=document.getElementById("themeBtn"),Rn=document.getElementById("themePop");function mo(){const i=ia==="dark"||ia==="auto"&&nf.matches?"dark":"light";qo.dataset.theme=Zl,qo.dataset.mode=i;const t=document.querySelector('meta[name="theme-color"]');t&&(t.content=getComputedStyle(qo).getPropertyValue("--paper").trim()||t.content),$p()}function $p(){if(!Rn)return;Rn.replaceChildren();const i=e=>Object.assign(document.createElement("p"),{className:"theme-k",textContent:e}),t=(e,n,s,r)=>{const a=document.createElement("div");a.className=r,a.setAttribute("role","radiogroup");for(const o of e){const l=document.createElement("button");l.type="button",l.dataset.t=o.id,l.setAttribute("role","radio"),l.setAttribute("aria-checked",String(o.id===n)),l.innerHTML=r==="theme-swatches"?"<i></i><span></span>":"<span></span>",l.querySelector("span").textContent=o.name,l.addEventListener("click",()=>s(o.id)),a.appendChild(l)}return a};Rn.append(i("Theme"),t(ef,Zl,e=>{Zl=e,nu("office.theme",e),mo()},"theme-swatches"),i("Mode"),t(nh,ia,e=>{ia=e,nu("office.appearance",e),mo()},"theme-modes"))}function ih(i){var t;Rn.hidden=!i,Xr.setAttribute("aria-expanded",String(i)),i&&((t=Rn.querySelector('[aria-checked="true"]'))==null||t.focus())}Xr==null||Xr.addEventListener("click",i=>{i.stopPropagation(),ih(Rn.hidden)});Rn==null||Rn.addEventListener("click",i=>i.stopPropagation());document.addEventListener("click",()=>{Rn&&!Rn.hidden&&ih(!1)});document.addEventListener("keydown",i=>{i.key==="Escape"&&Rn&&!Rn.hidden&&(ih(!1),Xr.focus())});nf.addEventListener("change",()=>{ia==="auto"&&mo()});mo();const lr=document.getElementById("acctBtn"),Pe=document.getElementById("acctPop"),Wp=[{id:"login",name:"Claude Code login"},{id:"apikey",name:"API key"}];let Tn=null,go=null,Ss=!1,Kn="",Yi=null;const We=(i,t={})=>Object.assign(document.createElement(i),t);function Ii(){if(!Pe)return;if(!Tn){Pe.replaceChildren(We("p",{className:"theme-k",textContent:"Claude access"}),We("p",{className:"acct-note",textContent:Kn||"Checking…"}));return}const i=go||Tn.mode;Pe.replaceChildren();const t=We("div",{className:"theme-modes acct-modes"});t.setAttribute("role","radiogroup");for(const n of Wp){const s=We("button",{type:"button"});s.setAttribute("role","radio"),s.setAttribute("aria-checked",String(n.id===i)),s.append(We("span",{textContent:n.name})),s.addEventListener("click",()=>{go=n.id,Kn="",n.id==="login"||Tn.keySet?Ko({mode:n.id}):Ii()}),t.append(s)}Pe.append(We("p",{className:"theme-k",textContent:"Claude access"}),t);const e=(n,s="acct-note")=>Pe.append(We("p",{className:s,textContent:n}));if(i==="login")e("Jobs run on your Claude plan, using the login Claude Code keeps on this machine. If it isn’t signed in yet, run claude once in a terminal.");else{Tn.keySet&&Tn.mode==="apikey"?e(`Using the key ending ${Tn.keyHint}${Tn.keyFrom==="env"?", from ANTHROPIC_API_KEY":""}. Jobs are billed to that API account.`):e("Jobs are billed to the API account the key belongs to. It is kept on this machine only.");const n=We("form",{className:"acct-form"}),s=We("input",{type:"password",placeholder:Tn.keySet?"Replace with another key":"sk-ant-…",autocomplete:"off",spellcheck:!1});s.setAttribute("aria-label","Anthropic API key");const r=We("button",{type:"submit",className:"primary small",textContent:Ss?"Checking…":"Save",disabled:Ss});if(n.append(s,r),n.addEventListener("submit",a=>{a.preventDefault(),s.value.trim()&&Ko({mode:"apikey",key:s.value})}),Pe.append(n),Tn.keyFrom==="office"){const a=We("button",{type:"button",className:"acct-forget",textContent:"Forget this key"});a.addEventListener("click",()=>Ko(null)),Pe.append(a)}Ss||queueMicrotask(()=>{Tn.keySet||s.focus()})}Kn&&e(Kn,"acct-note acct-err"),Pe.append(We("p",{className:"acct-note acct-fine",textContent:"Jobs already running finish the way they started."})),Xp()}function Xp(){if(!Yi)return;Pe.append(We("p",{className:"theme-k",textContent:"Context limit"}));const i=We("form",{className:"acct-form"}),t=We("input",{type:"number",min:0,step:1e4,value:Yi.tokens,required:!0});t.setAttribute("aria-label","Context limit in tokens");const e=We("button",{type:"submit",className:"primary small",textContent:"Save"});if(i.append(t,e),i.addEventListener("submit",n=>{n.preventDefault();const s=Number(t.value);Number.isInteger(s)&&s>=0?iu(s):(Kn="Use a whole number of tokens, or 0 to turn it off.",Ii())}),Pe.append(i,We("p",{className:"acct-note acct-fine",textContent:Yi.tokens?`Agents are nudged to clear their context past ${Yi.tokens.toLocaleString()} tokens.`:"Off: agents are never nudged to clear their context."})),Yi.custom){const n=We("button",{type:"button",className:"acct-forget",textContent:`Back to the default (${Yi.default.toLocaleString()})`});n.addEventListener("click",()=>iu(null)),Pe.append(n)}}async function iu(i){Kn="";try{const t=await fetch("/api/context-limit",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tokens:i})}),e=await t.json();if(!t.ok)throw new Error(e.error||"That didn’t save.");Yi=e}catch(t){Kn=t.message}Ii()}function Yo(i){i&&(Yi=i,!Ss&&Pe&&!Pe.hidden&&Ii())}async function Ko(i){Ss=!0,Kn="",Ii();try{const t=await fetch("/api/auth",i?{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i)}:{method:"DELETE"}),e=await t.json();if(!t.ok)throw new Error(e.error||"That didn’t save.");Tn=e,go=null}catch(t){Kn=t.message}Ss=!1,Ii()}function Jl(i){i&&(Tn=i,Ss||Ii())}function Lo(i){var t;Pe.hidden=!i,lr.setAttribute("aria-expanded",String(i)),i||(go=null,Kn=""),Ii(),i&&((t=Pe.querySelector('[aria-checked="true"]'))==null||t.focus()),i&&!Tn&&fetch("/api/auth").then(e=>e.ok?e.json():Promise.reject()).then(Jl,()=>{Kn="Restart the office server to choose this.",Ii()})}lr==null||lr.addEventListener("click",()=>Lo(Pe.hidden));var Jd;(Jd=document.getElementById("themeBtn"))==null||Jd.addEventListener("click",()=>{Pe.hidden||Lo(!1)});document.addEventListener("click",i=>{Pe&&!Pe.hidden&&!Pe.contains(i.target)&&!lr.contains(i.target)&&Lo(!1)});document.addEventListener("keydown",i=>{i.key==="Escape"&&Pe&&!Pe.hidden&&(Lo(!1),lr.focus())});const cr=document.getElementById("linkBtn"),Ue=document.getElementById("linkPop"),Zo=document.getElementById("app"),sh=[{id:"plan",name:"Plan only"},{id:"edit",name:"Edit files"},{id:"auto",name:"Full autonomy"}],sa={plan:0,edit:1,auto:2},jp=2e6,qp=/^[0-9A-HJKMNP-TV-Z]{8}$/;let Zn=null,Gr={},Pi=null,ns=null,Li=null,hr=null,hn="",fi="",vo=!1;const Pt=(i,t={},...e)=>{const n=Object.assign(document.createElement(i),t);return n.append(...e.filter(s=>s!=null&&s!==!1)),n},Fn=(i,t="acct-note")=>Pt("p",{className:t,textContent:i});async function ki(i,t,e){const n=t===void 0?{method:e||"GET"}:{method:e||"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)},s=await fetch(i,n),r=await s.json().catch(()=>({}));if(!s.ok)throw new Error(r.error||(s.status===404?"Restart the office server to use links.":"That didn’t work."));return r}function Yp(i){const t=String(i||"").toUpperCase().replace(/[\s-]+/g,"").replace(/[IL]/g,"1").replace(/O/g,"0");return qp.test(t)?t:null}const Kp=i=>{const t=String(i).toUpperCase().replace(/-/g,"");return`${t.slice(0,4)}-${t.slice(4)}`};function Ql(i){return i>=1e6?`${+(i/1e6).toFixed(1)}M`:i>=1e3?`${Math.round(i/1e3)}k`:String(i)}function Zp(i){const t=typeof i=="number"?i:Date.parse(i);if(!t)return"";const e=t-Date.now();if(e<=0)return"Expired. Make a new one.";const n=Math.ceil(e/6e4),s=Math.floor(n/60),r=n%60,a=new Date(t).toLocaleString([],{weekday:"short",hour:"numeric",minute:"2-digit"});return`Works once. Expires in ${s?`${s} h ${r} min`:`${r} min`} (${a}).`}function Jp(i){var n,s;const t=((n=i.repos)==null?void 0:n.length)||0,e=((s=sh.find(r=>r.id===i.clearance))==null?void 0:s.name)||i.clearance;return`${t===1?i.repos[0]:`${t} projects`} · ${e} · ${Ql(i.tokensPerDay||0)} tokens a day`}function Qp(i){return i.kind!=="guest"?"Linked office":i.role==="guest"?"Guest · you visit them":"Guest · they visit you"}function sn(){if(!Ue||Ue.hidden)return;const i=Gr.handle||(Pi==null?void 0:Pi.handle);Ue.replaceChildren(Pt("p",{className:"theme-k",textContent:"Linked offices"})),i?(Ue.append(Pt("p",{className:"lb-me"},"This office is ",Pt("strong",{textContent:`@${i}`}))),Ue.append(em()),ns&&Ue.append(nm()),Li&&Ue.append(sm())):Ue.append(...tm()),fi&&Ue.append(Fn(fi,"acct-note acct-err")),Gr.error?Ue.append(Fn(`Link service: ${Gr.error}`,"acct-note acct-err")):Zn!=null&&Zn.length&&Gr.connected===!1&&Ue.append(Fn("Connecting to the link service…","acct-note acct-fine")),Ue.append(rm())}function tm(){const i=[Fn("Linked offices see each other’s agents walk in as visitors, and a guest can run jobs here within the limits you set. First, pick a handle for this office.")];if(Pi&&!Pi.configured)return[...i,Fn("This office has no link service set up.","acct-note acct-err")];const t=Pt("form",{className:"acct-form"}),e=Pt("input",{type:"text",placeholder:"Pick a handle",autocomplete:"off",spellcheck:!1,maxLength:20});return e.setAttribute("aria-label","Handle"),t.append(e,Pt("button",{type:"submit",className:"primary small",textContent:hn==="claim"?"Claiming…":"Claim",disabled:!!hn})),t.addEventListener("submit",async n=>{n.preventDefault(),e.value.trim()&&await Do("claim",async()=>{om(await ki("/api/leaderboard/handle",{handle:e.value.trim()}),!0),_r(await ki("/api/links"))})}),[...i,t,Fn("Claiming a handle doesn’t put you on the leaderboard. Sharing your counters there is a separate choice.","acct-note acct-fine")]}function em(){const i=Pt("div",{className:"link-actions"}),t=Pt("button",{type:"button",className:"ghost small",textContent:hn==="link"?"Making a code…":"Invite an office",disabled:!!hn});t.addEventListener("click",()=>{Li=null,rf("link")});const e=Pt("button",{type:"button",className:"ghost small",textContent:"Invite a guest",disabled:!!hn});e.setAttribute("aria-expanded",String(!!Li)),e.addEventListener("click",im);const n=Pt("form",{className:"acct-form link-redeem"}),s=Pt("input",{type:"text",placeholder:"Enter a code, e.g. K7QX-M2PD",autocomplete:"off",spellcheck:!1,maxLength:12});return s.setAttribute("aria-label","Invite code"),n.append(s,Pt("button",{type:"submit",className:"primary small",textContent:hn==="redeem"?"Linking…":"Link",disabled:!!hn})),n.addEventListener("submit",r=>{r.preventDefault();const a=Yp(s.value);if(!a){fi="A code is 8 letters and numbers, like K7QX-M2PD.",sn();return}Do("redeem",async()=>{_r(await ki("/api/links/redeem",{code:a})),ns=null})}),i.append(Pt("div",{className:"link-row"},t,e),n),i}function nm(){const i=Pt("div",{className:"link-code"}),t=Kp(ns.code),e=Pt("button",{type:"button",className:"ghost small",textContent:vo?"Copied":"Copy"});return e.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(t),vo=!0}catch{fi="Couldn’t copy. Select the code and copy it by hand."}sn()}),i.append(Pt("p",{className:"theme-k",textContent:ns.kind==="guest"?"Guest code":"Office code"}),Pt("div",{className:"link-code-row"},Pt("output",{className:"link-code-v",textContent:t}),e),Fn(`${ns.kind==="guest"?"Give this to your guest. They enter it in their own office.":"Give this to the other office. They enter it under Linked offices."} ${Zp(ns.expiresAt)}`,"acct-note acct-fine")),i}async function im(){if(Li){Li=null,sn();return}if(Li={repos:new Set,clearance:"edit",full:!1,tokensPerDay:jp},ns=null,sn(),!hr){try{hr=(await ki("/api/repos")).repos||[]}catch(i){hr=[],fi=i.message}sn()}}function sm(){const i=Li,t=Pt("form",{className:"link-guest"});t.append(Pt("p",{className:"theme-k",textContent:"Invite a guest"}),Fn("A guest can start jobs with your agents in the projects you pick, at or below the clearance you set. Their jobs run on your Claude account.","acct-note acct-fine"));const e=Pt("fieldset",{className:"link-repos"},Pt("legend",{textContent:`Projects they can use (${i.repos.size} picked)`}));hr?hr.length||e.append(Fn("No projects found.","acct-note acct-fine")):e.append(Fn("Loading…","acct-note acct-fine"));for(const c of hr||[]){const h=Pt("input",{type:"checkbox",checked:i.repos.has(c)});h.addEventListener("change",()=>{h.checked?i.repos.add(c):i.repos.delete(c),sn()}),e.append(Pt("label",{},h,Pt("span",{textContent:c})))}const n=Pt("div",{className:"theme-modes acct-modes link-cap"});n.setAttribute("role","radiogroup"),n.setAttribute("aria-label","Clearance cap");for(const c of sh.slice(0,2)){const h=Pt("button",{type:"button",textContent:c.name,disabled:i.full});h.setAttribute("role","radio"),h.setAttribute("aria-checked",String(!i.full&&i.clearance===c.id)),h.addEventListener("click",()=>{i.clearance=c.id,sn()}),n.append(h)}const s=Pt("input",{type:"checkbox",checked:i.full});s.addEventListener("change",()=>{i.full=s.checked,sn()});const r=Pt("div",{className:"link-warn"},Pt("p",{textContent:"Full autonomy lets the guest run any command on this machine, with your files and your logins. Only allow it for someone you’d hand your laptop to."}),Pt("label",{},s,Pt("span",{textContent:"Allow full autonomy anyway"}))),a=Pt("input",{type:"number",min:1e5,step:1e5,value:i.tokensPerDay,required:!0});a.setAttribute("aria-label","Tokens per day");const o=Pt("span",{className:"acct-fine",textContent:Ql(i.tokensPerDay)});a.addEventListener("input",()=>{i.tokensPerDay=Math.floor(Number(a.value))||0,o.textContent=Ql(i.tokensPerDay)});const l=i.repos.size>0&&!hn;return t.append(e,Pt("p",{className:"link-k",textContent:"Clearance cap"}),n,r,Pt("label",{className:"link-k link-tokens"},Pt("span",{textContent:"Tokens per day"}),a,o),Pt("div",{className:"link-row"},Pt("button",{type:"submit",className:"primary small",textContent:hn==="guest"?"Making a code…":"Make guest code",disabled:!l}),i.repos.size?null:Pt("span",{className:"acct-fine",textContent:"Pick at least one project."}))),t.addEventListener("submit",c=>{if(c.preventDefault(),!i.repos.size||i.tokensPerDay<1e5){fi=i.repos.size?"Allow at least 100,000 tokens a day.":"Pick at least one project.",sn();return}rf("guest",{repos:[...i.repos],clearance:i.full?"auto":i.clearance,tokensPerDay:i.tokensPerDay})}),t}function rm(){const i=Pt("div",{className:"lb-board"});if(!Zn)return i.append(Fn("Loading links…","acct-note acct-fine")),i;if(!Zn.length)return i.append(Fn("No links yet.","acct-note acct-fine")),i;const t=Pt("ul",{className:"lb-list link-list"});for(const e of Zn){const n=Pt("li",{className:"link-item"},Pt("span",{className:"link-who"},Pt("strong",{textContent:`@${e.peer}`}),Pt("span",{className:"acct-fine",textContent:Qp(e)}),e.guest?Pt("span",{className:"acct-fine",textContent:Jp(e.guest)}):null)),s=Pt("span",{className:"link-row"});if(e.kind==="guest"&&e.role==="guest"){const a=Pt("button",{type:"button",className:"primary small",textContent:`Visit @${e.peer}`});a.addEventListener("click",()=>{location.search=`?visit=${encodeURIComponent(e.id)}`}),s.append(a)}const r=Pt("button",{type:"button",className:"acct-forget",textContent:hn===e.id?"Unlinking…":"Unlink",disabled:!!hn});r.addEventListener("click",()=>am(e)),s.append(r),n.append(s),t.append(n)}return i.append(t),i}async function Do(i,t){hn=i,fi="",sn();try{await t()}catch(e){fi=e.message}hn="",sn()}function rf(i,t){return vo=!1,Do(i,async()=>{const e=await ki("/api/links/invite",t?{kind:i,guest:t}:{kind:i});ns={kind:e.kind||i,code:e.code,expiresAt:e.expiresAt},Li=null})}function am(i){const t=i.kind!=="guest"?"You stop seeing each other’s agents.":i.role==="host"?"Their running jobs stop and they lose access right away.":"You can’t visit their office again without a new code.";confirm(`Unlink @${i.peer}? ${t}`)&&Do(i.id,async()=>{_r(await ki(`/api/links/${encodeURIComponent(i.id)}`,void 0,"DELETE"))})}function om(i,t=!1){Pi=i,t&&document.dispatchEvent(new CustomEvent("office:leaderboard",{detail:i}))}function _r(i){!i||!Array.isArray(i.links)||(Zn=i.links,Gr={handle:i.handle||null,connected:i.connected,error:i.error||null},ko(),hn||sn())}document.addEventListener("office:leaderboard",i=>{Pi=i.detail,hn||sn()});function Io(i){if(Ue.hidden=!i,cr.setAttribute("aria-expanded",String(i)),!i){fi="",Li=null,vo=!1;return}sn(),ki("/api/links").then(_r,t=>{Zn||(Zn=[]),fi=t.message,sn()}),Pi||ki("/api/leaderboard").then(t=>{Pi=t,sn()},()=>{})}cr==null||cr.addEventListener("click",()=>Io(Ue.hidden));var Qd;for(const i of["themeBtn","acctBtn"])(Qd=document.getElementById(i))==null||Qd.addEventListener("click",()=>{Ue.hidden||Io(!1)});document.addEventListener("click",i=>{Ue&&!Ue.hidden&&i.target.isConnected&&!Ue.contains(i.target)&&!cr.contains(i.target)&&Io(!1)});document.addEventListener("keydown",i=>{i.key==="Escape"&&Ue&&!Ue.hidden&&(Io(!1),cr.focus())});const Gt={on:!1,link:null,host:"",repos:null,clearance:"edit",tokensPerDay:0};{const i=new URLSearchParams(location.search).get("visit");i&&Object.assign(Gt,{on:!0,link:i})}function lm(i){i&&(ws="",Object.assign(Gt,{on:!0,link:i.link??Gt.link,host:i.host??Gt.host,repos:Array.isArray(i.repos)?i.repos:Gt.repos,clearance:sa[i.clearance]!=null?i.clearance:Gt.clearance,tokensPerDay:i.tokensPerDay??Gt.tokensPerDay}),ko())}function Ns(i,t=""){return i=encodeURIComponent(i),Gt.on?`/api/visit/${encodeURIComponent(Gt.link)}/jobs/${i}${t}`:`/api/jobs/${i}${t}`}function Jo(i,t,e){return Gt.on?{text:i,mode:t}:{message:i,mode:t,files:e}}const Qo=i=>`#${i.replace(/\s+/g,"-")}`.toLowerCase();async function cm({text:i,mode:t,model:e}){const n=(i.match(/(^|\s)#[\w.-]+/g)||[]).map(c=>c.trim().toLowerCase()),s=Gt.repos||[],r=s.filter(c=>n.includes(Qo(c)));if(r.length!==1){const c=s.map(Qo).join(", ")||"none yet";throw new Error(r.length?"Name just one project per job.":`Name the project with a # tag. You can use: ${c}.`)}const a=r[0],o=i.replace(new RegExp(`(^|\\s)${Qo(a).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(?=\\s|$)`,"i")," ").replace(/\s+/g," ").trim();if(!o)throw new Error("Say what the job is, as well as the project.");const{job:l}=await ki(`/api/visit/${encodeURIComponent(Gt.link)}/jobs`,{repo:a,prompt:o,mode:t,model:e});return l}function hm(i){return!Gt.on||!i?i:Object.fromEntries(Object.entries(i).filter(([t])=>(sa[t]??9)<=sa[Gt.clearance]))}function su(i){return!Gt.on||!Array.isArray(i)?i:i.filter(t=>{var e;return(e=Gt.repos)==null?void 0:e.includes(t)})}let ws="",to=!1;function um(i){if(!Gt.on)return null;if(i===4404)ws="The host ended this link. You can’t visit any more.";else if(i===4502)ws="Can’t reach the host’s office right now. Trying again…";else return ws="",null;return to=i===4404,ko(),i===4404?0:1e4}function ko(){var r,a,o,l;if(!Gt.on)return;const i=Gt.host||((r=Zn==null?void 0:Zn.find(c=>c.id===Gt.link))==null?void 0:r.peer)||"";i&&(Gt.host=i),Zo.classList.add("visiting"),Zo.dataset.visiting=i,Zo.classList.toggle("visit-ended",!!to);const t=document.getElementById("input");if(t){t.placeholder=to?"This link has ended.":`Start a job${i?` at @${i}`:""} · #project`;for(const c of document.querySelectorAll("#composer textarea, #composer select, #composer button"))c.disabled=!!to}const e=document.getElementById("mode");if(e){for(const c of e.options)c.hidden=c.disabled=sa[c.value]>sa[Gt.clearance];(a=e.selectedOptions[0])!=null&&a.disabled&&(e.value=Gt.clearance)}let n=document.getElementById("visitBar");n||(n=Pt("div",{className:"visit-bar",id:"visitBar"}),n.setAttribute("role","status"),(o=document.querySelector(".brand"))==null||o.after(n));const s=Pt("a",{href:location.pathname,textContent:"Back to my office"});n.replaceChildren(Pt("span",{},"Visiting ",Pt("strong",{textContent:i?`@${i}`:"a linked office"}),Gt.repos?` · ${Gt.repos.length} ${Gt.repos.length===1?"project":"projects"}, up to ${(l=sh.find(c=>c.id===Gt.clearance))==null?void 0:l.name.toLowerCase()}`:""),s),n.classList.toggle("visit-off",!!ws),ws&&n.append(Pt("p",{className:"visit-note",textContent:ws}))}ko();const nr=document.getElementById("setBtn"),Ie=document.getElementById("settings");let Es=null,Je={},ur=!1,as="",af=()=>{};const Ce=(i,t={})=>Object.assign(document.createElement(i),t);Ce.kids=(i,t)=>(i.append(...t),i);const eo=i=>i.key in Je?Je[i.key]:i.value,ru=(i,t)=>i.kind==="bool"?t?"on":"off":i.kind==="time"?t||"off":i.kind==="text"?t||"the account name":i.kind==="number"?`${Number(t).toLocaleString()}${i.unit?` ${i.unit}`:""}`:String(t),of=(i,t)=>Number.isInteger(t)&&t>=i.min&&t<=i.max,lf=()=>Object.keys(Je);function dm(i){const t=eo(i),e=`set-${i.key}`,n=r=>{Object.is(r,i.value)?delete Je[i.key]:Je[i.key]=r,rh(),cf(i)};if(i.kind==="bool"){const r=Ce("button",{type:"button",id:e,className:"set-switch"});return r.setAttribute("role","switch"),r.setAttribute("aria-checked",String(!!t)),r.addEventListener("click",()=>{n(!eo(i)),r.setAttribute("aria-checked",String(!!eo(i)))}),r}if(i.kind==="choice"){const r=Ce("div",{className:"theme-modes set-choice"});r.setAttribute("role","radiogroup"),r.setAttribute("aria-label",i.label),r.style.gridTemplateColumns=`repeat(${i.options.length}, 1fr)`;for(const a of i.options){const o=Ce("button",{type:"button",textContent:a});o.setAttribute("role","radio"),o.setAttribute("aria-checked",String(a===t)),o.addEventListener("click",()=>{n(a);for(const l of r.children)l.setAttribute("aria-checked",String(l.textContent===a))}),r.append(o)}return r}const s=Ce("input",{id:e,className:"set-input"});return s.spellcheck=!1,s.autocomplete="off",i.kind==="number"?Object.assign(s,{type:"number",min:i.min,max:i.max,step:i.step||1,value:t,inputMode:"numeric"}):i.kind==="time"?Object.assign(s,{type:"time",value:t}):Object.assign(s,{type:"text",value:t,maxLength:i.max,placeholder:i.default||"Your first name"}),s.addEventListener("input",()=>{const r=s.value;n(i.kind==="number"?r===""?NaN:Number(r):r)}),s}const tc=new Map;function cf(i){const t=tc.get(i.key);if(!t)return;t.classList.toggle("set-changed",i.key in Je);const e=t.querySelector(".set-fine");e.replaceChildren();const n=eo(i);if(i.kind==="number"&&!of(i,n)){e.textContent=`Use a whole number from ${i.min.toLocaleString()} to ${i.max.toLocaleString()}.`,e.classList.add("acct-err");return}if(e.classList.remove("acct-err"),i.hint&&e.append(i.hint," "),i.custom&&!(i.key in Je)){const s=Ce("button",{type:"button",className:"acct-forget set-reset",textContent:`Use the default (${ru(i,i.default)})`});s.addEventListener("click",()=>ec({[i.key]:null})),e.append(s)}else i.custom||e.append(`Default: ${ru(i,i.default)}.`)}function rh(){const i=lf().length,t=Ie.querySelector(".set-save"),e=Ie.querySelector(".set-undo"),n=Ie.querySelector(".set-msg");if(!t)return;const s=Es.some(r=>r.key in Je&&r.kind==="number"&&!of(r,Je[r.key]));t.disabled=ur||!i||s,t.textContent=ur?"Saving…":i>1?`Save ${i} changes`:"Save",e.hidden=!i||ur,n.textContent=as||(i?"Unsaved changes":""),n.classList.toggle("acct-err",!!as)}function dr(){tc.clear();const i=Ie.querySelector(".set-body");if(i.replaceChildren(),!Es){i.append(Ce("p",{className:"acct-note",textContent:as||"Loading…"}));return}const t=[...new Set(Es.map(e=>e.group))];for(const e of t){const n=Ce("section",{className:"set-group"});n.append(Ce("h3",{className:"theme-k",textContent:e}));for(const s of Es.filter(r=>r.group===e)){const r=Ce("div",{className:"set-row"}),a=Ce("div",{className:"set-text"}),o=Ce("label",{className:"set-label",textContent:s.label});o.htmlFor=`set-${s.key}`,a.append(o,Ce("p",{className:"acct-note acct-fine set-fine"})),r.append(a,dm(s)),tc.set(s.key,r),n.append(r),cf(s)}i.append(n)}rh()}async function ec(i){ur=!0,as="",rh();try{const t=await fetch("/api/settings",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i)}),e=await t.json();if(!t.ok)throw new Error(e.error||"That didn’t save.");for(const n of Object.keys(i))delete Je[n];ah(e),af("Settings saved","good")}catch(t){as=t.message}ur=!1,dr()}let hf=()=>{};function ah(i){Es=i.settings;for(const t of Es)t.key in Je&&Object.is(Je[t.key],t.value)&&delete Je[t.key];i.owner!==void 0&&hf(i.owner)}function au(i){i!=null&&i.settings&&(ah(i),Ie!=null&&Ie.open&&!ur&&dr())}function fm(){var i;as="",Ie.showModal(),nr.setAttribute("aria-expanded","true"),dr(),Es||fetch("/api/settings").then(t=>t.ok?t.json():Promise.reject()).then(t=>{ah(t),dr()},()=>{as="Restart the office server to use Settings.",dr()}),(i=Ie.querySelector("input, button.set-switch, [role=radio]"))==null||i.focus()}function tl(){return lf().length&&!confirm("Discard your unsaved changes?")?!1:(Je={},Ie.close(),!0)}function pm({toast:i,renderOwner:t}){if(af=i,hf=t,!(!nr||!Ie)){if(Gt.on){nr.hidden=!0;return}Ie.append(Ce.kids(Ce("header",{className:"set-head"}),[Ce("h2",{textContent:"Settings"}),Object.assign(Ce("button",{type:"button",className:"theme-btn set-x"}),{innerHTML:'<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18"/></svg>',ariaLabel:"Close settings"})]),Ce("div",{className:"set-body"}),Ce.kids(Ce("footer",{className:"set-foot"}),[Ce("span",{className:"set-msg",role:"status"}),Ce("button",{type:"button",className:"set-undo acct-forget",textContent:"Discard",hidden:!0}),Ce("button",{type:"button",className:"primary small set-save",textContent:"Save",disabled:!0})])),Ie.querySelector(".set-x").addEventListener("click",tl),Ie.querySelector(".set-undo").addEventListener("click",()=>{Je={},as="",dr()}),Ie.querySelector(".set-save").addEventListener("click",()=>ec({...Je})),nr.addEventListener("click",fm),Ie.addEventListener("cancel",e=>{e.preventDefault(),tl()}),Ie.addEventListener("click",e=>{e.target===Ie&&tl()}),Ie.addEventListener("close",()=>{nr.setAttribute("aria-expanded","false"),nr.focus()}),Ie.addEventListener("keydown",e=>{e.key==="Enter"&&e.target.matches("input")&&!Ie.querySelector(".set-save").disabled&&(e.preventDefault(),ec({...Je}))})}}const fr=document.getElementById("lbBtn"),Te=document.getElementById("lbPop"),uf=[{id:"jobs",name:"Jobs",value:i=>String(i.jobs)},{id:"tokens",name:"Tokens",value:i=>oh(i.tokens)},{id:"time",name:"Time",value:i=>lh(i.seconds)}],mm=[{id:"week",name:"This week"},{id:"all",name:"All time"}];let jt=null,nc="week",jr="jobs",Zi=null,ic=!1,Ai=!1,kn="",sc="";const Kt=(i,t={})=>Object.assign(document.createElement(i),t);function oh(i){return i>=1e9?`${(i/1e9).toFixed(1)}B`:i>=1e6?`${(i/1e6).toFixed(1)}M`:i>=1e3?`${(i/1e3).toFixed(i>=1e5?0:1)}k`:String(i)}function lh(i){const t=Math.round(i/60);return t<1?i>0?"<1m":"0m":t<60?`${t}m`:`${Math.floor(t/60)}h ${String(t%60).padStart(2,"0")}m`}function df(i){const t=Math.max(0,Math.round((Date.now()-i)/1e3));return t<90?"just now":t<5400?`${Math.round(t/60)} min ago`:t<129600?`${Math.round(t/3600)} h ago`:`${Math.round(t/86400)} days ago`}function ou(i,t,e,n,s=""){const r=Kt("div",{className:`theme-modes lb-tabs ${s}`});r.setAttribute("role","radiogroup"),r.setAttribute("aria-label",e);for(const a of i){const o=Kt("button",{type:"button"});o.setAttribute("role","radio"),o.setAttribute("aria-checked",String(a.id===t)),o.append(Kt("span",{textContent:a.name})),o.addEventListener("click",()=>n(a.id)),r.append(o)}return r}function Jn(){if(!Te)return;Te.replaceChildren(Kt("p",{className:"theme-k",textContent:"Leaderboard"}));const i=(t,e="acct-note")=>Te.append(Kt("p",{className:e,textContent:t}));if(!jt){i(kn||"Checking…");return}if(!jt.configured){i("No leaderboard is set up for this office. Whoever hosts one gives you its address: set it as OFFICE_LEADERBOARD_URL and restart the office.");return}if(lu())gm();else if(jt.joined){const t=jt.week,e=Kt("p",{className:"lb-me"});Te.append(e),e.append(Kt("strong",{textContent:jt.handle}),Kt("span",{textContent:` · ${t.jobs} ${t.jobs===1?"job":"jobs"}, ${oh(t.tokens)} tokens, ${lh(t.seconds)} this week`}));const n=jt.error?`Not shared yet: ${jt.error}`:jt.lastSync?`Shared ${df(jt.lastSync)}.`:"Sharing…";i(n,jt.error?"acct-note acct-err":"acct-note acct-fine")}else{i("Compete on jobs finished, tokens used and time your agents spend working. Joining shares exactly these counters per day, for the last two weeks and from now on, under the handle you claim. Never prompts, projects, files, chat or cost.");const t=Kt("form",{className:"acct-form"}),e=Kt("input",{type:"text",placeholder:"Pick a handle",autocomplete:"off",spellcheck:!1,maxLength:20});e.setAttribute("aria-label","Handle"),t.append(e,Kt("button",{type:"submit",className:"primary small",textContent:Ai?"Joining…":"Join",disabled:Ai})),t.addEventListener("submit",n=>{n.preventDefault(),e.value.trim()&&xo("POST",{handle:e.value})}),Te.append(t),kn&&i(kn,"acct-note acct-err")}if(Te.append(ou(mm,nc,"Period",t=>{nc=t,_o()},"lb-period"),ou(uf,jr,"Ranked by",t=>{jr=t,Jn()},"lb-metric")),Te.append(vm()),jt.joined&&!lu()){const t=Kt("button",{type:"button",className:"acct-forget",textContent:Ai?"Working…":"Leave and delete my data",disabled:Ai});t.addEventListener("click",()=>{confirm("Leave the leaderboard? Your handle is released and your counters are deleted from the service.")&&xo("DELETE")}),Te.append(t),kn&&i(kn,"acct-note acct-err")}}const lu=()=>!!jt&&"sharing"in jt&&!!jt.handle;function gm(){const i=(s,r="acct-note")=>Te.append(Kt("p",{className:r,textContent:s})),t=Kt("p",{className:"lb-me"});if(t.append(Kt("strong",{textContent:jt.handle})),jt.sharing&&jt.week){const s=jt.week;t.append(Kt("span",{textContent:` · ${s.jobs} ${s.jobs===1?"job":"jobs"}, ${oh(s.tokens)} tokens, ${lh(s.seconds)} this week`}))}Te.append(t);const e=Kt("input",{type:"checkbox",checked:!!jt.sharing,disabled:Ai});e.addEventListener("change",()=>{if(e.checked){xo("POST",{handle:jt.handle});return}confirm("Stop sharing? Your counters are deleted from the board. You keep your handle while you have linked offices; with none, the handle is released too.")?xo("DELETE"):e.checked=!0});const n=Kt("label",{className:"lb-share"});if(n.append(e,Kt("span",{textContent:"Share my counters on the board"})),Te.append(n),jt.sharing){const s=jt.error?`Not shared yet: ${jt.error}`:jt.lastSync?`Shared ${df(jt.lastSync)}.`:"Sharing…";i(s,jt.error?"acct-note acct-err":"acct-note acct-fine")}else i("Sharing sends jobs finished, tokens and agent time per day, for the last two weeks and from now on. Never prompts, projects, files, chat or cost.","acct-note acct-fine");kn&&i(kn,"acct-note acct-err")}function vm(){var r;const i=Kt("div",{className:"lb-board"});if(!Zi)return i.append(Kt("p",{className:"acct-note",textContent:ic?"Loading…":sc||"No board yet."})),i;const e=Zi[jr==="time"?"time":jr]||[];if(!e.length)return i.append(Kt("p",{className:"acct-note",textContent:"Nobody on the board yet."})),i;const n=uf.find(a=>a.id===jr),s=Kt("ol",{className:"lb-list"});for(const a of e){const o=Kt("li",{className:a.handle.toLowerCase()===((r=jt.handle)==null?void 0:r.toLowerCase())?"lb-row lb-you":"lb-row"});o.append(Kt("span",{className:"lb-rank",textContent:String(a.rank)}),Kt("span",{className:"lb-name",textContent:a.handle}),Kt("span",{className:"lb-val",textContent:n.value(a)})),s.append(o)}return i.append(s),Zi.players>e.length&&i.append(Kt("p",{className:"acct-note acct-fine",textContent:`Top ${e.length} of ${Zi.players}.`})),Zi.since&&i.append(Kt("p",{className:"acct-note acct-fine",textContent:"Weeks start Monday, UTC."})),i}async function _o(){if(jt!=null&&jt.configured){ic=!0,sc="",Jn();try{const i=await fetch(`/api/leaderboard/board?period=${nc}`),t=await i.json();if(!i.ok)throw new Error(t.error||"Couldn’t load the board.");Zi=t}catch(i){Zi=null,sc=i.message}ic=!1,Te.hidden||Jn()}}async function xo(i,t){Ai=!0,kn="",Jn();try{const e=await fetch("/api/leaderboard",i==="POST"?{method:i,headers:{"content-type":"application/json"},body:JSON.stringify(t)}:{method:i}),n=await e.json();if(!e.ok)throw new Error(n.error||"That didn’t work.");oa(n),Zi=null}catch(e){kn=e.message}Ai=!1,Jn(),kn||_o()}function cu(i){i&&(oa(i),!Ai&&!Te.hidden&&Jn())}function oa(i){jt=i,document.dispatchEvent(new CustomEvent("office:leaderboard",{detail:i}))}document.addEventListener("office:leaderboard",i=>{i.detail!==jt&&(jt=i.detail,!Ai&&Te&&!Te.hidden&&Jn())});function No(i){if(Te.hidden=!i,fr.setAttribute("aria-expanded",String(i)),!i){kn="";return}Jn(),jt?_o():fetch("/api/leaderboard").then(t=>t.ok?t.json():Promise.reject()).then(t=>{oa(t),Jn(),_o()},()=>{kn="Restart the office server to use this.",Jn()})}fr==null||fr.addEventListener("click",()=>No(Te.hidden));var tf;for(const i of["themeBtn","acctBtn"])(tf=document.getElementById(i))==null||tf.addEventListener("click",()=>{Te.hidden||No(!1)});document.addEventListener("click",i=>{const t=i.composedPath();Te&&!Te.hidden&&!t.includes(Te)&&!t.includes(fr)&&No(!1)});document.addEventListener("keydown",i=>{i.key==="Escape"&&Te&&!Te.hidden&&(No(!1),fr.focus())});const rc="office.nameAsked",_m="office.name",xm=i=>i.trim().replace(/\s+/g,"_").replace(/[^A-Za-z0-9_-]/g,"").slice(0,20);function ym(){const i=Kt("dialog",{className:"name-ask"}),t=Kt("form",{method:"dialog"}),e=Kt("input",{type:"text",placeholder:"Your name",autocomplete:"off",spellcheck:!1,maxLength:40});e.setAttribute("aria-label","Your name");const n=Kt("p",{className:"acct-note acct-err",hidden:!0}),s=Kt("button",{type:"submit",className:"primary small",textContent:"Continue"}),r=Kt("button",{type:"button",className:"acct-forget",textContent:"Not now"}),a=Kt("div",{className:"acct-form"});a.append(e,s),t.append(Kt("h2",{textContent:"Welcome to the office"}),Kt("p",{className:"acct-note",textContent:jt!=null&&jt.configured?"What should we call you? Your name becomes your handle on the leaderboard. Nothing is shared until you join it.":"What should we call you?"}),a,n,r),i.append(t);const o=()=>{try{localStorage.setItem(rc,"1")}catch{}i.close(),i.remove()};r.addEventListener("click",o),i.addEventListener("cancel",o),t.addEventListener("submit",async l=>{l.preventDefault();const c=e.value.trim(),h=xm(c);if(c){n.hidden=!0,s.disabled=!0;try{if(jt!=null&&jt.configured){if(h.length<3)throw new Error("Use at least 3 letters or numbers.");const u=await fetch("/api/leaderboard/handle",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({handle:h})}),d=await u.json();if(!u.ok)throw new Error(d.error||"That handle didn’t work.");oa(d),Te.hidden||Jn()}try{localStorage.setItem(_m,c)}catch{}o()}catch(u){n.textContent=u.message,n.hidden=!1,s.disabled=!1,e.focus()}}}),document.body.append(i),i.showModal(),e.focus()}try{!localStorage.getItem(rc)&&!new URLSearchParams(location.search).has("visit")&&fetch("/api/leaderboard").then(i=>i.ok?i.json():null).catch(()=>null).then(i=>{if(i&&oa(i),i!=null&&i.handle){try{localStorage.setItem(rc,"1")}catch{}return}ym()})}catch{}/**
3
3
  * @license
4
4
  * Copyright 2010-2024 Three.js Authors
5
5
  * SPDX-License-Identifier: MIT
6
- */const jc="169",Ci={ROTATE:0,DOLLY:1,PAN:2},Ji={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},jp=0,Wh=1,qp=2,Vd=1,Gd=2,Mi=3,es=0,on=1,si=2,Xe=0,sr=1,Xl=2,Xh=3,jh=4,$d=5,$n=100,Yp=101,Kp=102,Zp=103,Jp=104,Nr=200,Qp=201,tm=202,em=203,jl=204,ql=205,Yl=206,nm=207,Kl=208,im=209,sm=210,rm=211,am=212,om=213,lm=214,Zl=0,Jl=1,Ql=2,hr=3,tc=4,ec=5,nc=6,ic=7,Wd=0,cm=1,hm=2,Qi=0,Xd=1,jd=2,qd=3,Yd=4,um=5,Kd=6,qc=7,Zd=300,ur=301,dr=302,sc=303,rc=304,To=306,Pi=1e3,ms=1001,ac=1002,tn=1003,dm=1004,ra=1005,Wn=1006,Go=1007,gs=1008,hi=1009,Jd=1010,Qd=1011,Kr=1012,Yc=1013,_s=1014,wi=1015,Li=1016,Kc=1017,Zc=1018,xs=1020,tf=35902,ef=1021,nf=1022,Dn=1023,sf=1024,rf=1025,rr=1026,ys=1027,af=1028,Jc=1029,of=1030,Qc=1031,th=1033,Xa=33776,ja=33777,qa=33778,Ya=33779,oc=35840,lc=35841,cc=35842,hc=35843,uc=36196,dc=37492,fc=37496,pc=37808,mc=37809,gc=37810,vc=37811,_c=37812,xc=37813,yc=37814,Mc=37815,bc=37816,Sc=37817,wc=37818,Ec=37819,Tc=37820,Ac=37821,Ka=36492,Cc=36494,Rc=36495,lf=36283,Pc=36284,Lc=36285,Dc=36286,fm=3200,pm=3201,eh=0,mm=1,Xi="",je="srgb",is="srgb-linear",nh="display-p3",Ao="display-p3-linear",co="linear",ye="srgb",ho="rec709",uo="p3",Cs=7680,qh=519,gm=512,vm=513,_m=514,cf=515,xm=516,ym=517,Mm=518,bm=519,Yh=35044,Kh="300 es",Ei=2e3,fo=2001;class bs{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const n=this._listeners;n[t]===void 0&&(n[t]=[]),n[t].indexOf(e)===-1&&n[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;const n=this._listeners;return n[t]!==void 0&&n[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;const s=this._listeners[t];if(s!==void 0){const r=s.indexOf(e);r!==-1&&s.splice(r,1)}}dispatchEvent(t){if(this._listeners===void 0)return;const n=this._listeners[t.type];if(n!==void 0){t.target=this;const s=n.slice(0);for(let r=0,a=s.length;r<a;r++)s[r].call(this,t);t.target=null}}}const Ke=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Zh=1234567;const zr=Math.PI/180,Zr=180/Math.PI;function vr(){const i=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(Ke[i&255]+Ke[i>>8&255]+Ke[i>>16&255]+Ke[i>>24&255]+"-"+Ke[t&255]+Ke[t>>8&255]+"-"+Ke[t>>16&15|64]+Ke[t>>24&255]+"-"+Ke[e&63|128]+Ke[e>>8&255]+"-"+Ke[e>>16&255]+Ke[e>>24&255]+Ke[n&255]+Ke[n>>8&255]+Ke[n>>16&255]+Ke[n>>24&255]).toLowerCase()}function Ue(i,t,e){return Math.max(t,Math.min(e,i))}function ih(i,t){return(i%t+t)%t}function Sm(i,t,e,n,s){return n+(i-t)*(s-n)/(e-t)}function wm(i,t,e){return i!==t?(e-i)/(t-i):0}function Br(i,t,e){return(1-e)*i+e*t}function Em(i,t,e,n){return Br(i,t,1-Math.exp(-e*n))}function Tm(i,t=1){return t-Math.abs(ih(i,t*2)-t)}function Am(i,t,e){return i<=t?0:i>=e?1:(i=(i-t)/(e-t),i*i*(3-2*i))}function Cm(i,t,e){return i<=t?0:i>=e?1:(i=(i-t)/(e-t),i*i*i*(i*(i*6-15)+10))}function Rm(i,t){return i+Math.floor(Math.random()*(t-i+1))}function Pm(i,t){return i+Math.random()*(t-i)}function Lm(i){return i*(.5-Math.random())}function Dm(i){i!==void 0&&(Zh=i);let t=Zh+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function Im(i){return i*zr}function km(i){return i*Zr}function Nm(i){return(i&i-1)===0&&i!==0}function Um(i){return Math.pow(2,Math.ceil(Math.log(i)/Math.LN2))}function Om(i){return Math.pow(2,Math.floor(Math.log(i)/Math.LN2))}function Fm(i,t,e,n,s){const r=Math.cos,a=Math.sin,o=r(e/2),l=a(e/2),c=r((t+n)/2),h=a((t+n)/2),u=r((t-n)/2),d=a((t-n)/2),f=r((n-t)/2),g=a((n-t)/2);switch(s){case"XYX":i.set(o*h,l*u,l*d,o*c);break;case"YZY":i.set(l*d,o*h,l*u,o*c);break;case"ZXZ":i.set(l*u,l*d,o*h,o*c);break;case"XZX":i.set(o*h,l*g,l*f,o*c);break;case"YXY":i.set(l*f,o*h,l*g,o*c);break;case"ZYZ":i.set(l*g,l*f,o*h,o*c);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function qs(i,t){switch(t.constructor){case Float32Array:return i;case Uint32Array:return i/4294967295;case Uint16Array:return i/65535;case Uint8Array:return i/255;case Int32Array:return Math.max(i/2147483647,-1);case Int16Array:return Math.max(i/32767,-1);case Int8Array:return Math.max(i/127,-1);default:throw new Error("Invalid component type.")}}function nn(i,t){switch(t.constructor){case Float32Array:return i;case Uint32Array:return Math.round(i*4294967295);case Uint16Array:return Math.round(i*65535);case Uint8Array:return Math.round(i*255);case Int32Array:return Math.round(i*2147483647);case Int16Array:return Math.round(i*32767);case Int8Array:return Math.round(i*127);default:throw new Error("Invalid component type.")}}const fs={DEG2RAD:zr,RAD2DEG:Zr,generateUUID:vr,clamp:Ue,euclideanModulo:ih,mapLinear:Sm,inverseLerp:wm,lerp:Br,damp:Em,pingpong:Tm,smoothstep:Am,smootherstep:Cm,randInt:Rm,randFloat:Pm,randFloatSpread:Lm,seededRandom:Dm,degToRad:Im,radToDeg:km,isPowerOfTwo:Nm,ceilPowerOfTwo:Um,floorPowerOfTwo:Om,setQuaternionFromProperEuler:Fm,normalize:nn,denormalize:qs};class rt{constructor(t=0,e=0){rt.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,n=this.y,s=t.elements;return this.x=s[0]*e+s[3]*n+s[6],this.y=s[1]*e+s[4]*n+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(Ue(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const n=Math.cos(e),s=Math.sin(e),r=this.x-t.x,a=this.y-t.y;return this.x=r*n-a*s+t.x,this.y=r*s+a*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Xt{constructor(t,e,n,s,r,a,o,l,c){Xt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,n,s,r,a,o,l,c)}set(t,e,n,s,r,a,o,l,c){const h=this.elements;return h[0]=t,h[1]=s,h[2]=o,h[3]=e,h[4]=r,h[5]=l,h[6]=n,h[7]=a,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,s=e.elements,r=this.elements,a=n[0],o=n[3],l=n[6],c=n[1],h=n[4],u=n[7],d=n[2],f=n[5],g=n[8],_=s[0],m=s[3],p=s[6],y=s[1],x=s[4],S=s[7],L=s[2],T=s[5],E=s[8];return r[0]=a*_+o*y+l*L,r[3]=a*m+o*x+l*T,r[6]=a*p+o*S+l*E,r[1]=c*_+h*y+u*L,r[4]=c*m+h*x+u*T,r[7]=c*p+h*S+u*E,r[2]=d*_+f*y+g*L,r[5]=d*m+f*x+g*T,r[8]=d*p+f*S+g*E,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8];return e*a*h-e*o*c-n*r*h+n*o*l+s*r*c-s*a*l}invert(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=h*a-o*c,d=o*l-h*r,f=c*r-a*l,g=e*u+n*d+s*f;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);const _=1/g;return t[0]=u*_,t[1]=(s*c-h*n)*_,t[2]=(o*n-s*a)*_,t[3]=d*_,t[4]=(h*e-s*l)*_,t[5]=(s*r-o*e)*_,t[6]=f*_,t[7]=(n*l-c*e)*_,t[8]=(a*e-n*r)*_,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,s,r,a,o){const l=Math.cos(r),c=Math.sin(r);return this.set(n*l,n*c,-n*(l*a+c*o)+a+t,-s*c,s*l,-s*(-c*a+l*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply($o.makeScale(t,e)),this}rotate(t){return this.premultiply($o.makeRotation(-t)),this}translate(t,e){return this.premultiply($o.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,n=t.elements;for(let s=0;s<9;s++)if(e[s]!==n[s])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const $o=new Xt;function hf(i){for(let t=i.length-1;t>=0;--t)if(i[t]>=65535)return!0;return!1}function po(i){return document.createElementNS("http://www.w3.org/1999/xhtml",i)}function zm(){const i=po("canvas");return i.style.display="block",i}const Jh={};function Za(i){i in Jh||(Jh[i]=!0,console.warn(i))}function Bm(i,t,e){return new Promise(function(n,s){function r(){switch(i.clientWaitSync(t,i.SYNC_FLUSH_COMMANDS_BIT,0)){case i.WAIT_FAILED:s();break;case i.TIMEOUT_EXPIRED:setTimeout(r,e);break;default:n()}}setTimeout(r,e)})}function Hm(i){const t=i.elements;t[2]=.5*t[2]+.5*t[3],t[6]=.5*t[6]+.5*t[7],t[10]=.5*t[10]+.5*t[11],t[14]=.5*t[14]+.5*t[15]}function Vm(i){const t=i.elements;t[11]===-1?(t[10]=-t[10]-1,t[14]=-t[14]):(t[10]=-t[10],t[14]=-t[14]+1)}const Qh=new Xt().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),tu=new Xt().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),yr={[is]:{transfer:co,primaries:ho,luminanceCoefficients:[.2126,.7152,.0722],toReference:i=>i,fromReference:i=>i},[je]:{transfer:ye,primaries:ho,luminanceCoefficients:[.2126,.7152,.0722],toReference:i=>i.convertSRGBToLinear(),fromReference:i=>i.convertLinearToSRGB()},[Ao]:{transfer:co,primaries:uo,luminanceCoefficients:[.2289,.6917,.0793],toReference:i=>i.applyMatrix3(tu),fromReference:i=>i.applyMatrix3(Qh)},[nh]:{transfer:ye,primaries:uo,luminanceCoefficients:[.2289,.6917,.0793],toReference:i=>i.convertSRGBToLinear().applyMatrix3(tu),fromReference:i=>i.applyMatrix3(Qh).convertLinearToSRGB()}},Gm=new Set([is,Ao]),oe={enabled:!0,_workingColorSpace:is,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(i){if(!Gm.has(i))throw new Error(`Unsupported working color space, "${i}".`);this._workingColorSpace=i},convert:function(i,t,e){if(this.enabled===!1||t===e||!t||!e)return i;const n=yr[t].toReference,s=yr[e].fromReference;return s(n(i))},fromWorkingColorSpace:function(i,t){return this.convert(i,this._workingColorSpace,t)},toWorkingColorSpace:function(i,t){return this.convert(i,t,this._workingColorSpace)},getPrimaries:function(i){return yr[i].primaries},getTransfer:function(i){return i===Xi?co:yr[i].transfer},getLuminanceCoefficients:function(i,t=this._workingColorSpace){return i.fromArray(yr[t].luminanceCoefficients)}};function ar(i){return i<.04045?i*.0773993808:Math.pow(i*.9478672986+.0521327014,2.4)}function Wo(i){return i<.0031308?i*12.92:1.055*Math.pow(i,.41666)-.055}let Rs;class $m{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{Rs===void 0&&(Rs=po("canvas")),Rs.width=t.width,Rs.height=t.height;const n=Rs.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=Rs}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=po("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const s=n.getImageData(0,0,t.width,t.height),r=s.data;for(let a=0;a<r.length;a++)r[a]=ar(r[a]/255)*255;return n.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let n=0;n<e.length;n++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[n]=Math.floor(ar(e[n]/255)*255):e[n]=ar(e[n]);return{data:e,width:t.width,height:t.height}}else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Wm=0;class uf{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Wm++}),this.uuid=vr(),this.data=t,this.dataReady=!0,this.version=0}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const n={uuid:this.uuid,url:""},s=this.data;if(s!==null){let r;if(Array.isArray(s)){r=[];for(let a=0,o=s.length;a<o;a++)s[a].isDataTexture?r.push(Xo(s[a].image)):r.push(Xo(s[a]))}else r=Xo(s);n.url=r}return e||(t.images[this.uuid]=n),n}}function Xo(i){return typeof HTMLImageElement<"u"&&i instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&i instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&i instanceof ImageBitmap?$m.getDataURL(i):i.data?{data:Array.from(i.data),width:i.width,height:i.height,type:i.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let Xm=0;class en extends bs{constructor(t=en.DEFAULT_IMAGE,e=en.DEFAULT_MAPPING,n=ms,s=ms,r=Wn,a=gs,o=Dn,l=hi,c=en.DEFAULT_ANISOTROPY,h=Xi){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Xm++}),this.uuid=vr(),this.name="",this.source=new uf(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=n,this.wrapT=s,this.magFilter=r,this.minFilter=a,this.anisotropy=c,this.format=o,this.internalFormat=null,this.type=l,this.offset=new rt(0,0),this.repeat=new rt(1,1),this.center=new rt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Xt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const n={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==Zd)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Pi:t.x=t.x-Math.floor(t.x);break;case ms:t.x=t.x<0?0:1;break;case ac:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case Pi:t.y=t.y-Math.floor(t.y);break;case ms:t.y=t.y<0?0:1;break;case ac:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}en.DEFAULT_IMAGE=null;en.DEFAULT_MAPPING=Zd;en.DEFAULT_ANISOTROPY=1;class me{constructor(t=0,e=0,n=0,s=1){me.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,s){return this.x=t,this.y=e,this.z=n,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,n=this.y,s=this.z,r=this.w,a=t.elements;return this.x=a[0]*e+a[4]*n+a[8]*s+a[12]*r,this.y=a[1]*e+a[5]*n+a[9]*s+a[13]*r,this.z=a[2]*e+a[6]*n+a[10]*s+a[14]*r,this.w=a[3]*e+a[7]*n+a[11]*s+a[15]*r,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,s,r;const l=t.elements,c=l[0],h=l[4],u=l[8],d=l[1],f=l[5],g=l[9],_=l[2],m=l[6],p=l[10];if(Math.abs(h-d)<.01&&Math.abs(u-_)<.01&&Math.abs(g-m)<.01){if(Math.abs(h+d)<.1&&Math.abs(u+_)<.1&&Math.abs(g+m)<.1&&Math.abs(c+f+p-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(c+1)/2,S=(f+1)/2,L=(p+1)/2,T=(h+d)/4,E=(u+_)/4,P=(g+m)/4;return x>S&&x>L?x<.01?(n=0,s=.707106781,r=.707106781):(n=Math.sqrt(x),s=T/n,r=E/n):S>L?S<.01?(n=.707106781,s=0,r=.707106781):(s=Math.sqrt(S),n=T/s,r=P/s):L<.01?(n=.707106781,s=.707106781,r=0):(r=Math.sqrt(L),n=E/r,s=P/r),this.set(n,s,r,e),this}let y=Math.sqrt((m-g)*(m-g)+(u-_)*(u-_)+(d-h)*(d-h));return Math.abs(y)<.001&&(y=1),this.x=(m-g)/y,this.y=(u-_)/y,this.z=(d-h)/y,this.w=Math.acos((c+f+p-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class jm extends bs{constructor(t=1,e=1,n={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new me(0,0,t,e),this.scissorTest=!1,this.viewport=new me(0,0,t,e);const s={width:t,height:e,depth:1};n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Wn,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},n);const r=new en(s,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace);r.flipY=!1,r.generateMipmaps=n.generateMipmaps,r.internalFormat=n.internalFormat,this.textures=[];const a=n.count;for(let o=0;o<a;o++)this.textures[o]=r.clone(),this.textures[o].isRenderTargetTexture=!0;this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this.depthTexture=n.depthTexture,this.samples=n.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}setSize(t,e,n=1){if(this.width!==t||this.height!==e||this.depth!==n){this.width=t,this.height=e,this.depth=n;for(let s=0,r=this.textures.length;s<r;s++)this.textures[s].image.width=t,this.textures[s].image.height=e,this.textures[s].image.depth=n;this.dispose()}this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let n=0,s=t.textures.length;n<s;n++)this.textures[n]=t.textures[n].clone(),this.textures[n].isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new uf(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Yn extends jm{constructor(t=1,e=1,n={}){super(t,e,n),this.isWebGLRenderTarget=!0}}class df extends en{constructor(t=null,e=1,n=1,s=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:n,depth:s},this.magFilter=tn,this.minFilter=tn,this.wrapR=ms,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class qm extends en{constructor(t=null,e=1,n=1,s=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:n,depth:s},this.magFilter=tn,this.minFilter=tn,this.wrapR=ms,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class ns{constructor(t=0,e=0,n=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=s}static slerpFlat(t,e,n,s,r,a,o){let l=n[s+0],c=n[s+1],h=n[s+2],u=n[s+3];const d=r[a+0],f=r[a+1],g=r[a+2],_=r[a+3];if(o===0){t[e+0]=l,t[e+1]=c,t[e+2]=h,t[e+3]=u;return}if(o===1){t[e+0]=d,t[e+1]=f,t[e+2]=g,t[e+3]=_;return}if(u!==_||l!==d||c!==f||h!==g){let m=1-o;const p=l*d+c*f+h*g+u*_,y=p>=0?1:-1,x=1-p*p;if(x>Number.EPSILON){const L=Math.sqrt(x),T=Math.atan2(L,p*y);m=Math.sin(m*T)/L,o=Math.sin(o*T)/L}const S=o*y;if(l=l*m+d*S,c=c*m+f*S,h=h*m+g*S,u=u*m+_*S,m===1-o){const L=1/Math.sqrt(l*l+c*c+h*h+u*u);l*=L,c*=L,h*=L,u*=L}}t[e]=l,t[e+1]=c,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,s,r,a){const o=n[s],l=n[s+1],c=n[s+2],h=n[s+3],u=r[a],d=r[a+1],f=r[a+2],g=r[a+3];return t[e]=o*g+h*u+l*f-c*d,t[e+1]=l*g+h*d+c*u-o*f,t[e+2]=c*g+h*f+o*d-l*u,t[e+3]=h*g-o*u-l*d-c*f,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,s){return this._x=t,this._y=e,this._z=n,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const n=t._x,s=t._y,r=t._z,a=t._order,o=Math.cos,l=Math.sin,c=o(n/2),h=o(s/2),u=o(r/2),d=l(n/2),f=l(s/2),g=l(r/2);switch(a){case"XYZ":this._x=d*h*u+c*f*g,this._y=c*f*u-d*h*g,this._z=c*h*g+d*f*u,this._w=c*h*u-d*f*g;break;case"YXZ":this._x=d*h*u+c*f*g,this._y=c*f*u-d*h*g,this._z=c*h*g-d*f*u,this._w=c*h*u+d*f*g;break;case"ZXY":this._x=d*h*u-c*f*g,this._y=c*f*u+d*h*g,this._z=c*h*g+d*f*u,this._w=c*h*u-d*f*g;break;case"ZYX":this._x=d*h*u-c*f*g,this._y=c*f*u+d*h*g,this._z=c*h*g-d*f*u,this._w=c*h*u+d*f*g;break;case"YZX":this._x=d*h*u+c*f*g,this._y=c*f*u+d*h*g,this._z=c*h*g-d*f*u,this._w=c*h*u-d*f*g;break;case"XZY":this._x=d*h*u-c*f*g,this._y=c*f*u-d*h*g,this._z=c*h*g+d*f*u,this._w=c*h*u+d*f*g;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,s=Math.sin(n);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],s=e[4],r=e[8],a=e[1],o=e[5],l=e[9],c=e[2],h=e[6],u=e[10],d=n+o+u;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(h-l)*f,this._y=(r-c)*f,this._z=(a-s)*f}else if(n>o&&n>u){const f=2*Math.sqrt(1+n-o-u);this._w=(h-l)/f,this._x=.25*f,this._y=(s+a)/f,this._z=(r+c)/f}else if(o>u){const f=2*Math.sqrt(1+o-n-u);this._w=(r-c)/f,this._x=(s+a)/f,this._y=.25*f,this._z=(l+h)/f}else{const f=2*Math.sqrt(1+u-n-o);this._w=(a-s)/f,this._x=(r+c)/f,this._y=(l+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<Number.EPSILON?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Ue(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(n===0)return this;const s=Math.min(1,e/n);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const n=t._x,s=t._y,r=t._z,a=t._w,o=e._x,l=e._y,c=e._z,h=e._w;return this._x=n*h+a*o+s*c-r*l,this._y=s*h+a*l+r*o-n*c,this._z=r*h+a*c+n*l-s*o,this._w=a*h-n*o-s*l-r*c,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const n=this._x,s=this._y,r=this._z,a=this._w;let o=a*t._w+n*t._x+s*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=a,this._x=n,this._y=s,this._z=r,this;const l=1-o*o;if(l<=Number.EPSILON){const f=1-e;return this._w=f*a+e*this._w,this._x=f*n+e*this._x,this._y=f*s+e*this._y,this._z=f*r+e*this._z,this.normalize(),this}const c=Math.sqrt(l),h=Math.atan2(c,o),u=Math.sin((1-e)*h)/c,d=Math.sin(e*h)/c;return this._w=a*u+this._w*d,this._x=n*u+this._x*d,this._y=s*u+this._y*d,this._z=r*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),s=Math.sqrt(1-n),r=Math.sqrt(n);return this.set(s*Math.sin(t),s*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class R{constructor(t=0,e=0,n=0){R.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return n===void 0&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(eu.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(eu.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*s,this.y=r[1]*e+r[4]*n+r[7]*s,this.z=r[2]*e+r[5]*n+r[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,s=this.z,r=t.elements,a=1/(r[3]*e+r[7]*n+r[11]*s+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*s+r[12])*a,this.y=(r[1]*e+r[5]*n+r[9]*s+r[13])*a,this.z=(r[2]*e+r[6]*n+r[10]*s+r[14])*a,this}applyQuaternion(t){const e=this.x,n=this.y,s=this.z,r=t.x,a=t.y,o=t.z,l=t.w,c=2*(a*s-o*n),h=2*(o*e-r*s),u=2*(r*n-a*e);return this.x=e+l*c+a*u-o*h,this.y=n+l*h+o*c-r*u,this.z=s+l*u+r*h-a*c,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,n=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*s,this.y=r[1]*e+r[5]*n+r[9]*s,this.z=r[2]*e+r[6]*n+r[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,s=t.y,r=t.z,a=e.x,o=e.y,l=e.z;return this.x=s*l-r*o,this.y=r*a-n*l,this.z=n*o-s*a,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return jo.copy(this).projectOnVector(t),this.sub(jo)}reflect(t){return this.sub(jo.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(Ue(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,s=this.z-t.z;return e*e+n*n+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){const s=Math.sin(e)*t;return this.x=s*Math.sin(n),this.y=Math.cos(e)*t,this.z=s*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const jo=new R,eu=new ns;class Qr{constructor(t=new R(1/0,1/0,1/0),e=new R(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e+=3)this.expandByPoint(zn.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(zn.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const n=zn.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(n),this.max.copy(t).add(n),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const n=t.geometry;if(n!==void 0){const r=n.getAttribute("position");if(e===!0&&r!==void 0&&t.isInstancedMesh!==!0)for(let a=0,o=r.count;a<o;a++)t.isMesh===!0?t.getVertexPosition(a,zn):zn.fromBufferAttribute(r,a),zn.applyMatrix4(t.matrixWorld),this.expandByPoint(zn);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),aa.copy(t.boundingBox)):(n.boundingBox===null&&n.computeBoundingBox(),aa.copy(n.boundingBox)),aa.applyMatrix4(t.matrixWorld),this.union(aa)}const s=t.children;for(let r=0,a=s.length;r<a;r++)this.expandByObject(s[r],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,zn),zn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Mr),oa.subVectors(this.max,Mr),Ps.subVectors(t.a,Mr),Ls.subVectors(t.b,Mr),Ds.subVectors(t.c,Mr),Ui.subVectors(Ls,Ps),Oi.subVectors(Ds,Ls),rs.subVectors(Ps,Ds);let e=[0,-Ui.z,Ui.y,0,-Oi.z,Oi.y,0,-rs.z,rs.y,Ui.z,0,-Ui.x,Oi.z,0,-Oi.x,rs.z,0,-rs.x,-Ui.y,Ui.x,0,-Oi.y,Oi.x,0,-rs.y,rs.x,0];return!qo(e,Ps,Ls,Ds,oa)||(e=[1,0,0,0,1,0,0,0,1],!qo(e,Ps,Ls,Ds,oa))?!1:(la.crossVectors(Ui,Oi),e=[la.x,la.y,la.z],qo(e,Ps,Ls,Ds,oa))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,zn).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(zn).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(mi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),mi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),mi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),mi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),mi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),mi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),mi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),mi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(mi),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const mi=[new R,new R,new R,new R,new R,new R,new R,new R],zn=new R,aa=new Qr,Ps=new R,Ls=new R,Ds=new R,Ui=new R,Oi=new R,rs=new R,Mr=new R,oa=new R,la=new R,as=new R;function qo(i,t,e,n,s){for(let r=0,a=i.length-3;r<=a;r+=3){as.fromArray(i,r);const o=s.x*Math.abs(as.x)+s.y*Math.abs(as.y)+s.z*Math.abs(as.z),l=t.dot(as),c=e.dot(as),h=n.dot(as);if(Math.max(-Math.max(l,c,h),Math.min(l,c,h))>o)return!1}return!0}const Ym=new Qr,br=new R,Yo=new R;class sh{constructor(t=new R,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const n=this.center;e!==void 0?n.copy(e):Ym.setFromPoints(t).getCenter(n);let s=0;for(let r=0,a=t.length;r<a;r++)s=Math.max(s,n.distanceToSquared(t[r]));return this.radius=Math.sqrt(s),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const n=this.center.distanceToSquared(t);return e.copy(t),n>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;br.subVectors(t,this.center);const e=br.lengthSq();if(e>this.radius*this.radius){const n=Math.sqrt(e),s=(n-this.radius)*.5;this.center.addScaledVector(br,s/n),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Yo.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(br.copy(t.center).add(Yo)),this.expandByPoint(br.copy(t.center).sub(Yo))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}const gi=new R,Ko=new R,ca=new R,Fi=new R,Zo=new R,ha=new R,Jo=new R;class rh{constructor(t=new R,e=new R(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,gi)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=gi.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(gi.copy(this.origin).addScaledVector(this.direction,e),gi.distanceToSquared(t))}distanceSqToSegment(t,e,n,s){Ko.copy(t).add(e).multiplyScalar(.5),ca.copy(e).sub(t).normalize(),Fi.copy(this.origin).sub(Ko);const r=t.distanceTo(e)*.5,a=-this.direction.dot(ca),o=Fi.dot(this.direction),l=-Fi.dot(ca),c=Fi.lengthSq(),h=Math.abs(1-a*a);let u,d,f,g;if(h>0)if(u=a*l-o,d=a*o-l,g=r*h,u>=0)if(d>=-g)if(d<=g){const _=1/h;u*=_,d*=_,f=u*(u+a*d+2*o)+d*(a*u+d+2*l)+c}else d=r,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*l)+c;else d=-r,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*l)+c;else d<=-g?(u=Math.max(0,-(-a*r+o)),d=u>0?-r:Math.min(Math.max(-r,-l),r),f=-u*u+d*(d+2*l)+c):d<=g?(u=0,d=Math.min(Math.max(-r,-l),r),f=d*(d+2*l)+c):(u=Math.max(0,-(a*r+o)),d=u>0?r:Math.min(Math.max(-r,-l),r),f=-u*u+d*(d+2*l)+c);else d=a>0?-r:r,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*l)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy(Ko).addScaledVector(ca,d),f}intersectSphere(t,e){gi.subVectors(t.center,this.origin);const n=gi.dot(this.direction),s=gi.dot(gi)-n*n,r=t.radius*t.radius;if(s>r)return null;const a=Math.sqrt(r-s),o=n-a,l=n+a;return l<0?null:o<0?this.at(l,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return n===null?null:this.at(n,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,s,r,a,o,l;const c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,d=this.origin;return c>=0?(n=(t.min.x-d.x)*c,s=(t.max.x-d.x)*c):(n=(t.max.x-d.x)*c,s=(t.min.x-d.x)*c),h>=0?(r=(t.min.y-d.y)*h,a=(t.max.y-d.y)*h):(r=(t.max.y-d.y)*h,a=(t.min.y-d.y)*h),n>a||r>s||((r>n||isNaN(n))&&(n=r),(a<s||isNaN(s))&&(s=a),u>=0?(o=(t.min.z-d.z)*u,l=(t.max.z-d.z)*u):(o=(t.max.z-d.z)*u,l=(t.min.z-d.z)*u),n>l||o>s)||((o>n||n!==n)&&(n=o),(l<s||s!==s)&&(s=l),s<0)?null:this.at(n>=0?n:s,e)}intersectsBox(t){return this.intersectBox(t,gi)!==null}intersectTriangle(t,e,n,s,r){Zo.subVectors(e,t),ha.subVectors(n,t),Jo.crossVectors(Zo,ha);let a=this.direction.dot(Jo),o;if(a>0){if(s)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Fi.subVectors(this.origin,t);const l=o*this.direction.dot(ha.crossVectors(Fi,ha));if(l<0)return null;const c=o*this.direction.dot(Zo.cross(Fi));if(c<0||l+c>a)return null;const h=-o*Fi.dot(Jo);return h<0?null:this.at(h/a,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class fe{constructor(t,e,n,s,r,a,o,l,c,h,u,d,f,g,_,m){fe.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,n,s,r,a,o,l,c,h,u,d,f,g,_,m)}set(t,e,n,s,r,a,o,l,c,h,u,d,f,g,_,m){const p=this.elements;return p[0]=t,p[4]=e,p[8]=n,p[12]=s,p[1]=r,p[5]=a,p[9]=o,p[13]=l,p[2]=c,p[6]=h,p[10]=u,p[14]=d,p[3]=f,p[7]=g,p[11]=_,p[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new fe().fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,n=t.elements,s=1/Is.setFromMatrixColumn(t,0).length(),r=1/Is.setFromMatrixColumn(t,1).length(),a=1/Is.setFromMatrixColumn(t,2).length();return e[0]=n[0]*s,e[1]=n[1]*s,e[2]=n[2]*s,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*a,e[9]=n[9]*a,e[10]=n[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,s=t.y,r=t.z,a=Math.cos(n),o=Math.sin(n),l=Math.cos(s),c=Math.sin(s),h=Math.cos(r),u=Math.sin(r);if(t.order==="XYZ"){const d=a*h,f=a*u,g=o*h,_=o*u;e[0]=l*h,e[4]=-l*u,e[8]=c,e[1]=f+g*c,e[5]=d-_*c,e[9]=-o*l,e[2]=_-d*c,e[6]=g+f*c,e[10]=a*l}else if(t.order==="YXZ"){const d=l*h,f=l*u,g=c*h,_=c*u;e[0]=d+_*o,e[4]=g*o-f,e[8]=a*c,e[1]=a*u,e[5]=a*h,e[9]=-o,e[2]=f*o-g,e[6]=_+d*o,e[10]=a*l}else if(t.order==="ZXY"){const d=l*h,f=l*u,g=c*h,_=c*u;e[0]=d-_*o,e[4]=-a*u,e[8]=g+f*o,e[1]=f+g*o,e[5]=a*h,e[9]=_-d*o,e[2]=-a*c,e[6]=o,e[10]=a*l}else if(t.order==="ZYX"){const d=a*h,f=a*u,g=o*h,_=o*u;e[0]=l*h,e[4]=g*c-f,e[8]=d*c+_,e[1]=l*u,e[5]=_*c+d,e[9]=f*c-g,e[2]=-c,e[6]=o*l,e[10]=a*l}else if(t.order==="YZX"){const d=a*l,f=a*c,g=o*l,_=o*c;e[0]=l*h,e[4]=_-d*u,e[8]=g*u+f,e[1]=u,e[5]=a*h,e[9]=-o*h,e[2]=-c*h,e[6]=f*u+g,e[10]=d-_*u}else if(t.order==="XZY"){const d=a*l,f=a*c,g=o*l,_=o*c;e[0]=l*h,e[4]=-u,e[8]=c*h,e[1]=d*u+_,e[5]=a*h,e[9]=f*u-g,e[2]=g*u-f,e[6]=o*h,e[10]=_*u+d}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Km,t,Zm)}lookAt(t,e,n){const s=this.elements;return yn.subVectors(t,e),yn.lengthSq()===0&&(yn.z=1),yn.normalize(),zi.crossVectors(n,yn),zi.lengthSq()===0&&(Math.abs(n.z)===1?yn.x+=1e-4:yn.z+=1e-4,yn.normalize(),zi.crossVectors(n,yn)),zi.normalize(),ua.crossVectors(yn,zi),s[0]=zi.x,s[4]=ua.x,s[8]=yn.x,s[1]=zi.y,s[5]=ua.y,s[9]=yn.y,s[2]=zi.z,s[6]=ua.z,s[10]=yn.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,s=e.elements,r=this.elements,a=n[0],o=n[4],l=n[8],c=n[12],h=n[1],u=n[5],d=n[9],f=n[13],g=n[2],_=n[6],m=n[10],p=n[14],y=n[3],x=n[7],S=n[11],L=n[15],T=s[0],E=s[4],P=s[8],U=s[12],v=s[1],b=s[5],I=s[9],O=s[13],$=s[2],Y=s[6],z=s[10],K=s[14],V=s[3],at=s[7],ct=s[11],_t=s[15];return r[0]=a*T+o*v+l*$+c*V,r[4]=a*E+o*b+l*Y+c*at,r[8]=a*P+o*I+l*z+c*ct,r[12]=a*U+o*O+l*K+c*_t,r[1]=h*T+u*v+d*$+f*V,r[5]=h*E+u*b+d*Y+f*at,r[9]=h*P+u*I+d*z+f*ct,r[13]=h*U+u*O+d*K+f*_t,r[2]=g*T+_*v+m*$+p*V,r[6]=g*E+_*b+m*Y+p*at,r[10]=g*P+_*I+m*z+p*ct,r[14]=g*U+_*O+m*K+p*_t,r[3]=y*T+x*v+S*$+L*V,r[7]=y*E+x*b+S*Y+L*at,r[11]=y*P+x*I+S*z+L*ct,r[15]=y*U+x*O+S*K+L*_t,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[4],s=t[8],r=t[12],a=t[1],o=t[5],l=t[9],c=t[13],h=t[2],u=t[6],d=t[10],f=t[14],g=t[3],_=t[7],m=t[11],p=t[15];return g*(+r*l*u-s*c*u-r*o*d+n*c*d+s*o*f-n*l*f)+_*(+e*l*f-e*c*d+r*a*d-s*a*f+s*c*h-r*l*h)+m*(+e*c*u-e*o*f-r*a*u+n*a*f+r*o*h-n*c*h)+p*(-s*o*h-e*l*u+e*o*d+s*a*u-n*a*d+n*l*h)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=t[9],d=t[10],f=t[11],g=t[12],_=t[13],m=t[14],p=t[15],y=u*m*c-_*d*c+_*l*f-o*m*f-u*l*p+o*d*p,x=g*d*c-h*m*c-g*l*f+a*m*f+h*l*p-a*d*p,S=h*_*c-g*u*c+g*o*f-a*_*f-h*o*p+a*u*p,L=g*u*l-h*_*l-g*o*d+a*_*d+h*o*m-a*u*m,T=e*y+n*x+s*S+r*L;if(T===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/T;return t[0]=y*E,t[1]=(_*d*r-u*m*r-_*s*f+n*m*f+u*s*p-n*d*p)*E,t[2]=(o*m*r-_*l*r+_*s*c-n*m*c-o*s*p+n*l*p)*E,t[3]=(u*l*r-o*d*r-u*s*c+n*d*c+o*s*f-n*l*f)*E,t[4]=x*E,t[5]=(h*m*r-g*d*r+g*s*f-e*m*f-h*s*p+e*d*p)*E,t[6]=(g*l*r-a*m*r-g*s*c+e*m*c+a*s*p-e*l*p)*E,t[7]=(a*d*r-h*l*r+h*s*c-e*d*c-a*s*f+e*l*f)*E,t[8]=S*E,t[9]=(g*u*r-h*_*r-g*n*f+e*_*f+h*n*p-e*u*p)*E,t[10]=(a*_*r-g*o*r+g*n*c-e*_*c-a*n*p+e*o*p)*E,t[11]=(h*o*r-a*u*r-h*n*c+e*u*c+a*n*f-e*o*f)*E,t[12]=L*E,t[13]=(h*_*s-g*u*s+g*n*d-e*_*d-h*n*m+e*u*m)*E,t[14]=(g*o*s-a*_*s-g*n*l+e*_*l+a*n*m-e*o*m)*E,t[15]=(a*u*s-h*o*s+h*n*l-e*u*l-a*n*d+e*o*d)*E,this}scale(t){const e=this.elements,n=t.x,s=t.y,r=t.z;return e[0]*=n,e[4]*=s,e[8]*=r,e[1]*=n,e[5]*=s,e[9]*=r,e[2]*=n,e[6]*=s,e[10]*=r,e[3]*=n,e[7]*=s,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,s))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),s=Math.sin(e),r=1-n,a=t.x,o=t.y,l=t.z,c=r*a,h=r*o;return this.set(c*a+n,c*o-s*l,c*l+s*o,0,c*o+s*l,h*o+n,h*l-s*a,0,c*l-s*o,h*l+s*a,r*l*l+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,s,r,a){return this.set(1,n,r,0,t,1,a,0,e,s,1,0,0,0,0,1),this}compose(t,e,n){const s=this.elements,r=e._x,a=e._y,o=e._z,l=e._w,c=r+r,h=a+a,u=o+o,d=r*c,f=r*h,g=r*u,_=a*h,m=a*u,p=o*u,y=l*c,x=l*h,S=l*u,L=n.x,T=n.y,E=n.z;return s[0]=(1-(_+p))*L,s[1]=(f+S)*L,s[2]=(g-x)*L,s[3]=0,s[4]=(f-S)*T,s[5]=(1-(d+p))*T,s[6]=(m+y)*T,s[7]=0,s[8]=(g+x)*E,s[9]=(m-y)*E,s[10]=(1-(d+_))*E,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,n){const s=this.elements;let r=Is.set(s[0],s[1],s[2]).length();const a=Is.set(s[4],s[5],s[6]).length(),o=Is.set(s[8],s[9],s[10]).length();this.determinant()<0&&(r=-r),t.x=s[12],t.y=s[13],t.z=s[14],Bn.copy(this);const c=1/r,h=1/a,u=1/o;return Bn.elements[0]*=c,Bn.elements[1]*=c,Bn.elements[2]*=c,Bn.elements[4]*=h,Bn.elements[5]*=h,Bn.elements[6]*=h,Bn.elements[8]*=u,Bn.elements[9]*=u,Bn.elements[10]*=u,e.setFromRotationMatrix(Bn),n.x=r,n.y=a,n.z=o,this}makePerspective(t,e,n,s,r,a,o=Ei){const l=this.elements,c=2*r/(e-t),h=2*r/(n-s),u=(e+t)/(e-t),d=(n+s)/(n-s);let f,g;if(o===Ei)f=-(a+r)/(a-r),g=-2*a*r/(a-r);else if(o===fo)f=-a/(a-r),g=-a*r/(a-r);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return l[0]=c,l[4]=0,l[8]=u,l[12]=0,l[1]=0,l[5]=h,l[9]=d,l[13]=0,l[2]=0,l[6]=0,l[10]=f,l[14]=g,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,n,s,r,a,o=Ei){const l=this.elements,c=1/(e-t),h=1/(n-s),u=1/(a-r),d=(e+t)*c,f=(n+s)*h;let g,_;if(o===Ei)g=(a+r)*u,_=-2*u;else if(o===fo)g=r*u,_=-1*u;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return l[0]=2*c,l[4]=0,l[8]=0,l[12]=-d,l[1]=0,l[5]=2*h,l[9]=0,l[13]=-f,l[2]=0,l[6]=0,l[10]=_,l[14]=-g,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let s=0;s<16;s++)if(e[s]!==n[s])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const Is=new R,Bn=new fe,Km=new R(0,0,0),Zm=new R(1,1,1),zi=new R,ua=new R,yn=new R,nu=new fe,iu=new ns;class ui{constructor(t=0,e=0,n=0,s=ui.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,s=this._order){return this._x=t,this._y=e,this._z=n,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){const s=t.elements,r=s[0],a=s[4],o=s[8],l=s[1],c=s[5],h=s[9],u=s[2],d=s[6],f=s[10];switch(e){case"XYZ":this._y=Math.asin(Ue(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-a,r)):(this._x=Math.atan2(d,c),this._z=0);break;case"YXZ":this._x=Math.asin(-Ue(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(Ue(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,c)):(this._y=0,this._z=Math.atan2(l,r));break;case"ZYX":this._y=Math.asin(-Ue(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(l,r)):(this._x=0,this._z=Math.atan2(-a,c));break;case"YZX":this._z=Math.asin(Ue(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(o,f));break;case"XZY":this._z=Math.asin(-Ue(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-h,f),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,n===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return nu.makeRotationFromQuaternion(t),this.setFromRotationMatrix(nu,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return iu.setFromEuler(this),this.setFromQuaternion(iu,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}ui.DEFAULT_ORDER="XYZ";class ah{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let Jm=0;const su=new R,ks=new ns,vi=new fe,da=new R,Sr=new R,Qm=new R,t0=new ns,ru=new R(1,0,0),au=new R(0,1,0),ou=new R(0,0,1),lu={type:"added"},e0={type:"removed"},Ns={type:"childadded",child:null},Qo={type:"childremoved",child:null};class Ye extends bs{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Jm++}),this.uuid=vr(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ye.DEFAULT_UP.clone();const t=new R,e=new ui,n=new ns,s=new R(1,1,1);function r(){n.setFromEuler(e,!1)}function a(){e.setFromQuaternion(n,void 0,!1)}e._onChange(r),n._onChange(a),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new fe},normalMatrix:{value:new Xt}}),this.matrix=new fe,this.matrixWorld=new fe,this.matrixAutoUpdate=Ye.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ye.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new ah,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return ks.setFromAxisAngle(t,e),this.quaternion.multiply(ks),this}rotateOnWorldAxis(t,e){return ks.setFromAxisAngle(t,e),this.quaternion.premultiply(ks),this}rotateX(t){return this.rotateOnAxis(ru,t)}rotateY(t){return this.rotateOnAxis(au,t)}rotateZ(t){return this.rotateOnAxis(ou,t)}translateOnAxis(t,e){return su.copy(t).applyQuaternion(this.quaternion),this.position.add(su.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(ru,t)}translateY(t){return this.translateOnAxis(au,t)}translateZ(t){return this.translateOnAxis(ou,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(vi.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?da.copy(t):da.set(t,e,n);const s=this.parent;this.updateWorldMatrix(!0,!1),Sr.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?vi.lookAt(Sr,da,this.up):vi.lookAt(da,Sr,this.up),this.quaternion.setFromRotationMatrix(vi),s&&(vi.extractRotation(s.matrixWorld),ks.setFromRotationMatrix(vi),this.quaternion.premultiply(ks.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(lu),Ns.child=t,this.dispatchEvent(Ns),Ns.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let n=0;n<arguments.length;n++)this.remove(arguments[n]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(e0),Qo.child=t,this.dispatchEvent(Qo),Qo.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),vi.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),vi.multiply(t.parent.matrixWorld)),t.applyMatrix4(vi),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(lu),Ns.child=t,this.dispatchEvent(Ns),Ns.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let n=0,s=this.children.length;n<s;n++){const a=this.children[n].getObjectByProperty(t,e);if(a!==void 0)return a}}getObjectsByProperty(t,e,n=[]){this[t]===e&&n.push(this);const s=this.children;for(let r=0,a=s.length;r<a;r++)s[r].getObjectsByProperty(t,e,n);return n}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Sr,t,Qm),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Sr,t0,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let n=0,s=e.length;n<s;n++)e[n].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let n=0,s=e.length;n<s;n++)e[n].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let n=0,s=e.length;n<s;n++)e[n].updateMatrixWorld(t)}updateWorldMatrix(t,e){const n=this.parent;if(t===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const s=this.children;for(let r=0,a=s.length;r<a;r++)s[r].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",n={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.castShadow===!0&&(s.castShadow=!0),this.receiveShadow===!0&&(s.receiveShadow=!0),this.visible===!1&&(s.visible=!1),this.frustumCulled===!1&&(s.frustumCulled=!1),this.renderOrder!==0&&(s.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.visibility=this._visibility,s.active=this._active,s.bounds=this._bounds.map(o=>({boxInitialized:o.boxInitialized,boxMin:o.box.min.toArray(),boxMax:o.box.max.toArray(),sphereInitialized:o.sphereInitialized,sphereRadius:o.sphere.radius,sphereCenter:o.sphere.center.toArray()})),s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.geometryCount=this._geometryCount,s.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere={center:s.boundingSphere.center.toArray(),radius:s.boundingSphere.radius}),this.boundingBox!==null&&(s.boundingBox={min:s.boundingBox.min.toArray(),max:s.boundingBox.max.toArray()}));function r(o,l){return o[l.uuid]===void 0&&(o[l.uuid]=l.toJSON(t)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=r(t.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const l=o.shapes;if(Array.isArray(l))for(let c=0,h=l.length;c<h;c++){const u=l[c];r(t.shapes,u)}else r(t.shapes,l)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(r(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let l=0,c=this.material.length;l<c;l++)o.push(r(t.materials,this.material[l]));s.material=o}else s.material=r(t.materials,this.material);if(this.children.length>0){s.children=[];for(let o=0;o<this.children.length;o++)s.children.push(this.children[o].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let o=0;o<this.animations.length;o++){const l=this.animations[o];s.animations.push(r(t.animations,l))}}if(e){const o=a(t.geometries),l=a(t.materials),c=a(t.textures),h=a(t.images),u=a(t.shapes),d=a(t.skeletons),f=a(t.animations),g=a(t.nodes);o.length>0&&(n.geometries=o),l.length>0&&(n.materials=l),c.length>0&&(n.textures=c),h.length>0&&(n.images=h),u.length>0&&(n.shapes=u),d.length>0&&(n.skeletons=d),f.length>0&&(n.animations=f),g.length>0&&(n.nodes=g)}return n.object=s,n;function a(o){const l=[];for(const c in o){const h=o[c];delete h.metadata,l.push(h)}return l}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let n=0;n<t.children.length;n++){const s=t.children[n];this.add(s.clone())}return this}}Ye.DEFAULT_UP=new R(0,1,0);Ye.DEFAULT_MATRIX_AUTO_UPDATE=!0;Ye.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const Hn=new R,_i=new R,tl=new R,xi=new R,Us=new R,Os=new R,cu=new R,el=new R,nl=new R,il=new R,sl=new me,rl=new me,al=new me;class Xn{constructor(t=new R,e=new R,n=new R){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,s){s.subVectors(n,e),Hn.subVectors(t,e),s.cross(Hn);const r=s.lengthSq();return r>0?s.multiplyScalar(1/Math.sqrt(r)):s.set(0,0,0)}static getBarycoord(t,e,n,s,r){Hn.subVectors(s,e),_i.subVectors(n,e),tl.subVectors(t,e);const a=Hn.dot(Hn),o=Hn.dot(_i),l=Hn.dot(tl),c=_i.dot(_i),h=_i.dot(tl),u=a*c-o*o;if(u===0)return r.set(0,0,0),null;const d=1/u,f=(c*l-o*h)*d,g=(a*h-o*l)*d;return r.set(1-f-g,g,f)}static containsPoint(t,e,n,s){return this.getBarycoord(t,e,n,s,xi)===null?!1:xi.x>=0&&xi.y>=0&&xi.x+xi.y<=1}static getInterpolation(t,e,n,s,r,a,o,l){return this.getBarycoord(t,e,n,s,xi)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(r,xi.x),l.addScaledVector(a,xi.y),l.addScaledVector(o,xi.z),l)}static getInterpolatedAttribute(t,e,n,s,r,a){return sl.setScalar(0),rl.setScalar(0),al.setScalar(0),sl.fromBufferAttribute(t,e),rl.fromBufferAttribute(t,n),al.fromBufferAttribute(t,s),a.setScalar(0),a.addScaledVector(sl,r.x),a.addScaledVector(rl,r.y),a.addScaledVector(al,r.z),a}static isFrontFacing(t,e,n,s){return Hn.subVectors(n,e),_i.subVectors(t,e),Hn.cross(_i).dot(s)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,s){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,n,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,s),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Hn.subVectors(this.c,this.b),_i.subVectors(this.a,this.b),Hn.cross(_i).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Xn.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Xn.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,s,r){return Xn.getInterpolation(t,this.a,this.b,this.c,e,n,s,r)}containsPoint(t){return Xn.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Xn.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,s=this.b,r=this.c;let a,o;Us.subVectors(s,n),Os.subVectors(r,n),el.subVectors(t,n);const l=Us.dot(el),c=Os.dot(el);if(l<=0&&c<=0)return e.copy(n);nl.subVectors(t,s);const h=Us.dot(nl),u=Os.dot(nl);if(h>=0&&u<=h)return e.copy(s);const d=l*u-h*c;if(d<=0&&l>=0&&h<=0)return a=l/(l-h),e.copy(n).addScaledVector(Us,a);il.subVectors(t,r);const f=Us.dot(il),g=Os.dot(il);if(g>=0&&f<=g)return e.copy(r);const _=f*c-l*g;if(_<=0&&c>=0&&g<=0)return o=c/(c-g),e.copy(n).addScaledVector(Os,o);const m=h*g-f*u;if(m<=0&&u-h>=0&&f-g>=0)return cu.subVectors(r,s),o=(u-h)/(u-h+(f-g)),e.copy(s).addScaledVector(cu,o);const p=1/(m+_+d);return a=_*p,o=d*p,e.copy(n).addScaledVector(Us,a).addScaledVector(Os,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const ff={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Bi={h:0,s:0,l:0},fa={h:0,s:0,l:0};function ol(i,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?i+(t-i)*6*e:e<1/2?t:e<2/3?i+(t-i)*6*(2/3-e):i}class Zt{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(e===void 0&&n===void 0){const s=t;s&&s.isColor?this.copy(s):typeof s=="number"?this.setHex(s):typeof s=="string"&&this.setStyle(s)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=je){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,oe.toWorkingColorSpace(this,e),this}setRGB(t,e,n,s=oe.workingColorSpace){return this.r=t,this.g=e,this.b=n,oe.toWorkingColorSpace(this,s),this}setHSL(t,e,n,s=oe.workingColorSpace){if(t=ih(t,1),e=Ue(e,0,1),n=Ue(n,0,1),e===0)this.r=this.g=this.b=n;else{const r=n<=.5?n*(1+e):n+e-n*e,a=2*n-r;this.r=ol(a,r,t+1/3),this.g=ol(a,r,t),this.b=ol(a,r,t-1/3)}return oe.toWorkingColorSpace(this,s),this}setStyle(t,e=je){function n(r){r!==void 0&&parseFloat(r)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let s;if(s=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const a=s[1],o=s[2];switch(a){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(s=/^\#([A-Fa-f\d]+)$/.exec(t)){const r=s[1],a=r.length;if(a===3)return this.setRGB(parseInt(r.charAt(0),16)/15,parseInt(r.charAt(1),16)/15,parseInt(r.charAt(2),16)/15,e);if(a===6)return this.setHex(parseInt(r,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=je){const n=ff[t.toLowerCase()];return n!==void 0?this.setHex(n,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=ar(t.r),this.g=ar(t.g),this.b=ar(t.b),this}copyLinearToSRGB(t){return this.r=Wo(t.r),this.g=Wo(t.g),this.b=Wo(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=je){return oe.fromWorkingColorSpace(Ze.copy(this),t),Math.round(Ue(Ze.r*255,0,255))*65536+Math.round(Ue(Ze.g*255,0,255))*256+Math.round(Ue(Ze.b*255,0,255))}getHexString(t=je){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=oe.workingColorSpace){oe.fromWorkingColorSpace(Ze.copy(this),e);const n=Ze.r,s=Ze.g,r=Ze.b,a=Math.max(n,s,r),o=Math.min(n,s,r);let l,c;const h=(o+a)/2;if(o===a)l=0,c=0;else{const u=a-o;switch(c=h<=.5?u/(a+o):u/(2-a-o),a){case n:l=(s-r)/u+(s<r?6:0);break;case s:l=(r-n)/u+2;break;case r:l=(n-s)/u+4;break}l/=6}return t.h=l,t.s=c,t.l=h,t}getRGB(t,e=oe.workingColorSpace){return oe.fromWorkingColorSpace(Ze.copy(this),e),t.r=Ze.r,t.g=Ze.g,t.b=Ze.b,t}getStyle(t=je){oe.fromWorkingColorSpace(Ze.copy(this),t);const e=Ze.r,n=Ze.g,s=Ze.b;return t!==je?`color(${t} ${e.toFixed(3)} ${n.toFixed(3)} ${s.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(n*255)},${Math.round(s*255)})`}offsetHSL(t,e,n){return this.getHSL(Bi),this.setHSL(Bi.h+t,Bi.s+e,Bi.l+n)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,n){return this.r=t.r+(e.r-t.r)*n,this.g=t.g+(e.g-t.g)*n,this.b=t.b+(e.b-t.b)*n,this}lerpHSL(t,e){this.getHSL(Bi),t.getHSL(fa);const n=Br(Bi.h,fa.h,e),s=Br(Bi.s,fa.s,e),r=Br(Bi.l,fa.l,e);return this.setHSL(n,s,r),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,n=this.g,s=this.b,r=t.elements;return this.r=r[0]*e+r[3]*n+r[6]*s,this.g=r[1]*e+r[4]*n+r[7]*s,this.b=r[2]*e+r[5]*n+r[8]*s,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const Ze=new Zt;Zt.NAMES=ff;let n0=0;class Ii extends bs{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:n0++}),this.uuid=vr(),this.name="",this.type="Material",this.blending=sr,this.side=es,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=jl,this.blendDst=ql,this.blendEquation=$n,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new Zt(0,0,0),this.blendAlpha=0,this.depthFunc=hr,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=qh,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Cs,this.stencilZFail=Cs,this.stencilZPass=Cs,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const n=t[e];if(n===void 0){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const s=this[e];if(s===void 0){console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`);continue}s&&s.isColor?s.set(n):s&&s.isVector3&&n&&n.isVector3?s.copy(n):this[e]=n}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const n={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.dispersion!==void 0&&(n.dispersion=this.dispersion),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapRotation!==void 0&&(n.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==sr&&(n.blending=this.blending),this.side!==es&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==jl&&(n.blendSrc=this.blendSrc),this.blendDst!==ql&&(n.blendDst=this.blendDst),this.blendEquation!==$n&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==hr&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==qh&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Cs&&(n.stencilFail=this.stencilFail),this.stencilZFail!==Cs&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==Cs&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function s(r){const a=[];for(const o in r){const l=r[o];delete l.metadata,a.push(l)}return a}if(e){const r=s(t.textures),a=s(t.images);r.length>0&&(n.textures=r),a.length>0&&(n.images=a)}return n}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let n=null;if(e!==null){const s=e.length;n=new Array(s);for(let r=0;r!==s;++r)n[r]=e[r].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}}class ln extends Ii{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Zt(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new ui,this.combine=Wd,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const De=new R,pa=new rt;class oi{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=n,this.usage=Yh,this.updateRanges=[],this.gpuType=wi,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let s=0,r=this.itemSize;s<r;s++)this.array[t+s]=e.array[n+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,n=this.count;e<n;e++)pa.fromBufferAttribute(this,e),pa.applyMatrix3(t),this.setXY(e,pa.x,pa.y);else if(this.itemSize===3)for(let e=0,n=this.count;e<n;e++)De.fromBufferAttribute(this,e),De.applyMatrix3(t),this.setXYZ(e,De.x,De.y,De.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)De.fromBufferAttribute(this,e),De.applyMatrix4(t),this.setXYZ(e,De.x,De.y,De.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)De.fromBufferAttribute(this,e),De.applyNormalMatrix(t),this.setXYZ(e,De.x,De.y,De.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)De.fromBufferAttribute(this,e),De.transformDirection(t),this.setXYZ(e,De.x,De.y,De.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let n=this.array[t*this.itemSize+e];return this.normalized&&(n=qs(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=nn(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=qs(e,this.array)),e}setX(t,e){return this.normalized&&(e=nn(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=qs(e,this.array)),e}setY(t,e){return this.normalized&&(e=nn(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=qs(e,this.array)),e}setZ(t,e){return this.normalized&&(e=nn(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=qs(e,this.array)),e}setW(t,e){return this.normalized&&(e=nn(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=nn(e,this.array),n=nn(n,this.array)),this.array[t+0]=e,this.array[t+1]=n,this}setXYZ(t,e,n,s){return t*=this.itemSize,this.normalized&&(e=nn(e,this.array),n=nn(n,this.array),s=nn(s,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=s,this}setXYZW(t,e,n,s,r){return t*=this.itemSize,this.normalized&&(e=nn(e,this.array),n=nn(n,this.array),s=nn(s,this.array),r=nn(r,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=s,this.array[t+3]=r,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==Yh&&(t.usage=this.usage),t}}class pf extends oi{constructor(t,e,n){super(new Uint16Array(t),e,n)}}class mf extends oi{constructor(t,e,n){super(new Uint32Array(t),e,n)}}class he extends oi{constructor(t,e,n){super(new Float32Array(t),e,n)}}let i0=0;const Cn=new fe,ll=new Ye,Fs=new R,Mn=new Qr,wr=new Qr,Be=new R;class cn extends bs{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:i0++}),this.uuid=vr(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(hf(t)?mf:pf)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,n=0){this.groups.push({start:t,count:e,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const n=this.attributes.normal;if(n!==void 0){const r=new Xt().getNormalMatrix(t);n.applyNormalMatrix(r),n.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return Cn.makeRotationFromQuaternion(t),this.applyMatrix4(Cn),this}rotateX(t){return Cn.makeRotationX(t),this.applyMatrix4(Cn),this}rotateY(t){return Cn.makeRotationY(t),this.applyMatrix4(Cn),this}rotateZ(t){return Cn.makeRotationZ(t),this.applyMatrix4(Cn),this}translate(t,e,n){return Cn.makeTranslation(t,e,n),this.applyMatrix4(Cn),this}scale(t,e,n){return Cn.makeScale(t,e,n),this.applyMatrix4(Cn),this}lookAt(t){return ll.lookAt(t),ll.updateMatrix(),this.applyMatrix4(ll.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Fs).negate(),this.translate(Fs.x,Fs.y,Fs.z),this}setFromPoints(t){const e=[];for(let n=0,s=t.length;n<s;n++){const r=t[n];e.push(r.x,r.y,r.z||0)}return this.setAttribute("position",new he(e,3)),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Qr);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new R(-1/0,-1/0,-1/0),new R(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let n=0,s=e.length;n<s;n++){const r=e[n];Mn.setFromBufferAttribute(r),this.morphTargetsRelative?(Be.addVectors(this.boundingBox.min,Mn.min),this.boundingBox.expandByPoint(Be),Be.addVectors(this.boundingBox.max,Mn.max),this.boundingBox.expandByPoint(Be)):(this.boundingBox.expandByPoint(Mn.min),this.boundingBox.expandByPoint(Mn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new sh);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(t){const n=this.boundingSphere.center;if(Mn.setFromBufferAttribute(t),e)for(let r=0,a=e.length;r<a;r++){const o=e[r];wr.setFromBufferAttribute(o),this.morphTargetsRelative?(Be.addVectors(Mn.min,wr.min),Mn.expandByPoint(Be),Be.addVectors(Mn.max,wr.max),Mn.expandByPoint(Be)):(Mn.expandByPoint(wr.min),Mn.expandByPoint(wr.max))}Mn.getCenter(n);let s=0;for(let r=0,a=t.count;r<a;r++)Be.fromBufferAttribute(t,r),s=Math.max(s,n.distanceToSquared(Be));if(e)for(let r=0,a=e.length;r<a;r++){const o=e[r],l=this.morphTargetsRelative;for(let c=0,h=o.count;c<h;c++)Be.fromBufferAttribute(o,c),l&&(Fs.fromBufferAttribute(t,c),Be.add(Fs)),s=Math.max(s,n.distanceToSquared(Be))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const n=e.position,s=e.normal,r=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new oi(new Float32Array(4*n.count),4));const a=this.getAttribute("tangent"),o=[],l=[];for(let P=0;P<n.count;P++)o[P]=new R,l[P]=new R;const c=new R,h=new R,u=new R,d=new rt,f=new rt,g=new rt,_=new R,m=new R;function p(P,U,v){c.fromBufferAttribute(n,P),h.fromBufferAttribute(n,U),u.fromBufferAttribute(n,v),d.fromBufferAttribute(r,P),f.fromBufferAttribute(r,U),g.fromBufferAttribute(r,v),h.sub(c),u.sub(c),f.sub(d),g.sub(d);const b=1/(f.x*g.y-g.x*f.y);isFinite(b)&&(_.copy(h).multiplyScalar(g.y).addScaledVector(u,-f.y).multiplyScalar(b),m.copy(u).multiplyScalar(f.x).addScaledVector(h,-g.x).multiplyScalar(b),o[P].add(_),o[U].add(_),o[v].add(_),l[P].add(m),l[U].add(m),l[v].add(m))}let y=this.groups;y.length===0&&(y=[{start:0,count:t.count}]);for(let P=0,U=y.length;P<U;++P){const v=y[P],b=v.start,I=v.count;for(let O=b,$=b+I;O<$;O+=3)p(t.getX(O+0),t.getX(O+1),t.getX(O+2))}const x=new R,S=new R,L=new R,T=new R;function E(P){L.fromBufferAttribute(s,P),T.copy(L);const U=o[P];x.copy(U),x.sub(L.multiplyScalar(L.dot(U))).normalize(),S.crossVectors(T,U);const b=S.dot(l[P])<0?-1:1;a.setXYZW(P,x.x,x.y,x.z,b)}for(let P=0,U=y.length;P<U;++P){const v=y[P],b=v.start,I=v.count;for(let O=b,$=b+I;O<$;O+=3)E(t.getX(O+0)),E(t.getX(O+1)),E(t.getX(O+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let n=this.getAttribute("normal");if(n===void 0)n=new oi(new Float32Array(e.count*3),3),this.setAttribute("normal",n);else for(let d=0,f=n.count;d<f;d++)n.setXYZ(d,0,0,0);const s=new R,r=new R,a=new R,o=new R,l=new R,c=new R,h=new R,u=new R;if(t)for(let d=0,f=t.count;d<f;d+=3){const g=t.getX(d+0),_=t.getX(d+1),m=t.getX(d+2);s.fromBufferAttribute(e,g),r.fromBufferAttribute(e,_),a.fromBufferAttribute(e,m),h.subVectors(a,r),u.subVectors(s,r),h.cross(u),o.fromBufferAttribute(n,g),l.fromBufferAttribute(n,_),c.fromBufferAttribute(n,m),o.add(h),l.add(h),c.add(h),n.setXYZ(g,o.x,o.y,o.z),n.setXYZ(_,l.x,l.y,l.z),n.setXYZ(m,c.x,c.y,c.z)}else for(let d=0,f=e.count;d<f;d+=3)s.fromBufferAttribute(e,d+0),r.fromBufferAttribute(e,d+1),a.fromBufferAttribute(e,d+2),h.subVectors(a,r),u.subVectors(s,r),h.cross(u),n.setXYZ(d+0,h.x,h.y,h.z),n.setXYZ(d+1,h.x,h.y,h.z),n.setXYZ(d+2,h.x,h.y,h.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,n=t.count;e<n;e++)Be.fromBufferAttribute(t,e),Be.normalize(),t.setXYZ(e,Be.x,Be.y,Be.z)}toNonIndexed(){function t(o,l){const c=o.array,h=o.itemSize,u=o.normalized,d=new c.constructor(l.length*h);let f=0,g=0;for(let _=0,m=l.length;_<m;_++){o.isInterleavedBufferAttribute?f=l[_]*o.data.stride+o.offset:f=l[_]*h;for(let p=0;p<h;p++)d[g++]=c[f++]}return new oi(d,h,u)}if(this.index===null)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new cn,n=this.index.array,s=this.attributes;for(const o in s){const l=s[o],c=t(l,n);e.setAttribute(o,c)}const r=this.morphAttributes;for(const o in r){const l=[],c=r[o];for(let h=0,u=c.length;h<u;h++){const d=c[h],f=t(d,n);l.push(f)}e.morphAttributes[o]=l}e.morphTargetsRelative=this.morphTargetsRelative;const a=this.groups;for(let o=0,l=a.length;o<l;o++){const c=a[o];e.addGroup(c.start,c.count,c.materialIndex)}return e}toJSON(){const t={metadata:{version:4.6,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0){const l=this.parameters;for(const c in l)l[c]!==void 0&&(t[c]=l[c]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const n=this.attributes;for(const l in n){const c=n[l];t.data.attributes[l]=c.toJSON(t.data)}const s={};let r=!1;for(const l in this.morphAttributes){const c=this.morphAttributes[l],h=[];for(let u=0,d=c.length;u<d;u++){const f=c[u];h.push(f.toJSON(t.data))}h.length>0&&(s[l]=h,r=!0)}r&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const a=this.groups;a.length>0&&(t.data.groups=JSON.parse(JSON.stringify(a)));const o=this.boundingSphere;return o!==null&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;n!==null&&this.setIndex(n.clone(e));const s=t.attributes;for(const c in s){const h=s[c];this.setAttribute(c,h.clone(e))}const r=t.morphAttributes;for(const c in r){const h=[],u=r[c];for(let d=0,f=u.length;d<f;d++)h.push(u[d].clone(e));this.morphAttributes[c]=h}this.morphTargetsRelative=t.morphTargetsRelative;const a=t.groups;for(let c=0,h=a.length;c<h;c++){const u=a[c];this.addGroup(u.start,u.count,u.materialIndex)}const o=t.boundingBox;o!==null&&(this.boundingBox=o.clone());const l=t.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const hu=new fe,os=new rh,ma=new sh,uu=new R,ga=new R,va=new R,_a=new R,cl=new R,xa=new R,du=new R,ya=new R;class yt extends Ye{constructor(t=new cn,e=new ln){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),t.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),t.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const e=this.geometry.morphAttributes,n=Object.keys(e);if(n.length>0){const s=e[n[0]];if(s!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,a=s.length;r<a;r++){const o=s[r].name||String(r);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=r}}}}getVertexPosition(t,e){const n=this.geometry,s=n.attributes.position,r=n.morphAttributes.position,a=n.morphTargetsRelative;e.fromBufferAttribute(s,t);const o=this.morphTargetInfluences;if(r&&o){xa.set(0,0,0);for(let l=0,c=r.length;l<c;l++){const h=o[l],u=r[l];h!==0&&(cl.fromBufferAttribute(u,t),a?xa.addScaledVector(cl,h):xa.addScaledVector(cl.sub(e),h))}e.add(xa)}return e}raycast(t,e){const n=this.geometry,s=this.material,r=this.matrixWorld;s!==void 0&&(n.boundingSphere===null&&n.computeBoundingSphere(),ma.copy(n.boundingSphere),ma.applyMatrix4(r),os.copy(t.ray).recast(t.near),!(ma.containsPoint(os.origin)===!1&&(os.intersectSphere(ma,uu)===null||os.origin.distanceToSquared(uu)>(t.far-t.near)**2))&&(hu.copy(r).invert(),os.copy(t.ray).applyMatrix4(hu),!(n.boundingBox!==null&&os.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(t,e,os)))}_computeIntersections(t,e,n){let s;const r=this.geometry,a=this.material,o=r.index,l=r.attributes.position,c=r.attributes.uv,h=r.attributes.uv1,u=r.attributes.normal,d=r.groups,f=r.drawRange;if(o!==null)if(Array.isArray(a))for(let g=0,_=d.length;g<_;g++){const m=d[g],p=a[m.materialIndex],y=Math.max(m.start,f.start),x=Math.min(o.count,Math.min(m.start+m.count,f.start+f.count));for(let S=y,L=x;S<L;S+=3){const T=o.getX(S),E=o.getX(S+1),P=o.getX(S+2);s=Ma(this,p,t,n,c,h,u,T,E,P),s&&(s.faceIndex=Math.floor(S/3),s.face.materialIndex=m.materialIndex,e.push(s))}}else{const g=Math.max(0,f.start),_=Math.min(o.count,f.start+f.count);for(let m=g,p=_;m<p;m+=3){const y=o.getX(m),x=o.getX(m+1),S=o.getX(m+2);s=Ma(this,a,t,n,c,h,u,y,x,S),s&&(s.faceIndex=Math.floor(m/3),e.push(s))}}else if(l!==void 0)if(Array.isArray(a))for(let g=0,_=d.length;g<_;g++){const m=d[g],p=a[m.materialIndex],y=Math.max(m.start,f.start),x=Math.min(l.count,Math.min(m.start+m.count,f.start+f.count));for(let S=y,L=x;S<L;S+=3){const T=S,E=S+1,P=S+2;s=Ma(this,p,t,n,c,h,u,T,E,P),s&&(s.faceIndex=Math.floor(S/3),s.face.materialIndex=m.materialIndex,e.push(s))}}else{const g=Math.max(0,f.start),_=Math.min(l.count,f.start+f.count);for(let m=g,p=_;m<p;m+=3){const y=m,x=m+1,S=m+2;s=Ma(this,a,t,n,c,h,u,y,x,S),s&&(s.faceIndex=Math.floor(m/3),e.push(s))}}}}function s0(i,t,e,n,s,r,a,o){let l;if(t.side===on?l=n.intersectTriangle(a,r,s,!0,o):l=n.intersectTriangle(s,r,a,t.side===es,o),l===null)return null;ya.copy(o),ya.applyMatrix4(i.matrixWorld);const c=e.ray.origin.distanceTo(ya);return c<e.near||c>e.far?null:{distance:c,point:ya.clone(),object:i}}function Ma(i,t,e,n,s,r,a,o,l,c){i.getVertexPosition(o,ga),i.getVertexPosition(l,va),i.getVertexPosition(c,_a);const h=s0(i,t,e,n,ga,va,_a,du);if(h){const u=new R;Xn.getBarycoord(du,ga,va,_a,u),s&&(h.uv=Xn.getInterpolatedAttribute(s,o,l,c,u,new rt)),r&&(h.uv1=Xn.getInterpolatedAttribute(r,o,l,c,u,new rt)),a&&(h.normal=Xn.getInterpolatedAttribute(a,o,l,c,u,new R),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const d={a:o,b:l,c,normal:new R,materialIndex:0};Xn.getNormal(ga,va,_a,d.normal),h.face=d,h.barycoord=u}return h}class qe extends cn{constructor(t=1,e=1,n=1,s=1,r=1,a=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:s,heightSegments:r,depthSegments:a};const o=this;s=Math.floor(s),r=Math.floor(r),a=Math.floor(a);const l=[],c=[],h=[],u=[];let d=0,f=0;g("z","y","x",-1,-1,n,e,t,a,r,0),g("z","y","x",1,-1,n,e,-t,a,r,1),g("x","z","y",1,1,t,n,e,s,a,2),g("x","z","y",1,-1,t,n,-e,s,a,3),g("x","y","z",1,-1,t,e,n,s,r,4),g("x","y","z",-1,-1,t,e,-n,s,r,5),this.setIndex(l),this.setAttribute("position",new he(c,3)),this.setAttribute("normal",new he(h,3)),this.setAttribute("uv",new he(u,2));function g(_,m,p,y,x,S,L,T,E,P,U){const v=S/E,b=L/P,I=S/2,O=L/2,$=T/2,Y=E+1,z=P+1;let K=0,V=0;const at=new R;for(let ct=0;ct<z;ct++){const _t=ct*b-O;for(let Gt=0;Gt<Y;Gt++){const Jt=Gt*v-I;at[_]=Jt*y,at[m]=_t*x,at[p]=$,c.push(at.x,at.y,at.z),at[_]=0,at[m]=0,at[p]=T>0?1:-1,h.push(at.x,at.y,at.z),u.push(Gt/E),u.push(1-ct/P),K+=1}}for(let ct=0;ct<P;ct++)for(let _t=0;_t<E;_t++){const Gt=d+_t+Y*ct,Jt=d+_t+Y*(ct+1),X=d+(_t+1)+Y*(ct+1),et=d+(_t+1)+Y*ct;l.push(Gt,Jt,et),l.push(Jt,X,et),V+=6}o.addGroup(f,V,U),f+=V,d+=K}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new qe(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function fr(i){const t={};for(const e in i){t[e]={};for(const n in i[e]){const s=i[e][n];s&&(s.isColor||s.isMatrix3||s.isMatrix4||s.isVector2||s.isVector3||s.isVector4||s.isTexture||s.isQuaternion)?s.isRenderTargetTexture?(console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[e][n]=null):t[e][n]=s.clone():Array.isArray(s)?t[e][n]=s.slice():t[e][n]=s}}return t}function sn(i){const t={};for(let e=0;e<i.length;e++){const n=fr(i[e]);for(const s in n)t[s]=n[s]}return t}function r0(i){const t=[];for(let e=0;e<i.length;e++)t.push(i[e].clone());return t}function gf(i){const t=i.getRenderTarget();return t===null?i.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:oe.workingColorSpace}const ji={clone:fr,merge:sn};var a0=`void main() {
6
+ */const ch="169",Di={ROTATE:0,DOLLY:1,PAN:2},is={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},Mm=0,hu=1,bm=2,ff=1,pf=2,Ei=3,os=0,un=1,li=2,Ye=0,pr=1,ac=2,uu=3,du=4,mf=5,jn=100,Sm=101,wm=102,Em=103,Tm=104,$r=200,Am=201,Cm=202,Rm=203,oc=204,lc=205,cc=206,Pm=207,hc=208,Lm=209,Dm=210,Im=211,km=212,Nm=213,Um=214,uc=0,dc=1,fc=2,xr=3,pc=4,mc=5,gc=6,vc=7,gf=0,Om=1,Fm=2,ss=0,vf=1,_f=2,xf=3,yf=4,zm=5,Mf=6,hh=7,bf=300,yr=301,Mr=302,_c=303,xc=304,Uo=306,Ni=1e3,Ms=1001,yc=1002,rn=1003,Bm=1004,pa=1005,qn=1006,el=1007,bs=1008,pi=1009,Sf=1010,wf=1011,ra=1012,uh=1013,Ts=1014,Ci=1015,Ui=1016,dh=1017,fh=1018,As=1020,Ef=35902,Tf=1021,Af=1022,Nn=1023,Cf=1024,Rf=1025,mr=1026,Cs=1027,Pf=1028,ph=1029,Lf=1030,mh=1031,gh=1033,no=33776,io=33777,so=33778,ro=33779,Mc=35840,bc=35841,Sc=35842,wc=35843,Ec=36196,Tc=37492,Ac=37496,Cc=37808,Rc=37809,Pc=37810,Lc=37811,Dc=37812,Ic=37813,kc=37814,Nc=37815,Uc=37816,Oc=37817,Fc=37818,zc=37819,Bc=37820,Hc=37821,ao=36492,Vc=36494,Gc=36495,Df=36283,$c=36284,Wc=36285,Xc=36286,Hm=3200,Vm=3201,vh=0,Gm=1,Ji="",Ke="srgb",cs="srgb-linear",_h="display-p3",Oo="display-p3-linear",yo="linear",ye="srgb",Mo="rec709",bo="p3",Us=7680,fu=519,$m=512,Wm=513,Xm=514,If=515,jm=516,qm=517,Ym=518,Km=519,pu=35044,mu="300 es",Ri=2e3,So=2001;class Ps{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const n=this._listeners;n[t]===void 0&&(n[t]=[]),n[t].indexOf(e)===-1&&n[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;const n=this._listeners;return n[t]!==void 0&&n[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;const s=this._listeners[t];if(s!==void 0){const r=s.indexOf(e);r!==-1&&s.splice(r,1)}}dispatchEvent(t){if(this._listeners===void 0)return;const n=this._listeners[t.type];if(n!==void 0){t.target=this;const s=n.slice(0);for(let r=0,a=s.length;r<a;r++)s[r].call(this,t);t.target=null}}}const tn=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let gu=1234567;const qr=Math.PI/180,aa=180/Math.PI;function Tr(){const i=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(tn[i&255]+tn[i>>8&255]+tn[i>>16&255]+tn[i>>24&255]+"-"+tn[t&255]+tn[t>>8&255]+"-"+tn[t>>16&15|64]+tn[t>>24&255]+"-"+tn[e&63|128]+tn[e>>8&255]+"-"+tn[e>>16&255]+tn[e>>24&255]+tn[n&255]+tn[n>>8&255]+tn[n>>16&255]+tn[n>>24&255]).toLowerCase()}function ze(i,t,e){return Math.max(t,Math.min(e,i))}function xh(i,t){return(i%t+t)%t}function Zm(i,t,e,n,s){return n+(i-t)*(s-n)/(e-t)}function Jm(i,t,e){return i!==t?(e-i)/(t-i):0}function Yr(i,t,e){return(1-e)*i+e*t}function Qm(i,t,e,n){return Yr(i,t,1-Math.exp(-e*n))}function t0(i,t=1){return t-Math.abs(xh(i,t*2)-t)}function e0(i,t,e){return i<=t?0:i>=e?1:(i=(i-t)/(e-t),i*i*(3-2*i))}function n0(i,t,e){return i<=t?0:i>=e?1:(i=(i-t)/(e-t),i*i*i*(i*(i*6-15)+10))}function i0(i,t){return i+Math.floor(Math.random()*(t-i+1))}function s0(i,t){return i+Math.random()*(t-i)}function r0(i){return i*(.5-Math.random())}function a0(i){i!==void 0&&(gu=i);let t=gu+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function o0(i){return i*qr}function l0(i){return i*aa}function c0(i){return(i&i-1)===0&&i!==0}function h0(i){return Math.pow(2,Math.ceil(Math.log(i)/Math.LN2))}function u0(i){return Math.pow(2,Math.floor(Math.log(i)/Math.LN2))}function d0(i,t,e,n,s){const r=Math.cos,a=Math.sin,o=r(e/2),l=a(e/2),c=r((t+n)/2),h=a((t+n)/2),u=r((t-n)/2),d=a((t-n)/2),f=r((n-t)/2),g=a((n-t)/2);switch(s){case"XYX":i.set(o*h,l*u,l*d,o*c);break;case"YZY":i.set(l*d,o*h,l*u,o*c);break;case"ZXZ":i.set(l*u,l*d,o*h,o*c);break;case"XZX":i.set(o*h,l*g,l*f,o*c);break;case"YXY":i.set(l*f,o*h,l*g,o*c);break;case"ZYZ":i.set(l*g,l*f,o*h,o*c);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function ir(i,t){switch(t.constructor){case Float32Array:return i;case Uint32Array:return i/4294967295;case Uint16Array:return i/65535;case Uint8Array:return i/255;case Int32Array:return Math.max(i/2147483647,-1);case Int16Array:return Math.max(i/32767,-1);case Int8Array:return Math.max(i/127,-1);default:throw new Error("Invalid component type.")}}function on(i,t){switch(t.constructor){case Float32Array:return i;case Uint32Array:return Math.round(i*4294967295);case Uint16Array:return Math.round(i*65535);case Uint8Array:return Math.round(i*255);case Int32Array:return Math.round(i*2147483647);case Int16Array:return Math.round(i*32767);case Int8Array:return Math.round(i*127);default:throw new Error("Invalid component type.")}}const xs={DEG2RAD:qr,RAD2DEG:aa,generateUUID:Tr,clamp:ze,euclideanModulo:xh,mapLinear:Zm,inverseLerp:Jm,lerp:Yr,damp:Qm,pingpong:t0,smoothstep:e0,smootherstep:n0,randInt:i0,randFloat:s0,randFloatSpread:r0,seededRandom:a0,degToRad:o0,radToDeg:l0,isPowerOfTwo:c0,ceilPowerOfTwo:h0,floorPowerOfTwo:u0,setQuaternionFromProperEuler:d0,normalize:on,denormalize:ir};class rt{constructor(t=0,e=0){rt.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,n=this.y,s=t.elements;return this.x=s[0]*e+s[3]*n+s[6],this.y=s[1]*e+s[4]*n+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(ze(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const n=Math.cos(e),s=Math.sin(e),r=this.x-t.x,a=this.y-t.y;return this.x=r*n-a*s+t.x,this.y=r*s+a*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Xt{constructor(t,e,n,s,r,a,o,l,c){Xt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,n,s,r,a,o,l,c)}set(t,e,n,s,r,a,o,l,c){const h=this.elements;return h[0]=t,h[1]=s,h[2]=o,h[3]=e,h[4]=r,h[5]=l,h[6]=n,h[7]=a,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,s=e.elements,r=this.elements,a=n[0],o=n[3],l=n[6],c=n[1],h=n[4],u=n[7],d=n[2],f=n[5],g=n[8],_=s[0],m=s[3],p=s[6],y=s[1],x=s[4],S=s[7],L=s[2],T=s[5],E=s[8];return r[0]=a*_+o*y+l*L,r[3]=a*m+o*x+l*T,r[6]=a*p+o*S+l*E,r[1]=c*_+h*y+u*L,r[4]=c*m+h*x+u*T,r[7]=c*p+h*S+u*E,r[2]=d*_+f*y+g*L,r[5]=d*m+f*x+g*T,r[8]=d*p+f*S+g*E,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8];return e*a*h-e*o*c-n*r*h+n*o*l+s*r*c-s*a*l}invert(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=h*a-o*c,d=o*l-h*r,f=c*r-a*l,g=e*u+n*d+s*f;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);const _=1/g;return t[0]=u*_,t[1]=(s*c-h*n)*_,t[2]=(o*n-s*a)*_,t[3]=d*_,t[4]=(h*e-s*l)*_,t[5]=(s*r-o*e)*_,t[6]=f*_,t[7]=(n*l-c*e)*_,t[8]=(a*e-n*r)*_,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,s,r,a,o){const l=Math.cos(r),c=Math.sin(r);return this.set(n*l,n*c,-n*(l*a+c*o)+a+t,-s*c,s*l,-s*(-c*a+l*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(nl.makeScale(t,e)),this}rotate(t){return this.premultiply(nl.makeRotation(-t)),this}translate(t,e){return this.premultiply(nl.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,n=t.elements;for(let s=0;s<9;s++)if(e[s]!==n[s])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const nl=new Xt;function kf(i){for(let t=i.length-1;t>=0;--t)if(i[t]>=65535)return!0;return!1}function wo(i){return document.createElementNS("http://www.w3.org/1999/xhtml",i)}function f0(){const i=wo("canvas");return i.style.display="block",i}const vu={};function oo(i){i in vu||(vu[i]=!0,console.warn(i))}function p0(i,t,e){return new Promise(function(n,s){function r(){switch(i.clientWaitSync(t,i.SYNC_FLUSH_COMMANDS_BIT,0)){case i.WAIT_FAILED:s();break;case i.TIMEOUT_EXPIRED:setTimeout(r,e);break;default:n()}}setTimeout(r,e)})}function m0(i){const t=i.elements;t[2]=.5*t[2]+.5*t[3],t[6]=.5*t[6]+.5*t[7],t[10]=.5*t[10]+.5*t[11],t[14]=.5*t[14]+.5*t[15]}function g0(i){const t=i.elements;t[11]===-1?(t[10]=-t[10]-1,t[14]=-t[14]):(t[10]=-t[10],t[14]=-t[14]+1)}const _u=new Xt().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),xu=new Xt().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),Rr={[cs]:{transfer:yo,primaries:Mo,luminanceCoefficients:[.2126,.7152,.0722],toReference:i=>i,fromReference:i=>i},[Ke]:{transfer:ye,primaries:Mo,luminanceCoefficients:[.2126,.7152,.0722],toReference:i=>i.convertSRGBToLinear(),fromReference:i=>i.convertLinearToSRGB()},[Oo]:{transfer:yo,primaries:bo,luminanceCoefficients:[.2289,.6917,.0793],toReference:i=>i.applyMatrix3(xu),fromReference:i=>i.applyMatrix3(_u)},[_h]:{transfer:ye,primaries:bo,luminanceCoefficients:[.2289,.6917,.0793],toReference:i=>i.convertSRGBToLinear().applyMatrix3(xu),fromReference:i=>i.applyMatrix3(_u).convertLinearToSRGB()}},v0=new Set([cs,Oo]),oe={enabled:!0,_workingColorSpace:cs,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(i){if(!v0.has(i))throw new Error(`Unsupported working color space, "${i}".`);this._workingColorSpace=i},convert:function(i,t,e){if(this.enabled===!1||t===e||!t||!e)return i;const n=Rr[t].toReference,s=Rr[e].fromReference;return s(n(i))},fromWorkingColorSpace:function(i,t){return this.convert(i,this._workingColorSpace,t)},toWorkingColorSpace:function(i,t){return this.convert(i,t,this._workingColorSpace)},getPrimaries:function(i){return Rr[i].primaries},getTransfer:function(i){return i===Ji?yo:Rr[i].transfer},getLuminanceCoefficients:function(i,t=this._workingColorSpace){return i.fromArray(Rr[t].luminanceCoefficients)}};function gr(i){return i<.04045?i*.0773993808:Math.pow(i*.9478672986+.0521327014,2.4)}function il(i){return i<.0031308?i*12.92:1.055*Math.pow(i,.41666)-.055}let Os;class _0{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{Os===void 0&&(Os=wo("canvas")),Os.width=t.width,Os.height=t.height;const n=Os.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=Os}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=wo("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const s=n.getImageData(0,0,t.width,t.height),r=s.data;for(let a=0;a<r.length;a++)r[a]=gr(r[a]/255)*255;return n.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let n=0;n<e.length;n++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[n]=Math.floor(gr(e[n]/255)*255):e[n]=gr(e[n]);return{data:e,width:t.width,height:t.height}}else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let x0=0;class Nf{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:x0++}),this.uuid=Tr(),this.data=t,this.dataReady=!0,this.version=0}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const n={uuid:this.uuid,url:""},s=this.data;if(s!==null){let r;if(Array.isArray(s)){r=[];for(let a=0,o=s.length;a<o;a++)s[a].isDataTexture?r.push(sl(s[a].image)):r.push(sl(s[a]))}else r=sl(s);n.url=r}return e||(t.images[this.uuid]=n),n}}function sl(i){return typeof HTMLImageElement<"u"&&i instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&i instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&i instanceof ImageBitmap?_0.getDataURL(i):i.data?{data:Array.from(i.data),width:i.width,height:i.height,type:i.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let y0=0;class an extends Ps{constructor(t=an.DEFAULT_IMAGE,e=an.DEFAULT_MAPPING,n=Ms,s=Ms,r=qn,a=bs,o=Nn,l=pi,c=an.DEFAULT_ANISOTROPY,h=Ji){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:y0++}),this.uuid=Tr(),this.name="",this.source=new Nf(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=n,this.wrapT=s,this.magFilter=r,this.minFilter=a,this.anisotropy=c,this.format=o,this.internalFormat=null,this.type=l,this.offset=new rt(0,0),this.repeat=new rt(1,1),this.center=new rt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Xt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const n={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==bf)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Ni:t.x=t.x-Math.floor(t.x);break;case Ms:t.x=t.x<0?0:1;break;case yc:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case Ni:t.y=t.y-Math.floor(t.y);break;case Ms:t.y=t.y<0?0:1;break;case yc:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}an.DEFAULT_IMAGE=null;an.DEFAULT_MAPPING=bf;an.DEFAULT_ANISOTROPY=1;class me{constructor(t=0,e=0,n=0,s=1){me.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,s){return this.x=t,this.y=e,this.z=n,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,n=this.y,s=this.z,r=this.w,a=t.elements;return this.x=a[0]*e+a[4]*n+a[8]*s+a[12]*r,this.y=a[1]*e+a[5]*n+a[9]*s+a[13]*r,this.z=a[2]*e+a[6]*n+a[10]*s+a[14]*r,this.w=a[3]*e+a[7]*n+a[11]*s+a[15]*r,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,s,r;const l=t.elements,c=l[0],h=l[4],u=l[8],d=l[1],f=l[5],g=l[9],_=l[2],m=l[6],p=l[10];if(Math.abs(h-d)<.01&&Math.abs(u-_)<.01&&Math.abs(g-m)<.01){if(Math.abs(h+d)<.1&&Math.abs(u+_)<.1&&Math.abs(g+m)<.1&&Math.abs(c+f+p-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(c+1)/2,S=(f+1)/2,L=(p+1)/2,T=(h+d)/4,E=(u+_)/4,P=(g+m)/4;return x>S&&x>L?x<.01?(n=0,s=.707106781,r=.707106781):(n=Math.sqrt(x),s=T/n,r=E/n):S>L?S<.01?(n=.707106781,s=0,r=.707106781):(s=Math.sqrt(S),n=T/s,r=P/s):L<.01?(n=.707106781,s=.707106781,r=0):(r=Math.sqrt(L),n=E/r,s=P/r),this.set(n,s,r,e),this}let y=Math.sqrt((m-g)*(m-g)+(u-_)*(u-_)+(d-h)*(d-h));return Math.abs(y)<.001&&(y=1),this.x=(m-g)/y,this.y=(u-_)/y,this.z=(d-h)/y,this.w=Math.acos((c+f+p-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class M0 extends Ps{constructor(t=1,e=1,n={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new me(0,0,t,e),this.scissorTest=!1,this.viewport=new me(0,0,t,e);const s={width:t,height:e,depth:1};n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:qn,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},n);const r=new an(s,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace);r.flipY=!1,r.generateMipmaps=n.generateMipmaps,r.internalFormat=n.internalFormat,this.textures=[];const a=n.count;for(let o=0;o<a;o++)this.textures[o]=r.clone(),this.textures[o].isRenderTargetTexture=!0;this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this.depthTexture=n.depthTexture,this.samples=n.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}setSize(t,e,n=1){if(this.width!==t||this.height!==e||this.depth!==n){this.width=t,this.height=e,this.depth=n;for(let s=0,r=this.textures.length;s<r;s++)this.textures[s].image.width=t,this.textures[s].image.height=e,this.textures[s].image.depth=n;this.dispose()}this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let n=0,s=t.textures.length;n<s;n++)this.textures[n]=t.textures[n].clone(),this.textures[n].isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new Nf(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Qn extends M0{constructor(t=1,e=1,n={}){super(t,e,n),this.isWebGLRenderTarget=!0}}class Uf extends an{constructor(t=null,e=1,n=1,s=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:n,depth:s},this.magFilter=rn,this.minFilter=rn,this.wrapR=Ms,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class b0 extends an{constructor(t=null,e=1,n=1,s=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:n,depth:s},this.magFilter=rn,this.minFilter=rn,this.wrapR=Ms,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class ls{constructor(t=0,e=0,n=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=s}static slerpFlat(t,e,n,s,r,a,o){let l=n[s+0],c=n[s+1],h=n[s+2],u=n[s+3];const d=r[a+0],f=r[a+1],g=r[a+2],_=r[a+3];if(o===0){t[e+0]=l,t[e+1]=c,t[e+2]=h,t[e+3]=u;return}if(o===1){t[e+0]=d,t[e+1]=f,t[e+2]=g,t[e+3]=_;return}if(u!==_||l!==d||c!==f||h!==g){let m=1-o;const p=l*d+c*f+h*g+u*_,y=p>=0?1:-1,x=1-p*p;if(x>Number.EPSILON){const L=Math.sqrt(x),T=Math.atan2(L,p*y);m=Math.sin(m*T)/L,o=Math.sin(o*T)/L}const S=o*y;if(l=l*m+d*S,c=c*m+f*S,h=h*m+g*S,u=u*m+_*S,m===1-o){const L=1/Math.sqrt(l*l+c*c+h*h+u*u);l*=L,c*=L,h*=L,u*=L}}t[e]=l,t[e+1]=c,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,s,r,a){const o=n[s],l=n[s+1],c=n[s+2],h=n[s+3],u=r[a],d=r[a+1],f=r[a+2],g=r[a+3];return t[e]=o*g+h*u+l*f-c*d,t[e+1]=l*g+h*d+c*u-o*f,t[e+2]=c*g+h*f+o*d-l*u,t[e+3]=h*g-o*u-l*d-c*f,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,s){return this._x=t,this._y=e,this._z=n,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const n=t._x,s=t._y,r=t._z,a=t._order,o=Math.cos,l=Math.sin,c=o(n/2),h=o(s/2),u=o(r/2),d=l(n/2),f=l(s/2),g=l(r/2);switch(a){case"XYZ":this._x=d*h*u+c*f*g,this._y=c*f*u-d*h*g,this._z=c*h*g+d*f*u,this._w=c*h*u-d*f*g;break;case"YXZ":this._x=d*h*u+c*f*g,this._y=c*f*u-d*h*g,this._z=c*h*g-d*f*u,this._w=c*h*u+d*f*g;break;case"ZXY":this._x=d*h*u-c*f*g,this._y=c*f*u+d*h*g,this._z=c*h*g+d*f*u,this._w=c*h*u-d*f*g;break;case"ZYX":this._x=d*h*u-c*f*g,this._y=c*f*u+d*h*g,this._z=c*h*g-d*f*u,this._w=c*h*u+d*f*g;break;case"YZX":this._x=d*h*u+c*f*g,this._y=c*f*u+d*h*g,this._z=c*h*g-d*f*u,this._w=c*h*u-d*f*g;break;case"XZY":this._x=d*h*u-c*f*g,this._y=c*f*u-d*h*g,this._z=c*h*g+d*f*u,this._w=c*h*u+d*f*g;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,s=Math.sin(n);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],s=e[4],r=e[8],a=e[1],o=e[5],l=e[9],c=e[2],h=e[6],u=e[10],d=n+o+u;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(h-l)*f,this._y=(r-c)*f,this._z=(a-s)*f}else if(n>o&&n>u){const f=2*Math.sqrt(1+n-o-u);this._w=(h-l)/f,this._x=.25*f,this._y=(s+a)/f,this._z=(r+c)/f}else if(o>u){const f=2*Math.sqrt(1+o-n-u);this._w=(r-c)/f,this._x=(s+a)/f,this._y=.25*f,this._z=(l+h)/f}else{const f=2*Math.sqrt(1+u-n-o);this._w=(a-s)/f,this._x=(r+c)/f,this._y=(l+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<Number.EPSILON?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(ze(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(n===0)return this;const s=Math.min(1,e/n);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const n=t._x,s=t._y,r=t._z,a=t._w,o=e._x,l=e._y,c=e._z,h=e._w;return this._x=n*h+a*o+s*c-r*l,this._y=s*h+a*l+r*o-n*c,this._z=r*h+a*c+n*l-s*o,this._w=a*h-n*o-s*l-r*c,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const n=this._x,s=this._y,r=this._z,a=this._w;let o=a*t._w+n*t._x+s*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=a,this._x=n,this._y=s,this._z=r,this;const l=1-o*o;if(l<=Number.EPSILON){const f=1-e;return this._w=f*a+e*this._w,this._x=f*n+e*this._x,this._y=f*s+e*this._y,this._z=f*r+e*this._z,this.normalize(),this}const c=Math.sqrt(l),h=Math.atan2(c,o),u=Math.sin((1-e)*h)/c,d=Math.sin(e*h)/c;return this._w=a*u+this._w*d,this._x=n*u+this._x*d,this._y=s*u+this._y*d,this._z=r*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),s=Math.sqrt(1-n),r=Math.sqrt(n);return this.set(s*Math.sin(t),s*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class R{constructor(t=0,e=0,n=0){R.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return n===void 0&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(yu.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(yu.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*s,this.y=r[1]*e+r[4]*n+r[7]*s,this.z=r[2]*e+r[5]*n+r[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,s=this.z,r=t.elements,a=1/(r[3]*e+r[7]*n+r[11]*s+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*s+r[12])*a,this.y=(r[1]*e+r[5]*n+r[9]*s+r[13])*a,this.z=(r[2]*e+r[6]*n+r[10]*s+r[14])*a,this}applyQuaternion(t){const e=this.x,n=this.y,s=this.z,r=t.x,a=t.y,o=t.z,l=t.w,c=2*(a*s-o*n),h=2*(o*e-r*s),u=2*(r*n-a*e);return this.x=e+l*c+a*u-o*h,this.y=n+l*h+o*c-r*u,this.z=s+l*u+r*h-a*c,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,n=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*s,this.y=r[1]*e+r[5]*n+r[9]*s,this.z=r[2]*e+r[6]*n+r[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,s=t.y,r=t.z,a=e.x,o=e.y,l=e.z;return this.x=s*l-r*o,this.y=r*a-n*l,this.z=n*o-s*a,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return rl.copy(this).projectOnVector(t),this.sub(rl)}reflect(t){return this.sub(rl.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(ze(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,s=this.z-t.z;return e*e+n*n+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){const s=Math.sin(e)*t;return this.x=s*Math.sin(n),this.y=Math.cos(e)*t,this.z=s*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const rl=new R,yu=new ls;class la{constructor(t=new R(1/0,1/0,1/0),e=new R(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e+=3)this.expandByPoint(Vn.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(Vn.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const n=Vn.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(n),this.max.copy(t).add(n),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const n=t.geometry;if(n!==void 0){const r=n.getAttribute("position");if(e===!0&&r!==void 0&&t.isInstancedMesh!==!0)for(let a=0,o=r.count;a<o;a++)t.isMesh===!0?t.getVertexPosition(a,Vn):Vn.fromBufferAttribute(r,a),Vn.applyMatrix4(t.matrixWorld),this.expandByPoint(Vn);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),ma.copy(t.boundingBox)):(n.boundingBox===null&&n.computeBoundingBox(),ma.copy(n.boundingBox)),ma.applyMatrix4(t.matrixWorld),this.union(ma)}const s=t.children;for(let r=0,a=s.length;r<a;r++)this.expandByObject(s[r],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,Vn),Vn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Pr),ga.subVectors(this.max,Pr),Fs.subVectors(t.a,Pr),zs.subVectors(t.b,Pr),Bs.subVectors(t.c,Pr),Hi.subVectors(zs,Fs),Vi.subVectors(Bs,zs),us.subVectors(Fs,Bs);let e=[0,-Hi.z,Hi.y,0,-Vi.z,Vi.y,0,-us.z,us.y,Hi.z,0,-Hi.x,Vi.z,0,-Vi.x,us.z,0,-us.x,-Hi.y,Hi.x,0,-Vi.y,Vi.x,0,-us.y,us.x,0];return!al(e,Fs,zs,Bs,ga)||(e=[1,0,0,0,1,0,0,0,1],!al(e,Fs,zs,Bs,ga))?!1:(va.crossVectors(Hi,Vi),e=[va.x,va.y,va.z],al(e,Fs,zs,Bs,ga))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Vn).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(Vn).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(xi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),xi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),xi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),xi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),xi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),xi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),xi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),xi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(xi),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const xi=[new R,new R,new R,new R,new R,new R,new R,new R],Vn=new R,ma=new la,Fs=new R,zs=new R,Bs=new R,Hi=new R,Vi=new R,us=new R,Pr=new R,ga=new R,va=new R,ds=new R;function al(i,t,e,n,s){for(let r=0,a=i.length-3;r<=a;r+=3){ds.fromArray(i,r);const o=s.x*Math.abs(ds.x)+s.y*Math.abs(ds.y)+s.z*Math.abs(ds.z),l=t.dot(ds),c=e.dot(ds),h=n.dot(ds);if(Math.max(-Math.max(l,c,h),Math.min(l,c,h))>o)return!1}return!0}const S0=new la,Lr=new R,ol=new R;class yh{constructor(t=new R,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const n=this.center;e!==void 0?n.copy(e):S0.setFromPoints(t).getCenter(n);let s=0;for(let r=0,a=t.length;r<a;r++)s=Math.max(s,n.distanceToSquared(t[r]));return this.radius=Math.sqrt(s),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const n=this.center.distanceToSquared(t);return e.copy(t),n>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;Lr.subVectors(t,this.center);const e=Lr.lengthSq();if(e>this.radius*this.radius){const n=Math.sqrt(e),s=(n-this.radius)*.5;this.center.addScaledVector(Lr,s/n),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(ol.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Lr.copy(t.center).add(ol)),this.expandByPoint(Lr.copy(t.center).sub(ol))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}const yi=new R,ll=new R,_a=new R,Gi=new R,cl=new R,xa=new R,hl=new R;class Mh{constructor(t=new R,e=new R(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,yi)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=yi.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(yi.copy(this.origin).addScaledVector(this.direction,e),yi.distanceToSquared(t))}distanceSqToSegment(t,e,n,s){ll.copy(t).add(e).multiplyScalar(.5),_a.copy(e).sub(t).normalize(),Gi.copy(this.origin).sub(ll);const r=t.distanceTo(e)*.5,a=-this.direction.dot(_a),o=Gi.dot(this.direction),l=-Gi.dot(_a),c=Gi.lengthSq(),h=Math.abs(1-a*a);let u,d,f,g;if(h>0)if(u=a*l-o,d=a*o-l,g=r*h,u>=0)if(d>=-g)if(d<=g){const _=1/h;u*=_,d*=_,f=u*(u+a*d+2*o)+d*(a*u+d+2*l)+c}else d=r,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*l)+c;else d=-r,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*l)+c;else d<=-g?(u=Math.max(0,-(-a*r+o)),d=u>0?-r:Math.min(Math.max(-r,-l),r),f=-u*u+d*(d+2*l)+c):d<=g?(u=0,d=Math.min(Math.max(-r,-l),r),f=d*(d+2*l)+c):(u=Math.max(0,-(a*r+o)),d=u>0?r:Math.min(Math.max(-r,-l),r),f=-u*u+d*(d+2*l)+c);else d=a>0?-r:r,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*l)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy(ll).addScaledVector(_a,d),f}intersectSphere(t,e){yi.subVectors(t.center,this.origin);const n=yi.dot(this.direction),s=yi.dot(yi)-n*n,r=t.radius*t.radius;if(s>r)return null;const a=Math.sqrt(r-s),o=n-a,l=n+a;return l<0?null:o<0?this.at(l,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return n===null?null:this.at(n,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,s,r,a,o,l;const c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,d=this.origin;return c>=0?(n=(t.min.x-d.x)*c,s=(t.max.x-d.x)*c):(n=(t.max.x-d.x)*c,s=(t.min.x-d.x)*c),h>=0?(r=(t.min.y-d.y)*h,a=(t.max.y-d.y)*h):(r=(t.max.y-d.y)*h,a=(t.min.y-d.y)*h),n>a||r>s||((r>n||isNaN(n))&&(n=r),(a<s||isNaN(s))&&(s=a),u>=0?(o=(t.min.z-d.z)*u,l=(t.max.z-d.z)*u):(o=(t.max.z-d.z)*u,l=(t.min.z-d.z)*u),n>l||o>s)||((o>n||n!==n)&&(n=o),(l<s||s!==s)&&(s=l),s<0)?null:this.at(n>=0?n:s,e)}intersectsBox(t){return this.intersectBox(t,yi)!==null}intersectTriangle(t,e,n,s,r){cl.subVectors(e,t),xa.subVectors(n,t),hl.crossVectors(cl,xa);let a=this.direction.dot(hl),o;if(a>0){if(s)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Gi.subVectors(this.origin,t);const l=o*this.direction.dot(xa.crossVectors(Gi,xa));if(l<0)return null;const c=o*this.direction.dot(cl.cross(Gi));if(c<0||l+c>a)return null;const h=-o*Gi.dot(hl);return h<0?null:this.at(h/a,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class fe{constructor(t,e,n,s,r,a,o,l,c,h,u,d,f,g,_,m){fe.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,n,s,r,a,o,l,c,h,u,d,f,g,_,m)}set(t,e,n,s,r,a,o,l,c,h,u,d,f,g,_,m){const p=this.elements;return p[0]=t,p[4]=e,p[8]=n,p[12]=s,p[1]=r,p[5]=a,p[9]=o,p[13]=l,p[2]=c,p[6]=h,p[10]=u,p[14]=d,p[3]=f,p[7]=g,p[11]=_,p[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new fe().fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,n=t.elements,s=1/Hs.setFromMatrixColumn(t,0).length(),r=1/Hs.setFromMatrixColumn(t,1).length(),a=1/Hs.setFromMatrixColumn(t,2).length();return e[0]=n[0]*s,e[1]=n[1]*s,e[2]=n[2]*s,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*a,e[9]=n[9]*a,e[10]=n[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,s=t.y,r=t.z,a=Math.cos(n),o=Math.sin(n),l=Math.cos(s),c=Math.sin(s),h=Math.cos(r),u=Math.sin(r);if(t.order==="XYZ"){const d=a*h,f=a*u,g=o*h,_=o*u;e[0]=l*h,e[4]=-l*u,e[8]=c,e[1]=f+g*c,e[5]=d-_*c,e[9]=-o*l,e[2]=_-d*c,e[6]=g+f*c,e[10]=a*l}else if(t.order==="YXZ"){const d=l*h,f=l*u,g=c*h,_=c*u;e[0]=d+_*o,e[4]=g*o-f,e[8]=a*c,e[1]=a*u,e[5]=a*h,e[9]=-o,e[2]=f*o-g,e[6]=_+d*o,e[10]=a*l}else if(t.order==="ZXY"){const d=l*h,f=l*u,g=c*h,_=c*u;e[0]=d-_*o,e[4]=-a*u,e[8]=g+f*o,e[1]=f+g*o,e[5]=a*h,e[9]=_-d*o,e[2]=-a*c,e[6]=o,e[10]=a*l}else if(t.order==="ZYX"){const d=a*h,f=a*u,g=o*h,_=o*u;e[0]=l*h,e[4]=g*c-f,e[8]=d*c+_,e[1]=l*u,e[5]=_*c+d,e[9]=f*c-g,e[2]=-c,e[6]=o*l,e[10]=a*l}else if(t.order==="YZX"){const d=a*l,f=a*c,g=o*l,_=o*c;e[0]=l*h,e[4]=_-d*u,e[8]=g*u+f,e[1]=u,e[5]=a*h,e[9]=-o*h,e[2]=-c*h,e[6]=f*u+g,e[10]=d-_*u}else if(t.order==="XZY"){const d=a*l,f=a*c,g=o*l,_=o*c;e[0]=l*h,e[4]=-u,e[8]=c*h,e[1]=d*u+_,e[5]=a*h,e[9]=f*u-g,e[2]=g*u-f,e[6]=o*h,e[10]=_*u+d}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(w0,t,E0)}lookAt(t,e,n){const s=this.elements;return wn.subVectors(t,e),wn.lengthSq()===0&&(wn.z=1),wn.normalize(),$i.crossVectors(n,wn),$i.lengthSq()===0&&(Math.abs(n.z)===1?wn.x+=1e-4:wn.z+=1e-4,wn.normalize(),$i.crossVectors(n,wn)),$i.normalize(),ya.crossVectors(wn,$i),s[0]=$i.x,s[4]=ya.x,s[8]=wn.x,s[1]=$i.y,s[5]=ya.y,s[9]=wn.y,s[2]=$i.z,s[6]=ya.z,s[10]=wn.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,s=e.elements,r=this.elements,a=n[0],o=n[4],l=n[8],c=n[12],h=n[1],u=n[5],d=n[9],f=n[13],g=n[2],_=n[6],m=n[10],p=n[14],y=n[3],x=n[7],S=n[11],L=n[15],T=s[0],E=s[4],P=s[8],U=s[12],v=s[1],b=s[5],I=s[9],O=s[13],$=s[2],K=s[6],z=s[10],Z=s[14],V=s[3],at=s[7],ct=s[11],_t=s[15];return r[0]=a*T+o*v+l*$+c*V,r[4]=a*E+o*b+l*K+c*at,r[8]=a*P+o*I+l*z+c*ct,r[12]=a*U+o*O+l*Z+c*_t,r[1]=h*T+u*v+d*$+f*V,r[5]=h*E+u*b+d*K+f*at,r[9]=h*P+u*I+d*z+f*ct,r[13]=h*U+u*O+d*Z+f*_t,r[2]=g*T+_*v+m*$+p*V,r[6]=g*E+_*b+m*K+p*at,r[10]=g*P+_*I+m*z+p*ct,r[14]=g*U+_*O+m*Z+p*_t,r[3]=y*T+x*v+S*$+L*V,r[7]=y*E+x*b+S*K+L*at,r[11]=y*P+x*I+S*z+L*ct,r[15]=y*U+x*O+S*Z+L*_t,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[4],s=t[8],r=t[12],a=t[1],o=t[5],l=t[9],c=t[13],h=t[2],u=t[6],d=t[10],f=t[14],g=t[3],_=t[7],m=t[11],p=t[15];return g*(+r*l*u-s*c*u-r*o*d+n*c*d+s*o*f-n*l*f)+_*(+e*l*f-e*c*d+r*a*d-s*a*f+s*c*h-r*l*h)+m*(+e*c*u-e*o*f-r*a*u+n*a*f+r*o*h-n*c*h)+p*(-s*o*h-e*l*u+e*o*d+s*a*u-n*a*d+n*l*h)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=t[9],d=t[10],f=t[11],g=t[12],_=t[13],m=t[14],p=t[15],y=u*m*c-_*d*c+_*l*f-o*m*f-u*l*p+o*d*p,x=g*d*c-h*m*c-g*l*f+a*m*f+h*l*p-a*d*p,S=h*_*c-g*u*c+g*o*f-a*_*f-h*o*p+a*u*p,L=g*u*l-h*_*l-g*o*d+a*_*d+h*o*m-a*u*m,T=e*y+n*x+s*S+r*L;if(T===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/T;return t[0]=y*E,t[1]=(_*d*r-u*m*r-_*s*f+n*m*f+u*s*p-n*d*p)*E,t[2]=(o*m*r-_*l*r+_*s*c-n*m*c-o*s*p+n*l*p)*E,t[3]=(u*l*r-o*d*r-u*s*c+n*d*c+o*s*f-n*l*f)*E,t[4]=x*E,t[5]=(h*m*r-g*d*r+g*s*f-e*m*f-h*s*p+e*d*p)*E,t[6]=(g*l*r-a*m*r-g*s*c+e*m*c+a*s*p-e*l*p)*E,t[7]=(a*d*r-h*l*r+h*s*c-e*d*c-a*s*f+e*l*f)*E,t[8]=S*E,t[9]=(g*u*r-h*_*r-g*n*f+e*_*f+h*n*p-e*u*p)*E,t[10]=(a*_*r-g*o*r+g*n*c-e*_*c-a*n*p+e*o*p)*E,t[11]=(h*o*r-a*u*r-h*n*c+e*u*c+a*n*f-e*o*f)*E,t[12]=L*E,t[13]=(h*_*s-g*u*s+g*n*d-e*_*d-h*n*m+e*u*m)*E,t[14]=(g*o*s-a*_*s-g*n*l+e*_*l+a*n*m-e*o*m)*E,t[15]=(a*u*s-h*o*s+h*n*l-e*u*l-a*n*d+e*o*d)*E,this}scale(t){const e=this.elements,n=t.x,s=t.y,r=t.z;return e[0]*=n,e[4]*=s,e[8]*=r,e[1]*=n,e[5]*=s,e[9]*=r,e[2]*=n,e[6]*=s,e[10]*=r,e[3]*=n,e[7]*=s,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,s))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),s=Math.sin(e),r=1-n,a=t.x,o=t.y,l=t.z,c=r*a,h=r*o;return this.set(c*a+n,c*o-s*l,c*l+s*o,0,c*o+s*l,h*o+n,h*l-s*a,0,c*l-s*o,h*l+s*a,r*l*l+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,s,r,a){return this.set(1,n,r,0,t,1,a,0,e,s,1,0,0,0,0,1),this}compose(t,e,n){const s=this.elements,r=e._x,a=e._y,o=e._z,l=e._w,c=r+r,h=a+a,u=o+o,d=r*c,f=r*h,g=r*u,_=a*h,m=a*u,p=o*u,y=l*c,x=l*h,S=l*u,L=n.x,T=n.y,E=n.z;return s[0]=(1-(_+p))*L,s[1]=(f+S)*L,s[2]=(g-x)*L,s[3]=0,s[4]=(f-S)*T,s[5]=(1-(d+p))*T,s[6]=(m+y)*T,s[7]=0,s[8]=(g+x)*E,s[9]=(m-y)*E,s[10]=(1-(d+_))*E,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,n){const s=this.elements;let r=Hs.set(s[0],s[1],s[2]).length();const a=Hs.set(s[4],s[5],s[6]).length(),o=Hs.set(s[8],s[9],s[10]).length();this.determinant()<0&&(r=-r),t.x=s[12],t.y=s[13],t.z=s[14],Gn.copy(this);const c=1/r,h=1/a,u=1/o;return Gn.elements[0]*=c,Gn.elements[1]*=c,Gn.elements[2]*=c,Gn.elements[4]*=h,Gn.elements[5]*=h,Gn.elements[6]*=h,Gn.elements[8]*=u,Gn.elements[9]*=u,Gn.elements[10]*=u,e.setFromRotationMatrix(Gn),n.x=r,n.y=a,n.z=o,this}makePerspective(t,e,n,s,r,a,o=Ri){const l=this.elements,c=2*r/(e-t),h=2*r/(n-s),u=(e+t)/(e-t),d=(n+s)/(n-s);let f,g;if(o===Ri)f=-(a+r)/(a-r),g=-2*a*r/(a-r);else if(o===So)f=-a/(a-r),g=-a*r/(a-r);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return l[0]=c,l[4]=0,l[8]=u,l[12]=0,l[1]=0,l[5]=h,l[9]=d,l[13]=0,l[2]=0,l[6]=0,l[10]=f,l[14]=g,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,n,s,r,a,o=Ri){const l=this.elements,c=1/(e-t),h=1/(n-s),u=1/(a-r),d=(e+t)*c,f=(n+s)*h;let g,_;if(o===Ri)g=(a+r)*u,_=-2*u;else if(o===So)g=r*u,_=-1*u;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return l[0]=2*c,l[4]=0,l[8]=0,l[12]=-d,l[1]=0,l[5]=2*h,l[9]=0,l[13]=-f,l[2]=0,l[6]=0,l[10]=_,l[14]=-g,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let s=0;s<16;s++)if(e[s]!==n[s])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const Hs=new R,Gn=new fe,w0=new R(0,0,0),E0=new R(1,1,1),$i=new R,ya=new R,wn=new R,Mu=new fe,bu=new ls;class mi{constructor(t=0,e=0,n=0,s=mi.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,s=this._order){return this._x=t,this._y=e,this._z=n,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){const s=t.elements,r=s[0],a=s[4],o=s[8],l=s[1],c=s[5],h=s[9],u=s[2],d=s[6],f=s[10];switch(e){case"XYZ":this._y=Math.asin(ze(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-a,r)):(this._x=Math.atan2(d,c),this._z=0);break;case"YXZ":this._x=Math.asin(-ze(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(ze(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,c)):(this._y=0,this._z=Math.atan2(l,r));break;case"ZYX":this._y=Math.asin(-ze(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(l,r)):(this._x=0,this._z=Math.atan2(-a,c));break;case"YZX":this._z=Math.asin(ze(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(o,f));break;case"XZY":this._z=Math.asin(-ze(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-h,f),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,n===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return Mu.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Mu,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return bu.setFromEuler(this),this.setFromQuaternion(bu,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}mi.DEFAULT_ORDER="XYZ";class bh{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let T0=0;const Su=new R,Vs=new ls,Mi=new fe,Ma=new R,Dr=new R,A0=new R,C0=new ls,wu=new R(1,0,0),Eu=new R(0,1,0),Tu=new R(0,0,1),Au={type:"added"},R0={type:"removed"},Gs={type:"childadded",child:null},ul={type:"childremoved",child:null};class Qe extends Ps{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:T0++}),this.uuid=Tr(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Qe.DEFAULT_UP.clone();const t=new R,e=new mi,n=new ls,s=new R(1,1,1);function r(){n.setFromEuler(e,!1)}function a(){e.setFromQuaternion(n,void 0,!1)}e._onChange(r),n._onChange(a),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new fe},normalMatrix:{value:new Xt}}),this.matrix=new fe,this.matrixWorld=new fe,this.matrixAutoUpdate=Qe.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Qe.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new bh,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Vs.setFromAxisAngle(t,e),this.quaternion.multiply(Vs),this}rotateOnWorldAxis(t,e){return Vs.setFromAxisAngle(t,e),this.quaternion.premultiply(Vs),this}rotateX(t){return this.rotateOnAxis(wu,t)}rotateY(t){return this.rotateOnAxis(Eu,t)}rotateZ(t){return this.rotateOnAxis(Tu,t)}translateOnAxis(t,e){return Su.copy(t).applyQuaternion(this.quaternion),this.position.add(Su.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(wu,t)}translateY(t){return this.translateOnAxis(Eu,t)}translateZ(t){return this.translateOnAxis(Tu,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Mi.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?Ma.copy(t):Ma.set(t,e,n);const s=this.parent;this.updateWorldMatrix(!0,!1),Dr.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Mi.lookAt(Dr,Ma,this.up):Mi.lookAt(Ma,Dr,this.up),this.quaternion.setFromRotationMatrix(Mi),s&&(Mi.extractRotation(s.matrixWorld),Vs.setFromRotationMatrix(Mi),this.quaternion.premultiply(Vs.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(Au),Gs.child=t,this.dispatchEvent(Gs),Gs.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let n=0;n<arguments.length;n++)this.remove(arguments[n]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(R0),ul.child=t,this.dispatchEvent(ul),ul.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),Mi.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),Mi.multiply(t.parent.matrixWorld)),t.applyMatrix4(Mi),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Au),Gs.child=t,this.dispatchEvent(Gs),Gs.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let n=0,s=this.children.length;n<s;n++){const a=this.children[n].getObjectByProperty(t,e);if(a!==void 0)return a}}getObjectsByProperty(t,e,n=[]){this[t]===e&&n.push(this);const s=this.children;for(let r=0,a=s.length;r<a;r++)s[r].getObjectsByProperty(t,e,n);return n}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Dr,t,A0),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Dr,C0,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let n=0,s=e.length;n<s;n++)e[n].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let n=0,s=e.length;n<s;n++)e[n].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let n=0,s=e.length;n<s;n++)e[n].updateMatrixWorld(t)}updateWorldMatrix(t,e){const n=this.parent;if(t===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const s=this.children;for(let r=0,a=s.length;r<a;r++)s[r].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",n={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.castShadow===!0&&(s.castShadow=!0),this.receiveShadow===!0&&(s.receiveShadow=!0),this.visible===!1&&(s.visible=!1),this.frustumCulled===!1&&(s.frustumCulled=!1),this.renderOrder!==0&&(s.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.visibility=this._visibility,s.active=this._active,s.bounds=this._bounds.map(o=>({boxInitialized:o.boxInitialized,boxMin:o.box.min.toArray(),boxMax:o.box.max.toArray(),sphereInitialized:o.sphereInitialized,sphereRadius:o.sphere.radius,sphereCenter:o.sphere.center.toArray()})),s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.geometryCount=this._geometryCount,s.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere={center:s.boundingSphere.center.toArray(),radius:s.boundingSphere.radius}),this.boundingBox!==null&&(s.boundingBox={min:s.boundingBox.min.toArray(),max:s.boundingBox.max.toArray()}));function r(o,l){return o[l.uuid]===void 0&&(o[l.uuid]=l.toJSON(t)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=r(t.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const l=o.shapes;if(Array.isArray(l))for(let c=0,h=l.length;c<h;c++){const u=l[c];r(t.shapes,u)}else r(t.shapes,l)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(r(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let l=0,c=this.material.length;l<c;l++)o.push(r(t.materials,this.material[l]));s.material=o}else s.material=r(t.materials,this.material);if(this.children.length>0){s.children=[];for(let o=0;o<this.children.length;o++)s.children.push(this.children[o].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let o=0;o<this.animations.length;o++){const l=this.animations[o];s.animations.push(r(t.animations,l))}}if(e){const o=a(t.geometries),l=a(t.materials),c=a(t.textures),h=a(t.images),u=a(t.shapes),d=a(t.skeletons),f=a(t.animations),g=a(t.nodes);o.length>0&&(n.geometries=o),l.length>0&&(n.materials=l),c.length>0&&(n.textures=c),h.length>0&&(n.images=h),u.length>0&&(n.shapes=u),d.length>0&&(n.skeletons=d),f.length>0&&(n.animations=f),g.length>0&&(n.nodes=g)}return n.object=s,n;function a(o){const l=[];for(const c in o){const h=o[c];delete h.metadata,l.push(h)}return l}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let n=0;n<t.children.length;n++){const s=t.children[n];this.add(s.clone())}return this}}Qe.DEFAULT_UP=new R(0,1,0);Qe.DEFAULT_MATRIX_AUTO_UPDATE=!0;Qe.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const $n=new R,bi=new R,dl=new R,Si=new R,$s=new R,Ws=new R,Cu=new R,fl=new R,pl=new R,ml=new R,gl=new me,vl=new me,_l=new me;class Yn{constructor(t=new R,e=new R,n=new R){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,s){s.subVectors(n,e),$n.subVectors(t,e),s.cross($n);const r=s.lengthSq();return r>0?s.multiplyScalar(1/Math.sqrt(r)):s.set(0,0,0)}static getBarycoord(t,e,n,s,r){$n.subVectors(s,e),bi.subVectors(n,e),dl.subVectors(t,e);const a=$n.dot($n),o=$n.dot(bi),l=$n.dot(dl),c=bi.dot(bi),h=bi.dot(dl),u=a*c-o*o;if(u===0)return r.set(0,0,0),null;const d=1/u,f=(c*l-o*h)*d,g=(a*h-o*l)*d;return r.set(1-f-g,g,f)}static containsPoint(t,e,n,s){return this.getBarycoord(t,e,n,s,Si)===null?!1:Si.x>=0&&Si.y>=0&&Si.x+Si.y<=1}static getInterpolation(t,e,n,s,r,a,o,l){return this.getBarycoord(t,e,n,s,Si)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(r,Si.x),l.addScaledVector(a,Si.y),l.addScaledVector(o,Si.z),l)}static getInterpolatedAttribute(t,e,n,s,r,a){return gl.setScalar(0),vl.setScalar(0),_l.setScalar(0),gl.fromBufferAttribute(t,e),vl.fromBufferAttribute(t,n),_l.fromBufferAttribute(t,s),a.setScalar(0),a.addScaledVector(gl,r.x),a.addScaledVector(vl,r.y),a.addScaledVector(_l,r.z),a}static isFrontFacing(t,e,n,s){return $n.subVectors(n,e),bi.subVectors(t,e),$n.cross(bi).dot(s)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,s){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,n,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,s),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return $n.subVectors(this.c,this.b),bi.subVectors(this.a,this.b),$n.cross(bi).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Yn.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Yn.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,s,r){return Yn.getInterpolation(t,this.a,this.b,this.c,e,n,s,r)}containsPoint(t){return Yn.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Yn.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,s=this.b,r=this.c;let a,o;$s.subVectors(s,n),Ws.subVectors(r,n),fl.subVectors(t,n);const l=$s.dot(fl),c=Ws.dot(fl);if(l<=0&&c<=0)return e.copy(n);pl.subVectors(t,s);const h=$s.dot(pl),u=Ws.dot(pl);if(h>=0&&u<=h)return e.copy(s);const d=l*u-h*c;if(d<=0&&l>=0&&h<=0)return a=l/(l-h),e.copy(n).addScaledVector($s,a);ml.subVectors(t,r);const f=$s.dot(ml),g=Ws.dot(ml);if(g>=0&&f<=g)return e.copy(r);const _=f*c-l*g;if(_<=0&&c>=0&&g<=0)return o=c/(c-g),e.copy(n).addScaledVector(Ws,o);const m=h*g-f*u;if(m<=0&&u-h>=0&&f-g>=0)return Cu.subVectors(r,s),o=(u-h)/(u-h+(f-g)),e.copy(s).addScaledVector(Cu,o);const p=1/(m+_+d);return a=_*p,o=d*p,e.copy(n).addScaledVector($s,a).addScaledVector(Ws,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const Of={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Wi={h:0,s:0,l:0},ba={h:0,s:0,l:0};function xl(i,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?i+(t-i)*6*e:e<1/2?t:e<2/3?i+(t-i)*6*(2/3-e):i}class Zt{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(e===void 0&&n===void 0){const s=t;s&&s.isColor?this.copy(s):typeof s=="number"?this.setHex(s):typeof s=="string"&&this.setStyle(s)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Ke){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,oe.toWorkingColorSpace(this,e),this}setRGB(t,e,n,s=oe.workingColorSpace){return this.r=t,this.g=e,this.b=n,oe.toWorkingColorSpace(this,s),this}setHSL(t,e,n,s=oe.workingColorSpace){if(t=xh(t,1),e=ze(e,0,1),n=ze(n,0,1),e===0)this.r=this.g=this.b=n;else{const r=n<=.5?n*(1+e):n+e-n*e,a=2*n-r;this.r=xl(a,r,t+1/3),this.g=xl(a,r,t),this.b=xl(a,r,t-1/3)}return oe.toWorkingColorSpace(this,s),this}setStyle(t,e=Ke){function n(r){r!==void 0&&parseFloat(r)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let s;if(s=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const a=s[1],o=s[2];switch(a){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(s=/^\#([A-Fa-f\d]+)$/.exec(t)){const r=s[1],a=r.length;if(a===3)return this.setRGB(parseInt(r.charAt(0),16)/15,parseInt(r.charAt(1),16)/15,parseInt(r.charAt(2),16)/15,e);if(a===6)return this.setHex(parseInt(r,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Ke){const n=Of[t.toLowerCase()];return n!==void 0?this.setHex(n,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=gr(t.r),this.g=gr(t.g),this.b=gr(t.b),this}copyLinearToSRGB(t){return this.r=il(t.r),this.g=il(t.g),this.b=il(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Ke){return oe.fromWorkingColorSpace(en.copy(this),t),Math.round(ze(en.r*255,0,255))*65536+Math.round(ze(en.g*255,0,255))*256+Math.round(ze(en.b*255,0,255))}getHexString(t=Ke){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=oe.workingColorSpace){oe.fromWorkingColorSpace(en.copy(this),e);const n=en.r,s=en.g,r=en.b,a=Math.max(n,s,r),o=Math.min(n,s,r);let l,c;const h=(o+a)/2;if(o===a)l=0,c=0;else{const u=a-o;switch(c=h<=.5?u/(a+o):u/(2-a-o),a){case n:l=(s-r)/u+(s<r?6:0);break;case s:l=(r-n)/u+2;break;case r:l=(n-s)/u+4;break}l/=6}return t.h=l,t.s=c,t.l=h,t}getRGB(t,e=oe.workingColorSpace){return oe.fromWorkingColorSpace(en.copy(this),e),t.r=en.r,t.g=en.g,t.b=en.b,t}getStyle(t=Ke){oe.fromWorkingColorSpace(en.copy(this),t);const e=en.r,n=en.g,s=en.b;return t!==Ke?`color(${t} ${e.toFixed(3)} ${n.toFixed(3)} ${s.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(n*255)},${Math.round(s*255)})`}offsetHSL(t,e,n){return this.getHSL(Wi),this.setHSL(Wi.h+t,Wi.s+e,Wi.l+n)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,n){return this.r=t.r+(e.r-t.r)*n,this.g=t.g+(e.g-t.g)*n,this.b=t.b+(e.b-t.b)*n,this}lerpHSL(t,e){this.getHSL(Wi),t.getHSL(ba);const n=Yr(Wi.h,ba.h,e),s=Yr(Wi.s,ba.s,e),r=Yr(Wi.l,ba.l,e);return this.setHSL(n,s,r),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,n=this.g,s=this.b,r=t.elements;return this.r=r[0]*e+r[3]*n+r[6]*s,this.g=r[1]*e+r[4]*n+r[7]*s,this.b=r[2]*e+r[5]*n+r[8]*s,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const en=new Zt;Zt.NAMES=Of;let P0=0;class Fi extends Ps{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:P0++}),this.uuid=Tr(),this.name="",this.type="Material",this.blending=pr,this.side=os,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=oc,this.blendDst=lc,this.blendEquation=jn,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new Zt(0,0,0),this.blendAlpha=0,this.depthFunc=xr,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=fu,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Us,this.stencilZFail=Us,this.stencilZPass=Us,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const n=t[e];if(n===void 0){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const s=this[e];if(s===void 0){console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`);continue}s&&s.isColor?s.set(n):s&&s.isVector3&&n&&n.isVector3?s.copy(n):this[e]=n}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const n={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.dispersion!==void 0&&(n.dispersion=this.dispersion),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapRotation!==void 0&&(n.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==pr&&(n.blending=this.blending),this.side!==os&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==oc&&(n.blendSrc=this.blendSrc),this.blendDst!==lc&&(n.blendDst=this.blendDst),this.blendEquation!==jn&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==xr&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==fu&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Us&&(n.stencilFail=this.stencilFail),this.stencilZFail!==Us&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==Us&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function s(r){const a=[];for(const o in r){const l=r[o];delete l.metadata,a.push(l)}return a}if(e){const r=s(t.textures),a=s(t.images);r.length>0&&(n.textures=r),a.length>0&&(n.images=a)}return n}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let n=null;if(e!==null){const s=e.length;n=new Array(s);for(let r=0;r!==s;++r)n[r]=e[r].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}}class dn extends Fi{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Zt(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new mi,this.combine=gf,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const Ne=new R,Sa=new rt;class ui{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=n,this.usage=pu,this.updateRanges=[],this.gpuType=Ci,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let s=0,r=this.itemSize;s<r;s++)this.array[t+s]=e.array[n+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,n=this.count;e<n;e++)Sa.fromBufferAttribute(this,e),Sa.applyMatrix3(t),this.setXY(e,Sa.x,Sa.y);else if(this.itemSize===3)for(let e=0,n=this.count;e<n;e++)Ne.fromBufferAttribute(this,e),Ne.applyMatrix3(t),this.setXYZ(e,Ne.x,Ne.y,Ne.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)Ne.fromBufferAttribute(this,e),Ne.applyMatrix4(t),this.setXYZ(e,Ne.x,Ne.y,Ne.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)Ne.fromBufferAttribute(this,e),Ne.applyNormalMatrix(t),this.setXYZ(e,Ne.x,Ne.y,Ne.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)Ne.fromBufferAttribute(this,e),Ne.transformDirection(t),this.setXYZ(e,Ne.x,Ne.y,Ne.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let n=this.array[t*this.itemSize+e];return this.normalized&&(n=ir(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=on(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=ir(e,this.array)),e}setX(t,e){return this.normalized&&(e=on(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=ir(e,this.array)),e}setY(t,e){return this.normalized&&(e=on(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=ir(e,this.array)),e}setZ(t,e){return this.normalized&&(e=on(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=ir(e,this.array)),e}setW(t,e){return this.normalized&&(e=on(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=on(e,this.array),n=on(n,this.array)),this.array[t+0]=e,this.array[t+1]=n,this}setXYZ(t,e,n,s){return t*=this.itemSize,this.normalized&&(e=on(e,this.array),n=on(n,this.array),s=on(s,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=s,this}setXYZW(t,e,n,s,r){return t*=this.itemSize,this.normalized&&(e=on(e,this.array),n=on(n,this.array),s=on(s,this.array),r=on(r,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=s,this.array[t+3]=r,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==pu&&(t.usage=this.usage),t}}class Ff extends ui{constructor(t,e,n){super(new Uint16Array(t),e,n)}}class zf extends ui{constructor(t,e,n){super(new Uint32Array(t),e,n)}}class he extends ui{constructor(t,e,n){super(new Float32Array(t),e,n)}}let L0=0;const Ln=new fe,yl=new Qe,Xs=new R,En=new la,Ir=new la,Ge=new R;class fn extends Ps{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:L0++}),this.uuid=Tr(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(kf(t)?zf:Ff)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,n=0){this.groups.push({start:t,count:e,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const n=this.attributes.normal;if(n!==void 0){const r=new Xt().getNormalMatrix(t);n.applyNormalMatrix(r),n.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return Ln.makeRotationFromQuaternion(t),this.applyMatrix4(Ln),this}rotateX(t){return Ln.makeRotationX(t),this.applyMatrix4(Ln),this}rotateY(t){return Ln.makeRotationY(t),this.applyMatrix4(Ln),this}rotateZ(t){return Ln.makeRotationZ(t),this.applyMatrix4(Ln),this}translate(t,e,n){return Ln.makeTranslation(t,e,n),this.applyMatrix4(Ln),this}scale(t,e,n){return Ln.makeScale(t,e,n),this.applyMatrix4(Ln),this}lookAt(t){return yl.lookAt(t),yl.updateMatrix(),this.applyMatrix4(yl.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Xs).negate(),this.translate(Xs.x,Xs.y,Xs.z),this}setFromPoints(t){const e=[];for(let n=0,s=t.length;n<s;n++){const r=t[n];e.push(r.x,r.y,r.z||0)}return this.setAttribute("position",new he(e,3)),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new la);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new R(-1/0,-1/0,-1/0),new R(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let n=0,s=e.length;n<s;n++){const r=e[n];En.setFromBufferAttribute(r),this.morphTargetsRelative?(Ge.addVectors(this.boundingBox.min,En.min),this.boundingBox.expandByPoint(Ge),Ge.addVectors(this.boundingBox.max,En.max),this.boundingBox.expandByPoint(Ge)):(this.boundingBox.expandByPoint(En.min),this.boundingBox.expandByPoint(En.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new yh);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(t){const n=this.boundingSphere.center;if(En.setFromBufferAttribute(t),e)for(let r=0,a=e.length;r<a;r++){const o=e[r];Ir.setFromBufferAttribute(o),this.morphTargetsRelative?(Ge.addVectors(En.min,Ir.min),En.expandByPoint(Ge),Ge.addVectors(En.max,Ir.max),En.expandByPoint(Ge)):(En.expandByPoint(Ir.min),En.expandByPoint(Ir.max))}En.getCenter(n);let s=0;for(let r=0,a=t.count;r<a;r++)Ge.fromBufferAttribute(t,r),s=Math.max(s,n.distanceToSquared(Ge));if(e)for(let r=0,a=e.length;r<a;r++){const o=e[r],l=this.morphTargetsRelative;for(let c=0,h=o.count;c<h;c++)Ge.fromBufferAttribute(o,c),l&&(Xs.fromBufferAttribute(t,c),Ge.add(Xs)),s=Math.max(s,n.distanceToSquared(Ge))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const n=e.position,s=e.normal,r=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new ui(new Float32Array(4*n.count),4));const a=this.getAttribute("tangent"),o=[],l=[];for(let P=0;P<n.count;P++)o[P]=new R,l[P]=new R;const c=new R,h=new R,u=new R,d=new rt,f=new rt,g=new rt,_=new R,m=new R;function p(P,U,v){c.fromBufferAttribute(n,P),h.fromBufferAttribute(n,U),u.fromBufferAttribute(n,v),d.fromBufferAttribute(r,P),f.fromBufferAttribute(r,U),g.fromBufferAttribute(r,v),h.sub(c),u.sub(c),f.sub(d),g.sub(d);const b=1/(f.x*g.y-g.x*f.y);isFinite(b)&&(_.copy(h).multiplyScalar(g.y).addScaledVector(u,-f.y).multiplyScalar(b),m.copy(u).multiplyScalar(f.x).addScaledVector(h,-g.x).multiplyScalar(b),o[P].add(_),o[U].add(_),o[v].add(_),l[P].add(m),l[U].add(m),l[v].add(m))}let y=this.groups;y.length===0&&(y=[{start:0,count:t.count}]);for(let P=0,U=y.length;P<U;++P){const v=y[P],b=v.start,I=v.count;for(let O=b,$=b+I;O<$;O+=3)p(t.getX(O+0),t.getX(O+1),t.getX(O+2))}const x=new R,S=new R,L=new R,T=new R;function E(P){L.fromBufferAttribute(s,P),T.copy(L);const U=o[P];x.copy(U),x.sub(L.multiplyScalar(L.dot(U))).normalize(),S.crossVectors(T,U);const b=S.dot(l[P])<0?-1:1;a.setXYZW(P,x.x,x.y,x.z,b)}for(let P=0,U=y.length;P<U;++P){const v=y[P],b=v.start,I=v.count;for(let O=b,$=b+I;O<$;O+=3)E(t.getX(O+0)),E(t.getX(O+1)),E(t.getX(O+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let n=this.getAttribute("normal");if(n===void 0)n=new ui(new Float32Array(e.count*3),3),this.setAttribute("normal",n);else for(let d=0,f=n.count;d<f;d++)n.setXYZ(d,0,0,0);const s=new R,r=new R,a=new R,o=new R,l=new R,c=new R,h=new R,u=new R;if(t)for(let d=0,f=t.count;d<f;d+=3){const g=t.getX(d+0),_=t.getX(d+1),m=t.getX(d+2);s.fromBufferAttribute(e,g),r.fromBufferAttribute(e,_),a.fromBufferAttribute(e,m),h.subVectors(a,r),u.subVectors(s,r),h.cross(u),o.fromBufferAttribute(n,g),l.fromBufferAttribute(n,_),c.fromBufferAttribute(n,m),o.add(h),l.add(h),c.add(h),n.setXYZ(g,o.x,o.y,o.z),n.setXYZ(_,l.x,l.y,l.z),n.setXYZ(m,c.x,c.y,c.z)}else for(let d=0,f=e.count;d<f;d+=3)s.fromBufferAttribute(e,d+0),r.fromBufferAttribute(e,d+1),a.fromBufferAttribute(e,d+2),h.subVectors(a,r),u.subVectors(s,r),h.cross(u),n.setXYZ(d+0,h.x,h.y,h.z),n.setXYZ(d+1,h.x,h.y,h.z),n.setXYZ(d+2,h.x,h.y,h.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,n=t.count;e<n;e++)Ge.fromBufferAttribute(t,e),Ge.normalize(),t.setXYZ(e,Ge.x,Ge.y,Ge.z)}toNonIndexed(){function t(o,l){const c=o.array,h=o.itemSize,u=o.normalized,d=new c.constructor(l.length*h);let f=0,g=0;for(let _=0,m=l.length;_<m;_++){o.isInterleavedBufferAttribute?f=l[_]*o.data.stride+o.offset:f=l[_]*h;for(let p=0;p<h;p++)d[g++]=c[f++]}return new ui(d,h,u)}if(this.index===null)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new fn,n=this.index.array,s=this.attributes;for(const o in s){const l=s[o],c=t(l,n);e.setAttribute(o,c)}const r=this.morphAttributes;for(const o in r){const l=[],c=r[o];for(let h=0,u=c.length;h<u;h++){const d=c[h],f=t(d,n);l.push(f)}e.morphAttributes[o]=l}e.morphTargetsRelative=this.morphTargetsRelative;const a=this.groups;for(let o=0,l=a.length;o<l;o++){const c=a[o];e.addGroup(c.start,c.count,c.materialIndex)}return e}toJSON(){const t={metadata:{version:4.6,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0){const l=this.parameters;for(const c in l)l[c]!==void 0&&(t[c]=l[c]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const n=this.attributes;for(const l in n){const c=n[l];t.data.attributes[l]=c.toJSON(t.data)}const s={};let r=!1;for(const l in this.morphAttributes){const c=this.morphAttributes[l],h=[];for(let u=0,d=c.length;u<d;u++){const f=c[u];h.push(f.toJSON(t.data))}h.length>0&&(s[l]=h,r=!0)}r&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const a=this.groups;a.length>0&&(t.data.groups=JSON.parse(JSON.stringify(a)));const o=this.boundingSphere;return o!==null&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;n!==null&&this.setIndex(n.clone(e));const s=t.attributes;for(const c in s){const h=s[c];this.setAttribute(c,h.clone(e))}const r=t.morphAttributes;for(const c in r){const h=[],u=r[c];for(let d=0,f=u.length;d<f;d++)h.push(u[d].clone(e));this.morphAttributes[c]=h}this.morphTargetsRelative=t.morphTargetsRelative;const a=t.groups;for(let c=0,h=a.length;c<h;c++){const u=a[c];this.addGroup(u.start,u.count,u.materialIndex)}const o=t.boundingBox;o!==null&&(this.boundingBox=o.clone());const l=t.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Ru=new fe,fs=new Mh,wa=new yh,Pu=new R,Ea=new R,Ta=new R,Aa=new R,Ml=new R,Ca=new R,Lu=new R,Ra=new R;class yt extends Qe{constructor(t=new fn,e=new dn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),t.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),t.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const e=this.geometry.morphAttributes,n=Object.keys(e);if(n.length>0){const s=e[n[0]];if(s!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,a=s.length;r<a;r++){const o=s[r].name||String(r);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=r}}}}getVertexPosition(t,e){const n=this.geometry,s=n.attributes.position,r=n.morphAttributes.position,a=n.morphTargetsRelative;e.fromBufferAttribute(s,t);const o=this.morphTargetInfluences;if(r&&o){Ca.set(0,0,0);for(let l=0,c=r.length;l<c;l++){const h=o[l],u=r[l];h!==0&&(Ml.fromBufferAttribute(u,t),a?Ca.addScaledVector(Ml,h):Ca.addScaledVector(Ml.sub(e),h))}e.add(Ca)}return e}raycast(t,e){const n=this.geometry,s=this.material,r=this.matrixWorld;s!==void 0&&(n.boundingSphere===null&&n.computeBoundingSphere(),wa.copy(n.boundingSphere),wa.applyMatrix4(r),fs.copy(t.ray).recast(t.near),!(wa.containsPoint(fs.origin)===!1&&(fs.intersectSphere(wa,Pu)===null||fs.origin.distanceToSquared(Pu)>(t.far-t.near)**2))&&(Ru.copy(r).invert(),fs.copy(t.ray).applyMatrix4(Ru),!(n.boundingBox!==null&&fs.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(t,e,fs)))}_computeIntersections(t,e,n){let s;const r=this.geometry,a=this.material,o=r.index,l=r.attributes.position,c=r.attributes.uv,h=r.attributes.uv1,u=r.attributes.normal,d=r.groups,f=r.drawRange;if(o!==null)if(Array.isArray(a))for(let g=0,_=d.length;g<_;g++){const m=d[g],p=a[m.materialIndex],y=Math.max(m.start,f.start),x=Math.min(o.count,Math.min(m.start+m.count,f.start+f.count));for(let S=y,L=x;S<L;S+=3){const T=o.getX(S),E=o.getX(S+1),P=o.getX(S+2);s=Pa(this,p,t,n,c,h,u,T,E,P),s&&(s.faceIndex=Math.floor(S/3),s.face.materialIndex=m.materialIndex,e.push(s))}}else{const g=Math.max(0,f.start),_=Math.min(o.count,f.start+f.count);for(let m=g,p=_;m<p;m+=3){const y=o.getX(m),x=o.getX(m+1),S=o.getX(m+2);s=Pa(this,a,t,n,c,h,u,y,x,S),s&&(s.faceIndex=Math.floor(m/3),e.push(s))}}else if(l!==void 0)if(Array.isArray(a))for(let g=0,_=d.length;g<_;g++){const m=d[g],p=a[m.materialIndex],y=Math.max(m.start,f.start),x=Math.min(l.count,Math.min(m.start+m.count,f.start+f.count));for(let S=y,L=x;S<L;S+=3){const T=S,E=S+1,P=S+2;s=Pa(this,p,t,n,c,h,u,T,E,P),s&&(s.faceIndex=Math.floor(S/3),s.face.materialIndex=m.materialIndex,e.push(s))}}else{const g=Math.max(0,f.start),_=Math.min(l.count,f.start+f.count);for(let m=g,p=_;m<p;m+=3){const y=m,x=m+1,S=m+2;s=Pa(this,a,t,n,c,h,u,y,x,S),s&&(s.faceIndex=Math.floor(m/3),e.push(s))}}}}function D0(i,t,e,n,s,r,a,o){let l;if(t.side===un?l=n.intersectTriangle(a,r,s,!0,o):l=n.intersectTriangle(s,r,a,t.side===os,o),l===null)return null;Ra.copy(o),Ra.applyMatrix4(i.matrixWorld);const c=e.ray.origin.distanceTo(Ra);return c<e.near||c>e.far?null:{distance:c,point:Ra.clone(),object:i}}function Pa(i,t,e,n,s,r,a,o,l,c){i.getVertexPosition(o,Ea),i.getVertexPosition(l,Ta),i.getVertexPosition(c,Aa);const h=D0(i,t,e,n,Ea,Ta,Aa,Lu);if(h){const u=new R;Yn.getBarycoord(Lu,Ea,Ta,Aa,u),s&&(h.uv=Yn.getInterpolatedAttribute(s,o,l,c,u,new rt)),r&&(h.uv1=Yn.getInterpolatedAttribute(r,o,l,c,u,new rt)),a&&(h.normal=Yn.getInterpolatedAttribute(a,o,l,c,u,new R),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const d={a:o,b:l,c,normal:new R,materialIndex:0};Yn.getNormal(Ea,Ta,Aa,d.normal),h.face=d,h.barycoord=u}return h}class Ze extends fn{constructor(t=1,e=1,n=1,s=1,r=1,a=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:s,heightSegments:r,depthSegments:a};const o=this;s=Math.floor(s),r=Math.floor(r),a=Math.floor(a);const l=[],c=[],h=[],u=[];let d=0,f=0;g("z","y","x",-1,-1,n,e,t,a,r,0),g("z","y","x",1,-1,n,e,-t,a,r,1),g("x","z","y",1,1,t,n,e,s,a,2),g("x","z","y",1,-1,t,n,-e,s,a,3),g("x","y","z",1,-1,t,e,n,s,r,4),g("x","y","z",-1,-1,t,e,-n,s,r,5),this.setIndex(l),this.setAttribute("position",new he(c,3)),this.setAttribute("normal",new he(h,3)),this.setAttribute("uv",new he(u,2));function g(_,m,p,y,x,S,L,T,E,P,U){const v=S/E,b=L/P,I=S/2,O=L/2,$=T/2,K=E+1,z=P+1;let Z=0,V=0;const at=new R;for(let ct=0;ct<z;ct++){const _t=ct*b-O;for(let $t=0;$t<K;$t++){const Jt=$t*v-I;at[_]=Jt*y,at[m]=_t*x,at[p]=$,c.push(at.x,at.y,at.z),at[_]=0,at[m]=0,at[p]=T>0?1:-1,h.push(at.x,at.y,at.z),u.push($t/E),u.push(1-ct/P),Z+=1}}for(let ct=0;ct<P;ct++)for(let _t=0;_t<E;_t++){const $t=d+_t+K*ct,Jt=d+_t+K*(ct+1),X=d+(_t+1)+K*(ct+1),et=d+(_t+1)+K*ct;l.push($t,Jt,et),l.push(Jt,X,et),V+=6}o.addGroup(f,V,U),f+=V,d+=Z}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ze(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function br(i){const t={};for(const e in i){t[e]={};for(const n in i[e]){const s=i[e][n];s&&(s.isColor||s.isMatrix3||s.isMatrix4||s.isVector2||s.isVector3||s.isVector4||s.isTexture||s.isQuaternion)?s.isRenderTargetTexture?(console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[e][n]=null):t[e][n]=s.clone():Array.isArray(s)?t[e][n]=s.slice():t[e][n]=s}}return t}function ln(i){const t={};for(let e=0;e<i.length;e++){const n=br(i[e]);for(const s in n)t[s]=n[s]}return t}function I0(i){const t=[];for(let e=0;e<i.length;e++)t.push(i[e].clone());return t}function Bf(i){const t=i.getRenderTarget();return t===null?i.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:oe.workingColorSpace}const Qi={clone:br,merge:ln};var k0=`void main() {
7
7
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
8
- }`,o0=`void main() {
8
+ }`,N0=`void main() {
9
9
  gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
10
- }`;class Je extends Ii{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=a0,this.fragmentShader=o0,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,t!==void 0&&this.setValues(t)}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=fr(t.uniforms),this.uniformsGroups=r0(t.uniformsGroups),this.defines=Object.assign({},t.defines),this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.fog=t.fog,this.lights=t.lights,this.clipping=t.clipping,this.extensions=Object.assign({},t.extensions),this.glslVersion=t.glslVersion,this}toJSON(t){const e=super.toJSON(t);e.glslVersion=this.glslVersion,e.uniforms={};for(const s in this.uniforms){const a=this.uniforms[s].value;a&&a.isTexture?e.uniforms[s]={type:"t",value:a.toJSON(t).uuid}:a&&a.isColor?e.uniforms[s]={type:"c",value:a.getHex()}:a&&a.isVector2?e.uniforms[s]={type:"v2",value:a.toArray()}:a&&a.isVector3?e.uniforms[s]={type:"v3",value:a.toArray()}:a&&a.isVector4?e.uniforms[s]={type:"v4",value:a.toArray()}:a&&a.isMatrix3?e.uniforms[s]={type:"m3",value:a.toArray()}:a&&a.isMatrix4?e.uniforms[s]={type:"m4",value:a.toArray()}:e.uniforms[s]={value:a}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const n={};for(const s in this.extensions)this.extensions[s]===!0&&(n[s]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}}class vf extends Ye{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new fe,this.projectionMatrix=new fe,this.projectionMatrixInverse=new fe,this.coordinateSystem=Ei}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}const Hi=new R,fu=new rt,pu=new rt;class wn extends vf{constructor(t=50,e=1,n=.1,s=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,this.far=s,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=Zr*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(zr*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return Zr*2*Math.atan(Math.tan(zr*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,n){Hi.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Hi.x,Hi.y).multiplyScalar(-t/Hi.z),Hi.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(Hi.x,Hi.y).multiplyScalar(-t/Hi.z)}getViewSize(t,e){return this.getViewBounds(t,fu,pu),e.subVectors(pu,fu)}setViewOffset(t,e,n,s,r,a){this.aspect=t/e,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=s,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(zr*.5*this.fov)/this.zoom,n=2*e,s=this.aspect*n,r=-.5*s;const a=this.view;if(this.view!==null&&this.view.enabled){const l=a.fullWidth,c=a.fullHeight;r+=a.offsetX*s/l,e-=a.offsetY*n/c,s*=a.width/l,n*=a.height/c}const o=this.filmOffset;o!==0&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+s,e,e-n,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const zs=-90,Bs=1;class l0 extends Ye{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const s=new wn(zs,Bs,t,e);s.layers=this.layers,this.add(s);const r=new wn(zs,Bs,t,e);r.layers=this.layers,this.add(r);const a=new wn(zs,Bs,t,e);a.layers=this.layers,this.add(a);const o=new wn(zs,Bs,t,e);o.layers=this.layers,this.add(o);const l=new wn(zs,Bs,t,e);l.layers=this.layers,this.add(l);const c=new wn(zs,Bs,t,e);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[n,s,r,a,o,l]=e;for(const c of e)this.remove(c);if(t===Ei)n.up.set(0,1,0),n.lookAt(1,0,0),s.up.set(0,1,0),s.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(t===fo)n.up.set(0,-1,0),n.lookAt(-1,0,0),s.up.set(0,-1,0),s.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(const c of e)this.add(c),c.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:s}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,a,o,l,c,h]=this.children,u=t.getRenderTarget(),d=t.getActiveCubeFace(),f=t.getActiveMipmapLevel(),g=t.xr.enabled;t.xr.enabled=!1;const _=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,s),t.render(e,r),t.setRenderTarget(n,1,s),t.render(e,a),t.setRenderTarget(n,2,s),t.render(e,o),t.setRenderTarget(n,3,s),t.render(e,l),t.setRenderTarget(n,4,s),t.render(e,c),n.texture.generateMipmaps=_,t.setRenderTarget(n,5,s),t.render(e,h),t.setRenderTarget(u,d,f),t.xr.enabled=g,n.texture.needsPMREMUpdate=!0}}class _f extends en{constructor(t,e,n,s,r,a,o,l,c,h){t=t!==void 0?t:[],e=e!==void 0?e:ur,super(t,e,n,s,r,a,o,l,c,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class c0 extends Yn{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const n={width:t,height:t,depth:1},s=[n,n,n,n,n,n];this.texture=new _f(s,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=e.generateMipmaps!==void 0?e.generateMipmaps:!1,this.texture.minFilter=e.minFilter!==void 0?e.minFilter:Wn}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const n={uniforms:{tEquirect:{value:null}},vertexShader:`
10
+ }`;class nn extends Fi{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=k0,this.fragmentShader=N0,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,t!==void 0&&this.setValues(t)}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=br(t.uniforms),this.uniformsGroups=I0(t.uniformsGroups),this.defines=Object.assign({},t.defines),this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.fog=t.fog,this.lights=t.lights,this.clipping=t.clipping,this.extensions=Object.assign({},t.extensions),this.glslVersion=t.glslVersion,this}toJSON(t){const e=super.toJSON(t);e.glslVersion=this.glslVersion,e.uniforms={};for(const s in this.uniforms){const a=this.uniforms[s].value;a&&a.isTexture?e.uniforms[s]={type:"t",value:a.toJSON(t).uuid}:a&&a.isColor?e.uniforms[s]={type:"c",value:a.getHex()}:a&&a.isVector2?e.uniforms[s]={type:"v2",value:a.toArray()}:a&&a.isVector3?e.uniforms[s]={type:"v3",value:a.toArray()}:a&&a.isVector4?e.uniforms[s]={type:"v4",value:a.toArray()}:a&&a.isMatrix3?e.uniforms[s]={type:"m3",value:a.toArray()}:a&&a.isMatrix4?e.uniforms[s]={type:"m4",value:a.toArray()}:e.uniforms[s]={value:a}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const n={};for(const s in this.extensions)this.extensions[s]===!0&&(n[s]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}}class Hf extends Qe{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new fe,this.projectionMatrix=new fe,this.projectionMatrixInverse=new fe,this.coordinateSystem=Ri}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}const Xi=new R,Du=new rt,Iu=new rt;class Cn extends Hf{constructor(t=50,e=1,n=.1,s=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,this.far=s,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=aa*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(qr*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return aa*2*Math.atan(Math.tan(qr*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,n){Xi.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Xi.x,Xi.y).multiplyScalar(-t/Xi.z),Xi.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(Xi.x,Xi.y).multiplyScalar(-t/Xi.z)}getViewSize(t,e){return this.getViewBounds(t,Du,Iu),e.subVectors(Iu,Du)}setViewOffset(t,e,n,s,r,a){this.aspect=t/e,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=s,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(qr*.5*this.fov)/this.zoom,n=2*e,s=this.aspect*n,r=-.5*s;const a=this.view;if(this.view!==null&&this.view.enabled){const l=a.fullWidth,c=a.fullHeight;r+=a.offsetX*s/l,e-=a.offsetY*n/c,s*=a.width/l,n*=a.height/c}const o=this.filmOffset;o!==0&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+s,e,e-n,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const js=-90,qs=1;class U0 extends Qe{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const s=new Cn(js,qs,t,e);s.layers=this.layers,this.add(s);const r=new Cn(js,qs,t,e);r.layers=this.layers,this.add(r);const a=new Cn(js,qs,t,e);a.layers=this.layers,this.add(a);const o=new Cn(js,qs,t,e);o.layers=this.layers,this.add(o);const l=new Cn(js,qs,t,e);l.layers=this.layers,this.add(l);const c=new Cn(js,qs,t,e);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[n,s,r,a,o,l]=e;for(const c of e)this.remove(c);if(t===Ri)n.up.set(0,1,0),n.lookAt(1,0,0),s.up.set(0,1,0),s.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(t===So)n.up.set(0,-1,0),n.lookAt(-1,0,0),s.up.set(0,-1,0),s.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(const c of e)this.add(c),c.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:s}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,a,o,l,c,h]=this.children,u=t.getRenderTarget(),d=t.getActiveCubeFace(),f=t.getActiveMipmapLevel(),g=t.xr.enabled;t.xr.enabled=!1;const _=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,s),t.render(e,r),t.setRenderTarget(n,1,s),t.render(e,a),t.setRenderTarget(n,2,s),t.render(e,o),t.setRenderTarget(n,3,s),t.render(e,l),t.setRenderTarget(n,4,s),t.render(e,c),n.texture.generateMipmaps=_,t.setRenderTarget(n,5,s),t.render(e,h),t.setRenderTarget(u,d,f),t.xr.enabled=g,n.texture.needsPMREMUpdate=!0}}class Vf extends an{constructor(t,e,n,s,r,a,o,l,c,h){t=t!==void 0?t:[],e=e!==void 0?e:yr,super(t,e,n,s,r,a,o,l,c,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class O0 extends Qn{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const n={width:t,height:t,depth:1},s=[n,n,n,n,n,n];this.texture=new Vf(s,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=e.generateMipmaps!==void 0?e.generateMipmaps:!1,this.texture.minFilter=e.minFilter!==void 0?e.minFilter:qn}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const n={uniforms:{tEquirect:{value:null}},vertexShader:`
11
11
 
12
12
  varying vec3 vWorldDirection;
13
13
 
@@ -42,9 +42,9 @@ var _p=Object.defineProperty;var xp=(i,t,e)=>t in i?_p(i,t,{enumerable:!0,config
42
42
  gl_FragColor = texture2D( tEquirect, sampleUV );
43
43
 
44
44
  }
45
- `},s=new qe(5,5,5),r=new Je({name:"CubemapFromEquirect",uniforms:fr(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:on,blending:Xe});r.uniforms.tEquirect.value=e;const a=new yt(s,r),o=e.minFilter;return e.minFilter===gs&&(e.minFilter=Wn),new l0(1,10,this).update(t,a),e.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(t,e,n,s){const r=t.getRenderTarget();for(let a=0;a<6;a++)t.setRenderTarget(this,a),t.clear(e,n,s);t.setRenderTarget(r)}}const hl=new R,h0=new R,u0=new Xt;class $i{constructor(t=new R(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,s){return this.normal.set(t,e,n),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const s=hl.subVectors(n,e).cross(h0.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const n=t.delta(hl),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/s;return r<0||r>1?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const n=e||u0.getNormalMatrix(t),s=this.coplanarPoint(hl).applyMatrix4(t),r=this.normal.applyMatrix3(n).normalize();return this.constant=-s.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const ls=new sh,ba=new R;class oh{constructor(t=new $i,e=new $i,n=new $i,s=new $i,r=new $i,a=new $i){this.planes=[t,e,n,s,r,a]}set(t,e,n,s,r,a){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(n),o[3].copy(s),o[4].copy(r),o[5].copy(a),this}copy(t){const e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=Ei){const n=this.planes,s=t.elements,r=s[0],a=s[1],o=s[2],l=s[3],c=s[4],h=s[5],u=s[6],d=s[7],f=s[8],g=s[9],_=s[10],m=s[11],p=s[12],y=s[13],x=s[14],S=s[15];if(n[0].setComponents(l-r,d-c,m-f,S-p).normalize(),n[1].setComponents(l+r,d+c,m+f,S+p).normalize(),n[2].setComponents(l+a,d+h,m+g,S+y).normalize(),n[3].setComponents(l-a,d-h,m-g,S-y).normalize(),n[4].setComponents(l-o,d-u,m-_,S-x).normalize(),e===Ei)n[5].setComponents(l+o,d+u,m+_,S+x).normalize();else if(e===fo)n[5].setComponents(o,u,_,x).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);return this}intersectsObject(t){if(t.boundingSphere!==void 0)t.boundingSphere===null&&t.computeBoundingSphere(),ls.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),ls.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(ls)}intersectsSprite(t){return ls.center.set(0,0,0),ls.radius=.7071067811865476,ls.applyMatrix4(t.matrixWorld),this.intersectsSphere(ls)}intersectsSphere(t){const e=this.planes,n=t.center,s=-t.radius;for(let r=0;r<6;r++)if(e[r].distanceToPoint(n)<s)return!1;return!0}intersectsBox(t){const e=this.planes;for(let n=0;n<6;n++){const s=e[n];if(ba.x=s.normal.x>0?t.max.x:t.min.x,ba.y=s.normal.y>0?t.max.y:t.min.y,ba.z=s.normal.z>0?t.max.z:t.min.z,s.distanceToPoint(ba)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}function xf(){let i=null,t=!1,e=null,n=null;function s(r,a){e(r,a),n=i.requestAnimationFrame(s)}return{start:function(){t!==!0&&e!==null&&(n=i.requestAnimationFrame(s),t=!0)},stop:function(){i.cancelAnimationFrame(n),t=!1},setAnimationLoop:function(r){e=r},setContext:function(r){i=r}}}function d0(i){const t=new WeakMap;function e(o,l){const c=o.array,h=o.usage,u=c.byteLength,d=i.createBuffer();i.bindBuffer(l,d),i.bufferData(l,c,h),o.onUploadCallback();let f;if(c instanceof Float32Array)f=i.FLOAT;else if(c instanceof Uint16Array)o.isFloat16BufferAttribute?f=i.HALF_FLOAT:f=i.UNSIGNED_SHORT;else if(c instanceof Int16Array)f=i.SHORT;else if(c instanceof Uint32Array)f=i.UNSIGNED_INT;else if(c instanceof Int32Array)f=i.INT;else if(c instanceof Int8Array)f=i.BYTE;else if(c instanceof Uint8Array)f=i.UNSIGNED_BYTE;else if(c instanceof Uint8ClampedArray)f=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+c);return{buffer:d,type:f,bytesPerElement:c.BYTES_PER_ELEMENT,version:o.version,size:u}}function n(o,l,c){const h=l.array,u=l.updateRanges;if(i.bindBuffer(c,o),u.length===0)i.bufferSubData(c,0,h);else{u.sort((f,g)=>f.start-g.start);let d=0;for(let f=1;f<u.length;f++){const g=u[d],_=u[f];_.start<=g.start+g.count+1?g.count=Math.max(g.count,_.start+_.count-g.start):(++d,u[d]=_)}u.length=d+1;for(let f=0,g=u.length;f<g;f++){const _=u[f];i.bufferSubData(c,_.start*h.BYTES_PER_ELEMENT,h,_.start,_.count)}l.clearUpdateRanges()}l.onUploadCallback()}function s(o){return o.isInterleavedBufferAttribute&&(o=o.data),t.get(o)}function r(o){o.isInterleavedBufferAttribute&&(o=o.data);const l=t.get(o);l&&(i.deleteBuffer(l.buffer),t.delete(o))}function a(o,l){if(o.isInterleavedBufferAttribute&&(o=o.data),o.isGLBufferAttribute){const h=t.get(o);(!h||h.version<o.version)&&t.set(o,{buffer:o.buffer,type:o.type,bytesPerElement:o.elementSize,version:o.version});return}const c=t.get(o);if(c===void 0)t.set(o,e(o,l));else if(c.version<o.version){if(c.size!==o.array.byteLength)throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");n(c.buffer,o,l),c.version=o.version}}return{get:s,remove:r,update:a}}class di extends cn{constructor(t=1,e=1,n=1,s=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:n,heightSegments:s};const r=t/2,a=e/2,o=Math.floor(n),l=Math.floor(s),c=o+1,h=l+1,u=t/o,d=e/l,f=[],g=[],_=[],m=[];for(let p=0;p<h;p++){const y=p*d-a;for(let x=0;x<c;x++){const S=x*u-r;g.push(S,-y,0),_.push(0,0,1),m.push(x/o),m.push(1-p/l)}}for(let p=0;p<l;p++)for(let y=0;y<o;y++){const x=y+c*p,S=y+c*(p+1),L=y+1+c*(p+1),T=y+1+c*p;f.push(x,S,T),f.push(S,L,T)}this.setIndex(f),this.setAttribute("position",new he(g,3)),this.setAttribute("normal",new he(_,3)),this.setAttribute("uv",new he(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new di(t.width,t.height,t.widthSegments,t.heightSegments)}}var f0=`#ifdef USE_ALPHAHASH
45
+ `},s=new Ze(5,5,5),r=new nn({name:"CubemapFromEquirect",uniforms:br(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:un,blending:Ye});r.uniforms.tEquirect.value=e;const a=new yt(s,r),o=e.minFilter;return e.minFilter===bs&&(e.minFilter=qn),new U0(1,10,this).update(t,a),e.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(t,e,n,s){const r=t.getRenderTarget();for(let a=0;a<6;a++)t.setRenderTarget(this,a),t.clear(e,n,s);t.setRenderTarget(r)}}const bl=new R,F0=new R,z0=new Xt;class Ki{constructor(t=new R(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,s){return this.normal.set(t,e,n),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const s=bl.subVectors(n,e).cross(F0.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const n=t.delta(bl),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/s;return r<0||r>1?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const n=e||z0.getNormalMatrix(t),s=this.coplanarPoint(bl).applyMatrix4(t),r=this.normal.applyMatrix3(n).normalize();return this.constant=-s.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const ps=new yh,La=new R;class Sh{constructor(t=new Ki,e=new Ki,n=new Ki,s=new Ki,r=new Ki,a=new Ki){this.planes=[t,e,n,s,r,a]}set(t,e,n,s,r,a){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(n),o[3].copy(s),o[4].copy(r),o[5].copy(a),this}copy(t){const e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=Ri){const n=this.planes,s=t.elements,r=s[0],a=s[1],o=s[2],l=s[3],c=s[4],h=s[5],u=s[6],d=s[7],f=s[8],g=s[9],_=s[10],m=s[11],p=s[12],y=s[13],x=s[14],S=s[15];if(n[0].setComponents(l-r,d-c,m-f,S-p).normalize(),n[1].setComponents(l+r,d+c,m+f,S+p).normalize(),n[2].setComponents(l+a,d+h,m+g,S+y).normalize(),n[3].setComponents(l-a,d-h,m-g,S-y).normalize(),n[4].setComponents(l-o,d-u,m-_,S-x).normalize(),e===Ri)n[5].setComponents(l+o,d+u,m+_,S+x).normalize();else if(e===So)n[5].setComponents(o,u,_,x).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);return this}intersectsObject(t){if(t.boundingSphere!==void 0)t.boundingSphere===null&&t.computeBoundingSphere(),ps.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),ps.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(ps)}intersectsSprite(t){return ps.center.set(0,0,0),ps.radius=.7071067811865476,ps.applyMatrix4(t.matrixWorld),this.intersectsSphere(ps)}intersectsSphere(t){const e=this.planes,n=t.center,s=-t.radius;for(let r=0;r<6;r++)if(e[r].distanceToPoint(n)<s)return!1;return!0}intersectsBox(t){const e=this.planes;for(let n=0;n<6;n++){const s=e[n];if(La.x=s.normal.x>0?t.max.x:t.min.x,La.y=s.normal.y>0?t.max.y:t.min.y,La.z=s.normal.z>0?t.max.z:t.min.z,s.distanceToPoint(La)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}function Gf(){let i=null,t=!1,e=null,n=null;function s(r,a){e(r,a),n=i.requestAnimationFrame(s)}return{start:function(){t!==!0&&e!==null&&(n=i.requestAnimationFrame(s),t=!0)},stop:function(){i.cancelAnimationFrame(n),t=!1},setAnimationLoop:function(r){e=r},setContext:function(r){i=r}}}function B0(i){const t=new WeakMap;function e(o,l){const c=o.array,h=o.usage,u=c.byteLength,d=i.createBuffer();i.bindBuffer(l,d),i.bufferData(l,c,h),o.onUploadCallback();let f;if(c instanceof Float32Array)f=i.FLOAT;else if(c instanceof Uint16Array)o.isFloat16BufferAttribute?f=i.HALF_FLOAT:f=i.UNSIGNED_SHORT;else if(c instanceof Int16Array)f=i.SHORT;else if(c instanceof Uint32Array)f=i.UNSIGNED_INT;else if(c instanceof Int32Array)f=i.INT;else if(c instanceof Int8Array)f=i.BYTE;else if(c instanceof Uint8Array)f=i.UNSIGNED_BYTE;else if(c instanceof Uint8ClampedArray)f=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+c);return{buffer:d,type:f,bytesPerElement:c.BYTES_PER_ELEMENT,version:o.version,size:u}}function n(o,l,c){const h=l.array,u=l.updateRanges;if(i.bindBuffer(c,o),u.length===0)i.bufferSubData(c,0,h);else{u.sort((f,g)=>f.start-g.start);let d=0;for(let f=1;f<u.length;f++){const g=u[d],_=u[f];_.start<=g.start+g.count+1?g.count=Math.max(g.count,_.start+_.count-g.start):(++d,u[d]=_)}u.length=d+1;for(let f=0,g=u.length;f<g;f++){const _=u[f];i.bufferSubData(c,_.start*h.BYTES_PER_ELEMENT,h,_.start,_.count)}l.clearUpdateRanges()}l.onUploadCallback()}function s(o){return o.isInterleavedBufferAttribute&&(o=o.data),t.get(o)}function r(o){o.isInterleavedBufferAttribute&&(o=o.data);const l=t.get(o);l&&(i.deleteBuffer(l.buffer),t.delete(o))}function a(o,l){if(o.isInterleavedBufferAttribute&&(o=o.data),o.isGLBufferAttribute){const h=t.get(o);(!h||h.version<o.version)&&t.set(o,{buffer:o.buffer,type:o.type,bytesPerElement:o.elementSize,version:o.version});return}const c=t.get(o);if(c===void 0)t.set(o,e(o,l));else if(c.version<o.version){if(c.size!==o.array.byteLength)throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");n(c.buffer,o,l),c.version=o.version}}return{get:s,remove:r,update:a}}class gi extends fn{constructor(t=1,e=1,n=1,s=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:n,heightSegments:s};const r=t/2,a=e/2,o=Math.floor(n),l=Math.floor(s),c=o+1,h=l+1,u=t/o,d=e/l,f=[],g=[],_=[],m=[];for(let p=0;p<h;p++){const y=p*d-a;for(let x=0;x<c;x++){const S=x*u-r;g.push(S,-y,0),_.push(0,0,1),m.push(x/o),m.push(1-p/l)}}for(let p=0;p<l;p++)for(let y=0;y<o;y++){const x=y+c*p,S=y+c*(p+1),L=y+1+c*(p+1),T=y+1+c*p;f.push(x,S,T),f.push(S,L,T)}this.setIndex(f),this.setAttribute("position",new he(g,3)),this.setAttribute("normal",new he(_,3)),this.setAttribute("uv",new he(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new gi(t.width,t.height,t.widthSegments,t.heightSegments)}}var H0=`#ifdef USE_ALPHAHASH
46
46
  if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
47
- #endif`,p0=`#ifdef USE_ALPHAHASH
47
+ #endif`,V0=`#ifdef USE_ALPHAHASH
48
48
  const float ALPHA_HASH_SCALE = 0.05;
49
49
  float hash2D( vec2 value ) {
50
50
  return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
@@ -79,20 +79,20 @@ var _p=Object.defineProperty;var xp=(i,t,e)=>t in i?_p(i,t,{enumerable:!0,config
79
79
  : cases.z;
80
80
  return clamp( threshold , 1.0e-6, 1.0 );
81
81
  }
82
- #endif`,m0=`#ifdef USE_ALPHAMAP
82
+ #endif`,G0=`#ifdef USE_ALPHAMAP
83
83
  diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
84
- #endif`,g0=`#ifdef USE_ALPHAMAP
84
+ #endif`,$0=`#ifdef USE_ALPHAMAP
85
85
  uniform sampler2D alphaMap;
86
- #endif`,v0=`#ifdef USE_ALPHATEST
86
+ #endif`,W0=`#ifdef USE_ALPHATEST
87
87
  #ifdef ALPHA_TO_COVERAGE
88
88
  diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
89
89
  if ( diffuseColor.a == 0.0 ) discard;
90
90
  #else
91
91
  if ( diffuseColor.a < alphaTest ) discard;
92
92
  #endif
93
- #endif`,_0=`#ifdef USE_ALPHATEST
93
+ #endif`,X0=`#ifdef USE_ALPHATEST
94
94
  uniform float alphaTest;
95
- #endif`,x0=`#ifdef USE_AOMAP
95
+ #endif`,j0=`#ifdef USE_AOMAP
96
96
  float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
97
97
  reflectedLight.indirectDiffuse *= ambientOcclusion;
98
98
  #if defined( USE_CLEARCOAT )
@@ -105,10 +105,10 @@ var _p=Object.defineProperty;var xp=(i,t,e)=>t in i?_p(i,t,{enumerable:!0,config
105
105
  float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
106
106
  reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
107
107
  #endif
108
- #endif`,y0=`#ifdef USE_AOMAP
108
+ #endif`,q0=`#ifdef USE_AOMAP
109
109
  uniform sampler2D aoMap;
110
110
  uniform float aoMapIntensity;
111
- #endif`,M0=`#ifdef USE_BATCHING
111
+ #endif`,Y0=`#ifdef USE_BATCHING
112
112
  #if ! defined( GL_ANGLE_multi_draw )
113
113
  #define gl_DrawID _gl_DrawID
114
114
  uniform int _gl_DrawID;
@@ -142,15 +142,15 @@ var _p=Object.defineProperty;var xp=(i,t,e)=>t in i?_p(i,t,{enumerable:!0,config
142
142
  int y = j / size;
143
143
  return texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;
144
144
  }
145
- #endif`,b0=`#ifdef USE_BATCHING
145
+ #endif`,K0=`#ifdef USE_BATCHING
146
146
  mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
147
- #endif`,S0=`vec3 transformed = vec3( position );
147
+ #endif`,Z0=`vec3 transformed = vec3( position );
148
148
  #ifdef USE_ALPHAHASH
149
149
  vPosition = vec3( position );
150
- #endif`,w0=`vec3 objectNormal = vec3( normal );
150
+ #endif`,J0=`vec3 objectNormal = vec3( normal );
151
151
  #ifdef USE_TANGENT
152
152
  vec3 objectTangent = vec3( tangent.xyz );
153
- #endif`,E0=`float G_BlinnPhong_Implicit( ) {
153
+ #endif`,Q0=`float G_BlinnPhong_Implicit( ) {
154
154
  return 0.25;
155
155
  }
156
156
  float D_BlinnPhong( const in float shininess, const in float dotNH ) {
@@ -164,7 +164,7 @@ vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in ve
164
164
  float G = G_BlinnPhong_Implicit( );
165
165
  float D = D_BlinnPhong( shininess, dotNH );
166
166
  return F * ( G * D );
167
- } // validated`,T0=`#ifdef USE_IRIDESCENCE
167
+ } // validated`,tg=`#ifdef USE_IRIDESCENCE
168
168
  const mat3 XYZ_TO_REC709 = mat3(
169
169
  3.2404542, -0.9692660, 0.0556434,
170
170
  -1.5371385, 1.8760108, -0.2040259,
@@ -227,7 +227,7 @@ vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in ve
227
227
  }
228
228
  return max( I, vec3( 0.0 ) );
229
229
  }
230
- #endif`,A0=`#ifdef USE_BUMPMAP
230
+ #endif`,eg=`#ifdef USE_BUMPMAP
231
231
  uniform sampler2D bumpMap;
232
232
  uniform float bumpScale;
233
233
  vec2 dHdxy_fwd() {
@@ -248,7 +248,7 @@ vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in ve
248
248
  vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
249
249
  return normalize( abs( fDet ) * surf_norm - vGrad );
250
250
  }
251
- #endif`,C0=`#if NUM_CLIPPING_PLANES > 0
251
+ #endif`,ng=`#if NUM_CLIPPING_PLANES > 0
252
252
  vec4 plane;
253
253
  #ifdef ALPHA_TO_COVERAGE
254
254
  float distanceToPlane, distanceGradient;
@@ -294,26 +294,26 @@ vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in ve
294
294
  if ( clipped ) discard;
295
295
  #endif
296
296
  #endif
297
- #endif`,R0=`#if NUM_CLIPPING_PLANES > 0
297
+ #endif`,ig=`#if NUM_CLIPPING_PLANES > 0
298
298
  varying vec3 vClipPosition;
299
299
  uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
300
- #endif`,P0=`#if NUM_CLIPPING_PLANES > 0
300
+ #endif`,sg=`#if NUM_CLIPPING_PLANES > 0
301
301
  varying vec3 vClipPosition;
302
- #endif`,L0=`#if NUM_CLIPPING_PLANES > 0
302
+ #endif`,rg=`#if NUM_CLIPPING_PLANES > 0
303
303
  vClipPosition = - mvPosition.xyz;
304
- #endif`,D0=`#if defined( USE_COLOR_ALPHA )
304
+ #endif`,ag=`#if defined( USE_COLOR_ALPHA )
305
305
  diffuseColor *= vColor;
306
306
  #elif defined( USE_COLOR )
307
307
  diffuseColor.rgb *= vColor;
308
- #endif`,I0=`#if defined( USE_COLOR_ALPHA )
308
+ #endif`,og=`#if defined( USE_COLOR_ALPHA )
309
309
  varying vec4 vColor;
310
310
  #elif defined( USE_COLOR )
311
311
  varying vec3 vColor;
312
- #endif`,k0=`#if defined( USE_COLOR_ALPHA )
312
+ #endif`,lg=`#if defined( USE_COLOR_ALPHA )
313
313
  varying vec4 vColor;
314
314
  #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
315
315
  varying vec3 vColor;
316
- #endif`,N0=`#if defined( USE_COLOR_ALPHA )
316
+ #endif`,cg=`#if defined( USE_COLOR_ALPHA )
317
317
  vColor = vec4( 1.0 );
318
318
  #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
319
319
  vColor = vec3( 1.0 );
@@ -327,7 +327,7 @@ vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in ve
327
327
  #ifdef USE_BATCHING_COLOR
328
328
  vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );
329
329
  vColor.xyz *= batchingColor.xyz;
330
- #endif`,U0=`#define PI 3.141592653589793
330
+ #endif`,hg=`#define PI 3.141592653589793
331
331
  #define PI2 6.283185307179586
332
332
  #define PI_HALF 1.5707963267948966
333
333
  #define RECIPROCAL_PI 0.3183098861837907
@@ -401,7 +401,7 @@ vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
401
401
  float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
402
402
  float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
403
403
  return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
404
- } // validated`,O0=`#ifdef ENVMAP_TYPE_CUBE_UV
404
+ } // validated`,ug=`#ifdef ENVMAP_TYPE_CUBE_UV
405
405
  #define cubeUV_minMipLevel 4.0
406
406
  #define cubeUV_minTileSize 16.0
407
407
  float getFace( vec3 direction ) {
@@ -494,7 +494,7 @@ float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
494
494
  return vec4( mix( color0, color1, mipF ), 1.0 );
495
495
  }
496
496
  }
497
- #endif`,F0=`vec3 transformedNormal = objectNormal;
497
+ #endif`,dg=`vec3 transformedNormal = objectNormal;
498
498
  #ifdef USE_TANGENT
499
499
  vec3 transformedTangent = objectTangent;
500
500
  #endif
@@ -523,18 +523,18 @@ transformedNormal = normalMatrix * transformedNormal;
523
523
  #ifdef FLIP_SIDED
524
524
  transformedTangent = - transformedTangent;
525
525
  #endif
526
- #endif`,z0=`#ifdef USE_DISPLACEMENTMAP
526
+ #endif`,fg=`#ifdef USE_DISPLACEMENTMAP
527
527
  uniform sampler2D displacementMap;
528
528
  uniform float displacementScale;
529
529
  uniform float displacementBias;
530
- #endif`,B0=`#ifdef USE_DISPLACEMENTMAP
530
+ #endif`,pg=`#ifdef USE_DISPLACEMENTMAP
531
531
  transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
532
- #endif`,H0=`#ifdef USE_EMISSIVEMAP
532
+ #endif`,mg=`#ifdef USE_EMISSIVEMAP
533
533
  vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
534
534
  totalEmissiveRadiance *= emissiveColor.rgb;
535
- #endif`,V0=`#ifdef USE_EMISSIVEMAP
535
+ #endif`,gg=`#ifdef USE_EMISSIVEMAP
536
536
  uniform sampler2D emissiveMap;
537
- #endif`,G0="gl_FragColor = linearToOutputTexel( gl_FragColor );",$0=`
537
+ #endif`,vg="gl_FragColor = linearToOutputTexel( gl_FragColor );",_g=`
538
538
  const mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(
539
539
  vec3( 0.8224621, 0.177538, 0.0 ),
540
540
  vec3( 0.0331941, 0.9668058, 0.0 ),
@@ -556,7 +556,7 @@ vec4 LinearTransferOETF( in vec4 value ) {
556
556
  }
557
557
  vec4 sRGBTransferOETF( in vec4 value ) {
558
558
  return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
559
- }`,W0=`#ifdef USE_ENVMAP
559
+ }`,xg=`#ifdef USE_ENVMAP
560
560
  #ifdef ENV_WORLDPOS
561
561
  vec3 cameraToFrag;
562
562
  if ( isOrthographic ) {
@@ -585,7 +585,7 @@ vec4 sRGBTransferOETF( in vec4 value ) {
585
585
  #elif defined( ENVMAP_BLENDING_ADD )
586
586
  outgoingLight += envColor.xyz * specularStrength * reflectivity;
587
587
  #endif
588
- #endif`,X0=`#ifdef USE_ENVMAP
588
+ #endif`,yg=`#ifdef USE_ENVMAP
589
589
  uniform float envMapIntensity;
590
590
  uniform float flipEnvMap;
591
591
  uniform mat3 envMapRotation;
@@ -595,7 +595,7 @@ vec4 sRGBTransferOETF( in vec4 value ) {
595
595
  uniform sampler2D envMap;
596
596
  #endif
597
597
 
598
- #endif`,j0=`#ifdef USE_ENVMAP
598
+ #endif`,Mg=`#ifdef USE_ENVMAP
599
599
  uniform float reflectivity;
600
600
  #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
601
601
  #define ENV_WORLDPOS
@@ -606,7 +606,7 @@ vec4 sRGBTransferOETF( in vec4 value ) {
606
606
  #else
607
607
  varying vec3 vReflect;
608
608
  #endif
609
- #endif`,q0=`#ifdef USE_ENVMAP
609
+ #endif`,bg=`#ifdef USE_ENVMAP
610
610
  #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
611
611
  #define ENV_WORLDPOS
612
612
  #endif
@@ -617,7 +617,7 @@ vec4 sRGBTransferOETF( in vec4 value ) {
617
617
  varying vec3 vReflect;
618
618
  uniform float refractionRatio;
619
619
  #endif
620
- #endif`,Y0=`#ifdef USE_ENVMAP
620
+ #endif`,Sg=`#ifdef USE_ENVMAP
621
621
  #ifdef ENV_WORLDPOS
622
622
  vWorldPosition = worldPosition.xyz;
623
623
  #else
@@ -634,18 +634,18 @@ vec4 sRGBTransferOETF( in vec4 value ) {
634
634
  vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
635
635
  #endif
636
636
  #endif
637
- #endif`,K0=`#ifdef USE_FOG
637
+ #endif`,wg=`#ifdef USE_FOG
638
638
  vFogDepth = - mvPosition.z;
639
- #endif`,Z0=`#ifdef USE_FOG
639
+ #endif`,Eg=`#ifdef USE_FOG
640
640
  varying float vFogDepth;
641
- #endif`,J0=`#ifdef USE_FOG
641
+ #endif`,Tg=`#ifdef USE_FOG
642
642
  #ifdef FOG_EXP2
643
643
  float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
644
644
  #else
645
645
  float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
646
646
  #endif
647
647
  gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
648
- #endif`,Q0=`#ifdef USE_FOG
648
+ #endif`,Ag=`#ifdef USE_FOG
649
649
  uniform vec3 fogColor;
650
650
  varying float vFogDepth;
651
651
  #ifdef FOG_EXP2
@@ -654,7 +654,7 @@ vec4 sRGBTransferOETF( in vec4 value ) {
654
654
  uniform float fogNear;
655
655
  uniform float fogFar;
656
656
  #endif
657
- #endif`,tg=`#ifdef USE_GRADIENTMAP
657
+ #endif`,Cg=`#ifdef USE_GRADIENTMAP
658
658
  uniform sampler2D gradientMap;
659
659
  #endif
660
660
  vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
@@ -666,12 +666,12 @@ vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
666
666
  vec2 fw = fwidth( coord ) * 0.5;
667
667
  return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
668
668
  #endif
669
- }`,eg=`#ifdef USE_LIGHTMAP
669
+ }`,Rg=`#ifdef USE_LIGHTMAP
670
670
  uniform sampler2D lightMap;
671
671
  uniform float lightMapIntensity;
672
- #endif`,ng=`LambertMaterial material;
672
+ #endif`,Pg=`LambertMaterial material;
673
673
  material.diffuseColor = diffuseColor.rgb;
674
- material.specularStrength = specularStrength;`,ig=`varying vec3 vViewPosition;
674
+ material.specularStrength = specularStrength;`,Lg=`varying vec3 vViewPosition;
675
675
  struct LambertMaterial {
676
676
  vec3 diffuseColor;
677
677
  float specularStrength;
@@ -685,7 +685,7 @@ void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometr
685
685
  reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
686
686
  }
687
687
  #define RE_Direct RE_Direct_Lambert
688
- #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,sg=`uniform bool receiveShadow;
688
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,Dg=`uniform bool receiveShadow;
689
689
  uniform vec3 ambientLightColor;
690
690
  #if defined( USE_LIGHT_PROBES )
691
691
  uniform vec3 lightProbe[ 9 ];
@@ -801,7 +801,7 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi
801
801
  vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
802
802
  return irradiance;
803
803
  }
804
- #endif`,rg=`#ifdef USE_ENVMAP
804
+ #endif`,Ig=`#ifdef USE_ENVMAP
805
805
  vec3 getIBLIrradiance( const in vec3 normal ) {
806
806
  #ifdef ENVMAP_TYPE_CUBE_UV
807
807
  vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
@@ -834,8 +834,8 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi
834
834
  #endif
835
835
  }
836
836
  #endif
837
- #endif`,ag=`ToonMaterial material;
838
- material.diffuseColor = diffuseColor.rgb;`,og=`varying vec3 vViewPosition;
837
+ #endif`,kg=`ToonMaterial material;
838
+ material.diffuseColor = diffuseColor.rgb;`,Ng=`varying vec3 vViewPosition;
839
839
  struct ToonMaterial {
840
840
  vec3 diffuseColor;
841
841
  };
@@ -847,11 +847,11 @@ void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPo
847
847
  reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
848
848
  }
849
849
  #define RE_Direct RE_Direct_Toon
850
- #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,lg=`BlinnPhongMaterial material;
850
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,Ug=`BlinnPhongMaterial material;
851
851
  material.diffuseColor = diffuseColor.rgb;
852
852
  material.specularColor = specular;
853
853
  material.specularShininess = shininess;
854
- material.specularStrength = specularStrength;`,cg=`varying vec3 vViewPosition;
854
+ material.specularStrength = specularStrength;`,Og=`varying vec3 vViewPosition;
855
855
  struct BlinnPhongMaterial {
856
856
  vec3 diffuseColor;
857
857
  vec3 specularColor;
@@ -868,7 +868,7 @@ void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geom
868
868
  reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
869
869
  }
870
870
  #define RE_Direct RE_Direct_BlinnPhong
871
- #define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,hg=`PhysicalMaterial material;
871
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,Fg=`PhysicalMaterial material;
872
872
  material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
873
873
  vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
874
874
  float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
@@ -954,7 +954,7 @@ material.roughness = min( material.roughness, 1.0 );
954
954
  material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
955
955
  material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
956
956
  material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
957
- #endif`,ug=`struct PhysicalMaterial {
957
+ #endif`,zg=`struct PhysicalMaterial {
958
958
  vec3 diffuseColor;
959
959
  float roughness;
960
960
  vec3 specularColor;
@@ -1255,7 +1255,7 @@ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradia
1255
1255
  #define RE_IndirectSpecular RE_IndirectSpecular_Physical
1256
1256
  float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
1257
1257
  return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
1258
- }`,dg=`
1258
+ }`,Bg=`
1259
1259
  vec3 geometryPosition = - vViewPosition;
1260
1260
  vec3 geometryNormal = normal;
1261
1261
  vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
@@ -1370,7 +1370,7 @@ IncidentLight directLight;
1370
1370
  #if defined( RE_IndirectSpecular )
1371
1371
  vec3 radiance = vec3( 0.0 );
1372
1372
  vec3 clearcoatRadiance = vec3( 0.0 );
1373
- #endif`,fg=`#if defined( RE_IndirectDiffuse )
1373
+ #endif`,Hg=`#if defined( RE_IndirectDiffuse )
1374
1374
  #ifdef USE_LIGHTMAP
1375
1375
  vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
1376
1376
  vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
@@ -1389,33 +1389,33 @@ IncidentLight directLight;
1389
1389
  #ifdef USE_CLEARCOAT
1390
1390
  clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
1391
1391
  #endif
1392
- #endif`,pg=`#if defined( RE_IndirectDiffuse )
1392
+ #endif`,Vg=`#if defined( RE_IndirectDiffuse )
1393
1393
  RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1394
1394
  #endif
1395
1395
  #if defined( RE_IndirectSpecular )
1396
1396
  RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1397
- #endif`,mg=`#if defined( USE_LOGDEPTHBUF )
1397
+ #endif`,Gg=`#if defined( USE_LOGDEPTHBUF )
1398
1398
  gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
1399
- #endif`,gg=`#if defined( USE_LOGDEPTHBUF )
1399
+ #endif`,$g=`#if defined( USE_LOGDEPTHBUF )
1400
1400
  uniform float logDepthBufFC;
1401
1401
  varying float vFragDepth;
1402
1402
  varying float vIsPerspective;
1403
- #endif`,vg=`#ifdef USE_LOGDEPTHBUF
1403
+ #endif`,Wg=`#ifdef USE_LOGDEPTHBUF
1404
1404
  varying float vFragDepth;
1405
1405
  varying float vIsPerspective;
1406
- #endif`,_g=`#ifdef USE_LOGDEPTHBUF
1406
+ #endif`,Xg=`#ifdef USE_LOGDEPTHBUF
1407
1407
  vFragDepth = 1.0 + gl_Position.w;
1408
1408
  vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
1409
- #endif`,xg=`#ifdef USE_MAP
1409
+ #endif`,jg=`#ifdef USE_MAP
1410
1410
  vec4 sampledDiffuseColor = texture2D( map, vMapUv );
1411
1411
  #ifdef DECODE_VIDEO_TEXTURE
1412
1412
  sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );
1413
1413
 
1414
1414
  #endif
1415
1415
  diffuseColor *= sampledDiffuseColor;
1416
- #endif`,yg=`#ifdef USE_MAP
1416
+ #endif`,qg=`#ifdef USE_MAP
1417
1417
  uniform sampler2D map;
1418
- #endif`,Mg=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
1418
+ #endif`,Yg=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
1419
1419
  #if defined( USE_POINTS_UV )
1420
1420
  vec2 uv = vUv;
1421
1421
  #else
@@ -1427,7 +1427,7 @@ IncidentLight directLight;
1427
1427
  #endif
1428
1428
  #ifdef USE_ALPHAMAP
1429
1429
  diffuseColor.a *= texture2D( alphaMap, uv ).g;
1430
- #endif`,bg=`#if defined( USE_POINTS_UV )
1430
+ #endif`,Kg=`#if defined( USE_POINTS_UV )
1431
1431
  varying vec2 vUv;
1432
1432
  #else
1433
1433
  #if defined( USE_MAP ) || defined( USE_ALPHAMAP )
@@ -1439,19 +1439,19 @@ IncidentLight directLight;
1439
1439
  #endif
1440
1440
  #ifdef USE_ALPHAMAP
1441
1441
  uniform sampler2D alphaMap;
1442
- #endif`,Sg=`float metalnessFactor = metalness;
1442
+ #endif`,Zg=`float metalnessFactor = metalness;
1443
1443
  #ifdef USE_METALNESSMAP
1444
1444
  vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
1445
1445
  metalnessFactor *= texelMetalness.b;
1446
- #endif`,wg=`#ifdef USE_METALNESSMAP
1446
+ #endif`,Jg=`#ifdef USE_METALNESSMAP
1447
1447
  uniform sampler2D metalnessMap;
1448
- #endif`,Eg=`#ifdef USE_INSTANCING_MORPH
1448
+ #endif`,Qg=`#ifdef USE_INSTANCING_MORPH
1449
1449
  float morphTargetInfluences[ MORPHTARGETS_COUNT ];
1450
1450
  float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
1451
1451
  for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1452
1452
  morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
1453
1453
  }
1454
- #endif`,Tg=`#if defined( USE_MORPHCOLORS )
1454
+ #endif`,tv=`#if defined( USE_MORPHCOLORS )
1455
1455
  vColor *= morphTargetBaseInfluence;
1456
1456
  for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1457
1457
  #if defined( USE_COLOR_ALPHA )
@@ -1460,12 +1460,12 @@ IncidentLight directLight;
1460
1460
  if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
1461
1461
  #endif
1462
1462
  }
1463
- #endif`,Ag=`#ifdef USE_MORPHNORMALS
1463
+ #endif`,ev=`#ifdef USE_MORPHNORMALS
1464
1464
  objectNormal *= morphTargetBaseInfluence;
1465
1465
  for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1466
1466
  if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
1467
1467
  }
1468
- #endif`,Cg=`#ifdef USE_MORPHTARGETS
1468
+ #endif`,nv=`#ifdef USE_MORPHTARGETS
1469
1469
  #ifndef USE_INSTANCING_MORPH
1470
1470
  uniform float morphTargetBaseInfluence;
1471
1471
  uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
@@ -1479,12 +1479,12 @@ IncidentLight directLight;
1479
1479
  ivec3 morphUV = ivec3( x, y, morphTargetIndex );
1480
1480
  return texelFetch( morphTargetsTexture, morphUV, 0 );
1481
1481
  }
1482
- #endif`,Rg=`#ifdef USE_MORPHTARGETS
1482
+ #endif`,iv=`#ifdef USE_MORPHTARGETS
1483
1483
  transformed *= morphTargetBaseInfluence;
1484
1484
  for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1485
1485
  if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
1486
1486
  }
1487
- #endif`,Pg=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
1487
+ #endif`,sv=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
1488
1488
  #ifdef FLAT_SHADED
1489
1489
  vec3 fdx = dFdx( vViewPosition );
1490
1490
  vec3 fdy = dFdy( vViewPosition );
@@ -1525,7 +1525,7 @@ IncidentLight directLight;
1525
1525
  tbn2[1] *= faceDirection;
1526
1526
  #endif
1527
1527
  #endif
1528
- vec3 nonPerturbedNormal = normal;`,Lg=`#ifdef USE_NORMALMAP_OBJECTSPACE
1528
+ vec3 nonPerturbedNormal = normal;`,rv=`#ifdef USE_NORMALMAP_OBJECTSPACE
1529
1529
  normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
1530
1530
  #ifdef FLIP_SIDED
1531
1531
  normal = - normal;
@@ -1540,25 +1540,25 @@ vec3 nonPerturbedNormal = normal;`,Lg=`#ifdef USE_NORMALMAP_OBJECTSPACE
1540
1540
  normal = normalize( tbn * mapN );
1541
1541
  #elif defined( USE_BUMPMAP )
1542
1542
  normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
1543
- #endif`,Dg=`#ifndef FLAT_SHADED
1543
+ #endif`,av=`#ifndef FLAT_SHADED
1544
1544
  varying vec3 vNormal;
1545
1545
  #ifdef USE_TANGENT
1546
1546
  varying vec3 vTangent;
1547
1547
  varying vec3 vBitangent;
1548
1548
  #endif
1549
- #endif`,Ig=`#ifndef FLAT_SHADED
1549
+ #endif`,ov=`#ifndef FLAT_SHADED
1550
1550
  varying vec3 vNormal;
1551
1551
  #ifdef USE_TANGENT
1552
1552
  varying vec3 vTangent;
1553
1553
  varying vec3 vBitangent;
1554
1554
  #endif
1555
- #endif`,kg=`#ifndef FLAT_SHADED
1555
+ #endif`,lv=`#ifndef FLAT_SHADED
1556
1556
  vNormal = normalize( transformedNormal );
1557
1557
  #ifdef USE_TANGENT
1558
1558
  vTangent = normalize( transformedTangent );
1559
1559
  vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
1560
1560
  #endif
1561
- #endif`,Ng=`#ifdef USE_NORMALMAP
1561
+ #endif`,cv=`#ifdef USE_NORMALMAP
1562
1562
  uniform sampler2D normalMap;
1563
1563
  uniform vec2 normalScale;
1564
1564
  #endif
@@ -1580,13 +1580,13 @@ vec3 nonPerturbedNormal = normal;`,Lg=`#ifdef USE_NORMALMAP_OBJECTSPACE
1580
1580
  float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
1581
1581
  return mat3( T * scale, B * scale, N );
1582
1582
  }
1583
- #endif`,Ug=`#ifdef USE_CLEARCOAT
1583
+ #endif`,hv=`#ifdef USE_CLEARCOAT
1584
1584
  vec3 clearcoatNormal = nonPerturbedNormal;
1585
- #endif`,Og=`#ifdef USE_CLEARCOAT_NORMALMAP
1585
+ #endif`,uv=`#ifdef USE_CLEARCOAT_NORMALMAP
1586
1586
  vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
1587
1587
  clearcoatMapN.xy *= clearcoatNormalScale;
1588
1588
  clearcoatNormal = normalize( tbn2 * clearcoatMapN );
1589
- #endif`,Fg=`#ifdef USE_CLEARCOATMAP
1589
+ #endif`,dv=`#ifdef USE_CLEARCOATMAP
1590
1590
  uniform sampler2D clearcoatMap;
1591
1591
  #endif
1592
1592
  #ifdef USE_CLEARCOAT_NORMALMAP
@@ -1595,18 +1595,18 @@ vec3 nonPerturbedNormal = normal;`,Lg=`#ifdef USE_NORMALMAP_OBJECTSPACE
1595
1595
  #endif
1596
1596
  #ifdef USE_CLEARCOAT_ROUGHNESSMAP
1597
1597
  uniform sampler2D clearcoatRoughnessMap;
1598
- #endif`,zg=`#ifdef USE_IRIDESCENCEMAP
1598
+ #endif`,fv=`#ifdef USE_IRIDESCENCEMAP
1599
1599
  uniform sampler2D iridescenceMap;
1600
1600
  #endif
1601
1601
  #ifdef USE_IRIDESCENCE_THICKNESSMAP
1602
1602
  uniform sampler2D iridescenceThicknessMap;
1603
- #endif`,Bg=`#ifdef OPAQUE
1603
+ #endif`,pv=`#ifdef OPAQUE
1604
1604
  diffuseColor.a = 1.0;
1605
1605
  #endif
1606
1606
  #ifdef USE_TRANSMISSION
1607
1607
  diffuseColor.a *= material.transmissionAlpha;
1608
1608
  #endif
1609
- gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,Hg=`vec3 packNormalToRGB( const in vec3 normal ) {
1609
+ gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,mv=`vec3 packNormalToRGB( const in vec3 normal ) {
1610
1610
  return normalize( normal ) * 0.5 + 0.5;
1611
1611
  }
1612
1612
  vec3 unpackRGBToNormal( const in vec3 rgb ) {
@@ -1675,9 +1675,9 @@ float viewZToPerspectiveDepth( const in float viewZ, const in float near, const
1675
1675
  }
1676
1676
  float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
1677
1677
  return ( near * far ) / ( ( far - near ) * depth - far );
1678
- }`,Vg=`#ifdef PREMULTIPLIED_ALPHA
1678
+ }`,gv=`#ifdef PREMULTIPLIED_ALPHA
1679
1679
  gl_FragColor.rgb *= gl_FragColor.a;
1680
- #endif`,Gg=`vec4 mvPosition = vec4( transformed, 1.0 );
1680
+ #endif`,vv=`vec4 mvPosition = vec4( transformed, 1.0 );
1681
1681
  #ifdef USE_BATCHING
1682
1682
  mvPosition = batchingMatrix * mvPosition;
1683
1683
  #endif
@@ -1685,22 +1685,22 @@ float perspectiveDepthToViewZ( const in float depth, const in float near, const
1685
1685
  mvPosition = instanceMatrix * mvPosition;
1686
1686
  #endif
1687
1687
  mvPosition = modelViewMatrix * mvPosition;
1688
- gl_Position = projectionMatrix * mvPosition;`,$g=`#ifdef DITHERING
1688
+ gl_Position = projectionMatrix * mvPosition;`,_v=`#ifdef DITHERING
1689
1689
  gl_FragColor.rgb = dithering( gl_FragColor.rgb );
1690
- #endif`,Wg=`#ifdef DITHERING
1690
+ #endif`,xv=`#ifdef DITHERING
1691
1691
  vec3 dithering( vec3 color ) {
1692
1692
  float grid_position = rand( gl_FragCoord.xy );
1693
1693
  vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
1694
1694
  dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
1695
1695
  return color + dither_shift_RGB;
1696
1696
  }
1697
- #endif`,Xg=`float roughnessFactor = roughness;
1697
+ #endif`,yv=`float roughnessFactor = roughness;
1698
1698
  #ifdef USE_ROUGHNESSMAP
1699
1699
  vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
1700
1700
  roughnessFactor *= texelRoughness.g;
1701
- #endif`,jg=`#ifdef USE_ROUGHNESSMAP
1701
+ #endif`,Mv=`#ifdef USE_ROUGHNESSMAP
1702
1702
  uniform sampler2D roughnessMap;
1703
- #endif`,qg=`#if NUM_SPOT_LIGHT_COORDS > 0
1703
+ #endif`,bv=`#if NUM_SPOT_LIGHT_COORDS > 0
1704
1704
  varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
1705
1705
  #endif
1706
1706
  #if NUM_SPOT_LIGHT_MAPS > 0
@@ -1886,7 +1886,7 @@ gl_Position = projectionMatrix * mvPosition;`,$g=`#ifdef DITHERING
1886
1886
  }
1887
1887
  return mix( 1.0, shadow, shadowIntensity );
1888
1888
  }
1889
- #endif`,Yg=`#if NUM_SPOT_LIGHT_COORDS > 0
1889
+ #endif`,Sv=`#if NUM_SPOT_LIGHT_COORDS > 0
1890
1890
  uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
1891
1891
  varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
1892
1892
  #endif
@@ -1927,7 +1927,7 @@ gl_Position = projectionMatrix * mvPosition;`,$g=`#ifdef DITHERING
1927
1927
  };
1928
1928
  uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
1929
1929
  #endif
1930
- #endif`,Kg=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
1930
+ #endif`,wv=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
1931
1931
  vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
1932
1932
  vec4 shadowWorldPosition;
1933
1933
  #endif
@@ -1959,7 +1959,7 @@ gl_Position = projectionMatrix * mvPosition;`,$g=`#ifdef DITHERING
1959
1959
  vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
1960
1960
  }
1961
1961
  #pragma unroll_loop_end
1962
- #endif`,Zg=`float getShadowMask() {
1962
+ #endif`,Ev=`float getShadowMask() {
1963
1963
  float shadow = 1.0;
1964
1964
  #ifdef USE_SHADOWMAP
1965
1965
  #if NUM_DIR_LIGHT_SHADOWS > 0
@@ -1991,12 +1991,12 @@ gl_Position = projectionMatrix * mvPosition;`,$g=`#ifdef DITHERING
1991
1991
  #endif
1992
1992
  #endif
1993
1993
  return shadow;
1994
- }`,Jg=`#ifdef USE_SKINNING
1994
+ }`,Tv=`#ifdef USE_SKINNING
1995
1995
  mat4 boneMatX = getBoneMatrix( skinIndex.x );
1996
1996
  mat4 boneMatY = getBoneMatrix( skinIndex.y );
1997
1997
  mat4 boneMatZ = getBoneMatrix( skinIndex.z );
1998
1998
  mat4 boneMatW = getBoneMatrix( skinIndex.w );
1999
- #endif`,Qg=`#ifdef USE_SKINNING
1999
+ #endif`,Av=`#ifdef USE_SKINNING
2000
2000
  uniform mat4 bindMatrix;
2001
2001
  uniform mat4 bindMatrixInverse;
2002
2002
  uniform highp sampler2D boneTexture;
@@ -2011,7 +2011,7 @@ gl_Position = projectionMatrix * mvPosition;`,$g=`#ifdef DITHERING
2011
2011
  vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
2012
2012
  return mat4( v1, v2, v3, v4 );
2013
2013
  }
2014
- #endif`,tv=`#ifdef USE_SKINNING
2014
+ #endif`,Cv=`#ifdef USE_SKINNING
2015
2015
  vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
2016
2016
  vec4 skinned = vec4( 0.0 );
2017
2017
  skinned += boneMatX * skinVertex * skinWeight.x;
@@ -2019,7 +2019,7 @@ gl_Position = projectionMatrix * mvPosition;`,$g=`#ifdef DITHERING
2019
2019
  skinned += boneMatZ * skinVertex * skinWeight.z;
2020
2020
  skinned += boneMatW * skinVertex * skinWeight.w;
2021
2021
  transformed = ( bindMatrixInverse * skinned ).xyz;
2022
- #endif`,ev=`#ifdef USE_SKINNING
2022
+ #endif`,Rv=`#ifdef USE_SKINNING
2023
2023
  mat4 skinMatrix = mat4( 0.0 );
2024
2024
  skinMatrix += skinWeight.x * boneMatX;
2025
2025
  skinMatrix += skinWeight.y * boneMatY;
@@ -2030,17 +2030,17 @@ gl_Position = projectionMatrix * mvPosition;`,$g=`#ifdef DITHERING
2030
2030
  #ifdef USE_TANGENT
2031
2031
  objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
2032
2032
  #endif
2033
- #endif`,nv=`float specularStrength;
2033
+ #endif`,Pv=`float specularStrength;
2034
2034
  #ifdef USE_SPECULARMAP
2035
2035
  vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
2036
2036
  specularStrength = texelSpecular.r;
2037
2037
  #else
2038
2038
  specularStrength = 1.0;
2039
- #endif`,iv=`#ifdef USE_SPECULARMAP
2039
+ #endif`,Lv=`#ifdef USE_SPECULARMAP
2040
2040
  uniform sampler2D specularMap;
2041
- #endif`,sv=`#if defined( TONE_MAPPING )
2041
+ #endif`,Dv=`#if defined( TONE_MAPPING )
2042
2042
  gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
2043
- #endif`,rv=`#ifndef saturate
2043
+ #endif`,Iv=`#ifndef saturate
2044
2044
  #define saturate( a ) clamp( a, 0.0, 1.0 )
2045
2045
  #endif
2046
2046
  uniform float toneMappingExposure;
@@ -2137,7 +2137,7 @@ vec3 NeutralToneMapping( vec3 color ) {
2137
2137
  float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
2138
2138
  return mix( color, vec3( newPeak ), g );
2139
2139
  }
2140
- vec3 CustomToneMapping( vec3 color ) { return color; }`,av=`#ifdef USE_TRANSMISSION
2140
+ vec3 CustomToneMapping( vec3 color ) { return color; }`,kv=`#ifdef USE_TRANSMISSION
2141
2141
  material.transmission = transmission;
2142
2142
  material.transmissionAlpha = 1.0;
2143
2143
  material.thickness = thickness;
@@ -2158,7 +2158,7 @@ vec3 CustomToneMapping( vec3 color ) { return color; }`,av=`#ifdef USE_TRANSMISS
2158
2158
  material.attenuationColor, material.attenuationDistance );
2159
2159
  material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
2160
2160
  totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
2161
- #endif`,ov=`#ifdef USE_TRANSMISSION
2161
+ #endif`,Nv=`#ifdef USE_TRANSMISSION
2162
2162
  uniform float transmission;
2163
2163
  uniform float thickness;
2164
2164
  uniform float attenuationDistance;
@@ -2289,7 +2289,7 @@ vec3 CustomToneMapping( vec3 color ) { return color; }`,av=`#ifdef USE_TRANSMISS
2289
2289
  float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
2290
2290
  return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
2291
2291
  }
2292
- #endif`,lv=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2292
+ #endif`,Uv=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2293
2293
  varying vec2 vUv;
2294
2294
  #endif
2295
2295
  #ifdef USE_MAP
@@ -2359,7 +2359,7 @@ vec3 CustomToneMapping( vec3 color ) { return color; }`,av=`#ifdef USE_TRANSMISS
2359
2359
  #ifdef USE_THICKNESSMAP
2360
2360
  uniform mat3 thicknessMapTransform;
2361
2361
  varying vec2 vThicknessMapUv;
2362
- #endif`,cv=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2362
+ #endif`,Ov=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2363
2363
  varying vec2 vUv;
2364
2364
  #endif
2365
2365
  #ifdef USE_MAP
@@ -2453,7 +2453,7 @@ vec3 CustomToneMapping( vec3 color ) { return color; }`,av=`#ifdef USE_TRANSMISS
2453
2453
  #ifdef USE_THICKNESSMAP
2454
2454
  uniform mat3 thicknessMapTransform;
2455
2455
  varying vec2 vThicknessMapUv;
2456
- #endif`,hv=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2456
+ #endif`,Fv=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2457
2457
  vUv = vec3( uv, 1 ).xy;
2458
2458
  #endif
2459
2459
  #ifdef USE_MAP
@@ -2524,7 +2524,7 @@ vec3 CustomToneMapping( vec3 color ) { return color; }`,av=`#ifdef USE_TRANSMISS
2524
2524
  #endif
2525
2525
  #ifdef USE_THICKNESSMAP
2526
2526
  vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
2527
- #endif`,uv=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
2527
+ #endif`,zv=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
2528
2528
  vec4 worldPosition = vec4( transformed, 1.0 );
2529
2529
  #ifdef USE_BATCHING
2530
2530
  worldPosition = batchingMatrix * worldPosition;
@@ -2533,12 +2533,12 @@ vec3 CustomToneMapping( vec3 color ) { return color; }`,av=`#ifdef USE_TRANSMISS
2533
2533
  worldPosition = instanceMatrix * worldPosition;
2534
2534
  #endif
2535
2535
  worldPosition = modelMatrix * worldPosition;
2536
- #endif`;const dv=`varying vec2 vUv;
2536
+ #endif`;const Bv=`varying vec2 vUv;
2537
2537
  uniform mat3 uvTransform;
2538
2538
  void main() {
2539
2539
  vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
2540
2540
  gl_Position = vec4( position.xy, 1.0, 1.0 );
2541
- }`,fv=`uniform sampler2D t2D;
2541
+ }`,Hv=`uniform sampler2D t2D;
2542
2542
  uniform float backgroundIntensity;
2543
2543
  varying vec2 vUv;
2544
2544
  void main() {
@@ -2550,14 +2550,14 @@ void main() {
2550
2550
  gl_FragColor = texColor;
2551
2551
  #include <tonemapping_fragment>
2552
2552
  #include <colorspace_fragment>
2553
- }`,pv=`varying vec3 vWorldDirection;
2553
+ }`,Vv=`varying vec3 vWorldDirection;
2554
2554
  #include <common>
2555
2555
  void main() {
2556
2556
  vWorldDirection = transformDirection( position, modelMatrix );
2557
2557
  #include <begin_vertex>
2558
2558
  #include <project_vertex>
2559
2559
  gl_Position.z = gl_Position.w;
2560
- }`,mv=`#ifdef ENVMAP_TYPE_CUBE
2560
+ }`,Gv=`#ifdef ENVMAP_TYPE_CUBE
2561
2561
  uniform samplerCube envMap;
2562
2562
  #elif defined( ENVMAP_TYPE_CUBE_UV )
2563
2563
  uniform sampler2D envMap;
@@ -2580,14 +2580,14 @@ void main() {
2580
2580
  gl_FragColor = texColor;
2581
2581
  #include <tonemapping_fragment>
2582
2582
  #include <colorspace_fragment>
2583
- }`,gv=`varying vec3 vWorldDirection;
2583
+ }`,$v=`varying vec3 vWorldDirection;
2584
2584
  #include <common>
2585
2585
  void main() {
2586
2586
  vWorldDirection = transformDirection( position, modelMatrix );
2587
2587
  #include <begin_vertex>
2588
2588
  #include <project_vertex>
2589
2589
  gl_Position.z = gl_Position.w;
2590
- }`,vv=`uniform samplerCube tCube;
2590
+ }`,Wv=`uniform samplerCube tCube;
2591
2591
  uniform float tFlip;
2592
2592
  uniform float opacity;
2593
2593
  varying vec3 vWorldDirection;
@@ -2597,7 +2597,7 @@ void main() {
2597
2597
  gl_FragColor.a *= opacity;
2598
2598
  #include <tonemapping_fragment>
2599
2599
  #include <colorspace_fragment>
2600
- }`,_v=`#include <common>
2600
+ }`,Xv=`#include <common>
2601
2601
  #include <batching_pars_vertex>
2602
2602
  #include <uv_pars_vertex>
2603
2603
  #include <displacementmap_pars_vertex>
@@ -2624,7 +2624,7 @@ void main() {
2624
2624
  #include <logdepthbuf_vertex>
2625
2625
  #include <clipping_planes_vertex>
2626
2626
  vHighPrecisionZW = gl_Position.zw;
2627
- }`,xv=`#if DEPTH_PACKING == 3200
2627
+ }`,jv=`#if DEPTH_PACKING == 3200
2628
2628
  uniform float opacity;
2629
2629
  #endif
2630
2630
  #include <common>
@@ -2658,7 +2658,7 @@ void main() {
2658
2658
  #elif DEPTH_PACKING == 3203
2659
2659
  gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
2660
2660
  #endif
2661
- }`,yv=`#define DISTANCE
2661
+ }`,qv=`#define DISTANCE
2662
2662
  varying vec3 vWorldPosition;
2663
2663
  #include <common>
2664
2664
  #include <batching_pars_vertex>
@@ -2685,7 +2685,7 @@ void main() {
2685
2685
  #include <worldpos_vertex>
2686
2686
  #include <clipping_planes_vertex>
2687
2687
  vWorldPosition = worldPosition.xyz;
2688
- }`,Mv=`#define DISTANCE
2688
+ }`,Yv=`#define DISTANCE
2689
2689
  uniform vec3 referencePosition;
2690
2690
  uniform float nearDistance;
2691
2691
  uniform float farDistance;
@@ -2709,13 +2709,13 @@ void main () {
2709
2709
  dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
2710
2710
  dist = saturate( dist );
2711
2711
  gl_FragColor = packDepthToRGBA( dist );
2712
- }`,bv=`varying vec3 vWorldDirection;
2712
+ }`,Kv=`varying vec3 vWorldDirection;
2713
2713
  #include <common>
2714
2714
  void main() {
2715
2715
  vWorldDirection = transformDirection( position, modelMatrix );
2716
2716
  #include <begin_vertex>
2717
2717
  #include <project_vertex>
2718
- }`,Sv=`uniform sampler2D tEquirect;
2718
+ }`,Zv=`uniform sampler2D tEquirect;
2719
2719
  varying vec3 vWorldDirection;
2720
2720
  #include <common>
2721
2721
  void main() {
@@ -2724,7 +2724,7 @@ void main() {
2724
2724
  gl_FragColor = texture2D( tEquirect, sampleUV );
2725
2725
  #include <tonemapping_fragment>
2726
2726
  #include <colorspace_fragment>
2727
- }`,wv=`uniform float scale;
2727
+ }`,Jv=`uniform float scale;
2728
2728
  attribute float lineDistance;
2729
2729
  varying float vLineDistance;
2730
2730
  #include <common>
@@ -2746,7 +2746,7 @@ void main() {
2746
2746
  #include <logdepthbuf_vertex>
2747
2747
  #include <clipping_planes_vertex>
2748
2748
  #include <fog_vertex>
2749
- }`,Ev=`uniform vec3 diffuse;
2749
+ }`,Qv=`uniform vec3 diffuse;
2750
2750
  uniform float opacity;
2751
2751
  uniform float dashSize;
2752
2752
  uniform float totalSize;
@@ -2774,7 +2774,7 @@ void main() {
2774
2774
  #include <colorspace_fragment>
2775
2775
  #include <fog_fragment>
2776
2776
  #include <premultiplied_alpha_fragment>
2777
- }`,Tv=`#include <common>
2777
+ }`,t_=`#include <common>
2778
2778
  #include <batching_pars_vertex>
2779
2779
  #include <uv_pars_vertex>
2780
2780
  #include <envmap_pars_vertex>
@@ -2806,7 +2806,7 @@ void main() {
2806
2806
  #include <worldpos_vertex>
2807
2807
  #include <envmap_vertex>
2808
2808
  #include <fog_vertex>
2809
- }`,Av=`uniform vec3 diffuse;
2809
+ }`,e_=`uniform vec3 diffuse;
2810
2810
  uniform float opacity;
2811
2811
  #ifndef FLAT_SHADED
2812
2812
  varying vec3 vNormal;
@@ -2854,7 +2854,7 @@ void main() {
2854
2854
  #include <fog_fragment>
2855
2855
  #include <premultiplied_alpha_fragment>
2856
2856
  #include <dithering_fragment>
2857
- }`,Cv=`#define LAMBERT
2857
+ }`,n_=`#define LAMBERT
2858
2858
  varying vec3 vViewPosition;
2859
2859
  #include <common>
2860
2860
  #include <batching_pars_vertex>
@@ -2893,7 +2893,7 @@ void main() {
2893
2893
  #include <envmap_vertex>
2894
2894
  #include <shadowmap_vertex>
2895
2895
  #include <fog_vertex>
2896
- }`,Rv=`#define LAMBERT
2896
+ }`,i_=`#define LAMBERT
2897
2897
  uniform vec3 diffuse;
2898
2898
  uniform vec3 emissive;
2899
2899
  uniform float opacity;
@@ -2950,7 +2950,7 @@ void main() {
2950
2950
  #include <fog_fragment>
2951
2951
  #include <premultiplied_alpha_fragment>
2952
2952
  #include <dithering_fragment>
2953
- }`,Pv=`#define MATCAP
2953
+ }`,s_=`#define MATCAP
2954
2954
  varying vec3 vViewPosition;
2955
2955
  #include <common>
2956
2956
  #include <batching_pars_vertex>
@@ -2984,7 +2984,7 @@ void main() {
2984
2984
  #include <clipping_planes_vertex>
2985
2985
  #include <fog_vertex>
2986
2986
  vViewPosition = - mvPosition.xyz;
2987
- }`,Lv=`#define MATCAP
2987
+ }`,r_=`#define MATCAP
2988
2988
  uniform vec3 diffuse;
2989
2989
  uniform float opacity;
2990
2990
  uniform sampler2D matcap;
@@ -3030,7 +3030,7 @@ void main() {
3030
3030
  #include <fog_fragment>
3031
3031
  #include <premultiplied_alpha_fragment>
3032
3032
  #include <dithering_fragment>
3033
- }`,Dv=`#define NORMAL
3033
+ }`,a_=`#define NORMAL
3034
3034
  #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3035
3035
  varying vec3 vViewPosition;
3036
3036
  #endif
@@ -3063,7 +3063,7 @@ void main() {
3063
3063
  #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3064
3064
  vViewPosition = - mvPosition.xyz;
3065
3065
  #endif
3066
- }`,Iv=`#define NORMAL
3066
+ }`,o_=`#define NORMAL
3067
3067
  uniform float opacity;
3068
3068
  #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3069
3069
  varying vec3 vViewPosition;
@@ -3085,7 +3085,7 @@ void main() {
3085
3085
  #ifdef OPAQUE
3086
3086
  gl_FragColor.a = 1.0;
3087
3087
  #endif
3088
- }`,kv=`#define PHONG
3088
+ }`,l_=`#define PHONG
3089
3089
  varying vec3 vViewPosition;
3090
3090
  #include <common>
3091
3091
  #include <batching_pars_vertex>
@@ -3124,7 +3124,7 @@ void main() {
3124
3124
  #include <envmap_vertex>
3125
3125
  #include <shadowmap_vertex>
3126
3126
  #include <fog_vertex>
3127
- }`,Nv=`#define PHONG
3127
+ }`,c_=`#define PHONG
3128
3128
  uniform vec3 diffuse;
3129
3129
  uniform vec3 emissive;
3130
3130
  uniform vec3 specular;
@@ -3183,7 +3183,7 @@ void main() {
3183
3183
  #include <fog_fragment>
3184
3184
  #include <premultiplied_alpha_fragment>
3185
3185
  #include <dithering_fragment>
3186
- }`,Uv=`#define STANDARD
3186
+ }`,h_=`#define STANDARD
3187
3187
  varying vec3 vViewPosition;
3188
3188
  #ifdef USE_TRANSMISSION
3189
3189
  varying vec3 vWorldPosition;
@@ -3226,7 +3226,7 @@ void main() {
3226
3226
  #ifdef USE_TRANSMISSION
3227
3227
  vWorldPosition = worldPosition.xyz;
3228
3228
  #endif
3229
- }`,Ov=`#define STANDARD
3229
+ }`,u_=`#define STANDARD
3230
3230
  #ifdef PHYSICAL
3231
3231
  #define IOR
3232
3232
  #define USE_SPECULAR
@@ -3351,7 +3351,7 @@ void main() {
3351
3351
  #include <fog_fragment>
3352
3352
  #include <premultiplied_alpha_fragment>
3353
3353
  #include <dithering_fragment>
3354
- }`,Fv=`#define TOON
3354
+ }`,d_=`#define TOON
3355
3355
  varying vec3 vViewPosition;
3356
3356
  #include <common>
3357
3357
  #include <batching_pars_vertex>
@@ -3388,7 +3388,7 @@ void main() {
3388
3388
  #include <worldpos_vertex>
3389
3389
  #include <shadowmap_vertex>
3390
3390
  #include <fog_vertex>
3391
- }`,zv=`#define TOON
3391
+ }`,f_=`#define TOON
3392
3392
  uniform vec3 diffuse;
3393
3393
  uniform vec3 emissive;
3394
3394
  uniform float opacity;
@@ -3441,7 +3441,7 @@ void main() {
3441
3441
  #include <fog_fragment>
3442
3442
  #include <premultiplied_alpha_fragment>
3443
3443
  #include <dithering_fragment>
3444
- }`,Bv=`uniform float size;
3444
+ }`,p_=`uniform float size;
3445
3445
  uniform float scale;
3446
3446
  #include <common>
3447
3447
  #include <color_pars_vertex>
@@ -3472,7 +3472,7 @@ void main() {
3472
3472
  #include <clipping_planes_vertex>
3473
3473
  #include <worldpos_vertex>
3474
3474
  #include <fog_vertex>
3475
- }`,Hv=`uniform vec3 diffuse;
3475
+ }`,m_=`uniform vec3 diffuse;
3476
3476
  uniform float opacity;
3477
3477
  #include <common>
3478
3478
  #include <color_pars_fragment>
@@ -3497,7 +3497,7 @@ void main() {
3497
3497
  #include <colorspace_fragment>
3498
3498
  #include <fog_fragment>
3499
3499
  #include <premultiplied_alpha_fragment>
3500
- }`,Vv=`#include <common>
3500
+ }`,g_=`#include <common>
3501
3501
  #include <batching_pars_vertex>
3502
3502
  #include <fog_pars_vertex>
3503
3503
  #include <morphtarget_pars_vertex>
@@ -3520,7 +3520,7 @@ void main() {
3520
3520
  #include <worldpos_vertex>
3521
3521
  #include <shadowmap_vertex>
3522
3522
  #include <fog_vertex>
3523
- }`,Gv=`uniform vec3 color;
3523
+ }`,v_=`uniform vec3 color;
3524
3524
  uniform float opacity;
3525
3525
  #include <common>
3526
3526
  #include <packing>
@@ -3536,7 +3536,7 @@ void main() {
3536
3536
  #include <tonemapping_fragment>
3537
3537
  #include <colorspace_fragment>
3538
3538
  #include <fog_fragment>
3539
- }`,$v=`uniform float rotation;
3539
+ }`,__=`uniform float rotation;
3540
3540
  uniform vec2 center;
3541
3541
  #include <common>
3542
3542
  #include <uv_pars_vertex>
@@ -3560,7 +3560,7 @@ void main() {
3560
3560
  #include <logdepthbuf_vertex>
3561
3561
  #include <clipping_planes_vertex>
3562
3562
  #include <fog_vertex>
3563
- }`,Wv=`uniform vec3 diffuse;
3563
+ }`,x_=`uniform vec3 diffuse;
3564
3564
  uniform float opacity;
3565
3565
  #include <common>
3566
3566
  #include <uv_pars_fragment>
@@ -3585,7 +3585,7 @@ void main() {
3585
3585
  #include <tonemapping_fragment>
3586
3586
  #include <colorspace_fragment>
3587
3587
  #include <fog_fragment>
3588
- }`,Wt={alphahash_fragment:f0,alphahash_pars_fragment:p0,alphamap_fragment:m0,alphamap_pars_fragment:g0,alphatest_fragment:v0,alphatest_pars_fragment:_0,aomap_fragment:x0,aomap_pars_fragment:y0,batching_pars_vertex:M0,batching_vertex:b0,begin_vertex:S0,beginnormal_vertex:w0,bsdfs:E0,iridescence_fragment:T0,bumpmap_pars_fragment:A0,clipping_planes_fragment:C0,clipping_planes_pars_fragment:R0,clipping_planes_pars_vertex:P0,clipping_planes_vertex:L0,color_fragment:D0,color_pars_fragment:I0,color_pars_vertex:k0,color_vertex:N0,common:U0,cube_uv_reflection_fragment:O0,defaultnormal_vertex:F0,displacementmap_pars_vertex:z0,displacementmap_vertex:B0,emissivemap_fragment:H0,emissivemap_pars_fragment:V0,colorspace_fragment:G0,colorspace_pars_fragment:$0,envmap_fragment:W0,envmap_common_pars_fragment:X0,envmap_pars_fragment:j0,envmap_pars_vertex:q0,envmap_physical_pars_fragment:rg,envmap_vertex:Y0,fog_vertex:K0,fog_pars_vertex:Z0,fog_fragment:J0,fog_pars_fragment:Q0,gradientmap_pars_fragment:tg,lightmap_pars_fragment:eg,lights_lambert_fragment:ng,lights_lambert_pars_fragment:ig,lights_pars_begin:sg,lights_toon_fragment:ag,lights_toon_pars_fragment:og,lights_phong_fragment:lg,lights_phong_pars_fragment:cg,lights_physical_fragment:hg,lights_physical_pars_fragment:ug,lights_fragment_begin:dg,lights_fragment_maps:fg,lights_fragment_end:pg,logdepthbuf_fragment:mg,logdepthbuf_pars_fragment:gg,logdepthbuf_pars_vertex:vg,logdepthbuf_vertex:_g,map_fragment:xg,map_pars_fragment:yg,map_particle_fragment:Mg,map_particle_pars_fragment:bg,metalnessmap_fragment:Sg,metalnessmap_pars_fragment:wg,morphinstance_vertex:Eg,morphcolor_vertex:Tg,morphnormal_vertex:Ag,morphtarget_pars_vertex:Cg,morphtarget_vertex:Rg,normal_fragment_begin:Pg,normal_fragment_maps:Lg,normal_pars_fragment:Dg,normal_pars_vertex:Ig,normal_vertex:kg,normalmap_pars_fragment:Ng,clearcoat_normal_fragment_begin:Ug,clearcoat_normal_fragment_maps:Og,clearcoat_pars_fragment:Fg,iridescence_pars_fragment:zg,opaque_fragment:Bg,packing:Hg,premultiplied_alpha_fragment:Vg,project_vertex:Gg,dithering_fragment:$g,dithering_pars_fragment:Wg,roughnessmap_fragment:Xg,roughnessmap_pars_fragment:jg,shadowmap_pars_fragment:qg,shadowmap_pars_vertex:Yg,shadowmap_vertex:Kg,shadowmask_pars_fragment:Zg,skinbase_vertex:Jg,skinning_pars_vertex:Qg,skinning_vertex:tv,skinnormal_vertex:ev,specularmap_fragment:nv,specularmap_pars_fragment:iv,tonemapping_fragment:sv,tonemapping_pars_fragment:rv,transmission_fragment:av,transmission_pars_fragment:ov,uv_pars_fragment:lv,uv_pars_vertex:cv,uv_vertex:hv,worldpos_vertex:uv,background_vert:dv,background_frag:fv,backgroundCube_vert:pv,backgroundCube_frag:mv,cube_vert:gv,cube_frag:vv,depth_vert:_v,depth_frag:xv,distanceRGBA_vert:yv,distanceRGBA_frag:Mv,equirect_vert:bv,equirect_frag:Sv,linedashed_vert:wv,linedashed_frag:Ev,meshbasic_vert:Tv,meshbasic_frag:Av,meshlambert_vert:Cv,meshlambert_frag:Rv,meshmatcap_vert:Pv,meshmatcap_frag:Lv,meshnormal_vert:Dv,meshnormal_frag:Iv,meshphong_vert:kv,meshphong_frag:Nv,meshphysical_vert:Uv,meshphysical_frag:Ov,meshtoon_vert:Fv,meshtoon_frag:zv,points_vert:Bv,points_frag:Hv,shadow_vert:Vv,shadow_frag:Gv,sprite_vert:$v,sprite_frag:Wv},ut={common:{diffuse:{value:new Zt(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Xt},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Xt}},envmap:{envMap:{value:null},envMapRotation:{value:new Xt},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Xt}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Xt}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Xt},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Xt},normalScale:{value:new rt(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Xt},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Xt}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Xt}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Xt}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Zt(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Zt(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0},uvTransform:{value:new Xt}},sprite:{diffuse:{value:new Zt(16777215)},opacity:{value:1},center:{value:new rt(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Xt},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0}}},ni={basic:{uniforms:sn([ut.common,ut.specularmap,ut.envmap,ut.aomap,ut.lightmap,ut.fog]),vertexShader:Wt.meshbasic_vert,fragmentShader:Wt.meshbasic_frag},lambert:{uniforms:sn([ut.common,ut.specularmap,ut.envmap,ut.aomap,ut.lightmap,ut.emissivemap,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.fog,ut.lights,{emissive:{value:new Zt(0)}}]),vertexShader:Wt.meshlambert_vert,fragmentShader:Wt.meshlambert_frag},phong:{uniforms:sn([ut.common,ut.specularmap,ut.envmap,ut.aomap,ut.lightmap,ut.emissivemap,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.fog,ut.lights,{emissive:{value:new Zt(0)},specular:{value:new Zt(1118481)},shininess:{value:30}}]),vertexShader:Wt.meshphong_vert,fragmentShader:Wt.meshphong_frag},standard:{uniforms:sn([ut.common,ut.envmap,ut.aomap,ut.lightmap,ut.emissivemap,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.roughnessmap,ut.metalnessmap,ut.fog,ut.lights,{emissive:{value:new Zt(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Wt.meshphysical_vert,fragmentShader:Wt.meshphysical_frag},toon:{uniforms:sn([ut.common,ut.aomap,ut.lightmap,ut.emissivemap,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.gradientmap,ut.fog,ut.lights,{emissive:{value:new Zt(0)}}]),vertexShader:Wt.meshtoon_vert,fragmentShader:Wt.meshtoon_frag},matcap:{uniforms:sn([ut.common,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.fog,{matcap:{value:null}}]),vertexShader:Wt.meshmatcap_vert,fragmentShader:Wt.meshmatcap_frag},points:{uniforms:sn([ut.points,ut.fog]),vertexShader:Wt.points_vert,fragmentShader:Wt.points_frag},dashed:{uniforms:sn([ut.common,ut.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Wt.linedashed_vert,fragmentShader:Wt.linedashed_frag},depth:{uniforms:sn([ut.common,ut.displacementmap]),vertexShader:Wt.depth_vert,fragmentShader:Wt.depth_frag},normal:{uniforms:sn([ut.common,ut.bumpmap,ut.normalmap,ut.displacementmap,{opacity:{value:1}}]),vertexShader:Wt.meshnormal_vert,fragmentShader:Wt.meshnormal_frag},sprite:{uniforms:sn([ut.sprite,ut.fog]),vertexShader:Wt.sprite_vert,fragmentShader:Wt.sprite_frag},background:{uniforms:{uvTransform:{value:new Xt},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Wt.background_vert,fragmentShader:Wt.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Xt}},vertexShader:Wt.backgroundCube_vert,fragmentShader:Wt.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Wt.cube_vert,fragmentShader:Wt.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Wt.equirect_vert,fragmentShader:Wt.equirect_frag},distanceRGBA:{uniforms:sn([ut.common,ut.displacementmap,{referencePosition:{value:new R},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Wt.distanceRGBA_vert,fragmentShader:Wt.distanceRGBA_frag},shadow:{uniforms:sn([ut.lights,ut.fog,{color:{value:new Zt(0)},opacity:{value:1}}]),vertexShader:Wt.shadow_vert,fragmentShader:Wt.shadow_frag}};ni.physical={uniforms:sn([ni.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Xt},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Xt},clearcoatNormalScale:{value:new rt(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Xt},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Xt},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Xt},sheen:{value:0},sheenColor:{value:new Zt(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Xt},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Xt},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Xt},transmissionSamplerSize:{value:new rt},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Xt},attenuationDistance:{value:0},attenuationColor:{value:new Zt(0)},specularColor:{value:new Zt(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Xt},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Xt},anisotropyVector:{value:new rt},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Xt}}]),vertexShader:Wt.meshphysical_vert,fragmentShader:Wt.meshphysical_frag};const Sa={r:0,b:0,g:0},cs=new ui,Xv=new fe;function jv(i,t,e,n,s,r,a){const o=new Zt(0);let l=r===!0?0:1,c,h,u=null,d=0,f=null;function g(y){let x=y.isScene===!0?y.background:null;return x&&x.isTexture&&(x=(y.backgroundBlurriness>0?e:t).get(x)),x}function _(y){let x=!1;const S=g(y);S===null?p(o,l):S&&S.isColor&&(p(S,1),x=!0);const L=i.xr.getEnvironmentBlendMode();L==="additive"?n.buffers.color.setClear(0,0,0,1,a):L==="alpha-blend"&&n.buffers.color.setClear(0,0,0,0,a),(i.autoClear||x)&&(n.buffers.depth.setTest(!0),n.buffers.depth.setMask(!0),n.buffers.color.setMask(!0),i.clear(i.autoClearColor,i.autoClearDepth,i.autoClearStencil))}function m(y,x){const S=g(x);S&&(S.isCubeTexture||S.mapping===To)?(h===void 0&&(h=new yt(new qe(1,1,1),new Je({name:"BackgroundCubeMaterial",uniforms:fr(ni.backgroundCube.uniforms),vertexShader:ni.backgroundCube.vertexShader,fragmentShader:ni.backgroundCube.fragmentShader,side:on,depthTest:!1,depthWrite:!1,fog:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(L,T,E){this.matrixWorld.copyPosition(E.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),s.update(h)),cs.copy(x.backgroundRotation),cs.x*=-1,cs.y*=-1,cs.z*=-1,S.isCubeTexture&&S.isRenderTargetTexture===!1&&(cs.y*=-1,cs.z*=-1),h.material.uniforms.envMap.value=S,h.material.uniforms.flipEnvMap.value=S.isCubeTexture&&S.isRenderTargetTexture===!1?-1:1,h.material.uniforms.backgroundBlurriness.value=x.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,h.material.uniforms.backgroundRotation.value.setFromMatrix4(Xv.makeRotationFromEuler(cs)),h.material.toneMapped=oe.getTransfer(S.colorSpace)!==ye,(u!==S||d!==S.version||f!==i.toneMapping)&&(h.material.needsUpdate=!0,u=S,d=S.version,f=i.toneMapping),h.layers.enableAll(),y.unshift(h,h.geometry,h.material,0,0,null)):S&&S.isTexture&&(c===void 0&&(c=new yt(new di(2,2),new Je({name:"BackgroundMaterial",uniforms:fr(ni.background.uniforms),vertexShader:ni.background.vertexShader,fragmentShader:ni.background.fragmentShader,side:es,depthTest:!1,depthWrite:!1,fog:!1})),c.geometry.deleteAttribute("normal"),Object.defineProperty(c.material,"map",{get:function(){return this.uniforms.t2D.value}}),s.update(c)),c.material.uniforms.t2D.value=S,c.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,c.material.toneMapped=oe.getTransfer(S.colorSpace)!==ye,S.matrixAutoUpdate===!0&&S.updateMatrix(),c.material.uniforms.uvTransform.value.copy(S.matrix),(u!==S||d!==S.version||f!==i.toneMapping)&&(c.material.needsUpdate=!0,u=S,d=S.version,f=i.toneMapping),c.layers.enableAll(),y.unshift(c,c.geometry,c.material,0,0,null))}function p(y,x){y.getRGB(Sa,gf(i)),n.buffers.color.setClear(Sa.r,Sa.g,Sa.b,x,a)}return{getClearColor:function(){return o},setClearColor:function(y,x=1){o.set(y),l=x,p(o,l)},getClearAlpha:function(){return l},setClearAlpha:function(y){l=y,p(o,l)},render:_,addToRenderList:m}}function qv(i,t){const e=i.getParameter(i.MAX_VERTEX_ATTRIBS),n={},s=d(null);let r=s,a=!1;function o(v,b,I,O,$){let Y=!1;const z=u(O,I,b);r!==z&&(r=z,c(r.object)),Y=f(v,O,I,$),Y&&g(v,O,I,$),$!==null&&t.update($,i.ELEMENT_ARRAY_BUFFER),(Y||a)&&(a=!1,S(v,b,I,O),$!==null&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,t.get($).buffer))}function l(){return i.createVertexArray()}function c(v){return i.bindVertexArray(v)}function h(v){return i.deleteVertexArray(v)}function u(v,b,I){const O=I.wireframe===!0;let $=n[v.id];$===void 0&&($={},n[v.id]=$);let Y=$[b.id];Y===void 0&&(Y={},$[b.id]=Y);let z=Y[O];return z===void 0&&(z=d(l()),Y[O]=z),z}function d(v){const b=[],I=[],O=[];for(let $=0;$<e;$++)b[$]=0,I[$]=0,O[$]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:b,enabledAttributes:I,attributeDivisors:O,object:v,attributes:{},index:null}}function f(v,b,I,O){const $=r.attributes,Y=b.attributes;let z=0;const K=I.getAttributes();for(const V in K)if(K[V].location>=0){const ct=$[V];let _t=Y[V];if(_t===void 0&&(V==="instanceMatrix"&&v.instanceMatrix&&(_t=v.instanceMatrix),V==="instanceColor"&&v.instanceColor&&(_t=v.instanceColor)),ct===void 0||ct.attribute!==_t||_t&&ct.data!==_t.data)return!0;z++}return r.attributesNum!==z||r.index!==O}function g(v,b,I,O){const $={},Y=b.attributes;let z=0;const K=I.getAttributes();for(const V in K)if(K[V].location>=0){let ct=Y[V];ct===void 0&&(V==="instanceMatrix"&&v.instanceMatrix&&(ct=v.instanceMatrix),V==="instanceColor"&&v.instanceColor&&(ct=v.instanceColor));const _t={};_t.attribute=ct,ct&&ct.data&&(_t.data=ct.data),$[V]=_t,z++}r.attributes=$,r.attributesNum=z,r.index=O}function _(){const v=r.newAttributes;for(let b=0,I=v.length;b<I;b++)v[b]=0}function m(v){p(v,0)}function p(v,b){const I=r.newAttributes,O=r.enabledAttributes,$=r.attributeDivisors;I[v]=1,O[v]===0&&(i.enableVertexAttribArray(v),O[v]=1),$[v]!==b&&(i.vertexAttribDivisor(v,b),$[v]=b)}function y(){const v=r.newAttributes,b=r.enabledAttributes;for(let I=0,O=b.length;I<O;I++)b[I]!==v[I]&&(i.disableVertexAttribArray(I),b[I]=0)}function x(v,b,I,O,$,Y,z){z===!0?i.vertexAttribIPointer(v,b,I,$,Y):i.vertexAttribPointer(v,b,I,O,$,Y)}function S(v,b,I,O){_();const $=O.attributes,Y=I.getAttributes(),z=b.defaultAttributeValues;for(const K in Y){const V=Y[K];if(V.location>=0){let at=$[K];if(at===void 0&&(K==="instanceMatrix"&&v.instanceMatrix&&(at=v.instanceMatrix),K==="instanceColor"&&v.instanceColor&&(at=v.instanceColor)),at!==void 0){const ct=at.normalized,_t=at.itemSize,Gt=t.get(at);if(Gt===void 0)continue;const Jt=Gt.buffer,X=Gt.type,et=Gt.bytesPerElement,ft=X===i.INT||X===i.UNSIGNED_INT||at.gpuType===Yc;if(at.isInterleavedBufferAttribute){const ot=at.data,At=ot.stride,Tt=at.offset;if(ot.isInstancedInterleavedBuffer){for(let Ft=0;Ft<V.locationSize;Ft++)p(V.location+Ft,ot.meshPerAttribute);v.isInstancedMesh!==!0&&O._maxInstanceCount===void 0&&(O._maxInstanceCount=ot.meshPerAttribute*ot.count)}else for(let Ft=0;Ft<V.locationSize;Ft++)m(V.location+Ft);i.bindBuffer(i.ARRAY_BUFFER,Jt);for(let Ft=0;Ft<V.locationSize;Ft++)x(V.location+Ft,_t/V.locationSize,X,ct,At*et,(Tt+_t/V.locationSize*Ft)*et,ft)}else{if(at.isInstancedBufferAttribute){for(let ot=0;ot<V.locationSize;ot++)p(V.location+ot,at.meshPerAttribute);v.isInstancedMesh!==!0&&O._maxInstanceCount===void 0&&(O._maxInstanceCount=at.meshPerAttribute*at.count)}else for(let ot=0;ot<V.locationSize;ot++)m(V.location+ot);i.bindBuffer(i.ARRAY_BUFFER,Jt);for(let ot=0;ot<V.locationSize;ot++)x(V.location+ot,_t/V.locationSize,X,ct,_t*et,_t/V.locationSize*ot*et,ft)}}else if(z!==void 0){const ct=z[K];if(ct!==void 0)switch(ct.length){case 2:i.vertexAttrib2fv(V.location,ct);break;case 3:i.vertexAttrib3fv(V.location,ct);break;case 4:i.vertexAttrib4fv(V.location,ct);break;default:i.vertexAttrib1fv(V.location,ct)}}}}y()}function L(){P();for(const v in n){const b=n[v];for(const I in b){const O=b[I];for(const $ in O)h(O[$].object),delete O[$];delete b[I]}delete n[v]}}function T(v){if(n[v.id]===void 0)return;const b=n[v.id];for(const I in b){const O=b[I];for(const $ in O)h(O[$].object),delete O[$];delete b[I]}delete n[v.id]}function E(v){for(const b in n){const I=n[b];if(I[v.id]===void 0)continue;const O=I[v.id];for(const $ in O)h(O[$].object),delete O[$];delete I[v.id]}}function P(){U(),a=!0,r!==s&&(r=s,c(r.object))}function U(){s.geometry=null,s.program=null,s.wireframe=!1}return{setup:o,reset:P,resetDefaultState:U,dispose:L,releaseStatesOfGeometry:T,releaseStatesOfProgram:E,initAttributes:_,enableAttribute:m,disableUnusedAttributes:y}}function Yv(i,t,e){let n;function s(c){n=c}function r(c,h){i.drawArrays(n,c,h),e.update(h,n,1)}function a(c,h,u){u!==0&&(i.drawArraysInstanced(n,c,h,u),e.update(h,n,u))}function o(c,h,u){if(u===0)return;t.get("WEBGL_multi_draw").multiDrawArraysWEBGL(n,c,0,h,0,u);let f=0;for(let g=0;g<u;g++)f+=h[g];e.update(f,n,1)}function l(c,h,u,d){if(u===0)return;const f=t.get("WEBGL_multi_draw");if(f===null)for(let g=0;g<c.length;g++)a(c[g],h[g],d[g]);else{f.multiDrawArraysInstancedWEBGL(n,c,0,h,0,d,0,u);let g=0;for(let _=0;_<u;_++)g+=h[_];for(let _=0;_<d.length;_++)e.update(g,n,d[_])}}this.setMode=s,this.render=r,this.renderInstances=a,this.renderMultiDraw=o,this.renderMultiDrawInstances=l}function Kv(i,t,e,n){let s;function r(){if(s!==void 0)return s;if(t.has("EXT_texture_filter_anisotropic")===!0){const E=t.get("EXT_texture_filter_anisotropic");s=i.getParameter(E.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else s=0;return s}function a(E){return!(E!==Dn&&n.convert(E)!==i.getParameter(i.IMPLEMENTATION_COLOR_READ_FORMAT))}function o(E){const P=E===Li&&(t.has("EXT_color_buffer_half_float")||t.has("EXT_color_buffer_float"));return!(E!==hi&&n.convert(E)!==i.getParameter(i.IMPLEMENTATION_COLOR_READ_TYPE)&&E!==wi&&!P)}function l(E){if(E==="highp"){if(i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.HIGH_FLOAT).precision>0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT).precision>0)return"highp";E="mediump"}return E==="mediump"&&i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.MEDIUM_FLOAT).precision>0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let c=e.precision!==void 0?e.precision:"highp";const h=l(c);h!==c&&(console.warn("THREE.WebGLRenderer:",c,"not supported, using",h,"instead."),c=h);const u=e.logarithmicDepthBuffer===!0,d=e.reverseDepthBuffer===!0&&t.has("EXT_clip_control");if(d===!0){const E=t.get("EXT_clip_control");E.clipControlEXT(E.LOWER_LEFT_EXT,E.ZERO_TO_ONE_EXT)}const f=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),g=i.getParameter(i.MAX_VERTEX_TEXTURE_IMAGE_UNITS),_=i.getParameter(i.MAX_TEXTURE_SIZE),m=i.getParameter(i.MAX_CUBE_MAP_TEXTURE_SIZE),p=i.getParameter(i.MAX_VERTEX_ATTRIBS),y=i.getParameter(i.MAX_VERTEX_UNIFORM_VECTORS),x=i.getParameter(i.MAX_VARYING_VECTORS),S=i.getParameter(i.MAX_FRAGMENT_UNIFORM_VECTORS),L=g>0,T=i.getParameter(i.MAX_SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:r,getMaxPrecision:l,textureFormatReadable:a,textureTypeReadable:o,precision:c,logarithmicDepthBuffer:u,reverseDepthBuffer:d,maxTextures:f,maxVertexTextures:g,maxTextureSize:_,maxCubemapSize:m,maxAttributes:p,maxVertexUniforms:y,maxVaryings:x,maxFragmentUniforms:S,vertexTextures:L,maxSamples:T}}function Zv(i){const t=this;let e=null,n=0,s=!1,r=!1;const a=new $i,o=new Xt,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(u,d){const f=u.length!==0||d||n!==0||s;return s=d,n=u.length,f},this.beginShadows=function(){r=!0,h(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(u,d){e=h(u,d,0)},this.setState=function(u,d,f){const g=u.clippingPlanes,_=u.clipIntersection,m=u.clipShadows,p=i.get(u);if(!s||g===null||g.length===0||r&&!m)r?h(null):c();else{const y=r?0:n,x=y*4;let S=p.clippingState||null;l.value=S,S=h(g,d,x,f);for(let L=0;L!==x;++L)S[L]=e[L];p.clippingState=S,this.numIntersection=_?this.numPlanes:0,this.numPlanes+=y}};function c(){l.value!==e&&(l.value=e,l.needsUpdate=n>0),t.numPlanes=n,t.numIntersection=0}function h(u,d,f,g){const _=u!==null?u.length:0;let m=null;if(_!==0){if(m=l.value,g!==!0||m===null){const p=f+_*4,y=d.matrixWorldInverse;o.getNormalMatrix(y),(m===null||m.length<p)&&(m=new Float32Array(p));for(let x=0,S=f;x!==_;++x,S+=4)a.copy(u[x]).applyMatrix4(y,o),a.normal.toArray(m,S),m[S+3]=a.constant}l.value=m,l.needsUpdate=!0}return t.numPlanes=_,t.numIntersection=0,m}}function Jv(i){let t=new WeakMap;function e(a,o){return o===sc?a.mapping=ur:o===rc&&(a.mapping=dr),a}function n(a){if(a&&a.isTexture){const o=a.mapping;if(o===sc||o===rc)if(t.has(a)){const l=t.get(a).texture;return e(l,a.mapping)}else{const l=a.image;if(l&&l.height>0){const c=new c0(l.height);return c.fromEquirectangularTexture(i,a),t.set(a,c),a.addEventListener("dispose",s),e(c.texture,a.mapping)}else return null}}return a}function s(a){const o=a.target;o.removeEventListener("dispose",s);const l=t.get(o);l!==void 0&&(t.delete(o),l.dispose())}function r(){t=new WeakMap}return{get:n,dispose:r}}class lh extends vf{constructor(t=-1,e=1,n=1,s=-1,r=.1,a=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=n,this.bottom=s,this.near=r,this.far=a,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=t.view===null?null:Object.assign({},t.view),this}setViewOffset(t,e,n,s,r,a){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=s,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,s=(this.top+this.bottom)/2;let r=n-t,a=n+t,o=s+e,l=s-e;if(this.view!==null&&this.view.enabled){const c=(this.right-this.left)/this.view.fullWidth/this.zoom,h=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=c*this.view.offsetX,a=r+c*this.view.width,o-=h*this.view.offsetY,l=o-h*this.view.height}this.projectionMatrix.makeOrthographic(r,a,o,l,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,this.view!==null&&(e.object.view=Object.assign({},this.view)),e}}const Ys=4,mu=[.125,.215,.35,.446,.526,.582],ps=20,ul=new lh,gu=new Zt;let dl=null,fl=0,pl=0,ml=!1;const ds=(1+Math.sqrt(5))/2,Hs=1/ds,vu=[new R(-ds,Hs,0),new R(ds,Hs,0),new R(-Hs,0,ds),new R(Hs,0,ds),new R(0,ds,-Hs),new R(0,ds,Hs),new R(-1,1,-1),new R(1,1,-1),new R(-1,1,1),new R(1,1,1)];class Ic{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,n=.1,s=100){dl=this._renderer.getRenderTarget(),fl=this._renderer.getActiveCubeFace(),pl=this._renderer.getActiveMipmapLevel(),ml=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,n,s,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=yu(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=xu(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let t=0;t<this._lodPlanes.length;t++)this._lodPlanes[t].dispose()}_cleanup(t){this._renderer.setRenderTarget(dl,fl,pl),this._renderer.xr.enabled=ml,t.scissorTest=!1,wa(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===ur||t.mapping===dr?this._setSize(t.image.length===0?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),dl=this._renderer.getRenderTarget(),fl=this._renderer.getActiveCubeFace(),pl=this._renderer.getActiveMipmapLevel(),ml=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const n=e||this._allocateTargets();return this._textureToCubeUV(t,n),this._applyPMREM(n),this._cleanup(n),n}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,n={magFilter:Wn,minFilter:Wn,generateMipmaps:!1,type:Li,format:Dn,colorSpace:is,depthBuffer:!1},s=_u(t,e,n);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=_u(t,e,n);const{_lodMax:r}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas}=Qv(r)),this._blurMaterial=t_(r,t,e)}return s}_compileMaterial(t){const e=new yt(this._lodPlanes[0],t);this._renderer.compile(e,ul)}_sceneToCubeUV(t,e,n,s){const o=new wn(90,1,e,n),l=[1,-1,1,1,1,1],c=[1,1,1,-1,-1,-1],h=this._renderer,u=h.autoClear,d=h.toneMapping;h.getClearColor(gu),h.toneMapping=Qi,h.autoClear=!1;const f=new ln({name:"PMREM.Background",side:on,depthWrite:!1,depthTest:!1}),g=new yt(new qe,f);let _=!1;const m=t.background;m?m.isColor&&(f.color.copy(m),t.background=null,_=!0):(f.color.copy(gu),_=!0);for(let p=0;p<6;p++){const y=p%3;y===0?(o.up.set(0,l[p],0),o.lookAt(c[p],0,0)):y===1?(o.up.set(0,0,l[p]),o.lookAt(0,c[p],0)):(o.up.set(0,l[p],0),o.lookAt(0,0,c[p]));const x=this._cubeSize;wa(s,y*x,p>2?x:0,x,x),h.setRenderTarget(s),_&&h.render(g,o),h.render(t,o)}g.geometry.dispose(),g.material.dispose(),h.toneMapping=d,h.autoClear=u,t.background=m}_textureToCubeUV(t,e){const n=this._renderer,s=t.mapping===ur||t.mapping===dr;s?(this._cubemapMaterial===null&&(this._cubemapMaterial=yu()),this._cubemapMaterial.uniforms.flipEnvMap.value=t.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=xu());const r=s?this._cubemapMaterial:this._equirectMaterial,a=new yt(this._lodPlanes[0],r),o=r.uniforms;o.envMap.value=t;const l=this._cubeSize;wa(e,0,0,3*l,2*l),n.setRenderTarget(e),n.render(a,ul)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;const s=this._lodPlanes.length;for(let r=1;r<s;r++){const a=Math.sqrt(this._sigmas[r]*this._sigmas[r]-this._sigmas[r-1]*this._sigmas[r-1]),o=vu[(s-r-1)%vu.length];this._blur(t,r-1,r,a,o)}e.autoClear=n}_blur(t,e,n,s,r){const a=this._pingPongRenderTarget;this._halfBlur(t,a,e,n,s,"latitudinal",r),this._halfBlur(a,t,n,n,s,"longitudinal",r)}_halfBlur(t,e,n,s,r,a,o){const l=this._renderer,c=this._blurMaterial;a!=="latitudinal"&&a!=="longitudinal"&&console.error("blur direction must be either latitudinal or longitudinal!");const h=3,u=new yt(this._lodPlanes[s],c),d=c.uniforms,f=this._sizeLods[n]-1,g=isFinite(r)?Math.PI/(2*f):2*Math.PI/(2*ps-1),_=r/g,m=isFinite(r)?1+Math.floor(h*_):ps;m>ps&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${ps}`);const p=[];let y=0;for(let E=0;E<ps;++E){const P=E/_,U=Math.exp(-P*P/2);p.push(U),E===0?y+=U:E<m&&(y+=2*U)}for(let E=0;E<p.length;E++)p[E]=p[E]/y;d.envMap.value=t.texture,d.samples.value=m,d.weights.value=p,d.latitudinal.value=a==="latitudinal",o&&(d.poleAxis.value=o);const{_lodMax:x}=this;d.dTheta.value=g,d.mipInt.value=x-n;const S=this._sizeLods[s],L=3*S*(s>x-Ys?s-x+Ys:0),T=4*(this._cubeSize-S);wa(e,L,T,3*S,2*S),l.setRenderTarget(e),l.render(u,ul)}}function Qv(i){const t=[],e=[],n=[];let s=i;const r=i-Ys+1+mu.length;for(let a=0;a<r;a++){const o=Math.pow(2,s);e.push(o);let l=1/o;a>i-Ys?l=mu[a-i+Ys-1]:a===0&&(l=0),n.push(l);const c=1/(o-2),h=-c,u=1+c,d=[h,h,u,h,u,u,h,h,u,u,h,u],f=6,g=6,_=3,m=2,p=1,y=new Float32Array(_*g*f),x=new Float32Array(m*g*f),S=new Float32Array(p*g*f);for(let T=0;T<f;T++){const E=T%3*2/3-1,P=T>2?0:-1,U=[E,P,0,E+2/3,P,0,E+2/3,P+1,0,E,P,0,E+2/3,P+1,0,E,P+1,0];y.set(U,_*g*T),x.set(d,m*g*T);const v=[T,T,T,T,T,T];S.set(v,p*g*T)}const L=new cn;L.setAttribute("position",new oi(y,_)),L.setAttribute("uv",new oi(x,m)),L.setAttribute("faceIndex",new oi(S,p)),t.push(L),s>Ys&&s--}return{lodPlanes:t,sizeLods:e,sigmas:n}}function _u(i,t,e){const n=new Yn(i,t,e);return n.texture.mapping=To,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function wa(i,t,e,n,s){i.viewport.set(t,e,n,s),i.scissor.set(t,e,n,s)}function t_(i,t,e){const n=new Float32Array(ps),s=new R(0,1,0);return new Je({name:"SphericalGaussianBlur",defines:{n:ps,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${i}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:s}},vertexShader:ch(),fragmentShader:`
3588
+ }`,Wt={alphahash_fragment:H0,alphahash_pars_fragment:V0,alphamap_fragment:G0,alphamap_pars_fragment:$0,alphatest_fragment:W0,alphatest_pars_fragment:X0,aomap_fragment:j0,aomap_pars_fragment:q0,batching_pars_vertex:Y0,batching_vertex:K0,begin_vertex:Z0,beginnormal_vertex:J0,bsdfs:Q0,iridescence_fragment:tg,bumpmap_pars_fragment:eg,clipping_planes_fragment:ng,clipping_planes_pars_fragment:ig,clipping_planes_pars_vertex:sg,clipping_planes_vertex:rg,color_fragment:ag,color_pars_fragment:og,color_pars_vertex:lg,color_vertex:cg,common:hg,cube_uv_reflection_fragment:ug,defaultnormal_vertex:dg,displacementmap_pars_vertex:fg,displacementmap_vertex:pg,emissivemap_fragment:mg,emissivemap_pars_fragment:gg,colorspace_fragment:vg,colorspace_pars_fragment:_g,envmap_fragment:xg,envmap_common_pars_fragment:yg,envmap_pars_fragment:Mg,envmap_pars_vertex:bg,envmap_physical_pars_fragment:Ig,envmap_vertex:Sg,fog_vertex:wg,fog_pars_vertex:Eg,fog_fragment:Tg,fog_pars_fragment:Ag,gradientmap_pars_fragment:Cg,lightmap_pars_fragment:Rg,lights_lambert_fragment:Pg,lights_lambert_pars_fragment:Lg,lights_pars_begin:Dg,lights_toon_fragment:kg,lights_toon_pars_fragment:Ng,lights_phong_fragment:Ug,lights_phong_pars_fragment:Og,lights_physical_fragment:Fg,lights_physical_pars_fragment:zg,lights_fragment_begin:Bg,lights_fragment_maps:Hg,lights_fragment_end:Vg,logdepthbuf_fragment:Gg,logdepthbuf_pars_fragment:$g,logdepthbuf_pars_vertex:Wg,logdepthbuf_vertex:Xg,map_fragment:jg,map_pars_fragment:qg,map_particle_fragment:Yg,map_particle_pars_fragment:Kg,metalnessmap_fragment:Zg,metalnessmap_pars_fragment:Jg,morphinstance_vertex:Qg,morphcolor_vertex:tv,morphnormal_vertex:ev,morphtarget_pars_vertex:nv,morphtarget_vertex:iv,normal_fragment_begin:sv,normal_fragment_maps:rv,normal_pars_fragment:av,normal_pars_vertex:ov,normal_vertex:lv,normalmap_pars_fragment:cv,clearcoat_normal_fragment_begin:hv,clearcoat_normal_fragment_maps:uv,clearcoat_pars_fragment:dv,iridescence_pars_fragment:fv,opaque_fragment:pv,packing:mv,premultiplied_alpha_fragment:gv,project_vertex:vv,dithering_fragment:_v,dithering_pars_fragment:xv,roughnessmap_fragment:yv,roughnessmap_pars_fragment:Mv,shadowmap_pars_fragment:bv,shadowmap_pars_vertex:Sv,shadowmap_vertex:wv,shadowmask_pars_fragment:Ev,skinbase_vertex:Tv,skinning_pars_vertex:Av,skinning_vertex:Cv,skinnormal_vertex:Rv,specularmap_fragment:Pv,specularmap_pars_fragment:Lv,tonemapping_fragment:Dv,tonemapping_pars_fragment:Iv,transmission_fragment:kv,transmission_pars_fragment:Nv,uv_pars_fragment:Uv,uv_pars_vertex:Ov,uv_vertex:Fv,worldpos_vertex:zv,background_vert:Bv,background_frag:Hv,backgroundCube_vert:Vv,backgroundCube_frag:Gv,cube_vert:$v,cube_frag:Wv,depth_vert:Xv,depth_frag:jv,distanceRGBA_vert:qv,distanceRGBA_frag:Yv,equirect_vert:Kv,equirect_frag:Zv,linedashed_vert:Jv,linedashed_frag:Qv,meshbasic_vert:t_,meshbasic_frag:e_,meshlambert_vert:n_,meshlambert_frag:i_,meshmatcap_vert:s_,meshmatcap_frag:r_,meshnormal_vert:a_,meshnormal_frag:o_,meshphong_vert:l_,meshphong_frag:c_,meshphysical_vert:h_,meshphysical_frag:u_,meshtoon_vert:d_,meshtoon_frag:f_,points_vert:p_,points_frag:m_,shadow_vert:g_,shadow_frag:v_,sprite_vert:__,sprite_frag:x_},ut={common:{diffuse:{value:new Zt(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Xt},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Xt}},envmap:{envMap:{value:null},envMapRotation:{value:new Xt},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Xt}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Xt}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Xt},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Xt},normalScale:{value:new rt(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Xt},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Xt}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Xt}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Xt}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Zt(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Zt(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0},uvTransform:{value:new Xt}},sprite:{diffuse:{value:new Zt(16777215)},opacity:{value:1},center:{value:new rt(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Xt},alphaMap:{value:null},alphaMapTransform:{value:new Xt},alphaTest:{value:0}}},ai={basic:{uniforms:ln([ut.common,ut.specularmap,ut.envmap,ut.aomap,ut.lightmap,ut.fog]),vertexShader:Wt.meshbasic_vert,fragmentShader:Wt.meshbasic_frag},lambert:{uniforms:ln([ut.common,ut.specularmap,ut.envmap,ut.aomap,ut.lightmap,ut.emissivemap,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.fog,ut.lights,{emissive:{value:new Zt(0)}}]),vertexShader:Wt.meshlambert_vert,fragmentShader:Wt.meshlambert_frag},phong:{uniforms:ln([ut.common,ut.specularmap,ut.envmap,ut.aomap,ut.lightmap,ut.emissivemap,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.fog,ut.lights,{emissive:{value:new Zt(0)},specular:{value:new Zt(1118481)},shininess:{value:30}}]),vertexShader:Wt.meshphong_vert,fragmentShader:Wt.meshphong_frag},standard:{uniforms:ln([ut.common,ut.envmap,ut.aomap,ut.lightmap,ut.emissivemap,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.roughnessmap,ut.metalnessmap,ut.fog,ut.lights,{emissive:{value:new Zt(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Wt.meshphysical_vert,fragmentShader:Wt.meshphysical_frag},toon:{uniforms:ln([ut.common,ut.aomap,ut.lightmap,ut.emissivemap,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.gradientmap,ut.fog,ut.lights,{emissive:{value:new Zt(0)}}]),vertexShader:Wt.meshtoon_vert,fragmentShader:Wt.meshtoon_frag},matcap:{uniforms:ln([ut.common,ut.bumpmap,ut.normalmap,ut.displacementmap,ut.fog,{matcap:{value:null}}]),vertexShader:Wt.meshmatcap_vert,fragmentShader:Wt.meshmatcap_frag},points:{uniforms:ln([ut.points,ut.fog]),vertexShader:Wt.points_vert,fragmentShader:Wt.points_frag},dashed:{uniforms:ln([ut.common,ut.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Wt.linedashed_vert,fragmentShader:Wt.linedashed_frag},depth:{uniforms:ln([ut.common,ut.displacementmap]),vertexShader:Wt.depth_vert,fragmentShader:Wt.depth_frag},normal:{uniforms:ln([ut.common,ut.bumpmap,ut.normalmap,ut.displacementmap,{opacity:{value:1}}]),vertexShader:Wt.meshnormal_vert,fragmentShader:Wt.meshnormal_frag},sprite:{uniforms:ln([ut.sprite,ut.fog]),vertexShader:Wt.sprite_vert,fragmentShader:Wt.sprite_frag},background:{uniforms:{uvTransform:{value:new Xt},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Wt.background_vert,fragmentShader:Wt.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Xt}},vertexShader:Wt.backgroundCube_vert,fragmentShader:Wt.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Wt.cube_vert,fragmentShader:Wt.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Wt.equirect_vert,fragmentShader:Wt.equirect_frag},distanceRGBA:{uniforms:ln([ut.common,ut.displacementmap,{referencePosition:{value:new R},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Wt.distanceRGBA_vert,fragmentShader:Wt.distanceRGBA_frag},shadow:{uniforms:ln([ut.lights,ut.fog,{color:{value:new Zt(0)},opacity:{value:1}}]),vertexShader:Wt.shadow_vert,fragmentShader:Wt.shadow_frag}};ai.physical={uniforms:ln([ai.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Xt},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Xt},clearcoatNormalScale:{value:new rt(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Xt},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Xt},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Xt},sheen:{value:0},sheenColor:{value:new Zt(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Xt},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Xt},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Xt},transmissionSamplerSize:{value:new rt},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Xt},attenuationDistance:{value:0},attenuationColor:{value:new Zt(0)},specularColor:{value:new Zt(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Xt},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Xt},anisotropyVector:{value:new rt},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Xt}}]),vertexShader:Wt.meshphysical_vert,fragmentShader:Wt.meshphysical_frag};const Da={r:0,b:0,g:0},ms=new mi,y_=new fe;function M_(i,t,e,n,s,r,a){const o=new Zt(0);let l=r===!0?0:1,c,h,u=null,d=0,f=null;function g(y){let x=y.isScene===!0?y.background:null;return x&&x.isTexture&&(x=(y.backgroundBlurriness>0?e:t).get(x)),x}function _(y){let x=!1;const S=g(y);S===null?p(o,l):S&&S.isColor&&(p(S,1),x=!0);const L=i.xr.getEnvironmentBlendMode();L==="additive"?n.buffers.color.setClear(0,0,0,1,a):L==="alpha-blend"&&n.buffers.color.setClear(0,0,0,0,a),(i.autoClear||x)&&(n.buffers.depth.setTest(!0),n.buffers.depth.setMask(!0),n.buffers.color.setMask(!0),i.clear(i.autoClearColor,i.autoClearDepth,i.autoClearStencil))}function m(y,x){const S=g(x);S&&(S.isCubeTexture||S.mapping===Uo)?(h===void 0&&(h=new yt(new Ze(1,1,1),new nn({name:"BackgroundCubeMaterial",uniforms:br(ai.backgroundCube.uniforms),vertexShader:ai.backgroundCube.vertexShader,fragmentShader:ai.backgroundCube.fragmentShader,side:un,depthTest:!1,depthWrite:!1,fog:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(L,T,E){this.matrixWorld.copyPosition(E.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),s.update(h)),ms.copy(x.backgroundRotation),ms.x*=-1,ms.y*=-1,ms.z*=-1,S.isCubeTexture&&S.isRenderTargetTexture===!1&&(ms.y*=-1,ms.z*=-1),h.material.uniforms.envMap.value=S,h.material.uniforms.flipEnvMap.value=S.isCubeTexture&&S.isRenderTargetTexture===!1?-1:1,h.material.uniforms.backgroundBlurriness.value=x.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,h.material.uniforms.backgroundRotation.value.setFromMatrix4(y_.makeRotationFromEuler(ms)),h.material.toneMapped=oe.getTransfer(S.colorSpace)!==ye,(u!==S||d!==S.version||f!==i.toneMapping)&&(h.material.needsUpdate=!0,u=S,d=S.version,f=i.toneMapping),h.layers.enableAll(),y.unshift(h,h.geometry,h.material,0,0,null)):S&&S.isTexture&&(c===void 0&&(c=new yt(new gi(2,2),new nn({name:"BackgroundMaterial",uniforms:br(ai.background.uniforms),vertexShader:ai.background.vertexShader,fragmentShader:ai.background.fragmentShader,side:os,depthTest:!1,depthWrite:!1,fog:!1})),c.geometry.deleteAttribute("normal"),Object.defineProperty(c.material,"map",{get:function(){return this.uniforms.t2D.value}}),s.update(c)),c.material.uniforms.t2D.value=S,c.material.uniforms.backgroundIntensity.value=x.backgroundIntensity,c.material.toneMapped=oe.getTransfer(S.colorSpace)!==ye,S.matrixAutoUpdate===!0&&S.updateMatrix(),c.material.uniforms.uvTransform.value.copy(S.matrix),(u!==S||d!==S.version||f!==i.toneMapping)&&(c.material.needsUpdate=!0,u=S,d=S.version,f=i.toneMapping),c.layers.enableAll(),y.unshift(c,c.geometry,c.material,0,0,null))}function p(y,x){y.getRGB(Da,Bf(i)),n.buffers.color.setClear(Da.r,Da.g,Da.b,x,a)}return{getClearColor:function(){return o},setClearColor:function(y,x=1){o.set(y),l=x,p(o,l)},getClearAlpha:function(){return l},setClearAlpha:function(y){l=y,p(o,l)},render:_,addToRenderList:m}}function b_(i,t){const e=i.getParameter(i.MAX_VERTEX_ATTRIBS),n={},s=d(null);let r=s,a=!1;function o(v,b,I,O,$){let K=!1;const z=u(O,I,b);r!==z&&(r=z,c(r.object)),K=f(v,O,I,$),K&&g(v,O,I,$),$!==null&&t.update($,i.ELEMENT_ARRAY_BUFFER),(K||a)&&(a=!1,S(v,b,I,O),$!==null&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,t.get($).buffer))}function l(){return i.createVertexArray()}function c(v){return i.bindVertexArray(v)}function h(v){return i.deleteVertexArray(v)}function u(v,b,I){const O=I.wireframe===!0;let $=n[v.id];$===void 0&&($={},n[v.id]=$);let K=$[b.id];K===void 0&&(K={},$[b.id]=K);let z=K[O];return z===void 0&&(z=d(l()),K[O]=z),z}function d(v){const b=[],I=[],O=[];for(let $=0;$<e;$++)b[$]=0,I[$]=0,O[$]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:b,enabledAttributes:I,attributeDivisors:O,object:v,attributes:{},index:null}}function f(v,b,I,O){const $=r.attributes,K=b.attributes;let z=0;const Z=I.getAttributes();for(const V in Z)if(Z[V].location>=0){const ct=$[V];let _t=K[V];if(_t===void 0&&(V==="instanceMatrix"&&v.instanceMatrix&&(_t=v.instanceMatrix),V==="instanceColor"&&v.instanceColor&&(_t=v.instanceColor)),ct===void 0||ct.attribute!==_t||_t&&ct.data!==_t.data)return!0;z++}return r.attributesNum!==z||r.index!==O}function g(v,b,I,O){const $={},K=b.attributes;let z=0;const Z=I.getAttributes();for(const V in Z)if(Z[V].location>=0){let ct=K[V];ct===void 0&&(V==="instanceMatrix"&&v.instanceMatrix&&(ct=v.instanceMatrix),V==="instanceColor"&&v.instanceColor&&(ct=v.instanceColor));const _t={};_t.attribute=ct,ct&&ct.data&&(_t.data=ct.data),$[V]=_t,z++}r.attributes=$,r.attributesNum=z,r.index=O}function _(){const v=r.newAttributes;for(let b=0,I=v.length;b<I;b++)v[b]=0}function m(v){p(v,0)}function p(v,b){const I=r.newAttributes,O=r.enabledAttributes,$=r.attributeDivisors;I[v]=1,O[v]===0&&(i.enableVertexAttribArray(v),O[v]=1),$[v]!==b&&(i.vertexAttribDivisor(v,b),$[v]=b)}function y(){const v=r.newAttributes,b=r.enabledAttributes;for(let I=0,O=b.length;I<O;I++)b[I]!==v[I]&&(i.disableVertexAttribArray(I),b[I]=0)}function x(v,b,I,O,$,K,z){z===!0?i.vertexAttribIPointer(v,b,I,$,K):i.vertexAttribPointer(v,b,I,O,$,K)}function S(v,b,I,O){_();const $=O.attributes,K=I.getAttributes(),z=b.defaultAttributeValues;for(const Z in K){const V=K[Z];if(V.location>=0){let at=$[Z];if(at===void 0&&(Z==="instanceMatrix"&&v.instanceMatrix&&(at=v.instanceMatrix),Z==="instanceColor"&&v.instanceColor&&(at=v.instanceColor)),at!==void 0){const ct=at.normalized,_t=at.itemSize,$t=t.get(at);if($t===void 0)continue;const Jt=$t.buffer,X=$t.type,et=$t.bytesPerElement,ft=X===i.INT||X===i.UNSIGNED_INT||at.gpuType===uh;if(at.isInterleavedBufferAttribute){const ot=at.data,At=ot.stride,Tt=at.offset;if(ot.isInstancedInterleavedBuffer){for(let zt=0;zt<V.locationSize;zt++)p(V.location+zt,ot.meshPerAttribute);v.isInstancedMesh!==!0&&O._maxInstanceCount===void 0&&(O._maxInstanceCount=ot.meshPerAttribute*ot.count)}else for(let zt=0;zt<V.locationSize;zt++)m(V.location+zt);i.bindBuffer(i.ARRAY_BUFFER,Jt);for(let zt=0;zt<V.locationSize;zt++)x(V.location+zt,_t/V.locationSize,X,ct,At*et,(Tt+_t/V.locationSize*zt)*et,ft)}else{if(at.isInstancedBufferAttribute){for(let ot=0;ot<V.locationSize;ot++)p(V.location+ot,at.meshPerAttribute);v.isInstancedMesh!==!0&&O._maxInstanceCount===void 0&&(O._maxInstanceCount=at.meshPerAttribute*at.count)}else for(let ot=0;ot<V.locationSize;ot++)m(V.location+ot);i.bindBuffer(i.ARRAY_BUFFER,Jt);for(let ot=0;ot<V.locationSize;ot++)x(V.location+ot,_t/V.locationSize,X,ct,_t*et,_t/V.locationSize*ot*et,ft)}}else if(z!==void 0){const ct=z[Z];if(ct!==void 0)switch(ct.length){case 2:i.vertexAttrib2fv(V.location,ct);break;case 3:i.vertexAttrib3fv(V.location,ct);break;case 4:i.vertexAttrib4fv(V.location,ct);break;default:i.vertexAttrib1fv(V.location,ct)}}}}y()}function L(){P();for(const v in n){const b=n[v];for(const I in b){const O=b[I];for(const $ in O)h(O[$].object),delete O[$];delete b[I]}delete n[v]}}function T(v){if(n[v.id]===void 0)return;const b=n[v.id];for(const I in b){const O=b[I];for(const $ in O)h(O[$].object),delete O[$];delete b[I]}delete n[v.id]}function E(v){for(const b in n){const I=n[b];if(I[v.id]===void 0)continue;const O=I[v.id];for(const $ in O)h(O[$].object),delete O[$];delete I[v.id]}}function P(){U(),a=!0,r!==s&&(r=s,c(r.object))}function U(){s.geometry=null,s.program=null,s.wireframe=!1}return{setup:o,reset:P,resetDefaultState:U,dispose:L,releaseStatesOfGeometry:T,releaseStatesOfProgram:E,initAttributes:_,enableAttribute:m,disableUnusedAttributes:y}}function S_(i,t,e){let n;function s(c){n=c}function r(c,h){i.drawArrays(n,c,h),e.update(h,n,1)}function a(c,h,u){u!==0&&(i.drawArraysInstanced(n,c,h,u),e.update(h,n,u))}function o(c,h,u){if(u===0)return;t.get("WEBGL_multi_draw").multiDrawArraysWEBGL(n,c,0,h,0,u);let f=0;for(let g=0;g<u;g++)f+=h[g];e.update(f,n,1)}function l(c,h,u,d){if(u===0)return;const f=t.get("WEBGL_multi_draw");if(f===null)for(let g=0;g<c.length;g++)a(c[g],h[g],d[g]);else{f.multiDrawArraysInstancedWEBGL(n,c,0,h,0,d,0,u);let g=0;for(let _=0;_<u;_++)g+=h[_];for(let _=0;_<d.length;_++)e.update(g,n,d[_])}}this.setMode=s,this.render=r,this.renderInstances=a,this.renderMultiDraw=o,this.renderMultiDrawInstances=l}function w_(i,t,e,n){let s;function r(){if(s!==void 0)return s;if(t.has("EXT_texture_filter_anisotropic")===!0){const E=t.get("EXT_texture_filter_anisotropic");s=i.getParameter(E.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else s=0;return s}function a(E){return!(E!==Nn&&n.convert(E)!==i.getParameter(i.IMPLEMENTATION_COLOR_READ_FORMAT))}function o(E){const P=E===Ui&&(t.has("EXT_color_buffer_half_float")||t.has("EXT_color_buffer_float"));return!(E!==pi&&n.convert(E)!==i.getParameter(i.IMPLEMENTATION_COLOR_READ_TYPE)&&E!==Ci&&!P)}function l(E){if(E==="highp"){if(i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.HIGH_FLOAT).precision>0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT).precision>0)return"highp";E="mediump"}return E==="mediump"&&i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.MEDIUM_FLOAT).precision>0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let c=e.precision!==void 0?e.precision:"highp";const h=l(c);h!==c&&(console.warn("THREE.WebGLRenderer:",c,"not supported, using",h,"instead."),c=h);const u=e.logarithmicDepthBuffer===!0,d=e.reverseDepthBuffer===!0&&t.has("EXT_clip_control");if(d===!0){const E=t.get("EXT_clip_control");E.clipControlEXT(E.LOWER_LEFT_EXT,E.ZERO_TO_ONE_EXT)}const f=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),g=i.getParameter(i.MAX_VERTEX_TEXTURE_IMAGE_UNITS),_=i.getParameter(i.MAX_TEXTURE_SIZE),m=i.getParameter(i.MAX_CUBE_MAP_TEXTURE_SIZE),p=i.getParameter(i.MAX_VERTEX_ATTRIBS),y=i.getParameter(i.MAX_VERTEX_UNIFORM_VECTORS),x=i.getParameter(i.MAX_VARYING_VECTORS),S=i.getParameter(i.MAX_FRAGMENT_UNIFORM_VECTORS),L=g>0,T=i.getParameter(i.MAX_SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:r,getMaxPrecision:l,textureFormatReadable:a,textureTypeReadable:o,precision:c,logarithmicDepthBuffer:u,reverseDepthBuffer:d,maxTextures:f,maxVertexTextures:g,maxTextureSize:_,maxCubemapSize:m,maxAttributes:p,maxVertexUniforms:y,maxVaryings:x,maxFragmentUniforms:S,vertexTextures:L,maxSamples:T}}function E_(i){const t=this;let e=null,n=0,s=!1,r=!1;const a=new Ki,o=new Xt,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(u,d){const f=u.length!==0||d||n!==0||s;return s=d,n=u.length,f},this.beginShadows=function(){r=!0,h(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(u,d){e=h(u,d,0)},this.setState=function(u,d,f){const g=u.clippingPlanes,_=u.clipIntersection,m=u.clipShadows,p=i.get(u);if(!s||g===null||g.length===0||r&&!m)r?h(null):c();else{const y=r?0:n,x=y*4;let S=p.clippingState||null;l.value=S,S=h(g,d,x,f);for(let L=0;L!==x;++L)S[L]=e[L];p.clippingState=S,this.numIntersection=_?this.numPlanes:0,this.numPlanes+=y}};function c(){l.value!==e&&(l.value=e,l.needsUpdate=n>0),t.numPlanes=n,t.numIntersection=0}function h(u,d,f,g){const _=u!==null?u.length:0;let m=null;if(_!==0){if(m=l.value,g!==!0||m===null){const p=f+_*4,y=d.matrixWorldInverse;o.getNormalMatrix(y),(m===null||m.length<p)&&(m=new Float32Array(p));for(let x=0,S=f;x!==_;++x,S+=4)a.copy(u[x]).applyMatrix4(y,o),a.normal.toArray(m,S),m[S+3]=a.constant}l.value=m,l.needsUpdate=!0}return t.numPlanes=_,t.numIntersection=0,m}}function T_(i){let t=new WeakMap;function e(a,o){return o===_c?a.mapping=yr:o===xc&&(a.mapping=Mr),a}function n(a){if(a&&a.isTexture){const o=a.mapping;if(o===_c||o===xc)if(t.has(a)){const l=t.get(a).texture;return e(l,a.mapping)}else{const l=a.image;if(l&&l.height>0){const c=new O0(l.height);return c.fromEquirectangularTexture(i,a),t.set(a,c),a.addEventListener("dispose",s),e(c.texture,a.mapping)}else return null}}return a}function s(a){const o=a.target;o.removeEventListener("dispose",s);const l=t.get(o);l!==void 0&&(t.delete(o),l.dispose())}function r(){t=new WeakMap}return{get:n,dispose:r}}class wh extends Hf{constructor(t=-1,e=1,n=1,s=-1,r=.1,a=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=n,this.bottom=s,this.near=r,this.far=a,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=t.view===null?null:Object.assign({},t.view),this}setViewOffset(t,e,n,s,r,a){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=s,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,s=(this.top+this.bottom)/2;let r=n-t,a=n+t,o=s+e,l=s-e;if(this.view!==null&&this.view.enabled){const c=(this.right-this.left)/this.view.fullWidth/this.zoom,h=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=c*this.view.offsetX,a=r+c*this.view.width,o-=h*this.view.offsetY,l=o-h*this.view.height}this.projectionMatrix.makeOrthographic(r,a,o,l,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,this.view!==null&&(e.object.view=Object.assign({},this.view)),e}}const sr=4,ku=[.125,.215,.35,.446,.526,.582],ys=20,Sl=new wh,Nu=new Zt;let wl=null,El=0,Tl=0,Al=!1;const _s=(1+Math.sqrt(5))/2,Ys=1/_s,Uu=[new R(-_s,Ys,0),new R(_s,Ys,0),new R(-Ys,0,_s),new R(Ys,0,_s),new R(0,_s,-Ys),new R(0,_s,Ys),new R(-1,1,-1),new R(1,1,-1),new R(-1,1,1),new R(1,1,1)];class jc{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,n=.1,s=100){wl=this._renderer.getRenderTarget(),El=this._renderer.getActiveCubeFace(),Tl=this._renderer.getActiveMipmapLevel(),Al=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,n,s,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=zu(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Fu(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let t=0;t<this._lodPlanes.length;t++)this._lodPlanes[t].dispose()}_cleanup(t){this._renderer.setRenderTarget(wl,El,Tl),this._renderer.xr.enabled=Al,t.scissorTest=!1,Ia(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===yr||t.mapping===Mr?this._setSize(t.image.length===0?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),wl=this._renderer.getRenderTarget(),El=this._renderer.getActiveCubeFace(),Tl=this._renderer.getActiveMipmapLevel(),Al=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const n=e||this._allocateTargets();return this._textureToCubeUV(t,n),this._applyPMREM(n),this._cleanup(n),n}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,n={magFilter:qn,minFilter:qn,generateMipmaps:!1,type:Ui,format:Nn,colorSpace:cs,depthBuffer:!1},s=Ou(t,e,n);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Ou(t,e,n);const{_lodMax:r}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas}=A_(r)),this._blurMaterial=C_(r,t,e)}return s}_compileMaterial(t){const e=new yt(this._lodPlanes[0],t);this._renderer.compile(e,Sl)}_sceneToCubeUV(t,e,n,s){const o=new Cn(90,1,e,n),l=[1,-1,1,1,1,1],c=[1,1,1,-1,-1,-1],h=this._renderer,u=h.autoClear,d=h.toneMapping;h.getClearColor(Nu),h.toneMapping=ss,h.autoClear=!1;const f=new dn({name:"PMREM.Background",side:un,depthWrite:!1,depthTest:!1}),g=new yt(new Ze,f);let _=!1;const m=t.background;m?m.isColor&&(f.color.copy(m),t.background=null,_=!0):(f.color.copy(Nu),_=!0);for(let p=0;p<6;p++){const y=p%3;y===0?(o.up.set(0,l[p],0),o.lookAt(c[p],0,0)):y===1?(o.up.set(0,0,l[p]),o.lookAt(0,c[p],0)):(o.up.set(0,l[p],0),o.lookAt(0,0,c[p]));const x=this._cubeSize;Ia(s,y*x,p>2?x:0,x,x),h.setRenderTarget(s),_&&h.render(g,o),h.render(t,o)}g.geometry.dispose(),g.material.dispose(),h.toneMapping=d,h.autoClear=u,t.background=m}_textureToCubeUV(t,e){const n=this._renderer,s=t.mapping===yr||t.mapping===Mr;s?(this._cubemapMaterial===null&&(this._cubemapMaterial=zu()),this._cubemapMaterial.uniforms.flipEnvMap.value=t.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=Fu());const r=s?this._cubemapMaterial:this._equirectMaterial,a=new yt(this._lodPlanes[0],r),o=r.uniforms;o.envMap.value=t;const l=this._cubeSize;Ia(e,0,0,3*l,2*l),n.setRenderTarget(e),n.render(a,Sl)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;const s=this._lodPlanes.length;for(let r=1;r<s;r++){const a=Math.sqrt(this._sigmas[r]*this._sigmas[r]-this._sigmas[r-1]*this._sigmas[r-1]),o=Uu[(s-r-1)%Uu.length];this._blur(t,r-1,r,a,o)}e.autoClear=n}_blur(t,e,n,s,r){const a=this._pingPongRenderTarget;this._halfBlur(t,a,e,n,s,"latitudinal",r),this._halfBlur(a,t,n,n,s,"longitudinal",r)}_halfBlur(t,e,n,s,r,a,o){const l=this._renderer,c=this._blurMaterial;a!=="latitudinal"&&a!=="longitudinal"&&console.error("blur direction must be either latitudinal or longitudinal!");const h=3,u=new yt(this._lodPlanes[s],c),d=c.uniforms,f=this._sizeLods[n]-1,g=isFinite(r)?Math.PI/(2*f):2*Math.PI/(2*ys-1),_=r/g,m=isFinite(r)?1+Math.floor(h*_):ys;m>ys&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${ys}`);const p=[];let y=0;for(let E=0;E<ys;++E){const P=E/_,U=Math.exp(-P*P/2);p.push(U),E===0?y+=U:E<m&&(y+=2*U)}for(let E=0;E<p.length;E++)p[E]=p[E]/y;d.envMap.value=t.texture,d.samples.value=m,d.weights.value=p,d.latitudinal.value=a==="latitudinal",o&&(d.poleAxis.value=o);const{_lodMax:x}=this;d.dTheta.value=g,d.mipInt.value=x-n;const S=this._sizeLods[s],L=3*S*(s>x-sr?s-x+sr:0),T=4*(this._cubeSize-S);Ia(e,L,T,3*S,2*S),l.setRenderTarget(e),l.render(u,Sl)}}function A_(i){const t=[],e=[],n=[];let s=i;const r=i-sr+1+ku.length;for(let a=0;a<r;a++){const o=Math.pow(2,s);e.push(o);let l=1/o;a>i-sr?l=ku[a-i+sr-1]:a===0&&(l=0),n.push(l);const c=1/(o-2),h=-c,u=1+c,d=[h,h,u,h,u,u,h,h,u,u,h,u],f=6,g=6,_=3,m=2,p=1,y=new Float32Array(_*g*f),x=new Float32Array(m*g*f),S=new Float32Array(p*g*f);for(let T=0;T<f;T++){const E=T%3*2/3-1,P=T>2?0:-1,U=[E,P,0,E+2/3,P,0,E+2/3,P+1,0,E,P,0,E+2/3,P+1,0,E,P+1,0];y.set(U,_*g*T),x.set(d,m*g*T);const v=[T,T,T,T,T,T];S.set(v,p*g*T)}const L=new fn;L.setAttribute("position",new ui(y,_)),L.setAttribute("uv",new ui(x,m)),L.setAttribute("faceIndex",new ui(S,p)),t.push(L),s>sr&&s--}return{lodPlanes:t,sizeLods:e,sigmas:n}}function Ou(i,t,e){const n=new Qn(i,t,e);return n.texture.mapping=Uo,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function Ia(i,t,e,n,s){i.viewport.set(t,e,n,s),i.scissor.set(t,e,n,s)}function C_(i,t,e){const n=new Float32Array(ys),s=new R(0,1,0);return new nn({name:"SphericalGaussianBlur",defines:{n:ys,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${i}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:s}},vertexShader:Eh(),fragmentShader:`
3589
3589
 
3590
3590
  precision mediump float;
3591
3591
  precision mediump int;
@@ -3645,7 +3645,7 @@ void main() {
3645
3645
  }
3646
3646
 
3647
3647
  }
3648
- `,blending:Xe,depthTest:!1,depthWrite:!1})}function xu(){return new Je({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:ch(),fragmentShader:`
3648
+ `,blending:Ye,depthTest:!1,depthWrite:!1})}function Fu(){return new nn({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:Eh(),fragmentShader:`
3649
3649
 
3650
3650
  precision mediump float;
3651
3651
  precision mediump int;
@@ -3664,7 +3664,7 @@ void main() {
3664
3664
  gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );
3665
3665
 
3666
3666
  }
3667
- `,blending:Xe,depthTest:!1,depthWrite:!1})}function yu(){return new Je({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:ch(),fragmentShader:`
3667
+ `,blending:Ye,depthTest:!1,depthWrite:!1})}function zu(){return new nn({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Eh(),fragmentShader:`
3668
3668
 
3669
3669
  precision mediump float;
3670
3670
  precision mediump int;
@@ -3680,7 +3680,7 @@ void main() {
3680
3680
  gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );
3681
3681
 
3682
3682
  }
3683
- `,blending:Xe,depthTest:!1,depthWrite:!1})}function ch(){return`
3683
+ `,blending:Ye,depthTest:!1,depthWrite:!1})}function Eh(){return`
3684
3684
 
3685
3685
  precision mediump float;
3686
3686
  precision mediump int;
@@ -3735,16 +3735,16 @@ void main() {
3735
3735
  gl_Position = vec4( position, 1.0 );
3736
3736
 
3737
3737
  }
3738
- `}function e_(i){let t=new WeakMap,e=null;function n(o){if(o&&o.isTexture){const l=o.mapping,c=l===sc||l===rc,h=l===ur||l===dr;if(c||h){let u=t.get(o);const d=u!==void 0?u.texture.pmremVersion:0;if(o.isRenderTargetTexture&&o.pmremVersion!==d)return e===null&&(e=new Ic(i)),u=c?e.fromEquirectangular(o,u):e.fromCubemap(o,u),u.texture.pmremVersion=o.pmremVersion,t.set(o,u),u.texture;if(u!==void 0)return u.texture;{const f=o.image;return c&&f&&f.height>0||h&&f&&s(f)?(e===null&&(e=new Ic(i)),u=c?e.fromEquirectangular(o):e.fromCubemap(o),u.texture.pmremVersion=o.pmremVersion,t.set(o,u),o.addEventListener("dispose",r),u.texture):null}}}return o}function s(o){let l=0;const c=6;for(let h=0;h<c;h++)o[h]!==void 0&&l++;return l===c}function r(o){const l=o.target;l.removeEventListener("dispose",r);const c=t.get(l);c!==void 0&&(t.delete(l),c.dispose())}function a(){t=new WeakMap,e!==null&&(e.dispose(),e=null)}return{get:n,dispose:a}}function n_(i){const t={};function e(n){if(t[n]!==void 0)return t[n];let s;switch(n){case"WEBGL_depth_texture":s=i.getExtension("WEBGL_depth_texture")||i.getExtension("MOZ_WEBGL_depth_texture")||i.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=i.getExtension("EXT_texture_filter_anisotropic")||i.getExtension("MOZ_EXT_texture_filter_anisotropic")||i.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":s=i.getExtension("WEBGL_compressed_texture_s3tc")||i.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||i.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":s=i.getExtension("WEBGL_compressed_texture_pvrtc")||i.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=i.getExtension(n)}return t[n]=s,s}return{has:function(n){return e(n)!==null},init:function(){e("EXT_color_buffer_float"),e("WEBGL_clip_cull_distance"),e("OES_texture_float_linear"),e("EXT_color_buffer_half_float"),e("WEBGL_multisampled_render_to_texture"),e("WEBGL_render_shared_exponent")},get:function(n){const s=e(n);return s===null&&Za("THREE.WebGLRenderer: "+n+" extension not supported."),s}}}function i_(i,t,e,n){const s={},r=new WeakMap;function a(u){const d=u.target;d.index!==null&&t.remove(d.index);for(const g in d.attributes)t.remove(d.attributes[g]);for(const g in d.morphAttributes){const _=d.morphAttributes[g];for(let m=0,p=_.length;m<p;m++)t.remove(_[m])}d.removeEventListener("dispose",a),delete s[d.id];const f=r.get(d);f&&(t.remove(f),r.delete(d)),n.releaseStatesOfGeometry(d),d.isInstancedBufferGeometry===!0&&delete d._maxInstanceCount,e.memory.geometries--}function o(u,d){return s[d.id]===!0||(d.addEventListener("dispose",a),s[d.id]=!0,e.memory.geometries++),d}function l(u){const d=u.attributes;for(const g in d)t.update(d[g],i.ARRAY_BUFFER);const f=u.morphAttributes;for(const g in f){const _=f[g];for(let m=0,p=_.length;m<p;m++)t.update(_[m],i.ARRAY_BUFFER)}}function c(u){const d=[],f=u.index,g=u.attributes.position;let _=0;if(f!==null){const y=f.array;_=f.version;for(let x=0,S=y.length;x<S;x+=3){const L=y[x+0],T=y[x+1],E=y[x+2];d.push(L,T,T,E,E,L)}}else if(g!==void 0){const y=g.array;_=g.version;for(let x=0,S=y.length/3-1;x<S;x+=3){const L=x+0,T=x+1,E=x+2;d.push(L,T,T,E,E,L)}}else return;const m=new(hf(d)?mf:pf)(d,1);m.version=_;const p=r.get(u);p&&t.remove(p),r.set(u,m)}function h(u){const d=r.get(u);if(d){const f=u.index;f!==null&&d.version<f.version&&c(u)}else c(u);return r.get(u)}return{get:o,update:l,getWireframeAttribute:h}}function s_(i,t,e){let n;function s(d){n=d}let r,a;function o(d){r=d.type,a=d.bytesPerElement}function l(d,f){i.drawElements(n,f,r,d*a),e.update(f,n,1)}function c(d,f,g){g!==0&&(i.drawElementsInstanced(n,f,r,d*a,g),e.update(f,n,g))}function h(d,f,g){if(g===0)return;t.get("WEBGL_multi_draw").multiDrawElementsWEBGL(n,f,0,r,d,0,g);let m=0;for(let p=0;p<g;p++)m+=f[p];e.update(m,n,1)}function u(d,f,g,_){if(g===0)return;const m=t.get("WEBGL_multi_draw");if(m===null)for(let p=0;p<d.length;p++)c(d[p]/a,f[p],_[p]);else{m.multiDrawElementsInstancedWEBGL(n,f,0,r,d,0,_,0,g);let p=0;for(let y=0;y<g;y++)p+=f[y];for(let y=0;y<_.length;y++)e.update(p,n,_[y])}}this.setMode=s,this.setIndex=o,this.render=l,this.renderInstances=c,this.renderMultiDraw=h,this.renderMultiDrawInstances=u}function r_(i){const t={geometries:0,textures:0},e={frame:0,calls:0,triangles:0,points:0,lines:0};function n(r,a,o){switch(e.calls++,a){case i.TRIANGLES:e.triangles+=o*(r/3);break;case i.LINES:e.lines+=o*(r/2);break;case i.LINE_STRIP:e.lines+=o*(r-1);break;case i.LINE_LOOP:e.lines+=o*r;break;case i.POINTS:e.points+=o*r;break;default:console.error("THREE.WebGLInfo: Unknown draw mode:",a);break}}function s(){e.calls=0,e.triangles=0,e.points=0,e.lines=0}return{memory:t,render:e,programs:null,autoReset:!0,reset:s,update:n}}function a_(i,t,e){const n=new WeakMap,s=new me;function r(a,o,l){const c=a.morphTargetInfluences,h=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,u=h!==void 0?h.length:0;let d=n.get(o);if(d===void 0||d.count!==u){let v=function(){P.dispose(),n.delete(o),o.removeEventListener("dispose",v)};var f=v;d!==void 0&&d.texture.dispose();const g=o.morphAttributes.position!==void 0,_=o.morphAttributes.normal!==void 0,m=o.morphAttributes.color!==void 0,p=o.morphAttributes.position||[],y=o.morphAttributes.normal||[],x=o.morphAttributes.color||[];let S=0;g===!0&&(S=1),_===!0&&(S=2),m===!0&&(S=3);let L=o.attributes.position.count*S,T=1;L>t.maxTextureSize&&(T=Math.ceil(L/t.maxTextureSize),L=t.maxTextureSize);const E=new Float32Array(L*T*4*u),P=new df(E,L,T,u);P.type=wi,P.needsUpdate=!0;const U=S*4;for(let b=0;b<u;b++){const I=p[b],O=y[b],$=x[b],Y=L*T*4*b;for(let z=0;z<I.count;z++){const K=z*U;g===!0&&(s.fromBufferAttribute(I,z),E[Y+K+0]=s.x,E[Y+K+1]=s.y,E[Y+K+2]=s.z,E[Y+K+3]=0),_===!0&&(s.fromBufferAttribute(O,z),E[Y+K+4]=s.x,E[Y+K+5]=s.y,E[Y+K+6]=s.z,E[Y+K+7]=0),m===!0&&(s.fromBufferAttribute($,z),E[Y+K+8]=s.x,E[Y+K+9]=s.y,E[Y+K+10]=s.z,E[Y+K+11]=$.itemSize===4?s.w:1)}}d={count:u,texture:P,size:new rt(L,T)},n.set(o,d),o.addEventListener("dispose",v)}if(a.isInstancedMesh===!0&&a.morphTexture!==null)l.getUniforms().setValue(i,"morphTexture",a.morphTexture,e);else{let g=0;for(let m=0;m<c.length;m++)g+=c[m];const _=o.morphTargetsRelative?1:1-g;l.getUniforms().setValue(i,"morphTargetBaseInfluence",_),l.getUniforms().setValue(i,"morphTargetInfluences",c)}l.getUniforms().setValue(i,"morphTargetsTexture",d.texture,e),l.getUniforms().setValue(i,"morphTargetsTextureSize",d.size)}return{update:r}}function o_(i,t,e,n){let s=new WeakMap;function r(l){const c=n.render.frame,h=l.geometry,u=t.get(l,h);if(s.get(u)!==c&&(t.update(u),s.set(u,c)),l.isInstancedMesh&&(l.hasEventListener("dispose",o)===!1&&l.addEventListener("dispose",o),s.get(l)!==c&&(e.update(l.instanceMatrix,i.ARRAY_BUFFER),l.instanceColor!==null&&e.update(l.instanceColor,i.ARRAY_BUFFER),s.set(l,c))),l.isSkinnedMesh){const d=l.skeleton;s.get(d)!==c&&(d.update(),s.set(d,c))}return u}function a(){s=new WeakMap}function o(l){const c=l.target;c.removeEventListener("dispose",o),e.remove(c.instanceMatrix),c.instanceColor!==null&&e.remove(c.instanceColor)}return{update:r,dispose:a}}class hh extends en{constructor(t,e,n,s,r,a,o,l,c,h=rr){if(h!==rr&&h!==ys)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");n===void 0&&h===rr&&(n=_s),n===void 0&&h===ys&&(n=xs),super(null,s,r,a,o,l,h,n,c),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=o!==void 0?o:tn,this.minFilter=l!==void 0?l:tn,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}const yf=new en,Mu=new hh(1,1),Mf=new df,bf=new qm,Sf=new _f,bu=[],Su=[],wu=new Float32Array(16),Eu=new Float32Array(9),Tu=new Float32Array(4);function _r(i,t,e){const n=i[0];if(n<=0||n>0)return i;const s=t*e;let r=bu[s];if(r===void 0&&(r=new Float32Array(s),bu[s]=r),t!==0){n.toArray(r,0);for(let a=1,o=0;a!==t;++a)o+=e,i[a].toArray(r,o)}return r}function Oe(i,t){if(i.length!==t.length)return!1;for(let e=0,n=i.length;e<n;e++)if(i[e]!==t[e])return!1;return!0}function Fe(i,t){for(let e=0,n=t.length;e<n;e++)i[e]=t[e]}function Co(i,t){let e=Su[t];e===void 0&&(e=new Int32Array(t),Su[t]=e);for(let n=0;n!==t;++n)e[n]=i.allocateTextureUnit();return e}function l_(i,t){const e=this.cache;e[0]!==t&&(i.uniform1f(this.addr,t),e[0]=t)}function c_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y)&&(i.uniform2f(this.addr,t.x,t.y),e[0]=t.x,e[1]=t.y);else{if(Oe(e,t))return;i.uniform2fv(this.addr,t),Fe(e,t)}}function h_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z)&&(i.uniform3f(this.addr,t.x,t.y,t.z),e[0]=t.x,e[1]=t.y,e[2]=t.z);else if(t.r!==void 0)(e[0]!==t.r||e[1]!==t.g||e[2]!==t.b)&&(i.uniform3f(this.addr,t.r,t.g,t.b),e[0]=t.r,e[1]=t.g,e[2]=t.b);else{if(Oe(e,t))return;i.uniform3fv(this.addr,t),Fe(e,t)}}function u_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z||e[3]!==t.w)&&(i.uniform4f(this.addr,t.x,t.y,t.z,t.w),e[0]=t.x,e[1]=t.y,e[2]=t.z,e[3]=t.w);else{if(Oe(e,t))return;i.uniform4fv(this.addr,t),Fe(e,t)}}function d_(i,t){const e=this.cache,n=t.elements;if(n===void 0){if(Oe(e,t))return;i.uniformMatrix2fv(this.addr,!1,t),Fe(e,t)}else{if(Oe(e,n))return;Tu.set(n),i.uniformMatrix2fv(this.addr,!1,Tu),Fe(e,n)}}function f_(i,t){const e=this.cache,n=t.elements;if(n===void 0){if(Oe(e,t))return;i.uniformMatrix3fv(this.addr,!1,t),Fe(e,t)}else{if(Oe(e,n))return;Eu.set(n),i.uniformMatrix3fv(this.addr,!1,Eu),Fe(e,n)}}function p_(i,t){const e=this.cache,n=t.elements;if(n===void 0){if(Oe(e,t))return;i.uniformMatrix4fv(this.addr,!1,t),Fe(e,t)}else{if(Oe(e,n))return;wu.set(n),i.uniformMatrix4fv(this.addr,!1,wu),Fe(e,n)}}function m_(i,t){const e=this.cache;e[0]!==t&&(i.uniform1i(this.addr,t),e[0]=t)}function g_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y)&&(i.uniform2i(this.addr,t.x,t.y),e[0]=t.x,e[1]=t.y);else{if(Oe(e,t))return;i.uniform2iv(this.addr,t),Fe(e,t)}}function v_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z)&&(i.uniform3i(this.addr,t.x,t.y,t.z),e[0]=t.x,e[1]=t.y,e[2]=t.z);else{if(Oe(e,t))return;i.uniform3iv(this.addr,t),Fe(e,t)}}function __(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z||e[3]!==t.w)&&(i.uniform4i(this.addr,t.x,t.y,t.z,t.w),e[0]=t.x,e[1]=t.y,e[2]=t.z,e[3]=t.w);else{if(Oe(e,t))return;i.uniform4iv(this.addr,t),Fe(e,t)}}function x_(i,t){const e=this.cache;e[0]!==t&&(i.uniform1ui(this.addr,t),e[0]=t)}function y_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y)&&(i.uniform2ui(this.addr,t.x,t.y),e[0]=t.x,e[1]=t.y);else{if(Oe(e,t))return;i.uniform2uiv(this.addr,t),Fe(e,t)}}function M_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z)&&(i.uniform3ui(this.addr,t.x,t.y,t.z),e[0]=t.x,e[1]=t.y,e[2]=t.z);else{if(Oe(e,t))return;i.uniform3uiv(this.addr,t),Fe(e,t)}}function b_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z||e[3]!==t.w)&&(i.uniform4ui(this.addr,t.x,t.y,t.z,t.w),e[0]=t.x,e[1]=t.y,e[2]=t.z,e[3]=t.w);else{if(Oe(e,t))return;i.uniform4uiv(this.addr,t),Fe(e,t)}}function S_(i,t,e){const n=this.cache,s=e.allocateTextureUnit();n[0]!==s&&(i.uniform1i(this.addr,s),n[0]=s);let r;this.type===i.SAMPLER_2D_SHADOW?(Mu.compareFunction=cf,r=Mu):r=yf,e.setTexture2D(t||r,s)}function w_(i,t,e){const n=this.cache,s=e.allocateTextureUnit();n[0]!==s&&(i.uniform1i(this.addr,s),n[0]=s),e.setTexture3D(t||bf,s)}function E_(i,t,e){const n=this.cache,s=e.allocateTextureUnit();n[0]!==s&&(i.uniform1i(this.addr,s),n[0]=s),e.setTextureCube(t||Sf,s)}function T_(i,t,e){const n=this.cache,s=e.allocateTextureUnit();n[0]!==s&&(i.uniform1i(this.addr,s),n[0]=s),e.setTexture2DArray(t||Mf,s)}function A_(i){switch(i){case 5126:return l_;case 35664:return c_;case 35665:return h_;case 35666:return u_;case 35674:return d_;case 35675:return f_;case 35676:return p_;case 5124:case 35670:return m_;case 35667:case 35671:return g_;case 35668:case 35672:return v_;case 35669:case 35673:return __;case 5125:return x_;case 36294:return y_;case 36295:return M_;case 36296:return b_;case 35678:case 36198:case 36298:case 36306:case 35682:return S_;case 35679:case 36299:case 36307:return w_;case 35680:case 36300:case 36308:case 36293:return E_;case 36289:case 36303:case 36311:case 36292:return T_}}function C_(i,t){i.uniform1fv(this.addr,t)}function R_(i,t){const e=_r(t,this.size,2);i.uniform2fv(this.addr,e)}function P_(i,t){const e=_r(t,this.size,3);i.uniform3fv(this.addr,e)}function L_(i,t){const e=_r(t,this.size,4);i.uniform4fv(this.addr,e)}function D_(i,t){const e=_r(t,this.size,4);i.uniformMatrix2fv(this.addr,!1,e)}function I_(i,t){const e=_r(t,this.size,9);i.uniformMatrix3fv(this.addr,!1,e)}function k_(i,t){const e=_r(t,this.size,16);i.uniformMatrix4fv(this.addr,!1,e)}function N_(i,t){i.uniform1iv(this.addr,t)}function U_(i,t){i.uniform2iv(this.addr,t)}function O_(i,t){i.uniform3iv(this.addr,t)}function F_(i,t){i.uniform4iv(this.addr,t)}function z_(i,t){i.uniform1uiv(this.addr,t)}function B_(i,t){i.uniform2uiv(this.addr,t)}function H_(i,t){i.uniform3uiv(this.addr,t)}function V_(i,t){i.uniform4uiv(this.addr,t)}function G_(i,t,e){const n=this.cache,s=t.length,r=Co(e,s);Oe(n,r)||(i.uniform1iv(this.addr,r),Fe(n,r));for(let a=0;a!==s;++a)e.setTexture2D(t[a]||yf,r[a])}function $_(i,t,e){const n=this.cache,s=t.length,r=Co(e,s);Oe(n,r)||(i.uniform1iv(this.addr,r),Fe(n,r));for(let a=0;a!==s;++a)e.setTexture3D(t[a]||bf,r[a])}function W_(i,t,e){const n=this.cache,s=t.length,r=Co(e,s);Oe(n,r)||(i.uniform1iv(this.addr,r),Fe(n,r));for(let a=0;a!==s;++a)e.setTextureCube(t[a]||Sf,r[a])}function X_(i,t,e){const n=this.cache,s=t.length,r=Co(e,s);Oe(n,r)||(i.uniform1iv(this.addr,r),Fe(n,r));for(let a=0;a!==s;++a)e.setTexture2DArray(t[a]||Mf,r[a])}function j_(i){switch(i){case 5126:return C_;case 35664:return R_;case 35665:return P_;case 35666:return L_;case 35674:return D_;case 35675:return I_;case 35676:return k_;case 5124:case 35670:return N_;case 35667:case 35671:return U_;case 35668:case 35672:return O_;case 35669:case 35673:return F_;case 5125:return z_;case 36294:return B_;case 36295:return H_;case 36296:return V_;case 35678:case 36198:case 36298:case 36306:case 35682:return G_;case 35679:case 36299:case 36307:return $_;case 35680:case 36300:case 36308:case 36293:return W_;case 36289:case 36303:case 36311:case 36292:return X_}}class q_{constructor(t,e,n){this.id=t,this.addr=n,this.cache=[],this.type=e.type,this.setValue=A_(e.type)}}class Y_{constructor(t,e,n){this.id=t,this.addr=n,this.cache=[],this.type=e.type,this.size=e.size,this.setValue=j_(e.type)}}class K_{constructor(t){this.id=t,this.seq=[],this.map={}}setValue(t,e,n){const s=this.seq;for(let r=0,a=s.length;r!==a;++r){const o=s[r];o.setValue(t,e[o.id],n)}}}const gl=/(\w+)(\])?(\[|\.)?/g;function Au(i,t){i.seq.push(t),i.map[t.id]=t}function Z_(i,t,e){const n=i.name,s=n.length;for(gl.lastIndex=0;;){const r=gl.exec(n),a=gl.lastIndex;let o=r[1];const l=r[2]==="]",c=r[3];if(l&&(o=o|0),c===void 0||c==="["&&a+2===s){Au(e,c===void 0?new q_(o,i,t):new Y_(o,i,t));break}else{let u=e.map[o];u===void 0&&(u=new K_(o),Au(e,u)),e=u}}}class Ja{constructor(t,e){this.seq=[],this.map={};const n=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);for(let s=0;s<n;++s){const r=t.getActiveUniform(e,s),a=t.getUniformLocation(e,r.name);Z_(r,a,this)}}setValue(t,e,n,s){const r=this.map[e];r!==void 0&&r.setValue(t,n,s)}setOptional(t,e,n){const s=e[n];s!==void 0&&this.setValue(t,n,s)}static upload(t,e,n,s){for(let r=0,a=e.length;r!==a;++r){const o=e[r],l=n[o.id];l.needsUpdate!==!1&&o.setValue(t,l.value,s)}}static seqWithValue(t,e){const n=[];for(let s=0,r=t.length;s!==r;++s){const a=t[s];a.id in e&&n.push(a)}return n}}function Cu(i,t,e){const n=i.createShader(t);return i.shaderSource(n,e),i.compileShader(n),n}const J_=37297;let Q_=0;function tx(i,t){const e=i.split(`
3738
+ `}function R_(i){let t=new WeakMap,e=null;function n(o){if(o&&o.isTexture){const l=o.mapping,c=l===_c||l===xc,h=l===yr||l===Mr;if(c||h){let u=t.get(o);const d=u!==void 0?u.texture.pmremVersion:0;if(o.isRenderTargetTexture&&o.pmremVersion!==d)return e===null&&(e=new jc(i)),u=c?e.fromEquirectangular(o,u):e.fromCubemap(o,u),u.texture.pmremVersion=o.pmremVersion,t.set(o,u),u.texture;if(u!==void 0)return u.texture;{const f=o.image;return c&&f&&f.height>0||h&&f&&s(f)?(e===null&&(e=new jc(i)),u=c?e.fromEquirectangular(o):e.fromCubemap(o),u.texture.pmremVersion=o.pmremVersion,t.set(o,u),o.addEventListener("dispose",r),u.texture):null}}}return o}function s(o){let l=0;const c=6;for(let h=0;h<c;h++)o[h]!==void 0&&l++;return l===c}function r(o){const l=o.target;l.removeEventListener("dispose",r);const c=t.get(l);c!==void 0&&(t.delete(l),c.dispose())}function a(){t=new WeakMap,e!==null&&(e.dispose(),e=null)}return{get:n,dispose:a}}function P_(i){const t={};function e(n){if(t[n]!==void 0)return t[n];let s;switch(n){case"WEBGL_depth_texture":s=i.getExtension("WEBGL_depth_texture")||i.getExtension("MOZ_WEBGL_depth_texture")||i.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=i.getExtension("EXT_texture_filter_anisotropic")||i.getExtension("MOZ_EXT_texture_filter_anisotropic")||i.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":s=i.getExtension("WEBGL_compressed_texture_s3tc")||i.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||i.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":s=i.getExtension("WEBGL_compressed_texture_pvrtc")||i.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=i.getExtension(n)}return t[n]=s,s}return{has:function(n){return e(n)!==null},init:function(){e("EXT_color_buffer_float"),e("WEBGL_clip_cull_distance"),e("OES_texture_float_linear"),e("EXT_color_buffer_half_float"),e("WEBGL_multisampled_render_to_texture"),e("WEBGL_render_shared_exponent")},get:function(n){const s=e(n);return s===null&&oo("THREE.WebGLRenderer: "+n+" extension not supported."),s}}}function L_(i,t,e,n){const s={},r=new WeakMap;function a(u){const d=u.target;d.index!==null&&t.remove(d.index);for(const g in d.attributes)t.remove(d.attributes[g]);for(const g in d.morphAttributes){const _=d.morphAttributes[g];for(let m=0,p=_.length;m<p;m++)t.remove(_[m])}d.removeEventListener("dispose",a),delete s[d.id];const f=r.get(d);f&&(t.remove(f),r.delete(d)),n.releaseStatesOfGeometry(d),d.isInstancedBufferGeometry===!0&&delete d._maxInstanceCount,e.memory.geometries--}function o(u,d){return s[d.id]===!0||(d.addEventListener("dispose",a),s[d.id]=!0,e.memory.geometries++),d}function l(u){const d=u.attributes;for(const g in d)t.update(d[g],i.ARRAY_BUFFER);const f=u.morphAttributes;for(const g in f){const _=f[g];for(let m=0,p=_.length;m<p;m++)t.update(_[m],i.ARRAY_BUFFER)}}function c(u){const d=[],f=u.index,g=u.attributes.position;let _=0;if(f!==null){const y=f.array;_=f.version;for(let x=0,S=y.length;x<S;x+=3){const L=y[x+0],T=y[x+1],E=y[x+2];d.push(L,T,T,E,E,L)}}else if(g!==void 0){const y=g.array;_=g.version;for(let x=0,S=y.length/3-1;x<S;x+=3){const L=x+0,T=x+1,E=x+2;d.push(L,T,T,E,E,L)}}else return;const m=new(kf(d)?zf:Ff)(d,1);m.version=_;const p=r.get(u);p&&t.remove(p),r.set(u,m)}function h(u){const d=r.get(u);if(d){const f=u.index;f!==null&&d.version<f.version&&c(u)}else c(u);return r.get(u)}return{get:o,update:l,getWireframeAttribute:h}}function D_(i,t,e){let n;function s(d){n=d}let r,a;function o(d){r=d.type,a=d.bytesPerElement}function l(d,f){i.drawElements(n,f,r,d*a),e.update(f,n,1)}function c(d,f,g){g!==0&&(i.drawElementsInstanced(n,f,r,d*a,g),e.update(f,n,g))}function h(d,f,g){if(g===0)return;t.get("WEBGL_multi_draw").multiDrawElementsWEBGL(n,f,0,r,d,0,g);let m=0;for(let p=0;p<g;p++)m+=f[p];e.update(m,n,1)}function u(d,f,g,_){if(g===0)return;const m=t.get("WEBGL_multi_draw");if(m===null)for(let p=0;p<d.length;p++)c(d[p]/a,f[p],_[p]);else{m.multiDrawElementsInstancedWEBGL(n,f,0,r,d,0,_,0,g);let p=0;for(let y=0;y<g;y++)p+=f[y];for(let y=0;y<_.length;y++)e.update(p,n,_[y])}}this.setMode=s,this.setIndex=o,this.render=l,this.renderInstances=c,this.renderMultiDraw=h,this.renderMultiDrawInstances=u}function I_(i){const t={geometries:0,textures:0},e={frame:0,calls:0,triangles:0,points:0,lines:0};function n(r,a,o){switch(e.calls++,a){case i.TRIANGLES:e.triangles+=o*(r/3);break;case i.LINES:e.lines+=o*(r/2);break;case i.LINE_STRIP:e.lines+=o*(r-1);break;case i.LINE_LOOP:e.lines+=o*r;break;case i.POINTS:e.points+=o*r;break;default:console.error("THREE.WebGLInfo: Unknown draw mode:",a);break}}function s(){e.calls=0,e.triangles=0,e.points=0,e.lines=0}return{memory:t,render:e,programs:null,autoReset:!0,reset:s,update:n}}function k_(i,t,e){const n=new WeakMap,s=new me;function r(a,o,l){const c=a.morphTargetInfluences,h=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,u=h!==void 0?h.length:0;let d=n.get(o);if(d===void 0||d.count!==u){let v=function(){P.dispose(),n.delete(o),o.removeEventListener("dispose",v)};var f=v;d!==void 0&&d.texture.dispose();const g=o.morphAttributes.position!==void 0,_=o.morphAttributes.normal!==void 0,m=o.morphAttributes.color!==void 0,p=o.morphAttributes.position||[],y=o.morphAttributes.normal||[],x=o.morphAttributes.color||[];let S=0;g===!0&&(S=1),_===!0&&(S=2),m===!0&&(S=3);let L=o.attributes.position.count*S,T=1;L>t.maxTextureSize&&(T=Math.ceil(L/t.maxTextureSize),L=t.maxTextureSize);const E=new Float32Array(L*T*4*u),P=new Uf(E,L,T,u);P.type=Ci,P.needsUpdate=!0;const U=S*4;for(let b=0;b<u;b++){const I=p[b],O=y[b],$=x[b],K=L*T*4*b;for(let z=0;z<I.count;z++){const Z=z*U;g===!0&&(s.fromBufferAttribute(I,z),E[K+Z+0]=s.x,E[K+Z+1]=s.y,E[K+Z+2]=s.z,E[K+Z+3]=0),_===!0&&(s.fromBufferAttribute(O,z),E[K+Z+4]=s.x,E[K+Z+5]=s.y,E[K+Z+6]=s.z,E[K+Z+7]=0),m===!0&&(s.fromBufferAttribute($,z),E[K+Z+8]=s.x,E[K+Z+9]=s.y,E[K+Z+10]=s.z,E[K+Z+11]=$.itemSize===4?s.w:1)}}d={count:u,texture:P,size:new rt(L,T)},n.set(o,d),o.addEventListener("dispose",v)}if(a.isInstancedMesh===!0&&a.morphTexture!==null)l.getUniforms().setValue(i,"morphTexture",a.morphTexture,e);else{let g=0;for(let m=0;m<c.length;m++)g+=c[m];const _=o.morphTargetsRelative?1:1-g;l.getUniforms().setValue(i,"morphTargetBaseInfluence",_),l.getUniforms().setValue(i,"morphTargetInfluences",c)}l.getUniforms().setValue(i,"morphTargetsTexture",d.texture,e),l.getUniforms().setValue(i,"morphTargetsTextureSize",d.size)}return{update:r}}function N_(i,t,e,n){let s=new WeakMap;function r(l){const c=n.render.frame,h=l.geometry,u=t.get(l,h);if(s.get(u)!==c&&(t.update(u),s.set(u,c)),l.isInstancedMesh&&(l.hasEventListener("dispose",o)===!1&&l.addEventListener("dispose",o),s.get(l)!==c&&(e.update(l.instanceMatrix,i.ARRAY_BUFFER),l.instanceColor!==null&&e.update(l.instanceColor,i.ARRAY_BUFFER),s.set(l,c))),l.isSkinnedMesh){const d=l.skeleton;s.get(d)!==c&&(d.update(),s.set(d,c))}return u}function a(){s=new WeakMap}function o(l){const c=l.target;c.removeEventListener("dispose",o),e.remove(c.instanceMatrix),c.instanceColor!==null&&e.remove(c.instanceColor)}return{update:r,dispose:a}}class Th extends an{constructor(t,e,n,s,r,a,o,l,c,h=mr){if(h!==mr&&h!==Cs)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");n===void 0&&h===mr&&(n=Ts),n===void 0&&h===Cs&&(n=As),super(null,s,r,a,o,l,h,n,c),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=o!==void 0?o:rn,this.minFilter=l!==void 0?l:rn,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}const $f=new an,Bu=new Th(1,1),Wf=new Uf,Xf=new b0,jf=new Vf,Hu=[],Vu=[],Gu=new Float32Array(16),$u=new Float32Array(9),Wu=new Float32Array(4);function Ar(i,t,e){const n=i[0];if(n<=0||n>0)return i;const s=t*e;let r=Hu[s];if(r===void 0&&(r=new Float32Array(s),Hu[s]=r),t!==0){n.toArray(r,0);for(let a=1,o=0;a!==t;++a)o+=e,i[a].toArray(r,o)}return r}function Be(i,t){if(i.length!==t.length)return!1;for(let e=0,n=i.length;e<n;e++)if(i[e]!==t[e])return!1;return!0}function He(i,t){for(let e=0,n=t.length;e<n;e++)i[e]=t[e]}function Fo(i,t){let e=Vu[t];e===void 0&&(e=new Int32Array(t),Vu[t]=e);for(let n=0;n!==t;++n)e[n]=i.allocateTextureUnit();return e}function U_(i,t){const e=this.cache;e[0]!==t&&(i.uniform1f(this.addr,t),e[0]=t)}function O_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y)&&(i.uniform2f(this.addr,t.x,t.y),e[0]=t.x,e[1]=t.y);else{if(Be(e,t))return;i.uniform2fv(this.addr,t),He(e,t)}}function F_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z)&&(i.uniform3f(this.addr,t.x,t.y,t.z),e[0]=t.x,e[1]=t.y,e[2]=t.z);else if(t.r!==void 0)(e[0]!==t.r||e[1]!==t.g||e[2]!==t.b)&&(i.uniform3f(this.addr,t.r,t.g,t.b),e[0]=t.r,e[1]=t.g,e[2]=t.b);else{if(Be(e,t))return;i.uniform3fv(this.addr,t),He(e,t)}}function z_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z||e[3]!==t.w)&&(i.uniform4f(this.addr,t.x,t.y,t.z,t.w),e[0]=t.x,e[1]=t.y,e[2]=t.z,e[3]=t.w);else{if(Be(e,t))return;i.uniform4fv(this.addr,t),He(e,t)}}function B_(i,t){const e=this.cache,n=t.elements;if(n===void 0){if(Be(e,t))return;i.uniformMatrix2fv(this.addr,!1,t),He(e,t)}else{if(Be(e,n))return;Wu.set(n),i.uniformMatrix2fv(this.addr,!1,Wu),He(e,n)}}function H_(i,t){const e=this.cache,n=t.elements;if(n===void 0){if(Be(e,t))return;i.uniformMatrix3fv(this.addr,!1,t),He(e,t)}else{if(Be(e,n))return;$u.set(n),i.uniformMatrix3fv(this.addr,!1,$u),He(e,n)}}function V_(i,t){const e=this.cache,n=t.elements;if(n===void 0){if(Be(e,t))return;i.uniformMatrix4fv(this.addr,!1,t),He(e,t)}else{if(Be(e,n))return;Gu.set(n),i.uniformMatrix4fv(this.addr,!1,Gu),He(e,n)}}function G_(i,t){const e=this.cache;e[0]!==t&&(i.uniform1i(this.addr,t),e[0]=t)}function $_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y)&&(i.uniform2i(this.addr,t.x,t.y),e[0]=t.x,e[1]=t.y);else{if(Be(e,t))return;i.uniform2iv(this.addr,t),He(e,t)}}function W_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z)&&(i.uniform3i(this.addr,t.x,t.y,t.z),e[0]=t.x,e[1]=t.y,e[2]=t.z);else{if(Be(e,t))return;i.uniform3iv(this.addr,t),He(e,t)}}function X_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z||e[3]!==t.w)&&(i.uniform4i(this.addr,t.x,t.y,t.z,t.w),e[0]=t.x,e[1]=t.y,e[2]=t.z,e[3]=t.w);else{if(Be(e,t))return;i.uniform4iv(this.addr,t),He(e,t)}}function j_(i,t){const e=this.cache;e[0]!==t&&(i.uniform1ui(this.addr,t),e[0]=t)}function q_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y)&&(i.uniform2ui(this.addr,t.x,t.y),e[0]=t.x,e[1]=t.y);else{if(Be(e,t))return;i.uniform2uiv(this.addr,t),He(e,t)}}function Y_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z)&&(i.uniform3ui(this.addr,t.x,t.y,t.z),e[0]=t.x,e[1]=t.y,e[2]=t.z);else{if(Be(e,t))return;i.uniform3uiv(this.addr,t),He(e,t)}}function K_(i,t){const e=this.cache;if(t.x!==void 0)(e[0]!==t.x||e[1]!==t.y||e[2]!==t.z||e[3]!==t.w)&&(i.uniform4ui(this.addr,t.x,t.y,t.z,t.w),e[0]=t.x,e[1]=t.y,e[2]=t.z,e[3]=t.w);else{if(Be(e,t))return;i.uniform4uiv(this.addr,t),He(e,t)}}function Z_(i,t,e){const n=this.cache,s=e.allocateTextureUnit();n[0]!==s&&(i.uniform1i(this.addr,s),n[0]=s);let r;this.type===i.SAMPLER_2D_SHADOW?(Bu.compareFunction=If,r=Bu):r=$f,e.setTexture2D(t||r,s)}function J_(i,t,e){const n=this.cache,s=e.allocateTextureUnit();n[0]!==s&&(i.uniform1i(this.addr,s),n[0]=s),e.setTexture3D(t||Xf,s)}function Q_(i,t,e){const n=this.cache,s=e.allocateTextureUnit();n[0]!==s&&(i.uniform1i(this.addr,s),n[0]=s),e.setTextureCube(t||jf,s)}function tx(i,t,e){const n=this.cache,s=e.allocateTextureUnit();n[0]!==s&&(i.uniform1i(this.addr,s),n[0]=s),e.setTexture2DArray(t||Wf,s)}function ex(i){switch(i){case 5126:return U_;case 35664:return O_;case 35665:return F_;case 35666:return z_;case 35674:return B_;case 35675:return H_;case 35676:return V_;case 5124:case 35670:return G_;case 35667:case 35671:return $_;case 35668:case 35672:return W_;case 35669:case 35673:return X_;case 5125:return j_;case 36294:return q_;case 36295:return Y_;case 36296:return K_;case 35678:case 36198:case 36298:case 36306:case 35682:return Z_;case 35679:case 36299:case 36307:return J_;case 35680:case 36300:case 36308:case 36293:return Q_;case 36289:case 36303:case 36311:case 36292:return tx}}function nx(i,t){i.uniform1fv(this.addr,t)}function ix(i,t){const e=Ar(t,this.size,2);i.uniform2fv(this.addr,e)}function sx(i,t){const e=Ar(t,this.size,3);i.uniform3fv(this.addr,e)}function rx(i,t){const e=Ar(t,this.size,4);i.uniform4fv(this.addr,e)}function ax(i,t){const e=Ar(t,this.size,4);i.uniformMatrix2fv(this.addr,!1,e)}function ox(i,t){const e=Ar(t,this.size,9);i.uniformMatrix3fv(this.addr,!1,e)}function lx(i,t){const e=Ar(t,this.size,16);i.uniformMatrix4fv(this.addr,!1,e)}function cx(i,t){i.uniform1iv(this.addr,t)}function hx(i,t){i.uniform2iv(this.addr,t)}function ux(i,t){i.uniform3iv(this.addr,t)}function dx(i,t){i.uniform4iv(this.addr,t)}function fx(i,t){i.uniform1uiv(this.addr,t)}function px(i,t){i.uniform2uiv(this.addr,t)}function mx(i,t){i.uniform3uiv(this.addr,t)}function gx(i,t){i.uniform4uiv(this.addr,t)}function vx(i,t,e){const n=this.cache,s=t.length,r=Fo(e,s);Be(n,r)||(i.uniform1iv(this.addr,r),He(n,r));for(let a=0;a!==s;++a)e.setTexture2D(t[a]||$f,r[a])}function _x(i,t,e){const n=this.cache,s=t.length,r=Fo(e,s);Be(n,r)||(i.uniform1iv(this.addr,r),He(n,r));for(let a=0;a!==s;++a)e.setTexture3D(t[a]||Xf,r[a])}function xx(i,t,e){const n=this.cache,s=t.length,r=Fo(e,s);Be(n,r)||(i.uniform1iv(this.addr,r),He(n,r));for(let a=0;a!==s;++a)e.setTextureCube(t[a]||jf,r[a])}function yx(i,t,e){const n=this.cache,s=t.length,r=Fo(e,s);Be(n,r)||(i.uniform1iv(this.addr,r),He(n,r));for(let a=0;a!==s;++a)e.setTexture2DArray(t[a]||Wf,r[a])}function Mx(i){switch(i){case 5126:return nx;case 35664:return ix;case 35665:return sx;case 35666:return rx;case 35674:return ax;case 35675:return ox;case 35676:return lx;case 5124:case 35670:return cx;case 35667:case 35671:return hx;case 35668:case 35672:return ux;case 35669:case 35673:return dx;case 5125:return fx;case 36294:return px;case 36295:return mx;case 36296:return gx;case 35678:case 36198:case 36298:case 36306:case 35682:return vx;case 35679:case 36299:case 36307:return _x;case 35680:case 36300:case 36308:case 36293:return xx;case 36289:case 36303:case 36311:case 36292:return yx}}class bx{constructor(t,e,n){this.id=t,this.addr=n,this.cache=[],this.type=e.type,this.setValue=ex(e.type)}}class Sx{constructor(t,e,n){this.id=t,this.addr=n,this.cache=[],this.type=e.type,this.size=e.size,this.setValue=Mx(e.type)}}class wx{constructor(t){this.id=t,this.seq=[],this.map={}}setValue(t,e,n){const s=this.seq;for(let r=0,a=s.length;r!==a;++r){const o=s[r];o.setValue(t,e[o.id],n)}}}const Cl=/(\w+)(\])?(\[|\.)?/g;function Xu(i,t){i.seq.push(t),i.map[t.id]=t}function Ex(i,t,e){const n=i.name,s=n.length;for(Cl.lastIndex=0;;){const r=Cl.exec(n),a=Cl.lastIndex;let o=r[1];const l=r[2]==="]",c=r[3];if(l&&(o=o|0),c===void 0||c==="["&&a+2===s){Xu(e,c===void 0?new bx(o,i,t):new Sx(o,i,t));break}else{let u=e.map[o];u===void 0&&(u=new wx(o),Xu(e,u)),e=u}}}class lo{constructor(t,e){this.seq=[],this.map={};const n=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);for(let s=0;s<n;++s){const r=t.getActiveUniform(e,s),a=t.getUniformLocation(e,r.name);Ex(r,a,this)}}setValue(t,e,n,s){const r=this.map[e];r!==void 0&&r.setValue(t,n,s)}setOptional(t,e,n){const s=e[n];s!==void 0&&this.setValue(t,n,s)}static upload(t,e,n,s){for(let r=0,a=e.length;r!==a;++r){const o=e[r],l=n[o.id];l.needsUpdate!==!1&&o.setValue(t,l.value,s)}}static seqWithValue(t,e){const n=[];for(let s=0,r=t.length;s!==r;++s){const a=t[s];a.id in e&&n.push(a)}return n}}function ju(i,t,e){const n=i.createShader(t);return i.shaderSource(n,e),i.compileShader(n),n}const Tx=37297;let Ax=0;function Cx(i,t){const e=i.split(`
3739
3739
  `),n=[],s=Math.max(t-6,0),r=Math.min(t+6,e.length);for(let a=s;a<r;a++){const o=a+1;n.push(`${o===t?">":" "} ${o}: ${e[a]}`)}return n.join(`
3740
- `)}function ex(i){const t=oe.getPrimaries(oe.workingColorSpace),e=oe.getPrimaries(i);let n;switch(t===e?n="":t===uo&&e===ho?n="LinearDisplayP3ToLinearSRGB":t===ho&&e===uo&&(n="LinearSRGBToLinearDisplayP3"),i){case is:case Ao:return[n,"LinearTransferOETF"];case je:case nh:return[n,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space:",i),[n,"LinearTransferOETF"]}}function Ru(i,t,e){const n=i.getShaderParameter(t,i.COMPILE_STATUS),s=i.getShaderInfoLog(t).trim();if(n&&s==="")return"";const r=/ERROR: 0:(\d+)/.exec(s);if(r){const a=parseInt(r[1]);return e.toUpperCase()+`
3740
+ `)}function Rx(i){const t=oe.getPrimaries(oe.workingColorSpace),e=oe.getPrimaries(i);let n;switch(t===e?n="":t===bo&&e===Mo?n="LinearDisplayP3ToLinearSRGB":t===Mo&&e===bo&&(n="LinearSRGBToLinearDisplayP3"),i){case cs:case Oo:return[n,"LinearTransferOETF"];case Ke:case _h:return[n,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space:",i),[n,"LinearTransferOETF"]}}function qu(i,t,e){const n=i.getShaderParameter(t,i.COMPILE_STATUS),s=i.getShaderInfoLog(t).trim();if(n&&s==="")return"";const r=/ERROR: 0:(\d+)/.exec(s);if(r){const a=parseInt(r[1]);return e.toUpperCase()+`
3741
3741
 
3742
3742
  `+s+`
3743
3743
 
3744
- `+tx(i.getShaderSource(t),a)}else return s}function nx(i,t){const e=ex(t);return`vec4 ${i}( vec4 value ) { return ${e[0]}( ${e[1]}( value ) ); }`}function ix(i,t){let e;switch(t){case Xd:e="Linear";break;case jd:e="Reinhard";break;case qd:e="Cineon";break;case Yd:e="ACESFilmic";break;case Kd:e="AgX";break;case qc:e="Neutral";break;case um:e="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",t),e="Linear"}return"vec3 "+i+"( vec3 color ) { return "+e+"ToneMapping( color ); }"}const Ea=new R;function sx(){oe.getLuminanceCoefficients(Ea);const i=Ea.x.toFixed(4),t=Ea.y.toFixed(4),e=Ea.z.toFixed(4);return["float luminance( const in vec3 rgb ) {",` const vec3 weights = vec3( ${i}, ${t}, ${e} );`," return dot( weights, rgb );","}"].join(`
3745
- `)}function rx(i){return[i.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",i.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(Ur).join(`
3746
- `)}function ax(i){const t=[];for(const e in i){const n=i[e];n!==!1&&t.push("#define "+e+" "+n)}return t.join(`
3747
- `)}function ox(i,t){const e={},n=i.getProgramParameter(t,i.ACTIVE_ATTRIBUTES);for(let s=0;s<n;s++){const r=i.getActiveAttrib(t,s),a=r.name;let o=1;r.type===i.FLOAT_MAT2&&(o=2),r.type===i.FLOAT_MAT3&&(o=3),r.type===i.FLOAT_MAT4&&(o=4),e[a]={type:r.type,location:i.getAttribLocation(t,a),locationSize:o}}return e}function Ur(i){return i!==""}function Pu(i,t){const e=t.numSpotLightShadows+t.numSpotLightMaps-t.numSpotLightShadowsWithMaps;return i.replace(/NUM_DIR_LIGHTS/g,t.numDirLights).replace(/NUM_SPOT_LIGHTS/g,t.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,t.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,e).replace(/NUM_RECT_AREA_LIGHTS/g,t.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,t.numPointLights).replace(/NUM_HEMI_LIGHTS/g,t.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,t.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,t.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,t.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,t.numPointLightShadows)}function Lu(i,t){return i.replace(/NUM_CLIPPING_PLANES/g,t.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,t.numClippingPlanes-t.numClipIntersection)}const lx=/^[ \t]*#include +<([\w\d./]+)>/gm;function kc(i){return i.replace(lx,hx)}const cx=new Map;function hx(i,t){let e=Wt[t];if(e===void 0){const n=cx.get(t);if(n!==void 0)e=Wt[n],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',t,n);else throw new Error("Can not resolve #include <"+t+">")}return kc(e)}const ux=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Du(i){return i.replace(ux,dx)}function dx(i,t,e,n){let s="";for(let r=parseInt(t);r<parseInt(e);r++)s+=n.replace(/\[\s*i\s*\]/g,"[ "+r+" ]").replace(/UNROLLED_LOOP_INDEX/g,r);return s}function Iu(i){let t=`precision ${i.precision} float;
3744
+ `+Cx(i.getShaderSource(t),a)}else return s}function Px(i,t){const e=Rx(t);return`vec4 ${i}( vec4 value ) { return ${e[0]}( ${e[1]}( value ) ); }`}function Lx(i,t){let e;switch(t){case vf:e="Linear";break;case _f:e="Reinhard";break;case xf:e="Cineon";break;case yf:e="ACESFilmic";break;case Mf:e="AgX";break;case hh:e="Neutral";break;case zm:e="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",t),e="Linear"}return"vec3 "+i+"( vec3 color ) { return "+e+"ToneMapping( color ); }"}const ka=new R;function Dx(){oe.getLuminanceCoefficients(ka);const i=ka.x.toFixed(4),t=ka.y.toFixed(4),e=ka.z.toFixed(4);return["float luminance( const in vec3 rgb ) {",` const vec3 weights = vec3( ${i}, ${t}, ${e} );`," return dot( weights, rgb );","}"].join(`
3745
+ `)}function Ix(i){return[i.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",i.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(Wr).join(`
3746
+ `)}function kx(i){const t=[];for(const e in i){const n=i[e];n!==!1&&t.push("#define "+e+" "+n)}return t.join(`
3747
+ `)}function Nx(i,t){const e={},n=i.getProgramParameter(t,i.ACTIVE_ATTRIBUTES);for(let s=0;s<n;s++){const r=i.getActiveAttrib(t,s),a=r.name;let o=1;r.type===i.FLOAT_MAT2&&(o=2),r.type===i.FLOAT_MAT3&&(o=3),r.type===i.FLOAT_MAT4&&(o=4),e[a]={type:r.type,location:i.getAttribLocation(t,a),locationSize:o}}return e}function Wr(i){return i!==""}function Yu(i,t){const e=t.numSpotLightShadows+t.numSpotLightMaps-t.numSpotLightShadowsWithMaps;return i.replace(/NUM_DIR_LIGHTS/g,t.numDirLights).replace(/NUM_SPOT_LIGHTS/g,t.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,t.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,e).replace(/NUM_RECT_AREA_LIGHTS/g,t.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,t.numPointLights).replace(/NUM_HEMI_LIGHTS/g,t.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,t.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,t.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,t.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,t.numPointLightShadows)}function Ku(i,t){return i.replace(/NUM_CLIPPING_PLANES/g,t.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,t.numClippingPlanes-t.numClipIntersection)}const Ux=/^[ \t]*#include +<([\w\d./]+)>/gm;function qc(i){return i.replace(Ux,Fx)}const Ox=new Map;function Fx(i,t){let e=Wt[t];if(e===void 0){const n=Ox.get(t);if(n!==void 0)e=Wt[n],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',t,n);else throw new Error("Can not resolve #include <"+t+">")}return qc(e)}const zx=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Zu(i){return i.replace(zx,Bx)}function Bx(i,t,e,n){let s="";for(let r=parseInt(t);r<parseInt(e);r++)s+=n.replace(/\[\s*i\s*\]/g,"[ "+r+" ]").replace(/UNROLLED_LOOP_INDEX/g,r);return s}function Ju(i){let t=`precision ${i.precision} float;
3748
3748
  precision ${i.precision} int;
3749
3749
  precision ${i.precision} sampler2D;
3750
3750
  precision ${i.precision} samplerCube;
@@ -3764,30 +3764,30 @@ void main() {
3764
3764
  `;return i.precision==="highp"?t+=`
3765
3765
  #define HIGH_PRECISION`:i.precision==="mediump"?t+=`
3766
3766
  #define MEDIUM_PRECISION`:i.precision==="lowp"&&(t+=`
3767
- #define LOW_PRECISION`),t}function fx(i){let t="SHADOWMAP_TYPE_BASIC";return i.shadowMapType===Vd?t="SHADOWMAP_TYPE_PCF":i.shadowMapType===Gd?t="SHADOWMAP_TYPE_PCF_SOFT":i.shadowMapType===Mi&&(t="SHADOWMAP_TYPE_VSM"),t}function px(i){let t="ENVMAP_TYPE_CUBE";if(i.envMap)switch(i.envMapMode){case ur:case dr:t="ENVMAP_TYPE_CUBE";break;case To:t="ENVMAP_TYPE_CUBE_UV";break}return t}function mx(i){let t="ENVMAP_MODE_REFLECTION";if(i.envMap)switch(i.envMapMode){case dr:t="ENVMAP_MODE_REFRACTION";break}return t}function gx(i){let t="ENVMAP_BLENDING_NONE";if(i.envMap)switch(i.combine){case Wd:t="ENVMAP_BLENDING_MULTIPLY";break;case cm:t="ENVMAP_BLENDING_MIX";break;case hm:t="ENVMAP_BLENDING_ADD";break}return t}function vx(i){const t=i.envMapCubeUVHeight;if(t===null)return null;const e=Math.log2(t)-2,n=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),7*16)),texelHeight:n,maxMip:e}}function _x(i,t,e,n){const s=i.getContext(),r=e.defines;let a=e.vertexShader,o=e.fragmentShader;const l=fx(e),c=px(e),h=mx(e),u=gx(e),d=vx(e),f=rx(e),g=ax(r),_=s.createProgram();let m,p,y=e.glslVersion?"#version "+e.glslVersion+`
3768
- `:"";e.isRawShaderMaterial?(m=["#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g].filter(Ur).join(`
3767
+ #define LOW_PRECISION`),t}function Hx(i){let t="SHADOWMAP_TYPE_BASIC";return i.shadowMapType===ff?t="SHADOWMAP_TYPE_PCF":i.shadowMapType===pf?t="SHADOWMAP_TYPE_PCF_SOFT":i.shadowMapType===Ei&&(t="SHADOWMAP_TYPE_VSM"),t}function Vx(i){let t="ENVMAP_TYPE_CUBE";if(i.envMap)switch(i.envMapMode){case yr:case Mr:t="ENVMAP_TYPE_CUBE";break;case Uo:t="ENVMAP_TYPE_CUBE_UV";break}return t}function Gx(i){let t="ENVMAP_MODE_REFLECTION";if(i.envMap)switch(i.envMapMode){case Mr:t="ENVMAP_MODE_REFRACTION";break}return t}function $x(i){let t="ENVMAP_BLENDING_NONE";if(i.envMap)switch(i.combine){case gf:t="ENVMAP_BLENDING_MULTIPLY";break;case Om:t="ENVMAP_BLENDING_MIX";break;case Fm:t="ENVMAP_BLENDING_ADD";break}return t}function Wx(i){const t=i.envMapCubeUVHeight;if(t===null)return null;const e=Math.log2(t)-2,n=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),7*16)),texelHeight:n,maxMip:e}}function Xx(i,t,e,n){const s=i.getContext(),r=e.defines;let a=e.vertexShader,o=e.fragmentShader;const l=Hx(e),c=Vx(e),h=Gx(e),u=$x(e),d=Wx(e),f=Ix(e),g=kx(r),_=s.createProgram();let m,p,y=e.glslVersion?"#version "+e.glslVersion+`
3768
+ `:"";e.isRawShaderMaterial?(m=["#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g].filter(Wr).join(`
3769
3769
  `),m.length>0&&(m+=`
3770
- `),p=["#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g].filter(Ur).join(`
3770
+ `),p=["#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g].filter(Wr).join(`
3771
3771
  `),p.length>0&&(p+=`
3772
- `)):(m=[Iu(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g,e.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",e.batching?"#define USE_BATCHING":"",e.batchingColor?"#define USE_BATCHING_COLOR":"",e.instancing?"#define USE_INSTANCING":"",e.instancingColor?"#define USE_INSTANCING_COLOR":"",e.instancingMorph?"#define USE_INSTANCING_MORPH":"",e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.map?"#define USE_MAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+h:"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.displacementMap?"#define USE_DISPLACEMENTMAP":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.mapUv?"#define MAP_UV "+e.mapUv:"",e.alphaMapUv?"#define ALPHAMAP_UV "+e.alphaMapUv:"",e.lightMapUv?"#define LIGHTMAP_UV "+e.lightMapUv:"",e.aoMapUv?"#define AOMAP_UV "+e.aoMapUv:"",e.emissiveMapUv?"#define EMISSIVEMAP_UV "+e.emissiveMapUv:"",e.bumpMapUv?"#define BUMPMAP_UV "+e.bumpMapUv:"",e.normalMapUv?"#define NORMALMAP_UV "+e.normalMapUv:"",e.displacementMapUv?"#define DISPLACEMENTMAP_UV "+e.displacementMapUv:"",e.metalnessMapUv?"#define METALNESSMAP_UV "+e.metalnessMapUv:"",e.roughnessMapUv?"#define ROUGHNESSMAP_UV "+e.roughnessMapUv:"",e.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+e.anisotropyMapUv:"",e.clearcoatMapUv?"#define CLEARCOATMAP_UV "+e.clearcoatMapUv:"",e.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+e.clearcoatNormalMapUv:"",e.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+e.clearcoatRoughnessMapUv:"",e.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+e.iridescenceMapUv:"",e.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+e.iridescenceThicknessMapUv:"",e.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+e.sheenColorMapUv:"",e.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+e.sheenRoughnessMapUv:"",e.specularMapUv?"#define SPECULARMAP_UV "+e.specularMapUv:"",e.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+e.specularColorMapUv:"",e.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+e.specularIntensityMapUv:"",e.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+e.transmissionMapUv:"",e.thicknessMapUv?"#define THICKNESSMAP_UV "+e.thicknessMapUv:"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.flatShading?"#define FLAT_SHADED":"",e.skinning?"#define USE_SKINNING":"",e.morphTargets?"#define USE_MORPHTARGETS":"",e.morphNormals&&e.flatShading===!1?"#define USE_MORPHNORMALS":"",e.morphColors?"#define USE_MORPHCOLORS":"",e.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+e.morphTextureStride:"",e.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+e.morphTargetsCount:"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+l:"",e.sizeAttenuation?"#define USE_SIZEATTENUATION":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",e.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH"," uniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",`
3773
- `].filter(Ur).join(`
3774
- `),p=[Iu(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g,e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",e.map?"#define USE_MAP":"",e.matcap?"#define USE_MATCAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+c:"",e.envMap?"#define "+h:"",e.envMap?"#define "+u:"",d?"#define CUBEUV_TEXEL_WIDTH "+d.texelWidth:"",d?"#define CUBEUV_TEXEL_HEIGHT "+d.texelHeight:"",d?"#define CUBEUV_MAX_MIP "+d.maxMip+".0":"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoat?"#define USE_CLEARCOAT":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.dispersion?"#define USE_DISPERSION":"",e.iridescence?"#define USE_IRIDESCENCE":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaTest?"#define USE_ALPHATEST":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.sheen?"#define USE_SHEEN":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors||e.instancingColor||e.batchingColor?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.gradientMap?"#define USE_GRADIENTMAP":"",e.flatShading?"#define FLAT_SHADED":"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+l:"",e.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",e.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",e.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",e.toneMapping!==Qi?"#define TONE_MAPPING":"",e.toneMapping!==Qi?Wt.tonemapping_pars_fragment:"",e.toneMapping!==Qi?ix("toneMapping",e.toneMapping):"",e.dithering?"#define DITHERING":"",e.opaque?"#define OPAQUE":"",Wt.colorspace_pars_fragment,nx("linearToOutputTexel",e.outputColorSpace),sx(),e.useDepthPacking?"#define DEPTH_PACKING "+e.depthPacking:"",`
3775
- `].filter(Ur).join(`
3776
- `)),a=kc(a),a=Pu(a,e),a=Lu(a,e),o=kc(o),o=Pu(o,e),o=Lu(o,e),a=Du(a),o=Du(o),e.isRawShaderMaterial!==!0&&(y=`#version 300 es
3772
+ `)):(m=[Ju(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g,e.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",e.batching?"#define USE_BATCHING":"",e.batchingColor?"#define USE_BATCHING_COLOR":"",e.instancing?"#define USE_INSTANCING":"",e.instancingColor?"#define USE_INSTANCING_COLOR":"",e.instancingMorph?"#define USE_INSTANCING_MORPH":"",e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.map?"#define USE_MAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+h:"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.displacementMap?"#define USE_DISPLACEMENTMAP":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.mapUv?"#define MAP_UV "+e.mapUv:"",e.alphaMapUv?"#define ALPHAMAP_UV "+e.alphaMapUv:"",e.lightMapUv?"#define LIGHTMAP_UV "+e.lightMapUv:"",e.aoMapUv?"#define AOMAP_UV "+e.aoMapUv:"",e.emissiveMapUv?"#define EMISSIVEMAP_UV "+e.emissiveMapUv:"",e.bumpMapUv?"#define BUMPMAP_UV "+e.bumpMapUv:"",e.normalMapUv?"#define NORMALMAP_UV "+e.normalMapUv:"",e.displacementMapUv?"#define DISPLACEMENTMAP_UV "+e.displacementMapUv:"",e.metalnessMapUv?"#define METALNESSMAP_UV "+e.metalnessMapUv:"",e.roughnessMapUv?"#define ROUGHNESSMAP_UV "+e.roughnessMapUv:"",e.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+e.anisotropyMapUv:"",e.clearcoatMapUv?"#define CLEARCOATMAP_UV "+e.clearcoatMapUv:"",e.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+e.clearcoatNormalMapUv:"",e.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+e.clearcoatRoughnessMapUv:"",e.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+e.iridescenceMapUv:"",e.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+e.iridescenceThicknessMapUv:"",e.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+e.sheenColorMapUv:"",e.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+e.sheenRoughnessMapUv:"",e.specularMapUv?"#define SPECULARMAP_UV "+e.specularMapUv:"",e.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+e.specularColorMapUv:"",e.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+e.specularIntensityMapUv:"",e.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+e.transmissionMapUv:"",e.thicknessMapUv?"#define THICKNESSMAP_UV "+e.thicknessMapUv:"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.flatShading?"#define FLAT_SHADED":"",e.skinning?"#define USE_SKINNING":"",e.morphTargets?"#define USE_MORPHTARGETS":"",e.morphNormals&&e.flatShading===!1?"#define USE_MORPHNORMALS":"",e.morphColors?"#define USE_MORPHCOLORS":"",e.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+e.morphTextureStride:"",e.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+e.morphTargetsCount:"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+l:"",e.sizeAttenuation?"#define USE_SIZEATTENUATION":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",e.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH"," uniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",`
3773
+ `].filter(Wr).join(`
3774
+ `),p=[Ju(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g,e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",e.map?"#define USE_MAP":"",e.matcap?"#define USE_MATCAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+c:"",e.envMap?"#define "+h:"",e.envMap?"#define "+u:"",d?"#define CUBEUV_TEXEL_WIDTH "+d.texelWidth:"",d?"#define CUBEUV_TEXEL_HEIGHT "+d.texelHeight:"",d?"#define CUBEUV_MAX_MIP "+d.maxMip+".0":"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoat?"#define USE_CLEARCOAT":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.dispersion?"#define USE_DISPERSION":"",e.iridescence?"#define USE_IRIDESCENCE":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaTest?"#define USE_ALPHATEST":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.sheen?"#define USE_SHEEN":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors||e.instancingColor||e.batchingColor?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.gradientMap?"#define USE_GRADIENTMAP":"",e.flatShading?"#define FLAT_SHADED":"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+l:"",e.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",e.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",e.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",e.toneMapping!==ss?"#define TONE_MAPPING":"",e.toneMapping!==ss?Wt.tonemapping_pars_fragment:"",e.toneMapping!==ss?Lx("toneMapping",e.toneMapping):"",e.dithering?"#define DITHERING":"",e.opaque?"#define OPAQUE":"",Wt.colorspace_pars_fragment,Px("linearToOutputTexel",e.outputColorSpace),Dx(),e.useDepthPacking?"#define DEPTH_PACKING "+e.depthPacking:"",`
3775
+ `].filter(Wr).join(`
3776
+ `)),a=qc(a),a=Yu(a,e),a=Ku(a,e),o=qc(o),o=Yu(o,e),o=Ku(o,e),a=Zu(a),o=Zu(o),e.isRawShaderMaterial!==!0&&(y=`#version 300 es
3777
3777
  `,m=[f,"#define attribute in","#define varying out","#define texture2D texture"].join(`
3778
3778
  `)+`
3779
- `+m,p=["#define varying in",e.glslVersion===Kh?"":"layout(location = 0) out highp vec4 pc_fragColor;",e.glslVersion===Kh?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(`
3779
+ `+m,p=["#define varying in",e.glslVersion===mu?"":"layout(location = 0) out highp vec4 pc_fragColor;",e.glslVersion===mu?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(`
3780
3780
  `)+`
3781
- `+p);const x=y+m+a,S=y+p+o,L=Cu(s,s.VERTEX_SHADER,x),T=Cu(s,s.FRAGMENT_SHADER,S);s.attachShader(_,L),s.attachShader(_,T),e.index0AttributeName!==void 0?s.bindAttribLocation(_,0,e.index0AttributeName):e.morphTargets===!0&&s.bindAttribLocation(_,0,"position"),s.linkProgram(_);function E(b){if(i.debug.checkShaderErrors){const I=s.getProgramInfoLog(_).trim(),O=s.getShaderInfoLog(L).trim(),$=s.getShaderInfoLog(T).trim();let Y=!0,z=!0;if(s.getProgramParameter(_,s.LINK_STATUS)===!1)if(Y=!1,typeof i.debug.onShaderError=="function")i.debug.onShaderError(s,_,L,T);else{const K=Ru(s,L,"vertex"),V=Ru(s,T,"fragment");console.error("THREE.WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(_,s.VALIDATE_STATUS)+`
3781
+ `+p);const x=y+m+a,S=y+p+o,L=ju(s,s.VERTEX_SHADER,x),T=ju(s,s.FRAGMENT_SHADER,S);s.attachShader(_,L),s.attachShader(_,T),e.index0AttributeName!==void 0?s.bindAttribLocation(_,0,e.index0AttributeName):e.morphTargets===!0&&s.bindAttribLocation(_,0,"position"),s.linkProgram(_);function E(b){if(i.debug.checkShaderErrors){const I=s.getProgramInfoLog(_).trim(),O=s.getShaderInfoLog(L).trim(),$=s.getShaderInfoLog(T).trim();let K=!0,z=!0;if(s.getProgramParameter(_,s.LINK_STATUS)===!1)if(K=!1,typeof i.debug.onShaderError=="function")i.debug.onShaderError(s,_,L,T);else{const Z=qu(s,L,"vertex"),V=qu(s,T,"fragment");console.error("THREE.WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(_,s.VALIDATE_STATUS)+`
3782
3782
 
3783
3783
  Material Name: `+b.name+`
3784
3784
  Material Type: `+b.type+`
3785
3785
 
3786
3786
  Program Info Log: `+I+`
3787
- `+K+`
3788
- `+V)}else I!==""?console.warn("THREE.WebGLProgram: Program Info Log:",I):(O===""||$==="")&&(z=!1);z&&(b.diagnostics={runnable:Y,programLog:I,vertexShader:{log:O,prefix:m},fragmentShader:{log:$,prefix:p}})}s.deleteShader(L),s.deleteShader(T),P=new Ja(s,_),U=ox(s,_)}let P;this.getUniforms=function(){return P===void 0&&E(this),P};let U;this.getAttributes=function(){return U===void 0&&E(this),U};let v=e.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return v===!1&&(v=s.getProgramParameter(_,J_)),v},this.destroy=function(){n.releaseStatesOfProgram(this),s.deleteProgram(_),this.program=void 0},this.type=e.shaderType,this.name=e.shaderName,this.id=Q_++,this.cacheKey=t,this.usedTimes=1,this.program=_,this.vertexShader=L,this.fragmentShader=T,this}let xx=0;class yx{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,n=t.fragmentShader,s=this._getShaderStage(e),r=this._getShaderStage(n),a=this._getShaderCacheForMaterial(t);return a.has(s)===!1&&(a.add(s),s.usedTimes++),a.has(r)===!1&&(a.add(r),r.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const n of e)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let n=e.get(t);return n===void 0&&(n=new Set,e.set(t,n)),n}_getShaderStage(t){const e=this.shaderCache;let n=e.get(t);return n===void 0&&(n=new Mx(t),e.set(t,n)),n}}class Mx{constructor(t){this.id=xx++,this.code=t,this.usedTimes=0}}function bx(i,t,e,n,s,r,a){const o=new ah,l=new yx,c=new Set,h=[],u=s.logarithmicDepthBuffer,d=s.reverseDepthBuffer,f=s.vertexTextures;let g=s.precision;const _={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function m(v){return c.add(v),v===0?"uv":`uv${v}`}function p(v,b,I,O,$){const Y=O.fog,z=$.geometry,K=v.isMeshStandardMaterial?O.environment:null,V=(v.isMeshStandardMaterial?e:t).get(v.envMap||K),at=V&&V.mapping===To?V.image.height:null,ct=_[v.type];v.precision!==null&&(g=s.getMaxPrecision(v.precision),g!==v.precision&&console.warn("THREE.WebGLProgram.getParameters:",v.precision,"not supported, using",g,"instead."));const _t=z.morphAttributes.position||z.morphAttributes.normal||z.morphAttributes.color,Gt=_t!==void 0?_t.length:0;let Jt=0;z.morphAttributes.position!==void 0&&(Jt=1),z.morphAttributes.normal!==void 0&&(Jt=2),z.morphAttributes.color!==void 0&&(Jt=3);let X,et,ft,ot;if(ct){const un=ni[ct];X=un.vertexShader,et=un.fragmentShader}else X=v.vertexShader,et=v.fragmentShader,l.update(v),ft=l.getVertexShaderID(v),ot=l.getFragmentShaderID(v);const At=i.getRenderTarget(),Tt=$.isInstancedMesh===!0,Ft=$.isBatchedMesh===!0,ie=!!v.map,W=!!v.matcap,A=!!V,It=!!v.aoMap,Ct=!!v.lightMap,zt=!!v.bumpMap,Dt=!!v.normalMap,ue=!!v.displacementMap,kt=!!v.emissiveMap,C=!!v.metalnessMap,M=!!v.roughnessMap,F=v.anisotropy>0,q=v.clearcoat>0,Q=v.dispersion>0,j=v.iridescence>0,St=v.sheen>0,ht=v.transmission>0,pt=F&&!!v.anisotropyMap,Yt=q&&!!v.clearcoatMap,nt=q&&!!v.clearcoatNormalMap,mt=q&&!!v.clearcoatRoughnessMap,Nt=j&&!!v.iridescenceMap,Ut=j&&!!v.iridescenceThicknessMap,Mt=St&&!!v.sheenColorMap,Qt=St&&!!v.sheenRoughnessMap,Vt=!!v.specularMap,se=!!v.specularColorMap,D=!!v.specularIntensityMap,dt=ht&&!!v.transmissionMap,G=ht&&!!v.thicknessMap,Z=!!v.gradientMap,gt=!!v.alphaMap,xt=v.alphaTest>0,ne=!!v.alphaHash,Le=!!v.extensions;let hn=Qi;v.toneMapped&&(At===null||At.isXRRenderTarget===!0)&&(hn=i.toneMapping);const ae={shaderID:ct,shaderType:v.type,shaderName:v.name,vertexShader:X,fragmentShader:et,defines:v.defines,customVertexShaderID:ft,customFragmentShaderID:ot,isRawShaderMaterial:v.isRawShaderMaterial===!0,glslVersion:v.glslVersion,precision:g,batching:Ft,batchingColor:Ft&&$._colorsTexture!==null,instancing:Tt,instancingColor:Tt&&$.instanceColor!==null,instancingMorph:Tt&&$.morphTexture!==null,supportsVertexTextures:f,outputColorSpace:At===null?i.outputColorSpace:At.isXRRenderTarget===!0?At.texture.colorSpace:is,alphaToCoverage:!!v.alphaToCoverage,map:ie,matcap:W,envMap:A,envMapMode:A&&V.mapping,envMapCubeUVHeight:at,aoMap:It,lightMap:Ct,bumpMap:zt,normalMap:Dt,displacementMap:f&&ue,emissiveMap:kt,normalMapObjectSpace:Dt&&v.normalMapType===mm,normalMapTangentSpace:Dt&&v.normalMapType===eh,metalnessMap:C,roughnessMap:M,anisotropy:F,anisotropyMap:pt,clearcoat:q,clearcoatMap:Yt,clearcoatNormalMap:nt,clearcoatRoughnessMap:mt,dispersion:Q,iridescence:j,iridescenceMap:Nt,iridescenceThicknessMap:Ut,sheen:St,sheenColorMap:Mt,sheenRoughnessMap:Qt,specularMap:Vt,specularColorMap:se,specularIntensityMap:D,transmission:ht,transmissionMap:dt,thicknessMap:G,gradientMap:Z,opaque:v.transparent===!1&&v.blending===sr&&v.alphaToCoverage===!1,alphaMap:gt,alphaTest:xt,alphaHash:ne,combine:v.combine,mapUv:ie&&m(v.map.channel),aoMapUv:It&&m(v.aoMap.channel),lightMapUv:Ct&&m(v.lightMap.channel),bumpMapUv:zt&&m(v.bumpMap.channel),normalMapUv:Dt&&m(v.normalMap.channel),displacementMapUv:ue&&m(v.displacementMap.channel),emissiveMapUv:kt&&m(v.emissiveMap.channel),metalnessMapUv:C&&m(v.metalnessMap.channel),roughnessMapUv:M&&m(v.roughnessMap.channel),anisotropyMapUv:pt&&m(v.anisotropyMap.channel),clearcoatMapUv:Yt&&m(v.clearcoatMap.channel),clearcoatNormalMapUv:nt&&m(v.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:mt&&m(v.clearcoatRoughnessMap.channel),iridescenceMapUv:Nt&&m(v.iridescenceMap.channel),iridescenceThicknessMapUv:Ut&&m(v.iridescenceThicknessMap.channel),sheenColorMapUv:Mt&&m(v.sheenColorMap.channel),sheenRoughnessMapUv:Qt&&m(v.sheenRoughnessMap.channel),specularMapUv:Vt&&m(v.specularMap.channel),specularColorMapUv:se&&m(v.specularColorMap.channel),specularIntensityMapUv:D&&m(v.specularIntensityMap.channel),transmissionMapUv:dt&&m(v.transmissionMap.channel),thicknessMapUv:G&&m(v.thicknessMap.channel),alphaMapUv:gt&&m(v.alphaMap.channel),vertexTangents:!!z.attributes.tangent&&(Dt||F),vertexColors:v.vertexColors,vertexAlphas:v.vertexColors===!0&&!!z.attributes.color&&z.attributes.color.itemSize===4,pointsUvs:$.isPoints===!0&&!!z.attributes.uv&&(ie||gt),fog:!!Y,useFog:v.fog===!0,fogExp2:!!Y&&Y.isFogExp2,flatShading:v.flatShading===!0,sizeAttenuation:v.sizeAttenuation===!0,logarithmicDepthBuffer:u,reverseDepthBuffer:d,skinning:$.isSkinnedMesh===!0,morphTargets:z.morphAttributes.position!==void 0,morphNormals:z.morphAttributes.normal!==void 0,morphColors:z.morphAttributes.color!==void 0,morphTargetsCount:Gt,morphTextureStride:Jt,numDirLights:b.directional.length,numPointLights:b.point.length,numSpotLights:b.spot.length,numSpotLightMaps:b.spotLightMap.length,numRectAreaLights:b.rectArea.length,numHemiLights:b.hemi.length,numDirLightShadows:b.directionalShadowMap.length,numPointLightShadows:b.pointShadowMap.length,numSpotLightShadows:b.spotShadowMap.length,numSpotLightShadowsWithMaps:b.numSpotLightShadowsWithMaps,numLightProbes:b.numLightProbes,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:v.dithering,shadowMapEnabled:i.shadowMap.enabled&&I.length>0,shadowMapType:i.shadowMap.type,toneMapping:hn,decodeVideoTexture:ie&&v.map.isVideoTexture===!0&&oe.getTransfer(v.map.colorSpace)===ye,premultipliedAlpha:v.premultipliedAlpha,doubleSided:v.side===si,flipSided:v.side===on,useDepthPacking:v.depthPacking>=0,depthPacking:v.depthPacking||0,index0AttributeName:v.index0AttributeName,extensionClipCullDistance:Le&&v.extensions.clipCullDistance===!0&&n.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(Le&&v.extensions.multiDraw===!0||Ft)&&n.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:v.customProgramCacheKey()};return ae.vertexUv1s=c.has(1),ae.vertexUv2s=c.has(2),ae.vertexUv3s=c.has(3),c.clear(),ae}function y(v){const b=[];if(v.shaderID?b.push(v.shaderID):(b.push(v.customVertexShaderID),b.push(v.customFragmentShaderID)),v.defines!==void 0)for(const I in v.defines)b.push(I),b.push(v.defines[I]);return v.isRawShaderMaterial===!1&&(x(b,v),S(b,v),b.push(i.outputColorSpace)),b.push(v.customProgramCacheKey),b.join()}function x(v,b){v.push(b.precision),v.push(b.outputColorSpace),v.push(b.envMapMode),v.push(b.envMapCubeUVHeight),v.push(b.mapUv),v.push(b.alphaMapUv),v.push(b.lightMapUv),v.push(b.aoMapUv),v.push(b.bumpMapUv),v.push(b.normalMapUv),v.push(b.displacementMapUv),v.push(b.emissiveMapUv),v.push(b.metalnessMapUv),v.push(b.roughnessMapUv),v.push(b.anisotropyMapUv),v.push(b.clearcoatMapUv),v.push(b.clearcoatNormalMapUv),v.push(b.clearcoatRoughnessMapUv),v.push(b.iridescenceMapUv),v.push(b.iridescenceThicknessMapUv),v.push(b.sheenColorMapUv),v.push(b.sheenRoughnessMapUv),v.push(b.specularMapUv),v.push(b.specularColorMapUv),v.push(b.specularIntensityMapUv),v.push(b.transmissionMapUv),v.push(b.thicknessMapUv),v.push(b.combine),v.push(b.fogExp2),v.push(b.sizeAttenuation),v.push(b.morphTargetsCount),v.push(b.morphAttributeCount),v.push(b.numDirLights),v.push(b.numPointLights),v.push(b.numSpotLights),v.push(b.numSpotLightMaps),v.push(b.numHemiLights),v.push(b.numRectAreaLights),v.push(b.numDirLightShadows),v.push(b.numPointLightShadows),v.push(b.numSpotLightShadows),v.push(b.numSpotLightShadowsWithMaps),v.push(b.numLightProbes),v.push(b.shadowMapType),v.push(b.toneMapping),v.push(b.numClippingPlanes),v.push(b.numClipIntersection),v.push(b.depthPacking)}function S(v,b){o.disableAll(),b.supportsVertexTextures&&o.enable(0),b.instancing&&o.enable(1),b.instancingColor&&o.enable(2),b.instancingMorph&&o.enable(3),b.matcap&&o.enable(4),b.envMap&&o.enable(5),b.normalMapObjectSpace&&o.enable(6),b.normalMapTangentSpace&&o.enable(7),b.clearcoat&&o.enable(8),b.iridescence&&o.enable(9),b.alphaTest&&o.enable(10),b.vertexColors&&o.enable(11),b.vertexAlphas&&o.enable(12),b.vertexUv1s&&o.enable(13),b.vertexUv2s&&o.enable(14),b.vertexUv3s&&o.enable(15),b.vertexTangents&&o.enable(16),b.anisotropy&&o.enable(17),b.alphaHash&&o.enable(18),b.batching&&o.enable(19),b.dispersion&&o.enable(20),b.batchingColor&&o.enable(21),v.push(o.mask),o.disableAll(),b.fog&&o.enable(0),b.useFog&&o.enable(1),b.flatShading&&o.enable(2),b.logarithmicDepthBuffer&&o.enable(3),b.reverseDepthBuffer&&o.enable(4),b.skinning&&o.enable(5),b.morphTargets&&o.enable(6),b.morphNormals&&o.enable(7),b.morphColors&&o.enable(8),b.premultipliedAlpha&&o.enable(9),b.shadowMapEnabled&&o.enable(10),b.doubleSided&&o.enable(11),b.flipSided&&o.enable(12),b.useDepthPacking&&o.enable(13),b.dithering&&o.enable(14),b.transmission&&o.enable(15),b.sheen&&o.enable(16),b.opaque&&o.enable(17),b.pointsUvs&&o.enable(18),b.decodeVideoTexture&&o.enable(19),b.alphaToCoverage&&o.enable(20),v.push(o.mask)}function L(v){const b=_[v.type];let I;if(b){const O=ni[b];I=ji.clone(O.uniforms)}else I=v.uniforms;return I}function T(v,b){let I;for(let O=0,$=h.length;O<$;O++){const Y=h[O];if(Y.cacheKey===b){I=Y,++I.usedTimes;break}}return I===void 0&&(I=new _x(i,b,v,r),h.push(I)),I}function E(v){if(--v.usedTimes===0){const b=h.indexOf(v);h[b]=h[h.length-1],h.pop(),v.destroy()}}function P(v){l.remove(v)}function U(){l.dispose()}return{getParameters:p,getProgramCacheKey:y,getUniforms:L,acquireProgram:T,releaseProgram:E,releaseShaderCache:P,programs:h,dispose:U}}function Sx(){let i=new WeakMap;function t(a){return i.has(a)}function e(a){let o=i.get(a);return o===void 0&&(o={},i.set(a,o)),o}function n(a){i.delete(a)}function s(a,o,l){i.get(a)[o]=l}function r(){i=new WeakMap}return{has:t,get:e,remove:n,update:s,dispose:r}}function wx(i,t){return i.groupOrder!==t.groupOrder?i.groupOrder-t.groupOrder:i.renderOrder!==t.renderOrder?i.renderOrder-t.renderOrder:i.material.id!==t.material.id?i.material.id-t.material.id:i.z!==t.z?i.z-t.z:i.id-t.id}function ku(i,t){return i.groupOrder!==t.groupOrder?i.groupOrder-t.groupOrder:i.renderOrder!==t.renderOrder?i.renderOrder-t.renderOrder:i.z!==t.z?t.z-i.z:i.id-t.id}function Nu(){const i=[];let t=0;const e=[],n=[],s=[];function r(){t=0,e.length=0,n.length=0,s.length=0}function a(u,d,f,g,_,m){let p=i[t];return p===void 0?(p={id:u.id,object:u,geometry:d,material:f,groupOrder:g,renderOrder:u.renderOrder,z:_,group:m},i[t]=p):(p.id=u.id,p.object=u,p.geometry=d,p.material=f,p.groupOrder=g,p.renderOrder=u.renderOrder,p.z=_,p.group=m),t++,p}function o(u,d,f,g,_,m){const p=a(u,d,f,g,_,m);f.transmission>0?n.push(p):f.transparent===!0?s.push(p):e.push(p)}function l(u,d,f,g,_,m){const p=a(u,d,f,g,_,m);f.transmission>0?n.unshift(p):f.transparent===!0?s.unshift(p):e.unshift(p)}function c(u,d){e.length>1&&e.sort(u||wx),n.length>1&&n.sort(d||ku),s.length>1&&s.sort(d||ku)}function h(){for(let u=t,d=i.length;u<d;u++){const f=i[u];if(f.id===null)break;f.id=null,f.object=null,f.geometry=null,f.material=null,f.group=null}}return{opaque:e,transmissive:n,transparent:s,init:r,push:o,unshift:l,finish:h,sort:c}}function Ex(){let i=new WeakMap;function t(n,s){const r=i.get(n);let a;return r===void 0?(a=new Nu,i.set(n,[a])):s>=r.length?(a=new Nu,r.push(a)):a=r[s],a}function e(){i=new WeakMap}return{get:t,dispose:e}}function Tx(){const i={};return{get:function(t){if(i[t.id]!==void 0)return i[t.id];let e;switch(t.type){case"DirectionalLight":e={direction:new R,color:new Zt};break;case"SpotLight":e={position:new R,direction:new R,color:new Zt,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":e={position:new R,color:new Zt,distance:0,decay:0};break;case"HemisphereLight":e={direction:new R,skyColor:new Zt,groundColor:new Zt};break;case"RectAreaLight":e={color:new Zt,position:new R,halfWidth:new R,halfHeight:new R};break}return i[t.id]=e,e}}}function Ax(){const i={};return{get:function(t){if(i[t.id]!==void 0)return i[t.id];let e;switch(t.type){case"DirectionalLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new rt};break;case"SpotLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new rt};break;case"PointLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new rt,shadowCameraNear:1,shadowCameraFar:1e3};break}return i[t.id]=e,e}}}let Cx=0;function Rx(i,t){return(t.castShadow?2:0)-(i.castShadow?2:0)+(t.map?1:0)-(i.map?1:0)}function Px(i){const t=new Tx,e=Ax(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let c=0;c<9;c++)n.probe.push(new R);const s=new R,r=new fe,a=new fe;function o(c){let h=0,u=0,d=0;for(let U=0;U<9;U++)n.probe[U].set(0,0,0);let f=0,g=0,_=0,m=0,p=0,y=0,x=0,S=0,L=0,T=0,E=0;c.sort(Rx);for(let U=0,v=c.length;U<v;U++){const b=c[U],I=b.color,O=b.intensity,$=b.distance,Y=b.shadow&&b.shadow.map?b.shadow.map.texture:null;if(b.isAmbientLight)h+=I.r*O,u+=I.g*O,d+=I.b*O;else if(b.isLightProbe){for(let z=0;z<9;z++)n.probe[z].addScaledVector(b.sh.coefficients[z],O);E++}else if(b.isDirectionalLight){const z=t.get(b);if(z.color.copy(b.color).multiplyScalar(b.intensity),b.castShadow){const K=b.shadow,V=e.get(b);V.shadowIntensity=K.intensity,V.shadowBias=K.bias,V.shadowNormalBias=K.normalBias,V.shadowRadius=K.radius,V.shadowMapSize=K.mapSize,n.directionalShadow[f]=V,n.directionalShadowMap[f]=Y,n.directionalShadowMatrix[f]=b.shadow.matrix,y++}n.directional[f]=z,f++}else if(b.isSpotLight){const z=t.get(b);z.position.setFromMatrixPosition(b.matrixWorld),z.color.copy(I).multiplyScalar(O),z.distance=$,z.coneCos=Math.cos(b.angle),z.penumbraCos=Math.cos(b.angle*(1-b.penumbra)),z.decay=b.decay,n.spot[_]=z;const K=b.shadow;if(b.map&&(n.spotLightMap[L]=b.map,L++,K.updateMatrices(b),b.castShadow&&T++),n.spotLightMatrix[_]=K.matrix,b.castShadow){const V=e.get(b);V.shadowIntensity=K.intensity,V.shadowBias=K.bias,V.shadowNormalBias=K.normalBias,V.shadowRadius=K.radius,V.shadowMapSize=K.mapSize,n.spotShadow[_]=V,n.spotShadowMap[_]=Y,S++}_++}else if(b.isRectAreaLight){const z=t.get(b);z.color.copy(I).multiplyScalar(O),z.halfWidth.set(b.width*.5,0,0),z.halfHeight.set(0,b.height*.5,0),n.rectArea[m]=z,m++}else if(b.isPointLight){const z=t.get(b);if(z.color.copy(b.color).multiplyScalar(b.intensity),z.distance=b.distance,z.decay=b.decay,b.castShadow){const K=b.shadow,V=e.get(b);V.shadowIntensity=K.intensity,V.shadowBias=K.bias,V.shadowNormalBias=K.normalBias,V.shadowRadius=K.radius,V.shadowMapSize=K.mapSize,V.shadowCameraNear=K.camera.near,V.shadowCameraFar=K.camera.far,n.pointShadow[g]=V,n.pointShadowMap[g]=Y,n.pointShadowMatrix[g]=b.shadow.matrix,x++}n.point[g]=z,g++}else if(b.isHemisphereLight){const z=t.get(b);z.skyColor.copy(b.color).multiplyScalar(O),z.groundColor.copy(b.groundColor).multiplyScalar(O),n.hemi[p]=z,p++}}m>0&&(i.has("OES_texture_float_linear")===!0?(n.rectAreaLTC1=ut.LTC_FLOAT_1,n.rectAreaLTC2=ut.LTC_FLOAT_2):(n.rectAreaLTC1=ut.LTC_HALF_1,n.rectAreaLTC2=ut.LTC_HALF_2)),n.ambient[0]=h,n.ambient[1]=u,n.ambient[2]=d;const P=n.hash;(P.directionalLength!==f||P.pointLength!==g||P.spotLength!==_||P.rectAreaLength!==m||P.hemiLength!==p||P.numDirectionalShadows!==y||P.numPointShadows!==x||P.numSpotShadows!==S||P.numSpotMaps!==L||P.numLightProbes!==E)&&(n.directional.length=f,n.spot.length=_,n.rectArea.length=m,n.point.length=g,n.hemi.length=p,n.directionalShadow.length=y,n.directionalShadowMap.length=y,n.pointShadow.length=x,n.pointShadowMap.length=x,n.spotShadow.length=S,n.spotShadowMap.length=S,n.directionalShadowMatrix.length=y,n.pointShadowMatrix.length=x,n.spotLightMatrix.length=S+L-T,n.spotLightMap.length=L,n.numSpotLightShadowsWithMaps=T,n.numLightProbes=E,P.directionalLength=f,P.pointLength=g,P.spotLength=_,P.rectAreaLength=m,P.hemiLength=p,P.numDirectionalShadows=y,P.numPointShadows=x,P.numSpotShadows=S,P.numSpotMaps=L,P.numLightProbes=E,n.version=Cx++)}function l(c,h){let u=0,d=0,f=0,g=0,_=0;const m=h.matrixWorldInverse;for(let p=0,y=c.length;p<y;p++){const x=c[p];if(x.isDirectionalLight){const S=n.directional[u];S.direction.setFromMatrixPosition(x.matrixWorld),s.setFromMatrixPosition(x.target.matrixWorld),S.direction.sub(s),S.direction.transformDirection(m),u++}else if(x.isSpotLight){const S=n.spot[f];S.position.setFromMatrixPosition(x.matrixWorld),S.position.applyMatrix4(m),S.direction.setFromMatrixPosition(x.matrixWorld),s.setFromMatrixPosition(x.target.matrixWorld),S.direction.sub(s),S.direction.transformDirection(m),f++}else if(x.isRectAreaLight){const S=n.rectArea[g];S.position.setFromMatrixPosition(x.matrixWorld),S.position.applyMatrix4(m),a.identity(),r.copy(x.matrixWorld),r.premultiply(m),a.extractRotation(r),S.halfWidth.set(x.width*.5,0,0),S.halfHeight.set(0,x.height*.5,0),S.halfWidth.applyMatrix4(a),S.halfHeight.applyMatrix4(a),g++}else if(x.isPointLight){const S=n.point[d];S.position.setFromMatrixPosition(x.matrixWorld),S.position.applyMatrix4(m),d++}else if(x.isHemisphereLight){const S=n.hemi[_];S.direction.setFromMatrixPosition(x.matrixWorld),S.direction.transformDirection(m),_++}}}return{setup:o,setupView:l,state:n}}function Uu(i){const t=new Px(i),e=[],n=[];function s(h){c.camera=h,e.length=0,n.length=0}function r(h){e.push(h)}function a(h){n.push(h)}function o(){t.setup(e)}function l(h){t.setupView(e,h)}const c={lightsArray:e,shadowsArray:n,camera:null,lights:t,transmissionRenderTarget:{}};return{init:s,state:c,setupLights:o,setupLightsView:l,pushLight:r,pushShadow:a}}function Lx(i){let t=new WeakMap;function e(s,r=0){const a=t.get(s);let o;return a===void 0?(o=new Uu(i),t.set(s,[o])):r>=a.length?(o=new Uu(i),a.push(o)):o=a[r],o}function n(){t=new WeakMap}return{get:e,dispose:n}}class Dx extends Ii{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=fm,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class Ix extends Ii{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}const kx=`void main() {
3787
+ `+Z+`
3788
+ `+V)}else I!==""?console.warn("THREE.WebGLProgram: Program Info Log:",I):(O===""||$==="")&&(z=!1);z&&(b.diagnostics={runnable:K,programLog:I,vertexShader:{log:O,prefix:m},fragmentShader:{log:$,prefix:p}})}s.deleteShader(L),s.deleteShader(T),P=new lo(s,_),U=Nx(s,_)}let P;this.getUniforms=function(){return P===void 0&&E(this),P};let U;this.getAttributes=function(){return U===void 0&&E(this),U};let v=e.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return v===!1&&(v=s.getProgramParameter(_,Tx)),v},this.destroy=function(){n.releaseStatesOfProgram(this),s.deleteProgram(_),this.program=void 0},this.type=e.shaderType,this.name=e.shaderName,this.id=Ax++,this.cacheKey=t,this.usedTimes=1,this.program=_,this.vertexShader=L,this.fragmentShader=T,this}let jx=0;class qx{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,n=t.fragmentShader,s=this._getShaderStage(e),r=this._getShaderStage(n),a=this._getShaderCacheForMaterial(t);return a.has(s)===!1&&(a.add(s),s.usedTimes++),a.has(r)===!1&&(a.add(r),r.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const n of e)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let n=e.get(t);return n===void 0&&(n=new Set,e.set(t,n)),n}_getShaderStage(t){const e=this.shaderCache;let n=e.get(t);return n===void 0&&(n=new Yx(t),e.set(t,n)),n}}class Yx{constructor(t){this.id=jx++,this.code=t,this.usedTimes=0}}function Kx(i,t,e,n,s,r,a){const o=new bh,l=new qx,c=new Set,h=[],u=s.logarithmicDepthBuffer,d=s.reverseDepthBuffer,f=s.vertexTextures;let g=s.precision;const _={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function m(v){return c.add(v),v===0?"uv":`uv${v}`}function p(v,b,I,O,$){const K=O.fog,z=$.geometry,Z=v.isMeshStandardMaterial?O.environment:null,V=(v.isMeshStandardMaterial?e:t).get(v.envMap||Z),at=V&&V.mapping===Uo?V.image.height:null,ct=_[v.type];v.precision!==null&&(g=s.getMaxPrecision(v.precision),g!==v.precision&&console.warn("THREE.WebGLProgram.getParameters:",v.precision,"not supported, using",g,"instead."));const _t=z.morphAttributes.position||z.morphAttributes.normal||z.morphAttributes.color,$t=_t!==void 0?_t.length:0;let Jt=0;z.morphAttributes.position!==void 0&&(Jt=1),z.morphAttributes.normal!==void 0&&(Jt=2),z.morphAttributes.color!==void 0&&(Jt=3);let X,et,ft,ot;if(ct){const mn=ai[ct];X=mn.vertexShader,et=mn.fragmentShader}else X=v.vertexShader,et=v.fragmentShader,l.update(v),ft=l.getVertexShaderID(v),ot=l.getFragmentShaderID(v);const At=i.getRenderTarget(),Tt=$.isInstancedMesh===!0,zt=$.isBatchedMesh===!0,ie=!!v.map,W=!!v.matcap,A=!!V,It=!!v.aoMap,Ct=!!v.lightMap,Bt=!!v.bumpMap,Dt=!!v.normalMap,ue=!!v.displacementMap,Nt=!!v.emissiveMap,C=!!v.metalnessMap,M=!!v.roughnessMap,F=v.anisotropy>0,Y=v.clearcoat>0,Q=v.dispersion>0,j=v.iridescence>0,St=v.sheen>0,ht=v.transmission>0,pt=F&&!!v.anisotropyMap,Yt=Y&&!!v.clearcoatMap,nt=Y&&!!v.clearcoatNormalMap,mt=Y&&!!v.clearcoatRoughnessMap,Ut=j&&!!v.iridescenceMap,Ot=j&&!!v.iridescenceThicknessMap,Mt=St&&!!v.sheenColorMap,Qt=St&&!!v.sheenRoughnessMap,Vt=!!v.specularMap,se=!!v.specularColorMap,D=!!v.specularIntensityMap,dt=ht&&!!v.transmissionMap,G=ht&&!!v.thicknessMap,J=!!v.gradientMap,gt=!!v.alphaMap,xt=v.alphaTest>0,ne=!!v.alphaHash,ke=!!v.extensions;let pn=ss;v.toneMapped&&(At===null||At.isXRRenderTarget===!0)&&(pn=i.toneMapping);const ae={shaderID:ct,shaderType:v.type,shaderName:v.name,vertexShader:X,fragmentShader:et,defines:v.defines,customVertexShaderID:ft,customFragmentShaderID:ot,isRawShaderMaterial:v.isRawShaderMaterial===!0,glslVersion:v.glslVersion,precision:g,batching:zt,batchingColor:zt&&$._colorsTexture!==null,instancing:Tt,instancingColor:Tt&&$.instanceColor!==null,instancingMorph:Tt&&$.morphTexture!==null,supportsVertexTextures:f,outputColorSpace:At===null?i.outputColorSpace:At.isXRRenderTarget===!0?At.texture.colorSpace:cs,alphaToCoverage:!!v.alphaToCoverage,map:ie,matcap:W,envMap:A,envMapMode:A&&V.mapping,envMapCubeUVHeight:at,aoMap:It,lightMap:Ct,bumpMap:Bt,normalMap:Dt,displacementMap:f&&ue,emissiveMap:Nt,normalMapObjectSpace:Dt&&v.normalMapType===Gm,normalMapTangentSpace:Dt&&v.normalMapType===vh,metalnessMap:C,roughnessMap:M,anisotropy:F,anisotropyMap:pt,clearcoat:Y,clearcoatMap:Yt,clearcoatNormalMap:nt,clearcoatRoughnessMap:mt,dispersion:Q,iridescence:j,iridescenceMap:Ut,iridescenceThicknessMap:Ot,sheen:St,sheenColorMap:Mt,sheenRoughnessMap:Qt,specularMap:Vt,specularColorMap:se,specularIntensityMap:D,transmission:ht,transmissionMap:dt,thicknessMap:G,gradientMap:J,opaque:v.transparent===!1&&v.blending===pr&&v.alphaToCoverage===!1,alphaMap:gt,alphaTest:xt,alphaHash:ne,combine:v.combine,mapUv:ie&&m(v.map.channel),aoMapUv:It&&m(v.aoMap.channel),lightMapUv:Ct&&m(v.lightMap.channel),bumpMapUv:Bt&&m(v.bumpMap.channel),normalMapUv:Dt&&m(v.normalMap.channel),displacementMapUv:ue&&m(v.displacementMap.channel),emissiveMapUv:Nt&&m(v.emissiveMap.channel),metalnessMapUv:C&&m(v.metalnessMap.channel),roughnessMapUv:M&&m(v.roughnessMap.channel),anisotropyMapUv:pt&&m(v.anisotropyMap.channel),clearcoatMapUv:Yt&&m(v.clearcoatMap.channel),clearcoatNormalMapUv:nt&&m(v.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:mt&&m(v.clearcoatRoughnessMap.channel),iridescenceMapUv:Ut&&m(v.iridescenceMap.channel),iridescenceThicknessMapUv:Ot&&m(v.iridescenceThicknessMap.channel),sheenColorMapUv:Mt&&m(v.sheenColorMap.channel),sheenRoughnessMapUv:Qt&&m(v.sheenRoughnessMap.channel),specularMapUv:Vt&&m(v.specularMap.channel),specularColorMapUv:se&&m(v.specularColorMap.channel),specularIntensityMapUv:D&&m(v.specularIntensityMap.channel),transmissionMapUv:dt&&m(v.transmissionMap.channel),thicknessMapUv:G&&m(v.thicknessMap.channel),alphaMapUv:gt&&m(v.alphaMap.channel),vertexTangents:!!z.attributes.tangent&&(Dt||F),vertexColors:v.vertexColors,vertexAlphas:v.vertexColors===!0&&!!z.attributes.color&&z.attributes.color.itemSize===4,pointsUvs:$.isPoints===!0&&!!z.attributes.uv&&(ie||gt),fog:!!K,useFog:v.fog===!0,fogExp2:!!K&&K.isFogExp2,flatShading:v.flatShading===!0,sizeAttenuation:v.sizeAttenuation===!0,logarithmicDepthBuffer:u,reverseDepthBuffer:d,skinning:$.isSkinnedMesh===!0,morphTargets:z.morphAttributes.position!==void 0,morphNormals:z.morphAttributes.normal!==void 0,morphColors:z.morphAttributes.color!==void 0,morphTargetsCount:$t,morphTextureStride:Jt,numDirLights:b.directional.length,numPointLights:b.point.length,numSpotLights:b.spot.length,numSpotLightMaps:b.spotLightMap.length,numRectAreaLights:b.rectArea.length,numHemiLights:b.hemi.length,numDirLightShadows:b.directionalShadowMap.length,numPointLightShadows:b.pointShadowMap.length,numSpotLightShadows:b.spotShadowMap.length,numSpotLightShadowsWithMaps:b.numSpotLightShadowsWithMaps,numLightProbes:b.numLightProbes,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:v.dithering,shadowMapEnabled:i.shadowMap.enabled&&I.length>0,shadowMapType:i.shadowMap.type,toneMapping:pn,decodeVideoTexture:ie&&v.map.isVideoTexture===!0&&oe.getTransfer(v.map.colorSpace)===ye,premultipliedAlpha:v.premultipliedAlpha,doubleSided:v.side===li,flipSided:v.side===un,useDepthPacking:v.depthPacking>=0,depthPacking:v.depthPacking||0,index0AttributeName:v.index0AttributeName,extensionClipCullDistance:ke&&v.extensions.clipCullDistance===!0&&n.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(ke&&v.extensions.multiDraw===!0||zt)&&n.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:v.customProgramCacheKey()};return ae.vertexUv1s=c.has(1),ae.vertexUv2s=c.has(2),ae.vertexUv3s=c.has(3),c.clear(),ae}function y(v){const b=[];if(v.shaderID?b.push(v.shaderID):(b.push(v.customVertexShaderID),b.push(v.customFragmentShaderID)),v.defines!==void 0)for(const I in v.defines)b.push(I),b.push(v.defines[I]);return v.isRawShaderMaterial===!1&&(x(b,v),S(b,v),b.push(i.outputColorSpace)),b.push(v.customProgramCacheKey),b.join()}function x(v,b){v.push(b.precision),v.push(b.outputColorSpace),v.push(b.envMapMode),v.push(b.envMapCubeUVHeight),v.push(b.mapUv),v.push(b.alphaMapUv),v.push(b.lightMapUv),v.push(b.aoMapUv),v.push(b.bumpMapUv),v.push(b.normalMapUv),v.push(b.displacementMapUv),v.push(b.emissiveMapUv),v.push(b.metalnessMapUv),v.push(b.roughnessMapUv),v.push(b.anisotropyMapUv),v.push(b.clearcoatMapUv),v.push(b.clearcoatNormalMapUv),v.push(b.clearcoatRoughnessMapUv),v.push(b.iridescenceMapUv),v.push(b.iridescenceThicknessMapUv),v.push(b.sheenColorMapUv),v.push(b.sheenRoughnessMapUv),v.push(b.specularMapUv),v.push(b.specularColorMapUv),v.push(b.specularIntensityMapUv),v.push(b.transmissionMapUv),v.push(b.thicknessMapUv),v.push(b.combine),v.push(b.fogExp2),v.push(b.sizeAttenuation),v.push(b.morphTargetsCount),v.push(b.morphAttributeCount),v.push(b.numDirLights),v.push(b.numPointLights),v.push(b.numSpotLights),v.push(b.numSpotLightMaps),v.push(b.numHemiLights),v.push(b.numRectAreaLights),v.push(b.numDirLightShadows),v.push(b.numPointLightShadows),v.push(b.numSpotLightShadows),v.push(b.numSpotLightShadowsWithMaps),v.push(b.numLightProbes),v.push(b.shadowMapType),v.push(b.toneMapping),v.push(b.numClippingPlanes),v.push(b.numClipIntersection),v.push(b.depthPacking)}function S(v,b){o.disableAll(),b.supportsVertexTextures&&o.enable(0),b.instancing&&o.enable(1),b.instancingColor&&o.enable(2),b.instancingMorph&&o.enable(3),b.matcap&&o.enable(4),b.envMap&&o.enable(5),b.normalMapObjectSpace&&o.enable(6),b.normalMapTangentSpace&&o.enable(7),b.clearcoat&&o.enable(8),b.iridescence&&o.enable(9),b.alphaTest&&o.enable(10),b.vertexColors&&o.enable(11),b.vertexAlphas&&o.enable(12),b.vertexUv1s&&o.enable(13),b.vertexUv2s&&o.enable(14),b.vertexUv3s&&o.enable(15),b.vertexTangents&&o.enable(16),b.anisotropy&&o.enable(17),b.alphaHash&&o.enable(18),b.batching&&o.enable(19),b.dispersion&&o.enable(20),b.batchingColor&&o.enable(21),v.push(o.mask),o.disableAll(),b.fog&&o.enable(0),b.useFog&&o.enable(1),b.flatShading&&o.enable(2),b.logarithmicDepthBuffer&&o.enable(3),b.reverseDepthBuffer&&o.enable(4),b.skinning&&o.enable(5),b.morphTargets&&o.enable(6),b.morphNormals&&o.enable(7),b.morphColors&&o.enable(8),b.premultipliedAlpha&&o.enable(9),b.shadowMapEnabled&&o.enable(10),b.doubleSided&&o.enable(11),b.flipSided&&o.enable(12),b.useDepthPacking&&o.enable(13),b.dithering&&o.enable(14),b.transmission&&o.enable(15),b.sheen&&o.enable(16),b.opaque&&o.enable(17),b.pointsUvs&&o.enable(18),b.decodeVideoTexture&&o.enable(19),b.alphaToCoverage&&o.enable(20),v.push(o.mask)}function L(v){const b=_[v.type];let I;if(b){const O=ai[b];I=Qi.clone(O.uniforms)}else I=v.uniforms;return I}function T(v,b){let I;for(let O=0,$=h.length;O<$;O++){const K=h[O];if(K.cacheKey===b){I=K,++I.usedTimes;break}}return I===void 0&&(I=new Xx(i,b,v,r),h.push(I)),I}function E(v){if(--v.usedTimes===0){const b=h.indexOf(v);h[b]=h[h.length-1],h.pop(),v.destroy()}}function P(v){l.remove(v)}function U(){l.dispose()}return{getParameters:p,getProgramCacheKey:y,getUniforms:L,acquireProgram:T,releaseProgram:E,releaseShaderCache:P,programs:h,dispose:U}}function Zx(){let i=new WeakMap;function t(a){return i.has(a)}function e(a){let o=i.get(a);return o===void 0&&(o={},i.set(a,o)),o}function n(a){i.delete(a)}function s(a,o,l){i.get(a)[o]=l}function r(){i=new WeakMap}return{has:t,get:e,remove:n,update:s,dispose:r}}function Jx(i,t){return i.groupOrder!==t.groupOrder?i.groupOrder-t.groupOrder:i.renderOrder!==t.renderOrder?i.renderOrder-t.renderOrder:i.material.id!==t.material.id?i.material.id-t.material.id:i.z!==t.z?i.z-t.z:i.id-t.id}function Qu(i,t){return i.groupOrder!==t.groupOrder?i.groupOrder-t.groupOrder:i.renderOrder!==t.renderOrder?i.renderOrder-t.renderOrder:i.z!==t.z?t.z-i.z:i.id-t.id}function td(){const i=[];let t=0;const e=[],n=[],s=[];function r(){t=0,e.length=0,n.length=0,s.length=0}function a(u,d,f,g,_,m){let p=i[t];return p===void 0?(p={id:u.id,object:u,geometry:d,material:f,groupOrder:g,renderOrder:u.renderOrder,z:_,group:m},i[t]=p):(p.id=u.id,p.object=u,p.geometry=d,p.material=f,p.groupOrder=g,p.renderOrder=u.renderOrder,p.z=_,p.group=m),t++,p}function o(u,d,f,g,_,m){const p=a(u,d,f,g,_,m);f.transmission>0?n.push(p):f.transparent===!0?s.push(p):e.push(p)}function l(u,d,f,g,_,m){const p=a(u,d,f,g,_,m);f.transmission>0?n.unshift(p):f.transparent===!0?s.unshift(p):e.unshift(p)}function c(u,d){e.length>1&&e.sort(u||Jx),n.length>1&&n.sort(d||Qu),s.length>1&&s.sort(d||Qu)}function h(){for(let u=t,d=i.length;u<d;u++){const f=i[u];if(f.id===null)break;f.id=null,f.object=null,f.geometry=null,f.material=null,f.group=null}}return{opaque:e,transmissive:n,transparent:s,init:r,push:o,unshift:l,finish:h,sort:c}}function Qx(){let i=new WeakMap;function t(n,s){const r=i.get(n);let a;return r===void 0?(a=new td,i.set(n,[a])):s>=r.length?(a=new td,r.push(a)):a=r[s],a}function e(){i=new WeakMap}return{get:t,dispose:e}}function ty(){const i={};return{get:function(t){if(i[t.id]!==void 0)return i[t.id];let e;switch(t.type){case"DirectionalLight":e={direction:new R,color:new Zt};break;case"SpotLight":e={position:new R,direction:new R,color:new Zt,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":e={position:new R,color:new Zt,distance:0,decay:0};break;case"HemisphereLight":e={direction:new R,skyColor:new Zt,groundColor:new Zt};break;case"RectAreaLight":e={color:new Zt,position:new R,halfWidth:new R,halfHeight:new R};break}return i[t.id]=e,e}}}function ey(){const i={};return{get:function(t){if(i[t.id]!==void 0)return i[t.id];let e;switch(t.type){case"DirectionalLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new rt};break;case"SpotLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new rt};break;case"PointLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new rt,shadowCameraNear:1,shadowCameraFar:1e3};break}return i[t.id]=e,e}}}let ny=0;function iy(i,t){return(t.castShadow?2:0)-(i.castShadow?2:0)+(t.map?1:0)-(i.map?1:0)}function sy(i){const t=new ty,e=ey(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let c=0;c<9;c++)n.probe.push(new R);const s=new R,r=new fe,a=new fe;function o(c){let h=0,u=0,d=0;for(let U=0;U<9;U++)n.probe[U].set(0,0,0);let f=0,g=0,_=0,m=0,p=0,y=0,x=0,S=0,L=0,T=0,E=0;c.sort(iy);for(let U=0,v=c.length;U<v;U++){const b=c[U],I=b.color,O=b.intensity,$=b.distance,K=b.shadow&&b.shadow.map?b.shadow.map.texture:null;if(b.isAmbientLight)h+=I.r*O,u+=I.g*O,d+=I.b*O;else if(b.isLightProbe){for(let z=0;z<9;z++)n.probe[z].addScaledVector(b.sh.coefficients[z],O);E++}else if(b.isDirectionalLight){const z=t.get(b);if(z.color.copy(b.color).multiplyScalar(b.intensity),b.castShadow){const Z=b.shadow,V=e.get(b);V.shadowIntensity=Z.intensity,V.shadowBias=Z.bias,V.shadowNormalBias=Z.normalBias,V.shadowRadius=Z.radius,V.shadowMapSize=Z.mapSize,n.directionalShadow[f]=V,n.directionalShadowMap[f]=K,n.directionalShadowMatrix[f]=b.shadow.matrix,y++}n.directional[f]=z,f++}else if(b.isSpotLight){const z=t.get(b);z.position.setFromMatrixPosition(b.matrixWorld),z.color.copy(I).multiplyScalar(O),z.distance=$,z.coneCos=Math.cos(b.angle),z.penumbraCos=Math.cos(b.angle*(1-b.penumbra)),z.decay=b.decay,n.spot[_]=z;const Z=b.shadow;if(b.map&&(n.spotLightMap[L]=b.map,L++,Z.updateMatrices(b),b.castShadow&&T++),n.spotLightMatrix[_]=Z.matrix,b.castShadow){const V=e.get(b);V.shadowIntensity=Z.intensity,V.shadowBias=Z.bias,V.shadowNormalBias=Z.normalBias,V.shadowRadius=Z.radius,V.shadowMapSize=Z.mapSize,n.spotShadow[_]=V,n.spotShadowMap[_]=K,S++}_++}else if(b.isRectAreaLight){const z=t.get(b);z.color.copy(I).multiplyScalar(O),z.halfWidth.set(b.width*.5,0,0),z.halfHeight.set(0,b.height*.5,0),n.rectArea[m]=z,m++}else if(b.isPointLight){const z=t.get(b);if(z.color.copy(b.color).multiplyScalar(b.intensity),z.distance=b.distance,z.decay=b.decay,b.castShadow){const Z=b.shadow,V=e.get(b);V.shadowIntensity=Z.intensity,V.shadowBias=Z.bias,V.shadowNormalBias=Z.normalBias,V.shadowRadius=Z.radius,V.shadowMapSize=Z.mapSize,V.shadowCameraNear=Z.camera.near,V.shadowCameraFar=Z.camera.far,n.pointShadow[g]=V,n.pointShadowMap[g]=K,n.pointShadowMatrix[g]=b.shadow.matrix,x++}n.point[g]=z,g++}else if(b.isHemisphereLight){const z=t.get(b);z.skyColor.copy(b.color).multiplyScalar(O),z.groundColor.copy(b.groundColor).multiplyScalar(O),n.hemi[p]=z,p++}}m>0&&(i.has("OES_texture_float_linear")===!0?(n.rectAreaLTC1=ut.LTC_FLOAT_1,n.rectAreaLTC2=ut.LTC_FLOAT_2):(n.rectAreaLTC1=ut.LTC_HALF_1,n.rectAreaLTC2=ut.LTC_HALF_2)),n.ambient[0]=h,n.ambient[1]=u,n.ambient[2]=d;const P=n.hash;(P.directionalLength!==f||P.pointLength!==g||P.spotLength!==_||P.rectAreaLength!==m||P.hemiLength!==p||P.numDirectionalShadows!==y||P.numPointShadows!==x||P.numSpotShadows!==S||P.numSpotMaps!==L||P.numLightProbes!==E)&&(n.directional.length=f,n.spot.length=_,n.rectArea.length=m,n.point.length=g,n.hemi.length=p,n.directionalShadow.length=y,n.directionalShadowMap.length=y,n.pointShadow.length=x,n.pointShadowMap.length=x,n.spotShadow.length=S,n.spotShadowMap.length=S,n.directionalShadowMatrix.length=y,n.pointShadowMatrix.length=x,n.spotLightMatrix.length=S+L-T,n.spotLightMap.length=L,n.numSpotLightShadowsWithMaps=T,n.numLightProbes=E,P.directionalLength=f,P.pointLength=g,P.spotLength=_,P.rectAreaLength=m,P.hemiLength=p,P.numDirectionalShadows=y,P.numPointShadows=x,P.numSpotShadows=S,P.numSpotMaps=L,P.numLightProbes=E,n.version=ny++)}function l(c,h){let u=0,d=0,f=0,g=0,_=0;const m=h.matrixWorldInverse;for(let p=0,y=c.length;p<y;p++){const x=c[p];if(x.isDirectionalLight){const S=n.directional[u];S.direction.setFromMatrixPosition(x.matrixWorld),s.setFromMatrixPosition(x.target.matrixWorld),S.direction.sub(s),S.direction.transformDirection(m),u++}else if(x.isSpotLight){const S=n.spot[f];S.position.setFromMatrixPosition(x.matrixWorld),S.position.applyMatrix4(m),S.direction.setFromMatrixPosition(x.matrixWorld),s.setFromMatrixPosition(x.target.matrixWorld),S.direction.sub(s),S.direction.transformDirection(m),f++}else if(x.isRectAreaLight){const S=n.rectArea[g];S.position.setFromMatrixPosition(x.matrixWorld),S.position.applyMatrix4(m),a.identity(),r.copy(x.matrixWorld),r.premultiply(m),a.extractRotation(r),S.halfWidth.set(x.width*.5,0,0),S.halfHeight.set(0,x.height*.5,0),S.halfWidth.applyMatrix4(a),S.halfHeight.applyMatrix4(a),g++}else if(x.isPointLight){const S=n.point[d];S.position.setFromMatrixPosition(x.matrixWorld),S.position.applyMatrix4(m),d++}else if(x.isHemisphereLight){const S=n.hemi[_];S.direction.setFromMatrixPosition(x.matrixWorld),S.direction.transformDirection(m),_++}}}return{setup:o,setupView:l,state:n}}function ed(i){const t=new sy(i),e=[],n=[];function s(h){c.camera=h,e.length=0,n.length=0}function r(h){e.push(h)}function a(h){n.push(h)}function o(){t.setup(e)}function l(h){t.setupView(e,h)}const c={lightsArray:e,shadowsArray:n,camera:null,lights:t,transmissionRenderTarget:{}};return{init:s,state:c,setupLights:o,setupLightsView:l,pushLight:r,pushShadow:a}}function ry(i){let t=new WeakMap;function e(s,r=0){const a=t.get(s);let o;return a===void 0?(o=new ed(i),t.set(s,[o])):r>=a.length?(o=new ed(i),a.push(o)):o=a[r],o}function n(){t=new WeakMap}return{get:e,dispose:n}}class ay extends Fi{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=Hm,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class oy extends Fi{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}const ly=`void main() {
3789
3789
  gl_Position = vec4( position, 1.0 );
3790
- }`,Nx=`uniform sampler2D shadow_pass;
3790
+ }`,cy=`uniform sampler2D shadow_pass;
3791
3791
  uniform vec2 resolution;
3792
3792
  uniform float radius;
3793
3793
  #include <packing>
@@ -3813,12 +3813,12 @@ void main() {
3813
3813
  squared_mean = squared_mean / samples;
3814
3814
  float std_dev = sqrt( squared_mean - mean * mean );
3815
3815
  gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );
3816
- }`;function Ux(i,t,e){let n=new oh;const s=new rt,r=new rt,a=new me,o=new Dx({depthPacking:pm}),l=new Ix,c={},h=e.maxTextureSize,u={[es]:on,[on]:es,[si]:si},d=new Je({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new rt},radius:{value:4}},vertexShader:kx,fragmentShader:Nx}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const g=new cn;g.setAttribute("position",new oi(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const _=new yt(g,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Vd;let p=this.type;this.render=function(T,E,P){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||T.length===0)return;const U=i.getRenderTarget(),v=i.getActiveCubeFace(),b=i.getActiveMipmapLevel(),I=i.state;I.setBlending(Xe),I.buffers.color.setClear(1,1,1,1),I.buffers.depth.setTest(!0),I.setScissorTest(!1);const O=p!==Mi&&this.type===Mi,$=p===Mi&&this.type!==Mi;for(let Y=0,z=T.length;Y<z;Y++){const K=T[Y],V=K.shadow;if(V===void 0){console.warn("THREE.WebGLShadowMap:",K,"has no shadow.");continue}if(V.autoUpdate===!1&&V.needsUpdate===!1)continue;s.copy(V.mapSize);const at=V.getFrameExtents();if(s.multiply(at),r.copy(V.mapSize),(s.x>h||s.y>h)&&(s.x>h&&(r.x=Math.floor(h/at.x),s.x=r.x*at.x,V.mapSize.x=r.x),s.y>h&&(r.y=Math.floor(h/at.y),s.y=r.y*at.y,V.mapSize.y=r.y)),V.map===null||O===!0||$===!0){const _t=this.type!==Mi?{minFilter:tn,magFilter:tn}:{};V.map!==null&&V.map.dispose(),V.map=new Yn(s.x,s.y,_t),V.map.texture.name=K.name+".shadowMap",V.camera.updateProjectionMatrix()}i.setRenderTarget(V.map),i.clear();const ct=V.getViewportCount();for(let _t=0;_t<ct;_t++){const Gt=V.getViewport(_t);a.set(r.x*Gt.x,r.y*Gt.y,r.x*Gt.z,r.y*Gt.w),I.viewport(a),V.updateMatrices(K,_t),n=V.getFrustum(),S(E,P,V.camera,K,this.type)}V.isPointLightShadow!==!0&&this.type===Mi&&y(V,P),V.needsUpdate=!1}p=this.type,m.needsUpdate=!1,i.setRenderTarget(U,v,b)};function y(T,E){const P=t.update(_);d.defines.VSM_SAMPLES!==T.blurSamples&&(d.defines.VSM_SAMPLES=T.blurSamples,f.defines.VSM_SAMPLES=T.blurSamples,d.needsUpdate=!0,f.needsUpdate=!0),T.mapPass===null&&(T.mapPass=new Yn(s.x,s.y)),d.uniforms.shadow_pass.value=T.map.texture,d.uniforms.resolution.value=T.mapSize,d.uniforms.radius.value=T.radius,i.setRenderTarget(T.mapPass),i.clear(),i.renderBufferDirect(E,null,P,d,_,null),f.uniforms.shadow_pass.value=T.mapPass.texture,f.uniforms.resolution.value=T.mapSize,f.uniforms.radius.value=T.radius,i.setRenderTarget(T.map),i.clear(),i.renderBufferDirect(E,null,P,f,_,null)}function x(T,E,P,U){let v=null;const b=P.isPointLight===!0?T.customDistanceMaterial:T.customDepthMaterial;if(b!==void 0)v=b;else if(v=P.isPointLight===!0?l:o,i.localClippingEnabled&&E.clipShadows===!0&&Array.isArray(E.clippingPlanes)&&E.clippingPlanes.length!==0||E.displacementMap&&E.displacementScale!==0||E.alphaMap&&E.alphaTest>0||E.map&&E.alphaTest>0){const I=v.uuid,O=E.uuid;let $=c[I];$===void 0&&($={},c[I]=$);let Y=$[O];Y===void 0&&(Y=v.clone(),$[O]=Y,E.addEventListener("dispose",L)),v=Y}if(v.visible=E.visible,v.wireframe=E.wireframe,U===Mi?v.side=E.shadowSide!==null?E.shadowSide:E.side:v.side=E.shadowSide!==null?E.shadowSide:u[E.side],v.alphaMap=E.alphaMap,v.alphaTest=E.alphaTest,v.map=E.map,v.clipShadows=E.clipShadows,v.clippingPlanes=E.clippingPlanes,v.clipIntersection=E.clipIntersection,v.displacementMap=E.displacementMap,v.displacementScale=E.displacementScale,v.displacementBias=E.displacementBias,v.wireframeLinewidth=E.wireframeLinewidth,v.linewidth=E.linewidth,P.isPointLight===!0&&v.isMeshDistanceMaterial===!0){const I=i.properties.get(v);I.light=P}return v}function S(T,E,P,U,v){if(T.visible===!1)return;if(T.layers.test(E.layers)&&(T.isMesh||T.isLine||T.isPoints)&&(T.castShadow||T.receiveShadow&&v===Mi)&&(!T.frustumCulled||n.intersectsObject(T))){T.modelViewMatrix.multiplyMatrices(P.matrixWorldInverse,T.matrixWorld);const O=t.update(T),$=T.material;if(Array.isArray($)){const Y=O.groups;for(let z=0,K=Y.length;z<K;z++){const V=Y[z],at=$[V.materialIndex];if(at&&at.visible){const ct=x(T,at,U,v);T.onBeforeShadow(i,T,E,P,O,ct,V),i.renderBufferDirect(P,null,O,ct,T,V),T.onAfterShadow(i,T,E,P,O,ct,V)}}}else if($.visible){const Y=x(T,$,U,v);T.onBeforeShadow(i,T,E,P,O,Y,null),i.renderBufferDirect(P,null,O,Y,T,null),T.onAfterShadow(i,T,E,P,O,Y,null)}}const I=T.children;for(let O=0,$=I.length;O<$;O++)S(I[O],E,P,U,v)}function L(T){T.target.removeEventListener("dispose",L);for(const P in c){const U=c[P],v=T.target.uuid;v in U&&(U[v].dispose(),delete U[v])}}}const Ox={[Zl]:Jl,[Ql]:nc,[tc]:ic,[hr]:ec,[Jl]:Zl,[nc]:Ql,[ic]:tc,[ec]:hr};function Fx(i){function t(){let D=!1;const dt=new me;let G=null;const Z=new me(0,0,0,0);return{setMask:function(gt){G!==gt&&!D&&(i.colorMask(gt,gt,gt,gt),G=gt)},setLocked:function(gt){D=gt},setClear:function(gt,xt,ne,Le,hn){hn===!0&&(gt*=Le,xt*=Le,ne*=Le),dt.set(gt,xt,ne,Le),Z.equals(dt)===!1&&(i.clearColor(gt,xt,ne,Le),Z.copy(dt))},reset:function(){D=!1,G=null,Z.set(-1,0,0,0)}}}function e(){let D=!1,dt=!1,G=null,Z=null,gt=null;return{setReversed:function(xt){dt=xt},setTest:function(xt){xt?ft(i.DEPTH_TEST):ot(i.DEPTH_TEST)},setMask:function(xt){G!==xt&&!D&&(i.depthMask(xt),G=xt)},setFunc:function(xt){if(dt&&(xt=Ox[xt]),Z!==xt){switch(xt){case Zl:i.depthFunc(i.NEVER);break;case Jl:i.depthFunc(i.ALWAYS);break;case Ql:i.depthFunc(i.LESS);break;case hr:i.depthFunc(i.LEQUAL);break;case tc:i.depthFunc(i.EQUAL);break;case ec:i.depthFunc(i.GEQUAL);break;case nc:i.depthFunc(i.GREATER);break;case ic:i.depthFunc(i.NOTEQUAL);break;default:i.depthFunc(i.LEQUAL)}Z=xt}},setLocked:function(xt){D=xt},setClear:function(xt){gt!==xt&&(i.clearDepth(xt),gt=xt)},reset:function(){D=!1,G=null,Z=null,gt=null}}}function n(){let D=!1,dt=null,G=null,Z=null,gt=null,xt=null,ne=null,Le=null,hn=null;return{setTest:function(ae){D||(ae?ft(i.STENCIL_TEST):ot(i.STENCIL_TEST))},setMask:function(ae){dt!==ae&&!D&&(i.stencilMask(ae),dt=ae)},setFunc:function(ae,un,pi){(G!==ae||Z!==un||gt!==pi)&&(i.stencilFunc(ae,un,pi),G=ae,Z=un,gt=pi)},setOp:function(ae,un,pi){(xt!==ae||ne!==un||Le!==pi)&&(i.stencilOp(ae,un,pi),xt=ae,ne=un,Le=pi)},setLocked:function(ae){D=ae},setClear:function(ae){hn!==ae&&(i.clearStencil(ae),hn=ae)},reset:function(){D=!1,dt=null,G=null,Z=null,gt=null,xt=null,ne=null,Le=null,hn=null}}}const s=new t,r=new e,a=new n,o=new WeakMap,l=new WeakMap;let c={},h={},u=new WeakMap,d=[],f=null,g=!1,_=null,m=null,p=null,y=null,x=null,S=null,L=null,T=new Zt(0,0,0),E=0,P=!1,U=null,v=null,b=null,I=null,O=null;const $=i.getParameter(i.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let Y=!1,z=0;const K=i.getParameter(i.VERSION);K.indexOf("WebGL")!==-1?(z=parseFloat(/^WebGL (\d)/.exec(K)[1]),Y=z>=1):K.indexOf("OpenGL ES")!==-1&&(z=parseFloat(/^OpenGL ES (\d)/.exec(K)[1]),Y=z>=2);let V=null,at={};const ct=i.getParameter(i.SCISSOR_BOX),_t=i.getParameter(i.VIEWPORT),Gt=new me().fromArray(ct),Jt=new me().fromArray(_t);function X(D,dt,G,Z){const gt=new Uint8Array(4),xt=i.createTexture();i.bindTexture(D,xt),i.texParameteri(D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(D,i.TEXTURE_MAG_FILTER,i.NEAREST);for(let ne=0;ne<G;ne++)D===i.TEXTURE_3D||D===i.TEXTURE_2D_ARRAY?i.texImage3D(dt,0,i.RGBA,1,1,Z,0,i.RGBA,i.UNSIGNED_BYTE,gt):i.texImage2D(dt+ne,0,i.RGBA,1,1,0,i.RGBA,i.UNSIGNED_BYTE,gt);return xt}const et={};et[i.TEXTURE_2D]=X(i.TEXTURE_2D,i.TEXTURE_2D,1),et[i.TEXTURE_CUBE_MAP]=X(i.TEXTURE_CUBE_MAP,i.TEXTURE_CUBE_MAP_POSITIVE_X,6),et[i.TEXTURE_2D_ARRAY]=X(i.TEXTURE_2D_ARRAY,i.TEXTURE_2D_ARRAY,1,1),et[i.TEXTURE_3D]=X(i.TEXTURE_3D,i.TEXTURE_3D,1,1),s.setClear(0,0,0,1),r.setClear(1),a.setClear(0),ft(i.DEPTH_TEST),r.setFunc(hr),Ct(!1),zt(Wh),ft(i.CULL_FACE),A(Xe);function ft(D){c[D]!==!0&&(i.enable(D),c[D]=!0)}function ot(D){c[D]!==!1&&(i.disable(D),c[D]=!1)}function At(D,dt){return h[D]!==dt?(i.bindFramebuffer(D,dt),h[D]=dt,D===i.DRAW_FRAMEBUFFER&&(h[i.FRAMEBUFFER]=dt),D===i.FRAMEBUFFER&&(h[i.DRAW_FRAMEBUFFER]=dt),!0):!1}function Tt(D,dt){let G=d,Z=!1;if(D){G=u.get(dt),G===void 0&&(G=[],u.set(dt,G));const gt=D.textures;if(G.length!==gt.length||G[0]!==i.COLOR_ATTACHMENT0){for(let xt=0,ne=gt.length;xt<ne;xt++)G[xt]=i.COLOR_ATTACHMENT0+xt;G.length=gt.length,Z=!0}}else G[0]!==i.BACK&&(G[0]=i.BACK,Z=!0);Z&&i.drawBuffers(G)}function Ft(D){return f!==D?(i.useProgram(D),f=D,!0):!1}const ie={[$n]:i.FUNC_ADD,[Yp]:i.FUNC_SUBTRACT,[Kp]:i.FUNC_REVERSE_SUBTRACT};ie[Zp]=i.MIN,ie[Jp]=i.MAX;const W={[Nr]:i.ZERO,[Qp]:i.ONE,[tm]:i.SRC_COLOR,[jl]:i.SRC_ALPHA,[sm]:i.SRC_ALPHA_SATURATE,[Kl]:i.DST_COLOR,[Yl]:i.DST_ALPHA,[em]:i.ONE_MINUS_SRC_COLOR,[ql]:i.ONE_MINUS_SRC_ALPHA,[im]:i.ONE_MINUS_DST_COLOR,[nm]:i.ONE_MINUS_DST_ALPHA,[rm]:i.CONSTANT_COLOR,[am]:i.ONE_MINUS_CONSTANT_COLOR,[om]:i.CONSTANT_ALPHA,[lm]:i.ONE_MINUS_CONSTANT_ALPHA};function A(D,dt,G,Z,gt,xt,ne,Le,hn,ae){if(D===Xe){g===!0&&(ot(i.BLEND),g=!1);return}if(g===!1&&(ft(i.BLEND),g=!0),D!==$d){if(D!==_||ae!==P){if((m!==$n||x!==$n)&&(i.blendEquation(i.FUNC_ADD),m=$n,x=$n),ae)switch(D){case sr:i.blendFuncSeparate(i.ONE,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA);break;case Xl:i.blendFunc(i.ONE,i.ONE);break;case Xh:i.blendFuncSeparate(i.ZERO,i.ONE_MINUS_SRC_COLOR,i.ZERO,i.ONE);break;case jh:i.blendFuncSeparate(i.ZERO,i.SRC_COLOR,i.ZERO,i.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",D);break}else switch(D){case sr:i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA);break;case Xl:i.blendFunc(i.SRC_ALPHA,i.ONE);break;case Xh:i.blendFuncSeparate(i.ZERO,i.ONE_MINUS_SRC_COLOR,i.ZERO,i.ONE);break;case jh:i.blendFunc(i.ZERO,i.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",D);break}p=null,y=null,S=null,L=null,T.set(0,0,0),E=0,_=D,P=ae}return}gt=gt||dt,xt=xt||G,ne=ne||Z,(dt!==m||gt!==x)&&(i.blendEquationSeparate(ie[dt],ie[gt]),m=dt,x=gt),(G!==p||Z!==y||xt!==S||ne!==L)&&(i.blendFuncSeparate(W[G],W[Z],W[xt],W[ne]),p=G,y=Z,S=xt,L=ne),(Le.equals(T)===!1||hn!==E)&&(i.blendColor(Le.r,Le.g,Le.b,hn),T.copy(Le),E=hn),_=D,P=!1}function It(D,dt){D.side===si?ot(i.CULL_FACE):ft(i.CULL_FACE);let G=D.side===on;dt&&(G=!G),Ct(G),D.blending===sr&&D.transparent===!1?A(Xe):A(D.blending,D.blendEquation,D.blendSrc,D.blendDst,D.blendEquationAlpha,D.blendSrcAlpha,D.blendDstAlpha,D.blendColor,D.blendAlpha,D.premultipliedAlpha),r.setFunc(D.depthFunc),r.setTest(D.depthTest),r.setMask(D.depthWrite),s.setMask(D.colorWrite);const Z=D.stencilWrite;a.setTest(Z),Z&&(a.setMask(D.stencilWriteMask),a.setFunc(D.stencilFunc,D.stencilRef,D.stencilFuncMask),a.setOp(D.stencilFail,D.stencilZFail,D.stencilZPass)),ue(D.polygonOffset,D.polygonOffsetFactor,D.polygonOffsetUnits),D.alphaToCoverage===!0?ft(i.SAMPLE_ALPHA_TO_COVERAGE):ot(i.SAMPLE_ALPHA_TO_COVERAGE)}function Ct(D){U!==D&&(D?i.frontFace(i.CW):i.frontFace(i.CCW),U=D)}function zt(D){D!==jp?(ft(i.CULL_FACE),D!==v&&(D===Wh?i.cullFace(i.BACK):D===qp?i.cullFace(i.FRONT):i.cullFace(i.FRONT_AND_BACK))):ot(i.CULL_FACE),v=D}function Dt(D){D!==b&&(Y&&i.lineWidth(D),b=D)}function ue(D,dt,G){D?(ft(i.POLYGON_OFFSET_FILL),(I!==dt||O!==G)&&(i.polygonOffset(dt,G),I=dt,O=G)):ot(i.POLYGON_OFFSET_FILL)}function kt(D){D?ft(i.SCISSOR_TEST):ot(i.SCISSOR_TEST)}function C(D){D===void 0&&(D=i.TEXTURE0+$-1),V!==D&&(i.activeTexture(D),V=D)}function M(D,dt,G){G===void 0&&(V===null?G=i.TEXTURE0+$-1:G=V);let Z=at[G];Z===void 0&&(Z={type:void 0,texture:void 0},at[G]=Z),(Z.type!==D||Z.texture!==dt)&&(V!==G&&(i.activeTexture(G),V=G),i.bindTexture(D,dt||et[D]),Z.type=D,Z.texture=dt)}function F(){const D=at[V];D!==void 0&&D.type!==void 0&&(i.bindTexture(D.type,null),D.type=void 0,D.texture=void 0)}function q(){try{i.compressedTexImage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function Q(){try{i.compressedTexImage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function j(){try{i.texSubImage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function St(){try{i.texSubImage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function ht(){try{i.compressedTexSubImage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function pt(){try{i.compressedTexSubImage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function Yt(){try{i.texStorage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function nt(){try{i.texStorage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function mt(){try{i.texImage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function Nt(){try{i.texImage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function Ut(D){Gt.equals(D)===!1&&(i.scissor(D.x,D.y,D.z,D.w),Gt.copy(D))}function Mt(D){Jt.equals(D)===!1&&(i.viewport(D.x,D.y,D.z,D.w),Jt.copy(D))}function Qt(D,dt){let G=l.get(dt);G===void 0&&(G=new WeakMap,l.set(dt,G));let Z=G.get(D);Z===void 0&&(Z=i.getUniformBlockIndex(dt,D.name),G.set(D,Z))}function Vt(D,dt){const Z=l.get(dt).get(D);o.get(dt)!==Z&&(i.uniformBlockBinding(dt,Z,D.__bindingPointIndex),o.set(dt,Z))}function se(){i.disable(i.BLEND),i.disable(i.CULL_FACE),i.disable(i.DEPTH_TEST),i.disable(i.POLYGON_OFFSET_FILL),i.disable(i.SCISSOR_TEST),i.disable(i.STENCIL_TEST),i.disable(i.SAMPLE_ALPHA_TO_COVERAGE),i.blendEquation(i.FUNC_ADD),i.blendFunc(i.ONE,i.ZERO),i.blendFuncSeparate(i.ONE,i.ZERO,i.ONE,i.ZERO),i.blendColor(0,0,0,0),i.colorMask(!0,!0,!0,!0),i.clearColor(0,0,0,0),i.depthMask(!0),i.depthFunc(i.LESS),i.clearDepth(1),i.stencilMask(4294967295),i.stencilFunc(i.ALWAYS,0,4294967295),i.stencilOp(i.KEEP,i.KEEP,i.KEEP),i.clearStencil(0),i.cullFace(i.BACK),i.frontFace(i.CCW),i.polygonOffset(0,0),i.activeTexture(i.TEXTURE0),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,null),i.bindFramebuffer(i.READ_FRAMEBUFFER,null),i.useProgram(null),i.lineWidth(1),i.scissor(0,0,i.canvas.width,i.canvas.height),i.viewport(0,0,i.canvas.width,i.canvas.height),c={},V=null,at={},h={},u=new WeakMap,d=[],f=null,g=!1,_=null,m=null,p=null,y=null,x=null,S=null,L=null,T=new Zt(0,0,0),E=0,P=!1,U=null,v=null,b=null,I=null,O=null,Gt.set(0,0,i.canvas.width,i.canvas.height),Jt.set(0,0,i.canvas.width,i.canvas.height),s.reset(),r.reset(),a.reset()}return{buffers:{color:s,depth:r,stencil:a},enable:ft,disable:ot,bindFramebuffer:At,drawBuffers:Tt,useProgram:Ft,setBlending:A,setMaterial:It,setFlipSided:Ct,setCullFace:zt,setLineWidth:Dt,setPolygonOffset:ue,setScissorTest:kt,activeTexture:C,bindTexture:M,unbindTexture:F,compressedTexImage2D:q,compressedTexImage3D:Q,texImage2D:mt,texImage3D:Nt,updateUBOMapping:Qt,uniformBlockBinding:Vt,texStorage2D:Yt,texStorage3D:nt,texSubImage2D:j,texSubImage3D:St,compressedTexSubImage2D:ht,compressedTexSubImage3D:pt,scissor:Ut,viewport:Mt,reset:se}}function Ou(i,t,e,n){const s=zx(n);switch(e){case ef:return i*t;case sf:return i*t;case rf:return i*t*2;case af:return i*t/s.components*s.byteLength;case Jc:return i*t/s.components*s.byteLength;case of:return i*t*2/s.components*s.byteLength;case Qc:return i*t*2/s.components*s.byteLength;case nf:return i*t*3/s.components*s.byteLength;case Dn:return i*t*4/s.components*s.byteLength;case th:return i*t*4/s.components*s.byteLength;case Xa:case ja:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*8;case qa:case Ya:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*16;case lc:case hc:return Math.max(i,16)*Math.max(t,8)/4;case oc:case cc:return Math.max(i,8)*Math.max(t,8)/2;case uc:case dc:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*8;case fc:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*16;case pc:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*16;case mc:return Math.floor((i+4)/5)*Math.floor((t+3)/4)*16;case gc:return Math.floor((i+4)/5)*Math.floor((t+4)/5)*16;case vc:return Math.floor((i+5)/6)*Math.floor((t+4)/5)*16;case _c:return Math.floor((i+5)/6)*Math.floor((t+5)/6)*16;case xc:return Math.floor((i+7)/8)*Math.floor((t+4)/5)*16;case yc:return Math.floor((i+7)/8)*Math.floor((t+5)/6)*16;case Mc:return Math.floor((i+7)/8)*Math.floor((t+7)/8)*16;case bc:return Math.floor((i+9)/10)*Math.floor((t+4)/5)*16;case Sc:return Math.floor((i+9)/10)*Math.floor((t+5)/6)*16;case wc:return Math.floor((i+9)/10)*Math.floor((t+7)/8)*16;case Ec:return Math.floor((i+9)/10)*Math.floor((t+9)/10)*16;case Tc:return Math.floor((i+11)/12)*Math.floor((t+9)/10)*16;case Ac:return Math.floor((i+11)/12)*Math.floor((t+11)/12)*16;case Ka:case Cc:case Rc:return Math.ceil(i/4)*Math.ceil(t/4)*16;case lf:case Pc:return Math.ceil(i/4)*Math.ceil(t/4)*8;case Lc:case Dc:return Math.ceil(i/4)*Math.ceil(t/4)*16}throw new Error(`Unable to determine texture byte length for ${e} format.`)}function zx(i){switch(i){case hi:case Jd:return{byteLength:1,components:1};case Kr:case Qd:case Li:return{byteLength:2,components:1};case Kc:case Zc:return{byteLength:2,components:4};case _s:case Yc:case wi:return{byteLength:4,components:1};case tf:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${i}.`)}function Bx(i,t,e,n,s,r,a){const o=t.has("WEBGL_multisampled_render_to_texture")?t.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new rt,h=new WeakMap;let u;const d=new WeakMap;let f=!1;try{f=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(C,M){return f?new OffscreenCanvas(C,M):po("canvas")}function _(C,M,F){let q=1;const Q=kt(C);if((Q.width>F||Q.height>F)&&(q=F/Math.max(Q.width,Q.height)),q<1)if(typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&C instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&C instanceof ImageBitmap||typeof VideoFrame<"u"&&C instanceof VideoFrame){const j=Math.floor(q*Q.width),St=Math.floor(q*Q.height);u===void 0&&(u=g(j,St));const ht=M?g(j,St):u;return ht.width=j,ht.height=St,ht.getContext("2d").drawImage(C,0,0,j,St),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+Q.width+"x"+Q.height+") to ("+j+"x"+St+")."),ht}else return"data"in C&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+Q.width+"x"+Q.height+")."),C;return C}function m(C){return C.generateMipmaps&&C.minFilter!==tn&&C.minFilter!==Wn}function p(C){i.generateMipmap(C)}function y(C,M,F,q,Q=!1){if(C!==null){if(i[C]!==void 0)return i[C];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+C+"'")}let j=M;if(M===i.RED&&(F===i.FLOAT&&(j=i.R32F),F===i.HALF_FLOAT&&(j=i.R16F),F===i.UNSIGNED_BYTE&&(j=i.R8)),M===i.RED_INTEGER&&(F===i.UNSIGNED_BYTE&&(j=i.R8UI),F===i.UNSIGNED_SHORT&&(j=i.R16UI),F===i.UNSIGNED_INT&&(j=i.R32UI),F===i.BYTE&&(j=i.R8I),F===i.SHORT&&(j=i.R16I),F===i.INT&&(j=i.R32I)),M===i.RG&&(F===i.FLOAT&&(j=i.RG32F),F===i.HALF_FLOAT&&(j=i.RG16F),F===i.UNSIGNED_BYTE&&(j=i.RG8)),M===i.RG_INTEGER&&(F===i.UNSIGNED_BYTE&&(j=i.RG8UI),F===i.UNSIGNED_SHORT&&(j=i.RG16UI),F===i.UNSIGNED_INT&&(j=i.RG32UI),F===i.BYTE&&(j=i.RG8I),F===i.SHORT&&(j=i.RG16I),F===i.INT&&(j=i.RG32I)),M===i.RGB_INTEGER&&(F===i.UNSIGNED_BYTE&&(j=i.RGB8UI),F===i.UNSIGNED_SHORT&&(j=i.RGB16UI),F===i.UNSIGNED_INT&&(j=i.RGB32UI),F===i.BYTE&&(j=i.RGB8I),F===i.SHORT&&(j=i.RGB16I),F===i.INT&&(j=i.RGB32I)),M===i.RGBA_INTEGER&&(F===i.UNSIGNED_BYTE&&(j=i.RGBA8UI),F===i.UNSIGNED_SHORT&&(j=i.RGBA16UI),F===i.UNSIGNED_INT&&(j=i.RGBA32UI),F===i.BYTE&&(j=i.RGBA8I),F===i.SHORT&&(j=i.RGBA16I),F===i.INT&&(j=i.RGBA32I)),M===i.RGB&&F===i.UNSIGNED_INT_5_9_9_9_REV&&(j=i.RGB9_E5),M===i.RGBA){const St=Q?co:oe.getTransfer(q);F===i.FLOAT&&(j=i.RGBA32F),F===i.HALF_FLOAT&&(j=i.RGBA16F),F===i.UNSIGNED_BYTE&&(j=St===ye?i.SRGB8_ALPHA8:i.RGBA8),F===i.UNSIGNED_SHORT_4_4_4_4&&(j=i.RGBA4),F===i.UNSIGNED_SHORT_5_5_5_1&&(j=i.RGB5_A1)}return(j===i.R16F||j===i.R32F||j===i.RG16F||j===i.RG32F||j===i.RGBA16F||j===i.RGBA32F)&&t.get("EXT_color_buffer_float"),j}function x(C,M){let F;return C?M===null||M===_s||M===xs?F=i.DEPTH24_STENCIL8:M===wi?F=i.DEPTH32F_STENCIL8:M===Kr&&(F=i.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):M===null||M===_s||M===xs?F=i.DEPTH_COMPONENT24:M===wi?F=i.DEPTH_COMPONENT32F:M===Kr&&(F=i.DEPTH_COMPONENT16),F}function S(C,M){return m(C)===!0||C.isFramebufferTexture&&C.minFilter!==tn&&C.minFilter!==Wn?Math.log2(Math.max(M.width,M.height))+1:C.mipmaps!==void 0&&C.mipmaps.length>0?C.mipmaps.length:C.isCompressedTexture&&Array.isArray(C.image)?M.mipmaps.length:1}function L(C){const M=C.target;M.removeEventListener("dispose",L),E(M),M.isVideoTexture&&h.delete(M)}function T(C){const M=C.target;M.removeEventListener("dispose",T),U(M)}function E(C){const M=n.get(C);if(M.__webglInit===void 0)return;const F=C.source,q=d.get(F);if(q){const Q=q[M.__cacheKey];Q.usedTimes--,Q.usedTimes===0&&P(C),Object.keys(q).length===0&&d.delete(F)}n.remove(C)}function P(C){const M=n.get(C);i.deleteTexture(M.__webglTexture);const F=C.source,q=d.get(F);delete q[M.__cacheKey],a.memory.textures--}function U(C){const M=n.get(C);if(C.depthTexture&&C.depthTexture.dispose(),C.isWebGLCubeRenderTarget)for(let q=0;q<6;q++){if(Array.isArray(M.__webglFramebuffer[q]))for(let Q=0;Q<M.__webglFramebuffer[q].length;Q++)i.deleteFramebuffer(M.__webglFramebuffer[q][Q]);else i.deleteFramebuffer(M.__webglFramebuffer[q]);M.__webglDepthbuffer&&i.deleteRenderbuffer(M.__webglDepthbuffer[q])}else{if(Array.isArray(M.__webglFramebuffer))for(let q=0;q<M.__webglFramebuffer.length;q++)i.deleteFramebuffer(M.__webglFramebuffer[q]);else i.deleteFramebuffer(M.__webglFramebuffer);if(M.__webglDepthbuffer&&i.deleteRenderbuffer(M.__webglDepthbuffer),M.__webglMultisampledFramebuffer&&i.deleteFramebuffer(M.__webglMultisampledFramebuffer),M.__webglColorRenderbuffer)for(let q=0;q<M.__webglColorRenderbuffer.length;q++)M.__webglColorRenderbuffer[q]&&i.deleteRenderbuffer(M.__webglColorRenderbuffer[q]);M.__webglDepthRenderbuffer&&i.deleteRenderbuffer(M.__webglDepthRenderbuffer)}const F=C.textures;for(let q=0,Q=F.length;q<Q;q++){const j=n.get(F[q]);j.__webglTexture&&(i.deleteTexture(j.__webglTexture),a.memory.textures--),n.remove(F[q])}n.remove(C)}let v=0;function b(){v=0}function I(){const C=v;return C>=s.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+C+" texture units while this GPU supports only "+s.maxTextures),v+=1,C}function O(C){const M=[];return M.push(C.wrapS),M.push(C.wrapT),M.push(C.wrapR||0),M.push(C.magFilter),M.push(C.minFilter),M.push(C.anisotropy),M.push(C.internalFormat),M.push(C.format),M.push(C.type),M.push(C.generateMipmaps),M.push(C.premultiplyAlpha),M.push(C.flipY),M.push(C.unpackAlignment),M.push(C.colorSpace),M.join()}function $(C,M){const F=n.get(C);if(C.isVideoTexture&&Dt(C),C.isRenderTargetTexture===!1&&C.version>0&&F.__version!==C.version){const q=C.image;if(q===null)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else if(q.complete===!1)console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");else{Jt(F,C,M);return}}e.bindTexture(i.TEXTURE_2D,F.__webglTexture,i.TEXTURE0+M)}function Y(C,M){const F=n.get(C);if(C.version>0&&F.__version!==C.version){Jt(F,C,M);return}e.bindTexture(i.TEXTURE_2D_ARRAY,F.__webglTexture,i.TEXTURE0+M)}function z(C,M){const F=n.get(C);if(C.version>0&&F.__version!==C.version){Jt(F,C,M);return}e.bindTexture(i.TEXTURE_3D,F.__webglTexture,i.TEXTURE0+M)}function K(C,M){const F=n.get(C);if(C.version>0&&F.__version!==C.version){X(F,C,M);return}e.bindTexture(i.TEXTURE_CUBE_MAP,F.__webglTexture,i.TEXTURE0+M)}const V={[Pi]:i.REPEAT,[ms]:i.CLAMP_TO_EDGE,[ac]:i.MIRRORED_REPEAT},at={[tn]:i.NEAREST,[dm]:i.NEAREST_MIPMAP_NEAREST,[ra]:i.NEAREST_MIPMAP_LINEAR,[Wn]:i.LINEAR,[Go]:i.LINEAR_MIPMAP_NEAREST,[gs]:i.LINEAR_MIPMAP_LINEAR},ct={[gm]:i.NEVER,[bm]:i.ALWAYS,[vm]:i.LESS,[cf]:i.LEQUAL,[_m]:i.EQUAL,[Mm]:i.GEQUAL,[xm]:i.GREATER,[ym]:i.NOTEQUAL};function _t(C,M){if(M.type===wi&&t.has("OES_texture_float_linear")===!1&&(M.magFilter===Wn||M.magFilter===Go||M.magFilter===ra||M.magFilter===gs||M.minFilter===Wn||M.minFilter===Go||M.minFilter===ra||M.minFilter===gs)&&console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),i.texParameteri(C,i.TEXTURE_WRAP_S,V[M.wrapS]),i.texParameteri(C,i.TEXTURE_WRAP_T,V[M.wrapT]),(C===i.TEXTURE_3D||C===i.TEXTURE_2D_ARRAY)&&i.texParameteri(C,i.TEXTURE_WRAP_R,V[M.wrapR]),i.texParameteri(C,i.TEXTURE_MAG_FILTER,at[M.magFilter]),i.texParameteri(C,i.TEXTURE_MIN_FILTER,at[M.minFilter]),M.compareFunction&&(i.texParameteri(C,i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE),i.texParameteri(C,i.TEXTURE_COMPARE_FUNC,ct[M.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){if(M.magFilter===tn||M.minFilter!==ra&&M.minFilter!==gs||M.type===wi&&t.has("OES_texture_float_linear")===!1)return;if(M.anisotropy>1||n.get(M).__currentAnisotropy){const F=t.get("EXT_texture_filter_anisotropic");i.texParameterf(C,F.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(M.anisotropy,s.getMaxAnisotropy())),n.get(M).__currentAnisotropy=M.anisotropy}}}function Gt(C,M){let F=!1;C.__webglInit===void 0&&(C.__webglInit=!0,M.addEventListener("dispose",L));const q=M.source;let Q=d.get(q);Q===void 0&&(Q={},d.set(q,Q));const j=O(M);if(j!==C.__cacheKey){Q[j]===void 0&&(Q[j]={texture:i.createTexture(),usedTimes:0},a.memory.textures++,F=!0),Q[j].usedTimes++;const St=Q[C.__cacheKey];St!==void 0&&(Q[C.__cacheKey].usedTimes--,St.usedTimes===0&&P(M)),C.__cacheKey=j,C.__webglTexture=Q[j].texture}return F}function Jt(C,M,F){let q=i.TEXTURE_2D;(M.isDataArrayTexture||M.isCompressedArrayTexture)&&(q=i.TEXTURE_2D_ARRAY),M.isData3DTexture&&(q=i.TEXTURE_3D);const Q=Gt(C,M),j=M.source;e.bindTexture(q,C.__webglTexture,i.TEXTURE0+F);const St=n.get(j);if(j.version!==St.__version||Q===!0){e.activeTexture(i.TEXTURE0+F);const ht=oe.getPrimaries(oe.workingColorSpace),pt=M.colorSpace===Xi?null:oe.getPrimaries(M.colorSpace),Yt=M.colorSpace===Xi||ht===pt?i.NONE:i.BROWSER_DEFAULT_WEBGL;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,M.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,M.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,M.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,Yt);let nt=_(M.image,!1,s.maxTextureSize);nt=ue(M,nt);const mt=r.convert(M.format,M.colorSpace),Nt=r.convert(M.type);let Ut=y(M.internalFormat,mt,Nt,M.colorSpace,M.isVideoTexture);_t(q,M);let Mt;const Qt=M.mipmaps,Vt=M.isVideoTexture!==!0,se=St.__version===void 0||Q===!0,D=j.dataReady,dt=S(M,nt);if(M.isDepthTexture)Ut=x(M.format===ys,M.type),se&&(Vt?e.texStorage2D(i.TEXTURE_2D,1,Ut,nt.width,nt.height):e.texImage2D(i.TEXTURE_2D,0,Ut,nt.width,nt.height,0,mt,Nt,null));else if(M.isDataTexture)if(Qt.length>0){Vt&&se&&e.texStorage2D(i.TEXTURE_2D,dt,Ut,Qt[0].width,Qt[0].height);for(let G=0,Z=Qt.length;G<Z;G++)Mt=Qt[G],Vt?D&&e.texSubImage2D(i.TEXTURE_2D,G,0,0,Mt.width,Mt.height,mt,Nt,Mt.data):e.texImage2D(i.TEXTURE_2D,G,Ut,Mt.width,Mt.height,0,mt,Nt,Mt.data);M.generateMipmaps=!1}else Vt?(se&&e.texStorage2D(i.TEXTURE_2D,dt,Ut,nt.width,nt.height),D&&e.texSubImage2D(i.TEXTURE_2D,0,0,0,nt.width,nt.height,mt,Nt,nt.data)):e.texImage2D(i.TEXTURE_2D,0,Ut,nt.width,nt.height,0,mt,Nt,nt.data);else if(M.isCompressedTexture)if(M.isCompressedArrayTexture){Vt&&se&&e.texStorage3D(i.TEXTURE_2D_ARRAY,dt,Ut,Qt[0].width,Qt[0].height,nt.depth);for(let G=0,Z=Qt.length;G<Z;G++)if(Mt=Qt[G],M.format!==Dn)if(mt!==null)if(Vt){if(D)if(M.layerUpdates.size>0){const gt=Ou(Mt.width,Mt.height,M.format,M.type);for(const xt of M.layerUpdates){const ne=Mt.data.subarray(xt*gt/Mt.data.BYTES_PER_ELEMENT,(xt+1)*gt/Mt.data.BYTES_PER_ELEMENT);e.compressedTexSubImage3D(i.TEXTURE_2D_ARRAY,G,0,0,xt,Mt.width,Mt.height,1,mt,ne,0,0)}M.clearLayerUpdates()}else e.compressedTexSubImage3D(i.TEXTURE_2D_ARRAY,G,0,0,0,Mt.width,Mt.height,nt.depth,mt,Mt.data,0,0)}else e.compressedTexImage3D(i.TEXTURE_2D_ARRAY,G,Ut,Mt.width,Mt.height,nt.depth,0,Mt.data,0,0);else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Vt?D&&e.texSubImage3D(i.TEXTURE_2D_ARRAY,G,0,0,0,Mt.width,Mt.height,nt.depth,mt,Nt,Mt.data):e.texImage3D(i.TEXTURE_2D_ARRAY,G,Ut,Mt.width,Mt.height,nt.depth,0,mt,Nt,Mt.data)}else{Vt&&se&&e.texStorage2D(i.TEXTURE_2D,dt,Ut,Qt[0].width,Qt[0].height);for(let G=0,Z=Qt.length;G<Z;G++)Mt=Qt[G],M.format!==Dn?mt!==null?Vt?D&&e.compressedTexSubImage2D(i.TEXTURE_2D,G,0,0,Mt.width,Mt.height,mt,Mt.data):e.compressedTexImage2D(i.TEXTURE_2D,G,Ut,Mt.width,Mt.height,0,Mt.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):Vt?D&&e.texSubImage2D(i.TEXTURE_2D,G,0,0,Mt.width,Mt.height,mt,Nt,Mt.data):e.texImage2D(i.TEXTURE_2D,G,Ut,Mt.width,Mt.height,0,mt,Nt,Mt.data)}else if(M.isDataArrayTexture)if(Vt){if(se&&e.texStorage3D(i.TEXTURE_2D_ARRAY,dt,Ut,nt.width,nt.height,nt.depth),D)if(M.layerUpdates.size>0){const G=Ou(nt.width,nt.height,M.format,M.type);for(const Z of M.layerUpdates){const gt=nt.data.subarray(Z*G/nt.data.BYTES_PER_ELEMENT,(Z+1)*G/nt.data.BYTES_PER_ELEMENT);e.texSubImage3D(i.TEXTURE_2D_ARRAY,0,0,0,Z,nt.width,nt.height,1,mt,Nt,gt)}M.clearLayerUpdates()}else e.texSubImage3D(i.TEXTURE_2D_ARRAY,0,0,0,0,nt.width,nt.height,nt.depth,mt,Nt,nt.data)}else e.texImage3D(i.TEXTURE_2D_ARRAY,0,Ut,nt.width,nt.height,nt.depth,0,mt,Nt,nt.data);else if(M.isData3DTexture)Vt?(se&&e.texStorage3D(i.TEXTURE_3D,dt,Ut,nt.width,nt.height,nt.depth),D&&e.texSubImage3D(i.TEXTURE_3D,0,0,0,0,nt.width,nt.height,nt.depth,mt,Nt,nt.data)):e.texImage3D(i.TEXTURE_3D,0,Ut,nt.width,nt.height,nt.depth,0,mt,Nt,nt.data);else if(M.isFramebufferTexture){if(se)if(Vt)e.texStorage2D(i.TEXTURE_2D,dt,Ut,nt.width,nt.height);else{let G=nt.width,Z=nt.height;for(let gt=0;gt<dt;gt++)e.texImage2D(i.TEXTURE_2D,gt,Ut,G,Z,0,mt,Nt,null),G>>=1,Z>>=1}}else if(Qt.length>0){if(Vt&&se){const G=kt(Qt[0]);e.texStorage2D(i.TEXTURE_2D,dt,Ut,G.width,G.height)}for(let G=0,Z=Qt.length;G<Z;G++)Mt=Qt[G],Vt?D&&e.texSubImage2D(i.TEXTURE_2D,G,0,0,mt,Nt,Mt):e.texImage2D(i.TEXTURE_2D,G,Ut,mt,Nt,Mt);M.generateMipmaps=!1}else if(Vt){if(se){const G=kt(nt);e.texStorage2D(i.TEXTURE_2D,dt,Ut,G.width,G.height)}D&&e.texSubImage2D(i.TEXTURE_2D,0,0,0,mt,Nt,nt)}else e.texImage2D(i.TEXTURE_2D,0,Ut,mt,Nt,nt);m(M)&&p(q),St.__version=j.version,M.onUpdate&&M.onUpdate(M)}C.__version=M.version}function X(C,M,F){if(M.image.length!==6)return;const q=Gt(C,M),Q=M.source;e.bindTexture(i.TEXTURE_CUBE_MAP,C.__webglTexture,i.TEXTURE0+F);const j=n.get(Q);if(Q.version!==j.__version||q===!0){e.activeTexture(i.TEXTURE0+F);const St=oe.getPrimaries(oe.workingColorSpace),ht=M.colorSpace===Xi?null:oe.getPrimaries(M.colorSpace),pt=M.colorSpace===Xi||St===ht?i.NONE:i.BROWSER_DEFAULT_WEBGL;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,M.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,M.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,M.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,pt);const Yt=M.isCompressedTexture||M.image[0].isCompressedTexture,nt=M.image[0]&&M.image[0].isDataTexture,mt=[];for(let Z=0;Z<6;Z++)!Yt&&!nt?mt[Z]=_(M.image[Z],!0,s.maxCubemapSize):mt[Z]=nt?M.image[Z].image:M.image[Z],mt[Z]=ue(M,mt[Z]);const Nt=mt[0],Ut=r.convert(M.format,M.colorSpace),Mt=r.convert(M.type),Qt=y(M.internalFormat,Ut,Mt,M.colorSpace),Vt=M.isVideoTexture!==!0,se=j.__version===void 0||q===!0,D=Q.dataReady;let dt=S(M,Nt);_t(i.TEXTURE_CUBE_MAP,M);let G;if(Yt){Vt&&se&&e.texStorage2D(i.TEXTURE_CUBE_MAP,dt,Qt,Nt.width,Nt.height);for(let Z=0;Z<6;Z++){G=mt[Z].mipmaps;for(let gt=0;gt<G.length;gt++){const xt=G[gt];M.format!==Dn?Ut!==null?Vt?D&&e.compressedTexSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,gt,0,0,xt.width,xt.height,Ut,xt.data):e.compressedTexImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,gt,Qt,xt.width,xt.height,0,xt.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,gt,0,0,xt.width,xt.height,Ut,Mt,xt.data):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,gt,Qt,xt.width,xt.height,0,Ut,Mt,xt.data)}}}else{if(G=M.mipmaps,Vt&&se){G.length>0&&dt++;const Z=kt(mt[0]);e.texStorage2D(i.TEXTURE_CUBE_MAP,dt,Qt,Z.width,Z.height)}for(let Z=0;Z<6;Z++)if(nt){Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0,0,0,mt[Z].width,mt[Z].height,Ut,Mt,mt[Z].data):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0,Qt,mt[Z].width,mt[Z].height,0,Ut,Mt,mt[Z].data);for(let gt=0;gt<G.length;gt++){const ne=G[gt].image[Z].image;Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,gt+1,0,0,ne.width,ne.height,Ut,Mt,ne.data):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,gt+1,Qt,ne.width,ne.height,0,Ut,Mt,ne.data)}}else{Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0,0,0,Ut,Mt,mt[Z]):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0,Qt,Ut,Mt,mt[Z]);for(let gt=0;gt<G.length;gt++){const xt=G[gt];Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,gt+1,0,0,Ut,Mt,xt.image[Z]):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+Z,gt+1,Qt,Ut,Mt,xt.image[Z])}}}m(M)&&p(i.TEXTURE_CUBE_MAP),j.__version=Q.version,M.onUpdate&&M.onUpdate(M)}C.__version=M.version}function et(C,M,F,q,Q,j){const St=r.convert(F.format,F.colorSpace),ht=r.convert(F.type),pt=y(F.internalFormat,St,ht,F.colorSpace);if(!n.get(M).__hasExternalTextures){const nt=Math.max(1,M.width>>j),mt=Math.max(1,M.height>>j);Q===i.TEXTURE_3D||Q===i.TEXTURE_2D_ARRAY?e.texImage3D(Q,j,pt,nt,mt,M.depth,0,St,ht,null):e.texImage2D(Q,j,pt,nt,mt,0,St,ht,null)}e.bindFramebuffer(i.FRAMEBUFFER,C),zt(M)?o.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,q,Q,n.get(F).__webglTexture,0,Ct(M)):(Q===i.TEXTURE_2D||Q>=i.TEXTURE_CUBE_MAP_POSITIVE_X&&Q<=i.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&i.framebufferTexture2D(i.FRAMEBUFFER,q,Q,n.get(F).__webglTexture,j),e.bindFramebuffer(i.FRAMEBUFFER,null)}function ft(C,M,F){if(i.bindRenderbuffer(i.RENDERBUFFER,C),M.depthBuffer){const q=M.depthTexture,Q=q&&q.isDepthTexture?q.type:null,j=x(M.stencilBuffer,Q),St=M.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,ht=Ct(M);zt(M)?o.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,ht,j,M.width,M.height):F?i.renderbufferStorageMultisample(i.RENDERBUFFER,ht,j,M.width,M.height):i.renderbufferStorage(i.RENDERBUFFER,j,M.width,M.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,St,i.RENDERBUFFER,C)}else{const q=M.textures;for(let Q=0;Q<q.length;Q++){const j=q[Q],St=r.convert(j.format,j.colorSpace),ht=r.convert(j.type),pt=y(j.internalFormat,St,ht,j.colorSpace),Yt=Ct(M);F&&zt(M)===!1?i.renderbufferStorageMultisample(i.RENDERBUFFER,Yt,pt,M.width,M.height):zt(M)?o.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,Yt,pt,M.width,M.height):i.renderbufferStorage(i.RENDERBUFFER,pt,M.width,M.height)}}i.bindRenderbuffer(i.RENDERBUFFER,null)}function ot(C,M){if(M&&M.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(e.bindFramebuffer(i.FRAMEBUFFER,C),!(M.depthTexture&&M.depthTexture.isDepthTexture))throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");(!n.get(M.depthTexture).__webglTexture||M.depthTexture.image.width!==M.width||M.depthTexture.image.height!==M.height)&&(M.depthTexture.image.width=M.width,M.depthTexture.image.height=M.height,M.depthTexture.needsUpdate=!0),$(M.depthTexture,0);const q=n.get(M.depthTexture).__webglTexture,Q=Ct(M);if(M.depthTexture.format===rr)zt(M)?o.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,q,0,Q):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,q,0);else if(M.depthTexture.format===ys)zt(M)?o.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_2D,q,0,Q):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_2D,q,0);else throw new Error("Unknown depthTexture format")}function At(C){const M=n.get(C),F=C.isWebGLCubeRenderTarget===!0;if(M.__boundDepthTexture!==C.depthTexture){const q=C.depthTexture;if(M.__depthDisposeCallback&&M.__depthDisposeCallback(),q){const Q=()=>{delete M.__boundDepthTexture,delete M.__depthDisposeCallback,q.removeEventListener("dispose",Q)};q.addEventListener("dispose",Q),M.__depthDisposeCallback=Q}M.__boundDepthTexture=q}if(C.depthTexture&&!M.__autoAllocateDepthBuffer){if(F)throw new Error("target.depthTexture not supported in Cube render targets");ot(M.__webglFramebuffer,C)}else if(F){M.__webglDepthbuffer=[];for(let q=0;q<6;q++)if(e.bindFramebuffer(i.FRAMEBUFFER,M.__webglFramebuffer[q]),M.__webglDepthbuffer[q]===void 0)M.__webglDepthbuffer[q]=i.createRenderbuffer(),ft(M.__webglDepthbuffer[q],C,!1);else{const Q=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,j=M.__webglDepthbuffer[q];i.bindRenderbuffer(i.RENDERBUFFER,j),i.framebufferRenderbuffer(i.FRAMEBUFFER,Q,i.RENDERBUFFER,j)}}else if(e.bindFramebuffer(i.FRAMEBUFFER,M.__webglFramebuffer),M.__webglDepthbuffer===void 0)M.__webglDepthbuffer=i.createRenderbuffer(),ft(M.__webglDepthbuffer,C,!1);else{const q=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,Q=M.__webglDepthbuffer;i.bindRenderbuffer(i.RENDERBUFFER,Q),i.framebufferRenderbuffer(i.FRAMEBUFFER,q,i.RENDERBUFFER,Q)}e.bindFramebuffer(i.FRAMEBUFFER,null)}function Tt(C,M,F){const q=n.get(C);M!==void 0&&et(q.__webglFramebuffer,C,C.texture,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,0),F!==void 0&&At(C)}function Ft(C){const M=C.texture,F=n.get(C),q=n.get(M);C.addEventListener("dispose",T);const Q=C.textures,j=C.isWebGLCubeRenderTarget===!0,St=Q.length>1;if(St||(q.__webglTexture===void 0&&(q.__webglTexture=i.createTexture()),q.__version=M.version,a.memory.textures++),j){F.__webglFramebuffer=[];for(let ht=0;ht<6;ht++)if(M.mipmaps&&M.mipmaps.length>0){F.__webglFramebuffer[ht]=[];for(let pt=0;pt<M.mipmaps.length;pt++)F.__webglFramebuffer[ht][pt]=i.createFramebuffer()}else F.__webglFramebuffer[ht]=i.createFramebuffer()}else{if(M.mipmaps&&M.mipmaps.length>0){F.__webglFramebuffer=[];for(let ht=0;ht<M.mipmaps.length;ht++)F.__webglFramebuffer[ht]=i.createFramebuffer()}else F.__webglFramebuffer=i.createFramebuffer();if(St)for(let ht=0,pt=Q.length;ht<pt;ht++){const Yt=n.get(Q[ht]);Yt.__webglTexture===void 0&&(Yt.__webglTexture=i.createTexture(),a.memory.textures++)}if(C.samples>0&&zt(C)===!1){F.__webglMultisampledFramebuffer=i.createFramebuffer(),F.__webglColorRenderbuffer=[],e.bindFramebuffer(i.FRAMEBUFFER,F.__webglMultisampledFramebuffer);for(let ht=0;ht<Q.length;ht++){const pt=Q[ht];F.__webglColorRenderbuffer[ht]=i.createRenderbuffer(),i.bindRenderbuffer(i.RENDERBUFFER,F.__webglColorRenderbuffer[ht]);const Yt=r.convert(pt.format,pt.colorSpace),nt=r.convert(pt.type),mt=y(pt.internalFormat,Yt,nt,pt.colorSpace,C.isXRRenderTarget===!0),Nt=Ct(C);i.renderbufferStorageMultisample(i.RENDERBUFFER,Nt,mt,C.width,C.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+ht,i.RENDERBUFFER,F.__webglColorRenderbuffer[ht])}i.bindRenderbuffer(i.RENDERBUFFER,null),C.depthBuffer&&(F.__webglDepthRenderbuffer=i.createRenderbuffer(),ft(F.__webglDepthRenderbuffer,C,!0)),e.bindFramebuffer(i.FRAMEBUFFER,null)}}if(j){e.bindTexture(i.TEXTURE_CUBE_MAP,q.__webglTexture),_t(i.TEXTURE_CUBE_MAP,M);for(let ht=0;ht<6;ht++)if(M.mipmaps&&M.mipmaps.length>0)for(let pt=0;pt<M.mipmaps.length;pt++)et(F.__webglFramebuffer[ht][pt],C,M,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+ht,pt);else et(F.__webglFramebuffer[ht],C,M,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+ht,0);m(M)&&p(i.TEXTURE_CUBE_MAP),e.unbindTexture()}else if(St){for(let ht=0,pt=Q.length;ht<pt;ht++){const Yt=Q[ht],nt=n.get(Yt);e.bindTexture(i.TEXTURE_2D,nt.__webglTexture),_t(i.TEXTURE_2D,Yt),et(F.__webglFramebuffer,C,Yt,i.COLOR_ATTACHMENT0+ht,i.TEXTURE_2D,0),m(Yt)&&p(i.TEXTURE_2D)}e.unbindTexture()}else{let ht=i.TEXTURE_2D;if((C.isWebGL3DRenderTarget||C.isWebGLArrayRenderTarget)&&(ht=C.isWebGL3DRenderTarget?i.TEXTURE_3D:i.TEXTURE_2D_ARRAY),e.bindTexture(ht,q.__webglTexture),_t(ht,M),M.mipmaps&&M.mipmaps.length>0)for(let pt=0;pt<M.mipmaps.length;pt++)et(F.__webglFramebuffer[pt],C,M,i.COLOR_ATTACHMENT0,ht,pt);else et(F.__webglFramebuffer,C,M,i.COLOR_ATTACHMENT0,ht,0);m(M)&&p(ht),e.unbindTexture()}C.depthBuffer&&At(C)}function ie(C){const M=C.textures;for(let F=0,q=M.length;F<q;F++){const Q=M[F];if(m(Q)){const j=C.isWebGLCubeRenderTarget?i.TEXTURE_CUBE_MAP:i.TEXTURE_2D,St=n.get(Q).__webglTexture;e.bindTexture(j,St),p(j),e.unbindTexture()}}}const W=[],A=[];function It(C){if(C.samples>0){if(zt(C)===!1){const M=C.textures,F=C.width,q=C.height;let Q=i.COLOR_BUFFER_BIT;const j=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,St=n.get(C),ht=M.length>1;if(ht)for(let pt=0;pt<M.length;pt++)e.bindFramebuffer(i.FRAMEBUFFER,St.__webglMultisampledFramebuffer),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+pt,i.RENDERBUFFER,null),e.bindFramebuffer(i.FRAMEBUFFER,St.__webglFramebuffer),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0+pt,i.TEXTURE_2D,null,0);e.bindFramebuffer(i.READ_FRAMEBUFFER,St.__webglMultisampledFramebuffer),e.bindFramebuffer(i.DRAW_FRAMEBUFFER,St.__webglFramebuffer);for(let pt=0;pt<M.length;pt++){if(C.resolveDepthBuffer&&(C.depthBuffer&&(Q|=i.DEPTH_BUFFER_BIT),C.stencilBuffer&&C.resolveStencilBuffer&&(Q|=i.STENCIL_BUFFER_BIT)),ht){i.framebufferRenderbuffer(i.READ_FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,St.__webglColorRenderbuffer[pt]);const Yt=n.get(M[pt]).__webglTexture;i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,Yt,0)}i.blitFramebuffer(0,0,F,q,0,0,F,q,Q,i.NEAREST),l===!0&&(W.length=0,A.length=0,W.push(i.COLOR_ATTACHMENT0+pt),C.depthBuffer&&C.resolveDepthBuffer===!1&&(W.push(j),A.push(j),i.invalidateFramebuffer(i.DRAW_FRAMEBUFFER,A)),i.invalidateFramebuffer(i.READ_FRAMEBUFFER,W))}if(e.bindFramebuffer(i.READ_FRAMEBUFFER,null),e.bindFramebuffer(i.DRAW_FRAMEBUFFER,null),ht)for(let pt=0;pt<M.length;pt++){e.bindFramebuffer(i.FRAMEBUFFER,St.__webglMultisampledFramebuffer),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+pt,i.RENDERBUFFER,St.__webglColorRenderbuffer[pt]);const Yt=n.get(M[pt]).__webglTexture;e.bindFramebuffer(i.FRAMEBUFFER,St.__webglFramebuffer),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0+pt,i.TEXTURE_2D,Yt,0)}e.bindFramebuffer(i.DRAW_FRAMEBUFFER,St.__webglMultisampledFramebuffer)}else if(C.depthBuffer&&C.resolveDepthBuffer===!1&&l){const M=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT;i.invalidateFramebuffer(i.DRAW_FRAMEBUFFER,[M])}}}function Ct(C){return Math.min(s.maxSamples,C.samples)}function zt(C){const M=n.get(C);return C.samples>0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&M.__useRenderToTexture!==!1}function Dt(C){const M=a.render.frame;h.get(C)!==M&&(h.set(C,M),C.update())}function ue(C,M){const F=C.colorSpace,q=C.format,Q=C.type;return C.isCompressedTexture===!0||C.isVideoTexture===!0||F!==is&&F!==Xi&&(oe.getTransfer(F)===ye?(q!==Dn||Q!==hi)&&console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",F)),M}function kt(C){return typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement?(c.width=C.naturalWidth||C.width,c.height=C.naturalHeight||C.height):typeof VideoFrame<"u"&&C instanceof VideoFrame?(c.width=C.displayWidth,c.height=C.displayHeight):(c.width=C.width,c.height=C.height),c}this.allocateTextureUnit=I,this.resetTextureUnits=b,this.setTexture2D=$,this.setTexture2DArray=Y,this.setTexture3D=z,this.setTextureCube=K,this.rebindTextures=Tt,this.setupRenderTarget=Ft,this.updateRenderTargetMipmap=ie,this.updateMultisampleRenderTarget=It,this.setupDepthRenderbuffer=At,this.setupFrameBufferTexture=et,this.useMultisampledRTT=zt}function Hx(i,t){function e(n,s=Xi){let r;const a=oe.getTransfer(s);if(n===hi)return i.UNSIGNED_BYTE;if(n===Kc)return i.UNSIGNED_SHORT_4_4_4_4;if(n===Zc)return i.UNSIGNED_SHORT_5_5_5_1;if(n===tf)return i.UNSIGNED_INT_5_9_9_9_REV;if(n===Jd)return i.BYTE;if(n===Qd)return i.SHORT;if(n===Kr)return i.UNSIGNED_SHORT;if(n===Yc)return i.INT;if(n===_s)return i.UNSIGNED_INT;if(n===wi)return i.FLOAT;if(n===Li)return i.HALF_FLOAT;if(n===ef)return i.ALPHA;if(n===nf)return i.RGB;if(n===Dn)return i.RGBA;if(n===sf)return i.LUMINANCE;if(n===rf)return i.LUMINANCE_ALPHA;if(n===rr)return i.DEPTH_COMPONENT;if(n===ys)return i.DEPTH_STENCIL;if(n===af)return i.RED;if(n===Jc)return i.RED_INTEGER;if(n===of)return i.RG;if(n===Qc)return i.RG_INTEGER;if(n===th)return i.RGBA_INTEGER;if(n===Xa||n===ja||n===qa||n===Ya)if(a===ye)if(r=t.get("WEBGL_compressed_texture_s3tc_srgb"),r!==null){if(n===Xa)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===ja)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===qa)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===Ya)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(r=t.get("WEBGL_compressed_texture_s3tc"),r!==null){if(n===Xa)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===ja)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===qa)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===Ya)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===oc||n===lc||n===cc||n===hc)if(r=t.get("WEBGL_compressed_texture_pvrtc"),r!==null){if(n===oc)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===lc)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===cc)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===hc)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===uc||n===dc||n===fc)if(r=t.get("WEBGL_compressed_texture_etc"),r!==null){if(n===uc||n===dc)return a===ye?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(n===fc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(n===pc||n===mc||n===gc||n===vc||n===_c||n===xc||n===yc||n===Mc||n===bc||n===Sc||n===wc||n===Ec||n===Tc||n===Ac)if(r=t.get("WEBGL_compressed_texture_astc"),r!==null){if(n===pc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===mc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===gc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===vc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===_c)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===xc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===yc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===Mc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===bc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===Sc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===wc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===Ec)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===Tc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===Ac)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===Ka||n===Cc||n===Rc)if(r=t.get("EXT_texture_compression_bptc"),r!==null){if(n===Ka)return a===ye?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===Cc)return r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===Rc)return r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===lf||n===Pc||n===Lc||n===Dc)if(r=t.get("EXT_texture_compression_rgtc"),r!==null){if(n===Ka)return r.COMPRESSED_RED_RGTC1_EXT;if(n===Pc)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===Lc)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===Dc)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===xs?i.UNSIGNED_INT_24_8:i[n]!==void 0?i[n]:null}return{convert:e}}class Vx extends wn{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class qt extends Ye{constructor(){super(),this.isGroup=!0,this.type="Group"}}const Gx={type:"move"};class vl{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new qt,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new qt,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new R,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new R),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new qt,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new R,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new R),this._grip}dispatchEvent(t){return this._targetRay!==null&&this._targetRay.dispatchEvent(t),this._grip!==null&&this._grip.dispatchEvent(t),this._hand!==null&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){const e=this._hand;if(e)for(const n of t.hand.values())this._getHandJoint(e,n)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(t,e,n){let s=null,r=null,a=null;const o=this._targetRay,l=this._grip,c=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(c&&t.hand){a=!0;for(const _ of t.hand.values()){const m=e.getJointPose(_,n),p=this._getHandJoint(c,_);m!==null&&(p.matrix.fromArray(m.transform.matrix),p.matrix.decompose(p.position,p.rotation,p.scale),p.matrixWorldNeedsUpdate=!0,p.jointRadius=m.radius),p.visible=m!==null}const h=c.joints["index-finger-tip"],u=c.joints["thumb-tip"],d=h.position.distanceTo(u.position),f=.02,g=.005;c.inputState.pinching&&d>f+g?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!c.inputState.pinching&&d<=f-g&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else l!==null&&t.gripSpace&&(r=e.getPose(t.gripSpace,n),r!==null&&(l.matrix.fromArray(r.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,r.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(r.linearVelocity)):l.hasLinearVelocity=!1,r.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(r.angularVelocity)):l.hasAngularVelocity=!1));o!==null&&(s=e.getPose(t.targetRaySpace,n),s===null&&r!==null&&(s=r),s!==null&&(o.matrix.fromArray(s.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,s.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(s.linearVelocity)):o.hasLinearVelocity=!1,s.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(s.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(Gx)))}return o!==null&&(o.visible=s!==null),l!==null&&(l.visible=r!==null),c!==null&&(c.visible=a!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){const n=new qt;n.matrixAutoUpdate=!1,n.visible=!1,t.joints[e.jointName]=n,t.add(n)}return t.joints[e.jointName]}}const $x=`
3816
+ }`;function hy(i,t,e){let n=new Sh;const s=new rt,r=new rt,a=new me,o=new ay({depthPacking:Vm}),l=new oy,c={},h=e.maxTextureSize,u={[os]:un,[un]:os,[li]:li},d=new nn({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new rt},radius:{value:4}},vertexShader:ly,fragmentShader:cy}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const g=new fn;g.setAttribute("position",new ui(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const _=new yt(g,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=ff;let p=this.type;this.render=function(T,E,P){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||T.length===0)return;const U=i.getRenderTarget(),v=i.getActiveCubeFace(),b=i.getActiveMipmapLevel(),I=i.state;I.setBlending(Ye),I.buffers.color.setClear(1,1,1,1),I.buffers.depth.setTest(!0),I.setScissorTest(!1);const O=p!==Ei&&this.type===Ei,$=p===Ei&&this.type!==Ei;for(let K=0,z=T.length;K<z;K++){const Z=T[K],V=Z.shadow;if(V===void 0){console.warn("THREE.WebGLShadowMap:",Z,"has no shadow.");continue}if(V.autoUpdate===!1&&V.needsUpdate===!1)continue;s.copy(V.mapSize);const at=V.getFrameExtents();if(s.multiply(at),r.copy(V.mapSize),(s.x>h||s.y>h)&&(s.x>h&&(r.x=Math.floor(h/at.x),s.x=r.x*at.x,V.mapSize.x=r.x),s.y>h&&(r.y=Math.floor(h/at.y),s.y=r.y*at.y,V.mapSize.y=r.y)),V.map===null||O===!0||$===!0){const _t=this.type!==Ei?{minFilter:rn,magFilter:rn}:{};V.map!==null&&V.map.dispose(),V.map=new Qn(s.x,s.y,_t),V.map.texture.name=Z.name+".shadowMap",V.camera.updateProjectionMatrix()}i.setRenderTarget(V.map),i.clear();const ct=V.getViewportCount();for(let _t=0;_t<ct;_t++){const $t=V.getViewport(_t);a.set(r.x*$t.x,r.y*$t.y,r.x*$t.z,r.y*$t.w),I.viewport(a),V.updateMatrices(Z,_t),n=V.getFrustum(),S(E,P,V.camera,Z,this.type)}V.isPointLightShadow!==!0&&this.type===Ei&&y(V,P),V.needsUpdate=!1}p=this.type,m.needsUpdate=!1,i.setRenderTarget(U,v,b)};function y(T,E){const P=t.update(_);d.defines.VSM_SAMPLES!==T.blurSamples&&(d.defines.VSM_SAMPLES=T.blurSamples,f.defines.VSM_SAMPLES=T.blurSamples,d.needsUpdate=!0,f.needsUpdate=!0),T.mapPass===null&&(T.mapPass=new Qn(s.x,s.y)),d.uniforms.shadow_pass.value=T.map.texture,d.uniforms.resolution.value=T.mapSize,d.uniforms.radius.value=T.radius,i.setRenderTarget(T.mapPass),i.clear(),i.renderBufferDirect(E,null,P,d,_,null),f.uniforms.shadow_pass.value=T.mapPass.texture,f.uniforms.resolution.value=T.mapSize,f.uniforms.radius.value=T.radius,i.setRenderTarget(T.map),i.clear(),i.renderBufferDirect(E,null,P,f,_,null)}function x(T,E,P,U){let v=null;const b=P.isPointLight===!0?T.customDistanceMaterial:T.customDepthMaterial;if(b!==void 0)v=b;else if(v=P.isPointLight===!0?l:o,i.localClippingEnabled&&E.clipShadows===!0&&Array.isArray(E.clippingPlanes)&&E.clippingPlanes.length!==0||E.displacementMap&&E.displacementScale!==0||E.alphaMap&&E.alphaTest>0||E.map&&E.alphaTest>0){const I=v.uuid,O=E.uuid;let $=c[I];$===void 0&&($={},c[I]=$);let K=$[O];K===void 0&&(K=v.clone(),$[O]=K,E.addEventListener("dispose",L)),v=K}if(v.visible=E.visible,v.wireframe=E.wireframe,U===Ei?v.side=E.shadowSide!==null?E.shadowSide:E.side:v.side=E.shadowSide!==null?E.shadowSide:u[E.side],v.alphaMap=E.alphaMap,v.alphaTest=E.alphaTest,v.map=E.map,v.clipShadows=E.clipShadows,v.clippingPlanes=E.clippingPlanes,v.clipIntersection=E.clipIntersection,v.displacementMap=E.displacementMap,v.displacementScale=E.displacementScale,v.displacementBias=E.displacementBias,v.wireframeLinewidth=E.wireframeLinewidth,v.linewidth=E.linewidth,P.isPointLight===!0&&v.isMeshDistanceMaterial===!0){const I=i.properties.get(v);I.light=P}return v}function S(T,E,P,U,v){if(T.visible===!1)return;if(T.layers.test(E.layers)&&(T.isMesh||T.isLine||T.isPoints)&&(T.castShadow||T.receiveShadow&&v===Ei)&&(!T.frustumCulled||n.intersectsObject(T))){T.modelViewMatrix.multiplyMatrices(P.matrixWorldInverse,T.matrixWorld);const O=t.update(T),$=T.material;if(Array.isArray($)){const K=O.groups;for(let z=0,Z=K.length;z<Z;z++){const V=K[z],at=$[V.materialIndex];if(at&&at.visible){const ct=x(T,at,U,v);T.onBeforeShadow(i,T,E,P,O,ct,V),i.renderBufferDirect(P,null,O,ct,T,V),T.onAfterShadow(i,T,E,P,O,ct,V)}}}else if($.visible){const K=x(T,$,U,v);T.onBeforeShadow(i,T,E,P,O,K,null),i.renderBufferDirect(P,null,O,K,T,null),T.onAfterShadow(i,T,E,P,O,K,null)}}const I=T.children;for(let O=0,$=I.length;O<$;O++)S(I[O],E,P,U,v)}function L(T){T.target.removeEventListener("dispose",L);for(const P in c){const U=c[P],v=T.target.uuid;v in U&&(U[v].dispose(),delete U[v])}}}const uy={[uc]:dc,[fc]:gc,[pc]:vc,[xr]:mc,[dc]:uc,[gc]:fc,[vc]:pc,[mc]:xr};function dy(i){function t(){let D=!1;const dt=new me;let G=null;const J=new me(0,0,0,0);return{setMask:function(gt){G!==gt&&!D&&(i.colorMask(gt,gt,gt,gt),G=gt)},setLocked:function(gt){D=gt},setClear:function(gt,xt,ne,ke,pn){pn===!0&&(gt*=ke,xt*=ke,ne*=ke),dt.set(gt,xt,ne,ke),J.equals(dt)===!1&&(i.clearColor(gt,xt,ne,ke),J.copy(dt))},reset:function(){D=!1,G=null,J.set(-1,0,0,0)}}}function e(){let D=!1,dt=!1,G=null,J=null,gt=null;return{setReversed:function(xt){dt=xt},setTest:function(xt){xt?ft(i.DEPTH_TEST):ot(i.DEPTH_TEST)},setMask:function(xt){G!==xt&&!D&&(i.depthMask(xt),G=xt)},setFunc:function(xt){if(dt&&(xt=uy[xt]),J!==xt){switch(xt){case uc:i.depthFunc(i.NEVER);break;case dc:i.depthFunc(i.ALWAYS);break;case fc:i.depthFunc(i.LESS);break;case xr:i.depthFunc(i.LEQUAL);break;case pc:i.depthFunc(i.EQUAL);break;case mc:i.depthFunc(i.GEQUAL);break;case gc:i.depthFunc(i.GREATER);break;case vc:i.depthFunc(i.NOTEQUAL);break;default:i.depthFunc(i.LEQUAL)}J=xt}},setLocked:function(xt){D=xt},setClear:function(xt){gt!==xt&&(i.clearDepth(xt),gt=xt)},reset:function(){D=!1,G=null,J=null,gt=null}}}function n(){let D=!1,dt=null,G=null,J=null,gt=null,xt=null,ne=null,ke=null,pn=null;return{setTest:function(ae){D||(ae?ft(i.STENCIL_TEST):ot(i.STENCIL_TEST))},setMask:function(ae){dt!==ae&&!D&&(i.stencilMask(ae),dt=ae)},setFunc:function(ae,mn,_i){(G!==ae||J!==mn||gt!==_i)&&(i.stencilFunc(ae,mn,_i),G=ae,J=mn,gt=_i)},setOp:function(ae,mn,_i){(xt!==ae||ne!==mn||ke!==_i)&&(i.stencilOp(ae,mn,_i),xt=ae,ne=mn,ke=_i)},setLocked:function(ae){D=ae},setClear:function(ae){pn!==ae&&(i.clearStencil(ae),pn=ae)},reset:function(){D=!1,dt=null,G=null,J=null,gt=null,xt=null,ne=null,ke=null,pn=null}}}const s=new t,r=new e,a=new n,o=new WeakMap,l=new WeakMap;let c={},h={},u=new WeakMap,d=[],f=null,g=!1,_=null,m=null,p=null,y=null,x=null,S=null,L=null,T=new Zt(0,0,0),E=0,P=!1,U=null,v=null,b=null,I=null,O=null;const $=i.getParameter(i.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let K=!1,z=0;const Z=i.getParameter(i.VERSION);Z.indexOf("WebGL")!==-1?(z=parseFloat(/^WebGL (\d)/.exec(Z)[1]),K=z>=1):Z.indexOf("OpenGL ES")!==-1&&(z=parseFloat(/^OpenGL ES (\d)/.exec(Z)[1]),K=z>=2);let V=null,at={};const ct=i.getParameter(i.SCISSOR_BOX),_t=i.getParameter(i.VIEWPORT),$t=new me().fromArray(ct),Jt=new me().fromArray(_t);function X(D,dt,G,J){const gt=new Uint8Array(4),xt=i.createTexture();i.bindTexture(D,xt),i.texParameteri(D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(D,i.TEXTURE_MAG_FILTER,i.NEAREST);for(let ne=0;ne<G;ne++)D===i.TEXTURE_3D||D===i.TEXTURE_2D_ARRAY?i.texImage3D(dt,0,i.RGBA,1,1,J,0,i.RGBA,i.UNSIGNED_BYTE,gt):i.texImage2D(dt+ne,0,i.RGBA,1,1,0,i.RGBA,i.UNSIGNED_BYTE,gt);return xt}const et={};et[i.TEXTURE_2D]=X(i.TEXTURE_2D,i.TEXTURE_2D,1),et[i.TEXTURE_CUBE_MAP]=X(i.TEXTURE_CUBE_MAP,i.TEXTURE_CUBE_MAP_POSITIVE_X,6),et[i.TEXTURE_2D_ARRAY]=X(i.TEXTURE_2D_ARRAY,i.TEXTURE_2D_ARRAY,1,1),et[i.TEXTURE_3D]=X(i.TEXTURE_3D,i.TEXTURE_3D,1,1),s.setClear(0,0,0,1),r.setClear(1),a.setClear(0),ft(i.DEPTH_TEST),r.setFunc(xr),Ct(!1),Bt(hu),ft(i.CULL_FACE),A(Ye);function ft(D){c[D]!==!0&&(i.enable(D),c[D]=!0)}function ot(D){c[D]!==!1&&(i.disable(D),c[D]=!1)}function At(D,dt){return h[D]!==dt?(i.bindFramebuffer(D,dt),h[D]=dt,D===i.DRAW_FRAMEBUFFER&&(h[i.FRAMEBUFFER]=dt),D===i.FRAMEBUFFER&&(h[i.DRAW_FRAMEBUFFER]=dt),!0):!1}function Tt(D,dt){let G=d,J=!1;if(D){G=u.get(dt),G===void 0&&(G=[],u.set(dt,G));const gt=D.textures;if(G.length!==gt.length||G[0]!==i.COLOR_ATTACHMENT0){for(let xt=0,ne=gt.length;xt<ne;xt++)G[xt]=i.COLOR_ATTACHMENT0+xt;G.length=gt.length,J=!0}}else G[0]!==i.BACK&&(G[0]=i.BACK,J=!0);J&&i.drawBuffers(G)}function zt(D){return f!==D?(i.useProgram(D),f=D,!0):!1}const ie={[jn]:i.FUNC_ADD,[Sm]:i.FUNC_SUBTRACT,[wm]:i.FUNC_REVERSE_SUBTRACT};ie[Em]=i.MIN,ie[Tm]=i.MAX;const W={[$r]:i.ZERO,[Am]:i.ONE,[Cm]:i.SRC_COLOR,[oc]:i.SRC_ALPHA,[Dm]:i.SRC_ALPHA_SATURATE,[hc]:i.DST_COLOR,[cc]:i.DST_ALPHA,[Rm]:i.ONE_MINUS_SRC_COLOR,[lc]:i.ONE_MINUS_SRC_ALPHA,[Lm]:i.ONE_MINUS_DST_COLOR,[Pm]:i.ONE_MINUS_DST_ALPHA,[Im]:i.CONSTANT_COLOR,[km]:i.ONE_MINUS_CONSTANT_COLOR,[Nm]:i.CONSTANT_ALPHA,[Um]:i.ONE_MINUS_CONSTANT_ALPHA};function A(D,dt,G,J,gt,xt,ne,ke,pn,ae){if(D===Ye){g===!0&&(ot(i.BLEND),g=!1);return}if(g===!1&&(ft(i.BLEND),g=!0),D!==mf){if(D!==_||ae!==P){if((m!==jn||x!==jn)&&(i.blendEquation(i.FUNC_ADD),m=jn,x=jn),ae)switch(D){case pr:i.blendFuncSeparate(i.ONE,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA);break;case ac:i.blendFunc(i.ONE,i.ONE);break;case uu:i.blendFuncSeparate(i.ZERO,i.ONE_MINUS_SRC_COLOR,i.ZERO,i.ONE);break;case du:i.blendFuncSeparate(i.ZERO,i.SRC_COLOR,i.ZERO,i.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",D);break}else switch(D){case pr:i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA);break;case ac:i.blendFunc(i.SRC_ALPHA,i.ONE);break;case uu:i.blendFuncSeparate(i.ZERO,i.ONE_MINUS_SRC_COLOR,i.ZERO,i.ONE);break;case du:i.blendFunc(i.ZERO,i.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",D);break}p=null,y=null,S=null,L=null,T.set(0,0,0),E=0,_=D,P=ae}return}gt=gt||dt,xt=xt||G,ne=ne||J,(dt!==m||gt!==x)&&(i.blendEquationSeparate(ie[dt],ie[gt]),m=dt,x=gt),(G!==p||J!==y||xt!==S||ne!==L)&&(i.blendFuncSeparate(W[G],W[J],W[xt],W[ne]),p=G,y=J,S=xt,L=ne),(ke.equals(T)===!1||pn!==E)&&(i.blendColor(ke.r,ke.g,ke.b,pn),T.copy(ke),E=pn),_=D,P=!1}function It(D,dt){D.side===li?ot(i.CULL_FACE):ft(i.CULL_FACE);let G=D.side===un;dt&&(G=!G),Ct(G),D.blending===pr&&D.transparent===!1?A(Ye):A(D.blending,D.blendEquation,D.blendSrc,D.blendDst,D.blendEquationAlpha,D.blendSrcAlpha,D.blendDstAlpha,D.blendColor,D.blendAlpha,D.premultipliedAlpha),r.setFunc(D.depthFunc),r.setTest(D.depthTest),r.setMask(D.depthWrite),s.setMask(D.colorWrite);const J=D.stencilWrite;a.setTest(J),J&&(a.setMask(D.stencilWriteMask),a.setFunc(D.stencilFunc,D.stencilRef,D.stencilFuncMask),a.setOp(D.stencilFail,D.stencilZFail,D.stencilZPass)),ue(D.polygonOffset,D.polygonOffsetFactor,D.polygonOffsetUnits),D.alphaToCoverage===!0?ft(i.SAMPLE_ALPHA_TO_COVERAGE):ot(i.SAMPLE_ALPHA_TO_COVERAGE)}function Ct(D){U!==D&&(D?i.frontFace(i.CW):i.frontFace(i.CCW),U=D)}function Bt(D){D!==Mm?(ft(i.CULL_FACE),D!==v&&(D===hu?i.cullFace(i.BACK):D===bm?i.cullFace(i.FRONT):i.cullFace(i.FRONT_AND_BACK))):ot(i.CULL_FACE),v=D}function Dt(D){D!==b&&(K&&i.lineWidth(D),b=D)}function ue(D,dt,G){D?(ft(i.POLYGON_OFFSET_FILL),(I!==dt||O!==G)&&(i.polygonOffset(dt,G),I=dt,O=G)):ot(i.POLYGON_OFFSET_FILL)}function Nt(D){D?ft(i.SCISSOR_TEST):ot(i.SCISSOR_TEST)}function C(D){D===void 0&&(D=i.TEXTURE0+$-1),V!==D&&(i.activeTexture(D),V=D)}function M(D,dt,G){G===void 0&&(V===null?G=i.TEXTURE0+$-1:G=V);let J=at[G];J===void 0&&(J={type:void 0,texture:void 0},at[G]=J),(J.type!==D||J.texture!==dt)&&(V!==G&&(i.activeTexture(G),V=G),i.bindTexture(D,dt||et[D]),J.type=D,J.texture=dt)}function F(){const D=at[V];D!==void 0&&D.type!==void 0&&(i.bindTexture(D.type,null),D.type=void 0,D.texture=void 0)}function Y(){try{i.compressedTexImage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function Q(){try{i.compressedTexImage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function j(){try{i.texSubImage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function St(){try{i.texSubImage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function ht(){try{i.compressedTexSubImage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function pt(){try{i.compressedTexSubImage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function Yt(){try{i.texStorage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function nt(){try{i.texStorage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function mt(){try{i.texImage2D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function Ut(){try{i.texImage3D.apply(i,arguments)}catch(D){console.error("THREE.WebGLState:",D)}}function Ot(D){$t.equals(D)===!1&&(i.scissor(D.x,D.y,D.z,D.w),$t.copy(D))}function Mt(D){Jt.equals(D)===!1&&(i.viewport(D.x,D.y,D.z,D.w),Jt.copy(D))}function Qt(D,dt){let G=l.get(dt);G===void 0&&(G=new WeakMap,l.set(dt,G));let J=G.get(D);J===void 0&&(J=i.getUniformBlockIndex(dt,D.name),G.set(D,J))}function Vt(D,dt){const J=l.get(dt).get(D);o.get(dt)!==J&&(i.uniformBlockBinding(dt,J,D.__bindingPointIndex),o.set(dt,J))}function se(){i.disable(i.BLEND),i.disable(i.CULL_FACE),i.disable(i.DEPTH_TEST),i.disable(i.POLYGON_OFFSET_FILL),i.disable(i.SCISSOR_TEST),i.disable(i.STENCIL_TEST),i.disable(i.SAMPLE_ALPHA_TO_COVERAGE),i.blendEquation(i.FUNC_ADD),i.blendFunc(i.ONE,i.ZERO),i.blendFuncSeparate(i.ONE,i.ZERO,i.ONE,i.ZERO),i.blendColor(0,0,0,0),i.colorMask(!0,!0,!0,!0),i.clearColor(0,0,0,0),i.depthMask(!0),i.depthFunc(i.LESS),i.clearDepth(1),i.stencilMask(4294967295),i.stencilFunc(i.ALWAYS,0,4294967295),i.stencilOp(i.KEEP,i.KEEP,i.KEEP),i.clearStencil(0),i.cullFace(i.BACK),i.frontFace(i.CCW),i.polygonOffset(0,0),i.activeTexture(i.TEXTURE0),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,null),i.bindFramebuffer(i.READ_FRAMEBUFFER,null),i.useProgram(null),i.lineWidth(1),i.scissor(0,0,i.canvas.width,i.canvas.height),i.viewport(0,0,i.canvas.width,i.canvas.height),c={},V=null,at={},h={},u=new WeakMap,d=[],f=null,g=!1,_=null,m=null,p=null,y=null,x=null,S=null,L=null,T=new Zt(0,0,0),E=0,P=!1,U=null,v=null,b=null,I=null,O=null,$t.set(0,0,i.canvas.width,i.canvas.height),Jt.set(0,0,i.canvas.width,i.canvas.height),s.reset(),r.reset(),a.reset()}return{buffers:{color:s,depth:r,stencil:a},enable:ft,disable:ot,bindFramebuffer:At,drawBuffers:Tt,useProgram:zt,setBlending:A,setMaterial:It,setFlipSided:Ct,setCullFace:Bt,setLineWidth:Dt,setPolygonOffset:ue,setScissorTest:Nt,activeTexture:C,bindTexture:M,unbindTexture:F,compressedTexImage2D:Y,compressedTexImage3D:Q,texImage2D:mt,texImage3D:Ut,updateUBOMapping:Qt,uniformBlockBinding:Vt,texStorage2D:Yt,texStorage3D:nt,texSubImage2D:j,texSubImage3D:St,compressedTexSubImage2D:ht,compressedTexSubImage3D:pt,scissor:Ot,viewport:Mt,reset:se}}function nd(i,t,e,n){const s=fy(n);switch(e){case Tf:return i*t;case Cf:return i*t;case Rf:return i*t*2;case Pf:return i*t/s.components*s.byteLength;case ph:return i*t/s.components*s.byteLength;case Lf:return i*t*2/s.components*s.byteLength;case mh:return i*t*2/s.components*s.byteLength;case Af:return i*t*3/s.components*s.byteLength;case Nn:return i*t*4/s.components*s.byteLength;case gh:return i*t*4/s.components*s.byteLength;case no:case io:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*8;case so:case ro:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*16;case bc:case wc:return Math.max(i,16)*Math.max(t,8)/4;case Mc:case Sc:return Math.max(i,8)*Math.max(t,8)/2;case Ec:case Tc:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*8;case Ac:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*16;case Cc:return Math.floor((i+3)/4)*Math.floor((t+3)/4)*16;case Rc:return Math.floor((i+4)/5)*Math.floor((t+3)/4)*16;case Pc:return Math.floor((i+4)/5)*Math.floor((t+4)/5)*16;case Lc:return Math.floor((i+5)/6)*Math.floor((t+4)/5)*16;case Dc:return Math.floor((i+5)/6)*Math.floor((t+5)/6)*16;case Ic:return Math.floor((i+7)/8)*Math.floor((t+4)/5)*16;case kc:return Math.floor((i+7)/8)*Math.floor((t+5)/6)*16;case Nc:return Math.floor((i+7)/8)*Math.floor((t+7)/8)*16;case Uc:return Math.floor((i+9)/10)*Math.floor((t+4)/5)*16;case Oc:return Math.floor((i+9)/10)*Math.floor((t+5)/6)*16;case Fc:return Math.floor((i+9)/10)*Math.floor((t+7)/8)*16;case zc:return Math.floor((i+9)/10)*Math.floor((t+9)/10)*16;case Bc:return Math.floor((i+11)/12)*Math.floor((t+9)/10)*16;case Hc:return Math.floor((i+11)/12)*Math.floor((t+11)/12)*16;case ao:case Vc:case Gc:return Math.ceil(i/4)*Math.ceil(t/4)*16;case Df:case $c:return Math.ceil(i/4)*Math.ceil(t/4)*8;case Wc:case Xc:return Math.ceil(i/4)*Math.ceil(t/4)*16}throw new Error(`Unable to determine texture byte length for ${e} format.`)}function fy(i){switch(i){case pi:case Sf:return{byteLength:1,components:1};case ra:case wf:case Ui:return{byteLength:2,components:1};case dh:case fh:return{byteLength:2,components:4};case Ts:case uh:case Ci:return{byteLength:4,components:1};case Ef:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${i}.`)}function py(i,t,e,n,s,r,a){const o=t.has("WEBGL_multisampled_render_to_texture")?t.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new rt,h=new WeakMap;let u;const d=new WeakMap;let f=!1;try{f=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(C,M){return f?new OffscreenCanvas(C,M):wo("canvas")}function _(C,M,F){let Y=1;const Q=Nt(C);if((Q.width>F||Q.height>F)&&(Y=F/Math.max(Q.width,Q.height)),Y<1)if(typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&C instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&C instanceof ImageBitmap||typeof VideoFrame<"u"&&C instanceof VideoFrame){const j=Math.floor(Y*Q.width),St=Math.floor(Y*Q.height);u===void 0&&(u=g(j,St));const ht=M?g(j,St):u;return ht.width=j,ht.height=St,ht.getContext("2d").drawImage(C,0,0,j,St),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+Q.width+"x"+Q.height+") to ("+j+"x"+St+")."),ht}else return"data"in C&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+Q.width+"x"+Q.height+")."),C;return C}function m(C){return C.generateMipmaps&&C.minFilter!==rn&&C.minFilter!==qn}function p(C){i.generateMipmap(C)}function y(C,M,F,Y,Q=!1){if(C!==null){if(i[C]!==void 0)return i[C];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+C+"'")}let j=M;if(M===i.RED&&(F===i.FLOAT&&(j=i.R32F),F===i.HALF_FLOAT&&(j=i.R16F),F===i.UNSIGNED_BYTE&&(j=i.R8)),M===i.RED_INTEGER&&(F===i.UNSIGNED_BYTE&&(j=i.R8UI),F===i.UNSIGNED_SHORT&&(j=i.R16UI),F===i.UNSIGNED_INT&&(j=i.R32UI),F===i.BYTE&&(j=i.R8I),F===i.SHORT&&(j=i.R16I),F===i.INT&&(j=i.R32I)),M===i.RG&&(F===i.FLOAT&&(j=i.RG32F),F===i.HALF_FLOAT&&(j=i.RG16F),F===i.UNSIGNED_BYTE&&(j=i.RG8)),M===i.RG_INTEGER&&(F===i.UNSIGNED_BYTE&&(j=i.RG8UI),F===i.UNSIGNED_SHORT&&(j=i.RG16UI),F===i.UNSIGNED_INT&&(j=i.RG32UI),F===i.BYTE&&(j=i.RG8I),F===i.SHORT&&(j=i.RG16I),F===i.INT&&(j=i.RG32I)),M===i.RGB_INTEGER&&(F===i.UNSIGNED_BYTE&&(j=i.RGB8UI),F===i.UNSIGNED_SHORT&&(j=i.RGB16UI),F===i.UNSIGNED_INT&&(j=i.RGB32UI),F===i.BYTE&&(j=i.RGB8I),F===i.SHORT&&(j=i.RGB16I),F===i.INT&&(j=i.RGB32I)),M===i.RGBA_INTEGER&&(F===i.UNSIGNED_BYTE&&(j=i.RGBA8UI),F===i.UNSIGNED_SHORT&&(j=i.RGBA16UI),F===i.UNSIGNED_INT&&(j=i.RGBA32UI),F===i.BYTE&&(j=i.RGBA8I),F===i.SHORT&&(j=i.RGBA16I),F===i.INT&&(j=i.RGBA32I)),M===i.RGB&&F===i.UNSIGNED_INT_5_9_9_9_REV&&(j=i.RGB9_E5),M===i.RGBA){const St=Q?yo:oe.getTransfer(Y);F===i.FLOAT&&(j=i.RGBA32F),F===i.HALF_FLOAT&&(j=i.RGBA16F),F===i.UNSIGNED_BYTE&&(j=St===ye?i.SRGB8_ALPHA8:i.RGBA8),F===i.UNSIGNED_SHORT_4_4_4_4&&(j=i.RGBA4),F===i.UNSIGNED_SHORT_5_5_5_1&&(j=i.RGB5_A1)}return(j===i.R16F||j===i.R32F||j===i.RG16F||j===i.RG32F||j===i.RGBA16F||j===i.RGBA32F)&&t.get("EXT_color_buffer_float"),j}function x(C,M){let F;return C?M===null||M===Ts||M===As?F=i.DEPTH24_STENCIL8:M===Ci?F=i.DEPTH32F_STENCIL8:M===ra&&(F=i.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):M===null||M===Ts||M===As?F=i.DEPTH_COMPONENT24:M===Ci?F=i.DEPTH_COMPONENT32F:M===ra&&(F=i.DEPTH_COMPONENT16),F}function S(C,M){return m(C)===!0||C.isFramebufferTexture&&C.minFilter!==rn&&C.minFilter!==qn?Math.log2(Math.max(M.width,M.height))+1:C.mipmaps!==void 0&&C.mipmaps.length>0?C.mipmaps.length:C.isCompressedTexture&&Array.isArray(C.image)?M.mipmaps.length:1}function L(C){const M=C.target;M.removeEventListener("dispose",L),E(M),M.isVideoTexture&&h.delete(M)}function T(C){const M=C.target;M.removeEventListener("dispose",T),U(M)}function E(C){const M=n.get(C);if(M.__webglInit===void 0)return;const F=C.source,Y=d.get(F);if(Y){const Q=Y[M.__cacheKey];Q.usedTimes--,Q.usedTimes===0&&P(C),Object.keys(Y).length===0&&d.delete(F)}n.remove(C)}function P(C){const M=n.get(C);i.deleteTexture(M.__webglTexture);const F=C.source,Y=d.get(F);delete Y[M.__cacheKey],a.memory.textures--}function U(C){const M=n.get(C);if(C.depthTexture&&C.depthTexture.dispose(),C.isWebGLCubeRenderTarget)for(let Y=0;Y<6;Y++){if(Array.isArray(M.__webglFramebuffer[Y]))for(let Q=0;Q<M.__webglFramebuffer[Y].length;Q++)i.deleteFramebuffer(M.__webglFramebuffer[Y][Q]);else i.deleteFramebuffer(M.__webglFramebuffer[Y]);M.__webglDepthbuffer&&i.deleteRenderbuffer(M.__webglDepthbuffer[Y])}else{if(Array.isArray(M.__webglFramebuffer))for(let Y=0;Y<M.__webglFramebuffer.length;Y++)i.deleteFramebuffer(M.__webglFramebuffer[Y]);else i.deleteFramebuffer(M.__webglFramebuffer);if(M.__webglDepthbuffer&&i.deleteRenderbuffer(M.__webglDepthbuffer),M.__webglMultisampledFramebuffer&&i.deleteFramebuffer(M.__webglMultisampledFramebuffer),M.__webglColorRenderbuffer)for(let Y=0;Y<M.__webglColorRenderbuffer.length;Y++)M.__webglColorRenderbuffer[Y]&&i.deleteRenderbuffer(M.__webglColorRenderbuffer[Y]);M.__webglDepthRenderbuffer&&i.deleteRenderbuffer(M.__webglDepthRenderbuffer)}const F=C.textures;for(let Y=0,Q=F.length;Y<Q;Y++){const j=n.get(F[Y]);j.__webglTexture&&(i.deleteTexture(j.__webglTexture),a.memory.textures--),n.remove(F[Y])}n.remove(C)}let v=0;function b(){v=0}function I(){const C=v;return C>=s.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+C+" texture units while this GPU supports only "+s.maxTextures),v+=1,C}function O(C){const M=[];return M.push(C.wrapS),M.push(C.wrapT),M.push(C.wrapR||0),M.push(C.magFilter),M.push(C.minFilter),M.push(C.anisotropy),M.push(C.internalFormat),M.push(C.format),M.push(C.type),M.push(C.generateMipmaps),M.push(C.premultiplyAlpha),M.push(C.flipY),M.push(C.unpackAlignment),M.push(C.colorSpace),M.join()}function $(C,M){const F=n.get(C);if(C.isVideoTexture&&Dt(C),C.isRenderTargetTexture===!1&&C.version>0&&F.__version!==C.version){const Y=C.image;if(Y===null)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else if(Y.complete===!1)console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");else{Jt(F,C,M);return}}e.bindTexture(i.TEXTURE_2D,F.__webglTexture,i.TEXTURE0+M)}function K(C,M){const F=n.get(C);if(C.version>0&&F.__version!==C.version){Jt(F,C,M);return}e.bindTexture(i.TEXTURE_2D_ARRAY,F.__webglTexture,i.TEXTURE0+M)}function z(C,M){const F=n.get(C);if(C.version>0&&F.__version!==C.version){Jt(F,C,M);return}e.bindTexture(i.TEXTURE_3D,F.__webglTexture,i.TEXTURE0+M)}function Z(C,M){const F=n.get(C);if(C.version>0&&F.__version!==C.version){X(F,C,M);return}e.bindTexture(i.TEXTURE_CUBE_MAP,F.__webglTexture,i.TEXTURE0+M)}const V={[Ni]:i.REPEAT,[Ms]:i.CLAMP_TO_EDGE,[yc]:i.MIRRORED_REPEAT},at={[rn]:i.NEAREST,[Bm]:i.NEAREST_MIPMAP_NEAREST,[pa]:i.NEAREST_MIPMAP_LINEAR,[qn]:i.LINEAR,[el]:i.LINEAR_MIPMAP_NEAREST,[bs]:i.LINEAR_MIPMAP_LINEAR},ct={[$m]:i.NEVER,[Km]:i.ALWAYS,[Wm]:i.LESS,[If]:i.LEQUAL,[Xm]:i.EQUAL,[Ym]:i.GEQUAL,[jm]:i.GREATER,[qm]:i.NOTEQUAL};function _t(C,M){if(M.type===Ci&&t.has("OES_texture_float_linear")===!1&&(M.magFilter===qn||M.magFilter===el||M.magFilter===pa||M.magFilter===bs||M.minFilter===qn||M.minFilter===el||M.minFilter===pa||M.minFilter===bs)&&console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),i.texParameteri(C,i.TEXTURE_WRAP_S,V[M.wrapS]),i.texParameteri(C,i.TEXTURE_WRAP_T,V[M.wrapT]),(C===i.TEXTURE_3D||C===i.TEXTURE_2D_ARRAY)&&i.texParameteri(C,i.TEXTURE_WRAP_R,V[M.wrapR]),i.texParameteri(C,i.TEXTURE_MAG_FILTER,at[M.magFilter]),i.texParameteri(C,i.TEXTURE_MIN_FILTER,at[M.minFilter]),M.compareFunction&&(i.texParameteri(C,i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE),i.texParameteri(C,i.TEXTURE_COMPARE_FUNC,ct[M.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){if(M.magFilter===rn||M.minFilter!==pa&&M.minFilter!==bs||M.type===Ci&&t.has("OES_texture_float_linear")===!1)return;if(M.anisotropy>1||n.get(M).__currentAnisotropy){const F=t.get("EXT_texture_filter_anisotropic");i.texParameterf(C,F.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(M.anisotropy,s.getMaxAnisotropy())),n.get(M).__currentAnisotropy=M.anisotropy}}}function $t(C,M){let F=!1;C.__webglInit===void 0&&(C.__webglInit=!0,M.addEventListener("dispose",L));const Y=M.source;let Q=d.get(Y);Q===void 0&&(Q={},d.set(Y,Q));const j=O(M);if(j!==C.__cacheKey){Q[j]===void 0&&(Q[j]={texture:i.createTexture(),usedTimes:0},a.memory.textures++,F=!0),Q[j].usedTimes++;const St=Q[C.__cacheKey];St!==void 0&&(Q[C.__cacheKey].usedTimes--,St.usedTimes===0&&P(M)),C.__cacheKey=j,C.__webglTexture=Q[j].texture}return F}function Jt(C,M,F){let Y=i.TEXTURE_2D;(M.isDataArrayTexture||M.isCompressedArrayTexture)&&(Y=i.TEXTURE_2D_ARRAY),M.isData3DTexture&&(Y=i.TEXTURE_3D);const Q=$t(C,M),j=M.source;e.bindTexture(Y,C.__webglTexture,i.TEXTURE0+F);const St=n.get(j);if(j.version!==St.__version||Q===!0){e.activeTexture(i.TEXTURE0+F);const ht=oe.getPrimaries(oe.workingColorSpace),pt=M.colorSpace===Ji?null:oe.getPrimaries(M.colorSpace),Yt=M.colorSpace===Ji||ht===pt?i.NONE:i.BROWSER_DEFAULT_WEBGL;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,M.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,M.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,M.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,Yt);let nt=_(M.image,!1,s.maxTextureSize);nt=ue(M,nt);const mt=r.convert(M.format,M.colorSpace),Ut=r.convert(M.type);let Ot=y(M.internalFormat,mt,Ut,M.colorSpace,M.isVideoTexture);_t(Y,M);let Mt;const Qt=M.mipmaps,Vt=M.isVideoTexture!==!0,se=St.__version===void 0||Q===!0,D=j.dataReady,dt=S(M,nt);if(M.isDepthTexture)Ot=x(M.format===Cs,M.type),se&&(Vt?e.texStorage2D(i.TEXTURE_2D,1,Ot,nt.width,nt.height):e.texImage2D(i.TEXTURE_2D,0,Ot,nt.width,nt.height,0,mt,Ut,null));else if(M.isDataTexture)if(Qt.length>0){Vt&&se&&e.texStorage2D(i.TEXTURE_2D,dt,Ot,Qt[0].width,Qt[0].height);for(let G=0,J=Qt.length;G<J;G++)Mt=Qt[G],Vt?D&&e.texSubImage2D(i.TEXTURE_2D,G,0,0,Mt.width,Mt.height,mt,Ut,Mt.data):e.texImage2D(i.TEXTURE_2D,G,Ot,Mt.width,Mt.height,0,mt,Ut,Mt.data);M.generateMipmaps=!1}else Vt?(se&&e.texStorage2D(i.TEXTURE_2D,dt,Ot,nt.width,nt.height),D&&e.texSubImage2D(i.TEXTURE_2D,0,0,0,nt.width,nt.height,mt,Ut,nt.data)):e.texImage2D(i.TEXTURE_2D,0,Ot,nt.width,nt.height,0,mt,Ut,nt.data);else if(M.isCompressedTexture)if(M.isCompressedArrayTexture){Vt&&se&&e.texStorage3D(i.TEXTURE_2D_ARRAY,dt,Ot,Qt[0].width,Qt[0].height,nt.depth);for(let G=0,J=Qt.length;G<J;G++)if(Mt=Qt[G],M.format!==Nn)if(mt!==null)if(Vt){if(D)if(M.layerUpdates.size>0){const gt=nd(Mt.width,Mt.height,M.format,M.type);for(const xt of M.layerUpdates){const ne=Mt.data.subarray(xt*gt/Mt.data.BYTES_PER_ELEMENT,(xt+1)*gt/Mt.data.BYTES_PER_ELEMENT);e.compressedTexSubImage3D(i.TEXTURE_2D_ARRAY,G,0,0,xt,Mt.width,Mt.height,1,mt,ne,0,0)}M.clearLayerUpdates()}else e.compressedTexSubImage3D(i.TEXTURE_2D_ARRAY,G,0,0,0,Mt.width,Mt.height,nt.depth,mt,Mt.data,0,0)}else e.compressedTexImage3D(i.TEXTURE_2D_ARRAY,G,Ot,Mt.width,Mt.height,nt.depth,0,Mt.data,0,0);else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Vt?D&&e.texSubImage3D(i.TEXTURE_2D_ARRAY,G,0,0,0,Mt.width,Mt.height,nt.depth,mt,Ut,Mt.data):e.texImage3D(i.TEXTURE_2D_ARRAY,G,Ot,Mt.width,Mt.height,nt.depth,0,mt,Ut,Mt.data)}else{Vt&&se&&e.texStorage2D(i.TEXTURE_2D,dt,Ot,Qt[0].width,Qt[0].height);for(let G=0,J=Qt.length;G<J;G++)Mt=Qt[G],M.format!==Nn?mt!==null?Vt?D&&e.compressedTexSubImage2D(i.TEXTURE_2D,G,0,0,Mt.width,Mt.height,mt,Mt.data):e.compressedTexImage2D(i.TEXTURE_2D,G,Ot,Mt.width,Mt.height,0,Mt.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):Vt?D&&e.texSubImage2D(i.TEXTURE_2D,G,0,0,Mt.width,Mt.height,mt,Ut,Mt.data):e.texImage2D(i.TEXTURE_2D,G,Ot,Mt.width,Mt.height,0,mt,Ut,Mt.data)}else if(M.isDataArrayTexture)if(Vt){if(se&&e.texStorage3D(i.TEXTURE_2D_ARRAY,dt,Ot,nt.width,nt.height,nt.depth),D)if(M.layerUpdates.size>0){const G=nd(nt.width,nt.height,M.format,M.type);for(const J of M.layerUpdates){const gt=nt.data.subarray(J*G/nt.data.BYTES_PER_ELEMENT,(J+1)*G/nt.data.BYTES_PER_ELEMENT);e.texSubImage3D(i.TEXTURE_2D_ARRAY,0,0,0,J,nt.width,nt.height,1,mt,Ut,gt)}M.clearLayerUpdates()}else e.texSubImage3D(i.TEXTURE_2D_ARRAY,0,0,0,0,nt.width,nt.height,nt.depth,mt,Ut,nt.data)}else e.texImage3D(i.TEXTURE_2D_ARRAY,0,Ot,nt.width,nt.height,nt.depth,0,mt,Ut,nt.data);else if(M.isData3DTexture)Vt?(se&&e.texStorage3D(i.TEXTURE_3D,dt,Ot,nt.width,nt.height,nt.depth),D&&e.texSubImage3D(i.TEXTURE_3D,0,0,0,0,nt.width,nt.height,nt.depth,mt,Ut,nt.data)):e.texImage3D(i.TEXTURE_3D,0,Ot,nt.width,nt.height,nt.depth,0,mt,Ut,nt.data);else if(M.isFramebufferTexture){if(se)if(Vt)e.texStorage2D(i.TEXTURE_2D,dt,Ot,nt.width,nt.height);else{let G=nt.width,J=nt.height;for(let gt=0;gt<dt;gt++)e.texImage2D(i.TEXTURE_2D,gt,Ot,G,J,0,mt,Ut,null),G>>=1,J>>=1}}else if(Qt.length>0){if(Vt&&se){const G=Nt(Qt[0]);e.texStorage2D(i.TEXTURE_2D,dt,Ot,G.width,G.height)}for(let G=0,J=Qt.length;G<J;G++)Mt=Qt[G],Vt?D&&e.texSubImage2D(i.TEXTURE_2D,G,0,0,mt,Ut,Mt):e.texImage2D(i.TEXTURE_2D,G,Ot,mt,Ut,Mt);M.generateMipmaps=!1}else if(Vt){if(se){const G=Nt(nt);e.texStorage2D(i.TEXTURE_2D,dt,Ot,G.width,G.height)}D&&e.texSubImage2D(i.TEXTURE_2D,0,0,0,mt,Ut,nt)}else e.texImage2D(i.TEXTURE_2D,0,Ot,mt,Ut,nt);m(M)&&p(Y),St.__version=j.version,M.onUpdate&&M.onUpdate(M)}C.__version=M.version}function X(C,M,F){if(M.image.length!==6)return;const Y=$t(C,M),Q=M.source;e.bindTexture(i.TEXTURE_CUBE_MAP,C.__webglTexture,i.TEXTURE0+F);const j=n.get(Q);if(Q.version!==j.__version||Y===!0){e.activeTexture(i.TEXTURE0+F);const St=oe.getPrimaries(oe.workingColorSpace),ht=M.colorSpace===Ji?null:oe.getPrimaries(M.colorSpace),pt=M.colorSpace===Ji||St===ht?i.NONE:i.BROWSER_DEFAULT_WEBGL;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,M.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,M.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,M.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,pt);const Yt=M.isCompressedTexture||M.image[0].isCompressedTexture,nt=M.image[0]&&M.image[0].isDataTexture,mt=[];for(let J=0;J<6;J++)!Yt&&!nt?mt[J]=_(M.image[J],!0,s.maxCubemapSize):mt[J]=nt?M.image[J].image:M.image[J],mt[J]=ue(M,mt[J]);const Ut=mt[0],Ot=r.convert(M.format,M.colorSpace),Mt=r.convert(M.type),Qt=y(M.internalFormat,Ot,Mt,M.colorSpace),Vt=M.isVideoTexture!==!0,se=j.__version===void 0||Y===!0,D=Q.dataReady;let dt=S(M,Ut);_t(i.TEXTURE_CUBE_MAP,M);let G;if(Yt){Vt&&se&&e.texStorage2D(i.TEXTURE_CUBE_MAP,dt,Qt,Ut.width,Ut.height);for(let J=0;J<6;J++){G=mt[J].mipmaps;for(let gt=0;gt<G.length;gt++){const xt=G[gt];M.format!==Nn?Ot!==null?Vt?D&&e.compressedTexSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,gt,0,0,xt.width,xt.height,Ot,xt.data):e.compressedTexImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,gt,Qt,xt.width,xt.height,0,xt.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,gt,0,0,xt.width,xt.height,Ot,Mt,xt.data):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,gt,Qt,xt.width,xt.height,0,Ot,Mt,xt.data)}}}else{if(G=M.mipmaps,Vt&&se){G.length>0&&dt++;const J=Nt(mt[0]);e.texStorage2D(i.TEXTURE_CUBE_MAP,dt,Qt,J.width,J.height)}for(let J=0;J<6;J++)if(nt){Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,0,0,0,mt[J].width,mt[J].height,Ot,Mt,mt[J].data):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,0,Qt,mt[J].width,mt[J].height,0,Ot,Mt,mt[J].data);for(let gt=0;gt<G.length;gt++){const ne=G[gt].image[J].image;Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,gt+1,0,0,ne.width,ne.height,Ot,Mt,ne.data):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,gt+1,Qt,ne.width,ne.height,0,Ot,Mt,ne.data)}}else{Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,0,0,0,Ot,Mt,mt[J]):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,0,Qt,Ot,Mt,mt[J]);for(let gt=0;gt<G.length;gt++){const xt=G[gt];Vt?D&&e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,gt+1,0,0,Ot,Mt,xt.image[J]):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+J,gt+1,Qt,Ot,Mt,xt.image[J])}}}m(M)&&p(i.TEXTURE_CUBE_MAP),j.__version=Q.version,M.onUpdate&&M.onUpdate(M)}C.__version=M.version}function et(C,M,F,Y,Q,j){const St=r.convert(F.format,F.colorSpace),ht=r.convert(F.type),pt=y(F.internalFormat,St,ht,F.colorSpace);if(!n.get(M).__hasExternalTextures){const nt=Math.max(1,M.width>>j),mt=Math.max(1,M.height>>j);Q===i.TEXTURE_3D||Q===i.TEXTURE_2D_ARRAY?e.texImage3D(Q,j,pt,nt,mt,M.depth,0,St,ht,null):e.texImage2D(Q,j,pt,nt,mt,0,St,ht,null)}e.bindFramebuffer(i.FRAMEBUFFER,C),Bt(M)?o.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,Y,Q,n.get(F).__webglTexture,0,Ct(M)):(Q===i.TEXTURE_2D||Q>=i.TEXTURE_CUBE_MAP_POSITIVE_X&&Q<=i.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&i.framebufferTexture2D(i.FRAMEBUFFER,Y,Q,n.get(F).__webglTexture,j),e.bindFramebuffer(i.FRAMEBUFFER,null)}function ft(C,M,F){if(i.bindRenderbuffer(i.RENDERBUFFER,C),M.depthBuffer){const Y=M.depthTexture,Q=Y&&Y.isDepthTexture?Y.type:null,j=x(M.stencilBuffer,Q),St=M.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,ht=Ct(M);Bt(M)?o.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,ht,j,M.width,M.height):F?i.renderbufferStorageMultisample(i.RENDERBUFFER,ht,j,M.width,M.height):i.renderbufferStorage(i.RENDERBUFFER,j,M.width,M.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,St,i.RENDERBUFFER,C)}else{const Y=M.textures;for(let Q=0;Q<Y.length;Q++){const j=Y[Q],St=r.convert(j.format,j.colorSpace),ht=r.convert(j.type),pt=y(j.internalFormat,St,ht,j.colorSpace),Yt=Ct(M);F&&Bt(M)===!1?i.renderbufferStorageMultisample(i.RENDERBUFFER,Yt,pt,M.width,M.height):Bt(M)?o.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,Yt,pt,M.width,M.height):i.renderbufferStorage(i.RENDERBUFFER,pt,M.width,M.height)}}i.bindRenderbuffer(i.RENDERBUFFER,null)}function ot(C,M){if(M&&M.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(e.bindFramebuffer(i.FRAMEBUFFER,C),!(M.depthTexture&&M.depthTexture.isDepthTexture))throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");(!n.get(M.depthTexture).__webglTexture||M.depthTexture.image.width!==M.width||M.depthTexture.image.height!==M.height)&&(M.depthTexture.image.width=M.width,M.depthTexture.image.height=M.height,M.depthTexture.needsUpdate=!0),$(M.depthTexture,0);const Y=n.get(M.depthTexture).__webglTexture,Q=Ct(M);if(M.depthTexture.format===mr)Bt(M)?o.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,Y,0,Q):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,Y,0);else if(M.depthTexture.format===Cs)Bt(M)?o.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_2D,Y,0,Q):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_2D,Y,0);else throw new Error("Unknown depthTexture format")}function At(C){const M=n.get(C),F=C.isWebGLCubeRenderTarget===!0;if(M.__boundDepthTexture!==C.depthTexture){const Y=C.depthTexture;if(M.__depthDisposeCallback&&M.__depthDisposeCallback(),Y){const Q=()=>{delete M.__boundDepthTexture,delete M.__depthDisposeCallback,Y.removeEventListener("dispose",Q)};Y.addEventListener("dispose",Q),M.__depthDisposeCallback=Q}M.__boundDepthTexture=Y}if(C.depthTexture&&!M.__autoAllocateDepthBuffer){if(F)throw new Error("target.depthTexture not supported in Cube render targets");ot(M.__webglFramebuffer,C)}else if(F){M.__webglDepthbuffer=[];for(let Y=0;Y<6;Y++)if(e.bindFramebuffer(i.FRAMEBUFFER,M.__webglFramebuffer[Y]),M.__webglDepthbuffer[Y]===void 0)M.__webglDepthbuffer[Y]=i.createRenderbuffer(),ft(M.__webglDepthbuffer[Y],C,!1);else{const Q=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,j=M.__webglDepthbuffer[Y];i.bindRenderbuffer(i.RENDERBUFFER,j),i.framebufferRenderbuffer(i.FRAMEBUFFER,Q,i.RENDERBUFFER,j)}}else if(e.bindFramebuffer(i.FRAMEBUFFER,M.__webglFramebuffer),M.__webglDepthbuffer===void 0)M.__webglDepthbuffer=i.createRenderbuffer(),ft(M.__webglDepthbuffer,C,!1);else{const Y=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,Q=M.__webglDepthbuffer;i.bindRenderbuffer(i.RENDERBUFFER,Q),i.framebufferRenderbuffer(i.FRAMEBUFFER,Y,i.RENDERBUFFER,Q)}e.bindFramebuffer(i.FRAMEBUFFER,null)}function Tt(C,M,F){const Y=n.get(C);M!==void 0&&et(Y.__webglFramebuffer,C,C.texture,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,0),F!==void 0&&At(C)}function zt(C){const M=C.texture,F=n.get(C),Y=n.get(M);C.addEventListener("dispose",T);const Q=C.textures,j=C.isWebGLCubeRenderTarget===!0,St=Q.length>1;if(St||(Y.__webglTexture===void 0&&(Y.__webglTexture=i.createTexture()),Y.__version=M.version,a.memory.textures++),j){F.__webglFramebuffer=[];for(let ht=0;ht<6;ht++)if(M.mipmaps&&M.mipmaps.length>0){F.__webglFramebuffer[ht]=[];for(let pt=0;pt<M.mipmaps.length;pt++)F.__webglFramebuffer[ht][pt]=i.createFramebuffer()}else F.__webglFramebuffer[ht]=i.createFramebuffer()}else{if(M.mipmaps&&M.mipmaps.length>0){F.__webglFramebuffer=[];for(let ht=0;ht<M.mipmaps.length;ht++)F.__webglFramebuffer[ht]=i.createFramebuffer()}else F.__webglFramebuffer=i.createFramebuffer();if(St)for(let ht=0,pt=Q.length;ht<pt;ht++){const Yt=n.get(Q[ht]);Yt.__webglTexture===void 0&&(Yt.__webglTexture=i.createTexture(),a.memory.textures++)}if(C.samples>0&&Bt(C)===!1){F.__webglMultisampledFramebuffer=i.createFramebuffer(),F.__webglColorRenderbuffer=[],e.bindFramebuffer(i.FRAMEBUFFER,F.__webglMultisampledFramebuffer);for(let ht=0;ht<Q.length;ht++){const pt=Q[ht];F.__webglColorRenderbuffer[ht]=i.createRenderbuffer(),i.bindRenderbuffer(i.RENDERBUFFER,F.__webglColorRenderbuffer[ht]);const Yt=r.convert(pt.format,pt.colorSpace),nt=r.convert(pt.type),mt=y(pt.internalFormat,Yt,nt,pt.colorSpace,C.isXRRenderTarget===!0),Ut=Ct(C);i.renderbufferStorageMultisample(i.RENDERBUFFER,Ut,mt,C.width,C.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+ht,i.RENDERBUFFER,F.__webglColorRenderbuffer[ht])}i.bindRenderbuffer(i.RENDERBUFFER,null),C.depthBuffer&&(F.__webglDepthRenderbuffer=i.createRenderbuffer(),ft(F.__webglDepthRenderbuffer,C,!0)),e.bindFramebuffer(i.FRAMEBUFFER,null)}}if(j){e.bindTexture(i.TEXTURE_CUBE_MAP,Y.__webglTexture),_t(i.TEXTURE_CUBE_MAP,M);for(let ht=0;ht<6;ht++)if(M.mipmaps&&M.mipmaps.length>0)for(let pt=0;pt<M.mipmaps.length;pt++)et(F.__webglFramebuffer[ht][pt],C,M,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+ht,pt);else et(F.__webglFramebuffer[ht],C,M,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+ht,0);m(M)&&p(i.TEXTURE_CUBE_MAP),e.unbindTexture()}else if(St){for(let ht=0,pt=Q.length;ht<pt;ht++){const Yt=Q[ht],nt=n.get(Yt);e.bindTexture(i.TEXTURE_2D,nt.__webglTexture),_t(i.TEXTURE_2D,Yt),et(F.__webglFramebuffer,C,Yt,i.COLOR_ATTACHMENT0+ht,i.TEXTURE_2D,0),m(Yt)&&p(i.TEXTURE_2D)}e.unbindTexture()}else{let ht=i.TEXTURE_2D;if((C.isWebGL3DRenderTarget||C.isWebGLArrayRenderTarget)&&(ht=C.isWebGL3DRenderTarget?i.TEXTURE_3D:i.TEXTURE_2D_ARRAY),e.bindTexture(ht,Y.__webglTexture),_t(ht,M),M.mipmaps&&M.mipmaps.length>0)for(let pt=0;pt<M.mipmaps.length;pt++)et(F.__webglFramebuffer[pt],C,M,i.COLOR_ATTACHMENT0,ht,pt);else et(F.__webglFramebuffer,C,M,i.COLOR_ATTACHMENT0,ht,0);m(M)&&p(ht),e.unbindTexture()}C.depthBuffer&&At(C)}function ie(C){const M=C.textures;for(let F=0,Y=M.length;F<Y;F++){const Q=M[F];if(m(Q)){const j=C.isWebGLCubeRenderTarget?i.TEXTURE_CUBE_MAP:i.TEXTURE_2D,St=n.get(Q).__webglTexture;e.bindTexture(j,St),p(j),e.unbindTexture()}}}const W=[],A=[];function It(C){if(C.samples>0){if(Bt(C)===!1){const M=C.textures,F=C.width,Y=C.height;let Q=i.COLOR_BUFFER_BIT;const j=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,St=n.get(C),ht=M.length>1;if(ht)for(let pt=0;pt<M.length;pt++)e.bindFramebuffer(i.FRAMEBUFFER,St.__webglMultisampledFramebuffer),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+pt,i.RENDERBUFFER,null),e.bindFramebuffer(i.FRAMEBUFFER,St.__webglFramebuffer),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0+pt,i.TEXTURE_2D,null,0);e.bindFramebuffer(i.READ_FRAMEBUFFER,St.__webglMultisampledFramebuffer),e.bindFramebuffer(i.DRAW_FRAMEBUFFER,St.__webglFramebuffer);for(let pt=0;pt<M.length;pt++){if(C.resolveDepthBuffer&&(C.depthBuffer&&(Q|=i.DEPTH_BUFFER_BIT),C.stencilBuffer&&C.resolveStencilBuffer&&(Q|=i.STENCIL_BUFFER_BIT)),ht){i.framebufferRenderbuffer(i.READ_FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,St.__webglColorRenderbuffer[pt]);const Yt=n.get(M[pt]).__webglTexture;i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,Yt,0)}i.blitFramebuffer(0,0,F,Y,0,0,F,Y,Q,i.NEAREST),l===!0&&(W.length=0,A.length=0,W.push(i.COLOR_ATTACHMENT0+pt),C.depthBuffer&&C.resolveDepthBuffer===!1&&(W.push(j),A.push(j),i.invalidateFramebuffer(i.DRAW_FRAMEBUFFER,A)),i.invalidateFramebuffer(i.READ_FRAMEBUFFER,W))}if(e.bindFramebuffer(i.READ_FRAMEBUFFER,null),e.bindFramebuffer(i.DRAW_FRAMEBUFFER,null),ht)for(let pt=0;pt<M.length;pt++){e.bindFramebuffer(i.FRAMEBUFFER,St.__webglMultisampledFramebuffer),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+pt,i.RENDERBUFFER,St.__webglColorRenderbuffer[pt]);const Yt=n.get(M[pt]).__webglTexture;e.bindFramebuffer(i.FRAMEBUFFER,St.__webglFramebuffer),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0+pt,i.TEXTURE_2D,Yt,0)}e.bindFramebuffer(i.DRAW_FRAMEBUFFER,St.__webglMultisampledFramebuffer)}else if(C.depthBuffer&&C.resolveDepthBuffer===!1&&l){const M=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT;i.invalidateFramebuffer(i.DRAW_FRAMEBUFFER,[M])}}}function Ct(C){return Math.min(s.maxSamples,C.samples)}function Bt(C){const M=n.get(C);return C.samples>0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&M.__useRenderToTexture!==!1}function Dt(C){const M=a.render.frame;h.get(C)!==M&&(h.set(C,M),C.update())}function ue(C,M){const F=C.colorSpace,Y=C.format,Q=C.type;return C.isCompressedTexture===!0||C.isVideoTexture===!0||F!==cs&&F!==Ji&&(oe.getTransfer(F)===ye?(Y!==Nn||Q!==pi)&&console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",F)),M}function Nt(C){return typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement?(c.width=C.naturalWidth||C.width,c.height=C.naturalHeight||C.height):typeof VideoFrame<"u"&&C instanceof VideoFrame?(c.width=C.displayWidth,c.height=C.displayHeight):(c.width=C.width,c.height=C.height),c}this.allocateTextureUnit=I,this.resetTextureUnits=b,this.setTexture2D=$,this.setTexture2DArray=K,this.setTexture3D=z,this.setTextureCube=Z,this.rebindTextures=Tt,this.setupRenderTarget=zt,this.updateRenderTargetMipmap=ie,this.updateMultisampleRenderTarget=It,this.setupDepthRenderbuffer=At,this.setupFrameBufferTexture=et,this.useMultisampledRTT=Bt}function my(i,t){function e(n,s=Ji){let r;const a=oe.getTransfer(s);if(n===pi)return i.UNSIGNED_BYTE;if(n===dh)return i.UNSIGNED_SHORT_4_4_4_4;if(n===fh)return i.UNSIGNED_SHORT_5_5_5_1;if(n===Ef)return i.UNSIGNED_INT_5_9_9_9_REV;if(n===Sf)return i.BYTE;if(n===wf)return i.SHORT;if(n===ra)return i.UNSIGNED_SHORT;if(n===uh)return i.INT;if(n===Ts)return i.UNSIGNED_INT;if(n===Ci)return i.FLOAT;if(n===Ui)return i.HALF_FLOAT;if(n===Tf)return i.ALPHA;if(n===Af)return i.RGB;if(n===Nn)return i.RGBA;if(n===Cf)return i.LUMINANCE;if(n===Rf)return i.LUMINANCE_ALPHA;if(n===mr)return i.DEPTH_COMPONENT;if(n===Cs)return i.DEPTH_STENCIL;if(n===Pf)return i.RED;if(n===ph)return i.RED_INTEGER;if(n===Lf)return i.RG;if(n===mh)return i.RG_INTEGER;if(n===gh)return i.RGBA_INTEGER;if(n===no||n===io||n===so||n===ro)if(a===ye)if(r=t.get("WEBGL_compressed_texture_s3tc_srgb"),r!==null){if(n===no)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===io)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===so)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===ro)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(r=t.get("WEBGL_compressed_texture_s3tc"),r!==null){if(n===no)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===io)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===so)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===ro)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===Mc||n===bc||n===Sc||n===wc)if(r=t.get("WEBGL_compressed_texture_pvrtc"),r!==null){if(n===Mc)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===bc)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===Sc)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===wc)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===Ec||n===Tc||n===Ac)if(r=t.get("WEBGL_compressed_texture_etc"),r!==null){if(n===Ec||n===Tc)return a===ye?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(n===Ac)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(n===Cc||n===Rc||n===Pc||n===Lc||n===Dc||n===Ic||n===kc||n===Nc||n===Uc||n===Oc||n===Fc||n===zc||n===Bc||n===Hc)if(r=t.get("WEBGL_compressed_texture_astc"),r!==null){if(n===Cc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===Rc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===Pc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===Lc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===Dc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===Ic)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===kc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===Nc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===Uc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===Oc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===Fc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===zc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===Bc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===Hc)return a===ye?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===ao||n===Vc||n===Gc)if(r=t.get("EXT_texture_compression_bptc"),r!==null){if(n===ao)return a===ye?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===Vc)return r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===Gc)return r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===Df||n===$c||n===Wc||n===Xc)if(r=t.get("EXT_texture_compression_rgtc"),r!==null){if(n===ao)return r.COMPRESSED_RED_RGTC1_EXT;if(n===$c)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===Wc)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===Xc)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===As?i.UNSIGNED_INT_24_8:i[n]!==void 0?i[n]:null}return{convert:e}}class gy extends Cn{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class qt extends Qe{constructor(){super(),this.isGroup=!0,this.type="Group"}}const vy={type:"move"};class Rl{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new qt,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new qt,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new R,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new R),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new qt,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new R,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new R),this._grip}dispatchEvent(t){return this._targetRay!==null&&this._targetRay.dispatchEvent(t),this._grip!==null&&this._grip.dispatchEvent(t),this._hand!==null&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){const e=this._hand;if(e)for(const n of t.hand.values())this._getHandJoint(e,n)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(t,e,n){let s=null,r=null,a=null;const o=this._targetRay,l=this._grip,c=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(c&&t.hand){a=!0;for(const _ of t.hand.values()){const m=e.getJointPose(_,n),p=this._getHandJoint(c,_);m!==null&&(p.matrix.fromArray(m.transform.matrix),p.matrix.decompose(p.position,p.rotation,p.scale),p.matrixWorldNeedsUpdate=!0,p.jointRadius=m.radius),p.visible=m!==null}const h=c.joints["index-finger-tip"],u=c.joints["thumb-tip"],d=h.position.distanceTo(u.position),f=.02,g=.005;c.inputState.pinching&&d>f+g?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!c.inputState.pinching&&d<=f-g&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else l!==null&&t.gripSpace&&(r=e.getPose(t.gripSpace,n),r!==null&&(l.matrix.fromArray(r.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,r.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(r.linearVelocity)):l.hasLinearVelocity=!1,r.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(r.angularVelocity)):l.hasAngularVelocity=!1));o!==null&&(s=e.getPose(t.targetRaySpace,n),s===null&&r!==null&&(s=r),s!==null&&(o.matrix.fromArray(s.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,s.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(s.linearVelocity)):o.hasLinearVelocity=!1,s.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(s.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(vy)))}return o!==null&&(o.visible=s!==null),l!==null&&(l.visible=r!==null),c!==null&&(c.visible=a!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){const n=new qt;n.matrixAutoUpdate=!1,n.visible=!1,t.joints[e.jointName]=n,t.add(n)}return t.joints[e.jointName]}}const _y=`
3817
3817
  void main() {
3818
3818
 
3819
3819
  gl_Position = vec4( position, 1.0 );
3820
3820
 
3821
- }`,Wx=`
3821
+ }`,xy=`
3822
3822
  uniform sampler2DArray depthColor;
3823
3823
  uniform float depthWidth;
3824
3824
  uniform float depthHeight;
@@ -3837,7 +3837,7 @@ void main() {
3837
3837
 
3838
3838
  }
3839
3839
 
3840
- }`;class Xx{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e,n){if(this.texture===null){const s=new en,r=t.properties.get(s);r.__webglTexture=e.texture,(e.depthNear!=n.depthNear||e.depthFar!=n.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=s}}getMesh(t){if(this.texture!==null&&this.mesh===null){const e=t.cameras[0].viewport,n=new Je({vertexShader:$x,fragmentShader:Wx,uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new yt(new di(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class jx extends bs{constructor(t,e){super();const n=this;let s=null,r=1,a=null,o="local-floor",l=1,c=null,h=null,u=null,d=null,f=null,g=null;const _=new Xx,m=e.getContextAttributes();let p=null,y=null;const x=[],S=[],L=new rt;let T=null;const E=new wn;E.layers.enable(1),E.viewport=new me;const P=new wn;P.layers.enable(2),P.viewport=new me;const U=[E,P],v=new Vx;v.layers.enable(1),v.layers.enable(2);let b=null,I=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(X){let et=x[X];return et===void 0&&(et=new vl,x[X]=et),et.getTargetRaySpace()},this.getControllerGrip=function(X){let et=x[X];return et===void 0&&(et=new vl,x[X]=et),et.getGripSpace()},this.getHand=function(X){let et=x[X];return et===void 0&&(et=new vl,x[X]=et),et.getHandSpace()};function O(X){const et=S.indexOf(X.inputSource);if(et===-1)return;const ft=x[et];ft!==void 0&&(ft.update(X.inputSource,X.frame,c||a),ft.dispatchEvent({type:X.type,data:X.inputSource}))}function $(){s.removeEventListener("select",O),s.removeEventListener("selectstart",O),s.removeEventListener("selectend",O),s.removeEventListener("squeeze",O),s.removeEventListener("squeezestart",O),s.removeEventListener("squeezeend",O),s.removeEventListener("end",$),s.removeEventListener("inputsourceschange",Y);for(let X=0;X<x.length;X++){const et=S[X];et!==null&&(S[X]=null,x[X].disconnect(et))}b=null,I=null,_.reset(),t.setRenderTarget(p),f=null,d=null,u=null,s=null,y=null,Jt.stop(),n.isPresenting=!1,t.setPixelRatio(T),t.setSize(L.width,L.height,!1),n.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(X){r=X,n.isPresenting===!0&&console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(X){o=X,n.isPresenting===!0&&console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return c||a},this.setReferenceSpace=function(X){c=X},this.getBaseLayer=function(){return d!==null?d:f},this.getBinding=function(){return u},this.getFrame=function(){return g},this.getSession=function(){return s},this.setSession=async function(X){if(s=X,s!==null){if(p=t.getRenderTarget(),s.addEventListener("select",O),s.addEventListener("selectstart",O),s.addEventListener("selectend",O),s.addEventListener("squeeze",O),s.addEventListener("squeezestart",O),s.addEventListener("squeezeend",O),s.addEventListener("end",$),s.addEventListener("inputsourceschange",Y),m.xrCompatible!==!0&&await e.makeXRCompatible(),T=t.getPixelRatio(),t.getSize(L),s.renderState.layers===void 0){const et={antialias:m.antialias,alpha:!0,depth:m.depth,stencil:m.stencil,framebufferScaleFactor:r};f=new XRWebGLLayer(s,e,et),s.updateRenderState({baseLayer:f}),t.setPixelRatio(1),t.setSize(f.framebufferWidth,f.framebufferHeight,!1),y=new Yn(f.framebufferWidth,f.framebufferHeight,{format:Dn,type:hi,colorSpace:t.outputColorSpace,stencilBuffer:m.stencil})}else{let et=null,ft=null,ot=null;m.depth&&(ot=m.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,et=m.stencil?ys:rr,ft=m.stencil?xs:_s);const At={colorFormat:e.RGBA8,depthFormat:ot,scaleFactor:r};u=new XRWebGLBinding(s,e),d=u.createProjectionLayer(At),s.updateRenderState({layers:[d]}),t.setPixelRatio(1),t.setSize(d.textureWidth,d.textureHeight,!1),y=new Yn(d.textureWidth,d.textureHeight,{format:Dn,type:hi,depthTexture:new hh(d.textureWidth,d.textureHeight,ft,void 0,void 0,void 0,void 0,void 0,void 0,et),stencilBuffer:m.stencil,colorSpace:t.outputColorSpace,samples:m.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1})}y.isXRRenderTarget=!0,this.setFoveation(l),c=null,a=await s.requestReferenceSpace(o),Jt.setContext(s),Jt.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(s!==null)return s.environmentBlendMode},this.getDepthTexture=function(){return _.getDepthTexture()};function Y(X){for(let et=0;et<X.removed.length;et++){const ft=X.removed[et],ot=S.indexOf(ft);ot>=0&&(S[ot]=null,x[ot].disconnect(ft))}for(let et=0;et<X.added.length;et++){const ft=X.added[et];let ot=S.indexOf(ft);if(ot===-1){for(let Tt=0;Tt<x.length;Tt++)if(Tt>=S.length){S.push(ft),ot=Tt;break}else if(S[Tt]===null){S[Tt]=ft,ot=Tt;break}if(ot===-1)break}const At=x[ot];At&&At.connect(ft)}}const z=new R,K=new R;function V(X,et,ft){z.setFromMatrixPosition(et.matrixWorld),K.setFromMatrixPosition(ft.matrixWorld);const ot=z.distanceTo(K),At=et.projectionMatrix.elements,Tt=ft.projectionMatrix.elements,Ft=At[14]/(At[10]-1),ie=At[14]/(At[10]+1),W=(At[9]+1)/At[5],A=(At[9]-1)/At[5],It=(At[8]-1)/At[0],Ct=(Tt[8]+1)/Tt[0],zt=Ft*It,Dt=Ft*Ct,ue=ot/(-It+Ct),kt=ue*-It;if(et.matrixWorld.decompose(X.position,X.quaternion,X.scale),X.translateX(kt),X.translateZ(ue),X.matrixWorld.compose(X.position,X.quaternion,X.scale),X.matrixWorldInverse.copy(X.matrixWorld).invert(),At[10]===-1)X.projectionMatrix.copy(et.projectionMatrix),X.projectionMatrixInverse.copy(et.projectionMatrixInverse);else{const C=Ft+ue,M=ie+ue,F=zt-kt,q=Dt+(ot-kt),Q=W*ie/M*C,j=A*ie/M*C;X.projectionMatrix.makePerspective(F,q,Q,j,C,M),X.projectionMatrixInverse.copy(X.projectionMatrix).invert()}}function at(X,et){et===null?X.matrixWorld.copy(X.matrix):X.matrixWorld.multiplyMatrices(et.matrixWorld,X.matrix),X.matrixWorldInverse.copy(X.matrixWorld).invert()}this.updateCamera=function(X){if(s===null)return;let et=X.near,ft=X.far;_.texture!==null&&(_.depthNear>0&&(et=_.depthNear),_.depthFar>0&&(ft=_.depthFar)),v.near=P.near=E.near=et,v.far=P.far=E.far=ft,(b!==v.near||I!==v.far)&&(s.updateRenderState({depthNear:v.near,depthFar:v.far}),b=v.near,I=v.far);const ot=X.parent,At=v.cameras;at(v,ot);for(let Tt=0;Tt<At.length;Tt++)at(At[Tt],ot);At.length===2?V(v,E,P):v.projectionMatrix.copy(E.projectionMatrix),ct(X,v,ot)};function ct(X,et,ft){ft===null?X.matrix.copy(et.matrixWorld):(X.matrix.copy(ft.matrixWorld),X.matrix.invert(),X.matrix.multiply(et.matrixWorld)),X.matrix.decompose(X.position,X.quaternion,X.scale),X.updateMatrixWorld(!0),X.projectionMatrix.copy(et.projectionMatrix),X.projectionMatrixInverse.copy(et.projectionMatrixInverse),X.isPerspectiveCamera&&(X.fov=Zr*2*Math.atan(1/X.projectionMatrix.elements[5]),X.zoom=1)}this.getCamera=function(){return v},this.getFoveation=function(){if(!(d===null&&f===null))return l},this.setFoveation=function(X){l=X,d!==null&&(d.fixedFoveation=X),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=X)},this.hasDepthSensing=function(){return _.texture!==null},this.getDepthSensingMesh=function(){return _.getMesh(v)};let _t=null;function Gt(X,et){if(h=et.getViewerPose(c||a),g=et,h!==null){const ft=h.views;f!==null&&(t.setRenderTargetFramebuffer(y,f.framebuffer),t.setRenderTarget(y));let ot=!1;ft.length!==v.cameras.length&&(v.cameras.length=0,ot=!0);for(let Tt=0;Tt<ft.length;Tt++){const Ft=ft[Tt];let ie=null;if(f!==null)ie=f.getViewport(Ft);else{const A=u.getViewSubImage(d,Ft);ie=A.viewport,Tt===0&&(t.setRenderTargetTextures(y,A.colorTexture,d.ignoreDepthValues?void 0:A.depthStencilTexture),t.setRenderTarget(y))}let W=U[Tt];W===void 0&&(W=new wn,W.layers.enable(Tt),W.viewport=new me,U[Tt]=W),W.matrix.fromArray(Ft.transform.matrix),W.matrix.decompose(W.position,W.quaternion,W.scale),W.projectionMatrix.fromArray(Ft.projectionMatrix),W.projectionMatrixInverse.copy(W.projectionMatrix).invert(),W.viewport.set(ie.x,ie.y,ie.width,ie.height),Tt===0&&(v.matrix.copy(W.matrix),v.matrix.decompose(v.position,v.quaternion,v.scale)),ot===!0&&v.cameras.push(W)}const At=s.enabledFeatures;if(At&&At.includes("depth-sensing")){const Tt=u.getDepthInformation(ft[0]);Tt&&Tt.isValid&&Tt.texture&&_.init(t,Tt,s.renderState)}}for(let ft=0;ft<x.length;ft++){const ot=S[ft],At=x[ft];ot!==null&&At!==void 0&&At.update(ot,et,c||a)}_t&&_t(X,et),et.detectedPlanes&&n.dispatchEvent({type:"planesdetected",data:et}),g=null}const Jt=new xf;Jt.setAnimationLoop(Gt),this.setAnimationLoop=function(X){_t=X},this.dispose=function(){}}}const hs=new ui,qx=new fe;function Yx(i,t){function e(m,p){m.matrixAutoUpdate===!0&&m.updateMatrix(),p.value.copy(m.matrix)}function n(m,p){p.color.getRGB(m.fogColor.value,gf(i)),p.isFog?(m.fogNear.value=p.near,m.fogFar.value=p.far):p.isFogExp2&&(m.fogDensity.value=p.density)}function s(m,p,y,x,S){p.isMeshBasicMaterial||p.isMeshLambertMaterial?r(m,p):p.isMeshToonMaterial?(r(m,p),u(m,p)):p.isMeshPhongMaterial?(r(m,p),h(m,p)):p.isMeshStandardMaterial?(r(m,p),d(m,p),p.isMeshPhysicalMaterial&&f(m,p,S)):p.isMeshMatcapMaterial?(r(m,p),g(m,p)):p.isMeshDepthMaterial?r(m,p):p.isMeshDistanceMaterial?(r(m,p),_(m,p)):p.isMeshNormalMaterial?r(m,p):p.isLineBasicMaterial?(a(m,p),p.isLineDashedMaterial&&o(m,p)):p.isPointsMaterial?l(m,p,y,x):p.isSpriteMaterial?c(m,p):p.isShadowMaterial?(m.color.value.copy(p.color),m.opacity.value=p.opacity):p.isShaderMaterial&&(p.uniformsNeedUpdate=!1)}function r(m,p){m.opacity.value=p.opacity,p.color&&m.diffuse.value.copy(p.color),p.emissive&&m.emissive.value.copy(p.emissive).multiplyScalar(p.emissiveIntensity),p.map&&(m.map.value=p.map,e(p.map,m.mapTransform)),p.alphaMap&&(m.alphaMap.value=p.alphaMap,e(p.alphaMap,m.alphaMapTransform)),p.bumpMap&&(m.bumpMap.value=p.bumpMap,e(p.bumpMap,m.bumpMapTransform),m.bumpScale.value=p.bumpScale,p.side===on&&(m.bumpScale.value*=-1)),p.normalMap&&(m.normalMap.value=p.normalMap,e(p.normalMap,m.normalMapTransform),m.normalScale.value.copy(p.normalScale),p.side===on&&m.normalScale.value.negate()),p.displacementMap&&(m.displacementMap.value=p.displacementMap,e(p.displacementMap,m.displacementMapTransform),m.displacementScale.value=p.displacementScale,m.displacementBias.value=p.displacementBias),p.emissiveMap&&(m.emissiveMap.value=p.emissiveMap,e(p.emissiveMap,m.emissiveMapTransform)),p.specularMap&&(m.specularMap.value=p.specularMap,e(p.specularMap,m.specularMapTransform)),p.alphaTest>0&&(m.alphaTest.value=p.alphaTest);const y=t.get(p),x=y.envMap,S=y.envMapRotation;x&&(m.envMap.value=x,hs.copy(S),hs.x*=-1,hs.y*=-1,hs.z*=-1,x.isCubeTexture&&x.isRenderTargetTexture===!1&&(hs.y*=-1,hs.z*=-1),m.envMapRotation.value.setFromMatrix4(qx.makeRotationFromEuler(hs)),m.flipEnvMap.value=x.isCubeTexture&&x.isRenderTargetTexture===!1?-1:1,m.reflectivity.value=p.reflectivity,m.ior.value=p.ior,m.refractionRatio.value=p.refractionRatio),p.lightMap&&(m.lightMap.value=p.lightMap,m.lightMapIntensity.value=p.lightMapIntensity,e(p.lightMap,m.lightMapTransform)),p.aoMap&&(m.aoMap.value=p.aoMap,m.aoMapIntensity.value=p.aoMapIntensity,e(p.aoMap,m.aoMapTransform))}function a(m,p){m.diffuse.value.copy(p.color),m.opacity.value=p.opacity,p.map&&(m.map.value=p.map,e(p.map,m.mapTransform))}function o(m,p){m.dashSize.value=p.dashSize,m.totalSize.value=p.dashSize+p.gapSize,m.scale.value=p.scale}function l(m,p,y,x){m.diffuse.value.copy(p.color),m.opacity.value=p.opacity,m.size.value=p.size*y,m.scale.value=x*.5,p.map&&(m.map.value=p.map,e(p.map,m.uvTransform)),p.alphaMap&&(m.alphaMap.value=p.alphaMap,e(p.alphaMap,m.alphaMapTransform)),p.alphaTest>0&&(m.alphaTest.value=p.alphaTest)}function c(m,p){m.diffuse.value.copy(p.color),m.opacity.value=p.opacity,m.rotation.value=p.rotation,p.map&&(m.map.value=p.map,e(p.map,m.mapTransform)),p.alphaMap&&(m.alphaMap.value=p.alphaMap,e(p.alphaMap,m.alphaMapTransform)),p.alphaTest>0&&(m.alphaTest.value=p.alphaTest)}function h(m,p){m.specular.value.copy(p.specular),m.shininess.value=Math.max(p.shininess,1e-4)}function u(m,p){p.gradientMap&&(m.gradientMap.value=p.gradientMap)}function d(m,p){m.metalness.value=p.metalness,p.metalnessMap&&(m.metalnessMap.value=p.metalnessMap,e(p.metalnessMap,m.metalnessMapTransform)),m.roughness.value=p.roughness,p.roughnessMap&&(m.roughnessMap.value=p.roughnessMap,e(p.roughnessMap,m.roughnessMapTransform)),p.envMap&&(m.envMapIntensity.value=p.envMapIntensity)}function f(m,p,y){m.ior.value=p.ior,p.sheen>0&&(m.sheenColor.value.copy(p.sheenColor).multiplyScalar(p.sheen),m.sheenRoughness.value=p.sheenRoughness,p.sheenColorMap&&(m.sheenColorMap.value=p.sheenColorMap,e(p.sheenColorMap,m.sheenColorMapTransform)),p.sheenRoughnessMap&&(m.sheenRoughnessMap.value=p.sheenRoughnessMap,e(p.sheenRoughnessMap,m.sheenRoughnessMapTransform))),p.clearcoat>0&&(m.clearcoat.value=p.clearcoat,m.clearcoatRoughness.value=p.clearcoatRoughness,p.clearcoatMap&&(m.clearcoatMap.value=p.clearcoatMap,e(p.clearcoatMap,m.clearcoatMapTransform)),p.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=p.clearcoatRoughnessMap,e(p.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),p.clearcoatNormalMap&&(m.clearcoatNormalMap.value=p.clearcoatNormalMap,e(p.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(p.clearcoatNormalScale),p.side===on&&m.clearcoatNormalScale.value.negate())),p.dispersion>0&&(m.dispersion.value=p.dispersion),p.iridescence>0&&(m.iridescence.value=p.iridescence,m.iridescenceIOR.value=p.iridescenceIOR,m.iridescenceThicknessMinimum.value=p.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=p.iridescenceThicknessRange[1],p.iridescenceMap&&(m.iridescenceMap.value=p.iridescenceMap,e(p.iridescenceMap,m.iridescenceMapTransform)),p.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=p.iridescenceThicknessMap,e(p.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),p.transmission>0&&(m.transmission.value=p.transmission,m.transmissionSamplerMap.value=y.texture,m.transmissionSamplerSize.value.set(y.width,y.height),p.transmissionMap&&(m.transmissionMap.value=p.transmissionMap,e(p.transmissionMap,m.transmissionMapTransform)),m.thickness.value=p.thickness,p.thicknessMap&&(m.thicknessMap.value=p.thicknessMap,e(p.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=p.attenuationDistance,m.attenuationColor.value.copy(p.attenuationColor)),p.anisotropy>0&&(m.anisotropyVector.value.set(p.anisotropy*Math.cos(p.anisotropyRotation),p.anisotropy*Math.sin(p.anisotropyRotation)),p.anisotropyMap&&(m.anisotropyMap.value=p.anisotropyMap,e(p.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=p.specularIntensity,m.specularColor.value.copy(p.specularColor),p.specularColorMap&&(m.specularColorMap.value=p.specularColorMap,e(p.specularColorMap,m.specularColorMapTransform)),p.specularIntensityMap&&(m.specularIntensityMap.value=p.specularIntensityMap,e(p.specularIntensityMap,m.specularIntensityMapTransform))}function g(m,p){p.matcap&&(m.matcap.value=p.matcap)}function _(m,p){const y=t.get(p).light;m.referencePosition.value.setFromMatrixPosition(y.matrixWorld),m.nearDistance.value=y.shadow.camera.near,m.farDistance.value=y.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:s}}function Kx(i,t,e,n){let s={},r={},a=[];const o=i.getParameter(i.MAX_UNIFORM_BUFFER_BINDINGS);function l(y,x){const S=x.program;n.uniformBlockBinding(y,S)}function c(y,x){let S=s[y.id];S===void 0&&(g(y),S=h(y),s[y.id]=S,y.addEventListener("dispose",m));const L=x.program;n.updateUBOMapping(y,L);const T=t.render.frame;r[y.id]!==T&&(d(y),r[y.id]=T)}function h(y){const x=u();y.__bindingPointIndex=x;const S=i.createBuffer(),L=y.__size,T=y.usage;return i.bindBuffer(i.UNIFORM_BUFFER,S),i.bufferData(i.UNIFORM_BUFFER,L,T),i.bindBuffer(i.UNIFORM_BUFFER,null),i.bindBufferBase(i.UNIFORM_BUFFER,x,S),S}function u(){for(let y=0;y<o;y++)if(a.indexOf(y)===-1)return a.push(y),y;return console.error("THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function d(y){const x=s[y.id],S=y.uniforms,L=y.__cache;i.bindBuffer(i.UNIFORM_BUFFER,x);for(let T=0,E=S.length;T<E;T++){const P=Array.isArray(S[T])?S[T]:[S[T]];for(let U=0,v=P.length;U<v;U++){const b=P[U];if(f(b,T,U,L)===!0){const I=b.__offset,O=Array.isArray(b.value)?b.value:[b.value];let $=0;for(let Y=0;Y<O.length;Y++){const z=O[Y],K=_(z);typeof z=="number"||typeof z=="boolean"?(b.__data[0]=z,i.bufferSubData(i.UNIFORM_BUFFER,I+$,b.__data)):z.isMatrix3?(b.__data[0]=z.elements[0],b.__data[1]=z.elements[1],b.__data[2]=z.elements[2],b.__data[3]=0,b.__data[4]=z.elements[3],b.__data[5]=z.elements[4],b.__data[6]=z.elements[5],b.__data[7]=0,b.__data[8]=z.elements[6],b.__data[9]=z.elements[7],b.__data[10]=z.elements[8],b.__data[11]=0):(z.toArray(b.__data,$),$+=K.storage/Float32Array.BYTES_PER_ELEMENT)}i.bufferSubData(i.UNIFORM_BUFFER,I,b.__data)}}}i.bindBuffer(i.UNIFORM_BUFFER,null)}function f(y,x,S,L){const T=y.value,E=x+"_"+S;if(L[E]===void 0)return typeof T=="number"||typeof T=="boolean"?L[E]=T:L[E]=T.clone(),!0;{const P=L[E];if(typeof T=="number"||typeof T=="boolean"){if(P!==T)return L[E]=T,!0}else if(P.equals(T)===!1)return P.copy(T),!0}return!1}function g(y){const x=y.uniforms;let S=0;const L=16;for(let E=0,P=x.length;E<P;E++){const U=Array.isArray(x[E])?x[E]:[x[E]];for(let v=0,b=U.length;v<b;v++){const I=U[v],O=Array.isArray(I.value)?I.value:[I.value];for(let $=0,Y=O.length;$<Y;$++){const z=O[$],K=_(z),V=S%L,at=V%K.boundary,ct=V+at;S+=at,ct!==0&&L-ct<K.storage&&(S+=L-ct),I.__data=new Float32Array(K.storage/Float32Array.BYTES_PER_ELEMENT),I.__offset=S,S+=K.storage}}}const T=S%L;return T>0&&(S+=L-T),y.__size=S,y.__cache={},this}function _(y){const x={boundary:0,storage:0};return typeof y=="number"||typeof y=="boolean"?(x.boundary=4,x.storage=4):y.isVector2?(x.boundary=8,x.storage=8):y.isVector3||y.isColor?(x.boundary=16,x.storage=12):y.isVector4?(x.boundary=16,x.storage=16):y.isMatrix3?(x.boundary=48,x.storage=48):y.isMatrix4?(x.boundary=64,x.storage=64):y.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",y),x}function m(y){const x=y.target;x.removeEventListener("dispose",m);const S=a.indexOf(x.__bindingPointIndex);a.splice(S,1),i.deleteBuffer(s[x.id]),delete s[x.id],delete r[x.id]}function p(){for(const y in s)i.deleteBuffer(s[y]);a=[],s={},r={}}return{bind:l,update:c,dispose:p}}class Zx{constructor(t={}){const{canvas:e=zm(),context:n=null,depth:s=!0,stencil:r=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:u=!1}=t;this.isWebGLRenderer=!0;let d;if(n!==null){if(typeof WebGLRenderingContext<"u"&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");d=n.getContextAttributes().alpha}else d=a;const f=new Uint32Array(4),g=new Int32Array(4);let _=null,m=null;const p=[],y=[];this.domElement=e,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this._outputColorSpace=je,this.toneMapping=Qi,this.toneMappingExposure=1;const x=this;let S=!1,L=0,T=0,E=null,P=-1,U=null;const v=new me,b=new me;let I=null;const O=new Zt(0);let $=0,Y=e.width,z=e.height,K=1,V=null,at=null;const ct=new me(0,0,Y,z),_t=new me(0,0,Y,z);let Gt=!1;const Jt=new oh;let X=!1,et=!1;const ft=new fe,ot=new fe,At=new R,Tt=new me,Ft={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let ie=!1;function W(){return E===null?K:1}let A=n;function It(w,k){return e.getContext(w,k)}try{const w={alpha:!0,depth:s,stencil:r,antialias:o,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:h,failIfMajorPerformanceCaveat:u};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${jc}`),e.addEventListener("webglcontextlost",Z,!1),e.addEventListener("webglcontextrestored",gt,!1),e.addEventListener("webglcontextcreationerror",xt,!1),A===null){const k="webgl2";if(A=It(k,w),A===null)throw It(k)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(w){throw console.error("THREE.WebGLRenderer: "+w.message),w}let Ct,zt,Dt,ue,kt,C,M,F,q,Q,j,St,ht,pt,Yt,nt,mt,Nt,Ut,Mt,Qt,Vt,se,D;function dt(){Ct=new n_(A),Ct.init(),Vt=new Hx(A,Ct),zt=new Kv(A,Ct,t,Vt),Dt=new Fx(A),zt.reverseDepthBuffer&&Dt.buffers.depth.setReversed(!0),ue=new r_(A),kt=new Sx,C=new Bx(A,Ct,Dt,kt,zt,Vt,ue),M=new Jv(x),F=new e_(x),q=new d0(A),se=new qv(A,q),Q=new i_(A,q,ue,se),j=new o_(A,Q,q,ue),Ut=new a_(A,zt,C),nt=new Zv(kt),St=new bx(x,M,F,Ct,zt,se,nt),ht=new Yx(x,kt),pt=new Ex,Yt=new Lx(Ct),Nt=new jv(x,M,F,Dt,j,d,l),mt=new Ux(x,j,zt),D=new Kx(A,ue,zt,Dt),Mt=new Yv(A,Ct,ue),Qt=new s_(A,Ct,ue),ue.programs=St.programs,x.capabilities=zt,x.extensions=Ct,x.properties=kt,x.renderLists=pt,x.shadowMap=mt,x.state=Dt,x.info=ue}dt();const G=new jx(x,A);this.xr=G,this.getContext=function(){return A},this.getContextAttributes=function(){return A.getContextAttributes()},this.forceContextLoss=function(){const w=Ct.get("WEBGL_lose_context");w&&w.loseContext()},this.forceContextRestore=function(){const w=Ct.get("WEBGL_lose_context");w&&w.restoreContext()},this.getPixelRatio=function(){return K},this.setPixelRatio=function(w){w!==void 0&&(K=w,this.setSize(Y,z,!1))},this.getSize=function(w){return w.set(Y,z)},this.setSize=function(w,k,B=!0){if(G.isPresenting){console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");return}Y=w,z=k,e.width=Math.floor(w*K),e.height=Math.floor(k*K),B===!0&&(e.style.width=w+"px",e.style.height=k+"px"),this.setViewport(0,0,w,k)},this.getDrawingBufferSize=function(w){return w.set(Y*K,z*K).floor()},this.setDrawingBufferSize=function(w,k,B){Y=w,z=k,K=B,e.width=Math.floor(w*B),e.height=Math.floor(k*B),this.setViewport(0,0,w,k)},this.getCurrentViewport=function(w){return w.copy(v)},this.getViewport=function(w){return w.copy(ct)},this.setViewport=function(w,k,B,H){w.isVector4?ct.set(w.x,w.y,w.z,w.w):ct.set(w,k,B,H),Dt.viewport(v.copy(ct).multiplyScalar(K).round())},this.getScissor=function(w){return w.copy(_t)},this.setScissor=function(w,k,B,H){w.isVector4?_t.set(w.x,w.y,w.z,w.w):_t.set(w,k,B,H),Dt.scissor(b.copy(_t).multiplyScalar(K).round())},this.getScissorTest=function(){return Gt},this.setScissorTest=function(w){Dt.setScissorTest(Gt=w)},this.setOpaqueSort=function(w){V=w},this.setTransparentSort=function(w){at=w},this.getClearColor=function(w){return w.copy(Nt.getClearColor())},this.setClearColor=function(){Nt.setClearColor.apply(Nt,arguments)},this.getClearAlpha=function(){return Nt.getClearAlpha()},this.setClearAlpha=function(){Nt.setClearAlpha.apply(Nt,arguments)},this.clear=function(w=!0,k=!0,B=!0){let H=0;if(w){let N=!1;if(E!==null){const st=E.texture.format;N=st===th||st===Qc||st===Jc}if(N){const st=E.texture.type,vt=st===hi||st===_s||st===Kr||st===xs||st===Kc||st===Zc,bt=Nt.getClearColor(),Et=Nt.getClearAlpha(),Ot=bt.r,Bt=bt.g,Rt=bt.b;vt?(f[0]=Ot,f[1]=Bt,f[2]=Rt,f[3]=Et,A.clearBufferuiv(A.COLOR,0,f)):(g[0]=Ot,g[1]=Bt,g[2]=Rt,g[3]=Et,A.clearBufferiv(A.COLOR,0,g))}else H|=A.COLOR_BUFFER_BIT}k&&(H|=A.DEPTH_BUFFER_BIT,A.clearDepth(this.capabilities.reverseDepthBuffer?0:1)),B&&(H|=A.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),A.clear(H)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){e.removeEventListener("webglcontextlost",Z,!1),e.removeEventListener("webglcontextrestored",gt,!1),e.removeEventListener("webglcontextcreationerror",xt,!1),pt.dispose(),Yt.dispose(),kt.dispose(),M.dispose(),F.dispose(),j.dispose(),se.dispose(),D.dispose(),St.dispose(),G.dispose(),G.removeEventListener("sessionstart",Dh),G.removeEventListener("sessionend",Ih),ss.stop()};function Z(w){w.preventDefault(),console.log("THREE.WebGLRenderer: Context Lost."),S=!0}function gt(){console.log("THREE.WebGLRenderer: Context Restored."),S=!1;const w=ue.autoReset,k=mt.enabled,B=mt.autoUpdate,H=mt.needsUpdate,N=mt.type;dt(),ue.autoReset=w,mt.enabled=k,mt.autoUpdate=B,mt.needsUpdate=H,mt.type=N}function xt(w){console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ",w.statusMessage)}function ne(w){const k=w.target;k.removeEventListener("dispose",ne),Le(k)}function Le(w){hn(w),kt.remove(w)}function hn(w){const k=kt.get(w).programs;k!==void 0&&(k.forEach(function(B){St.releaseProgram(B)}),w.isShaderMaterial&&St.releaseShaderCache(w))}this.renderBufferDirect=function(w,k,B,H,N,st){k===null&&(k=Ft);const vt=N.isMesh&&N.matrixWorld.determinant()<0,bt=pp(w,k,B,H,N);Dt.setMaterial(H,vt);let Et=B.index,Ot=1;if(H.wireframe===!0){if(Et=Q.getWireframeAttribute(B),Et===void 0)return;Ot=2}const Bt=B.drawRange,Rt=B.attributes.position;let de=Bt.start*Ot,be=(Bt.start+Bt.count)*Ot;st!==null&&(de=Math.max(de,st.start*Ot),be=Math.min(be,(st.start+st.count)*Ot)),Et!==null?(de=Math.max(de,0),be=Math.min(be,Et.count)):Rt!=null&&(de=Math.max(de,0),be=Math.min(be,Rt.count));const Ce=be-de;if(Ce<0||Ce===1/0)return;se.setup(N,H,bt,B,Et);let _n,le=Mt;if(Et!==null&&(_n=q.get(Et),le=Qt,le.setIndex(_n)),N.isMesh)H.wireframe===!0?(Dt.setLineWidth(H.wireframeLinewidth*W()),le.setMode(A.LINES)):le.setMode(A.TRIANGLES);else if(N.isLine){let Lt=H.linewidth;Lt===void 0&&(Lt=1),Dt.setLineWidth(Lt*W()),N.isLineSegments?le.setMode(A.LINES):N.isLineLoop?le.setMode(A.LINE_LOOP):le.setMode(A.LINE_STRIP)}else N.isPoints?le.setMode(A.POINTS):N.isSprite&&le.setMode(A.TRIANGLES);if(N.isBatchedMesh)if(N._multiDrawInstances!==null)le.renderMultiDrawInstances(N._multiDrawStarts,N._multiDrawCounts,N._multiDrawCount,N._multiDrawInstances);else if(Ct.get("WEBGL_multi_draw"))le.renderMultiDraw(N._multiDrawStarts,N._multiDrawCounts,N._multiDrawCount);else{const Lt=N._multiDrawStarts,Ge=N._multiDrawCounts,ce=N._multiDrawCount,Fn=Et?q.get(Et).bytesPerElement:1,Ts=kt.get(H).currentProgram.getUniforms();for(let xn=0;xn<ce;xn++)Ts.setValue(A,"_gl_DrawID",xn),le.render(Lt[xn]/Fn,Ge[xn])}else if(N.isInstancedMesh)le.renderInstances(de,Ce,N.count);else if(B.isInstancedBufferGeometry){const Lt=B._maxInstanceCount!==void 0?B._maxInstanceCount:1/0,Ge=Math.min(B.instanceCount,Lt);le.renderInstances(de,Ce,Ge)}else le.render(de,Ce)};function ae(w,k,B){w.transparent===!0&&w.side===si&&w.forceSinglePass===!1?(w.side=on,w.needsUpdate=!0,sa(w,k,B),w.side=es,w.needsUpdate=!0,sa(w,k,B),w.side=si):sa(w,k,B)}this.compile=function(w,k,B=null){B===null&&(B=w),m=Yt.get(B),m.init(k),y.push(m),B.traverseVisible(function(N){N.isLight&&N.layers.test(k.layers)&&(m.pushLight(N),N.castShadow&&m.pushShadow(N))}),w!==B&&w.traverseVisible(function(N){N.isLight&&N.layers.test(k.layers)&&(m.pushLight(N),N.castShadow&&m.pushShadow(N))}),m.setupLights();const H=new Set;return w.traverse(function(N){if(!(N.isMesh||N.isPoints||N.isLine||N.isSprite))return;const st=N.material;if(st)if(Array.isArray(st))for(let vt=0;vt<st.length;vt++){const bt=st[vt];ae(bt,B,N),H.add(bt)}else ae(st,B,N),H.add(st)}),y.pop(),m=null,H},this.compileAsync=function(w,k,B=null){const H=this.compile(w,k,B);return new Promise(N=>{function st(){if(H.forEach(function(vt){kt.get(vt).currentProgram.isReady()&&H.delete(vt)}),H.size===0){N(w);return}setTimeout(st,10)}Ct.get("KHR_parallel_shader_compile")!==null?st():setTimeout(st,10)})};let un=null;function pi(w){un&&un(w)}function Dh(){ss.stop()}function Ih(){ss.start()}const ss=new xf;ss.setAnimationLoop(pi),typeof self<"u"&&ss.setContext(self),this.setAnimationLoop=function(w){un=w,G.setAnimationLoop(w),w===null?ss.stop():ss.start()},G.addEventListener("sessionstart",Dh),G.addEventListener("sessionend",Ih),this.render=function(w,k){if(k!==void 0&&k.isCamera!==!0){console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(S===!0)return;if(w.matrixWorldAutoUpdate===!0&&w.updateMatrixWorld(),k.parent===null&&k.matrixWorldAutoUpdate===!0&&k.updateMatrixWorld(),G.enabled===!0&&G.isPresenting===!0&&(G.cameraAutoUpdate===!0&&G.updateCamera(k),k=G.getCamera()),w.isScene===!0&&w.onBeforeRender(x,w,k,E),m=Yt.get(w,y.length),m.init(k),y.push(m),ot.multiplyMatrices(k.projectionMatrix,k.matrixWorldInverse),Jt.setFromProjectionMatrix(ot),et=this.localClippingEnabled,X=nt.init(this.clippingPlanes,et),_=pt.get(w,p.length),_.init(),p.push(_),G.enabled===!0&&G.isPresenting===!0){const st=x.xr.getDepthSensingMesh();st!==null&&ko(st,k,-1/0,x.sortObjects)}ko(w,k,0,x.sortObjects),_.finish(),x.sortObjects===!0&&_.sort(V,at),ie=G.enabled===!1||G.isPresenting===!1||G.hasDepthSensing()===!1,ie&&Nt.addToRenderList(_,w),this.info.render.frame++,X===!0&&nt.beginShadows();const B=m.state.shadowsArray;mt.render(B,w,k),X===!0&&nt.endShadows(),this.info.autoReset===!0&&this.info.reset();const H=_.opaque,N=_.transmissive;if(m.setupLights(),k.isArrayCamera){const st=k.cameras;if(N.length>0)for(let vt=0,bt=st.length;vt<bt;vt++){const Et=st[vt];Nh(H,N,w,Et)}ie&&Nt.render(w);for(let vt=0,bt=st.length;vt<bt;vt++){const Et=st[vt];kh(_,w,Et,Et.viewport)}}else N.length>0&&Nh(H,N,w,k),ie&&Nt.render(w),kh(_,w,k);E!==null&&(C.updateMultisampleRenderTarget(E),C.updateRenderTargetMipmap(E)),w.isScene===!0&&w.onAfterRender(x,w,k),se.resetDefaultState(),P=-1,U=null,y.pop(),y.length>0?(m=y[y.length-1],X===!0&&nt.setGlobalState(x.clippingPlanes,m.state.camera)):m=null,p.pop(),p.length>0?_=p[p.length-1]:_=null};function ko(w,k,B,H){if(w.visible===!1)return;if(w.layers.test(k.layers)){if(w.isGroup)B=w.renderOrder;else if(w.isLOD)w.autoUpdate===!0&&w.update(k);else if(w.isLight)m.pushLight(w),w.castShadow&&m.pushShadow(w);else if(w.isSprite){if(!w.frustumCulled||Jt.intersectsSprite(w)){H&&Tt.setFromMatrixPosition(w.matrixWorld).applyMatrix4(ot);const vt=j.update(w),bt=w.material;bt.visible&&_.push(w,vt,bt,B,Tt.z,null)}}else if((w.isMesh||w.isLine||w.isPoints)&&(!w.frustumCulled||Jt.intersectsObject(w))){const vt=j.update(w),bt=w.material;if(H&&(w.boundingSphere!==void 0?(w.boundingSphere===null&&w.computeBoundingSphere(),Tt.copy(w.boundingSphere.center)):(vt.boundingSphere===null&&vt.computeBoundingSphere(),Tt.copy(vt.boundingSphere.center)),Tt.applyMatrix4(w.matrixWorld).applyMatrix4(ot)),Array.isArray(bt)){const Et=vt.groups;for(let Ot=0,Bt=Et.length;Ot<Bt;Ot++){const Rt=Et[Ot],de=bt[Rt.materialIndex];de&&de.visible&&_.push(w,vt,de,B,Tt.z,Rt)}}else bt.visible&&_.push(w,vt,bt,B,Tt.z,null)}}const st=w.children;for(let vt=0,bt=st.length;vt<bt;vt++)ko(st[vt],k,B,H)}function kh(w,k,B,H){const N=w.opaque,st=w.transmissive,vt=w.transparent;m.setupLightsView(B),X===!0&&nt.setGlobalState(x.clippingPlanes,B),H&&Dt.viewport(v.copy(H)),N.length>0&&ia(N,k,B),st.length>0&&ia(st,k,B),vt.length>0&&ia(vt,k,B),Dt.buffers.depth.setTest(!0),Dt.buffers.depth.setMask(!0),Dt.buffers.color.setMask(!0),Dt.setPolygonOffset(!1)}function Nh(w,k,B,H){if((B.isScene===!0?B.overrideMaterial:null)!==null)return;m.state.transmissionRenderTarget[H.id]===void 0&&(m.state.transmissionRenderTarget[H.id]=new Yn(1,1,{generateMipmaps:!0,type:Ct.has("EXT_color_buffer_half_float")||Ct.has("EXT_color_buffer_float")?Li:hi,minFilter:gs,samples:4,stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:oe.workingColorSpace}));const st=m.state.transmissionRenderTarget[H.id],vt=H.viewport||v;st.setSize(vt.z,vt.w);const bt=x.getRenderTarget();x.setRenderTarget(st),x.getClearColor(O),$=x.getClearAlpha(),$<1&&x.setClearColor(16777215,.5),x.clear(),ie&&Nt.render(B);const Et=x.toneMapping;x.toneMapping=Qi;const Ot=H.viewport;if(H.viewport!==void 0&&(H.viewport=void 0),m.setupLightsView(H),X===!0&&nt.setGlobalState(x.clippingPlanes,H),ia(w,B,H),C.updateMultisampleRenderTarget(st),C.updateRenderTargetMipmap(st),Ct.has("WEBGL_multisampled_render_to_texture")===!1){let Bt=!1;for(let Rt=0,de=k.length;Rt<de;Rt++){const be=k[Rt],Ce=be.object,_n=be.geometry,le=be.material,Lt=be.group;if(le.side===si&&Ce.layers.test(H.layers)){const Ge=le.side;le.side=on,le.needsUpdate=!0,Uh(Ce,B,H,_n,le,Lt),le.side=Ge,le.needsUpdate=!0,Bt=!0}}Bt===!0&&(C.updateMultisampleRenderTarget(st),C.updateRenderTargetMipmap(st))}x.setRenderTarget(bt),x.setClearColor(O,$),Ot!==void 0&&(H.viewport=Ot),x.toneMapping=Et}function ia(w,k,B){const H=k.isScene===!0?k.overrideMaterial:null;for(let N=0,st=w.length;N<st;N++){const vt=w[N],bt=vt.object,Et=vt.geometry,Ot=H===null?vt.material:H,Bt=vt.group;bt.layers.test(B.layers)&&Uh(bt,k,B,Et,Ot,Bt)}}function Uh(w,k,B,H,N,st){w.onBeforeRender(x,k,B,H,N,st),w.modelViewMatrix.multiplyMatrices(B.matrixWorldInverse,w.matrixWorld),w.normalMatrix.getNormalMatrix(w.modelViewMatrix),N.onBeforeRender(x,k,B,H,w,st),N.transparent===!0&&N.side===si&&N.forceSinglePass===!1?(N.side=on,N.needsUpdate=!0,x.renderBufferDirect(B,k,H,N,w,st),N.side=es,N.needsUpdate=!0,x.renderBufferDirect(B,k,H,N,w,st),N.side=si):x.renderBufferDirect(B,k,H,N,w,st),w.onAfterRender(x,k,B,H,N,st)}function sa(w,k,B){k.isScene!==!0&&(k=Ft);const H=kt.get(w),N=m.state.lights,st=m.state.shadowsArray,vt=N.state.version,bt=St.getParameters(w,N.state,st,k,B),Et=St.getProgramCacheKey(bt);let Ot=H.programs;H.environment=w.isMeshStandardMaterial?k.environment:null,H.fog=k.fog,H.envMap=(w.isMeshStandardMaterial?F:M).get(w.envMap||H.environment),H.envMapRotation=H.environment!==null&&w.envMap===null?k.environmentRotation:w.envMapRotation,Ot===void 0&&(w.addEventListener("dispose",ne),Ot=new Map,H.programs=Ot);let Bt=Ot.get(Et);if(Bt!==void 0){if(H.currentProgram===Bt&&H.lightsStateVersion===vt)return Fh(w,bt),Bt}else bt.uniforms=St.getUniforms(w),w.onBeforeCompile(bt,x),Bt=St.acquireProgram(bt,Et),Ot.set(Et,Bt),H.uniforms=bt.uniforms;const Rt=H.uniforms;return(!w.isShaderMaterial&&!w.isRawShaderMaterial||w.clipping===!0)&&(Rt.clippingPlanes=nt.uniform),Fh(w,bt),H.needsLights=gp(w),H.lightsStateVersion=vt,H.needsLights&&(Rt.ambientLightColor.value=N.state.ambient,Rt.lightProbe.value=N.state.probe,Rt.directionalLights.value=N.state.directional,Rt.directionalLightShadows.value=N.state.directionalShadow,Rt.spotLights.value=N.state.spot,Rt.spotLightShadows.value=N.state.spotShadow,Rt.rectAreaLights.value=N.state.rectArea,Rt.ltc_1.value=N.state.rectAreaLTC1,Rt.ltc_2.value=N.state.rectAreaLTC2,Rt.pointLights.value=N.state.point,Rt.pointLightShadows.value=N.state.pointShadow,Rt.hemisphereLights.value=N.state.hemi,Rt.directionalShadowMap.value=N.state.directionalShadowMap,Rt.directionalShadowMatrix.value=N.state.directionalShadowMatrix,Rt.spotShadowMap.value=N.state.spotShadowMap,Rt.spotLightMatrix.value=N.state.spotLightMatrix,Rt.spotLightMap.value=N.state.spotLightMap,Rt.pointShadowMap.value=N.state.pointShadowMap,Rt.pointShadowMatrix.value=N.state.pointShadowMatrix),H.currentProgram=Bt,H.uniformsList=null,Bt}function Oh(w){if(w.uniformsList===null){const k=w.currentProgram.getUniforms();w.uniformsList=Ja.seqWithValue(k.seq,w.uniforms)}return w.uniformsList}function Fh(w,k){const B=kt.get(w);B.outputColorSpace=k.outputColorSpace,B.batching=k.batching,B.batchingColor=k.batchingColor,B.instancing=k.instancing,B.instancingColor=k.instancingColor,B.instancingMorph=k.instancingMorph,B.skinning=k.skinning,B.morphTargets=k.morphTargets,B.morphNormals=k.morphNormals,B.morphColors=k.morphColors,B.morphTargetsCount=k.morphTargetsCount,B.numClippingPlanes=k.numClippingPlanes,B.numIntersection=k.numClipIntersection,B.vertexAlphas=k.vertexAlphas,B.vertexTangents=k.vertexTangents,B.toneMapping=k.toneMapping}function pp(w,k,B,H,N){k.isScene!==!0&&(k=Ft),C.resetTextureUnits();const st=k.fog,vt=H.isMeshStandardMaterial?k.environment:null,bt=E===null?x.outputColorSpace:E.isXRRenderTarget===!0?E.texture.colorSpace:is,Et=(H.isMeshStandardMaterial?F:M).get(H.envMap||vt),Ot=H.vertexColors===!0&&!!B.attributes.color&&B.attributes.color.itemSize===4,Bt=!!B.attributes.tangent&&(!!H.normalMap||H.anisotropy>0),Rt=!!B.morphAttributes.position,de=!!B.morphAttributes.normal,be=!!B.morphAttributes.color;let Ce=Qi;H.toneMapped&&(E===null||E.isXRRenderTarget===!0)&&(Ce=x.toneMapping);const _n=B.morphAttributes.position||B.morphAttributes.normal||B.morphAttributes.color,le=_n!==void 0?_n.length:0,Lt=kt.get(H),Ge=m.state.lights;if(X===!0&&(et===!0||w!==U)){const Tn=w===U&&H.id===P;nt.setState(H,w,Tn)}let ce=!1;H.version===Lt.__version?(Lt.needsLights&&Lt.lightsStateVersion!==Ge.state.version||Lt.outputColorSpace!==bt||N.isBatchedMesh&&Lt.batching===!1||!N.isBatchedMesh&&Lt.batching===!0||N.isBatchedMesh&&Lt.batchingColor===!0&&N.colorTexture===null||N.isBatchedMesh&&Lt.batchingColor===!1&&N.colorTexture!==null||N.isInstancedMesh&&Lt.instancing===!1||!N.isInstancedMesh&&Lt.instancing===!0||N.isSkinnedMesh&&Lt.skinning===!1||!N.isSkinnedMesh&&Lt.skinning===!0||N.isInstancedMesh&&Lt.instancingColor===!0&&N.instanceColor===null||N.isInstancedMesh&&Lt.instancingColor===!1&&N.instanceColor!==null||N.isInstancedMesh&&Lt.instancingMorph===!0&&N.morphTexture===null||N.isInstancedMesh&&Lt.instancingMorph===!1&&N.morphTexture!==null||Lt.envMap!==Et||H.fog===!0&&Lt.fog!==st||Lt.numClippingPlanes!==void 0&&(Lt.numClippingPlanes!==nt.numPlanes||Lt.numIntersection!==nt.numIntersection)||Lt.vertexAlphas!==Ot||Lt.vertexTangents!==Bt||Lt.morphTargets!==Rt||Lt.morphNormals!==de||Lt.morphColors!==be||Lt.toneMapping!==Ce||Lt.morphTargetsCount!==le)&&(ce=!0):(ce=!0,Lt.__version=H.version);let Fn=Lt.currentProgram;ce===!0&&(Fn=sa(H,k,N));let Ts=!1,xn=!1,No=!1;const Pe=Fn.getUniforms(),Ni=Lt.uniforms;if(Dt.useProgram(Fn.program)&&(Ts=!0,xn=!0,No=!0),H.id!==P&&(P=H.id,xn=!0),Ts||U!==w){zt.reverseDepthBuffer?(ft.copy(w.projectionMatrix),Hm(ft),Vm(ft),Pe.setValue(A,"projectionMatrix",ft)):Pe.setValue(A,"projectionMatrix",w.projectionMatrix),Pe.setValue(A,"viewMatrix",w.matrixWorldInverse);const Tn=Pe.map.cameraPosition;Tn!==void 0&&Tn.setValue(A,At.setFromMatrixPosition(w.matrixWorld)),zt.logarithmicDepthBuffer&&Pe.setValue(A,"logDepthBufFC",2/(Math.log(w.far+1)/Math.LN2)),(H.isMeshPhongMaterial||H.isMeshToonMaterial||H.isMeshLambertMaterial||H.isMeshBasicMaterial||H.isMeshStandardMaterial||H.isShaderMaterial)&&Pe.setValue(A,"isOrthographic",w.isOrthographicCamera===!0),U!==w&&(U=w,xn=!0,No=!0)}if(N.isSkinnedMesh){Pe.setOptional(A,N,"bindMatrix"),Pe.setOptional(A,N,"bindMatrixInverse");const Tn=N.skeleton;Tn&&(Tn.boneTexture===null&&Tn.computeBoneTexture(),Pe.setValue(A,"boneTexture",Tn.boneTexture,C))}N.isBatchedMesh&&(Pe.setOptional(A,N,"batchingTexture"),Pe.setValue(A,"batchingTexture",N._matricesTexture,C),Pe.setOptional(A,N,"batchingIdTexture"),Pe.setValue(A,"batchingIdTexture",N._indirectTexture,C),Pe.setOptional(A,N,"batchingColorTexture"),N._colorsTexture!==null&&Pe.setValue(A,"batchingColorTexture",N._colorsTexture,C));const Uo=B.morphAttributes;if((Uo.position!==void 0||Uo.normal!==void 0||Uo.color!==void 0)&&Ut.update(N,B,Fn),(xn||Lt.receiveShadow!==N.receiveShadow)&&(Lt.receiveShadow=N.receiveShadow,Pe.setValue(A,"receiveShadow",N.receiveShadow)),H.isMeshGouraudMaterial&&H.envMap!==null&&(Ni.envMap.value=Et,Ni.flipEnvMap.value=Et.isCubeTexture&&Et.isRenderTargetTexture===!1?-1:1),H.isMeshStandardMaterial&&H.envMap===null&&k.environment!==null&&(Ni.envMapIntensity.value=k.environmentIntensity),xn&&(Pe.setValue(A,"toneMappingExposure",x.toneMappingExposure),Lt.needsLights&&mp(Ni,No),st&&H.fog===!0&&ht.refreshFogUniforms(Ni,st),ht.refreshMaterialUniforms(Ni,H,K,z,m.state.transmissionRenderTarget[w.id]),Ja.upload(A,Oh(Lt),Ni,C)),H.isShaderMaterial&&H.uniformsNeedUpdate===!0&&(Ja.upload(A,Oh(Lt),Ni,C),H.uniformsNeedUpdate=!1),H.isSpriteMaterial&&Pe.setValue(A,"center",N.center),Pe.setValue(A,"modelViewMatrix",N.modelViewMatrix),Pe.setValue(A,"normalMatrix",N.normalMatrix),Pe.setValue(A,"modelMatrix",N.matrixWorld),H.isShaderMaterial||H.isRawShaderMaterial){const Tn=H.uniformsGroups;for(let Oo=0,vp=Tn.length;Oo<vp;Oo++){const zh=Tn[Oo];D.update(zh,Fn),D.bind(zh,Fn)}}return Fn}function mp(w,k){w.ambientLightColor.needsUpdate=k,w.lightProbe.needsUpdate=k,w.directionalLights.needsUpdate=k,w.directionalLightShadows.needsUpdate=k,w.pointLights.needsUpdate=k,w.pointLightShadows.needsUpdate=k,w.spotLights.needsUpdate=k,w.spotLightShadows.needsUpdate=k,w.rectAreaLights.needsUpdate=k,w.hemisphereLights.needsUpdate=k}function gp(w){return w.isMeshLambertMaterial||w.isMeshToonMaterial||w.isMeshPhongMaterial||w.isMeshStandardMaterial||w.isShadowMaterial||w.isShaderMaterial&&w.lights===!0}this.getActiveCubeFace=function(){return L},this.getActiveMipmapLevel=function(){return T},this.getRenderTarget=function(){return E},this.setRenderTargetTextures=function(w,k,B){kt.get(w.texture).__webglTexture=k,kt.get(w.depthTexture).__webglTexture=B;const H=kt.get(w);H.__hasExternalTextures=!0,H.__autoAllocateDepthBuffer=B===void 0,H.__autoAllocateDepthBuffer||Ct.has("WEBGL_multisampled_render_to_texture")===!0&&(console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"),H.__useRenderToTexture=!1)},this.setRenderTargetFramebuffer=function(w,k){const B=kt.get(w);B.__webglFramebuffer=k,B.__useDefaultFramebuffer=k===void 0},this.setRenderTarget=function(w,k=0,B=0){E=w,L=k,T=B;let H=!0,N=null,st=!1,vt=!1;if(w){const Et=kt.get(w);if(Et.__useDefaultFramebuffer!==void 0)Dt.bindFramebuffer(A.FRAMEBUFFER,null),H=!1;else if(Et.__webglFramebuffer===void 0)C.setupRenderTarget(w);else if(Et.__hasExternalTextures)C.rebindTextures(w,kt.get(w.texture).__webglTexture,kt.get(w.depthTexture).__webglTexture);else if(w.depthBuffer){const Rt=w.depthTexture;if(Et.__boundDepthTexture!==Rt){if(Rt!==null&&kt.has(Rt)&&(w.width!==Rt.image.width||w.height!==Rt.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");C.setupDepthRenderbuffer(w)}}const Ot=w.texture;(Ot.isData3DTexture||Ot.isDataArrayTexture||Ot.isCompressedArrayTexture)&&(vt=!0);const Bt=kt.get(w).__webglFramebuffer;w.isWebGLCubeRenderTarget?(Array.isArray(Bt[k])?N=Bt[k][B]:N=Bt[k],st=!0):w.samples>0&&C.useMultisampledRTT(w)===!1?N=kt.get(w).__webglMultisampledFramebuffer:Array.isArray(Bt)?N=Bt[B]:N=Bt,v.copy(w.viewport),b.copy(w.scissor),I=w.scissorTest}else v.copy(ct).multiplyScalar(K).floor(),b.copy(_t).multiplyScalar(K).floor(),I=Gt;if(Dt.bindFramebuffer(A.FRAMEBUFFER,N)&&H&&Dt.drawBuffers(w,N),Dt.viewport(v),Dt.scissor(b),Dt.setScissorTest(I),st){const Et=kt.get(w.texture);A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_CUBE_MAP_POSITIVE_X+k,Et.__webglTexture,B)}else if(vt){const Et=kt.get(w.texture),Ot=k||0;A.framebufferTextureLayer(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,Et.__webglTexture,B||0,Ot)}P=-1},this.readRenderTargetPixels=function(w,k,B,H,N,st,vt){if(!(w&&w.isWebGLRenderTarget)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let bt=kt.get(w).__webglFramebuffer;if(w.isWebGLCubeRenderTarget&&vt!==void 0&&(bt=bt[vt]),bt){Dt.bindFramebuffer(A.FRAMEBUFFER,bt);try{const Et=w.texture,Ot=Et.format,Bt=Et.type;if(!zt.textureFormatReadable(Ot)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!zt.textureTypeReadable(Bt)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}k>=0&&k<=w.width-H&&B>=0&&B<=w.height-N&&A.readPixels(k,B,H,N,Vt.convert(Ot),Vt.convert(Bt),st)}finally{const Et=E!==null?kt.get(E).__webglFramebuffer:null;Dt.bindFramebuffer(A.FRAMEBUFFER,Et)}}},this.readRenderTargetPixelsAsync=async function(w,k,B,H,N,st,vt){if(!(w&&w.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let bt=kt.get(w).__webglFramebuffer;if(w.isWebGLCubeRenderTarget&&vt!==void 0&&(bt=bt[vt]),bt){const Et=w.texture,Ot=Et.format,Bt=Et.type;if(!zt.textureFormatReadable(Ot))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!zt.textureTypeReadable(Bt))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");if(k>=0&&k<=w.width-H&&B>=0&&B<=w.height-N){Dt.bindFramebuffer(A.FRAMEBUFFER,bt);const Rt=A.createBuffer();A.bindBuffer(A.PIXEL_PACK_BUFFER,Rt),A.bufferData(A.PIXEL_PACK_BUFFER,st.byteLength,A.STREAM_READ),A.readPixels(k,B,H,N,Vt.convert(Ot),Vt.convert(Bt),0);const de=E!==null?kt.get(E).__webglFramebuffer:null;Dt.bindFramebuffer(A.FRAMEBUFFER,de);const be=A.fenceSync(A.SYNC_GPU_COMMANDS_COMPLETE,0);return A.flush(),await Bm(A,be,4),A.bindBuffer(A.PIXEL_PACK_BUFFER,Rt),A.getBufferSubData(A.PIXEL_PACK_BUFFER,0,st),A.deleteBuffer(Rt),A.deleteSync(be),st}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(w,k=null,B=0){w.isTexture!==!0&&(Za("WebGLRenderer: copyFramebufferToTexture function signature has changed."),k=arguments[0]||null,w=arguments[1]);const H=Math.pow(2,-B),N=Math.floor(w.image.width*H),st=Math.floor(w.image.height*H),vt=k!==null?k.x:0,bt=k!==null?k.y:0;C.setTexture2D(w,0),A.copyTexSubImage2D(A.TEXTURE_2D,B,0,0,vt,bt,N,st),Dt.unbindTexture()},this.copyTextureToTexture=function(w,k,B=null,H=null,N=0){w.isTexture!==!0&&(Za("WebGLRenderer: copyTextureToTexture function signature has changed."),H=arguments[0]||null,w=arguments[1],k=arguments[2],N=arguments[3]||0,B=null);let st,vt,bt,Et,Ot,Bt;B!==null?(st=B.max.x-B.min.x,vt=B.max.y-B.min.y,bt=B.min.x,Et=B.min.y):(st=w.image.width,vt=w.image.height,bt=0,Et=0),H!==null?(Ot=H.x,Bt=H.y):(Ot=0,Bt=0);const Rt=Vt.convert(k.format),de=Vt.convert(k.type);C.setTexture2D(k,0),A.pixelStorei(A.UNPACK_FLIP_Y_WEBGL,k.flipY),A.pixelStorei(A.UNPACK_PREMULTIPLY_ALPHA_WEBGL,k.premultiplyAlpha),A.pixelStorei(A.UNPACK_ALIGNMENT,k.unpackAlignment);const be=A.getParameter(A.UNPACK_ROW_LENGTH),Ce=A.getParameter(A.UNPACK_IMAGE_HEIGHT),_n=A.getParameter(A.UNPACK_SKIP_PIXELS),le=A.getParameter(A.UNPACK_SKIP_ROWS),Lt=A.getParameter(A.UNPACK_SKIP_IMAGES),Ge=w.isCompressedTexture?w.mipmaps[N]:w.image;A.pixelStorei(A.UNPACK_ROW_LENGTH,Ge.width),A.pixelStorei(A.UNPACK_IMAGE_HEIGHT,Ge.height),A.pixelStorei(A.UNPACK_SKIP_PIXELS,bt),A.pixelStorei(A.UNPACK_SKIP_ROWS,Et),w.isDataTexture?A.texSubImage2D(A.TEXTURE_2D,N,Ot,Bt,st,vt,Rt,de,Ge.data):w.isCompressedTexture?A.compressedTexSubImage2D(A.TEXTURE_2D,N,Ot,Bt,Ge.width,Ge.height,Rt,Ge.data):A.texSubImage2D(A.TEXTURE_2D,N,Ot,Bt,st,vt,Rt,de,Ge),A.pixelStorei(A.UNPACK_ROW_LENGTH,be),A.pixelStorei(A.UNPACK_IMAGE_HEIGHT,Ce),A.pixelStorei(A.UNPACK_SKIP_PIXELS,_n),A.pixelStorei(A.UNPACK_SKIP_ROWS,le),A.pixelStorei(A.UNPACK_SKIP_IMAGES,Lt),N===0&&k.generateMipmaps&&A.generateMipmap(A.TEXTURE_2D),Dt.unbindTexture()},this.copyTextureToTexture3D=function(w,k,B=null,H=null,N=0){w.isTexture!==!0&&(Za("WebGLRenderer: copyTextureToTexture3D function signature has changed."),B=arguments[0]||null,H=arguments[1]||null,w=arguments[2],k=arguments[3],N=arguments[4]||0);let st,vt,bt,Et,Ot,Bt,Rt,de,be;const Ce=w.isCompressedTexture?w.mipmaps[N]:w.image;B!==null?(st=B.max.x-B.min.x,vt=B.max.y-B.min.y,bt=B.max.z-B.min.z,Et=B.min.x,Ot=B.min.y,Bt=B.min.z):(st=Ce.width,vt=Ce.height,bt=Ce.depth,Et=0,Ot=0,Bt=0),H!==null?(Rt=H.x,de=H.y,be=H.z):(Rt=0,de=0,be=0);const _n=Vt.convert(k.format),le=Vt.convert(k.type);let Lt;if(k.isData3DTexture)C.setTexture3D(k,0),Lt=A.TEXTURE_3D;else if(k.isDataArrayTexture||k.isCompressedArrayTexture)C.setTexture2DArray(k,0),Lt=A.TEXTURE_2D_ARRAY;else{console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.");return}A.pixelStorei(A.UNPACK_FLIP_Y_WEBGL,k.flipY),A.pixelStorei(A.UNPACK_PREMULTIPLY_ALPHA_WEBGL,k.premultiplyAlpha),A.pixelStorei(A.UNPACK_ALIGNMENT,k.unpackAlignment);const Ge=A.getParameter(A.UNPACK_ROW_LENGTH),ce=A.getParameter(A.UNPACK_IMAGE_HEIGHT),Fn=A.getParameter(A.UNPACK_SKIP_PIXELS),Ts=A.getParameter(A.UNPACK_SKIP_ROWS),xn=A.getParameter(A.UNPACK_SKIP_IMAGES);A.pixelStorei(A.UNPACK_ROW_LENGTH,Ce.width),A.pixelStorei(A.UNPACK_IMAGE_HEIGHT,Ce.height),A.pixelStorei(A.UNPACK_SKIP_PIXELS,Et),A.pixelStorei(A.UNPACK_SKIP_ROWS,Ot),A.pixelStorei(A.UNPACK_SKIP_IMAGES,Bt),w.isDataTexture||w.isData3DTexture?A.texSubImage3D(Lt,N,Rt,de,be,st,vt,bt,_n,le,Ce.data):k.isCompressedArrayTexture?A.compressedTexSubImage3D(Lt,N,Rt,de,be,st,vt,bt,_n,Ce.data):A.texSubImage3D(Lt,N,Rt,de,be,st,vt,bt,_n,le,Ce),A.pixelStorei(A.UNPACK_ROW_LENGTH,Ge),A.pixelStorei(A.UNPACK_IMAGE_HEIGHT,ce),A.pixelStorei(A.UNPACK_SKIP_PIXELS,Fn),A.pixelStorei(A.UNPACK_SKIP_ROWS,Ts),A.pixelStorei(A.UNPACK_SKIP_IMAGES,xn),N===0&&k.generateMipmaps&&A.generateMipmap(Lt),Dt.unbindTexture()},this.initRenderTarget=function(w){kt.get(w).__webglFramebuffer===void 0&&C.setupRenderTarget(w)},this.initTexture=function(w){w.isCubeTexture?C.setTextureCube(w,0):w.isData3DTexture?C.setTexture3D(w,0):w.isDataArrayTexture||w.isCompressedArrayTexture?C.setTexture2DArray(w,0):C.setTexture2D(w,0),Dt.unbindTexture()},this.resetState=function(){L=0,T=0,E=null,Dt.reset(),se.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return Ei}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=t===nh?"display-p3":"srgb",e.unpackColorSpace=oe.workingColorSpace===Ao?"display-p3":"srgb"}}class wf extends Ye{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new ui,this.environmentIntensity=1,this.environmentRotation=new ui,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),t.background!==null&&(this.background=t.background.clone()),t.environment!==null&&(this.environment=t.environment.clone()),t.fog!==null&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),t.overrideMaterial!==null&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return this.fog!==null&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class Ef extends en{constructor(t=null,e=1,n=1,s,r,a,o,l,c=tn,h=tn,u,d){super(null,a,o,l,c,h,s,r,u,d),this.isDataTexture=!0,this.image={data:t,width:e,height:n},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class ki extends en{constructor(t,e,n,s,r,a,o,l,c){super(t,e,n,s,r,a,o,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}}class fi{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const n=this.getUtoTmapping(t);return this.getPoint(n,e)}getPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return e}getSpacedPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPointAt(n/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let n,s=this.getPoint(0),r=0;e.push(0);for(let a=1;a<=t;a++)n=this.getPoint(a/t),r+=n.distanceTo(s),e.push(r),s=n;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const n=this.getLengths();let s=0;const r=n.length;let a;e?a=e:a=t*n[r-1];let o=0,l=r-1,c;for(;o<=l;)if(s=Math.floor(o+(l-o)/2),c=n[s]-a,c<0)o=s+1;else if(c>0)l=s-1;else{l=s;break}if(s=l,n[s]===a)return s/(r-1);const h=n[s],d=n[s+1]-h,f=(a-h)/d;return(s+f)/(r-1)}getTangent(t,e){let s=t-1e-4,r=t+1e-4;s<0&&(s=0),r>1&&(r=1);const a=this.getPoint(s),o=this.getPoint(r),l=e||(a.isVector2?new rt:new R);return l.copy(o).sub(a).normalize(),l}getTangentAt(t,e){const n=this.getUtoTmapping(t);return this.getTangent(n,e)}computeFrenetFrames(t,e){const n=new R,s=[],r=[],a=[],o=new R,l=new fe;for(let f=0;f<=t;f++){const g=f/t;s[f]=this.getTangentAt(g,new R)}r[0]=new R,a[0]=new R;let c=Number.MAX_VALUE;const h=Math.abs(s[0].x),u=Math.abs(s[0].y),d=Math.abs(s[0].z);h<=c&&(c=h,n.set(1,0,0)),u<=c&&(c=u,n.set(0,1,0)),d<=c&&n.set(0,0,1),o.crossVectors(s[0],n).normalize(),r[0].crossVectors(s[0],o),a[0].crossVectors(s[0],r[0]);for(let f=1;f<=t;f++){if(r[f]=r[f-1].clone(),a[f]=a[f-1].clone(),o.crossVectors(s[f-1],s[f]),o.length()>Number.EPSILON){o.normalize();const g=Math.acos(Ue(s[f-1].dot(s[f]),-1,1));r[f].applyMatrix4(l.makeRotationAxis(o,g))}a[f].crossVectors(s[f],r[f])}if(e===!0){let f=Math.acos(Ue(r[0].dot(r[t]),-1,1));f/=t,s[0].dot(o.crossVectors(r[0],r[t]))>0&&(f=-f);for(let g=1;g<=t;g++)r[g].applyMatrix4(l.makeRotationAxis(s[g],f*g)),a[g].crossVectors(s[g],r[g])}return{tangents:s,normals:r,binormals:a}}clone(){return new this.constructor().copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class uh extends fi{constructor(t=0,e=0,n=1,s=1,r=0,a=Math.PI*2,o=!1,l=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=n,this.yRadius=s,this.aStartAngle=r,this.aEndAngle=a,this.aClockwise=o,this.aRotation=l}getPoint(t,e=new rt){const n=e,s=Math.PI*2;let r=this.aEndAngle-this.aStartAngle;const a=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=s;for(;r>s;)r-=s;r<Number.EPSILON&&(a?r=0:r=s),this.aClockwise===!0&&!a&&(r===s?r=-s:r=r-s);const o=this.aStartAngle+t*r;let l=this.aX+this.xRadius*Math.cos(o),c=this.aY+this.yRadius*Math.sin(o);if(this.aRotation!==0){const h=Math.cos(this.aRotation),u=Math.sin(this.aRotation),d=l-this.aX,f=c-this.aY;l=d*h-f*u+this.aX,c=d*u+f*h+this.aY}return n.set(l,c)}copy(t){return super.copy(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}toJSON(){const t=super.toJSON();return t.aX=this.aX,t.aY=this.aY,t.xRadius=this.xRadius,t.yRadius=this.yRadius,t.aStartAngle=this.aStartAngle,t.aEndAngle=this.aEndAngle,t.aClockwise=this.aClockwise,t.aRotation=this.aRotation,t}fromJSON(t){return super.fromJSON(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}}class Jx extends uh{constructor(t,e,n,s,r,a){super(t,e,n,n,s,r,a),this.isArcCurve=!0,this.type="ArcCurve"}}function dh(){let i=0,t=0,e=0,n=0;function s(r,a,o,l){i=r,t=o,e=-3*r+3*a-2*o-l,n=2*r-2*a+o+l}return{initCatmullRom:function(r,a,o,l,c){s(a,o,c*(o-r),c*(l-a))},initNonuniformCatmullRom:function(r,a,o,l,c,h,u){let d=(a-r)/c-(o-r)/(c+h)+(o-a)/h,f=(o-a)/h-(l-a)/(h+u)+(l-o)/u;d*=h,f*=h,s(a,o,d,f)},calc:function(r){const a=r*r,o=a*r;return i+t*r+e*a+n*o}}}const Ta=new R,_l=new dh,xl=new dh,yl=new dh;class Qx extends fi{constructor(t=[],e=!1,n="centripetal",s=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=n,this.tension=s}getPoint(t,e=new R){const n=e,s=this.points,r=s.length,a=(r-(this.closed?0:1))*t;let o=Math.floor(a),l=a-o;this.closed?o+=o>0?0:(Math.floor(Math.abs(o)/r)+1)*r:l===0&&o===r-1&&(o=r-2,l=1);let c,h;this.closed||o>0?c=s[(o-1)%r]:(Ta.subVectors(s[0],s[1]).add(s[0]),c=Ta);const u=s[o%r],d=s[(o+1)%r];if(this.closed||o+2<r?h=s[(o+2)%r]:(Ta.subVectors(s[r-1],s[r-2]).add(s[r-1]),h=Ta),this.curveType==="centripetal"||this.curveType==="chordal"){const f=this.curveType==="chordal"?.5:.25;let g=Math.pow(c.distanceToSquared(u),f),_=Math.pow(u.distanceToSquared(d),f),m=Math.pow(d.distanceToSquared(h),f);_<1e-4&&(_=1),g<1e-4&&(g=_),m<1e-4&&(m=_),_l.initNonuniformCatmullRom(c.x,u.x,d.x,h.x,g,_,m),xl.initNonuniformCatmullRom(c.y,u.y,d.y,h.y,g,_,m),yl.initNonuniformCatmullRom(c.z,u.z,d.z,h.z,g,_,m)}else this.curveType==="catmullrom"&&(_l.initCatmullRom(c.x,u.x,d.x,h.x,this.tension),xl.initCatmullRom(c.y,u.y,d.y,h.y,this.tension),yl.initCatmullRom(c.z,u.z,d.z,h.z,this.tension));return n.set(_l.calc(l),xl.calc(l),yl.calc(l)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const s=t.points[e];this.points.push(s.clone())}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const s=this.points[e];t.points.push(s.toArray())}return t.closed=this.closed,t.curveType=this.curveType,t.tension=this.tension,t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const s=t.points[e];this.points.push(new R().fromArray(s))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function Fu(i,t,e,n,s){const r=(n-t)*.5,a=(s-e)*.5,o=i*i,l=i*o;return(2*e-2*n+r+a)*l+(-3*e+3*n-2*r-a)*o+r*i+e}function ty(i,t){const e=1-i;return e*e*t}function ey(i,t){return 2*(1-i)*i*t}function ny(i,t){return i*i*t}function Hr(i,t,e,n){return ty(i,t)+ey(i,e)+ny(i,n)}function iy(i,t){const e=1-i;return e*e*e*t}function sy(i,t){const e=1-i;return 3*e*e*i*t}function ry(i,t){return 3*(1-i)*i*i*t}function ay(i,t){return i*i*i*t}function Vr(i,t,e,n,s){return iy(i,t)+sy(i,e)+ry(i,n)+ay(i,s)}class Tf extends fi{constructor(t=new rt,e=new rt,n=new rt,s=new rt){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=n,this.v3=s}getPoint(t,e=new rt){const n=e,s=this.v0,r=this.v1,a=this.v2,o=this.v3;return n.set(Vr(t,s.x,r.x,a.x,o.x),Vr(t,s.y,r.y,a.y,o.y)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class oy extends fi{constructor(t=new R,e=new R,n=new R,s=new R){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=n,this.v3=s}getPoint(t,e=new R){const n=e,s=this.v0,r=this.v1,a=this.v2,o=this.v3;return n.set(Vr(t,s.x,r.x,a.x,o.x),Vr(t,s.y,r.y,a.y,o.y),Vr(t,s.z,r.z,a.z,o.z)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class Af extends fi{constructor(t=new rt,e=new rt){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new rt){const n=e;return t===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new rt){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class ly extends fi{constructor(t=new R,e=new R){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new R){const n=e;return t===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new R){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Cf extends fi{constructor(t=new rt,e=new rt,n=new rt){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new rt){const n=e,s=this.v0,r=this.v1,a=this.v2;return n.set(Hr(t,s.x,r.x,a.x),Hr(t,s.y,r.y,a.y)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class cy extends fi{constructor(t=new R,e=new R,n=new R){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new R){const n=e,s=this.v0,r=this.v1,a=this.v2;return n.set(Hr(t,s.x,r.x,a.x),Hr(t,s.y,r.y,a.y),Hr(t,s.z,r.z,a.z)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Rf extends fi{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new rt){const n=e,s=this.points,r=(s.length-1)*t,a=Math.floor(r),o=r-a,l=s[a===0?a:a-1],c=s[a],h=s[a>s.length-2?s.length-1:a+1],u=s[a>s.length-3?s.length-1:a+2];return n.set(Fu(o,l.x,c.x,h.x,u.x),Fu(o,l.y,c.y,h.y,u.y)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const s=t.points[e];this.points.push(s.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const s=this.points[e];t.points.push(s.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const s=t.points[e];this.points.push(new rt().fromArray(s))}return this}}var zu=Object.freeze({__proto__:null,ArcCurve:Jx,CatmullRomCurve3:Qx,CubicBezierCurve:Tf,CubicBezierCurve3:oy,EllipseCurve:uh,LineCurve:Af,LineCurve3:ly,QuadraticBezierCurve:Cf,QuadraticBezierCurve3:cy,SplineCurve:Rf});class hy extends fi{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(t){this.curves.push(t)}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);if(!t.equals(e)){const n=t.isVector2===!0?"LineCurve":"LineCurve3";this.curves.push(new zu[n](e,t))}return this}getPoint(t,e){const n=t*this.getLength(),s=this.getCurveLengths();let r=0;for(;r<s.length;){if(s[r]>=n){const a=s[r]-n,o=this.curves[r],l=o.getLength(),c=l===0?0:1-a/l;return o.getPointAt(c,e)}r++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let n=0,s=this.curves.length;n<s;n++)e+=this.curves[n].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let n;for(let s=0,r=this.curves;s<r.length;s++){const a=r[s],o=a.isEllipseCurve?t*2:a.isLineCurve||a.isLineCurve3?1:a.isSplineCurve?t*a.points.length:t,l=a.getPoints(o);for(let c=0;c<l.length;c++){const h=l[c];n&&n.equals(h)||(e.push(h),n=h)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const s=t.curves[e];this.curves.push(s.clone())}return this.autoClose=t.autoClose,this}toJSON(){const t=super.toJSON();t.autoClose=this.autoClose,t.curves=[];for(let e=0,n=this.curves.length;e<n;e++){const s=this.curves[e];t.curves.push(s.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.autoClose=t.autoClose,this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const s=t.curves[e];this.curves.push(new zu[s.type]().fromJSON(s))}return this}}class uy extends hy{constructor(t){super(),this.type="Path",this.currentPoint=new rt,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,n=t.length;e<n;e++)this.lineTo(t[e].x,t[e].y);return this}moveTo(t,e){return this.currentPoint.set(t,e),this}lineTo(t,e){const n=new Af(this.currentPoint.clone(),new rt(t,e));return this.curves.push(n),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,n,s){const r=new Cf(this.currentPoint.clone(),new rt(t,e),new rt(n,s));return this.curves.push(r),this.currentPoint.set(n,s),this}bezierCurveTo(t,e,n,s,r,a){const o=new Tf(this.currentPoint.clone(),new rt(t,e),new rt(n,s),new rt(r,a));return this.curves.push(o),this.currentPoint.set(r,a),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),n=new Rf(e);return this.curves.push(n),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,n,s,r,a){const o=this.currentPoint.x,l=this.currentPoint.y;return this.absarc(t+o,e+l,n,s,r,a),this}absarc(t,e,n,s,r,a){return this.absellipse(t,e,n,n,s,r,a),this}ellipse(t,e,n,s,r,a,o,l){const c=this.currentPoint.x,h=this.currentPoint.y;return this.absellipse(t+c,e+h,n,s,r,a,o,l),this}absellipse(t,e,n,s,r,a,o,l){const c=new uh(t,e,n,s,r,a,o,l);if(this.curves.length>0){const u=c.getPoint(0);u.equals(this.currentPoint)||this.lineTo(u.x,u.y)}this.curves.push(c);const h=c.getPoint(1);return this.currentPoint.copy(h),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class Ro extends cn{constructor(t=[new rt(0,-.5),new rt(.5,0),new rt(0,.5)],e=12,n=0,s=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:n,phiLength:s},e=Math.floor(e),s=Ue(s,0,Math.PI*2);const r=[],a=[],o=[],l=[],c=[],h=1/e,u=new R,d=new rt,f=new R,g=new R,_=new R;let m=0,p=0;for(let y=0;y<=t.length-1;y++)switch(y){case 0:m=t[y+1].x-t[y].x,p=t[y+1].y-t[y].y,f.x=p*1,f.y=-m,f.z=p*0,_.copy(f),f.normalize(),l.push(f.x,f.y,f.z);break;case t.length-1:l.push(_.x,_.y,_.z);break;default:m=t[y+1].x-t[y].x,p=t[y+1].y-t[y].y,f.x=p*1,f.y=-m,f.z=p*0,g.copy(f),f.x+=_.x,f.y+=_.y,f.z+=_.z,f.normalize(),l.push(f.x,f.y,f.z),_.copy(g)}for(let y=0;y<=e;y++){const x=n+y*h*s,S=Math.sin(x),L=Math.cos(x);for(let T=0;T<=t.length-1;T++){u.x=t[T].x*S,u.y=t[T].y,u.z=t[T].x*L,a.push(u.x,u.y,u.z),d.x=y/e,d.y=T/(t.length-1),o.push(d.x,d.y);const E=l[3*T+0]*S,P=l[3*T+1],U=l[3*T+0]*L;c.push(E,P,U)}}for(let y=0;y<e;y++)for(let x=0;x<t.length-1;x++){const S=x+y*t.length,L=S,T=S+t.length,E=S+t.length+1,P=S+1;r.push(L,T,P),r.push(E,P,T)}this.setIndex(r),this.setAttribute("position",new he(a,3)),this.setAttribute("uv",new he(o,2)),this.setAttribute("normal",new he(c,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ro(t.points,t.segments,t.phiStart,t.phiLength)}}class fh extends Ro{constructor(t=1,e=1,n=4,s=8){const r=new uy;r.absarc(0,-e/2,t,Math.PI*1.5,0),r.absarc(0,e/2,t,0,Math.PI*.5),super(r.getPoints(n),s),this.type="CapsuleGeometry",this.parameters={radius:t,length:e,capSegments:n,radialSegments:s}}static fromJSON(t){return new fh(t.radius,t.length,t.capSegments,t.radialSegments)}}class Di extends cn{constructor(t=1,e=32,n=0,s=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:n,thetaLength:s},e=Math.max(3,e);const r=[],a=[],o=[],l=[],c=new R,h=new rt;a.push(0,0,0),o.push(0,0,1),l.push(.5,.5);for(let u=0,d=3;u<=e;u++,d+=3){const f=n+u/e*s;c.x=t*Math.cos(f),c.y=t*Math.sin(f),a.push(c.x,c.y,c.z),o.push(0,0,1),h.x=(a[d]/t+1)/2,h.y=(a[d+1]/t+1)/2,l.push(h.x,h.y)}for(let u=1;u<=e;u++)r.push(u,u+1,0);this.setIndex(r),this.setAttribute("position",new he(a,3)),this.setAttribute("normal",new he(o,3)),this.setAttribute("uv",new he(l,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Di(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class Un extends cn{constructor(t=1,e=1,n=1,s=32,r=1,a=!1,o=0,l=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:n,radialSegments:s,heightSegments:r,openEnded:a,thetaStart:o,thetaLength:l};const c=this;s=Math.floor(s),r=Math.floor(r);const h=[],u=[],d=[],f=[];let g=0;const _=[],m=n/2;let p=0;y(),a===!1&&(t>0&&x(!0),e>0&&x(!1)),this.setIndex(h),this.setAttribute("position",new he(u,3)),this.setAttribute("normal",new he(d,3)),this.setAttribute("uv",new he(f,2));function y(){const S=new R,L=new R;let T=0;const E=(e-t)/n;for(let P=0;P<=r;P++){const U=[],v=P/r,b=v*(e-t)+t;for(let I=0;I<=s;I++){const O=I/s,$=O*l+o,Y=Math.sin($),z=Math.cos($);L.x=b*Y,L.y=-v*n+m,L.z=b*z,u.push(L.x,L.y,L.z),S.set(Y,E,z).normalize(),d.push(S.x,S.y,S.z),f.push(O,1-v),U.push(g++)}_.push(U)}for(let P=0;P<s;P++)for(let U=0;U<r;U++){const v=_[U][P],b=_[U+1][P],I=_[U+1][P+1],O=_[U][P+1];t>0&&(h.push(v,b,O),T+=3),e>0&&(h.push(b,I,O),T+=3)}c.addGroup(p,T,0),p+=T}function x(S){const L=g,T=new rt,E=new R;let P=0;const U=S===!0?t:e,v=S===!0?1:-1;for(let I=1;I<=s;I++)u.push(0,m*v,0),d.push(0,v,0),f.push(.5,.5),g++;const b=g;for(let I=0;I<=s;I++){const $=I/s*l+o,Y=Math.cos($),z=Math.sin($);E.x=U*z,E.y=m*v,E.z=U*Y,u.push(E.x,E.y,E.z),d.push(0,v,0),T.x=Y*.5+.5,T.y=z*.5*v+.5,f.push(T.x,T.y),g++}for(let I=0;I<s;I++){const O=L+I,$=b+I;S===!0?h.push($,$+1,O):h.push($+1,$,O),P+=3}c.addGroup(p,P,S===!0?1:2),p+=P}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Un(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class ta extends Un{constructor(t=1,e=1,n=32,s=1,r=!1,a=0,o=Math.PI*2){super(0,t,e,n,s,r,a,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:n,heightSegments:s,openEnded:r,thetaStart:a,thetaLength:o}}static fromJSON(t){return new ta(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class ph extends cn{constructor(t=[],e=[],n=1,s=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:n,detail:s};const r=[],a=[];o(s),c(n),h(),this.setAttribute("position",new he(r,3)),this.setAttribute("normal",new he(r.slice(),3)),this.setAttribute("uv",new he(a,2)),s===0?this.computeVertexNormals():this.normalizeNormals();function o(y){const x=new R,S=new R,L=new R;for(let T=0;T<e.length;T+=3)f(e[T+0],x),f(e[T+1],S),f(e[T+2],L),l(x,S,L,y)}function l(y,x,S,L){const T=L+1,E=[];for(let P=0;P<=T;P++){E[P]=[];const U=y.clone().lerp(S,P/T),v=x.clone().lerp(S,P/T),b=T-P;for(let I=0;I<=b;I++)I===0&&P===T?E[P][I]=U:E[P][I]=U.clone().lerp(v,I/b)}for(let P=0;P<T;P++)for(let U=0;U<2*(T-P)-1;U++){const v=Math.floor(U/2);U%2===0?(d(E[P][v+1]),d(E[P+1][v]),d(E[P][v])):(d(E[P][v+1]),d(E[P+1][v+1]),d(E[P+1][v]))}}function c(y){const x=new R;for(let S=0;S<r.length;S+=3)x.x=r[S+0],x.y=r[S+1],x.z=r[S+2],x.normalize().multiplyScalar(y),r[S+0]=x.x,r[S+1]=x.y,r[S+2]=x.z}function h(){const y=new R;for(let x=0;x<r.length;x+=3){y.x=r[x+0],y.y=r[x+1],y.z=r[x+2];const S=m(y)/2/Math.PI+.5,L=p(y)/Math.PI+.5;a.push(S,1-L)}g(),u()}function u(){for(let y=0;y<a.length;y+=6){const x=a[y+0],S=a[y+2],L=a[y+4],T=Math.max(x,S,L),E=Math.min(x,S,L);T>.9&&E<.1&&(x<.2&&(a[y+0]+=1),S<.2&&(a[y+2]+=1),L<.2&&(a[y+4]+=1))}}function d(y){r.push(y.x,y.y,y.z)}function f(y,x){const S=y*3;x.x=t[S+0],x.y=t[S+1],x.z=t[S+2]}function g(){const y=new R,x=new R,S=new R,L=new R,T=new rt,E=new rt,P=new rt;for(let U=0,v=0;U<r.length;U+=9,v+=6){y.set(r[U+0],r[U+1],r[U+2]),x.set(r[U+3],r[U+4],r[U+5]),S.set(r[U+6],r[U+7],r[U+8]),T.set(a[v+0],a[v+1]),E.set(a[v+2],a[v+3]),P.set(a[v+4],a[v+5]),L.copy(y).add(x).add(S).divideScalar(3);const b=m(L);_(T,v+0,y,b),_(E,v+2,x,b),_(P,v+4,S,b)}}function _(y,x,S,L){L<0&&y.x===1&&(a[x]=y.x-1),S.x===0&&S.z===0&&(a[x]=L/2/Math.PI+.5)}function m(y){return Math.atan2(y.z,-y.x)}function p(y){return Math.atan2(-y.y,Math.sqrt(y.x*y.x+y.z*y.z))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ph(t.vertices,t.indices,t.radius,t.details)}}class pr extends ph{constructor(t=1,e=0){const n=(1+Math.sqrt(5))/2,s=[-1,n,0,1,n,0,-1,-n,0,1,-n,0,0,-1,n,0,1,n,0,-1,-n,0,1,-n,n,0,-1,n,0,1,-n,0,-1,-n,0,1],r=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1];super(s,r,t,e),this.type="IcosahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new pr(t.radius,t.detail)}}class mh extends cn{constructor(t=.5,e=1,n=32,s=1,r=0,a=Math.PI*2){super(),this.type="RingGeometry",this.parameters={innerRadius:t,outerRadius:e,thetaSegments:n,phiSegments:s,thetaStart:r,thetaLength:a},n=Math.max(3,n),s=Math.max(1,s);const o=[],l=[],c=[],h=[];let u=t;const d=(e-t)/s,f=new R,g=new rt;for(let _=0;_<=s;_++){for(let m=0;m<=n;m++){const p=r+m/n*a;f.x=u*Math.cos(p),f.y=u*Math.sin(p),l.push(f.x,f.y,f.z),c.push(0,0,1),g.x=(f.x/e+1)/2,g.y=(f.y/e+1)/2,h.push(g.x,g.y)}u+=d}for(let _=0;_<s;_++){const m=_*(n+1);for(let p=0;p<n;p++){const y=p+m,x=y,S=y+n+1,L=y+n+2,T=y+1;o.push(x,S,T),o.push(S,L,T)}}this.setIndex(o),this.setAttribute("position",new he(l,3)),this.setAttribute("normal",new he(c,3)),this.setAttribute("uv",new he(h,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new mh(t.innerRadius,t.outerRadius,t.thetaSegments,t.phiSegments,t.thetaStart,t.thetaLength)}}class li extends cn{constructor(t=1,e=32,n=16,s=0,r=Math.PI*2,a=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:n,phiStart:s,phiLength:r,thetaStart:a,thetaLength:o},e=Math.max(3,Math.floor(e)),n=Math.max(2,Math.floor(n));const l=Math.min(a+o,Math.PI);let c=0;const h=[],u=new R,d=new R,f=[],g=[],_=[],m=[];for(let p=0;p<=n;p++){const y=[],x=p/n;let S=0;p===0&&a===0?S=.5/e:p===n&&l===Math.PI&&(S=-.5/e);for(let L=0;L<=e;L++){const T=L/e;u.x=-t*Math.cos(s+T*r)*Math.sin(a+x*o),u.y=t*Math.cos(a+x*o),u.z=t*Math.sin(s+T*r)*Math.sin(a+x*o),g.push(u.x,u.y,u.z),d.copy(u).normalize(),_.push(d.x,d.y,d.z),m.push(T+S,1-x),y.push(c++)}h.push(y)}for(let p=0;p<n;p++)for(let y=0;y<e;y++){const x=h[p][y+1],S=h[p][y],L=h[p+1][y],T=h[p+1][y+1];(p!==0||a>0)&&f.push(x,S,T),(p!==n-1||l<Math.PI)&&f.push(S,L,T)}this.setIndex(f),this.setAttribute("position",new he(g,3)),this.setAttribute("normal",new he(_,3)),this.setAttribute("uv",new he(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new li(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class ii extends cn{constructor(t=1,e=.4,n=12,s=48,r=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:n,tubularSegments:s,arc:r},n=Math.floor(n),s=Math.floor(s);const a=[],o=[],l=[],c=[],h=new R,u=new R,d=new R;for(let f=0;f<=n;f++)for(let g=0;g<=s;g++){const _=g/s*r,m=f/n*Math.PI*2;u.x=(t+e*Math.cos(m))*Math.cos(_),u.y=(t+e*Math.cos(m))*Math.sin(_),u.z=e*Math.sin(m),o.push(u.x,u.y,u.z),h.x=t*Math.cos(_),h.y=t*Math.sin(_),d.subVectors(u,h).normalize(),l.push(d.x,d.y,d.z),c.push(g/s),c.push(f/n)}for(let f=1;f<=n;f++)for(let g=1;g<=s;g++){const _=(s+1)*f+g-1,m=(s+1)*(f-1)+g-1,p=(s+1)*(f-1)+g,y=(s+1)*f+g;a.push(_,m,y),a.push(m,p,y)}this.setIndex(a),this.setAttribute("position",new he(o,3)),this.setAttribute("normal",new he(l,3)),this.setAttribute("uv",new he(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ii(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class dy extends Ii{constructor(t){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new Zt(0),this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.fog=t.fog,this}}class fy extends Je{constructor(t){super(t),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class On extends Ii{constructor(t){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new Zt(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Zt(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=eh,this.normalScale=new rt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new ui,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.envMapIntensity=t.envMapIntensity,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class py extends Ii{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=eh,this.normalScale=new rt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class gh extends Ye{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new Zt(t),this.intensity=e}dispose(){}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,this.groundColor!==void 0&&(e.object.groundColor=this.groundColor.getHex()),this.distance!==void 0&&(e.object.distance=this.distance),this.angle!==void 0&&(e.object.angle=this.angle),this.decay!==void 0&&(e.object.decay=this.decay),this.penumbra!==void 0&&(e.object.penumbra=this.penumbra),this.shadow!==void 0&&(e.object.shadow=this.shadow.toJSON()),this.target!==void 0&&(e.object.target=this.target.uuid),e}}class my extends gh{constructor(t,e,n){super(t,n),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Ye.DEFAULT_UP),this.updateMatrix(),this.groundColor=new Zt(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}}const Ml=new fe,Bu=new R,Hu=new R;class Pf{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new rt(512,512),this.map=null,this.mapPass=null,this.matrix=new fe,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new oh,this._frameExtents=new rt(1,1),this._viewportCount=1,this._viewports=[new me(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,n=this.matrix;Bu.setFromMatrixPosition(t.matrixWorld),e.position.copy(Bu),Hu.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Hu),e.updateMatrixWorld(),Ml.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Ml),n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Ml)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.intensity=t.intensity,this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return new this.constructor().copy(this)}toJSON(){const t={};return this.intensity!==1&&(t.intensity=this.intensity),this.bias!==0&&(t.bias=this.bias),this.normalBias!==0&&(t.normalBias=this.normalBias),this.radius!==1&&(t.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}const Vu=new fe,Er=new R,bl=new R;class gy extends Pf{constructor(){super(new wn(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new rt(4,2),this._viewportCount=6,this._viewports=[new me(2,1,1,1),new me(0,1,1,1),new me(3,1,1,1),new me(1,1,1,1),new me(3,0,1,1),new me(1,0,1,1)],this._cubeDirections=[new R(1,0,0),new R(-1,0,0),new R(0,0,1),new R(0,0,-1),new R(0,1,0),new R(0,-1,0)],this._cubeUps=[new R(0,1,0),new R(0,1,0),new R(0,1,0),new R(0,1,0),new R(0,0,1),new R(0,0,-1)]}updateMatrices(t,e=0){const n=this.camera,s=this.matrix,r=t.distance||n.far;r!==n.far&&(n.far=r,n.updateProjectionMatrix()),Er.setFromMatrixPosition(t.matrixWorld),n.position.copy(Er),bl.copy(n.position),bl.add(this._cubeDirections[e]),n.up.copy(this._cubeUps[e]),n.lookAt(bl),n.updateMatrixWorld(),s.makeTranslation(-Er.x,-Er.y,-Er.z),Vu.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Vu)}}class vy extends gh{constructor(t,e,n=0,s=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=n,this.decay=s,this.shadow=new gy}get power(){return this.intensity*4*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}}class _y extends Pf{constructor(){super(new lh(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class xy extends gh{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Ye.DEFAULT_UP),this.updateMatrix(),this.target=new Ye,this.shadow=new _y}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class Lf{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Gu(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=Gu();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Gu(){return performance.now()}const $u=new fe;class Df{constructor(t,e,n=0,s=1/0){this.ray=new rh(t,e),this.near=n,this.far=s,this.camera=null,this.layers=new ah,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e.isOrthographicCamera?(this.ray.origin.set(t.x,t.y,(e.near+e.far)/(e.near-e.far)).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e):console.error("THREE.Raycaster: Unsupported camera type: "+e.type)}setFromXRController(t){return $u.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4($u),this}intersectObject(t,e=!0,n=[]){return Nc(t,this,n,e),n.sort(Wu),n}intersectObjects(t,e=!0,n=[]){for(let s=0,r=t.length;s<r;s++)Nc(t[s],this,n,e);return n.sort(Wu),n}}function Wu(i,t){return i.distance-t.distance}function Nc(i,t,e,n){let s=!0;if(i.layers.test(t.layers)&&i.raycast(t,e)===!1&&(s=!1),s===!0&&n===!0){const r=i.children;for(let a=0,o=r.length;a<o;a++)Nc(r[a],t,e,!0)}}class mr{constructor(t=1,e=0,n=0){return this.radius=t,this.phi=e,this.theta=n,this}set(t,e,n){return this.radius=t,this.phi=e,this.theta=n,this}copy(t){return this.radius=t.radius,this.phi=t.phi,this.theta=t.theta,this}makeSafe(){return this.phi=Math.max(1e-6,Math.min(Math.PI-1e-6,this.phi)),this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,n){return this.radius=Math.sqrt(t*t+e*e+n*n),this.radius===0?(this.theta=0,this.phi=0):(this.theta=Math.atan2(t,n),this.phi=Math.acos(Ue(e/this.radius,-1,1))),this}clone(){return new this.constructor().copy(this)}}class yy extends bs{constructor(t,e=null){super(),this.object=t,this.domElement=e,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(){}disconnect(){}dispose(){}update(){}}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:jc}}));typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=jc);const Xu={type:"change"},vh={type:"start"},If={type:"end"},Aa=new rh,ju=new $i,My=Math.cos(70*fs.DEG2RAD),ke=new R,dn=2*Math.PI,pe={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},Sl=1e-6;class by extends yy{constructor(t,e=null){super(t,e),this.state=pe.NONE,this.enabled=!0,this.target=new R,this.cursor=new R,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.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:Ci.ROTATE,MIDDLE:Ci.DOLLY,RIGHT:Ci.PAN},this.touches={ONE:Ji.ROTATE,TWO:Ji.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new R,this._lastQuaternion=new ns,this._lastTargetPosition=new R,this._quat=new ns().setFromUnitVectors(t.up,new R(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new mr,this._sphericalDelta=new mr,this._scale=1,this._panOffset=new R,this._rotateStart=new rt,this._rotateEnd=new rt,this._rotateDelta=new rt,this._panStart=new rt,this._panEnd=new rt,this._panDelta=new rt,this._dollyStart=new rt,this._dollyEnd=new rt,this._dollyDelta=new rt,this._dollyDirection=new R,this._mouse=new rt,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=wy.bind(this),this._onPointerDown=Sy.bind(this),this._onPointerUp=Ey.bind(this),this._onContextMenu=Dy.bind(this),this._onMouseWheel=Cy.bind(this),this._onKeyDown=Ry.bind(this),this._onTouchStart=Py.bind(this),this._onTouchMove=Ly.bind(this),this._onMouseDown=Ty.bind(this),this._onMouseMove=Ay.bind(this),this._interceptControlDown=Iy.bind(this),this._interceptControlUp=ky.bind(this),this.domElement!==null&&this.connect(),this.update()}connect(){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.removeEventListener("pointermove",this._onPointerMove),this.domElement.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(t){t.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=t}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(Xu),this.update(),this.state=pe.NONE}update(t=null){const e=this.object.position;ke.copy(e).sub(this.target),ke.applyQuaternion(this._quat),this._spherical.setFromVector3(ke),this.autoRotate&&this.state===pe.NONE&&this._rotateLeft(this._getAutoRotationAngle(t)),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 n=this.minAzimuthAngle,s=this.maxAzimuthAngle;isFinite(n)&&isFinite(s)&&(n<-Math.PI?n+=dn:n>Math.PI&&(n-=dn),s<-Math.PI?s+=dn:s>Math.PI&&(s-=dn),n<=s?this._spherical.theta=Math.max(n,Math.min(s,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+s)/2?Math.max(n,this._spherical.theta):Math.min(s,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 r=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const a=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),r=a!=this._spherical.radius}if(ke.setFromSpherical(this._spherical),ke.applyQuaternion(this._quatInverse),e.copy(this.target).add(ke),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 a=null;if(this.object.isPerspectiveCamera){const o=ke.length();a=this._clampDistance(o*this._scale);const l=o-a;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),r=!!l}else if(this.object.isOrthographicCamera){const o=new R(this._mouse.x,this._mouse.y,0);o.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),r=l!==this.object.zoom;const c=new R(this._mouse.x,this._mouse.y,0);c.unproject(this.object),this.object.position.sub(c).add(o),this.object.updateMatrixWorld(),a=ke.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;a!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(a).add(this.object.position):(Aa.origin.copy(this.object.position),Aa.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Aa.direction))<My?this.object.lookAt(this.target):(ju.setFromNormalAndCoplanarPoint(this.object.up,this.target),Aa.intersectPlane(ju,this.target))))}else if(this.object.isOrthographicCamera){const a=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),a!==this.object.zoom&&(this.object.updateProjectionMatrix(),r=!0)}return this._scale=1,this._performCursorZoom=!1,r||this._lastPosition.distanceToSquared(this.object.position)>Sl||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Sl||this._lastTargetPosition.distanceToSquared(this.target)>Sl?(this.dispatchEvent(Xu),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(t){return t!==null?dn/60*this.autoRotateSpeed*t:dn/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(t*.01);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){ke.setFromMatrixColumn(e,0),ke.multiplyScalar(-t),this._panOffset.add(ke)}_panUp(t,e){this.screenSpacePanning===!0?ke.setFromMatrixColumn(e,1):(ke.setFromMatrixColumn(e,0),ke.crossVectors(this.object.up,ke)),ke.multiplyScalar(t),this._panOffset.add(ke)}_pan(t,e){const n=this.domElement;if(this.object.isPerspectiveCamera){const s=this.object.position;ke.copy(s).sub(this.target);let r=ke.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*r/n.clientHeight,this.object.matrix),this._panUp(2*e*r/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),s=t-n.left,r=e-n.top,a=n.width,o=n.height;this._mouse.x=s/a*2-1,this._mouse.y=-(r/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(dn*this._rotateDelta.x/e.clientHeight),this._rotateUp(dn*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.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(t){this._panEnd.set(t.clientX,t.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(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateUp(dn*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateUp(-dn*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateLeft(dn*this.rotateSpeed/this.domElement.clientHeight):this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateLeft(-dn*this.rotateSpeed/this.domElement.clientHeight):this._pan(-this.keyPanSpeed,0),e=!0;break}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(this._pointers.length===1)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),s=.5*(t.pageY+e.y);this._rotateStart.set(n,s)}}_handleTouchStartPan(t){if(this._pointers.length===1)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),s=.5*(t.pageY+e.y);this._panStart.set(n,s)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,s=t.pageY-e.y,r=Math.sqrt(n*n+s*s);this._dollyStart.set(0,r)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(this._pointers.length==1)this._rotateEnd.set(t.pageX,t.pageY);else{const n=this._getSecondPointerPosition(t),s=.5*(t.pageX+n.x),r=.5*(t.pageY+n.y);this._rotateEnd.set(s,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(dn*this._rotateDelta.x/e.clientHeight),this._rotateUp(dn*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(this._pointers.length===1)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),s=.5*(t.pageY+e.y);this._panEnd.set(n,s)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,s=t.pageY-e.y,r=Math.sqrt(n*n+s*s);this._dollyEnd.set(0,r),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 a=(t.pageX+e.x)*.5,o=(t.pageY+e.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId){this._pointers.splice(e,1);return}}_isTrackingPointer(t){for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return!0;return!1}_trackPointer(t){let e=this._pointerPositions[t.pointerId];e===void 0&&(e=new rt,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[e]}_customWheelEvent(t){const e=t.deltaMode,n={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(e){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return t.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function Sy(i){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(i.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(i)&&(this._addPointer(i),i.pointerType==="touch"?this._onTouchStart(i):this._onMouseDown(i)))}function wy(i){this.enabled!==!1&&(i.pointerType==="touch"?this._onTouchMove(i):this._onMouseMove(i))}function Ey(i){switch(this._removePointer(i),this._pointers.length){case 0:this.domElement.releasePointerCapture(i.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(If),this.state=pe.NONE;break;case 1:const t=this._pointers[0],e=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:e.x,pageY:e.y});break}}function Ty(i){let t;switch(i.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=-1}switch(t){case Ci.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(i),this.state=pe.DOLLY;break;case Ci.ROTATE:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=pe.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=pe.ROTATE}break;case Ci.PAN:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=pe.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=pe.PAN}break;default:this.state=pe.NONE}this.state!==pe.NONE&&this.dispatchEvent(vh)}function Ay(i){switch(this.state){case pe.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(i);break;case pe.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(i);break;case pe.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(i);break}}function Cy(i){this.enabled===!1||this.enableZoom===!1||this.state!==pe.NONE||(i.preventDefault(),this.dispatchEvent(vh),this._handleMouseWheel(this._customWheelEvent(i)),this.dispatchEvent(If))}function Ry(i){this.enabled===!1||this.enablePan===!1||this._handleKeyDown(i)}function Py(i){switch(this._trackPointer(i),this._pointers.length){case 1:switch(this.touches.ONE){case Ji.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(i),this.state=pe.TOUCH_ROTATE;break;case Ji.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(i),this.state=pe.TOUCH_PAN;break;default:this.state=pe.NONE}break;case 2:switch(this.touches.TWO){case Ji.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(i),this.state=pe.TOUCH_DOLLY_PAN;break;case Ji.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(i),this.state=pe.TOUCH_DOLLY_ROTATE;break;default:this.state=pe.NONE}break;default:this.state=pe.NONE}this.state!==pe.NONE&&this.dispatchEvent(vh)}function Ly(i){switch(this._trackPointer(i),this.state){case pe.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(i),this.update();break;case pe.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(i),this.update();break;case pe.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(i),this.update();break;case pe.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(i),this.update();break;default:this.state=pe.NONE}}function Dy(i){this.enabled!==!1&&i.preventDefault()}function Iy(i){i.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function ky(i){i.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}class Ny extends by{constructor(t,e){super(t,e),this.screenSpacePanning=!1,this.mouseButtons={LEFT:Ci.PAN,MIDDLE:Ci.DOLLY,RIGHT:Ci.ROTATE},this.touches={ONE:Ji.PAN,TWO:Ji.DOLLY_ROTATE}}}class Uy extends wf{constructor(){super();const t=new qe;t.deleteAttribute("uv");const e=new On({side:on}),n=new On,s=new vy(16777215,900,28,2);s.position.set(.418,16.199,.3),this.add(s);const r=new yt(t,e);r.position.set(-.757,13.219,.717),r.scale.set(31.713,28.305,28.591),this.add(r);const a=new yt(t,n);a.position.set(-10.906,2.009,1.846),a.rotation.set(0,-.195,0),a.scale.set(2.328,7.905,4.651),this.add(a);const o=new yt(t,n);o.position.set(-5.607,-.754,-.758),o.rotation.set(0,.994,0),o.scale.set(1.97,1.534,3.955),this.add(o);const l=new yt(t,n);l.position.set(6.167,.857,7.803),l.rotation.set(0,.561,0),l.scale.set(3.927,6.285,3.687),this.add(l);const c=new yt(t,n);c.position.set(-2.017,.018,6.124),c.rotation.set(0,.333,0),c.scale.set(2.002,4.566,2.064),this.add(c);const h=new yt(t,n);h.position.set(2.291,-.756,-2.621),h.rotation.set(0,-.286,0),h.scale.set(1.546,1.552,1.496),this.add(h);const u=new yt(t,n);u.position.set(-2.193,-.369,-5.547),u.rotation.set(0,.516,0),u.scale.set(3.875,3.487,2.986),this.add(u);const d=new yt(t,Vs(50));d.position.set(-16.116,14.37,8.208),d.scale.set(.1,2.428,2.739),this.add(d);const f=new yt(t,Vs(50));f.position.set(-16.109,18.021,-8.207),f.scale.set(.1,2.425,2.751),this.add(f);const g=new yt(t,Vs(17));g.position.set(14.904,12.198,-1.832),g.scale.set(.15,4.265,6.331),this.add(g);const _=new yt(t,Vs(43));_.position.set(-.462,8.89,14.52),_.scale.set(4.38,5.441,.088),this.add(_);const m=new yt(t,Vs(20));m.position.set(3.235,11.486,-12.541),m.scale.set(2.5,2,.1),this.add(m);const p=new yt(t,Vs(100));p.position.set(0,20,0),p.scale.set(1,.1,1),this.add(p)}dispose(){const t=new Set;this.traverse(e=>{e.isMesh&&(t.add(e.geometry),t.add(e.material))});for(const e of t)e.dispose()}}function Vs(i){const t=new ln;return t.color.setScalar(i),t}const Qa={name:"CopyShader",uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:`
3840
+ }`;class yy{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e,n){if(this.texture===null){const s=new an,r=t.properties.get(s);r.__webglTexture=e.texture,(e.depthNear!=n.depthNear||e.depthFar!=n.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=s}}getMesh(t){if(this.texture!==null&&this.mesh===null){const e=t.cameras[0].viewport,n=new nn({vertexShader:_y,fragmentShader:xy,uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new yt(new gi(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class My extends Ps{constructor(t,e){super();const n=this;let s=null,r=1,a=null,o="local-floor",l=1,c=null,h=null,u=null,d=null,f=null,g=null;const _=new yy,m=e.getContextAttributes();let p=null,y=null;const x=[],S=[],L=new rt;let T=null;const E=new Cn;E.layers.enable(1),E.viewport=new me;const P=new Cn;P.layers.enable(2),P.viewport=new me;const U=[E,P],v=new gy;v.layers.enable(1),v.layers.enable(2);let b=null,I=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(X){let et=x[X];return et===void 0&&(et=new Rl,x[X]=et),et.getTargetRaySpace()},this.getControllerGrip=function(X){let et=x[X];return et===void 0&&(et=new Rl,x[X]=et),et.getGripSpace()},this.getHand=function(X){let et=x[X];return et===void 0&&(et=new Rl,x[X]=et),et.getHandSpace()};function O(X){const et=S.indexOf(X.inputSource);if(et===-1)return;const ft=x[et];ft!==void 0&&(ft.update(X.inputSource,X.frame,c||a),ft.dispatchEvent({type:X.type,data:X.inputSource}))}function $(){s.removeEventListener("select",O),s.removeEventListener("selectstart",O),s.removeEventListener("selectend",O),s.removeEventListener("squeeze",O),s.removeEventListener("squeezestart",O),s.removeEventListener("squeezeend",O),s.removeEventListener("end",$),s.removeEventListener("inputsourceschange",K);for(let X=0;X<x.length;X++){const et=S[X];et!==null&&(S[X]=null,x[X].disconnect(et))}b=null,I=null,_.reset(),t.setRenderTarget(p),f=null,d=null,u=null,s=null,y=null,Jt.stop(),n.isPresenting=!1,t.setPixelRatio(T),t.setSize(L.width,L.height,!1),n.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(X){r=X,n.isPresenting===!0&&console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(X){o=X,n.isPresenting===!0&&console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return c||a},this.setReferenceSpace=function(X){c=X},this.getBaseLayer=function(){return d!==null?d:f},this.getBinding=function(){return u},this.getFrame=function(){return g},this.getSession=function(){return s},this.setSession=async function(X){if(s=X,s!==null){if(p=t.getRenderTarget(),s.addEventListener("select",O),s.addEventListener("selectstart",O),s.addEventListener("selectend",O),s.addEventListener("squeeze",O),s.addEventListener("squeezestart",O),s.addEventListener("squeezeend",O),s.addEventListener("end",$),s.addEventListener("inputsourceschange",K),m.xrCompatible!==!0&&await e.makeXRCompatible(),T=t.getPixelRatio(),t.getSize(L),s.renderState.layers===void 0){const et={antialias:m.antialias,alpha:!0,depth:m.depth,stencil:m.stencil,framebufferScaleFactor:r};f=new XRWebGLLayer(s,e,et),s.updateRenderState({baseLayer:f}),t.setPixelRatio(1),t.setSize(f.framebufferWidth,f.framebufferHeight,!1),y=new Qn(f.framebufferWidth,f.framebufferHeight,{format:Nn,type:pi,colorSpace:t.outputColorSpace,stencilBuffer:m.stencil})}else{let et=null,ft=null,ot=null;m.depth&&(ot=m.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,et=m.stencil?Cs:mr,ft=m.stencil?As:Ts);const At={colorFormat:e.RGBA8,depthFormat:ot,scaleFactor:r};u=new XRWebGLBinding(s,e),d=u.createProjectionLayer(At),s.updateRenderState({layers:[d]}),t.setPixelRatio(1),t.setSize(d.textureWidth,d.textureHeight,!1),y=new Qn(d.textureWidth,d.textureHeight,{format:Nn,type:pi,depthTexture:new Th(d.textureWidth,d.textureHeight,ft,void 0,void 0,void 0,void 0,void 0,void 0,et),stencilBuffer:m.stencil,colorSpace:t.outputColorSpace,samples:m.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1})}y.isXRRenderTarget=!0,this.setFoveation(l),c=null,a=await s.requestReferenceSpace(o),Jt.setContext(s),Jt.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(s!==null)return s.environmentBlendMode},this.getDepthTexture=function(){return _.getDepthTexture()};function K(X){for(let et=0;et<X.removed.length;et++){const ft=X.removed[et],ot=S.indexOf(ft);ot>=0&&(S[ot]=null,x[ot].disconnect(ft))}for(let et=0;et<X.added.length;et++){const ft=X.added[et];let ot=S.indexOf(ft);if(ot===-1){for(let Tt=0;Tt<x.length;Tt++)if(Tt>=S.length){S.push(ft),ot=Tt;break}else if(S[Tt]===null){S[Tt]=ft,ot=Tt;break}if(ot===-1)break}const At=x[ot];At&&At.connect(ft)}}const z=new R,Z=new R;function V(X,et,ft){z.setFromMatrixPosition(et.matrixWorld),Z.setFromMatrixPosition(ft.matrixWorld);const ot=z.distanceTo(Z),At=et.projectionMatrix.elements,Tt=ft.projectionMatrix.elements,zt=At[14]/(At[10]-1),ie=At[14]/(At[10]+1),W=(At[9]+1)/At[5],A=(At[9]-1)/At[5],It=(At[8]-1)/At[0],Ct=(Tt[8]+1)/Tt[0],Bt=zt*It,Dt=zt*Ct,ue=ot/(-It+Ct),Nt=ue*-It;if(et.matrixWorld.decompose(X.position,X.quaternion,X.scale),X.translateX(Nt),X.translateZ(ue),X.matrixWorld.compose(X.position,X.quaternion,X.scale),X.matrixWorldInverse.copy(X.matrixWorld).invert(),At[10]===-1)X.projectionMatrix.copy(et.projectionMatrix),X.projectionMatrixInverse.copy(et.projectionMatrixInverse);else{const C=zt+ue,M=ie+ue,F=Bt-Nt,Y=Dt+(ot-Nt),Q=W*ie/M*C,j=A*ie/M*C;X.projectionMatrix.makePerspective(F,Y,Q,j,C,M),X.projectionMatrixInverse.copy(X.projectionMatrix).invert()}}function at(X,et){et===null?X.matrixWorld.copy(X.matrix):X.matrixWorld.multiplyMatrices(et.matrixWorld,X.matrix),X.matrixWorldInverse.copy(X.matrixWorld).invert()}this.updateCamera=function(X){if(s===null)return;let et=X.near,ft=X.far;_.texture!==null&&(_.depthNear>0&&(et=_.depthNear),_.depthFar>0&&(ft=_.depthFar)),v.near=P.near=E.near=et,v.far=P.far=E.far=ft,(b!==v.near||I!==v.far)&&(s.updateRenderState({depthNear:v.near,depthFar:v.far}),b=v.near,I=v.far);const ot=X.parent,At=v.cameras;at(v,ot);for(let Tt=0;Tt<At.length;Tt++)at(At[Tt],ot);At.length===2?V(v,E,P):v.projectionMatrix.copy(E.projectionMatrix),ct(X,v,ot)};function ct(X,et,ft){ft===null?X.matrix.copy(et.matrixWorld):(X.matrix.copy(ft.matrixWorld),X.matrix.invert(),X.matrix.multiply(et.matrixWorld)),X.matrix.decompose(X.position,X.quaternion,X.scale),X.updateMatrixWorld(!0),X.projectionMatrix.copy(et.projectionMatrix),X.projectionMatrixInverse.copy(et.projectionMatrixInverse),X.isPerspectiveCamera&&(X.fov=aa*2*Math.atan(1/X.projectionMatrix.elements[5]),X.zoom=1)}this.getCamera=function(){return v},this.getFoveation=function(){if(!(d===null&&f===null))return l},this.setFoveation=function(X){l=X,d!==null&&(d.fixedFoveation=X),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=X)},this.hasDepthSensing=function(){return _.texture!==null},this.getDepthSensingMesh=function(){return _.getMesh(v)};let _t=null;function $t(X,et){if(h=et.getViewerPose(c||a),g=et,h!==null){const ft=h.views;f!==null&&(t.setRenderTargetFramebuffer(y,f.framebuffer),t.setRenderTarget(y));let ot=!1;ft.length!==v.cameras.length&&(v.cameras.length=0,ot=!0);for(let Tt=0;Tt<ft.length;Tt++){const zt=ft[Tt];let ie=null;if(f!==null)ie=f.getViewport(zt);else{const A=u.getViewSubImage(d,zt);ie=A.viewport,Tt===0&&(t.setRenderTargetTextures(y,A.colorTexture,d.ignoreDepthValues?void 0:A.depthStencilTexture),t.setRenderTarget(y))}let W=U[Tt];W===void 0&&(W=new Cn,W.layers.enable(Tt),W.viewport=new me,U[Tt]=W),W.matrix.fromArray(zt.transform.matrix),W.matrix.decompose(W.position,W.quaternion,W.scale),W.projectionMatrix.fromArray(zt.projectionMatrix),W.projectionMatrixInverse.copy(W.projectionMatrix).invert(),W.viewport.set(ie.x,ie.y,ie.width,ie.height),Tt===0&&(v.matrix.copy(W.matrix),v.matrix.decompose(v.position,v.quaternion,v.scale)),ot===!0&&v.cameras.push(W)}const At=s.enabledFeatures;if(At&&At.includes("depth-sensing")){const Tt=u.getDepthInformation(ft[0]);Tt&&Tt.isValid&&Tt.texture&&_.init(t,Tt,s.renderState)}}for(let ft=0;ft<x.length;ft++){const ot=S[ft],At=x[ft];ot!==null&&At!==void 0&&At.update(ot,et,c||a)}_t&&_t(X,et),et.detectedPlanes&&n.dispatchEvent({type:"planesdetected",data:et}),g=null}const Jt=new Gf;Jt.setAnimationLoop($t),this.setAnimationLoop=function(X){_t=X},this.dispose=function(){}}}const gs=new mi,by=new fe;function Sy(i,t){function e(m,p){m.matrixAutoUpdate===!0&&m.updateMatrix(),p.value.copy(m.matrix)}function n(m,p){p.color.getRGB(m.fogColor.value,Bf(i)),p.isFog?(m.fogNear.value=p.near,m.fogFar.value=p.far):p.isFogExp2&&(m.fogDensity.value=p.density)}function s(m,p,y,x,S){p.isMeshBasicMaterial||p.isMeshLambertMaterial?r(m,p):p.isMeshToonMaterial?(r(m,p),u(m,p)):p.isMeshPhongMaterial?(r(m,p),h(m,p)):p.isMeshStandardMaterial?(r(m,p),d(m,p),p.isMeshPhysicalMaterial&&f(m,p,S)):p.isMeshMatcapMaterial?(r(m,p),g(m,p)):p.isMeshDepthMaterial?r(m,p):p.isMeshDistanceMaterial?(r(m,p),_(m,p)):p.isMeshNormalMaterial?r(m,p):p.isLineBasicMaterial?(a(m,p),p.isLineDashedMaterial&&o(m,p)):p.isPointsMaterial?l(m,p,y,x):p.isSpriteMaterial?c(m,p):p.isShadowMaterial?(m.color.value.copy(p.color),m.opacity.value=p.opacity):p.isShaderMaterial&&(p.uniformsNeedUpdate=!1)}function r(m,p){m.opacity.value=p.opacity,p.color&&m.diffuse.value.copy(p.color),p.emissive&&m.emissive.value.copy(p.emissive).multiplyScalar(p.emissiveIntensity),p.map&&(m.map.value=p.map,e(p.map,m.mapTransform)),p.alphaMap&&(m.alphaMap.value=p.alphaMap,e(p.alphaMap,m.alphaMapTransform)),p.bumpMap&&(m.bumpMap.value=p.bumpMap,e(p.bumpMap,m.bumpMapTransform),m.bumpScale.value=p.bumpScale,p.side===un&&(m.bumpScale.value*=-1)),p.normalMap&&(m.normalMap.value=p.normalMap,e(p.normalMap,m.normalMapTransform),m.normalScale.value.copy(p.normalScale),p.side===un&&m.normalScale.value.negate()),p.displacementMap&&(m.displacementMap.value=p.displacementMap,e(p.displacementMap,m.displacementMapTransform),m.displacementScale.value=p.displacementScale,m.displacementBias.value=p.displacementBias),p.emissiveMap&&(m.emissiveMap.value=p.emissiveMap,e(p.emissiveMap,m.emissiveMapTransform)),p.specularMap&&(m.specularMap.value=p.specularMap,e(p.specularMap,m.specularMapTransform)),p.alphaTest>0&&(m.alphaTest.value=p.alphaTest);const y=t.get(p),x=y.envMap,S=y.envMapRotation;x&&(m.envMap.value=x,gs.copy(S),gs.x*=-1,gs.y*=-1,gs.z*=-1,x.isCubeTexture&&x.isRenderTargetTexture===!1&&(gs.y*=-1,gs.z*=-1),m.envMapRotation.value.setFromMatrix4(by.makeRotationFromEuler(gs)),m.flipEnvMap.value=x.isCubeTexture&&x.isRenderTargetTexture===!1?-1:1,m.reflectivity.value=p.reflectivity,m.ior.value=p.ior,m.refractionRatio.value=p.refractionRatio),p.lightMap&&(m.lightMap.value=p.lightMap,m.lightMapIntensity.value=p.lightMapIntensity,e(p.lightMap,m.lightMapTransform)),p.aoMap&&(m.aoMap.value=p.aoMap,m.aoMapIntensity.value=p.aoMapIntensity,e(p.aoMap,m.aoMapTransform))}function a(m,p){m.diffuse.value.copy(p.color),m.opacity.value=p.opacity,p.map&&(m.map.value=p.map,e(p.map,m.mapTransform))}function o(m,p){m.dashSize.value=p.dashSize,m.totalSize.value=p.dashSize+p.gapSize,m.scale.value=p.scale}function l(m,p,y,x){m.diffuse.value.copy(p.color),m.opacity.value=p.opacity,m.size.value=p.size*y,m.scale.value=x*.5,p.map&&(m.map.value=p.map,e(p.map,m.uvTransform)),p.alphaMap&&(m.alphaMap.value=p.alphaMap,e(p.alphaMap,m.alphaMapTransform)),p.alphaTest>0&&(m.alphaTest.value=p.alphaTest)}function c(m,p){m.diffuse.value.copy(p.color),m.opacity.value=p.opacity,m.rotation.value=p.rotation,p.map&&(m.map.value=p.map,e(p.map,m.mapTransform)),p.alphaMap&&(m.alphaMap.value=p.alphaMap,e(p.alphaMap,m.alphaMapTransform)),p.alphaTest>0&&(m.alphaTest.value=p.alphaTest)}function h(m,p){m.specular.value.copy(p.specular),m.shininess.value=Math.max(p.shininess,1e-4)}function u(m,p){p.gradientMap&&(m.gradientMap.value=p.gradientMap)}function d(m,p){m.metalness.value=p.metalness,p.metalnessMap&&(m.metalnessMap.value=p.metalnessMap,e(p.metalnessMap,m.metalnessMapTransform)),m.roughness.value=p.roughness,p.roughnessMap&&(m.roughnessMap.value=p.roughnessMap,e(p.roughnessMap,m.roughnessMapTransform)),p.envMap&&(m.envMapIntensity.value=p.envMapIntensity)}function f(m,p,y){m.ior.value=p.ior,p.sheen>0&&(m.sheenColor.value.copy(p.sheenColor).multiplyScalar(p.sheen),m.sheenRoughness.value=p.sheenRoughness,p.sheenColorMap&&(m.sheenColorMap.value=p.sheenColorMap,e(p.sheenColorMap,m.sheenColorMapTransform)),p.sheenRoughnessMap&&(m.sheenRoughnessMap.value=p.sheenRoughnessMap,e(p.sheenRoughnessMap,m.sheenRoughnessMapTransform))),p.clearcoat>0&&(m.clearcoat.value=p.clearcoat,m.clearcoatRoughness.value=p.clearcoatRoughness,p.clearcoatMap&&(m.clearcoatMap.value=p.clearcoatMap,e(p.clearcoatMap,m.clearcoatMapTransform)),p.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=p.clearcoatRoughnessMap,e(p.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),p.clearcoatNormalMap&&(m.clearcoatNormalMap.value=p.clearcoatNormalMap,e(p.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(p.clearcoatNormalScale),p.side===un&&m.clearcoatNormalScale.value.negate())),p.dispersion>0&&(m.dispersion.value=p.dispersion),p.iridescence>0&&(m.iridescence.value=p.iridescence,m.iridescenceIOR.value=p.iridescenceIOR,m.iridescenceThicknessMinimum.value=p.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=p.iridescenceThicknessRange[1],p.iridescenceMap&&(m.iridescenceMap.value=p.iridescenceMap,e(p.iridescenceMap,m.iridescenceMapTransform)),p.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=p.iridescenceThicknessMap,e(p.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),p.transmission>0&&(m.transmission.value=p.transmission,m.transmissionSamplerMap.value=y.texture,m.transmissionSamplerSize.value.set(y.width,y.height),p.transmissionMap&&(m.transmissionMap.value=p.transmissionMap,e(p.transmissionMap,m.transmissionMapTransform)),m.thickness.value=p.thickness,p.thicknessMap&&(m.thicknessMap.value=p.thicknessMap,e(p.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=p.attenuationDistance,m.attenuationColor.value.copy(p.attenuationColor)),p.anisotropy>0&&(m.anisotropyVector.value.set(p.anisotropy*Math.cos(p.anisotropyRotation),p.anisotropy*Math.sin(p.anisotropyRotation)),p.anisotropyMap&&(m.anisotropyMap.value=p.anisotropyMap,e(p.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=p.specularIntensity,m.specularColor.value.copy(p.specularColor),p.specularColorMap&&(m.specularColorMap.value=p.specularColorMap,e(p.specularColorMap,m.specularColorMapTransform)),p.specularIntensityMap&&(m.specularIntensityMap.value=p.specularIntensityMap,e(p.specularIntensityMap,m.specularIntensityMapTransform))}function g(m,p){p.matcap&&(m.matcap.value=p.matcap)}function _(m,p){const y=t.get(p).light;m.referencePosition.value.setFromMatrixPosition(y.matrixWorld),m.nearDistance.value=y.shadow.camera.near,m.farDistance.value=y.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:s}}function wy(i,t,e,n){let s={},r={},a=[];const o=i.getParameter(i.MAX_UNIFORM_BUFFER_BINDINGS);function l(y,x){const S=x.program;n.uniformBlockBinding(y,S)}function c(y,x){let S=s[y.id];S===void 0&&(g(y),S=h(y),s[y.id]=S,y.addEventListener("dispose",m));const L=x.program;n.updateUBOMapping(y,L);const T=t.render.frame;r[y.id]!==T&&(d(y),r[y.id]=T)}function h(y){const x=u();y.__bindingPointIndex=x;const S=i.createBuffer(),L=y.__size,T=y.usage;return i.bindBuffer(i.UNIFORM_BUFFER,S),i.bufferData(i.UNIFORM_BUFFER,L,T),i.bindBuffer(i.UNIFORM_BUFFER,null),i.bindBufferBase(i.UNIFORM_BUFFER,x,S),S}function u(){for(let y=0;y<o;y++)if(a.indexOf(y)===-1)return a.push(y),y;return console.error("THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function d(y){const x=s[y.id],S=y.uniforms,L=y.__cache;i.bindBuffer(i.UNIFORM_BUFFER,x);for(let T=0,E=S.length;T<E;T++){const P=Array.isArray(S[T])?S[T]:[S[T]];for(let U=0,v=P.length;U<v;U++){const b=P[U];if(f(b,T,U,L)===!0){const I=b.__offset,O=Array.isArray(b.value)?b.value:[b.value];let $=0;for(let K=0;K<O.length;K++){const z=O[K],Z=_(z);typeof z=="number"||typeof z=="boolean"?(b.__data[0]=z,i.bufferSubData(i.UNIFORM_BUFFER,I+$,b.__data)):z.isMatrix3?(b.__data[0]=z.elements[0],b.__data[1]=z.elements[1],b.__data[2]=z.elements[2],b.__data[3]=0,b.__data[4]=z.elements[3],b.__data[5]=z.elements[4],b.__data[6]=z.elements[5],b.__data[7]=0,b.__data[8]=z.elements[6],b.__data[9]=z.elements[7],b.__data[10]=z.elements[8],b.__data[11]=0):(z.toArray(b.__data,$),$+=Z.storage/Float32Array.BYTES_PER_ELEMENT)}i.bufferSubData(i.UNIFORM_BUFFER,I,b.__data)}}}i.bindBuffer(i.UNIFORM_BUFFER,null)}function f(y,x,S,L){const T=y.value,E=x+"_"+S;if(L[E]===void 0)return typeof T=="number"||typeof T=="boolean"?L[E]=T:L[E]=T.clone(),!0;{const P=L[E];if(typeof T=="number"||typeof T=="boolean"){if(P!==T)return L[E]=T,!0}else if(P.equals(T)===!1)return P.copy(T),!0}return!1}function g(y){const x=y.uniforms;let S=0;const L=16;for(let E=0,P=x.length;E<P;E++){const U=Array.isArray(x[E])?x[E]:[x[E]];for(let v=0,b=U.length;v<b;v++){const I=U[v],O=Array.isArray(I.value)?I.value:[I.value];for(let $=0,K=O.length;$<K;$++){const z=O[$],Z=_(z),V=S%L,at=V%Z.boundary,ct=V+at;S+=at,ct!==0&&L-ct<Z.storage&&(S+=L-ct),I.__data=new Float32Array(Z.storage/Float32Array.BYTES_PER_ELEMENT),I.__offset=S,S+=Z.storage}}}const T=S%L;return T>0&&(S+=L-T),y.__size=S,y.__cache={},this}function _(y){const x={boundary:0,storage:0};return typeof y=="number"||typeof y=="boolean"?(x.boundary=4,x.storage=4):y.isVector2?(x.boundary=8,x.storage=8):y.isVector3||y.isColor?(x.boundary=16,x.storage=12):y.isVector4?(x.boundary=16,x.storage=16):y.isMatrix3?(x.boundary=48,x.storage=48):y.isMatrix4?(x.boundary=64,x.storage=64):y.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",y),x}function m(y){const x=y.target;x.removeEventListener("dispose",m);const S=a.indexOf(x.__bindingPointIndex);a.splice(S,1),i.deleteBuffer(s[x.id]),delete s[x.id],delete r[x.id]}function p(){for(const y in s)i.deleteBuffer(s[y]);a=[],s={},r={}}return{bind:l,update:c,dispose:p}}class Ey{constructor(t={}){const{canvas:e=f0(),context:n=null,depth:s=!0,stencil:r=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:u=!1}=t;this.isWebGLRenderer=!0;let d;if(n!==null){if(typeof WebGLRenderingContext<"u"&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");d=n.getContextAttributes().alpha}else d=a;const f=new Uint32Array(4),g=new Int32Array(4);let _=null,m=null;const p=[],y=[];this.domElement=e,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this._outputColorSpace=Ke,this.toneMapping=ss,this.toneMappingExposure=1;const x=this;let S=!1,L=0,T=0,E=null,P=-1,U=null;const v=new me,b=new me;let I=null;const O=new Zt(0);let $=0,K=e.width,z=e.height,Z=1,V=null,at=null;const ct=new me(0,0,K,z),_t=new me(0,0,K,z);let $t=!1;const Jt=new Sh;let X=!1,et=!1;const ft=new fe,ot=new fe,At=new R,Tt=new me,zt={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let ie=!1;function W(){return E===null?Z:1}let A=n;function It(w,k){return e.getContext(w,k)}try{const w={alpha:!0,depth:s,stencil:r,antialias:o,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:h,failIfMajorPerformanceCaveat:u};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${ch}`),e.addEventListener("webglcontextlost",J,!1),e.addEventListener("webglcontextrestored",gt,!1),e.addEventListener("webglcontextcreationerror",xt,!1),A===null){const k="webgl2";if(A=It(k,w),A===null)throw It(k)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(w){throw console.error("THREE.WebGLRenderer: "+w.message),w}let Ct,Bt,Dt,ue,Nt,C,M,F,Y,Q,j,St,ht,pt,Yt,nt,mt,Ut,Ot,Mt,Qt,Vt,se,D;function dt(){Ct=new P_(A),Ct.init(),Vt=new my(A,Ct),Bt=new w_(A,Ct,t,Vt),Dt=new dy(A),Bt.reverseDepthBuffer&&Dt.buffers.depth.setReversed(!0),ue=new I_(A),Nt=new Zx,C=new py(A,Ct,Dt,Nt,Bt,Vt,ue),M=new T_(x),F=new R_(x),Y=new B0(A),se=new b_(A,Y),Q=new L_(A,Y,ue,se),j=new N_(A,Q,Y,ue),Ot=new k_(A,Bt,C),nt=new E_(Nt),St=new Kx(x,M,F,Ct,Bt,se,nt),ht=new Sy(x,Nt),pt=new Qx,Yt=new ry(Ct),Ut=new M_(x,M,F,Dt,j,d,l),mt=new hy(x,j,Bt),D=new wy(A,ue,Bt,Dt),Mt=new S_(A,Ct,ue),Qt=new D_(A,Ct,ue),ue.programs=St.programs,x.capabilities=Bt,x.extensions=Ct,x.properties=Nt,x.renderLists=pt,x.shadowMap=mt,x.state=Dt,x.info=ue}dt();const G=new My(x,A);this.xr=G,this.getContext=function(){return A},this.getContextAttributes=function(){return A.getContextAttributes()},this.forceContextLoss=function(){const w=Ct.get("WEBGL_lose_context");w&&w.loseContext()},this.forceContextRestore=function(){const w=Ct.get("WEBGL_lose_context");w&&w.restoreContext()},this.getPixelRatio=function(){return Z},this.setPixelRatio=function(w){w!==void 0&&(Z=w,this.setSize(K,z,!1))},this.getSize=function(w){return w.set(K,z)},this.setSize=function(w,k,B=!0){if(G.isPresenting){console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");return}K=w,z=k,e.width=Math.floor(w*Z),e.height=Math.floor(k*Z),B===!0&&(e.style.width=w+"px",e.style.height=k+"px"),this.setViewport(0,0,w,k)},this.getDrawingBufferSize=function(w){return w.set(K*Z,z*Z).floor()},this.setDrawingBufferSize=function(w,k,B){K=w,z=k,Z=B,e.width=Math.floor(w*B),e.height=Math.floor(k*B),this.setViewport(0,0,w,k)},this.getCurrentViewport=function(w){return w.copy(v)},this.getViewport=function(w){return w.copy(ct)},this.setViewport=function(w,k,B,H){w.isVector4?ct.set(w.x,w.y,w.z,w.w):ct.set(w,k,B,H),Dt.viewport(v.copy(ct).multiplyScalar(Z).round())},this.getScissor=function(w){return w.copy(_t)},this.setScissor=function(w,k,B,H){w.isVector4?_t.set(w.x,w.y,w.z,w.w):_t.set(w,k,B,H),Dt.scissor(b.copy(_t).multiplyScalar(Z).round())},this.getScissorTest=function(){return $t},this.setScissorTest=function(w){Dt.setScissorTest($t=w)},this.setOpaqueSort=function(w){V=w},this.setTransparentSort=function(w){at=w},this.getClearColor=function(w){return w.copy(Ut.getClearColor())},this.setClearColor=function(){Ut.setClearColor.apply(Ut,arguments)},this.getClearAlpha=function(){return Ut.getClearAlpha()},this.setClearAlpha=function(){Ut.setClearAlpha.apply(Ut,arguments)},this.clear=function(w=!0,k=!0,B=!0){let H=0;if(w){let N=!1;if(E!==null){const st=E.texture.format;N=st===gh||st===mh||st===ph}if(N){const st=E.texture.type,vt=st===pi||st===Ts||st===ra||st===As||st===dh||st===fh,bt=Ut.getClearColor(),Et=Ut.getClearAlpha(),Ft=bt.r,Ht=bt.g,Rt=bt.b;vt?(f[0]=Ft,f[1]=Ht,f[2]=Rt,f[3]=Et,A.clearBufferuiv(A.COLOR,0,f)):(g[0]=Ft,g[1]=Ht,g[2]=Rt,g[3]=Et,A.clearBufferiv(A.COLOR,0,g))}else H|=A.COLOR_BUFFER_BIT}k&&(H|=A.DEPTH_BUFFER_BIT,A.clearDepth(this.capabilities.reverseDepthBuffer?0:1)),B&&(H|=A.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),A.clear(H)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){e.removeEventListener("webglcontextlost",J,!1),e.removeEventListener("webglcontextrestored",gt,!1),e.removeEventListener("webglcontextcreationerror",xt,!1),pt.dispose(),Yt.dispose(),Nt.dispose(),M.dispose(),F.dispose(),j.dispose(),se.dispose(),D.dispose(),St.dispose(),G.dispose(),G.removeEventListener("sessionstart",qh),G.removeEventListener("sessionend",Yh),hs.stop()};function J(w){w.preventDefault(),console.log("THREE.WebGLRenderer: Context Lost."),S=!0}function gt(){console.log("THREE.WebGLRenderer: Context Restored."),S=!1;const w=ue.autoReset,k=mt.enabled,B=mt.autoUpdate,H=mt.needsUpdate,N=mt.type;dt(),ue.autoReset=w,mt.enabled=k,mt.autoUpdate=B,mt.needsUpdate=H,mt.type=N}function xt(w){console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ",w.statusMessage)}function ne(w){const k=w.target;k.removeEventListener("dispose",ne),ke(k)}function ke(w){pn(w),Nt.remove(w)}function pn(w){const k=Nt.get(w).programs;k!==void 0&&(k.forEach(function(B){St.releaseProgram(B)}),w.isShaderMaterial&&St.releaseShaderCache(w))}this.renderBufferDirect=function(w,k,B,H,N,st){k===null&&(k=zt);const vt=N.isMesh&&N.matrixWorld.determinant()<0,bt=Fp(w,k,B,H,N);Dt.setMaterial(H,vt);let Et=B.index,Ft=1;if(H.wireframe===!0){if(Et=Q.getWireframeAttribute(B),Et===void 0)return;Ft=2}const Ht=B.drawRange,Rt=B.attributes.position;let de=Ht.start*Ft,be=(Ht.start+Ht.count)*Ft;st!==null&&(de=Math.max(de,st.start*Ft),be=Math.min(be,(st.start+st.count)*Ft)),Et!==null?(de=Math.max(de,0),be=Math.min(be,Et.count)):Rt!=null&&(de=Math.max(de,0),be=Math.min(be,Rt.count));const Re=be-de;if(Re<0||Re===1/0)return;se.setup(N,H,bt,B,Et);let bn,le=Mt;if(Et!==null&&(bn=Y.get(Et),le=Qt,le.setIndex(bn)),N.isMesh)H.wireframe===!0?(Dt.setLineWidth(H.wireframeLinewidth*W()),le.setMode(A.LINES)):le.setMode(A.TRIANGLES);else if(N.isLine){let Lt=H.linewidth;Lt===void 0&&(Lt=1),Dt.setLineWidth(Lt*W()),N.isLineSegments?le.setMode(A.LINES):N.isLineLoop?le.setMode(A.LINE_LOOP):le.setMode(A.LINE_STRIP)}else N.isPoints?le.setMode(A.POINTS):N.isSprite&&le.setMode(A.TRIANGLES);if(N.isBatchedMesh)if(N._multiDrawInstances!==null)le.renderMultiDrawInstances(N._multiDrawStarts,N._multiDrawCounts,N._multiDrawCount,N._multiDrawInstances);else if(Ct.get("WEBGL_multi_draw"))le.renderMultiDraw(N._multiDrawStarts,N._multiDrawCounts,N._multiDrawCount);else{const Lt=N._multiDrawStarts,je=N._multiDrawCounts,ce=N._multiDrawCount,Hn=Et?Y.get(Et).bytesPerElement:1,ks=Nt.get(H).currentProgram.getUniforms();for(let Sn=0;Sn<ce;Sn++)ks.setValue(A,"_gl_DrawID",Sn),le.render(Lt[Sn]/Hn,je[Sn])}else if(N.isInstancedMesh)le.renderInstances(de,Re,N.count);else if(B.isInstancedBufferGeometry){const Lt=B._maxInstanceCount!==void 0?B._maxInstanceCount:1/0,je=Math.min(B.instanceCount,Lt);le.renderInstances(de,Re,je)}else le.render(de,Re)};function ae(w,k,B){w.transparent===!0&&w.side===li&&w.forceSinglePass===!1?(w.side=un,w.needsUpdate=!0,fa(w,k,B),w.side=os,w.needsUpdate=!0,fa(w,k,B),w.side=li):fa(w,k,B)}this.compile=function(w,k,B=null){B===null&&(B=w),m=Yt.get(B),m.init(k),y.push(m),B.traverseVisible(function(N){N.isLight&&N.layers.test(k.layers)&&(m.pushLight(N),N.castShadow&&m.pushShadow(N))}),w!==B&&w.traverseVisible(function(N){N.isLight&&N.layers.test(k.layers)&&(m.pushLight(N),N.castShadow&&m.pushShadow(N))}),m.setupLights();const H=new Set;return w.traverse(function(N){if(!(N.isMesh||N.isPoints||N.isLine||N.isSprite))return;const st=N.material;if(st)if(Array.isArray(st))for(let vt=0;vt<st.length;vt++){const bt=st[vt];ae(bt,B,N),H.add(bt)}else ae(st,B,N),H.add(st)}),y.pop(),m=null,H},this.compileAsync=function(w,k,B=null){const H=this.compile(w,k,B);return new Promise(N=>{function st(){if(H.forEach(function(vt){Nt.get(vt).currentProgram.isReady()&&H.delete(vt)}),H.size===0){N(w);return}setTimeout(st,10)}Ct.get("KHR_parallel_shader_compile")!==null?st():setTimeout(st,10)})};let mn=null;function _i(w){mn&&mn(w)}function qh(){hs.stop()}function Yh(){hs.start()}const hs=new Gf;hs.setAnimationLoop(_i),typeof self<"u"&&hs.setContext(self),this.setAnimationLoop=function(w){mn=w,G.setAnimationLoop(w),w===null?hs.stop():hs.start()},G.addEventListener("sessionstart",qh),G.addEventListener("sessionend",Yh),this.render=function(w,k){if(k!==void 0&&k.isCamera!==!0){console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(S===!0)return;if(w.matrixWorldAutoUpdate===!0&&w.updateMatrixWorld(),k.parent===null&&k.matrixWorldAutoUpdate===!0&&k.updateMatrixWorld(),G.enabled===!0&&G.isPresenting===!0&&(G.cameraAutoUpdate===!0&&G.updateCamera(k),k=G.getCamera()),w.isScene===!0&&w.onBeforeRender(x,w,k,E),m=Yt.get(w,y.length),m.init(k),y.push(m),ot.multiplyMatrices(k.projectionMatrix,k.matrixWorldInverse),Jt.setFromProjectionMatrix(ot),et=this.localClippingEnabled,X=nt.init(this.clippingPlanes,et),_=pt.get(w,p.length),_.init(),p.push(_),G.enabled===!0&&G.isPresenting===!0){const st=x.xr.getDepthSensingMesh();st!==null&&$o(st,k,-1/0,x.sortObjects)}$o(w,k,0,x.sortObjects),_.finish(),x.sortObjects===!0&&_.sort(V,at),ie=G.enabled===!1||G.isPresenting===!1||G.hasDepthSensing()===!1,ie&&Ut.addToRenderList(_,w),this.info.render.frame++,X===!0&&nt.beginShadows();const B=m.state.shadowsArray;mt.render(B,w,k),X===!0&&nt.endShadows(),this.info.autoReset===!0&&this.info.reset();const H=_.opaque,N=_.transmissive;if(m.setupLights(),k.isArrayCamera){const st=k.cameras;if(N.length>0)for(let vt=0,bt=st.length;vt<bt;vt++){const Et=st[vt];Zh(H,N,w,Et)}ie&&Ut.render(w);for(let vt=0,bt=st.length;vt<bt;vt++){const Et=st[vt];Kh(_,w,Et,Et.viewport)}}else N.length>0&&Zh(H,N,w,k),ie&&Ut.render(w),Kh(_,w,k);E!==null&&(C.updateMultisampleRenderTarget(E),C.updateRenderTargetMipmap(E)),w.isScene===!0&&w.onAfterRender(x,w,k),se.resetDefaultState(),P=-1,U=null,y.pop(),y.length>0?(m=y[y.length-1],X===!0&&nt.setGlobalState(x.clippingPlanes,m.state.camera)):m=null,p.pop(),p.length>0?_=p[p.length-1]:_=null};function $o(w,k,B,H){if(w.visible===!1)return;if(w.layers.test(k.layers)){if(w.isGroup)B=w.renderOrder;else if(w.isLOD)w.autoUpdate===!0&&w.update(k);else if(w.isLight)m.pushLight(w),w.castShadow&&m.pushShadow(w);else if(w.isSprite){if(!w.frustumCulled||Jt.intersectsSprite(w)){H&&Tt.setFromMatrixPosition(w.matrixWorld).applyMatrix4(ot);const vt=j.update(w),bt=w.material;bt.visible&&_.push(w,vt,bt,B,Tt.z,null)}}else if((w.isMesh||w.isLine||w.isPoints)&&(!w.frustumCulled||Jt.intersectsObject(w))){const vt=j.update(w),bt=w.material;if(H&&(w.boundingSphere!==void 0?(w.boundingSphere===null&&w.computeBoundingSphere(),Tt.copy(w.boundingSphere.center)):(vt.boundingSphere===null&&vt.computeBoundingSphere(),Tt.copy(vt.boundingSphere.center)),Tt.applyMatrix4(w.matrixWorld).applyMatrix4(ot)),Array.isArray(bt)){const Et=vt.groups;for(let Ft=0,Ht=Et.length;Ft<Ht;Ft++){const Rt=Et[Ft],de=bt[Rt.materialIndex];de&&de.visible&&_.push(w,vt,de,B,Tt.z,Rt)}}else bt.visible&&_.push(w,vt,bt,B,Tt.z,null)}}const st=w.children;for(let vt=0,bt=st.length;vt<bt;vt++)$o(st[vt],k,B,H)}function Kh(w,k,B,H){const N=w.opaque,st=w.transmissive,vt=w.transparent;m.setupLightsView(B),X===!0&&nt.setGlobalState(x.clippingPlanes,B),H&&Dt.viewport(v.copy(H)),N.length>0&&da(N,k,B),st.length>0&&da(st,k,B),vt.length>0&&da(vt,k,B),Dt.buffers.depth.setTest(!0),Dt.buffers.depth.setMask(!0),Dt.buffers.color.setMask(!0),Dt.setPolygonOffset(!1)}function Zh(w,k,B,H){if((B.isScene===!0?B.overrideMaterial:null)!==null)return;m.state.transmissionRenderTarget[H.id]===void 0&&(m.state.transmissionRenderTarget[H.id]=new Qn(1,1,{generateMipmaps:!0,type:Ct.has("EXT_color_buffer_half_float")||Ct.has("EXT_color_buffer_float")?Ui:pi,minFilter:bs,samples:4,stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:oe.workingColorSpace}));const st=m.state.transmissionRenderTarget[H.id],vt=H.viewport||v;st.setSize(vt.z,vt.w);const bt=x.getRenderTarget();x.setRenderTarget(st),x.getClearColor(O),$=x.getClearAlpha(),$<1&&x.setClearColor(16777215,.5),x.clear(),ie&&Ut.render(B);const Et=x.toneMapping;x.toneMapping=ss;const Ft=H.viewport;if(H.viewport!==void 0&&(H.viewport=void 0),m.setupLightsView(H),X===!0&&nt.setGlobalState(x.clippingPlanes,H),da(w,B,H),C.updateMultisampleRenderTarget(st),C.updateRenderTargetMipmap(st),Ct.has("WEBGL_multisampled_render_to_texture")===!1){let Ht=!1;for(let Rt=0,de=k.length;Rt<de;Rt++){const be=k[Rt],Re=be.object,bn=be.geometry,le=be.material,Lt=be.group;if(le.side===li&&Re.layers.test(H.layers)){const je=le.side;le.side=un,le.needsUpdate=!0,Jh(Re,B,H,bn,le,Lt),le.side=je,le.needsUpdate=!0,Ht=!0}}Ht===!0&&(C.updateMultisampleRenderTarget(st),C.updateRenderTargetMipmap(st))}x.setRenderTarget(bt),x.setClearColor(O,$),Ft!==void 0&&(H.viewport=Ft),x.toneMapping=Et}function da(w,k,B){const H=k.isScene===!0?k.overrideMaterial:null;for(let N=0,st=w.length;N<st;N++){const vt=w[N],bt=vt.object,Et=vt.geometry,Ft=H===null?vt.material:H,Ht=vt.group;bt.layers.test(B.layers)&&Jh(bt,k,B,Et,Ft,Ht)}}function Jh(w,k,B,H,N,st){w.onBeforeRender(x,k,B,H,N,st),w.modelViewMatrix.multiplyMatrices(B.matrixWorldInverse,w.matrixWorld),w.normalMatrix.getNormalMatrix(w.modelViewMatrix),N.onBeforeRender(x,k,B,H,w,st),N.transparent===!0&&N.side===li&&N.forceSinglePass===!1?(N.side=un,N.needsUpdate=!0,x.renderBufferDirect(B,k,H,N,w,st),N.side=os,N.needsUpdate=!0,x.renderBufferDirect(B,k,H,N,w,st),N.side=li):x.renderBufferDirect(B,k,H,N,w,st),w.onAfterRender(x,k,B,H,N,st)}function fa(w,k,B){k.isScene!==!0&&(k=zt);const H=Nt.get(w),N=m.state.lights,st=m.state.shadowsArray,vt=N.state.version,bt=St.getParameters(w,N.state,st,k,B),Et=St.getProgramCacheKey(bt);let Ft=H.programs;H.environment=w.isMeshStandardMaterial?k.environment:null,H.fog=k.fog,H.envMap=(w.isMeshStandardMaterial?F:M).get(w.envMap||H.environment),H.envMapRotation=H.environment!==null&&w.envMap===null?k.environmentRotation:w.envMapRotation,Ft===void 0&&(w.addEventListener("dispose",ne),Ft=new Map,H.programs=Ft);let Ht=Ft.get(Et);if(Ht!==void 0){if(H.currentProgram===Ht&&H.lightsStateVersion===vt)return tu(w,bt),Ht}else bt.uniforms=St.getUniforms(w),w.onBeforeCompile(bt,x),Ht=St.acquireProgram(bt,Et),Ft.set(Et,Ht),H.uniforms=bt.uniforms;const Rt=H.uniforms;return(!w.isShaderMaterial&&!w.isRawShaderMaterial||w.clipping===!0)&&(Rt.clippingPlanes=nt.uniform),tu(w,bt),H.needsLights=Bp(w),H.lightsStateVersion=vt,H.needsLights&&(Rt.ambientLightColor.value=N.state.ambient,Rt.lightProbe.value=N.state.probe,Rt.directionalLights.value=N.state.directional,Rt.directionalLightShadows.value=N.state.directionalShadow,Rt.spotLights.value=N.state.spot,Rt.spotLightShadows.value=N.state.spotShadow,Rt.rectAreaLights.value=N.state.rectArea,Rt.ltc_1.value=N.state.rectAreaLTC1,Rt.ltc_2.value=N.state.rectAreaLTC2,Rt.pointLights.value=N.state.point,Rt.pointLightShadows.value=N.state.pointShadow,Rt.hemisphereLights.value=N.state.hemi,Rt.directionalShadowMap.value=N.state.directionalShadowMap,Rt.directionalShadowMatrix.value=N.state.directionalShadowMatrix,Rt.spotShadowMap.value=N.state.spotShadowMap,Rt.spotLightMatrix.value=N.state.spotLightMatrix,Rt.spotLightMap.value=N.state.spotLightMap,Rt.pointShadowMap.value=N.state.pointShadowMap,Rt.pointShadowMatrix.value=N.state.pointShadowMatrix),H.currentProgram=Ht,H.uniformsList=null,Ht}function Qh(w){if(w.uniformsList===null){const k=w.currentProgram.getUniforms();w.uniformsList=lo.seqWithValue(k.seq,w.uniforms)}return w.uniformsList}function tu(w,k){const B=Nt.get(w);B.outputColorSpace=k.outputColorSpace,B.batching=k.batching,B.batchingColor=k.batchingColor,B.instancing=k.instancing,B.instancingColor=k.instancingColor,B.instancingMorph=k.instancingMorph,B.skinning=k.skinning,B.morphTargets=k.morphTargets,B.morphNormals=k.morphNormals,B.morphColors=k.morphColors,B.morphTargetsCount=k.morphTargetsCount,B.numClippingPlanes=k.numClippingPlanes,B.numIntersection=k.numClipIntersection,B.vertexAlphas=k.vertexAlphas,B.vertexTangents=k.vertexTangents,B.toneMapping=k.toneMapping}function Fp(w,k,B,H,N){k.isScene!==!0&&(k=zt),C.resetTextureUnits();const st=k.fog,vt=H.isMeshStandardMaterial?k.environment:null,bt=E===null?x.outputColorSpace:E.isXRRenderTarget===!0?E.texture.colorSpace:cs,Et=(H.isMeshStandardMaterial?F:M).get(H.envMap||vt),Ft=H.vertexColors===!0&&!!B.attributes.color&&B.attributes.color.itemSize===4,Ht=!!B.attributes.tangent&&(!!H.normalMap||H.anisotropy>0),Rt=!!B.morphAttributes.position,de=!!B.morphAttributes.normal,be=!!B.morphAttributes.color;let Re=ss;H.toneMapped&&(E===null||E.isXRRenderTarget===!0)&&(Re=x.toneMapping);const bn=B.morphAttributes.position||B.morphAttributes.normal||B.morphAttributes.color,le=bn!==void 0?bn.length:0,Lt=Nt.get(H),je=m.state.lights;if(X===!0&&(et===!0||w!==U)){const Pn=w===U&&H.id===P;nt.setState(H,w,Pn)}let ce=!1;H.version===Lt.__version?(Lt.needsLights&&Lt.lightsStateVersion!==je.state.version||Lt.outputColorSpace!==bt||N.isBatchedMesh&&Lt.batching===!1||!N.isBatchedMesh&&Lt.batching===!0||N.isBatchedMesh&&Lt.batchingColor===!0&&N.colorTexture===null||N.isBatchedMesh&&Lt.batchingColor===!1&&N.colorTexture!==null||N.isInstancedMesh&&Lt.instancing===!1||!N.isInstancedMesh&&Lt.instancing===!0||N.isSkinnedMesh&&Lt.skinning===!1||!N.isSkinnedMesh&&Lt.skinning===!0||N.isInstancedMesh&&Lt.instancingColor===!0&&N.instanceColor===null||N.isInstancedMesh&&Lt.instancingColor===!1&&N.instanceColor!==null||N.isInstancedMesh&&Lt.instancingMorph===!0&&N.morphTexture===null||N.isInstancedMesh&&Lt.instancingMorph===!1&&N.morphTexture!==null||Lt.envMap!==Et||H.fog===!0&&Lt.fog!==st||Lt.numClippingPlanes!==void 0&&(Lt.numClippingPlanes!==nt.numPlanes||Lt.numIntersection!==nt.numIntersection)||Lt.vertexAlphas!==Ft||Lt.vertexTangents!==Ht||Lt.morphTargets!==Rt||Lt.morphNormals!==de||Lt.morphColors!==be||Lt.toneMapping!==Re||Lt.morphTargetsCount!==le)&&(ce=!0):(ce=!0,Lt.__version=H.version);let Hn=Lt.currentProgram;ce===!0&&(Hn=fa(H,k,N));let ks=!1,Sn=!1,Wo=!1;const De=Hn.getUniforms(),Bi=Lt.uniforms;if(Dt.useProgram(Hn.program)&&(ks=!0,Sn=!0,Wo=!0),H.id!==P&&(P=H.id,Sn=!0),ks||U!==w){Bt.reverseDepthBuffer?(ft.copy(w.projectionMatrix),m0(ft),g0(ft),De.setValue(A,"projectionMatrix",ft)):De.setValue(A,"projectionMatrix",w.projectionMatrix),De.setValue(A,"viewMatrix",w.matrixWorldInverse);const Pn=De.map.cameraPosition;Pn!==void 0&&Pn.setValue(A,At.setFromMatrixPosition(w.matrixWorld)),Bt.logarithmicDepthBuffer&&De.setValue(A,"logDepthBufFC",2/(Math.log(w.far+1)/Math.LN2)),(H.isMeshPhongMaterial||H.isMeshToonMaterial||H.isMeshLambertMaterial||H.isMeshBasicMaterial||H.isMeshStandardMaterial||H.isShaderMaterial)&&De.setValue(A,"isOrthographic",w.isOrthographicCamera===!0),U!==w&&(U=w,Sn=!0,Wo=!0)}if(N.isSkinnedMesh){De.setOptional(A,N,"bindMatrix"),De.setOptional(A,N,"bindMatrixInverse");const Pn=N.skeleton;Pn&&(Pn.boneTexture===null&&Pn.computeBoneTexture(),De.setValue(A,"boneTexture",Pn.boneTexture,C))}N.isBatchedMesh&&(De.setOptional(A,N,"batchingTexture"),De.setValue(A,"batchingTexture",N._matricesTexture,C),De.setOptional(A,N,"batchingIdTexture"),De.setValue(A,"batchingIdTexture",N._indirectTexture,C),De.setOptional(A,N,"batchingColorTexture"),N._colorsTexture!==null&&De.setValue(A,"batchingColorTexture",N._colorsTexture,C));const Xo=B.morphAttributes;if((Xo.position!==void 0||Xo.normal!==void 0||Xo.color!==void 0)&&Ot.update(N,B,Hn),(Sn||Lt.receiveShadow!==N.receiveShadow)&&(Lt.receiveShadow=N.receiveShadow,De.setValue(A,"receiveShadow",N.receiveShadow)),H.isMeshGouraudMaterial&&H.envMap!==null&&(Bi.envMap.value=Et,Bi.flipEnvMap.value=Et.isCubeTexture&&Et.isRenderTargetTexture===!1?-1:1),H.isMeshStandardMaterial&&H.envMap===null&&k.environment!==null&&(Bi.envMapIntensity.value=k.environmentIntensity),Sn&&(De.setValue(A,"toneMappingExposure",x.toneMappingExposure),Lt.needsLights&&zp(Bi,Wo),st&&H.fog===!0&&ht.refreshFogUniforms(Bi,st),ht.refreshMaterialUniforms(Bi,H,Z,z,m.state.transmissionRenderTarget[w.id]),lo.upload(A,Qh(Lt),Bi,C)),H.isShaderMaterial&&H.uniformsNeedUpdate===!0&&(lo.upload(A,Qh(Lt),Bi,C),H.uniformsNeedUpdate=!1),H.isSpriteMaterial&&De.setValue(A,"center",N.center),De.setValue(A,"modelViewMatrix",N.modelViewMatrix),De.setValue(A,"normalMatrix",N.normalMatrix),De.setValue(A,"modelMatrix",N.matrixWorld),H.isShaderMaterial||H.isRawShaderMaterial){const Pn=H.uniformsGroups;for(let jo=0,Hp=Pn.length;jo<Hp;jo++){const eu=Pn[jo];D.update(eu,Hn),D.bind(eu,Hn)}}return Hn}function zp(w,k){w.ambientLightColor.needsUpdate=k,w.lightProbe.needsUpdate=k,w.directionalLights.needsUpdate=k,w.directionalLightShadows.needsUpdate=k,w.pointLights.needsUpdate=k,w.pointLightShadows.needsUpdate=k,w.spotLights.needsUpdate=k,w.spotLightShadows.needsUpdate=k,w.rectAreaLights.needsUpdate=k,w.hemisphereLights.needsUpdate=k}function Bp(w){return w.isMeshLambertMaterial||w.isMeshToonMaterial||w.isMeshPhongMaterial||w.isMeshStandardMaterial||w.isShadowMaterial||w.isShaderMaterial&&w.lights===!0}this.getActiveCubeFace=function(){return L},this.getActiveMipmapLevel=function(){return T},this.getRenderTarget=function(){return E},this.setRenderTargetTextures=function(w,k,B){Nt.get(w.texture).__webglTexture=k,Nt.get(w.depthTexture).__webglTexture=B;const H=Nt.get(w);H.__hasExternalTextures=!0,H.__autoAllocateDepthBuffer=B===void 0,H.__autoAllocateDepthBuffer||Ct.has("WEBGL_multisampled_render_to_texture")===!0&&(console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"),H.__useRenderToTexture=!1)},this.setRenderTargetFramebuffer=function(w,k){const B=Nt.get(w);B.__webglFramebuffer=k,B.__useDefaultFramebuffer=k===void 0},this.setRenderTarget=function(w,k=0,B=0){E=w,L=k,T=B;let H=!0,N=null,st=!1,vt=!1;if(w){const Et=Nt.get(w);if(Et.__useDefaultFramebuffer!==void 0)Dt.bindFramebuffer(A.FRAMEBUFFER,null),H=!1;else if(Et.__webglFramebuffer===void 0)C.setupRenderTarget(w);else if(Et.__hasExternalTextures)C.rebindTextures(w,Nt.get(w.texture).__webglTexture,Nt.get(w.depthTexture).__webglTexture);else if(w.depthBuffer){const Rt=w.depthTexture;if(Et.__boundDepthTexture!==Rt){if(Rt!==null&&Nt.has(Rt)&&(w.width!==Rt.image.width||w.height!==Rt.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");C.setupDepthRenderbuffer(w)}}const Ft=w.texture;(Ft.isData3DTexture||Ft.isDataArrayTexture||Ft.isCompressedArrayTexture)&&(vt=!0);const Ht=Nt.get(w).__webglFramebuffer;w.isWebGLCubeRenderTarget?(Array.isArray(Ht[k])?N=Ht[k][B]:N=Ht[k],st=!0):w.samples>0&&C.useMultisampledRTT(w)===!1?N=Nt.get(w).__webglMultisampledFramebuffer:Array.isArray(Ht)?N=Ht[B]:N=Ht,v.copy(w.viewport),b.copy(w.scissor),I=w.scissorTest}else v.copy(ct).multiplyScalar(Z).floor(),b.copy(_t).multiplyScalar(Z).floor(),I=$t;if(Dt.bindFramebuffer(A.FRAMEBUFFER,N)&&H&&Dt.drawBuffers(w,N),Dt.viewport(v),Dt.scissor(b),Dt.setScissorTest(I),st){const Et=Nt.get(w.texture);A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_CUBE_MAP_POSITIVE_X+k,Et.__webglTexture,B)}else if(vt){const Et=Nt.get(w.texture),Ft=k||0;A.framebufferTextureLayer(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,Et.__webglTexture,B||0,Ft)}P=-1},this.readRenderTargetPixels=function(w,k,B,H,N,st,vt){if(!(w&&w.isWebGLRenderTarget)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let bt=Nt.get(w).__webglFramebuffer;if(w.isWebGLCubeRenderTarget&&vt!==void 0&&(bt=bt[vt]),bt){Dt.bindFramebuffer(A.FRAMEBUFFER,bt);try{const Et=w.texture,Ft=Et.format,Ht=Et.type;if(!Bt.textureFormatReadable(Ft)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!Bt.textureTypeReadable(Ht)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}k>=0&&k<=w.width-H&&B>=0&&B<=w.height-N&&A.readPixels(k,B,H,N,Vt.convert(Ft),Vt.convert(Ht),st)}finally{const Et=E!==null?Nt.get(E).__webglFramebuffer:null;Dt.bindFramebuffer(A.FRAMEBUFFER,Et)}}},this.readRenderTargetPixelsAsync=async function(w,k,B,H,N,st,vt){if(!(w&&w.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let bt=Nt.get(w).__webglFramebuffer;if(w.isWebGLCubeRenderTarget&&vt!==void 0&&(bt=bt[vt]),bt){const Et=w.texture,Ft=Et.format,Ht=Et.type;if(!Bt.textureFormatReadable(Ft))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!Bt.textureTypeReadable(Ht))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");if(k>=0&&k<=w.width-H&&B>=0&&B<=w.height-N){Dt.bindFramebuffer(A.FRAMEBUFFER,bt);const Rt=A.createBuffer();A.bindBuffer(A.PIXEL_PACK_BUFFER,Rt),A.bufferData(A.PIXEL_PACK_BUFFER,st.byteLength,A.STREAM_READ),A.readPixels(k,B,H,N,Vt.convert(Ft),Vt.convert(Ht),0);const de=E!==null?Nt.get(E).__webglFramebuffer:null;Dt.bindFramebuffer(A.FRAMEBUFFER,de);const be=A.fenceSync(A.SYNC_GPU_COMMANDS_COMPLETE,0);return A.flush(),await p0(A,be,4),A.bindBuffer(A.PIXEL_PACK_BUFFER,Rt),A.getBufferSubData(A.PIXEL_PACK_BUFFER,0,st),A.deleteBuffer(Rt),A.deleteSync(be),st}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(w,k=null,B=0){w.isTexture!==!0&&(oo("WebGLRenderer: copyFramebufferToTexture function signature has changed."),k=arguments[0]||null,w=arguments[1]);const H=Math.pow(2,-B),N=Math.floor(w.image.width*H),st=Math.floor(w.image.height*H),vt=k!==null?k.x:0,bt=k!==null?k.y:0;C.setTexture2D(w,0),A.copyTexSubImage2D(A.TEXTURE_2D,B,0,0,vt,bt,N,st),Dt.unbindTexture()},this.copyTextureToTexture=function(w,k,B=null,H=null,N=0){w.isTexture!==!0&&(oo("WebGLRenderer: copyTextureToTexture function signature has changed."),H=arguments[0]||null,w=arguments[1],k=arguments[2],N=arguments[3]||0,B=null);let st,vt,bt,Et,Ft,Ht;B!==null?(st=B.max.x-B.min.x,vt=B.max.y-B.min.y,bt=B.min.x,Et=B.min.y):(st=w.image.width,vt=w.image.height,bt=0,Et=0),H!==null?(Ft=H.x,Ht=H.y):(Ft=0,Ht=0);const Rt=Vt.convert(k.format),de=Vt.convert(k.type);C.setTexture2D(k,0),A.pixelStorei(A.UNPACK_FLIP_Y_WEBGL,k.flipY),A.pixelStorei(A.UNPACK_PREMULTIPLY_ALPHA_WEBGL,k.premultiplyAlpha),A.pixelStorei(A.UNPACK_ALIGNMENT,k.unpackAlignment);const be=A.getParameter(A.UNPACK_ROW_LENGTH),Re=A.getParameter(A.UNPACK_IMAGE_HEIGHT),bn=A.getParameter(A.UNPACK_SKIP_PIXELS),le=A.getParameter(A.UNPACK_SKIP_ROWS),Lt=A.getParameter(A.UNPACK_SKIP_IMAGES),je=w.isCompressedTexture?w.mipmaps[N]:w.image;A.pixelStorei(A.UNPACK_ROW_LENGTH,je.width),A.pixelStorei(A.UNPACK_IMAGE_HEIGHT,je.height),A.pixelStorei(A.UNPACK_SKIP_PIXELS,bt),A.pixelStorei(A.UNPACK_SKIP_ROWS,Et),w.isDataTexture?A.texSubImage2D(A.TEXTURE_2D,N,Ft,Ht,st,vt,Rt,de,je.data):w.isCompressedTexture?A.compressedTexSubImage2D(A.TEXTURE_2D,N,Ft,Ht,je.width,je.height,Rt,je.data):A.texSubImage2D(A.TEXTURE_2D,N,Ft,Ht,st,vt,Rt,de,je),A.pixelStorei(A.UNPACK_ROW_LENGTH,be),A.pixelStorei(A.UNPACK_IMAGE_HEIGHT,Re),A.pixelStorei(A.UNPACK_SKIP_PIXELS,bn),A.pixelStorei(A.UNPACK_SKIP_ROWS,le),A.pixelStorei(A.UNPACK_SKIP_IMAGES,Lt),N===0&&k.generateMipmaps&&A.generateMipmap(A.TEXTURE_2D),Dt.unbindTexture()},this.copyTextureToTexture3D=function(w,k,B=null,H=null,N=0){w.isTexture!==!0&&(oo("WebGLRenderer: copyTextureToTexture3D function signature has changed."),B=arguments[0]||null,H=arguments[1]||null,w=arguments[2],k=arguments[3],N=arguments[4]||0);let st,vt,bt,Et,Ft,Ht,Rt,de,be;const Re=w.isCompressedTexture?w.mipmaps[N]:w.image;B!==null?(st=B.max.x-B.min.x,vt=B.max.y-B.min.y,bt=B.max.z-B.min.z,Et=B.min.x,Ft=B.min.y,Ht=B.min.z):(st=Re.width,vt=Re.height,bt=Re.depth,Et=0,Ft=0,Ht=0),H!==null?(Rt=H.x,de=H.y,be=H.z):(Rt=0,de=0,be=0);const bn=Vt.convert(k.format),le=Vt.convert(k.type);let Lt;if(k.isData3DTexture)C.setTexture3D(k,0),Lt=A.TEXTURE_3D;else if(k.isDataArrayTexture||k.isCompressedArrayTexture)C.setTexture2DArray(k,0),Lt=A.TEXTURE_2D_ARRAY;else{console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.");return}A.pixelStorei(A.UNPACK_FLIP_Y_WEBGL,k.flipY),A.pixelStorei(A.UNPACK_PREMULTIPLY_ALPHA_WEBGL,k.premultiplyAlpha),A.pixelStorei(A.UNPACK_ALIGNMENT,k.unpackAlignment);const je=A.getParameter(A.UNPACK_ROW_LENGTH),ce=A.getParameter(A.UNPACK_IMAGE_HEIGHT),Hn=A.getParameter(A.UNPACK_SKIP_PIXELS),ks=A.getParameter(A.UNPACK_SKIP_ROWS),Sn=A.getParameter(A.UNPACK_SKIP_IMAGES);A.pixelStorei(A.UNPACK_ROW_LENGTH,Re.width),A.pixelStorei(A.UNPACK_IMAGE_HEIGHT,Re.height),A.pixelStorei(A.UNPACK_SKIP_PIXELS,Et),A.pixelStorei(A.UNPACK_SKIP_ROWS,Ft),A.pixelStorei(A.UNPACK_SKIP_IMAGES,Ht),w.isDataTexture||w.isData3DTexture?A.texSubImage3D(Lt,N,Rt,de,be,st,vt,bt,bn,le,Re.data):k.isCompressedArrayTexture?A.compressedTexSubImage3D(Lt,N,Rt,de,be,st,vt,bt,bn,Re.data):A.texSubImage3D(Lt,N,Rt,de,be,st,vt,bt,bn,le,Re),A.pixelStorei(A.UNPACK_ROW_LENGTH,je),A.pixelStorei(A.UNPACK_IMAGE_HEIGHT,ce),A.pixelStorei(A.UNPACK_SKIP_PIXELS,Hn),A.pixelStorei(A.UNPACK_SKIP_ROWS,ks),A.pixelStorei(A.UNPACK_SKIP_IMAGES,Sn),N===0&&k.generateMipmaps&&A.generateMipmap(Lt),Dt.unbindTexture()},this.initRenderTarget=function(w){Nt.get(w).__webglFramebuffer===void 0&&C.setupRenderTarget(w)},this.initTexture=function(w){w.isCubeTexture?C.setTextureCube(w,0):w.isData3DTexture?C.setTexture3D(w,0):w.isDataArrayTexture||w.isCompressedArrayTexture?C.setTexture2DArray(w,0):C.setTexture2D(w,0),Dt.unbindTexture()},this.resetState=function(){L=0,T=0,E=null,Dt.reset(),se.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return Ri}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=t===_h?"display-p3":"srgb",e.unpackColorSpace=oe.workingColorSpace===Oo?"display-p3":"srgb"}}class qf extends Qe{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new mi,this.environmentIntensity=1,this.environmentRotation=new mi,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),t.background!==null&&(this.background=t.background.clone()),t.environment!==null&&(this.environment=t.environment.clone()),t.fog!==null&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),t.overrideMaterial!==null&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return this.fog!==null&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class Yf extends an{constructor(t=null,e=1,n=1,s,r,a,o,l,c=rn,h=rn,u,d){super(null,a,o,l,c,h,s,r,u,d),this.isDataTexture=!0,this.image={data:t,width:e,height:n},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class zi extends an{constructor(t,e,n,s,r,a,o,l,c){super(t,e,n,s,r,a,o,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}}class vi{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const n=this.getUtoTmapping(t);return this.getPoint(n,e)}getPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return e}getSpacedPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPointAt(n/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let n,s=this.getPoint(0),r=0;e.push(0);for(let a=1;a<=t;a++)n=this.getPoint(a/t),r+=n.distanceTo(s),e.push(r),s=n;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const n=this.getLengths();let s=0;const r=n.length;let a;e?a=e:a=t*n[r-1];let o=0,l=r-1,c;for(;o<=l;)if(s=Math.floor(o+(l-o)/2),c=n[s]-a,c<0)o=s+1;else if(c>0)l=s-1;else{l=s;break}if(s=l,n[s]===a)return s/(r-1);const h=n[s],d=n[s+1]-h,f=(a-h)/d;return(s+f)/(r-1)}getTangent(t,e){let s=t-1e-4,r=t+1e-4;s<0&&(s=0),r>1&&(r=1);const a=this.getPoint(s),o=this.getPoint(r),l=e||(a.isVector2?new rt:new R);return l.copy(o).sub(a).normalize(),l}getTangentAt(t,e){const n=this.getUtoTmapping(t);return this.getTangent(n,e)}computeFrenetFrames(t,e){const n=new R,s=[],r=[],a=[],o=new R,l=new fe;for(let f=0;f<=t;f++){const g=f/t;s[f]=this.getTangentAt(g,new R)}r[0]=new R,a[0]=new R;let c=Number.MAX_VALUE;const h=Math.abs(s[0].x),u=Math.abs(s[0].y),d=Math.abs(s[0].z);h<=c&&(c=h,n.set(1,0,0)),u<=c&&(c=u,n.set(0,1,0)),d<=c&&n.set(0,0,1),o.crossVectors(s[0],n).normalize(),r[0].crossVectors(s[0],o),a[0].crossVectors(s[0],r[0]);for(let f=1;f<=t;f++){if(r[f]=r[f-1].clone(),a[f]=a[f-1].clone(),o.crossVectors(s[f-1],s[f]),o.length()>Number.EPSILON){o.normalize();const g=Math.acos(ze(s[f-1].dot(s[f]),-1,1));r[f].applyMatrix4(l.makeRotationAxis(o,g))}a[f].crossVectors(s[f],r[f])}if(e===!0){let f=Math.acos(ze(r[0].dot(r[t]),-1,1));f/=t,s[0].dot(o.crossVectors(r[0],r[t]))>0&&(f=-f);for(let g=1;g<=t;g++)r[g].applyMatrix4(l.makeRotationAxis(s[g],f*g)),a[g].crossVectors(s[g],r[g])}return{tangents:s,normals:r,binormals:a}}clone(){return new this.constructor().copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class Ah extends vi{constructor(t=0,e=0,n=1,s=1,r=0,a=Math.PI*2,o=!1,l=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=n,this.yRadius=s,this.aStartAngle=r,this.aEndAngle=a,this.aClockwise=o,this.aRotation=l}getPoint(t,e=new rt){const n=e,s=Math.PI*2;let r=this.aEndAngle-this.aStartAngle;const a=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=s;for(;r>s;)r-=s;r<Number.EPSILON&&(a?r=0:r=s),this.aClockwise===!0&&!a&&(r===s?r=-s:r=r-s);const o=this.aStartAngle+t*r;let l=this.aX+this.xRadius*Math.cos(o),c=this.aY+this.yRadius*Math.sin(o);if(this.aRotation!==0){const h=Math.cos(this.aRotation),u=Math.sin(this.aRotation),d=l-this.aX,f=c-this.aY;l=d*h-f*u+this.aX,c=d*u+f*h+this.aY}return n.set(l,c)}copy(t){return super.copy(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}toJSON(){const t=super.toJSON();return t.aX=this.aX,t.aY=this.aY,t.xRadius=this.xRadius,t.yRadius=this.yRadius,t.aStartAngle=this.aStartAngle,t.aEndAngle=this.aEndAngle,t.aClockwise=this.aClockwise,t.aRotation=this.aRotation,t}fromJSON(t){return super.fromJSON(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}}class Ty extends Ah{constructor(t,e,n,s,r,a){super(t,e,n,n,s,r,a),this.isArcCurve=!0,this.type="ArcCurve"}}function Ch(){let i=0,t=0,e=0,n=0;function s(r,a,o,l){i=r,t=o,e=-3*r+3*a-2*o-l,n=2*r-2*a+o+l}return{initCatmullRom:function(r,a,o,l,c){s(a,o,c*(o-r),c*(l-a))},initNonuniformCatmullRom:function(r,a,o,l,c,h,u){let d=(a-r)/c-(o-r)/(c+h)+(o-a)/h,f=(o-a)/h-(l-a)/(h+u)+(l-o)/u;d*=h,f*=h,s(a,o,d,f)},calc:function(r){const a=r*r,o=a*r;return i+t*r+e*a+n*o}}}const Na=new R,Pl=new Ch,Ll=new Ch,Dl=new Ch;class Ay extends vi{constructor(t=[],e=!1,n="centripetal",s=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=n,this.tension=s}getPoint(t,e=new R){const n=e,s=this.points,r=s.length,a=(r-(this.closed?0:1))*t;let o=Math.floor(a),l=a-o;this.closed?o+=o>0?0:(Math.floor(Math.abs(o)/r)+1)*r:l===0&&o===r-1&&(o=r-2,l=1);let c,h;this.closed||o>0?c=s[(o-1)%r]:(Na.subVectors(s[0],s[1]).add(s[0]),c=Na);const u=s[o%r],d=s[(o+1)%r];if(this.closed||o+2<r?h=s[(o+2)%r]:(Na.subVectors(s[r-1],s[r-2]).add(s[r-1]),h=Na),this.curveType==="centripetal"||this.curveType==="chordal"){const f=this.curveType==="chordal"?.5:.25;let g=Math.pow(c.distanceToSquared(u),f),_=Math.pow(u.distanceToSquared(d),f),m=Math.pow(d.distanceToSquared(h),f);_<1e-4&&(_=1),g<1e-4&&(g=_),m<1e-4&&(m=_),Pl.initNonuniformCatmullRom(c.x,u.x,d.x,h.x,g,_,m),Ll.initNonuniformCatmullRom(c.y,u.y,d.y,h.y,g,_,m),Dl.initNonuniformCatmullRom(c.z,u.z,d.z,h.z,g,_,m)}else this.curveType==="catmullrom"&&(Pl.initCatmullRom(c.x,u.x,d.x,h.x,this.tension),Ll.initCatmullRom(c.y,u.y,d.y,h.y,this.tension),Dl.initCatmullRom(c.z,u.z,d.z,h.z,this.tension));return n.set(Pl.calc(l),Ll.calc(l),Dl.calc(l)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const s=t.points[e];this.points.push(s.clone())}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const s=this.points[e];t.points.push(s.toArray())}return t.closed=this.closed,t.curveType=this.curveType,t.tension=this.tension,t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const s=t.points[e];this.points.push(new R().fromArray(s))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function id(i,t,e,n,s){const r=(n-t)*.5,a=(s-e)*.5,o=i*i,l=i*o;return(2*e-2*n+r+a)*l+(-3*e+3*n-2*r-a)*o+r*i+e}function Cy(i,t){const e=1-i;return e*e*t}function Ry(i,t){return 2*(1-i)*i*t}function Py(i,t){return i*i*t}function Kr(i,t,e,n){return Cy(i,t)+Ry(i,e)+Py(i,n)}function Ly(i,t){const e=1-i;return e*e*e*t}function Dy(i,t){const e=1-i;return 3*e*e*i*t}function Iy(i,t){return 3*(1-i)*i*i*t}function ky(i,t){return i*i*i*t}function Zr(i,t,e,n,s){return Ly(i,t)+Dy(i,e)+Iy(i,n)+ky(i,s)}class Kf extends vi{constructor(t=new rt,e=new rt,n=new rt,s=new rt){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=n,this.v3=s}getPoint(t,e=new rt){const n=e,s=this.v0,r=this.v1,a=this.v2,o=this.v3;return n.set(Zr(t,s.x,r.x,a.x,o.x),Zr(t,s.y,r.y,a.y,o.y)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class Ny extends vi{constructor(t=new R,e=new R,n=new R,s=new R){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=n,this.v3=s}getPoint(t,e=new R){const n=e,s=this.v0,r=this.v1,a=this.v2,o=this.v3;return n.set(Zr(t,s.x,r.x,a.x,o.x),Zr(t,s.y,r.y,a.y,o.y),Zr(t,s.z,r.z,a.z,o.z)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class Zf extends vi{constructor(t=new rt,e=new rt){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new rt){const n=e;return t===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new rt){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Uy extends vi{constructor(t=new R,e=new R){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new R){const n=e;return t===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new R){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Jf extends vi{constructor(t=new rt,e=new rt,n=new rt){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new rt){const n=e,s=this.v0,r=this.v1,a=this.v2;return n.set(Kr(t,s.x,r.x,a.x),Kr(t,s.y,r.y,a.y)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Oy extends vi{constructor(t=new R,e=new R,n=new R){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new R){const n=e,s=this.v0,r=this.v1,a=this.v2;return n.set(Kr(t,s.x,r.x,a.x),Kr(t,s.y,r.y,a.y),Kr(t,s.z,r.z,a.z)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Qf extends vi{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new rt){const n=e,s=this.points,r=(s.length-1)*t,a=Math.floor(r),o=r-a,l=s[a===0?a:a-1],c=s[a],h=s[a>s.length-2?s.length-1:a+1],u=s[a>s.length-3?s.length-1:a+2];return n.set(id(o,l.x,c.x,h.x,u.x),id(o,l.y,c.y,h.y,u.y)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const s=t.points[e];this.points.push(s.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const s=this.points[e];t.points.push(s.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const s=t.points[e];this.points.push(new rt().fromArray(s))}return this}}var sd=Object.freeze({__proto__:null,ArcCurve:Ty,CatmullRomCurve3:Ay,CubicBezierCurve:Kf,CubicBezierCurve3:Ny,EllipseCurve:Ah,LineCurve:Zf,LineCurve3:Uy,QuadraticBezierCurve:Jf,QuadraticBezierCurve3:Oy,SplineCurve:Qf});class Fy extends vi{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(t){this.curves.push(t)}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);if(!t.equals(e)){const n=t.isVector2===!0?"LineCurve":"LineCurve3";this.curves.push(new sd[n](e,t))}return this}getPoint(t,e){const n=t*this.getLength(),s=this.getCurveLengths();let r=0;for(;r<s.length;){if(s[r]>=n){const a=s[r]-n,o=this.curves[r],l=o.getLength(),c=l===0?0:1-a/l;return o.getPointAt(c,e)}r++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let n=0,s=this.curves.length;n<s;n++)e+=this.curves[n].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let n;for(let s=0,r=this.curves;s<r.length;s++){const a=r[s],o=a.isEllipseCurve?t*2:a.isLineCurve||a.isLineCurve3?1:a.isSplineCurve?t*a.points.length:t,l=a.getPoints(o);for(let c=0;c<l.length;c++){const h=l[c];n&&n.equals(h)||(e.push(h),n=h)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const s=t.curves[e];this.curves.push(s.clone())}return this.autoClose=t.autoClose,this}toJSON(){const t=super.toJSON();t.autoClose=this.autoClose,t.curves=[];for(let e=0,n=this.curves.length;e<n;e++){const s=this.curves[e];t.curves.push(s.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.autoClose=t.autoClose,this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const s=t.curves[e];this.curves.push(new sd[s.type]().fromJSON(s))}return this}}class zy extends Fy{constructor(t){super(),this.type="Path",this.currentPoint=new rt,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,n=t.length;e<n;e++)this.lineTo(t[e].x,t[e].y);return this}moveTo(t,e){return this.currentPoint.set(t,e),this}lineTo(t,e){const n=new Zf(this.currentPoint.clone(),new rt(t,e));return this.curves.push(n),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,n,s){const r=new Jf(this.currentPoint.clone(),new rt(t,e),new rt(n,s));return this.curves.push(r),this.currentPoint.set(n,s),this}bezierCurveTo(t,e,n,s,r,a){const o=new Kf(this.currentPoint.clone(),new rt(t,e),new rt(n,s),new rt(r,a));return this.curves.push(o),this.currentPoint.set(r,a),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),n=new Qf(e);return this.curves.push(n),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,n,s,r,a){const o=this.currentPoint.x,l=this.currentPoint.y;return this.absarc(t+o,e+l,n,s,r,a),this}absarc(t,e,n,s,r,a){return this.absellipse(t,e,n,n,s,r,a),this}ellipse(t,e,n,s,r,a,o,l){const c=this.currentPoint.x,h=this.currentPoint.y;return this.absellipse(t+c,e+h,n,s,r,a,o,l),this}absellipse(t,e,n,s,r,a,o,l){const c=new Ah(t,e,n,s,r,a,o,l);if(this.curves.length>0){const u=c.getPoint(0);u.equals(this.currentPoint)||this.lineTo(u.x,u.y)}this.curves.push(c);const h=c.getPoint(1);return this.currentPoint.copy(h),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class zo extends fn{constructor(t=[new rt(0,-.5),new rt(.5,0),new rt(0,.5)],e=12,n=0,s=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:n,phiLength:s},e=Math.floor(e),s=ze(s,0,Math.PI*2);const r=[],a=[],o=[],l=[],c=[],h=1/e,u=new R,d=new rt,f=new R,g=new R,_=new R;let m=0,p=0;for(let y=0;y<=t.length-1;y++)switch(y){case 0:m=t[y+1].x-t[y].x,p=t[y+1].y-t[y].y,f.x=p*1,f.y=-m,f.z=p*0,_.copy(f),f.normalize(),l.push(f.x,f.y,f.z);break;case t.length-1:l.push(_.x,_.y,_.z);break;default:m=t[y+1].x-t[y].x,p=t[y+1].y-t[y].y,f.x=p*1,f.y=-m,f.z=p*0,g.copy(f),f.x+=_.x,f.y+=_.y,f.z+=_.z,f.normalize(),l.push(f.x,f.y,f.z),_.copy(g)}for(let y=0;y<=e;y++){const x=n+y*h*s,S=Math.sin(x),L=Math.cos(x);for(let T=0;T<=t.length-1;T++){u.x=t[T].x*S,u.y=t[T].y,u.z=t[T].x*L,a.push(u.x,u.y,u.z),d.x=y/e,d.y=T/(t.length-1),o.push(d.x,d.y);const E=l[3*T+0]*S,P=l[3*T+1],U=l[3*T+0]*L;c.push(E,P,U)}}for(let y=0;y<e;y++)for(let x=0;x<t.length-1;x++){const S=x+y*t.length,L=S,T=S+t.length,E=S+t.length+1,P=S+1;r.push(L,T,P),r.push(E,P,T)}this.setIndex(r),this.setAttribute("position",new he(a,3)),this.setAttribute("uv",new he(o,2)),this.setAttribute("normal",new he(c,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new zo(t.points,t.segments,t.phiStart,t.phiLength)}}class Rh extends zo{constructor(t=1,e=1,n=4,s=8){const r=new zy;r.absarc(0,-e/2,t,Math.PI*1.5,0),r.absarc(0,e/2,t,0,Math.PI*.5),super(r.getPoints(n),s),this.type="CapsuleGeometry",this.parameters={radius:t,length:e,capSegments:n,radialSegments:s}}static fromJSON(t){return new Rh(t.radius,t.length,t.capSegments,t.radialSegments)}}class Oi extends fn{constructor(t=1,e=32,n=0,s=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:n,thetaLength:s},e=Math.max(3,e);const r=[],a=[],o=[],l=[],c=new R,h=new rt;a.push(0,0,0),o.push(0,0,1),l.push(.5,.5);for(let u=0,d=3;u<=e;u++,d+=3){const f=n+u/e*s;c.x=t*Math.cos(f),c.y=t*Math.sin(f),a.push(c.x,c.y,c.z),o.push(0,0,1),h.x=(a[d]/t+1)/2,h.y=(a[d+1]/t+1)/2,l.push(h.x,h.y)}for(let u=1;u<=e;u++)r.push(u,u+1,0);this.setIndex(r),this.setAttribute("position",new he(a,3)),this.setAttribute("normal",new he(o,3)),this.setAttribute("uv",new he(l,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Oi(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class zn extends fn{constructor(t=1,e=1,n=1,s=32,r=1,a=!1,o=0,l=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:n,radialSegments:s,heightSegments:r,openEnded:a,thetaStart:o,thetaLength:l};const c=this;s=Math.floor(s),r=Math.floor(r);const h=[],u=[],d=[],f=[];let g=0;const _=[],m=n/2;let p=0;y(),a===!1&&(t>0&&x(!0),e>0&&x(!1)),this.setIndex(h),this.setAttribute("position",new he(u,3)),this.setAttribute("normal",new he(d,3)),this.setAttribute("uv",new he(f,2));function y(){const S=new R,L=new R;let T=0;const E=(e-t)/n;for(let P=0;P<=r;P++){const U=[],v=P/r,b=v*(e-t)+t;for(let I=0;I<=s;I++){const O=I/s,$=O*l+o,K=Math.sin($),z=Math.cos($);L.x=b*K,L.y=-v*n+m,L.z=b*z,u.push(L.x,L.y,L.z),S.set(K,E,z).normalize(),d.push(S.x,S.y,S.z),f.push(O,1-v),U.push(g++)}_.push(U)}for(let P=0;P<s;P++)for(let U=0;U<r;U++){const v=_[U][P],b=_[U+1][P],I=_[U+1][P+1],O=_[U][P+1];t>0&&(h.push(v,b,O),T+=3),e>0&&(h.push(b,I,O),T+=3)}c.addGroup(p,T,0),p+=T}function x(S){const L=g,T=new rt,E=new R;let P=0;const U=S===!0?t:e,v=S===!0?1:-1;for(let I=1;I<=s;I++)u.push(0,m*v,0),d.push(0,v,0),f.push(.5,.5),g++;const b=g;for(let I=0;I<=s;I++){const $=I/s*l+o,K=Math.cos($),z=Math.sin($);E.x=U*z,E.y=m*v,E.z=U*K,u.push(E.x,E.y,E.z),d.push(0,v,0),T.x=K*.5+.5,T.y=z*.5*v+.5,f.push(T.x,T.y),g++}for(let I=0;I<s;I++){const O=L+I,$=b+I;S===!0?h.push($,$+1,O):h.push($+1,$,O),P+=3}c.addGroup(p,P,S===!0?1:2),p+=P}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new zn(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class ca extends zn{constructor(t=1,e=1,n=32,s=1,r=!1,a=0,o=Math.PI*2){super(0,t,e,n,s,r,a,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:n,heightSegments:s,openEnded:r,thetaStart:a,thetaLength:o}}static fromJSON(t){return new ca(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Ph extends fn{constructor(t=[],e=[],n=1,s=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:n,detail:s};const r=[],a=[];o(s),c(n),h(),this.setAttribute("position",new he(r,3)),this.setAttribute("normal",new he(r.slice(),3)),this.setAttribute("uv",new he(a,2)),s===0?this.computeVertexNormals():this.normalizeNormals();function o(y){const x=new R,S=new R,L=new R;for(let T=0;T<e.length;T+=3)f(e[T+0],x),f(e[T+1],S),f(e[T+2],L),l(x,S,L,y)}function l(y,x,S,L){const T=L+1,E=[];for(let P=0;P<=T;P++){E[P]=[];const U=y.clone().lerp(S,P/T),v=x.clone().lerp(S,P/T),b=T-P;for(let I=0;I<=b;I++)I===0&&P===T?E[P][I]=U:E[P][I]=U.clone().lerp(v,I/b)}for(let P=0;P<T;P++)for(let U=0;U<2*(T-P)-1;U++){const v=Math.floor(U/2);U%2===0?(d(E[P][v+1]),d(E[P+1][v]),d(E[P][v])):(d(E[P][v+1]),d(E[P+1][v+1]),d(E[P+1][v]))}}function c(y){const x=new R;for(let S=0;S<r.length;S+=3)x.x=r[S+0],x.y=r[S+1],x.z=r[S+2],x.normalize().multiplyScalar(y),r[S+0]=x.x,r[S+1]=x.y,r[S+2]=x.z}function h(){const y=new R;for(let x=0;x<r.length;x+=3){y.x=r[x+0],y.y=r[x+1],y.z=r[x+2];const S=m(y)/2/Math.PI+.5,L=p(y)/Math.PI+.5;a.push(S,1-L)}g(),u()}function u(){for(let y=0;y<a.length;y+=6){const x=a[y+0],S=a[y+2],L=a[y+4],T=Math.max(x,S,L),E=Math.min(x,S,L);T>.9&&E<.1&&(x<.2&&(a[y+0]+=1),S<.2&&(a[y+2]+=1),L<.2&&(a[y+4]+=1))}}function d(y){r.push(y.x,y.y,y.z)}function f(y,x){const S=y*3;x.x=t[S+0],x.y=t[S+1],x.z=t[S+2]}function g(){const y=new R,x=new R,S=new R,L=new R,T=new rt,E=new rt,P=new rt;for(let U=0,v=0;U<r.length;U+=9,v+=6){y.set(r[U+0],r[U+1],r[U+2]),x.set(r[U+3],r[U+4],r[U+5]),S.set(r[U+6],r[U+7],r[U+8]),T.set(a[v+0],a[v+1]),E.set(a[v+2],a[v+3]),P.set(a[v+4],a[v+5]),L.copy(y).add(x).add(S).divideScalar(3);const b=m(L);_(T,v+0,y,b),_(E,v+2,x,b),_(P,v+4,S,b)}}function _(y,x,S,L){L<0&&y.x===1&&(a[x]=y.x-1),S.x===0&&S.z===0&&(a[x]=L/2/Math.PI+.5)}function m(y){return Math.atan2(y.z,-y.x)}function p(y){return Math.atan2(-y.y,Math.sqrt(y.x*y.x+y.z*y.z))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ph(t.vertices,t.indices,t.radius,t.details)}}class Sr extends Ph{constructor(t=1,e=0){const n=(1+Math.sqrt(5))/2,s=[-1,n,0,1,n,0,-1,-n,0,1,-n,0,0,-1,n,0,1,n,0,-1,-n,0,1,-n,n,0,-1,n,0,1,-n,0,-1,-n,0,1],r=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1];super(s,r,t,e),this.type="IcosahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new Sr(t.radius,t.detail)}}class Lh extends fn{constructor(t=.5,e=1,n=32,s=1,r=0,a=Math.PI*2){super(),this.type="RingGeometry",this.parameters={innerRadius:t,outerRadius:e,thetaSegments:n,phiSegments:s,thetaStart:r,thetaLength:a},n=Math.max(3,n),s=Math.max(1,s);const o=[],l=[],c=[],h=[];let u=t;const d=(e-t)/s,f=new R,g=new rt;for(let _=0;_<=s;_++){for(let m=0;m<=n;m++){const p=r+m/n*a;f.x=u*Math.cos(p),f.y=u*Math.sin(p),l.push(f.x,f.y,f.z),c.push(0,0,1),g.x=(f.x/e+1)/2,g.y=(f.y/e+1)/2,h.push(g.x,g.y)}u+=d}for(let _=0;_<s;_++){const m=_*(n+1);for(let p=0;p<n;p++){const y=p+m,x=y,S=y+n+1,L=y+n+2,T=y+1;o.push(x,S,T),o.push(S,L,T)}}this.setIndex(o),this.setAttribute("position",new he(l,3)),this.setAttribute("normal",new he(c,3)),this.setAttribute("uv",new he(h,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Lh(t.innerRadius,t.outerRadius,t.thetaSegments,t.phiSegments,t.thetaStart,t.thetaLength)}}class di extends fn{constructor(t=1,e=32,n=16,s=0,r=Math.PI*2,a=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:n,phiStart:s,phiLength:r,thetaStart:a,thetaLength:o},e=Math.max(3,Math.floor(e)),n=Math.max(2,Math.floor(n));const l=Math.min(a+o,Math.PI);let c=0;const h=[],u=new R,d=new R,f=[],g=[],_=[],m=[];for(let p=0;p<=n;p++){const y=[],x=p/n;let S=0;p===0&&a===0?S=.5/e:p===n&&l===Math.PI&&(S=-.5/e);for(let L=0;L<=e;L++){const T=L/e;u.x=-t*Math.cos(s+T*r)*Math.sin(a+x*o),u.y=t*Math.cos(a+x*o),u.z=t*Math.sin(s+T*r)*Math.sin(a+x*o),g.push(u.x,u.y,u.z),d.copy(u).normalize(),_.push(d.x,d.y,d.z),m.push(T+S,1-x),y.push(c++)}h.push(y)}for(let p=0;p<n;p++)for(let y=0;y<e;y++){const x=h[p][y+1],S=h[p][y],L=h[p+1][y],T=h[p+1][y+1];(p!==0||a>0)&&f.push(x,S,T),(p!==n-1||l<Math.PI)&&f.push(S,L,T)}this.setIndex(f),this.setAttribute("position",new he(g,3)),this.setAttribute("normal",new he(_,3)),this.setAttribute("uv",new he(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new di(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class oi extends fn{constructor(t=1,e=.4,n=12,s=48,r=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:n,tubularSegments:s,arc:r},n=Math.floor(n),s=Math.floor(s);const a=[],o=[],l=[],c=[],h=new R,u=new R,d=new R;for(let f=0;f<=n;f++)for(let g=0;g<=s;g++){const _=g/s*r,m=f/n*Math.PI*2;u.x=(t+e*Math.cos(m))*Math.cos(_),u.y=(t+e*Math.cos(m))*Math.sin(_),u.z=e*Math.sin(m),o.push(u.x,u.y,u.z),h.x=t*Math.cos(_),h.y=t*Math.sin(_),d.subVectors(u,h).normalize(),l.push(d.x,d.y,d.z),c.push(g/s),c.push(f/n)}for(let f=1;f<=n;f++)for(let g=1;g<=s;g++){const _=(s+1)*f+g-1,m=(s+1)*(f-1)+g-1,p=(s+1)*(f-1)+g,y=(s+1)*f+g;a.push(_,m,y),a.push(m,p,y)}this.setIndex(a),this.setAttribute("position",new he(o,3)),this.setAttribute("normal",new he(l,3)),this.setAttribute("uv",new he(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new oi(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class By extends Fi{constructor(t){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new Zt(0),this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.fog=t.fog,this}}class Hy extends nn{constructor(t){super(t),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class Bn extends Fi{constructor(t){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new Zt(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Zt(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=vh,this.normalScale=new rt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new mi,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.envMapIntensity=t.envMapIntensity,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Vy extends Fi{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=vh,this.normalScale=new rt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class Dh extends Qe{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new Zt(t),this.intensity=e}dispose(){}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,this.groundColor!==void 0&&(e.object.groundColor=this.groundColor.getHex()),this.distance!==void 0&&(e.object.distance=this.distance),this.angle!==void 0&&(e.object.angle=this.angle),this.decay!==void 0&&(e.object.decay=this.decay),this.penumbra!==void 0&&(e.object.penumbra=this.penumbra),this.shadow!==void 0&&(e.object.shadow=this.shadow.toJSON()),this.target!==void 0&&(e.object.target=this.target.uuid),e}}class Gy extends Dh{constructor(t,e,n){super(t,n),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Qe.DEFAULT_UP),this.updateMatrix(),this.groundColor=new Zt(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}}const Il=new fe,rd=new R,ad=new R;class tp{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new rt(512,512),this.map=null,this.mapPass=null,this.matrix=new fe,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Sh,this._frameExtents=new rt(1,1),this._viewportCount=1,this._viewports=[new me(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,n=this.matrix;rd.setFromMatrixPosition(t.matrixWorld),e.position.copy(rd),ad.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(ad),e.updateMatrixWorld(),Il.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Il),n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Il)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.intensity=t.intensity,this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return new this.constructor().copy(this)}toJSON(){const t={};return this.intensity!==1&&(t.intensity=this.intensity),this.bias!==0&&(t.bias=this.bias),this.normalBias!==0&&(t.normalBias=this.normalBias),this.radius!==1&&(t.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}const od=new fe,kr=new R,kl=new R;class $y extends tp{constructor(){super(new Cn(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new rt(4,2),this._viewportCount=6,this._viewports=[new me(2,1,1,1),new me(0,1,1,1),new me(3,1,1,1),new me(1,1,1,1),new me(3,0,1,1),new me(1,0,1,1)],this._cubeDirections=[new R(1,0,0),new R(-1,0,0),new R(0,0,1),new R(0,0,-1),new R(0,1,0),new R(0,-1,0)],this._cubeUps=[new R(0,1,0),new R(0,1,0),new R(0,1,0),new R(0,1,0),new R(0,0,1),new R(0,0,-1)]}updateMatrices(t,e=0){const n=this.camera,s=this.matrix,r=t.distance||n.far;r!==n.far&&(n.far=r,n.updateProjectionMatrix()),kr.setFromMatrixPosition(t.matrixWorld),n.position.copy(kr),kl.copy(n.position),kl.add(this._cubeDirections[e]),n.up.copy(this._cubeUps[e]),n.lookAt(kl),n.updateMatrixWorld(),s.makeTranslation(-kr.x,-kr.y,-kr.z),od.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse),this._frustum.setFromProjectionMatrix(od)}}class Wy extends Dh{constructor(t,e,n=0,s=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=n,this.decay=s,this.shadow=new $y}get power(){return this.intensity*4*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}}class Xy extends tp{constructor(){super(new wh(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class jy extends Dh{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Qe.DEFAULT_UP),this.updateMatrix(),this.target=new Qe,this.shadow=new Xy}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class ep{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=ld(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=ld();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function ld(){return performance.now()}const cd=new fe;class np{constructor(t,e,n=0,s=1/0){this.ray=new Mh(t,e),this.near=n,this.far=s,this.camera=null,this.layers=new bh,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e.isOrthographicCamera?(this.ray.origin.set(t.x,t.y,(e.near+e.far)/(e.near-e.far)).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e):console.error("THREE.Raycaster: Unsupported camera type: "+e.type)}setFromXRController(t){return cd.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(cd),this}intersectObject(t,e=!0,n=[]){return Yc(t,this,n,e),n.sort(hd),n}intersectObjects(t,e=!0,n=[]){for(let s=0,r=t.length;s<r;s++)Yc(t[s],this,n,e);return n.sort(hd),n}}function hd(i,t){return i.distance-t.distance}function Yc(i,t,e,n){let s=!0;if(i.layers.test(t.layers)&&i.raycast(t,e)===!1&&(s=!1),s===!0&&n===!0){const r=i.children;for(let a=0,o=r.length;a<o;a++)Yc(r[a],t,e,!0)}}class wr{constructor(t=1,e=0,n=0){return this.radius=t,this.phi=e,this.theta=n,this}set(t,e,n){return this.radius=t,this.phi=e,this.theta=n,this}copy(t){return this.radius=t.radius,this.phi=t.phi,this.theta=t.theta,this}makeSafe(){return this.phi=Math.max(1e-6,Math.min(Math.PI-1e-6,this.phi)),this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,n){return this.radius=Math.sqrt(t*t+e*e+n*n),this.radius===0?(this.theta=0,this.phi=0):(this.theta=Math.atan2(t,n),this.phi=Math.acos(ze(e/this.radius,-1,1))),this}clone(){return new this.constructor().copy(this)}}class qy extends Ps{constructor(t,e=null){super(),this.object=t,this.domElement=e,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(){}disconnect(){}dispose(){}update(){}}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:ch}}));typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=ch);const ud={type:"change"},Ih={type:"start"},ip={type:"end"},Ua=new Mh,dd=new Ki,Yy=Math.cos(70*xs.DEG2RAD),Oe=new R,gn=2*Math.PI,pe={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},Nl=1e-6;class Ky extends qy{constructor(t,e=null){super(t,e),this.state=pe.NONE,this.enabled=!0,this.target=new R,this.cursor=new R,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.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:Di.ROTATE,MIDDLE:Di.DOLLY,RIGHT:Di.PAN},this.touches={ONE:is.ROTATE,TWO:is.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new R,this._lastQuaternion=new ls,this._lastTargetPosition=new R,this._quat=new ls().setFromUnitVectors(t.up,new R(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new wr,this._sphericalDelta=new wr,this._scale=1,this._panOffset=new R,this._rotateStart=new rt,this._rotateEnd=new rt,this._rotateDelta=new rt,this._panStart=new rt,this._panEnd=new rt,this._panDelta=new rt,this._dollyStart=new rt,this._dollyEnd=new rt,this._dollyDelta=new rt,this._dollyDirection=new R,this._mouse=new rt,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Jy.bind(this),this._onPointerDown=Zy.bind(this),this._onPointerUp=Qy.bind(this),this._onContextMenu=aM.bind(this),this._onMouseWheel=nM.bind(this),this._onKeyDown=iM.bind(this),this._onTouchStart=sM.bind(this),this._onTouchMove=rM.bind(this),this._onMouseDown=tM.bind(this),this._onMouseMove=eM.bind(this),this._interceptControlDown=oM.bind(this),this._interceptControlUp=lM.bind(this),this.domElement!==null&&this.connect(),this.update()}connect(){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.removeEventListener("pointermove",this._onPointerMove),this.domElement.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(t){t.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=t}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(ud),this.update(),this.state=pe.NONE}update(t=null){const e=this.object.position;Oe.copy(e).sub(this.target),Oe.applyQuaternion(this._quat),this._spherical.setFromVector3(Oe),this.autoRotate&&this.state===pe.NONE&&this._rotateLeft(this._getAutoRotationAngle(t)),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 n=this.minAzimuthAngle,s=this.maxAzimuthAngle;isFinite(n)&&isFinite(s)&&(n<-Math.PI?n+=gn:n>Math.PI&&(n-=gn),s<-Math.PI?s+=gn:s>Math.PI&&(s-=gn),n<=s?this._spherical.theta=Math.max(n,Math.min(s,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+s)/2?Math.max(n,this._spherical.theta):Math.min(s,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 r=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const a=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),r=a!=this._spherical.radius}if(Oe.setFromSpherical(this._spherical),Oe.applyQuaternion(this._quatInverse),e.copy(this.target).add(Oe),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 a=null;if(this.object.isPerspectiveCamera){const o=Oe.length();a=this._clampDistance(o*this._scale);const l=o-a;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),r=!!l}else if(this.object.isOrthographicCamera){const o=new R(this._mouse.x,this._mouse.y,0);o.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),r=l!==this.object.zoom;const c=new R(this._mouse.x,this._mouse.y,0);c.unproject(this.object),this.object.position.sub(c).add(o),this.object.updateMatrixWorld(),a=Oe.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;a!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(a).add(this.object.position):(Ua.origin.copy(this.object.position),Ua.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Ua.direction))<Yy?this.object.lookAt(this.target):(dd.setFromNormalAndCoplanarPoint(this.object.up,this.target),Ua.intersectPlane(dd,this.target))))}else if(this.object.isOrthographicCamera){const a=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),a!==this.object.zoom&&(this.object.updateProjectionMatrix(),r=!0)}return this._scale=1,this._performCursorZoom=!1,r||this._lastPosition.distanceToSquared(this.object.position)>Nl||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Nl||this._lastTargetPosition.distanceToSquared(this.target)>Nl?(this.dispatchEvent(ud),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(t){return t!==null?gn/60*this.autoRotateSpeed*t:gn/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(t*.01);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){Oe.setFromMatrixColumn(e,0),Oe.multiplyScalar(-t),this._panOffset.add(Oe)}_panUp(t,e){this.screenSpacePanning===!0?Oe.setFromMatrixColumn(e,1):(Oe.setFromMatrixColumn(e,0),Oe.crossVectors(this.object.up,Oe)),Oe.multiplyScalar(t),this._panOffset.add(Oe)}_pan(t,e){const n=this.domElement;if(this.object.isPerspectiveCamera){const s=this.object.position;Oe.copy(s).sub(this.target);let r=Oe.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*r/n.clientHeight,this.object.matrix),this._panUp(2*e*r/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),s=t-n.left,r=e-n.top,a=n.width,o=n.height;this._mouse.x=s/a*2-1,this._mouse.y=-(r/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(gn*this._rotateDelta.x/e.clientHeight),this._rotateUp(gn*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.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(t){this._panEnd.set(t.clientX,t.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(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateUp(gn*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateUp(-gn*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateLeft(gn*this.rotateSpeed/this.domElement.clientHeight):this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateLeft(-gn*this.rotateSpeed/this.domElement.clientHeight):this._pan(-this.keyPanSpeed,0),e=!0;break}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(this._pointers.length===1)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),s=.5*(t.pageY+e.y);this._rotateStart.set(n,s)}}_handleTouchStartPan(t){if(this._pointers.length===1)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),s=.5*(t.pageY+e.y);this._panStart.set(n,s)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,s=t.pageY-e.y,r=Math.sqrt(n*n+s*s);this._dollyStart.set(0,r)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(this._pointers.length==1)this._rotateEnd.set(t.pageX,t.pageY);else{const n=this._getSecondPointerPosition(t),s=.5*(t.pageX+n.x),r=.5*(t.pageY+n.y);this._rotateEnd.set(s,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(gn*this._rotateDelta.x/e.clientHeight),this._rotateUp(gn*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(this._pointers.length===1)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),s=.5*(t.pageY+e.y);this._panEnd.set(n,s)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,s=t.pageY-e.y,r=Math.sqrt(n*n+s*s);this._dollyEnd.set(0,r),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 a=(t.pageX+e.x)*.5,o=(t.pageY+e.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId){this._pointers.splice(e,1);return}}_isTrackingPointer(t){for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return!0;return!1}_trackPointer(t){let e=this._pointerPositions[t.pointerId];e===void 0&&(e=new rt,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[e]}_customWheelEvent(t){const e=t.deltaMode,n={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(e){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return t.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function Zy(i){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(i.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(i)&&(this._addPointer(i),i.pointerType==="touch"?this._onTouchStart(i):this._onMouseDown(i)))}function Jy(i){this.enabled!==!1&&(i.pointerType==="touch"?this._onTouchMove(i):this._onMouseMove(i))}function Qy(i){switch(this._removePointer(i),this._pointers.length){case 0:this.domElement.releasePointerCapture(i.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(ip),this.state=pe.NONE;break;case 1:const t=this._pointers[0],e=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:e.x,pageY:e.y});break}}function tM(i){let t;switch(i.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=-1}switch(t){case Di.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(i),this.state=pe.DOLLY;break;case Di.ROTATE:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=pe.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=pe.ROTATE}break;case Di.PAN:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=pe.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=pe.PAN}break;default:this.state=pe.NONE}this.state!==pe.NONE&&this.dispatchEvent(Ih)}function eM(i){switch(this.state){case pe.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(i);break;case pe.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(i);break;case pe.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(i);break}}function nM(i){this.enabled===!1||this.enableZoom===!1||this.state!==pe.NONE||(i.preventDefault(),this.dispatchEvent(Ih),this._handleMouseWheel(this._customWheelEvent(i)),this.dispatchEvent(ip))}function iM(i){this.enabled===!1||this.enablePan===!1||this._handleKeyDown(i)}function sM(i){switch(this._trackPointer(i),this._pointers.length){case 1:switch(this.touches.ONE){case is.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(i),this.state=pe.TOUCH_ROTATE;break;case is.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(i),this.state=pe.TOUCH_PAN;break;default:this.state=pe.NONE}break;case 2:switch(this.touches.TWO){case is.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(i),this.state=pe.TOUCH_DOLLY_PAN;break;case is.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(i),this.state=pe.TOUCH_DOLLY_ROTATE;break;default:this.state=pe.NONE}break;default:this.state=pe.NONE}this.state!==pe.NONE&&this.dispatchEvent(Ih)}function rM(i){switch(this._trackPointer(i),this.state){case pe.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(i),this.update();break;case pe.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(i),this.update();break;case pe.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(i),this.update();break;case pe.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(i),this.update();break;default:this.state=pe.NONE}}function aM(i){this.enabled!==!1&&i.preventDefault()}function oM(i){i.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function lM(i){i.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}class cM extends Ky{constructor(t,e){super(t,e),this.screenSpacePanning=!1,this.mouseButtons={LEFT:Di.PAN,MIDDLE:Di.DOLLY,RIGHT:Di.ROTATE},this.touches={ONE:is.PAN,TWO:is.DOLLY_ROTATE}}}class hM extends qf{constructor(){super();const t=new Ze;t.deleteAttribute("uv");const e=new Bn({side:un}),n=new Bn,s=new Wy(16777215,900,28,2);s.position.set(.418,16.199,.3),this.add(s);const r=new yt(t,e);r.position.set(-.757,13.219,.717),r.scale.set(31.713,28.305,28.591),this.add(r);const a=new yt(t,n);a.position.set(-10.906,2.009,1.846),a.rotation.set(0,-.195,0),a.scale.set(2.328,7.905,4.651),this.add(a);const o=new yt(t,n);o.position.set(-5.607,-.754,-.758),o.rotation.set(0,.994,0),o.scale.set(1.97,1.534,3.955),this.add(o);const l=new yt(t,n);l.position.set(6.167,.857,7.803),l.rotation.set(0,.561,0),l.scale.set(3.927,6.285,3.687),this.add(l);const c=new yt(t,n);c.position.set(-2.017,.018,6.124),c.rotation.set(0,.333,0),c.scale.set(2.002,4.566,2.064),this.add(c);const h=new yt(t,n);h.position.set(2.291,-.756,-2.621),h.rotation.set(0,-.286,0),h.scale.set(1.546,1.552,1.496),this.add(h);const u=new yt(t,n);u.position.set(-2.193,-.369,-5.547),u.rotation.set(0,.516,0),u.scale.set(3.875,3.487,2.986),this.add(u);const d=new yt(t,Ks(50));d.position.set(-16.116,14.37,8.208),d.scale.set(.1,2.428,2.739),this.add(d);const f=new yt(t,Ks(50));f.position.set(-16.109,18.021,-8.207),f.scale.set(.1,2.425,2.751),this.add(f);const g=new yt(t,Ks(17));g.position.set(14.904,12.198,-1.832),g.scale.set(.15,4.265,6.331),this.add(g);const _=new yt(t,Ks(43));_.position.set(-.462,8.89,14.52),_.scale.set(4.38,5.441,.088),this.add(_);const m=new yt(t,Ks(20));m.position.set(3.235,11.486,-12.541),m.scale.set(2.5,2,.1),this.add(m);const p=new yt(t,Ks(100));p.position.set(0,20,0),p.scale.set(1,.1,1),this.add(p)}dispose(){const t=new Set;this.traverse(e=>{e.isMesh&&(t.add(e.geometry),t.add(e.material))});for(const e of t)e.dispose()}}function Ks(i){const t=new dn;return t.color.setScalar(i),t}const co={name:"CopyShader",uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:`
3841
3841
 
3842
3842
  varying vec2 vUv;
3843
3843
 
@@ -3860,7 +3860,7 @@ void main() {
3860
3860
  gl_FragColor = opacity * texel;
3861
3861
 
3862
3862
 
3863
- }`};class xr{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error("THREE.Pass: .render() must be implemented in derived pass.")}dispose(){}}const Oy=new lh(-1,1,1,-1,0,1);class Fy extends cn{constructor(){super(),this.setAttribute("position",new he([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new he([0,2,0,0,2,0],2))}}const zy=new Fy;class _h{constructor(t){this._mesh=new yt(zy,t)}dispose(){this._mesh.geometry.dispose()}render(t){t.render(this._mesh,Oy)}get material(){return this._mesh.material}set material(t){this._mesh.material=t}}class By extends xr{constructor(t,e){super(),this.textureID=e!==void 0?e:"tDiffuse",t instanceof Je?(this.uniforms=t.uniforms,this.material=t):t&&(this.uniforms=ji.clone(t.uniforms),this.material=new Je({name:t.name!==void 0?t.name:"unspecified",defines:Object.assign({},t.defines),uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader})),this.fsQuad=new _h(this.material)}render(t,e,n){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=n.texture),this.fsQuad.material=this.material,this.renderToScreen?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),this.fsQuad.render(t))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}class qu extends xr{constructor(t,e){super(),this.scene=t,this.camera=e,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(t,e,n){const s=t.getContext(),r=t.state;r.buffers.color.setMask(!1),r.buffers.depth.setMask(!1),r.buffers.color.setLocked(!0),r.buffers.depth.setLocked(!0);let a,o;this.inverse?(a=0,o=1):(a=1,o=0),r.buffers.stencil.setTest(!0),r.buffers.stencil.setOp(s.REPLACE,s.REPLACE,s.REPLACE),r.buffers.stencil.setFunc(s.ALWAYS,a,4294967295),r.buffers.stencil.setClear(o),r.buffers.stencil.setLocked(!0),t.setRenderTarget(n),this.clear&&t.clear(),t.render(this.scene,this.camera),t.setRenderTarget(e),this.clear&&t.clear(),t.render(this.scene,this.camera),r.buffers.color.setLocked(!1),r.buffers.depth.setLocked(!1),r.buffers.color.setMask(!0),r.buffers.depth.setMask(!0),r.buffers.stencil.setLocked(!1),r.buffers.stencil.setFunc(s.EQUAL,1,4294967295),r.buffers.stencil.setOp(s.KEEP,s.KEEP,s.KEEP),r.buffers.stencil.setLocked(!0)}}class Hy extends xr{constructor(){super(),this.needsSwap=!1}render(t){t.state.buffers.stencil.setLocked(!1),t.state.buffers.stencil.setTest(!1)}}class Vy{constructor(t,e){if(this.renderer=t,this._pixelRatio=t.getPixelRatio(),e===void 0){const n=t.getSize(new rt);this._width=n.width,this._height=n.height,e=new Yn(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Li}),e.texture.name="EffectComposer.rt1"}else this._width=e.width,this._height=e.height;this.renderTarget1=e,this.renderTarget2=e.clone(),this.renderTarget2.texture.name="EffectComposer.rt2",this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],this.copyPass=new By(Qa),this.copyPass.material.blending=Xe,this.clock=new Lf}swapBuffers(){const t=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=t}addPass(t){this.passes.push(t),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(t,e){this.passes.splice(e,0,t),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(t){const e=this.passes.indexOf(t);e!==-1&&this.passes.splice(e,1)}isLastEnabledPass(t){for(let e=t+1;e<this.passes.length;e++)if(this.passes[e].enabled)return!1;return!0}render(t){t===void 0&&(t=this.clock.getDelta());const e=this.renderer.getRenderTarget();let n=!1;for(let s=0,r=this.passes.length;s<r;s++){const a=this.passes[s];if(a.enabled!==!1){if(a.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(s),a.render(this.renderer,this.writeBuffer,this.readBuffer,t,n),a.needsSwap){if(n){const o=this.renderer.getContext(),l=this.renderer.state.buffers.stencil;l.setFunc(o.NOTEQUAL,1,4294967295),this.copyPass.render(this.renderer,this.writeBuffer,this.readBuffer,t),l.setFunc(o.EQUAL,1,4294967295)}this.swapBuffers()}qu!==void 0&&(a instanceof qu?n=!0:a instanceof Hy&&(n=!1))}}this.renderer.setRenderTarget(e)}reset(t){if(t===void 0){const e=this.renderer.getSize(new rt);this._pixelRatio=this.renderer.getPixelRatio(),this._width=e.width,this._height=e.height,t=this.renderTarget1.clone(),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=t,this.renderTarget2=t.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(t,e){this._width=t,this._height=e;const n=this._width*this._pixelRatio,s=this._height*this._pixelRatio;this.renderTarget1.setSize(n,s),this.renderTarget2.setSize(n,s);for(let r=0;r<this.passes.length;r++)this.passes[r].setSize(n,s)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.copyPass.dispose()}}class Gy extends xr{constructor(t,e,n=null,s=null,r=null){super(),this.scene=t,this.camera=e,this.overrideMaterial=n,this.clearColor=s,this.clearAlpha=r,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this._oldClearColor=new Zt}render(t,e,n){const s=t.autoClear;t.autoClear=!1;let r,a;this.overrideMaterial!==null&&(a=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),this.clearColor!==null&&(t.getClearColor(this._oldClearColor),t.setClearColor(this.clearColor,t.getClearAlpha())),this.clearAlpha!==null&&(r=t.getClearAlpha(),t.setClearAlpha(this.clearAlpha)),this.clearDepth==!0&&t.clearDepth(),t.setRenderTarget(this.renderToScreen?null:n),this.clear===!0&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),t.render(this.scene,this.camera),this.clearColor!==null&&t.setClearColor(this._oldClearColor),this.clearAlpha!==null&&t.setClearAlpha(r),this.overrideMaterial!==null&&(this.scene.overrideMaterial=a),t.autoClear=s}}const Ca={defines:{PERSPECTIVE_CAMERA:1,SAMPLES:16,NORMAL_VECTOR_TYPE:1,DEPTH_SWIZZLING:"x",SCREEN_SPACE_RADIUS:0,SCREEN_SPACE_RADIUS_SCALE:100,SCENE_CLIP_BOX:0},uniforms:{tNormal:{value:null},tDepth:{value:null},tNoise:{value:null},resolution:{value:new rt},cameraNear:{value:null},cameraFar:{value:null},cameraProjectionMatrix:{value:new fe},cameraProjectionMatrixInverse:{value:new fe},cameraWorldMatrix:{value:new fe},radius:{value:.25},distanceExponent:{value:1},thickness:{value:1},distanceFallOff:{value:1},scale:{value:1},sceneBoxMin:{value:new R(-1,-1,-1)},sceneBoxMax:{value:new R(1,1,1)}},vertexShader:`
3863
+ }`};class Cr{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error("THREE.Pass: .render() must be implemented in derived pass.")}dispose(){}}const uM=new wh(-1,1,1,-1,0,1);class dM extends fn{constructor(){super(),this.setAttribute("position",new he([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new he([0,2,0,0,2,0],2))}}const fM=new dM;class kh{constructor(t){this._mesh=new yt(fM,t)}dispose(){this._mesh.geometry.dispose()}render(t){t.render(this._mesh,uM)}get material(){return this._mesh.material}set material(t){this._mesh.material=t}}class pM extends Cr{constructor(t,e){super(),this.textureID=e!==void 0?e:"tDiffuse",t instanceof nn?(this.uniforms=t.uniforms,this.material=t):t&&(this.uniforms=Qi.clone(t.uniforms),this.material=new nn({name:t.name!==void 0?t.name:"unspecified",defines:Object.assign({},t.defines),uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader})),this.fsQuad=new kh(this.material)}render(t,e,n){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=n.texture),this.fsQuad.material=this.material,this.renderToScreen?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),this.fsQuad.render(t))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}class fd extends Cr{constructor(t,e){super(),this.scene=t,this.camera=e,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(t,e,n){const s=t.getContext(),r=t.state;r.buffers.color.setMask(!1),r.buffers.depth.setMask(!1),r.buffers.color.setLocked(!0),r.buffers.depth.setLocked(!0);let a,o;this.inverse?(a=0,o=1):(a=1,o=0),r.buffers.stencil.setTest(!0),r.buffers.stencil.setOp(s.REPLACE,s.REPLACE,s.REPLACE),r.buffers.stencil.setFunc(s.ALWAYS,a,4294967295),r.buffers.stencil.setClear(o),r.buffers.stencil.setLocked(!0),t.setRenderTarget(n),this.clear&&t.clear(),t.render(this.scene,this.camera),t.setRenderTarget(e),this.clear&&t.clear(),t.render(this.scene,this.camera),r.buffers.color.setLocked(!1),r.buffers.depth.setLocked(!1),r.buffers.color.setMask(!0),r.buffers.depth.setMask(!0),r.buffers.stencil.setLocked(!1),r.buffers.stencil.setFunc(s.EQUAL,1,4294967295),r.buffers.stencil.setOp(s.KEEP,s.KEEP,s.KEEP),r.buffers.stencil.setLocked(!0)}}class mM extends Cr{constructor(){super(),this.needsSwap=!1}render(t){t.state.buffers.stencil.setLocked(!1),t.state.buffers.stencil.setTest(!1)}}class gM{constructor(t,e){if(this.renderer=t,this._pixelRatio=t.getPixelRatio(),e===void 0){const n=t.getSize(new rt);this._width=n.width,this._height=n.height,e=new Qn(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Ui}),e.texture.name="EffectComposer.rt1"}else this._width=e.width,this._height=e.height;this.renderTarget1=e,this.renderTarget2=e.clone(),this.renderTarget2.texture.name="EffectComposer.rt2",this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],this.copyPass=new pM(co),this.copyPass.material.blending=Ye,this.clock=new ep}swapBuffers(){const t=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=t}addPass(t){this.passes.push(t),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(t,e){this.passes.splice(e,0,t),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(t){const e=this.passes.indexOf(t);e!==-1&&this.passes.splice(e,1)}isLastEnabledPass(t){for(let e=t+1;e<this.passes.length;e++)if(this.passes[e].enabled)return!1;return!0}render(t){t===void 0&&(t=this.clock.getDelta());const e=this.renderer.getRenderTarget();let n=!1;for(let s=0,r=this.passes.length;s<r;s++){const a=this.passes[s];if(a.enabled!==!1){if(a.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(s),a.render(this.renderer,this.writeBuffer,this.readBuffer,t,n),a.needsSwap){if(n){const o=this.renderer.getContext(),l=this.renderer.state.buffers.stencil;l.setFunc(o.NOTEQUAL,1,4294967295),this.copyPass.render(this.renderer,this.writeBuffer,this.readBuffer,t),l.setFunc(o.EQUAL,1,4294967295)}this.swapBuffers()}fd!==void 0&&(a instanceof fd?n=!0:a instanceof mM&&(n=!1))}}this.renderer.setRenderTarget(e)}reset(t){if(t===void 0){const e=this.renderer.getSize(new rt);this._pixelRatio=this.renderer.getPixelRatio(),this._width=e.width,this._height=e.height,t=this.renderTarget1.clone(),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=t,this.renderTarget2=t.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(t,e){this._width=t,this._height=e;const n=this._width*this._pixelRatio,s=this._height*this._pixelRatio;this.renderTarget1.setSize(n,s),this.renderTarget2.setSize(n,s);for(let r=0;r<this.passes.length;r++)this.passes[r].setSize(n,s)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.copyPass.dispose()}}class vM extends Cr{constructor(t,e,n=null,s=null,r=null){super(),this.scene=t,this.camera=e,this.overrideMaterial=n,this.clearColor=s,this.clearAlpha=r,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this._oldClearColor=new Zt}render(t,e,n){const s=t.autoClear;t.autoClear=!1;let r,a;this.overrideMaterial!==null&&(a=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),this.clearColor!==null&&(t.getClearColor(this._oldClearColor),t.setClearColor(this.clearColor,t.getClearAlpha())),this.clearAlpha!==null&&(r=t.getClearAlpha(),t.setClearAlpha(this.clearAlpha)),this.clearDepth==!0&&t.clearDepth(),t.setRenderTarget(this.renderToScreen?null:n),this.clear===!0&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),t.render(this.scene,this.camera),this.clearColor!==null&&t.setClearColor(this._oldClearColor),this.clearAlpha!==null&&t.setClearAlpha(r),this.overrideMaterial!==null&&(this.scene.overrideMaterial=a),t.autoClear=s}}const Oa={defines:{PERSPECTIVE_CAMERA:1,SAMPLES:16,NORMAL_VECTOR_TYPE:1,DEPTH_SWIZZLING:"x",SCREEN_SPACE_RADIUS:0,SCREEN_SPACE_RADIUS_SCALE:100,SCENE_CLIP_BOX:0},uniforms:{tNormal:{value:null},tDepth:{value:null},tNoise:{value:null},resolution:{value:new rt},cameraNear:{value:null},cameraFar:{value:null},cameraProjectionMatrix:{value:new fe},cameraProjectionMatrixInverse:{value:new fe},cameraWorldMatrix:{value:new fe},radius:{value:.25},distanceExponent:{value:1},thickness:{value:1},distanceFallOff:{value:1},scale:{value:1},sceneBoxMin:{value:new R(-1,-1,-1)},sceneBoxMax:{value:new R(1,1,1)}},vertexShader:`
3864
3864
 
3865
3865
  varying vec2 vUv;
3866
3866
 
@@ -4043,7 +4043,7 @@ void main() {
4043
4043
  ao = pow(ao, scale);
4044
4044
 
4045
4045
  gl_FragColor = FRAGMENT_OUTPUT;
4046
- }`},Ra={defines:{PERSPECTIVE_CAMERA:1},uniforms:{tDepth:{value:null},cameraNear:{value:null},cameraFar:{value:null}},vertexShader:`
4046
+ }`},Fa={defines:{PERSPECTIVE_CAMERA:1},uniforms:{tDepth:{value:null},cameraNear:{value:null},cameraFar:{value:null}},vertexShader:`
4047
4047
  varying vec2 vUv;
4048
4048
 
4049
4049
  void main() {
@@ -4071,7 +4071,7 @@ void main() {
4071
4071
  float depth = getLinearDepth( vUv );
4072
4072
  gl_FragColor = vec4( vec3( 1.0 - depth ), 1.0 );
4073
4073
 
4074
- }`},wl={uniforms:{tDiffuse:{value:null},intensity:{value:1}},vertexShader:`
4074
+ }`},Ul={uniforms:{tDiffuse:{value:null},intensity:{value:1}},vertexShader:`
4075
4075
  varying vec2 vUv;
4076
4076
 
4077
4077
  void main() {
@@ -4085,7 +4085,7 @@ void main() {
4085
4085
  void main() {
4086
4086
  vec4 texel = texture2D( tDiffuse, vUv );
4087
4087
  gl_FragColor = vec4(mix(vec3(1.), texel.rgb, intensity), texel.a);
4088
- }`};function $y(i=5){const t=Math.floor(i)%2===0?Math.floor(i)+1:Math.floor(i),e=Wy(t),n=e.length,s=new Uint8Array(n*4);for(let a=0;a<n;++a){const o=e[a],l=2*Math.PI*o/n,c=new R(Math.cos(l),Math.sin(l),0).normalize();s[a*4]=(c.x*.5+.5)*255,s[a*4+1]=(c.y*.5+.5)*255,s[a*4+2]=127,s[a*4+3]=255}const r=new Ef(s,t,t);return r.wrapS=Pi,r.wrapT=Pi,r.needsUpdate=!0,r}function Wy(i){const t=Math.floor(i)%2===0?Math.floor(i)+1:Math.floor(i),e=t*t,n=Array(e).fill(0);let s=Math.floor(t/2),r=t-1;for(let a=1;a<=e;){if(s===-1&&r===t?(r=t-2,s=0):(r===t&&(r=0),s<0&&(s=t-1)),n[s*t+r]!==0){r-=2,s++;continue}else n[s*t+r]=a++;r++,s--}return n}const Pa={defines:{SAMPLES:16,SAMPLE_VECTORS:kf(16,2,1),NORMAL_VECTOR_TYPE:1,DEPTH_VALUE_SOURCE:0},uniforms:{tDiffuse:{value:null},tNormal:{value:null},tDepth:{value:null},tNoise:{value:null},resolution:{value:new rt},cameraProjectionMatrixInverse:{value:new fe},lumaPhi:{value:5},depthPhi:{value:5},normalPhi:{value:5},radius:{value:4},index:{value:0}},vertexShader:`
4088
+ }`};function _M(i=5){const t=Math.floor(i)%2===0?Math.floor(i)+1:Math.floor(i),e=xM(t),n=e.length,s=new Uint8Array(n*4);for(let a=0;a<n;++a){const o=e[a],l=2*Math.PI*o/n,c=new R(Math.cos(l),Math.sin(l),0).normalize();s[a*4]=(c.x*.5+.5)*255,s[a*4+1]=(c.y*.5+.5)*255,s[a*4+2]=127,s[a*4+3]=255}const r=new Yf(s,t,t);return r.wrapS=Ni,r.wrapT=Ni,r.needsUpdate=!0,r}function xM(i){const t=Math.floor(i)%2===0?Math.floor(i)+1:Math.floor(i),e=t*t,n=Array(e).fill(0);let s=Math.floor(t/2),r=t-1;for(let a=1;a<=e;){if(s===-1&&r===t?(r=t-2,s=0):(r===t&&(r=0),s<0&&(s=t-1)),n[s*t+r]!==0){r-=2,s++;continue}else n[s*t+r]=a++;r++,s--}return n}const za={defines:{SAMPLES:16,SAMPLE_VECTORS:sp(16,2,1),NORMAL_VECTOR_TYPE:1,DEPTH_VALUE_SOURCE:0},uniforms:{tDiffuse:{value:null},tNormal:{value:null},tDepth:{value:null},tNoise:{value:null},resolution:{value:new rt},cameraProjectionMatrixInverse:{value:new fe},lumaPhi:{value:5},depthPhi:{value:5},normalPhi:{value:5},radius:{value:4},index:{value:0}},vertexShader:`
4089
4089
 
4090
4090
  varying vec2 vUv;
4091
4091
 
@@ -4230,7 +4230,7 @@ void main() {
4230
4230
  denoised /= totalWeight;
4231
4231
  }
4232
4232
  gl_FragColor = FRAGMENT_OUTPUT;
4233
- }`};function kf(i,t,e){const n=Xy(i,t,e);let s="vec3[SAMPLES](";for(let r=0;r<i;r++){const a=n[r];s+=`vec3(${a.x}, ${a.y}, ${a.z})${r<i-1?",":")"}`}return s}function Xy(i,t,e){const n=[];for(let s=0;s<i;s++){const r=2*Math.PI*t*s/i,a=Math.pow(s/(i-1),e);n.push(new R(Math.cos(r),Math.sin(r),a))}return n}class jy{constructor(t=Math){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.grad4=[[0,1,1,1],[0,1,1,-1],[0,1,-1,1],[0,1,-1,-1],[0,-1,1,1],[0,-1,1,-1],[0,-1,-1,1],[0,-1,-1,-1],[1,0,1,1],[1,0,1,-1],[1,0,-1,1],[1,0,-1,-1],[-1,0,1,1],[-1,0,1,-1],[-1,0,-1,1],[-1,0,-1,-1],[1,1,0,1],[1,1,0,-1],[1,-1,0,1],[1,-1,0,-1],[-1,1,0,1],[-1,1,0,-1],[-1,-1,0,1],[-1,-1,0,-1],[1,1,1,0],[1,1,-1,0],[1,-1,1,0],[1,-1,-1,0],[-1,1,1,0],[-1,1,-1,0],[-1,-1,1,0],[-1,-1,-1,0]],this.p=[];for(let e=0;e<256;e++)this.p[e]=Math.floor(t.random()*256);this.perm=[];for(let e=0;e<512;e++)this.perm[e]=this.p[e&255];this.simplex=[[0,1,2,3],[0,1,3,2],[0,0,0,0],[0,2,3,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,3,0],[0,2,1,3],[0,0,0,0],[0,3,1,2],[0,3,2,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,3,2,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,0,3],[0,0,0,0],[1,3,0,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,3,0,1],[2,3,1,0],[1,0,2,3],[1,0,3,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,3,1],[0,0,0,0],[2,1,3,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,1,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,0,1,2],[3,0,2,1],[0,0,0,0],[3,1,2,0],[2,1,0,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,1,0,2],[0,0,0,0],[3,2,0,1],[3,2,1,0]]}dot(t,e,n){return t[0]*e+t[1]*n}dot3(t,e,n,s){return t[0]*e+t[1]*n+t[2]*s}dot4(t,e,n,s,r){return t[0]*e+t[1]*n+t[2]*s+t[3]*r}noise(t,e){let n,s,r;const a=.5*(Math.sqrt(3)-1),o=(t+e)*a,l=Math.floor(t+o),c=Math.floor(e+o),h=(3-Math.sqrt(3))/6,u=(l+c)*h,d=l-u,f=c-u,g=t-d,_=e-f;let m,p;g>_?(m=1,p=0):(m=0,p=1);const y=g-m+h,x=_-p+h,S=g-1+2*h,L=_-1+2*h,T=l&255,E=c&255,P=this.perm[T+this.perm[E]]%12,U=this.perm[T+m+this.perm[E+p]]%12,v=this.perm[T+1+this.perm[E+1]]%12;let b=.5-g*g-_*_;b<0?n=0:(b*=b,n=b*b*this.dot(this.grad3[P],g,_));let I=.5-y*y-x*x;I<0?s=0:(I*=I,s=I*I*this.dot(this.grad3[U],y,x));let O=.5-S*S-L*L;return O<0?r=0:(O*=O,r=O*O*this.dot(this.grad3[v],S,L)),70*(n+s+r)}noise3d(t,e,n){let s,r,a,o;const c=(t+e+n)*.3333333333333333,h=Math.floor(t+c),u=Math.floor(e+c),d=Math.floor(n+c),f=1/6,g=(h+u+d)*f,_=h-g,m=u-g,p=d-g,y=t-_,x=e-m,S=n-p;let L,T,E,P,U,v;y>=x?x>=S?(L=1,T=0,E=0,P=1,U=1,v=0):y>=S?(L=1,T=0,E=0,P=1,U=0,v=1):(L=0,T=0,E=1,P=1,U=0,v=1):x<S?(L=0,T=0,E=1,P=0,U=1,v=1):y<S?(L=0,T=1,E=0,P=0,U=1,v=1):(L=0,T=1,E=0,P=1,U=1,v=0);const b=y-L+f,I=x-T+f,O=S-E+f,$=y-P+2*f,Y=x-U+2*f,z=S-v+2*f,K=y-1+3*f,V=x-1+3*f,at=S-1+3*f,ct=h&255,_t=u&255,Gt=d&255,Jt=this.perm[ct+this.perm[_t+this.perm[Gt]]]%12,X=this.perm[ct+L+this.perm[_t+T+this.perm[Gt+E]]]%12,et=this.perm[ct+P+this.perm[_t+U+this.perm[Gt+v]]]%12,ft=this.perm[ct+1+this.perm[_t+1+this.perm[Gt+1]]]%12;let ot=.6-y*y-x*x-S*S;ot<0?s=0:(ot*=ot,s=ot*ot*this.dot3(this.grad3[Jt],y,x,S));let At=.6-b*b-I*I-O*O;At<0?r=0:(At*=At,r=At*At*this.dot3(this.grad3[X],b,I,O));let Tt=.6-$*$-Y*Y-z*z;Tt<0?a=0:(Tt*=Tt,a=Tt*Tt*this.dot3(this.grad3[et],$,Y,z));let Ft=.6-K*K-V*V-at*at;return Ft<0?o=0:(Ft*=Ft,o=Ft*Ft*this.dot3(this.grad3[ft],K,V,at)),32*(s+r+a+o)}noise4d(t,e,n,s){const r=this.grad4,a=this.simplex,o=this.perm,l=(Math.sqrt(5)-1)/4,c=(5-Math.sqrt(5))/20;let h,u,d,f,g;const _=(t+e+n+s)*l,m=Math.floor(t+_),p=Math.floor(e+_),y=Math.floor(n+_),x=Math.floor(s+_),S=(m+p+y+x)*c,L=m-S,T=p-S,E=y-S,P=x-S,U=t-L,v=e-T,b=n-E,I=s-P,O=U>v?32:0,$=U>b?16:0,Y=v>b?8:0,z=U>I?4:0,K=v>I?2:0,V=b>I?1:0,at=O+$+Y+z+K+V,ct=a[at][0]>=3?1:0,_t=a[at][1]>=3?1:0,Gt=a[at][2]>=3?1:0,Jt=a[at][3]>=3?1:0,X=a[at][0]>=2?1:0,et=a[at][1]>=2?1:0,ft=a[at][2]>=2?1:0,ot=a[at][3]>=2?1:0,At=a[at][0]>=1?1:0,Tt=a[at][1]>=1?1:0,Ft=a[at][2]>=1?1:0,ie=a[at][3]>=1?1:0,W=U-ct+c,A=v-_t+c,It=b-Gt+c,Ct=I-Jt+c,zt=U-X+2*c,Dt=v-et+2*c,ue=b-ft+2*c,kt=I-ot+2*c,C=U-At+3*c,M=v-Tt+3*c,F=b-Ft+3*c,q=I-ie+3*c,Q=U-1+4*c,j=v-1+4*c,St=b-1+4*c,ht=I-1+4*c,pt=m&255,Yt=p&255,nt=y&255,mt=x&255,Nt=o[pt+o[Yt+o[nt+o[mt]]]]%32,Ut=o[pt+ct+o[Yt+_t+o[nt+Gt+o[mt+Jt]]]]%32,Mt=o[pt+X+o[Yt+et+o[nt+ft+o[mt+ot]]]]%32,Qt=o[pt+At+o[Yt+Tt+o[nt+Ft+o[mt+ie]]]]%32,Vt=o[pt+1+o[Yt+1+o[nt+1+o[mt+1]]]]%32;let se=.6-U*U-v*v-b*b-I*I;se<0?h=0:(se*=se,h=se*se*this.dot4(r[Nt],U,v,b,I));let D=.6-W*W-A*A-It*It-Ct*Ct;D<0?u=0:(D*=D,u=D*D*this.dot4(r[Ut],W,A,It,Ct));let dt=.6-zt*zt-Dt*Dt-ue*ue-kt*kt;dt<0?d=0:(dt*=dt,d=dt*dt*this.dot4(r[Mt],zt,Dt,ue,kt));let G=.6-C*C-M*M-F*F-q*q;G<0?f=0:(G*=G,f=G*G*this.dot4(r[Qt],C,M,F,q));let Z=.6-Q*Q-j*j-St*St-ht*ht;return Z<0?g=0:(Z*=Z,g=Z*Z*this.dot4(r[Vt],Q,j,St,ht)),27*(h+u+d+f+g)}}class ei extends xr{constructor(t,e,n,s,r,a,o){super(),this.width=n!==void 0?n:512,this.height=s!==void 0?s:512,this.clear=!0,this.camera=e,this.scene=t,this.output=0,this._renderGBuffer=!0,this._visibilityCache=new Map,this.blendIntensity=1,this.pdRings=2,this.pdRadiusExponent=2,this.pdSamples=16,this.gtaoNoiseTexture=$y(),this.pdNoiseTexture=this.generateNoise(),this.gtaoRenderTarget=new Yn(this.width,this.height,{type:Li}),this.pdRenderTarget=this.gtaoRenderTarget.clone(),this.gtaoMaterial=new Je({defines:Object.assign({},Ca.defines),uniforms:ji.clone(Ca.uniforms),vertexShader:Ca.vertexShader,fragmentShader:Ca.fragmentShader,blending:Xe,depthTest:!1,depthWrite:!1}),this.gtaoMaterial.defines.PERSPECTIVE_CAMERA=this.camera.isPerspectiveCamera?1:0,this.gtaoMaterial.uniforms.tNoise.value=this.gtaoNoiseTexture,this.gtaoMaterial.uniforms.resolution.value.set(this.width,this.height),this.gtaoMaterial.uniforms.cameraNear.value=this.camera.near,this.gtaoMaterial.uniforms.cameraFar.value=this.camera.far,this.normalMaterial=new py,this.normalMaterial.blending=Xe,this.pdMaterial=new Je({defines:Object.assign({},Pa.defines),uniforms:ji.clone(Pa.uniforms),vertexShader:Pa.vertexShader,fragmentShader:Pa.fragmentShader,depthTest:!1,depthWrite:!1}),this.pdMaterial.uniforms.tDiffuse.value=this.gtaoRenderTarget.texture,this.pdMaterial.uniforms.tNoise.value=this.pdNoiseTexture,this.pdMaterial.uniforms.resolution.value.set(this.width,this.height),this.pdMaterial.uniforms.lumaPhi.value=10,this.pdMaterial.uniforms.depthPhi.value=2,this.pdMaterial.uniforms.normalPhi.value=3,this.pdMaterial.uniforms.radius.value=8,this.depthRenderMaterial=new Je({defines:Object.assign({},Ra.defines),uniforms:ji.clone(Ra.uniforms),vertexShader:Ra.vertexShader,fragmentShader:Ra.fragmentShader,blending:Xe}),this.depthRenderMaterial.uniforms.cameraNear.value=this.camera.near,this.depthRenderMaterial.uniforms.cameraFar.value=this.camera.far,this.copyMaterial=new Je({uniforms:ji.clone(Qa.uniforms),vertexShader:Qa.vertexShader,fragmentShader:Qa.fragmentShader,transparent:!0,depthTest:!1,depthWrite:!1,blendSrc:Kl,blendDst:Nr,blendEquation:$n,blendSrcAlpha:Yl,blendDstAlpha:Nr,blendEquationAlpha:$n}),this.blendMaterial=new Je({uniforms:ji.clone(wl.uniforms),vertexShader:wl.vertexShader,fragmentShader:wl.fragmentShader,transparent:!0,depthTest:!1,depthWrite:!1,blending:$d,blendSrc:Kl,blendDst:Nr,blendEquation:$n,blendSrcAlpha:Yl,blendDstAlpha:Nr,blendEquationAlpha:$n}),this.fsQuad=new _h(null),this.originalClearColor=new Zt,this.setGBuffer(r?r.depthTexture:void 0,r?r.normalTexture:void 0),a!==void 0&&this.updateGtaoMaterial(a),o!==void 0&&this.updatePdMaterial(o)}dispose(){this.gtaoNoiseTexture.dispose(),this.pdNoiseTexture.dispose(),this.normalRenderTarget.dispose(),this.gtaoRenderTarget.dispose(),this.pdRenderTarget.dispose(),this.normalMaterial.dispose(),this.pdMaterial.dispose(),this.copyMaterial.dispose(),this.depthRenderMaterial.dispose(),this.fsQuad.dispose()}get gtaoMap(){return this.pdRenderTarget.texture}setGBuffer(t,e){t!==void 0?(this.depthTexture=t,this.normalTexture=e,this._renderGBuffer=!1):(this.depthTexture=new hh,this.depthTexture.format=ys,this.depthTexture.type=xs,this.normalRenderTarget=new Yn(this.width,this.height,{minFilter:tn,magFilter:tn,type:Li,depthTexture:this.depthTexture}),this.normalTexture=this.normalRenderTarget.texture,this._renderGBuffer=!0);const n=this.normalTexture?1:0,s=this.depthTexture===this.normalTexture?"w":"x";this.gtaoMaterial.defines.NORMAL_VECTOR_TYPE=n,this.gtaoMaterial.defines.DEPTH_SWIZZLING=s,this.gtaoMaterial.uniforms.tNormal.value=this.normalTexture,this.gtaoMaterial.uniforms.tDepth.value=this.depthTexture,this.pdMaterial.defines.NORMAL_VECTOR_TYPE=n,this.pdMaterial.defines.DEPTH_SWIZZLING=s,this.pdMaterial.uniforms.tNormal.value=this.normalTexture,this.pdMaterial.uniforms.tDepth.value=this.depthTexture,this.depthRenderMaterial.uniforms.tDepth.value=this.normalRenderTarget.depthTexture}setSceneClipBox(t){t?(this.gtaoMaterial.needsUpdate=this.gtaoMaterial.defines.SCENE_CLIP_BOX!==1,this.gtaoMaterial.defines.SCENE_CLIP_BOX=1,this.gtaoMaterial.uniforms.sceneBoxMin.value.copy(t.min),this.gtaoMaterial.uniforms.sceneBoxMax.value.copy(t.max)):(this.gtaoMaterial.needsUpdate=this.gtaoMaterial.defines.SCENE_CLIP_BOX===0,this.gtaoMaterial.defines.SCENE_CLIP_BOX=0)}updateGtaoMaterial(t){t.radius!==void 0&&(this.gtaoMaterial.uniforms.radius.value=t.radius),t.distanceExponent!==void 0&&(this.gtaoMaterial.uniforms.distanceExponent.value=t.distanceExponent),t.thickness!==void 0&&(this.gtaoMaterial.uniforms.thickness.value=t.thickness),t.distanceFallOff!==void 0&&(this.gtaoMaterial.uniforms.distanceFallOff.value=t.distanceFallOff,this.gtaoMaterial.needsUpdate=!0),t.scale!==void 0&&(this.gtaoMaterial.uniforms.scale.value=t.scale),t.samples!==void 0&&t.samples!==this.gtaoMaterial.defines.SAMPLES&&(this.gtaoMaterial.defines.SAMPLES=t.samples,this.gtaoMaterial.needsUpdate=!0),t.screenSpaceRadius!==void 0&&(t.screenSpaceRadius?1:0)!==this.gtaoMaterial.defines.SCREEN_SPACE_RADIUS&&(this.gtaoMaterial.defines.SCREEN_SPACE_RADIUS=t.screenSpaceRadius?1:0,this.gtaoMaterial.needsUpdate=!0)}updatePdMaterial(t){let e=!1;t.lumaPhi!==void 0&&(this.pdMaterial.uniforms.lumaPhi.value=t.lumaPhi),t.depthPhi!==void 0&&(this.pdMaterial.uniforms.depthPhi.value=t.depthPhi),t.normalPhi!==void 0&&(this.pdMaterial.uniforms.normalPhi.value=t.normalPhi),t.radius!==void 0&&t.radius!==this.radius&&(this.pdMaterial.uniforms.radius.value=t.radius),t.radiusExponent!==void 0&&t.radiusExponent!==this.pdRadiusExponent&&(this.pdRadiusExponent=t.radiusExponent,e=!0),t.rings!==void 0&&t.rings!==this.pdRings&&(this.pdRings=t.rings,e=!0),t.samples!==void 0&&t.samples!==this.pdSamples&&(this.pdSamples=t.samples,e=!0),e&&(this.pdMaterial.defines.SAMPLES=this.pdSamples,this.pdMaterial.defines.SAMPLE_VECTORS=kf(this.pdSamples,this.pdRings,this.pdRadiusExponent),this.pdMaterial.needsUpdate=!0)}render(t,e,n){switch(this._renderGBuffer&&(this.overrideVisibility(),this.renderOverride(t,this.normalMaterial,this.normalRenderTarget,7829503,1),this.restoreVisibility()),this.gtaoMaterial.uniforms.cameraNear.value=this.camera.near,this.gtaoMaterial.uniforms.cameraFar.value=this.camera.far,this.gtaoMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.gtaoMaterial.uniforms.cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse),this.gtaoMaterial.uniforms.cameraWorldMatrix.value.copy(this.camera.matrixWorld),this.renderPass(t,this.gtaoMaterial,this.gtaoRenderTarget,16777215,1),this.pdMaterial.uniforms.cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse),this.renderPass(t,this.pdMaterial,this.pdRenderTarget,16777215,1),this.output){case ei.OUTPUT.Off:break;case ei.OUTPUT.Diffuse:this.copyMaterial.uniforms.tDiffuse.value=n.texture,this.copyMaterial.blending=Xe,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e);break;case ei.OUTPUT.AO:this.copyMaterial.uniforms.tDiffuse.value=this.gtaoRenderTarget.texture,this.copyMaterial.blending=Xe,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e);break;case ei.OUTPUT.Denoise:this.copyMaterial.uniforms.tDiffuse.value=this.pdRenderTarget.texture,this.copyMaterial.blending=Xe,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e);break;case ei.OUTPUT.Depth:this.depthRenderMaterial.uniforms.cameraNear.value=this.camera.near,this.depthRenderMaterial.uniforms.cameraFar.value=this.camera.far,this.renderPass(t,this.depthRenderMaterial,this.renderToScreen?null:e);break;case ei.OUTPUT.Normal:this.copyMaterial.uniforms.tDiffuse.value=this.normalRenderTarget.texture,this.copyMaterial.blending=Xe,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e);break;case ei.OUTPUT.Default:this.copyMaterial.uniforms.tDiffuse.value=n.texture,this.copyMaterial.blending=Xe,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e),this.blendMaterial.uniforms.intensity.value=this.blendIntensity,this.blendMaterial.uniforms.tDiffuse.value=this.pdRenderTarget.texture,this.renderPass(t,this.blendMaterial,this.renderToScreen?null:e);break;default:console.warn("THREE.GTAOPass: Unknown output type.")}}renderPass(t,e,n,s,r){t.getClearColor(this.originalClearColor);const a=t.getClearAlpha(),o=t.autoClear;t.setRenderTarget(n),t.autoClear=!1,s!=null&&(t.setClearColor(s),t.setClearAlpha(r||0),t.clear()),this.fsQuad.material=e,this.fsQuad.render(t),t.autoClear=o,t.setClearColor(this.originalClearColor),t.setClearAlpha(a)}renderOverride(t,e,n,s,r){t.getClearColor(this.originalClearColor);const a=t.getClearAlpha(),o=t.autoClear;t.setRenderTarget(n),t.autoClear=!1,s=e.clearColor||s,r=e.clearAlpha||r,s!=null&&(t.setClearColor(s),t.setClearAlpha(r||0),t.clear()),this.scene.overrideMaterial=e,t.render(this.scene,this.camera),this.scene.overrideMaterial=null,t.autoClear=o,t.setClearColor(this.originalClearColor),t.setClearAlpha(a)}setSize(t,e){this.width=t,this.height=e,this.gtaoRenderTarget.setSize(t,e),this.normalRenderTarget.setSize(t,e),this.pdRenderTarget.setSize(t,e),this.gtaoMaterial.uniforms.resolution.value.set(t,e),this.gtaoMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.gtaoMaterial.uniforms.cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse),this.pdMaterial.uniforms.resolution.value.set(t,e),this.pdMaterial.uniforms.cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse)}overrideVisibility(){const t=this.scene,e=this._visibilityCache;t.traverse(function(n){e.set(n,n.visible),(n.isPoints||n.isLine)&&(n.visible=!1)})}restoreVisibility(){const t=this.scene,e=this._visibilityCache;t.traverse(function(n){const s=e.get(n);n.visible=s}),e.clear()}generateNoise(t=64){const e=new jy,n=t*t*4,s=new Uint8Array(n);for(let a=0;a<t;a++)for(let o=0;o<t;o++){const l=a,c=o;s[(a*t+o)*4]=(e.noise(l,c)*.5+.5)*255,s[(a*t+o)*4+1]=(e.noise(l+t,c)*.5+.5)*255,s[(a*t+o)*4+2]=(e.noise(l,c+t)*.5+.5)*255,s[(a*t+o)*4+3]=(e.noise(l+t,c+t)*.5+.5)*255}const r=new Ef(s,t,t,Dn,hi);return r.wrapS=Pi,r.wrapT=Pi,r.needsUpdate=!0,r}}ei.OUTPUT={Off:-1,Default:0,Diffuse:1,Depth:2,Normal:3,AO:4,Denoise:5};const qy={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1}},vertexShader:`
4233
+ }`};function sp(i,t,e){const n=yM(i,t,e);let s="vec3[SAMPLES](";for(let r=0;r<i;r++){const a=n[r];s+=`vec3(${a.x}, ${a.y}, ${a.z})${r<i-1?",":")"}`}return s}function yM(i,t,e){const n=[];for(let s=0;s<i;s++){const r=2*Math.PI*t*s/i,a=Math.pow(s/(i-1),e);n.push(new R(Math.cos(r),Math.sin(r),a))}return n}class MM{constructor(t=Math){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.grad4=[[0,1,1,1],[0,1,1,-1],[0,1,-1,1],[0,1,-1,-1],[0,-1,1,1],[0,-1,1,-1],[0,-1,-1,1],[0,-1,-1,-1],[1,0,1,1],[1,0,1,-1],[1,0,-1,1],[1,0,-1,-1],[-1,0,1,1],[-1,0,1,-1],[-1,0,-1,1],[-1,0,-1,-1],[1,1,0,1],[1,1,0,-1],[1,-1,0,1],[1,-1,0,-1],[-1,1,0,1],[-1,1,0,-1],[-1,-1,0,1],[-1,-1,0,-1],[1,1,1,0],[1,1,-1,0],[1,-1,1,0],[1,-1,-1,0],[-1,1,1,0],[-1,1,-1,0],[-1,-1,1,0],[-1,-1,-1,0]],this.p=[];for(let e=0;e<256;e++)this.p[e]=Math.floor(t.random()*256);this.perm=[];for(let e=0;e<512;e++)this.perm[e]=this.p[e&255];this.simplex=[[0,1,2,3],[0,1,3,2],[0,0,0,0],[0,2,3,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,3,0],[0,2,1,3],[0,0,0,0],[0,3,1,2],[0,3,2,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,3,2,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,0,3],[0,0,0,0],[1,3,0,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,3,0,1],[2,3,1,0],[1,0,2,3],[1,0,3,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,3,1],[0,0,0,0],[2,1,3,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,1,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,0,1,2],[3,0,2,1],[0,0,0,0],[3,1,2,0],[2,1,0,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,1,0,2],[0,0,0,0],[3,2,0,1],[3,2,1,0]]}dot(t,e,n){return t[0]*e+t[1]*n}dot3(t,e,n,s){return t[0]*e+t[1]*n+t[2]*s}dot4(t,e,n,s,r){return t[0]*e+t[1]*n+t[2]*s+t[3]*r}noise(t,e){let n,s,r;const a=.5*(Math.sqrt(3)-1),o=(t+e)*a,l=Math.floor(t+o),c=Math.floor(e+o),h=(3-Math.sqrt(3))/6,u=(l+c)*h,d=l-u,f=c-u,g=t-d,_=e-f;let m,p;g>_?(m=1,p=0):(m=0,p=1);const y=g-m+h,x=_-p+h,S=g-1+2*h,L=_-1+2*h,T=l&255,E=c&255,P=this.perm[T+this.perm[E]]%12,U=this.perm[T+m+this.perm[E+p]]%12,v=this.perm[T+1+this.perm[E+1]]%12;let b=.5-g*g-_*_;b<0?n=0:(b*=b,n=b*b*this.dot(this.grad3[P],g,_));let I=.5-y*y-x*x;I<0?s=0:(I*=I,s=I*I*this.dot(this.grad3[U],y,x));let O=.5-S*S-L*L;return O<0?r=0:(O*=O,r=O*O*this.dot(this.grad3[v],S,L)),70*(n+s+r)}noise3d(t,e,n){let s,r,a,o;const c=(t+e+n)*.3333333333333333,h=Math.floor(t+c),u=Math.floor(e+c),d=Math.floor(n+c),f=1/6,g=(h+u+d)*f,_=h-g,m=u-g,p=d-g,y=t-_,x=e-m,S=n-p;let L,T,E,P,U,v;y>=x?x>=S?(L=1,T=0,E=0,P=1,U=1,v=0):y>=S?(L=1,T=0,E=0,P=1,U=0,v=1):(L=0,T=0,E=1,P=1,U=0,v=1):x<S?(L=0,T=0,E=1,P=0,U=1,v=1):y<S?(L=0,T=1,E=0,P=0,U=1,v=1):(L=0,T=1,E=0,P=1,U=1,v=0);const b=y-L+f,I=x-T+f,O=S-E+f,$=y-P+2*f,K=x-U+2*f,z=S-v+2*f,Z=y-1+3*f,V=x-1+3*f,at=S-1+3*f,ct=h&255,_t=u&255,$t=d&255,Jt=this.perm[ct+this.perm[_t+this.perm[$t]]]%12,X=this.perm[ct+L+this.perm[_t+T+this.perm[$t+E]]]%12,et=this.perm[ct+P+this.perm[_t+U+this.perm[$t+v]]]%12,ft=this.perm[ct+1+this.perm[_t+1+this.perm[$t+1]]]%12;let ot=.6-y*y-x*x-S*S;ot<0?s=0:(ot*=ot,s=ot*ot*this.dot3(this.grad3[Jt],y,x,S));let At=.6-b*b-I*I-O*O;At<0?r=0:(At*=At,r=At*At*this.dot3(this.grad3[X],b,I,O));let Tt=.6-$*$-K*K-z*z;Tt<0?a=0:(Tt*=Tt,a=Tt*Tt*this.dot3(this.grad3[et],$,K,z));let zt=.6-Z*Z-V*V-at*at;return zt<0?o=0:(zt*=zt,o=zt*zt*this.dot3(this.grad3[ft],Z,V,at)),32*(s+r+a+o)}noise4d(t,e,n,s){const r=this.grad4,a=this.simplex,o=this.perm,l=(Math.sqrt(5)-1)/4,c=(5-Math.sqrt(5))/20;let h,u,d,f,g;const _=(t+e+n+s)*l,m=Math.floor(t+_),p=Math.floor(e+_),y=Math.floor(n+_),x=Math.floor(s+_),S=(m+p+y+x)*c,L=m-S,T=p-S,E=y-S,P=x-S,U=t-L,v=e-T,b=n-E,I=s-P,O=U>v?32:0,$=U>b?16:0,K=v>b?8:0,z=U>I?4:0,Z=v>I?2:0,V=b>I?1:0,at=O+$+K+z+Z+V,ct=a[at][0]>=3?1:0,_t=a[at][1]>=3?1:0,$t=a[at][2]>=3?1:0,Jt=a[at][3]>=3?1:0,X=a[at][0]>=2?1:0,et=a[at][1]>=2?1:0,ft=a[at][2]>=2?1:0,ot=a[at][3]>=2?1:0,At=a[at][0]>=1?1:0,Tt=a[at][1]>=1?1:0,zt=a[at][2]>=1?1:0,ie=a[at][3]>=1?1:0,W=U-ct+c,A=v-_t+c,It=b-$t+c,Ct=I-Jt+c,Bt=U-X+2*c,Dt=v-et+2*c,ue=b-ft+2*c,Nt=I-ot+2*c,C=U-At+3*c,M=v-Tt+3*c,F=b-zt+3*c,Y=I-ie+3*c,Q=U-1+4*c,j=v-1+4*c,St=b-1+4*c,ht=I-1+4*c,pt=m&255,Yt=p&255,nt=y&255,mt=x&255,Ut=o[pt+o[Yt+o[nt+o[mt]]]]%32,Ot=o[pt+ct+o[Yt+_t+o[nt+$t+o[mt+Jt]]]]%32,Mt=o[pt+X+o[Yt+et+o[nt+ft+o[mt+ot]]]]%32,Qt=o[pt+At+o[Yt+Tt+o[nt+zt+o[mt+ie]]]]%32,Vt=o[pt+1+o[Yt+1+o[nt+1+o[mt+1]]]]%32;let se=.6-U*U-v*v-b*b-I*I;se<0?h=0:(se*=se,h=se*se*this.dot4(r[Ut],U,v,b,I));let D=.6-W*W-A*A-It*It-Ct*Ct;D<0?u=0:(D*=D,u=D*D*this.dot4(r[Ot],W,A,It,Ct));let dt=.6-Bt*Bt-Dt*Dt-ue*ue-Nt*Nt;dt<0?d=0:(dt*=dt,d=dt*dt*this.dot4(r[Mt],Bt,Dt,ue,Nt));let G=.6-C*C-M*M-F*F-Y*Y;G<0?f=0:(G*=G,f=G*G*this.dot4(r[Qt],C,M,F,Y));let J=.6-Q*Q-j*j-St*St-ht*ht;return J<0?g=0:(J*=J,g=J*J*this.dot4(r[Vt],Q,j,St,ht)),27*(h+u+d+f+g)}}class ri extends Cr{constructor(t,e,n,s,r,a,o){super(),this.width=n!==void 0?n:512,this.height=s!==void 0?s:512,this.clear=!0,this.camera=e,this.scene=t,this.output=0,this._renderGBuffer=!0,this._visibilityCache=new Map,this.blendIntensity=1,this.pdRings=2,this.pdRadiusExponent=2,this.pdSamples=16,this.gtaoNoiseTexture=_M(),this.pdNoiseTexture=this.generateNoise(),this.gtaoRenderTarget=new Qn(this.width,this.height,{type:Ui}),this.pdRenderTarget=this.gtaoRenderTarget.clone(),this.gtaoMaterial=new nn({defines:Object.assign({},Oa.defines),uniforms:Qi.clone(Oa.uniforms),vertexShader:Oa.vertexShader,fragmentShader:Oa.fragmentShader,blending:Ye,depthTest:!1,depthWrite:!1}),this.gtaoMaterial.defines.PERSPECTIVE_CAMERA=this.camera.isPerspectiveCamera?1:0,this.gtaoMaterial.uniforms.tNoise.value=this.gtaoNoiseTexture,this.gtaoMaterial.uniforms.resolution.value.set(this.width,this.height),this.gtaoMaterial.uniforms.cameraNear.value=this.camera.near,this.gtaoMaterial.uniforms.cameraFar.value=this.camera.far,this.normalMaterial=new Vy,this.normalMaterial.blending=Ye,this.pdMaterial=new nn({defines:Object.assign({},za.defines),uniforms:Qi.clone(za.uniforms),vertexShader:za.vertexShader,fragmentShader:za.fragmentShader,depthTest:!1,depthWrite:!1}),this.pdMaterial.uniforms.tDiffuse.value=this.gtaoRenderTarget.texture,this.pdMaterial.uniforms.tNoise.value=this.pdNoiseTexture,this.pdMaterial.uniforms.resolution.value.set(this.width,this.height),this.pdMaterial.uniforms.lumaPhi.value=10,this.pdMaterial.uniforms.depthPhi.value=2,this.pdMaterial.uniforms.normalPhi.value=3,this.pdMaterial.uniforms.radius.value=8,this.depthRenderMaterial=new nn({defines:Object.assign({},Fa.defines),uniforms:Qi.clone(Fa.uniforms),vertexShader:Fa.vertexShader,fragmentShader:Fa.fragmentShader,blending:Ye}),this.depthRenderMaterial.uniforms.cameraNear.value=this.camera.near,this.depthRenderMaterial.uniforms.cameraFar.value=this.camera.far,this.copyMaterial=new nn({uniforms:Qi.clone(co.uniforms),vertexShader:co.vertexShader,fragmentShader:co.fragmentShader,transparent:!0,depthTest:!1,depthWrite:!1,blendSrc:hc,blendDst:$r,blendEquation:jn,blendSrcAlpha:cc,blendDstAlpha:$r,blendEquationAlpha:jn}),this.blendMaterial=new nn({uniforms:Qi.clone(Ul.uniforms),vertexShader:Ul.vertexShader,fragmentShader:Ul.fragmentShader,transparent:!0,depthTest:!1,depthWrite:!1,blending:mf,blendSrc:hc,blendDst:$r,blendEquation:jn,blendSrcAlpha:cc,blendDstAlpha:$r,blendEquationAlpha:jn}),this.fsQuad=new kh(null),this.originalClearColor=new Zt,this.setGBuffer(r?r.depthTexture:void 0,r?r.normalTexture:void 0),a!==void 0&&this.updateGtaoMaterial(a),o!==void 0&&this.updatePdMaterial(o)}dispose(){this.gtaoNoiseTexture.dispose(),this.pdNoiseTexture.dispose(),this.normalRenderTarget.dispose(),this.gtaoRenderTarget.dispose(),this.pdRenderTarget.dispose(),this.normalMaterial.dispose(),this.pdMaterial.dispose(),this.copyMaterial.dispose(),this.depthRenderMaterial.dispose(),this.fsQuad.dispose()}get gtaoMap(){return this.pdRenderTarget.texture}setGBuffer(t,e){t!==void 0?(this.depthTexture=t,this.normalTexture=e,this._renderGBuffer=!1):(this.depthTexture=new Th,this.depthTexture.format=Cs,this.depthTexture.type=As,this.normalRenderTarget=new Qn(this.width,this.height,{minFilter:rn,magFilter:rn,type:Ui,depthTexture:this.depthTexture}),this.normalTexture=this.normalRenderTarget.texture,this._renderGBuffer=!0);const n=this.normalTexture?1:0,s=this.depthTexture===this.normalTexture?"w":"x";this.gtaoMaterial.defines.NORMAL_VECTOR_TYPE=n,this.gtaoMaterial.defines.DEPTH_SWIZZLING=s,this.gtaoMaterial.uniforms.tNormal.value=this.normalTexture,this.gtaoMaterial.uniforms.tDepth.value=this.depthTexture,this.pdMaterial.defines.NORMAL_VECTOR_TYPE=n,this.pdMaterial.defines.DEPTH_SWIZZLING=s,this.pdMaterial.uniforms.tNormal.value=this.normalTexture,this.pdMaterial.uniforms.tDepth.value=this.depthTexture,this.depthRenderMaterial.uniforms.tDepth.value=this.normalRenderTarget.depthTexture}setSceneClipBox(t){t?(this.gtaoMaterial.needsUpdate=this.gtaoMaterial.defines.SCENE_CLIP_BOX!==1,this.gtaoMaterial.defines.SCENE_CLIP_BOX=1,this.gtaoMaterial.uniforms.sceneBoxMin.value.copy(t.min),this.gtaoMaterial.uniforms.sceneBoxMax.value.copy(t.max)):(this.gtaoMaterial.needsUpdate=this.gtaoMaterial.defines.SCENE_CLIP_BOX===0,this.gtaoMaterial.defines.SCENE_CLIP_BOX=0)}updateGtaoMaterial(t){t.radius!==void 0&&(this.gtaoMaterial.uniforms.radius.value=t.radius),t.distanceExponent!==void 0&&(this.gtaoMaterial.uniforms.distanceExponent.value=t.distanceExponent),t.thickness!==void 0&&(this.gtaoMaterial.uniforms.thickness.value=t.thickness),t.distanceFallOff!==void 0&&(this.gtaoMaterial.uniforms.distanceFallOff.value=t.distanceFallOff,this.gtaoMaterial.needsUpdate=!0),t.scale!==void 0&&(this.gtaoMaterial.uniforms.scale.value=t.scale),t.samples!==void 0&&t.samples!==this.gtaoMaterial.defines.SAMPLES&&(this.gtaoMaterial.defines.SAMPLES=t.samples,this.gtaoMaterial.needsUpdate=!0),t.screenSpaceRadius!==void 0&&(t.screenSpaceRadius?1:0)!==this.gtaoMaterial.defines.SCREEN_SPACE_RADIUS&&(this.gtaoMaterial.defines.SCREEN_SPACE_RADIUS=t.screenSpaceRadius?1:0,this.gtaoMaterial.needsUpdate=!0)}updatePdMaterial(t){let e=!1;t.lumaPhi!==void 0&&(this.pdMaterial.uniforms.lumaPhi.value=t.lumaPhi),t.depthPhi!==void 0&&(this.pdMaterial.uniforms.depthPhi.value=t.depthPhi),t.normalPhi!==void 0&&(this.pdMaterial.uniforms.normalPhi.value=t.normalPhi),t.radius!==void 0&&t.radius!==this.radius&&(this.pdMaterial.uniforms.radius.value=t.radius),t.radiusExponent!==void 0&&t.radiusExponent!==this.pdRadiusExponent&&(this.pdRadiusExponent=t.radiusExponent,e=!0),t.rings!==void 0&&t.rings!==this.pdRings&&(this.pdRings=t.rings,e=!0),t.samples!==void 0&&t.samples!==this.pdSamples&&(this.pdSamples=t.samples,e=!0),e&&(this.pdMaterial.defines.SAMPLES=this.pdSamples,this.pdMaterial.defines.SAMPLE_VECTORS=sp(this.pdSamples,this.pdRings,this.pdRadiusExponent),this.pdMaterial.needsUpdate=!0)}render(t,e,n){switch(this._renderGBuffer&&(this.overrideVisibility(),this.renderOverride(t,this.normalMaterial,this.normalRenderTarget,7829503,1),this.restoreVisibility()),this.gtaoMaterial.uniforms.cameraNear.value=this.camera.near,this.gtaoMaterial.uniforms.cameraFar.value=this.camera.far,this.gtaoMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.gtaoMaterial.uniforms.cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse),this.gtaoMaterial.uniforms.cameraWorldMatrix.value.copy(this.camera.matrixWorld),this.renderPass(t,this.gtaoMaterial,this.gtaoRenderTarget,16777215,1),this.pdMaterial.uniforms.cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse),this.renderPass(t,this.pdMaterial,this.pdRenderTarget,16777215,1),this.output){case ri.OUTPUT.Off:break;case ri.OUTPUT.Diffuse:this.copyMaterial.uniforms.tDiffuse.value=n.texture,this.copyMaterial.blending=Ye,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e);break;case ri.OUTPUT.AO:this.copyMaterial.uniforms.tDiffuse.value=this.gtaoRenderTarget.texture,this.copyMaterial.blending=Ye,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e);break;case ri.OUTPUT.Denoise:this.copyMaterial.uniforms.tDiffuse.value=this.pdRenderTarget.texture,this.copyMaterial.blending=Ye,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e);break;case ri.OUTPUT.Depth:this.depthRenderMaterial.uniforms.cameraNear.value=this.camera.near,this.depthRenderMaterial.uniforms.cameraFar.value=this.camera.far,this.renderPass(t,this.depthRenderMaterial,this.renderToScreen?null:e);break;case ri.OUTPUT.Normal:this.copyMaterial.uniforms.tDiffuse.value=this.normalRenderTarget.texture,this.copyMaterial.blending=Ye,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e);break;case ri.OUTPUT.Default:this.copyMaterial.uniforms.tDiffuse.value=n.texture,this.copyMaterial.blending=Ye,this.renderPass(t,this.copyMaterial,this.renderToScreen?null:e),this.blendMaterial.uniforms.intensity.value=this.blendIntensity,this.blendMaterial.uniforms.tDiffuse.value=this.pdRenderTarget.texture,this.renderPass(t,this.blendMaterial,this.renderToScreen?null:e);break;default:console.warn("THREE.GTAOPass: Unknown output type.")}}renderPass(t,e,n,s,r){t.getClearColor(this.originalClearColor);const a=t.getClearAlpha(),o=t.autoClear;t.setRenderTarget(n),t.autoClear=!1,s!=null&&(t.setClearColor(s),t.setClearAlpha(r||0),t.clear()),this.fsQuad.material=e,this.fsQuad.render(t),t.autoClear=o,t.setClearColor(this.originalClearColor),t.setClearAlpha(a)}renderOverride(t,e,n,s,r){t.getClearColor(this.originalClearColor);const a=t.getClearAlpha(),o=t.autoClear;t.setRenderTarget(n),t.autoClear=!1,s=e.clearColor||s,r=e.clearAlpha||r,s!=null&&(t.setClearColor(s),t.setClearAlpha(r||0),t.clear()),this.scene.overrideMaterial=e,t.render(this.scene,this.camera),this.scene.overrideMaterial=null,t.autoClear=o,t.setClearColor(this.originalClearColor),t.setClearAlpha(a)}setSize(t,e){this.width=t,this.height=e,this.gtaoRenderTarget.setSize(t,e),this.normalRenderTarget.setSize(t,e),this.pdRenderTarget.setSize(t,e),this.gtaoMaterial.uniforms.resolution.value.set(t,e),this.gtaoMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.gtaoMaterial.uniforms.cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse),this.pdMaterial.uniforms.resolution.value.set(t,e),this.pdMaterial.uniforms.cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse)}overrideVisibility(){const t=this.scene,e=this._visibilityCache;t.traverse(function(n){e.set(n,n.visible),(n.isPoints||n.isLine)&&(n.visible=!1)})}restoreVisibility(){const t=this.scene,e=this._visibilityCache;t.traverse(function(n){const s=e.get(n);n.visible=s}),e.clear()}generateNoise(t=64){const e=new MM,n=t*t*4,s=new Uint8Array(n);for(let a=0;a<t;a++)for(let o=0;o<t;o++){const l=a,c=o;s[(a*t+o)*4]=(e.noise(l,c)*.5+.5)*255,s[(a*t+o)*4+1]=(e.noise(l+t,c)*.5+.5)*255,s[(a*t+o)*4+2]=(e.noise(l,c+t)*.5+.5)*255,s[(a*t+o)*4+3]=(e.noise(l+t,c+t)*.5+.5)*255}const r=new Yf(s,t,t,Nn,pi);return r.wrapS=Ni,r.wrapT=Ni,r.needsUpdate=!0,r}}ri.OUTPUT={Off:-1,Default:0,Diffuse:1,Depth:2,Normal:3,AO:4,Denoise:5};const bM={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1}},vertexShader:`
4234
4234
  precision highp float;
4235
4235
 
4236
4236
  uniform mat4 modelViewMatrix;
@@ -4297,12 +4297,12 @@ void main() {
4297
4297
 
4298
4298
  #endif
4299
4299
 
4300
- }`};class Yy extends xr{constructor(){super();const t=qy;this.uniforms=ji.clone(t.uniforms),this.material=new fy({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad=new _h(this.material),this._outputColorSpace=null,this._toneMapping=null}render(t,e,n){this.uniforms.tDiffuse.value=n.texture,this.uniforms.toneMappingExposure.value=t.toneMappingExposure,(this._outputColorSpace!==t.outputColorSpace||this._toneMapping!==t.toneMapping)&&(this._outputColorSpace=t.outputColorSpace,this._toneMapping=t.toneMapping,this.material.defines={},oe.getTransfer(this._outputColorSpace)===ye&&(this.material.defines.SRGB_TRANSFER=""),this._toneMapping===Xd?this.material.defines.LINEAR_TONE_MAPPING="":this._toneMapping===jd?this.material.defines.REINHARD_TONE_MAPPING="":this._toneMapping===qd?this.material.defines.CINEON_TONE_MAPPING="":this._toneMapping===Yd?this.material.defines.ACES_FILMIC_TONE_MAPPING="":this._toneMapping===Kd?this.material.defines.AGX_TONE_MAPPING="":this._toneMapping===qc&&(this.material.defines.NEUTRAL_TONE_MAPPING=""),this.material.needsUpdate=!0),this.renderToScreen===!0?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),this.fsQuad.render(t))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}class Ky{constructor(t,e){this.w=t,this.d=e,this.ox=-t/2,this.oz=-e/2,this.cells=new Uint8Array(t*e)}inside(t,e){return t>=0&&e>=0&&t<this.w&&e<this.d}blocked(t,e){return!this.inside(t,e)||this.cells[e*this.w+t]===1}cellOf(t,e){return[Math.floor(t-this.ox),Math.floor(e-this.oz)]}center(t,e){return[this.ox+t+.5,this.oz+e+.5]}block(t,e,n,s){const[r,a]=this.cellOf(t,n),[o,l]=this.cellOf(e-1e-6,s-1e-6);for(let c=a;c<=l;c++)for(let h=r;h<=o;h++)this.inside(h,c)&&(this.cells[c*this.w+h]=1)}nearestFree(t,e){if(!this.blocked(t,e))return[t,e];const n=new Set([e*this.w+t]),s=[[t,e]];for(;s.length;){const[r,a]=s.shift();for(const[o,l]of[[1,0],[-1,0],[0,1],[0,-1]]){const c=r+o,h=a+l;if(!(!this.inside(c,h)||n.has(h*this.w+c))){if(!this.blocked(c,h))return[c,h];n.add(h*this.w+c),s.push([c,h])}}}return[t,e]}clear(t,e,n,s){const r=Math.hypot(n-t,s-e),a=Math.ceil(r/.2);for(let o=1;o<a;o++){const l=o/a,[c,h]=this.cellOf(t+(n-t)*l,e+(s-e)*l);if(this.blocked(c,h))return!1}return!0}path(t,e,n,s){const r=this.nearestFree(...this.cellOf(t,e)),a=this.nearestFree(...this.cellOf(n,s)),o=(y,x)=>x*this.w+y,l=(y,x)=>Math.hypot(y-a[0],x-a[1]),c=new Map([[o(...r),0]]),h=new Map,u=[[l(...r),...r]],d=new Set;let f=!1;for(;u.length;){let y=0;for(let T=1;T<u.length;T++)u[T][0]<u[y][0]&&(y=T);const[,x,S]=u.splice(y,1)[0],L=o(x,S);if(!d.has(L)){if(d.add(L),x===a[0]&&S===a[1]){f=!0;break}for(let T=-1;T<=1;T++)for(let E=-1;E<=1;E++){if(!T&&!E)continue;const P=x+T,U=S+E;if(this.blocked(P,U)||T&&E&&(this.blocked(x+T,S)||this.blocked(x,S+E)))continue;const v=o(P,U),b=c.get(L)+(T&&E?Math.SQRT2:1);b<(c.get(v)??1/0)&&(c.set(v,b),h.set(v,L),u.push([b+l(P,U),P,U]))}}}const g=[];if(f){let y=o(...a);for(;y!==void 0;)g.unshift(this.center(y%this.w,Math.floor(y/this.w))),y=h.get(y)}g.push([n,s]);const _=[];let m=[t,e],p=0;for(;p<g.length;){let y=p;for(let x=g.length-1;x>p;x--)if(this.clear(m[0],m[1],g[x][0],g[x][1])){y=x;break}_.push(g[y]),m=g[y],p=y+1}return _}}const El=new Map;function Se(i,t={}){const e=i+JSON.stringify(t);return El.has(e)||El.set(e,new On({color:i,roughness:.7,...t})),El.get(e)}const Tr=(i,t)=>"#"+new Zt(i).multiplyScalar(t).getHexString();function re(i,t,e,n=0,s=0,r=0){const a=new yt(i,t);return a.position.set(n,s,r),a.castShadow=!0,a.receiveShadow=!0,e.add(a),a}const Jn=(i,t)=>new fh(i,Math.max(.001,t),5,12),yi=(i,t=20,e=14)=>new li(i,t,e),Zy=.93,Jy=.45,Qy=.44,tM=.06,eM=.1,ee=.46,Nf={ada:{hair:"afro",pants:"#3a3f5c",shoes:"#26211d"},tunde:{hair:"short",pants:"#4b4136",shoes:"#1c1c1c",extra:"lanyard"},mira:{hair:"bob",pants:"#2f3b52",shoes:"#5b4636"},kai:{hair:"spiky",pants:"#38383d",shoes:"#e9e6df",extra:"hood"},zola:{hair:"ponytail",pants:"#4d3f5e",shoes:"#2b2b2b"},remi:{hair:"bun",pants:"#3f4f60",shoes:"#704d38",extra:"glasses"},obi:{hair:"buzz",pants:"#2c3a32",shoes:"#1d1d1d",extra:"headphones"},lin:{hair:"long",pants:"#3b3b4a",shoes:"#2a2a2a"},chief:{hair:"side",pants:"#22232e",shoes:"#141414",extra:"suit"}};function La(i,t,e,n,s,r,a,o,l,c){const h=new qt;h.position.set(t,e,0),i.add(h),re(Jn(r,n-r),o,h,0,-n/2);const u=new qt;u.position.y=-n,h.add(u),re(Jn(a,s-a),l,u,0,-s/2);const d=new qt;return d.position.y=-s,u.add(d),c==null||c(d),{pivot:h,joint:u,end:d}}class Gr{constructor(t){const e=Nf[t.id]||{hair:"short",pants:"#34384a",shoes:"#222"};this.look=e;const n=Se(t.skin,{roughness:.6}),s=Se(t.shirt),r=Se(Tr(t.shirt,.9)),a=Se(e.pants),o=Se(e.shoes,{roughness:.5}),l=Se(t.hair,{roughness:.85});this.group=new qt,this.body=new qt,this.group.add(this.body),this.hips=new qt,this.hips.position.y=.95,this.body.add(this.hips),re(Jn(.2,.06),a,this.hips,0,.02).scale.set(1,1,.8);const h=_=>{re(new qe(.15,.09,.26),o,_,0,-.02,.05).geometry.translate(0,0,0)};this.legL=La(this.hips,-.11,-.02,.45,.44,.1,.085,a,a,h),this.legR=La(this.hips,.11,-.02,.45,.44,.1,.085,a,a,h),this.torso=new qt,this.hips.add(this.torso);const u=[[.001,0],[.19,0],[.225,.08],[.23,.24],[.22,.36],[.255,.5],[.24,.58],[.15,.645],[.001,.66]].map(([_,m])=>new rt(_,m)),d=re(new Ro(u,20),e.extra==="suit"?Se("#2b2d42"):s,this.torso,0,.04);d.scale.z=.8,re(new ii(.11,.03,8,20),e.extra==="suit"?Se("#f4f1ea"):Se(Tr(t.shirt,.8)),this.torso,0,.67).rotation.x=Math.PI/2,re(new Un(.075,.085,.14,12),n,this.torso,0,.73);const f=_=>re(yi(.07,12,10),n,_,0,-.02),g=e.extra==="suit"?Se("#2b2d42"):r;this.armL=La(this.torso,-.29,.58,.32,.3,.072,.062,g,e.extra==="suit"||e.extra==="hood"?g:n,f),this.armR=La(this.torso,.29,.58,.32,.3,.072,.062,g,e.extra==="suit"||e.extra==="hood"?g:n,f),this.buildHead(t,n,l),this.buildExtras(t,e,l),this.book=re(new qe(.34,.05,.26),Se("#3d7ea6"),this.torso,0,.3,.36),this.book.rotation.x=-.6,this.book.visible=!1,this.mug=re(new Un(.06,.055,.13,12),Se("#ffffff"),this.armR.end,0,-.06,.07),this.mug.visible=!1,this.blinkAt=1+Math.random()*3,this.blink=0,this.cur={}}buildHead(t,e,n){this.head=new qt,this.head.position.y=.78,this.torso.add(this.head),re(yi(.33,28,20),e,this.head,0,.3).scale.set(1,.97,.94);for(const a of[-1,1])re(yi(.06,10,8),e,this.head,a*.32,.29,-.01).scale.set(.6,1,1);re(yi(.032,10,8),Se(Tr(t.skin,.88),{roughness:.6}),this.head,0,.27,.31),this.eyes=[];for(const a of[-1,1]){const o=new qt;o.position.set(a*.115,.33,.285),o.rotation.y=a*.28,this.head.add(o);const l=new yt(yi(.042,14,10),Se("#17181c",{roughness:.3}));l.scale.set(.82,1.2,.5),o.add(l);const c=new yt(yi(.013,8,6),new ln({color:"#ffffff"}));c.position.set(.012,.018,.02),o.add(c),this.eyes.push(o)}this.brows=[];for(const a of[-1,1]){const o=new yt(Jn(.014,.08),Se(Tr(t.hair,.9)));o.rotation.z=Math.PI/2;const l=new qt;l.position.set(a*.115,.425,.275),l.rotation.y=a*.28,l.add(o),this.head.add(l),this.brows.push(l)}this.mouth=new yt(new ii(.055,.012,6,18,Math.PI),Se("#5b2a2a",{roughness:.5})),this.mouth.position.set(0,.205,.292),this.mouth.rotation.z=Math.PI,this.head.add(this.mouth);for(const a of[-1,1]){const o=new yt(new Di(.045,16),new ln({color:"#ff8d7a",transparent:!0,opacity:.22,depthWrite:!1}));o.position.set(a*.19,.24,.245),o.rotation.y=a*.62,this.head.add(o)}const r=(a=.345,o=.52,l=-.25)=>{const c=re(new li(a,28,16,0,Math.PI*2,0,Math.PI*o),n,this.head,0,.31,-.01);return c.rotation.x=l,c.scale.set(1,1,.97),c};switch(this.look.hair){case"afro":r(.35,.55),re(yi(.43,24,18),n,this.head,0,.47,-.08).scale.set(1,.85,.95);break;case"bob":{r(.36,.56,-.32);for(const a of[-1,1])re(Jn(.09,.2),n,this.head,a*.29,.22,-.1).scale.set(.75,1,1.1);re(Jn(.05,.3),n,this.head,0,.55,.17).rotation.z=Math.PI/2;break}case"spiky":r(.35,.5);for(let a=0;a<9;a++){const o=a/9*Math.PI*2;re(new ta(.07,.22,6),n,this.head,Math.cos(o)*.17,.6,Math.sin(o)*.17-.03).rotation.set(Math.sin(o)*.7,0,-Math.cos(o)*.7)}break;case"ponytail":{r(.35,.55),re(yi(.07,10,8),Se("#e07a5f"),this.head,0,.42,-.33);const a=re(Jn(.08,.32),n,this.head,0,.22,-.4);a.rotation.x=.35,this.tail=a;break}case"bun":r(.35,.55),re(yi(.14,16,12),n,this.head,0,.66,-.1);break;case"buzz":r(.338,.5,-.3);break;case"long":{r(.36,.58,-.2),re(Jn(.16,.42),n,this.head,0,.1,-.2).scale.set(1.75,1,.6);break}case"side":{r(.35,.5),re(Jn(.07,.3),n,this.head,.06,.58,.12).rotation.set(.2,0,Math.PI/2-.25);break}default:r(.35,.5)}}buildExtras(t,e,n){if(e.extra==="glasses"||e.extra==="suit"){const s=Se("#1b1b1f",{roughness:.4});for(const r of[-1,1]){const a=re(new ii(.06,.011,6,18),s,this.head,r*.115,.33,.3);a.rotation.y=r*.28}re(Jn(.009,.06),s,this.head,0,.34,.315).rotation.z=Math.PI/2}if(e.extra==="suit"){const s=re(new qe(.06,.3,.02),Se("#b23a3a"),this.torso,0,.47,.19);s.rotation.x=-.12,re(new qe(.16,.18,.02),Se("#f4f1ea"),this.torso,0,.56,.175).rotation.x=-.15}if(e.extra==="headphones"){const s=re(new ii(.35,.025,8,24,Math.PI),Se("#22252b"),this.head,0,.32,0);s.rotation.y=Math.PI/2,s.rotation.x=-.15;for(const r of[-1,1])re(new Un(.09,.09,.07,18),Se("#e05f4a"),this.head,r*.34,.3,0).rotation.z=Math.PI/2}if(e.extra==="lanyard"&&(re(new ii(.16,.01,6,20,Math.PI),Se("#2a6fb0"),this.torso,0,.62,.12).rotation.set(-.25,0,Math.PI),re(new qe(.1,.13,.015),Se("#ffffff"),this.torso,0,.42,.205).rotation.x=-.1),e.extra==="hood"){const s=re(new ii(.2,.06,10,24),Se(Tr(t.shirt,.85)),this.torso,0,.64,-.05);s.rotation.x=Math.PI/2+.35,s.scale.set(1,1,.7)}}static sit(t=ee,e=-1.4){const n=t+eM,s=n-Jy*Math.cos(e),r=-Math.acos(Math.min(1,Math.max(-1,(s-tM)/Qy)));return{y:n-Zy,hip:e,knee:r-e}}pose(t,e,n,s={}){const r=Math.min(1,e*10);let a=0,o=0,l=0,c=0,h=.05,u=.05,d=-.12,f=-.12,g=-.07,_=.07,m=0,p=0,y=0,x=0,S=0;const L=Math.sin(n*1.7)*.012;switch(this.book.visible=t==="read",this.mug.visible=t==="mug",t){case"walk":{const v=Math.sin(n*9.5),b=Math.cos(n*9.5);a=v*.5,o=-v*.5,l=Math.max(0,-b)*.9+.05,c=Math.max(0,b)*.9+.05,h=-v*.45,u=v*.45,d=f=-.35,m=Math.abs(b)*.05,p=.06,x=Math.sin(n*4.75)*.04;break}case"desk":{const v=Gr.sit(s.seatY,-1.45);a=o=v.hip,l=c=v.knee,m=v.y,p=.08,s.typing?(h=-.5+Math.sin(n*17)*.05,u=-.5+Math.sin(n*17+2)*.05,d=-1.15+Math.sin(n*19)*.12,f=-1.15+Math.sin(n*19+1.6)*.12,g=-.18,_=.18,y=.12+Math.sin(n*.7)*.03):s.waiting?(u=-.95,f=-2.25,_=.05,h=-.4,d=-1,x=Math.sin(n*.6)*.45,y=-.05):(h=u=-.35,d=f=-.9,g=-.2,_=.2,p=-.04,x=Math.sin(n*.35)*.3);break}case"couch":{const v=Gr.sit(s.seatY,-1.3);a=o=v.hip,l=c=v.knee,m=v.y,p=-.18,h=u=-.2,d=f=-.75,g=-.15,_=.15,x=Math.sin(n*.3)*.5,S=Math.sin(n*.21)*.06;break}case"sit":{const v=Gr.sit(s.seatY,-1.42);a=o=v.hip,l=c=v.knee,m=v.y,p=.03,h=u=-.32,d=f=-.95,g=-.16,_=.16,x=Math.sin(n*.4)*.4,S=Math.sin(n*.27)*.05;break}case"read":h=u=-.55,d=f=-1.35,g=-.12,_=.12,y=.4,x=Math.sin(n*.6)*.12;break;case"type":h=-.75+Math.sin(n*14)*.08,u=-.75+Math.sin(n*14+2)*.08,d=-.9,f=-.9,g=-.15,_=.15,y=.08;break;case"gaze":h=u=.3,d=f=-.25,g=-.12,_=.12,y=-.18,x=Math.sin(n*.45)*.35;break;case"write":u=-2.2+Math.sin(n*6)*.2,f=-.5+Math.sin(n*9)*.15,_=.25,x=Math.sin(n*1.2)*.1,y=-.08;break;case"mug":{const v=Math.sin(n*.8)>.75;u=v?-.85:-.45,f=v?-2.05:-1.55,_=.1,y=v?-.15:.02,x=v?0:Math.sin(n*.4)*.3;break}case"cue":p=.62,h=-1.5,d=-.12,g=-.12,u=-.95,f=-1.35,_=.14,y=-.5,a=o=-.12,l=c=.14,x=Math.sin(n*.8)*.05;break;case"talk":u=-.55+Math.sin(n*4)*.2,f=-1.1+Math.sin(n*5.3)*.2,_=.2,h=-.1,d=-.4,S=Math.sin(n*2.2)*.06,y=-.04;break;case"celebrate":h=u=-2.75,d=f=-.25,g=-.35,_=.35,m=Math.abs(Math.sin(n*8))*.32,y=-.15,l=c=m>.05?.4:.1,a=o=-l*.5;break;case"slump":y=.45,p=.22,h=u=.12,d=f=-.05;break;default:x=Math.sin(n*.5)*.25}const T=this.cur,E=(v,b,I=r)=>T[v]=T[v]===void 0?b:T[v]+(b-T[v])*I,P=t==="walk",U=P?Math.min(1,e*18):r;this.legL.pivot.rotation.x=E("hipL",a,U),this.legR.pivot.rotation.x=E("hipR",o,U),this.legL.joint.rotation.x=E("kneeL",l,U),this.legR.joint.rotation.x=E("kneeR",c,U),this.armL.pivot.rotation.x=E("shL",h,U),this.armR.pivot.rotation.x=E("shR",u,U),this.armL.pivot.rotation.z=E("outL",g),this.armR.pivot.rotation.z=E("outR",_),this.armL.joint.rotation.x=E("elL",d,U),this.armR.joint.rotation.x=E("elR",f,U),this.torso.rotation.x=E("lean",p),this.torso.scale.y=1+L,this.head.rotation.x=E("headX",y,r*.6),this.head.rotation.y=E("headY",x,r*.4),this.head.rotation.z=E("headZ",S,r*.6),this.body.position.y=P||t==="celebrate"?m:E("y",m),this.tail&&(this.tail.rotation.x=.35+Math.sin(n*(P?9.5:1.5))*(P?.12:.03))}express(t,e,n){n>this.blinkAt&&(this.blink=.14,this.blinkAt=n+2+Math.random()*4),this.blink=Math.max(0,this.blink-e);const s=this.blink>0,r=Math.min(1,e*12),a=this.cur,o=(p,y)=>a[p]=a[p]===void 0?y:a[p]+(y-a[p])*r;let l=1,c=0,h=0,u=1,d=1,f=!1;t==="happy"?(l=.3,c=.025,u=1.45,d=1.6):t==="think"?(c=.02,h=.25,u=.55,l=.9):t==="worried"?(h=-.35,c=.01,f=!0,u=.8):t==="talk"&&(u=.8,d=.6+Math.abs(Math.sin(n*13))*1.6,c=Math.sin(n*3)*.008),s&&t!=="happy"&&(l=.1);const g=o("eyeY",l);for(const p of this.eyes)p.scale.y=g;const _=o("browY",c),m=o("browTilt",h);this.brows.forEach((p,y)=>{p.position.y=.425+_,p.rotation.z=(y?-1:1)*m}),this.mouth.rotation.z=f?0:Math.PI,this.mouth.position.y=f?.18:.205,this.mouth.scale.set(o("mouthX",u),o("mouthY",d),1)}}const fn=40,Pn=30,Ve={x:7.6,z:10.9,felt:.84},wt={wall:"#f5f0e8",trim:"#d9cdbb",wood:"#c39a6b",woodDark:"#8c6440",metal:"#3b404c",rack:"#262a33",pot:"#e4d6c1",couch:"#5b7fa6",rug:"#c99b84",glass:"#cfe6f2",board:"#fbfaf7",chair:"#30343d"},Tl=new Map;function xe(i,t={}){const e=i+JSON.stringify(t);return Tl.has(e)||Tl.set(e,new On({color:i,roughness:.82,...t})),Tl.get(e)}function it(i,t,e,n,s,r,a,o,l){const c=new yt(new qe(t,e,n),l instanceof Ii?l:xe(s,l));return c.position.set(r,a,o),c.castShadow=!0,c.receiveShadow=!0,i.add(c),c}function ts(i,t,e,n,s){const r=document.createElement("canvas");r.width=n,r.height=s;const a=new ki(r);a.colorSpace=je,a.anisotropy=4;const o=new yt(new di(t,e),new ln({map:a,toneMapped:!1}));return i.add(o),{canvas:r,ctx:r.getContext("2d"),tex:a,mesh:o}}const ri='"Inter Variable", Inter, system-ui, sans-serif',nM='"JetBrains Mono", ui-monospace, monospace';function te(i,t,e,n,s,r,a,o,l=16,c){const h=new yt(new Un(t,e,n,l),c instanceof Ii?c:xe(s,c));return h.position.set(r,a,o),h.castShadow=!0,h.receiveShadow=!0,i.add(h),h}const Yu=["#5f9e6e","#477d55","#6fae74","#3f7350","#7dbb7a"];function iM(i,t,e,n,s=1,r="bush"){const a=new qt;a.position.set(e,0,n),a.rotation.y=e*1.7+n,a.scale.setScalar(s),te(a,.35,.27,.6,wt.pot,0,.3,0,18),te(a,.37,.37,.06,"#d8c8b0",0,.6,0,18),te(a,.31,.31,.02,"#5a4130",0,.62,0,18);const o=(l,c,h,u,d)=>{const f=new yt(new pr(l,0),xe(Yu[d%Yu.length],{flatShading:!0}));f.position.set(c,h,u),f.rotation.set(c*3,u*5,h),f.castShadow=!0,a.add(f)};if(r==="tall")te(a,.035,.05,1.5,wt.woodDark,0,1.35,0,6),o(.42,.12,1.55,.05,1),o(.48,-.15,1.95,-.08,0),o(.38,.18,2.3,.1,2),o(.3,-.05,2.6,0,4);else if(r==="snake")for(let l=0;l<7;l++){const c=l/7*Math.PI*2,h=.8+l*37%5*.12,u=new yt(new ta(.07,h,4),xe(l%2?"#4e8a5c":"#6f9f5a",{flatShading:!0}));u.position.set(Math.cos(c)*.12,.62+h/2,Math.sin(c)*.12),u.rotation.set(Math.sin(c)*.18,c,-Math.cos(c)*.18),u.scale.z=.35,u.castShadow=!0,a.add(u)}else o(.55,0,1,0,0),o(.4,.3,1.25,.1,1),o(.38,-.28,1.2,-.12,2),o(.36,.05,1.5,-.2,3);return i.add(a),t.block(e-.45*s,e+.45*s,n-.45*s,n+.45*s),a}function Uf(i,t,e,n){te(i,.09,.07,.12,"#e8dccb",t,e+.06,n,12);const s=new yt(new pr(.1,0),xe("#7aa874",{flatShading:!0}));s.position.set(t,e+.17,n),s.scale.y=.7,s.castShadow=!0,i.add(s)}function Uc(i,t,e,n,s=3){const r=["#e07a5f","#3d7ea6","#f2cc8f","#81b29a","#9c6ade"];for(let a=0;a<s;a++){const o=it(i,.34-a*.03,.05,.25,r[(a+Math.round(t*7))%r.length],t,e+.025+a*.05,n);o.rotation.y=(a-1)*.15}}function sM(i,t,e,n){const s=xe("#2f3440",{roughness:.5});te(i,.11,.12,.03,null,t,e+.015,n,16,s);const r=it(i,.03,.42,.03,null,t,e+.22,n,s);r.rotation.x=-.25;const a=it(i,.03,.03,.3,null,t,e+.42,n+.13,s);a.rotation.x=.35;const o=te(i,.05,.12,.14,null,t,e+.36,n+.27,16,xe("#e9b949",{roughness:.45}));o.rotation.x=.4;const l=new yt(new Di(.1,16),new ln({color:"#fff3c9"}));l.position.set(t,e+.3,n+.3),l.rotation.x=-Math.PI/2+.4,i.add(l)}function Ar(i,t,e,n,s,r,a="#3b3330"){const o=[it(i.g,n+.14,s+.14,.05,a,t,e,.18)],l=ts(i.g,n,s,Math.round(256*n),Math.round(256*s));l.mesh.position.set(t,e,.21),l.mesh.material=new On({map:l.tex,roughness:.9}),r(l.ctx,l.canvas.width,l.canvas.height),l.tex.needsUpdate=!0,o.push(l.mesh),i.attach.push(...o)}const Cr={sunset(i,t,e){i.fillStyle="#f4e3c8",i.fillRect(0,0,t,e),i.fillStyle="#e9967a",i.beginPath(),i.arc(t*.62,e*.45,t*.2,0,Math.PI*2),i.fill(),i.fillStyle="#8fb0a0",i.beginPath(),i.moveTo(0,e),i.lineTo(0,e*.62),i.quadraticCurveTo(t*.35,e*.4,t*.7,e*.66),i.lineTo(t,e*.58),i.lineTo(t,e),i.fill(),i.fillStyle="#4f7c74",i.beginPath(),i.moveTo(0,e),i.lineTo(0,e*.8),i.quadraticCurveTo(t*.5,e*.6,t,e*.82),i.lineTo(t,e),i.fill()},blocks(i,t,e){i.fillStyle="#f7f1e6",i.fillRect(0,0,t,e);const n=["#e07a5f","#3d405b","#81b29a","#f2cc8f"];i.fillStyle=n[0],i.fillRect(t*.12,e*.12,t*.42,e*.4),i.fillStyle=n[1],i.fillRect(t*.54,e*.12,t*.34,e*.22),i.fillStyle=n[2],i.fillRect(t*.54,e*.34,t*.34,e*.54),i.fillStyle=n[3],i.fillRect(t*.12,e*.52,t*.42,e*.36),i.fillStyle="#3d405b",i.beginPath(),i.arc(t*.33,e*.7,t*.1,0,Math.PI*2),i.fill()},arcs(i,t,e){i.fillStyle="#efe6d8",i.fillRect(0,0,t,e),["#c8553d","#f28f3b","#ffd5c2","#588b8b"].forEach((s,r)=>{i.strokeStyle=s,i.lineWidth=t*.07,i.beginPath(),i.arc(t/2,e*.85,t*(.38-r*.09),Math.PI,0),i.stroke()})},leaf(i,t,e){i.fillStyle="#e7ece4",i.fillRect(0,0,t,e),i.fillStyle="#5f8f6b",i.beginPath(),i.ellipse(t/2,e/2,t*.18,e*.36,.35,0,Math.PI*2),i.fill(),i.strokeStyle="#e7ece4",i.lineWidth=t*.015,i.beginPath(),i.moveTo(t*.38,e*.82),i.lineTo(t*.62,e*.18),i.stroke()}};function rM(i,t,e){const n=ts(i.g,.9,.9,256,256);n.mesh.geometry=new Di(.45,40),n.mesh.position.set(t,e,.22);const s=te(i.g,.5,.5,.08,"#3b3330",t,e,.17,40);s.rotation.x=Math.PI/2,i.attach.push(s,n.mesh);const r=()=>{const{ctx:a,tex:o}=n;a.fillStyle="#fbf8f2",a.fillRect(0,0,256,256),a.translate(128,128),a.fillStyle="#3b3330";for(let d=0;d<12;d++)a.save(),a.rotate(d/12*Math.PI*2),a.fillRect(-3,-112,6,d%3?12:22),a.restore();const l=new Date,c=l.getMinutes(),h=l.getHours()%12+c/60,u=(d,f,g,_)=>{a.save(),a.rotate(d),a.fillStyle=_,a.fillRect(-g/2,-f,g,f+14),a.restore()};u(h/12*Math.PI*2,62,9,"#3b3330"),u(c/60*Math.PI*2,92,6,"#3b3330"),a.fillStyle="#e07a5f",a.beginPath(),a.arc(0,0,8,0,Math.PI*2),a.fill(),a.setTransform(1,0,0,1,0,0),o.needsUpdate=!0};r(),setInterval(r,3e4)}function aM(){const i=document.createElement("canvas");i.width=i.height=512;const t=i.getContext("2d"),e=8,n=512/e;for(let r=0;r<e;r++)for(let a=0;a<e;a++){t.fillStyle=`hsl(${170+Math.random()*8}, ${9+Math.random()*4}%, ${82+Math.random()*2.5}%)`,t.fillRect(r*n,a*n,n,n),t.globalAlpha=.05;for(let o=0;o<40;o++)t.fillStyle=Math.random()<.5?"#000":"#fff",t.fillRect(r*n+Math.random()*n,a*n+Math.random()*n,2,2);t.globalAlpha=1,t.fillStyle="rgba(60, 80, 80, 0.09)",t.fillRect(r*n,a*n,n,1.5),t.fillRect(r*n,a*n,1.5,n)}const s=new ki(i);return s.colorSpace=je,s.wrapS=s.wrapT=Pi,s.repeat.set(24.5/8,12.6/8),s.anisotropy=8,s}let Da;function oM(i,t,e,n,s){if(!Da){const a=document.createElement("canvas");a.width=256,a.height=64;const o=a.getContext("2d"),l=o.createLinearGradient(0,0,256,0);l.addColorStop(0,"rgba(255, 236, 200, 0.55)"),l.addColorStop(1,"rgba(255, 236, 200, 0)"),o.fillStyle=l,o.fillRect(0,0,256,64),Da=new ki(a),Da.colorSpace=je}const r=new yt(new di(n,s),new ln({map:Da,transparent:!0,depthWrite:!1,blending:Xl,opacity:.5}));r.rotation.x=-Math.PI/2,r.position.set(t,.025,e),i.add(r)}let Al;function lM(){if(!Al){const i=zf();i.repeat.set(.5,.22),Al=new On({map:i,color:"#f0d6b4",roughness:.52})}return Al}let Gs;function cM(){if(Gs)return Gs;const i=document.createElement("canvas");i.width=384,i.height=128;const t=i.getContext("2d"),e=15,n=5,s=i.width/e,r=i.height/n,a=3;t.fillStyle="#cfcac1",t.fillRect(0,0,i.width,i.height);const o=(c,h,u,d)=>{t.fillStyle="#f7f5f1",t.fillRect(c,h,u,d),t.fillStyle="rgba(88, 84, 78, 0.22)",t.fillRect(c,h+d-2,u,2)};for(let c=0;c<n-1;c++)for(let h=0;h<e;h++)o(h*s+a,c*r+a,s-a*2,r-a*2);const l=(n-1)*r;for(const c of[0,1,2,11,12,13,14])o(c*s+a,l+a,s-a*2,r-a*2);return o(3*s+a,l+a,s*8-a*2,r-a*2),Gs=new ki(i),Gs.colorSpace=je,Gs.anisotropy=4,Gs}function Ku(i,t,e,n,s,r,a=500){const o=new qt;o.position.set(n,s,r),i.add(o);const l=new yt(new qe(t+.08,e+.12,.05),["#272d38","#272d38","#272d38","#272d38","#1e232c","#3c4352"].map(h=>xe(h)));l.position.set(0,-.015,-.03),l.castShadow=!0,l.receiveShadow=!0,o.add(l),it(o,(t+.08)*.55,.035,.012,"#323a47",0,-e*.34,-.056).castShadow=!1;const c=ts(o,t,e,Math.round(t*a),Math.round(e*a));return c.mesh.position.set(0,.015,.002),{g:o,face:c}}function hM(i,t,e,n){const s=xe("#23272f",{roughness:.6});te(i,.11,.13,.025,"#2f3440",t,e+.012,n,14),te(i,.022,.022,.3,"#2f3440",t,e+.16,n,10);const r=new yt(new ii(.11,.022,6,16,Math.PI),s);r.position.set(t,e+.3,n),r.castShadow=!0,i.add(r);for(const a of[-.11,.11]){const o=te(i,.065,.065,.05,null,t+a,e+.28,n,14,s);o.rotation.z=Math.PI/2,o.castShadow=!0}}function uM(i,t,e,n){const s=xe("#f4c430",{roughness:.45}),r=new yt(new li(.075,12,10),s);r.position.set(t,e+.06,n),r.scale.set(1,.85,1.25),r.castShadow=!0,i.add(r);const a=new yt(new li(.05,12,10),s);a.position.set(t,e+.15,n-.05),a.castShadow=!0,i.add(a);const o=new yt(new ta(.022,.06,8),xe("#e8833a",{roughness:.5}));o.position.set(t,e+.14,n-.11),o.rotation.x=-Math.PI/2,i.add(o);for(const l of[-.02,.02]){const c=new yt(new li(.008,6,6),xe("#1a1a1a"));c.position.set(t+l,e+.17,n-.085),i.add(c)}}function dM(i,t,e,n,s){const r=new qt;r.position.set(t,e,n),r.rotation.y=-.4+s%2*.8,i.add(r),it(r,.26,.21,.02,"#3b3330",0,.12,0);const a=ts(r,.21,.16,84,64);a.mesh.position.set(0,.125,.012);const{ctx:o,canvas:l}=a;o.fillStyle="#cfe3ef",o.fillRect(0,0,l.width,l.height),o.fillStyle="#8fb0a0",o.beginPath(),o.moveTo(0,l.height),o.quadraticCurveTo(l.width*.5,l.height*.35,l.width,l.height),o.fill(),o.fillStyle="#f2cc8f",o.beginPath(),o.arc(l.width*.72,l.height*.3,7,0,Math.PI*2),o.fill(),a.tex.needsUpdate=!0;const c=it(r,.02,.1,.02,"#3b3330",0,.05,-.04);c.rotation.x=.35}function fM(i,t,e,n){const s=it(i,.3,.035,.38,"#44506b",t,e+.018,n);s.rotation.y=.18;const r=it(i,.27,.02,.35,"#f6f2e8",t,e+.028,n+.01);r.rotation.y=.18,te(i,.009,.009,.24,"#e07a5f",t+.04,e+.045,n,8).rotation.set(0,.5,Math.PI/2)}function pM(i,t,e,n,s){const r=new qt;r.position.set(e,0,n);const a=it(r,2.5,.1,1.15,null,0,.78,0,lM());a.receiveShadow=!0,it(r,2.54,.03,1.19,wt.woodDark,0,.742,0);for(const E of[-1.08,1.08])it(r,.09,.72,.16,wt.metal,E,.37,0),it(r,.13,.06,1,wt.metal,E,.03,0),it(r,.13,.05,.86,wt.metal,E,.715,0);it(r,1.95,.07,.08,wt.metal,0,.67,-.18),it(r,2,.3,.04,wt.woodDark,0,.57,-.5);const o=it(r,1.3,.05,.12,"#2a2e38",0,.5,-.3);o.castShadow=!1,it(r,.58,.62,.56,"#e6ded0",.78,.31,-.2);for(const E of[.17,.45]){it(r,.5,.24,.02,"#f1ebe0",.78,E,.09);const P=te(r,.013,.013,.16,"#8d94a3",.78,E,.105,8);P.rotation.z=Math.PI/2}it(r,.17,.07,.2,wt.metal,0,.87,-.47),te(r,.03,.035,.52,wt.metal,0,1.12,-.47,12);const l=it(r,.055,.055,.32,wt.metal,0,1.35,-.38);l.rotation.x=.3,it(r,.14,.14,.05,wt.metal,0,1.42,-.31);const c=Ku(r,1.5,.84,0,1.46,-.295);c.g.rotation.x=.05;const h=new ln({color:"#2a3442",toneMapped:!1}),u=new yt(new Di(.014,12),h);u.position.set(.68,-.47,.03),c.g.add(u),s%3===1&&[["#f6d365",-.04,.09],["#f3a6b2",-.19,-.06]].forEach(([E,P,U])=>{const v=it(c.g,.11,.11,.004,E,.8,P,.02);v.rotation.z=U,v.castShadow=!1});const d=Ku(r,.6,.36,-.99,1.08,-.02,500);d.g.rotation.y=.62,it(d.g,.3,.03,.2,wt.metal,0,-.25,0),it(d.g,.06,.2,.06,wt.metal,0,-.14,0);const f=it(r,1.18,.008,.42,"#454d5e",0,.834,.16);f.castShadow=!1,it(r,.8,.022,.27,"#e9e6e1",-.02,.849,.15);const g=new yt(new di(.76,.23),new On({map:cM(),roughness:.7}));g.rotation.x=-Math.PI/2,g.position.set(-.02,.861,.15),g.receiveShadow=!0,r.add(g);const _=new yt(new li(.055,12,8),xe("#e9e6e1"));_.position.set(.52,.843,.18),_.scale.set(1,.6,1.45),_.castShadow=!0,r.add(_),it(r,.012,.004,.05,"#9aa3b2",.52,.874,.15).castShadow=!1;const m=["#e07a5f","#3d7ea6","#f2cc8f","#81b29a"][s%4];te(r,.07,.065,.16,m,.66,.91,-.08,14);const p=new yt(new ii(.045,.012,6,12,Math.PI*1.2),xe(m));p.position.set(.73,.92,-.08),p.rotation.y=Math.PI/2,p.rotation.z=-.3,r.add(p);const y=new yt(new Di(.062,14),xe("#4a3328",{roughness:.3}));y.rotation.x=-Math.PI/2,y.position.set(.66,.985,-.08),r.add(y),[()=>sM(r,.98,.83,-.38),()=>Uf(r,1,.83,-.3),()=>Uc(r,.98,.83,-.32),()=>hM(r,1,.83,-.3),()=>uM(r,1,.83,-.28),()=>dM(r,1,.83,-.3,s)][s%6](),s%4===2&&fM(r,-.55,.835,-.18);const x=new qt;x.position.set(.86,.835,.44),r.add(x),it(x,.46,.022,.1,"#2f343f",0,.011,0);const S=ts(x,.42,.11,256,67);S.mesh.position.set(0,.07,.015),S.mesh.rotation.x=-.42,S.mesh.material=new On({map:S.tex,roughness:.75});const L=Of(wt.chair);L.position.set(0,0,1.05),r.add(L),i.add(r),t.block(e-1.3,e+1.3,n-.7,n+.5);const T={index:s,x:e,z:n,seat:new R(e,0,n+1.05),seatY:ee,screen:c.face,side:d.face,plate:S,led:h,chair:L};return Ff(T,{}),T}function Of(i){const t=new qt,e=xe("#3c4250",{roughness:.9});it(t,.6,.07,.58,i,0,ee-.035,0);const n=it(t,.56,.05,.54,null,0,ee+.01,.01,e);n.castShadow=!1;const s=new qt;s.position.set(0,ee,.3),s.rotation.x=.12,t.add(s),it(s,.56,.3,.09,i,0,.19,0),it(s,.52,.34,.05,null,0,.52,.005,e);for(const r of[-.25,.25])it(s,.05,.36,.06,i,r,.52,0);it(s,.34,.13,.06,i,0,.79,-.01);for(const r of[-.33,.33]){it(t,.05,.22,.4,i,r,ee+.09,.06);const a=it(t,.09,.05,.44,null,r,ee+.21,.04,e);a.castShadow=!1}te(t,.055,.055,.18,"#6e7684",0,ee-.14,0,12),te(t,.042,.042,ee-.22,wt.metal,0,(ee-.22)/2+.06,0,10),te(t,.11,.13,.05,wt.metal,0,.08,0,14);for(let r=0;r<5;r++){const a=r/5*Math.PI*2,o=it(t,.07,.045,.3,wt.metal,0,.075,0);o.position.set(Math.sin(a)*.17,.075,Math.cos(a)*.17),o.rotation.y=a;const l=te(t,.035,.035,.025,"#22262e",Math.sin(a)*.31,.04,Math.cos(a)*.31,10);l.rotation.z=Math.PI/2,l.rotation.y=a}return t}function Zu(i,t,e,n,s){const r=new qt;r.position.set(e,0,n),r.rotation.y=s,it(r,1.35,ee-.14,1.2,wt.couch,0,(ee-.14)/2,0),it(r,1.15,.14,1,"#6c8fb6",0,ee-.07,.05),it(r,1.35,.78,.26,wt.couch,0,ee+.25,-.47);for(const o of[-.54,.54])it(r,.27,.56,1.2,wt.couch,o,ee-.06,0);for(const[o,l]of[[-.55,-.5],[.55,-.5],[-.55,.5],[.55,.5]])te(r,.05,.04,.12,wt.woodDark,o,.06,l,8);i.add(r);const a=.75;return t.block(e-a,e+a,n-a,n+a),r}function mM(i,t,e,n){te(i,.26,.26,.08,n,t,ee-.04,e,20),te(i,.035,.035,ee-.09,wt.metal,t,(ee-.09)/2,e,8),te(i,.2,.22,.03,wt.metal,t,.015,e,16)}function Ju(i,{title:t="",subtitle:e="",lines:n=[],accent:s="#7bd389",idle:r=!1,t:a=0}){const{ctx:o,canvas:l,tex:c}=i.screen,h=l.width,u=l.height,d=h/512,f=o.createLinearGradient(0,0,0,u);if(f.addColorStop(0,"#141c26"),f.addColorStop(1,"#0d131b"),o.fillStyle=f,o.fillRect(0,0,h,u),r){o.textAlign="center",o.fillStyle="#2f3a49",o.font=`600 ${34*d}px ${ri}`,o.fillText(t,h/2,u/2+4*d),o.fillStyle="#263040",o.font=`400 ${20*d}px ${ri}`,o.fillText(e,h/2,u/2+36*d),o.textAlign="left",c.needsUpdate=!0;return}o.fillStyle=s,o.fillRect(0,0,h,5*d),o.globalAlpha=.09,o.fillRect(0,5*d,h,76*d),o.globalAlpha=1,o.beginPath(),o.arc(30*d,40*d,6*d,0,Math.PI*2),o.fillStyle=s,o.globalAlpha=.55+.45*Math.sin(a*3),o.fill(),o.globalAlpha=1,o.fillStyle="#eaeff5",o.font=`650 ${26*d}px ${ri}`,o.fillText(t,46*d,48*d),o.fillStyle="#7d8a9c",o.font=`400 ${18*d}px ${ri}`,o.fillText(e,46*d,73*d),o.fillStyle="rgba(125, 138, 156, 0.22)",o.fillRect(24*d,92*d,1.5*d,u-104*d),o.font=`400 ${18*d}px ${nM}`;const g=n.slice(-8);g.forEach((_,m)=>{const p=m===g.length-1,y=116*d+m*23*d;o.globalAlpha=p?1:.45+m*.06,o.fillStyle=_.color||(p?"#eaeff5":"#8b98aa");let x=_.text;for(;o.measureText(x).width>h-56*d&&x.length>4;)x=x.slice(0,-2);x!==_.text&&(x=x.slice(0,-1)+"…"),o.fillText(x,38*d,y),o.globalAlpha=1}),Math.floor(a*2)%2===0&&(o.fillStyle=s,o.fillRect(38*d,116*d+g.length*23*d-14*d,9*d,17*d)),c.needsUpdate=!0}function Ff(i,{name:t="",accent:e="#7d8a9c",state:n="open"}={}){const s=n==="working";i.led&&i.led.color.set(s?e:n==="open"?"#232a35":"#39455a");const r=i.plate;if(r){const{ctx:o,canvas:l,tex:c}=r;o.fillStyle="#2c323d",o.fillRect(0,0,l.width,l.height),o.fillStyle=n==="open"?"#454c5a":e,o.fillRect(0,0,9,l.height),o.fillStyle=n==="open"?"#8d97a6":"#f3f1ed",o.font=`650 30px ${ri}`,o.textBaseline="middle",o.fillText(t,26,l.height/2+1),o.textBaseline="alphabetic",c.needsUpdate=!0}const a=i.side;if(a){const{ctx:o,canvas:l,tex:c}=a,h=l.width,u=l.height;if(o.fillStyle=n==="open"?"#0b0f15":"#121a24",o.fillRect(0,0,h,u),n==="open"){o.fillStyle="#1b2430",o.beginPath(),o.arc(h/2,u/2,5,0,Math.PI*2),o.fill(),c.needsUpdate=!0;return}o.fillStyle=e,o.globalAlpha=.85,o.fillRect(0,0,h,4),o.globalAlpha=1,o.font=`600 ${Math.round(u*.1)}px ${ri}`,o.fillStyle="#6f7d8f",o.fillText(t.toUpperCase(),14,26),o.textAlign="right",o.fillStyle=s?e:"#4d5a6b",o.fillText(s?"ACTIVE":n==="away"?"OFFLINE":"IDLE",h-14,26),o.textAlign="left";let d=0;for(const f of t+n)d=(d*31+f.charCodeAt(0))%9973;for(let f=0;f<6;f++){const g=44+f*Math.round((u-58)/6),_=Math.max(4,Math.round(u*.045));o.fillStyle="#1b2531",o.fillRect(14,g,h-28,_),d=(d*31+17)%9973;const m=s?.25+d%70/100:.08+d%25/100;o.fillStyle=f===0&&s?e:"#35445a",o.fillRect(14,g,Math.round((h-28)*m),_)}c.needsUpdate=!0}}function gM(i){const t=new Ky(fn,Pn),e=[],n=xe("#a97a50"),s=new On({map:zf(),roughness:.7}),r=new yt(new qe(fn+.6,.7,Pn+.6),[n,n,s,n,n,n]);r.position.y=-.35,r.receiveShadow=!0,r.castShadow=!0,i.add(r);const a=new yt(new di(160,160),new dy({opacity:.14}));a.rotation.x=-Math.PI/2,a.position.y=-.72,a.receiveShadow=!0,i.add(a),i.add(vM(fn+16,Pn+16));const o=it(i,24.5,.02,12.6,null,0,.011,1.2,new On({map:aM(),roughness:1}));o.castShadow=!1;const l=[Ia(i,fn+.6,0,-Pn/2-.15,0,[0,0,-1]),Ia(i,fn+.6,0,Pn/2+.15,Math.PI,[0,0,1],[[-fn/2-.3,-19.2],[-16.8,fn/2+.3]]),Ia(i,Pn,-fn/2-.15,0,Math.PI/2,[-1,0,0]),Ia(i,Pn,fn/2+.15,0,-Math.PI/2,[1,0,0])],[c,,h,u]=l;t.block(-fn/2,fn/2,-Pn/2,-Pn/2+.2),t.block(-fn/2,-fn/2+.2,-Pn/2,Pn/2);for(const W of[-6,0,6]){const A=-W;h.attach.push(it(h.g,3.6,2.2,.06,wt.glass,A,2.2,.15,{emissive:"#bfe3f5",emissiveIntensity:.45,roughness:.15}),it(h.g,3.8,.12,.14,wt.trim,A,1.08,.2),it(h.g,3.8,.12,.14,wt.trim,A,3.32,.2),it(h.g,.1,2.3,.14,wt.trim,A,2.2,.2))}for(const W of[-6,0,6])oM(i,-17.4,W,5,3.6);const d=[];[[-9,-3],[-3,-3],[3,-3],[9,-3],[-9,5],[-3,5],[3,5],[9,5]].forEach(([W,A],It)=>d.push(pM(i,t,W,A,It)));const f=["#e07a5f","#3d7ea6","#f2cc8f","#81b29a","#9c6ade","#e5989b","#2a9d8f","#577590"];for(const W of[-18.4,-16.2,-14,-11.8]){it(i,2,3.2,.7,wt.woodDark,W,1.6,-14.5);for(let A=0;A<4;A++){const It=.45+A*.75;it(i,1.86,.05,.62,wt.wood,W,It-.04,-14.42);let Ct=W-.85;for(;Ct<W+.8;){const zt=.1+Math.random()*.1,Dt=.4+Math.random()*.22;it(i,zt,Dt,.45,f[Math.floor(Math.random()*f.length)],Ct+zt/2,It+Dt/2,-14.4),Ct+=zt+.02}}}t.block(-19.6,-10.7,-15,-14);for(const W of[12,13.4,14.8,16.2,17.6]){it(i,1.2,2.7,1,wt.rack,W,1.35,-14.4);for(let A=0;A<9;A++){const It=it(i,.07,.07,.03,"#000",W-.4+A%3*.12,.5+Math.floor(A/3)*.7+Math.random()*.2,-13.88,new On({color:"#0a0a0a",emissive:["#4ade80","#60a5fa","#fbbf24"][A%3],emissiveIntensity:1.2}));It.castShadow=!1,e.push(It)}for(let A=0;A<6;A++)it(i,1,.02,.02,"#4b5261",W,.35+A*.42,-13.89)}t.block(11.2,18.4,-15,-13.7);const g=new qt;g.position.set(-18.6,0,0);const _=new yt(new Un(.35,.45,.9,16),xe(wt.woodDark));_.position.y=.45;const m=new yt(new li(.45,24,16),xe("#4f8fc0",{roughness:.5}));m.position.y=1.35;const p=new yt(new pr(.46,1),xe("#7fb069",{flatShading:!0,transparent:!0,opacity:.85}));p.position.y=1.35,p.scale.set(1,.9,.7);for(const W of[_,m,p])W.castShadow=!0,g.add(W);i.add(g),t.block(-19.2,-18,-.6,.6);const y=new qt;y.position.set(15.6,0,-8),it(y,5,2.4,.08,wt.board,0,1.9,0,{roughness:.4}),it(y,5.2,.1,.14,wt.metal,0,.66,.02),it(y,.08,1.9,.08,wt.metal,-2.3,.6,0),it(y,.08,1.9,.08,wt.metal,2.3,.6,0);const x=ts(y,4.8,2.2,640,290);x.mesh.position.set(0,1.9,.045),i.add(y),t.block(13,18.2,-8.4,-7.6);const S=it(i,9,.02,5.4,wt.rug,-14,.01,10.6);S.castShadow=!1;const L=new qt;L.position.set(-14.5,0,8.4),it(L,5,ee-.14,1.2,wt.couch,0,(ee-.14)/2,0),it(L,5,.8,.3,wt.couch,0,ee+.26,-.48);for(const W of[-2.35,2.35])it(L,.3,.6,1.2,wt.couch,W,ee-.08,0);for(const W of[-1.5,0,1.5])it(L,1.4,.14,1,"#6c8fb6",W,ee-.07,.05);for(const[W,A]of[[-2.2,-.5],[2.2,-.5],[-2.2,.5],[2.2,.5]])te(L,.05,.04,.12,wt.woodDark,W,.06,A,8);i.add(L),t.block(-17,-12,7.8,9),Zu(i,t,-17.3,10.9,Math.PI/2),Zu(i,t,-12,10.9,-Math.PI/2),it(i,2.4,.08,1.2,wt.wood,-14.5,.48,10.6);for(const[W,A]of[[-1.1,-.5],[1.1,-.5],[-1.1,.5],[1.1,.5]])it(i,.06,.44,.06,wt.metal,-14.5+W,.22,10.6+A);t.block(-15.8,-13.2,10,11.2),it(i,1.3,.95,3.2,"#efe9df",-19.3,.475,12),it(i,.55,.65,.5,"#2c2f36",-19.35,1.28,11.4),it(i,.12,.08,.12,"#c0392b",-19.05,1.4,11.4,{emissive:"#c0392b",emissiveIntensity:.6});for(let W=0;W<3;W++){const A=new yt(new Un(.07,.06,.14,10),xe("#ffffff"));A.position.set(-19.2,1.02,12.5+W*.25),i.add(A)}t.block(-20,-18.6,10.4,13.6);const T=new qt;T.position.set(-11,0,12),te(T,.3,.34,.04,wt.metal,0,.02,0,20),te(T,.04,.04,1.05,wt.metal,0,.55,0,10),te(T,.48,.48,.05,wt.wood,0,1.08,0,28);for(const[W,A,It]of[[-.18,.08,"#e07a5f"],[.2,-.1,"#3d7ea6"]])te(T,.06,.05,.13,It,W,1.17,A,12);i.add(T),t.block(-11.5,-10.5,11.5,12.5),c.attach.push(it(c.g,9.4,3.5,.08,"#d9cdbb",0,2.2,.2));const E=ts(c.g,9,3.2,1536,546);E.mesh.position.set(0,2.2,.26),c.attach.push(E.mesh);const P=new qt;P.position.set(15.5,0,10.6),it(P,3.4,1.05,.9,"#efe9df",0,.525,0),it(P,3.5,.06,1,wt.wood,0,1.08,0),it(P,.9,.55,.05,wt.metal,-.8,1.4,-.25);const U=ts(P,1.6,.34,400,85);U.mesh.position.set(0,.62,.456),U.ctx.fillStyle="#efe9df",U.ctx.fillRect(0,0,400,85),U.ctx.fillStyle="#1d1b18",U.ctx.font=`650 38px ${ri}`,U.ctx.textAlign="center",U.ctx.fillText("Chief of Staff",200,56),U.tex.needsUpdate=!0;const v=Of(wt.chair);v.position.set(0,0,-1),v.rotation.y=Math.PI,P.add(v),i.add(P),t.block(13.7,17.3,10.1,11.1);const b=it(i,2.4,.02,1.6,"#b9a58f",18.2,.01,13.4);b.castShadow=!1,Ar(c,-7.6,2.5,1.6,1.1,Cr.sunset),rM(c,7.6,2.7),Ar(u,1.4,2.4,1,1.4,Cr.arcs),Ar(u,3,2.4,1,1.4,Cr.blocks),Ar(u,4.6,2.4,1,1.4,Cr.leaf),Ar(h,11,2.5,1.2,.9,Cr.blocks,"#c39a6b");const I=new qt;I.position.set(19.35,0,3),it(I,.7,.75,3.6,wt.woodDark,0,.4,0),it(I,.76,.05,3.7,wt.wood,0,.8,0);for(const W of[-1.2,0,1.2])it(I,.02,.6,1.1,"#9a7350",-.36,.4,W);for(const[W]of[[-1.7],[1.7]])it(I,.6,.06,.06,wt.metal,0,.03,W);Uc(I,0,.82,-1.1,4),Uf(I,0,.82,.2),te(I,.11,.08,.38,"#3d7ea6",.05,1.01,1.2,14,{roughness:.35});for(let W=0;W<3;W++){const A=te(I,.008,.008,.5,"#5f8f6b",.05+(W-1)*.04,1.4,1.2,4);A.rotation.z=(W-1)*.3;const It=new yt(new pr(.06,0),xe(["#f2cc8f","#e5989b","#fff"][W],{flatShading:!0}));It.position.set(.05+(W-1)*.12,1.64,1.2),I.add(It)}i.add(I),t.block(18.9,20,1.1,4.9);const O=new qt;O.position.set(-1,0,11.6),it(O,5.2,.08,1.4,wt.wood,0,.78,0);for(const W of[-2.3,2.3])it(O,.08,.74,1.1,wt.metal,W,.38,0);for(const W of[-1.7,0,1.7])for(const A of[-1.05,1.05])mM(O,W,A,["#e07a5f","#f2cc8f","#81b29a"][Math.round(W+2)%3]);Uc(O,-1.4,.82,.1,2),te(O,.06,.06,.14,"#ffffff",.5,.89,-.2,12);const $=new qt;$.position.set(1.3,.82,.1),it($,.5,.025,.35,"#c7ccd4",0,.012,0);const Y=it($,.5,.34,.02,"#c7ccd4",0,.17,-.17);Y.rotation.x=-.25,O.add($);for(const W of[-1.6,1.6]){te(O,.02,.02,1.6,"#2f3440",W,3.4,0,6);const A=te(O,.06,.32,.28,"#2f3440",W,2.55,0,20,{roughness:.5});A.castShadow=!1;const It=new yt(new Di(.29,20),new ln({color:"#fff1c4"}));It.rotation.x=Math.PI/2,It.position.set(W,2.405,0),O.add(It)}i.add(O),t.block(-3.8,1.8,10.3,12.9);const z=new qt;z.position.set(Ve.x,0,Ve.z);const K=.84;it(z,3.7,.22,2.1,wt.woodDark,0,.71,0);for(const[W,A]of[[-1.55,-.85],[1.55,-.85],[-1.55,.85],[1.55,.85]])it(z,.2,.62,.2,wt.woodDark,W,.31,A);it(z,3.5,.03,1.9,"#2f7a57",0,K-.015,0,{roughness:1});const V=[];for(const W of[-1,1]){for(const A of[-1,1])V.push([1.32,.1,.25,W*.82,A*.925]);V.push([.25,.1,1.36,W*1.725,0])}for(const[W,A,It,Ct,zt]of V)it(z,W,A,It,wt.wood,Ct,K+.05,zt);for(const W of[-1,1])for(const A of[-1,1])it(z,.3,.1,.3,wt.wood,W*1.83,K+.05,A*.98);for(const[W,A,It,Ct]of[[1.28,.06,.82,.83],[1.28,.06,.82,-.83],[1.28,.06,-.82,.83],[1.28,.06,-.82,-.83]])it(z,W,.05,A,"#256646",It,K+.025,Ct).castShadow=!1;for(const W of[-1,1])it(z,.06,.05,1.3,"#256646",W*1.57,K+.025,0).castShadow=!1;const at=new ln({color:"#0c0d10"});for(const[W,A]of[[-1.6,-.8],[1.6,-.8],[-1.6,.8],[1.6,.8],[0,-.835],[0,.835]]){const It=new yt(new Un(.15,.15,.02,20),at);It.position.set(W,K+.002,A),z.add(It)}i.add(z),t.block(Ve.x-1.95,Ve.x+1.95,Ve.z-1.15,Ve.z+1.15);const ct=new qt;ct.position.set(-18,0,8.2),te(ct,.22,.24,.04,"#2f3440",0,.02,0,20),te(ct,.025,.025,1.7,"#2f3440",0,.87,0,8);const _t=te(ct,.22,.3,.38,"#f3e7d3",0,1.85,0,24,{emissive:"#ffe2a8",emissiveIntensity:.35,roughness:.9});_t.castShadow=!1,i.add(ct),t.block(-18.4,-17.6,7.8,8.6);const Gt=it(i,5,.02,3.2,"#c9b79c",15.5,.012,12.6,{roughness:1});Gt.castShadow=!1;const Jt=it(i,4.6,.022,2.8,"#ddd0bb",15.5,.013,12.6,{roughness:1});Jt.castShadow=!1;const X=[[-19,-9.5,1.1,"tall"],[10,-14,1,"snake"],[-9.8,-14.2,.9,"bush"],[19,-11,1.2,"tall"],[-10.3,14,1,"bush"],[6.2,13.8,1.1,"tall"],[19,8.5,1,"snake"],[19.2,0,.9,"bush"],[-19.1,14.2,.8,"snake"],[11.6,13.9,1,"bush"]];for(const[W,A,It,Ct]of X)iM(i,t,W,A,It,Ct);const et={n:Math.PI,s:0,w:-Math.PI/2,e:Math.PI/2},ft=W=>W.map(([A,It,Ct,zt,Dt])=>({pos:new R(A,0,It),face:et[Ct],pose:zt,seatY:Dt,taken:null})),ot={library:{label:"Library",spots:ft([[-17.6,-12.9,"n","read"],[-15.3,-12.9,"n","read"],[-13.1,-12.9,"n","read"],[-11,-12.9,"n","read"]])},servers:{label:"Server room",spots:ft([[12.7,-12.6,"n","type"],[14.1,-12.6,"n","type"],[15.5,-12.6,"n","type"],[16.9,-12.6,"n","type"]])},window:{label:"Research window",spots:ft([[-17.5,-6,"w","gaze"],[-17.5,-2.6,"w","gaze"],[-17.5,2.6,"w","gaze"],[-17.5,6,"w","gaze"]])},whiteboard:{label:"Whiteboard",spots:ft([[13.9,-6.4,"n","write"],[15.2,-6.4,"n","write"],[16.5,-6.4,"n","write"],[17.8,-6.4,"n","write"]])},lounge:{label:"Break room",spots:ft([[-16,8.5,"s","couch",ee],[-14.5,8.5,"s","couch",ee],[-13,8.5,"s","couch",ee],[-17.2,10.9,"e","couch",ee],[-11.9,10.9,"w","couch",ee],[-2.7,10.55,"s","sit",ee],[-1,10.55,"s","sit",ee],[.7,10.55,"s","sit",ee],[-2.7,12.65,"n","sit",ee],[-1,12.65,"n","sit",ee],[.7,12.65,"n","sit",ee],[-17.9,11.4,"w","mug"],[-17.9,12.8,"w","mug"],[-11.95,12,"e","mug"],[-10.05,12,"w","mug"]])}},At=new R(15.3,0,-2.4),Tt=Array.from({length:10},(W,A)=>{const It=Math.PI+A/10*Math.PI*2,Ct=new R(At.x+Math.sin(It)*2.3,0,At.z+Math.cos(It)*2.3);return{pos:Ct,face:Math.atan2(At.x-Ct.x,At.z-Ct.z)}});ot.lounge.spots.push({pos:new R(Ve.x-.9,0,Ve.z-1.65),face:et.s,pose:"stand",taken:null,game:!0},{pos:new R(Ve.x+.9,0,Ve.z+1.65),face:et.n,pose:"stand",taken:null,game:!0});const Ft=(W,A,It,Ct,zt)=>({pos:new R(W,0,A),face:Math.atan2(It-W,Ct-A),pose:zt,taken:null});return ot.hotdesk={label:"Hot desks",spots:[-4.5,-2.7,-.9,.9,2.7,4.5].map(W=>Ft(W,-13.4,W,-15,"read"))},ot.poolside={label:"Pool table",spots:[[4.9,10.9],[10.3,10.9],[9.6,8.8],[5.6,8.8]].map(([W,A])=>Ft(W,A,Ve.x,Ve.z,"mug"))},ot.coffee={label:"Coffee",spots:ot.lounge.spots.filter(W=>W.pose==="mug")},ot.huddle={label:"Break-room table",spots:[[-4.5,11],[-4.5,12.2],[2.5,11],[2.5,12.2],[-1.85,9.6],[-.15,9.6]].map(([W,A])=>Ft(W,A,-1,11.6,"stand"))},{grid:t,desks:d,stations:ot,pool:z,standup:Tt,board:E,scribble:x,blinkers:e,globe:p,slab:r,updateWalls:(W,A,It)=>xM(l,W,A,It),door:new R(18.6,0,14.4),reception:{seat:new R(15.5,0,9.6),seatY:ee}}}function zf(){const i=document.createElement("canvas");i.width=i.height=1024;const t=i.getContext("2d"),e=16,n=i.height/e;for(let r=0;r<e;r++){let a=-Math.random()*400;for(;a<i.width;){const o=380+Math.random()*520,l=73+Math.random()*3.5;t.fillStyle=`hsl(${32+Math.random()*3}, ${33+Math.random()*5}%, ${l}%)`,t.fillRect(a,r*n,o,n),t.globalAlpha=.045;for(let c=0;c<6;c++)t.fillStyle=Math.random()<.5?"#7a5634":"#fff6e8",t.fillRect(a,r*n+Math.random()*n,o,1+Math.random()*2);t.globalAlpha=1,t.fillStyle="rgba(90, 60, 35, 0.22)",t.fillRect(a,r*n,2,n),a+=o}t.fillStyle="rgba(90, 60, 35, 0.18)",t.fillRect(0,r*n,i.width,2)}const s=new ki(i);return s.colorSpace=je,s.wrapS=s.wrapT=Pi,s.repeat.set(fn/8,Pn/8),s.anisotropy=8,s}function vM(i,t){const e=document.createElement("canvas");e.width=e.height=256;const n=e.getContext("2d"),s=n.createRadialGradient(128,128,30,128,128,128);s.addColorStop(0,"rgba(60, 40, 20, 0.28)"),s.addColorStop(.6,"rgba(60, 40, 20, 0.12)"),s.addColorStop(1,"rgba(60, 40, 20, 0)"),n.fillStyle=s,n.fillRect(0,0,256,256);const r=new ki(e),a=new yt(new di(i,t),new ln({map:r,transparent:!0,depthWrite:!1}));return a.rotation.x=-Math.PI/2,a.position.y=-.715,a}const Ks=4.2,_M=.5;function Ia(i,t,e,n,s,r,a=[[-t/2,t/2]]){const o=new qt;o.position.set(e,0,n),o.rotation.y=s;const l=new qt,c=new qt;o.add(l,c);for(const[u,d]of a){const f=new yt(new qe(d-u,Ks,.3),xe(wt.wall));f.position.set((u+d)/2,Ks/2,0),f.castShadow=f.receiveShadow=!0,l.add(f);const g=new yt(new qe(d-u,.1,.36),xe("#cbbba3"));g.position.set((u+d)/2,.05,0),c.add(g);const _=new yt(new qe(d-u,.22,.04),xe(wt.trim));_.position.set((u+d)/2,.11,.17),o.add(_)}i.add(o);const h={g:o,body:l,cap:c,outward:new R(...r),h:Ks,attach:[]};return c.position.y=Ks,h}const Qu=new R;function xM(i,t,e,n){Qu.subVectors(t.position,e).setY(0).normalize();for(const s of i){const r=s.outward.dot(Qu)>.2?_M:Ks;s.h+=(r-s.h)*Math.min(1,n*7),s.body.scale.y=s.h/Ks,s.cap.position.y=s.h;for(const a of s.attach)a.visible=s.h>3.4}}const yM={queued:0,working:1,done:2,failed:2,stopped:2},MM={queued:"#fde68a",working:"#bfdbfe",done:"#bbf7d0",failed:"#fecaca",stopped:"#e5e7eb"};function Bf(i,t){const{ctx:e,canvas:n,tex:s}=i,r=n.width,a=n.height;e.fillStyle="#fbfaf7",e.fillRect(0,0,r,a);const o=["Queued","Working","Shipped"],l=r/3;o.forEach((c,h)=>{e.fillStyle="#1d1b18",e.font=`650 34px ${ri}`,e.fillText(c,h*l+28,54),h&&(e.fillStyle="#e7e1d7",e.fillRect(h*l,20,3,a-40)),t.filter(d=>yM[d.status]===h).sort((d,f)=>(f.endedAt||f.queuedAt)-(d.endedAt||d.queuedAt)).slice(0,6).forEach((d,f)=>{const g=h*l+28+f%2*(l/2-18),_=80+Math.floor(f/2)*150,m=l/2-36,p=130;e.save(),e.translate(g+m/2,_+p/2),e.rotate((d.id.charCodeAt(0)%7-3)*.008),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(-m/2+4,-p/2+6,m,p),e.fillStyle=MM[d.status],e.fillRect(-m/2,-p/2,m,p),e.fillStyle="#1d1b18",e.font=`600 22px ${ri}`,bM(e,d.title,-m/2+14,-p/2+34,m-28,26,3),e.fillStyle="#5b554c",e.font=`400 18px ${ri}`,e.fillText(d.repo.slice(0,22),-m/2+14,p/2-14),e.restore()})}),s.needsUpdate=!0}function bM(i,t,e,n,s,r,a){const o=String(t).split(/\s+/);let l="",c=0;for(let h=0;h<o.length;h++){const u=l?l+" "+o[h]:o[h];if(i.measureText(u).width>s&&l){if(c===a-1){i.fillText(l+"…",e,n+c*r);return}i.fillText(l,e,n+c*r),l=o[h],c++}else l=u}i.fillText(l,e,n+c*r)}function Oc(i,t){const{ctx:e,canvas:n,tex:s}=i;e.fillStyle="#fbfaf7",e.fillRect(0,0,n.width,n.height),e.fillStyle="#2f5d8a",e.font='600 30px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive',e.fillText("Today",26,46),e.font='400 24px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive',t.slice(0,7).forEach((r,a)=>{e.fillStyle=r.done?"#6b8f71":"#3a3a3a";const o=(r.done?"✓ ":"• ")+r.text;e.fillText(o.length>44?o.slice(0,43)+"…":o,30,86+a*30)}),s.needsUpdate=!0}const td=(i,t,e)=>{let n=((t-i+Math.PI)%(Math.PI*2)+Math.PI*2)%(Math.PI*2)-Math.PI;return i+n*e},Rr=(i,t)=>i+Math.random()*(t-i);function ka(i,t=34){let e=String(i||"").replace(/\s+/g," ").trim();const n=e.search(/[,;:]| \u2014 | - | and | with | so that | in order /i);if(n>11&&(e=e.slice(0,n)),e.length<=t)return e;const s=e.lastIndexOf(" ",t);return e.slice(0,s>t*.6?s:t).replace(/[,.;:]$/,"")+"…"}const ed=["coffee?","anyone seen my mug","back in 5","nice weather","who broke main","lunch soon?","reading the docs, honestly","standup when"];let Cl=null;function SM(){if(Cl)return Cl;const i=document.createElement("canvas");i.width=i.height=64;const t=i.getContext("2d"),e=t.createRadialGradient(32,32,4,32,32,32);return e.addColorStop(0,"rgba(40, 28, 16, 0.32)"),e.addColorStop(1,"rgba(40, 28, 16, 0)"),t.fillStyle=e,t.fillRect(0,0,64,64),Cl=new ki(i)}class xh{constructor(t,e,n,s={}){this.staff=t,this.id=t.id,this.name=t.name,this.world=e,this.desk=s.desk||e.desks[e.agentIndex(t.id)],this.deskFace=s.face??Math.PI,this.root=new qt,this.fig=new Gr(t),this.root.add(this.fig.group),this.body=this.fig.body;const r=new yt(new Di(.5,24),new ln({map:SM(),transparent:!0,depthWrite:!1}));r.rotation.x=-Math.PI/2,r.position.y=.015,this.root.add(r),this.ring=new yt(new mh(.55,.68,40),new ln({color:t.shirt,transparent:!0,opacity:.9})),this.ring.rotation.x=-Math.PI/2,this.ring.position.y=.03,this.ring.visible=!1,this.root.add(this.ring),this.root.traverse(c=>{c.userData.agentId=t.id}),e.scene.add(this.root),this.pos=this.root.position,this.heading=0,this.path=[],this.goal=null,this.placeKey=null,this.spot=null,this.pose="stand",this.want="lounge",this.dwellUntil=0,this.wanderAt=0,this.chatAt=Rr(8,30),this.anim=null,this.job=null,this.lines=[],this.phase=Math.random()*10,this.label=document.createElement("div"),this.label.className="agent-label";const a=document.createElement("div");a.className="bubble";const o=document.createElement("div");o.className="name";const l=document.createElement("i");/^#[0-9a-f]{3,8}$/i.test(t.shirt??"")&&(l.style.background=t.shirt),o.append(l,String(t.name??"")),this.label.append(a,o),this.bubbleEl=this.label.querySelector(".bubble"),n.appendChild(this.label),this.say("")}say(t,e="",n=0){t!==this.bubbleText&&(this.labelDirty=!0),this.bubbleText=t,this.bubbleEl.textContent=t,this.bubbleEl.className="bubble"+(e?" "+e:""),this.bubbleEl.style.display=t?"":"none",this.bubbleUntil=n?(this.now||0)+n/1e3:0}teleport(t){const e=this.resolve(t);e&&(this.pos.copy(e.pos),this.heading=e.face,this.root.rotation.y=e.face,this.goal=e,this.path=[],this.arrive(0))}resolve(t,e=!1){if(t==="desk")return{key:t,pos:this.desk.seat.clone(),face:this.deskFace,pose:"desk",seatY:this.desk.seatY};if(t==="visit")return this.visitTarget;if(t==="standup")return this.meeting;if(t==="door")return{key:t,pos:this.world.door.clone(),face:Math.PI,pose:"stand"};const n=this.world.stations[t];if(!n)return null;let s=!e&&this.spot&&n.spots.includes(this.spot)?this.spot:null;if(!s){const a=n.spots.filter(l=>!l.game&&(!l.taken||l.taken===this.id)),o=e?a.filter(l=>l!==this.spot):a;s=(o.length?o:a)[Math.floor(Math.random()*(o.length||a.length))]}if(!s)return t==="lounge"?null:this.resolve("desk");this.spot&&this.spot!==s&&(this.spot.taken=null),s.taken=this.id,this.spot=s;const r=t==="lounge"?0:.12;return{key:t,pos:s.pos.clone().add(new R(Rr(-r,r),0,Rr(-r,r))),face:s.face,pose:s.pose,seatY:s.seatY}}goTo(t,e,n=!1){t==="desk"&&this.spot&&(this.spot.taken=null,this.spot=null);const s=this.resolve(t,n);s&&(this.goal=s,this.placeKey=null,this.path=this.world.grid.path(this.pos.x,this.pos.z,s.pos.x,s.pos.z),this.path.length||this.arrive(e))}arrive(t){const e=this.goal;this.pos.set(e.pos.x,0,e.pos.z),this.placeKey=e.key,this.pose=e.pose,this.seatY=e.seatY,this.dwellUntil=t+(e.key==="desk"?.8:e.key==="lounge"?0:e.key==="visit"?3.4:e.key==="standup"?.5:2.4),e.key==="lounge"&&(this.wanderAt=t+Rr(18,40))}assign(t,e=!1){this.job=t,this.anim=null,this.want="desk",this.lines=[],this.say("On it","",0),e&&this.teleport("desk")}visit(t,e){const n=this.world.grid,s=[[1.1,0],[-1.1,0],[0,1.1],[0,-1.1],[.9,.9],[-.9,.9]],[r,a]=s.find(([l,c])=>!n.blocked(...n.cellOf(t.pos.x+l,t.pos.z+c)))||[1.1,0],o=new R(t.pos.x+r,0,t.pos.z+a);this.visitTarget={key:"visit",pos:o,face:Math.atan2(t.pos.x-o.x,t.pos.z-o.z),pose:"talk"},this.afterVisit=this.want==="visit"?this.afterVisit:this.want,this.want="visit",this.placeKey=null,this.path=[],this.spot&&(this.spot.taken=null,this.spot=null),this.say(ka(e,52),"talk",0)}onLog(t){if(!this.job)return;const e=(...r)=>!this.meeting&&this.say(...r),n={tool:null,text:"#e8edf3",error:"#f87171",thinking:"#64748b",system:"#64748b"}[t.kind],s=r=>{this.want==="visit"?this.afterVisit=r:this.want=r};if(t.kind==="tool")s("desk"),e(ka(t.summary)),this.lines.push({text:"› "+t.summary,color:n});else if(t.kind==="text"){s("desk");const r=t.summary.split(new RegExp("(?<=[.!?])\\s|\\n"))[0];e(ka(r,44)),this.lines.push({text:r,color:n})}else t.kind==="thinking"?e("thinking…","thinking"):t.kind==="error"?(e(t.blocked?"Needs clearance":"Hm, that failed","warn"),this.lines.push({text:"✕ "+t.summary.split(`
4301
- `)[0],color:n})):t.kind==="system"&&(this.lines.push({text:t.summary,color:n}),t.wait&&(s("desk"),e(ka(t.summary,30)+"…","thinking")));this.lines.length>40&&this.lines.splice(0,this.lines.length-40)}meet(t,e=!1){if(this.meeting={key:"standup",pos:t.pos.clone(),face:t.face,pose:"stand"},this.spot&&(this.spot.taken=null,this.spot=null),e)return this.teleport("standup");this.want!=="visit"&&(this.path=[],this.placeKey=null)}adjourn(){this.meeting=null,this.placeKey==="standup"&&(this.placeKey=null)}speak(t){this.say(t,"talk",5200),this.anim={kind:"talk",until:(this.now||0)+4.8}}leave(){this.leaving=!0,this.want="door",this.spot&&(this.spot.taken=null,this.spot=null),this.say("Heading home","idle",3e3)}stay(){this.leaving=!1,this.want="lounge",this.say("Oh, staying!","good",2500)}dispose(){this.spot&&(this.spot.taken=null),this.world.scene.remove(this.root),this.label.remove()}finish(t){const e=this.now||0;this.anim={kind:t==="done"?"celebrate":"slump",until:e+2.2},this.say(t==="done"?"Shipped it!":t==="waiting"?"Need your answer":t==="stopped"?"Okay, stopping":"Hit a wall",t==="done"?"good":"warn",4e3),this.job=null,this.afterVisit=null,this.want="lounge"}think(t){var s;if(this.anim&&t<this.anim.until)return;this.anim=null,this.bubbleUntil&&t>this.bubbleUntil&&this.say("");const e=this.meeting&&!this.leaving&&this.want!=="visit"?"standup":this.want;if(this.path.length){((s=this.goal)==null?void 0:s.key)==="lounge"&&e!=="lounge"&&this.goTo(e,t);return}if(t<this.dwellUntil)return;if(this.leaving&&this.placeKey==="door"){this.gone=!0;return}this.placeKey==="visit"&&this.want==="visit"&&(this.want=this.job?this.afterVisit||"desk":"lounge",this.afterVisit=null,this.bubbleEl.classList.contains("talk")&&this.say(""));const n=this.meeting&&!this.leaving&&this.want!=="visit"?"standup":this.want;n!==this.placeKey?this.goTo(n,t):n==="lounge"&&t>this.wanderAt&&this.goTo("lounge",t,!0),!this.job&&!this.meeting&&!this.chatting&&t>this.chatAt&&(this.chatAt=t+Rr(25,60),Math.random()<.5&&this.say(ed[Math.floor(Math.random()*ed.length)],"idle",3500))}update(t,e){var s;this.now=e,this.think(e);let n=!1;if(this.path.length){const[r,a]=this.path[0],o=r-this.pos.x,l=a-this.pos.z,c=Math.hypot(o,l),h=3.4*t;c<=h?(this.pos.x=r,this.pos.z=a,this.path.shift(),this.path.length||this.arrive(e)):(this.pos.x+=o/c*h,this.pos.z+=l/c*h,this.heading=td(this.heading,Math.atan2(o,l),Math.min(1,t*12)),n=!0)}!n&&this.goal&&!this.path.length&&(this.heading=td(this.heading,this.goal.face,Math.min(1,t*8))),this.root.rotation.y=this.heading,this.animate(n?"walk":((s=this.anim)==null?void 0:s.kind)||this.pose,t,e)}animate(t,e,n){var a;this.fig.pose(t,e,n+this.phase,{typing:!!this.job&&!this.job.waiting&&this.job.id!=="idle",waiting:!!((a=this.job)!=null&&a.waiting),seatY:this.seatY});const s=this.bubbleEl.className,r=t==="celebrate"?"happy":t==="slump"||s.includes("warn")?"worried":t==="talk"||s.includes("idle")&&this.bubbleText?"talk":s.includes("thinking")?"think":s.includes("good")?"happy":"neutral";this.fig.express(r,e,n+this.phase)}placeLabel(t,e,n){const s=new R(this.pos.x,this.body.position.y+2.5+(this.fig.look.hair==="afro"?.2:0),this.pos.z).project(t);if(this.onScreen=s.z<=1,!this.onScreen){this.label.style.display="none",this.lift=0;return}this.label.style.display="",this.anchorX=(s.x*.5+.5)*e,this.anchorY=(-s.y*.5+.5)*n,this.depth=s.z,this.label.style.zIndex=String(Math.round((1-s.z)*1e4)),(this.labelDirty||!this.labelW)&&this.measureLabel()}measureLabel(){this.label.offsetWidth&&(this.labelDirty=!1,this.labelW=this.label.offsetWidth,this.labelH=this.label.offsetHeight)}labelBox(t){const e=this.anchorY-t;return{left:this.anchorX-this.labelW/2,right:this.anchorX+this.labelW/2,top:e-this.labelH,bottom:e}}setLift(t,e){const n=this.lift===void 0?1:Math.min(1,e*9);this.lift=(this.lift||0)+(t-(this.lift||0))*n,Math.abs(this.lift-t)<.4&&(this.lift=t),this.label.style.transform=`translate(-50%, -100%) translate(${this.anchorX}px, ${this.anchorY-this.lift}px)`}setBuried(t){t!==this.buried&&(this.buried=t,this.label.classList.toggle("buried",t))}setCrowded(t,e){t?this.uncrowdAt=e+.6:this.crowded&&e<(this.uncrowdAt||0)&&(t=!0),t!==this.crowded&&(this.crowded=t,this.label.classList.toggle("crowded",t),this.measureLabel())}setSelected(t){this.ring.visible=t,this.label.classList.toggle("selected",t)}}const Na=(i,t)=>i+Math.random()*(t-i),$r=i=>i[Math.floor(Math.random()*i.length)];async function qi(i,t,e){const n=await fetch(i,t===void 0?{method:e||"GET"}:{method:e||"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`Request failed (${n.status})`);return n.json().catch(()=>({}))}const wM=[["Coffee machine is making that noise again.","It does that when it likes you.","It has never liked me."],["Weekend plans, {b}?","Sleep, then more sleep.","Ambitious. I respect it."],["Did you see the size of that last diff?","I saw it. I chose not to look closer.","Wise."],["{b}, tabs or spaces?","Whatever the linter says.","Diplomatic answer.","It's the only safe one in here."],["I renamed one variable and forty tests broke.","Only forty? Lucky.","You have a dark sense of luck, {b}."],["Who keeps leaving one sip in the coffee pot?","Not me.","That is exactly what someone guilty would say."],["Favourite error message?",'"Something went wrong."',"So helpful. So honest."],["Read anything good lately?","The changelog for our test runner. Gripping stuff.","No spoilers please."],["This couch is too comfy.","Dangerous for productivity.","Good thing nobody has given us work yet."],["Do you ever dream in stack traces?","Only on deploy days.","Same."],["{b}, you were quiet in standup.","Saving my words for code review.","Ominous."],["Hot take: README files are love letters.","To whom?","To whoever opens this repo at 2am.","That's beautiful, {a}."],["What's the plant's name?","I call it Prod.","Why?","Because we don't touch it."],["I fixed a bug by deleting code today.","Best kind of fix.","Felt like spring cleaning."],["Lunch?","Already had it. Twice.","Bold."],['Have you noticed the boss says "quick change" a lot?',"Never quick.","Rarely one change."],["If you could rewrite one thing from scratch?","The build config.","Wouldn't we all."],["How do you stay so calm, {b}?","Small commits.","That explains a lot."]],EM=[{pair:["tunde","obi"],lines:["Still thinking about idempotency keys, {b}.","You always are. It is why I trust you with the ledger.","Say it again, but with a retry.","Same result. That is the whole point."]},{pair:["tunde","obi"],lines:["Remember the first ledger?","Four of us and one whiteboard.","We never did erase that whiteboard.","It's load-bearing now."]},{pair:["kai","zola"],lines:["Submission day, {b}. Checklist out?","Always out. Step one: breathe.","Step two: provisioning profile.","Step two is where we cry."]},{pair:["kai","zola"],lines:["Another rejection email. I can feel it.","Read it first. Then panic.","That is not on the checklist.","I will add it."]},{pair:["ada","mira"],lines:["I had a thought about the dashboard, {b}.","Is it a question? Please let it be a question.","It is a question.","Then I love it already. Go."]},{pair:["ada","tunde"],lines:["Does the new screen survive a retry, {b}?","You asked before I did.","You taught me.","Noted. Quietly proud."]},{pair:["ada","kai"],lines:["It should feel the same on web and app.","Thumbs do not agree.","Thumbs never do.","Move the button down, {a}."]},{pair:["mira","lin"],lines:["Could you look at this early, {b}? Before it is finished?","You ask early. I like that.","Startup scars.","The good kind of scar."]},{pair:["mira","tunde"],lines:["I could just own this whole feature, {b}.","Could you also wait for my green light?","That is the hard part.","It is the part that saves you."]},{pair:["mira","zola"],lines:["Ship it now, {b}?","Not yet.","How about now?","Ask me after the checklist."]},{pair:["lin","obi"],lines:["Another payload for you, {a}.","Guilty until proven valid.","You read my mind.","I read your schema."]},{pair:["lin","tunde"],lines:["Your logs are very readable, {b}.","I log everything now.","I know. It started on a train.","Do not remind me."]},{pair:["zola","tunde"],lines:["That alert again.","I saw it.","We nod?","We nod."]},{pair:["remi","mira"],lines:["Found a bug in your feature, {b}.","Wonderful. Send me the steps.","No defence? No excuses?","I would rather have the bug than the excuse."]}],TM=[{who:"tunde",lines:["Remember the Tuesday, {b}?","Nobody has forgotten the Tuesday.","That is why I log everything now.","Fair enough."]},{who:"kai",lines:["Did you hear? An app rejected over one permission string.","Is this the one you keep telling us about?","Never gets old.","It does, {a}."]},{who:"ada",lines:["Found a loading spinner I actually like.","Is it going in the folder?","It is going in the folder.","There is a folder?"]},{who:"zola",lines:["The release train ran on time again.","Because of the checklist.","Because of the checklist.","We all owe it a coffee."]},{who:"obi",lines:["Webhooks are promises, {b}.","To whom?","To whichever team is waiting on them.","Heavy thought for a coffee break."]},{who:"mira",lines:["One quick question, {b}.","Your questions are never quick.","This one is tiny.","Narrator: it was not."]},{who:"lin",lines:["Anyone have a worry they have not told anyone?","Not yet.","My door is open, and so is the kettle.","Thanks, {a}."]},{who:"remi",lines:['Anyone say "it works on my machine" today?',"Not me.","Good. I was sharpening my pencil.","Please do not."]}];function AM(i,t){const e=EM.filter(r=>r.pair.includes(i.id)&&r.pair.includes(t.id)),n=TM.filter(r=>r.who===i.id||r.who===t.id),s=Math.random();if(e.length&&s<.55){const r=$r(e);return nd(r.pair[0],r.lines,i,t)}if(n.length&&s<.8){const r=$r(n);return nd(r.who,r.lines,i,t)}return{who:[i,t],script:$r(wM)}}function nd(i,t,e,n){return{who:i===e.id?[e,n]:[n,e],script:t}}const Pr=i=>!i.job&&!i.meeting&&!i.leaving&&!i.path.length&&i.want==="lounge"&&i.placeKey==="lounge"&&!i.playing;class CM{constructor(){this.next=Na(10,20),this.chat=null,this.claiming=!1}update(t,e){if(this.chat)return this.step(e);if(this.claiming||e<this.next)return;const n=t.filter(Pr);if(n.length<2)return;const s=$r(n),r=$r(n.filter(a=>a!==s));this.claim(s,r,e)}async claim(t,e,n){this.claiming=!0,this.next=n+Na(20,45);let s=null,r=null;try{({id:s,script:r}=await qi("/api/chill",{who:[t.id,e.id]}))}catch{}if(this.claiming=!1,!!s){if(!Pr(t)||!Pr(e))return this.release(s);this.start(t,e,s,r)}}start(t,e,n,s){const{who:[r,a],script:o}=Array.isArray(s)&&s.length>=2?{who:[t,e],script:s}:AM(t,e),l=o.map(c=>c.replaceAll("{a}",r.name).replaceAll("{b}",a.name));for(const[c,h]of[[r,a],[a,r]])c.chatting=!0,c.wanderAt=1/0,c.pose!=="couch"&&(c.goal={...c.goal,face:Math.atan2(h.pos.x-c.pos.x,h.pos.z-c.pos.z)});this.chat={id:n,who:[r,a],script:l,line:0,at:0}}step(t){const e=this.chat;if(!e.who.every(Pr))return this.end(t);if(t<e.at)return;if(e.line>=e.script.length)return this.end(t);const n=e.who[e.line%2],s=e.script[e.line];n.say(s,"idle",3200+s.length*30),qi(`/api/chill/${e.id}/line`,{from:n.id,text:s}).catch(()=>{}),e.at=t+2.6+s.length*.035,e.line++}end(t){this.release(this.chat.id);for(const e of this.chat.who)e.chatting=!1,Pr(e)&&(e.wanderAt=t+Na(8,20));this.chat=null,this.next=t+Na(20,45)}release(t){qi(`/api/chill/${t}`,void 0,"DELETE").catch(()=>{})}}const $e=3.2,bi=1.6,Re=.075,Hf=.9,Ua=.78,id=7,RM=1/240,Oa=.15,sd=.135,yh=[{x:-$e/2,z:-bi/2,r:Oa},{x:$e/2,z:-bi/2,r:Oa},{x:-$e/2,z:bi/2,r:Oa},{x:$e/2,z:bi/2,r:Oa},{x:0,z:-bi/2-.035,r:sd},{x:0,z:bi/2+.035,r:sd}],Fa=i=>i===0?"cue":i===8?"eight":i<8?"solids":"stripes";function Fc(){const i=[{n:0,x:-$e/4,z:0,vx:0,vz:0,in:!1}],t=[1,2,3,4,5,6,7,9,10,11,12,13,14,15].sort(()=>Math.random()-.5),e=new Array(15);e[4]=8;const n=[10,14];e[n[0]]=t.splice(t.findIndex(a=>a<8),1)[0],e[n[1]]=t.splice(t.findIndex(a=>a>8),1)[0];for(let a=0;a<15;a++)e[a]||(e[a]=t.pop());const s=Re*2*1.002;let r=0;for(let a=0;a<5;a++)for(let o=0;o<=a;o++)i.push({n:e[r++],x:$e/4+a*s*.866,z:(o-a/2)*s,vx:0,vz:0,in:!1});return i}function PM(i,t,e={}){var s,r,a;let n=t;for(;n>1e-9;){const o=Math.min(RM,n);n-=o;for(const l of i){if(l.in)continue;const c=Math.hypot(l.vx,l.vz);if(c>0){const f=Math.max(0,c-Hf*o),g=f/c;l.vx*=g,l.vz*=g,f<.012&&(l.vx=0,l.vz=0)}l.x+=l.vx*o,l.z+=l.vz*o;const h=$e/2-Re,u=bi/2-Re;let d=!1;l.x<-h?(l.x=-h,l.vx=Math.abs(l.vx)*Ua,d=!0):l.x>h&&(l.x=h,l.vx=-Math.abs(l.vx)*Ua,d=!0),l.z<-u?(l.z=-u,l.vz=Math.abs(l.vz)*Ua,d=!0):l.z>u&&(l.z=u,l.vz=-Math.abs(l.vz)*Ua,d=!0),d&&((s=e.cushion)==null||s.call(e,l));for(const f of yh)if(Math.hypot(l.x-f.x,l.z-f.z)<f.r){l.in=!0,l.vx=0,l.vz=0,l.pocket=f,(r=e.pocket)==null||r.call(e,l,f);break}}for(let l=0;l<i.length;l++){const c=i[l];if(!c.in)for(let h=l+1;h<i.length;h++){const u=i[h];if(u.in)continue;const d=u.x-c.x,f=u.z-c.z,g=d*d+f*f;if(g>=4*Re*Re||g===0)continue;const _=Math.sqrt(g),m=d/_,p=f/_,y=(2*Re-_)/2;c.x-=m*y,c.z-=p*y,u.x+=m*y,u.z+=p*y;const x=(u.vx-c.vx)*m+(u.vz-c.vz)*p;if(x<0){const S=-1.96*x/2;c.vx-=S*m,c.vz-=S*p,u.vx+=S*m,u.vz+=S*p,(a=e.hit)==null||a.call(e,c,u,-x)}}}}}const LM=i=>i.some(t=>!t.in&&(t.vx||t.vz));class DM{constructor(t){this.players=t,this.balls=Fc(),this.turn=0,this.groups=null,this.shots=0,this.winner=null,this.over=null,this.inHand=!0,this.begin()}get cue(){return this.balls[0]}get shooter(){return this.players[this.turn]}get other(){return this.players[1-this.turn]}begin(){this.log={first:null,potted:[],cushion:!1,legal:this.targets().map(t=>t.n)}}targets(t=this.shooter){const e=this.balls.filter(s=>s.n&&!s.in);if(!this.groups)return e.filter(s=>s.n!==8);const n=e.filter(s=>Fa(s.n)===this.groups[t]);return n.length?n:e.filter(s=>s.n===8)}remaining(t){return this.groups?this.balls.filter(e=>e.n&&!e.in&&Fa(e.n)===this.groups[t]).length:7}recorder(){return{hit:(t,e)=>{this.log.first===null&&(t.n===0||e.n===0)&&(this.log.first=t.n===0?e.n:t.n)},pocket:t=>this.log.potted.push(t.n),cushion:()=>{this.log.cushion=!0}}}settle(){this.shots++;const{first:t,potted:e}=this.log,n=this.shooter,s=this.shots===1,r=e.includes(0),a=e.includes(8),o=this.log.legal,l={foul:!1,why:"",potted:e.filter(h=>h),continues:!1,assigned:null,eight:a};if(s&&a){const h=this.balls.find(u=>u.n===8);h.in=!1,h.x=$e/4,h.z=0,h.vx=h.vz=0,e.splice(e.indexOf(8),1),l.eight=!1}if(t===null?(l.foul=!0,l.why="missed everything"):o.includes(t)||(l.foul=!0,l.why=t===8?"hit the eight first":"wrong ball first"),r&&(l.foul=!0,l.why="scratched"),!l.foul&&!s&&!e.length&&!this.log.cushion&&(l.foul=!0,l.why="nothing reached a cushion"),l.eight){const h=this.groups&&o.every(u=>u===8);return h&&!l.foul?this.finish(n,"eight"):this.finish(this.other,h?"foul-eight":"early-eight"),l.over=this.over,l}if(!this.groups&&!l.foul&&!s){const h=e.find(u=>u&&u!==8);if(h){const u=Fa(h);this.groups={[n]:u,[this.other]:u==="solids"?"stripes":"solids"},l.assigned=u}}if(r){const h=this.cue;h.in=!1,h.vx=h.vz=0}const c=e.filter(h=>h&&h!==8&&(!this.groups||Fa(h)===this.groups[n]));if(l.continues=!l.foul&&c.length>0,this.inHand=l.foul,l.continues||(this.turn=1-this.turn),this.shots>=80&&!this.winner){const h=this.remaining(this.players[0]),u=this.remaining(this.players[1]);this.finish(h<=u?this.players[0]:this.players[1],"worn-out"),l.over=this.over}return this.begin(),l}finish(t,e){this.winner=t,this.over=e}placeCue(t){const e=this.cue,n=(r,a)=>this.balls.every(o=>o===e||o.in||Math.hypot(o.x-r,o.z-a)>Re*2.4),s=t?[[-$e/4,0],[-$e/4,.2],[-$e/4,-.2]]:[[-$e/4,0],[-$e/3,.3],[-$e/3,-.3],[.3,.3],[.3,-.3],[-.2,.5],[-.2,-.5],[-$e/2+.3,.2]];for(const[r,a]of s)if(n(r,a)){e.x=r,e.z=a,e.vx=e.vz=0,e.in=!1;return}for(let r=0;r<200;r++){const a=(Math.random()-.5)*($e-.4),o=(Math.random()-.5)*(bi-.4);if(n(a,o)){e.x=a,e.z=o,e.vx=e.vz=0,e.in=!1;return}}}}const Rl=(i,t,e,n,s,r,a)=>{const o=n-t,l=s-e,c=o*o+l*l||1e-9;for(const h of i){if(h.in||r.includes(h))continue;const u=Math.max(0,Math.min(1,((h.x-t)*o+(h.z-e)*l)/c));if(Math.hypot(h.x-(t+u*o),h.z-(e+u*l))<a)return!1}return!0};function IM(i,t=.7){const e=i.balls,n=i.cue,s=i.targets();let r=null;if(i.shots===0){const c=e.find(h=>h.n!==0&&h.x===Math.min(...e.filter(u=>u.n).map(u=>u.x)));r={angle:Math.atan2(c.z-n.z,c.x-n.x),speed:5.6+Math.random()*1.2,target:c,pocket:null,clean:!1,power:"break"}}else{for(const c of s)for(const h of yh){const u=h.x*.97,d=h.z*.97,f=u-c.x,g=d-c.z,_=Math.hypot(f,g)||1e-9,m=c.x-f/_*2*Re,p=c.z-g/_*2*Re;if(Math.abs(m)>$e/2-Re||Math.abs(p)>bi/2-Re)continue;const y=m-n.x,x=p-n.z,S=Math.hypot(y,x);if(S<Re*2)continue;const L=(y*f+x*g)/(S*_);if(L<.34||!Rl(e,n.x,n.z,m,p,[n,c],Re*2*.98)||!Rl(e,c.x,c.z,u,d,[n,c],Re*2*.98))continue;const T=L*2-(S+_)*.35-(c.n===8,0);(!r||T>r.score)&&(r={angle:Math.atan2(x,y),speed:Math.min(id*.8,Math.sqrt(2*Hf*(S+_*1.3))+1.1),target:c,pocket:h,clean:!0,score:T})}if(!r){const c=s.length?s:e.filter(f=>f.n&&!f.in),h=c.filter(f=>Rl(e,n.x,n.z,f.x,f.z,[n,f],Re*2*.98)),u=h.length?h:c;u.sort((f,g)=>Math.hypot(f.x-n.x,f.z-n.z)-Math.hypot(g.x-n.x,g.z-n.z));const d=u[0];r={angle:Math.atan2(d.z-n.z,d.x-n.x),speed:2.6+Math.random()*1.2,target:d,pocket:null,clean:!1}}}const a=Math.hypot(r.target.x-n.x,r.target.z-n.z),o=(.006+.026*(1-t))*(.8+a*.35),l=()=>(Math.random()+Math.random()+Math.random()-1.5)*1.4;return r.angle+=l()*o*(r.power==="break"?.6:1),r.speed=Math.min(id,Math.max(1.2,r.speed*(1+l()*.06*(1.2-t)))),r}function kM(i,t,e){i.cue.vx=Math.cos(t)*e,i.cue.vz=Math.sin(t)*e}let Gn=null,to=null,mo=!1;try{mo=localStorage.getItem("office.muted")==="1"}catch{}function Vf(){if(!Gn){const i=window.AudioContext||window.webkitAudioContext;if(!i)return;Gn=new i,to=Gn.createGain(),to.gain.value=.5,to.connect(Gn.destination)}Gn.state==="suspended"&&Gn.resume()}addEventListener("pointerdown",Vf);addEventListener("keydown",Vf);function Rn(i,t,e,{type:n="sine",gain:s=.2}={}){const r=Gn.currentTime+t,a=Gn.createOscillator(),o=Gn.createGain();a.type=n,a.frequency.setValueAtTime(i,r),o.gain.setValueAtTime(1e-4,r),o.gain.exponentialRampToValueAtTime(s,r+.012),o.gain.exponentialRampToValueAtTime(1e-4,r+e),a.connect(o).connect(to),a.start(r),a.stop(r+e+.05)}const $s=()=>!mo&&Gn&&Gn.state==="running",rn={get muted(){return mo},setMuted(i){mo=i;try{localStorage.setItem("office.muted",i?"1":"0")}catch{}},ship(){$s()&&([659.25,830.61,987.77].forEach((i,t)=>{Rn(i,t*.085,.55,{gain:.16}),Rn(i*2,t*.085,.3,{type:"triangle",gain:.035})}),Rn(1318.5,.26,.9,{gain:.09}))},fail(){$s()&&(Rn(293.66,0,.35,{type:"triangle",gain:.12}),Rn(246.94,.14,.5,{type:"triangle",gain:.12}))},levelUp(){$s()&&[523.25,659.25,783.99,1046.5,1318.5].forEach((i,t)=>Rn(i,t*.07,.7,{gain:.13}))},knock(){$s()&&(Rn(880,0,.09,{gain:.06}),Rn(1174.7,.07,.12,{gain:.05}))},click(i=.5){if(!$s())return;const t=.025+i*.07;Rn(1900+Math.random()*500,0,.035,{type:"triangle",gain:t}),Rn(3100,0,.02,{gain:t*.5})},pocket(){$s()&&(Rn(180,0,.18,{type:"triangle",gain:.09}),Rn(120,.06,.22,{type:"sine",gain:.07}))}},Ws=(i,t)=>i+Math.random()*(t-i),Zn=i=>i[Math.floor(Math.random()*i.length)],NM=["#f2c230","#2f5fb3","#d6402f","#6a3a9c","#e8803a","#2f8a4f","#8a2a2e"];function UM(i){const t=document.createElement("canvas");t.width=128,t.height=64;const e=t.getContext("2d"),n=i===0?"#f4f1ea":i===8?"#1b1b1f":NM[(i-1)%7];if(e.fillStyle=i>8?"#f4f1ea":n,e.fillRect(0,0,128,64),i>8&&(e.fillStyle=n,e.fillRect(0,14,128,36)),i){e.font="700 17px Inter, system-ui, sans-serif",e.textAlign="center",e.textBaseline="middle";for(const r of[32,96])e.fillStyle="#f4f1ea",e.beginPath(),e.arc(r,32,13,0,Math.PI*2),e.fill(),e.fillStyle="#1b1b1f",e.fillText(String(i),r,33)}const s=new ki(t);return s.colorSpace=je,s}const OM=["corner","corner","corner","corner","side","side"],FM=i=>OM[yh.indexOf(i)]||"pocket",zM=[["Eight ball? Loser buys the coffee.","You are on."],["Quick game of eight ball?","Rack them up."],["Pool table is free. That never happens.","Then we have to."],["Break is yours.","Bold of you to give me the break."]],BM=["Nice.","Smooth.","That one dropped.","Clean.","In."],HM=["So close.","Rolled out.","Unlucky.","The table is tilted."],VM=["Scratch.","Ugh, foul.","The cue ball had other plans."],GM=["Ball in hand.","Your table.","Thank you."],$M=["Here goes.","Let me see this one.","Easy.","Trust the line."],WM=["Good game.","That was fun.","Rematch later?"],XM=["Rematch.","Good game. Coffee is on me.","The table was tilted."];class jM{constructor(t,e){this.spots=e.stations.lounge.spots.filter(a=>a.game),this.root=new qt,this.root.position.set(Ve.x,0,Ve.z),t.add(this.root);const n=new li(Re,20,14);this.meshes=[];for(let a=0;a<=15;a++){const o=new yt(n,new On({map:UM(a),roughness:.22,metalness:.02}));o.castShadow=!0,o.userData={x:0,z:0,sunk:null},this.root.add(o),this.meshes.push(o)}this.cue=new qt;const s=new yt(new Un(.016,.026,1.9,8),xe("#d9b27a"));s.rotation.z=Math.PI/2,s.position.x=-.95,s.castShadow=!0;const r=new yt(new Un(.016,.016,.04,8),xe("#5b8fb0"));r.rotation.z=Math.PI/2,r.position.x=-.02,this.cue.add(s,r),this.cueOuter=new qt,this.cueOuter.add(this.cue),this.cue.rotation.z=-.12,this.cueOuter.visible=!1,this.root.add(this.cueOuter),this.resting=Fc(),this.view=this.resting,this.next=Ws(25,45),this.s=null,this.claiming=!1}get playing(){return!!this.s}update(t,e,n){this.s?this.run(e,n):!this.claiming&&e>=this.next&&this.tryStart(t,e),this.draw(e,n)}tryStart(t,e){const n=o=>!o.gone&&!o.job&&!o.meeting&&!o.leaving&&o.want==="lounge"&&!o.playing&&!o.chatting,s=t.filter(n);if(this.next=e+Ws(15,30),s.length<2)return;const r=Zn(s),a=Zn(s.filter(o=>o!==r));this.claim(r,a,e)}async claim(t,e,n){this.claiming=!0;let s=null;try{({id:s}=await qi("/api/chill",{who:[t.id,e.id],game:!0}))}catch{}if(this.claiming=!1,!s)return;const r=a=>!a.gone&&!a.job&&!a.meeting&&!a.leaving&&a.want==="lounge"&&!a.playing&&!a.chatting;if(!r(t)||!r(e))return this.release(s);this.begin(t,e,s,n)}begin(t,e,n,s){const r=[t,e];r.forEach((o,l)=>{const c=this.spots[l];o.spot&&o.spot!==c&&(o.spot.taken=null),o.spot=c,c.taken=o.id,o.playing=!0,o.chatting=!0,o.wanderAt=1/0,o.goTo("lounge",s)});const a=o=>.45+([...o.id].reduce((l,c)=>l*31+c.charCodeAt(0),7)>>>0)%50/100;this.s={id:n,players:r,skill:r.map(a),phase:"walk",deadline:s+60,game:null,plan:null,shots:0}}called(t){return t.gone||t.job||t.meeting||t.leaving||t.want!=="lounge"}run(t,e){const n=this.s;if(n.players.some(o=>this.called(o)))return this.stop(t,!1);for(const o of n.players)o.wanderAt=1/0;t-(n.pinged??0)>30&&(n.pinged=t,qi(`/api/chill/${n.id}/ping`,{}).catch(()=>{}));const[s,r]=n.players,a=o=>{var l;return o.placeKey==="lounge"&&!o.path.length&&((l=o.spot)==null?void 0:l.game)};switch(n.phase){case"walk":{if(t>n.deadline)return this.stop(t,!1);if(!a(s)||!a(r))return;n.game=new DM([s.id,r.id]),this.view=n.game.balls;for(const c of this.meshes)c.userData.sunk=null;const[o,l]=Zn(zM);s.say(o,"idle",3200),n.phase="rack",n.until=t+1.2,n.line=l,n.said=!1,qi(`/api/chill/${n.id}/line`,{from:s.id,text:o}).catch(()=>{});return}case"rack":!n.said&&t>n.until-.4&&(r.say(n.line,"idle",2600),n.said=!0),t>n.until&&this.aim(t);return;case"aim":return this.aiming(t);case"roll":{const o=n.rec;if(n.clicks=0,PM(n.game.balls,Math.min(e,.05),o),n.rolled+=e,n.rolled>.3&&(this.cueOuter.visible=!1),LM(n.game.balls)&&n.rolled<22)return;for(const l of n.game.balls)l.vx=0,l.vz=0;return this.settled(t)}case"pause":t>n.until&&this.aim(t);return;case"over":t>n.until&&this.stop(t,!0)}}agentOf(t){return this.s.players.find(e=>e.id===t)}aim(t){const e=this.s,n=e.game,s=this.agentOf(n.shooter),r=this.agentOf(n.other),a=e.players.indexOf(s);n.inHand&&n.placeCue(n.shots===0),e.plan=IM(n,e.skill[a]),e.t0=t,e.dur=Ws(1.5,2.2),e.struck=!1,e.phase="aim",e.shooter=s,e.waiter=r;const o=Ve.x+n.cue.x,l=Ve.z+n.cue.z;s.goal={...s.goal,face:Math.atan2(o-s.pos.x,l-s.pos.z)},r.goal={...r.goal,face:Math.atan2(o-r.pos.x,l-r.pos.z)};const c=e.plan.pocket&&FM(e.plan.pocket),h=c&&Math.random()<.4?e.plan.target.n===8?`Eight ball, ${c} pocket.`:`${c[0].toUpperCase()}${c.slice(1)} pocket.`:Math.random()<.18?Zn($M):"";h&&s.say(h,"idle",2400),this.cueOuter.visible=!0}aiming(t){const e=this.s,n=e.game,s=Math.min(1,(t-e.t0)/e.dur);e.shooter.anim={kind:"cue",until:t+.5},e.waiter.anim={kind:"mug",until:t+.5};const r=s<.55?.07+Math.sin(s*40)*.006:s<.85?.07+((s-.55)/.3)**2*.34:.41*(1-(s-.85)/.15)+.02;this.placeCue(r,e.plan.angle),s>=1&&!e.struck&&(e.struck=!0,kM(n,e.plan.angle,e.plan.speed),rn.click(Math.min(1,e.plan.speed/6)),e.rec=this.recorder(n),e.rolled=0,e.clicks=0,e.phase="roll",e.shooter.anim=null)}recorder(t){const e=t.recorder();return{hit:(n,s,r)=>{e.hit(n,s,r),this.s.clicks++<2&&rn.click(Math.min(1,r/4))},pocket:(n,s)=>{e.pocket(n,s),rn.pocket()},cushion:e.cushion}}settled(t){const e=this.s,n=e.game,s=e.shooter,r=e.waiter,a=n.settle();e.shots++;const o=a.potted.length>0;if(a.over)return this.over(t,a);a.assigned?s.say(`${a.assigned==="solids"?"Solids":"Stripes"} for me.`,"idle",2800):a.foul?(s.say(Zn(VM),"warn",2400),Math.random()<.5&&setTimeout(()=>this.s&&r.say(Zn(GM),"idle",2200),700)):o&&a.continues?Math.random()<.45&&s.say(Zn(BM),"good",2200):Math.random()<.22&&s.say(Zn(HM),"idle",2200),e.phase="pause",e.until=t+1.1+(a.foul?.6:0)}over(t,e){const n=this.s,s=n.game,r=this.agentOf(s.winner),a=n.players.find(l=>l!==r),o={eight:`Eight ball down. Good game, ${a.name}.`,"early-eight":`${a.name} dropped the eight early, so that one is mine. Good game.`,"foul-eight":`The eight went in with a foul, ${a.name}. Still a good game.`,"worn-out":`Called it after ${s.shots} shots, fewer balls left. Good game, ${a.name}.`}[s.over];r.say(Zn(WM),"good",3600),a.say(Zn(XM),"idle",3600),r.anim={kind:"celebrate",until:t+2.2},a.anim={kind:"slump",until:t+1.8},qi(`/api/chill/${n.id}/line`,{from:r.id,text:o}).catch(()=>{}),n.phase="over",n.until=t+5}stop(t,e){var s;const n=this.s;if(n){this.release(n.id);for(const r of n.players)r.playing=!1,r.chatting=!1,r.anim=null,(s=r.spot)!=null&&s.game&&(r.spot.taken=null,r.spot=null),!r.gone&&!r.job&&!r.meeting&&r.want==="lounge"?r.wanderAt=t+Ws(5,12):r.wanderAt=0;this.cueOuter.visible=!1,this.resting=Fc(),this.view=this.resting;for(const r of this.meshes)r.userData.sunk=null;this.s=null,this.next=t+(e?Ws(60,150):Ws(30,60))}}release(t){qi(`/api/chill/${t}`,void 0,"DELETE").catch(()=>{})}placeCue(t,e){const n=this.s.game.cue,s=Math.cos(e),r=Math.sin(e);this.cueOuter.position.set(n.x-s*(Re+t),Ve.felt+Re,n.z-r*(Re+t)),this.cueOuter.rotation.y=-e}draw(t,e){const n=Ve.felt;for(const s of this.view){const r=this.meshes[s.n],a=r.userData;if(s.in){a.sunk===null&&(a.sunk=t);const h=Math.min(1,(t-a.sunk)/.35),u=s.pocket;r.visible=h<1,r.position.set(s.x+(((u==null?void 0:u.x)??s.x)-s.x)*h,n+Re-h*.22,s.z+(((u==null?void 0:u.z)??s.z)-s.z)*h),r.scale.setScalar(1-h*.5);continue}a.sunk=null,r.visible=!0,r.scale.setScalar(1),r.position.set(s.x,n+Re,s.z);const o=s.x-a.x,l=s.z-a.z,c=Math.hypot(o,l);if(c>1e-5&&c<.5){const h=new R(l,0,-o).normalize();r.quaternion.premultiply(new ns().setFromAxisAngle(h,c/Re))}a.x=s.x,a.z=s.z}}}const Pl=6,rd=["#7c5cff","#0e9f9a","#d9488f","#c98a12","#3b82f6","#65a30d"],qM=/^#[0-9a-f]{6}$/i,Xs=(i,t)=>String(i??"").replace(/\s+/g," ").trim().slice(0,t),Ll=(i,t)=>qM.test(i)?i:t,YM=new Set(["working","idle","break","meeting","away"]);function KM(i){return Array.isArray(i)?i.filter(t=>t&&typeof t.link=="string"&&t.link).map(t=>({link:Xs(t.link,80),handle:Xs(t.handle,40)||"friend",agents:(Array.isArray(t.agents)?t.agents:[]).filter(e=>e&&typeof e.id=="string"&&e.id).map(e=>{var n,s,r;return{id:Xs(e.id,40),name:Xs(e.name,40)||"Visitor",role:Xs(e.role,60),state:YM.has(e.state)?e.state:"idle",look:{shirt:Ll((n=e.look)==null?void 0:n.shirt,"#8a8f9c"),hair:Ll((s=e.look)==null?void 0:s.hair,"#3b2f2a"),skin:Ll((r=e.look)==null?void 0:r.skin,"#c68e63")},job:e.job&&typeof e.job=="object"?{title:Xs(e.job.title,120)}:null}})})):[]}class ZM extends xh{constructor(t,e,n,s,r,a){const o=Object.hasOwn(Nf,e.id)?e.id:"visitor";super({id:o,name:"",...e.look},s,r,{desk:{seat:s.door.clone(),seatY:0}}),this.key=`${t.link}:${e.id}`,this.id=this.key,this.root.traverse(u=>{u.userData.agentId=this.key,u.userData.visitor=this.key}),this.tint=n,this.chatAt=1/0,this.hangout=Math.random()<.5?"poolside":"coffee";const l=new Zt(n);this.fig.group.traverse(u=>{var d;!u.isMesh||!((d=u.material)!=null&&d.color)||(u.material=u.material.clone(),u.material.color.lerp(l,.16),u.material.emissive&&(u.material.emissive.copy(l),u.material.emissiveIntensity=.07))}),this.ring.material.color.set(n),this.ring.material.opacity=.6,this.ring.visible=!0,this.label.classList.add("visitor"),this.label.style.setProperty("--tint",n);const c=this.label.querySelector(".name");c.replaceChildren();const h=document.createElement("i");if(h.style.background=n,this.nameEl=document.createElement("span"),this.handleEl=document.createElement("span"),this.handleEl.className="handle",c.append(h,this.nameEl,this.handleEl),this.set(t,e),a){this.teleport(this.want);return}this.teleport("door"),this.say(`Hi from @${t.handle}`,"good",4e3)}set(t,e){this.office=t,this.info=e,this.name=e.name,this.nameEl.textContent!==e.name&&(this.nameEl.textContent=e.name,this.labelDirty=!0),this.handleEl.textContent!==` · @${t.handle}`&&(this.handleEl.textContent=` · @${t.handle}`,this.labelDirty=!0),this.leaving&&(this.leaving=!1,this.say("Forgot something","idle",2500)),this.want=this.place(e.state)}place(t){const e=t==="working"?["hotdesk","huddle",this.hangout]:t==="meeting"?["huddle","hotdesk"]:[this.hangout,this.hangout==="coffee"?"poolside":"coffee","huddle"];return e.find(n=>this.roomAt(n))||e[0]}roomAt(t){return this.world.stations[t].spots.some(e=>!e.game&&(!e.taken||e.taken===this.id))}resolve(t,e){if(t==="desk"){this.spot&&(this.spot.taken=null,this.spot=null);const n=this.world.door.clone().add(new R(-4.2+Math.random()*1.6,0,-1.4+Math.random()*.8));return{key:t,pos:n,face:Math.atan2(-n.x,-n.z),pose:"stand"}}return super.resolve(t,e)}leave(){this.leaving||(super.leave(),this.say(`Back to @${this.office.handle}`,"idle",3e3))}dispose(){this.fig.group.traverse(t=>{t.isMesh&&t.material.dispose()}),super.dispose()}}class JM{constructor({world:t,labels:e,camera:n,canvas:s}){Object.assign(this,{world:t,labels:e,camera:n,canvas:s}),this.on=new Map,this.offices=[],this.tints=new Map,this.list=[],this.first=!0,this.sign=document.createElement("div"),this.sign.className="door-sign",this.sign.hidden=!0,e.appendChild(this.sign),this.card=document.createElement("div"),this.card.className="visitor-card",this.card.hidden=!0,e.appendChild(this.card),this.ray=new Df,s.addEventListener("pointermove",r=>this.hover(r)),s.addEventListener("pointerleave",()=>{this.card.hidden=!0})}handle(t){if(t.t==="visitors")return this.receive(t.offices),!0;if(t.t==="hello"&&Array.isArray(t.visitors)&&this.receive(t.visitors,this.first),t.t==="hello"&&(this.first=!1),t.t==="links"&&Array.isArray(t.links)){const e=new Set(t.links.map(n=>n==null?void 0:n.id));this.receive(this.offices.filter(n=>e.has(n.link)))}return!1}tintOf(t){return this.tints.has(t)||this.tints.set(t,rd[this.tints.size%rd.length]),this.tints.get(t)}receive(t,e=!1){this.offices=KM(t);const n=new Map,s=this.offices.map(o=>o.agents.filter(l=>l.state!=="away").map(l=>[`${o.link}:${l.id}`,o,l]));for(const o of s)for(const[l,c,h]of o)n.set(l,[c,h]);const r=new Set([...this.on.values()].filter(o=>!o.leaving&&n.has(o.key)).map(o=>o.key).slice(0,Pl));for(let o=0;r.size<Pl&&s.some(l=>l.length>o);o++)for(const l of s)l[o]&&r.size<Pl&&r.add(l[o][0]);for(const o of this.on.values())r.has(o.key)||o.leave();for(const o of r){const[l,c]=n.get(o),h=this.on.get(o);h?h.set(l,c):this.on.set(o,new ZM(l,c,this.tintOf(l.link),this.world,this.labels,e))}const a=new Map;for(const[o,[l]]of n)r.has(o)||a.set(l.handle,(a.get(l.handle)||0)+1);this.sign.replaceChildren(...[...a].map(([o,l])=>{const c=document.createElement("div");return c.textContent=`+${l} from @${o}`,c})),this.sign.hidden=!a.size,this.list=[...this.on.values()]}update(t,e){for(const n of this.on.values())n.update(t,e),n.gone&&(n.dispose(),this.on.delete(n.key),this.list=[...this.on.values()])}placeSign(t,e){if(this.sign.hidden)return;const n=this.world.door.clone().setY(2.7).project(this.camera);if(n.z>1){this.sign.style.display="none";return}this.sign.style.display="",this.sign.style.transform=`translate(-50%, -100%) translate(${(n.x*.5+.5)*t}px, ${(-n.y*.5+.5)*e}px)`}hover(t){if(t.buttons||!this.list.length){this.card.hidden=!0;return}const e=this.canvas.getBoundingClientRect();this.ray.setFromCamera(new rt((t.clientX-e.left)/e.width*2-1,-((t.clientY-e.top)/e.height)*2+1),this.camera);const n=this.ray.intersectObjects(this.list.map(o=>o.root),!0)[0],s=n&&this.on.get(n.object.userData.visitor);if(!s){this.card.hidden=!0;return}(this.card.dataset.key!==s.key||this.card.dataset.stamp!==JSON.stringify(s.info))&&this.fillCard(s),this.card.hidden=!1;let r=t.clientX-e.left+14,a=t.clientY-e.top+14;r+this.card.offsetWidth>e.width-8&&(r-=this.card.offsetWidth+28),a+this.card.offsetHeight>e.height-8&&(a-=this.card.offsetHeight+28),this.card.style.transform=`translate(${r}px, ${a}px)`}fillCard(t){var a;const{info:e,office:n}=t;this.card.dataset.key=t.key,this.card.dataset.stamp=JSON.stringify(e),this.card.style.setProperty("--tint",t.tint);const s=(o,l)=>{const c=document.createElement("div");return c.className=o,c.textContent=l,c},r={working:"Working",idle:"Between jobs",break:"On a break",meeting:"In a meeting",away:"Heading home"}[e.state];this.card.replaceChildren(s("vc-who",`${e.name} · @${n.handle}`),s("vc-role",e.role||"Agent"),s("vc-job",((a=e.job)==null?void 0:a.title)||(e.state==="working"?"On a job":"No job right now")),s("vc-state",`${r} · visiting from @${n.handle}`))}}class QM{constructor(t){this.scene=t,this.bits=[],this.geo=new di(.14,.09)}burst(t,e){for(let n=0;n<70;n++){const s=new yt(this.geo,new ln({color:e[n%e.length],side:si,transparent:!0}));s.position.set(t.x,2.4,t.z);const r=Math.random()*Math.PI*2,a=1.5+Math.random()*3;s.userData={v:new R(Math.cos(r)*a,4+Math.random()*4,Math.sin(r)*a),spin:new R(Math.random()*10,Math.random()*10,Math.random()*10),life:2.2+Math.random()*.8},this.scene.add(s),this.bits.push(s)}}update(t){for(let e=this.bits.length-1;e>=0;e--){const n=this.bits[e],s=n.userData;s.life-=t,s.v.y-=9*t,s.v.multiplyScalar(1-t*1.2),n.position.addScaledVector(s.v,t),n.position.y<.02?(n.position.y=.02,s.v.set(0,0,0),n.rotation.set(-Math.PI/2,0,n.rotation.z)):(n.rotation.x+=s.spin.x*t,n.rotation.y+=s.spin.y*t,n.rotation.z+=s.spin.z*t),n.material.opacity=Math.min(1,s.life/.6),s.life<=0&&(this.scene.remove(n),n.material.dispose(),this.bits.splice(e,1))}}}function Mh(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let Ss=Mh();function Gf(i){Ss=i}const $f=/[&<>"']/,t1=new RegExp($f.source,"g"),Wf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,e1=new RegExp(Wf.source,"g"),n1={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ad=i=>n1[i];function Sn(i,t){if(t){if($f.test(i))return i.replace(t1,ad)}else if(Wf.test(i))return i.replace(e1,ad);return i}const i1=/(^|[^\[])\^/g;function ve(i,t){let e=typeof i=="string"?i:i.source;t=t||"";const n={replace:(s,r)=>{let a=typeof r=="string"?r:r.source;return a=a.replace(i1,"$1"),e=e.replace(s,a),n},getRegex:()=>new RegExp(e,t)};return n}function od(i){try{i=encodeURI(i).replace(/%25/g,"%")}catch{return null}return i}const Wr={exec:()=>null};function ld(i,t){const e=i.replace(/\|/g,(r,a,o)=>{let l=!1,c=a;for(;--c>=0&&o[c]==="\\";)l=!l;return l?"|":" |"}),n=e.split(/ \|/);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(/\\\|/g,"|");return n}function Lr(i,t,e){const n=i.length;if(n===0)return"";let s=0;for(;s<n&&i.charAt(n-s-1)===t;)s++;return i.slice(0,n-s)}function s1(i,t){if(i.indexOf(t[1])===-1)return-1;let e=0;for(let n=0;n<i.length;n++)if(i[n]==="\\")n++;else if(i[n]===t[0])e++;else if(i[n]===t[1]&&(e--,e<0))return n;return-1}function cd(i,t,e,n){const s=t.href,r=t.title?Sn(t.title):null,a=i[1].replace(/\\([\[\]])/g,"$1");if(i[0].charAt(0)!=="!"){n.state.inLink=!0;const o={type:"link",raw:e,href:s,title:r,text:a,tokens:n.inlineTokens(a)};return n.state.inLink=!1,o}return{type:"image",raw:e,href:s,title:r,text:Sn(a)}}function r1(i,t){const e=i.match(/^(\s+)(?:```)/);if(e===null)return t;const n=e[1];return t.split(`
4300
+ }`};class SM extends Cr{constructor(){super();const t=bM;this.uniforms=Qi.clone(t.uniforms),this.material=new Hy({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad=new kh(this.material),this._outputColorSpace=null,this._toneMapping=null}render(t,e,n){this.uniforms.tDiffuse.value=n.texture,this.uniforms.toneMappingExposure.value=t.toneMappingExposure,(this._outputColorSpace!==t.outputColorSpace||this._toneMapping!==t.toneMapping)&&(this._outputColorSpace=t.outputColorSpace,this._toneMapping=t.toneMapping,this.material.defines={},oe.getTransfer(this._outputColorSpace)===ye&&(this.material.defines.SRGB_TRANSFER=""),this._toneMapping===vf?this.material.defines.LINEAR_TONE_MAPPING="":this._toneMapping===_f?this.material.defines.REINHARD_TONE_MAPPING="":this._toneMapping===xf?this.material.defines.CINEON_TONE_MAPPING="":this._toneMapping===yf?this.material.defines.ACES_FILMIC_TONE_MAPPING="":this._toneMapping===Mf?this.material.defines.AGX_TONE_MAPPING="":this._toneMapping===hh&&(this.material.defines.NEUTRAL_TONE_MAPPING=""),this.material.needsUpdate=!0),this.renderToScreen===!0?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),this.fsQuad.render(t))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}class wM{constructor(t,e){this.w=t,this.d=e,this.ox=-t/2,this.oz=-e/2,this.cells=new Uint8Array(t*e)}inside(t,e){return t>=0&&e>=0&&t<this.w&&e<this.d}blocked(t,e){return!this.inside(t,e)||this.cells[e*this.w+t]===1}cellOf(t,e){return[Math.floor(t-this.ox),Math.floor(e-this.oz)]}center(t,e){return[this.ox+t+.5,this.oz+e+.5]}block(t,e,n,s){const[r,a]=this.cellOf(t,n),[o,l]=this.cellOf(e-1e-6,s-1e-6);for(let c=a;c<=l;c++)for(let h=r;h<=o;h++)this.inside(h,c)&&(this.cells[c*this.w+h]=1)}nearestFree(t,e){if(!this.blocked(t,e))return[t,e];const n=new Set([e*this.w+t]),s=[[t,e]];for(;s.length;){const[r,a]=s.shift();for(const[o,l]of[[1,0],[-1,0],[0,1],[0,-1]]){const c=r+o,h=a+l;if(!(!this.inside(c,h)||n.has(h*this.w+c))){if(!this.blocked(c,h))return[c,h];n.add(h*this.w+c),s.push([c,h])}}}return[t,e]}clear(t,e,n,s){const r=Math.hypot(n-t,s-e),a=Math.ceil(r/.2);for(let o=1;o<a;o++){const l=o/a,[c,h]=this.cellOf(t+(n-t)*l,e+(s-e)*l);if(this.blocked(c,h))return!1}return!0}path(t,e,n,s){const r=this.nearestFree(...this.cellOf(t,e)),a=this.nearestFree(...this.cellOf(n,s)),o=(y,x)=>x*this.w+y,l=(y,x)=>Math.hypot(y-a[0],x-a[1]),c=new Map([[o(...r),0]]),h=new Map,u=[[l(...r),...r]],d=new Set;let f=!1;for(;u.length;){let y=0;for(let T=1;T<u.length;T++)u[T][0]<u[y][0]&&(y=T);const[,x,S]=u.splice(y,1)[0],L=o(x,S);if(!d.has(L)){if(d.add(L),x===a[0]&&S===a[1]){f=!0;break}for(let T=-1;T<=1;T++)for(let E=-1;E<=1;E++){if(!T&&!E)continue;const P=x+T,U=S+E;if(this.blocked(P,U)||T&&E&&(this.blocked(x+T,S)||this.blocked(x,S+E)))continue;const v=o(P,U),b=c.get(L)+(T&&E?Math.SQRT2:1);b<(c.get(v)??1/0)&&(c.set(v,b),h.set(v,L),u.push([b+l(P,U),P,U]))}}}const g=[];if(f){let y=o(...a);for(;y!==void 0;)g.unshift(this.center(y%this.w,Math.floor(y/this.w))),y=h.get(y)}g.push([n,s]);const _=[];let m=[t,e],p=0;for(;p<g.length;){let y=p;for(let x=g.length-1;x>p;x--)if(this.clear(m[0],m[1],g[x][0],g[x][1])){y=x;break}_.push(g[y]),m=g[y],p=y+1}return _}}const Ol=new Map;function Se(i,t={}){const e=i+JSON.stringify(t);return Ol.has(e)||Ol.set(e,new Bn({color:i,roughness:.7,...t})),Ol.get(e)}const Nr=(i,t)=>"#"+new Zt(i).multiplyScalar(t).getHexString();function re(i,t,e,n=0,s=0,r=0){const a=new yt(i,t);return a.position.set(n,s,r),a.castShadow=!0,a.receiveShadow=!0,e.add(a),a}const ni=(i,t)=>new Rh(i,Math.max(.001,t),5,12),wi=(i,t=20,e=14)=>new di(i,t,e),EM=.93,TM=.45,AM=.44,CM=.06,RM=.1,ee=.46,rp={ada:{hair:"afro",pants:"#3a3f5c",shoes:"#26211d"},tunde:{hair:"short",pants:"#4b4136",shoes:"#1c1c1c",extra:"lanyard"},mira:{hair:"bob",pants:"#2f3b52",shoes:"#5b4636"},kai:{hair:"spiky",pants:"#38383d",shoes:"#e9e6df",extra:"hood"},zola:{hair:"ponytail",pants:"#4d3f5e",shoes:"#2b2b2b"},remi:{hair:"bun",pants:"#3f4f60",shoes:"#704d38",extra:"glasses"},obi:{hair:"buzz",pants:"#2c3a32",shoes:"#1d1d1d",extra:"headphones"},lin:{hair:"long",pants:"#3b3b4a",shoes:"#2a2a2a"},chief:{hair:"side",pants:"#22232e",shoes:"#141414",extra:"suit"}};function Ba(i,t,e,n,s,r,a,o,l,c){const h=new qt;h.position.set(t,e,0),i.add(h),re(ni(r,n-r),o,h,0,-n/2);const u=new qt;u.position.y=-n,h.add(u),re(ni(a,s-a),l,u,0,-s/2);const d=new qt;return d.position.y=-s,u.add(d),c==null||c(d),{pivot:h,joint:u,end:d}}class Jr{constructor(t){const e=rp[t.id]||{hair:"short",pants:"#34384a",shoes:"#222"};this.look=e;const n=Se(t.skin,{roughness:.6}),s=Se(t.shirt),r=Se(Nr(t.shirt,.9)),a=Se(e.pants),o=Se(e.shoes,{roughness:.5}),l=Se(t.hair,{roughness:.85});this.group=new qt,this.body=new qt,this.group.add(this.body),this.hips=new qt,this.hips.position.y=.95,this.body.add(this.hips),re(ni(.2,.06),a,this.hips,0,.02).scale.set(1,1,.8);const h=_=>{re(new Ze(.15,.09,.26),o,_,0,-.02,.05).geometry.translate(0,0,0)};this.legL=Ba(this.hips,-.11,-.02,.45,.44,.1,.085,a,a,h),this.legR=Ba(this.hips,.11,-.02,.45,.44,.1,.085,a,a,h),this.torso=new qt,this.hips.add(this.torso);const u=[[.001,0],[.19,0],[.225,.08],[.23,.24],[.22,.36],[.255,.5],[.24,.58],[.15,.645],[.001,.66]].map(([_,m])=>new rt(_,m)),d=re(new zo(u,20),e.extra==="suit"?Se("#2b2d42"):s,this.torso,0,.04);d.scale.z=.8,re(new oi(.11,.03,8,20),e.extra==="suit"?Se("#f4f1ea"):Se(Nr(t.shirt,.8)),this.torso,0,.67).rotation.x=Math.PI/2,re(new zn(.075,.085,.14,12),n,this.torso,0,.73);const f=_=>re(wi(.07,12,10),n,_,0,-.02),g=e.extra==="suit"?Se("#2b2d42"):r;this.armL=Ba(this.torso,-.29,.58,.32,.3,.072,.062,g,e.extra==="suit"||e.extra==="hood"?g:n,f),this.armR=Ba(this.torso,.29,.58,.32,.3,.072,.062,g,e.extra==="suit"||e.extra==="hood"?g:n,f),this.buildHead(t,n,l),this.buildExtras(t,e,l),this.book=re(new Ze(.34,.05,.26),Se("#3d7ea6"),this.torso,0,.3,.36),this.book.rotation.x=-.6,this.book.visible=!1,this.mug=re(new zn(.06,.055,.13,12),Se("#ffffff"),this.armR.end,0,-.06,.07),this.mug.visible=!1,this.blinkAt=1+Math.random()*3,this.blink=0,this.cur={}}buildHead(t,e,n){this.head=new qt,this.head.position.y=.78,this.torso.add(this.head),re(wi(.33,28,20),e,this.head,0,.3).scale.set(1,.97,.94);for(const a of[-1,1])re(wi(.06,10,8),e,this.head,a*.32,.29,-.01).scale.set(.6,1,1);re(wi(.032,10,8),Se(Nr(t.skin,.88),{roughness:.6}),this.head,0,.27,.31),this.eyes=[];for(const a of[-1,1]){const o=new qt;o.position.set(a*.115,.33,.285),o.rotation.y=a*.28,this.head.add(o);const l=new yt(wi(.042,14,10),Se("#17181c",{roughness:.3}));l.scale.set(.82,1.2,.5),o.add(l);const c=new yt(wi(.013,8,6),new dn({color:"#ffffff"}));c.position.set(.012,.018,.02),o.add(c),this.eyes.push(o)}this.brows=[];for(const a of[-1,1]){const o=new yt(ni(.014,.08),Se(Nr(t.hair,.9)));o.rotation.z=Math.PI/2;const l=new qt;l.position.set(a*.115,.425,.275),l.rotation.y=a*.28,l.add(o),this.head.add(l),this.brows.push(l)}this.mouth=new yt(new oi(.055,.012,6,18,Math.PI),Se("#5b2a2a",{roughness:.5})),this.mouth.position.set(0,.205,.292),this.mouth.rotation.z=Math.PI,this.head.add(this.mouth);for(const a of[-1,1]){const o=new yt(new Oi(.045,16),new dn({color:"#ff8d7a",transparent:!0,opacity:.22,depthWrite:!1}));o.position.set(a*.19,.24,.245),o.rotation.y=a*.62,this.head.add(o)}const r=(a=.345,o=.52,l=-.25)=>{const c=re(new di(a,28,16,0,Math.PI*2,0,Math.PI*o),n,this.head,0,.31,-.01);return c.rotation.x=l,c.scale.set(1,1,.97),c};switch(this.look.hair){case"afro":r(.35,.55),re(wi(.43,24,18),n,this.head,0,.47,-.08).scale.set(1,.85,.95);break;case"bob":{r(.36,.56,-.32);for(const a of[-1,1])re(ni(.09,.2),n,this.head,a*.29,.22,-.1).scale.set(.75,1,1.1);re(ni(.05,.3),n,this.head,0,.55,.17).rotation.z=Math.PI/2;break}case"spiky":r(.35,.5);for(let a=0;a<9;a++){const o=a/9*Math.PI*2;re(new ca(.07,.22,6),n,this.head,Math.cos(o)*.17,.6,Math.sin(o)*.17-.03).rotation.set(Math.sin(o)*.7,0,-Math.cos(o)*.7)}break;case"ponytail":{r(.35,.55),re(wi(.07,10,8),Se("#e07a5f"),this.head,0,.42,-.33);const a=re(ni(.08,.32),n,this.head,0,.22,-.4);a.rotation.x=.35,this.tail=a;break}case"bun":r(.35,.55),re(wi(.14,16,12),n,this.head,0,.66,-.1);break;case"buzz":r(.338,.5,-.3);break;case"long":{r(.36,.58,-.2),re(ni(.16,.42),n,this.head,0,.1,-.2).scale.set(1.75,1,.6);break}case"side":{r(.35,.5),re(ni(.07,.3),n,this.head,.06,.58,.12).rotation.set(.2,0,Math.PI/2-.25);break}default:r(.35,.5)}}buildExtras(t,e,n){if(e.extra==="glasses"||e.extra==="suit"){const s=Se("#1b1b1f",{roughness:.4});for(const r of[-1,1]){const a=re(new oi(.06,.011,6,18),s,this.head,r*.115,.33,.3);a.rotation.y=r*.28}re(ni(.009,.06),s,this.head,0,.34,.315).rotation.z=Math.PI/2}if(e.extra==="suit"){const s=re(new Ze(.06,.3,.02),Se("#b23a3a"),this.torso,0,.47,.19);s.rotation.x=-.12,re(new Ze(.16,.18,.02),Se("#f4f1ea"),this.torso,0,.56,.175).rotation.x=-.15}if(e.extra==="headphones"){const s=re(new oi(.35,.025,8,24,Math.PI),Se("#22252b"),this.head,0,.32,0);s.rotation.y=Math.PI/2,s.rotation.x=-.15;for(const r of[-1,1])re(new zn(.09,.09,.07,18),Se("#e05f4a"),this.head,r*.34,.3,0).rotation.z=Math.PI/2}if(e.extra==="lanyard"&&(re(new oi(.16,.01,6,20,Math.PI),Se("#2a6fb0"),this.torso,0,.62,.12).rotation.set(-.25,0,Math.PI),re(new Ze(.1,.13,.015),Se("#ffffff"),this.torso,0,.42,.205).rotation.x=-.1),e.extra==="hood"){const s=re(new oi(.2,.06,10,24),Se(Nr(t.shirt,.85)),this.torso,0,.64,-.05);s.rotation.x=Math.PI/2+.35,s.scale.set(1,1,.7)}}static sit(t=ee,e=-1.4){const n=t+RM,s=n-TM*Math.cos(e),r=-Math.acos(Math.min(1,Math.max(-1,(s-CM)/AM)));return{y:n-EM,hip:e,knee:r-e}}pose(t,e,n,s={}){const r=Math.min(1,e*10);let a=0,o=0,l=0,c=0,h=.05,u=.05,d=-.12,f=-.12,g=-.07,_=.07,m=0,p=0,y=0,x=0,S=0;const L=Math.sin(n*1.7)*.012;switch(this.book.visible=t==="read",this.mug.visible=t==="mug",t){case"walk":{const v=Math.sin(n*9.5),b=Math.cos(n*9.5);a=v*.5,o=-v*.5,l=Math.max(0,-b)*.9+.05,c=Math.max(0,b)*.9+.05,h=-v*.45,u=v*.45,d=f=-.35,m=Math.abs(b)*.05,p=.06,x=Math.sin(n*4.75)*.04;break}case"desk":{const v=Jr.sit(s.seatY,-1.45);a=o=v.hip,l=c=v.knee,m=v.y,p=.08,s.typing?(h=-.5+Math.sin(n*17)*.05,u=-.5+Math.sin(n*17+2)*.05,d=-1.15+Math.sin(n*19)*.12,f=-1.15+Math.sin(n*19+1.6)*.12,g=-.18,_=.18,y=.12+Math.sin(n*.7)*.03):s.waiting?(u=-.95,f=-2.25,_=.05,h=-.4,d=-1,x=Math.sin(n*.6)*.45,y=-.05):(h=u=-.35,d=f=-.9,g=-.2,_=.2,p=-.04,x=Math.sin(n*.35)*.3);break}case"couch":{const v=Jr.sit(s.seatY,-1.3);a=o=v.hip,l=c=v.knee,m=v.y,p=-.18,h=u=-.2,d=f=-.75,g=-.15,_=.15,x=Math.sin(n*.3)*.5,S=Math.sin(n*.21)*.06;break}case"sit":{const v=Jr.sit(s.seatY,-1.42);a=o=v.hip,l=c=v.knee,m=v.y,p=.03,h=u=-.32,d=f=-.95,g=-.16,_=.16,x=Math.sin(n*.4)*.4,S=Math.sin(n*.27)*.05;break}case"read":h=u=-.55,d=f=-1.35,g=-.12,_=.12,y=.4,x=Math.sin(n*.6)*.12;break;case"type":h=-.75+Math.sin(n*14)*.08,u=-.75+Math.sin(n*14+2)*.08,d=-.9,f=-.9,g=-.15,_=.15,y=.08;break;case"gaze":h=u=.3,d=f=-.25,g=-.12,_=.12,y=-.18,x=Math.sin(n*.45)*.35;break;case"write":u=-2.2+Math.sin(n*6)*.2,f=-.5+Math.sin(n*9)*.15,_=.25,x=Math.sin(n*1.2)*.1,y=-.08;break;case"mug":{const v=Math.sin(n*.8)>.75;u=v?-.85:-.45,f=v?-2.05:-1.55,_=.1,y=v?-.15:.02,x=v?0:Math.sin(n*.4)*.3;break}case"cue":p=.62,h=-1.5,d=-.12,g=-.12,u=-.95,f=-1.35,_=.14,y=-.5,a=o=-.12,l=c=.14,x=Math.sin(n*.8)*.05;break;case"talk":u=-.55+Math.sin(n*4)*.2,f=-1.1+Math.sin(n*5.3)*.2,_=.2,h=-.1,d=-.4,S=Math.sin(n*2.2)*.06,y=-.04;break;case"celebrate":h=u=-2.75,d=f=-.25,g=-.35,_=.35,m=Math.abs(Math.sin(n*8))*.32,y=-.15,l=c=m>.05?.4:.1,a=o=-l*.5;break;case"slump":y=.45,p=.22,h=u=.12,d=f=-.05;break;default:x=Math.sin(n*.5)*.25}const T=this.cur,E=(v,b,I=r)=>T[v]=T[v]===void 0?b:T[v]+(b-T[v])*I,P=t==="walk",U=P?Math.min(1,e*18):r;this.legL.pivot.rotation.x=E("hipL",a,U),this.legR.pivot.rotation.x=E("hipR",o,U),this.legL.joint.rotation.x=E("kneeL",l,U),this.legR.joint.rotation.x=E("kneeR",c,U),this.armL.pivot.rotation.x=E("shL",h,U),this.armR.pivot.rotation.x=E("shR",u,U),this.armL.pivot.rotation.z=E("outL",g),this.armR.pivot.rotation.z=E("outR",_),this.armL.joint.rotation.x=E("elL",d,U),this.armR.joint.rotation.x=E("elR",f,U),this.torso.rotation.x=E("lean",p),this.torso.scale.y=1+L,this.head.rotation.x=E("headX",y,r*.6),this.head.rotation.y=E("headY",x,r*.4),this.head.rotation.z=E("headZ",S,r*.6),this.body.position.y=P||t==="celebrate"?m:E("y",m),this.tail&&(this.tail.rotation.x=.35+Math.sin(n*(P?9.5:1.5))*(P?.12:.03))}express(t,e,n){n>this.blinkAt&&(this.blink=.14,this.blinkAt=n+2+Math.random()*4),this.blink=Math.max(0,this.blink-e);const s=this.blink>0,r=Math.min(1,e*12),a=this.cur,o=(p,y)=>a[p]=a[p]===void 0?y:a[p]+(y-a[p])*r;let l=1,c=0,h=0,u=1,d=1,f=!1;t==="happy"?(l=.3,c=.025,u=1.45,d=1.6):t==="think"?(c=.02,h=.25,u=.55,l=.9):t==="worried"?(h=-.35,c=.01,f=!0,u=.8):t==="talk"&&(u=.8,d=.6+Math.abs(Math.sin(n*13))*1.6,c=Math.sin(n*3)*.008),s&&t!=="happy"&&(l=.1);const g=o("eyeY",l);for(const p of this.eyes)p.scale.y=g;const _=o("browY",c),m=o("browTilt",h);this.brows.forEach((p,y)=>{p.position.y=.425+_,p.rotation.z=(y?-1:1)*m}),this.mouth.rotation.z=f?0:Math.PI,this.mouth.position.y=f?.18:.205,this.mouth.scale.set(o("mouthX",u),o("mouthY",d),1)}}const vn=40,In=30,Xe={x:7.6,z:10.9,felt:.84},wt={wall:"#f5f0e8",trim:"#d9cdbb",wood:"#c39a6b",woodDark:"#8c6440",metal:"#3b404c",rack:"#262a33",pot:"#e4d6c1",couch:"#5b7fa6",rug:"#c99b84",glass:"#cfe6f2",board:"#fbfaf7",chair:"#30343d"},Fl=new Map;function xe(i,t={}){const e=i+JSON.stringify(t);return Fl.has(e)||Fl.set(e,new Bn({color:i,roughness:.82,...t})),Fl.get(e)}function it(i,t,e,n,s,r,a,o,l){const c=new yt(new Ze(t,e,n),l instanceof Fi?l:xe(s,l));return c.position.set(r,a,o),c.castShadow=!0,c.receiveShadow=!0,i.add(c),c}function rs(i,t,e,n,s){const r=document.createElement("canvas");r.width=n,r.height=s;const a=new zi(r);a.colorSpace=Ke,a.anisotropy=4;const o=new yt(new gi(t,e),new dn({map:a,toneMapped:!1}));return i.add(o),{canvas:r,ctx:r.getContext("2d"),tex:a,mesh:o}}const ci='"Inter Variable", Inter, system-ui, sans-serif',PM='"JetBrains Mono", ui-monospace, monospace';function te(i,t,e,n,s,r,a,o,l=16,c){const h=new yt(new zn(t,e,n,l),c instanceof Fi?c:xe(s,c));return h.position.set(r,a,o),h.castShadow=!0,h.receiveShadow=!0,i.add(h),h}const pd=["#5f9e6e","#477d55","#6fae74","#3f7350","#7dbb7a"];function LM(i,t,e,n,s=1,r="bush"){const a=new qt;a.position.set(e,0,n),a.rotation.y=e*1.7+n,a.scale.setScalar(s),te(a,.35,.27,.6,wt.pot,0,.3,0,18),te(a,.37,.37,.06,"#d8c8b0",0,.6,0,18),te(a,.31,.31,.02,"#5a4130",0,.62,0,18);const o=(l,c,h,u,d)=>{const f=new yt(new Sr(l,0),xe(pd[d%pd.length],{flatShading:!0}));f.position.set(c,h,u),f.rotation.set(c*3,u*5,h),f.castShadow=!0,a.add(f)};if(r==="tall")te(a,.035,.05,1.5,wt.woodDark,0,1.35,0,6),o(.42,.12,1.55,.05,1),o(.48,-.15,1.95,-.08,0),o(.38,.18,2.3,.1,2),o(.3,-.05,2.6,0,4);else if(r==="snake")for(let l=0;l<7;l++){const c=l/7*Math.PI*2,h=.8+l*37%5*.12,u=new yt(new ca(.07,h,4),xe(l%2?"#4e8a5c":"#6f9f5a",{flatShading:!0}));u.position.set(Math.cos(c)*.12,.62+h/2,Math.sin(c)*.12),u.rotation.set(Math.sin(c)*.18,c,-Math.cos(c)*.18),u.scale.z=.35,u.castShadow=!0,a.add(u)}else o(.55,0,1,0,0),o(.4,.3,1.25,.1,1),o(.38,-.28,1.2,-.12,2),o(.36,.05,1.5,-.2,3);return i.add(a),t.block(e-.45*s,e+.45*s,n-.45*s,n+.45*s),a}function ap(i,t,e,n){te(i,.09,.07,.12,"#e8dccb",t,e+.06,n,12);const s=new yt(new Sr(.1,0),xe("#7aa874",{flatShading:!0}));s.position.set(t,e+.17,n),s.scale.y=.7,s.castShadow=!0,i.add(s)}function Kc(i,t,e,n,s=3){const r=["#e07a5f","#3d7ea6","#f2cc8f","#81b29a","#9c6ade"];for(let a=0;a<s;a++){const o=it(i,.34-a*.03,.05,.25,r[(a+Math.round(t*7))%r.length],t,e+.025+a*.05,n);o.rotation.y=(a-1)*.15}}function DM(i,t,e,n){const s=xe("#2f3440",{roughness:.5});te(i,.11,.12,.03,null,t,e+.015,n,16,s);const r=it(i,.03,.42,.03,null,t,e+.22,n,s);r.rotation.x=-.25;const a=it(i,.03,.03,.3,null,t,e+.42,n+.13,s);a.rotation.x=.35;const o=te(i,.05,.12,.14,null,t,e+.36,n+.27,16,xe("#e9b949",{roughness:.45}));o.rotation.x=.4;const l=new yt(new Oi(.1,16),new dn({color:"#fff3c9"}));l.position.set(t,e+.3,n+.3),l.rotation.x=-Math.PI/2+.4,i.add(l)}function Ur(i,t,e,n,s,r,a="#3b3330"){const o=[it(i.g,n+.14,s+.14,.05,a,t,e,.18)],l=rs(i.g,n,s,Math.round(256*n),Math.round(256*s));l.mesh.position.set(t,e,.21),l.mesh.material=new Bn({map:l.tex,roughness:.9}),r(l.ctx,l.canvas.width,l.canvas.height),l.tex.needsUpdate=!0,o.push(l.mesh),i.attach.push(...o)}const Or={sunset(i,t,e){i.fillStyle="#f4e3c8",i.fillRect(0,0,t,e),i.fillStyle="#e9967a",i.beginPath(),i.arc(t*.62,e*.45,t*.2,0,Math.PI*2),i.fill(),i.fillStyle="#8fb0a0",i.beginPath(),i.moveTo(0,e),i.lineTo(0,e*.62),i.quadraticCurveTo(t*.35,e*.4,t*.7,e*.66),i.lineTo(t,e*.58),i.lineTo(t,e),i.fill(),i.fillStyle="#4f7c74",i.beginPath(),i.moveTo(0,e),i.lineTo(0,e*.8),i.quadraticCurveTo(t*.5,e*.6,t,e*.82),i.lineTo(t,e),i.fill()},blocks(i,t,e){i.fillStyle="#f7f1e6",i.fillRect(0,0,t,e);const n=["#e07a5f","#3d405b","#81b29a","#f2cc8f"];i.fillStyle=n[0],i.fillRect(t*.12,e*.12,t*.42,e*.4),i.fillStyle=n[1],i.fillRect(t*.54,e*.12,t*.34,e*.22),i.fillStyle=n[2],i.fillRect(t*.54,e*.34,t*.34,e*.54),i.fillStyle=n[3],i.fillRect(t*.12,e*.52,t*.42,e*.36),i.fillStyle="#3d405b",i.beginPath(),i.arc(t*.33,e*.7,t*.1,0,Math.PI*2),i.fill()},arcs(i,t,e){i.fillStyle="#efe6d8",i.fillRect(0,0,t,e),["#c8553d","#f28f3b","#ffd5c2","#588b8b"].forEach((s,r)=>{i.strokeStyle=s,i.lineWidth=t*.07,i.beginPath(),i.arc(t/2,e*.85,t*(.38-r*.09),Math.PI,0),i.stroke()})},leaf(i,t,e){i.fillStyle="#e7ece4",i.fillRect(0,0,t,e),i.fillStyle="#5f8f6b",i.beginPath(),i.ellipse(t/2,e/2,t*.18,e*.36,.35,0,Math.PI*2),i.fill(),i.strokeStyle="#e7ece4",i.lineWidth=t*.015,i.beginPath(),i.moveTo(t*.38,e*.82),i.lineTo(t*.62,e*.18),i.stroke()}};function IM(i,t,e){const n=rs(i.g,.9,.9,256,256);n.mesh.geometry=new Oi(.45,40),n.mesh.position.set(t,e,.22);const s=te(i.g,.5,.5,.08,"#3b3330",t,e,.17,40);s.rotation.x=Math.PI/2,i.attach.push(s,n.mesh);const r=()=>{const{ctx:a,tex:o}=n;a.fillStyle="#fbf8f2",a.fillRect(0,0,256,256),a.translate(128,128),a.fillStyle="#3b3330";for(let d=0;d<12;d++)a.save(),a.rotate(d/12*Math.PI*2),a.fillRect(-3,-112,6,d%3?12:22),a.restore();const l=new Date,c=l.getMinutes(),h=l.getHours()%12+c/60,u=(d,f,g,_)=>{a.save(),a.rotate(d),a.fillStyle=_,a.fillRect(-g/2,-f,g,f+14),a.restore()};u(h/12*Math.PI*2,62,9,"#3b3330"),u(c/60*Math.PI*2,92,6,"#3b3330"),a.fillStyle="#e07a5f",a.beginPath(),a.arc(0,0,8,0,Math.PI*2),a.fill(),a.setTransform(1,0,0,1,0,0),o.needsUpdate=!0};r(),setInterval(r,3e4)}function kM(){const i=document.createElement("canvas");i.width=i.height=512;const t=i.getContext("2d"),e=8,n=512/e;for(let r=0;r<e;r++)for(let a=0;a<e;a++){t.fillStyle=`hsl(${170+Math.random()*8}, ${9+Math.random()*4}%, ${82+Math.random()*2.5}%)`,t.fillRect(r*n,a*n,n,n),t.globalAlpha=.05;for(let o=0;o<40;o++)t.fillStyle=Math.random()<.5?"#000":"#fff",t.fillRect(r*n+Math.random()*n,a*n+Math.random()*n,2,2);t.globalAlpha=1,t.fillStyle="rgba(60, 80, 80, 0.09)",t.fillRect(r*n,a*n,n,1.5),t.fillRect(r*n,a*n,1.5,n)}const s=new zi(i);return s.colorSpace=Ke,s.wrapS=s.wrapT=Ni,s.repeat.set(24.5/8,12.6/8),s.anisotropy=8,s}let Ha;function NM(i,t,e,n,s){if(!Ha){const a=document.createElement("canvas");a.width=256,a.height=64;const o=a.getContext("2d"),l=o.createLinearGradient(0,0,256,0);l.addColorStop(0,"rgba(255, 236, 200, 0.55)"),l.addColorStop(1,"rgba(255, 236, 200, 0)"),o.fillStyle=l,o.fillRect(0,0,256,64),Ha=new zi(a),Ha.colorSpace=Ke}const r=new yt(new gi(n,s),new dn({map:Ha,transparent:!0,depthWrite:!1,blending:ac,opacity:.5}));r.rotation.x=-Math.PI/2,r.position.set(t,.025,e),i.add(r)}let zl;function UM(){if(!zl){const i=cp();i.repeat.set(.5,.22),zl=new Bn({map:i,color:"#f0d6b4",roughness:.52})}return zl}let Zs;function OM(){if(Zs)return Zs;const i=document.createElement("canvas");i.width=384,i.height=128;const t=i.getContext("2d"),e=15,n=5,s=i.width/e,r=i.height/n,a=3;t.fillStyle="#cfcac1",t.fillRect(0,0,i.width,i.height);const o=(c,h,u,d)=>{t.fillStyle="#f7f5f1",t.fillRect(c,h,u,d),t.fillStyle="rgba(88, 84, 78, 0.22)",t.fillRect(c,h+d-2,u,2)};for(let c=0;c<n-1;c++)for(let h=0;h<e;h++)o(h*s+a,c*r+a,s-a*2,r-a*2);const l=(n-1)*r;for(const c of[0,1,2,11,12,13,14])o(c*s+a,l+a,s-a*2,r-a*2);return o(3*s+a,l+a,s*8-a*2,r-a*2),Zs=new zi(i),Zs.colorSpace=Ke,Zs.anisotropy=4,Zs}function md(i,t,e,n,s,r,a=500){const o=new qt;o.position.set(n,s,r),i.add(o);const l=new yt(new Ze(t+.08,e+.12,.05),["#272d38","#272d38","#272d38","#272d38","#1e232c","#3c4352"].map(h=>xe(h)));l.position.set(0,-.015,-.03),l.castShadow=!0,l.receiveShadow=!0,o.add(l),it(o,(t+.08)*.55,.035,.012,"#323a47",0,-e*.34,-.056).castShadow=!1;const c=rs(o,t,e,Math.round(t*a),Math.round(e*a));return c.mesh.position.set(0,.015,.002),{g:o,face:c}}function FM(i,t,e,n){const s=xe("#23272f",{roughness:.6});te(i,.11,.13,.025,"#2f3440",t,e+.012,n,14),te(i,.022,.022,.3,"#2f3440",t,e+.16,n,10);const r=new yt(new oi(.11,.022,6,16,Math.PI),s);r.position.set(t,e+.3,n),r.castShadow=!0,i.add(r);for(const a of[-.11,.11]){const o=te(i,.065,.065,.05,null,t+a,e+.28,n,14,s);o.rotation.z=Math.PI/2,o.castShadow=!0}}function zM(i,t,e,n){const s=xe("#f4c430",{roughness:.45}),r=new yt(new di(.075,12,10),s);r.position.set(t,e+.06,n),r.scale.set(1,.85,1.25),r.castShadow=!0,i.add(r);const a=new yt(new di(.05,12,10),s);a.position.set(t,e+.15,n-.05),a.castShadow=!0,i.add(a);const o=new yt(new ca(.022,.06,8),xe("#e8833a",{roughness:.5}));o.position.set(t,e+.14,n-.11),o.rotation.x=-Math.PI/2,i.add(o);for(const l of[-.02,.02]){const c=new yt(new di(.008,6,6),xe("#1a1a1a"));c.position.set(t+l,e+.17,n-.085),i.add(c)}}function BM(i,t,e,n,s){const r=new qt;r.position.set(t,e,n),r.rotation.y=-.4+s%2*.8,i.add(r),it(r,.26,.21,.02,"#3b3330",0,.12,0);const a=rs(r,.21,.16,84,64);a.mesh.position.set(0,.125,.012);const{ctx:o,canvas:l}=a;o.fillStyle="#cfe3ef",o.fillRect(0,0,l.width,l.height),o.fillStyle="#8fb0a0",o.beginPath(),o.moveTo(0,l.height),o.quadraticCurveTo(l.width*.5,l.height*.35,l.width,l.height),o.fill(),o.fillStyle="#f2cc8f",o.beginPath(),o.arc(l.width*.72,l.height*.3,7,0,Math.PI*2),o.fill(),a.tex.needsUpdate=!0;const c=it(r,.02,.1,.02,"#3b3330",0,.05,-.04);c.rotation.x=.35}function HM(i,t,e,n){const s=it(i,.3,.035,.38,"#44506b",t,e+.018,n);s.rotation.y=.18;const r=it(i,.27,.02,.35,"#f6f2e8",t,e+.028,n+.01);r.rotation.y=.18,te(i,.009,.009,.24,"#e07a5f",t+.04,e+.045,n,8).rotation.set(0,.5,Math.PI/2)}function VM(i,t,e,n,s){const r=new qt;r.position.set(e,0,n);const a=it(r,2.5,.1,1.15,null,0,.78,0,UM());a.receiveShadow=!0,it(r,2.54,.03,1.19,wt.woodDark,0,.742,0);for(const E of[-1.08,1.08])it(r,.09,.72,.16,wt.metal,E,.37,0),it(r,.13,.06,1,wt.metal,E,.03,0),it(r,.13,.05,.86,wt.metal,E,.715,0);it(r,1.95,.07,.08,wt.metal,0,.67,-.18),it(r,2,.3,.04,wt.woodDark,0,.57,-.5);const o=it(r,1.3,.05,.12,"#2a2e38",0,.5,-.3);o.castShadow=!1,it(r,.58,.62,.56,"#e6ded0",.78,.31,-.2);for(const E of[.17,.45]){it(r,.5,.24,.02,"#f1ebe0",.78,E,.09);const P=te(r,.013,.013,.16,"#8d94a3",.78,E,.105,8);P.rotation.z=Math.PI/2}it(r,.17,.07,.2,wt.metal,0,.87,-.47),te(r,.03,.035,.52,wt.metal,0,1.12,-.47,12);const l=it(r,.055,.055,.32,wt.metal,0,1.35,-.38);l.rotation.x=.3,it(r,.14,.14,.05,wt.metal,0,1.42,-.31);const c=md(r,1.5,.84,0,1.46,-.295);c.g.rotation.x=.05;const h=new dn({color:"#2a3442",toneMapped:!1}),u=new yt(new Oi(.014,12),h);u.position.set(.68,-.47,.03),c.g.add(u),s%3===1&&[["#f6d365",-.04,.09],["#f3a6b2",-.19,-.06]].forEach(([E,P,U])=>{const v=it(c.g,.11,.11,.004,E,.8,P,.02);v.rotation.z=U,v.castShadow=!1});const d=md(r,.6,.36,-.99,1.08,-.02,500);d.g.rotation.y=.62,it(d.g,.3,.03,.2,wt.metal,0,-.25,0),it(d.g,.06,.2,.06,wt.metal,0,-.14,0);const f=it(r,1.18,.008,.42,"#454d5e",0,.834,.16);f.castShadow=!1,it(r,.8,.022,.27,"#e9e6e1",-.02,.849,.15);const g=new yt(new gi(.76,.23),new Bn({map:OM(),roughness:.7}));g.rotation.x=-Math.PI/2,g.position.set(-.02,.861,.15),g.receiveShadow=!0,r.add(g);const _=new yt(new di(.055,12,8),xe("#e9e6e1"));_.position.set(.52,.843,.18),_.scale.set(1,.6,1.45),_.castShadow=!0,r.add(_),it(r,.012,.004,.05,"#9aa3b2",.52,.874,.15).castShadow=!1;const m=["#e07a5f","#3d7ea6","#f2cc8f","#81b29a"][s%4];te(r,.07,.065,.16,m,.66,.91,-.08,14);const p=new yt(new oi(.045,.012,6,12,Math.PI*1.2),xe(m));p.position.set(.73,.92,-.08),p.rotation.y=Math.PI/2,p.rotation.z=-.3,r.add(p);const y=new yt(new Oi(.062,14),xe("#4a3328",{roughness:.3}));y.rotation.x=-Math.PI/2,y.position.set(.66,.985,-.08),r.add(y),[()=>DM(r,.98,.83,-.38),()=>ap(r,1,.83,-.3),()=>Kc(r,.98,.83,-.32),()=>FM(r,1,.83,-.3),()=>zM(r,1,.83,-.28),()=>BM(r,1,.83,-.3,s)][s%6](),s%4===2&&HM(r,-.55,.835,-.18);const x=new qt;x.position.set(.86,.835,.44),r.add(x),it(x,.46,.022,.1,"#2f343f",0,.011,0);const S=rs(x,.42,.11,256,67);S.mesh.position.set(0,.07,.015),S.mesh.rotation.x=-.42,S.mesh.material=new Bn({map:S.tex,roughness:.75});const L=op(wt.chair);L.position.set(0,0,1.05),r.add(L),i.add(r),t.block(e-1.3,e+1.3,n-.7,n+.5);const T={index:s,x:e,z:n,seat:new R(e,0,n+1.05),seatY:ee,screen:c.face,side:d.face,plate:S,led:h,chair:L};return lp(T,{}),T}function op(i){const t=new qt,e=xe("#3c4250",{roughness:.9});it(t,.6,.07,.58,i,0,ee-.035,0);const n=it(t,.56,.05,.54,null,0,ee+.01,.01,e);n.castShadow=!1;const s=new qt;s.position.set(0,ee,.3),s.rotation.x=.12,t.add(s),it(s,.56,.3,.09,i,0,.19,0),it(s,.52,.34,.05,null,0,.52,.005,e);for(const r of[-.25,.25])it(s,.05,.36,.06,i,r,.52,0);it(s,.34,.13,.06,i,0,.79,-.01);for(const r of[-.33,.33]){it(t,.05,.22,.4,i,r,ee+.09,.06);const a=it(t,.09,.05,.44,null,r,ee+.21,.04,e);a.castShadow=!1}te(t,.055,.055,.18,"#6e7684",0,ee-.14,0,12),te(t,.042,.042,ee-.22,wt.metal,0,(ee-.22)/2+.06,0,10),te(t,.11,.13,.05,wt.metal,0,.08,0,14);for(let r=0;r<5;r++){const a=r/5*Math.PI*2,o=it(t,.07,.045,.3,wt.metal,0,.075,0);o.position.set(Math.sin(a)*.17,.075,Math.cos(a)*.17),o.rotation.y=a;const l=te(t,.035,.035,.025,"#22262e",Math.sin(a)*.31,.04,Math.cos(a)*.31,10);l.rotation.z=Math.PI/2,l.rotation.y=a}return t}function gd(i,t,e,n,s){const r=new qt;r.position.set(e,0,n),r.rotation.y=s,it(r,1.35,ee-.14,1.2,wt.couch,0,(ee-.14)/2,0),it(r,1.15,.14,1,"#6c8fb6",0,ee-.07,.05),it(r,1.35,.78,.26,wt.couch,0,ee+.25,-.47);for(const o of[-.54,.54])it(r,.27,.56,1.2,wt.couch,o,ee-.06,0);for(const[o,l]of[[-.55,-.5],[.55,-.5],[-.55,.5],[.55,.5]])te(r,.05,.04,.12,wt.woodDark,o,.06,l,8);i.add(r);const a=.75;return t.block(e-a,e+a,n-a,n+a),r}function GM(i,t,e,n){te(i,.26,.26,.08,n,t,ee-.04,e,20),te(i,.035,.035,ee-.09,wt.metal,t,(ee-.09)/2,e,8),te(i,.2,.22,.03,wt.metal,t,.015,e,16)}function vd(i,{title:t="",subtitle:e="",lines:n=[],accent:s="#7bd389",idle:r=!1,t:a=0}){const{ctx:o,canvas:l,tex:c}=i.screen,h=l.width,u=l.height,d=h/512,f=o.createLinearGradient(0,0,0,u);if(f.addColorStop(0,"#141c26"),f.addColorStop(1,"#0d131b"),o.fillStyle=f,o.fillRect(0,0,h,u),r){o.textAlign="center",o.fillStyle="#2f3a49",o.font=`600 ${34*d}px ${ci}`,o.fillText(t,h/2,u/2+4*d),o.fillStyle="#263040",o.font=`400 ${20*d}px ${ci}`,o.fillText(e,h/2,u/2+36*d),o.textAlign="left",c.needsUpdate=!0;return}o.fillStyle=s,o.fillRect(0,0,h,5*d),o.globalAlpha=.09,o.fillRect(0,5*d,h,76*d),o.globalAlpha=1,o.beginPath(),o.arc(30*d,40*d,6*d,0,Math.PI*2),o.fillStyle=s,o.globalAlpha=.55+.45*Math.sin(a*3),o.fill(),o.globalAlpha=1,o.fillStyle="#eaeff5",o.font=`650 ${26*d}px ${ci}`,o.fillText(t,46*d,48*d),o.fillStyle="#7d8a9c",o.font=`400 ${18*d}px ${ci}`,o.fillText(e,46*d,73*d),o.fillStyle="rgba(125, 138, 156, 0.22)",o.fillRect(24*d,92*d,1.5*d,u-104*d),o.font=`400 ${18*d}px ${PM}`;const g=n.slice(-8);g.forEach((_,m)=>{const p=m===g.length-1,y=116*d+m*23*d;o.globalAlpha=p?1:.45+m*.06,o.fillStyle=_.color||(p?"#eaeff5":"#8b98aa");let x=_.text;for(;o.measureText(x).width>h-56*d&&x.length>4;)x=x.slice(0,-2);x!==_.text&&(x=x.slice(0,-1)+"…"),o.fillText(x,38*d,y),o.globalAlpha=1}),Math.floor(a*2)%2===0&&(o.fillStyle=s,o.fillRect(38*d,116*d+g.length*23*d-14*d,9*d,17*d)),c.needsUpdate=!0}function lp(i,{name:t="",accent:e="#7d8a9c",state:n="open"}={}){const s=n==="working";i.led&&i.led.color.set(s?e:n==="open"?"#232a35":"#39455a");const r=i.plate;if(r){const{ctx:o,canvas:l,tex:c}=r;o.fillStyle="#2c323d",o.fillRect(0,0,l.width,l.height),o.fillStyle=n==="open"?"#454c5a":e,o.fillRect(0,0,9,l.height),o.fillStyle=n==="open"?"#8d97a6":"#f3f1ed",o.font=`650 30px ${ci}`,o.textBaseline="middle",o.fillText(t,26,l.height/2+1),o.textBaseline="alphabetic",c.needsUpdate=!0}const a=i.side;if(a){const{ctx:o,canvas:l,tex:c}=a,h=l.width,u=l.height;if(o.fillStyle=n==="open"?"#0b0f15":"#121a24",o.fillRect(0,0,h,u),n==="open"){o.fillStyle="#1b2430",o.beginPath(),o.arc(h/2,u/2,5,0,Math.PI*2),o.fill(),c.needsUpdate=!0;return}o.fillStyle=e,o.globalAlpha=.85,o.fillRect(0,0,h,4),o.globalAlpha=1,o.font=`600 ${Math.round(u*.1)}px ${ci}`,o.fillStyle="#6f7d8f",o.fillText(t.toUpperCase(),14,26),o.textAlign="right",o.fillStyle=s?e:"#4d5a6b",o.fillText(s?"ACTIVE":n==="away"?"OFFLINE":"IDLE",h-14,26),o.textAlign="left";let d=0;for(const f of t+n)d=(d*31+f.charCodeAt(0))%9973;for(let f=0;f<6;f++){const g=44+f*Math.round((u-58)/6),_=Math.max(4,Math.round(u*.045));o.fillStyle="#1b2531",o.fillRect(14,g,h-28,_),d=(d*31+17)%9973;const m=s?.25+d%70/100:.08+d%25/100;o.fillStyle=f===0&&s?e:"#35445a",o.fillRect(14,g,Math.round((h-28)*m),_)}c.needsUpdate=!0}}function $M(i){const t=new wM(vn,In),e=[],n=xe("#a97a50"),s=new Bn({map:cp(),roughness:.7}),r=new yt(new Ze(vn+.6,.7,In+.6),[n,n,s,n,n,n]);r.position.y=-.35,r.receiveShadow=!0,r.castShadow=!0,i.add(r);const a=new yt(new gi(160,160),new By({opacity:.14}));a.rotation.x=-Math.PI/2,a.position.y=-.72,a.receiveShadow=!0,i.add(a),i.add(WM(vn+16,In+16));const o=it(i,24.5,.02,12.6,null,0,.011,1.2,new Bn({map:kM(),roughness:1}));o.castShadow=!1;const l=[Va(i,vn+.6,0,-In/2-.15,0,[0,0,-1]),Va(i,vn+.6,0,In/2+.15,Math.PI,[0,0,1],[[-vn/2-.3,-19.2],[-16.8,vn/2+.3]]),Va(i,In,-vn/2-.15,0,Math.PI/2,[-1,0,0]),Va(i,In,vn/2+.15,0,-Math.PI/2,[1,0,0])],[c,,h,u]=l;t.block(-vn/2,vn/2,-In/2,-In/2+.2),t.block(-vn/2,-vn/2+.2,-In/2,In/2);for(const W of[-6,0,6]){const A=-W;h.attach.push(it(h.g,3.6,2.2,.06,wt.glass,A,2.2,.15,{emissive:"#bfe3f5",emissiveIntensity:.45,roughness:.15}),it(h.g,3.8,.12,.14,wt.trim,A,1.08,.2),it(h.g,3.8,.12,.14,wt.trim,A,3.32,.2),it(h.g,.1,2.3,.14,wt.trim,A,2.2,.2))}for(const W of[-6,0,6])NM(i,-17.4,W,5,3.6);const d=[];[[-9,-3],[-3,-3],[3,-3],[9,-3],[-9,5],[-3,5],[3,5],[9,5]].forEach(([W,A],It)=>d.push(VM(i,t,W,A,It)));const f=["#e07a5f","#3d7ea6","#f2cc8f","#81b29a","#9c6ade","#e5989b","#2a9d8f","#577590"];for(const W of[-18.4,-16.2,-14,-11.8]){it(i,2,3.2,.7,wt.woodDark,W,1.6,-14.5);for(let A=0;A<4;A++){const It=.45+A*.75;it(i,1.86,.05,.62,wt.wood,W,It-.04,-14.42);let Ct=W-.85;for(;Ct<W+.8;){const Bt=.1+Math.random()*.1,Dt=.4+Math.random()*.22;it(i,Bt,Dt,.45,f[Math.floor(Math.random()*f.length)],Ct+Bt/2,It+Dt/2,-14.4),Ct+=Bt+.02}}}t.block(-19.6,-10.7,-15,-14);for(const W of[12,13.4,14.8,16.2,17.6]){it(i,1.2,2.7,1,wt.rack,W,1.35,-14.4);for(let A=0;A<9;A++){const It=it(i,.07,.07,.03,"#000",W-.4+A%3*.12,.5+Math.floor(A/3)*.7+Math.random()*.2,-13.88,new Bn({color:"#0a0a0a",emissive:["#4ade80","#60a5fa","#fbbf24"][A%3],emissiveIntensity:1.2}));It.castShadow=!1,e.push(It)}for(let A=0;A<6;A++)it(i,1,.02,.02,"#4b5261",W,.35+A*.42,-13.89)}t.block(11.2,18.4,-15,-13.7);const g=new qt;g.position.set(-18.6,0,0);const _=new yt(new zn(.35,.45,.9,16),xe(wt.woodDark));_.position.y=.45;const m=new yt(new di(.45,24,16),xe("#4f8fc0",{roughness:.5}));m.position.y=1.35;const p=new yt(new Sr(.46,1),xe("#7fb069",{flatShading:!0,transparent:!0,opacity:.85}));p.position.y=1.35,p.scale.set(1,.9,.7);for(const W of[_,m,p])W.castShadow=!0,g.add(W);i.add(g),t.block(-19.2,-18,-.6,.6);const y=new qt;y.position.set(15.6,0,-8),it(y,5,2.4,.08,wt.board,0,1.9,0,{roughness:.4}),it(y,5.2,.1,.14,wt.metal,0,.66,.02),it(y,.08,1.9,.08,wt.metal,-2.3,.6,0),it(y,.08,1.9,.08,wt.metal,2.3,.6,0);const x=rs(y,4.8,2.2,640,290);x.mesh.position.set(0,1.9,.045),i.add(y),t.block(13,18.2,-8.4,-7.6);const S=it(i,9,.02,5.4,wt.rug,-14,.01,10.6);S.castShadow=!1;const L=new qt;L.position.set(-14.5,0,8.4),it(L,5,ee-.14,1.2,wt.couch,0,(ee-.14)/2,0),it(L,5,.8,.3,wt.couch,0,ee+.26,-.48);for(const W of[-2.35,2.35])it(L,.3,.6,1.2,wt.couch,W,ee-.08,0);for(const W of[-1.5,0,1.5])it(L,1.4,.14,1,"#6c8fb6",W,ee-.07,.05);for(const[W,A]of[[-2.2,-.5],[2.2,-.5],[-2.2,.5],[2.2,.5]])te(L,.05,.04,.12,wt.woodDark,W,.06,A,8);i.add(L),t.block(-17,-12,7.8,9),gd(i,t,-17.3,10.9,Math.PI/2),gd(i,t,-12,10.9,-Math.PI/2),it(i,2.4,.08,1.2,wt.wood,-14.5,.48,10.6);for(const[W,A]of[[-1.1,-.5],[1.1,-.5],[-1.1,.5],[1.1,.5]])it(i,.06,.44,.06,wt.metal,-14.5+W,.22,10.6+A);t.block(-15.8,-13.2,10,11.2),it(i,1.3,.95,3.2,"#efe9df",-19.3,.475,12),it(i,.55,.65,.5,"#2c2f36",-19.35,1.28,11.4),it(i,.12,.08,.12,"#c0392b",-19.05,1.4,11.4,{emissive:"#c0392b",emissiveIntensity:.6});for(let W=0;W<3;W++){const A=new yt(new zn(.07,.06,.14,10),xe("#ffffff"));A.position.set(-19.2,1.02,12.5+W*.25),i.add(A)}t.block(-20,-18.6,10.4,13.6);const T=new qt;T.position.set(-11,0,12),te(T,.3,.34,.04,wt.metal,0,.02,0,20),te(T,.04,.04,1.05,wt.metal,0,.55,0,10),te(T,.48,.48,.05,wt.wood,0,1.08,0,28);for(const[W,A,It]of[[-.18,.08,"#e07a5f"],[.2,-.1,"#3d7ea6"]])te(T,.06,.05,.13,It,W,1.17,A,12);i.add(T),t.block(-11.5,-10.5,11.5,12.5),c.attach.push(it(c.g,9.4,3.5,.08,"#d9cdbb",0,2.2,.2));const E=rs(c.g,9,3.2,1536,546);E.mesh.position.set(0,2.2,.26),c.attach.push(E.mesh);const P=new qt;P.position.set(15.5,0,10.6),it(P,3.4,1.05,.9,"#efe9df",0,.525,0),it(P,3.5,.06,1,wt.wood,0,1.08,0),it(P,.9,.55,.05,wt.metal,-.8,1.4,-.25);const U=rs(P,1.6,.34,400,85);U.mesh.position.set(0,.62,.456),U.ctx.fillStyle="#efe9df",U.ctx.fillRect(0,0,400,85),U.ctx.fillStyle="#1d1b18",U.ctx.font=`650 38px ${ci}`,U.ctx.textAlign="center",U.ctx.fillText("Chief of Staff",200,56),U.tex.needsUpdate=!0;const v=op(wt.chair);v.position.set(0,0,-1),v.rotation.y=Math.PI,P.add(v),i.add(P),t.block(13.7,17.3,10.1,11.1);const b=it(i,2.4,.02,1.6,"#b9a58f",18.2,.01,13.4);b.castShadow=!1,Ur(c,-7.6,2.5,1.6,1.1,Or.sunset),IM(c,7.6,2.7),Ur(u,1.4,2.4,1,1.4,Or.arcs),Ur(u,3,2.4,1,1.4,Or.blocks),Ur(u,4.6,2.4,1,1.4,Or.leaf),Ur(h,11,2.5,1.2,.9,Or.blocks,"#c39a6b");const I=new qt;I.position.set(19.35,0,3),it(I,.7,.75,3.6,wt.woodDark,0,.4,0),it(I,.76,.05,3.7,wt.wood,0,.8,0);for(const W of[-1.2,0,1.2])it(I,.02,.6,1.1,"#9a7350",-.36,.4,W);for(const[W]of[[-1.7],[1.7]])it(I,.6,.06,.06,wt.metal,0,.03,W);Kc(I,0,.82,-1.1,4),ap(I,0,.82,.2),te(I,.11,.08,.38,"#3d7ea6",.05,1.01,1.2,14,{roughness:.35});for(let W=0;W<3;W++){const A=te(I,.008,.008,.5,"#5f8f6b",.05+(W-1)*.04,1.4,1.2,4);A.rotation.z=(W-1)*.3;const It=new yt(new Sr(.06,0),xe(["#f2cc8f","#e5989b","#fff"][W],{flatShading:!0}));It.position.set(.05+(W-1)*.12,1.64,1.2),I.add(It)}i.add(I),t.block(18.9,20,1.1,4.9);const O=new qt;O.position.set(-1,0,11.6),it(O,5.2,.08,1.4,wt.wood,0,.78,0);for(const W of[-2.3,2.3])it(O,.08,.74,1.1,wt.metal,W,.38,0);for(const W of[-1.7,0,1.7])for(const A of[-1.05,1.05])GM(O,W,A,["#e07a5f","#f2cc8f","#81b29a"][Math.round(W+2)%3]);Kc(O,-1.4,.82,.1,2),te(O,.06,.06,.14,"#ffffff",.5,.89,-.2,12);const $=new qt;$.position.set(1.3,.82,.1),it($,.5,.025,.35,"#c7ccd4",0,.012,0);const K=it($,.5,.34,.02,"#c7ccd4",0,.17,-.17);K.rotation.x=-.25,O.add($);for(const W of[-1.6,1.6]){te(O,.02,.02,1.6,"#2f3440",W,3.4,0,6);const A=te(O,.06,.32,.28,"#2f3440",W,2.55,0,20,{roughness:.5});A.castShadow=!1;const It=new yt(new Oi(.29,20),new dn({color:"#fff1c4"}));It.rotation.x=Math.PI/2,It.position.set(W,2.405,0),O.add(It)}i.add(O),t.block(-3.8,1.8,10.3,12.9);const z=new qt;z.position.set(Xe.x,0,Xe.z);const Z=.84;it(z,3.7,.22,2.1,wt.woodDark,0,.71,0);for(const[W,A]of[[-1.55,-.85],[1.55,-.85],[-1.55,.85],[1.55,.85]])it(z,.2,.62,.2,wt.woodDark,W,.31,A);it(z,3.5,.03,1.9,"#2f7a57",0,Z-.015,0,{roughness:1});const V=[];for(const W of[-1,1]){for(const A of[-1,1])V.push([1.32,.1,.25,W*.82,A*.925]);V.push([.25,.1,1.36,W*1.725,0])}for(const[W,A,It,Ct,Bt]of V)it(z,W,A,It,wt.wood,Ct,Z+.05,Bt);for(const W of[-1,1])for(const A of[-1,1])it(z,.3,.1,.3,wt.wood,W*1.83,Z+.05,A*.98);for(const[W,A,It,Ct]of[[1.28,.06,.82,.83],[1.28,.06,.82,-.83],[1.28,.06,-.82,.83],[1.28,.06,-.82,-.83]])it(z,W,.05,A,"#256646",It,Z+.025,Ct).castShadow=!1;for(const W of[-1,1])it(z,.06,.05,1.3,"#256646",W*1.57,Z+.025,0).castShadow=!1;const at=new dn({color:"#0c0d10"});for(const[W,A]of[[-1.6,-.8],[1.6,-.8],[-1.6,.8],[1.6,.8],[0,-.835],[0,.835]]){const It=new yt(new zn(.15,.15,.02,20),at);It.position.set(W,Z+.002,A),z.add(It)}i.add(z),t.block(Xe.x-1.95,Xe.x+1.95,Xe.z-1.15,Xe.z+1.15);const ct=new qt;ct.position.set(-18,0,8.2),te(ct,.22,.24,.04,"#2f3440",0,.02,0,20),te(ct,.025,.025,1.7,"#2f3440",0,.87,0,8);const _t=te(ct,.22,.3,.38,"#f3e7d3",0,1.85,0,24,{emissive:"#ffe2a8",emissiveIntensity:.35,roughness:.9});_t.castShadow=!1,i.add(ct),t.block(-18.4,-17.6,7.8,8.6);const $t=it(i,5,.02,3.2,"#c9b79c",15.5,.012,12.6,{roughness:1});$t.castShadow=!1;const Jt=it(i,4.6,.022,2.8,"#ddd0bb",15.5,.013,12.6,{roughness:1});Jt.castShadow=!1;const X=[[-19,-9.5,1.1,"tall"],[10,-14,1,"snake"],[-9.8,-14.2,.9,"bush"],[19,-11,1.2,"tall"],[-10.3,14,1,"bush"],[6.2,13.8,1.1,"tall"],[19,8.5,1,"snake"],[19.2,0,.9,"bush"],[-19.1,14.2,.8,"snake"],[11.6,13.9,1,"bush"]];for(const[W,A,It,Ct]of X)LM(i,t,W,A,It,Ct);const et={n:Math.PI,s:0,w:-Math.PI/2,e:Math.PI/2},ft=W=>W.map(([A,It,Ct,Bt,Dt])=>({pos:new R(A,0,It),face:et[Ct],pose:Bt,seatY:Dt,taken:null})),ot={library:{label:"Library",spots:ft([[-17.6,-12.9,"n","read"],[-15.3,-12.9,"n","read"],[-13.1,-12.9,"n","read"],[-11,-12.9,"n","read"]])},servers:{label:"Server room",spots:ft([[12.7,-12.6,"n","type"],[14.1,-12.6,"n","type"],[15.5,-12.6,"n","type"],[16.9,-12.6,"n","type"]])},window:{label:"Research window",spots:ft([[-17.5,-6,"w","gaze"],[-17.5,-2.6,"w","gaze"],[-17.5,2.6,"w","gaze"],[-17.5,6,"w","gaze"]])},whiteboard:{label:"Whiteboard",spots:ft([[13.9,-6.4,"n","write"],[15.2,-6.4,"n","write"],[16.5,-6.4,"n","write"],[17.8,-6.4,"n","write"]])},lounge:{label:"Break room",spots:ft([[-16,8.5,"s","couch",ee],[-14.5,8.5,"s","couch",ee],[-13,8.5,"s","couch",ee],[-17.2,10.9,"e","couch",ee],[-11.9,10.9,"w","couch",ee],[-2.7,10.55,"s","sit",ee],[-1,10.55,"s","sit",ee],[.7,10.55,"s","sit",ee],[-2.7,12.65,"n","sit",ee],[-1,12.65,"n","sit",ee],[.7,12.65,"n","sit",ee],[-17.9,11.4,"w","mug"],[-17.9,12.8,"w","mug"],[-11.95,12,"e","mug"],[-10.05,12,"w","mug"]])}},At=new R(15.3,0,-2.4),Tt=Array.from({length:10},(W,A)=>{const It=Math.PI+A/10*Math.PI*2,Ct=new R(At.x+Math.sin(It)*2.3,0,At.z+Math.cos(It)*2.3);return{pos:Ct,face:Math.atan2(At.x-Ct.x,At.z-Ct.z)}});ot.lounge.spots.push({pos:new R(Xe.x-.9,0,Xe.z-1.65),face:et.s,pose:"stand",taken:null,game:!0},{pos:new R(Xe.x+.9,0,Xe.z+1.65),face:et.n,pose:"stand",taken:null,game:!0});const zt=(W,A,It,Ct,Bt)=>({pos:new R(W,0,A),face:Math.atan2(It-W,Ct-A),pose:Bt,taken:null});return ot.hotdesk={label:"Hot desks",spots:[-4.5,-2.7,-.9,.9,2.7,4.5].map(W=>zt(W,-13.4,W,-15,"read"))},ot.poolside={label:"Pool table",spots:[[4.9,10.9],[10.3,10.9],[9.6,8.8],[5.6,8.8]].map(([W,A])=>zt(W,A,Xe.x,Xe.z,"mug"))},ot.coffee={label:"Coffee",spots:ot.lounge.spots.filter(W=>W.pose==="mug")},ot.huddle={label:"Break-room table",spots:[[-4.5,11],[-4.5,12.2],[2.5,11],[2.5,12.2],[-1.85,9.6],[-.15,9.6]].map(([W,A])=>zt(W,A,-1,11.6,"stand"))},{grid:t,desks:d,stations:ot,pool:z,standup:Tt,board:E,scribble:x,blinkers:e,globe:p,slab:r,updateWalls:(W,A,It)=>jM(l,W,A,It),door:new R(18.6,0,14.4),reception:{seat:new R(15.5,0,9.6),seatY:ee}}}function cp(){const i=document.createElement("canvas");i.width=i.height=1024;const t=i.getContext("2d"),e=16,n=i.height/e;for(let r=0;r<e;r++){let a=-Math.random()*400;for(;a<i.width;){const o=380+Math.random()*520,l=73+Math.random()*3.5;t.fillStyle=`hsl(${32+Math.random()*3}, ${33+Math.random()*5}%, ${l}%)`,t.fillRect(a,r*n,o,n),t.globalAlpha=.045;for(let c=0;c<6;c++)t.fillStyle=Math.random()<.5?"#7a5634":"#fff6e8",t.fillRect(a,r*n+Math.random()*n,o,1+Math.random()*2);t.globalAlpha=1,t.fillStyle="rgba(90, 60, 35, 0.22)",t.fillRect(a,r*n,2,n),a+=o}t.fillStyle="rgba(90, 60, 35, 0.18)",t.fillRect(0,r*n,i.width,2)}const s=new zi(i);return s.colorSpace=Ke,s.wrapS=s.wrapT=Ni,s.repeat.set(vn/8,In/8),s.anisotropy=8,s}function WM(i,t){const e=document.createElement("canvas");e.width=e.height=256;const n=e.getContext("2d"),s=n.createRadialGradient(128,128,30,128,128,128);s.addColorStop(0,"rgba(60, 40, 20, 0.28)"),s.addColorStop(.6,"rgba(60, 40, 20, 0.12)"),s.addColorStop(1,"rgba(60, 40, 20, 0)"),n.fillStyle=s,n.fillRect(0,0,256,256);const r=new zi(e),a=new yt(new gi(i,t),new dn({map:r,transparent:!0,depthWrite:!1}));return a.rotation.x=-Math.PI/2,a.position.y=-.715,a}const rr=4.2,XM=.5;function Va(i,t,e,n,s,r,a=[[-t/2,t/2]]){const o=new qt;o.position.set(e,0,n),o.rotation.y=s;const l=new qt,c=new qt;o.add(l,c);for(const[u,d]of a){const f=new yt(new Ze(d-u,rr,.3),xe(wt.wall));f.position.set((u+d)/2,rr/2,0),f.castShadow=f.receiveShadow=!0,l.add(f);const g=new yt(new Ze(d-u,.1,.36),xe("#cbbba3"));g.position.set((u+d)/2,.05,0),c.add(g);const _=new yt(new Ze(d-u,.22,.04),xe(wt.trim));_.position.set((u+d)/2,.11,.17),o.add(_)}i.add(o);const h={g:o,body:l,cap:c,outward:new R(...r),h:rr,attach:[]};return c.position.y=rr,h}const _d=new R;function jM(i,t,e,n){_d.subVectors(t.position,e).setY(0).normalize();for(const s of i){const r=s.outward.dot(_d)>.2?XM:rr;s.h+=(r-s.h)*Math.min(1,n*7),s.body.scale.y=s.h/rr,s.cap.position.y=s.h;for(const a of s.attach)a.visible=s.h>3.4}}const qM={queued:0,working:1,done:2,failed:2,stopped:2},YM={queued:"#fde68a",working:"#bfdbfe",done:"#bbf7d0",failed:"#fecaca",stopped:"#e5e7eb"};function hp(i,t){const{ctx:e,canvas:n,tex:s}=i,r=n.width,a=n.height;e.fillStyle="#fbfaf7",e.fillRect(0,0,r,a);const o=["Queued","Working","Shipped"],l=r/3;o.forEach((c,h)=>{e.fillStyle="#1d1b18",e.font=`650 34px ${ci}`,e.fillText(c,h*l+28,54),h&&(e.fillStyle="#e7e1d7",e.fillRect(h*l,20,3,a-40)),t.filter(d=>qM[d.status]===h).sort((d,f)=>(f.endedAt||f.queuedAt)-(d.endedAt||d.queuedAt)).slice(0,6).forEach((d,f)=>{const g=h*l+28+f%2*(l/2-18),_=80+Math.floor(f/2)*150,m=l/2-36,p=130;e.save(),e.translate(g+m/2,_+p/2),e.rotate((d.id.charCodeAt(0)%7-3)*.008),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(-m/2+4,-p/2+6,m,p),e.fillStyle=YM[d.status],e.fillRect(-m/2,-p/2,m,p),e.fillStyle="#1d1b18",e.font=`600 22px ${ci}`,KM(e,d.title,-m/2+14,-p/2+34,m-28,26,3),e.fillStyle="#5b554c",e.font=`400 18px ${ci}`,e.fillText(d.repo.slice(0,22),-m/2+14,p/2-14),e.restore()})}),s.needsUpdate=!0}function KM(i,t,e,n,s,r,a){const o=String(t).split(/\s+/);let l="",c=0;for(let h=0;h<o.length;h++){const u=l?l+" "+o[h]:o[h];if(i.measureText(u).width>s&&l){if(c===a-1){i.fillText(l+"…",e,n+c*r);return}i.fillText(l,e,n+c*r),l=o[h],c++}else l=u}i.fillText(l,e,n+c*r)}function Zc(i,t){const{ctx:e,canvas:n,tex:s}=i;e.fillStyle="#fbfaf7",e.fillRect(0,0,n.width,n.height),e.fillStyle="#2f5d8a",e.font='600 30px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive',e.fillText("Today",26,46),e.font='400 24px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive',t.slice(0,7).forEach((r,a)=>{e.fillStyle=r.done?"#6b8f71":"#3a3a3a";const o=(r.done?"✓ ":"• ")+r.text;e.fillText(o.length>44?o.slice(0,43)+"…":o,30,86+a*30)}),s.needsUpdate=!0}const xd=(i,t,e)=>{let n=((t-i+Math.PI)%(Math.PI*2)+Math.PI*2)%(Math.PI*2)-Math.PI;return i+n*e},Fr=(i,t)=>i+Math.random()*(t-i);function Ga(i,t=34){let e=String(i||"").replace(/\s+/g," ").trim();const n=e.search(/[,;:]| \u2014 | - | and | with | so that | in order /i);if(n>11&&(e=e.slice(0,n)),e.length<=t)return e;const s=e.lastIndexOf(" ",t);return e.slice(0,s>t*.6?s:t).replace(/[,.;:]$/,"")+"…"}const yd=["coffee?","anyone seen my mug","back in 5","nice weather","who broke main","lunch soon?","reading the docs, honestly","standup when"];let Bl=null;function ZM(){if(Bl)return Bl;const i=document.createElement("canvas");i.width=i.height=64;const t=i.getContext("2d"),e=t.createRadialGradient(32,32,4,32,32,32);return e.addColorStop(0,"rgba(40, 28, 16, 0.32)"),e.addColorStop(1,"rgba(40, 28, 16, 0)"),t.fillStyle=e,t.fillRect(0,0,64,64),Bl=new zi(i)}class Nh{constructor(t,e,n,s={}){this.staff=t,this.id=t.id,this.name=t.name,this.world=e,this.desk=s.desk||e.desks[e.agentIndex(t.id)],this.deskFace=s.face??Math.PI,this.root=new qt,this.fig=new Jr(t),this.root.add(this.fig.group),this.body=this.fig.body;const r=new yt(new Oi(.5,24),new dn({map:ZM(),transparent:!0,depthWrite:!1}));r.rotation.x=-Math.PI/2,r.position.y=.015,this.root.add(r),this.ring=new yt(new Lh(.55,.68,40),new dn({color:t.shirt,transparent:!0,opacity:.9})),this.ring.rotation.x=-Math.PI/2,this.ring.position.y=.03,this.ring.visible=!1,this.root.add(this.ring),this.root.traverse(c=>{c.userData.agentId=t.id}),e.scene.add(this.root),this.pos=this.root.position,this.heading=0,this.path=[],this.goal=null,this.placeKey=null,this.spot=null,this.pose="stand",this.want="lounge",this.dwellUntil=0,this.wanderAt=0,this.chatAt=Fr(8,30),this.anim=null,this.job=null,this.lines=[],this.phase=Math.random()*10,this.label=document.createElement("div"),this.label.className="agent-label";const a=document.createElement("div");a.className="bubble";const o=document.createElement("div");o.className="name";const l=document.createElement("i");/^#[0-9a-f]{3,8}$/i.test(t.shirt??"")&&(l.style.background=t.shirt),o.append(l,String(t.name??"")),this.label.append(a,o),this.bubbleEl=this.label.querySelector(".bubble"),n.appendChild(this.label),this.say("")}say(t,e="",n=0){t!==this.bubbleText&&(this.labelDirty=!0),this.bubbleText=t,this.bubbleEl.textContent=t,this.bubbleEl.className="bubble"+(e?" "+e:""),this.bubbleEl.style.display=t?"":"none",this.bubbleUntil=n?(this.now||0)+n/1e3:0}teleport(t){const e=this.resolve(t);e&&(this.pos.copy(e.pos),this.heading=e.face,this.root.rotation.y=e.face,this.goal=e,this.path=[],this.arrive(0))}resolve(t,e=!1){if(t==="desk")return{key:t,pos:this.desk.seat.clone(),face:this.deskFace,pose:"desk",seatY:this.desk.seatY};if(t==="visit")return this.visitTarget;if(t==="standup")return this.meeting;if(t==="door")return{key:t,pos:this.world.door.clone(),face:Math.PI,pose:"stand"};const n=this.world.stations[t];if(!n)return null;let s=!e&&this.spot&&n.spots.includes(this.spot)?this.spot:null;if(!s){const a=n.spots.filter(l=>!l.game&&(!l.taken||l.taken===this.id)),o=e?a.filter(l=>l!==this.spot):a;s=(o.length?o:a)[Math.floor(Math.random()*(o.length||a.length))]}if(!s)return t==="lounge"?null:this.resolve("desk");this.spot&&this.spot!==s&&(this.spot.taken=null),s.taken=this.id,this.spot=s;const r=t==="lounge"?0:.12;return{key:t,pos:s.pos.clone().add(new R(Fr(-r,r),0,Fr(-r,r))),face:s.face,pose:s.pose,seatY:s.seatY}}goTo(t,e,n=!1){t==="desk"&&this.spot&&(this.spot.taken=null,this.spot=null);const s=this.resolve(t,n);s&&(this.goal=s,this.placeKey=null,this.path=this.world.grid.path(this.pos.x,this.pos.z,s.pos.x,s.pos.z),this.path.length||this.arrive(e))}arrive(t){const e=this.goal;this.pos.set(e.pos.x,0,e.pos.z),this.placeKey=e.key,this.pose=e.pose,this.seatY=e.seatY,this.dwellUntil=t+(e.key==="desk"?.8:e.key==="lounge"?0:e.key==="visit"?3.4:e.key==="standup"?.5:2.4),e.key==="lounge"&&(this.wanderAt=t+Fr(18,40))}assign(t,e=!1){this.job=t,this.anim=null,this.want="desk",this.lines=[],this.say("On it","",0),e&&this.teleport("desk")}visit(t,e){const n=this.world.grid,s=[[1.1,0],[-1.1,0],[0,1.1],[0,-1.1],[.9,.9],[-.9,.9]],[r,a]=s.find(([l,c])=>!n.blocked(...n.cellOf(t.pos.x+l,t.pos.z+c)))||[1.1,0],o=new R(t.pos.x+r,0,t.pos.z+a);this.visitTarget={key:"visit",pos:o,face:Math.atan2(t.pos.x-o.x,t.pos.z-o.z),pose:"talk"},this.afterVisit=this.want==="visit"?this.afterVisit:this.want,this.want="visit",this.placeKey=null,this.path=[],this.spot&&(this.spot.taken=null,this.spot=null),this.say(Ga(e,52),"talk",0)}onLog(t){if(!this.job)return;const e=(...r)=>!this.meeting&&this.say(...r),n={tool:null,text:"#e8edf3",error:"#f87171",thinking:"#64748b",system:"#64748b"}[t.kind],s=r=>{this.want==="visit"?this.afterVisit=r:this.want=r};if(t.kind==="tool")s("desk"),e(Ga(t.summary)),this.lines.push({text:"› "+t.summary,color:n});else if(t.kind==="text"){s("desk");const r=t.summary.split(new RegExp("(?<=[.!?])\\s|\\n"))[0];e(Ga(r,44)),this.lines.push({text:r,color:n})}else t.kind==="thinking"?e("thinking…","thinking"):t.kind==="error"?(e(t.blocked?"Needs clearance":"Hm, that failed","warn"),this.lines.push({text:"✕ "+t.summary.split(`
4301
+ `)[0],color:n})):t.kind==="system"&&(this.lines.push({text:t.summary,color:n}),t.wait&&(s("desk"),e(Ga(t.summary,30)+"…","thinking")));this.lines.length>40&&this.lines.splice(0,this.lines.length-40)}meet(t,e=!1){if(this.meeting={key:"standup",pos:t.pos.clone(),face:t.face,pose:"stand"},this.spot&&(this.spot.taken=null,this.spot=null),e)return this.teleport("standup");this.want!=="visit"&&(this.path=[],this.placeKey=null)}adjourn(){this.meeting=null,this.placeKey==="standup"&&(this.placeKey=null)}speak(t){this.say(t,"talk",5200),this.anim={kind:"talk",until:(this.now||0)+4.8}}leave(){this.leaving=!0,this.want="door",this.spot&&(this.spot.taken=null,this.spot=null),this.say("Heading home","idle",3e3)}stay(){this.leaving=!1,this.want="lounge",this.say("Oh, staying!","good",2500)}dispose(){this.spot&&(this.spot.taken=null),this.world.scene.remove(this.root),this.label.remove()}finish(t){const e=this.now||0;this.anim={kind:t==="done"?"celebrate":"slump",until:e+2.2},this.say(t==="done"?"Shipped it!":t==="waiting"?"Need your answer":t==="stopped"?"Okay, stopping":"Hit a wall",t==="done"?"good":"warn",4e3),this.job=null,this.afterVisit=null,this.want="lounge"}think(t){var s;if(this.anim&&t<this.anim.until)return;this.anim=null,this.bubbleUntil&&t>this.bubbleUntil&&this.say("");const e=this.meeting&&!this.leaving&&this.want!=="visit"?"standup":this.want;if(this.path.length){((s=this.goal)==null?void 0:s.key)==="lounge"&&e!=="lounge"&&this.goTo(e,t);return}if(t<this.dwellUntil)return;if(this.leaving&&this.placeKey==="door"){this.gone=!0;return}this.placeKey==="visit"&&this.want==="visit"&&(this.want=this.job?this.afterVisit||"desk":"lounge",this.afterVisit=null,this.bubbleEl.classList.contains("talk")&&this.say(""));const n=this.meeting&&!this.leaving&&this.want!=="visit"?"standup":this.want;n!==this.placeKey?this.goTo(n,t):n==="lounge"&&t>this.wanderAt&&this.goTo("lounge",t,!0),!this.job&&!this.meeting&&!this.chatting&&t>this.chatAt&&(this.chatAt=t+Fr(25,60),Math.random()<.5&&this.say(yd[Math.floor(Math.random()*yd.length)],"idle",3500))}update(t,e){var s;this.now=e,this.think(e);let n=!1;if(this.path.length){const[r,a]=this.path[0],o=r-this.pos.x,l=a-this.pos.z,c=Math.hypot(o,l),h=3.4*t;c<=h?(this.pos.x=r,this.pos.z=a,this.path.shift(),this.path.length||this.arrive(e)):(this.pos.x+=o/c*h,this.pos.z+=l/c*h,this.heading=xd(this.heading,Math.atan2(o,l),Math.min(1,t*12)),n=!0)}!n&&this.goal&&!this.path.length&&(this.heading=xd(this.heading,this.goal.face,Math.min(1,t*8))),this.root.rotation.y=this.heading,this.animate(n?"walk":((s=this.anim)==null?void 0:s.kind)||this.pose,t,e)}animate(t,e,n){var a;this.fig.pose(t,e,n+this.phase,{typing:!!this.job&&!this.job.waiting&&this.job.id!=="idle",waiting:!!((a=this.job)!=null&&a.waiting),seatY:this.seatY});const s=this.bubbleEl.className,r=t==="celebrate"?"happy":t==="slump"||s.includes("warn")?"worried":t==="talk"||s.includes("idle")&&this.bubbleText?"talk":s.includes("thinking")?"think":s.includes("good")?"happy":"neutral";this.fig.express(r,e,n+this.phase)}placeLabel(t,e,n){const s=new R(this.pos.x,this.body.position.y+2.5+(this.fig.look.hair==="afro"?.2:0),this.pos.z).project(t);if(this.onScreen=s.z<=1,!this.onScreen){this.label.style.display="none",this.lift=0;return}this.label.style.display="",this.anchorX=(s.x*.5+.5)*e,this.anchorY=(-s.y*.5+.5)*n,this.depth=s.z,this.label.style.zIndex=String(Math.round((1-s.z)*1e4)),(this.labelDirty||!this.labelW)&&this.measureLabel()}measureLabel(){this.label.offsetWidth&&(this.labelDirty=!1,this.labelW=this.label.offsetWidth,this.labelH=this.label.offsetHeight)}labelBox(t){const e=this.anchorY-t;return{left:this.anchorX-this.labelW/2,right:this.anchorX+this.labelW/2,top:e-this.labelH,bottom:e}}setLift(t,e){const n=this.lift===void 0?1:Math.min(1,e*9);this.lift=(this.lift||0)+(t-(this.lift||0))*n,Math.abs(this.lift-t)<.4&&(this.lift=t),this.label.style.transform=`translate(-50%, -100%) translate(${this.anchorX}px, ${this.anchorY-this.lift}px)`}setBuried(t){t!==this.buried&&(this.buried=t,this.label.classList.toggle("buried",t))}setCrowded(t,e){t?this.uncrowdAt=e+.6:this.crowded&&e<(this.uncrowdAt||0)&&(t=!0),t!==this.crowded&&(this.crowded=t,this.label.classList.toggle("crowded",t),this.measureLabel())}setSelected(t){this.ring.visible=t,this.label.classList.toggle("selected",t)}}const $a=(i,t)=>i+Math.random()*(t-i),Qr=i=>i[Math.floor(Math.random()*i.length)];async function ts(i,t,e){const n=await fetch(i,t===void 0?{method:e||"GET"}:{method:e||"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`Request failed (${n.status})`);return n.json().catch(()=>({}))}const JM=[["Coffee machine is making that noise again.","It does that when it likes you.","It has never liked me."],["Weekend plans, {b}?","Sleep, then more sleep.","Ambitious. I respect it."],["Did you see the size of that last diff?","I saw it. I chose not to look closer.","Wise."],["{b}, tabs or spaces?","Whatever the linter says.","Diplomatic answer.","It's the only safe one in here."],["I renamed one variable and forty tests broke.","Only forty? Lucky.","You have a dark sense of luck, {b}."],["Who keeps leaving one sip in the coffee pot?","Not me.","That is exactly what someone guilty would say."],["Favourite error message?",'"Something went wrong."',"So helpful. So honest."],["Read anything good lately?","The changelog for our test runner. Gripping stuff.","No spoilers please."],["This couch is too comfy.","Dangerous for productivity.","Good thing nobody has given us work yet."],["Do you ever dream in stack traces?","Only on deploy days.","Same."],["{b}, you were quiet in standup.","Saving my words for code review.","Ominous."],["Hot take: README files are love letters.","To whom?","To whoever opens this repo at 2am.","That's beautiful, {a}."],["What's the plant's name?","I call it Prod.","Why?","Because we don't touch it."],["I fixed a bug by deleting code today.","Best kind of fix.","Felt like spring cleaning."],["Lunch?","Already had it. Twice.","Bold."],['Have you noticed the boss says "quick change" a lot?',"Never quick.","Rarely one change."],["If you could rewrite one thing from scratch?","The build config.","Wouldn't we all."],["How do you stay so calm, {b}?","Small commits.","That explains a lot."]],QM=[{pair:["tunde","obi"],lines:["Still thinking about idempotency keys, {b}.","You always are. It is why I trust you with the ledger.","Say it again, but with a retry.","Same result. That is the whole point."]},{pair:["tunde","obi"],lines:["Remember the first ledger?","Four of us and one whiteboard.","We never did erase that whiteboard.","It's load-bearing now."]},{pair:["kai","zola"],lines:["Submission day, {b}. Checklist out?","Always out. Step one: breathe.","Step two: provisioning profile.","Step two is where we cry."]},{pair:["kai","zola"],lines:["Another rejection email. I can feel it.","Read it first. Then panic.","That is not on the checklist.","I will add it."]},{pair:["ada","mira"],lines:["I had a thought about the dashboard, {b}.","Is it a question? Please let it be a question.","It is a question.","Then I love it already. Go."]},{pair:["ada","tunde"],lines:["Does the new screen survive a retry, {b}?","You asked before I did.","You taught me.","Noted. Quietly proud."]},{pair:["ada","kai"],lines:["It should feel the same on web and app.","Thumbs do not agree.","Thumbs never do.","Move the button down, {a}."]},{pair:["mira","lin"],lines:["Could you look at this early, {b}? Before it is finished?","You ask early. I like that.","Startup scars.","The good kind of scar."]},{pair:["mira","tunde"],lines:["I could just own this whole feature, {b}.","Could you also wait for my green light?","That is the hard part.","It is the part that saves you."]},{pair:["mira","zola"],lines:["Ship it now, {b}?","Not yet.","How about now?","Ask me after the checklist."]},{pair:["lin","obi"],lines:["Another payload for you, {a}.","Guilty until proven valid.","You read my mind.","I read your schema."]},{pair:["lin","tunde"],lines:["Your logs are very readable, {b}.","I log everything now.","I know. It started on a train.","Do not remind me."]},{pair:["zola","tunde"],lines:["That alert again.","I saw it.","We nod?","We nod."]},{pair:["remi","mira"],lines:["Found a bug in your feature, {b}.","Wonderful. Send me the steps.","No defence? No excuses?","I would rather have the bug than the excuse."]}],tb=[{who:"tunde",lines:["Remember the Tuesday, {b}?","Nobody has forgotten the Tuesday.","That is why I log everything now.","Fair enough."]},{who:"kai",lines:["Did you hear? An app rejected over one permission string.","Is this the one you keep telling us about?","Never gets old.","It does, {a}."]},{who:"ada",lines:["Found a loading spinner I actually like.","Is it going in the folder?","It is going in the folder.","There is a folder?"]},{who:"zola",lines:["The release train ran on time again.","Because of the checklist.","Because of the checklist.","We all owe it a coffee."]},{who:"obi",lines:["Webhooks are promises, {b}.","To whom?","To whichever team is waiting on them.","Heavy thought for a coffee break."]},{who:"mira",lines:["One quick question, {b}.","Your questions are never quick.","This one is tiny.","Narrator: it was not."]},{who:"lin",lines:["Anyone have a worry they have not told anyone?","Not yet.","My door is open, and so is the kettle.","Thanks, {a}."]},{who:"remi",lines:['Anyone say "it works on my machine" today?',"Not me.","Good. I was sharpening my pencil.","Please do not."]}];function eb(i,t){const e=QM.filter(r=>r.pair.includes(i.id)&&r.pair.includes(t.id)),n=tb.filter(r=>r.who===i.id||r.who===t.id),s=Math.random();if(e.length&&s<.55){const r=Qr(e);return Md(r.pair[0],r.lines,i,t)}if(n.length&&s<.8){const r=Qr(n);return Md(r.who,r.lines,i,t)}return{who:[i,t],script:Qr(JM)}}function Md(i,t,e,n){return{who:i===e.id?[e,n]:[n,e],script:t}}const zr=i=>!i.job&&!i.meeting&&!i.leaving&&!i.path.length&&i.want==="lounge"&&i.placeKey==="lounge"&&!i.playing;class nb{constructor(){this.next=$a(10,20),this.chat=null,this.claiming=!1}update(t,e){if(this.chat)return this.step(e);if(this.claiming||e<this.next)return;const n=t.filter(zr);if(n.length<2)return;const s=Qr(n),r=Qr(n.filter(a=>a!==s));this.claim(s,r,e)}async claim(t,e,n){this.claiming=!0,this.next=n+$a(20,45);let s=null,r=null;try{({id:s,script:r}=await ts("/api/chill",{who:[t.id,e.id]}))}catch{}if(this.claiming=!1,!!s){if(!zr(t)||!zr(e))return this.release(s);this.start(t,e,s,r)}}start(t,e,n,s){const{who:[r,a],script:o}=Array.isArray(s)&&s.length>=2?{who:[t,e],script:s}:eb(t,e),l=o.map(c=>c.replaceAll("{a}",r.name).replaceAll("{b}",a.name));for(const[c,h]of[[r,a],[a,r]])c.chatting=!0,c.wanderAt=1/0,c.pose!=="couch"&&(c.goal={...c.goal,face:Math.atan2(h.pos.x-c.pos.x,h.pos.z-c.pos.z)});this.chat={id:n,who:[r,a],script:l,line:0,at:0}}step(t){const e=this.chat;if(!e.who.every(zr))return this.end(t);if(t<e.at)return;if(e.line>=e.script.length)return this.end(t);const n=e.who[e.line%2],s=e.script[e.line];n.say(s,"idle",3200+s.length*30),ts(`/api/chill/${e.id}/line`,{from:n.id,text:s}).catch(()=>{}),e.at=t+2.6+s.length*.035,e.line++}end(t){this.release(this.chat.id);for(const e of this.chat.who)e.chatting=!1,zr(e)&&(e.wanderAt=t+$a(8,20));this.chat=null,this.next=t+$a(20,45)}release(t){ts(`/api/chill/${t}`,void 0,"DELETE").catch(()=>{})}}const qe=3.2,Ti=1.6,Le=.075,up=.9,Wa=.78,bd=7,ib=1/240,Xa=.15,Sd=.135,Uh=[{x:-qe/2,z:-Ti/2,r:Xa},{x:qe/2,z:-Ti/2,r:Xa},{x:-qe/2,z:Ti/2,r:Xa},{x:qe/2,z:Ti/2,r:Xa},{x:0,z:-Ti/2-.035,r:Sd},{x:0,z:Ti/2+.035,r:Sd}],ja=i=>i===0?"cue":i===8?"eight":i<8?"solids":"stripes";function Jc(){const i=[{n:0,x:-qe/4,z:0,vx:0,vz:0,in:!1}],t=[1,2,3,4,5,6,7,9,10,11,12,13,14,15].sort(()=>Math.random()-.5),e=new Array(15);e[4]=8;const n=[10,14];e[n[0]]=t.splice(t.findIndex(a=>a<8),1)[0],e[n[1]]=t.splice(t.findIndex(a=>a>8),1)[0];for(let a=0;a<15;a++)e[a]||(e[a]=t.pop());const s=Le*2*1.002;let r=0;for(let a=0;a<5;a++)for(let o=0;o<=a;o++)i.push({n:e[r++],x:qe/4+a*s*.866,z:(o-a/2)*s,vx:0,vz:0,in:!1});return i}function sb(i,t,e={}){var s,r,a;let n=t;for(;n>1e-9;){const o=Math.min(ib,n);n-=o;for(const l of i){if(l.in)continue;const c=Math.hypot(l.vx,l.vz);if(c>0){const f=Math.max(0,c-up*o),g=f/c;l.vx*=g,l.vz*=g,f<.012&&(l.vx=0,l.vz=0)}l.x+=l.vx*o,l.z+=l.vz*o;const h=qe/2-Le,u=Ti/2-Le;let d=!1;l.x<-h?(l.x=-h,l.vx=Math.abs(l.vx)*Wa,d=!0):l.x>h&&(l.x=h,l.vx=-Math.abs(l.vx)*Wa,d=!0),l.z<-u?(l.z=-u,l.vz=Math.abs(l.vz)*Wa,d=!0):l.z>u&&(l.z=u,l.vz=-Math.abs(l.vz)*Wa,d=!0),d&&((s=e.cushion)==null||s.call(e,l));for(const f of Uh)if(Math.hypot(l.x-f.x,l.z-f.z)<f.r){l.in=!0,l.vx=0,l.vz=0,l.pocket=f,(r=e.pocket)==null||r.call(e,l,f);break}}for(let l=0;l<i.length;l++){const c=i[l];if(!c.in)for(let h=l+1;h<i.length;h++){const u=i[h];if(u.in)continue;const d=u.x-c.x,f=u.z-c.z,g=d*d+f*f;if(g>=4*Le*Le||g===0)continue;const _=Math.sqrt(g),m=d/_,p=f/_,y=(2*Le-_)/2;c.x-=m*y,c.z-=p*y,u.x+=m*y,u.z+=p*y;const x=(u.vx-c.vx)*m+(u.vz-c.vz)*p;if(x<0){const S=-1.96*x/2;c.vx-=S*m,c.vz-=S*p,u.vx+=S*m,u.vz+=S*p,(a=e.hit)==null||a.call(e,c,u,-x)}}}}}const rb=i=>i.some(t=>!t.in&&(t.vx||t.vz));class ab{constructor(t){this.players=t,this.balls=Jc(),this.turn=0,this.groups=null,this.shots=0,this.winner=null,this.over=null,this.inHand=!0,this.begin()}get cue(){return this.balls[0]}get shooter(){return this.players[this.turn]}get other(){return this.players[1-this.turn]}begin(){this.log={first:null,potted:[],cushion:!1,legal:this.targets().map(t=>t.n)}}targets(t=this.shooter){const e=this.balls.filter(s=>s.n&&!s.in);if(!this.groups)return e.filter(s=>s.n!==8);const n=e.filter(s=>ja(s.n)===this.groups[t]);return n.length?n:e.filter(s=>s.n===8)}remaining(t){return this.groups?this.balls.filter(e=>e.n&&!e.in&&ja(e.n)===this.groups[t]).length:7}recorder(){return{hit:(t,e)=>{this.log.first===null&&(t.n===0||e.n===0)&&(this.log.first=t.n===0?e.n:t.n)},pocket:t=>this.log.potted.push(t.n),cushion:()=>{this.log.cushion=!0}}}settle(){this.shots++;const{first:t,potted:e}=this.log,n=this.shooter,s=this.shots===1,r=e.includes(0),a=e.includes(8),o=this.log.legal,l={foul:!1,why:"",potted:e.filter(h=>h),continues:!1,assigned:null,eight:a};if(s&&a){const h=this.balls.find(u=>u.n===8);h.in=!1,h.x=qe/4,h.z=0,h.vx=h.vz=0,e.splice(e.indexOf(8),1),l.eight=!1}if(t===null?(l.foul=!0,l.why="missed everything"):o.includes(t)||(l.foul=!0,l.why=t===8?"hit the eight first":"wrong ball first"),r&&(l.foul=!0,l.why="scratched"),!l.foul&&!s&&!e.length&&!this.log.cushion&&(l.foul=!0,l.why="nothing reached a cushion"),l.eight){const h=this.groups&&o.every(u=>u===8);return h&&!l.foul?this.finish(n,"eight"):this.finish(this.other,h?"foul-eight":"early-eight"),l.over=this.over,l}if(!this.groups&&!l.foul&&!s){const h=e.find(u=>u&&u!==8);if(h){const u=ja(h);this.groups={[n]:u,[this.other]:u==="solids"?"stripes":"solids"},l.assigned=u}}if(r){const h=this.cue;h.in=!1,h.vx=h.vz=0}const c=e.filter(h=>h&&h!==8&&(!this.groups||ja(h)===this.groups[n]));if(l.continues=!l.foul&&c.length>0,this.inHand=l.foul,l.continues||(this.turn=1-this.turn),this.shots>=80&&!this.winner){const h=this.remaining(this.players[0]),u=this.remaining(this.players[1]);this.finish(h<=u?this.players[0]:this.players[1],"worn-out"),l.over=this.over}return this.begin(),l}finish(t,e){this.winner=t,this.over=e}placeCue(t){const e=this.cue,n=(r,a)=>this.balls.every(o=>o===e||o.in||Math.hypot(o.x-r,o.z-a)>Le*2.4),s=t?[[-qe/4,0],[-qe/4,.2],[-qe/4,-.2]]:[[-qe/4,0],[-qe/3,.3],[-qe/3,-.3],[.3,.3],[.3,-.3],[-.2,.5],[-.2,-.5],[-qe/2+.3,.2]];for(const[r,a]of s)if(n(r,a)){e.x=r,e.z=a,e.vx=e.vz=0,e.in=!1;return}for(let r=0;r<200;r++){const a=(Math.random()-.5)*(qe-.4),o=(Math.random()-.5)*(Ti-.4);if(n(a,o)){e.x=a,e.z=o,e.vx=e.vz=0,e.in=!1;return}}}}const Hl=(i,t,e,n,s,r,a)=>{const o=n-t,l=s-e,c=o*o+l*l||1e-9;for(const h of i){if(h.in||r.includes(h))continue;const u=Math.max(0,Math.min(1,((h.x-t)*o+(h.z-e)*l)/c));if(Math.hypot(h.x-(t+u*o),h.z-(e+u*l))<a)return!1}return!0};function ob(i,t=.7){const e=i.balls,n=i.cue,s=i.targets();let r=null;if(i.shots===0){const c=e.find(h=>h.n!==0&&h.x===Math.min(...e.filter(u=>u.n).map(u=>u.x)));r={angle:Math.atan2(c.z-n.z,c.x-n.x),speed:5.6+Math.random()*1.2,target:c,pocket:null,clean:!1,power:"break"}}else{for(const c of s)for(const h of Uh){const u=h.x*.97,d=h.z*.97,f=u-c.x,g=d-c.z,_=Math.hypot(f,g)||1e-9,m=c.x-f/_*2*Le,p=c.z-g/_*2*Le;if(Math.abs(m)>qe/2-Le||Math.abs(p)>Ti/2-Le)continue;const y=m-n.x,x=p-n.z,S=Math.hypot(y,x);if(S<Le*2)continue;const L=(y*f+x*g)/(S*_);if(L<.34||!Hl(e,n.x,n.z,m,p,[n,c],Le*2*.98)||!Hl(e,c.x,c.z,u,d,[n,c],Le*2*.98))continue;const T=L*2-(S+_)*.35-(c.n===8,0);(!r||T>r.score)&&(r={angle:Math.atan2(x,y),speed:Math.min(bd*.8,Math.sqrt(2*up*(S+_*1.3))+1.1),target:c,pocket:h,clean:!0,score:T})}if(!r){const c=s.length?s:e.filter(f=>f.n&&!f.in),h=c.filter(f=>Hl(e,n.x,n.z,f.x,f.z,[n,f],Le*2*.98)),u=h.length?h:c;u.sort((f,g)=>Math.hypot(f.x-n.x,f.z-n.z)-Math.hypot(g.x-n.x,g.z-n.z));const d=u[0];r={angle:Math.atan2(d.z-n.z,d.x-n.x),speed:2.6+Math.random()*1.2,target:d,pocket:null,clean:!1}}}const a=Math.hypot(r.target.x-n.x,r.target.z-n.z),o=(.006+.026*(1-t))*(.8+a*.35),l=()=>(Math.random()+Math.random()+Math.random()-1.5)*1.4;return r.angle+=l()*o*(r.power==="break"?.6:1),r.speed=Math.min(bd,Math.max(1.2,r.speed*(1+l()*.06*(1.2-t)))),r}function lb(i,t,e){i.cue.vx=Math.cos(t)*e,i.cue.vz=Math.sin(t)*e}let Xn=null,ho=null,Eo=!1;try{Eo=localStorage.getItem("office.muted")==="1"}catch{}function dp(){if(!Xn){const i=window.AudioContext||window.webkitAudioContext;if(!i)return;Xn=new i,ho=Xn.createGain(),ho.gain.value=.5,ho.connect(Xn.destination)}Xn.state==="suspended"&&Xn.resume()}addEventListener("pointerdown",dp);addEventListener("keydown",dp);function Dn(i,t,e,{type:n="sine",gain:s=.2}={}){const r=Xn.currentTime+t,a=Xn.createOscillator(),o=Xn.createGain();a.type=n,a.frequency.setValueAtTime(i,r),o.gain.setValueAtTime(1e-4,r),o.gain.exponentialRampToValueAtTime(s,r+.012),o.gain.exponentialRampToValueAtTime(1e-4,r+e),a.connect(o).connect(ho),a.start(r),a.stop(r+e+.05)}const Js=()=>!Eo&&Xn&&Xn.state==="running",cn={get muted(){return Eo},setMuted(i){Eo=i;try{localStorage.setItem("office.muted",i?"1":"0")}catch{}},ship(){Js()&&([659.25,830.61,987.77].forEach((i,t)=>{Dn(i,t*.085,.55,{gain:.16}),Dn(i*2,t*.085,.3,{type:"triangle",gain:.035})}),Dn(1318.5,.26,.9,{gain:.09}))},fail(){Js()&&(Dn(293.66,0,.35,{type:"triangle",gain:.12}),Dn(246.94,.14,.5,{type:"triangle",gain:.12}))},levelUp(){Js()&&[523.25,659.25,783.99,1046.5,1318.5].forEach((i,t)=>Dn(i,t*.07,.7,{gain:.13}))},knock(){Js()&&(Dn(880,0,.09,{gain:.06}),Dn(1174.7,.07,.12,{gain:.05}))},click(i=.5){if(!Js())return;const t=.025+i*.07;Dn(1900+Math.random()*500,0,.035,{type:"triangle",gain:t}),Dn(3100,0,.02,{gain:t*.5})},pocket(){Js()&&(Dn(180,0,.18,{type:"triangle",gain:.09}),Dn(120,.06,.22,{type:"sine",gain:.07}))}},Qs=(i,t)=>i+Math.random()*(t-i),ei=i=>i[Math.floor(Math.random()*i.length)],cb=["#f2c230","#2f5fb3","#d6402f","#6a3a9c","#e8803a","#2f8a4f","#8a2a2e"];function hb(i){const t=document.createElement("canvas");t.width=128,t.height=64;const e=t.getContext("2d"),n=i===0?"#f4f1ea":i===8?"#1b1b1f":cb[(i-1)%7];if(e.fillStyle=i>8?"#f4f1ea":n,e.fillRect(0,0,128,64),i>8&&(e.fillStyle=n,e.fillRect(0,14,128,36)),i){e.font="700 17px Inter, system-ui, sans-serif",e.textAlign="center",e.textBaseline="middle";for(const r of[32,96])e.fillStyle="#f4f1ea",e.beginPath(),e.arc(r,32,13,0,Math.PI*2),e.fill(),e.fillStyle="#1b1b1f",e.fillText(String(i),r,33)}const s=new zi(t);return s.colorSpace=Ke,s}const ub=["corner","corner","corner","corner","side","side"],db=i=>ub[Uh.indexOf(i)]||"pocket",fb=[["Eight ball? Loser buys the coffee.","You are on."],["Quick game of eight ball?","Rack them up."],["Pool table is free. That never happens.","Then we have to."],["Break is yours.","Bold of you to give me the break."]],pb=["Nice.","Smooth.","That one dropped.","Clean.","In."],mb=["So close.","Rolled out.","Unlucky.","The table is tilted."],gb=["Scratch.","Ugh, foul.","The cue ball had other plans."],vb=["Ball in hand.","Your table.","Thank you."],_b=["Here goes.","Let me see this one.","Easy.","Trust the line."],xb=["Good game.","That was fun.","Rematch later?"],yb=["Rematch.","Good game. Coffee is on me.","The table was tilted."];class Mb{constructor(t,e){this.spots=e.stations.lounge.spots.filter(a=>a.game),this.root=new qt,this.root.position.set(Xe.x,0,Xe.z),t.add(this.root);const n=new di(Le,20,14);this.meshes=[];for(let a=0;a<=15;a++){const o=new yt(n,new Bn({map:hb(a),roughness:.22,metalness:.02}));o.castShadow=!0,o.userData={x:0,z:0,sunk:null},this.root.add(o),this.meshes.push(o)}this.cue=new qt;const s=new yt(new zn(.016,.026,1.9,8),xe("#d9b27a"));s.rotation.z=Math.PI/2,s.position.x=-.95,s.castShadow=!0;const r=new yt(new zn(.016,.016,.04,8),xe("#5b8fb0"));r.rotation.z=Math.PI/2,r.position.x=-.02,this.cue.add(s,r),this.cueOuter=new qt,this.cueOuter.add(this.cue),this.cue.rotation.z=-.12,this.cueOuter.visible=!1,this.root.add(this.cueOuter),this.resting=Jc(),this.view=this.resting,this.next=Qs(25,45),this.s=null,this.claiming=!1}get playing(){return!!this.s}update(t,e,n){this.s?this.run(e,n):!this.claiming&&e>=this.next&&this.tryStart(t,e),this.draw(e,n)}tryStart(t,e){const n=o=>!o.gone&&!o.job&&!o.meeting&&!o.leaving&&o.want==="lounge"&&!o.playing&&!o.chatting,s=t.filter(n);if(this.next=e+Qs(15,30),s.length<2)return;const r=ei(s),a=ei(s.filter(o=>o!==r));this.claim(r,a,e)}async claim(t,e,n){this.claiming=!0;let s=null;try{({id:s}=await ts("/api/chill",{who:[t.id,e.id],game:!0}))}catch{}if(this.claiming=!1,!s)return;const r=a=>!a.gone&&!a.job&&!a.meeting&&!a.leaving&&a.want==="lounge"&&!a.playing&&!a.chatting;if(!r(t)||!r(e))return this.release(s);this.begin(t,e,s,n)}begin(t,e,n,s){const r=[t,e];r.forEach((o,l)=>{const c=this.spots[l];o.spot&&o.spot!==c&&(o.spot.taken=null),o.spot=c,c.taken=o.id,o.playing=!0,o.chatting=!0,o.wanderAt=1/0,o.goTo("lounge",s)});const a=o=>.45+([...o.id].reduce((l,c)=>l*31+c.charCodeAt(0),7)>>>0)%50/100;this.s={id:n,players:r,skill:r.map(a),phase:"walk",deadline:s+60,game:null,plan:null,shots:0}}called(t){return t.gone||t.job||t.meeting||t.leaving||t.want!=="lounge"}run(t,e){const n=this.s;if(n.players.some(o=>this.called(o)))return this.stop(t,!1);for(const o of n.players)o.wanderAt=1/0;t-(n.pinged??0)>30&&(n.pinged=t,ts(`/api/chill/${n.id}/ping`,{}).catch(()=>{}));const[s,r]=n.players,a=o=>{var l;return o.placeKey==="lounge"&&!o.path.length&&((l=o.spot)==null?void 0:l.game)};switch(n.phase){case"walk":{if(t>n.deadline)return this.stop(t,!1);if(!a(s)||!a(r))return;n.game=new ab([s.id,r.id]),this.view=n.game.balls;for(const c of this.meshes)c.userData.sunk=null;const[o,l]=ei(fb);s.say(o,"idle",3200),n.phase="rack",n.until=t+1.2,n.line=l,n.said=!1,ts(`/api/chill/${n.id}/line`,{from:s.id,text:o}).catch(()=>{});return}case"rack":!n.said&&t>n.until-.4&&(r.say(n.line,"idle",2600),n.said=!0),t>n.until&&this.aim(t);return;case"aim":return this.aiming(t);case"roll":{const o=n.rec;if(n.clicks=0,sb(n.game.balls,Math.min(e,.05),o),n.rolled+=e,n.rolled>.3&&(this.cueOuter.visible=!1),rb(n.game.balls)&&n.rolled<22)return;for(const l of n.game.balls)l.vx=0,l.vz=0;return this.settled(t)}case"pause":t>n.until&&this.aim(t);return;case"over":t>n.until&&this.stop(t,!0)}}agentOf(t){return this.s.players.find(e=>e.id===t)}aim(t){const e=this.s,n=e.game,s=this.agentOf(n.shooter),r=this.agentOf(n.other),a=e.players.indexOf(s);n.inHand&&n.placeCue(n.shots===0),e.plan=ob(n,e.skill[a]),e.t0=t,e.dur=Qs(1.5,2.2),e.struck=!1,e.phase="aim",e.shooter=s,e.waiter=r;const o=Xe.x+n.cue.x,l=Xe.z+n.cue.z;s.goal={...s.goal,face:Math.atan2(o-s.pos.x,l-s.pos.z)},r.goal={...r.goal,face:Math.atan2(o-r.pos.x,l-r.pos.z)};const c=e.plan.pocket&&db(e.plan.pocket),h=c&&Math.random()<.4?e.plan.target.n===8?`Eight ball, ${c} pocket.`:`${c[0].toUpperCase()}${c.slice(1)} pocket.`:Math.random()<.18?ei(_b):"";h&&s.say(h,"idle",2400),this.cueOuter.visible=!0}aiming(t){const e=this.s,n=e.game,s=Math.min(1,(t-e.t0)/e.dur);e.shooter.anim={kind:"cue",until:t+.5},e.waiter.anim={kind:"mug",until:t+.5};const r=s<.55?.07+Math.sin(s*40)*.006:s<.85?.07+((s-.55)/.3)**2*.34:.41*(1-(s-.85)/.15)+.02;this.placeCue(r,e.plan.angle),s>=1&&!e.struck&&(e.struck=!0,lb(n,e.plan.angle,e.plan.speed),cn.click(Math.min(1,e.plan.speed/6)),e.rec=this.recorder(n),e.rolled=0,e.clicks=0,e.phase="roll",e.shooter.anim=null)}recorder(t){const e=t.recorder();return{hit:(n,s,r)=>{e.hit(n,s,r),this.s.clicks++<2&&cn.click(Math.min(1,r/4))},pocket:(n,s)=>{e.pocket(n,s),cn.pocket()},cushion:e.cushion}}settled(t){const e=this.s,n=e.game,s=e.shooter,r=e.waiter,a=n.settle();e.shots++;const o=a.potted.length>0;if(a.over)return this.over(t,a);a.assigned?s.say(`${a.assigned==="solids"?"Solids":"Stripes"} for me.`,"idle",2800):a.foul?(s.say(ei(gb),"warn",2400),Math.random()<.5&&setTimeout(()=>this.s&&r.say(ei(vb),"idle",2200),700)):o&&a.continues?Math.random()<.45&&s.say(ei(pb),"good",2200):Math.random()<.22&&s.say(ei(mb),"idle",2200),e.phase="pause",e.until=t+1.1+(a.foul?.6:0)}over(t,e){const n=this.s,s=n.game,r=this.agentOf(s.winner),a=n.players.find(l=>l!==r),o={eight:`Eight ball down. Good game, ${a.name}.`,"early-eight":`${a.name} dropped the eight early, so that one is mine. Good game.`,"foul-eight":`The eight went in with a foul, ${a.name}. Still a good game.`,"worn-out":`Called it after ${s.shots} shots, fewer balls left. Good game, ${a.name}.`}[s.over];r.say(ei(xb),"good",3600),a.say(ei(yb),"idle",3600),r.anim={kind:"celebrate",until:t+2.2},a.anim={kind:"slump",until:t+1.8},ts(`/api/chill/${n.id}/line`,{from:r.id,text:o}).catch(()=>{}),n.phase="over",n.until=t+5}stop(t,e){var s;const n=this.s;if(n){this.release(n.id);for(const r of n.players)r.playing=!1,r.chatting=!1,r.anim=null,(s=r.spot)!=null&&s.game&&(r.spot.taken=null,r.spot=null),!r.gone&&!r.job&&!r.meeting&&r.want==="lounge"?r.wanderAt=t+Qs(5,12):r.wanderAt=0;this.cueOuter.visible=!1,this.resting=Jc(),this.view=this.resting;for(const r of this.meshes)r.userData.sunk=null;this.s=null,this.next=t+(e?Qs(60,150):Qs(30,60))}}release(t){ts(`/api/chill/${t}`,void 0,"DELETE").catch(()=>{})}placeCue(t,e){const n=this.s.game.cue,s=Math.cos(e),r=Math.sin(e);this.cueOuter.position.set(n.x-s*(Le+t),Xe.felt+Le,n.z-r*(Le+t)),this.cueOuter.rotation.y=-e}draw(t,e){const n=Xe.felt;for(const s of this.view){const r=this.meshes[s.n],a=r.userData;if(s.in){a.sunk===null&&(a.sunk=t);const h=Math.min(1,(t-a.sunk)/.35),u=s.pocket;r.visible=h<1,r.position.set(s.x+(((u==null?void 0:u.x)??s.x)-s.x)*h,n+Le-h*.22,s.z+(((u==null?void 0:u.z)??s.z)-s.z)*h),r.scale.setScalar(1-h*.5);continue}a.sunk=null,r.visible=!0,r.scale.setScalar(1),r.position.set(s.x,n+Le,s.z);const o=s.x-a.x,l=s.z-a.z,c=Math.hypot(o,l);if(c>1e-5&&c<.5){const h=new R(l,0,-o).normalize();r.quaternion.premultiply(new ls().setFromAxisAngle(h,c/Le))}a.x=s.x,a.z=s.z}}}const Vl=6,wd=["#7c5cff","#0e9f9a","#d9488f","#c98a12","#3b82f6","#65a30d"],bb=/^#[0-9a-f]{6}$/i,tr=(i,t)=>String(i??"").replace(/\s+/g," ").trim().slice(0,t),Gl=(i,t)=>bb.test(i)?i:t,Sb=new Set(["working","idle","break","meeting","away"]);function wb(i){return Array.isArray(i)?i.filter(t=>t&&typeof t.link=="string"&&t.link).map(t=>({link:tr(t.link,80),handle:tr(t.handle,40)||"friend",agents:(Array.isArray(t.agents)?t.agents:[]).filter(e=>e&&typeof e.id=="string"&&e.id).map(e=>{var n,s,r;return{id:tr(e.id,40),name:tr(e.name,40)||"Visitor",role:tr(e.role,60),state:Sb.has(e.state)?e.state:"idle",look:{shirt:Gl((n=e.look)==null?void 0:n.shirt,"#8a8f9c"),hair:Gl((s=e.look)==null?void 0:s.hair,"#3b2f2a"),skin:Gl((r=e.look)==null?void 0:r.skin,"#c68e63")},job:e.job&&typeof e.job=="object"?{title:tr(e.job.title,120)}:null}})})):[]}class Eb extends Nh{constructor(t,e,n,s,r,a){const o=Object.hasOwn(rp,e.id)?e.id:"visitor";super({id:o,name:"",...e.look},s,r,{desk:{seat:s.door.clone(),seatY:0}}),this.key=`${t.link}:${e.id}`,this.id=this.key,this.root.traverse(u=>{u.userData.agentId=this.key,u.userData.visitor=this.key}),this.tint=n,this.chatAt=1/0,this.hangout=Math.random()<.5?"poolside":"coffee";const l=new Zt(n);this.fig.group.traverse(u=>{var d;!u.isMesh||!((d=u.material)!=null&&d.color)||(u.material=u.material.clone(),u.material.color.lerp(l,.16),u.material.emissive&&(u.material.emissive.copy(l),u.material.emissiveIntensity=.07))}),this.ring.material.color.set(n),this.ring.material.opacity=.6,this.ring.visible=!0,this.label.classList.add("visitor"),this.label.style.setProperty("--tint",n);const c=this.label.querySelector(".name");c.replaceChildren();const h=document.createElement("i");if(h.style.background=n,this.nameEl=document.createElement("span"),this.handleEl=document.createElement("span"),this.handleEl.className="handle",c.append(h,this.nameEl,this.handleEl),this.set(t,e),a){this.teleport(this.want);return}this.teleport("door"),this.say(`Hi from @${t.handle}`,"good",4e3)}set(t,e){this.office=t,this.info=e,this.name=e.name,this.nameEl.textContent!==e.name&&(this.nameEl.textContent=e.name,this.labelDirty=!0),this.handleEl.textContent!==` · @${t.handle}`&&(this.handleEl.textContent=` · @${t.handle}`,this.labelDirty=!0),this.leaving&&(this.leaving=!1,this.say("Forgot something","idle",2500)),this.want=this.place(e.state)}place(t){const e=t==="working"?["hotdesk","huddle",this.hangout]:t==="meeting"?["huddle","hotdesk"]:[this.hangout,this.hangout==="coffee"?"poolside":"coffee","huddle"];return e.find(n=>this.roomAt(n))||e[0]}roomAt(t){return this.world.stations[t].spots.some(e=>!e.game&&(!e.taken||e.taken===this.id))}resolve(t,e){if(t==="desk"){this.spot&&(this.spot.taken=null,this.spot=null);const n=this.world.door.clone().add(new R(-4.2+Math.random()*1.6,0,-1.4+Math.random()*.8));return{key:t,pos:n,face:Math.atan2(-n.x,-n.z),pose:"stand"}}return super.resolve(t,e)}leave(){this.leaving||(super.leave(),this.say(`Back to @${this.office.handle}`,"idle",3e3))}dispose(){this.fig.group.traverse(t=>{t.isMesh&&t.material.dispose()}),super.dispose()}}class Tb{constructor({world:t,labels:e,camera:n,canvas:s}){Object.assign(this,{world:t,labels:e,camera:n,canvas:s}),this.on=new Map,this.offices=[],this.tints=new Map,this.list=[],this.first=!0,this.sign=document.createElement("div"),this.sign.className="door-sign",this.sign.hidden=!0,e.appendChild(this.sign),this.card=document.createElement("div"),this.card.className="visitor-card",this.card.hidden=!0,e.appendChild(this.card),this.ray=new np,s.addEventListener("pointermove",r=>this.hover(r)),s.addEventListener("pointerleave",()=>{this.card.hidden=!0})}handle(t){if(t.t==="visitors")return this.receive(t.offices),!0;if(t.t==="hello"&&Array.isArray(t.visitors)&&this.receive(t.visitors,this.first),t.t==="hello"&&(this.first=!1),t.t==="links"&&Array.isArray(t.links)){const e=new Set(t.links.map(n=>n==null?void 0:n.id));this.receive(this.offices.filter(n=>e.has(n.link)))}return!1}tintOf(t){return this.tints.has(t)||this.tints.set(t,wd[this.tints.size%wd.length]),this.tints.get(t)}receive(t,e=!1){this.offices=wb(t);const n=new Map,s=this.offices.map(o=>o.agents.filter(l=>l.state!=="away").map(l=>[`${o.link}:${l.id}`,o,l]));for(const o of s)for(const[l,c,h]of o)n.set(l,[c,h]);const r=new Set([...this.on.values()].filter(o=>!o.leaving&&n.has(o.key)).map(o=>o.key).slice(0,Vl));for(let o=0;r.size<Vl&&s.some(l=>l.length>o);o++)for(const l of s)l[o]&&r.size<Vl&&r.add(l[o][0]);for(const o of this.on.values())r.has(o.key)||o.leave();for(const o of r){const[l,c]=n.get(o),h=this.on.get(o);h?h.set(l,c):this.on.set(o,new Eb(l,c,this.tintOf(l.link),this.world,this.labels,e))}const a=new Map;for(const[o,[l]]of n)r.has(o)||a.set(l.handle,(a.get(l.handle)||0)+1);this.sign.replaceChildren(...[...a].map(([o,l])=>{const c=document.createElement("div");return c.textContent=`+${l} from @${o}`,c})),this.sign.hidden=!a.size,this.list=[...this.on.values()]}update(t,e){for(const n of this.on.values())n.update(t,e),n.gone&&(n.dispose(),this.on.delete(n.key),this.list=[...this.on.values()])}placeSign(t,e){if(this.sign.hidden)return;const n=this.world.door.clone().setY(2.7).project(this.camera);if(n.z>1){this.sign.style.display="none";return}this.sign.style.display="",this.sign.style.transform=`translate(-50%, -100%) translate(${(n.x*.5+.5)*t}px, ${(-n.y*.5+.5)*e}px)`}hover(t){if(t.buttons||!this.list.length){this.card.hidden=!0;return}const e=this.canvas.getBoundingClientRect();this.ray.setFromCamera(new rt((t.clientX-e.left)/e.width*2-1,-((t.clientY-e.top)/e.height)*2+1),this.camera);const n=this.ray.intersectObjects(this.list.map(o=>o.root),!0)[0],s=n&&this.on.get(n.object.userData.visitor);if(!s){this.card.hidden=!0;return}(this.card.dataset.key!==s.key||this.card.dataset.stamp!==JSON.stringify(s.info))&&this.fillCard(s),this.card.hidden=!1;let r=t.clientX-e.left+14,a=t.clientY-e.top+14;r+this.card.offsetWidth>e.width-8&&(r-=this.card.offsetWidth+28),a+this.card.offsetHeight>e.height-8&&(a-=this.card.offsetHeight+28),this.card.style.transform=`translate(${r}px, ${a}px)`}fillCard(t){var a;const{info:e,office:n}=t;this.card.dataset.key=t.key,this.card.dataset.stamp=JSON.stringify(e),this.card.style.setProperty("--tint",t.tint);const s=(o,l)=>{const c=document.createElement("div");return c.className=o,c.textContent=l,c},r={working:"Working",idle:"Between jobs",break:"On a break",meeting:"In a meeting",away:"Heading home"}[e.state];this.card.replaceChildren(s("vc-who",`${e.name} · @${n.handle}`),s("vc-role",e.role||"Agent"),s("vc-job",((a=e.job)==null?void 0:a.title)||(e.state==="working"?"On a job":"No job right now")),s("vc-state",`${r} · visiting from @${n.handle}`))}}class Ab{constructor(t){this.scene=t,this.bits=[],this.geo=new gi(.14,.09)}burst(t,e){for(let n=0;n<70;n++){const s=new yt(this.geo,new dn({color:e[n%e.length],side:li,transparent:!0}));s.position.set(t.x,2.4,t.z);const r=Math.random()*Math.PI*2,a=1.5+Math.random()*3;s.userData={v:new R(Math.cos(r)*a,4+Math.random()*4,Math.sin(r)*a),spin:new R(Math.random()*10,Math.random()*10,Math.random()*10),life:2.2+Math.random()*.8},this.scene.add(s),this.bits.push(s)}}update(t){for(let e=this.bits.length-1;e>=0;e--){const n=this.bits[e],s=n.userData;s.life-=t,s.v.y-=9*t,s.v.multiplyScalar(1-t*1.2),n.position.addScaledVector(s.v,t),n.position.y<.02?(n.position.y=.02,s.v.set(0,0,0),n.rotation.set(-Math.PI/2,0,n.rotation.z)):(n.rotation.x+=s.spin.x*t,n.rotation.y+=s.spin.y*t,n.rotation.z+=s.spin.z*t),n.material.opacity=Math.min(1,s.life/.6),s.life<=0&&(this.scene.remove(n),n.material.dispose(),this.bits.splice(e,1))}}}function Oh(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let Ls=Oh();function fp(i){Ls=i}const pp=/[&<>"']/,Cb=new RegExp(pp.source,"g"),mp=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Rb=new RegExp(mp.source,"g"),Pb={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Ed=i=>Pb[i];function An(i,t){if(t){if(pp.test(i))return i.replace(Cb,Ed)}else if(mp.test(i))return i.replace(Rb,Ed);return i}const Lb=/(^|[^\[])\^/g;function ve(i,t){let e=typeof i=="string"?i:i.source;t=t||"";const n={replace:(s,r)=>{let a=typeof r=="string"?r:r.source;return a=a.replace(Lb,"$1"),e=e.replace(s,a),n},getRegex:()=>new RegExp(e,t)};return n}function Td(i){try{i=encodeURI(i).replace(/%25/g,"%")}catch{return null}return i}const ta={exec:()=>null};function Ad(i,t){const e=i.replace(/\|/g,(r,a,o)=>{let l=!1,c=a;for(;--c>=0&&o[c]==="\\";)l=!l;return l?"|":" |"}),n=e.split(/ \|/);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(/\\\|/g,"|");return n}function Br(i,t,e){const n=i.length;if(n===0)return"";let s=0;for(;s<n&&i.charAt(n-s-1)===t;)s++;return i.slice(0,n-s)}function Db(i,t){if(i.indexOf(t[1])===-1)return-1;let e=0;for(let n=0;n<i.length;n++)if(i[n]==="\\")n++;else if(i[n]===t[0])e++;else if(i[n]===t[1]&&(e--,e<0))return n;return-1}function Cd(i,t,e,n){const s=t.href,r=t.title?An(t.title):null,a=i[1].replace(/\\([\[\]])/g,"$1");if(i[0].charAt(0)!=="!"){n.state.inLink=!0;const o={type:"link",raw:e,href:s,title:r,text:a,tokens:n.inlineTokens(a)};return n.state.inLink=!1,o}return{type:"image",raw:e,href:s,title:r,text:An(a)}}function Ib(i,t){const e=i.match(/^(\s+)(?:```)/);if(e===null)return t;const n=e[1];return t.split(`
4302
4302
  `).map(s=>{const r=s.match(/^\s+/);if(r===null)return s;const[a]=r;return a.length>=n.length?s.slice(n.length):s}).join(`
4303
- `)}class go{constructor(t){_e(this,"options");_e(this,"rules");_e(this,"lexer");this.options=t||Ss}space(t){const e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){const e=this.rules.block.code.exec(t);if(e){const n=e[0].replace(/^(?: {1,4}| {0,3}\t)/gm,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?n:Lr(n,`
4304
- `)}}}fences(t){const e=this.rules.block.fences.exec(t);if(e){const n=e[0],s=r1(n,e[3]||"");return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(t){const e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(/#$/.test(n)){const s=Lr(n,"#");(this.options.pedantic||!s||/ $/.test(s))&&(n=s.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){const e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Lr(e[0],`
4305
- `)}}blockquote(t){const e=this.rules.block.blockquote.exec(t);if(e){let n=Lr(e[0],`
4303
+ `)}class To{constructor(t){_e(this,"options");_e(this,"rules");_e(this,"lexer");this.options=t||Ls}space(t){const e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){const e=this.rules.block.code.exec(t);if(e){const n=e[0].replace(/^(?: {1,4}| {0,3}\t)/gm,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?n:Br(n,`
4304
+ `)}}}fences(t){const e=this.rules.block.fences.exec(t);if(e){const n=e[0],s=Ib(n,e[3]||"");return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(t){const e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(/#$/.test(n)){const s=Br(n,"#");(this.options.pedantic||!s||/ $/.test(s))&&(n=s.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){const e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Br(e[0],`
4305
+ `)}}blockquote(t){const e=this.rules.block.blockquote.exec(t);if(e){let n=Br(e[0],`
4306
4306
  `).split(`
4307
4307
  `),s="",r="";const a=[];for(;n.length>0;){let o=!1;const l=[];let c;for(c=0;c<n.length;c++)if(/^ {0,3}>/.test(n[c]))l.push(n[c]),o=!0;else if(!o)l.push(n[c]);else break;n=n.slice(c);const h=l.join(`
4308
4308
  `),u=h.replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,`
@@ -4320,10 +4320,10 @@ ${u}`:u;const d=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.block
4320
4320
  `,1)[0];let E;if(d=T,this.options.pedantic?(d=d.replace(/^ {1,4}(?=( {4})*[^ ])/g," "),E=d):E=d.replace(/\t/g," "),x.test(d)||S.test(d)||L.test(d)||p.test(d)||y.test(d))break;if(E.search(/[^ ]/)>=g||!d.trim())h+=`
4321
4321
  `+E.slice(g);else{if(f||u.replace(/\t/g," ").search(/[^ ]/)>=4||x.test(u)||S.test(u)||y.test(u))break;h+=`
4322
4322
  `+d}!f&&!d.trim()&&(f=!0),c+=T+`
4323
- `,t=t.substring(T.length+1),u=E.slice(g)}}r.loose||(o?r.loose=!0:/\n[ \t]*\n[ \t]*$/.test(c)&&(o=!0));let _=null,m;this.options.gfm&&(_=/^\[[ xX]\] /.exec(h),_&&(m=_[0]!=="[ ] ",h=h.replace(/^\[[ xX]\] +/,""))),r.items.push({type:"list_item",raw:c,task:!!_,checked:m,loose:!1,text:h,tokens:[]}),r.raw+=c}r.items[r.items.length-1].raw=r.items[r.items.length-1].raw.trimEnd(),r.items[r.items.length-1].text=r.items[r.items.length-1].text.trimEnd(),r.raw=r.raw.trimEnd();for(let l=0;l<r.items.length;l++)if(this.lexer.state.top=!1,r.items[l].tokens=this.lexer.blockTokens(r.items[l].text,[]),!r.loose){const c=r.items[l].tokens.filter(u=>u.type==="space"),h=c.length>0&&c.some(u=>/\n.*\n/.test(u.raw));r.loose=h}if(r.loose)for(let l=0;l<r.items.length;l++)r.items[l].loose=!0;return r}}html(t){const e=this.rules.block.html.exec(t);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(t){const e=this.rules.block.def.exec(t);if(e){const n=e[1].toLowerCase().replace(/\s+/g," "),s=e[2]?e[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:e[0],href:s,title:r}}}table(t){const e=this.rules.block.table.exec(t);if(!e||!/[:|]/.test(e[2]))return;const n=ld(e[1]),s=e[2].replace(/^\||\| *$/g,"").split("|"),r=e[3]&&e[3].trim()?e[3].replace(/\n[ \t]*$/,"").split(`
4324
- `):[],a={type:"table",raw:e[0],header:[],align:[],rows:[]};if(n.length===s.length){for(const o of s)/^ *-+: *$/.test(o)?a.align.push("right"):/^ *:-+: *$/.test(o)?a.align.push("center"):/^ *:-+ *$/.test(o)?a.align.push("left"):a.align.push(null);for(let o=0;o<n.length;o++)a.header.push({text:n[o],tokens:this.lexer.inline(n[o]),header:!0,align:a.align[o]});for(const o of r)a.rows.push(ld(o,a.header.length).map((l,c)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:a.align[c]})));return a}}lheading(t){const e=this.rules.block.lheading.exec(t);if(e)return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(t){const e=this.rules.block.paragraph.exec(t);if(e){const n=e[1].charAt(e[1].length-1)===`
4325
- `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){const e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){const e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:Sn(e[1])}}tag(t){const e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&/^<a /i.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){const e=this.rules.inline.link.exec(t);if(e){const n=e[2].trim();if(!this.options.pedantic&&/^</.test(n)){if(!/>$/.test(n))return;const a=Lr(n.slice(0,-1),"\\");if((n.length-a.length)%2===0)return}else{const a=s1(e[2],"()");if(a>-1){const l=(e[0].indexOf("!")===0?5:4)+e[1].length+a;e[2]=e[2].substring(0,a),e[0]=e[0].substring(0,l).trim(),e[3]=""}}let s=e[2],r="";if(this.options.pedantic){const a=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(s);a&&(s=a[1],r=a[3])}else r=e[3]?e[3].slice(1,-1):"";return s=s.trim(),/^</.test(s)&&(this.options.pedantic&&!/>$/.test(n)?s=s.slice(1):s=s.slice(1,-1)),cd(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){const s=(n[2]||n[1]).replace(/\s+/g," "),r=e[s.toLowerCase()];if(!r){const a=n[0].charAt(0);return{type:"text",raw:a,text:a}}return cd(n,r,n[0],this.lexer)}}emStrong(t,e,n=""){let s=this.rules.inline.emStrongLDelim.exec(t);if(!s||s[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const a=[...s[0]].length-1;let o,l,c=a,h=0;const u=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,e=e.slice(-1*t.length+a);(s=u.exec(e))!=null;){if(o=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!o)continue;if(l=[...o].length,s[3]||s[4]){c+=l;continue}else if((s[5]||s[6])&&a%3&&!((a+l)%3)){h+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+h);const d=[...s[0]][0].length,f=t.slice(0,a+s.index+d+l);if(Math.min(a,l)%2){const _=f.slice(1,-1);return{type:"em",raw:f,text:_,tokens:this.lexer.inlineTokens(_)}}const g=f.slice(2,-2);return{type:"strong",raw:f,text:g,tokens:this.lexer.inlineTokens(g)}}}}codespan(t){const e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(/\n/g," ");const s=/[^ ]/.test(n),r=/^ /.test(n)&&/ $/.test(n);return s&&r&&(n=n.substring(1,n.length-1)),n=Sn(n,!0),{type:"codespan",raw:e[0],text:n}}}br(t){const e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){const e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){const e=this.rules.inline.autolink.exec(t);if(e){let n,s;return e[2]==="@"?(n=Sn(e[1]),s="mailto:"+n):(n=Sn(e[1]),s=n),{type:"link",raw:e[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}url(t){var n;let e;if(e=this.rules.inline.url.exec(t)){let s,r;if(e[2]==="@")s=Sn(e[0]),r="mailto:"+s;else{let a;do a=e[0],e[0]=((n=this.rules.inline._backpedal.exec(e[0]))==null?void 0:n[0])??"";while(a!==e[0]);s=Sn(e[0]),e[1]==="www."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:s,href:r,tokens:[{type:"text",raw:s,text:s}]}}}inlineText(t){const e=this.rules.inline.text.exec(t);if(e){let n;return this.lexer.state.inRawBlock?n=e[0]:n=Sn(e[0]),{type:"text",raw:e[0],text:n}}}}const a1=/^(?:[ \t]*(?:\n|$))+/,o1=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,l1=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,ea=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,c1=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Xf=/(?:[*+-]|\d{1,9}[.)])/,jf=ve(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,Xf).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),bh=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,h1=/^[^\n]+/,Sh=/(?!\s*\])(?:\\.|[^\[\]\\])+/,u1=ve(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Sh).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),d1=ve(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Xf).getRegex(),Po="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",wh=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,f1=ve("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",wh).replace("tag",Po).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),qf=ve(bh).replace("hr",ea).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Po).getRegex(),p1=ve(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",qf).getRegex(),Eh={blockquote:p1,code:o1,def:u1,fences:l1,heading:c1,hr:ea,html:f1,lheading:jf,list:d1,newline:a1,paragraph:qf,table:Wr,text:h1},hd=ve("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ea).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Po).getRegex(),m1={...Eh,table:hd,paragraph:ve(bh).replace("hr",ea).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",hd).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Po).getRegex()},g1={...Eh,html:ve(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",wh).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Wr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ve(bh).replace("hr",ea).replace("heading",` *#{1,6} *[^
4326
- ]`).replace("lheading",jf).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Yf=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,v1=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Kf=/^( {2,}|\\)\n(?!\s*$)/,_1=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,na="\\p{P}\\p{S}",x1=ve(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,na).getRegex(),y1=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,M1=ve(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,na).getRegex(),b1=ve("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,na).getRegex(),S1=ve("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,na).getRegex(),w1=ve(/\\([punct])/,"gu").replace(/punct/g,na).getRegex(),E1=ve(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),T1=ve(wh).replace("(?:-->|$)","-->").getRegex(),A1=ve("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",T1).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),vo=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,C1=ve(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",vo).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Zf=ve(/^!?\[(label)\]\[(ref)\]/).replace("label",vo).replace("ref",Sh).getRegex(),Jf=ve(/^!?\[(ref)\](?:\[\])?/).replace("ref",Sh).getRegex(),R1=ve("reflink|nolink(?!\\()","g").replace("reflink",Zf).replace("nolink",Jf).getRegex(),Th={_backpedal:Wr,anyPunctuation:w1,autolink:E1,blockSkip:y1,br:Kf,code:v1,del:Wr,emStrongLDelim:M1,emStrongRDelimAst:b1,emStrongRDelimUnd:S1,escape:Yf,link:C1,nolink:Jf,punctuation:x1,reflink:Zf,reflinkSearch:R1,tag:A1,text:_1,url:Wr},P1={...Th,link:ve(/^!?\[(label)\]\((.*?)\)/).replace("label",vo).getRegex(),reflink:ve(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",vo).getRegex()},zc={...Th,escape:ve(Yf).replace("])","~|])").getRegex(),url:ve(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},L1={...zc,br:ve(Kf).replace("{2,}","*").getRegex(),text:ve(zc.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},za={normal:Eh,gfm:m1,pedantic:g1},Dr={normal:Th,gfm:zc,breaks:L1,pedantic:P1};class In{constructor(t){_e(this,"tokens");_e(this,"options");_e(this,"state");_e(this,"tokenizer");_e(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Ss,this.options.tokenizer=this.options.tokenizer||new go,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const e={block:za.normal,inline:Dr.normal};this.options.pedantic?(e.block=za.pedantic,e.inline=Dr.pedantic):this.options.gfm&&(e.block=za.gfm,this.options.breaks?e.inline=Dr.breaks:e.inline=Dr.gfm),this.tokenizer.rules=e}static get rules(){return{block:za,inline:Dr}}static lex(t,e){return new In(e).lex(t)}static lexInline(t,e){return new In(e).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
4323
+ `,t=t.substring(T.length+1),u=E.slice(g)}}r.loose||(o?r.loose=!0:/\n[ \t]*\n[ \t]*$/.test(c)&&(o=!0));let _=null,m;this.options.gfm&&(_=/^\[[ xX]\] /.exec(h),_&&(m=_[0]!=="[ ] ",h=h.replace(/^\[[ xX]\] +/,""))),r.items.push({type:"list_item",raw:c,task:!!_,checked:m,loose:!1,text:h,tokens:[]}),r.raw+=c}r.items[r.items.length-1].raw=r.items[r.items.length-1].raw.trimEnd(),r.items[r.items.length-1].text=r.items[r.items.length-1].text.trimEnd(),r.raw=r.raw.trimEnd();for(let l=0;l<r.items.length;l++)if(this.lexer.state.top=!1,r.items[l].tokens=this.lexer.blockTokens(r.items[l].text,[]),!r.loose){const c=r.items[l].tokens.filter(u=>u.type==="space"),h=c.length>0&&c.some(u=>/\n.*\n/.test(u.raw));r.loose=h}if(r.loose)for(let l=0;l<r.items.length;l++)r.items[l].loose=!0;return r}}html(t){const e=this.rules.block.html.exec(t);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(t){const e=this.rules.block.def.exec(t);if(e){const n=e[1].toLowerCase().replace(/\s+/g," "),s=e[2]?e[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:e[0],href:s,title:r}}}table(t){const e=this.rules.block.table.exec(t);if(!e||!/[:|]/.test(e[2]))return;const n=Ad(e[1]),s=e[2].replace(/^\||\| *$/g,"").split("|"),r=e[3]&&e[3].trim()?e[3].replace(/\n[ \t]*$/,"").split(`
4324
+ `):[],a={type:"table",raw:e[0],header:[],align:[],rows:[]};if(n.length===s.length){for(const o of s)/^ *-+: *$/.test(o)?a.align.push("right"):/^ *:-+: *$/.test(o)?a.align.push("center"):/^ *:-+ *$/.test(o)?a.align.push("left"):a.align.push(null);for(let o=0;o<n.length;o++)a.header.push({text:n[o],tokens:this.lexer.inline(n[o]),header:!0,align:a.align[o]});for(const o of r)a.rows.push(Ad(o,a.header.length).map((l,c)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:a.align[c]})));return a}}lheading(t){const e=this.rules.block.lheading.exec(t);if(e)return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(t){const e=this.rules.block.paragraph.exec(t);if(e){const n=e[1].charAt(e[1].length-1)===`
4325
+ `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){const e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){const e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:An(e[1])}}tag(t){const e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&/^<a /i.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){const e=this.rules.inline.link.exec(t);if(e){const n=e[2].trim();if(!this.options.pedantic&&/^</.test(n)){if(!/>$/.test(n))return;const a=Br(n.slice(0,-1),"\\");if((n.length-a.length)%2===0)return}else{const a=Db(e[2],"()");if(a>-1){const l=(e[0].indexOf("!")===0?5:4)+e[1].length+a;e[2]=e[2].substring(0,a),e[0]=e[0].substring(0,l).trim(),e[3]=""}}let s=e[2],r="";if(this.options.pedantic){const a=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(s);a&&(s=a[1],r=a[3])}else r=e[3]?e[3].slice(1,-1):"";return s=s.trim(),/^</.test(s)&&(this.options.pedantic&&!/>$/.test(n)?s=s.slice(1):s=s.slice(1,-1)),Cd(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){const s=(n[2]||n[1]).replace(/\s+/g," "),r=e[s.toLowerCase()];if(!r){const a=n[0].charAt(0);return{type:"text",raw:a,text:a}}return Cd(n,r,n[0],this.lexer)}}emStrong(t,e,n=""){let s=this.rules.inline.emStrongLDelim.exec(t);if(!s||s[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const a=[...s[0]].length-1;let o,l,c=a,h=0;const u=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,e=e.slice(-1*t.length+a);(s=u.exec(e))!=null;){if(o=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!o)continue;if(l=[...o].length,s[3]||s[4]){c+=l;continue}else if((s[5]||s[6])&&a%3&&!((a+l)%3)){h+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+h);const d=[...s[0]][0].length,f=t.slice(0,a+s.index+d+l);if(Math.min(a,l)%2){const _=f.slice(1,-1);return{type:"em",raw:f,text:_,tokens:this.lexer.inlineTokens(_)}}const g=f.slice(2,-2);return{type:"strong",raw:f,text:g,tokens:this.lexer.inlineTokens(g)}}}}codespan(t){const e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(/\n/g," ");const s=/[^ ]/.test(n),r=/^ /.test(n)&&/ $/.test(n);return s&&r&&(n=n.substring(1,n.length-1)),n=An(n,!0),{type:"codespan",raw:e[0],text:n}}}br(t){const e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){const e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){const e=this.rules.inline.autolink.exec(t);if(e){let n,s;return e[2]==="@"?(n=An(e[1]),s="mailto:"+n):(n=An(e[1]),s=n),{type:"link",raw:e[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}url(t){var n;let e;if(e=this.rules.inline.url.exec(t)){let s,r;if(e[2]==="@")s=An(e[0]),r="mailto:"+s;else{let a;do a=e[0],e[0]=((n=this.rules.inline._backpedal.exec(e[0]))==null?void 0:n[0])??"";while(a!==e[0]);s=An(e[0]),e[1]==="www."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:s,href:r,tokens:[{type:"text",raw:s,text:s}]}}}inlineText(t){const e=this.rules.inline.text.exec(t);if(e){let n;return this.lexer.state.inRawBlock?n=e[0]:n=An(e[0]),{type:"text",raw:e[0],text:n}}}}const kb=/^(?:[ \t]*(?:\n|$))+/,Nb=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ub=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,ha=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ob=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,gp=/(?:[*+-]|\d{1,9}[.)])/,vp=ve(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,gp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),Fh=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Fb=/^[^\n]+/,zh=/(?!\s*\])(?:\\.|[^\[\]\\])+/,zb=ve(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",zh).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Bb=ve(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,gp).getRegex(),Bo="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Bh=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Hb=ve("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",Bh).replace("tag",Bo).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),_p=ve(Fh).replace("hr",ha).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Bo).getRegex(),Vb=ve(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",_p).getRegex(),Hh={blockquote:Vb,code:Nb,def:zb,fences:Ub,heading:Ob,hr:ha,html:Hb,lheading:vp,list:Bb,newline:kb,paragraph:_p,table:ta,text:Fb},Rd=ve("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ha).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Bo).getRegex(),Gb={...Hh,table:Rd,paragraph:ve(Fh).replace("hr",ha).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Rd).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Bo).getRegex()},$b={...Hh,html:ve(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Bh).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:ta,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ve(Fh).replace("hr",ha).replace("heading",` *#{1,6} *[^
4326
+ ]`).replace("lheading",vp).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},xp=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Wb=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,yp=/^( {2,}|\\)\n(?!\s*$)/,Xb=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ua="\\p{P}\\p{S}",jb=ve(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,ua).getRegex(),qb=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,Yb=ve(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,ua).getRegex(),Kb=ve("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,ua).getRegex(),Zb=ve("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,ua).getRegex(),Jb=ve(/\\([punct])/,"gu").replace(/punct/g,ua).getRegex(),Qb=ve(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),t1=ve(Bh).replace("(?:-->|$)","-->").getRegex(),e1=ve("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",t1).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ao=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,n1=ve(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",Ao).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Mp=ve(/^!?\[(label)\]\[(ref)\]/).replace("label",Ao).replace("ref",zh).getRegex(),bp=ve(/^!?\[(ref)\](?:\[\])?/).replace("ref",zh).getRegex(),i1=ve("reflink|nolink(?!\\()","g").replace("reflink",Mp).replace("nolink",bp).getRegex(),Vh={_backpedal:ta,anyPunctuation:Jb,autolink:Qb,blockSkip:qb,br:yp,code:Wb,del:ta,emStrongLDelim:Yb,emStrongRDelimAst:Kb,emStrongRDelimUnd:Zb,escape:xp,link:n1,nolink:bp,punctuation:jb,reflink:Mp,reflinkSearch:i1,tag:e1,text:Xb,url:ta},s1={...Vh,link:ve(/^!?\[(label)\]\((.*?)\)/).replace("label",Ao).getRegex(),reflink:ve(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Ao).getRegex()},Qc={...Vh,escape:ve(xp).replace("])","~|])").getRegex(),url:ve(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},r1={...Qc,br:ve(yp).replace("{2,}","*").getRegex(),text:ve(Qc.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},qa={normal:Hh,gfm:Gb,pedantic:$b},Hr={normal:Vh,gfm:Qc,breaks:r1,pedantic:s1};class Un{constructor(t){_e(this,"tokens");_e(this,"options");_e(this,"state");_e(this,"tokenizer");_e(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Ls,this.options.tokenizer=this.options.tokenizer||new To,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const e={block:qa.normal,inline:Hr.normal};this.options.pedantic?(e.block=qa.pedantic,e.inline=Hr.pedantic):this.options.gfm&&(e.block=qa.gfm,this.options.breaks?e.inline=Hr.breaks:e.inline=Hr.gfm),this.tokenizer.rules=e}static get rules(){return{block:qa,inline:Hr}}static lex(t,e){return new Un(e).lex(t)}static lexInline(t,e){return new Un(e).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
4327
4327
  `),this.blockTokens(t,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const n=this.inlineQueue[e];this.inlineTokens(n.src,n.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,e=[],n=!1){this.options.pedantic&&(t=t.replace(/\t/g," ").replace(/^ +$/gm,""));let s,r,a;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(o=>(s=o.call({lexer:this},t,e))?(t=t.substring(s.raw.length),e.push(s),!0):!1))){if(s=this.tokenizer.space(t)){t=t.substring(s.raw.length),s.raw.length===1&&e.length>0?e[e.length-1].raw+=`
4328
4328
  `:e.push(s);continue}if(s=this.tokenizer.code(t)){t=t.substring(s.raw.length),r=e[e.length-1],r&&(r.type==="paragraph"||r.type==="text")?(r.raw+=`
4329
4329
  `+s.raw,r.text+=`
@@ -4333,9 +4333,9 @@ ${u}`:u;const d=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.block
4333
4333
  `+s.raw,r.text+=`
4334
4334
  `+s.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):e.push(s),n=a.length!==t.length,t=t.substring(s.raw.length);continue}if(s=this.tokenizer.text(t)){t=t.substring(s.raw.length),r=e[e.length-1],r&&r.type==="text"?(r.raw+=`
4335
4335
  `+s.raw,r.text+=`
4336
- `+s.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):e.push(s);continue}if(t){const o="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(o);break}else throw new Error(o)}}return this.state.top=!0,e}inline(t,e=[]){return this.inlineQueue.push({src:t,tokens:e}),e}inlineTokens(t,e=[]){let n,s,r,a=t,o,l,c;if(this.tokens.links){const h=Object.keys(this.tokens.links);if(h.length>0)for(;(o=this.tokenizer.rules.inline.reflinkSearch.exec(a))!=null;)h.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(a=a.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(o=this.tokenizer.rules.inline.blockSkip.exec(a))!=null;)a=a.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(o=this.tokenizer.rules.inline.anyPunctuation.exec(a))!=null;)a=a.slice(0,o.index)+"++"+a.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(h=>(n=h.call({lexer:this},t,e))?(t=t.substring(n.raw.length),e.push(n),!0):!1))){if(n=this.tokenizer.escape(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.tag(t)){t=t.substring(n.raw.length),s=e[e.length-1],s&&n.type==="text"&&s.type==="text"?(s.raw+=n.raw,s.text+=n.text):e.push(n);continue}if(n=this.tokenizer.link(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(n.raw.length),s=e[e.length-1],s&&n.type==="text"&&s.type==="text"?(s.raw+=n.raw,s.text+=n.text):e.push(n);continue}if(n=this.tokenizer.emStrong(t,a,c)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.codespan(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.br(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.del(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.autolink(t)){t=t.substring(n.raw.length),e.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(t))){t=t.substring(n.raw.length),e.push(n);continue}if(r=t,this.options.extensions&&this.options.extensions.startInline){let h=1/0;const u=t.slice(1);let d;this.options.extensions.startInline.forEach(f=>{d=f.call({lexer:this},u),typeof d=="number"&&d>=0&&(h=Math.min(h,d))}),h<1/0&&h>=0&&(r=t.substring(0,h+1))}if(n=this.tokenizer.inlineText(r)){t=t.substring(n.raw.length),n.raw.slice(-1)!=="_"&&(c=n.raw.slice(-1)),l=!0,s=e[e.length-1],s&&s.type==="text"?(s.raw+=n.raw,s.text+=n.text):e.push(n);continue}if(t){const h="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(h);break}else throw new Error(h)}}return e}}class _o{constructor(t){_e(this,"options");_e(this,"parser");this.options=t||Ss}space(t){return""}code({text:t,lang:e,escaped:n}){var a;const s=(a=(e||"").match(/^\S*/))==null?void 0:a[0],r=t.replace(/\n$/,"")+`
4337
- `;return s?'<pre><code class="language-'+Sn(s)+'">'+(n?r:Sn(r,!0))+`</code></pre>
4338
- `:"<pre><code>"+(n?r:Sn(r,!0))+`</code></pre>
4336
+ `+s.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):e.push(s);continue}if(t){const o="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(o);break}else throw new Error(o)}}return this.state.top=!0,e}inline(t,e=[]){return this.inlineQueue.push({src:t,tokens:e}),e}inlineTokens(t,e=[]){let n,s,r,a=t,o,l,c;if(this.tokens.links){const h=Object.keys(this.tokens.links);if(h.length>0)for(;(o=this.tokenizer.rules.inline.reflinkSearch.exec(a))!=null;)h.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(a=a.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(o=this.tokenizer.rules.inline.blockSkip.exec(a))!=null;)a=a.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(o=this.tokenizer.rules.inline.anyPunctuation.exec(a))!=null;)a=a.slice(0,o.index)+"++"+a.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(h=>(n=h.call({lexer:this},t,e))?(t=t.substring(n.raw.length),e.push(n),!0):!1))){if(n=this.tokenizer.escape(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.tag(t)){t=t.substring(n.raw.length),s=e[e.length-1],s&&n.type==="text"&&s.type==="text"?(s.raw+=n.raw,s.text+=n.text):e.push(n);continue}if(n=this.tokenizer.link(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(n.raw.length),s=e[e.length-1],s&&n.type==="text"&&s.type==="text"?(s.raw+=n.raw,s.text+=n.text):e.push(n);continue}if(n=this.tokenizer.emStrong(t,a,c)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.codespan(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.br(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.del(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.autolink(t)){t=t.substring(n.raw.length),e.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(t))){t=t.substring(n.raw.length),e.push(n);continue}if(r=t,this.options.extensions&&this.options.extensions.startInline){let h=1/0;const u=t.slice(1);let d;this.options.extensions.startInline.forEach(f=>{d=f.call({lexer:this},u),typeof d=="number"&&d>=0&&(h=Math.min(h,d))}),h<1/0&&h>=0&&(r=t.substring(0,h+1))}if(n=this.tokenizer.inlineText(r)){t=t.substring(n.raw.length),n.raw.slice(-1)!=="_"&&(c=n.raw.slice(-1)),l=!0,s=e[e.length-1],s&&s.type==="text"?(s.raw+=n.raw,s.text+=n.text):e.push(n);continue}if(t){const h="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(h);break}else throw new Error(h)}}return e}}class Co{constructor(t){_e(this,"options");_e(this,"parser");this.options=t||Ls}space(t){return""}code({text:t,lang:e,escaped:n}){var a;const s=(a=(e||"").match(/^\S*/))==null?void 0:a[0],r=t.replace(/\n$/,"")+`
4337
+ `;return s?'<pre><code class="language-'+An(s)+'">'+(n?r:An(r,!0))+`</code></pre>
4338
+ `:"<pre><code>"+(n?r:An(r,!0))+`</code></pre>
4339
4339
  `}blockquote({tokens:t}){return`<blockquote>
4340
4340
  ${this.parser.parse(t)}</blockquote>
4341
4341
  `}html({text:t}){return t}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
@@ -4351,19 +4351,19 @@ ${this.parser.parse(t)}</blockquote>
4351
4351
  `}tablerow({text:t}){return`<tr>
4352
4352
  ${t}</tr>
4353
4353
  `}tablecell(t){const e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
4354
- `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${t}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){const s=this.parser.parseInline(n),r=od(t);if(r===null)return s;t=r;let a='<a href="'+t+'"';return e&&(a+=' title="'+e+'"'),a+=">"+s+"</a>",a}image({href:t,title:e,text:n}){const s=od(t);if(s===null)return n;t=s;let r=`<img src="${t}" alt="${n}"`;return e&&(r+=` title="${e}"`),r+=">",r}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):t.text}}class Ah{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}}class kn{constructor(t){_e(this,"options");_e(this,"renderer");_e(this,"textRenderer");this.options=t||Ss,this.options.renderer=this.options.renderer||new _o,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Ah}static parse(t,e){return new kn(e).parse(t)}static parseInline(t,e){return new kn(e).parseInline(t)}parse(t,e=!0){let n="";for(let s=0;s<t.length;s++){const r=t[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const o=r,l=this.options.extensions.renderers[o.type].call({parser:this},o);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(o.type)){n+=l||"";continue}}const a=r;switch(a.type){case"space":{n+=this.renderer.space(a);continue}case"hr":{n+=this.renderer.hr(a);continue}case"heading":{n+=this.renderer.heading(a);continue}case"code":{n+=this.renderer.code(a);continue}case"table":{n+=this.renderer.table(a);continue}case"blockquote":{n+=this.renderer.blockquote(a);continue}case"list":{n+=this.renderer.list(a);continue}case"html":{n+=this.renderer.html(a);continue}case"paragraph":{n+=this.renderer.paragraph(a);continue}case"text":{let o=a,l=this.renderer.text(o);for(;s+1<t.length&&t[s+1].type==="text";)o=t[++s],l+=`
4355
- `+this.renderer.text(o);e?n+=this.renderer.paragraph({type:"paragraph",raw:l,text:l,tokens:[{type:"text",raw:l,text:l}]}):n+=l;continue}default:{const o='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(t,e){e=e||this.renderer;let n="";for(let s=0;s<t.length;s++){const r=t[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const o=this.options.extensions.renderers[r.type].call({parser:this},r);if(o!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=o||"";continue}}const a=r;switch(a.type){case"escape":{n+=e.text(a);break}case"html":{n+=e.html(a);break}case"link":{n+=e.link(a);break}case"image":{n+=e.image(a);break}case"strong":{n+=e.strong(a);break}case"em":{n+=e.em(a);break}case"codespan":{n+=e.codespan(a);break}case"br":{n+=e.br(a);break}case"del":{n+=e.del(a);break}case"text":{n+=e.text(a);break}default:{const o='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}}class Xr{constructor(t){_e(this,"options");_e(this,"block");this.options=t||Ss}preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}provideLexer(){return this.block?In.lex:In.lexInline}provideParser(){return this.block?kn.parse:kn.parseInline}}_e(Xr,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));class Qf{constructor(...t){_e(this,"defaults",Mh());_e(this,"options",this.setOptions);_e(this,"parse",this.parseMarkdown(!0));_e(this,"parseInline",this.parseMarkdown(!1));_e(this,"Parser",kn);_e(this,"Renderer",_o);_e(this,"TextRenderer",Ah);_e(this,"Lexer",In);_e(this,"Tokenizer",go);_e(this,"Hooks",Xr);this.use(...t)}walkTokens(t,e){var s,r;let n=[];for(const a of t)switch(n=n.concat(e.call(this,a)),a.type){case"table":{const o=a;for(const l of o.header)n=n.concat(this.walkTokens(l.tokens,e));for(const l of o.rows)for(const c of l)n=n.concat(this.walkTokens(c.tokens,e));break}case"list":{const o=a;n=n.concat(this.walkTokens(o.items,e));break}default:{const o=a;(r=(s=this.defaults.extensions)==null?void 0:s.childTokens)!=null&&r[o.type]?this.defaults.extensions.childTokens[o.type].forEach(l=>{const c=o[l].flat(1/0);n=n.concat(this.walkTokens(c,e))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,e)))}}return n}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{const s={...n};if(s.async=this.defaults.async||s.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){const a=e.renderers[r.name];a?e.renderers[r.name]=function(...o){let l=r.renderer.apply(this,o);return l===!1&&(l=a.apply(this,o)),l}:e.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const a=e[r.level];a?a.unshift(r.tokenizer):e[r.level]=[r.tokenizer],r.start&&(r.level==="block"?e.startBlock?e.startBlock.push(r.start):e.startBlock=[r.start]:r.level==="inline"&&(e.startInline?e.startInline.push(r.start):e.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(e.childTokens[r.name]=r.childTokens)}),s.extensions=e),n.renderer){const r=this.defaults.renderer||new _o(this.defaults);for(const a in n.renderer){if(!(a in r))throw new Error(`renderer '${a}' does not exist`);if(["options","parser"].includes(a))continue;const o=a,l=n.renderer[o],c=r[o];r[o]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u||""}}s.renderer=r}if(n.tokenizer){const r=this.defaults.tokenizer||new go(this.defaults);for(const a in n.tokenizer){if(!(a in r))throw new Error(`tokenizer '${a}' does not exist`);if(["options","rules","lexer"].includes(a))continue;const o=a,l=n.tokenizer[o],c=r[o];r[o]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u}}s.tokenizer=r}if(n.hooks){const r=this.defaults.hooks||new Xr;for(const a in n.hooks){if(!(a in r))throw new Error(`hook '${a}' does not exist`);if(["options","block"].includes(a))continue;const o=a,l=n.hooks[o],c=r[o];Xr.passThroughHooks.has(a)?r[o]=h=>{if(this.defaults.async)return Promise.resolve(l.call(r,h)).then(d=>c.call(r,d));const u=l.call(r,h);return c.call(r,u)}:r[o]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u}}s.hooks=r}if(n.walkTokens){const r=this.defaults.walkTokens,a=n.walkTokens;s.walkTokens=function(o){let l=[];return l.push(a.call(this,o)),r&&(l=l.concat(r.call(this,o))),l}}this.defaults={...this.defaults,...s}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return In.lex(t,e??this.defaults)}parser(t,e){return kn.parse(t,e??this.defaults)}parseMarkdown(t){return(n,s)=>{const r={...s},a={...this.defaults,...r},o=this.onError(!!a.silent,!!a.async);if(this.defaults.async===!0&&r.async===!1)return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof n>"u"||n===null)return o(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));a.hooks&&(a.hooks.options=a,a.hooks.block=t);const l=a.hooks?a.hooks.provideLexer():t?In.lex:In.lexInline,c=a.hooks?a.hooks.provideParser():t?kn.parse:kn.parseInline;if(a.async)return Promise.resolve(a.hooks?a.hooks.preprocess(n):n).then(h=>l(h,a)).then(h=>a.hooks?a.hooks.processAllTokens(h):h).then(h=>a.walkTokens?Promise.all(this.walkTokens(h,a.walkTokens)).then(()=>h):h).then(h=>c(h,a)).then(h=>a.hooks?a.hooks.postprocess(h):h).catch(o);try{a.hooks&&(n=a.hooks.preprocess(n));let h=l(n,a);a.hooks&&(h=a.hooks.processAllTokens(h)),a.walkTokens&&this.walkTokens(h,a.walkTokens);let u=c(h,a);return a.hooks&&(u=a.hooks.postprocess(u)),u}catch(h){return o(h)}}}onError(t,e){return n=>{if(n.message+=`
4356
- Please report this to https://github.com/markedjs/marked.`,t){const s="<p>An error occurred:</p><pre>"+Sn(n.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(n);throw n}}}const Ms=new Qf;function ge(i,t){return Ms.parse(i,t)}ge.options=ge.setOptions=function(i){return Ms.setOptions(i),ge.defaults=Ms.defaults,Gf(ge.defaults),ge};ge.getDefaults=Mh;ge.defaults=Ss;ge.use=function(...i){return Ms.use(...i),ge.defaults=Ms.defaults,Gf(ge.defaults),ge};ge.walkTokens=function(i,t){return Ms.walkTokens(i,t)};ge.parseInline=Ms.parseInline;ge.Parser=kn;ge.parser=kn.parse;ge.Renderer=_o;ge.TextRenderer=Ah;ge.Lexer=In;ge.lexer=In.lex;ge.Tokenizer=go;ge.Hooks=Xr;ge.parse=ge;ge.options;ge.setOptions;ge.use;ge.walkTokens;ge.parseInline;kn.parse;In.lex;function D1(i){let t=String(i??"");if(t=t.replace(/```[\s\S]*?```/g," (code) ").replace(/~~~[\s\S]*?~~~/g," (code) ").replace(/`([^`]*)`/g,(n,s)=>/[\/\\]/.test(s)?" that file ":/^\W*$/.test(s)?" ":` ${s} `).replace(/!\[[^\]]*\]\([^)]*\)/g," ").replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/https?:\/\/\S+/g," a link ").replace(/^\s{0,3}#{1,6}\s*/gm,"").replace(/^\s*>\s?/gm,"").replace(/^\s*[-*+]\s+/gm,", ").replace(/^\s*\d+\.\s+/gm,", ").replace(/(\*\*|__|\*|_|~~)/g,"").replace(/^\s*\|.*\|\s*$/gm," ").replace(/^\s*[-=:|]{3,}\s*$/gm," ").replace(/(?:\.{0,2}\/)?(?:[\w.-]+\/){1,}[\w.-]+(?::\d+)?/g," that file ").replace(/\b[\w-]+\.(?:js|ts|tsx|jsx|css|html|json|md|py|go|rs|sh|yml|yaml)\b(?::\d+)?/gi," that file ").replace(/[#*`_~>|]/g," ").replace(/\s*,\s*,+/g,", ").replace(/[ \t]+/g," ").replace(/\n{2,}/g,". ").replace(/\n/g," ").replace(/\s+([.,!?;:])/g,"$1").replace(/([:;,])[.,]+/g,"$1").replace(/([.!?])\s*,\s*/g,"$1 ").replace(/\.{2,}/g,".").replace(/\s{2,}/g," ").replace(/^[\s.,;:!?]+/,"").trim(),!/[a-z0-9]/i.test(t))return"";const e=460;if(t.length>e){const n=t.slice(0,e),s=Math.max(n.lastIndexOf(". "),n.lastIndexOf("! "),n.lastIndexOf("? "));t=s>160?n.slice(0,s+1):n.replace(/\s+\S*$/,"")+"…"}return t}const ud=(i,t)=>{try{if(t===void 0)return localStorage.getItem(i);localStorage.setItem(i,t)}catch{}return null},I1=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus",""],Qn={rec:null,stream:null,startedAt:0,get active(){return!!this.rec&&this.rec.state!=="inactive"},get supported(){var i;return typeof window<"u"&&!!((i=navigator.mediaDevices)!=null&&i.getUserMedia&&window.MediaRecorder)},async start(){if(this.active)return;this.stream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});const i=I1.find(t=>!t||MediaRecorder.isTypeSupported(t));this.rec=new MediaRecorder(this.stream,i?{mimeType:i}:{}),this.chunks=[],this.rec.ondataavailable=t=>{t.data.size&&this.chunks.push(t.data)},this.rec.start(250),this.startedAt=Date.now()},stop(){return this.active?new Promise(i=>{this.rec.onstop=()=>{var n;const t=((n=this.rec.mimeType)==null?void 0:n.split(";")[0])||"audio/webm",e=this.chunks.length?new Blob(this.chunks,{type:t}):null;this.release(),i(e&&e.size>1200?e:null)},this.rec.stop()}):Promise.resolve(null)},cancel(){this.active&&(this.rec.onstop=null,this.rec.stop()),this.release()},release(){var i;(i=this.stream)==null||i.getTracks().forEach(t=>t.stop()),this.rec=null,this.stream=null,this.startedAt=0}};function k1(i){const t={"audio/webm":"webm","audio/mp4":"m4a","audio/ogg":"ogg","audio/wav":"wav"}[i.type]||"webm",e=new Date().toISOString().slice(0,19).replace(/[:T]/g,"-");return new File([i],`voice-note-${e}.${t}`,{type:i.type})}const dd={chief:["Moira","Fiona","Serena","Karen"],ada:["Samantha","Ava","Allison","Susan"],tunde:["Daniel","Oliver","Arthur","Alex"],mira:["Karen","Zoe","Tessa","Fiona"],kai:["Reed","Tom","Alex","Rocko"],zola:["Tessa","Nicky","Joelle","Samantha"],remi:["Rishi","Veena","Aman","Tara"],obi:["Flo","Eddy","Daniel","Reed"],lin:["Sandy","Shelley","Kathy","Moira"]},fd=i=>{const t=`${i.voiceURI||""} ${i.name||""}`.toLowerCase();return t.includes("premium")?3:t.includes("enhanced")?2:t.includes("compact")?0:1};class N1{constructor(){this.on=ud("office.speak")==="1",this.voices=[],this.queue=[],this.saying=null;const t=typeof window<"u"&&window.speechSynthesis;if(!t)return;const e=()=>{this.voices=t.getVoices()||[]};e(),t.onvoiceschanged=e}get supported(){return typeof window<"u"&&!!window.speechSynthesis}setOn(t){this.on=t,ud("office.speak",t?"1":"0"),t||this.stop()}voiceFor(t){this.voices.length||(this.voices=window.speechSynthesis.getVoices()||[]);const e=this.voices.filter(a=>/^en\b/i.test(a.lang)||/^en[-_]/i.test(a.lang)),n=e.length?e:this.voices;for(const a of dd[t]||[]){const o=n.filter(l=>l.name.toLowerCase().startsWith(a.toLowerCase()));if(o.length)return o.sort((l,c)=>fd(c)-fd(l))[0]}const s=Object.keys(dd),r=Math.max(0,s.indexOf(t));return n[r%n.length]||null}speak(t,e="chief",{force:n=!1}={}){if(!this.supported||!this.on&&!n)return;const s=D1(t);s&&(this.queue.push({say:s,from:e}),this.next())}next(){if(this.saying||!this.queue.length)return;const{say:t,from:e}=this.queue.shift(),n=new SpeechSynthesisUtterance(t),s=this.voiceFor(e);s&&(n.voice=s,n.lang=s.lang),n.rate=1.05,n.pitch=e==="chief"?1:1.02,this.saying=n;const r=()=>{this.saying=null,this.next()};n.onend=r,n.onerror=r,window.speechSynthesis.speak(n)}stop(){this.queue=[],this.saying=null;try{window.speechSynthesis.cancel()}catch{}}get busy(){return!!this.saying||!!this.queue.length}}const ai=new N1,J=i=>document.getElementById(i),pd=["👍","❤️","😂","🎉","👀","🙏","🔥","✅"],U1=[["Smileys",["😀","😄","😁","😆","😅","🤣","😂","🙂","😉","😊","😇","🥰","😍","🤩","😘","😋","😛","🤪","🤔","🤨","😐","😑","😶","🙄","😏","😬","😌","😴","🤯","🥳","😎","🤓","🧐","😕","😟","😮","😲","😳","🥺","😢","😭","😱","😤","😡","🤬","💀","🤡","👻"]],["Gestures",["👍","👎","👌","🤌","✌️","🤞","🤝","👏","🙌","👐","🙏","💪","👋","🤙","👀","🫡","🤷","🤦","🙋","🙇"]],["Hearts",["❤️","🧡","💛","💚","💙","💜","🖤","🤍","💔","💯","💥","💫","✨","⭐","🔥","⚡"]],["Work",["✅","❌","⚠️","❓","❗","🚀","🎉","🎯","🏆","🐛","🔧","🛠️","💡","📌","📎","📝","📈","📉","⏳","🧪","🔒","🧠","☕","🍕"]]],lt=i=>String(i??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]),tp=new Qf({gfm:!0,breaks:!0});tp.use({renderer:{html:i=>lt(i.text??i),link:({href:i,text:t})=>/^https?:\/\//i.test(i)?`<a href="${lt(i)}" target="_blank" rel="noreferrer">${lt(t)}</a>`:lt(t),image:({text:i})=>lt(i)}});const Dl=i=>tp.parse(String(i??"")),jr={queued:"Queued",working:"Working",done:"Shipped",failed:"Failed",stopped:"Stopped"},O1={haiku:"Haiku",sonnet:"Sonnet",opus:"Opus"},F1=i=>{var t,e;return O1[i]||((e=[...((t=J("model"))==null?void 0:t.options)||[]].find(n=>n.value===i))==null?void 0:e.text)||i||"Default"},Il={library:"Library",servers:"Server room",window:"Research",whiteboard:"Whiteboard",desk:"Desk"},Gi=(i,t)=>typeof t=="string"&&Object.hasOwn(i,t)?t:"",kl=i=>jr[Gi(jr,i)]||"",Vi=i=>Number.isFinite(i)?i:0,js=i=>typeof i=="string"&&/^#[0-9a-f]{3,8}$/i.test(i)?i:"#999",Ba=(i,t)=>{try{if(t===void 0)return localStorage.getItem(i);localStorage.setItem(i,t)}catch{}return null};function md(i){const t=Math.max(0,Math.round(i/1e3));if(t<60)return`${t}s`;const e=Math.floor(t/60);return e<60?`${e}m ${t%60}s`:`${Math.floor(e/60)}h ${e%60}m`}const z1=i=>{const t=Math.ceil(i/6e4);if(t<60)return`${t}m`;const e=Math.floor(t/60);return e<24?`${e}h ${t%60}m`:`${Math.floor(e/24)}d ${e%24}h`},B1=i=>{const t=new Date(i),e=t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"});return t.toDateString()===new Date().toDateString()?e:`${t.toLocaleDateString([],{weekday:"short"})} ${e}`},Ir=i=>i>=1<<30?`${(i/(1<<30)).toFixed(1)} GB`:`${Math.round(i/(1<<20))} MB`,gd=i=>`${i>=10?Math.round(i):Math.round(i*10)/10}%`;async function He(i,t,e){const n=t===void 0?e?{method:e}:{}:{method:e||"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)},s=await fetch(i,n),r=await s.json().catch(()=>({}));if(!s.ok)throw new Error(r.error||`Request failed (${s.status})`);return r}const ep=i=>i<1024?`${i} B`:i<1048576?`${Math.round(i/1024)} KB`:`${(i/1048576).toFixed(1)} MB`,Ha=i=>`/api/uploads/${i.id}/${encodeURIComponent(i.name)}`;class vd{constructor(t,e){this.el=t,this.onError=e,this.items=[],t.onclick=n=>{const s=n.target.closest("[data-drop]");s&&(this.items=this.items.filter(r=>r.key!==s.dataset.drop),this.render())}}add(t){for(const e of t){const n={key:Math.random().toString(36).slice(2),name:e.name||"pasted",size:e.size,preview:e.type.startsWith("image/")?URL.createObjectURL(e):null},s=e.name||`pasted-${Date.now()}.${(e.type.split("/")[1]||"bin").replace("jpeg","jpg")}`;n.done=fetch("/api/uploads",{method:"POST",headers:{"x-file-name":encodeURIComponent(s),"content-type":e.type||"application/octet-stream"},body:e}).then(async r=>{const a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a.error||`Upload failed (${r.status})`);n.id=a.id}).catch(r=>{this.items=this.items.filter(a=>a!==n),this.render(),this.onError(`${n.name}: ${r.message}`)}).finally(()=>{n.loading=!1,this.render()}),n.loading=!0,this.items.push(n)}this.render()}attach({id:t,name:e,size:n}){this.items.push({key:Math.random().toString(36).slice(2),id:t,name:e,size:n,done:Promise.resolve(),voice:!0}),this.render()}async ids(){return await Promise.all(this.items.map(t=>t.done)),this.items.filter(t=>t.id).map(t=>t.id)}get empty(){return!this.items.length}clear(){this.items.forEach(t=>t.preview&&URL.revokeObjectURL(t.preview)),this.items=[],this.render()}render(){this.el.hidden=!this.items.length,this.el.innerHTML=this.items.map(t=>`
4357
- <span class="file ${t.loading?"loading":""}" title="${lt(t.name)} · ${ep(t.size)}">
4354
+ `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${t}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){const s=this.parser.parseInline(n),r=Td(t);if(r===null)return s;t=r;let a='<a href="'+t+'"';return e&&(a+=' title="'+e+'"'),a+=">"+s+"</a>",a}image({href:t,title:e,text:n}){const s=Td(t);if(s===null)return n;t=s;let r=`<img src="${t}" alt="${n}"`;return e&&(r+=` title="${e}"`),r+=">",r}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):t.text}}class Gh{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}}class On{constructor(t){_e(this,"options");_e(this,"renderer");_e(this,"textRenderer");this.options=t||Ls,this.options.renderer=this.options.renderer||new Co,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Gh}static parse(t,e){return new On(e).parse(t)}static parseInline(t,e){return new On(e).parseInline(t)}parse(t,e=!0){let n="";for(let s=0;s<t.length;s++){const r=t[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const o=r,l=this.options.extensions.renderers[o.type].call({parser:this},o);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(o.type)){n+=l||"";continue}}const a=r;switch(a.type){case"space":{n+=this.renderer.space(a);continue}case"hr":{n+=this.renderer.hr(a);continue}case"heading":{n+=this.renderer.heading(a);continue}case"code":{n+=this.renderer.code(a);continue}case"table":{n+=this.renderer.table(a);continue}case"blockquote":{n+=this.renderer.blockquote(a);continue}case"list":{n+=this.renderer.list(a);continue}case"html":{n+=this.renderer.html(a);continue}case"paragraph":{n+=this.renderer.paragraph(a);continue}case"text":{let o=a,l=this.renderer.text(o);for(;s+1<t.length&&t[s+1].type==="text";)o=t[++s],l+=`
4355
+ `+this.renderer.text(o);e?n+=this.renderer.paragraph({type:"paragraph",raw:l,text:l,tokens:[{type:"text",raw:l,text:l}]}):n+=l;continue}default:{const o='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(t,e){e=e||this.renderer;let n="";for(let s=0;s<t.length;s++){const r=t[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const o=this.options.extensions.renderers[r.type].call({parser:this},r);if(o!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=o||"";continue}}const a=r;switch(a.type){case"escape":{n+=e.text(a);break}case"html":{n+=e.html(a);break}case"link":{n+=e.link(a);break}case"image":{n+=e.image(a);break}case"strong":{n+=e.strong(a);break}case"em":{n+=e.em(a);break}case"codespan":{n+=e.codespan(a);break}case"br":{n+=e.br(a);break}case"del":{n+=e.del(a);break}case"text":{n+=e.text(a);break}default:{const o='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}}class ea{constructor(t){_e(this,"options");_e(this,"block");this.options=t||Ls}preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}provideLexer(){return this.block?Un.lex:Un.lexInline}provideParser(){return this.block?On.parse:On.parseInline}}_e(ea,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));class Sp{constructor(...t){_e(this,"defaults",Oh());_e(this,"options",this.setOptions);_e(this,"parse",this.parseMarkdown(!0));_e(this,"parseInline",this.parseMarkdown(!1));_e(this,"Parser",On);_e(this,"Renderer",Co);_e(this,"TextRenderer",Gh);_e(this,"Lexer",Un);_e(this,"Tokenizer",To);_e(this,"Hooks",ea);this.use(...t)}walkTokens(t,e){var s,r;let n=[];for(const a of t)switch(n=n.concat(e.call(this,a)),a.type){case"table":{const o=a;for(const l of o.header)n=n.concat(this.walkTokens(l.tokens,e));for(const l of o.rows)for(const c of l)n=n.concat(this.walkTokens(c.tokens,e));break}case"list":{const o=a;n=n.concat(this.walkTokens(o.items,e));break}default:{const o=a;(r=(s=this.defaults.extensions)==null?void 0:s.childTokens)!=null&&r[o.type]?this.defaults.extensions.childTokens[o.type].forEach(l=>{const c=o[l].flat(1/0);n=n.concat(this.walkTokens(c,e))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,e)))}}return n}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{const s={...n};if(s.async=this.defaults.async||s.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){const a=e.renderers[r.name];a?e.renderers[r.name]=function(...o){let l=r.renderer.apply(this,o);return l===!1&&(l=a.apply(this,o)),l}:e.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const a=e[r.level];a?a.unshift(r.tokenizer):e[r.level]=[r.tokenizer],r.start&&(r.level==="block"?e.startBlock?e.startBlock.push(r.start):e.startBlock=[r.start]:r.level==="inline"&&(e.startInline?e.startInline.push(r.start):e.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(e.childTokens[r.name]=r.childTokens)}),s.extensions=e),n.renderer){const r=this.defaults.renderer||new Co(this.defaults);for(const a in n.renderer){if(!(a in r))throw new Error(`renderer '${a}' does not exist`);if(["options","parser"].includes(a))continue;const o=a,l=n.renderer[o],c=r[o];r[o]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u||""}}s.renderer=r}if(n.tokenizer){const r=this.defaults.tokenizer||new To(this.defaults);for(const a in n.tokenizer){if(!(a in r))throw new Error(`tokenizer '${a}' does not exist`);if(["options","rules","lexer"].includes(a))continue;const o=a,l=n.tokenizer[o],c=r[o];r[o]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u}}s.tokenizer=r}if(n.hooks){const r=this.defaults.hooks||new ea;for(const a in n.hooks){if(!(a in r))throw new Error(`hook '${a}' does not exist`);if(["options","block"].includes(a))continue;const o=a,l=n.hooks[o],c=r[o];ea.passThroughHooks.has(a)?r[o]=h=>{if(this.defaults.async)return Promise.resolve(l.call(r,h)).then(d=>c.call(r,d));const u=l.call(r,h);return c.call(r,u)}:r[o]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u}}s.hooks=r}if(n.walkTokens){const r=this.defaults.walkTokens,a=n.walkTokens;s.walkTokens=function(o){let l=[];return l.push(a.call(this,o)),r&&(l=l.concat(r.call(this,o))),l}}this.defaults={...this.defaults,...s}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Un.lex(t,e??this.defaults)}parser(t,e){return On.parse(t,e??this.defaults)}parseMarkdown(t){return(n,s)=>{const r={...s},a={...this.defaults,...r},o=this.onError(!!a.silent,!!a.async);if(this.defaults.async===!0&&r.async===!1)return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof n>"u"||n===null)return o(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));a.hooks&&(a.hooks.options=a,a.hooks.block=t);const l=a.hooks?a.hooks.provideLexer():t?Un.lex:Un.lexInline,c=a.hooks?a.hooks.provideParser():t?On.parse:On.parseInline;if(a.async)return Promise.resolve(a.hooks?a.hooks.preprocess(n):n).then(h=>l(h,a)).then(h=>a.hooks?a.hooks.processAllTokens(h):h).then(h=>a.walkTokens?Promise.all(this.walkTokens(h,a.walkTokens)).then(()=>h):h).then(h=>c(h,a)).then(h=>a.hooks?a.hooks.postprocess(h):h).catch(o);try{a.hooks&&(n=a.hooks.preprocess(n));let h=l(n,a);a.hooks&&(h=a.hooks.processAllTokens(h)),a.walkTokens&&this.walkTokens(h,a.walkTokens);let u=c(h,a);return a.hooks&&(u=a.hooks.postprocess(u)),u}catch(h){return o(h)}}}onError(t,e){return n=>{if(n.message+=`
4356
+ Please report this to https://github.com/markedjs/marked.`,t){const s="<p>An error occurred:</p><pre>"+An(n.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(n);throw n}}}const Rs=new Sp;function ge(i,t){return Rs.parse(i,t)}ge.options=ge.setOptions=function(i){return Rs.setOptions(i),ge.defaults=Rs.defaults,fp(ge.defaults),ge};ge.getDefaults=Oh;ge.defaults=Ls;ge.use=function(...i){return Rs.use(...i),ge.defaults=Rs.defaults,fp(ge.defaults),ge};ge.walkTokens=function(i,t){return Rs.walkTokens(i,t)};ge.parseInline=Rs.parseInline;ge.Parser=On;ge.parser=On.parse;ge.Renderer=Co;ge.TextRenderer=Gh;ge.Lexer=Un;ge.lexer=Un.lex;ge.Tokenizer=To;ge.Hooks=ea;ge.parse=ge;ge.options;ge.setOptions;ge.use;ge.walkTokens;ge.parseInline;On.parse;Un.lex;function a1(i){let t=String(i??"");if(t=t.replace(/```[\s\S]*?```/g," (code) ").replace(/~~~[\s\S]*?~~~/g," (code) ").replace(/`([^`]*)`/g,(n,s)=>/[\/\\]/.test(s)?" that file ":/^\W*$/.test(s)?" ":` ${s} `).replace(/!\[[^\]]*\]\([^)]*\)/g," ").replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/https?:\/\/\S+/g," a link ").replace(/^\s{0,3}#{1,6}\s*/gm,"").replace(/^\s*>\s?/gm,"").replace(/^\s*[-*+]\s+/gm,", ").replace(/^\s*\d+\.\s+/gm,", ").replace(/(\*\*|__|\*|_|~~)/g,"").replace(/^\s*\|.*\|\s*$/gm," ").replace(/^\s*[-=:|]{3,}\s*$/gm," ").replace(/(?:\.{0,2}\/)?(?:[\w.-]+\/){1,}[\w.-]+(?::\d+)?/g," that file ").replace(/\b[\w-]+\.(?:js|ts|tsx|jsx|css|html|json|md|py|go|rs|sh|yml|yaml)\b(?::\d+)?/gi," that file ").replace(/[#*`_~>|]/g," ").replace(/\s*,\s*,+/g,", ").replace(/[ \t]+/g," ").replace(/\n{2,}/g,". ").replace(/\n/g," ").replace(/\s+([.,!?;:])/g,"$1").replace(/([:;,])[.,]+/g,"$1").replace(/([.!?])\s*,\s*/g,"$1 ").replace(/\.{2,}/g,".").replace(/\s{2,}/g," ").replace(/^[\s.,;:!?]+/,"").trim(),!/[a-z0-9]/i.test(t))return"";const e=460;if(t.length>e){const n=t.slice(0,e),s=Math.max(n.lastIndexOf(". "),n.lastIndexOf("! "),n.lastIndexOf("? "));t=s>160?n.slice(0,s+1):n.replace(/\s+\S*$/,"")+"…"}return t}const Pd=(i,t)=>{try{if(t===void 0)return localStorage.getItem(i);localStorage.setItem(i,t)}catch{}return null},o1=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus",""],ii={rec:null,stream:null,startedAt:0,get active(){return!!this.rec&&this.rec.state!=="inactive"},get supported(){var i;return typeof window<"u"&&!!((i=navigator.mediaDevices)!=null&&i.getUserMedia&&window.MediaRecorder)},async start(){if(this.active)return;this.stream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});const i=o1.find(t=>!t||MediaRecorder.isTypeSupported(t));this.rec=new MediaRecorder(this.stream,i?{mimeType:i}:{}),this.chunks=[],this.rec.ondataavailable=t=>{t.data.size&&this.chunks.push(t.data)},this.rec.start(250),this.startedAt=Date.now()},stop(){return this.active?new Promise(i=>{this.rec.onstop=()=>{var n;const t=((n=this.rec.mimeType)==null?void 0:n.split(";")[0])||"audio/webm",e=this.chunks.length?new Blob(this.chunks,{type:t}):null;this.release(),i(e&&e.size>1200?e:null)},this.rec.stop()}):Promise.resolve(null)},cancel(){this.active&&(this.rec.onstop=null,this.rec.stop()),this.release()},release(){var i;(i=this.stream)==null||i.getTracks().forEach(t=>t.stop()),this.rec=null,this.stream=null,this.startedAt=0}};function l1(i){const t={"audio/webm":"webm","audio/mp4":"m4a","audio/ogg":"ogg","audio/wav":"wav"}[i.type]||"webm",e=new Date().toISOString().slice(0,19).replace(/[:T]/g,"-");return new File([i],`voice-note-${e}.${t}`,{type:i.type})}const Ld={chief:["Moira","Fiona","Serena","Karen"],ada:["Samantha","Ava","Allison","Susan"],tunde:["Daniel","Oliver","Arthur","Alex"],mira:["Karen","Zoe","Tessa","Fiona"],kai:["Reed","Tom","Alex","Rocko"],zola:["Tessa","Nicky","Joelle","Samantha"],remi:["Rishi","Veena","Aman","Tara"],obi:["Flo","Eddy","Daniel","Reed"],lin:["Sandy","Shelley","Kathy","Moira"]},Dd=i=>{const t=`${i.voiceURI||""} ${i.name||""}`.toLowerCase();return t.includes("premium")?3:t.includes("enhanced")?2:t.includes("compact")?0:1};class c1{constructor(){this.on=Pd("office.speak")==="1",this.voices=[],this.queue=[],this.saying=null;const t=typeof window<"u"&&window.speechSynthesis;if(!t)return;const e=()=>{this.voices=t.getVoices()||[]};e(),t.onvoiceschanged=e}get supported(){return typeof window<"u"&&!!window.speechSynthesis}setOn(t){this.on=t,Pd("office.speak",t?"1":"0"),t||this.stop()}voiceFor(t){this.voices.length||(this.voices=window.speechSynthesis.getVoices()||[]);const e=this.voices.filter(a=>/^en\b/i.test(a.lang)||/^en[-_]/i.test(a.lang)),n=e.length?e:this.voices;for(const a of Ld[t]||[]){const o=n.filter(l=>l.name.toLowerCase().startsWith(a.toLowerCase()));if(o.length)return o.sort((l,c)=>Dd(c)-Dd(l))[0]}const s=Object.keys(Ld),r=Math.max(0,s.indexOf(t));return n[r%n.length]||null}speak(t,e="chief",{force:n=!1}={}){if(!this.supported||!this.on&&!n)return;const s=a1(t);s&&(this.queue.push({say:s,from:e}),this.next())}next(){if(this.saying||!this.queue.length)return;const{say:t,from:e}=this.queue.shift(),n=new SpeechSynthesisUtterance(t),s=this.voiceFor(e);s&&(n.voice=s,n.lang=s.lang),n.rate=1.05,n.pitch=e==="chief"?1:1.02,this.saying=n;const r=()=>{this.saying=null,this.next()};n.onend=r,n.onerror=r,window.speechSynthesis.speak(n)}stop(){this.queue=[],this.saying=null;try{window.speechSynthesis.cancel()}catch{}}get busy(){return!!this.saying||!!this.queue.length}}const hi=new c1,q=i=>document.getElementById(i),Id=["👍","❤️","😂","🎉","👀","🙏","🔥","✅"],h1=[["Smileys",["😀","😄","😁","😆","😅","🤣","😂","🙂","😉","😊","😇","🥰","😍","🤩","😘","😋","😛","🤪","🤔","🤨","😐","😑","😶","🙄","😏","😬","😌","😴","🤯","🥳","😎","🤓","🧐","😕","😟","😮","😲","😳","🥺","😢","😭","😱","😤","😡","🤬","💀","🤡","👻"]],["Gestures",["👍","👎","👌","🤌","✌️","🤞","🤝","👏","🙌","👐","🙏","💪","👋","🤙","👀","🫡","🤷","🤦","🙋","🙇"]],["Hearts",["❤️","🧡","💛","💚","💙","💜","🖤","🤍","💔","💯","💥","💫","✨","⭐","🔥","⚡"]],["Work",["✅","❌","⚠️","❓","❗","🚀","🎉","🎯","🏆","🐛","🔧","🛠️","💡","📌","📎","📝","📈","📉","⏳","🧪","🔒","🧠","☕","🍕"]]],lt=i=>String(i??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]),wp=new Sp({gfm:!0,breaks:!0});wp.use({renderer:{html:i=>lt(i.text??i),link:({href:i,text:t})=>/^https?:\/\//i.test(i)?`<a href="${lt(i)}" target="_blank" rel="noreferrer">${lt(t)}</a>`:lt(t),image:({text:i})=>lt(i)}});const $l=i=>wp.parse(String(i??"")),na={queued:"Queued",working:"Working",done:"Shipped",failed:"Failed",stopped:"Stopped"},u1={haiku:"Haiku",sonnet:"Sonnet",opus:"Opus"},d1=i=>{var t,e;return u1[i]||((e=[...((t=q("model"))==null?void 0:t.options)||[]].find(n=>n.value===i))==null?void 0:e.text)||i||"Default"},Wl={library:"Library",servers:"Server room",window:"Research",whiteboard:"Whiteboard",desk:"Desk"},qi=(i,t)=>typeof t=="string"&&Object.hasOwn(i,t)?t:"",Xl=i=>na[qi(na,i)]||"",ji=i=>Number.isFinite(i)?i:0,er=i=>typeof i=="string"&&/^#[0-9a-f]{3,8}$/i.test(i)?i:"#999",Ya=(i,t)=>{try{if(t===void 0)return localStorage.getItem(i);localStorage.setItem(i,t)}catch{}return null};function kd(i){const t=Math.max(0,Math.round(i/1e3));if(t<60)return`${t}s`;const e=Math.floor(t/60);return e<60?`${e}m ${t%60}s`:`${Math.floor(e/60)}h ${e%60}m`}const f1=i=>{const t=Math.ceil(i/6e4);if(t<60)return`${t}m`;const e=Math.floor(t/60);return e<24?`${e}h ${t%60}m`:`${Math.floor(e/24)}d ${e%24}h`},p1=i=>{const t=new Date(i),e=t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"});return t.toDateString()===new Date().toDateString()?e:`${t.toLocaleDateString([],{weekday:"short"})} ${e}`},Vr=i=>i>=1<<30?`${(i/(1<<30)).toFixed(1)} GB`:`${Math.round(i/(1<<20))} MB`,Nd=i=>`${i>=10?Math.round(i):Math.round(i*10)/10}%`;async function $e(i,t,e){const n=t===void 0?e?{method:e}:{}:{method:e||"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)},s=await fetch(i,n),r=await s.json().catch(()=>({}));if(!s.ok)throw new Error(r.error||`Request failed (${s.status})`);return r}const Ep=i=>i<1024?`${i} B`:i<1048576?`${Math.round(i/1024)} KB`:`${(i/1048576).toFixed(1)} MB`,Ka=i=>`/api/uploads/${i.id}/${encodeURIComponent(i.name)}`;class Ud{constructor(t,e){this.el=t,this.onError=e,this.items=[],t.onclick=n=>{const s=n.target.closest("[data-drop]");s&&(this.items=this.items.filter(r=>r.key!==s.dataset.drop),this.render())}}add(t){for(const e of t){const n={key:Math.random().toString(36).slice(2),name:e.name||"pasted",size:e.size,preview:e.type.startsWith("image/")?URL.createObjectURL(e):null},s=e.name||`pasted-${Date.now()}.${(e.type.split("/")[1]||"bin").replace("jpeg","jpg")}`;n.done=fetch("/api/uploads",{method:"POST",headers:{"x-file-name":encodeURIComponent(s),"content-type":e.type||"application/octet-stream"},body:e}).then(async r=>{const a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a.error||`Upload failed (${r.status})`);n.id=a.id}).catch(r=>{this.items=this.items.filter(a=>a!==n),this.render(),this.onError(`${n.name}: ${r.message}`)}).finally(()=>{n.loading=!1,this.render()}),n.loading=!0,this.items.push(n)}this.render()}attach({id:t,name:e,size:n}){this.items.push({key:Math.random().toString(36).slice(2),id:t,name:e,size:n,done:Promise.resolve(),voice:!0}),this.render()}async ids(){return await Promise.all(this.items.map(t=>t.done)),this.items.filter(t=>t.id).map(t=>t.id)}get empty(){return!this.items.length}clear(){this.items.forEach(t=>t.preview&&URL.revokeObjectURL(t.preview)),this.items=[],this.render()}render(){this.el.hidden=!this.items.length,this.el.innerHTML=this.items.map(t=>`
4357
+ <span class="file ${t.loading?"loading":""}" title="${lt(t.name)} · ${Ep(t.size)}">
4358
4358
  ${t.preview?`<img src="${t.preview}" alt="">`:t.voice?"<b>VOICE</b>":"<b>FILE</b>"}
4359
4359
  <span>${lt(t.name)}</span>
4360
4360
  <button type="button" data-drop="${t.key}" aria-label="Remove ${lt(t.name)}">×</button>
4361
- </span>`).join("")}}function _d(i,{zone:t,input:e,picker:n,button:s}){s.onclick=()=>n.click(),n.onchange=()=>{i.add([...n.files]),n.value=""},e.addEventListener("paste",r=>{var o;const a=[...((o=r.clipboardData)==null?void 0:o.files)||[]];a.length&&(r.preventDefault(),i.add(a))}),t.addEventListener("dragover",r=>{[...r.dataTransfer.types].includes("Files")&&(r.preventDefault(),t.classList.add("dropping"))}),t.addEventListener("dragleave",r=>{t.contains(r.relatedTarget)||t.classList.remove("dropping")}),t.addEventListener("drop",r=>{t.classList.remove("dropping"),r.dataTransfer.files.length&&(r.preventDefault(),i.add([...r.dataTransfer.files]))})}const xd=i=>i!=null&&i.length?`<div class="files">${i.map(t=>t.image?`<a class="thumb" href="${Ha(t)}" target="_blank" rel="noreferrer" title="${lt(t.name)}"><img src="${Ha(t)}" alt="${lt(t.name)}" loading="lazy"></a>`:t.audio?`<audio class="voice" controls preload="metadata" src="${Ha(t)}" title="${lt(t.name)}"></audio>`:`<a class="file" href="${Ha(t)}" title="${lt(t.name)} · ${ep(t.size)}"><b>FILE</b><span>${lt(t.name)}</span></a>`).join("")}</div>`:"",Va={more:'<svg viewBox="0 0 24 24"><path d="M7 7l5 5 5-5M7 13l5 5 5-5"/></svg>',speak:'<svg viewBox="0 0 24 24"><path d="M11 5 6 9H3v6h3l5 4V5Z"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/></svg>',open:'<svg viewBox="0 0 24 24"><path d="M14 4h6v6M20 4l-9 9"/><path d="M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>',reply:'<svg viewBox="0 0 24 24"><path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z"/></svg>'};class H1{constructor(t){this.app=t,this.openId=null,this.repos=null,this.channels=[{id:"general",name:"general"}],this.channel=Ba("office.channel")||"general",this.unread=new Map,J("clear").onclick=async()=>{await He("/api/jobs/clear",{}),this.closeDetail()},J("away").onclick=e=>{const n=e.target.closest("[data-recall]");n&&this.app.recall(n.dataset.recall)},J("jobs").onclick=e=>{const n=e.target.closest("[data-id]");n&&this.app.openJob(n.dataset.id)},J("projects").onclick=e=>{const n=e.target.closest(".job[data-id]");if(n)return this.app.openJob(n.dataset.id);const s=e.target.closest("[data-new]");if(s)return this.focusInput(`#${s.dataset.new.replace(/\s+/g,"-")} `);const r=e.target.closest(".head[data-project]");r&&(this.projectOpen=this.projectOpen===r.dataset.project?null:r.dataset.project,this.renderProjects())},document.querySelectorAll(".tabs button").forEach(e=>e.onclick=()=>this.tab(e.dataset.tab)),document.querySelectorAll("#mnav button").forEach(e=>e.onclick=()=>{e.dataset.m==="office"?this.mobile("office"):this.tab(e.dataset.m)}),this.bindTeam(),this.bindChat(),this.bindChannels(),this.renderChannels(),addEventListener("keydown",e=>{var s;const n=/INPUT|TEXTAREA|SELECT/.test((s=document.activeElement)==null?void 0:s.tagName);(e.key==="n"||e.key==="/")&&!n&&!e.metaKey&&!e.ctrlKey&&(e.preventDefault(),this.focusInput()),e.key==="Escape"&&!n&&this.closeDetail()}),setInterval(()=>this.tick(),1e3)}renderLevel(t){J("lv").textContent=`Lv ${t.level}`,J("lv").title=`Level ${t.level}`,J("xpbar").style.width=`${Math.min(100,(t.xp-t.floor)/(t.next-t.floor)*100)}%`,J("xptext").textContent=`${t.xp-t.floor} / ${t.next-t.floor} XP`}renderUsage(t){if(t!==void 0&&(this.usage=t),t=this.usage,J("usage").hidden=!t,!t)return;const e=t.error&&!t.session&&!t.week;J("useErr").hidden=!e,J("useErr").textContent=e?t.error:"";for(const[n,s]of[["useSession",t.session],["useWeek",t.week]]){const r=J(n);if(r.hidden=!s,!s)continue;const a=s.resetsAt?s.resetsAt-Date.now():null;r.className=`meter ${s.pct>=90?"hot":s.pct>=70?"warm":""}`,r.querySelector("i").style.width=`${Math.min(100,s.pct)}%`,r.querySelector(".v").textContent=`${s.pct}%`,r.querySelector(".r").textContent=a===null?"":a<=0?"Resetting now":`Resets in ${z1(a)}`,r.title=s.resetsAt?`Resets ${B1(s.resetsAt)}`:""}}renderProc(t,e){e&&(this.machine=e),this.procs=t||null;const n=this.machine,s=Object.values(this.procs||{}).filter(u=>u);if(J("load").hidden=!s.length||!n,J("load").hidden)return this.renderMeta(this.app.job(this.openId));const r=s.reduce((u,d)=>u+(d.cpu||0),0),a=s.reduce((u,d)=>u+d.mem,0),o=r/n.cores,l=a/n.mem*100,c=`${s.length} ${s.length===1?"agent":"agents"}`,h=`${(r/100).toFixed(1)} of ${n.cores} cores`;this.meter("loadCpu",o,gd(o),s.length>1?`${c} · ${h}`:h,`${c} using ${h}`),this.meter("loadMem",l,Ir(a),`${gd(l)} of ${Ir(n.mem)}`,`${c} holding ${Ir(a)} of ${Ir(n.mem)}`),this.renderMeta(this.app.job(this.openId))}meter(t,e,n,s,r){const a=J(t);a.hidden=!1,a.className=`meter ${e>=90?"hot":e>=70?"warm":""}`,a.querySelector("i").style.width=`${Math.min(100,e)}%`,a.querySelector(".v").textContent=n,a.querySelector(".r").textContent=s,a.title=r}renderStats(t,e=0){const n=r=>t.filter(a=>a.status===r&&!a.awaitingBoss).length,s=t.reduce((r,a)=>r+(a.cost||0),e);J("stats").innerHTML=[`<span><b>${n("working")}</b> working</span>`,`<span><b>${n("queued")}</b> queued</span>`,`<span><b>${n("done")}</b> shipped</span>`,`<span><b>$${s.toFixed(2)}</b> spent</span>`].join("")}renderJobs(t,e){const n={working:0,queued:1,done:2,failed:2,stopped:2},s=[...t].sort((a,o)=>n[a.status]-n[o.status]||(o.endedAt||o.queuedAt)-(a.endedAt||a.queuedAt));J("jobs").innerHTML=s.length?s.map(a=>`
4361
+ </span>`).join("")}}function Od(i,{zone:t,input:e,picker:n,button:s}){s.onclick=()=>n.click(),n.onchange=()=>{i.add([...n.files]),n.value=""},e.addEventListener("paste",r=>{var o;const a=[...((o=r.clipboardData)==null?void 0:o.files)||[]];a.length&&(r.preventDefault(),i.add(a))}),t.addEventListener("dragover",r=>{[...r.dataTransfer.types].includes("Files")&&(r.preventDefault(),t.classList.add("dropping"))}),t.addEventListener("dragleave",r=>{t.contains(r.relatedTarget)||t.classList.remove("dropping")}),t.addEventListener("drop",r=>{t.classList.remove("dropping"),r.dataTransfer.files.length&&(r.preventDefault(),i.add([...r.dataTransfer.files]))})}const Fd=i=>i!=null&&i.length?`<div class="files">${i.map(t=>t.image?`<a class="thumb" href="${Ka(t)}" target="_blank" rel="noreferrer" title="${lt(t.name)}"><img src="${Ka(t)}" alt="${lt(t.name)}" loading="lazy"></a>`:t.audio?`<audio class="voice" controls preload="metadata" src="${Ka(t)}" title="${lt(t.name)}"></audio>`:`<a class="file" href="${Ka(t)}" title="${lt(t.name)} · ${Ep(t.size)}"><b>FILE</b><span>${lt(t.name)}</span></a>`).join("")}</div>`:"",Za={more:'<svg viewBox="0 0 24 24"><path d="M7 7l5 5 5-5M7 13l5 5 5-5"/></svg>',speak:'<svg viewBox="0 0 24 24"><path d="M11 5 6 9H3v6h3l5 4V5Z"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/></svg>',open:'<svg viewBox="0 0 24 24"><path d="M14 4h6v6M20 4l-9 9"/><path d="M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>',reply:'<svg viewBox="0 0 24 24"><path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z"/></svg>'};class m1{constructor(t){this.app=t,this.openId=null,this.repos=null,this.channels=[{id:"general",name:"general"}],this.channel=Ya("office.channel")||"general",this.unread=new Map,q("clear").onclick=async()=>{await $e("/api/jobs/clear",{}),this.closeDetail()},q("away").onclick=e=>{const n=e.target.closest("[data-recall]");n&&this.app.recall(n.dataset.recall)},q("jobs").onclick=e=>{const n=e.target.closest("[data-id]");n&&this.app.openJob(n.dataset.id)},q("projects").onclick=e=>{const n=e.target.closest(".job[data-id]");if(n)return this.app.openJob(n.dataset.id);const s=e.target.closest("[data-new]");if(s)return this.focusInput(`#${s.dataset.new.replace(/\s+/g,"-")} `);const r=e.target.closest(".head[data-project]");r&&(this.projectOpen=this.projectOpen===r.dataset.project?null:r.dataset.project,this.renderProjects())},document.querySelectorAll(".tabs button").forEach(e=>e.onclick=()=>this.tab(e.dataset.tab)),document.querySelectorAll("#mnav button").forEach(e=>e.onclick=()=>{e.dataset.m==="office"?this.mobile("office"):this.tab(e.dataset.m)}),this.bindTeam(),this.bindChat(),this.bindChannels(),this.bindFold(),this.renderChannels(),addEventListener("keydown",e=>{var s;const n=/INPUT|TEXTAREA|SELECT/.test((s=document.activeElement)==null?void 0:s.tagName);(e.key==="n"||e.key==="/")&&!n&&!e.metaKey&&!e.ctrlKey&&(e.preventDefault(),this.focusInput()),e.key==="Escape"&&!n&&this.closeDetail()}),setInterval(()=>this.tick(),1e3)}renderOwner(t){t=String(t||"").trim();const e=t?`${t}${/s$/i.test(t)?"’":"’s"} Office`:"Your Office";q("officeName").textContent=e,document.title=e}bindFold(){const t=q("fold"),e=q("gaugesBox"),n=r=>{e.hidden=!r,t.setAttribute("aria-expanded",String(r));const a=r?"Hide usage":"Show usage";t.setAttribute("aria-label",a),t.title=a;try{localStorage.setItem("office.gauges",r?"1":"0")}catch{}};let s=!1;try{s=localStorage.getItem("office.gauges")==="1"}catch{}n(s),t.addEventListener("click",()=>n(e.hidden)),q("officeName").addEventListener("click",()=>n(e.hidden))}renderLevel(t){const e=`${t.xp-t.floor} / ${t.next-t.floor} XP`;q("lvNum").textContent=t.level,q("lv").title=`Level ${t.level} · ${e}`,q("lv").setAttribute("aria-label",`Level ${t.level}, ${e}`),q("lv").style.setProperty("--p",Math.min(100,(t.xp-t.floor)/(t.next-t.floor)*100)),q("xptext").textContent=e}renderUsage(t){if(t!==void 0&&(this.usage=t),t=this.usage,q("usage").hidden=!t,!t)return;const e=t.error&&!t.session&&!t.week;q("useErr").hidden=!e,q("useErr").textContent=e?t.error:"";for(const[n,s]of[["useSession",t.session],["useWeek",t.week]]){const r=q(n);if(r.hidden=!s,!s)continue;const a=s.resetsAt?s.resetsAt-Date.now():null;r.className=`meter ${s.pct>=90?"hot":s.pct>=70?"warm":""}`,r.style.setProperty("--p",Math.min(100,s.pct)),r.querySelector(".v").textContent=`${s.pct}%`,r.querySelector(".r").textContent=a===null?"":a<=0?"Resetting now":`Resets in ${f1(a)}`,r.title=[s.resetsAt?`Resets ${p1(s.resetsAt)}`:"",r.querySelector(".r").textContent].filter(Boolean).join(" · ")}}renderProc(t,e){e&&(this.machine=e),this.procs=t||null;const n=this.machine,s=Object.values(this.procs||{}).filter(u=>u);if(q("load").hidden=!s.length||!n,q("load").hidden)return this.renderMeta(this.app.job(this.openId));const r=s.reduce((u,d)=>u+(d.cpu||0),0),a=s.reduce((u,d)=>u+d.mem,0),o=r/n.cores,l=a/n.mem*100,c=`${s.length} ${s.length===1?"agent":"agents"}`,h=`${(r/100).toFixed(1)} of ${n.cores} cores`;this.meter("loadCpu",o,Nd(o),s.length>1?`${c} · ${h}`:h,`${c} using ${h}`),this.meter("loadMem",l,Vr(a),`${Nd(l)} of ${Vr(n.mem)}`,`${c} holding ${Vr(a)} of ${Vr(n.mem)}`),this.renderMeta(this.app.job(this.openId))}meter(t,e,n,s,r){const a=q(t);a.hidden=!1,a.className=`meter ${e>=90?"hot":e>=70?"warm":""}`,a.style.setProperty("--p",Math.min(100,e)),a.querySelector(".v").textContent=n,a.querySelector(".r").textContent=s,a.title=`${r} · ${s}`}renderStats(t,e=0){const n=r=>t.filter(a=>a.status===r&&!a.awaitingBoss).length,s=t.reduce((r,a)=>r+(a.cost||0),e);q("stats").innerHTML=[`<span><b>${n("working")}</b> working</span>`,`<span><b>${n("queued")}</b> queued</span>`,`<span><b>${n("done")}</b> shipped</span>`,`<span><b>$${s.toFixed(2)}</b> spent</span>`].join("")}renderJobs(t,e){const n={working:0,queued:1,done:2,failed:2,stopped:2},s=[...t].sort((a,o)=>n[a.status]-n[o.status]||(o.endedAt||o.queuedAt)-(a.endedAt||a.queuedAt));q("jobs").innerHTML=s.length?s.map(a=>`
4362
4362
  <button class="job ${a.id===this.openId?"open":""}" data-id="${lt(a.id)}">
4363
- <span class="dot ${Gi(jr,a.status)}"></span>
4363
+ <span class="dot ${qi(na,a.status)}"></span>
4364
4364
  <span class="t">${lt(a.title)}</span>
4365
- <span class="m">${a.from?`<b class="from">from ${lt(a.from)}</b> · `:""}${lt(a.repo)}${a.agentId?" · "+lt(e(a.agentId)):""} · ${kl(a.status)}</span>
4366
- </button>`).join(""):'<p class="empty">No jobs yet. Ask for something in the chat.</p>',J("clear").hidden=!s.some(a=>n[a.status]===2);const r=s.filter(a=>n[a.status]<2).length;J("jobCount").textContent=r?String(r):"",J("mJobCount").textContent=r?String(r):"",this.renderProjects(t)}async loadProjects(){try{this.repos=$h((await He("/api/repos")).repos)}catch{this.repos||(this.repos=[])}this.renderProjects()}renderProjects(t=this.lastJobs||[]){if(this.lastJobs=t,J("projectsPane").hidden)return;if(!this.repos){J("projects").innerHTML='<p class="empty">Looking for projects…</p>';return}const e=new Map;for(const r of t)(e.get(r.repo)||e.set(r.repo,[]).get(r.repo)).push(r);const n=r=>r.endedAt||r.startedAt||r.queuedAt||0,s=[...e].filter(([r])=>this.repos.includes(r)).map(([r,a])=>{a.sort((u,d)=>n(d)-n(u));const o=a.filter(u=>u.status==="working").length,l=a.filter(u=>u.status==="queued").length,c=o?"working":l?"queued":a[0].status==="failed"?"failed":"done",h=o?lt(this.app.busyIn(r)):l?`${l} queued`:`Last: ${lt(a[0].title)}`;return{name:r,js:a,live:o,queued:l,state:c,note:h,last:n(a[0])}}).sort((r,a)=>!!a.live-!!r.live||a.last-r.last).slice(0,8);J("projects").innerHTML=s.length?s.map(r=>{const a=this.projectOpen===r.name;return`<div class="project${a?" open":""}">
4365
+ <span class="m">${a.from?`<b class="from">from ${lt(a.from)}</b> · `:""}${lt(a.repo)}${a.agentId?" · "+lt(e(a.agentId)):""} · ${Xl(a.status)}</span>
4366
+ </button>`).join(""):'<p class="empty">No jobs yet. Ask for something in the chat.</p>',q("clear").hidden=!s.some(a=>n[a.status]===2);const r=s.filter(a=>n[a.status]<2).length;q("jobCount").textContent=r?String(r):"",q("mJobCount").textContent=r?String(r):"",this.renderProjects(t)}async loadProjects(){try{this.repos=su((await $e("/api/repos")).repos)}catch{this.repos||(this.repos=[])}this.renderProjects()}renderProjects(t=this.lastJobs||[]){if(this.lastJobs=t,q("projectsPane").hidden)return;if(!this.repos){q("projects").innerHTML='<p class="empty">Looking for projects…</p>';return}const e=new Map;for(const r of t)(e.get(r.repo)||e.set(r.repo,[]).get(r.repo)).push(r);const n=r=>r.endedAt||r.startedAt||r.queuedAt||0,s=[...e].filter(([r])=>this.repos.includes(r)).map(([r,a])=>{a.sort((u,d)=>n(d)-n(u));const o=a.filter(u=>u.status==="working").length,l=a.filter(u=>u.status==="queued").length,c=o?"working":l?"queued":a[0].status==="failed"?"failed":"done",h=o?lt(this.app.busyIn(r)):l?`${l} queued`:`Last: ${lt(a[0].title)}`;return{name:r,js:a,live:o,queued:l,state:c,note:h,last:n(a[0])}}).sort((r,a)=>!!a.live-!!r.live||a.last-r.last).slice(0,8);q("projects").innerHTML=s.length?s.map(r=>{const a=this.projectOpen===r.name;return`<div class="project${a?" open":""}">
4367
4367
  <button type="button" class="head" data-project="${lt(r.name)}" aria-expanded="${a}">
4368
4368
  <span class="dot ${r.state}"></span>
4369
4369
  <span class="n">${lt(r.name)}</span>
@@ -4371,33 +4371,33 @@ Please report this to https://github.com/markedjs/marked.`,t){const s="<p>An err
4371
4371
  <span class="m">${r.note}</span>
4372
4372
  </button>
4373
4373
  ${a?`<div class="sub">${r.js.length?r.js.slice(0,8).map(o=>`
4374
- <button class="job" data-id="${lt(o.id)}"><span class="dot ${Gi(jr,o.status)}"></span><span class="t">${lt(o.title)}</span>
4375
- <span class="m">${o.agentId?lt(this.app.staffName(o.agentId))+" · ":""}${kl(o.status)}</span></button>`).join(""):'<p class="none">Nothing has run here yet.</p>'}
4374
+ <button class="job" data-id="${lt(o.id)}"><span class="dot ${qi(na,o.status)}"></span><span class="t">${lt(o.title)}</span>
4375
+ <span class="m">${o.agentId?lt(this.app.staffName(o.agentId))+" · ":""}${Xl(o.status)}</span></button>`).join(""):'<p class="none">Nothing has run here yet.</p>'}
4376
4376
  <button type="button" class="ghost" data-new="${lt(r.name)}">New job in ${lt(r.name)}</button></div>`:""}
4377
- </div>`}).join(""):'<p class="empty">No projects worked on yet. Ask for something in the chat.</p>'}async openDetail(t){this.openId=t;let e=await He(As(t));this.openId===t&&($t.on&&(e=e.job),this.app.mergeLog(e),this.renderDetail(),this.app.refreshLists())}closeDetail(){this.openId=null,J("detail").hidden=!0,this.app.refreshLists(),this.app.select(null)}renderDetail(){const t=this.app.job(this.openId);if(!t)return this.closeDetail();const e=J("detail");e.hidden=!1,e.innerHTML=`
4377
+ </div>`}).join(""):'<p class="empty">No projects worked on yet. Ask for something in the chat.</p>'}async openDetail(t){this.openId=t;let e=await $e(Ns(t));this.openId===t&&(Gt.on&&(e=e.job),this.app.mergeLog(e),this.renderDetail(),this.app.refreshLists())}closeDetail(){this.openId=null,q("detail").hidden=!0,this.app.refreshLists(),this.app.select(null)}renderDetail(){const t=this.app.job(this.openId);if(!t)return this.closeDetail();const e=q("detail");e.hidden=!1,e.innerHTML=`
4378
4378
  <div class="d-head">
4379
- <span class="pill ${Gi(jr,t.status)}">${kl(t.status)}</span>
4379
+ <span class="pill ${qi(na,t.status)}">${Xl(t.status)}</span>
4380
4380
  <button class="x" title="Close (Esc)">×</button>
4381
4381
  </div>
4382
4382
  <h2>${lt(t.title)}</h2>
4383
4383
  <dl class="meta" id="meta"></dl>
4384
4384
  <div id="changes"></div>
4385
4385
  <div class="log" id="log">${t.log.map((s,r)=>this.entry(s,null,t.log[r-1])).join("")}</div>
4386
- <div class="d-foot">${this.footer(t)}</div>`,e.querySelector(".x").onclick=()=>this.closeDetail(),this.renderMeta(t),this.renderChanges(t);const n=J("log");n.scrollTop=n.scrollHeight,this.bindFooter(t)}renderChanges(t){const e=J("changes"),n=t.changes;if(!e)return;if(!n||!n.count){e.innerHTML=n?'<div class="changes none">No files changed.</div>':"";return}const s=this.changesOpen===t.id,r={added:"A",modified:"M",deleted:"D"};e.innerHTML=`
4386
+ <div class="d-foot">${this.footer(t)}</div>`,e.querySelector(".x").onclick=()=>this.closeDetail(),this.renderMeta(t),this.renderChanges(t);const n=q("log");n.scrollTop=n.scrollHeight,this.bindFooter(t)}renderChanges(t){const e=q("changes"),n=t.changes;if(!e)return;if(!n||!n.count){e.innerHTML=n?'<div class="changes none">No files changed.</div>':"";return}const s=this.changesOpen===t.id,r={added:"A",modified:"M",deleted:"D"};e.innerHTML=`
4387
4387
  <div class="changes">
4388
4388
  <button class="c-head" aria-expanded="${s}">
4389
4389
  <span class="c-title">What changed</span>
4390
- <span class="c-sum">${Vi(n.count)} file${n.count===1?"":"s"} <b class="add">+${Vi(n.add)}</b> <b class="del">−${Vi(n.del)}</b></span>
4390
+ <span class="c-sum">${ji(n.count)} file${n.count===1?"":"s"} <b class="add">+${ji(n.add)}</b> <b class="del">−${ji(n.del)}</b></span>
4391
4391
  <span class="c-caret">${s?"▾":"▸"}</span>
4392
4392
  </button>
4393
4393
  ${s?`<ul class="c-files">${n.files.map((a,o)=>`
4394
4394
  <li><button class="c-file" data-i="${o}" aria-expanded="false">
4395
- <span class="st ${Gi(r,a.status)}">${r[Gi(r,a.status)]||""}</span><span class="p" title="${lt(a.path)}">${lt(a.path)}</span>
4396
- <span class="n">${a.binary?"binary":`<b class="add">+${Vi(a.add)}</b> <b class="del">−${Vi(a.del)}</b>`}</span>
4397
- </button></li>`).join("")}${n.count>n.files.length?`<li class="more">and ${Vi(n.count-n.files.length)} more</li>`:""}</ul>`:""}
4398
- </div>`,e.querySelector(".c-head").onclick=()=>{this.changesOpen=s?null:t.id,this.renderChanges(t)},e.querySelectorAll(".c-file").forEach(a=>a.onclick=async()=>{const o=a.parentElement,l=o.querySelector("pre");if(l){l.remove(),a.setAttribute("aria-expanded","false");return}a.setAttribute("aria-expanded","true");const c=document.createElement("pre");c.className="c-diff",c.textContent="Loading…",o.append(c);try{const{diff:h}=await He(As(t.id,`/diff?path=${encodeURIComponent(n.files[a.dataset.i].path)}`));c.innerHTML=h.split(`
4395
+ <span class="st ${qi(r,a.status)}">${r[qi(r,a.status)]||""}</span><span class="p" title="${lt(a.path)}">${lt(a.path)}</span>
4396
+ <span class="n">${a.binary?"binary":`<b class="add">+${ji(a.add)}</b> <b class="del">−${ji(a.del)}</b>`}</span>
4397
+ </button></li>`).join("")}${n.count>n.files.length?`<li class="more">and ${ji(n.count-n.files.length)} more</li>`:""}</ul>`:""}
4398
+ </div>`,e.querySelector(".c-head").onclick=()=>{this.changesOpen=s?null:t.id,this.renderChanges(t)},e.querySelectorAll(".c-file").forEach(a=>a.onclick=async()=>{const o=a.parentElement,l=o.querySelector("pre");if(l){l.remove(),a.setAttribute("aria-expanded","false");return}a.setAttribute("aria-expanded","true");const c=document.createElement("pre");c.className="c-diff",c.textContent="Loading…",o.append(c);try{const{diff:h}=await $e(Ns(t.id,`/diff?path=${encodeURIComponent(n.files[a.dataset.i].path)}`));c.innerHTML=h.split(`
4399
4399
  `).filter(u=>!/^(diff --git|index |--- |\+\+\+ )/.test(u)).map(u=>`<span class="${u[0]==="+"?"add":u[0]==="-"?"del":u[0]==="@"?"hunk":""}">${lt(u)||" "}</span>`).join(`
4400
- `)||"No textual changes."}catch(h){c.textContent=h.message}})}renderMeta(t){var a;const e=J("meta");if(!e||!t)return;const n=t.status==="working"||t.status==="queued"?Date.now():t.endedAt||Date.now(),s=[["Project",t.repo],...t.from&&!$t.on?[["From",`${t.from} (guest)`]]:[],["Agent",t.agentId?this.app.staffName(t.agentId):"Unassigned"],["Clearance",this.app.modes[t.mode]||t.mode],["Model",[F1(t.model),t.autoModel&&"chief’s pick",t.escalations?`moved up ${t.escalations}×`:""].filter(Boolean).join(" · ")],["Context",t.context?`${(t.context/1e3).toFixed(1)}k tokens`:"—"],["Time",t.startedAt?md(n-t.startedAt):"—"],["Cost",`$${(t.cost||0).toFixed(3)}`],["XP",t.xp?`+${t.xp}`:"—"]],r=(a=this.procs)==null?void 0:a[t.id];r&&(s.push(["CPU",r.cpu===null?"measuring…":`${Math.round(r.cpu)}%`]),s.push(["Memory",Ir(r.mem)]),s.push(["Processes",String(r.procs)])),e.innerHTML=s.map(([o,l])=>`<div><dt>${o}</dt><dd>${lt(l)}</dd></div>`).join("")}entry(t,e,n){const s=t.kind==="result"&&(n?n.kind==="text"&&n.summary===t.summary:(e==null?void 0:e.dataset.text)===t.summary);switch(t.kind){case"user":return`<div class="e user"><span class="who">You</span><p>${lt(t.summary)}</p></div>`;case"system":return`<div class="e sys">${lt(t.summary)}</div>`;case"thinking":return'<div class="e sys">thinking…</div>';case"tool":return`<div class="e tool"><span class="st ${Gi(Il,t.station)}" title="${Il[Gi(Il,t.station)]||""}"></span>${lt(t.summary)}</div>`;case"text":return`<div class="e text md" data-text="${lt(t.summary)}">${Dl(t.summary)}</div>`;case"error":return`<div class="e err">${lt(t.summary)}</div>`;case"result":return`<div class="e result ${t.ok?"ok":"bad"}"><span class="who">${t.ok?"Result":"Ended early"}${Vi(t.ms)?` · ${md(t.ms)}`:""}${Vi(t.cost)?` · $${t.cost.toFixed(3)}`:""}</span>${s?"":`<div class="md">${Dl(t.summary)}</div>`}</div>`;default:return""}}appendLog(t,e){if(t!==this.openId)return;const n=J("log");if(!n)return;const s=n.scrollHeight-n.scrollTop-n.clientHeight<60;n.insertAdjacentHTML("beforeend",this.entry(e,n.lastElementChild)),s&&(n.scrollTop=n.scrollHeight)}footer(t){var s;if(t.status==="working")return'<button class="ghost danger" data-act="stop">Stop work</button>';if(t.status==="queued")return'<button class="ghost danger" data-act="stop">Pull from queue</button>';const e=(s=t.denials)!=null&&s.length?`<div class="notice">Blocked from using <b>${t.denials.map(lt).join(", ")}</b>.
4400
+ `)||"No textual changes."}catch(h){c.textContent=h.message}})}renderMeta(t){var a;const e=q("meta");if(!e||!t)return;const n=t.status==="working"||t.status==="queued"?Date.now():t.endedAt||Date.now(),s=[["Project",t.repo],...t.from&&!Gt.on?[["From",`${t.from} (guest)`]]:[],["Agent",t.agentId?this.app.staffName(t.agentId):"Unassigned"],["Clearance",this.app.modes[t.mode]||t.mode],["Model",[d1(t.model),t.autoModel&&"chief’s pick",t.escalations?`moved up ${t.escalations}×`:""].filter(Boolean).join(" · ")],["Context",t.context?`${(t.context/1e3).toFixed(1)}k tokens`:"—"],["Time",t.startedAt?kd(n-t.startedAt):"—"],["Cost",`$${(t.cost||0).toFixed(3)}`],["XP",t.xp?`+${t.xp}`:"—"]],r=(a=this.procs)==null?void 0:a[t.id];r&&(s.push(["CPU",r.cpu===null?"measuring…":`${Math.round(r.cpu)}%`]),s.push(["Memory",Vr(r.mem)]),s.push(["Processes",String(r.procs)])),e.innerHTML=s.map(([o,l])=>`<div><dt>${o}</dt><dd>${lt(l)}</dd></div>`).join("")}entry(t,e,n){const s=t.kind==="result"&&(n?n.kind==="text"&&n.summary===t.summary:(e==null?void 0:e.dataset.text)===t.summary);switch(t.kind){case"user":return`<div class="e user"><span class="who">You</span><p>${lt(t.summary)}</p></div>`;case"system":return`<div class="e sys">${lt(t.summary)}</div>`;case"thinking":return'<div class="e sys">thinking…</div>';case"tool":return`<div class="e tool"><span class="st ${qi(Wl,t.station)}" title="${Wl[qi(Wl,t.station)]||""}"></span>${lt(t.summary)}</div>`;case"text":return`<div class="e text md" data-text="${lt(t.summary)}">${$l(t.summary)}</div>`;case"error":return`<div class="e err">${lt(t.summary)}</div>`;case"result":return`<div class="e result ${t.ok?"ok":"bad"}"><span class="who">${t.ok?"Result":"Ended early"}${ji(t.ms)?` · ${kd(t.ms)}`:""}${ji(t.cost)?` · $${t.cost.toFixed(3)}`:""}</span>${s?"":`<div class="md">${$l(t.summary)}</div>`}</div>`;default:return""}}appendLog(t,e){if(t!==this.openId)return;const n=q("log");if(!n)return;const s=n.scrollHeight-n.scrollTop-n.clientHeight<60;n.insertAdjacentHTML("beforeend",this.entry(e,n.lastElementChild)),s&&(n.scrollTop=n.scrollHeight)}footer(t){var s;if(t.status==="working")return'<button class="ghost danger" data-act="stop">Stop work</button>';if(t.status==="queued")return'<button class="ghost danger" data-act="stop">Pull from queue</button>';const e=(s=t.denials)!=null&&s.length?`<div class="notice">Blocked from using <b>${t.denials.map(lt).join(", ")}</b>.
4401
4401
  <button class="primary small" data-act="grant">Grant full autonomy and continue</button></div>`:"",n=t.mode==="plan"&&t.status==="done"?`<div class="notice">That's the plan. <button class="primary small" data-act="approve">Approve and build it</button></div>`:"";return`${e}${n}
4402
4402
  <form class="reply" data-act="reply">
4403
4403
  <div class="tray" hidden></div>
@@ -4410,29 +4410,29 @@ Please report this to https://github.com/markedjs/marked.`,t){const s="<p>An err
4410
4410
  <input type="file" multiple hidden />
4411
4411
  <button class="primary small" type="submit">Send</button>
4412
4412
  </div>
4413
- </form>`}bindFooter(t){const e=J("detail").querySelector(".d-foot"),n=async r=>{try{await r()}catch(a){this.toast(a.message,"bad")}};e.querySelectorAll('[data-act="stop"]').forEach(r=>r.onclick=()=>n(()=>He(As(t.id,"/stop"),{}))),e.querySelectorAll('[data-act="grant"]').forEach(r=>r.onclick=()=>n(()=>He(As(t.id,"/reply"),Ho("You now have permission to run the commands that were blocked. Carry on from where you stopped.","auto")))),e.querySelectorAll('[data-act="approve"]').forEach(r=>r.onclick=()=>n(()=>He(As(t.id,"/reply"),Ho("Approved. Go ahead and implement the plan.","edit"))));const s=e.querySelector("form.reply");if(s){const r=new vd(s.querySelector(".tray"),a=>this.toast(a,"bad"));_d(r,{zone:s,input:s.message,picker:s.querySelector("input[type=file]"),button:s.querySelector(".attach")}),s.onsubmit=a=>{a.preventDefault();const o=new FormData(s);n(async()=>{const l=await r.ids();await He(As(t.id,"/reply"),Ho(o.get("message"),o.get("mode"),l)),r.clear()})},s.message.onkeydown=a=>{a.key==="Enter"&&(a.metaKey||a.ctrlKey)&&s.requestSubmit()}}}tick(){const t=this.openId&&this.app.job(this.openId);t&&(t.status==="working"||t.status==="queued")&&this.renderMeta(t),this.usage&&this.renderUsage()}renderChannels(t){t&&(this.channels=t),this.channels.some(s=>s.id===this.channel)||(this.channel="general",this.thread=null,this.chat&&setTimeout(()=>this.paintChat()));const e=J("channels"),n=e.querySelector(".new-channel");e.innerHTML=this.channels.map(s=>{const r=this.unread.get(s.id)||0,a=s.id===this.channel,o=(s.members||[]).map(c=>this.app.person(c).name).join(", "),l=`#${s.name}${s.purpose?` — ${s.purpose}`:""}${o?`
4413
+ </form>`}bindFooter(t){const e=q("detail").querySelector(".d-foot"),n=async r=>{try{await r()}catch(a){this.toast(a.message,"bad")}};e.querySelectorAll('[data-act="stop"]').forEach(r=>r.onclick=()=>n(()=>$e(Ns(t.id,"/stop"),{}))),e.querySelectorAll('[data-act="grant"]').forEach(r=>r.onclick=()=>n(()=>$e(Ns(t.id,"/reply"),Jo("You now have permission to run the commands that were blocked. Carry on from where you stopped.","auto")))),e.querySelectorAll('[data-act="approve"]').forEach(r=>r.onclick=()=>n(()=>$e(Ns(t.id,"/reply"),Jo("Approved. Go ahead and implement the plan.","edit"))));const s=e.querySelector("form.reply");if(s){const r=new Ud(s.querySelector(".tray"),a=>this.toast(a,"bad"));Od(r,{zone:s,input:s.message,picker:s.querySelector("input[type=file]"),button:s.querySelector(".attach")}),s.onsubmit=a=>{a.preventDefault();const o=new FormData(s);n(async()=>{const l=await r.ids();await $e(Ns(t.id,"/reply"),Jo(o.get("message"),o.get("mode"),l)),r.clear()})},s.message.onkeydown=a=>{a.key==="Enter"&&(a.metaKey||a.ctrlKey)&&s.requestSubmit()}}}tick(){const t=this.openId&&this.app.job(this.openId);t&&(t.status==="working"||t.status==="queued")&&this.renderMeta(t),this.usage&&this.renderUsage()}renderChannels(t){t&&(this.channels=t),this.channels.some(s=>s.id===this.channel)||(this.channel="general",this.thread=null,this.chat&&setTimeout(()=>this.paintChat()));const e=q("channels"),n=e.querySelector(".new-channel");e.innerHTML=this.channels.map(s=>{const r=this.unread.get(s.id)||0,a=s.id===this.channel,o=(s.members||[]).map(c=>this.app.person(c).name).join(", "),l=`#${s.name}${s.purpose?` — ${s.purpose}`:""}${o?`
4414
4414
  In it: ${o}`:""}`;return`<button type="button" role="tab" aria-selected="${a}" class="channel ${a?"on":""}" data-channel="${lt(s.id)}" title="${lt(l)}">
4415
- <span class="hash">#</span>${lt(s.name)}${r&&!a?`<span class="badge">${r>99?"99+":r}</span>`:""}</button>`}).join("")+(this.channel==="general"?"":`<button type="button" class="channel close" data-close-channel="${lt(this.channel)}" aria-label="Close this channel" title="Close this channel">×</button>`)+'<button type="button" class="channel add" data-new-channel aria-label="New channel" title="New channel">+</button>',n&&e.append(n),this.setPlaceholder()}setPlaceholder(){$t.on||(J("input").placeholder=`Message #${this.channel} · @agent #project`)}selectChannel(t){this.channels.some(e=>e.id===t)&&(this.channel=t,this.unread.delete(t),Ba("office.channel",t),this.thread=null,this.renderChannels(),this.paintChat(),this.tab("chat"))}bindChannels(){J("channels").onclick=t=>{const e=t.target.closest("[data-close-channel]");if(e)return this.deleteChannel(e.dataset.closeChannel);const n=t.target.closest("[data-channel]");if(n)return this.selectChannel(n.dataset.channel);t.target.closest("[data-new-channel]")&&this.newChannel()}}newChannel(){const t=J("channels");if(t.querySelector(".new-channel"))return t.querySelector(".new-channel input").focus();const e=document.createElement("form");e.className="new-channel",e.innerHTML='<span class="hash">#</span><input maxlength="24" placeholder="new-channel" aria-label="Channel name" />';const n=()=>e.remove();e.onsubmit=async s=>{s.preventDefault();const r=e.querySelector("input").value.trim();if(!r)return n();try{const a=await He("/api/channels",{name:r});n(),this.selectChannel(a.id)}catch(a){this.toast(a.message,"bad"),e.querySelector("input").select()}},e.querySelector("input").onkeydown=s=>{s.key==="Escape"&&(s.preventDefault(),n())},e.querySelector("input").onblur=()=>setTimeout(()=>{var s;(s=e.querySelector("input"))!=null&&s.value.trim()||n()},120),t.append(e),e.querySelector("input").focus()}async deleteChannel(t){try{await He(`/api/channels/${encodeURIComponent(t)}`,void 0,"DELETE"),this.toast(`#${t} closed`,"good")}catch(e){this.toast(e.message,"bad")}}mobile(t){J("app").dataset.m=t==="office"?"office":"side",t==="chat"&&(J("mChatDot").hidden=!0),document.querySelectorAll("#mnav button").forEach(e=>e.classList.toggle("on",e.dataset.m===t))}tab(t){this.mobile(t),document.querySelectorAll(".tabs button").forEach(e=>e.classList.toggle("on",e.dataset.tab===t)),J("chatPane").hidden=t!=="chat"||!!this.thread,J("threadPane").hidden=t!=="chat"||!this.thread,J("jobsPane").hidden=t!=="jobs",J("teamPane").hidden=t!=="team",J("projectsPane").hidden=t!=="projects",t==="team"&&this.renderTeam(),t==="projects"&&this.loadProjects(),t==="chat"&&this.scrollChat(!0)}focusInput(t=""){this.thread=null,this.tab("chat");const e=J("input");t&&!e.value.includes(t.trim())&&(e.value=t+e.value),e.focus(),e.setSelectionRange(e.value.length,e.value.length),this.autosize()}bindChat(){const t=J("input");for(const n of["mode","model"]){const s=Ba(`office.${n}`);s!==null&&[...J(n).options].some(r=>r.value===s)&&(J(n).value=s),J(n).onchange=()=>Ba(`office.${n}`,J(n).value)}J("composer").onsubmit=n=>{n.preventDefault(),this.send()},this.tray=new vd(J("tray"),n=>this.toast(n,"bad")),_d(this.tray,{zone:J("composer"),input:t,picker:J("file"),button:J("attach")}),this.bindVoice(),t.oninput=()=>{this.autosize(),this.suggest()},t.onclick=()=>this.suggest(),t.onblur=()=>setTimeout(()=>J("ac").hidden=!0,120),t.onkeydown=n=>{const s=J("ac");if(!s.hidden){const r=[...s.children],a=r.findIndex(o=>o.classList.contains("on"));if(n.key==="ArrowDown"||n.key==="ArrowUp"){n.preventDefault();const o=(a+(n.key==="ArrowDown"?1:-1)+r.length)%r.length;r.forEach((l,c)=>l.classList.toggle("on",c===o));return}if(n.key==="Enter"||n.key==="Tab"){n.preventDefault(),this.pick(r[Math.max(0,a)]);return}if(n.key==="Escape"){n.preventDefault(),s.hidden=!0;return}}n.key==="Enter"&&!n.shiftKey&&!n.isComposing&&(n.preventDefault(),this.send())},J("ac").onmousedown=n=>{const s=n.target.closest("[data-insert]");s&&(n.preventDefault(),this.pick(s))};const e=J("threadInput");J("threadComposer").onsubmit=n=>{n.preventDefault(),this.sendThread()},J("threadBack").onclick=()=>this.closeThread(),e.oninput=()=>this.autosize(e),e.onkeydown=n=>{if(n.key==="Escape"){n.preventDefault(),this.closeThread();return}n.key==="Enter"&&!n.shiftKey&&!n.isComposing&&(n.preventDefault(),this.sendThread())},J("msgs").onclick=J("threadMsgs").onclick=n=>{const s=n.target.closest("[data-thread]");if(s)return this.openThread(s.dataset.thread);const r=n.target.closest("[data-pick]");if(r)return this.openPicker(r);const a=n.target.closest("[data-react]");if(a)return this.react(a.closest(".msg").dataset.id,a.dataset.react);const o=n.target.closest("[data-say]");if(o){const u=this.chat.get(o.closest(".msg").dataset.id);ai.stop(),u&&ai.speak(u.text,u.from,{force:!0});return}const l=n.target.closest("[data-open]");if(l)return this.app.openJob(l.dataset.open);const c=n.target.closest("[data-more]");if(c){c.closest(".msg").classList.add("full"),c.remove();return}const h=n.target.closest("[data-grant]");h&&He(`/api/jobs/${h.dataset.grant}/reply`,{message:"You now have permission to run the commands that were blocked. Carry on from where you stopped.",mode:"auto"}).then(()=>h.remove(),u=>this.toast(u.message,"bad"))}}autosize(t=J("input")){t.style.height="auto",t.style.height=Math.min(t.scrollHeight,140)+"px"}bindVoice(){const t=J("mic"),e=J("rec"),n=J("recText");if(!Qn.supported){t.hidden=!0;return}let s=null;const r=h=>{e.hidden=h==="idle",e.classList.toggle("working",h==="working"),t.classList.toggle("on",h==="recording"),t.disabled=h==="working",J("recStop").hidden=J("recDrop").hidden=h!=="recording",h==="working"&&(n.textContent="Transcribing…")},a=()=>{const h=Math.floor((Date.now()-Qn.startedAt)/1e3);n.textContent=`Recording ${Math.floor(h/60)}:${String(h%60).padStart(2,"0")}`},o=async()=>{const h=this.app.voice;if(h&&!h.ok)return this.toast(h.reason,"bad");try{await Qn.start()}catch(u){return this.toast(u.name==="NotAllowedError"?"The browser is blocking the microphone. Allow it for this page and try again.":`No microphone here: ${u.message}`,"bad")}ai.stop(),r("recording"),a(),s=setInterval(a,500)},l=async()=>{clearInterval(s);const h=await Qn.stop();if(!h)return r("idle");r("working");try{const u=k1(h),d=await fetch("/api/voice",{method:"POST",headers:{"x-file-name":encodeURIComponent(u.name),"content-type":u.type||"audio/webm"},body:u}),f=await d.json().catch(()=>({}));if(!d.ok)throw new Error(f.error||`Transcribing failed (${d.status})`);this.tray.attach(f);const g=J("input");f.text?g.value=g.value.trim()?`${g.value.trim()} ${f.text}`:f.text:this.toast("I couldn't make out any words in that one — it's attached if you want to send it anyway.","bad"),g.focus(),g.setSelectionRange(g.value.length,g.value.length),this.autosize()}catch(u){this.toast(u.message,"bad")}r("idle")},c=()=>{clearInterval(s),Qn.cancel(),r("idle")};t.onclick=()=>Qn.active?l():o(),J("recStop").onclick=l,J("recDrop").onclick=c,addEventListener("keydown",h=>{if(h.key==="Escape"&&Qn.active)return h.preventDefault(),c();h.altKey&&/^(m|µ)$/i.test(h.key)&&(h.preventDefault(),Qn.active?l():o())}),r("idle")}async send(){const t=J("input"),e=t.value.trim();if(!(!e&&this.tray.empty||this.sending)){this.sending=!0,t.value="",this.autosize(),J("ac").hidden=!0;try{const n=await this.tray.ids();if(!e&&!n.length)return;if($t.on){const s=await $p({text:e,mode:J("mode").value,model:J("model").value});s&&(this.app.jobs.set(s.id,s),this.app.refreshLists(),this.app.openJob(s.id));return}await He("/api/chat",{text:e,files:n,channel:this.channel,mode:J("mode").value,model:J("model").value}),this.tray.clear()}catch(n){t.value=e,this.toast(n.message,"bad")}finally{this.sending=!1}}}async suggest(){const t=J("input"),n=t.value.slice(0,t.selectionStart).match(/(^|\s)([@#])([\w.-]*)$/),s=J("ac");if(!n){s.hidden=!0;return}const[,,r,a]=n,o=a.toLowerCase().replace(/[^a-z0-9]/g,"");let l;if(r==="@")l=this.app.roster().map(c=>({insert:`@${c.name}`,label:c.name,note:c.note,dot:c.color}));else{if(!this.repos)try{this.repos=$h((await He("/api/repos")).repos)}catch{this.repos=[]}l=this.repos.map(c=>({insert:`#${c.replace(/\s+/g,"-")}`,label:c,note:this.app.busyIn(c)}))}if(l=l.filter(c=>c.label.toLowerCase().replace(/[^a-z0-9]/g,"").includes(o)).sort((c,h)=>c.label.toLowerCase().replace(/[^a-z0-9]/g,"").indexOf(o)-h.label.toLowerCase().replace(/[^a-z0-9]/g,"").indexOf(o)).slice(0,8),!l.length){s.hidden=!0;return}s.innerHTML=l.map((c,h)=>`
4415
+ <span class="hash">#</span>${lt(s.name)}${r&&!a?`<span class="badge">${r>99?"99+":r}</span>`:""}</button>`}).join("")+(this.channel==="general"?"":`<button type="button" class="channel close" data-close-channel="${lt(this.channel)}" aria-label="Close this channel" title="Close this channel">×</button>`)+'<button type="button" class="channel add" data-new-channel aria-label="New channel" title="New channel">+</button>',n&&e.append(n),this.setPlaceholder()}setPlaceholder(){Gt.on||(q("input").placeholder=`Message #${this.channel} · @agent #project`)}selectChannel(t){this.channels.some(e=>e.id===t)&&(this.channel=t,this.unread.delete(t),Ya("office.channel",t),this.thread=null,this.renderChannels(),this.paintChat(),this.tab("chat"))}bindChannels(){q("channels").onclick=t=>{const e=t.target.closest("[data-close-channel]");if(e)return this.deleteChannel(e.dataset.closeChannel);const n=t.target.closest("[data-channel]");if(n)return this.selectChannel(n.dataset.channel);t.target.closest("[data-new-channel]")&&this.newChannel()}}newChannel(){const t=q("channels");if(t.querySelector(".new-channel"))return t.querySelector(".new-channel input").focus();const e=document.createElement("form");e.className="new-channel",e.innerHTML='<span class="hash">#</span><input maxlength="24" placeholder="new-channel" aria-label="Channel name" />';const n=()=>e.remove();e.onsubmit=async s=>{s.preventDefault();const r=e.querySelector("input").value.trim();if(!r)return n();try{const a=await $e("/api/channels",{name:r});n(),this.selectChannel(a.id)}catch(a){this.toast(a.message,"bad"),e.querySelector("input").select()}},e.querySelector("input").onkeydown=s=>{s.key==="Escape"&&(s.preventDefault(),n())},e.querySelector("input").onblur=()=>setTimeout(()=>{var s;(s=e.querySelector("input"))!=null&&s.value.trim()||n()},120),t.append(e),e.querySelector("input").focus()}async deleteChannel(t){try{await $e(`/api/channels/${encodeURIComponent(t)}`,void 0,"DELETE"),this.toast(`#${t} closed`,"good")}catch(e){this.toast(e.message,"bad")}}mobile(t){q("app").dataset.m=t==="office"?"office":"side",t==="chat"&&(q("mChatDot").hidden=!0),document.querySelectorAll("#mnav button").forEach(e=>e.classList.toggle("on",e.dataset.m===t))}tab(t){this.mobile(t),document.querySelectorAll(".tabs button").forEach(e=>e.classList.toggle("on",e.dataset.tab===t)),q("chatPane").hidden=t!=="chat"||!!this.thread,q("threadPane").hidden=t!=="chat"||!this.thread,q("jobsPane").hidden=t!=="jobs",q("teamPane").hidden=t!=="team",q("projectsPane").hidden=t!=="projects",t==="team"&&this.renderTeam(),t==="projects"&&this.loadProjects(),t==="chat"&&this.scrollChat(!0)}focusInput(t=""){this.thread=null,this.tab("chat");const e=q("input");t&&!e.value.includes(t.trim())&&(e.value=t+e.value),e.focus(),e.setSelectionRange(e.value.length,e.value.length),this.autosize()}bindChat(){const t=q("input");for(const n of["mode","model"]){const s=Ya(`office.${n}`);s!==null&&[...q(n).options].some(r=>r.value===s)&&(q(n).value=s),q(n).onchange=()=>Ya(`office.${n}`,q(n).value)}q("composer").onsubmit=n=>{n.preventDefault(),this.send()},this.tray=new Ud(q("tray"),n=>this.toast(n,"bad")),Od(this.tray,{zone:q("composer"),input:t,picker:q("file"),button:q("attach")}),this.bindVoice(),t.oninput=()=>{this.autosize(),this.suggest()},t.onclick=()=>this.suggest(),t.onblur=()=>setTimeout(()=>q("ac").hidden=!0,120),t.onkeydown=n=>{const s=q("ac");if(!s.hidden){const r=[...s.children],a=r.findIndex(o=>o.classList.contains("on"));if(n.key==="ArrowDown"||n.key==="ArrowUp"){n.preventDefault();const o=(a+(n.key==="ArrowDown"?1:-1)+r.length)%r.length;r.forEach((l,c)=>l.classList.toggle("on",c===o));return}if(n.key==="Enter"||n.key==="Tab"){n.preventDefault(),this.pick(r[Math.max(0,a)]);return}if(n.key==="Escape"){n.preventDefault(),s.hidden=!0;return}}n.key==="Enter"&&!n.shiftKey&&!n.isComposing&&(n.preventDefault(),this.send())},q("ac").onmousedown=n=>{const s=n.target.closest("[data-insert]");s&&(n.preventDefault(),this.pick(s))};const e=q("threadInput");q("threadComposer").onsubmit=n=>{n.preventDefault(),this.sendThread()},q("threadBack").onclick=()=>this.closeThread(),e.oninput=()=>this.autosize(e),e.onkeydown=n=>{if(n.key==="Escape"){n.preventDefault(),this.closeThread();return}n.key==="Enter"&&!n.shiftKey&&!n.isComposing&&(n.preventDefault(),this.sendThread())},q("msgs").onclick=q("threadMsgs").onclick=n=>{const s=n.target.closest("[data-thread]");if(s)return this.openThread(s.dataset.thread);const r=n.target.closest("[data-pick]");if(r)return this.openPicker(r);const a=n.target.closest("[data-react]");if(a)return this.react(a.closest(".msg").dataset.id,a.dataset.react);const o=n.target.closest("[data-say]");if(o){const u=this.chat.get(o.closest(".msg").dataset.id);hi.stop(),u&&hi.speak(u.text,u.from,{force:!0});return}const l=n.target.closest("[data-open]");if(l)return this.app.openJob(l.dataset.open);const c=n.target.closest("[data-more]");if(c){c.closest(".msg").classList.add("full"),c.remove();return}const h=n.target.closest("[data-grant]");h&&$e(`/api/jobs/${h.dataset.grant}/reply`,{message:"You now have permission to run the commands that were blocked. Carry on from where you stopped.",mode:"auto"}).then(()=>h.remove(),u=>this.toast(u.message,"bad"))}}autosize(t=q("input")){t.style.height="auto",t.style.height=Math.min(t.scrollHeight,140)+"px"}bindVoice(){const t=q("mic"),e=q("rec"),n=q("recText");if(!ii.supported){t.hidden=!0;return}let s=null;const r=h=>{e.hidden=h==="idle",e.classList.toggle("working",h==="working"),t.classList.toggle("on",h==="recording"),t.disabled=h==="working",q("recStop").hidden=q("recDrop").hidden=h!=="recording",h==="working"&&(n.textContent="Transcribing…")},a=()=>{const h=Math.floor((Date.now()-ii.startedAt)/1e3);n.textContent=`Recording ${Math.floor(h/60)}:${String(h%60).padStart(2,"0")}`},o=async()=>{const h=this.app.voice;if(h&&!h.ok)return this.toast(h.reason,"bad");try{await ii.start()}catch(u){return this.toast(u.name==="NotAllowedError"?"The browser is blocking the microphone. Allow it for this page and try again.":`No microphone here: ${u.message}`,"bad")}hi.stop(),r("recording"),a(),s=setInterval(a,500)},l=async()=>{clearInterval(s);const h=await ii.stop();if(!h)return r("idle");r("working");try{const u=l1(h),d=await fetch("/api/voice",{method:"POST",headers:{"x-file-name":encodeURIComponent(u.name),"content-type":u.type||"audio/webm"},body:u}),f=await d.json().catch(()=>({}));if(!d.ok)throw new Error(f.error||`Transcribing failed (${d.status})`);this.tray.attach(f);const g=q("input");f.text?g.value=g.value.trim()?`${g.value.trim()} ${f.text}`:f.text:this.toast("I couldn't make out any words in that one — it's attached if you want to send it anyway.","bad"),g.focus(),g.setSelectionRange(g.value.length,g.value.length),this.autosize()}catch(u){this.toast(u.message,"bad")}r("idle")},c=()=>{clearInterval(s),ii.cancel(),r("idle")};t.onclick=()=>ii.active?l():o(),q("recStop").onclick=l,q("recDrop").onclick=c,addEventListener("keydown",h=>{if(h.key==="Escape"&&ii.active)return h.preventDefault(),c();h.altKey&&/^(m|µ)$/i.test(h.key)&&(h.preventDefault(),ii.active?l():o())}),r("idle")}async send(){const t=q("input"),e=t.value.trim();if(!(!e&&this.tray.empty||this.sending)){this.sending=!0,t.value="",this.autosize(),q("ac").hidden=!0;try{const n=await this.tray.ids();if(!e&&!n.length)return;if(Gt.on){const s=await cm({text:e,mode:q("mode").value,model:q("model").value});s&&(this.app.jobs.set(s.id,s),this.app.refreshLists(),this.app.openJob(s.id));return}await $e("/api/chat",{text:e,files:n,channel:this.channel,mode:q("mode").value,model:q("model").value}),this.tray.clear()}catch(n){t.value=e,this.toast(n.message,"bad")}finally{this.sending=!1}}}async suggest(){const t=q("input"),n=t.value.slice(0,t.selectionStart).match(/(^|\s)([@#])([\w.-]*)$/),s=q("ac");if(!n){s.hidden=!0;return}const[,,r,a]=n,o=a.toLowerCase().replace(/[^a-z0-9]/g,"");let l;if(r==="@")l=this.app.roster().map(c=>({insert:`@${c.name}`,label:c.name,note:c.note,dot:c.color}));else{if(!this.repos)try{this.repos=su((await $e("/api/repos")).repos)}catch{this.repos=[]}l=this.repos.map(c=>({insert:`#${c.replace(/\s+/g,"-")}`,label:c,note:this.app.busyIn(c)}))}if(l=l.filter(c=>c.label.toLowerCase().replace(/[^a-z0-9]/g,"").includes(o)).sort((c,h)=>c.label.toLowerCase().replace(/[^a-z0-9]/g,"").indexOf(o)-h.label.toLowerCase().replace(/[^a-z0-9]/g,"").indexOf(o)).slice(0,8),!l.length){s.hidden=!0;return}s.innerHTML=l.map((c,h)=>`
4416
4416
  <div class="item ${h===0?"on":""}" data-insert="${lt(c.insert)}" data-len="${a.length+1}">
4417
- ${c.dot?`<i style="background:${js(c.dot)}"></i>`:'<i class="hash">#</i>'}
4417
+ ${c.dot?`<i style="background:${er(c.dot)}"></i>`:'<i class="hash">#</i>'}
4418
4418
  <span>${lt(c.label)}</span>${c.note?`<em>${lt(c.note)}</em>`:""}
4419
- </div>`).join(""),s.hidden=!1}pick(t){if(!t)return;const e=J("input"),n=e.selectionStart,s=n-Number(t.dataset.len);e.value=e.value.slice(0,s)+t.dataset.insert+" "+e.value.slice(n);const r=s+t.dataset.insert.length+1;e.setSelectionRange(r,r),J("ac").hidden=!0,e.focus()}renderChat(t){this.chat=new Map(t.map(e=>[e.id,e])),this.unread.clear(),this.renderChannels(),this.paintChat()}paintChat(){var e,n;const t=[...this.chat.values()].filter(s=>this.here(s)&&!this.inThread(s));J("msgs").innerHTML=t.length?t.map(s=>this.message(s)).join(""):`<p class="empty">${$t.on?`Start a job${$t.host?` at @${lt($t.host)}`:""}: say what you need and tag ${((e=$t.repos)==null?void 0:e.length)===1?"the project":"one of your projects"} with #${(n=$t.repos)!=null&&n.length?` (${$t.repos.map(s=>lt(`#${s.replace(/\s+/g,"-")}`)).join(", ")})`:""}. Only your own jobs show here.`:this.channel==="general"?"Tell the office what you need. Tag someone with @, or a project with #. The chief of staff hands everything else to whoever fits.":`Nothing in #${lt(this.channel)} yet. Whatever you ask for here stays here.`}</p>`,this.scrollChat(!0),this.thread&&this.renderThread()}here(t){return(t.channel||"general")===this.channel}inThread(t){return!!t.thread&&this.chat.has(t.thread)}replies(t){return[...this.chat.values()].filter(e=>e.thread===t)}addMessage(t){var s;if(this.chat.set(t.id,t),t.from!=="you"&&J("app").dataset.m==="office"&&(J("mChatDot").hidden=!1),!this.here(t)){const r=t.channel||"general";this.unread.set(r,(this.unread.get(r)||0)+1),this.renderChannels();return}if(this.inThread(t)){if(this.updateThreadSum(t.thread),this.thread===t.thread){const r=J("threadMsgs");r.insertAdjacentHTML("beforeend",this.message(t,!0)),r.querySelector(".thread-count").textContent=this.countLabel(this.replies(t.thread).length),requestAnimationFrame(()=>r.scrollTop=r.scrollHeight)}return}const e=J("msgs"),n=e.scrollHeight-e.scrollTop-e.clientHeight<80;(s=e.querySelector(".empty"))==null||s.remove(),e.insertAdjacentHTML("beforeend",this.message(t)),(n||t.from==="you")&&this.scrollChat(!0)}scrollChat(){const t=J("msgs");requestAnimationFrame(()=>t.scrollTop=t.scrollHeight)}openThread(t){if(!this.chat.has(t))return;const e=this.chat.get(t);this.here(e)||this.selectChannel(e.channel||"general"),this.thread=t,this.renderThread(),this.tab("chat"),J("threadInput").focus()}closeThread(){this.thread=null,this.tab("chat"),J("input").focus()}renderThread(){const t=this.chat.get(this.thread);if(!t)return this.closeThread();const e=this.replies(t.id);J("threadWhere").textContent=`Thread on ${this.app.person(t.from).name}'s message · #${t.channel||"general"}`;const n=J("threadMsgs");n.innerHTML=this.message(t,!0)+`<p class="thread-count">${this.countLabel(e.length)}</p>`+e.map(s=>this.message(s,!0)).join(""),requestAnimationFrame(()=>n.scrollTop=n.scrollHeight)}countLabel(t){return t?`${t} ${t===1?"reply":"replies"}`:"No replies yet"}updateThreadSum(t){var n;const e=J("msgs").querySelector(`.msg[data-id="${CSS.escape(t)}"]`);e&&((n=e.querySelector(".thread-sum"))==null||n.remove(),e.querySelector(".reacts").insertAdjacentHTML("beforebegin",this.threadSum(this.chat.get(t))))}threadSum(t){const e=this.replies(t.id);if(!e.length)return"";const n=e.at(-1),s=[...new Set(e.map(a=>a.from))].slice(-3).map(a=>`<i style="background:${js(this.app.person(a).color)}"></i>`).join(""),r=n.text.replace(/[*_`#>]/g,"").replace(/\s+/g," ").trim();return`
4419
+ </div>`).join(""),s.hidden=!1}pick(t){if(!t)return;const e=q("input"),n=e.selectionStart,s=n-Number(t.dataset.len);e.value=e.value.slice(0,s)+t.dataset.insert+" "+e.value.slice(n);const r=s+t.dataset.insert.length+1;e.setSelectionRange(r,r),q("ac").hidden=!0,e.focus()}renderChat(t){this.chat=new Map(t.map(e=>[e.id,e])),this.unread.clear(),this.renderChannels(),this.paintChat()}paintChat(){var e,n;const t=[...this.chat.values()].filter(s=>this.here(s)&&!this.inThread(s));q("msgs").innerHTML=t.length?t.map(s=>this.message(s)).join(""):`<p class="empty">${Gt.on?`Start a job${Gt.host?` at @${lt(Gt.host)}`:""}: say what you need and tag ${((e=Gt.repos)==null?void 0:e.length)===1?"the project":"one of your projects"} with #${(n=Gt.repos)!=null&&n.length?` (${Gt.repos.map(s=>lt(`#${s.replace(/\s+/g,"-")}`)).join(", ")})`:""}. Only your own jobs show here.`:this.channel==="general"?"Tell the office what you need. Tag someone with @, or a project with #. The chief of staff hands everything else to whoever fits.":`Nothing in #${lt(this.channel)} yet. Whatever you ask for here stays here.`}</p>`,this.scrollChat(!0),this.thread&&this.renderThread()}here(t){return(t.channel||"general")===this.channel}inThread(t){return!!t.thread&&this.chat.has(t.thread)}replies(t){return[...this.chat.values()].filter(e=>e.thread===t)}addMessage(t){var s;if(this.chat.set(t.id,t),t.from!=="you"&&q("app").dataset.m==="office"&&(q("mChatDot").hidden=!1),!this.here(t)){const r=t.channel||"general";this.unread.set(r,(this.unread.get(r)||0)+1),this.renderChannels();return}if(this.inThread(t)){if(this.updateThreadSum(t.thread),this.thread===t.thread){const r=q("threadMsgs");r.insertAdjacentHTML("beforeend",this.message(t,!0)),r.querySelector(".thread-count").textContent=this.countLabel(this.replies(t.thread).length),requestAnimationFrame(()=>r.scrollTop=r.scrollHeight)}return}const e=q("msgs"),n=e.scrollHeight-e.scrollTop-e.clientHeight<80;(s=e.querySelector(".empty"))==null||s.remove(),e.insertAdjacentHTML("beforeend",this.message(t)),(n||t.from==="you")&&this.scrollChat(!0)}scrollChat(){const t=q("msgs");requestAnimationFrame(()=>t.scrollTop=t.scrollHeight)}openThread(t){if(!this.chat.has(t))return;const e=this.chat.get(t);this.here(e)||this.selectChannel(e.channel||"general"),this.thread=t,this.renderThread(),this.tab("chat"),q("threadInput").focus()}closeThread(){this.thread=null,this.tab("chat"),q("input").focus()}renderThread(){const t=this.chat.get(this.thread);if(!t)return this.closeThread();const e=this.replies(t.id);q("threadWhere").textContent=`Thread on ${this.app.person(t.from).name}'s message · #${t.channel||"general"}`;const n=q("threadMsgs");n.innerHTML=this.message(t,!0)+`<p class="thread-count">${this.countLabel(e.length)}</p>`+e.map(s=>this.message(s,!0)).join(""),requestAnimationFrame(()=>n.scrollTop=n.scrollHeight)}countLabel(t){return t?`${t} ${t===1?"reply":"replies"}`:"No replies yet"}updateThreadSum(t){var n;const e=q("msgs").querySelector(`.msg[data-id="${CSS.escape(t)}"]`);e&&((n=e.querySelector(".thread-sum"))==null||n.remove(),e.querySelector(".reacts").insertAdjacentHTML("beforebegin",this.threadSum(this.chat.get(t))))}threadSum(t){const e=this.replies(t.id);if(!e.length)return"";const n=e.at(-1),s=[...new Set(e.map(a=>a.from))].slice(-3).map(a=>`<i style="background:${er(this.app.person(a).color)}"></i>`).join(""),r=n.text.replace(/[*_`#>]/g,"").replace(/\s+/g," ").trim();return`
4420
4420
  <button type="button" class="thread-sum" data-thread="${lt(t.id)}">
4421
4421
  <span class="faces">${s}</span><b>${this.countLabel(e.length)}</b>
4422
4422
  <span class="last">${lt(this.app.person(n.from).name)}: ${lt(r.length>70?r.slice(0,69)+"…":r)}</span>
4423
- </button>`}async sendThread(){const t=J("threadInput"),e=t.value.trim();if(!(!e||this.sending||!this.thread)){this.sending=!0,t.value="",this.autosize(t);try{await He("/api/chat",{text:e,thread:this.thread,mode:J("mode").value,model:J("model").value})}catch(n){t.value=e,this.toast(n.message,"bad")}finally{this.sending=!1}}}message(t,e=!1){var c,h;const n=this.app.person(t.from),s=t.to&&this.app.person(t.to),r=new Date(t.ts).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),a=t.from==="you"?`<p>${lt(t.text).replace(/(^|\s)([@#][\w.-]+)/g,'$1<span class="tag">$2</span>')}</p>`:Dl(t.text),o=t.from!=="you"&&t.from!=="chief"&&!t.to&&t.text.length>420,l=[o?`<button type="button" class="icon" data-more aria-label="Show all" title="Show all">${Va.more}</button>`:"",t.jobId&&t.from!=="you"?`<button type="button" class="icon" data-open="${t.jobId}" aria-label="Open job" title="Open job">${Va.open}</button>`:"",!e&&t.threadOf&&this.chat.has(t.threadOf)?`<button type="button" class="link" data-thread="${lt(t.threadOf)}">Updates are in this thread →</button>`:"",e?"":`<button type="button" class="icon quiet" data-thread="${lt(t.id)}" aria-label="Reply in thread" title="Reply in thread">${Va.reply}</button>`,t.from!=="you"&&t.text&&ai.supported?`<button type="button" class="icon quiet" data-say aria-label="Read aloud" title="Read aloud">${Va.speak}</button>`:"",(c=t.denials)!=null&&c.length?`<button type="button" class="primary small" data-grant="${t.jobId}">Grant full autonomy and continue</button>`:""].filter(Boolean).join("");return`
4423
+ </button>`}async sendThread(){const t=q("threadInput"),e=t.value.trim();if(!(!e||this.sending||!this.thread)){this.sending=!0,t.value="",this.autosize(t);try{await $e("/api/chat",{text:e,thread:this.thread,mode:q("mode").value,model:q("model").value})}catch(n){t.value=e,this.toast(n.message,"bad")}finally{this.sending=!1}}}message(t,e=!1){var c,h;const n=this.app.person(t.from),s=t.to&&this.app.person(t.to),r=new Date(t.ts).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),a=t.from==="you"?`<p>${lt(t.text).replace(/(^|\s)([@#][\w.-]+)/g,'$1<span class="tag">$2</span>')}</p>`:$l(t.text),o=t.from!=="you"&&t.from!=="chief"&&!t.to&&t.text.length>420,l=[o?`<button type="button" class="icon" data-more aria-label="Show all" title="Show all">${Za.more}</button>`:"",t.jobId&&t.from!=="you"?`<button type="button" class="icon" data-open="${t.jobId}" aria-label="Open job" title="Open job">${Za.open}</button>`:"",!e&&t.threadOf&&this.chat.has(t.threadOf)?`<button type="button" class="link" data-thread="${lt(t.threadOf)}">Updates are in this thread →</button>`:"",e?"":`<button type="button" class="icon quiet" data-thread="${lt(t.id)}" aria-label="Reply in thread" title="Reply in thread">${Za.reply}</button>`,t.from!=="you"&&t.text&&hi.supported?`<button type="button" class="icon quiet" data-say aria-label="Read aloud" title="Read aloud">${Za.speak}</button>`:"",(c=t.denials)!=null&&c.length?`<button type="button" class="primary small" data-grant="${t.jobId}">Grant full autonomy and continue</button>`:""].filter(Boolean).join("");return`
4424
4424
  <div data-id="${lt(t.id)}" class="msg from-${t.from==="you"?"you":t.from==="chief"?"chief":"agent"} ${t.kind||""} ${t.status||""} ${o?"clamp":""}">
4425
- <div class="who"><i style="background:${js(n.color)}"></i><b>${lt(n.name)}</b>${s?`<span class="arrow">→</span><i style="background:${js(s.color)}"></i><b>${lt(s.name)}</b>`:""}<time>${r}</time></div>
4425
+ <div class="who"><i style="background:${er(n.color)}"></i><b>${lt(n.name)}</b>${s?`<span class="arrow">→</span><i style="background:${er(s.color)}"></i><b>${lt(s.name)}</b>`:""}<time>${r}</time></div>
4426
4426
  ${t.kind==="handoff"?`<p class="kind">Handed off · ${lt(t.project||"")}</p>`:""}
4427
4427
  ${t.kind==="standup"&&t.from!=="chief"?'<p class="kind">Standup</p>':""}
4428
4428
  ${t.text?`<div class="body md">${a}</div>`:""}
4429
- ${xd(t.files)}
4429
+ ${Fd(t.files)}
4430
4430
  ${(h=t.denials)!=null&&h.length?`<p class="blocked">Blocked from using ${t.denials.map(lt).join(", ")}.</p>`:""}
4431
4431
  ${l?`<div class="acts">${l}</div>`:""}
4432
4432
  ${e?"":this.threadSum(t)}
4433
4433
  ${this.reactionRow(t)}
4434
- </div>`}reactionRow(t){const e=Object.entries(t.reactions||{}),n=e.map(([s,r])=>{const a=r.map(o=>this.app.person(o).name).join(", ");return`<button type="button" class="pill ${r.includes("you")?"mine":""}" data-react="${lt(s)}" title="${lt(a)}">${lt(s)}<span>${r.length}</span></button>`}).join("");return`<div class="reacts ${e.length?"some":""}">${n}<button type="button" class="add" data-pick aria-label="Add reaction" aria-haspopup="dialog" title="React">☺︎+</button></div>`}react(t,e){He(`/api/chat/${t}/react`,{emoji:e}).catch(n=>this.toast(n.message,"bad"))}openPicker(t){var l;const e=t.closest(".msg").dataset.id;let n=J("emojiPicker");if((n==null?void 0:n.dataset.for)===e)return this.closePicker();n||(n=document.createElement("div"),n.id="emojiPicker",n.className="emoji-picker",n.setAttribute("role","dialog"),n.setAttribute("aria-label","Pick a reaction"),document.body.append(n),n.onclick=c=>{const h=c.target.closest("[data-emoji]");if(!h)return;const u=h.dataset.emoji,d=[u,...this.recentEmoji().filter(f=>f!==u)].slice(0,8);localStorage.setItem("office.recentEmoji",JSON.stringify(d)),this.react(n.dataset.for,u),this.closePicker()},document.addEventListener("pointerdown",c=>{!n.hidden&&!n.contains(c.target)&&!c.target.closest("[data-pick]")&&this.closePicker()}),document.addEventListener("keydown",c=>{c.key==="Escape"&&!n.hidden&&this.closePicker()}));const s=[["Recent",this.recentEmoji()],...U1];n.innerHTML=s.map(([c,h])=>`<p>${c}</p><div class="grid">${[...h].map(u=>`<button type="button" data-emoji="${lt(u)}">${lt(u)}</button>`).join("")}</div>`).join(""),n.dataset.for=e,n.hidden=!1;const r=t.getBoundingClientRect(),a=n.offsetWidth,o=n.offsetHeight;n.style.left=Math.max(8,Math.min(r.right-a,innerWidth-a-8))+"px",n.style.top=(r.bottom+o+8<innerHeight?r.bottom+6:Math.max(8,r.top-o-6))+"px",(l=n.querySelector("button"))==null||l.focus()}closePicker(){const t=J("emojiPicker");t&&(t.hidden=!0,t.dataset.for="")}recentEmoji(){try{return JSON.parse(localStorage.getItem("office.recentEmoji"))||pd}catch{return pd}}forget(t=[]){var e,n;for(const s of t){(e=this.chat)==null||e.delete(s);for(const r of[J("msgs"),J("threadMsgs")])(n=r.querySelector(`.msg[data-id="${CSS.escape(s)}"]`))==null||n.remove()}}addVoice(t,e){var a;const n=(a=this.chat)==null?void 0:a.get(t);n&&(n.files=[...n.files||[],e]);const s=n?n.files:[e];let r=null;for(const o of[J("msgs"),J("threadMsgs")]){const l=o.querySelector(`.msg[data-id="${CSS.escape(t)}"]`);if(!l)continue;const c=document.createRange().createContextualFragment(xd(s)),h=l.querySelector(".files");h?h.replaceWith(c):(l.querySelector(".body")||l.querySelector(".who")).after(c),r=l}return(r==null?void 0:r.querySelector("audio.voice"))||null}setReactions(t,e){var s;const n=(s=this.chat)==null?void 0:s.get(t);n&&(n.reactions=e);for(const r of[J("msgs"),J("threadMsgs")]){const a=r.querySelector(`.msg[data-id="${CSS.escape(t)}"]`);a==null||a.querySelector(".reacts").replaceWith(document.createRange().createContextualFragment(this.reactionRow({reactions:e})))}}chiefBusy(t){J("typing").hidden=!t,t&&this.scrollChat()}toast(t,e="",n=null){const s=J("toast");if(s.textContent=t,n){const r=document.createElement("button");r.type="button",r.textContent=n.label,r.onclick=()=>{s.className="toast",n.run()},s.append(" ",r)}s.className=`toast show ${e} ${n?"act":""}`,clearTimeout(this.toastTimer),this.toastTimer=setTimeout(()=>s.className="toast",n?6e3:3200)}async post(t){try{const{text:e}=await He(t,{});e&&this.toast(e,"good")}catch(e){this.toast(e.message,"bad")}}bindTeam(){const t=J("team");t.onclick=e=>{var r;const n=e.target.closest("[data-member]");if(!n)return;const s=n.dataset.member;if(this.editing===s&&!this.dirty())this.editing=null;else if(this.editing!==s){if(this.dirty()&&!confirm("Discard your changes?"))return;this.editing=s}this.renderTeam(!0),(r=t.querySelector(".member.open input"))==null||r.focus()},t.onsubmit=async e=>{e.preventDefault();const n=e.target,s=n.querySelector("[type=submit]");s.disabled=!0;try{const r=await He(`/api/staff/${n.dataset.id}/profile`,Object.fromEntries(new FormData(n)));Object.assign(this.app.staff.find(a=>a.id===n.dataset.id)||{},r),this.toast(`Saved. ${this.app.staffName(n.dataset.id)} takes it from their next job.`,"good"),this.editing=null,this.renderTeam(!0)}catch(r){this.toast(r.message,"bad"),s.disabled=!1}},t.addEventListener("click",e=>{e.target.closest("[data-cancel]")&&(this.editing=null,this.renderTeam(!0))})}dirty(){const t=J("team").querySelector("form");if(!t)return!1;const e=this.app.staff.find(n=>n.id===t.dataset.id)||{};return["role","personality","background"].some(n=>t.elements[n].value.trim()!==(e[n]||""))}renderTeam(t=!1){if(J("teamPane").hidden||!t&&this.dirty())return;const{staff:e,progress:n,dismissed:s}=this.app,r=(n==null?void 0:n.capacity)||0;J("team").innerHTML=e.map((a,o)=>{const l=o>=r?"Not hired yet":s.has(a.id)?"Gone home":"",c=this.editing===a.id,h=`<button type="button" class="head" data-member="${lt(a.id)}" aria-expanded="${c}">
4435
- <i style="background:${js(a.shirt)}"></i>
4434
+ </div>`}reactionRow(t){const e=Object.entries(t.reactions||{}),n=e.map(([s,r])=>{const a=r.map(o=>this.app.person(o).name).join(", ");return`<button type="button" class="pill ${r.includes("you")?"mine":""}" data-react="${lt(s)}" title="${lt(a)}">${lt(s)}<span>${r.length}</span></button>`}).join("");return`<div class="reacts ${e.length?"some":""}">${n}<button type="button" class="add" data-pick aria-label="Add reaction" aria-haspopup="dialog" title="React">☺︎+</button></div>`}react(t,e){$e(`/api/chat/${t}/react`,{emoji:e}).catch(n=>this.toast(n.message,"bad"))}openPicker(t){var l;const e=t.closest(".msg").dataset.id;let n=q("emojiPicker");if((n==null?void 0:n.dataset.for)===e)return this.closePicker();n||(n=document.createElement("div"),n.id="emojiPicker",n.className="emoji-picker",n.setAttribute("role","dialog"),n.setAttribute("aria-label","Pick a reaction"),document.body.append(n),n.onclick=c=>{const h=c.target.closest("[data-emoji]");if(!h)return;const u=h.dataset.emoji,d=[u,...this.recentEmoji().filter(f=>f!==u)].slice(0,8);localStorage.setItem("office.recentEmoji",JSON.stringify(d)),this.react(n.dataset.for,u),this.closePicker()},document.addEventListener("pointerdown",c=>{!n.hidden&&!n.contains(c.target)&&!c.target.closest("[data-pick]")&&this.closePicker()}),document.addEventListener("keydown",c=>{c.key==="Escape"&&!n.hidden&&this.closePicker()}));const s=[["Recent",this.recentEmoji()],...h1];n.innerHTML=s.map(([c,h])=>`<p>${c}</p><div class="grid">${[...h].map(u=>`<button type="button" data-emoji="${lt(u)}">${lt(u)}</button>`).join("")}</div>`).join(""),n.dataset.for=e,n.hidden=!1;const r=t.getBoundingClientRect(),a=n.offsetWidth,o=n.offsetHeight;n.style.left=Math.max(8,Math.min(r.right-a,innerWidth-a-8))+"px",n.style.top=(r.bottom+o+8<innerHeight?r.bottom+6:Math.max(8,r.top-o-6))+"px",(l=n.querySelector("button"))==null||l.focus()}closePicker(){const t=q("emojiPicker");t&&(t.hidden=!0,t.dataset.for="")}recentEmoji(){try{return JSON.parse(localStorage.getItem("office.recentEmoji"))||Id}catch{return Id}}forget(t=[]){var e,n;for(const s of t){(e=this.chat)==null||e.delete(s);for(const r of[q("msgs"),q("threadMsgs")])(n=r.querySelector(`.msg[data-id="${CSS.escape(s)}"]`))==null||n.remove()}}addVoice(t,e){var a;const n=(a=this.chat)==null?void 0:a.get(t);n&&(n.files=[...n.files||[],e]);const s=n?n.files:[e];let r=null;for(const o of[q("msgs"),q("threadMsgs")]){const l=o.querySelector(`.msg[data-id="${CSS.escape(t)}"]`);if(!l)continue;const c=document.createRange().createContextualFragment(Fd(s)),h=l.querySelector(".files");h?h.replaceWith(c):(l.querySelector(".body")||l.querySelector(".who")).after(c),r=l}return(r==null?void 0:r.querySelector("audio.voice"))||null}setReactions(t,e){var s;const n=(s=this.chat)==null?void 0:s.get(t);n&&(n.reactions=e);for(const r of[q("msgs"),q("threadMsgs")]){const a=r.querySelector(`.msg[data-id="${CSS.escape(t)}"]`);a==null||a.querySelector(".reacts").replaceWith(document.createRange().createContextualFragment(this.reactionRow({reactions:e})))}}chiefBusy(t){q("typing").hidden=!t,t&&this.scrollChat()}toast(t,e="",n=null){const s=q("toast");if(s.textContent=t,n){const r=document.createElement("button");r.type="button",r.textContent=n.label,r.onclick=()=>{s.className="toast",n.run()},s.append(" ",r)}s.className=`toast show ${e} ${n?"act":""}`,clearTimeout(this.toastTimer),this.toastTimer=setTimeout(()=>s.className="toast",n?6e3:3200)}async post(t){try{const{text:e}=await $e(t,{});e&&this.toast(e,"good")}catch(e){this.toast(e.message,"bad")}}bindTeam(){const t=q("team");t.onclick=e=>{var r;const n=e.target.closest("[data-member]");if(!n)return;const s=n.dataset.member;if(this.editing===s&&!this.dirty())this.editing=null;else if(this.editing!==s){if(this.dirty()&&!confirm("Discard your changes?"))return;this.editing=s}this.renderTeam(!0),(r=t.querySelector(".member.open input"))==null||r.focus()},t.onsubmit=async e=>{e.preventDefault();const n=e.target,s=n.querySelector("[type=submit]");s.disabled=!0;try{const r=await $e(`/api/staff/${n.dataset.id}/profile`,Object.fromEntries(new FormData(n)));Object.assign(this.app.staff.find(a=>a.id===n.dataset.id)||{},r),this.toast(`Saved. ${this.app.staffName(n.dataset.id)} takes it from their next job.`,"good"),this.editing=null,this.renderTeam(!0)}catch(r){this.toast(r.message,"bad"),s.disabled=!1}},t.addEventListener("click",e=>{e.target.closest("[data-cancel]")&&(this.editing=null,this.renderTeam(!0))})}dirty(){const t=q("team").querySelector("form");if(!t)return!1;const e=this.app.staff.find(n=>n.id===t.dataset.id)||{};return["role","personality","background"].some(n=>t.elements[n].value.trim()!==(e[n]||""))}renderTeam(t=!1){if(q("teamPane").hidden||!t&&this.dirty())return;const{staff:e,progress:n,dismissed:s}=this.app,r=(n==null?void 0:n.capacity)||0;q("team").innerHTML=e.map((a,o)=>{const l=o>=r?"Not hired yet":s.has(a.id)?"Gone home":"",c=this.editing===a.id,h=`<button type="button" class="head" data-member="${lt(a.id)}" aria-expanded="${c}">
4435
+ <i style="background:${er(a.shirt)}"></i>
4436
4436
  <span class="n">${lt(a.name)}${l?` <em>${l}</em>`:""}</span>
4437
4437
  <span class="r">${lt(a.role||"No role yet")}</span>
4438
4438
  </button>`;return c?`<div class="member open">${h}
@@ -4443,15 +4443,15 @@ In it: ${o}`:""}`;return`<button type="button" role="tab" aria-selected="${a}" c
4443
4443
  <p class="hint-t">Shapes how ${lt(a.name)} writes and who the chief sends their way. It never lowers the bar on the work.</p>
4444
4444
  <div class="row"><button type="button" class="ghost small" data-cancel>Cancel</button><button type="submit" class="primary small">Save</button></div>
4445
4445
  </form>
4446
- </div>`:`<div class="member${o>=r?" later":""}">${h}${a.personality?`<p class="p">${lt(a.personality)}</p>`:""}</div>`}).join("")}renderAway(t){const e=J("away");e.hidden=!t.length,e.innerHTML=t.length?`<span>Gone home</span>${t.map(n=>`<button type="button" data-recall="${lt(n.id)}" title="Call ${lt(n.name)} back"><i style="background:${js(n.shirt)}"></i>${lt(n.name)}</button>`).join("")}`:""}banner(t,e){const n=J("banner");n.innerHTML=`<b>${lt(t)}</b><span>${lt(e)}</span>`,n.classList.remove("show"),n.offsetWidth,n.classList.add("show")}}const V1="modulepreload",G1=function(i){return"/"+i},yd={},Md=function(t,e,n){let s=Promise.resolve();if(e&&e.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),o=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));s=Promise.allSettled(e.map(l=>{if(l=G1(l),l in yd)return;yd[l]=!0;const c=l.endsWith(".css"),h=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${h}`))return;const u=document.createElement("link");if(u.rel=c?"stylesheet":V1,c||(u.as="script"),u.crossOrigin="",u.href=l,o&&u.setAttribute("nonce",o),document.head.appendChild(u),c)return new Promise((d,f)=>{u.addEventListener("load",d),u.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${l}`)))})}))}function r(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return s.then(a=>{for(const o of a||[])o.status==="rejected"&&r(o.reason);return t().catch(r)})},we=i=>document.getElementById(i),Nl="office.term.height",bd="office.term.folder",Sd=140,$1={background:"#221e18",foreground:"#ece4d6",cursor:"#f2cc8f",cursorAccent:"#221e18",selectionBackground:"rgba(242, 204, 143, 0.26)",black:"#3b342b",red:"#e4705c",green:"#8cc08a",yellow:"#e8bb63",blue:"#7fb2dd",magenta:"#cf9ad4",cyan:"#80c4bd",white:"#ded5c6",brightBlack:"#6f6454",brightRed:"#f2897a",brightGreen:"#a8d6a3",brightYellow:"#f6d088",brightBlue:"#a2cbf0",brightMagenta:"#e2b6e6",brightCyan:"#a3d9d2",brightWhite:"#fbf9f5"};let Ul=null;async function W1(){if(!Ul){const[{Terminal:i},{FitAddon:t}]=await Promise.all([Md(()=>import("./xterm-C7kOH91j.js").then(e=>e.x),__vite__mapDeps([0,1])),Md(()=>import("./addon-fit-BwprjgOP.js").then(e=>e.a),__vite__mapDeps([2,1]))]);Ul={Terminal:i,FitAddon:t}}return Ul}class X1{constructor({api:t,toast:e}){this.api=t,this.toast=e,this.sessions=[],this.active=null,this.status=null,this.seq=0,this.height=Number(localStorage.getItem(Nl))||300,we("termToggle").onclick=()=>this.toggle(),we("termHide").onclick=()=>this.hide(),we("termNew").onclick=()=>this.spawn(),we("termTabs").onclick=n=>{const s=n.target.closest("[data-close]");if(s)return this.close(s.dataset.close);const r=n.target.closest("[data-tab]");r&&this.select(r.dataset.tab)},we("termFolder").onchange=n=>localStorage.setItem(bd,n.target.value),this.bindGrip(),addEventListener("keydown",n=>{n.ctrlKey&&!n.metaKey&&!n.altKey&&(n.key==="`"||n.code==="Backquote")&&(n.preventDefault(),this.toggle())}),new ResizeObserver(()=>this.fit()).observe(we("termBody")),addEventListener("resize",()=>{this.open&&this.setHeight(this.height)})}get open(){return!we("term").hidden}async toggle(){this.open?this.hide():this.show()}hide(){we("term").hidden=!0,we("termToggle").classList.remove("on"),this.setHeight(0)}async show(){var t;we("term").hidden=!1,we("termToggle").classList.add("on"),this.setHeight(this.height),await this.refresh(),(t=this.status)!=null&&t.enabled&&(this.sessions.length?this.focus():this.spawn())}setHeight(t){we("view").style.setProperty("--term-h",`${Math.round(t&&this.limit(t))}px`)}limit(t){return Math.min(Math.max(Sd,we("view").clientHeight-120),Math.max(Sd,t))}bindGrip(){const t=we("termGrip");t.onpointerdown=e=>{t.setPointerCapture(e.pointerId);const n=e.clientY,s=this.height,r=o=>{this.height=this.limit(s-(o.clientY-n)),this.setHeight(this.height)},a=()=>{t.onpointermove=t.onpointerup=t.onpointercancel=null,localStorage.setItem(Nl,String(Math.round(this.height)))};t.onpointermove=r,t.onpointerup=t.onpointercancel=a},t.onkeydown=e=>{const n=e.key==="ArrowUp"?32:e.key==="ArrowDown"?-32:0;n&&(e.preventDefault(),this.height=this.limit(this.height+n),this.setHeight(this.height),localStorage.setItem(Nl,String(Math.round(this.height))))}}async refresh(){try{this.status=await this.api("/api/terminal")}catch(s){this.status={enabled:!1,reason:s.message}}const t=we("termOff");if(t.hidden=!!this.status.enabled,we("termBody").hidden=!this.status.enabled,we("termFolder").hidden=we("termNew").hidden=!this.status.enabled,!this.status.enabled){t.innerHTML=`<p><b>No terminal.</b> ${us(this.status.reason)}</p>
4446
+ </div>`:`<div class="member${o>=r?" later":""}">${h}${a.personality?`<p class="p">${lt(a.personality)}</p>`:""}</div>`}).join("")}renderAway(t){const e=q("away");e.hidden=!t.length,e.innerHTML=t.length?`<span>Gone home</span>${t.map(n=>`<button type="button" data-recall="${lt(n.id)}" title="Call ${lt(n.name)} back"><i style="background:${er(n.shirt)}"></i>${lt(n.name)}</button>`).join("")}`:""}banner(t,e){const n=q("banner");n.innerHTML=`<b>${lt(t)}</b><span>${lt(e)}</span>`,n.classList.remove("show"),n.offsetWidth,n.classList.add("show")}}const g1="modulepreload",v1=function(i){return"/"+i},zd={},Bd=function(t,e,n){let s=Promise.resolve();if(e&&e.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),o=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));s=Promise.allSettled(e.map(l=>{if(l=v1(l),l in zd)return;zd[l]=!0;const c=l.endsWith(".css"),h=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${h}`))return;const u=document.createElement("link");if(u.rel=c?"stylesheet":g1,c||(u.as="script"),u.crossOrigin="",u.href=l,o&&u.setAttribute("nonce",o),document.head.appendChild(u),c)return new Promise((d,f)=>{u.addEventListener("load",d),u.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${l}`)))})}))}function r(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return s.then(a=>{for(const o of a||[])o.status==="rejected"&&r(o.reason);return t().catch(r)})},we=i=>document.getElementById(i),jl="office.term.height",Hd="office.term.folder",Vd=140,_1={background:"#221e18",foreground:"#ece4d6",cursor:"#f2cc8f",cursorAccent:"#221e18",selectionBackground:"rgba(242, 204, 143, 0.26)",black:"#3b342b",red:"#e4705c",green:"#8cc08a",yellow:"#e8bb63",blue:"#7fb2dd",magenta:"#cf9ad4",cyan:"#80c4bd",white:"#ded5c6",brightBlack:"#6f6454",brightRed:"#f2897a",brightGreen:"#a8d6a3",brightYellow:"#f6d088",brightBlue:"#a2cbf0",brightMagenta:"#e2b6e6",brightCyan:"#a3d9d2",brightWhite:"#fbf9f5"};let ql=null;async function x1(){if(!ql){const[{Terminal:i},{FitAddon:t}]=await Promise.all([Bd(()=>import("./xterm-C7kOH91j.js").then(e=>e.x),__vite__mapDeps([0,1])),Bd(()=>import("./addon-fit-BwprjgOP.js").then(e=>e.a),__vite__mapDeps([2,1]))]);ql={Terminal:i,FitAddon:t}}return ql}class y1{constructor({api:t,toast:e}){this.api=t,this.toast=e,this.sessions=[],this.active=null,this.status=null,this.seq=0,this.height=Number(localStorage.getItem(jl))||300,we("termToggle").onclick=()=>this.toggle(),we("termHide").onclick=()=>this.hide(),we("termNew").onclick=()=>this.spawn(),we("termTabs").onclick=n=>{const s=n.target.closest("[data-close]");if(s)return this.close(s.dataset.close);const r=n.target.closest("[data-tab]");r&&this.select(r.dataset.tab)},we("termFolder").onchange=n=>localStorage.setItem(Hd,n.target.value),this.bindGrip(),addEventListener("keydown",n=>{n.ctrlKey&&!n.metaKey&&!n.altKey&&(n.key==="`"||n.code==="Backquote")&&(n.preventDefault(),this.toggle())}),new ResizeObserver(()=>this.fit()).observe(we("termBody")),addEventListener("resize",()=>{this.open&&this.setHeight(this.height)})}get open(){return!we("term").hidden}async toggle(){this.open?this.hide():this.show()}hide(){we("term").hidden=!0,we("termToggle").classList.remove("on"),this.setHeight(0)}async show(){var t;we("term").hidden=!1,we("termToggle").classList.add("on"),this.setHeight(this.height),await this.refresh(),(t=this.status)!=null&&t.enabled&&(this.sessions.length?this.focus():this.spawn())}setHeight(t){we("view").style.setProperty("--term-h",`${Math.round(t&&this.limit(t))}px`)}limit(t){return Math.min(Math.max(Vd,we("view").clientHeight-120),Math.max(Vd,t))}bindGrip(){const t=we("termGrip");t.onpointerdown=e=>{t.setPointerCapture(e.pointerId);const n=e.clientY,s=this.height,r=o=>{this.height=this.limit(s-(o.clientY-n)),this.setHeight(this.height)},a=()=>{t.onpointermove=t.onpointerup=t.onpointercancel=null,localStorage.setItem(jl,String(Math.round(this.height)))};t.onpointermove=r,t.onpointerup=t.onpointercancel=a},t.onkeydown=e=>{const n=e.key==="ArrowUp"?32:e.key==="ArrowDown"?-32:0;n&&(e.preventDefault(),this.height=this.limit(this.height+n),this.setHeight(this.height),localStorage.setItem(jl,String(Math.round(this.height))))}}async refresh(){try{this.status=await this.api("/api/terminal")}catch(s){this.status={enabled:!1,reason:s.message}}const t=we("termOff");if(t.hidden=!!this.status.enabled,we("termBody").hidden=!this.status.enabled,we("termFolder").hidden=we("termNew").hidden=!this.status.enabled,!this.status.enabled){t.innerHTML=`<p><b>No terminal.</b> ${vs(this.status.reason)}</p>
4447
4447
  <p class="term-why">Shell access is off by default because anything in this browser would get a shell
4448
4448
  as you — no clearance picker, no job log. Turn it on only on a machine you trust:</p>
4449
- <pre>OFFICE_TERMINAL=1 npm start</pre>`,we("termNote").textContent="";return}const e=we("termFolder"),n=e.value||localStorage.getItem(bd)||"";e.innerHTML=[`<option value="">${us(this.status.root)}</option>`,...this.status.folders.map(s=>`<option value="${us(s)}">${us(s)}</option>`)].join(""),e.value=[...e.options].some(s=>s.value===n)?n:"",we("termNote").textContent=this.status.shell.split("/").pop(),we("termNote").title=`${this.status.shell} · up to ${this.status.max} at once · closes itself after ${this.status.idleMinutes} min idle`}async spawn(){var _;if(await this.refresh(),!((_=this.status)!=null&&_.enabled))return;const{Terminal:t,FitAddon:e}=await W1(),n=we("termFolder").value;let s;try{s=await this.api("/api/terminal/ticket",{folder:n})}catch(m){return this.toast(m.message,"bad")}const r=`t${++this.seq}`,a=this.sessions.filter(m=>m.folder===n).length,o=document.createElement("div");o.className="term-pane",o.dataset.pane=r,we("termBody").append(o);const l=new t({theme:$1,fontFamily:"'JetBrains Mono', ui-monospace, monospace",fontSize:12.5,lineHeight:1.35,cursorBlink:!0,scrollback:5e3,allowProposedApi:!0,macOptionIsMeta:!0}),c=new e;l.loadAddon(c),l.open(o);const h=location.protocol==="https:"?"wss":"ws",u=new WebSocket(`${h}://${location.host}/ws/terminal?ticket=${encodeURIComponent(s.ticket)}`),d=a?`${s.cwd} ${a+1}`:s.cwd,f={id:r,folder:n,label:d,term:l,fit:c,ws:u,el:o,live:!1};this.sessions.push(f),this.select(r);const g=()=>{u.readyState===WebSocket.OPEN&&u.send(JSON.stringify({t:"size",cols:l.cols,rows:l.rows}))};u.onopen=()=>{this.fit(),g()},u.onmessage=m=>{const p=JSON.parse(m.data);p.t==="ready"?(f.live=!0,g(),this.renderTabs()):p.t==="out"?l.write(p.d):p.t==="exit"&&(f.live=!1,l.write(`\r
4449
+ <pre>OFFICE_TERMINAL=1 npm start</pre>`,we("termNote").textContent="";return}const e=we("termFolder"),n=e.value||localStorage.getItem(Hd)||"";e.innerHTML=[`<option value="">${vs(this.status.root)}</option>`,...this.status.folders.map(s=>`<option value="${vs(s)}">${vs(s)}</option>`)].join(""),e.value=[...e.options].some(s=>s.value===n)?n:"",we("termNote").textContent=this.status.shell.split("/").pop(),we("termNote").title=`${this.status.shell} · up to ${this.status.max} at once · closes itself after ${this.status.idleMinutes} min idle`}async spawn(){var _;if(await this.refresh(),!((_=this.status)!=null&&_.enabled))return;const{Terminal:t,FitAddon:e}=await x1(),n=we("termFolder").value;let s;try{s=await this.api("/api/terminal/ticket",{folder:n})}catch(m){return this.toast(m.message,"bad")}const r=`t${++this.seq}`,a=this.sessions.filter(m=>m.folder===n).length,o=document.createElement("div");o.className="term-pane",o.dataset.pane=r,we("termBody").append(o);const l=new t({theme:_1,fontFamily:"'JetBrains Mono', ui-monospace, monospace",fontSize:12.5,lineHeight:1.35,cursorBlink:!0,scrollback:5e3,allowProposedApi:!0,macOptionIsMeta:!0}),c=new e;l.loadAddon(c),l.open(o);const h=location.protocol==="https:"?"wss":"ws",u=new WebSocket(`${h}://${location.host}/ws/terminal?ticket=${encodeURIComponent(s.ticket)}`),d=a?`${s.cwd} ${a+1}`:s.cwd,f={id:r,folder:n,label:d,term:l,fit:c,ws:u,el:o,live:!1};this.sessions.push(f),this.select(r);const g=()=>{u.readyState===WebSocket.OPEN&&u.send(JSON.stringify({t:"size",cols:l.cols,rows:l.rows}))};u.onopen=()=>{this.fit(),g()},u.onmessage=m=>{const p=JSON.parse(m.data);p.t==="ready"?(f.live=!0,g(),this.renderTabs()):p.t==="out"?l.write(p.d):p.t==="exit"&&(f.live=!1,l.write(`\r
4450
4450
  \x1B[2m— ${p.why||`shell exited${p.code?` (${p.code})`:""}`} —\x1B[0m\r
4451
4451
  `),this.renderTabs())},u.onerror=()=>{},u.onclose=m=>{!f.live&&!m.wasClean&&l.write(`\r
4452
4452
  \x1B[2m— ${m.reason||"the office refused the terminal"} —\x1B[0m\r
4453
4453
  `),f.live=!1,this.renderTabs()},l.onData(m=>{u.readyState===WebSocket.OPEN&&u.send(JSON.stringify({t:"in",d:m}))}),l.onResize(g),l.onTitleChange(m=>{f.title=m,this.renderTabs()})}select(t){const e=this.sessions.find(n=>n.id===t);if(e){this.active=t;for(const n of this.sessions)n.el.classList.toggle("on",n===e);this.renderTabs(),this.fit(),this.focus()}}focus(){var t;(t=this.sessions.find(e=>e.id===this.active))==null||t.term.focus()}close(t){const e=this.sessions.findIndex(r=>r.id===t);if(e<0)return;const[n]=this.sessions.splice(e,1);try{n.ws.close()}catch{}if(n.term.dispose(),n.el.remove(),this.active!==t)return this.renderTabs();const s=this.sessions[e]||this.sessions[e-1];this.active=null,s?this.select(s.id):(this.renderTabs(),this.hide())}renderTabs(){we("termTabs").innerHTML=this.sessions.map(t=>{const e=[t.label,t.live?t.title:"the shell has exited"].filter(Boolean).join(" · ");return`<span class="term-tab${t.id===this.active?" on":""}${t.live?"":" dead"}">
4454
- <button type="button" data-tab="${t.id}" role="tab" aria-selected="${t.id===this.active}" title="${us(e)}">${us(t.label)}</button>
4455
- <button type="button" class="x" data-close="${t.id}" aria-label="Close ${us(t.label)}">
4454
+ <button type="button" data-tab="${t.id}" role="tab" aria-selected="${t.id===this.active}" title="${vs(e)}">${vs(t.label)}</button>
4455
+ <button type="button" class="x" data-close="${t.id}" aria-label="Close ${vs(t.label)}">
4456
4456
  <svg viewBox="0 0 24 24"><path d="M6 18L18 6M6 6l12 12"/></svg>
4457
- </button></span>`}).join("")}fit(){if(!this.open)return;const t=this.sessions.find(e=>e.id===this.active);if(!(!t||!t.el.clientHeight))try{t.fit.fit()}catch{}}}const us=i=>String(i??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]);{const i=document.getElementById("app"),t=document.getElementById("side-grip"),e="office.sideWidth",n=320,s=24,r=()=>Math.max(n,Math.min(900,innerWidth-420)),a=u=>i.style.setProperty("--side-w",`${Math.round(Math.min(r(),Math.max(n,u)))}px`),o=Number(localStorage.getItem(e));o&&a(o);const l=()=>t.parentElement.getBoundingClientRect().width,c=()=>localStorage.setItem(e,String(Math.round(l())));t.addEventListener("pointerdown",u=>{t.setPointerCapture(u.pointerId),i.classList.add("resizing"),u.preventDefault()}),t.addEventListener("pointermove",u=>{t.hasPointerCapture(u.pointerId)&&a(u.clientX)});const h=u=>{t.hasPointerCapture(u.pointerId)&&(t.releasePointerCapture(u.pointerId),i.classList.remove("resizing"),c())};t.addEventListener("pointerup",h),t.addEventListener("pointercancel",h),t.addEventListener("dblclick",()=>{i.style.removeProperty("--side-w"),localStorage.removeItem(e)}),t.addEventListener("keydown",u=>{const d=u.key==="ArrowLeft"?-s:u.key==="ArrowRight"?s:0;d&&(u.preventDefault(),a(l()+d),c())})}{const i=document.getElementById("app"),t="office.sideZoom",e=.8,n=1.8,s=a=>(a=Math.round(Math.min(n,Math.max(e,a))*100)/100,i.style.setProperty("--side-zoom",String(a)),a===1?localStorage.removeItem(t):localStorage.setItem(t,String(a)),a);let r=Number(localStorage.getItem(t))||1;s(r),addEventListener("keydown",a=>{if(!(a.ctrlKey||a.metaKey)||a.altKey)return;const o=a.key;if(o==="+"||o==="=")r=s(r+.1);else if(o==="-"||o==="_")r=s(r-.1);else if(o==="0")r=s(1);else return;a.preventDefault()}),document.querySelector(".side").addEventListener("wheel",a=>{a.ctrlKey&&(a.preventDefault(),r=s(r-Math.sign(a.deltaY)*.05))},{passive:!1})}document.getElementById("view");const xo=document.getElementById("stage"),Ch=document.getElementById("labels"),ze=new Zx({antialias:!0,alpha:!0});ze.setClearColor(0,0);ze.setPixelRatio(Math.min(devicePixelRatio,2));ze.shadowMap.enabled=!0;ze.shadowMap.type=Gd;ze.toneMapping=qc;ze.toneMappingExposure=1;xo.appendChild(ze.domElement);const Kn=new wf;Kn.background=j1();Kn.environment=new Ic(ze).fromScene(new Uy,.04).texture;Kn.environmentIntensity=.55;Kn.add(new my("#fff8ef","#b9ab99",.55));const ws=new xy("#fff0d8",1.75);ws.position.set(-18,34,20);ws.castShadow=!0;ws.shadow.mapSize.set(4096,4096);Object.assign(ws.shadow.camera,{left:-32,right:32,top:28,bottom:-28,near:1,far:100});ws.shadow.bias=-3e-4;ws.shadow.normalBias=.03;Kn.add(ws);const Me=new wn(30,1,.5,400),Ne={target:new R(0,0,.5),radius:60,phi:.86,theta:Math.PI/4};Me.position.setFromSpherical(new mr(Ne.radius,Ne.phi,Ne.theta)).add(Ne.target);const Ae=new Ny(Me,ze.domElement);Ae.target.copy(Ne.target);Object.assign(Ae,{enableDamping:!0,dampingFactor:.09,minPolarAngle:.25,maxPolarAngle:1.22,minDistance:12,maxDistance:260,zoomToCursor:!0,rotateSpeed:.55,zoomSpeed:.9,panSpeed:1.1});const np=[];for(const i of[-20.3,20.3])for(const t of[-15.3,15.3])for(const e of[-.7,3])np.push(new R(i,e,t));function ip(i,t,e){const n=Me.aspect<.9?1.7:.93,s=Me.clone();let r=15,a=260;for(let o=0;o<20;o++){const l=(r+a)/2;s.position.setFromSpherical(new mr(l,i,t)).add(e),s.lookAt(e),s.updateMatrixWorld(),np.every(h=>{const u=h.clone().project(s);return Math.abs(u.x)<n&&Math.abs(u.y)<.88})?a=l:r=l}return a}const gr=new Vy(ze,new Yn(1,1,{type:Li,samples:4}));gr.addPass(new Gy(Kn,Me));const Lo=new ei(Kn,Me,1,1);Lo.updateGtaoMaterial({radius:.9,distanceExponent:1.6,thickness:1.5,scale:1.1,samples:16});Lo.updatePdMaterial({lumaPhi:10,depthPhi:2,normalPhi:3,radius:6,rings:2,samples:16});Lo.blendIntensity=.85;gr.addPass(Lo);gr.addPass(new Yy);function j1(){const i=document.createElement("canvas");i.width=512,i.height=512;const t=i.getContext("2d"),e=t.createRadialGradient(256,190,20,256,230,400);e.addColorStop(0,"#f7f3ec"),e.addColorStop(.6,"#ece5da"),e.addColorStop(1,"#d9d0c2"),t.fillStyle=e,t.fillRect(0,0,512,512);const n=new ki(i);return n.colorSpace=je,n}let Zs=1,ti=1,Do=!1;function sp(){const i=ti;if(Zs=xo.clientWidth,ti=xo.clientHeight,ze.setSize(Zs,ti,!1),gr.setPixelRatio(Math.min(devicePixelRatio,1.5)),gr.setSize(Zs,ti),Me.aspect=Zs/ti,Me.updateProjectionMatrix(),!Do)Ne.radius=ip(Ne.phi,Ne.theta,Ne.target),Me.position.setFromSpherical(new mr(Ne.radius,Ne.phi,Ne.theta)).add(Ne.target),Ae.target.copy(Ne.target);else if(i>1&&ti>1&&ti!==i){const t=Me.position.clone().sub(Ae.target),e=fs.clamp(t.length()*(ti/i),Ae.minDistance,Ae.maxDistance);Me.position.copy(Ae.target).add(t.setLength(e))}}new ResizeObserver(sp).observe(xo);sp();const vn=gM(Kn),rp=new QM(Kn),ap={id:"chief",name:"Chief",shirt:"#2b2d42",hair:"#8d8d8d",skin:"#a8714a"},tt={staff:[],chiefCost:0,modes:{},progress:null,jobs:new Map,agents:new Map,dismissed:new Set,selected:null,job:i=>tt.jobs.get(i),staffName:i=>{var t;return((t=tt.staff.find(e=>e.id===i))==null?void 0:t.name)||""},person:i=>{if(i==="you")return{name:"You",color:"#c9c1b4"};if(i==="chief")return{name:"Chief of Staff",color:ap.shirt};const t=tt.staff.find(e=>e.id===i);return{name:(t==null?void 0:t.name)||i,color:(t==null?void 0:t.shirt)||"#999"}},onFloor:()=>{var i;return tt.staff.slice(0,((i=tt.progress)==null?void 0:i.capacity)||0).filter(t=>!tt.dismissed.has(t.id))},roster:()=>tt.onFloor().map(i=>{const t=[...tt.jobs.values()].find(e=>e.status==="working"&&e.agentId===i.id);return{name:i.name,color:i.shirt,note:t?`on ${t.repo}`:"free"}}),busyIn:i=>{const t=[...tt.jobs.values()].filter(e=>e.status==="working"&&e.repo===i).map(e=>tt.staffName(e.agentId));return t.length?`${t.join(", ")} here`:""}},Rh={scene:Kn,...vn,agentIndex:i=>tt.staff.findIndex(t=>t.id===i)},Ht=new H1(tt);new X1({api:He,toast:(i,t)=>Ht.toast(i,t)});const mn=new xh(ap,Rh,Ch,{desk:vn.reception,face:0}),q1=new CM,Y1=new jM(Kn,vn),eo=new JM({world:Rh,labels:Ch,camera:Me,canvas:ze.domElement});mn.want="desk";mn.teleport("desk");tt.mergeLog=i=>{const t=tt.jobs.get(i.id);t?t.log=i.log:tt.jobs.set(i.id,i)};tt.refreshLists=()=>{const i=[...tt.jobs.values()];Ht.renderJobs(i,tt.staffName),Ht.renderStats(i,tt.chiefCost),Bf(vn.board,i)};tt.openJob=i=>{Ht.openDetail(i);const t=tt.jobs.get(i),e=(t==null?void 0:t.status)==="working"&&tt.agents.get(t.agentId);e&&(tt.select(e.id,!1),hp())};tt.select=(i,t=!0)=>{for(const r of tt.agents.values())r.setSelected(r.id===i);if(tt.selected=i,i||(Es=!1),!i||!t)return;const e=tt.agents.get(i);hp(),Ht.focusInput(`@${e.name} `);const n=[...tt.jobs.values()].filter(r=>r.agentId===i),s=n.find(r=>r.status==="working")||n.sort((r,a)=>(a.endedAt||0)-(r.endedAt||0))[0];s&&Ht.openDetail(s.id),(s==null?void 0:s.status)!=="working"&&Ht.toast(`${e.name} is between jobs. Press N to give them one.`,"",{label:"Send home",run:()=>tt.dismiss(e.id)})};tt.dismiss=i=>!$t.on&&Ht.post(`/api/staff/${i}/dismiss`);tt.recall=i=>!$t.on&&Ht.post(`/api/staff/${i}/recall`);function op(i,t){tt.onFloor().forEach(e=>{const n=tt.agents.get(e.id);if(n){n.leaving&&n.stay();return}const s=new xh(e,Rh,Ch);tt.agents.set(e.id,s),i?s.teleport("lounge"):(s.teleport("door"),s.say(t||`Hi, I'm ${e.name}!`,"good",5e3))})}function wd(i,t){tt.dismissed=new Set(i||[]);for(const e of tt.agents.values())!tt.dismissed.has(e.id)||e.leaving||e.job||(t?e.gone=!0:e.leave());op(t,"Back in!"),Ht.renderAway(tt.staff.filter(e=>tt.dismissed.has(e.id))),Ht.renderTeam()}function K1(i){var t,e;for(const n of tt.agents.values()){const s=[...tt.jobs.values()].find(r=>r.status==="working"&&r.agentId===n.id);s&&((t=n.job)==null?void 0:t.id)!==s.id?(n.assign(s,i),s.log.forEach(r=>n.onLog(r))):!s&&n.job&&n.finish(((e=tt.jobs.get(n.job.id))==null?void 0:e.status)||"stopped")}}function Ed(i=[],t=!1){const e=vn.standup;mn.meet(e[0],t),i.forEach((n,s)=>{var r;return(r=tt.agents.get(n))==null?void 0:r.meet(e[1+Math.round(s*(e.length-2)/Math.max(1,i.length-1))],t)}),tt.standupOn=!0,document.getElementById("standup").disabled=!0}function Td(){mn.adjourn();for(const i of tt.agents.values())i.adjourn();tt.standupOn=!1,document.getElementById("standup").disabled=!1}let Ga=!0;function Bc(){const i=$t.on?`/ws/visit/${encodeURIComponent($t.link)}`:"/ws",t=new WebSocket(`${location.protocol==="https:"?"wss":"ws"}://${location.host}${i}`);t.onmessage=e=>Z1(JSON.parse(e.data)),t.onclose=e=>{const n=Xp(e.code);if(n!=null){n&&setTimeout(Bc,n);return}Ht.toast("Lost the office line. Reconnecting…","bad"),setTimeout(Bc,1500)}}function Z1(i){var t,e,n,s,r,a,o,l;if(!eo.handle(i)){if(i.t==="hello"){Gp(i.visiting),tt.staff=i.staff,tt.voice=i.voice,gn=i.tts||gn,or(),tt.modes=Wp(i.modes),tt.progress=i.progress,tt.chiefCost=i.chiefCost||0,tt.jobs=new Map(i.jobs.map(h=>[h.id,h])),Ht.renderChannels(i.channels||[{id:"general",name:"general"}]),Ht.renderChat(i.chat||[]),Ht.chiefBusy(i.chiefBusy),wd(i.dismissed,Ga),K1(Ga),i.standup?Ed(i.standup.who,Ga):tt.standupOn&&Td(),Ga=!1,Ht.renderLevel(tt.progress),Ht.renderUsage(i.usage),Bl(i.auth),Gh(i.leaderboard),cr(i.links),Ht.renderProc(i.procs,i.machine),tt.refreshLists();const c=ib();Oc(vn.scribble,c),Ht.openId&&(tt.jobs.has(Ht.openId)?Ht.openDetail(Ht.openId):Ht.closeDetail())}else if(i.t==="job"){const c=tt.jobs.get(i.job.id),h={...i.job,log:(c==null?void 0:c.log)||[]};if(tt.jobs.set(h.id,h),h.status==="working"){const u=tt.agents.get(h.agentId);u&&((t=u.job)==null?void 0:t.id)!==h.id?u.assign(h):u&&(u.job=h)}else for(const u of tt.agents.values()){if(((e=u.job)==null?void 0:e.id)!==h.id)continue;const d=h.status==="done"&&!h.awaitingBoss;u.finish(d?"done":h.awaitingBoss?"waiting":h.status),d&&rp.burst(u.pos,[u.staff.shirt,"#f2cc8f","#81b29a","#3d7ea6","#ffffff"]),d&&(rn.ship(),Ol(`${u.name} shipped`,h.title)),h.status==="failed"&&(rn.fail(),Ol(`${u.name} hit a wall`,h.title))}(c==null?void 0:c.status)!==h.status?(Ht.openId===h.id&&Ht.renderDetail(),h.awaitingBoss&&(c==null?void 0:c.status)==="working"?Ht.toast(`${tt.staffName(h.agentId)} is waiting on you: “${h.title}”`,"warn"):h.status==="done"&&(c==null?void 0:c.status)==="working"&&Ht.toast(`${tt.staffName(h.agentId)} shipped “${h.title}”`,"good"),h.status==="failed"&&(c==null?void 0:c.status)==="working"&&Ht.toast(`${tt.staffName(h.agentId)} hit a wall on “${h.title}”`,"bad")):Ht.openId===h.id&&((n=c==null?void 0:c.changes)==null?void 0:n.end)!==((s=h.changes)==null?void 0:s.end)&&Ht.renderChanges(h),tt.refreshLists()}else if(i.t==="log"){const c=tt.jobs.get(i.jobId);if(!c)return;c.log.push(i.entry),c.log.length>600&&c.log.shift();for(const h of tt.agents.values())((r=h.job)==null?void 0:r.id)===c.id&&h.onLog(i.entry);i.entry.todos&&Oc(vn.scribble,i.entry.todos),Ht.appendLog(c.id,i.entry)}else if(i.t==="channels")Ht.renderChannels(i.channels);else if(i.t==="chat"){Ht.addMessage(i.msg);const c=tt.agents.get(i.msg.from),h=tt.agents.get(i.msg.to);if(c&&h&&(c.visit(h,i.msg.text),rn.knock()),nb(i.msg),i.msg.kind==="flag"&&(rn.knock(),Ol("The boss is needed",i.msg.text.replace(/\*\*/g,""))),i.msg.kind==="standup"){const u=i.msg.say||i.msg.text;(a=i.msg.from==="chief"?mn:c)==null||a.speak(u.length>90?u.slice(0,89)+"…":u)}else i.msg.from==="chief"&&(mn.job=null,mn.say(i.msg.text.length>90?i.msg.text.slice(0,89)+"…":i.msg.text,"",6e3))}else if(i.t==="forget")Ht.forget(i.ids);else if(i.t==="voice"){const c=Ht.addVoice(i.id,i.file);c&&gn.replies&&!Qn.active&&!document.hidden&&c.play().catch(()=>{})}else if(i.t==="tts")gn={...gn,...i},or();else if(i.t==="react")Ht.setReactions(i.id,i.reactions);else if(i.t==="standup")i.phase==="start"?(Ed(i.who),Ht.banner("Standup","Everyone to the whiteboard."),rn.knock()):Td();else if(i.t==="chief")Ht.chiefBusy(i.busy),i.busy?(mn.job={id:"routing"},mn.say("Reading your message…","thinking")):mn.job=null,i.cost!==void 0&&(tt.chiefCost=i.cost,tt.refreshLists());else if(i.t==="staff")wd(i.dismissed,!1);else if(i.t==="profile"){const c=tt.staff.find(h=>h.id===i.id);c&&Object.assign(c,i.profile),Ht.renderTeam()}else if(i.t==="auth")Bl(i.auth);else if(i.t==="leaderboard")Gh(i.leaderboard);else if(i.t==="links")cr(i);else if(i.t==="usage")Ht.renderUsage(i.usage);else if(i.t==="proc")Ht.renderProc(i.procs,i.machine);else if(i.t==="xp"){tt.progress=i.progress,Ht.renderLevel(tt.progress);const c=tt.agents.get(i.agentId);if(c){const h=document.createElement("span");h.className="xpfloat",h.textContent=`+${i.gained} XP`,c.label.appendChild(h),setTimeout(()=>h.remove(),1800)}if(i.levelUp){setTimeout(()=>rn.levelUp(),700);const h=(o=tt.staff[tt.progress.capacity-1])==null?void 0:o.name,u=!tt.agents.has((l=tt.staff[tt.progress.capacity-1])==null?void 0:l.id);Ht.banner(`Level ${tt.progress.level}`,u?`${h} just joined the office.`:"The office is fully staffed."),op(!1)}}}}let Hc=0;function Ol(i,t){if(document.hidden){Hc++,document.title=`(${Hc}) Agent Office`;try{"Notification"in window&&Notification.permission==="granted"&&new Notification(i,{body:t,silent:!0})}catch{}}}document.addEventListener("visibilitychange",()=>{document.hidden||(Hc=0,document.title="Agent Office")});document.getElementById("composer").addEventListener("submit",()=>{try{"Notification"in window&&Notification.permission==="default"&&Notification.requestPermission()}catch{}},{once:!0});const J1='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5 6 9H3v6h3l5 4V5Z"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/><path d="M18.5 5.5a9 9 0 0 1 0 13"/></svg>',Q1='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5 6 9H3v6h3l5 4V5Z"/><path d="m22 9-6 6"/><path d="m16 9 6 6"/></svg>',no=document.getElementById("sound");function lp(){no.innerHTML=rn.muted?Q1:J1;const i=rn.muted?"Sound off":"Sound on";no.title=i,no.setAttribute("aria-label",i)}no.onclick=()=>{rn.setMuted(!rn.muted),lp(),rn.muted||rn.ship()};lp();const tb='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a3 3 0 0 1 3 3v5a3 3 0 0 1-6 0V6a3 3 0 0 1 3-3z"/><path d="M5 11a7 7 0 0 0 14 0"/><path d="M12 18v3"/></svg>',eb='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M9 9V6a3 3 0 0 1 5.6-1.5M15 11a3 3 0 0 1-4.5 2.6"/><path d="M5 11a7 7 0 0 0 11 5.7M19 11v0"/><path d="M12 18v3"/><path d="m3 3 18 18"/></svg>',Js=document.getElementById("speak");let gn={ok:!1,replies:!1};const cp=()=>gn.ok?gn.replies:ai.on;function or(){const i=cp();Js.innerHTML=i?tb:eb,Js.classList.toggle("on",i);const t=i?gn.ok?"Agents reply with voice notes":"Replies read aloud":"Replies are silent";Js.title=t,Js.setAttribute("aria-label",t)}ai.supported||(Js.hidden=!0);Js.onclick=async()=>{const i=!cp();if(!gn.ok){ai.setOn(i),or(),i&&ai.speak("Voice on. I will read replies out as they land.","chief",{force:!0});return}gn={...gn,replies:i},or();try{const t=await fetch("/api/voice/replies",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({on:i})});if(!t.ok)throw new Error((await t.json().catch(()=>({}))).error||`Request failed (${t.status})`)}catch(t){gn={...gn,replies:!i},or(),Ht.toast(t.message,"bad")}};or();function nb(i){gn.ok||!ai.on||i.from==="you"||i.to||i.kind==="chill"||Qn.active||ai.speak(i.text,i.from)}function ib(){let i=null;for(const t of tt.jobs.values())for(const e of t.log)e.todos&&(!i||e.ts>i.ts)&&(i=e);return(i==null?void 0:i.todos)||[]}const pn=new mr,sb=i=>i<.5?4*i*i*i:1-(-2*i+2)**3/2;let Ee=null,Es=!1;function hp(){Es=!0,Ee=null,Do=!0}function Ph({target:i,radius:t,phi:e,theta:n},s=.7){pn.setFromVector3(Me.position.clone().sub(Ae.target)),Ee={t:0,dur:s,target0:Ae.target.clone(),target1:(i||Ae.target).clone().setY(0),r0:pn.radius,r1:t??pn.radius,p0:pn.phi,p1:e??pn.phi,th0:pn.theta,th1:n??pn.theta}}function yo(i){Do=!0,pn.setFromVector3(Me.position.clone().sub(Ae.target));const t=Ee?Ee.th1:pn.theta;Ph({theta:t+i*Math.PI/4,target:Ee==null?void 0:Ee.target1},.55)}function up(){Es=!1,pn.setFromVector3(Me.position.clone().sub(Ae.target));let i=Ne.theta;for(;i-pn.theta>Math.PI;)i-=Math.PI*2;for(;pn.theta-i>Math.PI;)i+=Math.PI*2;Ph({target:Ne.target,radius:ip(Ne.phi,i,Ne.target),phi:Ne.phi,theta:i},.9)}Ae.addEventListener("start",()=>{Do=!0,Ee=null,Es=!1,setTimeout(()=>{var i;return(i=document.querySelector(".hint"))==null?void 0:i.classList.add("gone")},5e3)});document.getElementById("turnLeft").onclick=()=>yo(-1);document.getElementById("turnRight").onclick=()=>yo(1);document.getElementById("recenter").onclick=()=>up();document.getElementById("standup").onclick=()=>Ht.post("/api/standup");const Yi=new Set;addEventListener("keydown",i=>{var e;if(/INPUT|TEXTAREA|SELECT/.test((e=document.activeElement)==null?void 0:e.tagName)||i.metaKey||i.ctrlKey)return;const t=i.key.toLowerCase();t==="q"?yo(-1):t==="e"?yo(1):t==="r"?up():"wasd".includes(t)&&t.length===1&&(Yi.add(t),Ee=null,Es=!1)});addEventListener("keyup",i=>Yi.delete(i.key.toLowerCase()));addEventListener("blur",()=>Yi.clear());const $a=new R,Fl=new R,Vn=new R;function rb(i){if(Ee){Ee.t=Math.min(1,Ee.t+i/Ee.dur);const n=sb(Ee.t),s=Ee.target0.clone().lerp(Ee.target1,n);pn.set(fs.lerp(Ee.r0,Ee.r1,n),fs.lerp(Ee.p0,Ee.p1,n),fs.lerp(Ee.th0,Ee.th1,n)),Ae.target.copy(s),Me.position.setFromSpherical(pn).add(s),Ee.t>=1&&(Ee=null)}Vn.set(0,0,0);const t=Es&&tt.agents.get(tt.selected);if(t&&Vn.set(t.pos.x-Ae.target.x,0,t.pos.z-Ae.target.z).multiplyScalar(Math.min(1,i*3)),Yi.size){$a.subVectors(Ae.target,Me.position).setY(0).normalize(),Fl.crossVectors($a,Me.up).normalize();const n=.45*Me.position.distanceTo(Ae.target)*i;Yi.has("w")&&Vn.addScaledVector($a,n),Yi.has("s")&&Vn.addScaledVector($a,-n),Yi.has("d")&&Vn.addScaledVector(Fl,n),Yi.has("a")&&Vn.addScaledVector(Fl,-n)}Ae.target.add(Vn),Me.position.add(Vn),Ae.update();const e=Ae.target;Vn.set(fs.clamp(e.x,-19,19)-e.x,-e.y,fs.clamp(e.z,-14,14)-e.z),e.add(Vn),Me.position.add(Vn)}const Io=new Df,Ad=new rt;function Lh(i){const t=ze.domElement.getBoundingClientRect();Ad.set((i.clientX-t.left)/t.width*2-1,-((i.clientY-t.top)/t.height)*2+1),Io.setFromCamera(Ad,Me)}const dp=()=>[...tt.agents.values(),mn].map(i=>i.root);let io=null;ze.domElement.addEventListener("pointerdown",i=>{io=[i.clientX,i.clientY]});ze.domElement.addEventListener("pointerup",i=>{if(!io||Math.hypot(i.clientX-io[0],i.clientY-io[1])>5||i.button!==0)return;Lh(i);const t=Io.intersectObjects(dp(),!0)[0];t&&(t.object.userData.agentId==="chief"?(Ht.focusInput(),mn.say("Tell me what you need.","",3e3)):tt.select(t.object.userData.agentId))});ze.domElement.addEventListener("dblclick",i=>{Lh(i);const t=Io.intersectObject(vn.slab,!1)[0];t&&(Es=!1,Ph({target:t.point,radius:Math.min(Me.position.distanceTo(Ae.target),34)},.8))});ze.domElement.addEventListener("contextmenu",i=>i.preventDefault());ze.domElement.addEventListener("pointermove",i=>{i.buttons||(Lh(i),ze.domElement.style.cursor=Io.intersectObjects(dp(),!0).length?"pointer":"")});const Cd=new Lf;let Rd=0,Pd=0;function ab(i){vn.desks.forEach((t,e)=>{const n=tt.staff[e],s=n&&tt.agents.get(n.id),r=!s&&n&&tt.dismissed.has(n.id),a=s!=null&&s.job?"working":s?"break":r?"away":"open",o=a!=="open",l=`${(n==null?void 0:n.name)||""} ${a}`;if(t.plateKey!==l&&(t.plateKey=l,Ff(t,{name:o?n.name:"Open desk",accent:o?n.shirt:"#7d8a9c",state:a})),s!=null&&s.job){Ju(t,{title:s.job.repo,subtitle:s.job.title,lines:s.lines,accent:n.shirt,t:i}),t.idleKey=null;return}const c=s?`${n.name}`:r?`away ${n.name}`:"open";if(t.idleKey===c)return;t.idleKey=c;const h=tt.progress?e-1:0;Ju(t,s?{idle:!0,title:n.name,subtitle:"on a break"}:r?{idle:!0,title:n.name,subtitle:"gone home"}:{idle:!0,title:"Open desk",subtitle:`hires at level ${h}`})})}let Ld=!1;function fp(){const i=Math.min(Cd.getDelta(),.05),t=Cd.elapsedTime;rb(i),vn.updateWalls(Me,Ae.target,i);for(const s of tt.agents.values())s.update(i,t),s.gone&&(s.dispose(),tt.agents.delete(s.id),tt.selected===s.id&&tt.select(null));if(q1.update([...tt.agents.values()],t),Y1.update([...tt.agents.values()],t,i),mn.update(i,t),eo.update(i,t),rp.update(i),vn.globe.rotation.y+=i*.4,(Rd-=i)<=0&&(Rd=.4,ab(t)),(Pd-=i)<=0){Pd=.15;for(const s of vn.blinkers)Math.random()<.25&&(s.material.emissiveIntensity=Math.random()<.5?.15:1.4)}gr.render(i);const e=Me.position.distanceTo(Ae.target)>74,n=[];for(const s of[...tt.agents.values(),mn,...eo.list])e!==Ld&&(s.label.classList.toggle("far",e),s.labelDirty=!0),s.placeLabel(Me,Zs,ti),s.onScreen&&n.push(s);lb(n,i,t),eo.placeSign(Zs,ti),Ld=e,requestAnimationFrame(fp)}const ob=4,Dd=(i,t)=>i.left<t.right-1&&i.right>t.left+1&&i.top<t.bottom-1&&i.bottom>t.top+1;function lb(i,t,e){const n=[],s=r=>r.id===tt.selected?-1:r.depth;for(const r of[...i].sort((a,o)=>s(a)-s(o))){let a=0,o=!1;for(let h=0;h<2;h++){const u=Math.max(0,Math.min(o?140:80,r.anchorY-r.labelH-6));a=0;for(let d=0;d<10&&a<=u;d++){const f=r.labelBox(a),g=n.find(_=>Dd(_,f));if(!g)break;a+=f.bottom-g.top+ob}if(a<=u||o){a=Math.min(a,u);break}o=!0,r.setCrowded(!0,e)}o||r.setCrowded(!1,e),r.setLift(a,t);const l=r.labelBox(r.lift),c=n.some(h=>Dd(h,l));r.setBuried(c),c||n.push(l)}}Bf(vn.board,[]);Oc(vn.scribble,[]);Bc();fp();
4457
+ </button></span>`}).join("")}fit(){if(!this.open)return;const t=this.sessions.find(e=>e.id===this.active);if(!(!t||!t.el.clientHeight))try{t.fit.fit()}catch{}}}const vs=i=>String(i??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]);{const i=document.getElementById("app"),t=document.getElementById("side-grip"),e="office.sideWidth",n=320,s=24,r=()=>Math.max(n,Math.min(900,innerWidth-420)),a=u=>i.style.setProperty("--side-w",`${Math.round(Math.min(r(),Math.max(n,u)))}px`),o=Number(localStorage.getItem(e));o&&a(o);const l=()=>t.parentElement.getBoundingClientRect().width,c=()=>localStorage.setItem(e,String(Math.round(l())));t.addEventListener("pointerdown",u=>{t.setPointerCapture(u.pointerId),i.classList.add("resizing"),u.preventDefault()}),t.addEventListener("pointermove",u=>{t.hasPointerCapture(u.pointerId)&&a(u.clientX)});const h=u=>{t.hasPointerCapture(u.pointerId)&&(t.releasePointerCapture(u.pointerId),i.classList.remove("resizing"),c())};t.addEventListener("pointerup",h),t.addEventListener("pointercancel",h),t.addEventListener("dblclick",()=>{i.style.removeProperty("--side-w"),localStorage.removeItem(e)}),t.addEventListener("keydown",u=>{const d=u.key==="ArrowLeft"?-s:u.key==="ArrowRight"?s:0;d&&(u.preventDefault(),a(l()+d),c())})}{const i=document.getElementById("app"),t="office.sideZoom",e=.8,n=1.8,s=a=>(a=Math.round(Math.min(n,Math.max(e,a))*100)/100,i.style.setProperty("--side-zoom",String(a)),a===1?localStorage.removeItem(t):localStorage.setItem(t,String(a)),a);let r=Number(localStorage.getItem(t))||1;s(r),addEventListener("keydown",a=>{if(!(a.ctrlKey||a.metaKey)||a.altKey)return;const o=a.key;if(o==="+"||o==="=")r=s(r+.1);else if(o==="-"||o==="_")r=s(r-.1);else if(o==="0")r=s(1);else return;a.preventDefault()}),document.querySelector(".side").addEventListener("wheel",a=>{a.ctrlKey&&(a.preventDefault(),r=s(r-Math.sign(a.deltaY)*.05))},{passive:!1})}document.getElementById("view");const Ro=document.getElementById("stage"),$h=document.getElementById("labels"),Ve=new Ey({antialias:!0,alpha:!0});Ve.setClearColor(0,0);Ve.setPixelRatio(Math.min(devicePixelRatio,2));Ve.shadowMap.enabled=!0;Ve.shadowMap.type=pf;Ve.toneMapping=hh;Ve.toneMappingExposure=1;Ro.appendChild(Ve.domElement);const ti=new qf;ti.background=M1();ti.environment=new jc(Ve).fromScene(new hM,.04).texture;ti.environmentIntensity=.55;ti.add(new Gy("#fff8ef","#b9ab99",.55));const Ds=new jy("#fff0d8",1.75);Ds.position.set(-18,34,20);Ds.castShadow=!0;Ds.shadow.mapSize.set(4096,4096);Object.assign(Ds.shadow.camera,{left:-32,right:32,top:28,bottom:-28,near:1,far:100});Ds.shadow.bias=-3e-4;Ds.shadow.normalBias=.03;ti.add(Ds);const Me=new Cn(30,1,.5,400),Fe={target:new R(0,0,.5),radius:60,phi:.86,theta:Math.PI/4};Me.position.setFromSpherical(new wr(Fe.radius,Fe.phi,Fe.theta)).add(Fe.target);const Ae=new cM(Me,Ve.domElement);Ae.target.copy(Fe.target);Object.assign(Ae,{enableDamping:!0,dampingFactor:.09,minPolarAngle:.25,maxPolarAngle:1.22,minDistance:12,maxDistance:260,zoomToCursor:!0,rotateSpeed:.55,zoomSpeed:.9,panSpeed:1.1});const Tp=[];for(const i of[-20.3,20.3])for(const t of[-15.3,15.3])for(const e of[-.7,3])Tp.push(new R(i,e,t));function Ap(i,t,e){const n=Me.aspect<.9?1.7:.93,s=Me.clone();let r=15,a=260;for(let o=0;o<20;o++){const l=(r+a)/2;s.position.setFromSpherical(new wr(l,i,t)).add(e),s.lookAt(e),s.updateMatrixWorld(),Tp.every(h=>{const u=h.clone().project(s);return Math.abs(u.x)<n&&Math.abs(u.y)<.88})?a=l:r=l}return a}const Er=new gM(Ve,new Qn(1,1,{type:Ui,samples:4}));Er.addPass(new vM(ti,Me));const Ho=new ri(ti,Me,1,1);Ho.updateGtaoMaterial({radius:.9,distanceExponent:1.6,thickness:1.5,scale:1.1,samples:16});Ho.updatePdMaterial({lumaPhi:10,depthPhi:2,normalPhi:3,radius:6,rings:2,samples:16});Ho.blendIntensity=.85;Er.addPass(Ho);Er.addPass(new SM);function M1(){const i=document.createElement("canvas");i.width=512,i.height=512;const t=i.getContext("2d"),e=t.createRadialGradient(256,190,20,256,230,400);e.addColorStop(0,"#f7f3ec"),e.addColorStop(.6,"#ece5da"),e.addColorStop(1,"#d9d0c2"),t.fillStyle=e,t.fillRect(0,0,512,512);const n=new zi(i);return n.colorSpace=Ke,n}let ar=1,si=1,Vo=!1;function Cp(){const i=si;if(ar=Ro.clientWidth,si=Ro.clientHeight,Ve.setSize(ar,si,!1),Er.setPixelRatio(Math.min(devicePixelRatio,1.5)),Er.setSize(ar,si),Me.aspect=ar/si,Me.updateProjectionMatrix(),!Vo)Fe.radius=Ap(Fe.phi,Fe.theta,Fe.target),Me.position.setFromSpherical(new wr(Fe.radius,Fe.phi,Fe.theta)).add(Fe.target),Ae.target.copy(Fe.target);else if(i>1&&si>1&&si!==i){const t=Me.position.clone().sub(Ae.target),e=xs.clamp(t.length()*(si/i),Ae.minDistance,Ae.maxDistance);Me.position.copy(Ae.target).add(t.setLength(e))}}new ResizeObserver(Cp).observe(Ro);Cp();const Mn=$M(ti),Rp=new Ab(ti),Pp={id:"chief",name:"Chief",shirt:"#2b2d42",hair:"#8d8d8d",skin:"#a8714a"},tt={staff:[],chiefCost:0,modes:{},progress:null,jobs:new Map,agents:new Map,dismissed:new Set,selected:null,job:i=>tt.jobs.get(i),staffName:i=>{var t;return((t=tt.staff.find(e=>e.id===i))==null?void 0:t.name)||""},person:i=>{if(i==="you")return{name:"You",color:"#c9c1b4"};if(i==="chief")return{name:"Chief of Staff",color:Pp.shirt};const t=tt.staff.find(e=>e.id===i);return{name:(t==null?void 0:t.name)||i,color:(t==null?void 0:t.shirt)||"#999"}},onFloor:()=>{var i;return tt.staff.slice(0,((i=tt.progress)==null?void 0:i.capacity)||0).filter(t=>!tt.dismissed.has(t.id))},roster:()=>tt.onFloor().map(i=>{const t=[...tt.jobs.values()].find(e=>e.status==="working"&&e.agentId===i.id);return{name:i.name,color:i.shirt,note:t?`on ${t.repo}`:"free"}}),busyIn:i=>{const t=[...tt.jobs.values()].filter(e=>e.status==="working"&&e.repo===i).map(e=>tt.staffName(e.agentId));return t.length?`${t.join(", ")} here`:""}},Wh={scene:ti,...Mn,agentIndex:i=>tt.staff.findIndex(t=>t.id===i)},kt=new m1(tt);pm({toast:(i,t)=>kt.toast(i,t),renderOwner:i=>{Gt.on||kt.renderOwner(i)}});new y1({api:$e,toast:(i,t)=>kt.toast(i,t)});const xn=new Nh(Pp,Wh,$h,{desk:Mn.reception,face:0}),b1=new nb,S1=new Mb(ti,Mn),uo=new Tb({world:Wh,labels:$h,camera:Me,canvas:Ve.domElement});xn.want="desk";xn.teleport("desk");tt.mergeLog=i=>{const t=tt.jobs.get(i.id);t?t.log=i.log:tt.jobs.set(i.id,i)};tt.refreshLists=()=>{const i=[...tt.jobs.values()];kt.renderJobs(i,tt.staffName),kt.renderStats(i,tt.chiefCost),hp(Mn.board,i)};tt.openJob=i=>{kt.openDetail(i);const t=tt.jobs.get(i),e=(t==null?void 0:t.status)==="working"&&tt.agents.get(t.agentId);e&&(tt.select(e.id,!1),kp())};tt.select=(i,t=!0)=>{for(const r of tt.agents.values())r.setSelected(r.id===i);if(tt.selected=i,i||(Is=!1),!i||!t)return;const e=tt.agents.get(i);kp(),kt.focusInput(`@${e.name} `);const n=[...tt.jobs.values()].filter(r=>r.agentId===i),s=n.find(r=>r.status==="working")||n.sort((r,a)=>(a.endedAt||0)-(r.endedAt||0))[0];s&&kt.openDetail(s.id),(s==null?void 0:s.status)!=="working"&&kt.toast(`${e.name} is between jobs. Press N to give them one.`,"",{label:"Send home",run:()=>tt.dismiss(e.id)})};tt.dismiss=i=>!Gt.on&&kt.post(`/api/staff/${i}/dismiss`);tt.recall=i=>!Gt.on&&kt.post(`/api/staff/${i}/recall`);function Lp(i,t){tt.onFloor().forEach(e=>{const n=tt.agents.get(e.id);if(n){n.leaving&&n.stay();return}const s=new Nh(e,Wh,$h);tt.agents.set(e.id,s),i?s.teleport("lounge"):(s.teleport("door"),s.say(t||`Hi, I'm ${e.name}!`,"good",5e3))})}function Gd(i,t){tt.dismissed=new Set(i||[]);for(const e of tt.agents.values())!tt.dismissed.has(e.id)||e.leaving||e.job||(t?e.gone=!0:e.leave());Lp(t,"Back in!"),kt.renderAway(tt.staff.filter(e=>tt.dismissed.has(e.id))),kt.renderTeam()}function w1(i){var t,e;for(const n of tt.agents.values()){const s=[...tt.jobs.values()].find(r=>r.status==="working"&&r.agentId===n.id);s&&((t=n.job)==null?void 0:t.id)!==s.id?(n.assign(s,i),s.log.forEach(r=>n.onLog(r))):!s&&n.job&&n.finish(((e=tt.jobs.get(n.job.id))==null?void 0:e.status)||"stopped")}}function $d(i=[],t=!1){const e=Mn.standup;xn.meet(e[0],t),i.forEach((n,s)=>{var r;return(r=tt.agents.get(n))==null?void 0:r.meet(e[1+Math.round(s*(e.length-2)/Math.max(1,i.length-1))],t)}),tt.standupOn=!0,document.getElementById("standup").disabled=!0}function Wd(){xn.adjourn();for(const i of tt.agents.values())i.adjourn();tt.standupOn=!1,document.getElementById("standup").disabled=!1}let Ja=!0;function th(){const i=Gt.on?`/ws/visit/${encodeURIComponent(Gt.link)}`:"/ws",t=new WebSocket(`${location.protocol==="https:"?"wss":"ws"}://${location.host}${i}`);t.onmessage=e=>E1(JSON.parse(e.data)),t.onclose=e=>{const n=um(e.code);if(n!=null){n&&setTimeout(th,n);return}kt.toast("Lost the office line. Reconnecting…","bad"),setTimeout(th,1500)}}function E1(i){var t,e,n,s,r,a,o,l;if(!uo.handle(i)){if(i.t==="hello"){lm(i.visiting),tt.staff=i.staff,i.visiting||kt.renderOwner(i.owner),tt.voice=i.voice,yn=i.tts||yn,vr(),tt.modes=hm(i.modes),tt.progress=i.progress,tt.chiefCost=i.chiefCost||0,tt.jobs=new Map(i.jobs.map(h=>[h.id,h])),kt.renderChannels(i.channels||[{id:"general",name:"general"}]),kt.renderChat(i.chat||[]),kt.chiefBusy(i.chiefBusy),Gd(i.dismissed,Ja),w1(Ja),i.standup?$d(i.standup.who,Ja):tt.standupOn&&Wd(),Ja=!1,kt.renderLevel(tt.progress),kt.renderUsage(i.usage),Jl(i.auth),Yo(i.contextLimit),i.visiting||au(i),cu(i.leaderboard),_r(i.links),kt.renderProc(i.procs,i.machine),tt.refreshLists();const c=L1();Zc(Mn.scribble,c),kt.openId&&(tt.jobs.has(kt.openId)?kt.openDetail(kt.openId):kt.closeDetail())}else if(i.t==="job"){const c=tt.jobs.get(i.job.id),h={...i.job,log:(c==null?void 0:c.log)||[]};if(tt.jobs.set(h.id,h),h.status==="working"){const u=tt.agents.get(h.agentId);u&&((t=u.job)==null?void 0:t.id)!==h.id?u.assign(h):u&&(u.job=h)}else for(const u of tt.agents.values()){if(((e=u.job)==null?void 0:e.id)!==h.id)continue;const d=h.status==="done"&&!h.awaitingBoss;u.finish(d?"done":h.awaitingBoss?"waiting":h.status),d&&Rp.burst(u.pos,[u.staff.shirt,"#f2cc8f","#81b29a","#3d7ea6","#ffffff"]),d&&(cn.ship(),Yl(`${u.name} shipped`,h.title)),h.status==="failed"&&(cn.fail(),Yl(`${u.name} hit a wall`,h.title))}(c==null?void 0:c.status)!==h.status?(kt.openId===h.id&&kt.renderDetail(),h.awaitingBoss&&(c==null?void 0:c.status)==="working"?kt.toast(`${tt.staffName(h.agentId)} is waiting on you: “${h.title}”`,"warn"):h.status==="done"&&(c==null?void 0:c.status)==="working"&&kt.toast(`${tt.staffName(h.agentId)} shipped “${h.title}”`,"good"),h.status==="failed"&&(c==null?void 0:c.status)==="working"&&kt.toast(`${tt.staffName(h.agentId)} hit a wall on “${h.title}”`,"bad")):kt.openId===h.id&&((n=c==null?void 0:c.changes)==null?void 0:n.end)!==((s=h.changes)==null?void 0:s.end)&&kt.renderChanges(h),tt.refreshLists()}else if(i.t==="log"){const c=tt.jobs.get(i.jobId);if(!c)return;c.log.push(i.entry),c.log.length>600&&c.log.shift();for(const h of tt.agents.values())((r=h.job)==null?void 0:r.id)===c.id&&h.onLog(i.entry);i.entry.todos&&Zc(Mn.scribble,i.entry.todos),kt.appendLog(c.id,i.entry)}else if(i.t==="channels")kt.renderChannels(i.channels);else if(i.t==="chat"){kt.addMessage(i.msg);const c=tt.agents.get(i.msg.from),h=tt.agents.get(i.msg.to);if(c&&h&&(c.visit(h,i.msg.text),cn.knock()),P1(i.msg),i.msg.kind==="flag"&&(cn.knock(),Yl("The boss is needed",i.msg.text.replace(/\*\*/g,""))),i.msg.kind==="standup"){const u=i.msg.say||i.msg.text;(a=i.msg.from==="chief"?xn:c)==null||a.speak(u.length>90?u.slice(0,89)+"…":u)}else i.msg.from==="chief"&&(xn.job=null,xn.say(i.msg.text.length>90?i.msg.text.slice(0,89)+"…":i.msg.text,"",6e3))}else if(i.t==="forget")kt.forget(i.ids);else if(i.t==="voice"){const c=kt.addVoice(i.id,i.file);c&&yn.replies&&!ii.active&&!document.hidden&&c.play().catch(()=>{})}else if(i.t==="tts")yn={...yn,...i},vr();else if(i.t==="react")kt.setReactions(i.id,i.reactions);else if(i.t==="standup")i.phase==="start"?($d(i.who),kt.banner("Standup","Everyone to the whiteboard."),cn.knock()):Wd();else if(i.t==="chief")kt.chiefBusy(i.busy),i.busy?(xn.job={id:"routing"},xn.say("Reading your message…","thinking")):xn.job=null,i.cost!==void 0&&(tt.chiefCost=i.cost,tt.refreshLists());else if(i.t==="staff")Gd(i.dismissed,!1);else if(i.t==="profile"){const c=tt.staff.find(h=>h.id===i.id);c&&Object.assign(c,i.profile),kt.renderTeam()}else if(i.t==="auth")Jl(i.auth);else if(i.t==="contextLimit")Yo(i.contextLimit);else if(i.t==="settings")Yo(i.contextLimit),au(i);else if(i.t==="leaderboard")cu(i.leaderboard);else if(i.t==="links")_r(i);else if(i.t==="usage")kt.renderUsage(i.usage);else if(i.t==="proc")kt.renderProc(i.procs,i.machine);else if(i.t==="xp"){tt.progress=i.progress,kt.renderLevel(tt.progress);const c=tt.agents.get(i.agentId);if(c){const h=document.createElement("span");h.className="xpfloat",h.textContent=`+${i.gained} XP`,c.label.appendChild(h),setTimeout(()=>h.remove(),1800)}if(i.levelUp){setTimeout(()=>cn.levelUp(),700);const h=(o=tt.staff[tt.progress.capacity-1])==null?void 0:o.name,u=!tt.agents.has((l=tt.staff[tt.progress.capacity-1])==null?void 0:l.id);kt.banner(`Level ${tt.progress.level}`,u?`${h} just joined the office.`:"The office is fully staffed."),Lp(!1)}}}}let eh=0;function Yl(i,t){if(document.hidden){eh++,document.title=`(${eh}) Agent Office`;try{"Notification"in window&&Notification.permission==="granted"&&new Notification(i,{body:t,silent:!0})}catch{}}}document.addEventListener("visibilitychange",()=>{document.hidden||(eh=0,document.title="Agent Office")});document.getElementById("composer").addEventListener("submit",()=>{try{"Notification"in window&&Notification.permission==="default"&&Notification.requestPermission()}catch{}},{once:!0});const T1='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5 6 9H3v6h3l5 4V5Z"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/><path d="M18.5 5.5a9 9 0 0 1 0 13"/></svg>',A1='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5 6 9H3v6h3l5 4V5Z"/><path d="m22 9-6 6"/><path d="m16 9 6 6"/></svg>',fo=document.getElementById("sound");function Dp(){fo.innerHTML=cn.muted?A1:T1;const i=cn.muted?"Sound off":"Sound on";fo.title=i,fo.setAttribute("aria-label",i)}fo.onclick=()=>{cn.setMuted(!cn.muted),Dp(),cn.muted||cn.ship()};Dp();const C1='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a3 3 0 0 1 3 3v5a3 3 0 0 1-6 0V6a3 3 0 0 1 3-3z"/><path d="M5 11a7 7 0 0 0 14 0"/><path d="M12 18v3"/></svg>',R1='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M9 9V6a3 3 0 0 1 5.6-1.5M15 11a3 3 0 0 1-4.5 2.6"/><path d="M5 11a7 7 0 0 0 11 5.7M19 11v0"/><path d="M12 18v3"/><path d="m3 3 18 18"/></svg>',or=document.getElementById("speak");let yn={ok:!1,replies:!1};const Ip=()=>yn.ok?yn.replies:hi.on;function vr(){const i=Ip();or.innerHTML=i?C1:R1,or.classList.toggle("on",i);const t=i?yn.ok?"Agents reply with voice notes":"Replies read aloud":"Replies are silent";or.title=t,or.setAttribute("aria-label",t)}hi.supported||(or.hidden=!0);or.onclick=async()=>{const i=!Ip();if(!yn.ok){hi.setOn(i),vr(),i&&hi.speak("Voice on. I will read replies out as they land.","chief",{force:!0});return}yn={...yn,replies:i},vr();try{const t=await fetch("/api/voice/replies",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({on:i})});if(!t.ok)throw new Error((await t.json().catch(()=>({}))).error||`Request failed (${t.status})`)}catch(t){yn={...yn,replies:!i},vr(),kt.toast(t.message,"bad")}};vr();function P1(i){yn.ok||!hi.on||i.from==="you"||i.to||i.kind==="chill"||ii.active||hi.speak(i.text,i.from)}function L1(){let i=null;for(const t of tt.jobs.values())for(const e of t.log)e.todos&&(!i||e.ts>i.ts)&&(i=e);return(i==null?void 0:i.todos)||[]}const _n=new wr,D1=i=>i<.5?4*i*i*i:1-(-2*i+2)**3/2;let Ee=null,Is=!1;function kp(){Is=!0,Ee=null,Vo=!0}function Xh({target:i,radius:t,phi:e,theta:n},s=.7){_n.setFromVector3(Me.position.clone().sub(Ae.target)),Ee={t:0,dur:s,target0:Ae.target.clone(),target1:(i||Ae.target).clone().setY(0),r0:_n.radius,r1:t??_n.radius,p0:_n.phi,p1:e??_n.phi,th0:_n.theta,th1:n??_n.theta}}function Po(i){Vo=!0,_n.setFromVector3(Me.position.clone().sub(Ae.target));const t=Ee?Ee.th1:_n.theta;Xh({theta:t+i*Math.PI/4,target:Ee==null?void 0:Ee.target1},.55)}function Np(){Is=!1,_n.setFromVector3(Me.position.clone().sub(Ae.target));let i=Fe.theta;for(;i-_n.theta>Math.PI;)i-=Math.PI*2;for(;_n.theta-i>Math.PI;)i+=Math.PI*2;Xh({target:Fe.target,radius:Ap(Fe.phi,i,Fe.target),phi:Fe.phi,theta:i},.9)}Ae.addEventListener("start",()=>{Vo=!0,Ee=null,Is=!1,setTimeout(()=>{var i;return(i=document.querySelector(".hint"))==null?void 0:i.classList.add("gone")},5e3)});document.getElementById("turnLeft").onclick=()=>Po(-1);document.getElementById("turnRight").onclick=()=>Po(1);document.getElementById("recenter").onclick=()=>Np();document.getElementById("standup").onclick=()=>kt.post("/api/standup");const es=new Set;addEventListener("keydown",i=>{var e;if(/INPUT|TEXTAREA|SELECT/.test((e=document.activeElement)==null?void 0:e.tagName)||i.metaKey||i.ctrlKey)return;const t=i.key.toLowerCase();t==="q"?Po(-1):t==="e"?Po(1):t==="r"?Np():"wasd".includes(t)&&t.length===1&&(es.add(t),Ee=null,Is=!1)});addEventListener("keyup",i=>es.delete(i.key.toLowerCase()));addEventListener("blur",()=>es.clear());const Qa=new R,Kl=new R,Wn=new R;function I1(i){if(Ee){Ee.t=Math.min(1,Ee.t+i/Ee.dur);const n=D1(Ee.t),s=Ee.target0.clone().lerp(Ee.target1,n);_n.set(xs.lerp(Ee.r0,Ee.r1,n),xs.lerp(Ee.p0,Ee.p1,n),xs.lerp(Ee.th0,Ee.th1,n)),Ae.target.copy(s),Me.position.setFromSpherical(_n).add(s),Ee.t>=1&&(Ee=null)}Wn.set(0,0,0);const t=Is&&tt.agents.get(tt.selected);if(t&&Wn.set(t.pos.x-Ae.target.x,0,t.pos.z-Ae.target.z).multiplyScalar(Math.min(1,i*3)),es.size){Qa.subVectors(Ae.target,Me.position).setY(0).normalize(),Kl.crossVectors(Qa,Me.up).normalize();const n=.45*Me.position.distanceTo(Ae.target)*i;es.has("w")&&Wn.addScaledVector(Qa,n),es.has("s")&&Wn.addScaledVector(Qa,-n),es.has("d")&&Wn.addScaledVector(Kl,n),es.has("a")&&Wn.addScaledVector(Kl,-n)}Ae.target.add(Wn),Me.position.add(Wn),Ae.update();const e=Ae.target;Wn.set(xs.clamp(e.x,-19,19)-e.x,-e.y,xs.clamp(e.z,-14,14)-e.z),e.add(Wn),Me.position.add(Wn)}const Go=new np,Xd=new rt;function jh(i){const t=Ve.domElement.getBoundingClientRect();Xd.set((i.clientX-t.left)/t.width*2-1,-((i.clientY-t.top)/t.height)*2+1),Go.setFromCamera(Xd,Me)}const Up=()=>[...tt.agents.values(),xn].map(i=>i.root);let po=null;Ve.domElement.addEventListener("pointerdown",i=>{po=[i.clientX,i.clientY]});Ve.domElement.addEventListener("pointerup",i=>{if(!po||Math.hypot(i.clientX-po[0],i.clientY-po[1])>5||i.button!==0)return;jh(i);const t=Go.intersectObjects(Up(),!0)[0];t&&(t.object.userData.agentId==="chief"?(kt.focusInput(),xn.say("Tell me what you need.","",3e3)):tt.select(t.object.userData.agentId))});Ve.domElement.addEventListener("dblclick",i=>{jh(i);const t=Go.intersectObject(Mn.slab,!1)[0];t&&(Is=!1,Xh({target:t.point,radius:Math.min(Me.position.distanceTo(Ae.target),34)},.8))});Ve.domElement.addEventListener("contextmenu",i=>i.preventDefault());Ve.domElement.addEventListener("pointermove",i=>{i.buttons||(jh(i),Ve.domElement.style.cursor=Go.intersectObjects(Up(),!0).length?"pointer":"")});const jd=new ep;let qd=0,Yd=0;function k1(i){Mn.desks.forEach((t,e)=>{const n=tt.staff[e],s=n&&tt.agents.get(n.id),r=!s&&n&&tt.dismissed.has(n.id),a=s!=null&&s.job?"working":s?"break":r?"away":"open",o=a!=="open",l=`${(n==null?void 0:n.name)||""} ${a}`;if(t.plateKey!==l&&(t.plateKey=l,lp(t,{name:o?n.name:"Open desk",accent:o?n.shirt:"#7d8a9c",state:a})),s!=null&&s.job){vd(t,{title:s.job.repo,subtitle:s.job.title,lines:s.lines,accent:n.shirt,t:i}),t.idleKey=null;return}const c=s?`${n.name}`:r?`away ${n.name}`:"open";if(t.idleKey===c)return;t.idleKey=c;const h=tt.progress?e-1:0;vd(t,s?{idle:!0,title:n.name,subtitle:"on a break"}:r?{idle:!0,title:n.name,subtitle:"gone home"}:{idle:!0,title:"Open desk",subtitle:`hires at level ${h}`})})}let Kd=!1;function Op(){const i=Math.min(jd.getDelta(),.05),t=jd.elapsedTime;I1(i),Mn.updateWalls(Me,Ae.target,i);for(const s of tt.agents.values())s.update(i,t),s.gone&&(s.dispose(),tt.agents.delete(s.id),tt.selected===s.id&&tt.select(null));if(b1.update([...tt.agents.values()],t),S1.update([...tt.agents.values()],t,i),xn.update(i,t),uo.update(i,t),Rp.update(i),Mn.globe.rotation.y+=i*.4,(qd-=i)<=0&&(qd=.4,k1(t)),(Yd-=i)<=0){Yd=.15;for(const s of Mn.blinkers)Math.random()<.25&&(s.material.emissiveIntensity=Math.random()<.5?.15:1.4)}Er.render(i);const e=Me.position.distanceTo(Ae.target)>74,n=[];for(const s of[...tt.agents.values(),xn,...uo.list])e!==Kd&&(s.label.classList.toggle("far",e),s.labelDirty=!0),s.placeLabel(Me,ar,si),s.onScreen&&n.push(s);U1(n,i,t),uo.placeSign(ar,si),Kd=e,requestAnimationFrame(Op)}const N1=4,Zd=(i,t)=>i.left<t.right-1&&i.right>t.left+1&&i.top<t.bottom-1&&i.bottom>t.top+1;function U1(i,t,e){const n=[],s=r=>r.id===tt.selected?-1:r.depth;for(const r of[...i].sort((a,o)=>s(a)-s(o))){let a=0,o=!1;for(let h=0;h<2;h++){const u=Math.max(0,Math.min(o?140:80,r.anchorY-r.labelH-6));a=0;for(let d=0;d<10&&a<=u;d++){const f=r.labelBox(a),g=n.find(_=>Zd(_,f));if(!g)break;a+=f.bottom-g.top+N1}if(a<=u||o){a=Math.min(a,u);break}o=!0,r.setCrowded(!0,e)}o||r.setCrowded(!1,e),r.setLift(a,t);const l=r.labelBox(r.lift),c=n.some(h=>Zd(h,l));r.setBuried(c),c||n.push(l)}}hp(Mn.board,[]);Zc(Mn.scribble,[]);th();Op();