@rr0/ufoathome 0.105.2 → 0.105.3

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.
@@ -769,7 +769,7 @@ ${iM.CSS}
769
769
  margin: 0.4em 0 0;
770
770
  padding-left: 1.2em;
771
771
  }
772
- `;class Ka extends Error{constructor(t,e,i){super(`${t}: ${e}${i===void 0?"":` (HTTP ${i})`}`),this.kind=t,this.url=e,this.status=i,this.name="SightingFetchError"}}class Gc{static async json(t){const e=new URL(t,location.href);if(location.protocol==="https:"&&e.protocol==="http:")throw new Ka("mixed-content",t);let i;try{i=await fetch(t)}catch{throw await this.diagnose(t,e)}if(!i.ok)throw new Ka("status",t,i.status);try{return await i.json()}catch{throw new Ka("malformed",t)}}static async diagnose(t,e){if(e.origin===location.origin)return new Ka("unreachable",t);try{return await fetch(t,{mode:"no-cors"}),new Ka("cors",t)}catch{return new Ka("unreachable",t)}}}class hn{constructor(t){this.entries=t}static empty(){return new hn(new Map)}get size(){return this.entries.size}at(t){return this.entries.get(t)}paths(){return[...this.entries.keys()]}set(t,e){e.basis==="stated"&&e.rationale===void 0?this.entries.delete(t):this.entries.set(t,e)}clear(t){for(const e of this.entries.keys())(e===t||e.startsWith(`${t}.`))&&this.entries.delete(e)}static strip(t){const e=new hn(new Map);return{recording:hn.stripValue(t,[],e),provenance:e}}static restore(t,e){if(e.size===0)return t;const i=structuredClone(t);for(const n of e.paths()){const s=e.at(n),r=n.split("."),o=hn.holderOf(i,r);if(!o)continue;const c=r[r.length-1],l=o[c];l!==void 0&&(s.of!==void 0&&JSON.stringify(s.of)!==JSON.stringify(l)||(o[c]={value:l,...s.basis==="stated"?{}:{basis:s.basis},...s.rationale===void 0?{}:{rationale:s.rationale}}))}return i}static isWrapper(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&"value"in t}static stripValue(t,e,i){return hn.isWrapper(t)?(i.set(e.join("."),{basis:t.basis??"stated",...t.rationale===void 0?{}:{rationale:t.rationale},of:t.value}),hn.stripValue(t.value,e,i)):Array.isArray(t)?t.map((n,s)=>hn.stripValue(n,[...e,String(s)],i)):typeof t=="object"&&t!==null?Object.fromEntries(Object.entries(t).map(([n,s])=>[n,hn.stripValue(s,[...e,n],i)])):t}static holderOf(t,e){let i=t;for(const n of e.slice(0,-1)){if(typeof i!="object"||i===null)return;i=i[n]}return typeof i=="object"&&i!==null?i:void 0}}class cs{static SIGHTING_EVENT="sighting";static INTERPRETATION_EVENT="interpretation";static isCase(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Array.isArray(t.events)&&!("timeline"in t)}static sightingUrls(t,e){return(t.events??[]).filter(i=>i.eventType===cs.SIGHTING_EVENT&&!i.interpretationOf&&typeof i.url=="string"&&i.url!=="").map(i=>new URL(i.url,e).href)}static interpretationEvents(t,e){return e?(t.events??[]).filter(i=>i.eventType===cs.INTERPRETATION_EVENT?i.sighting===e:i.eventType!==cs.SIGHTING_EVENT||i.interpretationOf===void 0?!1:[i.interpretationOf].flat().includes(e)).map(i=>i):[]}static async interpretationOf(t,e,i){if(t.bodies||t.reentries)return cs.withModelsFrom(hn.strip({title:t.title,bodies:t.bodies??[],smoke:t.smoke,reentries:t.reentries}).recording,e);if(!t.url)return{title:t.title,bodies:[]};const n=new URL(t.url,e).href,s=await i(n),r="timeline"in s&&s.interpretation?s.interpretation:s;return cs.withModelsFrom(hn.strip({title:t.title??r.title,bodies:r.bodies??[],smoke:r.smoke,reentries:r.reentries}).recording,n)}static withModelsFrom(t,e){return{...t,bodies:t.bodies.map(i=>i.model?.url?{...i,model:{...i.model,url:new URL(i.model.url,e).href}}:i)}}}class Vc{static ISO=/^P(?:(\d+(?:[.,]\d+)?)W)?(?:(\d+(?:[.,]\d+)?)D)?(?:T(?:(\d+(?:[.,]\d+)?)H)?(?:(\d+(?:[.,]\d+)?)M)?(?:(\d+(?:[.,]\d+)?)S)?)?$/;static seconds(t){const e=t.trim().toUpperCase(),i=Vc.ISO.exec(e);if(!i||e==="P"||e.endsWith("T"))return;const[,n,s,r,o,c]=i,l=u=>u===void 0?0:Number(u.replace(",",".")),h=l(n)*604800+l(s)*86400+l(r)*3600+l(o)*60+l(c);return Number.isFinite(h)?h:void 0}static parse(t){let e=t.trim();if(e==="")return;const i=e.slice(-1),n="?~%".includes(i)?i:"";n!==""&&(e=e.slice(0,-1).trim());const s=e.split("/");if(s.length>2)return;const r=s.map(u=>Vc.seconds(u));if(r.some(u=>u===void 0))return;const[o,c]=r,l=Math.min(o,c??o),h=Math.max(o,c??o);return{doubt:n,minSeconds:l,maxSeconds:h,chosenSeconds:(l+h)/2}}static isExact(t){const e=Vc.parse(t);return e!==void 0&&e.doubt===""&&e.minSeconds===e.maxSeconds}static format(t){const e=Math.max(0,Math.round(t*10)/10),i=Math.floor(e/3600),n=Math.floor(e%3600/60),s=Math.round(e%60*10)/10;return`PT${`${i>0?`${i}H`:""}${n>0?`${n}M`:""}${s>0||i===0&&n===0?`${s}S`:""}`}`}static say(t){const e=Math.round(t*10)/10;if(e<60)return`${e} s`;const i=Math.floor(e/3600),n=Math.floor(e%3600/60),s=Math.round(e%60*10)/10,r=[];return i>0&&r.push(`${i} h`),n>0&&r.push(`${n} min`),s>0&&r.push(`${s} s`),r.join(" ")}}class Fe{static MOON_ANGULAR_WIDTH_DEG=.5237;static CANVAS_WIDTH_PX=640;static CANVAS_HEIGHT_PX=360;static angularWidthDeg(t){return 2*Math.atan(t.sizeM/(2*t.distanceM))*180/Math.PI}static inMoons(t){return t/Fe.MOON_ANGULAR_WIDTH_DEG}static lerpAngular(t,e,i){if(!(!t||!e))return{widthDeg:t.widthDeg+(e.widthDeg-t.widthDeg)*i,heightDeg:t.heightDeg+(e.heightDeg-t.heightDeg)*i}}static sizeMAt(t,e){return 2*t*Math.tan(e*Math.PI/360)}static distanceMAt(t,e){return t/(2*Math.tan(e*Math.PI/360))}}function Sy(a,t,e){if(!a||!t)return e<1?a:t;const i=((t.azimuthDeg-a.azimuthDeg)%360+540)%360-180;return{azimuthDeg:((a.azimuthDeg+i*e)%360+360)%360,altitudeDeg:a.altitudeDeg+(t.altitudeDeg-a.altitudeDeg)*e}}function wy(a,t,e){const{bounds:i}=a;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height}function vn(a,t,e){return a+(t-a)*e}function Em(a){const t=/^#([0-9a-f]{6})$/i.exec(a);if(!t)return;const e=parseInt(t[1],16);return[e>>16&255,e>>8&255,e&255]}function _y(a){return`#${a.map(t=>Math.round(t).toString(16).padStart(2,"0")).join("")}`}function Ey(a,t,e){const i=Em(a),n=Em(t);return!i||!n?e<1?a:t:_y([vn(i[0],n[0],e),vn(i[1],n[1],e),vn(i[2],n[2],e)])}function Ay(a,t,e){const i={x:vn(a.bounds.x,t.bounds.x,e),y:vn(a.bounds.y,t.bounds.y,e),width:vn(a.bounds.width,t.bounds.width,e),height:vn(a.bounds.height,t.bounds.height,e)},n=vn(a.angle,t.angle,e),s=vn(a.transparency,t.transparency,e),r=vn(a.haloScale,t.haloScale,e),o=vn(a.blur??0,t.blur??0,e),c=vn(a.brightness??0,t.brightness??0,e),l=Ey(a.color,t.color,e),h=Fe.lerpAngular(a.angular,t.angular,e),u=Sy(a.aim,t.aim,e);return a.kind==="polygon"&&t.kind==="polygon"&&a.points.length===t.points.length?{...a,bounds:i,angle:n,transparency:s,haloScale:r,blur:o,brightness:c,color:l,angular:h,aim:u,points:a.points.map((d,f)=>({x:vn(d.x,t.points[f].x,e),y:vn(d.y,t.points[f].y,e)}))}:{...e<1?a:t,bounds:i,angle:n,transparency:s,haloScale:r,blur:o,brightness:c,color:l,angular:h,aim:u}}class aa{static DEFAULT_COLOR="#e8e6df";static complete(t,e=[]){const i=new Map;return t.map((n,s)=>({keyframe:n,index:s})).sort((n,s)=>n.keyframe.t-s.keyframe.t).map(({keyframe:n,index:s})=>({t:n.t,shapes:(n.shapes??[]).map((r,o)=>{const c=`timeline.keyframes.${s}.shapes.${o}.shape`,l=aa.completed(r,i.get(r.sourceId),c,e);return i.set(r.sourceId,l),{sourceId:r.sourceId,shape:l}})}))}static completed(t,e,i,n){const s=t.shape??{},r=e??aa.firstAppearance(s,i,n),o={...r};s.bounds&&e&&(e.aim||e.angular)&&!s.aim&&!s.angular&&n.push({kind:"pixels-over-angles",path:i}),s.bounds&&(s.aim||delete o.aim,s.angular||delete o.angular);const c=s.kind??r.kind??"oval",l={...o,...s,kind:c};if(c==="polygon"&&!l.points){n.push({kind:"defaulted",path:`${i}.points`,expected:"rectangle"});const{width:h,height:u}=l.bounds;return{...l,points:[{x:0,y:0},{x:h,y:0},{x:h,y:u},{x:0,y:u}]}}return l}static firstAppearance(t,e,i){return t.kind||i.push({kind:"defaulted",path:`${e}.kind`,expected:'"oval"'}),t.color||i.push({kind:"defaulted",path:`${e}.color`,expected:`"${aa.DEFAULT_COLOR}"`}),!t.bounds&&!t.aim&&i.push({kind:"unplaced",path:e}),!t.bounds&&!t.angular&&i.push({kind:"unsized",path:e}),{kind:t.kind??"oval",bounds:{...aa.NEUTRAL_BOUNDS},color:aa.DEFAULT_COLOR,angle:0,transparency:0,haloScale:0,selected:!1}}static NEUTRAL_BOUNDS={x:Fe.CANVAS_WIDTH_PX/2,y:Fe.CANVAS_HEIGHT_PX/2,width:1,height:1}}class Ku{keyframes=[];order=[];groups=[];addKeyframe(t,e){const i=this.findInsertIndex(t);if(this.keyframes[i]?.t===t){const n=new Set(e.map(s=>s.sourceId));this.keyframes[i]={t,shapes:[...this.keyframes[i].shapes.filter(s=>!n.has(s.sourceId)),...e]}}else this.keyframes.splice(i,0,{t,shapes:[...e]});for(const n of e)this.order.includes(n.sourceId)||this.order.push(n.sourceId)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getKeyframeAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e];return i?.t===t?i:void 0}getShapeAt(t,e){return this.getKeyframeAt(t)?.shapes.find(i=>i.sourceId===e)?.shape}getLatestShapeAt(t,e){let i=this.findInsertIndex(t);for(this.keyframes[i]?.t!==t&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return n.shape}}getInterpolatedShapeAt(t,e){const i=this.findShapeAtOrBefore(t,e);if(i?.t===t)return i.shape;const n=this.findShapeAtOrAfter(t,e);return i?n?Ay(i.shape,n.shape,(t-i.t)/(n.t-i.t)):i.shape:n?.shape}findShapeAtOrBefore(t,e){let i=this.findInsertIndex(t);for(this.keyframes[i]?.t!==t&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}findShapeAtOrAfter(t,e){for(let i=this.findInsertIndex(t);i<this.keyframes.length;i++){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}hitTest(t,e,i,n){const s=this.sourceIds;for(let r=s.length-1;r>=0;r--){if(n?.has(s[r]))continue;const o=this.getInterpolatedShapeAt(t,s[r]);if(o&&wy(o,e,i))return{sourceId:s[r],shape:o}}}removeSource(t){for(let e=this.keyframes.length-1;e>=0;e--){const i=this.keyframes[e].shapes.filter(n=>n.sourceId!==t);i.length===0?this.keyframes.splice(e,1):i.length!==this.keyframes[e].shapes.length&&(this.keyframes[e]={t:this.keyframes[e].t,shapes:i})}this.order=this.order.filter(e=>e!==t),this.removeFromGroup(t)}group(t){if(!(t.length<2)){for(const e of t)this.removeFromGroup(e);this.groups.push([...t])}}ungroup(t){const e=this.groups.findIndex(i=>i.includes(t));e!==-1&&this.groups.splice(e,1)}groupMembers(t){return this.groups.find(e=>e.includes(t))}removeFromGroup(t){const e=this.groups.findIndex(n=>n.includes(t));if(e===-1)return;const i=this.groups[e].filter(n=>n!==t);i.length<2?this.groups.splice(e,1):this.groups[e]=i}bringToFront(t){const e=this.order.indexOf(t);e!==-1&&(this.order.splice(e,1),this.order.push(t))}sendToBack(t){const e=this.order.indexOf(t);e!==-1&&(this.order.splice(e,1),this.order.unshift(t))}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get sourceIds(){return[...this.order]}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes,order:this.order,groups:this.groups}}static fromJSON(t,e){const i=new Ku;for(const n of aa.complete(t.keyframes??[],e))i.addKeyframe(n.t,n.shapes);if(t.order){const n=i.order.filter(s=>!t.order.includes(s));i.order=[...t.order,...n]}return t.groups&&(i.groups=t.groups.map(n=>n.filter(s=>i.order.includes(s))).filter(n=>n.length>=2)),i}}function Ty(a,t,e){return Math.max(t,Math.min(e,a))}function Ry(a,t,e){const i=((t-a)%360+540)%360-180;return((a+i*e)%360+360)%360}function Za(a,t,e){return a+(t-a)*e}function Dy(a,t,e){return{lat:a.lat===void 0||t.lat===void 0?void 0:Za(a.lat,t.lat,e),lng:a.lng===void 0||t.lng===void 0?void 0:Za(a.lng,t.lng,e),elevationM:Za(a.elevationM,t.elevationM,e),headingDeg:a.headingDeg===void 0||t.headingDeg===void 0?void 0:Ry(a.headingDeg,t.headingDeg,e),pitchDeg:Za(a.pitchDeg,t.pitchDeg,e),rollDeg:Za(a.rollDeg??0,t.rollDeg??0,e),fovDeg:Za(a.fovDeg,t.fovDeg,e),fNumber:a.fNumber,focusDistanceM:a.focusDistanceM,filter:a.filter}}class Pa{static at(t,e,i,n,s){const r=t[i],c=t[i+1]-r;if(c<=0)return e[i];const l=Pa.tangent(t,e,i,s),h=Pa.tangent(t,e,i+1,s),u=(n-r)/c,d=u*u,f=d*u;return(2*f-3*d+1)*e[i]+(f-2*d+u)*c*l+(-2*f+3*d)*e[i+1]+(f-d)*c*h}static BRAKE_S=.8;static paced(t,e,i,n){if(!i&&!n)return t;const s=e>0?Math.min(.5,Pa.BRAKE_S/e):.5;if(i&&n){const o=1/(1-s);return t<=s?o*t*t/(2*s):t>=1-s?1-o*(1-t)*(1-t)/(2*s):o*(t-s/2)}const r=o=>{const c=1/(1-s/2);if(o<=1-s)return c*o;const l=o-(1-s);return c*(1-s)+c*(l-l*l/(2*s))};return n?r(t):1-r(1-t)}static tangent(t,e,i,n){const s=t.length-1,r=f=>(e[f+1]-e[f])/(t[f+1]-t[f]||1);if(i===0)return n?0:r(0);if(i===s)return n?0:r(s-1);const o=r(i-1),c=r(i);if(o*c<=0)return 0;const l=t[i]-t[i-1],h=t[i+1]-t[i],u=2*h+l,d=h+2*l;return(u+d)/(u/o+d/c)}}class el{keyframes=[];addKeyframe(t,e){const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,pose:e}:this.keyframes.splice(i,0,{t,pose:e})}clear(){this.keyframes.length=0}removeKeyframeAt(t){const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getLatestPoseAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].pose:void 0}getInterpolatedPoseAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.pose;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];if(!i)return n?.pose;if(!n)return i.pose;const s=Dy(i.pose,n.pose,Ty((t-i.t)/(n.t-i.t),0,1));return this.humanly(e-1,t,s)}humanly(t,e,i){const n=Math.max(0,t-1),s=Math.min(this.keyframes.length-1,t+2),r=this.keyframes.slice(n,s+1),o=t-n,c=r.map(S=>S.t),l=(S,M)=>{const x=r.map(_=>S(_.pose));if(!x.some(_=>_===void 0))return Pa.at(c,x,o,e,M)},h=r.map(S=>S.pose.headingDeg);let u;if(h.every(S=>S!==void 0)){const S=[h[0]];for(let M=1;M<h.length;M++)S.push(S[M-1]+((h[M]-h[M-1])%360+540)%360-180);u=(Pa.at(c,S,o,e,!0)%360+360)%360}const d=this.keyframes[t],f=this.keyframes[t+1],p=(S,M)=>S.lat===M.lat&&S.lng===M.lng&&S.elevationM===M.elevationM,v=!p(d.pose,f.pose),m=v&&t>0&&p(this.keyframes[t-1].pose,d.pose),g=v&&t+2<this.keyframes.length&&p(f.pose,this.keyframes[t+2].pose);let b;if(m||g){const S=Pa.paced((e-d.t)/(f.t-d.t),(f.t-d.t)/1e3,m,g),M=(x,_)=>x===void 0||_===void 0?void 0:x+(_-x)*S;b={lat:M(d.pose.lat,f.pose.lat),lng:M(d.pose.lng,f.pose.lng),elevationM:M(d.pose.elevationM,f.pose.elevationM)}}return{...i,lat:b?b.lat:l(S=>S.lat,!1)??i.lat,lng:b?b.lng:l(S=>S.lng,!1)??i.lng,elevationM:b?b.elevationM:l(S=>S.elevationM,!1)??i.elevationM,headingDeg:u??i.headingDeg,pitchDeg:l(S=>S.pitchDeg,!0)??i.pitchDeg,rollDeg:l(S=>S.rollDeg??0,!0)??i.rollDeg,fovDeg:l(S=>S.fovDeg,!0)??i.fovDeg}}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new el;for(const i of t.keyframes)e.addKeyframe(i.t,i.pose);return e}}class Rr{static MAX_CHANGE_PER_S=.05;points;followed;constructor(t){let e="none",i=0;this.points=t.map(({t:n,weather:s})=>(s.precipitationType!=="none"&&(e=s.precipitationType,i=s.precipitationIntensity),{t:n,lastFalling:e,lastFallingIntensity:i,intensity:s.precipitationType==="none"?0:s.precipitationIntensity,type:s.precipitationType})),this.followed=[];for(let n=0;n<this.points.length;n++){if(n===0){this.followed.push(this.points[0].intensity);continue}const s=this.points[n-1],r=this.points[n];this.followed.push(Rr.follow(this.followed[n-1],s.intensity,r.intensity,(r.t-s.t)/1e3,(r.t-s.t)/1e3))}}at(t){if(this.points.length===0||t<this.points[0].t)return;let e=this.points.length-1;for(;e>0&&this.points[e].t>t;)e--;const i=this.points[e],n=this.points[e+1],s=n?Rr.follow(this.followed[e],i.intensity,n.intensity,(n.t-i.t)/1e3,(t-i.t)/1e3):Rr.follow(this.followed[e],i.intensity,i.intensity,1,(t-i.t)/1e3);return{type:Rr.typeBetween(i,n,t,s),intensity:s,character:Rr.characterBetween(i,n,t)}}static characterBetween(t,e,i){return t.type==="none"?e&&e.type!=="none"?e.intensity:t.lastFallingIntensity:!e||e.type==="none"?t.intensity:t.intensity+(e.intensity-t.intensity)*(i-t.t)/(e.t-t.t||1)}static typeBetween(t,e,i,n){return t.type==="none"?e&&e.type!=="none"&&i>t.t?e.type:n>0?t.lastFalling:"none":e&&e.type==="none"&&n<=0?"none":t.type}static follow(t,e,i,n,s){const r=Rr.MAX_CHANGE_PER_S,o=n>0?(i-e)/n:0,c=u=>e+o*Math.min(Math.max(u,0),n);let l=t,h=0;for(let u=0;u<8&&h<s;u++){const d=c(h)-l;if(Math.abs(d)<1e-9){const S=h<n?o:0;if(Math.abs(S)<=r){const x=h<n?Math.min(s,n):s;l=c(x),h=x;continue}const M=Math.min(s,n);l+=Math.sign(S)*r*(M-h),h=M;continue}const f=Math.sign(d),p=h<n?o:0,v=r-f*p,m=v>0?h+Math.abs(d)/v:1/0,g=h<n?n:1/0,b=Math.min(s,m,g);l+=f*r*(b-h),h=b,b===m&&(l=c(h))}return Math.min(1,Math.max(0,l))}}const Mp=1e3,Iy=.65,Zu={cloudCover:0,cloudDarkness:0,precipitationType:"none",precipitationIntensity:0,windDirectionDeg:0,windSpeed:0,storm:!1};function Qh(a){if(a.cloudLayers!==void 0)return a.cloudLayers;const t=[],e=a.lowerCloudCover??a.cloudCover;return e>0&&t.push({id:"lower",type:"cumulus",baseM:a.cloudBaseM??Mp,thicknessM:650,coverage:e,sizeM:1400,density:1,darkness:a.cloudDarkness}),(a.highCloudCover??0)>0&&t.push({id:"cirrus",type:"cirrus",baseM:8e3,thicknessM:400,coverage:a.highCloudCover,sizeM:2200,density:.35,darkness:a.cloudDarkness,iceCrystalAlignment:a.iceCrystalAlignment}),t}function Je(a,t,e){return a+(t-a)*e}function yp(a,t,e){const i=((t-a)%360+540)%360-180;return((a+i*e)%360+360)%360}function Cy(a,t,e){return Math.max(t,Math.min(e,a))}function Py(a=[],t=[],e){if(!(!a.length&&!t.length))return[...new Set([...a.map(i=>i.id),...t.map(i=>i.id)])].map(i=>{const n=a.find(c=>c.id===i),s=t.find(c=>c.id===i),r=n??{...s,density:0},o=s??{...n,density:0};return{...r,eastM:Je(r.eastM,o.eastM,e),northM:Je(r.northM,o.northM,e),baseM:Je(r.baseM,o.baseM,e),thicknessM:Je(r.thicknessM,o.thicknessM,e),widthM:Je(r.widthM,o.widthM,e),depthM:Je(r.depthM,o.depthM,e),rotationDeg:yp(r.rotationDeg,o.rotationDeg,e),density:Je(r.density,o.density,e),darkness:Je(r.darkness??0,o.darkness??0,e)}})}function Oy(a,t,e){if(a.cloudLayers===void 0&&t.cloudLayers===void 0)return;const i=Qh(a),n=Qh(t);return e>=1?n.map(r=>({...r})):[...new Set([...i.map(r=>r.id),...n.map(r=>r.id)])].map(r=>{const o=i.find(u=>u.id===r),c=n.find(u=>u.id===r),l=o??{...c,coverage:0},h=c??{...o,coverage:0};return{...l,instances:Py(o?.instances,c?.instances,e),baseM:Je(l.baseM,h.baseM,e),thicknessM:Je(l.thicknessM,h.thicknessM,e),coverage:Je(l.coverage,h.coverage,e),sizeM:Je(l.sizeM,h.sizeM,e),density:Je(l.density,h.density,e),darkness:Je(l.darkness??a.cloudDarkness,h.darkness??t.cloudDarkness,e),iceCrystalAlignment:l.iceCrystalAlignment===void 0||h.iceCrystalAlignment===void 0?void 0:Je(l.iceCrystalAlignment,h.iceCrystalAlignment,e),windSpeed:l.windSpeed===void 0&&h.windSpeed===void 0?void 0:Je(l.windSpeed??a.windSpeed,h.windSpeed??t.windSpeed,e),windDirectionDeg:l.windDirectionDeg===void 0&&h.windDirectionDeg===void 0?void 0:yp(l.windDirectionDeg??a.windDirectionDeg,h.windDirectionDeg??t.windDirectionDeg,e)}})}function Ly(a,t,e){return{cloudLayers:Oy(a,t,e),cloudCover:Je(a.cloudCover,t.cloudCover,e),cloudDarkness:Je(a.cloudDarkness,t.cloudDarkness,e),highCloudCover:a.highCloudCover===void 0||t.highCloudCover===void 0?void 0:Je(a.highCloudCover,t.highCloudCover,e),iceCrystalAlignment:a.iceCrystalAlignment===void 0||t.iceCrystalAlignment===void 0?void 0:Je(a.iceCrystalAlignment,t.iceCrystalAlignment,e),lowerCloudCover:a.lowerCloudCover===void 0||t.lowerCloudCover===void 0?void 0:Je(a.lowerCloudCover,t.lowerCloudCover,e),cloudBaseM:a.cloudBaseM===void 0||t.cloudBaseM===void 0?void 0:Je(a.cloudBaseM,t.cloudBaseM,e),relativeHumidity:a.relativeHumidity===void 0||t.relativeHumidity===void 0?void 0:Je(a.relativeHumidity,t.relativeHumidity,e),precipitationType:e<1?a.precipitationType:t.precipitationType,precipitationIntensity:Je(a.precipitationIntensity,t.precipitationIntensity,e),windDirectionDeg:yp(a.windDirectionDeg,t.windDirectionDeg,e),windSpeed:Je(a.windSpeed,t.windSpeed,e),storm:e<1?a.storm:t.storm}}class il{keyframes=[];ramp;addKeyframe(t,e){this.ramp=void 0;const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,weather:e}:this.keyframes.splice(i,0,{t,weather:e})}clear(){this.ramp=void 0,this.keyframes.length=0}removeKeyframeAt(t){this.ramp=void 0;const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getLatestWeatherAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].weather:void 0}getInterpolatedWeatherAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.weather;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];return i?n?Ly(i.weather,n.weather,Cy((t-i.t)/(n.t-i.t),0,1)):i.weather:n?.weather}getActualWeatherAt(t){const e=this.getInterpolatedWeatherAt(t);if(!e)return;const i=(this.ramp??=new Rr(this.keyframes)).at(t);if(!i)return e;const{type:n,intensity:s,character:r}=i,o=r>0?Math.min(1,s/r):n==="none"?0:1;return{...e,precipitationType:n,precipitationIntensity:r,precipitationAmount:o}}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new il;for(const i of t.keyframes)e.addKeyframe(i.t,{...Zu,...i.weather});return e}}class nl{keyframes=[];addKeyframe(t,e){const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,sound:e}:this.keyframes.splice(i,0,{t,sound:e})}clear(){this.keyframes.length=0}removeKeyframeAt(t){const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}getLatestSoundAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].sound:void 0}getInterpolatedSoundAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.sound;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];if(!i)return n?.sound;if(!n)return i.sound;const s=(t-i.t)/(n.t-i.t);return this.lerp(i.sound,n.sound,Math.max(0,Math.min(1,s)))}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new nl;for(const i of t.keyframes)e.addKeyframe(i.t,i.sound);return e}lerp(t,e,i){return{kind:i<1?t.kind:e.kind,volume:t.volume+(e.volume-t.volume)*i,pitchHz:t.pitchHz+(e.pitchHz-t.pitchHz)*i,src:i<1?t.src:e.src}}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}}const Ny=100,ky={kind:"none",volume:0,pitchHz:Ny},Rl=[{id:"eye",name:"Naked eye",flare:0,projection:"equidistant",stabilization:.97},{id:"rectilinear-lens",name:"Camera, unknown device",projection:"rectilinear",fNumber:8,fNumberRange:{min:2,max:22},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:8},apertureBlades:6},{id:"roamer-1-120",name:"Roamer 1, 120 film",projection:"rectilinear",frame:{widthMm:74,heightMm:60,focalLengthMm:100},fNumber:11,exposureSeconds:1/50,years:{from:1930,to:1965},detailUm:40,medium:{kind:"negative",iso:125}},{id:"instamatic-126",name:"Instamatic, 126 film",projection:"rectilinear",frame:{widthMm:28,heightMm:28,focalLengthMm:43},fNumber:11,exposureSeconds:1/90,years:{from:1963,to:1988},apertureBlades:5,detailUm:20,medium:{kind:"negative",iso:64}},{id:"slr-35mm-50",name:"35 mm SLR, 50 mm lens",projection:"rectilinear",frame:{widthMm:36,heightMm:24,focalLengthMm:50},fNumber:8,fNumberRange:{min:2,max:16},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:3600},years:{from:1959},apertureBlades:6,detailUm:20,medium:{kind:"negative",iso:100}},{id:"slr-35mm-zoom",name:"35 mm SLR, 70-210 mm zoom",projection:"rectilinear",frame:{widthMm:36,heightMm:24,focalLengthMm:135,focalRangeMm:{minMm:70,maxMm:210}},fNumber:8,fNumberRange:{min:4,max:22},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:3600},apertureBlades:8,years:{from:1975},detailUm:20,medium:{kind:"negative",iso:100}},{id:"phone-landscape",name:"Phone, held sideways",projection:"rectilinear",frame:{widthMm:7.6,heightMm:5.7,focalLengthMm:5.7},fNumber:1.8,exposureSeconds:1/120,exposureRangeSeconds:{min:1/8e3,max:10},years:{from:2007},apertureBlades:void 0,detailUm:1.4,medium:{kind:"sensor",iso:100,autoExposure:!0}},{id:"phone-portrait",name:"Phone, held upright",projection:"rectilinear",frame:{widthMm:5.7,heightMm:7.6,focalLengthMm:5.7},fNumber:1.8,exposureSeconds:1/120,exposureRangeSeconds:{min:1/8e3,max:10},years:{from:2007},apertureBlades:void 0,detailUm:1.4,medium:{kind:"sensor",iso:100,autoExposure:!0}}];class bi{static get default(){return Rl[0]}static byId(t){return Rl.find(e=>e.id===t)??this.default}static UNAIDED_FIELD_DEG=60;static UNAIDED_ASPECT=16/9;static fieldOfViewDeg(t){const e=t.frame;return e?2*Math.atan(e.heightMm/(2*e.focalLengthMm))*180/Math.PI:bi.UNAIDED_FIELD_DEG}static aspectOf(t){const e=t.frame;return e?e.widthMm/e.heightMm:bi.UNAIDED_ASPECT}static frameWidthPx(t,e){return Math.round(e*bi.aspectOf(t))}static availableAt(t){return t===void 0?Rl:Rl.filter(e=>!e.years||t>=e.years.from&&(e.years.to===void 0||t<=e.years.to))}static fieldOfViewDegAt(t,e){const i=t.frame;if(!(!i||e<=0))return 2*Math.atan(i.heightMm/(2*e))*180/Math.PI}static focalLengthMmFor(t,e){const i=t.frame;if(!(!i||e<=0||e>=180))return i.heightMm/(2*Math.tan(e*Math.PI/360))}static bladesShowing(t,e){const i=e??t.fNumber;if(i===void 0||t.apertureBlades===void 0)return 0;const n=t.fNumberRange;return!n||n.max<=n.min?1:Math.max(0,Math.min(1,(i-n.min)/(n.max-n.min)))}static LENS_FLARE_ARTIFACTS=1;static flareArtifactsOf(t){return t.flare??bi.LENS_FLARE_ARTIFACTS}static starPointsOf(t){const e=t.apertureBlades;return e===void 0||e<3?0:e%2===0?e:e*2}}class za extends Error{}class Ju{constructor(t){this.name=t}validate(t){return!0}}class nM extends Ju{min;max;constructor(t,e,i){super(t),this.min=e,this.max=i}validate(t){if(typeof t!="number")throw new za(`${this.name} value must be a number, but was ${t}`);if(t<this.min||t>this.max)throw new za(`${this.name} value must be >= ${this.min} and <= ${this.max}, but was ${t}`);return super.validate(t)}}class Ai{name;min;max;duration;subUnit;validator;constructor(t,e,i,n,s=new nM(t,e,i)){this.name=t,this.min=e,this.max=i,this.subUnit=n,this.duration=n?(n.max-n.min+1)*n.duration:1,this.validator=s}validate(t){return this.validator.validate(t)}[Symbol.iterator](){let t=this.min;return{next:()=>{const e={done:t>this.max,value:t};return t++,e}}}}class sM{millisecond;second;minute;hour;day;month;year}class Fy extends sM{}class rM extends Fy{millisecond=new Ai("millisecond",0,999,void 0);second=new Ai("second",0,59,this.millisecond);minute=new Ai("minute",0,59,this.second);hour=new Ai("hour",0,23,this.minute);day=new Ai("day",1,31,this.hour);month=new Ai("month",1,12,this.day);year=new Ai("year",0,9999,this.month)}const Kt=new rM;class Uy extends nM{constructor(t=1,e=12){super("month",t,e)}}class Os{static instance=new Os;render(t){return t.value.toString()}}class Ji{unit;#t;constructor(t,e){this.unit=e,this.value=typeof t=="number"?t:t.value}get value(){return this.#t}set value(t){this.unit.validate(t),this.#t=t}get duration(){return this.value*this.unit.duration}#e(t){if(this.constructor.name!==t.constructor.name)throw new Ju(`${this.unit.name} "${this.toString()}" cannot be compared with ${t.unit?.name} "${t.toString()}"`)}compare(t){return this.#e(t),this.value-t.value}isEqual(t){return this.compare(t)===0}isBefore(t){return this.compare(t)<0}isAfter(t){return this.compare(t)>0}previous(t=this.unit){const e=this.value-1;return new this.constructor(e,t)}next(t=this.unit){const e=this.value+1;return new this.constructor(e,t)}toString(t=Os.instance){return t.render(this)}toSpec(){return{value:this.value}}toJSON(){return this.toSpec()}}class He{static#t=new Map;static register(t,e){He.#t.set(t,e)}static get(t){const e=He.#t.get(t);if(!e)throw new za(`No default parser registered for ${t.name}: import "@rr0/time/defaults" or pass a parser to fromString()`);return e()}}class tu extends Ji{constructor(t=new Date().getFullYear(),e=Kt.year){super(t,e)}static fromString(t,e=He.get(tu)){return new tu(e.parse(t))}}class Xs extends Os{static default=new Xs("0",2);constructor(t,e){super(),this.char=t,this.size=e}render(t){return super.render(t).padStart(this.size,this.char)}}class eu extends Ji{constructor(t=new Date().getMonth()+1,e=Kt.month){super(t,e)}static fromString(t,e=He.get(eu)){return new eu(e.parse(t))}toString(t=Xs.default){return super.toString(t)}}class iu extends Ji{constructor(t=new Date().getDate(),e=Kt.day){super(t,e)}static fromString(t,e=He.get(iu)){const i=e.parse(t);return new iu(i)}toString(t=Xs.default){return super.toString(t)}}class nu extends Ji{constructor(t=new Date().getHours(),e=Kt.hour){super(t,e)}static fromString(t,e=He.get(nu)){return new nu(e.parse(t))}toString(t=Xs.default){return super.toString(t)}}class su extends Ji{constructor(t=new Date().getMinutes(),e=Kt.minute){super(t,e)}static fromString(t,e=He.get(su)){return new su(e.parse(t))}toString(t=Xs.default){return super.toString(t)}}class ru extends Ji{constructor(t=new Date().getSeconds(),e=Kt.second){super(t,e)}static fromString(t,e=He.get(ru)){return new ru(e.parse(t),Kt.second)}toString(t=Xs.default){return super.toString(t)}}class Xa extends Ji{static renderer=new Xs("0",3);constructor(t,e=Kt.millisecond){super(t,e)}static parseFraction(t){return parseInt(t.padEnd(3,"0").substring(0,3),10)}toString(t=Xa.renderer){return super.toString(t)}}class zy{render(t){return t.toString()}}class By extends zy{render(t){const e=t.value,i=Math.abs(e),n=Math.floor(i/60),s=i%60;if(n===0&&s===0)return"Z";{const r=e<0?"-":"+",o=n.toString().padStart(2,"0"),c=s>0?":"+s.toString().padEnd(2,"0"):"";return r+o+c}}}class $o{value;name="timeshift";renderer;constructor(t=0){this.value=t}static fromString(t,e=He.get($o),i=void 0){const n=e.parse(t,i);return new $o(n)}toString(t=new By){return t.render(this)}toSpec(){return{value:this.value}}toJSON(){return this.toSpec()}}class $i{static timeshift(t,e){return t+($i.isDaylight(e)?60:0)}static isDaylight(t){const{year:e,month:i,day:n}=t,s=t.hour??12;if(![e,i,n].every(Number.isInteger))throw new RangeError("Daylight saving time depends on the year, month and day");const r=$i.rule(e);if(!r)return!1;const o=$i.rank(i,n,s);return o>=$i.rank(r.start.month,r.start.day,2)&&o<$i.rank(r.end.month,r.end.day,2)}static rule(t){if(t<1967)return;const e={month:10,day:$i.sunday(t,10,-1)};return t>=2007?{start:{month:3,day:$i.sunday(t,3,2)},end:{month:11,day:$i.sunday(t,11,1)}}:t>=1987?{start:{month:4,day:$i.sunday(t,4,1)},end:e}:t===1975?{start:{month:2,day:23},end:e}:t===1974?{start:{month:1,day:6},end:e}:{start:{month:4,day:$i.sunday(t,4,-1)},end:e}}static sunday(t,e,i){const n=new Date(Date.UTC(2e3,e-1,1));n.setUTCFullYear(t);const s=1+(7-n.getUTCDay())%7;if(i>0)return s+7*(i-1);const r=[31,$i.isLeap(t)?29:28,31,30,31,30,31,31,30,31,30,31][e-1];let o=s;for(;o+7<=r;)o+=7;return o}static isLeap(t){return t%4===0&&(t%100!==0||t%400===0)}static rank(t,e,i){return(t*100+e)*100+i}}const Hy={name:"PST",timeshift:"-08",title:"Pacific Standard Time (US)"},Gy={name:"PDT",timeshift:"-07",title:"Pacific Daylight Time (US)"},Vy={name:"MDT",timeshift:"-06",title:"Mountain Standard Time (US)"},Wy={name:"MST",timeshift:"-07",title:"Mountain Daylight Time (US)"},Xy={name:"PT",timeshift:a=>$i.timeshift(-480,a),title:"Pacific Time (US)"},Yy={name:"MT",timeshift:a=>$i.timeshift(-420,a),title:"Mountain Time (US)"},qy={name:"CT",timeshift:a=>$i.timeshift(-360,a),title:"Central Time (US)"},$y={name:"ET",timeshift:a=>$i.timeshift(-300,a),title:"Eastern Time (US)"},Ky={name:"CWT",timeshift:"-05",title:"Central War Time (US)"},Zy={name:"CDT",timeshift:"-05",title:"Central Daylight Time"},Jy={name:"EST",timeshift:"-05",title:"Eastern Standard Time (US)"},jy={name:"EDT",timeshift:"-04",title:"Eastern Time (US)"},Qy={name:"AST",timeshift:"-04",title:"Atlantic Standard Time (US)"},tx={name:"ADT",timeshift:"-03",title:"Atlantic Daylight Time (US)"},ex={name:"UTC",timeshift:"Z",title:"Coordinated Universal Time"},ix={name:"Z",timeshift:"Z",title:"UTC"},nx={name:"GMT",timeshift:"Z",title:"Greenwich Mean Time"},sx={name:"BST",timeshift:"+01",title:"British Summer Time"},rx={name:"CEST",timeshift:"+02",title:"Central European Summer Time"},ax={name:"CET",timeshift:"+01",title:"Central European Time"},ox={name:"MSK",timeshift:"+03",title:"Moscow Time (RU)"},cx={name:"IST",timeshift:"+05:30",title:"Indian Standard Time"},lx={name:"BJT",timeshift:"+08",title:"Beijing Time"},hx={name:"CST",timeshift:"-06",title:"Central Standard Time"},ux={name:"JST",timeshift:"+09",title:"Japan Standard Time"},dx={name:"AEST",timeshift:"+10",title:"Australian Eastern Standard Time"},fx={name:"NZST",timeshift:"+12",title:"New Zealand Standard Time"},px={name:"LST",timeshift:"?",title:"Local Sideral Time"},Am=[tx,dx,Qy,lx,sx,hx,Zy,ax,rx,qy,Ky,jy,Jy,$y,nx,cx,ux,px,Vy,ox,Wy,Yy,fx,Gy,Hy,Xy,ex,ix];class ju{static instance=new ju;renderComponent(t,e){return t[e].toString()}renderSecond(t){return this.renderComponent(t,"second")+(t.millisecond?"."+t.millisecond.toString():"")}render(t){const e=[];t.year&&e.push(this.renderComponent(t,"year")),t.month&&e.push(this.renderComponent(t,"month")),t.day&&e.push(this.renderComponent(t,"day"));const i=[];t.hour&&i.push(this.renderComponent(t,"hour")),t.minute&&i.push(this.renderComponent(t,"minute")),t.second&&i.push(this.renderSecond(t));const n=e.join("-"),s=t.timeshift?t.timeshift.toString():"",r=i.join(":")+s;return n+(r.length>0?"T"+r:"")}}class sa extends za{constructor(t="method is abstract"){super(t)}}class xp{units;constructor(t){this.units=t}newYear(t){throw new sa}newMonth(t){throw new sa}newDay(t){throw new sa}newHour(t){throw new sa}newMinute(t){throw new sa}newSecond(t){throw new sa}}class mx extends sM{millisecond=new Ai("milliseconds",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,void 0);second=new Ai("seconds",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.millisecond);minute=new Ai("minutes",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.second);hour=new Ai("hours",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.minutes);day=new Ai("days",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.hour);month=new Ai("months",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.day);year=new Ai("years",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.month)}const bp=new mx;class Sp{static instance=new Sp;render(t){const e=da.toSpec(t);let i="P";const n=e.years;n&&(i+=n.toString()+"Y");const s=e.months;s&&(i+=s.toString(Os.instance)+"MM");const r=e.days;r&&(i+=r.toString(Os.instance)+"D");const o=e.hours;o&&(i+=o.toString(Os.instance)+"H");const c=e.minutes;c&&(i+=c.toString(Os.instance)+"M");const l=e.seconds;return l&&(i+=l.toString(Os.instance)+"S"),i}}class da extends Ji{constructor(t={years:new Date().getFullYear(),months:new Date().getMonth(),days:new Date().getDate(),hours:new Date().getHours(),minutes:new Date().getMinutes(),seconds:new Date().getSeconds(),milliseconds:new Date().getMilliseconds()}){super({value:typeof t=="number"?t:+(t.years?t.years*Kt.year.duration:0)+(t.months?t.months*Kt.month.duration:0)+(t.days?t.days*Kt.day.duration:0)+(t.hours?t.hours*Kt.hour.duration:0)+(t.minutes?t.minutes*Kt.minute.duration:0)+(t.seconds?t.seconds*Kt.second.duration:0)},new Ai("millisecond",0,Number.MAX_SAFE_INTEGER,void 0))}static toSpec(t,e=vx){let i=typeof t=="number"?t:t.value;const n=i>0?1:-1;i=Math.abs(i);const s={},r=i/Kt.year.duration,o=Math.floor(r);o>0&&(s.years=e.newYear(n*o),i-=o*Kt.year.duration);const c=i/Kt.month.duration,l=Math.floor(c);l>0&&(s.months=e.newMonth(n*l),i-=l*Kt.month.duration);const h=i/Kt.day.duration,u=Math.floor(h);u>0&&(s.days=e.newDay(n*u),i-=u*Kt.day.duration);const d=i/Kt.hour.duration,f=Math.floor(d);f>0&&(s.hours=e.newHour(n*f),i-=f*Kt.hour.duration);const p=i/Kt.minute.duration,v=Math.floor(p);v>0&&(s.minutes=e.newMinute(n*v),i-=v*Kt.minute.duration);const m=i/Kt.second.duration,g=Math.floor(n*m);return g>0&&(s.seconds=e.newSecond(g)),s}static fromString(t,e=He.get(da)){return new da(e.parse(t))}static between(t,e){const i=e.getTime(),n=t.getTime();return new da(i-n)}toSpec(){return da.toSpec(this)}toString(t=Sp.instance){return t.render(this)}}class aM extends xp{constructor(t){super(t)}newYear(t){return new tu(t,this.units.year)}newMonth(t){return new eu(t,this.units.month)}newDay(t){return new iu(t,this.units.day)}newHour(t){return new nu(t,this.units.hour)}newMinute(t){return new su(t,this.units.minute)}newSecond(t){return new ru(t,this.units.second)}newMillisecond(t){return new Xa(t,this.units.millisecond)}newTimeshift(t){return new $o(typeof t=="number"?t:t.value)}}const gx=new aM(Kt),vx=new aM(bp);class rs{#t;#e;#i;#n;#s;#r;#a;#o;constructor(t={year:new Date().getFullYear(),month:new Date().getMonth()+1,day:new Date().getDate(),hour:new Date().getHours(),minute:new Date().getMinutes(),second:new Date().getSeconds(),timeshift:rs.timeshiftOf(new Date)}){this.year=t.year,this.month=t.month,this.day=t.day,this.hour=t.hour,this.minute=t.minute,this.second=t.second,this.millisecond=t.millisecond,this.timeshift=t.timeshift}get year(){return this.#t}set year(t){const e=typeof t=="number";this.#t&&e?this.#t.value=t:this.#t=e?this.factory.newYear(t):!t||t.start||t instanceof Ji?t:this.factory.newYear(t)}get month(){return this.#e}set month(t){const e=typeof t=="number";this.#e&&e?this.#e.value=t:this.#e=e?this.factory.newMonth(t):!t||t.start||t instanceof Ji?t:this.factory.newMonth(t)}get day(){return this.#i}set day(t){const e=typeof t=="number";this.#i&&e?this.#i.value=t:this.#i=e?this.factory.newDay(t):!t||t.start||t instanceof Ji?t:this.factory.newDay(t)}get hour(){return this.#n}set hour(t){const e=typeof t=="number";this.#n&&e?this.#n.value=t:this.#n=e?this.factory.newHour(t):!t||t.start||t instanceof Ji?t:this.factory.newHour(t)}get minute(){return this.#s}set minute(t){const e=typeof t=="number";this.#s&&e?this.#s.value=t:this.#s=e?this.factory.newMinute(t):!t||t.start||t instanceof Ji?t:this.factory.newMinute(t)}get second(){return this.#r}set second(t){const e=typeof t=="number";this.#r&&e?this.#r.value=t:this.#r=e?this.factory.newSecond(t):!t||t.start||t instanceof Ji?t:this.factory.newSecond(t)}get millisecond(){return this.#a}set millisecond(t){const e=typeof t=="number";this.#a&&e?this.#a.value=t:this.#a=e||t&&!(t instanceof Ji)?this.factory.newMillisecond(t):t}get timeshift(){return this.#o}set timeshift(t){const e=typeof t=="number";this.#o&&e?this.#o.value=t:this.#o=e||t&&!(t instanceof $o)?this.factory.newTimeshift(t):t}get factory(){return gx}static fromString(t,e=He.get(rs)){const{year:i,month:n,day:s,hour:r,minute:o,second:c,millisecond:l,timeshift:h}=e.parse(t);return new rs({year:i,month:n,day:s,hour:r,minute:o,second:c,millisecond:l,timeshift:h})}static timeshiftOf(t){return-t.getTimezoneOffset()||0}static fromDate(t){return new rs({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),timeshift:rs.timeshiftOf(t)})}static newInstance(){const t=new Date().toISOString(),e=t.indexOf("."),i=t.substring(0,e)+t.substring(e+4);return rs.fromString(i)}#c(t){if(this.constructor.name!==t.constructor.name)throw new Ju(`Date "${this.toString()}" cannot be compared with "${t.toString()}"`)}compare(t){return this.#c(t),this.getTime()-t.getTime()}delta(t){const e=this.compare(t);return new da(e)}getTime(){return(this.year?.duration||0)+(this.month?.duration||0)+(this.day?.duration||0)+(this.hour?.duration||0)+(this.minute?.duration||0)+(this.second?.duration||0)+(this.millisecond?.duration||0)}isEqual(t){return this.compare(t)===0}isBefore(t){return this.compare(t)<0}isAfter(t){return this.compare(t)>0}clone(){return new rs(this.toSpec())}previous(){let t=this.clone();try{t.second=this.second.previous()}catch{try{t.minute=this.minute.previous()}catch{try{t.hour=this.hour.previous()}catch{try{t.day=this.day.previous()}catch{try{t.month=this.month.previous()}catch{t.year=this.year.previous()}}}}}return t}next(){let t=this.clone();try{t.second=this.second.next()}catch{try{t.minute=this.minute.next()}catch{try{t.hour=this.hour.next()}catch{try{t.day=this.day.next()}catch{try{t.month=this.month.next()}catch{t.year=this.year.next()}}}}}return t}toString(t=ju.instance){return t.render(this)}toSpec(){const t={},e=this.year?.toSpec();e&&(t.year=e);const i=this.month?.toSpec();i&&(t.month=i);const n=this.day?.toSpec();n&&(t.day=n);const s=this.hour?.toSpec();s&&(t.hour=s);const r=this.minute?.toSpec();r&&(t.minute=r);const o=this.second?.toSpec();o&&(t.second=o);const c=this.millisecond?.toSpec();c&&(t.millisecond=c);const l=this.timeshift?.toSpec();return l&&(t.timeshift=l),t}toJSON(){return this.toSpec()}}class yl extends Os{static instance=new yl(Xs.default);constructor(t){super(),this.valueRenderer=t}render(t){return(this.valueRenderer?this.valueRenderer.render(t):super.render(t))+this.qualifier(t)}qualifier(t){return t.uncertain?t.approximate?"%":"?":t.approximate?"~":""}}class Ya extends Ji{#t;#e;constructor(t,e){super(t,e),this.#t=t.uncertain||!1,this.#e=t.approximate||!1}get uncertain(){return this.#t}set uncertain(t){return this.#t=t}get approximate(){return this.#e}set approximate(t){return this.#e=t}isCertainAndPrecise(){return!this.approximate&&!this.uncertain}isEqual(t){return this.isCertainAndPrecise()&&super.isEqual(t)}isBefore(t){return this.isCertainAndPrecise()&&super.isBefore(t)}isAfter(t){return this.isCertainAndPrecise()&&super.isAfter(t)}toString(t=yl.instance){return super.toString(t)}toSpec(){return{...super.toSpec(),uncertain:this.uncertain,approximate:this.approximate}}toJSON(){return this.toSpec()}}class oM extends rM{year=new Ai("year",-9999,9999,this.month);yearExtended=new Ai("year",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.month)}const Fh=new oM;class fa extends Ya{constructor(t,e=Fh.year){super(t,e)}static fromString(t,e=Fh.year,i=He.get(fa)){const n=i.parse(t),s=n.value.start;if(t.startsWith("Y")&&(e=Fh.yearExtended),s!==void 0){const r=new fa(Object.assign({...n},{value:Math.max(s,e.min)})),o=new fa(Object.assign({...n},{value:Math.min(n.value.end,e.max)}));return{start:r,end:o}}else return new fa(n,e)}}class cM extends Ju{monthValidator=new Uy;validate(t){switch(t){case 21:case 22:case 23:case 24:return!0;default:return this.monthValidator.validate(t)}}}class pa extends Ya{constructor(t,e=new Ai(Kt.month.name,1,24,Kt.day,new cM)){super(t,e)}static fromString(t,e=He.get(pa)){const i=e.parse(t),n=i.value.start;if(n!==void 0){let s=Kt.month;const r=new pa(Object.assign({...i},{value:Math.max(n,s.min)})),o=new pa(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new pa(i)}toString(t){return super.toString(t).padStart(2,"0")}}class ma extends Ya{constructor(t,e=Kt.day){super(t,e)}static fromString(t,e=He.get(ma)){const i=e.parse(t),n=i.value.start;if(n!==void 0){let s=Kt.day;const r=new ma(Object.assign({...i},{value:Math.max(n,s.min)})),o=new ma(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new ma(i)}toString(t){return super.toString(t).padStart(2,"0")}}class ga extends Ya{constructor(t,e=Kt.hour){super(t,e)}static fromString(t,e=He.get(ga)){const i=e.parse(t),n=i.value.start;if(n!==void 0){let s=Kt.hour;const r=new ga(Object.assign({...i},{value:Math.max(n,s.min)})),o=new ga(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new ga(i)}}class va extends Ya{constructor(t,e=Kt.minute){super(t,e)}static fromString(t,e=He.get(va)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.minute,r=new va(Object.assign({...i},{value:Math.max(n,s.min)})),o=new va(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new va(i)}toString(t=yl.instance){return super.toString(t)}}class Ma extends Ya{constructor(t,e=Kt.second){super(t,e)}static fromString(t,e=He.get(Ma)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.second,r=new Ma(Object.assign({...i},{value:Math.max(n,s.min)})),o=new Ma(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new Ma(i)}}class Ko extends $o{static fromString(t,e=He.get(Ko),i=void 0){return new Ko(e.parse(t,i))}}class lM extends xp{constructor(t){super(t)}newYear(t){return new fa(t,this.units.year)}newMonth(t){return new pa(t,this.units.month)}newDay(t){return new ma(t,this.units.day)}newHour(t){return new ga(t,this.units.hour)}newMinute(t){return new va(t,this.units.minute)}newSecond(t){return new Ma(t,this.units.second)}newMillisecond(t){return new Xa(t,this.units.millisecond)}newTimeshift(t){return new Ko(typeof t=="number"?t:t.value)}}const Mx=new lM(Fh);new lM(bp);class oa extends rs{constructor(t){super(t)}get factory(){return Mx}get uncertain(){return this.year?.uncertain===!0||this.month?.uncertain===!0||this.day?.uncertain===!0||this.hour?.uncertain===!0||this.minute?.uncertain===!0||this.second?.uncertain===!0}get approximate(){return this.year?.approximate===!0||this.month?.approximate===!0||this.day?.approximate===!0||this.hour?.approximate===!0||this.minute?.approximate===!0||this.second?.approximate===!0}static fromDate(t){return new oa({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),timeshift:rs.timeshiftOf(t)})}static fromString(t,e=He.get(oa)){const i=e.parse(t);return new oa(i)}static newInstance(){const t=new Date().toISOString(),e=t.indexOf("."),i=t.substring(0,e)+t.substring(e+4);return oa.fromString(i)}clone(){return new oa(this.toSpec())}}class sc extends Ya{uncertainComponent;approximateComponent;constructor(t,e){super(t,e),this.uncertainComponent=t.uncertainComponent||!1,this.approximateComponent=t.approximateComponent||!1}get uncertain(){return super.uncertain||this.uncertainComponent}set uncertain(t){return super.uncertain=t}get approximate(){return super.approximate||this.approximateComponent}set approximate(t){return super.approximate=t}get uncertainGroup(){return super.uncertain}get approximateGroup(){return super.approximate}toSpec(){return{...super.toSpec(),uncertain:this.uncertainGroup,approximate:this.approximateGroup,uncertainComponent:this.uncertainComponent,approximateComponent:this.approximateComponent}}toJSON(){return this.toSpec()}}class yx extends oM{year=new Ai("year",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.month)}const Wf=new yx;class ya extends sc{constructor(t,e=Wf.year){super(t,e)}static fromString(t,e=Wf.year,i=He.get(ya)){const n=i.parse(t),s=n.value.start;if(s!==void 0){const r=new ya(Object.assign({...n},{value:Math.max(s,e.min)})),o=new ya(Object.assign({...n},{value:Math.min(n.value.end,e.max)})),c={start:r,end:o},l=n.value.estimate;return l&&(c.estimate=l),c}else return new ya(n)}}class xx extends cM{validate(t){switch(t){case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 41:return!0;default:return super.validate(t)}}}class xa extends sc{constructor(t,e=new Ai(Kt.month.name,1,41,Kt.day,new xx)){super(t,e)}static fromString(t,e=He.get(xa)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.month,r=new xa(Object.assign({...i},{value:Math.max(n,s.min)})),o=new xa(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new xa(i)}toString(t){return super.toString(t).padStart(2,"0")}}class ba extends sc{constructor(t,e=Kt.day){super(t,e)}static fromString(t,e=He.get(ba)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.day,r=new ba(Object.assign({...i},{value:Math.max(n,s.min)})),o=new ba(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new ba(i)}toString(t){return super.toString(t).padStart(2,"0")}}class Sa extends sc{constructor(t,e=Kt.hour){super(t,e)}static fromString(t,e=He.get(Sa)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.hour,r=new Sa(Object.assign({...i},{value:Math.max(n,s.min)})),o=new Sa(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new Sa(i)}}class wa extends sc{constructor(t,e=Kt.minute){super(t,e)}static fromString(t,e=He.get(wa)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.minute,r=new wa(Object.assign({...i},{value:Math.max(n,s.min)})),o=new wa(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new wa(i)}}class _a extends sc{constructor(t,e=Kt.second){super(t,e)}static fromString(t,e=Kt.second,i=He.get(_a)){const n=i.parse(t),s=n.value.start;if(s!==void 0){const r=new _a(Object.assign({...n},{value:Math.max(s,e.min)})),o=new _a(Object.assign({...n},{value:Math.min(n.value.end,e.max)}));return{start:r,end:o}}else return new _a(n,e)}}class hM extends Ko{}class bx extends yl{qualifier(){return""}}class Dr extends ju{static instance=new Dr;static valueRenderer=new bx(Xs.default);static names=["year","month","day","hour","minute","second"];static qualifier(t,e){return t?e?"%":"?":e?"~":""}renderComponent(t,e){const i=t[e],n=Dr.names.slice(Dr.names.indexOf(e)+1).map(o=>t[o]).filter(Boolean),s=Dr.qualifier(i.uncertainComponent,i.approximateComponent),r=Dr.qualifier(i.uncertainGroup&&!i.uncertainComponent&&!n.some(o=>o.uncertain),i.approximateGroup&&!i.approximateComponent&&!n.some(o=>o.approximate));return s+i.toString(Dr.valueRenderer)+r}}class uM extends xp{constructor(t){super(t)}newYear(t){return new ya(t,this.units.year)}newMonth(t){return new xa(t,this.units.month)}newDay(t){return new ba(t,this.units.day)}newHour(t){return new Sa(t,this.units.hour)}newMinute(t){return new wa(t,this.units.minute)}newSecond(t){return new _a(t,this.units.second)}newMillisecond(t){return new Xa(t,this.units.millisecond)}newTimeshift(t){return new hM(typeof t=="number"?t:t.value)}}const Sx=new uM(Wf);new uM(bp);class ca extends oa{constructor(t){super(t)}toString(t=Dr.instance){return super.toString(t)}get year(){return super.year}set year(t){super.year=t}get month(){return super.month}set month(t){super.month=t}get factory(){return Sx}static fromDate(t){return new ca({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),timeshift:rs.timeshiftOf(t)})}static fromString(t,e=He.get(ca)){const i=e.parse(t);return new ca(i)}static newInstance(){const t=new Date().toISOString(),e=t.indexOf("."),i=t.substring(0,e)+t.substring(e+4);return ca.fromString(i)}clone(){return new ca(this.toSpec())}}class Qu{regExp;constructor(t,e){this.name=t,this.regExp=new RegExp(`^(?:${e})$`)}regexGroups(t){const e=this.regExp.exec(t);if(!e)throw new za(`Invalid ${this.name} "${t}"`);return e.groups}parseGroups(t){throw new sa(`${this.constructor.name} is abstract`)}parse(t){const e=this.regexGroups(t);return this.parseGroups(e)}}class wp extends Qu{constructor(t,e){super(t,e)}static read(t){return{value:t?parseInt(t,10):void 0}}parseGroups(t){return wp.read(t[this.name])}parse(t){if(t.startsWith("-"))throw new za(`${this.name} cannot be negative`);return super.parse(t)}}class at{static groupName(...t){return t.reduce((e,i)=>e?e+i.charAt(0).toUpperCase()+i.substring(1):i,"")}static group(t,...e){return`(?<${t}>${e.join("")})`}static optional(t){return t+"?"}static nonCapturingGroup(...t){return`(?:${t.join("")})`}static optionalGroup(t,...e){return at.optional(at.group(t,...e))}static optionalNonCapturingGroup(...t){return at.optional(at.nonCapturingGroup(...t))}static numberGroup(t,e,i,n="\\d"){return at.group(t,`${i||""}[${n}]${e}`)}}const Tm="timeshiftValue",Rm="shiftHour",Dm="shiftMinute";class _p extends Qu{static format(t=""){return Am.map(e=>e.name).join("|")+"|"+at.nonCapturingGroup(at.group(t+Rm,at.numberGroup(at.groupName(t,Tm),"{2}","[+-]")),at.optionalNonCapturingGroup(":?",at.numberGroup(at.groupName(t,Dm),"{2}",void 0)))}constructor(){super(Tm,_p.format())}parse(t,e){let i=0;const n=Am.find(s=>s.name===t);if(n){if(typeof n.timeshift=="function")try{return n.timeshift(e??{})}catch(s){throw new za(`The time zone ${t} depends on the date: ${s.message}`)}t=n.timeshift}if(t!=="Z"){const s=this.regexGroups(t),r=s[Rm];r&&(i+=parseInt(r,10)*60);const o=s[Dm];o&&(i+=parseInt(o,10))}return i}}class ai extends wp{static uncertainGroup="uncertain";static approximateGroup="approx";static uncertainAndApproximateGroup=ai.uncertainGroup+ai.approximateGroup;constructor(t,e){super(t,e)}static qualifierFormat(t,e){return at.optionalGroup(t,`\\${e}`)}static formatSuffix(t){return this.qualifierFormat(at.groupName(ai.uncertainGroup,t),"?")+this.qualifierFormat(at.groupName(ai.approximateGroup,t),"~")+this.qualifierFormat(at.groupName(ai.uncertainAndApproximateGroup,t),"%")}static numberFormat(t,e,i){return at.numberGroup(t,e,i,"\\dX")+this.formatSuffix(t)}getValueAndSign(t){let e=t[this.name],i;return e.charAt(0)==="-"?(i=-1,e=e.substring(1)):i=1,{valueStr:e,sign:i}}parseGroups(t){const{valueStr:e,sign:i}=this.getValueAndSign(t);let n=0,s;for(s=0;s<e.length;s++){const l=e[s];if(l==="X")break;n=n*10+parseInt(l,10)}if(s<e.length){let l=1;for(let d=0;d<e.length-s;d++)l*=10;const h=i*n*l,u=h+l-1;n={start:h,end:u}}else n*=i;const r=t[at.groupName(ai.uncertainAndApproximateGroup,this.name)],o=t[at.groupName(ai.approximateGroup,this.name)]||r,c=t[at.groupName(ai.uncertainGroup,this.name)]||r;return{value:n,approximate:o?!!o:!1,uncertain:c?!!c:!1}}}const Im="yearValue";class au extends ai{constructor(){super(Im,au.format())}static format(t=""){return"Y?"+ai.numberFormat(at.groupName(t,Im),"+","[-]?")}parse(t){const e=this.regexGroups(t);return this.parseGroups(e)}}const Cm="monthValue";class ou extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Cm),"{1,2}",void 0)}constructor(){super(Cm,ou.format())}}const Pm="dayValue";class cu extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Pm),"{1,2}",void 0)}constructor(){super(Pm,cu.format())}}const Om="hourValue";class lu extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Om),"{1,2}",void 0)}constructor(){super(Om,lu.format())}}const Lm="minuteValue";class hu extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Lm),"{1,2}",void 0)}constructor(){super(Lm,hu.format())}}const Nm="secondValue";class uu extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Nm),"{1,2}",void 0)}constructor(){super(Nm,uu.format())}}class du extends _p{}class Ri extends Qu{static yearGroup="year";static monthGroup="month";static dayGroup="day";static hourGroup="hour";static minuteGroup="minute";static secondGroup="second";static millisecondGroup="millisecond";static timeshiftGroup="timeshift";constructor(t=Ri.format()){super("date",t)}static format(t=""){return at.group(at.groupName(t,Ri.yearGroup),au.format(t))+at.optionalNonCapturingGroup("-",at.group(at.groupName(t,Ri.monthGroup),ou.format(t)),at.optionalNonCapturingGroup("-",at.group(at.groupName(t,Ri.dayGroup),cu.format(t)),at.optionalNonCapturingGroup("[T ]",at.group(at.groupName(t,Ri.hourGroup),lu.format(t)),":",at.group(at.groupName(t,Ri.minuteGroup),hu.format(t)),at.optionalNonCapturingGroup(":",at.group(at.groupName(t,Ri.secondGroup),uu.format(t)),at.optionalNonCapturingGroup("[.,]",at.group(at.groupName(t,Ri.millisecondGroup),"\\d+"))),at.optionalGroup(at.groupName(t,Ri.timeshiftGroup),du.format(t)))))}parseGroups(t){const e=t[Ri.millisecondGroup],i=e?Xa.parseFraction(e):void 0,n=t[Ri.secondGroup],s=n?Ma.fromString(n,new uu):void 0,r=t[Ri.minuteGroup];let o;r&&(o=va.fromString(r,new hu),o.uncertain=o.uncertain||s?.uncertain||!1,o.approximate=o.approximate||s?.approximate||!1);const c=t[Ri.hourGroup];let l;c&&(l=ga.fromString(c,new lu),l.uncertain=l.uncertain||o?.uncertain||!1,l.approximate=l.approximate||o?.approximate||!1);const h=t[Ri.dayGroup];let u;h&&(u=ma.fromString(h,new cu),u.uncertain=u.uncertain||l?.uncertain||!1,u.approximate=u.approximate||l?.approximate||!1);const d=t[Ri.monthGroup];let f;d&&(f=pa.fromString(d,new ou),f.uncertain=f.uncertain||u?.uncertain||!1,f.approximate=f.approximate||u?.approximate||!1);const p=t[Ri.yearGroup];let v;p&&(v=fa.fromString(p,void 0,new au),v.uncertain=v.uncertain||f?.uncertain||!1,v.approximate=v.approximate||f?.approximate||!1);const m=t[Ri.timeshiftGroup],g=m?Ko.fromString(m,new du,{year:v?.value,month:f?.value,day:u?.value,hour:l?.value}):void 0;return{year:v,month:f,day:u,hour:l,minute:o,second:s,millisecond:i,timeshift:g}}}class xi extends ai{static uncertainGroup="uncertain1";static approximateGroup="approx1";static uncertainAndApproximateGroup=xi.uncertainGroup+xi.approximateGroup;constructor(t,e){super(t,e)}static numberFormat(t,e,i){return this.qualifierFormat(at.groupName(xi.uncertainGroup,t),"?")+this.qualifierFormat(at.groupName(xi.approximateGroup,t),"~")+this.qualifierFormat(at.groupName(xi.uncertainAndApproximateGroup,t),"%")+ai.numberFormat(t,e,i)}parseGroups(t){const e=super.parseGroups(t),i=t[at.groupName(xi.uncertainAndApproximateGroup,this.name)];return(t[at.groupName(xi.uncertainGroup,this.name)]||i)&&(e.uncertainComponent=!0),(t[at.groupName(xi.approximateGroup,this.name)]||i)&&(e.approximateComponent=!0),e}}const lc="yearValue",km="exp",Fm="signif";class fu extends xi{constructor(){super(lc,fu.format())}static format(t=""){return"Y?"+at.nonCapturingGroup(at.group(at.groupName(t,km),"[-]?\\d+E\\d+")+"|"+xi.numberFormat(at.groupName(t,lc),"+","[-]?")+at.optionalGroup(at.groupName(t,Fm),"S\\d+"))}parseGroups(t){const e=t[km];if(e){const r=e.indexOf("E"),o=parseInt(e.substring(r+1),10),l=parseInt(e.substring(0,r),10)*Math.pow(10,o);t[lc]=l.toString()}const i=t[Fm],n=t[lc];if(i){const r=parseInt(i.substring(1),10),{valueStr:o,sign:c}=this.getValueAndSign(t);let l="";for(let h=0;h<o.length;h++)l+=h<r?o.charAt(h):"X";t[lc]=(c<0?"-":"")+l}const s=super.parseGroups(t);return i&&(s.value.estimate=parseInt(n,10)),s}parse(t){const e=this.regexGroups(t);return this.parseGroups(e)}}const Um="monthValue";class pu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,Um),"{1,2}",void 0)}constructor(){super(Um,pu.format())}}const zm="dayValue";class mu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,zm),"{1,2}",void 0)}constructor(){super(zm,mu.format())}}const Bm="hourValue";class gu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,Bm),"{1,2}",void 0)}constructor(){super(Bm,gu.format())}}const Hm="secondValue";class vu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,Hm),"{1,2}",void 0)}constructor(){super(Hm,vu.format())}}const Gm="minuteValue";class Mu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,Gm),"{1,2}",void 0)}constructor(){super(Gm,Mu.format())}}class wx extends du{}class Di extends Qu{static yearGroup=Ri.yearGroup;static monthGroup="month";static dayGroup="day";static hourGroup="hour";static minuteGroup="minute";static secondGroup="second";static millisecondGroup="millisecond";static timeshiftGroup="timeshift";constructor(){super("date",Di.format())}static format(t=""){return at.group(at.groupName(t,Di.yearGroup),fu.format(t))+at.optionalNonCapturingGroup("-",at.group(at.groupName(t,Di.monthGroup),pu.format(t)),at.optionalNonCapturingGroup("-",at.group(at.groupName(t,Di.dayGroup),mu.format(t)),at.optionalNonCapturingGroup("[T ]",at.group(at.groupName(t,Di.hourGroup),gu.format(t)),":",at.group(at.groupName(t,Di.minuteGroup),Mu.format(t)),at.optionalNonCapturingGroup(":",at.group(at.groupName(t,Di.secondGroup),vu.format(t)),at.optionalNonCapturingGroup("[.,]",at.group(at.groupName(t,Di.millisecondGroup),"\\d+"))),at.optionalGroup(at.groupName(t,Di.timeshiftGroup),wx.format(t)))))}parseGroups(t){const e=t[Di.millisecondGroup],i=e?Xa.parseFraction(e):void 0,n=t[Di.secondGroup];let s;n&&(s=_a.fromString(n,void 0,new vu),s.uncertain=s?.uncertain||!1,s.approximate=s?.approximate||!1);const r=t[Di.minuteGroup];let o;r&&(o=wa.fromString(r,new Mu),o.uncertain=o.uncertain||s?.uncertain||!1,o.approximate=o.approximate||s?.approximate||!1);const c=t[Di.hourGroup];let l;c&&(l=Sa.fromString(c,new gu),l.uncertain=l.uncertain||o?.uncertain||!1,l.approximate=l.approximate||o?.approximate||!1);const h=t[Di.dayGroup];let u;h&&(u=ba.fromString(h,new mu),u.uncertain=u.uncertain||l?.uncertain||!1,u.approximate=u.approximate||l?.approximate||!1);const d=t[Di.monthGroup];let f;d&&(f=xa.fromString(d,new pu),f.uncertain=f.uncertain||u?.uncertain||!1,f.approximate=f.approximate||u?.approximate||!1);const p=t[Di.yearGroup];let v;p&&(v=ya.fromString(p,void 0,new fu),v.uncertain=v.uncertain||f?.uncertain||!1,v.approximate=v.approximate||f?.approximate||!1);const m=t[Di.timeshiftGroup],g=m?hM.fromString(m,new du,{year:v?.value,month:f?.value,day:u?.value,hour:l?.value}):void 0;return{year:v,month:f,day:u,hour:l,minute:o,second:s,millisecond:i,timeshift:g}}}const dM=["spring","summer","autumn","winter"],Xf=21,_x=32,Ex=/^(?<hour>[01]?\d|2[0-3]):(?<minute>[0-5]\d)(?::(?<second>[0-5]\d))?[?~%]?$/;let Ax;function Tx(){return Ax??=new Di}function Ja(a){return typeof a?.value=="number"?a.value:void 0}function vd(a){const t=a.trim();if(/^\d{1,2}:/.test(t)){const r=Ex.exec(t)?.groups;return r?{year:void 0,month:void 0,day:void 0,hour:Number(r.hour),minute:Number(r.minute),second:r.second?Number(r.second):void 0,raw:t}:void 0}let e;try{e=ca.fromString(t,Tx())}catch{return}const i=Ja(e.year),n=Ja(e.month),s=n!==void 0&&n>=Xf&&n<=_x;if(!(e.timeshift||i!==void 0&&Math.abs(i)>9999)&&!(n!==void 0&&n>12&&!s)&&!(s&&(e.day||e.hour)))return{year:i,month:s?void 0:n,...s?{season:dM[(n-Xf)%4]}:{},day:Ja(e.day),hour:Ja(e.hour),minute:Ja(e.minute),second:Ja(e.second),raw:t}}function Uh(a){if(a.raw!==void 0)return a.raw;if(a.year===void 0){if(a.hour===void 0)return"";let e=`${String(a.hour).padStart(2,"0")}:${String(a.minute??0).padStart(2,"0")}`;return a.second!==void 0&&(e+=`:${String(a.second).padStart(2,"0")}`),e}let t=String(a.year).padStart(4,"0");return a.season!==void 0?`${t}-${Xf+dM.indexOf(a.season)}`:(a.month===void 0||(t+=`-${String(a.month).padStart(2,"0")}`,a.day===void 0)||(t+=`-${String(a.day).padStart(2,"0")}`,a.hour===void 0)||(t+=`T${String(a.hour).padStart(2,"0")}:${String(a.minute??0).padStart(2,"0")}`,a.second!==void 0&&(t+=`:${String(a.second).padStart(2,"0")}`)),t)}function Yf(a){if(a.year!==void 0)return Date.UTC(a.year,(a.month??1)-1,a.day??1,a.hour??0,a.minute??0,a.second??0)}function Vm(a){return(((a.day??0)*24+(a.hour??0))*60+(a.minute??0))*6e4+(a.second??0)*1e3}const Rx=["year","month","day","hour","minute"],Dx=["day","hour","minute"];function Wm(a,t){return t.filter(e=>a[e]!==void 0).join(",")}function fM(a){if(a.durationSeconds!==void 0)return a.durationSeconds*1e3;const t=a.durationText===void 0?void 0:Vc.parse(a.durationText);if(t)return t.chosenSeconds*1e3;if(!a.time||!a.endTime)return;const e=a.time.year!==void 0&&a.endTime.year!==void 0,i=e?Rx:Dx,n=Wm(a.time,i);if(!(n===""||n!==Wm(a.endTime,i)))return e?Yf(a.endTime)-Yf(a.time):Vm(a.endTime)-Vm(a.time)}class td{constructor(t,e,i,n,s,r,o,c,l=[],h,u,d,f=[],p=[],v=[],m=[]){this.event=t,this.timeline=e,this.observerTrack=i,this.weatherTrack=n,this.soundTrack=s,this.observer=r,this.id=o,this.weather=c,this.decor=l,this.weatherSource=h,this.instrumentId=u,this.exposureSeconds=d,this.milestones=f,this.references=p,this.roads=v,this.traces=m}provenance=hn.empty();loadIssues=[];account;sources;interpretation;sway;lightPollution;observerMap;iso;vehicle;get observerCount(){return 1+this.decor.filter(t=>t.kind==="observer").length}get exposure(){return this.exposureSeconds??this.instrument.exposureSeconds}get instrument(){return bi.byId(this.instrumentId)}static create(t,e,i){return new td({eventType:"sighting",time:t,place:e},new Ku,new el,new il,new nl,i)}}const Ix=0,Cx=0;function Ze(a,t){const e=a.observerTrack.getInterpolatedPoseAt(t);if(e)return e;const i=a.event.place?.[0];if(i)return{lat:i.lat,lng:i.lng,elevationM:Ix,headingDeg:void 0,pitchDeg:Cx,fovDeg:bi.fieldOfViewDeg(a.instrument)}}function Eo(a,t){return a.weatherTrack.getInterpolatedWeatherAt(t)??a.weather??Zu}function Dl(a,t){return a.weatherTrack.getActualWeatherAt(t)??a.weather??Zu}function pM(a,t){return a.soundTrack.getInterpolatedSoundAt(t)??ky}class er{constructor(t,e,i,n="en"){this.parts=t,this.messages=e,this.onChange=i,this.locale=n,this.setMessages(e),t.text.addEventListener("input",()=>{this.readText(),this.showDeduction()}),t.picker.addEventListener("change",()=>this.writeFromPicker()),t.mode.addEventListener("click",()=>this.setPrecise(!this.precise)),t.text.addEventListener("blur",()=>this.validate()),t.text.addEventListener("focus",()=>this.showDeduction())}precise=!0;hint="";get isPrecise(){return this.precise}setMessages(t,e=this.locale){this.messages=t,this.locale=e,t.edtfPlaceholder!==void 0&&(this.parts.text.placeholder=t.edtfPlaceholder),this.parts.mode.title=t.edtfModeTitle,this.parts.mode.setAttribute("aria-label",t.edtfModeTitle),this.setPrecise(this.precise)}setPrecise(t){this.precise=t,this.parts.picker.hidden=!t,this.parts.text.hidden=t,this.parts.mode.textContent=t?this.messages.datePrecise:this.messages.dateEdtf,this.parts.mode.setAttribute("aria-pressed",String(!t)),this.parts.help&&(this.parts.help.hidden=t),this.showDeduction()}set(t){const{text:e,picker:i}=this.parts;e.value=t?Uh(t):"",i.step=er.stepFor(t),i.value=er.pickerValueOf(t),e.setCustomValidity(""),e.classList.remove("invalid"),this.showDeduction()}static opensPrecise(...t){return t.every(e=>e===void 0||er.isPickable(e)&&er.qualifierOf(Uh(e))==="")}static isPickable(t){return!!t&&t.year!==void 0&&t.month!==void 0&&t.day!==void 0&&t.hour!==void 0&&t.minute!==void 0}static pickerValueOf(t){if(!er.isPickable(t))return"";const e=(n,s=2)=>String(n).padStart(s,"0"),i=t.second?`:${e(t.second)}`:"";return`${e(t.year,4)}-${e(t.month)}-${e(t.day)}T${e(t.hour)}:${e(t.minute)}${i}`}static stepFor(t){return t?.second?"1":"60"}static qualifierOf(t){const e=/[?%]/.test(t),i=/[~%]/.test(t);return e&&i?"%":e?"?":i?"~":""}describe(t){return er.describeTime(t,this.messages,this.locale)}static describeTime(t,e,i){const n=Uh(t),s=er.qualifierOf(n),r=h=>String(h).padStart(2,"0"),o=[];if(t.season!==void 0){const h={spring:e.timeSeasonSpring,summer:e.timeSeasonSummer,autumn:e.timeSeasonAutumn,winter:e.timeSeasonWinter}[t.season];o.push(t.year!==void 0?`${h} ${t.year}`:h)}else if(t.year!==void 0){const h=t.day!==void 0?{...t.year>=1583?{weekday:"long"}:{},year:"numeric",month:"long",day:"numeric"}:t.month!==void 0?{year:"numeric",month:"long"}:{year:"numeric"},u=new Date(Date.UTC(t.year,(t.month??1)-1,t.day??1));o.push(new Intl.DateTimeFormat(i,{...h,timeZone:"UTC"}).format(u))}t.hour!==void 0&&o.push(`${r(t.hour)}:${r(t.minute??0)}${t.second!==void 0?`:${r(t.second)}`:""}`);const c=o.join(", "),l=s==="~"?e.timeQualifierApproximate:s==="?"?e.timeQualifierUncertain:s==="%"?e.timeQualifierBoth:"";return l?`${c} — ${l.toLowerCase()}`:c}setHint(t){this.hint=t,this.showDeduction()}showDeduction(){const{text:t}=this.parts,e=t.value.trim();if(this.precise||e===""){t.title=this.hint;return}const i=vd(e);t.title=i?`→ ${this.describe(i)}`:this.messages.edtfInvalid}readText(){const t=this.parts.text.value.trim();if(t===""){this.clean(),this.onChange(void 0);return}const e=vd(t);e&&(this.clean(),this.onChange(e))}clean(){this.parts.text.setCustomValidity(""),this.parts.text.classList.remove("invalid")}writeFromPicker(){const{picker:t,text:e}=this.parts;t.value===""&&t.validity.badInput||(e.value=t.value===""?"":t.value.replace(/\.\d+$/,""),this.readText())}validate(){const{text:t}=this.parts,e=t.value.trim();e===""||vd(e)||(t.setCustomValidity(this.messages.edtfInvalid),t.classList.add("invalid"))}}const Xm=2;function mM(a){return a==="building"||a==="vehicle"}const gM={aircraft:{id:"poly-google-airliner"}};function qf(a){return a.model??gM[a.kind]}function vM(a,t){const e=a.litKeyframes;if(!e||e.length===0)return a.lit??!1;let i=e[0];for(const n of e){if(n.t>t)break;i=n}return i.lit}function Ym(a,t){const e=a.observerKeyframes;if(!e||e.length===0)return{side:a.observerSide,facing:a.observerFacing};let i=e[0];for(const n of e){if(n.t>t)break;i=n}return{side:i.side,facing:i.facing}}function Px(a,t){return a.pattern.kind==="steady"?!0:MM(a,t,t+1)>.5}function MM(a,t,e){if(a.pattern.kind==="steady")return 1;const{perMinute:i,dutyCycle:n,phase:s=0}=a.pattern,r=Math.min(Math.max(n,0),1);if(r===0||i<=0)return 0;const o=6e4/i,c=t/o+s,l=e/o+s;if(l<=c)return Math.min(Math.max(c-Math.floor(c),0),r)<r?1:0;const h=u=>Math.floor(u)*r+Math.min(u-Math.floor(u),r);return(h(l)-h(c))/(l-c)}function Hr(a,t){const e=a.track,i={eastM:a.eastM,northM:a.northM,altitudeM:0,headingDeg:a.headingDeg};if(!e||e.length===0)return i;if(e.length===1||t<=e[0].t)return qm(e[0],a);const n=e[e.length-1];if(t>=n.t)return qm(n,a);for(let s=0;s<e.length-1;s++){const r=e[s],o=e[s+1];if(t<r.t||t>o.t)continue;const c=o.t-r.t,l=c===0?0:(t-r.t)/c;return{eastM:r.eastM+(o.eastM-r.eastM)*l,northM:r.northM+(o.northM-r.northM)*l,altitudeM:(r.altitudeM??0)+((o.altitudeM??0)-(r.altitudeM??0))*l,headingDeg:r.headingDeg??a.headingDeg}}return i}function qm(a,t){return{eastM:a.eastM,northM:a.northM,altitudeM:a.altitudeM??0,headingDeg:a.headingDeg??t.headingDeg}}const $m="#ff2200",Km="#00ff44",Zr="#ffffff",Il="#ffa500",ja="#ff0000",Ox="#2244ff",Lx=[{id:"airliner",name:"Airliner",kinds:["aircraft"],create:()=>[{id:"nav-port",offsetM:{x:-17,y:0,z:0},color:$m,pattern:{kind:"steady"}},{id:"nav-starboard",offsetM:{x:17,y:0,z:0},color:Km,pattern:{kind:"steady"}},{id:"nav-tail",offsetM:{x:0,y:1,z:-18},color:Zr,pattern:{kind:"steady"}},{id:"beacon-top",offsetM:{x:0,y:2,z:0},color:ja,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.18}},{id:"beacon-bottom",offsetM:{x:0,y:-2,z:0},color:ja,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.18}},{id:"strobe-port",offsetM:{x:-17,y:0,z:-1},color:Zr,intensity:20,pattern:{kind:"flash",perMinute:60,dutyCycle:.01}},{id:"strobe-starboard",offsetM:{x:17,y:0,z:-1},color:Zr,intensity:20,pattern:{kind:"flash",perMinute:60,dutyCycle:.01,phase:.08}}]},{id:"helicopter",name:"Helicopter",kinds:["aircraft"],create:()=>[{id:"nav-port",offsetM:{x:-5,y:0,z:0},color:$m,pattern:{kind:"steady"}},{id:"nav-starboard",offsetM:{x:5,y:0,z:0},color:Km,pattern:{kind:"steady"}},{id:"nav-tail",offsetM:{x:0,y:1,z:-7},color:Zr,pattern:{kind:"steady"}},{id:"beacon",offsetM:{x:0,y:2,z:-2},color:ja,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.2}},{id:"strobe",offsetM:{x:0,y:-1,z:0},color:Zr,intensity:15,pattern:{kind:"flash",perMinute:75,dutyCycle:.015}}]},{id:"car-headlights",name:"Car, headlights on",kinds:["vehicle"],create:()=>[{id:"head-left",offsetM:{x:-.7,y:.6,z:2},color:Zr,intensity:2,pattern:{kind:"steady"}},{id:"head-right",offsetM:{x:.7,y:.6,z:2},color:Zr,intensity:2,pattern:{kind:"steady"}},{id:"tail-left",offsetM:{x:-.7,y:.6,z:-2},color:ja,pattern:{kind:"steady"}},{id:"tail-right",offsetM:{x:.7,y:.6,z:-2},color:ja,pattern:{kind:"steady"}}]},{id:"car-hazards",name:"Car, hazard flashers",kinds:["vehicle"],create:()=>[{id:"hazard-front-left",offsetM:{x:-.8,y:.6,z:2},color:Il,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-front-right",offsetM:{x:.8,y:.6,z:2},color:Il,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-rear-left",offsetM:{x:-.8,y:.6,z:-2},color:Il,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-rear-right",offsetM:{x:.8,y:.6,z:-2},color:Il,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}}]},{id:"emergency-beacons",name:"Emergency vehicle beacons",kinds:["vehicle"],create:()=>[{id:"beacon-blue",offsetM:{x:-.4,y:1.6,z:0},color:Ox,intensity:2.5,pattern:{kind:"flash",perMinute:120,dutyCycle:.1}},{id:"beacon-red",offsetM:{x:.4,y:1.6,z:0},color:ja,intensity:2.5,pattern:{kind:"flash",perMinute:120,dutyCycle:.1,phase:.5}}]},{id:"streetlamp",name:"Streetlamp",kinds:["streetlight"],create:()=>[{id:"lamp",offsetM:{x:0,y:5,z:0},color:"#ffd9a0",intensity:2,pattern:{kind:"steady"}}]}];class ls{static NONE={id:"none",name:"No filter",opticalDensity:0};static SOLAR_VISUAL={id:"solar-visual",name:"Solar filter for the eye (OD 5)",opticalDensity:5};static SOLAR_PHOTO={id:"solar-photo",name:"Solar film for a camera (OD 3.8)",opticalDensity:3.8};static ALL=[ls.NONE,ls.SOLAR_VISUAL,ls.SOLAR_PHOTO];static byId(t){return ls.ALL.find(e=>e.id===t)??ls.NONE}static transmittance(t){return 10**-t.opticalDensity}static magnitudes(t){return 2.5*t.opticalDensity}}class zh{constructor(t){this.names=t}name(t){return this.names[t.toLowerCase()]??t}stored(t){const e=t.trim().toLowerCase();for(const[i,n]of Object.entries(this.names))if(n.toLowerCase()===e)return i;return t.trim()}}class sl{constructor(t,e,i,n=new zh({}),s){this.labels=t,this.naming=e,this.said=i,this.tags=n,this.timeWords=s}entriesFor(t,e,i={}){const n=[];return this.addSummary(n,t),this.addObservation(n,t),this.addObserver(n,t,e),this.addLocation(n,t,e,i.groundElevationM,i.roadGradeDeg??0),this.addDecor(n,t,e,i),i.phenomena===!0&&this.addPhenomena(n,t,e),this.addTemporal(n,t),this.addWeather(n,t,e),this.addSound(n,t,e),n}push(t,e,i,n,s,r="",o={}){s===void 0||s===""||t.push({group:e,field:i,label:n,value:String(s),unit:r,color:o.color,fromSource:o.fromSource===!0})}percent(t){return t===void 0?void 0:`${Math.round(t*100)} %`}rounded(t,e=0){return t===void 0?void 0:String(Number(t.toFixed(e)))}shows(t,e=0){return t!==void 0&&Number(t.toFixed(e))!==0}showsPercent(t){return this.shows(t===void 0?void 0:t*100)}percentShown(t){return this.showsPercent(t)?this.percent(t):void 0}roundedShown(t,e=0){return this.shows(t,e)?this.rounded(t,e):void 0}static DESCRIPTION_WORDS=3;addSummary(t,e){const i=this.said.read(e.event.description)?.trim();if(!i)return;const n=i.split(/\s+/),s=n.length>sl.DESCRIPTION_WORDS?`${n.slice(0,sl.DESCRIPTION_WORDS).join(" ")}…`:i;this.push(t,"summary","description",this.labels.summaryDescription,s),t[t.length-1].full=i}addObservation(t,e){const i=e.event.tags;this.push(t,"observation","tags",this.labels.tags,i&&i.length>0?i.map(n=>this.tags.name(n)).join(", "):void 0)}filterName(t){return t===ls.SOLAR_VISUAL?this.labels.filterSolarVisual:t===ls.SOLAR_PHOTO?this.labels.filterSolarPhoto:t.name}addObserver(t,e,i){const n=e.observer;this.push(t,"observer","observerId",this.labels.observerId,n?.id),this.push(t,"observer","observerTitle",this.labels.observerTitle,n?.title),this.push(t,"observer","observerLastName",this.labels.observerLastName,n?.lastName);const s=n?.firstNames;this.push(t,"observer","observerFirstNames",this.labels.observerFirstNames,s&&s.length>0?s.join(", "):void 0);const r=e.instrument;this.push(t,"observer","instrument",this.labels.instrument,this.naming.instrument(r));const o=e.exposure;this.push(t,"observer","exposureSeconds",this.labels.exposure,o===void 0?void 0:o<1?`1/${Math.round(1/o)}`:this.rounded(o,2),"s");const c=Ze(e,i);if(c){const l=bi.focalLengthMmFor(r,c.fovDeg);l===void 0?this.push(t,"observer","focalLength",this.labels.fieldOfView,this.rounded(c.fovDeg,1),"°"):this.push(t,"observer","focalLength",this.labels.focalLength,this.rounded(l,1),"mm"),this.push(t,"observer","fNumber",this.labels.aperture,this.rounded(c.fNumber??r.fNumber,1)),this.push(t,"observer","focusDistance",this.labels.focusDistance,this.rounded(c.focusDistanceM,1),"m"),this.push(t,"observer","roll",this.labels.roll,this.roundedShown(c.rollDeg),"°");const h=ls.byId(c.filter);h!==ls.NONE&&this.push(t,"observer","filter",this.labels.filter,this.filterName(h))}}degreesMinutesSeconds(t,e,i){if(t===void 0||!Number.isFinite(t))return;const n=Math.round(Math.abs(t)*3600),s=Math.floor(n/3600),r=Math.floor(n%3600/60),o=n%60;return`${s}°${String(r).padStart(2,"0")}′${String(o).padStart(2,"0")}″ ${this.naming.point(t<0?i:e)}`}addLocation(t,e,i,n,s){const r=e.event.place?.[0];this.push(t,"location","placeName",this.labels.placeName,r?.name);const o=Ze(e,i);if(!o)return;this.push(t,"location","lat",this.labels.latitude,this.degreesMinutesSeconds(o.lat,0,180)),this.push(t,"location","lng",this.labels.longitude,this.degreesMinutesSeconds(o.lng,90,270));const c=this.rounded(o.headingDeg);this.push(t,"location","heading",this.labels.heading,c,o.headingDeg===void 0?"°":`° (${this.naming.point(o.headingDeg)})`),this.push(t,"location","pitch",this.labels.pitch,o.pitchDeg===void 0?void 0:this.rounded(o.pitchDeg+s),"°"),n===void 0?this.push(t,"location","elevation",this.labels.heightAboveGround,this.roundedShown(o.elevationM),"m"):this.push(t,"location","elevation",this.labels.elevation,this.rounded(n+o.elevationM),"m")}addDecor(t,e,i,n){const s=e.decor.find(l=>l.id===n.decorId);if(!s){if(n.decorPicker===!0)for(const l of e.decor)this.push(t,"decor",`decor:${l.id}`,this.decorLabel(l),this.decorKindName(l.kind));return}this.push(t,"decor","decorTitle",this.labels.decorTitle,this.said.read(s.title));const r=Hr(s,i);this.push(t,"decor","decorEast",this.labels.decorEast,this.rounded(r.eastM,1),"m"),this.push(t,"decor","decorNorth",this.labels.decorNorth,this.rounded(r.northM,1),"m"),this.push(t,"decor","decorAltitude",this.labels.decorAltitude,this.roundedShown(r.altitudeM),"m"),this.push(t,"decor","decorHeading",this.labels.decorHeading,this.rounded(r.headingDeg),"°"),vM(s,i)&&this.push(t,"decor","decorLit",this.labels.decorLit,"✓");const o=s.lights?.map(l=>l.id).join()??"",c=o===""?void 0:Lx.find(l=>l.create().map(h=>h.id).join()===o);this.push(t,"decor","decorLightRig",this.labels.decorLights,c?.name),this.push(t,"decor","decorFloors",this.labels.decorFloors,s.floors),this.push(t,"decor","decorOccupiedFloor",this.labels.decorOccupiedFloor,s.occupiedFloor),this.push(t,"decor","decorObserverSide",this.labels.decorObserverSide,this.decorSideName(s.observerSide));for(const[l,h]of Object.entries(s.windows??{}))this.push(t,"decor",`decorWindow${this.capitalise(l)}`,`${this.labels.decorWindows} ${this.decorSideName(l)}`,h,"%")}timeText(t){return this.timeWords?er.describeTime(t,this.timeWords.messages,this.timeWords.locale):Uh(t)}addTemporal(t,e){const i=e.event;this.push(t,"temporal","obs-time",this.labels.observationTime,i.time&&this.timeText(i.time)),this.push(t,"temporal","obs-end-time",this.labels.observationEndTime,i.endTime&&this.timeText(i.endTime));const n=fM(i);this.push(t,"temporal","durationSeconds",this.labels.duration,this.roundedShown(n&&n/1e3,1),"s"),this.push(t,"temporal","timeZone",this.labels.utcOffset,i.timeZone),this.push(t,"temporal","utcOffsetHours",this.labels.utcOffset,this.rounded(i.utcOffsetHours,1),"UTC±h")}addWeather(t,e,i){const n=Eo(e,i),r={fromSource:e.weatherSource!==void 0},o=this.showsPercent(n.cloudCover)||this.showsPercent(n.lowerCloudCover)||this.showsPercent(n.highCloudCover);this.push(t,"weather","cloudCover",this.labels.cloudCover,this.percentShown(n.cloudCover),"",r),this.push(t,"weather","highCloudCover",this.labels.highCloudCover,this.percentShown(n.highCloudCover),"",r),this.push(t,"weather","iceCrystalAlignment",this.labels.iceCrystalAlignment,this.showsPercent(n.highCloudCover)?this.percent(n.iceCrystalAlignment):void 0),this.push(t,"weather","cloudDarkness",this.labels.cloudDarkness,o?this.percent(n.cloudDarkness):void 0,"",r),this.push(t,"weather","cloudBase",this.labels.cloudBase,o?this.rounded(n.cloudBaseM):void 0,"m",r);const c=n.precipitationType!=="none"&&this.showsPercent(n.precipitationIntensity);this.push(t,"weather","precipitationType",this.labels.precipitationType,c?this.precipitationName(n.precipitationType):void 0,"",r),this.push(t,"weather","precipitationIntensity",this.labels.precipitationIntensity,c?this.percent(n.precipitationIntensity):void 0,"",r),this.push(t,"weather","windDirection",this.labels.windDirection,this.shows(n.windSpeed,2)?this.rounded(n.windDirectionDeg):void 0,"°",r),this.push(t,"weather","windSpeed",this.labels.windSpeed,this.roundedShown(n.windSpeed,2),"m/s",r),n.storm&&this.push(t,"weather","storm",this.labels.storm,"✓","",r)}addSound(t,e,i){const n=pM(e,i);n.kind!=="none"&&(this.push(t,"sound","soundKind",this.labels.soundKind,this.soundKindName(n.kind)),this.push(t,"sound","soundVolume",this.labels.soundVolume,this.percentShown(n.volume)),this.push(t,"sound","soundPitch",this.labels.soundPitch,this.roundedShown(n.pitchHz),"Hz"),this.push(t,"sound","soundSrc",this.labels.soundSrc,n.src))}addPhenomena(t,e,i){for(const n of e.timeline.sourceIds){const s=e.timeline.getInterpolatedShapeAt(i,n),r=s?.angular,o=r?`${this.rounded(r.widthDeg,2)} × ${this.rounded(r.heightDeg,2)}°`:void 0;this.push(t,"phenomenon",`shape:${n}`,this.said.read(s?.title)??n,o)}for(const n of e.interpretation?.bodies??[]){const s=n.track.find(o=>o.sizeM?.widthM!==void 0)?.sizeM?.widthM,r=n.model.id??n.model.url?.replace(/^.*\//,"");this.push(t,"phenomenon",`body:${n.id}`,this.said.read(n.title)??n.id,[r,s!==void 0?`${this.rounded(s,2)} m`:void 0].filter(Boolean).join(", "))}}decorLabel(t){return this.said.read(t.title)??this.decorKindName(t.kind)}decorKindName(t){switch(t){case"building":return this.labels.decorBuilding;case"tree":return this.labels.decorTree;case"shrub":return this.labels.decorShrub;case"bridge":return this.labels.decorBridge;case"wire":return this.labels.decorWire;case"crop":return this.labels.decorCrop;case"terrace":return this.labels.decorTerrace;case"mound":return this.labels.decorMound;case"streetlight":return this.labels.decorStreetlight;case"vehicle":return this.labels.decorVehicle;case"aircraft":return this.labels.decorAircraft;default:return this.labels.decorObserver}}decorSideName(t){switch(t){case"front":return this.labels.decorSideFront;case"behind":return this.labels.decorSideBehind;case"left":return this.labels.decorSideLeft;case"right":return this.labels.decorSideRight;case"front-left":return this.labels.decorSideFrontLeft;case"front-right":return this.labels.decorSideFrontRight;case"behind-left":return this.labels.decorSideBehindLeft;case"behind-right":return this.labels.decorSideBehindRight;default:return}}precipitationName(t){switch(t){case"rain":return this.labels.precipitationRain;case"snow":return this.labels.precipitationSnow;case"hail":return this.labels.precipitationHail;default:return this.labels.precipitationNone}}soundKindName(t){switch(t){case"hum":return this.labels.soundHum;case"whistle":return this.labels.soundWhistle;case"rumble":return this.labels.soundRumble;case"crackle":return this.labels.soundCrackle;default:return this.labels.soundNone}}capitalise(t){return t.replace(/(^|-)([a-z])/g,(e,i,n)=>n.toUpperCase())}}class Yn{constructor(t){this.preferences=t}read(t){if(t===void 0||typeof t=="string")return t===""?void 0:t;for(const i of this.preferences){const n=t[i]??t[Yn.base(i)];if(n)return n}const e=new Set(this.preferences.map(i=>Yn.base(i)));for(const[i,n]of Object.entries(t))if(n&&e.has(Yn.base(i)))return n;return Object.values(t).find(i=>i)??void 0}write(t,e,i){const n=e?.trim()?e.trim():void 0;if(t===void 0||typeof t=="string")return n;const s={...t},r=Object.keys(s).find(o=>o===i)??Object.keys(s).find(o=>Yn.base(o)===Yn.base(i))??i;return n===void 0?delete s[r]:s[r]=n,Object.keys(s).length===0?void 0:s}static base(t){return t.toLowerCase().split("-")[0]}}function Ep(a,t){for(const e of a){const i=e.toLowerCase().split("-")[0];if(t.includes(i))return i}return"en"}class Gr{static preferencesFor(t){const e=navigator.languages??[],i=this.declaredFor(t);return i?[i,...e]:e}static declaredFor(t){for(let e=t;e;){const i=e.closest("[lang]")?.getAttribute("lang")?.trim();if(i)return i;const n=e.getRootNode();e=n instanceof ShadowRoot?n.host:void 0}}}const Nx="Global Meteor Network",kx="https://globalmeteornetwork.org/data/",Fx="“Thunder” by Jerimee",Ux="https://creativecommons.org/licenses/by/3.0/",zx="CC BY 3.0";class rn{static fill(t,e){t.innerHTML="";const i=h=>t.appendChild(h),n=e.currentTerrainAttribution;n&&i(rn.text(n));const s=e.currentRoadAttribution;s&&i(rn.text(s));const r=e.ufoElement.observerMapCredit;r&&!n?.includes(r)&&i(rn.text(r));for(const h of e.decorModelCredits){const u=h.author?` — ${h.author}`:"",d=document.createElement("li");h.sourceUrl?d.append(rn.link(h.sourceUrl,h.title),document.createTextNode(`${u} (${h.license})`)):d.textContent=`${h.title}${u} (${h.license})`,i(d)}for(const h of e.ufoElement.sighting.references){if(!h.credit)continue;const u=document.createElement("li");h.creditUrl?u.appendChild(rn.link(h.creditUrl,h.credit)):u.textContent=h.credit,i(u)}if(e.ufoElement.sighting.traces.length>0){const h=new Yn(Gr.preferencesFor(e)),u=new Set(e.ufoElement.sighting.traces.map(d=>h.read(d.source)).filter(d=>!!d));for(const d of u)i(rn.text(d))}const o=e.satelliteState;if(o.status==="ready"&&o.credit){const h=document.createElement("li");h.appendChild(rn.link(o.creditUrl??"",o.credit)),i(h)}if(e.fireballState.status==="ready"&&e.fireballState.records.length>0){const h=document.createElement("li");h.append(rn.link(kx,Nx),document.createTextNode(" (CC BY 4.0)")),i(h)}const c=e.aircraftState;if(c.status==="ready"&&c.shown>0){const h=document.createElement("li");if(h.appendChild(rn.link(c.creditUrl,c.credit)),i(h),c.trailCredit){const u=document.createElement("li");u.appendChild(rn.link(c.trailCredit.creditUrl,c.trailCredit.credit)),i(u)}}const l=rn.text(`${Fx} (`);l.append(rn.link(Ux,zx),document.createTextNode(")")),i(l)}static text(t){const e=document.createElement("li");return e.textContent=t,e}static link(t,e){const i=document.createElement("a");return i.href=t,i.target="_blank",i.rel="noopener",i.textContent=e,i}}const Bx=[{id:"coverage",name:"Coverage",credit:"UFO@home",creditUrl:"https://ufoathome.org",create:()=>({about:"observer",assess:async a=>{const{CoverageAssessor:t}=await je(async()=>{const{CoverageAssessor:e}=await import("./CoverageAssessor-CZfxbN9A.js");return{CoverageAssessor:e}},[],import.meta.url);return new t().assess(a)}})},{id:"hynek",name:"Hynek",credit:"J. Allen Hynek",creditUrl:"https://rr0.org/science/crypto/ufo/observation/classification/hynek/",create:()=>({about:"temporal",assess:async a=>{const{HynekAssessor:t}=await je(async()=>{const{HynekAssessor:e}=await import("./HynekAssessor-DPsLpEGQ.js");return{HynekAssessor:e}},[],import.meta.url);return new t().assess(a)}})}];class Hx{constructor(t){this.labels=t}async read(t){const e=[],i=new Set;for(const n of Bx){let s;try{s=await n.create().assess(t)}catch{continue}for(const o of s.criteria)o.basis===void 0&&!o.unsupported&&i.add(o.id);const r=s.score===void 0?s.verdict===void 0?"":this.verdictName(n.id,s.verdict):`${Math.round(s.score*100)}%`;r!==""&&e.push({group:"assessment",field:n.id,label:this.labels.assessmentNames[n.id]??n.name,value:r,unit:"",fromSource:!1,about:n.create().about})}return{entries:e,unanswered:i}}verdictName(t,e){return this.labels.assessmentVerdicts[`${t}.${e}`]??e.toUpperCase()}}const yM=Math.PI/180,yu=111320;function si(a,t,e,i){const n=yu*Math.cos(e*yM),s=(a-e)*yu;return{x:(t-i)*n,z:-s}}function Nn(a,t,e,i){const n=yu*Math.cos(e*yM),s=-t,r=a;return{lat:e+s/yu,lng:i+r/n}}class Ro{static HALF_SPAN_MS=2e3;static MIN_SPEED_MS=1;static at(t,e,i){const n=t.event.place?.[0],s=t.observerTrack;if(!n)return 0;const r=v=>{const m=s.getInterpolatedPoseAt(Math.max(0,v));if(!m||m.lat===void 0||m.lng===void 0)return;const g=si(m.lat,m.lng,n.lat,n.lng);return{eastM:g.x,northM:-g.z,heading:m.headingDeg}},o=r(e-Ro.HALF_SPAN_MS),c=r(e+Ro.HALF_SPAN_MS),l=r(e);if(!o||!c||!l)return 0;const h=Math.hypot(c.eastM-o.eastM,c.northM-o.northM),u=2*Ro.HALF_SPAN_MS/1e3;if(h/u<Ro.MIN_SPEED_MS)return 0;const d=i.heightAt(c.eastM,c.northM)-i.heightAt(o.eastM,o.northM),f=Math.atan2(d,h)*180/Math.PI;if(l.heading===void 0)return f;const p=Math.atan2(c.eastM-o.eastM,c.northM-o.northM)*180/Math.PI;return f*Math.max(0,Math.cos((l.heading-p)*Math.PI/180))}}class Oa{static sessionDeclared=!1;static unlock(t){if(Oa.declarePlayback(),t.state!=="running")try{Promise.resolve(t.resume()).catch(()=>{});const e=t.createBufferSource();e.buffer=t.createBuffer(1,1,22050),e.connect(t.destination),e.start(0)}catch{}}static declarePlayback(){if(!(Oa.sessionDeclared||typeof navigator>"u")){Oa.sessionDeclared=!0;try{const t=navigator.audioSession;t&&(t.type="playback")}catch{}}}}const Gx=.08,Zm=.15,Jm=2,Vx=2e3;class Wx{context;noiseBuffer;voices=new Map;level=1;master;paused=!0;requested=[];resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("VehicleAudio: Web Audio unavailable, vehicles stay silent:",t);return}}Oa.unlock(this.context),this.apply()}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}setPaused(t){t!==this.paused&&(this.paused=t,this.apply())}setVoices(t){this.requested=t,this.apply()}dispose(){for(const t of[...this.voices.keys()])this.release(t);this.context?.close(),this.context=void 0,this.master=void 0}masterOf(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}apply(){const t=this.context;if(!t)return;const e=this.paused?[]:this.requested.filter(n=>n.inside||n.distanceM<Vx),i=new Set(e.map(n=>n.id));for(const n of[...this.voices.keys()])i.has(n)||this.release(n);for(const n of e){const s=this.voices.get(n.id)??this.build(t,n.id);this.retarget(t,s,n)}}build(t,e){const i=t.createGain();i.gain.value=0;const n=t.createBiquadFilter();n.type="lowpass",n.connect(i).connect(this.masterOf(t));const s=t.createOscillator();s.type="sawtooth";const r=t.createOscillator();r.type="sine";const o=t.createGain(),c=t.createBiquadFilter();c.type="lowpass",c.frequency.value=900,s.connect(c),r.connect(c),c.connect(o).connect(n);const l=()=>{const x=t.createBufferSource();return x.buffer=this.noise(t),x.loop=!0,x.loopStart=Math.random()*Jm*.5,x},h=l(),u=t.createBiquadFilter();u.type="bandpass",u.Q.value=4;const d=t.createGain();h.connect(u).connect(d).connect(n);const f=l(),p=t.createBiquadFilter();p.type="lowpass",p.frequency.value=600;const v=t.createGain();f.connect(p).connect(v).connect(n);const m=l(),g=t.createBiquadFilter();g.type="bandpass",g.frequency.value=1400,g.Q.value=.7;const b=t.createGain();m.connect(g).connect(b).connect(n);const S=[s,r,h,f,m];for(const x of S)x.start();const M={nodes:[i,n,o,c,u,d,p,v,g,b,...S],sources:S,firing:s,crank:r,knock:u,engineGain:o,knockGain:d,roadGain:v,windGain:b,cabin:n,output:i};return this.voices.set(e,M),M}retarget(t,e,{profile:i,state:n,noise:s,inside:r,windowsOpen:o,distanceM:c}){const l=t.currentTime,h=(b,S)=>b.setTargetAtTime(S,l,Gx),u=n.rpm/60,d=u*i.cylinders/2,f=Math.min(1,n.rpm/i.shiftUpRpm),p=Math.min(1.5,n.speedMps/30);h(e.firing.frequency,d),h(e.crank.frequency,u),h(e.knock.frequency,d*3),h(e.engineGain.gain,i.engineGain*(.25+.75*n.load)*(.5+.5*f)*.3),h(e.knockGain.gain,i.roughness*(.2+.8*n.load)*.4),h(e.roadGain.gain,i.roadGain*p**1.5*.8);const v=!r||o;h(e.windGain.gain,p**2*(v?.5:.06));const m=r?o?3500:700:8e3/(1+c/60);h(e.cabin.frequency,m);const g=r?.5:Math.min(1,8/Math.max(c,1));h(e.output.gain,g*s)}release(t){const e=this.voices.get(t);if(!e)return;this.voices.delete(t);const i=this.context;i&&(e.output.gain.setTargetAtTime(0,i.currentTime,Zm/3),setTimeout(()=>{for(const n of e.sources)try{n.stop()}catch{}for(const n of e.nodes)n.disconnect()},Zm*1e3*3))}noise(t){if(this.noiseBuffer)return this.noiseBuffer;const e=t.createBuffer(1,t.sampleRate*Jm,t.sampleRate),i=e.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;return this.noiseBuffer=e,e}}class rl{static BY_KIND={car:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},generic:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},van:{cylinders:4,idleRpm:750,kmhPer1000Rpm:[7,12,19,27,35,42],shiftUpRpm:2600,shiftDownRpm:1200,engineGain:.8,roadGain:.7,roughness:.45},truck:{cylinders:6,idleRpm:600,kmhPer1000Rpm:[5,8,12,17,23,30,38,48],shiftUpRpm:1900,shiftDownRpm:1e3,engineGain:1,roadGain:.9,roughness:.55},motorcycle:{cylinders:2,idleRpm:1100,kmhPer1000Rpm:[12,18,24,30,35,40],shiftUpRpm:6e3,shiftDownRpm:2500,engineGain:.9,roadGain:.3,roughness:.3}};static of(t){return rl.BY_KIND[t??"generic"]??rl.BY_KIND.generic}}class Ea{constructor(t,e){this.samples=t,this.startMs=e}static SAMPLE_MS=100;static STANDING_MPS=.3;static of(t,e,i,n){const s=Ea.SAMPLE_MS,r=[];for(let l=i;l<=n+s/2;l+=s){const h=e(l-s/2),u=e(l+s/2);if(!h||!u)return;r.push(Math.hypot(u.eastM-h.eastM,u.northM-h.northM)/(s/1e3))}const o=[];let c=1;for(let l=0;l<r.length;l++){const h=r[l],u=(r[Math.min(l+1,r.length-1)]-r[Math.max(l-1,0)])/(2*s/1e3);if(h<Ea.STANDING_MPS){c=1,o.push({speedMps:h,rpm:t.idleRpm,load:.1,gear:0});continue}const d=h*3.6,f=g=>d/t.kmhPer1000Rpm[g-1]*1e3;for(;c<t.kmhPer1000Rpm.length&&f(c)>t.shiftUpRpm;)c++;for(;c>1&&f(c)<t.shiftDownRpm;)c--;const p=Math.max(f(c),t.idleRpm*(1+.3*Math.min(1,h/3))),v=.15+.5*Math.min(1,(h/35)**2),m=u>.15?Math.min(1,v+u/2.5):u<-.3?.05:v;o.push({speedMps:h,rpm:p,load:m,gear:c})}return new Ea(o,i)}at(t){const e=(t-this.startMs)/Ea.SAMPLE_MS,i=Math.min(Math.max(Math.floor(e),0),this.samples.length-1),n=this.samples[i],s=this.samples[Math.min(i+1,this.samples.length-1)],r=Math.min(Math.max(e-i,0),1);return{speedMps:n.speedMps+(s.speedMps-n.speedMps)*r,rpm:n.rpm+(s.rpm-n.rpm)*r,load:n.load+(s.load-n.load)*r,gear:r<.5?n.gear:s.gear}}}class xu{drives=new Map;at(t,e){const i=[],n=t.event.place?.[0],s=l=>{const h=t.observerTrack.getInterpolatedPoseAt(l),u=h?.lat??n?.lat,d=h?.lng??n?.lng;if(u===void 0||d===void 0||!n)return;const f=si(u,d,n.lat,n.lng);return{eastM:f.x,northM:-f.z}},r=Math.max(t.observerTrack.duration,(t.event.durationSeconds??0)*1e3),o=t.vehicle;if(o){const l=rl.of(o.kind),h=this.drive(`observer:${o.kind}`,xu.trackKey(t),()=>Ea.of(l,s,0,r));h&&i.push({id:"observer",profile:l,state:h.at(e),noise:o.noise??1,inside:!0,windowsOpen:o.windowsOpen===!0,distanceM:0})}const c=s(e);for(const l of t.decor){if(!l.engine||!c)continue;const h=rl.of(l.engine.kind),u=v=>{const m=Hr(l,v);return{eastM:m.eastM,northM:m.northM}},d=this.drive(`decor:${l.id}`,xu.decorKey(l,r),()=>Ea.of(h,u,0,r));if(!d)continue;const f=Hr(l,e),p=Math.hypot(f.eastM-c.eastM,f.northM-c.northM,f.altitudeM);i.push({id:`decor:${l.id}`,profile:h,state:d.at(e),noise:l.engine.noise??1,inside:!1,windowsOpen:!0,distanceM:p})}return i}drive(t,e,i){const n=this.drives.get(t);if(n&&n.key===e)return n.drive;const s=i();return this.drives.set(t,{key:e,drive:s}),s}static trackKey(t){return t.observerTrack.allKeyframes.map(i=>`${i.t}:${i.pose.lat}:${i.pose.lng}`).join(";")}static decorKey(t,e){return`${e}|${t.eastM},${t.northM}|`+(t.track??[]).map(i=>`${i.t}:${i.eastM}:${i.northM}`).join(";")}}const jm=864e5,Qm=4e4;function Xx(a){const t=Math.floor(a.getTime()/jm);return{elapsedMs:a.getTime()-t*jm,shiftM:{x:tg.unit(t,2654435761)*Qm,z:tg.unit(t,2246822507)*Qm}}}class tg{static unit(t,e){let i=Math.imul(t|0,e)^e;return i=Math.imul(i^i>>>15,739982445),i=Math.imul(i^i>>>12,695872825),i^=i>>>15,(i>>>0)/4294967295*2-1}}function eg(a,t,e,i,n,s,r){const o=i?.lat!==void 0&&i.lng!==void 0&&n?.lat!==void 0&&n.lng!==void 0?si(n.lat,n.lng,i.lat,i.lng):{x:0,z:0};if(r){const h=t.getInterpolatedWeatherAt(0)??e,u=s===void 0?void 0:h.cloudLayers?.find(p=>p.id===s),d=(u?.windDirectionDeg??h.windDirectionDeg)*Math.PI/180,f=(u?.windSpeed??h.windSpeed)*r.elapsedMs/1e3;o.x+=r.shiftM.x-Math.sin(d)*f,o.z+=r.shiftM.z+Math.cos(d)*f}const c=Math.max(0,a),l=[0,...t.allKeyframes.map(h=>h.t).filter(h=>h>0&&h<c),c];for(let h=1;h<l.length;h++){const u=l[h-1],d=l[h]-u;if(d===0)continue;const f=32;for(let p=0;p<=f;p++){const v=t.getInterpolatedWeatherAt(u+d*p/f)??e,m=s===void 0?void 0:v.cloudLayers?.find(M=>M.id===s),g=(m?.windDirectionDeg??v.windDirectionDeg)*Math.PI/180,b=p===0||p===f?1:p%2===0?2:4,S=(m?.windSpeed??v.windSpeed)*d/1e3/f/3*b;o.x-=Math.sin(g)*S,o.z+=Math.cos(g)*S}}return o}const Yx=`
772
+ `;class Ka extends Error{constructor(t,e,i){super(`${t}: ${e}${i===void 0?"":` (HTTP ${i})`}`),this.kind=t,this.url=e,this.status=i,this.name="SightingFetchError"}}class Gc{static async json(t){const e=new URL(t,location.href);if(location.protocol==="https:"&&e.protocol==="http:")throw new Ka("mixed-content",t);let i;try{i=await fetch(t)}catch{throw await this.diagnose(t,e)}if(!i.ok)throw new Ka("status",t,i.status);try{return await i.json()}catch{throw new Ka("malformed",t)}}static async diagnose(t,e){if(e.origin===location.origin)return new Ka("unreachable",t);try{return await fetch(t,{mode:"no-cors"}),new Ka("cors",t)}catch{return new Ka("unreachable",t)}}}class hn{constructor(t){this.entries=t}static empty(){return new hn(new Map)}get size(){return this.entries.size}at(t){return this.entries.get(t)}paths(){return[...this.entries.keys()]}set(t,e){e.basis==="stated"&&e.rationale===void 0?this.entries.delete(t):this.entries.set(t,e)}clear(t){for(const e of this.entries.keys())(e===t||e.startsWith(`${t}.`))&&this.entries.delete(e)}static strip(t){const e=new hn(new Map);return{recording:hn.stripValue(t,[],e),provenance:e}}static restore(t,e){if(e.size===0)return t;const i=structuredClone(t);for(const n of e.paths()){const s=e.at(n),r=n.split("."),o=hn.holderOf(i,r);if(!o)continue;const c=r[r.length-1],l=o[c];l!==void 0&&(s.of!==void 0&&JSON.stringify(s.of)!==JSON.stringify(l)||(o[c]={value:l,...s.basis==="stated"?{}:{basis:s.basis},...s.rationale===void 0?{}:{rationale:s.rationale}}))}return i}static isWrapper(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&"value"in t}static stripValue(t,e,i){return hn.isWrapper(t)?(i.set(e.join("."),{basis:t.basis??"stated",...t.rationale===void 0?{}:{rationale:t.rationale},of:t.value}),hn.stripValue(t.value,e,i)):Array.isArray(t)?t.map((n,s)=>hn.stripValue(n,[...e,String(s)],i)):typeof t=="object"&&t!==null?Object.fromEntries(Object.entries(t).map(([n,s])=>[n,hn.stripValue(s,[...e,n],i)])):t}static holderOf(t,e){let i=t;for(const n of e.slice(0,-1)){if(typeof i!="object"||i===null)return;i=i[n]}return typeof i=="object"&&i!==null?i:void 0}}class cs{static SIGHTING_EVENT="sighting";static INTERPRETATION_EVENT="interpretation";static isCase(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Array.isArray(t.events)&&!("timeline"in t)}static sightingUrls(t,e){return(t.events??[]).filter(i=>i.eventType===cs.SIGHTING_EVENT&&!i.interpretationOf&&typeof i.url=="string"&&i.url!=="").map(i=>new URL(i.url,e).href)}static interpretationEvents(t,e){return e?(t.events??[]).filter(i=>i.eventType===cs.INTERPRETATION_EVENT?i.sighting===e:i.eventType!==cs.SIGHTING_EVENT||i.interpretationOf===void 0?!1:[i.interpretationOf].flat().includes(e)).map(i=>i):[]}static async interpretationOf(t,e,i){if(t.bodies||t.reentries)return cs.withModelsFrom(hn.strip({title:t.title,bodies:t.bodies??[],smoke:t.smoke,reentries:t.reentries}).recording,e);if(!t.url)return{title:t.title,bodies:[]};const n=new URL(t.url,e).href,s=await i(n),r="timeline"in s&&s.interpretation?s.interpretation:s;return cs.withModelsFrom(hn.strip({title:t.title??r.title,bodies:r.bodies??[],smoke:r.smoke,reentries:r.reentries}).recording,n)}static withModelsFrom(t,e){return{...t,bodies:t.bodies.map(i=>i.model?.url?{...i,model:{...i.model,url:new URL(i.model.url,e).href}}:i)}}}class Vc{static ISO=/^P(?:(\d+(?:[.,]\d+)?)W)?(?:(\d+(?:[.,]\d+)?)D)?(?:T(?:(\d+(?:[.,]\d+)?)H)?(?:(\d+(?:[.,]\d+)?)M)?(?:(\d+(?:[.,]\d+)?)S)?)?$/;static seconds(t){const e=t.trim().toUpperCase(),i=Vc.ISO.exec(e);if(!i||e==="P"||e.endsWith("T"))return;const[,n,s,r,o,c]=i,l=u=>u===void 0?0:Number(u.replace(",",".")),h=l(n)*604800+l(s)*86400+l(r)*3600+l(o)*60+l(c);return Number.isFinite(h)?h:void 0}static parse(t){let e=t.trim();if(e==="")return;const i=e.slice(-1),n="?~%".includes(i)?i:"";n!==""&&(e=e.slice(0,-1).trim());const s=e.split("/");if(s.length>2)return;const r=s.map(u=>Vc.seconds(u));if(r.some(u=>u===void 0))return;const[o,c]=r,l=Math.min(o,c??o),h=Math.max(o,c??o);return{doubt:n,minSeconds:l,maxSeconds:h,chosenSeconds:(l+h)/2}}static isExact(t){const e=Vc.parse(t);return e!==void 0&&e.doubt===""&&e.minSeconds===e.maxSeconds}static format(t){const e=Math.max(0,Math.round(t*10)/10),i=Math.floor(e/3600),n=Math.floor(e%3600/60),s=Math.round(e%60*10)/10;return`PT${`${i>0?`${i}H`:""}${n>0?`${n}M`:""}${s>0||i===0&&n===0?`${s}S`:""}`}`}static say(t){const e=Math.round(t*10)/10;if(e<60)return`${e} s`;const i=Math.floor(e/3600),n=Math.floor(e%3600/60),s=Math.round(e%60*10)/10,r=[];return i>0&&r.push(`${i} h`),n>0&&r.push(`${n} min`),s>0&&r.push(`${s} s`),r.join(" ")}}class Fe{static MOON_ANGULAR_WIDTH_DEG=.5237;static CANVAS_WIDTH_PX=640;static CANVAS_HEIGHT_PX=360;static angularWidthDeg(t){return 2*Math.atan(t.sizeM/(2*t.distanceM))*180/Math.PI}static inMoons(t){return t/Fe.MOON_ANGULAR_WIDTH_DEG}static lerpAngular(t,e,i){if(!(!t||!e))return{widthDeg:t.widthDeg+(e.widthDeg-t.widthDeg)*i,heightDeg:t.heightDeg+(e.heightDeg-t.heightDeg)*i}}static sizeMAt(t,e){return 2*t*Math.tan(e*Math.PI/360)}static distanceMAt(t,e){return t/(2*Math.tan(e*Math.PI/360))}}function Sy(a,t,e){if(!a||!t)return e<1?a:t;const i=((t.azimuthDeg-a.azimuthDeg)%360+540)%360-180;return{azimuthDeg:((a.azimuthDeg+i*e)%360+360)%360,altitudeDeg:a.altitudeDeg+(t.altitudeDeg-a.altitudeDeg)*e}}function wy(a,t,e){const{bounds:i}=a;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height}function vn(a,t,e){return a+(t-a)*e}function Em(a){const t=/^#([0-9a-f]{6})$/i.exec(a);if(!t)return;const e=parseInt(t[1],16);return[e>>16&255,e>>8&255,e&255]}function _y(a){return`#${a.map(t=>Math.round(t).toString(16).padStart(2,"0")).join("")}`}function Ey(a,t,e){const i=Em(a),n=Em(t);return!i||!n?e<1?a:t:_y([vn(i[0],n[0],e),vn(i[1],n[1],e),vn(i[2],n[2],e)])}function Ay(a,t,e){const i={x:vn(a.bounds.x,t.bounds.x,e),y:vn(a.bounds.y,t.bounds.y,e),width:vn(a.bounds.width,t.bounds.width,e),height:vn(a.bounds.height,t.bounds.height,e)},n=vn(a.angle,t.angle,e),s=vn(a.transparency,t.transparency,e),r=vn(a.haloScale,t.haloScale,e),o=vn(a.blur??0,t.blur??0,e),c=vn(a.brightness??0,t.brightness??0,e),l=Ey(a.color,t.color,e),h=Fe.lerpAngular(a.angular,t.angular,e),u=Sy(a.aim,t.aim,e);return a.kind==="polygon"&&t.kind==="polygon"&&a.points.length===t.points.length?{...a,bounds:i,angle:n,transparency:s,haloScale:r,blur:o,brightness:c,color:l,angular:h,aim:u,points:a.points.map((d,f)=>({x:vn(d.x,t.points[f].x,e),y:vn(d.y,t.points[f].y,e)}))}:{...e<1?a:t,bounds:i,angle:n,transparency:s,haloScale:r,blur:o,brightness:c,color:l,angular:h,aim:u}}class aa{static DEFAULT_COLOR="#e8e6df";static complete(t,e=[]){const i=new Map;return t.map((n,s)=>({keyframe:n,index:s})).sort((n,s)=>n.keyframe.t-s.keyframe.t).map(({keyframe:n,index:s})=>({t:n.t,shapes:(n.shapes??[]).map((r,o)=>{const c=`timeline.keyframes.${s}.shapes.${o}.shape`,l=aa.completed(r,i.get(r.sourceId),c,e);return i.set(r.sourceId,l),{sourceId:r.sourceId,shape:l}})}))}static completed(t,e,i,n){const s=t.shape??{},r=e??aa.firstAppearance(s,i,n),o={...r};s.bounds&&e&&(e.aim||e.angular)&&!s.aim&&!s.angular&&n.push({kind:"pixels-over-angles",path:i}),s.bounds&&(s.aim||delete o.aim,s.angular||delete o.angular);const c=s.kind??r.kind??"oval",l={...o,...s,kind:c};if(c==="polygon"&&!l.points){n.push({kind:"defaulted",path:`${i}.points`,expected:"rectangle"});const{width:h,height:u}=l.bounds;return{...l,points:[{x:0,y:0},{x:h,y:0},{x:h,y:u},{x:0,y:u}]}}return l}static firstAppearance(t,e,i){return t.kind||i.push({kind:"defaulted",path:`${e}.kind`,expected:'"oval"'}),t.color||i.push({kind:"defaulted",path:`${e}.color`,expected:`"${aa.DEFAULT_COLOR}"`}),!t.bounds&&!t.aim&&i.push({kind:"unplaced",path:e}),!t.bounds&&!t.angular&&i.push({kind:"unsized",path:e}),{kind:t.kind??"oval",bounds:{...aa.NEUTRAL_BOUNDS},color:aa.DEFAULT_COLOR,angle:0,transparency:0,haloScale:0,selected:!1}}static NEUTRAL_BOUNDS={x:Fe.CANVAS_WIDTH_PX/2,y:Fe.CANVAS_HEIGHT_PX/2,width:1,height:1}}class Ku{keyframes=[];order=[];groups=[];addKeyframe(t,e){const i=this.findInsertIndex(t);if(this.keyframes[i]?.t===t){const n=new Set(e.map(s=>s.sourceId));this.keyframes[i]={t,shapes:[...this.keyframes[i].shapes.filter(s=>!n.has(s.sourceId)),...e]}}else this.keyframes.splice(i,0,{t,shapes:[...e]});for(const n of e)this.order.includes(n.sourceId)||this.order.push(n.sourceId)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getKeyframeAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e];return i?.t===t?i:void 0}getShapeAt(t,e){return this.getKeyframeAt(t)?.shapes.find(i=>i.sourceId===e)?.shape}getLatestShapeAt(t,e){let i=this.findInsertIndex(t);for(this.keyframes[i]?.t!==t&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return n.shape}}getInterpolatedShapeAt(t,e){const i=this.findShapeAtOrBefore(t,e);if(i?.t===t)return i.shape;const n=this.findShapeAtOrAfter(t,e);return i?n?Ay(i.shape,n.shape,(t-i.t)/(n.t-i.t)):i.shape:n?.shape}findShapeAtOrBefore(t,e){let i=this.findInsertIndex(t);for(this.keyframes[i]?.t!==t&&(i-=1);i>=0;i--){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}findShapeAtOrAfter(t,e){for(let i=this.findInsertIndex(t);i<this.keyframes.length;i++){const n=this.keyframes[i].shapes.find(s=>s.sourceId===e);if(n)return{t:this.keyframes[i].t,shape:n.shape}}}hitTest(t,e,i,n){const s=this.sourceIds;for(let r=s.length-1;r>=0;r--){if(n?.has(s[r]))continue;const o=this.getInterpolatedShapeAt(t,s[r]);if(o&&wy(o,e,i))return{sourceId:s[r],shape:o}}}removeSource(t){for(let e=this.keyframes.length-1;e>=0;e--){const i=this.keyframes[e].shapes.filter(n=>n.sourceId!==t);i.length===0?this.keyframes.splice(e,1):i.length!==this.keyframes[e].shapes.length&&(this.keyframes[e]={t:this.keyframes[e].t,shapes:i})}this.order=this.order.filter(e=>e!==t),this.removeFromGroup(t)}group(t){if(!(t.length<2)){for(const e of t)this.removeFromGroup(e);this.groups.push([...t])}}ungroup(t){const e=this.groups.findIndex(i=>i.includes(t));e!==-1&&this.groups.splice(e,1)}groupMembers(t){return this.groups.find(e=>e.includes(t))}removeFromGroup(t){const e=this.groups.findIndex(n=>n.includes(t));if(e===-1)return;const i=this.groups[e].filter(n=>n!==t);i.length<2?this.groups.splice(e,1):this.groups[e]=i}bringToFront(t){const e=this.order.indexOf(t);e!==-1&&(this.order.splice(e,1),this.order.push(t))}sendToBack(t){const e=this.order.indexOf(t);e!==-1&&(this.order.splice(e,1),this.order.unshift(t))}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get sourceIds(){return[...this.order]}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes,order:this.order,groups:this.groups}}static fromJSON(t,e){const i=new Ku;for(const n of aa.complete(t.keyframes??[],e))i.addKeyframe(n.t,n.shapes);if(t.order){const n=i.order.filter(s=>!t.order.includes(s));i.order=[...t.order,...n]}return t.groups&&(i.groups=t.groups.map(n=>n.filter(s=>i.order.includes(s))).filter(n=>n.length>=2)),i}}function Ty(a,t,e){return Math.max(t,Math.min(e,a))}function Ry(a,t,e){const i=((t-a)%360+540)%360-180;return((a+i*e)%360+360)%360}function Za(a,t,e){return a+(t-a)*e}function Dy(a,t,e){return{lat:a.lat===void 0||t.lat===void 0?void 0:Za(a.lat,t.lat,e),lng:a.lng===void 0||t.lng===void 0?void 0:Za(a.lng,t.lng,e),elevationM:Za(a.elevationM,t.elevationM,e),headingDeg:a.headingDeg===void 0||t.headingDeg===void 0?void 0:Ry(a.headingDeg,t.headingDeg,e),pitchDeg:Za(a.pitchDeg,t.pitchDeg,e),rollDeg:Za(a.rollDeg??0,t.rollDeg??0,e),fovDeg:Za(a.fovDeg,t.fovDeg,e),fNumber:a.fNumber,focusDistanceM:a.focusDistanceM,filter:a.filter}}class Pa{static at(t,e,i,n,s){const r=t[i],c=t[i+1]-r;if(c<=0)return e[i];const l=Pa.tangent(t,e,i,s),h=Pa.tangent(t,e,i+1,s),u=(n-r)/c,d=u*u,f=d*u;return(2*f-3*d+1)*e[i]+(f-2*d+u)*c*l+(-2*f+3*d)*e[i+1]+(f-d)*c*h}static BRAKE_S=.8;static paced(t,e,i,n){if(!i&&!n)return t;const s=e>0?Math.min(.5,Pa.BRAKE_S/e):.5;if(i&&n){const o=1/(1-s);return t<=s?o*t*t/(2*s):t>=1-s?1-o*(1-t)*(1-t)/(2*s):o*(t-s/2)}const r=o=>{const c=1/(1-s/2);if(o<=1-s)return c*o;const l=o-(1-s);return c*(1-s)+c*(l-l*l/(2*s))};return n?r(t):1-r(1-t)}static tangent(t,e,i,n){const s=t.length-1,r=f=>(e[f+1]-e[f])/(t[f+1]-t[f]||1);if(i===0)return n?0:r(0);if(i===s)return n?0:r(s-1);const o=r(i-1),c=r(i);if(o*c<=0)return 0;const l=t[i]-t[i-1],h=t[i+1]-t[i],u=2*h+l,d=h+2*l;return(u+d)/(u/o+d/c)}}class el{keyframes=[];addKeyframe(t,e){const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,pose:e}:this.keyframes.splice(i,0,{t,pose:e})}clear(){this.keyframes.length=0}removeKeyframeAt(t){const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getLatestPoseAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].pose:void 0}getInterpolatedPoseAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.pose;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];if(!i)return n?.pose;if(!n)return i.pose;const s=Dy(i.pose,n.pose,Ty((t-i.t)/(n.t-i.t),0,1));return this.humanly(e-1,t,s)}humanly(t,e,i){const n=Math.max(0,t-1),s=Math.min(this.keyframes.length-1,t+2),r=this.keyframes.slice(n,s+1),o=t-n,c=r.map(S=>S.t),l=(S,M)=>{const x=r.map(_=>S(_.pose));if(!x.some(_=>_===void 0))return Pa.at(c,x,o,e,M)},h=r.map(S=>S.pose.headingDeg);let u;if(h.every(S=>S!==void 0)){const S=[h[0]];for(let M=1;M<h.length;M++)S.push(S[M-1]+((h[M]-h[M-1])%360+540)%360-180);u=(Pa.at(c,S,o,e,!0)%360+360)%360}const d=this.keyframes[t],f=this.keyframes[t+1],p=(S,M)=>S.lat===M.lat&&S.lng===M.lng&&S.elevationM===M.elevationM,v=!p(d.pose,f.pose),m=v&&t>0&&p(this.keyframes[t-1].pose,d.pose),g=v&&t+2<this.keyframes.length&&p(f.pose,this.keyframes[t+2].pose);let b;if(m||g){const S=Pa.paced((e-d.t)/(f.t-d.t),(f.t-d.t)/1e3,m,g),M=(x,_)=>x===void 0||_===void 0?void 0:x+(_-x)*S;b={lat:M(d.pose.lat,f.pose.lat),lng:M(d.pose.lng,f.pose.lng),elevationM:M(d.pose.elevationM,f.pose.elevationM)}}return{...i,lat:b?b.lat:l(S=>S.lat,!1)??i.lat,lng:b?b.lng:l(S=>S.lng,!1)??i.lng,elevationM:b?b.elevationM:l(S=>S.elevationM,!1)??i.elevationM,headingDeg:u??i.headingDeg,pitchDeg:l(S=>S.pitchDeg,!0)??i.pitchDeg,rollDeg:l(S=>S.rollDeg??0,!0)??i.rollDeg,fovDeg:l(S=>S.fovDeg,!0)??i.fovDeg}}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new el;for(const i of t.keyframes)e.addKeyframe(i.t,i.pose);return e}}class Rr{static MAX_CHANGE_PER_S=.05;points;followed;constructor(t){let e="none",i=0;this.points=t.map(({t:n,weather:s})=>(s.precipitationType!=="none"&&(e=s.precipitationType,i=s.precipitationIntensity),{t:n,lastFalling:e,lastFallingIntensity:i,intensity:s.precipitationType==="none"?0:s.precipitationIntensity,type:s.precipitationType})),this.followed=[];for(let n=0;n<this.points.length;n++){if(n===0){this.followed.push(this.points[0].intensity);continue}const s=this.points[n-1],r=this.points[n];this.followed.push(Rr.follow(this.followed[n-1],s.intensity,r.intensity,(r.t-s.t)/1e3,(r.t-s.t)/1e3))}}at(t){if(this.points.length===0||t<this.points[0].t)return;let e=this.points.length-1;for(;e>0&&this.points[e].t>t;)e--;const i=this.points[e],n=this.points[e+1],s=n?Rr.follow(this.followed[e],i.intensity,n.intensity,(n.t-i.t)/1e3,(t-i.t)/1e3):Rr.follow(this.followed[e],i.intensity,i.intensity,1,(t-i.t)/1e3);return{type:Rr.typeBetween(i,n,t,s),intensity:s,character:Rr.characterBetween(i,n,t)}}static characterBetween(t,e,i){return t.type==="none"?e&&e.type!=="none"?e.intensity:t.lastFallingIntensity:!e||e.type==="none"?t.intensity:t.intensity+(e.intensity-t.intensity)*(i-t.t)/(e.t-t.t||1)}static typeBetween(t,e,i,n){return t.type==="none"?e&&e.type!=="none"&&i>t.t?e.type:n>0?t.lastFalling:"none":e&&e.type==="none"&&n<=0?"none":t.type}static follow(t,e,i,n,s){const r=Rr.MAX_CHANGE_PER_S,o=n>0?(i-e)/n:0,c=u=>e+o*Math.min(Math.max(u,0),n);let l=t,h=0;for(let u=0;u<8&&h<s;u++){const d=c(h)-l;if(Math.abs(d)<1e-9){const S=h<n?o:0;if(Math.abs(S)<=r){const x=h<n?Math.min(s,n):s;l=c(x),h=x;continue}const M=Math.min(s,n);l+=Math.sign(S)*r*(M-h),h=M;continue}const f=Math.sign(d),p=h<n?o:0,v=r-f*p,m=v>0?h+Math.abs(d)/v:1/0,g=h<n?n:1/0,b=Math.min(s,m,g);l+=f*r*(b-h),h=b,b===m&&(l=c(h))}return Math.min(1,Math.max(0,l))}}const Mp=1e3,Iy=.65,Zu={cloudCover:0,cloudDarkness:0,precipitationType:"none",precipitationIntensity:0,windDirectionDeg:0,windSpeed:0,storm:!1};function Qh(a){if(a.cloudLayers!==void 0)return a.cloudLayers;const t=[],e=a.lowerCloudCover??a.cloudCover;return e>0&&t.push({id:"lower",type:"cumulus",baseM:a.cloudBaseM??Mp,thicknessM:650,coverage:e,sizeM:1400,density:1,darkness:a.cloudDarkness}),(a.highCloudCover??0)>0&&t.push({id:"cirrus",type:"cirrus",baseM:8e3,thicknessM:400,coverage:a.highCloudCover,sizeM:2200,density:.35,darkness:a.cloudDarkness,iceCrystalAlignment:a.iceCrystalAlignment}),t}function Je(a,t,e){return a+(t-a)*e}function yp(a,t,e){const i=((t-a)%360+540)%360-180;return((a+i*e)%360+360)%360}function Cy(a,t,e){return Math.max(t,Math.min(e,a))}function Py(a=[],t=[],e){if(!(!a.length&&!t.length))return[...new Set([...a.map(i=>i.id),...t.map(i=>i.id)])].map(i=>{const n=a.find(c=>c.id===i),s=t.find(c=>c.id===i),r=n??{...s,density:0},o=s??{...n,density:0};return{...r,eastM:Je(r.eastM,o.eastM,e),northM:Je(r.northM,o.northM,e),baseM:Je(r.baseM,o.baseM,e),thicknessM:Je(r.thicknessM,o.thicknessM,e),widthM:Je(r.widthM,o.widthM,e),depthM:Je(r.depthM,o.depthM,e),rotationDeg:yp(r.rotationDeg,o.rotationDeg,e),density:Je(r.density,o.density,e),darkness:Je(r.darkness??0,o.darkness??0,e)}})}function Oy(a,t,e){if(a.cloudLayers===void 0&&t.cloudLayers===void 0)return;const i=Qh(a),n=Qh(t);return e>=1?n.map(r=>({...r})):[...new Set([...i.map(r=>r.id),...n.map(r=>r.id)])].map(r=>{const o=i.find(u=>u.id===r),c=n.find(u=>u.id===r),l=o??{...c,coverage:0},h=c??{...o,coverage:0};return{...l,instances:Py(o?.instances,c?.instances,e),baseM:Je(l.baseM,h.baseM,e),thicknessM:Je(l.thicknessM,h.thicknessM,e),coverage:Je(l.coverage,h.coverage,e),sizeM:Je(l.sizeM,h.sizeM,e),density:Je(l.density,h.density,e),darkness:Je(l.darkness??a.cloudDarkness,h.darkness??t.cloudDarkness,e),iceCrystalAlignment:l.iceCrystalAlignment===void 0||h.iceCrystalAlignment===void 0?void 0:Je(l.iceCrystalAlignment,h.iceCrystalAlignment,e),windSpeed:l.windSpeed===void 0&&h.windSpeed===void 0?void 0:Je(l.windSpeed??a.windSpeed,h.windSpeed??t.windSpeed,e),windDirectionDeg:l.windDirectionDeg===void 0&&h.windDirectionDeg===void 0?void 0:yp(l.windDirectionDeg??a.windDirectionDeg,h.windDirectionDeg??t.windDirectionDeg,e)}})}function Ly(a,t,e){return{cloudLayers:Oy(a,t,e),cloudCover:Je(a.cloudCover,t.cloudCover,e),cloudDarkness:Je(a.cloudDarkness,t.cloudDarkness,e),highCloudCover:a.highCloudCover===void 0||t.highCloudCover===void 0?void 0:Je(a.highCloudCover,t.highCloudCover,e),iceCrystalAlignment:a.iceCrystalAlignment===void 0||t.iceCrystalAlignment===void 0?void 0:Je(a.iceCrystalAlignment,t.iceCrystalAlignment,e),lowerCloudCover:a.lowerCloudCover===void 0||t.lowerCloudCover===void 0?void 0:Je(a.lowerCloudCover,t.lowerCloudCover,e),cloudBaseM:a.cloudBaseM===void 0||t.cloudBaseM===void 0?void 0:Je(a.cloudBaseM,t.cloudBaseM,e),relativeHumidity:a.relativeHumidity===void 0||t.relativeHumidity===void 0?void 0:Je(a.relativeHumidity,t.relativeHumidity,e),precipitationType:e<1?a.precipitationType:t.precipitationType,precipitationIntensity:Je(a.precipitationIntensity,t.precipitationIntensity,e),windDirectionDeg:yp(a.windDirectionDeg,t.windDirectionDeg,e),windSpeed:Je(a.windSpeed,t.windSpeed,e),storm:e<1?a.storm:t.storm}}class il{keyframes=[];ramp;addKeyframe(t,e){this.ramp=void 0;const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,weather:e}:this.keyframes.splice(i,0,{t,weather:e})}clear(){this.ramp=void 0,this.keyframes.length=0}removeKeyframeAt(t){this.ramp=void 0;const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}getLatestWeatherAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].weather:void 0}getInterpolatedWeatherAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.weather;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];return i?n?Ly(i.weather,n.weather,Cy((t-i.t)/(n.t-i.t),0,1)):i.weather:n?.weather}getActualWeatherAt(t){const e=this.getInterpolatedWeatherAt(t);if(!e)return;const i=(this.ramp??=new Rr(this.keyframes)).at(t);if(!i)return e;const{type:n,intensity:s,character:r}=i,o=r>0?Math.min(1,s/r):n==="none"?0:1;return{...e,precipitationType:n,precipitationIntensity:r,precipitationAmount:o}}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new il;for(const i of t.keyframes)e.addKeyframe(i.t,{...Zu,...i.weather});return e}}class nl{keyframes=[];addKeyframe(t,e){const i=this.findInsertIndex(t);this.keyframes[i]?.t===t?this.keyframes[i]={t,sound:e}:this.keyframes.splice(i,0,{t,sound:e})}clear(){this.keyframes.length=0}removeKeyframeAt(t){const e=this.findInsertIndex(t);this.keyframes[e]?.t===t&&this.keyframes.splice(e,1)}getLatestSoundAt(t){let e=this.findInsertIndex(t);return this.keyframes[e]?.t!==t&&(e-=1),e>=0?this.keyframes[e].sound:void 0}getInterpolatedSoundAt(t){const e=this.findInsertIndex(t),i=this.keyframes[e]?.t===t?this.keyframes[e]:this.keyframes[e-1];if(i?.t===t)return i.sound;const n=this.keyframes[e]?.t===t?void 0:this.keyframes[e];if(!i)return n?.sound;if(!n)return i.sound;const s=(t-i.t)/(n.t-i.t);return this.lerp(i.sound,n.sound,Math.max(0,Math.min(1,s)))}get duration(){return this.keyframes.length===0?0:this.keyframes[this.keyframes.length-1].t}get allKeyframes(){return this.keyframes}toJSON(){return{keyframes:this.keyframes}}static fromJSON(t){const e=new nl;for(const i of t.keyframes)e.addKeyframe(i.t,i.sound);return e}lerp(t,e,i){return{kind:i<1?t.kind:e.kind,volume:t.volume+(e.volume-t.volume)*i,pitchHz:t.pitchHz+(e.pitchHz-t.pitchHz)*i,src:i<1?t.src:e.src}}findInsertIndex(t){let e=0,i=this.keyframes.length;for(;e<i;){const n=e+i>>>1;this.keyframes[n].t<t?e=n+1:i=n}return e}}const Ny=100,ky={kind:"none",volume:0,pitchHz:Ny},Rl=[{id:"eye",name:"Naked eye",flare:0,projection:"equidistant",stabilization:.97},{id:"rectilinear-lens",name:"Camera, unknown device",projection:"rectilinear",fNumber:8,fNumberRange:{min:2,max:22},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:8},apertureBlades:6},{id:"roamer-1-120",name:"Roamer 1, 120 film",projection:"rectilinear",frame:{widthMm:74,heightMm:60,focalLengthMm:100},fNumber:11,exposureSeconds:1/50,years:{from:1930,to:1965},detailUm:40,medium:{kind:"negative",iso:125}},{id:"instamatic-126",name:"Instamatic, 126 film",projection:"rectilinear",frame:{widthMm:28,heightMm:28,focalLengthMm:43},fNumber:11,exposureSeconds:1/90,years:{from:1963,to:1988},apertureBlades:5,detailUm:20,medium:{kind:"negative",iso:64}},{id:"slr-35mm-50",name:"35 mm SLR, 50 mm lens",projection:"rectilinear",frame:{widthMm:36,heightMm:24,focalLengthMm:50},fNumber:8,fNumberRange:{min:2,max:16},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:3600},years:{from:1959},apertureBlades:6,detailUm:20,medium:{kind:"negative",iso:100}},{id:"slr-35mm-zoom",name:"35 mm SLR, 70-210 mm zoom",projection:"rectilinear",frame:{widthMm:36,heightMm:24,focalLengthMm:135,focalRangeMm:{minMm:70,maxMm:210}},fNumber:8,fNumberRange:{min:4,max:22},exposureSeconds:1/250,exposureRangeSeconds:{min:1/1e3,max:3600},apertureBlades:8,years:{from:1975},detailUm:20,medium:{kind:"negative",iso:100}},{id:"phone-landscape",name:"Phone, held sideways",projection:"rectilinear",frame:{widthMm:7.6,heightMm:5.7,focalLengthMm:5.7},fNumber:1.8,exposureSeconds:1/120,exposureRangeSeconds:{min:1/8e3,max:10},years:{from:2007},apertureBlades:void 0,detailUm:1.4,medium:{kind:"sensor",iso:100,autoExposure:!0}},{id:"phone-portrait",name:"Phone, held upright",projection:"rectilinear",frame:{widthMm:5.7,heightMm:7.6,focalLengthMm:5.7},fNumber:1.8,exposureSeconds:1/120,exposureRangeSeconds:{min:1/8e3,max:10},years:{from:2007},apertureBlades:void 0,detailUm:1.4,medium:{kind:"sensor",iso:100,autoExposure:!0}}];class bi{static get default(){return Rl[0]}static byId(t){return Rl.find(e=>e.id===t)??this.default}static UNAIDED_FIELD_DEG=60;static UNAIDED_ASPECT=16/9;static fieldOfViewDeg(t){const e=t.frame;return e?2*Math.atan(e.heightMm/(2*e.focalLengthMm))*180/Math.PI:bi.UNAIDED_FIELD_DEG}static aspectOf(t){const e=t.frame;return e?e.widthMm/e.heightMm:bi.UNAIDED_ASPECT}static frameWidthPx(t,e){return Math.round(e*bi.aspectOf(t))}static availableAt(t){return t===void 0?Rl:Rl.filter(e=>!e.years||t>=e.years.from&&(e.years.to===void 0||t<=e.years.to))}static fieldOfViewDegAt(t,e){const i=t.frame;if(!(!i||e<=0))return 2*Math.atan(i.heightMm/(2*e))*180/Math.PI}static focalLengthMmFor(t,e){const i=t.frame;if(!(!i||e<=0||e>=180))return i.heightMm/(2*Math.tan(e*Math.PI/360))}static bladesShowing(t,e){const i=e??t.fNumber;if(i===void 0||t.apertureBlades===void 0)return 0;const n=t.fNumberRange;return!n||n.max<=n.min?1:Math.max(0,Math.min(1,(i-n.min)/(n.max-n.min)))}static LENS_FLARE_ARTIFACTS=1;static flareArtifactsOf(t){return t.flare??bi.LENS_FLARE_ARTIFACTS}static starPointsOf(t){const e=t.apertureBlades;return e===void 0||e<3?0:e%2===0?e:e*2}}class za extends Error{}class Ju{constructor(t){this.name=t}validate(t){return!0}}class nM extends Ju{min;max;constructor(t,e,i){super(t),this.min=e,this.max=i}validate(t){if(typeof t!="number")throw new za(`${this.name} value must be a number, but was ${t}`);if(t<this.min||t>this.max)throw new za(`${this.name} value must be >= ${this.min} and <= ${this.max}, but was ${t}`);return super.validate(t)}}class Ai{name;min;max;duration;subUnit;validator;constructor(t,e,i,n,s=new nM(t,e,i)){this.name=t,this.min=e,this.max=i,this.subUnit=n,this.duration=n?(n.max-n.min+1)*n.duration:1,this.validator=s}validate(t){return this.validator.validate(t)}[Symbol.iterator](){let t=this.min;return{next:()=>{const e={done:t>this.max,value:t};return t++,e}}}}class sM{millisecond;second;minute;hour;day;month;year}class Fy extends sM{}class rM extends Fy{millisecond=new Ai("millisecond",0,999,void 0);second=new Ai("second",0,59,this.millisecond);minute=new Ai("minute",0,59,this.second);hour=new Ai("hour",0,23,this.minute);day=new Ai("day",1,31,this.hour);month=new Ai("month",1,12,this.day);year=new Ai("year",0,9999,this.month)}const Kt=new rM;class Uy extends nM{constructor(t=1,e=12){super("month",t,e)}}class Os{static instance=new Os;render(t){return t.value.toString()}}class Ji{unit;#t;constructor(t,e){this.unit=e,this.value=typeof t=="number"?t:t.value}get value(){return this.#t}set value(t){this.unit.validate(t),this.#t=t}get duration(){return this.value*this.unit.duration}#e(t){if(this.constructor.name!==t.constructor.name)throw new Ju(`${this.unit.name} "${this.toString()}" cannot be compared with ${t.unit?.name} "${t.toString()}"`)}compare(t){return this.#e(t),this.value-t.value}isEqual(t){return this.compare(t)===0}isBefore(t){return this.compare(t)<0}isAfter(t){return this.compare(t)>0}previous(t=this.unit){const e=this.value-1;return new this.constructor(e,t)}next(t=this.unit){const e=this.value+1;return new this.constructor(e,t)}toString(t=Os.instance){return t.render(this)}toSpec(){return{value:this.value}}toJSON(){return this.toSpec()}}class He{static#t=new Map;static register(t,e){He.#t.set(t,e)}static get(t){const e=He.#t.get(t);if(!e)throw new za(`No default parser registered for ${t.name}: import "@rr0/time/defaults" or pass a parser to fromString()`);return e()}}class tu extends Ji{constructor(t=new Date().getFullYear(),e=Kt.year){super(t,e)}static fromString(t,e=He.get(tu)){return new tu(e.parse(t))}}class Xs extends Os{static default=new Xs("0",2);constructor(t,e){super(),this.char=t,this.size=e}render(t){return super.render(t).padStart(this.size,this.char)}}class eu extends Ji{constructor(t=new Date().getMonth()+1,e=Kt.month){super(t,e)}static fromString(t,e=He.get(eu)){return new eu(e.parse(t))}toString(t=Xs.default){return super.toString(t)}}class iu extends Ji{constructor(t=new Date().getDate(),e=Kt.day){super(t,e)}static fromString(t,e=He.get(iu)){const i=e.parse(t);return new iu(i)}toString(t=Xs.default){return super.toString(t)}}class nu extends Ji{constructor(t=new Date().getHours(),e=Kt.hour){super(t,e)}static fromString(t,e=He.get(nu)){return new nu(e.parse(t))}toString(t=Xs.default){return super.toString(t)}}class su extends Ji{constructor(t=new Date().getMinutes(),e=Kt.minute){super(t,e)}static fromString(t,e=He.get(su)){return new su(e.parse(t))}toString(t=Xs.default){return super.toString(t)}}class ru extends Ji{constructor(t=new Date().getSeconds(),e=Kt.second){super(t,e)}static fromString(t,e=He.get(ru)){return new ru(e.parse(t),Kt.second)}toString(t=Xs.default){return super.toString(t)}}class Xa extends Ji{static renderer=new Xs("0",3);constructor(t,e=Kt.millisecond){super(t,e)}static parseFraction(t){return parseInt(t.padEnd(3,"0").substring(0,3),10)}toString(t=Xa.renderer){return super.toString(t)}}class zy{render(t){return t.toString()}}class By extends zy{render(t){const e=t.value,i=Math.abs(e),n=Math.floor(i/60),s=i%60;if(n===0&&s===0)return"Z";{const r=e<0?"-":"+",o=n.toString().padStart(2,"0"),c=s>0?":"+s.toString().padEnd(2,"0"):"";return r+o+c}}}class $o{value;name="timeshift";renderer;constructor(t=0){this.value=t}static fromString(t,e=He.get($o),i=void 0){const n=e.parse(t,i);return new $o(n)}toString(t=new By){return t.render(this)}toSpec(){return{value:this.value}}toJSON(){return this.toSpec()}}class $i{static timeshift(t,e){return t+($i.isDaylight(e)?60:0)}static isDaylight(t){const{year:e,month:i,day:n}=t,s=t.hour??12;if(![e,i,n].every(Number.isInteger))throw new RangeError("Daylight saving time depends on the year, month and day");const r=$i.rule(e);if(!r)return!1;const o=$i.rank(i,n,s);return o>=$i.rank(r.start.month,r.start.day,2)&&o<$i.rank(r.end.month,r.end.day,2)}static rule(t){if(t<1967)return;const e={month:10,day:$i.sunday(t,10,-1)};return t>=2007?{start:{month:3,day:$i.sunday(t,3,2)},end:{month:11,day:$i.sunday(t,11,1)}}:t>=1987?{start:{month:4,day:$i.sunday(t,4,1)},end:e}:t===1975?{start:{month:2,day:23},end:e}:t===1974?{start:{month:1,day:6},end:e}:{start:{month:4,day:$i.sunday(t,4,-1)},end:e}}static sunday(t,e,i){const n=new Date(Date.UTC(2e3,e-1,1));n.setUTCFullYear(t);const s=1+(7-n.getUTCDay())%7;if(i>0)return s+7*(i-1);const r=[31,$i.isLeap(t)?29:28,31,30,31,30,31,31,30,31,30,31][e-1];let o=s;for(;o+7<=r;)o+=7;return o}static isLeap(t){return t%4===0&&(t%100!==0||t%400===0)}static rank(t,e,i){return(t*100+e)*100+i}}const Hy={name:"PST",timeshift:"-08",title:"Pacific Standard Time (US)"},Gy={name:"PDT",timeshift:"-07",title:"Pacific Daylight Time (US)"},Vy={name:"MDT",timeshift:"-06",title:"Mountain Standard Time (US)"},Wy={name:"MST",timeshift:"-07",title:"Mountain Daylight Time (US)"},Xy={name:"PT",timeshift:a=>$i.timeshift(-480,a),title:"Pacific Time (US)"},Yy={name:"MT",timeshift:a=>$i.timeshift(-420,a),title:"Mountain Time (US)"},qy={name:"CT",timeshift:a=>$i.timeshift(-360,a),title:"Central Time (US)"},$y={name:"ET",timeshift:a=>$i.timeshift(-300,a),title:"Eastern Time (US)"},Ky={name:"CWT",timeshift:"-05",title:"Central War Time (US)"},Zy={name:"CDT",timeshift:"-05",title:"Central Daylight Time"},Jy={name:"EST",timeshift:"-05",title:"Eastern Standard Time (US)"},jy={name:"EDT",timeshift:"-04",title:"Eastern Time (US)"},Qy={name:"AST",timeshift:"-04",title:"Atlantic Standard Time (US)"},tx={name:"ADT",timeshift:"-03",title:"Atlantic Daylight Time (US)"},ex={name:"UTC",timeshift:"Z",title:"Coordinated Universal Time"},ix={name:"Z",timeshift:"Z",title:"UTC"},nx={name:"GMT",timeshift:"Z",title:"Greenwich Mean Time"},sx={name:"BST",timeshift:"+01",title:"British Summer Time"},rx={name:"CEST",timeshift:"+02",title:"Central European Summer Time"},ax={name:"CET",timeshift:"+01",title:"Central European Time"},ox={name:"MSK",timeshift:"+03",title:"Moscow Time (RU)"},cx={name:"IST",timeshift:"+05:30",title:"Indian Standard Time"},lx={name:"BJT",timeshift:"+08",title:"Beijing Time"},hx={name:"CST",timeshift:"-06",title:"Central Standard Time"},ux={name:"JST",timeshift:"+09",title:"Japan Standard Time"},dx={name:"AEST",timeshift:"+10",title:"Australian Eastern Standard Time"},fx={name:"NZST",timeshift:"+12",title:"New Zealand Standard Time"},px={name:"LST",timeshift:"?",title:"Local Sideral Time"},Am=[tx,dx,Qy,lx,sx,hx,Zy,ax,rx,qy,Ky,jy,Jy,$y,nx,cx,ux,px,Vy,ox,Wy,Yy,fx,Gy,Hy,Xy,ex,ix];class ju{static instance=new ju;renderComponent(t,e){return t[e].toString()}renderSecond(t){return this.renderComponent(t,"second")+(t.millisecond?"."+t.millisecond.toString():"")}render(t){const e=[];t.year&&e.push(this.renderComponent(t,"year")),t.month&&e.push(this.renderComponent(t,"month")),t.day&&e.push(this.renderComponent(t,"day"));const i=[];t.hour&&i.push(this.renderComponent(t,"hour")),t.minute&&i.push(this.renderComponent(t,"minute")),t.second&&i.push(this.renderSecond(t));const n=e.join("-"),s=t.timeshift?t.timeshift.toString():"",r=i.join(":")+s;return n+(r.length>0?"T"+r:"")}}class sa extends za{constructor(t="method is abstract"){super(t)}}class xp{units;constructor(t){this.units=t}newYear(t){throw new sa}newMonth(t){throw new sa}newDay(t){throw new sa}newHour(t){throw new sa}newMinute(t){throw new sa}newSecond(t){throw new sa}}class mx extends sM{millisecond=new Ai("milliseconds",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,void 0);second=new Ai("seconds",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.millisecond);minute=new Ai("minutes",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.second);hour=new Ai("hours",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.minutes);day=new Ai("days",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.hour);month=new Ai("months",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.day);year=new Ai("years",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.month)}const bp=new mx;class Sp{static instance=new Sp;render(t){const e=da.toSpec(t);let i="P";const n=e.years;n&&(i+=n.toString()+"Y");const s=e.months;s&&(i+=s.toString(Os.instance)+"MM");const r=e.days;r&&(i+=r.toString(Os.instance)+"D");const o=e.hours;o&&(i+=o.toString(Os.instance)+"H");const c=e.minutes;c&&(i+=c.toString(Os.instance)+"M");const l=e.seconds;return l&&(i+=l.toString(Os.instance)+"S"),i}}class da extends Ji{constructor(t={years:new Date().getFullYear(),months:new Date().getMonth(),days:new Date().getDate(),hours:new Date().getHours(),minutes:new Date().getMinutes(),seconds:new Date().getSeconds(),milliseconds:new Date().getMilliseconds()}){super({value:typeof t=="number"?t:+(t.years?t.years*Kt.year.duration:0)+(t.months?t.months*Kt.month.duration:0)+(t.days?t.days*Kt.day.duration:0)+(t.hours?t.hours*Kt.hour.duration:0)+(t.minutes?t.minutes*Kt.minute.duration:0)+(t.seconds?t.seconds*Kt.second.duration:0)},new Ai("millisecond",0,Number.MAX_SAFE_INTEGER,void 0))}static toSpec(t,e=vx){let i=typeof t=="number"?t:t.value;const n=i>0?1:-1;i=Math.abs(i);const s={},r=i/Kt.year.duration,o=Math.floor(r);o>0&&(s.years=e.newYear(n*o),i-=o*Kt.year.duration);const c=i/Kt.month.duration,l=Math.floor(c);l>0&&(s.months=e.newMonth(n*l),i-=l*Kt.month.duration);const h=i/Kt.day.duration,u=Math.floor(h);u>0&&(s.days=e.newDay(n*u),i-=u*Kt.day.duration);const d=i/Kt.hour.duration,f=Math.floor(d);f>0&&(s.hours=e.newHour(n*f),i-=f*Kt.hour.duration);const p=i/Kt.minute.duration,v=Math.floor(p);v>0&&(s.minutes=e.newMinute(n*v),i-=v*Kt.minute.duration);const m=i/Kt.second.duration,g=Math.floor(n*m);return g>0&&(s.seconds=e.newSecond(g)),s}static fromString(t,e=He.get(da)){return new da(e.parse(t))}static between(t,e){const i=e.getTime(),n=t.getTime();return new da(i-n)}toSpec(){return da.toSpec(this)}toString(t=Sp.instance){return t.render(this)}}class aM extends xp{constructor(t){super(t)}newYear(t){return new tu(t,this.units.year)}newMonth(t){return new eu(t,this.units.month)}newDay(t){return new iu(t,this.units.day)}newHour(t){return new nu(t,this.units.hour)}newMinute(t){return new su(t,this.units.minute)}newSecond(t){return new ru(t,this.units.second)}newMillisecond(t){return new Xa(t,this.units.millisecond)}newTimeshift(t){return new $o(typeof t=="number"?t:t.value)}}const gx=new aM(Kt),vx=new aM(bp);class rs{#t;#e;#i;#n;#s;#r;#a;#o;constructor(t={year:new Date().getFullYear(),month:new Date().getMonth()+1,day:new Date().getDate(),hour:new Date().getHours(),minute:new Date().getMinutes(),second:new Date().getSeconds(),timeshift:rs.timeshiftOf(new Date)}){this.year=t.year,this.month=t.month,this.day=t.day,this.hour=t.hour,this.minute=t.minute,this.second=t.second,this.millisecond=t.millisecond,this.timeshift=t.timeshift}get year(){return this.#t}set year(t){const e=typeof t=="number";this.#t&&e?this.#t.value=t:this.#t=e?this.factory.newYear(t):!t||t.start||t instanceof Ji?t:this.factory.newYear(t)}get month(){return this.#e}set month(t){const e=typeof t=="number";this.#e&&e?this.#e.value=t:this.#e=e?this.factory.newMonth(t):!t||t.start||t instanceof Ji?t:this.factory.newMonth(t)}get day(){return this.#i}set day(t){const e=typeof t=="number";this.#i&&e?this.#i.value=t:this.#i=e?this.factory.newDay(t):!t||t.start||t instanceof Ji?t:this.factory.newDay(t)}get hour(){return this.#n}set hour(t){const e=typeof t=="number";this.#n&&e?this.#n.value=t:this.#n=e?this.factory.newHour(t):!t||t.start||t instanceof Ji?t:this.factory.newHour(t)}get minute(){return this.#s}set minute(t){const e=typeof t=="number";this.#s&&e?this.#s.value=t:this.#s=e?this.factory.newMinute(t):!t||t.start||t instanceof Ji?t:this.factory.newMinute(t)}get second(){return this.#r}set second(t){const e=typeof t=="number";this.#r&&e?this.#r.value=t:this.#r=e?this.factory.newSecond(t):!t||t.start||t instanceof Ji?t:this.factory.newSecond(t)}get millisecond(){return this.#a}set millisecond(t){const e=typeof t=="number";this.#a&&e?this.#a.value=t:this.#a=e||t&&!(t instanceof Ji)?this.factory.newMillisecond(t):t}get timeshift(){return this.#o}set timeshift(t){const e=typeof t=="number";this.#o&&e?this.#o.value=t:this.#o=e||t&&!(t instanceof $o)?this.factory.newTimeshift(t):t}get factory(){return gx}static fromString(t,e=He.get(rs)){const{year:i,month:n,day:s,hour:r,minute:o,second:c,millisecond:l,timeshift:h}=e.parse(t);return new rs({year:i,month:n,day:s,hour:r,minute:o,second:c,millisecond:l,timeshift:h})}static timeshiftOf(t){return-t.getTimezoneOffset()||0}static fromDate(t){return new rs({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),timeshift:rs.timeshiftOf(t)})}static newInstance(){const t=new Date().toISOString(),e=t.indexOf("."),i=t.substring(0,e)+t.substring(e+4);return rs.fromString(i)}#c(t){if(this.constructor.name!==t.constructor.name)throw new Ju(`Date "${this.toString()}" cannot be compared with "${t.toString()}"`)}compare(t){return this.#c(t),this.getTime()-t.getTime()}delta(t){const e=this.compare(t);return new da(e)}getTime(){return(this.year?.duration||0)+(this.month?.duration||0)+(this.day?.duration||0)+(this.hour?.duration||0)+(this.minute?.duration||0)+(this.second?.duration||0)+(this.millisecond?.duration||0)}isEqual(t){return this.compare(t)===0}isBefore(t){return this.compare(t)<0}isAfter(t){return this.compare(t)>0}clone(){return new rs(this.toSpec())}previous(){let t=this.clone();try{t.second=this.second.previous()}catch{try{t.minute=this.minute.previous()}catch{try{t.hour=this.hour.previous()}catch{try{t.day=this.day.previous()}catch{try{t.month=this.month.previous()}catch{t.year=this.year.previous()}}}}}return t}next(){let t=this.clone();try{t.second=this.second.next()}catch{try{t.minute=this.minute.next()}catch{try{t.hour=this.hour.next()}catch{try{t.day=this.day.next()}catch{try{t.month=this.month.next()}catch{t.year=this.year.next()}}}}}return t}toString(t=ju.instance){return t.render(this)}toSpec(){const t={},e=this.year?.toSpec();e&&(t.year=e);const i=this.month?.toSpec();i&&(t.month=i);const n=this.day?.toSpec();n&&(t.day=n);const s=this.hour?.toSpec();s&&(t.hour=s);const r=this.minute?.toSpec();r&&(t.minute=r);const o=this.second?.toSpec();o&&(t.second=o);const c=this.millisecond?.toSpec();c&&(t.millisecond=c);const l=this.timeshift?.toSpec();return l&&(t.timeshift=l),t}toJSON(){return this.toSpec()}}class yl extends Os{static instance=new yl(Xs.default);constructor(t){super(),this.valueRenderer=t}render(t){return(this.valueRenderer?this.valueRenderer.render(t):super.render(t))+this.qualifier(t)}qualifier(t){return t.uncertain?t.approximate?"%":"?":t.approximate?"~":""}}class Ya extends Ji{#t;#e;constructor(t,e){super(t,e),this.#t=t.uncertain||!1,this.#e=t.approximate||!1}get uncertain(){return this.#t}set uncertain(t){return this.#t=t}get approximate(){return this.#e}set approximate(t){return this.#e=t}isCertainAndPrecise(){return!this.approximate&&!this.uncertain}isEqual(t){return this.isCertainAndPrecise()&&super.isEqual(t)}isBefore(t){return this.isCertainAndPrecise()&&super.isBefore(t)}isAfter(t){return this.isCertainAndPrecise()&&super.isAfter(t)}toString(t=yl.instance){return super.toString(t)}toSpec(){return{...super.toSpec(),uncertain:this.uncertain,approximate:this.approximate}}toJSON(){return this.toSpec()}}class oM extends rM{year=new Ai("year",-9999,9999,this.month);yearExtended=new Ai("year",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.month)}const Fh=new oM;class fa extends Ya{constructor(t,e=Fh.year){super(t,e)}static fromString(t,e=Fh.year,i=He.get(fa)){const n=i.parse(t),s=n.value.start;if(t.startsWith("Y")&&(e=Fh.yearExtended),s!==void 0){const r=new fa(Object.assign({...n},{value:Math.max(s,e.min)})),o=new fa(Object.assign({...n},{value:Math.min(n.value.end,e.max)}));return{start:r,end:o}}else return new fa(n,e)}}class cM extends Ju{monthValidator=new Uy;validate(t){switch(t){case 21:case 22:case 23:case 24:return!0;default:return this.monthValidator.validate(t)}}}class pa extends Ya{constructor(t,e=new Ai(Kt.month.name,1,24,Kt.day,new cM)){super(t,e)}static fromString(t,e=He.get(pa)){const i=e.parse(t),n=i.value.start;if(n!==void 0){let s=Kt.month;const r=new pa(Object.assign({...i},{value:Math.max(n,s.min)})),o=new pa(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new pa(i)}toString(t){return super.toString(t).padStart(2,"0")}}class ma extends Ya{constructor(t,e=Kt.day){super(t,e)}static fromString(t,e=He.get(ma)){const i=e.parse(t),n=i.value.start;if(n!==void 0){let s=Kt.day;const r=new ma(Object.assign({...i},{value:Math.max(n,s.min)})),o=new ma(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new ma(i)}toString(t){return super.toString(t).padStart(2,"0")}}class ga extends Ya{constructor(t,e=Kt.hour){super(t,e)}static fromString(t,e=He.get(ga)){const i=e.parse(t),n=i.value.start;if(n!==void 0){let s=Kt.hour;const r=new ga(Object.assign({...i},{value:Math.max(n,s.min)})),o=new ga(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new ga(i)}}class va extends Ya{constructor(t,e=Kt.minute){super(t,e)}static fromString(t,e=He.get(va)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.minute,r=new va(Object.assign({...i},{value:Math.max(n,s.min)})),o=new va(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new va(i)}toString(t=yl.instance){return super.toString(t)}}class Ma extends Ya{constructor(t,e=Kt.second){super(t,e)}static fromString(t,e=He.get(Ma)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.second,r=new Ma(Object.assign({...i},{value:Math.max(n,s.min)})),o=new Ma(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new Ma(i)}}class Ko extends $o{static fromString(t,e=He.get(Ko),i=void 0){return new Ko(e.parse(t,i))}}class lM extends xp{constructor(t){super(t)}newYear(t){return new fa(t,this.units.year)}newMonth(t){return new pa(t,this.units.month)}newDay(t){return new ma(t,this.units.day)}newHour(t){return new ga(t,this.units.hour)}newMinute(t){return new va(t,this.units.minute)}newSecond(t){return new Ma(t,this.units.second)}newMillisecond(t){return new Xa(t,this.units.millisecond)}newTimeshift(t){return new Ko(typeof t=="number"?t:t.value)}}const Mx=new lM(Fh);new lM(bp);class oa extends rs{constructor(t){super(t)}get factory(){return Mx}get uncertain(){return this.year?.uncertain===!0||this.month?.uncertain===!0||this.day?.uncertain===!0||this.hour?.uncertain===!0||this.minute?.uncertain===!0||this.second?.uncertain===!0}get approximate(){return this.year?.approximate===!0||this.month?.approximate===!0||this.day?.approximate===!0||this.hour?.approximate===!0||this.minute?.approximate===!0||this.second?.approximate===!0}static fromDate(t){return new oa({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),timeshift:rs.timeshiftOf(t)})}static fromString(t,e=He.get(oa)){const i=e.parse(t);return new oa(i)}static newInstance(){const t=new Date().toISOString(),e=t.indexOf("."),i=t.substring(0,e)+t.substring(e+4);return oa.fromString(i)}clone(){return new oa(this.toSpec())}}class sc extends Ya{uncertainComponent;approximateComponent;constructor(t,e){super(t,e),this.uncertainComponent=t.uncertainComponent||!1,this.approximateComponent=t.approximateComponent||!1}get uncertain(){return super.uncertain||this.uncertainComponent}set uncertain(t){return super.uncertain=t}get approximate(){return super.approximate||this.approximateComponent}set approximate(t){return super.approximate=t}get uncertainGroup(){return super.uncertain}get approximateGroup(){return super.approximate}toSpec(){return{...super.toSpec(),uncertain:this.uncertainGroup,approximate:this.approximateGroup,uncertainComponent:this.uncertainComponent,approximateComponent:this.approximateComponent}}toJSON(){return this.toSpec()}}class yx extends oM{year=new Ai("year",Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,this.month)}const Wf=new yx;class ya extends sc{constructor(t,e=Wf.year){super(t,e)}static fromString(t,e=Wf.year,i=He.get(ya)){const n=i.parse(t),s=n.value.start;if(s!==void 0){const r=new ya(Object.assign({...n},{value:Math.max(s,e.min)})),o=new ya(Object.assign({...n},{value:Math.min(n.value.end,e.max)})),c={start:r,end:o},l=n.value.estimate;return l&&(c.estimate=l),c}else return new ya(n)}}class xx extends cM{validate(t){switch(t){case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 41:return!0;default:return super.validate(t)}}}class xa extends sc{constructor(t,e=new Ai(Kt.month.name,1,41,Kt.day,new xx)){super(t,e)}static fromString(t,e=He.get(xa)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.month,r=new xa(Object.assign({...i},{value:Math.max(n,s.min)})),o=new xa(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new xa(i)}toString(t){return super.toString(t).padStart(2,"0")}}class ba extends sc{constructor(t,e=Kt.day){super(t,e)}static fromString(t,e=He.get(ba)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.day,r=new ba(Object.assign({...i},{value:Math.max(n,s.min)})),o=new ba(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new ba(i)}toString(t){return super.toString(t).padStart(2,"0")}}class Sa extends sc{constructor(t,e=Kt.hour){super(t,e)}static fromString(t,e=He.get(Sa)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.hour,r=new Sa(Object.assign({...i},{value:Math.max(n,s.min)})),o=new Sa(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new Sa(i)}}class wa extends sc{constructor(t,e=Kt.minute){super(t,e)}static fromString(t,e=He.get(wa)){const i=e.parse(t),n=i.value.start;if(n!==void 0){const s=Kt.minute,r=new wa(Object.assign({...i},{value:Math.max(n,s.min)})),o=new wa(Object.assign({...i},{value:Math.min(i.value.end,s.max)}));return{start:r,end:o}}else return new wa(i)}}class _a extends sc{constructor(t,e=Kt.second){super(t,e)}static fromString(t,e=Kt.second,i=He.get(_a)){const n=i.parse(t),s=n.value.start;if(s!==void 0){const r=new _a(Object.assign({...n},{value:Math.max(s,e.min)})),o=new _a(Object.assign({...n},{value:Math.min(n.value.end,e.max)}));return{start:r,end:o}}else return new _a(n,e)}}class hM extends Ko{}class bx extends yl{qualifier(){return""}}class Dr extends ju{static instance=new Dr;static valueRenderer=new bx(Xs.default);static names=["year","month","day","hour","minute","second"];static qualifier(t,e){return t?e?"%":"?":e?"~":""}renderComponent(t,e){const i=t[e],n=Dr.names.slice(Dr.names.indexOf(e)+1).map(o=>t[o]).filter(Boolean),s=Dr.qualifier(i.uncertainComponent,i.approximateComponent),r=Dr.qualifier(i.uncertainGroup&&!i.uncertainComponent&&!n.some(o=>o.uncertain),i.approximateGroup&&!i.approximateComponent&&!n.some(o=>o.approximate));return s+i.toString(Dr.valueRenderer)+r}}class uM extends xp{constructor(t){super(t)}newYear(t){return new ya(t,this.units.year)}newMonth(t){return new xa(t,this.units.month)}newDay(t){return new ba(t,this.units.day)}newHour(t){return new Sa(t,this.units.hour)}newMinute(t){return new wa(t,this.units.minute)}newSecond(t){return new _a(t,this.units.second)}newMillisecond(t){return new Xa(t,this.units.millisecond)}newTimeshift(t){return new hM(typeof t=="number"?t:t.value)}}const Sx=new uM(Wf);new uM(bp);class ca extends oa{constructor(t){super(t)}toString(t=Dr.instance){return super.toString(t)}get year(){return super.year}set year(t){super.year=t}get month(){return super.month}set month(t){super.month=t}get factory(){return Sx}static fromDate(t){return new ca({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),timeshift:rs.timeshiftOf(t)})}static fromString(t,e=He.get(ca)){const i=e.parse(t);return new ca(i)}static newInstance(){const t=new Date().toISOString(),e=t.indexOf("."),i=t.substring(0,e)+t.substring(e+4);return ca.fromString(i)}clone(){return new ca(this.toSpec())}}class Qu{regExp;constructor(t,e){this.name=t,this.regExp=new RegExp(`^(?:${e})$`)}regexGroups(t){const e=this.regExp.exec(t);if(!e)throw new za(`Invalid ${this.name} "${t}"`);return e.groups}parseGroups(t){throw new sa(`${this.constructor.name} is abstract`)}parse(t){const e=this.regexGroups(t);return this.parseGroups(e)}}class wp extends Qu{constructor(t,e){super(t,e)}static read(t){return{value:t?parseInt(t,10):void 0}}parseGroups(t){return wp.read(t[this.name])}parse(t){if(t.startsWith("-"))throw new za(`${this.name} cannot be negative`);return super.parse(t)}}class at{static groupName(...t){return t.reduce((e,i)=>e?e+i.charAt(0).toUpperCase()+i.substring(1):i,"")}static group(t,...e){return`(?<${t}>${e.join("")})`}static optional(t){return t+"?"}static nonCapturingGroup(...t){return`(?:${t.join("")})`}static optionalGroup(t,...e){return at.optional(at.group(t,...e))}static optionalNonCapturingGroup(...t){return at.optional(at.nonCapturingGroup(...t))}static numberGroup(t,e,i,n="\\d"){return at.group(t,`${i||""}[${n}]${e}`)}}const Tm="timeshiftValue",Rm="shiftHour",Dm="shiftMinute";class _p extends Qu{static format(t=""){return Am.map(e=>e.name).join("|")+"|"+at.nonCapturingGroup(at.group(t+Rm,at.numberGroup(at.groupName(t,Tm),"{2}","[+-]")),at.optionalNonCapturingGroup(":?",at.numberGroup(at.groupName(t,Dm),"{2}",void 0)))}constructor(){super(Tm,_p.format())}parse(t,e){let i=0;const n=Am.find(s=>s.name===t);if(n){if(typeof n.timeshift=="function")try{return n.timeshift(e??{})}catch(s){throw new za(`The time zone ${t} depends on the date: ${s.message}`)}t=n.timeshift}if(t!=="Z"){const s=this.regexGroups(t),r=s[Rm];r&&(i+=parseInt(r,10)*60);const o=s[Dm];o&&(i+=parseInt(o,10))}return i}}class ai extends wp{static uncertainGroup="uncertain";static approximateGroup="approx";static uncertainAndApproximateGroup=ai.uncertainGroup+ai.approximateGroup;constructor(t,e){super(t,e)}static qualifierFormat(t,e){return at.optionalGroup(t,`\\${e}`)}static formatSuffix(t){return this.qualifierFormat(at.groupName(ai.uncertainGroup,t),"?")+this.qualifierFormat(at.groupName(ai.approximateGroup,t),"~")+this.qualifierFormat(at.groupName(ai.uncertainAndApproximateGroup,t),"%")}static numberFormat(t,e,i){return at.numberGroup(t,e,i,"\\dX")+this.formatSuffix(t)}getValueAndSign(t){let e=t[this.name],i;return e.charAt(0)==="-"?(i=-1,e=e.substring(1)):i=1,{valueStr:e,sign:i}}parseGroups(t){const{valueStr:e,sign:i}=this.getValueAndSign(t);let n=0,s;for(s=0;s<e.length;s++){const l=e[s];if(l==="X")break;n=n*10+parseInt(l,10)}if(s<e.length){let l=1;for(let d=0;d<e.length-s;d++)l*=10;const h=i*n*l,u=h+l-1;n={start:h,end:u}}else n*=i;const r=t[at.groupName(ai.uncertainAndApproximateGroup,this.name)],o=t[at.groupName(ai.approximateGroup,this.name)]||r,c=t[at.groupName(ai.uncertainGroup,this.name)]||r;return{value:n,approximate:o?!!o:!1,uncertain:c?!!c:!1}}}const Im="yearValue";class au extends ai{constructor(){super(Im,au.format())}static format(t=""){return"Y?"+ai.numberFormat(at.groupName(t,Im),"+","[-]?")}parse(t){const e=this.regexGroups(t);return this.parseGroups(e)}}const Cm="monthValue";class ou extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Cm),"{1,2}",void 0)}constructor(){super(Cm,ou.format())}}const Pm="dayValue";class cu extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Pm),"{1,2}",void 0)}constructor(){super(Pm,cu.format())}}const Om="hourValue";class lu extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Om),"{1,2}",void 0)}constructor(){super(Om,lu.format())}}const Lm="minuteValue";class hu extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Lm),"{1,2}",void 0)}constructor(){super(Lm,hu.format())}}const Nm="secondValue";class uu extends ai{static format(t=""){return ai.numberFormat(at.groupName(t,Nm),"{1,2}",void 0)}constructor(){super(Nm,uu.format())}}class du extends _p{}class Di extends Qu{static yearGroup="year";static monthGroup="month";static dayGroup="day";static hourGroup="hour";static minuteGroup="minute";static secondGroup="second";static millisecondGroup="millisecond";static timeshiftGroup="timeshift";constructor(t=Di.format()){super("date",t)}static format(t=""){return at.group(at.groupName(t,Di.yearGroup),au.format(t))+at.optionalNonCapturingGroup("-",at.group(at.groupName(t,Di.monthGroup),ou.format(t)),at.optionalNonCapturingGroup("-",at.group(at.groupName(t,Di.dayGroup),cu.format(t)),at.optionalNonCapturingGroup("[T ]",at.group(at.groupName(t,Di.hourGroup),lu.format(t)),":",at.group(at.groupName(t,Di.minuteGroup),hu.format(t)),at.optionalNonCapturingGroup(":",at.group(at.groupName(t,Di.secondGroup),uu.format(t)),at.optionalNonCapturingGroup("[.,]",at.group(at.groupName(t,Di.millisecondGroup),"\\d+"))),at.optionalGroup(at.groupName(t,Di.timeshiftGroup),du.format(t)))))}parseGroups(t){const e=t[Di.millisecondGroup],i=e?Xa.parseFraction(e):void 0,n=t[Di.secondGroup],s=n?Ma.fromString(n,new uu):void 0,r=t[Di.minuteGroup];let o;r&&(o=va.fromString(r,new hu),o.uncertain=o.uncertain||s?.uncertain||!1,o.approximate=o.approximate||s?.approximate||!1);const c=t[Di.hourGroup];let l;c&&(l=ga.fromString(c,new lu),l.uncertain=l.uncertain||o?.uncertain||!1,l.approximate=l.approximate||o?.approximate||!1);const h=t[Di.dayGroup];let u;h&&(u=ma.fromString(h,new cu),u.uncertain=u.uncertain||l?.uncertain||!1,u.approximate=u.approximate||l?.approximate||!1);const d=t[Di.monthGroup];let f;d&&(f=pa.fromString(d,new ou),f.uncertain=f.uncertain||u?.uncertain||!1,f.approximate=f.approximate||u?.approximate||!1);const p=t[Di.yearGroup];let v;p&&(v=fa.fromString(p,void 0,new au),v.uncertain=v.uncertain||f?.uncertain||!1,v.approximate=v.approximate||f?.approximate||!1);const m=t[Di.timeshiftGroup],g=m?Ko.fromString(m,new du,{year:v?.value,month:f?.value,day:u?.value,hour:l?.value}):void 0;return{year:v,month:f,day:u,hour:l,minute:o,second:s,millisecond:i,timeshift:g}}}class xi extends ai{static uncertainGroup="uncertain1";static approximateGroup="approx1";static uncertainAndApproximateGroup=xi.uncertainGroup+xi.approximateGroup;constructor(t,e){super(t,e)}static numberFormat(t,e,i){return this.qualifierFormat(at.groupName(xi.uncertainGroup,t),"?")+this.qualifierFormat(at.groupName(xi.approximateGroup,t),"~")+this.qualifierFormat(at.groupName(xi.uncertainAndApproximateGroup,t),"%")+ai.numberFormat(t,e,i)}parseGroups(t){const e=super.parseGroups(t),i=t[at.groupName(xi.uncertainAndApproximateGroup,this.name)];return(t[at.groupName(xi.uncertainGroup,this.name)]||i)&&(e.uncertainComponent=!0),(t[at.groupName(xi.approximateGroup,this.name)]||i)&&(e.approximateComponent=!0),e}}const lc="yearValue",km="exp",Fm="signif";class fu extends xi{constructor(){super(lc,fu.format())}static format(t=""){return"Y?"+at.nonCapturingGroup(at.group(at.groupName(t,km),"[-]?\\d+E\\d+")+"|"+xi.numberFormat(at.groupName(t,lc),"+","[-]?")+at.optionalGroup(at.groupName(t,Fm),"S\\d+"))}parseGroups(t){const e=t[km];if(e){const r=e.indexOf("E"),o=parseInt(e.substring(r+1),10),l=parseInt(e.substring(0,r),10)*Math.pow(10,o);t[lc]=l.toString()}const i=t[Fm],n=t[lc];if(i){const r=parseInt(i.substring(1),10),{valueStr:o,sign:c}=this.getValueAndSign(t);let l="";for(let h=0;h<o.length;h++)l+=h<r?o.charAt(h):"X";t[lc]=(c<0?"-":"")+l}const s=super.parseGroups(t);return i&&(s.value.estimate=parseInt(n,10)),s}parse(t){const e=this.regexGroups(t);return this.parseGroups(e)}}const Um="monthValue";class pu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,Um),"{1,2}",void 0)}constructor(){super(Um,pu.format())}}const zm="dayValue";class mu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,zm),"{1,2}",void 0)}constructor(){super(zm,mu.format())}}const Bm="hourValue";class gu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,Bm),"{1,2}",void 0)}constructor(){super(Bm,gu.format())}}const Hm="secondValue";class vu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,Hm),"{1,2}",void 0)}constructor(){super(Hm,vu.format())}}const Gm="minuteValue";class Mu extends xi{static format(t=""){return xi.numberFormat(at.groupName(t,Gm),"{1,2}",void 0)}constructor(){super(Gm,Mu.format())}}class wx extends du{}class Ii extends Qu{static yearGroup=Di.yearGroup;static monthGroup="month";static dayGroup="day";static hourGroup="hour";static minuteGroup="minute";static secondGroup="second";static millisecondGroup="millisecond";static timeshiftGroup="timeshift";constructor(){super("date",Ii.format())}static format(t=""){return at.group(at.groupName(t,Ii.yearGroup),fu.format(t))+at.optionalNonCapturingGroup("-",at.group(at.groupName(t,Ii.monthGroup),pu.format(t)),at.optionalNonCapturingGroup("-",at.group(at.groupName(t,Ii.dayGroup),mu.format(t)),at.optionalNonCapturingGroup("[T ]",at.group(at.groupName(t,Ii.hourGroup),gu.format(t)),":",at.group(at.groupName(t,Ii.minuteGroup),Mu.format(t)),at.optionalNonCapturingGroup(":",at.group(at.groupName(t,Ii.secondGroup),vu.format(t)),at.optionalNonCapturingGroup("[.,]",at.group(at.groupName(t,Ii.millisecondGroup),"\\d+"))),at.optionalGroup(at.groupName(t,Ii.timeshiftGroup),wx.format(t)))))}parseGroups(t){const e=t[Ii.millisecondGroup],i=e?Xa.parseFraction(e):void 0,n=t[Ii.secondGroup];let s;n&&(s=_a.fromString(n,void 0,new vu),s.uncertain=s?.uncertain||!1,s.approximate=s?.approximate||!1);const r=t[Ii.minuteGroup];let o;r&&(o=wa.fromString(r,new Mu),o.uncertain=o.uncertain||s?.uncertain||!1,o.approximate=o.approximate||s?.approximate||!1);const c=t[Ii.hourGroup];let l;c&&(l=Sa.fromString(c,new gu),l.uncertain=l.uncertain||o?.uncertain||!1,l.approximate=l.approximate||o?.approximate||!1);const h=t[Ii.dayGroup];let u;h&&(u=ba.fromString(h,new mu),u.uncertain=u.uncertain||l?.uncertain||!1,u.approximate=u.approximate||l?.approximate||!1);const d=t[Ii.monthGroup];let f;d&&(f=xa.fromString(d,new pu),f.uncertain=f.uncertain||u?.uncertain||!1,f.approximate=f.approximate||u?.approximate||!1);const p=t[Ii.yearGroup];let v;p&&(v=ya.fromString(p,void 0,new fu),v.uncertain=v.uncertain||f?.uncertain||!1,v.approximate=v.approximate||f?.approximate||!1);const m=t[Ii.timeshiftGroup],g=m?hM.fromString(m,new du,{year:v?.value,month:f?.value,day:u?.value,hour:l?.value}):void 0;return{year:v,month:f,day:u,hour:l,minute:o,second:s,millisecond:i,timeshift:g}}}const dM=["spring","summer","autumn","winter"],Xf=21,_x=32,Ex=/^(?<hour>[01]?\d|2[0-3]):(?<minute>[0-5]\d)(?::(?<second>[0-5]\d))?[?~%]?$/;let Ax;function Tx(){return Ax??=new Ii}function Ja(a){return typeof a?.value=="number"?a.value:void 0}function vd(a){const t=a.trim();if(/^\d{1,2}:/.test(t)){const r=Ex.exec(t)?.groups;return r?{year:void 0,month:void 0,day:void 0,hour:Number(r.hour),minute:Number(r.minute),second:r.second?Number(r.second):void 0,raw:t}:void 0}let e;try{e=ca.fromString(t,Tx())}catch{return}const i=Ja(e.year),n=Ja(e.month),s=n!==void 0&&n>=Xf&&n<=_x;if(!(e.timeshift||i!==void 0&&Math.abs(i)>9999)&&!(n!==void 0&&n>12&&!s)&&!(s&&(e.day||e.hour)))return{year:i,month:s?void 0:n,...s?{season:dM[(n-Xf)%4]}:{},day:Ja(e.day),hour:Ja(e.hour),minute:Ja(e.minute),second:Ja(e.second),raw:t}}function Uh(a){if(a.raw!==void 0)return a.raw;if(a.year===void 0){if(a.hour===void 0)return"";let e=`${String(a.hour).padStart(2,"0")}:${String(a.minute??0).padStart(2,"0")}`;return a.second!==void 0&&(e+=`:${String(a.second).padStart(2,"0")}`),e}let t=String(a.year).padStart(4,"0");return a.season!==void 0?`${t}-${Xf+dM.indexOf(a.season)}`:(a.month===void 0||(t+=`-${String(a.month).padStart(2,"0")}`,a.day===void 0)||(t+=`-${String(a.day).padStart(2,"0")}`,a.hour===void 0)||(t+=`T${String(a.hour).padStart(2,"0")}:${String(a.minute??0).padStart(2,"0")}`,a.second!==void 0&&(t+=`:${String(a.second).padStart(2,"0")}`)),t)}function Yf(a){if(a.year!==void 0)return Date.UTC(a.year,(a.month??1)-1,a.day??1,a.hour??0,a.minute??0,a.second??0)}function Vm(a){return(((a.day??0)*24+(a.hour??0))*60+(a.minute??0))*6e4+(a.second??0)*1e3}const Rx=["year","month","day","hour","minute"],Dx=["day","hour","minute"];function Wm(a,t){return t.filter(e=>a[e]!==void 0).join(",")}function fM(a){if(a.durationSeconds!==void 0)return a.durationSeconds*1e3;const t=a.durationText===void 0?void 0:Vc.parse(a.durationText);if(t)return t.chosenSeconds*1e3;if(!a.time||!a.endTime)return;const e=a.time.year!==void 0&&a.endTime.year!==void 0,i=e?Rx:Dx,n=Wm(a.time,i);if(!(n===""||n!==Wm(a.endTime,i)))return e?Yf(a.endTime)-Yf(a.time):Vm(a.endTime)-Vm(a.time)}class td{constructor(t,e,i,n,s,r,o,c,l=[],h,u,d,f=[],p=[],v=[],m=[]){this.event=t,this.timeline=e,this.observerTrack=i,this.weatherTrack=n,this.soundTrack=s,this.observer=r,this.id=o,this.weather=c,this.decor=l,this.weatherSource=h,this.instrumentId=u,this.exposureSeconds=d,this.milestones=f,this.references=p,this.roads=v,this.traces=m}provenance=hn.empty();loadIssues=[];account;sources;interpretation;sway;lightPollution;observerMap;iso;vehicle;get observerCount(){return 1+this.decor.filter(t=>t.kind==="observer").length}get exposure(){return this.exposureSeconds??this.instrument.exposureSeconds}get instrument(){return bi.byId(this.instrumentId)}static create(t,e,i){return new td({eventType:"sighting",time:t,place:e},new Ku,new el,new il,new nl,i)}}const Ix=0,Cx=0;function Ze(a,t){const e=a.observerTrack.getInterpolatedPoseAt(t);if(e)return e;const i=a.event.place?.[0];if(i)return{lat:i.lat,lng:i.lng,elevationM:Ix,headingDeg:void 0,pitchDeg:Cx,fovDeg:bi.fieldOfViewDeg(a.instrument)}}function Eo(a,t){return a.weatherTrack.getInterpolatedWeatherAt(t)??a.weather??Zu}function Dl(a,t){return a.weatherTrack.getActualWeatherAt(t)??a.weather??Zu}function pM(a,t){return a.soundTrack.getInterpolatedSoundAt(t)??ky}class er{constructor(t,e,i,n="en"){this.parts=t,this.messages=e,this.onChange=i,this.locale=n,this.setMessages(e),t.text.addEventListener("input",()=>{this.readText(),this.showDeduction()}),t.picker.addEventListener("change",()=>this.writeFromPicker()),t.mode.addEventListener("click",()=>this.setPrecise(!this.precise)),t.text.addEventListener("blur",()=>this.validate()),t.text.addEventListener("focus",()=>this.showDeduction())}precise=!0;hint="";get isPrecise(){return this.precise}setMessages(t,e=this.locale){this.messages=t,this.locale=e,t.edtfPlaceholder!==void 0&&(this.parts.text.placeholder=t.edtfPlaceholder),this.parts.mode.title=t.edtfModeTitle,this.parts.mode.setAttribute("aria-label",t.edtfModeTitle),this.setPrecise(this.precise)}setPrecise(t){this.precise=t,this.parts.picker.hidden=!t,this.parts.text.hidden=t,this.parts.mode.textContent=t?this.messages.datePrecise:this.messages.dateEdtf,this.parts.mode.setAttribute("aria-pressed",String(!t)),this.parts.help&&(this.parts.help.hidden=t),this.showDeduction()}set(t){const{text:e,picker:i}=this.parts;e.value=t?Uh(t):"",i.step=er.stepFor(t),i.value=er.pickerValueOf(t),e.setCustomValidity(""),e.classList.remove("invalid"),this.showDeduction()}static opensPrecise(...t){return t.every(e=>e===void 0||er.isPickable(e)&&er.qualifierOf(Uh(e))==="")}static isPickable(t){return!!t&&t.year!==void 0&&t.month!==void 0&&t.day!==void 0&&t.hour!==void 0&&t.minute!==void 0}static pickerValueOf(t){if(!er.isPickable(t))return"";const e=(n,s=2)=>String(n).padStart(s,"0"),i=t.second?`:${e(t.second)}`:"";return`${e(t.year,4)}-${e(t.month)}-${e(t.day)}T${e(t.hour)}:${e(t.minute)}${i}`}static stepFor(t){return t?.second?"1":"60"}static qualifierOf(t){const e=/[?%]/.test(t),i=/[~%]/.test(t);return e&&i?"%":e?"?":i?"~":""}describe(t){return er.describeTime(t,this.messages,this.locale)}static describeTime(t,e,i){const n=Uh(t),s=er.qualifierOf(n),r=h=>String(h).padStart(2,"0"),o=[];if(t.season!==void 0){const h={spring:e.timeSeasonSpring,summer:e.timeSeasonSummer,autumn:e.timeSeasonAutumn,winter:e.timeSeasonWinter}[t.season];o.push(t.year!==void 0?`${h} ${t.year}`:h)}else if(t.year!==void 0){const h=t.day!==void 0?{...t.year>=1583?{weekday:"long"}:{},year:"numeric",month:"long",day:"numeric"}:t.month!==void 0?{year:"numeric",month:"long"}:{year:"numeric"},u=new Date(Date.UTC(t.year,(t.month??1)-1,t.day??1));o.push(new Intl.DateTimeFormat(i,{...h,timeZone:"UTC"}).format(u))}t.hour!==void 0&&o.push(`${r(t.hour)}:${r(t.minute??0)}${t.second!==void 0?`:${r(t.second)}`:""}`);const c=o.join(", "),l=s==="~"?e.timeQualifierApproximate:s==="?"?e.timeQualifierUncertain:s==="%"?e.timeQualifierBoth:"";return l?`${c} — ${l.toLowerCase()}`:c}setHint(t){this.hint=t,this.showDeduction()}showDeduction(){const{text:t}=this.parts,e=t.value.trim();if(this.precise||e===""){t.title=this.hint;return}const i=vd(e);t.title=i?`→ ${this.describe(i)}`:this.messages.edtfInvalid}readText(){const t=this.parts.text.value.trim();if(t===""){this.clean(),this.onChange(void 0);return}const e=vd(t);e&&(this.clean(),this.onChange(e))}clean(){this.parts.text.setCustomValidity(""),this.parts.text.classList.remove("invalid")}writeFromPicker(){const{picker:t,text:e}=this.parts;t.value===""&&t.validity.badInput||(e.value=t.value===""?"":t.value.replace(/\.\d+$/,""),this.readText())}validate(){const{text:t}=this.parts,e=t.value.trim();e===""||vd(e)||(t.setCustomValidity(this.messages.edtfInvalid),t.classList.add("invalid"))}}const Xm=2;function mM(a){return a==="building"||a==="vehicle"}const gM={aircraft:{id:"poly-google-airliner"}};function qf(a){return a.model??gM[a.kind]}function vM(a,t){const e=a.litKeyframes;if(!e||e.length===0)return a.lit??!1;let i=e[0];for(const n of e){if(n.t>t)break;i=n}return i.lit}function Ym(a,t){const e=a.observerKeyframes;if(!e||e.length===0)return{side:a.observerSide,facing:a.observerFacing};let i=e[0];for(const n of e){if(n.t>t)break;i=n}return{side:i.side,facing:i.facing}}function Px(a,t){return a.pattern.kind==="steady"?!0:MM(a,t,t+1)>.5}function MM(a,t,e){if(a.pattern.kind==="steady")return 1;const{perMinute:i,dutyCycle:n,phase:s=0}=a.pattern,r=Math.min(Math.max(n,0),1);if(r===0||i<=0)return 0;const o=6e4/i,c=t/o+s,l=e/o+s;if(l<=c)return Math.min(Math.max(c-Math.floor(c),0),r)<r?1:0;const h=u=>Math.floor(u)*r+Math.min(u-Math.floor(u),r);return(h(l)-h(c))/(l-c)}function Hr(a,t){const e=a.track,i={eastM:a.eastM,northM:a.northM,altitudeM:0,headingDeg:a.headingDeg};if(!e||e.length===0)return i;if(e.length===1||t<=e[0].t)return qm(e[0],a);const n=e[e.length-1];if(t>=n.t)return qm(n,a);for(let s=0;s<e.length-1;s++){const r=e[s],o=e[s+1];if(t<r.t||t>o.t)continue;const c=o.t-r.t,l=c===0?0:(t-r.t)/c;return{eastM:r.eastM+(o.eastM-r.eastM)*l,northM:r.northM+(o.northM-r.northM)*l,altitudeM:(r.altitudeM??0)+((o.altitudeM??0)-(r.altitudeM??0))*l,headingDeg:r.headingDeg??a.headingDeg}}return i}function qm(a,t){return{eastM:a.eastM,northM:a.northM,altitudeM:a.altitudeM??0,headingDeg:a.headingDeg??t.headingDeg}}const $m="#ff2200",Km="#00ff44",Zr="#ffffff",Il="#ffa500",ja="#ff0000",Ox="#2244ff",Lx=[{id:"airliner",name:"Airliner",kinds:["aircraft"],create:()=>[{id:"nav-port",offsetM:{x:-17,y:0,z:0},color:$m,pattern:{kind:"steady"}},{id:"nav-starboard",offsetM:{x:17,y:0,z:0},color:Km,pattern:{kind:"steady"}},{id:"nav-tail",offsetM:{x:0,y:1,z:-18},color:Zr,pattern:{kind:"steady"}},{id:"beacon-top",offsetM:{x:0,y:2,z:0},color:ja,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.18}},{id:"beacon-bottom",offsetM:{x:0,y:-2,z:0},color:ja,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.18}},{id:"strobe-port",offsetM:{x:-17,y:0,z:-1},color:Zr,intensity:20,pattern:{kind:"flash",perMinute:60,dutyCycle:.01}},{id:"strobe-starboard",offsetM:{x:17,y:0,z:-1},color:Zr,intensity:20,pattern:{kind:"flash",perMinute:60,dutyCycle:.01,phase:.08}}]},{id:"helicopter",name:"Helicopter",kinds:["aircraft"],create:()=>[{id:"nav-port",offsetM:{x:-5,y:0,z:0},color:$m,pattern:{kind:"steady"}},{id:"nav-starboard",offsetM:{x:5,y:0,z:0},color:Km,pattern:{kind:"steady"}},{id:"nav-tail",offsetM:{x:0,y:1,z:-7},color:Zr,pattern:{kind:"steady"}},{id:"beacon",offsetM:{x:0,y:2,z:-2},color:ja,intensity:1.5,pattern:{kind:"flash",perMinute:45,dutyCycle:.2}},{id:"strobe",offsetM:{x:0,y:-1,z:0},color:Zr,intensity:15,pattern:{kind:"flash",perMinute:75,dutyCycle:.015}}]},{id:"car-headlights",name:"Car, headlights on",kinds:["vehicle"],create:()=>[{id:"head-left",offsetM:{x:-.7,y:.6,z:2},color:Zr,intensity:2,pattern:{kind:"steady"}},{id:"head-right",offsetM:{x:.7,y:.6,z:2},color:Zr,intensity:2,pattern:{kind:"steady"}},{id:"tail-left",offsetM:{x:-.7,y:.6,z:-2},color:ja,pattern:{kind:"steady"}},{id:"tail-right",offsetM:{x:.7,y:.6,z:-2},color:ja,pattern:{kind:"steady"}}]},{id:"car-hazards",name:"Car, hazard flashers",kinds:["vehicle"],create:()=>[{id:"hazard-front-left",offsetM:{x:-.8,y:.6,z:2},color:Il,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-front-right",offsetM:{x:.8,y:.6,z:2},color:Il,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-rear-left",offsetM:{x:-.8,y:.6,z:-2},color:Il,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}},{id:"hazard-rear-right",offsetM:{x:.8,y:.6,z:-2},color:Il,pattern:{kind:"flash",perMinute:90,dutyCycle:.5}}]},{id:"emergency-beacons",name:"Emergency vehicle beacons",kinds:["vehicle"],create:()=>[{id:"beacon-blue",offsetM:{x:-.4,y:1.6,z:0},color:Ox,intensity:2.5,pattern:{kind:"flash",perMinute:120,dutyCycle:.1}},{id:"beacon-red",offsetM:{x:.4,y:1.6,z:0},color:ja,intensity:2.5,pattern:{kind:"flash",perMinute:120,dutyCycle:.1,phase:.5}}]},{id:"streetlamp",name:"Streetlamp",kinds:["streetlight"],create:()=>[{id:"lamp",offsetM:{x:0,y:5,z:0},color:"#ffd9a0",intensity:2,pattern:{kind:"steady"}}]}];class ls{static NONE={id:"none",name:"No filter",opticalDensity:0};static SOLAR_VISUAL={id:"solar-visual",name:"Solar filter for the eye (OD 5)",opticalDensity:5};static SOLAR_PHOTO={id:"solar-photo",name:"Solar film for a camera (OD 3.8)",opticalDensity:3.8};static ALL=[ls.NONE,ls.SOLAR_VISUAL,ls.SOLAR_PHOTO];static byId(t){return ls.ALL.find(e=>e.id===t)??ls.NONE}static transmittance(t){return 10**-t.opticalDensity}static magnitudes(t){return 2.5*t.opticalDensity}}class zh{constructor(t){this.names=t}name(t){return this.names[t.toLowerCase()]??t}stored(t){const e=t.trim().toLowerCase();for(const[i,n]of Object.entries(this.names))if(n.toLowerCase()===e)return i;return t.trim()}}class sl{constructor(t,e,i,n=new zh({}),s){this.labels=t,this.naming=e,this.said=i,this.tags=n,this.timeWords=s}entriesFor(t,e,i={}){const n=[];return this.addSummary(n,t),this.addObservation(n,t),this.addObserver(n,t,e),this.addLocation(n,t,e,i.groundElevationM,i.roadGradeDeg??0),this.addDecor(n,t,e,i),i.phenomena===!0&&this.addPhenomena(n,t,e),this.addTemporal(n,t),this.addWeather(n,t,e),this.addSound(n,t,e),n}push(t,e,i,n,s,r="",o={}){s===void 0||s===""||t.push({group:e,field:i,label:n,value:String(s),unit:r,color:o.color,fromSource:o.fromSource===!0})}percent(t){return t===void 0?void 0:`${Math.round(t*100)} %`}rounded(t,e=0){return t===void 0?void 0:String(Number(t.toFixed(e)))}shows(t,e=0){return t!==void 0&&Number(t.toFixed(e))!==0}showsPercent(t){return this.shows(t===void 0?void 0:t*100)}percentShown(t){return this.showsPercent(t)?this.percent(t):void 0}roundedShown(t,e=0){return this.shows(t,e)?this.rounded(t,e):void 0}static DESCRIPTION_WORDS=3;addSummary(t,e){const i=this.said.read(e.event.description)?.trim();if(!i)return;const n=i.split(/\s+/),s=n.length>sl.DESCRIPTION_WORDS?`${n.slice(0,sl.DESCRIPTION_WORDS).join(" ")}…`:i;this.push(t,"summary","description",this.labels.summaryDescription,s),t[t.length-1].full=i}addObservation(t,e){const i=e.event.tags;this.push(t,"observation","tags",this.labels.tags,i&&i.length>0?i.map(n=>this.tags.name(n)).join(", "):void 0)}filterName(t){return t===ls.SOLAR_VISUAL?this.labels.filterSolarVisual:t===ls.SOLAR_PHOTO?this.labels.filterSolarPhoto:t.name}addObserver(t,e,i){const n=e.observer;this.push(t,"observer","observerId",this.labels.observerId,n?.id),this.push(t,"observer","observerTitle",this.labels.observerTitle,n?.title),this.push(t,"observer","observerLastName",this.labels.observerLastName,n?.lastName);const s=n?.firstNames;this.push(t,"observer","observerFirstNames",this.labels.observerFirstNames,s&&s.length>0?s.join(", "):void 0);const r=e.instrument;this.push(t,"observer","instrument",this.labels.instrument,this.naming.instrument(r));const o=e.exposure;this.push(t,"observer","exposureSeconds",this.labels.exposure,o===void 0?void 0:o<1?`1/${Math.round(1/o)}`:this.rounded(o,2),"s");const c=Ze(e,i);if(c){const l=bi.focalLengthMmFor(r,c.fovDeg);l===void 0?this.push(t,"observer","focalLength",this.labels.fieldOfView,this.rounded(c.fovDeg,1),"°"):this.push(t,"observer","focalLength",this.labels.focalLength,this.rounded(l,1),"mm"),this.push(t,"observer","fNumber",this.labels.aperture,this.rounded(c.fNumber??r.fNumber,1)),this.push(t,"observer","focusDistance",this.labels.focusDistance,this.rounded(c.focusDistanceM,1),"m"),this.push(t,"observer","roll",this.labels.roll,this.roundedShown(c.rollDeg),"°");const h=ls.byId(c.filter);h!==ls.NONE&&this.push(t,"observer","filter",this.labels.filter,this.filterName(h))}}degreesMinutesSeconds(t,e,i){if(t===void 0||!Number.isFinite(t))return;const n=Math.round(Math.abs(t)*3600),s=Math.floor(n/3600),r=Math.floor(n%3600/60),o=n%60;return`${s}°${String(r).padStart(2,"0")}′${String(o).padStart(2,"0")}″ ${this.naming.point(t<0?i:e)}`}addLocation(t,e,i,n,s){const r=e.event.place?.[0];this.push(t,"location","placeName",this.labels.placeName,r?.name);const o=Ze(e,i);if(!o)return;this.push(t,"location","lat",this.labels.latitude,this.degreesMinutesSeconds(o.lat,0,180)),this.push(t,"location","lng",this.labels.longitude,this.degreesMinutesSeconds(o.lng,90,270));const c=this.rounded(o.headingDeg);this.push(t,"location","heading",this.labels.heading,c,o.headingDeg===void 0?"°":`° (${this.naming.point(o.headingDeg)})`),this.push(t,"location","pitch",this.labels.pitch,o.pitchDeg===void 0?void 0:this.rounded(o.pitchDeg+s),"°"),n===void 0?this.push(t,"location","elevation",this.labels.heightAboveGround,this.roundedShown(o.elevationM),"m"):this.push(t,"location","elevation",this.labels.elevation,this.rounded(n+o.elevationM),"m")}addDecor(t,e,i,n){const s=e.decor.find(l=>l.id===n.decorId);if(!s){if(n.decorPicker===!0)for(const l of e.decor)this.push(t,"decor",`decor:${l.id}`,this.decorLabel(l),this.decorKindName(l.kind));return}this.push(t,"decor","decorTitle",this.labels.decorTitle,this.said.read(s.title));const r=Hr(s,i);this.push(t,"decor","decorEast",this.labels.decorEast,this.rounded(r.eastM,1),"m"),this.push(t,"decor","decorNorth",this.labels.decorNorth,this.rounded(r.northM,1),"m"),this.push(t,"decor","decorAltitude",this.labels.decorAltitude,this.roundedShown(r.altitudeM),"m"),this.push(t,"decor","decorHeading",this.labels.decorHeading,this.rounded(r.headingDeg),"°"),vM(s,i)&&this.push(t,"decor","decorLit",this.labels.decorLit,"✓");const o=s.lights?.map(l=>l.id).join()??"",c=o===""?void 0:Lx.find(l=>l.create().map(h=>h.id).join()===o);this.push(t,"decor","decorLightRig",this.labels.decorLights,c?.name),this.push(t,"decor","decorFloors",this.labels.decorFloors,s.floors),this.push(t,"decor","decorOccupiedFloor",this.labels.decorOccupiedFloor,s.occupiedFloor),this.push(t,"decor","decorObserverSide",this.labels.decorObserverSide,this.decorSideName(s.observerSide));for(const[l,h]of Object.entries(s.windows??{}))this.push(t,"decor",`decorWindow${this.capitalise(l)}`,`${this.labels.decorWindows} ${this.decorSideName(l)}`,h,"%")}timeText(t){return this.timeWords?er.describeTime(t,this.timeWords.messages,this.timeWords.locale):Uh(t)}addTemporal(t,e){const i=e.event;this.push(t,"temporal","obs-time",this.labels.observationTime,i.time&&this.timeText(i.time)),this.push(t,"temporal","obs-end-time",this.labels.observationEndTime,i.endTime&&this.timeText(i.endTime));const n=fM(i);this.push(t,"temporal","durationSeconds",this.labels.duration,this.roundedShown(n&&n/1e3,1),"s"),this.push(t,"temporal","timeZone",this.labels.utcOffset,i.timeZone),this.push(t,"temporal","utcOffsetHours",this.labels.utcOffset,this.rounded(i.utcOffsetHours,1),"UTC±h")}addWeather(t,e,i){const n=Eo(e,i),r={fromSource:e.weatherSource!==void 0},o=this.showsPercent(n.cloudCover)||this.showsPercent(n.lowerCloudCover)||this.showsPercent(n.highCloudCover);this.push(t,"weather","cloudCover",this.labels.cloudCover,this.percentShown(n.cloudCover),"",r),this.push(t,"weather","highCloudCover",this.labels.highCloudCover,this.percentShown(n.highCloudCover),"",r),this.push(t,"weather","iceCrystalAlignment",this.labels.iceCrystalAlignment,this.showsPercent(n.highCloudCover)?this.percent(n.iceCrystalAlignment):void 0),this.push(t,"weather","cloudDarkness",this.labels.cloudDarkness,o?this.percent(n.cloudDarkness):void 0,"",r),this.push(t,"weather","cloudBase",this.labels.cloudBase,o?this.rounded(n.cloudBaseM):void 0,"m",r);const c=n.precipitationType!=="none"&&this.showsPercent(n.precipitationIntensity);this.push(t,"weather","precipitationType",this.labels.precipitationType,c?this.precipitationName(n.precipitationType):void 0,"",r),this.push(t,"weather","precipitationIntensity",this.labels.precipitationIntensity,c?this.percent(n.precipitationIntensity):void 0,"",r),this.push(t,"weather","windDirection",this.labels.windDirection,this.shows(n.windSpeed,2)?this.rounded(n.windDirectionDeg):void 0,"°",r),this.push(t,"weather","windSpeed",this.labels.windSpeed,this.roundedShown(n.windSpeed,2),"m/s",r),n.storm&&this.push(t,"weather","storm",this.labels.storm,"✓","",r)}addSound(t,e,i){const n=pM(e,i);n.kind!=="none"&&(this.push(t,"sound","soundKind",this.labels.soundKind,this.soundKindName(n.kind)),this.push(t,"sound","soundVolume",this.labels.soundVolume,this.percentShown(n.volume)),this.push(t,"sound","soundPitch",this.labels.soundPitch,this.roundedShown(n.pitchHz),"Hz"),this.push(t,"sound","soundSrc",this.labels.soundSrc,n.src))}addPhenomena(t,e,i){for(const n of e.timeline.sourceIds){const s=e.timeline.getInterpolatedShapeAt(i,n),r=s?.angular,o=r?`${this.rounded(r.widthDeg,2)} × ${this.rounded(r.heightDeg,2)}°`:void 0;this.push(t,"phenomenon",`shape:${n}`,this.said.read(s?.title)??n,o)}for(const n of e.interpretation?.bodies??[]){const s=n.track.find(o=>o.sizeM?.widthM!==void 0)?.sizeM?.widthM,r=n.model.id??n.model.url?.replace(/^.*\//,"");this.push(t,"phenomenon",`body:${n.id}`,this.said.read(n.title)??n.id,[r,s!==void 0?`${this.rounded(s,2)} m`:void 0].filter(Boolean).join(", "))}}decorLabel(t){return this.said.read(t.title)??this.decorKindName(t.kind)}decorKindName(t){switch(t){case"building":return this.labels.decorBuilding;case"tree":return this.labels.decorTree;case"shrub":return this.labels.decorShrub;case"bridge":return this.labels.decorBridge;case"wire":return this.labels.decorWire;case"crop":return this.labels.decorCrop;case"terrace":return this.labels.decorTerrace;case"mound":return this.labels.decorMound;case"streetlight":return this.labels.decorStreetlight;case"vehicle":return this.labels.decorVehicle;case"aircraft":return this.labels.decorAircraft;default:return this.labels.decorObserver}}decorSideName(t){switch(t){case"front":return this.labels.decorSideFront;case"behind":return this.labels.decorSideBehind;case"left":return this.labels.decorSideLeft;case"right":return this.labels.decorSideRight;case"front-left":return this.labels.decorSideFrontLeft;case"front-right":return this.labels.decorSideFrontRight;case"behind-left":return this.labels.decorSideBehindLeft;case"behind-right":return this.labels.decorSideBehindRight;default:return}}precipitationName(t){switch(t){case"rain":return this.labels.precipitationRain;case"snow":return this.labels.precipitationSnow;case"hail":return this.labels.precipitationHail;default:return this.labels.precipitationNone}}soundKindName(t){switch(t){case"hum":return this.labels.soundHum;case"whistle":return this.labels.soundWhistle;case"rumble":return this.labels.soundRumble;case"crackle":return this.labels.soundCrackle;default:return this.labels.soundNone}}capitalise(t){return t.replace(/(^|-)([a-z])/g,(e,i,n)=>n.toUpperCase())}}class Yn{constructor(t){this.preferences=t}read(t){if(t===void 0||typeof t=="string")return t===""?void 0:t;for(const i of this.preferences){const n=t[i]??t[Yn.base(i)];if(n)return n}const e=new Set(this.preferences.map(i=>Yn.base(i)));for(const[i,n]of Object.entries(t))if(n&&e.has(Yn.base(i)))return n;return Object.values(t).find(i=>i)??void 0}write(t,e,i){const n=e?.trim()?e.trim():void 0;if(t===void 0||typeof t=="string")return n;const s={...t},r=Object.keys(s).find(o=>o===i)??Object.keys(s).find(o=>Yn.base(o)===Yn.base(i))??i;return n===void 0?delete s[r]:s[r]=n,Object.keys(s).length===0?void 0:s}static base(t){return t.toLowerCase().split("-")[0]}}function Ep(a,t){for(const e of a){const i=e.toLowerCase().split("-")[0];if(t.includes(i))return i}return"en"}class Gr{static preferencesFor(t){const e=navigator.languages??[],i=this.declaredFor(t);return i?[i,...e]:e}static declaredFor(t){for(let e=t;e;){const i=e.closest("[lang]")?.getAttribute("lang")?.trim();if(i)return i;const n=e.getRootNode();e=n instanceof ShadowRoot?n.host:void 0}}}const Nx="Global Meteor Network",kx="https://globalmeteornetwork.org/data/",Fx="“Thunder” by Jerimee",Ux="https://creativecommons.org/licenses/by/3.0/",zx="CC BY 3.0";class rn{static fill(t,e){t.innerHTML="";const i=h=>t.appendChild(h),n=e.currentTerrainAttribution;n&&i(rn.text(n));const s=e.currentRoadAttribution;s&&i(rn.text(s));const r=e.ufoElement.observerMapCredit;r&&!n?.includes(r)&&i(rn.text(r));for(const h of e.decorModelCredits){const u=h.author?` — ${h.author}`:"",d=document.createElement("li");h.sourceUrl?d.append(rn.link(h.sourceUrl,h.title),document.createTextNode(`${u} (${h.license})`)):d.textContent=`${h.title}${u} (${h.license})`,i(d)}for(const h of e.ufoElement.sighting.references){if(!h.credit)continue;const u=document.createElement("li");h.creditUrl?u.appendChild(rn.link(h.creditUrl,h.credit)):u.textContent=h.credit,i(u)}if(e.ufoElement.sighting.traces.length>0){const h=new Yn(Gr.preferencesFor(e)),u=new Set(e.ufoElement.sighting.traces.map(d=>h.read(d.source)).filter(d=>!!d));for(const d of u)i(rn.text(d))}const o=e.satelliteState;if(o.status==="ready"&&o.credit){const h=document.createElement("li");h.appendChild(rn.link(o.creditUrl??"",o.credit)),i(h)}if(e.fireballState.status==="ready"&&e.fireballState.records.length>0){const h=document.createElement("li");h.append(rn.link(kx,Nx),document.createTextNode(" (CC BY 4.0)")),i(h)}const c=e.aircraftState;if(c.status==="ready"&&c.shown>0){const h=document.createElement("li");if(h.appendChild(rn.link(c.creditUrl,c.credit)),i(h),c.trailCredit){const u=document.createElement("li");u.appendChild(rn.link(c.trailCredit.creditUrl,c.trailCredit.credit)),i(u)}}const l=rn.text(`${Fx} (`);l.append(rn.link(Ux,zx),document.createTextNode(")")),i(l)}static text(t){const e=document.createElement("li");return e.textContent=t,e}static link(t,e){const i=document.createElement("a");return i.href=t,i.target="_blank",i.rel="noopener",i.textContent=e,i}}const Bx=[{id:"coverage",name:"Coverage",credit:"UFO@home",creditUrl:"https://ufoathome.org",create:()=>({about:"observer",assess:async a=>{const{CoverageAssessor:t}=await je(async()=>{const{CoverageAssessor:e}=await import("./CoverageAssessor-CZfxbN9A.js");return{CoverageAssessor:e}},[],import.meta.url);return new t().assess(a)}})},{id:"hynek",name:"Hynek",credit:"J. Allen Hynek",creditUrl:"https://rr0.org/science/crypto/ufo/observation/classification/hynek/",create:()=>({about:"temporal",assess:async a=>{const{HynekAssessor:t}=await je(async()=>{const{HynekAssessor:e}=await import("./HynekAssessor-DPsLpEGQ.js");return{HynekAssessor:e}},[],import.meta.url);return new t().assess(a)}})}];class Hx{constructor(t){this.labels=t}async read(t){const e=[],i=new Set;for(const n of Bx){let s;try{s=await n.create().assess(t)}catch{continue}for(const o of s.criteria)o.basis===void 0&&!o.unsupported&&i.add(o.id);const r=s.score===void 0?s.verdict===void 0?"":this.verdictName(n.id,s.verdict):`${Math.round(s.score*100)}%`;r!==""&&e.push({group:"assessment",field:n.id,label:this.labels.assessmentNames[n.id]??n.name,value:r,unit:"",fromSource:!1,about:n.create().about})}return{entries:e,unanswered:i}}verdictName(t,e){return this.labels.assessmentVerdicts[`${t}.${e}`]??e.toUpperCase()}}const yM=Math.PI/180,yu=111320;function si(a,t,e,i){const n=yu*Math.cos(e*yM),s=(a-e)*yu;return{x:(t-i)*n,z:-s}}function Nn(a,t,e,i){const n=yu*Math.cos(e*yM),s=-t,r=a;return{lat:e+s/yu,lng:i+r/n}}class Ro{static HALF_SPAN_MS=2e3;static MIN_SPEED_MS=1;static at(t,e,i){const n=t.event.place?.[0],s=t.observerTrack;if(!n)return 0;const r=v=>{const m=s.getInterpolatedPoseAt(Math.max(0,v));if(!m||m.lat===void 0||m.lng===void 0)return;const g=si(m.lat,m.lng,n.lat,n.lng);return{eastM:g.x,northM:-g.z,heading:m.headingDeg}},o=r(e-Ro.HALF_SPAN_MS),c=r(e+Ro.HALF_SPAN_MS),l=r(e);if(!o||!c||!l)return 0;const h=Math.hypot(c.eastM-o.eastM,c.northM-o.northM),u=2*Ro.HALF_SPAN_MS/1e3;if(h/u<Ro.MIN_SPEED_MS)return 0;const d=i.heightAt(c.eastM,c.northM)-i.heightAt(o.eastM,o.northM),f=Math.atan2(d,h)*180/Math.PI;if(l.heading===void 0)return f;const p=Math.atan2(c.eastM-o.eastM,c.northM-o.northM)*180/Math.PI;return f*Math.max(0,Math.cos((l.heading-p)*Math.PI/180))}}class Oa{static sessionDeclared=!1;static unlock(t){if(Oa.declarePlayback(),t.state!=="running")try{Promise.resolve(t.resume()).catch(()=>{});const e=t.createBufferSource();e.buffer=t.createBuffer(1,1,22050),e.connect(t.destination),e.start(0)}catch{}}static declarePlayback(){if(!(Oa.sessionDeclared||typeof navigator>"u")){Oa.sessionDeclared=!0;try{const t=navigator.audioSession;t&&(t.type="playback")}catch{}}}}const Gx=.08,Zm=.15,Jm=2,Vx=2e3;class Wx{context;noiseBuffer;voices=new Map;level=1;master;paused=!0;requested=[];resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("VehicleAudio: Web Audio unavailable, vehicles stay silent:",t);return}}Oa.unlock(this.context),this.apply()}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}setPaused(t){t!==this.paused&&(this.paused=t,this.apply())}setVoices(t){this.requested=t,this.apply()}dispose(){for(const t of[...this.voices.keys()])this.release(t);this.context?.close(),this.context=void 0,this.master=void 0}masterOf(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}apply(){const t=this.context;if(!t)return;const e=this.paused?[]:this.requested.filter(n=>n.inside||n.distanceM<Vx),i=new Set(e.map(n=>n.id));for(const n of[...this.voices.keys()])i.has(n)||this.release(n);for(const n of e){const s=this.voices.get(n.id)??this.build(t,n.id);this.retarget(t,s,n)}}build(t,e){const i=t.createGain();i.gain.value=0;const n=t.createBiquadFilter();n.type="lowpass",n.connect(i).connect(this.masterOf(t));const s=t.createOscillator();s.type="sawtooth";const r=t.createOscillator();r.type="sine";const o=t.createGain(),c=t.createBiquadFilter();c.type="lowpass",c.frequency.value=900,s.connect(c),r.connect(c),c.connect(o).connect(n);const l=()=>{const x=t.createBufferSource();return x.buffer=this.noise(t),x.loop=!0,x.loopStart=Math.random()*Jm*.5,x},h=l(),u=t.createBiquadFilter();u.type="bandpass",u.Q.value=4;const d=t.createGain();h.connect(u).connect(d).connect(n);const f=l(),p=t.createBiquadFilter();p.type="lowpass",p.frequency.value=600;const v=t.createGain();f.connect(p).connect(v).connect(n);const m=l(),g=t.createBiquadFilter();g.type="bandpass",g.frequency.value=1400,g.Q.value=.7;const b=t.createGain();m.connect(g).connect(b).connect(n);const S=[s,r,h,f,m];for(const x of S)x.start();const M={nodes:[i,n,o,c,u,d,p,v,g,b,...S],sources:S,firing:s,crank:r,knock:u,engineGain:o,knockGain:d,roadGain:v,windGain:b,cabin:n,output:i};return this.voices.set(e,M),M}retarget(t,e,{profile:i,state:n,noise:s,inside:r,windowsOpen:o,distanceM:c}){const l=t.currentTime,h=(b,S)=>b.setTargetAtTime(S,l,Gx),u=n.rpm/60,d=u*i.cylinders/2,f=Math.min(1,n.rpm/i.shiftUpRpm),p=Math.min(1.5,n.speedMps/30);h(e.firing.frequency,d),h(e.crank.frequency,u),h(e.knock.frequency,d*3),h(e.engineGain.gain,i.engineGain*(.25+.75*n.load)*(.5+.5*f)*.3),h(e.knockGain.gain,i.roughness*(.2+.8*n.load)*.4),h(e.roadGain.gain,i.roadGain*p**1.5*.8);const v=!r||o;h(e.windGain.gain,p**2*(v?.5:.06));const m=r?o?3500:700:8e3/(1+c/60);h(e.cabin.frequency,m);const g=r?.5:Math.min(1,8/Math.max(c,1));h(e.output.gain,g*s)}release(t){const e=this.voices.get(t);if(!e)return;this.voices.delete(t);const i=this.context;i&&(e.output.gain.setTargetAtTime(0,i.currentTime,Zm/3),setTimeout(()=>{for(const n of e.sources)try{n.stop()}catch{}for(const n of e.nodes)n.disconnect()},Zm*1e3*3))}noise(t){if(this.noiseBuffer)return this.noiseBuffer;const e=t.createBuffer(1,t.sampleRate*Jm,t.sampleRate),i=e.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;return this.noiseBuffer=e,e}}class rl{static BY_KIND={car:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},generic:{cylinders:4,idleRpm:800,kmhPer1000Rpm:[8,14,21,29,37,45],shiftUpRpm:3e3,shiftDownRpm:1300,engineGain:.6,roadGain:.5,roughness:.15},van:{cylinders:4,idleRpm:750,kmhPer1000Rpm:[7,12,19,27,35,42],shiftUpRpm:2600,shiftDownRpm:1200,engineGain:.8,roadGain:.7,roughness:.45},truck:{cylinders:6,idleRpm:600,kmhPer1000Rpm:[5,8,12,17,23,30,38,48],shiftUpRpm:1900,shiftDownRpm:1e3,engineGain:1,roadGain:.9,roughness:.55},motorcycle:{cylinders:2,idleRpm:1100,kmhPer1000Rpm:[12,18,24,30,35,40],shiftUpRpm:6e3,shiftDownRpm:2500,engineGain:.9,roadGain:.3,roughness:.3}};static of(t){return rl.BY_KIND[t??"generic"]??rl.BY_KIND.generic}}class Ea{constructor(t,e){this.samples=t,this.startMs=e}static SAMPLE_MS=100;static STANDING_MPS=.3;static of(t,e,i,n){const s=Ea.SAMPLE_MS,r=[];for(let l=i;l<=n+s/2;l+=s){const h=e(l-s/2),u=e(l+s/2);if(!h||!u)return;r.push(Math.hypot(u.eastM-h.eastM,u.northM-h.northM)/(s/1e3))}const o=[];let c=1;for(let l=0;l<r.length;l++){const h=r[l],u=(r[Math.min(l+1,r.length-1)]-r[Math.max(l-1,0)])/(2*s/1e3);if(h<Ea.STANDING_MPS){c=1,o.push({speedMps:h,rpm:t.idleRpm,load:.1,gear:0});continue}const d=h*3.6,f=g=>d/t.kmhPer1000Rpm[g-1]*1e3;for(;c<t.kmhPer1000Rpm.length&&f(c)>t.shiftUpRpm;)c++;for(;c>1&&f(c)<t.shiftDownRpm;)c--;const p=Math.max(f(c),t.idleRpm*(1+.3*Math.min(1,h/3))),v=.15+.5*Math.min(1,(h/35)**2),m=u>.15?Math.min(1,v+u/2.5):u<-.3?.05:v;o.push({speedMps:h,rpm:p,load:m,gear:c})}return new Ea(o,i)}at(t){const e=(t-this.startMs)/Ea.SAMPLE_MS,i=Math.min(Math.max(Math.floor(e),0),this.samples.length-1),n=this.samples[i],s=this.samples[Math.min(i+1,this.samples.length-1)],r=Math.min(Math.max(e-i,0),1);return{speedMps:n.speedMps+(s.speedMps-n.speedMps)*r,rpm:n.rpm+(s.rpm-n.rpm)*r,load:n.load+(s.load-n.load)*r,gear:r<.5?n.gear:s.gear}}}class xu{drives=new Map;at(t,e){const i=[],n=t.event.place?.[0],s=l=>{const h=t.observerTrack.getInterpolatedPoseAt(l),u=h?.lat??n?.lat,d=h?.lng??n?.lng;if(u===void 0||d===void 0||!n)return;const f=si(u,d,n.lat,n.lng);return{eastM:f.x,northM:-f.z}},r=Math.max(t.observerTrack.duration,(t.event.durationSeconds??0)*1e3),o=t.vehicle;if(o){const l=rl.of(o.kind),h=this.drive(`observer:${o.kind}`,xu.trackKey(t),()=>Ea.of(l,s,0,r));h&&i.push({id:"observer",profile:l,state:h.at(e),noise:o.noise??1,inside:!0,windowsOpen:o.windowsOpen===!0,distanceM:0})}const c=s(e);for(const l of t.decor){if(!l.engine||!c)continue;const h=rl.of(l.engine.kind),u=v=>{const m=Hr(l,v);return{eastM:m.eastM,northM:m.northM}},d=this.drive(`decor:${l.id}`,xu.decorKey(l,r),()=>Ea.of(h,u,0,r));if(!d)continue;const f=Hr(l,e),p=Math.hypot(f.eastM-c.eastM,f.northM-c.northM,f.altitudeM);i.push({id:`decor:${l.id}`,profile:h,state:d.at(e),noise:l.engine.noise??1,inside:!1,windowsOpen:!0,distanceM:p})}return i}drive(t,e,i){const n=this.drives.get(t);if(n&&n.key===e)return n.drive;const s=i();return this.drives.set(t,{key:e,drive:s}),s}static trackKey(t){return t.observerTrack.allKeyframes.map(i=>`${i.t}:${i.pose.lat}:${i.pose.lng}`).join(";")}static decorKey(t,e){return`${e}|${t.eastM},${t.northM}|`+(t.track??[]).map(i=>`${i.t}:${i.eastM}:${i.northM}`).join(";")}}const jm=864e5,Qm=4e4;function Xx(a){const t=Math.floor(a.getTime()/jm);return{elapsedMs:a.getTime()-t*jm,shiftM:{x:tg.unit(t,2654435761)*Qm,z:tg.unit(t,2246822507)*Qm}}}class tg{static unit(t,e){let i=Math.imul(t|0,e)^e;return i=Math.imul(i^i>>>15,739982445),i=Math.imul(i^i>>>12,695872825),i^=i>>>15,(i>>>0)/4294967295*2-1}}function eg(a,t,e,i,n,s,r){const o=i?.lat!==void 0&&i.lng!==void 0&&n?.lat!==void 0&&n.lng!==void 0?si(n.lat,n.lng,i.lat,i.lng):{x:0,z:0};if(r){const h=t.getInterpolatedWeatherAt(0)??e,u=s===void 0?void 0:h.cloudLayers?.find(p=>p.id===s),d=(u?.windDirectionDeg??h.windDirectionDeg)*Math.PI/180,f=(u?.windSpeed??h.windSpeed)*r.elapsedMs/1e3;o.x+=r.shiftM.x-Math.sin(d)*f,o.z+=r.shiftM.z+Math.cos(d)*f}const c=Math.max(0,a),l=[0,...t.allKeyframes.map(h=>h.t).filter(h=>h>0&&h<c),c];for(let h=1;h<l.length;h++){const u=l[h-1],d=l[h]-u;if(d===0)continue;const f=32;for(let p=0;p<=f;p++){const v=t.getInterpolatedWeatherAt(u+d*p/f)??e,m=s===void 0?void 0:v.cloudLayers?.find(M=>M.id===s),g=(m?.windDirectionDeg??v.windDirectionDeg)*Math.PI/180,b=p===0||p===f?1:p%2===0?2:4,S=(m?.windSpeed??v.windSpeed)*d/1e3/f/3*b;o.x-=Math.sin(g)*S,o.z+=Math.cos(g)*S}}return o}const Yx=`
773
773
  <div class="stage" id="stage">
774
774
  <div class="frame" id="frame">
775
775
  <canvas id="scene-canvas"></canvas>
@@ -2180,11 +2180,11 @@ canvas[data-cursor="rotate"] {
2180
2180
  `;class Fo{constructor(t){this.points=t}static STATIONARY_M=5;static of(t){const e=[];for(const i of t.observerTrack.allKeyframes){const{lat:n,lng:s,headingDeg:r}=i.pose;n===void 0||s===void 0||e.push({t:i.t,lat:n,lng:s,headingDeg:r})}if(e.length===0){const i=t.event.place?.[0];if(!i)return;e.push({t:0,lat:i.lat,lng:i.lng})}return new Fo(e)}static TRAVEL_M=50;get travels(){return this.spanM>Fo.TRAVEL_M}get moved(){return this.spanM>Fo.STATIONARY_M}get spanM(){const t=this.box,e=(t.south+t.north)/2,i=(t.west+t.east)/2;return Math.max(Math.abs(si(e,t.east,e,t.west).x),Math.abs(si(t.north,i,t.south,i).z))}get center(){const t=this.box;return{lat:(t.south+t.north)/2,lng:(t.west+t.east)/2}}boundsAround(t,e){const{lat:i,lng:n}=this.center,s=Math.max(this.spanM*(1+e),t)/2;return{north:Nn(0,-s,i,n).lat,south:Nn(0,s,i,n).lat,east:Nn(s,0,i,n).lng,west:Nn(-s,0,i,n).lng}}get box(){const t=this.points.map(i=>i.lat),e=this.points.map(i=>i.lng);return{south:Math.min(...t),north:Math.max(...t),west:Math.min(...e),east:Math.max(...e)}}}class Bn{constructor(t,e){this.rotationPassed=t,this.scale=e}static SWAY_M=.012;static BREATH_M=.003;static DRIFT_YAW_DEG=.5;static DRIFT_PITCH_DEG=.4;static DRIFT_ROLL_DEG=.3;static GAZE_DRIFT_SHARE=.35;static HAND_HELD_S=.5;static HZ=[.11,.23,.17,.29,.37,.07];static of(t){const e=t.event.tags?.includes("paralysis")||(t.exposure??0)>Bn.HAND_HELD_S,i=t.sway??(e?0:1);if(i>0)return new Bn(Math.max(1-(t.instrument.stabilization??0),Bn.GAZE_DRIFT_SHARE),i)}offsetAt(t){const e=t/1e3,i=this.scale,n=(u,d)=>Math.sin(2*Math.PI*u*e+d),[s,r,o,c,l,h]=Bn.HZ;return{eastM:i*Bn.SWAY_M*(.7*n(s,.3)+.3*n(c,1.9)),northM:i*Bn.SWAY_M*(.6*n(o,2.2)+.4*n(l,.8)),upM:i*Bn.BREATH_M*n(r,0),yawDeg:i*this.rotationPassed*Bn.DRIFT_YAW_DEG*(.6*n(h,1.1)+.4*n(c,2.7)),pitchDeg:i*this.rotationPassed*Bn.DRIFT_PITCH_DEG*(.5*n(r,1.6)+.5*n(o,.4)),rollDeg:i*this.rotationPassed*Bn.DRIFT_ROLL_DEG*n(s,2.9)}}}class Ce{constructor(t,e){this.stretches=t,this.rotationPassed=e}static REFERENCE_SPEED_M_PER_S=1.4;static REFERENCE_STEP_HZ=1.9;static CADENCE_EXPONENT=.43;static RISE_M_PER_M_PER_S=.0175;static SWAY_M=.0175;static SLOWEST_WALK_M_PER_S=.2;static FASTEST_WALK_M_PER_S=2.2;static HEAD_ROLL_DEG=1.5;static HEAD_PITCH_DEG=1.25;static HEAD_YAW_DEG=1;static STOP_LURCH_M=.035;static STOP_PITCH_DEG=3;static START_LURCH_M=.015;static START_PITCH_DEG=1.2;static JOLT_HZ=1.4;static JOLT_DECAY_S=.35;static JOLT_LASTS_MS=1500;static STILL=Object.freeze({eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0});static of(t){const e=Fo.of(t);if(!e||e.points.length<2)return;const i=[];let n=0;for(let s=1;s<e.points.length;s++){const r=e.points[s-1],o=e.points[s],c=(o.t-r.t)/1e3;if(c<=0)continue;const l=si(o.lat,o.lng,r.lat,r.lng),h=l.x,u=-l.z,d=Math.hypot(h,u),f=d/c,p=Ce.stepHzFor(f);i.push({startMs:r.t,endMs:o.t,speedMPerS:f,eastUnit:d>0?h/d:0,northUnit:d>0?u/d:0,stepHz:p,stepsBefore:n,rampsIn:!0,rampsOut:!0}),n+=p*c}for(let s=0;s<i.length;s++){const r=i[s-1],o=i[s+1];i[s].rampsIn=r===void 0||r.stepHz===0,i[s].rampsOut=o===void 0||o.stepHz===0}if(i.some(s=>s.stepHz>0))return new Ce(i,1-(t.instrument.stabilization??0))}static bodyAt(t,e,i=!1){const n=Ce.of(t)?.offsetAt(e)??Ce.STILL;return i?n:Ce.add(n,Bn.of(t)?.offsetAt(e))}static stepHzFor(t){return t<Ce.SLOWEST_WALK_M_PER_S||t>Ce.FASTEST_WALK_M_PER_S?0:Ce.REFERENCE_STEP_HZ*Math.pow(t/Ce.REFERENCE_SPEED_M_PER_S,Ce.CADENCE_EXPONENT)}offsetAt(t){return Ce.add(this.cycleAt(t),this.joltAt(t))}joltAt(t){for(const e of this.stretches){if(e.stepHz===0)continue;const i=e.speedMPerS/Ce.REFERENCE_SPEED_M_PER_S,n=(o,c,l,h)=>{if(o<0||o>Ce.JOLT_LASTS_MS)return;const u=o/1e3,d=Math.exp(-u/Ce.JOLT_DECAY_S)*Math.sin(2*Math.PI*Ce.JOLT_HZ*u),f=h*c*i*d;return{eastM:f*e.eastUnit,northM:f*e.northUnit,upM:-Math.abs(f)*.3,rollDeg:0,pitchDeg:-h*l*i*d*this.rotationPassed,yawDeg:0}},s=e.rampsOut?n(t-e.endMs,Ce.STOP_LURCH_M,Ce.STOP_PITCH_DEG,1):void 0;if(s)return s;const r=e.rampsIn?n(t-e.startMs,Ce.START_LURCH_M,Ce.START_PITCH_DEG,-1):void 0;if(r)return r}}static add(t,e){return e?{eastM:t.eastM+e.eastM,northM:t.northM+e.northM,upM:t.upM+e.upM,rollDeg:t.rollDeg+e.rollDeg,pitchDeg:t.pitchDeg+e.pitchDeg,yawDeg:t.yawDeg+e.yawDeg}:t}cycleAt(t){const e=this.stretches.find(c=>t>=c.startMs&&t<=c.endMs);if(!e||e.stepHz===0)return Ce.STILL;const i=e.stepsBefore+e.stepHz*(t-e.startMs)/1e3,n=2*Math.PI*i,s=this.amplitudeAt(e,t),r=Ce.SWAY_M*s*Math.cos(n/2),o=s*this.rotationPassed*e.speedMPerS/Ce.REFERENCE_SPEED_M_PER_S;return{eastM:r*e.northUnit,northM:-r*e.eastUnit,upM:Ce.RISE_M_PER_M_PER_S*e.speedMPerS*s*Math.cos(n),rollDeg:Ce.HEAD_ROLL_DEG*o*Math.cos(n/2),pitchDeg:-1.25*o*Math.cos(n),yawDeg:Ce.HEAD_YAW_DEG*o*Math.cos(n/2)}}amplitudeAt(t,e){const i=1e3/t.stepHz,n=Math.min(i,(t.endMs-t.startMs)/2);if(n<=0)return 1;const s=e-t.startMs,r=t.endMs-e,o=Math.min(t.rampsIn?s/n:1,t.rampsOut?r/n:1,1);return(1-Math.cos(Math.PI*Math.max(o,0)))/2}}class Zx{constructor(t,e){this.timeline=t,this.onFrame=e}rafId=null;state="stopped";currentT=0;lastWallTime=0;playbackRate=1;loop=!1;onEnded;durationOverrideMs=0;get seekableDuration(){return Math.max(this.timeline.duration,this.durationOverrideMs)}play(){if(this.state==="playing")return;this.currentT>=this.seekableDuration&&(this.currentT=0,this.resolveFrame(0)),this.state="playing",this.lastWallTime=performance.now();const t=()=>{if(this.state!=="playing")return;const e=performance.now();if(this.currentT+=(e-this.lastWallTime)*this.playbackRate,this.lastWallTime=e,this.currentT>=this.seekableDuration){if(this.loop&&this.seekableDuration>0){this.currentT%=this.seekableDuration,this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(t);return}this.currentT=this.seekableDuration,this.stop(),this.resolveFrame(this.currentT),this.onEnded?.();return}this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(t)};this.rafId=requestAnimationFrame(t)}pause(){this.state==="playing"&&(this.state="paused",this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null))}stop(){this.state="stopped",this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}seek(t){this.currentT=Math.max(0,Math.min(t,this.seekableDuration)),this.resolveFrame(this.currentT)}get playbackState(){return this.state}get time(){return this.currentT}resolveFrame(t){const e=new Map;for(const i of this.timeline.sourceIds){const n=this.timeline.getInterpolatedShapeAt(t,i);n&&e.set(i,n)}this.onFrame(t,e)}}const xM=["nw","n","ne","e","se","s","sw","w"],Jx=24,Cl=8,jx=3,Qx=8;function Pl(a,t,e){const i=a.x-t.x,n=a.y-t.y,s=Math.cos(e),r=Math.sin(e);return{x:t.x+i*s-n*r,y:t.y+i*r+n*s}}function hc(a){return{x:a.x+a.width/2,y:a.y+a.height/2}}const tb={nw:{left:!0,top:!0},n:{top:!0},ne:{right:!0,top:!0},e:{right:!0},se:{right:!0,bottom:!0},s:{bottom:!0},sw:{left:!0,bottom:!0},w:{left:!0}};class Dn{static handlePointsFor(t){const{x:e,y:i,width:n,height:s}=t.bounds,r={nw:{x:e,y:i},n:{x:e+n/2,y:i},ne:{x:e+n,y:i},e:{x:e+n,y:i+s/2},se:{x:e+n,y:i+s},s:{x:e+n/2,y:i+s},sw:{x:e,y:i+s},w:{x:e,y:i+s/2},rotate:{x:e+n/2,y:i-Jx}},o=hc(t.bounds),c={};for(const l of Object.keys(r))c[l]=Pl(r[l],o,t.angle);return c}static hitTestHandle(t,e,i=8,n=[...xM,"rotate"]){const s=Dn.handlePointsFor(t);for(const r of n)if(Math.hypot(e.x-s[r].x,e.y-s[r].y)<=i)return r}static HANDLE_DIRECTION_DEG={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315};static resizeAxisFor(t,e){const n=((Dn.HANDLE_DIRECTION_DEG[t]+e*180/Math.PI)%180+180)%180/45,s=["ew","nwse","ns","nesw"];return s[Math.round(n)%s.length]}static resizeBounds(t,e,i,n){const s=hc(t),r=Pl(n,s,-e),{x:o,y:c,width:l,height:h}=t,u=tb[i];let d=o,f=c,p=o+l,v=c+h;return u.left&&(d=Math.min(r.x,p-Cl)),u.right&&(p=Math.max(r.x,d+Cl)),u.top&&(f=Math.min(r.y,v-Cl)),u.bottom&&(v=Math.max(r.y,f+Cl)),{x:d,y:f,width:p-d,height:v-f}}static resizeShape(t,e,i){if(e==="rotate")throw new Error("resizeShape does not accept the rotate handle");const{width:n,height:s}=t.bounds,r=Dn.resizeBounds(t.bounds,t.angle,e,i);if(t.kind==="oval")return{...t,bounds:r};const o=n===0?1:r.width/n,c=s===0?1:r.height/s;return{...t,bounds:r,points:t.points.map(l=>({x:l.x*o,y:l.y*c}))}}static rotateShape(t,e){const i=hc(t.bounds),n=Math.atan2(e.y-i.y,e.x-i.x)+Math.PI/2;return{...t,angle:n}}static groupBoundsFor(t){const e=Math.min(...t.map(r=>r.x)),i=Math.min(...t.map(r=>r.y)),n=Math.max(...t.map(r=>r.x+r.width)),s=Math.max(...t.map(r=>r.y+r.height));return{x:e,y:i,width:n-e,height:s-i}}static vertexPointsFor(t){const e=hc(t.bounds);return t.points.map(i=>Pl({x:t.bounds.x+i.x,y:t.bounds.y+i.y},e,t.angle))}static hitTestVertex(t,e,i=Qx){const n=Dn.vertexPointsFor(t);let s,r=i;return n.forEach((o,c)=>{const l=Math.hypot(e.x-o.x,e.y-o.y);l<=r&&(r=l,s=c)}),s}static toLocalPoint(t,e){const i=hc(t.bounds),n=Pl(e,i,-t.angle);return{x:n.x-t.bounds.x,y:n.y-t.bounds.y}}static moveVertex(t,e,i){const n=t.points.map((u,d)=>d===e?Dn.toLocalPoint(t,i):u),s=Math.min(...n.map(u=>u.x)),r=Math.min(...n.map(u=>u.y)),o=Math.max(...n.map(u=>u.x)),c=Math.max(...n.map(u=>u.y)),l={x:t.bounds.x+s,y:t.bounds.y+r,width:o-s,height:c-r},h=n.map(u=>({x:u.x-s,y:u.y-r}));return{...t,bounds:l,points:h}}static insertVertexNear(t,e){const i=Dn.toLocalPoint(t,e),{points:n}=t;let s=n.length-1,r=1/0;for(let c=0;c<n.length;c++){const l=n[c],h=n[(c+1)%n.length],u=Dn.distanceToSegment(i,l,h);u<r&&(r=u,s=c)}const o=[...n.slice(0,s+1),i,...n.slice(s+1)];return{...t,points:o}}static distanceToSegment(t,e,i){const n=i.x-e.x,s=i.y-e.y,r=n*n+s*s,o=r===0?0:Math.max(0,Math.min(1,((t.x-e.x)*n+(t.y-e.y)*s)/r)),c=e.x+o*n,l=e.y+o*s;return Math.hypot(t.x-c,t.y-l)}static deleteVertex(t,e){return t.points.length<=jx?t:{...t,points:t.points.filter((i,n)=>n!==e)}}}const $f=6,Ol=$f/2,ig=20,ng=24,sg=9,rg=6,ag=7,og=6,ys=4;class al{constructor(t){this.ctx=t}starPoints=0;roll=0;clear(t,e){this.ctx.clearRect(0,0,t,e)}static paintExtent(t){const{x:e,y:i,width:n,height:s}=t.bounds,r=e+n/2,o=i+s/2,c=t.angle%(2*Math.PI)!==0,l=Math.hypot(n,s)/2,h=c?l:n/2,u=c?l:s/2,d=Math.max(n,s)/2,f=t.brightness??0,p=f>0?Math.max(d*(1+sg*f),og*f)-d:0,v=f>0?d*(1+ag*f)-d:0,m=3*ng*(t.blur??0)+1.5*ig*t.haloScale,g=Math.max(p,v,0)+m+2;return{x:r-h-g,y:o-u-g,width:2*(h+g),height:2*(u+g)}}paintInto(t,e,i,n=!1){this.ctx.save(),this.ctx.scale(i,i),this.ctx.translate(-e.x,-e.y);const s=t.selected?{...t,selected:!1}:t;n?this.paintGhost(s,1.5):this.paintShape(s),this.ctx.restore()}paintShape(t){this.ctx.save(),this.ctx.globalAlpha=1-t.transparency;const e=t.blur??0;e>0&&(this.ctx.filter=`blur(${(ng*e).toFixed(2)}px)`);const i=t.brightness??0;i>0&&this.paintDazzle(t,i),t.haloScale>0&&this.paintHalo(t),this.paintBase(t),this.ctx.restore(),t.selected&&this.paintSelectionHandles(t)}setStarPoints(t){this.starPoints=Math.max(0,Math.floor(t))}setRoll(t){this.roll=t}paintDazzle(t,e){const{x:i,y:n,width:s,height:r}=t.bounds,o=i+s/2,c=n+r/2,l=Math.max(s,r)/2,h=Math.max(l*(1+sg*e),og*e);if(h<=0)return;this.ctx.save(),this.ctx.globalCompositeOperation="lighter";const u=this.ctx.createRadialGradient(o,c,0,o,c,h);for(let d=0;d<=rg;d++){const f=d/rg,p=1/(1+24*f*f);this.ctx.globalAlpha=1,u.addColorStop(f,this.withAlpha(t.color,p*e*.55))}if(this.ctx.fillStyle=u,this.ctx.beginPath(),this.ctx.arc(o,c,h,0,2*Math.PI),this.ctx.fill(),this.starPoints>0){const d=l*(1+ag*e);this.ctx.lineWidth=Math.max(1,l*.12),this.ctx.lineCap="round";for(let f=0;f<this.starPoints;f++){const p=f/this.starPoints*Math.PI*2+this.roll,v=o+Math.cos(p)*d,m=c+Math.sin(p)*d,g=this.ctx.createLinearGradient(o,c,v,m);g.addColorStop(0,this.withAlpha(t.color,e*.55)),g.addColorStop(.35,this.withAlpha(t.color,e*.22)),g.addColorStop(1,this.withAlpha(t.color,0)),this.ctx.strokeStyle=g,this.ctx.beginPath(),this.ctx.moveTo(o,c),this.ctx.lineTo(v,m),this.ctx.stroke()}}this.ctx.restore()}dazzledFill(t,e){if(e<=0)return t.color;const i=/^#([0-9a-f]{6})$/i.exec(t.color.trim());if(!i)return t.color;const n=Number.parseInt(i[1],16),s=r=>Math.round(r+(255-r)*e);return`rgb(${s(n>>16&255)}, ${s(n>>8&255)}, ${s(n&255)})`}withAlpha(t,e){const i=Math.max(0,Math.min(1,e)),n=/^#([0-9a-f]{6})$/i.exec(t.trim());if(!n)return t;const s=Number.parseInt(n[1],16);return`rgba(${s>>16&255}, ${s>>8&255}, ${s&255}, ${i.toFixed(3)})`}paintBase(t){this.ctx.fillStyle=this.dazzledFill(t,t.brightness??0),this.tracePath(t),this.ctx.fill()}paintGhost(t,e){this.ctx.save(),this.tracePath(t),this.ctx.setLineDash([e*3,e*2]),this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color,this.ctx.stroke(),this.ctx.restore()}tracePath(t){if(this.ctx.beginPath(),t.kind==="oval"){const{x:e,y:i,width:n,height:s}=t.bounds,r=n/2,o=s/2;this.ctx.ellipse(e+r,i+o,r,o,t.angle,0,2*Math.PI)}else{const{x:e,y:i,width:n,height:s}=t.bounds;this.ctx.save(),this.ctx.translate(e+n/2,i+s/2),this.ctx.rotate(t.angle),this.ctx.translate(-n/2,-s/2),t.points.forEach((r,o)=>{o===0?this.ctx.moveTo(r.x,r.y):this.ctx.lineTo(r.x,r.y)}),this.ctx.closePath(),this.ctx.restore()}}paintHalo(t){this.ctx.save(),this.ctx.shadowColor=t.color,this.ctx.shadowBlur=ig*t.haloScale,this.paintBase(t),this.ctx.restore()}paintSelectionHandles(t){this.paintHandleFrame(Dn.handlePointsFor(t),{includeRotate:!0}),t.kind==="polygon"&&this.paintVertexHandles(t)}paintVertexHandles(t){this.ctx.fillStyle="#39f";for(const e of Dn.vertexPointsFor(t))this.ctx.beginPath(),this.ctx.ellipse(e.x,e.y,ys,ys,0,0,2*Math.PI),this.ctx.fill()}paintMemberOutline(t){this.paintOutline(Dn.handlePointsFor(t))}paintSelectionOnly(t){this.paintSelectionHandles(t)}paintPictureFrame(t,e,i){const n=this.ctx;if(n.save(),t&&t.length===4){n.strokeStyle="#39f",n.lineWidth=1.5,n.setLineDash([6,4]),n.beginPath(),n.moveTo(t[0].x,t[0].y);for(const s of t.slice(1))n.lineTo(s.x,s.y);n.closePath(),n.stroke(),n.setLineDash([])}for(const s of e){const r=al.landmarkColour(s.residualDeg),o=s.selected?3:2;s.selected&&(n.strokeStyle="#fff",n.lineWidth=o+3,n.beginPath(),n.ellipse(s.picture.x,s.picture.y,ys+2,ys+2,0,0,2*Math.PI),n.stroke()),s.scene&&(n.strokeStyle=r,n.lineWidth=1,n.beginPath(),n.moveTo(s.picture.x,s.picture.y),n.lineTo(s.scene.x,s.scene.y),n.stroke(),n.fillStyle=r,n.beginPath(),n.ellipse(s.scene.x,s.scene.y,ys,ys,0,0,2*Math.PI),n.fill()),n.strokeStyle=r,n.lineWidth=o,n.beginPath(),n.ellipse(s.picture.x,s.picture.y,ys+2,ys+2,0,0,2*Math.PI),n.stroke(),this.paintLabel(s.label,s.picture.x+ys+5,s.picture.y-ys-2,r)}i&&this.paintLabel(i,8,8,"#fff",13),n.restore()}static landmarkColour(t){return t===void 0?"#ffb000":t<=1?"#3c3":t<=3?"#ffb000":"#f33"}paintLabel(t,e,i,n,s=11){const r=this.ctx;r.save(),r.font=`${s}px system-ui, sans-serif`,r.textBaseline="top";const o=r.measureText(t).width;r.fillStyle="rgba(0, 0, 0, 0.6)",r.fillRect(e-3,i-2,o+6,s+4),r.fillStyle=n,r.fillText(t,e,i),r.restore()}paintGroupHandles(t){this.paintHandleFrame(Dn.handlePointsFor({bounds:t,angle:0}),{includeRotate:!0})}paintOutline(t){this.ctx.strokeStyle="lightgray",this.ctx.beginPath(),this.ctx.moveTo(t.nw.x,t.nw.y),this.ctx.lineTo(t.ne.x,t.ne.y),this.ctx.lineTo(t.se.x,t.se.y),this.ctx.lineTo(t.sw.x,t.sw.y),this.ctx.closePath(),this.ctx.stroke()}paintHandleFrame(t,{includeRotate:e}){this.paintOutline(t),this.ctx.fillStyle="lightgray";for(const i of xM){const n=t[i];this.ctx.fillRect(n.x-Ol,n.y-Ol,$f,$f)}e&&(this.ctx.beginPath(),this.ctx.moveTo(t.n.x,t.n.y),this.ctx.lineTo(t.rotate.x,t.rotate.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.ellipse(t.rotate.x,t.rotate.y,Ol+1,Ol+1,0,0,2*Math.PI),this.ctx.fill())}}const cg=.05,lg=.08,hg=2,ug=3,eb=14,ib=.02;class nb{context;voice;voiceToken=0;buffers=new Map;noiseBuffer;crackleBuffer;requested;level=1;master;output(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("SightingAudio: Web Audio unavailable, the sighting stays silent:",t);return}}Oa.unlock(this.context)}setSound(t){if(this.requested=t,!this.context)return;const e=this.keyFor(t);if(!e){this.silence();return}if(this.voice?.key!==e){this.stopVoice();const i=++this.voiceToken;e.startsWith("src:")?this.buildRecordedVoice(t.src,e,i):this.voice=this.buildSynthesizedVoice(t,e)}this.applyTo(this.voice,t)}silence(){this.voiceToken++,this.stopVoice()}dispose(){this.silence(),this.context?.close(),this.context=void 0,this.master=void 0,this.buffers.clear(),this.noiseBuffer=void 0,this.crackleBuffer=void 0}keyFor(t){if(!(t.volume<=0))return t.src?`src:${t.src}`:t.kind==="none"?void 0:t.kind}applyTo(t,e){const i=this.context;if(!t||!i)return;const n=i.currentTime;t.volumeParam.setTargetAtTime(Math.max(0,Math.min(1,e.volume))*t.gainScale,n,cg);for(const{param:s,ratio:r}of t.pitch)s.setTargetAtTime(Math.min(e.pitchHz*r,i.sampleRate/2-1),n,cg)}buildSynthesizedVoice(t,e){const i=this.context;if(i)switch(t.kind){case"hum":return this.buildHum(i,e);case"whistle":return this.buildWhistle(i,e);case"rumble":return this.buildRumble(i,e);case"crackle":return this.buildCrackle(i,e);default:return}}buildHum(t,e){const i=t.createOscillator();i.type="sawtooth";const n=t.createOscillator();n.type="sawtooth";const s=t.createBiquadFilter();s.type="lowpass",s.Q.value=1;const r=t.createGain();return r.gain.value=0,i.connect(s),n.connect(s),s.connect(r).connect(this.output(t)),i.start(),n.start(),{key:e,nodes:[s,r],sources:[i,n],volumeParam:r.gain,gainScale:.16,pitch:[{param:i.frequency,ratio:1},{param:n.frequency,ratio:1.006},{param:s.frequency,ratio:6}]}}buildWhistle(t,e){const i=t.createOscillator();i.type="sine";const n=t.createOscillator();n.type="sine",n.frequency.value=5;const s=t.createGain(),r=t.createGain();return r.gain.value=0,n.connect(s).connect(i.frequency),i.connect(r).connect(this.output(t)),i.start(),n.start(),{key:e,nodes:[s,r],sources:[i,n],volumeParam:r.gain,gainScale:.22,pitch:[{param:i.frequency,ratio:1},{param:s.gain,ratio:.012}]}}buildRumble(t,e){const i=t.createBufferSource();i.buffer=this.brownNoise(t),i.loop=!0;const n=t.createBiquadFilter();n.type="lowpass",n.Q.value=.8;const s=t.createGain();return s.gain.value=0,i.connect(n).connect(s).connect(this.output(t)),i.start(),{key:e,nodes:[n,s],sources:[i],volumeParam:s.gain,gainScale:1.4,pitch:[{param:n.frequency,ratio:1}]}}buildCrackle(t,e){const i=t.createBufferSource();i.buffer=this.whiteNoise(t),i.loop=!0;const n=t.createBiquadFilter();n.type="bandpass",n.Q.value=1.2;const s=t.createGain();s.gain.value=0;const r=t.createBufferSource();r.buffer=this.crackleEnvelope(t),r.loop=!0;const o=t.createGain();return o.gain.value=0,r.connect(o).connect(s.gain),i.connect(n).connect(s).connect(this.output(t)),i.start(),r.start(),{key:e,nodes:[n,s,o],sources:[i,r],volumeParam:o.gain,gainScale:.9,pitch:[{param:n.frequency,ratio:4}]}}async buildRecordedVoice(t,e,i){const n=this.context;if(!n)return;let s;try{s=await this.getBuffer(t)}catch(c){console.warn("SightingAudio: the recorded sound failed to load, staying silent:",c);return}if(i!==this.voiceToken||!this.context)return;const r=n.createBufferSource();r.buffer=s,r.loop=!0;const o=n.createGain();o.gain.value=0,r.connect(o).connect(this.output(n)),r.start(),this.voice={key:e,nodes:[o],sources:[r],volumeParam:o.gain,gainScale:1,pitch:[]},this.requested&&this.applyTo(this.voice,this.requested)}async getBuffer(t){const e=this.context;if(!e)throw new Error("SightingAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(t);return i||(i=fetch(t).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${t}`);return n.arrayBuffer()}).then(n=>e.decodeAudioData(n)),this.buffers.set(t,i)),i}whiteNoise(t){if(!this.noiseBuffer){const e=t.createBuffer(1,Math.floor(t.sampleRate*hg),t.sampleRate),i=e.getChannelData(0);for(let n=0;n<i.length;n++)i[n]=Math.random()*2-1;this.noiseBuffer=e}return this.noiseBuffer}brownNoise(t){const e=t.createBuffer(1,Math.floor(t.sampleRate*hg),t.sampleRate),i=e.getChannelData(0);let n=0,s=0;for(let r=0;r<i.length;r++)n=(n+.02*(Math.random()*2-1))/1.02,i[r]=n,s=Math.max(s,Math.abs(n));if(s>0)for(let r=0;r<i.length;r++)i[r]/=s;return e}crackleEnvelope(t){if(!this.crackleBuffer){const e=t.createBuffer(1,Math.floor(t.sampleRate*ug),t.sampleRate),i=e.getChannelData(0),n=Math.max(1,Math.floor(ib*t.sampleRate)),s=Math.round(ug*eb);for(let r=0;r<s;r++){const o=Math.floor(Math.random()*i.length),c=.4+Math.random()*.6;for(let l=0;l<n&&o+l<i.length;l++)i[o+l]=Math.max(i[o+l],c*(1-l/n))}this.crackleBuffer=e}return this.crackleBuffer}stopVoice(){const t=this.voice,e=this.context;if(this.voice=void 0,!t||!e)return;const i=e.currentTime;t.volumeParam.cancelScheduledValues(i),t.volumeParam.setTargetAtTime(0,i,lg/3);const n=i+lg;for(const s of t.sources){s.onended=()=>{s.disconnect();for(const r of t.nodes)r.disconnect()};try{s.stop(n)}catch{s.disconnect();for(const r of t.nodes)r.disconnect()}}}}function Wc(a){return[...a].sort((t,e)=>t.t-e.t)}function Md(a,t){let e;for(const i of Wc(a)){if(i.t>t)break;e=i}return e}const yd=Math.PI/180,Ll=180/Math.PI;class rr{constructor(t,e,i){this.kind=t,this.canvasHeightPx=e,this.fovDeg=i;const n=i*yd/2;this.focalPx=t==="equidistant"?e/2/n:e/2/Math.tan(n)}focalPx;static of(t,e,i){return new rr(t.projection,e,i)}degToPx(t){const e=t*yd;return this.kind==="equidistant"?this.focalPx*e:2*this.focalPx*Math.tan(e/2)}pxToDeg(t){return this.kind==="equidistant"?t/this.focalPx*Ll:2*Math.atan(t/(2*this.focalPx))*Ll}angleDegToRadiusPx(t){const e=t*yd;return this.kind==="equidistant"?this.focalPx*e:this.focalPx*Math.tan(e)}halfWidthAngleDeg(t){return this.radiusPxToAngleDeg(this.canvasHeightPx*t/2)}radiusPxToAngleDeg(t){return this.kind==="equidistant"?t/this.focalPx*Ll:Math.atan(t/this.focalPx)*Ll}ofBounds(t){return{widthDeg:this.pxToDeg(t.width),heightDeg:this.pxToDeg(t.height)}}toBoundsSize(t){return{width:this.degToPx(t.widthDeg),height:this.degToPx(t.heightDeg)}}widthPx(t){return this.degToPx(Fe.angularWidthDeg(t))}}class xn{static fovOf(t,e){return Ze(t,e)?.fovDeg??bi.fieldOfViewDeg(t.instrument)}static toAngular(t){this.eachKeyframe(t,(e,i)=>({...e,angular:i.ofBounds(e.bounds)}))}static toBounds(t){this.eachKeyframe(t,(e,i)=>{if(!e.angular)return e;const{width:n,height:s}=i.toBoundsSize(e.angular),r={x:e.bounds.x+(e.bounds.width-n)/2,y:e.bounds.y+(e.bounds.height-s)/2,width:n,height:s};if(e.kind!=="polygon")return{...e,bounds:r};const o=e.bounds.width===0?1:n/e.bounds.width,c=e.bounds.height===0?1:s/e.bounds.height;return{...e,bounds:r,points:e.points.map(l=>({x:l.x*o,y:l.y*c}))}})}static toAim(t){this.eachKeyframe(t,(e,i,n)=>{const s=e.aim&&this.positionOf(t,e.aim,e.bounds,i,n);if(s&&Math.abs(s.x-e.bounds.x)<xn.UNMOVED_PX&&Math.abs(s.y-e.bounds.y)<xn.UNMOVED_PX)return e;const r=this.aimFrom(t,i,n,e.bounds);return r?{...e,aim:r}:e})}static UNMOVED_PX=.01;static aimOf(t,e,i){const n=rr.of(t.instrument,Fe.CANVAS_HEIGHT_PX,this.fovOf(t,e));return this.aimFrom(t,n,Ze(t,e),i)}static aimFrom(t,e,i,n){if(i?.headingDeg===void 0)return;const s=this.frameCentre(t),r=e.radiusPxToAngleDeg(n.x+n.width/2-s.x),o=e.radiusPxToAngleDeg(s.y-(n.y+n.height/2));return{azimuthDeg:((i.headingDeg+r)%360+360)%360,altitudeDeg:i.pitchDeg+o}}static toPosition(t){this.eachKeyframe(t,(e,i,n)=>{const s=e.aim&&this.positionOf(t,e.aim,e.bounds,i,n);return s?{...e,bounds:{...e.bounds,...s}}:e})}static positionOf(t,e,i,n,s){if(s?.headingDeg===void 0)return;const r=this.frameCentre(t),o=this.shortestArc(e.azimuthDeg-s.headingDeg),c=e.altitudeDeg-s.pitchDeg;return{x:r.x+this.offAxisPx(n,o)-i.width/2,y:r.y-this.offAxisPx(n,c)-i.height/2}}static frameCentre(t){return{x:bi.frameWidthPx(t.instrument,Fe.CANVAS_HEIGHT_PX)/2,y:Fe.CANVAS_HEIGHT_PX/2}}static shortestArc(t){return(t%360+540)%360-180}static offAxisPx(t,e){return Math.abs(e)>=xn.OFF_CANVAS_DEG?Math.sign(e)*xn.OFF_CANVAS_PX:t.angleDegToRadiusPx(e)}static OFF_CANVAS_DEG=89;static OFF_CANVAS_PX=1e5;static reproject(t,e,i){const n=bi.frameWidthPx(e,Fe.CANVAS_HEIGHT_PX)/2,s=bi.frameWidthPx(t.instrument,Fe.CANVAS_HEIGHT_PX)/2,r=Fe.CANVAS_HEIGHT_PX/2;for(const o of[...t.timeline.allKeyframes]){const c=this.fovOf(t,o.t),l=i?.get(o.t)??c,h=rr.of(e,Fe.CANVAS_HEIGHT_PX,l),u=rr.of(t.instrument,Fe.CANVAS_HEIGHT_PX,c);t.timeline.addKeyframe(o.t,o.shapes.map(d=>{const{bounds:f}=d.shape,p=f.x+f.width/2-n,v=f.y+f.height/2-r,m=Math.hypot(p,v),g=m===0?1:u.angleDegToRadiusPx(h.radiusPxToAngleDeg(m))/m,b={...f,x:s+p*g-f.width/2,y:r+v*g-f.height/2};return{...d,shape:{...d.shape,bounds:b}}}))}this.toBounds(t)}static eachKeyframe(t,e){const{timeline:i}=t;for(const n of[...i.allKeyframes]){const s=Ze(t,n.t),r=this.fovOf(t,n.t),o=rr.of(t.instrument,Fe.CANVAS_HEIGHT_PX,r);i.addKeyframe(n.t,n.shapes.map(c=>({...c,shape:e(c.shape,o,s)})))}}}function sb(a){return hn.restore(rb(a),a.provenance)}function rb(a){return xn.toAngular(a),xn.toAim(a),{version:1,id:a.id,time:a.event.time,endTime:a.event.endTime,durationSeconds:a.event.durationSeconds,durationText:a.event.durationText,utcOffsetHours:a.event.utcOffsetHours,timeZone:a.event.timeZone,place:a.event.place,observer:a.observer,account:a.account,sources:a.sources?.length?a.sources:void 0,sway:a.sway,vehicle:a.vehicle,description:a.event.description,tags:a.event.tags,timeline:a.timeline.toJSON(),observerTrack:a.observerTrack.toJSON(),weatherTrack:a.weatherTrack.toJSON(),soundTrack:a.soundTrack.toJSON(),weather:a.weather,decor:a.decor,milestones:a.milestones.length>0?a.milestones:void 0,references:a.references.length>0?a.references:void 0,roads:a.roads.length>0?a.roads:void 0,traces:a.traces.length>0?a.traces:void 0,weatherSource:a.weatherSource,instrument:a.instrumentId,exposureSeconds:a.exposureSeconds,iso:a.iso,lightPollution:a.lightPollution,observerMap:a.observerMap,interpretation:a.interpretation}}function ab(a){const{recording:t,provenance:e}=hn.strip(a),i=ob(t);return i.provenance=e,i}function ob(a){const t=[],e=new td({eventType:"sighting",time:a.time,endTime:a.endTime,durationSeconds:a.durationSeconds,durationText:a.durationText,utcOffsetHours:a.utcOffsetHours,timeZone:a.timeZone,place:a.place,description:a.description,tags:a.tags},Ku.fromJSON(a.timeline,t),a.observerTrack?el.fromJSON(a.observerTrack):new el,a.weatherTrack?il.fromJSON(a.weatherTrack):new il,a.soundTrack?nl.fromJSON(a.soundTrack):new nl,a.observer&&{id:a.observer.id,title:a.observer.title,lastName:a.observer.lastName,firstNames:a.observer.firstNames},a.id,a.weather,a.decor??[],a.weatherSource,a.instrument,a.exposureSeconds??a.observerTrack?.keyframes.map(i=>i.pose.exposureSeconds).find(i=>i!==void 0),Wc(a.milestones??[]),a.references??[],a.roads??[],a.traces??[]);return e.account=a.account,e.sources=a.sources,e.sway=a.sway,e.iso=a.iso,e.lightPollution=a.lightPollution,e.observerMap=a.observerMap,e.vehicle=a.vehicle,e.interpretation=a.interpretation,e.loadIssues=t,xn.toBounds(e),xn.toPosition(e),e}class Zo{static EN={"unknown-key":"{path}: unknown key, ignored","wrong-type":"{path}: expected {expected}, found {found}","not-in-list":"{path}: {found} is not one of {expected}",defaulted:"{path}: missing, {expected} used",unplaced:"{path}: no aim (and no bounds), drawn at the middle of the view",unsized:"{path}: no angular size (and no bounds), drawn one pixel wide","pixels-over-angles":"{path}: bounds restated without aim or angular, so the shape follows the pixels"};static text(t,e=Zo.EN){return e[t.kind].replace("{path}",t.path).replace("{expected}",t.expected??"").replace("{found}",t.found??"")}static warn(t,e){if(t.length===0)return;const i=t.map(n=>` ${Zo.text(n)}`);console.warn(`UFO@home: ${t.length} problem(s) in ${e??"this recording"}:
2181
2181
  ${i.join(`
2182
2182
  `)}`)}}class ts{constructor(t){this.format=t}issues(t){const e=[];return this.object(t,this.format,"",e),e}object(t,e,i,n){if(!ts.isObject(t)){n.push({kind:"wrong-type",path:i||"(the file)",expected:"object",found:ts.typeOf(t)});return}for(const[s,r]of Object.entries(t)){const o=i?`${i}.${s}`:s,c=e[s];c?this.field(r,c,o,n):n.push({kind:"unknown-key",path:o})}}field(t,e,i,n){if(ts.isStated(t)){this.field(t.value,e,i,n);return}if(!(e.loose||t===void 0||t===null))switch(e.type){case"enum":(typeof t!="string"||!e.values?.includes(t))&&n.push({kind:"not-in-list",path:i,expected:(e.values??[]).map(s=>`"${s}"`).join(", "),found:JSON.stringify(t)});return;case"object":e.fields?this.object(t,e.fields,i,n):ts.isObject(t)||n.push({kind:"wrong-type",path:i,expected:"object",found:ts.typeOf(t)});return;case"array":Array.isArray(t)?e.fields&&t.forEach((s,r)=>{const o=ts.isStated(s)?s.value:s;this.object(o,e.fields,`${i}.${r}`,n)}):n.push({kind:"wrong-type",path:i,expected:"array",found:ts.typeOf(t)});return;default:typeof t!==e.type&&n.push({kind:"wrong-type",path:i,expected:e.type,found:ts.typeOf(t)})}}static isObject(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}static isStated(t){return ts.isObject(t)&&"value"in t&&Object.keys(t).every(e=>e==="value"||e==="basis"||e==="rationale")}static typeOf(t){return Array.isArray(t)?"array":t===null?"null":typeof t}}class as{static PIXELS_PER_INSTANT=2;static INSTANTS_PER_FLASH=2;static MAX_INSTANTS=512;static windowEndingAt(t,e){const i=Number.isFinite(e)?Math.max(0,e):0,n=Math.max(0,t-i*1e3),s=Math.max(0,t-n);return{fromMs:n,toMs:t,ms:s,seconds:s/1e3}}static instants(t,e,i,n,s){if(!(n>0))return 1;const r=s>0?as.travelDegOver(t,e,i,i+n*1e3)/s/as.PIXELS_PER_INSTANT:0,o=as.flashesOver(t,n)*as.INSTANTS_PER_FLASH,c=Math.ceil(Math.max(r,o));return c<2?1:Math.min(as.MAX_INSTANTS,c)}static travelDegOver(t,e,i,n){let s=0;for(const r of t){if(!r.track||r.track.length<2)continue;const o=as.directionAt(r,e,i),c=as.directionAt(r,e,n),l=Math.min(1,Math.max(-1,o.x*c.x+o.y*c.y+o.z*c.z));s=Math.max(s,Math.acos(l)*180/Math.PI)}return s}static flashesOver(t,e){let i=0;for(const n of t)for(const s of n.lights??[])s.pattern.kind==="flash"&&(i=Math.max(i,s.pattern.perMinute));return i/60*e}static directionAt(t,e,i){const n=Hr(t,i),s=n.eastM,r=n.altitudeM-e,o=n.northM,c=Math.hypot(s,r,o);return c===0?{x:0,y:1,z:0}:{x:s/c,y:r/c,z:o/c}}}const Ap=["en","fr","es","it"],cb={en:()=>je(()=>Promise.resolve().then(()=>fb),void 0,import.meta.url).then(a=>a.ufoMessages_en),fr:()=>je(()=>import("./UfoMessages_fr-bJNAf-AU.js"),[],import.meta.url).then(a=>a.ufoMessages_fr),es:()=>je(()=>import("./UfoMessages_es-LFW_B5H2.js"),[],import.meta.url).then(a=>a.ufoMessages_es),it:()=>je(()=>import("./UfoMessages_it-B-jnc4M-.js"),[],import.meta.url).then(a=>a.ufoMessages_it)};function lb(a){return cb[a]()}const hb={en:()=>je(()=>Promise.resolve().then(()=>eI),void 0,import.meta.url).then(a=>a.sightingMessages_en),fr:()=>je(()=>import("./SightingMessages_fr-BC_g9MLr.js"),[],import.meta.url).then(a=>a.sightingMessages_fr),es:()=>je(()=>import("./SightingMessages_es-B5pZonER.js"),[],import.meta.url).then(a=>a.sightingMessages_es),it:()=>je(()=>import("./SightingMessages_it-CJRrig_B.js"),[],import.meta.url).then(a=>a.sightingMessages_it)};function ub(a){return hb[a]()}function db(a){switch(a){case"fr":return je(()=>import("./TagNames_fr-Dnqq6HQ5.js"),[],import.meta.url).then(t=>t.tagNames_fr);case"es":return je(()=>import("./TagNames_es-BfnMpc3D.js"),[],import.meta.url).then(t=>t.tagNames_es);case"it":return je(()=>import("./TagNames_it-n6E4EGYO.js"),[],import.meta.url).then(t=>t.tagNames_it);default:return Promise.resolve({})}}function bM(a){switch(a){case"fr":return je(()=>import("./SceneNames_fr-BFN6x9Z7.js"),[],import.meta.url).then(t=>t.sceneNames_fr);case"es":return je(()=>import("./SceneNames_es-BuZsPlTw.js"),[],import.meta.url).then(t=>t.sceneNames_es);case"it":return je(()=>import("./SceneNames_it-BOuH3VIw.js"),[],import.meta.url).then(t=>t.sceneNames_it);default:return Promise.resolve(void 0)}}const SM={play:"Play",pause:"Pause",noDuration:"No observation duration",currentPosition:"Current position",duration:"Duration",switchToElapsed:"click to show elapsed time",switchToClockTime:"click to show the time of day",fullscreen:"Fullscreen",exitFullscreen:"Exit fullscreen",mute:"Mute",unmute:"Unmute",noSound:"No sound recorded",moments:"Moments",moreControls:"More controls",fewerControls:"Fewer controls",showObserverMap:"Show where the observer was",hideObserverMap:"Hide where the observer was",mapImageryUnavailable:"Aerial imagery unavailable",zoomMapIn:"Zoom in",zoomMapOut:"Zoom out",fitMap:"Back to the whole path",placeObserverHere:"Put the observer here",showReferences:"Show the pictures of the place",hideReferences:"Hide the pictures of the place",showTraces:"Show the investigator's lines",hideTraces:"Hide the investigator's lines",referenceOpacity:"Picture opacity",referencesMenu:"Pictures of the place",showMilestones:"Show the account's moments",hideMilestones:"Hide the account's moments",observerHere:"The observer, here",decorHere:"Scenery",recordingIssues:"{count} problem(s) in this recording: it may not play as its author meant",issueTemplates:Zo.EN},fb=Object.freeze(Object.defineProperty({__proto__:null,ufoMessages_en:SM},Symbol.toStringTag,{value:"Module"})),wM=Math.PI/180,pb=180/Math.PI,mb=256,_M=19,gb=1.25;function EM(a,t){return 156543.03392*Math.cos(a*wM)/2**t}function AM(a,t){return EM(a,t)*mb}function vb(a,t){let e=0;for(;e<_M&&AM(a,e+1)>=t;)e++;return e}function TM(a,t){return AM(a,t)}function Mb(a,t){const e=t*gb;let i=0;for(;i<_M&&EM(a,i)>e;)i++;return i}function Bh(a){const t=a*wM;return(1-Math.log(Math.tan(t)+1/Math.cos(t))/Math.PI)/2}function RM(a,t,e){const i=2**e;return{x:(a+180)/360*i,y:Bh(t)*i}}function DM(a,t,e){const i=Bh(a.north),n=Bh(a.south);return{x:(t-a.west)/(a.east-a.west),y:(Bh(e)-i)/(n-i)}}function yb(a,t,e){const{x:i,y:n}=RM(a,t,e);return{x:Math.floor(i),y:Math.floor(n),z:e}}function xb(a){const t=2**a.z,e=a.x/t*360-180,i=(a.x+1)/t*360-180,n=dg(a.y,t);return{south:dg(a.y+1,t),north:n,west:e,east:i}}function dg(a,t){const e=a/t;return Math.atan(Math.sinh(Math.PI*(1-2*e)))*pb}function IM(a,t,e,i){const n=yb(a,t,e),s=Math.floor(i/2),r=[];for(let l=-s;l<=s;l++)for(let h=-s;h<=s;h++)r.push({x:n.x+h,y:n.y+l,z:e});const o=r.map(xb),c={south:Math.min(...o.map(l=>l.south)),north:Math.max(...o.map(l=>l.north)),west:Math.min(...o.map(l=>l.west)),east:Math.max(...o.map(l=>l.east))};return{tiles:r,bounds:c}}const bb="#2ec4ff";class la{constructor(t){this.ctx=t}static SCALE_STEPS_M=[5e3,2e3,1e3,500,200,100,50,20,10,5];static MARKER_RADIUS_PX=8.5;static ON_MARKER_M=3;targets=[];hitTest(t,e){let i,n=1/0;for(const s of this.targets){const r=Math.hypot(s.x-t,s.y-e);r>s.radius||r>n||(i=s,n=r)}return i}get width(){return this.ctx.canvas.width}get height(){return this.ctx.canvas.height}paint(t){const{ctx:e}=this;e.save(),this.targets=[],e.clearRect(0,0,this.width,this.height),this.paintGround(t),this.paintNight(t.nightFraction),this.paintPath(t),this.paintTraces(t),t.position?(this.paintCone(t,t.position),this.paintDecor(t),this.paintMarkers(t),this.paintObserver(t,t.position)):(this.paintDecor(t),this.paintMarkers(t)),this.paintNorth(),this.paintFooter(t.bounds,t.attribution),e.restore()}toCanvas(t,e,i){const n=DM(t,i,e);return{x:n.x*this.width,y:n.y*this.height}}paintGround(t){const{ctx:e}=this;e.fillStyle="#1d2321",e.fillRect(0,0,this.width,this.height);const i=t.imagery;if(!i)return;const n=this.toCanvas(t.bounds,i.bounds.north,i.bounds.west),s=this.toCanvas(t.bounds,i.bounds.south,i.bounds.east);e.drawImage(i.source,n.x,n.y,s.x-n.x,s.y-n.y)}paintNight(t=0){if(t<=0)return;const{ctx:e}=this;e.save(),e.fillStyle=`rgba(6, 12, 30, ${Math.min(t,1)*.78})`,e.fillRect(0,0,this.width,this.height),e.restore()}paintDecor(t){const{ctx:e}=this;for(const i of t.decor){const n=this.toCanvas(t.bounds,i.lat,i.lng);if(i.label&&this.targets.push({kind:"decor",label:i.label,lat:i.lat,lng:i.lng,x:n.x,y:n.y,radius:7}),e.beginPath(),e.rect(n.x-3.5,n.y-3.5,7,7),e.fillStyle="rgba(120, 220, 255, 0.85)",e.fill(),e.lineWidth=1.5,e.strokeStyle="rgba(0, 0, 0, 0.7)",e.stroke(),i.headingDeg===void 0)continue;const s=(i.headingDeg-90)*Math.PI/180;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(n.x+Math.cos(s)*10,n.y+Math.sin(s)*10),e.lineWidth=3,e.strokeStyle="rgba(0, 0, 0, 0.6)",e.stroke(),e.lineWidth=1.5,e.strokeStyle="rgba(120, 220, 255, 0.9)",e.stroke()}}paintPath(t){if(!t.path.moved)return;const{ctx:e}=this,i=t.path.points.map(n=>this.toCanvas(t.bounds,n.lat,n.lng));e.beginPath(),e.moveTo(i[0].x,i[0].y);for(const n of i.slice(1))e.lineTo(n.x,n.y);e.lineJoin="round",e.lineCap="round",e.strokeStyle="rgba(0, 0, 0, 0.65)",e.lineWidth=5,e.stroke(),e.strokeStyle="rgba(255, 255, 255, 0.9)",e.lineWidth=2,e.stroke()}paintTraces(t){const{ctx:e}=this;for(const i of t.traces??[]){const n=i.points.map(r=>this.toCanvas(t.bounds,r.lat,r.lng));if(n.length===0)continue;const s=i.color??bb;if(i.kind==="point")e.beginPath(),e.moveTo(n[0].x,n[0].y-6),e.lineTo(n[0].x+6,n[0].y),e.lineTo(n[0].x,n[0].y+6),e.lineTo(n[0].x-6,n[0].y),e.closePath(),e.fillStyle=s,e.fill(),e.lineWidth=1.5,e.strokeStyle="rgba(0, 0, 0, 0.8)",e.stroke();else{e.beginPath(),e.moveTo(n[0].x,n[0].y);for(const r of n.slice(1))e.lineTo(r.x,r.y);i.kind==="polygon"&&e.closePath(),e.lineJoin="round",e.setLineDash([]),e.strokeStyle="rgba(0, 0, 0, 0.65)",e.lineWidth=4.5,e.stroke(),e.setLineDash([9,5]),e.strokeStyle=s,e.lineWidth=2.5,e.stroke(),e.setLineDash([])}if(i.label){e.font="11px sans-serif",e.textAlign="left",e.textBaseline="middle";let r=n[0];if(i.kind==="line"&&t.position){const o=this.toCanvas(t.bounds,t.position.lat,t.position.lng);r=n.reduce((c,l)=>Math.hypot(l.x-o.x,l.y-o.y)>Math.hypot(c.x-o.x,c.y-o.y)?l:c)}this.paintOutlinedText(i.label,r.x+9,r.y-9)}}}paintCone(t,e){const{headingDeg:i,coneHalfAngleDeg:n}=t;if(i===void 0||n===void 0)return;const{ctx:s}=this,r=this.toCanvas(t.bounds,e.lat,e.lng),o=Math.hypot(this.width,this.height),c=(i-90)*Math.PI/180,l=n*Math.PI/180;s.save(),s.beginPath(),s.moveTo(r.x,r.y),s.arc(r.x,r.y,o,c-l,c+l),s.closePath();const h=s.createRadialGradient(r.x,r.y,0,r.x,r.y,o);h.addColorStop(0,"rgba(255, 224, 130, 0.55)"),h.addColorStop(.35,"rgba(255, 224, 130, 0.22)"),h.addColorStop(1,"rgba(255, 224, 130, 0)"),s.fillStyle=h,s.fill(),s.restore()}paintMarkers(t){const{ctx:e}=this;e.textAlign="center",e.textBaseline="middle",e.font="bold 10px sans-serif";for(const i of[...t.markers].sort((n,s)=>Number(n.current)-Number(s.current))){const n=this.toCanvas(t.bounds,i.lat,i.lng);this.targets.push({kind:"milestone",label:i.note?`${i.label} — ${i.note}`:i.label,lat:i.lat,lng:i.lng,t:i.t,x:n.x,y:n.y,radius:la.MARKER_RADIUS_PX}),e.beginPath(),e.arc(n.x,n.y,la.MARKER_RADIUS_PX,0,Math.PI*2),e.fillStyle=i.current?"rgba(255, 224, 130, 0.95)":"rgba(0, 0, 0, 0.55)",e.fill(),e.lineWidth=2,e.strokeStyle="rgba(255, 255, 255, 0.9)",e.stroke(),e.fillStyle=i.current?"#1d2321":"#fff",e.fillText(i.label,n.x,n.y)}}paintObserver(t,e){const{ctx:i}=this,n=this.toCanvas(t.bounds,e.lat,e.lng);t.observerLabel&&this.targets.push({kind:"observer",label:t.observerLabel,lat:e.lat,lng:e.lng,x:n.x,y:n.y,radius:8});const s=t.markers.some(r=>{if(!r.current)return!1;const o=si(r.lat,r.lng,e.lat,e.lng);return Math.hypot(o.x,o.z)<=la.ON_MARKER_M});i.beginPath(),i.arc(n.x,n.y,s?la.MARKER_RADIUS_PX+2.5:5.5,0,Math.PI*2),s||(i.fillStyle="#ff5a3c",i.fill()),i.lineWidth=4,i.strokeStyle="rgba(0, 0, 0, 0.5)",i.stroke(),i.lineWidth=s?3:2.5,i.strokeStyle=s?"#ff5a3c":"#fff",i.stroke()}paintNorth(){const{ctx:t}=this,e=this.width-14,i=16;t.beginPath(),t.moveTo(e,i-9),t.lineTo(e-4.5,i+5),t.lineTo(e,i+2),t.lineTo(e+4.5,i+5),t.closePath(),t.fillStyle="rgba(255, 255, 255, 0.92)",t.strokeStyle="rgba(0, 0, 0, 0.6)",t.lineWidth=1,t.fill(),t.stroke(),t.font="bold 9px sans-serif",t.textAlign="center",t.textBaseline="top",t.strokeText("N",e,i+6),t.fillText("N",e,i+6)}paintFooter(t,e){const{ctx:i}=this;i.font="9px sans-serif",i.textBaseline="bottom";const n=e?this.wrap(e,this.width-20):[];let s=this.height-4;i.textAlign="right";for(const f of n.slice().reverse())this.paintOutlinedText(f,this.width-6,s),s-=11;const r=(t.south+t.north)/2,c=Math.abs(si(r,t.east,r,t.west).x)/this.width,l=la.SCALE_STEPS_M.find(f=>f/c<=this.width/3);if(l===void 0)return;const h=l/c,u=8,d=s-3;i.lineWidth=3,i.strokeStyle="rgba(0, 0, 0, 0.6)",i.beginPath(),i.moveTo(u,d),i.lineTo(u+h,d),i.stroke(),i.lineWidth=1.5,i.strokeStyle="rgba(255, 255, 255, 0.95)",i.stroke(),i.textAlign="left",this.paintOutlinedText(l>=1e3?`${l/1e3} km`:`${l} m`,u,d-3)}paintOutlinedText(t,e,i){const{ctx:n}=this;n.lineWidth=3,n.strokeStyle="rgba(0, 0, 0, 0.75)",n.strokeText(t,e,i),n.fillStyle="#fff",n.fillText(t,e,i)}wrap(t,e){const i=[];let n="";for(const s of t.split(" ")){const r=n?`${n} ${s}`:s;n&&this.ctx.measureText(r).width>e?(i.push(n),n=s):n=r}return n&&i.push(n),i}}class ni{static MIN_ZOOM=.25;static MAX_ZOOM=64;zoom=1;centerX=.5;centerY=.5;get changed(){return this.zoom!==1||this.centerX!==.5||this.centerY!==.5}get zoomFactor(){return this.zoom}reset(){this.zoom=1,this.centerX=.5,this.centerY=.5}zoomAt(t,e,i){const n=Math.min(ni.MAX_ZOOM,Math.max(ni.MIN_ZOOM,this.zoom*i)),s=this.centerX+(t-.5)/this.zoom,r=this.centerY+(e-.5)/this.zoom;this.centerX=s-(t-.5)/n,this.centerY=r-(e-.5)/n,this.zoom=n}panBy(t,e){this.centerX-=t/this.zoom,this.centerY-=e/this.zoom}refit(t,e){if(!this.changed)return;const i=this.boundsWithin(t),n=ni.mercatorY01(e.north),s=ni.mercatorY01(e.south),r=ni.mercatorY01(i.north),o=ni.mercatorY01(i.south);this.zoom=(e.east-e.west)/(i.east-i.west),this.centerX=((i.west+i.east)/2-e.west)/(e.east-e.west),this.centerY=((r+o)/2-n)/(s-n)}keepInView(t,e,i){if(!this.changed)return!1;const n=this.boundsWithin(t),s=ni.mercatorY01(n.north),r=ni.mercatorY01(n.south),o=(e.lng-n.west)/(n.east-n.west),c=(ni.mercatorY01(e.lat)-s)/(r-s);return o>=i&&o<=1-i&&c>=i&&c<=1-i?!1:(this.panBy(.5-o,.5-c),!0)}boundsWithin(t){if(!this.changed)return t;const e=.5/this.zoom,i=ni.mercatorY01(t.north),n=ni.mercatorY01(t.south),s=t.east-t.west;return{west:t.west+(this.centerX-e)*s,east:t.west+(this.centerX+e)*s,north:ni.latitudeAt(i+(this.centerY-e)*(n-i)),south:ni.latitudeAt(i+(this.centerY+e)*(n-i))}}static including(t,e,i=3){const n=(t.north+t.south)/2,s=(t.east+t.west)/2,r=si(n,t.east,n,s).x;let o=r;for(const c of e){const{x:l,z:h}=si(c.lat,c.lng,n,s),u=Math.max(Math.abs(l),Math.abs(h));u<=r*i&&(o=Math.max(o,u*1.15))}return o<=r?t:{north:Nn(0,-o,n,s).lat,south:Nn(0,o,n,s).lat,east:Nn(o,0,n,s).lng,west:Nn(-o,0,n,s).lng}}static expand(t,e){const i=t.east-t.west,n=t.north-t.south;return{west:t.west-i*e,east:t.east+i*e,south:t.south-n*e,north:t.north+n*e}}static pointAt(t,e,i){const n=ni.mercatorY01(t.north),s=ni.mercatorY01(t.south);return{lat:ni.latitudeAt(n+i*(s-n)),lng:t.west+e*(t.east-t.west)}}static mercatorY01(t){const e=t*Math.PI/180;return(1-Math.log(Math.tan(e)+1/Math.cos(e))/Math.PI)/2}static latitudeAt(t){return Math.atan(Math.sinh(Math.PI*(1-2*t)))*180/Math.PI}}const Un=256,fg=3,Sb=32768;class wb{fetchImpl;tileUrlTemplate;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=t.tileUrlTemplate??"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"}async getElevationGrid(t,e){const i=(t.south+t.north)/2,n=(t.west+t.east)/2,s=Math.abs(si(i,t.east,i,t.west).x),r=Math.abs(si(t.north,n,t.south,n).z),o=vb(i,Math.max(s,r)),{tiles:c}=IM(n,i,o,fg),l=fg*Un,h=new Float32Array(l*l),u=c[0];await Promise.all(c.map(f=>this.decodeTileInto(f,u,h,l)));const d=new Float32Array(e.width*e.height);for(let f=0;f<e.height;f++){const p=t.north+(t.south-t.north)*(f/(e.height-1));for(let v=0;v<e.width;v++){const m=t.west+(t.east-t.west)*(v/(e.width-1));d[f*e.width+v]=this.sampleAt(p,m,o,u,h,l)}}return{heights:d,width:e.width,height:e.height,bounds:t}}async decodeTileInto(t,e,i,n){const s=this.tileUrlTemplate.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y)),r=await this.fetchImpl(s);if(!r.ok)throw new Error(`Elevation tile fetch failed (${r.status}): ${s}`);const o=await createImageBitmap(await r.blob()),c=document.createElement("canvas");c.width=Un,c.height=Un;const l=c.getContext("2d");if(!l)throw new Error("2D canvas context unavailable");l.drawImage(o,0,0);const{data:h}=l.getImageData(0,0,Un,Un),u=(t.x-e.x)*Un,d=(t.y-e.y)*Un;for(let f=0;f<Un;f++)for(let p=0;p<Un;p++){const v=(f*Un+p)*4,m=h[v]*256+h[v+1]+h[v+2]/256-Sb,g=u+p,b=d+f;i[b*n+g]=m}}sampleAt(t,e,i,n,s,r){const{x:o,y:c}=RM(e,t,i),l=(o-n.x)*Un,h=(c-n.y)*Un,u=Math.max(0,Math.min(r-1,Math.floor(l))),d=Math.max(0,Math.min(r-1,Math.floor(h))),f=Math.min(r-1,u+1),p=Math.min(r-1,d+1),v=l-u,m=h-d,g=s[d*r+u],b=s[d*r+f],S=s[p*r+u],M=s[p*r+f],x=g+(b-g)*v,_=S+(M-S)*v;return x+(_-x)*m}}const Hh=256,_b=5;async function Eb(a,t,e,i){const n=(a.south+a.north)/2,s=(a.west+a.east)/2,r=Math.abs(si(n,a.east,n,a.west).x),o=Math.abs(si(a.north,s,a.south,s).z),c=Math.max(r,o),{zoom:l,gridSize:h}=Ab(n,c,Math.max(t.width,t.height)),{tiles:u,bounds:d}=IM(s,n,l,h),f=h*Hh,p=document.createElement("canvas");p.width=f,p.height=f;const v=p.getContext("2d");if(!v)throw new Error("2D canvas context unavailable");const m=u[0];await Promise.all(u.map(async M=>{const x=e(M),_=await i(x);if(!_.ok)throw new Error(`Imagery tile fetch failed (${_.status}): ${x}`);const E=await createImageBitmap(await _.blob());v.drawImage(E,(M.x-m.x)*Hh,(M.y-m.y)*Hh)}));const g=Math.min(Math.max(t.width,t.height),f);if(g===f)return{source:p,width:f,height:f,bounds:d};const b=document.createElement("canvas");b.width=g,b.height=g;const S=b.getContext("2d");if(!S)throw new Error("2D canvas context unavailable");return S.drawImage(p,0,0,f,f,0,0,g,g),{source:b,width:g,height:g,bounds:d}}function Ab(a,t,e){let i=Mb(a,t/Math.max(1,e)),n=pg(a,i,t);for(;n>_b&&i>0;)i--,n=pg(a,i,t);return{zoom:i,gridSize:n,mPerPixel:TM(a,i)/Hh}}function pg(a,t,e){const i=Math.ceil(e/2/TM(a,t));return Math.max(3,2*i+1)}class Tb{attribution="Imagery © Esri, Maxar, Earthstar Geographics, and the GIS User Community";fetchImpl;tileUrlTemplate;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.tileUrlTemplate=t.tileUrlTemplate??"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"}async getImageryTexture(t,e){return Eb(t,e,i=>this.tileUrlTemplate.replace("{z}",String(i.z)).replace("{y}",String(i.y)).replace("{x}",String(i.x)),this.fetchImpl)}}class es{attribution="Roads © OpenStreetMap contributors, as surveyed today";contemporary=!0;static DRIVABLE=["motorway","trunk","primary","secondary","tertiary","unclassified","residential","service","track","motorway_link","trunk_link","primary_link","secondary_link","tertiary_link"];static WIDTH_M={motorway:11,trunk:9,primary:8,secondary:7,tertiary:6.5,unclassified:5.5,residential:5.5,service:4,track:3.5};static DEFAULT_WIDTH_M=5;static ENDPOINTS=["https://overpass-api.de/api/interpreter","https://overpass.kumi.systems/api/interpreter","https://overpass.private.coffee/api/interpreter"];fetchImpl;endpoints;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.endpoints=t.endpoints??es.ENDPOINTS}static queue=Promise.resolve();static RETRY_MS=4e3;async getRoads(t){const e=`${t.south},${t.west},${t.north},${t.east}`,i=`[out:json][timeout:30];way["highway"~"^(${es.DRIVABLE.join("|")})$"](${e});out geom;`;return this.waysFrom(await this.queued(()=>this.ask(i)))}waysFrom(t){const e=[];for(const i of t.elements??[]){const n=i.geometry,s=i.tags;!s||!n||n.length<2||e.push({id:`osm-${i.id??e.length}`,name:s.name,surface:es.surfaceOf(s),widthM:es.widthOf(s),points:n.map(r=>({lat:r.lat,lng:r.lon}))})}return e}queued(t){const e=es.queue.then(t,t);return es.queue=e.catch(()=>{}),e}async ask(t){let e;for(const i of this.endpoints)for(let n=0;n<2;n++){try{const s=await this.fetchImpl(`${i}?data=${encodeURIComponent(t)}`);if(s.ok)return await s.json();if(e=new Error(`${new URL(i).host} refused (${s.status})`),s.status!==429&&s.status!==504)break}catch(s){e=new Error(`${new URL(i).host} unreachable (${String(s)})`);break}await new Promise(s=>setTimeout(s,es.RETRY_MS))}throw e??new Error("No Overpass instance answered")}static widthOf(t){const e=Number.parseFloat(t.width??t.est_width??"");if(Number.isFinite(e)&&e>0)return e;const i=Number.parseInt(t.lanes??"",10);return Number.isFinite(i)&&i>0?i*3.5:es.WIDTH_M[t.highway]??es.DEFAULT_WIDTH_M}static surfaceOf(t){const e=t.surface;return e==="dirt"||e==="earth"||e==="mud"?"dirt":e==="gravel"||e==="fine_gravel"||e==="compacted"||e==="ground"||e==="sand"||e==="unpaved"?"gravel":e?"paved":t.highway==="track"?"gravel":"paved"}}const xd="https://ufoathome.org/roads/index.json";class Do{attributionRead;contemporaryRead;fetchImpl;indexUrls;fallback;index;static shared=new Map;sharing;constructor(t={}){this.sharing=!t.fetchImpl,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??Do.defaultIndexUrls(),this.fallback=t.fallback}get attribution(){return this.attributionRead??this.fallback?.attribution??"Roads © OpenStreetMap contributors"}get contemporary(){return this.contemporaryRead??this.fallback?.contemporary??!0}async getRoads(t){const e=await this.held(t);if(e)return e;if(!this.fallback)return[];const i=await this.fallback.getRoads(t);return this.attributionRead=this.fallback.attribution,this.contemporaryRead=this.fallback.contemporary,i}async held(t){let e;try{e=await this.load()}catch{return}const i=e.find(({entry:n})=>n.north>=t.north&&n.south<=t.south&&n.east>=t.east&&n.west<=t.west);if(i)try{const n=await this.fetchImpl(new URL(i.entry.file,i.indexUrl).href);if(!n.ok)return;const s=await n.json();return Array.isArray(s?.ways)?(this.attributionRead=s.attribution,this.contemporaryRead=s.contemporary,s.ways):void 0}catch{return}}load(){if(this.index)return this.index;if(!this.sharing)return this.index=this.fetchFirstAvailable();const t=this.indexUrls.join(`
2183
- `);let e=Do.shared.get(t);return e||(e=this.fetchFirstAvailable(),Do.shared.set(t,e),e.then(i=>{i.length===0&&Do.shared.delete(t)})),this.index=e}async fetchFirstAvailable(){for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(!e.ok)continue;const i=await e.json();if(Array.isArray(i?.entries))return i.entries.map(n=>({entry:n,indexUrl:t}))}catch{}return[]}static defaultIndexUrls(){const t=`?v=${encodeURIComponent("0.105.2")}`,e=typeof location>"u"?void 0:new URL("/roads/index.json",location.href).href;return(e&&e!==xd?[e,xd]:[xd]).map(i=>i+t)}}function Rb(){return{elevation:new wb,imagery:CM(),roads:Db()}}function CM(){return new Tb}function Db(){return new Do({fallback:new es})}const Ib=new Set,ks="show-observer-map",Fs="hide-milestones";class pe extends HTMLElement{static get observedAttributes(){return["src",ks,Fs]}shadow;stageElement;canvas;canvasRenderer;tooltip;toolbar;issuesBox;issuesButton;issuesPanel;playPauseButton;static OBSERVER_MAP_MIN_SPAN_M=400;static OBSERVER_MAP_MARGIN=.6;static OBSERVER_MAP_IMAGERY_PX=768;fullscreenButton;cornerButtons;observerMapButton;referencesButton;tracesButton;tracesShownState=!0;referenceOpacityInput;referencesShownState=!0;accountHidden=!1;referenceViews=new Map;referencesMenu;referenceOpacityTouched=!1;milestonesButton;observerMapPanel;observerMapCanvas;observerMapRenderer;mapZoomInButton;mapZoomOutButton;mapFitButton;observerMapView=new ni;observerMapDrag;suppressObserverMapClick=!1;observerMapImageryTimer;observerPlacing=!1;seekInput;playbackFlash;milestoneMarks;milestoneCaption;timeStartLabel;timeEndLabel;timePill;muteButton;volumeInput;controlsRow;momentsBox;momentsButton;momentsCurrent;momentsMenu;moreButton;controlsRight;seekSegments;seekDot;seekPreview;seekPreviewCanvas;seekPreviewTitle;seekPreviewTime;observerPath;observerMapBounds;observerMapImagery;observerMapImageryBounds;observerMapImageryViewWidth=0;observerMapImageryLoading=!1;observerMapImageryCredit;observerMapImageryFailed=!1;creditShownExternally=!1;lookYawDeg=0;lookPitchDeg=0;milestonesShown=!0;currentSighting=td.create();issues=[];issueCheck=0;sightingAudio=new nb;soundPreview;player;loopEnabled=!1;playbackBeforeClick;highlightedSourceIds=new Set;paintsShapes=!0;steadyObserver=!1;static LIVE_BODY_MAX_RATE=2;get steadyBody(){return this.steadyObserver||this.player.playbackState!=="playing"||this.player.playbackRate>pe.LIVE_BODY_MAX_RATE}selectionShown=!0;overlayPainter;enableClickToPlay=!0;fullscreenTarget;messages=SM;realDurationMs;realStartMs;showClockTime=!0;handleFullscreenChange=()=>{this.updateFullscreenButton(),this.updateMuteButton(),this.resizeObserverMap()};controlsFitObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.fitControls());controlsMutations;fitControls(){const t=this.controlsRow,e=t.classList.contains("more-open"),i=()=>t.scrollWidth>t.clientWidth+1,n=!this.momentsMenu.hidden;if(this.momentsMenu.hidden=!0,t.classList.remove("narrow","more-open","nomoments","compact","tiny"),t.clientWidth>0&&i()){t.classList.add("narrow");for(const s of["nomoments","compact","tiny"]){if(!i())break;t.classList.add(s)}e&&t.classList.add("more-open")}this.momentsMenu.hidden=!n,this.updateMoreButton()}setControlsFolded(t){this.controlsRow.classList.toggle("more-open",!t),this.updateMoreButton()}updateMoreButton(){const t=this.controlsRow.classList.contains("more-open");pe.setIcon(this.moreButton,t?Gt.UNFOLDED:Gt.FOLDED);const e=t?this.messages.fewerControls:this.messages.moreControls;this.moreButton.title=e,this.moreButton.setAttribute("aria-label",e),this.moreButton.setAttribute("aria-expanded",String(t))}addControl(t){this.controlsRight.insertBefore(t,this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null),this.fitControls()}observerMapResizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.resizeObserverMap());resizeObserverMap(){this.observerMapPanel.hidden||(this.sizeObserverMapCanvas(),this.paintObserverMap(this.currentTime))}simulatedFullscreen=!1;styleBeforeSimulatedFullscreen;bodyOverflowBeforeSimulatedFullscreen;handleSimulatedFullscreenKey=t=>{t.key==="Escape"&&this.exitSimulatedFullscreen()};handlePointerMove=t=>{const e=this.canvasPointFromEvent(t),i=e&&this.shapeAt(e.x,e.y),n=this.said.read(i?.shape.title);if(!n){this.tooltip.hidden=!0;return}this.tooltip.textContent=n,this.tooltip.hidden=!1;const s=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${t.clientX-s.left+12}px`,this.tooltip.style.top=`${t.clientY-s.top+12}px`};handleObserverMapPointerMove=t=>{if(this.dragObserverMap(t))return;const e=this.observerMapTargetFrom(t);if(!e){if(!this.observerPlacing){this.tooltip.hidden=!0,this.observerMapCanvas.style.cursor="grab";return}this.observerMapCanvas.style.cursor="crosshair",this.showObserverMapTooltip(t,this.messages.placeObserverHere);return}this.observerMapCanvas.style.cursor="pointer",this.showObserverMapTooltip(t,e.label)};showObserverMapTooltip(t,e){this.tooltip.textContent=e,this.tooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${t.clientX-i.left+12}px`,this.tooltip.style.top=`${t.clientY-i.top+12}px`}handleObserverMapClick=t=>{if(this.suppressObserverMapClick){this.suppressObserverMapClick=!1;return}const e=this.observerMapTargetFrom(t);if(!e){this.observerPlacing&&this.placeObserverFrom(t);return}if(e.kind==="milestone"&&e.t!==void 0){this.player.seek(e.t);return}this.dispatchEvent(new CustomEvent("lookat",{detail:{lat:e.lat,lng:e.lng,kind:e.kind},bubbles:!0,composed:!0}))};observerMapTargetFrom(t){const e=this.observerMapCanvas.getBoundingClientRect();if(!(e.width===0||e.height===0))return this.observerMapRenderer.hitTest((t.clientX-e.left)/e.width*this.observerMapCanvas.width,(t.clientY-e.top)/e.height*this.observerMapCanvas.height)}handlePointerLeave=()=>{this.tooltip.hidden=!0};handleObserverMapPointerDown=t=>{t.button===0&&(this.suppressObserverMapClick=!1,this.observerMapDrag={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,lastX:t.clientX,lastY:t.clientY,moved:!1})};handleObserverMapPointerUp=t=>{const e=this.observerMapDrag;!e||e.pointerId!==t.pointerId||(this.observerMapDrag=void 0,this.observerMapCanvas.classList.remove("dragging"),e.moved&&(this.suppressObserverMapClick=!0,this.paintObserverMap(this.currentTime),this.observerMapCanvas.hasPointerCapture?.(t.pointerId)&&this.observerMapCanvas.releasePointerCapture(t.pointerId)))};dragObserverMap(t){const e=this.observerMapDrag;if(!e||e.pointerId!==t.pointerId)return!1;if(!e.moved){if(Math.hypot(t.clientX-e.startX,t.clientY-e.startY)<pe.OBSERVER_MAP_DRAG_PX)return!1;e.moved=!0,this.tooltip.hidden=!0,this.observerMapCanvas.classList.add("dragging"),this.observerMapCanvas.setPointerCapture?.(t.pointerId)}const i=this.observerMapCanvas.getBoundingClientRect();return i.width>0&&i.height>0&&(this.observerMapView.panBy((t.clientX-e.lastX)/i.width,(t.clientY-e.lastY)/i.height),this.observerMapViewChanged()),e.lastX=t.clientX,e.lastY=t.clientY,!0}static OBSERVER_MAP_DRAG_PX=4;handleObserverMapWheel=t=>{t.preventDefault();const e=this.observerMapCanvas.getBoundingClientRect();if(e.width===0||e.height===0)return;const i=t.deltaMode===0?t.deltaY:t.deltaY*40;this.zoomObserverMap((t.clientX-e.left)/e.width,(t.clientY-e.top)/e.height,Math.exp(-i*.002))};zoomObserverMap(t,e,i){this.observerMapView.zoomAt(t,e,i),this.observerMapViewChanged()}observerMapViewChanged(){this.mapFitButton.hidden=!this.observerMapView.changed,this.mapZoomInButton.disabled=this.observerMapView.zoomFactor>=ni.MAX_ZOOM,this.mapZoomOutButton.disabled=this.observerMapView.zoomFactor<=ni.MIN_ZOOM,this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}scheduleObserverMapImagery(){this.observerMapImageryTimer===void 0&&(this.observerMapImageryTimer=setTimeout(()=>{this.observerMapImageryTimer=void 0,this.loadObserverMapImagery()},pe.OBSERVER_MAP_IMAGERY_DELAY_MS))}static OBSERVER_MAP_FOLLOW_MARGIN=.1;static OBSERVER_MAP_IMAGERY_DELAY_MS=300;get observerMapViewBounds(){return this.observerMapBounds&&this.observerMapView.boundsWithin(this.observerMapBounds)}placeObserverFrom(t){const e=this.observerMapViewBounds,i=this.observerMapCanvas.getBoundingClientRect();if(!e||i.width===0||i.height===0)return;const n=ni.pointAt(e,(t.clientX-i.left)/i.width,(t.clientY-i.top)/i.height);this.dispatchEvent(new CustomEvent("observerplace",{detail:n,bubbles:!0,composed:!0}))}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=`<style>${Kx}</style>${$x}`,this.shadow.appendChild(t.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new al(this.canvas.getContext("2d")),this.tooltip=this.shadow.getElementById("tooltip"),this.toolbar=this.shadow.getElementById("toolbar"),this.issuesBox=this.shadow.getElementById("issues"),this.issuesButton=this.shadow.getElementById("issues-button"),this.issuesPanel=this.shadow.getElementById("issues-panel"),this.issuesButton.addEventListener("click",e=>{e.stopPropagation(),this.issuesPanel.hidden=!this.issuesPanel.hidden,this.issuesButton.setAttribute("aria-expanded",String(!this.issuesPanel.hidden))}),this.playPauseButton=this.shadow.getElementById("play-pause"),this.fullscreenButton=this.shadow.getElementById("fullscreen"),this.cornerButtons=this.shadow.getElementById("corner-buttons"),this.observerMapButton=this.shadow.getElementById("observer-map"),this.referencesButton=this.shadow.getElementById("references"),this.tracesButton=this.shadow.getElementById("traces"),this.referenceOpacityInput=this.shadow.getElementById("reference-opacity"),this.referencesMenu=this.shadow.getElementById("references-menu"),this.milestonesButton=this.shadow.getElementById("milestones"),this.observerMapPanel=this.shadow.getElementById("observer-map-panel"),this.observerMapCanvas=this.shadow.getElementById("observer-map-canvas"),this.observerMapRenderer=new la(this.observerMapCanvas.getContext("2d")),this.mapZoomInButton=this.shadow.getElementById("map-zoom-in"),this.mapZoomOutButton=this.shadow.getElementById("map-zoom-out"),this.mapFitButton=this.shadow.getElementById("map-fit"),this.seekInput=this.shadow.getElementById("seek"),this.playbackFlash=this.shadow.getElementById("playback-flash"),this.milestoneMarks=this.shadow.getElementById("milestone-marks"),this.milestoneCaption=this.shadow.getElementById("milestone-caption"),this.timeStartLabel=this.shadow.getElementById("time-start"),this.timeEndLabel=this.shadow.getElementById("time-end"),this.timePill=this.shadow.getElementById("time"),this.muteButton=this.shadow.getElementById("mute"),this.controlsRight=this.shadow.getElementById("controls-right"),this.seekSegments=this.shadow.getElementById("seek-segments"),this.seekDot=this.shadow.getElementById("seek-dot"),this.seekPreview=this.shadow.getElementById("seek-preview"),this.seekPreviewCanvas=this.shadow.getElementById("seek-preview-canvas"),this.seekPreviewTitle=this.shadow.getElementById("seek-preview-title"),this.seekPreviewTime=this.shadow.getElementById("seek-preview-time"),this.timePill.addEventListener("click",()=>this.toggleTimeDisplay()),this.timePill.addEventListener("keydown",e=>{e.key!=="Enter"&&e.key!==" "||(e.preventDefault(),this.toggleTimeDisplay())}),this.volumeInput=this.shadow.getElementById("volume"),this.controlsRow=this.shadow.querySelector(".controls"),this.momentsBox=this.shadow.getElementById("moments"),this.momentsButton=this.shadow.getElementById("moments-button"),this.momentsCurrent=this.shadow.getElementById("moments-current"),this.momentsMenu=this.shadow.getElementById("moments-menu"),this.momentsButton.addEventListener("click",()=>this.toggleMomentsMenu()),this.moreButton=this.shadow.getElementById("controls-more"),this.moreButton.addEventListener("click",()=>this.setControlsFolded(this.controlsRow.classList.contains("more-open"))),this.muteButton.addEventListener("click",()=>this.toggleMuted()),this.volumeInput.addEventListener("input",()=>{this.setVolume(Number(this.volumeInput.value))}),this.fullscreenTarget=this.stageElement,this.playPauseButton.addEventListener("click",()=>this.togglePlayPause()),this.fullscreenButton.addEventListener("click",()=>this.toggleFullscreen()),this.addEventListener("keydown",this.handleFullscreenKey),this.observerMapButton.addEventListener("click",()=>this.toggleObserverMap()),this.referencesButton.addEventListener("click",()=>this.toggleReferences()),this.tracesButton.addEventListener("click",()=>this.toggleTraces()),this.referenceOpacityInput.addEventListener("input",()=>{this.referenceOpacityTouched=!0,this.dispatchReferenceView()}),this.milestonesButton.addEventListener("click",()=>this.toggleMilestones()),this.observerMapCanvas.addEventListener("pointermove",this.handleObserverMapPointerMove),this.observerMapCanvas.addEventListener("pointerleave",this.handlePointerLeave),this.observerMapCanvas.addEventListener("click",this.handleObserverMapClick),this.observerMapCanvas.addEventListener("pointerdown",this.handleObserverMapPointerDown),this.observerMapCanvas.addEventListener("pointerup",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("pointercancel",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("wheel",this.handleObserverMapWheel,{passive:!1}),this.mapZoomInButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,2)),this.mapZoomOutButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,.5)),this.mapFitButton.addEventListener("click",()=>{this.observerMapView.reset(),this.observerMapViewChanged()}),this.seekInput.addEventListener("input",()=>this.player.seek(this.snapSeekToMark(Number(this.seekInput.value)))),this.seekInput.addEventListener("pointerdown",e=>{this.suspendForScrub(),this.seekSnapArmed=!0,this.nameMarkUnder(e),this.beginTouchScrub(e)}),this.seekInput.addEventListener("pointerup",e=>{this.seekSnapArmed=!1,this.endTouchScrub(e)}),this.seekInput.addEventListener("pointercancel",e=>this.endTouchScrub(e)),this.seekInput.addEventListener("pointermove",e=>{this.nameMarkUnder(e),this.hoverSeek(e),this.touchScrub(e)}),this.seekInput.addEventListener("pointerleave",()=>{this.seekInput.removeAttribute("title"),this.leaveSeek()}),this.seekInput.addEventListener("keydown",this.handleSeekKey),this.stageElement.addEventListener("pointerdown",()=>{this.handlePointerDown(),this.touchedStage()},!0);for(const e of["touchend","click"])this.stageElement.addEventListener(e,()=>this.sightingAudio.resume(),!0);this.stageElement.addEventListener("pointermove",()=>this.touchedStage()),this.canvas.addEventListener("click",e=>{if(this.enableClickToPlay){if(this.tapRevealedOnly){this.tapRevealedOnly=!1;return}e.detail<=1&&(this.playbackBeforeClick={state:this.playbackState,time:this.currentTime}),this.togglePlayPause()}}),this.canvas.addEventListener("dblclick",e=>{this.enableClickToPlay&&(e.preventDefault(),this.restorePlayback(),this.toggleFullscreen())}),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerleave",this.handlePointerLeave),document.addEventListener("fullscreenchange",this.handleFullscreenChange),document.addEventListener("pointerdown",this.handleMomentsDismiss,!0),document.addEventListener("keydown",this.handleMomentsDismiss,!0),document.addEventListener("visibilitychange",this.handleVisibility),window.addEventListener("pagehide",this.handleHidden),document.addEventListener("pointerup",this.handlePointerRelease,!0),document.addEventListener("pointercancel",this.handlePointerRelease,!0),this.observerMapResizeObserver?.observe(this.observerMapPanel),this.controlsFitObserver?.observe(this.controlsRow),this.controlsFitObserver?.observe(this.controlsRow.querySelector(".controls-left")),typeof MutationObserver<"u"&&(this.controlsMutations=new MutationObserver(()=>this.fitControls()),this.controlsMutations.observe(this.controlsRight,{attributes:!0,attributeFilter:["hidden"],childList:!0,subtree:!0})),this.hostControls(void 0),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.refresh()}connectedCallback(){this.saidTexts=void 0,this.loadLocaleMessages();const t=this.getAttribute("src");t&&this.loadFromSrc(t)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange),document.removeEventListener("pointerdown",this.handleMomentsDismiss,!0),document.removeEventListener("keydown",this.handleMomentsDismiss,!0),document.removeEventListener("visibilitychange",this.handleVisibility),window.removeEventListener("pagehide",this.handleHidden),document.removeEventListener("pointerup",this.handlePointerRelease,!0),document.removeEventListener("pointercancel",this.handlePointerRelease,!0),window.clearTimeout(this.controlsIdleTimer),this.observerMapResizeObserver?.disconnect(),this.controlsFitObserver?.disconnect(),this.controlsMutations?.disconnect(),this.exitSimulatedFullscreen(),this.sightingAudio.dispose()}attributeChangedCallback(t,e,i){t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),t===ks&&this.applyObserverMapDefault(),t===Fs&&this.setMilestonesShown(!this.hasAttribute(Fs))}async loadFromSrc(t){this.sightingData=await Gc.json(t)}get sightingData(){return sb(this.currentSighting)}set sightingData(t){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=ab(t),this.issuesPanel.hidden=!0,this.issuesButton.setAttribute("aria-expanded","false"),this.reportIssues(t,this.currentSighting),this.observerMapView.reset(),this.mapFitButton.hidden=!0,this.observerMapAsked=!1,this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh(),this.applyObserverMapDefault()}get recordingIssues(){return this.issues}async reportIssues(t,e){const i=++this.issueCheck;let n=[];try{const{default:s}=await je(async()=>{const{default:r}=await import("./sightingSchema-5AlscPkV.js");return{default:r}},[],import.meta.url);n=new ts(s).issues(t)}catch{}i===this.issueCheck&&(this.issues=[...n,...e.loadIssues],Zo.warn(this.issues,e.id),this.renderIssues(),this.dispatchEvent(new CustomEvent(Cb,{detail:{issues:this.issues},bubbles:!0,composed:!0})))}renderIssues(){const t=this.issues.length;this.issuesBox.hidden=t===0,this.shadow.getElementById("issues-count").textContent=String(t);const e=this.messages.recordingIssues.replace("{count}",String(t));this.issuesButton.title=e,this.issuesButton.setAttribute("aria-label",e),this.shadow.getElementById("issues-title").textContent=e,this.shadow.getElementById("issues-list").replaceChildren(...this.issues.map(i=>{const n=document.createElement("li");return n.textContent=Zo.text(i,this.messages.issueTemplates),n}))}get sighting(){return this.currentSighting}previewSound(t){this.soundPreview=t,this.sightingAudio.resume(),this.sightingAudio.setSound(t)}stopSoundPreview(){this.soundPreview=void 0,this.sightingAudio.silence()}get canvasElement(){return this.canvas}get renderer(){return this.canvasRenderer}get currentTime(){return this.player.time}set currentTime(t){this.player.seek(t)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}set autoReplayEnabled(t){t!==this.loopEnabled&&this.toggleLoop()}play(){if(!(this.player.seekableDuration<=0||this.playbackState==="playing")){if(this.clockHeld){this.playAfterHold=!0;return}this.togglePlayPause()}}clockHeld=!1;playAfterHold=!1;holdClock(t){if(t!==this.clockHeld){if(this.clockHeld=t,t){if(this.playbackState!=="playing")return;this.playAfterHold=!0,this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh(),this.updatePlayPauseButton();return}this.playAfterHold&&(this.playAfterHold=!1,!(this.player.seekableDuration<=0||this.playbackState==="playing")&&(this.sightingAudio.resume(),this.player.play(),this.updatePlayPauseButton()))}}pause(){this.playAfterHold=!1,this.playbackState==="playing"&&this.togglePlayPause()}get positionLabel(){return this.timeStartLabel.textContent??""}get durationLabel(){return this.timeEndLabel.textContent??""}get showingClockTime(){return this.canShowClockTime}get canSwitchTimeDisplay(){return this.realStartMs!==void 0}toggleTimeDisplay(){this.canSwitchTimeDisplay&&(this.showClockTime=!this.showClockTime,this.updateTimeLabels(),this.updateTimeLabelTitles(),this.dispatchEvent(new CustomEvent("timedisplaychange",{bubbles:!0,composed:!0})))}get canShowClockTime(){return this.realStartMs!==void 0&&this.showClockTime}set showToolbar(t){this.toolbar.classList.toggle("hidden",!t),t?this.controlsRight.appendChild(this.fullscreenButton):this.cornerButtons.appendChild(this.fullscreenButton)}get playbackState(){return this.player.playbackState}get selectedSourceIds(){return this.highlightedSourceIds}get durationSeconds(){return this.currentSighting.event.durationSeconds}set durationSeconds(t){this.currentSighting.event.durationSeconds=t,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(t){const e=new Set(t);e.size===this.highlightedSourceIds.size&&[...e].every(n=>this.highlightedSourceIds.has(n))||(this.highlightedSourceIds=e,this.refresh())}hasVisibleShapeAt(t,e){return this.shapeAt(t,e)!==void 0}refresh(){this.applyFrameFormat(),this.updateMuteButton(),this.updateTimeLabels(),this.seekInput.max=String(this.player.seekableDuration),this.refreshMilestoneMarks(),this.updateMilestonesButton(),this.updateObserverMap(),this.updateReferences(),this.updateTracesButton(),this.player.seek(this.player.time)}hostControls(t){const e=[this.milestonesButton,this.referencesButton,this.referenceOpacityInput,this.tracesButton,this.observerMapButton];if(t)for(const i of e)t.appendChild(i);else{const i=this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null;for(const n of e)this.controlsRight.insertBefore(n,i)}}get referencesShown(){return this.referencesShownState}get referenceOpacity(){return Number(this.referenceOpacityInput.value)}get severalReferences(){return this.currentSighting.references.length>1}toggleReferences(){if(this.severalReferences){this.toggleReferencesMenu();return}this.referencesShownState=!this.referencesShownState,this.updateReferencesButton(),this.dispatchReferenceView()}updateReferences(){const t=this.currentSighting.references;!this.referenceOpacityTouched&&t.length>0&&(this.referenceOpacityInput.value=String(t[0].opacity));for(const e of[...this.referenceViews.keys()])t.some(i=>i.id===e)||this.referenceViews.delete(e);this.severalReferences?this.referencesMenu.hidden||this.renderReferencesMenu():this.closeReferencesMenu(),this.updateReferencesButton(),this.severalReferences&&this.dispatchReferenceView()}viewOfReference(t){let e=this.referenceViews.get(t.id);return e||(e={shown:!0,opacity:t.opacity},this.referenceViews.set(t.id,e)),e}toggleReferencesMenu(){this.referencesMenu.hidden?this.openReferencesMenu():this.closeReferencesMenu()}openReferencesMenu(){this.renderReferencesMenu(),this.referencesMenu.hidden=!1,this.placeReferencesMenu(),this.referencesButton.setAttribute("aria-expanded","true"),document.addEventListener("pointerdown",this.handleReferencesMenuOutside,!0),document.addEventListener("keydown",this.handleReferencesMenuKey,!0)}closeReferencesMenu(){this.referencesMenu.hidden||(this.referencesMenu.hidden=!0,this.referencesButton.setAttribute("aria-expanded","false"),document.removeEventListener("pointerdown",this.handleReferencesMenuOutside,!0),document.removeEventListener("keydown",this.handleReferencesMenuKey,!0))}handleReferencesMenuOutside=t=>{const e=t.composedPath();e.includes(this.referencesMenu)||e.includes(this.referencesButton)||this.closeReferencesMenu()};handleReferencesMenuKey=t=>{t.key==="Escape"&&(this.closeReferencesMenu(),this.referencesButton.focus())};placeReferencesMenu(){const t=this.referencesButton.getBoundingClientRect(),e=this.referencesMenu,i=4;e.style.bottom=`${Math.max(i,window.innerHeight-t.top+i)}px`,e.style.top="auto";const n=e.getBoundingClientRect().width;e.style.left=`${Math.max(i,Math.min(t.left,window.innerWidth-n-i))}px`}renderReferencesMenu(){const t=this.currentSighting.references.map(e=>{const i=this.viewOfReference(e),n=this.said.read(e.title)??e.id,s=document.createElement("div");s.className="reference-row";const r=document.createElement("label"),o=document.createElement("input");o.type="checkbox",o.checked=i.shown;const c=document.createElement("span");c.textContent=n,c.title=n,r.append(o,c);const l=document.createElement("input");return l.type="range",l.min="0",l.max="1",l.step="0.05",l.value=String(i.opacity),l.title=this.messages.referenceOpacity,l.setAttribute("aria-label",`${this.messages.referenceOpacity}: ${n}`),l.disabled=!i.shown,o.addEventListener("change",()=>{i.shown=o.checked,l.disabled=!i.shown,this.updateReferencesButton(),this.dispatchReferenceView()}),l.addEventListener("input",()=>{i.opacity=Number(l.value),this.dispatchReferenceView()}),s.append(r,l),s});this.referencesMenu.setAttribute("aria-label",this.messages.referencesMenu),this.referencesMenu.replaceChildren(...t)}updateReferencesButton(){const t=this.currentSighting.references.length>0,e=this.severalReferences,i=e?this.currentSighting.references.some(s=>this.viewOfReference(s).shown):this.referencesShownState;this.referencesButton.hidden=!t,this.referenceOpacityInput.hidden=!t||!this.referencesShownState||e,this.referencesButton.setAttribute("aria-pressed",String(i)),e?this.referencesButton.setAttribute("aria-haspopup","true"):this.referencesButton.removeAttribute("aria-haspopup"),pe.setIcon(this.referencesButton,i?Gt.PICTURES_ON:Gt.PICTURES_OFF);const n=e?this.messages.referencesMenu:this.referencesShownState?this.messages.hideReferences:this.messages.showReferences;this.referencesButton.title=n,this.referencesButton.setAttribute("aria-label",n),this.referenceOpacityInput.title=this.messages.referenceOpacity,this.referenceOpacityInput.setAttribute("aria-label",this.messages.referenceOpacity)}get tracesShown(){return this.tracesShownState}toggleTraces(){this.tracesShownState=!this.tracesShownState,this.updateTracesButton(),this.updateObserverMap(),this.dispatchEvent(new CustomEvent("traceview",{detail:{shown:this.tracesShown}}))}updateTracesButton(){this.tracesButton.hidden=this.currentSighting.traces.length===0,this.tracesButton.setAttribute("aria-pressed",String(this.tracesShownState)),pe.setIcon(this.tracesButton,this.tracesShownState?Gt.TRACES_ON:Gt.TRACES_OFF);const t=this.tracesShownState?this.messages.hideTraces:this.messages.showTraces;this.tracesButton.title=t,this.tracesButton.setAttribute("aria-label",t)}dispatchReferenceView(){const t=this.severalReferences?Object.fromEntries(this.currentSighting.references.map(e=>[e.id,{...this.viewOfReference(e)}])):void 0;this.dispatchEvent(new CustomEvent("referenceview",{detail:{shown:this.referencesShown,opacity:this.referenceOpacity,views:t}}))}refreshMilestoneMarks(){const t=this.player.seekableDuration,e=t>0?Wc(this.sighting.milestones):[];this.milestoneMarks.replaceChildren(...e.map(i=>{const n=document.createElement("button");n.type="button",n.className="milestone-mark",n.style.left=`${Math.min(Math.max(i.t/t,0),1)*100}%`;const s=this.said.read(i.label)??"",r=this.said.read(i.note),o=r?`${s} — ${r}`:s;return n.title=o,n.setAttribute("aria-label",o),n.dataset.t=String(i.t),n.addEventListener("click",()=>this.player.seek(i.t)),n})),this.refreshSeekSegments(t,e.map(i=>i.t)),this.refreshMomentsPicker(e)}refreshMomentsPicker(t){const e=this.milestonesShown&&t.length>0;this.momentsBox.hidden=!e,this.closeMomentsMenu(),this.momentsMenu.replaceChildren(...t.map(i=>{const n=document.createElement("li"),s=document.createElement("button");s.type="button",s.dataset.t=String(i.t);const r=this.said.read(i.label)??"",o=this.said.read(i.note);return s.textContent=o?`${r} — ${o}`:r,s.addEventListener("click",()=>{this.player.seek(i.t),this.closeMomentsMenu()}),n.appendChild(s),n})),this.momentsButton.title=this.messages.moments,this.showCurrentMoment(void 0)}showCurrentMoment(t){const i=(t?this.said.read(t.label)??"":"")||this.messages.moments;this.momentsCurrent.textContent!==i&&(this.momentsCurrent.textContent=i);for(const n of this.momentsMenu.querySelectorAll("button")){const s=t!==void 0&&Number(n.dataset.t)===t.t;n.getAttribute("aria-current")==="true"!==s&&n.setAttribute("aria-current",String(s))}}toggleMomentsMenu(){this.momentsMenu.hidden?(this.momentsMenu.hidden=!1,this.momentsButton.setAttribute("aria-expanded","true")):this.closeMomentsMenu()}closeMomentsMenu(){this.momentsMenu.hidden=!0,this.momentsButton.setAttribute("aria-expanded","false")}handleMomentsDismiss=t=>{if(!this.momentsMenu.hidden){if(t instanceof KeyboardEvent){t.key==="Escape"&&this.closeMomentsMenu();return}t.composedPath().some(e=>e===this.momentsMenu||e===this.momentsButton)||this.closeMomentsMenu()}};seekSegmentList=[];refreshSeekSegments(t,e){const n=[0,...this.milestonesShown&&t>0?[...new Set(e.filter(r=>r>0&&r<t))].sort((r,o)=>r-o):[],Math.max(t,0)];this.seekSegmentList=[];const s=[];for(let r=0;r<n.length-1;r++){const o=document.createElement("div");o.className="seek-segment",o.style.flexGrow=String(Math.max(n[r+1]-n[r],1));const c=document.createElement("i");c.className="seek-hover";const l=document.createElement("i");l.className="seek-played",o.append(c,l),s.push(o),this.seekSegmentList.push({start:n[r],end:n[r+1],element:o,played:l,hover:c})}this.seekSegments.replaceChildren(...s),this.paintSeekProgress(this.player.time)}static fillOf(t,e){const i=t.end-t.start,n=i>0?(e-t.start)/i:e>=t.end?1:0;return`${Math.min(Math.max(n,0),1)*100}%`}paintSeekProgress(t){for(const i of this.seekSegmentList)i.played.style.width=pe.fillOf(i,t);const e=this.player.seekableDuration;this.seekDot.style.left=`${e>0?Math.min(Math.max(t/e,0),1)*100:0}%`}hoverSeek(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=Math.min(Math.max((t.clientX-e.left)/e.width,0),1),s=n*i,r=this.seekSegmentList.length-1;this.seekSegmentList.forEach((f,p)=>{f.hover.style.width=pe.fillOf(f,s),f.element.classList.toggle("hovered",s>=f.start&&(s<f.end||p===r))});const o=this.milestonesShown?this.sighting.milestones:[],c=o.length>0?Md(o,s):void 0,l=c?this.said.read(c.label)??"":"",h=c?this.said.read(c.note):void 0,u=h?`${l} — ${h}`:l;this.seekPreviewTitle.textContent=u,this.seekPreviewTime.textContent=this.formatPosition(s),this.seekPreview.hidden=!1;const d=this.seekPreview.offsetWidth;this.seekPreview.style.left=`${Math.min(Math.max(n*e.width-d/2,0),Math.max(e.width-d,0))}px`,this.paintSeekPreview(s)}leaveSeek(){for(const t of this.seekSegmentList)t.hover.style.width="0",t.element.classList.remove("hovered");this.seekPreview.hidden=!0}seekPreviewPainter;paintSeekPreview(t){const e=this.seekPreviewPainter;this.seekPreviewCanvas.hidden=e===void 0,e?.(t,this.seekPreviewCanvas)}scrubbingPointer;beginTouchScrub(t){if(t.pointerType!=="mouse"){this.scrubbingPointer=t.pointerId;try{this.seekInput.setPointerCapture(t.pointerId)}catch{}this.seekToPointer(t)}}touchScrub(t){t.pointerId===this.scrubbingPointer&&this.seekToPointer(t)}endTouchScrub(t){t.pointerId===this.scrubbingPointer&&(this.scrubbingPointer=void 0,this.seekToPointer(t))}seekToPointer(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=Math.min(Math.max((t.clientX-e.left)/e.width,0),1);this.player.seek(this.snapSeekToMark(n*i))}seekSnapArmed=!1;static MARK_SNAP_PX=6;markNear(t){const e=this.player.seekableDuration,i=this.seekInput.getBoundingClientRect().width;if(e<=0||i<=0)return;const n=pe.MARK_SNAP_PX/i*e;let s;for(const r of this.milestoneMarks.children){const o=Number(r.dataset.t);Math.abs(o-t)>n||(!s||Math.abs(o-t)<Math.abs(s.t-t))&&(s={t:o,name:r.title})}return s}snapSeekToMark(t){return this.seekSnapArmed?(this.seekSnapArmed=!1,this.markNear(t)?.t??t):t}nameMarkUnder(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=(t.clientX-e.left)/e.width*i,s=this.markNear(n);s?this.seekInput.title=s.name:this.seekInput.removeAttribute("title")}showMilestoneAt(t){const e=this.milestonesShown&&this.sighting.milestones.length>0?Md(this.sighting.milestones,t):void 0;if(this.milestoneCaption.hidden=e===void 0,this.showCurrentMoment(e),!e)return;const i=document.createElement("b");i.textContent=this.said.read(e.label)??"";const n=this.said.read(e.note),s=n?` — ${n}`:"";this.milestoneCaption.replaceChildren(i,document.createTextNode(s))}exposureInstants(t){const e=this.exposureTimes(t),i=1/e.length;return e.map(n=>({shapes:this.shapesAt(n),share:i}))}exposureTimes(t=this.currentTime){const e=as.windowEndingAt(t,this.currentSighting.exposure??0);if(e.ms<pe.SHORTEST_VISIBLE_EXPOSURE_MS)return[t];const i=Math.min(pe.MAX_EXPOSURE_STEPS,Math.max(2,Math.round(e.ms/pe.SHORTEST_VISIBLE_EXPOSURE_MS))),n=Math.ceil(this.travelPxOver(e.fromMs,e.ms)/pe.EXPOSURE_STEP_PX),s=Math.min(pe.MAX_TRAVEL_STEPS,Math.max(i,n)),r=[];for(let o=0;o<s;o++)r.push(e.fromMs+e.ms*o/(s-1));return r}travelPxOver(t,e){const i=this.shapesAt(t),n=this.shapesAt(t+e);let s=0;for(const[r,o]of i){const c=n.get(r);if(!c)continue;const l=c.bounds.x+c.bounds.width/2-(o.bounds.x+o.bounds.width/2),h=c.bounds.y+c.bounds.height/2-(o.bounds.y+o.bounds.height/2);s=Math.max(s,Math.hypot(l,h))}return s}shapeAt(t,e,i){if(!this.accountHidden)for(const n of this.exposureTimes()){const s=this.currentSighting.timeline.hitTest(n,t,e,i);if(s)return s}}shapesAt(t){const e=new Map;for(const i of this.currentSighting.timeline.sourceIds){const n=this.currentSighting.timeline.getInterpolatedShapeAt(t,i);n&&e.set(i,n)}return e}static SHORTEST_VISIBLE_EXPOSURE_MS=20;static MAX_EXPOSURE_STEPS=48;static EXPOSURE_STEP_PX=2;static MAX_TRAVEL_STEPS=320;applyFrameFormat(){const t=bi.frameWidthPx(this.currentSighting.instrument,this.canvas.height);if(this.canvas.width===t)return;this.canvas.width=t,this.canvas.parentElement?.style.setProperty("--frame-aspect",`${t} / ${this.canvas.height}`)}canvasPointFromEvent(t){const e=this.canvas.getBoundingClientRect();if(!(e.width===0||e.height===0))return{x:(t.clientX-e.left)/e.width*this.canvas.width,y:(t.clientY-e.top)/e.height*this.canvas.height}}onFrame(t,e){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const i=this.playbackState!=="playing"?this.highlightedSourceIds:Ib;this.canvasRenderer.setStarPoints(bi.starPointsOf(this.sighting.instrument));const n=(Ze(this.sighting,t)?.rollDeg??0)+this.gaitAt(t).rollDeg;this.canvasRenderer.setRoll(n*Math.PI/180);const s=this.exposureInstants(t),r=this.frameShift;if(this.paintsShapes)for(const o of s)for(const[,c]of o.shapes){const l=o.share,h=l===1?c:{...c,transparency:1-(1-c.transparency)*l};this.canvasRenderer.paintShape(this.shifted(h,r))}for(const[o,c]of s[0].shapes)!this.selectionShown||!i.has(o)||(this.paintsShapes?i.size===1?this.canvasRenderer.paintShape({...c,selected:!0}):this.canvasRenderer.paintMemberOutline(c):this.canvasRenderer.paintSelectionOnly(this.shifted(c,r)));if(this.selectionShown&&i.size>1){const o=Dn.groupBoundsFor([...e].filter(([c])=>i.has(c)).map(([,c])=>c.bounds));this.canvasRenderer.paintGroupHandles(o)}this.overlayPainter?.(this.canvasRenderer),this.mapShapeBounds=s.flatMap(o=>[...o.shapes.values()].filter(c=>c.transparency<1).map(c=>this.shifted(c,r).bounds)),this.keepObserverMapClear(),this.seekInput.value=String(t),this.paintSeekProgress(t),this.timeStartLabel.textContent=this.formatPosition(t),this.showMilestoneAt(t),this.paintObserverMap(t),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(pM(this.currentSighting,t))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:t}}))}shifted(t,e){return e.x===0&&e.y===0?t:{...t,bounds:{...t.bounds,x:t.bounds.x+e.x,y:t.bounds.y+e.y}}}createPlayer(){const t=new Zx(this.currentSighting.timeline,(e,i)=>this.onFrame(e,i));return t.loop=this.loopEnabled,t.onEnded=()=>{this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("ended",{bubbles:!0,composed:!0}))},t}static SEEK_KEY_STEP_MS=5e3;handleFullscreenKey=t=>{t.key.toLowerCase()!=="f"||t.altKey||t.ctrlKey||t.metaKey||!this.enableClickToPlay||t.composedPath().some(i=>i instanceof HTMLElement&&(i.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(i.tagName)&&i.type!=="range"))||(t.preventDefault(),this.toggleFullscreen())};handleSeekKey=t=>{if(t.altKey||t.ctrlKey||t.metaKey)return;const e=t.key==="ArrowLeft"?-1:t.key==="ArrowRight"?1:0;if(e){t.preventDefault();const i=this.player.seekableDuration;this.player.seek(Math.min(i,Math.max(0,this.player.time+e*pe.SEEK_KEY_STEP_MS)))}else t.key===" "&&(t.preventDefault(),this.togglePlayPause())};togglePlayPause(){if(!(this.player.seekableDuration<=0)){if(this.player.playbackState==="playing")this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh();else if(this.clockHeld){this.playAfterHold=!this.playAfterHold;return}else this.sightingAudio.resume(),this.player.play();this.updatePlayPauseButton(),this.flashPlayback()}}flashPlayback(){const t=this.playbackFlash;t.innerHTML=this.player.playbackState==="playing"?Gt.PLAY:Gt.PAUSE,t.classList.remove("flashing"),t.offsetWidth,t.classList.add("flashing")}static icons=new WeakMap;static setIcon(t,e){pe.icons.get(t)!==e&&(pe.icons.set(t,e),t.innerHTML=e)}set captionHeld(t){this.stageElement.classList.toggle("caption-held",t)}static CONTROLS_IDLE_MS=3e3;controlsIdleTimer;wasPlaying=!1;quietControlsValue=!1;get quietControls(){return this.quietControlsValue}set quietControls(t){this.quietControlsValue=t,this.stageElement.classList.toggle("quiet",t)}tapRevealedOnly=!1;get hoverless(){return typeof matchMedia=="function"&&matchMedia("(hover: none)").matches}touchedStage(){if(!this.hoverless)return;this.player.playbackState==="playing"&&!this.stageElement.classList.contains("touched")&&(this.tapRevealedOnly=!0),this.revealControls()}pointerHeld=!1;handlePointerDown=()=>{this.pointerHeld=!0};resumeAfterScrub=!1;suspendForScrub(){this.player.playbackState==="playing"&&(this.resumeAfterScrub=!0,this.stopPlaying())}stopPlaying(){this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh(),this.updatePlayPauseButton()}resumeFromScrub(){this.resumeAfterScrub&&(this.resumeAfterScrub=!1,this.sightingAudio.resume(),this.player.play(),this.updatePlayPauseButton())}handleHidden=()=>{this.player.playbackState==="playing"&&this.stopPlaying(),this.resumeAfterScrub=!1};handleVisibility=()=>{document.visibilityState==="hidden"&&this.handleHidden()};handlePointerRelease=()=>{this.resumeAfterScrub&&window.setTimeout(()=>this.resumeFromScrub(),0),this.pointerHeld&&(this.pointerHeld=!1,this.hoverless&&this.stageElement.classList.contains("touched")&&this.revealControls())};revealControls(){this.stageElement.classList.add("touched"),window.clearTimeout(this.controlsIdleTimer),this.player.playbackState==="playing"&&(this.pointerHeld||!this.momentsMenu.hidden||(this.controlsIdleTimer=window.setTimeout(()=>{this.stageElement.classList.remove("touched"),this.tapRevealedOnly=!1},pe.CONTROLS_IDLE_MS)))}updatePlayPauseButton(){const t=this.player.playbackState==="playing";this.stageElement.classList.toggle("paused",!t),t!==this.wasPlaying&&t&&this.hoverless&&(!this.quietControlsValue||this.stageElement.classList.contains("touched"))&&this.revealControls(),this.wasPlaying=t,pe.setIcon(this.playPauseButton,t?Gt.PAUSE:Gt.PLAY);const e=this.player.seekableDuration>0;this.playPauseButton.disabled=!e;const i=e?t?this.messages.pause:this.messages.play:this.messages.noDuration;this.playPauseButton.title=i,this.playPauseButton.setAttribute("aria-label",i)}toggleLoop(){this.loopEnabled=!this.loopEnabled,this.player.loop=this.loopEnabled}restorePlayback(){const t=this.playbackBeforeClick;t&&(this.currentTime=t.time,t.state==="playing"?this.play():this.pause())}get canUseNativeFullscreen(){return typeof this.fullscreenTarget.requestFullscreen=="function"&&document.fullscreenEnabled}toggleFullscreen(){if(!this.canUseNativeFullscreen){this.simulatedFullscreen?this.exitSimulatedFullscreen():this.enterSimulatedFullscreen();return}document.fullscreenElement?document.exitFullscreen():this.fullscreenTarget.requestFullscreen().catch(t=>{console.error("<rr0-ufo>: requestFullscreen() failed —",t)})}enterSimulatedFullscreen(){const t=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen=t.getAttribute("style")??"",this.bodyOverflowBeforeSimulatedFullscreen=document.body.style.overflow;const e=t.style;e.setProperty("position","fixed"),e.setProperty("inset","0"),e.setProperty("margin","0"),e.setProperty("max-width","none"),e.setProperty("max-height","none"),e.setProperty("aspect-ratio","auto"),e.setProperty("z-index","2147483647"),e.setProperty("background","#000"),e.setProperty("width","100vw"),e.setProperty("width","100dvw"),e.setProperty("height","100vh"),e.setProperty("height","100dvh"),document.body.style.overflow="hidden",this.simulatedFullscreen=!0,document.addEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}exitSimulatedFullscreen(){if(!this.simulatedFullscreen)return;const t=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen?t.setAttribute("style",this.styleBeforeSimulatedFullscreen):t.removeAttribute("style"),document.body.style.overflow=this.bodyOverflowBeforeSimulatedFullscreen??"",this.simulatedFullscreen=!1,document.removeEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}toggleObserverMap(){const t=this.observerMapPanel.hidden;this.observerMapAsked=t,this.setObserverMapOpen(t),this.keepObserverMapClear(),this.dispatchEvent(new CustomEvent("observermapchange",{bubbles:!0,composed:!0,detail:{open:t}}))}get observerMapOpen(){return!this.observerMapPanel.hidden}get milestonesVisible(){return this.milestonesShown}observerMapAsked=!1;applyObserverMapDefault(){const t=this.getAttribute(ks),e=t===null?this.sighting.observerMap??this.observerPath?.travels===!0:t!=="false";this.setObserverMapOpen(e&&this.observerPath!==void 0)}setObserverMapOpen(t){this.observerMapPanel.hidden=!t,this.observerMapPanel.removeAttribute("title"),this.observerMapButton.setAttribute("aria-pressed",String(t)),this.updateObserverMapButton(),t&&(this.sizeObserverMapCanvas(),this.loadObserverMapImagery(),this.paintObserverMap(this.currentTime))}updateObserverMapButton(){const t=!this.observerMapPanel.hidden;pe.setIcon(this.observerMapButton,t?Gt.MAP_ON:Gt.MAP_OFF);const e=t?this.messages.hideObserverMap:this.messages.showObserverMap;this.observerMapButton.title=e,this.observerMapButton.setAttribute("aria-label",e);const i=[[this.mapZoomInButton,this.messages.zoomMapIn],[this.mapZoomOutButton,this.messages.zoomMapOut],[this.mapFitButton,this.messages.fitMap]];for(const[n,s]of i)n.title=s,n.setAttribute("aria-label",s)}updateObserverMap(){const t=this.observerPath!==void 0;if(this.observerPath=Fo.of(this.currentSighting),this.observerMapButton.hidden=this.observerPath===void 0,!t&&this.observerPath&&this.applyObserverMapDefault(),!this.observerPath){this.setObserverMapOpen(!1),this.observerMapBounds=void 0;return}const e=this.tracesShownState?this.currentSighting.traces.flatMap(n=>n.points):[],i=ni.including(this.observerPath.boundsAround(pe.OBSERVER_MAP_MIN_SPAN_M,pe.OBSERVER_MAP_MARGIN),e);(!this.observerMapBounds||!this.sameGround(this.observerMapBounds,i))&&(this.observerMapBounds&&this.observerMapView.refit(this.observerMapBounds,i),this.observerMapBounds=i,this.observerMapImagery=void 0,this.observerMapImageryCredit=void 0,this.observerMapImageryFailed=!1,this.observerMapImageryBounds=void 0,this.observerMapImageryLoading=!1,this.observerMapPanel.hidden||this.loadObserverMapImagery())}sameGround(t,e){const i=Math.abs(t.east-t.west)/20;return Math.abs(t.north-e.north)<i&&Math.abs(t.south-e.south)<i&&Math.abs(t.west-e.west)<i&&Math.abs(t.east-e.east)<i}async loadObserverMapImagery(){const t=this.observerMapViewBounds;if(!t||this.observerMapPanel.hidden||this.observerMapImageryLoading||!this.observerMapImageryNeededFor(t))return;const e=this.observerMapView.changed,i=e?ni.expand(t,pe.OBSERVER_MAP_IMAGERY_AHEAD):t,n=pe.OBSERVER_MAP_IMAGERY_PX*(e?1+2*pe.OBSERVER_MAP_IMAGERY_AHEAD:1);this.observerMapImageryBounds=i,this.observerMapImageryViewWidth=t.east-t.west,this.observerMapImageryLoading=!0;const s=CM();try{const r=await s.getImageryTexture(i,{width:n,height:n});if(this.observerMapImageryBounds!==i)return;this.observerMapImagery=r,this.observerMapImageryCredit=s.attribution,this.observerMapImageryFailed=!1}catch{if(this.observerMapImageryBounds!==i)return;this.observerMapImageryFailed=this.observerMapImagery===void 0}finally{this.observerMapImageryBounds===i&&(this.observerMapImageryLoading=!1)}this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}static OBSERVER_MAP_IMAGERY_AHEAD=.5;static OBSERVER_MAP_IMAGERY_LOOKAHEAD=.25;observerMapImageryNeededFor(t){const e=this.observerMapImageryBounds;if(!e)return!0;const i=this.observerMapImagery?.bounds??e,n=this.observerMapView.changed?ni.expand(t,pe.OBSERVER_MAP_IMAGERY_LOOKAHEAD):t,s=n.west>=i.west&&n.east<=i.east&&n.south>=i.south&&n.north<=i.north,r=t.east-t.west>this.observerMapImageryViewWidth/2;return!s||!r}get observerMapCredit(){return this.observerMapImageryCredit}get observerMapFooterLine(){return this.observerMapImageryFailed?this.messages.mapImageryUnavailable:this.creditShownExternally?void 0:this.observerMapImageryCredit}mapShapeBounds=[];mapSceneBounds=[];setMapSubjectBounds(t){this.mapSceneBounds=t.map(e=>({x:e.x*this.canvas.width,y:e.y*this.canvas.height,width:e.width*this.canvas.width,height:e.height*this.canvas.height})),this.keepObserverMapClear()}keepObserverMapClear(){if(this.observerMapPanel.hidden)return;const t=this.observerMapBoxPx;if(!t)return;const e=[...this.mapShapeBounds,...this.mapSceneBounds],i=(l,h,u)=>{for(const d of e)if(!(d.x+d.width<l-u||d.x>h+u)&&!(d.y>t.bottom+u||d.y+d.height<t.top-u))return!0;return!1},n=[this.canvas.width-t.width,this.canvas.width],s=[0,t.width],r=pe.OBSERVER_MAP_CLEARANCE_PX,o=i(...n,0),c=i(...s,0);if(this.observerMapPanel.classList.toggle("subject-overlap",o&&c&&!this.observerMapAsked),this.observerMapPanel.classList.contains("on-the-left")){!o&&(c||!i(n[0],n[1],r))&&this.observerMapPanel.classList.remove("on-the-left");return}i(n[0],n[1],0)&&!i(s[0],s[1],0)&&this.observerMapPanel.classList.add("on-the-left")}observerMapBoxPx;static OBSERVER_MAP_CLEARANCE_PX=24;sizeObserverMapCanvas(){const t=this.observerMapPanel.clientWidth;if(t===0)return;const e=Math.round(t*(globalThis.devicePixelRatio??1));this.measureObserverMapBox(),this.observerMapCanvas.width!==e&&(this.observerMapCanvas.width=e,this.observerMapCanvas.height=e)}measureObserverMapBox(){const t=this.observerMapPanel.getBoundingClientRect(),e=this.canvas.getBoundingClientRect();if(e.width===0||e.height===0)return;const i=this.canvas.width/e.width,n=this.canvas.height/e.height;this.observerMapBoxPx={width:t.width*i,top:(t.top-e.top)*n,bottom:(t.bottom-e.top)*n}}paintObserverMap(t){if(this.observerMapPanel.hidden||!this.observerPath||!this.observerMapBounds)return;const e=Ze(this.currentSighting,t);e?.lat!==void 0&&e.lng!==void 0&&!this.observerMapDrag?.moved&&this.observerMapView.keepInView(this.observerMapBounds,{lat:e.lat,lng:e.lng},pe.OBSERVER_MAP_FOLLOW_MARGIN)&&this.scheduleObserverMapImagery();const i=this.currentSighting.instrument,n=[],s=this.currentSighting.milestones.length>0?Md(this.currentSighting.milestones,t):void 0;for(const r of this.milestonesShown?Wc(this.currentSighting.milestones):[]){const o=Ze(this.currentSighting,r.t);o?.lat===void 0||o.lng===void 0||n.push({label:this.said.read(r.label)??"",note:this.said.read(r.note),t:r.t,lat:o.lat,lng:o.lng,current:r===s})}this.observerMapRenderer.paint({bounds:this.observerMapViewBounds,imagery:this.observerMapImagery,path:this.observerPath,position:e?.lat!==void 0&&e.lng!==void 0?{lat:e.lat,lng:e.lng}:void 0,headingDeg:e?.headingDeg===void 0?void 0:e.headingDeg+this.lookYawDeg,coneHalfAngleDeg:e?rr.of(i,this.canvas.height,e.fovDeg).halfWidthAngleDeg(bi.aspectOf(i)):void 0,markers:n,traces:(this.tracesShownState?this.currentSighting.traces:[]).map(r=>({kind:r.kind,points:r.points,color:r.color,label:this.said.read(r.title)})),decor:this.observerMapDecorAt(t),observerLabel:this.said.read(this.currentSighting.observer?.title)??this.messages.observerHere,nightFraction:this.observerMapNightFraction,attribution:this.observerMapFooterLine})}toggleMilestones(){this.setMilestonesShown(!this.milestonesShown)}setMilestonesShown(t){this.milestonesShown=t,this.milestoneMarks.hidden=!t,this.momentsBox.hidden=!t||this.sighting.milestones.length===0,this.refreshSeekSegments(this.player.seekableDuration,Wc(this.sighting.milestones).map(e=>e.t)),this.milestonesButton.setAttribute("aria-pressed",String(t)),this.updateMilestonesButton(),this.showMilestoneAt(this.currentTime),this.paintObserverMap(this.currentTime)}updateMilestonesButton(){this.milestonesButton.hidden=this.currentSighting.milestones.length===0,this.momentsButton.title=this.messages.moments,pe.setIcon(this.milestonesButton,this.milestonesShown?Gt.MILESTONES_ON:Gt.MILESTONES_OFF);const t=this.milestonesShown?this.messages.hideMilestones:this.messages.showMilestones;this.milestonesButton.title=t,this.milestonesButton.setAttribute("aria-label",t)}observerMapDecorAt(t){const e=Ze(this.currentSighting,0);return e?.lat===void 0||e.lng===void 0?[]:this.currentSighting.decor.filter(i=>i.kind!=="crop").map(i=>{const n=Hr(i,t),{lat:s,lng:r}=Nn(n.eastM,-n.northM,e.lat,e.lng);return{lat:s,lng:r,headingDeg:n.headingDeg,label:this.said.read(i.title)??this.messages.decorHere}})}observerMapNightFraction;setSunAltitude(t){const e=t===void 0?void 0:Math.max(0,Math.min(1,-t/12));e!==this.observerMapNightFraction&&(this.observerMapNightFraction=e,this.paintObserverMap(this.currentTime))}setLookOffset(t,e){t===this.lookYawDeg&&e===this.lookPitchDeg||(this.lookYawDeg=t,this.lookPitchDeg=e,this.refresh())}get frameShiftPx(){return this.frameShift}get frameShift(){const t=this.gaitAt(this.currentTime),e=this.lookYawDeg+t.yawDeg,i=this.lookPitchDeg+t.pitchDeg;if(e===0&&i===0)return{x:0,y:0};const n=Ze(this.currentSighting,this.currentTime),s=rr.of(this.currentSighting.instrument,this.canvas.height,n?.fovDeg??60);return{x:-s.angleDegToRadiusPx(e),y:s.angleDegToRadiusPx(i)}}gaitAt(t){return Ce.bodyAt(this.currentSighting,t,this.steadyBody)}mutedState=!1;get muted(){return this.mutedState}set muted(t){t!==this.mutedState&&(this.mutedState=t,!t&&this.volumeState===0&&(this.volumeState=pe.RESTORED_VOLUME),this.applyLevel())}volumeState=1;static RESTORED_VOLUME=.5;get volume(){return this.volumeState}set volume(t){this.setVolume(t)}setVolume(t){this.volumeState=Math.min(Math.max(t,0),1),this.mutedState=this.volumeState===0,this.applyLevel()}get level(){return this.mutedState?0:this.volumeState}applyLevel(){this.sightingAudio.setLevel(this.level),this.updateMuteButton(),this.dispatchEvent(new CustomEvent("mutedchange",{bubbles:!0,composed:!0,detail:{muted:this.mutedState,volume:this.volumeState}}))}toggleMuted(){this.hasSound&&(this.muted=!this.mutedState)}ambientSound;get hasSound(){return this.currentSighting.soundTrack.allKeyframes.length>0||this.ambientSound?.(this.currentSighting)===!0}updateMuteButton(){const t=!this.hasSound;if(this.muteButton.disabled=t,this.volumeInput.hidden=t,t){pe.setIcon(this.muteButton,Gt.MUTED),this.muteButton.title=this.messages.noSound,this.muteButton.setAttribute("aria-label",this.messages.noSound),this.muteButton.setAttribute("aria-pressed","true");return}pe.setIcon(this.muteButton,this.mutedState?Gt.MUTED:Gt.VOLUME);const e=this.mutedState?this.messages.unmute:this.messages.mute;this.muteButton.title=e,this.muteButton.setAttribute("aria-label",e),this.muteButton.setAttribute("aria-pressed",String(this.mutedState)),this.volumeInput.value=String(this.level)}updateFullscreenButton(){const t=this.simulatedFullscreen||document.fullscreenElement===this.fullscreenTarget;pe.setIcon(this.fullscreenButton,t?Gt.EXIT_FULLSCREEN:Gt.ENTER_FULLSCREEN),this.fullscreenButton.title=t?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}get said(){return this.saidTexts??=new Yn(Gr.preferencesFor(this))}saidTexts;async loadLocaleMessages(){const t=Ep(Gr.preferencesFor(this),Ap);if(t===this.messagesLanguage||t==="en"&&this.messagesLanguage===void 0)return;this.messagesLanguage=t;const e=await lb(t);this.messagesLanguage===t&&this.applyMessages(e)}messagesLanguage;updateTimeLabelTitles(){const t=this.showClockTime?this.messages.switchToElapsed:this.messages.switchToClockTime,e=this.canSwitchTimeDisplay?` — ${t}`:"";this.timeStartLabel.title=this.messages.currentPosition+e,this.timeEndLabel.title=this.messages.duration+e,this.timePill.classList.toggle("switchable",this.canSwitchTimeDisplay),this.canSwitchTimeDisplay?(this.timePill.setAttribute("role","button"),this.timePill.setAttribute("tabindex","0")):(this.timePill.removeAttribute("role"),this.timePill.removeAttribute("tabindex"))}applyMessages(t){this.messages=t,this.updateTimeLabelTitles(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.renderIssues()}updateTimeLabels(){const t=this.currentSighting.event,e=fM(t);this.realDurationMs=e!==void 0&&e>0?e:void 0,this.realStartMs=t.time?Yf(t.time):void 0;const i=this.currentSighting.timeline.duration;this.player.playbackRate=this.realDurationMs!==void 0&&i>0?i/this.realDurationMs:1,this.player.durationOverrideMs=i>0?0:this.realDurationMs??0,this.timeEndLabel.textContent=this.formatEndOfTimeline(),this.timeStartLabel.textContent=this.formatPosition(this.player.time),this.updateTimeLabelTitles()}formatPosition(t){if(this.realDurationMs===void 0)return Nl(t);const e=this.currentSighting.timeline.duration,i=e>0&&t<=e?t/e*this.realDurationMs:t;return this.canShowClockTime?gg(mg(this.realStartMs+i)):Nl(i)}formatEndOfTimeline(){return this.realDurationMs===void 0?Nl(this.currentSighting.timeline.duration):this.canShowClockTime?gg(mg(this.realStartMs+this.realDurationMs)):Nl(this.realDurationMs)}}function mg(a){const t=new Date(a);return{hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds()}}function gg(a){if(a.hour===void 0)return"0:00";const t=e=>String(e).padStart(2,"0");return a.second?`${t(a.hour)}:${t(a.minute??0)}:${t(a.second)}`:`${t(a.hour)}:${t(a.minute??0)}`}function Nl(a){const t=Math.round(a/1e3),e=Math.floor(t/60),i=t%60;return`${e}:${String(i).padStart(2,"0")}`}const Kf="rr0-ufo";function PM(){customElements.get(Kf)||customElements.define(Kf,pe)}const Cb="recordingissues";/**
2183
+ `);let e=Do.shared.get(t);return e||(e=this.fetchFirstAvailable(),Do.shared.set(t,e),e.then(i=>{i.length===0&&Do.shared.delete(t)})),this.index=e}async fetchFirstAvailable(){for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(!e.ok)continue;const i=await e.json();if(Array.isArray(i?.entries))return i.entries.map(n=>({entry:n,indexUrl:t}))}catch{}return[]}static defaultIndexUrls(){const t=`?v=${encodeURIComponent("0.105.3")}`,e=typeof location>"u"?void 0:new URL("/roads/index.json",location.href).href;return(e&&e!==xd?[e,xd]:[xd]).map(i=>i+t)}}function Rb(){return{elevation:new wb,imagery:CM(),roads:Db()}}function CM(){return new Tb}function Db(){return new Do({fallback:new es})}const Ib=new Set,ks="show-observer-map",Fs="hide-milestones";class pe extends HTMLElement{static get observedAttributes(){return["src",ks,Fs]}shadow;stageElement;canvas;canvasRenderer;tooltip;toolbar;issuesBox;issuesButton;issuesPanel;playPauseButton;static OBSERVER_MAP_MIN_SPAN_M=400;static OBSERVER_MAP_MARGIN=.6;static OBSERVER_MAP_IMAGERY_PX=768;fullscreenButton;cornerButtons;observerMapButton;referencesButton;tracesButton;tracesShownState=!0;referenceOpacityInput;referencesShownState=!0;accountHidden=!1;referenceViews=new Map;referencesMenu;referenceOpacityTouched=!1;milestonesButton;observerMapPanel;observerMapCanvas;observerMapRenderer;mapZoomInButton;mapZoomOutButton;mapFitButton;observerMapView=new ni;observerMapDrag;suppressObserverMapClick=!1;observerMapImageryTimer;observerPlacing=!1;seekInput;playbackFlash;milestoneMarks;milestoneCaption;timeStartLabel;timeEndLabel;timePill;muteButton;volumeInput;controlsRow;momentsBox;momentsButton;momentsCurrent;momentsMenu;moreButton;controlsRight;seekSegments;seekDot;seekPreview;seekPreviewCanvas;seekPreviewTitle;seekPreviewTime;observerPath;observerMapBounds;observerMapImagery;observerMapImageryBounds;observerMapImageryViewWidth=0;observerMapImageryLoading=!1;observerMapImageryCredit;observerMapImageryFailed=!1;creditShownExternally=!1;lookYawDeg=0;lookPitchDeg=0;milestonesShown=!0;currentSighting=td.create();issues=[];issueCheck=0;sightingAudio=new nb;soundPreview;player;loopEnabled=!1;playbackBeforeClick;highlightedSourceIds=new Set;paintsShapes=!0;steadyObserver=!1;static LIVE_BODY_MAX_RATE=2;get steadyBody(){return this.steadyObserver||this.player.playbackState!=="playing"||this.player.playbackRate>pe.LIVE_BODY_MAX_RATE}selectionShown=!0;overlayPainter;enableClickToPlay=!0;fullscreenTarget;messages=SM;realDurationMs;realStartMs;showClockTime=!0;handleFullscreenChange=()=>{this.updateFullscreenButton(),this.updateMuteButton(),this.resizeObserverMap()};controlsFitObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.fitControls());controlsMutations;fitControls(){const t=this.controlsRow,e=t.classList.contains("more-open"),i=()=>t.scrollWidth>t.clientWidth+1,n=!this.momentsMenu.hidden;if(this.momentsMenu.hidden=!0,t.classList.remove("narrow","more-open","nomoments","compact","tiny"),t.clientWidth>0&&i()){t.classList.add("narrow");for(const s of["nomoments","compact","tiny"]){if(!i())break;t.classList.add(s)}e&&t.classList.add("more-open")}this.momentsMenu.hidden=!n,this.updateMoreButton()}setControlsFolded(t){this.controlsRow.classList.toggle("more-open",!t),this.updateMoreButton()}updateMoreButton(){const t=this.controlsRow.classList.contains("more-open");pe.setIcon(this.moreButton,t?Gt.UNFOLDED:Gt.FOLDED);const e=t?this.messages.fewerControls:this.messages.moreControls;this.moreButton.title=e,this.moreButton.setAttribute("aria-label",e),this.moreButton.setAttribute("aria-expanded",String(t))}addControl(t){this.controlsRight.insertBefore(t,this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null),this.fitControls()}observerMapResizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(()=>this.resizeObserverMap());resizeObserverMap(){this.observerMapPanel.hidden||(this.sizeObserverMapCanvas(),this.paintObserverMap(this.currentTime))}simulatedFullscreen=!1;styleBeforeSimulatedFullscreen;bodyOverflowBeforeSimulatedFullscreen;handleSimulatedFullscreenKey=t=>{t.key==="Escape"&&this.exitSimulatedFullscreen()};handlePointerMove=t=>{const e=this.canvasPointFromEvent(t),i=e&&this.shapeAt(e.x,e.y),n=this.said.read(i?.shape.title);if(!n){this.tooltip.hidden=!0;return}this.tooltip.textContent=n,this.tooltip.hidden=!1;const s=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${t.clientX-s.left+12}px`,this.tooltip.style.top=`${t.clientY-s.top+12}px`};handleObserverMapPointerMove=t=>{if(this.dragObserverMap(t))return;const e=this.observerMapTargetFrom(t);if(!e){if(!this.observerPlacing){this.tooltip.hidden=!0,this.observerMapCanvas.style.cursor="grab";return}this.observerMapCanvas.style.cursor="crosshair",this.showObserverMapTooltip(t,this.messages.placeObserverHere);return}this.observerMapCanvas.style.cursor="pointer",this.showObserverMapTooltip(t,e.label)};showObserverMapTooltip(t,e){this.tooltip.textContent=e,this.tooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${t.clientX-i.left+12}px`,this.tooltip.style.top=`${t.clientY-i.top+12}px`}handleObserverMapClick=t=>{if(this.suppressObserverMapClick){this.suppressObserverMapClick=!1;return}const e=this.observerMapTargetFrom(t);if(!e){this.observerPlacing&&this.placeObserverFrom(t);return}if(e.kind==="milestone"&&e.t!==void 0){this.player.seek(e.t);return}this.dispatchEvent(new CustomEvent("lookat",{detail:{lat:e.lat,lng:e.lng,kind:e.kind},bubbles:!0,composed:!0}))};observerMapTargetFrom(t){const e=this.observerMapCanvas.getBoundingClientRect();if(!(e.width===0||e.height===0))return this.observerMapRenderer.hitTest((t.clientX-e.left)/e.width*this.observerMapCanvas.width,(t.clientY-e.top)/e.height*this.observerMapCanvas.height)}handlePointerLeave=()=>{this.tooltip.hidden=!0};handleObserverMapPointerDown=t=>{t.button===0&&(this.suppressObserverMapClick=!1,this.observerMapDrag={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,lastX:t.clientX,lastY:t.clientY,moved:!1})};handleObserverMapPointerUp=t=>{const e=this.observerMapDrag;!e||e.pointerId!==t.pointerId||(this.observerMapDrag=void 0,this.observerMapCanvas.classList.remove("dragging"),e.moved&&(this.suppressObserverMapClick=!0,this.paintObserverMap(this.currentTime),this.observerMapCanvas.hasPointerCapture?.(t.pointerId)&&this.observerMapCanvas.releasePointerCapture(t.pointerId)))};dragObserverMap(t){const e=this.observerMapDrag;if(!e||e.pointerId!==t.pointerId)return!1;if(!e.moved){if(Math.hypot(t.clientX-e.startX,t.clientY-e.startY)<pe.OBSERVER_MAP_DRAG_PX)return!1;e.moved=!0,this.tooltip.hidden=!0,this.observerMapCanvas.classList.add("dragging"),this.observerMapCanvas.setPointerCapture?.(t.pointerId)}const i=this.observerMapCanvas.getBoundingClientRect();return i.width>0&&i.height>0&&(this.observerMapView.panBy((t.clientX-e.lastX)/i.width,(t.clientY-e.lastY)/i.height),this.observerMapViewChanged()),e.lastX=t.clientX,e.lastY=t.clientY,!0}static OBSERVER_MAP_DRAG_PX=4;handleObserverMapWheel=t=>{t.preventDefault();const e=this.observerMapCanvas.getBoundingClientRect();if(e.width===0||e.height===0)return;const i=t.deltaMode===0?t.deltaY:t.deltaY*40;this.zoomObserverMap((t.clientX-e.left)/e.width,(t.clientY-e.top)/e.height,Math.exp(-i*.002))};zoomObserverMap(t,e,i){this.observerMapView.zoomAt(t,e,i),this.observerMapViewChanged()}observerMapViewChanged(){this.mapFitButton.hidden=!this.observerMapView.changed,this.mapZoomInButton.disabled=this.observerMapView.zoomFactor>=ni.MAX_ZOOM,this.mapZoomOutButton.disabled=this.observerMapView.zoomFactor<=ni.MIN_ZOOM,this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}scheduleObserverMapImagery(){this.observerMapImageryTimer===void 0&&(this.observerMapImageryTimer=setTimeout(()=>{this.observerMapImageryTimer=void 0,this.loadObserverMapImagery()},pe.OBSERVER_MAP_IMAGERY_DELAY_MS))}static OBSERVER_MAP_FOLLOW_MARGIN=.1;static OBSERVER_MAP_IMAGERY_DELAY_MS=300;get observerMapViewBounds(){return this.observerMapBounds&&this.observerMapView.boundsWithin(this.observerMapBounds)}placeObserverFrom(t){const e=this.observerMapViewBounds,i=this.observerMapCanvas.getBoundingClientRect();if(!e||i.width===0||i.height===0)return;const n=ni.pointAt(e,(t.clientX-i.left)/i.width,(t.clientY-i.top)/i.height);this.dispatchEvent(new CustomEvent("observerplace",{detail:n,bubbles:!0,composed:!0}))}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=`<style>${Kx}</style>${$x}`,this.shadow.appendChild(t.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new al(this.canvas.getContext("2d")),this.tooltip=this.shadow.getElementById("tooltip"),this.toolbar=this.shadow.getElementById("toolbar"),this.issuesBox=this.shadow.getElementById("issues"),this.issuesButton=this.shadow.getElementById("issues-button"),this.issuesPanel=this.shadow.getElementById("issues-panel"),this.issuesButton.addEventListener("click",e=>{e.stopPropagation(),this.issuesPanel.hidden=!this.issuesPanel.hidden,this.issuesButton.setAttribute("aria-expanded",String(!this.issuesPanel.hidden))}),this.playPauseButton=this.shadow.getElementById("play-pause"),this.fullscreenButton=this.shadow.getElementById("fullscreen"),this.cornerButtons=this.shadow.getElementById("corner-buttons"),this.observerMapButton=this.shadow.getElementById("observer-map"),this.referencesButton=this.shadow.getElementById("references"),this.tracesButton=this.shadow.getElementById("traces"),this.referenceOpacityInput=this.shadow.getElementById("reference-opacity"),this.referencesMenu=this.shadow.getElementById("references-menu"),this.milestonesButton=this.shadow.getElementById("milestones"),this.observerMapPanel=this.shadow.getElementById("observer-map-panel"),this.observerMapCanvas=this.shadow.getElementById("observer-map-canvas"),this.observerMapRenderer=new la(this.observerMapCanvas.getContext("2d")),this.mapZoomInButton=this.shadow.getElementById("map-zoom-in"),this.mapZoomOutButton=this.shadow.getElementById("map-zoom-out"),this.mapFitButton=this.shadow.getElementById("map-fit"),this.seekInput=this.shadow.getElementById("seek"),this.playbackFlash=this.shadow.getElementById("playback-flash"),this.milestoneMarks=this.shadow.getElementById("milestone-marks"),this.milestoneCaption=this.shadow.getElementById("milestone-caption"),this.timeStartLabel=this.shadow.getElementById("time-start"),this.timeEndLabel=this.shadow.getElementById("time-end"),this.timePill=this.shadow.getElementById("time"),this.muteButton=this.shadow.getElementById("mute"),this.controlsRight=this.shadow.getElementById("controls-right"),this.seekSegments=this.shadow.getElementById("seek-segments"),this.seekDot=this.shadow.getElementById("seek-dot"),this.seekPreview=this.shadow.getElementById("seek-preview"),this.seekPreviewCanvas=this.shadow.getElementById("seek-preview-canvas"),this.seekPreviewTitle=this.shadow.getElementById("seek-preview-title"),this.seekPreviewTime=this.shadow.getElementById("seek-preview-time"),this.timePill.addEventListener("click",()=>this.toggleTimeDisplay()),this.timePill.addEventListener("keydown",e=>{e.key!=="Enter"&&e.key!==" "||(e.preventDefault(),this.toggleTimeDisplay())}),this.volumeInput=this.shadow.getElementById("volume"),this.controlsRow=this.shadow.querySelector(".controls"),this.momentsBox=this.shadow.getElementById("moments"),this.momentsButton=this.shadow.getElementById("moments-button"),this.momentsCurrent=this.shadow.getElementById("moments-current"),this.momentsMenu=this.shadow.getElementById("moments-menu"),this.momentsButton.addEventListener("click",()=>this.toggleMomentsMenu()),this.moreButton=this.shadow.getElementById("controls-more"),this.moreButton.addEventListener("click",()=>this.setControlsFolded(this.controlsRow.classList.contains("more-open"))),this.muteButton.addEventListener("click",()=>this.toggleMuted()),this.volumeInput.addEventListener("input",()=>{this.setVolume(Number(this.volumeInput.value))}),this.fullscreenTarget=this.stageElement,this.playPauseButton.addEventListener("click",()=>this.togglePlayPause()),this.fullscreenButton.addEventListener("click",()=>this.toggleFullscreen()),this.addEventListener("keydown",this.handleFullscreenKey),this.observerMapButton.addEventListener("click",()=>this.toggleObserverMap()),this.referencesButton.addEventListener("click",()=>this.toggleReferences()),this.tracesButton.addEventListener("click",()=>this.toggleTraces()),this.referenceOpacityInput.addEventListener("input",()=>{this.referenceOpacityTouched=!0,this.dispatchReferenceView()}),this.milestonesButton.addEventListener("click",()=>this.toggleMilestones()),this.observerMapCanvas.addEventListener("pointermove",this.handleObserverMapPointerMove),this.observerMapCanvas.addEventListener("pointerleave",this.handlePointerLeave),this.observerMapCanvas.addEventListener("click",this.handleObserverMapClick),this.observerMapCanvas.addEventListener("pointerdown",this.handleObserverMapPointerDown),this.observerMapCanvas.addEventListener("pointerup",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("pointercancel",this.handleObserverMapPointerUp),this.observerMapCanvas.addEventListener("wheel",this.handleObserverMapWheel,{passive:!1}),this.mapZoomInButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,2)),this.mapZoomOutButton.addEventListener("click",()=>this.zoomObserverMap(.5,.5,.5)),this.mapFitButton.addEventListener("click",()=>{this.observerMapView.reset(),this.observerMapViewChanged()}),this.seekInput.addEventListener("input",()=>this.player.seek(this.snapSeekToMark(Number(this.seekInput.value)))),this.seekInput.addEventListener("pointerdown",e=>{this.suspendForScrub(),this.seekSnapArmed=!0,this.nameMarkUnder(e),this.beginTouchScrub(e)}),this.seekInput.addEventListener("pointerup",e=>{this.seekSnapArmed=!1,this.endTouchScrub(e)}),this.seekInput.addEventListener("pointercancel",e=>this.endTouchScrub(e)),this.seekInput.addEventListener("pointermove",e=>{this.nameMarkUnder(e),this.hoverSeek(e),this.touchScrub(e)}),this.seekInput.addEventListener("pointerleave",()=>{this.seekInput.removeAttribute("title"),this.leaveSeek()}),this.seekInput.addEventListener("keydown",this.handleSeekKey),this.stageElement.addEventListener("pointerdown",()=>{this.handlePointerDown(),this.touchedStage()},!0);for(const e of["touchend","click"])this.stageElement.addEventListener(e,()=>this.sightingAudio.resume(),!0);this.stageElement.addEventListener("pointermove",()=>this.touchedStage()),this.canvas.addEventListener("click",e=>{if(this.enableClickToPlay){if(this.tapRevealedOnly){this.tapRevealedOnly=!1;return}e.detail<=1&&(this.playbackBeforeClick={state:this.playbackState,time:this.currentTime}),this.togglePlayPause()}}),this.canvas.addEventListener("dblclick",e=>{this.enableClickToPlay&&(e.preventDefault(),this.restorePlayback(),this.toggleFullscreen())}),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerleave",this.handlePointerLeave),document.addEventListener("fullscreenchange",this.handleFullscreenChange),document.addEventListener("pointerdown",this.handleMomentsDismiss,!0),document.addEventListener("keydown",this.handleMomentsDismiss,!0),document.addEventListener("visibilitychange",this.handleVisibility),window.addEventListener("pagehide",this.handleHidden),document.addEventListener("pointerup",this.handlePointerRelease,!0),document.addEventListener("pointercancel",this.handlePointerRelease,!0),this.observerMapResizeObserver?.observe(this.observerMapPanel),this.controlsFitObserver?.observe(this.controlsRow),this.controlsFitObserver?.observe(this.controlsRow.querySelector(".controls-left")),typeof MutationObserver<"u"&&(this.controlsMutations=new MutationObserver(()=>this.fitControls()),this.controlsMutations.observe(this.controlsRight,{attributes:!0,attributeFilter:["hidden"],childList:!0,subtree:!0})),this.hostControls(void 0),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.refresh()}connectedCallback(){this.saidTexts=void 0,this.loadLocaleMessages();const t=this.getAttribute("src");t&&this.loadFromSrc(t)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange),document.removeEventListener("pointerdown",this.handleMomentsDismiss,!0),document.removeEventListener("keydown",this.handleMomentsDismiss,!0),document.removeEventListener("visibilitychange",this.handleVisibility),window.removeEventListener("pagehide",this.handleHidden),document.removeEventListener("pointerup",this.handlePointerRelease,!0),document.removeEventListener("pointercancel",this.handlePointerRelease,!0),window.clearTimeout(this.controlsIdleTimer),this.observerMapResizeObserver?.disconnect(),this.controlsFitObserver?.disconnect(),this.controlsMutations?.disconnect(),this.exitSimulatedFullscreen(),this.sightingAudio.dispose()}attributeChangedCallback(t,e,i){t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),t===ks&&this.applyObserverMapDefault(),t===Fs&&this.setMilestonesShown(!this.hasAttribute(Fs))}async loadFromSrc(t){this.sightingData=await Gc.json(t)}get sightingData(){return sb(this.currentSighting)}set sightingData(t){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=ab(t),this.issuesPanel.hidden=!0,this.issuesButton.setAttribute("aria-expanded","false"),this.reportIssues(t,this.currentSighting),this.observerMapView.reset(),this.mapFitButton.hidden=!0,this.observerMapAsked=!1,this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh(),this.applyObserverMapDefault()}get recordingIssues(){return this.issues}async reportIssues(t,e){const i=++this.issueCheck;let n=[];try{const{default:s}=await je(async()=>{const{default:r}=await import("./sightingSchema-5AlscPkV.js");return{default:r}},[],import.meta.url);n=new ts(s).issues(t)}catch{}i===this.issueCheck&&(this.issues=[...n,...e.loadIssues],Zo.warn(this.issues,e.id),this.renderIssues(),this.dispatchEvent(new CustomEvent(Cb,{detail:{issues:this.issues},bubbles:!0,composed:!0})))}renderIssues(){const t=this.issues.length;this.issuesBox.hidden=t===0,this.shadow.getElementById("issues-count").textContent=String(t);const e=this.messages.recordingIssues.replace("{count}",String(t));this.issuesButton.title=e,this.issuesButton.setAttribute("aria-label",e),this.shadow.getElementById("issues-title").textContent=e,this.shadow.getElementById("issues-list").replaceChildren(...this.issues.map(i=>{const n=document.createElement("li");return n.textContent=Zo.text(i,this.messages.issueTemplates),n}))}get sighting(){return this.currentSighting}previewSound(t){this.soundPreview=t,this.sightingAudio.resume(),this.sightingAudio.setSound(t)}stopSoundPreview(){this.soundPreview=void 0,this.sightingAudio.silence()}get canvasElement(){return this.canvas}get renderer(){return this.canvasRenderer}get currentTime(){return this.player.time}set currentTime(t){this.player.seek(t)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}set autoReplayEnabled(t){t!==this.loopEnabled&&this.toggleLoop()}play(){if(!(this.player.seekableDuration<=0||this.playbackState==="playing")){if(this.clockHeld){this.playAfterHold=!0;return}this.togglePlayPause()}}clockHeld=!1;playAfterHold=!1;holdClock(t){if(t!==this.clockHeld){if(this.clockHeld=t,t){if(this.playbackState!=="playing")return;this.playAfterHold=!0,this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh(),this.updatePlayPauseButton();return}this.playAfterHold&&(this.playAfterHold=!1,!(this.player.seekableDuration<=0||this.playbackState==="playing")&&(this.sightingAudio.resume(),this.player.play(),this.updatePlayPauseButton()))}}pause(){this.playAfterHold=!1,this.playbackState==="playing"&&this.togglePlayPause()}get positionLabel(){return this.timeStartLabel.textContent??""}get durationLabel(){return this.timeEndLabel.textContent??""}get showingClockTime(){return this.canShowClockTime}get canSwitchTimeDisplay(){return this.realStartMs!==void 0}toggleTimeDisplay(){this.canSwitchTimeDisplay&&(this.showClockTime=!this.showClockTime,this.updateTimeLabels(),this.updateTimeLabelTitles(),this.dispatchEvent(new CustomEvent("timedisplaychange",{bubbles:!0,composed:!0})))}get canShowClockTime(){return this.realStartMs!==void 0&&this.showClockTime}set showToolbar(t){this.toolbar.classList.toggle("hidden",!t),t?this.controlsRight.appendChild(this.fullscreenButton):this.cornerButtons.appendChild(this.fullscreenButton)}get playbackState(){return this.player.playbackState}get selectedSourceIds(){return this.highlightedSourceIds}get durationSeconds(){return this.currentSighting.event.durationSeconds}set durationSeconds(t){this.currentSighting.event.durationSeconds=t,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(t){const e=new Set(t);e.size===this.highlightedSourceIds.size&&[...e].every(n=>this.highlightedSourceIds.has(n))||(this.highlightedSourceIds=e,this.refresh())}hasVisibleShapeAt(t,e){return this.shapeAt(t,e)!==void 0}refresh(){this.applyFrameFormat(),this.updateMuteButton(),this.updateTimeLabels(),this.seekInput.max=String(this.player.seekableDuration),this.refreshMilestoneMarks(),this.updateMilestonesButton(),this.updateObserverMap(),this.updateReferences(),this.updateTracesButton(),this.player.seek(this.player.time)}hostControls(t){const e=[this.milestonesButton,this.referencesButton,this.referenceOpacityInput,this.tracesButton,this.observerMapButton];if(t)for(const i of e)t.appendChild(i);else{const i=this.fullscreenButton.parentElement===this.controlsRight?this.fullscreenButton:null;for(const n of e)this.controlsRight.insertBefore(n,i)}}get referencesShown(){return this.referencesShownState}get referenceOpacity(){return Number(this.referenceOpacityInput.value)}get severalReferences(){return this.currentSighting.references.length>1}toggleReferences(){if(this.severalReferences){this.toggleReferencesMenu();return}this.referencesShownState=!this.referencesShownState,this.updateReferencesButton(),this.dispatchReferenceView()}updateReferences(){const t=this.currentSighting.references;!this.referenceOpacityTouched&&t.length>0&&(this.referenceOpacityInput.value=String(t[0].opacity));for(const e of[...this.referenceViews.keys()])t.some(i=>i.id===e)||this.referenceViews.delete(e);this.severalReferences?this.referencesMenu.hidden||this.renderReferencesMenu():this.closeReferencesMenu(),this.updateReferencesButton(),this.severalReferences&&this.dispatchReferenceView()}viewOfReference(t){let e=this.referenceViews.get(t.id);return e||(e={shown:!0,opacity:t.opacity},this.referenceViews.set(t.id,e)),e}toggleReferencesMenu(){this.referencesMenu.hidden?this.openReferencesMenu():this.closeReferencesMenu()}openReferencesMenu(){this.renderReferencesMenu(),this.referencesMenu.hidden=!1,this.placeReferencesMenu(),this.referencesButton.setAttribute("aria-expanded","true"),document.addEventListener("pointerdown",this.handleReferencesMenuOutside,!0),document.addEventListener("keydown",this.handleReferencesMenuKey,!0)}closeReferencesMenu(){this.referencesMenu.hidden||(this.referencesMenu.hidden=!0,this.referencesButton.setAttribute("aria-expanded","false"),document.removeEventListener("pointerdown",this.handleReferencesMenuOutside,!0),document.removeEventListener("keydown",this.handleReferencesMenuKey,!0))}handleReferencesMenuOutside=t=>{const e=t.composedPath();e.includes(this.referencesMenu)||e.includes(this.referencesButton)||this.closeReferencesMenu()};handleReferencesMenuKey=t=>{t.key==="Escape"&&(this.closeReferencesMenu(),this.referencesButton.focus())};placeReferencesMenu(){const t=this.referencesButton.getBoundingClientRect(),e=this.referencesMenu,i=4;e.style.bottom=`${Math.max(i,window.innerHeight-t.top+i)}px`,e.style.top="auto";const n=e.getBoundingClientRect().width;e.style.left=`${Math.max(i,Math.min(t.left,window.innerWidth-n-i))}px`}renderReferencesMenu(){const t=this.currentSighting.references.map(e=>{const i=this.viewOfReference(e),n=this.said.read(e.title)??e.id,s=document.createElement("div");s.className="reference-row";const r=document.createElement("label"),o=document.createElement("input");o.type="checkbox",o.checked=i.shown;const c=document.createElement("span");c.textContent=n,c.title=n,r.append(o,c);const l=document.createElement("input");return l.type="range",l.min="0",l.max="1",l.step="0.05",l.value=String(i.opacity),l.title=this.messages.referenceOpacity,l.setAttribute("aria-label",`${this.messages.referenceOpacity}: ${n}`),l.disabled=!i.shown,o.addEventListener("change",()=>{i.shown=o.checked,l.disabled=!i.shown,this.updateReferencesButton(),this.dispatchReferenceView()}),l.addEventListener("input",()=>{i.opacity=Number(l.value),this.dispatchReferenceView()}),s.append(r,l),s});this.referencesMenu.setAttribute("aria-label",this.messages.referencesMenu),this.referencesMenu.replaceChildren(...t)}updateReferencesButton(){const t=this.currentSighting.references.length>0,e=this.severalReferences,i=e?this.currentSighting.references.some(s=>this.viewOfReference(s).shown):this.referencesShownState;this.referencesButton.hidden=!t,this.referenceOpacityInput.hidden=!t||!this.referencesShownState||e,this.referencesButton.setAttribute("aria-pressed",String(i)),e?this.referencesButton.setAttribute("aria-haspopup","true"):this.referencesButton.removeAttribute("aria-haspopup"),pe.setIcon(this.referencesButton,i?Gt.PICTURES_ON:Gt.PICTURES_OFF);const n=e?this.messages.referencesMenu:this.referencesShownState?this.messages.hideReferences:this.messages.showReferences;this.referencesButton.title=n,this.referencesButton.setAttribute("aria-label",n),this.referenceOpacityInput.title=this.messages.referenceOpacity,this.referenceOpacityInput.setAttribute("aria-label",this.messages.referenceOpacity)}get tracesShown(){return this.tracesShownState}toggleTraces(){this.tracesShownState=!this.tracesShownState,this.updateTracesButton(),this.updateObserverMap(),this.dispatchEvent(new CustomEvent("traceview",{detail:{shown:this.tracesShown}}))}updateTracesButton(){this.tracesButton.hidden=this.currentSighting.traces.length===0,this.tracesButton.setAttribute("aria-pressed",String(this.tracesShownState)),pe.setIcon(this.tracesButton,this.tracesShownState?Gt.TRACES_ON:Gt.TRACES_OFF);const t=this.tracesShownState?this.messages.hideTraces:this.messages.showTraces;this.tracesButton.title=t,this.tracesButton.setAttribute("aria-label",t)}dispatchReferenceView(){const t=this.severalReferences?Object.fromEntries(this.currentSighting.references.map(e=>[e.id,{...this.viewOfReference(e)}])):void 0;this.dispatchEvent(new CustomEvent("referenceview",{detail:{shown:this.referencesShown,opacity:this.referenceOpacity,views:t}}))}refreshMilestoneMarks(){const t=this.player.seekableDuration,e=t>0?Wc(this.sighting.milestones):[];this.milestoneMarks.replaceChildren(...e.map(i=>{const n=document.createElement("button");n.type="button",n.className="milestone-mark",n.style.left=`${Math.min(Math.max(i.t/t,0),1)*100}%`;const s=this.said.read(i.label)??"",r=this.said.read(i.note),o=r?`${s} — ${r}`:s;return n.title=o,n.setAttribute("aria-label",o),n.dataset.t=String(i.t),n.addEventListener("click",()=>this.player.seek(i.t)),n})),this.refreshSeekSegments(t,e.map(i=>i.t)),this.refreshMomentsPicker(e)}refreshMomentsPicker(t){const e=this.milestonesShown&&t.length>0;this.momentsBox.hidden=!e,this.closeMomentsMenu(),this.momentsMenu.replaceChildren(...t.map(i=>{const n=document.createElement("li"),s=document.createElement("button");s.type="button",s.dataset.t=String(i.t);const r=this.said.read(i.label)??"",o=this.said.read(i.note);return s.textContent=o?`${r} — ${o}`:r,s.addEventListener("click",()=>{this.player.seek(i.t),this.closeMomentsMenu()}),n.appendChild(s),n})),this.momentsButton.title=this.messages.moments,this.showCurrentMoment(void 0)}showCurrentMoment(t){const i=(t?this.said.read(t.label)??"":"")||this.messages.moments;this.momentsCurrent.textContent!==i&&(this.momentsCurrent.textContent=i);for(const n of this.momentsMenu.querySelectorAll("button")){const s=t!==void 0&&Number(n.dataset.t)===t.t;n.getAttribute("aria-current")==="true"!==s&&n.setAttribute("aria-current",String(s))}}toggleMomentsMenu(){this.momentsMenu.hidden?(this.momentsMenu.hidden=!1,this.momentsButton.setAttribute("aria-expanded","true")):this.closeMomentsMenu()}closeMomentsMenu(){this.momentsMenu.hidden=!0,this.momentsButton.setAttribute("aria-expanded","false")}handleMomentsDismiss=t=>{if(!this.momentsMenu.hidden){if(t instanceof KeyboardEvent){t.key==="Escape"&&this.closeMomentsMenu();return}t.composedPath().some(e=>e===this.momentsMenu||e===this.momentsButton)||this.closeMomentsMenu()}};seekSegmentList=[];refreshSeekSegments(t,e){const n=[0,...this.milestonesShown&&t>0?[...new Set(e.filter(r=>r>0&&r<t))].sort((r,o)=>r-o):[],Math.max(t,0)];this.seekSegmentList=[];const s=[];for(let r=0;r<n.length-1;r++){const o=document.createElement("div");o.className="seek-segment",o.style.flexGrow=String(Math.max(n[r+1]-n[r],1));const c=document.createElement("i");c.className="seek-hover";const l=document.createElement("i");l.className="seek-played",o.append(c,l),s.push(o),this.seekSegmentList.push({start:n[r],end:n[r+1],element:o,played:l,hover:c})}this.seekSegments.replaceChildren(...s),this.paintSeekProgress(this.player.time)}static fillOf(t,e){const i=t.end-t.start,n=i>0?(e-t.start)/i:e>=t.end?1:0;return`${Math.min(Math.max(n,0),1)*100}%`}paintSeekProgress(t){for(const i of this.seekSegmentList)i.played.style.width=pe.fillOf(i,t);const e=this.player.seekableDuration;this.seekDot.style.left=`${e>0?Math.min(Math.max(t/e,0),1)*100:0}%`}hoverSeek(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=Math.min(Math.max((t.clientX-e.left)/e.width,0),1),s=n*i,r=this.seekSegmentList.length-1;this.seekSegmentList.forEach((f,p)=>{f.hover.style.width=pe.fillOf(f,s),f.element.classList.toggle("hovered",s>=f.start&&(s<f.end||p===r))});const o=this.milestonesShown?this.sighting.milestones:[],c=o.length>0?Md(o,s):void 0,l=c?this.said.read(c.label)??"":"",h=c?this.said.read(c.note):void 0,u=h?`${l} — ${h}`:l;this.seekPreviewTitle.textContent=u,this.seekPreviewTime.textContent=this.formatPosition(s),this.seekPreview.hidden=!1;const d=this.seekPreview.offsetWidth;this.seekPreview.style.left=`${Math.min(Math.max(n*e.width-d/2,0),Math.max(e.width-d,0))}px`,this.paintSeekPreview(s)}leaveSeek(){for(const t of this.seekSegmentList)t.hover.style.width="0",t.element.classList.remove("hovered");this.seekPreview.hidden=!0}seekPreviewPainter;paintSeekPreview(t){const e=this.seekPreviewPainter;this.seekPreviewCanvas.hidden=e===void 0,e?.(t,this.seekPreviewCanvas)}scrubbingPointer;beginTouchScrub(t){if(t.pointerType!=="mouse"){this.scrubbingPointer=t.pointerId;try{this.seekInput.setPointerCapture(t.pointerId)}catch{}this.seekToPointer(t)}}touchScrub(t){t.pointerId===this.scrubbingPointer&&this.seekToPointer(t)}endTouchScrub(t){t.pointerId===this.scrubbingPointer&&(this.scrubbingPointer=void 0,this.seekToPointer(t))}seekToPointer(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=Math.min(Math.max((t.clientX-e.left)/e.width,0),1);this.player.seek(this.snapSeekToMark(n*i))}seekSnapArmed=!1;static MARK_SNAP_PX=6;markNear(t){const e=this.player.seekableDuration,i=this.seekInput.getBoundingClientRect().width;if(e<=0||i<=0)return;const n=pe.MARK_SNAP_PX/i*e;let s;for(const r of this.milestoneMarks.children){const o=Number(r.dataset.t);Math.abs(o-t)>n||(!s||Math.abs(o-t)<Math.abs(s.t-t))&&(s={t:o,name:r.title})}return s}snapSeekToMark(t){return this.seekSnapArmed?(this.seekSnapArmed=!1,this.markNear(t)?.t??t):t}nameMarkUnder(t){const e=this.seekInput.getBoundingClientRect(),i=this.player.seekableDuration;if(e.width<=0||i<=0)return;const n=(t.clientX-e.left)/e.width*i,s=this.markNear(n);s?this.seekInput.title=s.name:this.seekInput.removeAttribute("title")}showMilestoneAt(t){const e=this.milestonesShown&&this.sighting.milestones.length>0?Md(this.sighting.milestones,t):void 0;if(this.milestoneCaption.hidden=e===void 0,this.showCurrentMoment(e),!e)return;const i=document.createElement("b");i.textContent=this.said.read(e.label)??"";const n=this.said.read(e.note),s=n?` — ${n}`:"";this.milestoneCaption.replaceChildren(i,document.createTextNode(s))}exposureInstants(t){const e=this.exposureTimes(t),i=1/e.length;return e.map(n=>({shapes:this.shapesAt(n),share:i}))}exposureTimes(t=this.currentTime){const e=as.windowEndingAt(t,this.currentSighting.exposure??0);if(e.ms<pe.SHORTEST_VISIBLE_EXPOSURE_MS)return[t];const i=Math.min(pe.MAX_EXPOSURE_STEPS,Math.max(2,Math.round(e.ms/pe.SHORTEST_VISIBLE_EXPOSURE_MS))),n=Math.ceil(this.travelPxOver(e.fromMs,e.ms)/pe.EXPOSURE_STEP_PX),s=Math.min(pe.MAX_TRAVEL_STEPS,Math.max(i,n)),r=[];for(let o=0;o<s;o++)r.push(e.fromMs+e.ms*o/(s-1));return r}travelPxOver(t,e){const i=this.shapesAt(t),n=this.shapesAt(t+e);let s=0;for(const[r,o]of i){const c=n.get(r);if(!c)continue;const l=c.bounds.x+c.bounds.width/2-(o.bounds.x+o.bounds.width/2),h=c.bounds.y+c.bounds.height/2-(o.bounds.y+o.bounds.height/2);s=Math.max(s,Math.hypot(l,h))}return s}shapeAt(t,e,i){if(!this.accountHidden)for(const n of this.exposureTimes()){const s=this.currentSighting.timeline.hitTest(n,t,e,i);if(s)return s}}shapesAt(t){const e=new Map;for(const i of this.currentSighting.timeline.sourceIds){const n=this.currentSighting.timeline.getInterpolatedShapeAt(t,i);n&&e.set(i,n)}return e}static SHORTEST_VISIBLE_EXPOSURE_MS=20;static MAX_EXPOSURE_STEPS=48;static EXPOSURE_STEP_PX=2;static MAX_TRAVEL_STEPS=320;applyFrameFormat(){const t=bi.frameWidthPx(this.currentSighting.instrument,this.canvas.height);if(this.canvas.width===t)return;this.canvas.width=t,this.canvas.parentElement?.style.setProperty("--frame-aspect",`${t} / ${this.canvas.height}`)}canvasPointFromEvent(t){const e=this.canvas.getBoundingClientRect();if(!(e.width===0||e.height===0))return{x:(t.clientX-e.left)/e.width*this.canvas.width,y:(t.clientY-e.top)/e.height*this.canvas.height}}onFrame(t,e){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const i=this.playbackState!=="playing"?this.highlightedSourceIds:Ib;this.canvasRenderer.setStarPoints(bi.starPointsOf(this.sighting.instrument));const n=(Ze(this.sighting,t)?.rollDeg??0)+this.gaitAt(t).rollDeg;this.canvasRenderer.setRoll(n*Math.PI/180);const s=this.exposureInstants(t),r=this.frameShift;if(this.paintsShapes)for(const o of s)for(const[,c]of o.shapes){const l=o.share,h=l===1?c:{...c,transparency:1-(1-c.transparency)*l};this.canvasRenderer.paintShape(this.shifted(h,r))}for(const[o,c]of s[0].shapes)!this.selectionShown||!i.has(o)||(this.paintsShapes?i.size===1?this.canvasRenderer.paintShape({...c,selected:!0}):this.canvasRenderer.paintMemberOutline(c):this.canvasRenderer.paintSelectionOnly(this.shifted(c,r)));if(this.selectionShown&&i.size>1){const o=Dn.groupBoundsFor([...e].filter(([c])=>i.has(c)).map(([,c])=>c.bounds));this.canvasRenderer.paintGroupHandles(o)}this.overlayPainter?.(this.canvasRenderer),this.mapShapeBounds=s.flatMap(o=>[...o.shapes.values()].filter(c=>c.transparency<1).map(c=>this.shifted(c,r).bounds)),this.keepObserverMapClear(),this.seekInput.value=String(t),this.paintSeekProgress(t),this.timeStartLabel.textContent=this.formatPosition(t),this.showMilestoneAt(t),this.paintObserverMap(t),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(pM(this.currentSighting,t))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:t}}))}shifted(t,e){return e.x===0&&e.y===0?t:{...t,bounds:{...t.bounds,x:t.bounds.x+e.x,y:t.bounds.y+e.y}}}createPlayer(){const t=new Zx(this.currentSighting.timeline,(e,i)=>this.onFrame(e,i));return t.loop=this.loopEnabled,t.onEnded=()=>{this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("ended",{bubbles:!0,composed:!0}))},t}static SEEK_KEY_STEP_MS=5e3;handleFullscreenKey=t=>{t.key.toLowerCase()!=="f"||t.altKey||t.ctrlKey||t.metaKey||!this.enableClickToPlay||t.composedPath().some(i=>i instanceof HTMLElement&&(i.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(i.tagName)&&i.type!=="range"))||(t.preventDefault(),this.toggleFullscreen())};handleSeekKey=t=>{if(t.altKey||t.ctrlKey||t.metaKey)return;const e=t.key==="ArrowLeft"?-1:t.key==="ArrowRight"?1:0;if(e){t.preventDefault();const i=this.player.seekableDuration;this.player.seek(Math.min(i,Math.max(0,this.player.time+e*pe.SEEK_KEY_STEP_MS)))}else t.key===" "&&(t.preventDefault(),this.togglePlayPause())};togglePlayPause(){if(!(this.player.seekableDuration<=0)){if(this.player.playbackState==="playing")this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh();else if(this.clockHeld){this.playAfterHold=!this.playAfterHold;return}else this.sightingAudio.resume(),this.player.play();this.updatePlayPauseButton(),this.flashPlayback()}}flashPlayback(){const t=this.playbackFlash;t.innerHTML=this.player.playbackState==="playing"?Gt.PLAY:Gt.PAUSE,t.classList.remove("flashing"),t.offsetWidth,t.classList.add("flashing")}static icons=new WeakMap;static setIcon(t,e){pe.icons.get(t)!==e&&(pe.icons.set(t,e),t.innerHTML=e)}set captionHeld(t){this.stageElement.classList.toggle("caption-held",t)}static CONTROLS_IDLE_MS=3e3;controlsIdleTimer;wasPlaying=!1;quietControlsValue=!1;get quietControls(){return this.quietControlsValue}set quietControls(t){this.quietControlsValue=t,this.stageElement.classList.toggle("quiet",t)}tapRevealedOnly=!1;get hoverless(){return typeof matchMedia=="function"&&matchMedia("(hover: none)").matches}touchedStage(){if(!this.hoverless)return;this.player.playbackState==="playing"&&!this.stageElement.classList.contains("touched")&&(this.tapRevealedOnly=!0),this.revealControls()}pointerHeld=!1;handlePointerDown=()=>{this.pointerHeld=!0};resumeAfterScrub=!1;suspendForScrub(){this.player.playbackState==="playing"&&(this.resumeAfterScrub=!0,this.stopPlaying())}stopPlaying(){this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh(),this.updatePlayPauseButton()}resumeFromScrub(){this.resumeAfterScrub&&(this.resumeAfterScrub=!1,this.sightingAudio.resume(),this.player.play(),this.updatePlayPauseButton())}handleHidden=()=>{this.player.playbackState==="playing"&&this.stopPlaying(),this.resumeAfterScrub=!1};handleVisibility=()=>{document.visibilityState==="hidden"&&this.handleHidden()};handlePointerRelease=()=>{this.resumeAfterScrub&&window.setTimeout(()=>this.resumeFromScrub(),0),this.pointerHeld&&(this.pointerHeld=!1,this.hoverless&&this.stageElement.classList.contains("touched")&&this.revealControls())};revealControls(){this.stageElement.classList.add("touched"),window.clearTimeout(this.controlsIdleTimer),this.player.playbackState==="playing"&&(this.pointerHeld||!this.momentsMenu.hidden||(this.controlsIdleTimer=window.setTimeout(()=>{this.stageElement.classList.remove("touched"),this.tapRevealedOnly=!1},pe.CONTROLS_IDLE_MS)))}updatePlayPauseButton(){const t=this.player.playbackState==="playing";this.stageElement.classList.toggle("paused",!t),t!==this.wasPlaying&&t&&this.hoverless&&(!this.quietControlsValue||this.stageElement.classList.contains("touched"))&&this.revealControls(),this.wasPlaying=t,pe.setIcon(this.playPauseButton,t?Gt.PAUSE:Gt.PLAY);const e=this.player.seekableDuration>0;this.playPauseButton.disabled=!e;const i=e?t?this.messages.pause:this.messages.play:this.messages.noDuration;this.playPauseButton.title=i,this.playPauseButton.setAttribute("aria-label",i)}toggleLoop(){this.loopEnabled=!this.loopEnabled,this.player.loop=this.loopEnabled}restorePlayback(){const t=this.playbackBeforeClick;t&&(this.currentTime=t.time,t.state==="playing"?this.play():this.pause())}get canUseNativeFullscreen(){return typeof this.fullscreenTarget.requestFullscreen=="function"&&document.fullscreenEnabled}toggleFullscreen(){if(!this.canUseNativeFullscreen){this.simulatedFullscreen?this.exitSimulatedFullscreen():this.enterSimulatedFullscreen();return}document.fullscreenElement?document.exitFullscreen():this.fullscreenTarget.requestFullscreen().catch(t=>{console.error("<rr0-ufo>: requestFullscreen() failed —",t)})}enterSimulatedFullscreen(){const t=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen=t.getAttribute("style")??"",this.bodyOverflowBeforeSimulatedFullscreen=document.body.style.overflow;const e=t.style;e.setProperty("position","fixed"),e.setProperty("inset","0"),e.setProperty("margin","0"),e.setProperty("max-width","none"),e.setProperty("max-height","none"),e.setProperty("aspect-ratio","auto"),e.setProperty("z-index","2147483647"),e.setProperty("background","#000"),e.setProperty("width","100vw"),e.setProperty("width","100dvw"),e.setProperty("height","100vh"),e.setProperty("height","100dvh"),document.body.style.overflow="hidden",this.simulatedFullscreen=!0,document.addEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}exitSimulatedFullscreen(){if(!this.simulatedFullscreen)return;const t=this.fullscreenTarget;this.styleBeforeSimulatedFullscreen?t.setAttribute("style",this.styleBeforeSimulatedFullscreen):t.removeAttribute("style"),document.body.style.overflow=this.bodyOverflowBeforeSimulatedFullscreen??"",this.simulatedFullscreen=!1,document.removeEventListener("keydown",this.handleSimulatedFullscreenKey),this.updateFullscreenButton(),this.updateMuteButton()}toggleObserverMap(){const t=this.observerMapPanel.hidden;this.observerMapAsked=t,this.setObserverMapOpen(t),this.keepObserverMapClear(),this.dispatchEvent(new CustomEvent("observermapchange",{bubbles:!0,composed:!0,detail:{open:t}}))}get observerMapOpen(){return!this.observerMapPanel.hidden}get milestonesVisible(){return this.milestonesShown}observerMapAsked=!1;applyObserverMapDefault(){const t=this.getAttribute(ks),e=t===null?this.sighting.observerMap??this.observerPath?.travels===!0:t!=="false";this.setObserverMapOpen(e&&this.observerPath!==void 0)}setObserverMapOpen(t){this.observerMapPanel.hidden=!t,this.observerMapPanel.removeAttribute("title"),this.observerMapButton.setAttribute("aria-pressed",String(t)),this.updateObserverMapButton(),t&&(this.sizeObserverMapCanvas(),this.loadObserverMapImagery(),this.paintObserverMap(this.currentTime))}updateObserverMapButton(){const t=!this.observerMapPanel.hidden;pe.setIcon(this.observerMapButton,t?Gt.MAP_ON:Gt.MAP_OFF);const e=t?this.messages.hideObserverMap:this.messages.showObserverMap;this.observerMapButton.title=e,this.observerMapButton.setAttribute("aria-label",e);const i=[[this.mapZoomInButton,this.messages.zoomMapIn],[this.mapZoomOutButton,this.messages.zoomMapOut],[this.mapFitButton,this.messages.fitMap]];for(const[n,s]of i)n.title=s,n.setAttribute("aria-label",s)}updateObserverMap(){const t=this.observerPath!==void 0;if(this.observerPath=Fo.of(this.currentSighting),this.observerMapButton.hidden=this.observerPath===void 0,!t&&this.observerPath&&this.applyObserverMapDefault(),!this.observerPath){this.setObserverMapOpen(!1),this.observerMapBounds=void 0;return}const e=this.tracesShownState?this.currentSighting.traces.flatMap(n=>n.points):[],i=ni.including(this.observerPath.boundsAround(pe.OBSERVER_MAP_MIN_SPAN_M,pe.OBSERVER_MAP_MARGIN),e);(!this.observerMapBounds||!this.sameGround(this.observerMapBounds,i))&&(this.observerMapBounds&&this.observerMapView.refit(this.observerMapBounds,i),this.observerMapBounds=i,this.observerMapImagery=void 0,this.observerMapImageryCredit=void 0,this.observerMapImageryFailed=!1,this.observerMapImageryBounds=void 0,this.observerMapImageryLoading=!1,this.observerMapPanel.hidden||this.loadObserverMapImagery())}sameGround(t,e){const i=Math.abs(t.east-t.west)/20;return Math.abs(t.north-e.north)<i&&Math.abs(t.south-e.south)<i&&Math.abs(t.west-e.west)<i&&Math.abs(t.east-e.east)<i}async loadObserverMapImagery(){const t=this.observerMapViewBounds;if(!t||this.observerMapPanel.hidden||this.observerMapImageryLoading||!this.observerMapImageryNeededFor(t))return;const e=this.observerMapView.changed,i=e?ni.expand(t,pe.OBSERVER_MAP_IMAGERY_AHEAD):t,n=pe.OBSERVER_MAP_IMAGERY_PX*(e?1+2*pe.OBSERVER_MAP_IMAGERY_AHEAD:1);this.observerMapImageryBounds=i,this.observerMapImageryViewWidth=t.east-t.west,this.observerMapImageryLoading=!0;const s=CM();try{const r=await s.getImageryTexture(i,{width:n,height:n});if(this.observerMapImageryBounds!==i)return;this.observerMapImagery=r,this.observerMapImageryCredit=s.attribution,this.observerMapImageryFailed=!1}catch{if(this.observerMapImageryBounds!==i)return;this.observerMapImageryFailed=this.observerMapImagery===void 0}finally{this.observerMapImageryBounds===i&&(this.observerMapImageryLoading=!1)}this.paintObserverMap(this.currentTime),this.scheduleObserverMapImagery()}static OBSERVER_MAP_IMAGERY_AHEAD=.5;static OBSERVER_MAP_IMAGERY_LOOKAHEAD=.25;observerMapImageryNeededFor(t){const e=this.observerMapImageryBounds;if(!e)return!0;const i=this.observerMapImagery?.bounds??e,n=this.observerMapView.changed?ni.expand(t,pe.OBSERVER_MAP_IMAGERY_LOOKAHEAD):t,s=n.west>=i.west&&n.east<=i.east&&n.south>=i.south&&n.north<=i.north,r=t.east-t.west>this.observerMapImageryViewWidth/2;return!s||!r}get observerMapCredit(){return this.observerMapImageryCredit}get observerMapFooterLine(){return this.observerMapImageryFailed?this.messages.mapImageryUnavailable:this.creditShownExternally?void 0:this.observerMapImageryCredit}mapShapeBounds=[];mapSceneBounds=[];setMapSubjectBounds(t){this.mapSceneBounds=t.map(e=>({x:e.x*this.canvas.width,y:e.y*this.canvas.height,width:e.width*this.canvas.width,height:e.height*this.canvas.height})),this.keepObserverMapClear()}keepObserverMapClear(){if(this.observerMapPanel.hidden)return;const t=this.observerMapBoxPx;if(!t)return;const e=[...this.mapShapeBounds,...this.mapSceneBounds],i=(l,h,u)=>{for(const d of e)if(!(d.x+d.width<l-u||d.x>h+u)&&!(d.y>t.bottom+u||d.y+d.height<t.top-u))return!0;return!1},n=[this.canvas.width-t.width,this.canvas.width],s=[0,t.width],r=pe.OBSERVER_MAP_CLEARANCE_PX,o=i(...n,0),c=i(...s,0);if(this.observerMapPanel.classList.toggle("subject-overlap",o&&c&&!this.observerMapAsked),this.observerMapPanel.classList.contains("on-the-left")){!o&&(c||!i(n[0],n[1],r))&&this.observerMapPanel.classList.remove("on-the-left");return}i(n[0],n[1],0)&&!i(s[0],s[1],0)&&this.observerMapPanel.classList.add("on-the-left")}observerMapBoxPx;static OBSERVER_MAP_CLEARANCE_PX=24;sizeObserverMapCanvas(){const t=this.observerMapPanel.clientWidth;if(t===0)return;const e=Math.round(t*(globalThis.devicePixelRatio??1));this.measureObserverMapBox(),this.observerMapCanvas.width!==e&&(this.observerMapCanvas.width=e,this.observerMapCanvas.height=e)}measureObserverMapBox(){const t=this.observerMapPanel.getBoundingClientRect(),e=this.canvas.getBoundingClientRect();if(e.width===0||e.height===0)return;const i=this.canvas.width/e.width,n=this.canvas.height/e.height;this.observerMapBoxPx={width:t.width*i,top:(t.top-e.top)*n,bottom:(t.bottom-e.top)*n}}paintObserverMap(t){if(this.observerMapPanel.hidden||!this.observerPath||!this.observerMapBounds)return;const e=Ze(this.currentSighting,t);e?.lat!==void 0&&e.lng!==void 0&&!this.observerMapDrag?.moved&&this.observerMapView.keepInView(this.observerMapBounds,{lat:e.lat,lng:e.lng},pe.OBSERVER_MAP_FOLLOW_MARGIN)&&this.scheduleObserverMapImagery();const i=this.currentSighting.instrument,n=[],s=this.currentSighting.milestones.length>0?Md(this.currentSighting.milestones,t):void 0;for(const r of this.milestonesShown?Wc(this.currentSighting.milestones):[]){const o=Ze(this.currentSighting,r.t);o?.lat===void 0||o.lng===void 0||n.push({label:this.said.read(r.label)??"",note:this.said.read(r.note),t:r.t,lat:o.lat,lng:o.lng,current:r===s})}this.observerMapRenderer.paint({bounds:this.observerMapViewBounds,imagery:this.observerMapImagery,path:this.observerPath,position:e?.lat!==void 0&&e.lng!==void 0?{lat:e.lat,lng:e.lng}:void 0,headingDeg:e?.headingDeg===void 0?void 0:e.headingDeg+this.lookYawDeg,coneHalfAngleDeg:e?rr.of(i,this.canvas.height,e.fovDeg).halfWidthAngleDeg(bi.aspectOf(i)):void 0,markers:n,traces:(this.tracesShownState?this.currentSighting.traces:[]).map(r=>({kind:r.kind,points:r.points,color:r.color,label:this.said.read(r.title)})),decor:this.observerMapDecorAt(t),observerLabel:this.said.read(this.currentSighting.observer?.title)??this.messages.observerHere,nightFraction:this.observerMapNightFraction,attribution:this.observerMapFooterLine})}toggleMilestones(){this.setMilestonesShown(!this.milestonesShown)}setMilestonesShown(t){this.milestonesShown=t,this.milestoneMarks.hidden=!t,this.momentsBox.hidden=!t||this.sighting.milestones.length===0,this.refreshSeekSegments(this.player.seekableDuration,Wc(this.sighting.milestones).map(e=>e.t)),this.milestonesButton.setAttribute("aria-pressed",String(t)),this.updateMilestonesButton(),this.showMilestoneAt(this.currentTime),this.paintObserverMap(this.currentTime)}updateMilestonesButton(){this.milestonesButton.hidden=this.currentSighting.milestones.length===0,this.momentsButton.title=this.messages.moments,pe.setIcon(this.milestonesButton,this.milestonesShown?Gt.MILESTONES_ON:Gt.MILESTONES_OFF);const t=this.milestonesShown?this.messages.hideMilestones:this.messages.showMilestones;this.milestonesButton.title=t,this.milestonesButton.setAttribute("aria-label",t)}observerMapDecorAt(t){const e=Ze(this.currentSighting,0);return e?.lat===void 0||e.lng===void 0?[]:this.currentSighting.decor.filter(i=>i.kind!=="crop").map(i=>{const n=Hr(i,t),{lat:s,lng:r}=Nn(n.eastM,-n.northM,e.lat,e.lng);return{lat:s,lng:r,headingDeg:n.headingDeg,label:this.said.read(i.title)??this.messages.decorHere}})}observerMapNightFraction;setSunAltitude(t){const e=t===void 0?void 0:Math.max(0,Math.min(1,-t/12));e!==this.observerMapNightFraction&&(this.observerMapNightFraction=e,this.paintObserverMap(this.currentTime))}setLookOffset(t,e){t===this.lookYawDeg&&e===this.lookPitchDeg||(this.lookYawDeg=t,this.lookPitchDeg=e,this.refresh())}get frameShiftPx(){return this.frameShift}get frameShift(){const t=this.gaitAt(this.currentTime),e=this.lookYawDeg+t.yawDeg,i=this.lookPitchDeg+t.pitchDeg;if(e===0&&i===0)return{x:0,y:0};const n=Ze(this.currentSighting,this.currentTime),s=rr.of(this.currentSighting.instrument,this.canvas.height,n?.fovDeg??60);return{x:-s.angleDegToRadiusPx(e),y:s.angleDegToRadiusPx(i)}}gaitAt(t){return Ce.bodyAt(this.currentSighting,t,this.steadyBody)}mutedState=!1;get muted(){return this.mutedState}set muted(t){t!==this.mutedState&&(this.mutedState=t,!t&&this.volumeState===0&&(this.volumeState=pe.RESTORED_VOLUME),this.applyLevel())}volumeState=1;static RESTORED_VOLUME=.5;get volume(){return this.volumeState}set volume(t){this.setVolume(t)}setVolume(t){this.volumeState=Math.min(Math.max(t,0),1),this.mutedState=this.volumeState===0,this.applyLevel()}get level(){return this.mutedState?0:this.volumeState}applyLevel(){this.sightingAudio.setLevel(this.level),this.updateMuteButton(),this.dispatchEvent(new CustomEvent("mutedchange",{bubbles:!0,composed:!0,detail:{muted:this.mutedState,volume:this.volumeState}}))}toggleMuted(){this.hasSound&&(this.muted=!this.mutedState)}ambientSound;get hasSound(){return this.currentSighting.soundTrack.allKeyframes.length>0||this.ambientSound?.(this.currentSighting)===!0}updateMuteButton(){const t=!this.hasSound;if(this.muteButton.disabled=t,this.volumeInput.hidden=t,t){pe.setIcon(this.muteButton,Gt.MUTED),this.muteButton.title=this.messages.noSound,this.muteButton.setAttribute("aria-label",this.messages.noSound),this.muteButton.setAttribute("aria-pressed","true");return}pe.setIcon(this.muteButton,this.mutedState?Gt.MUTED:Gt.VOLUME);const e=this.mutedState?this.messages.unmute:this.messages.mute;this.muteButton.title=e,this.muteButton.setAttribute("aria-label",e),this.muteButton.setAttribute("aria-pressed",String(this.mutedState)),this.volumeInput.value=String(this.level)}updateFullscreenButton(){const t=this.simulatedFullscreen||document.fullscreenElement===this.fullscreenTarget;pe.setIcon(this.fullscreenButton,t?Gt.EXIT_FULLSCREEN:Gt.ENTER_FULLSCREEN),this.fullscreenButton.title=t?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}get said(){return this.saidTexts??=new Yn(Gr.preferencesFor(this))}saidTexts;async loadLocaleMessages(){const t=Ep(Gr.preferencesFor(this),Ap);if(t===this.messagesLanguage||t==="en"&&this.messagesLanguage===void 0)return;this.messagesLanguage=t;const e=await lb(t);this.messagesLanguage===t&&this.applyMessages(e)}messagesLanguage;updateTimeLabelTitles(){const t=this.showClockTime?this.messages.switchToElapsed:this.messages.switchToClockTime,e=this.canSwitchTimeDisplay?` — ${t}`:"";this.timeStartLabel.title=this.messages.currentPosition+e,this.timeEndLabel.title=this.messages.duration+e,this.timePill.classList.toggle("switchable",this.canSwitchTimeDisplay),this.canSwitchTimeDisplay?(this.timePill.setAttribute("role","button"),this.timePill.setAttribute("tabindex","0")):(this.timePill.removeAttribute("role"),this.timePill.removeAttribute("tabindex"))}applyMessages(t){this.messages=t,this.updateTimeLabelTitles(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.updateMuteButton(),this.updateObserverMapButton(),this.updateReferencesButton(),this.updateTracesButton(),this.updateMilestonesButton(),this.renderIssues()}updateTimeLabels(){const t=this.currentSighting.event,e=fM(t);this.realDurationMs=e!==void 0&&e>0?e:void 0,this.realStartMs=t.time?Yf(t.time):void 0;const i=this.currentSighting.timeline.duration;this.player.playbackRate=this.realDurationMs!==void 0&&i>0?i/this.realDurationMs:1,this.player.durationOverrideMs=i>0?0:this.realDurationMs??0,this.timeEndLabel.textContent=this.formatEndOfTimeline(),this.timeStartLabel.textContent=this.formatPosition(this.player.time),this.updateTimeLabelTitles()}formatPosition(t){if(this.realDurationMs===void 0)return Nl(t);const e=this.currentSighting.timeline.duration,i=e>0&&t<=e?t/e*this.realDurationMs:t;return this.canShowClockTime?gg(mg(this.realStartMs+i)):Nl(i)}formatEndOfTimeline(){return this.realDurationMs===void 0?Nl(this.currentSighting.timeline.duration):this.canShowClockTime?gg(mg(this.realStartMs+this.realDurationMs)):Nl(this.realDurationMs)}}function mg(a){const t=new Date(a);return{hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds()}}function gg(a){if(a.hour===void 0)return"0:00";const t=e=>String(e).padStart(2,"0");return a.second?`${t(a.hour)}:${t(a.minute??0)}:${t(a.second)}`:`${t(a.hour)}:${t(a.minute??0)}`}function Nl(a){const t=Math.round(a/1e3),e=Math.floor(t/60),i=t%60;return`${e}:${String(i).padStart(2,"0")}`}const Kf="rr0-ufo";function PM(){customElements.get(Kf)||customElements.define(Kf,pe)}const Cb="recordingissues";/**
2184
2184
  * @license
2185
2185
  * Copyright 2010-2026 Three.js Authors
2186
2186
  * SPDX-License-Identifier: MIT
2187
- */const Tp="185",Pb=0,vg=1,Ob=2,Xc=1,Lb=2,Lc=3,Xr=0,Qe=1,bn=2,Bs=0,Vr=1,Pi=2,Mg=3,yg=4,xl=5,ha=100,Nb=101,kb=102,Fb=103,Ub=104,Nc=200,ol=201,zb=202,Bb=203,Zf=204,cl=205,Hb=206,Gb=207,Vb=208,Wb=209,Xb=210,Yb=211,qb=212,$b=213,Kb=214,Jf=0,jf=1,Qf=2,Jo=3,t0=4,e0=5,i0=6,n0=7,Rp=0,Zb=1,Jb=2,Hs=0,OM=1,LM=2,NM=3,kM=4,FM=5,UM=6,zM=7,xg="attached",jb="detached",BM=300,Ba=301,jo=302,bd=303,Sd=304,ed=306,Qo=1e3,Bi=1001,s0=1002,Ue=1003,Qb=1004,kl=1005,de=1006,wd=1007,Aa=1008,Ln=1009,HM=1010,GM=1011,ll=1012,Dp=1013,Kn=1014,ji=1015,qe=1016,Ip=1017,Cp=1018,hl=1020,VM=35902,WM=35899,XM=1021,YM=1022,Gi=1023,lr=1026,Ta=1027,tc=1028,Pp=1029,Ha=1030,Op=1031,Lp=1033,Gh=33776,Vh=33777,Wh=33778,Xh=33779,r0=35840,a0=35841,o0=35842,c0=35843,l0=36196,h0=37492,u0=37496,d0=37488,f0=37489,bu=37490,p0=37491,m0=37808,g0=37809,v0=37810,M0=37811,y0=37812,x0=37813,b0=37814,S0=37815,w0=37816,_0=37817,E0=37818,A0=37819,T0=37820,R0=37821,D0=36492,I0=36494,C0=36495,P0=36283,O0=36284,Su=36285,L0=36286,qM=2200,tS=2201,eS=2202,wu=2300,N0=2301,_d=2302,bg=2303,Io=2400,Co=2401,_u=2402,Np=2500,iS=2501,rI=0,aI=1,oI=2,nS=3200,Eu=0,sS=1,Lr="",un="srgb",Au="srgb-linear",Tu="linear",Pe="srgb",Qa=7680,Sg=519,rS=512,aS=513,oS=514,kp=515,cS=516,lS=517,Fp=518,hS=519,k0=35044,Ru="300 es",Us=2e3,ul=2001;function uS(a){for(let t=a.length-1;t>=0;--t)if(a[t]>=65535)return!0;return!1}function dS(a){return ArrayBuffer.isView(a)&&!(a instanceof DataView)}function dl(a){return document.createElementNS("http://www.w3.org/1999/xhtml",a)}function fS(){const a=dl("canvas");return a.style.display="block",a}const wg={};function Du(...a){const t="THREE."+a.shift();console.log(t,...a)}function $M(a){const t=a[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=a[1];e&&e.isStackTrace?a[0]+=" "+e.getLocation():a[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return a}function Pt(...a){a=$M(a);const t="THREE."+a.shift();{const e=a[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...a)}}function qt(...a){a=$M(a);const t="THREE."+a.shift();{const e=a[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...a)}}function Uo(...a){const t=a.join(" ");t in wg||(wg[t]=!0,Pt(...a))}function pS(a,t,e){return new Promise(function(i,n){function s(){switch(a.clientWaitSync(t,a.SYNC_FLUSH_COMMANDS_BIT,0)){case a.WAIT_FAILED:n();break;case a.TIMEOUT_EXPIRED:setTimeout(s,e);break;default:i()}}setTimeout(s,e)})}const mS={[Jf]:jf,[Qf]:i0,[t0]:n0,[Jo]:e0,[jf]:Jf,[i0]:Qf,[n0]:t0,[e0]:Jo};class $r{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const n=i[t];if(n!==void 0){const s=n.indexOf(e);s!==-1&&n.splice(s,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const n=i.slice(0);for(let s=0,r=n.length;s<r;s++)n[s].call(this,t);t.target=null}}}const Xi=["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 _g=1234567;const Yc=Math.PI/180,ec=180/Math.PI;function ds(){const a=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Xi[a&255]+Xi[a>>8&255]+Xi[a>>16&255]+Xi[a>>24&255]+"-"+Xi[t&255]+Xi[t>>8&255]+"-"+Xi[t>>16&15|64]+Xi[t>>24&255]+"-"+Xi[e&63|128]+Xi[e>>8&255]+"-"+Xi[e>>16&255]+Xi[e>>24&255]+Xi[i&255]+Xi[i>>8&255]+Xi[i>>16&255]+Xi[i>>24&255]).toLowerCase()}function Qt(a,t,e){return Math.max(t,Math.min(e,a))}function Up(a,t){return(a%t+t)%t}function gS(a,t,e,i,n){return i+(a-t)*(n-i)/(e-t)}function vS(a,t,e){return a!==t?(e-a)/(t-a):0}function qc(a,t,e){return(1-e)*a+e*t}function MS(a,t,e,i){return qc(a,t,1-Math.exp(-e*i))}function yS(a,t=1){return t-Math.abs(Up(a,t*2)-t)}function xS(a,t,e){return a<=t?0:a>=e?1:(a=(a-t)/(e-t),a*a*(3-2*a))}function bS(a,t,e){return a<=t?0:a>=e?1:(a=(a-t)/(e-t),a*a*a*(a*(a*6-15)+10))}function SS(a,t){return a+Math.floor(Math.random()*(t-a+1))}function wS(a,t){return a+Math.random()*(t-a)}function _S(a){return a*(.5-Math.random())}function ES(a){a!==void 0&&(_g=a);let t=_g+=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 AS(a){return a*Yc}function TS(a){return a*ec}function RS(a){return(a&a-1)===0&&a!==0}function DS(a){return Math.pow(2,Math.ceil(Math.log(a)/Math.LN2))}function IS(a){return Math.pow(2,Math.floor(Math.log(a)/Math.LN2))}function CS(a,t,e,i,n){const s=Math.cos,r=Math.sin,o=s(e/2),c=r(e/2),l=s((t+i)/2),h=r((t+i)/2),u=s((t-i)/2),d=r((t-i)/2),f=s((i-t)/2),p=r((i-t)/2);switch(n){case"XYX":a.set(o*h,c*u,c*d,o*l);break;case"YZY":a.set(c*d,o*h,c*u,o*l);break;case"ZXZ":a.set(c*u,c*d,o*h,o*l);break;case"XZX":a.set(o*h,c*p,c*f,o*l);break;case"YXY":a.set(c*f,o*h,c*p,o*l);break;case"ZYZ":a.set(c*p,c*f,o*h,o*l);break;default:Pt("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function hs(a,t){switch(t.constructor){case Float32Array:return a;case Uint32Array:return a/4294967295;case Uint16Array:return a/65535;case Uint8Array:return a/255;case Int32Array:return Math.max(a/2147483647,-1);case Int16Array:return Math.max(a/32767,-1);case Int8Array:return Math.max(a/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function Oe(a,t){switch(t.constructor){case Float32Array:return a;case Uint32Array:return Math.round(a*4294967295);case Uint16Array:return Math.round(a*65535);case Uint8Array:return Math.round(a*255);case Int32Array:return Math.round(a*2147483647);case Int16Array:return Math.round(a*32767);case Int8Array:return Math.round(a*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const cI={DEG2RAD:Yc,RAD2DEG:ec,generateUUID:ds,clamp:Qt,euclideanModulo:Up,mapLinear:gS,inverseLerp:vS,lerp:qc,damp:MS,pingpong:yS,smoothstep:xS,smootherstep:bS,randInt:SS,randFloat:wS,randFloatSpread:_S,seededRandom:ES,degToRad:AS,radToDeg:TS,isPowerOfTwo:RS,ceilPowerOfTwo:DS,floorPowerOfTwo:IS,setQuaternionFromProperEuler:CS,normalize:Oe,denormalize:hs};class bt{static{bt.prototype.isVector2=!0}constructor(t=0,e=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("THREE.Vector2: 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("THREE.Vector2: 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,i=this.y,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6],this.y=n[1]*e+n[4]*i+n[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=Qt(this.x,t.x,e.x),this.y=Qt(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=Qt(this.x,t,e),this.y=Qt(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qt(i,t,e))}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 i=this.dot(t)/e;return Math.acos(Qt(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,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 i=Math.cos(e),n=Math.sin(e),s=this.x-t.x,r=this.y-t.y;return this.x=s*i-r*n+t.x,this.y=s*n+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Sn{constructor(t=0,e=0,i=0,n=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=n}static slerpFlat(t,e,i,n,s,r,o){let c=i[n+0],l=i[n+1],h=i[n+2],u=i[n+3],d=s[r+0],f=s[r+1],p=s[r+2],v=s[r+3];if(u!==v||c!==d||l!==f||h!==p){let m=c*d+l*f+h*p+u*v;m<0&&(d=-d,f=-f,p=-p,v=-v,m=-m);let g=1-o;if(m<.9995){const b=Math.acos(m),S=Math.sin(b);g=Math.sin(g*b)/S,o=Math.sin(o*b)/S,c=c*g+d*o,l=l*g+f*o,h=h*g+p*o,u=u*g+v*o}else{c=c*g+d*o,l=l*g+f*o,h=h*g+p*o,u=u*g+v*o;const b=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=b,l*=b,h*=b,u*=b}}t[e]=c,t[e+1]=l,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,n,s,r){const o=i[n],c=i[n+1],l=i[n+2],h=i[n+3],u=s[r],d=s[r+1],f=s[r+2],p=s[r+3];return t[e]=o*p+h*u+c*f-l*d,t[e+1]=c*p+h*d+l*u-o*f,t[e+2]=l*p+h*f+o*d-c*u,t[e+3]=h*p-o*u-c*d-l*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,i,n){return this._x=t,this._y=e,this._z=i,this._w=n,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 i=t._x,n=t._y,s=t._z,r=t._order,o=Math.cos,c=Math.sin,l=o(i/2),h=o(n/2),u=o(s/2),d=c(i/2),f=c(n/2),p=c(s/2);switch(r){case"XYZ":this._x=d*h*u+l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u-d*f*p;break;case"YXZ":this._x=d*h*u+l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u+d*f*p;break;case"ZXY":this._x=d*h*u-l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u-d*f*p;break;case"ZYX":this._x=d*h*u-l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u+d*f*p;break;case"YZX":this._x=d*h*u+l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u-d*f*p;break;case"XZY":this._x=d*h*u-l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u+d*f*p;break;default:Pt("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,n=Math.sin(i);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],n=e[4],s=e[8],r=e[1],o=e[5],c=e[9],l=e[2],h=e[6],u=e[10],d=i+o+u;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(h-c)*f,this._y=(s-l)*f,this._z=(r-n)*f}else if(i>o&&i>u){const f=2*Math.sqrt(1+i-o-u);this._w=(h-c)/f,this._x=.25*f,this._y=(n+r)/f,this._z=(s+l)/f}else if(o>u){const f=2*Math.sqrt(1+o-i-u);this._w=(s-l)/f,this._x=(n+r)/f,this._y=.25*f,this._z=(c+h)/f}else{const f=2*Math.sqrt(1+u-i-o);this._w=(r-n)/f,this._x=(s+l)/f,this._y=(c+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(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=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Qt(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const n=Math.min(1,e/i);return this.slerp(t,n),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 i=t._x,n=t._y,s=t._z,r=t._w,o=e._x,c=e._y,l=e._z,h=e._w;return this._x=i*h+r*o+n*l-s*c,this._y=n*h+r*c+s*o-i*l,this._z=s*h+r*l+i*c-n*o,this._w=r*h-i*o-n*c-s*l,this._onChangeCallback(),this}slerp(t,e){let i=t._x,n=t._y,s=t._z,r=t._w,o=this.dot(t);o<0&&(i=-i,n=-n,s=-s,r=-r,o=-o);let c=1-e;if(o<.9995){const l=Math.acos(o),h=Math.sin(l);c=Math.sin(c*l)/h,e=Math.sin(e*l)/h,this._x=this._x*c+i*e,this._y=this._y*c+n*e,this._z=this._z*c+s*e,this._w=this._w*c+r*e,this._onChangeCallback()}else this._x=this._x*c+i*e,this._y=this._y*c+n*e,this._z=this._z*c+s*e,this._w=this._w*c+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),n=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(n*Math.sin(t),n*Math.cos(t),s*Math.sin(e),s*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{static{R.prototype.isVector3=!0}constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,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("THREE.Vector3: 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("THREE.Vector3: 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(Eg.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Eg.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6]*n,this.y=s[1]*e+s[4]*i+s[7]*n,this.z=s[2]*e+s[5]*i+s[8]*n,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t.elements,r=1/(s[3]*e+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*e+s[4]*i+s[8]*n+s[12])*r,this.y=(s[1]*e+s[5]*i+s[9]*n+s[13])*r,this.z=(s[2]*e+s[6]*i+s[10]*n+s[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,o=t.z,c=t.w,l=2*(r*n-o*i),h=2*(o*e-s*n),u=2*(s*i-r*e);return this.x=e+c*l+r*u-o*h,this.y=i+c*h+o*l-s*u,this.z=n+c*u+s*h-r*l,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,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[4]*i+s[8]*n,this.y=s[1]*e+s[5]*i+s[9]*n,this.z=s[2]*e+s[6]*i+s[10]*n,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=Qt(this.x,t.x,e.x),this.y=Qt(this.y,t.y,e.y),this.z=Qt(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=Qt(this.x,t,e),this.y=Qt(this.y,t,e),this.z=Qt(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qt(i,t,e))}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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,o=e.y,c=e.z;return this.x=n*c-s*o,this.y=s*r-i*c,this.z=i*o-n*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Ed.copy(this).projectOnVector(t),this.sub(Ed)}reflect(t){return this.sub(Ed.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 i=this.dot(t)/e;return Math.acos(Qt(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,n=this.z-t.z;return e*e+i*i+n*n}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,i){const n=Math.sin(e)*t;return this.x=n*Math.sin(i),this.y=Math.cos(e)*t,this.z=n*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,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(),i=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=n,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,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Ed=new R,Eg=new Sn;class Jt{static{Jt.prototype.isMatrix3=!0}constructor(t,e,i,n,s,r,o,c,l){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,n,s,r,o,c,l)}set(t,e,i,n,s,r,o,c,l){const h=this.elements;return h[0]=t,h[1]=n,h[2]=o,h[3]=e,h[4]=s,h[5]=c,h[6]=i,h[7]=r,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.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 i=t.elements,n=e.elements,s=this.elements,r=i[0],o=i[3],c=i[6],l=i[1],h=i[4],u=i[7],d=i[2],f=i[5],p=i[8],v=n[0],m=n[3],g=n[6],b=n[1],S=n[4],M=n[7],x=n[2],_=n[5],E=n[8];return s[0]=r*v+o*b+c*x,s[3]=r*m+o*S+c*_,s[6]=r*g+o*M+c*E,s[1]=l*v+h*b+u*x,s[4]=l*m+h*S+u*_,s[7]=l*g+h*M+u*E,s[2]=d*v+f*b+p*x,s[5]=d*m+f*S+p*_,s[8]=d*g+f*M+p*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],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8];return e*r*h-e*o*l-i*s*h+i*o*c+n*s*l-n*r*c}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=h*r-o*l,d=o*c-h*s,f=l*s-r*c,p=e*u+i*d+n*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const v=1/p;return t[0]=u*v,t[1]=(n*l-h*i)*v,t[2]=(o*i-n*r)*v,t[3]=d*v,t[4]=(h*e-n*c)*v,t[5]=(n*s-o*e)*v,t[6]=f*v,t[7]=(i*c-l*e)*v,t[8]=(r*e-i*s)*v,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,i,n,s,r,o){const c=Math.cos(s),l=Math.sin(s);return this.set(i*c,i*l,-i*(c*r+l*o)+r+t,-n*l,n*c,-n*(-l*r+c*o)+o+e,0,0,1),this}scale(t,e){return Uo("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Ad.makeScale(t,e)),this}rotate(t){return Uo("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Ad.makeRotation(-t)),this}translate(t,e){return Uo("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Ad.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),i=Math.sin(t);return this.set(e,-i,0,i,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,i=t.elements;for(let n=0;n<9;n++)if(e[n]!==i[n])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const Ad=new Jt,Ag=new Jt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Tg=new Jt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function PS(){const a={enabled:!0,workingColorSpace:Au,spaces:{},convert:function(n,s,r){return this.enabled===!1||s===r||!s||!r||(this.spaces[s].transfer===Pe&&(n.r=or(n.r),n.g=or(n.g),n.b=or(n.b)),this.spaces[s].primaries!==this.spaces[r].primaries&&(n.applyMatrix3(this.spaces[s].toXYZ),n.applyMatrix3(this.spaces[r].fromXYZ)),this.spaces[r].transfer===Pe&&(n.r=zo(n.r),n.g=zo(n.g),n.b=zo(n.b))),n},workingToColorSpace:function(n,s){return this.convert(n,this.workingColorSpace,s)},colorSpaceToWorking:function(n,s){return this.convert(n,s,this.workingColorSpace)},getPrimaries:function(n){return this.spaces[n].primaries},getTransfer:function(n){return n===Lr?Tu:this.spaces[n].transfer},getToneMappingMode:function(n){return this.spaces[n].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(n,s=this.workingColorSpace){return n.fromArray(this.spaces[s].luminanceCoefficients)},define:function(n){Object.assign(this.spaces,n)},_getMatrix:function(n,s,r){return n.copy(this.spaces[s].toXYZ).multiply(this.spaces[r].fromXYZ)},_getDrawingBufferColorSpace:function(n){return this.spaces[n].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(n=this.workingColorSpace){return this.spaces[n].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(n,s){return Uo("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),a.workingToColorSpace(n,s)},toWorkingColorSpace:function(n,s){return Uo("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),a.colorSpaceToWorking(n,s)}},t=[.64,.33,.3,.6,.15,.06],e=[.2126,.7152,.0722],i=[.3127,.329];return a.define({[Au]:{primaries:t,whitePoint:i,transfer:Tu,toXYZ:Ag,fromXYZ:Tg,luminanceCoefficients:e,workingColorSpaceConfig:{unpackColorSpace:un},outputColorSpaceConfig:{drawingBufferColorSpace:un}},[un]:{primaries:t,whitePoint:i,transfer:Pe,toXYZ:Ag,fromXYZ:Tg,luminanceCoefficients:e,outputColorSpaceConfig:{drawingBufferColorSpace:un}}}),a}const me=PS();function or(a){return a<.04045?a*.0773993808:Math.pow(a*.9478672986+.0521327014,2.4)}function zo(a){return a<.0031308?a*12.92:1.055*Math.pow(a,.41666)-.055}let to;class OS{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{to===void 0&&(to=dl("canvas")),to.width=t.width,to.height=t.height;const n=to.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),i=to}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=dl("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const n=i.getImageData(0,0,t.width,t.height),s=n.data;for(let r=0;r<s.length;r++)s[r]=or(s[r]/255)*255;return i.putImageData(n,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(or(e[i]/255)*255):e[i]=or(e[i]);return{data:e,width:t.width,height:t.height}}else return Pt("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let LS=0;class zp{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:LS++}),this.uuid=ds(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayWidth,e.displayHeight,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}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 i={uuid:this.uuid,url:""},n=this.data;if(n!==null){let s;if(Array.isArray(n)){s=[];for(let r=0,o=n.length;r<o;r++)n[r].isDataTexture?s.push(Td(n[r].image)):s.push(Td(n[r]))}else s=Td(n);i.url=s}return e||(t.images[this.uuid]=i),i}}function Td(a){return typeof HTMLImageElement<"u"&&a instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&a instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&a instanceof ImageBitmap?OS.getDataURL(a):a.data?{data:Array.from(a.data),width:a.width,height:a.height,type:a.data.constructor.name}:(Pt("Texture: Unable to serialize Texture."),{})}let NS=0;const Rd=new R;class Hi extends $r{constructor(t=Hi.DEFAULT_IMAGE,e=Hi.DEFAULT_MAPPING,i=Bi,n=Bi,s=de,r=Aa,o=Gi,c=Ln,l=Hi.DEFAULT_ANISOTROPY,h=Lr){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:NS++}),this.uuid=ds(),this.name="",this.source=new zp(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=r,this.anisotropy=l,this.format=o,this.internalFormat=null,this.type=c,this.offset=new bt(0,0),this.repeat=new bt(1,1),this.center=new bt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Jt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Rd).x}get height(){return this.source.getSize(Rd).y}get depth(){return this.source.getSize(Rd).z}get image(){return this.source.data}set image(t){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)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}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.normalized=t.normalized,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.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){Pt(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const n=this[e];if(n===void 0){Pt(`Texture.setValues(): property '${e}' does not exist.`);continue}n&&i&&n.isVector2&&i.isVector2||n&&i&&n.isVector3&&i.isVector3||n&&i&&n.isMatrix3&&i.isMatrix3?n.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,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,normalized:this.normalized,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&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==BM)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Qo:t.x=t.x-Math.floor(t.x);break;case Bi:t.x=t.x<0?0:1;break;case s0: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 Qo:t.y=t.y-Math.floor(t.y);break;case Bi:t.y=t.y<0?0:1;break;case s0: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++}}Hi.DEFAULT_IMAGE=null;Hi.DEFAULT_MAPPING=BM;Hi.DEFAULT_ANISOTROPY=1;class ue{static{ue.prototype.isVector4=!0}constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n}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,i,n){return this.x=t,this.y=e,this.z=i,this.w=n,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("THREE.Vector4: 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("THREE.Vector4: 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,i=this.y,n=this.z,s=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*n+r[12]*s,this.y=r[1]*e+r[5]*i+r[9]*n+r[13]*s,this.z=r[2]*e+r[6]*i+r[10]*n+r[14]*s,this.w=r[3]*e+r[7]*i+r[11]*n+r[15]*s,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,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,i,n,s;const c=t.elements,l=c[0],h=c[4],u=c[8],d=c[1],f=c[5],p=c[9],v=c[2],m=c[6],g=c[10];if(Math.abs(h-d)<.01&&Math.abs(u-v)<.01&&Math.abs(p-m)<.01){if(Math.abs(h+d)<.1&&Math.abs(u+v)<.1&&Math.abs(p+m)<.1&&Math.abs(l+f+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const S=(l+1)/2,M=(f+1)/2,x=(g+1)/2,_=(h+d)/4,E=(u+v)/4,y=(p+m)/4;return S>M&&S>x?S<.01?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(S),n=_/i,s=E/i):M>x?M<.01?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(M),i=_/n,s=y/n):x<.01?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(x),i=E/s,n=y/s),this.set(i,n,s,e),this}let b=Math.sqrt((m-p)*(m-p)+(u-v)*(u-v)+(d-h)*(d-h));return Math.abs(b)<.001&&(b=1),this.x=(m-p)/b,this.y=(u-v)/b,this.z=(d-h)/b,this.w=Math.acos((l+f+g-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=Qt(this.x,t.x,e.x),this.y=Qt(this.y,t.y,e.y),this.z=Qt(this.z,t.z,e.z),this.w=Qt(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=Qt(this.x,t,e),this.y=Qt(this.y,t,e),this.z=Qt(this.z,t,e),this.w=Qt(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qt(i,t,e))}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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,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 kS extends $r{constructor(t=1,e=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:de,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},i),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=i.depth,this.scissor=new ue(0,0,t,e),this.scissorTest=!1,this.viewport=new ue(0,0,t,e),this.textures=[];const n={width:t,height:e,depth:i.depth},s=new Hi(n),r=i.count;for(let o=0;o<r;o++)this.textures[o]=s.clone(),this.textures[o].isRenderTargetTexture=!0,this.textures[o].renderTarget=this;this._setTextureOptions(i),this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.resolveDepthBuffer=i.resolveDepthBuffer,this.resolveStencilBuffer=i.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=i.depthTexture,this.samples=i.samples,this.multiview=i.multiview,this.useArrayDepthTexture=i.useArrayDepthTexture}_setTextureOptions(t={}){const e={minFilter:de,generateMipmaps:!1,flipY:!1,internalFormat:null};t.mapping!==void 0&&(e.mapping=t.mapping),t.wrapS!==void 0&&(e.wrapS=t.wrapS),t.wrapT!==void 0&&(e.wrapT=t.wrapT),t.wrapR!==void 0&&(e.wrapR=t.wrapR),t.magFilter!==void 0&&(e.magFilter=t.magFilter),t.minFilter!==void 0&&(e.minFilter=t.minFilter),t.format!==void 0&&(e.format=t.format),t.type!==void 0&&(e.type=t.type),t.anisotropy!==void 0&&(e.anisotropy=t.anisotropy),t.colorSpace!==void 0&&(e.colorSpace=t.colorSpace),t.flipY!==void 0&&(e.flipY=t.flipY),t.generateMipmaps!==void 0&&(e.generateMipmaps=t.generateMipmaps),t.internalFormat!==void 0&&(e.internalFormat=t.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(e)}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}set depthTexture(t){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),t!==null&&(t.renderTarget=this),this._depthTexture=t}get depthTexture(){return this._depthTexture}setSize(t,e,i=1){if(this.width!==t||this.height!==e||this.depth!==i){this.width=t,this.height=e,this.depth=i;for(let n=0,s=this.textures.length;n<s;n++)this.textures[n].image.width=t,this.textures[n].image.height=e,this.textures[n].image.depth=i,this.textures[n].isData3DTexture!==!0&&(this.textures[n].isArrayTexture=this.textures[n].image.depth>1);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 e=0,i=t.textures.length;e<i;e++){this.textures[e]=t.textures[e].clone(),this.textures[e].isRenderTargetTexture=!0,this.textures[e].renderTarget=this;const n=Object.assign({},t.textures[e].image);this.textures[e].source=new zp(n)}return 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.multiview=t.multiview,this.useArrayDepthTexture=t.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class oi extends kS{constructor(t=1,e=1,i={}){super(t,e,i),this.isWebGLRenderTarget=!0}}class KM extends Hi{constructor(t=null,e=1,i=1,n=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:i,depth:n},this.magFilter=Ue,this.minFilter=Ue,this.wrapR=Bi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class ZM extends Hi{constructor(t=null,e=1,i=1,n=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:i,depth:n},this.magFilter=Ue,this.minFilter=Ue,this.wrapR=Bi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class ne{static{ne.prototype.isMatrix4=!0}constructor(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m){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,i,n,s,r,o,c,l,h,u,d,f,p,v,m)}set(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m){const g=this.elements;return g[0]=t,g[4]=e,g[8]=i,g[12]=n,g[1]=s,g[5]=r,g[9]=o,g[13]=c,g[2]=l,g[6]=h,g[10]=u,g[14]=d,g[3]=f,g[7]=p,g[11]=v,g[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 ne().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[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,i){return this.determinantAffine()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();const e=this.elements,i=t.elements,n=1/eo.setFromMatrixColumn(t,0).length(),s=1/eo.setFromMatrixColumn(t,1).length(),r=1/eo.setFromMatrixColumn(t,2).length();return e[0]=i[0]*n,e[1]=i[1]*n,e[2]=i[2]*n,e[3]=0,e[4]=i[4]*s,e[5]=i[5]*s,e[6]=i[6]*s,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,n=t.y,s=t.z,r=Math.cos(i),o=Math.sin(i),c=Math.cos(n),l=Math.sin(n),h=Math.cos(s),u=Math.sin(s);if(t.order==="XYZ"){const d=r*h,f=r*u,p=o*h,v=o*u;e[0]=c*h,e[4]=-c*u,e[8]=l,e[1]=f+p*l,e[5]=d-v*l,e[9]=-o*c,e[2]=v-d*l,e[6]=p+f*l,e[10]=r*c}else if(t.order==="YXZ"){const d=c*h,f=c*u,p=l*h,v=l*u;e[0]=d+v*o,e[4]=p*o-f,e[8]=r*l,e[1]=r*u,e[5]=r*h,e[9]=-o,e[2]=f*o-p,e[6]=v+d*o,e[10]=r*c}else if(t.order==="ZXY"){const d=c*h,f=c*u,p=l*h,v=l*u;e[0]=d-v*o,e[4]=-r*u,e[8]=p+f*o,e[1]=f+p*o,e[5]=r*h,e[9]=v-d*o,e[2]=-r*l,e[6]=o,e[10]=r*c}else if(t.order==="ZYX"){const d=r*h,f=r*u,p=o*h,v=o*u;e[0]=c*h,e[4]=p*l-f,e[8]=d*l+v,e[1]=c*u,e[5]=v*l+d,e[9]=f*l-p,e[2]=-l,e[6]=o*c,e[10]=r*c}else if(t.order==="YZX"){const d=r*c,f=r*l,p=o*c,v=o*l;e[0]=c*h,e[4]=v-d*u,e[8]=p*u+f,e[1]=u,e[5]=r*h,e[9]=-o*h,e[2]=-l*h,e[6]=f*u+p,e[10]=d-v*u}else if(t.order==="XZY"){const d=r*c,f=r*l,p=o*c,v=o*l;e[0]=c*h,e[4]=-u,e[8]=l*h,e[1]=d*u+v,e[5]=r*h,e[9]=f*u-p,e[2]=p*u-f,e[6]=o*h,e[10]=v*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(FS,t,US)}lookAt(t,e,i){const n=this.elements;return En.subVectors(t,e),En.lengthSq()===0&&(En.z=1),En.normalize(),Mr.crossVectors(i,En),Mr.lengthSq()===0&&(Math.abs(i.z)===1?En.x+=1e-4:En.z+=1e-4,En.normalize(),Mr.crossVectors(i,En)),Mr.normalize(),Fl.crossVectors(En,Mr),n[0]=Mr.x,n[4]=Fl.x,n[8]=En.x,n[1]=Mr.y,n[5]=Fl.y,n[9]=En.y,n[2]=Mr.z,n[6]=Fl.z,n[10]=En.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],o=i[4],c=i[8],l=i[12],h=i[1],u=i[5],d=i[9],f=i[13],p=i[2],v=i[6],m=i[10],g=i[14],b=i[3],S=i[7],M=i[11],x=i[15],_=n[0],E=n[4],y=n[8],T=n[12],I=n[1],C=n[5],P=n[9],B=n[13],W=n[2],O=n[6],H=n[10],U=n[14],q=n[3],Q=n[7],J=n[11],it=n[15];return s[0]=r*_+o*I+c*W+l*q,s[4]=r*E+o*C+c*O+l*Q,s[8]=r*y+o*P+c*H+l*J,s[12]=r*T+o*B+c*U+l*it,s[1]=h*_+u*I+d*W+f*q,s[5]=h*E+u*C+d*O+f*Q,s[9]=h*y+u*P+d*H+f*J,s[13]=h*T+u*B+d*U+f*it,s[2]=p*_+v*I+m*W+g*q,s[6]=p*E+v*C+m*O+g*Q,s[10]=p*y+v*P+m*H+g*J,s[14]=p*T+v*B+m*U+g*it,s[3]=b*_+S*I+M*W+x*q,s[7]=b*E+S*C+M*O+x*Q,s[11]=b*y+S*P+M*H+x*J,s[15]=b*T+S*B+M*U+x*it,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],i=t[4],n=t[8],s=t[12],r=t[1],o=t[5],c=t[9],l=t[13],h=t[2],u=t[6],d=t[10],f=t[14],p=t[3],v=t[7],m=t[11],g=t[15],b=c*f-l*d,S=o*f-l*u,M=o*d-c*u,x=r*f-l*h,_=r*d-c*h,E=r*u-o*h;return e*(v*b-m*S+g*M)-i*(p*b-m*x+g*_)+n*(p*S-v*x+g*E)-s*(p*M-v*_+m*E)}determinantAffine(){const t=this.elements,e=t[0],i=t[4],n=t[8],s=t[1],r=t[5],o=t[9],c=t[2],l=t[6],h=t[10];return e*(r*h-o*l)-i*(s*h-o*c)+n*(s*l-r*c)}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,i){const n=this.elements;return t.isVector3?(n[12]=t.x,n[13]=t.y,n[14]=t.z):(n[12]=t,n[13]=e,n[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=t[9],d=t[10],f=t[11],p=t[12],v=t[13],m=t[14],g=t[15],b=e*o-i*r,S=e*c-n*r,M=e*l-s*r,x=i*c-n*o,_=i*l-s*o,E=n*l-s*c,y=h*v-u*p,T=h*m-d*p,I=h*g-f*p,C=u*m-d*v,P=u*g-f*v,B=d*g-f*m,W=b*B-S*P+M*C+x*I-_*T+E*y;if(W===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const O=1/W;return t[0]=(o*B-c*P+l*C)*O,t[1]=(n*P-i*B-s*C)*O,t[2]=(v*E-m*_+g*x)*O,t[3]=(d*_-u*E-f*x)*O,t[4]=(c*I-r*B-l*T)*O,t[5]=(e*B-n*I+s*T)*O,t[6]=(m*M-p*E-g*S)*O,t[7]=(h*E-d*M+f*S)*O,t[8]=(r*P-o*I+l*y)*O,t[9]=(i*I-e*P-s*y)*O,t[10]=(p*_-v*M+g*b)*O,t[11]=(u*M-h*_-f*b)*O,t[12]=(o*T-r*C-c*y)*O,t[13]=(e*C-i*T+n*y)*O,t[14]=(v*S-p*x-m*b)*O,t[15]=(h*x-u*S+d*b)*O,this}scale(t){const e=this.elements,i=t.x,n=t.y,s=t.z;return e[0]*=i,e[4]*=n,e[8]*=s,e[1]*=i,e[5]*=n,e[9]*=s,e[2]*=i,e[6]*=n,e[10]*=s,e[3]*=i,e[7]*=n,e[11]*=s,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],n=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,n))}makeTranslation(t,e,i){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,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),n=Math.sin(e),s=1-i,r=t.x,o=t.y,c=t.z,l=s*r,h=s*o;return this.set(l*r+i,l*o-n*c,l*c+n*o,0,l*o+n*c,h*o+i,h*c-n*r,0,l*c-n*o,h*c+n*r,s*c*c+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,n,s,r){return this.set(1,i,s,0,t,1,r,0,e,n,1,0,0,0,0,1),this}compose(t,e,i){const n=this.elements,s=e._x,r=e._y,o=e._z,c=e._w,l=s+s,h=r+r,u=o+o,d=s*l,f=s*h,p=s*u,v=r*h,m=r*u,g=o*u,b=c*l,S=c*h,M=c*u,x=i.x,_=i.y,E=i.z;return n[0]=(1-(v+g))*x,n[1]=(f+M)*x,n[2]=(p-S)*x,n[3]=0,n[4]=(f-M)*_,n[5]=(1-(d+g))*_,n[6]=(m+b)*_,n[7]=0,n[8]=(p+S)*E,n[9]=(m-b)*E,n[10]=(1-(d+v))*E,n[11]=0,n[12]=t.x,n[13]=t.y,n[14]=t.z,n[15]=1,this}decompose(t,e,i){const n=this.elements;t.x=n[12],t.y=n[13],t.z=n[14];const s=this.determinantAffine();if(s===0)return i.set(1,1,1),e.identity(),this;let r=eo.set(n[0],n[1],n[2]).length();const o=eo.set(n[4],n[5],n[6]).length(),c=eo.set(n[8],n[9],n[10]).length();s<0&&(r=-r),Jn.copy(this);const l=1/r,h=1/o,u=1/c;return Jn.elements[0]*=l,Jn.elements[1]*=l,Jn.elements[2]*=l,Jn.elements[4]*=h,Jn.elements[5]*=h,Jn.elements[6]*=h,Jn.elements[8]*=u,Jn.elements[9]*=u,Jn.elements[10]*=u,e.setFromRotationMatrix(Jn),i.x=r,i.y=o,i.z=c,this}makePerspective(t,e,i,n,s,r,o=Us,c=!1){const l=this.elements,h=2*s/(e-t),u=2*s/(i-n),d=(e+t)/(e-t),f=(i+n)/(i-n);let p,v;if(c)p=s/(r-s),v=r*s/(r-s);else if(o===Us)p=-(r+s)/(r-s),v=-2*r*s/(r-s);else if(o===ul)p=-r/(r-s),v=-r*s/(r-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return l[0]=h,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=u,l[9]=f,l[13]=0,l[2]=0,l[6]=0,l[10]=p,l[14]=v,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,i,n,s,r,o=Us,c=!1){const l=this.elements,h=2/(e-t),u=2/(i-n),d=-(e+t)/(e-t),f=-(i+n)/(i-n);let p,v;if(c)p=1/(r-s),v=r/(r-s);else if(o===Us)p=-2/(r-s),v=-(r+s)/(r-s);else if(o===ul)p=-1/(r-s),v=-s/(r-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return l[0]=h,l[4]=0,l[8]=0,l[12]=d,l[1]=0,l[5]=u,l[9]=0,l[13]=f,l[2]=0,l[6]=0,l[10]=p,l[14]=v,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let n=0;n<16;n++)if(e[n]!==i[n])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const eo=new R,Jn=new ne,FS=new R(0,0,0),US=new R(1,1,1),Mr=new R,Fl=new R,En=new R,Rg=new ne,Dg=new Sn;class hr{constructor(t=0,e=0,i=0,n=hr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=n}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,i,n=this._order){return this._x=t,this._y=e,this._z=i,this._order=n,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,i=!0){const n=t.elements,s=n[0],r=n[4],o=n[8],c=n[1],l=n[5],h=n[9],u=n[2],d=n[6],f=n[10];switch(e){case"XYZ":this._y=Math.asin(Qt(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Qt(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin(Qt(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Qt(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(Qt(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(o,f));break;case"XZY":this._z=Math.asin(-Qt(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:Pt("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return Rg.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Rg,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Dg.setFromEuler(this),this.setFromQuaternion(Dg,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}}hr.DEFAULT_ORDER="XYZ";class Bp{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 zS=0;const Ig=new R,io=new Sn,Ys=new ne,Ul=new R,uc=new R,BS=new R,HS=new Sn,Cg=new R(1,0,0),Pg=new R(0,1,0),Og=new R(0,0,1),Lg={type:"added"},GS={type:"removed"},no={type:"childadded",child:null},Dd={type:"childremoved",child:null};class ti extends $r{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:zS++}),this.uuid=ds(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=ti.DEFAULT_UP.clone();const t=new R,e=new hr,i=new Sn,n=new R(1,1,1);function s(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(s),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new ne},normalMatrix:{value:new Jt}}),this.matrix=new ne,this.matrixWorld=new ne,this.matrixAutoUpdate=ti.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=ti.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Bp,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}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 io.setFromAxisAngle(t,e),this.quaternion.multiply(io),this}rotateOnWorldAxis(t,e){return io.setFromAxisAngle(t,e),this.quaternion.premultiply(io),this}rotateX(t){return this.rotateOnAxis(Cg,t)}rotateY(t){return this.rotateOnAxis(Pg,t)}rotateZ(t){return this.rotateOnAxis(Og,t)}translateOnAxis(t,e){return Ig.copy(t).applyQuaternion(this.quaternion),this.position.add(Ig.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Cg,t)}translateY(t){return this.translateOnAxis(Pg,t)}translateZ(t){return this.translateOnAxis(Og,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Ys.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ul.copy(t):Ul.set(t,e,i);const n=this.parent;this.updateWorldMatrix(!0,!1),uc.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Ys.lookAt(uc,Ul,this.up):Ys.lookAt(Ul,uc,this.up),this.quaternion.setFromRotationMatrix(Ys),n&&(Ys.extractRotation(n.matrixWorld),io.setFromRotationMatrix(Ys),this.quaternion.premultiply(io.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(qt("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(Lg),no.child=t,this.dispatchEvent(no),no.child=null):qt("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(GS),Dd.child=t,this.dispatchEvent(Dd),Dd.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),Ys.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),Ys.multiply(t.parent.matrixWorld)),t.applyMatrix4(Ys),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Lg),no.child=t,this.dispatchEvent(no),no.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 i=0,n=this.children.length;i<n;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const n=this.children;for(let s=0,r=n.length;s<r;s++)n[s].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(uc,t,BS),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(uc,HS,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 i=0,n=e.length;i<n;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].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);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,n=t.z,s=this.matrix.elements;s[12]+=e-s[0]*e-s[4]*i-s[8]*n,s[13]+=i-s[1]*e-s[5]*i-s[9]*n,s[14]+=n-s[2]*e-s[6]*i-s[10]*n}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 i=0,n=e.length;i<n;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e,i=!1){const n=this.parent;if(t===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),e===!0){const s=this.children;for(let r=0,o=s.length;r<o;r++)s[r].updateWorldMatrix(!1,!0,i)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const n={};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.castShadow===!0&&(n.castShadow=!0),this.receiveShadow===!0&&(n.receiveShadow=!0),this.visible===!1&&(n.visible=!1),this.frustumCulled===!1&&(n.frustumCulled=!1),this.renderOrder!==0&&(n.renderOrder=this.renderOrder),this.static!==!1&&(n.static=this.static),Object.keys(this.userData).length>0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),this.pivot!==null&&(n.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(n.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(n.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(n.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(n.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(n.type="BatchedMesh",n.perObjectFrustumCulled=this.perObjectFrustumCulled,n.sortObjects=this.sortObjects,n.drawRanges=this._drawRanges,n.reservedRanges=this._reservedRanges,n.geometryInfo=this._geometryInfo.map(o=>({...o,boundingBox:o.boundingBox?o.boundingBox.toJSON():void 0,boundingSphere:o.boundingSphere?o.boundingSphere.toJSON():void 0})),n.instanceInfo=this._instanceInfo.map(o=>({...o})),n.availableInstanceIds=this._availableInstanceIds.slice(),n.availableGeometryIds=this._availableGeometryIds.slice(),n.nextIndexStart=this._nextIndexStart,n.nextVertexStart=this._nextVertexStart,n.geometryCount=this._geometryCount,n.maxInstanceCount=this._maxInstanceCount,n.maxVertexCount=this._maxVertexCount,n.maxIndexCount=this._maxIndexCount,n.geometryInitialized=this._geometryInitialized,n.matricesTexture=this._matricesTexture.toJSON(t),n.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(n.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(n.boundingBox=this.boundingBox.toJSON()));function s(o,c){return o[c.uuid]===void 0&&(o[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(t.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const c=o.shapes;if(Array.isArray(c))for(let l=0,h=c.length;l<h;l++){const u=c[l];s(t.shapes,u)}else s(t.shapes,c)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(t.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let c=0,l=this.material.length;c<l;c++)o.push(s(t.materials,this.material[c]));n.material=o}else n.material=s(t.materials,this.material);if(this.children.length>0){n.children=[];for(let o=0;o<this.children.length;o++)n.children.push(this.children[o].toJSON(t).object)}if(this.animations.length>0){n.animations=[];for(let o=0;o<this.animations.length;o++){const c=this.animations[o];n.animations.push(s(t.animations,c))}}if(e){const o=r(t.geometries),c=r(t.materials),l=r(t.textures),h=r(t.images),u=r(t.shapes),d=r(t.skeletons),f=r(t.animations),p=r(t.nodes);o.length>0&&(i.geometries=o),c.length>0&&(i.materials=c),l.length>0&&(i.textures=l),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),d.length>0&&(i.skeletons=d),f.length>0&&(i.animations=f),p.length>0&&(i.nodes=p)}return i.object=n,i;function r(o){const c=[];for(const l in o){const h=o[l];delete h.metadata,c.push(h)}return c}}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.pivot=t.pivot!==null?t.pivot.clone():null,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.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const n=t.children[i];this.add(n.clone())}return this}}ti.DEFAULT_UP=new R(0,1,0);ti.DEFAULT_MATRIX_AUTO_UPDATE=!0;ti.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Ee extends ti{constructor(){super(),this.isGroup=!0,this.type="Group"}}const VS={type:"move"};class Id{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Ee,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 Ee,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 Ee,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.eventsEnabled=!1),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 i of t.hand.values())this._getHandJoint(e,i)}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,i){let n=null,s=null,r=null;const o=this._targetRay,c=this._grip,l=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(l&&t.hand){r=!0;for(const v of t.hand.values()){const m=e.getJointPose(v,i),g=this._getHandJoint(l,v);m!==null&&(g.matrix.fromArray(m.transform.matrix),g.matrix.decompose(g.position,g.rotation,g.scale),g.matrixWorldNeedsUpdate=!0,g.jointRadius=m.radius),g.visible=m!==null}const h=l.joints["index-finger-tip"],u=l.joints["thumb-tip"],d=h.position.distanceTo(u.position),f=.02,p=.005;l.inputState.pinching&&d>f+p?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&d<=f-p&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else c!==null&&t.gripSpace&&(s=e.getPose(t.gripSpace,i),s!==null&&(c.matrix.fromArray(s.transform.matrix),c.matrix.decompose(c.position,c.rotation,c.scale),c.matrixWorldNeedsUpdate=!0,s.linearVelocity?(c.hasLinearVelocity=!0,c.linearVelocity.copy(s.linearVelocity)):c.hasLinearVelocity=!1,s.angularVelocity?(c.hasAngularVelocity=!0,c.angularVelocity.copy(s.angularVelocity)):c.hasAngularVelocity=!1,c.eventsEnabled&&c.dispatchEvent({type:"gripUpdated",data:t,target:this})));o!==null&&(n=e.getPose(t.targetRaySpace,i),n===null&&s!==null&&(n=s),n!==null&&(o.matrix.fromArray(n.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,n.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(n.linearVelocity)):o.hasLinearVelocity=!1,n.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(n.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(VS)))}return o!==null&&(o.visible=n!==null),c!==null&&(c.visible=s!==null),l!==null&&(l.visible=r!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){const i=new Ee;i.matrixAutoUpdate=!1,i.visible=!1,t.joints[e.jointName]=i,t.add(i)}return t.joints[e.jointName]}}const JM={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},yr={h:0,s:0,l:0},zl={h:0,s:0,l:0};function Cd(a,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+(t-a)*6*e:e<1/2?t:e<2/3?a+(t-a)*6*(2/3-e):a}class st{constructor(t,e,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,i)}set(t,e,i){if(e===void 0&&i===void 0){const n=t;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(t,e,i);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=un){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,me.colorSpaceToWorking(this,e),this}setRGB(t,e,i,n=me.workingColorSpace){return this.r=t,this.g=e,this.b=i,me.colorSpaceToWorking(this,n),this}setHSL(t,e,i,n=me.workingColorSpace){if(t=Up(t,1),e=Qt(e,0,1),i=Qt(i,0,1),e===0)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+e):i+e-i*e,r=2*i-s;this.r=Cd(r,s,t+1/3),this.g=Cd(r,s,t),this.b=Cd(r,s,t-1/3)}return me.colorSpaceToWorking(this,n),this}setStyle(t,e=un){function i(s){s!==void 0&&parseFloat(s)<1&&Pt("Color: Alpha component of "+t+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(t)){let s;const r=n[1],o=n[2];switch(r){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,e);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,e);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,e);break;default:Pt("Color: Unknown color model "+t)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=n[1],r=s.length;if(r===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(r===6)return this.setHex(parseInt(s,16),e);Pt("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=un){const i=JM[t.toLowerCase()];return i!==void 0?this.setHex(i,e):Pt("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=or(t.r),this.g=or(t.g),this.b=or(t.b),this}copyLinearToSRGB(t){return this.r=zo(t.r),this.g=zo(t.g),this.b=zo(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=un){return me.workingToColorSpace(Yi.copy(this),t),Math.round(Qt(Yi.r*255,0,255))*65536+Math.round(Qt(Yi.g*255,0,255))*256+Math.round(Qt(Yi.b*255,0,255))}getHexString(t=un){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=me.workingColorSpace){me.workingToColorSpace(Yi.copy(this),e);const i=Yi.r,n=Yi.g,s=Yi.b,r=Math.max(i,n,s),o=Math.min(i,n,s);let c,l;const h=(o+r)/2;if(o===r)c=0,l=0;else{const u=r-o;switch(l=h<=.5?u/(r+o):u/(2-r-o),r){case i:c=(n-s)/u+(n<s?6:0);break;case n:c=(s-i)/u+2;break;case s:c=(i-n)/u+4;break}c/=6}return t.h=c,t.s=l,t.l=h,t}getRGB(t,e=me.workingColorSpace){return me.workingToColorSpace(Yi.copy(this),e),t.r=Yi.r,t.g=Yi.g,t.b=Yi.b,t}getStyle(t=un){me.workingToColorSpace(Yi.copy(this),t);const e=Yi.r,i=Yi.g,n=Yi.b;return t!==un?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(i*255)},${Math.round(n*255)})`}offsetHSL(t,e,i){return this.getHSL(yr),this.setHSL(yr.h+t,yr.s+e,yr.l+i)}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,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(yr),t.getHSL(zl);const i=qc(yr.h,zl.h,e),n=qc(yr.s,zl.s,e),s=qc(yr.l,zl.l,e);return this.setHSL(i,n,s),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,i=this.g,n=this.b,s=t.elements;return this.r=s[0]*e+s[3]*i+s[6]*n,this.g=s[1]*e+s[4]*i+s[7]*n,this.b=s[2]*e+s[5]*i+s[8]*n,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 Yi=new st;st.NAMES=JM;class Hp{constructor(t,e=1,i=1e3){this.isFog=!0,this.name="",this.color=new st(t),this.near=e,this.far=i}clone(){return new Hp(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class Gs extends ti{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 hr,this.environmentIntensity=1,this.environmentRotation=new hr,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}}const jn=new R,qs=new R,Pd=new R,$s=new R,so=new R,ro=new R,Ng=new R,Od=new R,Ld=new R,Nd=new R,kd=new ue,Fd=new ue,Ud=new ue;class qn{constructor(t=new R,e=new R,i=new R){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,n){n.subVectors(i,e),jn.subVectors(t,e),n.cross(jn);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(t,e,i,n,s){jn.subVectors(n,e),qs.subVectors(i,e),Pd.subVectors(t,e);const r=jn.dot(jn),o=jn.dot(qs),c=jn.dot(Pd),l=qs.dot(qs),h=qs.dot(Pd),u=r*l-o*o;if(u===0)return s.set(0,0,0),null;const d=1/u,f=(l*c-o*h)*d,p=(r*h-o*c)*d;return s.set(1-f-p,p,f)}static containsPoint(t,e,i,n){return this.getBarycoord(t,e,i,n,$s)===null?!1:$s.x>=0&&$s.y>=0&&$s.x+$s.y<=1}static getInterpolation(t,e,i,n,s,r,o,c){return this.getBarycoord(t,e,i,n,$s)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(s,$s.x),c.addScaledVector(r,$s.y),c.addScaledVector(o,$s.z),c)}static getInterpolatedAttribute(t,e,i,n,s,r){return kd.setScalar(0),Fd.setScalar(0),Ud.setScalar(0),kd.fromBufferAttribute(t,e),Fd.fromBufferAttribute(t,i),Ud.fromBufferAttribute(t,n),r.setScalar(0),r.addScaledVector(kd,s.x),r.addScaledVector(Fd,s.y),r.addScaledVector(Ud,s.z),r}static isFrontFacing(t,e,i,n){return jn.subVectors(i,e),qs.subVectors(t,e),jn.cross(qs).dot(n)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,n){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[n]),this}setFromAttributeAndIndices(t,e,i,n){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,n),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 jn.subVectors(this.c,this.b),qs.subVectors(this.a,this.b),jn.cross(qs).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return qn.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return qn.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,n,s){return qn.getInterpolation(t,this.a,this.b,this.c,e,i,n,s)}containsPoint(t){return qn.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return qn.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,n=this.b,s=this.c;let r,o;so.subVectors(n,i),ro.subVectors(s,i),Od.subVectors(t,i);const c=so.dot(Od),l=ro.dot(Od);if(c<=0&&l<=0)return e.copy(i);Ld.subVectors(t,n);const h=so.dot(Ld),u=ro.dot(Ld);if(h>=0&&u<=h)return e.copy(n);const d=c*u-h*l;if(d<=0&&c>=0&&h<=0)return r=c/(c-h),e.copy(i).addScaledVector(so,r);Nd.subVectors(t,s);const f=so.dot(Nd),p=ro.dot(Nd);if(p>=0&&f<=p)return e.copy(s);const v=f*l-c*p;if(v<=0&&l>=0&&p<=0)return o=l/(l-p),e.copy(i).addScaledVector(ro,o);const m=h*p-f*u;if(m<=0&&u-h>=0&&f-p>=0)return Ng.subVectors(s,n),o=(u-h)/(u-h+(f-p)),e.copy(n).addScaledVector(Ng,o);const g=1/(m+v+d);return r=v*g,o=d*g,e.copy(i).addScaledVector(so,r).addScaledVector(ro,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class Qi{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,i=t.length;e<i;e+=3)this.expandByPoint(Qn.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(Qn.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=Qn.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),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 i=t.geometry;if(i!==void 0){const s=i.getAttribute("position");if(e===!0&&s!==void 0&&t.isInstancedMesh!==!0)for(let r=0,o=s.count;r<o;r++)t.isMesh===!0?t.getVertexPosition(r,Qn):Qn.fromBufferAttribute(s,r),Qn.applyMatrix4(t.matrixWorld),this.expandByPoint(Qn);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Bl.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Bl.copy(i.boundingBox)),Bl.applyMatrix4(t.matrixWorld),this.union(Bl)}const n=t.children;for(let s=0,r=n.length;s<r;s++)this.expandByObject(n[s],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,Qn),Qn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(dc),Hl.subVectors(this.max,dc),ao.subVectors(t.a,dc),oo.subVectors(t.b,dc),co.subVectors(t.c,dc),xr.subVectors(oo,ao),br.subVectors(co,oo),Jr.subVectors(ao,co);let e=[0,-xr.z,xr.y,0,-br.z,br.y,0,-Jr.z,Jr.y,xr.z,0,-xr.x,br.z,0,-br.x,Jr.z,0,-Jr.x,-xr.y,xr.x,0,-br.y,br.x,0,-Jr.y,Jr.x,0];return!zd(e,ao,oo,co,Hl)||(e=[1,0,0,0,1,0,0,0,1],!zd(e,ao,oo,co,Hl))?!1:(Gl.crossVectors(xr,br),e=[Gl.x,Gl.y,Gl.z],zd(e,ao,oo,co,Hl))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Qn).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(Qn).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:(Ks[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ks[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ks[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ks[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ks[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ks[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ks[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ks[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ks),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)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const Ks=[new R,new R,new R,new R,new R,new R,new R,new R],Qn=new R,Bl=new Qi,ao=new R,oo=new R,co=new R,xr=new R,br=new R,Jr=new R,dc=new R,Hl=new R,Gl=new R,jr=new R;function zd(a,t,e,i,n){for(let s=0,r=a.length-3;s<=r;s+=3){jr.fromArray(a,s);const o=n.x*Math.abs(jr.x)+n.y*Math.abs(jr.y)+n.z*Math.abs(jr.z),c=t.dot(jr),l=e.dot(jr),h=i.dot(jr);if(Math.max(-Math.max(c,l,h),Math.min(c,l,h))>o)return!1}return!0}const sr=WS();function WS(){const a=new ArrayBuffer(4),t=new Float32Array(a),e=new Uint32Array(a),i=new Uint32Array(512),n=new Uint32Array(512);for(let c=0;c<256;++c){const l=c-127;l<-27?(i[c]=0,i[c|256]=32768,n[c]=24,n[c|256]=24):l<-14?(i[c]=1024>>-l-14,i[c|256]=1024>>-l-14|32768,n[c]=-l-1,n[c|256]=-l-1):l<=15?(i[c]=l+15<<10,i[c|256]=l+15<<10|32768,n[c]=13,n[c|256]=13):l<128?(i[c]=31744,i[c|256]=64512,n[c]=24,n[c|256]=24):(i[c]=31744,i[c|256]=64512,n[c]=13,n[c|256]=13)}const s=new Uint32Array(2048),r=new Uint32Array(64),o=new Uint32Array(64);for(let c=1;c<1024;++c){let l=c<<13,h=0;for(;(l&8388608)===0;)l<<=1,h-=8388608;l&=-8388609,h+=947912704,s[c]=l|h}for(let c=1024;c<2048;++c)s[c]=939524096+(c-1024<<13);for(let c=1;c<31;++c)r[c]=c<<23;r[31]=1199570944,r[32]=2147483648;for(let c=33;c<63;++c)r[c]=2147483648+(c-32<<23);r[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(o[c]=1024);return{floatView:t,uint32View:e,baseTable:i,shiftTable:n,mantissaTable:s,exponentTable:r,offsetTable:o}}function XS(a){Math.abs(a)>65504&&Pt("DataUtils.toHalfFloat(): Value out of range."),a=Qt(a,-65504,65504),sr.floatView[0]=a;const t=sr.uint32View[0],e=t>>23&511;return sr.baseTable[e]+((t&8388607)>>sr.shiftTable[e])}function YS(a){const t=a>>10;return sr.uint32View[0]=sr.mantissaTable[sr.offsetTable[t]+(a&1023)]+sr.exponentTable[t],sr.floatView[0]}class kn{static toHalfFloat(t){return XS(t)}static fromHalfFloat(t){return YS(t)}}const _i=new R,Vl=new bt;let qS=0;class te extends $r{constructor(t,e,i=!1){if(super(),Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:qS++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=k0,this.updateRanges=[],this.gpuType=ji,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,i){t*=this.itemSize,i*=e.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[t+n]=e.array[i+n];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)Vl.fromBufferAttribute(this,e),Vl.applyMatrix3(t),this.setXY(e,Vl.x,Vl.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)_i.fromBufferAttribute(this,e),_i.applyMatrix3(t),this.setXYZ(e,_i.x,_i.y,_i.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)_i.fromBufferAttribute(this,e),_i.applyMatrix4(t),this.setXYZ(e,_i.x,_i.y,_i.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)_i.fromBufferAttribute(this,e),_i.applyNormalMatrix(t),this.setXYZ(e,_i.x,_i.y,_i.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)_i.fromBufferAttribute(this,e),_i.transformDirection(t),this.setXYZ(e,_i.x,_i.y,_i.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=hs(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=Oe(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=hs(e,this.array)),e}setX(t,e){return this.normalized&&(e=Oe(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=hs(e,this.array)),e}setY(t,e){return this.normalized&&(e=Oe(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=hs(e,this.array)),e}setZ(t,e){return this.normalized&&(e=Oe(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=hs(e,this.array)),e}setW(t,e){return this.normalized&&(e=Oe(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,n){return t*=this.itemSize,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array),n=Oe(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t*=this.itemSize,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array),n=Oe(n,this.array),s=Oe(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this.array[t+3]=s,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!==k0&&(t.usage=this.usage),t}dispose(){this.dispatchEvent({type:"dispose"})}}class jM extends te{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class Gp extends te{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class ve extends te{constructor(t,e,i){super(new Float32Array(t),e,i)}}const $S=new Qi,fc=new R,Bd=new R;class dr{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 i=this.center;e!==void 0?i.copy(e):$S.setFromPoints(t).getCenter(i);let n=0;for(let s=0,r=t.length;s<r;s++)n=Math.max(n,i.distanceToSquared(t[s]));return this.radius=Math.sqrt(n),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 i=this.center.distanceToSquared(t);return e.copy(t),i>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;fc.subVectors(t,this.center);const e=fc.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),n=(i-this.radius)*.5;this.center.addScaledVector(fc,n/i),this.radius+=n}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):(Bd.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(fc.copy(t.center).add(Bd)),this.expandByPoint(fc.copy(t.center).sub(Bd))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let KS=0;const zn=new ne,Hd=new ti,lo=new R,An=new Qi,pc=new Qi,Ni=new R;class ae extends $r{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:KS++}),this.uuid=ds(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(uS(t)?Gp:jM)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}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,i=0){this.groups.push({start:t,count:e,materialIndex:i})}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 i=this.attributes.normal;if(i!==void 0){const s=new Jt().getNormalMatrix(t);i.applyNormalMatrix(s),i.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(t),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return zn.makeRotationFromQuaternion(t),this.applyMatrix4(zn),this}rotateX(t){return zn.makeRotationX(t),this.applyMatrix4(zn),this}rotateY(t){return zn.makeRotationY(t),this.applyMatrix4(zn),this}rotateZ(t){return zn.makeRotationZ(t),this.applyMatrix4(zn),this}translate(t,e,i){return zn.makeTranslation(t,e,i),this.applyMatrix4(zn),this}scale(t,e,i){return zn.makeScale(t,e,i),this.applyMatrix4(zn),this}lookAt(t){return Hd.lookAt(t),Hd.updateMatrix(),this.applyMatrix4(Hd.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(lo).negate(),this.translate(lo.x,lo.y,lo.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let n=0,s=t.length;n<s;n++){const r=t[n];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new ve(i,3))}else{const i=Math.min(t.length,e.count);for(let n=0;n<i;n++){const s=t[n];e.setXYZ(n,s.x,s.y,s.z||0)}t.length>e.count&&Pt("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Qi);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){qt("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 i=0,n=e.length;i<n;i++){const s=e[i];An.setFromBufferAttribute(s),this.morphTargetsRelative?(Ni.addVectors(this.boundingBox.min,An.min),this.boundingBox.expandByPoint(Ni),Ni.addVectors(this.boundingBox.max,An.max),this.boundingBox.expandByPoint(Ni)):(this.boundingBox.expandByPoint(An.min),this.boundingBox.expandByPoint(An.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&qt('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 dr);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){qt("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(t){const i=this.boundingSphere.center;if(An.setFromBufferAttribute(t),e)for(let s=0,r=e.length;s<r;s++){const o=e[s];pc.setFromBufferAttribute(o),this.morphTargetsRelative?(Ni.addVectors(An.min,pc.min),An.expandByPoint(Ni),Ni.addVectors(An.max,pc.max),An.expandByPoint(Ni)):(An.expandByPoint(pc.min),An.expandByPoint(pc.max))}An.getCenter(i);let n=0;for(let s=0,r=t.count;s<r;s++)Ni.fromBufferAttribute(t,s),n=Math.max(n,i.distanceToSquared(Ni));if(e)for(let s=0,r=e.length;s<r;s++){const o=e[s],c=this.morphTargetsRelative;for(let l=0,h=o.count;l<h;l++)Ni.fromBufferAttribute(o,l),c&&(lo.fromBufferAttribute(t,l),Ni.add(lo)),n=Math.max(n,i.distanceToSquared(Ni))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&qt('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){qt("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,n=e.normal,s=e.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new te(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const o=[],c=[];for(let y=0;y<i.count;y++)o[y]=new R,c[y]=new R;const l=new R,h=new R,u=new R,d=new bt,f=new bt,p=new bt,v=new R,m=new R;function g(y,T,I){l.fromBufferAttribute(i,y),h.fromBufferAttribute(i,T),u.fromBufferAttribute(i,I),d.fromBufferAttribute(s,y),f.fromBufferAttribute(s,T),p.fromBufferAttribute(s,I),h.sub(l),u.sub(l),f.sub(d),p.sub(d);const C=1/(f.x*p.y-p.x*f.y);isFinite(C)&&(v.copy(h).multiplyScalar(p.y).addScaledVector(u,-f.y).multiplyScalar(C),m.copy(u).multiplyScalar(f.x).addScaledVector(h,-p.x).multiplyScalar(C),o[y].add(v),o[T].add(v),o[I].add(v),c[y].add(m),c[T].add(m),c[I].add(m))}let b=this.groups;b.length===0&&(b=[{start:0,count:t.count}]);for(let y=0,T=b.length;y<T;++y){const I=b[y],C=I.start,P=I.count;for(let B=C,W=C+P;B<W;B+=3)g(t.getX(B+0),t.getX(B+1),t.getX(B+2))}const S=new R,M=new R,x=new R,_=new R;function E(y){x.fromBufferAttribute(n,y),_.copy(x);const T=o[y];S.copy(T),S.sub(x.multiplyScalar(x.dot(T))).normalize(),M.crossVectors(_,T);const C=M.dot(c[y])<0?-1:1;r.setXYZW(y,S.x,S.y,S.z,C)}for(let y=0,T=b.length;y<T;++y){const I=b[y],C=I.start,P=I.count;for(let B=C,W=C+P;B<W;B+=3)E(t.getX(B+0)),E(t.getX(B+1)),E(t.getX(B+2))}this._transformed=!0}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==e.count)i=new te(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let d=0,f=i.count;d<f;d++)i.setXYZ(d,0,0,0);const n=new R,s=new R,r=new R,o=new R,c=new R,l=new R,h=new R,u=new R;if(t)for(let d=0,f=t.count;d<f;d+=3){const p=t.getX(d+0),v=t.getX(d+1),m=t.getX(d+2);n.fromBufferAttribute(e,p),s.fromBufferAttribute(e,v),r.fromBufferAttribute(e,m),h.subVectors(r,s),u.subVectors(n,s),h.cross(u),o.fromBufferAttribute(i,p),c.fromBufferAttribute(i,v),l.fromBufferAttribute(i,m),o.add(h),c.add(h),l.add(h),i.setXYZ(p,o.x,o.y,o.z),i.setXYZ(v,c.x,c.y,c.z),i.setXYZ(m,l.x,l.y,l.z)}else for(let d=0,f=e.count;d<f;d+=3)n.fromBufferAttribute(e,d+0),s.fromBufferAttribute(e,d+1),r.fromBufferAttribute(e,d+2),h.subVectors(r,s),u.subVectors(n,s),h.cross(u),i.setXYZ(d+0,h.x,h.y,h.z),i.setXYZ(d+1,h.x,h.y,h.z),i.setXYZ(d+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)Ni.fromBufferAttribute(t,e),Ni.normalize(),t.setXYZ(e,Ni.x,Ni.y,Ni.z)}toNonIndexed(){function t(o,c){const l=o.array,h=o.itemSize,u=o.normalized,d=new l.constructor(c.length*h);let f=0,p=0;for(let v=0,m=c.length;v<m;v++){o.isInterleavedBufferAttribute?f=c[v]*o.data.stride+o.offset:f=c[v]*h;for(let g=0;g<h;g++)d[p++]=l[f++]}return new te(d,h,u)}if(this.index===null)return Pt("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new ae,i=this.index.array,n=this.attributes;for(const o in n){const c=n[o],l=t(c,i);e.setAttribute(o,l)}const s=this.morphAttributes;for(const o in s){const c=[],l=s[o];for(let h=0,u=l.length;h<u;h++){const d=l[h],f=t(d,i);c.push(f)}e.morphAttributes[o]=c}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let o=0,c=r.length;o<c;o++){const l=r[o];e.addGroup(l.start,l.count,l.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const c=this.parameters;for(const l in c)c[l]!==void 0&&(t[l]=c[l]);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 i=this.attributes;for(const c in i){const l=i[c];t.data.attributes[c]=l.toJSON(t.data)}const n={};let s=!1;for(const c in this.morphAttributes){const l=this.morphAttributes[c],h=[];for(let u=0,d=l.length;u<d;u++){const f=l[u];h.push(f.toJSON(t.data))}h.length>0&&(n[c]=h,s=!0)}s&&(t.data.morphAttributes=n,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const o=this.boundingSphere;return o!==null&&(t.data.boundingSphere=o.toJSON()),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 i=t.index;i!==null&&this.setIndex(i.clone());const n=t.attributes;for(const l in n){const h=n[l];this.setAttribute(l,h.clone(e))}const s=t.morphAttributes;for(const l in s){const h=[],u=s[l];for(let d=0,f=u.length;d<f;d++)h.push(u[d].clone(e));this.morphAttributes[l]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let l=0,h=r.length;l<h;l++){const u=r[l];this.addGroup(u.start,u.count,u.materialIndex)}const o=t.boundingBox;o!==null&&(this.boundingBox=o.clone());const c=t.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this._transformed=t._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class QM{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=k0,this.updateRanges=[],this.version=0,this.uuid=ds()}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.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,i){t*=this.stride,i*=e.stride;for(let n=0,s=this.stride;n<s;n++)this.array[t+n]=e.array[i+n];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=ds()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(e,this.stride);return i.setUsage(this.usage),i}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=ds()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const tn=new R;class Iu{constructor(t,e,i,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=i,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,i=this.data.count;e<i;e++)tn.fromBufferAttribute(this,e),tn.applyMatrix4(t),this.setXYZ(e,tn.x,tn.y,tn.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)tn.fromBufferAttribute(this,e),tn.applyNormalMatrix(t),this.setXYZ(e,tn.x,tn.y,tn.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)tn.fromBufferAttribute(this,e),tn.transformDirection(t),this.setXYZ(e,tn.x,tn.y,tn.z);return this}getComponent(t,e){let i=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(i=hs(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=Oe(i,this.array)),this.data.array[t*this.data.stride+this.offset+e]=i,this}setX(t,e){return this.normalized&&(e=Oe(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=Oe(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=Oe(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=Oe(e,this.array)),this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){let e=this.data.array[t*this.data.stride+this.offset];return this.normalized&&(e=hs(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=hs(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=hs(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=hs(e,this.array)),e}setXY(t,e,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this}setXYZ(t,e,i,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array),n=Oe(n,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array),n=Oe(n,this.array),s=Oe(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this.data.array[t+3]=s,this}clone(t){if(t===void 0){Du("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)e.push(this.data.array[n+s])}return new te(new this.array.constructor(e),this.itemSize,this.normalized)}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new Iu(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(t===void 0){Du("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)e.push(this.data.array[n+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let ZS=0;class fr extends $r{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:ZS++}),this.uuid=ds(),this.name="",this.type="Material",this.blending=Vr,this.side=Xr,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Zf,this.blendDst=cl,this.blendEquation=ha,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new st(0,0,0),this.blendAlpha=0,this.depthFunc=Jo,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=Sg,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Qa,this.stencilZFail=Qa,this.stencilZPass=Qa,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.allowOverride=!0,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 i=t[e];if(i===void 0){Pt(`Material: parameter '${e}' has value of undefined.`);continue}const n=this[e];if(n===void 0){Pt(`Material: '${e}' is not a property of THREE.${this.type}.`);continue}n&&n.isColor?n.set(i):n&&n.isVector2&&i&&i.isVector2||n&&n.isEuler&&i&&i.isEuler||n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const i={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),this.roughness!==void 0&&(i.roughness=this.roughness),this.metalness!==void 0&&(i.metalness=this.metalness),this.sheen!==void 0&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(i.shininess=this.shininess),this.clearcoat!==void 0&&(i.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).uuid),this.dispersion!==void 0&&(i.dispersion=this.dispersion),this.iridescence!==void 0&&(i.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(i.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(i.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(i.combine=this.combine)),this.envMapRotation!==void 0&&(i.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(i.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(i.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(i.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(i.size=this.size),this.shadowSide!==null&&(i.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==Vr&&(i.blending=this.blending),this.side!==Xr&&(i.side=this.side),this.vertexColors===!0&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.transparent===!0&&(i.transparent=!0),this.blendSrc!==Zf&&(i.blendSrc=this.blendSrc),this.blendDst!==cl&&(i.blendDst=this.blendDst),this.blendEquation!==ha&&(i.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(i.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(i.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(i.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(i.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(i.blendAlpha=this.blendAlpha),this.depthFunc!==Jo&&(i.depthFunc=this.depthFunc),this.depthTest===!1&&(i.depthTest=this.depthTest),this.depthWrite===!1&&(i.depthWrite=this.depthWrite),this.colorWrite===!1&&(i.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(i.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==Sg&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Qa&&(i.stencilFail=this.stencilFail),this.stencilZFail!==Qa&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==Qa&&(i.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(i.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(i.rotation=this.rotation),this.polygonOffset===!0&&(i.polygonOffset=!0),this.polygonOffsetFactor!==0&&(i.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(i.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(i.linewidth=this.linewidth),this.dashSize!==void 0&&(i.dashSize=this.dashSize),this.gapSize!==void 0&&(i.gapSize=this.gapSize),this.scale!==void 0&&(i.scale=this.scale),this.dithering===!0&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),this.alphaHash===!0&&(i.alphaHash=!0),this.alphaToCoverage===!0&&(i.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(i.premultipliedAlpha=!0),this.forceSinglePass===!0&&(i.forceSinglePass=!0),this.allowOverride===!1&&(i.allowOverride=!1),this.wireframe===!0&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(i.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(i.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(i.flatShading=!0),this.visible===!1&&(i.visible=!1),this.toneMapped===!1&&(i.toneMapped=!1),this.fog===!1&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData);function n(s){const r=[];for(const o in s){const c=s[o];delete c.metadata,r.push(c)}return r}if(e){const s=n(t.textures),r=n(t.images);s.length>0&&(i.textures=s),r.length>0&&(i.images=r)}return i}fromJSON(t,e){if(t.uuid!==void 0&&(this.uuid=t.uuid),t.name!==void 0&&(this.name=t.name),t.color!==void 0&&this.color!==void 0&&this.color.setHex(t.color),t.roughness!==void 0&&(this.roughness=t.roughness),t.metalness!==void 0&&(this.metalness=t.metalness),t.sheen!==void 0&&(this.sheen=t.sheen),t.sheenColor!==void 0&&(this.sheenColor=new st().setHex(t.sheenColor)),t.sheenRoughness!==void 0&&(this.sheenRoughness=t.sheenRoughness),t.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(t.emissive),t.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(t.specular),t.specularIntensity!==void 0&&(this.specularIntensity=t.specularIntensity),t.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(t.specularColor),t.shininess!==void 0&&(this.shininess=t.shininess),t.clearcoat!==void 0&&(this.clearcoat=t.clearcoat),t.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=t.clearcoatRoughness),t.dispersion!==void 0&&(this.dispersion=t.dispersion),t.iridescence!==void 0&&(this.iridescence=t.iridescence),t.iridescenceIOR!==void 0&&(this.iridescenceIOR=t.iridescenceIOR),t.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=t.iridescenceThicknessRange),t.transmission!==void 0&&(this.transmission=t.transmission),t.thickness!==void 0&&(this.thickness=t.thickness),t.attenuationDistance!==void 0&&(this.attenuationDistance=t.attenuationDistance),t.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(t.attenuationColor),t.anisotropy!==void 0&&(this.anisotropy=t.anisotropy),t.anisotropyRotation!==void 0&&(this.anisotropyRotation=t.anisotropyRotation),t.fog!==void 0&&(this.fog=t.fog),t.flatShading!==void 0&&(this.flatShading=t.flatShading),t.blending!==void 0&&(this.blending=t.blending),t.combine!==void 0&&(this.combine=t.combine),t.side!==void 0&&(this.side=t.side),t.shadowSide!==void 0&&(this.shadowSide=t.shadowSide),t.opacity!==void 0&&(this.opacity=t.opacity),t.transparent!==void 0&&(this.transparent=t.transparent),t.alphaTest!==void 0&&(this.alphaTest=t.alphaTest),t.alphaHash!==void 0&&(this.alphaHash=t.alphaHash),t.depthFunc!==void 0&&(this.depthFunc=t.depthFunc),t.depthTest!==void 0&&(this.depthTest=t.depthTest),t.depthWrite!==void 0&&(this.depthWrite=t.depthWrite),t.colorWrite!==void 0&&(this.colorWrite=t.colorWrite),t.blendSrc!==void 0&&(this.blendSrc=t.blendSrc),t.blendDst!==void 0&&(this.blendDst=t.blendDst),t.blendEquation!==void 0&&(this.blendEquation=t.blendEquation),t.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=t.blendSrcAlpha),t.blendDstAlpha!==void 0&&(this.blendDstAlpha=t.blendDstAlpha),t.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=t.blendEquationAlpha),t.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(t.blendColor),t.blendAlpha!==void 0&&(this.blendAlpha=t.blendAlpha),t.stencilWriteMask!==void 0&&(this.stencilWriteMask=t.stencilWriteMask),t.stencilFunc!==void 0&&(this.stencilFunc=t.stencilFunc),t.stencilRef!==void 0&&(this.stencilRef=t.stencilRef),t.stencilFuncMask!==void 0&&(this.stencilFuncMask=t.stencilFuncMask),t.stencilFail!==void 0&&(this.stencilFail=t.stencilFail),t.stencilZFail!==void 0&&(this.stencilZFail=t.stencilZFail),t.stencilZPass!==void 0&&(this.stencilZPass=t.stencilZPass),t.stencilWrite!==void 0&&(this.stencilWrite=t.stencilWrite),t.wireframe!==void 0&&(this.wireframe=t.wireframe),t.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=t.wireframeLinewidth),t.wireframeLinecap!==void 0&&(this.wireframeLinecap=t.wireframeLinecap),t.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=t.wireframeLinejoin),t.rotation!==void 0&&(this.rotation=t.rotation),t.linewidth!==void 0&&(this.linewidth=t.linewidth),t.dashSize!==void 0&&(this.dashSize=t.dashSize),t.gapSize!==void 0&&(this.gapSize=t.gapSize),t.scale!==void 0&&(this.scale=t.scale),t.polygonOffset!==void 0&&(this.polygonOffset=t.polygonOffset),t.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=t.polygonOffsetFactor),t.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=t.polygonOffsetUnits),t.dithering!==void 0&&(this.dithering=t.dithering),t.alphaToCoverage!==void 0&&(this.alphaToCoverage=t.alphaToCoverage),t.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=t.premultipliedAlpha),t.forceSinglePass!==void 0&&(this.forceSinglePass=t.forceSinglePass),t.allowOverride!==void 0&&(this.allowOverride=t.allowOverride),t.visible!==void 0&&(this.visible=t.visible),t.toneMapped!==void 0&&(this.toneMapped=t.toneMapped),t.userData!==void 0&&(this.userData=t.userData),t.vertexColors!==void 0&&(typeof t.vertexColors=="number"?this.vertexColors=t.vertexColors>0:this.vertexColors=t.vertexColors),t.size!==void 0&&(this.size=t.size),t.sizeAttenuation!==void 0&&(this.sizeAttenuation=t.sizeAttenuation),t.map!==void 0&&(this.map=e[t.map]||null),t.matcap!==void 0&&(this.matcap=e[t.matcap]||null),t.alphaMap!==void 0&&(this.alphaMap=e[t.alphaMap]||null),t.bumpMap!==void 0&&(this.bumpMap=e[t.bumpMap]||null),t.bumpScale!==void 0&&(this.bumpScale=t.bumpScale),t.normalMap!==void 0&&(this.normalMap=e[t.normalMap]||null),t.normalMapType!==void 0&&(this.normalMapType=t.normalMapType),t.normalScale!==void 0){let i=t.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new bt().fromArray(i)}return t.displacementMap!==void 0&&(this.displacementMap=e[t.displacementMap]||null),t.displacementScale!==void 0&&(this.displacementScale=t.displacementScale),t.displacementBias!==void 0&&(this.displacementBias=t.displacementBias),t.roughnessMap!==void 0&&(this.roughnessMap=e[t.roughnessMap]||null),t.metalnessMap!==void 0&&(this.metalnessMap=e[t.metalnessMap]||null),t.emissiveMap!==void 0&&(this.emissiveMap=e[t.emissiveMap]||null),t.emissiveIntensity!==void 0&&(this.emissiveIntensity=t.emissiveIntensity),t.specularMap!==void 0&&(this.specularMap=e[t.specularMap]||null),t.specularIntensityMap!==void 0&&(this.specularIntensityMap=e[t.specularIntensityMap]||null),t.specularColorMap!==void 0&&(this.specularColorMap=e[t.specularColorMap]||null),t.envMap!==void 0&&(this.envMap=e[t.envMap]||null),t.envMapRotation!==void 0&&this.envMapRotation.fromArray(t.envMapRotation),t.envMapIntensity!==void 0&&(this.envMapIntensity=t.envMapIntensity),t.reflectivity!==void 0&&(this.reflectivity=t.reflectivity),t.refractionRatio!==void 0&&(this.refractionRatio=t.refractionRatio),t.lightMap!==void 0&&(this.lightMap=e[t.lightMap]||null),t.lightMapIntensity!==void 0&&(this.lightMapIntensity=t.lightMapIntensity),t.aoMap!==void 0&&(this.aoMap=e[t.aoMap]||null),t.aoMapIntensity!==void 0&&(this.aoMapIntensity=t.aoMapIntensity),t.gradientMap!==void 0&&(this.gradientMap=e[t.gradientMap]||null),t.clearcoatMap!==void 0&&(this.clearcoatMap=e[t.clearcoatMap]||null),t.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=e[t.clearcoatRoughnessMap]||null),t.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=e[t.clearcoatNormalMap]||null),t.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new bt().fromArray(t.clearcoatNormalScale)),t.iridescenceMap!==void 0&&(this.iridescenceMap=e[t.iridescenceMap]||null),t.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=e[t.iridescenceThicknessMap]||null),t.transmissionMap!==void 0&&(this.transmissionMap=e[t.transmissionMap]||null),t.thicknessMap!==void 0&&(this.thicknessMap=e[t.thicknessMap]||null),t.anisotropyMap!==void 0&&(this.anisotropyMap=e[t.anisotropyMap]||null),t.sheenColorMap!==void 0&&(this.sheenColorMap=e[t.sheenColorMap]||null),t.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=e[t.sheenRoughnessMap]||null),this}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 i=null;if(e!==null){const n=e.length;i=new Array(n);for(let s=0;s!==n;++s)i[s]=e[s].clone()}return this.clippingPlanes=i,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.allowOverride=t.allowOverride,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++}}class Yh extends fr{constructor(t){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new st(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.rotation=t.rotation,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}let ho;const mc=new R,uo=new R,fo=new R,po=new bt,gc=new bt,t2=new ne,Wl=new R,vc=new R,Xl=new R,kg=new bt,Gd=new bt,Fg=new bt;class Mc extends ti{constructor(t=new Yh){if(super(),this.isSprite=!0,this.type="Sprite",ho===void 0){ho=new ae;const e=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new QM(e,5);ho.setIndex([0,1,2,0,2,3]),ho.setAttribute("position",new Iu(i,3,0,!1)),ho.setAttribute("uv",new Iu(i,2,3,!1))}this.geometry=ho,this.material=t,this.center=new bt(.5,.5),this.count=1}raycast(t,e){t.camera===null&&qt('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),uo.setFromMatrixScale(this.matrixWorld),t2.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),fo.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&uo.multiplyScalar(-fo.z);const i=this.material.rotation;let n,s;i!==0&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;Yl(Wl.set(-.5,-.5,0),fo,r,uo,n,s),Yl(vc.set(.5,-.5,0),fo,r,uo,n,s),Yl(Xl.set(.5,.5,0),fo,r,uo,n,s),kg.set(0,0),Gd.set(1,0),Fg.set(1,1);let o=t.ray.intersectTriangle(Wl,vc,Xl,!1,mc);if(o===null&&(Yl(vc.set(-.5,.5,0),fo,r,uo,n,s),Gd.set(0,1),o=t.ray.intersectTriangle(Wl,Xl,vc,!1,mc),o===null))return;const c=t.ray.origin.distanceTo(mc);c<t.near||c>t.far||e.push({distance:c,point:mc.clone(),uv:qn.getInterpolation(mc,Wl,vc,Xl,kg,Gd,Fg,new bt),face:null,object:this})}copy(t,e){return super.copy(t,e),t.center!==void 0&&this.center.copy(t.center),this.material=t.material,this}}function Yl(a,t,e,i,n,s){po.subVectors(a,e).addScalar(.5).multiply(i),n!==void 0?(gc.x=s*po.x-n*po.y,gc.y=n*po.x+s*po.y):gc.copy(po),a.copy(t),a.x+=gc.x,a.y+=gc.y,a.applyMatrix4(t2)}const Zs=new R,Vd=new R,ql=new R,Sr=new R,Wd=new R,$l=new R,Xd=new R;class bl{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,Zs)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Zs.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Zs.copy(this.origin).addScaledVector(this.direction,e),Zs.distanceToSquared(t))}distanceSqToSegment(t,e,i,n){Vd.copy(t).add(e).multiplyScalar(.5),ql.copy(e).sub(t).normalize(),Sr.copy(this.origin).sub(Vd);const s=t.distanceTo(e)*.5,r=-this.direction.dot(ql),o=Sr.dot(this.direction),c=-Sr.dot(ql),l=Sr.lengthSq(),h=Math.abs(1-r*r);let u,d,f,p;if(h>0)if(u=r*c-o,d=r*o-c,p=s*h,u>=0)if(d>=-p)if(d<=p){const v=1/h;u*=v,d*=v,f=u*(u+r*d+2*o)+d*(r*u+d+2*c)+l}else d=s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;else d=-s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;else d<=-p?(u=Math.max(0,-(-r*s+o)),d=u>0?-s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l):d<=p?(u=0,d=Math.min(Math.max(-s,-c),s),f=d*(d+2*c)+l):(u=Math.max(0,-(r*s+o)),d=u>0?s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l);else d=r>0?-s:s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,u),n&&n.copy(Vd).addScaledVector(ql,d),f}intersectSphere(t,e){Zs.subVectors(t.center,this.origin);const i=Zs.dot(this.direction),n=Zs.dot(Zs)-i*i,s=t.radius*t.radius;if(n>s)return null;const r=Math.sqrt(s-n),o=i-r,c=i+r;return c<0?null:o<0?this.at(c,e):this.at(o,e)}intersectsSphere(t){return t.radius<0?!1: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 i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,n,s,r,o,c;const l=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,d=this.origin;return l>=0?(i=(t.min.x-d.x)*l,n=(t.max.x-d.x)*l):(i=(t.max.x-d.x)*l,n=(t.min.x-d.x)*l),h>=0?(s=(t.min.y-d.y)*h,r=(t.max.y-d.y)*h):(s=(t.max.y-d.y)*h,r=(t.min.y-d.y)*h),i>r||s>n||((s>i||isNaN(i))&&(i=s),(r<n||isNaN(n))&&(n=r),u>=0?(o=(t.min.z-d.z)*u,c=(t.max.z-d.z)*u):(o=(t.max.z-d.z)*u,c=(t.min.z-d.z)*u),i>c||o>n)||((o>i||i!==i)&&(i=o),(c<n||n!==n)&&(n=c),n<0)?null:this.at(i>=0?i:n,e)}intersectsBox(t){return this.intersectBox(t,Zs)!==null}intersectTriangle(t,e,i,n,s){Wd.subVectors(e,t),$l.subVectors(i,t),Xd.crossVectors(Wd,$l);let r=this.direction.dot(Xd),o;if(r>0){if(n)return null;o=1}else if(r<0)o=-1,r=-r;else return null;Sr.subVectors(this.origin,t);const c=o*this.direction.dot($l.crossVectors(Sr,$l));if(c<0)return null;const l=o*this.direction.dot(Wd.cross(Sr));if(l<0||c+l>r)return null;const h=-o*Sr.dot(Xd);return h<0?null:this.at(h/r,s)}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 wn extends fr{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new st(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 hr,this.combine=Rp,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 Ug=new ne,Qr=new bl,Kl=new dr,zg=new R,Zl=new R,Jl=new R,jl=new R,Yd=new R,Ql=new R,Bg=new R,th=new R;class At extends ti{constructor(t=new ae,e=new wn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,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,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}getVertexPosition(t,e){const i=this.geometry,n=i.attributes.position,s=i.morphAttributes.position,r=i.morphTargetsRelative;e.fromBufferAttribute(n,t);const o=this.morphTargetInfluences;if(s&&o){Ql.set(0,0,0);for(let c=0,l=s.length;c<l;c++){const h=o[c],u=s[c];h!==0&&(Yd.fromBufferAttribute(u,t),r?Ql.addScaledVector(Yd,h):Ql.addScaledVector(Yd.sub(e),h))}e.add(Ql)}return e}raycast(t,e){const i=this.geometry,n=this.material,s=this.matrixWorld;n!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),Kl.copy(i.boundingSphere),Kl.applyMatrix4(s),Qr.copy(t.ray).recast(t.near),!(Kl.containsPoint(Qr.origin)===!1&&(Qr.intersectSphere(Kl,zg)===null||Qr.origin.distanceToSquared(zg)>(t.far-t.near)**2))&&(Ug.copy(s).invert(),Qr.copy(t.ray).applyMatrix4(Ug),!(i.boundingBox!==null&&Qr.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(t,e,Qr)))}_computeIntersections(t,e,i){let n;const s=this.geometry,r=this.material,o=s.index,c=s.attributes.position,l=s.attributes.uv,h=s.attributes.uv1,u=s.attributes.normal,d=s.groups,f=s.drawRange;if(o!==null)if(Array.isArray(r))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=r[m.materialIndex],b=Math.max(m.start,f.start),S=Math.min(o.count,Math.min(m.start+m.count,f.start+f.count));for(let M=b,x=S;M<x;M+=3){const _=o.getX(M),E=o.getX(M+1),y=o.getX(M+2);n=eh(this,g,t,i,l,h,u,_,E,y),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,e.push(n))}}else{const p=Math.max(0,f.start),v=Math.min(o.count,f.start+f.count);for(let m=p,g=v;m<g;m+=3){const b=o.getX(m),S=o.getX(m+1),M=o.getX(m+2);n=eh(this,r,t,i,l,h,u,b,S,M),n&&(n.faceIndex=Math.floor(m/3),e.push(n))}}else if(c!==void 0)if(Array.isArray(r))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=r[m.materialIndex],b=Math.max(m.start,f.start),S=Math.min(c.count,Math.min(m.start+m.count,f.start+f.count));for(let M=b,x=S;M<x;M+=3){const _=M,E=M+1,y=M+2;n=eh(this,g,t,i,l,h,u,_,E,y),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,e.push(n))}}else{const p=Math.max(0,f.start),v=Math.min(c.count,f.start+f.count);for(let m=p,g=v;m<g;m+=3){const b=m,S=m+1,M=m+2;n=eh(this,r,t,i,l,h,u,b,S,M),n&&(n.faceIndex=Math.floor(m/3),e.push(n))}}}}function JS(a,t,e,i,n,s,r,o){let c;if(t.side===Qe?c=i.intersectTriangle(r,s,n,!0,o):c=i.intersectTriangle(n,s,r,t.side===Xr,o),c===null)return null;th.copy(o),th.applyMatrix4(a.matrixWorld);const l=e.ray.origin.distanceTo(th);return l<e.near||l>e.far?null:{distance:l,point:th.clone(),object:a}}function eh(a,t,e,i,n,s,r,o,c,l){a.getVertexPosition(o,Zl),a.getVertexPosition(c,Jl),a.getVertexPosition(l,jl);const h=JS(a,t,e,i,Zl,Jl,jl,Bg);if(h){const u=new R;qn.getBarycoord(Bg,Zl,Jl,jl,u),n&&(h.uv=qn.getInterpolatedAttribute(n,o,c,l,u,new bt)),s&&(h.uv1=qn.getInterpolatedAttribute(s,o,c,l,u,new bt)),r&&(h.normal=qn.getInterpolatedAttribute(r,o,c,l,u,new R),h.normal.dot(i.direction)>0&&h.normal.multiplyScalar(-1));const d={a:o,b:c,c:l,normal:new R,materialIndex:0};qn.getNormal(Zl,Jl,jl,d.normal),h.face=d,h.barycoord=u}return h}const yc=new ue,Hg=new ue,Gg=new ue,jS=new ue,Vg=new ne,ih=new R,qd=new dr,Wg=new ne,$d=new bl;class lI extends At{constructor(t,e){super(t,e),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=xg,this.bindMatrix=new ne,this.bindMatrixInverse=new ne,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const t=this.geometry;this.boundingBox===null&&(this.boundingBox=new Qi),this.boundingBox.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,ih),this.boundingBox.expandByPoint(ih)}computeBoundingSphere(){const t=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new dr),this.boundingSphere.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,ih),this.boundingSphere.expandByPoint(ih)}copy(t,e){return super.copy(t,e),this.bindMode=t.bindMode,this.bindMatrix.copy(t.bindMatrix),this.bindMatrixInverse.copy(t.bindMatrixInverse),this.skeleton=t.skeleton,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}raycast(t,e){const i=this.material,n=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),qd.copy(this.boundingSphere),qd.applyMatrix4(n),t.ray.intersectsSphere(qd)!==!1&&(Wg.copy(n).invert(),$d.copy(t.ray).applyMatrix4(Wg),!(this.boundingBox!==null&&$d.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(t,e,$d)))}getVertexPosition(t,e){return super.getVertexPosition(t,e),this.applyBoneTransform(t,e),e}bind(t,e){this.skeleton=t,e===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.copy(e).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const t=new ue,e=this.geometry.attributes.skinWeight;for(let i=0,n=e.count;i<n;i++){t.fromBufferAttribute(e,i);const s=1/t.manhattanLength();s!==1/0?t.multiplyScalar(s):t.set(1,0,0,0),e.setXYZW(i,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),this.bindMode===xg?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===jb?this.bindMatrixInverse.copy(this.bindMatrix).invert():Pt("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(t,e){const i=this.skeleton,n=this.geometry;Hg.fromBufferAttribute(n.attributes.skinIndex,t),Gg.fromBufferAttribute(n.attributes.skinWeight,t),e.isVector4?(yc.copy(e),e.set(0,0,0,0)):(yc.set(...e,1),e.set(0,0,0)),yc.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){const r=Gg.getComponent(s);if(r!==0){const o=Hg.getComponent(s);Vg.multiplyMatrices(i.bones[o].matrixWorld,i.boneInverses[o]),e.addScaledVector(jS.copy(yc).applyMatrix4(Vg),r)}}return e.isVector4&&(e.w=yc.w),e.applyMatrix4(this.bindMatrixInverse)}}class QS extends ti{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Vs extends Hi{constructor(t=null,e=1,i=1,n,s,r,o,c,l=Ue,h=Ue,u,d){super(null,r,o,c,l,h,n,s,u,d),this.isDataTexture=!0,this.image={data:t,width:e,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Xg=new ne,tw=new ne;class e2{constructor(t=[],e=[]){this.uuid=ds(),this.bones=t.slice(0),this.boneInverses=e,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const t=this.bones,e=this.boneInverses;if(this.boneMatrices=new Float32Array(t.length*16),e.length===0)this.calculateInverses();else if(t.length!==e.length){Pt("Skeleton: Number of inverse bone matrices does not match amount of bones."),this.boneInverses=[];for(let i=0,n=this.bones.length;i<n;i++)this.boneInverses.push(new ne)}}calculateInverses(){this.boneInverses.length=0;for(let t=0,e=this.bones.length;t<e;t++){const i=new ne;this.bones[t]&&i.copy(this.bones[t].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];i&&i.matrixWorld.copy(this.boneInverses[t]).invert()}for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];i&&(i.parent&&i.parent.isBone?(i.matrix.copy(i.parent.matrixWorld).invert(),i.matrix.multiply(i.matrixWorld)):i.matrix.copy(i.matrixWorld),i.matrix.decompose(i.position,i.quaternion,i.scale))}}update(){const t=this.bones,e=this.boneInverses,i=this.boneMatrices,n=this.boneTexture;for(let s=0,r=t.length;s<r;s++){const o=t[s]?t[s].matrixWorld:tw;Xg.multiplyMatrices(o,e[s]),Xg.toArray(i,s*16)}n!==null&&(n.needsUpdate=!0)}clone(){return new e2(this.bones,this.boneInverses)}computeBoneTexture(){let t=Math.sqrt(this.bones.length*4);t=Math.ceil(t/4)*4,t=Math.max(t,4);const e=new Float32Array(t*t*4);e.set(this.boneMatrices);const i=new Vs(e,t,t,Gi,ji);return i.needsUpdate=!0,this.boneMatrices=e,this.boneTexture=i,this}getBoneByName(t){for(let e=0,i=this.bones.length;e<i;e++){const n=this.bones[e];if(n.name===t)return n}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(t,e){this.uuid=t.uuid;for(let i=0,n=t.bones.length;i<n;i++){const s=t.bones[i];let r=e[s];r===void 0&&(Pt("Skeleton: No bone found with UUID:",s),r=new QS),this.bones.push(r),this.boneInverses.push(new ne().fromArray(t.boneInverses[i]))}return this.init(),this}toJSON(){const t={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};t.uuid=this.uuid;const e=this.bones,i=this.boneInverses;for(let n=0,s=e.length;n<s;n++){const r=e[n];t.bones.push(r.uuid);const o=i[n];t.boneInverses.push(o.toArray())}return t}}class Yg extends te{constructor(t,e,i,n=1){super(t,e,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=n}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}const mo=new ne,qg=new ne,nh=[],$g=new Qi,ew=new ne,xc=new At,bc=new dr;class hI extends At{constructor(t,e,i){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new Yg(new Float32Array(i*16),16),this.instanceColor=null,this.morphTexture=null,this.count=i,this.boundingBox=null,this.boundingSphere=null;for(let n=0;n<i;n++)this.setMatrixAt(n,ew)}computeBoundingBox(){const t=this.geometry,e=this.count;this.boundingBox===null&&(this.boundingBox=new Qi),t.boundingBox===null&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,mo),$g.copy(t.boundingBox).applyMatrix4(mo),this.boundingBox.union($g)}computeBoundingSphere(){const t=this.geometry,e=this.count;this.boundingSphere===null&&(this.boundingSphere=new dr),t.boundingSphere===null&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,mo),bc.copy(t.boundingSphere).applyMatrix4(mo),this.boundingSphere.union(bc)}copy(t,e){return super.copy(t,e),this.instanceMatrix.copy(t.instanceMatrix),t.morphTexture!==null&&(this.morphTexture=t.morphTexture.clone()),t.instanceColor!==null&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}getColorAt(t,e){return this.instanceColor===null?e.setRGB(1,1,1):e.fromArray(this.instanceColor.array,t*3)}getMatrixAt(t,e){return e.fromArray(this.instanceMatrix.array,t*16)}getMorphAt(t,e){const i=e.morphTargetInfluences,n=this.morphTexture.source.data.data,s=i.length+1,r=t*s+1;for(let o=0;o<i.length;o++)i[o]=n[r+o]}raycast(t,e){const i=this.matrixWorld,n=this.count;if(xc.geometry=this.geometry,xc.material=this.material,xc.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),bc.copy(this.boundingSphere),bc.applyMatrix4(i),t.ray.intersectsSphere(bc)!==!1))for(let s=0;s<n;s++){this.getMatrixAt(s,mo),qg.multiplyMatrices(i,mo),xc.matrixWorld=qg,xc.raycast(t,nh);for(let r=0,o=nh.length;r<o;r++){const c=nh[r];c.instanceId=s,c.object=this,e.push(c)}nh.length=0}}setColorAt(t,e){return this.instanceColor===null&&(this.instanceColor=new Yg(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),e.toArray(this.instanceColor.array,t*3),this}setMatrixAt(t,e){return e.toArray(this.instanceMatrix.array,t*16),this}setMorphAt(t,e){const i=e.morphTargetInfluences,n=i.length+1;this.morphTexture===null&&(this.morphTexture=new Vs(new Float32Array(n*this.count),n,this.count,tc,ji));const s=this.morphTexture.source.data.data;let r=0;for(let l=0;l<i.length;l++)r+=i[l];const o=this.geometry.morphTargetsRelative?1:1-r,c=n*t;return s[c]=o,s.set(i,c+1),this}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"}),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null)}}const Kd=new R,iw=new R,nw=new Jt;class Ir{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,i,n){return this.normal.set(t,e,i),this.constant=n,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const n=Kd.subVectors(i,e).cross(iw.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(n,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,i=!0){const n=t.delta(Kd),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 i===!0&&(r<0||r>1)?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<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 i=e||nw.getNormalMatrix(t),n=this.coplanarPoint(Kd).applyMatrix4(t),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),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 ta=new dr,sw=new bt(.5,.5),sh=new R;class Vp{constructor(t=new Ir,e=new Ir,i=new Ir,n=new Ir,s=new Ir,r=new Ir){this.planes=[t,e,i,n,s,r]}set(t,e,i,n,s,r){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(i),o[3].copy(n),o[4].copy(s),o[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t,e=Us,i=!1){const n=this.planes,s=t.elements,r=s[0],o=s[1],c=s[2],l=s[3],h=s[4],u=s[5],d=s[6],f=s[7],p=s[8],v=s[9],m=s[10],g=s[11],b=s[12],S=s[13],M=s[14],x=s[15];if(n[0].setComponents(l-r,f-h,g-p,x-b).normalize(),n[1].setComponents(l+r,f+h,g+p,x+b).normalize(),n[2].setComponents(l+o,f+u,g+v,x+S).normalize(),n[3].setComponents(l-o,f-u,g-v,x-S).normalize(),i)n[4].setComponents(c,d,m,M).normalize(),n[5].setComponents(l-c,f-d,g-m,x-M).normalize();else if(n[4].setComponents(l-c,f-d,g-m,x-M).normalize(),e===Us)n[5].setComponents(l+c,f+d,g+m,x+M).normalize();else if(e===ul)n[5].setComponents(c,d,m,M).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(),ta.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),ta.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(ta)}intersectsSprite(t){ta.center.set(0,0,0);const e=sw.distanceTo(t.center);return ta.radius=.7071067811865476+e,ta.applyMatrix4(t.matrixWorld),this.intersectsSphere(ta)}intersectsSphere(t){const e=this.planes,i=t.center,n=-t.radius;for(let s=0;s<6;s++)if(e[s].distanceToPoint(i)<n)return!1;return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const n=e[i];if(sh.x=n.normal.x>0?t.max.x:t.min.x,sh.y=n.normal.y>0?t.max.y:t.min.y,sh.z=n.normal.z>0?t.max.z:t.min.z,n.distanceToPoint(sh)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class rw extends fr{constructor(t){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new st(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this.fog=t.fog,this}}const Cu=new R,Pu=new R,Kg=new ne,Sc=new bl,rh=new dr,Zd=new R,Zg=new R;class i2 extends ti{constructor(t=new ae,e=new rw){super(),this.isLine=!0,this.type="Line",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[0];for(let n=1,s=e.count;n<s;n++)Cu.fromBufferAttribute(e,n-1),Pu.fromBufferAttribute(e,n),i[n]=i[n-1],i[n]+=Cu.distanceTo(Pu);t.setAttribute("lineDistance",new ve(i,1))}else Pt("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Line.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),rh.copy(i.boundingSphere),rh.applyMatrix4(n),rh.radius+=s,t.ray.intersectsSphere(rh)===!1)return;Kg.copy(n).invert(),Sc.copy(t.ray).applyMatrix4(Kg);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),c=o*o,l=this.isLineSegments?2:1,h=i.index,d=i.attributes.position;if(h!==null){const f=Math.max(0,r.start),p=Math.min(h.count,r.start+r.count);for(let v=f,m=p-1;v<m;v+=l){const g=h.getX(v),b=h.getX(v+1),S=ah(this,t,Sc,c,g,b,v);S&&e.push(S)}if(this.isLineLoop){const v=h.getX(p-1),m=h.getX(f),g=ah(this,t,Sc,c,v,m,p-1);g&&e.push(g)}}else{const f=Math.max(0,r.start),p=Math.min(d.count,r.start+r.count);for(let v=f,m=p-1;v<m;v+=l){const g=ah(this,t,Sc,c,v,v+1,v);g&&e.push(g)}if(this.isLineLoop){const v=ah(this,t,Sc,c,p-1,f,p-1);v&&e.push(v)}}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function ah(a,t,e,i,n,s,r){const o=a.geometry.attributes.position;if(Cu.fromBufferAttribute(o,n),Pu.fromBufferAttribute(o,s),e.distanceSqToSegment(Cu,Pu,Zd,Zg)>i)return;Zd.applyMatrix4(a.matrixWorld);const l=t.ray.origin.distanceTo(Zd);if(!(l<t.near||l>t.far))return{distance:l,point:Zg.clone().applyMatrix4(a.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:a}}const Jg=new R,jg=new R;class uI extends i2{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[];for(let n=0,s=e.count;n<s;n+=2)Jg.fromBufferAttribute(e,n),jg.fromBufferAttribute(e,n+1),i[n]=n===0?0:i[n-1],i[n+1]=i[n]+Jg.distanceTo(jg);t.setAttribute("lineDistance",new ve(i,1))}else Pt("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class dI extends i2{constructor(t,e){super(t,e),this.isLineLoop=!0,this.type="LineLoop"}}class F0 extends fr{constructor(t){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new st(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}const Qg=new ne,U0=new bl,oh=new dr,ch=new R;class In extends ti{constructor(t=new ae,e=new F0){super(),this.isPoints=!0,this.type="Points",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Points.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),oh.copy(i.boundingSphere),oh.applyMatrix4(n),oh.radius+=s,t.ray.intersectsSphere(oh)===!1)return;Qg.copy(n).invert(),U0.copy(t.ray).applyMatrix4(Qg);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),c=o*o,l=i.index,u=i.attributes.position;if(l!==null){const d=Math.max(0,r.start),f=Math.min(l.count,r.start+r.count);for(let p=d,v=f;p<v;p++){const m=l.getX(p);ch.fromBufferAttribute(u,m),t1(ch,m,c,n,t,e,this)}}else{const d=Math.max(0,r.start),f=Math.min(u.count,r.start+r.count);for(let p=d,v=f;p<v;p++)ch.fromBufferAttribute(u,p),t1(ch,p,c,n,t,e,this)}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function t1(a,t,e,i,n,s,r){const o=U0.distanceSqToPoint(a);if(o<e){const c=new R;U0.closestPointToPoint(a,c),c.applyMatrix4(i);const l=n.ray.origin.distanceTo(c);if(l<n.near||l>n.far)return;s.push({distance:l,distanceToRay:Math.sqrt(o),point:c,index:t,face:null,faceIndex:null,barycoord:null,object:r})}}class n2 extends Hi{constructor(t=[],e=Ba,i,n,s,r,o,c,l,h){super(t,e,i,n,s,r,o,c,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class pr extends Hi{constructor(t,e,i,n,s,r,o,c,l){super(t,e,i,n,s,r,o,c,l),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Yr extends Hi{constructor(t,e,i=Kn,n,s,r,o=Ue,c=Ue,l,h=lr,u=1){if(h!==lr&&h!==Ta)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:t,height:e,depth:u};super(d,n,s,r,o,c,h,i,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.source=new zp(Object.assign({},t.image)),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}class aw extends Yr{constructor(t,e=Kn,i=Ba,n,s,r=Ue,o=Ue,c,l=lr){const h={width:t,height:t,depth:1},u=[h,h,h,h,h,h];super(t,t,e,i,n,s,r,o,c,l),this.image=u,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(t){this.image=t}}class s2 extends Hi{constructor(t=null){super(),this.sourceTexture=t,this.isExternalTexture=!0}copy(t){return super.copy(t),this.sourceTexture=t.sourceTexture,this}}class Vi extends ae{constructor(t=1,e=1,i=1,n=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:n,heightSegments:s,depthSegments:r};const o=this;n=Math.floor(n),s=Math.floor(s),r=Math.floor(r);const c=[],l=[],h=[],u=[];let d=0,f=0;p("z","y","x",-1,-1,i,e,t,r,s,0),p("z","y","x",1,-1,i,e,-t,r,s,1),p("x","z","y",1,1,t,i,e,n,r,2),p("x","z","y",1,-1,t,i,-e,n,r,3),p("x","y","z",1,-1,t,e,i,n,s,4),p("x","y","z",-1,-1,t,e,-i,n,s,5),this.setIndex(c),this.setAttribute("position",new ve(l,3)),this.setAttribute("normal",new ve(h,3)),this.setAttribute("uv",new ve(u,2));function p(v,m,g,b,S,M,x,_,E,y,T){const I=M/E,C=x/y,P=M/2,B=x/2,W=_/2,O=E+1,H=y+1;let U=0,q=0;const Q=new R;for(let J=0;J<H;J++){const it=J*C-B;for(let ot=0;ot<O;ot++){const $t=ot*I-P;Q[v]=$t*b,Q[m]=it*S,Q[g]=W,l.push(Q.x,Q.y,Q.z),Q[v]=0,Q[m]=0,Q[g]=_>0?1:-1,h.push(Q.x,Q.y,Q.z),u.push(ot/E),u.push(1-J/y),U+=1}}for(let J=0;J<y;J++)for(let it=0;it<E;it++){const ot=d+it+O*J,$t=d+it+O*(J+1),re=d+(it+1)+O*(J+1),jt=d+(it+1)+O*J;c.push(ot,$t,jt),c.push($t,re,jt),q+=6}o.addGroup(f,q,T),f+=q,d+=U}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Vi(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}class Wp extends ae{constructor(t=1,e=32,i=0,n=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:i,thetaLength:n},e=Math.max(3,e);const s=[],r=[],o=[],c=[],l=new R,h=new bt;r.push(0,0,0),o.push(0,0,1),c.push(.5,.5);for(let u=0,d=3;u<=e;u++,d+=3){const f=i+u/e*n;l.x=t*Math.cos(f),l.y=t*Math.sin(f),r.push(l.x,l.y,l.z),o.push(0,0,1),h.x=(r[d]/t+1)/2,h.y=(r[d+1]/t+1)/2,c.push(h.x,h.y)}for(let u=1;u<=e;u++)s.push(u,u+1,0);this.setIndex(s),this.setAttribute("position",new ve(r,3)),this.setAttribute("normal",new ve(o,3)),this.setAttribute("uv",new ve(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Wp(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class Zn extends ae{constructor(t=1,e=1,i=1,n=32,s=1,r=!1,o=0,c=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:i,radialSegments:n,heightSegments:s,openEnded:r,thetaStart:o,thetaLength:c};const l=this;n=Math.floor(n),s=Math.floor(s);const h=[],u=[],d=[],f=[];let p=0;const v=[],m=i/2;let g=0;b(),r===!1&&(t>0&&S(!0),e>0&&S(!1)),this.setIndex(h),this.setAttribute("position",new ve(u,3)),this.setAttribute("normal",new ve(d,3)),this.setAttribute("uv",new ve(f,2));function b(){const M=new R,x=new R;let _=0;const E=(e-t)/i;for(let y=0;y<=s;y++){const T=[],I=y/s,C=I*(e-t)+t;for(let P=0;P<=n;P++){const B=P/n,W=B*c+o,O=Math.sin(W),H=Math.cos(W);x.x=C*O,x.y=-I*i+m,x.z=C*H,u.push(x.x,x.y,x.z),M.set(O,E,H).normalize(),d.push(M.x,M.y,M.z),f.push(B,1-I),T.push(p++)}v.push(T)}for(let y=0;y<n;y++)for(let T=0;T<s;T++){const I=v[T][y],C=v[T+1][y],P=v[T+1][y+1],B=v[T][y+1];(t>0||T!==0)&&(h.push(I,C,B),_+=3),(e>0||T!==s-1)&&(h.push(C,P,B),_+=3)}l.addGroup(g,_,0),g+=_}function S(M){const x=p,_=new bt,E=new R;let y=0;const T=M===!0?t:e,I=M===!0?1:-1;for(let P=1;P<=n;P++)u.push(0,m*I,0),d.push(0,I,0),f.push(.5,.5),p++;const C=p;for(let P=0;P<=n;P++){const W=P/n*c+o,O=Math.cos(W),H=Math.sin(W);E.x=T*H,E.y=m*I,E.z=T*O,u.push(E.x,E.y,E.z),d.push(0,I,0),_.x=O*.5+.5,_.y=H*.5*I+.5,f.push(_.x,_.y),p++}for(let P=0;P<n;P++){const B=x+P,W=C+P;M===!0?h.push(W,W+1,B):h.push(W+1,W,B),y+=3}l.addGroup(g,y,M===!0?1:2),g+=y}}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 rc extends Zn{constructor(t=1,e=1,i=32,n=1,s=!1,r=0,o=Math.PI*2){super(0,t,e,i,n,s,r,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:i,heightSegments:n,openEnded:s,thetaStart:r,thetaLength:o}}static fromJSON(t){return new rc(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class id extends ae{constructor(t=[new bt(0,-.5),new bt(.5,0),new bt(0,.5)],e=12,i=0,n=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:i,phiLength:n},e=Math.floor(e),n=Qt(n,0,Math.PI*2);const s=[],r=[],o=[],c=[],l=[],h=1/e,u=new R,d=new bt,f=new R,p=new R,v=new R;let m=0,g=0;for(let b=0;b<=t.length-1;b++)switch(b){case 0:m=t[b+1].x-t[b].x,g=t[b+1].y-t[b].y,f.x=g*1,f.y=-m,f.z=g*0,v.copy(f),f.normalize(),c.push(f.x,f.y,f.z);break;case t.length-1:c.push(v.x,v.y,v.z);break;default:m=t[b+1].x-t[b].x,g=t[b+1].y-t[b].y,f.x=g*1,f.y=-m,f.z=g*0,p.copy(f),f.x+=v.x,f.y+=v.y,f.z+=v.z,f.normalize(),c.push(f.x,f.y,f.z),v.copy(p)}for(let b=0;b<=e;b++){const S=i+b*h*n,M=Math.sin(S),x=Math.cos(S);for(let _=0;_<=t.length-1;_++){u.x=t[_].x*M,u.y=t[_].y,u.z=t[_].x*x,r.push(u.x,u.y,u.z),d.x=b/e,d.y=_/(t.length-1),o.push(d.x,d.y);const E=c[3*_+0]*M,y=c[3*_+1],T=c[3*_+0]*x;l.push(E,y,T)}}for(let b=0;b<e;b++)for(let S=0;S<t.length-1;S++){const M=S+b*t.length,x=M,_=M+t.length,E=M+t.length+1,y=M+1;s.push(x,_,y),s.push(E,y,_)}this.setIndex(s),this.setAttribute("position",new ve(r,3)),this.setAttribute("uv",new ve(o,2)),this.setAttribute("normal",new ve(l,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new id(t.points,t.segments,t.phiStart,t.phiLength)}}class dn extends ae{constructor(t=1,e=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:n};const s=t/2,r=e/2,o=Math.floor(i),c=Math.floor(n),l=o+1,h=c+1,u=t/o,d=e/c,f=[],p=[],v=[],m=[];for(let g=0;g<h;g++){const b=g*d-r;for(let S=0;S<l;S++){const M=S*u-s;p.push(M,-b,0),v.push(0,0,1),m.push(S/o),m.push(1-g/c)}}for(let g=0;g<c;g++)for(let b=0;b<o;b++){const S=b+l*g,M=b+l*(g+1),x=b+1+l*(g+1),_=b+1+l*g;f.push(S,M,_),f.push(M,x,_)}this.setIndex(f),this.setAttribute("position",new ve(p,3)),this.setAttribute("normal",new ve(v,3)),this.setAttribute("uv",new ve(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new dn(t.width,t.height,t.widthSegments,t.heightSegments)}}class pi extends ae{constructor(t=1,e=32,i=16,n=0,s=Math.PI*2,r=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:i,phiStart:n,phiLength:s,thetaStart:r,thetaLength:o},e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));const c=Math.min(r+o,Math.PI);let l=0;const h=[],u=new R,d=new R,f=[],p=[],v=[],m=[];for(let g=0;g<=i;g++){const b=[],S=g/i,M=r+S*o,x=t*Math.cos(M),_=Math.sqrt(t*t-x*x);let E=0;g===0&&r===0?E=.5/e:g===i&&c===Math.PI&&(E=-.5/e);for(let y=0;y<=e;y++){const T=y/e,I=n+T*s;u.x=-_*Math.cos(I),u.y=x,u.z=_*Math.sin(I),p.push(u.x,u.y,u.z),d.copy(u).normalize(),v.push(d.x,d.y,d.z),m.push(T+E,1-S),b.push(l++)}h.push(b)}for(let g=0;g<i;g++)for(let b=0;b<e;b++){const S=h[g][b+1],M=h[g][b],x=h[g+1][b],_=h[g+1][b+1];(g!==0||r>0)&&f.push(S,M,_),(g!==i-1||c<Math.PI)&&f.push(M,x,_)}this.setIndex(f),this.setAttribute("position",new ve(p,3)),this.setAttribute("normal",new ve(v,3)),this.setAttribute("uv",new ve(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new pi(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class Xp extends ae{constructor(t=1,e=.4,i=12,n=48,s=Math.PI*2,r=0,o=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:i,tubularSegments:n,arc:s,thetaStart:r,thetaLength:o},i=Math.floor(i),n=Math.floor(n);const c=[],l=[],h=[],u=[],d=new R,f=new R,p=new R;for(let v=0;v<=i;v++){const m=r+v/i*o;for(let g=0;g<=n;g++){const b=g/n*s;f.x=(t+e*Math.cos(m))*Math.cos(b),f.y=(t+e*Math.cos(m))*Math.sin(b),f.z=e*Math.sin(m),l.push(f.x,f.y,f.z),d.x=t*Math.cos(b),d.y=t*Math.sin(b),p.subVectors(f,d).normalize(),h.push(p.x,p.y,p.z),u.push(g/n),u.push(v/i)}}for(let v=1;v<=i;v++)for(let m=1;m<=n;m++){const g=(n+1)*v+m-1,b=(n+1)*(v-1)+m-1,S=(n+1)*(v-1)+m,M=(n+1)*v+m;c.push(g,b,M),c.push(b,S,M)}this.setIndex(c),this.setAttribute("position",new ve(l,3)),this.setAttribute("normal",new ve(h,3)),this.setAttribute("uv",new ve(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Xp(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class fI extends ae{constructor(t=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:t},t!==null){const e=[],i=new Set,n=new R,s=new R;if(t.index!==null){const r=t.attributes.position,o=t.index;let c=t.groups;c.length===0&&(c=[{start:0,count:o.count,materialIndex:0}]);for(let l=0,h=c.length;l<h;++l){const u=c[l],d=u.start,f=u.count;for(let p=d,v=d+f;p<v;p+=3)for(let m=0;m<3;m++){const g=o.getX(p+m),b=o.getX(p+(m+1)%3);n.fromBufferAttribute(r,g),s.fromBufferAttribute(r,b),e1(n,s,i)===!0&&(e.push(n.x,n.y,n.z),e.push(s.x,s.y,s.z))}}}else{const r=t.attributes.position;for(let o=0,c=r.count/3;o<c;o++)for(let l=0;l<3;l++){const h=3*o+l,u=3*o+(l+1)%3;n.fromBufferAttribute(r,h),s.fromBufferAttribute(r,u),e1(n,s,i)===!0&&(e.push(n.x,n.y,n.z),e.push(s.x,s.y,s.z))}}this.setAttribute("position",new ve(e,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}function e1(a,t,e){const i=`${a.x},${a.y},${a.z}-${t.x},${t.y},${t.z}`,n=`${t.x},${t.y},${t.z}-${a.x},${a.y},${a.z}`;return e.has(i)===!0||e.has(n)===!0?!1:(e.add(i),e.add(n),!0)}function ic(a){const t={};for(const e in a){t[e]={};for(const i in a[e]){const n=a[e][i];if(i1(n))n.isRenderTargetTexture?(Pt("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[e][i]=null):t[e][i]=n.clone();else if(Array.isArray(n))if(i1(n[0])){const s=[];for(let r=0,o=n.length;r<o;r++)s[r]=n[r].clone();t[e][i]=s}else t[e][i]=n.slice();else t[e][i]=n}}return t}function en(a){const t={};for(let e=0;e<a.length;e++){const i=ic(a[e]);for(const n in i)t[n]=i[n]}return t}function i1(a){return a&&(a.isColor||a.isMatrix3||a.isMatrix4||a.isVector2||a.isVector3||a.isVector4||a.isTexture||a.isQuaternion)}function ow(a){const t=[];for(let e=0;e<a.length;e++)t.push(a[e].clone());return t}function r2(a){const t=a.getRenderTarget();return t===null?a.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:me.workingColorSpace}const cw={clone:ic,merge:en};var lw=`void main() {
2187
+ */const Tp="185",Pb=0,vg=1,Ob=2,Xc=1,Lb=2,Lc=3,Xr=0,Qe=1,bn=2,Bs=0,Vr=1,Ti=2,Mg=3,yg=4,xl=5,ha=100,Nb=101,kb=102,Fb=103,Ub=104,Nc=200,ol=201,zb=202,Bb=203,Zf=204,cl=205,Hb=206,Gb=207,Vb=208,Wb=209,Xb=210,Yb=211,qb=212,$b=213,Kb=214,Jf=0,jf=1,Qf=2,Jo=3,t0=4,e0=5,i0=6,n0=7,Rp=0,Zb=1,Jb=2,Hs=0,OM=1,LM=2,NM=3,kM=4,FM=5,UM=6,zM=7,xg="attached",jb="detached",BM=300,Ba=301,jo=302,bd=303,Sd=304,ed=306,Qo=1e3,Bi=1001,s0=1002,Ue=1003,Qb=1004,kl=1005,de=1006,wd=1007,Aa=1008,Ln=1009,HM=1010,GM=1011,ll=1012,Dp=1013,Kn=1014,ji=1015,qe=1016,Ip=1017,Cp=1018,hl=1020,VM=35902,WM=35899,XM=1021,YM=1022,Gi=1023,lr=1026,Ta=1027,tc=1028,Pp=1029,Ha=1030,Op=1031,Lp=1033,Gh=33776,Vh=33777,Wh=33778,Xh=33779,r0=35840,a0=35841,o0=35842,c0=35843,l0=36196,h0=37492,u0=37496,d0=37488,f0=37489,bu=37490,p0=37491,m0=37808,g0=37809,v0=37810,M0=37811,y0=37812,x0=37813,b0=37814,S0=37815,w0=37816,_0=37817,E0=37818,A0=37819,T0=37820,R0=37821,D0=36492,I0=36494,C0=36495,P0=36283,O0=36284,Su=36285,L0=36286,qM=2200,tS=2201,eS=2202,wu=2300,N0=2301,_d=2302,bg=2303,Io=2400,Co=2401,_u=2402,Np=2500,iS=2501,rI=0,aI=1,oI=2,nS=3200,Eu=0,sS=1,Lr="",un="srgb",Au="srgb-linear",Tu="linear",Pe="srgb",Qa=7680,Sg=519,rS=512,aS=513,oS=514,kp=515,cS=516,lS=517,Fp=518,hS=519,k0=35044,Ru="300 es",Us=2e3,ul=2001;function uS(a){for(let t=a.length-1;t>=0;--t)if(a[t]>=65535)return!0;return!1}function dS(a){return ArrayBuffer.isView(a)&&!(a instanceof DataView)}function dl(a){return document.createElementNS("http://www.w3.org/1999/xhtml",a)}function fS(){const a=dl("canvas");return a.style.display="block",a}const wg={};function Du(...a){const t="THREE."+a.shift();console.log(t,...a)}function $M(a){const t=a[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=a[1];e&&e.isStackTrace?a[0]+=" "+e.getLocation():a[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return a}function Pt(...a){a=$M(a);const t="THREE."+a.shift();{const e=a[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...a)}}function qt(...a){a=$M(a);const t="THREE."+a.shift();{const e=a[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...a)}}function Uo(...a){const t=a.join(" ");t in wg||(wg[t]=!0,Pt(...a))}function pS(a,t,e){return new Promise(function(i,n){function s(){switch(a.clientWaitSync(t,a.SYNC_FLUSH_COMMANDS_BIT,0)){case a.WAIT_FAILED:n();break;case a.TIMEOUT_EXPIRED:setTimeout(s,e);break;default:i()}}setTimeout(s,e)})}const mS={[Jf]:jf,[Qf]:i0,[t0]:n0,[Jo]:e0,[jf]:Jf,[i0]:Qf,[n0]:t0,[e0]:Jo};class $r{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const n=i[t];if(n!==void 0){const s=n.indexOf(e);s!==-1&&n.splice(s,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const n=i.slice(0);for(let s=0,r=n.length;s<r;s++)n[s].call(this,t);t.target=null}}}const Xi=["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 _g=1234567;const Yc=Math.PI/180,ec=180/Math.PI;function ds(){const a=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Xi[a&255]+Xi[a>>8&255]+Xi[a>>16&255]+Xi[a>>24&255]+"-"+Xi[t&255]+Xi[t>>8&255]+"-"+Xi[t>>16&15|64]+Xi[t>>24&255]+"-"+Xi[e&63|128]+Xi[e>>8&255]+"-"+Xi[e>>16&255]+Xi[e>>24&255]+Xi[i&255]+Xi[i>>8&255]+Xi[i>>16&255]+Xi[i>>24&255]).toLowerCase()}function Qt(a,t,e){return Math.max(t,Math.min(e,a))}function Up(a,t){return(a%t+t)%t}function gS(a,t,e,i,n){return i+(a-t)*(n-i)/(e-t)}function vS(a,t,e){return a!==t?(e-a)/(t-a):0}function qc(a,t,e){return(1-e)*a+e*t}function MS(a,t,e,i){return qc(a,t,1-Math.exp(-e*i))}function yS(a,t=1){return t-Math.abs(Up(a,t*2)-t)}function xS(a,t,e){return a<=t?0:a>=e?1:(a=(a-t)/(e-t),a*a*(3-2*a))}function bS(a,t,e){return a<=t?0:a>=e?1:(a=(a-t)/(e-t),a*a*a*(a*(a*6-15)+10))}function SS(a,t){return a+Math.floor(Math.random()*(t-a+1))}function wS(a,t){return a+Math.random()*(t-a)}function _S(a){return a*(.5-Math.random())}function ES(a){a!==void 0&&(_g=a);let t=_g+=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 AS(a){return a*Yc}function TS(a){return a*ec}function RS(a){return(a&a-1)===0&&a!==0}function DS(a){return Math.pow(2,Math.ceil(Math.log(a)/Math.LN2))}function IS(a){return Math.pow(2,Math.floor(Math.log(a)/Math.LN2))}function CS(a,t,e,i,n){const s=Math.cos,r=Math.sin,o=s(e/2),c=r(e/2),l=s((t+i)/2),h=r((t+i)/2),u=s((t-i)/2),d=r((t-i)/2),f=s((i-t)/2),p=r((i-t)/2);switch(n){case"XYX":a.set(o*h,c*u,c*d,o*l);break;case"YZY":a.set(c*d,o*h,c*u,o*l);break;case"ZXZ":a.set(c*u,c*d,o*h,o*l);break;case"XZX":a.set(o*h,c*p,c*f,o*l);break;case"YXY":a.set(c*f,o*h,c*p,o*l);break;case"ZYZ":a.set(c*p,c*f,o*h,o*l);break;default:Pt("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function hs(a,t){switch(t.constructor){case Float32Array:return a;case Uint32Array:return a/4294967295;case Uint16Array:return a/65535;case Uint8Array:return a/255;case Int32Array:return Math.max(a/2147483647,-1);case Int16Array:return Math.max(a/32767,-1);case Int8Array:return Math.max(a/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function Oe(a,t){switch(t.constructor){case Float32Array:return a;case Uint32Array:return Math.round(a*4294967295);case Uint16Array:return Math.round(a*65535);case Uint8Array:return Math.round(a*255);case Int32Array:return Math.round(a*2147483647);case Int16Array:return Math.round(a*32767);case Int8Array:return Math.round(a*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const cI={DEG2RAD:Yc,RAD2DEG:ec,generateUUID:ds,clamp:Qt,euclideanModulo:Up,mapLinear:gS,inverseLerp:vS,lerp:qc,damp:MS,pingpong:yS,smoothstep:xS,smootherstep:bS,randInt:SS,randFloat:wS,randFloatSpread:_S,seededRandom:ES,degToRad:AS,radToDeg:TS,isPowerOfTwo:RS,ceilPowerOfTwo:DS,floorPowerOfTwo:IS,setQuaternionFromProperEuler:CS,normalize:Oe,denormalize:hs};class bt{static{bt.prototype.isVector2=!0}constructor(t=0,e=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("THREE.Vector2: 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("THREE.Vector2: 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,i=this.y,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6],this.y=n[1]*e+n[4]*i+n[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=Qt(this.x,t.x,e.x),this.y=Qt(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=Qt(this.x,t,e),this.y=Qt(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qt(i,t,e))}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 i=this.dot(t)/e;return Math.acos(Qt(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,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 i=Math.cos(e),n=Math.sin(e),s=this.x-t.x,r=this.y-t.y;return this.x=s*i-r*n+t.x,this.y=s*n+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Sn{constructor(t=0,e=0,i=0,n=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=n}static slerpFlat(t,e,i,n,s,r,o){let c=i[n+0],l=i[n+1],h=i[n+2],u=i[n+3],d=s[r+0],f=s[r+1],p=s[r+2],v=s[r+3];if(u!==v||c!==d||l!==f||h!==p){let m=c*d+l*f+h*p+u*v;m<0&&(d=-d,f=-f,p=-p,v=-v,m=-m);let g=1-o;if(m<.9995){const b=Math.acos(m),S=Math.sin(b);g=Math.sin(g*b)/S,o=Math.sin(o*b)/S,c=c*g+d*o,l=l*g+f*o,h=h*g+p*o,u=u*g+v*o}else{c=c*g+d*o,l=l*g+f*o,h=h*g+p*o,u=u*g+v*o;const b=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=b,l*=b,h*=b,u*=b}}t[e]=c,t[e+1]=l,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,n,s,r){const o=i[n],c=i[n+1],l=i[n+2],h=i[n+3],u=s[r],d=s[r+1],f=s[r+2],p=s[r+3];return t[e]=o*p+h*u+c*f-l*d,t[e+1]=c*p+h*d+l*u-o*f,t[e+2]=l*p+h*f+o*d-c*u,t[e+3]=h*p-o*u-c*d-l*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,i,n){return this._x=t,this._y=e,this._z=i,this._w=n,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 i=t._x,n=t._y,s=t._z,r=t._order,o=Math.cos,c=Math.sin,l=o(i/2),h=o(n/2),u=o(s/2),d=c(i/2),f=c(n/2),p=c(s/2);switch(r){case"XYZ":this._x=d*h*u+l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u-d*f*p;break;case"YXZ":this._x=d*h*u+l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u+d*f*p;break;case"ZXY":this._x=d*h*u-l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u-d*f*p;break;case"ZYX":this._x=d*h*u-l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u+d*f*p;break;case"YZX":this._x=d*h*u+l*f*p,this._y=l*f*u+d*h*p,this._z=l*h*p-d*f*u,this._w=l*h*u-d*f*p;break;case"XZY":this._x=d*h*u-l*f*p,this._y=l*f*u-d*h*p,this._z=l*h*p+d*f*u,this._w=l*h*u+d*f*p;break;default:Pt("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,n=Math.sin(i);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],n=e[4],s=e[8],r=e[1],o=e[5],c=e[9],l=e[2],h=e[6],u=e[10],d=i+o+u;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(h-c)*f,this._y=(s-l)*f,this._z=(r-n)*f}else if(i>o&&i>u){const f=2*Math.sqrt(1+i-o-u);this._w=(h-c)/f,this._x=.25*f,this._y=(n+r)/f,this._z=(s+l)/f}else if(o>u){const f=2*Math.sqrt(1+o-i-u);this._w=(s-l)/f,this._x=(n+r)/f,this._y=.25*f,this._z=(c+h)/f}else{const f=2*Math.sqrt(1+u-i-o);this._w=(r-n)/f,this._x=(s+l)/f,this._y=(c+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(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=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Qt(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const n=Math.min(1,e/i);return this.slerp(t,n),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 i=t._x,n=t._y,s=t._z,r=t._w,o=e._x,c=e._y,l=e._z,h=e._w;return this._x=i*h+r*o+n*l-s*c,this._y=n*h+r*c+s*o-i*l,this._z=s*h+r*l+i*c-n*o,this._w=r*h-i*o-n*c-s*l,this._onChangeCallback(),this}slerp(t,e){let i=t._x,n=t._y,s=t._z,r=t._w,o=this.dot(t);o<0&&(i=-i,n=-n,s=-s,r=-r,o=-o);let c=1-e;if(o<.9995){const l=Math.acos(o),h=Math.sin(l);c=Math.sin(c*l)/h,e=Math.sin(e*l)/h,this._x=this._x*c+i*e,this._y=this._y*c+n*e,this._z=this._z*c+s*e,this._w=this._w*c+r*e,this._onChangeCallback()}else this._x=this._x*c+i*e,this._y=this._y*c+n*e,this._z=this._z*c+s*e,this._w=this._w*c+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),n=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(n*Math.sin(t),n*Math.cos(t),s*Math.sin(e),s*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{static{R.prototype.isVector3=!0}constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,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("THREE.Vector3: 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("THREE.Vector3: 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(Eg.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Eg.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6]*n,this.y=s[1]*e+s[4]*i+s[7]*n,this.z=s[2]*e+s[5]*i+s[8]*n,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t.elements,r=1/(s[3]*e+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*e+s[4]*i+s[8]*n+s[12])*r,this.y=(s[1]*e+s[5]*i+s[9]*n+s[13])*r,this.z=(s[2]*e+s[6]*i+s[10]*n+s[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,o=t.z,c=t.w,l=2*(r*n-o*i),h=2*(o*e-s*n),u=2*(s*i-r*e);return this.x=e+c*l+r*u-o*h,this.y=i+c*h+o*l-s*u,this.z=n+c*u+s*h-r*l,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,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[4]*i+s[8]*n,this.y=s[1]*e+s[5]*i+s[9]*n,this.z=s[2]*e+s[6]*i+s[10]*n,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=Qt(this.x,t.x,e.x),this.y=Qt(this.y,t.y,e.y),this.z=Qt(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=Qt(this.x,t,e),this.y=Qt(this.y,t,e),this.z=Qt(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qt(i,t,e))}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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,o=e.y,c=e.z;return this.x=n*c-s*o,this.y=s*r-i*c,this.z=i*o-n*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Ed.copy(this).projectOnVector(t),this.sub(Ed)}reflect(t){return this.sub(Ed.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 i=this.dot(t)/e;return Math.acos(Qt(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,n=this.z-t.z;return e*e+i*i+n*n}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,i){const n=Math.sin(e)*t;return this.x=n*Math.sin(i),this.y=Math.cos(e)*t,this.z=n*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,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(),i=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=n,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,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Ed=new R,Eg=new Sn;class Jt{static{Jt.prototype.isMatrix3=!0}constructor(t,e,i,n,s,r,o,c,l){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,n,s,r,o,c,l)}set(t,e,i,n,s,r,o,c,l){const h=this.elements;return h[0]=t,h[1]=n,h[2]=o,h[3]=e,h[4]=s,h[5]=c,h[6]=i,h[7]=r,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.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 i=t.elements,n=e.elements,s=this.elements,r=i[0],o=i[3],c=i[6],l=i[1],h=i[4],u=i[7],d=i[2],f=i[5],p=i[8],v=n[0],m=n[3],g=n[6],b=n[1],S=n[4],M=n[7],x=n[2],_=n[5],E=n[8];return s[0]=r*v+o*b+c*x,s[3]=r*m+o*S+c*_,s[6]=r*g+o*M+c*E,s[1]=l*v+h*b+u*x,s[4]=l*m+h*S+u*_,s[7]=l*g+h*M+u*E,s[2]=d*v+f*b+p*x,s[5]=d*m+f*S+p*_,s[8]=d*g+f*M+p*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],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8];return e*r*h-e*o*l-i*s*h+i*o*c+n*s*l-n*r*c}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=h*r-o*l,d=o*c-h*s,f=l*s-r*c,p=e*u+i*d+n*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const v=1/p;return t[0]=u*v,t[1]=(n*l-h*i)*v,t[2]=(o*i-n*r)*v,t[3]=d*v,t[4]=(h*e-n*c)*v,t[5]=(n*s-o*e)*v,t[6]=f*v,t[7]=(i*c-l*e)*v,t[8]=(r*e-i*s)*v,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,i,n,s,r,o){const c=Math.cos(s),l=Math.sin(s);return this.set(i*c,i*l,-i*(c*r+l*o)+r+t,-n*l,n*c,-n*(-l*r+c*o)+o+e,0,0,1),this}scale(t,e){return Uo("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Ad.makeScale(t,e)),this}rotate(t){return Uo("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Ad.makeRotation(-t)),this}translate(t,e){return Uo("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Ad.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),i=Math.sin(t);return this.set(e,-i,0,i,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,i=t.elements;for(let n=0;n<9;n++)if(e[n]!==i[n])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const Ad=new Jt,Ag=new Jt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Tg=new Jt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function PS(){const a={enabled:!0,workingColorSpace:Au,spaces:{},convert:function(n,s,r){return this.enabled===!1||s===r||!s||!r||(this.spaces[s].transfer===Pe&&(n.r=or(n.r),n.g=or(n.g),n.b=or(n.b)),this.spaces[s].primaries!==this.spaces[r].primaries&&(n.applyMatrix3(this.spaces[s].toXYZ),n.applyMatrix3(this.spaces[r].fromXYZ)),this.spaces[r].transfer===Pe&&(n.r=zo(n.r),n.g=zo(n.g),n.b=zo(n.b))),n},workingToColorSpace:function(n,s){return this.convert(n,this.workingColorSpace,s)},colorSpaceToWorking:function(n,s){return this.convert(n,s,this.workingColorSpace)},getPrimaries:function(n){return this.spaces[n].primaries},getTransfer:function(n){return n===Lr?Tu:this.spaces[n].transfer},getToneMappingMode:function(n){return this.spaces[n].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(n,s=this.workingColorSpace){return n.fromArray(this.spaces[s].luminanceCoefficients)},define:function(n){Object.assign(this.spaces,n)},_getMatrix:function(n,s,r){return n.copy(this.spaces[s].toXYZ).multiply(this.spaces[r].fromXYZ)},_getDrawingBufferColorSpace:function(n){return this.spaces[n].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(n=this.workingColorSpace){return this.spaces[n].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(n,s){return Uo("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),a.workingToColorSpace(n,s)},toWorkingColorSpace:function(n,s){return Uo("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),a.colorSpaceToWorking(n,s)}},t=[.64,.33,.3,.6,.15,.06],e=[.2126,.7152,.0722],i=[.3127,.329];return a.define({[Au]:{primaries:t,whitePoint:i,transfer:Tu,toXYZ:Ag,fromXYZ:Tg,luminanceCoefficients:e,workingColorSpaceConfig:{unpackColorSpace:un},outputColorSpaceConfig:{drawingBufferColorSpace:un}},[un]:{primaries:t,whitePoint:i,transfer:Pe,toXYZ:Ag,fromXYZ:Tg,luminanceCoefficients:e,outputColorSpaceConfig:{drawingBufferColorSpace:un}}}),a}const me=PS();function or(a){return a<.04045?a*.0773993808:Math.pow(a*.9478672986+.0521327014,2.4)}function zo(a){return a<.0031308?a*12.92:1.055*Math.pow(a,.41666)-.055}let to;class OS{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{to===void 0&&(to=dl("canvas")),to.width=t.width,to.height=t.height;const n=to.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),i=to}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=dl("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const n=i.getImageData(0,0,t.width,t.height),s=n.data;for(let r=0;r<s.length;r++)s[r]=or(s[r]/255)*255;return i.putImageData(n,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(or(e[i]/255)*255):e[i]=or(e[i]);return{data:e,width:t.width,height:t.height}}else return Pt("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let LS=0;class zp{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:LS++}),this.uuid=ds(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayWidth,e.displayHeight,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}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 i={uuid:this.uuid,url:""},n=this.data;if(n!==null){let s;if(Array.isArray(n)){s=[];for(let r=0,o=n.length;r<o;r++)n[r].isDataTexture?s.push(Td(n[r].image)):s.push(Td(n[r]))}else s=Td(n);i.url=s}return e||(t.images[this.uuid]=i),i}}function Td(a){return typeof HTMLImageElement<"u"&&a instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&a instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&a instanceof ImageBitmap?OS.getDataURL(a):a.data?{data:Array.from(a.data),width:a.width,height:a.height,type:a.data.constructor.name}:(Pt("Texture: Unable to serialize Texture."),{})}let NS=0;const Rd=new R;class Hi extends $r{constructor(t=Hi.DEFAULT_IMAGE,e=Hi.DEFAULT_MAPPING,i=Bi,n=Bi,s=de,r=Aa,o=Gi,c=Ln,l=Hi.DEFAULT_ANISOTROPY,h=Lr){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:NS++}),this.uuid=ds(),this.name="",this.source=new zp(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=r,this.anisotropy=l,this.format=o,this.internalFormat=null,this.type=c,this.offset=new bt(0,0),this.repeat=new bt(1,1),this.center=new bt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Jt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Rd).x}get height(){return this.source.getSize(Rd).y}get depth(){return this.source.getSize(Rd).z}get image(){return this.source.data}set image(t){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)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}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.normalized=t.normalized,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.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){Pt(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const n=this[e];if(n===void 0){Pt(`Texture.setValues(): property '${e}' does not exist.`);continue}n&&i&&n.isVector2&&i.isVector2||n&&i&&n.isVector3&&i.isVector3||n&&i&&n.isMatrix3&&i.isMatrix3?n.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,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,normalized:this.normalized,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&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==BM)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Qo:t.x=t.x-Math.floor(t.x);break;case Bi:t.x=t.x<0?0:1;break;case s0: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 Qo:t.y=t.y-Math.floor(t.y);break;case Bi:t.y=t.y<0?0:1;break;case s0: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++}}Hi.DEFAULT_IMAGE=null;Hi.DEFAULT_MAPPING=BM;Hi.DEFAULT_ANISOTROPY=1;class ue{static{ue.prototype.isVector4=!0}constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n}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,i,n){return this.x=t,this.y=e,this.z=i,this.w=n,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("THREE.Vector4: 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("THREE.Vector4: 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,i=this.y,n=this.z,s=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*n+r[12]*s,this.y=r[1]*e+r[5]*i+r[9]*n+r[13]*s,this.z=r[2]*e+r[6]*i+r[10]*n+r[14]*s,this.w=r[3]*e+r[7]*i+r[11]*n+r[15]*s,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,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,i,n,s;const c=t.elements,l=c[0],h=c[4],u=c[8],d=c[1],f=c[5],p=c[9],v=c[2],m=c[6],g=c[10];if(Math.abs(h-d)<.01&&Math.abs(u-v)<.01&&Math.abs(p-m)<.01){if(Math.abs(h+d)<.1&&Math.abs(u+v)<.1&&Math.abs(p+m)<.1&&Math.abs(l+f+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const S=(l+1)/2,M=(f+1)/2,x=(g+1)/2,_=(h+d)/4,E=(u+v)/4,y=(p+m)/4;return S>M&&S>x?S<.01?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(S),n=_/i,s=E/i):M>x?M<.01?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(M),i=_/n,s=y/n):x<.01?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(x),i=E/s,n=y/s),this.set(i,n,s,e),this}let b=Math.sqrt((m-p)*(m-p)+(u-v)*(u-v)+(d-h)*(d-h));return Math.abs(b)<.001&&(b=1),this.x=(m-p)/b,this.y=(u-v)/b,this.z=(d-h)/b,this.w=Math.acos((l+f+g-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=Qt(this.x,t.x,e.x),this.y=Qt(this.y,t.y,e.y),this.z=Qt(this.z,t.z,e.z),this.w=Qt(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=Qt(this.x,t,e),this.y=Qt(this.y,t,e),this.z=Qt(this.z,t,e),this.w=Qt(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qt(i,t,e))}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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,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 kS extends $r{constructor(t=1,e=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:de,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},i),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=i.depth,this.scissor=new ue(0,0,t,e),this.scissorTest=!1,this.viewport=new ue(0,0,t,e),this.textures=[];const n={width:t,height:e,depth:i.depth},s=new Hi(n),r=i.count;for(let o=0;o<r;o++)this.textures[o]=s.clone(),this.textures[o].isRenderTargetTexture=!0,this.textures[o].renderTarget=this;this._setTextureOptions(i),this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.resolveDepthBuffer=i.resolveDepthBuffer,this.resolveStencilBuffer=i.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=i.depthTexture,this.samples=i.samples,this.multiview=i.multiview,this.useArrayDepthTexture=i.useArrayDepthTexture}_setTextureOptions(t={}){const e={minFilter:de,generateMipmaps:!1,flipY:!1,internalFormat:null};t.mapping!==void 0&&(e.mapping=t.mapping),t.wrapS!==void 0&&(e.wrapS=t.wrapS),t.wrapT!==void 0&&(e.wrapT=t.wrapT),t.wrapR!==void 0&&(e.wrapR=t.wrapR),t.magFilter!==void 0&&(e.magFilter=t.magFilter),t.minFilter!==void 0&&(e.minFilter=t.minFilter),t.format!==void 0&&(e.format=t.format),t.type!==void 0&&(e.type=t.type),t.anisotropy!==void 0&&(e.anisotropy=t.anisotropy),t.colorSpace!==void 0&&(e.colorSpace=t.colorSpace),t.flipY!==void 0&&(e.flipY=t.flipY),t.generateMipmaps!==void 0&&(e.generateMipmaps=t.generateMipmaps),t.internalFormat!==void 0&&(e.internalFormat=t.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(e)}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}set depthTexture(t){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),t!==null&&(t.renderTarget=this),this._depthTexture=t}get depthTexture(){return this._depthTexture}setSize(t,e,i=1){if(this.width!==t||this.height!==e||this.depth!==i){this.width=t,this.height=e,this.depth=i;for(let n=0,s=this.textures.length;n<s;n++)this.textures[n].image.width=t,this.textures[n].image.height=e,this.textures[n].image.depth=i,this.textures[n].isData3DTexture!==!0&&(this.textures[n].isArrayTexture=this.textures[n].image.depth>1);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 e=0,i=t.textures.length;e<i;e++){this.textures[e]=t.textures[e].clone(),this.textures[e].isRenderTargetTexture=!0,this.textures[e].renderTarget=this;const n=Object.assign({},t.textures[e].image);this.textures[e].source=new zp(n)}return 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.multiview=t.multiview,this.useArrayDepthTexture=t.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class oi extends kS{constructor(t=1,e=1,i={}){super(t,e,i),this.isWebGLRenderTarget=!0}}class KM extends Hi{constructor(t=null,e=1,i=1,n=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:i,depth:n},this.magFilter=Ue,this.minFilter=Ue,this.wrapR=Bi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class ZM extends Hi{constructor(t=null,e=1,i=1,n=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:i,depth:n},this.magFilter=Ue,this.minFilter=Ue,this.wrapR=Bi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class ne{static{ne.prototype.isMatrix4=!0}constructor(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m){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,i,n,s,r,o,c,l,h,u,d,f,p,v,m)}set(t,e,i,n,s,r,o,c,l,h,u,d,f,p,v,m){const g=this.elements;return g[0]=t,g[4]=e,g[8]=i,g[12]=n,g[1]=s,g[5]=r,g[9]=o,g[13]=c,g[2]=l,g[6]=h,g[10]=u,g[14]=d,g[3]=f,g[7]=p,g[11]=v,g[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 ne().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[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,i){return this.determinantAffine()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();const e=this.elements,i=t.elements,n=1/eo.setFromMatrixColumn(t,0).length(),s=1/eo.setFromMatrixColumn(t,1).length(),r=1/eo.setFromMatrixColumn(t,2).length();return e[0]=i[0]*n,e[1]=i[1]*n,e[2]=i[2]*n,e[3]=0,e[4]=i[4]*s,e[5]=i[5]*s,e[6]=i[6]*s,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,n=t.y,s=t.z,r=Math.cos(i),o=Math.sin(i),c=Math.cos(n),l=Math.sin(n),h=Math.cos(s),u=Math.sin(s);if(t.order==="XYZ"){const d=r*h,f=r*u,p=o*h,v=o*u;e[0]=c*h,e[4]=-c*u,e[8]=l,e[1]=f+p*l,e[5]=d-v*l,e[9]=-o*c,e[2]=v-d*l,e[6]=p+f*l,e[10]=r*c}else if(t.order==="YXZ"){const d=c*h,f=c*u,p=l*h,v=l*u;e[0]=d+v*o,e[4]=p*o-f,e[8]=r*l,e[1]=r*u,e[5]=r*h,e[9]=-o,e[2]=f*o-p,e[6]=v+d*o,e[10]=r*c}else if(t.order==="ZXY"){const d=c*h,f=c*u,p=l*h,v=l*u;e[0]=d-v*o,e[4]=-r*u,e[8]=p+f*o,e[1]=f+p*o,e[5]=r*h,e[9]=v-d*o,e[2]=-r*l,e[6]=o,e[10]=r*c}else if(t.order==="ZYX"){const d=r*h,f=r*u,p=o*h,v=o*u;e[0]=c*h,e[4]=p*l-f,e[8]=d*l+v,e[1]=c*u,e[5]=v*l+d,e[9]=f*l-p,e[2]=-l,e[6]=o*c,e[10]=r*c}else if(t.order==="YZX"){const d=r*c,f=r*l,p=o*c,v=o*l;e[0]=c*h,e[4]=v-d*u,e[8]=p*u+f,e[1]=u,e[5]=r*h,e[9]=-o*h,e[2]=-l*h,e[6]=f*u+p,e[10]=d-v*u}else if(t.order==="XZY"){const d=r*c,f=r*l,p=o*c,v=o*l;e[0]=c*h,e[4]=-u,e[8]=l*h,e[1]=d*u+v,e[5]=r*h,e[9]=f*u-p,e[2]=p*u-f,e[6]=o*h,e[10]=v*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(FS,t,US)}lookAt(t,e,i){const n=this.elements;return En.subVectors(t,e),En.lengthSq()===0&&(En.z=1),En.normalize(),Mr.crossVectors(i,En),Mr.lengthSq()===0&&(Math.abs(i.z)===1?En.x+=1e-4:En.z+=1e-4,En.normalize(),Mr.crossVectors(i,En)),Mr.normalize(),Fl.crossVectors(En,Mr),n[0]=Mr.x,n[4]=Fl.x,n[8]=En.x,n[1]=Mr.y,n[5]=Fl.y,n[9]=En.y,n[2]=Mr.z,n[6]=Fl.z,n[10]=En.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],o=i[4],c=i[8],l=i[12],h=i[1],u=i[5],d=i[9],f=i[13],p=i[2],v=i[6],m=i[10],g=i[14],b=i[3],S=i[7],M=i[11],x=i[15],_=n[0],E=n[4],y=n[8],T=n[12],I=n[1],C=n[5],P=n[9],B=n[13],W=n[2],O=n[6],H=n[10],U=n[14],q=n[3],Q=n[7],J=n[11],it=n[15];return s[0]=r*_+o*I+c*W+l*q,s[4]=r*E+o*C+c*O+l*Q,s[8]=r*y+o*P+c*H+l*J,s[12]=r*T+o*B+c*U+l*it,s[1]=h*_+u*I+d*W+f*q,s[5]=h*E+u*C+d*O+f*Q,s[9]=h*y+u*P+d*H+f*J,s[13]=h*T+u*B+d*U+f*it,s[2]=p*_+v*I+m*W+g*q,s[6]=p*E+v*C+m*O+g*Q,s[10]=p*y+v*P+m*H+g*J,s[14]=p*T+v*B+m*U+g*it,s[3]=b*_+S*I+M*W+x*q,s[7]=b*E+S*C+M*O+x*Q,s[11]=b*y+S*P+M*H+x*J,s[15]=b*T+S*B+M*U+x*it,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],i=t[4],n=t[8],s=t[12],r=t[1],o=t[5],c=t[9],l=t[13],h=t[2],u=t[6],d=t[10],f=t[14],p=t[3],v=t[7],m=t[11],g=t[15],b=c*f-l*d,S=o*f-l*u,M=o*d-c*u,x=r*f-l*h,_=r*d-c*h,E=r*u-o*h;return e*(v*b-m*S+g*M)-i*(p*b-m*x+g*_)+n*(p*S-v*x+g*E)-s*(p*M-v*_+m*E)}determinantAffine(){const t=this.elements,e=t[0],i=t[4],n=t[8],s=t[1],r=t[5],o=t[9],c=t[2],l=t[6],h=t[10];return e*(r*h-o*l)-i*(s*h-o*c)+n*(s*l-r*c)}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,i){const n=this.elements;return t.isVector3?(n[12]=t.x,n[13]=t.y,n[14]=t.z):(n[12]=t,n[13]=e,n[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=t[9],d=t[10],f=t[11],p=t[12],v=t[13],m=t[14],g=t[15],b=e*o-i*r,S=e*c-n*r,M=e*l-s*r,x=i*c-n*o,_=i*l-s*o,E=n*l-s*c,y=h*v-u*p,T=h*m-d*p,I=h*g-f*p,C=u*m-d*v,P=u*g-f*v,B=d*g-f*m,W=b*B-S*P+M*C+x*I-_*T+E*y;if(W===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const O=1/W;return t[0]=(o*B-c*P+l*C)*O,t[1]=(n*P-i*B-s*C)*O,t[2]=(v*E-m*_+g*x)*O,t[3]=(d*_-u*E-f*x)*O,t[4]=(c*I-r*B-l*T)*O,t[5]=(e*B-n*I+s*T)*O,t[6]=(m*M-p*E-g*S)*O,t[7]=(h*E-d*M+f*S)*O,t[8]=(r*P-o*I+l*y)*O,t[9]=(i*I-e*P-s*y)*O,t[10]=(p*_-v*M+g*b)*O,t[11]=(u*M-h*_-f*b)*O,t[12]=(o*T-r*C-c*y)*O,t[13]=(e*C-i*T+n*y)*O,t[14]=(v*S-p*x-m*b)*O,t[15]=(h*x-u*S+d*b)*O,this}scale(t){const e=this.elements,i=t.x,n=t.y,s=t.z;return e[0]*=i,e[4]*=n,e[8]*=s,e[1]*=i,e[5]*=n,e[9]*=s,e[2]*=i,e[6]*=n,e[10]*=s,e[3]*=i,e[7]*=n,e[11]*=s,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],n=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,n))}makeTranslation(t,e,i){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,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),n=Math.sin(e),s=1-i,r=t.x,o=t.y,c=t.z,l=s*r,h=s*o;return this.set(l*r+i,l*o-n*c,l*c+n*o,0,l*o+n*c,h*o+i,h*c-n*r,0,l*c-n*o,h*c+n*r,s*c*c+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,n,s,r){return this.set(1,i,s,0,t,1,r,0,e,n,1,0,0,0,0,1),this}compose(t,e,i){const n=this.elements,s=e._x,r=e._y,o=e._z,c=e._w,l=s+s,h=r+r,u=o+o,d=s*l,f=s*h,p=s*u,v=r*h,m=r*u,g=o*u,b=c*l,S=c*h,M=c*u,x=i.x,_=i.y,E=i.z;return n[0]=(1-(v+g))*x,n[1]=(f+M)*x,n[2]=(p-S)*x,n[3]=0,n[4]=(f-M)*_,n[5]=(1-(d+g))*_,n[6]=(m+b)*_,n[7]=0,n[8]=(p+S)*E,n[9]=(m-b)*E,n[10]=(1-(d+v))*E,n[11]=0,n[12]=t.x,n[13]=t.y,n[14]=t.z,n[15]=1,this}decompose(t,e,i){const n=this.elements;t.x=n[12],t.y=n[13],t.z=n[14];const s=this.determinantAffine();if(s===0)return i.set(1,1,1),e.identity(),this;let r=eo.set(n[0],n[1],n[2]).length();const o=eo.set(n[4],n[5],n[6]).length(),c=eo.set(n[8],n[9],n[10]).length();s<0&&(r=-r),Jn.copy(this);const l=1/r,h=1/o,u=1/c;return Jn.elements[0]*=l,Jn.elements[1]*=l,Jn.elements[2]*=l,Jn.elements[4]*=h,Jn.elements[5]*=h,Jn.elements[6]*=h,Jn.elements[8]*=u,Jn.elements[9]*=u,Jn.elements[10]*=u,e.setFromRotationMatrix(Jn),i.x=r,i.y=o,i.z=c,this}makePerspective(t,e,i,n,s,r,o=Us,c=!1){const l=this.elements,h=2*s/(e-t),u=2*s/(i-n),d=(e+t)/(e-t),f=(i+n)/(i-n);let p,v;if(c)p=s/(r-s),v=r*s/(r-s);else if(o===Us)p=-(r+s)/(r-s),v=-2*r*s/(r-s);else if(o===ul)p=-r/(r-s),v=-r*s/(r-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return l[0]=h,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=u,l[9]=f,l[13]=0,l[2]=0,l[6]=0,l[10]=p,l[14]=v,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,i,n,s,r,o=Us,c=!1){const l=this.elements,h=2/(e-t),u=2/(i-n),d=-(e+t)/(e-t),f=-(i+n)/(i-n);let p,v;if(c)p=1/(r-s),v=r/(r-s);else if(o===Us)p=-2/(r-s),v=-(r+s)/(r-s);else if(o===ul)p=-1/(r-s),v=-s/(r-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return l[0]=h,l[4]=0,l[8]=0,l[12]=d,l[1]=0,l[5]=u,l[9]=0,l[13]=f,l[2]=0,l[6]=0,l[10]=p,l[14]=v,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let n=0;n<16;n++)if(e[n]!==i[n])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const eo=new R,Jn=new ne,FS=new R(0,0,0),US=new R(1,1,1),Mr=new R,Fl=new R,En=new R,Rg=new ne,Dg=new Sn;class hr{constructor(t=0,e=0,i=0,n=hr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=n}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,i,n=this._order){return this._x=t,this._y=e,this._z=i,this._order=n,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,i=!0){const n=t.elements,s=n[0],r=n[4],o=n[8],c=n[1],l=n[5],h=n[9],u=n[2],d=n[6],f=n[10];switch(e){case"XYZ":this._y=Math.asin(Qt(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Qt(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin(Qt(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Qt(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(Qt(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(o,f));break;case"XZY":this._z=Math.asin(-Qt(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:Pt("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return Rg.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Rg,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Dg.setFromEuler(this),this.setFromQuaternion(Dg,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}}hr.DEFAULT_ORDER="XYZ";class Bp{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 zS=0;const Ig=new R,io=new Sn,Ys=new ne,Ul=new R,uc=new R,BS=new R,HS=new Sn,Cg=new R(1,0,0),Pg=new R(0,1,0),Og=new R(0,0,1),Lg={type:"added"},GS={type:"removed"},no={type:"childadded",child:null},Dd={type:"childremoved",child:null};class ti extends $r{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:zS++}),this.uuid=ds(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=ti.DEFAULT_UP.clone();const t=new R,e=new hr,i=new Sn,n=new R(1,1,1);function s(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(s),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new ne},normalMatrix:{value:new Jt}}),this.matrix=new ne,this.matrixWorld=new ne,this.matrixAutoUpdate=ti.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=ti.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Bp,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}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 io.setFromAxisAngle(t,e),this.quaternion.multiply(io),this}rotateOnWorldAxis(t,e){return io.setFromAxisAngle(t,e),this.quaternion.premultiply(io),this}rotateX(t){return this.rotateOnAxis(Cg,t)}rotateY(t){return this.rotateOnAxis(Pg,t)}rotateZ(t){return this.rotateOnAxis(Og,t)}translateOnAxis(t,e){return Ig.copy(t).applyQuaternion(this.quaternion),this.position.add(Ig.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Cg,t)}translateY(t){return this.translateOnAxis(Pg,t)}translateZ(t){return this.translateOnAxis(Og,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Ys.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ul.copy(t):Ul.set(t,e,i);const n=this.parent;this.updateWorldMatrix(!0,!1),uc.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Ys.lookAt(uc,Ul,this.up):Ys.lookAt(Ul,uc,this.up),this.quaternion.setFromRotationMatrix(Ys),n&&(Ys.extractRotation(n.matrixWorld),io.setFromRotationMatrix(Ys),this.quaternion.premultiply(io.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(qt("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(Lg),no.child=t,this.dispatchEvent(no),no.child=null):qt("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(GS),Dd.child=t,this.dispatchEvent(Dd),Dd.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),Ys.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),Ys.multiply(t.parent.matrixWorld)),t.applyMatrix4(Ys),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Lg),no.child=t,this.dispatchEvent(no),no.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 i=0,n=this.children.length;i<n;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const n=this.children;for(let s=0,r=n.length;s<r;s++)n[s].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(uc,t,BS),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(uc,HS,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 i=0,n=e.length;i<n;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].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);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,n=t.z,s=this.matrix.elements;s[12]+=e-s[0]*e-s[4]*i-s[8]*n,s[13]+=i-s[1]*e-s[5]*i-s[9]*n,s[14]+=n-s[2]*e-s[6]*i-s[10]*n}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 i=0,n=e.length;i<n;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e,i=!1){const n=this.parent;if(t===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),e===!0){const s=this.children;for(let r=0,o=s.length;r<o;r++)s[r].updateWorldMatrix(!1,!0,i)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const n={};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.castShadow===!0&&(n.castShadow=!0),this.receiveShadow===!0&&(n.receiveShadow=!0),this.visible===!1&&(n.visible=!1),this.frustumCulled===!1&&(n.frustumCulled=!1),this.renderOrder!==0&&(n.renderOrder=this.renderOrder),this.static!==!1&&(n.static=this.static),Object.keys(this.userData).length>0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),this.pivot!==null&&(n.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(n.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(n.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(n.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(n.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(n.type="BatchedMesh",n.perObjectFrustumCulled=this.perObjectFrustumCulled,n.sortObjects=this.sortObjects,n.drawRanges=this._drawRanges,n.reservedRanges=this._reservedRanges,n.geometryInfo=this._geometryInfo.map(o=>({...o,boundingBox:o.boundingBox?o.boundingBox.toJSON():void 0,boundingSphere:o.boundingSphere?o.boundingSphere.toJSON():void 0})),n.instanceInfo=this._instanceInfo.map(o=>({...o})),n.availableInstanceIds=this._availableInstanceIds.slice(),n.availableGeometryIds=this._availableGeometryIds.slice(),n.nextIndexStart=this._nextIndexStart,n.nextVertexStart=this._nextVertexStart,n.geometryCount=this._geometryCount,n.maxInstanceCount=this._maxInstanceCount,n.maxVertexCount=this._maxVertexCount,n.maxIndexCount=this._maxIndexCount,n.geometryInitialized=this._geometryInitialized,n.matricesTexture=this._matricesTexture.toJSON(t),n.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(n.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(n.boundingBox=this.boundingBox.toJSON()));function s(o,c){return o[c.uuid]===void 0&&(o[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(t.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const c=o.shapes;if(Array.isArray(c))for(let l=0,h=c.length;l<h;l++){const u=c[l];s(t.shapes,u)}else s(t.shapes,c)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(t.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let c=0,l=this.material.length;c<l;c++)o.push(s(t.materials,this.material[c]));n.material=o}else n.material=s(t.materials,this.material);if(this.children.length>0){n.children=[];for(let o=0;o<this.children.length;o++)n.children.push(this.children[o].toJSON(t).object)}if(this.animations.length>0){n.animations=[];for(let o=0;o<this.animations.length;o++){const c=this.animations[o];n.animations.push(s(t.animations,c))}}if(e){const o=r(t.geometries),c=r(t.materials),l=r(t.textures),h=r(t.images),u=r(t.shapes),d=r(t.skeletons),f=r(t.animations),p=r(t.nodes);o.length>0&&(i.geometries=o),c.length>0&&(i.materials=c),l.length>0&&(i.textures=l),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),d.length>0&&(i.skeletons=d),f.length>0&&(i.animations=f),p.length>0&&(i.nodes=p)}return i.object=n,i;function r(o){const c=[];for(const l in o){const h=o[l];delete h.metadata,c.push(h)}return c}}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.pivot=t.pivot!==null?t.pivot.clone():null,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.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const n=t.children[i];this.add(n.clone())}return this}}ti.DEFAULT_UP=new R(0,1,0);ti.DEFAULT_MATRIX_AUTO_UPDATE=!0;ti.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Ee extends ti{constructor(){super(),this.isGroup=!0,this.type="Group"}}const VS={type:"move"};class Id{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Ee,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 Ee,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 Ee,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.eventsEnabled=!1),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 i of t.hand.values())this._getHandJoint(e,i)}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,i){let n=null,s=null,r=null;const o=this._targetRay,c=this._grip,l=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(l&&t.hand){r=!0;for(const v of t.hand.values()){const m=e.getJointPose(v,i),g=this._getHandJoint(l,v);m!==null&&(g.matrix.fromArray(m.transform.matrix),g.matrix.decompose(g.position,g.rotation,g.scale),g.matrixWorldNeedsUpdate=!0,g.jointRadius=m.radius),g.visible=m!==null}const h=l.joints["index-finger-tip"],u=l.joints["thumb-tip"],d=h.position.distanceTo(u.position),f=.02,p=.005;l.inputState.pinching&&d>f+p?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&d<=f-p&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else c!==null&&t.gripSpace&&(s=e.getPose(t.gripSpace,i),s!==null&&(c.matrix.fromArray(s.transform.matrix),c.matrix.decompose(c.position,c.rotation,c.scale),c.matrixWorldNeedsUpdate=!0,s.linearVelocity?(c.hasLinearVelocity=!0,c.linearVelocity.copy(s.linearVelocity)):c.hasLinearVelocity=!1,s.angularVelocity?(c.hasAngularVelocity=!0,c.angularVelocity.copy(s.angularVelocity)):c.hasAngularVelocity=!1,c.eventsEnabled&&c.dispatchEvent({type:"gripUpdated",data:t,target:this})));o!==null&&(n=e.getPose(t.targetRaySpace,i),n===null&&s!==null&&(n=s),n!==null&&(o.matrix.fromArray(n.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,n.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(n.linearVelocity)):o.hasLinearVelocity=!1,n.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(n.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(VS)))}return o!==null&&(o.visible=n!==null),c!==null&&(c.visible=s!==null),l!==null&&(l.visible=r!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){const i=new Ee;i.matrixAutoUpdate=!1,i.visible=!1,t.joints[e.jointName]=i,t.add(i)}return t.joints[e.jointName]}}const JM={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},yr={h:0,s:0,l:0},zl={h:0,s:0,l:0};function Cd(a,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+(t-a)*6*e:e<1/2?t:e<2/3?a+(t-a)*6*(2/3-e):a}class st{constructor(t,e,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,i)}set(t,e,i){if(e===void 0&&i===void 0){const n=t;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(t,e,i);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=un){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,me.colorSpaceToWorking(this,e),this}setRGB(t,e,i,n=me.workingColorSpace){return this.r=t,this.g=e,this.b=i,me.colorSpaceToWorking(this,n),this}setHSL(t,e,i,n=me.workingColorSpace){if(t=Up(t,1),e=Qt(e,0,1),i=Qt(i,0,1),e===0)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+e):i+e-i*e,r=2*i-s;this.r=Cd(r,s,t+1/3),this.g=Cd(r,s,t),this.b=Cd(r,s,t-1/3)}return me.colorSpaceToWorking(this,n),this}setStyle(t,e=un){function i(s){s!==void 0&&parseFloat(s)<1&&Pt("Color: Alpha component of "+t+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(t)){let s;const r=n[1],o=n[2];switch(r){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,e);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,e);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,e);break;default:Pt("Color: Unknown color model "+t)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=n[1],r=s.length;if(r===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(r===6)return this.setHex(parseInt(s,16),e);Pt("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=un){const i=JM[t.toLowerCase()];return i!==void 0?this.setHex(i,e):Pt("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=or(t.r),this.g=or(t.g),this.b=or(t.b),this}copyLinearToSRGB(t){return this.r=zo(t.r),this.g=zo(t.g),this.b=zo(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=un){return me.workingToColorSpace(Yi.copy(this),t),Math.round(Qt(Yi.r*255,0,255))*65536+Math.round(Qt(Yi.g*255,0,255))*256+Math.round(Qt(Yi.b*255,0,255))}getHexString(t=un){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=me.workingColorSpace){me.workingToColorSpace(Yi.copy(this),e);const i=Yi.r,n=Yi.g,s=Yi.b,r=Math.max(i,n,s),o=Math.min(i,n,s);let c,l;const h=(o+r)/2;if(o===r)c=0,l=0;else{const u=r-o;switch(l=h<=.5?u/(r+o):u/(2-r-o),r){case i:c=(n-s)/u+(n<s?6:0);break;case n:c=(s-i)/u+2;break;case s:c=(i-n)/u+4;break}c/=6}return t.h=c,t.s=l,t.l=h,t}getRGB(t,e=me.workingColorSpace){return me.workingToColorSpace(Yi.copy(this),e),t.r=Yi.r,t.g=Yi.g,t.b=Yi.b,t}getStyle(t=un){me.workingToColorSpace(Yi.copy(this),t);const e=Yi.r,i=Yi.g,n=Yi.b;return t!==un?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(i*255)},${Math.round(n*255)})`}offsetHSL(t,e,i){return this.getHSL(yr),this.setHSL(yr.h+t,yr.s+e,yr.l+i)}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,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(yr),t.getHSL(zl);const i=qc(yr.h,zl.h,e),n=qc(yr.s,zl.s,e),s=qc(yr.l,zl.l,e);return this.setHSL(i,n,s),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,i=this.g,n=this.b,s=t.elements;return this.r=s[0]*e+s[3]*i+s[6]*n,this.g=s[1]*e+s[4]*i+s[7]*n,this.b=s[2]*e+s[5]*i+s[8]*n,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 Yi=new st;st.NAMES=JM;class Hp{constructor(t,e=1,i=1e3){this.isFog=!0,this.name="",this.color=new st(t),this.near=e,this.far=i}clone(){return new Hp(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class Gs extends ti{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 hr,this.environmentIntensity=1,this.environmentRotation=new hr,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}}const jn=new R,qs=new R,Pd=new R,$s=new R,so=new R,ro=new R,Ng=new R,Od=new R,Ld=new R,Nd=new R,kd=new ue,Fd=new ue,Ud=new ue;class qn{constructor(t=new R,e=new R,i=new R){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,n){n.subVectors(i,e),jn.subVectors(t,e),n.cross(jn);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(t,e,i,n,s){jn.subVectors(n,e),qs.subVectors(i,e),Pd.subVectors(t,e);const r=jn.dot(jn),o=jn.dot(qs),c=jn.dot(Pd),l=qs.dot(qs),h=qs.dot(Pd),u=r*l-o*o;if(u===0)return s.set(0,0,0),null;const d=1/u,f=(l*c-o*h)*d,p=(r*h-o*c)*d;return s.set(1-f-p,p,f)}static containsPoint(t,e,i,n){return this.getBarycoord(t,e,i,n,$s)===null?!1:$s.x>=0&&$s.y>=0&&$s.x+$s.y<=1}static getInterpolation(t,e,i,n,s,r,o,c){return this.getBarycoord(t,e,i,n,$s)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(s,$s.x),c.addScaledVector(r,$s.y),c.addScaledVector(o,$s.z),c)}static getInterpolatedAttribute(t,e,i,n,s,r){return kd.setScalar(0),Fd.setScalar(0),Ud.setScalar(0),kd.fromBufferAttribute(t,e),Fd.fromBufferAttribute(t,i),Ud.fromBufferAttribute(t,n),r.setScalar(0),r.addScaledVector(kd,s.x),r.addScaledVector(Fd,s.y),r.addScaledVector(Ud,s.z),r}static isFrontFacing(t,e,i,n){return jn.subVectors(i,e),qs.subVectors(t,e),jn.cross(qs).dot(n)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,n){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[n]),this}setFromAttributeAndIndices(t,e,i,n){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,n),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 jn.subVectors(this.c,this.b),qs.subVectors(this.a,this.b),jn.cross(qs).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return qn.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return qn.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,n,s){return qn.getInterpolation(t,this.a,this.b,this.c,e,i,n,s)}containsPoint(t){return qn.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return qn.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,n=this.b,s=this.c;let r,o;so.subVectors(n,i),ro.subVectors(s,i),Od.subVectors(t,i);const c=so.dot(Od),l=ro.dot(Od);if(c<=0&&l<=0)return e.copy(i);Ld.subVectors(t,n);const h=so.dot(Ld),u=ro.dot(Ld);if(h>=0&&u<=h)return e.copy(n);const d=c*u-h*l;if(d<=0&&c>=0&&h<=0)return r=c/(c-h),e.copy(i).addScaledVector(so,r);Nd.subVectors(t,s);const f=so.dot(Nd),p=ro.dot(Nd);if(p>=0&&f<=p)return e.copy(s);const v=f*l-c*p;if(v<=0&&l>=0&&p<=0)return o=l/(l-p),e.copy(i).addScaledVector(ro,o);const m=h*p-f*u;if(m<=0&&u-h>=0&&f-p>=0)return Ng.subVectors(s,n),o=(u-h)/(u-h+(f-p)),e.copy(n).addScaledVector(Ng,o);const g=1/(m+v+d);return r=v*g,o=d*g,e.copy(i).addScaledVector(so,r).addScaledVector(ro,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class Qi{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,i=t.length;e<i;e+=3)this.expandByPoint(Qn.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(Qn.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=Qn.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),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 i=t.geometry;if(i!==void 0){const s=i.getAttribute("position");if(e===!0&&s!==void 0&&t.isInstancedMesh!==!0)for(let r=0,o=s.count;r<o;r++)t.isMesh===!0?t.getVertexPosition(r,Qn):Qn.fromBufferAttribute(s,r),Qn.applyMatrix4(t.matrixWorld),this.expandByPoint(Qn);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Bl.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Bl.copy(i.boundingBox)),Bl.applyMatrix4(t.matrixWorld),this.union(Bl)}const n=t.children;for(let s=0,r=n.length;s<r;s++)this.expandByObject(n[s],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,Qn),Qn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(dc),Hl.subVectors(this.max,dc),ao.subVectors(t.a,dc),oo.subVectors(t.b,dc),co.subVectors(t.c,dc),xr.subVectors(oo,ao),br.subVectors(co,oo),Jr.subVectors(ao,co);let e=[0,-xr.z,xr.y,0,-br.z,br.y,0,-Jr.z,Jr.y,xr.z,0,-xr.x,br.z,0,-br.x,Jr.z,0,-Jr.x,-xr.y,xr.x,0,-br.y,br.x,0,-Jr.y,Jr.x,0];return!zd(e,ao,oo,co,Hl)||(e=[1,0,0,0,1,0,0,0,1],!zd(e,ao,oo,co,Hl))?!1:(Gl.crossVectors(xr,br),e=[Gl.x,Gl.y,Gl.z],zd(e,ao,oo,co,Hl))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Qn).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(Qn).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:(Ks[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ks[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ks[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ks[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ks[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ks[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ks[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ks[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ks),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)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const Ks=[new R,new R,new R,new R,new R,new R,new R,new R],Qn=new R,Bl=new Qi,ao=new R,oo=new R,co=new R,xr=new R,br=new R,Jr=new R,dc=new R,Hl=new R,Gl=new R,jr=new R;function zd(a,t,e,i,n){for(let s=0,r=a.length-3;s<=r;s+=3){jr.fromArray(a,s);const o=n.x*Math.abs(jr.x)+n.y*Math.abs(jr.y)+n.z*Math.abs(jr.z),c=t.dot(jr),l=e.dot(jr),h=i.dot(jr);if(Math.max(-Math.max(c,l,h),Math.min(c,l,h))>o)return!1}return!0}const sr=WS();function WS(){const a=new ArrayBuffer(4),t=new Float32Array(a),e=new Uint32Array(a),i=new Uint32Array(512),n=new Uint32Array(512);for(let c=0;c<256;++c){const l=c-127;l<-27?(i[c]=0,i[c|256]=32768,n[c]=24,n[c|256]=24):l<-14?(i[c]=1024>>-l-14,i[c|256]=1024>>-l-14|32768,n[c]=-l-1,n[c|256]=-l-1):l<=15?(i[c]=l+15<<10,i[c|256]=l+15<<10|32768,n[c]=13,n[c|256]=13):l<128?(i[c]=31744,i[c|256]=64512,n[c]=24,n[c|256]=24):(i[c]=31744,i[c|256]=64512,n[c]=13,n[c|256]=13)}const s=new Uint32Array(2048),r=new Uint32Array(64),o=new Uint32Array(64);for(let c=1;c<1024;++c){let l=c<<13,h=0;for(;(l&8388608)===0;)l<<=1,h-=8388608;l&=-8388609,h+=947912704,s[c]=l|h}for(let c=1024;c<2048;++c)s[c]=939524096+(c-1024<<13);for(let c=1;c<31;++c)r[c]=c<<23;r[31]=1199570944,r[32]=2147483648;for(let c=33;c<63;++c)r[c]=2147483648+(c-32<<23);r[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(o[c]=1024);return{floatView:t,uint32View:e,baseTable:i,shiftTable:n,mantissaTable:s,exponentTable:r,offsetTable:o}}function XS(a){Math.abs(a)>65504&&Pt("DataUtils.toHalfFloat(): Value out of range."),a=Qt(a,-65504,65504),sr.floatView[0]=a;const t=sr.uint32View[0],e=t>>23&511;return sr.baseTable[e]+((t&8388607)>>sr.shiftTable[e])}function YS(a){const t=a>>10;return sr.uint32View[0]=sr.mantissaTable[sr.offsetTable[t]+(a&1023)]+sr.exponentTable[t],sr.floatView[0]}class kn{static toHalfFloat(t){return XS(t)}static fromHalfFloat(t){return YS(t)}}const _i=new R,Vl=new bt;let qS=0;class te extends $r{constructor(t,e,i=!1){if(super(),Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:qS++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=k0,this.updateRanges=[],this.gpuType=ji,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,i){t*=this.itemSize,i*=e.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[t+n]=e.array[i+n];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)Vl.fromBufferAttribute(this,e),Vl.applyMatrix3(t),this.setXY(e,Vl.x,Vl.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)_i.fromBufferAttribute(this,e),_i.applyMatrix3(t),this.setXYZ(e,_i.x,_i.y,_i.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)_i.fromBufferAttribute(this,e),_i.applyMatrix4(t),this.setXYZ(e,_i.x,_i.y,_i.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)_i.fromBufferAttribute(this,e),_i.applyNormalMatrix(t),this.setXYZ(e,_i.x,_i.y,_i.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)_i.fromBufferAttribute(this,e),_i.transformDirection(t),this.setXYZ(e,_i.x,_i.y,_i.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=hs(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=Oe(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=hs(e,this.array)),e}setX(t,e){return this.normalized&&(e=Oe(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=hs(e,this.array)),e}setY(t,e){return this.normalized&&(e=Oe(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=hs(e,this.array)),e}setZ(t,e){return this.normalized&&(e=Oe(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=hs(e,this.array)),e}setW(t,e){return this.normalized&&(e=Oe(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,n){return t*=this.itemSize,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array),n=Oe(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t*=this.itemSize,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array),n=Oe(n,this.array),s=Oe(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this.array[t+3]=s,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!==k0&&(t.usage=this.usage),t}dispose(){this.dispatchEvent({type:"dispose"})}}class jM extends te{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class Gp extends te{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class ve extends te{constructor(t,e,i){super(new Float32Array(t),e,i)}}const $S=new Qi,fc=new R,Bd=new R;class dr{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 i=this.center;e!==void 0?i.copy(e):$S.setFromPoints(t).getCenter(i);let n=0;for(let s=0,r=t.length;s<r;s++)n=Math.max(n,i.distanceToSquared(t[s]));return this.radius=Math.sqrt(n),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 i=this.center.distanceToSquared(t);return e.copy(t),i>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;fc.subVectors(t,this.center);const e=fc.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),n=(i-this.radius)*.5;this.center.addScaledVector(fc,n/i),this.radius+=n}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):(Bd.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(fc.copy(t.center).add(Bd)),this.expandByPoint(fc.copy(t.center).sub(Bd))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let KS=0;const zn=new ne,Hd=new ti,lo=new R,An=new Qi,pc=new Qi,Ni=new R;class ae extends $r{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:KS++}),this.uuid=ds(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(uS(t)?Gp:jM)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}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,i=0){this.groups.push({start:t,count:e,materialIndex:i})}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 i=this.attributes.normal;if(i!==void 0){const s=new Jt().getNormalMatrix(t);i.applyNormalMatrix(s),i.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(t),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return zn.makeRotationFromQuaternion(t),this.applyMatrix4(zn),this}rotateX(t){return zn.makeRotationX(t),this.applyMatrix4(zn),this}rotateY(t){return zn.makeRotationY(t),this.applyMatrix4(zn),this}rotateZ(t){return zn.makeRotationZ(t),this.applyMatrix4(zn),this}translate(t,e,i){return zn.makeTranslation(t,e,i),this.applyMatrix4(zn),this}scale(t,e,i){return zn.makeScale(t,e,i),this.applyMatrix4(zn),this}lookAt(t){return Hd.lookAt(t),Hd.updateMatrix(),this.applyMatrix4(Hd.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(lo).negate(),this.translate(lo.x,lo.y,lo.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let n=0,s=t.length;n<s;n++){const r=t[n];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new ve(i,3))}else{const i=Math.min(t.length,e.count);for(let n=0;n<i;n++){const s=t[n];e.setXYZ(n,s.x,s.y,s.z||0)}t.length>e.count&&Pt("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Qi);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){qt("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 i=0,n=e.length;i<n;i++){const s=e[i];An.setFromBufferAttribute(s),this.morphTargetsRelative?(Ni.addVectors(this.boundingBox.min,An.min),this.boundingBox.expandByPoint(Ni),Ni.addVectors(this.boundingBox.max,An.max),this.boundingBox.expandByPoint(Ni)):(this.boundingBox.expandByPoint(An.min),this.boundingBox.expandByPoint(An.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&qt('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 dr);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){qt("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(t){const i=this.boundingSphere.center;if(An.setFromBufferAttribute(t),e)for(let s=0,r=e.length;s<r;s++){const o=e[s];pc.setFromBufferAttribute(o),this.morphTargetsRelative?(Ni.addVectors(An.min,pc.min),An.expandByPoint(Ni),Ni.addVectors(An.max,pc.max),An.expandByPoint(Ni)):(An.expandByPoint(pc.min),An.expandByPoint(pc.max))}An.getCenter(i);let n=0;for(let s=0,r=t.count;s<r;s++)Ni.fromBufferAttribute(t,s),n=Math.max(n,i.distanceToSquared(Ni));if(e)for(let s=0,r=e.length;s<r;s++){const o=e[s],c=this.morphTargetsRelative;for(let l=0,h=o.count;l<h;l++)Ni.fromBufferAttribute(o,l),c&&(lo.fromBufferAttribute(t,l),Ni.add(lo)),n=Math.max(n,i.distanceToSquared(Ni))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&qt('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){qt("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,n=e.normal,s=e.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new te(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const o=[],c=[];for(let y=0;y<i.count;y++)o[y]=new R,c[y]=new R;const l=new R,h=new R,u=new R,d=new bt,f=new bt,p=new bt,v=new R,m=new R;function g(y,T,I){l.fromBufferAttribute(i,y),h.fromBufferAttribute(i,T),u.fromBufferAttribute(i,I),d.fromBufferAttribute(s,y),f.fromBufferAttribute(s,T),p.fromBufferAttribute(s,I),h.sub(l),u.sub(l),f.sub(d),p.sub(d);const C=1/(f.x*p.y-p.x*f.y);isFinite(C)&&(v.copy(h).multiplyScalar(p.y).addScaledVector(u,-f.y).multiplyScalar(C),m.copy(u).multiplyScalar(f.x).addScaledVector(h,-p.x).multiplyScalar(C),o[y].add(v),o[T].add(v),o[I].add(v),c[y].add(m),c[T].add(m),c[I].add(m))}let b=this.groups;b.length===0&&(b=[{start:0,count:t.count}]);for(let y=0,T=b.length;y<T;++y){const I=b[y],C=I.start,P=I.count;for(let B=C,W=C+P;B<W;B+=3)g(t.getX(B+0),t.getX(B+1),t.getX(B+2))}const S=new R,M=new R,x=new R,_=new R;function E(y){x.fromBufferAttribute(n,y),_.copy(x);const T=o[y];S.copy(T),S.sub(x.multiplyScalar(x.dot(T))).normalize(),M.crossVectors(_,T);const C=M.dot(c[y])<0?-1:1;r.setXYZW(y,S.x,S.y,S.z,C)}for(let y=0,T=b.length;y<T;++y){const I=b[y],C=I.start,P=I.count;for(let B=C,W=C+P;B<W;B+=3)E(t.getX(B+0)),E(t.getX(B+1)),E(t.getX(B+2))}this._transformed=!0}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==e.count)i=new te(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let d=0,f=i.count;d<f;d++)i.setXYZ(d,0,0,0);const n=new R,s=new R,r=new R,o=new R,c=new R,l=new R,h=new R,u=new R;if(t)for(let d=0,f=t.count;d<f;d+=3){const p=t.getX(d+0),v=t.getX(d+1),m=t.getX(d+2);n.fromBufferAttribute(e,p),s.fromBufferAttribute(e,v),r.fromBufferAttribute(e,m),h.subVectors(r,s),u.subVectors(n,s),h.cross(u),o.fromBufferAttribute(i,p),c.fromBufferAttribute(i,v),l.fromBufferAttribute(i,m),o.add(h),c.add(h),l.add(h),i.setXYZ(p,o.x,o.y,o.z),i.setXYZ(v,c.x,c.y,c.z),i.setXYZ(m,l.x,l.y,l.z)}else for(let d=0,f=e.count;d<f;d+=3)n.fromBufferAttribute(e,d+0),s.fromBufferAttribute(e,d+1),r.fromBufferAttribute(e,d+2),h.subVectors(r,s),u.subVectors(n,s),h.cross(u),i.setXYZ(d+0,h.x,h.y,h.z),i.setXYZ(d+1,h.x,h.y,h.z),i.setXYZ(d+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)Ni.fromBufferAttribute(t,e),Ni.normalize(),t.setXYZ(e,Ni.x,Ni.y,Ni.z)}toNonIndexed(){function t(o,c){const l=o.array,h=o.itemSize,u=o.normalized,d=new l.constructor(c.length*h);let f=0,p=0;for(let v=0,m=c.length;v<m;v++){o.isInterleavedBufferAttribute?f=c[v]*o.data.stride+o.offset:f=c[v]*h;for(let g=0;g<h;g++)d[p++]=l[f++]}return new te(d,h,u)}if(this.index===null)return Pt("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new ae,i=this.index.array,n=this.attributes;for(const o in n){const c=n[o],l=t(c,i);e.setAttribute(o,l)}const s=this.morphAttributes;for(const o in s){const c=[],l=s[o];for(let h=0,u=l.length;h<u;h++){const d=l[h],f=t(d,i);c.push(f)}e.morphAttributes[o]=c}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let o=0,c=r.length;o<c;o++){const l=r[o];e.addGroup(l.start,l.count,l.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const c=this.parameters;for(const l in c)c[l]!==void 0&&(t[l]=c[l]);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 i=this.attributes;for(const c in i){const l=i[c];t.data.attributes[c]=l.toJSON(t.data)}const n={};let s=!1;for(const c in this.morphAttributes){const l=this.morphAttributes[c],h=[];for(let u=0,d=l.length;u<d;u++){const f=l[u];h.push(f.toJSON(t.data))}h.length>0&&(n[c]=h,s=!0)}s&&(t.data.morphAttributes=n,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const o=this.boundingSphere;return o!==null&&(t.data.boundingSphere=o.toJSON()),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 i=t.index;i!==null&&this.setIndex(i.clone());const n=t.attributes;for(const l in n){const h=n[l];this.setAttribute(l,h.clone(e))}const s=t.morphAttributes;for(const l in s){const h=[],u=s[l];for(let d=0,f=u.length;d<f;d++)h.push(u[d].clone(e));this.morphAttributes[l]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let l=0,h=r.length;l<h;l++){const u=r[l];this.addGroup(u.start,u.count,u.materialIndex)}const o=t.boundingBox;o!==null&&(this.boundingBox=o.clone());const c=t.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this._transformed=t._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class QM{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=k0,this.updateRanges=[],this.version=0,this.uuid=ds()}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.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,i){t*=this.stride,i*=e.stride;for(let n=0,s=this.stride;n<s;n++)this.array[t+n]=e.array[i+n];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=ds()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(e,this.stride);return i.setUsage(this.usage),i}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=ds()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const tn=new R;class Iu{constructor(t,e,i,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=i,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,i=this.data.count;e<i;e++)tn.fromBufferAttribute(this,e),tn.applyMatrix4(t),this.setXYZ(e,tn.x,tn.y,tn.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)tn.fromBufferAttribute(this,e),tn.applyNormalMatrix(t),this.setXYZ(e,tn.x,tn.y,tn.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)tn.fromBufferAttribute(this,e),tn.transformDirection(t),this.setXYZ(e,tn.x,tn.y,tn.z);return this}getComponent(t,e){let i=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(i=hs(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=Oe(i,this.array)),this.data.array[t*this.data.stride+this.offset+e]=i,this}setX(t,e){return this.normalized&&(e=Oe(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=Oe(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=Oe(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=Oe(e,this.array)),this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){let e=this.data.array[t*this.data.stride+this.offset];return this.normalized&&(e=hs(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=hs(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=hs(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=hs(e,this.array)),e}setXY(t,e,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this}setXYZ(t,e,i,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array),n=Oe(n,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=Oe(e,this.array),i=Oe(i,this.array),n=Oe(n,this.array),s=Oe(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this.data.array[t+3]=s,this}clone(t){if(t===void 0){Du("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)e.push(this.data.array[n+s])}return new te(new this.array.constructor(e),this.itemSize,this.normalized)}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new Iu(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(t===void 0){Du("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const n=i*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)e.push(this.data.array[n+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let ZS=0;class fr extends $r{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:ZS++}),this.uuid=ds(),this.name="",this.type="Material",this.blending=Vr,this.side=Xr,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Zf,this.blendDst=cl,this.blendEquation=ha,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new st(0,0,0),this.blendAlpha=0,this.depthFunc=Jo,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=Sg,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Qa,this.stencilZFail=Qa,this.stencilZPass=Qa,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.allowOverride=!0,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 i=t[e];if(i===void 0){Pt(`Material: parameter '${e}' has value of undefined.`);continue}const n=this[e];if(n===void 0){Pt(`Material: '${e}' is not a property of THREE.${this.type}.`);continue}n&&n.isColor?n.set(i):n&&n.isVector2&&i&&i.isVector2||n&&n.isEuler&&i&&i.isEuler||n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const i={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),this.roughness!==void 0&&(i.roughness=this.roughness),this.metalness!==void 0&&(i.metalness=this.metalness),this.sheen!==void 0&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(i.shininess=this.shininess),this.clearcoat!==void 0&&(i.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).uuid),this.dispersion!==void 0&&(i.dispersion=this.dispersion),this.iridescence!==void 0&&(i.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(i.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(i.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(i.combine=this.combine)),this.envMapRotation!==void 0&&(i.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(i.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(i.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(i.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(i.size=this.size),this.shadowSide!==null&&(i.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==Vr&&(i.blending=this.blending),this.side!==Xr&&(i.side=this.side),this.vertexColors===!0&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.transparent===!0&&(i.transparent=!0),this.blendSrc!==Zf&&(i.blendSrc=this.blendSrc),this.blendDst!==cl&&(i.blendDst=this.blendDst),this.blendEquation!==ha&&(i.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(i.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(i.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(i.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(i.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(i.blendAlpha=this.blendAlpha),this.depthFunc!==Jo&&(i.depthFunc=this.depthFunc),this.depthTest===!1&&(i.depthTest=this.depthTest),this.depthWrite===!1&&(i.depthWrite=this.depthWrite),this.colorWrite===!1&&(i.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(i.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==Sg&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Qa&&(i.stencilFail=this.stencilFail),this.stencilZFail!==Qa&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==Qa&&(i.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(i.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(i.rotation=this.rotation),this.polygonOffset===!0&&(i.polygonOffset=!0),this.polygonOffsetFactor!==0&&(i.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(i.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(i.linewidth=this.linewidth),this.dashSize!==void 0&&(i.dashSize=this.dashSize),this.gapSize!==void 0&&(i.gapSize=this.gapSize),this.scale!==void 0&&(i.scale=this.scale),this.dithering===!0&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),this.alphaHash===!0&&(i.alphaHash=!0),this.alphaToCoverage===!0&&(i.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(i.premultipliedAlpha=!0),this.forceSinglePass===!0&&(i.forceSinglePass=!0),this.allowOverride===!1&&(i.allowOverride=!1),this.wireframe===!0&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(i.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(i.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(i.flatShading=!0),this.visible===!1&&(i.visible=!1),this.toneMapped===!1&&(i.toneMapped=!1),this.fog===!1&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData);function n(s){const r=[];for(const o in s){const c=s[o];delete c.metadata,r.push(c)}return r}if(e){const s=n(t.textures),r=n(t.images);s.length>0&&(i.textures=s),r.length>0&&(i.images=r)}return i}fromJSON(t,e){if(t.uuid!==void 0&&(this.uuid=t.uuid),t.name!==void 0&&(this.name=t.name),t.color!==void 0&&this.color!==void 0&&this.color.setHex(t.color),t.roughness!==void 0&&(this.roughness=t.roughness),t.metalness!==void 0&&(this.metalness=t.metalness),t.sheen!==void 0&&(this.sheen=t.sheen),t.sheenColor!==void 0&&(this.sheenColor=new st().setHex(t.sheenColor)),t.sheenRoughness!==void 0&&(this.sheenRoughness=t.sheenRoughness),t.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(t.emissive),t.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(t.specular),t.specularIntensity!==void 0&&(this.specularIntensity=t.specularIntensity),t.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(t.specularColor),t.shininess!==void 0&&(this.shininess=t.shininess),t.clearcoat!==void 0&&(this.clearcoat=t.clearcoat),t.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=t.clearcoatRoughness),t.dispersion!==void 0&&(this.dispersion=t.dispersion),t.iridescence!==void 0&&(this.iridescence=t.iridescence),t.iridescenceIOR!==void 0&&(this.iridescenceIOR=t.iridescenceIOR),t.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=t.iridescenceThicknessRange),t.transmission!==void 0&&(this.transmission=t.transmission),t.thickness!==void 0&&(this.thickness=t.thickness),t.attenuationDistance!==void 0&&(this.attenuationDistance=t.attenuationDistance),t.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(t.attenuationColor),t.anisotropy!==void 0&&(this.anisotropy=t.anisotropy),t.anisotropyRotation!==void 0&&(this.anisotropyRotation=t.anisotropyRotation),t.fog!==void 0&&(this.fog=t.fog),t.flatShading!==void 0&&(this.flatShading=t.flatShading),t.blending!==void 0&&(this.blending=t.blending),t.combine!==void 0&&(this.combine=t.combine),t.side!==void 0&&(this.side=t.side),t.shadowSide!==void 0&&(this.shadowSide=t.shadowSide),t.opacity!==void 0&&(this.opacity=t.opacity),t.transparent!==void 0&&(this.transparent=t.transparent),t.alphaTest!==void 0&&(this.alphaTest=t.alphaTest),t.alphaHash!==void 0&&(this.alphaHash=t.alphaHash),t.depthFunc!==void 0&&(this.depthFunc=t.depthFunc),t.depthTest!==void 0&&(this.depthTest=t.depthTest),t.depthWrite!==void 0&&(this.depthWrite=t.depthWrite),t.colorWrite!==void 0&&(this.colorWrite=t.colorWrite),t.blendSrc!==void 0&&(this.blendSrc=t.blendSrc),t.blendDst!==void 0&&(this.blendDst=t.blendDst),t.blendEquation!==void 0&&(this.blendEquation=t.blendEquation),t.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=t.blendSrcAlpha),t.blendDstAlpha!==void 0&&(this.blendDstAlpha=t.blendDstAlpha),t.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=t.blendEquationAlpha),t.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(t.blendColor),t.blendAlpha!==void 0&&(this.blendAlpha=t.blendAlpha),t.stencilWriteMask!==void 0&&(this.stencilWriteMask=t.stencilWriteMask),t.stencilFunc!==void 0&&(this.stencilFunc=t.stencilFunc),t.stencilRef!==void 0&&(this.stencilRef=t.stencilRef),t.stencilFuncMask!==void 0&&(this.stencilFuncMask=t.stencilFuncMask),t.stencilFail!==void 0&&(this.stencilFail=t.stencilFail),t.stencilZFail!==void 0&&(this.stencilZFail=t.stencilZFail),t.stencilZPass!==void 0&&(this.stencilZPass=t.stencilZPass),t.stencilWrite!==void 0&&(this.stencilWrite=t.stencilWrite),t.wireframe!==void 0&&(this.wireframe=t.wireframe),t.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=t.wireframeLinewidth),t.wireframeLinecap!==void 0&&(this.wireframeLinecap=t.wireframeLinecap),t.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=t.wireframeLinejoin),t.rotation!==void 0&&(this.rotation=t.rotation),t.linewidth!==void 0&&(this.linewidth=t.linewidth),t.dashSize!==void 0&&(this.dashSize=t.dashSize),t.gapSize!==void 0&&(this.gapSize=t.gapSize),t.scale!==void 0&&(this.scale=t.scale),t.polygonOffset!==void 0&&(this.polygonOffset=t.polygonOffset),t.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=t.polygonOffsetFactor),t.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=t.polygonOffsetUnits),t.dithering!==void 0&&(this.dithering=t.dithering),t.alphaToCoverage!==void 0&&(this.alphaToCoverage=t.alphaToCoverage),t.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=t.premultipliedAlpha),t.forceSinglePass!==void 0&&(this.forceSinglePass=t.forceSinglePass),t.allowOverride!==void 0&&(this.allowOverride=t.allowOverride),t.visible!==void 0&&(this.visible=t.visible),t.toneMapped!==void 0&&(this.toneMapped=t.toneMapped),t.userData!==void 0&&(this.userData=t.userData),t.vertexColors!==void 0&&(typeof t.vertexColors=="number"?this.vertexColors=t.vertexColors>0:this.vertexColors=t.vertexColors),t.size!==void 0&&(this.size=t.size),t.sizeAttenuation!==void 0&&(this.sizeAttenuation=t.sizeAttenuation),t.map!==void 0&&(this.map=e[t.map]||null),t.matcap!==void 0&&(this.matcap=e[t.matcap]||null),t.alphaMap!==void 0&&(this.alphaMap=e[t.alphaMap]||null),t.bumpMap!==void 0&&(this.bumpMap=e[t.bumpMap]||null),t.bumpScale!==void 0&&(this.bumpScale=t.bumpScale),t.normalMap!==void 0&&(this.normalMap=e[t.normalMap]||null),t.normalMapType!==void 0&&(this.normalMapType=t.normalMapType),t.normalScale!==void 0){let i=t.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new bt().fromArray(i)}return t.displacementMap!==void 0&&(this.displacementMap=e[t.displacementMap]||null),t.displacementScale!==void 0&&(this.displacementScale=t.displacementScale),t.displacementBias!==void 0&&(this.displacementBias=t.displacementBias),t.roughnessMap!==void 0&&(this.roughnessMap=e[t.roughnessMap]||null),t.metalnessMap!==void 0&&(this.metalnessMap=e[t.metalnessMap]||null),t.emissiveMap!==void 0&&(this.emissiveMap=e[t.emissiveMap]||null),t.emissiveIntensity!==void 0&&(this.emissiveIntensity=t.emissiveIntensity),t.specularMap!==void 0&&(this.specularMap=e[t.specularMap]||null),t.specularIntensityMap!==void 0&&(this.specularIntensityMap=e[t.specularIntensityMap]||null),t.specularColorMap!==void 0&&(this.specularColorMap=e[t.specularColorMap]||null),t.envMap!==void 0&&(this.envMap=e[t.envMap]||null),t.envMapRotation!==void 0&&this.envMapRotation.fromArray(t.envMapRotation),t.envMapIntensity!==void 0&&(this.envMapIntensity=t.envMapIntensity),t.reflectivity!==void 0&&(this.reflectivity=t.reflectivity),t.refractionRatio!==void 0&&(this.refractionRatio=t.refractionRatio),t.lightMap!==void 0&&(this.lightMap=e[t.lightMap]||null),t.lightMapIntensity!==void 0&&(this.lightMapIntensity=t.lightMapIntensity),t.aoMap!==void 0&&(this.aoMap=e[t.aoMap]||null),t.aoMapIntensity!==void 0&&(this.aoMapIntensity=t.aoMapIntensity),t.gradientMap!==void 0&&(this.gradientMap=e[t.gradientMap]||null),t.clearcoatMap!==void 0&&(this.clearcoatMap=e[t.clearcoatMap]||null),t.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=e[t.clearcoatRoughnessMap]||null),t.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=e[t.clearcoatNormalMap]||null),t.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new bt().fromArray(t.clearcoatNormalScale)),t.iridescenceMap!==void 0&&(this.iridescenceMap=e[t.iridescenceMap]||null),t.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=e[t.iridescenceThicknessMap]||null),t.transmissionMap!==void 0&&(this.transmissionMap=e[t.transmissionMap]||null),t.thicknessMap!==void 0&&(this.thicknessMap=e[t.thicknessMap]||null),t.anisotropyMap!==void 0&&(this.anisotropyMap=e[t.anisotropyMap]||null),t.sheenColorMap!==void 0&&(this.sheenColorMap=e[t.sheenColorMap]||null),t.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=e[t.sheenRoughnessMap]||null),this}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 i=null;if(e!==null){const n=e.length;i=new Array(n);for(let s=0;s!==n;++s)i[s]=e[s].clone()}return this.clippingPlanes=i,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.allowOverride=t.allowOverride,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++}}class Yh extends fr{constructor(t){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new st(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.rotation=t.rotation,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}let ho;const mc=new R,uo=new R,fo=new R,po=new bt,gc=new bt,t2=new ne,Wl=new R,vc=new R,Xl=new R,kg=new bt,Gd=new bt,Fg=new bt;class Mc extends ti{constructor(t=new Yh){if(super(),this.isSprite=!0,this.type="Sprite",ho===void 0){ho=new ae;const e=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new QM(e,5);ho.setIndex([0,1,2,0,2,3]),ho.setAttribute("position",new Iu(i,3,0,!1)),ho.setAttribute("uv",new Iu(i,2,3,!1))}this.geometry=ho,this.material=t,this.center=new bt(.5,.5),this.count=1}raycast(t,e){t.camera===null&&qt('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),uo.setFromMatrixScale(this.matrixWorld),t2.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),fo.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&uo.multiplyScalar(-fo.z);const i=this.material.rotation;let n,s;i!==0&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;Yl(Wl.set(-.5,-.5,0),fo,r,uo,n,s),Yl(vc.set(.5,-.5,0),fo,r,uo,n,s),Yl(Xl.set(.5,.5,0),fo,r,uo,n,s),kg.set(0,0),Gd.set(1,0),Fg.set(1,1);let o=t.ray.intersectTriangle(Wl,vc,Xl,!1,mc);if(o===null&&(Yl(vc.set(-.5,.5,0),fo,r,uo,n,s),Gd.set(0,1),o=t.ray.intersectTriangle(Wl,Xl,vc,!1,mc),o===null))return;const c=t.ray.origin.distanceTo(mc);c<t.near||c>t.far||e.push({distance:c,point:mc.clone(),uv:qn.getInterpolation(mc,Wl,vc,Xl,kg,Gd,Fg,new bt),face:null,object:this})}copy(t,e){return super.copy(t,e),t.center!==void 0&&this.center.copy(t.center),this.material=t.material,this}}function Yl(a,t,e,i,n,s){po.subVectors(a,e).addScalar(.5).multiply(i),n!==void 0?(gc.x=s*po.x-n*po.y,gc.y=n*po.x+s*po.y):gc.copy(po),a.copy(t),a.x+=gc.x,a.y+=gc.y,a.applyMatrix4(t2)}const Zs=new R,Vd=new R,ql=new R,Sr=new R,Wd=new R,$l=new R,Xd=new R;class bl{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,Zs)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Zs.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Zs.copy(this.origin).addScaledVector(this.direction,e),Zs.distanceToSquared(t))}distanceSqToSegment(t,e,i,n){Vd.copy(t).add(e).multiplyScalar(.5),ql.copy(e).sub(t).normalize(),Sr.copy(this.origin).sub(Vd);const s=t.distanceTo(e)*.5,r=-this.direction.dot(ql),o=Sr.dot(this.direction),c=-Sr.dot(ql),l=Sr.lengthSq(),h=Math.abs(1-r*r);let u,d,f,p;if(h>0)if(u=r*c-o,d=r*o-c,p=s*h,u>=0)if(d>=-p)if(d<=p){const v=1/h;u*=v,d*=v,f=u*(u+r*d+2*o)+d*(r*u+d+2*c)+l}else d=s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;else d=-s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;else d<=-p?(u=Math.max(0,-(-r*s+o)),d=u>0?-s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l):d<=p?(u=0,d=Math.min(Math.max(-s,-c),s),f=d*(d+2*c)+l):(u=Math.max(0,-(r*s+o)),d=u>0?s:Math.min(Math.max(-s,-c),s),f=-u*u+d*(d+2*c)+l);else d=r>0?-s:s,u=Math.max(0,-(r*d+o)),f=-u*u+d*(d+2*c)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,u),n&&n.copy(Vd).addScaledVector(ql,d),f}intersectSphere(t,e){Zs.subVectors(t.center,this.origin);const i=Zs.dot(this.direction),n=Zs.dot(Zs)-i*i,s=t.radius*t.radius;if(n>s)return null;const r=Math.sqrt(s-n),o=i-r,c=i+r;return c<0?null:o<0?this.at(c,e):this.at(o,e)}intersectsSphere(t){return t.radius<0?!1: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 i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,n,s,r,o,c;const l=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,d=this.origin;return l>=0?(i=(t.min.x-d.x)*l,n=(t.max.x-d.x)*l):(i=(t.max.x-d.x)*l,n=(t.min.x-d.x)*l),h>=0?(s=(t.min.y-d.y)*h,r=(t.max.y-d.y)*h):(s=(t.max.y-d.y)*h,r=(t.min.y-d.y)*h),i>r||s>n||((s>i||isNaN(i))&&(i=s),(r<n||isNaN(n))&&(n=r),u>=0?(o=(t.min.z-d.z)*u,c=(t.max.z-d.z)*u):(o=(t.max.z-d.z)*u,c=(t.min.z-d.z)*u),i>c||o>n)||((o>i||i!==i)&&(i=o),(c<n||n!==n)&&(n=c),n<0)?null:this.at(i>=0?i:n,e)}intersectsBox(t){return this.intersectBox(t,Zs)!==null}intersectTriangle(t,e,i,n,s){Wd.subVectors(e,t),$l.subVectors(i,t),Xd.crossVectors(Wd,$l);let r=this.direction.dot(Xd),o;if(r>0){if(n)return null;o=1}else if(r<0)o=-1,r=-r;else return null;Sr.subVectors(this.origin,t);const c=o*this.direction.dot($l.crossVectors(Sr,$l));if(c<0)return null;const l=o*this.direction.dot(Wd.cross(Sr));if(l<0||c+l>r)return null;const h=-o*Sr.dot(Xd);return h<0?null:this.at(h/r,s)}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 wn extends fr{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new st(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 hr,this.combine=Rp,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 Ug=new ne,Qr=new bl,Kl=new dr,zg=new R,Zl=new R,Jl=new R,jl=new R,Yd=new R,Ql=new R,Bg=new R,th=new R;class At extends ti{constructor(t=new ae,e=new wn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,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,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}getVertexPosition(t,e){const i=this.geometry,n=i.attributes.position,s=i.morphAttributes.position,r=i.morphTargetsRelative;e.fromBufferAttribute(n,t);const o=this.morphTargetInfluences;if(s&&o){Ql.set(0,0,0);for(let c=0,l=s.length;c<l;c++){const h=o[c],u=s[c];h!==0&&(Yd.fromBufferAttribute(u,t),r?Ql.addScaledVector(Yd,h):Ql.addScaledVector(Yd.sub(e),h))}e.add(Ql)}return e}raycast(t,e){const i=this.geometry,n=this.material,s=this.matrixWorld;n!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),Kl.copy(i.boundingSphere),Kl.applyMatrix4(s),Qr.copy(t.ray).recast(t.near),!(Kl.containsPoint(Qr.origin)===!1&&(Qr.intersectSphere(Kl,zg)===null||Qr.origin.distanceToSquared(zg)>(t.far-t.near)**2))&&(Ug.copy(s).invert(),Qr.copy(t.ray).applyMatrix4(Ug),!(i.boundingBox!==null&&Qr.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(t,e,Qr)))}_computeIntersections(t,e,i){let n;const s=this.geometry,r=this.material,o=s.index,c=s.attributes.position,l=s.attributes.uv,h=s.attributes.uv1,u=s.attributes.normal,d=s.groups,f=s.drawRange;if(o!==null)if(Array.isArray(r))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=r[m.materialIndex],b=Math.max(m.start,f.start),S=Math.min(o.count,Math.min(m.start+m.count,f.start+f.count));for(let M=b,x=S;M<x;M+=3){const _=o.getX(M),E=o.getX(M+1),y=o.getX(M+2);n=eh(this,g,t,i,l,h,u,_,E,y),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,e.push(n))}}else{const p=Math.max(0,f.start),v=Math.min(o.count,f.start+f.count);for(let m=p,g=v;m<g;m+=3){const b=o.getX(m),S=o.getX(m+1),M=o.getX(m+2);n=eh(this,r,t,i,l,h,u,b,S,M),n&&(n.faceIndex=Math.floor(m/3),e.push(n))}}else if(c!==void 0)if(Array.isArray(r))for(let p=0,v=d.length;p<v;p++){const m=d[p],g=r[m.materialIndex],b=Math.max(m.start,f.start),S=Math.min(c.count,Math.min(m.start+m.count,f.start+f.count));for(let M=b,x=S;M<x;M+=3){const _=M,E=M+1,y=M+2;n=eh(this,g,t,i,l,h,u,_,E,y),n&&(n.faceIndex=Math.floor(M/3),n.face.materialIndex=m.materialIndex,e.push(n))}}else{const p=Math.max(0,f.start),v=Math.min(c.count,f.start+f.count);for(let m=p,g=v;m<g;m+=3){const b=m,S=m+1,M=m+2;n=eh(this,r,t,i,l,h,u,b,S,M),n&&(n.faceIndex=Math.floor(m/3),e.push(n))}}}}function JS(a,t,e,i,n,s,r,o){let c;if(t.side===Qe?c=i.intersectTriangle(r,s,n,!0,o):c=i.intersectTriangle(n,s,r,t.side===Xr,o),c===null)return null;th.copy(o),th.applyMatrix4(a.matrixWorld);const l=e.ray.origin.distanceTo(th);return l<e.near||l>e.far?null:{distance:l,point:th.clone(),object:a}}function eh(a,t,e,i,n,s,r,o,c,l){a.getVertexPosition(o,Zl),a.getVertexPosition(c,Jl),a.getVertexPosition(l,jl);const h=JS(a,t,e,i,Zl,Jl,jl,Bg);if(h){const u=new R;qn.getBarycoord(Bg,Zl,Jl,jl,u),n&&(h.uv=qn.getInterpolatedAttribute(n,o,c,l,u,new bt)),s&&(h.uv1=qn.getInterpolatedAttribute(s,o,c,l,u,new bt)),r&&(h.normal=qn.getInterpolatedAttribute(r,o,c,l,u,new R),h.normal.dot(i.direction)>0&&h.normal.multiplyScalar(-1));const d={a:o,b:c,c:l,normal:new R,materialIndex:0};qn.getNormal(Zl,Jl,jl,d.normal),h.face=d,h.barycoord=u}return h}const yc=new ue,Hg=new ue,Gg=new ue,jS=new ue,Vg=new ne,ih=new R,qd=new dr,Wg=new ne,$d=new bl;class lI extends At{constructor(t,e){super(t,e),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=xg,this.bindMatrix=new ne,this.bindMatrixInverse=new ne,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const t=this.geometry;this.boundingBox===null&&(this.boundingBox=new Qi),this.boundingBox.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,ih),this.boundingBox.expandByPoint(ih)}computeBoundingSphere(){const t=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new dr),this.boundingSphere.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,ih),this.boundingSphere.expandByPoint(ih)}copy(t,e){return super.copy(t,e),this.bindMode=t.bindMode,this.bindMatrix.copy(t.bindMatrix),this.bindMatrixInverse.copy(t.bindMatrixInverse),this.skeleton=t.skeleton,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}raycast(t,e){const i=this.material,n=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),qd.copy(this.boundingSphere),qd.applyMatrix4(n),t.ray.intersectsSphere(qd)!==!1&&(Wg.copy(n).invert(),$d.copy(t.ray).applyMatrix4(Wg),!(this.boundingBox!==null&&$d.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(t,e,$d)))}getVertexPosition(t,e){return super.getVertexPosition(t,e),this.applyBoneTransform(t,e),e}bind(t,e){this.skeleton=t,e===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.copy(e).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const t=new ue,e=this.geometry.attributes.skinWeight;for(let i=0,n=e.count;i<n;i++){t.fromBufferAttribute(e,i);const s=1/t.manhattanLength();s!==1/0?t.multiplyScalar(s):t.set(1,0,0,0),e.setXYZW(i,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),this.bindMode===xg?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===jb?this.bindMatrixInverse.copy(this.bindMatrix).invert():Pt("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(t,e){const i=this.skeleton,n=this.geometry;Hg.fromBufferAttribute(n.attributes.skinIndex,t),Gg.fromBufferAttribute(n.attributes.skinWeight,t),e.isVector4?(yc.copy(e),e.set(0,0,0,0)):(yc.set(...e,1),e.set(0,0,0)),yc.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){const r=Gg.getComponent(s);if(r!==0){const o=Hg.getComponent(s);Vg.multiplyMatrices(i.bones[o].matrixWorld,i.boneInverses[o]),e.addScaledVector(jS.copy(yc).applyMatrix4(Vg),r)}}return e.isVector4&&(e.w=yc.w),e.applyMatrix4(this.bindMatrixInverse)}}class QS extends ti{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Vs extends Hi{constructor(t=null,e=1,i=1,n,s,r,o,c,l=Ue,h=Ue,u,d){super(null,r,o,c,l,h,n,s,u,d),this.isDataTexture=!0,this.image={data:t,width:e,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Xg=new ne,tw=new ne;class e2{constructor(t=[],e=[]){this.uuid=ds(),this.bones=t.slice(0),this.boneInverses=e,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const t=this.bones,e=this.boneInverses;if(this.boneMatrices=new Float32Array(t.length*16),e.length===0)this.calculateInverses();else if(t.length!==e.length){Pt("Skeleton: Number of inverse bone matrices does not match amount of bones."),this.boneInverses=[];for(let i=0,n=this.bones.length;i<n;i++)this.boneInverses.push(new ne)}}calculateInverses(){this.boneInverses.length=0;for(let t=0,e=this.bones.length;t<e;t++){const i=new ne;this.bones[t]&&i.copy(this.bones[t].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];i&&i.matrixWorld.copy(this.boneInverses[t]).invert()}for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];i&&(i.parent&&i.parent.isBone?(i.matrix.copy(i.parent.matrixWorld).invert(),i.matrix.multiply(i.matrixWorld)):i.matrix.copy(i.matrixWorld),i.matrix.decompose(i.position,i.quaternion,i.scale))}}update(){const t=this.bones,e=this.boneInverses,i=this.boneMatrices,n=this.boneTexture;for(let s=0,r=t.length;s<r;s++){const o=t[s]?t[s].matrixWorld:tw;Xg.multiplyMatrices(o,e[s]),Xg.toArray(i,s*16)}n!==null&&(n.needsUpdate=!0)}clone(){return new e2(this.bones,this.boneInverses)}computeBoneTexture(){let t=Math.sqrt(this.bones.length*4);t=Math.ceil(t/4)*4,t=Math.max(t,4);const e=new Float32Array(t*t*4);e.set(this.boneMatrices);const i=new Vs(e,t,t,Gi,ji);return i.needsUpdate=!0,this.boneMatrices=e,this.boneTexture=i,this}getBoneByName(t){for(let e=0,i=this.bones.length;e<i;e++){const n=this.bones[e];if(n.name===t)return n}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(t,e){this.uuid=t.uuid;for(let i=0,n=t.bones.length;i<n;i++){const s=t.bones[i];let r=e[s];r===void 0&&(Pt("Skeleton: No bone found with UUID:",s),r=new QS),this.bones.push(r),this.boneInverses.push(new ne().fromArray(t.boneInverses[i]))}return this.init(),this}toJSON(){const t={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};t.uuid=this.uuid;const e=this.bones,i=this.boneInverses;for(let n=0,s=e.length;n<s;n++){const r=e[n];t.bones.push(r.uuid);const o=i[n];t.boneInverses.push(o.toArray())}return t}}class Yg extends te{constructor(t,e,i,n=1){super(t,e,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=n}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}const mo=new ne,qg=new ne,nh=[],$g=new Qi,ew=new ne,xc=new At,bc=new dr;class hI extends At{constructor(t,e,i){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new Yg(new Float32Array(i*16),16),this.instanceColor=null,this.morphTexture=null,this.count=i,this.boundingBox=null,this.boundingSphere=null;for(let n=0;n<i;n++)this.setMatrixAt(n,ew)}computeBoundingBox(){const t=this.geometry,e=this.count;this.boundingBox===null&&(this.boundingBox=new Qi),t.boundingBox===null&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,mo),$g.copy(t.boundingBox).applyMatrix4(mo),this.boundingBox.union($g)}computeBoundingSphere(){const t=this.geometry,e=this.count;this.boundingSphere===null&&(this.boundingSphere=new dr),t.boundingSphere===null&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,mo),bc.copy(t.boundingSphere).applyMatrix4(mo),this.boundingSphere.union(bc)}copy(t,e){return super.copy(t,e),this.instanceMatrix.copy(t.instanceMatrix),t.morphTexture!==null&&(this.morphTexture=t.morphTexture.clone()),t.instanceColor!==null&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}getColorAt(t,e){return this.instanceColor===null?e.setRGB(1,1,1):e.fromArray(this.instanceColor.array,t*3)}getMatrixAt(t,e){return e.fromArray(this.instanceMatrix.array,t*16)}getMorphAt(t,e){const i=e.morphTargetInfluences,n=this.morphTexture.source.data.data,s=i.length+1,r=t*s+1;for(let o=0;o<i.length;o++)i[o]=n[r+o]}raycast(t,e){const i=this.matrixWorld,n=this.count;if(xc.geometry=this.geometry,xc.material=this.material,xc.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),bc.copy(this.boundingSphere),bc.applyMatrix4(i),t.ray.intersectsSphere(bc)!==!1))for(let s=0;s<n;s++){this.getMatrixAt(s,mo),qg.multiplyMatrices(i,mo),xc.matrixWorld=qg,xc.raycast(t,nh);for(let r=0,o=nh.length;r<o;r++){const c=nh[r];c.instanceId=s,c.object=this,e.push(c)}nh.length=0}}setColorAt(t,e){return this.instanceColor===null&&(this.instanceColor=new Yg(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),e.toArray(this.instanceColor.array,t*3),this}setMatrixAt(t,e){return e.toArray(this.instanceMatrix.array,t*16),this}setMorphAt(t,e){const i=e.morphTargetInfluences,n=i.length+1;this.morphTexture===null&&(this.morphTexture=new Vs(new Float32Array(n*this.count),n,this.count,tc,ji));const s=this.morphTexture.source.data.data;let r=0;for(let l=0;l<i.length;l++)r+=i[l];const o=this.geometry.morphTargetsRelative?1:1-r,c=n*t;return s[c]=o,s.set(i,c+1),this}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"}),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null)}}const Kd=new R,iw=new R,nw=new Jt;class Ir{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,i,n){return this.normal.set(t,e,i),this.constant=n,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const n=Kd.subVectors(i,e).cross(iw.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(n,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,i=!0){const n=t.delta(Kd),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 i===!0&&(r<0||r>1)?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<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 i=e||nw.getNormalMatrix(t),n=this.coplanarPoint(Kd).applyMatrix4(t),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),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 ta=new dr,sw=new bt(.5,.5),sh=new R;class Vp{constructor(t=new Ir,e=new Ir,i=new Ir,n=new Ir,s=new Ir,r=new Ir){this.planes=[t,e,i,n,s,r]}set(t,e,i,n,s,r){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(i),o[3].copy(n),o[4].copy(s),o[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t,e=Us,i=!1){const n=this.planes,s=t.elements,r=s[0],o=s[1],c=s[2],l=s[3],h=s[4],u=s[5],d=s[6],f=s[7],p=s[8],v=s[9],m=s[10],g=s[11],b=s[12],S=s[13],M=s[14],x=s[15];if(n[0].setComponents(l-r,f-h,g-p,x-b).normalize(),n[1].setComponents(l+r,f+h,g+p,x+b).normalize(),n[2].setComponents(l+o,f+u,g+v,x+S).normalize(),n[3].setComponents(l-o,f-u,g-v,x-S).normalize(),i)n[4].setComponents(c,d,m,M).normalize(),n[5].setComponents(l-c,f-d,g-m,x-M).normalize();else if(n[4].setComponents(l-c,f-d,g-m,x-M).normalize(),e===Us)n[5].setComponents(l+c,f+d,g+m,x+M).normalize();else if(e===ul)n[5].setComponents(c,d,m,M).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(),ta.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),ta.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(ta)}intersectsSprite(t){ta.center.set(0,0,0);const e=sw.distanceTo(t.center);return ta.radius=.7071067811865476+e,ta.applyMatrix4(t.matrixWorld),this.intersectsSphere(ta)}intersectsSphere(t){const e=this.planes,i=t.center,n=-t.radius;for(let s=0;s<6;s++)if(e[s].distanceToPoint(i)<n)return!1;return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const n=e[i];if(sh.x=n.normal.x>0?t.max.x:t.min.x,sh.y=n.normal.y>0?t.max.y:t.min.y,sh.z=n.normal.z>0?t.max.z:t.min.z,n.distanceToPoint(sh)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class rw extends fr{constructor(t){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new st(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this.fog=t.fog,this}}const Cu=new R,Pu=new R,Kg=new ne,Sc=new bl,rh=new dr,Zd=new R,Zg=new R;class i2 extends ti{constructor(t=new ae,e=new rw){super(),this.isLine=!0,this.type="Line",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[0];for(let n=1,s=e.count;n<s;n++)Cu.fromBufferAttribute(e,n-1),Pu.fromBufferAttribute(e,n),i[n]=i[n-1],i[n]+=Cu.distanceTo(Pu);t.setAttribute("lineDistance",new ve(i,1))}else Pt("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Line.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),rh.copy(i.boundingSphere),rh.applyMatrix4(n),rh.radius+=s,t.ray.intersectsSphere(rh)===!1)return;Kg.copy(n).invert(),Sc.copy(t.ray).applyMatrix4(Kg);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),c=o*o,l=this.isLineSegments?2:1,h=i.index,d=i.attributes.position;if(h!==null){const f=Math.max(0,r.start),p=Math.min(h.count,r.start+r.count);for(let v=f,m=p-1;v<m;v+=l){const g=h.getX(v),b=h.getX(v+1),S=ah(this,t,Sc,c,g,b,v);S&&e.push(S)}if(this.isLineLoop){const v=h.getX(p-1),m=h.getX(f),g=ah(this,t,Sc,c,v,m,p-1);g&&e.push(g)}}else{const f=Math.max(0,r.start),p=Math.min(d.count,r.start+r.count);for(let v=f,m=p-1;v<m;v+=l){const g=ah(this,t,Sc,c,v,v+1,v);g&&e.push(g)}if(this.isLineLoop){const v=ah(this,t,Sc,c,p-1,f,p-1);v&&e.push(v)}}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function ah(a,t,e,i,n,s,r){const o=a.geometry.attributes.position;if(Cu.fromBufferAttribute(o,n),Pu.fromBufferAttribute(o,s),e.distanceSqToSegment(Cu,Pu,Zd,Zg)>i)return;Zd.applyMatrix4(a.matrixWorld);const l=t.ray.origin.distanceTo(Zd);if(!(l<t.near||l>t.far))return{distance:l,point:Zg.clone().applyMatrix4(a.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:a}}const Jg=new R,jg=new R;class uI extends i2{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[];for(let n=0,s=e.count;n<s;n+=2)Jg.fromBufferAttribute(e,n),jg.fromBufferAttribute(e,n+1),i[n]=n===0?0:i[n-1],i[n+1]=i[n]+Jg.distanceTo(jg);t.setAttribute("lineDistance",new ve(i,1))}else Pt("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class dI extends i2{constructor(t,e){super(t,e),this.isLineLoop=!0,this.type="LineLoop"}}class F0 extends fr{constructor(t){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new st(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}const Qg=new ne,U0=new bl,oh=new dr,ch=new R;class In extends ti{constructor(t=new ae,e=new F0){super(),this.isPoints=!0,this.type="Points",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Points.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),oh.copy(i.boundingSphere),oh.applyMatrix4(n),oh.radius+=s,t.ray.intersectsSphere(oh)===!1)return;Qg.copy(n).invert(),U0.copy(t.ray).applyMatrix4(Qg);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),c=o*o,l=i.index,u=i.attributes.position;if(l!==null){const d=Math.max(0,r.start),f=Math.min(l.count,r.start+r.count);for(let p=d,v=f;p<v;p++){const m=l.getX(p);ch.fromBufferAttribute(u,m),t1(ch,m,c,n,t,e,this)}}else{const d=Math.max(0,r.start),f=Math.min(u.count,r.start+r.count);for(let p=d,v=f;p<v;p++)ch.fromBufferAttribute(u,p),t1(ch,p,c,n,t,e,this)}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const n=e[i[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,r=n.length;s<r;s++){const o=n[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=s}}}}}function t1(a,t,e,i,n,s,r){const o=U0.distanceSqToPoint(a);if(o<e){const c=new R;U0.closestPointToPoint(a,c),c.applyMatrix4(i);const l=n.ray.origin.distanceTo(c);if(l<n.near||l>n.far)return;s.push({distance:l,distanceToRay:Math.sqrt(o),point:c,index:t,face:null,faceIndex:null,barycoord:null,object:r})}}class n2 extends Hi{constructor(t=[],e=Ba,i,n,s,r,o,c,l,h){super(t,e,i,n,s,r,o,c,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class pr extends Hi{constructor(t,e,i,n,s,r,o,c,l){super(t,e,i,n,s,r,o,c,l),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Yr extends Hi{constructor(t,e,i=Kn,n,s,r,o=Ue,c=Ue,l,h=lr,u=1){if(h!==lr&&h!==Ta)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:t,height:e,depth:u};super(d,n,s,r,o,c,h,i,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.source=new zp(Object.assign({},t.image)),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}class aw extends Yr{constructor(t,e=Kn,i=Ba,n,s,r=Ue,o=Ue,c,l=lr){const h={width:t,height:t,depth:1},u=[h,h,h,h,h,h];super(t,t,e,i,n,s,r,o,c,l),this.image=u,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(t){this.image=t}}class s2 extends Hi{constructor(t=null){super(),this.sourceTexture=t,this.isExternalTexture=!0}copy(t){return super.copy(t),this.sourceTexture=t.sourceTexture,this}}class Vi extends ae{constructor(t=1,e=1,i=1,n=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:n,heightSegments:s,depthSegments:r};const o=this;n=Math.floor(n),s=Math.floor(s),r=Math.floor(r);const c=[],l=[],h=[],u=[];let d=0,f=0;p("z","y","x",-1,-1,i,e,t,r,s,0),p("z","y","x",1,-1,i,e,-t,r,s,1),p("x","z","y",1,1,t,i,e,n,r,2),p("x","z","y",1,-1,t,i,-e,n,r,3),p("x","y","z",1,-1,t,e,i,n,s,4),p("x","y","z",-1,-1,t,e,-i,n,s,5),this.setIndex(c),this.setAttribute("position",new ve(l,3)),this.setAttribute("normal",new ve(h,3)),this.setAttribute("uv",new ve(u,2));function p(v,m,g,b,S,M,x,_,E,y,T){const I=M/E,C=x/y,P=M/2,B=x/2,W=_/2,O=E+1,H=y+1;let U=0,q=0;const Q=new R;for(let J=0;J<H;J++){const it=J*C-B;for(let ot=0;ot<O;ot++){const $t=ot*I-P;Q[v]=$t*b,Q[m]=it*S,Q[g]=W,l.push(Q.x,Q.y,Q.z),Q[v]=0,Q[m]=0,Q[g]=_>0?1:-1,h.push(Q.x,Q.y,Q.z),u.push(ot/E),u.push(1-J/y),U+=1}}for(let J=0;J<y;J++)for(let it=0;it<E;it++){const ot=d+it+O*J,$t=d+it+O*(J+1),re=d+(it+1)+O*(J+1),jt=d+(it+1)+O*J;c.push(ot,$t,jt),c.push($t,re,jt),q+=6}o.addGroup(f,q,T),f+=q,d+=U}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Vi(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}class Wp extends ae{constructor(t=1,e=32,i=0,n=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:i,thetaLength:n},e=Math.max(3,e);const s=[],r=[],o=[],c=[],l=new R,h=new bt;r.push(0,0,0),o.push(0,0,1),c.push(.5,.5);for(let u=0,d=3;u<=e;u++,d+=3){const f=i+u/e*n;l.x=t*Math.cos(f),l.y=t*Math.sin(f),r.push(l.x,l.y,l.z),o.push(0,0,1),h.x=(r[d]/t+1)/2,h.y=(r[d+1]/t+1)/2,c.push(h.x,h.y)}for(let u=1;u<=e;u++)s.push(u,u+1,0);this.setIndex(s),this.setAttribute("position",new ve(r,3)),this.setAttribute("normal",new ve(o,3)),this.setAttribute("uv",new ve(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Wp(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class Zn extends ae{constructor(t=1,e=1,i=1,n=32,s=1,r=!1,o=0,c=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:i,radialSegments:n,heightSegments:s,openEnded:r,thetaStart:o,thetaLength:c};const l=this;n=Math.floor(n),s=Math.floor(s);const h=[],u=[],d=[],f=[];let p=0;const v=[],m=i/2;let g=0;b(),r===!1&&(t>0&&S(!0),e>0&&S(!1)),this.setIndex(h),this.setAttribute("position",new ve(u,3)),this.setAttribute("normal",new ve(d,3)),this.setAttribute("uv",new ve(f,2));function b(){const M=new R,x=new R;let _=0;const E=(e-t)/i;for(let y=0;y<=s;y++){const T=[],I=y/s,C=I*(e-t)+t;for(let P=0;P<=n;P++){const B=P/n,W=B*c+o,O=Math.sin(W),H=Math.cos(W);x.x=C*O,x.y=-I*i+m,x.z=C*H,u.push(x.x,x.y,x.z),M.set(O,E,H).normalize(),d.push(M.x,M.y,M.z),f.push(B,1-I),T.push(p++)}v.push(T)}for(let y=0;y<n;y++)for(let T=0;T<s;T++){const I=v[T][y],C=v[T+1][y],P=v[T+1][y+1],B=v[T][y+1];(t>0||T!==0)&&(h.push(I,C,B),_+=3),(e>0||T!==s-1)&&(h.push(C,P,B),_+=3)}l.addGroup(g,_,0),g+=_}function S(M){const x=p,_=new bt,E=new R;let y=0;const T=M===!0?t:e,I=M===!0?1:-1;for(let P=1;P<=n;P++)u.push(0,m*I,0),d.push(0,I,0),f.push(.5,.5),p++;const C=p;for(let P=0;P<=n;P++){const W=P/n*c+o,O=Math.cos(W),H=Math.sin(W);E.x=T*H,E.y=m*I,E.z=T*O,u.push(E.x,E.y,E.z),d.push(0,I,0),_.x=O*.5+.5,_.y=H*.5*I+.5,f.push(_.x,_.y),p++}for(let P=0;P<n;P++){const B=x+P,W=C+P;M===!0?h.push(W,W+1,B):h.push(W+1,W,B),y+=3}l.addGroup(g,y,M===!0?1:2),g+=y}}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 rc extends Zn{constructor(t=1,e=1,i=32,n=1,s=!1,r=0,o=Math.PI*2){super(0,t,e,i,n,s,r,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:i,heightSegments:n,openEnded:s,thetaStart:r,thetaLength:o}}static fromJSON(t){return new rc(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class id extends ae{constructor(t=[new bt(0,-.5),new bt(.5,0),new bt(0,.5)],e=12,i=0,n=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:i,phiLength:n},e=Math.floor(e),n=Qt(n,0,Math.PI*2);const s=[],r=[],o=[],c=[],l=[],h=1/e,u=new R,d=new bt,f=new R,p=new R,v=new R;let m=0,g=0;for(let b=0;b<=t.length-1;b++)switch(b){case 0:m=t[b+1].x-t[b].x,g=t[b+1].y-t[b].y,f.x=g*1,f.y=-m,f.z=g*0,v.copy(f),f.normalize(),c.push(f.x,f.y,f.z);break;case t.length-1:c.push(v.x,v.y,v.z);break;default:m=t[b+1].x-t[b].x,g=t[b+1].y-t[b].y,f.x=g*1,f.y=-m,f.z=g*0,p.copy(f),f.x+=v.x,f.y+=v.y,f.z+=v.z,f.normalize(),c.push(f.x,f.y,f.z),v.copy(p)}for(let b=0;b<=e;b++){const S=i+b*h*n,M=Math.sin(S),x=Math.cos(S);for(let _=0;_<=t.length-1;_++){u.x=t[_].x*M,u.y=t[_].y,u.z=t[_].x*x,r.push(u.x,u.y,u.z),d.x=b/e,d.y=_/(t.length-1),o.push(d.x,d.y);const E=c[3*_+0]*M,y=c[3*_+1],T=c[3*_+0]*x;l.push(E,y,T)}}for(let b=0;b<e;b++)for(let S=0;S<t.length-1;S++){const M=S+b*t.length,x=M,_=M+t.length,E=M+t.length+1,y=M+1;s.push(x,_,y),s.push(E,y,_)}this.setIndex(s),this.setAttribute("position",new ve(r,3)),this.setAttribute("uv",new ve(o,2)),this.setAttribute("normal",new ve(l,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new id(t.points,t.segments,t.phiStart,t.phiLength)}}class dn extends ae{constructor(t=1,e=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:n};const s=t/2,r=e/2,o=Math.floor(i),c=Math.floor(n),l=o+1,h=c+1,u=t/o,d=e/c,f=[],p=[],v=[],m=[];for(let g=0;g<h;g++){const b=g*d-r;for(let S=0;S<l;S++){const M=S*u-s;p.push(M,-b,0),v.push(0,0,1),m.push(S/o),m.push(1-g/c)}}for(let g=0;g<c;g++)for(let b=0;b<o;b++){const S=b+l*g,M=b+l*(g+1),x=b+1+l*(g+1),_=b+1+l*g;f.push(S,M,_),f.push(M,x,_)}this.setIndex(f),this.setAttribute("position",new ve(p,3)),this.setAttribute("normal",new ve(v,3)),this.setAttribute("uv",new ve(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new dn(t.width,t.height,t.widthSegments,t.heightSegments)}}class pi extends ae{constructor(t=1,e=32,i=16,n=0,s=Math.PI*2,r=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:i,phiStart:n,phiLength:s,thetaStart:r,thetaLength:o},e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));const c=Math.min(r+o,Math.PI);let l=0;const h=[],u=new R,d=new R,f=[],p=[],v=[],m=[];for(let g=0;g<=i;g++){const b=[],S=g/i,M=r+S*o,x=t*Math.cos(M),_=Math.sqrt(t*t-x*x);let E=0;g===0&&r===0?E=.5/e:g===i&&c===Math.PI&&(E=-.5/e);for(let y=0;y<=e;y++){const T=y/e,I=n+T*s;u.x=-_*Math.cos(I),u.y=x,u.z=_*Math.sin(I),p.push(u.x,u.y,u.z),d.copy(u).normalize(),v.push(d.x,d.y,d.z),m.push(T+E,1-S),b.push(l++)}h.push(b)}for(let g=0;g<i;g++)for(let b=0;b<e;b++){const S=h[g][b+1],M=h[g][b],x=h[g+1][b],_=h[g+1][b+1];(g!==0||r>0)&&f.push(S,M,_),(g!==i-1||c<Math.PI)&&f.push(M,x,_)}this.setIndex(f),this.setAttribute("position",new ve(p,3)),this.setAttribute("normal",new ve(v,3)),this.setAttribute("uv",new ve(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new pi(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class Xp extends ae{constructor(t=1,e=.4,i=12,n=48,s=Math.PI*2,r=0,o=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:i,tubularSegments:n,arc:s,thetaStart:r,thetaLength:o},i=Math.floor(i),n=Math.floor(n);const c=[],l=[],h=[],u=[],d=new R,f=new R,p=new R;for(let v=0;v<=i;v++){const m=r+v/i*o;for(let g=0;g<=n;g++){const b=g/n*s;f.x=(t+e*Math.cos(m))*Math.cos(b),f.y=(t+e*Math.cos(m))*Math.sin(b),f.z=e*Math.sin(m),l.push(f.x,f.y,f.z),d.x=t*Math.cos(b),d.y=t*Math.sin(b),p.subVectors(f,d).normalize(),h.push(p.x,p.y,p.z),u.push(g/n),u.push(v/i)}}for(let v=1;v<=i;v++)for(let m=1;m<=n;m++){const g=(n+1)*v+m-1,b=(n+1)*(v-1)+m-1,S=(n+1)*(v-1)+m,M=(n+1)*v+m;c.push(g,b,M),c.push(b,S,M)}this.setIndex(c),this.setAttribute("position",new ve(l,3)),this.setAttribute("normal",new ve(h,3)),this.setAttribute("uv",new ve(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Xp(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class fI extends ae{constructor(t=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:t},t!==null){const e=[],i=new Set,n=new R,s=new R;if(t.index!==null){const r=t.attributes.position,o=t.index;let c=t.groups;c.length===0&&(c=[{start:0,count:o.count,materialIndex:0}]);for(let l=0,h=c.length;l<h;++l){const u=c[l],d=u.start,f=u.count;for(let p=d,v=d+f;p<v;p+=3)for(let m=0;m<3;m++){const g=o.getX(p+m),b=o.getX(p+(m+1)%3);n.fromBufferAttribute(r,g),s.fromBufferAttribute(r,b),e1(n,s,i)===!0&&(e.push(n.x,n.y,n.z),e.push(s.x,s.y,s.z))}}}else{const r=t.attributes.position;for(let o=0,c=r.count/3;o<c;o++)for(let l=0;l<3;l++){const h=3*o+l,u=3*o+(l+1)%3;n.fromBufferAttribute(r,h),s.fromBufferAttribute(r,u),e1(n,s,i)===!0&&(e.push(n.x,n.y,n.z),e.push(s.x,s.y,s.z))}}this.setAttribute("position",new ve(e,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}function e1(a,t,e){const i=`${a.x},${a.y},${a.z}-${t.x},${t.y},${t.z}`,n=`${t.x},${t.y},${t.z}-${a.x},${a.y},${a.z}`;return e.has(i)===!0||e.has(n)===!0?!1:(e.add(i),e.add(n),!0)}function ic(a){const t={};for(const e in a){t[e]={};for(const i in a[e]){const n=a[e][i];if(i1(n))n.isRenderTargetTexture?(Pt("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[e][i]=null):t[e][i]=n.clone();else if(Array.isArray(n))if(i1(n[0])){const s=[];for(let r=0,o=n.length;r<o;r++)s[r]=n[r].clone();t[e][i]=s}else t[e][i]=n.slice();else t[e][i]=n}}return t}function en(a){const t={};for(let e=0;e<a.length;e++){const i=ic(a[e]);for(const n in i)t[n]=i[n]}return t}function i1(a){return a&&(a.isColor||a.isMatrix3||a.isMatrix4||a.isVector2||a.isVector3||a.isVector4||a.isTexture||a.isQuaternion)}function ow(a){const t=[];for(let e=0;e<a.length;e++)t.push(a[e].clone());return t}function r2(a){const t=a.getRenderTarget();return t===null?a.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:me.workingColorSpace}const cw={clone:ic,merge:en};var lw=`void main() {
2188
2188
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
2189
2189
  }`,hw=`void main() {
2190
2190
  gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
@@ -6271,7 +6271,7 @@ void main() {
6271
6271
  squared_mean = squared_mean / samples;
6272
6272
  float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
6273
6273
  gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
6274
- }`,AA=[new R(1,0,0),new R(-1,0,0),new R(0,1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1)],TA=[new R(0,-1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1),new R(0,-1,0),new R(0,-1,0)],k1=new ne,_c=new R,af=new R;function RA(a,t,e){let i=new Vp;const n=new bt,s=new bt,r=new ue,o=new dw,c=new fw,l={},h=e.maxTextureSize,u={[Xr]:Qe,[Qe]:Xr,[bn]:bn},d=new Me({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new bt},radius:{value:4}},vertexShader:_A,fragmentShader:EA}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const p=new ae;p.setAttribute("position",new te(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const v=new At(p,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Xc;let g=this.type;this.render=function(_,E,y){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||_.length===0)return;this.type===Lb&&(Pt("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=Xc);const T=a.getRenderTarget(),I=a.getActiveCubeFace(),C=a.getActiveMipmapLevel(),P=a.state;P.setBlending(Bs),P.buffers.depth.getReversed()===!0?P.buffers.color.setClear(0,0,0,0):P.buffers.color.setClear(1,1,1,1),P.buffers.depth.setTest(!0),P.setScissorTest(!1);const B=g!==this.type;B&&E.traverse(function(W){W.material&&(Array.isArray(W.material)?W.material.forEach(O=>O.needsUpdate=!0):W.material.needsUpdate=!0)});for(let W=0,O=_.length;W<O;W++){const H=_[W],U=H.shadow;if(U===void 0){Pt("WebGLShadowMap:",H,"has no shadow.");continue}if(U.autoUpdate===!1&&U.needsUpdate===!1)continue;n.copy(U.mapSize);const q=U.getFrameExtents();n.multiply(q),s.copy(U.mapSize),(n.x>h||n.y>h)&&(n.x>h&&(s.x=Math.floor(h/q.x),n.x=s.x*q.x,U.mapSize.x=s.x),n.y>h&&(s.y=Math.floor(h/q.y),n.y=s.y*q.y,U.mapSize.y=s.y));const Q=a.state.buffers.depth.getReversed();if(U.camera._reversedDepth=Q,U.map===null||B===!0){if(U.map!==null&&(U.map.depthTexture!==null&&(U.map.depthTexture.dispose(),U.map.depthTexture=null),U.map.dispose()),this.type===Lc){if(H.isPointLight){Pt("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}U.map=new oi(n.x,n.y,{format:Ha,type:qe,minFilter:de,magFilter:de,generateMipmaps:!1}),U.map.texture.name=H.name+".shadowMap",U.map.depthTexture=new Yr(n.x,n.y,ji),U.map.depthTexture.name=H.name+".shadowMapDepth",U.map.depthTexture.format=lr,U.map.depthTexture.compareFunction=null,U.map.depthTexture.minFilter=Ue,U.map.depthTexture.magFilter=Ue}else H.isPointLight?(U.map=new fl(n.x),U.map.depthTexture=new aw(n.x,Kn)):(U.map=new oi(n.x,n.y),U.map.depthTexture=new Yr(n.x,n.y,Kn)),U.map.depthTexture.name=H.name+".shadowMap",U.map.depthTexture.format=lr,this.type===Xc?(U.map.depthTexture.compareFunction=Q?Fp:kp,U.map.depthTexture.minFilter=de,U.map.depthTexture.magFilter=de):(U.map.depthTexture.compareFunction=null,U.map.depthTexture.minFilter=Ue,U.map.depthTexture.magFilter=Ue);U.camera.updateProjectionMatrix()}const J=U.map.isWebGLCubeRenderTarget?6:1;for(let it=0;it<J;it++){if(U.map.isWebGLCubeRenderTarget)a.setRenderTarget(U.map,it),a.clear();else{it===0&&(a.setRenderTarget(U.map),a.clear());const ot=U.getViewport(it);r.set(s.x*ot.x,s.y*ot.y,s.x*ot.z,s.y*ot.w),P.viewport(r)}if(H.isPointLight){const ot=U.camera,$t=U.matrix,re=H.distance||ot.far;re!==ot.far&&(ot.far=re,ot.updateProjectionMatrix()),_c.setFromMatrixPosition(H.matrixWorld),ot.position.copy(_c),af.copy(ot.position),af.add(AA[it]),ot.up.copy(TA[it]),ot.lookAt(af),ot.updateMatrixWorld(),$t.makeTranslation(-_c.x,-_c.y,-_c.z),k1.multiplyMatrices(ot.projectionMatrix,ot.matrixWorldInverse),U._frustum.setFromProjectionMatrix(k1,ot.coordinateSystem,ot.reversedDepth)}else U.updateMatrices(H);i=U.getFrustum(),M(E,y,U.camera,H,this.type)}U.isPointLightShadow!==!0&&this.type===Lc&&b(U,y),U.needsUpdate=!1}g=this.type,m.needsUpdate=!1,a.setRenderTarget(T,I,C)};function b(_,E){const y=t.update(v);d.defines.VSM_SAMPLES!==_.blurSamples&&(d.defines.VSM_SAMPLES=_.blurSamples,f.defines.VSM_SAMPLES=_.blurSamples,d.needsUpdate=!0,f.needsUpdate=!0),_.mapPass===null&&(_.mapPass=new oi(n.x,n.y,{format:Ha,type:qe})),d.uniforms.shadow_pass.value=_.map.depthTexture,d.uniforms.resolution.value=_.mapSize,d.uniforms.radius.value=_.radius,a.setRenderTarget(_.mapPass),a.clear(),a.renderBufferDirect(E,null,y,d,v,null),f.uniforms.shadow_pass.value=_.mapPass.texture,f.uniforms.resolution.value=_.mapSize,f.uniforms.radius.value=_.radius,a.setRenderTarget(_.map),a.clear(),a.renderBufferDirect(E,null,y,f,v,null)}function S(_,E,y,T){let I=null;const C=y.isPointLight===!0?_.customDistanceMaterial:_.customDepthMaterial;if(C!==void 0)I=C;else if(I=y.isPointLight===!0?c:o,a.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||E.alphaToCoverage===!0){const P=I.uuid,B=E.uuid;let W=l[P];W===void 0&&(W={},l[P]=W);let O=W[B];O===void 0&&(O=I.clone(),W[B]=O,E.addEventListener("dispose",x)),I=O}if(I.visible=E.visible,I.wireframe=E.wireframe,T===Lc?I.side=E.shadowSide!==null?E.shadowSide:E.side:I.side=E.shadowSide!==null?E.shadowSide:u[E.side],I.alphaMap=E.alphaMap,I.alphaTest=E.alphaToCoverage===!0?.5:E.alphaTest,I.map=E.map,I.clipShadows=E.clipShadows,I.clippingPlanes=E.clippingPlanes,I.clipIntersection=E.clipIntersection,I.displacementMap=E.displacementMap,I.displacementScale=E.displacementScale,I.displacementBias=E.displacementBias,I.wireframeLinewidth=E.wireframeLinewidth,I.linewidth=E.linewidth,y.isPointLight===!0&&I.isMeshDistanceMaterial===!0){const P=a.properties.get(I);P.light=y}return I}function M(_,E,y,T,I){if(_.visible===!1)return;if(_.layers.test(E.layers)&&(_.isMesh||_.isLine||_.isPoints)&&(_.castShadow||_.receiveShadow&&I===Lc)&&(!_.frustumCulled||i.intersectsObject(_))){_.modelViewMatrix.multiplyMatrices(y.matrixWorldInverse,_.matrixWorld);const B=t.update(_),W=_.material;if(Array.isArray(W)){const O=B.groups;for(let H=0,U=O.length;H<U;H++){const q=O[H],Q=W[q.materialIndex];if(Q&&Q.visible){const J=S(_,Q,T,I);_.onBeforeShadow(a,_,E,y,B,J,q),a.renderBufferDirect(y,null,B,J,_,q),_.onAfterShadow(a,_,E,y,B,J,q)}}}else if(W.visible){const O=S(_,W,T,I);_.onBeforeShadow(a,_,E,y,B,O,null),a.renderBufferDirect(y,null,B,O,_,null),_.onAfterShadow(a,_,E,y,B,O,null)}}const P=_.children;for(let B=0,W=P.length;B<W;B++)M(P[B],E,y,T,I)}function x(_){_.target.removeEventListener("dispose",x);for(const y in l){const T=l[y],I=_.target.uuid;I in T&&(T[I].dispose(),delete T[I])}}}function DA(a,t){function e(){let L=!1;const lt=new ue;let j=null;const pt=new ue(0,0,0,0);return{setMask:function(xt){j!==xt&&!L&&(a.colorMask(xt,xt,xt,xt),j=xt)},setLocked:function(xt){L=xt},setClear:function(xt,et,Ot,Tt,hi){hi===!0&&(xt*=Tt,et*=Tt,Ot*=Tt),lt.set(xt,et,Ot,Tt),pt.equals(lt)===!1&&(a.clearColor(xt,et,Ot,Tt),pt.copy(lt))},reset:function(){L=!1,j=null,pt.set(-1,0,0,0)}}}function i(){let L=!1,lt=!1,j=null,pt=null,xt=null;return{setReversed:function(et){if(lt!==et){const Ot=t.get("EXT_clip_control");et?Ot.clipControlEXT(Ot.LOWER_LEFT_EXT,Ot.ZERO_TO_ONE_EXT):Ot.clipControlEXT(Ot.LOWER_LEFT_EXT,Ot.NEGATIVE_ONE_TO_ONE_EXT),lt=et;const Tt=xt;xt=null,this.setClear(Tt)}},getReversed:function(){return lt},setTest:function(et){et?nt(a.DEPTH_TEST):z(a.DEPTH_TEST)},setMask:function(et){j!==et&&!L&&(a.depthMask(et),j=et)},setFunc:function(et){if(lt&&(et=mS[et]),pt!==et){switch(et){case Jf:a.depthFunc(a.NEVER);break;case jf:a.depthFunc(a.ALWAYS);break;case Qf:a.depthFunc(a.LESS);break;case Jo:a.depthFunc(a.LEQUAL);break;case t0:a.depthFunc(a.EQUAL);break;case e0:a.depthFunc(a.GEQUAL);break;case i0:a.depthFunc(a.GREATER);break;case n0:a.depthFunc(a.NOTEQUAL);break;default:a.depthFunc(a.LEQUAL)}pt=et}},setLocked:function(et){L=et},setClear:function(et){xt!==et&&(xt=et,lt&&(et=1-et),a.clearDepth(et))},reset:function(){L=!1,j=null,pt=null,xt=null,lt=!1}}}function n(){let L=!1,lt=null,j=null,pt=null,xt=null,et=null,Ot=null,Tt=null,hi=null;return{setTest:function(Ge){L||(Ge?nt(a.STENCIL_TEST):z(a.STENCIL_TEST))},setMask:function(Ge){lt!==Ge&&!L&&(a.stencilMask(Ge),lt=Ge)},setFunc:function(Ge,gs,vs){(j!==Ge||pt!==gs||xt!==vs)&&(a.stencilFunc(Ge,gs,vs),j=Ge,pt=gs,xt=vs)},setOp:function(Ge,gs,vs){(et!==Ge||Ot!==gs||Tt!==vs)&&(a.stencilOp(Ge,gs,vs),et=Ge,Ot=gs,Tt=vs)},setLocked:function(Ge){L=Ge},setClear:function(Ge){hi!==Ge&&(a.clearStencil(Ge),hi=Ge)},reset:function(){L=!1,lt=null,j=null,pt=null,xt=null,et=null,Ot=null,Tt=null,hi=null}}}const s=new e,r=new i,o=new n,c=new WeakMap,l=new WeakMap;let h={},u={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,b=null,S=null,M=null,x=null,_=null,E=null,y=new st(0,0,0),T=0,I=!1,C=null,P=null,B=null,W=null,O=null;const H=a.getParameter(a.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let U=!1,q=0;const Q=a.getParameter(a.VERSION);Q.indexOf("WebGL")!==-1?(q=parseFloat(/^WebGL (\d)/.exec(Q)[1]),U=q>=1):Q.indexOf("OpenGL ES")!==-1&&(q=parseFloat(/^OpenGL ES (\d)/.exec(Q)[1]),U=q>=2);let J=null,it={};const ot=a.getParameter(a.SCISSOR_BOX),$t=a.getParameter(a.VIEWPORT),re=new ue().fromArray(ot),jt=new ue().fromArray($t);function $(L,lt,j,pt){const xt=new Uint8Array(4),et=a.createTexture();a.bindTexture(L,et),a.texParameteri(L,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(L,a.TEXTURE_MAG_FILTER,a.NEAREST);for(let Ot=0;Ot<j;Ot++)L===a.TEXTURE_3D||L===a.TEXTURE_2D_ARRAY?a.texImage3D(lt,0,a.RGBA,1,1,pt,0,a.RGBA,a.UNSIGNED_BYTE,xt):a.texImage2D(lt+Ot,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,xt);return et}const rt={};rt[a.TEXTURE_2D]=$(a.TEXTURE_2D,a.TEXTURE_2D,1),rt[a.TEXTURE_CUBE_MAP]=$(a.TEXTURE_CUBE_MAP,a.TEXTURE_CUBE_MAP_POSITIVE_X,6),rt[a.TEXTURE_2D_ARRAY]=$(a.TEXTURE_2D_ARRAY,a.TEXTURE_2D_ARRAY,1,1),rt[a.TEXTURE_3D]=$(a.TEXTURE_3D,a.TEXTURE_3D,1,1),s.setClear(0,0,0,1),r.setClear(1),o.setClear(0),nt(a.DEPTH_TEST),r.setFunc(Jo),Te(!1),Re(vg),nt(a.CULL_FACE),Vt(Bs);function nt(L){h[L]!==!0&&(a.enable(L),h[L]=!0)}function z(L){h[L]!==!1&&(a.disable(L),h[L]=!1)}function It(L,lt){return d[L]!==lt?(a.bindFramebuffer(L,lt),d[L]=lt,L===a.DRAW_FRAMEBUFFER&&(d[a.FRAMEBUFFER]=lt),L===a.FRAMEBUFFER&&(d[a.DRAW_FRAMEBUFFER]=lt),!0):!1}function Ut(L,lt){let j=p,pt=!1;if(L){j=f.get(lt),j===void 0&&(j=[],f.set(lt,j));const xt=L.textures;if(j.length!==xt.length||j[0]!==a.COLOR_ATTACHMENT0){for(let et=0,Ot=xt.length;et<Ot;et++)j[et]=a.COLOR_ATTACHMENT0+et;j.length=xt.length,pt=!0}}else j[0]!==a.BACK&&(j[0]=a.BACK,pt=!0);pt&&a.drawBuffers(j)}function Lt(L){return v!==L?(a.useProgram(L),v=L,!0):!1}const _t={[ha]:a.FUNC_ADD,[Nb]:a.FUNC_SUBTRACT,[kb]:a.FUNC_REVERSE_SUBTRACT};_t[Fb]=a.MIN,_t[Ub]=a.MAX;const Ht={[Nc]:a.ZERO,[ol]:a.ONE,[zb]:a.SRC_COLOR,[Zf]:a.SRC_ALPHA,[Xb]:a.SRC_ALPHA_SATURATE,[Vb]:a.DST_COLOR,[Hb]:a.DST_ALPHA,[Bb]:a.ONE_MINUS_SRC_COLOR,[cl]:a.ONE_MINUS_SRC_ALPHA,[Wb]:a.ONE_MINUS_DST_COLOR,[Gb]:a.ONE_MINUS_DST_ALPHA,[Yb]:a.CONSTANT_COLOR,[qb]:a.ONE_MINUS_CONSTANT_COLOR,[$b]:a.CONSTANT_ALPHA,[Kb]:a.ONE_MINUS_CONSTANT_ALPHA};function Vt(L,lt,j,pt,xt,et,Ot,Tt,hi,Ge){if(L===Bs){m===!0&&(z(a.BLEND),m=!1);return}if(m===!1&&(nt(a.BLEND),m=!0),L!==xl){if(L!==g||Ge!==I){if((b!==ha||x!==ha)&&(a.blendEquation(a.FUNC_ADD),b=ha,x=ha),Ge)switch(L){case Vr:a.blendFuncSeparate(a.ONE,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA);break;case Pi:a.blendFunc(a.ONE,a.ONE);break;case Mg:a.blendFuncSeparate(a.ZERO,a.ONE_MINUS_SRC_COLOR,a.ZERO,a.ONE);break;case yg:a.blendFuncSeparate(a.DST_COLOR,a.ONE_MINUS_SRC_ALPHA,a.ZERO,a.ONE);break;default:qt("WebGLState: Invalid blending: ",L);break}else switch(L){case Vr:a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA);break;case Pi:a.blendFuncSeparate(a.SRC_ALPHA,a.ONE,a.ONE,a.ONE);break;case Mg:qt("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case yg:qt("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:qt("WebGLState: Invalid blending: ",L);break}S=null,M=null,_=null,E=null,y.set(0,0,0),T=0,g=L,I=Ge}return}xt=xt||lt,et=et||j,Ot=Ot||pt,(lt!==b||xt!==x)&&(a.blendEquationSeparate(_t[lt],_t[xt]),b=lt,x=xt),(j!==S||pt!==M||et!==_||Ot!==E)&&(a.blendFuncSeparate(Ht[j],Ht[pt],Ht[et],Ht[Ot]),S=j,M=pt,_=et,E=Ot),(Tt.equals(y)===!1||hi!==T)&&(a.blendColor(Tt.r,Tt.g,Tt.b,hi),y.copy(Tt),T=hi),g=L,I=!1}function Wt(L,lt){L.side===bn?z(a.CULL_FACE):nt(a.CULL_FACE);let j=L.side===Qe;lt&&(j=!j),Te(j),L.blending===Vr&&L.transparent===!1?Vt(Bs):Vt(L.blending,L.blendEquation,L.blendSrc,L.blendDst,L.blendEquationAlpha,L.blendSrcAlpha,L.blendDstAlpha,L.blendColor,L.blendAlpha,L.premultipliedAlpha),r.setFunc(L.depthFunc),r.setTest(L.depthTest),r.setMask(L.depthWrite),s.setMask(L.colorWrite);const pt=L.stencilWrite;o.setTest(pt),pt&&(o.setMask(L.stencilWriteMask),o.setFunc(L.stencilFunc,L.stencilRef,L.stencilFuncMask),o.setOp(L.stencilFail,L.stencilZFail,L.stencilZPass)),ei(L.polygonOffset,L.polygonOffsetFactor,L.polygonOffsetUnits),L.alphaToCoverage===!0?nt(a.SAMPLE_ALPHA_TO_COVERAGE):z(a.SAMPLE_ALPHA_TO_COVERAGE)}function Te(L){C!==L&&(L?a.frontFace(a.CW):a.frontFace(a.CCW),C=L)}function Re(L){L!==Pb?(nt(a.CULL_FACE),L!==P&&(L===vg?a.cullFace(a.BACK):L===Ob?a.cullFace(a.FRONT):a.cullFace(a.FRONT_AND_BACK))):z(a.CULL_FACE),P=L}function ci(L){L!==B&&(U&&a.lineWidth(L),B=L)}function ei(L,lt,j){L?(nt(a.POLYGON_OFFSET_FILL),(W!==lt||O!==j)&&(W=lt,O=j,r.getReversed()&&(lt=-lt),a.polygonOffset(lt,j))):z(a.POLYGON_OFFSET_FILL)}function li(L){L?nt(a.SCISSOR_TEST):z(a.SCISSOR_TEST)}function wi(L){L===void 0&&(L=a.TEXTURE0+H-1),J!==L&&(a.activeTexture(L),J=L)}function N(L,lt,j){j===void 0&&(J===null?j=a.TEXTURE0+H-1:j=J);let pt=it[j];pt===void 0&&(pt={type:void 0,texture:void 0},it[j]=pt),(pt.type!==L||pt.texture!==lt)&&(J!==j&&(a.activeTexture(j),J=j),a.bindTexture(L,lt||rt[L]),pt.type=L,pt.texture=lt)}function fn(){const L=it[J];L!==void 0&&L.type!==void 0&&(a.bindTexture(L.type,null),L.type=void 0,L.texture=void 0)}function De(){try{a.compressedTexImage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function D(){try{a.compressedTexImage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function w(){try{a.texSubImage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function F(){try{a.texSubImage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function X(){try{a.compressedTexSubImage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function K(){try{a.compressedTexSubImage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function ct(){try{a.texStorage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function ht(){try{a.texStorage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function Z(){try{a.texImage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function tt(){try{a.texImage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function dt(L){return u[L]!==void 0?u[L]:a.getParameter(L)}function Nt(L,lt){u[L]!==lt&&(a.pixelStorei(L,lt),u[L]=lt)}function gt(L){re.equals(L)===!1&&(a.scissor(L.x,L.y,L.z,L.w),re.copy(L))}function ft(L){jt.equals(L)===!1&&(a.viewport(L.x,L.y,L.z,L.w),jt.copy(L))}function Bt(L,lt){let j=l.get(lt);j===void 0&&(j=new WeakMap,l.set(lt,j));let pt=j.get(L);pt===void 0&&(pt=a.getUniformBlockIndex(lt,L.name),j.set(L,pt))}function Yt(L,lt){const pt=l.get(lt).get(L);c.get(lt)!==pt&&(a.uniformBlockBinding(lt,pt,L.__bindingPointIndex),c.set(lt,pt))}function ee(){a.disable(a.BLEND),a.disable(a.CULL_FACE),a.disable(a.DEPTH_TEST),a.disable(a.POLYGON_OFFSET_FILL),a.disable(a.SCISSOR_TEST),a.disable(a.STENCIL_TEST),a.disable(a.SAMPLE_ALPHA_TO_COVERAGE),a.blendEquation(a.FUNC_ADD),a.blendFunc(a.ONE,a.ZERO),a.blendFuncSeparate(a.ONE,a.ZERO,a.ONE,a.ZERO),a.blendColor(0,0,0,0),a.colorMask(!0,!0,!0,!0),a.clearColor(0,0,0,0),a.depthMask(!0),a.depthFunc(a.LESS),r.setReversed(!1),a.clearDepth(1),a.stencilMask(4294967295),a.stencilFunc(a.ALWAYS,0,4294967295),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),a.clearStencil(0),a.cullFace(a.BACK),a.frontFace(a.CCW),a.polygonOffset(0,0),a.activeTexture(a.TEXTURE0),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,null),a.bindFramebuffer(a.READ_FRAMEBUFFER,null),a.useProgram(null),a.lineWidth(1),a.scissor(0,0,a.canvas.width,a.canvas.height),a.viewport(0,0,a.canvas.width,a.canvas.height),a.pixelStorei(a.PACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,!1),a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,a.BROWSER_DEFAULT_WEBGL),a.pixelStorei(a.PACK_ROW_LENGTH,0),a.pixelStorei(a.PACK_SKIP_PIXELS,0),a.pixelStorei(a.PACK_SKIP_ROWS,0),a.pixelStorei(a.UNPACK_ROW_LENGTH,0),a.pixelStorei(a.UNPACK_IMAGE_HEIGHT,0),a.pixelStorei(a.UNPACK_SKIP_PIXELS,0),a.pixelStorei(a.UNPACK_SKIP_ROWS,0),a.pixelStorei(a.UNPACK_SKIP_IMAGES,0),h={},u={},J=null,it={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,b=null,S=null,M=null,x=null,_=null,E=null,y=new st(0,0,0),T=0,I=!1,C=null,P=null,B=null,W=null,O=null,re.set(0,0,a.canvas.width,a.canvas.height),jt.set(0,0,a.canvas.width,a.canvas.height),s.reset(),r.reset(),o.reset()}return{buffers:{color:s,depth:r,stencil:o},enable:nt,disable:z,bindFramebuffer:It,drawBuffers:Ut,useProgram:Lt,setBlending:Vt,setMaterial:Wt,setFlipSided:Te,setCullFace:Re,setLineWidth:ci,setPolygonOffset:ei,setScissorTest:li,activeTexture:wi,bindTexture:N,unbindTexture:fn,compressedTexImage2D:De,compressedTexImage3D:D,texImage2D:Z,texImage3D:tt,pixelStorei:Nt,getParameter:dt,updateUBOMapping:Bt,uniformBlockBinding:Yt,texStorage2D:ct,texStorage3D:ht,texSubImage2D:w,texSubImage3D:F,compressedTexSubImage2D:X,compressedTexSubImage3D:K,scissor:gt,viewport:ft,reset:ee}}function IA(a,t,e,i,n,s,r){const o=t.has("WEBGL_multisampled_render_to_texture")?t.get("WEBGL_multisampled_render_to_texture"):null,c=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),l=new bt,h=new WeakMap,u=new Set;let d;const f=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function v(D,w){return p?new OffscreenCanvas(D,w):dl("canvas")}function m(D,w,F){let X=1;const K=De(D);if((K.width>F||K.height>F)&&(X=F/Math.max(K.width,K.height)),X<1)if(typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&D instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&D instanceof ImageBitmap||typeof VideoFrame<"u"&&D instanceof VideoFrame){const ct=Math.floor(X*K.width),ht=Math.floor(X*K.height);d===void 0&&(d=v(ct,ht));const Z=w?v(ct,ht):d;return Z.width=ct,Z.height=ht,Z.getContext("2d").drawImage(D,0,0,ct,ht),Pt("WebGLRenderer: Texture has been resized from ("+K.width+"x"+K.height+") to ("+ct+"x"+ht+")."),Z}else return"data"in D&&Pt("WebGLRenderer: Image in DataTexture is too big ("+K.width+"x"+K.height+")."),D;return D}function g(D){return D.generateMipmaps}function b(D){a.generateMipmap(D)}function S(D){return D.isWebGLCubeRenderTarget?a.TEXTURE_CUBE_MAP:D.isWebGL3DRenderTarget?a.TEXTURE_3D:D.isWebGLArrayRenderTarget||D.isCompressedArrayTexture?a.TEXTURE_2D_ARRAY:a.TEXTURE_2D}function M(D,w,F,X,K,ct=!1){if(D!==null){if(a[D]!==void 0)return a[D];Pt("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+D+"'")}let ht;X&&(ht=t.get("EXT_texture_norm16"),ht||Pt("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let Z=w;if(w===a.RED&&(F===a.FLOAT&&(Z=a.R32F),F===a.HALF_FLOAT&&(Z=a.R16F),F===a.UNSIGNED_BYTE&&(Z=a.R8),F===a.UNSIGNED_SHORT&&ht&&(Z=ht.R16_EXT),F===a.SHORT&&ht&&(Z=ht.R16_SNORM_EXT)),w===a.RED_INTEGER&&(F===a.UNSIGNED_BYTE&&(Z=a.R8UI),F===a.UNSIGNED_SHORT&&(Z=a.R16UI),F===a.UNSIGNED_INT&&(Z=a.R32UI),F===a.BYTE&&(Z=a.R8I),F===a.SHORT&&(Z=a.R16I),F===a.INT&&(Z=a.R32I)),w===a.RG&&(F===a.FLOAT&&(Z=a.RG32F),F===a.HALF_FLOAT&&(Z=a.RG16F),F===a.UNSIGNED_BYTE&&(Z=a.RG8),F===a.UNSIGNED_SHORT&&ht&&(Z=ht.RG16_EXT),F===a.SHORT&&ht&&(Z=ht.RG16_SNORM_EXT)),w===a.RG_INTEGER&&(F===a.UNSIGNED_BYTE&&(Z=a.RG8UI),F===a.UNSIGNED_SHORT&&(Z=a.RG16UI),F===a.UNSIGNED_INT&&(Z=a.RG32UI),F===a.BYTE&&(Z=a.RG8I),F===a.SHORT&&(Z=a.RG16I),F===a.INT&&(Z=a.RG32I)),w===a.RGB_INTEGER&&(F===a.UNSIGNED_BYTE&&(Z=a.RGB8UI),F===a.UNSIGNED_SHORT&&(Z=a.RGB16UI),F===a.UNSIGNED_INT&&(Z=a.RGB32UI),F===a.BYTE&&(Z=a.RGB8I),F===a.SHORT&&(Z=a.RGB16I),F===a.INT&&(Z=a.RGB32I)),w===a.RGBA_INTEGER&&(F===a.UNSIGNED_BYTE&&(Z=a.RGBA8UI),F===a.UNSIGNED_SHORT&&(Z=a.RGBA16UI),F===a.UNSIGNED_INT&&(Z=a.RGBA32UI),F===a.BYTE&&(Z=a.RGBA8I),F===a.SHORT&&(Z=a.RGBA16I),F===a.INT&&(Z=a.RGBA32I)),w===a.RGB&&(F===a.UNSIGNED_SHORT&&ht&&(Z=ht.RGB16_EXT),F===a.SHORT&&ht&&(Z=ht.RGB16_SNORM_EXT),F===a.UNSIGNED_INT_5_9_9_9_REV&&(Z=a.RGB9_E5),F===a.UNSIGNED_INT_10F_11F_11F_REV&&(Z=a.R11F_G11F_B10F)),w===a.RGBA){const tt=ct?Tu:me.getTransfer(K);F===a.FLOAT&&(Z=a.RGBA32F),F===a.HALF_FLOAT&&(Z=a.RGBA16F),F===a.UNSIGNED_BYTE&&(Z=tt===Pe?a.SRGB8_ALPHA8:a.RGBA8),F===a.UNSIGNED_SHORT&&ht&&(Z=ht.RGBA16_EXT),F===a.SHORT&&ht&&(Z=ht.RGBA16_SNORM_EXT),F===a.UNSIGNED_SHORT_4_4_4_4&&(Z=a.RGBA4),F===a.UNSIGNED_SHORT_5_5_5_1&&(Z=a.RGB5_A1)}return(Z===a.R16F||Z===a.R32F||Z===a.RG16F||Z===a.RG32F||Z===a.RGBA16F||Z===a.RGBA32F)&&t.get("EXT_color_buffer_float"),Z}function x(D,w){let F;return D?w===null||w===Kn||w===hl?F=a.DEPTH24_STENCIL8:w===ji?F=a.DEPTH32F_STENCIL8:w===ll&&(F=a.DEPTH24_STENCIL8,Pt("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):w===null||w===Kn||w===hl?F=a.DEPTH_COMPONENT24:w===ji?F=a.DEPTH_COMPONENT32F:w===ll&&(F=a.DEPTH_COMPONENT16),F}function _(D,w){return g(D)===!0||D.isFramebufferTexture&&D.minFilter!==Ue&&D.minFilter!==de?Math.log2(Math.max(w.width,w.height))+1:D.mipmaps!==void 0&&D.mipmaps.length>0?D.mipmaps.length:D.isCompressedTexture&&Array.isArray(D.image)?w.mipmaps.length:1}function E(D){const w=D.target;w.removeEventListener("dispose",E),T(w),w.isVideoTexture&&h.delete(w),w.isHTMLTexture&&u.delete(w)}function y(D){const w=D.target;w.removeEventListener("dispose",y),C(w)}function T(D){const w=i.get(D);if(w.__webglInit===void 0)return;const F=D.source,X=f.get(F);if(X){const K=X[w.__cacheKey];K.usedTimes--,K.usedTimes===0&&I(D),Object.keys(X).length===0&&f.delete(F)}i.remove(D)}function I(D){const w=i.get(D);a.deleteTexture(w.__webglTexture);const F=D.source,X=f.get(F);delete X[w.__cacheKey],r.memory.textures--}function C(D){const w=i.get(D);if(D.depthTexture&&(D.depthTexture.dispose(),i.remove(D.depthTexture)),D.isWebGLCubeRenderTarget)for(let X=0;X<6;X++){if(Array.isArray(w.__webglFramebuffer[X]))for(let K=0;K<w.__webglFramebuffer[X].length;K++)a.deleteFramebuffer(w.__webglFramebuffer[X][K]);else a.deleteFramebuffer(w.__webglFramebuffer[X]);w.__webglDepthbuffer&&a.deleteRenderbuffer(w.__webglDepthbuffer[X])}else{if(Array.isArray(w.__webglFramebuffer))for(let X=0;X<w.__webglFramebuffer.length;X++)a.deleteFramebuffer(w.__webglFramebuffer[X]);else a.deleteFramebuffer(w.__webglFramebuffer);if(w.__webglDepthbuffer&&a.deleteRenderbuffer(w.__webglDepthbuffer),w.__webglMultisampledFramebuffer&&a.deleteFramebuffer(w.__webglMultisampledFramebuffer),w.__webglColorRenderbuffer)for(let X=0;X<w.__webglColorRenderbuffer.length;X++)w.__webglColorRenderbuffer[X]&&a.deleteRenderbuffer(w.__webglColorRenderbuffer[X]);w.__webglDepthRenderbuffer&&a.deleteRenderbuffer(w.__webglDepthRenderbuffer)}const F=D.textures;for(let X=0,K=F.length;X<K;X++){const ct=i.get(F[X]);ct.__webglTexture&&(a.deleteTexture(ct.__webglTexture),r.memory.textures--),i.remove(F[X])}i.remove(D)}let P=0;function B(){P=0}function W(){return P}function O(D){P=D}function H(){const D=P;return D>=n.maxTextures&&Pt("WebGLTextures: Trying to use "+D+" texture units while this GPU supports only "+n.maxTextures),P+=1,D}function U(D){const w=[];return w.push(D.wrapS),w.push(D.wrapT),w.push(D.wrapR||0),w.push(D.magFilter),w.push(D.minFilter),w.push(D.anisotropy),w.push(D.internalFormat),w.push(D.format),w.push(D.type),w.push(D.generateMipmaps),w.push(D.premultiplyAlpha),w.push(D.flipY),w.push(D.unpackAlignment),w.push(D.colorSpace),w.join()}function q(D,w){const F=i.get(D);if(D.isVideoTexture&&N(D),D.isRenderTargetTexture===!1&&D.isExternalTexture!==!0&&D.version>0&&F.__version!==D.version){const X=D.image;if(X===null)Pt("WebGLRenderer: Texture marked for update but no image data found.");else if(X.complete===!1)Pt("WebGLRenderer: Texture marked for update but image is incomplete");else{z(F,D,w);return}}else D.isExternalTexture&&(F.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(a.TEXTURE_2D,F.__webglTexture,a.TEXTURE0+w)}function Q(D,w){const F=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&F.__version!==D.version){z(F,D,w);return}else D.isExternalTexture&&(F.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(a.TEXTURE_2D_ARRAY,F.__webglTexture,a.TEXTURE0+w)}function J(D,w){const F=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&F.__version!==D.version){z(F,D,w);return}e.bindTexture(a.TEXTURE_3D,F.__webglTexture,a.TEXTURE0+w)}function it(D,w){const F=i.get(D);if(D.isCubeDepthTexture!==!0&&D.version>0&&F.__version!==D.version){It(F,D,w);return}e.bindTexture(a.TEXTURE_CUBE_MAP,F.__webglTexture,a.TEXTURE0+w)}const ot={[Qo]:a.REPEAT,[Bi]:a.CLAMP_TO_EDGE,[s0]:a.MIRRORED_REPEAT},$t={[Ue]:a.NEAREST,[Qb]:a.NEAREST_MIPMAP_NEAREST,[kl]:a.NEAREST_MIPMAP_LINEAR,[de]:a.LINEAR,[wd]:a.LINEAR_MIPMAP_NEAREST,[Aa]:a.LINEAR_MIPMAP_LINEAR},re={[rS]:a.NEVER,[hS]:a.ALWAYS,[aS]:a.LESS,[kp]:a.LEQUAL,[oS]:a.EQUAL,[Fp]:a.GEQUAL,[cS]:a.GREATER,[lS]:a.NOTEQUAL};function jt(D,w){if(w.type===ji&&t.has("OES_texture_float_linear")===!1&&(w.magFilter===de||w.magFilter===wd||w.magFilter===kl||w.magFilter===Aa||w.minFilter===de||w.minFilter===wd||w.minFilter===kl||w.minFilter===Aa)&&Pt("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),a.texParameteri(D,a.TEXTURE_WRAP_S,ot[w.wrapS]),a.texParameteri(D,a.TEXTURE_WRAP_T,ot[w.wrapT]),(D===a.TEXTURE_3D||D===a.TEXTURE_2D_ARRAY)&&a.texParameteri(D,a.TEXTURE_WRAP_R,ot[w.wrapR]),a.texParameteri(D,a.TEXTURE_MAG_FILTER,$t[w.magFilter]),a.texParameteri(D,a.TEXTURE_MIN_FILTER,$t[w.minFilter]),w.compareFunction&&(a.texParameteri(D,a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE),a.texParameteri(D,a.TEXTURE_COMPARE_FUNC,re[w.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){if(w.magFilter===Ue||w.minFilter!==kl&&w.minFilter!==Aa||w.type===ji&&t.has("OES_texture_float_linear")===!1)return;if(w.anisotropy>1||i.get(w).__currentAnisotropy){const F=t.get("EXT_texture_filter_anisotropic");a.texParameterf(D,F.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(w.anisotropy,n.getMaxAnisotropy())),i.get(w).__currentAnisotropy=w.anisotropy}}}function $(D,w){let F=!1;D.__webglInit===void 0&&(D.__webglInit=!0,w.addEventListener("dispose",E));const X=w.source;let K=f.get(X);K===void 0&&(K={},f.set(X,K));const ct=U(w);if(ct!==D.__cacheKey){K[ct]===void 0&&(K[ct]={texture:a.createTexture(),usedTimes:0},r.memory.textures++,F=!0),K[ct].usedTimes++;const ht=K[D.__cacheKey];ht!==void 0&&(K[D.__cacheKey].usedTimes--,ht.usedTimes===0&&I(w)),D.__cacheKey=ct,D.__webglTexture=K[ct].texture}return F}function rt(D,w,F){return Math.floor(Math.floor(D/F)/w)}function nt(D,w,F,X){const ct=D.updateRanges;if(ct.length===0)e.texSubImage2D(a.TEXTURE_2D,0,0,0,w.width,w.height,F,X,w.data);else{ct.sort((Nt,gt)=>Nt.start-gt.start);let ht=0;for(let Nt=1;Nt<ct.length;Nt++){const gt=ct[ht],ft=ct[Nt],Bt=gt.start+gt.count,Yt=rt(ft.start,w.width,4),ee=rt(gt.start,w.width,4);ft.start<=Bt+1&&Yt===ee&&rt(ft.start+ft.count-1,w.width,4)===Yt?gt.count=Math.max(gt.count,ft.start+ft.count-gt.start):(++ht,ct[ht]=ft)}ct.length=ht+1;const Z=e.getParameter(a.UNPACK_ROW_LENGTH),tt=e.getParameter(a.UNPACK_SKIP_PIXELS),dt=e.getParameter(a.UNPACK_SKIP_ROWS);e.pixelStorei(a.UNPACK_ROW_LENGTH,w.width);for(let Nt=0,gt=ct.length;Nt<gt;Nt++){const ft=ct[Nt],Bt=Math.floor(ft.start/4),Yt=Math.ceil(ft.count/4),ee=Bt%w.width,L=Math.floor(Bt/w.width),lt=Yt,j=1;e.pixelStorei(a.UNPACK_SKIP_PIXELS,ee),e.pixelStorei(a.UNPACK_SKIP_ROWS,L),e.texSubImage2D(a.TEXTURE_2D,0,ee,L,lt,j,F,X,w.data)}D.clearUpdateRanges(),e.pixelStorei(a.UNPACK_ROW_LENGTH,Z),e.pixelStorei(a.UNPACK_SKIP_PIXELS,tt),e.pixelStorei(a.UNPACK_SKIP_ROWS,dt)}}function z(D,w,F){let X=a.TEXTURE_2D;(w.isDataArrayTexture||w.isCompressedArrayTexture)&&(X=a.TEXTURE_2D_ARRAY),w.isData3DTexture&&(X=a.TEXTURE_3D);const K=$(D,w),ct=w.source;e.bindTexture(X,D.__webglTexture,a.TEXTURE0+F);const ht=i.get(ct);if(ct.version!==ht.__version||K===!0){if(e.activeTexture(a.TEXTURE0+F),(typeof ImageBitmap<"u"&&w.image instanceof ImageBitmap)===!1){const j=me.getPrimaries(me.workingColorSpace),pt=w.colorSpace===Lr?null:me.getPrimaries(w.colorSpace),xt=w.colorSpace===Lr||j===pt?a.NONE:a.BROWSER_DEFAULT_WEBGL;e.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,w.flipY),e.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,w.premultiplyAlpha),e.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,xt)}e.pixelStorei(a.UNPACK_ALIGNMENT,w.unpackAlignment);let tt=m(w.image,!1,n.maxTextureSize);tt=fn(w,tt);const dt=s.convert(w.format,w.colorSpace),Nt=s.convert(w.type);let gt=M(w.internalFormat,dt,Nt,w.normalized,w.colorSpace,w.isVideoTexture);jt(X,w);let ft;const Bt=w.mipmaps,Yt=w.isVideoTexture!==!0,ee=ht.__version===void 0||K===!0,L=ct.dataReady,lt=_(w,tt);if(w.isDepthTexture)gt=x(w.format===Ta,w.type),ee&&(Yt?e.texStorage2D(a.TEXTURE_2D,1,gt,tt.width,tt.height):e.texImage2D(a.TEXTURE_2D,0,gt,tt.width,tt.height,0,dt,Nt,null));else if(w.isDataTexture)if(Bt.length>0){Yt&&ee&&e.texStorage2D(a.TEXTURE_2D,lt,gt,Bt[0].width,Bt[0].height);for(let j=0,pt=Bt.length;j<pt;j++)ft=Bt[j],Yt?L&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ft.width,ft.height,dt,Nt,ft.data):e.texImage2D(a.TEXTURE_2D,j,gt,ft.width,ft.height,0,dt,Nt,ft.data);w.generateMipmaps=!1}else Yt?(ee&&e.texStorage2D(a.TEXTURE_2D,lt,gt,tt.width,tt.height),L&&nt(w,tt,dt,Nt)):e.texImage2D(a.TEXTURE_2D,0,gt,tt.width,tt.height,0,dt,Nt,tt.data);else if(w.isCompressedTexture)if(w.isCompressedArrayTexture){Yt&&ee&&e.texStorage3D(a.TEXTURE_2D_ARRAY,lt,gt,Bt[0].width,Bt[0].height,tt.depth);for(let j=0,pt=Bt.length;j<pt;j++)if(ft=Bt[j],w.format!==Gi)if(dt!==null)if(Yt){if(L)if(w.layerUpdates.size>0){const xt=p1(ft.width,ft.height,w.format,w.type);for(const et of w.layerUpdates){const Ot=ft.data.subarray(et*xt/ft.data.BYTES_PER_ELEMENT,(et+1)*xt/ft.data.BYTES_PER_ELEMENT);e.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,et,ft.width,ft.height,1,dt,Ot)}w.clearLayerUpdates()}else e.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,0,ft.width,ft.height,tt.depth,dt,ft.data)}else e.compressedTexImage3D(a.TEXTURE_2D_ARRAY,j,gt,ft.width,ft.height,tt.depth,0,ft.data,0,0);else Pt("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Yt?L&&e.texSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,0,ft.width,ft.height,tt.depth,dt,Nt,ft.data):e.texImage3D(a.TEXTURE_2D_ARRAY,j,gt,ft.width,ft.height,tt.depth,0,dt,Nt,ft.data)}else{Yt&&ee&&e.texStorage2D(a.TEXTURE_2D,lt,gt,Bt[0].width,Bt[0].height);for(let j=0,pt=Bt.length;j<pt;j++)ft=Bt[j],w.format!==Gi?dt!==null?Yt?L&&e.compressedTexSubImage2D(a.TEXTURE_2D,j,0,0,ft.width,ft.height,dt,ft.data):e.compressedTexImage2D(a.TEXTURE_2D,j,gt,ft.width,ft.height,0,ft.data):Pt("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):Yt?L&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ft.width,ft.height,dt,Nt,ft.data):e.texImage2D(a.TEXTURE_2D,j,gt,ft.width,ft.height,0,dt,Nt,ft.data)}else if(w.isDataArrayTexture)if(Yt){if(ee&&e.texStorage3D(a.TEXTURE_2D_ARRAY,lt,gt,tt.width,tt.height,tt.depth),L)if(w.layerUpdates.size>0){const j=p1(tt.width,tt.height,w.format,w.type);for(const pt of w.layerUpdates){const xt=tt.data.subarray(pt*j/tt.data.BYTES_PER_ELEMENT,(pt+1)*j/tt.data.BYTES_PER_ELEMENT);e.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,pt,tt.width,tt.height,1,dt,Nt,xt)}w.clearLayerUpdates()}else e.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,0,tt.width,tt.height,tt.depth,dt,Nt,tt.data)}else e.texImage3D(a.TEXTURE_2D_ARRAY,0,gt,tt.width,tt.height,tt.depth,0,dt,Nt,tt.data);else if(w.isData3DTexture)Yt?(ee&&e.texStorage3D(a.TEXTURE_3D,lt,gt,tt.width,tt.height,tt.depth),L&&e.texSubImage3D(a.TEXTURE_3D,0,0,0,0,tt.width,tt.height,tt.depth,dt,Nt,tt.data)):e.texImage3D(a.TEXTURE_3D,0,gt,tt.width,tt.height,tt.depth,0,dt,Nt,tt.data);else if(w.isFramebufferTexture){if(ee)if(Yt)e.texStorage2D(a.TEXTURE_2D,lt,gt,tt.width,tt.height);else{let j=tt.width,pt=tt.height;for(let xt=0;xt<lt;xt++)e.texImage2D(a.TEXTURE_2D,xt,gt,j,pt,0,dt,Nt,null),j>>=1,pt>>=1}}else if(w.isHTMLTexture){if("texElementImage2D"in a){const j=a.canvas;if(j.hasAttribute("layoutsubtree")||j.setAttribute("layoutsubtree","true"),tt.parentNode!==j){j.appendChild(tt),u.add(w),j.onpaint=pt=>{const xt=pt.changedElements;for(const et of u)xt.includes(et.image)&&(et.needsUpdate=!0)},j.requestPaint();return}if(a.texElementImage2D.length===3)a.texElementImage2D(a.TEXTURE_2D,a.RGBA8,tt);else{const xt=a.RGBA,et=a.RGBA,Ot=a.UNSIGNED_BYTE;a.texElementImage2D(a.TEXTURE_2D,0,xt,et,Ot,tt)}a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE)}}else if(Bt.length>0){if(Yt&&ee){const j=De(Bt[0]);e.texStorage2D(a.TEXTURE_2D,lt,gt,j.width,j.height)}for(let j=0,pt=Bt.length;j<pt;j++)ft=Bt[j],Yt?L&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,dt,Nt,ft):e.texImage2D(a.TEXTURE_2D,j,gt,dt,Nt,ft);w.generateMipmaps=!1}else if(Yt){if(ee){const j=De(tt);e.texStorage2D(a.TEXTURE_2D,lt,gt,j.width,j.height)}L&&e.texSubImage2D(a.TEXTURE_2D,0,0,0,dt,Nt,tt)}else e.texImage2D(a.TEXTURE_2D,0,gt,dt,Nt,tt);g(w)&&b(X),ht.__version=ct.version,w.onUpdate&&w.onUpdate(w)}D.__version=w.version}function It(D,w,F){if(w.image.length!==6)return;const X=$(D,w),K=w.source;e.bindTexture(a.TEXTURE_CUBE_MAP,D.__webglTexture,a.TEXTURE0+F);const ct=i.get(K);if(K.version!==ct.__version||X===!0){e.activeTexture(a.TEXTURE0+F);const ht=me.getPrimaries(me.workingColorSpace),Z=w.colorSpace===Lr?null:me.getPrimaries(w.colorSpace),tt=w.colorSpace===Lr||ht===Z?a.NONE:a.BROWSER_DEFAULT_WEBGL;e.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,w.flipY),e.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,w.premultiplyAlpha),e.pixelStorei(a.UNPACK_ALIGNMENT,w.unpackAlignment),e.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,tt);const dt=w.isCompressedTexture||w.image[0].isCompressedTexture,Nt=w.image[0]&&w.image[0].isDataTexture,gt=[];for(let et=0;et<6;et++)!dt&&!Nt?gt[et]=m(w.image[et],!0,n.maxCubemapSize):gt[et]=Nt?w.image[et].image:w.image[et],gt[et]=fn(w,gt[et]);const ft=gt[0],Bt=s.convert(w.format,w.colorSpace),Yt=s.convert(w.type),ee=M(w.internalFormat,Bt,Yt,w.normalized,w.colorSpace),L=w.isVideoTexture!==!0,lt=ct.__version===void 0||X===!0,j=K.dataReady;let pt=_(w,ft);jt(a.TEXTURE_CUBE_MAP,w);let xt;if(dt){L&&lt&&e.texStorage2D(a.TEXTURE_CUBE_MAP,pt,ee,ft.width,ft.height);for(let et=0;et<6;et++){xt=gt[et].mipmaps;for(let Ot=0;Ot<xt.length;Ot++){const Tt=xt[Ot];w.format!==Gi?Bt!==null?L?j&&e.compressedTexSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot,0,0,Tt.width,Tt.height,Bt,Tt.data):e.compressedTexImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot,ee,Tt.width,Tt.height,0,Tt.data):Pt("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot,0,0,Tt.width,Tt.height,Bt,Yt,Tt.data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot,ee,Tt.width,Tt.height,0,Bt,Yt,Tt.data)}}}else{if(xt=w.mipmaps,L&&lt){xt.length>0&&pt++;const et=De(gt[0]);e.texStorage2D(a.TEXTURE_CUBE_MAP,pt,ee,et.width,et.height)}for(let et=0;et<6;et++)if(Nt){L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,0,0,gt[et].width,gt[et].height,Bt,Yt,gt[et].data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,ee,gt[et].width,gt[et].height,0,Bt,Yt,gt[et].data);for(let Ot=0;Ot<xt.length;Ot++){const hi=xt[Ot].image[et].image;L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot+1,0,0,hi.width,hi.height,Bt,Yt,hi.data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot+1,ee,hi.width,hi.height,0,Bt,Yt,hi.data)}}else{L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,0,0,Bt,Yt,gt[et]):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,ee,Bt,Yt,gt[et]);for(let Ot=0;Ot<xt.length;Ot++){const Tt=xt[Ot];L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot+1,0,0,Bt,Yt,Tt.image[et]):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot+1,ee,Bt,Yt,Tt.image[et])}}}g(w)&&b(a.TEXTURE_CUBE_MAP),ct.__version=K.version,w.onUpdate&&w.onUpdate(w)}D.__version=w.version}function Ut(D,w,F,X,K,ct){const ht=s.convert(F.format,F.colorSpace),Z=s.convert(F.type),tt=M(F.internalFormat,ht,Z,F.normalized,F.colorSpace),dt=i.get(w),Nt=i.get(F);if(Nt.__renderTarget=w,!dt.__hasExternalTextures){const gt=Math.max(1,w.width>>ct),ft=Math.max(1,w.height>>ct);K===a.TEXTURE_3D||K===a.TEXTURE_2D_ARRAY?e.texImage3D(K,ct,tt,gt,ft,w.depth,0,ht,Z,null):e.texImage2D(K,ct,tt,gt,ft,0,ht,Z,null)}e.bindFramebuffer(a.FRAMEBUFFER,D),wi(w)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,X,K,Nt.__webglTexture,0,li(w)):(K===a.TEXTURE_2D||K>=a.TEXTURE_CUBE_MAP_POSITIVE_X&&K<=a.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&a.framebufferTexture2D(a.FRAMEBUFFER,X,K,Nt.__webglTexture,ct),e.bindFramebuffer(a.FRAMEBUFFER,null)}function Lt(D,w,F){if(a.bindRenderbuffer(a.RENDERBUFFER,D),w.depthBuffer){const X=w.depthTexture,K=X&&X.isDepthTexture?X.type:null,ct=x(w.stencilBuffer,K),ht=w.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;wi(w)?o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER,li(w),ct,w.width,w.height):F?a.renderbufferStorageMultisample(a.RENDERBUFFER,li(w),ct,w.width,w.height):a.renderbufferStorage(a.RENDERBUFFER,ct,w.width,w.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,ht,a.RENDERBUFFER,D)}else{const X=w.textures;for(let K=0;K<X.length;K++){const ct=X[K],ht=s.convert(ct.format,ct.colorSpace),Z=s.convert(ct.type),tt=M(ct.internalFormat,ht,Z,ct.normalized,ct.colorSpace);wi(w)?o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER,li(w),tt,w.width,w.height):F?a.renderbufferStorageMultisample(a.RENDERBUFFER,li(w),tt,w.width,w.height):a.renderbufferStorage(a.RENDERBUFFER,tt,w.width,w.height)}}a.bindRenderbuffer(a.RENDERBUFFER,null)}function _t(D,w,F){const X=w.isWebGLCubeRenderTarget===!0;if(e.bindFramebuffer(a.FRAMEBUFFER,D),!(w.depthTexture&&w.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const K=i.get(w.depthTexture);if(K.__renderTarget=w,(!K.__webglTexture||w.depthTexture.image.width!==w.width||w.depthTexture.image.height!==w.height)&&(w.depthTexture.image.width=w.width,w.depthTexture.image.height=w.height,w.depthTexture.needsUpdate=!0),X){if(K.__webglInit===void 0&&(K.__webglInit=!0,w.depthTexture.addEventListener("dispose",E)),K.__webglTexture===void 0){K.__webglTexture=a.createTexture(),e.bindTexture(a.TEXTURE_CUBE_MAP,K.__webglTexture),jt(a.TEXTURE_CUBE_MAP,w.depthTexture);const dt=s.convert(w.depthTexture.format),Nt=s.convert(w.depthTexture.type);let gt;w.depthTexture.format===lr?gt=a.DEPTH_COMPONENT24:w.depthTexture.format===Ta&&(gt=a.DEPTH24_STENCIL8);for(let ft=0;ft<6;ft++)a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+ft,0,gt,w.width,w.height,0,dt,Nt,null)}}else q(w.depthTexture,0);const ct=K.__webglTexture,ht=li(w),Z=X?a.TEXTURE_CUBE_MAP_POSITIVE_X+F:a.TEXTURE_2D,tt=w.depthTexture.format===Ta?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;if(w.depthTexture.format===lr)wi(w)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,tt,Z,ct,0,ht):a.framebufferTexture2D(a.FRAMEBUFFER,tt,Z,ct,0);else if(w.depthTexture.format===Ta)wi(w)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,tt,Z,ct,0,ht):a.framebufferTexture2D(a.FRAMEBUFFER,tt,Z,ct,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function Ht(D){const w=i.get(D),F=D.isWebGLCubeRenderTarget===!0;if(w.__boundDepthTexture!==D.depthTexture){const X=D.depthTexture;if(w.__depthDisposeCallback&&w.__depthDisposeCallback(),X){const K=()=>{delete w.__boundDepthTexture,delete w.__depthDisposeCallback,X.removeEventListener("dispose",K)};X.addEventListener("dispose",K),w.__depthDisposeCallback=K}w.__boundDepthTexture=X}if(D.depthTexture&&!w.__autoAllocateDepthBuffer)if(F)for(let X=0;X<6;X++)_t(w.__webglFramebuffer[X],D,X);else{const X=D.texture.mipmaps;X&&X.length>0?_t(w.__webglFramebuffer[0],D,0):_t(w.__webglFramebuffer,D,0)}else if(F){w.__webglDepthbuffer=[];for(let X=0;X<6;X++)if(e.bindFramebuffer(a.FRAMEBUFFER,w.__webglFramebuffer[X]),w.__webglDepthbuffer[X]===void 0)w.__webglDepthbuffer[X]=a.createRenderbuffer(),Lt(w.__webglDepthbuffer[X],D,!1);else{const K=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ct=w.__webglDepthbuffer[X];a.bindRenderbuffer(a.RENDERBUFFER,ct),a.framebufferRenderbuffer(a.FRAMEBUFFER,K,a.RENDERBUFFER,ct)}}else{const X=D.texture.mipmaps;if(X&&X.length>0?e.bindFramebuffer(a.FRAMEBUFFER,w.__webglFramebuffer[0]):e.bindFramebuffer(a.FRAMEBUFFER,w.__webglFramebuffer),w.__webglDepthbuffer===void 0)w.__webglDepthbuffer=a.createRenderbuffer(),Lt(w.__webglDepthbuffer,D,!1);else{const K=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ct=w.__webglDepthbuffer;a.bindRenderbuffer(a.RENDERBUFFER,ct),a.framebufferRenderbuffer(a.FRAMEBUFFER,K,a.RENDERBUFFER,ct)}}e.bindFramebuffer(a.FRAMEBUFFER,null)}function Vt(D,w,F){const X=i.get(D);w!==void 0&&Ut(X.__webglFramebuffer,D,D.texture,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,0),F!==void 0&&Ht(D)}function Wt(D){const w=D.texture,F=i.get(D),X=i.get(w);D.addEventListener("dispose",y);const K=D.textures,ct=D.isWebGLCubeRenderTarget===!0,ht=K.length>1;if(ht||(X.__webglTexture===void 0&&(X.__webglTexture=a.createTexture()),X.__version=w.version,r.memory.textures++),ct){F.__webglFramebuffer=[];for(let Z=0;Z<6;Z++)if(w.mipmaps&&w.mipmaps.length>0){F.__webglFramebuffer[Z]=[];for(let tt=0;tt<w.mipmaps.length;tt++)F.__webglFramebuffer[Z][tt]=a.createFramebuffer()}else F.__webglFramebuffer[Z]=a.createFramebuffer()}else{if(w.mipmaps&&w.mipmaps.length>0){F.__webglFramebuffer=[];for(let Z=0;Z<w.mipmaps.length;Z++)F.__webglFramebuffer[Z]=a.createFramebuffer()}else F.__webglFramebuffer=a.createFramebuffer();if(ht)for(let Z=0,tt=K.length;Z<tt;Z++){const dt=i.get(K[Z]);dt.__webglTexture===void 0&&(dt.__webglTexture=a.createTexture(),r.memory.textures++)}if(D.samples>0&&wi(D)===!1){F.__webglMultisampledFramebuffer=a.createFramebuffer(),F.__webglColorRenderbuffer=[],e.bindFramebuffer(a.FRAMEBUFFER,F.__webglMultisampledFramebuffer);for(let Z=0;Z<K.length;Z++){const tt=K[Z];F.__webglColorRenderbuffer[Z]=a.createRenderbuffer(),a.bindRenderbuffer(a.RENDERBUFFER,F.__webglColorRenderbuffer[Z]);const dt=s.convert(tt.format,tt.colorSpace),Nt=s.convert(tt.type),gt=M(tt.internalFormat,dt,Nt,tt.normalized,tt.colorSpace,D.isXRRenderTarget===!0),ft=li(D);a.renderbufferStorageMultisample(a.RENDERBUFFER,ft,gt,D.width,D.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+Z,a.RENDERBUFFER,F.__webglColorRenderbuffer[Z])}a.bindRenderbuffer(a.RENDERBUFFER,null),D.depthBuffer&&(F.__webglDepthRenderbuffer=a.createRenderbuffer(),Lt(F.__webglDepthRenderbuffer,D,!0)),e.bindFramebuffer(a.FRAMEBUFFER,null)}}if(ct){e.bindTexture(a.TEXTURE_CUBE_MAP,X.__webglTexture),jt(a.TEXTURE_CUBE_MAP,w);for(let Z=0;Z<6;Z++)if(w.mipmaps&&w.mipmaps.length>0)for(let tt=0;tt<w.mipmaps.length;tt++)Ut(F.__webglFramebuffer[Z][tt],D,w,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+Z,tt);else Ut(F.__webglFramebuffer[Z],D,w,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0);g(w)&&b(a.TEXTURE_CUBE_MAP),e.unbindTexture()}else if(ht){for(let Z=0,tt=K.length;Z<tt;Z++){const dt=K[Z],Nt=i.get(dt);let gt=a.TEXTURE_2D;(D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(gt=D.isWebGL3DRenderTarget?a.TEXTURE_3D:a.TEXTURE_2D_ARRAY),e.bindTexture(gt,Nt.__webglTexture),jt(gt,dt),Ut(F.__webglFramebuffer,D,dt,a.COLOR_ATTACHMENT0+Z,gt,0),g(dt)&&b(gt)}e.unbindTexture()}else{let Z=a.TEXTURE_2D;if((D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(Z=D.isWebGL3DRenderTarget?a.TEXTURE_3D:a.TEXTURE_2D_ARRAY),e.bindTexture(Z,X.__webglTexture),jt(Z,w),w.mipmaps&&w.mipmaps.length>0)for(let tt=0;tt<w.mipmaps.length;tt++)Ut(F.__webglFramebuffer[tt],D,w,a.COLOR_ATTACHMENT0,Z,tt);else Ut(F.__webglFramebuffer,D,w,a.COLOR_ATTACHMENT0,Z,0);g(w)&&b(Z),e.unbindTexture()}D.depthBuffer&&Ht(D)}function Te(D){const w=D.textures;for(let F=0,X=w.length;F<X;F++){const K=w[F];if(g(K)){const ct=S(D),ht=i.get(K).__webglTexture;e.bindTexture(ct,ht),b(ct),e.unbindTexture()}}}const Re=[],ci=[];function ei(D){if(D.samples>0){if(wi(D)===!1){const w=D.textures,F=D.width,X=D.height;let K=a.COLOR_BUFFER_BIT;const ct=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ht=i.get(D),Z=w.length>1;if(Z)for(let dt=0;dt<w.length;dt++)e.bindFramebuffer(a.FRAMEBUFFER,ht.__webglMultisampledFramebuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+dt,a.RENDERBUFFER,null),e.bindFramebuffer(a.FRAMEBUFFER,ht.__webglFramebuffer),a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0+dt,a.TEXTURE_2D,null,0);e.bindFramebuffer(a.READ_FRAMEBUFFER,ht.__webglMultisampledFramebuffer);const tt=D.texture.mipmaps;tt&&tt.length>0?e.bindFramebuffer(a.DRAW_FRAMEBUFFER,ht.__webglFramebuffer[0]):e.bindFramebuffer(a.DRAW_FRAMEBUFFER,ht.__webglFramebuffer);for(let dt=0;dt<w.length;dt++){if(D.resolveDepthBuffer&&(D.depthBuffer&&(K|=a.DEPTH_BUFFER_BIT),D.stencilBuffer&&D.resolveStencilBuffer&&(K|=a.STENCIL_BUFFER_BIT)),Z){a.framebufferRenderbuffer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.RENDERBUFFER,ht.__webglColorRenderbuffer[dt]);const Nt=i.get(w[dt]).__webglTexture;a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,Nt,0)}a.blitFramebuffer(0,0,F,X,0,0,F,X,K,a.NEAREST),c===!0&&(Re.length=0,ci.length=0,Re.push(a.COLOR_ATTACHMENT0+dt),D.depthBuffer&&D.resolveDepthBuffer===!1&&(Re.push(ct),ci.push(ct),a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER,ci)),a.invalidateFramebuffer(a.READ_FRAMEBUFFER,Re))}if(e.bindFramebuffer(a.READ_FRAMEBUFFER,null),e.bindFramebuffer(a.DRAW_FRAMEBUFFER,null),Z)for(let dt=0;dt<w.length;dt++){e.bindFramebuffer(a.FRAMEBUFFER,ht.__webglMultisampledFramebuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+dt,a.RENDERBUFFER,ht.__webglColorRenderbuffer[dt]);const Nt=i.get(w[dt]).__webglTexture;e.bindFramebuffer(a.FRAMEBUFFER,ht.__webglFramebuffer),a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0+dt,a.TEXTURE_2D,Nt,0)}e.bindFramebuffer(a.DRAW_FRAMEBUFFER,ht.__webglMultisampledFramebuffer)}else if(D.depthBuffer&&D.resolveDepthBuffer===!1&&c){const w=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER,[w])}}}function li(D){return Math.min(n.maxSamples,D.samples)}function wi(D){const w=i.get(D);return D.samples>0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&w.__useRenderToTexture!==!1}function N(D){const w=r.render.frame;h.get(D)!==w&&(h.set(D,w),D.update())}function fn(D,w){const F=D.colorSpace,X=D.format,K=D.type;return D.isCompressedTexture===!0||D.isVideoTexture===!0||F!==Au&&F!==Lr&&(me.getTransfer(F)===Pe?(X!==Gi||K!==Ln)&&Pt("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):qt("WebGLTextures: Unsupported texture color space:",F)),w}function De(D){return typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement?(l.width=D.naturalWidth||D.width,l.height=D.naturalHeight||D.height):typeof VideoFrame<"u"&&D instanceof VideoFrame?(l.width=D.displayWidth,l.height=D.displayHeight):(l.width=D.width,l.height=D.height),l}this.allocateTextureUnit=H,this.resetTextureUnits=B,this.getTextureUnits=W,this.setTextureUnits=O,this.setTexture2D=q,this.setTexture2DArray=Q,this.setTexture3D=J,this.setTextureCube=it,this.rebindTextures=Vt,this.setupRenderTarget=Wt,this.updateRenderTargetMipmap=Te,this.updateMultisampleRenderTarget=ei,this.setupDepthRenderbuffer=Ht,this.setupFrameBufferTexture=Ut,this.useMultisampledRTT=wi,this.isReversedDepthBuffer=function(){return e.buffers.depth.getReversed()}}function CA(a,t){function e(i,n=Lr){let s;const r=me.getTransfer(n);if(i===Ln)return a.UNSIGNED_BYTE;if(i===Ip)return a.UNSIGNED_SHORT_4_4_4_4;if(i===Cp)return a.UNSIGNED_SHORT_5_5_5_1;if(i===VM)return a.UNSIGNED_INT_5_9_9_9_REV;if(i===WM)return a.UNSIGNED_INT_10F_11F_11F_REV;if(i===HM)return a.BYTE;if(i===GM)return a.SHORT;if(i===ll)return a.UNSIGNED_SHORT;if(i===Dp)return a.INT;if(i===Kn)return a.UNSIGNED_INT;if(i===ji)return a.FLOAT;if(i===qe)return a.HALF_FLOAT;if(i===XM)return a.ALPHA;if(i===YM)return a.RGB;if(i===Gi)return a.RGBA;if(i===lr)return a.DEPTH_COMPONENT;if(i===Ta)return a.DEPTH_STENCIL;if(i===tc)return a.RED;if(i===Pp)return a.RED_INTEGER;if(i===Ha)return a.RG;if(i===Op)return a.RG_INTEGER;if(i===Lp)return a.RGBA_INTEGER;if(i===Gh||i===Vh||i===Wh||i===Xh)if(r===Pe)if(s=t.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(i===Gh)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===Vh)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Wh)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Xh)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=t.get("WEBGL_compressed_texture_s3tc"),s!==null){if(i===Gh)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===Vh)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Wh)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Xh)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===r0||i===a0||i===o0||i===c0)if(s=t.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(i===r0)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===a0)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===o0)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===c0)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===l0||i===h0||i===u0||i===d0||i===f0||i===bu||i===p0)if(s=t.get("WEBGL_compressed_texture_etc"),s!==null){if(i===l0||i===h0)return r===Pe?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===u0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===d0)return s.COMPRESSED_R11_EAC;if(i===f0)return s.COMPRESSED_SIGNED_R11_EAC;if(i===bu)return s.COMPRESSED_RG11_EAC;if(i===p0)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===m0||i===g0||i===v0||i===M0||i===y0||i===x0||i===b0||i===S0||i===w0||i===_0||i===E0||i===A0||i===T0||i===R0)if(s=t.get("WEBGL_compressed_texture_astc"),s!==null){if(i===m0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===g0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===v0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===M0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===y0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===x0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===b0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===S0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===w0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===_0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===E0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===A0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===T0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===R0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===D0||i===I0||i===C0)if(s=t.get("EXT_texture_compression_bptc"),s!==null){if(i===D0)return r===Pe?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===I0)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===C0)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===P0||i===O0||i===Su||i===L0)if(s=t.get("EXT_texture_compression_rgtc"),s!==null){if(i===P0)return s.COMPRESSED_RED_RGTC1_EXT;if(i===O0)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===Su)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===L0)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===hl?a.UNSIGNED_INT_24_8:a[i]!==void 0?a[i]:null}return{convert:e}}const PA=`
6274
+ }`,AA=[new R(1,0,0),new R(-1,0,0),new R(0,1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1)],TA=[new R(0,-1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1),new R(0,-1,0),new R(0,-1,0)],k1=new ne,_c=new R,af=new R;function RA(a,t,e){let i=new Vp;const n=new bt,s=new bt,r=new ue,o=new dw,c=new fw,l={},h=e.maxTextureSize,u={[Xr]:Qe,[Qe]:Xr,[bn]:bn},d=new Me({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new bt},radius:{value:4}},vertexShader:_A,fragmentShader:EA}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const p=new ae;p.setAttribute("position",new te(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const v=new At(p,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Xc;let g=this.type;this.render=function(_,E,y){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||_.length===0)return;this.type===Lb&&(Pt("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=Xc);const T=a.getRenderTarget(),I=a.getActiveCubeFace(),C=a.getActiveMipmapLevel(),P=a.state;P.setBlending(Bs),P.buffers.depth.getReversed()===!0?P.buffers.color.setClear(0,0,0,0):P.buffers.color.setClear(1,1,1,1),P.buffers.depth.setTest(!0),P.setScissorTest(!1);const B=g!==this.type;B&&E.traverse(function(W){W.material&&(Array.isArray(W.material)?W.material.forEach(O=>O.needsUpdate=!0):W.material.needsUpdate=!0)});for(let W=0,O=_.length;W<O;W++){const H=_[W],U=H.shadow;if(U===void 0){Pt("WebGLShadowMap:",H,"has no shadow.");continue}if(U.autoUpdate===!1&&U.needsUpdate===!1)continue;n.copy(U.mapSize);const q=U.getFrameExtents();n.multiply(q),s.copy(U.mapSize),(n.x>h||n.y>h)&&(n.x>h&&(s.x=Math.floor(h/q.x),n.x=s.x*q.x,U.mapSize.x=s.x),n.y>h&&(s.y=Math.floor(h/q.y),n.y=s.y*q.y,U.mapSize.y=s.y));const Q=a.state.buffers.depth.getReversed();if(U.camera._reversedDepth=Q,U.map===null||B===!0){if(U.map!==null&&(U.map.depthTexture!==null&&(U.map.depthTexture.dispose(),U.map.depthTexture=null),U.map.dispose()),this.type===Lc){if(H.isPointLight){Pt("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}U.map=new oi(n.x,n.y,{format:Ha,type:qe,minFilter:de,magFilter:de,generateMipmaps:!1}),U.map.texture.name=H.name+".shadowMap",U.map.depthTexture=new Yr(n.x,n.y,ji),U.map.depthTexture.name=H.name+".shadowMapDepth",U.map.depthTexture.format=lr,U.map.depthTexture.compareFunction=null,U.map.depthTexture.minFilter=Ue,U.map.depthTexture.magFilter=Ue}else H.isPointLight?(U.map=new fl(n.x),U.map.depthTexture=new aw(n.x,Kn)):(U.map=new oi(n.x,n.y),U.map.depthTexture=new Yr(n.x,n.y,Kn)),U.map.depthTexture.name=H.name+".shadowMap",U.map.depthTexture.format=lr,this.type===Xc?(U.map.depthTexture.compareFunction=Q?Fp:kp,U.map.depthTexture.minFilter=de,U.map.depthTexture.magFilter=de):(U.map.depthTexture.compareFunction=null,U.map.depthTexture.minFilter=Ue,U.map.depthTexture.magFilter=Ue);U.camera.updateProjectionMatrix()}const J=U.map.isWebGLCubeRenderTarget?6:1;for(let it=0;it<J;it++){if(U.map.isWebGLCubeRenderTarget)a.setRenderTarget(U.map,it),a.clear();else{it===0&&(a.setRenderTarget(U.map),a.clear());const ot=U.getViewport(it);r.set(s.x*ot.x,s.y*ot.y,s.x*ot.z,s.y*ot.w),P.viewport(r)}if(H.isPointLight){const ot=U.camera,$t=U.matrix,re=H.distance||ot.far;re!==ot.far&&(ot.far=re,ot.updateProjectionMatrix()),_c.setFromMatrixPosition(H.matrixWorld),ot.position.copy(_c),af.copy(ot.position),af.add(AA[it]),ot.up.copy(TA[it]),ot.lookAt(af),ot.updateMatrixWorld(),$t.makeTranslation(-_c.x,-_c.y,-_c.z),k1.multiplyMatrices(ot.projectionMatrix,ot.matrixWorldInverse),U._frustum.setFromProjectionMatrix(k1,ot.coordinateSystem,ot.reversedDepth)}else U.updateMatrices(H);i=U.getFrustum(),M(E,y,U.camera,H,this.type)}U.isPointLightShadow!==!0&&this.type===Lc&&b(U,y),U.needsUpdate=!1}g=this.type,m.needsUpdate=!1,a.setRenderTarget(T,I,C)};function b(_,E){const y=t.update(v);d.defines.VSM_SAMPLES!==_.blurSamples&&(d.defines.VSM_SAMPLES=_.blurSamples,f.defines.VSM_SAMPLES=_.blurSamples,d.needsUpdate=!0,f.needsUpdate=!0),_.mapPass===null&&(_.mapPass=new oi(n.x,n.y,{format:Ha,type:qe})),d.uniforms.shadow_pass.value=_.map.depthTexture,d.uniforms.resolution.value=_.mapSize,d.uniforms.radius.value=_.radius,a.setRenderTarget(_.mapPass),a.clear(),a.renderBufferDirect(E,null,y,d,v,null),f.uniforms.shadow_pass.value=_.mapPass.texture,f.uniforms.resolution.value=_.mapSize,f.uniforms.radius.value=_.radius,a.setRenderTarget(_.map),a.clear(),a.renderBufferDirect(E,null,y,f,v,null)}function S(_,E,y,T){let I=null;const C=y.isPointLight===!0?_.customDistanceMaterial:_.customDepthMaterial;if(C!==void 0)I=C;else if(I=y.isPointLight===!0?c:o,a.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||E.alphaToCoverage===!0){const P=I.uuid,B=E.uuid;let W=l[P];W===void 0&&(W={},l[P]=W);let O=W[B];O===void 0&&(O=I.clone(),W[B]=O,E.addEventListener("dispose",x)),I=O}if(I.visible=E.visible,I.wireframe=E.wireframe,T===Lc?I.side=E.shadowSide!==null?E.shadowSide:E.side:I.side=E.shadowSide!==null?E.shadowSide:u[E.side],I.alphaMap=E.alphaMap,I.alphaTest=E.alphaToCoverage===!0?.5:E.alphaTest,I.map=E.map,I.clipShadows=E.clipShadows,I.clippingPlanes=E.clippingPlanes,I.clipIntersection=E.clipIntersection,I.displacementMap=E.displacementMap,I.displacementScale=E.displacementScale,I.displacementBias=E.displacementBias,I.wireframeLinewidth=E.wireframeLinewidth,I.linewidth=E.linewidth,y.isPointLight===!0&&I.isMeshDistanceMaterial===!0){const P=a.properties.get(I);P.light=y}return I}function M(_,E,y,T,I){if(_.visible===!1)return;if(_.layers.test(E.layers)&&(_.isMesh||_.isLine||_.isPoints)&&(_.castShadow||_.receiveShadow&&I===Lc)&&(!_.frustumCulled||i.intersectsObject(_))){_.modelViewMatrix.multiplyMatrices(y.matrixWorldInverse,_.matrixWorld);const B=t.update(_),W=_.material;if(Array.isArray(W)){const O=B.groups;for(let H=0,U=O.length;H<U;H++){const q=O[H],Q=W[q.materialIndex];if(Q&&Q.visible){const J=S(_,Q,T,I);_.onBeforeShadow(a,_,E,y,B,J,q),a.renderBufferDirect(y,null,B,J,_,q),_.onAfterShadow(a,_,E,y,B,J,q)}}}else if(W.visible){const O=S(_,W,T,I);_.onBeforeShadow(a,_,E,y,B,O,null),a.renderBufferDirect(y,null,B,O,_,null),_.onAfterShadow(a,_,E,y,B,O,null)}}const P=_.children;for(let B=0,W=P.length;B<W;B++)M(P[B],E,y,T,I)}function x(_){_.target.removeEventListener("dispose",x);for(const y in l){const T=l[y],I=_.target.uuid;I in T&&(T[I].dispose(),delete T[I])}}}function DA(a,t){function e(){let L=!1;const lt=new ue;let j=null;const pt=new ue(0,0,0,0);return{setMask:function(xt){j!==xt&&!L&&(a.colorMask(xt,xt,xt,xt),j=xt)},setLocked:function(xt){L=xt},setClear:function(xt,et,Ot,Tt,hi){hi===!0&&(xt*=Tt,et*=Tt,Ot*=Tt),lt.set(xt,et,Ot,Tt),pt.equals(lt)===!1&&(a.clearColor(xt,et,Ot,Tt),pt.copy(lt))},reset:function(){L=!1,j=null,pt.set(-1,0,0,0)}}}function i(){let L=!1,lt=!1,j=null,pt=null,xt=null;return{setReversed:function(et){if(lt!==et){const Ot=t.get("EXT_clip_control");et?Ot.clipControlEXT(Ot.LOWER_LEFT_EXT,Ot.ZERO_TO_ONE_EXT):Ot.clipControlEXT(Ot.LOWER_LEFT_EXT,Ot.NEGATIVE_ONE_TO_ONE_EXT),lt=et;const Tt=xt;xt=null,this.setClear(Tt)}},getReversed:function(){return lt},setTest:function(et){et?nt(a.DEPTH_TEST):z(a.DEPTH_TEST)},setMask:function(et){j!==et&&!L&&(a.depthMask(et),j=et)},setFunc:function(et){if(lt&&(et=mS[et]),pt!==et){switch(et){case Jf:a.depthFunc(a.NEVER);break;case jf:a.depthFunc(a.ALWAYS);break;case Qf:a.depthFunc(a.LESS);break;case Jo:a.depthFunc(a.LEQUAL);break;case t0:a.depthFunc(a.EQUAL);break;case e0:a.depthFunc(a.GEQUAL);break;case i0:a.depthFunc(a.GREATER);break;case n0:a.depthFunc(a.NOTEQUAL);break;default:a.depthFunc(a.LEQUAL)}pt=et}},setLocked:function(et){L=et},setClear:function(et){xt!==et&&(xt=et,lt&&(et=1-et),a.clearDepth(et))},reset:function(){L=!1,j=null,pt=null,xt=null,lt=!1}}}function n(){let L=!1,lt=null,j=null,pt=null,xt=null,et=null,Ot=null,Tt=null,hi=null;return{setTest:function(Ge){L||(Ge?nt(a.STENCIL_TEST):z(a.STENCIL_TEST))},setMask:function(Ge){lt!==Ge&&!L&&(a.stencilMask(Ge),lt=Ge)},setFunc:function(Ge,gs,vs){(j!==Ge||pt!==gs||xt!==vs)&&(a.stencilFunc(Ge,gs,vs),j=Ge,pt=gs,xt=vs)},setOp:function(Ge,gs,vs){(et!==Ge||Ot!==gs||Tt!==vs)&&(a.stencilOp(Ge,gs,vs),et=Ge,Ot=gs,Tt=vs)},setLocked:function(Ge){L=Ge},setClear:function(Ge){hi!==Ge&&(a.clearStencil(Ge),hi=Ge)},reset:function(){L=!1,lt=null,j=null,pt=null,xt=null,et=null,Ot=null,Tt=null,hi=null}}}const s=new e,r=new i,o=new n,c=new WeakMap,l=new WeakMap;let h={},u={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,b=null,S=null,M=null,x=null,_=null,E=null,y=new st(0,0,0),T=0,I=!1,C=null,P=null,B=null,W=null,O=null;const H=a.getParameter(a.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let U=!1,q=0;const Q=a.getParameter(a.VERSION);Q.indexOf("WebGL")!==-1?(q=parseFloat(/^WebGL (\d)/.exec(Q)[1]),U=q>=1):Q.indexOf("OpenGL ES")!==-1&&(q=parseFloat(/^OpenGL ES (\d)/.exec(Q)[1]),U=q>=2);let J=null,it={};const ot=a.getParameter(a.SCISSOR_BOX),$t=a.getParameter(a.VIEWPORT),re=new ue().fromArray(ot),jt=new ue().fromArray($t);function $(L,lt,j,pt){const xt=new Uint8Array(4),et=a.createTexture();a.bindTexture(L,et),a.texParameteri(L,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(L,a.TEXTURE_MAG_FILTER,a.NEAREST);for(let Ot=0;Ot<j;Ot++)L===a.TEXTURE_3D||L===a.TEXTURE_2D_ARRAY?a.texImage3D(lt,0,a.RGBA,1,1,pt,0,a.RGBA,a.UNSIGNED_BYTE,xt):a.texImage2D(lt+Ot,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,xt);return et}const rt={};rt[a.TEXTURE_2D]=$(a.TEXTURE_2D,a.TEXTURE_2D,1),rt[a.TEXTURE_CUBE_MAP]=$(a.TEXTURE_CUBE_MAP,a.TEXTURE_CUBE_MAP_POSITIVE_X,6),rt[a.TEXTURE_2D_ARRAY]=$(a.TEXTURE_2D_ARRAY,a.TEXTURE_2D_ARRAY,1,1),rt[a.TEXTURE_3D]=$(a.TEXTURE_3D,a.TEXTURE_3D,1,1),s.setClear(0,0,0,1),r.setClear(1),o.setClear(0),nt(a.DEPTH_TEST),r.setFunc(Jo),Te(!1),Re(vg),nt(a.CULL_FACE),Vt(Bs);function nt(L){h[L]!==!0&&(a.enable(L),h[L]=!0)}function z(L){h[L]!==!1&&(a.disable(L),h[L]=!1)}function It(L,lt){return d[L]!==lt?(a.bindFramebuffer(L,lt),d[L]=lt,L===a.DRAW_FRAMEBUFFER&&(d[a.FRAMEBUFFER]=lt),L===a.FRAMEBUFFER&&(d[a.DRAW_FRAMEBUFFER]=lt),!0):!1}function Ut(L,lt){let j=p,pt=!1;if(L){j=f.get(lt),j===void 0&&(j=[],f.set(lt,j));const xt=L.textures;if(j.length!==xt.length||j[0]!==a.COLOR_ATTACHMENT0){for(let et=0,Ot=xt.length;et<Ot;et++)j[et]=a.COLOR_ATTACHMENT0+et;j.length=xt.length,pt=!0}}else j[0]!==a.BACK&&(j[0]=a.BACK,pt=!0);pt&&a.drawBuffers(j)}function Lt(L){return v!==L?(a.useProgram(L),v=L,!0):!1}const _t={[ha]:a.FUNC_ADD,[Nb]:a.FUNC_SUBTRACT,[kb]:a.FUNC_REVERSE_SUBTRACT};_t[Fb]=a.MIN,_t[Ub]=a.MAX;const Ht={[Nc]:a.ZERO,[ol]:a.ONE,[zb]:a.SRC_COLOR,[Zf]:a.SRC_ALPHA,[Xb]:a.SRC_ALPHA_SATURATE,[Vb]:a.DST_COLOR,[Hb]:a.DST_ALPHA,[Bb]:a.ONE_MINUS_SRC_COLOR,[cl]:a.ONE_MINUS_SRC_ALPHA,[Wb]:a.ONE_MINUS_DST_COLOR,[Gb]:a.ONE_MINUS_DST_ALPHA,[Yb]:a.CONSTANT_COLOR,[qb]:a.ONE_MINUS_CONSTANT_COLOR,[$b]:a.CONSTANT_ALPHA,[Kb]:a.ONE_MINUS_CONSTANT_ALPHA};function Vt(L,lt,j,pt,xt,et,Ot,Tt,hi,Ge){if(L===Bs){m===!0&&(z(a.BLEND),m=!1);return}if(m===!1&&(nt(a.BLEND),m=!0),L!==xl){if(L!==g||Ge!==I){if((b!==ha||x!==ha)&&(a.blendEquation(a.FUNC_ADD),b=ha,x=ha),Ge)switch(L){case Vr:a.blendFuncSeparate(a.ONE,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA);break;case Ti:a.blendFunc(a.ONE,a.ONE);break;case Mg:a.blendFuncSeparate(a.ZERO,a.ONE_MINUS_SRC_COLOR,a.ZERO,a.ONE);break;case yg:a.blendFuncSeparate(a.DST_COLOR,a.ONE_MINUS_SRC_ALPHA,a.ZERO,a.ONE);break;default:qt("WebGLState: Invalid blending: ",L);break}else switch(L){case Vr:a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA);break;case Ti:a.blendFuncSeparate(a.SRC_ALPHA,a.ONE,a.ONE,a.ONE);break;case Mg:qt("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case yg:qt("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:qt("WebGLState: Invalid blending: ",L);break}S=null,M=null,_=null,E=null,y.set(0,0,0),T=0,g=L,I=Ge}return}xt=xt||lt,et=et||j,Ot=Ot||pt,(lt!==b||xt!==x)&&(a.blendEquationSeparate(_t[lt],_t[xt]),b=lt,x=xt),(j!==S||pt!==M||et!==_||Ot!==E)&&(a.blendFuncSeparate(Ht[j],Ht[pt],Ht[et],Ht[Ot]),S=j,M=pt,_=et,E=Ot),(Tt.equals(y)===!1||hi!==T)&&(a.blendColor(Tt.r,Tt.g,Tt.b,hi),y.copy(Tt),T=hi),g=L,I=!1}function Wt(L,lt){L.side===bn?z(a.CULL_FACE):nt(a.CULL_FACE);let j=L.side===Qe;lt&&(j=!j),Te(j),L.blending===Vr&&L.transparent===!1?Vt(Bs):Vt(L.blending,L.blendEquation,L.blendSrc,L.blendDst,L.blendEquationAlpha,L.blendSrcAlpha,L.blendDstAlpha,L.blendColor,L.blendAlpha,L.premultipliedAlpha),r.setFunc(L.depthFunc),r.setTest(L.depthTest),r.setMask(L.depthWrite),s.setMask(L.colorWrite);const pt=L.stencilWrite;o.setTest(pt),pt&&(o.setMask(L.stencilWriteMask),o.setFunc(L.stencilFunc,L.stencilRef,L.stencilFuncMask),o.setOp(L.stencilFail,L.stencilZFail,L.stencilZPass)),ei(L.polygonOffset,L.polygonOffsetFactor,L.polygonOffsetUnits),L.alphaToCoverage===!0?nt(a.SAMPLE_ALPHA_TO_COVERAGE):z(a.SAMPLE_ALPHA_TO_COVERAGE)}function Te(L){C!==L&&(L?a.frontFace(a.CW):a.frontFace(a.CCW),C=L)}function Re(L){L!==Pb?(nt(a.CULL_FACE),L!==P&&(L===vg?a.cullFace(a.BACK):L===Ob?a.cullFace(a.FRONT):a.cullFace(a.FRONT_AND_BACK))):z(a.CULL_FACE),P=L}function ci(L){L!==B&&(U&&a.lineWidth(L),B=L)}function ei(L,lt,j){L?(nt(a.POLYGON_OFFSET_FILL),(W!==lt||O!==j)&&(W=lt,O=j,r.getReversed()&&(lt=-lt),a.polygonOffset(lt,j))):z(a.POLYGON_OFFSET_FILL)}function li(L){L?nt(a.SCISSOR_TEST):z(a.SCISSOR_TEST)}function wi(L){L===void 0&&(L=a.TEXTURE0+H-1),J!==L&&(a.activeTexture(L),J=L)}function N(L,lt,j){j===void 0&&(J===null?j=a.TEXTURE0+H-1:j=J);let pt=it[j];pt===void 0&&(pt={type:void 0,texture:void 0},it[j]=pt),(pt.type!==L||pt.texture!==lt)&&(J!==j&&(a.activeTexture(j),J=j),a.bindTexture(L,lt||rt[L]),pt.type=L,pt.texture=lt)}function fn(){const L=it[J];L!==void 0&&L.type!==void 0&&(a.bindTexture(L.type,null),L.type=void 0,L.texture=void 0)}function De(){try{a.compressedTexImage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function D(){try{a.compressedTexImage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function w(){try{a.texSubImage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function F(){try{a.texSubImage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function X(){try{a.compressedTexSubImage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function K(){try{a.compressedTexSubImage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function ct(){try{a.texStorage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function ht(){try{a.texStorage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function Z(){try{a.texImage2D(...arguments)}catch(L){qt("WebGLState:",L)}}function tt(){try{a.texImage3D(...arguments)}catch(L){qt("WebGLState:",L)}}function dt(L){return u[L]!==void 0?u[L]:a.getParameter(L)}function Nt(L,lt){u[L]!==lt&&(a.pixelStorei(L,lt),u[L]=lt)}function gt(L){re.equals(L)===!1&&(a.scissor(L.x,L.y,L.z,L.w),re.copy(L))}function ft(L){jt.equals(L)===!1&&(a.viewport(L.x,L.y,L.z,L.w),jt.copy(L))}function Bt(L,lt){let j=l.get(lt);j===void 0&&(j=new WeakMap,l.set(lt,j));let pt=j.get(L);pt===void 0&&(pt=a.getUniformBlockIndex(lt,L.name),j.set(L,pt))}function Yt(L,lt){const pt=l.get(lt).get(L);c.get(lt)!==pt&&(a.uniformBlockBinding(lt,pt,L.__bindingPointIndex),c.set(lt,pt))}function ee(){a.disable(a.BLEND),a.disable(a.CULL_FACE),a.disable(a.DEPTH_TEST),a.disable(a.POLYGON_OFFSET_FILL),a.disable(a.SCISSOR_TEST),a.disable(a.STENCIL_TEST),a.disable(a.SAMPLE_ALPHA_TO_COVERAGE),a.blendEquation(a.FUNC_ADD),a.blendFunc(a.ONE,a.ZERO),a.blendFuncSeparate(a.ONE,a.ZERO,a.ONE,a.ZERO),a.blendColor(0,0,0,0),a.colorMask(!0,!0,!0,!0),a.clearColor(0,0,0,0),a.depthMask(!0),a.depthFunc(a.LESS),r.setReversed(!1),a.clearDepth(1),a.stencilMask(4294967295),a.stencilFunc(a.ALWAYS,0,4294967295),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),a.clearStencil(0),a.cullFace(a.BACK),a.frontFace(a.CCW),a.polygonOffset(0,0),a.activeTexture(a.TEXTURE0),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,null),a.bindFramebuffer(a.READ_FRAMEBUFFER,null),a.useProgram(null),a.lineWidth(1),a.scissor(0,0,a.canvas.width,a.canvas.height),a.viewport(0,0,a.canvas.width,a.canvas.height),a.pixelStorei(a.PACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_ALIGNMENT,4),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,!1),a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,a.BROWSER_DEFAULT_WEBGL),a.pixelStorei(a.PACK_ROW_LENGTH,0),a.pixelStorei(a.PACK_SKIP_PIXELS,0),a.pixelStorei(a.PACK_SKIP_ROWS,0),a.pixelStorei(a.UNPACK_ROW_LENGTH,0),a.pixelStorei(a.UNPACK_IMAGE_HEIGHT,0),a.pixelStorei(a.UNPACK_SKIP_PIXELS,0),a.pixelStorei(a.UNPACK_SKIP_ROWS,0),a.pixelStorei(a.UNPACK_SKIP_IMAGES,0),h={},u={},J=null,it={},d={},f=new WeakMap,p=[],v=null,m=!1,g=null,b=null,S=null,M=null,x=null,_=null,E=null,y=new st(0,0,0),T=0,I=!1,C=null,P=null,B=null,W=null,O=null,re.set(0,0,a.canvas.width,a.canvas.height),jt.set(0,0,a.canvas.width,a.canvas.height),s.reset(),r.reset(),o.reset()}return{buffers:{color:s,depth:r,stencil:o},enable:nt,disable:z,bindFramebuffer:It,drawBuffers:Ut,useProgram:Lt,setBlending:Vt,setMaterial:Wt,setFlipSided:Te,setCullFace:Re,setLineWidth:ci,setPolygonOffset:ei,setScissorTest:li,activeTexture:wi,bindTexture:N,unbindTexture:fn,compressedTexImage2D:De,compressedTexImage3D:D,texImage2D:Z,texImage3D:tt,pixelStorei:Nt,getParameter:dt,updateUBOMapping:Bt,uniformBlockBinding:Yt,texStorage2D:ct,texStorage3D:ht,texSubImage2D:w,texSubImage3D:F,compressedTexSubImage2D:X,compressedTexSubImage3D:K,scissor:gt,viewport:ft,reset:ee}}function IA(a,t,e,i,n,s,r){const o=t.has("WEBGL_multisampled_render_to_texture")?t.get("WEBGL_multisampled_render_to_texture"):null,c=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),l=new bt,h=new WeakMap,u=new Set;let d;const f=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function v(D,w){return p?new OffscreenCanvas(D,w):dl("canvas")}function m(D,w,F){let X=1;const K=De(D);if((K.width>F||K.height>F)&&(X=F/Math.max(K.width,K.height)),X<1)if(typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&D instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&D instanceof ImageBitmap||typeof VideoFrame<"u"&&D instanceof VideoFrame){const ct=Math.floor(X*K.width),ht=Math.floor(X*K.height);d===void 0&&(d=v(ct,ht));const Z=w?v(ct,ht):d;return Z.width=ct,Z.height=ht,Z.getContext("2d").drawImage(D,0,0,ct,ht),Pt("WebGLRenderer: Texture has been resized from ("+K.width+"x"+K.height+") to ("+ct+"x"+ht+")."),Z}else return"data"in D&&Pt("WebGLRenderer: Image in DataTexture is too big ("+K.width+"x"+K.height+")."),D;return D}function g(D){return D.generateMipmaps}function b(D){a.generateMipmap(D)}function S(D){return D.isWebGLCubeRenderTarget?a.TEXTURE_CUBE_MAP:D.isWebGL3DRenderTarget?a.TEXTURE_3D:D.isWebGLArrayRenderTarget||D.isCompressedArrayTexture?a.TEXTURE_2D_ARRAY:a.TEXTURE_2D}function M(D,w,F,X,K,ct=!1){if(D!==null){if(a[D]!==void 0)return a[D];Pt("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+D+"'")}let ht;X&&(ht=t.get("EXT_texture_norm16"),ht||Pt("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let Z=w;if(w===a.RED&&(F===a.FLOAT&&(Z=a.R32F),F===a.HALF_FLOAT&&(Z=a.R16F),F===a.UNSIGNED_BYTE&&(Z=a.R8),F===a.UNSIGNED_SHORT&&ht&&(Z=ht.R16_EXT),F===a.SHORT&&ht&&(Z=ht.R16_SNORM_EXT)),w===a.RED_INTEGER&&(F===a.UNSIGNED_BYTE&&(Z=a.R8UI),F===a.UNSIGNED_SHORT&&(Z=a.R16UI),F===a.UNSIGNED_INT&&(Z=a.R32UI),F===a.BYTE&&(Z=a.R8I),F===a.SHORT&&(Z=a.R16I),F===a.INT&&(Z=a.R32I)),w===a.RG&&(F===a.FLOAT&&(Z=a.RG32F),F===a.HALF_FLOAT&&(Z=a.RG16F),F===a.UNSIGNED_BYTE&&(Z=a.RG8),F===a.UNSIGNED_SHORT&&ht&&(Z=ht.RG16_EXT),F===a.SHORT&&ht&&(Z=ht.RG16_SNORM_EXT)),w===a.RG_INTEGER&&(F===a.UNSIGNED_BYTE&&(Z=a.RG8UI),F===a.UNSIGNED_SHORT&&(Z=a.RG16UI),F===a.UNSIGNED_INT&&(Z=a.RG32UI),F===a.BYTE&&(Z=a.RG8I),F===a.SHORT&&(Z=a.RG16I),F===a.INT&&(Z=a.RG32I)),w===a.RGB_INTEGER&&(F===a.UNSIGNED_BYTE&&(Z=a.RGB8UI),F===a.UNSIGNED_SHORT&&(Z=a.RGB16UI),F===a.UNSIGNED_INT&&(Z=a.RGB32UI),F===a.BYTE&&(Z=a.RGB8I),F===a.SHORT&&(Z=a.RGB16I),F===a.INT&&(Z=a.RGB32I)),w===a.RGBA_INTEGER&&(F===a.UNSIGNED_BYTE&&(Z=a.RGBA8UI),F===a.UNSIGNED_SHORT&&(Z=a.RGBA16UI),F===a.UNSIGNED_INT&&(Z=a.RGBA32UI),F===a.BYTE&&(Z=a.RGBA8I),F===a.SHORT&&(Z=a.RGBA16I),F===a.INT&&(Z=a.RGBA32I)),w===a.RGB&&(F===a.UNSIGNED_SHORT&&ht&&(Z=ht.RGB16_EXT),F===a.SHORT&&ht&&(Z=ht.RGB16_SNORM_EXT),F===a.UNSIGNED_INT_5_9_9_9_REV&&(Z=a.RGB9_E5),F===a.UNSIGNED_INT_10F_11F_11F_REV&&(Z=a.R11F_G11F_B10F)),w===a.RGBA){const tt=ct?Tu:me.getTransfer(K);F===a.FLOAT&&(Z=a.RGBA32F),F===a.HALF_FLOAT&&(Z=a.RGBA16F),F===a.UNSIGNED_BYTE&&(Z=tt===Pe?a.SRGB8_ALPHA8:a.RGBA8),F===a.UNSIGNED_SHORT&&ht&&(Z=ht.RGBA16_EXT),F===a.SHORT&&ht&&(Z=ht.RGBA16_SNORM_EXT),F===a.UNSIGNED_SHORT_4_4_4_4&&(Z=a.RGBA4),F===a.UNSIGNED_SHORT_5_5_5_1&&(Z=a.RGB5_A1)}return(Z===a.R16F||Z===a.R32F||Z===a.RG16F||Z===a.RG32F||Z===a.RGBA16F||Z===a.RGBA32F)&&t.get("EXT_color_buffer_float"),Z}function x(D,w){let F;return D?w===null||w===Kn||w===hl?F=a.DEPTH24_STENCIL8:w===ji?F=a.DEPTH32F_STENCIL8:w===ll&&(F=a.DEPTH24_STENCIL8,Pt("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):w===null||w===Kn||w===hl?F=a.DEPTH_COMPONENT24:w===ji?F=a.DEPTH_COMPONENT32F:w===ll&&(F=a.DEPTH_COMPONENT16),F}function _(D,w){return g(D)===!0||D.isFramebufferTexture&&D.minFilter!==Ue&&D.minFilter!==de?Math.log2(Math.max(w.width,w.height))+1:D.mipmaps!==void 0&&D.mipmaps.length>0?D.mipmaps.length:D.isCompressedTexture&&Array.isArray(D.image)?w.mipmaps.length:1}function E(D){const w=D.target;w.removeEventListener("dispose",E),T(w),w.isVideoTexture&&h.delete(w),w.isHTMLTexture&&u.delete(w)}function y(D){const w=D.target;w.removeEventListener("dispose",y),C(w)}function T(D){const w=i.get(D);if(w.__webglInit===void 0)return;const F=D.source,X=f.get(F);if(X){const K=X[w.__cacheKey];K.usedTimes--,K.usedTimes===0&&I(D),Object.keys(X).length===0&&f.delete(F)}i.remove(D)}function I(D){const w=i.get(D);a.deleteTexture(w.__webglTexture);const F=D.source,X=f.get(F);delete X[w.__cacheKey],r.memory.textures--}function C(D){const w=i.get(D);if(D.depthTexture&&(D.depthTexture.dispose(),i.remove(D.depthTexture)),D.isWebGLCubeRenderTarget)for(let X=0;X<6;X++){if(Array.isArray(w.__webglFramebuffer[X]))for(let K=0;K<w.__webglFramebuffer[X].length;K++)a.deleteFramebuffer(w.__webglFramebuffer[X][K]);else a.deleteFramebuffer(w.__webglFramebuffer[X]);w.__webglDepthbuffer&&a.deleteRenderbuffer(w.__webglDepthbuffer[X])}else{if(Array.isArray(w.__webglFramebuffer))for(let X=0;X<w.__webglFramebuffer.length;X++)a.deleteFramebuffer(w.__webglFramebuffer[X]);else a.deleteFramebuffer(w.__webglFramebuffer);if(w.__webglDepthbuffer&&a.deleteRenderbuffer(w.__webglDepthbuffer),w.__webglMultisampledFramebuffer&&a.deleteFramebuffer(w.__webglMultisampledFramebuffer),w.__webglColorRenderbuffer)for(let X=0;X<w.__webglColorRenderbuffer.length;X++)w.__webglColorRenderbuffer[X]&&a.deleteRenderbuffer(w.__webglColorRenderbuffer[X]);w.__webglDepthRenderbuffer&&a.deleteRenderbuffer(w.__webglDepthRenderbuffer)}const F=D.textures;for(let X=0,K=F.length;X<K;X++){const ct=i.get(F[X]);ct.__webglTexture&&(a.deleteTexture(ct.__webglTexture),r.memory.textures--),i.remove(F[X])}i.remove(D)}let P=0;function B(){P=0}function W(){return P}function O(D){P=D}function H(){const D=P;return D>=n.maxTextures&&Pt("WebGLTextures: Trying to use "+D+" texture units while this GPU supports only "+n.maxTextures),P+=1,D}function U(D){const w=[];return w.push(D.wrapS),w.push(D.wrapT),w.push(D.wrapR||0),w.push(D.magFilter),w.push(D.minFilter),w.push(D.anisotropy),w.push(D.internalFormat),w.push(D.format),w.push(D.type),w.push(D.generateMipmaps),w.push(D.premultiplyAlpha),w.push(D.flipY),w.push(D.unpackAlignment),w.push(D.colorSpace),w.join()}function q(D,w){const F=i.get(D);if(D.isVideoTexture&&N(D),D.isRenderTargetTexture===!1&&D.isExternalTexture!==!0&&D.version>0&&F.__version!==D.version){const X=D.image;if(X===null)Pt("WebGLRenderer: Texture marked for update but no image data found.");else if(X.complete===!1)Pt("WebGLRenderer: Texture marked for update but image is incomplete");else{z(F,D,w);return}}else D.isExternalTexture&&(F.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(a.TEXTURE_2D,F.__webglTexture,a.TEXTURE0+w)}function Q(D,w){const F=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&F.__version!==D.version){z(F,D,w);return}else D.isExternalTexture&&(F.__webglTexture=D.sourceTexture?D.sourceTexture:null);e.bindTexture(a.TEXTURE_2D_ARRAY,F.__webglTexture,a.TEXTURE0+w)}function J(D,w){const F=i.get(D);if(D.isRenderTargetTexture===!1&&D.version>0&&F.__version!==D.version){z(F,D,w);return}e.bindTexture(a.TEXTURE_3D,F.__webglTexture,a.TEXTURE0+w)}function it(D,w){const F=i.get(D);if(D.isCubeDepthTexture!==!0&&D.version>0&&F.__version!==D.version){It(F,D,w);return}e.bindTexture(a.TEXTURE_CUBE_MAP,F.__webglTexture,a.TEXTURE0+w)}const ot={[Qo]:a.REPEAT,[Bi]:a.CLAMP_TO_EDGE,[s0]:a.MIRRORED_REPEAT},$t={[Ue]:a.NEAREST,[Qb]:a.NEAREST_MIPMAP_NEAREST,[kl]:a.NEAREST_MIPMAP_LINEAR,[de]:a.LINEAR,[wd]:a.LINEAR_MIPMAP_NEAREST,[Aa]:a.LINEAR_MIPMAP_LINEAR},re={[rS]:a.NEVER,[hS]:a.ALWAYS,[aS]:a.LESS,[kp]:a.LEQUAL,[oS]:a.EQUAL,[Fp]:a.GEQUAL,[cS]:a.GREATER,[lS]:a.NOTEQUAL};function jt(D,w){if(w.type===ji&&t.has("OES_texture_float_linear")===!1&&(w.magFilter===de||w.magFilter===wd||w.magFilter===kl||w.magFilter===Aa||w.minFilter===de||w.minFilter===wd||w.minFilter===kl||w.minFilter===Aa)&&Pt("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),a.texParameteri(D,a.TEXTURE_WRAP_S,ot[w.wrapS]),a.texParameteri(D,a.TEXTURE_WRAP_T,ot[w.wrapT]),(D===a.TEXTURE_3D||D===a.TEXTURE_2D_ARRAY)&&a.texParameteri(D,a.TEXTURE_WRAP_R,ot[w.wrapR]),a.texParameteri(D,a.TEXTURE_MAG_FILTER,$t[w.magFilter]),a.texParameteri(D,a.TEXTURE_MIN_FILTER,$t[w.minFilter]),w.compareFunction&&(a.texParameteri(D,a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE),a.texParameteri(D,a.TEXTURE_COMPARE_FUNC,re[w.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){if(w.magFilter===Ue||w.minFilter!==kl&&w.minFilter!==Aa||w.type===ji&&t.has("OES_texture_float_linear")===!1)return;if(w.anisotropy>1||i.get(w).__currentAnisotropy){const F=t.get("EXT_texture_filter_anisotropic");a.texParameterf(D,F.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(w.anisotropy,n.getMaxAnisotropy())),i.get(w).__currentAnisotropy=w.anisotropy}}}function $(D,w){let F=!1;D.__webglInit===void 0&&(D.__webglInit=!0,w.addEventListener("dispose",E));const X=w.source;let K=f.get(X);K===void 0&&(K={},f.set(X,K));const ct=U(w);if(ct!==D.__cacheKey){K[ct]===void 0&&(K[ct]={texture:a.createTexture(),usedTimes:0},r.memory.textures++,F=!0),K[ct].usedTimes++;const ht=K[D.__cacheKey];ht!==void 0&&(K[D.__cacheKey].usedTimes--,ht.usedTimes===0&&I(w)),D.__cacheKey=ct,D.__webglTexture=K[ct].texture}return F}function rt(D,w,F){return Math.floor(Math.floor(D/F)/w)}function nt(D,w,F,X){const ct=D.updateRanges;if(ct.length===0)e.texSubImage2D(a.TEXTURE_2D,0,0,0,w.width,w.height,F,X,w.data);else{ct.sort((Nt,gt)=>Nt.start-gt.start);let ht=0;for(let Nt=1;Nt<ct.length;Nt++){const gt=ct[ht],ft=ct[Nt],Bt=gt.start+gt.count,Yt=rt(ft.start,w.width,4),ee=rt(gt.start,w.width,4);ft.start<=Bt+1&&Yt===ee&&rt(ft.start+ft.count-1,w.width,4)===Yt?gt.count=Math.max(gt.count,ft.start+ft.count-gt.start):(++ht,ct[ht]=ft)}ct.length=ht+1;const Z=e.getParameter(a.UNPACK_ROW_LENGTH),tt=e.getParameter(a.UNPACK_SKIP_PIXELS),dt=e.getParameter(a.UNPACK_SKIP_ROWS);e.pixelStorei(a.UNPACK_ROW_LENGTH,w.width);for(let Nt=0,gt=ct.length;Nt<gt;Nt++){const ft=ct[Nt],Bt=Math.floor(ft.start/4),Yt=Math.ceil(ft.count/4),ee=Bt%w.width,L=Math.floor(Bt/w.width),lt=Yt,j=1;e.pixelStorei(a.UNPACK_SKIP_PIXELS,ee),e.pixelStorei(a.UNPACK_SKIP_ROWS,L),e.texSubImage2D(a.TEXTURE_2D,0,ee,L,lt,j,F,X,w.data)}D.clearUpdateRanges(),e.pixelStorei(a.UNPACK_ROW_LENGTH,Z),e.pixelStorei(a.UNPACK_SKIP_PIXELS,tt),e.pixelStorei(a.UNPACK_SKIP_ROWS,dt)}}function z(D,w,F){let X=a.TEXTURE_2D;(w.isDataArrayTexture||w.isCompressedArrayTexture)&&(X=a.TEXTURE_2D_ARRAY),w.isData3DTexture&&(X=a.TEXTURE_3D);const K=$(D,w),ct=w.source;e.bindTexture(X,D.__webglTexture,a.TEXTURE0+F);const ht=i.get(ct);if(ct.version!==ht.__version||K===!0){if(e.activeTexture(a.TEXTURE0+F),(typeof ImageBitmap<"u"&&w.image instanceof ImageBitmap)===!1){const j=me.getPrimaries(me.workingColorSpace),pt=w.colorSpace===Lr?null:me.getPrimaries(w.colorSpace),xt=w.colorSpace===Lr||j===pt?a.NONE:a.BROWSER_DEFAULT_WEBGL;e.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,w.flipY),e.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,w.premultiplyAlpha),e.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,xt)}e.pixelStorei(a.UNPACK_ALIGNMENT,w.unpackAlignment);let tt=m(w.image,!1,n.maxTextureSize);tt=fn(w,tt);const dt=s.convert(w.format,w.colorSpace),Nt=s.convert(w.type);let gt=M(w.internalFormat,dt,Nt,w.normalized,w.colorSpace,w.isVideoTexture);jt(X,w);let ft;const Bt=w.mipmaps,Yt=w.isVideoTexture!==!0,ee=ht.__version===void 0||K===!0,L=ct.dataReady,lt=_(w,tt);if(w.isDepthTexture)gt=x(w.format===Ta,w.type),ee&&(Yt?e.texStorage2D(a.TEXTURE_2D,1,gt,tt.width,tt.height):e.texImage2D(a.TEXTURE_2D,0,gt,tt.width,tt.height,0,dt,Nt,null));else if(w.isDataTexture)if(Bt.length>0){Yt&&ee&&e.texStorage2D(a.TEXTURE_2D,lt,gt,Bt[0].width,Bt[0].height);for(let j=0,pt=Bt.length;j<pt;j++)ft=Bt[j],Yt?L&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ft.width,ft.height,dt,Nt,ft.data):e.texImage2D(a.TEXTURE_2D,j,gt,ft.width,ft.height,0,dt,Nt,ft.data);w.generateMipmaps=!1}else Yt?(ee&&e.texStorage2D(a.TEXTURE_2D,lt,gt,tt.width,tt.height),L&&nt(w,tt,dt,Nt)):e.texImage2D(a.TEXTURE_2D,0,gt,tt.width,tt.height,0,dt,Nt,tt.data);else if(w.isCompressedTexture)if(w.isCompressedArrayTexture){Yt&&ee&&e.texStorage3D(a.TEXTURE_2D_ARRAY,lt,gt,Bt[0].width,Bt[0].height,tt.depth);for(let j=0,pt=Bt.length;j<pt;j++)if(ft=Bt[j],w.format!==Gi)if(dt!==null)if(Yt){if(L)if(w.layerUpdates.size>0){const xt=p1(ft.width,ft.height,w.format,w.type);for(const et of w.layerUpdates){const Ot=ft.data.subarray(et*xt/ft.data.BYTES_PER_ELEMENT,(et+1)*xt/ft.data.BYTES_PER_ELEMENT);e.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,et,ft.width,ft.height,1,dt,Ot)}w.clearLayerUpdates()}else e.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,0,ft.width,ft.height,tt.depth,dt,ft.data)}else e.compressedTexImage3D(a.TEXTURE_2D_ARRAY,j,gt,ft.width,ft.height,tt.depth,0,ft.data,0,0);else Pt("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Yt?L&&e.texSubImage3D(a.TEXTURE_2D_ARRAY,j,0,0,0,ft.width,ft.height,tt.depth,dt,Nt,ft.data):e.texImage3D(a.TEXTURE_2D_ARRAY,j,gt,ft.width,ft.height,tt.depth,0,dt,Nt,ft.data)}else{Yt&&ee&&e.texStorage2D(a.TEXTURE_2D,lt,gt,Bt[0].width,Bt[0].height);for(let j=0,pt=Bt.length;j<pt;j++)ft=Bt[j],w.format!==Gi?dt!==null?Yt?L&&e.compressedTexSubImage2D(a.TEXTURE_2D,j,0,0,ft.width,ft.height,dt,ft.data):e.compressedTexImage2D(a.TEXTURE_2D,j,gt,ft.width,ft.height,0,ft.data):Pt("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):Yt?L&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,ft.width,ft.height,dt,Nt,ft.data):e.texImage2D(a.TEXTURE_2D,j,gt,ft.width,ft.height,0,dt,Nt,ft.data)}else if(w.isDataArrayTexture)if(Yt){if(ee&&e.texStorage3D(a.TEXTURE_2D_ARRAY,lt,gt,tt.width,tt.height,tt.depth),L)if(w.layerUpdates.size>0){const j=p1(tt.width,tt.height,w.format,w.type);for(const pt of w.layerUpdates){const xt=tt.data.subarray(pt*j/tt.data.BYTES_PER_ELEMENT,(pt+1)*j/tt.data.BYTES_PER_ELEMENT);e.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,pt,tt.width,tt.height,1,dt,Nt,xt)}w.clearLayerUpdates()}else e.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,0,tt.width,tt.height,tt.depth,dt,Nt,tt.data)}else e.texImage3D(a.TEXTURE_2D_ARRAY,0,gt,tt.width,tt.height,tt.depth,0,dt,Nt,tt.data);else if(w.isData3DTexture)Yt?(ee&&e.texStorage3D(a.TEXTURE_3D,lt,gt,tt.width,tt.height,tt.depth),L&&e.texSubImage3D(a.TEXTURE_3D,0,0,0,0,tt.width,tt.height,tt.depth,dt,Nt,tt.data)):e.texImage3D(a.TEXTURE_3D,0,gt,tt.width,tt.height,tt.depth,0,dt,Nt,tt.data);else if(w.isFramebufferTexture){if(ee)if(Yt)e.texStorage2D(a.TEXTURE_2D,lt,gt,tt.width,tt.height);else{let j=tt.width,pt=tt.height;for(let xt=0;xt<lt;xt++)e.texImage2D(a.TEXTURE_2D,xt,gt,j,pt,0,dt,Nt,null),j>>=1,pt>>=1}}else if(w.isHTMLTexture){if("texElementImage2D"in a){const j=a.canvas;if(j.hasAttribute("layoutsubtree")||j.setAttribute("layoutsubtree","true"),tt.parentNode!==j){j.appendChild(tt),u.add(w),j.onpaint=pt=>{const xt=pt.changedElements;for(const et of u)xt.includes(et.image)&&(et.needsUpdate=!0)},j.requestPaint();return}if(a.texElementImage2D.length===3)a.texElementImage2D(a.TEXTURE_2D,a.RGBA8,tt);else{const xt=a.RGBA,et=a.RGBA,Ot=a.UNSIGNED_BYTE;a.texElementImage2D(a.TEXTURE_2D,0,xt,et,Ot,tt)}a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE)}}else if(Bt.length>0){if(Yt&&ee){const j=De(Bt[0]);e.texStorage2D(a.TEXTURE_2D,lt,gt,j.width,j.height)}for(let j=0,pt=Bt.length;j<pt;j++)ft=Bt[j],Yt?L&&e.texSubImage2D(a.TEXTURE_2D,j,0,0,dt,Nt,ft):e.texImage2D(a.TEXTURE_2D,j,gt,dt,Nt,ft);w.generateMipmaps=!1}else if(Yt){if(ee){const j=De(tt);e.texStorage2D(a.TEXTURE_2D,lt,gt,j.width,j.height)}L&&e.texSubImage2D(a.TEXTURE_2D,0,0,0,dt,Nt,tt)}else e.texImage2D(a.TEXTURE_2D,0,gt,dt,Nt,tt);g(w)&&b(X),ht.__version=ct.version,w.onUpdate&&w.onUpdate(w)}D.__version=w.version}function It(D,w,F){if(w.image.length!==6)return;const X=$(D,w),K=w.source;e.bindTexture(a.TEXTURE_CUBE_MAP,D.__webglTexture,a.TEXTURE0+F);const ct=i.get(K);if(K.version!==ct.__version||X===!0){e.activeTexture(a.TEXTURE0+F);const ht=me.getPrimaries(me.workingColorSpace),Z=w.colorSpace===Lr?null:me.getPrimaries(w.colorSpace),tt=w.colorSpace===Lr||ht===Z?a.NONE:a.BROWSER_DEFAULT_WEBGL;e.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,w.flipY),e.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,w.premultiplyAlpha),e.pixelStorei(a.UNPACK_ALIGNMENT,w.unpackAlignment),e.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,tt);const dt=w.isCompressedTexture||w.image[0].isCompressedTexture,Nt=w.image[0]&&w.image[0].isDataTexture,gt=[];for(let et=0;et<6;et++)!dt&&!Nt?gt[et]=m(w.image[et],!0,n.maxCubemapSize):gt[et]=Nt?w.image[et].image:w.image[et],gt[et]=fn(w,gt[et]);const ft=gt[0],Bt=s.convert(w.format,w.colorSpace),Yt=s.convert(w.type),ee=M(w.internalFormat,Bt,Yt,w.normalized,w.colorSpace),L=w.isVideoTexture!==!0,lt=ct.__version===void 0||X===!0,j=K.dataReady;let pt=_(w,ft);jt(a.TEXTURE_CUBE_MAP,w);let xt;if(dt){L&&lt&&e.texStorage2D(a.TEXTURE_CUBE_MAP,pt,ee,ft.width,ft.height);for(let et=0;et<6;et++){xt=gt[et].mipmaps;for(let Ot=0;Ot<xt.length;Ot++){const Tt=xt[Ot];w.format!==Gi?Bt!==null?L?j&&e.compressedTexSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot,0,0,Tt.width,Tt.height,Bt,Tt.data):e.compressedTexImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot,ee,Tt.width,Tt.height,0,Tt.data):Pt("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot,0,0,Tt.width,Tt.height,Bt,Yt,Tt.data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot,ee,Tt.width,Tt.height,0,Bt,Yt,Tt.data)}}}else{if(xt=w.mipmaps,L&&lt){xt.length>0&&pt++;const et=De(gt[0]);e.texStorage2D(a.TEXTURE_CUBE_MAP,pt,ee,et.width,et.height)}for(let et=0;et<6;et++)if(Nt){L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,0,0,gt[et].width,gt[et].height,Bt,Yt,gt[et].data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,ee,gt[et].width,gt[et].height,0,Bt,Yt,gt[et].data);for(let Ot=0;Ot<xt.length;Ot++){const hi=xt[Ot].image[et].image;L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot+1,0,0,hi.width,hi.height,Bt,Yt,hi.data):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot+1,ee,hi.width,hi.height,0,Bt,Yt,hi.data)}}else{L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,0,0,Bt,Yt,gt[et]):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,0,ee,Bt,Yt,gt[et]);for(let Ot=0;Ot<xt.length;Ot++){const Tt=xt[Ot];L?j&&e.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot+1,0,0,Bt,Yt,Tt.image[et]):e.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+et,Ot+1,ee,Bt,Yt,Tt.image[et])}}}g(w)&&b(a.TEXTURE_CUBE_MAP),ct.__version=K.version,w.onUpdate&&w.onUpdate(w)}D.__version=w.version}function Ut(D,w,F,X,K,ct){const ht=s.convert(F.format,F.colorSpace),Z=s.convert(F.type),tt=M(F.internalFormat,ht,Z,F.normalized,F.colorSpace),dt=i.get(w),Nt=i.get(F);if(Nt.__renderTarget=w,!dt.__hasExternalTextures){const gt=Math.max(1,w.width>>ct),ft=Math.max(1,w.height>>ct);K===a.TEXTURE_3D||K===a.TEXTURE_2D_ARRAY?e.texImage3D(K,ct,tt,gt,ft,w.depth,0,ht,Z,null):e.texImage2D(K,ct,tt,gt,ft,0,ht,Z,null)}e.bindFramebuffer(a.FRAMEBUFFER,D),wi(w)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,X,K,Nt.__webglTexture,0,li(w)):(K===a.TEXTURE_2D||K>=a.TEXTURE_CUBE_MAP_POSITIVE_X&&K<=a.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&a.framebufferTexture2D(a.FRAMEBUFFER,X,K,Nt.__webglTexture,ct),e.bindFramebuffer(a.FRAMEBUFFER,null)}function Lt(D,w,F){if(a.bindRenderbuffer(a.RENDERBUFFER,D),w.depthBuffer){const X=w.depthTexture,K=X&&X.isDepthTexture?X.type:null,ct=x(w.stencilBuffer,K),ht=w.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;wi(w)?o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER,li(w),ct,w.width,w.height):F?a.renderbufferStorageMultisample(a.RENDERBUFFER,li(w),ct,w.width,w.height):a.renderbufferStorage(a.RENDERBUFFER,ct,w.width,w.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,ht,a.RENDERBUFFER,D)}else{const X=w.textures;for(let K=0;K<X.length;K++){const ct=X[K],ht=s.convert(ct.format,ct.colorSpace),Z=s.convert(ct.type),tt=M(ct.internalFormat,ht,Z,ct.normalized,ct.colorSpace);wi(w)?o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER,li(w),tt,w.width,w.height):F?a.renderbufferStorageMultisample(a.RENDERBUFFER,li(w),tt,w.width,w.height):a.renderbufferStorage(a.RENDERBUFFER,tt,w.width,w.height)}}a.bindRenderbuffer(a.RENDERBUFFER,null)}function _t(D,w,F){const X=w.isWebGLCubeRenderTarget===!0;if(e.bindFramebuffer(a.FRAMEBUFFER,D),!(w.depthTexture&&w.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const K=i.get(w.depthTexture);if(K.__renderTarget=w,(!K.__webglTexture||w.depthTexture.image.width!==w.width||w.depthTexture.image.height!==w.height)&&(w.depthTexture.image.width=w.width,w.depthTexture.image.height=w.height,w.depthTexture.needsUpdate=!0),X){if(K.__webglInit===void 0&&(K.__webglInit=!0,w.depthTexture.addEventListener("dispose",E)),K.__webglTexture===void 0){K.__webglTexture=a.createTexture(),e.bindTexture(a.TEXTURE_CUBE_MAP,K.__webglTexture),jt(a.TEXTURE_CUBE_MAP,w.depthTexture);const dt=s.convert(w.depthTexture.format),Nt=s.convert(w.depthTexture.type);let gt;w.depthTexture.format===lr?gt=a.DEPTH_COMPONENT24:w.depthTexture.format===Ta&&(gt=a.DEPTH24_STENCIL8);for(let ft=0;ft<6;ft++)a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+ft,0,gt,w.width,w.height,0,dt,Nt,null)}}else q(w.depthTexture,0);const ct=K.__webglTexture,ht=li(w),Z=X?a.TEXTURE_CUBE_MAP_POSITIVE_X+F:a.TEXTURE_2D,tt=w.depthTexture.format===Ta?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;if(w.depthTexture.format===lr)wi(w)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,tt,Z,ct,0,ht):a.framebufferTexture2D(a.FRAMEBUFFER,tt,Z,ct,0);else if(w.depthTexture.format===Ta)wi(w)?o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER,tt,Z,ct,0,ht):a.framebufferTexture2D(a.FRAMEBUFFER,tt,Z,ct,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function Ht(D){const w=i.get(D),F=D.isWebGLCubeRenderTarget===!0;if(w.__boundDepthTexture!==D.depthTexture){const X=D.depthTexture;if(w.__depthDisposeCallback&&w.__depthDisposeCallback(),X){const K=()=>{delete w.__boundDepthTexture,delete w.__depthDisposeCallback,X.removeEventListener("dispose",K)};X.addEventListener("dispose",K),w.__depthDisposeCallback=K}w.__boundDepthTexture=X}if(D.depthTexture&&!w.__autoAllocateDepthBuffer)if(F)for(let X=0;X<6;X++)_t(w.__webglFramebuffer[X],D,X);else{const X=D.texture.mipmaps;X&&X.length>0?_t(w.__webglFramebuffer[0],D,0):_t(w.__webglFramebuffer,D,0)}else if(F){w.__webglDepthbuffer=[];for(let X=0;X<6;X++)if(e.bindFramebuffer(a.FRAMEBUFFER,w.__webglFramebuffer[X]),w.__webglDepthbuffer[X]===void 0)w.__webglDepthbuffer[X]=a.createRenderbuffer(),Lt(w.__webglDepthbuffer[X],D,!1);else{const K=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ct=w.__webglDepthbuffer[X];a.bindRenderbuffer(a.RENDERBUFFER,ct),a.framebufferRenderbuffer(a.FRAMEBUFFER,K,a.RENDERBUFFER,ct)}}else{const X=D.texture.mipmaps;if(X&&X.length>0?e.bindFramebuffer(a.FRAMEBUFFER,w.__webglFramebuffer[0]):e.bindFramebuffer(a.FRAMEBUFFER,w.__webglFramebuffer),w.__webglDepthbuffer===void 0)w.__webglDepthbuffer=a.createRenderbuffer(),Lt(w.__webglDepthbuffer,D,!1);else{const K=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ct=w.__webglDepthbuffer;a.bindRenderbuffer(a.RENDERBUFFER,ct),a.framebufferRenderbuffer(a.FRAMEBUFFER,K,a.RENDERBUFFER,ct)}}e.bindFramebuffer(a.FRAMEBUFFER,null)}function Vt(D,w,F){const X=i.get(D);w!==void 0&&Ut(X.__webglFramebuffer,D,D.texture,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,0),F!==void 0&&Ht(D)}function Wt(D){const w=D.texture,F=i.get(D),X=i.get(w);D.addEventListener("dispose",y);const K=D.textures,ct=D.isWebGLCubeRenderTarget===!0,ht=K.length>1;if(ht||(X.__webglTexture===void 0&&(X.__webglTexture=a.createTexture()),X.__version=w.version,r.memory.textures++),ct){F.__webglFramebuffer=[];for(let Z=0;Z<6;Z++)if(w.mipmaps&&w.mipmaps.length>0){F.__webglFramebuffer[Z]=[];for(let tt=0;tt<w.mipmaps.length;tt++)F.__webglFramebuffer[Z][tt]=a.createFramebuffer()}else F.__webglFramebuffer[Z]=a.createFramebuffer()}else{if(w.mipmaps&&w.mipmaps.length>0){F.__webglFramebuffer=[];for(let Z=0;Z<w.mipmaps.length;Z++)F.__webglFramebuffer[Z]=a.createFramebuffer()}else F.__webglFramebuffer=a.createFramebuffer();if(ht)for(let Z=0,tt=K.length;Z<tt;Z++){const dt=i.get(K[Z]);dt.__webglTexture===void 0&&(dt.__webglTexture=a.createTexture(),r.memory.textures++)}if(D.samples>0&&wi(D)===!1){F.__webglMultisampledFramebuffer=a.createFramebuffer(),F.__webglColorRenderbuffer=[],e.bindFramebuffer(a.FRAMEBUFFER,F.__webglMultisampledFramebuffer);for(let Z=0;Z<K.length;Z++){const tt=K[Z];F.__webglColorRenderbuffer[Z]=a.createRenderbuffer(),a.bindRenderbuffer(a.RENDERBUFFER,F.__webglColorRenderbuffer[Z]);const dt=s.convert(tt.format,tt.colorSpace),Nt=s.convert(tt.type),gt=M(tt.internalFormat,dt,Nt,tt.normalized,tt.colorSpace,D.isXRRenderTarget===!0),ft=li(D);a.renderbufferStorageMultisample(a.RENDERBUFFER,ft,gt,D.width,D.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+Z,a.RENDERBUFFER,F.__webglColorRenderbuffer[Z])}a.bindRenderbuffer(a.RENDERBUFFER,null),D.depthBuffer&&(F.__webglDepthRenderbuffer=a.createRenderbuffer(),Lt(F.__webglDepthRenderbuffer,D,!0)),e.bindFramebuffer(a.FRAMEBUFFER,null)}}if(ct){e.bindTexture(a.TEXTURE_CUBE_MAP,X.__webglTexture),jt(a.TEXTURE_CUBE_MAP,w);for(let Z=0;Z<6;Z++)if(w.mipmaps&&w.mipmaps.length>0)for(let tt=0;tt<w.mipmaps.length;tt++)Ut(F.__webglFramebuffer[Z][tt],D,w,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+Z,tt);else Ut(F.__webglFramebuffer[Z],D,w,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+Z,0);g(w)&&b(a.TEXTURE_CUBE_MAP),e.unbindTexture()}else if(ht){for(let Z=0,tt=K.length;Z<tt;Z++){const dt=K[Z],Nt=i.get(dt);let gt=a.TEXTURE_2D;(D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(gt=D.isWebGL3DRenderTarget?a.TEXTURE_3D:a.TEXTURE_2D_ARRAY),e.bindTexture(gt,Nt.__webglTexture),jt(gt,dt),Ut(F.__webglFramebuffer,D,dt,a.COLOR_ATTACHMENT0+Z,gt,0),g(dt)&&b(gt)}e.unbindTexture()}else{let Z=a.TEXTURE_2D;if((D.isWebGL3DRenderTarget||D.isWebGLArrayRenderTarget)&&(Z=D.isWebGL3DRenderTarget?a.TEXTURE_3D:a.TEXTURE_2D_ARRAY),e.bindTexture(Z,X.__webglTexture),jt(Z,w),w.mipmaps&&w.mipmaps.length>0)for(let tt=0;tt<w.mipmaps.length;tt++)Ut(F.__webglFramebuffer[tt],D,w,a.COLOR_ATTACHMENT0,Z,tt);else Ut(F.__webglFramebuffer,D,w,a.COLOR_ATTACHMENT0,Z,0);g(w)&&b(Z),e.unbindTexture()}D.depthBuffer&&Ht(D)}function Te(D){const w=D.textures;for(let F=0,X=w.length;F<X;F++){const K=w[F];if(g(K)){const ct=S(D),ht=i.get(K).__webglTexture;e.bindTexture(ct,ht),b(ct),e.unbindTexture()}}}const Re=[],ci=[];function ei(D){if(D.samples>0){if(wi(D)===!1){const w=D.textures,F=D.width,X=D.height;let K=a.COLOR_BUFFER_BIT;const ct=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT,ht=i.get(D),Z=w.length>1;if(Z)for(let dt=0;dt<w.length;dt++)e.bindFramebuffer(a.FRAMEBUFFER,ht.__webglMultisampledFramebuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+dt,a.RENDERBUFFER,null),e.bindFramebuffer(a.FRAMEBUFFER,ht.__webglFramebuffer),a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0+dt,a.TEXTURE_2D,null,0);e.bindFramebuffer(a.READ_FRAMEBUFFER,ht.__webglMultisampledFramebuffer);const tt=D.texture.mipmaps;tt&&tt.length>0?e.bindFramebuffer(a.DRAW_FRAMEBUFFER,ht.__webglFramebuffer[0]):e.bindFramebuffer(a.DRAW_FRAMEBUFFER,ht.__webglFramebuffer);for(let dt=0;dt<w.length;dt++){if(D.resolveDepthBuffer&&(D.depthBuffer&&(K|=a.DEPTH_BUFFER_BIT),D.stencilBuffer&&D.resolveStencilBuffer&&(K|=a.STENCIL_BUFFER_BIT)),Z){a.framebufferRenderbuffer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.RENDERBUFFER,ht.__webglColorRenderbuffer[dt]);const Nt=i.get(w[dt]).__webglTexture;a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,Nt,0)}a.blitFramebuffer(0,0,F,X,0,0,F,X,K,a.NEAREST),c===!0&&(Re.length=0,ci.length=0,Re.push(a.COLOR_ATTACHMENT0+dt),D.depthBuffer&&D.resolveDepthBuffer===!1&&(Re.push(ct),ci.push(ct),a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER,ci)),a.invalidateFramebuffer(a.READ_FRAMEBUFFER,Re))}if(e.bindFramebuffer(a.READ_FRAMEBUFFER,null),e.bindFramebuffer(a.DRAW_FRAMEBUFFER,null),Z)for(let dt=0;dt<w.length;dt++){e.bindFramebuffer(a.FRAMEBUFFER,ht.__webglMultisampledFramebuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+dt,a.RENDERBUFFER,ht.__webglColorRenderbuffer[dt]);const Nt=i.get(w[dt]).__webglTexture;e.bindFramebuffer(a.FRAMEBUFFER,ht.__webglFramebuffer),a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0+dt,a.TEXTURE_2D,Nt,0)}e.bindFramebuffer(a.DRAW_FRAMEBUFFER,ht.__webglMultisampledFramebuffer)}else if(D.depthBuffer&&D.resolveDepthBuffer===!1&&c){const w=D.stencilBuffer?a.DEPTH_STENCIL_ATTACHMENT:a.DEPTH_ATTACHMENT;a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER,[w])}}}function li(D){return Math.min(n.maxSamples,D.samples)}function wi(D){const w=i.get(D);return D.samples>0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&w.__useRenderToTexture!==!1}function N(D){const w=r.render.frame;h.get(D)!==w&&(h.set(D,w),D.update())}function fn(D,w){const F=D.colorSpace,X=D.format,K=D.type;return D.isCompressedTexture===!0||D.isVideoTexture===!0||F!==Au&&F!==Lr&&(me.getTransfer(F)===Pe?(X!==Gi||K!==Ln)&&Pt("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):qt("WebGLTextures: Unsupported texture color space:",F)),w}function De(D){return typeof HTMLImageElement<"u"&&D instanceof HTMLImageElement?(l.width=D.naturalWidth||D.width,l.height=D.naturalHeight||D.height):typeof VideoFrame<"u"&&D instanceof VideoFrame?(l.width=D.displayWidth,l.height=D.displayHeight):(l.width=D.width,l.height=D.height),l}this.allocateTextureUnit=H,this.resetTextureUnits=B,this.getTextureUnits=W,this.setTextureUnits=O,this.setTexture2D=q,this.setTexture2DArray=Q,this.setTexture3D=J,this.setTextureCube=it,this.rebindTextures=Vt,this.setupRenderTarget=Wt,this.updateRenderTargetMipmap=Te,this.updateMultisampleRenderTarget=ei,this.setupDepthRenderbuffer=Ht,this.setupFrameBufferTexture=Ut,this.useMultisampledRTT=wi,this.isReversedDepthBuffer=function(){return e.buffers.depth.getReversed()}}function CA(a,t){function e(i,n=Lr){let s;const r=me.getTransfer(n);if(i===Ln)return a.UNSIGNED_BYTE;if(i===Ip)return a.UNSIGNED_SHORT_4_4_4_4;if(i===Cp)return a.UNSIGNED_SHORT_5_5_5_1;if(i===VM)return a.UNSIGNED_INT_5_9_9_9_REV;if(i===WM)return a.UNSIGNED_INT_10F_11F_11F_REV;if(i===HM)return a.BYTE;if(i===GM)return a.SHORT;if(i===ll)return a.UNSIGNED_SHORT;if(i===Dp)return a.INT;if(i===Kn)return a.UNSIGNED_INT;if(i===ji)return a.FLOAT;if(i===qe)return a.HALF_FLOAT;if(i===XM)return a.ALPHA;if(i===YM)return a.RGB;if(i===Gi)return a.RGBA;if(i===lr)return a.DEPTH_COMPONENT;if(i===Ta)return a.DEPTH_STENCIL;if(i===tc)return a.RED;if(i===Pp)return a.RED_INTEGER;if(i===Ha)return a.RG;if(i===Op)return a.RG_INTEGER;if(i===Lp)return a.RGBA_INTEGER;if(i===Gh||i===Vh||i===Wh||i===Xh)if(r===Pe)if(s=t.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(i===Gh)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===Vh)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Wh)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Xh)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=t.get("WEBGL_compressed_texture_s3tc"),s!==null){if(i===Gh)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===Vh)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Wh)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Xh)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===r0||i===a0||i===o0||i===c0)if(s=t.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(i===r0)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===a0)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===o0)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===c0)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===l0||i===h0||i===u0||i===d0||i===f0||i===bu||i===p0)if(s=t.get("WEBGL_compressed_texture_etc"),s!==null){if(i===l0||i===h0)return r===Pe?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===u0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===d0)return s.COMPRESSED_R11_EAC;if(i===f0)return s.COMPRESSED_SIGNED_R11_EAC;if(i===bu)return s.COMPRESSED_RG11_EAC;if(i===p0)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===m0||i===g0||i===v0||i===M0||i===y0||i===x0||i===b0||i===S0||i===w0||i===_0||i===E0||i===A0||i===T0||i===R0)if(s=t.get("WEBGL_compressed_texture_astc"),s!==null){if(i===m0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===g0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===v0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===M0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===y0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===x0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===b0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===S0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===w0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===_0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===E0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===A0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===T0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===R0)return r===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===D0||i===I0||i===C0)if(s=t.get("EXT_texture_compression_bptc"),s!==null){if(i===D0)return r===Pe?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===I0)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===C0)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===P0||i===O0||i===Su||i===L0)if(s=t.get("EXT_texture_compression_rgtc"),s!==null){if(i===P0)return s.COMPRESSED_RED_RGTC1_EXT;if(i===O0)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===Su)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===L0)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===hl?a.UNSIGNED_INT_24_8:a[i]!==void 0?a[i]:null}return{convert:e}}const PA=`
6275
6275
  void main() {
6276
6276
 
6277
6277
  gl_Position = vec4( position, 1.0 );
@@ -6820,7 +6820,7 @@ float transmissionAt(vec3 dir, float distanceM) {
6820
6820
  if (transmission < 0.015) break;
6821
6821
  }
6822
6822
  return transmission;
6823
- }`,i=/\b(noiseMap|sunDir|sunColor|ambientColor|hazeColor|offsetM|seedOffset|localCenter|localSize|localRotation|baseM|thicknessM|eyeM|coverage|sizeM|density|darkness|flatness|SLICE|MAX_HOLES|holeCount|holeCenter|holeSize|holeRotation|R|roots|altitude|coverageThreshold|ellipsoidRadius|clipLocal|densityAt|transmissionAt)\b/g;return(t+e).replace(i,n=>a+n)}class Lu{mesh;uniforms;constructor(t,e){this.uniforms={noiseMap:{value:t},sunDir:{value:new R(0,1,0)},sunColor:{value:new st(1,1,1)},ambientColor:{value:new st(.4,.45,.5)},hazeColor:{value:new st(.5,.6,.7)},offsetM:{value:new R},seedOffset:{value:new R},localCenter:{value:new R},localSize:{value:new R},localRotation:{value:0},holeCount:{value:0},holeCenter:{value:Array.from({length:Ec},()=>new R)},holeSize:{value:Array.from({length:Ec},()=>new R)},holeRotation:{value:new Array(Ec).fill(0)},baseM:{value:1e3},thicknessM:{value:650},eyeM:{value:1.6},coverage:{value:.5},sizeM:{value:1400},density:{value:1},darkness:{value:0},flatness:{value:0}};const i=new Me({uniforms:this.uniforms,vertexShader:$A,fragmentShader:q0,transparent:!0,depthWrite:!1,depthTest:!0,side:Qe});this.mesh=new At(new pi(e,32,16),i),this.mesh.frustumCulled=!1}update(t,e,i,n=[]){const s=this.uniforms;s.localSize.value.set(i?.widthM??0,i?.thicknessM??0,i?.depthM??0),s.localCenter.value.set(i?.eastM??0,i?i.baseM+i.thicknessM/2:0,-(i?.northM??0)),s.localRotation.value=(i?.rotationDeg??0)*Math.PI/180,s.holeCount.value=Math.min(Ec,n.length),n.slice(0,Ec).forEach((o,c)=>{s.holeCenter.value[c].set(o.eastM,o.baseM+o.thicknessM/2,-o.northM),s.holeSize.value[c].set(o.widthM,o.thicknessM,o.depthM),s.holeRotation.value[c]=o.rotationDeg*Math.PI/180}),s.baseM.value=Math.max(0,t.baseM),s.thicknessM.value=Math.max(10,t.thicknessM),s.coverage.value=Math.max(0,Math.min(1,t.coverage)),s.sizeM.value=Math.max(50,t.sizeM),s.density.value=Math.max(0,Math.min(2,t.density)),s.darkness.value=Math.max(0,Math.min(1,t.darkness??0)),s.eyeM.value=Math.max(.1,e),s.flatness.value=t.type==="stratus"?1:t.type==="stratocumulus"?.45:0;const r=Y0(t);s.seedOffset.value.set(r%97/97,r%61/61,r%37/37),this.mesh.visible=s.density.value>0&&(i!==void 0||s.coverage.value>0)}static thresholdFor(t){const e=Math.min(.999,Math.max(.001,t));return .564-.2516*(Math.sqrt(3)/Math.PI)*Math.log(e/(1-e))}densityAt(t){const e=this.uniforms,i=(O,H,U)=>{const q=Math.max(0,Math.min(1,(U-O)/(H-O)));return q*q*(3-2*q)},n=(O,H,U)=>O+(H-O)*U,s=e.eyeM.value+t.y,r=2*Ur*s+t.x**2+s**2+t.z**2,o=r/(Math.sqrt(Ur**2+r)+Ur),c=(o-e.baseM.value)/e.thicknessM.value,l=e.localSize.value.x>0;if(c<=0||c>=1||e.coverage.value<=0&&!l)return 0;const h=(O,H,U)=>{const q=t.x+e.offsetM.value.x-O.x,Q=t.z+e.offsetM.value.z-O.z,J=Math.cos(U),it=Math.sin(U);return Math.hypot((J*q-it*Q)/(H.x*.5),(o-O.y)/(H.y*.5),(it*q+J*Q)/(H.z*.5))},u=l?h(e.localCenter.value,e.localSize.value,e.localRotation.value):0;if(u>1.3)return 0;const d=[t.x,t.y,t.z].map((O,H)=>(O+e.offsetM.value.getComponent(H))/(e.sizeM.value*4)+e.seedOffset.value.getComponent(H)),f=e.noiseMap.value.image.data,p=(O,H,U)=>{const q=[O,H,U].map(ot=>(ot%1+1)%1*yi-.5),Q=q.map(Math.floor),J=q.map((ot,$t)=>ot-Q[$t]);let it=0;for(let ot=0;ot<2;ot++)for(let $t=0;$t<2;$t++)for(let re=0;re<2;re++){const jt=(Q[0]+re+yi)%yi,$=(Q[1]+$t+yi)%yi,rt=(Q[2]+ot+yi)%yi;it+=f[jt+yi*($+yi*rt)]/255*(re?J[0]:1-J[0])*($t?J[1]:1-J[1])*(ot?J[2]:1-J[2])}return it},v=[d[0]*.173,of,d[2]*.173];d[0]+=(p(v[0]+.13,v[1]+.27,v[2]+.41)-.5)*1.3,d[2]+=(p(v[0]+.67,v[1]+.53,v[2]+.19)-.5)*1.3;const m=(d[0]*.731+d[2]*.682)*1.371,g=(-d[0]*.682+d[2]*.731)*1.371;let b=i(.2,.8,p(d[0],of,d[2])*.65+p(m,of+.37,g)*.35);const S=i(8e3,4e4,Math.hypot(t.x,t.y,t.z)),M=n(p(d[0]*2,d[1]*3,d[2]*2),.5,S),x=n(p(d[0]*7,d[1]*7,d[2]*7),.5,S);let _=Lu.thresholdFor(e.coverage.value),E=1,y=0;if(l){const O=u+(M-.5)*.18;y=1-i(.35,1,O),E=1-i(.85,1.15,O),b=n(b,1,y),_=Math.min(_,Lu.thresholdFor(.5))}for(let O=0;O<e.holeCount.value;O++)E*=i(.85,1.15,h(e.holeCenter.value[O],e.holeSize.value[O],e.holeRotation.value[O])+(M-.5)*.18);if(E<.001)return 0;const T=(1-e.flatness.value)*.3*c*c;let I=i(_-.1+T,_+.1+T,b+(M-.5)*.12*c);if(I=n(I,1,i(.92,1,e.coverage.value)),I=n(I,Math.max(e.coverage.value,y),S),I<.001)return 0;const C=n(.45+.55*M,.96,e.flatness.value),P=i(0,.09,c)*(1-i(C-.22,C,c)),B=n(Math.max(0,I-(1-M)*.38-(1-x)*.1),I*.8,e.flatness.value),W=n(1-S,1,i(.5,.92,e.coverage.value));return P*B*e.density.value*E*W}transmissionAt(t,e=1/0){const i=this.uniforms,n=qA(t.y,i.eyeM.value,i.baseM.value,i.thicknessM.value);if(!n)return 1;let[s,r]=n;if(i.localSize.value.x>0){const h=i.localCenter.value.clone().sub(i.offsetM.value);h.y-=i.eyeM.value+(h.x**2+h.z**2)/(2*Ur);const u=i.localSize.value.length()*.5+25,d=t.x*h.x+t.y*h.y+t.z*h.z,f=d*d-h.lengthSq()+u*u;if(f<0)return 1;s=Math.max(s,d-Math.sqrt(f)),r=Math.min(r,d+Math.sqrt(f))}const o=Math.min(r,e,s+18e3);if(o<=s)return 1;const c=(o-s)/48;let l=1;for(let h=0;h<48;h++){const u=s+(h+.5)*c;if(l*=Math.exp(-this.densityAt({x:t.x*u,y:t.y*u,z:t.z*u})*c*.006),l<.015)break}return l}dispose(){this.mesh.removeFromParent(),this.mesh.geometry.dispose(),this.mesh.material.dispose()}}class Ci{static VIOLET_NM=400;static DEEP_RED_NM=700;static SAMPLES=Ci.build(24);static build(t){const e=[];let i=0,n=0,s=0;for(let r=0;r<t;r++){const o=Ci.VIOLET_NM+(r+.5)/t*(Ci.DEEP_RED_NM-Ci.VIOLET_NM),[c,l,h]=Ci.colourMatching(o),u={wavelengthNm:o,r:Math.max(0,3.2406*c-1.5372*l-.4986*h),g:Math.max(0,-.9689*c+1.8758*l+.0415*h),b:Math.max(0,.0557*c-.204*l+1.057*h)};i+=u.r,n+=u.g,s+=u.b,e.push(u)}for(const r of e)r.r/=i,r.g/=n,r.b/=s;return e}static tristimulus(t,e,i){let n=0,s=0,r=0;for(let c=0;c<t.length;c++){const[l,h,u]=Ci.colourMatching(t[c]);n+=l*e[c],s+=h*e[c],r+=u*e[c]}const o=683*i;return[n*o,s*o,r*o]}static scotopic(t){const e=t/1e3;return .992*Math.exp(-321.9*(e-.5)**2)}static linearSrgbOf([t,e,i]){return[3.2406*t-1.5372*e-.4986*i,-.9689*t+1.8758*e+.0415*i,.0557*t-.204*e+1.057*i]}static colourMatching(t){const e=(i,n,s)=>{const r=(t-i)/(t<i?n:s);return Math.exp(-.5*r*r)};return[1.056*e(599.8,37.9,31)+.362*e(442,16,26.7)-.065*e(501.1,20.4,26.2),.821*e(568.8,46.9,40.5)+.286*e(530.9,16.3,31.1),1.217*e(437,11.8,36)+.681*e(459,26,13.8)]}}class Nu{static reflectance(t,e,i){const s=e/i*Math.sqrt(Math.max(0,1-t*t));if(s>=1)return 1;const r=Math.sqrt(Math.max(0,1-s*s)),o=(i*t-e*r)/(i*t+e*r),c=(e*t-i*r)/(e*t+i*r);return(o*o+c*c)/2}}class zi{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3312;static ANCHOR_BLUE=1.3404;static B=(zi.ANCHOR_BLUE-zi.ANCHOR_RED)/(1/(zi.BLUE_NM*zi.BLUE_NM)-1/(zi.RED_NM*zi.RED_NM));static A=zi.ANCHOR_RED-zi.B/(zi.RED_NM*zi.RED_NM);static indexAt(t){return zi.A+zi.B/(t*t)}}class Bo{static MAX_CHORDS=4;index=1.333;set refractiveIndex(t){this.index=t}trace(t,e){const i=Math.min(1,Math.max(0,t)),n=Math.sqrt(Math.max(0,1-i*i)),s=i/this.index,r=Math.sqrt(Math.max(0,1-s*s)),o=Math.asin(i),c=Math.asin(s),l=Nu.reflectance(n,1,this.index);let h=0;e[h].chords=0,e[h].scatteringAngle=Bo.folded(Math.PI-2*o),e[h].weight=l,h++;const u=Nu.reflectance(r,this.index,1);let d=1-l;for(let f=1;f<=Bo.MAX_CHORDS&&h<e.length;f++){const p=2*(o-c)+(f-1)*(Math.PI-2*c);e[h].chords=f,e[h].scatteringAngle=Bo.folded(p),e[h].weight=d*(1-u),h++,d*=u}return h}static folded(t){const e=2*Math.PI;let i=t%e;return i<0&&(i+=e),i>Math.PI?e-i:i}}class vi{static BINS=1800;static SOURCE_RADIUS_DEG=.265;static FULL_UNTIL_DEG=60;static FADED_BY_DEG=90;static IMPACT_STEPS=4096;drop=new Bo;previous=vi.emergences();current=vi.emergences();tally=new Float32Array(vi.BINS*3);radiance=new Float32Array(vi.BINS*3);scratch=new Float32Array(vi.BINS*3);static emergences(){return Array.from({length:Bo.MAX_CHORDS+1},()=>({chords:0,scatteringAngle:0,weight:0}))}compute(){this.tally.fill(0);for(const t of Ci.SAMPLES)this.sweep(t);return this.toRadiance(),this.blurBySourceDisc(),{bins:vi.BINS,data:this.radiance,binDeg:180/vi.BINS}}sweep(t){this.drop.refractiveIndex=zi.indexAt(t.wavelengthNm);const e=vi.IMPACT_STEPS;let i=this.drop.trace(0,this.previous);const n=1/e;for(let s=1;s<=e;s++){const r=this.drop.trace(Math.sqrt(s/e),this.current);for(let o=0;o<Math.min(r,i);o++){const c=this.previous[o],l=this.current[o];c.chords===l.chords&&this.deposit(c.scatteringAngle,l.scatteringAngle,(c.weight+l.weight)/2*n,t)}i=r,this.copyInto(this.current,this.previous)}}copyInto(t,e){for(let i=0;i<t.length;i++)e[i].chords=t[i].chords,e[i].scatteringAngle=t[i].scatteringAngle,e[i].weight=t[i].weight}deposit(t,e,i,n){if(i<=0)return;const s=vi.BINS,r=Math.PI/s,o=Math.min(t,e),c=Math.max(t,e),l=c-o,h=Math.min(s-1,Math.max(0,Math.floor(o/r))),u=Math.min(s-1,Math.max(0,Math.floor(c/r)));if(l<=0||h===u){this.add(h,i,n);return}for(let d=h;d<=u;d++){const f=Math.min(c,(d+1)*r)-Math.max(o,d*r);f>0&&this.add(d,i*f/l,n)}}add(t,e,i){const n=t*3,s=e*Ci.SAMPLES.length;this.tally[n]+=s*i.r,this.tally[n+1]+=s*i.g,this.tally[n+2]+=s*i.b}toRadiance(){const t=vi.BINS,e=Math.PI/t;for(let i=0;i<t;i++){const n=2*Math.PI*(Math.cos(i*e)-Math.cos((i+1)*e)),s=n>0?this.backwardShare((i+.5)*(180/t))/n:0,r=i*3;this.radiance[r]=this.tally[r]*s,this.radiance[r+1]=this.tally[r+1]*s,this.radiance[r+2]=this.tally[r+2]*s}}backwardShare(t){const e=180-t;if(e<=vi.FULL_UNTIL_DEG)return 1;if(e>=vi.FADED_BY_DEG)return 0;const i=(e-vi.FULL_UNTIL_DEG)/(vi.FADED_BY_DEG-vi.FULL_UNTIL_DEG);return Math.cos(i*Math.PI/2)**2}blurBySourceDisc(){const t=vi.BINS,e=vi.SOURCE_RADIUS_DEG*t/180,i=Math.max(1,Math.ceil(e)),n=[];let s=0;for(let r=-i;r<=i;r++){const o=Math.max(0,e*e-r*r),c=Math.sqrt(o);n.push(c),s+=c}if(!(s<=0)){this.scratch.set(this.radiance);for(let r=0;r<t;r++){let o=0,c=0,l=0;for(let u=-i;u<=i;u++){const d=Math.min(t-1,Math.max(0,r+u))*3,f=n[u+i];o+=this.scratch[d]*f,c+=this.scratch[d+1]*f,l+=this.scratch[d+2]*f}const h=r*3;this.radiance[h]=o/s,this.radiance[h+1]=c/s,this.radiance[h+2]=l/s}}}}class Ra{static RADIUS=880;static RENDER_ORDER=5.5;static GAIN=.22;static MOON_SATURATION=.15;object;material;sky=new vi;texture;texels;computed=!1;constructor(){this.texels=new Uint16Array(vi.BINS*4),this.texture=new Vs(this.texels,vi.BINS,1,Gi,qe),this.texture.minFilter=de,this.texture.magFilter=de,this.texture.wrapS=Bi,this.texture.wrapT=Bi,this.texture.needsUpdate=!0,this.material=new Me({uniforms:{uSource:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,1,1)},uSaturation:{value:1},uProfile:{value:this.texture},uGain:{value:Ra.GAIN}},vertexShader:`
6823
+ }`,i=/\b(noiseMap|sunDir|sunColor|ambientColor|hazeColor|offsetM|seedOffset|localCenter|localSize|localRotation|baseM|thicknessM|eyeM|coverage|sizeM|density|darkness|flatness|SLICE|MAX_HOLES|holeCount|holeCenter|holeSize|holeRotation|R|roots|altitude|coverageThreshold|ellipsoidRadius|clipLocal|densityAt|transmissionAt)\b/g;return(t+e).replace(i,n=>a+n)}class Lu{mesh;uniforms;constructor(t,e){this.uniforms={noiseMap:{value:t},sunDir:{value:new R(0,1,0)},sunColor:{value:new st(1,1,1)},ambientColor:{value:new st(.4,.45,.5)},hazeColor:{value:new st(.5,.6,.7)},offsetM:{value:new R},seedOffset:{value:new R},localCenter:{value:new R},localSize:{value:new R},localRotation:{value:0},holeCount:{value:0},holeCenter:{value:Array.from({length:Ec},()=>new R)},holeSize:{value:Array.from({length:Ec},()=>new R)},holeRotation:{value:new Array(Ec).fill(0)},baseM:{value:1e3},thicknessM:{value:650},eyeM:{value:1.6},coverage:{value:.5},sizeM:{value:1400},density:{value:1},darkness:{value:0},flatness:{value:0}};const i=new Me({uniforms:this.uniforms,vertexShader:$A,fragmentShader:q0,transparent:!0,depthWrite:!1,depthTest:!0,side:Qe});this.mesh=new At(new pi(e,32,16),i),this.mesh.frustumCulled=!1}update(t,e,i,n=[]){const s=this.uniforms;s.localSize.value.set(i?.widthM??0,i?.thicknessM??0,i?.depthM??0),s.localCenter.value.set(i?.eastM??0,i?i.baseM+i.thicknessM/2:0,-(i?.northM??0)),s.localRotation.value=(i?.rotationDeg??0)*Math.PI/180,s.holeCount.value=Math.min(Ec,n.length),n.slice(0,Ec).forEach((o,c)=>{s.holeCenter.value[c].set(o.eastM,o.baseM+o.thicknessM/2,-o.northM),s.holeSize.value[c].set(o.widthM,o.thicknessM,o.depthM),s.holeRotation.value[c]=o.rotationDeg*Math.PI/180}),s.baseM.value=Math.max(0,t.baseM),s.thicknessM.value=Math.max(10,t.thicknessM),s.coverage.value=Math.max(0,Math.min(1,t.coverage)),s.sizeM.value=Math.max(50,t.sizeM),s.density.value=Math.max(0,Math.min(2,t.density)),s.darkness.value=Math.max(0,Math.min(1,t.darkness??0)),s.eyeM.value=Math.max(.1,e),s.flatness.value=t.type==="stratus"?1:t.type==="stratocumulus"?.45:0;const r=Y0(t);s.seedOffset.value.set(r%97/97,r%61/61,r%37/37),this.mesh.visible=s.density.value>0&&(i!==void 0||s.coverage.value>0)}static thresholdFor(t){const e=Math.min(.999,Math.max(.001,t));return .564-.2516*(Math.sqrt(3)/Math.PI)*Math.log(e/(1-e))}densityAt(t){const e=this.uniforms,i=(O,H,U)=>{const q=Math.max(0,Math.min(1,(U-O)/(H-O)));return q*q*(3-2*q)},n=(O,H,U)=>O+(H-O)*U,s=e.eyeM.value+t.y,r=2*Ur*s+t.x**2+s**2+t.z**2,o=r/(Math.sqrt(Ur**2+r)+Ur),c=(o-e.baseM.value)/e.thicknessM.value,l=e.localSize.value.x>0;if(c<=0||c>=1||e.coverage.value<=0&&!l)return 0;const h=(O,H,U)=>{const q=t.x+e.offsetM.value.x-O.x,Q=t.z+e.offsetM.value.z-O.z,J=Math.cos(U),it=Math.sin(U);return Math.hypot((J*q-it*Q)/(H.x*.5),(o-O.y)/(H.y*.5),(it*q+J*Q)/(H.z*.5))},u=l?h(e.localCenter.value,e.localSize.value,e.localRotation.value):0;if(u>1.3)return 0;const d=[t.x,t.y,t.z].map((O,H)=>(O+e.offsetM.value.getComponent(H))/(e.sizeM.value*4)+e.seedOffset.value.getComponent(H)),f=e.noiseMap.value.image.data,p=(O,H,U)=>{const q=[O,H,U].map(ot=>(ot%1+1)%1*yi-.5),Q=q.map(Math.floor),J=q.map((ot,$t)=>ot-Q[$t]);let it=0;for(let ot=0;ot<2;ot++)for(let $t=0;$t<2;$t++)for(let re=0;re<2;re++){const jt=(Q[0]+re+yi)%yi,$=(Q[1]+$t+yi)%yi,rt=(Q[2]+ot+yi)%yi;it+=f[jt+yi*($+yi*rt)]/255*(re?J[0]:1-J[0])*($t?J[1]:1-J[1])*(ot?J[2]:1-J[2])}return it},v=[d[0]*.173,of,d[2]*.173];d[0]+=(p(v[0]+.13,v[1]+.27,v[2]+.41)-.5)*1.3,d[2]+=(p(v[0]+.67,v[1]+.53,v[2]+.19)-.5)*1.3;const m=(d[0]*.731+d[2]*.682)*1.371,g=(-d[0]*.682+d[2]*.731)*1.371;let b=i(.2,.8,p(d[0],of,d[2])*.65+p(m,of+.37,g)*.35);const S=i(8e3,4e4,Math.hypot(t.x,t.y,t.z)),M=n(p(d[0]*2,d[1]*3,d[2]*2),.5,S),x=n(p(d[0]*7,d[1]*7,d[2]*7),.5,S);let _=Lu.thresholdFor(e.coverage.value),E=1,y=0;if(l){const O=u+(M-.5)*.18;y=1-i(.35,1,O),E=1-i(.85,1.15,O),b=n(b,1,y),_=Math.min(_,Lu.thresholdFor(.5))}for(let O=0;O<e.holeCount.value;O++)E*=i(.85,1.15,h(e.holeCenter.value[O],e.holeSize.value[O],e.holeRotation.value[O])+(M-.5)*.18);if(E<.001)return 0;const T=(1-e.flatness.value)*.3*c*c;let I=i(_-.1+T,_+.1+T,b+(M-.5)*.12*c);if(I=n(I,1,i(.92,1,e.coverage.value)),I=n(I,Math.max(e.coverage.value,y),S),I<.001)return 0;const C=n(.45+.55*M,.96,e.flatness.value),P=i(0,.09,c)*(1-i(C-.22,C,c)),B=n(Math.max(0,I-(1-M)*.38-(1-x)*.1),I*.8,e.flatness.value),W=n(1-S,1,i(.5,.92,e.coverage.value));return P*B*e.density.value*E*W}transmissionAt(t,e=1/0){const i=this.uniforms,n=qA(t.y,i.eyeM.value,i.baseM.value,i.thicknessM.value);if(!n)return 1;let[s,r]=n;if(i.localSize.value.x>0){const h=i.localCenter.value.clone().sub(i.offsetM.value);h.y-=i.eyeM.value+(h.x**2+h.z**2)/(2*Ur);const u=i.localSize.value.length()*.5+25,d=t.x*h.x+t.y*h.y+t.z*h.z,f=d*d-h.lengthSq()+u*u;if(f<0)return 1;s=Math.max(s,d-Math.sqrt(f)),r=Math.min(r,d+Math.sqrt(f))}const o=Math.min(r,e,s+18e3);if(o<=s)return 1;const c=(o-s)/48;let l=1;for(let h=0;h<48;h++){const u=s+(h+.5)*c;if(l*=Math.exp(-this.densityAt({x:t.x*u,y:t.y*u,z:t.z*u})*c*.006),l<.015)break}return l}dispose(){this.mesh.removeFromParent(),this.mesh.geometry.dispose(),this.mesh.material.dispose()}}class Pi{static VIOLET_NM=400;static DEEP_RED_NM=700;static SAMPLES=Pi.build(24);static build(t){const e=[];let i=0,n=0,s=0;for(let r=0;r<t;r++){const o=Pi.VIOLET_NM+(r+.5)/t*(Pi.DEEP_RED_NM-Pi.VIOLET_NM),[c,l,h]=Pi.colourMatching(o),u={wavelengthNm:o,r:Math.max(0,3.2406*c-1.5372*l-.4986*h),g:Math.max(0,-.9689*c+1.8758*l+.0415*h),b:Math.max(0,.0557*c-.204*l+1.057*h)};i+=u.r,n+=u.g,s+=u.b,e.push(u)}for(const r of e)r.r/=i,r.g/=n,r.b/=s;return e}static tristimulus(t,e,i){let n=0,s=0,r=0;for(let c=0;c<t.length;c++){const[l,h,u]=Pi.colourMatching(t[c]);n+=l*e[c],s+=h*e[c],r+=u*e[c]}const o=683*i;return[n*o,s*o,r*o]}static scotopic(t){const e=t/1e3;return .992*Math.exp(-321.9*(e-.5)**2)}static linearSrgbOf([t,e,i]){return[3.2406*t-1.5372*e-.4986*i,-.9689*t+1.8758*e+.0415*i,.0557*t-.204*e+1.057*i]}static colourMatching(t){const e=(i,n,s)=>{const r=(t-i)/(t<i?n:s);return Math.exp(-.5*r*r)};return[1.056*e(599.8,37.9,31)+.362*e(442,16,26.7)-.065*e(501.1,20.4,26.2),.821*e(568.8,46.9,40.5)+.286*e(530.9,16.3,31.1),1.217*e(437,11.8,36)+.681*e(459,26,13.8)]}}class Nu{static reflectance(t,e,i){const s=e/i*Math.sqrt(Math.max(0,1-t*t));if(s>=1)return 1;const r=Math.sqrt(Math.max(0,1-s*s)),o=(i*t-e*r)/(i*t+e*r),c=(e*t-i*r)/(e*t+i*r);return(o*o+c*c)/2}}class zi{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3312;static ANCHOR_BLUE=1.3404;static B=(zi.ANCHOR_BLUE-zi.ANCHOR_RED)/(1/(zi.BLUE_NM*zi.BLUE_NM)-1/(zi.RED_NM*zi.RED_NM));static A=zi.ANCHOR_RED-zi.B/(zi.RED_NM*zi.RED_NM);static indexAt(t){return zi.A+zi.B/(t*t)}}class Bo{static MAX_CHORDS=4;index=1.333;set refractiveIndex(t){this.index=t}trace(t,e){const i=Math.min(1,Math.max(0,t)),n=Math.sqrt(Math.max(0,1-i*i)),s=i/this.index,r=Math.sqrt(Math.max(0,1-s*s)),o=Math.asin(i),c=Math.asin(s),l=Nu.reflectance(n,1,this.index);let h=0;e[h].chords=0,e[h].scatteringAngle=Bo.folded(Math.PI-2*o),e[h].weight=l,h++;const u=Nu.reflectance(r,this.index,1);let d=1-l;for(let f=1;f<=Bo.MAX_CHORDS&&h<e.length;f++){const p=2*(o-c)+(f-1)*(Math.PI-2*c);e[h].chords=f,e[h].scatteringAngle=Bo.folded(p),e[h].weight=d*(1-u),h++,d*=u}return h}static folded(t){const e=2*Math.PI;let i=t%e;return i<0&&(i+=e),i>Math.PI?e-i:i}}class vi{static BINS=1800;static SOURCE_RADIUS_DEG=.265;static FULL_UNTIL_DEG=60;static FADED_BY_DEG=90;static IMPACT_STEPS=4096;drop=new Bo;previous=vi.emergences();current=vi.emergences();tally=new Float32Array(vi.BINS*3);radiance=new Float32Array(vi.BINS*3);scratch=new Float32Array(vi.BINS*3);static emergences(){return Array.from({length:Bo.MAX_CHORDS+1},()=>({chords:0,scatteringAngle:0,weight:0}))}compute(){this.tally.fill(0);for(const t of Pi.SAMPLES)this.sweep(t);return this.toRadiance(),this.blurBySourceDisc(),{bins:vi.BINS,data:this.radiance,binDeg:180/vi.BINS}}sweep(t){this.drop.refractiveIndex=zi.indexAt(t.wavelengthNm);const e=vi.IMPACT_STEPS;let i=this.drop.trace(0,this.previous);const n=1/e;for(let s=1;s<=e;s++){const r=this.drop.trace(Math.sqrt(s/e),this.current);for(let o=0;o<Math.min(r,i);o++){const c=this.previous[o],l=this.current[o];c.chords===l.chords&&this.deposit(c.scatteringAngle,l.scatteringAngle,(c.weight+l.weight)/2*n,t)}i=r,this.copyInto(this.current,this.previous)}}copyInto(t,e){for(let i=0;i<t.length;i++)e[i].chords=t[i].chords,e[i].scatteringAngle=t[i].scatteringAngle,e[i].weight=t[i].weight}deposit(t,e,i,n){if(i<=0)return;const s=vi.BINS,r=Math.PI/s,o=Math.min(t,e),c=Math.max(t,e),l=c-o,h=Math.min(s-1,Math.max(0,Math.floor(o/r))),u=Math.min(s-1,Math.max(0,Math.floor(c/r)));if(l<=0||h===u){this.add(h,i,n);return}for(let d=h;d<=u;d++){const f=Math.min(c,(d+1)*r)-Math.max(o,d*r);f>0&&this.add(d,i*f/l,n)}}add(t,e,i){const n=t*3,s=e*Pi.SAMPLES.length;this.tally[n]+=s*i.r,this.tally[n+1]+=s*i.g,this.tally[n+2]+=s*i.b}toRadiance(){const t=vi.BINS,e=Math.PI/t;for(let i=0;i<t;i++){const n=2*Math.PI*(Math.cos(i*e)-Math.cos((i+1)*e)),s=n>0?this.backwardShare((i+.5)*(180/t))/n:0,r=i*3;this.radiance[r]=this.tally[r]*s,this.radiance[r+1]=this.tally[r+1]*s,this.radiance[r+2]=this.tally[r+2]*s}}backwardShare(t){const e=180-t;if(e<=vi.FULL_UNTIL_DEG)return 1;if(e>=vi.FADED_BY_DEG)return 0;const i=(e-vi.FULL_UNTIL_DEG)/(vi.FADED_BY_DEG-vi.FULL_UNTIL_DEG);return Math.cos(i*Math.PI/2)**2}blurBySourceDisc(){const t=vi.BINS,e=vi.SOURCE_RADIUS_DEG*t/180,i=Math.max(1,Math.ceil(e)),n=[];let s=0;for(let r=-i;r<=i;r++){const o=Math.max(0,e*e-r*r),c=Math.sqrt(o);n.push(c),s+=c}if(!(s<=0)){this.scratch.set(this.radiance);for(let r=0;r<t;r++){let o=0,c=0,l=0;for(let u=-i;u<=i;u++){const d=Math.min(t-1,Math.max(0,r+u))*3,f=n[u+i];o+=this.scratch[d]*f,c+=this.scratch[d+1]*f,l+=this.scratch[d+2]*f}const h=r*3;this.radiance[h]=o/s,this.radiance[h+1]=c/s,this.radiance[h+2]=l/s}}}}class Ra{static RADIUS=880;static RENDER_ORDER=5.5;static GAIN=.22;static MOON_SATURATION=.15;object;material;sky=new vi;texture;texels;computed=!1;constructor(){this.texels=new Uint16Array(vi.BINS*4),this.texture=new Vs(this.texels,vi.BINS,1,Gi,qe),this.texture.minFilter=de,this.texture.magFilter=de,this.texture.wrapS=Bi,this.texture.wrapT=Bi,this.texture.needsUpdate=!0,this.material=new Me({uniforms:{uSource:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,1,1)},uSaturation:{value:1},uProfile:{value:this.texture},uGain:{value:Ra.GAIN}},vertexShader:`
6824
6824
  varying vec3 vDirection;
6825
6825
  void main() {
6826
6826
  vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
@@ -6848,7 +6848,7 @@ float transmissionAt(vec3 dir, float distanceM) {
6848
6848
  light = mix(vec3(grey), light, uSaturation);
6849
6849
  gl_FragColor = vec4(light * uStrength, 1.0);
6850
6850
  }
6851
- `,transparent:!0,blending:Pi,depthWrite:!1,depthTest:!0,side:Qe,fog:!1}),this.object=new At(new pi(Ra.RADIUS,64,32),this.material),this.object.renderOrder=Ra.RENDER_ORDER,this.object.frustumCulled=!1,this.object.visible=!1}update(t,e,i,n){const s=this.material.uniforms;if(e<=0){s.uStrength.value=0,this.object.visible=!1;return}this.computed||this.publish(),s.uSource.value.set(t.x,t.y,t.z).normalize(),s.uStrength.value=e,s.uTint.value.set(i[0],i[1],i[2]),s.uSaturation.value=n?1:Ra.MOON_SATURATION,this.object.visible=!0}publish(){const e=this.sky.compute().data;for(let i=0,n=0;n<e.length;i+=4,n+=3)this.texels[i]=kn.toHalfFloat(e[n]),this.texels[i+1]=kn.toHalfFloat(e[n+1]),this.texels[i+2]=kn.toHalfFloat(e[n+2]),this.texels[i+3]=1;this.texture.needsUpdate=!0,this.computed=!0}dispose(){this.texture.dispose(),this.object.geometry.dispose(),this.material.dispose()}}class Ho{constructor(t,e,i){this.group=t,this.radius=e,this.mode=i}decks=new Map;noise;halo;update(t,e){const i=Qh(t).flatMap(r=>{const o={...r,darkness:r.darkness??t.cloudDarkness};return[{layer:o,parentId:o.id,key:JSON.stringify([o.id]),instance:void 0},...(o.instances??[]).map(c=>({parentId:o.id,key:JSON.stringify([o.id,c.id]),instance:c,layer:{...o,id:`${o.id}/${c.id}`,baseM:c.baseM,thicknessM:c.thicknessM,density:c.density,darkness:c.darkness??o.darkness,seed:c.seed??Y0(o),instances:void 0}}))]}),n=new Set(i.map(r=>r.key));for(const[r,o]of this.decks)n.has(r)||(this.disposeDeck(o),this.decks.delete(r));[...i].sort((r,o)=>Math.abs(o.layer.baseM+o.layer.thicknessM/2-e)-Math.abs(r.layer.baseM+r.layer.thicknessM/2-e)).forEach(({layer:r,key:o,instance:c,parentId:l},h)=>{const u=c!==void 0||r.type!=="cirrus"&&(this.mode==="volume"||(r.instances?.length??0)>0);let d=this.decks.get(o);if(d&&!!d.volume!==u&&(this.disposeDeck(d),this.decks.delete(o),d=void 0),!d){if(d={layer:r,parentId:l,instance:c},u)this.noise??=YA(),d.volume=new Lu(this.noise,this.radius),this.group.add(d.volume.mesh);else{const p=W0(new st(1,1,1),r.coverage,Math.max(1,Math.abs(r.baseM-e)*.25*1400/Math.max(50,r.sizeM)),r.type==="cirrus"?1:0);d.uniforms=p.uniforms,d.surface=new At(X0(this.radius),p.material),this.group.add(d.surface)}this.decks.set(o,d)}d.layer=r,d.instance=c;const f=Ho.deckOrder(r.baseM<e,h,i.length);d.volume&&(d.volume.update(r,e,c,c?[]:r.instances??[]),d.volume.mesh.renderOrder=f),d.surface&&d.uniforms&&(d.surface.renderOrder=f,d.surface.scale.y=r.baseM<e?-1:1,d.surface.visible=r.coverage>0&&r.density>0,d.uniforms.coverage.value=r.coverage,d.uniforms.opticalDensity.value=r.type==="cirrus"?r.density/.35:r.density,d.uniforms.darkness.value=Math.max(0,Math.min(1,r.darkness??t.cloudDarkness)),d.uniforms.layerHeight.value=Math.max(1,Math.abs(r.baseM-e)*.25*1400/Math.max(50,r.sizeM)),d.uniforms.fibrous.value=r.type==="cirrus"?1:0)}),this.halo&&this.hostHalo(this.halo)}hostHalo(t){this.halo=t;const e=t?this.cirrusDeck:void 0;for(const i of this.decks.values())i.surface&&Ho.carryHalo(i.surface.material,i===e?t:void 0);t&&(t.hosted=e!==void 0)}static carryHalo(t,e){const i=t.uniforms;if(e){if(i.uHaloShown===e.deckUniforms.uHaloShown)return;Object.assign(i,e.deckUniforms),i.uPremultiplied.value=1,t.blending=xl,t.blendSrc=t.blendSrcAlpha=ol,t.blendDst=t.blendDstAlpha=cl}else{if(i.uPremultiplied.value===0)return;i.uHaloShown={value:0},i.uPremultiplied.value=0,t.blending=Vr}}static deckOrder(t,e,i){const n=e/Math.max(1,i);return t?Ra.RENDER_ORDER+.1+.3*n:4+n}setOffsets(t,e){for(const i of this.decks.values()){const n=e[i.parentId]??t;i.volume?.uniforms.offsetM.value.set(n.x,0,n.z);const s=.25*1400/Math.max(50,i.layer.sizeM),r=Y0(i.layer);i.uniforms?.fieldOffset.value.set(n.x*s+r%97,0,n.z*s+r%37)}}static sunVisibility(t,e){const i=Math.acos(Ur/(Ur+Math.max(0,e)))*180/Math.PI,n=Math.min(1,Math.max(0,(t+i+.84)/1.14));return n*n*(3-2*n)}setLighting(t,e,i,n){const s=Math.asin(Math.max(-1,Math.min(1,t.y/Math.max(1e-9,t.length()))))*180/Math.PI;for(const r of this.decks.values()){const o=r.volume?.uniforms??r.uniforms;o.sunDir.value.copy(t),o.sunColor.value.copy(e),r.volume||o.sunColor.value.multiplyScalar(Ho.sunVisibility(s,r.layer.baseM)),o.ambientColor.value.copy(i),r.volume?.uniforms.hazeColor.value.copy(n)}}get cirrusMask(){const t=this.cirrusDeck;return t?.uniforms?{cover:t.layer.coverage,layerHeight:t.uniforms.layerHeight.value,offset:t.uniforms.fieldOffset.value,iceCrystalAlignment:t.layer.iceCrystalAlignment}:void 0}get cirrusDeck(){return[...this.decks.values()].filter(t=>t.layer.type==="cirrus"&&t.uniforms).sort((t,e)=>e.layer.coverage-t.layer.coverage)[0]}get meshes(){return[...this.decks.values()].flatMap(t=>[t.volume?.mesh,t.surface].filter(e=>e!==void 0))}get volumes(){return[...this.decks.values()].flatMap(t=>t.volume?.mesh.visible?[t.volume]:[])}pickInstance(t){let e=1/0,i;for(const n of this.decks.values()){if(!n.instance||!n.volume?.mesh.visible)continue;const s=n.volume.uniforms,r=s.localCenter.value.clone().sub(s.offsetM.value);r.y-=s.eyeM.value+(r.x**2+r.z**2)/(2*6371e3);const o=r.dot(t);o<=0||o>=e||n.volume.transmissionAt(t)>.98||(e=o,i={layerId:n.parentId,instanceId:n.instance.id,center:r})}return i}transmissionAt(t,e=!1){let i=1;for(const n of this.decks.values())e&&n.layer.type==="cirrus"||(n.volume?i*=n.volume.transmissionAt(t):n.uniforms&&(i*=1-(n.layer.type==="cirrus"?we.iceAlphaAt:we.alphaAt)(t,n.uniforms.layerHeight.value,n.layer.coverage,n.uniforms.fieldOffset.value)*(n.layer.type==="cirrus"?.2:.95)));return i}disposeDeck(t){t.volume?.dispose(),t.surface&&(t.surface.removeFromParent(),t.surface.geometry.dispose(),t.surface.material.dispose())}dispose(){this.halo&&(this.halo.hosted=!1),this.halo=void 0;for(const t of this.decks.values())this.disposeDeck(t);this.decks.clear(),this.noise?.dispose()}}class Rt{static RESPONSE_EXPONENT=.74;static DAYLIGHT_ANCHOR_CD_M2=3e3;static DAYLIGHT_ANCHOR_RESPONSE=.42;static NIGHT_ANCHOR_CD_M2=172e-6;static NIGHT_ANCHOR_RESPONSE=.006;static anchoredSemiSaturation(t,e){const i=Rt.anchorResponse(e);return t*(1/i-1)**(1/Rt.RESPONSE_EXPONENT)}static anchorResponse(t){return Rt.lightnessOf(t)}static fromLightness(t){const e=(100*t+16)/116;return e>6/29?e**3:3*(6/29)**2*(e-4/29)}static lightnessOf(t){const e=Math.max(t,0);return(e>216/24389?116*Math.cbrt(e)-16:24389/27*e)/100}static get ADAPTATION_EXPONENT(){const t=Rt.anchoredSemiSaturation(Rt.DAYLIGHT_ANCHOR_CD_M2,Rt.DAYLIGHT_ANCHOR_RESPONSE),e=Rt.anchoredSemiSaturation(Rt.NIGHT_ANCHOR_CD_M2,Rt.NIGHT_ANCHOR_RESPONSE);return Math.log(t/e)/Math.log(Rt.DAYLIGHT_ANCHOR_CD_M2/Rt.NIGHT_ANCHOR_CD_M2)}static ROD_HALF_LUMINANCE_CD_M2=.04;static SCOTOPIC_TINT=[.853,.995,1.483];static get SEMI_SATURATION_SCALE(){return Rt.anchoredSemiSaturation(Rt.DAYLIGHT_ANCHOR_CD_M2,Rt.DAYLIGHT_ANCHOR_RESPONSE)/Rt.DAYLIGHT_ANCHOR_CD_M2**Rt.ADAPTATION_EXPONENT}static rodShare(t){return Rt.ROD_HALF_LUMINANCE_CD_M2/(Rt.ROD_HALF_LUMINANCE_CD_M2+Math.max(t,0))}static MOONLIT_ANCHOR_CD_M2=.0035;static MOONLIT_ANCHOR_RESPONSE=.0075;static semiSaturation(t){const e=Rt.MOONLIT_ANCHOR_RESPONSE,i=Math.max(t,1e-9),s=[[Rt.NIGHT_ANCHOR_CD_M2,Rt.NIGHT_ANCHOR_RESPONSE],[Rt.MOONLIT_ANCHOR_CD_M2,e],[Rt.DAYLIGHT_ANCHOR_CD_M2,Rt.DAYLIGHT_ANCHOR_RESPONSE]].map(([l,h])=>[Math.log(l),Math.log(Rt.anchoredSemiSaturation(l,h))]),r=Math.log(i),[o,c]=r<s[1][0]?[s[0],s[1]]:[s[1],s[2]];return Math.exp(o[1]+(c[1]-o[1])*(r-o[0])/(c[0]-o[0]))}static response(t,e){const i=Rt.RESPONSE_EXPONENT,n=Math.max(t,0)**i;return n/(n+Rt.semiSaturation(e)**i)}static displayOf(t,e,i,n=Rt.rodShare(i)){const s=(1-n)*t[1]+n*e,r=Rt.response(s,i),[o,c,l]=Ci.linearSrgbOf(t),h=Math.max(t[1],1e-12),u=Rt.SCOTOPIC_TINT,d=.2126*u[0]+.7152*u[1]+.0722*u[2],f=(p,v)=>Math.max(0,(1-n)*p/h+n*v/d)*r;return[f(o,u[0]),f(c,u[1]),f(l,u[2])]}static relativeOf(t,e,i,n=Rt.rodShare(i)){const s=(1-n)*t[1]+n*e,r=Math.max(s,0)/Rt.semiSaturation(i),[o,c,l]=Ci.linearSrgbOf(t),h=Math.max(t[1],1e-12),u=Rt.SCOTOPIC_TINT,d=.2126*u[0]+.7152*u[1]+.0722*u[2],f=(p,v)=>Math.max(0,(1-n)*p/h+n*v/d)*r;return[f(o,u[0]),f(c,u[1]),f(l,u[2])]}static respond(t){const e=Math.max(t,0)**Rt.RESPONSE_EXPONENT;return e/(e+1)}static relativeOfResponse(t){const e=Math.min(Math.max(t,0),.995);return(e/(1-e))**(1/Rt.RESPONSE_EXPONENT)}static finish(t){const e=.2126*t[0]+.7152*t[1]+.0722*t[2];if(!(e>0))return[0,0,0];const i=Rt.fromLightness(Rt.respond(e)),n=i/e,s=[t[0]*n,t[1]*n,t[2]*n],r=Math.max(...s);if(r<=1)return s;const o=(1-i)/(r-i);return s.map(c=>i+(c-i)*o)}}const _2=`
6851
+ `,transparent:!0,blending:Ti,depthWrite:!1,depthTest:!0,side:Qe,fog:!1}),this.object=new At(new pi(Ra.RADIUS,64,32),this.material),this.object.renderOrder=Ra.RENDER_ORDER,this.object.frustumCulled=!1,this.object.visible=!1}update(t,e,i,n){const s=this.material.uniforms;if(e<=0){s.uStrength.value=0,this.object.visible=!1;return}this.computed||this.publish(),s.uSource.value.set(t.x,t.y,t.z).normalize(),s.uStrength.value=e,s.uTint.value.set(i[0],i[1],i[2]),s.uSaturation.value=n?1:Ra.MOON_SATURATION,this.object.visible=!0}publish(){const e=this.sky.compute().data;for(let i=0,n=0;n<e.length;i+=4,n+=3)this.texels[i]=kn.toHalfFloat(e[n]),this.texels[i+1]=kn.toHalfFloat(e[n+1]),this.texels[i+2]=kn.toHalfFloat(e[n+2]),this.texels[i+3]=1;this.texture.needsUpdate=!0,this.computed=!0}dispose(){this.texture.dispose(),this.object.geometry.dispose(),this.material.dispose()}}class Ho{constructor(t,e,i){this.group=t,this.radius=e,this.mode=i}decks=new Map;noise;halo;update(t,e){const i=Qh(t).flatMap(r=>{const o={...r,darkness:r.darkness??t.cloudDarkness};return[{layer:o,parentId:o.id,key:JSON.stringify([o.id]),instance:void 0},...(o.instances??[]).map(c=>({parentId:o.id,key:JSON.stringify([o.id,c.id]),instance:c,layer:{...o,id:`${o.id}/${c.id}`,baseM:c.baseM,thicknessM:c.thicknessM,density:c.density,darkness:c.darkness??o.darkness,seed:c.seed??Y0(o),instances:void 0}}))]}),n=new Set(i.map(r=>r.key));for(const[r,o]of this.decks)n.has(r)||(this.disposeDeck(o),this.decks.delete(r));[...i].sort((r,o)=>Math.abs(o.layer.baseM+o.layer.thicknessM/2-e)-Math.abs(r.layer.baseM+r.layer.thicknessM/2-e)).forEach(({layer:r,key:o,instance:c,parentId:l},h)=>{const u=c!==void 0||r.type!=="cirrus"&&(this.mode==="volume"||(r.instances?.length??0)>0);let d=this.decks.get(o);if(d&&!!d.volume!==u&&(this.disposeDeck(d),this.decks.delete(o),d=void 0),!d){if(d={layer:r,parentId:l,instance:c},u)this.noise??=YA(),d.volume=new Lu(this.noise,this.radius),this.group.add(d.volume.mesh);else{const p=W0(new st(1,1,1),r.coverage,Math.max(1,Math.abs(r.baseM-e)*.25*1400/Math.max(50,r.sizeM)),r.type==="cirrus"?1:0);d.uniforms=p.uniforms,d.surface=new At(X0(this.radius),p.material),this.group.add(d.surface)}this.decks.set(o,d)}d.layer=r,d.instance=c;const f=Ho.deckOrder(r.baseM<e,h,i.length);d.volume&&(d.volume.update(r,e,c,c?[]:r.instances??[]),d.volume.mesh.renderOrder=f),d.surface&&d.uniforms&&(d.surface.renderOrder=f,d.surface.scale.y=r.baseM<e?-1:1,d.surface.visible=r.coverage>0&&r.density>0,d.uniforms.coverage.value=r.coverage,d.uniforms.opticalDensity.value=r.type==="cirrus"?r.density/.35:r.density,d.uniforms.darkness.value=Math.max(0,Math.min(1,r.darkness??t.cloudDarkness)),d.uniforms.layerHeight.value=Math.max(1,Math.abs(r.baseM-e)*.25*1400/Math.max(50,r.sizeM)),d.uniforms.fibrous.value=r.type==="cirrus"?1:0)}),this.halo&&this.hostHalo(this.halo)}hostHalo(t){this.halo=t;const e=t?this.cirrusDeck:void 0;for(const i of this.decks.values())i.surface&&Ho.carryHalo(i.surface.material,i===e?t:void 0);t&&(t.hosted=e!==void 0)}static carryHalo(t,e){const i=t.uniforms;if(e){if(i.uHaloShown===e.deckUniforms.uHaloShown)return;Object.assign(i,e.deckUniforms),i.uPremultiplied.value=1,t.blending=xl,t.blendSrc=t.blendSrcAlpha=ol,t.blendDst=t.blendDstAlpha=cl}else{if(i.uPremultiplied.value===0)return;i.uHaloShown={value:0},i.uPremultiplied.value=0,t.blending=Vr}}static deckOrder(t,e,i){const n=e/Math.max(1,i);return t?Ra.RENDER_ORDER+.1+.3*n:4+n}setOffsets(t,e){for(const i of this.decks.values()){const n=e[i.parentId]??t;i.volume?.uniforms.offsetM.value.set(n.x,0,n.z);const s=.25*1400/Math.max(50,i.layer.sizeM),r=Y0(i.layer);i.uniforms?.fieldOffset.value.set(n.x*s+r%97,0,n.z*s+r%37)}}static sunVisibility(t,e){const i=Math.acos(Ur/(Ur+Math.max(0,e)))*180/Math.PI,n=Math.min(1,Math.max(0,(t+i+.84)/1.14));return n*n*(3-2*n)}setLighting(t,e,i,n){const s=Math.asin(Math.max(-1,Math.min(1,t.y/Math.max(1e-9,t.length()))))*180/Math.PI;for(const r of this.decks.values()){const o=r.volume?.uniforms??r.uniforms;o.sunDir.value.copy(t),o.sunColor.value.copy(e),r.volume||o.sunColor.value.multiplyScalar(Ho.sunVisibility(s,r.layer.baseM)),o.ambientColor.value.copy(i),r.volume?.uniforms.hazeColor.value.copy(n)}}get cirrusMask(){const t=this.cirrusDeck;return t?.uniforms?{cover:t.layer.coverage,layerHeight:t.uniforms.layerHeight.value,offset:t.uniforms.fieldOffset.value,iceCrystalAlignment:t.layer.iceCrystalAlignment}:void 0}get cirrusDeck(){return[...this.decks.values()].filter(t=>t.layer.type==="cirrus"&&t.uniforms).sort((t,e)=>e.layer.coverage-t.layer.coverage)[0]}get meshes(){return[...this.decks.values()].flatMap(t=>[t.volume?.mesh,t.surface].filter(e=>e!==void 0))}get volumes(){return[...this.decks.values()].flatMap(t=>t.volume?.mesh.visible?[t.volume]:[])}pickInstance(t){let e=1/0,i;for(const n of this.decks.values()){if(!n.instance||!n.volume?.mesh.visible)continue;const s=n.volume.uniforms,r=s.localCenter.value.clone().sub(s.offsetM.value);r.y-=s.eyeM.value+(r.x**2+r.z**2)/(2*6371e3);const o=r.dot(t);o<=0||o>=e||n.volume.transmissionAt(t)>.98||(e=o,i={layerId:n.parentId,instanceId:n.instance.id,center:r})}return i}transmissionAt(t,e=!1){let i=1;for(const n of this.decks.values())e&&n.layer.type==="cirrus"||(n.volume?i*=n.volume.transmissionAt(t):n.uniforms&&(i*=1-(n.layer.type==="cirrus"?we.iceAlphaAt:we.alphaAt)(t,n.uniforms.layerHeight.value,n.layer.coverage,n.uniforms.fieldOffset.value)*(n.layer.type==="cirrus"?.2:.95)));return i}disposeDeck(t){t.volume?.dispose(),t.surface&&(t.surface.removeFromParent(),t.surface.geometry.dispose(),t.surface.material.dispose())}dispose(){this.halo&&(this.halo.hosted=!1),this.halo=void 0;for(const t of this.decks.values())this.disposeDeck(t);this.decks.clear(),this.noise?.dispose()}}class Rt{static RESPONSE_EXPONENT=.74;static DAYLIGHT_ANCHOR_CD_M2=3e3;static DAYLIGHT_ANCHOR_RESPONSE=.42;static NIGHT_ANCHOR_CD_M2=172e-6;static NIGHT_ANCHOR_RESPONSE=.006;static anchoredSemiSaturation(t,e){const i=Rt.anchorResponse(e);return t*(1/i-1)**(1/Rt.RESPONSE_EXPONENT)}static anchorResponse(t){return Rt.lightnessOf(t)}static fromLightness(t){const e=(100*t+16)/116;return e>6/29?e**3:3*(6/29)**2*(e-4/29)}static lightnessOf(t){const e=Math.max(t,0);return(e>216/24389?116*Math.cbrt(e)-16:24389/27*e)/100}static get ADAPTATION_EXPONENT(){const t=Rt.anchoredSemiSaturation(Rt.DAYLIGHT_ANCHOR_CD_M2,Rt.DAYLIGHT_ANCHOR_RESPONSE),e=Rt.anchoredSemiSaturation(Rt.NIGHT_ANCHOR_CD_M2,Rt.NIGHT_ANCHOR_RESPONSE);return Math.log(t/e)/Math.log(Rt.DAYLIGHT_ANCHOR_CD_M2/Rt.NIGHT_ANCHOR_CD_M2)}static ROD_HALF_LUMINANCE_CD_M2=.04;static SCOTOPIC_TINT=[.853,.995,1.483];static get SEMI_SATURATION_SCALE(){return Rt.anchoredSemiSaturation(Rt.DAYLIGHT_ANCHOR_CD_M2,Rt.DAYLIGHT_ANCHOR_RESPONSE)/Rt.DAYLIGHT_ANCHOR_CD_M2**Rt.ADAPTATION_EXPONENT}static rodShare(t){return Rt.ROD_HALF_LUMINANCE_CD_M2/(Rt.ROD_HALF_LUMINANCE_CD_M2+Math.max(t,0))}static MOONLIT_ANCHOR_CD_M2=.0035;static MOONLIT_ANCHOR_RESPONSE=.0075;static semiSaturation(t){const e=Rt.MOONLIT_ANCHOR_RESPONSE,i=Math.max(t,1e-9),s=[[Rt.NIGHT_ANCHOR_CD_M2,Rt.NIGHT_ANCHOR_RESPONSE],[Rt.MOONLIT_ANCHOR_CD_M2,e],[Rt.DAYLIGHT_ANCHOR_CD_M2,Rt.DAYLIGHT_ANCHOR_RESPONSE]].map(([l,h])=>[Math.log(l),Math.log(Rt.anchoredSemiSaturation(l,h))]),r=Math.log(i),[o,c]=r<s[1][0]?[s[0],s[1]]:[s[1],s[2]];return Math.exp(o[1]+(c[1]-o[1])*(r-o[0])/(c[0]-o[0]))}static response(t,e){const i=Rt.RESPONSE_EXPONENT,n=Math.max(t,0)**i;return n/(n+Rt.semiSaturation(e)**i)}static displayOf(t,e,i,n=Rt.rodShare(i)){const s=(1-n)*t[1]+n*e,r=Rt.response(s,i),[o,c,l]=Pi.linearSrgbOf(t),h=Math.max(t[1],1e-12),u=Rt.SCOTOPIC_TINT,d=.2126*u[0]+.7152*u[1]+.0722*u[2],f=(p,v)=>Math.max(0,(1-n)*p/h+n*v/d)*r;return[f(o,u[0]),f(c,u[1]),f(l,u[2])]}static relativeOf(t,e,i,n=Rt.rodShare(i)){const s=(1-n)*t[1]+n*e,r=Math.max(s,0)/Rt.semiSaturation(i),[o,c,l]=Pi.linearSrgbOf(t),h=Math.max(t[1],1e-12),u=Rt.SCOTOPIC_TINT,d=.2126*u[0]+.7152*u[1]+.0722*u[2],f=(p,v)=>Math.max(0,(1-n)*p/h+n*v/d)*r;return[f(o,u[0]),f(c,u[1]),f(l,u[2])]}static respond(t){const e=Math.max(t,0)**Rt.RESPONSE_EXPONENT;return e/(e+1)}static relativeOfResponse(t){const e=Math.min(Math.max(t,0),.995);return(e/(1-e))**(1/Rt.RESPONSE_EXPONENT)}static finish(t){const e=.2126*t[0]+.7152*t[1]+.0722*t[2];if(!(e>0))return[0,0,0];const i=Rt.fromLightness(Rt.respond(e)),n=i/e,s=[t[0]*n,t[1]*n,t[2]*n],r=Math.max(...s);if(r<=1)return s;const o=(1-i)/(r-i);return s.map(c=>i+(c-i)*o)}}const _2=`
6852
6852
  vec3 encodeSrgb(vec3 linear) {
6853
6853
  vec3 clamped = max(linear, vec3(0.0));
6854
6854
  vec3 low = clamped * 12.92;
@@ -7014,11 +7014,11 @@ vec3 finish(vec3 relative, vec4 overlay) {
7014
7014
  * @fileoverview Astronomy calculation library for browser scripting and Node.js.
7015
7015
  * @author Don Cross <cosinekitty@gmail.com>
7016
7016
  * @license MIT
7017
- */const em=173.1446326846693,Ls=14959787069098932e-8,mt=.017453292519943295,V1=.26179938779914946,fs=57.29577951308232,E2=3.819718634205488,uT=365.24217,W1=new Date("2000-01-01T12:00:00Z"),js=2*Math.PI,Er=3600*(180/Math.PI),Oo=484813681109536e-20,A2=10800*60,dT=2*A2,X1=7292115e-11,fT=A2/Math.PI,pT=-.17-5*Math.log10(fT),mT=29.530588,gT=24*3600,Fc=695700,vT=Fc/Ls,Z0=.996647180302104,MT=Z0*Z0,J0=6378.1366,yT=J0/Ls,xT=1737.4,bT=1736,ST=bT/Ls,T2=81.30056,im=.0002959122082855911,j0=2825345909524226e-22,Q0=8459715185680659e-23,tp=1292024916781969e-23,ep=1524358900784276e-23;function Fu(a){if(a!==!0&&a!==!1)throw console.trace(),`Value is not boolean: ${a}`;return a}function Si(a){if(!Number.isFinite(a))throw console.trace(),`Value is not a finite number: ${a}`;return a}function So(a){return a-Math.floor(a)}function R2(a,t){const e=a.x*a.x+a.y*a.y+a.z*a.z;if(Math.abs(e)<1e-8)throw"AngleBetween: first vector is too short.";const i=t.x*t.x+t.y*t.y+t.z*t.z;if(Math.abs(i)<1e-8)throw"AngleBetween: second vector is too short.";const n=(a.x*t.x+a.y*t.y+a.z*t.z)/Math.sqrt(e*i);return n<=-1?180:n>=1?0:fs*Math.acos(n)}var ut;(function(a){a.Sun="Sun",a.Moon="Moon",a.Mercury="Mercury",a.Venus="Venus",a.Earth="Earth",a.Mars="Mars",a.Jupiter="Jupiter",a.Saturn="Saturn",a.Uranus="Uranus",a.Neptune="Neptune",a.Pluto="Pluto",a.SSB="SSB",a.EMB="EMB",a.Star1="Star1",a.Star2="Star2",a.Star3="Star3",a.Star4="Star4",a.Star5="Star5",a.Star6="Star6",a.Star7="Star7",a.Star8="Star8"})(ut||(ut={}));const wT=[ut.Star1,ut.Star2,ut.Star3,ut.Star4,ut.Star5,ut.Star6,ut.Star7,ut.Star8],_T=[{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0}];function ET(a){const t=wT.indexOf(a);return t>=0?_T[t]:null}function nm(a){const t=ET(a);return t&&t.dist>0?t:null}var Ti;(function(a){a[a.From2000=0]="From2000",a[a.Into2000=1]="Into2000"})(Ti||(Ti={}));const zs={Mercury:[[[[4.40250710144,0,0],[.40989414977,1.48302034195,26087.9031415742],[.050462942,4.47785489551,52175.8062831484],[.00855346844,1.16520322459,78263.70942472259],[.00165590362,4.11969163423,104351.61256629678],[.00034561897,.77930768443,130439.51570787099],[7583476e-11,3.71348404924,156527.41884944518]],[[26087.90313685529,0,0],[.01131199811,6.21874197797,26087.9031415742],[.00292242298,3.04449355541,52175.8062831484],[.00075775081,6.08568821653,78263.70942472259],[.00019676525,2.80965111777,104351.61256629678]]],[[[.11737528961,1.98357498767,26087.9031415742],[.02388076996,5.03738959686,52175.8062831484],[.01222839532,3.14159265359,0],[.0054325181,1.79644363964,78263.70942472259],[.0012977877,4.83232503958,104351.61256629678],[.00031866927,1.58088495658,130439.51570787099],[7963301e-11,4.60972126127,156527.41884944518]],[[.00274646065,3.95008450011,26087.9031415742],[.00099737713,3.14159265359,0]]],[[[.39528271651,0,0],[.07834131818,6.19233722598,26087.9031415742],[.00795525558,2.95989690104,52175.8062831484],[.00121281764,6.01064153797,78263.70942472259],[.00021921969,2.77820093972,104351.61256629678],[4354065e-11,5.82894543774,130439.51570787099]],[[.0021734774,4.65617158665,26087.9031415742],[.00044141826,1.42385544001,52175.8062831484]]]],Venus:[[[[3.17614666774,0,0],[.01353968419,5.59313319619,10213.285546211],[.00089891645,5.30650047764,20426.571092422],[5477194e-11,4.41630661466,7860.4193924392],[3455741e-11,2.6996444782,11790.6290886588],[2372061e-11,2.99377542079,3930.2096962196],[1317168e-11,5.18668228402,26.2983197998],[1664146e-11,4.25018630147,1577.3435424478],[1438387e-11,4.15745084182,9683.5945811164],[1200521e-11,6.15357116043,30639.856638633]],[[10213.28554621638,0,0],[.00095617813,2.4640651111,10213.285546211],[7787201e-11,.6247848222,20426.571092422]]],[[[.05923638472,.26702775812,10213.285546211],[.00040107978,1.14737178112,20426.571092422],[.00032814918,3.14159265359,0]],[[.00287821243,1.88964962838,10213.285546211]]],[[[.72334820891,0,0],[.00489824182,4.02151831717,10213.285546211],[1658058e-11,4.90206728031,20426.571092422],[1378043e-11,1.12846591367,11790.6290886588],[1632096e-11,2.84548795207,7860.4193924392],[498395e-11,2.58682193892,9683.5945811164],[221985e-11,2.01346696541,19367.1891622328],[237454e-11,2.55136053886,15720.8387848784]],[[.00034551041,.89198706276,10213.285546211]]]],Earth:[[[[1.75347045673,0,0],[.03341656453,4.66925680415,6283.0758499914],[.00034894275,4.62610242189,12566.1516999828],[3417572e-11,2.82886579754,3.523118349],[3497056e-11,2.74411783405,5753.3848848968],[3135899e-11,3.62767041756,77713.7714681205],[2676218e-11,4.41808345438,7860.4193924392],[2342691e-11,6.13516214446,3930.2096962196],[1273165e-11,2.03709657878,529.6909650946],[1324294e-11,.74246341673,11506.7697697936],[901854e-11,2.04505446477,26.2983197998],[1199167e-11,1.10962946234,1577.3435424478],[857223e-11,3.50849152283,398.1490034082],[779786e-11,1.17882681962,5223.6939198022],[99025e-10,5.23268072088,5884.9268465832],[753141e-11,2.53339052847,5507.5532386674],[505267e-11,4.58292599973,18849.2275499742],[492392e-11,4.20505711826,775.522611324],[356672e-11,2.91954114478,.0673103028],[284125e-11,1.89869240932,796.2980068164],[242879e-11,.34481445893,5486.777843175],[317087e-11,5.84901948512,11790.6290886588],[271112e-11,.31486255375,10977.078804699],[206217e-11,4.80646631478,2544.3144198834],[205478e-11,1.86953770281,5573.1428014331],[202318e-11,2.45767790232,6069.7767545534],[126225e-11,1.08295459501,20.7753954924],[155516e-11,.83306084617,213.299095438]],[[6283.0758499914,0,0],[.00206058863,2.67823455808,6283.0758499914],[4303419e-11,2.63512233481,12566.1516999828]],[[8721859e-11,1.07253635559,6283.0758499914]]],[[],[[.00227777722,3.4137662053,6283.0758499914],[3805678e-11,3.37063423795,12566.1516999828]]],[[[1.00013988784,0,0],[.01670699632,3.09846350258,6283.0758499914],[.00013956024,3.05524609456,12566.1516999828],[308372e-10,5.19846674381,77713.7714681205],[1628463e-11,1.17387558054,5753.3848848968],[1575572e-11,2.84685214877,7860.4193924392],[924799e-11,5.45292236722,11506.7697697936],[542439e-11,4.56409151453,3930.2096962196],[47211e-10,3.66100022149,5884.9268465832],[85831e-11,1.27079125277,161000.6857376741],[57056e-11,2.01374292245,83996.84731811189],[55736e-11,5.2415979917,71430.69561812909],[174844e-11,3.01193636733,18849.2275499742],[243181e-11,4.2734953079,11790.6290886588]],[[.00103018607,1.10748968172,6283.0758499914],[1721238e-11,1.06442300386,12566.1516999828]],[[4359385e-11,5.78455133808,6283.0758499914]]]],Mars:[[[[6.20347711581,0,0],[.18656368093,5.0503710027,3340.6124266998],[.01108216816,5.40099836344,6681.2248533996],[.00091798406,5.75478744667,10021.8372800994],[.00027744987,5.97049513147,3.523118349],[.00010610235,2.93958560338,2281.2304965106],[.00012315897,.84956094002,2810.9214616052],[8926784e-11,4.15697846427,.0172536522],[8715691e-11,6.11005153139,13362.4497067992],[6797556e-11,.36462229657,398.1490034082],[7774872e-11,3.33968761376,5621.8429232104],[3575078e-11,1.6618650571,2544.3144198834],[4161108e-11,.22814971327,2942.4634232916],[3075252e-11,.85696614132,191.4482661116],[2628117e-11,.64806124465,3337.0893083508],[2937546e-11,6.07893711402,.0673103028],[2389414e-11,5.03896442664,796.2980068164],[2579844e-11,.02996736156,3344.1355450488],[1528141e-11,1.14979301996,6151.533888305],[1798806e-11,.65634057445,529.6909650946],[1264357e-11,3.62275122593,5092.1519581158],[1286228e-11,3.06796065034,2146.1654164752],[1546404e-11,2.91579701718,1751.539531416],[1024902e-11,3.69334099279,8962.4553499102],[891566e-11,.18293837498,16703.062133499],[858759e-11,2.4009381194,2914.0142358238],[832715e-11,2.46418619474,3340.5951730476],[83272e-10,4.49495782139,3340.629680352],[712902e-11,3.66335473479,1059.3819301892],[748723e-11,3.82248614017,155.4203994342],[723861e-11,.67497311481,3738.761430108],[635548e-11,2.92182225127,8432.7643848156],[655162e-11,.48864064125,3127.3133312618],[550474e-11,3.81001042328,.9803210682],[55275e-10,4.47479317037,1748.016413067],[425966e-11,.55364317304,6283.0758499914],[415131e-11,.49662285038,213.299095438],[472167e-11,3.62547124025,1194.4470102246],[306551e-11,.38052848348,6684.7479717486],[312141e-11,.99853944405,6677.7017350506],[293198e-11,4.22131299634,20.7753954924],[302375e-11,4.48618007156,3532.0606928114],[274027e-11,.54222167059,3340.545116397],[281079e-11,5.88163521788,1349.8674096588],[231183e-11,1.28242156993,3870.3033917944],[283602e-11,5.7688543494,3149.1641605882],[236117e-11,5.75503217933,3333.498879699],[274033e-11,.13372524985,3340.6797370026],[299395e-11,2.78323740866,6254.6266625236]],[[3340.61242700512,0,0],[.01457554523,3.60433733236,3340.6124266998],[.00168414711,3.92318567804,6681.2248533996],[.00020622975,4.26108844583,10021.8372800994],[3452392e-11,4.7321039319,3.523118349],[2586332e-11,4.60670058555,13362.4497067992],[841535e-11,4.45864030426,2281.2304965106]],[[.00058152577,2.04961712429,3340.6124266998],[.00013459579,2.45738706163,6681.2248533996]]],[[[.03197134986,3.76832042431,3340.6124266998],[.00298033234,4.10616996305,6681.2248533996],[.00289104742,0,0],[.00031365539,4.4465105309,10021.8372800994],[34841e-9,4.7881254926,13362.4497067992]],[[.00217310991,6.04472194776,3340.6124266998],[.00020976948,3.14159265359,0],[.00012834709,1.60810667915,6681.2248533996]]],[[[1.53033488271,0,0],[.1418495316,3.47971283528,3340.6124266998],[.00660776362,3.81783443019,6681.2248533996],[.00046179117,4.15595316782,10021.8372800994],[8109733e-11,5.55958416318,2810.9214616052],[7485318e-11,1.77239078402,5621.8429232104],[5523191e-11,1.3643630377,2281.2304965106],[382516e-10,4.49407183687,13362.4497067992],[2306537e-11,.09081579001,2544.3144198834],[1999396e-11,5.36059617709,3337.0893083508],[2484394e-11,4.9254563992,2942.4634232916],[1960195e-11,4.74249437639,3344.1355450488],[1167119e-11,2.11260868341,5092.1519581158],[1102816e-11,5.00908403998,398.1490034082],[899066e-11,4.40791133207,529.6909650946],[992252e-11,5.83861961952,6151.533888305],[807354e-11,2.10217065501,1059.3819301892],[797915e-11,3.44839203899,796.2980068164],[740975e-11,1.49906336885,2146.1654164752]],[[.01107433345,2.03250524857,3340.6124266998],[.00103175887,2.37071847807,6681.2248533996],[128772e-9,0,0],[.0001081588,2.70888095665,10021.8372800994]],[[.00044242249,.47930604954,3340.6124266998],[8138042e-11,.86998389204,6681.2248533996]]]],Jupiter:[[[[.59954691494,0,0],[.09695898719,5.06191793158,529.6909650946],[.00573610142,1.44406205629,7.1135470008],[.00306389205,5.41734730184,1059.3819301892],[.00097178296,4.14264726552,632.7837393132],[.00072903078,3.64042916389,522.5774180938],[.00064263975,3.41145165351,103.0927742186],[.00039806064,2.29376740788,419.4846438752],[.00038857767,1.27231755835,316.3918696566],[.00027964629,1.7845459182,536.8045120954],[.0001358973,5.7748104079,1589.0728952838],[8246349e-11,3.5822792584,206.1855484372],[8768704e-11,3.63000308199,949.1756089698],[7368042e-11,5.0810119427,735.8765135318],[626315e-10,.02497628807,213.299095438],[6114062e-11,4.51319998626,1162.4747044078],[4905396e-11,1.32084470588,110.2063212194],[5305285e-11,1.30671216791,14.2270940016],[5305441e-11,4.18625634012,1052.2683831884],[4647248e-11,4.69958103684,3.9321532631],[3045023e-11,4.31676431084,426.598190876],[2609999e-11,1.56667394063,846.0828347512],[2028191e-11,1.06376530715,3.1813937377],[1764763e-11,2.14148655117,1066.49547719],[1722972e-11,3.88036268267,1265.5674786264],[1920945e-11,.97168196472,639.897286314],[1633223e-11,3.58201833555,515.463871093],[1431999e-11,4.29685556046,625.6701923124],[973272e-11,4.09764549134,95.9792272178]],[[529.69096508814,0,0],[.00489503243,4.2208293947,529.6909650946],[.00228917222,6.02646855621,7.1135470008],[.00030099479,4.54540782858,1059.3819301892],[.0002072092,5.45943156902,522.5774180938],[.00012103653,.16994816098,536.8045120954],[6067987e-11,4.42422292017,103.0927742186],[5433968e-11,3.98480737746,419.4846438752],[4237744e-11,5.89008707199,14.2270940016]],[[.00047233601,4.32148536482,7.1135470008],[.00030649436,2.929777887,529.6909650946],[.00014837605,3.14159265359,0]]],[[[.02268615702,3.55852606721,529.6909650946],[.00109971634,3.90809347197,1059.3819301892],[.00110090358,0,0],[8101428e-11,3.60509572885,522.5774180938],[6043996e-11,4.25883108339,1589.0728952838],[6437782e-11,.30627119215,536.8045120954]],[[.00078203446,1.52377859742,529.6909650946]]],[[[5.20887429326,0,0],[.25209327119,3.49108639871,529.6909650946],[.00610599976,3.84115365948,1059.3819301892],[.00282029458,2.57419881293,632.7837393132],[.00187647346,2.07590383214,522.5774180938],[.00086792905,.71001145545,419.4846438752],[.00072062974,.21465724607,536.8045120954],[.00065517248,5.9799588479,316.3918696566],[.00029134542,1.67759379655,103.0927742186],[.00030135335,2.16132003734,949.1756089698],[.00023453271,3.54023522184,735.8765135318],[.00022283743,4.19362594399,1589.0728952838],[.00023947298,.2745803748,7.1135470008],[.00013032614,2.96042965363,1162.4747044078],[970336e-10,1.90669633585,206.1855484372],[.00012749023,2.71550286592,1052.2683831884],[7057931e-11,2.18184839926,1265.5674786264],[6137703e-11,6.26418240033,846.0828347512],[2616976e-11,2.00994012876,1581.959348283]],[[.0127180152,2.64937512894,529.6909650946],[.00061661816,3.00076460387,1059.3819301892],[.00053443713,3.89717383175,522.5774180938],[.00031185171,4.88276958012,536.8045120954],[.00041390269,0,0]]]],Saturn:[[[[.87401354025,0,0],[.11107659762,3.96205090159,213.299095438],[.01414150957,4.58581516874,7.1135470008],[.00398379389,.52112032699,206.1855484372],[.00350769243,3.30329907896,426.598190876],[.00206816305,.24658372002,103.0927742186],[792713e-9,3.84007056878,220.4126424388],[.00023990355,4.66976924553,110.2063212194],[.00016573588,.43719228296,419.4846438752],[.00014906995,5.76903183869,316.3918696566],[.0001582029,.93809155235,632.7837393132],[.00014609559,1.56518472,3.9321532631],[.00013160301,4.44891291899,14.2270940016],[.00015053543,2.71669915667,639.897286314],[.00013005299,5.98119023644,11.0457002639],[.00010725067,3.12939523827,202.2533951741],[5863206e-11,.23656938524,529.6909650946],[5227757e-11,4.20783365759,3.1813937377],[6126317e-11,1.76328667907,277.0349937414],[5019687e-11,3.17787728405,433.7117378768],[459255e-10,.61977744975,199.0720014364],[4005867e-11,2.24479718502,63.7358983034],[2953796e-11,.98280366998,95.9792272178],[387367e-10,3.22283226966,138.5174968707],[2461186e-11,2.03163875071,735.8765135318],[3269484e-11,.77492638211,949.1756089698],[1758145e-11,3.2658010994,522.5774180938],[1640172e-11,5.5050445305,846.0828347512],[1391327e-11,4.02333150505,323.5054166574],[1580648e-11,4.37265307169,309.2783226558],[1123498e-11,2.83726798446,415.5524906121],[1017275e-11,3.71700135395,227.5261894396],[848642e-11,3.1915017083,209.3669421749]],[[213.2990952169,0,0],[.01297370862,1.82834923978,213.299095438],[.00564345393,2.88499717272,7.1135470008],[.00093734369,1.06311793502,426.598190876],[.00107674962,2.27769131009,206.1855484372],[.00040244455,2.04108104671,220.4126424388],[.00019941774,1.2795439047,103.0927742186],[.00010511678,2.7488034213,14.2270940016],[6416106e-11,.38238295041,639.897286314],[4848994e-11,2.43037610229,419.4846438752],[4056892e-11,2.92133209468,110.2063212194],[3768635e-11,3.6496533078,3.9321532631]],[[.0011644133,1.17988132879,7.1135470008],[.00091841837,.0732519584,213.299095438],[.00036661728,0,0],[.00015274496,4.06493179167,206.1855484372]]],[[[.04330678039,3.60284428399,213.299095438],[.00240348302,2.85238489373,426.598190876],[.00084745939,0,0],[.00030863357,3.48441504555,220.4126424388],[.00034116062,.57297307557,206.1855484372],[.0001473407,2.11846596715,639.897286314],[9916667e-11,5.79003188904,419.4846438752],[6993564e-11,4.7360468972,7.1135470008],[4807588e-11,5.43305312061,316.3918696566]],[[.00198927992,4.93901017903,213.299095438],[.00036947916,3.14159265359,0],[.00017966989,.5197943111,426.598190876]]],[[[9.55758135486,0,0],[.52921382865,2.39226219573,213.299095438],[.01873679867,5.2354960466,206.1855484372],[.01464663929,1.64763042902,426.598190876],[.00821891141,5.93520042303,316.3918696566],[.00547506923,5.0153261898,103.0927742186],[.0037168465,2.27114821115,220.4126424388],[.00361778765,3.13904301847,7.1135470008],[.00140617506,5.70406606781,632.7837393132],[.00108974848,3.29313390175,110.2063212194],[.00069006962,5.94099540992,419.4846438752],[.00061053367,.94037691801,639.897286314],[.00048913294,1.55733638681,202.2533951741],[.00034143772,.19519102597,277.0349937414],[.00032401773,5.47084567016,949.1756089698],[.00020936596,.46349251129,735.8765135318],[9796004e-11,5.20477537945,1265.5674786264],[.00011993338,5.98050967385,846.0828347512],[208393e-9,1.52102476129,433.7117378768],[.00015298404,3.0594381494,529.6909650946],[6465823e-11,.17732249942,1052.2683831884],[.00011380257,1.7310542704,522.5774180938],[3419618e-11,4.94550542171,1581.959348283]],[[.0618298134,.2584351148,213.299095438],[.00506577242,.71114625261,206.1855484372],[.00341394029,5.79635741658,426.598190876],[.00188491195,.47215589652,220.4126424388],[.00186261486,3.14159265359,0],[.00143891146,1.40744822888,7.1135470008]],[[.00436902572,4.78671677509,213.299095438]]]],Uranus:[[[[5.48129294297,0,0],[.09260408234,.89106421507,74.7815985673],[.01504247898,3.6271926092,1.4844727083],[.00365981674,1.89962179044,73.297125859],[.00272328168,3.35823706307,149.5631971346],[.00070328461,5.39254450063,63.7358983034],[.00068892678,6.09292483287,76.2660712756],[.00061998615,2.26952066061,2.9689454166],[.00061950719,2.85098872691,11.0457002639],[.0002646877,3.14152083966,71.8126531507],[.00025710476,6.11379840493,454.9093665273],[.0002107885,4.36059339067,148.0787244263],[.00017818647,1.74436930289,36.6485629295],[.00014613507,4.73732166022,3.9321532631],[.00011162509,5.8268179635,224.3447957019],[.0001099791,.48865004018,138.5174968707],[9527478e-11,2.95516862826,35.1640902212],[7545601e-11,5.236265824,109.9456887885],[4220241e-11,3.23328220918,70.8494453042],[40519e-9,2.277550173,151.0476698429],[3354596e-11,1.0654900738,4.4534181249],[2926718e-11,4.62903718891,9.5612275556],[349034e-10,5.48306144511,146.594251718],[3144069e-11,4.75199570434,77.7505439839],[2922333e-11,5.35235361027,85.8272988312],[2272788e-11,4.36600400036,70.3281804424],[2051219e-11,1.51773566586,.1118745846],[2148602e-11,.60745949945,38.1330356378],[1991643e-11,4.92437588682,277.0349937414],[1376226e-11,2.04283539351,65.2203710117],[1666902e-11,3.62744066769,380.12776796],[1284107e-11,3.11347961505,202.2533951741],[1150429e-11,.93343589092,3.1813937377],[1533221e-11,2.58594681212,52.6901980395],[1281604e-11,.54271272721,222.8603229936],[1372139e-11,4.19641530878,111.4301614968],[1221029e-11,.1990065003,108.4612160802],[946181e-11,1.19253165736,127.4717966068],[1150989e-11,4.17898916639,33.6796175129]],[[74.7815986091,0,0],[.00154332863,5.24158770553,74.7815985673],[.00024456474,1.71260334156,1.4844727083],[9258442e-11,.4282973235,11.0457002639],[8265977e-11,1.50218091379,63.7358983034],[915016e-10,1.41213765216,149.5631971346]]],[[[.01346277648,2.61877810547,74.7815985673],[623414e-9,5.08111189648,149.5631971346],[.00061601196,3.14159265359,0],[9963722e-11,1.61603805646,76.2660712756],[992616e-10,.57630380333,73.297125859]],[[.00034101978,.01321929936,74.7815985673]]],[[[19.21264847206,0,0],[.88784984413,5.60377527014,74.7815985673],[.03440836062,.32836099706,73.297125859],[.0205565386,1.7829515933,149.5631971346],[.0064932241,4.52247285911,76.2660712756],[.00602247865,3.86003823674,63.7358983034],[.00496404167,1.40139935333,454.9093665273],[.00338525369,1.58002770318,138.5174968707],[.00243509114,1.57086606044,71.8126531507],[.00190522303,1.99809394714,1.4844727083],[.00161858838,2.79137786799,148.0787244263],[.00143706183,1.38368544947,11.0457002639],[.00093192405,.17437220467,36.6485629295],[.00071424548,4.24509236074,224.3447957019],[.00089806014,3.66105364565,109.9456887885],[.00039009723,1.66971401684,70.8494453042],[.00046677296,1.39976401694,35.1640902212],[.00039025624,3.36234773834,277.0349937414],[.00036755274,3.88649278513,146.594251718],[.00030348723,.70100838798,151.0476698429],[.00029156413,3.180563367,77.7505439839],[.00022637073,.72518687029,529.6909650946],[.00011959076,1.7504339214,984.6003316219],[.00025620756,5.25656086672,380.12776796]],[[.01479896629,3.67205697578,74.7815985673]]]],Neptune:[[[[5.31188633046,0,0],[.0179847553,2.9010127389,38.1330356378],[.01019727652,.48580922867,1.4844727083],[.00124531845,4.83008090676,36.6485629295],[.00042064466,5.41054993053,2.9689454166],[.00037714584,6.09221808686,35.1640902212],[.00033784738,1.24488874087,76.2660712756],[.00016482741,7727998e-11,491.5579294568],[9198584e-11,4.93747051954,39.6175083461],[899425e-10,.27462171806,175.1660598002]],[[38.13303563957,0,0],[.00016604172,4.86323329249,1.4844727083],[.00015744045,2.27887427527,38.1330356378]]],[[[.03088622933,1.44104372644,38.1330356378],[.00027780087,5.91271884599,76.2660712756],[.00027623609,0,0],[.00015355489,2.52123799551,36.6485629295],[.00015448133,3.50877079215,39.6175083461]]],[[[30.07013205828,0,0],[.27062259632,1.32999459377,38.1330356378],[.01691764014,3.25186135653,36.6485629295],[.00807830553,5.18592878704,1.4844727083],[.0053776051,4.52113935896,35.1640902212],[.00495725141,1.5710564165,491.5579294568],[.00274571975,1.84552258866,175.1660598002],[.0001201232,1.92059384991,1021.2488945514],[.00121801746,5.79754470298,76.2660712756],[.00100896068,.3770272493,73.297125859],[.00135134092,3.37220609835,39.6175083461],[7571796e-11,1.07149207335,388.4651552382]]]]};function AT(a){var t,e,i,n,s,r,o;const c=2e3+(a-14)/uT;return c<-500?(t=(c-1820)/100,-20+32*t*t):c<500?(t=c/100,e=t*t,i=t*e,n=e*e,s=e*i,r=i*i,10583.6-1014.41*t+33.78311*e-5.952053*i-.1798452*n+.022174192*s+.0090316521*r):c<1600?(t=(c-1e3)/100,e=t*t,i=t*e,n=e*e,s=e*i,r=i*i,1574.2-556.01*t+71.23472*e+.319781*i-.8503463*n-.005050998*s+.0083572073*r):c<1700?(t=c-1600,e=t*t,i=t*e,120-.9808*t-.01532*e+i/7129):c<1800?(t=c-1700,e=t*t,i=t*e,n=e*e,8.83+.1603*t-.0059285*e+13336e-8*i-n/1174e3):c<1860?(t=c-1800,e=t*t,i=t*e,n=e*e,s=e*i,r=i*i,o=i*n,13.72-.332447*t+.0068612*e+.0041116*i-37436e-8*n+121272e-10*s-1699e-10*r+875e-12*o):c<1900?(t=c-1860,e=t*t,i=t*e,n=e*e,s=e*i,7.62+.5737*t-.251754*e+.01680668*i-.0004473624*n+s/233174):c<1920?(t=c-1900,e=t*t,i=t*e,n=e*e,-2.79+1.494119*t-.0598939*e+.0061966*i-197e-6*n):c<1941?(t=c-1920,e=t*t,i=t*e,21.2+.84493*t-.0761*e+.0020936*i):c<1961?(t=c-1950,e=t*t,i=t*e,29.07+.407*t-e/233+i/2547):c<1986?(t=c-1975,e=t*t,i=t*e,45.45+1.067*t-e/260-i/718):c<2005?(t=c-2e3,e=t*t,i=t*e,n=e*e,s=e*i,63.86+.3345*t-.060374*e+.0017275*i+651814e-9*n+2373599e-11*s):c<2050?(t=c-2e3,62.92+.32217*t+.005589*t*t):c<2150?(t=(c-1820)/100,-20+32*t*t-.5628*(2150-c)):(t=(c-1820)/100,-20+32*t*t)}let TT=AT;function Y1(a){return a+TT(a)/86400}class La{constructor(t){if(t instanceof La){this.date=t.date,this.ut=t.ut,this.tt=t.tt;return}const e=1e3*3600*24;if(t instanceof Date&&Number.isFinite(t.getTime())){this.date=t,this.ut=(t.getTime()-W1.getTime())/e,this.tt=Y1(this.ut);return}if(Number.isFinite(t)){this.date=new Date(W1.getTime()+t*e),this.ut=t,this.tt=Y1(this.ut);return}throw"Argument must be a Date object, an AstroTime object, or a numeric UTC Julian date."}static FromTerrestrialTime(t){let e=new La(t);for(;;){const i=t-e.tt;if(Math.abs(i)<1e-12)return e;e=e.AddDays(i)}}toString(){return this.date.toISOString()}AddDays(t){return new La(this.ut+t)}}function RT(a,t,e){return new La(a.ut+e*(t.ut-a.ut))}function Ne(a){return a instanceof La?a:new La(a)}function DT(a){function t(d){return d%dT*Oo}const e=a.tt/36525,i=t(128710479305e-5+e*1295965810481e-4),n=t(335779.526232+e*17395272628478e-4),s=t(107226070369e-5+e*1602961601209e-3),r=t(450160.398036-e*69628905431e-4);let o=Math.sin(r),c=Math.cos(r),l=(-172064161-174666*e)*o+33386*c,h=(92052331+9086*e)*c+15377*o,u=2*(n-s+r);return o=Math.sin(u),c=Math.cos(u),l+=(-13170906-1675*e)*o-13696*c,h+=(5730336-3015*e)*c-4587*o,u=2*(n+r),o=Math.sin(u),c=Math.cos(u),l+=(-2276413-234*e)*o+2796*c,h+=(978459-485*e)*c+1374*o,u=2*r,o=Math.sin(u),c=Math.cos(u),l+=(2074554+207*e)*o-698*c,h+=(-897492+470*e)*c-291*o,o=Math.sin(i),c=Math.cos(i),l+=(1475877-3633*e)*o+11817*c,h+=(73871-184*e)*c-1924*o,{dpsi:-135e-6+l*1e-7,deps:388e-6+h*1e-7}}function D2(a){var t=a.tt/36525,e=((((-434e-10*t-576e-9)*t+.0020034)*t-1831e-7)*t-46.836769)*t+84381.406;return e/3600}var mh;function _l(a){if(!mh||Math.abs(mh.tt-a.tt)>1e-6){const t=DT(a),e=D2(a),i=e+t.deps/3600;mh={tt:a.tt,dpsi:t.dpsi,deps:t.deps,ee:t.dpsi*Math.cos(e*mt)/15,mobl:e,tobl:i}}return mh}function IT(a,t){const e=a*mt,i=Math.cos(e),n=Math.sin(e);return[t[0],t[1]*i-t[2]*n,t[1]*n+t[2]*i]}function CT(a,t){return IT(D2(a),t)}function I2(a){const t=a.tt/36525;function e(Lt,_t){const Ht=[];let Vt;for(Vt=0;Vt<=_t-Lt;++Vt)Ht.push(0);return{min:Lt,array:Ht}}function i(Lt,_t,Ht,Vt){const Wt=[];for(let Te=0;Te<=_t-Lt;++Te)Wt.push(e(Ht,Vt));return{min:Lt,array:Wt}}function n(Lt,_t,Ht){const Vt=Lt.array[_t-Lt.min];return Vt.array[Ht-Vt.min]}function s(Lt,_t,Ht,Vt){const Wt=Lt.array[_t-Lt.min];Wt.array[Ht-Wt.min]=Vt}let r,o,c,l,h,u,d,f,p,v,m,g,b,S,M,x,_,E,y,T,I,C,P,B=i(-6,6,1,4),W=i(-6,6,1,4);function O(Lt,_t){return n(B,Lt,_t)}function H(Lt,_t){return n(W,Lt,_t)}function U(Lt,_t,Ht){return s(B,Lt,_t,Ht)}function q(Lt,_t,Ht){return s(W,Lt,_t,Ht)}function Q(Lt,_t,Ht,Vt,Wt){Wt(Lt*Ht-_t*Vt,_t*Ht+Lt*Vt)}function J(Lt){return Math.sin(js*Lt)}d=t*t,p=0,P=0,m=0,g=3422.7;var it=J(.19833+.05611*t),ot=J(.27869+.04508*t),$t=J(.16827-.36903*t),re=J(.34734-5.37261*t),jt=J(.10498-5.37899*t),$=J(.42681-.41855*t),rt=J(.14943-5.37511*t);for(E=.84*it+.31*ot+14.27*$t+7.26*re+.28*jt+.24*$,y=2.94*it+.31*ot+14.27*$t+9.34*re+1.12*jt+.83*$,T=-6.4*it-1.89*$,I=.21*it+.31*ot+14.27*$t-88.7*re-15.3*jt+.24*$-1.86*rt,C=E-T,f=-3332e-9*J(.59734-5.37261*t)-539e-9*J(.35498-5.37899*t)-64e-9*J(.39943-5.37511*t),b=js*So(.60643382+1336.85522467*t-313e-8*d)+E/Er,S=js*So(.37489701+1325.55240982*t+2565e-8*d)+y/Er,M=js*So(.99312619+99.99735956*t-44e-8*d)+T/Er,x=js*So(.25909118+1342.2278298*t-892e-8*d)+I/Er,_=js*So(.82736186+1236.85308708*t-397e-8*d)+C/Er,h=1;h<=4;++h){switch(h){case 1:c=S,o=4,l=1.000002208;break;case 2:c=M,o=3,l=.997504612-.002495388*t;break;case 3:c=x,o=4,l=1.000002708+139.978*f;break;case 4:c=_,o=6,l=1;break;default:throw`Internal error: I = ${h}`}for(U(0,h,1),U(1,h,Math.cos(c)*l),q(0,h,0),q(1,h,Math.sin(c)*l),u=2;u<=o;++u)Q(O(u-1,h),H(u-1,h),O(1,h),H(1,h),(Lt,_t)=>(U(u,h,Lt),q(u,h,_t)));for(u=1;u<=o;++u)U(-u,h,O(u,h)),q(-u,h,-H(u,h))}function nt(Lt,_t,Ht,Vt){for(var Wt={x:1,y:0},Te=[0,Lt,_t,Ht,Vt],Re=1;Re<=4;++Re)Te[Re]!==0&&Q(Wt.x,Wt.y,O(Te[Re],Re),H(Te[Re],Re),(ci,ei)=>(Wt.x=ci,Wt.y=ei));return Wt}function z(Lt,_t,Ht,Vt,Wt,Te,Re,ci){var ei=nt(Wt,Te,Re,ci);p+=Lt*ei.y,P+=_t*ei.y,m+=Ht*ei.x,g+=Vt*ei.x}z(13.902,14.06,-.001,.2607,0,0,0,4),z(.403,-4.01,.394,.0023,0,0,0,3),z(2369.912,2373.36,.601,28.2333,0,0,0,2),z(-125.154,-112.79,-.725,-.9781,0,0,0,1),z(1.979,6.98,-.445,.0433,1,0,0,4),z(191.953,192.72,.029,3.0861,1,0,0,2),z(-8.466,-13.51,.455,-.1093,1,0,0,1),z(22639.5,22609.07,.079,186.5398,1,0,0,0),z(18.609,3.59,-.094,.0118,1,0,0,-1),z(-4586.465,-4578.13,-.077,34.3117,1,0,0,-2),z(3.215,5.44,.192,-.0386,1,0,0,-3),z(-38.428,-38.64,.001,.6008,1,0,0,-4),z(-.393,-1.43,-.092,.0086,1,0,0,-6),z(-.289,-1.59,.123,-.0053,0,1,0,4),z(-24.42,-25.1,.04,-.3,0,1,0,2),z(18.023,17.93,.007,.1494,0,1,0,1),z(-668.146,-126.98,-1.302,-.3997,0,1,0,0),z(.56,.32,-.001,-.0037,0,1,0,-1),z(-165.145,-165.06,.054,1.9178,0,1,0,-2),z(-1.877,-6.46,-.416,.0339,0,1,0,-4),z(.213,1.02,-.074,.0054,2,0,0,4),z(14.387,14.78,-.017,.2833,2,0,0,2),z(-.586,-1.2,.054,-.01,2,0,0,1),z(769.016,767.96,.107,10.1657,2,0,0,0),z(1.75,2.01,-.018,.0155,2,0,0,-1),z(-211.656,-152.53,5.679,-.3039,2,0,0,-2),z(1.225,.91,-.03,-.0088,2,0,0,-3),z(-30.773,-34.07,-.308,.3722,2,0,0,-4),z(-.57,-1.4,-.074,.0109,2,0,0,-6),z(-2.921,-11.75,.787,-.0484,1,1,0,2),z(1.267,1.52,-.022,.0164,1,1,0,1),z(-109.673,-115.18,.461,-.949,1,1,0,0),z(-205.962,-182.36,2.056,1.4437,1,1,0,-2),z(.233,.36,.012,-.0025,1,1,0,-3),z(-4.391,-9.66,-.471,.0673,1,1,0,-4),z(.283,1.53,-.111,.006,1,-1,0,4),z(14.577,31.7,-1.54,.2302,1,-1,0,2),z(147.687,138.76,.679,1.1528,1,-1,0,0),z(-1.089,.55,.021,0,1,-1,0,-1),z(28.475,23.59,-.443,-.2257,1,-1,0,-2),z(-.276,-.38,-.006,-.0036,1,-1,0,-3),z(.636,2.27,.146,-.0102,1,-1,0,-4),z(-.189,-1.68,.131,-.0028,0,2,0,2),z(-7.486,-.66,-.037,-.0086,0,2,0,0),z(-8.096,-16.35,-.74,.0918,0,2,0,-2),z(-5.741,-.04,0,-9e-4,0,0,2,2),z(.255,0,0,0,0,0,2,1),z(-411.608,-.2,0,-.0124,0,0,2,0),z(.584,.84,0,.0071,0,0,2,-1),z(-55.173,-52.14,0,-.1052,0,0,2,-2),z(.254,.25,0,-.0017,0,0,2,-3),z(.025,-1.67,0,.0031,0,0,2,-4),z(1.06,2.96,-.166,.0243,3,0,0,2),z(36.124,50.64,-1.3,.6215,3,0,0,0),z(-13.193,-16.4,.258,-.1187,3,0,0,-2),z(-1.187,-.74,.042,.0074,3,0,0,-4),z(-.293,-.31,-.002,.0046,3,0,0,-6),z(-.29,-1.45,.116,-.0051,2,1,0,2),z(-7.649,-10.56,.259,-.1038,2,1,0,0),z(-8.627,-7.59,.078,-.0192,2,1,0,-2),z(-2.74,-2.54,.022,.0324,2,1,0,-4),z(1.181,3.32,-.212,.0213,2,-1,0,2),z(9.703,11.67,-.151,.1268,2,-1,0,0),z(-.352,-.37,.001,-.0028,2,-1,0,-1),z(-2.494,-1.17,-.003,-.0017,2,-1,0,-2),z(.36,.2,-.012,-.0043,2,-1,0,-4),z(-1.167,-1.25,.008,-.0106,1,2,0,0),z(-7.412,-6.12,.117,.0484,1,2,0,-2),z(-.311,-.65,-.032,.0044,1,2,0,-4),z(.757,1.82,-.105,.0112,1,-2,0,2),z(2.58,2.32,.027,.0196,1,-2,0,0),z(2.533,2.4,-.014,-.0212,1,-2,0,-2),z(-.344,-.57,-.025,.0036,0,3,0,-2),z(-.992,-.02,0,0,1,0,2,2),z(-45.099,-.02,0,-.001,1,0,2,0),z(-.179,-9.52,0,-.0833,1,0,2,-2),z(-.301,-.33,0,.0014,1,0,2,-4),z(-6.382,-3.37,0,-.0481,1,0,-2,2),z(39.528,85.13,0,-.7136,1,0,-2,0),z(9.366,.71,0,-.0112,1,0,-2,-2),z(.202,.02,0,0,1,0,-2,-4),z(.415,.1,0,.0013,0,1,2,0),z(-2.152,-2.26,0,-.0066,0,1,2,-2),z(-1.44,-1.3,0,.0014,0,1,-2,2),z(.384,-.04,0,0,0,1,-2,-2),z(1.938,3.6,-.145,.0401,4,0,0,0),z(-.952,-1.58,.052,-.013,4,0,0,-2),z(-.551,-.94,.032,-.0097,3,1,0,0),z(-.482,-.57,.005,-.0045,3,1,0,-2),z(.681,.96,-.026,.0115,3,-1,0,0),z(-.297,-.27,.002,-9e-4,2,2,0,-2),z(.254,.21,-.003,0,2,-2,0,-2),z(-.25,-.22,.004,.0014,1,3,0,-2),z(-3.996,0,0,4e-4,2,0,2,0),z(.557,-.75,0,-.009,2,0,2,-2),z(-.459,-.38,0,-.0053,2,0,-2,2),z(-1.298,.74,0,4e-4,2,0,-2,0),z(.538,1.14,0,-.0141,2,0,-2,-2),z(.263,.02,0,0,1,1,2,0),z(.426,.07,0,-6e-4,1,1,-2,-2),z(-.304,.03,0,3e-4,1,-1,2,0),z(-.372,-.19,0,-.0027,1,-1,-2,2),z(.418,0,0,0,0,0,4,0),z(-.33,-.04,0,0,3,0,2,0);function It(Lt,_t,Ht,Vt,Wt){return Lt*nt(_t,Ht,Vt,Wt).y}v=0,v+=It(-526.069,0,0,1,-2),v+=It(-3.352,0,0,1,-4),v+=It(44.297,1,0,1,-2),v+=It(-6,1,0,1,-4),v+=It(20.599,-1,0,1,0),v+=It(-30.598,-1,0,1,-2),v+=It(-24.649,-2,0,1,0),v+=It(-2,-2,0,1,-2),v+=It(-22.571,0,1,1,-2),v+=It(10.985,0,-1,1,-2),p+=.82*J(.7736-62.5512*t)+.31*J(.0466-125.1025*t)+.35*J(.5785-25.1042*t)+.66*J(.4591+1335.8075*t)+.64*J(.313-91.568*t)+1.14*J(.148+1331.2898*t)+.21*J(.5918+1056.5859*t)+.44*J(.5784+1322.8595*t)+.24*J(.2275-5.7374*t)+.28*J(.2965+2.6929*t)+.33*J(.3132+6.3368*t),r=x+P/Er;let Ut=(1.000002708+139.978*f)*(18518.511+1.189+m)*Math.sin(r)-6.24*Math.sin(3*r)+v;return{geo_eclip_lon:js*So((b+p/Er)/js),geo_eclip_lat:Math.PI/(180*3600)*Ut,distance_au:Er*yT/(.999953253*g)}}function C2(a,t){return[a.rot[0][0]*t[0]+a.rot[1][0]*t[1]+a.rot[2][0]*t[2],a.rot[0][1]*t[0]+a.rot[1][1]*t[1]+a.rot[2][1]*t[2],a.rot[0][2]*t[0]+a.rot[1][2]*t[1]+a.rot[2][2]*t[2]]}function pl(a,t,e){const i=sm(t,e);return C2(i,a)}function sm(a,t){const e=a.tt/36525;let i=84381.406,n=((((-951e-10*e+132851e-9)*e-.00114045)*e-1.0790069)*e+5038.481507)*e,s=((((3337e-10*e-467e-9)*e-.00772503)*e+.0512623)*e-.025754)*e+i,r=((((-56e-9*e+170663e-9)*e-.00121197)*e-2.3814292)*e+10.556403)*e;i*=Oo,n*=Oo,s*=Oo,r*=Oo;const o=Math.sin(i),c=Math.cos(i),l=Math.sin(-n),h=Math.cos(-n),u=Math.sin(-s),d=Math.cos(-s),f=Math.sin(r),p=Math.cos(r),v=p*h-l*f*d,m=p*l*c+f*d*h*c-o*f*u,g=p*l*o+f*d*h*o+c*f*u,b=-f*h-l*p*d,S=-f*l*c+p*d*h*c-o*p*u,M=-f*l*o+p*d*h*o+c*p*u,x=l*u,_=-u*h*c-o*d,E=-u*h*o+d*c;if(t===Ti.Into2000)return new Ws([[v,m,g],[b,S,M],[x,_,E]]);if(t===Ti.From2000)return new Ws([[v,b,x],[m,S,_],[g,M,E]]);throw"Invalid precess direction"}function PT(a){const t=.779057273264+.00273781191135448*a.ut,e=a.ut%1;let i=360*((t+e)%1);return i<0&&(i+=360),i}let gh;function El(a){if(!gh||gh.tt!==a.tt){const t=a.tt/36525;let e=15*_l(a).ee;const i=PT(a);let s=((e+.014506+((((-368e-10*t-29956e-9)*t-44e-8)*t+1.3915817)*t+4612.156534)*t)/3600+i)%360/15;s<0&&(s+=24),gh={tt:a.tt,st:s}}return gh.st}function OT(a){const t=Ne(a);return El(t)}function P2(a,t){const e=a.latitude*mt,i=Math.sin(e),n=Math.cos(e),s=1/Math.hypot(n,Z0*i),r=MT*s,o=a.height/1e3,c=J0*s+o,l=J0*r+o,h=(15*t+a.longitude)*mt,u=Math.sin(h),d=Math.cos(h);return{pos:[c*n*d/Ls,c*n*u/Ls,l*i/Ls],vel:[-X1*c*n*u*86400/Ls,X1*c*n*d*86400/Ls,0]}}function Uu(a,t,e){const i=rm(t,e);return C2(i,a)}function rm(a,t){const e=_l(a),i=e.mobl*mt,n=e.tobl*mt,s=e.dpsi*Oo,r=Math.cos(i),o=Math.sin(i),c=Math.cos(n),l=Math.sin(n),h=Math.cos(s),u=Math.sin(s),d=h,f=-u*r,p=-u*o,v=u*c,m=h*r*c+o*l,g=h*o*c-r*l,b=u*l,S=h*r*l-o*c,M=h*o*l+r*c;if(t===Ti.From2000)return new Ws([[d,v,b],[f,m,S],[p,g,M]]);if(t===Ti.Into2000)return new Ws([[d,f,p],[v,m,g],[b,S,M]]);throw"Invalid precess direction"}function cd(a,t,e){return e===Ti.Into2000?pl(Uu(a,t,e),t,e):Uu(pl(a,t,e),t,e)}function O2(a,t){const e=El(a),i=P2(t,e).pos;return cd(i,a,Ti.Into2000)}class ge{constructor(t,e,i,n){this.x=t,this.y=e,this.z=i,this.t=n}Length(){return Math.hypot(this.x,this.y,this.z)}}class zr{constructor(t,e,i,n,s,r,o){this.x=t,this.y=e,this.z=i,this.vx=n,this.vy=s,this.vz=r,this.t=o}}class ld{constructor(t,e,i){this.lat=Si(t),this.lon=Si(e),this.dist=Si(i)}}class ip{constructor(t,e,i,n){this.ra=Si(t),this.dec=Si(e),this.dist=Si(i),this.vec=n}}class Ws{constructor(t){this.rot=t}}class LT{constructor(t,e,i,n){this.azimuth=Si(t),this.altitude=Si(e),this.ra=Si(i),this.dec=Si(n)}}class NT{constructor(t,e,i){this.vec=t,this.elat=Si(e),this.elon=Si(i)}}function L2(a,t){return new ge(a[0],a[1],a[2],t)}function kT(a,t){const e=L2(a,t),i=e.x*e.x+e.y*e.y,n=Math.sqrt(i+e.z*e.z);if(i===0){if(e.z===0)throw"Indeterminate sky coordinates";return new ip(0,e.z<0?-90:90,n,e)}let s=E2*Math.atan2(e.y,e.x);s<0&&(s+=24);const r=fs*Math.atan2(a[2],Math.sqrt(i));return new ip(s,r,n,e)}function Wo(a,t){const e=a*mt,i=Math.cos(e),n=Math.sin(e);return[i*t[0]+n*t[1],i*t[1]-n*t[0],t[2]]}function am(a,t,e,i,n){let s=Ne(a);hd(t),Si(e),Si(i);const r=Math.sin(t.latitude*mt),o=Math.cos(t.latitude*mt),c=Math.sin(t.longitude*mt),l=Math.cos(t.longitude*mt),h=Math.sin(i*mt),u=Math.cos(i*mt),d=Math.sin(e*V1),f=Math.cos(e*V1);let p=[o*l,o*c,r],v=[-r*l,-r*c,o],m=[c,-l,0];const g=-15*El(s);let b=Wo(g,p),S=Wo(g,v),M=Wo(g,m),x=[u*f,u*d,h];const _=x[0]*b[0]+x[1]*b[1]+x[2]*b[2],E=x[0]*S[0]+x[1]*S[1]+x[2]*S[2],y=x[0]*M[0]+x[1]*M[1]+x[2]*M[2];let T=Math.hypot(E,y),I;T>0?(I=-fs*Math.atan2(y,E),I<0&&(I+=360)):I=0;let C=fs*Math.atan2(T,_),P=e,B=i;if(n){let W=C,O=V2(n,90-C);if(C-=O,O>0&&C>3e-4){const H=Math.sin(C*mt),U=Math.cos(C*mt),q=Math.sin(W*mt),Q=Math.cos(W*mt),J=[];for(let it=0;it<3;++it)J.push((x[it]-Q*b[it])/q*H+b[it]*U);T=Math.hypot(J[0],J[1]),T>0?(P=E2*Math.atan2(J[1],J[0]),P<0&&(P+=24)):P=0,B=fs*Math.atan2(J[2],T)}}return new LT(I,90-C,P,B)}function hd(a){if(!(a instanceof qr))throw`Not an instance of the Observer class: ${a}`;if(Si(a.latitude),Si(a.longitude),Si(a.height),a.latitude<-90||a.latitude>90)throw`Latitude ${a.latitude} is out of range. Must be -90..+90.`;return a}class qr{constructor(t,e,i){this.latitude=t,this.longitude=e,this.height=i,hd(this)}}function FT(a){const t=Ne(a).AddDays(-1/em),e=Yo(zs.Earth,t),i=[-e.x,-e.y,-e.z],[n,s,r]=cd(i,t,Ti.From2000),o=mt*_l(t).tobl,c=Math.cos(o),l=Math.sin(o),h=new ge(n,s,r,t);return N2(h,c,l)}function ml(a,t,e,i,n){hd(e),Fu(i),Fu(n);const s=Ne(t),r=O2(s,e),o=Bu(a,s,n),c=[o.x-r[0],o.y-r[1],o.z-r[2]],l=cd(c,s,Ti.From2000);return kT(l,s)}function np(a,t,e){const i=Ne(a),n=El(i);let s=P2(t,n).pos;return e||(s=cd(s,i,Ti.Into2000)),L2(s,i)}function N2(a,t,e){const i=a.x,n=a.y*t+a.z*e,s=-a.y*e+a.z*t,r=Math.hypot(i,n);let o=0;r>0&&(o=fs*Math.atan2(n,i),o<0&&(o+=360));let c=fs*Math.atan2(s,r),l=new ge(i,n,s,a.t);return new NT(l,c,o)}function sp(a){const t=_l(a.t),e=[a.x,a.y,a.z],i=pl(e,a.t,Ti.From2000),[n,s,r]=Uu(i,a.t,Ti.From2000),o=new ge(n,s,r,a.t),c=t.tobl*mt;return N2(o,Math.cos(c),Math.sin(c))}function ur(a){const t=Ne(a),e=I2(t),i=e.distance_au*Math.cos(e.geo_eclip_lat),n=[i*Math.cos(e.geo_eclip_lon),i*Math.sin(e.geo_eclip_lon),e.distance_au*Math.sin(e.geo_eclip_lat)],s=CT(t,n),r=pl(s,t,Ti.Into2000);return new ge(r[0],r[1],r[2],t)}function k2(a){const t=Ne(a),e=1e-5,i=t.AddDays(-e),n=t.AddDays(+e),s=ur(i),r=ur(n);return new zr((s.x+r.x)/2,(s.y+r.y)/2,(s.z+r.z)/2,(r.x-s.x)/(2*e),(r.y-s.y)/(2*e),(r.z-s.z)/(2*e),t)}function UT(a){const t=Ne(a),e=k2(t),i=1+T2;return new zr(e.x/i,e.y/i,e.z/i,e.vx/i,e.vy/i,e.vz/i,t)}function Xo(a,t,e){let i=1,n=0;for(let s of a){let r=0;for(let[c,l,h]of s)r+=c*Math.cos(l+t*h);let o=i*r;e&&(o%=js),n+=o,i*=t}return n}function hf(a,t){let e=1,i=0,n=0,s=0;for(let r of a){let o=0,c=0;for(let[l,h,u]of r){let d=h+t*u;o+=l*u*Math.sin(d),s>0&&(c+=l*Math.cos(d))}n+=s*i*c-e*o,i=e,e*=t,++s}return n}const Uc=365250,rp=0,ap=1,op=2;function cp(a){return new Zi(a[0]+44036e-11*a[1]-190919e-12*a[2],-479966e-12*a[0]+.917482137087*a[1]-.397776982902*a[2],.397776982902*a[1]+.917482137087*a[2])}function F2(a,t,e){const i=e*Math.cos(t),n=Math.cos(a),s=Math.sin(a);return[i*n,i*s,e*Math.sin(t)]}function Yo(a,t){const e=t.tt/Uc,i=Xo(a[rp],e,!0),n=Xo(a[ap],e,!1),s=Xo(a[op],e,!1),r=F2(i,n,s);return cp(r).ToAstroVector(t)}function lp(a,t){const e=t/Uc,i=Xo(a[rp],e,!0),n=Xo(a[ap],e,!1),s=Xo(a[op],e,!1),r=hf(a[rp],e),o=hf(a[ap],e),c=hf(a[op],e),l=Math.cos(i),h=Math.sin(i),u=Math.cos(n),d=Math.sin(n),f=+(c*u*l)-s*d*l*o-s*u*h*r,p=+(c*u*h)-s*d*h*o+s*u*l*r,v=+(c*d)+s*u*o,m=F2(i,n,s),g=[f/Uc,p/Uc,v/Uc],b=cp(m),S=cp(g);return new Ga(t,b,S)}function vh(a,t,e,i){const n=i/(i+im),s=Yo(zs[e],t);a.x+=n*s.x,a.y+=n*s.y,a.z+=n*s.z}function zT(a){const t=new ge(0,0,0,a);return vh(t,a,ut.Jupiter,j0),vh(t,a,ut.Saturn,Q0),vh(t,a,ut.Uranus,tp),vh(t,a,ut.Neptune,ep),t}const hp=51,BT=29200,Lo=146,Qs=201,Da=[[-73e4,[-26.118207232108,-14.376168177825,3.384402515299],[.0016339372163656,-.0027861699588508,-.0013585880229445]],[-700800,[41.974905202127,-.448502952929,-12.770351505989],[.00073458569351457,.0022785014891658,.00048619778602049]],[-671600,[14.706930780744,44.269110540027,9.353698474772],[-.00210001479998,.00022295915939915,.00070143443551414]],[-642400,[-29.441003929957,-6.43016153057,6.858481011305],[.00084495803960544,-.0030783914758711,-.0012106305981192]],[-613200,[39.444396946234,-6.557989760571,-13.913760296463],[.0011480029005873,.0022400006880665,.00035168075922288]],[-584e3,[20.2303809507,43.266966657189,7.382966091923],[-.0019754081700585,.00053457141292226,.00075929169129793]],[-554800,[-30.65832536462,2.093818874552,9.880531138071],[61010603013347e-18,-.0031326500935382,-.00099346125151067]],[-525600,[35.737703251673,-12.587706024764,-14.677847247563],[.0015802939375649,.0021347678412429,.00019074436384343]],[-496400,[25.466295188546,41.367478338417,5.216476873382],[-.0018054401046468,.0008328308359951,.00080260156912107]],[-467200,[-29.847174904071,10.636426313081,12.297904180106],[-.00063257063052907,-.0029969577578221,-.00074476074151596]],[-438e3,[30.774692107687,-18.236637015304,-14.945535879896],[.0020113162005465,.0019353827024189,-20937793168297e-19]],[-408800,[30.243153324028,38.656267888503,2.938501750218],[-.0016052508674468,.0011183495337525,.00083333973416824]],[-379600,[-27.288984772533,18.643162147874,14.023633623329],[-.0011856388898191,-.0027170609282181,-.00049015526126399]],[-350400,[24.519605196774,-23.245756064727,-14.626862367368],[.0024322321483154,.0016062008146048,-.00023369181613312]],[-321200,[34.505274805875,35.125338586954,.557361475637],[-.0013824391637782,.0013833397561817,.00084823598806262]],[-292e3,[-23.275363915119,25.818514298769,15.055381588598],[-.0016062295460975,-.0023395961498533,-.00024377362639479]],[-262800,[17.050384798092,-27.180376290126,-13.608963321694],[.0028175521080578,.0011358749093955,-.00049548725258825]],[-233600,[38.093671910285,30.880588383337,-1.843688067413],[-.0011317697153459,.0016128814698472,.00084177586176055]],[-204400,[-18.197852930878,31.932869934309,15.438294826279],[-.0019117272501813,-.0019146495909842,-19657304369835e-18]],[-175200,[8.528924039997,-29.618422200048,-11.805400994258],[.0031034370787005,.0005139363329243,-.00077293066202546]],[-146e3,[40.94685725864,25.904973592021,-4.256336240499],[-.00083652705194051,.0018129497136404,.0008156422827306]],[-116800,[-12.326958895325,36.881883446292,15.217158258711],[-.0021166103705038,-.001481442003599,.00017401209844705]],[-87600,[-.633258375909,-30.018759794709,-9.17193287495],[.0032016994581737,-.00025279858672148,-.0010411088271861]],[-58400,[42.936048423883,20.344685584452,-6.588027007912],[-.00050525450073192,.0019910074335507,.00077440196540269]],[-29200,[-5.975910552974,40.61180995846,14.470131723673],[-.0022184202156107,-.0010562361130164,.00033652250216211]],[0,[-9.875369580774,-27.978926224737,-5.753711824704],[.0030287533248818,-.0011276087003636,-.0012651326732361]],[29200,[43.958831986165,14.214147973292,-8.808306227163],[-.00014717608981871,.0021404187242141,.00071486567806614]],[58400,[.67813676352,43.094461639362,13.243238780721],[-.0022358226110718,-.00063233636090933,.00047664798895648]],[87600,[-18.282602096834,-23.30503958666,-1.766620508028],[.0025567245263557,-.0019902940754171,-.0013943491701082]],[116800,[43.873338744526,7.700705617215,-10.814273666425],[.00023174803055677,.0022402163127924,.00062988756452032]],[146e3,[7.392949027906,44.382678951534,11.629500214854],[-.002193281545383,-.00021751799585364,.00059556516201114]],[175200,[-24.981690229261,-16.204012851426,2.466457544298],[.001819398914958,-.0026765419531201,-.0013848283502247]],[204400,[42.530187039511,.845935508021,-12.554907527683],[.00065059779150669,.0022725657282262,.00051133743202822]],[233600,[13.999526486822,44.462363044894,9.669418486465],[-.0021079296569252,.00017533423831993,.00069128485798076]],[262800,[-29.184024803031,-7.371243995762,6.493275957928],[.00093581363109681,-.0030610357109184,-.0012364201089345]],[292e3,[39.831980671753,-6.078405766765,-13.909815358656],[.0011117769689167,.0022362097830152,.00036230548231153]],[321200,[20.294955108476,43.417190420251,7.450091985932],[-.0019742157451535,.00053102050468554,.00075938408813008]],[350400,[-30.66999230216,2.318743558955,9.973480913858],[45605107450676e-18,-.0031308219926928,-.00099066533301924]],[379600,[35.626122155983,-12.897647509224,-14.777586508444],[.0016015684949743,.0021171931182284,.00018002516202204]],[408800,[26.133186148561,41.232139187599,5.00640132622],[-.0017857704419579,.00086046232702817,.00080614690298954]],[438e3,[-29.57674022923,11.863535943587,12.631323039872],[-.00072292830060955,-.0029587820140709,-.000708242964503]],[467200,[29.910805787391,-19.159019294,-15.013363865194],[.0020871080437997,.0018848372554514,-38528655083926e-18]],[496400,[31.375957451819,38.050372720763,2.433138343754],[-.0015546055556611,.0011699815465629,.00083565439266001]],[525600,[-26.360071336928,20.662505904952,14.414696258958],[-.0013142373118349,-.0026236647854842,-.00042542017598193]],[554800,[22.599441488648,-24.508879898306,-14.484045731468],[.0025454108304806,.0014917058755191,-.00030243665086079]],[584e3,[35.877864013014,33.894226366071,-.224524636277],[-.0012941245730845,.0014560427668319,.00084762160640137]],[613200,[-21.538149762417,28.204068269761,15.321973799534],[-.001731211740901,-.0021939631314577,-.0001631691327518]],[642400,[13.971521374415,-28.339941764789,-13.083792871886],[.0029334630526035,.00091860931752944,-.00059939422488627]],[671600,[39.526942044143,28.93989736011,-2.872799527539],[-.0010068481658095,.001702113288809,.00083578230511981]],[700800,[-15.576200701394,34.399412961275,15.466033737854],[-.0020098814612884,-.0017191109825989,70414782780416e-18]],[73e4,[4.24325283709,-30.118201690825,-10.707441231349],[.0031725847067411,.0001609846120227,-.00090672150593868]]];class Zi{constructor(t,e,i){this.x=t,this.y=e,this.z=i}clone(){return new Zi(this.x,this.y,this.z)}ToAstroVector(t){return new ge(this.x,this.y,this.z,t)}static zero(){return new Zi(0,0,0)}quadrature(){return this.x*this.x+this.y*this.y+this.z*this.z}add(t){return new Zi(this.x+t.x,this.y+t.y,this.z+t.z)}sub(t){return new Zi(this.x-t.x,this.y-t.y,this.z-t.z)}incr(t){this.x+=t.x,this.y+=t.y,this.z+=t.z}decr(t){this.x-=t.x,this.y-=t.y,this.z-=t.z}mul(t){return new Zi(t*this.x,t*this.y,t*this.z)}div(t){return new Zi(this.x/t,this.y/t,this.z/t)}mean(t){return new Zi((this.x+t.x)/2,(this.y+t.y)/2,(this.z+t.z)/2)}neg(){return new Zi(-this.x,-this.y,-this.z)}}class Ga{constructor(t,e,i){this.tt=t,this.r=e,this.v=i}clone(){return new Ga(this.tt,this.r,this.v)}sub(t){return new Ga(this.tt,this.r.sub(t.r),this.v.sub(t.v))}}function HT(a){let[t,[e,i,n],[s,r,o]]=a;return new Ga(t,new Zi(e,i,n),new Zi(s,r,o))}function Mh(a,t,e,i){const n=i/(i+im),s=lp(zs[e],t);return a.r.incr(s.r.mul(n)),a.v.incr(s.v.mul(n)),s}function Ac(a,t,e){const i=e.sub(a),n=i.quadrature();return i.mul(t/(n*Math.sqrt(n)))}class ud{constructor(t){let e=new Ga(t,new Zi(0,0,0),new Zi(0,0,0));this.Jupiter=Mh(e,t,ut.Jupiter,j0),this.Saturn=Mh(e,t,ut.Saturn,Q0),this.Uranus=Mh(e,t,ut.Uranus,tp),this.Neptune=Mh(e,t,ut.Neptune,ep),this.Jupiter.r.decr(e.r),this.Jupiter.v.decr(e.v),this.Saturn.r.decr(e.r),this.Saturn.v.decr(e.v),this.Uranus.r.decr(e.r),this.Uranus.v.decr(e.v),this.Neptune.r.decr(e.r),this.Neptune.v.decr(e.v),this.Sun=new Ga(t,e.r.mul(-1),e.v.mul(-1))}Acceleration(t){let e=Ac(t,im,this.Sun.r);return e.incr(Ac(t,j0,this.Jupiter.r)),e.incr(Ac(t,Q0,this.Saturn.r)),e.incr(Ac(t,tp,this.Uranus.r)),e.incr(Ac(t,ep,this.Neptune.r)),e}}class dd{constructor(t,e,i,n){this.tt=t,this.r=e,this.v=i,this.a=n}clone(){return new dd(this.tt,this.r.clone(),this.v.clone(),this.a.clone())}}class U2{constructor(t,e){this.bary=t,this.grav=e}}function zu(a,t,e,i){return new Zi(t.x+a*(e.x+a*i.x/2),t.y+a*(e.y+a*i.y/2),t.z+a*(e.z+a*i.z/2))}function q1(a,t,e){return new Zi(t.x+a*e.x,t.y+a*e.y,t.z+a*e.z)}function up(a,t){const e=a-t.tt,i=new ud(a),n=zu(e,t.r,t.v,t.a),s=i.Acceleration(n).mean(t.a),r=zu(e,t.r,t.v,s),o=t.v.add(s.mul(e)),c=i.Acceleration(r),l=new dd(a,r,o,c);return new U2(i,l)}const GT=[];function z2(a,t){const e=Math.floor(a);return e<0?0:e>=t?t-1:e}function dp(a){const t=HT(a),e=new ud(t.tt),i=t.r.add(e.Sun.r),n=t.v.add(e.Sun.v),s=e.Acceleration(i),r=new dd(t.tt,i,n,s);return new U2(e,r)}function VT(a,t){const e=Da[0][0];if(t<e||t>Da[hp-1][0])return null;const i=z2((t-e)/BT,hp-1);if(!a[i]){const s=a[i]=[];s[0]=dp(Da[i]).grav,s[Qs-1]=dp(Da[i+1]).grav;let r,o=s[0].tt;for(r=1;r<Qs-1;++r)s[r]=up(o+=Lo,s[r-1]).grav;o=s[Qs-1].tt;var n=[];for(n[Qs-1]=s[Qs-1],r=Qs-2;r>0;--r)n[r]=up(o-=Lo,n[r+1]).grav;for(r=Qs-2;r>0;--r){const c=r/(Qs-1);s[r].r=s[r].r.mul(1-c).add(n[r].r.mul(c)),s[r].v=s[r].v.mul(1-c).add(n[r].v.mul(c)),s[r].a=s[r].a.mul(1-c).add(n[r].a.mul(c))}}return a[i]}function $1(a,t,e){let i=dp(a);const n=Math.ceil((t-i.grav.tt)/e);for(let s=0;s<n;++s)i=up(s+1===n?t:i.grav.tt+e,i.grav);return i}function B2(a,t){let e,i,n;const s=VT(GT,a.tt);if(s){const r=z2((a.tt-s[0].tt)/Lo,Qs-1),o=s[r],c=s[r+1],l=o.a.mean(c.a),h=zu(a.tt-o.tt,o.r,o.v,l),u=q1(a.tt-o.tt,o.v,l),d=zu(a.tt-c.tt,c.r,c.v,l),f=q1(a.tt-c.tt,c.v,l),p=(a.tt-o.tt)/Lo;e=h.mul(1-p).add(d.mul(p)),i=u.mul(1-p).add(f.mul(p))}else{let r;a.tt<Da[0][0]?r=$1(Da[0],a.tt,-Lo):r=$1(Da[hp-1],a.tt,+Lo),e=r.grav.r,i=r.grav.v,n=r.bary}return n||(n=new ud(a.tt)),e=e.sub(n.Sun.r),i=i.sub(n.Sun.v),new zr(e.x,e.y,e.z,i.x,i.y,i.z,a)}function Wr(a,t){var e=Ne(t);if(a in zs)return Yo(zs[a],e);if(a===ut.Pluto){const r=B2(e);return new ge(r.x,r.y,r.z,e)}if(a===ut.Sun)return new ge(0,0,0,e);if(a===ut.Moon){var i=Yo(zs.Earth,e),n=ur(e);return new ge(i.x+n.x,i.y+n.y,i.z+n.z,e)}if(a===ut.EMB){const r=Yo(zs.Earth,e),o=ur(e),c=1+T2;return new ge(r.x+o.x/c,r.y+o.y/c,r.z+o.z/c,e)}if(a===ut.SSB)return zT(e);const s=nm(a);if(s){const r=new ld(s.dec,15*s.ra,s.dist);return hm(r,e)}throw`HelioVector: Unknown body "${a}"`}function WT(a,t){let e=t,i=0;for(let n=0;n<10;++n){const s=a(e),r=s.Length()/em;if(r>1)throw"Object is too distant for light-travel solver.";const o=t.AddDays(-r);if(i=Math.abs(o.tt-e.tt),i<1e-9)return s;e=o}throw`Light-travel time solver did not converge: dt = ${i}`}class XT{constructor(t,e,i,n){this.observerBody=t,this.targetBody=e,this.aberration=i,this.observerPos=n}Position(t){this.aberration&&(this.observerPos=Wr(this.observerBody,t));const e=Wr(this.targetBody,t);return new ge(e.x-this.observerPos.x,e.y-this.observerPos.y,e.z-this.observerPos.z,t)}}function YT(a,t,e,i){Fu(i);const n=Ne(a);if(nm(e)){const o=Wr(e,n);if(i){const l=$T(t,n),h=new ge(o.x-l.x,o.y-l.y,o.z-l.z,n),u=em/h.Length();return new ge(h.x+l.vx/u,h.y+l.vy/u,h.z+l.vz/u,n)}const c=Wr(t,n);return new ge(o.x-c.x,o.y-c.y,o.z-c.z,n)}let s;i?s=new ge(0,0,0,n):s=Wr(t,n);const r=new XT(t,e,i,s);return WT(o=>r.Position(o),n)}function Bu(a,t,e){Fu(e);const i=Ne(t);switch(a){case ut.Earth:return new ge(0,0,0,i);case ut.Moon:return ur(i);default:const n=YT(i,ut.Earth,a,e);return n.t=i,n}}function qT(a,t){return new zr(a.r.x,a.r.y,a.r.z,a.v.x,a.v.y,a.v.z,t)}function $T(a,t){const e=Ne(t);switch(a){case ut.Sun:return new zr(0,0,0,0,0,0,e);case ut.SSB:const i=new ud(e.tt);return new zr(-i.Sun.r.x,-i.Sun.r.y,-i.Sun.r.z,-i.Sun.v.x,-i.Sun.v.y,-i.Sun.v.z,e);case ut.Mercury:case ut.Venus:case ut.Earth:case ut.Mars:case ut.Jupiter:case ut.Saturn:case ut.Uranus:case ut.Neptune:const n=lp(zs[a],e.tt);return qT(n,e);case ut.Pluto:return B2(e);case ut.Moon:case ut.EMB:const s=lp(zs.Earth,e.tt),r=a==ut.Moon?k2(e):UT(e);return new zr(r.x+s.r.x,r.y+s.r.y,r.z+s.r.z,r.vx+s.v.x,r.vy+s.v.y,r.vz+s.v.z,e);default:if(nm(a)){const o=Wr(a,e);return new zr(o.x,o.y,o.z,0,0,0,e)}throw`HelioState: Unsupported body "${a}"`}}function KT(a,t,e,i,n){let s=(n+e)/2-i,r=(n-e)/2,o=i,c;if(s==0){if(r==0||(c=-o/r,c<-1||c>1))return null}else{let u=r*r-4*s*o;if(u<=0)return null;let d=Math.sqrt(u),f=(-r+d)/(2*s),p=(-r-d)/(2*s);if(-1<=f&&f<=1){if(-1<=p&&p<=1)return null;c=f}else if(-1<=p&&p<=1)c=p;else return null}let l=a+c*t,h=(2*s*c+r)/t;return{t:l,df_dt:h}}function om(a,t,e,i){const n=Si(i&&i.dt_tolerance_seconds||1),s=Math.abs(n/gT);let r=i&&i.init_f1||a(t),o=i&&i.init_f2||a(e),c=NaN,l=0,h=i&&i.iter_limit||20,u=!0;for(;;){if(++l>h)throw"Excessive iteration in Search()";let d=RT(t,e,.5),f=d.ut-t.ut;if(Math.abs(f)<s)return d;u?c=a(d):u=!0;let p=KT(d.ut,e.ut-d.ut,r,c,o);if(p){let v=Ne(p.t),m=a(v);if(p.df_dt!==0){if(Math.abs(m/p.df_dt)<s)return v;let g=1.2*Math.abs(m/p.df_dt);if(g<f/10){let b=v.AddDays(-g),S=v.AddDays(+g);if((b.ut-t.ut)*(b.ut-e.ut)<0&&(S.ut-t.ut)*(S.ut-e.ut)<0){let M=a(b),x=a(S);if(M<0&&x>=0){r=M,o=x,t=b,e=S,c=m,u=!1;continue}}}}}if(r<0&&c>=0){e=d,o=c;continue}if(c<0&&o>=0){t=d,r=c;continue}return null}}function ZT(a){let t=a;for(;t<=-180;)t+=360;for(;t>180;)t-=360;return t}function JT(a){for(;a<0;)a+=360;for(;a>=360;)a-=360;return a}function jT(a,t,e){if(a===ut.Earth||t===ut.Earth)throw"The Earth does not have a longitude as seen from itself.";const i=Ne(e),n=Bu(a,i,!1),s=sp(n),r=Bu(t,i,!1),o=sp(r);return JT(s.elon-o.elon)}function QT(a,t,e,i){let n,s=0,r=0,o=0;switch(a){case ut.Mercury:n=-.6,s=4.98,r=-4.88,o=3.02;break;case ut.Venus:t<163.6?(n=-4.47,s=1.03,r=.57,o=.13):(n=.98,s=-1.02);break;case ut.Mars:n=-1.52,s=1.6;break;case ut.Jupiter:n=-9.4,s=.5;break;case ut.Uranus:n=-7.19,s=.25;break;case ut.Neptune:n=-6.87;break;case ut.Pluto:n=-1,s=4;break;default:throw`VisualMagnitude: unsupported body ${a}`}const c=t/100;let l=n+c*(s+c*(r+c*o));return l+=5*Math.log10(e*i),l}function t4(a,t,e,i,n){const s=sp(i),r=mt*28.06,o=mt*(169.51+382e-7*n.tt),c=mt*s.elat,l=mt*s.elon,h=Math.asin(Math.sin(c)*Math.cos(r)-Math.cos(c)*Math.sin(r)*Math.sin(l-o)),u=Math.sin(Math.abs(h));let d=-9+.044*a;return d+=u*(-2.6+1.2*u),d+=5*Math.log10(t*e),{mag:d,ring_tilt:fs*h}}function e4(a,t,e){let i=a*mt,n=i*i,s=n*n,r=-12.717+1.49*Math.abs(i)+.0431*s;const o=385000.6/Ls;let c=e/o;return r+=5*Math.log10(t*c),r}class i4{constructor(t,e,i,n,s,r,o,c){this.time=t,this.mag=e,this.phase_angle=i,this.helio_dist=n,this.geo_dist=s,this.gc=r,this.hc=o,this.ring_tilt=c,this.phase_fraction=(1+Math.cos(mt*i))/2}}function H2(a,t){if(a===ut.Earth)throw"The illumination of the Earth is not defined.";const e=Ne(t),i=Yo(zs.Earth,e);let n,s,r,o;a===ut.Sun?(r=new ge(-i.x,-i.y,-i.z,e),s=new ge(0,0,0,e),n=0):(a===ut.Moon?(r=ur(e),s=new ge(i.x+r.x,i.y+r.y,i.z+r.z,e)):(s=Wr(a,t),r=new ge(s.x-i.x,s.y-i.y,s.z-i.z,e)),n=R2(r,s));let c=r.Length(),l=s.Length(),h;if(a===ut.Sun)o=pT+5*Math.log10(c);else if(a===ut.Moon)o=e4(n,l,c);else if(a===ut.Saturn){const u=t4(n,l,c,r,e);o=u.mag,h=u.ring_tilt}else o=QT(a,n,l,c);return new i4(e,o,n,l,c,r,s,h)}function G2(a){return jT(ut.Moon,ut.Sun,a)}function n4(a,t,e){function i(d){let f=G2(d);return ZT(f-a)}Si(a),Si(e);const n=1.5,s=Ne(t);let r=i(s),o,c,l;{if(r>0&&(r-=360),o=-(mT*r)/360,c=o-n,c>e)return null;l=Math.min(e,o+n)}const h=s.AddDays(c),u=s.AddDays(l);return om(i,h,u,{dt_tolerance_seconds:.1})}var K1;(function(a){a[a.Pericenter=0]="Pericenter",a[a.Apocenter=1]="Apocenter"})(K1||(K1={}));function cm(a){return new Ws([[a.rot[0][0],a.rot[1][0],a.rot[2][0]],[a.rot[0][1],a.rot[1][1],a.rot[2][1]],[a.rot[0][2],a.rot[1][2],a.rot[2][2]]])}function lm(a,t){return new Ws([[t.rot[0][0]*a.rot[0][0]+t.rot[1][0]*a.rot[0][1]+t.rot[2][0]*a.rot[0][2],t.rot[0][1]*a.rot[0][0]+t.rot[1][1]*a.rot[0][1]+t.rot[2][1]*a.rot[0][2],t.rot[0][2]*a.rot[0][0]+t.rot[1][2]*a.rot[0][1]+t.rot[2][2]*a.rot[0][2]],[t.rot[0][0]*a.rot[1][0]+t.rot[1][0]*a.rot[1][1]+t.rot[2][0]*a.rot[1][2],t.rot[0][1]*a.rot[1][0]+t.rot[1][1]*a.rot[1][1]+t.rot[2][1]*a.rot[1][2],t.rot[0][2]*a.rot[1][0]+t.rot[1][2]*a.rot[1][1]+t.rot[2][2]*a.rot[1][2]],[t.rot[0][0]*a.rot[2][0]+t.rot[1][0]*a.rot[2][1]+t.rot[2][0]*a.rot[2][2],t.rot[0][1]*a.rot[2][0]+t.rot[1][1]*a.rot[2][1]+t.rot[2][1]*a.rot[2][2],t.rot[0][2]*a.rot[2][0]+t.rot[1][2]*a.rot[2][1]+t.rot[2][2]*a.rot[2][2]]])}function hm(a,t){t=Ne(t);const e=a.lat*mt,i=a.lon*mt,n=a.dist*Math.cos(e);return new ge(n*Math.cos(i),n*Math.sin(i),a.dist*Math.sin(e),t)}function fd(a){const t=s4(a);return new ip(t.lon/15,t.lat,t.dist,a)}function s4(a){const t=a.x*a.x+a.y*a.y,e=Math.sqrt(t+a.z*a.z);let i,n;if(t===0){if(a.z===0)throw"Zero-length vector not allowed.";n=0,i=a.z<0?-90:90}else n=fs*Math.atan2(a.y,a.x),n<0&&(n+=360),i=fs*Math.atan2(a.z,Math.sqrt(t));return new ld(i,n,e)}function V2(a,t){let e;if(Si(t),t<-90||t>90)return 0;if(a==="normal"||a==="jplhor"){let i=t;i<-1&&(i=-1),e=1.02/Math.tan((i+10.3/(i+5.11))*mt)/60,a==="normal"&&t<-1&&(e*=(t+90)/89)}else if(!a)e=0;else throw`Invalid refraction option: ${a}`;return e}function cr(a,t){return new ge(a.rot[0][0]*t.x+a.rot[1][0]*t.y+a.rot[2][0]*t.z,a.rot[0][1]*t.x+a.rot[1][1]*t.y+a.rot[2][1]*t.z,a.rot[0][2]*t.x+a.rot[1][2]*t.y+a.rot[2][2]*t.z,t.t)}function r4(){return new Ws([[1,0,0],[0,.9174821430670688,-.3977769691083922],[0,.3977769691083922,.9174821430670688]])}function a4(){return new Ws([[1,0,0],[0,.9174821430670688,.3977769691083922],[0,-.3977769691083922,.9174821430670688]])}function W2(a){a=Ne(a);const t=sm(a,Ti.From2000),e=rm(a,Ti.From2000);return lm(t,e)}function X2(a){a=Ne(a);const t=rm(a,Ti.Into2000),e=sm(a,Ti.Into2000);return lm(t,e)}function o4(a,t){a=Ne(a);const e=Math.sin(t.latitude*mt),i=Math.cos(t.latitude*mt),n=Math.sin(t.longitude*mt),s=Math.cos(t.longitude*mt),r=[i*s,i*n,e],o=[-e*s,-e*n,i],c=[n,-s,0],l=-15*El(a),h=Wo(l,r),u=Wo(l,o),d=Wo(l,c);return new Ws([[u[0],d[0],h[0]],[u[1],d[1],h[1]],[u[2],d[2],h[2]]])}function c4(a,t){const e=o4(a,t);return cm(e)}function l4(a,t){a=Ne(a);const e=c4(a,t),i=X2(a);return lm(e,i)}function h4(a,t){const e=l4(a,t);return cm(e)}function u4(a){const e=_l(Ne(a)).tobl*mt,i=Math.cos(e),n=Math.sin(e);return new Ws([[1,0,0],[0,+i,+n],[0,-n,+i]])}var Va;(function(a){a.Penumbral="penumbral",a.Partial="partial",a.Annular="annular",a.Total="total"})(Va||(Va={}));class d4{constructor(t,e,i,n,s,r,o){this.time=t,this.u=e,this.r=i,this.k=n,this.p=s,this.target=r,this.dir=o}}function f4(a,t,e,i){const n=(i.x*e.x+i.y*e.y+i.z*e.z)/(i.x*i.x+i.y*i.y+i.z*i.z),s=n*i.x-e.x,r=n*i.y-e.y,o=n*i.z-e.z,c=Ls*Math.hypot(s,r,o),l=+Fc-(1+n)*(Fc-a),h=-Fc+(1+n)*(Fc+a);return new d4(t,n,c,l,h,e,i)}function fp(a,t){const e=O2(a,t),i=Bu(ut.Sun,a,!0),n=ur(a),s=new ge(e[0]-n.x,e[1]-n.y,e[2]-n.z,a);return n.x-=i.x,n.y-=i.y,n.z-=i.z,f4(xT,a,s,n)}function p4(a,t){const e=11574074074074073e-21,i=t.AddDays(-e),n=t.AddDays(+e),s=a(i);return(a(n).r-s.r)/e}function m4(a,t){const e=a.AddDays(-.2),i=a.AddDays(.2);function n(r){return fp(r,t)}const s=om(r=>p4(n,r),e,i);if(!s)throw`PeakLocalMoonShadow: search failure for search_center_time = ${a}`;return fp(s,t)}function g4(a){const t=I2(a);return fs*t.geo_eclip_lat}function v4(a,t,e){if(a<=0)throw"Radius of first disc must be positive.";if(t<=0)throw"Radius of second disc must be positive.";if(e<0)throw"Distance between discs is not allowed to be negative.";if(e>=a+t)return 0;if(e==0)return a<=t?1:t*t/(a*a);const i=(a*a-t*t+e*e)/(2*e),n=a*a-i*i;if(n<=0)return a<=t?1:t*t/(a*a);const s=Math.sqrt(n),r=a*a*Math.acos(i/a)-i*s,o=t*t*Math.acos((e-i)/t)-(e-i)*s;return(r+o)/(Math.PI*a*a)}function M4(a,t){const e=new ge(a.x+t.x,a.y+t.y,a.z+t.z,a.t),i=Math.asin(vT/e.Length()),n=Math.asin(ST/t.Length()),s=R2(t,e),r=v4(i,n,s*mt);return Math.min(.9999,r)}function y4(a){return a>.014?Va.Total:Va.Annular}class x4{constructor(t,e){this.time=t,this.altitude=e}}class b4{constructor(t,e,i,n,s,r,o){this.kind=t,this.obscuration=e,this.partial_begin=i,this.total_begin=n,this.peak=s,this.total_end=r,this.partial_end=o}}function Z1(a){return a.p-a.r}function J1(a){return Math.abs(a.k)-a.r}function S4(a,t){const e=Y2(t,a.time);let i=a.time.AddDays(-.2),n=a.time.AddDays(.2);const s=yh(t,1,Z1,i,a.time),r=yh(t,-1,Z1,a.time,n);let o,c,l;a.r<Math.abs(a.k)?(i=a.time.AddDays(-.01),n=a.time.AddDays(.01),o=yh(t,1,J1,i,a.time),c=yh(t,-1,J1,a.time,n),l=y4(a.k)):l=Va.Partial;const h=l===Va.Total?1:M4(a.dir,a.target);return new b4(l,h,s,o,e,c,r)}function yh(a,t,e,i,n){function s(o){const c=fp(o,a);return t*e(c)}const r=om(s,i,n);if(!r)throw"Local eclipse transition search failed.";return Y2(a,r)}function Y2(a,t){const e=w4(t,a);return new x4(t,e)}function w4(a,t){const e=ml(ut.Sun,a,t,!0,!0);return am(a,t,e.ra,e.dec,"normal").altitude}function _4(a,t){a=Ne(a),hd(t);const e=1.8;let i=a;for(;;){const n=n4(0,i,40);if(!n)throw"Cannot find next new moon";const s=g4(n);if(Math.abs(s)<e){const r=m4(n,t);if(r.r<r.p){const o=S4(r,t);if(o.partial_begin.altitude>0||o.partial_end.altitude>0)return o}}i=n.AddDays(10)}}var j1;(function(a){a[a.Invalid=0]="Invalid",a[a.Ascending=1]="Ascending",a[a.Descending=-1]="Descending"})(j1||(j1={}));class q2{constructor(t,e,i,n){this.ra=t,this.dec=e,this.spin=i,this.north=n}}function E4(a){const t=Uu([0,0,1],a,Ti.Into2000),e=pl(t,a,Ti.Into2000),i=new ge(e[0],e[1],e[2],a),n=fd(i),s=190.41375788700253+360.9856122880876*a.ut;return new q2(n.ra,n.dec,s,i)}function A4(a,t){const e=Ne(t),i=e.tt,n=i/36525;let s,r,o;switch(a){case ut.Sun:s=286.13,r=63.87,o=84.176+14.1844*i;break;case ut.Mercury:s=281.0103-.0328*n,r=61.4155-.0049*n,o=329.5988+6.1385108*i+.01067257*Math.sin(mt*(174.7910857+4.092335*i))-.00112309*Math.sin(mt*(349.5821714+8.18467*i))-1104e-7*Math.sin(mt*(164.3732571+12.277005*i))-2539e-8*Math.sin(mt*(339.1643429+16.36934*i))-571e-8*Math.sin(mt*(153.9554286+20.461675*i));break;case ut.Venus:s=272.76,r=67.16,o=160.2-1.4813688*i;break;case ut.Earth:return E4(e);case ut.Moon:const d=mt*(125.045-.0529921*i),f=mt*(250.089-.1059842*i),p=mt*(260.008+13.0120009*i),v=mt*(176.625+13.3407154*i),m=mt*(357.529+.9856003*i),g=mt*(311.589+26.4057084*i),b=mt*(134.963+13.064993*i),S=mt*(276.617+.3287146*i),M=mt*(34.226+1.7484877*i),x=mt*(15.134-.1589763*i),_=mt*(119.743+.0036096*i),E=mt*(239.961+.1643573*i),y=mt*(25.053+12.9590088*i);s=269.9949+.0031*n-3.8787*Math.sin(d)-.1204*Math.sin(f)+.07*Math.sin(p)-.0172*Math.sin(v)+.0072*Math.sin(g)-.0052*Math.sin(x)+.0043*Math.sin(y),r=66.5392+.013*n+1.5419*Math.cos(d)+.0239*Math.cos(f)-.0278*Math.cos(p)+.0068*Math.cos(v)-.0029*Math.cos(g)+9e-4*Math.cos(b)+8e-4*Math.cos(x)-9e-4*Math.cos(y),o=38.3213+(13.17635815-14e-13*i)*i+3.561*Math.sin(d)+.1208*Math.sin(f)-.0642*Math.sin(p)+.0158*Math.sin(v)+.0252*Math.sin(m)-.0066*Math.sin(g)-.0047*Math.sin(b)-.0046*Math.sin(S)+.0028*Math.sin(M)+.0052*Math.sin(x)+.004*Math.sin(_)+.0019*Math.sin(E)-.0044*Math.sin(y);break;case ut.Mars:s=317.269202-.10927547*n+68e-6*Math.sin(mt*(198.991226+19139.4819985*n))+238e-6*Math.sin(mt*(226.292679+38280.8511281*n))+52e-6*Math.sin(mt*(249.663391+57420.7251593*n))+9e-6*Math.sin(mt*(266.18351+76560.636795*n))+.419057*Math.sin(mt*(79.398797+.5042615*n)),r=54.432516-.05827105*n+51e-6*Math.cos(mt*(122.433576+19139.9407476*n))+141e-6*Math.cos(mt*(43.058401+38280.8753272*n))+31e-6*Math.cos(mt*(57.663379+57420.7517205*n))+5e-6*Math.cos(mt*(79.476401+76560.6495004*n))+1.591274*Math.cos(mt*(166.325722+.5042615*n)),o=176.049863+350.891982443297*i+145e-6*Math.sin(mt*(129.071773+19140.0328244*n))+157e-6*Math.sin(mt*(36.352167+38281.0473591*n))+4e-5*Math.sin(mt*(56.668646+57420.929536*n))+1e-6*Math.sin(mt*(67.364003+76560.2552215*n))+1e-6*Math.sin(mt*(104.79268+95700.4387578*n))+.584542*Math.sin(mt*(95.391654+.5042615*n));break;case ut.Jupiter:const T=mt*(99.360714+4850.4046*n),I=mt*(175.895369+1191.9605*n),C=mt*(300.323162+262.5475*n),P=mt*(114.012305+6070.2476*n),B=mt*(49.511251+64.3*n);s=268.056595-.006499*n+117e-6*Math.sin(T)+938e-6*Math.sin(I)+.001432*Math.sin(C)+3e-5*Math.sin(P)+.00215*Math.sin(B),r=64.495303+.002413*n+5e-5*Math.cos(T)+404e-6*Math.cos(I)+617e-6*Math.cos(C)-13e-6*Math.cos(P)+926e-6*Math.cos(B),o=284.95+870.536*i;break;case ut.Saturn:s=40.589-.036*n,r=83.537-.004*n,o=38.9+810.7939024*i;break;case ut.Uranus:s=257.311,r=-15.175,o=203.81-501.1600928*i;break;case ut.Neptune:const W=mt*(357.85+52.316*n);s=299.36+.7*Math.sin(W),r=43.46-.51*Math.cos(W),o=249.978+541.1397757*i-.48*Math.sin(W);break;case ut.Pluto:s=132.993,r=-6.163,o=302.695+56.3625225*i;break;default:throw`Invalid body: ${a}`}const c=r*mt,l=s*mt,h=Math.cos(c),u=new ge(h*Math.cos(l),h*Math.sin(l),Math.sin(c),e);return new q2(s/15,r,o,u)}const T4=["Venus","Mars","Jupiter","Saturn"];function $2(a){return new qr(a.lat,a.lng,a.elevationM)}function um(a,t,e,i,n=!0){const s=am(e,$2(i),a,t,n?"normal":void 0);return{altitudeDeg:s.altitude,azimuthDeg:s.azimuth}}class os{up;north;west;constructor(t,e){const i=Ne(t),n=Math.sin(e.lat*tr),s=Math.cos(e.lat*tr),r=Math.sin(e.lng*tr),o=Math.cos(e.lng*tr),c=-15*OT(i),l=X2(i);this.up=os.rotate(l,os.spin(c,[s*o,s*r,n]),i),this.north=os.rotate(l,os.spin(c,[-n*o,-n*r,s]),i),this.west=os.rotate(l,os.spin(c,[r,-o,0]),i)}static ofJ2000(t,e,i,n,s=!0){const r=Ne(i),o=hm(new ld(e,t*15,1),r),c=fd(cr(W2(r),o));return um(c.ra,c.dec,i,n,s)}position(t,e){const i=Math.sin(e*tr),n=Math.cos(e*tr),s=Math.sin(t*tv),r=Math.cos(t*tv),o=n*r,c=n*s,l=i,h=o*this.up[0]+c*this.up[1]+l*this.up[2],u=o*this.north[0]+c*this.north[1]+l*this.north[2],d=o*this.west[0]+c*this.west[1]+l*this.west[2],f=Math.hypot(u,d);let p=0;f>0&&(p=-Q1*Math.atan2(d,u),p<0&&(p+=360));let v=Q1*Math.atan2(f,h);return v-=V2("normal",90-v),{altitudeDeg:90-v,azimuthDeg:p}}static spin(t,[e,i,n]){const s=Math.cos(t*tr),r=Math.sin(t*tr);return[s*e+r*i,s*i-r*e,n]}static rotate(t,[e,i,n],s){const r=cr(t,new ge(e,i,n,s));return[r.x,r.y,r.z]}}const tr=Math.PI/180,Q1=180/Math.PI,tv=15*tr;function xh(a,t,e){const i=$2(e),n=ml(ut[a],t,i,!0,!0),s=am(t,i,n.ra,n.dec,"normal");return{altitudeDeg:s.altitude,azimuthDeg:s.azimuth}}function uf(a,t){return H2(ut[a],t).mag}function R4(a){const t=G2(a),e=H2(ut.Moon,a);return{phaseFraction:t/360,illuminatedFraction:e.phase_fraction}}const D4=2e3,I4=3,C4=20;function ra(a,t,e){if(a.year===void 0&&a.month===void 0&&a.day===void 0&&a.hour===void 0)return;const i=a.year!==void 0,n=a.year??D4,s=a.month??(i?1:I4),r=a.day??(i?1:C4),o=e??Math.round(t/15);return new Date(Date.UTC(n,s-1,r,(a.hour??12)-o,a.minute??0,a.second??0))}const ev=["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"];class Na{static POINT_DEG=360/16;static point(t,e=ev){const i=(t%360+360)%360,n=Math.round(i/Na.POINT_DEG)%16;return e[n]}static POINTS=ev;static towards(t,e){return e?e.towards(Na.point(t,e.compassPoints)):`to the ${Na.point(t)}`}}class Es{static ANCHOR="vec4 diffuseColor = vec4( diffuse, opacity );";static CORE=.18;static RIM=.5;static FALLOFF={core:Es.CORE,rim:Es.RIM};static apply(t){t.transparent=!0,t.depthWrite=!1,t.onBeforeCompile=e=>{e.fragmentShader=Es.patch(e.fragmentShader)}}static patch(t){return t.replace(Es.ANCHOR,`float distanceFromCentre = length( gl_PointCoord - vec2( 0.5 ) );
7017
+ */const em=173.1446326846693,Ls=14959787069098932e-8,mt=.017453292519943295,V1=.26179938779914946,fs=57.29577951308232,E2=3.819718634205488,uT=365.24217,W1=new Date("2000-01-01T12:00:00Z"),js=2*Math.PI,Er=3600*(180/Math.PI),Oo=484813681109536e-20,A2=10800*60,dT=2*A2,X1=7292115e-11,fT=A2/Math.PI,pT=-.17-5*Math.log10(fT),mT=29.530588,gT=24*3600,Fc=695700,vT=Fc/Ls,Z0=.996647180302104,MT=Z0*Z0,J0=6378.1366,yT=J0/Ls,xT=1737.4,bT=1736,ST=bT/Ls,T2=81.30056,im=.0002959122082855911,j0=2825345909524226e-22,Q0=8459715185680659e-23,tp=1292024916781969e-23,ep=1524358900784276e-23;function Fu(a){if(a!==!0&&a!==!1)throw console.trace(),`Value is not boolean: ${a}`;return a}function Si(a){if(!Number.isFinite(a))throw console.trace(),`Value is not a finite number: ${a}`;return a}function So(a){return a-Math.floor(a)}function R2(a,t){const e=a.x*a.x+a.y*a.y+a.z*a.z;if(Math.abs(e)<1e-8)throw"AngleBetween: first vector is too short.";const i=t.x*t.x+t.y*t.y+t.z*t.z;if(Math.abs(i)<1e-8)throw"AngleBetween: second vector is too short.";const n=(a.x*t.x+a.y*t.y+a.z*t.z)/Math.sqrt(e*i);return n<=-1?180:n>=1?0:fs*Math.acos(n)}var ut;(function(a){a.Sun="Sun",a.Moon="Moon",a.Mercury="Mercury",a.Venus="Venus",a.Earth="Earth",a.Mars="Mars",a.Jupiter="Jupiter",a.Saturn="Saturn",a.Uranus="Uranus",a.Neptune="Neptune",a.Pluto="Pluto",a.SSB="SSB",a.EMB="EMB",a.Star1="Star1",a.Star2="Star2",a.Star3="Star3",a.Star4="Star4",a.Star5="Star5",a.Star6="Star6",a.Star7="Star7",a.Star8="Star8"})(ut||(ut={}));const wT=[ut.Star1,ut.Star2,ut.Star3,ut.Star4,ut.Star5,ut.Star6,ut.Star7,ut.Star8],_T=[{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0},{ra:0,dec:0,dist:0}];function ET(a){const t=wT.indexOf(a);return t>=0?_T[t]:null}function nm(a){const t=ET(a);return t&&t.dist>0?t:null}var Ri;(function(a){a[a.From2000=0]="From2000",a[a.Into2000=1]="Into2000"})(Ri||(Ri={}));const zs={Mercury:[[[[4.40250710144,0,0],[.40989414977,1.48302034195,26087.9031415742],[.050462942,4.47785489551,52175.8062831484],[.00855346844,1.16520322459,78263.70942472259],[.00165590362,4.11969163423,104351.61256629678],[.00034561897,.77930768443,130439.51570787099],[7583476e-11,3.71348404924,156527.41884944518]],[[26087.90313685529,0,0],[.01131199811,6.21874197797,26087.9031415742],[.00292242298,3.04449355541,52175.8062831484],[.00075775081,6.08568821653,78263.70942472259],[.00019676525,2.80965111777,104351.61256629678]]],[[[.11737528961,1.98357498767,26087.9031415742],[.02388076996,5.03738959686,52175.8062831484],[.01222839532,3.14159265359,0],[.0054325181,1.79644363964,78263.70942472259],[.0012977877,4.83232503958,104351.61256629678],[.00031866927,1.58088495658,130439.51570787099],[7963301e-11,4.60972126127,156527.41884944518]],[[.00274646065,3.95008450011,26087.9031415742],[.00099737713,3.14159265359,0]]],[[[.39528271651,0,0],[.07834131818,6.19233722598,26087.9031415742],[.00795525558,2.95989690104,52175.8062831484],[.00121281764,6.01064153797,78263.70942472259],[.00021921969,2.77820093972,104351.61256629678],[4354065e-11,5.82894543774,130439.51570787099]],[[.0021734774,4.65617158665,26087.9031415742],[.00044141826,1.42385544001,52175.8062831484]]]],Venus:[[[[3.17614666774,0,0],[.01353968419,5.59313319619,10213.285546211],[.00089891645,5.30650047764,20426.571092422],[5477194e-11,4.41630661466,7860.4193924392],[3455741e-11,2.6996444782,11790.6290886588],[2372061e-11,2.99377542079,3930.2096962196],[1317168e-11,5.18668228402,26.2983197998],[1664146e-11,4.25018630147,1577.3435424478],[1438387e-11,4.15745084182,9683.5945811164],[1200521e-11,6.15357116043,30639.856638633]],[[10213.28554621638,0,0],[.00095617813,2.4640651111,10213.285546211],[7787201e-11,.6247848222,20426.571092422]]],[[[.05923638472,.26702775812,10213.285546211],[.00040107978,1.14737178112,20426.571092422],[.00032814918,3.14159265359,0]],[[.00287821243,1.88964962838,10213.285546211]]],[[[.72334820891,0,0],[.00489824182,4.02151831717,10213.285546211],[1658058e-11,4.90206728031,20426.571092422],[1378043e-11,1.12846591367,11790.6290886588],[1632096e-11,2.84548795207,7860.4193924392],[498395e-11,2.58682193892,9683.5945811164],[221985e-11,2.01346696541,19367.1891622328],[237454e-11,2.55136053886,15720.8387848784]],[[.00034551041,.89198706276,10213.285546211]]]],Earth:[[[[1.75347045673,0,0],[.03341656453,4.66925680415,6283.0758499914],[.00034894275,4.62610242189,12566.1516999828],[3417572e-11,2.82886579754,3.523118349],[3497056e-11,2.74411783405,5753.3848848968],[3135899e-11,3.62767041756,77713.7714681205],[2676218e-11,4.41808345438,7860.4193924392],[2342691e-11,6.13516214446,3930.2096962196],[1273165e-11,2.03709657878,529.6909650946],[1324294e-11,.74246341673,11506.7697697936],[901854e-11,2.04505446477,26.2983197998],[1199167e-11,1.10962946234,1577.3435424478],[857223e-11,3.50849152283,398.1490034082],[779786e-11,1.17882681962,5223.6939198022],[99025e-10,5.23268072088,5884.9268465832],[753141e-11,2.53339052847,5507.5532386674],[505267e-11,4.58292599973,18849.2275499742],[492392e-11,4.20505711826,775.522611324],[356672e-11,2.91954114478,.0673103028],[284125e-11,1.89869240932,796.2980068164],[242879e-11,.34481445893,5486.777843175],[317087e-11,5.84901948512,11790.6290886588],[271112e-11,.31486255375,10977.078804699],[206217e-11,4.80646631478,2544.3144198834],[205478e-11,1.86953770281,5573.1428014331],[202318e-11,2.45767790232,6069.7767545534],[126225e-11,1.08295459501,20.7753954924],[155516e-11,.83306084617,213.299095438]],[[6283.0758499914,0,0],[.00206058863,2.67823455808,6283.0758499914],[4303419e-11,2.63512233481,12566.1516999828]],[[8721859e-11,1.07253635559,6283.0758499914]]],[[],[[.00227777722,3.4137662053,6283.0758499914],[3805678e-11,3.37063423795,12566.1516999828]]],[[[1.00013988784,0,0],[.01670699632,3.09846350258,6283.0758499914],[.00013956024,3.05524609456,12566.1516999828],[308372e-10,5.19846674381,77713.7714681205],[1628463e-11,1.17387558054,5753.3848848968],[1575572e-11,2.84685214877,7860.4193924392],[924799e-11,5.45292236722,11506.7697697936],[542439e-11,4.56409151453,3930.2096962196],[47211e-10,3.66100022149,5884.9268465832],[85831e-11,1.27079125277,161000.6857376741],[57056e-11,2.01374292245,83996.84731811189],[55736e-11,5.2415979917,71430.69561812909],[174844e-11,3.01193636733,18849.2275499742],[243181e-11,4.2734953079,11790.6290886588]],[[.00103018607,1.10748968172,6283.0758499914],[1721238e-11,1.06442300386,12566.1516999828]],[[4359385e-11,5.78455133808,6283.0758499914]]]],Mars:[[[[6.20347711581,0,0],[.18656368093,5.0503710027,3340.6124266998],[.01108216816,5.40099836344,6681.2248533996],[.00091798406,5.75478744667,10021.8372800994],[.00027744987,5.97049513147,3.523118349],[.00010610235,2.93958560338,2281.2304965106],[.00012315897,.84956094002,2810.9214616052],[8926784e-11,4.15697846427,.0172536522],[8715691e-11,6.11005153139,13362.4497067992],[6797556e-11,.36462229657,398.1490034082],[7774872e-11,3.33968761376,5621.8429232104],[3575078e-11,1.6618650571,2544.3144198834],[4161108e-11,.22814971327,2942.4634232916],[3075252e-11,.85696614132,191.4482661116],[2628117e-11,.64806124465,3337.0893083508],[2937546e-11,6.07893711402,.0673103028],[2389414e-11,5.03896442664,796.2980068164],[2579844e-11,.02996736156,3344.1355450488],[1528141e-11,1.14979301996,6151.533888305],[1798806e-11,.65634057445,529.6909650946],[1264357e-11,3.62275122593,5092.1519581158],[1286228e-11,3.06796065034,2146.1654164752],[1546404e-11,2.91579701718,1751.539531416],[1024902e-11,3.69334099279,8962.4553499102],[891566e-11,.18293837498,16703.062133499],[858759e-11,2.4009381194,2914.0142358238],[832715e-11,2.46418619474,3340.5951730476],[83272e-10,4.49495782139,3340.629680352],[712902e-11,3.66335473479,1059.3819301892],[748723e-11,3.82248614017,155.4203994342],[723861e-11,.67497311481,3738.761430108],[635548e-11,2.92182225127,8432.7643848156],[655162e-11,.48864064125,3127.3133312618],[550474e-11,3.81001042328,.9803210682],[55275e-10,4.47479317037,1748.016413067],[425966e-11,.55364317304,6283.0758499914],[415131e-11,.49662285038,213.299095438],[472167e-11,3.62547124025,1194.4470102246],[306551e-11,.38052848348,6684.7479717486],[312141e-11,.99853944405,6677.7017350506],[293198e-11,4.22131299634,20.7753954924],[302375e-11,4.48618007156,3532.0606928114],[274027e-11,.54222167059,3340.545116397],[281079e-11,5.88163521788,1349.8674096588],[231183e-11,1.28242156993,3870.3033917944],[283602e-11,5.7688543494,3149.1641605882],[236117e-11,5.75503217933,3333.498879699],[274033e-11,.13372524985,3340.6797370026],[299395e-11,2.78323740866,6254.6266625236]],[[3340.61242700512,0,0],[.01457554523,3.60433733236,3340.6124266998],[.00168414711,3.92318567804,6681.2248533996],[.00020622975,4.26108844583,10021.8372800994],[3452392e-11,4.7321039319,3.523118349],[2586332e-11,4.60670058555,13362.4497067992],[841535e-11,4.45864030426,2281.2304965106]],[[.00058152577,2.04961712429,3340.6124266998],[.00013459579,2.45738706163,6681.2248533996]]],[[[.03197134986,3.76832042431,3340.6124266998],[.00298033234,4.10616996305,6681.2248533996],[.00289104742,0,0],[.00031365539,4.4465105309,10021.8372800994],[34841e-9,4.7881254926,13362.4497067992]],[[.00217310991,6.04472194776,3340.6124266998],[.00020976948,3.14159265359,0],[.00012834709,1.60810667915,6681.2248533996]]],[[[1.53033488271,0,0],[.1418495316,3.47971283528,3340.6124266998],[.00660776362,3.81783443019,6681.2248533996],[.00046179117,4.15595316782,10021.8372800994],[8109733e-11,5.55958416318,2810.9214616052],[7485318e-11,1.77239078402,5621.8429232104],[5523191e-11,1.3643630377,2281.2304965106],[382516e-10,4.49407183687,13362.4497067992],[2306537e-11,.09081579001,2544.3144198834],[1999396e-11,5.36059617709,3337.0893083508],[2484394e-11,4.9254563992,2942.4634232916],[1960195e-11,4.74249437639,3344.1355450488],[1167119e-11,2.11260868341,5092.1519581158],[1102816e-11,5.00908403998,398.1490034082],[899066e-11,4.40791133207,529.6909650946],[992252e-11,5.83861961952,6151.533888305],[807354e-11,2.10217065501,1059.3819301892],[797915e-11,3.44839203899,796.2980068164],[740975e-11,1.49906336885,2146.1654164752]],[[.01107433345,2.03250524857,3340.6124266998],[.00103175887,2.37071847807,6681.2248533996],[128772e-9,0,0],[.0001081588,2.70888095665,10021.8372800994]],[[.00044242249,.47930604954,3340.6124266998],[8138042e-11,.86998389204,6681.2248533996]]]],Jupiter:[[[[.59954691494,0,0],[.09695898719,5.06191793158,529.6909650946],[.00573610142,1.44406205629,7.1135470008],[.00306389205,5.41734730184,1059.3819301892],[.00097178296,4.14264726552,632.7837393132],[.00072903078,3.64042916389,522.5774180938],[.00064263975,3.41145165351,103.0927742186],[.00039806064,2.29376740788,419.4846438752],[.00038857767,1.27231755835,316.3918696566],[.00027964629,1.7845459182,536.8045120954],[.0001358973,5.7748104079,1589.0728952838],[8246349e-11,3.5822792584,206.1855484372],[8768704e-11,3.63000308199,949.1756089698],[7368042e-11,5.0810119427,735.8765135318],[626315e-10,.02497628807,213.299095438],[6114062e-11,4.51319998626,1162.4747044078],[4905396e-11,1.32084470588,110.2063212194],[5305285e-11,1.30671216791,14.2270940016],[5305441e-11,4.18625634012,1052.2683831884],[4647248e-11,4.69958103684,3.9321532631],[3045023e-11,4.31676431084,426.598190876],[2609999e-11,1.56667394063,846.0828347512],[2028191e-11,1.06376530715,3.1813937377],[1764763e-11,2.14148655117,1066.49547719],[1722972e-11,3.88036268267,1265.5674786264],[1920945e-11,.97168196472,639.897286314],[1633223e-11,3.58201833555,515.463871093],[1431999e-11,4.29685556046,625.6701923124],[973272e-11,4.09764549134,95.9792272178]],[[529.69096508814,0,0],[.00489503243,4.2208293947,529.6909650946],[.00228917222,6.02646855621,7.1135470008],[.00030099479,4.54540782858,1059.3819301892],[.0002072092,5.45943156902,522.5774180938],[.00012103653,.16994816098,536.8045120954],[6067987e-11,4.42422292017,103.0927742186],[5433968e-11,3.98480737746,419.4846438752],[4237744e-11,5.89008707199,14.2270940016]],[[.00047233601,4.32148536482,7.1135470008],[.00030649436,2.929777887,529.6909650946],[.00014837605,3.14159265359,0]]],[[[.02268615702,3.55852606721,529.6909650946],[.00109971634,3.90809347197,1059.3819301892],[.00110090358,0,0],[8101428e-11,3.60509572885,522.5774180938],[6043996e-11,4.25883108339,1589.0728952838],[6437782e-11,.30627119215,536.8045120954]],[[.00078203446,1.52377859742,529.6909650946]]],[[[5.20887429326,0,0],[.25209327119,3.49108639871,529.6909650946],[.00610599976,3.84115365948,1059.3819301892],[.00282029458,2.57419881293,632.7837393132],[.00187647346,2.07590383214,522.5774180938],[.00086792905,.71001145545,419.4846438752],[.00072062974,.21465724607,536.8045120954],[.00065517248,5.9799588479,316.3918696566],[.00029134542,1.67759379655,103.0927742186],[.00030135335,2.16132003734,949.1756089698],[.00023453271,3.54023522184,735.8765135318],[.00022283743,4.19362594399,1589.0728952838],[.00023947298,.2745803748,7.1135470008],[.00013032614,2.96042965363,1162.4747044078],[970336e-10,1.90669633585,206.1855484372],[.00012749023,2.71550286592,1052.2683831884],[7057931e-11,2.18184839926,1265.5674786264],[6137703e-11,6.26418240033,846.0828347512],[2616976e-11,2.00994012876,1581.959348283]],[[.0127180152,2.64937512894,529.6909650946],[.00061661816,3.00076460387,1059.3819301892],[.00053443713,3.89717383175,522.5774180938],[.00031185171,4.88276958012,536.8045120954],[.00041390269,0,0]]]],Saturn:[[[[.87401354025,0,0],[.11107659762,3.96205090159,213.299095438],[.01414150957,4.58581516874,7.1135470008],[.00398379389,.52112032699,206.1855484372],[.00350769243,3.30329907896,426.598190876],[.00206816305,.24658372002,103.0927742186],[792713e-9,3.84007056878,220.4126424388],[.00023990355,4.66976924553,110.2063212194],[.00016573588,.43719228296,419.4846438752],[.00014906995,5.76903183869,316.3918696566],[.0001582029,.93809155235,632.7837393132],[.00014609559,1.56518472,3.9321532631],[.00013160301,4.44891291899,14.2270940016],[.00015053543,2.71669915667,639.897286314],[.00013005299,5.98119023644,11.0457002639],[.00010725067,3.12939523827,202.2533951741],[5863206e-11,.23656938524,529.6909650946],[5227757e-11,4.20783365759,3.1813937377],[6126317e-11,1.76328667907,277.0349937414],[5019687e-11,3.17787728405,433.7117378768],[459255e-10,.61977744975,199.0720014364],[4005867e-11,2.24479718502,63.7358983034],[2953796e-11,.98280366998,95.9792272178],[387367e-10,3.22283226966,138.5174968707],[2461186e-11,2.03163875071,735.8765135318],[3269484e-11,.77492638211,949.1756089698],[1758145e-11,3.2658010994,522.5774180938],[1640172e-11,5.5050445305,846.0828347512],[1391327e-11,4.02333150505,323.5054166574],[1580648e-11,4.37265307169,309.2783226558],[1123498e-11,2.83726798446,415.5524906121],[1017275e-11,3.71700135395,227.5261894396],[848642e-11,3.1915017083,209.3669421749]],[[213.2990952169,0,0],[.01297370862,1.82834923978,213.299095438],[.00564345393,2.88499717272,7.1135470008],[.00093734369,1.06311793502,426.598190876],[.00107674962,2.27769131009,206.1855484372],[.00040244455,2.04108104671,220.4126424388],[.00019941774,1.2795439047,103.0927742186],[.00010511678,2.7488034213,14.2270940016],[6416106e-11,.38238295041,639.897286314],[4848994e-11,2.43037610229,419.4846438752],[4056892e-11,2.92133209468,110.2063212194],[3768635e-11,3.6496533078,3.9321532631]],[[.0011644133,1.17988132879,7.1135470008],[.00091841837,.0732519584,213.299095438],[.00036661728,0,0],[.00015274496,4.06493179167,206.1855484372]]],[[[.04330678039,3.60284428399,213.299095438],[.00240348302,2.85238489373,426.598190876],[.00084745939,0,0],[.00030863357,3.48441504555,220.4126424388],[.00034116062,.57297307557,206.1855484372],[.0001473407,2.11846596715,639.897286314],[9916667e-11,5.79003188904,419.4846438752],[6993564e-11,4.7360468972,7.1135470008],[4807588e-11,5.43305312061,316.3918696566]],[[.00198927992,4.93901017903,213.299095438],[.00036947916,3.14159265359,0],[.00017966989,.5197943111,426.598190876]]],[[[9.55758135486,0,0],[.52921382865,2.39226219573,213.299095438],[.01873679867,5.2354960466,206.1855484372],[.01464663929,1.64763042902,426.598190876],[.00821891141,5.93520042303,316.3918696566],[.00547506923,5.0153261898,103.0927742186],[.0037168465,2.27114821115,220.4126424388],[.00361778765,3.13904301847,7.1135470008],[.00140617506,5.70406606781,632.7837393132],[.00108974848,3.29313390175,110.2063212194],[.00069006962,5.94099540992,419.4846438752],[.00061053367,.94037691801,639.897286314],[.00048913294,1.55733638681,202.2533951741],[.00034143772,.19519102597,277.0349937414],[.00032401773,5.47084567016,949.1756089698],[.00020936596,.46349251129,735.8765135318],[9796004e-11,5.20477537945,1265.5674786264],[.00011993338,5.98050967385,846.0828347512],[208393e-9,1.52102476129,433.7117378768],[.00015298404,3.0594381494,529.6909650946],[6465823e-11,.17732249942,1052.2683831884],[.00011380257,1.7310542704,522.5774180938],[3419618e-11,4.94550542171,1581.959348283]],[[.0618298134,.2584351148,213.299095438],[.00506577242,.71114625261,206.1855484372],[.00341394029,5.79635741658,426.598190876],[.00188491195,.47215589652,220.4126424388],[.00186261486,3.14159265359,0],[.00143891146,1.40744822888,7.1135470008]],[[.00436902572,4.78671677509,213.299095438]]]],Uranus:[[[[5.48129294297,0,0],[.09260408234,.89106421507,74.7815985673],[.01504247898,3.6271926092,1.4844727083],[.00365981674,1.89962179044,73.297125859],[.00272328168,3.35823706307,149.5631971346],[.00070328461,5.39254450063,63.7358983034],[.00068892678,6.09292483287,76.2660712756],[.00061998615,2.26952066061,2.9689454166],[.00061950719,2.85098872691,11.0457002639],[.0002646877,3.14152083966,71.8126531507],[.00025710476,6.11379840493,454.9093665273],[.0002107885,4.36059339067,148.0787244263],[.00017818647,1.74436930289,36.6485629295],[.00014613507,4.73732166022,3.9321532631],[.00011162509,5.8268179635,224.3447957019],[.0001099791,.48865004018,138.5174968707],[9527478e-11,2.95516862826,35.1640902212],[7545601e-11,5.236265824,109.9456887885],[4220241e-11,3.23328220918,70.8494453042],[40519e-9,2.277550173,151.0476698429],[3354596e-11,1.0654900738,4.4534181249],[2926718e-11,4.62903718891,9.5612275556],[349034e-10,5.48306144511,146.594251718],[3144069e-11,4.75199570434,77.7505439839],[2922333e-11,5.35235361027,85.8272988312],[2272788e-11,4.36600400036,70.3281804424],[2051219e-11,1.51773566586,.1118745846],[2148602e-11,.60745949945,38.1330356378],[1991643e-11,4.92437588682,277.0349937414],[1376226e-11,2.04283539351,65.2203710117],[1666902e-11,3.62744066769,380.12776796],[1284107e-11,3.11347961505,202.2533951741],[1150429e-11,.93343589092,3.1813937377],[1533221e-11,2.58594681212,52.6901980395],[1281604e-11,.54271272721,222.8603229936],[1372139e-11,4.19641530878,111.4301614968],[1221029e-11,.1990065003,108.4612160802],[946181e-11,1.19253165736,127.4717966068],[1150989e-11,4.17898916639,33.6796175129]],[[74.7815986091,0,0],[.00154332863,5.24158770553,74.7815985673],[.00024456474,1.71260334156,1.4844727083],[9258442e-11,.4282973235,11.0457002639],[8265977e-11,1.50218091379,63.7358983034],[915016e-10,1.41213765216,149.5631971346]]],[[[.01346277648,2.61877810547,74.7815985673],[623414e-9,5.08111189648,149.5631971346],[.00061601196,3.14159265359,0],[9963722e-11,1.61603805646,76.2660712756],[992616e-10,.57630380333,73.297125859]],[[.00034101978,.01321929936,74.7815985673]]],[[[19.21264847206,0,0],[.88784984413,5.60377527014,74.7815985673],[.03440836062,.32836099706,73.297125859],[.0205565386,1.7829515933,149.5631971346],[.0064932241,4.52247285911,76.2660712756],[.00602247865,3.86003823674,63.7358983034],[.00496404167,1.40139935333,454.9093665273],[.00338525369,1.58002770318,138.5174968707],[.00243509114,1.57086606044,71.8126531507],[.00190522303,1.99809394714,1.4844727083],[.00161858838,2.79137786799,148.0787244263],[.00143706183,1.38368544947,11.0457002639],[.00093192405,.17437220467,36.6485629295],[.00071424548,4.24509236074,224.3447957019],[.00089806014,3.66105364565,109.9456887885],[.00039009723,1.66971401684,70.8494453042],[.00046677296,1.39976401694,35.1640902212],[.00039025624,3.36234773834,277.0349937414],[.00036755274,3.88649278513,146.594251718],[.00030348723,.70100838798,151.0476698429],[.00029156413,3.180563367,77.7505439839],[.00022637073,.72518687029,529.6909650946],[.00011959076,1.7504339214,984.6003316219],[.00025620756,5.25656086672,380.12776796]],[[.01479896629,3.67205697578,74.7815985673]]]],Neptune:[[[[5.31188633046,0,0],[.0179847553,2.9010127389,38.1330356378],[.01019727652,.48580922867,1.4844727083],[.00124531845,4.83008090676,36.6485629295],[.00042064466,5.41054993053,2.9689454166],[.00037714584,6.09221808686,35.1640902212],[.00033784738,1.24488874087,76.2660712756],[.00016482741,7727998e-11,491.5579294568],[9198584e-11,4.93747051954,39.6175083461],[899425e-10,.27462171806,175.1660598002]],[[38.13303563957,0,0],[.00016604172,4.86323329249,1.4844727083],[.00015744045,2.27887427527,38.1330356378]]],[[[.03088622933,1.44104372644,38.1330356378],[.00027780087,5.91271884599,76.2660712756],[.00027623609,0,0],[.00015355489,2.52123799551,36.6485629295],[.00015448133,3.50877079215,39.6175083461]]],[[[30.07013205828,0,0],[.27062259632,1.32999459377,38.1330356378],[.01691764014,3.25186135653,36.6485629295],[.00807830553,5.18592878704,1.4844727083],[.0053776051,4.52113935896,35.1640902212],[.00495725141,1.5710564165,491.5579294568],[.00274571975,1.84552258866,175.1660598002],[.0001201232,1.92059384991,1021.2488945514],[.00121801746,5.79754470298,76.2660712756],[.00100896068,.3770272493,73.297125859],[.00135134092,3.37220609835,39.6175083461],[7571796e-11,1.07149207335,388.4651552382]]]]};function AT(a){var t,e,i,n,s,r,o;const c=2e3+(a-14)/uT;return c<-500?(t=(c-1820)/100,-20+32*t*t):c<500?(t=c/100,e=t*t,i=t*e,n=e*e,s=e*i,r=i*i,10583.6-1014.41*t+33.78311*e-5.952053*i-.1798452*n+.022174192*s+.0090316521*r):c<1600?(t=(c-1e3)/100,e=t*t,i=t*e,n=e*e,s=e*i,r=i*i,1574.2-556.01*t+71.23472*e+.319781*i-.8503463*n-.005050998*s+.0083572073*r):c<1700?(t=c-1600,e=t*t,i=t*e,120-.9808*t-.01532*e+i/7129):c<1800?(t=c-1700,e=t*t,i=t*e,n=e*e,8.83+.1603*t-.0059285*e+13336e-8*i-n/1174e3):c<1860?(t=c-1800,e=t*t,i=t*e,n=e*e,s=e*i,r=i*i,o=i*n,13.72-.332447*t+.0068612*e+.0041116*i-37436e-8*n+121272e-10*s-1699e-10*r+875e-12*o):c<1900?(t=c-1860,e=t*t,i=t*e,n=e*e,s=e*i,7.62+.5737*t-.251754*e+.01680668*i-.0004473624*n+s/233174):c<1920?(t=c-1900,e=t*t,i=t*e,n=e*e,-2.79+1.494119*t-.0598939*e+.0061966*i-197e-6*n):c<1941?(t=c-1920,e=t*t,i=t*e,21.2+.84493*t-.0761*e+.0020936*i):c<1961?(t=c-1950,e=t*t,i=t*e,29.07+.407*t-e/233+i/2547):c<1986?(t=c-1975,e=t*t,i=t*e,45.45+1.067*t-e/260-i/718):c<2005?(t=c-2e3,e=t*t,i=t*e,n=e*e,s=e*i,63.86+.3345*t-.060374*e+.0017275*i+651814e-9*n+2373599e-11*s):c<2050?(t=c-2e3,62.92+.32217*t+.005589*t*t):c<2150?(t=(c-1820)/100,-20+32*t*t-.5628*(2150-c)):(t=(c-1820)/100,-20+32*t*t)}let TT=AT;function Y1(a){return a+TT(a)/86400}class La{constructor(t){if(t instanceof La){this.date=t.date,this.ut=t.ut,this.tt=t.tt;return}const e=1e3*3600*24;if(t instanceof Date&&Number.isFinite(t.getTime())){this.date=t,this.ut=(t.getTime()-W1.getTime())/e,this.tt=Y1(this.ut);return}if(Number.isFinite(t)){this.date=new Date(W1.getTime()+t*e),this.ut=t,this.tt=Y1(this.ut);return}throw"Argument must be a Date object, an AstroTime object, or a numeric UTC Julian date."}static FromTerrestrialTime(t){let e=new La(t);for(;;){const i=t-e.tt;if(Math.abs(i)<1e-12)return e;e=e.AddDays(i)}}toString(){return this.date.toISOString()}AddDays(t){return new La(this.ut+t)}}function RT(a,t,e){return new La(a.ut+e*(t.ut-a.ut))}function Ne(a){return a instanceof La?a:new La(a)}function DT(a){function t(d){return d%dT*Oo}const e=a.tt/36525,i=t(128710479305e-5+e*1295965810481e-4),n=t(335779.526232+e*17395272628478e-4),s=t(107226070369e-5+e*1602961601209e-3),r=t(450160.398036-e*69628905431e-4);let o=Math.sin(r),c=Math.cos(r),l=(-172064161-174666*e)*o+33386*c,h=(92052331+9086*e)*c+15377*o,u=2*(n-s+r);return o=Math.sin(u),c=Math.cos(u),l+=(-13170906-1675*e)*o-13696*c,h+=(5730336-3015*e)*c-4587*o,u=2*(n+r),o=Math.sin(u),c=Math.cos(u),l+=(-2276413-234*e)*o+2796*c,h+=(978459-485*e)*c+1374*o,u=2*r,o=Math.sin(u),c=Math.cos(u),l+=(2074554+207*e)*o-698*c,h+=(-897492+470*e)*c-291*o,o=Math.sin(i),c=Math.cos(i),l+=(1475877-3633*e)*o+11817*c,h+=(73871-184*e)*c-1924*o,{dpsi:-135e-6+l*1e-7,deps:388e-6+h*1e-7}}function D2(a){var t=a.tt/36525,e=((((-434e-10*t-576e-9)*t+.0020034)*t-1831e-7)*t-46.836769)*t+84381.406;return e/3600}var mh;function _l(a){if(!mh||Math.abs(mh.tt-a.tt)>1e-6){const t=DT(a),e=D2(a),i=e+t.deps/3600;mh={tt:a.tt,dpsi:t.dpsi,deps:t.deps,ee:t.dpsi*Math.cos(e*mt)/15,mobl:e,tobl:i}}return mh}function IT(a,t){const e=a*mt,i=Math.cos(e),n=Math.sin(e);return[t[0],t[1]*i-t[2]*n,t[1]*n+t[2]*i]}function CT(a,t){return IT(D2(a),t)}function I2(a){const t=a.tt/36525;function e(Lt,_t){const Ht=[];let Vt;for(Vt=0;Vt<=_t-Lt;++Vt)Ht.push(0);return{min:Lt,array:Ht}}function i(Lt,_t,Ht,Vt){const Wt=[];for(let Te=0;Te<=_t-Lt;++Te)Wt.push(e(Ht,Vt));return{min:Lt,array:Wt}}function n(Lt,_t,Ht){const Vt=Lt.array[_t-Lt.min];return Vt.array[Ht-Vt.min]}function s(Lt,_t,Ht,Vt){const Wt=Lt.array[_t-Lt.min];Wt.array[Ht-Wt.min]=Vt}let r,o,c,l,h,u,d,f,p,v,m,g,b,S,M,x,_,E,y,T,I,C,P,B=i(-6,6,1,4),W=i(-6,6,1,4);function O(Lt,_t){return n(B,Lt,_t)}function H(Lt,_t){return n(W,Lt,_t)}function U(Lt,_t,Ht){return s(B,Lt,_t,Ht)}function q(Lt,_t,Ht){return s(W,Lt,_t,Ht)}function Q(Lt,_t,Ht,Vt,Wt){Wt(Lt*Ht-_t*Vt,_t*Ht+Lt*Vt)}function J(Lt){return Math.sin(js*Lt)}d=t*t,p=0,P=0,m=0,g=3422.7;var it=J(.19833+.05611*t),ot=J(.27869+.04508*t),$t=J(.16827-.36903*t),re=J(.34734-5.37261*t),jt=J(.10498-5.37899*t),$=J(.42681-.41855*t),rt=J(.14943-5.37511*t);for(E=.84*it+.31*ot+14.27*$t+7.26*re+.28*jt+.24*$,y=2.94*it+.31*ot+14.27*$t+9.34*re+1.12*jt+.83*$,T=-6.4*it-1.89*$,I=.21*it+.31*ot+14.27*$t-88.7*re-15.3*jt+.24*$-1.86*rt,C=E-T,f=-3332e-9*J(.59734-5.37261*t)-539e-9*J(.35498-5.37899*t)-64e-9*J(.39943-5.37511*t),b=js*So(.60643382+1336.85522467*t-313e-8*d)+E/Er,S=js*So(.37489701+1325.55240982*t+2565e-8*d)+y/Er,M=js*So(.99312619+99.99735956*t-44e-8*d)+T/Er,x=js*So(.25909118+1342.2278298*t-892e-8*d)+I/Er,_=js*So(.82736186+1236.85308708*t-397e-8*d)+C/Er,h=1;h<=4;++h){switch(h){case 1:c=S,o=4,l=1.000002208;break;case 2:c=M,o=3,l=.997504612-.002495388*t;break;case 3:c=x,o=4,l=1.000002708+139.978*f;break;case 4:c=_,o=6,l=1;break;default:throw`Internal error: I = ${h}`}for(U(0,h,1),U(1,h,Math.cos(c)*l),q(0,h,0),q(1,h,Math.sin(c)*l),u=2;u<=o;++u)Q(O(u-1,h),H(u-1,h),O(1,h),H(1,h),(Lt,_t)=>(U(u,h,Lt),q(u,h,_t)));for(u=1;u<=o;++u)U(-u,h,O(u,h)),q(-u,h,-H(u,h))}function nt(Lt,_t,Ht,Vt){for(var Wt={x:1,y:0},Te=[0,Lt,_t,Ht,Vt],Re=1;Re<=4;++Re)Te[Re]!==0&&Q(Wt.x,Wt.y,O(Te[Re],Re),H(Te[Re],Re),(ci,ei)=>(Wt.x=ci,Wt.y=ei));return Wt}function z(Lt,_t,Ht,Vt,Wt,Te,Re,ci){var ei=nt(Wt,Te,Re,ci);p+=Lt*ei.y,P+=_t*ei.y,m+=Ht*ei.x,g+=Vt*ei.x}z(13.902,14.06,-.001,.2607,0,0,0,4),z(.403,-4.01,.394,.0023,0,0,0,3),z(2369.912,2373.36,.601,28.2333,0,0,0,2),z(-125.154,-112.79,-.725,-.9781,0,0,0,1),z(1.979,6.98,-.445,.0433,1,0,0,4),z(191.953,192.72,.029,3.0861,1,0,0,2),z(-8.466,-13.51,.455,-.1093,1,0,0,1),z(22639.5,22609.07,.079,186.5398,1,0,0,0),z(18.609,3.59,-.094,.0118,1,0,0,-1),z(-4586.465,-4578.13,-.077,34.3117,1,0,0,-2),z(3.215,5.44,.192,-.0386,1,0,0,-3),z(-38.428,-38.64,.001,.6008,1,0,0,-4),z(-.393,-1.43,-.092,.0086,1,0,0,-6),z(-.289,-1.59,.123,-.0053,0,1,0,4),z(-24.42,-25.1,.04,-.3,0,1,0,2),z(18.023,17.93,.007,.1494,0,1,0,1),z(-668.146,-126.98,-1.302,-.3997,0,1,0,0),z(.56,.32,-.001,-.0037,0,1,0,-1),z(-165.145,-165.06,.054,1.9178,0,1,0,-2),z(-1.877,-6.46,-.416,.0339,0,1,0,-4),z(.213,1.02,-.074,.0054,2,0,0,4),z(14.387,14.78,-.017,.2833,2,0,0,2),z(-.586,-1.2,.054,-.01,2,0,0,1),z(769.016,767.96,.107,10.1657,2,0,0,0),z(1.75,2.01,-.018,.0155,2,0,0,-1),z(-211.656,-152.53,5.679,-.3039,2,0,0,-2),z(1.225,.91,-.03,-.0088,2,0,0,-3),z(-30.773,-34.07,-.308,.3722,2,0,0,-4),z(-.57,-1.4,-.074,.0109,2,0,0,-6),z(-2.921,-11.75,.787,-.0484,1,1,0,2),z(1.267,1.52,-.022,.0164,1,1,0,1),z(-109.673,-115.18,.461,-.949,1,1,0,0),z(-205.962,-182.36,2.056,1.4437,1,1,0,-2),z(.233,.36,.012,-.0025,1,1,0,-3),z(-4.391,-9.66,-.471,.0673,1,1,0,-4),z(.283,1.53,-.111,.006,1,-1,0,4),z(14.577,31.7,-1.54,.2302,1,-1,0,2),z(147.687,138.76,.679,1.1528,1,-1,0,0),z(-1.089,.55,.021,0,1,-1,0,-1),z(28.475,23.59,-.443,-.2257,1,-1,0,-2),z(-.276,-.38,-.006,-.0036,1,-1,0,-3),z(.636,2.27,.146,-.0102,1,-1,0,-4),z(-.189,-1.68,.131,-.0028,0,2,0,2),z(-7.486,-.66,-.037,-.0086,0,2,0,0),z(-8.096,-16.35,-.74,.0918,0,2,0,-2),z(-5.741,-.04,0,-9e-4,0,0,2,2),z(.255,0,0,0,0,0,2,1),z(-411.608,-.2,0,-.0124,0,0,2,0),z(.584,.84,0,.0071,0,0,2,-1),z(-55.173,-52.14,0,-.1052,0,0,2,-2),z(.254,.25,0,-.0017,0,0,2,-3),z(.025,-1.67,0,.0031,0,0,2,-4),z(1.06,2.96,-.166,.0243,3,0,0,2),z(36.124,50.64,-1.3,.6215,3,0,0,0),z(-13.193,-16.4,.258,-.1187,3,0,0,-2),z(-1.187,-.74,.042,.0074,3,0,0,-4),z(-.293,-.31,-.002,.0046,3,0,0,-6),z(-.29,-1.45,.116,-.0051,2,1,0,2),z(-7.649,-10.56,.259,-.1038,2,1,0,0),z(-8.627,-7.59,.078,-.0192,2,1,0,-2),z(-2.74,-2.54,.022,.0324,2,1,0,-4),z(1.181,3.32,-.212,.0213,2,-1,0,2),z(9.703,11.67,-.151,.1268,2,-1,0,0),z(-.352,-.37,.001,-.0028,2,-1,0,-1),z(-2.494,-1.17,-.003,-.0017,2,-1,0,-2),z(.36,.2,-.012,-.0043,2,-1,0,-4),z(-1.167,-1.25,.008,-.0106,1,2,0,0),z(-7.412,-6.12,.117,.0484,1,2,0,-2),z(-.311,-.65,-.032,.0044,1,2,0,-4),z(.757,1.82,-.105,.0112,1,-2,0,2),z(2.58,2.32,.027,.0196,1,-2,0,0),z(2.533,2.4,-.014,-.0212,1,-2,0,-2),z(-.344,-.57,-.025,.0036,0,3,0,-2),z(-.992,-.02,0,0,1,0,2,2),z(-45.099,-.02,0,-.001,1,0,2,0),z(-.179,-9.52,0,-.0833,1,0,2,-2),z(-.301,-.33,0,.0014,1,0,2,-4),z(-6.382,-3.37,0,-.0481,1,0,-2,2),z(39.528,85.13,0,-.7136,1,0,-2,0),z(9.366,.71,0,-.0112,1,0,-2,-2),z(.202,.02,0,0,1,0,-2,-4),z(.415,.1,0,.0013,0,1,2,0),z(-2.152,-2.26,0,-.0066,0,1,2,-2),z(-1.44,-1.3,0,.0014,0,1,-2,2),z(.384,-.04,0,0,0,1,-2,-2),z(1.938,3.6,-.145,.0401,4,0,0,0),z(-.952,-1.58,.052,-.013,4,0,0,-2),z(-.551,-.94,.032,-.0097,3,1,0,0),z(-.482,-.57,.005,-.0045,3,1,0,-2),z(.681,.96,-.026,.0115,3,-1,0,0),z(-.297,-.27,.002,-9e-4,2,2,0,-2),z(.254,.21,-.003,0,2,-2,0,-2),z(-.25,-.22,.004,.0014,1,3,0,-2),z(-3.996,0,0,4e-4,2,0,2,0),z(.557,-.75,0,-.009,2,0,2,-2),z(-.459,-.38,0,-.0053,2,0,-2,2),z(-1.298,.74,0,4e-4,2,0,-2,0),z(.538,1.14,0,-.0141,2,0,-2,-2),z(.263,.02,0,0,1,1,2,0),z(.426,.07,0,-6e-4,1,1,-2,-2),z(-.304,.03,0,3e-4,1,-1,2,0),z(-.372,-.19,0,-.0027,1,-1,-2,2),z(.418,0,0,0,0,0,4,0),z(-.33,-.04,0,0,3,0,2,0);function It(Lt,_t,Ht,Vt,Wt){return Lt*nt(_t,Ht,Vt,Wt).y}v=0,v+=It(-526.069,0,0,1,-2),v+=It(-3.352,0,0,1,-4),v+=It(44.297,1,0,1,-2),v+=It(-6,1,0,1,-4),v+=It(20.599,-1,0,1,0),v+=It(-30.598,-1,0,1,-2),v+=It(-24.649,-2,0,1,0),v+=It(-2,-2,0,1,-2),v+=It(-22.571,0,1,1,-2),v+=It(10.985,0,-1,1,-2),p+=.82*J(.7736-62.5512*t)+.31*J(.0466-125.1025*t)+.35*J(.5785-25.1042*t)+.66*J(.4591+1335.8075*t)+.64*J(.313-91.568*t)+1.14*J(.148+1331.2898*t)+.21*J(.5918+1056.5859*t)+.44*J(.5784+1322.8595*t)+.24*J(.2275-5.7374*t)+.28*J(.2965+2.6929*t)+.33*J(.3132+6.3368*t),r=x+P/Er;let Ut=(1.000002708+139.978*f)*(18518.511+1.189+m)*Math.sin(r)-6.24*Math.sin(3*r)+v;return{geo_eclip_lon:js*So((b+p/Er)/js),geo_eclip_lat:Math.PI/(180*3600)*Ut,distance_au:Er*yT/(.999953253*g)}}function C2(a,t){return[a.rot[0][0]*t[0]+a.rot[1][0]*t[1]+a.rot[2][0]*t[2],a.rot[0][1]*t[0]+a.rot[1][1]*t[1]+a.rot[2][1]*t[2],a.rot[0][2]*t[0]+a.rot[1][2]*t[1]+a.rot[2][2]*t[2]]}function pl(a,t,e){const i=sm(t,e);return C2(i,a)}function sm(a,t){const e=a.tt/36525;let i=84381.406,n=((((-951e-10*e+132851e-9)*e-.00114045)*e-1.0790069)*e+5038.481507)*e,s=((((3337e-10*e-467e-9)*e-.00772503)*e+.0512623)*e-.025754)*e+i,r=((((-56e-9*e+170663e-9)*e-.00121197)*e-2.3814292)*e+10.556403)*e;i*=Oo,n*=Oo,s*=Oo,r*=Oo;const o=Math.sin(i),c=Math.cos(i),l=Math.sin(-n),h=Math.cos(-n),u=Math.sin(-s),d=Math.cos(-s),f=Math.sin(r),p=Math.cos(r),v=p*h-l*f*d,m=p*l*c+f*d*h*c-o*f*u,g=p*l*o+f*d*h*o+c*f*u,b=-f*h-l*p*d,S=-f*l*c+p*d*h*c-o*p*u,M=-f*l*o+p*d*h*o+c*p*u,x=l*u,_=-u*h*c-o*d,E=-u*h*o+d*c;if(t===Ri.Into2000)return new Ws([[v,m,g],[b,S,M],[x,_,E]]);if(t===Ri.From2000)return new Ws([[v,b,x],[m,S,_],[g,M,E]]);throw"Invalid precess direction"}function PT(a){const t=.779057273264+.00273781191135448*a.ut,e=a.ut%1;let i=360*((t+e)%1);return i<0&&(i+=360),i}let gh;function El(a){if(!gh||gh.tt!==a.tt){const t=a.tt/36525;let e=15*_l(a).ee;const i=PT(a);let s=((e+.014506+((((-368e-10*t-29956e-9)*t-44e-8)*t+1.3915817)*t+4612.156534)*t)/3600+i)%360/15;s<0&&(s+=24),gh={tt:a.tt,st:s}}return gh.st}function OT(a){const t=Ne(a);return El(t)}function P2(a,t){const e=a.latitude*mt,i=Math.sin(e),n=Math.cos(e),s=1/Math.hypot(n,Z0*i),r=MT*s,o=a.height/1e3,c=J0*s+o,l=J0*r+o,h=(15*t+a.longitude)*mt,u=Math.sin(h),d=Math.cos(h);return{pos:[c*n*d/Ls,c*n*u/Ls,l*i/Ls],vel:[-X1*c*n*u*86400/Ls,X1*c*n*d*86400/Ls,0]}}function Uu(a,t,e){const i=rm(t,e);return C2(i,a)}function rm(a,t){const e=_l(a),i=e.mobl*mt,n=e.tobl*mt,s=e.dpsi*Oo,r=Math.cos(i),o=Math.sin(i),c=Math.cos(n),l=Math.sin(n),h=Math.cos(s),u=Math.sin(s),d=h,f=-u*r,p=-u*o,v=u*c,m=h*r*c+o*l,g=h*o*c-r*l,b=u*l,S=h*r*l-o*c,M=h*o*l+r*c;if(t===Ri.From2000)return new Ws([[d,v,b],[f,m,S],[p,g,M]]);if(t===Ri.Into2000)return new Ws([[d,f,p],[v,m,g],[b,S,M]]);throw"Invalid precess direction"}function cd(a,t,e){return e===Ri.Into2000?pl(Uu(a,t,e),t,e):Uu(pl(a,t,e),t,e)}function O2(a,t){const e=El(a),i=P2(t,e).pos;return cd(i,a,Ri.Into2000)}class ge{constructor(t,e,i,n){this.x=t,this.y=e,this.z=i,this.t=n}Length(){return Math.hypot(this.x,this.y,this.z)}}class zr{constructor(t,e,i,n,s,r,o){this.x=t,this.y=e,this.z=i,this.vx=n,this.vy=s,this.vz=r,this.t=o}}class ld{constructor(t,e,i){this.lat=Si(t),this.lon=Si(e),this.dist=Si(i)}}class ip{constructor(t,e,i,n){this.ra=Si(t),this.dec=Si(e),this.dist=Si(i),this.vec=n}}class Ws{constructor(t){this.rot=t}}class LT{constructor(t,e,i,n){this.azimuth=Si(t),this.altitude=Si(e),this.ra=Si(i),this.dec=Si(n)}}class NT{constructor(t,e,i){this.vec=t,this.elat=Si(e),this.elon=Si(i)}}function L2(a,t){return new ge(a[0],a[1],a[2],t)}function kT(a,t){const e=L2(a,t),i=e.x*e.x+e.y*e.y,n=Math.sqrt(i+e.z*e.z);if(i===0){if(e.z===0)throw"Indeterminate sky coordinates";return new ip(0,e.z<0?-90:90,n,e)}let s=E2*Math.atan2(e.y,e.x);s<0&&(s+=24);const r=fs*Math.atan2(a[2],Math.sqrt(i));return new ip(s,r,n,e)}function Wo(a,t){const e=a*mt,i=Math.cos(e),n=Math.sin(e);return[i*t[0]+n*t[1],i*t[1]-n*t[0],t[2]]}function am(a,t,e,i,n){let s=Ne(a);hd(t),Si(e),Si(i);const r=Math.sin(t.latitude*mt),o=Math.cos(t.latitude*mt),c=Math.sin(t.longitude*mt),l=Math.cos(t.longitude*mt),h=Math.sin(i*mt),u=Math.cos(i*mt),d=Math.sin(e*V1),f=Math.cos(e*V1);let p=[o*l,o*c,r],v=[-r*l,-r*c,o],m=[c,-l,0];const g=-15*El(s);let b=Wo(g,p),S=Wo(g,v),M=Wo(g,m),x=[u*f,u*d,h];const _=x[0]*b[0]+x[1]*b[1]+x[2]*b[2],E=x[0]*S[0]+x[1]*S[1]+x[2]*S[2],y=x[0]*M[0]+x[1]*M[1]+x[2]*M[2];let T=Math.hypot(E,y),I;T>0?(I=-fs*Math.atan2(y,E),I<0&&(I+=360)):I=0;let C=fs*Math.atan2(T,_),P=e,B=i;if(n){let W=C,O=V2(n,90-C);if(C-=O,O>0&&C>3e-4){const H=Math.sin(C*mt),U=Math.cos(C*mt),q=Math.sin(W*mt),Q=Math.cos(W*mt),J=[];for(let it=0;it<3;++it)J.push((x[it]-Q*b[it])/q*H+b[it]*U);T=Math.hypot(J[0],J[1]),T>0?(P=E2*Math.atan2(J[1],J[0]),P<0&&(P+=24)):P=0,B=fs*Math.atan2(J[2],T)}}return new LT(I,90-C,P,B)}function hd(a){if(!(a instanceof qr))throw`Not an instance of the Observer class: ${a}`;if(Si(a.latitude),Si(a.longitude),Si(a.height),a.latitude<-90||a.latitude>90)throw`Latitude ${a.latitude} is out of range. Must be -90..+90.`;return a}class qr{constructor(t,e,i){this.latitude=t,this.longitude=e,this.height=i,hd(this)}}function FT(a){const t=Ne(a).AddDays(-1/em),e=Yo(zs.Earth,t),i=[-e.x,-e.y,-e.z],[n,s,r]=cd(i,t,Ri.From2000),o=mt*_l(t).tobl,c=Math.cos(o),l=Math.sin(o),h=new ge(n,s,r,t);return N2(h,c,l)}function ml(a,t,e,i,n){hd(e),Fu(i),Fu(n);const s=Ne(t),r=O2(s,e),o=Bu(a,s,n),c=[o.x-r[0],o.y-r[1],o.z-r[2]],l=cd(c,s,Ri.From2000);return kT(l,s)}function np(a,t,e){const i=Ne(a),n=El(i);let s=P2(t,n).pos;return e||(s=cd(s,i,Ri.Into2000)),L2(s,i)}function N2(a,t,e){const i=a.x,n=a.y*t+a.z*e,s=-a.y*e+a.z*t,r=Math.hypot(i,n);let o=0;r>0&&(o=fs*Math.atan2(n,i),o<0&&(o+=360));let c=fs*Math.atan2(s,r),l=new ge(i,n,s,a.t);return new NT(l,c,o)}function sp(a){const t=_l(a.t),e=[a.x,a.y,a.z],i=pl(e,a.t,Ri.From2000),[n,s,r]=Uu(i,a.t,Ri.From2000),o=new ge(n,s,r,a.t),c=t.tobl*mt;return N2(o,Math.cos(c),Math.sin(c))}function ur(a){const t=Ne(a),e=I2(t),i=e.distance_au*Math.cos(e.geo_eclip_lat),n=[i*Math.cos(e.geo_eclip_lon),i*Math.sin(e.geo_eclip_lon),e.distance_au*Math.sin(e.geo_eclip_lat)],s=CT(t,n),r=pl(s,t,Ri.Into2000);return new ge(r[0],r[1],r[2],t)}function k2(a){const t=Ne(a),e=1e-5,i=t.AddDays(-e),n=t.AddDays(+e),s=ur(i),r=ur(n);return new zr((s.x+r.x)/2,(s.y+r.y)/2,(s.z+r.z)/2,(r.x-s.x)/(2*e),(r.y-s.y)/(2*e),(r.z-s.z)/(2*e),t)}function UT(a){const t=Ne(a),e=k2(t),i=1+T2;return new zr(e.x/i,e.y/i,e.z/i,e.vx/i,e.vy/i,e.vz/i,t)}function Xo(a,t,e){let i=1,n=0;for(let s of a){let r=0;for(let[c,l,h]of s)r+=c*Math.cos(l+t*h);let o=i*r;e&&(o%=js),n+=o,i*=t}return n}function hf(a,t){let e=1,i=0,n=0,s=0;for(let r of a){let o=0,c=0;for(let[l,h,u]of r){let d=h+t*u;o+=l*u*Math.sin(d),s>0&&(c+=l*Math.cos(d))}n+=s*i*c-e*o,i=e,e*=t,++s}return n}const Uc=365250,rp=0,ap=1,op=2;function cp(a){return new Zi(a[0]+44036e-11*a[1]-190919e-12*a[2],-479966e-12*a[0]+.917482137087*a[1]-.397776982902*a[2],.397776982902*a[1]+.917482137087*a[2])}function F2(a,t,e){const i=e*Math.cos(t),n=Math.cos(a),s=Math.sin(a);return[i*n,i*s,e*Math.sin(t)]}function Yo(a,t){const e=t.tt/Uc,i=Xo(a[rp],e,!0),n=Xo(a[ap],e,!1),s=Xo(a[op],e,!1),r=F2(i,n,s);return cp(r).ToAstroVector(t)}function lp(a,t){const e=t/Uc,i=Xo(a[rp],e,!0),n=Xo(a[ap],e,!1),s=Xo(a[op],e,!1),r=hf(a[rp],e),o=hf(a[ap],e),c=hf(a[op],e),l=Math.cos(i),h=Math.sin(i),u=Math.cos(n),d=Math.sin(n),f=+(c*u*l)-s*d*l*o-s*u*h*r,p=+(c*u*h)-s*d*h*o+s*u*l*r,v=+(c*d)+s*u*o,m=F2(i,n,s),g=[f/Uc,p/Uc,v/Uc],b=cp(m),S=cp(g);return new Ga(t,b,S)}function vh(a,t,e,i){const n=i/(i+im),s=Yo(zs[e],t);a.x+=n*s.x,a.y+=n*s.y,a.z+=n*s.z}function zT(a){const t=new ge(0,0,0,a);return vh(t,a,ut.Jupiter,j0),vh(t,a,ut.Saturn,Q0),vh(t,a,ut.Uranus,tp),vh(t,a,ut.Neptune,ep),t}const hp=51,BT=29200,Lo=146,Qs=201,Da=[[-73e4,[-26.118207232108,-14.376168177825,3.384402515299],[.0016339372163656,-.0027861699588508,-.0013585880229445]],[-700800,[41.974905202127,-.448502952929,-12.770351505989],[.00073458569351457,.0022785014891658,.00048619778602049]],[-671600,[14.706930780744,44.269110540027,9.353698474772],[-.00210001479998,.00022295915939915,.00070143443551414]],[-642400,[-29.441003929957,-6.43016153057,6.858481011305],[.00084495803960544,-.0030783914758711,-.0012106305981192]],[-613200,[39.444396946234,-6.557989760571,-13.913760296463],[.0011480029005873,.0022400006880665,.00035168075922288]],[-584e3,[20.2303809507,43.266966657189,7.382966091923],[-.0019754081700585,.00053457141292226,.00075929169129793]],[-554800,[-30.65832536462,2.093818874552,9.880531138071],[61010603013347e-18,-.0031326500935382,-.00099346125151067]],[-525600,[35.737703251673,-12.587706024764,-14.677847247563],[.0015802939375649,.0021347678412429,.00019074436384343]],[-496400,[25.466295188546,41.367478338417,5.216476873382],[-.0018054401046468,.0008328308359951,.00080260156912107]],[-467200,[-29.847174904071,10.636426313081,12.297904180106],[-.00063257063052907,-.0029969577578221,-.00074476074151596]],[-438e3,[30.774692107687,-18.236637015304,-14.945535879896],[.0020113162005465,.0019353827024189,-20937793168297e-19]],[-408800,[30.243153324028,38.656267888503,2.938501750218],[-.0016052508674468,.0011183495337525,.00083333973416824]],[-379600,[-27.288984772533,18.643162147874,14.023633623329],[-.0011856388898191,-.0027170609282181,-.00049015526126399]],[-350400,[24.519605196774,-23.245756064727,-14.626862367368],[.0024322321483154,.0016062008146048,-.00023369181613312]],[-321200,[34.505274805875,35.125338586954,.557361475637],[-.0013824391637782,.0013833397561817,.00084823598806262]],[-292e3,[-23.275363915119,25.818514298769,15.055381588598],[-.0016062295460975,-.0023395961498533,-.00024377362639479]],[-262800,[17.050384798092,-27.180376290126,-13.608963321694],[.0028175521080578,.0011358749093955,-.00049548725258825]],[-233600,[38.093671910285,30.880588383337,-1.843688067413],[-.0011317697153459,.0016128814698472,.00084177586176055]],[-204400,[-18.197852930878,31.932869934309,15.438294826279],[-.0019117272501813,-.0019146495909842,-19657304369835e-18]],[-175200,[8.528924039997,-29.618422200048,-11.805400994258],[.0031034370787005,.0005139363329243,-.00077293066202546]],[-146e3,[40.94685725864,25.904973592021,-4.256336240499],[-.00083652705194051,.0018129497136404,.0008156422827306]],[-116800,[-12.326958895325,36.881883446292,15.217158258711],[-.0021166103705038,-.001481442003599,.00017401209844705]],[-87600,[-.633258375909,-30.018759794709,-9.17193287495],[.0032016994581737,-.00025279858672148,-.0010411088271861]],[-58400,[42.936048423883,20.344685584452,-6.588027007912],[-.00050525450073192,.0019910074335507,.00077440196540269]],[-29200,[-5.975910552974,40.61180995846,14.470131723673],[-.0022184202156107,-.0010562361130164,.00033652250216211]],[0,[-9.875369580774,-27.978926224737,-5.753711824704],[.0030287533248818,-.0011276087003636,-.0012651326732361]],[29200,[43.958831986165,14.214147973292,-8.808306227163],[-.00014717608981871,.0021404187242141,.00071486567806614]],[58400,[.67813676352,43.094461639362,13.243238780721],[-.0022358226110718,-.00063233636090933,.00047664798895648]],[87600,[-18.282602096834,-23.30503958666,-1.766620508028],[.0025567245263557,-.0019902940754171,-.0013943491701082]],[116800,[43.873338744526,7.700705617215,-10.814273666425],[.00023174803055677,.0022402163127924,.00062988756452032]],[146e3,[7.392949027906,44.382678951534,11.629500214854],[-.002193281545383,-.00021751799585364,.00059556516201114]],[175200,[-24.981690229261,-16.204012851426,2.466457544298],[.001819398914958,-.0026765419531201,-.0013848283502247]],[204400,[42.530187039511,.845935508021,-12.554907527683],[.00065059779150669,.0022725657282262,.00051133743202822]],[233600,[13.999526486822,44.462363044894,9.669418486465],[-.0021079296569252,.00017533423831993,.00069128485798076]],[262800,[-29.184024803031,-7.371243995762,6.493275957928],[.00093581363109681,-.0030610357109184,-.0012364201089345]],[292e3,[39.831980671753,-6.078405766765,-13.909815358656],[.0011117769689167,.0022362097830152,.00036230548231153]],[321200,[20.294955108476,43.417190420251,7.450091985932],[-.0019742157451535,.00053102050468554,.00075938408813008]],[350400,[-30.66999230216,2.318743558955,9.973480913858],[45605107450676e-18,-.0031308219926928,-.00099066533301924]],[379600,[35.626122155983,-12.897647509224,-14.777586508444],[.0016015684949743,.0021171931182284,.00018002516202204]],[408800,[26.133186148561,41.232139187599,5.00640132622],[-.0017857704419579,.00086046232702817,.00080614690298954]],[438e3,[-29.57674022923,11.863535943587,12.631323039872],[-.00072292830060955,-.0029587820140709,-.000708242964503]],[467200,[29.910805787391,-19.159019294,-15.013363865194],[.0020871080437997,.0018848372554514,-38528655083926e-18]],[496400,[31.375957451819,38.050372720763,2.433138343754],[-.0015546055556611,.0011699815465629,.00083565439266001]],[525600,[-26.360071336928,20.662505904952,14.414696258958],[-.0013142373118349,-.0026236647854842,-.00042542017598193]],[554800,[22.599441488648,-24.508879898306,-14.484045731468],[.0025454108304806,.0014917058755191,-.00030243665086079]],[584e3,[35.877864013014,33.894226366071,-.224524636277],[-.0012941245730845,.0014560427668319,.00084762160640137]],[613200,[-21.538149762417,28.204068269761,15.321973799534],[-.001731211740901,-.0021939631314577,-.0001631691327518]],[642400,[13.971521374415,-28.339941764789,-13.083792871886],[.0029334630526035,.00091860931752944,-.00059939422488627]],[671600,[39.526942044143,28.93989736011,-2.872799527539],[-.0010068481658095,.001702113288809,.00083578230511981]],[700800,[-15.576200701394,34.399412961275,15.466033737854],[-.0020098814612884,-.0017191109825989,70414782780416e-18]],[73e4,[4.24325283709,-30.118201690825,-10.707441231349],[.0031725847067411,.0001609846120227,-.00090672150593868]]];class Zi{constructor(t,e,i){this.x=t,this.y=e,this.z=i}clone(){return new Zi(this.x,this.y,this.z)}ToAstroVector(t){return new ge(this.x,this.y,this.z,t)}static zero(){return new Zi(0,0,0)}quadrature(){return this.x*this.x+this.y*this.y+this.z*this.z}add(t){return new Zi(this.x+t.x,this.y+t.y,this.z+t.z)}sub(t){return new Zi(this.x-t.x,this.y-t.y,this.z-t.z)}incr(t){this.x+=t.x,this.y+=t.y,this.z+=t.z}decr(t){this.x-=t.x,this.y-=t.y,this.z-=t.z}mul(t){return new Zi(t*this.x,t*this.y,t*this.z)}div(t){return new Zi(this.x/t,this.y/t,this.z/t)}mean(t){return new Zi((this.x+t.x)/2,(this.y+t.y)/2,(this.z+t.z)/2)}neg(){return new Zi(-this.x,-this.y,-this.z)}}class Ga{constructor(t,e,i){this.tt=t,this.r=e,this.v=i}clone(){return new Ga(this.tt,this.r,this.v)}sub(t){return new Ga(this.tt,this.r.sub(t.r),this.v.sub(t.v))}}function HT(a){let[t,[e,i,n],[s,r,o]]=a;return new Ga(t,new Zi(e,i,n),new Zi(s,r,o))}function Mh(a,t,e,i){const n=i/(i+im),s=lp(zs[e],t);return a.r.incr(s.r.mul(n)),a.v.incr(s.v.mul(n)),s}function Ac(a,t,e){const i=e.sub(a),n=i.quadrature();return i.mul(t/(n*Math.sqrt(n)))}class ud{constructor(t){let e=new Ga(t,new Zi(0,0,0),new Zi(0,0,0));this.Jupiter=Mh(e,t,ut.Jupiter,j0),this.Saturn=Mh(e,t,ut.Saturn,Q0),this.Uranus=Mh(e,t,ut.Uranus,tp),this.Neptune=Mh(e,t,ut.Neptune,ep),this.Jupiter.r.decr(e.r),this.Jupiter.v.decr(e.v),this.Saturn.r.decr(e.r),this.Saturn.v.decr(e.v),this.Uranus.r.decr(e.r),this.Uranus.v.decr(e.v),this.Neptune.r.decr(e.r),this.Neptune.v.decr(e.v),this.Sun=new Ga(t,e.r.mul(-1),e.v.mul(-1))}Acceleration(t){let e=Ac(t,im,this.Sun.r);return e.incr(Ac(t,j0,this.Jupiter.r)),e.incr(Ac(t,Q0,this.Saturn.r)),e.incr(Ac(t,tp,this.Uranus.r)),e.incr(Ac(t,ep,this.Neptune.r)),e}}class dd{constructor(t,e,i,n){this.tt=t,this.r=e,this.v=i,this.a=n}clone(){return new dd(this.tt,this.r.clone(),this.v.clone(),this.a.clone())}}class U2{constructor(t,e){this.bary=t,this.grav=e}}function zu(a,t,e,i){return new Zi(t.x+a*(e.x+a*i.x/2),t.y+a*(e.y+a*i.y/2),t.z+a*(e.z+a*i.z/2))}function q1(a,t,e){return new Zi(t.x+a*e.x,t.y+a*e.y,t.z+a*e.z)}function up(a,t){const e=a-t.tt,i=new ud(a),n=zu(e,t.r,t.v,t.a),s=i.Acceleration(n).mean(t.a),r=zu(e,t.r,t.v,s),o=t.v.add(s.mul(e)),c=i.Acceleration(r),l=new dd(a,r,o,c);return new U2(i,l)}const GT=[];function z2(a,t){const e=Math.floor(a);return e<0?0:e>=t?t-1:e}function dp(a){const t=HT(a),e=new ud(t.tt),i=t.r.add(e.Sun.r),n=t.v.add(e.Sun.v),s=e.Acceleration(i),r=new dd(t.tt,i,n,s);return new U2(e,r)}function VT(a,t){const e=Da[0][0];if(t<e||t>Da[hp-1][0])return null;const i=z2((t-e)/BT,hp-1);if(!a[i]){const s=a[i]=[];s[0]=dp(Da[i]).grav,s[Qs-1]=dp(Da[i+1]).grav;let r,o=s[0].tt;for(r=1;r<Qs-1;++r)s[r]=up(o+=Lo,s[r-1]).grav;o=s[Qs-1].tt;var n=[];for(n[Qs-1]=s[Qs-1],r=Qs-2;r>0;--r)n[r]=up(o-=Lo,n[r+1]).grav;for(r=Qs-2;r>0;--r){const c=r/(Qs-1);s[r].r=s[r].r.mul(1-c).add(n[r].r.mul(c)),s[r].v=s[r].v.mul(1-c).add(n[r].v.mul(c)),s[r].a=s[r].a.mul(1-c).add(n[r].a.mul(c))}}return a[i]}function $1(a,t,e){let i=dp(a);const n=Math.ceil((t-i.grav.tt)/e);for(let s=0;s<n;++s)i=up(s+1===n?t:i.grav.tt+e,i.grav);return i}function B2(a,t){let e,i,n;const s=VT(GT,a.tt);if(s){const r=z2((a.tt-s[0].tt)/Lo,Qs-1),o=s[r],c=s[r+1],l=o.a.mean(c.a),h=zu(a.tt-o.tt,o.r,o.v,l),u=q1(a.tt-o.tt,o.v,l),d=zu(a.tt-c.tt,c.r,c.v,l),f=q1(a.tt-c.tt,c.v,l),p=(a.tt-o.tt)/Lo;e=h.mul(1-p).add(d.mul(p)),i=u.mul(1-p).add(f.mul(p))}else{let r;a.tt<Da[0][0]?r=$1(Da[0],a.tt,-Lo):r=$1(Da[hp-1],a.tt,+Lo),e=r.grav.r,i=r.grav.v,n=r.bary}return n||(n=new ud(a.tt)),e=e.sub(n.Sun.r),i=i.sub(n.Sun.v),new zr(e.x,e.y,e.z,i.x,i.y,i.z,a)}function Wr(a,t){var e=Ne(t);if(a in zs)return Yo(zs[a],e);if(a===ut.Pluto){const r=B2(e);return new ge(r.x,r.y,r.z,e)}if(a===ut.Sun)return new ge(0,0,0,e);if(a===ut.Moon){var i=Yo(zs.Earth,e),n=ur(e);return new ge(i.x+n.x,i.y+n.y,i.z+n.z,e)}if(a===ut.EMB){const r=Yo(zs.Earth,e),o=ur(e),c=1+T2;return new ge(r.x+o.x/c,r.y+o.y/c,r.z+o.z/c,e)}if(a===ut.SSB)return zT(e);const s=nm(a);if(s){const r=new ld(s.dec,15*s.ra,s.dist);return hm(r,e)}throw`HelioVector: Unknown body "${a}"`}function WT(a,t){let e=t,i=0;for(let n=0;n<10;++n){const s=a(e),r=s.Length()/em;if(r>1)throw"Object is too distant for light-travel solver.";const o=t.AddDays(-r);if(i=Math.abs(o.tt-e.tt),i<1e-9)return s;e=o}throw`Light-travel time solver did not converge: dt = ${i}`}class XT{constructor(t,e,i,n){this.observerBody=t,this.targetBody=e,this.aberration=i,this.observerPos=n}Position(t){this.aberration&&(this.observerPos=Wr(this.observerBody,t));const e=Wr(this.targetBody,t);return new ge(e.x-this.observerPos.x,e.y-this.observerPos.y,e.z-this.observerPos.z,t)}}function YT(a,t,e,i){Fu(i);const n=Ne(a);if(nm(e)){const o=Wr(e,n);if(i){const l=$T(t,n),h=new ge(o.x-l.x,o.y-l.y,o.z-l.z,n),u=em/h.Length();return new ge(h.x+l.vx/u,h.y+l.vy/u,h.z+l.vz/u,n)}const c=Wr(t,n);return new ge(o.x-c.x,o.y-c.y,o.z-c.z,n)}let s;i?s=new ge(0,0,0,n):s=Wr(t,n);const r=new XT(t,e,i,s);return WT(o=>r.Position(o),n)}function Bu(a,t,e){Fu(e);const i=Ne(t);switch(a){case ut.Earth:return new ge(0,0,0,i);case ut.Moon:return ur(i);default:const n=YT(i,ut.Earth,a,e);return n.t=i,n}}function qT(a,t){return new zr(a.r.x,a.r.y,a.r.z,a.v.x,a.v.y,a.v.z,t)}function $T(a,t){const e=Ne(t);switch(a){case ut.Sun:return new zr(0,0,0,0,0,0,e);case ut.SSB:const i=new ud(e.tt);return new zr(-i.Sun.r.x,-i.Sun.r.y,-i.Sun.r.z,-i.Sun.v.x,-i.Sun.v.y,-i.Sun.v.z,e);case ut.Mercury:case ut.Venus:case ut.Earth:case ut.Mars:case ut.Jupiter:case ut.Saturn:case ut.Uranus:case ut.Neptune:const n=lp(zs[a],e.tt);return qT(n,e);case ut.Pluto:return B2(e);case ut.Moon:case ut.EMB:const s=lp(zs.Earth,e.tt),r=a==ut.Moon?k2(e):UT(e);return new zr(r.x+s.r.x,r.y+s.r.y,r.z+s.r.z,r.vx+s.v.x,r.vy+s.v.y,r.vz+s.v.z,e);default:if(nm(a)){const o=Wr(a,e);return new zr(o.x,o.y,o.z,0,0,0,e)}throw`HelioState: Unsupported body "${a}"`}}function KT(a,t,e,i,n){let s=(n+e)/2-i,r=(n-e)/2,o=i,c;if(s==0){if(r==0||(c=-o/r,c<-1||c>1))return null}else{let u=r*r-4*s*o;if(u<=0)return null;let d=Math.sqrt(u),f=(-r+d)/(2*s),p=(-r-d)/(2*s);if(-1<=f&&f<=1){if(-1<=p&&p<=1)return null;c=f}else if(-1<=p&&p<=1)c=p;else return null}let l=a+c*t,h=(2*s*c+r)/t;return{t:l,df_dt:h}}function om(a,t,e,i){const n=Si(i&&i.dt_tolerance_seconds||1),s=Math.abs(n/gT);let r=i&&i.init_f1||a(t),o=i&&i.init_f2||a(e),c=NaN,l=0,h=i&&i.iter_limit||20,u=!0;for(;;){if(++l>h)throw"Excessive iteration in Search()";let d=RT(t,e,.5),f=d.ut-t.ut;if(Math.abs(f)<s)return d;u?c=a(d):u=!0;let p=KT(d.ut,e.ut-d.ut,r,c,o);if(p){let v=Ne(p.t),m=a(v);if(p.df_dt!==0){if(Math.abs(m/p.df_dt)<s)return v;let g=1.2*Math.abs(m/p.df_dt);if(g<f/10){let b=v.AddDays(-g),S=v.AddDays(+g);if((b.ut-t.ut)*(b.ut-e.ut)<0&&(S.ut-t.ut)*(S.ut-e.ut)<0){let M=a(b),x=a(S);if(M<0&&x>=0){r=M,o=x,t=b,e=S,c=m,u=!1;continue}}}}}if(r<0&&c>=0){e=d,o=c;continue}if(c<0&&o>=0){t=d,r=c;continue}return null}}function ZT(a){let t=a;for(;t<=-180;)t+=360;for(;t>180;)t-=360;return t}function JT(a){for(;a<0;)a+=360;for(;a>=360;)a-=360;return a}function jT(a,t,e){if(a===ut.Earth||t===ut.Earth)throw"The Earth does not have a longitude as seen from itself.";const i=Ne(e),n=Bu(a,i,!1),s=sp(n),r=Bu(t,i,!1),o=sp(r);return JT(s.elon-o.elon)}function QT(a,t,e,i){let n,s=0,r=0,o=0;switch(a){case ut.Mercury:n=-.6,s=4.98,r=-4.88,o=3.02;break;case ut.Venus:t<163.6?(n=-4.47,s=1.03,r=.57,o=.13):(n=.98,s=-1.02);break;case ut.Mars:n=-1.52,s=1.6;break;case ut.Jupiter:n=-9.4,s=.5;break;case ut.Uranus:n=-7.19,s=.25;break;case ut.Neptune:n=-6.87;break;case ut.Pluto:n=-1,s=4;break;default:throw`VisualMagnitude: unsupported body ${a}`}const c=t/100;let l=n+c*(s+c*(r+c*o));return l+=5*Math.log10(e*i),l}function t4(a,t,e,i,n){const s=sp(i),r=mt*28.06,o=mt*(169.51+382e-7*n.tt),c=mt*s.elat,l=mt*s.elon,h=Math.asin(Math.sin(c)*Math.cos(r)-Math.cos(c)*Math.sin(r)*Math.sin(l-o)),u=Math.sin(Math.abs(h));let d=-9+.044*a;return d+=u*(-2.6+1.2*u),d+=5*Math.log10(t*e),{mag:d,ring_tilt:fs*h}}function e4(a,t,e){let i=a*mt,n=i*i,s=n*n,r=-12.717+1.49*Math.abs(i)+.0431*s;const o=385000.6/Ls;let c=e/o;return r+=5*Math.log10(t*c),r}class i4{constructor(t,e,i,n,s,r,o,c){this.time=t,this.mag=e,this.phase_angle=i,this.helio_dist=n,this.geo_dist=s,this.gc=r,this.hc=o,this.ring_tilt=c,this.phase_fraction=(1+Math.cos(mt*i))/2}}function H2(a,t){if(a===ut.Earth)throw"The illumination of the Earth is not defined.";const e=Ne(t),i=Yo(zs.Earth,e);let n,s,r,o;a===ut.Sun?(r=new ge(-i.x,-i.y,-i.z,e),s=new ge(0,0,0,e),n=0):(a===ut.Moon?(r=ur(e),s=new ge(i.x+r.x,i.y+r.y,i.z+r.z,e)):(s=Wr(a,t),r=new ge(s.x-i.x,s.y-i.y,s.z-i.z,e)),n=R2(r,s));let c=r.Length(),l=s.Length(),h;if(a===ut.Sun)o=pT+5*Math.log10(c);else if(a===ut.Moon)o=e4(n,l,c);else if(a===ut.Saturn){const u=t4(n,l,c,r,e);o=u.mag,h=u.ring_tilt}else o=QT(a,n,l,c);return new i4(e,o,n,l,c,r,s,h)}function G2(a){return jT(ut.Moon,ut.Sun,a)}function n4(a,t,e){function i(d){let f=G2(d);return ZT(f-a)}Si(a),Si(e);const n=1.5,s=Ne(t);let r=i(s),o,c,l;{if(r>0&&(r-=360),o=-(mT*r)/360,c=o-n,c>e)return null;l=Math.min(e,o+n)}const h=s.AddDays(c),u=s.AddDays(l);return om(i,h,u,{dt_tolerance_seconds:.1})}var K1;(function(a){a[a.Pericenter=0]="Pericenter",a[a.Apocenter=1]="Apocenter"})(K1||(K1={}));function cm(a){return new Ws([[a.rot[0][0],a.rot[1][0],a.rot[2][0]],[a.rot[0][1],a.rot[1][1],a.rot[2][1]],[a.rot[0][2],a.rot[1][2],a.rot[2][2]]])}function lm(a,t){return new Ws([[t.rot[0][0]*a.rot[0][0]+t.rot[1][0]*a.rot[0][1]+t.rot[2][0]*a.rot[0][2],t.rot[0][1]*a.rot[0][0]+t.rot[1][1]*a.rot[0][1]+t.rot[2][1]*a.rot[0][2],t.rot[0][2]*a.rot[0][0]+t.rot[1][2]*a.rot[0][1]+t.rot[2][2]*a.rot[0][2]],[t.rot[0][0]*a.rot[1][0]+t.rot[1][0]*a.rot[1][1]+t.rot[2][0]*a.rot[1][2],t.rot[0][1]*a.rot[1][0]+t.rot[1][1]*a.rot[1][1]+t.rot[2][1]*a.rot[1][2],t.rot[0][2]*a.rot[1][0]+t.rot[1][2]*a.rot[1][1]+t.rot[2][2]*a.rot[1][2]],[t.rot[0][0]*a.rot[2][0]+t.rot[1][0]*a.rot[2][1]+t.rot[2][0]*a.rot[2][2],t.rot[0][1]*a.rot[2][0]+t.rot[1][1]*a.rot[2][1]+t.rot[2][1]*a.rot[2][2],t.rot[0][2]*a.rot[2][0]+t.rot[1][2]*a.rot[2][1]+t.rot[2][2]*a.rot[2][2]]])}function hm(a,t){t=Ne(t);const e=a.lat*mt,i=a.lon*mt,n=a.dist*Math.cos(e);return new ge(n*Math.cos(i),n*Math.sin(i),a.dist*Math.sin(e),t)}function fd(a){const t=s4(a);return new ip(t.lon/15,t.lat,t.dist,a)}function s4(a){const t=a.x*a.x+a.y*a.y,e=Math.sqrt(t+a.z*a.z);let i,n;if(t===0){if(a.z===0)throw"Zero-length vector not allowed.";n=0,i=a.z<0?-90:90}else n=fs*Math.atan2(a.y,a.x),n<0&&(n+=360),i=fs*Math.atan2(a.z,Math.sqrt(t));return new ld(i,n,e)}function V2(a,t){let e;if(Si(t),t<-90||t>90)return 0;if(a==="normal"||a==="jplhor"){let i=t;i<-1&&(i=-1),e=1.02/Math.tan((i+10.3/(i+5.11))*mt)/60,a==="normal"&&t<-1&&(e*=(t+90)/89)}else if(!a)e=0;else throw`Invalid refraction option: ${a}`;return e}function cr(a,t){return new ge(a.rot[0][0]*t.x+a.rot[1][0]*t.y+a.rot[2][0]*t.z,a.rot[0][1]*t.x+a.rot[1][1]*t.y+a.rot[2][1]*t.z,a.rot[0][2]*t.x+a.rot[1][2]*t.y+a.rot[2][2]*t.z,t.t)}function r4(){return new Ws([[1,0,0],[0,.9174821430670688,-.3977769691083922],[0,.3977769691083922,.9174821430670688]])}function a4(){return new Ws([[1,0,0],[0,.9174821430670688,.3977769691083922],[0,-.3977769691083922,.9174821430670688]])}function W2(a){a=Ne(a);const t=sm(a,Ri.From2000),e=rm(a,Ri.From2000);return lm(t,e)}function X2(a){a=Ne(a);const t=rm(a,Ri.Into2000),e=sm(a,Ri.Into2000);return lm(t,e)}function o4(a,t){a=Ne(a);const e=Math.sin(t.latitude*mt),i=Math.cos(t.latitude*mt),n=Math.sin(t.longitude*mt),s=Math.cos(t.longitude*mt),r=[i*s,i*n,e],o=[-e*s,-e*n,i],c=[n,-s,0],l=-15*El(a),h=Wo(l,r),u=Wo(l,o),d=Wo(l,c);return new Ws([[u[0],d[0],h[0]],[u[1],d[1],h[1]],[u[2],d[2],h[2]]])}function c4(a,t){const e=o4(a,t);return cm(e)}function l4(a,t){a=Ne(a);const e=c4(a,t),i=X2(a);return lm(e,i)}function h4(a,t){const e=l4(a,t);return cm(e)}function u4(a){const e=_l(Ne(a)).tobl*mt,i=Math.cos(e),n=Math.sin(e);return new Ws([[1,0,0],[0,+i,+n],[0,-n,+i]])}var Va;(function(a){a.Penumbral="penumbral",a.Partial="partial",a.Annular="annular",a.Total="total"})(Va||(Va={}));class d4{constructor(t,e,i,n,s,r,o){this.time=t,this.u=e,this.r=i,this.k=n,this.p=s,this.target=r,this.dir=o}}function f4(a,t,e,i){const n=(i.x*e.x+i.y*e.y+i.z*e.z)/(i.x*i.x+i.y*i.y+i.z*i.z),s=n*i.x-e.x,r=n*i.y-e.y,o=n*i.z-e.z,c=Ls*Math.hypot(s,r,o),l=+Fc-(1+n)*(Fc-a),h=-Fc+(1+n)*(Fc+a);return new d4(t,n,c,l,h,e,i)}function fp(a,t){const e=O2(a,t),i=Bu(ut.Sun,a,!0),n=ur(a),s=new ge(e[0]-n.x,e[1]-n.y,e[2]-n.z,a);return n.x-=i.x,n.y-=i.y,n.z-=i.z,f4(xT,a,s,n)}function p4(a,t){const e=11574074074074073e-21,i=t.AddDays(-e),n=t.AddDays(+e),s=a(i);return(a(n).r-s.r)/e}function m4(a,t){const e=a.AddDays(-.2),i=a.AddDays(.2);function n(r){return fp(r,t)}const s=om(r=>p4(n,r),e,i);if(!s)throw`PeakLocalMoonShadow: search failure for search_center_time = ${a}`;return fp(s,t)}function g4(a){const t=I2(a);return fs*t.geo_eclip_lat}function v4(a,t,e){if(a<=0)throw"Radius of first disc must be positive.";if(t<=0)throw"Radius of second disc must be positive.";if(e<0)throw"Distance between discs is not allowed to be negative.";if(e>=a+t)return 0;if(e==0)return a<=t?1:t*t/(a*a);const i=(a*a-t*t+e*e)/(2*e),n=a*a-i*i;if(n<=0)return a<=t?1:t*t/(a*a);const s=Math.sqrt(n),r=a*a*Math.acos(i/a)-i*s,o=t*t*Math.acos((e-i)/t)-(e-i)*s;return(r+o)/(Math.PI*a*a)}function M4(a,t){const e=new ge(a.x+t.x,a.y+t.y,a.z+t.z,a.t),i=Math.asin(vT/e.Length()),n=Math.asin(ST/t.Length()),s=R2(t,e),r=v4(i,n,s*mt);return Math.min(.9999,r)}function y4(a){return a>.014?Va.Total:Va.Annular}class x4{constructor(t,e){this.time=t,this.altitude=e}}class b4{constructor(t,e,i,n,s,r,o){this.kind=t,this.obscuration=e,this.partial_begin=i,this.total_begin=n,this.peak=s,this.total_end=r,this.partial_end=o}}function Z1(a){return a.p-a.r}function J1(a){return Math.abs(a.k)-a.r}function S4(a,t){const e=Y2(t,a.time);let i=a.time.AddDays(-.2),n=a.time.AddDays(.2);const s=yh(t,1,Z1,i,a.time),r=yh(t,-1,Z1,a.time,n);let o,c,l;a.r<Math.abs(a.k)?(i=a.time.AddDays(-.01),n=a.time.AddDays(.01),o=yh(t,1,J1,i,a.time),c=yh(t,-1,J1,a.time,n),l=y4(a.k)):l=Va.Partial;const h=l===Va.Total?1:M4(a.dir,a.target);return new b4(l,h,s,o,e,c,r)}function yh(a,t,e,i,n){function s(o){const c=fp(o,a);return t*e(c)}const r=om(s,i,n);if(!r)throw"Local eclipse transition search failed.";return Y2(a,r)}function Y2(a,t){const e=w4(t,a);return new x4(t,e)}function w4(a,t){const e=ml(ut.Sun,a,t,!0,!0);return am(a,t,e.ra,e.dec,"normal").altitude}function _4(a,t){a=Ne(a),hd(t);const e=1.8;let i=a;for(;;){const n=n4(0,i,40);if(!n)throw"Cannot find next new moon";const s=g4(n);if(Math.abs(s)<e){const r=m4(n,t);if(r.r<r.p){const o=S4(r,t);if(o.partial_begin.altitude>0||o.partial_end.altitude>0)return o}}i=n.AddDays(10)}}var j1;(function(a){a[a.Invalid=0]="Invalid",a[a.Ascending=1]="Ascending",a[a.Descending=-1]="Descending"})(j1||(j1={}));class q2{constructor(t,e,i,n){this.ra=t,this.dec=e,this.spin=i,this.north=n}}function E4(a){const t=Uu([0,0,1],a,Ri.Into2000),e=pl(t,a,Ri.Into2000),i=new ge(e[0],e[1],e[2],a),n=fd(i),s=190.41375788700253+360.9856122880876*a.ut;return new q2(n.ra,n.dec,s,i)}function A4(a,t){const e=Ne(t),i=e.tt,n=i/36525;let s,r,o;switch(a){case ut.Sun:s=286.13,r=63.87,o=84.176+14.1844*i;break;case ut.Mercury:s=281.0103-.0328*n,r=61.4155-.0049*n,o=329.5988+6.1385108*i+.01067257*Math.sin(mt*(174.7910857+4.092335*i))-.00112309*Math.sin(mt*(349.5821714+8.18467*i))-1104e-7*Math.sin(mt*(164.3732571+12.277005*i))-2539e-8*Math.sin(mt*(339.1643429+16.36934*i))-571e-8*Math.sin(mt*(153.9554286+20.461675*i));break;case ut.Venus:s=272.76,r=67.16,o=160.2-1.4813688*i;break;case ut.Earth:return E4(e);case ut.Moon:const d=mt*(125.045-.0529921*i),f=mt*(250.089-.1059842*i),p=mt*(260.008+13.0120009*i),v=mt*(176.625+13.3407154*i),m=mt*(357.529+.9856003*i),g=mt*(311.589+26.4057084*i),b=mt*(134.963+13.064993*i),S=mt*(276.617+.3287146*i),M=mt*(34.226+1.7484877*i),x=mt*(15.134-.1589763*i),_=mt*(119.743+.0036096*i),E=mt*(239.961+.1643573*i),y=mt*(25.053+12.9590088*i);s=269.9949+.0031*n-3.8787*Math.sin(d)-.1204*Math.sin(f)+.07*Math.sin(p)-.0172*Math.sin(v)+.0072*Math.sin(g)-.0052*Math.sin(x)+.0043*Math.sin(y),r=66.5392+.013*n+1.5419*Math.cos(d)+.0239*Math.cos(f)-.0278*Math.cos(p)+.0068*Math.cos(v)-.0029*Math.cos(g)+9e-4*Math.cos(b)+8e-4*Math.cos(x)-9e-4*Math.cos(y),o=38.3213+(13.17635815-14e-13*i)*i+3.561*Math.sin(d)+.1208*Math.sin(f)-.0642*Math.sin(p)+.0158*Math.sin(v)+.0252*Math.sin(m)-.0066*Math.sin(g)-.0047*Math.sin(b)-.0046*Math.sin(S)+.0028*Math.sin(M)+.0052*Math.sin(x)+.004*Math.sin(_)+.0019*Math.sin(E)-.0044*Math.sin(y);break;case ut.Mars:s=317.269202-.10927547*n+68e-6*Math.sin(mt*(198.991226+19139.4819985*n))+238e-6*Math.sin(mt*(226.292679+38280.8511281*n))+52e-6*Math.sin(mt*(249.663391+57420.7251593*n))+9e-6*Math.sin(mt*(266.18351+76560.636795*n))+.419057*Math.sin(mt*(79.398797+.5042615*n)),r=54.432516-.05827105*n+51e-6*Math.cos(mt*(122.433576+19139.9407476*n))+141e-6*Math.cos(mt*(43.058401+38280.8753272*n))+31e-6*Math.cos(mt*(57.663379+57420.7517205*n))+5e-6*Math.cos(mt*(79.476401+76560.6495004*n))+1.591274*Math.cos(mt*(166.325722+.5042615*n)),o=176.049863+350.891982443297*i+145e-6*Math.sin(mt*(129.071773+19140.0328244*n))+157e-6*Math.sin(mt*(36.352167+38281.0473591*n))+4e-5*Math.sin(mt*(56.668646+57420.929536*n))+1e-6*Math.sin(mt*(67.364003+76560.2552215*n))+1e-6*Math.sin(mt*(104.79268+95700.4387578*n))+.584542*Math.sin(mt*(95.391654+.5042615*n));break;case ut.Jupiter:const T=mt*(99.360714+4850.4046*n),I=mt*(175.895369+1191.9605*n),C=mt*(300.323162+262.5475*n),P=mt*(114.012305+6070.2476*n),B=mt*(49.511251+64.3*n);s=268.056595-.006499*n+117e-6*Math.sin(T)+938e-6*Math.sin(I)+.001432*Math.sin(C)+3e-5*Math.sin(P)+.00215*Math.sin(B),r=64.495303+.002413*n+5e-5*Math.cos(T)+404e-6*Math.cos(I)+617e-6*Math.cos(C)-13e-6*Math.cos(P)+926e-6*Math.cos(B),o=284.95+870.536*i;break;case ut.Saturn:s=40.589-.036*n,r=83.537-.004*n,o=38.9+810.7939024*i;break;case ut.Uranus:s=257.311,r=-15.175,o=203.81-501.1600928*i;break;case ut.Neptune:const W=mt*(357.85+52.316*n);s=299.36+.7*Math.sin(W),r=43.46-.51*Math.cos(W),o=249.978+541.1397757*i-.48*Math.sin(W);break;case ut.Pluto:s=132.993,r=-6.163,o=302.695+56.3625225*i;break;default:throw`Invalid body: ${a}`}const c=r*mt,l=s*mt,h=Math.cos(c),u=new ge(h*Math.cos(l),h*Math.sin(l),Math.sin(c),e);return new q2(s/15,r,o,u)}const T4=["Venus","Mars","Jupiter","Saturn"];function $2(a){return new qr(a.lat,a.lng,a.elevationM)}function um(a,t,e,i,n=!0){const s=am(e,$2(i),a,t,n?"normal":void 0);return{altitudeDeg:s.altitude,azimuthDeg:s.azimuth}}class os{up;north;west;constructor(t,e){const i=Ne(t),n=Math.sin(e.lat*tr),s=Math.cos(e.lat*tr),r=Math.sin(e.lng*tr),o=Math.cos(e.lng*tr),c=-15*OT(i),l=X2(i);this.up=os.rotate(l,os.spin(c,[s*o,s*r,n]),i),this.north=os.rotate(l,os.spin(c,[-n*o,-n*r,s]),i),this.west=os.rotate(l,os.spin(c,[r,-o,0]),i)}static ofJ2000(t,e,i,n,s=!0){const r=Ne(i),o=hm(new ld(e,t*15,1),r),c=fd(cr(W2(r),o));return um(c.ra,c.dec,i,n,s)}position(t,e){const i=Math.sin(e*tr),n=Math.cos(e*tr),s=Math.sin(t*tv),r=Math.cos(t*tv),o=n*r,c=n*s,l=i,h=o*this.up[0]+c*this.up[1]+l*this.up[2],u=o*this.north[0]+c*this.north[1]+l*this.north[2],d=o*this.west[0]+c*this.west[1]+l*this.west[2],f=Math.hypot(u,d);let p=0;f>0&&(p=-Q1*Math.atan2(d,u),p<0&&(p+=360));let v=Q1*Math.atan2(f,h);return v-=V2("normal",90-v),{altitudeDeg:90-v,azimuthDeg:p}}static spin(t,[e,i,n]){const s=Math.cos(t*tr),r=Math.sin(t*tr);return[s*e+r*i,s*i-r*e,n]}static rotate(t,[e,i,n],s){const r=cr(t,new ge(e,i,n,s));return[r.x,r.y,r.z]}}const tr=Math.PI/180,Q1=180/Math.PI,tv=15*tr;function xh(a,t,e){const i=$2(e),n=ml(ut[a],t,i,!0,!0),s=am(t,i,n.ra,n.dec,"normal");return{altitudeDeg:s.altitude,azimuthDeg:s.azimuth}}function uf(a,t){return H2(ut[a],t).mag}function R4(a){const t=G2(a),e=H2(ut.Moon,a);return{phaseFraction:t/360,illuminatedFraction:e.phase_fraction}}const D4=2e3,I4=3,C4=20;function ra(a,t,e){if(a.year===void 0&&a.month===void 0&&a.day===void 0&&a.hour===void 0)return;const i=a.year!==void 0,n=a.year??D4,s=a.month??(i?1:I4),r=a.day??(i?1:C4),o=e??Math.round(t/15);return new Date(Date.UTC(n,s-1,r,(a.hour??12)-o,a.minute??0,a.second??0))}const ev=["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"];class Na{static POINT_DEG=360/16;static point(t,e=ev){const i=(t%360+360)%360,n=Math.round(i/Na.POINT_DEG)%16;return e[n]}static POINTS=ev;static towards(t,e){return e?e.towards(Na.point(t,e.compassPoints)):`to the ${Na.point(t)}`}}class Es{static ANCHOR="vec4 diffuseColor = vec4( diffuse, opacity );";static CORE=.18;static RIM=.5;static FALLOFF={core:Es.CORE,rim:Es.RIM};static apply(t){t.transparent=!0,t.depthWrite=!1,t.onBeforeCompile=e=>{e.fragmentShader=Es.patch(e.fragmentShader)}}static patch(t){return t.replace(Es.ANCHOR,`float distanceFromCentre = length( gl_PointCoord - vec2( 0.5 ) );
7018
7018
  // Outside the inscribed circle there is no star at all — this is what kills the corners.
7019
7019
  if ( distanceFromCentre > ${Es.RIM.toFixed(2)} ) discard;
7020
7020
  float glare = 1.0 - smoothstep( ${Es.CORE.toFixed(2)}, ${Es.RIM.toFixed(2)}, distanceFromCentre );
7021
- vec4 diffuseColor = vec4( diffuse, opacity * glare );`)}}class Ct{static COVERAGE=Ct.integrateCoverage();static CONE_SOLID_ANGLE=Ct.acuitySolidAngle(0);static CONE_THRESHOLD_LUX=10**((-14.18-4)/2.5);static shared={uRodSolidAngle:{value:1e-7},uConeThreshold:{value:0},uViewportHeight:{value:1},uScintillationTime:{value:0}};static setTime(t){Ct.shared.uScintillationTime.value=t}static viewport=new ue;static track(t){t.userData.pointSource=!0,t.onBeforeRender=e=>{Ct.shared.uViewportHeight.value=Math.max(1,e.getCurrentViewport(Ct.viewport).w)}}static setEye(t,e){Ct.shared.uRodSolidAngle.value=Ct.acuitySolidAngle(t),Ct.shared.uConeThreshold.value=Ct.CONE_THRESHOLD_LUX*e}static material(t,e=!0){const i=new F0({vertexColors:!0,size:t,sizeAttenuation:!1,fog:!1});return i.transparent=!0,i.depthWrite=!1,i.blending=Pi,i.onBeforeCompile=n=>{n.uniforms.uRodSolidAngle=Ct.shared.uRodSolidAngle,n.uniforms.uConeThreshold=Ct.shared.uConeThreshold,n.uniforms.uViewportHeight=Ct.shared.uViewportHeight,n.uniforms.uScintillationTime=Ct.shared.uScintillationTime,n.vertexShader=Ct.patch(n.vertexShader,e),n.fragmentShader=Ct.patchFragment(n.fragmentShader)},i.customProgramCacheKey=()=>e?"point-sources":"point-sources-steady",i}static output={uOutputHalfFovRad:{value:.5236},uOutputAspect:{value:1},uOutputPixelAngle:{value:.003},uSrcTanHalfFovY:{value:1},uOcclusion:{value:null}};static twins=new WeakMap;static outputMaterial(t){let e=Ct.twins.get(t);if(e)return e;const i=t.customProgramCacheKey()==="point-sources";return e=new F0({vertexColors:!0,size:t.size,sizeAttenuation:!1,fog:!1}),e.transparent=!0,e.depthWrite=!1,e.depthTest=!1,e.blending=Pi,e.onBeforeCompile=n=>{n.uniforms.uRodSolidAngle=Ct.shared.uRodSolidAngle,n.uniforms.uConeThreshold=Ct.shared.uConeThreshold,n.uniforms.uViewportHeight=Ct.shared.uViewportHeight,n.uniforms.uScintillationTime=Ct.shared.uScintillationTime,Object.assign(n.uniforms,Ct.output),n.vertexShader=Ct.patchOutput(n.vertexShader,i),n.fragmentShader=Ct.patchFragment(n.fragmentShader)},e.customProgramCacheKey=()=>i?"point-sources-output":"point-sources-output-steady",Ct.twins.set(t,e),e}static PROJECT_ANCHOR="#include <project_vertex>";static patchOutput(t,e=!0){return Ct.patch(t,e).replace("uniform float uRodSolidAngle;",`${Ct.OUTPUT_UNIFORMS_GLSL}
7021
+ vec4 diffuseColor = vec4( diffuse, opacity * glare );`)}}class Ct{static COVERAGE=Ct.integrateCoverage();static CONE_SOLID_ANGLE=Ct.acuitySolidAngle(0);static CONE_THRESHOLD_LUX=10**((-14.18-4)/2.5);static shared={uRodSolidAngle:{value:1e-7},uConeThreshold:{value:0},uViewportHeight:{value:1},uScintillationTime:{value:0}};static setTime(t){Ct.shared.uScintillationTime.value=t}static viewport=new ue;static track(t){t.userData.pointSource=!0,t.onBeforeRender=e=>{Ct.shared.uViewportHeight.value=Math.max(1,e.getCurrentViewport(Ct.viewport).w)}}static setEye(t,e){Ct.shared.uRodSolidAngle.value=Ct.acuitySolidAngle(t),Ct.shared.uConeThreshold.value=Ct.CONE_THRESHOLD_LUX*e}static material(t,e=!0){const i=new F0({vertexColors:!0,size:t,sizeAttenuation:!1,fog:!1});return i.transparent=!0,i.depthWrite=!1,i.blending=Ti,i.onBeforeCompile=n=>{n.uniforms.uRodSolidAngle=Ct.shared.uRodSolidAngle,n.uniforms.uConeThreshold=Ct.shared.uConeThreshold,n.uniforms.uViewportHeight=Ct.shared.uViewportHeight,n.uniforms.uScintillationTime=Ct.shared.uScintillationTime,n.vertexShader=Ct.patch(n.vertexShader,e),n.fragmentShader=Ct.patchFragment(n.fragmentShader)},i.customProgramCacheKey=()=>e?"point-sources":"point-sources-steady",i}static output={uOutputHalfFovRad:{value:.5236},uOutputAspect:{value:1},uOutputPixelAngle:{value:.003},uSrcTanHalfFovY:{value:1},uOcclusion:{value:null}};static twins=new WeakMap;static outputMaterial(t){let e=Ct.twins.get(t);if(e)return e;const i=t.customProgramCacheKey()==="point-sources";return e=new F0({vertexColors:!0,size:t.size,sizeAttenuation:!1,fog:!1}),e.transparent=!0,e.depthWrite=!1,e.depthTest=!1,e.blending=Ti,e.onBeforeCompile=n=>{n.uniforms.uRodSolidAngle=Ct.shared.uRodSolidAngle,n.uniforms.uConeThreshold=Ct.shared.uConeThreshold,n.uniforms.uViewportHeight=Ct.shared.uViewportHeight,n.uniforms.uScintillationTime=Ct.shared.uScintillationTime,Object.assign(n.uniforms,Ct.output),n.vertexShader=Ct.patchOutput(n.vertexShader,i),n.fragmentShader=Ct.patchFragment(n.fragmentShader)},e.customProgramCacheKey=()=>i?"point-sources-output":"point-sources-output-steady",Ct.twins.set(t,e),e}static PROJECT_ANCHOR="#include <project_vertex>";static patchOutput(t,e=!0){return Ct.patch(t,e).replace("uniform float uRodSolidAngle;",`${Ct.OUTPUT_UNIFORMS_GLSL}
7022
7022
  uniform float uRodSolidAngle;`).replace(Ct.PROJECT_ANCHOR,`${Ct.PROJECT_ANCHOR}
7023
7023
  ${Ct.OUTPUT_PROJECTION_GLSL}`).replace("float pixelAngle = 2.0 / (projectionMatrix[1][1] * uViewportHeight);","float pixelAngle = uOutputPixelAngle;")}static OUTPUT_UNIFORMS_GLSL=`uniform float uOutputHalfFovRad;
7024
7024
  uniform float uOutputAspect;
@@ -7089,7 +7089,7 @@ void main() {`).replace(Es.ANCHOR,`float sigma = max(${Ct.MIN_SIGMA_PX.toFixed(2
7089
7089
  float fromCentre = length( gl_PointCoord - vec2( 0.5 ) ) * vRaster;
7090
7090
  if ( fromCentre > ${Ct.EDGE_SIGMAS.toFixed(1)} * sigma ) discard;
7091
7091
  float share = exp( -0.5 * fromCentre * fromCentre / ( sigma * sigma ) ) * vTotal / ( 6.2831853 * sigma * sigma );
7092
- vec4 diffuseColor = vec4( diffuse, opacity * share );`)}static integrateCoverage(){const{core:e,rim:i}=Es.FALLOFF;let n=0;for(let s=0;s<2e3;s++){const r=(s+.5)/2e3*i,o=Math.min(Math.max((r-e)/(i-e),0),1),c=1-o*o*(3-2*o);n+=c*2*Math.PI*r*(i/2e3)}return n}}class Ki{static K=10;static FAINTEST=.001;static MAX_RADIUS_DEG=30;mesh;constructor(t){this.mesh=new At(new dn(2,2),new Me({uniforms:{uColor:{value:new st(0,0,0)},uTanRadius:{value:.1},uSourceDeg:{value:.25},uInnerDeg:{value:0}},vertexShader:Ki.VERTEX,fragmentShader:Ki.FRAGMENT,transparent:!0,depthWrite:!1,depthTest:!1,blending:Pi,fog:!1})),this.mesh.name=t,this.mesh.frustumCulled=!1,this.mesh.visible=!1}static radiusDeg(t){return Math.min(Ki.MAX_RADIUS_DEG,Math.sqrt(Math.max(t,0)/Ki.FAINTEST))}shine(t,e,i,n=0){const s=Ki.K*Math.max(e[0],e[1],e[2]),r=Ki.radiusDeg(s);if(r<=Math.max(i,n)){this.mesh.visible=!1;return}this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z);const o=this.mesh.material.uniforms;o.uColor.value.setRGB(Ki.K*e[0],Ki.K*e[1],Ki.K*e[2]),o.uTanRadius.value=Math.tan(r*Math.PI/180),o.uSourceDeg.value=i,o.uInnerDeg.value=n}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static VERTEX=`
7092
+ vec4 diffuseColor = vec4( diffuse, opacity * share );`)}static integrateCoverage(){const{core:e,rim:i}=Es.FALLOFF;let n=0;for(let s=0;s<2e3;s++){const r=(s+.5)/2e3*i,o=Math.min(Math.max((r-e)/(i-e),0),1),c=1-o*o*(3-2*o);n+=c*2*Math.PI*r*(i/2e3)}return n}}class Ki{static K=10;static FAINTEST=.001;static MAX_RADIUS_DEG=30;mesh;constructor(t){this.mesh=new At(new dn(2,2),new Me({uniforms:{uColor:{value:new st(0,0,0)},uTanRadius:{value:.1},uSourceDeg:{value:.25},uInnerDeg:{value:0}},vertexShader:Ki.VERTEX,fragmentShader:Ki.FRAGMENT,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ti,fog:!1})),this.mesh.name=t,this.mesh.frustumCulled=!1,this.mesh.visible=!1}static radiusDeg(t){return Math.min(Ki.MAX_RADIUS_DEG,Math.sqrt(Math.max(t,0)/Ki.FAINTEST))}shine(t,e,i,n=0){const s=Ki.K*Math.max(e[0],e[1],e[2]),r=Ki.radiusDeg(s);if(r<=Math.max(i,n)){this.mesh.visible=!1;return}this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z);const o=this.mesh.material.uniforms;o.uColor.value.setRGB(Ki.K*e[0],Ki.K*e[1],Ki.K*e[2]),o.uTanRadius.value=Math.tan(r*Math.PI/180),o.uSourceDeg.value=i,o.uInnerDeg.value=n}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static VERTEX=`
7093
7093
  uniform float uTanRadius;
7094
7094
  varying vec2 vOffset;
7095
7095
  void main() {
@@ -7382,7 +7382,7 @@ void main() {
7382
7382
  vec3 onEncoded = encodeSrgb(uSkyColor + light) - encodeSrgb(uSkyColor);
7383
7383
  gl_FragColor = vec4(mix(light, onEncoded, uEncodeDestination), 1.0);
7384
7384
  }
7385
- `,transparent:!0,blending:Pi,depthWrite:!1,side:Qe,fog:!1}),this.mapsDone=this.maps.done,this.syncReady(),this.object=new At(new pi(Cr.RADIUS,64,32),this.material),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}static buildTexture(t,e,i,n){const s=new Vs(t,e,i,Gi,qe);return s.minFilter=de,s.magFilter=de,s.wrapS=n,s.wrapT=Bi,s.needsUpdate=!0,s}set onReady(t){this.repaint=t}setWithheld(t){this.withheld!==t&&(this.withheld=t,this.syncReady(),!t&&this.mapsDone&&this.repaint?.())}withheld=!1;mapsDone=!1;syncReady(){this.material.uniforms.uReady.value=this.mapsDone&&!this.withheld?1:0}update(t){if(St.moonlessMagPerArcsec2(t.sunAltitudeDeg)<Cr.TOO_BRIGHT_MAG_PER_ARCSEC2){this.object.visible=!1,this.stopWork();return}const i=this.material.uniforms;i.uGalactic.value.copy(t.galactic),i.uEclipticPole.value.copy(t.eclipticPole).normalize(),i.uSunLongitude.value.copy(t.sunLongitude).normalize(),i.uMoonDirection.value.copy(t.moon.direction).normalize(),i.uSunDirection.value.copy(t.sunDirection).normalize(),i.uMoonOutput.value=St.moonOutput(t.moon.phaseAngleDeg,t.moon.altitudeDeg),i.uTwilightOutput.value=St.twilightOutput(t.sunAltitudeDeg),i.uArtificialNanolamberts.value=St.artificialZenithNanolamberts(t.lightPollution),i.uSkyColor.value.copy(t.skyColor),this.object.visible=!0,this.mapsDone||this.scheduleWork()}setDestinationEncoded(t){this.material.uniforms.uEncodeDestination.value=t?1:0}hide(){this.object.visible=!1,this.stopWork()}scheduleWork(){this.maps.request(this.publish)}stopWork(){this.maps.cancel(this.publish)}publish=()=>{this.milkyWayTexture.needsUpdate=!0,this.zodiacalTexture.needsUpdate=!0,this.mapsDone=!0,this.syncReady(),this.repaint?.()};dispose(){this.stopWork(),this.milkyWayTexture.dispose(),this.zodiacalTexture.dispose(),this.object.geometry.dispose(),this.material.dispose()}}class Zc{static instance;static get shared(){return Zc.instance??=new Zc}static WORK_BUDGET_MS=6;milkyWayTexels=new Uint16Array(fe.LONGITUDE_STEPS*fe.LATITUDE_STEPS*4);zodiacalTexels=new Uint16Array(ri.LONGITUDE_STEPS*ri.LATITUDE_STEPS*4);galaxy=new fe;dust=new ri;waiting=new Set;workHandle;published=!1;get done(){return this.published}request(t){if(this.published){t();return}this.waiting.add(t),!(this.workHandle!==void 0||this.job||this.starting)&&(this.starting=!0,kr.with(e=>{this.starting=!1,this.waiting.size!==0&&(this.job=e.glow((i,n)=>{this.job=void 0,this.milkyWayTexels.set(i),this.zodiacalTexels.set(n),this.finish()},()=>{this.job=void 0,this.walkHere()}))},()=>{this.starting=!1,this.walkHere()}))}job;starting=!1;walkHere(){if(this.waiting.size===0||this.workHandle!==void 0)return;const t=()=>{this.workHandle=void 0;const e=performance.now()+Zc.WORK_BUDGET_MS;for(;performance.now()<e&&!(this.galaxy.done&&this.dust.done);)this.galaxy.walk(1),this.dust.walk(1);if(this.galaxy.done&&this.dust.done){this.publish();return}this.workHandle=requestAnimationFrame(t)};this.workHandle=requestAnimationFrame(t)}cancel(t){this.waiting.delete(t),!(this.waiting.size>0)&&(this.job?.cancel(),this.job=void 0,this.workHandle!==void 0&&(cancelAnimationFrame(this.workHandle),this.workHandle=void 0))}publish(){Hu.fromMap(this.galaxy.harvest(),this.milkyWayTexels),Hu.fromMap(this.dust.harvest(),this.zodiacalTexels),this.finish()}finish(){this.published=!0;const t=[...this.waiting];this.waiting.clear();for(const e of t)e()}}class ns{static GALACTIC_CENTRE={raHours:266.4051/15,decDeg:-28.936175};static GALACTIC_ROTATION={raHours:318.00448/15,decDeg:48.32964};static GALACTIC_POLE={raHours:192.85948/15,decDeg:27.12825};static ECLIPTIC_POLE={raHours:18,decDeg:90-23.439291};static galactic(t,e){return{centre:ns.at(ns.GALACTIC_CENTRE,t,e),rotation:ns.at(ns.GALACTIC_ROTATION,t,e),pole:ns.at(ns.GALACTIC_POLE,t,e)}}static eclipticPole(t,e){return ns.at(ns.ECLIPTIC_POLE,t,e)}static at(t,e,i){return os.ofJ2000(t.raHours,t.decDeg,e,i,!1)}}const Z4=`
7385
+ `,transparent:!0,blending:Ti,depthWrite:!1,side:Qe,fog:!1}),this.mapsDone=this.maps.done,this.syncReady(),this.object=new At(new pi(Cr.RADIUS,64,32),this.material),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}static buildTexture(t,e,i,n){const s=new Vs(t,e,i,Gi,qe);return s.minFilter=de,s.magFilter=de,s.wrapS=n,s.wrapT=Bi,s.needsUpdate=!0,s}set onReady(t){this.repaint=t}setWithheld(t){this.withheld!==t&&(this.withheld=t,this.syncReady(),!t&&this.mapsDone&&this.repaint?.())}withheld=!1;mapsDone=!1;syncReady(){this.material.uniforms.uReady.value=this.mapsDone&&!this.withheld?1:0}update(t){if(St.moonlessMagPerArcsec2(t.sunAltitudeDeg)<Cr.TOO_BRIGHT_MAG_PER_ARCSEC2){this.object.visible=!1,this.stopWork();return}const i=this.material.uniforms;i.uGalactic.value.copy(t.galactic),i.uEclipticPole.value.copy(t.eclipticPole).normalize(),i.uSunLongitude.value.copy(t.sunLongitude).normalize(),i.uMoonDirection.value.copy(t.moon.direction).normalize(),i.uSunDirection.value.copy(t.sunDirection).normalize(),i.uMoonOutput.value=St.moonOutput(t.moon.phaseAngleDeg,t.moon.altitudeDeg),i.uTwilightOutput.value=St.twilightOutput(t.sunAltitudeDeg),i.uArtificialNanolamberts.value=St.artificialZenithNanolamberts(t.lightPollution),i.uSkyColor.value.copy(t.skyColor),this.object.visible=!0,this.mapsDone||this.scheduleWork()}setDestinationEncoded(t){this.material.uniforms.uEncodeDestination.value=t?1:0}hide(){this.object.visible=!1,this.stopWork()}scheduleWork(){this.maps.request(this.publish)}stopWork(){this.maps.cancel(this.publish)}publish=()=>{this.milkyWayTexture.needsUpdate=!0,this.zodiacalTexture.needsUpdate=!0,this.mapsDone=!0,this.syncReady(),this.repaint?.()};dispose(){this.stopWork(),this.milkyWayTexture.dispose(),this.zodiacalTexture.dispose(),this.object.geometry.dispose(),this.material.dispose()}}class Zc{static instance;static get shared(){return Zc.instance??=new Zc}static WORK_BUDGET_MS=6;milkyWayTexels=new Uint16Array(fe.LONGITUDE_STEPS*fe.LATITUDE_STEPS*4);zodiacalTexels=new Uint16Array(ri.LONGITUDE_STEPS*ri.LATITUDE_STEPS*4);galaxy=new fe;dust=new ri;waiting=new Set;workHandle;published=!1;get done(){return this.published}request(t){if(this.published){t();return}this.waiting.add(t),!(this.workHandle!==void 0||this.job||this.starting)&&(this.starting=!0,kr.with(e=>{this.starting=!1,this.waiting.size!==0&&(this.job=e.glow((i,n)=>{this.job=void 0,this.milkyWayTexels.set(i),this.zodiacalTexels.set(n),this.finish()},()=>{this.job=void 0,this.walkHere()}))},()=>{this.starting=!1,this.walkHere()}))}job;starting=!1;walkHere(){if(this.waiting.size===0||this.workHandle!==void 0)return;const t=()=>{this.workHandle=void 0;const e=performance.now()+Zc.WORK_BUDGET_MS;for(;performance.now()<e&&!(this.galaxy.done&&this.dust.done);)this.galaxy.walk(1),this.dust.walk(1);if(this.galaxy.done&&this.dust.done){this.publish();return}this.workHandle=requestAnimationFrame(t)};this.workHandle=requestAnimationFrame(t)}cancel(t){this.waiting.delete(t),!(this.waiting.size>0)&&(this.job?.cancel(),this.job=void 0,this.workHandle!==void 0&&(cancelAnimationFrame(this.workHandle),this.workHandle=void 0))}publish(){Hu.fromMap(this.galaxy.harvest(),this.milkyWayTexels),Hu.fromMap(this.dust.harvest(),this.zodiacalTexels),this.finish()}finish(){this.published=!0;const t=[...this.waiting];this.waiting.clear();for(const e of t)e()}}class ns{static GALACTIC_CENTRE={raHours:266.4051/15,decDeg:-28.936175};static GALACTIC_ROTATION={raHours:318.00448/15,decDeg:48.32964};static GALACTIC_POLE={raHours:192.85948/15,decDeg:27.12825};static ECLIPTIC_POLE={raHours:18,decDeg:90-23.439291};static galactic(t,e){return{centre:ns.at(ns.GALACTIC_CENTRE,t,e),rotation:ns.at(ns.GALACTIC_ROTATION,t,e),pole:ns.at(ns.GALACTIC_POLE,t,e)}}static eclipticPole(t,e){return ns.at(ns.ECLIPTIC_POLE,t,e)}static at(t,e,i){return os.ofJ2000(t.raHours,t.decDeg,e,i,!1)}}const Z4=`
7386
7386
  varying vec2 vUv;
7387
7387
  void main() {
7388
7388
  vUv = uv;
@@ -7826,9 +7826,9 @@ void main()
7826
7826
  // stays what it always was for the optional artifacts.
7827
7827
  gl_FragColor = vec4(dazzle + artifactsContribution * uOpacity, 1.0);
7828
7828
  }
7829
- `;let Sh;function j4(){if(Sh)return Sh;const a=256,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d");e.fillStyle="rgba(60,60,60,1)",e.fillRect(0,0,a,a);const i=[[.3,.35,.22,.5],[.7,.6,.16,.35],[.55,.8,.3,.4],[.15,.7,.12,.3],[.85,.2,.18,.3]];for(const[n,s,r,o]of i){const c=e.createRadialGradient(n*a,s*a,0,n*a,s*a,r*a);c.addColorStop(0,`rgba(200,200,200,${o})`),c.addColorStop(1,"rgba(200,200,200,0)"),e.fillStyle=c,e.fillRect(0,0,a,a)}return Sh=new pr(t),Sh}function Q4(){const a={uTime:{value:0},uResolution:{value:new bt(1,1)},uLensPosition:{value:new bt(0,0)},uColorGain:{value:new st(55,55,51)},uOpacity:{value:.5},uFlareIntensity:{value:0},uStarPoints:{value:0},uTanHalfFov:{value:Math.tan(Math.PI/6)},uEquidistant:{value:0},uHalfFovRad:{value:Math.PI/6},uSourceRadiusDeg:{value:.265},uVeilStrength:{value:0},uDazzleColour:{value:new st(1,1,1)},uFlareSize:{value:.0025},uFlareSpeed:{value:.4},uFlareShape:{value:1.2},uHaloScale:{value:.5},uGhostScale:{value:.3},uAnimated:{value:!1},uAnamorphic:{value:!1},uSecondaryGhosts:{value:!0},uStarBurst:{value:!0},uAdditionalStreaks:{value:!0},uLensDirtTexture:{value:j4()}},t=new Me({uniforms:a,vertexShader:Z4,fragmentShader:J4,transparent:!0,depthWrite:!1,depthTest:!1,blending:Pi,fog:!1,name:"LensFlareShader"}),e=new At(new dn(2,2),t);return e.frustumCulled=!1,e.renderOrder=20,{mesh:e,uniforms:a}}class $n{static material(){return new wn({vertexColors:!0,transparent:!0,blending:Pi,depthWrite:!1,fog:!1,side:bn})}static track(t){t.userData.skyRibbon=!0}static twins=new WeakMap;static outputMaterial(t){let e=$n.twins.get(t);return e||(e=$n.material(),e.depthTest=!1,e.onBeforeCompile=i=>{Object.assign(i.uniforms,Ct.output),i.vertexShader=$n.patchOutput(i.vertexShader)},e.customProgramCacheKey=()=>"sky-ribbon-output",$n.twins.set(t,e),e)}static patchOutput(t){return t.replace("void main() {",`${Ct.OUTPUT_UNIFORMS_GLSL}
7829
+ `;let Sh;function j4(){if(Sh)return Sh;const a=256,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d");e.fillStyle="rgba(60,60,60,1)",e.fillRect(0,0,a,a);const i=[[.3,.35,.22,.5],[.7,.6,.16,.35],[.55,.8,.3,.4],[.15,.7,.12,.3],[.85,.2,.18,.3]];for(const[n,s,r,o]of i){const c=e.createRadialGradient(n*a,s*a,0,n*a,s*a,r*a);c.addColorStop(0,`rgba(200,200,200,${o})`),c.addColorStop(1,"rgba(200,200,200,0)"),e.fillStyle=c,e.fillRect(0,0,a,a)}return Sh=new pr(t),Sh}function Q4(){const a={uTime:{value:0},uResolution:{value:new bt(1,1)},uLensPosition:{value:new bt(0,0)},uColorGain:{value:new st(55,55,51)},uOpacity:{value:.5},uFlareIntensity:{value:0},uStarPoints:{value:0},uTanHalfFov:{value:Math.tan(Math.PI/6)},uEquidistant:{value:0},uHalfFovRad:{value:Math.PI/6},uSourceRadiusDeg:{value:.265},uVeilStrength:{value:0},uDazzleColour:{value:new st(1,1,1)},uFlareSize:{value:.0025},uFlareSpeed:{value:.4},uFlareShape:{value:1.2},uHaloScale:{value:.5},uGhostScale:{value:.3},uAnimated:{value:!1},uAnamorphic:{value:!1},uSecondaryGhosts:{value:!0},uStarBurst:{value:!0},uAdditionalStreaks:{value:!0},uLensDirtTexture:{value:j4()}},t=new Me({uniforms:a,vertexShader:Z4,fragmentShader:J4,transparent:!0,depthWrite:!1,depthTest:!1,blending:Ti,fog:!1,name:"LensFlareShader"}),e=new At(new dn(2,2),t);return e.frustumCulled=!1,e.renderOrder=20,{mesh:e,uniforms:a}}class $n{static material(){return new wn({vertexColors:!0,transparent:!0,blending:Ti,depthWrite:!1,fog:!1,side:bn})}static track(t){t.userData.skyRibbon=!0}static twins=new WeakMap;static outputMaterial(t){let e=$n.twins.get(t);return e||(e=$n.material(),e.depthTest=!1,e.onBeforeCompile=i=>{Object.assign(i.uniforms,Ct.output),i.vertexShader=$n.patchOutput(i.vertexShader)},e.customProgramCacheKey=()=>"sky-ribbon-output",$n.twins.set(t,e),e)}static patchOutput(t){return t.replace("void main() {",`${Ct.OUTPUT_UNIFORMS_GLSL}
7830
7830
  void main() {`).replace(Ct.PROJECT_ANCHOR,`${Ct.PROJECT_ANCHOR}
7831
- ${Ct.OUTPUT_PROJECTION_GLSL}`)}}class nn{constructor(t,e){this.width=t,this.height=e,this.target=new oi(t,e,{type:qe,samples:4}),this.occlusion=new oi(...nn.occlusionSize(t,e))}static OCCLUDER_LAYER=6;static CLOUD_LAYER=7;static OCCLUSION_SCALE=.5;target;occlusion;scene=new Gs;proxies=new Map;foreground=new wn({color:0,fog:!1});hidden=[];static occlusionSize(t,e){return[Math.max(1,Math.round(t*nn.OCCLUSION_SCALE)),Math.max(1,Math.round(e*nn.OCCLUSION_SCALE))]}resize(t,e){this.width=t,this.height=e,this.target.setSize(t,e),this.occlusion.setSize(...nn.occlusionSize(t,e))}take(t){this.hidden=t.points().filter(e=>nn.shown(e)&&nn.holdsPoints(e.geometry));for(const e of this.hidden)e.visible=!1;return this.hidden.length>0}restore(){for(const t of this.hidden)t.visible=!0}static shown(t){for(let e=t;e;e=e.parent)if(!e.visible)return!1;return!0}static holdsPoints(t){return(t.getAttribute("position")?.count??0)>0&&t.drawRange.count>0}draw(t,e,i,n,s,r){const o=t.getRenderTarget(),c=t.autoClear,l=t.shadowMap.autoUpdate;t.autoClear=!1,t.shadowMap.autoUpdate=!1,this.drawOcclusion(t,e,i,n);const h=this.width/this.height,u=Ct.output;u.uOutputHalfFovRad.value=s,u.uOutputAspect.value=h,u.uOutputPixelAngle.value=2*s/this.height,u.uSrcTanHalfFovY.value=r,u.uOcclusion.value=this.occlusion.texture,this.placeProxies(),Ke.clearTransparent(t,this.target),t.setRenderTarget(this.target),t.render(this.scene,i),t.autoClear=c,t.shadowMap.autoUpdate=l,t.setRenderTarget(o)}drawOcclusion(t,e,i,n){nn.markForeground(e,n.sky);for(const r of n.clouds())r.layers.enable(nn.CLOUD_LAYER);Ke.clearTransparent(t,this.occlusion),t.setRenderTarget(this.occlusion);const s=e.background;e.background=null,i.layers.set(nn.OCCLUDER_LAYER),e.overrideMaterial=this.foreground,t.render(e,i),e.overrideMaterial=null,i.layers.set(nn.CLOUD_LAYER),t.render(e,i),i.layers.set(0),e.background=s}static markForeground(t,e){for(const i of t.children)if(i!==e){if(i instanceof At&&i.layers.isEnabled(0)){const n=Array.isArray(i.material)?i.material[0]:i.material;n.depthWrite!==!1&&!n.transparent&&n.blending!==Pi?i.layers.enable(nn.OCCLUDER_LAYER):i.layers.disable(nn.OCCLUDER_LAYER)}nn.markForeground(i,e)}}placeProxies(){for(const t of this.hidden){let e=this.proxies.get(t);e||(e=t instanceof In?new In(t.geometry,Ct.outputMaterial(t.material)):new At(t.geometry,$n.outputMaterial(t.material)),e.matrixAutoUpdate=!1,e.frustumCulled=!1,this.proxies.set(t,e),this.scene.add(e)),e.geometry=t.geometry,t.updateWorldMatrix(!0,!1),e.matrix.copy(t.matrixWorld),e.matrixWorldNeedsUpdate=!0,e.visible=!0}for(const[t,e]of this.proxies)this.hidden.includes(t)||(e.visible=!1,t.parent||(this.scene.remove(e),this.proxies.delete(t)))}dispose(){this.target.dispose(),this.occlusion.dispose(),this.foreground.dispose()}}class Ke{static MAX_HALF_ANGLE_DEG=80;static MAX_CUBE_FACE=2048;static SAMPLES=4;pointLayer;cubeTarget;cubeCamera;cubeMaterial;cubeRotation=new Jt;target;overlayTarget;overlayCubeTarget;quadScene=new Gs;quadCamera=new ps(-1,1,1,-1,0,1);material;width;height;constructor(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e),this.target=new oi(this.width,this.height,{type:qe,samples:Ke.SAMPLES}),this.overlayTarget=new oi(this.width,this.height,{type:qe,samples:Ke.SAMPLES}),this.material=new Me({uniforms:{...ln,uSource:{value:this.target.texture},uHalfFovRad:{value:.5236},uAspect:{value:this.width/this.height},uSrcTanHalfFovY:{value:1},uResolution:{value:new bt(this.width,this.height)},uOverlay:{value:this.overlayTarget.texture},uPoints:{value:null},uPointsOn:{value:0},uMode:{value:On.Finished}},vertexShader:`
7831
+ ${Ct.OUTPUT_PROJECTION_GLSL}`)}}class nn{constructor(t,e){this.width=t,this.height=e,this.target=new oi(t,e,{type:qe,samples:4}),this.occlusion=new oi(...nn.occlusionSize(t,e))}static OCCLUDER_LAYER=6;static CLOUD_LAYER=7;static OCCLUSION_SCALE=.5;target;occlusion;scene=new Gs;proxies=new Map;foreground=new wn({color:0,fog:!1});hidden=[];static occlusionSize(t,e){return[Math.max(1,Math.round(t*nn.OCCLUSION_SCALE)),Math.max(1,Math.round(e*nn.OCCLUSION_SCALE))]}resize(t,e){this.width=t,this.height=e,this.target.setSize(t,e),this.occlusion.setSize(...nn.occlusionSize(t,e))}take(t){this.hidden=t.points().filter(e=>nn.shown(e)&&nn.holdsPoints(e.geometry));for(const e of this.hidden)e.visible=!1;return this.hidden.length>0}restore(){for(const t of this.hidden)t.visible=!0}static shown(t){for(let e=t;e;e=e.parent)if(!e.visible)return!1;return!0}static holdsPoints(t){return(t.getAttribute("position")?.count??0)>0&&t.drawRange.count>0}draw(t,e,i,n,s,r){const o=t.getRenderTarget(),c=t.autoClear,l=t.shadowMap.autoUpdate;t.autoClear=!1,t.shadowMap.autoUpdate=!1,this.drawOcclusion(t,e,i,n);const h=this.width/this.height,u=Ct.output;u.uOutputHalfFovRad.value=s,u.uOutputAspect.value=h,u.uOutputPixelAngle.value=2*s/this.height,u.uSrcTanHalfFovY.value=r,u.uOcclusion.value=this.occlusion.texture,this.placeProxies(),Ke.clearTransparent(t,this.target),t.setRenderTarget(this.target),t.render(this.scene,i),t.autoClear=c,t.shadowMap.autoUpdate=l,t.setRenderTarget(o)}drawOcclusion(t,e,i,n){nn.markForeground(e,n.sky);for(const r of n.clouds())r.layers.enable(nn.CLOUD_LAYER);Ke.clearTransparent(t,this.occlusion),t.setRenderTarget(this.occlusion);const s=e.background;e.background=null,i.layers.set(nn.OCCLUDER_LAYER),e.overrideMaterial=this.foreground,t.render(e,i),e.overrideMaterial=null,i.layers.set(nn.CLOUD_LAYER),t.render(e,i),i.layers.set(0),e.background=s}static markForeground(t,e){for(const i of t.children)if(i!==e){if(i instanceof At&&i.layers.isEnabled(0)){const n=Array.isArray(i.material)?i.material[0]:i.material;n.depthWrite!==!1&&!n.transparent&&n.blending!==Ti?i.layers.enable(nn.OCCLUDER_LAYER):i.layers.disable(nn.OCCLUDER_LAYER)}nn.markForeground(i,e)}}placeProxies(){for(const t of this.hidden){let e=this.proxies.get(t);e||(e=t instanceof In?new In(t.geometry,Ct.outputMaterial(t.material)):new At(t.geometry,$n.outputMaterial(t.material)),e.matrixAutoUpdate=!1,e.frustumCulled=!1,this.proxies.set(t,e),this.scene.add(e)),e.geometry=t.geometry,t.updateWorldMatrix(!0,!1),e.matrix.copy(t.matrixWorld),e.matrixWorldNeedsUpdate=!0,e.visible=!0}for(const[t,e]of this.proxies)this.hidden.includes(t)||(e.visible=!1,t.parent||(this.scene.remove(e),this.proxies.delete(t)))}dispose(){this.target.dispose(),this.occlusion.dispose(),this.foreground.dispose()}}class Ke{static MAX_HALF_ANGLE_DEG=80;static MAX_CUBE_FACE=2048;static SAMPLES=4;pointLayer;cubeTarget;cubeCamera;cubeMaterial;cubeRotation=new Jt;target;overlayTarget;overlayCubeTarget;quadScene=new Gs;quadCamera=new ps(-1,1,1,-1,0,1);material;width;height;constructor(t,e){this.width=Math.max(1,t),this.height=Math.max(1,e),this.target=new oi(this.width,this.height,{type:qe,samples:Ke.SAMPLES}),this.overlayTarget=new oi(this.width,this.height,{type:qe,samples:Ke.SAMPLES}),this.material=new Me({uniforms:{...ln,uSource:{value:this.target.texture},uHalfFovRad:{value:.5236},uAspect:{value:this.width/this.height},uSrcTanHalfFovY:{value:1},uResolution:{value:new bt(this.width,this.height)},uOverlay:{value:this.overlayTarget.texture},uPoints:{value:null},uPointsOn:{value:0},uMode:{value:On.Finished}},vertexShader:`
7832
7832
  varying vec2 vNdc;
7833
7833
  void main() {
7834
7834
  vNdc = position.xy;
@@ -8030,7 +8030,7 @@ ${Ct.OUTPUT_PROJECTION_GLSL}`)}}class nn{constructor(t,e){this.width=t,this.heig
8030
8030
  vec4 overlay = texture2D(uOverlay, vUv);
8031
8031
  ${$c}
8032
8032
  }
8033
- `,depthTest:!1,depthWrite:!1}),this.quadScene.add(new At(new dn(2,2),this.material))}render(t,e,i,n,s,r){const o=t.getRenderTarget(),c=r??{scene:this.scene,overlay:this.overlay};t.setRenderTarget(c.scene),t.render(e,i),s?.(),(n||r)&&(Ke.clearTransparent(t,c.overlay),n?.()),t.setRenderTarget(o),!r&&(this.material.uniforms.uMode.value=On.Finished,t.render(this.quadScene,this.quadCamera))}resize(t,e){this.scene.setSize(Math.max(1,t),Math.max(1,e)),this.overlay.setSize(Math.max(1,t),Math.max(1,e))}dispose(){this.scene.dispose(),this.overlay.dispose(),this.material.dispose(),this.quadScene.children[0].geometry.dispose()}}class _e{static MIN_RATIO=1;static STEP=.25;static MIN_SHARE_OF_DISPLAY=.75;static GPU_LATE_MS=12;static GPU_ROOM_MS=6;static INTERVAL_LATE_MS=21;static LOWER_COOLDOWN_MS=750;static RAISE_COOLDOWN_MS=2e3;static PROBE_WATCH_MS=2e3;static PROBE_EVERY_MS=6e3;static PROBE_BACKOFF_MS=3e4;ratio;maxRatio;timer;intervalMs;lastChangeMs=-1/0;nextProbeMs=0;probe;constructor(t,e){this.maxRatio=_e.clamp(t),this.ratio=this.maxRatio,this.timer=e?Gu.create(e):void 0}get pixelRatio(){return this.ratio}static SETTLE_MS=400;static SUSTAINED_MS=100;lastEditMs=-1/0;editStreakStartMs=-1/0;wasChanging=!1;noteChange(t){t-this.lastEditMs>_e.SETTLE_MS&&(this.editStreakStartMs=t),this.lastEditMs=t}changing(t){return t-this.lastEditMs<=_e.SETTLE_MS&&this.lastEditMs-this.editStreakStartMs>=_e.SUSTAINED_MS}ratioFor(t,e){return this.changing(t)?this.wasChanging?(this.update(t,e),this.ratio):(this.wasChanging=!0,this.reset(),this.ratio):(this.wasChanging=!1,this.maxRatio)}get timesGpu(){return this.timer!==void 0}set maximum(t){this.maxRatio=_e.clamp(t),this.ratio>this.maxRatio&&(this.ratio=this.maxRatio),this.ratio<this.minimum&&(this.ratio=Math.min(this.maxRatio,this.minimum))}get minimum(){const t=Math.floor(this.maxRatio*_e.MIN_SHARE_OF_DISPLAY/_e.STEP)*_e.STEP;return Math.max(_e.MIN_RATIO,t)}get maximum(){return this.maxRatio}beginDrawing(){this.timer?.begin()}endDrawing(){this.timer?.end()}reset(){this.intervalMs=void 0,this.probe=void 0,this.timer?.reset()}update(t,e){const i=this.timer?.poll();if(!(this.timer&&i===void 0))return i!==void 0?this.followGpu(t,i):this.followIntervals(t,e)}followGpu(t,e){if(e>_e.GPU_LATE_MS)return this.lower(t,_e.LOWER_COOLDOWN_MS);if(e<_e.GPU_ROOM_MS)return this.raise(t,_e.RAISE_COOLDOWN_MS)}followIntervals(t,e){if(!(e>0)||e>1e3)return;this.intervalMs=this.intervalMs===void 0?e:this.intervalMs*.9+e*.1;const i=this.intervalMs>_e.INTERVAL_LATE_MS;if(this.probe){if(i)return this.ratio=this.probe.ratioBefore,this.probe=void 0,this.lastChangeMs=t,this.nextProbeMs=t+_e.PROBE_BACKOFF_MS,this.ratio;t-this.probe.sinceMs>=_e.PROBE_WATCH_MS&&(this.probe=void 0,this.nextProbeMs=t+_e.PROBE_EVERY_MS);return}if(i){const n=this.lower(t,_e.LOWER_COOLDOWN_MS);return n!==void 0&&(this.nextProbeMs=t+_e.PROBE_EVERY_MS),n}if(this.ratio<this.maxRatio&&t>=this.nextProbeMs&&t-this.lastChangeMs>=_e.RAISE_COOLDOWN_MS){const n=this.ratio,s=this.raise(t,0);return s!==void 0&&(this.probe={sinceMs:t,ratioBefore:n}),s}}lower(t,e){if(!(this.ratio<=this.minimum||t-this.lastChangeMs<e))return this.ratio=Math.max(this.minimum,_e.clamp(this.ratio-_e.STEP)),this.lastChangeMs=t,this.ratio}raise(t,e){if(!(this.ratio>=this.maxRatio||t-this.lastChangeMs<e))return this.ratio=Math.min(this.maxRatio,_e.clamp(this.ratio+_e.STEP)),this.lastChangeMs=t,this.ratio}static clamp(t){return Number.isFinite(t)?Math.max(_e.MIN_RATIO,Math.round(t/_e.STEP)*_e.STEP):_e.MIN_RATIO}}class Gu{constructor(t,e){this.gl=t,this.extension=e}static IN_FLIGHT_MAX=8;static create(t){if(!(t instanceof WebGL2RenderingContext))return;const e=t.getExtension("EXT_disjoint_timer_query_webgl2");return e?new Gu(t,e):void 0}pending=[];active;smoothedMs;begin(){if(!(this.active||this.pending.length>=Gu.IN_FLIGHT_MAX))try{const t=this.gl.createQuery();if(!t)return;this.gl.beginQuery(this.extension.TIME_ELAPSED_EXT,t),this.active=t}catch{this.active=void 0}}end(){if(this.active){try{this.gl.endQuery(this.extension.TIME_ELAPSED_EXT),this.pending.push(this.active)}catch{}this.active=void 0}}poll(){const t=this.gl;try{for(let e=0;e<this.pending.length;e++){const i=this.pending[e];if(!t.getQueryParameter(i,t.QUERY_RESULT_AVAILABLE))continue;if(!t.getParameter(this.extension.GPU_DISJOINT_EXT)){const s=t.getQueryParameter(i,t.QUERY_RESULT)/1e6;this.smoothedMs=this.smoothedMs===void 0?s:this.smoothedMs*.8+s*.2}t.deleteQuery(i),this.pending.splice(e,1),e--}}catch{this.pending.length=0}return this.smoothedMs}reset(){this.smoothedMs=void 0}}class Se{static ICE_INDEX_RED=1.3067;static ICE_INDEX_BLUE=1.317;static SIDE_PRISM_ANGLE_DEG=60;static END_PRISM_ANGLE_DEG=90;static get PARHELIA_MAX_SUN_ALTITUDE_DEG(){const t=Se.ICE_INDEX_RED,e=Math.sqrt((4-t*t)/3);return Math.asin(Math.min(1,e))*180/Math.PI}static minimumDeviationDeg(t,e){const i=t*Math.PI/180,n=e*Math.sin(i/2);return n>1?Number.NaN:(2*Math.asin(n)-i)*180/Math.PI}static effectiveIndex(t,e){const i=e*Math.PI/180,n=Math.cos(i);return n<=0?Number.POSITIVE_INFINITY:Math.sqrt(t*t-Math.sin(i)**2)/n}static parheliaAzimuthDeg(t,e=Se.ICE_INDEX_RED){const i=Se.minimumDeviationDeg(Se.SIDE_PRISM_ANGLE_DEG,Se.effectiveIndex(e,t));return Number.isFinite(i)?i:void 0}static parheliaDistanceDeg(t,e=Se.ICE_INDEX_RED){const i=Se.parheliaAzimuthDeg(t,e);if(i===void 0)return;const n=t*Math.PI/180,s=Math.sin(n)**2,r=Math.cos(n)**2*Math.cos(i*Math.PI/180);return Math.acos(Math.max(-1,Math.min(1,s+r)))*180/Math.PI}static get PLATE_END_FACE_LIMIT_DEG(){const t=Se.ICE_INDEX_RED;return Math.asin(Math.min(1,Math.sqrt(t*t-1)))*180/Math.PI}static circumzenithalAltitudeDeg(t,e=Se.ICE_INDEX_RED){if(t<0||t>90-Se.PLATE_END_FACE_LIMIT_DEG)return;const i=Math.cos(t*Math.PI/180),n=Math.sqrt(e*e-i*i);if(!(n>=1))return Math.asin(n)*180/Math.PI}static DECK_HEIGHT_M=8e3;static deckLitUntilDeg(t){return Math.acos(6371e3/(6371e3+Math.max(0,t)))*180/Math.PI}static halo22(){return Se.ringOf("halo22",Se.SIDE_PRISM_ANGLE_DEG)}static halo46(){return Se.ringOf("halo46",Se.END_PRISM_ANGLE_DEG)}static ringOf(t,e){const i=Se.minimumDeviationDeg(e,Se.ICE_INDEX_RED),n=Se.minimumDeviationDeg(e,Se.ICE_INDEX_BLUE);return{id:t,angleDeg:(i+n)/2,redAngleDeg:i,blueAngleDeg:n}}static strength(t,e,i=90,n=0){const s=Math.max(0,Math.min(1,t)),r=Math.max(0,1-Math.max(0,Math.min(1,e))),o=i>=0?1:n<=0?0:Math.max(0,1+i/n);return s*r*o}static formsAt(t,e=0){if(t<=-e)return[];const i=[Se.halo22(),Se.halo46()],n=t>0?Se.parheliaDistanceDeg(t):void 0;n!==void 0&&i.push({id:"parhelia",angleDeg:n,redAngleDeg:n,blueAngleDeg:Se.parheliaDistanceDeg(t,Se.ICE_INDEX_BLUE)}),i.push({id:"tangentArc",angleDeg:Se.halo22().angleDeg}),t>0&&i.push({id:"parhelicCircle",angleDeg:t});const s=Se.circumzenithalAltitudeDeg(t);return s!==void 0&&i.push({id:"circumzenithal",angleDeg:s}),t>Se.PLATE_END_FACE_LIMIT_DEG&&i.push({id:"circumhorizontal"}),t<Se.PILLAR_MAX_SOURCE_ALTITUDE_DEG&&i.push({id:"pillar"}),i}static PILLAR_MAX_SOURCE_ALTITUDE_DEG=20}class Tn{static get WATER_INDEX_RED(){return zi.indexAt(zi.RED_NM)}static get WATER_INDEX_BLUE(){return zi.indexAt(zi.BLUE_NM)}static radiusDeg(t,e){const i=(e*e-1)/(t*t-1);if(i<0||i>1)return Number.NaN;const n=Math.acos(Math.sqrt(i)),s=Math.asin(Math.sin(n)/e),r=2*(n-s)+(t-1)*(Math.PI-2*s),o=2*Math.PI;let c=r%o;return c<0&&(c+=o),c>Math.PI&&(c=o-c),180-c*180/Math.PI}static primary(){return Tn.bowOf("primary",2,0)}static secondary(){return Tn.bowOf("secondary",3,0)}static bowOf(t,e,i){const n=Tn.radiusDeg(e,Tn.WATER_INDEX_RED),s=Tn.radiusDeg(e,Tn.WATER_INDEX_BLUE),r=(n+s)/2;return{id:t,radiusDeg:r,redRadiusDeg:n,violetRadiusDeg:s,topAltitudeDeg:r-i}}static alexandersBandDeg(){return{fromDeg:Tn.primary().redRadiusDeg,toDeg:Tn.secondary().redRadiusDeg}}static formsAt(t){return t<0?[]:[Tn.bowOf("primary",2,t),Tn.bowOf("secondary",3,t)].filter(e=>e.topAltitudeDeg>0)}static FULL_MOON_MAGNITUDE=-12.7;static moonlightShare(t){return Math.min(1,10**(-.4*(t-Tn.FULL_MOON_MAGNITUDE)))}static strength(t,e,i){if(i<=0)return 0;const n=Math.max(0,Math.min(1,t)),s=Math.max(0,1-Math.max(0,Math.min(1,e)));return n*s}}class Rn{constructor(t){this.radius=t;const e=Rn.SEGMENTS*Rn.VERTICES_PER_SEGMENT;this.positions=new Float32Array(e*3),this.colors=new Float32Array(e*3);const i=new ae;i.setAttribute("position",new te(this.positions,3)),i.setAttribute("color",new te(this.colors,3)),i.setDrawRange(0,0),this.object=new At(i,$n.material()),this.object.frustumCulled=!1,$n.track(this.object)}static POINTS=24;static SEGMENTS=Rn.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(Rn.ACROSS-1)*6;static HEAD_HALF_WIDTH_DEG=.15;static SPREAD_FRACTION=.05;static FADE_POWER=1.8;object;positions;colors;head;tip;brightness=0;set(t,e,i){this.head=t&&Xe(t.altitudeDeg,t.azimuthDeg,1),this.tip=e&&Xe(e.altitudeDeg,e.azimuthDeg,1),this.brightness=i,this.rebuild()}rebuild(){const t=this.object.geometry,e=this.head,i=this.tip;if(!e||!i||this.brightness<=0){t.setDrawRange(0,0);return}const n=this.angleBetween(e,i);if(n<=0){t.setDrawRange(0,0);return}const s=n*Rn.SPREAD_FRACTION*Math.PI/180,r=h=>this.scale(this.slerp(e,i,h),this.radius),o=h=>this.radius*(Rn.HEAD_HALF_WIDTH_DEG*Math.PI/180+s*h),c=h=>this.brightness*(1-h)**Rn.FADE_POWER;let l=0;for(let h=1;h<Rn.POINTS;h++){const u=(h-1)/Rn.SEGMENTS,d=h/Rn.SEGMENTS;l=this.pushBand(l,r(u),r(d),o(u),o(d),c(u),c(d))}t.setDrawRange(0,l),t.getAttribute("position").needsUpdate=!0,t.getAttribute("color").needsUpdate=!0}pushBand(t,e,i,n,s,r,o){const c=this.normalise(this.cross(this.normalise(e),this.normalise(this.subtract(i,e))));for(let l=0;l<Rn.ACROSS-1;l++){const h=l-1,u=l,d=this.across(e,c,n,h),f=this.across(i,c,s,h),p=this.across(e,c,n,u),v=this.across(i,c,s,u),m=(g,b)=>g===0?b:0;t=this.push(t,d,m(h,r)),t=this.push(t,f,m(h,o)),t=this.push(t,p,m(u,r)),t=this.push(t,f,m(h,o)),t=this.push(t,v,m(u,o)),t=this.push(t,p,m(u,r))}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i){const n=t*3;this.positions[n]=e.x,this.positions[n+1]=e.y,this.positions[n+2]=e.z;const s=Rt.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[n]=s*.55,this.colors[n+1]=s*.75,this.colors[n+2]=s,t+1}slerp(t,e,i){const n=this.angleBetweenRadians(t,e);if(n<1e-9)return t;const s=Math.sin(n),r=Math.sin((1-i)*n)/s,o=Math.sin(i*n)/s;return{x:t.x*r+e.x*o,y:t.y*r+e.y*o,z:t.z*r+e.z*o}}angleBetween(t,e){return this.angleBetweenRadians(t,e)*180/Math.PI}angleBetweenRadians(t,e){const i=t.x*e.x+t.y*e.y+t.z*e.z;return Math.acos(Math.min(1,Math.max(-1,i)))}scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class tR{object=new Ee;radius;tiers;drawn=[];constructor(t){this.radius=t,this.object.name="satellites",this.tiers=Vo.map(e=>{const i=new In(new ae,Ct.material(e.size));return Ct.track(i),i.frustumCulled=!1,this.object.add(i),i})}set(t,e,i,n){const s=this.tiers.map(()=>[]);this.drawn=[];for(const r of t){if(r.magnitude>e)continue;const o=i(r.position);if(o<=0)continue;const c=r.magnitude-2.5*Math.log10(o);if(c>e)continue;const l=Po(c,e),h=tm(l),{x:u,y:d,z:f}=Xe(r.position.altitudeDeg,r.position.azimuthDeg,this.radius),[p,v,m]=n(r.position,c);s[h].push({x:u,y:d,z:f,r:p,g:v,b:m,seed:r.norad*.6180339887%1}),this.drawn.push({satellite:r,direction:new R(u,d,f).normalize()})}this.tiers.forEach((r,o)=>{const c=s[o],l=new Float32Array(c.length*3),h=new Float32Array(c.length*3),u=new Float32Array(c.length);c.forEach((f,p)=>{l.set([f.x,f.y,f.z],p*3),h.set([f.r,f.g,f.b],p*3),u[p]=f.seed}),r.geometry.dispose();const d=new ae;d.setAttribute("position",new te(l,3)),d.setAttribute("color",new te(h,3)),d.setAttribute("seed",new te(u,1)),r.geometry=d})}get count(){return this.drawn.length}nearest(t,e){let i,n=e;for(const s of this.drawn){const r=s.direction.dot(t);r>n&&(n=r,i=s.satellite)}return i}dispose(){for(const t of this.tiers)t.geometry.dispose(),t.material.dispose();this.object.removeFromParent(),this.drawn=[]}}class mn{static RADIUS=840;static MAX_SEGMENTS=256;static VERTICES_PER_SEGMENT=12;static MIN_HALF_WIDTH_DEG=.05;static BRIGHT_HALF_WIDTH_DEG=.22;static TRAIN_SHARE=.6;object=new Ee;tiers;trains;positions;colors;shown=0;constructor(){this.object.name="reentries",this.tiers=Vo.map(i=>{const n=new In(new ae,Ct.material(i.size,!1));return Ct.track(n),n.frustumCulled=!1,this.object.add(n),n});const t=mn.MAX_SEGMENTS*mn.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const e=new ae;e.setAttribute("position",new te(this.positions,3)),e.setAttribute("color",new te(this.colors,3)),e.setDrawRange(0,0),this.trains=new At(e,$n.material()),this.trains.frustumCulled=!1,$n.track(this.trains),this.object.add(this.trains)}get count(){return this.shown}set(t,e,i,n){const s=this.tiers.map(()=>[]);let r=0,o=0;const c=new st;for(const h of t){const u=i(h.head);if(u<=0)continue;const d=h.magnitude-2.5*Math.log10(u);if(d>e)continue;o++,c.set(h.color);const f=Po(d,e),{x:p,y:v,z:m}=Xe(h.head.altitudeDeg,h.head.azimuthDeg,mn.RADIUS),[g,b,S]=n(h.head,d),M=Math.max(c.r,c.g,c.b)||1;s[tm(f)].push({x:p,y:v,z:m,r:g*c.r/M,g:b*c.g/M,b:S*c.b/M}),r=this.pushTrain(r,h.train,f,c)}this.shown=o,this.tiers.forEach((h,u)=>{const d=s[u],f=new Float32Array(d.length*3),p=new Float32Array(d.length*3);d.forEach((m,g)=>{f.set([m.x,m.y,m.z],g*3),p.set([m.r,m.g,m.b],g*3)}),h.geometry.dispose();const v=new ae;v.setAttribute("position",new te(f,3)),v.setAttribute("color",new te(p,3)),h.geometry=v});const l=this.trains.geometry;l.setDrawRange(0,r),l.getAttribute("position").needsUpdate=!0,l.getAttribute("color").needsUpdate=!0}pushTrain(t,e,i,n){const s=e.length-1;for(let r=0;r<s;r++){if(t+mn.VERTICES_PER_SEGMENT>mn.MAX_SEGMENTS*mn.VERTICES_PER_SEGMENT)return t;const o=1-r/s,c=1-(r+1)/s,l=Xe(e[r].altitudeDeg,e[r].azimuthDeg,mn.RADIUS),h=Xe(e[r+1].altitudeDeg,e[r+1].azimuthDeg,mn.RADIUS),u=f=>mn.RADIUS*((mn.MIN_HALF_WIDTH_DEG+mn.BRIGHT_HALF_WIDTH_DEG*i*f)*Math.PI/180),d=f=>mn.TRAIN_SHARE*i*f**1.6;t=this.pushRibbon(t,l,h,u(o),u(c),d(o),d(c),n)}return t}pushRibbon(t,e,i,n,s,r,o,c){const l={x:i.x-e.x,y:i.y-e.y,z:i.z-e.z};if(Math.hypot(l.x,l.y,l.z)<1e-9)return t;const h=this.normalise(this.cross(this.normalise(e),this.normalise(l)));for(const[u,d]of[[-1,0],[0,1]]){const f=this.across(e,h,n,u),p=this.across(i,h,s,u),v=this.across(e,h,n,d),m=this.across(i,h,s,d),g=(b,S)=>b===0?S:0;t=this.push(t,f,g(u,r),c),t=this.push(t,p,g(u,o),c),t=this.push(t,v,g(d,r),c),t=this.push(t,p,g(u,o),c),t=this.push(t,m,g(d,o),c),t=this.push(t,v,g(d,r),c)}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i,n){const s=t*3;this.positions[s]=e.x,this.positions[s+1]=e.y,this.positions[s+2]=e.z;const r=Rt.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[s]=r*n.r,this.colors[s+1]=r*n.g,this.colors[s+2]=r*n.b,t+1}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){for(const t of this.tiers)t.geometry.dispose(),t.material.dispose();this.trains.geometry.dispose(),this.trains.material.dispose(),this.object.removeFromParent()}}class pd{constructor(t){this.state=t}next(){this.state=this.state+1831565813|0;let t=this.state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}between(t,e){return t+this.next()*(e-t)}}class ka{static MIN_DURATION_MS=250;static MAX_DURATION_MS=1400;static schedule(t){const{ratePerHour:e,durationMs:i,velocityKmS:n,seed:s}=t;if(e<=0||i<=0)return[];const r=e*i/36e5,o=new pd(s),c=Math.floor(r),l=c+(o.next()<r-c?1:0),h=[];for(let u=0;u<l;u++){const d=Math.min(1,Math.max(0,(n-20)/52)),f=ka.MAX_DURATION_MS-d*(ka.MAX_DURATION_MS-ka.MIN_DURATION_MS),p=o.between(5,70);h.push({t:o.between(0,i),durationMs:f*o.between(.7,1.3),fromRadiantDeg:p,bearingDeg:o.between(0,360),lengthDeg:Math.sin(p*Math.PI/180)*o.between(8,40)*(.6+d),brightness:o.next()**3}),h.sort((v,m)=>v.t-m.t)}return h}static aliveAt(t,e){return t.filter(i=>e>=i.t&&e<=i.t+i.durationMs).map(i=>({meteor:i,progress:(e-i.t)/i.durationMs}))}}class Pr{object=new Ee;radius;core;glow;flashKey;static CORE_WIDTH_DEG=.06;static GLOW_WIDTH_DEG=.5;static SEGMENTS=28;static CORE_RELATIVE=1e3;constructor(t){this.radius=t,this.object.name="lightning-bolt",this.core=new wn({color:15659775,transparent:!0,opacity:0,blending:Pi,depthWrite:!1,fog:!1}),this.glow=new wn({color:10466559,transparent:!0,opacity:0,blending:Pi,depthWrite:!1,fog:!1}),this.object.visible=!1,this.object.renderOrder=5.95}set(t,e,i){if(!t||!t.cloudToGround||e<=.01){this.object.visible=!1;return}const n=`${t.channelSeed}:${Math.round(i)}`;n!==this.flashKey&&this.build(t,i,n),this.core.color.setHex(15659775).multiplyScalar(Pr.CORE_RELATIVE*Math.min(1,e*1.4)),this.glow.color.setHex(10466559).multiplyScalar(.1*Pr.CORE_RELATIVE*e*.35),this.core.opacity=1,this.glow.opacity=1,this.object.visible=!0}build(t,e,i){this.flashKey=i;for(const l of[...this.object.children])l.geometry.dispose(),this.object.remove(l);const n=new pd(t.channelSeed),s=Math.atan2(e,t.distanceM)*180/Math.PI,r=this.channel(n,t.azimuthDeg,s,0,1),o=[r],c=1+Math.floor(n.next()*2);for(let l=0;l<c;l++){const h=r[Math.floor(n.between(.15,.5)*r.length)];o.push(this.channel(n,h.azimuthDeg,h.altitudeDeg,h.altitudeDeg*n.between(.3,.7),.5))}for(const l of o)this.object.add(new At(this.ribbon(l,Pr.GLOW_WIDTH_DEG),this.glow)),this.object.add(new At(this.ribbon(l,Pr.CORE_WIDTH_DEG),this.core))}channel(t,e,i,n,s){const r=[],o=i-n;let c=e;for(let l=0;l<=Pr.SEGMENTS;l++){const h=i-o*l/Pr.SEGMENTS;r.push({azimuthDeg:c,altitudeDeg:h}),c+=t.between(-1,1)*o*.06*s}return r}ribbon(t,e){const i=new Float32Array(t.length*2*3),n=[],s=this.radius*Math.tan(e*Math.PI/180)/2,r=t.map(c=>{const{x:l,y:h,z:u}=Xe(c.altitudeDeg,c.azimuthDeg,this.radius);return new R(l,h,u)});r.forEach((c,l)=>{const h=r[Math.min(l+1,r.length-1)],u=r[Math.max(l-1,0)],f=h.clone().sub(u).normalize().cross(c.clone().normalize()).normalize().multiplyScalar(s);if(i.set([c.x+f.x,c.y+f.y,c.z+f.z],l*6),i.set([c.x-f.x,c.y-f.y,c.z-f.z],l*6+3),l<r.length-1){const p=l*2;n.push(p,p+1,p+2,p+1,p+3,p+2)}});const o=new ae;return o.setAttribute("position",new te(i,3)),o.setIndex(n),o}dispose(){for(const t of this.object.children)t.geometry.dispose();this.core.dispose(),this.glow.dispose(),this.object.removeFromParent()}}class Ii{static MIN_INTERVAL_S=8;static MAX_INTERVAL_S=25;static SEVERE_MIN_INTERVAL_S=2;static SEVERE_MAX_INTERVAL_S=8;static CLOUD_TO_GROUND_FRACTION=.25;static MIN_DISTANCE_M=1e3;static MAX_DISTANCE_M=15e3;static INTERSTROKE_MS=60;static STROKE_DECAY_MS=40;static SOUND_SPEED_M_S=343;static schedule(t){const e=new pd(t.seed),i=[],{minS:n,maxS:s}=Ii.intervalFor(t.intensity??.5);let r=e.between(0,s)*1e3;for(;r<t.durationMs;){const o=e.next()<Ii.CLOUD_TO_GROUND_FRACTION,c=Ii.MIN_DISTANCE_M,l=Ii.MAX_DISTANCE_M,h=Math.sqrt(e.between(c*c,l*l)),u=o?1+Math.floor(e.next()*4):1,d=[];let f=0;for(let p=0;p<u;p++)d.push({offsetMs:f,intensity:p===0?1:e.between(.4,.9)}),f+=Ii.INTERSTROKE_MS*e.between(.5,1.6);i.push({t:r,azimuthDeg:e.between(0,360),distanceM:h,cloudToGround:o,strokes:d,channelSeed:Math.floor(e.next()*2**31)}),r+=e.between(n,s)*1e3}return i}static intervalFor(t){const e=Math.min(1,Math.max(0,(t-.5)/.5));return{minS:Ii.MIN_INTERVAL_S-e*(Ii.MIN_INTERVAL_S-Ii.SEVERE_MIN_INTERVAL_S),maxS:Ii.MAX_INTERVAL_S-e*(Ii.MAX_INTERVAL_S-Ii.SEVERE_MAX_INTERVAL_S)}}static brightnessAt(t,e){let i=0;for(const n of t.strokes){const s=e-t.t-n.offsetMs;s<0||s>Ii.STROKE_DECAY_MS*6||(i+=n.intensity*Math.exp(-s/Ii.STROKE_DECAY_MS))}return Math.min(1,i)}static endOf(t){const e=t.strokes[t.strokes.length-1];return t.t+e.offsetMs+Ii.STROKE_DECAY_MS*6}static thunderDelayMs(t){return t.distanceM/Ii.SOUND_SPEED_M_S*1e3}}class gn{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3067;static ANCHOR_BLUE=1.317;static B=(gn.ANCHOR_BLUE-gn.ANCHOR_RED)/(1/(gn.BLUE_NM*gn.BLUE_NM)-1/(gn.RED_NM*gn.RED_NM));static A=gn.ANCHOR_RED-gn.B/(gn.RED_NM*gn.RED_NM);static indexAt(t){return gn.A+gn.B/(t*t)}}class gl{normals=new Float64Array(24);offsets=new Float64Array(8);radius=1;set(t,e,i,n,s,r){let o=0,c=0,l=0;Math.abs(i)<.9?(o=-e,c=t,l=0):(o=0,c=-i,l=e);const h=Math.hypot(o,c,l)||1;o/=h,c/=h,l/=h;const u=e*l-i*c,d=i*o-t*l,f=t*c-e*o,p=s/2,v=r/2;for(let m=0;m<6;m++){const g=n+m*Math.PI/3,b=Math.cos(g),S=Math.sin(g);this.normals[m*3]=o*b+u*S,this.normals[m*3+1]=c*b+d*S,this.normals[m*3+2]=l*b+f*S,this.offsets[m]=p}this.normals[18]=t,this.normals[19]=e,this.normals[20]=i,this.offsets[6]=v,this.normals[21]=-t,this.normals[22]=-e,this.normals[23]=-i,this.offsets[7]=v,this.radius=Math.hypot(p,v)}get aimRadius(){return this.radius}trace(t,e,i,n,s,r,o){let c=-e,l=t,h=0,u=Math.hypot(c,l,h);u<1e-6&&(c=1,l=0,h=0,u=1),c/=u,l/=u,h/=u;const d=e*h-i*l,f=i*c-t*h,p=t*l-e*c,v=c*n+d*s-t*this.radius*2,m=l*n+f*s-e*this.radius*2,g=h*n+p*s-i*this.radius*2;let b=-1,S=-1/0,M=1/0;for(let J=0;J<8;J++){const it=this.normals[J*3],ot=this.normals[J*3+1],$t=this.normals[J*3+2],re=it*t+ot*e+$t*i,jt=this.offsets[J]-(it*v+ot*m+$t*g);if(re>1e-9){const $=jt/re;$<M&&(M=$)}else if(re<-1e-9){const $=jt/re;$>S&&(S=$,b=J)}else if(jt<0)return 0}if(b<0||S>=M)return 0;let x=0;const _=this.normals[b*3],E=this.normals[b*3+1],y=this.normals[b*3+2],T=-(_*t+E*e+y*i),I=Nu.reflectance(T,1,r);o[x].x=t+2*T*_,o[x].y=e+2*T*E,o[x].z=i+2*T*y,o[x].weight=I,x++;const C=1/r,P=Math.sqrt(Math.max(0,1-C*C*(1-T*T)));let B=C*t+(C*T-P)*_,W=C*e+(C*T-P)*E,O=C*i+(C*T-P)*y,H=v+t*S,U=m+e*S,q=g+i*S,Q=1-I;for(let J=0;J<gl.MAX_BOUNCES&&Q>gl.MIN_WEIGHT;J++){let it=-1,ot=1/0;for(let z=0;z<8;z++){const It=this.normals[z*3],Ut=this.normals[z*3+1],Lt=this.normals[z*3+2],_t=It*B+Ut*W+Lt*O;if(_t<=1e-9)continue;const Ht=(this.offsets[z]-(It*H+Ut*U+Lt*q))/_t;Ht>1e-9&&Ht<ot&&(ot=Ht,it=z)}if(it<0)break;const $t=this.normals[it*3],re=this.normals[it*3+1],jt=this.normals[it*3+2],$=$t*B+re*W+jt*O,rt=r*Math.sqrt(Math.max(0,1-$*$));if(H+=B*ot,U+=W*ot,q+=O*ot,rt<1){const z=Math.sqrt(Math.max(0,1-rt*rt)),It=Nu.reflectance($,r,1);if(o[x].x=r*B-(r*$-z)*$t,o[x].y=r*W-(r*$-z)*re,o[x].z=r*O-(r*$-z)*jt,o[x].weight=Q*(1-It),x++,x>=o.length)return x;Q*=It}const nt=2*$;B-=nt*$t,W-=nt*re,O-=nt*jt}return x}static MAX_BOUNCES=6;static MIN_WEIGHT=1e-4}class ii{static AZIMUTH_BINS=512;static ALTITUDE_BINS=512;static POPULATIONS=[{orientation:"tumbling",widthMicrons:50,lengthMicrons:50,share:.52},{orientation:"plate",widthMicrons:100,lengthMicrons:15,share:.27},{orientation:"column",widthMicrons:40,lengthMicrons:120,share:.19},{orientation:"parry",widthMicrons:40,lengthMicrons:120,share:.02}];static WORST_TILT_DEG=180;static BEST_TILT_DEG=.5;static SOURCE_RADIUS_DEG=.265;static UNDEVIATED_DEG=.6;crystal=new gl;emergent=Array.from({length:gl.MAX_BOUNCES+2},()=>({x:0,y:0,z:0,weight:0}));tally=new Float32Array(ii.AZIMUTH_BINS*ii.ALTITUDE_BINS*3);radiance=new Float32Array(ii.AZIMUTH_BINS*ii.ALTITUDE_BINS*3);scratch=new Float32Array(ii.AZIMUTH_BINS*ii.ALTITUDE_BINS*3);seed=1;spare=0;hasSpare=!1;altitude=0;tilt=0;alignment=0;traced=0;begin(t,e,i=2654435769){this.seed=i>>>0||1,this.hasSpare=!1,this.tally.fill(0),this.traced=0,this.altitude=t*Math.PI/180,this.alignment=Math.min(1,Math.max(0,e));const n=ii.WORST_TILT_DEG*(ii.BEST_TILT_DEG/ii.WORST_TILT_DEG)**this.alignment;this.tilt=n*Math.PI/180}trace(t){const e=ii.AZIMUTH_BINS,i=ii.ALTITUDE_BINS,n=this.tally,s=ii.SOURCE_RADIUS_DEG*Math.PI/180,r=Math.cos(ii.UNDEVIATED_DEG*Math.PI/180),o=this.altitude;for(let c=0;c<t;c++){const l=this.pickPopulation();this.orient(l,this.tilt);const h=this.random()*2*Math.PI,u=s*Math.sqrt(this.random()),d=o+u*Math.sin(h),f=u*Math.cos(h)/Math.max(.05,Math.cos(o)),p=-Math.cos(d)*Math.cos(f),v=-Math.cos(d)*Math.sin(f),m=-Math.sin(d),g=this.crystal.aimRadius,b=(this.random()*2-1)*g,S=(this.random()*2-1)*g,M=4*g*g,x=Ci.SAMPLES[this.random()*Ci.SAMPLES.length|0],_=this.crystal.trace(p,v,m,b,S,gn.indexAt(x.wavelengthNm),this.emergent);for(let E=0;E<_;E++){const y=this.emergent[E],T=Math.hypot(y.x,y.y,y.z);if(T<1e-9||y.weight<=0)continue;const I=y.x/T,C=y.y/T,P=y.z/T;if(I*p+C*v+P*m>r)continue;const B=Math.asin(Math.max(-1,Math.min(1,-P))),W=Math.abs(Math.atan2(-C,-I)),O=Math.min(e-1,W/Math.PI*e|0),U=(Math.min(i-1,(B+Math.PI/2)/Math.PI*i|0)*e+O)*3,q=y.weight*M*Ci.SAMPLES.length;n[U]+=q*x.r,n[U+1]+=q*x.g,n[U+2]+=q*x.b}}this.traced+=t}get tracedRays(){return this.traced}harvest(){const t=ii.AZIMUTH_BINS,e=ii.ALTITUDE_BINS;return this.toRadiance(t,e),this.smooth(t,e),{width:t,height:e,data:this.radiance,sourceAltitudeDeg:this.altitude*180/Math.PI,alignment:this.alignment,rays:this.traced}}compute(t,e,i,n){return this.begin(t,e,n),this.trace(i),this.harvest()}toRadiance(t,e){const i=2*Math.PI/t,n=Math.max(1,this.traced),s=4*ii.REFERENCE_MICRONS*ii.REFERENCE_MICRONS;for(let r=0;r<e;r++){const o=Math.sin(r/e*Math.PI-Math.PI/2),c=Math.sin((r+1)/e*Math.PI-Math.PI/2),l=1/(i*(c-o)*n*s);for(let h=0;h<t;h++){const u=(r*t+h)*3;this.radiance[u]=this.tally[u]*l,this.radiance[u+1]=this.tally[u+1]*l,this.radiance[u+2]=this.tally[u+2]*l}}}static REFERENCE_MICRONS=50;smooth(t,e){const i=this.scratch,n=this.radiance;i.set(n);for(let r=0;r<e;r++){const o=r*t*3;for(let c=0;c<3;c++){let l=i[o+c];for(let h=0;h<t;h++){const u=o+h*3+c,d=h+1<t?i[u+3]:i[u];n[u]=(l+2*i[u]+d)/4,l=i[u]}}}i.set(n);const s=t*3;for(let r=0;r<e;r++){const o=r>0?-s:0,c=r+1<e?s:0,l=r*s;for(let h=l;h<l+s;h++)n[h]=(i[h+o]+2*i[h]+i[h+c])/4}}pickPopulation(){const t=this.random();let e=0;for(const i of ii.POPULATIONS)if(e+=i.share,t<=e)return i;return ii.POPULATIONS[ii.POPULATIONS.length-1]}orient(t,e){const i=this.random()*2*Math.PI;let n=this.random()*2*Math.PI,s=0,r=0,o=1;switch(t.orientation){case"tumbling":{o=this.random()*2-1;const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i);break}case"plate":{o=this.spreadAboutAnAxis(e);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i);break}case"column":case"parry":{o=this.spreadAboutAPlane(e);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i),t.orientation==="parry"&&(n=Math.PI/2+this.gaussian()*e);break}}this.crystal.set(s,r,o,n,t.widthMicrons,t.lengthMicrons)}random(){this.seed=this.seed+1831565813>>>0;let t=this.seed;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}spreadAboutAnAxis(t){const e=1/Math.max(1e-6,t*t),i=Math.max(1e-12,this.random()),n=1+Math.log(i+(1-i)*Math.exp(-2*e))/e;return Math.max(-1,Math.min(1,n))}spreadAboutAPlane(t){for(let e=0;e<8;e++){const i=this.gaussian()*t;if(i>=-1&&i<=1)return i}return this.random()*2-1}gaussian(){if(this.hasSpare)return this.hasSpare=!1,this.spare;const t=Math.sqrt(-2*Math.log(Math.max(1e-12,this.random()))),e=2*Math.PI*this.random();return this.spare=t*Math.sin(e),this.hasSpare=!0,t*Math.cos(e)}}class eR{static fromRadiance(t,e){const i=kn.toHalfFloat(1);for(let n=0,s=0;s<t.length;n+=4,s+=3)e[n]=kn.toHalfFloat(t[s]),e[n+1]=kn.toHalfFloat(t[s+1]),e[n+2]=kn.toHalfFloat(t[s+2]),e[n+3]=i}}class Ui{static RADIUS=880;static RAYS=9e5;static RAYS_PER_BATCH=2e3;static BUDGET_MS=6;static URGENT_BUDGET_MS=40;static ALTITUDE_STEP_DEG=1;static ALIGNMENT_STEP=.05;static LEAP_ALTITUDE_DEG=5;static LEAP_ALIGNMENT=.25;static GAIN=.55;setCloudOffset(t){this.material.uniforms.uFieldOffset.value.copy(t)}object;material;sky=new ii;texture;texels;mappedAltitudeDeg=Number.NaN;mappedAlignment=Number.NaN;tracing=!1;everDisplayed=!1;urgent=!1;workHandle;onRepaint;constructor(){const t=ii.AZIMUTH_BINS,e=ii.ALTITUDE_BINS;this.texels=new Uint16Array(t*e*4),this.texture=new Vs(this.texels,t,e,Gi,qe),this.texture.minFilter=de,this.texture.magFilter=de,this.texture.wrapS=Bi,this.texture.wrapT=Bi,this.texture.needsUpdate=!0,this.material=new Me({uniforms:{uSource:{value:new R(0,1,0)},uUp:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,.97,.92)},uIceCover:{value:0},uIceHeight:{value:1},uFieldOffset:{value:new R},uMap:{value:this.texture},uGain:{value:Ui.GAIN}},vertexShader:`
8033
+ `,depthTest:!1,depthWrite:!1}),this.quadScene.add(new At(new dn(2,2),this.material))}render(t,e,i,n,s,r){const o=t.getRenderTarget(),c=r??{scene:this.scene,overlay:this.overlay};t.setRenderTarget(c.scene),t.render(e,i),s?.(),(n||r)&&(Ke.clearTransparent(t,c.overlay),n?.()),t.setRenderTarget(o),!r&&(this.material.uniforms.uMode.value=On.Finished,t.render(this.quadScene,this.quadCamera))}resize(t,e){this.scene.setSize(Math.max(1,t),Math.max(1,e)),this.overlay.setSize(Math.max(1,t),Math.max(1,e))}dispose(){this.scene.dispose(),this.overlay.dispose(),this.material.dispose(),this.quadScene.children[0].geometry.dispose()}}class _e{static MIN_RATIO=1;static STEP=.25;static MIN_SHARE_OF_DISPLAY=.75;static GPU_LATE_MS=12;static GPU_ROOM_MS=6;static INTERVAL_LATE_MS=21;static LOWER_COOLDOWN_MS=750;static RAISE_COOLDOWN_MS=2e3;static PROBE_WATCH_MS=2e3;static PROBE_EVERY_MS=6e3;static PROBE_BACKOFF_MS=3e4;ratio;maxRatio;timer;intervalMs;lastChangeMs=-1/0;nextProbeMs=0;probe;constructor(t,e){this.maxRatio=_e.clamp(t),this.ratio=this.maxRatio,this.timer=e?Gu.create(e):void 0}get pixelRatio(){return this.ratio}static SETTLE_MS=400;static SUSTAINED_MS=100;lastEditMs=-1/0;editStreakStartMs=-1/0;wasChanging=!1;noteChange(t){t-this.lastEditMs>_e.SETTLE_MS&&(this.editStreakStartMs=t),this.lastEditMs=t}changing(t){return t-this.lastEditMs<=_e.SETTLE_MS&&this.lastEditMs-this.editStreakStartMs>=_e.SUSTAINED_MS}ratioFor(t,e){return this.changing(t)?this.wasChanging?(this.update(t,e),this.ratio):(this.wasChanging=!0,this.reset(),this.ratio):(this.wasChanging=!1,this.maxRatio)}get timesGpu(){return this.timer!==void 0}set maximum(t){this.maxRatio=_e.clamp(t),this.ratio>this.maxRatio&&(this.ratio=this.maxRatio),this.ratio<this.minimum&&(this.ratio=Math.min(this.maxRatio,this.minimum))}get minimum(){const t=Math.floor(this.maxRatio*_e.MIN_SHARE_OF_DISPLAY/_e.STEP)*_e.STEP;return Math.max(_e.MIN_RATIO,t)}get maximum(){return this.maxRatio}beginDrawing(){this.timer?.begin()}endDrawing(){this.timer?.end()}reset(){this.intervalMs=void 0,this.probe=void 0,this.timer?.reset()}update(t,e){const i=this.timer?.poll();if(!(this.timer&&i===void 0))return i!==void 0?this.followGpu(t,i):this.followIntervals(t,e)}followGpu(t,e){if(e>_e.GPU_LATE_MS)return this.lower(t,_e.LOWER_COOLDOWN_MS);if(e<_e.GPU_ROOM_MS)return this.raise(t,_e.RAISE_COOLDOWN_MS)}followIntervals(t,e){if(!(e>0)||e>1e3)return;this.intervalMs=this.intervalMs===void 0?e:this.intervalMs*.9+e*.1;const i=this.intervalMs>_e.INTERVAL_LATE_MS;if(this.probe){if(i)return this.ratio=this.probe.ratioBefore,this.probe=void 0,this.lastChangeMs=t,this.nextProbeMs=t+_e.PROBE_BACKOFF_MS,this.ratio;t-this.probe.sinceMs>=_e.PROBE_WATCH_MS&&(this.probe=void 0,this.nextProbeMs=t+_e.PROBE_EVERY_MS);return}if(i){const n=this.lower(t,_e.LOWER_COOLDOWN_MS);return n!==void 0&&(this.nextProbeMs=t+_e.PROBE_EVERY_MS),n}if(this.ratio<this.maxRatio&&t>=this.nextProbeMs&&t-this.lastChangeMs>=_e.RAISE_COOLDOWN_MS){const n=this.ratio,s=this.raise(t,0);return s!==void 0&&(this.probe={sinceMs:t,ratioBefore:n}),s}}lower(t,e){if(!(this.ratio<=this.minimum||t-this.lastChangeMs<e))return this.ratio=Math.max(this.minimum,_e.clamp(this.ratio-_e.STEP)),this.lastChangeMs=t,this.ratio}raise(t,e){if(!(this.ratio>=this.maxRatio||t-this.lastChangeMs<e))return this.ratio=Math.min(this.maxRatio,_e.clamp(this.ratio+_e.STEP)),this.lastChangeMs=t,this.ratio}static clamp(t){return Number.isFinite(t)?Math.max(_e.MIN_RATIO,Math.round(t/_e.STEP)*_e.STEP):_e.MIN_RATIO}}class Gu{constructor(t,e){this.gl=t,this.extension=e}static IN_FLIGHT_MAX=8;static create(t){if(!(t instanceof WebGL2RenderingContext))return;const e=t.getExtension("EXT_disjoint_timer_query_webgl2");return e?new Gu(t,e):void 0}pending=[];active;smoothedMs;begin(){if(!(this.active||this.pending.length>=Gu.IN_FLIGHT_MAX))try{const t=this.gl.createQuery();if(!t)return;this.gl.beginQuery(this.extension.TIME_ELAPSED_EXT,t),this.active=t}catch{this.active=void 0}}end(){if(this.active){try{this.gl.endQuery(this.extension.TIME_ELAPSED_EXT),this.pending.push(this.active)}catch{}this.active=void 0}}poll(){const t=this.gl;try{for(let e=0;e<this.pending.length;e++){const i=this.pending[e];if(!t.getQueryParameter(i,t.QUERY_RESULT_AVAILABLE))continue;if(!t.getParameter(this.extension.GPU_DISJOINT_EXT)){const s=t.getQueryParameter(i,t.QUERY_RESULT)/1e6;this.smoothedMs=this.smoothedMs===void 0?s:this.smoothedMs*.8+s*.2}t.deleteQuery(i),this.pending.splice(e,1),e--}}catch{this.pending.length=0}return this.smoothedMs}reset(){this.smoothedMs=void 0}}class Se{static ICE_INDEX_RED=1.3067;static ICE_INDEX_BLUE=1.317;static SIDE_PRISM_ANGLE_DEG=60;static END_PRISM_ANGLE_DEG=90;static get PARHELIA_MAX_SUN_ALTITUDE_DEG(){const t=Se.ICE_INDEX_RED,e=Math.sqrt((4-t*t)/3);return Math.asin(Math.min(1,e))*180/Math.PI}static minimumDeviationDeg(t,e){const i=t*Math.PI/180,n=e*Math.sin(i/2);return n>1?Number.NaN:(2*Math.asin(n)-i)*180/Math.PI}static effectiveIndex(t,e){const i=e*Math.PI/180,n=Math.cos(i);return n<=0?Number.POSITIVE_INFINITY:Math.sqrt(t*t-Math.sin(i)**2)/n}static parheliaAzimuthDeg(t,e=Se.ICE_INDEX_RED){const i=Se.minimumDeviationDeg(Se.SIDE_PRISM_ANGLE_DEG,Se.effectiveIndex(e,t));return Number.isFinite(i)?i:void 0}static parheliaDistanceDeg(t,e=Se.ICE_INDEX_RED){const i=Se.parheliaAzimuthDeg(t,e);if(i===void 0)return;const n=t*Math.PI/180,s=Math.sin(n)**2,r=Math.cos(n)**2*Math.cos(i*Math.PI/180);return Math.acos(Math.max(-1,Math.min(1,s+r)))*180/Math.PI}static get PLATE_END_FACE_LIMIT_DEG(){const t=Se.ICE_INDEX_RED;return Math.asin(Math.min(1,Math.sqrt(t*t-1)))*180/Math.PI}static circumzenithalAltitudeDeg(t,e=Se.ICE_INDEX_RED){if(t<0||t>90-Se.PLATE_END_FACE_LIMIT_DEG)return;const i=Math.cos(t*Math.PI/180),n=Math.sqrt(e*e-i*i);if(!(n>=1))return Math.asin(n)*180/Math.PI}static DECK_HEIGHT_M=8e3;static deckLitUntilDeg(t){return Math.acos(6371e3/(6371e3+Math.max(0,t)))*180/Math.PI}static halo22(){return Se.ringOf("halo22",Se.SIDE_PRISM_ANGLE_DEG)}static halo46(){return Se.ringOf("halo46",Se.END_PRISM_ANGLE_DEG)}static ringOf(t,e){const i=Se.minimumDeviationDeg(e,Se.ICE_INDEX_RED),n=Se.minimumDeviationDeg(e,Se.ICE_INDEX_BLUE);return{id:t,angleDeg:(i+n)/2,redAngleDeg:i,blueAngleDeg:n}}static strength(t,e,i=90,n=0){const s=Math.max(0,Math.min(1,t)),r=Math.max(0,1-Math.max(0,Math.min(1,e))),o=i>=0?1:n<=0?0:Math.max(0,1+i/n);return s*r*o}static formsAt(t,e=0){if(t<=-e)return[];const i=[Se.halo22(),Se.halo46()],n=t>0?Se.parheliaDistanceDeg(t):void 0;n!==void 0&&i.push({id:"parhelia",angleDeg:n,redAngleDeg:n,blueAngleDeg:Se.parheliaDistanceDeg(t,Se.ICE_INDEX_BLUE)}),i.push({id:"tangentArc",angleDeg:Se.halo22().angleDeg}),t>0&&i.push({id:"parhelicCircle",angleDeg:t});const s=Se.circumzenithalAltitudeDeg(t);return s!==void 0&&i.push({id:"circumzenithal",angleDeg:s}),t>Se.PLATE_END_FACE_LIMIT_DEG&&i.push({id:"circumhorizontal"}),t<Se.PILLAR_MAX_SOURCE_ALTITUDE_DEG&&i.push({id:"pillar"}),i}static PILLAR_MAX_SOURCE_ALTITUDE_DEG=20}class Tn{static get WATER_INDEX_RED(){return zi.indexAt(zi.RED_NM)}static get WATER_INDEX_BLUE(){return zi.indexAt(zi.BLUE_NM)}static radiusDeg(t,e){const i=(e*e-1)/(t*t-1);if(i<0||i>1)return Number.NaN;const n=Math.acos(Math.sqrt(i)),s=Math.asin(Math.sin(n)/e),r=2*(n-s)+(t-1)*(Math.PI-2*s),o=2*Math.PI;let c=r%o;return c<0&&(c+=o),c>Math.PI&&(c=o-c),180-c*180/Math.PI}static primary(){return Tn.bowOf("primary",2,0)}static secondary(){return Tn.bowOf("secondary",3,0)}static bowOf(t,e,i){const n=Tn.radiusDeg(e,Tn.WATER_INDEX_RED),s=Tn.radiusDeg(e,Tn.WATER_INDEX_BLUE),r=(n+s)/2;return{id:t,radiusDeg:r,redRadiusDeg:n,violetRadiusDeg:s,topAltitudeDeg:r-i}}static alexandersBandDeg(){return{fromDeg:Tn.primary().redRadiusDeg,toDeg:Tn.secondary().redRadiusDeg}}static formsAt(t){return t<0?[]:[Tn.bowOf("primary",2,t),Tn.bowOf("secondary",3,t)].filter(e=>e.topAltitudeDeg>0)}static FULL_MOON_MAGNITUDE=-12.7;static moonlightShare(t){return Math.min(1,10**(-.4*(t-Tn.FULL_MOON_MAGNITUDE)))}static strength(t,e,i){if(i<=0)return 0;const n=Math.max(0,Math.min(1,t)),s=Math.max(0,1-Math.max(0,Math.min(1,e)));return n*s}}class Rn{constructor(t){this.radius=t;const e=Rn.SEGMENTS*Rn.VERTICES_PER_SEGMENT;this.positions=new Float32Array(e*3),this.colors=new Float32Array(e*3);const i=new ae;i.setAttribute("position",new te(this.positions,3)),i.setAttribute("color",new te(this.colors,3)),i.setDrawRange(0,0),this.object=new At(i,$n.material()),this.object.frustumCulled=!1,$n.track(this.object)}static POINTS=24;static SEGMENTS=Rn.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(Rn.ACROSS-1)*6;static HEAD_HALF_WIDTH_DEG=.15;static SPREAD_FRACTION=.05;static FADE_POWER=1.8;object;positions;colors;head;tip;brightness=0;set(t,e,i){this.head=t&&Xe(t.altitudeDeg,t.azimuthDeg,1),this.tip=e&&Xe(e.altitudeDeg,e.azimuthDeg,1),this.brightness=i,this.rebuild()}rebuild(){const t=this.object.geometry,e=this.head,i=this.tip;if(!e||!i||this.brightness<=0){t.setDrawRange(0,0);return}const n=this.angleBetween(e,i);if(n<=0){t.setDrawRange(0,0);return}const s=n*Rn.SPREAD_FRACTION*Math.PI/180,r=h=>this.scale(this.slerp(e,i,h),this.radius),o=h=>this.radius*(Rn.HEAD_HALF_WIDTH_DEG*Math.PI/180+s*h),c=h=>this.brightness*(1-h)**Rn.FADE_POWER;let l=0;for(let h=1;h<Rn.POINTS;h++){const u=(h-1)/Rn.SEGMENTS,d=h/Rn.SEGMENTS;l=this.pushBand(l,r(u),r(d),o(u),o(d),c(u),c(d))}t.setDrawRange(0,l),t.getAttribute("position").needsUpdate=!0,t.getAttribute("color").needsUpdate=!0}pushBand(t,e,i,n,s,r,o){const c=this.normalise(this.cross(this.normalise(e),this.normalise(this.subtract(i,e))));for(let l=0;l<Rn.ACROSS-1;l++){const h=l-1,u=l,d=this.across(e,c,n,h),f=this.across(i,c,s,h),p=this.across(e,c,n,u),v=this.across(i,c,s,u),m=(g,b)=>g===0?b:0;t=this.push(t,d,m(h,r)),t=this.push(t,f,m(h,o)),t=this.push(t,p,m(u,r)),t=this.push(t,f,m(h,o)),t=this.push(t,v,m(u,o)),t=this.push(t,p,m(u,r))}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i){const n=t*3;this.positions[n]=e.x,this.positions[n+1]=e.y,this.positions[n+2]=e.z;const s=Rt.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[n]=s*.55,this.colors[n+1]=s*.75,this.colors[n+2]=s,t+1}slerp(t,e,i){const n=this.angleBetweenRadians(t,e);if(n<1e-9)return t;const s=Math.sin(n),r=Math.sin((1-i)*n)/s,o=Math.sin(i*n)/s;return{x:t.x*r+e.x*o,y:t.y*r+e.y*o,z:t.z*r+e.z*o}}angleBetween(t,e){return this.angleBetweenRadians(t,e)*180/Math.PI}angleBetweenRadians(t,e){const i=t.x*e.x+t.y*e.y+t.z*e.z;return Math.acos(Math.min(1,Math.max(-1,i)))}scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class tR{object=new Ee;radius;tiers;drawn=[];constructor(t){this.radius=t,this.object.name="satellites",this.tiers=Vo.map(e=>{const i=new In(new ae,Ct.material(e.size));return Ct.track(i),i.frustumCulled=!1,this.object.add(i),i})}set(t,e,i,n){const s=this.tiers.map(()=>[]);this.drawn=[];for(const r of t){if(r.magnitude>e)continue;const o=i(r.position);if(o<=0)continue;const c=r.magnitude-2.5*Math.log10(o);if(c>e)continue;const l=Po(c,e),h=tm(l),{x:u,y:d,z:f}=Xe(r.position.altitudeDeg,r.position.azimuthDeg,this.radius),[p,v,m]=n(r.position,c);s[h].push({x:u,y:d,z:f,r:p,g:v,b:m,seed:r.norad*.6180339887%1}),this.drawn.push({satellite:r,direction:new R(u,d,f).normalize()})}this.tiers.forEach((r,o)=>{const c=s[o],l=new Float32Array(c.length*3),h=new Float32Array(c.length*3),u=new Float32Array(c.length);c.forEach((f,p)=>{l.set([f.x,f.y,f.z],p*3),h.set([f.r,f.g,f.b],p*3),u[p]=f.seed}),r.geometry.dispose();const d=new ae;d.setAttribute("position",new te(l,3)),d.setAttribute("color",new te(h,3)),d.setAttribute("seed",new te(u,1)),r.geometry=d})}get count(){return this.drawn.length}nearest(t,e){let i,n=e;for(const s of this.drawn){const r=s.direction.dot(t);r>n&&(n=r,i=s.satellite)}return i}dispose(){for(const t of this.tiers)t.geometry.dispose(),t.material.dispose();this.object.removeFromParent(),this.drawn=[]}}class mn{static RADIUS=840;static MAX_SEGMENTS=256;static VERTICES_PER_SEGMENT=12;static MIN_HALF_WIDTH_DEG=.05;static BRIGHT_HALF_WIDTH_DEG=.22;static TRAIN_SHARE=.6;object=new Ee;tiers;trains;positions;colors;shown=0;constructor(){this.object.name="reentries",this.tiers=Vo.map(i=>{const n=new In(new ae,Ct.material(i.size,!1));return Ct.track(n),n.frustumCulled=!1,this.object.add(n),n});const t=mn.MAX_SEGMENTS*mn.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const e=new ae;e.setAttribute("position",new te(this.positions,3)),e.setAttribute("color",new te(this.colors,3)),e.setDrawRange(0,0),this.trains=new At(e,$n.material()),this.trains.frustumCulled=!1,$n.track(this.trains),this.object.add(this.trains)}get count(){return this.shown}set(t,e,i,n){const s=this.tiers.map(()=>[]);let r=0,o=0;const c=new st;for(const h of t){const u=i(h.head);if(u<=0)continue;const d=h.magnitude-2.5*Math.log10(u);if(d>e)continue;o++,c.set(h.color);const f=Po(d,e),{x:p,y:v,z:m}=Xe(h.head.altitudeDeg,h.head.azimuthDeg,mn.RADIUS),[g,b,S]=n(h.head,d),M=Math.max(c.r,c.g,c.b)||1;s[tm(f)].push({x:p,y:v,z:m,r:g*c.r/M,g:b*c.g/M,b:S*c.b/M}),r=this.pushTrain(r,h.train,f,c)}this.shown=o,this.tiers.forEach((h,u)=>{const d=s[u],f=new Float32Array(d.length*3),p=new Float32Array(d.length*3);d.forEach((m,g)=>{f.set([m.x,m.y,m.z],g*3),p.set([m.r,m.g,m.b],g*3)}),h.geometry.dispose();const v=new ae;v.setAttribute("position",new te(f,3)),v.setAttribute("color",new te(p,3)),h.geometry=v});const l=this.trains.geometry;l.setDrawRange(0,r),l.getAttribute("position").needsUpdate=!0,l.getAttribute("color").needsUpdate=!0}pushTrain(t,e,i,n){const s=e.length-1;for(let r=0;r<s;r++){if(t+mn.VERTICES_PER_SEGMENT>mn.MAX_SEGMENTS*mn.VERTICES_PER_SEGMENT)return t;const o=1-r/s,c=1-(r+1)/s,l=Xe(e[r].altitudeDeg,e[r].azimuthDeg,mn.RADIUS),h=Xe(e[r+1].altitudeDeg,e[r+1].azimuthDeg,mn.RADIUS),u=f=>mn.RADIUS*((mn.MIN_HALF_WIDTH_DEG+mn.BRIGHT_HALF_WIDTH_DEG*i*f)*Math.PI/180),d=f=>mn.TRAIN_SHARE*i*f**1.6;t=this.pushRibbon(t,l,h,u(o),u(c),d(o),d(c),n)}return t}pushRibbon(t,e,i,n,s,r,o,c){const l={x:i.x-e.x,y:i.y-e.y,z:i.z-e.z};if(Math.hypot(l.x,l.y,l.z)<1e-9)return t;const h=this.normalise(this.cross(this.normalise(e),this.normalise(l)));for(const[u,d]of[[-1,0],[0,1]]){const f=this.across(e,h,n,u),p=this.across(i,h,s,u),v=this.across(e,h,n,d),m=this.across(i,h,s,d),g=(b,S)=>b===0?S:0;t=this.push(t,f,g(u,r),c),t=this.push(t,p,g(u,o),c),t=this.push(t,v,g(d,r),c),t=this.push(t,p,g(u,o),c),t=this.push(t,m,g(d,o),c),t=this.push(t,v,g(d,r),c)}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i,n){const s=t*3;this.positions[s]=e.x,this.positions[s+1]=e.y,this.positions[s+2]=e.z;const r=Rt.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[s]=r*n.r,this.colors[s+1]=r*n.g,this.colors[s+2]=r*n.b,t+1}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){for(const t of this.tiers)t.geometry.dispose(),t.material.dispose();this.trains.geometry.dispose(),this.trains.material.dispose(),this.object.removeFromParent()}}class pd{constructor(t){this.state=t}next(){this.state=this.state+1831565813|0;let t=this.state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}between(t,e){return t+this.next()*(e-t)}}class ka{static MIN_DURATION_MS=250;static MAX_DURATION_MS=1400;static schedule(t){const{ratePerHour:e,durationMs:i,velocityKmS:n,seed:s}=t;if(e<=0||i<=0)return[];const r=e*i/36e5,o=new pd(s),c=Math.floor(r),l=c+(o.next()<r-c?1:0),h=[];for(let u=0;u<l;u++){const d=Math.min(1,Math.max(0,(n-20)/52)),f=ka.MAX_DURATION_MS-d*(ka.MAX_DURATION_MS-ka.MIN_DURATION_MS),p=o.between(5,70);h.push({t:o.between(0,i),durationMs:f*o.between(.7,1.3),fromRadiantDeg:p,bearingDeg:o.between(0,360),lengthDeg:Math.sin(p*Math.PI/180)*o.between(8,40)*(.6+d),brightness:o.next()**3}),h.sort((v,m)=>v.t-m.t)}return h}static aliveAt(t,e){return t.filter(i=>e>=i.t&&e<=i.t+i.durationMs).map(i=>({meteor:i,progress:(e-i.t)/i.durationMs}))}}class Pr{object=new Ee;radius;core;glow;flashKey;static CORE_WIDTH_DEG=.06;static GLOW_WIDTH_DEG=.5;static SEGMENTS=28;static CORE_RELATIVE=1e3;constructor(t){this.radius=t,this.object.name="lightning-bolt",this.core=new wn({color:15659775,transparent:!0,opacity:0,blending:Ti,depthWrite:!1,fog:!1}),this.glow=new wn({color:10466559,transparent:!0,opacity:0,blending:Ti,depthWrite:!1,fog:!1}),this.object.visible=!1,this.object.renderOrder=5.95}set(t,e,i){if(!t||!t.cloudToGround||e<=.01){this.object.visible=!1;return}const n=`${t.channelSeed}:${Math.round(i)}`;n!==this.flashKey&&this.build(t,i,n),this.core.color.setHex(15659775).multiplyScalar(Pr.CORE_RELATIVE*Math.min(1,e*1.4)),this.glow.color.setHex(10466559).multiplyScalar(.1*Pr.CORE_RELATIVE*e*.35),this.core.opacity=1,this.glow.opacity=1,this.object.visible=!0}build(t,e,i){this.flashKey=i;for(const l of[...this.object.children])l.geometry.dispose(),this.object.remove(l);const n=new pd(t.channelSeed),s=Math.atan2(e,t.distanceM)*180/Math.PI,r=this.channel(n,t.azimuthDeg,s,0,1),o=[r],c=1+Math.floor(n.next()*2);for(let l=0;l<c;l++){const h=r[Math.floor(n.between(.15,.5)*r.length)];o.push(this.channel(n,h.azimuthDeg,h.altitudeDeg,h.altitudeDeg*n.between(.3,.7),.5))}for(const l of o)this.object.add(new At(this.ribbon(l,Pr.GLOW_WIDTH_DEG),this.glow)),this.object.add(new At(this.ribbon(l,Pr.CORE_WIDTH_DEG),this.core))}channel(t,e,i,n,s){const r=[],o=i-n;let c=e;for(let l=0;l<=Pr.SEGMENTS;l++){const h=i-o*l/Pr.SEGMENTS;r.push({azimuthDeg:c,altitudeDeg:h}),c+=t.between(-1,1)*o*.06*s}return r}ribbon(t,e){const i=new Float32Array(t.length*2*3),n=[],s=this.radius*Math.tan(e*Math.PI/180)/2,r=t.map(c=>{const{x:l,y:h,z:u}=Xe(c.altitudeDeg,c.azimuthDeg,this.radius);return new R(l,h,u)});r.forEach((c,l)=>{const h=r[Math.min(l+1,r.length-1)],u=r[Math.max(l-1,0)],f=h.clone().sub(u).normalize().cross(c.clone().normalize()).normalize().multiplyScalar(s);if(i.set([c.x+f.x,c.y+f.y,c.z+f.z],l*6),i.set([c.x-f.x,c.y-f.y,c.z-f.z],l*6+3),l<r.length-1){const p=l*2;n.push(p,p+1,p+2,p+1,p+3,p+2)}});const o=new ae;return o.setAttribute("position",new te(i,3)),o.setIndex(n),o}dispose(){for(const t of this.object.children)t.geometry.dispose();this.core.dispose(),this.glow.dispose(),this.object.removeFromParent()}}class Ci{static MIN_INTERVAL_S=8;static MAX_INTERVAL_S=25;static SEVERE_MIN_INTERVAL_S=2;static SEVERE_MAX_INTERVAL_S=8;static CLOUD_TO_GROUND_FRACTION=.25;static MIN_DISTANCE_M=1e3;static MAX_DISTANCE_M=15e3;static INTERSTROKE_MS=60;static STROKE_DECAY_MS=40;static SOUND_SPEED_M_S=343;static schedule(t){const e=new pd(t.seed),i=[],{minS:n,maxS:s}=Ci.intervalFor(t.intensity??.5);let r=e.between(0,s)*1e3;for(;r<t.durationMs;){const o=e.next()<Ci.CLOUD_TO_GROUND_FRACTION,c=Ci.MIN_DISTANCE_M,l=Ci.MAX_DISTANCE_M,h=Math.sqrt(e.between(c*c,l*l)),u=o?1+Math.floor(e.next()*4):1,d=[];let f=0;for(let p=0;p<u;p++)d.push({offsetMs:f,intensity:p===0?1:e.between(.4,.9)}),f+=Ci.INTERSTROKE_MS*e.between(.5,1.6);i.push({t:r,azimuthDeg:e.between(0,360),distanceM:h,cloudToGround:o,strokes:d,channelSeed:Math.floor(e.next()*2**31)}),r+=e.between(n,s)*1e3}return i}static intervalFor(t){const e=Math.min(1,Math.max(0,(t-.5)/.5));return{minS:Ci.MIN_INTERVAL_S-e*(Ci.MIN_INTERVAL_S-Ci.SEVERE_MIN_INTERVAL_S),maxS:Ci.MAX_INTERVAL_S-e*(Ci.MAX_INTERVAL_S-Ci.SEVERE_MAX_INTERVAL_S)}}static brightnessAt(t,e){let i=0;for(const n of t.strokes){const s=e-t.t-n.offsetMs;s<0||s>Ci.STROKE_DECAY_MS*6||(i+=n.intensity*Math.exp(-s/Ci.STROKE_DECAY_MS))}return Math.min(1,i)}static endOf(t){const e=t.strokes[t.strokes.length-1];return t.t+e.offsetMs+Ci.STROKE_DECAY_MS*6}static thunderDelayMs(t){return t.distanceM/Ci.SOUND_SPEED_M_S*1e3}}class gn{static RED_NM=656.3;static BLUE_NM=435.8;static ANCHOR_RED=1.3067;static ANCHOR_BLUE=1.317;static B=(gn.ANCHOR_BLUE-gn.ANCHOR_RED)/(1/(gn.BLUE_NM*gn.BLUE_NM)-1/(gn.RED_NM*gn.RED_NM));static A=gn.ANCHOR_RED-gn.B/(gn.RED_NM*gn.RED_NM);static indexAt(t){return gn.A+gn.B/(t*t)}}class gl{normals=new Float64Array(24);offsets=new Float64Array(8);radius=1;set(t,e,i,n,s,r){let o=0,c=0,l=0;Math.abs(i)<.9?(o=-e,c=t,l=0):(o=0,c=-i,l=e);const h=Math.hypot(o,c,l)||1;o/=h,c/=h,l/=h;const u=e*l-i*c,d=i*o-t*l,f=t*c-e*o,p=s/2,v=r/2;for(let m=0;m<6;m++){const g=n+m*Math.PI/3,b=Math.cos(g),S=Math.sin(g);this.normals[m*3]=o*b+u*S,this.normals[m*3+1]=c*b+d*S,this.normals[m*3+2]=l*b+f*S,this.offsets[m]=p}this.normals[18]=t,this.normals[19]=e,this.normals[20]=i,this.offsets[6]=v,this.normals[21]=-t,this.normals[22]=-e,this.normals[23]=-i,this.offsets[7]=v,this.radius=Math.hypot(p,v)}get aimRadius(){return this.radius}trace(t,e,i,n,s,r,o){let c=-e,l=t,h=0,u=Math.hypot(c,l,h);u<1e-6&&(c=1,l=0,h=0,u=1),c/=u,l/=u,h/=u;const d=e*h-i*l,f=i*c-t*h,p=t*l-e*c,v=c*n+d*s-t*this.radius*2,m=l*n+f*s-e*this.radius*2,g=h*n+p*s-i*this.radius*2;let b=-1,S=-1/0,M=1/0;for(let J=0;J<8;J++){const it=this.normals[J*3],ot=this.normals[J*3+1],$t=this.normals[J*3+2],re=it*t+ot*e+$t*i,jt=this.offsets[J]-(it*v+ot*m+$t*g);if(re>1e-9){const $=jt/re;$<M&&(M=$)}else if(re<-1e-9){const $=jt/re;$>S&&(S=$,b=J)}else if(jt<0)return 0}if(b<0||S>=M)return 0;let x=0;const _=this.normals[b*3],E=this.normals[b*3+1],y=this.normals[b*3+2],T=-(_*t+E*e+y*i),I=Nu.reflectance(T,1,r);o[x].x=t+2*T*_,o[x].y=e+2*T*E,o[x].z=i+2*T*y,o[x].weight=I,x++;const C=1/r,P=Math.sqrt(Math.max(0,1-C*C*(1-T*T)));let B=C*t+(C*T-P)*_,W=C*e+(C*T-P)*E,O=C*i+(C*T-P)*y,H=v+t*S,U=m+e*S,q=g+i*S,Q=1-I;for(let J=0;J<gl.MAX_BOUNCES&&Q>gl.MIN_WEIGHT;J++){let it=-1,ot=1/0;for(let z=0;z<8;z++){const It=this.normals[z*3],Ut=this.normals[z*3+1],Lt=this.normals[z*3+2],_t=It*B+Ut*W+Lt*O;if(_t<=1e-9)continue;const Ht=(this.offsets[z]-(It*H+Ut*U+Lt*q))/_t;Ht>1e-9&&Ht<ot&&(ot=Ht,it=z)}if(it<0)break;const $t=this.normals[it*3],re=this.normals[it*3+1],jt=this.normals[it*3+2],$=$t*B+re*W+jt*O,rt=r*Math.sqrt(Math.max(0,1-$*$));if(H+=B*ot,U+=W*ot,q+=O*ot,rt<1){const z=Math.sqrt(Math.max(0,1-rt*rt)),It=Nu.reflectance($,r,1);if(o[x].x=r*B-(r*$-z)*$t,o[x].y=r*W-(r*$-z)*re,o[x].z=r*O-(r*$-z)*jt,o[x].weight=Q*(1-It),x++,x>=o.length)return x;Q*=It}const nt=2*$;B-=nt*$t,W-=nt*re,O-=nt*jt}return x}static MAX_BOUNCES=6;static MIN_WEIGHT=1e-4}class ii{static AZIMUTH_BINS=512;static ALTITUDE_BINS=512;static POPULATIONS=[{orientation:"tumbling",widthMicrons:50,lengthMicrons:50,share:.52},{orientation:"plate",widthMicrons:100,lengthMicrons:15,share:.27},{orientation:"column",widthMicrons:40,lengthMicrons:120,share:.19},{orientation:"parry",widthMicrons:40,lengthMicrons:120,share:.02}];static WORST_TILT_DEG=180;static BEST_TILT_DEG=.5;static SOURCE_RADIUS_DEG=.265;static UNDEVIATED_DEG=.6;crystal=new gl;emergent=Array.from({length:gl.MAX_BOUNCES+2},()=>({x:0,y:0,z:0,weight:0}));tally=new Float32Array(ii.AZIMUTH_BINS*ii.ALTITUDE_BINS*3);radiance=new Float32Array(ii.AZIMUTH_BINS*ii.ALTITUDE_BINS*3);scratch=new Float32Array(ii.AZIMUTH_BINS*ii.ALTITUDE_BINS*3);seed=1;spare=0;hasSpare=!1;altitude=0;tilt=0;alignment=0;traced=0;begin(t,e,i=2654435769){this.seed=i>>>0||1,this.hasSpare=!1,this.tally.fill(0),this.traced=0,this.altitude=t*Math.PI/180,this.alignment=Math.min(1,Math.max(0,e));const n=ii.WORST_TILT_DEG*(ii.BEST_TILT_DEG/ii.WORST_TILT_DEG)**this.alignment;this.tilt=n*Math.PI/180}trace(t){const e=ii.AZIMUTH_BINS,i=ii.ALTITUDE_BINS,n=this.tally,s=ii.SOURCE_RADIUS_DEG*Math.PI/180,r=Math.cos(ii.UNDEVIATED_DEG*Math.PI/180),o=this.altitude;for(let c=0;c<t;c++){const l=this.pickPopulation();this.orient(l,this.tilt);const h=this.random()*2*Math.PI,u=s*Math.sqrt(this.random()),d=o+u*Math.sin(h),f=u*Math.cos(h)/Math.max(.05,Math.cos(o)),p=-Math.cos(d)*Math.cos(f),v=-Math.cos(d)*Math.sin(f),m=-Math.sin(d),g=this.crystal.aimRadius,b=(this.random()*2-1)*g,S=(this.random()*2-1)*g,M=4*g*g,x=Pi.SAMPLES[this.random()*Pi.SAMPLES.length|0],_=this.crystal.trace(p,v,m,b,S,gn.indexAt(x.wavelengthNm),this.emergent);for(let E=0;E<_;E++){const y=this.emergent[E],T=Math.hypot(y.x,y.y,y.z);if(T<1e-9||y.weight<=0)continue;const I=y.x/T,C=y.y/T,P=y.z/T;if(I*p+C*v+P*m>r)continue;const B=Math.asin(Math.max(-1,Math.min(1,-P))),W=Math.abs(Math.atan2(-C,-I)),O=Math.min(e-1,W/Math.PI*e|0),U=(Math.min(i-1,(B+Math.PI/2)/Math.PI*i|0)*e+O)*3,q=y.weight*M*Pi.SAMPLES.length;n[U]+=q*x.r,n[U+1]+=q*x.g,n[U+2]+=q*x.b}}this.traced+=t}get tracedRays(){return this.traced}harvest(){const t=ii.AZIMUTH_BINS,e=ii.ALTITUDE_BINS;return this.toRadiance(t,e),this.smooth(t,e),{width:t,height:e,data:this.radiance,sourceAltitudeDeg:this.altitude*180/Math.PI,alignment:this.alignment,rays:this.traced}}compute(t,e,i,n){return this.begin(t,e,n),this.trace(i),this.harvest()}toRadiance(t,e){const i=2*Math.PI/t,n=Math.max(1,this.traced),s=4*ii.REFERENCE_MICRONS*ii.REFERENCE_MICRONS;for(let r=0;r<e;r++){const o=Math.sin(r/e*Math.PI-Math.PI/2),c=Math.sin((r+1)/e*Math.PI-Math.PI/2),l=1/(i*(c-o)*n*s);for(let h=0;h<t;h++){const u=(r*t+h)*3;this.radiance[u]=this.tally[u]*l,this.radiance[u+1]=this.tally[u+1]*l,this.radiance[u+2]=this.tally[u+2]*l}}}static REFERENCE_MICRONS=50;smooth(t,e){const i=this.scratch,n=this.radiance;i.set(n);for(let r=0;r<e;r++){const o=r*t*3;for(let c=0;c<3;c++){let l=i[o+c];for(let h=0;h<t;h++){const u=o+h*3+c,d=h+1<t?i[u+3]:i[u];n[u]=(l+2*i[u]+d)/4,l=i[u]}}}i.set(n);const s=t*3;for(let r=0;r<e;r++){const o=r>0?-s:0,c=r+1<e?s:0,l=r*s;for(let h=l;h<l+s;h++)n[h]=(i[h+o]+2*i[h]+i[h+c])/4}}pickPopulation(){const t=this.random();let e=0;for(const i of ii.POPULATIONS)if(e+=i.share,t<=e)return i;return ii.POPULATIONS[ii.POPULATIONS.length-1]}orient(t,e){const i=this.random()*2*Math.PI;let n=this.random()*2*Math.PI,s=0,r=0,o=1;switch(t.orientation){case"tumbling":{o=this.random()*2-1;const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i);break}case"plate":{o=this.spreadAboutAnAxis(e);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i);break}case"column":case"parry":{o=this.spreadAboutAPlane(e);const c=Math.sqrt(Math.max(0,1-o*o));s=c*Math.cos(i),r=c*Math.sin(i),t.orientation==="parry"&&(n=Math.PI/2+this.gaussian()*e);break}}this.crystal.set(s,r,o,n,t.widthMicrons,t.lengthMicrons)}random(){this.seed=this.seed+1831565813>>>0;let t=this.seed;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}spreadAboutAnAxis(t){const e=1/Math.max(1e-6,t*t),i=Math.max(1e-12,this.random()),n=1+Math.log(i+(1-i)*Math.exp(-2*e))/e;return Math.max(-1,Math.min(1,n))}spreadAboutAPlane(t){for(let e=0;e<8;e++){const i=this.gaussian()*t;if(i>=-1&&i<=1)return i}return this.random()*2-1}gaussian(){if(this.hasSpare)return this.hasSpare=!1,this.spare;const t=Math.sqrt(-2*Math.log(Math.max(1e-12,this.random()))),e=2*Math.PI*this.random();return this.spare=t*Math.sin(e),this.hasSpare=!0,t*Math.cos(e)}}class eR{static fromRadiance(t,e){const i=kn.toHalfFloat(1);for(let n=0,s=0;s<t.length;n+=4,s+=3)e[n]=kn.toHalfFloat(t[s]),e[n+1]=kn.toHalfFloat(t[s+1]),e[n+2]=kn.toHalfFloat(t[s+2]),e[n+3]=i}}class Ui{static RADIUS=880;static RAYS=9e5;static RAYS_PER_BATCH=2e3;static BUDGET_MS=6;static URGENT_BUDGET_MS=40;static ALTITUDE_STEP_DEG=1;static ALIGNMENT_STEP=.05;static LEAP_ALTITUDE_DEG=5;static LEAP_ALIGNMENT=.25;static GAIN=.55;setCloudOffset(t){this.material.uniforms.uFieldOffset.value.copy(t)}object;material;sky=new ii;texture;texels;mappedAltitudeDeg=Number.NaN;mappedAlignment=Number.NaN;tracing=!1;everDisplayed=!1;urgent=!1;workHandle;onRepaint;constructor(){const t=ii.AZIMUTH_BINS,e=ii.ALTITUDE_BINS;this.texels=new Uint16Array(t*e*4),this.texture=new Vs(this.texels,t,e,Gi,qe),this.texture.minFilter=de,this.texture.magFilter=de,this.texture.wrapS=Bi,this.texture.wrapT=Bi,this.texture.needsUpdate=!0,this.material=new Me({uniforms:{uSource:{value:new R(0,1,0)},uUp:{value:new R(0,1,0)},uStrength:{value:0},uTint:{value:new R(1,.97,.92)},uIceCover:{value:0},uIceHeight:{value:1},uFieldOffset:{value:new R},uMap:{value:this.texture},uGain:{value:Ui.GAIN}},vertexShader:`
8034
8034
  varying vec3 vDirection;
8035
8035
  void main() {
8036
8036
  vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
@@ -8059,8 +8059,8 @@ ${Ct.OUTPUT_PROJECTION_GLSL}`)}}class nn{constructor(t,e){this.width=t,this.heig
8059
8059
  if (ice <= 0.0) discard;
8060
8060
  gl_FragColor = vec4(iceHaloLight(dir, ice), 1.0);
8061
8061
  }
8062
- `,transparent:!0,blending:Pi,depthWrite:!1,side:Qe,fog:!1}),this.object=new At(new pi(Ui.RADIUS,64,32),this.material),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1;const i=this.material.uniforms;this.deckUniforms={uSource:i.uSource,uUp:i.uUp,uStrength:i.uStrength,uTint:i.uTint,uMap:i.uMap,uGain:i.uGain,uHaloShown:{value:0}}}deckUniforms;shown=!1;hostedByDeck=!1;set hosted(t){this.hostedByDeck=t,this.show(this.shown)}show(t){this.shown=t,this.object.visible=t&&!this.hostedByDeck,this.deckUniforms.uHaloShown.value=t?1:0}get awaitingFirstDisplay(){return this.tracing&&!this.everDisplayed}setUrgent(t){this.urgent=t}set onReady(t){this.onRepaint=t}update(t,e,i,n,s,r){const o=this.material.uniforms;if(i<=0){o.uStrength.value=0,this.show(!1),this.stopWork();return}o.uSource.value.set(t.x,t.y,t.z).normalize(),o.uStrength.value=i,o.uTint.value.set(n[0],n[1],n[2]),o.uIceCover.value=s.cover,o.uIceHeight.value=s.layerHeight,this.show(this.everDisplayed),this.requestMap(e,r)}requestMap(t,e){if(!(!(Math.abs(t-this.mappedAltitudeDeg)<Ui.ALTITUDE_STEP_DEG)||!(Math.abs(e-this.mappedAlignment)<Ui.ALIGNMENT_STEP))){this.next=void 0;return}if(this.tracing){if(this.tracingFor(t,e)){this.next=void 0;return}if(!(!(Math.abs(t-this.pendingAltitudeDeg)<Ui.LEAP_ALTITUDE_DEG)||!(Math.abs(e-this.pendingAlignment)<Ui.LEAP_ALIGNMENT))){this.next={sourceAltitudeDeg:t,alignment:e};return}}this.next=void 0,this.pendingAltitudeDeg=t,this.pendingAlignment=e,this.stopWork(),this.tracing=!0,this.startTracing(t,e)}startTracing(t,e){const i=++this.ticket,n=()=>{i!==this.ticket||!this.tracing||(this.sky.begin(t,e),this.scheduleWork())};kr.with(s=>{i!==this.ticket||!this.tracing||(this.job=s.trace(t,e,Ui.RAYS,r=>{this.job=void 0,this.texels.set(r),this.display(),this.finishTracing()},n))},n)}ticket=0;job;pendingAltitudeDeg=Number.NaN;pendingAlignment=Number.NaN;next;tracingFor(t,e){return this.tracing&&Math.abs(t-this.pendingAltitudeDeg)<Ui.ALTITUDE_STEP_DEG&&Math.abs(e-this.pendingAlignment)<Ui.ALIGNMENT_STEP}scheduleWork(){if(this.workHandle!==void 0)return;const t=()=>{if(this.workHandle=void 0,!this.tracing)return;const e=performance.now(),i=this.urgent?Ui.URGENT_BUDGET_MS:Ui.BUDGET_MS;do this.sky.trace(Ui.RAYS_PER_BATCH);while(this.sky.tracedRays<Ui.RAYS&&performance.now()-e<i);if(this.sky.tracedRays>=Ui.RAYS){this.publish(),this.finishTracing();return}this.workHandle=requestAnimationFrame(t)};this.workHandle=requestAnimationFrame(t)}finishTracing(){this.tracing=!1,this.mappedAltitudeDeg=this.pendingAltitudeDeg,this.mappedAlignment=this.pendingAlignment;const t=this.next;t&&this.requestMap(t.sourceAltitudeDeg,t.alignment)}stopWork(){this.ticket++,this.job?.cancel(),this.job=void 0,this.workHandle!==void 0&&cancelAnimationFrame(this.workHandle),this.workHandle=void 0,this.tracing=!1,this.next=void 0}publish(){eR.fromRadiance(this.sky.harvest().data,this.texels),this.display()}display(){this.texture.needsUpdate=!0,this.everDisplayed=!0,this.show(this.material.uniforms.uStrength.value>0),this.onRepaint?.()}dispose(){this.stopWork(),this.texture.dispose(),this.object.geometry.dispose(),this.material.dispose()}}class Fi{static MAX_CONCURRENT=24;static POINTS=8;static SEGMENTS=Fi.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(Fi.ACROSS-1)*6;static RADIUS=840;static MIN_HALF_WIDTH_DEG=.05;static BRIGHT_HALF_WIDTH_DEG=.22;object;positions;colors;meteors=[];radiantAltitudeDeg=0;radiantAzimuthDeg=0;constructor(){const t=Fi.MAX_CONCURRENT*Fi.SEGMENTS*Fi.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const e=new ae;e.setAttribute("position",new te(this.positions,3)),e.setAttribute("color",new te(this.colors,3)),e.setDrawRange(0,0),this.object=new At(e,$n.material()),this.object.frustumCulled=!1,$n.track(this.object)}get schedule(){return this.meteors}setShower(t,e,i){this.meteors=t,this.radiantAltitudeDeg=e,this.radiantAzimuthDeg=i}update(t){const e=this.object.geometry;if(this.meteors.length===0){e.setDrawRange(0,0);return}const i=ka.aliveAt(this.meteors,t).slice(0,Fi.MAX_CONCURRENT);let n=0;for(const{meteor:s,progress:r}of i){const o=this.radiantOf(s);if(!o)continue;const c=Xe(o.altitudeDeg,o.azimuthDeg,1),[l,h]=this.basisAround(c),u=s.fromRadiantDeg+r*s.lengthDeg,d=Math.max(s.fromRadiantDeg,u-s.lengthDeg*.6),f=Math.min(1,(1-r)*2.5),p=this.turn(l,h,s.bearingDeg),v=(.15+.85*s.brightness)*f,m=S=>v*S**1.6,g=S=>this.onSphere(c,p,d+(u-d)*S),b=S=>Fi.RADIUS*((Fi.MIN_HALF_WIDTH_DEG+Fi.BRIGHT_HALF_WIDTH_DEG*s.brightness*S)*Math.PI/180);for(let S=1;S<Fi.POINTS;S++){const M=(S-1)/Fi.SEGMENTS,x=S/Fi.SEGMENTS;n=this.pushRibbon(n,g(M),g(x),b(M),b(x),m(M),m(x))}}e.setDrawRange(0,n),e.getAttribute("position").needsUpdate=!0,e.getAttribute("color").needsUpdate=!0}midpointOf(t){const e=this.radiantOf(t);if(!e)return;const i=Xe(e.altitudeDeg,e.azimuthDeg,1),[n,s]=this.basisAround(i),r=this.turn(n,s,t.bearingDeg),o=this.onSphere(i,r,t.fromRadiantDeg+t.lengthDeg/2),c=Math.hypot(o.x,o.y,o.z)||1;return{altitudeDeg:Math.asin(o.y/c)*180/Math.PI,azimuthDeg:(Math.atan2(o.x,-o.z)*180/Math.PI+360)%360}}radiantOf(t){return t.radiant?t.radiant:this.radiantAltitudeDeg>0?{altitudeDeg:this.radiantAltitudeDeg,azimuthDeg:this.radiantAzimuthDeg}:void 0}pushRibbon(t,e,i,n,s,r,o){const c=this.normalise(this.cross(this.normalise(e),this.normalise(this.subtract(i,e))));for(let l=0;l<Fi.ACROSS-1;l++){const h=l-1,u=l,d=this.across(e,c,n,h),f=this.across(i,c,s,h),p=this.across(e,c,n,u),v=this.across(i,c,s,u),m=(g,b)=>g===0?b:0;t=this.push(t,d,m(h,r)),t=this.push(t,f,m(h,o)),t=this.push(t,p,m(u,r)),t=this.push(t,f,m(h,o)),t=this.push(t,v,m(u,o)),t=this.push(t,p,m(u,r))}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i){const n=t*3;this.positions[n]=e.x,this.positions[n+1]=e.y,this.positions[n+2]=e.z;const s=Rt.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[n]=s*.9,this.colors[n+1]=s*.95,this.colors[n+2]=s,t+1}turn(t,e,i){const n=i*Math.PI/180,s=Math.cos(n),r=Math.sin(n);return{x:t.x*s+e.x*r,y:t.y*s+e.y*r,z:t.z*s+e.z*r}}onSphere(t,e,i){const n=i*Math.PI/180,s=Math.cos(n),r=Math.sin(n);return{x:(t.x*s+e.x*r)*Fi.RADIUS,y:(t.y*s+e.y*r)*Fi.RADIUS,z:(t.z*s+e.z*r)*Fi.RADIUS}}basisAround(t){const e=Math.abs(t.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=this.normalise(this.cross(t,e));return[i,this.normalise(this.cross(t,i))]}subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class We{constructor(t,e={}){this.size=t,this.span=Math.min(t.lengthM,Math.max(0,e.spanM??t.lengthM)),this.bank=(t.lengthM-this.span)/2,this.deck=Math.min(t.heightM,e.deckThicknessM??We.DEFAULT_DECK_THICKNESS_M),this.railHeight=e.railing?.heightM??We.DEFAULT_RAILING_HEIGHT_M,this.postSpacing=Math.max(.3,e.railing?.postSpacingM??We.DEFAULT_POST_SPACING_M),this.rails=Math.max(0,Math.round(e.railing?.rails??We.DEFAULT_RAILS))}static DEFAULT_DECK_THICKNESS_M=1.2;static DEFAULT_RAILING_HEIGHT_M=1.05;static DEFAULT_POST_SPACING_M=1.5;static DEFAULT_RAILS=2;static BANK_SLOPE=1.5;static ABUTMENT_THICKNESS_M=1;static POST_SIDE_M=.08;static RAIL_HEIGHT_M=.08;static RAIL_DEPTH_M=.06;static BANK_STATIONS=12;static NATURAL_SIZE=Object.freeze({widthM:9,lengthM:40,heightM:6.5});span;bank;deck;railHeight;postSpacing;rails;roadAt(t){const e=Math.abs(t)-this.span/2;return e<=0?this.size.heightM:this.bank<=0?0:Math.max(0,this.size.heightM*(1-e/this.bank))}build(){const{widthM:t,heightM:e}=this.size,i=this.span/2,n=[];if(this.span>0){n.push(We.box(t,this.deck,this.span,0,e-this.deck/2,0));for(const c of[-1,1]){const l=e-this.deck;l>0&&this.bank>0&&n.push(We.box(t+1,l,We.ABUTMENT_THICKNESS_M,0,l/2,c*(i-We.ABUTMENT_THICKNESS_M/2)))}}const s=[];this.span>0&&s.push(We.box(t,.04,this.span,0,e+.02,0));const r=[];for(const c of[-1,1])this.bank<=0||(r.push(this.embankment(c)),s.push(this.bankRoad(c)));const o=[];for(const c of[-1,1])o.push(...this.railing(c*(t/2-We.POST_SIDE_M)));return{concrete:We.merge(n),road:We.merge(s),earth:We.merge(r),railing:We.merge(o)}}embankment(t){const e=this.size.widthM/2,i=this.stations(t),n=[],s=(l,h,u,d)=>{n.push(l.x,l.y,l.z,h.x,h.y,h.z,u.x,u.y,u.z,l.x,l.y,l.z,u.x,u.y,u.z,d.x,d.y,d.z)},r=l=>{const h=this.roadAt(l),u=e+We.BANK_SLOPE*h;return{leftFoot:new R(-u,0,l),leftTop:new R(-e,h,l),rightTop:new R(e,h,l),rightFoot:new R(u,0,l)}};for(let l=1;l<i.length;l++){const h=r(i[l-1]),u=r(i[l]),d=t>0,f=(p,v,m,g)=>d?s(p,v,m,g):s(g,m,v,p);f(h.leftFoot,h.leftTop,u.leftTop,u.leftFoot),f(h.leftTop,h.rightTop,u.rightTop,u.leftTop),f(h.rightTop,h.rightFoot,u.rightFoot,u.rightTop)}const o=r(i[0]);t>0?s(o.leftFoot,o.rightFoot,o.rightTop,o.leftTop):s(o.leftTop,o.rightTop,o.rightFoot,o.leftFoot);const c=new ae;return c.setAttribute("position",new ve(n,3)),c.computeVertexNormals(),c}bankRoad(t){const e=this.size.widthM/2,i=this.stations(t),n=[];for(let r=1;r<i.length;r++){const o=i[r-1],c=i[r],l=this.roadAt(o)+.02,h=this.roadAt(c)+.02,u=t>0?[[-e,l,o],[e,l,o],[e,h,c],[-e,h,c]]:[[-e,h,c],[e,h,c],[e,l,o],[-e,l,o]];for(const d of[0,2,1,0,3,2])n.push(...u[d])}const s=new ae;return s.setAttribute("position",new ve(n,3)),s.computeVertexNormals(),s}stations(t){const e=[];for(let i=0;i<=We.BANK_STATIONS;i++)e.push(t*(this.span/2+this.bank*i/We.BANK_STATIONS));return e}railing(t){const e=this.size.lengthM/2,i=Math.max(1,Math.round(this.size.lengthM/this.postSpacing)),n=[];for(let o=0;o<=i;o++)n.push(-e+this.size.lengthM*o/i);const s=[],r=We.POST_SIDE_M;for(const o of n)s.push(We.box(r,this.railHeight,r,t,this.roadAt(o)+this.railHeight/2,o));for(let o=1;o<=this.rails;o++){const c=this.railHeight*o/this.rails-We.RAIL_HEIGHT_M/2;for(let l=1;l<n.length;l++){const h=new R(t,this.roadAt(n[l-1])+c,n[l-1]),u=new R(t,this.roadAt(n[l])+c,n[l]);s.push(We.beam(h,u))}}return s}static box(t,e,i,n,s,r){return new Vi(t,e,i).translate(n,s,r)}static beam(t,e){const i=new R().subVectors(e,t),n=new Vi(We.RAIL_DEPTH_M,We.RAIL_HEIGHT_M,i.length()),s=new Sn().setFromUnitVectors(new R(0,0,1),i.clone().normalize()),r=new R().addVectors(t,e).multiplyScalar(.5);return n.applyMatrix4(new ne().compose(r,s,new R(1,1,1)))}static merge(t){const e=t.map(c=>c.getIndex()?c.toNonIndexed():c),i=e.reduce((c,l)=>c+l.getAttribute("position").count,0),n=new Float32Array(i*3),s=new Float32Array(i*3);let r=0;for(const c of e){const l=c.getAttribute("position"),h=c.getAttribute("normal");n.set(l.array,r*3),h&&s.set(h.array,r*3),r+=l.count}const o=new ae;o.setAttribute("position",new ve(n,3)),o.setAttribute("normal",new ve(s,3));for(const c of t)c.dispose();for(const c of e)c.dispose();return o}}class Ia{constructor(t,e={}){this.size=t,this.structure=e}static DEFAULT_DIAMETER_M=.008;static POLE_RADIUS_M=.13;static POLE_ABOVE_M=.5;static NATURAL_SIZE=Object.freeze({widthM:1,lengthM:30,heightM:5});get strands(){const t=this.structure.strands;return!t||t.length===0?[{heightM:this.size.heightM,acrossM:0}]:t.map(e=>({heightM:e.heightM,acrossM:e.acrossM??0}))}get poleStations(){const t=this.size.lengthM/2;switch(this.structure.poles??"both"){case"start":return[t];case"end":return[-t];case"none":return[];default:return[-t,t]}}get poleHeightM(){return this.structure.poleHeightM??Math.max(...this.strands.map(t=>t.heightM))+Ia.POLE_ABOVE_M}build(){const t=this.structure.diameterM??Ia.DEFAULT_DIAMETER_M,e=this.strands.map(n=>{const s=new Zn(t/2,t/2,this.size.lengthM,6);return s.rotateX(Math.PI/2),s.translate(n.acrossM,n.heightM,0),s}),i=this.poleStations.map(n=>{const s=new Zn(Ia.POLE_RADIUS_M*.8,Ia.POLE_RADIUS_M,this.poleHeightM,8);return s.translate(0,this.poleHeightM/2,n),s});return{strands:e,poles:i}}}const df=Math.PI/180;function Ae(a,t,e,i,n=!1){const s=n?new wn({color:new st(...e)}):new nc({color:new st(...e)}),r=new At(t,s);return r.position.y=i,r.userData={emissive:n},r.castShadow=!n,r.receiveShadow=!n,a.add(r),r}const ff=.25,iR=.002,nR=100,sR=1500,rR=.25,aR=1e3,oR=.15;function cR(a){const t=/^#([0-9a-f]{6})$/i.exec(a);if(!t)return[1,1,1];const e=parseInt(t[1],16);return[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]}const lR=[.32,.32,.3],Z2=[1,.85,.5],hR=[.25,.25,.25],J2=[1,.97,.85],uR=[.55,.68,.72],dR=.12,Ts=.03,Rs=.05,j2={front:0,behind:Math.PI,left:Math.PI/2,right:-Math.PI/2,"front-left":Math.PI/2,"behind-left":Math.PI/2,"front-right":-Math.PI/2,"behind-right":-Math.PI/2};function cn(a,t){return a?.[t]}function Ds(a,t,e,i,n,s,r,o){if(o===void 0)return;const c=new wn({color:new st(...uR).multiplyScalar(dR),transparent:!0,opacity:o/100,depthWrite:!1}),l=new At(new Vi(t,e,i),c);l.position.set(n,s,r),l.renderOrder=2,a.add(l)}const Gn=.05,pf=[.6,.58,.53],sv=[.5,.5,.48];function No(a,t,e,i,n,s,r,o){const c=new nc({color:new st(...o),side:Qe}),l=new At(new Vi(t,e,i),c);l.position.set(n,s,r),a.add(l)}function fR(a,t,e,i,n,s,r,o,c){const l=(i-s)/2,h=(p,v,m,g)=>{p<=0||(t?No(a,p,v,Gn,m,o+g,r,c):No(a,Gn,v,p,r,o+g,m,c))};h(e,l,0,i/2-l/2),h(e,l,0,-(i/2-l/2));const u=[...n].sort((p,v)=>p.center-v.center);let d=-e/2;for(const p of u){const m=p.center-p.main/2-d;h(m,s,d+m/2,0),d=p.center+p.main/2}const f=e/2-d;h(f,s,d+f/2,0)}function Q2(a,t,e,i,n,s,r,o,c,l){const h=(i+n)/2,u=n-i,d=(f,p,v,m)=>{f.length===0?p?No(a,v,u,Gn,0,h,m,pf):No(a,Gn,u,v,m,h,0,pf):fR(a,p,v,u,f,s,m,h,pf)};d(r,!0,t*2,-e+Gn),d(o,!0,t*2,e-Gn),d(c,!1,e*2,-t+Gn),d(l,!1,e*2,t-Gn),No(a,t*2,Gn,e*2,0,i+Gn,0,sv),No(a,t*2,Gn,e*2,0,n-Gn,0,sv)}function pp(a,t,e,i){switch(a){case"front":return{x:0,z:-(e-i)};case"behind":return{x:0,z:e-i};case"left":return{x:-(t-i),z:0};case"right":return{x:t-i,z:0};case"front-left":return{x:-(t-i),z:-Is};case"front-right":return{x:t-i,z:-Is};case"behind-left":return{x:-(t-i),z:Is};case"behind-right":return{x:t-i,z:Is}}}function ty(a,t,e,i,n,s,r,o){const c=vp();c.scale.setScalar(n),c.rotation.y=j2[e];const{x:l,z:h}=pp(t,s,r,o);c.position.set(l,i,h),a.add(c)}const mp=6,gp=6,Or=3,Tc=1.4,Rc=Or*.5,ey=1.2,iy=.35,pR=.75,mR=1.6;function rv(a,t,e,i,n){const s=new Ee,r=Math.max(1,a+1),o=r*Or;Ae(s,new Vi(mp,o,gp),[.55,.54,.5],o/2);const c=mp/2,l=gp/2;for(let h=0;h<r;h++){const u=h*Or+Or/2;Ds(s,Tc,Rc,Rs,0,u,-l-Ts,cn(t,"front")),Ds(s,Tc,Rc,Rs,0,u,l+Ts,cn(t,"behind")),Ds(s,Rs,Rc,Tc,-c-Ts,u,0,cn(t,"left")),Ds(s,Rs,Rc,Tc,c+Ts,u,0,cn(t,"right"))}if(e){const h=Math.min(Math.max(i??0,0),r-1);ty(s,e,n??e,h*Or,.72,c,l,ey);const u=d=>cn(t,d)!==void 0?[{main:Tc,center:0}]:[];Q2(s,c,l,h*Or,(h+1)*Or,Rc,u("front"),u("behind"),u("left"),u("right"))}return s}function av(){const a=new Ee,t=[[0,0,.55,.5],[.4,.1,.35,.4],[-.35,-.2,.4,.38],[.1,-.4,.35,.36],[-.15,.4,.3,.34]];for(const[e,i,n,s]of t){const r=new pi(n,10,7);r.scale(1,.85,1),r.translate(e,0,i),Ae(a,r,[.26,.28,.17],s)}return a}function gR(a){const t=new Ee,e=new We(Ye.sizeOf(a),a.bridge).build();Ae(t,e.concrete,[.6,.6,.58],0);const i=Ae(t,e.road,[.2,.2,.21],0),n=Ae(t,e.earth,[.3,.36,.22],0);for(const s of[i,n])s.material.side=bn;return Ae(t,e.railing,[.5,.52,.55],0),t}function vR(a){const t=new Ee,e=new Ia(Ye.sizeOf(a),a.wire).build();for(const i of e.strands)Ae(t,i,[.1,.1,.11],0);for(const i of e.poles)Ae(t,i,[.3,.24,.18],0);return t}function ov(){const a=new Ee;return Ae(a,new Zn(.15,.22,2,8),[.32,.22,.14],1),Ae(a,new rc(1.4,3,8),[.16,.32,.14],3.5),a}const cv=.275,MR=.35,yR=.9,xR=34,bR=8,SR=1.4;function lv(){const a=new Ee,t=new pi(cv,7,3,0,Math.PI*2,0,Math.PI/2);t.scale(1,MR/cv,1);const e=Ye.repeatOnGrid(t,xR,yR,bR,SR),i=Ae(a,e,[.26,.28,.22],0);return i.castShadow=!0,i.userData.cropBasePositions=e.getAttribute("position").array.slice(),i.userData.cropVerticesPerClump=t.getAttribute("position").count,t.dispose(),a}function hv(){const a=new Ee,t=new pi(1,7,3,0,Math.PI*2,0,Math.PI/2);return Ae(a,t,[.38,.36,.32],0),a}const wR=[.24,.22,.18],_R=[.14,.17,.08];function ER(){const a=new Ee,t=Ae(a,new Vi(1,1,1),wR,.5),e=Ae(a,new Vi(1,.03,1),_R,1.015);for(const i of[t,e])i.material.side=bn;return a}function uv(a){const t=new Ee;return Ae(t,new Zn(.05,.08,5,8),[.28,.28,.3],2.5),Ae(t,new pi(.25,12,8),a?Z2:lR,5.1,!0),t}const AR=[.08,.08,.08],Tr=.8,Ao=1,ws=1.7,mf=.6,ea=.46,wh=1.5,wo=.8,Is=.5,TR=ws;function dv(a,t,e,i){const n=new Ee;Ae(n,new Vi(1.8,1.4,4.2),[.45,.14,.14],.7),Ae(n,new Vi(Tr*2,mf,Ao*2),[.4,.12,.12],ws);for(const r of[-1.4,1.4])for(const o of[-.95,.95]){const c=Ae(n,new Zn(.4,.4,.3,12),AR,.4);c.rotation.z=Math.PI/2,c.position.x=o,c.position.z=r}const s=a?J2:hR;for(const r of[-.7,.7])Ae(n,new pi(.15,8,6),s,.7,!0).position.set(r,.7,-2.1);if(Ds(n,wh,ea,Rs,0,ws,-Ao-Ts,cn(t,"front")),Ds(n,wh,ea,Rs,0,ws,Ao+Ts,cn(t,"behind")),Ds(n,Rs,ea,wo,-Tr-Ts,ws,-Is,cn(t,"front-left")),Ds(n,Rs,ea,wo,-Tr-Ts,ws,Is,cn(t,"behind-left")),Ds(n,Rs,ea,wo,Tr+Ts,ws,-Is,cn(t,"front-right")),Ds(n,Rs,ea,wo,Tr+Ts,ws,Is,cn(t,"behind-right")),e){ty(n,e,i??e,pR,.5,Tr,Ao,iy);const r=(l,h)=>{const u=[];return cn(t,l)!==void 0&&u.push({main:wo,center:-Is}),cn(t,h)!==void 0&&u.push({main:wo,center:Is}),u},o=cn(t,"front")!==void 0?[{main:wh,center:0}]:[],c=cn(t,"behind")!==void 0?[{main:wh,center:0}]:[];Q2(n,Tr,Ao,ws-mf/2,ws+mf/2,ea,o,c,r("front-left","behind-left"),r("front-right","behind-right"))}return n}const fv=new Map;function pv(a,t){if(!a)return;const e=[[a.lengthM,t.lengthM],[a.heightM,t.heightM],[a.widthM,t.widthM]];for(const[i,n]of e)if(i!==void 0&&n>1e-6)return i/n}function gf(a,t){return t>1e-6?a/t:1}const ny=[.95,.9,.82],mv=[.72,.74,.78];function gv(){const a=new Ee;Ae(a,new Zn(.25,.3,1.5,10),mv,.75),Ae(a,new pi(.26,10,8),mv,1.74);const t=Ae(a,new rc(.07,.16,8),ny,1.74);return t.rotation.x=-Math.PI/2,t.position.z=-.22,a}function vp(){const a=new Ee;Ae(a,new Zn(.25,.3,1.5,10),[.3,.3,.35],.75),Ae(a,new pi(.22,10,8),[.62,.52,.46],1.72);const t=Ae(a,new rc(.07,.16,8),ny,1.72);return t.rotation.x=-Math.PI/2,t.position.z=-.2,a}const RR=17,vv=18.5,vf=[.16,.16,.18];function Mv(){const a=new Ee,t=Ae(a,new Zn(1.8,1.8,vv*2,10),vf,0);t.rotation.x=Math.PI/2,Ae(a,new Vi(RR*2,.5,4.5),vf,0);const e=Ae(a,new Vi(.4,5.5,4),vf,3);return e.position.z=-vv+2,a}class Ye{static GROWS_FROM_GROUND=new Set(["tree","shrub","crop","mound","terrace"]);static groundUnderFootprint(t,e,i,n,s,r=0){const o=Ye.sizeOf(t);if(r>o.heightM)return s(e,i);const c=(n??0)*Math.PI/180,l=Math.min(21,Math.max(2,Math.ceil(o.lengthM/.75)+1)),h=Math.min(21,Math.max(2,Math.ceil(o.widthM/.75)+1)),u=Ye.GROWS_FROM_GROUND.has(t.kind);let d=u?1/0:-1/0;for(let f=0;f<l;f++){const p=(f/(l-1)-.5)*o.lengthM;for(let v=0;v<h;v++){const m=(v/(h-1)-.5)*o.widthM,g=e+Math.sin(c)*p+Math.cos(c)*m,b=i-Math.cos(c)*p+Math.sin(c)*m;d=u?Math.min(d,s(g,b)):Math.max(d,s(g,b))}}return Number.isFinite(d)?d:s(e,i)}static occupantView(t,e=t.headingDeg){const i=t.observerSide;if(!i)throw new Error("occupantView requires object.observerSide to be set");const{x:n,z:s}=t.kind==="vehicle"?pp(i,Tr,Ao,iy):pp(i,mp/2,gp/2,ey),r=t.kind==="vehicle"?TR:(t.occupiedFloor??0)*Or+mR,o=(e??0)-j2[t.observerFacing??i]/df,c=this.scaleFor(t);return{x:n*c.x,z:s*c.z,eyeY:r*c.y,headingDeg:o}}static BODY_NAME="decor-body";static bodyOf(t){return t.getObjectByName(Ye.BODY_NAME)??t}static repeatOnGrid(t,e,i,n,s){const r=t.getAttribute("position"),o=t.getAttribute("normal"),c=t.getIndex();if(!c)throw new Error("repeatOnGrid needs an indexed geometry");const l=r.count,h=e*n,u=new Float32Array(l*h*3),d=new Float32Array(l*h*3),f=new Uint32Array(c.count*h),p=-((e-1)*i)/2,v=-((n-1)*s)/2;let m=0;for(let b=0;b<n;b++)for(let S=0;S<e;S++,m++){const M=v+b*s,x=p+S*i;for(let _=0;_<l;_++){const E=(m*l+_)*3;u[E]=r.getX(_)+M,u[E+1]=r.getY(_),u[E+2]=r.getZ(_)+x,d[E]=o.getX(_),d[E+1]=o.getY(_),d[E+2]=o.getZ(_)}for(let _=0;_<c.count;_++)f[m*c.count+_]=c.getX(_)+m*l}const g=new ae;return g.setAttribute("position",new ve(u,3)),g.setAttribute("normal",new ve(d,3)),g.setIndex(new Gp(f,1)),g}static fitTerrace(t,e,i){const n=Ye.sizeOf(e),s=n.widthM/2,r=n.lengthM/2,o=i(0,0)+n.heightM,c=Math.min(16,Math.max(1,Math.ceil(n.lengthM/3))),l=Ye.bodyOf(t).children.filter(M=>M.isMesh);if(l.length<2)return o;const h=Math.min(10,n.widthM/4),u=[-s];for(const M of[.25,.5,.75,1])u.push(-s+h*M);const d=Math.max(1,Math.ceil((n.widthM-2*h)/3));for(let M=1;M<d;M++)u.push(-s+h+(n.widthM-2*h)*M/d);for(const M of[1,.75,.5,.25,0])u.push(s-h*M);const f=M=>-r+n.lengthM*M/c,p=.8,v=(M,x)=>{const _=Math.min(1,Math.max(0,(s-Math.abs(M))/h)),E=_*_*(3-2*_);return E*o+(1-E)*Math.min(o,i(M,x))},m=[],g=(M,x)=>{const _=i(M[0],M[1])-p,E=i(x[0],x[1])-p,y=Math.max(v(M[0],M[1]),_),T=Math.max(v(x[0],x[1]),E);m.push(M[0],_,M[1],x[0],E,x[1],M[0],y,M[1]),m.push(x[0],E,x[1],x[0],T,x[1],M[0],y,M[1])};for(let M=0;M<u.length-1;M++)g([u[M],-r],[u[M+1],-r]),g([u[M],r],[u[M+1],r]);const b=[];for(let M=0;M<u.length-1;M++)for(let x=0;x<c;x++){const _=[u[M],f(x)],E=[u[M+1],f(x)],y=[u[M],f(x+1)],T=[u[M+1],f(x+1)];for(const[I,C,P]of[[_,y,E],[E,y,T]])for(const B of[I,C,P])b.push(B[0],v(B[0],B[1]),B[1])}const S=(M,x)=>{const _=new ae;_.setAttribute("position",new ve(x,3)),_.computeVertexNormals(),M.geometry.dispose(),M.geometry=_,M.position.y=0};return S(l[0],m),S(l[1],b),o}static fitCropToGround(t,e){t.updateMatrixWorld(!0);const i=new R;t.traverse(n=>{const s=n,r=s.userData.cropBasePositions,o=s.userData.cropVerticesPerClump;if(!s.isMesh||!r||!o)return;const c=s.geometry.getAttribute("position"),l=new ne().copy(s.matrixWorld).invert();for(let h=0;h<c.count;h+=o){i.set(r[h*3],0,r[h*3+2]).applyMatrix4(s.matrixWorld),i.y=e(i.x,i.z),i.applyMatrix4(l);for(let u=h;u<h+o;u++)c.setY(u,r[u*3+1]+i.y)}c.needsUpdate=!0,s.geometry.computeBoundingBox(),s.geometry.computeBoundingSphere()})}static paint(t,e){t.traverse(i=>{const n=i,s=n.userData;if(!n.isMesh||s?.emissive)return;const r=n.material;r?.color&&r.color.set(e)})}static build(t,e){const i=t.kind==="building"?rv(t.floors??Xm,t.windows,t.observerSide,t.occupiedFloor,t.observerFacing):t.kind==="tree"?ov():t.kind==="shrub"?av():t.kind==="bridge"?gR(t):t.kind==="wire"?vR(t):t.kind==="crop"?lv():t.kind==="terrace"?ER():t.kind==="mound"?hv():t.kind==="streetlight"?uv(e):t.kind==="vehicle"?dv(e,t.windows,t.observerSide,t.observerFacing):t.kind==="aircraft"?Mv():t.kind==="entity"?gv():vp();t.color&&this.paint(i,t.color);const n=this.scaleFor(t),s=new Ee;return i.name=Ye.BODY_NAME,i.scale.copy(n),s.add(i),t.headingDeg!==void 0&&(s.rotation.y=-t.headingDeg*df),this.addLights(s,t.lights),s}static scaleFor(t){const e=t.sizeM;if(!e||t.kind==="bridge"||t.kind==="wire"||t.kind==="terrace")return new R(1,1,1);const i=this.naturalSize(t.kind,t.floors);return new R(e.widthM===void 0?1:gf(e.widthM,i.widthM),e.heightM===void 0?1:gf(e.heightM,i.heightM),e.lengthM===void 0?1:gf(e.lengthM,i.lengthM))}static naturalSize(t,e){const i=t==="building"?Math.max(1,(e??Xm)+1):0;if(t==="bridge")return We.NATURAL_SIZE;if(t==="wire")return Ia.NATURAL_SIZE;if(t==="terrace")return{widthM:1,lengthM:1,heightM:1};const n=`${t}:${i}`,s=fv.get(n);if(s)return s;const r=t==="building"?rv(i-1,void 0,void 0,void 0):t==="tree"?ov():t==="shrub"?av():t==="crop"?lv():t==="mound"?hv():t==="streetlight"?uv(!1):t==="vehicle"?dv(!1,void 0,void 0):t==="aircraft"?Mv():t==="entity"?gv():vp(),o=new Qi().setFromObject(r),c={widthM:o.max.x-o.min.x,heightM:o.max.y-o.min.y,lengthM:o.max.z-o.min.z};return this.dispose(r),fv.set(n,c),c}static usesModel(t){return qf(t)!==void 0&&!(t.observerSide!==void 0&&mM(t.kind))}static applyModel(t,e,i,n={}){const s=this.bodyOf(t),r=new Ee;r.name=Ye.BODY_NAME,i.rotation.y=-(n.headingOffsetDeg??0)*df,i.updateMatrixWorld(!0);const o=new Qi().setFromObject(i),c={lengthM:o.max.z-o.min.z,heightM:o.max.y-o.min.y,widthM:o.max.x-o.min.x},l=pv(e.sizeM,c)??pv(n.depictedSizeM,c)??1;i.scale.multiplyScalar(l);const h=o.getCenter(new R).multiplyScalar(l);i.position.x-=h.x,i.position.z-=h.z,i.position.y-=e.kind==="aircraft"?h.y:o.min.y*l,i.traverse(u=>{u instanceof At&&(u.castShadow=!0,u.receiveShadow=!0)}),r.add(i),s.parent?(s.parent.add(r),s.removeFromParent()):t.add(r),this.dispose(s)}static sizeOf(t){const e=this.naturalSize(t.kind,t.floors);return{widthM:t.sizeM?.widthM??e.widthM,lengthM:t.sizeM?.lengthM??e.lengthM,heightM:t.sizeM?.heightM??e.heightM}}static addLights(t,e){for(const i of e??[]){const n=cR(i.color),s=Ae(t,new pi(ff,8,6),n,i.offsetM.y,!0);s.position.set(i.offsetM.x,i.offsetM.y,i.offsetM.z),s.userData={emissive:!0,lightId:i.id,lightColor:n},s.visible=!1;const r=s.material;r.blending=Pi,r.transparent=!0,r.depthWrite=!1,r.fog=!1}}static setLights(t,e,i,n,s=0,r=1,o=iR,c=[1,1,1]){if(!e||e.length===0)return;const l=new Map(e.map(f=>[f.id,f])),h=Math.max(1,n*o/ff),u=ff*h,d=r/(Math.PI*u*u);for(const f of t.children){if(!(f instanceof At))continue;const p=f.userData.lightId;if(!p)continue;const v=l.get(p);if(!v)continue;const m=s>0?MM(v,i,i+s):Px(v,i)?1:0;f.visible=m>0;const g=f.material,b=f.userData.lightColor;if(b){const S=m*nR*(v.intensity??1)*d;g.color.setRGB(b[0]*S*c[0],b[1]*S*c[1],b[2]*S*c[2])}f.scale.setScalar(h)}}static setLit(t,e,i,n=1){const[s,r,o]=e==="streetlight"?[sR,rR,Z2]:[aR,oR,J2],c=i?s*n/(Math.PI*r*r):0,l=[o[0]*c,o[1]*c,o[2]*c];t.traverse(h=>{const u=h.userData;!(h instanceof At)||!u.emissive||u.lightId||h.material.color.setRGB(...l)})}static dispose(t){t.traverse(e=>{if(!(e instanceof At)||e.userData.sharedModel)return;e.geometry.dispose();const i=e.material;for(const n of Array.isArray(i)?i:[i])n.dispose()})}}const Mf="https://ufoathome.org/models/index.json";class jc{attribution="3D models re-hosted by UFO@home, each under its own author's licence";fetchImpl;indexUrls;loading;static shared=new Map;sharing;constructor(t={}){this.sharing=!t.fetchImpl,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??DR()}async entries(t){const e=await this.load();return t?e.filter(i=>[i.kind].flat().includes(t)):e}async entry(t){return(await this.load()).find(e=>e.id===t)}load(){if(this.loading)return this.loading;if(!this.sharing)return this.loading=this.fetchFirstAvailable();const t=this.indexUrls.join(`
8063
- `);let e=jc.shared.get(t);return e||(e=this.fetchFirstAvailable(),jc.shared.set(t,e),e.then(i=>{i.length===0&&jc.shared.delete(t)})),this.loading=e}async fetchFirstAvailable(){for(const t of this.indexUrls){const e=await this.fetchIndex(t);if(e)return e}return[]}async fetchIndex(t){try{const e=await this.fetchImpl(t);if(!e.ok)return;const i=await e.json();return Array.isArray(i?.models)?i.models.map(({file:n,...s})=>({...s,url:new URL(n,t).href})):void 0}catch{return}}}function DR(){const a=`?v=${encodeURIComponent("0.105.2")}`,t=typeof location>"u"?void 0:new URL("/models/index.json",location.href).href;return(t&&t!==Mf?[t,Mf]:[Mf]).map(e=>e+a)}const IR=[{id:"ufoathome",name:"UFO@home",credit:"3D models re-hosted by UFO@home, each under its own author's licence",creditUrl:"https://ufoathome.org/models/",create:()=>new jc}];async function yf(a){const{GLTFLoader:t}=await je(async()=>{const{GLTFLoader:i}=await import("./GLTFLoader-C_t8vfKf.js");return{GLTFLoader:i}},[],import.meta.url),e=new t;return new Promise((i,n)=>{e.load(a,s=>i(Object.assign(s.scene,{animations:s.animations})),void 0,s=>n(new Error(`Could not load 3D model ${a}: ${s instanceof Error?s.message:String(s)}`)))})}const sy=["ellipsoid","sphere","disc","cylinder","cone","box","torus","figure"];class Cn{static MIN_ANGLE_RAD=.002;static FILL=(1-Math.exp(-4))/4;static MAX_SHARE=.3;mesh;constructor(t,e){this.mesh=new At(new dn(2,2),new Me({uniforms:{uColor:{value:new st(0,0,0)},uRadius:{value:1}},vertexShader:Cn.VERTEX,fragmentShader:Cn.FRAGMENT,transparent:!0,depthWrite:!1,blending:Pi,toneMapped:!1})),this.mesh.name=t,this.mesh.frustumCulled=!1,this.mesh.renderOrder=e,this.mesh.visible=!1}shine(t,e,i){this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z),this.mesh.material.uniforms.uRadius.value=e,this.mesh.material.uniforms.uColor.value.setRGB(i[0],i[1],i[2])}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static spread(t,e,i,n){const s=Math.max(t,n*Cn.MIN_ANGLE_RAD),r=Cn.FILL*Math.PI*s*s;return{radiusM:s,luminanceCdM2:i*Math.min(Cn.MAX_SHARE,e/r)}}static conserving(t){return Math.sqrt(t/(Cn.MAX_SHARE*Cn.FILL*Math.PI))}static VERTEX=`
8062
+ `,transparent:!0,blending:Ti,depthWrite:!1,side:Qe,fog:!1}),this.object=new At(new pi(Ui.RADIUS,64,32),this.material),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1;const i=this.material.uniforms;this.deckUniforms={uSource:i.uSource,uUp:i.uUp,uStrength:i.uStrength,uTint:i.uTint,uMap:i.uMap,uGain:i.uGain,uHaloShown:{value:0}}}deckUniforms;shown=!1;hostedByDeck=!1;set hosted(t){this.hostedByDeck=t,this.show(this.shown)}show(t){this.shown=t,this.object.visible=t&&!this.hostedByDeck,this.deckUniforms.uHaloShown.value=t?1:0}get awaitingFirstDisplay(){return this.tracing&&!this.everDisplayed}setUrgent(t){this.urgent=t}set onReady(t){this.onRepaint=t}update(t,e,i,n,s,r){const o=this.material.uniforms;if(i<=0){o.uStrength.value=0,this.show(!1),this.stopWork();return}o.uSource.value.set(t.x,t.y,t.z).normalize(),o.uStrength.value=i,o.uTint.value.set(n[0],n[1],n[2]),o.uIceCover.value=s.cover,o.uIceHeight.value=s.layerHeight,this.show(this.everDisplayed),this.requestMap(e,r)}requestMap(t,e){if(!(!(Math.abs(t-this.mappedAltitudeDeg)<Ui.ALTITUDE_STEP_DEG)||!(Math.abs(e-this.mappedAlignment)<Ui.ALIGNMENT_STEP))){this.next=void 0;return}if(this.tracing){if(this.tracingFor(t,e)){this.next=void 0;return}if(!(!(Math.abs(t-this.pendingAltitudeDeg)<Ui.LEAP_ALTITUDE_DEG)||!(Math.abs(e-this.pendingAlignment)<Ui.LEAP_ALIGNMENT))){this.next={sourceAltitudeDeg:t,alignment:e};return}}this.next=void 0,this.pendingAltitudeDeg=t,this.pendingAlignment=e,this.stopWork(),this.tracing=!0,this.startTracing(t,e)}startTracing(t,e){const i=++this.ticket,n=()=>{i!==this.ticket||!this.tracing||(this.sky.begin(t,e),this.scheduleWork())};kr.with(s=>{i!==this.ticket||!this.tracing||(this.job=s.trace(t,e,Ui.RAYS,r=>{this.job=void 0,this.texels.set(r),this.display(),this.finishTracing()},n))},n)}ticket=0;job;pendingAltitudeDeg=Number.NaN;pendingAlignment=Number.NaN;next;tracingFor(t,e){return this.tracing&&Math.abs(t-this.pendingAltitudeDeg)<Ui.ALTITUDE_STEP_DEG&&Math.abs(e-this.pendingAlignment)<Ui.ALIGNMENT_STEP}scheduleWork(){if(this.workHandle!==void 0)return;const t=()=>{if(this.workHandle=void 0,!this.tracing)return;const e=performance.now(),i=this.urgent?Ui.URGENT_BUDGET_MS:Ui.BUDGET_MS;do this.sky.trace(Ui.RAYS_PER_BATCH);while(this.sky.tracedRays<Ui.RAYS&&performance.now()-e<i);if(this.sky.tracedRays>=Ui.RAYS){this.publish(),this.finishTracing();return}this.workHandle=requestAnimationFrame(t)};this.workHandle=requestAnimationFrame(t)}finishTracing(){this.tracing=!1,this.mappedAltitudeDeg=this.pendingAltitudeDeg,this.mappedAlignment=this.pendingAlignment;const t=this.next;t&&this.requestMap(t.sourceAltitudeDeg,t.alignment)}stopWork(){this.ticket++,this.job?.cancel(),this.job=void 0,this.workHandle!==void 0&&cancelAnimationFrame(this.workHandle),this.workHandle=void 0,this.tracing=!1,this.next=void 0}publish(){eR.fromRadiance(this.sky.harvest().data,this.texels),this.display()}display(){this.texture.needsUpdate=!0,this.everDisplayed=!0,this.show(this.material.uniforms.uStrength.value>0),this.onRepaint?.()}dispose(){this.stopWork(),this.texture.dispose(),this.object.geometry.dispose(),this.material.dispose()}}class Fi{static MAX_CONCURRENT=24;static POINTS=8;static SEGMENTS=Fi.POINTS-1;static ACROSS=3;static VERTICES_PER_SEGMENT=(Fi.ACROSS-1)*6;static RADIUS=840;static MIN_HALF_WIDTH_DEG=.05;static BRIGHT_HALF_WIDTH_DEG=.22;object;positions;colors;meteors=[];radiantAltitudeDeg=0;radiantAzimuthDeg=0;constructor(){const t=Fi.MAX_CONCURRENT*Fi.SEGMENTS*Fi.VERTICES_PER_SEGMENT;this.positions=new Float32Array(t*3),this.colors=new Float32Array(t*3);const e=new ae;e.setAttribute("position",new te(this.positions,3)),e.setAttribute("color",new te(this.colors,3)),e.setDrawRange(0,0),this.object=new At(e,$n.material()),this.object.frustumCulled=!1,$n.track(this.object)}get schedule(){return this.meteors}setShower(t,e,i){this.meteors=t,this.radiantAltitudeDeg=e,this.radiantAzimuthDeg=i}update(t){const e=this.object.geometry;if(this.meteors.length===0){e.setDrawRange(0,0);return}const i=ka.aliveAt(this.meteors,t).slice(0,Fi.MAX_CONCURRENT);let n=0;for(const{meteor:s,progress:r}of i){const o=this.radiantOf(s);if(!o)continue;const c=Xe(o.altitudeDeg,o.azimuthDeg,1),[l,h]=this.basisAround(c),u=s.fromRadiantDeg+r*s.lengthDeg,d=Math.max(s.fromRadiantDeg,u-s.lengthDeg*.6),f=Math.min(1,(1-r)*2.5),p=this.turn(l,h,s.bearingDeg),v=(.15+.85*s.brightness)*f,m=S=>v*S**1.6,g=S=>this.onSphere(c,p,d+(u-d)*S),b=S=>Fi.RADIUS*((Fi.MIN_HALF_WIDTH_DEG+Fi.BRIGHT_HALF_WIDTH_DEG*s.brightness*S)*Math.PI/180);for(let S=1;S<Fi.POINTS;S++){const M=(S-1)/Fi.SEGMENTS,x=S/Fi.SEGMENTS;n=this.pushRibbon(n,g(M),g(x),b(M),b(x),m(M),m(x))}}e.setDrawRange(0,n),e.getAttribute("position").needsUpdate=!0,e.getAttribute("color").needsUpdate=!0}midpointOf(t){const e=this.radiantOf(t);if(!e)return;const i=Xe(e.altitudeDeg,e.azimuthDeg,1),[n,s]=this.basisAround(i),r=this.turn(n,s,t.bearingDeg),o=this.onSphere(i,r,t.fromRadiantDeg+t.lengthDeg/2),c=Math.hypot(o.x,o.y,o.z)||1;return{altitudeDeg:Math.asin(o.y/c)*180/Math.PI,azimuthDeg:(Math.atan2(o.x,-o.z)*180/Math.PI+360)%360}}radiantOf(t){return t.radiant?t.radiant:this.radiantAltitudeDeg>0?{altitudeDeg:this.radiantAltitudeDeg,azimuthDeg:this.radiantAzimuthDeg}:void 0}pushRibbon(t,e,i,n,s,r,o){const c=this.normalise(this.cross(this.normalise(e),this.normalise(this.subtract(i,e))));for(let l=0;l<Fi.ACROSS-1;l++){const h=l-1,u=l,d=this.across(e,c,n,h),f=this.across(i,c,s,h),p=this.across(e,c,n,u),v=this.across(i,c,s,u),m=(g,b)=>g===0?b:0;t=this.push(t,d,m(h,r)),t=this.push(t,f,m(h,o)),t=this.push(t,p,m(u,r)),t=this.push(t,f,m(h,o)),t=this.push(t,v,m(u,o)),t=this.push(t,p,m(u,r))}return t}across(t,e,i,n){return{x:t.x+e.x*i*n,y:t.y+e.y*i*n,z:t.z+e.z*i*n}}push(t,e,i){const n=t*3;this.positions[n]=e.x,this.positions[n+1]=e.y,this.positions[n+2]=e.z;const s=Rt.relativeOfResponse(Math.max(0,Math.min(1,i)));return this.colors[n]=s*.9,this.colors[n+1]=s*.95,this.colors[n+2]=s,t+1}turn(t,e,i){const n=i*Math.PI/180,s=Math.cos(n),r=Math.sin(n);return{x:t.x*s+e.x*r,y:t.y*s+e.y*r,z:t.z*s+e.z*r}}onSphere(t,e,i){const n=i*Math.PI/180,s=Math.cos(n),r=Math.sin(n);return{x:(t.x*s+e.x*r)*Fi.RADIUS,y:(t.y*s+e.y*r)*Fi.RADIUS,z:(t.z*s+e.z*r)*Fi.RADIUS}}basisAround(t){const e=Math.abs(t.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=this.normalise(this.cross(t,e));return[i,this.normalise(this.cross(t,i))]}subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class We{constructor(t,e={}){this.size=t,this.span=Math.min(t.lengthM,Math.max(0,e.spanM??t.lengthM)),this.bank=(t.lengthM-this.span)/2,this.deck=Math.min(t.heightM,e.deckThicknessM??We.DEFAULT_DECK_THICKNESS_M),this.railHeight=e.railing?.heightM??We.DEFAULT_RAILING_HEIGHT_M,this.postSpacing=Math.max(.3,e.railing?.postSpacingM??We.DEFAULT_POST_SPACING_M),this.rails=Math.max(0,Math.round(e.railing?.rails??We.DEFAULT_RAILS))}static DEFAULT_DECK_THICKNESS_M=1.2;static DEFAULT_RAILING_HEIGHT_M=1.05;static DEFAULT_POST_SPACING_M=1.5;static DEFAULT_RAILS=2;static BANK_SLOPE=1.5;static ABUTMENT_THICKNESS_M=1;static POST_SIDE_M=.08;static RAIL_HEIGHT_M=.08;static RAIL_DEPTH_M=.06;static BANK_STATIONS=12;static NATURAL_SIZE=Object.freeze({widthM:9,lengthM:40,heightM:6.5});span;bank;deck;railHeight;postSpacing;rails;roadAt(t){const e=Math.abs(t)-this.span/2;return e<=0?this.size.heightM:this.bank<=0?0:Math.max(0,this.size.heightM*(1-e/this.bank))}build(){const{widthM:t,heightM:e}=this.size,i=this.span/2,n=[];if(this.span>0){n.push(We.box(t,this.deck,this.span,0,e-this.deck/2,0));for(const c of[-1,1]){const l=e-this.deck;l>0&&this.bank>0&&n.push(We.box(t+1,l,We.ABUTMENT_THICKNESS_M,0,l/2,c*(i-We.ABUTMENT_THICKNESS_M/2)))}}const s=[];this.span>0&&s.push(We.box(t,.04,this.span,0,e+.02,0));const r=[];for(const c of[-1,1])this.bank<=0||(r.push(this.embankment(c)),s.push(this.bankRoad(c)));const o=[];for(const c of[-1,1])o.push(...this.railing(c*(t/2-We.POST_SIDE_M)));return{concrete:We.merge(n),road:We.merge(s),earth:We.merge(r),railing:We.merge(o)}}embankment(t){const e=this.size.widthM/2,i=this.stations(t),n=[],s=(l,h,u,d)=>{n.push(l.x,l.y,l.z,h.x,h.y,h.z,u.x,u.y,u.z,l.x,l.y,l.z,u.x,u.y,u.z,d.x,d.y,d.z)},r=l=>{const h=this.roadAt(l),u=e+We.BANK_SLOPE*h;return{leftFoot:new R(-u,0,l),leftTop:new R(-e,h,l),rightTop:new R(e,h,l),rightFoot:new R(u,0,l)}};for(let l=1;l<i.length;l++){const h=r(i[l-1]),u=r(i[l]),d=t>0,f=(p,v,m,g)=>d?s(p,v,m,g):s(g,m,v,p);f(h.leftFoot,h.leftTop,u.leftTop,u.leftFoot),f(h.leftTop,h.rightTop,u.rightTop,u.leftTop),f(h.rightTop,h.rightFoot,u.rightFoot,u.rightTop)}const o=r(i[0]);t>0?s(o.leftFoot,o.rightFoot,o.rightTop,o.leftTop):s(o.leftTop,o.rightTop,o.rightFoot,o.leftFoot);const c=new ae;return c.setAttribute("position",new ve(n,3)),c.computeVertexNormals(),c}bankRoad(t){const e=this.size.widthM/2,i=this.stations(t),n=[];for(let r=1;r<i.length;r++){const o=i[r-1],c=i[r],l=this.roadAt(o)+.02,h=this.roadAt(c)+.02,u=t>0?[[-e,l,o],[e,l,o],[e,h,c],[-e,h,c]]:[[-e,h,c],[e,h,c],[e,l,o],[-e,l,o]];for(const d of[0,2,1,0,3,2])n.push(...u[d])}const s=new ae;return s.setAttribute("position",new ve(n,3)),s.computeVertexNormals(),s}stations(t){const e=[];for(let i=0;i<=We.BANK_STATIONS;i++)e.push(t*(this.span/2+this.bank*i/We.BANK_STATIONS));return e}railing(t){const e=this.size.lengthM/2,i=Math.max(1,Math.round(this.size.lengthM/this.postSpacing)),n=[];for(let o=0;o<=i;o++)n.push(-e+this.size.lengthM*o/i);const s=[],r=We.POST_SIDE_M;for(const o of n)s.push(We.box(r,this.railHeight,r,t,this.roadAt(o)+this.railHeight/2,o));for(let o=1;o<=this.rails;o++){const c=this.railHeight*o/this.rails-We.RAIL_HEIGHT_M/2;for(let l=1;l<n.length;l++){const h=new R(t,this.roadAt(n[l-1])+c,n[l-1]),u=new R(t,this.roadAt(n[l])+c,n[l]);s.push(We.beam(h,u))}}return s}static box(t,e,i,n,s,r){return new Vi(t,e,i).translate(n,s,r)}static beam(t,e){const i=new R().subVectors(e,t),n=new Vi(We.RAIL_DEPTH_M,We.RAIL_HEIGHT_M,i.length()),s=new Sn().setFromUnitVectors(new R(0,0,1),i.clone().normalize()),r=new R().addVectors(t,e).multiplyScalar(.5);return n.applyMatrix4(new ne().compose(r,s,new R(1,1,1)))}static merge(t){const e=t.map(c=>c.getIndex()?c.toNonIndexed():c),i=e.reduce((c,l)=>c+l.getAttribute("position").count,0),n=new Float32Array(i*3),s=new Float32Array(i*3);let r=0;for(const c of e){const l=c.getAttribute("position"),h=c.getAttribute("normal");n.set(l.array,r*3),h&&s.set(h.array,r*3),r+=l.count}const o=new ae;o.setAttribute("position",new ve(n,3)),o.setAttribute("normal",new ve(s,3));for(const c of t)c.dispose();for(const c of e)c.dispose();return o}}class Ia{constructor(t,e={}){this.size=t,this.structure=e}static DEFAULT_DIAMETER_M=.008;static POLE_RADIUS_M=.13;static POLE_ABOVE_M=.5;static NATURAL_SIZE=Object.freeze({widthM:1,lengthM:30,heightM:5});get strands(){const t=this.structure.strands;return!t||t.length===0?[{heightM:this.size.heightM,acrossM:0}]:t.map(e=>({heightM:e.heightM,acrossM:e.acrossM??0}))}get poleStations(){const t=this.size.lengthM/2;switch(this.structure.poles??"both"){case"start":return[t];case"end":return[-t];case"none":return[];default:return[-t,t]}}get poleHeightM(){return this.structure.poleHeightM??Math.max(...this.strands.map(t=>t.heightM))+Ia.POLE_ABOVE_M}build(){const t=this.structure.diameterM??Ia.DEFAULT_DIAMETER_M,e=this.strands.map(n=>{const s=new Zn(t/2,t/2,this.size.lengthM,6);return s.rotateX(Math.PI/2),s.translate(n.acrossM,n.heightM,0),s}),i=this.poleStations.map(n=>{const s=new Zn(Ia.POLE_RADIUS_M*.8,Ia.POLE_RADIUS_M,this.poleHeightM,8);return s.translate(0,this.poleHeightM/2,n),s});return{strands:e,poles:i}}}const df=Math.PI/180;function Ae(a,t,e,i,n=!1){const s=n?new wn({color:new st(...e)}):new nc({color:new st(...e)}),r=new At(t,s);return r.position.y=i,r.userData={emissive:n},r.castShadow=!n,r.receiveShadow=!n,a.add(r),r}const ff=.25,iR=.002,nR=100,sR=1500,rR=.25,aR=1e3,oR=.15;function cR(a){const t=/^#([0-9a-f]{6})$/i.exec(a);if(!t)return[1,1,1];const e=parseInt(t[1],16);return[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]}const lR=[.32,.32,.3],Z2=[1,.85,.5],hR=[.25,.25,.25],J2=[1,.97,.85],uR=[.55,.68,.72],dR=.12,Ts=.03,Rs=.05,j2={front:0,behind:Math.PI,left:Math.PI/2,right:-Math.PI/2,"front-left":Math.PI/2,"behind-left":Math.PI/2,"front-right":-Math.PI/2,"behind-right":-Math.PI/2};function cn(a,t){return a?.[t]}function Ds(a,t,e,i,n,s,r,o){if(o===void 0)return;const c=new wn({color:new st(...uR).multiplyScalar(dR),transparent:!0,opacity:o/100,depthWrite:!1}),l=new At(new Vi(t,e,i),c);l.position.set(n,s,r),l.renderOrder=2,a.add(l)}const Gn=.05,pf=[.6,.58,.53],sv=[.5,.5,.48];function No(a,t,e,i,n,s,r,o){const c=new nc({color:new st(...o),side:Qe}),l=new At(new Vi(t,e,i),c);l.position.set(n,s,r),a.add(l)}function fR(a,t,e,i,n,s,r,o,c){const l=(i-s)/2,h=(p,v,m,g)=>{p<=0||(t?No(a,p,v,Gn,m,o+g,r,c):No(a,Gn,v,p,r,o+g,m,c))};h(e,l,0,i/2-l/2),h(e,l,0,-(i/2-l/2));const u=[...n].sort((p,v)=>p.center-v.center);let d=-e/2;for(const p of u){const m=p.center-p.main/2-d;h(m,s,d+m/2,0),d=p.center+p.main/2}const f=e/2-d;h(f,s,d+f/2,0)}function Q2(a,t,e,i,n,s,r,o,c,l){const h=(i+n)/2,u=n-i,d=(f,p,v,m)=>{f.length===0?p?No(a,v,u,Gn,0,h,m,pf):No(a,Gn,u,v,m,h,0,pf):fR(a,p,v,u,f,s,m,h,pf)};d(r,!0,t*2,-e+Gn),d(o,!0,t*2,e-Gn),d(c,!1,e*2,-t+Gn),d(l,!1,e*2,t-Gn),No(a,t*2,Gn,e*2,0,i+Gn,0,sv),No(a,t*2,Gn,e*2,0,n-Gn,0,sv)}function pp(a,t,e,i){switch(a){case"front":return{x:0,z:-(e-i)};case"behind":return{x:0,z:e-i};case"left":return{x:-(t-i),z:0};case"right":return{x:t-i,z:0};case"front-left":return{x:-(t-i),z:-Is};case"front-right":return{x:t-i,z:-Is};case"behind-left":return{x:-(t-i),z:Is};case"behind-right":return{x:t-i,z:Is}}}function ty(a,t,e,i,n,s,r,o){const c=vp();c.scale.setScalar(n),c.rotation.y=j2[e];const{x:l,z:h}=pp(t,s,r,o);c.position.set(l,i,h),a.add(c)}const mp=6,gp=6,Or=3,Tc=1.4,Rc=Or*.5,ey=1.2,iy=.35,pR=.75,mR=1.6;function rv(a,t,e,i,n){const s=new Ee,r=Math.max(1,a+1),o=r*Or;Ae(s,new Vi(mp,o,gp),[.55,.54,.5],o/2);const c=mp/2,l=gp/2;for(let h=0;h<r;h++){const u=h*Or+Or/2;Ds(s,Tc,Rc,Rs,0,u,-l-Ts,cn(t,"front")),Ds(s,Tc,Rc,Rs,0,u,l+Ts,cn(t,"behind")),Ds(s,Rs,Rc,Tc,-c-Ts,u,0,cn(t,"left")),Ds(s,Rs,Rc,Tc,c+Ts,u,0,cn(t,"right"))}if(e){const h=Math.min(Math.max(i??0,0),r-1);ty(s,e,n??e,h*Or,.72,c,l,ey);const u=d=>cn(t,d)!==void 0?[{main:Tc,center:0}]:[];Q2(s,c,l,h*Or,(h+1)*Or,Rc,u("front"),u("behind"),u("left"),u("right"))}return s}function av(){const a=new Ee,t=[[0,0,.55,.5],[.4,.1,.35,.4],[-.35,-.2,.4,.38],[.1,-.4,.35,.36],[-.15,.4,.3,.34]];for(const[e,i,n,s]of t){const r=new pi(n,10,7);r.scale(1,.85,1),r.translate(e,0,i),Ae(a,r,[.26,.28,.17],s)}return a}function gR(a){const t=new Ee,e=new We(Ye.sizeOf(a),a.bridge).build();Ae(t,e.concrete,[.6,.6,.58],0);const i=Ae(t,e.road,[.2,.2,.21],0),n=Ae(t,e.earth,[.3,.36,.22],0);for(const s of[i,n])s.material.side=bn;return Ae(t,e.railing,[.5,.52,.55],0),t}function vR(a){const t=new Ee,e=new Ia(Ye.sizeOf(a),a.wire).build();for(const i of e.strands)Ae(t,i,[.1,.1,.11],0);for(const i of e.poles)Ae(t,i,[.3,.24,.18],0);return t}function ov(){const a=new Ee;return Ae(a,new Zn(.15,.22,2,8),[.32,.22,.14],1),Ae(a,new rc(1.4,3,8),[.16,.32,.14],3.5),a}const cv=.275,MR=.35,yR=.9,xR=34,bR=8,SR=1.4;function lv(){const a=new Ee,t=new pi(cv,7,3,0,Math.PI*2,0,Math.PI/2);t.scale(1,MR/cv,1);const e=Ye.repeatOnGrid(t,xR,yR,bR,SR),i=Ae(a,e,[.26,.28,.22],0);return i.castShadow=!0,i.userData.cropBasePositions=e.getAttribute("position").array.slice(),i.userData.cropVerticesPerClump=t.getAttribute("position").count,t.dispose(),a}function hv(){const a=new Ee,t=new pi(1,7,3,0,Math.PI*2,0,Math.PI/2);return Ae(a,t,[.38,.36,.32],0),a}const wR=[.24,.22,.18],_R=[.14,.17,.08];function ER(){const a=new Ee,t=Ae(a,new Vi(1,1,1),wR,.5),e=Ae(a,new Vi(1,.03,1),_R,1.015);for(const i of[t,e])i.material.side=bn;return a}function uv(a){const t=new Ee;return Ae(t,new Zn(.05,.08,5,8),[.28,.28,.3],2.5),Ae(t,new pi(.25,12,8),a?Z2:lR,5.1,!0),t}const AR=[.08,.08,.08],Tr=.8,Ao=1,ws=1.7,mf=.6,ea=.46,wh=1.5,wo=.8,Is=.5,TR=ws;function dv(a,t,e,i){const n=new Ee;Ae(n,new Vi(1.8,1.4,4.2),[.45,.14,.14],.7),Ae(n,new Vi(Tr*2,mf,Ao*2),[.4,.12,.12],ws);for(const r of[-1.4,1.4])for(const o of[-.95,.95]){const c=Ae(n,new Zn(.4,.4,.3,12),AR,.4);c.rotation.z=Math.PI/2,c.position.x=o,c.position.z=r}const s=a?J2:hR;for(const r of[-.7,.7])Ae(n,new pi(.15,8,6),s,.7,!0).position.set(r,.7,-2.1);if(Ds(n,wh,ea,Rs,0,ws,-Ao-Ts,cn(t,"front")),Ds(n,wh,ea,Rs,0,ws,Ao+Ts,cn(t,"behind")),Ds(n,Rs,ea,wo,-Tr-Ts,ws,-Is,cn(t,"front-left")),Ds(n,Rs,ea,wo,-Tr-Ts,ws,Is,cn(t,"behind-left")),Ds(n,Rs,ea,wo,Tr+Ts,ws,-Is,cn(t,"front-right")),Ds(n,Rs,ea,wo,Tr+Ts,ws,Is,cn(t,"behind-right")),e){ty(n,e,i??e,pR,.5,Tr,Ao,iy);const r=(l,h)=>{const u=[];return cn(t,l)!==void 0&&u.push({main:wo,center:-Is}),cn(t,h)!==void 0&&u.push({main:wo,center:Is}),u},o=cn(t,"front")!==void 0?[{main:wh,center:0}]:[],c=cn(t,"behind")!==void 0?[{main:wh,center:0}]:[];Q2(n,Tr,Ao,ws-mf/2,ws+mf/2,ea,o,c,r("front-left","behind-left"),r("front-right","behind-right"))}return n}const fv=new Map;function pv(a,t){if(!a)return;const e=[[a.lengthM,t.lengthM],[a.heightM,t.heightM],[a.widthM,t.widthM]];for(const[i,n]of e)if(i!==void 0&&n>1e-6)return i/n}function gf(a,t){return t>1e-6?a/t:1}const ny=[.95,.9,.82],mv=[.72,.74,.78];function gv(){const a=new Ee;Ae(a,new Zn(.25,.3,1.5,10),mv,.75),Ae(a,new pi(.26,10,8),mv,1.74);const t=Ae(a,new rc(.07,.16,8),ny,1.74);return t.rotation.x=-Math.PI/2,t.position.z=-.22,a}function vp(){const a=new Ee;Ae(a,new Zn(.25,.3,1.5,10),[.3,.3,.35],.75),Ae(a,new pi(.22,10,8),[.62,.52,.46],1.72);const t=Ae(a,new rc(.07,.16,8),ny,1.72);return t.rotation.x=-Math.PI/2,t.position.z=-.2,a}const RR=17,vv=18.5,vf=[.16,.16,.18];function Mv(){const a=new Ee,t=Ae(a,new Zn(1.8,1.8,vv*2,10),vf,0);t.rotation.x=Math.PI/2,Ae(a,new Vi(RR*2,.5,4.5),vf,0);const e=Ae(a,new Vi(.4,5.5,4),vf,3);return e.position.z=-vv+2,a}class Ye{static GROWS_FROM_GROUND=new Set(["tree","shrub","crop","mound","terrace"]);static groundUnderFootprint(t,e,i,n,s,r=0){const o=Ye.sizeOf(t);if(r>o.heightM)return s(e,i);const c=(n??0)*Math.PI/180,l=Math.min(21,Math.max(2,Math.ceil(o.lengthM/.75)+1)),h=Math.min(21,Math.max(2,Math.ceil(o.widthM/.75)+1)),u=Ye.GROWS_FROM_GROUND.has(t.kind);let d=u?1/0:-1/0;for(let f=0;f<l;f++){const p=(f/(l-1)-.5)*o.lengthM;for(let v=0;v<h;v++){const m=(v/(h-1)-.5)*o.widthM,g=e+Math.sin(c)*p+Math.cos(c)*m,b=i-Math.cos(c)*p+Math.sin(c)*m;d=u?Math.min(d,s(g,b)):Math.max(d,s(g,b))}}return Number.isFinite(d)?d:s(e,i)}static occupantView(t,e=t.headingDeg){const i=t.observerSide;if(!i)throw new Error("occupantView requires object.observerSide to be set");const{x:n,z:s}=t.kind==="vehicle"?pp(i,Tr,Ao,iy):pp(i,mp/2,gp/2,ey),r=t.kind==="vehicle"?TR:(t.occupiedFloor??0)*Or+mR,o=(e??0)-j2[t.observerFacing??i]/df,c=this.scaleFor(t);return{x:n*c.x,z:s*c.z,eyeY:r*c.y,headingDeg:o}}static BODY_NAME="decor-body";static bodyOf(t){return t.getObjectByName(Ye.BODY_NAME)??t}static repeatOnGrid(t,e,i,n,s){const r=t.getAttribute("position"),o=t.getAttribute("normal"),c=t.getIndex();if(!c)throw new Error("repeatOnGrid needs an indexed geometry");const l=r.count,h=e*n,u=new Float32Array(l*h*3),d=new Float32Array(l*h*3),f=new Uint32Array(c.count*h),p=-((e-1)*i)/2,v=-((n-1)*s)/2;let m=0;for(let b=0;b<n;b++)for(let S=0;S<e;S++,m++){const M=v+b*s,x=p+S*i;for(let _=0;_<l;_++){const E=(m*l+_)*3;u[E]=r.getX(_)+M,u[E+1]=r.getY(_),u[E+2]=r.getZ(_)+x,d[E]=o.getX(_),d[E+1]=o.getY(_),d[E+2]=o.getZ(_)}for(let _=0;_<c.count;_++)f[m*c.count+_]=c.getX(_)+m*l}const g=new ae;return g.setAttribute("position",new ve(u,3)),g.setAttribute("normal",new ve(d,3)),g.setIndex(new Gp(f,1)),g}static fitTerrace(t,e,i){const n=Ye.sizeOf(e),s=n.widthM/2,r=n.lengthM/2,o=i(0,0)+n.heightM,c=Math.min(16,Math.max(1,Math.ceil(n.lengthM/3))),l=Ye.bodyOf(t).children.filter(M=>M.isMesh);if(l.length<2)return o;const h=Math.min(10,n.widthM/4),u=[-s];for(const M of[.25,.5,.75,1])u.push(-s+h*M);const d=Math.max(1,Math.ceil((n.widthM-2*h)/3));for(let M=1;M<d;M++)u.push(-s+h+(n.widthM-2*h)*M/d);for(const M of[1,.75,.5,.25,0])u.push(s-h*M);const f=M=>-r+n.lengthM*M/c,p=.8,v=(M,x)=>{const _=Math.min(1,Math.max(0,(s-Math.abs(M))/h)),E=_*_*(3-2*_);return E*o+(1-E)*Math.min(o,i(M,x))},m=[],g=(M,x)=>{const _=i(M[0],M[1])-p,E=i(x[0],x[1])-p,y=Math.max(v(M[0],M[1]),_),T=Math.max(v(x[0],x[1]),E);m.push(M[0],_,M[1],x[0],E,x[1],M[0],y,M[1]),m.push(x[0],E,x[1],x[0],T,x[1],M[0],y,M[1])};for(let M=0;M<u.length-1;M++)g([u[M],-r],[u[M+1],-r]),g([u[M],r],[u[M+1],r]);const b=[];for(let M=0;M<u.length-1;M++)for(let x=0;x<c;x++){const _=[u[M],f(x)],E=[u[M+1],f(x)],y=[u[M],f(x+1)],T=[u[M+1],f(x+1)];for(const[I,C,P]of[[_,y,E],[E,y,T]])for(const B of[I,C,P])b.push(B[0],v(B[0],B[1]),B[1])}const S=(M,x)=>{const _=new ae;_.setAttribute("position",new ve(x,3)),_.computeVertexNormals(),M.geometry.dispose(),M.geometry=_,M.position.y=0};return S(l[0],m),S(l[1],b),o}static fitCropToGround(t,e){t.updateMatrixWorld(!0);const i=new R;t.traverse(n=>{const s=n,r=s.userData.cropBasePositions,o=s.userData.cropVerticesPerClump;if(!s.isMesh||!r||!o)return;const c=s.geometry.getAttribute("position"),l=new ne().copy(s.matrixWorld).invert();for(let h=0;h<c.count;h+=o){i.set(r[h*3],0,r[h*3+2]).applyMatrix4(s.matrixWorld),i.y=e(i.x,i.z),i.applyMatrix4(l);for(let u=h;u<h+o;u++)c.setY(u,r[u*3+1]+i.y)}c.needsUpdate=!0,s.geometry.computeBoundingBox(),s.geometry.computeBoundingSphere()})}static paint(t,e){t.traverse(i=>{const n=i,s=n.userData;if(!n.isMesh||s?.emissive)return;const r=n.material;r?.color&&r.color.set(e)})}static build(t,e){const i=t.kind==="building"?rv(t.floors??Xm,t.windows,t.observerSide,t.occupiedFloor,t.observerFacing):t.kind==="tree"?ov():t.kind==="shrub"?av():t.kind==="bridge"?gR(t):t.kind==="wire"?vR(t):t.kind==="crop"?lv():t.kind==="terrace"?ER():t.kind==="mound"?hv():t.kind==="streetlight"?uv(e):t.kind==="vehicle"?dv(e,t.windows,t.observerSide,t.observerFacing):t.kind==="aircraft"?Mv():t.kind==="entity"?gv():vp();t.color&&this.paint(i,t.color);const n=this.scaleFor(t),s=new Ee;return i.name=Ye.BODY_NAME,i.scale.copy(n),s.add(i),t.headingDeg!==void 0&&(s.rotation.y=-t.headingDeg*df),this.addLights(s,t.lights),s}static scaleFor(t){const e=t.sizeM;if(!e||t.kind==="bridge"||t.kind==="wire"||t.kind==="terrace")return new R(1,1,1);const i=this.naturalSize(t.kind,t.floors);return new R(e.widthM===void 0?1:gf(e.widthM,i.widthM),e.heightM===void 0?1:gf(e.heightM,i.heightM),e.lengthM===void 0?1:gf(e.lengthM,i.lengthM))}static naturalSize(t,e){const i=t==="building"?Math.max(1,(e??Xm)+1):0;if(t==="bridge")return We.NATURAL_SIZE;if(t==="wire")return Ia.NATURAL_SIZE;if(t==="terrace")return{widthM:1,lengthM:1,heightM:1};const n=`${t}:${i}`,s=fv.get(n);if(s)return s;const r=t==="building"?rv(i-1,void 0,void 0,void 0):t==="tree"?ov():t==="shrub"?av():t==="crop"?lv():t==="mound"?hv():t==="streetlight"?uv(!1):t==="vehicle"?dv(!1,void 0,void 0):t==="aircraft"?Mv():t==="entity"?gv():vp(),o=new Qi().setFromObject(r),c={widthM:o.max.x-o.min.x,heightM:o.max.y-o.min.y,lengthM:o.max.z-o.min.z};return this.dispose(r),fv.set(n,c),c}static usesModel(t){return qf(t)!==void 0&&!(t.observerSide!==void 0&&mM(t.kind))}static applyModel(t,e,i,n={}){const s=this.bodyOf(t),r=new Ee;r.name=Ye.BODY_NAME,i.rotation.y=-(n.headingOffsetDeg??0)*df,i.updateMatrixWorld(!0);const o=new Qi().setFromObject(i),c={lengthM:o.max.z-o.min.z,heightM:o.max.y-o.min.y,widthM:o.max.x-o.min.x},l=pv(e.sizeM,c)??pv(n.depictedSizeM,c)??1;i.scale.multiplyScalar(l);const h=o.getCenter(new R).multiplyScalar(l);i.position.x-=h.x,i.position.z-=h.z,i.position.y-=e.kind==="aircraft"?h.y:o.min.y*l,i.traverse(u=>{u instanceof At&&(u.castShadow=!0,u.receiveShadow=!0)}),r.add(i),s.parent?(s.parent.add(r),s.removeFromParent()):t.add(r),this.dispose(s)}static sizeOf(t){const e=this.naturalSize(t.kind,t.floors);return{widthM:t.sizeM?.widthM??e.widthM,lengthM:t.sizeM?.lengthM??e.lengthM,heightM:t.sizeM?.heightM??e.heightM}}static addLights(t,e){for(const i of e??[]){const n=cR(i.color),s=Ae(t,new pi(ff,8,6),n,i.offsetM.y,!0);s.position.set(i.offsetM.x,i.offsetM.y,i.offsetM.z),s.userData={emissive:!0,lightId:i.id,lightColor:n},s.visible=!1;const r=s.material;r.blending=Ti,r.transparent=!0,r.depthWrite=!1,r.fog=!1}}static setLights(t,e,i,n,s=0,r=1,o=iR,c=[1,1,1]){if(!e||e.length===0)return;const l=new Map(e.map(f=>[f.id,f])),h=Math.max(1,n*o/ff),u=ff*h,d=r/(Math.PI*u*u);for(const f of t.children){if(!(f instanceof At))continue;const p=f.userData.lightId;if(!p)continue;const v=l.get(p);if(!v)continue;const m=s>0?MM(v,i,i+s):Px(v,i)?1:0;f.visible=m>0;const g=f.material,b=f.userData.lightColor;if(b){const S=m*nR*(v.intensity??1)*d;g.color.setRGB(b[0]*S*c[0],b[1]*S*c[1],b[2]*S*c[2])}f.scale.setScalar(h)}}static setLit(t,e,i,n=1){const[s,r,o]=e==="streetlight"?[sR,rR,Z2]:[aR,oR,J2],c=i?s*n/(Math.PI*r*r):0,l=[o[0]*c,o[1]*c,o[2]*c];t.traverse(h=>{const u=h.userData;!(h instanceof At)||!u.emissive||u.lightId||h.material.color.setRGB(...l)})}static dispose(t){t.traverse(e=>{if(!(e instanceof At)||e.userData.sharedModel)return;e.geometry.dispose();const i=e.material;for(const n of Array.isArray(i)?i:[i])n.dispose()})}}const Mf="https://ufoathome.org/models/index.json";class jc{attribution="3D models re-hosted by UFO@home, each under its own author's licence";fetchImpl;indexUrls;loading;static shared=new Map;sharing;constructor(t={}){this.sharing=!t.fetchImpl,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??DR()}async entries(t){const e=await this.load();return t?e.filter(i=>[i.kind].flat().includes(t)):e}async entry(t){return(await this.load()).find(e=>e.id===t)}load(){if(this.loading)return this.loading;if(!this.sharing)return this.loading=this.fetchFirstAvailable();const t=this.indexUrls.join(`
8063
+ `);let e=jc.shared.get(t);return e||(e=this.fetchFirstAvailable(),jc.shared.set(t,e),e.then(i=>{i.length===0&&jc.shared.delete(t)})),this.loading=e}async fetchFirstAvailable(){for(const t of this.indexUrls){const e=await this.fetchIndex(t);if(e)return e}return[]}async fetchIndex(t){try{const e=await this.fetchImpl(t);if(!e.ok)return;const i=await e.json();return Array.isArray(i?.models)?i.models.map(({file:n,...s})=>({...s,url:new URL(n,t).href})):void 0}catch{return}}}function DR(){const a=`?v=${encodeURIComponent("0.105.3")}`,t=typeof location>"u"?void 0:new URL("/models/index.json",location.href).href;return(t&&t!==Mf?[t,Mf]:[Mf]).map(e=>e+a)}const IR=[{id:"ufoathome",name:"UFO@home",credit:"3D models re-hosted by UFO@home, each under its own author's licence",creditUrl:"https://ufoathome.org/models/",create:()=>new jc}];async function yf(a){const{GLTFLoader:t}=await je(async()=>{const{GLTFLoader:i}=await import("./GLTFLoader-C_t8vfKf.js");return{GLTFLoader:i}},[],import.meta.url),e=new t;return new Promise((i,n)=>{e.load(a,s=>i(Object.assign(s.scene,{animations:s.animations})),void 0,s=>n(new Error(`Could not load 3D model ${a}: ${s instanceof Error?s.message:String(s)}`)))})}const sy=["ellipsoid","sphere","disc","cylinder","cone","box","torus","figure"];class Cn{static MIN_ANGLE_RAD=.002;static FILL=(1-Math.exp(-4))/4;static MAX_SHARE=.3;mesh;constructor(t,e){this.mesh=new At(new dn(2,2),new Me({uniforms:{uColor:{value:new st(0,0,0)},uRadius:{value:1}},vertexShader:Cn.VERTEX,fragmentShader:Cn.FRAGMENT,transparent:!0,depthWrite:!1,blending:Ti,toneMapped:!1})),this.mesh.name=t,this.mesh.frustumCulled=!1,this.mesh.renderOrder=e,this.mesh.visible=!1}shine(t,e,i){this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z),this.mesh.material.uniforms.uRadius.value=e,this.mesh.material.uniforms.uColor.value.setRGB(i[0],i[1],i[2])}hide(){this.mesh.visible=!1}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose()}static spread(t,e,i,n){const s=Math.max(t,n*Cn.MIN_ANGLE_RAD),r=Cn.FILL*Math.PI*s*s;return{radiusM:s,luminanceCdM2:i*Math.min(Cn.MAX_SHARE,e/r)}}static conserving(t){return Math.sqrt(t/(Cn.MAX_SHARE*Cn.FILL*Math.PI))}static VERTEX=`
8064
8064
  uniform float uRadius;
8065
8065
  varying vec2 vOffset;
8066
8066
  void main() {
@@ -8078,7 +8078,7 @@ ${Ct.OUTPUT_PROJECTION_GLSL}`)}}class nn{constructor(t,e){this.width=t,this.heig
8078
8078
  float weight = exp(-4.0 * d2);
8079
8079
  gl_FragColor = vec4(uColor * weight, weight);
8080
8080
  }
8081
- `}class Ca{static RENDER_ORDER=3;static LIGHT_AT=.35;static GLOW_MIN_ANGLE_RAD=Cn.MIN_ANGLE_RAD;static GLOW_FILL=Cn.FILL;static GLOW_MAX_SHARE=Cn.MAX_SHARE;mesh;light=new u2(16777215,0,0,2);glare=new Cn("flame-glow",Ca.RENDER_ORDER);scratch=new R;constructor(){const t=[];for(let s=0;s<=32;s++){const r=s/32,o=.5*(.7+.3*Math.sin(Math.min(1,r/.33)*Math.PI/2))*Math.pow(1-r,.55);t.push(new bt(Math.max(o,1e-4),-r))}const i=new id(t,48),n=new Me({uniforms:{uTime:{value:0},uColor:{value:new st(1,1,1)},uTipColor:{value:new st(1,1,1)}},vertexShader:Ca.VERTEX,fragmentShader:Ca.FRAGMENT,transparent:!0,depthWrite:!1,blending:Pi,side:bn,toneMapped:!1});this.mesh=new At(i,n),this.mesh.name="flame",this.mesh.frustumCulled=!1,this.mesh.renderOrder=Ca.RENDER_ORDER,this.mesh.visible=!1}get glow(){return this.glare.mesh}static glowFor(t,e){return Cn.spread(t.widthM*.6,.7*t.widthM*t.lengthM,t.luminanceCdM2,e)}shine(t,e){this.scratch.set(0,-.5,0).applyMatrix4(this.mesh.matrixWorld),this.glare.shine(this.scratch,t,e)}putOut(){this.mesh.visible=!1,this.glare.hide(),this.light.intensity=0}place(t,e,i,n){this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z),this.mesh.quaternion.set(e.x,e.y,e.z,e.w),this.mesh.scale.set(n,i,n),this.mesh.updateMatrixWorld(),this.light.position.set(0,-.35,0).applyMatrix4(this.mesh.matrixWorld)}set(t,e,i){const n=this.mesh.material.uniforms;n.uColor.value.setRGB(t[0],t[1],t[2]),n.uTipColor.value.setRGB(e[0],e[1],e[2]),n.uTime.value=i}illuminate(t,e){this.light.intensity=t,this.light.color.setRGB(e[0],e[1],e[2])}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.glare.dispose()}static VERTEX=`
8081
+ `}class Ca{static RENDER_ORDER=3;static LIGHT_AT=.35;static GLOW_MIN_ANGLE_RAD=Cn.MIN_ANGLE_RAD;static GLOW_FILL=Cn.FILL;static GLOW_MAX_SHARE=Cn.MAX_SHARE;mesh;light=new u2(16777215,0,0,2);glare=new Cn("flame-glow",Ca.RENDER_ORDER);scratch=new R;constructor(){const t=[];for(let s=0;s<=32;s++){const r=s/32,o=.5*(.7+.3*Math.sin(Math.min(1,r/.33)*Math.PI/2))*Math.pow(1-r,.55);t.push(new bt(Math.max(o,1e-4),-r))}const i=new id(t,48),n=new Me({uniforms:{uTime:{value:0},uColor:{value:new st(1,1,1)},uTipColor:{value:new st(1,1,1)}},vertexShader:Ca.VERTEX,fragmentShader:Ca.FRAGMENT,transparent:!0,depthWrite:!1,blending:Ti,side:bn,toneMapped:!1});this.mesh=new At(i,n),this.mesh.name="flame",this.mesh.frustumCulled=!1,this.mesh.renderOrder=Ca.RENDER_ORDER,this.mesh.visible=!1}get glow(){return this.glare.mesh}static glowFor(t,e){return Cn.spread(t.widthM*.6,.7*t.widthM*t.lengthM,t.luminanceCdM2,e)}shine(t,e){this.scratch.set(0,-.5,0).applyMatrix4(this.mesh.matrixWorld),this.glare.shine(this.scratch,t,e)}putOut(){this.mesh.visible=!1,this.glare.hide(),this.light.intensity=0}place(t,e,i,n){this.mesh.visible=!0,this.mesh.position.set(t.x,t.y,t.z),this.mesh.quaternion.set(e.x,e.y,e.z,e.w),this.mesh.scale.set(n,i,n),this.mesh.updateMatrixWorld(),this.light.position.set(0,-.35,0).applyMatrix4(this.mesh.matrixWorld)}set(t,e,i){const n=this.mesh.material.uniforms;n.uColor.value.setRGB(t[0],t[1],t[2]),n.uTipColor.value.setRGB(e[0],e[1],e[2]),n.uTime.value=i}illuminate(t,e){this.light.intensity=t,this.light.color.setRGB(e[0],e[1],e[2])}dispose(){this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.glare.dispose()}static VERTEX=`
8082
8082
  varying vec3 vLocal;
8083
8083
  varying vec3 vViewNormal;
8084
8084
  varying vec3 vViewPosition;
@@ -8204,7 +8204,7 @@ ${Ct.OUTPUT_PROJECTION_GLSL}`)}}class nn{constructor(t,e){this.width=t,this.heig
8204
8204
  `+n.vertexShader,n.vertexShader=n.vertexShader.replace("#include <project_vertex>",`#include <project_vertex>
8205
8205
  cloudPoint = (modelMatrix * vec4(transformed, 1.0)).xyz - cameraPosition;`);let s=`varying vec3 cloudPoint;
8206
8206
  `,r="";e.forEach((o,c)=>{const l=`cloud${c}_`;for(const[h,u]of Object.entries(o.uniforms))n.uniforms[l+h]=u;s+=KA(l),r+=`diffuseColor.a *= ${l}transmissionAt(normalize(cloudPoint), length(cloudPoint));
8207
- `}),n.fragmentShader=s+n.fragmentShader,n.fragmentShader=n.fragmentShader.replace("#include <opaque_fragment>",r+"#include <opaque_fragment>")},t.needsUpdate=!0}meshes=new Map;signatures=new Map;extents=new Map;placed=[];frame;direction=new R;up=new R;lookAt=new ne;vertex=new R;centre=new R;right=new R;above=new R;set(t,e){this.placed=t,this.frame=e;const i=new Set(t.map(n=>n.sourceId));for(const[n,s]of this.meshes)i.has(n)||(this.dispose(s),this.meshes.delete(n),this.signatures.delete(n),this.extents.delete(n));for(const n of t){let s=this.meshes.get(n.sourceId);s||(s=new At(new dn(1,1,ss.SEGMENTS,ss.SEGMENTS),new wn({transparent:!0,depthWrite:!1,depthTest:!0,fog:!1,toneMapped:!1})),this.configureCloudMaterial(s.material),s.frustumCulled=!1,s.layers.set(ay),this.scene.add(s),this.meshes.set(n.sourceId,s)),s.renderOrder=CR+n.renderOrder,s.visible=!n.hidden&&n.shape.transparency<1,s.visible&&this.paint(s,n,e)}}place(t,e,i){const n=this.frame;if(n)for(const s of this.placed){const r=this.meshes.get(s.sourceId);if(!r||!r.visible)continue;const o=this.extents.get(s.sourceId);if(!o)continue;const{bounds:c}=s.shape;let l=c.x+c.width/2,h=c.y+c.height/2,u=!0;if(s.aim){const d=i(ss.directionOf(s.aim,this.direction));d&&Math.abs(d.ndcX)<ss.FURTHEST_NDC&&Math.abs(d.ndcY)<ss.FURTHEST_NDC?(l=(d.ndcX+1)/2*n.canvasWidthPx,h=(1-d.ndcY)/2*n.canvasHeightPx):u=!1}u?this.curve(r,t,e,n,o,l,h,s.distanceM):this.flat(r,t,n,o,s.distanceM)}}static FURTHEST_NDC=4;curve(t,e,i,n,s,r,o,c){const l=r-s.width/2,h=o-s.height/2,u=t.geometry.attributes.position,d=ss.SEGMENTS;let f=0;for(let p=0;p<=d;p++){const v=h+p/d*s.height;for(let m=0;m<=d;m++){const g=l+m/d*s.width;i(g/n.canvasWidthPx*2-1,-(v/n.canvasHeightPx*2-1),this.direction),this.vertex.copy(e.position).addScaledVector(this.direction,c),u.setXYZ(f++,this.vertex.x,this.vertex.y,this.vertex.z)}}u.needsUpdate=!0,t.matrixAutoUpdate=!1,t.matrix.identity(),t.matrixWorldNeedsUpdate=!0,t.scale.set(Fe.sizeMAt(c,n.projection.pxToDeg(s.width)),Fe.sizeMAt(c,n.projection.pxToDeg(s.height)),1)}flat(t,e,i,n,s){const r=t.geometry.attributes.position,o=ss.SEGMENTS,c=Fe.sizeMAt(s,i.projection.pxToDeg(n.width)),l=Fe.sizeMAt(s,i.projection.pxToDeg(n.height));this.up.set(0,1,0).applyQuaternion(e.quaternion),this.centre.copy(e.position).addScaledVector(this.direction,s),this.lookAt.lookAt(e.position,this.centre,this.up),this.right.setFromMatrixColumn(this.lookAt,0),this.above.setFromMatrixColumn(this.lookAt,1);let h=0;for(let u=0;u<=o;u++){const d=.5-u/o;for(let f=0;f<=o;f++){const p=f/o-.5;this.vertex.copy(this.centre).addScaledVector(this.right,p*c).addScaledVector(this.above,d*l),r.setXYZ(h++,this.vertex.x,this.vertex.y,this.vertex.z)}}r.needsUpdate=!0,t.matrixAutoUpdate=!1,t.matrix.identity(),t.matrixWorldNeedsUpdate=!0,t.scale.set(c,l,1)}static SEGMENTS=16;static directionOf(t,e){const i=t.azimuthDeg*Math.PI/180,n=t.altitudeDeg*Math.PI/180;return e.set(Math.sin(i)*Math.cos(n),Math.sin(n),-Math.cos(i)*Math.cos(n))}get any(){for(const t of this.meshes.values())if(t.visible)return!0;return!1}get furthestM(){return this.placed.reduce((t,e)=>Math.max(t,e.distanceM),0)}paint(t,e,i){const{shape:n}=e,s=al.paintExtent(n),r=e.ghost?3:0,o={x:s.x-r,y:s.y-r,width:s.width+2*r,height:s.height+2*r};this.extents.set(e.sourceId,o);const c=`${ss.signatureOf(n,i)}|${e.ghost?"ghost":""}`;if(this.signatures.get(e.sourceId)===c&&t.material.map)return;this.signatures.set(e.sourceId,c);const l=Math.min(i.scale,PR/Math.max(o.width,o.height,1)),h=Math.max(1,Math.ceil(o.width*l)),u=Math.max(1,Math.ceil(o.height*l)),d=t.material.map,f=d?.image??document.createElement("canvas"),p=f.width!==h||f.height!==u;p&&(f.width=h,f.height=u);const v=f.getContext("2d");if(!v)return;v.clearRect(0,0,h,u);const m=new al(v);if(m.setStarPoints(i.starPoints),m.setRoll(i.rollRad),m.paintInto(n,o,l,e.ghost),d&&!p){d.needsUpdate=!0;return}d?.dispose();const g=new pr(f);g.colorSpace=un,g.minFilter=de,g.generateMipmaps=!1,t.material.map=g,t.material.needsUpdate=!0}static signatureOf(t,e){const{bounds:i}=t;return JSON.stringify([t.kind,Math.round(i.width*10),Math.round(i.height*10),t.color,t.angle,t.transparency,t.haloScale,t.blur??0,t.brightness??0,t.kind==="polygon"?t.points:void 0,e.scale,e.starPoints,e.rollRad])}dispose(t){t.removeFromParent(),t.geometry.dispose(),t.material.map?.dispose(),t.material.dispose()}clear(){for(const t of this.meshes.values())this.dispose(t);this.meshes.clear(),this.signatures.clear(),this.extents.clear(),this.placed=[]}}const oy=3,Eh=800,Dc=Math.PI/180;class is{constructor(t,e,i=is.fetchImage){this.scene=t,this.onImageLoaded=e,this.loadImage=i}meshes=new Map;signatures=new Map;images=new Map;loading=new Map;failed=new Set;references=[];views=new Map;shown=!0;observerAt;static PRESENT_WITHIN_M=2;static GONE_BEYOND_M=20;static presenceAt(t,e){if(!t.from||!e)return 1;const i=si(e.lat,e.lng,t.from.lat,t.from.lng),s=(Math.hypot(i.x,i.z)-is.PRESENT_WITHIN_M)/(is.GONE_BEYOND_M-is.PRESENT_WITHIN_M),r=Math.min(Math.max(s,0),1);return 1-r*r*(3-2*r)}set(t,e=this.views,i){this.references=t,this.observerAt=i,this.views=e;const n=new Set(t.map(s=>s.id));for(const[s,r]of this.meshes)n.has(s)||(this.dispose(r),this.meshes.delete(s),this.signatures.delete(s));for(const[s,r]of this.images){const o=t.find(c=>c.id===s);o&&o.src===r.texture.userData.src||(r.texture.dispose(),this.images.delete(s))}for(const s of t){const r=this.images.get(s.id);if(!r){this.load(s);continue}this.build(s,r)}}setShown(t){this.shown=t;for(const e of this.meshes.values())e.visible=t&&this.opacityOf(e.userData.id)>0}setView(t,e){this.views.set(t,e);const i=this.meshes.get(t);i&&this.applyOpacity(i,t)}get any(){for(const t of this.meshes.values())if(t.visible)return!0;return!1}place(t){for(const e of this.meshes.values())e.visible&&(e.position.copy(t.position),e.updateMatrixWorld())}get furthestM(){return this.meshes.size>0?Eh:0}directionOfPixel(t,e,i,n){const s=this.images.get(t.id),r=s?s.width/s.height:1,o=Math.tan(t.registration.fovDeg/2*Dc),c=o*r;return n.set((e*2-1)*c,(1-i*2)*o,-1).normalize(),n.applyQuaternion(is.orientation(t))}aspectOf(t){const e=this.images.get(t);return e?e.width/e.height:void 0}failedToLoad(t){return this.failed.has(t)}load(t){const e=t.src;if(this.loading.has(t.id)||this.failed.has(e))return;const i=this.loadImage(e).then(n=>{this.loading.delete(t.id);const s=this.references.find(r=>r.id===t.id);if(!s||s.src!==e){n.texture.dispose();return}n.texture.userData.src=e,this.images.set(t.id,n),this.build(s,n),this.onImageLoaded()},()=>{this.loading.delete(t.id),this.failed.add(e)});this.loading.set(t.id,i)}static async fetchImage(t){const e=await fetch(t);if(!e.ok)throw new Error(`${t}: ${e.status}`);const i=await createImageBitmap(await e.blob(),{imageOrientation:"flipY"}),n=new Hi(i);return n.flipY=!1,n.colorSpace=un,n.minFilter=de,n.magFilter=de,n.generateMipmaps=!1,n.needsUpdate=!0,{texture:n,width:i.width,height:i.height}}build(t,e){const i=is.signatureOf(t,e);let n=this.meshes.get(t.id);if(n&&this.signatures.get(t.id)===i){this.applyOpacity(n,t.id);return}n&&(this.dispose(n),this.meshes.delete(t.id)),n=new At(is.geometryOf(t,e),new wn({map:e.texture,transparent:!0,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1})),t.kind==="panorama"&&(n.material.side=Qe),n.frustumCulled=!1,n.layers.set(oy),n.userData.id=t.id,n.quaternion.copy(is.orientation(t)),this.scene.add(n),this.meshes.set(t.id,n),this.signatures.set(t.id,i),this.applyOpacity(n,t.id)}static geometryOf(t,e){if(t.kind==="panorama"){const r=new pi(Eh,64,32,Math.PI/2,Math.PI*2),o=r.attributes.uv;for(let c=0;c<o.count;c++)o.setX(c,1-o.getX(c));return o.needsUpdate=!0,r}const i=2*Eh*Math.tan(t.registration.fovDeg/2*Dc),n=i*(e.width/Math.max(e.height,1)),s=new dn(n,i);return s.translate(0,0,-Eh),s}static orientation(t){const{headingDeg:e,pitchDeg:i,rollDeg:n}=t.registration,s=new ti;return s.rotation.set(i*Dc,-e*Dc,-(n??0)*Dc,"YXZ"),s.quaternion}opacityOf(t){const e=this.references.find(s=>s.id===t),i=this.views.get(t),n=e?is.presenceAt(e,this.observerAt):1;return(i?.opacity??e?.opacity??0)*n}applyOpacity(t,e){const i=this.opacityOf(e);t.material.opacity=i,t.visible=this.shown&&i>0}static signatureOf(t,e){const{headingDeg:i,pitchDeg:n,rollDeg:s,fovDeg:r}=t.registration;return[t.kind,t.src,e.width,e.height,i,n,s??0,r].join("|")}dispose(t){this.scene.remove(t),t.geometry.dispose(),t.material.dispose()}disposeAll(){for(const t of this.meshes.values())this.dispose(t);this.meshes.clear(),this.signatures.clear();for(const t of this.images.values())t.texture.dispose();this.images.clear()}}class zt{static GROUND_RADIUS_M=636e4;static TOP_RADIUS_M=646e4;static WAVELENGTHS_NM=Array.from({length:15},(t,e)=>410+20*e);static WAVELENGTH_STEP_NM=20;static SOLAR_IRRADIANCE=[1.707,1.676,1.982,2.02,1.941,1.87,1.879,1.856,1.839,1.799,1.728,1.668,1.57,1.532,1.452];static OZONE_CROSS_SECTION=[.021,.069,.19,.418,.827,1.531,2.439,3.291,4.468,4.55,4.663,3.477,2.447,1.658,1.071];static RAYLEIGH_SCALE_HEIGHT_M=8e3;static AEROSOL_SCALE_HEIGHT_M=1200;static OZONE_PEAK_ALTITUDE_M=25e3;static OZONE_HALF_WIDTH_M=15e3;static DEFAULT_AEROSOL_OPTICAL_DEPTH=.1;static DEFAULT_OZONE_DOBSON=300;static AEROSOL_SINGLE_SCATTERING_ALBEDO=.9;static AEROSOL_ANGSTROM_EXPONENT=1.3;static AEROSOL_ASYMMETRY=.8;rayleighScattering;aerosolScattering;aerosolExtinction;ozoneAbsorption;constructor(t={}){const e=zt.WAVELENGTHS_NM.length,i=t.aerosolOpticalDepth??zt.DEFAULT_AEROSOL_OPTICAL_DEPTH,n=t.ozoneDobson??zt.DEFAULT_OZONE_DOBSON;this.rayleighScattering=new Float64Array(e),this.aerosolScattering=new Float64Array(e),this.aerosolExtinction=new Float64Array(e),this.ozoneAbsorption=new Float64Array(e);const s=n*2687e17/zt.OZONE_HALF_WIDTH_M;for(let r=0;r<e;r++){const o=zt.WAVELENGTHS_NM[r];this.rayleighScattering[r]=zt.rayleighAt(o);const c=i/zt.AEROSOL_SCALE_HEIGHT_M*(o/550)**-1.3;this.aerosolExtinction[r]=c,this.aerosolScattering[r]=c*zt.AEROSOL_SINGLE_SCATTERING_ALBEDO,this.ozoneAbsorption[r]=zt.OZONE_CROSS_SECTION[r]*1e-25*s}}static rayleighAt(t){const e=t/1e3,i=1/(e*e),n=e*e;return(1.0455996-341.29061*i-.9023085*n)/(1+.0027059889*i-85.968563*n)*1e-28*1e-4*2546899e19}static rayleighDensity(t){return Math.exp(-Math.max(t,0)/zt.RAYLEIGH_SCALE_HEIGHT_M)}static aerosolDensity(t){return Math.exp(-Math.max(t,0)/zt.AEROSOL_SCALE_HEIGHT_M)}static ozoneDensity(t){return Math.max(0,1-Math.abs(t-zt.OZONE_PEAK_ALTITUDE_M)/zt.OZONE_HALF_WIDTH_M)}static rayleighPhase(t){return 3/(16*Math.PI)*(1+t*t)}static aerosolPhase(t,e=zt.AEROSOL_ASYMMETRY){const i=e*e;return 3/(8*Math.PI)*(1-i)*(1+t*t)/((2+i)*Math.pow(Math.max(1+i-2*e*t,1e-6),1.5))}}class Xt{static TRANSMITTANCE_WIDTH=256;static TRANSMITTANCE_HEIGHT=64;static MULTIPLE_SIZE=64;static MULTIPLE_ROWS=16;static MULTIPLE_HEIGHT_POWER=2;static MULTIPLE_DIRECTIONS=16;static SKY_VIEW_WIDTH=192;static SKY_VIEW_HEIGHT=108;static STEPS=40;static MULTIPLE_STEPS=12;static GROUND_ALBEDO=.3;supported;renderer;transmittance;multiple;sunView;moonView;scene=new Gs;camera=new ps(-1,1,1,-1,0,1);quad;transmittanceMaterial;multipleMaterial;skyViewMaterial;transmittanceReady=!1;multipleRows=0;multipleColumn=0;mediumKey="";static MULTIPLE_BLOCK=16;static shared=new Map;building=!1;adopted;tableUniforms;constructor(t){this.renderer=t,this.supported=t.capabilities.isWebGL2&&t.extensions.has("EXT_color_buffer_float"),this.transmittance=new oi(Xt.TRANSMITTANCE_WIDTH,Xt.TRANSMITTANCE_HEIGHT,{count:4,type:qe,minFilter:de,magFilter:de,depthBuffer:!1}),this.multiple=new oi(Xt.MULTIPLE_SIZE,Xt.MULTIPLE_ROWS,{count:4,type:ji,minFilter:Ue,magFilter:Ue,depthBuffer:!1});const e=()=>new oi(Xt.SKY_VIEW_WIDTH,Xt.SKY_VIEW_HEIGHT,{type:ji,minFilter:Ue,magFilter:Ue,depthBuffer:!1});this.sunView=e(),this.moonView=e();const i=Xt.mediumUniforms(),n=this.tableUniforms={uT0:{value:this.transmittance.textures[0]},uT1:{value:this.transmittance.textures[1]},uT2:{value:this.transmittance.textures[2]},uT3:{value:this.transmittance.textures[3]},uM0:{value:this.multiple.textures[0]},uM1:{value:this.multiple.textures[1]},uM2:{value:this.multiple.textures[2]},uM3:{value:this.multiple.textures[3]}},s=(r,o={})=>new a2({glslVersion:Ru,uniforms:{...i,...n,...o},vertexShader:Xt.VERTEX,fragmentShader:r,depthTest:!1,depthWrite:!1});this.transmittanceMaterial=s(Xt.TRANSMITTANCE_FRAGMENT),this.multipleMaterial=s(Xt.MULTIPLE_FRAGMENT),this.skyViewMaterial=s(Xt.SKY_VIEW_FRAGMENT,{uObserverRadius:{value:zt.GROUND_RADIUS_M+2},uSourceMu:{value:1}}),this.quad=new At(new dn(2,2),this.transmittanceMaterial),this.quad.frustumCulled=!1,this.scene.add(this.quad)}get transmittanceTextures(){return this.transmittance.textures}get sunViewTexture(){return this.sunView.texture}get moonViewTexture(){return this.moonView.texture}get ready(){return this.supported&&(this.adopted!==void 0||this.transmittanceReady&&this.multipleRows>=Xt.MULTIPLE_ROWS)}setMedium(t){const e=[t.rayleighScattering,t.aerosolScattering,t.aerosolExtinction,t.ozoneAbsorption].map(n=>Array.from(n,s=>s.toPrecision(6)).join(",")).join("|");if(e===this.mediumKey)return;this.abandonBuilding(),this.releaseAdopted(),this.mediumKey=e;const i=(n,s)=>{const r=this.transmittanceMaterial.uniforms[n].value;for(let o=0;o<4;o++)r[o].set(s[o*4]??0,s[o*4+1]??0,s[o*4+2]??0,s[o*4+3]??0)};i("uRayleigh",t.rayleighScattering),i("uAerosolScattering",t.aerosolScattering),i("uAerosolExtinction",t.aerosolExtinction),i("uOzone",t.ozoneAbsorption),this.transmittanceReady=!1,this.multipleRows=0,this.multipleColumn=0}invalidate(){this.adopted||(this.abandonBuilding(),this.transmittanceReady=!1,this.multipleRows=0,this.multipleColumn=0)}advance(t){if(!this.supported||!this.mediumKey)return!1;if(this.ready)return!0;const e=Xt.shared.get(this.mediumKey);if(e&&e!=="building")return this.adopt(e),!0;if(e==="building"&&!this.building)return!1;e||(Xt.shared.set(this.mediumKey,"building"),this.building=!0);const i=this.renderer.getRenderTarget();let n=Math.max(1,t);this.transmittanceReady||(this.draw(this.transmittanceMaterial,this.transmittance),this.transmittanceReady=!0,n--);const s=Xt.MULTIPLE_SIZE,r=Xt.MULTIPLE_BLOCK;for(;n>0&&this.multipleRows<Xt.MULTIPLE_ROWS;n--)this.multiple.scissor.set(this.multipleColumn,this.multipleRows,r,1),this.multiple.scissorTest=!0,this.draw(this.multipleMaterial,this.multiple),this.multipleColumn+=r,this.multipleColumn>=s&&(this.multipleColumn=0,this.multipleRows++);return this.multiple.scissorTest=!1,this.renderer.setRenderTarget(i),this.ready&&this.building&&this.share(this.mediumKey),this.ready}async share(t){this.building=!1;try{const e=await Promise.all([0,1,2,3].map(n=>this.readRaw(this.transmittance,n,Uint16Array))),i=await Promise.all([0,1,2,3].map(n=>this.readRaw(this.multiple,n,Float32Array)));this.mediumKey===t?Xt.shared.set(t,{transmittance:e,multiple:i}):Xt.shared.delete(t)}catch{Xt.shared.delete(t)}}async readRaw(t,e,i){const n=new i(t.width*t.height*4);return await this.renderer.readRenderTargetPixelsAsync(t,0,0,t.width,t.height,n,void 0,e),n}adopt(t){const e=(s,r,o,c)=>{const l=new Vs(s,r,o,Gi,c?qe:ji);return l.minFilter=l.magFilter=c?de:Ue,l.needsUpdate=!0,l},i=t.transmittance.map(s=>e(s,Xt.TRANSMITTANCE_WIDTH,Xt.TRANSMITTANCE_HEIGHT,!0)),n=t.multiple.map(s=>e(s,Xt.MULTIPLE_SIZE,Xt.MULTIPLE_ROWS,!1));i.forEach((s,r)=>this.tableUniforms[`uT${r}`].value=s),n.forEach((s,r)=>this.tableUniforms[`uM${r}`].value=s),this.adopted=[...i,...n]}releaseAdopted(){if(this.adopted){for(const t of this.adopted)t.dispose();this.adopted=void 0;for(let t=0;t<4;t++)this.tableUniforms[`uT${t}`].value=this.transmittance.textures[t],this.tableUniforms[`uM${t}`].value=this.multiple.textures[t]}}abandonBuilding(){this.building&&(this.building=!1,Xt.shared.get(this.mediumKey)==="building"&&Xt.shared.delete(this.mediumKey))}renderSkyViews(t,e,i){if(!this.ready)return;const n=this.renderer.getRenderTarget(),s=this.skyViewMaterial.uniforms;s.uObserverRadius.value=zt.GROUND_RADIUS_M+Math.max(t,2),s.uSourceMu.value=Math.sin(e*Math.PI/180),this.draw(this.skyViewMaterial,this.sunView),s.uSourceMu.value=Math.sin(i*Math.PI/180),this.draw(this.skyViewMaterial,this.moonView),this.renderer.setRenderTarget(n)}static skyViewUv(t,e,i){const n=zt.GROUND_RADIUS_M+Math.max(t,2),s=zt.GROUND_RADIUS_M,r=Math.acos(Math.min(Math.sqrt(Math.max(n*n-s*s,0))/n,1)),o=Math.PI-r,c=e<o?.5*(1-Math.sqrt(Math.max(1-e/o,0))):.5+.5*Math.sqrt(Math.min((e-o)/r,1));return{u:Math.min(Math.max(Math.abs(i)/Math.PI,0),1),v:c}}async readTable(t,e){if(t==="multiple"){const s=new Float32Array(this.multiple.width*this.multiple.height*4);return await this.renderer.readRenderTargetPixelsAsync(this.multiple,0,0,this.multiple.width,this.multiple.height,s,void 0,e),s}const i=this.transmittance,n=new Uint16Array(i.width*i.height*4);return await this.renderer.readRenderTargetPixelsAsync(i,0,0,i.width,i.height,n,void 0,e),Float32Array.from(n,s=>kn.fromHalfFloat(s))}readSkyViewNow(t){const e=t==="sun"?this.sunView:this.moonView,i=new Float32Array(e.width*e.height*4),n=this.renderer.getContext();return n.bindBuffer(n.PIXEL_PACK_BUFFER,null),this.renderer.readRenderTargetPixels(e,0,0,e.width,e.height,i),i}async readSkyView(t){const e=t==="sun"?this.sunView:this.moonView,i=new Float32Array(e.width*e.height*4);return await this.renderer.readRenderTargetPixelsAsync(e,0,0,e.width,e.height,i),i}dispose(){this.abandonBuilding(),this.releaseAdopted(),this.transmittance.dispose(),this.multiple.dispose(),this.sunView.dispose(),this.moonView.dispose(),this.transmittanceMaterial.dispose(),this.multipleMaterial.dispose(),this.skyViewMaterial.dispose(),this.quad.geometry.dispose()}draw(t,e){this.quad.material=t,this.renderer.setRenderTarget(e),this.renderer.render(this.scene,this.camera)}static mediumUniforms(){const t=()=>[new ue,new ue,new ue,new ue],e=(i,n)=>{const s=t();return zt.WAVELENGTHS_NM.forEach((r,o)=>{s[Math.floor(o/4)].setComponent(o%4,i(r)*n*zt.WAVELENGTH_STEP_NM*zt.SOLAR_IRRADIANCE[o])}),s};return{uRayleigh:{value:t()},uAerosolScattering:{value:t()},uAerosolExtinction:{value:t()},uOzone:{value:t()},uCieX:{value:e(i=>Ci.colourMatching(i)[0],683)},uCieY:{value:e(i=>Ci.colourMatching(i)[1],683)},uCieZ:{value:e(i=>Ci.colourMatching(i)[2],683)},uScotopic:{value:e(i=>Ci.scotopic(i),1700)}}}static VERTEX=`
8207
+ `}),n.fragmentShader=s+n.fragmentShader,n.fragmentShader=n.fragmentShader.replace("#include <opaque_fragment>",r+"#include <opaque_fragment>")},t.needsUpdate=!0}meshes=new Map;signatures=new Map;extents=new Map;placed=[];frame;direction=new R;up=new R;lookAt=new ne;vertex=new R;centre=new R;right=new R;above=new R;set(t,e){this.placed=t,this.frame=e;const i=new Set(t.map(n=>n.sourceId));for(const[n,s]of this.meshes)i.has(n)||(this.dispose(s),this.meshes.delete(n),this.signatures.delete(n),this.extents.delete(n));for(const n of t){let s=this.meshes.get(n.sourceId);s||(s=new At(new dn(1,1,ss.SEGMENTS,ss.SEGMENTS),new wn({transparent:!0,depthWrite:!1,depthTest:!0,fog:!1,toneMapped:!1})),this.configureCloudMaterial(s.material),s.frustumCulled=!1,s.layers.set(ay),this.scene.add(s),this.meshes.set(n.sourceId,s)),s.renderOrder=CR+n.renderOrder,s.visible=!n.hidden&&n.shape.transparency<1,s.visible&&this.paint(s,n,e)}}place(t,e,i){const n=this.frame;if(n)for(const s of this.placed){const r=this.meshes.get(s.sourceId);if(!r||!r.visible)continue;const o=this.extents.get(s.sourceId);if(!o)continue;const{bounds:c}=s.shape;let l=c.x+c.width/2,h=c.y+c.height/2,u=!0;if(s.aim){const d=i(ss.directionOf(s.aim,this.direction));d&&Math.abs(d.ndcX)<ss.FURTHEST_NDC&&Math.abs(d.ndcY)<ss.FURTHEST_NDC?(l=(d.ndcX+1)/2*n.canvasWidthPx,h=(1-d.ndcY)/2*n.canvasHeightPx):u=!1}u?this.curve(r,t,e,n,o,l,h,s.distanceM):this.flat(r,t,n,o,s.distanceM)}}static FURTHEST_NDC=4;curve(t,e,i,n,s,r,o,c){const l=r-s.width/2,h=o-s.height/2,u=t.geometry.attributes.position,d=ss.SEGMENTS;let f=0;for(let p=0;p<=d;p++){const v=h+p/d*s.height;for(let m=0;m<=d;m++){const g=l+m/d*s.width;i(g/n.canvasWidthPx*2-1,-(v/n.canvasHeightPx*2-1),this.direction),this.vertex.copy(e.position).addScaledVector(this.direction,c),u.setXYZ(f++,this.vertex.x,this.vertex.y,this.vertex.z)}}u.needsUpdate=!0,t.matrixAutoUpdate=!1,t.matrix.identity(),t.matrixWorldNeedsUpdate=!0,t.scale.set(Fe.sizeMAt(c,n.projection.pxToDeg(s.width)),Fe.sizeMAt(c,n.projection.pxToDeg(s.height)),1)}flat(t,e,i,n,s){const r=t.geometry.attributes.position,o=ss.SEGMENTS,c=Fe.sizeMAt(s,i.projection.pxToDeg(n.width)),l=Fe.sizeMAt(s,i.projection.pxToDeg(n.height));this.up.set(0,1,0).applyQuaternion(e.quaternion),this.centre.copy(e.position).addScaledVector(this.direction,s),this.lookAt.lookAt(e.position,this.centre,this.up),this.right.setFromMatrixColumn(this.lookAt,0),this.above.setFromMatrixColumn(this.lookAt,1);let h=0;for(let u=0;u<=o;u++){const d=.5-u/o;for(let f=0;f<=o;f++){const p=f/o-.5;this.vertex.copy(this.centre).addScaledVector(this.right,p*c).addScaledVector(this.above,d*l),r.setXYZ(h++,this.vertex.x,this.vertex.y,this.vertex.z)}}r.needsUpdate=!0,t.matrixAutoUpdate=!1,t.matrix.identity(),t.matrixWorldNeedsUpdate=!0,t.scale.set(c,l,1)}static SEGMENTS=16;static directionOf(t,e){const i=t.azimuthDeg*Math.PI/180,n=t.altitudeDeg*Math.PI/180;return e.set(Math.sin(i)*Math.cos(n),Math.sin(n),-Math.cos(i)*Math.cos(n))}get any(){for(const t of this.meshes.values())if(t.visible)return!0;return!1}get furthestM(){return this.placed.reduce((t,e)=>Math.max(t,e.distanceM),0)}paint(t,e,i){const{shape:n}=e,s=al.paintExtent(n),r=e.ghost?3:0,o={x:s.x-r,y:s.y-r,width:s.width+2*r,height:s.height+2*r};this.extents.set(e.sourceId,o);const c=`${ss.signatureOf(n,i)}|${e.ghost?"ghost":""}`;if(this.signatures.get(e.sourceId)===c&&t.material.map)return;this.signatures.set(e.sourceId,c);const l=Math.min(i.scale,PR/Math.max(o.width,o.height,1)),h=Math.max(1,Math.ceil(o.width*l)),u=Math.max(1,Math.ceil(o.height*l)),d=t.material.map,f=d?.image??document.createElement("canvas"),p=f.width!==h||f.height!==u;p&&(f.width=h,f.height=u);const v=f.getContext("2d");if(!v)return;v.clearRect(0,0,h,u);const m=new al(v);if(m.setStarPoints(i.starPoints),m.setRoll(i.rollRad),m.paintInto(n,o,l,e.ghost),d&&!p){d.needsUpdate=!0;return}d?.dispose();const g=new pr(f);g.colorSpace=un,g.minFilter=de,g.generateMipmaps=!1,t.material.map=g,t.material.needsUpdate=!0}static signatureOf(t,e){const{bounds:i}=t;return JSON.stringify([t.kind,Math.round(i.width*10),Math.round(i.height*10),t.color,t.angle,t.transparency,t.haloScale,t.blur??0,t.brightness??0,t.kind==="polygon"?t.points:void 0,e.scale,e.starPoints,e.rollRad])}dispose(t){t.removeFromParent(),t.geometry.dispose(),t.material.map?.dispose(),t.material.dispose()}clear(){for(const t of this.meshes.values())this.dispose(t);this.meshes.clear(),this.signatures.clear(),this.extents.clear(),this.placed=[]}}const oy=3,Eh=800,Dc=Math.PI/180;class is{constructor(t,e,i=is.fetchImage){this.scene=t,this.onImageLoaded=e,this.loadImage=i}meshes=new Map;signatures=new Map;images=new Map;loading=new Map;failed=new Set;references=[];views=new Map;shown=!0;observerAt;static PRESENT_WITHIN_M=2;static GONE_BEYOND_M=20;static presenceAt(t,e){if(!t.from||!e)return 1;const i=si(e.lat,e.lng,t.from.lat,t.from.lng),s=(Math.hypot(i.x,i.z)-is.PRESENT_WITHIN_M)/(is.GONE_BEYOND_M-is.PRESENT_WITHIN_M),r=Math.min(Math.max(s,0),1);return 1-r*r*(3-2*r)}set(t,e=this.views,i){this.references=t,this.observerAt=i,this.views=e;const n=new Set(t.map(s=>s.id));for(const[s,r]of this.meshes)n.has(s)||(this.dispose(r),this.meshes.delete(s),this.signatures.delete(s));for(const[s,r]of this.images){const o=t.find(c=>c.id===s);o&&o.src===r.texture.userData.src||(r.texture.dispose(),this.images.delete(s))}for(const s of t){const r=this.images.get(s.id);if(!r){this.load(s);continue}this.build(s,r)}}setShown(t){this.shown=t;for(const e of this.meshes.values())e.visible=t&&this.opacityOf(e.userData.id)>0}setView(t,e){this.views.set(t,e);const i=this.meshes.get(t);i&&this.applyOpacity(i,t)}get any(){for(const t of this.meshes.values())if(t.visible)return!0;return!1}place(t){for(const e of this.meshes.values())e.visible&&(e.position.copy(t.position),e.updateMatrixWorld())}get furthestM(){return this.meshes.size>0?Eh:0}directionOfPixel(t,e,i,n){const s=this.images.get(t.id),r=s?s.width/s.height:1,o=Math.tan(t.registration.fovDeg/2*Dc),c=o*r;return n.set((e*2-1)*c,(1-i*2)*o,-1).normalize(),n.applyQuaternion(is.orientation(t))}aspectOf(t){const e=this.images.get(t);return e?e.width/e.height:void 0}failedToLoad(t){return this.failed.has(t)}load(t){const e=t.src;if(this.loading.has(t.id)||this.failed.has(e))return;const i=this.loadImage(e).then(n=>{this.loading.delete(t.id);const s=this.references.find(r=>r.id===t.id);if(!s||s.src!==e){n.texture.dispose();return}n.texture.userData.src=e,this.images.set(t.id,n),this.build(s,n),this.onImageLoaded()},()=>{this.loading.delete(t.id),this.failed.add(e)});this.loading.set(t.id,i)}static async fetchImage(t){const e=await fetch(t);if(!e.ok)throw new Error(`${t}: ${e.status}`);const i=await createImageBitmap(await e.blob(),{imageOrientation:"flipY"}),n=new Hi(i);return n.flipY=!1,n.colorSpace=un,n.minFilter=de,n.magFilter=de,n.generateMipmaps=!1,n.needsUpdate=!0,{texture:n,width:i.width,height:i.height}}build(t,e){const i=is.signatureOf(t,e);let n=this.meshes.get(t.id);if(n&&this.signatures.get(t.id)===i){this.applyOpacity(n,t.id);return}n&&(this.dispose(n),this.meshes.delete(t.id)),n=new At(is.geometryOf(t,e),new wn({map:e.texture,transparent:!0,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1})),t.kind==="panorama"&&(n.material.side=Qe),n.frustumCulled=!1,n.layers.set(oy),n.userData.id=t.id,n.quaternion.copy(is.orientation(t)),this.scene.add(n),this.meshes.set(t.id,n),this.signatures.set(t.id,i),this.applyOpacity(n,t.id)}static geometryOf(t,e){if(t.kind==="panorama"){const r=new pi(Eh,64,32,Math.PI/2,Math.PI*2),o=r.attributes.uv;for(let c=0;c<o.count;c++)o.setX(c,1-o.getX(c));return o.needsUpdate=!0,r}const i=2*Eh*Math.tan(t.registration.fovDeg/2*Dc),n=i*(e.width/Math.max(e.height,1)),s=new dn(n,i);return s.translate(0,0,-Eh),s}static orientation(t){const{headingDeg:e,pitchDeg:i,rollDeg:n}=t.registration,s=new ti;return s.rotation.set(i*Dc,-e*Dc,-(n??0)*Dc,"YXZ"),s.quaternion}opacityOf(t){const e=this.references.find(s=>s.id===t),i=this.views.get(t),n=e?is.presenceAt(e,this.observerAt):1;return(i?.opacity??e?.opacity??0)*n}applyOpacity(t,e){const i=this.opacityOf(e);t.material.opacity=i,t.visible=this.shown&&i>0}static signatureOf(t,e){const{headingDeg:i,pitchDeg:n,rollDeg:s,fovDeg:r}=t.registration;return[t.kind,t.src,e.width,e.height,i,n,s??0,r].join("|")}dispose(t){this.scene.remove(t),t.geometry.dispose(),t.material.dispose()}disposeAll(){for(const t of this.meshes.values())this.dispose(t);this.meshes.clear(),this.signatures.clear();for(const t of this.images.values())t.texture.dispose();this.images.clear()}}class zt{static GROUND_RADIUS_M=636e4;static TOP_RADIUS_M=646e4;static WAVELENGTHS_NM=Array.from({length:15},(t,e)=>410+20*e);static WAVELENGTH_STEP_NM=20;static SOLAR_IRRADIANCE=[1.707,1.676,1.982,2.02,1.941,1.87,1.879,1.856,1.839,1.799,1.728,1.668,1.57,1.532,1.452];static OZONE_CROSS_SECTION=[.021,.069,.19,.418,.827,1.531,2.439,3.291,4.468,4.55,4.663,3.477,2.447,1.658,1.071];static RAYLEIGH_SCALE_HEIGHT_M=8e3;static AEROSOL_SCALE_HEIGHT_M=1200;static OZONE_PEAK_ALTITUDE_M=25e3;static OZONE_HALF_WIDTH_M=15e3;static DEFAULT_AEROSOL_OPTICAL_DEPTH=.1;static DEFAULT_OZONE_DOBSON=300;static AEROSOL_SINGLE_SCATTERING_ALBEDO=.9;static AEROSOL_ANGSTROM_EXPONENT=1.3;static AEROSOL_ASYMMETRY=.8;rayleighScattering;aerosolScattering;aerosolExtinction;ozoneAbsorption;constructor(t={}){const e=zt.WAVELENGTHS_NM.length,i=t.aerosolOpticalDepth??zt.DEFAULT_AEROSOL_OPTICAL_DEPTH,n=t.ozoneDobson??zt.DEFAULT_OZONE_DOBSON;this.rayleighScattering=new Float64Array(e),this.aerosolScattering=new Float64Array(e),this.aerosolExtinction=new Float64Array(e),this.ozoneAbsorption=new Float64Array(e);const s=n*2687e17/zt.OZONE_HALF_WIDTH_M;for(let r=0;r<e;r++){const o=zt.WAVELENGTHS_NM[r];this.rayleighScattering[r]=zt.rayleighAt(o);const c=i/zt.AEROSOL_SCALE_HEIGHT_M*(o/550)**-1.3;this.aerosolExtinction[r]=c,this.aerosolScattering[r]=c*zt.AEROSOL_SINGLE_SCATTERING_ALBEDO,this.ozoneAbsorption[r]=zt.OZONE_CROSS_SECTION[r]*1e-25*s}}static rayleighAt(t){const e=t/1e3,i=1/(e*e),n=e*e;return(1.0455996-341.29061*i-.9023085*n)/(1+.0027059889*i-85.968563*n)*1e-28*1e-4*2546899e19}static rayleighDensity(t){return Math.exp(-Math.max(t,0)/zt.RAYLEIGH_SCALE_HEIGHT_M)}static aerosolDensity(t){return Math.exp(-Math.max(t,0)/zt.AEROSOL_SCALE_HEIGHT_M)}static ozoneDensity(t){return Math.max(0,1-Math.abs(t-zt.OZONE_PEAK_ALTITUDE_M)/zt.OZONE_HALF_WIDTH_M)}static rayleighPhase(t){return 3/(16*Math.PI)*(1+t*t)}static aerosolPhase(t,e=zt.AEROSOL_ASYMMETRY){const i=e*e;return 3/(8*Math.PI)*(1-i)*(1+t*t)/((2+i)*Math.pow(Math.max(1+i-2*e*t,1e-6),1.5))}}class Xt{static TRANSMITTANCE_WIDTH=256;static TRANSMITTANCE_HEIGHT=64;static MULTIPLE_SIZE=64;static MULTIPLE_ROWS=16;static MULTIPLE_HEIGHT_POWER=2;static MULTIPLE_DIRECTIONS=16;static SKY_VIEW_WIDTH=192;static SKY_VIEW_HEIGHT=108;static STEPS=40;static MULTIPLE_STEPS=12;static GROUND_ALBEDO=.3;supported;renderer;transmittance;multiple;sunView;moonView;scene=new Gs;camera=new ps(-1,1,1,-1,0,1);quad;transmittanceMaterial;multipleMaterial;skyViewMaterial;transmittanceReady=!1;multipleRows=0;multipleColumn=0;mediumKey="";static MULTIPLE_BLOCK=16;static shared=new Map;building=!1;adopted;tableUniforms;constructor(t){this.renderer=t,this.supported=t.capabilities.isWebGL2&&t.extensions.has("EXT_color_buffer_float"),this.transmittance=new oi(Xt.TRANSMITTANCE_WIDTH,Xt.TRANSMITTANCE_HEIGHT,{count:4,type:qe,minFilter:de,magFilter:de,depthBuffer:!1}),this.multiple=new oi(Xt.MULTIPLE_SIZE,Xt.MULTIPLE_ROWS,{count:4,type:ji,minFilter:Ue,magFilter:Ue,depthBuffer:!1});const e=()=>new oi(Xt.SKY_VIEW_WIDTH,Xt.SKY_VIEW_HEIGHT,{type:ji,minFilter:Ue,magFilter:Ue,depthBuffer:!1});this.sunView=e(),this.moonView=e();const i=Xt.mediumUniforms(),n=this.tableUniforms={uT0:{value:this.transmittance.textures[0]},uT1:{value:this.transmittance.textures[1]},uT2:{value:this.transmittance.textures[2]},uT3:{value:this.transmittance.textures[3]},uM0:{value:this.multiple.textures[0]},uM1:{value:this.multiple.textures[1]},uM2:{value:this.multiple.textures[2]},uM3:{value:this.multiple.textures[3]}},s=(r,o={})=>new a2({glslVersion:Ru,uniforms:{...i,...n,...o},vertexShader:Xt.VERTEX,fragmentShader:r,depthTest:!1,depthWrite:!1});this.transmittanceMaterial=s(Xt.TRANSMITTANCE_FRAGMENT),this.multipleMaterial=s(Xt.MULTIPLE_FRAGMENT),this.skyViewMaterial=s(Xt.SKY_VIEW_FRAGMENT,{uObserverRadius:{value:zt.GROUND_RADIUS_M+2},uSourceMu:{value:1}}),this.quad=new At(new dn(2,2),this.transmittanceMaterial),this.quad.frustumCulled=!1,this.scene.add(this.quad)}get transmittanceTextures(){return this.transmittance.textures}get sunViewTexture(){return this.sunView.texture}get moonViewTexture(){return this.moonView.texture}get ready(){return this.supported&&(this.adopted!==void 0||this.transmittanceReady&&this.multipleRows>=Xt.MULTIPLE_ROWS)}setMedium(t){const e=[t.rayleighScattering,t.aerosolScattering,t.aerosolExtinction,t.ozoneAbsorption].map(n=>Array.from(n,s=>s.toPrecision(6)).join(",")).join("|");if(e===this.mediumKey)return;this.abandonBuilding(),this.releaseAdopted(),this.mediumKey=e;const i=(n,s)=>{const r=this.transmittanceMaterial.uniforms[n].value;for(let o=0;o<4;o++)r[o].set(s[o*4]??0,s[o*4+1]??0,s[o*4+2]??0,s[o*4+3]??0)};i("uRayleigh",t.rayleighScattering),i("uAerosolScattering",t.aerosolScattering),i("uAerosolExtinction",t.aerosolExtinction),i("uOzone",t.ozoneAbsorption),this.transmittanceReady=!1,this.multipleRows=0,this.multipleColumn=0}invalidate(){this.adopted||(this.abandonBuilding(),this.transmittanceReady=!1,this.multipleRows=0,this.multipleColumn=0)}advance(t){if(!this.supported||!this.mediumKey)return!1;if(this.ready)return!0;const e=Xt.shared.get(this.mediumKey);if(e&&e!=="building")return this.adopt(e),!0;if(e==="building"&&!this.building)return!1;e||(Xt.shared.set(this.mediumKey,"building"),this.building=!0);const i=this.renderer.getRenderTarget();let n=Math.max(1,t);this.transmittanceReady||(this.draw(this.transmittanceMaterial,this.transmittance),this.transmittanceReady=!0,n--);const s=Xt.MULTIPLE_SIZE,r=Xt.MULTIPLE_BLOCK;for(;n>0&&this.multipleRows<Xt.MULTIPLE_ROWS;n--)this.multiple.scissor.set(this.multipleColumn,this.multipleRows,r,1),this.multiple.scissorTest=!0,this.draw(this.multipleMaterial,this.multiple),this.multipleColumn+=r,this.multipleColumn>=s&&(this.multipleColumn=0,this.multipleRows++);return this.multiple.scissorTest=!1,this.renderer.setRenderTarget(i),this.ready&&this.building&&this.share(this.mediumKey),this.ready}async share(t){this.building=!1;try{const e=await Promise.all([0,1,2,3].map(n=>this.readRaw(this.transmittance,n,Uint16Array))),i=await Promise.all([0,1,2,3].map(n=>this.readRaw(this.multiple,n,Float32Array)));this.mediumKey===t?Xt.shared.set(t,{transmittance:e,multiple:i}):Xt.shared.delete(t)}catch{Xt.shared.delete(t)}}async readRaw(t,e,i){const n=new i(t.width*t.height*4);return await this.renderer.readRenderTargetPixelsAsync(t,0,0,t.width,t.height,n,void 0,e),n}adopt(t){const e=(s,r,o,c)=>{const l=new Vs(s,r,o,Gi,c?qe:ji);return l.minFilter=l.magFilter=c?de:Ue,l.needsUpdate=!0,l},i=t.transmittance.map(s=>e(s,Xt.TRANSMITTANCE_WIDTH,Xt.TRANSMITTANCE_HEIGHT,!0)),n=t.multiple.map(s=>e(s,Xt.MULTIPLE_SIZE,Xt.MULTIPLE_ROWS,!1));i.forEach((s,r)=>this.tableUniforms[`uT${r}`].value=s),n.forEach((s,r)=>this.tableUniforms[`uM${r}`].value=s),this.adopted=[...i,...n]}releaseAdopted(){if(this.adopted){for(const t of this.adopted)t.dispose();this.adopted=void 0;for(let t=0;t<4;t++)this.tableUniforms[`uT${t}`].value=this.transmittance.textures[t],this.tableUniforms[`uM${t}`].value=this.multiple.textures[t]}}abandonBuilding(){this.building&&(this.building=!1,Xt.shared.get(this.mediumKey)==="building"&&Xt.shared.delete(this.mediumKey))}renderSkyViews(t,e,i){if(!this.ready)return;const n=this.renderer.getRenderTarget(),s=this.skyViewMaterial.uniforms;s.uObserverRadius.value=zt.GROUND_RADIUS_M+Math.max(t,2),s.uSourceMu.value=Math.sin(e*Math.PI/180),this.draw(this.skyViewMaterial,this.sunView),s.uSourceMu.value=Math.sin(i*Math.PI/180),this.draw(this.skyViewMaterial,this.moonView),this.renderer.setRenderTarget(n)}static skyViewUv(t,e,i){const n=zt.GROUND_RADIUS_M+Math.max(t,2),s=zt.GROUND_RADIUS_M,r=Math.acos(Math.min(Math.sqrt(Math.max(n*n-s*s,0))/n,1)),o=Math.PI-r,c=e<o?.5*(1-Math.sqrt(Math.max(1-e/o,0))):.5+.5*Math.sqrt(Math.min((e-o)/r,1));return{u:Math.min(Math.max(Math.abs(i)/Math.PI,0),1),v:c}}async readTable(t,e){if(t==="multiple"){const s=new Float32Array(this.multiple.width*this.multiple.height*4);return await this.renderer.readRenderTargetPixelsAsync(this.multiple,0,0,this.multiple.width,this.multiple.height,s,void 0,e),s}const i=this.transmittance,n=new Uint16Array(i.width*i.height*4);return await this.renderer.readRenderTargetPixelsAsync(i,0,0,i.width,i.height,n,void 0,e),Float32Array.from(n,s=>kn.fromHalfFloat(s))}readSkyViewNow(t){const e=t==="sun"?this.sunView:this.moonView,i=new Float32Array(e.width*e.height*4),n=this.renderer.getContext();return n.bindBuffer(n.PIXEL_PACK_BUFFER,null),this.renderer.readRenderTargetPixels(e,0,0,e.width,e.height,i),i}async readSkyView(t){const e=t==="sun"?this.sunView:this.moonView,i=new Float32Array(e.width*e.height*4);return await this.renderer.readRenderTargetPixelsAsync(e,0,0,e.width,e.height,i),i}dispose(){this.abandonBuilding(),this.releaseAdopted(),this.transmittance.dispose(),this.multiple.dispose(),this.sunView.dispose(),this.moonView.dispose(),this.transmittanceMaterial.dispose(),this.multipleMaterial.dispose(),this.skyViewMaterial.dispose(),this.quad.geometry.dispose()}draw(t,e){this.quad.material=t,this.renderer.setRenderTarget(e),this.renderer.render(this.scene,this.camera)}static mediumUniforms(){const t=()=>[new ue,new ue,new ue,new ue],e=(i,n)=>{const s=t();return zt.WAVELENGTHS_NM.forEach((r,o)=>{s[Math.floor(o/4)].setComponent(o%4,i(r)*n*zt.WAVELENGTH_STEP_NM*zt.SOLAR_IRRADIANCE[o])}),s};return{uRayleigh:{value:t()},uAerosolScattering:{value:t()},uAerosolExtinction:{value:t()},uOzone:{value:t()},uCieX:{value:e(i=>Pi.colourMatching(i)[0],683)},uCieY:{value:e(i=>Pi.colourMatching(i)[1],683)},uCieZ:{value:e(i=>Pi.colourMatching(i)[2],683)},uScotopic:{value:e(i=>Pi.scotopic(i),1700)}}}static VERTEX=`
8208
8208
  in vec3 position;
8209
8209
  void main() {
8210
8210
  gl_Position = vec4(position.xy, 0.0, 1.0);
@@ -8670,7 +8670,7 @@ void main() {`).replace("#include <opaque_fragment>",`
8670
8670
  float brightness = uCoefficient * pow(radii, -uExponent) * (1.0 - moonCover(direction)) * fade;
8671
8671
  gl_FragColor = vec4(uRadiance * brightness, 1.0);
8672
8672
  }
8673
- `,transparent:!0,blending:Pi,depthWrite:!1,side:Qe,fog:!1});this.object=new At(new pi(Ui.RADIUS,96,32,0,Math.PI*2,0,i),n),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(t,e){if(!t){this.object.visible=!1;return}const i=this.object.material.uniforms;this.towards.set(t.x,t.y,t.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),i.uSun.value.copy(this.towards),i.uRadiance.value.set(e[0],e[1],e[2]),this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class ye{static HAZE_COARSE_MODE={medianRadiusUm:1.5,geometricSigma:2};static CLOUD_DROPLETS={medianRadiusUm:8,geometricSigma:1.15};static COARSE_FRACTION=.3;static DIFFRACTED_SHARE=.5;static MAX_ANGLE_RAD=30*Math.PI/180;static STEPS=512;static RADII=32;static bessel1(t){const e=Math.abs(t);if(e<8){const l=t*t,h=t*(72362614232+l*(-7895059235+l*(2423968531e-1+l*(-2972611439e-3+l*(15704.4826+l*-30.16036606))))),u=144725228442+l*(2300535178+l*(1858330474e-2+l*(99447.43394+l*(376.9991397+l))));return h/u}const i=8/e,n=i*i,s=e-2.356194491,r=1+n*(.00183105+n*(-3516396496e-14+n*(2457520174e-15+n*-240337019e-15))),o=.04687499995+n*(-.0002002690873+n*(8449199096e-15+n*(-88228987e-14+n*105787412e-15))),c=Math.sqrt(.636619772/e)*(Math.cos(s)*r-i*Math.sin(s)*o);return t<0?-c:c}static airy(t){if(Math.abs(t)<1e-6)return 1;const e=2*ye.bessel1(t)/t;return e*e}static phaseOf(t,e,i){const n=2*Math.PI*e*1e3/i;return n*n/(4*Math.PI)*ye.airy(n*Math.sin(t))}static phase(t,e,i){let n=0,s=0;for(const{radiusUm:r,weight:o}of ye.radiiOf(i))n+=o*ye.phaseOf(t,r,e),s+=o;return n/s}static profile(t){const e=`${t.medianRadiusUm}:${t.geometricSigma}`,i=ye.profiles.get(e);if(i)return i;const n=ye.STEPS,s=new Float32Array(n*3),r=ye.radiiOf(t),o=r.reduce((c,{weight:l})=>c+l,0);for(let c=0;c<n;c++){const l=c/(n-1)*ye.MAX_ANGLE_RAD;let h=0,u=0,d=0;for(const f of Ci.SAMPLES){let p=0;for(const{radiusUm:v,weight:m}of r)p+=m*ye.phaseOf(l,v,f.wavelengthNm);p/=o,h+=p*f.r,u+=p*f.g,d+=p*f.b}s[c*3]=h,s[c*3+1]=u,s[c*3+2]=d}return ye.profiles.set(e,s),s}static profiles=new Map;static radiiOf(t){const e=ye.RADII,i=Math.log(Math.max(t.geometricSigma,1.0001)),n=[];for(let s=0;s<e;s++){const r=-3+6*(s+.5)/e;n.push({radiusUm:t.medianRadiusUm*Math.exp(r*i),weight:Math.exp(-.5*r*r)})}return n}static illuminanceOf(t){return 10**((-14.18-t)/2.5)}static aureoleScale(t,e){const i=t*e;return ye.DIFFRACTED_SHARE*ye.COARSE_FRACTION*i*Math.exp(-i)}static coronaScale(t){return ye.DIFFRACTED_SHARE*t*Math.exp(-t)}static airMass(t){const e=Math.max(t,0);return 1/(Math.sin(e*Math.PI/180)+.50572*(e+6.07995)**-1.6364)}}class Pn{static EARTH_RADIUS_M=6371e3;static DEG=Math.PI/180;static SUN_DISC_DEG=.54;static HORIZON_REFRACTION_DEG=.57;static dipDeg(t){return Math.acos(Pn.EARTH_RADIUS_M/(Pn.EARTH_RADIUS_M+Math.max(t,0)))/Pn.DEG}static sunElevationDeg(t,e,i){const n=Pn.DEG,s=e.lat*n,r=e.lng*n,o=t.altitudeDeg*n,c=t.azimuthDeg*n,l=[-Math.sin(r),Math.cos(r),0],h=[-Math.sin(s)*Math.cos(r),-Math.sin(s)*Math.sin(r),Math.cos(s)],u=[Math.cos(s)*Math.cos(r),Math.cos(s)*Math.sin(r),Math.sin(s)],d=[0,1,2].map(g=>l[g]*Math.sin(c)*Math.cos(o)+h[g]*Math.cos(c)*Math.cos(o)+u[g]*Math.sin(o)),f=i.lat*n,p=i.lng*n,v=[Math.cos(f)*Math.cos(p),Math.cos(f)*Math.sin(p),Math.sin(f)],m=d[0]*v[0]+d[1]*v[1]+d[2]*v[2];return Math.asin(Math.max(-1,Math.min(1,m)))/n}static litFraction(t,e){const i=t+Pn.dipDeg(e)+Pn.HORIZON_REFRACTION_DEG,n=Math.min(1,Math.max(0,i/Pn.SUN_DISC_DEG+.5));return n*n*(3-2*n)}}class Xn{static ID_PREFIX="traffic-";static keyOf(t){return`${t.nonIcao?"x":""}${t.icao.toString(16).padStart(6,"0")}`}static idOf(t,e){return`${Xn.ID_PREFIX}${Xn.keyOf(t)}-${e}`}}class fm{static RADIUS=Ui.RADIUS;object;texels;texture;up=new R(0,1,0);towards=new R;constructor(){const t=ye.STEPS;this.texels=new Uint16Array(t*4),this.texture=new Vs(this.texels,t,1,Gi,qe),this.texture.minFilter=de,this.texture.magFilter=de,this.texture.wrapS=Bi,this.texture.wrapT=Bi,this.texture.needsUpdate=!0;const e=new Me({uniforms:{uSource:{value:new R(0,1,0)},uMaxAngle:{value:ye.MAX_ANGLE_RAD},uMap:{value:this.texture},uSteps:{value:t}},vertexShader:`
8673
+ `,transparent:!0,blending:Ti,depthWrite:!1,side:Qe,fog:!1});this.object=new At(new pi(Ui.RADIUS,96,32,0,Math.PI*2,0,i),n),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(t,e){if(!t){this.object.visible=!1;return}const i=this.object.material.uniforms;this.towards.set(t.x,t.y,t.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),i.uSun.value.copy(this.towards),i.uRadiance.value.set(e[0],e[1],e[2]),this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}class ye{static HAZE_COARSE_MODE={medianRadiusUm:1.5,geometricSigma:2};static CLOUD_DROPLETS={medianRadiusUm:8,geometricSigma:1.15};static COARSE_FRACTION=.3;static DIFFRACTED_SHARE=.5;static MAX_ANGLE_RAD=30*Math.PI/180;static STEPS=512;static RADII=32;static bessel1(t){const e=Math.abs(t);if(e<8){const l=t*t,h=t*(72362614232+l*(-7895059235+l*(2423968531e-1+l*(-2972611439e-3+l*(15704.4826+l*-30.16036606))))),u=144725228442+l*(2300535178+l*(1858330474e-2+l*(99447.43394+l*(376.9991397+l))));return h/u}const i=8/e,n=i*i,s=e-2.356194491,r=1+n*(.00183105+n*(-3516396496e-14+n*(2457520174e-15+n*-240337019e-15))),o=.04687499995+n*(-.0002002690873+n*(8449199096e-15+n*(-88228987e-14+n*105787412e-15))),c=Math.sqrt(.636619772/e)*(Math.cos(s)*r-i*Math.sin(s)*o);return t<0?-c:c}static airy(t){if(Math.abs(t)<1e-6)return 1;const e=2*ye.bessel1(t)/t;return e*e}static phaseOf(t,e,i){const n=2*Math.PI*e*1e3/i;return n*n/(4*Math.PI)*ye.airy(n*Math.sin(t))}static phase(t,e,i){let n=0,s=0;for(const{radiusUm:r,weight:o}of ye.radiiOf(i))n+=o*ye.phaseOf(t,r,e),s+=o;return n/s}static profile(t){const e=`${t.medianRadiusUm}:${t.geometricSigma}`,i=ye.profiles.get(e);if(i)return i;const n=ye.STEPS,s=new Float32Array(n*3),r=ye.radiiOf(t),o=r.reduce((c,{weight:l})=>c+l,0);for(let c=0;c<n;c++){const l=c/(n-1)*ye.MAX_ANGLE_RAD;let h=0,u=0,d=0;for(const f of Pi.SAMPLES){let p=0;for(const{radiusUm:v,weight:m}of r)p+=m*ye.phaseOf(l,v,f.wavelengthNm);p/=o,h+=p*f.r,u+=p*f.g,d+=p*f.b}s[c*3]=h,s[c*3+1]=u,s[c*3+2]=d}return ye.profiles.set(e,s),s}static profiles=new Map;static radiiOf(t){const e=ye.RADII,i=Math.log(Math.max(t.geometricSigma,1.0001)),n=[];for(let s=0;s<e;s++){const r=-3+6*(s+.5)/e;n.push({radiusUm:t.medianRadiusUm*Math.exp(r*i),weight:Math.exp(-.5*r*r)})}return n}static illuminanceOf(t){return 10**((-14.18-t)/2.5)}static aureoleScale(t,e){const i=t*e;return ye.DIFFRACTED_SHARE*ye.COARSE_FRACTION*i*Math.exp(-i)}static coronaScale(t){return ye.DIFFRACTED_SHARE*t*Math.exp(-t)}static airMass(t){const e=Math.max(t,0);return 1/(Math.sin(e*Math.PI/180)+.50572*(e+6.07995)**-1.6364)}}class Pn{static EARTH_RADIUS_M=6371e3;static DEG=Math.PI/180;static SUN_DISC_DEG=.54;static HORIZON_REFRACTION_DEG=.57;static dipDeg(t){return Math.acos(Pn.EARTH_RADIUS_M/(Pn.EARTH_RADIUS_M+Math.max(t,0)))/Pn.DEG}static sunElevationDeg(t,e,i){const n=Pn.DEG,s=e.lat*n,r=e.lng*n,o=t.altitudeDeg*n,c=t.azimuthDeg*n,l=[-Math.sin(r),Math.cos(r),0],h=[-Math.sin(s)*Math.cos(r),-Math.sin(s)*Math.sin(r),Math.cos(s)],u=[Math.cos(s)*Math.cos(r),Math.cos(s)*Math.sin(r),Math.sin(s)],d=[0,1,2].map(g=>l[g]*Math.sin(c)*Math.cos(o)+h[g]*Math.cos(c)*Math.cos(o)+u[g]*Math.sin(o)),f=i.lat*n,p=i.lng*n,v=[Math.cos(f)*Math.cos(p),Math.cos(f)*Math.sin(p),Math.sin(f)],m=d[0]*v[0]+d[1]*v[1]+d[2]*v[2];return Math.asin(Math.max(-1,Math.min(1,m)))/n}static litFraction(t,e){const i=t+Pn.dipDeg(e)+Pn.HORIZON_REFRACTION_DEG,n=Math.min(1,Math.max(0,i/Pn.SUN_DISC_DEG+.5));return n*n*(3-2*n)}}class Xn{static ID_PREFIX="traffic-";static keyOf(t){return`${t.nonIcao?"x":""}${t.icao.toString(16).padStart(6,"0")}`}static idOf(t,e){return`${Xn.ID_PREFIX}${Xn.keyOf(t)}-${e}`}}class fm{static RADIUS=Ui.RADIUS;object;texels;texture;up=new R(0,1,0);towards=new R;constructor(){const t=ye.STEPS;this.texels=new Uint16Array(t*4),this.texture=new Vs(this.texels,t,1,Gi,qe),this.texture.minFilter=de,this.texture.magFilter=de,this.texture.wrapS=Bi,this.texture.wrapT=Bi,this.texture.needsUpdate=!0;const e=new Me({uniforms:{uSource:{value:new R(0,1,0)},uMaxAngle:{value:ye.MAX_ANGLE_RAD},uMap:{value:this.texture},uSteps:{value:t}},vertexShader:`
8674
8674
  varying vec3 vDirection;
8675
8675
  void main() {
8676
8676
  vDirection = normalize((modelMatrix * vec4(position, 1.0)).xyz - cameraPosition);
@@ -8691,7 +8691,7 @@ void main() {`).replace("#include <opaque_fragment>",`
8691
8691
  vec3 light = texture2D(uMap, vec2((along * (uSteps - 1.0) + 0.5) / uSteps, 0.5)).rgb;
8692
8692
  gl_FragColor = vec4(light, 1.0);
8693
8693
  }
8694
- `,transparent:!0,blending:Pi,depthWrite:!1,side:Qe,fog:!1});this.object=new At(new pi(fm.RADIUS,128,32,0,Math.PI*2,0,ye.MAX_ANGLE_RAD),e),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(t,e){if(!t||!e){this.object.visible=!1;return}this.towards.set(t.x,t.y,t.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),this.object.material.uniforms.uSource.value.copy(this.towards);for(let i=0;i<ye.STEPS;i++){for(let n=0;n<3;n++)this.texels[i*4+n]=kn.toHalfFloat(Math.min(e[i*3+n],6e4));this.texels[i*4+3]=kn.toHalfFloat(1)}this.texture.needsUpdate=!0,this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose()}}class Vu{constructor(t){this.generator=t}static SIZE=128;target=new fl(Vu.SIZE,{type:qe,generateMipmaps:!1,minFilter:de,magFilter:de});camera=new Kp(.1,2e5,this.target);filteredTarget;capturedAtMs=-1/0;capturedVersion;get sharp(){return this.target.texture}get filtered(){return this.filteredTarget?.texture}capture(t,e,i,n=[]){const s=t.shadowMap.autoUpdate;let r=!1;e.traverse(c=>{const l=c;l.isLight&&l.castShadow&&l.shadow&&!l.shadow.map&&(r=!0)}),t.shadowMap.autoUpdate=r?s:!1;const o=n.map(c=>c.visible);for(const c of n)c.visible=!1;this.camera.position.copy(i),this.camera.update(t,e),n.forEach((c,l)=>{c.visible=o[l]}),t.shadowMap.autoUpdate=s,this.filteredTarget=this.generator.fromCubemap(this.target.texture,this.filteredTarget),this.capturedAtMs=performance.now()}dispose(){this.target.dispose(),this.filteredTarget?.dispose()}}class Mn{static REFRESH_MS=250;generator;eye;probes=new Map;constructor(t){Mn.install(),this.generator=new B0(t),this.eye=new Vu(this.generator)}static decor;refresh(t,e,i,n,s,r,o,c=[],l,h=Mn.REFRESH_MS){for(const m of[...this.probes.keys()])n.some(g=>g.id===m&&g.shiny)||(this.probes.get(m).dispose(),this.probes.delete(m));const u=[{probe:this.eye}];for(const m of n){if(!m.shiny)continue;let g=this.probes.get(m.id);g||(g=new Vu(this.generator),this.probes.set(m.id,g)),u.push({probe:g,reflector:m})}const d=performance.now(),f=()=>u.filter(({probe:m})=>m.capturedVersion!==o),p=f().filter(({probe:m})=>d-m.capturedAtMs>=h);if(p.length>0){const m=p.reduce((g,b)=>b.probe.capturedAtMs<g.probe.capturedAtMs?b:g);if(m.reflector){const g=m.reflector.holder.getWorldPosition(this.scratch);m.probe.capture(t,e,g,[m.reflector.holder,...s]),Mn.reflectOn(m.reflector.holder,m.probe)}else{m.probe.capture(t,e,i,[...s,...c]),l?.(m.probe.sharp),Mn.decor=m.probe.filtered;for(const g of r)Mn.reflectOn(g,m.probe);for(const g of n)g.shiny||Mn.reflectOn(g.holder,m.probe)}m.probe.capturedVersion=o}const v=f();if(v.length!==0)return Math.max(16,Math.min(...v.map(({probe:m})=>h-(d-m.capturedAtMs))))}scratch=new R;static reflectOn(t,e={filtered:Mn.decor}){t.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[])s instanceof vl?e.sharp&&s.setSurroundings(e.sharp):s instanceof Nr&&e.filtered&&s.envMap!==e.filtered&&(s.envMap=e.filtered,s.needsUpdate=!0)})}dispose(){this.eye.dispose();for(const t of this.probes.values())t.dispose();this.generator.dispose()}static installed=!1;static install(){if(Mn.installed)return;Mn.installed=!0;const t="iblIrradiance += getIBLIrradiance( geometryNormal );";if(!Zt.lights_fragment_maps.includes(t)){console.warn("Reflections: three's lights_fragment_maps changed; the environment will light diffusely too");return}Zt.lights_fragment_maps=Zt.lights_fragment_maps.replace(t,"// The sky's diffuse light is the hemisphere light's (see Reflections).")}}function OR(a,t){return JSON.stringify(a.cloudLayers)===JSON.stringify(t.cloudLayers)&&a.cloudCover===t.cloudCover&&a.cloudDarkness===t.cloudDarkness&&a.cloudBaseM===t.cloudBaseM&&a.highCloudCover===t.highCloudCover&&a.iceCrystalAlignment===t.iceCrystalAlignment&&a.lowerCloudCover===t.lowerCloudCover&&a.relativeHumidity===t.relativeHumidity&&a.precipitationType===t.precipitationType&&a.precipitationIntensity===t.precipitationIntensity&&a.precipitationAmount===t.precipitationAmount&&a.windDirectionDeg===t.windDirectionDeg&&a.windSpeed===t.windSpeed&&a.storm===t.storm}const Ah=900,xf=1,yv=4,bf=5,xv=.5,Bc=900,LR=6371e3,NR=3e4;function bv(a){const t=Math.sqrt(2*LR*Math.max(a,0));return Math.max(Bc,Math.min(t,NR))}const Sf=.5,wf=850,_f=.03,kR=.015,pn=850,Ic=300,Ar=120,FR=700,UR=.04,Sv=4,Ef=1.5,wv=-1,zR=.01,Jh=-4,BR=2,HR=20,Th=2600,GR=.97,VR=.38,Rh=Jh,_v=1500,WR=400,XR=[0,45,90,135,180,225,270,315],YR=2,qR=16,Ev=4e3,Av=880,Dh=40,Tv=60,$R=10,KR=1,ZR=150,JR=55,jR=.5,QR=17,Rv=.265,Dv=[[0,0],...Array.from({length:8},(a,t)=>{const e=t*Math.PI/4;return[Math.cos(e)*Rv,Math.sin(e)*Rv]})],Af=700,Tf=250/Mp,tD=12,Iv=5,Rf=6,ia=[.92,.92,.95],Df=[.15,.15,.19],If={snow:{fallSpeedMPerS:2,size:.3,color:new st(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new st(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},To=0,Cf=0,eD=150,Pf=3e3,Cc=20,iD=15,Cv=To,nD=40,Pv=1,sD=9;function Of(a){return Pv+(sD-Pv)*a}const Ov=new st(.75,.82,.92),rD=10,aD=.5;function Lv(a){return ir(a/rD,aD,1)}const na=200,Nv=.18,kv=.32,oD=.35,Fv=new st(.85,.9,.98),Uv=5,zv=.85,Bv=.01;function cD(a,t,e=1){return Math.round(a*(Bv+(1-Bv)*t)*e)}function lD(a,t){return JSON.stringify(a.cloudLayers)===JSON.stringify(t.cloudLayers)&&a.cloudCover===t.cloudCover&&a.cloudDarkness===t.cloudDarkness&&a.cloudBaseM===t.cloudBaseM&&a.highCloudCover===t.highCloudCover&&a.iceCrystalAlignment===t.iceCrystalAlignment&&a.lowerCloudCover===t.lowerCloudCover}const Hv=230,Gv=.7,Vv=.05,hD=.6,uD=.7,dD=.15,Wv=.35,fD=3,pD=1/12,mD=.5,Ss=new st(.82,.86,1),gD=2500,vD=1.6,Lf=15,MD={Venus:new st(1,.96,.85),Mars:new st(1,.55,.4),Jupiter:new st(.95,.87,.72),Saturn:new st(.92,.86,.68)};class le{renderer;scene=new Gs;phenomena=new ss(this.scene);references=new is(this.scene,()=>this.render());camera;celestialGroup=new Ee;skyMesh;skyGradientMaterial;scatteredSky;lastAstronomy;skyColoursStale=!1;scatteredSkyFrameId=null;skyHoldUntilMs=void 0;onFirstFrameHold;firstFrameReady(){return(!this.scatteredSky||this.scatteredSky.ambient!==void 0)&&!this.iceHalos?.awaitingFirstDisplay}sceneSettled(){return this.firstFrameReady()&&this.arrivalsPending===0&&this.eyeSettledVersion>=this.lastArrivalVersion}arrivalsPending=0;eyeSettledVersion=-1;lastArrivalVersion=0;awaitArrival(t,e){if(this.skyHoldUntilMs===null)return t;this.arrivalsPending++;let i=!0;const n=()=>{i&&(i=!1,this.arrivalsPending--,this.lastArrivalVersion=this.sceneVersion,this.skyHoldUntilMs&&this.redrawHeld())},s=e===void 0?void 0:setTimeout(n,e);return e!==void 0&&(this.arrivalDeadlineMs=Math.max(this.arrivalDeadlineMs,performance.now()+e),this.skyHoldUntilMs&&this.arrivalDeadlineMs>this.skyHoldUntilMs&&(this.skyHoldUntilMs=this.arrivalDeadlineMs,setTimeout(()=>this.render(),e+20))),t.finally(()=>{clearTimeout(s),n()})}static ROADS_PATIENCE_MS=4e3;static TERRAIN_PATIENCE_MS=12e3;arrivalDeadlineMs=0;redrawHeld(){this.frameDirty=!0,!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))}holdForNewScene(t){this.surroundings=void 0,this.scatteredSky?.resetSurroundings(),this.startHold(),t&&this.awaitArrival(t).catch(()=>{})}startHold(){this.skyHoldUntilMs=Math.max(performance.now()+Ev,this.arrivalDeadlineMs),this.eyeSettledVersion=-1,this.lastArrivalVersion=this.sceneVersion+1,this.iceHalos?.setUrgent(!0),this.skyGlow?.setWithheld(!0),this.onFirstFrameHold?.(!0),setTimeout(()=>this.render(),Ev+20)}groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;roadSystem=new Hn;roadAttribution;roadWays;statedRoads=[];traces=[];traceLabels=new Map;tracesShown=!0;traceSystem;traceSystemLoading;traceResolution=new bt;decorModelProvider=IR[0].create();decorModelToken=0;decorModelCredits=new Map;bodySystem=new he(t=>this.awaitArrival(this.loadBodyModel(t)),()=>this.render(),()=>this.relativeScale);bodyOrigin={x:0,z:0};starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];terraces=[];decorGroups=new Map;decorPresence=new Map;decorSunlight=new Map;static TRAFFIC_MODEL_RANGE_PER_METRE=133;static TRAFFIC_MODEL_DEFAULT_LENGTH_M=37.6;static trafficModelRangeM(t){return(t.sizeM?.lengthM??le.TRAFFIC_MODEL_DEFAULT_LENGTH_M)*le.TRAFFIC_MODEL_RANGE_PER_METRE}pendingTrafficModels=new Map;contrails=[];contrailSystem;contrailSystemLoading;contrailSunlight=new Map;sceneSunBeam=[0,0,0];decorReferencePose;decorCurrentPose;decorTime=0;celestialLight=new h1(16777215,0);celestialLightTarget=new ti;skyLight=new Aw(16777215,0,0);streetlightLights=new Map;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;resolution;cssSize={width:1,height:1};frameDirty=!1;flushFrameId=null;framesDriven=!1;lastFrameTimeMs;raycaster=new qh;weather=Zu;observerElevationM=0;siteElevationM=0;air=new Wn;groundRadius=Bc;terrainRadius=Bc;cloudRendering="volume";layeredClouds;cloudLayerOffsetsM={};cloudOffsetM=new R;cloudFieldOffset=new R;cloudMesh;cirrusMesh;cirrusMaterial;cirrusUniforms;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new R;rainLastVerticalFacing=-1;rainViewportSize=new bt;lightningArmed=!1;lightningFlashes=[];lightningLevel=0;lightningBolt;lightningLight=new h1(16777215,0);baseFogColor=[0,0,0];lastSunPosition;lensFlare;sunUnhiddenFraction=1;lensFlareArtifactIntensity=0;sunWorldPosition=new R;sunVisible=!1;lensFlareScratch=new R;sunOcclusionRaycaster=new qh;sunOcclusionDirectionScratch=new R;sunOcclusionRightScratch=new R;sunOcclusionUpScratch=new R;ufoOcclusionRaycaster=new qh;projectionKind="rectilinear";starPoints=0;namedStars=[];equidistantPass;depthOfFieldPass;finishPass;exposureAccumulation;exposureInstants=1;get developingExposure(){return this.exposureInstants>1&&this.exposureInstantAt!==void 0}static EXPOSURE_BUDGET_MS=12;static exposureInstantsPerFrame(t){return Math.max(3,Math.round(6e6/Math.max(1,t)))}exposureFrameId=null;exposureInstantsDone=0;exposureInstantAt;restatingExposure=!1;lensOptics;instrumentMagnitudeGain=0;lightPollution;meteorSystem;cometTail;satelliteField;reentrySystem;iceHalos;lunarDiffraction;eclipsedSun=new Ml;eclipseDiscs;solarCorona;sunBeamFraction=1;sunDiscRadiance=[0,0,0];lunarDiffractionKey="";rainbow;skyGlow;cometKey;novaKeys=new Set;constructor(t,e=Rb()){this.renderer=new HA({canvas:t,antialias:!0}),this.resolution=new _e(Math.min(window.devicePixelRatio||1,2),this.renderer.getContext()),this.renderer.setPixelRatio(this.resolution.pixelRatio),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Xc,this.camera=new yn(60,t.width/Math.max(t.height,1),.1,Ah*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=e,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-Ar,this.celestialLight.shadow.camera.right=Ar,this.celestialLight.shadow.camera.top=Ar,this.celestialLight.shadow.camera.bottom=-Ar,this.celestialLight.shadow.camera.near=pn-Ic,this.celestialLight.shadow.camera.far=pn+Ic,this.celestialLight.shadow.bias=-.03/(2*Ic),this.celestialLight.shadow.normalBias=UR,this.celestialLight.target=this.celestialLightTarget,this.lightningLight.color.copy(Ss),this.scene.add(this.celestialLight,this.celestialLightTarget,this.skyLight,this.lightningLight),this.scene.add(this.celestialGroup),this.scene.add(this.bodySystem.group),this.scene.add(this.roadSystem.group);const i=new se(this.renderer,()=>{this.skyColoursStale=!0,this.render()});i.supported?this.scatteredSky=i:i.dispose()}get currentTerrainAttribution(){return this.terrainAttribution}get currentRoadAttribution(){return this.roadAttribution}resize(t,e){this.cssSize.width=t,this.cssSize.height=e,this.renderer.setSize(t,e,!1),this.camera.aspect=t/Math.max(e,1),this.camera.updateProjectionMatrix(),this.render()}setCloudRendering(t){t!==this.cloudRendering&&(this.cloudTransmissionMemo.clear(),this.cloudRendering=t,this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.buildClouds(),this.buildCirrus(),this.render())}setCloudOffset(t,e={}){this.cloudOffsetM.set(t.x,0,t.z),this.cloudLayerOffsetsM=e,this.layeredClouds?.setOffsets(t,e),this.cloudFieldOffset.set(t.x*Tf,0,t.z*Tf);for(const i of[this.cloudUniforms,this.cirrusUniforms])i?.fieldOffset.value.copy(this.cloudFieldOffset);this.iceHalos?.setCloudOffset(this.layeredClouds?.cirrusMask?.offset??this.cloudFieldOffset)}setObserverPose(t){const e=((t.rollDeg??0)+this.gaitOffset.rollDeg)*Ei,i=(t.pitchDeg+this.lookPitchDeg+this.gaitOffset.pitchDeg)*Ei;if(t.headingDeg!==void 0?this.camera.rotation.set(i,-(t.headingDeg+this.lookYawDeg+this.gaitOffset.yawDeg)*Ei,e,"YXZ"):this.camera.rotation.set(i,this.camera.rotation.y,e,"YXZ"),t.elevationM!==this.observerElevationM&&(this.observerElevationM=t.elevationM,this.syncCloudLayer(),Math.abs(bv(t.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/Bc),this.camera.far=Math.max(Ah*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.terrainMesh&&this.terrainOrigin&&t.lat!==void 0&&t.lng!==void 0){const n=si(this.terrainOrigin.lat,this.terrainOrigin.lng,t.lat,t.lng);this.terrainMesh.position.x=n.x,this.terrainMesh.position.z=n.z}this.poseElevationM=t.elevationM,this.poseCameraY=this.groundYUnder(0,0)+1.6+t.elevationM,this.camera.position.y=this.poseCameraY,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==t.fovDeg&&(this.camera.fov=t.fovDeg,this.camera.updateProjectionMatrix(),this.updateCompassScale())}setTerrainProviders(t){this.stopTerrainFade(),this.terrainProviders=t,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.roadSystem.clear(),this.roadAttribution=void 0,this.roadWays=void 0,this.applyGroundDepthWrite(),this.terrainBuildToken++}setTerrainOrigin(t,e,i){if(t===void 0||e===void 0)return;const n=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-n)<n*.1){const{x:c,z:l}=si(t,e,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(c*c+l*l)<ZR*(n/Bc))return}const s=this.terrainOrigin,r=this.terrainRadius;(!s||s.lat!==t||s.lng!==e)&&(this.roadSystem.clear(),this.roadAttribution=void 0),this.terrainOrigin={lat:t,lng:e},this.terrainRadius=n;const o=++this.terrainBuildToken;this.awaitArrival(F4(t,e,this.terrainProviders,n),le.TERRAIN_PATIENCE_MS).then(({mesh:c,attribution:l,originElevationM:h})=>{if(o!==this.terrainBuildToken)return;this.setSiteElevation(h??0);const u=this.terrainMesh,d=s?si(t,e,s.lat,s.lng):void 0;u&&d&&Math.hypot(d.x,d.z)<=r&&(c.position.y=u.position.y+this.groundYOfPatch(u,d.x,d.z)),u&&d&&Math.hypot(d.x,d.z)<=r?this.crossfadeTerrain(c,u):this.disposeMesh(this.terrainMesh),c.renderOrder=KR,this.terrainMesh=c,this.compileNextFrameOffThread(),this.terrainAttribution=l,this.scene.add(c),this.applyGroundDepthWrite(),this.decorCurrentPose&&(this.setObserverPose(this.decorCurrentPose),this.updateDecorAnchoring(this.decorReferencePose,this.decorCurrentPose,this.decorTime)),this.buildRoads(t,e,n),this.drapeStatedRoads(),this.drapeTraces(),this.render(),i?.()}).catch(c=>{console.warn("Terrain build failed, keeping the flat ground fallback:",c),i?.()})}static TERRAIN_CROSSFADE_MS=1200;fadingTerrain;crossfadeTerrain(t,e){this.stopTerrainFade();const i=t.material;i.opacity=0,i.polygonOffset=!0,i.polygonOffsetFactor=-1,i.polygonOffsetUnits=-4;const n=performance.now(),s=()=>{const r=Math.min(1,(performance.now()-n)/le.TERRAIN_CROSSFADE_MS);if(i.opacity=r*r*(3-2*r),this.render(),r<1&&this.fadingTerrain){this.fadingTerrain.frameId=requestAnimationFrame(s);return}i.polygonOffset=!1,i.opacity=1,this.fadingTerrain&&this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0,this.render()};this.fadingTerrain={mesh:e,frameId:requestAnimationFrame(s)}}stopTerrainFade(){if(!this.fadingTerrain)return;cancelAnimationFrame(this.fadingTerrain.frameId),this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0;const t=this.terrainMesh?.material;t&&(t.opacity=1,t.polygonOffset=!1)}static ROADS_MAX_RADIUS_M=5e3;buildRoads(t,e,i){const n=this.terrainProviders.roads;if(!n||i>le.ROADS_MAX_RADIUS_M){this.roadSystem.clear(),this.roadAttribution=void 0;return}const s=this.roadWays;if(s&&s.lat===t&&s.lng===e&&s.radiusM===i){this.drapeRoads(s.ways,t,e,n.contemporary);return}this.awaitArrival(n.getRoads(K2(t,e,i)),le.ROADS_PATIENCE_MS).then(r=>{this.terrainOrigin?.lat!==t||this.terrainOrigin?.lng!==e||(this.roadWays={lat:t,lng:e,radiusM:i,ways:r},this.drapeRoads(r,t,e,n.contemporary))}).catch(r=>{console.warn("Roads unavailable, drawing none:",r)})}setStatedRoads(t){t!==this.statedRoads&&(this.statedRoads=t,this.drapeStatedRoads(),this.render())}drapeStatedRoads(){const t=this.terrainMesh;t&&(this.roadSystem.group.position.copy(t.position),this.roadSystem.setStated(this.statedRoads,(e,i)=>this.groundYOfPatch(t,e,i)))}setTraces(t,e=new Map){t===this.traces&&e===this.traceLabels||(this.traces=t,this.traceLabels=e,!(t.length===0&&!this.traceSystem)&&this.loadTraceSystem().then(()=>{this.drapeTraces(),this.render()}))}setTracesShown(t){t!==this.tracesShown&&(this.tracesShown=t,this.drapeTraces(),this.render())}loadTraceSystem(){return this.traceSystemLoading??=je(async()=>{const{TraceSystem:t}=await import("./TraceSystem-B-YEiVUL.js");return{TraceSystem:t}},[],import.meta.url).then(({TraceSystem:t})=>{const e=new t(bf);this.scene.add(e.group),this.traceSystem=e})}drapeTraces(){const t=this.traceSystem,e=this.terrainMesh,i=this.terrainOrigin;!t||!e||!i||(t.group.position.copy(e.position),t.set(this.tracesShown?this.traces:[],this.traceLabels,i.lat,i.lng,this.siteElevationM,(n,s)=>this.groundYOfPatch(e,n,s)))}drapeRoads(t,e,i,n){const s=this.terrainMesh;s&&(this.roadSystem.group.position.copy(s.position),this.roadSystem.set(t,e,i,(r,o)=>this.groundYOfPatch(s,r,o),n),this.roadAttribution=t.length>0?this.terrainProviders.roads?.attribution:void 0,this.compileNextFrameOffThread(),this.render())}setShowCompass(t){this.showCompass!==t&&(this.showCompass=t,this.disposeCompassLabels(),t&&this.buildCompassLabels(),this.render())}setCompassPoints(t){this.compassPoints!==t&&(this.compassPoints=t,this.showCompass&&(this.disposeCompassLabels(),this.buildCompassLabels(),this.render()))}compassPoints;applyLensFlareTint(t){if(!this.lensFlare)return;const e=JR*(this.sunArriving[1]/QR);this.lensFlare.uniforms.uColorGain.value.setRGB(e*t[0],e*t[1],e*t[2]),this.applyDazzleStrength()}applyDazzleStrength(){if(!this.lensFlare)return;const[t,e,i]=this.sunArriving,n=Math.max(e,1e-30);this.lensFlare.uniforms.uDazzleColour.value.setRGB(t/n,1,i/n),this.lensFlare.uniforms.uVeilStrength.value=Ki.K*e*this.sunUnhiddenFraction}sunArriving=[0,0,0];setCompassHovered(t){this.compassHovered!==t&&(this.compassHovered=t,this.updateCompassVisibility())}setCompassForced(t){this.compassForced!==t&&(this.compassForced=t,this.updateCompassVisibility())}updateCompassVisibility(){const t=this.compassHovered||this.compassForced;if(this.compassSprites.some(e=>e.visible!==t)){for(const e of this.compassSprites)e.visible=t;this.developingExposure?this.exposureInstantsDone>0&&this.presentExposure():this.render()}}setWeather(t){if(OR(this.weather,t))return;this.cloudTransmissionMemo.clear();const e=this.weather;this.weather=t;const i=!lD(e,t),n=e.precipitationType!==t.precipitationType,s=e.precipitationIntensity!==t.precipitationIntensity||e.precipitationAmount!==t.precipitationAmount;(e.relativeHumidity!==t.relativeHumidity||n||s)&&(this.air=Wn.of(t),this.applyAir(),this.scatteredSky?.setConditions({aerosolOpticalDepth:t.relativeHumidity===void 0?void 0:Br.steppedOpticalDepth(t.relativeHumidity)}),this.pumpScatteredSky()),i&&(this.buildClouds(),this.buildCirrus()),n?this.buildPrecipitation():s&&this.updatePrecipitationDensity(),this.lastAstronomy&&(i&&(this.buildIceHalos(this.lastAstronomy.sun,this.lastAstronomy.moon),this.buildLunarDiffraction(this.lastAstronomy.moon)),(i||n||s)&&this.buildRainbow(this.lastAstronomy.sun,this.lastAstronomy.moon)),this.lightningArmed=t.storm&&t.cloudDarkness>=mD,this.syncAnimationLoop(),this.render()}setDecor(t){if(this.decorObjects!==t){this.decorObjects=t,this.decorModelToken++,this.decorModelCredits.clear(),this.pendingTrafficModels.clear();for(const e of this.decorGroups.values())e.removeFromParent(),Ye.dispose(e);this.decorGroups.clear(),this.streetlightLights.clear();for(const e of t){const i=Ye.build(e,e.lit??!1);this.scene.add(i),this.decorGroups.set(e.id,i),e.kind==="streetlight"&&this.addStreetlightLight(e.id,i),e.model&&e.id.startsWith(Xn.ID_PREFIX)?(this.pendingTrafficModels.set(e.id,e),this.awaitArrival(this.loadDecorModel(e,this.decorModelToken,!0))):this.reuseLoadedDecorModel(e,i)||this.awaitArrival(this.loadDecorModel(e,this.decorModelToken))}this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}}setDecorSunlight(t){this.decorSunlight=t}setContrails(t){t!==this.contrails&&(this.contrails=t,!(t.length===0&&!this.contrailSystem)&&this.loadContrailSystem().then(()=>{this.contrailSystem?.set(this.contrails),this.updateContrails(),this.render()}))}setContrailSunlight(t){this.contrailSunlight=t}loadContrailSystem(){return this.contrailSystemLoading??=je(async()=>{const{ContrailSystem:t}=await import("./ContrailSystem-CkzapJ6C.js");return{ContrailSystem:t}},__vite__mapDeps([0,1]),import.meta.url).then(({ContrailSystem:t})=>{const e=new t;this.scene.add(e.group),this.contrailSystem=e})}contrailTint(t){const e=this.contrailSunlight.get(t),i=this.lastAstronomy?.sun,n=le.CONTRAIL_SCATTERING,s=this.skyLight.color,r=[s.r*n*.5,s.g*n*.5,s.b*n*.5];if(e&&i){const o=Pn.litFraction(e.sunElevationDeg,e.heightM);if(o>0){const c=this.air.transmittanceFromSpace(e.heightM,e.sunElevationDeg),l=ye.illuminanceOf(i.magnitude)*this.relativeScale;for(let h=0;h<3;h++)r[h]+=n*l*c[h]*o}}return r}static CONTRAIL_SCATTERING=1/(4*Math.PI);updateContrails(){this.contrailSystem?.update(this.decorTime,{origin:this.bodyOrigin,eye:this.camera.position,pixelRad:this.contrailPixelRad()},t=>this.contrailTint(t))}contrailPixelRad(){const t=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.lampBloomRadiusRad()??0,this.camera.fov*Math.PI/180/t)}setDecorPresence(t){this.decorPresence=t}setDecorModelProvider(t){this.decorModelProvider=t;const e=this.decorObjects;this.decorObjects=[],this.setDecor(e)}get currentDecorModelCredits(){return[...this.decorModelCredits.values(),...this.bodySystem.modelCredits]}get bodyGround(){const{x:t,z:e}=this.bodyOrigin,i=this.groundYUnder(t,e);return{heightAt:(n,s)=>this.groundYUnder(t+n,e-s)-i}}setBodies(t,e=0,i=t.map(r=>r.id),n=[],s){const{x:r,z:o}=this.bodyOrigin,c=this.scatteredSky;this.bodySystem.set(t,{originX:r,originZ:o,originGroundY:this.groundYUnder(r,o),eye:this.camera.position,groundYAt:(h,u)=>this.groundYUnder(h,u),wind:s,light:this.plumeLight(),occluders:[...this.decorGroups.values()],transmittance:(h,u,d)=>this.transmittanceTo(h,u,d)},e,c?(h,u)=>c.relativeOfLuminance(h,u):void 0,i),this.bodySystem.setSmoke(n,e),this.bodySystem.any&&(this.celestialLight.castShadow=!0),this.fitShadowToBodies();const l=this.bodySystem.furthestFrom(this.camera.position)*1.2;l>this.camera.far&&(this.camera.far=l,this.camera.updateProjectionMatrix())}plumeLight(){const t=this.celestialLight.color,e=this.celestialLight.intensity*.5,i=this.skyLight.color,n=this.skyLight.groundColor,s=this.skyLight.intensity,r=(o,c,l)=>(o*e+(c+l)/2*s)/Math.PI;return[r(t.r,i.r,n.r),r(t.g,i.g,n.g),r(t.b,i.b,n.b)]}bodyOutline(t,e){return this.bodySystem.outlineOf(t,e)}documentUrl;modelUrl(t){return t.url?this.documentRelative(t.url):void 0}documentRelative(t){if(t.startsWith("data:"))return t;const e=this.documentUrl??(typeof location>"u"?void 0:location.href);return e?new URL(t,e).href:t}async loadBodyModel(t){const e=t.url?void 0:t.id?await this.decorModelProvider.entry(t.id):void 0,i=this.modelUrl(t)??e?.url,n=t.credit??e?.credit;if(!(!i||!n))return{scene:await yf(i),credit:n,headingOffsetDeg:t.headingOffsetDeg??e?.headingOffsetDeg}}loadedDecorModels=new Map;reuseLoadedDecorModel(t,e){const i=this.loadedDecorModels.get(t.id);return!i||i.ref!==JSON.stringify(qf(t))||!Ye.usesModel(t)?!1:(this.applyLoadedDecorModel(t,e,i),!0)}applyLoadedDecorModel(t,e,i){const n=i.scene.clone(!0);n.traverse(s=>{s instanceof At&&(s.userData.sharedModel=!0)}),Ye.applyModel(e,t,n,{headingOffsetDeg:i.headingOffsetDeg,depictedSizeM:i.depictedSizeM}),this.decorModelCredits.set(t.id,i.credit)}standInScenes=new Map;async loadDecorModel(t,e,i=!1){const n=i?gM[t.kind]:qf(t);if(!(!n||!Ye.usesModel(t)))try{const s=n.url?void 0:n.id?await this.decorModelProvider.entry(n.id):void 0,r=this.modelUrl(n)??s?.url,o=n.credit??s?.credit;if(!r||!o)return;const c=i?await this.standInScene(r):await yf(r);if(e!==this.decorModelToken||i&&!this.pendingTrafficModels.has(t.id))return;const l=this.decorGroups.get(t.id);if(!l)return;i||Mn.reflectOn(c);const h={ref:JSON.stringify(n),scene:c,headingOffsetDeg:n.headingOffsetDeg??s?.headingOffsetDeg,depictedSizeM:s?.sizeM,credit:o};i||this.loadedDecorModels.set(t.id,h),this.applyLoadedDecorModel(t,l,h),this.render()}catch(s){console.warn(`Keeping the built-in shape for decor "${t.id}":`,s)}}standInScene(t){let e=this.standInScenes.get(t);return e||(e=yf(t).then(i=>(Mn.reflectOn(i),i)),this.standInScenes.set(t,e)),e}updateDecorAnchoring(t,e,i=0){this.decorReferencePose=t,this.decorCurrentPose=e,this.decorTime=i;const n=t?.lat!==void 0&&t.lng!==void 0&&e?.lat!==void 0&&e?.lng!==void 0?si(t.lat,t.lng,e.lat,e.lng):{x:0,z:0},s=this.decorObjects.find(u=>u.observerSide!==void 0&&mM(u.kind));if(this.terrainMesh&&this.terrainOrigin&&e?.lat!==void 0&&e.lng!==void 0){const u=si(this.terrainOrigin.lat,this.terrainOrigin.lng,e.lat,e.lng);this.terrainMesh.position.x=u.x-(s?0:this.gaitOffset.eastM),this.terrainMesh.position.z=u.z+(s?0:this.gaitOffset.northM),this.roadSystem.group.position.copy(this.terrainMesh.position),this.traceSystem?.group.position.copy(this.terrainMesh.position)}s||(n.x-=this.gaitOffset.eastM,n.z+=this.gaitOffset.northM,this.camera.position.y=this.poseCameraY+this.gaitOffset.upM,this.celestialGroup.position.y=this.camera.position.y);const r={x:0,z:0};let o=0,c;if(s){const u=Hr(s,i),d=Ye.occupantView(s,u.headingDeg),f=-(u.headingDeg??0)*Ei,p=d.x*Math.cos(f)+d.z*Math.sin(f),v=-d.x*Math.sin(f)+d.z*Math.cos(f),m=u.eastM+n.x,g=-u.northM+n.z;r.x=-(m+p),r.z=-(g+v),this.camera.position.y=this.groundYUnder(m,g)+d.eyeY,c=d.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*Ei,-(d.headingDeg+this.indoorLookYawDeg)*Ei,0,"YXZ")}this.bodyOrigin={x:n.x+r.x,z:n.z+r.z},this.placeShadowFrustum(),this.placeTerraces(i,n,r);const l=this.terraces.map(u=>[u.x,u.z,u.cos,u.sin,u.halfWidthM,u.halfLengthM,u.levelY].map(d=>d.toFixed(3)).join(",")).join(";");!s&&this.terraces.length>0&&(this.poseCameraY=this.groundYUnder(0,0)+1.6+this.poseElevationM,this.camera.position.y=this.poseCameraY+this.gaitOffset.upM,this.celestialGroup.position.y=this.camera.position.y);for(const u of this.decorObjects){if(u.kind==="terrace")continue;const d=this.decorGroups.get(u.id);if(!d)continue;const f=Hr(u,i),p=f.eastM+n.x+r.x,v=-f.northM+n.z+r.z,m=this.terrainMesh,g=`${m?.geometry.uuid}:${(p-(m?.position.x??0)).toFixed(3)}:${(v-(m?.position.z??0)).toFixed(3)}:${(m?.position.y??0).toFixed(3)}:${f.headingDeg}:${f.altitudeM}:${l}`;if(d.userData.footprintKey!==g&&(d.userData.footprintGroundY=this.groundUnderFootprint(u,p,v,f.headingDeg,f.altitudeM),d.userData.footprintKey=g),d.position.set(p,d.userData.footprintGroundY+f.altitudeM,v),u.kind==="crop"){const x=Math.hypot(p,v);d.visible=x<=eD}const b=this.decorPresence.get(u.id),S=b!==void 0&&(i<b.fromMs||i>b.untilMs);b&&(d.visible=!S);const M=this.decorSunlight.get(u.id);if(M&&!S&&this.lightFromAbove(d,M),f.headingDeg!==void 0&&(d.rotation.y=-f.headingDeg*Ei),u.kind==="crop"&&d.visible){const x=this.terrainMesh,_=[x?.geometry.uuid,p-(x?.position.x??0),v-(x?.position.z??0),d.position.y-(x?.position.y??0),f.headingDeg,f.altitudeM].map(E=>typeof E=="number"?E.toFixed(4):E).join(":");d.userData.cropGroundKey!==_&&(Ye.fitCropToGround(d,(E,y)=>this.groundYUnder(E,y)+f.altitudeM),d.userData.cropGroundKey=_)}if(!S){const x=d.position.distanceTo(this.camera.position);o=Math.max(o,x),x<le.trafficModelRangeM(u)&&this.pendingTrafficModels.delete(u.id)&&this.loadDecorModel(u,this.decorModelToken)}}if(s&&c!==void 0){const u=this.decorGroups.get(s.id);u&&(this.camera.position.y=u.position.y+c)}this.updateContrails();const h=Math.max(Ah*1.2,this.groundRadius*2.5,o*1.2);Math.abs(this.camera.far-h)>1&&(this.camera.far=h,this.camera.updateProjectionMatrix())}groundYUnder(t,e){const i=this.terrainYUnder(t,e);let n=i;for(const s of this.terraces){const r=t-s.x,o=e-s.z,c=r*s.cos-o*s.sin,l=r*s.sin+o*s.cos;if(Math.abs(c)<=s.halfWidthM&&Math.abs(l)<=s.halfLengthM){const h=Math.min(1,Math.max(0,(s.halfWidthM-Math.abs(c))/s.bankM)),u=h*h*(3-2*h);n=Math.max(n,u*s.levelY+(1-u)*Math.min(s.levelY,i))}}return n}placeTerraces(t,e,i){this.terraces=[];const n=this.terrainMesh;for(const s of this.decorObjects){if(s.kind!=="terrace")continue;const r=this.decorGroups.get(s.id);if(!r)continue;const o=Hr(s,t),c=o.eastM+e.x+i.x,l=-o.northM+e.z+i.z,h=Ye.sizeOf(s),u=-(o.headingDeg??0)*Ei,d=Math.cos(u),f=Math.sin(u),p=`${n?.geometry.uuid}:${(c-(n?.position.x??0)).toFixed(3)}:${(l-(n?.position.z??0)).toFixed(3)}:${(n?.position.y??0).toFixed(3)}:${o.headingDeg}:${h.widthM}:${h.lengthM}:${h.heightM}`;r.position.set(c,0,l),o.headingDeg!==void 0&&(r.rotation.y=u),r.userData.terraceKey!==p&&(r.userData.terraceLevelY=Ye.fitTerrace(r,s,(v,m)=>this.terrainYUnder(c+v*d+m*f,l-v*f+m*d)),r.userData.terraceKey=p),this.terraces.push({x:c,z:l,cos:d,sin:f,halfWidthM:h.widthM/2,halfLengthM:h.lengthM/2,levelY:r.userData.terraceLevelY,bankM:Math.min(10,h.widthM/4)})}}terrainYUnder(t,e){const i=this.terrainMesh;return i?i.position.y+this.groundYOfPatch(i,t-i.position.x,e-i.position.z):Cf}groundYOfPatch(t,e,i){const n=t.geometry.getAttribute("position"),s=Math.round(Math.sqrt(n.count));if(s<2||s*s!==n.count)return Cf;const r=n.getX(0),o=n.getX(s-1),c=n.getZ(0),l=n.getZ((s-1)*s),h=ir((e-r)/(o-r)*(s-1),0,s-1),u=ir((i-c)/(l-c)*(s-1),0,s-1);if(!Number.isFinite(h)||!Number.isFinite(u))return Cf;const d=Math.min(Math.floor(h),s-2),f=Math.min(Math.floor(u),s-2),p=h-d,v=u-f,m=(x,_)=>n.getY(x*s+_),g=m(f,d),b=m(f,d+1),S=m(f+1,d),M=m(f+1,d+1);return p+v<=1?g+(b-g)*p+(S-g)*v:M+(S-M)*(1-p)+(b-M)*(1-v)}groundUnderFootprint(t,e,i,n,s=0){return Ye.groundUnderFootprint(t,e,i,n,(r,o)=>this.groundYUnder(r,o),s)}lookYawDeg=0;lookPitchDeg=0;poseCameraY=1.6;poseElevationM=0;setGait(t){this.gaitOffset=t}gaitOffset={eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0};setLookOffset(t,e){this.lookYawDeg=t,this.lookPitchDeg=e}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(t,e){this.indoorLookYawDeg=t,this.indoorLookPitchDeg=e}medium;setMedium(t,e,i,n){const s=t&&e!==void 0&&e>0&&i!==void 0&&i>0?{kind:t.kind,iso:n??t.iso,autoExposure:t.autoExposure===!0,exposureSeconds:e,fNumber:i}:void 0;JSON.stringify(s)!==JSON.stringify(this.medium)&&(this.medium=s,this.render())}applyMedium(){const t=this.medium,e=Math.max(this.relativeScale,1e-30);if(!t){ln.uMedium.value=0;return}ln.uMedium.value=t.kind==="negative"?1:t.kind==="slide"?2:3;const i=t.autoExposure?this.scatteredSky?.sceneAdaptation:void 0;ln.uMediumExposure.value=i!==void 0&&i>0?1/(e*i):.065*t.exposureSeconds*t.iso*this.filterTransmittance/(t.fNumber*t.fNumber*e)}grain;lampBloomRadiusRad(){if(!this.grain)return;const t=this.camera.fov*Math.PI/180,e=this.grain.frameHeightMm/(2*Math.tan(t/2)),i=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.grain.detailUm*.001/e,t/i)}bloomSize=new bt;lampTransmittance(t){const e=this.siteElevationM+this.camera.position.y,i=this.siteElevationM+t.position.y;return this.air.transmittance(e,i,t.position.distanceTo(this.camera.position))}updateDecorLitState(t,e=0){const i=this.lampBloomRadiusRad();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);if(s&&n.lights?.length&&Ye.setLights(s,n.lights,t,s.position.distanceTo(this.camera.position),e,this.relativeScale,i,this.lampTransmittance(s)),n.kind!=="streetlight"&&n.kind!=="vehicle")continue;const r=this.decorGroups.get(n.id);if(!r)continue;const o=vM(n,t);Ye.setLit(r,n.kind,o,this.relativeScale);const c=this.streetlightLights.get(n.id);c&&(c.visible=o)}}addStreetlightLight(t,e){const i=Ye.bodyOf(e),n=i.children.find(r=>r.userData.emissive);if(!n)return;const s=new u2(16764006,_v*this.relativeScale,WR);s.position.copy(n.position).multiply(i.scale),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,e.add(s),this.streetlightLights.set(t,s)}setAstronomy(t){(!this.lastAstronomy||Math.abs(this.lastAstronomy.sun.altitudeDeg-t.sun.altitudeDeg)>2)&&(this.surroundings=void 0,this.scatteredSky?.resetSurroundings()),this.lastAstronomy=t,this.scatteredSky?.update(this.scatteredSkyState(t)),this.skyHoldUntilMs===void 0&&this.startHold(),this.pumpScatteredSky(),this.lastSunPosition=t.sun,this.buildSky(t.sun),this.buildGround();const e=this.magnitudeLimitOf(t);this.buildStars(t.stars,e),this.placeBodies(t,e),this.buildIceHalos(t.sun,t.moon),this.buildRainbow(t.sun,t.moon),this.applySkyColours(t),this.syncAnimationLoop(),this.render()}static relativeSkyOf(t,e){const i=r=>{const o=us.luminanceOf(r);if(!(o>0))return[0,0,0];const c=Rt.relativeOfResponse(o)/o;return[r[0]*c,r[1]*c,r[2]*c]},n=i(t.zenith),s=i(t.horizon);return{zenith:n,horizon:s,airlight:s,skyIrradiance:[n[0]*Math.PI,n[1]*Math.PI,n[2]*Math.PI],scale:e}}placeBodies(t,e){this.bodiesScale=this.relativeScale,this.sunBeamFraction=Mi.beamFraction(t.eclipse),this.setBodyMesh("sun",t.sun,Sv,new st(1,.96,.88),t.sun.magnitude),this.placeEclipse(t),this.setMoonMesh(t.moon,e),this.buildPlanets(t.planets,e),this.buildComet(t.comet,e),this.buildNovae(t.novae??[],e)}placeEclipse(t){const e=t.eclipse;if(!e||t.sun.altitudeDeg<Jh){this.eclipsedSun.setMoon(void 0),this.eclipseDiscs=void 0,this.solarCorona?.show(void 0,[0,0,0]);return}const i=Sv/pn*(180/Math.PI),n=i/e.sunRadiusDeg,s=Xe(t.sun.altitudeDeg,t.sun.azimuthDeg,1),r=Xe(t.moon.altitudeDeg,t.moon.azimuthDeg,1),o=Math.acos(ir(s.x*r.x+s.y*r.y+s.z*r.z,-1,1)),c=o>1e-9?ir(e.separationDeg*n*Ei/o,0,2):0,l=Math.sin(o),[h,u]=o>1e-9?[Math.sin((1-c)*o)/l,Math.sin(c*o)/l]:[1,0],d={x:s.x*h+r.x*u,y:s.y*h+r.y*u,z:s.z*h+r.z*u},f=e.moonRadiusDeg*n;this.eclipseDiscs={sun:new R(s.x,s.y,s.z).normalize(),moon:new R(d.x,d.y,d.z).normalize(),sunRadiusRad:i*Ei,moonRadiusRad:f*Ei};const p=.01,v=(b,S)=>Xe(t.sun.altitudeDeg+b,t.sun.azimuthDeg+S,1),m={x:v(p,0).x-v(-p,0).x,y:v(p,0).y-v(-p,0).y,z:v(p,0).z-v(-p,0).z},g={x:v(0,p).x-v(0,-p).x,y:v(0,p).y-v(0,-p).y,z:v(0,p).z-v(0,-p).z};if(this.eclipsedSun.setMoon(d,f,e.limb?{profile:e.limb,scale:n,up:m,right:g}:void 0),e.obscuration<.9){this.solarCorona?.show(void 0,[0,0,0]);return}this.solarCorona||(this.solarCorona=new ko(i*Math.PI/180,this.eclipsedSun.cut),this.celestialGroup.add(this.solarCorona.object)),this.solarCorona.show(s,this.sunDiscRadiance)}bodiesScale=0;applySkyColours(t){this.skyColoursStale=!1,this.bodiesScale!==this.relativeScale&&(this.placeBodies(t,this.magnitudeLimitOf(t)),this.applyDazzleStrength(),this.buildIceHalos(t.sun,t.moon),this.buildRainbow(t.sun,t.moon));const e=this.scatteredSky?.ambient??le.relativeSkyOf(K0(t.sun.altitudeDeg),this.relativeScale),i=e,n=this.lightUnderClouds(t),s=r=>n?[0,1,2].map(o=>r[o]*n.through+n.radiance[o]*(1-n.through)):[r[0],r[1],r[2]];this.baseFogColor=[i.horizon[0],i.horizon[1],i.horizon[2]],this.airlight=s(i.airlight),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.scatteredSky?.ready?this.scatteredSky.material:this.skyGradientMaterial),this.updateCelestialLight(t,e),this.updateCloudLighting(t.sun,this.baseFogColor),Ct.setEye(this.scatteredSky?.rodShare??0,this.relativeScale),this.updateTwinkle(this.twinkleSeconds);for(const r of this.streetlightLights.values())r.intensity=_v*this.relativeScale;this.buildSkyGlow(t,i.zenith),this.applyAir(),this.buildLunarDiffraction(t.moon)}reflections;sceneVersion=0;reflectionTimer;buildLunarDiffraction(t){const e=this.scatteredSky?.ready?this.scatteredSky:void 0;if(t.altitudeDeg<-.5||!e){this.lunarDiffraction?.show(void 0),this.lunarDiffractionKey="";return}const i=this.weather.relativeHumidity,n=(i===void 0?zt.DEFAULT_AEROSOL_OPTICAL_DEPTH:Br.opticalDepth(i))*zt.aerosolDensity(this.siteElevationM+this.observerElevationM),s=this.cloudTransmission(t),r=-Math.log(Math.max(this.cloudTransmission(t,!0),1e-4)),o=ye.aureoleScale(n,ye.airMass(t.altitudeDeg))*s,c=ye.coronaScale(r),l=ye.illuminanceOf(t.magnitude),h=[t.altitudeDeg.toFixed(1),t.azimuthDeg.toFixed(1),t.magnitude.toFixed(2),o.toExponential(2),c.toExponential(2),Math.log10(Math.max(e.adaptation,1e-12)).toFixed(2)].join(":");if(h===this.lunarDiffractionKey)return;this.lunarDiffractionKey=h,this.lunarDiffraction||(this.lunarDiffraction=new fm,this.celestialGroup.add(this.lunarDiffraction.object));const u=ye.profile(ye.HAZE_COARSE_MODE),d=ye.profile(ye.CLOUD_DROPLETS),f=G1(t.altitudeDeg),p=new Float32Array(ye.STEPS*3);let v=0;for(let S=0;S<ye.STEPS;S++){const M=S*3,x=[0,1,2].map(E=>l*f[E]*(o*u[M+E]+c*d[M+E])),_=us.shown(x,us.luminanceOf(x),(E,y)=>e.relativeOfLuminance(E,y));p.set(_,M),v=Math.max(v,us.response(_))}const{x:m,y:g,z:b}=Xe(t.altitudeDeg,t.azimuthDeg,1);this.lunarDiffraction.show(v>1/200?{x:m,y:g,z:b}:void 0,p)}applyAir(){this.scene.fog instanceof Fa||(this.scene.fog=new Fa),this.scene.fog.setAir(this.air,this.siteElevationM,this.airlight)}airlight=[0,0,0];transmittanceTo(t,e,i){const n=this.camera.position;return this.air.transmittance(this.siteElevationM+n.y,this.siteElevationM+e,Math.hypot(t-n.x,e-n.y,i-n.z))}setSiteElevation(t){Math.abs(t-this.siteElevationM)<1||(this.siteElevationM=t,this.applyAir(),this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}umbraTint(){const t=this.siteElevationM+this.observerElevationM+1.6,[e,i,n]=this.air.transmittance(t,t,le.UMBRA_PATH_M),s=.2126*e+.7152*i+.0722*n;return s>0?[(.4124*e+.3576*i+.1805*n)/s,1,(.0193*e+.1192*i+.9505*n)/s]:[.9505,1,1.089]}static UMBRA_PATH_M=8e4;umbraOf(t){const e=t.eclipse?.horizonShare;return e&&Math.max(...e)<.1?{share:e,tint:this.umbraTint()}:void 0}scatteredSkyState(t){return{altitudeM:this.siteElevationM+this.observerElevationM+1.6,lightPollution:this.lightPollution,sun:{altitudeDeg:t.sun.altitudeDeg,azimuthDeg:t.sun.azimuthDeg,magnitude:t.sun.magnitude},sunLight:Mi.beamFraction(t.eclipse),zenithFloorCdM2:t.eclipse?Mi.UMBRA_ZENITH_CD_M2:void 0,umbra:this.umbraOf(t),moon:{altitudeDeg:t.moon.altitudeDeg,azimuthDeg:t.moon.azimuthDeg,magnitude:t.moon.magnitude,phaseAngleDeg:St.phaseAngleOf(t.moon.phase.illuminatedFraction)}}}pumpScatteredSky(){const t=this.scatteredSky;!t||t.tables.ready||this.scatteredSkyFrameId!==null||this.contextReleased||this.suspended||(this.scatteredSkyFrameId=requestAnimationFrame(()=>{this.scatteredSkyFrameId=null,!this.contextReleased&&(t.advance(this.skyHoldUntilMs?qR:YR),this.pumpScatteredSky())}))}cancelScatteredSkyPump(){this.scatteredSkyFrameId!==null&&(cancelAnimationFrame(this.scatteredSkyFrameId),this.scatteredSkyFrameId=null)}setSatellites(t){if(t.length===0&&!this.satelliteField?.count)return;this.satelliteField||(this.satelliteField=new tR(wf),this.celestialGroup.add(this.satelliteField.object));const e=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Kh(-90,this.instrumentMagnitudeGain);this.satelliteField.set(t,e,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}setReentries(t){if(t.length===0&&!this.reentrySystem?.count)return;this.reentrySystem||(this.reentrySystem=new mn,this.celestialGroup.add(this.reentrySystem.object));const e=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Kh(-90,this.instrumentMagnitudeGain);this.reentrySystem.set(t,e,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}get reentryCount(){return this.reentrySystem?.count??0}pickTrafficAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.direction,n=Math.cos(_f*this.camera.fov*Math.PI/180);let s,r=n;const o=new R;for(const[c,l]of this.decorGroups){if(!l.visible||!c.startsWith(Xn.ID_PREFIX))continue;o.copy(l.position).sub(this.camera.position).normalize();const h=o.dot(i);h>r&&(r=h,s=c)}return s&&!this.groundHides(t,e)?s:void 0}pickSatelliteAt(t,e){if(!this.satelliteField?.count)return;this.aimAtScreenPoint(this.raycaster,t,e);const i=Math.cos(_f*this.camera.fov*Math.PI/180),n=this.satelliteField.nearest(this.raycaster.ray.direction,i);return n&&this.groundHides(t,e)?void 0:n}updateCelestialLight(t,e){const i=this.relativeScale,n=t.sun.altitudeDeg>=Rh,s=!n&&t.moon.altitudeDeg>=Rh,r=n?t.sun:t.moon,o=[0,0,0],c=Math.max(0,Math.sin(Math.max(r.altitudeDeg,0)*Ei)),l=n||s?this.cloudTransmission(r):1,h=-Math.log(Math.max(l,1e-6)),u=Math.max(0,1/(1+.1125*h)-l),d=[0,0,0];if(n||s){const b=ye.illuminanceOf(r.magnitude)*i,S=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,r.altitudeDeg);for(let E=0;E<3;E++)o[E]=b*S[E]*l,d[E]=b*S[E]*u*c,this.cloudBeam[E]=b*S[E];const{x:M,y:x,z:_}=Xe(r.altitudeDeg,r.azimuthDeg,1);this.cloudBeamDirection.set(M,x,_)}else this.cloudBeam.fill(0);const f=this.surroundings;if(f)this.skyLight.color.setRGB(f.up[0]*i,f.up[1]*i,f.up[2]*i),this.skyLight.groundColor.setRGB(f.down[0]*i,f.down[1]*i,f.down[2]*i);else{const b=this.skyCloudTransmission(),S=e.skyIrradiance,M=[0,1,2].map(_=>S[_]*b+d[_]);this.skyLight.color.setRGB(M[0],M[1],M[2]);const x=Xt.GROUND_ALBEDO;this.skyLight.groundColor.setRGB(x*(M[0]+o[0]*c),x*(M[1]+o[1]*c),x*(M[2]+o[2]*c))}if(this.skyLight.intensity=1,this.sceneSunBeam=n?[o[0],o[1],o[2]]:[0,0,0],!n&&!s){this.celestialLight.intensity=0;return}const{x:p,y:v,z:m}=Xe(r.altitudeDeg,r.azimuthDeg,1);this.lightDirection.set(p,v,m),this.placeShadowFrustum();const g=Math.max(o[0],o[1],o[2],1e-30);this.celestialLight.color.setRGB(o[0]/g,o[1]/g,o[2]/g),this.celestialLight.intensity=g,this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}static MEAN_COSINE=.5;static ABOVE_CLOUD_M=8e3;lightFromAbove(t,e){const i=this.lastAstronomy?.sun,n=[0,0,0];if(i){const s=Pn.litFraction(e.sunElevationDeg,e.heightM);if(s>0){const r=this.air.transmittanceFromSpace(e.heightM,e.sunElevationDeg),o=ye.illuminanceOf(i.magnitude)*this.relativeScale,c=e.heightM>=le.ABOVE_CLOUD_M?1:this.cloudTransmission(i);for(let l=0;l<3;l++)n[l]=Math.max(0,o*r[l]*s*c-this.sceneSunBeam[l])}}t.traverse(s=>{const r=s.material;if(!(r instanceof nc||r instanceof Nr)||s.userData.emissive)return;r.map&&!r.emissiveMap&&(r.emissiveMap=r.map,r.needsUpdate=!0);const o=le.MEAN_COSINE/Math.PI;r.emissive.setRGB(r.color.r*n[0]*o,r.color.g*n[1]*o,r.color.b*n[2]*o)})}lightDirection=new R(0,1,0);placeShadowFrustum(){const t=this.lightDirection,e=this.celestialLight.shadow.camera,i=(e.right-e.left)/this.celestialLight.shadow.mapSize.x,n=this.shadowAxisX.crossVectors(this.shadowUp,t);n.lengthSq()<1e-8&&n.set(1,0,0),n.normalize();const s=this.shadowAxisY.crossVectors(t,n).normalize(),r=this.shadowWorld.set(this.bodyOrigin.x,0,this.bodyOrigin.z),o=l=>{const h=r.dot(l)/i;return(h-Math.round(h))*i},c=this.celestialLightTarget.position.set(0,0,0).addScaledVector(n,o(n)).addScaledVector(s,o(s));this.celestialLightTarget.updateMatrixWorld(),this.celestialLight.position.copy(c).addScaledVector(t,this.shadowLightDistanceM)}fitShadowToBodies(){const t=this.bodySystem.reachFrom(this.camera.position),e=Math.min(FR,Math.max(Ar,Math.ceil(t*1.25/20)*20));if(e===this.shadowHalfExtentM)return;this.shadowHalfExtentM=e;const i=this.celestialLight.shadow,n=i.camera;n.left=-e,n.right=e,n.top=e,n.bottom=-e;const s=Math.max(Ic,e*(Ic/Ar));this.shadowLightDistanceM=Math.max(pn,s+10),n.near=this.shadowLightDistanceM-s,n.far=this.shadowLightDistanceM+s,n.updateProjectionMatrix(),i.bias=-.03/(2*s);const r=e>2*Ar?2048:1024;i.mapSize.x!==r&&(i.mapSize.set(r,r),i.map?.dispose(),i.map=null),this.placeShadowFrustum()}shadowHalfExtentM=Ar;shadowLightDistanceM=pn;shadowUp=new R(0,1,0);shadowAxisX=new R;shadowAxisY=new R;shadowWorld=new R;skyCloudTransmission(){let t=this.cloudTransmission({altitudeDeg:90,azimuthDeg:0}),e=1;for(const i of[20,45,70]){const n=i*Ei,s=Math.sin(n)*Math.cos(n)*2;for(let r=0;r<360;r+=60)t+=s*this.cloudTransmission({altitudeDeg:i,azimuthDeg:r}),e+=s}return t/e}cloudBeam=[0,0,0];cloudBeamDirection=new R(0,1,0);get relativeScale(){return this.scatteredSky?.relativeScale??1/Rt.semiSaturation(Rt.DAYLIGHT_ANCHOR_CD_M2)}setMeteorShower(t,e,i){this.meteorSystem||(this.meteorSystem=new Fi,this.celestialGroup.add(this.meteorSystem.object)),this.meteorSystem.setShower(t,e,i)}get meteorSchedule(){return this.meteorSystem?.schedule??[]}meteorMidpoint(t){return this.meteorSystem?.midpointOf(t)}updateMeteors(t){this.meteorSystem?.update(t)}setInstrument(t){this.projectionKind=t.projection,this.grain=t.detailUm!==void 0&&t.frame?{detailUm:t.detailUm,frameHeightMm:t.frame.heightMm}:void 0;const e=bi.starPointsOf(t),i=bi.flareArtifactsOf(t);e===this.starPoints&&i===this.lensFlareArtifactIntensity||(this.starPoints=e,this.lensFlareArtifactIntensity=i,this.lensFlare&&(this.lensFlare.uniforms.uStarPoints.value=e,this.lensFlare.uniforms.uFlareIntensity.value=i),this.render())}magnitudeLimitOf(t){const e=St.starLossMagnitudes(t.sun.altitudeDeg,{phaseAngleDeg:St.phaseAngleOf(t.moon.phase.illuminatedFraction),altitudeDeg:t.moon.altitudeDeg},this.lightPollution);return Kh(t.sun.altitudeDeg,this.instrumentMagnitudeGain,e)}setLightPollution(t){t!==this.lightPollution&&(this.lightPollution=t,this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}setInstrumentGain(t,e=!1,i=0){const n=Number.isFinite(t)?t:0;this.instrumentMagnitudeGain=n-2.5*i,this.filterTransmittance=10**-i,this.scatteredSky?.setInstrument(e,n,i)}filterTransmittance=1;render(){this.restatingExposure||(this.sceneVersion++,this.frameDirty=!0,this.resolution.noteChange(performance.now()),!this.suspended&&(this.syncAnimationLoop(),!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))))}drawIfDirty(){if(!(!this.frameDirty||this.contextReleased||this.suspended)){if(this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy),this.compileBeforeNextDraw){this.compileBeforeNextDraw=!1;const t=this.compileOffThread().then(()=>{this.compiling===t&&(this.compiling=void 0,this.render())});this.compiling=t;return}if(!this.compiling){if(this.skyHoldUntilMs){if(!this.sceneSettled()&&performance.now()<this.skyHoldUntilMs){this.firstFrameReady()&&this.arrivalsPending===0&&this.refreshReflections(!0);return}this.skyHoldUntilMs=null,this.skyGlow?.setWithheld(!1),this.iceHalos?.setUrgent(!1),this.onFirstFrameHold?.(!1),this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy)}this.frameDirty=!1,this.refreshReflections(),this.resolution.beginDrawing();try{this.renderOnce(),this.drawn++}finally{this.resolution.endDrawing()}this.developingExposure&&this.startExposure()}}}drawn=0;get framesDrawn(){return this.drawn}compileBeforeNextDraw=!1;compiling;static COMPILE_WAIT_MS=1500;compileOffThread(){const t=this.renderer.compile(this.scene,this.camera);if(!this.renderer.extensions.get("KHR_parallel_shader_compile"))return Promise.resolve();const e=this.renderer.properties,i=performance.now()+le.COMPILE_WAIT_MS;return new Promise(n=>{const s=()=>{if(this.contextReleased)return n();for(const r of t){const o=e.get(r)?.currentProgram;(!o||o.isReady())&&t.delete(r)}t.size===0||performance.now()>i?n():setTimeout(s,10)};s()})}compileNextFrameOffThread(){this.compileBeforeNextDraw=!0}contextReleased=!1;releaseContext(){this.contextReleased||(this.contextReleased=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.compiling=void 0,this.cancelScatteredSkyPump(),this.renderer.forceContextLoss())}restoreContext(){this.contextReleased&&(this.contextReleased=!1,this.renderer.forceContextRestore(),this.scatteredSky?.invalidate(),this.pumpScatteredSky(),this.compileNextFrameOffThread(),this.syncAnimationLoop(),this.render())}suspended=!1;suspend(){this.suspended||(this.suspended=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.cancelScatteredSkyPump(),clearTimeout(this.reflectionTimer),this.reflectionTimer=void 0)}resume(){this.suspended&&(this.suspended=!1,this.pumpScatteredSky(),this.syncAnimationLoop(),this.render())}cancelFlush(){this.flushFrameId!==null&&(cancelAnimationFrame(this.flushFrameId),this.flushFrameId=null)}frame(t){if(this.animationsRunning){const e=this.lastFrameTimeMs===void 0?0:t-this.lastFrameTimeMs;this.lastFrameTimeMs=t,this.hasAnimations()&&this.animate(t,e);const i=this.resolution.ratioFor(t,e);i!==this.renderer.getPixelRatio()&&this.applyPixelRatio(i)}this.drawIfDirty()}refreshReflections(t=!1){this.reflections??=new Mn(this.renderer);const e=[...this.compassSprites,...this.lensFlare?[this.lensFlare.mesh]:[],...[...this.glareSprites.values()].map(o=>o.mesh)],i=[...this.starTiers.map(o=>o.points),...[...this.bodyMeshes.values()].filter(o=>o instanceof In),...[this.rainSystem?.points,this.precipitationPoints,this.rainSplashSystem?.points].filter(o=>o!==void 0)],n=this.relativeScale,s=this.sceneVersion,r=this.reflections.refresh(this.renderer,this.scene,this.camera.position,this.bodySystem.reflectors,e,[...this.decorGroups.values()],s,i,o=>this.measureSurroundings(o,n,s),t?0:Mn.REFRESH_MS);r===void 0||this.reflectionTimer||(this.reflectionTimer=setTimeout(()=>{this.reflectionTimer=void 0,this.frameDirty=!0,!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))},r))}measureSurroundings(t,e,i){const n=this.lastAstronomy;if(!n)return;this.probeIrradiance??=new Kc;const s=[n.sun,n.moon].filter(r=>r.altitudeDeg>-2).map(r=>Xe(r.altitudeDeg,r.azimuthDeg,1));this.probeIrradiance.measure(this.renderer,t,s,r=>{const o=f=>f.map(p=>p/e),c=this.surroundings,l={up:o(r.up),down:o(r.down)},h=(f,p)=>f.some((v,m)=>Math.abs(v-p[m])>.03*Math.max(Math.abs(v),Math.abs(p[m]),1e-12)),u=!c||h(c.up,l.up)||h(c.down,l.down);u&&(this.surroundings=l),this.eyeSettledVersion=-1;const d=this.scatteredSky?.adaptToSurroundings(Math.exp(r.logAverage)/e)??!1;if(!u&&!d){this.eyeSettledVersion=i,this.skyHoldUntilMs&&this.redrawHeld();return}this.skyColoursStale=!0,this.render()})}lightUnderClouds(t){const e=this.surroundings;if(!e)return;const i=t.sun.altitudeDeg>=Rh?t.sun:t.moon.altitudeDeg>=Rh?t.moon:void 0;if(!i)return;const n=this.relativeScale/Math.PI;return{through:this.cloudTransmission(i),radiance:[e.up[0]*n,e.up[1]*n,e.up[2]*n]}}probeIrradiance;surroundings;animate(t,e){const i=Math.min(e/1e3,pD);this.twinkleSeconds=t/1e3,this.updateTwinkle(this.twinkleSeconds),this.updatePrecipitation(t/1e3,i),this.updateRain(i),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=t/1e3),this.developingExposure||(this.frameDirty=!0)}setMaxPixelRatio(t){this.resolution.maximum=t,this.renderer.getPixelRatio()>this.resolution.maximum&&this.applyPixelRatio(this.resolution.maximum)}applyPixelRatio(t){this.renderer.setPixelRatio(t),this.renderer.setSize(this.cssSize.width,this.cssSize.height,!1),this.frameDirty=!0}setExposure(t,e){const i=e?Math.max(1,Math.round(t)):1;if(i===this.exposureInstants&&(i===1||e===this.exposureInstantAt)){this.exposureInstantAt=e;return}this.exposureInstants=i,this.exposureInstantAt=e,i===1&&(this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0),this.render()}renderOnce(t){if(this.onMapSubjectBounds){const r=this.mapSubjectBounds();t?this.exposureSubjectBounds.push(...r):this.onMapSubjectBounds(r)}const e=this.usableEquidistantPass();this.phenomena.setCloudLayers(this.layeredClouds?.volumes??[]),this.phenomena.place(this.camera,(r,o,c)=>this.directionAtScreenPoint(r,o,c),r=>this.screenPointOf(r)),this.references.place(this.camera);const i=Math.max(this.phenomena.furthestM,this.references.furthestM)*1.2;i>this.camera.far&&(this.camera.far=i,this.camera.updateProjectionMatrix()),ln.uRodShare.value=this.scatteredSky?.rodShare??0,ln.uRelativeScale.value=this.relativeScale,this.applyMedium();const n=this.references.any||this.phenomena.any||this.compassSprites.some(r=>r.visible);ln.uHasOverlay.value=n?1:0;const s=n?r=>this.renderOverlayPasses(r):void 0;if(this.skyGlow?.setDestinationEncoded(!1),!e){this.updateLensFlarePosition();const r=this.usableDepthOfFieldPass();r?r.render(this.renderer,this.scene,this.camera,s,t):this.usableFinishPass().render(this.renderer,this.scene,this.camera,s,void 0,t);return}e.render(this.renderer,this.scene,this.camera,this.camera.fov,()=>this.updateLensFlarePosition(),s,r=>{this.lensFlare&&(this.lensFlare.mesh.visible=r?!1:this.sunVisible)},()=>this.renderDazzleOnResample(),t,this.pointLayerHost)}pointLayerHost={points:()=>{const t=[];return this.celestialGroup.traverse(e=>{(e instanceof In&&e.userData.pointSource||e instanceof At&&e.userData.skyRibbon)&&t.push(e)}),t},clouds:()=>[...this.layeredClouds?.meshes??[],...this.cloudMesh?[this.cloudMesh]:[],...this.cirrusMesh?[this.cirrusMesh]:[]],sky:this.celestialGroup};renderOverlayPasses(t=this.camera){this.renderReferencesPass(t),this.renderBodiesOverReferences(t),this.renderPhenomenaPass(t),this.renderHudPass(t)}renderHudPass(t){const e=this.traceSystem?.any&&this.tracesShown;if(!e&&!this.compassSprites.some(s=>s.visible))return;e&&this.traceSystem.setView(this.renderer.getDrawingBufferSize(this.traceResolution),t.fov);const i=this.renderer.autoClear,n=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(bf),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=i,this.renderer.shadowMap.autoUpdate=n}renderBodiesOverReferences(t){if(!this.references.any||!this.bodySystem.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(ry),this.scene.overrideMaterial=this.bodyCutOutMaterial,this.renderer.render(this.scene,t),this.scene.overrideMaterial=null,t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}bodyCutOutMaterial=new wn({blending:xl,blendSrc:Nc,blendDst:Nc,blendSrcAlpha:Nc,blendDstAlpha:Nc,toneMapped:!1});renderReferencesPass(t){if(!this.references.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(oy),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}setReferences(t,e){this.references.set(t.map(i=>{const n=this.documentRelative(i.src);return n===i.src?i:{...i,src:n}}),void 0,e)}referenceAspect(t){return this.references.aspectOf(t)}directionAt(t,e){return this.directionAtScreenPoint(t,e,new R)}referenceFailedToLoad(t){return this.references.failedToLoad(this.documentRelative(t))}setReferencesShown(t){this.references.setShown(t),this.render()}setReferenceView(t,e){this.references.setView(t,e),this.render()}renderPhenomenaPass(t){if(!this.phenomena.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,this.renderer.clearDepth();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);s&&le.markDecorDepth(s,n.kind!=="crop")}t.layers.set(xf),this.scene.overrideMaterial=this.decorDepthMaterial,this.renderer.render(this.scene,t),this.scene.overrideMaterial=null,t.layers.set(ay),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}decorDepthMaterial=new wn({colorWrite:!1});static markDecorDepth(t,e){t.traverse(i=>{if(!(i instanceof At))return;const n=Array.isArray(i.material)?i.material[0]:i.material;e&&n.depthWrite!==!1&&n.blending!==Pi?i.layers.enable(xf):i.layers.disable(xf)})}startExposure(){this.cancelExposure(),this.exposureSubjectBounds=[];const t=this.renderer.getDrawingBufferSize(new bt),e=Math.max(1,Math.round(t.x)),i=Math.max(1,Math.round(t.y));this.exposureAccumulation||(this.exposureAccumulation=new JA(e,i)),this.exposureAccumulation.resize(e,i),this.exposureAccumulation.open(this.renderer),this.exposureInstantsDone=0,this.exposureFrameId=requestAnimationFrame(()=>this.developExposure())}developExposure(){this.exposureFrameId=null;const t=this.exposureInstantAt,e=this.exposureAccumulation;if(!t||!e)return;const i=1/this.exposureInstants;this.resolution.beginDrawing();const n=performance.now()+le.EXPOSURE_BUDGET_MS,s=le.exposureInstantsPerFrame(e.instantTarget.scene.width*e.instantTarget.scene.height);let r=0;do{this.restateAt(t,this.exposureInstantsDone);const o=this.compassSprites.map(c=>c.visible);for(const c of this.compassSprites)c.visible=!1;try{this.renderOnce(e.instantTarget)}finally{this.compassSprites.forEach((c,l)=>{c.visible=o[l]})}e.add(this.renderer,i),this.exposureInstantsDone++,r++}while(this.exposureInstantsDone<this.exposureInstants&&performance.now()<n&&r<s);this.restateAt(t,0),this.presentExposure(),this.resolution.endDrawing(),this.exposureInstantsDone<this.exposureInstants&&(this.exposureFrameId=requestAnimationFrame(()=>this.developExposure()))}presentExposure(){if(ln.uRodShare.value=this.scatteredSky?.rodShare??0,ln.uHasOverlay.value=1,ln.uRelativeScale.value=this.relativeScale,this.applyMedium(),this.exposureAccumulation?.develop(this.renderer,this.exposureInstants/this.exposureInstantsDone),this.onMapSubjectBounds?.(this.exposureSubjectBounds),!this.compassSprites.some(s=>s.visible))return;const t=new Gs,e=new ps(-1,1,1,-1,0,2),i=Dh/(Av*Math.tan(Tv*Ei/2));for(const s of this.compassSprites){if(!s.visible)continue;const r=s.getWorldPosition(new R).sub(this.camera.position).normalize(),o=this.screenPointOf(r);if(!o)continue;const c=new Mc(s.material);c.position.set(o.ndcX,o.ndcY,-1),c.scale.set(i/this.camera.aspect,i,1),t.add(c)}const n=this.renderer.autoClear;this.renderer.autoClear=!1;try{this.renderer.render(t,e)}finally{this.renderer.autoClear=n}}onMapSubjectBounds;exposureSubjectBounds=[];static MAP_SUBJECT_NEAREST_M=8;mapSubjectBounds(){const t=[],e=new Qi,i=new R,n=this.camera.getWorldDirection(new R),s=this.decorObjects.filter(o=>o.track?.length||o.kind==="aircraft"||o.kind==="vehicle").map(o=>this.decorGroups.get(o.id)),r=this.bodySystem.reflectors.map(o=>o.holder);for(const o of[...s,...r]){if(!o?.visible||(e.setFromObject(o),e.isEmpty())||e.distanceToPoint(this.camera.position)<le.MAP_SUBJECT_NEAREST_M)continue;let c=1/0,l=-1/0,h=1/0,u=-1/0;for(const d of[e.min.x,e.max.x])for(const f of[e.min.y,e.max.y])for(const p of[e.min.z,e.max.z]){if(i.set(d,f,p).sub(this.camera.position).normalize(),i.dot(n)<=0)continue;const v=this.screenPointOf(i);if(!v)continue;const m=(v.ndcX+1)/2,g=(1-v.ndcY)/2;c=Math.min(c,m),l=Math.max(l,m),h=Math.min(h,g),u=Math.max(u,g)}c=Math.max(c,0),l=Math.min(l,1),h=Math.max(h,0),u=Math.min(u,1),l>=c&&u>=h&&t.push({x:c,y:h,width:l-c,height:u-h})}return t}restateAt(t,e){this.restatingExposure=!0;try{t(e)}finally{this.restatingExposure=!1}}cancelExposure(){this.exposureFrameId!==null&&(cancelAnimationFrame(this.exposureFrameId),this.exposureFrameId=null)}setLensOptics(t){const e=this.lensOptics;this.lensOptics=t,(e===void 0!=(t===void 0)||e&&t&&(e.focalLengthMm!==t.focalLengthMm||e.fNumber!==t.fNumber||e.focusDistance!==t.focusDistance||e.frameHeightMm!==t.frameHeightMm))&&(t&&this.depthOfFieldPass&&this.depthOfFieldPass.setLens(t.focalLengthMm,t.fNumber,t.focusDistance,t.frameHeightMm),this.render())}usableDepthOfFieldPass(){const t=this.lensOptics;if(!t)return;const e=this.renderer.getDrawingBufferSize(new bt),i=Math.max(1,Math.round(e.x)),n=Math.max(1,Math.round(e.y));return this.depthOfFieldPass||(this.depthOfFieldPass=new Jc(i,n)),this.depthOfFieldPass.resize(i,n),this.depthOfFieldPass.setLens(t.focalLengthMm,t.fNumber,t.focusDistance,t.frameHeightMm),this.depthOfFieldPass}usableFinishPass(){const t=this.renderer.getDrawingBufferSize(new bt);return this.finishPass?this.finishPass.resize(t.x,t.y):this.finishPass=new dm(t.x,t.y),this.finishPass}usableEquidistantPass(){if(this.projectionKind!=="equidistant")return;const t=this.renderer.getDrawingBufferSize(new bt);return this.equidistantPass?this.equidistantPass.resize(t.x,t.y):this.equidistantPass=new Ke(t.x,t.y),this.equidistantPass}aimAtScreenPoint(t,e,i){const n=this.projectionKind==="equidistant"?this.equidistantPass:void 0;if(!n){t.setFromCamera(new bt(e,i),this.camera);return}const s=n.directionFor(e,i,this.camera.fov);this.camera.updateMatrixWorld(),t.ray.origin.setFromMatrixPosition(this.camera.matrixWorld),t.ray.direction.set(s.x,s.y,s.z).applyQuaternion(this.camera.quaternion).normalize(),t.camera=this.camera}pickCloudAt(t,e){return this.layeredClouds?.pickInstance(this.cloudDirectionAt(t,e))}cloudDirectionAt(t,e){return this.directionAtScreenPoint(t,e,new R)}directionAtScreenPoint(t,e,i){return this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e),i.copy(this.ufoOcclusionRaycaster.ray.direction)}screenPointOf(t){this.camera.updateMatrixWorld();const e=this.screenPointScratch.copy(t).applyQuaternion(this.screenPointQuaternion.copy(this.camera.quaternion).invert()),i=this.renderer.getDrawingBufferSize(this.screenPointSize),n=i.x/Math.max(i.y,1);if(this.projectionKind==="equidistant"&&this.equidistantPass)return Ke.ndcFor(e,this.camera.fov,n);if(e.z>=0)return;const s=Math.tan(this.camera.fov/2*Ei);return{ndcX:e.x/-e.z/(n*s),ndcY:e.y/-e.z/s}}screenPointScratch=new R;screenPointQuaternion=new Sn;screenPointSize=new bt;updateLensFlarePosition(){const t=this.lensFlare;if(!t)return;if(!this.sunVisible){t.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){t.mesh.visible=!1;return}const e=this.sunVisibleFraction();if(e<=0){t.mesh.visible=!1;return}t.mesh.visible=!0,this.sunUnhiddenFraction=e,this.applyDazzleStrength();const i=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);t.uniforms.uLensPosition.value.set(i.x,i.y);const n=this.renderer.domElement.width,s=this.renderer.domElement.height;t.uniforms.uResolution.value.set(n,s),t.uniforms.uTanHalfFov.value=Math.tan(this.camera.fov*Math.PI/360)}renderDazzleOnResample(){const t=this.lensFlare;if(!t||!this.sunVisible)return;const e=this.sunVisibleFraction();if(e<=0)return;this.sunUnhiddenFraction=e,this.applyDazzleStrength();const i=this.screenPointOf(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position).normalize());if(!i)return;const n=this.renderer.getDrawingBufferSize(this.screenPointSize);t.uniforms.uLensPosition.value.set(i.ndcX,i.ndcY),t.uniforms.uResolution.value.set(n.x,n.y),t.uniforms.uEquidistant.value=1,t.uniforms.uHalfFovRad.value=this.camera.fov*Math.PI/360;const s=this.renderer.autoClear;this.renderer.autoClear=!1,t.mesh.visible=!0,t.mesh.layers.enable(yv),this.camera.layers.set(yv),this.renderer.render(this.scene,this.camera),this.camera.layers.set(0),t.mesh.visible=!1,t.uniforms.uEquidistant.value=0,this.renderer.autoClear=s}sunVisibleFraction(){this.raycastableDecor().length>0&&this.scene.updateMatrixWorld();let t=0;for(const e of Dv)this.isSunOccluded(e[0],e[1])||t++;return t/Dv.length}raycastableDecor(){const t=[];for(const e of this.decorObjects){if(e.kind==="crop")continue;const i=this.decorGroups.get(e.id);i&&t.push(i)}return t}isSunOccluded(t=0,e=0){const i=this.raycastableDecor();if(!this.groundMesh&&!this.terrainMesh&&i.length===0)return!1;const n=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),s=n.length();if(n.normalize(),t!==0||e!==0){const o=Math.PI/180,c=this.sunOcclusionRightScratch.set(n.z,0,-n.x);c.lengthSq()<1e-9&&c.set(1,0,0),c.normalize();const l=this.sunOcclusionUpScratch.crossVectors(c,n).normalize();n.addScaledVector(c,t*o).addScaledVector(l,e*o).normalize()}if(this.groundBlocks(this.camera.position,n,s))return!0;if(i.length===0)return!1;this.sunOcclusionRaycaster.set(this.camera.position,n);const r=this.sunOcclusionRaycaster.intersectObjects(i,!0)[0];return r!==void 0&&r.distance<s}groundBlocks(t,e,i,n=0){const s=this.groundMesh;if(s&&e.y<0){const m=(s.position.y-t.y)/e.y;if(m>n&&m<i){const g=t.x+e.x*m-s.position.x,b=t.z+e.z*m-s.position.z;if(Math.hypot(g,b)<=this.groundRadius)return!0}}const r=this.terrainMesh;if(!r)return!1;const o=r.geometry.getAttribute("position"),c=Math.round(Math.sqrt(o.count));if(c<2||c*c!==o.count)return!1;const l=[r.position.x+o.getX(0),r.position.x+o.getX(c-1)],h=[r.position.z+o.getZ(0),r.position.z+o.getZ((c-1)*c)],u=Math.min(Math.abs(l[1]-l[0]),Math.abs(h[1]-h[0]))/(c-1);if(!(u>0))return!1;let d=n,f=i;for(const[m,g,b]of[[t.x,e.x,l],[t.z,e.z,h]]){const S=Math.min(b[0],b[1]),M=Math.max(b[0],b[1]);if(Math.abs(g)<1e-12){if(m<S||m>M)return!1;continue}const x=(S-m)/g,_=(M-m)/g;d=Math.max(d,Math.min(x,_)),f=Math.min(f,Math.max(x,_))}if(!(f>d))return!1;const p=Math.hypot(e.x,e.z),v=Math.min(4096,Math.max(8,Math.ceil((f-d)*p/(u/2))));for(let m=0;m<=v;m++){const g=d+(f-d)*m/v,b=t.x+e.x*g,S=t.y+e.y*g,M=t.z+e.z*g;if(S<=this.groundYUnder(b,M))return!0}return!1}setPhenomena(t,e){this.phenomena.set(t,e)}decorDistancesAt(t,e,i){this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e),this.ufoOcclusionRaycaster.near=xv;let n,s;for(const r of this.decorObjects){if(r.kind==="crop")continue;const o=this.decorGroups.get(r.id);if(!o)continue;const c=this.ufoOcclusionRaycaster.intersectObject(o,!0)[0];c&&(r.occludesSourceIds?.includes(i)?n=n===void 0?c.distance:Math.max(n,c.distance):s=s===void 0?c.distance:Math.min(s,c.distance))}return{behindM:n,inFrontM:s}}pickBodyAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.origin,n=this.raycaster.ray.direction,s=zR*this.camera.fov*Math.PI/180,r=[...this.hitAreas.entries()].map(([h,u])=>{const d=u.getWorldPosition(new R).sub(i);return{key:h,direction:d.clone().normalize(),radiusRad:Math.atan2(u.scale.x/2,d.length())}}),o=this.eclipseDiscs,c=o?[{key:"sun",direction:o.sun,radiusRad:o.sunRadiusRad},{key:"moon",direction:o.moon,radiusRad:o.moonRadiusRad,inFront:!0}]:[],l=le.nearestBody(n,[...r.filter(h=>!o||h.key!=="sun"&&h.key!=="moon"),...c],s);if(l)return this.groundHides(t,e)?void 0:l}static nearestBody(t,e,i){let n,s=1/0,r=1/0,o=!1;for(const c of e){const l=Math.acos(ir(c.direction.dot(t),-1,1))-c.radiusRad;if(l>i)continue;const h=l<=0,u=s<=0,d=c.inFront===!0;(h!==u?h:h?d!==o?d:c.radiusRad<r:l<s)&&(n=c.key,s=l,r=c.radiusRad,o=d)}return n}pickInterpretationBodyAt(t,e){const i=this.bodySystem.group.children.filter(f=>f.visible&&f.name.startsWith("body:"));if(i.length===0)return;this.aimAtScreenPoint(this.raycaster,t,e);const n=this.raycaster.ray.direction,s=this.raycaster.ray.origin,r=kR*this.camera.fov*Math.PI/180,o=[...this.decorGroups.values()],c=o.length>0?le.firstSolid(this.raycaster.intersectObjects(o,!0))?.distance:void 0;let l,h=1/0;const u=new Qi,d=new R;for(const f of i){if(u.setFromObject(f),u.isEmpty())continue;u.getCenter(d);const p=u.getSize(new R).length()/2,v=d.clone().sub(s),m=v.length();if(m===0||v.dot(n)<=0||c!==void 0&&c<m-p)continue;const g=Math.acos(Math.min(1,v.normalize().dot(n))),b=Math.max(r,Math.atan(p/m));g<=b&&b<h&&(h=b,l=f.name.slice(5))}return l}pickStarAt(t,e){if(this.namedStars.length===0)return;this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.direction,n=Math.cos(_f*this.camera.fov*Math.PI/180);let s,r=n;for(const o of this.namedStars){const c=o.direction.dot(i);c>r&&(r=c,s={star:o.star,altitudeDeg:o.altitudeDeg})}return s&&this.groundHides(t,e)?void 0:s}groundHides(t,e){if(!this.terrainMesh&&!this.groundMesh)return!1;this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e);const i=this.ufoOcclusionRaycaster.ray;return this.groundBlocks(i.origin,i.direction,1/0,xv)}bodyScreenBox(t){const e=this.bodySystem.boxOf(t,this.bodyBoxScratch);if(!e)return;let i=1/0,n=1/0,s=-1/0,r=-1/0;for(let o=0;o<8;o++){const c=this.bodyCornerScratch.set(o&1?e.max.x:e.min.x,o&2?e.max.y:e.min.y,o&4?e.max.z:e.min.z),l=this.screenPointOf(c.sub(this.camera.position).normalize());if(!l)return;i=Math.min(i,l.ndcX),s=Math.max(s,l.ndcX),n=Math.min(n,l.ndcY),r=Math.max(r,l.ndcY)}return{minX:i,minY:n,maxX:s,maxY:r}}bodyBoxScratch=new Qi;bodyCornerScratch=new R;pickPlacedBodyAt(t,e){return this.aimAtScreenPoint(this.raycaster,t,e),this.bodySystem.pick(this.raycaster)}decorScreenBox(t){const e=this.decorGroups.get(t);if(!e||!e.visible)return;const i=this.bodyBoxScratch.setFromObject(e);if(i.isEmpty())return;let n=1/0,s=1/0,r=-1/0,o=-1/0;for(let c=0;c<8;c++){const l=this.bodyCornerScratch.set(c&1?i.max.x:i.min.x,c&2?i.max.y:i.min.y,c&4?i.max.z:i.min.z),h=this.screenPointOf(l.sub(this.camera.position).normalize());if(!h)return;n=Math.min(n,h.ndcX),r=Math.max(r,h.ndcX),s=Math.min(s,h.ndcY),o=Math.max(o,h.ndcY)}return{minX:n,minY:s,maxX:r,maxY:o}}decorGroundPointAt(t,e,i,n=0){const s=this.decorGroups.get(t);if(!s)return;this.aimAtScreenPoint(this.raycaster,e,i);const r=this.raycaster.ray.intersectPlane(this.decorPlaneScratch.setComponents(0,1,0,-(s.position.y+n)),this.decorHitScratch);return r?{x:r.x,z:r.z}:void 0}decorMetresPerNdcY(t){const e=this.decorGroups.get(t);return e?e.position.distanceTo(this.camera.position)*Math.tan(this.camera.fov*Ei/2):0}decorGrabHeightAt(t,e,i){const n=this.decorGroups.get(t);if(!n)return 0;const s=this.bodyBoxScratch.setFromObject(n).max.y-n.position.y;this.aimAtScreenPoint(this.raycaster,e,i);const r=this.decorHitScratch.set(this.camera.position.x-n.position.x,0,this.camera.position.z-n.position.z);if(r.lengthSq()<1e-6)return 0;r.normalize();const o=this.decorPlaneScratch.setFromNormalAndCoplanarPoint(r,n.position),c=this.raycaster.ray.intersectPlane(o,this.decorHitScratch);return c?Math.min(Math.max(c.y-n.position.y,0),Math.max(s,0)):0}decorPlaneScratch=new Ir;decorHitScratch=new R;static firstSolid(t){return t.find(e=>{const i=e.object.material;return!(Array.isArray(i)?i:[i]).some(s=>s&&s.transparent&&s.opacity<le.SEE_THROUGH_BELOW)})}static SEE_THROUGH_BELOW=.9;pickDecorAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=[...this.decorGroups.entries()],n=le.firstSolid(this.raycaster.intersectObjects(i.map(([,r])=>r),!0));if(!n)return;let s=n.object;for(;s&&!i.some(([,r])=>r===s);)s=s.parent;return i.find(([,r])=>r===s)?.[0]}dispose(){this.stopTerrainFade(),this.stopTwinkle(),this.cancelFlush(),this.phenomena.clear(),this.references.disposeAll(),this.terrainBuildToken++,this.cancelScatteredSkyPump(),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.skyGradientMaterial),this.scatteredSky?.dispose(),this.scatteredSky=void 0,this.disposeMesh(this.skyMesh),this.disposeMesh(this.groundMesh),this.disposeMesh(this.terrainMesh),this.roadSystem.dispose(),this.traceSystem?.dispose(),this.contrailSystem?.dispose(),this.contrailSystem=void 0,this.disposeCloudSystem(),this.disposeCirrus(),this.disposePrecipitationPoints(),this.disposeRain(),this.disposeStarTiers(),this.meteorSystem?.dispose(),this.meteorSystem=void 0,this.iceHalos?.dispose(),this.iceHalos=void 0,this.rainbow?.dispose(),this.rainbow=void 0,this.skyGlow?.dispose(),this.skyGlow=void 0,this.depthOfFieldPass?.dispose(),this.finishPass?.dispose(),this.depthOfFieldPass=void 0,this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0,this.cometTail?.dispose(),this.cometTail=void 0,this.satelliteField?.dispose(),this.satelliteField=void 0,this.reentrySystem?.dispose(),this.reentrySystem=void 0,this.lightningBolt?.dispose(),this.lightningBolt=void 0;for(const t of this.bodyMeshes.values())this.disposeMesh(t);this.bodyMeshes.clear(),this.novaKeys.clear();for(const t of[...this.hitAreas.keys()])this.disposeHitArea(t);for(const t of[...this.glareSprites.keys()])this.disposeGlare(t);this.disposeCompassLabels();for(const t of this.decorGroups.values())Ye.dispose(t);this.decorGroups.clear(),this.streetlightLights.clear(),this.lensFlare&&(this.lensFlare.mesh.removeFromParent(),this.lensFlare.mesh.geometry.dispose(),this.lensFlare.mesh.material.dispose(),this.lensFlare=void 0),this.renderer.dispose()}animationsRunning=!1;startTwinkle(){if(this.animationFrameId!==null||!this.needsAnimationLoop())return;this.cancelFlush();const t=e=>{this.animationFrameId=null,this.frame(e),this.animationFrameId===null&&this.needsAnimationLoop()&&(this.animationFrameId=requestAnimationFrame(t))};this.animationFrameId=requestAnimationFrame(t)}setAnimationsRunning(t,e=!1){const i=t&&e;if(t===this.animationsRunning&&i===this.framesDriven)return;const n=this.animationsRunning;this.animationsRunning=t,this.framesDriven=i,t&&!n&&(this.lastFrameTimeMs=void 0,this.resolution.reset());const s=!t&&this.renderer.getPixelRatio()!==this.resolution.maximum;s&&this.applyPixelRatio(this.resolution.maximum),this.syncAnimationLoop(),(!t||this.frameDirty)&&this.render(),s&&this.drawIfDirty()}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}needsAnimationLoop(){return this.animationsRunning&&!this.framesDriven&&!this.suspended&&this.hasAnimations()}hasAnimations(){return this.starTiers.some(t=>t.brightness.length>0)||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.flareMayShow()}flareAimScratch=new R;flareMayShow(){if(this.lensFlare===void 0||!this.sunVisible)return!1;const t=this.lastAstronomy?.sun;return t!==void 0&&t.altitudeDeg<le.FLARE_ANIMATION_MIN_ALTITUDE_DEG?!1:(this.camera.getWorldDirection(this.flareAimScratch),this.flareAimScratch.dot(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position))>0)}static FLARE_ANIMATION_MIN_ALTITUDE_DEG=-3;syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(t){const e=this.skyMesh?.geometry??new pi(Ah,32,16),i=e.attributes.position,n=e.getAttribute("color")??new ve(new Float32Array(i.count*3),3);for(let r=0;r<i.count;r++){const{altitudeDeg:o,azimuthDeg:c}=tT(i.getX(r),i.getY(r),i.getZ(r)),l=cT(o,c,t.azimuthDeg,t.altitudeDeg);n.setXYZ(r,l[0],l[1],l[2])}if(n.needsUpdate=!0,this.skyMesh)return;e.setAttribute("color",n);const s=new wn({vertexColors:!0,side:Qe,fog:!1,depthWrite:!1});this.skyGradientMaterial=s,this.skyMesh=new At(e,s),this.skyMesh.renderOrder=-1,this.celestialGroup.add(this.skyMesh)}buildGround(){const t=bv(this.observerElevationM);if(this.groundMesh&&t===this.groundRadius)return;this.disposeMesh(this.groundMesh),this.groundRadius=t;const e=new Wp(this.groundRadius,48),i=new nc({color:new st(Sf,Sf,Sf),fog:!0});Fa.fadeRim(i,this.groundRadius*.75,this.groundRadius),this.groundMesh=new At(e,i),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh),this.applyGroundDepthWrite()}applyGroundDepthWrite(){const t=this.groundMesh?.material;if(!t)return;const e=this.terrainMesh===void 0;t.depthWrite!==e&&(t.depthWrite=e,t.needsUpdate=!0);const i=this.terrainMesh;let n=0;if(i){const s=i.geometry.getAttribute("position");n=1/0;for(let r=0;r<s.count;r++)Math.abs(s.getX(r)+i.position.x)>600||Math.abs(s.getZ(r)+i.position.z)>600||(n=Math.min(n,s.getY(r)+i.position.y));n=Number.isFinite(n)?Math.min(0,n)-1:0}this.groundMesh.position.y=n,this.groundMesh.renderOrder=0,t.depthTest=!0,t.needsUpdate=!0}cloudTransmission(t,e=!1){const i=`${t.altitudeDeg.toFixed(1)}:${t.azimuthDeg.toFixed(1)}:${Math.round(this.cloudOffsetM.x/10)}:${Math.round(this.cloudOffsetM.z/10)}:${Math.round(this.observerElevationM)}:`+Object.entries(this.cloudLayerOffsetsM).map(([r,o])=>`${r}=${Math.round(o.x/10)},${Math.round(o.z/10)}`).join(";")+(e?":water":""),n=this.cloudTransmissionMemo.get(i);if(n!==void 0)return n;this.cloudTransmissionMemo.size>256&&this.cloudTransmissionMemo.clear();const s=this.computeCloudTransmission(t,e);return this.cloudTransmissionMemo.set(i,s),s}cloudTransmissionMemo=new Map;computeCloudTransmission(t,e=!1){const i=Xe(t.altitudeDeg,t.azimuthDeg,1);if(this.layeredClouds)return this.layeredClouds.transmissionAt(i,e);let n=1;const s=this.lowerCloudCover();s>0&&(n*=1-we.alphaAt(i,Math.abs(this.cloudLayerOffset()),s,this.cloudFieldOffset)*GR);const r=e?0:this.weather.highCloudCover??0;return r>0&&(n*=1-we.iceAlphaAt(i,Th,r,this.cloudFieldOffset)*VR),Math.max(0,Math.min(1,n))}setBodyMesh(t,e,i,n,s){if(e.altitudeDeg<Jh){this.disposeMesh(this.bodyMeshes.get(t)),this.bodyMeshes.delete(t),this.disposeHitArea(t),this.disposeGlare(t),t==="sun"&&(this.sunVisible=!1);return}const{x:r,y:o,z:c}=Xe(e.altitudeDeg,e.azimuthDeg,pn),l=G1(e.altitudeDeg),h=this.cloudTransmission(e),u=this.arrivingIlluminance(e,s,h),d=le.unitLuminance(n);let f=this.bodyMeshes.get(t);if(t==="sun"){const p=Math.PI*(i/pn)**2,v=[0,1,2].map(g=>d[g]*u[g]/(this.sunBeamFraction*p));this.sunDiscRadiance=v;const m=v.map(g=>Math.min(le.BRIGHTEST_RELATIVE,g));f instanceof At||(this.disposeMesh(f),f=new At(new pi(1,16,16),this.eclipsedSun.material()),this.celestialGroup.add(f),this.bodyMeshes.set(t,f)),f.material.color.setRGB(m[0],m[1],m[2]),f.scale.setScalar(i)}else{if(!(f instanceof In)){this.disposeMesh(f);const m=new ae;m.setAttribute("position",new te(new Float32Array(3),3)),m.setAttribute("color",new te(new Float32Array(3),3)),f=new In(m,Ct.material(Vo[Vo.length-1].size,!1)),Ct.track(f),this.celestialGroup.add(f),this.bodyMeshes.set(t,f)}const p=f.geometry.getAttribute("color"),v=t.startsWith("comet:")?this.pointToPixel():1;p.setXYZ(0,d[0]*u[0]*v,d[1]*u[1]*v,d[2]*u[2]*v),p.needsUpdate=!0}if(f.position.set(r,o,c),this.setHitArea(t,r,o,c,i),t==="sun"&&(this.sunArriving=u),t.startsWith("comet:")?this.disposeGlare(t):t!=="sun"&&this.setGlare(t,r,o,c,u,i/pn*(180/Math.PI),le.POINT_VEIL_HOLD_DEG),t==="sun"){this.sunVisible=!0;const p=this.celestialGroup.scale.x;this.sunWorldPosition.set(r*p,o*p+this.celestialGroup.position.y,c*p),this.lensFlare||(this.lensFlare=Q4(),this.lensFlare.uniforms.uOpacity.value=jR,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.lensFlare.uniforms.uStarPoints.value=this.starPoints,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(l)}}setMoonMesh(t,e){const i="moon";if(t.magnitude>e||t.altitudeDeg<Jh){this.disposeMesh(this.bodyMeshes.get(i)),this.bodyMeshes.delete(i),this.disposeHitArea(i),this.disposeGlare(i);return}const{x:n,y:s,z:r}=Xe(t.altitudeDeg,t.azimuthDeg,pn),o=this.cloudTransmission(t),c=this.arrivingIlluminance(t,t.magnitude,o),l=t.radiusDeg??Cs.MEAN_RADIUS_DEG,h=pn*Math.tan(l*Ei),u=Math.max(ir(t.phase.illuminatedFraction,0,1),.01)*Math.PI*(h/pn)**2,d=new st(...c.map(v=>Math.min(le.BRIGHTEST_RELATIVE,v/u))),f=`${t.phase.phaseFraction<.5}:${Math.round(ir(t.phase.illuminatedFraction,0,1)*500)}`;let p=this.bodyMeshes.get(i);p instanceof Mc?(p.userData.phaseKey!==f&&(p.material.map?.dispose(),p.material.map=Yv(t.phase),p.userData.phaseKey=f),p.material.color.copy(d)):(this.disposeMesh(p),p=new Mc(new Yh({map:Yv(t.phase),color:d,fog:!1})),p.userData.phaseKey=f,this.celestialGroup.add(p),this.bodyMeshes.set(i,p)),p.scale.set(h*2,h*2,1),p.position.set(n,s,r),this.setHitArea(i,n,s,r,h),this.setGlare(i,n,s,r,c,l)}bentLight(t,e,i=BR){const[n,s,r]=this.arrivingIlluminance(t,e,1),o=Math.max(s,1e-30);return{scale:s/i,tint:[n/o,1,r/o]}}static litBySky(t,e){return le.litScratch.setRGB(t.r*e[0],t.g*e[1],t.b*e[2])}static litScratch=new st;pointToPixel(){const t=Math.max(1,this.renderer.getDrawingBufferSize(this.pointScratch).y),e=(this.camera.fov*Math.PI/180/t)**2;return Math.min(1,Ct.CONE_SOLID_ANGLE/e)}pointScratch=new bt;static POINT_VEIL_HOLD_DEG=.25;static BRIGHTEST_RELATIVE=6e4;arrivingIlluminance(t,e,i){const n=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,t.altitudeDeg),s=ye.illuminanceOf(e)*i*this.relativeScale;return[n[0]*s,n[1]*s,n[2]*s]}static unitLuminance(t){const e=us.luminanceOf([t.r,t.g,t.b]);return e>0?[t.r/e,t.g/e,t.b/e]:[1,1,1]}setHitArea(t,e,i,n,s){let r=this.hitAreas.get(t);if(!r){const c=new Yh({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1});r=new Mc(c),this.celestialGroup.add(r),this.hitAreas.set(t,r)}r.position.set(e,i,n);const o=s*2;r.scale.set(o,o,1)}disposeHitArea(t){const e=this.hitAreas.get(t);e&&(e.removeFromParent(),e.material.dispose(),this.hitAreas.delete(t))}setGlare(t,e,i,n,s,r,o=0){if(Ki.radiusDeg(Ki.K*Math.max(...s))<=Math.max(r,o)){this.disposeGlare(t);return}let c=this.glareSprites.get(t);c||(c=new Ki(`veil:${t}`),this.celestialGroup.add(c.mesh),this.glareSprites.set(t,c)),c.shine({x:e,y:i,z:n},s,r,o)}disposeGlare(t){const e=this.glareSprites.get(t);e&&(e.mesh.removeFromParent(),e.dispose(),this.glareSprites.delete(t))}buildComet(t,e){const i=t&&`comet:${t.id}`;if(!t||!i||t.magnitude>e){this.disposeComet();return}this.cometKey&&this.cometKey!==i&&this.disposeComet();const n=Po(t.magnitude,e),s=lf(n);this.cometKey=i,this.setBodyMesh(i,t.position,Ef*(.5+.5*n),new st(s,s,s),t.magnitude),this.cometTail||(this.cometTail=new Rn(pn),this.celestialGroup.add(this.cometTail.object)),this.cometTail.set(t.position,t.tailEnd,n)}buildIceHalos(t,e){this.iceHalos||(this.iceHalos=new Ui,this.iceHalos.setCloudOffset(this.cloudFieldOffset),this.iceHalos.onReady=()=>this.render(),this.celestialGroup.add(this.iceHalos.object)),this.iceHalos.setUrgent(!!this.skyHoldUntilMs);const i=this.highCloudCover(),n=this.layeredClouds?.cirrusMask;if(this.iceHalos.setCloudOffset(n?.offset??this.cloudFieldOffset),this.layeredClouds?.hostHalo(this.iceHalos),i===void 0){this.iceHalos.update({x:0,y:1,z:0},-1,0,[1,1,1],{cover:0,layerHeight:Th},0);return}const s=this.lowerCloudCover(),r=Se.deckLitUntilDeg(Se.DECK_HEIGHT_M),o=t.altitudeDeg>-r?t:e,c=this.bentLight(o,o===t?se.SUN_MAGNITUDE:e.magnitude),l=Se.strength(i,s,o.altitudeDeg,r)*c.scale,{x:h,y:u,z:d}=Xe(o.altitudeDeg,o.azimuthDeg,1);this.iceHalos.update({x:h,y:u,z:d},o.altitudeDeg,l,c.tint,{cover:n?.cover??i,layerHeight:n?.layerHeight??Th},n?.iceCrystalAlignment??this.weather.iceCrystalAlignment??Iy)}buildRainbow(t,e){this.rainbow||(this.rainbow=new Ra,this.celestialGroup.add(this.rainbow.object));const i=this.weather.precipitationType==="rain"?this.weather.precipitationIntensity*(this.weather.precipitationAmount??1):0,n=t.altitudeDeg>0,s=n?t:e,r=this.lowerCloudCover(),o=this.bentLight(s,n?se.SUN_MAGNITUDE:e.magnitude,HR),c=Tn.strength(i,r,s.altitudeDeg)*o.scale;if(c<=0){this.rainbow.update({x:0,y:1,z:0},0,[1,1,1],!0);return}const{x:l,y:h,z:u}=Xe(s.altitudeDeg,s.azimuthDeg,1);this.rainbow.update({x:l,y:h,z:u},c,o.tint,n)}buildSkyGlow(t,e){if(!t.frame){this.skyGlow?.hide();return}this.skyGlow||(this.skyGlow=new Cr,this.skyGlow.setWithheld(!!this.skyHoldUntilMs),this.skyGlow.onReady=()=>this.render(),this.celestialGroup.add(this.skyGlow.object));const{date:i,observer:n}=t.frame,s=ns.galactic(i,n),r=le.directionOf(s.centre),o=le.directionOf(s.rotation),c=le.directionOf(s.pole),l=new Jt().set(r.x,r.y,r.z,o.x,o.y,o.z,c.x,c.y,c.z),h=le.directionOf(ns.eclipticPole(i,n)),u=le.directionOf(t.sun),d=u.clone().addScaledVector(h,-u.dot(h)).normalize();this.skyGlow.update({galactic:l,eclipticPole:h,sunLongitude:d,sunDirection:u,sunAltitudeDeg:t.sun.altitudeDeg,moon:{direction:le.directionOf(t.moon),altitudeDeg:t.moon.altitudeDeg,phaseAngleDeg:St.phaseAngleOf(t.moon.phase.illuminatedFraction)},lightPollution:this.lightPollution,skyColor:new R(e[0],e[1],e[2])})}static directionOf(t){const{x:e,y:i,z:n}=Xe(t.altitudeDeg,t.azimuthDeg,1);return new R(e,i,n).normalize()}buildNovae(t,e){const i=new Set;for(const n of t){if(n.magnitude>e)continue;const s=`nova:${n.id}`;i.add(s);const r=Po(n.magnitude,e),o=lf(r);this.setBodyMesh(s,n.position,Ef*(.5+.5*r),new st(o,o,o),n.magnitude)}for(const n of this.novaKeys)i.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n));this.novaKeys=i}disposeComet(){this.cometTail?.set(void 0,void 0,0),this.cometKey&&(this.disposeMesh(this.bodyMeshes.get(this.cometKey)),this.bodyMeshes.delete(this.cometKey),this.disposeHitArea(this.cometKey),this.disposeGlare(this.cometKey),this.cometKey=void 0)}buildPlanets(t,e){const i=new Set(["sun","moon",...this.cometKey?[this.cometKey]:[],...this.novaKeys]);for(const n of t){if(n.magnitude>e)continue;i.add(n.body);const s=Po(n.magnitude,e),r=lf(s),o=MD[n.body]??new st(1,1,1),c=new st(o.r*r,o.g*r,o.b*r),l=Ef*(.5+.5*s);this.setBodyMesh(n.body,n.position,l,c,n.magnitude)}for(const n of[...this.bodyMeshes.keys()])i.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n))}buildStars(t,e){if(this.namedStars=[],!t||t.catalog.count===0){this.disposeStarTiers(),this.syncAnimationLoop();return}const{catalog:i,date:n,observer:s}=t,r=new os(n,s),o=Nf(1337),c=[],l=this.siteElevationM+this.observerElevationM;for(let h=0;h<i.count;h++){const u=i.mag[h];if(u>e)break;const{altitudeDeg:d,azimuthDeg:f}=r.position(i.ra[h],i.dec[h]);if(d<wv)continue;const{x:p,y:v,z:m}=Xe(d,f,wf);c.push({x:p,y:v,z:m,brightness:Po(u,e),illuminance:this.air.transmittanceFromSpace(l,d).map(g=>g*ye.illuminanceOf(u)),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}for(const h of P4){if(h.mag>e)continue;const{altitudeDeg:u,azimuthDeg:d}=r.position(h.raHours,h.decDeg);if(u<wv)continue;const{x:f,y:p,z:v}=Xe(u,d,wf);this.namedStars.push({star:h,direction:new R(f,p,v).normalize(),altitudeDeg:u})}this.starTiers=Vo.map((h,u)=>{const d=c.filter(x=>tm(x.brightness)===u),f=new Float32Array(d.length*3),p=new Float32Array(d.length),v=new Float32Array(d.length*3),m=new Float32Array(d.length),g=new Float32Array(d.length);d.forEach((x,_)=>{f[_*3]=x.x,f[_*3+1]=x.y,f[_*3+2]=x.z,p[_]=x.brightness,v.set(x.illuminance,_*3),m[_]=x.phase,g[_]=x.speedFactor});const b=new ae;b.setAttribute("position",new te(f,3)),b.setAttribute("seed",new te(m.map(x=>x/(2*Math.PI)),1));const S=new te(new Float32Array(d.length*3),3);b.setAttribute("color",S);let M=this.starTiers[u]?.points;return M?(M.geometry.dispose(),M.geometry=b):(M=new In(b,Ct.material(h.size)),Ct.track(M),this.celestialGroup.add(M)),{points:M,colorAttribute:S,brightness:p,illuminance:v,phase:m,speedFactor:g}}),this.starColoursRelative=Number.NaN,this.updateTwinkle(this.twinkleSeconds),this.startTwinkle()}twinkleSeconds=0;starColoursRelative=Number.NaN;updateTwinkle(t){Ct.setTime(t);const e=this.relativeScale;if(e!==this.starColoursRelative){this.starColoursRelative=e;for(const i of this.starTiers){const n=i.colorAttribute.array;for(let s=0;s<i.brightness.length;s++)n[s*3]=i.illuminance[s*3]*e,n[s*3+1]=i.illuminance[s*3+1]*e,n[s*3+2]=i.illuminance[s*3+2]*e;i.colorAttribute.needsUpdate=!0}}}buildClouds(){if(this.cloudRendering==="volume"||this.weather.cloudLayers!==void 0){this.layeredClouds||(this.disposeCloudSystem(),this.layeredClouds=new Ho(this.celestialGroup,Af,this.cloudRendering)),this.disposeCirrus(),this.layeredClouds.hostHalo(this.iceHalos),this.layeredClouds.update(this.weather,this.observerElevationM+1.6),this.layeredClouds.setOffsets(this.cloudOffsetM,this.cloudLayerOffsetsM),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const t=this.lowerCloudCover();if(t<=0){this.disposeCloudSystem();return}const e=this.weather.cloudDarkness,i=new st(ia[0]+(Df[0]-ia[0])*e,ia[1]+(Df[1]-ia[1])*e,ia[2]+(Df[2]-ia[2])*e);if(this.cloudMesh&&this.cloudUniforms){this.cloudUniforms.coverage.value=t,this.cloudUniforms.baseColor.value.copy(i),this.syncCloudLayer(),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}this.disposeCloudSystem();const{material:n,uniforms:s}=W0(i,t,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,s.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const r=X0(Af);this.cloudMesh=new At(r,n),this.faceCloudDeck(this.cloudMesh,this.cloudLayerOffset()),this.celestialGroup.add(this.cloudMesh)}lowerCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(t=>t.type!=="cirrus").reduce((t,e)=>t*(1-e.coverage),1):this.weather.lowerCloudCover??this.weather.cloudCover}highCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(t=>t.type==="cirrus").reduce((t,e)=>t*(1-e.coverage),1):this.weather.highCloudCover}buildCirrus(){const t=this.weather.highCloudCover??0;if(this.layeredClouds||t<=0){this.disposeCirrus();return}if(this.cirrusMesh&&this.cirrusUniforms){this.cirrusUniforms.coverage.value=t,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const{material:e,uniforms:i}=W0(new st(...ia),t,Th,1);this.cirrusMaterial=e,this.cirrusUniforms=i,i.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.cirrusMesh=new At(X0(Af*1.04),e),this.cirrusMesh.renderOrder=Iv-1,this.celestialGroup.add(this.cirrusMesh)}disposeCirrus(){this.cirrusMesh&&(this.cirrusMesh.removeFromParent(),this.cirrusMesh.geometry.dispose()),this.cirrusMaterial?.dispose(),this.cirrusMesh=void 0,this.cirrusMaterial=void 0,this.cirrusUniforms=void 0}syncCloudLayer(){this.layeredClouds?.update(this.weather,this.observerElevationM+1.6);const t=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(t)),this.cloudMesh&&this.faceCloudDeck(this.cloudMesh,t)}faceCloudDeck(t,e){const i=e<0;t.scale.y=i?-1:1,t.renderOrder=i?Ho.deckOrder(!0,0,1):Iv}cloudLayerOffset(){const e=((this.weather.cloudBaseM??Mp)-this.observerElevationM)*Tf;return Math.sign(e||1)*Math.max(Math.abs(e),tD)}updateCloudLighting(t,e){const i=[this.cloudUniforms,this.cirrusUniforms].filter(u=>u!==void 0);if(i.length===0&&!this.layeredClouds)return;const n=this.cloudBeamDirection,[s,r,o]=this.cloudBeam.map(u=>u/Math.PI),c=this.lightningLevel*Lf*this.relativeScale/Math.PI,l=new st(e[0]+Ss.r*c,e[1]+Ss.g*c,e[2]+Ss.b*c);this.layeredClouds?.setLighting(n.clone(),new st(s,r,o),l,l);const h=Math.max(0,n.y);for(const u of i)u.sunDir.value.copy(n),u.sunColor.value.setRGB(s*h,r*h,o*h),u.ambientColor.value.copy(l)}disposeCloudSystem(){this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.cloudMesh&&(this.cloudMesh.removeFromParent(),this.cloudMesh.geometry.dispose()),this.cloudMaterial?.dispose(),this.cloudMesh=void 0,this.cloudMaterial=void 0,this.cloudUniforms=void 0}disposePrecipitationPoints(){this.precipitationPoints&&(this.precipitationPoints.removeFromParent(),this.precipitationPoints.geometry.dispose(),this.precipitationPoints.material.dispose()),this.precipitationPoints=void 0,this.precipitationPositions=void 0,this.precipitationPhase=void 0,this.precipitationSpeedJitter=void 0,this.precipitationWobbleFreqJitter=void 0,this.precipitationWobbleAmpJitter=void 0,this.precipitationBounceRemaining=void 0,this.precipitationBounceHeight=void 0,this.precipitationBounceDuration=void 0,this.precipitationBounceVelX=void 0,this.precipitationBounceVelZ=void 0,this.precipitationUniforms=void 0}precipitationCount(t){return cD(t,this.weather.precipitationIntensity,this.weather.precipitationAmount??1)}updatePrecipitationDensity(){const t=[[this.rainSystem?.points,Pf],[this.rainSplashSystem?.points,na],[this.precipitationPoints,this.weather.precipitationType==="none"||this.weather.precipitationType==="rain"?void 0:If[this.weather.precipitationType].poolSize]];for(const[e,i]of t)e&&i!==void 0&&e.geometry.setDrawRange(0,this.precipitationCount(i));this.rainSystem&&(this.rainSystem.uniforms.uSpeedStreak.value=Lv(Of(this.weather.precipitationIntensity)))}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const t=this.weather.precipitationType;if(t==="none")return;if(t==="rain"){this.buildRain();return}const e=If[t],i=e.poolSize,n=Nf(9001),s=new Float32Array(i*3),r=new Float32Array(i),o=new Float32Array(i),c=new Float32Array(i),l=new Float32Array(i),h=new Float32Array(i),u=new Float32Array(i),d=new Float32Array(i),f=new Float32Array(i),p=new Float32Array(i);for(let S=0;S<i;S++){const M=n()*Math.PI*2,x=n()*e.radiusM;s[S*3]=Math.cos(M)*x,s[S*3+1]=To+n()*(e.topYM-To),s[S*3+2]=Math.sin(M)*x,r[S]=n()*Math.PI*2,o[S]=.7+n()*.6,c[S]=.6+n()*.8,l[S]=.4+n()*1.2}const v=new ae;v.setAttribute("position",new te(s,3)),v.setDrawRange(0,this.precipitationCount(i));const m={uSize:{value:e.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:e.opacity},uColor:{value:e.color.clone()},uHazeColor:{value:new st(...this.baseFogColor)},uTexture:{value:yD(t)},uNearFocusDistance:{value:Uv},uHazeDistance:{value:e.radiusM*zv}},g=new Me({uniforms:m,vertexShader:ED,fragmentShader:AD,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const b=new In(v,g);b.renderOrder=Rf,this.scene.add(b),this.precipitationPoints=b,this.precipitationPositions=s,this.precipitationPhase=r,this.precipitationSpeedJitter=o,this.precipitationWobbleFreqJitter=c,this.precipitationWobbleAmpJitter=l,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=u,this.precipitationBounceDuration=d,this.precipitationBounceVelX=f,this.precipitationBounceVelZ=p}updatePrecipitation(t,e){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter)return;this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor);const i=this.weather.precipitationType;if(i==="none"||i==="rain")return;const n=If[i];if(this.precipitationUniforms?.uColor.value.copy(le.litBySky(n.color,this.baseFogColor)),e<=0)return;const s=this.weather.windDirectionDeg*Ei,r=Math.sin(s)*this.weather.windSpeed*n.driftSensitivity,o=-Math.cos(s)*this.weather.windSpeed*n.driftSensitivity,c=this.precipitationPositions,l=this.precipitationPhase,h=this.precipitationSpeedJitter,u=this.precipitationWobbleFreqJitter,d=this.precipitationWobbleAmpJitter,f=this.precipitationBounceRemaining,p=this.precipitationBounceHeight,v=this.precipitationBounceDuration,m=this.precipitationBounceVelX,g=this.precipitationBounceVelZ,b=i==="snow"&&u&&d,S=i==="hail"&&f&&p&&v&&m&&g;for(let M=0,x=0;M<c.length;M+=3,x++){if(S&&f[x]>0){if(f[x]-=e,f[x]<=0){const y=Math.random()*Math.PI*2,T=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(y)*T,c[M+1]=n.topYM,c[M+2]=Math.sin(y)*T,f[x]=0}else{const y=1-f[x]/v[x];c[M+1]=To+Math.sin(Math.PI*y)*p[x],c[M]=Ih(c[M]+(r+m[x])*e,n.radiusM),c[M+2]=Ih(c[M+2]+(o+g[x])*e,n.radiusM)}continue}let _=0,E=0;if(b){const y=hD*u[x],T=uD*d[x];_=Math.sin(t*y*Math.PI*2+l[x])*T,E=Math.sin(t*y*Math.PI*2+l[x]+Math.PI/2)*T}if(c[M]+=(r+_)*e,c[M+1]-=n.fallSpeedMPerS*h[x]*e,c[M+2]+=(o+E)*e,c[M]=Ih(c[M],n.radiusM),c[M+2]=Ih(c[M+2],n.radiusM),c[M+1]<To){if(S){p[x]=Wv*(.2+Math.random()*1.6),v[x]=dD*(.5+Math.random()),f[x]=v[x];const I=Math.random()*Math.PI*2,C=fD*(p[x]/Wv);m[x]=Math.cos(I)*C,g[x]=Math.sin(I)*C,c[M+1]=To;continue}const y=Math.random()*Math.PI*2,T=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(y)*T,c[M+1]=n.topYM,c[M+2]=Math.sin(y)*T}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const t=Of(this.weather.precipitationIntensity);this.rainSystem=K4({count:Pf,radiusM:Cc,heightM:iD,bottomYM:Cv,overallSpeed:nD,color:Ov.clone(),opacity:.85,visibleCount:this.precipitationCount(Pf),speedStreak:Lv(t),pixelSize:Hv,seed:9001,nearFocusDistanceM:Uv,hazeDistanceM:Cc*zv,hazeColor:new st(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.syncRainSlant(),this.rainSystem.points.renderOrder=Rf,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const t=Nf(4242),e=new Float32Array(na*3),i=new Float32Array(na),n=new Float32Array(na),s=new Float32Array(na);for(let h=0;h<na;h++){const u=t()*Math.PI*2,d=Math.sqrt(t())*Cc;e[h*3]=Math.cos(u)*d,e[h*3+1]=Cv,e[h*3+2]=Math.sin(u)*d,n[h]=Xv(Nv,kv),i[h]=t()*n[h],s[h]=i[h]/n[h]}const r=new ae;r.setAttribute("position",new te(e,3));const o=new te(s,1);r.setAttribute("aLife",o),r.setDrawRange(0,this.precipitationCount(na));const c=new Me({uniforms:{uMaxSize:{value:oD},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:Fv.clone()},uTexture:{value:SD()}},vertexShader:wD,fragmentShader:_D,transparent:!0,depthWrite:!1}),l=new In(r,c);l.renderOrder=Rf,this.scene.add(l),this.rainSplashSystem={points:l,positions:e,life:i,duration:n,lifeAttribute:o}}disposeRain(){this.rainSystem&&(this.rainSystem.points.removeFromParent(),this.rainSystem.points.geometry.dispose(),this.rainSystem.points.material.dispose()),this.rainSystem=void 0,this.disposeRainSplashes()}disposeRainSplashes(){this.rainSplashSystem&&(this.rainSplashSystem.points.removeFromParent(),this.rainSplashSystem.points.geometry.dispose(),this.rainSplashSystem.points.material.dispose()),this.rainSplashSystem=void 0}syncRainSlant(){const t=this.rainSystem;if(!t)return;const e=this.weather.windDirectionDeg*Ei;t.uniforms.uDropVelocity.value.set(Math.sin(e)*this.weather.windSpeed,-Of(this.weather.precipitationIntensity),-Math.cos(e)*this.weather.windSpeed);const i=this.renderer.getSize(this.rainViewportSize);t.uniforms.uAspect.value=i.x/Math.max(i.y,1)}updateRain(t){const e=this.rainSystem;if(!e)return;e.uniforms.uTime.value+=t,e.uniforms.uHazeColor.value.setRGB(...this.baseFogColor),e.uniforms.uColor.value.copy(le.litBySky(Ov,this.baseFogColor));const i=this.rainSplashSystem?.points.material?.uniforms?.uColor;i&&i.value.copy(le.litBySky(Fv,this.baseFogColor));const n=this.weather.windDirectionDeg*Ei,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,o=Cc,c=h=>(h%(o*2)+o*3)%(o*2)-o;e.uniforms.uWindOffset.value.set(c(e.uniforms.uWindOffset.value.x+s*t),c(e.uniforms.uWindOffset.value.y+r*t)),this.syncRainSlant(),this.camera.getWorldDirection(this.rainCameraDirection);const l=Math.abs(this.rainCameraDirection.y);if(Math.abs(l-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=l;const h=Gv+(1-Gv)*(1-l),u=Vv+(1-Vv)*(1-l);e.uniforms.uUvSquash.value=u,e.uniforms.uPixelSize.value=Hv*h*(.5+.5*u)}this.updateRainSplashes(t)}updateRainSplashes(t){const e=this.rainSplashSystem;if(!e||t<=0)return;const{positions:i,life:n,duration:s,lifeAttribute:r}=e,o=r.array;for(let c=0,l=0;c<i.length;c+=3,l++){if(n[l]+=t,n[l]>=s[l]){const h=Math.random()*Math.PI*2,u=Math.sqrt(Math.random())*Cc;i[c]=Math.cos(h)*u,i[c+2]=Math.sin(h)*u,s[l]=Xv(Nv,kv),n[l]=0}o[l]=n[l]/s[l]}e.points.geometry.attributes.position.needsUpdate=!0,r.needsUpdate=!0}setLightning(t){this.lightningFlashes=t}updateLightning(t){let e,i=0;if(this.lightningArmed)for(const c of this.lightningFlashes){if(c.t>t)break;const l=Ii.brightnessAt(c,t);l>i&&(e=c,i=l)}const n=e?Math.min(1,Math.max(.1,(gD/e.distanceM)**2)):0,s=i*n*(e?.cloudToGround?1:.6);if(s===this.lightningLevel&&!e?.cloudToGround)return;if(this.lightningLevel=s,this.scene.fog){const c=this.scene.fog,l=s*Lf*this.relativeScale/Math.PI;c.color.setRGB(this.airlight[0]+Ss.r*l,this.airlight[1]+Ss.g*l,this.airlight[2]+Ss.b*l)}const r=this.skyMesh?.material?.color;if(r){const c=s*vD;r.setRGB(1+c*Ss.r,1+c*Ss.g,1+c*Ss.b)}if(this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.lightningLight.intensity=s*Lf*this.relativeScale,e){const{x:c,y:l,z:h}=Xe(25,e.azimuthDeg,pn);this.lightningLight.position.set(c,l,h)}this.lightningBolt||(this.lightningBolt=new Pr(pn*.95),this.celestialGroup.add(this.lightningBolt.object));const o=this.weather.cloudBaseM??1500;this.lightningBolt.set(e,i,o),this.render()}buildCompassLabels(){this.compassSprites=XR.map(t=>{const e=Na.point(t,this.compassPoints),i=new Yh({map:TD(e),depthTest:!1,fog:!1}),n=new Mc(i),{x:s,y:r,z:o}=Xe(0,t,Av);return n.position.set(s,r,o),n.scale.set(Dh,Dh,1),n.renderOrder=$R,n.layers.set(bf),n.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(n),n}),this.updateCompassScale()}updateCompassScale(){const t=this.camera.fov*Math.PI/360,e=Tv*Math.PI/360,i=Dh*Math.tan(t)/Math.tan(e);for(const n of this.compassSprites)n.scale.set(i,i,1)}disposeCompassLabels(){for(const t of this.compassSprites)t.removeFromParent(),t.material.map?.dispose(),t.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const t of this.starTiers)this.disposeMesh(t.points);this.starTiers=[]}disposeMesh(t){if(!t)return;t.removeFromParent(),"geometry"in t&&t.geometry.dispose();const e=t.material;for(const i of Array.isArray(e)?e:[e]){const n=i.map;n&&n.dispose(),i.dispose()}}}const Ei=Math.PI/180;function ir(a,t,e){return Math.max(t,Math.min(e,a))}function Xv(a,t){return a+Math.random()*(t-a)}function Ih(a,t){return(a%(t*2)+t*3)%(t*2)-t}let Ch,Ph;function yD(a){switch(a){case"snow":return xD();case"hail":return bD()}}function xD(){if(Ch)return Ch;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/2);return i.addColorStop(0,"rgba(255,255,255,0.95)"),i.addColorStop(.5,"rgba(255,255,255,0.55)"),i.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=i,e.fillRect(0,0,a,a),Ch=new pr(t),Ch}function bD(){if(Ph)return Ph;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/2);return i.addColorStop(0,"rgba(255,255,255,1)"),i.addColorStop(.55,"rgba(255,255,255,0.95)"),i.addColorStop(.8,"rgba(255,255,255,0.4)"),i.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=i,e.fillRect(0,0,a,a),Ph=new pr(t),Ph}let Oh;function SD(){if(Oh)return Oh;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/2);return i.addColorStop(0,"rgba(255,255,255,0)"),i.addColorStop(.4,"rgba(255,255,255,0)"),i.addColorStop(.6,"rgba(255,255,255,0.9)"),i.addColorStop(.8,"rgba(255,255,255,0.25)"),i.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=i,e.fillRect(0,0,a,a),Oh=new pr(t),Oh}const wD=`
8694
+ `,transparent:!0,blending:Ti,depthWrite:!1,side:Qe,fog:!1});this.object=new At(new pi(fm.RADIUS,128,32,0,Math.PI*2,0,ye.MAX_ANGLE_RAD),e),this.object.renderOrder=-1,this.object.frustumCulled=!1,this.object.visible=!1}show(t,e){if(!t||!e){this.object.visible=!1;return}this.towards.set(t.x,t.y,t.z).normalize(),this.object.quaternion.setFromUnitVectors(this.up,this.towards),this.object.material.uniforms.uSource.value.copy(this.towards);for(let i=0;i<ye.STEPS;i++){for(let n=0;n<3;n++)this.texels[i*4+n]=kn.toHalfFloat(Math.min(e[i*3+n],6e4));this.texels[i*4+3]=kn.toHalfFloat(1)}this.texture.needsUpdate=!0,this.object.visible=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose()}}class Vu{constructor(t){this.generator=t}static SIZE=128;target=new fl(Vu.SIZE,{type:qe,generateMipmaps:!1,minFilter:de,magFilter:de});camera=new Kp(.1,2e5,this.target);filteredTarget;capturedAtMs=-1/0;capturedVersion;get sharp(){return this.target.texture}get filtered(){return this.filteredTarget?.texture}capture(t,e,i,n=[]){const s=t.shadowMap.autoUpdate;let r=!1;e.traverse(c=>{const l=c;l.isLight&&l.castShadow&&l.shadow&&!l.shadow.map&&(r=!0)}),t.shadowMap.autoUpdate=r?s:!1;const o=n.map(c=>c.visible);for(const c of n)c.visible=!1;this.camera.position.copy(i),this.camera.update(t,e),n.forEach((c,l)=>{c.visible=o[l]}),t.shadowMap.autoUpdate=s,this.filteredTarget=this.generator.fromCubemap(this.target.texture,this.filteredTarget),this.capturedAtMs=performance.now()}dispose(){this.target.dispose(),this.filteredTarget?.dispose()}}class Mn{static REFRESH_MS=250;generator;eye;probes=new Map;constructor(t){Mn.install(),this.generator=new B0(t),this.eye=new Vu(this.generator)}static decor;refresh(t,e,i,n,s,r,o,c=[],l,h=Mn.REFRESH_MS){for(const m of[...this.probes.keys()])n.some(g=>g.id===m&&g.shiny)||(this.probes.get(m).dispose(),this.probes.delete(m));const u=[{probe:this.eye}];for(const m of n){if(!m.shiny)continue;let g=this.probes.get(m.id);g||(g=new Vu(this.generator),this.probes.set(m.id,g)),u.push({probe:g,reflector:m})}const d=performance.now(),f=()=>u.filter(({probe:m})=>m.capturedVersion!==o),p=f().filter(({probe:m})=>d-m.capturedAtMs>=h);if(p.length>0){const m=p.reduce((g,b)=>b.probe.capturedAtMs<g.probe.capturedAtMs?b:g);if(m.reflector){const g=m.reflector.holder.getWorldPosition(this.scratch);m.probe.capture(t,e,g,[m.reflector.holder,...s]),Mn.reflectOn(m.reflector.holder,m.probe)}else{m.probe.capture(t,e,i,[...s,...c]),l?.(m.probe.sharp),Mn.decor=m.probe.filtered;for(const g of r)Mn.reflectOn(g,m.probe);for(const g of n)g.shiny||Mn.reflectOn(g.holder,m.probe)}m.probe.capturedVersion=o}const v=f();if(v.length!==0)return Math.max(16,Math.min(...v.map(({probe:m})=>h-(d-m.capturedAtMs))))}scratch=new R;static reflectOn(t,e={filtered:Mn.decor}){t.traverse(i=>{const n=i.material;for(const s of Array.isArray(n)?n:n?[n]:[])s instanceof vl?e.sharp&&s.setSurroundings(e.sharp):s instanceof Nr&&e.filtered&&s.envMap!==e.filtered&&(s.envMap=e.filtered,s.needsUpdate=!0)})}dispose(){this.eye.dispose();for(const t of this.probes.values())t.dispose();this.generator.dispose()}static installed=!1;static install(){if(Mn.installed)return;Mn.installed=!0;const t="iblIrradiance += getIBLIrradiance( geometryNormal );";if(!Zt.lights_fragment_maps.includes(t)){console.warn("Reflections: three's lights_fragment_maps changed; the environment will light diffusely too");return}Zt.lights_fragment_maps=Zt.lights_fragment_maps.replace(t,"// The sky's diffuse light is the hemisphere light's (see Reflections).")}}function OR(a,t){return JSON.stringify(a.cloudLayers)===JSON.stringify(t.cloudLayers)&&a.cloudCover===t.cloudCover&&a.cloudDarkness===t.cloudDarkness&&a.cloudBaseM===t.cloudBaseM&&a.highCloudCover===t.highCloudCover&&a.iceCrystalAlignment===t.iceCrystalAlignment&&a.lowerCloudCover===t.lowerCloudCover&&a.relativeHumidity===t.relativeHumidity&&a.precipitationType===t.precipitationType&&a.precipitationIntensity===t.precipitationIntensity&&a.precipitationAmount===t.precipitationAmount&&a.windDirectionDeg===t.windDirectionDeg&&a.windSpeed===t.windSpeed&&a.storm===t.storm}const Ah=900,xf=1,yv=4,bf=5,xv=.5,Bc=900,LR=6371e3,NR=3e4;function bv(a){const t=Math.sqrt(2*LR*Math.max(a,0));return Math.max(Bc,Math.min(t,NR))}const Sf=.5,wf=850,_f=.03,kR=.015,pn=850,Ic=300,Ar=120,FR=700,UR=.04,Sv=4,Ef=1.5,wv=-1,zR=.01,Jh=-4,BR=2,HR=20,Th=2600,GR=.97,VR=.38,Rh=Jh,_v=1500,WR=400,XR=[0,45,90,135,180,225,270,315],YR=2,qR=16,Ev=4e3,Av=880,Dh=40,Tv=60,$R=10,KR=1,ZR=150,JR=55,jR=.5,QR=17,Rv=.265,Dv=[[0,0],...Array.from({length:8},(a,t)=>{const e=t*Math.PI/4;return[Math.cos(e)*Rv,Math.sin(e)*Rv]})],Af=700,Tf=250/Mp,tD=12,Iv=5,Rf=6,ia=[.92,.92,.95],Df=[.15,.15,.19],If={snow:{fallSpeedMPerS:2,size:.3,color:new st(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new st(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},To=0,Cf=0,eD=150,Pf=3e3,Cc=20,iD=15,Cv=To,nD=40,Pv=1,sD=9;function Of(a){return Pv+(sD-Pv)*a}const Ov=new st(.75,.82,.92),rD=10,aD=.5;function Lv(a){return ir(a/rD,aD,1)}const na=200,Nv=.18,kv=.32,oD=.35,Fv=new st(.85,.9,.98),Uv=5,zv=.85,Bv=.01;function cD(a,t,e=1){return Math.round(a*(Bv+(1-Bv)*t)*e)}function lD(a,t){return JSON.stringify(a.cloudLayers)===JSON.stringify(t.cloudLayers)&&a.cloudCover===t.cloudCover&&a.cloudDarkness===t.cloudDarkness&&a.cloudBaseM===t.cloudBaseM&&a.highCloudCover===t.highCloudCover&&a.iceCrystalAlignment===t.iceCrystalAlignment&&a.lowerCloudCover===t.lowerCloudCover}const Hv=230,Gv=.7,Vv=.05,hD=.6,uD=.7,dD=.15,Wv=.35,fD=3,pD=1/12,mD=.5,Ss=new st(.82,.86,1),gD=2500,vD=1.6,Lf=15,MD={Venus:new st(1,.96,.85),Mars:new st(1,.55,.4),Jupiter:new st(.95,.87,.72),Saturn:new st(.92,.86,.68)};class le{renderer;scene=new Gs;phenomena=new ss(this.scene);references=new is(this.scene,()=>this.render());camera;celestialGroup=new Ee;skyMesh;skyGradientMaterial;scatteredSky;lastAstronomy;skyColoursStale=!1;scatteredSkyFrameId=null;skyHoldUntilMs=void 0;onFirstFrameHold;firstFrameReady(){return(!this.scatteredSky||this.scatteredSky.ambient!==void 0)&&!this.iceHalos?.awaitingFirstDisplay}sceneSettled(){return this.firstFrameReady()&&this.arrivalsPending===0&&this.eyeSettledVersion>=this.lastArrivalVersion}arrivalsPending=0;eyeSettledVersion=-1;lastArrivalVersion=0;awaitArrival(t,e){if(this.skyHoldUntilMs===null)return t;this.arrivalsPending++;let i=!0;const n=()=>{i&&(i=!1,this.arrivalsPending--,this.lastArrivalVersion=this.sceneVersion,this.skyHoldUntilMs&&this.redrawHeld())},s=e===void 0?void 0:setTimeout(n,e);return e!==void 0&&(this.arrivalDeadlineMs=Math.max(this.arrivalDeadlineMs,performance.now()+e),this.skyHoldUntilMs&&this.arrivalDeadlineMs>this.skyHoldUntilMs&&(this.skyHoldUntilMs=this.arrivalDeadlineMs,setTimeout(()=>this.render(),e+20))),t.finally(()=>{clearTimeout(s),n()})}static ROADS_PATIENCE_MS=4e3;static TERRAIN_PATIENCE_MS=12e3;arrivalDeadlineMs=0;redrawHeld(){this.frameDirty=!0,!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))}holdForNewScene(t){this.surroundings=void 0,this.scatteredSky?.resetSurroundings(),this.startHold(),t&&this.awaitArrival(t).catch(()=>{})}startHold(){this.skyHoldUntilMs=Math.max(performance.now()+Ev,this.arrivalDeadlineMs),this.eyeSettledVersion=-1,this.lastArrivalVersion=this.sceneVersion+1,this.iceHalos?.setUrgent(!0),this.skyGlow?.setWithheld(!0),this.onFirstFrameHold?.(!0),setTimeout(()=>this.render(),Ev+20)}groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;roadSystem=new Hn;roadAttribution;roadWays;statedRoads=[];traces=[];traceLabels=new Map;tracesShown=!0;traceSystem;traceSystemLoading;traceResolution=new bt;decorModelProvider=IR[0].create();decorModelToken=0;decorModelCredits=new Map;bodySystem=new he(t=>this.awaitArrival(this.loadBodyModel(t)),()=>this.render(),()=>this.relativeScale);bodyOrigin={x:0,z:0};starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];terraces=[];decorGroups=new Map;decorPresence=new Map;decorSunlight=new Map;static TRAFFIC_MODEL_RANGE_PER_METRE=133;static TRAFFIC_MODEL_DEFAULT_LENGTH_M=37.6;static trafficModelRangeM(t){return(t.sizeM?.lengthM??le.TRAFFIC_MODEL_DEFAULT_LENGTH_M)*le.TRAFFIC_MODEL_RANGE_PER_METRE}pendingTrafficModels=new Map;contrails=[];contrailSystem;contrailSystemLoading;contrailSunlight=new Map;sceneSunBeam=[0,0,0];decorReferencePose;decorCurrentPose;decorTime=0;celestialLight=new h1(16777215,0);celestialLightTarget=new ti;skyLight=new Aw(16777215,0,0);streetlightLights=new Map;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;resolution;cssSize={width:1,height:1};frameDirty=!1;flushFrameId=null;framesDriven=!1;lastFrameTimeMs;raycaster=new qh;weather=Zu;observerElevationM=0;siteElevationM=0;air=new Wn;groundRadius=Bc;terrainRadius=Bc;cloudRendering="volume";layeredClouds;cloudLayerOffsetsM={};cloudOffsetM=new R;cloudFieldOffset=new R;cloudMesh;cirrusMesh;cirrusMaterial;cirrusUniforms;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new R;rainLastVerticalFacing=-1;rainViewportSize=new bt;lightningArmed=!1;lightningFlashes=[];lightningLevel=0;lightningBolt;lightningLight=new h1(16777215,0);baseFogColor=[0,0,0];lastSunPosition;lensFlare;sunUnhiddenFraction=1;lensFlareArtifactIntensity=0;sunWorldPosition=new R;sunVisible=!1;lensFlareScratch=new R;sunOcclusionRaycaster=new qh;sunOcclusionDirectionScratch=new R;sunOcclusionRightScratch=new R;sunOcclusionUpScratch=new R;ufoOcclusionRaycaster=new qh;projectionKind="rectilinear";starPoints=0;namedStars=[];equidistantPass;depthOfFieldPass;finishPass;exposureAccumulation;exposureInstants=1;get developingExposure(){return this.exposureInstants>1&&this.exposureInstantAt!==void 0}static EXPOSURE_BUDGET_MS=12;static exposureInstantsPerFrame(t){return Math.max(3,Math.round(6e6/Math.max(1,t)))}exposureFrameId=null;exposureInstantsDone=0;exposureInstantAt;restatingExposure=!1;lensOptics;instrumentMagnitudeGain=0;lightPollution;meteorSystem;cometTail;satelliteField;reentrySystem;iceHalos;lunarDiffraction;eclipsedSun=new Ml;eclipseDiscs;solarCorona;sunBeamFraction=1;sunDiscRadiance=[0,0,0];lunarDiffractionKey="";rainbow;skyGlow;cometKey;novaKeys=new Set;constructor(t,e=Rb()){this.renderer=new HA({canvas:t,antialias:!0}),this.resolution=new _e(Math.min(window.devicePixelRatio||1,2),this.renderer.getContext()),this.renderer.setPixelRatio(this.resolution.pixelRatio),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Xc,this.camera=new yn(60,t.width/Math.max(t.height,1),.1,Ah*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=e,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-Ar,this.celestialLight.shadow.camera.right=Ar,this.celestialLight.shadow.camera.top=Ar,this.celestialLight.shadow.camera.bottom=-Ar,this.celestialLight.shadow.camera.near=pn-Ic,this.celestialLight.shadow.camera.far=pn+Ic,this.celestialLight.shadow.bias=-.03/(2*Ic),this.celestialLight.shadow.normalBias=UR,this.celestialLight.target=this.celestialLightTarget,this.lightningLight.color.copy(Ss),this.scene.add(this.celestialLight,this.celestialLightTarget,this.skyLight,this.lightningLight),this.scene.add(this.celestialGroup),this.scene.add(this.bodySystem.group),this.scene.add(this.roadSystem.group);const i=new se(this.renderer,()=>{this.skyColoursStale=!0,this.render()});i.supported?this.scatteredSky=i:i.dispose()}get currentTerrainAttribution(){return this.terrainAttribution}get currentRoadAttribution(){return this.roadAttribution}resize(t,e){this.cssSize.width=t,this.cssSize.height=e,this.renderer.setSize(t,e,!1),this.camera.aspect=t/Math.max(e,1),this.camera.updateProjectionMatrix(),this.render()}setCloudRendering(t){t!==this.cloudRendering&&(this.cloudTransmissionMemo.clear(),this.cloudRendering=t,this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.buildClouds(),this.buildCirrus(),this.render())}setCloudOffset(t,e={}){this.cloudOffsetM.set(t.x,0,t.z),this.cloudLayerOffsetsM=e,this.layeredClouds?.setOffsets(t,e),this.cloudFieldOffset.set(t.x*Tf,0,t.z*Tf);for(const i of[this.cloudUniforms,this.cirrusUniforms])i?.fieldOffset.value.copy(this.cloudFieldOffset);this.iceHalos?.setCloudOffset(this.layeredClouds?.cirrusMask?.offset??this.cloudFieldOffset)}setObserverPose(t){const e=((t.rollDeg??0)+this.gaitOffset.rollDeg)*Ei,i=(t.pitchDeg+this.lookPitchDeg+this.gaitOffset.pitchDeg)*Ei;if(t.headingDeg!==void 0?this.camera.rotation.set(i,-(t.headingDeg+this.lookYawDeg+this.gaitOffset.yawDeg)*Ei,e,"YXZ"):this.camera.rotation.set(i,this.camera.rotation.y,e,"YXZ"),t.elevationM!==this.observerElevationM&&(this.observerElevationM=t.elevationM,this.syncCloudLayer(),Math.abs(bv(t.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/Bc),this.camera.far=Math.max(Ah*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.terrainMesh&&this.terrainOrigin&&t.lat!==void 0&&t.lng!==void 0){const n=si(this.terrainOrigin.lat,this.terrainOrigin.lng,t.lat,t.lng);this.terrainMesh.position.x=n.x,this.terrainMesh.position.z=n.z}this.poseElevationM=t.elevationM,this.poseCameraY=this.groundYUnder(0,0)+1.6+t.elevationM,this.camera.position.y=this.poseCameraY,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==t.fovDeg&&(this.camera.fov=t.fovDeg,this.camera.updateProjectionMatrix(),this.updateCompassScale())}setTerrainProviders(t){this.stopTerrainFade(),this.terrainProviders=t,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.roadSystem.clear(),this.roadAttribution=void 0,this.roadWays=void 0,this.applyGroundDepthWrite(),this.terrainBuildToken++}setTerrainOrigin(t,e,i){if(t===void 0||e===void 0)return;const n=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-n)<n*.1){const{x:c,z:l}=si(t,e,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(c*c+l*l)<ZR*(n/Bc))return}const s=this.terrainOrigin,r=this.terrainRadius;(!s||s.lat!==t||s.lng!==e)&&(this.roadSystem.clear(),this.roadAttribution=void 0),this.terrainOrigin={lat:t,lng:e},this.terrainRadius=n;const o=++this.terrainBuildToken;this.awaitArrival(F4(t,e,this.terrainProviders,n),le.TERRAIN_PATIENCE_MS).then(({mesh:c,attribution:l,originElevationM:h})=>{if(o!==this.terrainBuildToken)return;this.setSiteElevation(h??0);const u=this.terrainMesh,d=s?si(t,e,s.lat,s.lng):void 0;u&&d&&Math.hypot(d.x,d.z)<=r&&(c.position.y=u.position.y+this.groundYOfPatch(u,d.x,d.z)),u&&d&&Math.hypot(d.x,d.z)<=r?this.crossfadeTerrain(c,u):this.disposeMesh(this.terrainMesh),c.renderOrder=KR,this.terrainMesh=c,this.compileNextFrameOffThread(),this.terrainAttribution=l,this.scene.add(c),this.applyGroundDepthWrite(),this.decorCurrentPose&&(this.setObserverPose(this.decorCurrentPose),this.updateDecorAnchoring(this.decorReferencePose,this.decorCurrentPose,this.decorTime)),this.buildRoads(t,e,n),this.drapeStatedRoads(),this.drapeTraces(),this.render(),i?.()}).catch(c=>{console.warn("Terrain build failed, keeping the flat ground fallback:",c),i?.()})}static TERRAIN_CROSSFADE_MS=1200;fadingTerrain;crossfadeTerrain(t,e){this.stopTerrainFade();const i=t.material;i.opacity=0,i.polygonOffset=!0,i.polygonOffsetFactor=-1,i.polygonOffsetUnits=-4;const n=performance.now(),s=()=>{const r=Math.min(1,(performance.now()-n)/le.TERRAIN_CROSSFADE_MS);if(i.opacity=r*r*(3-2*r),this.render(),r<1&&this.fadingTerrain){this.fadingTerrain.frameId=requestAnimationFrame(s);return}i.polygonOffset=!1,i.opacity=1,this.fadingTerrain&&this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0,this.render()};this.fadingTerrain={mesh:e,frameId:requestAnimationFrame(s)}}stopTerrainFade(){if(!this.fadingTerrain)return;cancelAnimationFrame(this.fadingTerrain.frameId),this.disposeMesh(this.fadingTerrain.mesh),this.fadingTerrain=void 0;const t=this.terrainMesh?.material;t&&(t.opacity=1,t.polygonOffset=!1)}static ROADS_MAX_RADIUS_M=5e3;buildRoads(t,e,i){const n=this.terrainProviders.roads;if(!n||i>le.ROADS_MAX_RADIUS_M){this.roadSystem.clear(),this.roadAttribution=void 0;return}const s=this.roadWays;if(s&&s.lat===t&&s.lng===e&&s.radiusM===i){this.drapeRoads(s.ways,t,e,n.contemporary);return}this.awaitArrival(n.getRoads(K2(t,e,i)),le.ROADS_PATIENCE_MS).then(r=>{this.terrainOrigin?.lat!==t||this.terrainOrigin?.lng!==e||(this.roadWays={lat:t,lng:e,radiusM:i,ways:r},this.drapeRoads(r,t,e,n.contemporary))}).catch(r=>{console.warn("Roads unavailable, drawing none:",r)})}setStatedRoads(t){t!==this.statedRoads&&(this.statedRoads=t,this.drapeStatedRoads(),this.render())}drapeStatedRoads(){const t=this.terrainMesh;t&&(this.roadSystem.group.position.copy(t.position),this.roadSystem.setStated(this.statedRoads,(e,i)=>this.groundYOfPatch(t,e,i)))}setTraces(t,e=new Map){t===this.traces&&e===this.traceLabels||(this.traces=t,this.traceLabels=e,!(t.length===0&&!this.traceSystem)&&this.loadTraceSystem().then(()=>{this.drapeTraces(),this.render()}))}setTracesShown(t){t!==this.tracesShown&&(this.tracesShown=t,this.drapeTraces(),this.render())}loadTraceSystem(){return this.traceSystemLoading??=je(async()=>{const{TraceSystem:t}=await import("./TraceSystem-B-YEiVUL.js");return{TraceSystem:t}},[],import.meta.url).then(({TraceSystem:t})=>{const e=new t(bf);this.scene.add(e.group),this.traceSystem=e})}drapeTraces(){const t=this.traceSystem,e=this.terrainMesh,i=this.terrainOrigin;!t||!e||!i||(t.group.position.copy(e.position),t.set(this.tracesShown?this.traces:[],this.traceLabels,i.lat,i.lng,this.siteElevationM,(n,s)=>this.groundYOfPatch(e,n,s)))}drapeRoads(t,e,i,n){const s=this.terrainMesh;s&&(this.roadSystem.group.position.copy(s.position),this.roadSystem.set(t,e,i,(r,o)=>this.groundYOfPatch(s,r,o),n),this.roadAttribution=t.length>0?this.terrainProviders.roads?.attribution:void 0,this.compileNextFrameOffThread(),this.render())}setShowCompass(t){this.showCompass!==t&&(this.showCompass=t,this.disposeCompassLabels(),t&&this.buildCompassLabels(),this.render())}setCompassPoints(t){this.compassPoints!==t&&(this.compassPoints=t,this.showCompass&&(this.disposeCompassLabels(),this.buildCompassLabels(),this.render()))}compassPoints;applyLensFlareTint(t){if(!this.lensFlare)return;const e=JR*(this.sunArriving[1]/QR);this.lensFlare.uniforms.uColorGain.value.setRGB(e*t[0],e*t[1],e*t[2]),this.applyDazzleStrength()}applyDazzleStrength(){if(!this.lensFlare)return;const[t,e,i]=this.sunArriving,n=Math.max(e,1e-30);this.lensFlare.uniforms.uDazzleColour.value.setRGB(t/n,1,i/n),this.lensFlare.uniforms.uVeilStrength.value=Ki.K*e*this.sunUnhiddenFraction}sunArriving=[0,0,0];setCompassHovered(t){this.compassHovered!==t&&(this.compassHovered=t,this.updateCompassVisibility())}setCompassForced(t){this.compassForced!==t&&(this.compassForced=t,this.updateCompassVisibility())}updateCompassVisibility(){const t=this.compassHovered||this.compassForced;if(this.compassSprites.some(e=>e.visible!==t)){for(const e of this.compassSprites)e.visible=t;this.developingExposure?this.exposureInstantsDone>0&&this.presentExposure():this.render()}}setWeather(t){if(OR(this.weather,t))return;this.cloudTransmissionMemo.clear();const e=this.weather;this.weather=t;const i=!lD(e,t),n=e.precipitationType!==t.precipitationType,s=e.precipitationIntensity!==t.precipitationIntensity||e.precipitationAmount!==t.precipitationAmount;(e.relativeHumidity!==t.relativeHumidity||n||s)&&(this.air=Wn.of(t),this.applyAir(),this.scatteredSky?.setConditions({aerosolOpticalDepth:t.relativeHumidity===void 0?void 0:Br.steppedOpticalDepth(t.relativeHumidity)}),this.pumpScatteredSky()),i&&(this.buildClouds(),this.buildCirrus()),n?this.buildPrecipitation():s&&this.updatePrecipitationDensity(),this.lastAstronomy&&(i&&(this.buildIceHalos(this.lastAstronomy.sun,this.lastAstronomy.moon),this.buildLunarDiffraction(this.lastAstronomy.moon)),(i||n||s)&&this.buildRainbow(this.lastAstronomy.sun,this.lastAstronomy.moon)),this.lightningArmed=t.storm&&t.cloudDarkness>=mD,this.syncAnimationLoop(),this.render()}setDecor(t){if(this.decorObjects!==t){this.decorObjects=t,this.decorModelToken++,this.decorModelCredits.clear(),this.pendingTrafficModels.clear();for(const e of this.decorGroups.values())e.removeFromParent(),Ye.dispose(e);this.decorGroups.clear(),this.streetlightLights.clear();for(const e of t){const i=Ye.build(e,e.lit??!1);this.scene.add(i),this.decorGroups.set(e.id,i),e.kind==="streetlight"&&this.addStreetlightLight(e.id,i),e.model&&e.id.startsWith(Xn.ID_PREFIX)?(this.pendingTrafficModels.set(e.id,e),this.awaitArrival(this.loadDecorModel(e,this.decorModelToken,!0))):this.reuseLoadedDecorModel(e,i)||this.awaitArrival(this.loadDecorModel(e,this.decorModelToken))}this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}}setDecorSunlight(t){this.decorSunlight=t}setContrails(t){t!==this.contrails&&(this.contrails=t,!(t.length===0&&!this.contrailSystem)&&this.loadContrailSystem().then(()=>{this.contrailSystem?.set(this.contrails),this.updateContrails(),this.render()}))}setContrailSunlight(t){this.contrailSunlight=t}loadContrailSystem(){return this.contrailSystemLoading??=je(async()=>{const{ContrailSystem:t}=await import("./ContrailSystem-CkzapJ6C.js");return{ContrailSystem:t}},__vite__mapDeps([0,1]),import.meta.url).then(({ContrailSystem:t})=>{const e=new t;this.scene.add(e.group),this.contrailSystem=e})}contrailTint(t){const e=this.contrailSunlight.get(t),i=this.lastAstronomy?.sun,n=le.CONTRAIL_SCATTERING,s=this.skyLight.color,r=[s.r*n*.5,s.g*n*.5,s.b*n*.5];if(e&&i){const o=Pn.litFraction(e.sunElevationDeg,e.heightM);if(o>0){const c=this.air.transmittanceFromSpace(e.heightM,e.sunElevationDeg),l=ye.illuminanceOf(i.magnitude)*this.relativeScale;for(let h=0;h<3;h++)r[h]+=n*l*c[h]*o}}return r}static CONTRAIL_SCATTERING=1/(4*Math.PI);updateContrails(){this.contrailSystem?.update(this.decorTime,{origin:this.bodyOrigin,eye:this.camera.position,pixelRad:this.contrailPixelRad()},t=>this.contrailTint(t))}contrailPixelRad(){const t=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.lampBloomRadiusRad()??0,this.camera.fov*Math.PI/180/t)}setDecorPresence(t){this.decorPresence=t}setDecorModelProvider(t){this.decorModelProvider=t;const e=this.decorObjects;this.decorObjects=[],this.setDecor(e)}get currentDecorModelCredits(){return[...this.decorModelCredits.values(),...this.bodySystem.modelCredits]}get bodyGround(){const{x:t,z:e}=this.bodyOrigin,i=this.groundYUnder(t,e);return{heightAt:(n,s)=>this.groundYUnder(t+n,e-s)-i}}setBodies(t,e=0,i=t.map(r=>r.id),n=[],s){const{x:r,z:o}=this.bodyOrigin,c=this.scatteredSky;this.bodySystem.set(t,{originX:r,originZ:o,originGroundY:this.groundYUnder(r,o),eye:this.camera.position,groundYAt:(h,u)=>this.groundYUnder(h,u),wind:s,light:this.plumeLight(),occluders:[...this.decorGroups.values()],transmittance:(h,u,d)=>this.transmittanceTo(h,u,d)},e,c?(h,u)=>c.relativeOfLuminance(h,u):void 0,i),this.bodySystem.setSmoke(n,e),this.bodySystem.any&&(this.celestialLight.castShadow=!0),this.fitShadowToBodies();const l=this.bodySystem.furthestFrom(this.camera.position)*1.2;l>this.camera.far&&(this.camera.far=l,this.camera.updateProjectionMatrix())}plumeLight(){const t=this.celestialLight.color,e=this.celestialLight.intensity*.5,i=this.skyLight.color,n=this.skyLight.groundColor,s=this.skyLight.intensity,r=(o,c,l)=>(o*e+(c+l)/2*s)/Math.PI;return[r(t.r,i.r,n.r),r(t.g,i.g,n.g),r(t.b,i.b,n.b)]}bodyOutline(t,e){return this.bodySystem.outlineOf(t,e)}documentUrl;modelUrl(t){return t.url?this.documentRelative(t.url):void 0}documentRelative(t){if(t.startsWith("data:"))return t;const e=this.documentUrl??(typeof location>"u"?void 0:location.href);return e?new URL(t,e).href:t}async loadBodyModel(t){const e=t.url?void 0:t.id?await this.decorModelProvider.entry(t.id):void 0,i=this.modelUrl(t)??e?.url,n=t.credit??e?.credit;if(!(!i||!n))return{scene:await yf(i),credit:n,headingOffsetDeg:t.headingOffsetDeg??e?.headingOffsetDeg}}loadedDecorModels=new Map;reuseLoadedDecorModel(t,e){const i=this.loadedDecorModels.get(t.id);return!i||i.ref!==JSON.stringify(qf(t))||!Ye.usesModel(t)?!1:(this.applyLoadedDecorModel(t,e,i),!0)}applyLoadedDecorModel(t,e,i){const n=i.scene.clone(!0);n.traverse(s=>{s instanceof At&&(s.userData.sharedModel=!0)}),Ye.applyModel(e,t,n,{headingOffsetDeg:i.headingOffsetDeg,depictedSizeM:i.depictedSizeM}),this.decorModelCredits.set(t.id,i.credit)}standInScenes=new Map;async loadDecorModel(t,e,i=!1){const n=i?gM[t.kind]:qf(t);if(!(!n||!Ye.usesModel(t)))try{const s=n.url?void 0:n.id?await this.decorModelProvider.entry(n.id):void 0,r=this.modelUrl(n)??s?.url,o=n.credit??s?.credit;if(!r||!o)return;const c=i?await this.standInScene(r):await yf(r);if(e!==this.decorModelToken||i&&!this.pendingTrafficModels.has(t.id))return;const l=this.decorGroups.get(t.id);if(!l)return;i||Mn.reflectOn(c);const h={ref:JSON.stringify(n),scene:c,headingOffsetDeg:n.headingOffsetDeg??s?.headingOffsetDeg,depictedSizeM:s?.sizeM,credit:o};i||this.loadedDecorModels.set(t.id,h),this.applyLoadedDecorModel(t,l,h),this.render()}catch(s){console.warn(`Keeping the built-in shape for decor "${t.id}":`,s)}}standInScene(t){let e=this.standInScenes.get(t);return e||(e=yf(t).then(i=>(Mn.reflectOn(i),i)),this.standInScenes.set(t,e)),e}updateDecorAnchoring(t,e,i=0){this.decorReferencePose=t,this.decorCurrentPose=e,this.decorTime=i;const n=t?.lat!==void 0&&t.lng!==void 0&&e?.lat!==void 0&&e?.lng!==void 0?si(t.lat,t.lng,e.lat,e.lng):{x:0,z:0},s=this.decorObjects.find(u=>u.observerSide!==void 0&&mM(u.kind));if(this.terrainMesh&&this.terrainOrigin&&e?.lat!==void 0&&e.lng!==void 0){const u=si(this.terrainOrigin.lat,this.terrainOrigin.lng,e.lat,e.lng);this.terrainMesh.position.x=u.x-(s?0:this.gaitOffset.eastM),this.terrainMesh.position.z=u.z+(s?0:this.gaitOffset.northM),this.roadSystem.group.position.copy(this.terrainMesh.position),this.traceSystem?.group.position.copy(this.terrainMesh.position)}s||(n.x-=this.gaitOffset.eastM,n.z+=this.gaitOffset.northM,this.camera.position.y=this.poseCameraY+this.gaitOffset.upM,this.celestialGroup.position.y=this.camera.position.y);const r={x:0,z:0};let o=0,c;if(s){const u=Hr(s,i),d=Ye.occupantView(s,u.headingDeg),f=-(u.headingDeg??0)*Ei,p=d.x*Math.cos(f)+d.z*Math.sin(f),v=-d.x*Math.sin(f)+d.z*Math.cos(f),m=u.eastM+n.x,g=-u.northM+n.z;r.x=-(m+p),r.z=-(g+v),this.camera.position.y=this.groundYUnder(m,g)+d.eyeY,c=d.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*Ei,-(d.headingDeg+this.indoorLookYawDeg)*Ei,0,"YXZ")}this.bodyOrigin={x:n.x+r.x,z:n.z+r.z},this.placeShadowFrustum(),this.placeTerraces(i,n,r);const l=this.terraces.map(u=>[u.x,u.z,u.cos,u.sin,u.halfWidthM,u.halfLengthM,u.levelY].map(d=>d.toFixed(3)).join(",")).join(";");!s&&this.terraces.length>0&&(this.poseCameraY=this.groundYUnder(0,0)+1.6+this.poseElevationM,this.camera.position.y=this.poseCameraY+this.gaitOffset.upM,this.celestialGroup.position.y=this.camera.position.y);for(const u of this.decorObjects){if(u.kind==="terrace")continue;const d=this.decorGroups.get(u.id);if(!d)continue;const f=Hr(u,i),p=f.eastM+n.x+r.x,v=-f.northM+n.z+r.z,m=this.terrainMesh,g=`${m?.geometry.uuid}:${(p-(m?.position.x??0)).toFixed(3)}:${(v-(m?.position.z??0)).toFixed(3)}:${(m?.position.y??0).toFixed(3)}:${f.headingDeg}:${f.altitudeM}:${l}`;if(d.userData.footprintKey!==g&&(d.userData.footprintGroundY=this.groundUnderFootprint(u,p,v,f.headingDeg,f.altitudeM),d.userData.footprintKey=g),d.position.set(p,d.userData.footprintGroundY+f.altitudeM,v),u.kind==="crop"){const x=Math.hypot(p,v);d.visible=x<=eD}const b=this.decorPresence.get(u.id),S=b!==void 0&&(i<b.fromMs||i>b.untilMs);b&&(d.visible=!S);const M=this.decorSunlight.get(u.id);if(M&&!S&&this.lightFromAbove(d,M),f.headingDeg!==void 0&&(d.rotation.y=-f.headingDeg*Ei),u.kind==="crop"&&d.visible){const x=this.terrainMesh,_=[x?.geometry.uuid,p-(x?.position.x??0),v-(x?.position.z??0),d.position.y-(x?.position.y??0),f.headingDeg,f.altitudeM].map(E=>typeof E=="number"?E.toFixed(4):E).join(":");d.userData.cropGroundKey!==_&&(Ye.fitCropToGround(d,(E,y)=>this.groundYUnder(E,y)+f.altitudeM),d.userData.cropGroundKey=_)}if(!S){const x=d.position.distanceTo(this.camera.position);o=Math.max(o,x),x<le.trafficModelRangeM(u)&&this.pendingTrafficModels.delete(u.id)&&this.loadDecorModel(u,this.decorModelToken)}}if(s&&c!==void 0){const u=this.decorGroups.get(s.id);u&&(this.camera.position.y=u.position.y+c)}this.updateContrails();const h=Math.max(Ah*1.2,this.groundRadius*2.5,o*1.2);Math.abs(this.camera.far-h)>1&&(this.camera.far=h,this.camera.updateProjectionMatrix())}groundYUnder(t,e){const i=this.terrainYUnder(t,e);let n=i;for(const s of this.terraces){const r=t-s.x,o=e-s.z,c=r*s.cos-o*s.sin,l=r*s.sin+o*s.cos;if(Math.abs(c)<=s.halfWidthM&&Math.abs(l)<=s.halfLengthM){const h=Math.min(1,Math.max(0,(s.halfWidthM-Math.abs(c))/s.bankM)),u=h*h*(3-2*h);n=Math.max(n,u*s.levelY+(1-u)*Math.min(s.levelY,i))}}return n}placeTerraces(t,e,i){this.terraces=[];const n=this.terrainMesh;for(const s of this.decorObjects){if(s.kind!=="terrace")continue;const r=this.decorGroups.get(s.id);if(!r)continue;const o=Hr(s,t),c=o.eastM+e.x+i.x,l=-o.northM+e.z+i.z,h=Ye.sizeOf(s),u=-(o.headingDeg??0)*Ei,d=Math.cos(u),f=Math.sin(u),p=`${n?.geometry.uuid}:${(c-(n?.position.x??0)).toFixed(3)}:${(l-(n?.position.z??0)).toFixed(3)}:${(n?.position.y??0).toFixed(3)}:${o.headingDeg}:${h.widthM}:${h.lengthM}:${h.heightM}`;r.position.set(c,0,l),o.headingDeg!==void 0&&(r.rotation.y=u),r.userData.terraceKey!==p&&(r.userData.terraceLevelY=Ye.fitTerrace(r,s,(v,m)=>this.terrainYUnder(c+v*d+m*f,l-v*f+m*d)),r.userData.terraceKey=p),this.terraces.push({x:c,z:l,cos:d,sin:f,halfWidthM:h.widthM/2,halfLengthM:h.lengthM/2,levelY:r.userData.terraceLevelY,bankM:Math.min(10,h.widthM/4)})}}terrainYUnder(t,e){const i=this.terrainMesh;return i?i.position.y+this.groundYOfPatch(i,t-i.position.x,e-i.position.z):Cf}groundYOfPatch(t,e,i){const n=t.geometry.getAttribute("position"),s=Math.round(Math.sqrt(n.count));if(s<2||s*s!==n.count)return Cf;const r=n.getX(0),o=n.getX(s-1),c=n.getZ(0),l=n.getZ((s-1)*s),h=ir((e-r)/(o-r)*(s-1),0,s-1),u=ir((i-c)/(l-c)*(s-1),0,s-1);if(!Number.isFinite(h)||!Number.isFinite(u))return Cf;const d=Math.min(Math.floor(h),s-2),f=Math.min(Math.floor(u),s-2),p=h-d,v=u-f,m=(x,_)=>n.getY(x*s+_),g=m(f,d),b=m(f,d+1),S=m(f+1,d),M=m(f+1,d+1);return p+v<=1?g+(b-g)*p+(S-g)*v:M+(S-M)*(1-p)+(b-M)*(1-v)}groundUnderFootprint(t,e,i,n,s=0){return Ye.groundUnderFootprint(t,e,i,n,(r,o)=>this.groundYUnder(r,o),s)}lookYawDeg=0;lookPitchDeg=0;poseCameraY=1.6;poseElevationM=0;setGait(t){this.gaitOffset=t}gaitOffset={eastM:0,northM:0,upM:0,rollDeg:0,pitchDeg:0,yawDeg:0};setLookOffset(t,e){this.lookYawDeg=t,this.lookPitchDeg=e}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(t,e){this.indoorLookYawDeg=t,this.indoorLookPitchDeg=e}medium;setMedium(t,e,i,n){const s=t&&e!==void 0&&e>0&&i!==void 0&&i>0?{kind:t.kind,iso:n??t.iso,autoExposure:t.autoExposure===!0,exposureSeconds:e,fNumber:i}:void 0;JSON.stringify(s)!==JSON.stringify(this.medium)&&(this.medium=s,this.render())}applyMedium(){const t=this.medium,e=Math.max(this.relativeScale,1e-30);if(!t){ln.uMedium.value=0;return}ln.uMedium.value=t.kind==="negative"?1:t.kind==="slide"?2:3;const i=t.autoExposure?this.scatteredSky?.sceneAdaptation:void 0;ln.uMediumExposure.value=i!==void 0&&i>0?1/(e*i):.065*t.exposureSeconds*t.iso*this.filterTransmittance/(t.fNumber*t.fNumber*e)}grain;lampBloomRadiusRad(){if(!this.grain)return;const t=this.camera.fov*Math.PI/180,e=this.grain.frameHeightMm/(2*Math.tan(t/2)),i=Math.max(1,this.renderer.getDrawingBufferSize(this.bloomSize).y);return Math.max(this.grain.detailUm*.001/e,t/i)}bloomSize=new bt;lampTransmittance(t){const e=this.siteElevationM+this.camera.position.y,i=this.siteElevationM+t.position.y;return this.air.transmittance(e,i,t.position.distanceTo(this.camera.position))}updateDecorLitState(t,e=0){const i=this.lampBloomRadiusRad();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);if(s&&n.lights?.length&&Ye.setLights(s,n.lights,t,s.position.distanceTo(this.camera.position),e,this.relativeScale,i,this.lampTransmittance(s)),n.kind!=="streetlight"&&n.kind!=="vehicle")continue;const r=this.decorGroups.get(n.id);if(!r)continue;const o=vM(n,t);Ye.setLit(r,n.kind,o,this.relativeScale);const c=this.streetlightLights.get(n.id);c&&(c.visible=o)}}addStreetlightLight(t,e){const i=Ye.bodyOf(e),n=i.children.find(r=>r.userData.emissive);if(!n)return;const s=new u2(16764006,_v*this.relativeScale,WR);s.position.copy(n.position).multiply(i.scale),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,e.add(s),this.streetlightLights.set(t,s)}setAstronomy(t){(!this.lastAstronomy||Math.abs(this.lastAstronomy.sun.altitudeDeg-t.sun.altitudeDeg)>2)&&(this.surroundings=void 0,this.scatteredSky?.resetSurroundings()),this.lastAstronomy=t,this.scatteredSky?.update(this.scatteredSkyState(t)),this.skyHoldUntilMs===void 0&&this.startHold(),this.pumpScatteredSky(),this.lastSunPosition=t.sun,this.buildSky(t.sun),this.buildGround();const e=this.magnitudeLimitOf(t);this.buildStars(t.stars,e),this.placeBodies(t,e),this.buildIceHalos(t.sun,t.moon),this.buildRainbow(t.sun,t.moon),this.applySkyColours(t),this.syncAnimationLoop(),this.render()}static relativeSkyOf(t,e){const i=r=>{const o=us.luminanceOf(r);if(!(o>0))return[0,0,0];const c=Rt.relativeOfResponse(o)/o;return[r[0]*c,r[1]*c,r[2]*c]},n=i(t.zenith),s=i(t.horizon);return{zenith:n,horizon:s,airlight:s,skyIrradiance:[n[0]*Math.PI,n[1]*Math.PI,n[2]*Math.PI],scale:e}}placeBodies(t,e){this.bodiesScale=this.relativeScale,this.sunBeamFraction=Mi.beamFraction(t.eclipse),this.setBodyMesh("sun",t.sun,Sv,new st(1,.96,.88),t.sun.magnitude),this.placeEclipse(t),this.setMoonMesh(t.moon,e),this.buildPlanets(t.planets,e),this.buildComet(t.comet,e),this.buildNovae(t.novae??[],e)}placeEclipse(t){const e=t.eclipse;if(!e||t.sun.altitudeDeg<Jh){this.eclipsedSun.setMoon(void 0),this.eclipseDiscs=void 0,this.solarCorona?.show(void 0,[0,0,0]);return}const i=Sv/pn*(180/Math.PI),n=i/e.sunRadiusDeg,s=Xe(t.sun.altitudeDeg,t.sun.azimuthDeg,1),r=Xe(t.moon.altitudeDeg,t.moon.azimuthDeg,1),o=Math.acos(ir(s.x*r.x+s.y*r.y+s.z*r.z,-1,1)),c=o>1e-9?ir(e.separationDeg*n*Ei/o,0,2):0,l=Math.sin(o),[h,u]=o>1e-9?[Math.sin((1-c)*o)/l,Math.sin(c*o)/l]:[1,0],d={x:s.x*h+r.x*u,y:s.y*h+r.y*u,z:s.z*h+r.z*u},f=e.moonRadiusDeg*n;this.eclipseDiscs={sun:new R(s.x,s.y,s.z).normalize(),moon:new R(d.x,d.y,d.z).normalize(),sunRadiusRad:i*Ei,moonRadiusRad:f*Ei};const p=.01,v=(b,S)=>Xe(t.sun.altitudeDeg+b,t.sun.azimuthDeg+S,1),m={x:v(p,0).x-v(-p,0).x,y:v(p,0).y-v(-p,0).y,z:v(p,0).z-v(-p,0).z},g={x:v(0,p).x-v(0,-p).x,y:v(0,p).y-v(0,-p).y,z:v(0,p).z-v(0,-p).z};if(this.eclipsedSun.setMoon(d,f,e.limb?{profile:e.limb,scale:n,up:m,right:g}:void 0),e.obscuration<.9){this.solarCorona?.show(void 0,[0,0,0]);return}this.solarCorona||(this.solarCorona=new ko(i*Math.PI/180,this.eclipsedSun.cut),this.celestialGroup.add(this.solarCorona.object)),this.solarCorona.show(s,this.sunDiscRadiance)}bodiesScale=0;applySkyColours(t){this.skyColoursStale=!1,this.bodiesScale!==this.relativeScale&&(this.placeBodies(t,this.magnitudeLimitOf(t)),this.applyDazzleStrength(),this.buildIceHalos(t.sun,t.moon),this.buildRainbow(t.sun,t.moon));const e=this.scatteredSky?.ambient??le.relativeSkyOf(K0(t.sun.altitudeDeg),this.relativeScale),i=e,n=this.lightUnderClouds(t),s=r=>n?[0,1,2].map(o=>r[o]*n.through+n.radiance[o]*(1-n.through)):[r[0],r[1],r[2]];this.baseFogColor=[i.horizon[0],i.horizon[1],i.horizon[2]],this.airlight=s(i.airlight),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.scatteredSky?.ready?this.scatteredSky.material:this.skyGradientMaterial),this.updateCelestialLight(t,e),this.updateCloudLighting(t.sun,this.baseFogColor),Ct.setEye(this.scatteredSky?.rodShare??0,this.relativeScale),this.updateTwinkle(this.twinkleSeconds);for(const r of this.streetlightLights.values())r.intensity=_v*this.relativeScale;this.buildSkyGlow(t,i.zenith),this.applyAir(),this.buildLunarDiffraction(t.moon)}reflections;sceneVersion=0;reflectionTimer;buildLunarDiffraction(t){const e=this.scatteredSky?.ready?this.scatteredSky:void 0;if(t.altitudeDeg<-.5||!e){this.lunarDiffraction?.show(void 0),this.lunarDiffractionKey="";return}const i=this.weather.relativeHumidity,n=(i===void 0?zt.DEFAULT_AEROSOL_OPTICAL_DEPTH:Br.opticalDepth(i))*zt.aerosolDensity(this.siteElevationM+this.observerElevationM),s=this.cloudTransmission(t),r=-Math.log(Math.max(this.cloudTransmission(t,!0),1e-4)),o=ye.aureoleScale(n,ye.airMass(t.altitudeDeg))*s,c=ye.coronaScale(r),l=ye.illuminanceOf(t.magnitude),h=[t.altitudeDeg.toFixed(1),t.azimuthDeg.toFixed(1),t.magnitude.toFixed(2),o.toExponential(2),c.toExponential(2),Math.log10(Math.max(e.adaptation,1e-12)).toFixed(2)].join(":");if(h===this.lunarDiffractionKey)return;this.lunarDiffractionKey=h,this.lunarDiffraction||(this.lunarDiffraction=new fm,this.celestialGroup.add(this.lunarDiffraction.object));const u=ye.profile(ye.HAZE_COARSE_MODE),d=ye.profile(ye.CLOUD_DROPLETS),f=G1(t.altitudeDeg),p=new Float32Array(ye.STEPS*3);let v=0;for(let S=0;S<ye.STEPS;S++){const M=S*3,x=[0,1,2].map(E=>l*f[E]*(o*u[M+E]+c*d[M+E])),_=us.shown(x,us.luminanceOf(x),(E,y)=>e.relativeOfLuminance(E,y));p.set(_,M),v=Math.max(v,us.response(_))}const{x:m,y:g,z:b}=Xe(t.altitudeDeg,t.azimuthDeg,1);this.lunarDiffraction.show(v>1/200?{x:m,y:g,z:b}:void 0,p)}applyAir(){this.scene.fog instanceof Fa||(this.scene.fog=new Fa),this.scene.fog.setAir(this.air,this.siteElevationM,this.airlight)}airlight=[0,0,0];transmittanceTo(t,e,i){const n=this.camera.position;return this.air.transmittance(this.siteElevationM+n.y,this.siteElevationM+e,Math.hypot(t-n.x,e-n.y,i-n.z))}setSiteElevation(t){Math.abs(t-this.siteElevationM)<1||(this.siteElevationM=t,this.applyAir(),this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}umbraTint(){const t=this.siteElevationM+this.observerElevationM+1.6,[e,i,n]=this.air.transmittance(t,t,le.UMBRA_PATH_M),s=.2126*e+.7152*i+.0722*n;return s>0?[(.4124*e+.3576*i+.1805*n)/s,1,(.0193*e+.1192*i+.9505*n)/s]:[.9505,1,1.089]}static UMBRA_PATH_M=8e4;umbraOf(t){const e=t.eclipse?.horizonShare;return e&&Math.max(...e)<.1?{share:e,tint:this.umbraTint()}:void 0}scatteredSkyState(t){return{altitudeM:this.siteElevationM+this.observerElevationM+1.6,lightPollution:this.lightPollution,sun:{altitudeDeg:t.sun.altitudeDeg,azimuthDeg:t.sun.azimuthDeg,magnitude:t.sun.magnitude},sunLight:Mi.beamFraction(t.eclipse),zenithFloorCdM2:t.eclipse?Mi.UMBRA_ZENITH_CD_M2:void 0,umbra:this.umbraOf(t),moon:{altitudeDeg:t.moon.altitudeDeg,azimuthDeg:t.moon.azimuthDeg,magnitude:t.moon.magnitude,phaseAngleDeg:St.phaseAngleOf(t.moon.phase.illuminatedFraction)}}}pumpScatteredSky(){const t=this.scatteredSky;!t||t.tables.ready||this.scatteredSkyFrameId!==null||this.contextReleased||this.suspended||(this.scatteredSkyFrameId=requestAnimationFrame(()=>{this.scatteredSkyFrameId=null,!this.contextReleased&&(t.advance(this.skyHoldUntilMs?qR:YR),this.pumpScatteredSky())}))}cancelScatteredSkyPump(){this.scatteredSkyFrameId!==null&&(cancelAnimationFrame(this.scatteredSkyFrameId),this.scatteredSkyFrameId=null)}setSatellites(t){if(t.length===0&&!this.satelliteField?.count)return;this.satelliteField||(this.satelliteField=new tR(wf),this.celestialGroup.add(this.satelliteField.object));const e=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Kh(-90,this.instrumentMagnitudeGain);this.satelliteField.set(t,e,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}setReentries(t){if(t.length===0&&!this.reentrySystem?.count)return;this.reentrySystem||(this.reentrySystem=new mn,this.celestialGroup.add(this.reentrySystem.object));const e=this.lastAstronomy?this.magnitudeLimitOf(this.lastAstronomy):Kh(-90,this.instrumentMagnitudeGain);this.reentrySystem.set(t,e,i=>this.cloudTransmission(i),(i,n)=>this.arrivingIlluminance(i,n,1)),this.render()}get reentryCount(){return this.reentrySystem?.count??0}pickTrafficAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.direction,n=Math.cos(_f*this.camera.fov*Math.PI/180);let s,r=n;const o=new R;for(const[c,l]of this.decorGroups){if(!l.visible||!c.startsWith(Xn.ID_PREFIX))continue;o.copy(l.position).sub(this.camera.position).normalize();const h=o.dot(i);h>r&&(r=h,s=c)}return s&&!this.groundHides(t,e)?s:void 0}pickSatelliteAt(t,e){if(!this.satelliteField?.count)return;this.aimAtScreenPoint(this.raycaster,t,e);const i=Math.cos(_f*this.camera.fov*Math.PI/180),n=this.satelliteField.nearest(this.raycaster.ray.direction,i);return n&&this.groundHides(t,e)?void 0:n}updateCelestialLight(t,e){const i=this.relativeScale,n=t.sun.altitudeDeg>=Rh,s=!n&&t.moon.altitudeDeg>=Rh,r=n?t.sun:t.moon,o=[0,0,0],c=Math.max(0,Math.sin(Math.max(r.altitudeDeg,0)*Ei)),l=n||s?this.cloudTransmission(r):1,h=-Math.log(Math.max(l,1e-6)),u=Math.max(0,1/(1+.1125*h)-l),d=[0,0,0];if(n||s){const b=ye.illuminanceOf(r.magnitude)*i,S=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,r.altitudeDeg);for(let E=0;E<3;E++)o[E]=b*S[E]*l,d[E]=b*S[E]*u*c,this.cloudBeam[E]=b*S[E];const{x:M,y:x,z:_}=Xe(r.altitudeDeg,r.azimuthDeg,1);this.cloudBeamDirection.set(M,x,_)}else this.cloudBeam.fill(0);const f=this.surroundings;if(f)this.skyLight.color.setRGB(f.up[0]*i,f.up[1]*i,f.up[2]*i),this.skyLight.groundColor.setRGB(f.down[0]*i,f.down[1]*i,f.down[2]*i);else{const b=this.skyCloudTransmission(),S=e.skyIrradiance,M=[0,1,2].map(_=>S[_]*b+d[_]);this.skyLight.color.setRGB(M[0],M[1],M[2]);const x=Xt.GROUND_ALBEDO;this.skyLight.groundColor.setRGB(x*(M[0]+o[0]*c),x*(M[1]+o[1]*c),x*(M[2]+o[2]*c))}if(this.skyLight.intensity=1,this.sceneSunBeam=n?[o[0],o[1],o[2]]:[0,0,0],!n&&!s){this.celestialLight.intensity=0;return}const{x:p,y:v,z:m}=Xe(r.altitudeDeg,r.azimuthDeg,1);this.lightDirection.set(p,v,m),this.placeShadowFrustum();const g=Math.max(o[0],o[1],o[2],1e-30);this.celestialLight.color.setRGB(o[0]/g,o[1]/g,o[2]/g),this.celestialLight.intensity=g,this.celestialLight.castShadow=this.decorGroups.size>0||this.bodySystem.any}static MEAN_COSINE=.5;static ABOVE_CLOUD_M=8e3;lightFromAbove(t,e){const i=this.lastAstronomy?.sun,n=[0,0,0];if(i){const s=Pn.litFraction(e.sunElevationDeg,e.heightM);if(s>0){const r=this.air.transmittanceFromSpace(e.heightM,e.sunElevationDeg),o=ye.illuminanceOf(i.magnitude)*this.relativeScale,c=e.heightM>=le.ABOVE_CLOUD_M?1:this.cloudTransmission(i);for(let l=0;l<3;l++)n[l]=Math.max(0,o*r[l]*s*c-this.sceneSunBeam[l])}}t.traverse(s=>{const r=s.material;if(!(r instanceof nc||r instanceof Nr)||s.userData.emissive)return;r.map&&!r.emissiveMap&&(r.emissiveMap=r.map,r.needsUpdate=!0);const o=le.MEAN_COSINE/Math.PI;r.emissive.setRGB(r.color.r*n[0]*o,r.color.g*n[1]*o,r.color.b*n[2]*o)})}lightDirection=new R(0,1,0);placeShadowFrustum(){const t=this.lightDirection,e=this.celestialLight.shadow.camera,i=(e.right-e.left)/this.celestialLight.shadow.mapSize.x,n=this.shadowAxisX.crossVectors(this.shadowUp,t);n.lengthSq()<1e-8&&n.set(1,0,0),n.normalize();const s=this.shadowAxisY.crossVectors(t,n).normalize(),r=this.shadowWorld.set(this.bodyOrigin.x,0,this.bodyOrigin.z),o=l=>{const h=r.dot(l)/i;return(h-Math.round(h))*i},c=this.celestialLightTarget.position.set(0,0,0).addScaledVector(n,o(n)).addScaledVector(s,o(s));this.celestialLightTarget.updateMatrixWorld(),this.celestialLight.position.copy(c).addScaledVector(t,this.shadowLightDistanceM)}fitShadowToBodies(){const t=this.bodySystem.reachFrom(this.camera.position),e=Math.min(FR,Math.max(Ar,Math.ceil(t*1.25/20)*20));if(e===this.shadowHalfExtentM)return;this.shadowHalfExtentM=e;const i=this.celestialLight.shadow,n=i.camera;n.left=-e,n.right=e,n.top=e,n.bottom=-e;const s=Math.max(Ic,e*(Ic/Ar));this.shadowLightDistanceM=Math.max(pn,s+10),n.near=this.shadowLightDistanceM-s,n.far=this.shadowLightDistanceM+s,n.updateProjectionMatrix(),i.bias=-.03/(2*s);const r=e>2*Ar?2048:1024;i.mapSize.x!==r&&(i.mapSize.set(r,r),i.map?.dispose(),i.map=null),this.placeShadowFrustum()}shadowHalfExtentM=Ar;shadowLightDistanceM=pn;shadowUp=new R(0,1,0);shadowAxisX=new R;shadowAxisY=new R;shadowWorld=new R;skyCloudTransmission(){let t=this.cloudTransmission({altitudeDeg:90,azimuthDeg:0}),e=1;for(const i of[20,45,70]){const n=i*Ei,s=Math.sin(n)*Math.cos(n)*2;for(let r=0;r<360;r+=60)t+=s*this.cloudTransmission({altitudeDeg:i,azimuthDeg:r}),e+=s}return t/e}cloudBeam=[0,0,0];cloudBeamDirection=new R(0,1,0);get relativeScale(){return this.scatteredSky?.relativeScale??1/Rt.semiSaturation(Rt.DAYLIGHT_ANCHOR_CD_M2)}setMeteorShower(t,e,i){this.meteorSystem||(this.meteorSystem=new Fi,this.celestialGroup.add(this.meteorSystem.object)),this.meteorSystem.setShower(t,e,i)}get meteorSchedule(){return this.meteorSystem?.schedule??[]}meteorMidpoint(t){return this.meteorSystem?.midpointOf(t)}updateMeteors(t){this.meteorSystem?.update(t)}setInstrument(t){this.projectionKind=t.projection,this.grain=t.detailUm!==void 0&&t.frame?{detailUm:t.detailUm,frameHeightMm:t.frame.heightMm}:void 0;const e=bi.starPointsOf(t),i=bi.flareArtifactsOf(t);e===this.starPoints&&i===this.lensFlareArtifactIntensity||(this.starPoints=e,this.lensFlareArtifactIntensity=i,this.lensFlare&&(this.lensFlare.uniforms.uStarPoints.value=e,this.lensFlare.uniforms.uFlareIntensity.value=i),this.render())}magnitudeLimitOf(t){const e=St.starLossMagnitudes(t.sun.altitudeDeg,{phaseAngleDeg:St.phaseAngleOf(t.moon.phase.illuminatedFraction),altitudeDeg:t.moon.altitudeDeg},this.lightPollution);return Kh(t.sun.altitudeDeg,this.instrumentMagnitudeGain,e)}setLightPollution(t){t!==this.lightPollution&&(this.lightPollution=t,this.lastAstronomy&&this.scatteredSky?.update(this.scatteredSkyState(this.lastAstronomy)))}setInstrumentGain(t,e=!1,i=0){const n=Number.isFinite(t)?t:0;this.instrumentMagnitudeGain=n-2.5*i,this.filterTransmittance=10**-i,this.scatteredSky?.setInstrument(e,n,i)}filterTransmittance=1;render(){this.restatingExposure||(this.sceneVersion++,this.frameDirty=!0,this.resolution.noteChange(performance.now()),!this.suspended&&(this.syncAnimationLoop(),!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))))}drawIfDirty(){if(!(!this.frameDirty||this.contextReleased||this.suspended)){if(this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy),this.compileBeforeNextDraw){this.compileBeforeNextDraw=!1;const t=this.compileOffThread().then(()=>{this.compiling===t&&(this.compiling=void 0,this.render())});this.compiling=t;return}if(!this.compiling){if(this.skyHoldUntilMs){if(!this.sceneSettled()&&performance.now()<this.skyHoldUntilMs){this.firstFrameReady()&&this.arrivalsPending===0&&this.refreshReflections(!0);return}this.skyHoldUntilMs=null,this.skyGlow?.setWithheld(!1),this.iceHalos?.setUrgent(!1),this.onFirstFrameHold?.(!1),this.skyColoursStale&&this.lastAstronomy&&this.applySkyColours(this.lastAstronomy)}this.frameDirty=!1,this.refreshReflections(),this.resolution.beginDrawing();try{this.renderOnce(),this.drawn++}finally{this.resolution.endDrawing()}this.developingExposure&&this.startExposure()}}}drawn=0;get framesDrawn(){return this.drawn}compileBeforeNextDraw=!1;compiling;static COMPILE_WAIT_MS=1500;compileOffThread(){const t=this.renderer.compile(this.scene,this.camera);if(!this.renderer.extensions.get("KHR_parallel_shader_compile"))return Promise.resolve();const e=this.renderer.properties,i=performance.now()+le.COMPILE_WAIT_MS;return new Promise(n=>{const s=()=>{if(this.contextReleased)return n();for(const r of t){const o=e.get(r)?.currentProgram;(!o||o.isReady())&&t.delete(r)}t.size===0||performance.now()>i?n():setTimeout(s,10)};s()})}compileNextFrameOffThread(){this.compileBeforeNextDraw=!0}contextReleased=!1;releaseContext(){this.contextReleased||(this.contextReleased=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.compiling=void 0,this.cancelScatteredSkyPump(),this.renderer.forceContextLoss())}restoreContext(){this.contextReleased&&(this.contextReleased=!1,this.renderer.forceContextRestore(),this.scatteredSky?.invalidate(),this.pumpScatteredSky(),this.compileNextFrameOffThread(),this.syncAnimationLoop(),this.render())}suspended=!1;suspend(){this.suspended||(this.suspended=!0,this.stopTwinkle(),this.cancelFlush(),this.cancelExposure(),this.cancelScatteredSkyPump(),clearTimeout(this.reflectionTimer),this.reflectionTimer=void 0)}resume(){this.suspended&&(this.suspended=!1,this.pumpScatteredSky(),this.syncAnimationLoop(),this.render())}cancelFlush(){this.flushFrameId!==null&&(cancelAnimationFrame(this.flushFrameId),this.flushFrameId=null)}frame(t){if(this.animationsRunning){const e=this.lastFrameTimeMs===void 0?0:t-this.lastFrameTimeMs;this.lastFrameTimeMs=t,this.hasAnimations()&&this.animate(t,e);const i=this.resolution.ratioFor(t,e);i!==this.renderer.getPixelRatio()&&this.applyPixelRatio(i)}this.drawIfDirty()}refreshReflections(t=!1){this.reflections??=new Mn(this.renderer);const e=[...this.compassSprites,...this.lensFlare?[this.lensFlare.mesh]:[],...[...this.glareSprites.values()].map(o=>o.mesh)],i=[...this.starTiers.map(o=>o.points),...[...this.bodyMeshes.values()].filter(o=>o instanceof In),...[this.rainSystem?.points,this.precipitationPoints,this.rainSplashSystem?.points].filter(o=>o!==void 0)],n=this.relativeScale,s=this.sceneVersion,r=this.reflections.refresh(this.renderer,this.scene,this.camera.position,this.bodySystem.reflectors,e,[...this.decorGroups.values()],s,i,o=>this.measureSurroundings(o,n,s),t?0:Mn.REFRESH_MS);r===void 0||this.reflectionTimer||(this.reflectionTimer=setTimeout(()=>{this.reflectionTimer=void 0,this.frameDirty=!0,!(this.animationFrameId!==null||this.framesDriven||this.flushFrameId!==null)&&(this.flushFrameId=requestAnimationFrame(()=>{this.flushFrameId=null,this.drawIfDirty()}))},r))}measureSurroundings(t,e,i){const n=this.lastAstronomy;if(!n)return;this.probeIrradiance??=new Kc;const s=[n.sun,n.moon].filter(r=>r.altitudeDeg>-2).map(r=>Xe(r.altitudeDeg,r.azimuthDeg,1));this.probeIrradiance.measure(this.renderer,t,s,r=>{const o=f=>f.map(p=>p/e),c=this.surroundings,l={up:o(r.up),down:o(r.down)},h=(f,p)=>f.some((v,m)=>Math.abs(v-p[m])>.03*Math.max(Math.abs(v),Math.abs(p[m]),1e-12)),u=!c||h(c.up,l.up)||h(c.down,l.down);u&&(this.surroundings=l),this.eyeSettledVersion=-1;const d=this.scatteredSky?.adaptToSurroundings(Math.exp(r.logAverage)/e)??!1;if(!u&&!d){this.eyeSettledVersion=i,this.skyHoldUntilMs&&this.redrawHeld();return}this.skyColoursStale=!0,this.render()})}lightUnderClouds(t){const e=this.surroundings;if(!e)return;const i=t.sun.altitudeDeg>=Rh?t.sun:t.moon.altitudeDeg>=Rh?t.moon:void 0;if(!i)return;const n=this.relativeScale/Math.PI;return{through:this.cloudTransmission(i),radiance:[e.up[0]*n,e.up[1]*n,e.up[2]*n]}}probeIrradiance;surroundings;animate(t,e){const i=Math.min(e/1e3,pD);this.twinkleSeconds=t/1e3,this.updateTwinkle(this.twinkleSeconds),this.updatePrecipitation(t/1e3,i),this.updateRain(i),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=t/1e3),this.developingExposure||(this.frameDirty=!0)}setMaxPixelRatio(t){this.resolution.maximum=t,this.renderer.getPixelRatio()>this.resolution.maximum&&this.applyPixelRatio(this.resolution.maximum)}applyPixelRatio(t){this.renderer.setPixelRatio(t),this.renderer.setSize(this.cssSize.width,this.cssSize.height,!1),this.frameDirty=!0}setExposure(t,e){const i=e?Math.max(1,Math.round(t)):1;if(i===this.exposureInstants&&(i===1||e===this.exposureInstantAt)){this.exposureInstantAt=e;return}this.exposureInstants=i,this.exposureInstantAt=e,i===1&&(this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0),this.render()}renderOnce(t){if(this.onMapSubjectBounds){const r=this.mapSubjectBounds();t?this.exposureSubjectBounds.push(...r):this.onMapSubjectBounds(r)}const e=this.usableEquidistantPass();this.phenomena.setCloudLayers(this.layeredClouds?.volumes??[]),this.phenomena.place(this.camera,(r,o,c)=>this.directionAtScreenPoint(r,o,c),r=>this.screenPointOf(r)),this.references.place(this.camera);const i=Math.max(this.phenomena.furthestM,this.references.furthestM)*1.2;i>this.camera.far&&(this.camera.far=i,this.camera.updateProjectionMatrix()),ln.uRodShare.value=this.scatteredSky?.rodShare??0,ln.uRelativeScale.value=this.relativeScale,this.applyMedium();const n=this.references.any||this.phenomena.any||this.compassSprites.some(r=>r.visible);ln.uHasOverlay.value=n?1:0;const s=n?r=>this.renderOverlayPasses(r):void 0;if(this.skyGlow?.setDestinationEncoded(!1),!e){this.updateLensFlarePosition();const r=this.usableDepthOfFieldPass();r?r.render(this.renderer,this.scene,this.camera,s,t):this.usableFinishPass().render(this.renderer,this.scene,this.camera,s,void 0,t);return}e.render(this.renderer,this.scene,this.camera,this.camera.fov,()=>this.updateLensFlarePosition(),s,r=>{this.lensFlare&&(this.lensFlare.mesh.visible=r?!1:this.sunVisible)},()=>this.renderDazzleOnResample(),t,this.pointLayerHost)}pointLayerHost={points:()=>{const t=[];return this.celestialGroup.traverse(e=>{(e instanceof In&&e.userData.pointSource||e instanceof At&&e.userData.skyRibbon)&&t.push(e)}),t},clouds:()=>[...this.layeredClouds?.meshes??[],...this.cloudMesh?[this.cloudMesh]:[],...this.cirrusMesh?[this.cirrusMesh]:[]],sky:this.celestialGroup};renderOverlayPasses(t=this.camera){this.renderReferencesPass(t),this.renderBodiesOverReferences(t),this.renderPhenomenaPass(t),this.renderHudPass(t)}renderHudPass(t){const e=this.traceSystem?.any&&this.tracesShown;if(!e&&!this.compassSprites.some(s=>s.visible))return;e&&this.traceSystem.setView(this.renderer.getDrawingBufferSize(this.traceResolution),t.fov);const i=this.renderer.autoClear,n=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(bf),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=i,this.renderer.shadowMap.autoUpdate=n}renderBodiesOverReferences(t){if(!this.references.any||!this.bodySystem.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(ry),this.scene.overrideMaterial=this.bodyCutOutMaterial,this.renderer.render(this.scene,t),this.scene.overrideMaterial=null,t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}bodyCutOutMaterial=new wn({blending:xl,blendSrc:Nc,blendDst:Nc,blendSrcAlpha:Nc,blendDstAlpha:Nc,toneMapped:!1});renderReferencesPass(t){if(!this.references.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,t.layers.set(oy),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}setReferences(t,e){this.references.set(t.map(i=>{const n=this.documentRelative(i.src);return n===i.src?i:{...i,src:n}}),void 0,e)}referenceAspect(t){return this.references.aspectOf(t)}directionAt(t,e){return this.directionAtScreenPoint(t,e,new R)}referenceFailedToLoad(t){return this.references.failedToLoad(this.documentRelative(t))}setReferencesShown(t){this.references.setShown(t),this.render()}setReferenceView(t,e){this.references.setView(t,e),this.render()}renderPhenomenaPass(t){if(!this.phenomena.any)return;const e=this.renderer.autoClear,i=this.renderer.shadowMap.autoUpdate;this.renderer.autoClear=!1,this.renderer.shadowMap.autoUpdate=!1,this.renderer.clearDepth();for(const n of this.decorObjects){const s=this.decorGroups.get(n.id);s&&le.markDecorDepth(s,n.kind!=="crop")}t.layers.set(xf),this.scene.overrideMaterial=this.decorDepthMaterial,this.renderer.render(this.scene,t),this.scene.overrideMaterial=null,t.layers.set(ay),this.renderer.render(this.scene,t),t.layers.set(0),this.renderer.autoClear=e,this.renderer.shadowMap.autoUpdate=i}decorDepthMaterial=new wn({colorWrite:!1});static markDecorDepth(t,e){t.traverse(i=>{if(!(i instanceof At))return;const n=Array.isArray(i.material)?i.material[0]:i.material;e&&n.depthWrite!==!1&&n.blending!==Ti?i.layers.enable(xf):i.layers.disable(xf)})}startExposure(){this.cancelExposure(),this.exposureSubjectBounds=[];const t=this.renderer.getDrawingBufferSize(new bt),e=Math.max(1,Math.round(t.x)),i=Math.max(1,Math.round(t.y));this.exposureAccumulation||(this.exposureAccumulation=new JA(e,i)),this.exposureAccumulation.resize(e,i),this.exposureAccumulation.open(this.renderer),this.exposureInstantsDone=0,this.exposureFrameId=requestAnimationFrame(()=>this.developExposure())}developExposure(){this.exposureFrameId=null;const t=this.exposureInstantAt,e=this.exposureAccumulation;if(!t||!e)return;const i=1/this.exposureInstants;this.resolution.beginDrawing();const n=performance.now()+le.EXPOSURE_BUDGET_MS,s=le.exposureInstantsPerFrame(e.instantTarget.scene.width*e.instantTarget.scene.height);let r=0;do{this.restateAt(t,this.exposureInstantsDone);const o=this.compassSprites.map(c=>c.visible);for(const c of this.compassSprites)c.visible=!1;try{this.renderOnce(e.instantTarget)}finally{this.compassSprites.forEach((c,l)=>{c.visible=o[l]})}e.add(this.renderer,i),this.exposureInstantsDone++,r++}while(this.exposureInstantsDone<this.exposureInstants&&performance.now()<n&&r<s);this.restateAt(t,0),this.presentExposure(),this.resolution.endDrawing(),this.exposureInstantsDone<this.exposureInstants&&(this.exposureFrameId=requestAnimationFrame(()=>this.developExposure()))}presentExposure(){if(ln.uRodShare.value=this.scatteredSky?.rodShare??0,ln.uHasOverlay.value=1,ln.uRelativeScale.value=this.relativeScale,this.applyMedium(),this.exposureAccumulation?.develop(this.renderer,this.exposureInstants/this.exposureInstantsDone),this.onMapSubjectBounds?.(this.exposureSubjectBounds),!this.compassSprites.some(s=>s.visible))return;const t=new Gs,e=new ps(-1,1,1,-1,0,2),i=Dh/(Av*Math.tan(Tv*Ei/2));for(const s of this.compassSprites){if(!s.visible)continue;const r=s.getWorldPosition(new R).sub(this.camera.position).normalize(),o=this.screenPointOf(r);if(!o)continue;const c=new Mc(s.material);c.position.set(o.ndcX,o.ndcY,-1),c.scale.set(i/this.camera.aspect,i,1),t.add(c)}const n=this.renderer.autoClear;this.renderer.autoClear=!1;try{this.renderer.render(t,e)}finally{this.renderer.autoClear=n}}onMapSubjectBounds;exposureSubjectBounds=[];static MAP_SUBJECT_NEAREST_M=8;mapSubjectBounds(){const t=[],e=new Qi,i=new R,n=this.camera.getWorldDirection(new R),s=this.decorObjects.filter(o=>o.track?.length||o.kind==="aircraft"||o.kind==="vehicle").map(o=>this.decorGroups.get(o.id)),r=this.bodySystem.reflectors.map(o=>o.holder);for(const o of[...s,...r]){if(!o?.visible||(e.setFromObject(o),e.isEmpty())||e.distanceToPoint(this.camera.position)<le.MAP_SUBJECT_NEAREST_M)continue;let c=1/0,l=-1/0,h=1/0,u=-1/0;for(const d of[e.min.x,e.max.x])for(const f of[e.min.y,e.max.y])for(const p of[e.min.z,e.max.z]){if(i.set(d,f,p).sub(this.camera.position).normalize(),i.dot(n)<=0)continue;const v=this.screenPointOf(i);if(!v)continue;const m=(v.ndcX+1)/2,g=(1-v.ndcY)/2;c=Math.min(c,m),l=Math.max(l,m),h=Math.min(h,g),u=Math.max(u,g)}c=Math.max(c,0),l=Math.min(l,1),h=Math.max(h,0),u=Math.min(u,1),l>=c&&u>=h&&t.push({x:c,y:h,width:l-c,height:u-h})}return t}restateAt(t,e){this.restatingExposure=!0;try{t(e)}finally{this.restatingExposure=!1}}cancelExposure(){this.exposureFrameId!==null&&(cancelAnimationFrame(this.exposureFrameId),this.exposureFrameId=null)}setLensOptics(t){const e=this.lensOptics;this.lensOptics=t,(e===void 0!=(t===void 0)||e&&t&&(e.focalLengthMm!==t.focalLengthMm||e.fNumber!==t.fNumber||e.focusDistance!==t.focusDistance||e.frameHeightMm!==t.frameHeightMm))&&(t&&this.depthOfFieldPass&&this.depthOfFieldPass.setLens(t.focalLengthMm,t.fNumber,t.focusDistance,t.frameHeightMm),this.render())}usableDepthOfFieldPass(){const t=this.lensOptics;if(!t)return;const e=this.renderer.getDrawingBufferSize(new bt),i=Math.max(1,Math.round(e.x)),n=Math.max(1,Math.round(e.y));return this.depthOfFieldPass||(this.depthOfFieldPass=new Jc(i,n)),this.depthOfFieldPass.resize(i,n),this.depthOfFieldPass.setLens(t.focalLengthMm,t.fNumber,t.focusDistance,t.frameHeightMm),this.depthOfFieldPass}usableFinishPass(){const t=this.renderer.getDrawingBufferSize(new bt);return this.finishPass?this.finishPass.resize(t.x,t.y):this.finishPass=new dm(t.x,t.y),this.finishPass}usableEquidistantPass(){if(this.projectionKind!=="equidistant")return;const t=this.renderer.getDrawingBufferSize(new bt);return this.equidistantPass?this.equidistantPass.resize(t.x,t.y):this.equidistantPass=new Ke(t.x,t.y),this.equidistantPass}aimAtScreenPoint(t,e,i){const n=this.projectionKind==="equidistant"?this.equidistantPass:void 0;if(!n){t.setFromCamera(new bt(e,i),this.camera);return}const s=n.directionFor(e,i,this.camera.fov);this.camera.updateMatrixWorld(),t.ray.origin.setFromMatrixPosition(this.camera.matrixWorld),t.ray.direction.set(s.x,s.y,s.z).applyQuaternion(this.camera.quaternion).normalize(),t.camera=this.camera}pickCloudAt(t,e){return this.layeredClouds?.pickInstance(this.cloudDirectionAt(t,e))}cloudDirectionAt(t,e){return this.directionAtScreenPoint(t,e,new R)}directionAtScreenPoint(t,e,i){return this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e),i.copy(this.ufoOcclusionRaycaster.ray.direction)}screenPointOf(t){this.camera.updateMatrixWorld();const e=this.screenPointScratch.copy(t).applyQuaternion(this.screenPointQuaternion.copy(this.camera.quaternion).invert()),i=this.renderer.getDrawingBufferSize(this.screenPointSize),n=i.x/Math.max(i.y,1);if(this.projectionKind==="equidistant"&&this.equidistantPass)return Ke.ndcFor(e,this.camera.fov,n);if(e.z>=0)return;const s=Math.tan(this.camera.fov/2*Ei);return{ndcX:e.x/-e.z/(n*s),ndcY:e.y/-e.z/s}}screenPointScratch=new R;screenPointQuaternion=new Sn;screenPointSize=new bt;updateLensFlarePosition(){const t=this.lensFlare;if(!t)return;if(!this.sunVisible){t.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){t.mesh.visible=!1;return}const e=this.sunVisibleFraction();if(e<=0){t.mesh.visible=!1;return}t.mesh.visible=!0,this.sunUnhiddenFraction=e,this.applyDazzleStrength();const i=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);t.uniforms.uLensPosition.value.set(i.x,i.y);const n=this.renderer.domElement.width,s=this.renderer.domElement.height;t.uniforms.uResolution.value.set(n,s),t.uniforms.uTanHalfFov.value=Math.tan(this.camera.fov*Math.PI/360)}renderDazzleOnResample(){const t=this.lensFlare;if(!t||!this.sunVisible)return;const e=this.sunVisibleFraction();if(e<=0)return;this.sunUnhiddenFraction=e,this.applyDazzleStrength();const i=this.screenPointOf(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position).normalize());if(!i)return;const n=this.renderer.getDrawingBufferSize(this.screenPointSize);t.uniforms.uLensPosition.value.set(i.ndcX,i.ndcY),t.uniforms.uResolution.value.set(n.x,n.y),t.uniforms.uEquidistant.value=1,t.uniforms.uHalfFovRad.value=this.camera.fov*Math.PI/360;const s=this.renderer.autoClear;this.renderer.autoClear=!1,t.mesh.visible=!0,t.mesh.layers.enable(yv),this.camera.layers.set(yv),this.renderer.render(this.scene,this.camera),this.camera.layers.set(0),t.mesh.visible=!1,t.uniforms.uEquidistant.value=0,this.renderer.autoClear=s}sunVisibleFraction(){this.raycastableDecor().length>0&&this.scene.updateMatrixWorld();let t=0;for(const e of Dv)this.isSunOccluded(e[0],e[1])||t++;return t/Dv.length}raycastableDecor(){const t=[];for(const e of this.decorObjects){if(e.kind==="crop")continue;const i=this.decorGroups.get(e.id);i&&t.push(i)}return t}isSunOccluded(t=0,e=0){const i=this.raycastableDecor();if(!this.groundMesh&&!this.terrainMesh&&i.length===0)return!1;const n=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),s=n.length();if(n.normalize(),t!==0||e!==0){const o=Math.PI/180,c=this.sunOcclusionRightScratch.set(n.z,0,-n.x);c.lengthSq()<1e-9&&c.set(1,0,0),c.normalize();const l=this.sunOcclusionUpScratch.crossVectors(c,n).normalize();n.addScaledVector(c,t*o).addScaledVector(l,e*o).normalize()}if(this.groundBlocks(this.camera.position,n,s))return!0;if(i.length===0)return!1;this.sunOcclusionRaycaster.set(this.camera.position,n);const r=this.sunOcclusionRaycaster.intersectObjects(i,!0)[0];return r!==void 0&&r.distance<s}groundBlocks(t,e,i,n=0){const s=this.groundMesh;if(s&&e.y<0){const m=(s.position.y-t.y)/e.y;if(m>n&&m<i){const g=t.x+e.x*m-s.position.x,b=t.z+e.z*m-s.position.z;if(Math.hypot(g,b)<=this.groundRadius)return!0}}const r=this.terrainMesh;if(!r)return!1;const o=r.geometry.getAttribute("position"),c=Math.round(Math.sqrt(o.count));if(c<2||c*c!==o.count)return!1;const l=[r.position.x+o.getX(0),r.position.x+o.getX(c-1)],h=[r.position.z+o.getZ(0),r.position.z+o.getZ((c-1)*c)],u=Math.min(Math.abs(l[1]-l[0]),Math.abs(h[1]-h[0]))/(c-1);if(!(u>0))return!1;let d=n,f=i;for(const[m,g,b]of[[t.x,e.x,l],[t.z,e.z,h]]){const S=Math.min(b[0],b[1]),M=Math.max(b[0],b[1]);if(Math.abs(g)<1e-12){if(m<S||m>M)return!1;continue}const x=(S-m)/g,_=(M-m)/g;d=Math.max(d,Math.min(x,_)),f=Math.min(f,Math.max(x,_))}if(!(f>d))return!1;const p=Math.hypot(e.x,e.z),v=Math.min(4096,Math.max(8,Math.ceil((f-d)*p/(u/2))));for(let m=0;m<=v;m++){const g=d+(f-d)*m/v,b=t.x+e.x*g,S=t.y+e.y*g,M=t.z+e.z*g;if(S<=this.groundYUnder(b,M))return!0}return!1}setPhenomena(t,e){this.phenomena.set(t,e)}decorDistancesAt(t,e,i){this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e),this.ufoOcclusionRaycaster.near=xv;let n,s;for(const r of this.decorObjects){if(r.kind==="crop")continue;const o=this.decorGroups.get(r.id);if(!o)continue;const c=this.ufoOcclusionRaycaster.intersectObject(o,!0)[0];c&&(r.occludesSourceIds?.includes(i)?n=n===void 0?c.distance:Math.max(n,c.distance):s=s===void 0?c.distance:Math.min(s,c.distance))}return{behindM:n,inFrontM:s}}pickBodyAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.origin,n=this.raycaster.ray.direction,s=zR*this.camera.fov*Math.PI/180,r=[...this.hitAreas.entries()].map(([h,u])=>{const d=u.getWorldPosition(new R).sub(i);return{key:h,direction:d.clone().normalize(),radiusRad:Math.atan2(u.scale.x/2,d.length())}}),o=this.eclipseDiscs,c=o?[{key:"sun",direction:o.sun,radiusRad:o.sunRadiusRad},{key:"moon",direction:o.moon,radiusRad:o.moonRadiusRad,inFront:!0}]:[],l=le.nearestBody(n,[...r.filter(h=>!o||h.key!=="sun"&&h.key!=="moon"),...c],s);if(l)return this.groundHides(t,e)?void 0:l}static nearestBody(t,e,i){let n,s=1/0,r=1/0,o=!1;for(const c of e){const l=Math.acos(ir(c.direction.dot(t),-1,1))-c.radiusRad;if(l>i)continue;const h=l<=0,u=s<=0,d=c.inFront===!0;(h!==u?h:h?d!==o?d:c.radiusRad<r:l<s)&&(n=c.key,s=l,r=c.radiusRad,o=d)}return n}pickInterpretationBodyAt(t,e){const i=this.bodySystem.group.children.filter(f=>f.visible&&f.name.startsWith("body:"));if(i.length===0)return;this.aimAtScreenPoint(this.raycaster,t,e);const n=this.raycaster.ray.direction,s=this.raycaster.ray.origin,r=kR*this.camera.fov*Math.PI/180,o=[...this.decorGroups.values()],c=o.length>0?le.firstSolid(this.raycaster.intersectObjects(o,!0))?.distance:void 0;let l,h=1/0;const u=new Qi,d=new R;for(const f of i){if(u.setFromObject(f),u.isEmpty())continue;u.getCenter(d);const p=u.getSize(new R).length()/2,v=d.clone().sub(s),m=v.length();if(m===0||v.dot(n)<=0||c!==void 0&&c<m-p)continue;const g=Math.acos(Math.min(1,v.normalize().dot(n))),b=Math.max(r,Math.atan(p/m));g<=b&&b<h&&(h=b,l=f.name.slice(5))}return l}pickStarAt(t,e){if(this.namedStars.length===0)return;this.aimAtScreenPoint(this.raycaster,t,e);const i=this.raycaster.ray.direction,n=Math.cos(_f*this.camera.fov*Math.PI/180);let s,r=n;for(const o of this.namedStars){const c=o.direction.dot(i);c>r&&(r=c,s={star:o.star,altitudeDeg:o.altitudeDeg})}return s&&this.groundHides(t,e)?void 0:s}groundHides(t,e){if(!this.terrainMesh&&!this.groundMesh)return!1;this.aimAtScreenPoint(this.ufoOcclusionRaycaster,t,e);const i=this.ufoOcclusionRaycaster.ray;return this.groundBlocks(i.origin,i.direction,1/0,xv)}bodyScreenBox(t){const e=this.bodySystem.boxOf(t,this.bodyBoxScratch);if(!e)return;let i=1/0,n=1/0,s=-1/0,r=-1/0;for(let o=0;o<8;o++){const c=this.bodyCornerScratch.set(o&1?e.max.x:e.min.x,o&2?e.max.y:e.min.y,o&4?e.max.z:e.min.z),l=this.screenPointOf(c.sub(this.camera.position).normalize());if(!l)return;i=Math.min(i,l.ndcX),s=Math.max(s,l.ndcX),n=Math.min(n,l.ndcY),r=Math.max(r,l.ndcY)}return{minX:i,minY:n,maxX:s,maxY:r}}bodyBoxScratch=new Qi;bodyCornerScratch=new R;pickPlacedBodyAt(t,e){return this.aimAtScreenPoint(this.raycaster,t,e),this.bodySystem.pick(this.raycaster)}decorScreenBox(t){const e=this.decorGroups.get(t);if(!e||!e.visible)return;const i=this.bodyBoxScratch.setFromObject(e);if(i.isEmpty())return;let n=1/0,s=1/0,r=-1/0,o=-1/0;for(let c=0;c<8;c++){const l=this.bodyCornerScratch.set(c&1?i.max.x:i.min.x,c&2?i.max.y:i.min.y,c&4?i.max.z:i.min.z),h=this.screenPointOf(l.sub(this.camera.position).normalize());if(!h)return;n=Math.min(n,h.ndcX),r=Math.max(r,h.ndcX),s=Math.min(s,h.ndcY),o=Math.max(o,h.ndcY)}return{minX:n,minY:s,maxX:r,maxY:o}}decorGroundPointAt(t,e,i,n=0){const s=this.decorGroups.get(t);if(!s)return;this.aimAtScreenPoint(this.raycaster,e,i);const r=this.raycaster.ray.intersectPlane(this.decorPlaneScratch.setComponents(0,1,0,-(s.position.y+n)),this.decorHitScratch);return r?{x:r.x,z:r.z}:void 0}decorMetresPerNdcY(t){const e=this.decorGroups.get(t);return e?e.position.distanceTo(this.camera.position)*Math.tan(this.camera.fov*Ei/2):0}decorGrabHeightAt(t,e,i){const n=this.decorGroups.get(t);if(!n)return 0;const s=this.bodyBoxScratch.setFromObject(n).max.y-n.position.y;this.aimAtScreenPoint(this.raycaster,e,i);const r=this.decorHitScratch.set(this.camera.position.x-n.position.x,0,this.camera.position.z-n.position.z);if(r.lengthSq()<1e-6)return 0;r.normalize();const o=this.decorPlaneScratch.setFromNormalAndCoplanarPoint(r,n.position),c=this.raycaster.ray.intersectPlane(o,this.decorHitScratch);return c?Math.min(Math.max(c.y-n.position.y,0),Math.max(s,0)):0}decorPlaneScratch=new Ir;decorHitScratch=new R;static firstSolid(t){return t.find(e=>{const i=e.object.material;return!(Array.isArray(i)?i:[i]).some(s=>s&&s.transparent&&s.opacity<le.SEE_THROUGH_BELOW)})}static SEE_THROUGH_BELOW=.9;pickDecorAt(t,e){this.aimAtScreenPoint(this.raycaster,t,e);const i=[...this.decorGroups.entries()],n=le.firstSolid(this.raycaster.intersectObjects(i.map(([,r])=>r),!0));if(!n)return;let s=n.object;for(;s&&!i.some(([,r])=>r===s);)s=s.parent;return i.find(([,r])=>r===s)?.[0]}dispose(){this.stopTerrainFade(),this.stopTwinkle(),this.cancelFlush(),this.phenomena.clear(),this.references.disposeAll(),this.terrainBuildToken++,this.cancelScatteredSkyPump(),this.skyMesh&&this.skyGradientMaterial&&(this.skyMesh.material=this.skyGradientMaterial),this.scatteredSky?.dispose(),this.scatteredSky=void 0,this.disposeMesh(this.skyMesh),this.disposeMesh(this.groundMesh),this.disposeMesh(this.terrainMesh),this.roadSystem.dispose(),this.traceSystem?.dispose(),this.contrailSystem?.dispose(),this.contrailSystem=void 0,this.disposeCloudSystem(),this.disposeCirrus(),this.disposePrecipitationPoints(),this.disposeRain(),this.disposeStarTiers(),this.meteorSystem?.dispose(),this.meteorSystem=void 0,this.iceHalos?.dispose(),this.iceHalos=void 0,this.rainbow?.dispose(),this.rainbow=void 0,this.skyGlow?.dispose(),this.skyGlow=void 0,this.depthOfFieldPass?.dispose(),this.finishPass?.dispose(),this.depthOfFieldPass=void 0,this.cancelExposure(),this.exposureAccumulation?.dispose(),this.exposureAccumulation=void 0,this.cometTail?.dispose(),this.cometTail=void 0,this.satelliteField?.dispose(),this.satelliteField=void 0,this.reentrySystem?.dispose(),this.reentrySystem=void 0,this.lightningBolt?.dispose(),this.lightningBolt=void 0;for(const t of this.bodyMeshes.values())this.disposeMesh(t);this.bodyMeshes.clear(),this.novaKeys.clear();for(const t of[...this.hitAreas.keys()])this.disposeHitArea(t);for(const t of[...this.glareSprites.keys()])this.disposeGlare(t);this.disposeCompassLabels();for(const t of this.decorGroups.values())Ye.dispose(t);this.decorGroups.clear(),this.streetlightLights.clear(),this.lensFlare&&(this.lensFlare.mesh.removeFromParent(),this.lensFlare.mesh.geometry.dispose(),this.lensFlare.mesh.material.dispose(),this.lensFlare=void 0),this.renderer.dispose()}animationsRunning=!1;startTwinkle(){if(this.animationFrameId!==null||!this.needsAnimationLoop())return;this.cancelFlush();const t=e=>{this.animationFrameId=null,this.frame(e),this.animationFrameId===null&&this.needsAnimationLoop()&&(this.animationFrameId=requestAnimationFrame(t))};this.animationFrameId=requestAnimationFrame(t)}setAnimationsRunning(t,e=!1){const i=t&&e;if(t===this.animationsRunning&&i===this.framesDriven)return;const n=this.animationsRunning;this.animationsRunning=t,this.framesDriven=i,t&&!n&&(this.lastFrameTimeMs=void 0,this.resolution.reset());const s=!t&&this.renderer.getPixelRatio()!==this.resolution.maximum;s&&this.applyPixelRatio(this.resolution.maximum),this.syncAnimationLoop(),(!t||this.frameDirty)&&this.render(),s&&this.drawIfDirty()}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}needsAnimationLoop(){return this.animationsRunning&&!this.framesDriven&&!this.suspended&&this.hasAnimations()}hasAnimations(){return this.starTiers.some(t=>t.brightness.length>0)||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.flareMayShow()}flareAimScratch=new R;flareMayShow(){if(this.lensFlare===void 0||!this.sunVisible)return!1;const t=this.lastAstronomy?.sun;return t!==void 0&&t.altitudeDeg<le.FLARE_ANIMATION_MIN_ALTITUDE_DEG?!1:(this.camera.getWorldDirection(this.flareAimScratch),this.flareAimScratch.dot(this.lensFlareScratch.copy(this.sunWorldPosition).sub(this.camera.position))>0)}static FLARE_ANIMATION_MIN_ALTITUDE_DEG=-3;syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(t){const e=this.skyMesh?.geometry??new pi(Ah,32,16),i=e.attributes.position,n=e.getAttribute("color")??new ve(new Float32Array(i.count*3),3);for(let r=0;r<i.count;r++){const{altitudeDeg:o,azimuthDeg:c}=tT(i.getX(r),i.getY(r),i.getZ(r)),l=cT(o,c,t.azimuthDeg,t.altitudeDeg);n.setXYZ(r,l[0],l[1],l[2])}if(n.needsUpdate=!0,this.skyMesh)return;e.setAttribute("color",n);const s=new wn({vertexColors:!0,side:Qe,fog:!1,depthWrite:!1});this.skyGradientMaterial=s,this.skyMesh=new At(e,s),this.skyMesh.renderOrder=-1,this.celestialGroup.add(this.skyMesh)}buildGround(){const t=bv(this.observerElevationM);if(this.groundMesh&&t===this.groundRadius)return;this.disposeMesh(this.groundMesh),this.groundRadius=t;const e=new Wp(this.groundRadius,48),i=new nc({color:new st(Sf,Sf,Sf),fog:!0});Fa.fadeRim(i,this.groundRadius*.75,this.groundRadius),this.groundMesh=new At(e,i),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh),this.applyGroundDepthWrite()}applyGroundDepthWrite(){const t=this.groundMesh?.material;if(!t)return;const e=this.terrainMesh===void 0;t.depthWrite!==e&&(t.depthWrite=e,t.needsUpdate=!0);const i=this.terrainMesh;let n=0;if(i){const s=i.geometry.getAttribute("position");n=1/0;for(let r=0;r<s.count;r++)Math.abs(s.getX(r)+i.position.x)>600||Math.abs(s.getZ(r)+i.position.z)>600||(n=Math.min(n,s.getY(r)+i.position.y));n=Number.isFinite(n)?Math.min(0,n)-1:0}this.groundMesh.position.y=n,this.groundMesh.renderOrder=0,t.depthTest=!0,t.needsUpdate=!0}cloudTransmission(t,e=!1){const i=`${t.altitudeDeg.toFixed(1)}:${t.azimuthDeg.toFixed(1)}:${Math.round(this.cloudOffsetM.x/10)}:${Math.round(this.cloudOffsetM.z/10)}:${Math.round(this.observerElevationM)}:`+Object.entries(this.cloudLayerOffsetsM).map(([r,o])=>`${r}=${Math.round(o.x/10)},${Math.round(o.z/10)}`).join(";")+(e?":water":""),n=this.cloudTransmissionMemo.get(i);if(n!==void 0)return n;this.cloudTransmissionMemo.size>256&&this.cloudTransmissionMemo.clear();const s=this.computeCloudTransmission(t,e);return this.cloudTransmissionMemo.set(i,s),s}cloudTransmissionMemo=new Map;computeCloudTransmission(t,e=!1){const i=Xe(t.altitudeDeg,t.azimuthDeg,1);if(this.layeredClouds)return this.layeredClouds.transmissionAt(i,e);let n=1;const s=this.lowerCloudCover();s>0&&(n*=1-we.alphaAt(i,Math.abs(this.cloudLayerOffset()),s,this.cloudFieldOffset)*GR);const r=e?0:this.weather.highCloudCover??0;return r>0&&(n*=1-we.iceAlphaAt(i,Th,r,this.cloudFieldOffset)*VR),Math.max(0,Math.min(1,n))}setBodyMesh(t,e,i,n,s){if(e.altitudeDeg<Jh){this.disposeMesh(this.bodyMeshes.get(t)),this.bodyMeshes.delete(t),this.disposeHitArea(t),this.disposeGlare(t),t==="sun"&&(this.sunVisible=!1);return}const{x:r,y:o,z:c}=Xe(e.altitudeDeg,e.azimuthDeg,pn),l=G1(e.altitudeDeg),h=this.cloudTransmission(e),u=this.arrivingIlluminance(e,s,h),d=le.unitLuminance(n);let f=this.bodyMeshes.get(t);if(t==="sun"){const p=Math.PI*(i/pn)**2,v=[0,1,2].map(g=>d[g]*u[g]/(this.sunBeamFraction*p));this.sunDiscRadiance=v;const m=v.map(g=>Math.min(le.BRIGHTEST_RELATIVE,g));f instanceof At||(this.disposeMesh(f),f=new At(new pi(1,16,16),this.eclipsedSun.material()),this.celestialGroup.add(f),this.bodyMeshes.set(t,f)),f.material.color.setRGB(m[0],m[1],m[2]),f.scale.setScalar(i)}else{if(!(f instanceof In)){this.disposeMesh(f);const m=new ae;m.setAttribute("position",new te(new Float32Array(3),3)),m.setAttribute("color",new te(new Float32Array(3),3)),f=new In(m,Ct.material(Vo[Vo.length-1].size,!1)),Ct.track(f),this.celestialGroup.add(f),this.bodyMeshes.set(t,f)}const p=f.geometry.getAttribute("color"),v=t.startsWith("comet:")?this.pointToPixel():1;p.setXYZ(0,d[0]*u[0]*v,d[1]*u[1]*v,d[2]*u[2]*v),p.needsUpdate=!0}if(f.position.set(r,o,c),this.setHitArea(t,r,o,c,i),t==="sun"&&(this.sunArriving=u),t.startsWith("comet:")?this.disposeGlare(t):t!=="sun"&&this.setGlare(t,r,o,c,u,i/pn*(180/Math.PI),le.POINT_VEIL_HOLD_DEG),t==="sun"){this.sunVisible=!0;const p=this.celestialGroup.scale.x;this.sunWorldPosition.set(r*p,o*p+this.celestialGroup.position.y,c*p),this.lensFlare||(this.lensFlare=Q4(),this.lensFlare.uniforms.uOpacity.value=jR,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.lensFlare.uniforms.uStarPoints.value=this.starPoints,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(l)}}setMoonMesh(t,e){const i="moon";if(t.magnitude>e||t.altitudeDeg<Jh){this.disposeMesh(this.bodyMeshes.get(i)),this.bodyMeshes.delete(i),this.disposeHitArea(i),this.disposeGlare(i);return}const{x:n,y:s,z:r}=Xe(t.altitudeDeg,t.azimuthDeg,pn),o=this.cloudTransmission(t),c=this.arrivingIlluminance(t,t.magnitude,o),l=t.radiusDeg??Cs.MEAN_RADIUS_DEG,h=pn*Math.tan(l*Ei),u=Math.max(ir(t.phase.illuminatedFraction,0,1),.01)*Math.PI*(h/pn)**2,d=new st(...c.map(v=>Math.min(le.BRIGHTEST_RELATIVE,v/u))),f=`${t.phase.phaseFraction<.5}:${Math.round(ir(t.phase.illuminatedFraction,0,1)*500)}`;let p=this.bodyMeshes.get(i);p instanceof Mc?(p.userData.phaseKey!==f&&(p.material.map?.dispose(),p.material.map=Yv(t.phase),p.userData.phaseKey=f),p.material.color.copy(d)):(this.disposeMesh(p),p=new Mc(new Yh({map:Yv(t.phase),color:d,fog:!1,blending:Ti,depthWrite:!1})),p.userData.phaseKey=f,this.celestialGroup.add(p),this.bodyMeshes.set(i,p)),p.scale.set(h*2,h*2,1),p.position.set(n,s,r),this.setHitArea(i,n,s,r,h),this.setGlare(i,n,s,r,c,l)}bentLight(t,e,i=BR){const[n,s,r]=this.arrivingIlluminance(t,e,1),o=Math.max(s,1e-30);return{scale:s/i,tint:[n/o,1,r/o]}}static litBySky(t,e){return le.litScratch.setRGB(t.r*e[0],t.g*e[1],t.b*e[2])}static litScratch=new st;pointToPixel(){const t=Math.max(1,this.renderer.getDrawingBufferSize(this.pointScratch).y),e=(this.camera.fov*Math.PI/180/t)**2;return Math.min(1,Ct.CONE_SOLID_ANGLE/e)}pointScratch=new bt;static POINT_VEIL_HOLD_DEG=.25;static BRIGHTEST_RELATIVE=6e4;arrivingIlluminance(t,e,i){const n=this.air.transmittanceFromSpace(this.siteElevationM+this.observerElevationM,t.altitudeDeg),s=ye.illuminanceOf(e)*i*this.relativeScale;return[n[0]*s,n[1]*s,n[2]*s]}static unitLuminance(t){const e=us.luminanceOf([t.r,t.g,t.b]);return e>0?[t.r/e,t.g/e,t.b/e]:[1,1,1]}setHitArea(t,e,i,n,s){let r=this.hitAreas.get(t);if(!r){const c=new Yh({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1});r=new Mc(c),this.celestialGroup.add(r),this.hitAreas.set(t,r)}r.position.set(e,i,n);const o=s*2;r.scale.set(o,o,1)}disposeHitArea(t){const e=this.hitAreas.get(t);e&&(e.removeFromParent(),e.material.dispose(),this.hitAreas.delete(t))}setGlare(t,e,i,n,s,r,o=0){if(Ki.radiusDeg(Ki.K*Math.max(...s))<=Math.max(r,o)){this.disposeGlare(t);return}let c=this.glareSprites.get(t);c||(c=new Ki(`veil:${t}`),this.celestialGroup.add(c.mesh),this.glareSprites.set(t,c)),c.shine({x:e,y:i,z:n},s,r,o)}disposeGlare(t){const e=this.glareSprites.get(t);e&&(e.mesh.removeFromParent(),e.dispose(),this.glareSprites.delete(t))}buildComet(t,e){const i=t&&`comet:${t.id}`;if(!t||!i||t.magnitude>e){this.disposeComet();return}this.cometKey&&this.cometKey!==i&&this.disposeComet();const n=Po(t.magnitude,e),s=lf(n);this.cometKey=i,this.setBodyMesh(i,t.position,Ef*(.5+.5*n),new st(s,s,s),t.magnitude),this.cometTail||(this.cometTail=new Rn(pn),this.celestialGroup.add(this.cometTail.object)),this.cometTail.set(t.position,t.tailEnd,n)}buildIceHalos(t,e){this.iceHalos||(this.iceHalos=new Ui,this.iceHalos.setCloudOffset(this.cloudFieldOffset),this.iceHalos.onReady=()=>this.render(),this.celestialGroup.add(this.iceHalos.object)),this.iceHalos.setUrgent(!!this.skyHoldUntilMs);const i=this.highCloudCover(),n=this.layeredClouds?.cirrusMask;if(this.iceHalos.setCloudOffset(n?.offset??this.cloudFieldOffset),this.layeredClouds?.hostHalo(this.iceHalos),i===void 0){this.iceHalos.update({x:0,y:1,z:0},-1,0,[1,1,1],{cover:0,layerHeight:Th},0);return}const s=this.lowerCloudCover(),r=Se.deckLitUntilDeg(Se.DECK_HEIGHT_M),o=t.altitudeDeg>-r?t:e,c=this.bentLight(o,o===t?se.SUN_MAGNITUDE:e.magnitude),l=Se.strength(i,s,o.altitudeDeg,r)*c.scale,{x:h,y:u,z:d}=Xe(o.altitudeDeg,o.azimuthDeg,1);this.iceHalos.update({x:h,y:u,z:d},o.altitudeDeg,l,c.tint,{cover:n?.cover??i,layerHeight:n?.layerHeight??Th},n?.iceCrystalAlignment??this.weather.iceCrystalAlignment??Iy)}buildRainbow(t,e){this.rainbow||(this.rainbow=new Ra,this.celestialGroup.add(this.rainbow.object));const i=this.weather.precipitationType==="rain"?this.weather.precipitationIntensity*(this.weather.precipitationAmount??1):0,n=t.altitudeDeg>0,s=n?t:e,r=this.lowerCloudCover(),o=this.bentLight(s,n?se.SUN_MAGNITUDE:e.magnitude,HR),c=Tn.strength(i,r,s.altitudeDeg)*o.scale;if(c<=0){this.rainbow.update({x:0,y:1,z:0},0,[1,1,1],!0);return}const{x:l,y:h,z:u}=Xe(s.altitudeDeg,s.azimuthDeg,1);this.rainbow.update({x:l,y:h,z:u},c,o.tint,n)}buildSkyGlow(t,e){if(!t.frame){this.skyGlow?.hide();return}this.skyGlow||(this.skyGlow=new Cr,this.skyGlow.setWithheld(!!this.skyHoldUntilMs),this.skyGlow.onReady=()=>this.render(),this.celestialGroup.add(this.skyGlow.object));const{date:i,observer:n}=t.frame,s=ns.galactic(i,n),r=le.directionOf(s.centre),o=le.directionOf(s.rotation),c=le.directionOf(s.pole),l=new Jt().set(r.x,r.y,r.z,o.x,o.y,o.z,c.x,c.y,c.z),h=le.directionOf(ns.eclipticPole(i,n)),u=le.directionOf(t.sun),d=u.clone().addScaledVector(h,-u.dot(h)).normalize();this.skyGlow.update({galactic:l,eclipticPole:h,sunLongitude:d,sunDirection:u,sunAltitudeDeg:t.sun.altitudeDeg,moon:{direction:le.directionOf(t.moon),altitudeDeg:t.moon.altitudeDeg,phaseAngleDeg:St.phaseAngleOf(t.moon.phase.illuminatedFraction)},lightPollution:this.lightPollution,skyColor:new R(e[0],e[1],e[2])})}static directionOf(t){const{x:e,y:i,z:n}=Xe(t.altitudeDeg,t.azimuthDeg,1);return new R(e,i,n).normalize()}buildNovae(t,e){const i=new Set;for(const n of t){if(n.magnitude>e)continue;const s=`nova:${n.id}`;i.add(s);const r=Po(n.magnitude,e),o=lf(r);this.setBodyMesh(s,n.position,Ef*(.5+.5*r),new st(o,o,o),n.magnitude)}for(const n of this.novaKeys)i.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n));this.novaKeys=i}disposeComet(){this.cometTail?.set(void 0,void 0,0),this.cometKey&&(this.disposeMesh(this.bodyMeshes.get(this.cometKey)),this.bodyMeshes.delete(this.cometKey),this.disposeHitArea(this.cometKey),this.disposeGlare(this.cometKey),this.cometKey=void 0)}buildPlanets(t,e){const i=new Set(["sun","moon",...this.cometKey?[this.cometKey]:[],...this.novaKeys]);for(const n of t){if(n.magnitude>e)continue;i.add(n.body);const s=Po(n.magnitude,e),r=lf(s),o=MD[n.body]??new st(1,1,1),c=new st(o.r*r,o.g*r,o.b*r),l=Ef*(.5+.5*s);this.setBodyMesh(n.body,n.position,l,c,n.magnitude)}for(const n of[...this.bodyMeshes.keys()])i.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n))}buildStars(t,e){if(this.namedStars=[],!t||t.catalog.count===0){this.disposeStarTiers(),this.syncAnimationLoop();return}const{catalog:i,date:n,observer:s}=t,r=new os(n,s),o=Nf(1337),c=[],l=this.siteElevationM+this.observerElevationM;for(let h=0;h<i.count;h++){const u=i.mag[h];if(u>e)break;const{altitudeDeg:d,azimuthDeg:f}=r.position(i.ra[h],i.dec[h]);if(d<wv)continue;const{x:p,y:v,z:m}=Xe(d,f,wf);c.push({x:p,y:v,z:m,brightness:Po(u,e),illuminance:this.air.transmittanceFromSpace(l,d).map(g=>g*ye.illuminanceOf(u)),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}for(const h of P4){if(h.mag>e)continue;const{altitudeDeg:u,azimuthDeg:d}=r.position(h.raHours,h.decDeg);if(u<wv)continue;const{x:f,y:p,z:v}=Xe(u,d,wf);this.namedStars.push({star:h,direction:new R(f,p,v).normalize(),altitudeDeg:u})}this.starTiers=Vo.map((h,u)=>{const d=c.filter(x=>tm(x.brightness)===u),f=new Float32Array(d.length*3),p=new Float32Array(d.length),v=new Float32Array(d.length*3),m=new Float32Array(d.length),g=new Float32Array(d.length);d.forEach((x,_)=>{f[_*3]=x.x,f[_*3+1]=x.y,f[_*3+2]=x.z,p[_]=x.brightness,v.set(x.illuminance,_*3),m[_]=x.phase,g[_]=x.speedFactor});const b=new ae;b.setAttribute("position",new te(f,3)),b.setAttribute("seed",new te(m.map(x=>x/(2*Math.PI)),1));const S=new te(new Float32Array(d.length*3),3);b.setAttribute("color",S);let M=this.starTiers[u]?.points;return M?(M.geometry.dispose(),M.geometry=b):(M=new In(b,Ct.material(h.size)),Ct.track(M),this.celestialGroup.add(M)),{points:M,colorAttribute:S,brightness:p,illuminance:v,phase:m,speedFactor:g}}),this.starColoursRelative=Number.NaN,this.updateTwinkle(this.twinkleSeconds),this.startTwinkle()}twinkleSeconds=0;starColoursRelative=Number.NaN;updateTwinkle(t){Ct.setTime(t);const e=this.relativeScale;if(e!==this.starColoursRelative){this.starColoursRelative=e;for(const i of this.starTiers){const n=i.colorAttribute.array;for(let s=0;s<i.brightness.length;s++)n[s*3]=i.illuminance[s*3]*e,n[s*3+1]=i.illuminance[s*3+1]*e,n[s*3+2]=i.illuminance[s*3+2]*e;i.colorAttribute.needsUpdate=!0}}}buildClouds(){if(this.cloudRendering==="volume"||this.weather.cloudLayers!==void 0){this.layeredClouds||(this.disposeCloudSystem(),this.layeredClouds=new Ho(this.celestialGroup,Af,this.cloudRendering)),this.disposeCirrus(),this.layeredClouds.hostHalo(this.iceHalos),this.layeredClouds.update(this.weather,this.observerElevationM+1.6),this.layeredClouds.setOffsets(this.cloudOffsetM,this.cloudLayerOffsetsM),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const t=this.lowerCloudCover();if(t<=0){this.disposeCloudSystem();return}const e=this.weather.cloudDarkness,i=new st(ia[0]+(Df[0]-ia[0])*e,ia[1]+(Df[1]-ia[1])*e,ia[2]+(Df[2]-ia[2])*e);if(this.cloudMesh&&this.cloudUniforms){this.cloudUniforms.coverage.value=t,this.cloudUniforms.baseColor.value.copy(i),this.syncCloudLayer(),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}this.disposeCloudSystem();const{material:n,uniforms:s}=W0(i,t,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,s.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const r=X0(Af);this.cloudMesh=new At(r,n),this.faceCloudDeck(this.cloudMesh,this.cloudLayerOffset()),this.celestialGroup.add(this.cloudMesh)}lowerCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(t=>t.type!=="cirrus").reduce((t,e)=>t*(1-e.coverage),1):this.weather.lowerCloudCover??this.weather.cloudCover}highCloudCover(){return this.weather.cloudLayers?1-this.weather.cloudLayers.filter(t=>t.type==="cirrus").reduce((t,e)=>t*(1-e.coverage),1):this.weather.highCloudCover}buildCirrus(){const t=this.weather.highCloudCover??0;if(this.layeredClouds||t<=0){this.disposeCirrus();return}if(this.cirrusMesh&&this.cirrusUniforms){this.cirrusUniforms.coverage.value=t,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);return}const{material:e,uniforms:i}=W0(new st(...ia),t,Th,1);this.cirrusMaterial=e,this.cirrusUniforms=i,i.fieldOffset.value.copy(this.cloudFieldOffset),this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.cirrusMesh=new At(X0(Af*1.04),e),this.cirrusMesh.renderOrder=Iv-1,this.celestialGroup.add(this.cirrusMesh)}disposeCirrus(){this.cirrusMesh&&(this.cirrusMesh.removeFromParent(),this.cirrusMesh.geometry.dispose()),this.cirrusMaterial?.dispose(),this.cirrusMesh=void 0,this.cirrusMaterial=void 0,this.cirrusUniforms=void 0}syncCloudLayer(){this.layeredClouds?.update(this.weather,this.observerElevationM+1.6);const t=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(t)),this.cloudMesh&&this.faceCloudDeck(this.cloudMesh,t)}faceCloudDeck(t,e){const i=e<0;t.scale.y=i?-1:1,t.renderOrder=i?Ho.deckOrder(!0,0,1):Iv}cloudLayerOffset(){const e=((this.weather.cloudBaseM??Mp)-this.observerElevationM)*Tf;return Math.sign(e||1)*Math.max(Math.abs(e),tD)}updateCloudLighting(t,e){const i=[this.cloudUniforms,this.cirrusUniforms].filter(u=>u!==void 0);if(i.length===0&&!this.layeredClouds)return;const n=this.cloudBeamDirection,[s,r,o]=this.cloudBeam.map(u=>u/Math.PI),c=this.lightningLevel*Lf*this.relativeScale/Math.PI,l=new st(e[0]+Ss.r*c,e[1]+Ss.g*c,e[2]+Ss.b*c);this.layeredClouds?.setLighting(n.clone(),new st(s,r,o),l,l);const h=Math.max(0,n.y);for(const u of i)u.sunDir.value.copy(n),u.sunColor.value.setRGB(s*h,r*h,o*h),u.ambientColor.value.copy(l)}disposeCloudSystem(){this.layeredClouds?.dispose(),this.layeredClouds=void 0,this.cloudMesh&&(this.cloudMesh.removeFromParent(),this.cloudMesh.geometry.dispose()),this.cloudMaterial?.dispose(),this.cloudMesh=void 0,this.cloudMaterial=void 0,this.cloudUniforms=void 0}disposePrecipitationPoints(){this.precipitationPoints&&(this.precipitationPoints.removeFromParent(),this.precipitationPoints.geometry.dispose(),this.precipitationPoints.material.dispose()),this.precipitationPoints=void 0,this.precipitationPositions=void 0,this.precipitationPhase=void 0,this.precipitationSpeedJitter=void 0,this.precipitationWobbleFreqJitter=void 0,this.precipitationWobbleAmpJitter=void 0,this.precipitationBounceRemaining=void 0,this.precipitationBounceHeight=void 0,this.precipitationBounceDuration=void 0,this.precipitationBounceVelX=void 0,this.precipitationBounceVelZ=void 0,this.precipitationUniforms=void 0}precipitationCount(t){return cD(t,this.weather.precipitationIntensity,this.weather.precipitationAmount??1)}updatePrecipitationDensity(){const t=[[this.rainSystem?.points,Pf],[this.rainSplashSystem?.points,na],[this.precipitationPoints,this.weather.precipitationType==="none"||this.weather.precipitationType==="rain"?void 0:If[this.weather.precipitationType].poolSize]];for(const[e,i]of t)e&&i!==void 0&&e.geometry.setDrawRange(0,this.precipitationCount(i));this.rainSystem&&(this.rainSystem.uniforms.uSpeedStreak.value=Lv(Of(this.weather.precipitationIntensity)))}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const t=this.weather.precipitationType;if(t==="none")return;if(t==="rain"){this.buildRain();return}const e=If[t],i=e.poolSize,n=Nf(9001),s=new Float32Array(i*3),r=new Float32Array(i),o=new Float32Array(i),c=new Float32Array(i),l=new Float32Array(i),h=new Float32Array(i),u=new Float32Array(i),d=new Float32Array(i),f=new Float32Array(i),p=new Float32Array(i);for(let S=0;S<i;S++){const M=n()*Math.PI*2,x=n()*e.radiusM;s[S*3]=Math.cos(M)*x,s[S*3+1]=To+n()*(e.topYM-To),s[S*3+2]=Math.sin(M)*x,r[S]=n()*Math.PI*2,o[S]=.7+n()*.6,c[S]=.6+n()*.8,l[S]=.4+n()*1.2}const v=new ae;v.setAttribute("position",new te(s,3)),v.setDrawRange(0,this.precipitationCount(i));const m={uSize:{value:e.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:e.opacity},uColor:{value:e.color.clone()},uHazeColor:{value:new st(...this.baseFogColor)},uTexture:{value:yD(t)},uNearFocusDistance:{value:Uv},uHazeDistance:{value:e.radiusM*zv}},g=new Me({uniforms:m,vertexShader:ED,fragmentShader:AD,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const b=new In(v,g);b.renderOrder=Rf,this.scene.add(b),this.precipitationPoints=b,this.precipitationPositions=s,this.precipitationPhase=r,this.precipitationSpeedJitter=o,this.precipitationWobbleFreqJitter=c,this.precipitationWobbleAmpJitter=l,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=u,this.precipitationBounceDuration=d,this.precipitationBounceVelX=f,this.precipitationBounceVelZ=p}updatePrecipitation(t,e){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter)return;this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor);const i=this.weather.precipitationType;if(i==="none"||i==="rain")return;const n=If[i];if(this.precipitationUniforms?.uColor.value.copy(le.litBySky(n.color,this.baseFogColor)),e<=0)return;const s=this.weather.windDirectionDeg*Ei,r=Math.sin(s)*this.weather.windSpeed*n.driftSensitivity,o=-Math.cos(s)*this.weather.windSpeed*n.driftSensitivity,c=this.precipitationPositions,l=this.precipitationPhase,h=this.precipitationSpeedJitter,u=this.precipitationWobbleFreqJitter,d=this.precipitationWobbleAmpJitter,f=this.precipitationBounceRemaining,p=this.precipitationBounceHeight,v=this.precipitationBounceDuration,m=this.precipitationBounceVelX,g=this.precipitationBounceVelZ,b=i==="snow"&&u&&d,S=i==="hail"&&f&&p&&v&&m&&g;for(let M=0,x=0;M<c.length;M+=3,x++){if(S&&f[x]>0){if(f[x]-=e,f[x]<=0){const y=Math.random()*Math.PI*2,T=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(y)*T,c[M+1]=n.topYM,c[M+2]=Math.sin(y)*T,f[x]=0}else{const y=1-f[x]/v[x];c[M+1]=To+Math.sin(Math.PI*y)*p[x],c[M]=Ih(c[M]+(r+m[x])*e,n.radiusM),c[M+2]=Ih(c[M+2]+(o+g[x])*e,n.radiusM)}continue}let _=0,E=0;if(b){const y=hD*u[x],T=uD*d[x];_=Math.sin(t*y*Math.PI*2+l[x])*T,E=Math.sin(t*y*Math.PI*2+l[x]+Math.PI/2)*T}if(c[M]+=(r+_)*e,c[M+1]-=n.fallSpeedMPerS*h[x]*e,c[M+2]+=(o+E)*e,c[M]=Ih(c[M],n.radiusM),c[M+2]=Ih(c[M+2],n.radiusM),c[M+1]<To){if(S){p[x]=Wv*(.2+Math.random()*1.6),v[x]=dD*(.5+Math.random()),f[x]=v[x];const I=Math.random()*Math.PI*2,C=fD*(p[x]/Wv);m[x]=Math.cos(I)*C,g[x]=Math.sin(I)*C,c[M+1]=To;continue}const y=Math.random()*Math.PI*2,T=Math.sqrt(Math.random())*n.radiusM;c[M]=Math.cos(y)*T,c[M+1]=n.topYM,c[M+2]=Math.sin(y)*T}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const t=Of(this.weather.precipitationIntensity);this.rainSystem=K4({count:Pf,radiusM:Cc,heightM:iD,bottomYM:Cv,overallSpeed:nD,color:Ov.clone(),opacity:.85,visibleCount:this.precipitationCount(Pf),speedStreak:Lv(t),pixelSize:Hv,seed:9001,nearFocusDistanceM:Uv,hazeDistanceM:Cc*zv,hazeColor:new st(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.syncRainSlant(),this.rainSystem.points.renderOrder=Rf,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const t=Nf(4242),e=new Float32Array(na*3),i=new Float32Array(na),n=new Float32Array(na),s=new Float32Array(na);for(let h=0;h<na;h++){const u=t()*Math.PI*2,d=Math.sqrt(t())*Cc;e[h*3]=Math.cos(u)*d,e[h*3+1]=Cv,e[h*3+2]=Math.sin(u)*d,n[h]=Xv(Nv,kv),i[h]=t()*n[h],s[h]=i[h]/n[h]}const r=new ae;r.setAttribute("position",new te(e,3));const o=new te(s,1);r.setAttribute("aLife",o),r.setDrawRange(0,this.precipitationCount(na));const c=new Me({uniforms:{uMaxSize:{value:oD},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:Fv.clone()},uTexture:{value:SD()}},vertexShader:wD,fragmentShader:_D,transparent:!0,depthWrite:!1}),l=new In(r,c);l.renderOrder=Rf,this.scene.add(l),this.rainSplashSystem={points:l,positions:e,life:i,duration:n,lifeAttribute:o}}disposeRain(){this.rainSystem&&(this.rainSystem.points.removeFromParent(),this.rainSystem.points.geometry.dispose(),this.rainSystem.points.material.dispose()),this.rainSystem=void 0,this.disposeRainSplashes()}disposeRainSplashes(){this.rainSplashSystem&&(this.rainSplashSystem.points.removeFromParent(),this.rainSplashSystem.points.geometry.dispose(),this.rainSplashSystem.points.material.dispose()),this.rainSplashSystem=void 0}syncRainSlant(){const t=this.rainSystem;if(!t)return;const e=this.weather.windDirectionDeg*Ei;t.uniforms.uDropVelocity.value.set(Math.sin(e)*this.weather.windSpeed,-Of(this.weather.precipitationIntensity),-Math.cos(e)*this.weather.windSpeed);const i=this.renderer.getSize(this.rainViewportSize);t.uniforms.uAspect.value=i.x/Math.max(i.y,1)}updateRain(t){const e=this.rainSystem;if(!e)return;e.uniforms.uTime.value+=t,e.uniforms.uHazeColor.value.setRGB(...this.baseFogColor),e.uniforms.uColor.value.copy(le.litBySky(Ov,this.baseFogColor));const i=this.rainSplashSystem?.points.material?.uniforms?.uColor;i&&i.value.copy(le.litBySky(Fv,this.baseFogColor));const n=this.weather.windDirectionDeg*Ei,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,o=Cc,c=h=>(h%(o*2)+o*3)%(o*2)-o;e.uniforms.uWindOffset.value.set(c(e.uniforms.uWindOffset.value.x+s*t),c(e.uniforms.uWindOffset.value.y+r*t)),this.syncRainSlant(),this.camera.getWorldDirection(this.rainCameraDirection);const l=Math.abs(this.rainCameraDirection.y);if(Math.abs(l-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=l;const h=Gv+(1-Gv)*(1-l),u=Vv+(1-Vv)*(1-l);e.uniforms.uUvSquash.value=u,e.uniforms.uPixelSize.value=Hv*h*(.5+.5*u)}this.updateRainSplashes(t)}updateRainSplashes(t){const e=this.rainSplashSystem;if(!e||t<=0)return;const{positions:i,life:n,duration:s,lifeAttribute:r}=e,o=r.array;for(let c=0,l=0;c<i.length;c+=3,l++){if(n[l]+=t,n[l]>=s[l]){const h=Math.random()*Math.PI*2,u=Math.sqrt(Math.random())*Cc;i[c]=Math.cos(h)*u,i[c+2]=Math.sin(h)*u,s[l]=Xv(Nv,kv),n[l]=0}o[l]=n[l]/s[l]}e.points.geometry.attributes.position.needsUpdate=!0,r.needsUpdate=!0}setLightning(t){this.lightningFlashes=t}updateLightning(t){let e,i=0;if(this.lightningArmed)for(const c of this.lightningFlashes){if(c.t>t)break;const l=Ci.brightnessAt(c,t);l>i&&(e=c,i=l)}const n=e?Math.min(1,Math.max(.1,(gD/e.distanceM)**2)):0,s=i*n*(e?.cloudToGround?1:.6);if(s===this.lightningLevel&&!e?.cloudToGround)return;if(this.lightningLevel=s,this.scene.fog){const c=this.scene.fog,l=s*Lf*this.relativeScale/Math.PI;c.color.setRGB(this.airlight[0]+Ss.r*l,this.airlight[1]+Ss.g*l,this.airlight[2]+Ss.b*l)}const r=this.skyMesh?.material?.color;if(r){const c=s*vD;r.setRGB(1+c*Ss.r,1+c*Ss.g,1+c*Ss.b)}if(this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor),this.lightningLight.intensity=s*Lf*this.relativeScale,e){const{x:c,y:l,z:h}=Xe(25,e.azimuthDeg,pn);this.lightningLight.position.set(c,l,h)}this.lightningBolt||(this.lightningBolt=new Pr(pn*.95),this.celestialGroup.add(this.lightningBolt.object));const o=this.weather.cloudBaseM??1500;this.lightningBolt.set(e,i,o),this.render()}buildCompassLabels(){this.compassSprites=XR.map(t=>{const e=Na.point(t,this.compassPoints),i=new Yh({map:TD(e),depthTest:!1,fog:!1}),n=new Mc(i),{x:s,y:r,z:o}=Xe(0,t,Av);return n.position.set(s,r,o),n.scale.set(Dh,Dh,1),n.renderOrder=$R,n.layers.set(bf),n.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(n),n}),this.updateCompassScale()}updateCompassScale(){const t=this.camera.fov*Math.PI/360,e=Tv*Math.PI/360,i=Dh*Math.tan(t)/Math.tan(e);for(const n of this.compassSprites)n.scale.set(i,i,1)}disposeCompassLabels(){for(const t of this.compassSprites)t.removeFromParent(),t.material.map?.dispose(),t.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const t of this.starTiers)this.disposeMesh(t.points);this.starTiers=[]}disposeMesh(t){if(!t)return;t.removeFromParent(),"geometry"in t&&t.geometry.dispose();const e=t.material;for(const i of Array.isArray(e)?e:[e]){const n=i.map;n&&n.dispose(),i.dispose()}}}const Ei=Math.PI/180;function ir(a,t,e){return Math.max(t,Math.min(e,a))}function Xv(a,t){return a+Math.random()*(t-a)}function Ih(a,t){return(a%(t*2)+t*3)%(t*2)-t}let Ch,Ph;function yD(a){switch(a){case"snow":return xD();case"hail":return bD()}}function xD(){if(Ch)return Ch;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/2);return i.addColorStop(0,"rgba(255,255,255,0.95)"),i.addColorStop(.5,"rgba(255,255,255,0.55)"),i.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=i,e.fillRect(0,0,a,a),Ch=new pr(t),Ch}function bD(){if(Ph)return Ph;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/2);return i.addColorStop(0,"rgba(255,255,255,1)"),i.addColorStop(.55,"rgba(255,255,255,0.95)"),i.addColorStop(.8,"rgba(255,255,255,0.4)"),i.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=i,e.fillRect(0,0,a,a),Ph=new pr(t),Ph}let Oh;function SD(){if(Oh)return Oh;const a=64,t=document.createElement("canvas");t.width=a,t.height=a;const e=t.getContext("2d"),i=e.createRadialGradient(a/2,a/2,0,a/2,a/2,a/2);return i.addColorStop(0,"rgba(255,255,255,0)"),i.addColorStop(.4,"rgba(255,255,255,0)"),i.addColorStop(.6,"rgba(255,255,255,0.9)"),i.addColorStop(.8,"rgba(255,255,255,0.25)"),i.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=i,e.fillRect(0,0,a,a),Oh=new pr(t),Oh}const wD=`
8695
8695
  uniform float uMaxSize;
8696
8696
  uniform float uScale;
8697
8697
  attribute float aLife;
@@ -8757,6 +8757,6 @@ void main() {
8757
8757
  gl_FragColor = vec4(color, tex.a * uOpacity * (1.0 - blur * 0.5));
8758
8758
  }
8759
8759
  `;function Yv(a){const e=document.createElement("canvas");e.width=128,e.height=128;const i=e.getContext("2d"),n=128/2-2,s=128/2,r=128/2,o="#010101",c="#f4f1e2";i.fillStyle=o,i.beginPath(),i.arc(s,r,n,0,Math.PI*2),i.fill();const l=ir(a.illuminatedFraction,0,1),h=a.phaseFraction<.5,u=n*Math.abs(1-2*l),d=l<.5;return i.save(),i.beginPath(),i.arc(s,r,n,0,Math.PI*2),i.clip(),i.fillStyle=c,i.beginPath(),h?(i.arc(s,r,n,-Math.PI/2,Math.PI/2,!1),i.ellipse(s,r,u,n,0,Math.PI/2,-Math.PI/2,d)):(i.arc(s,r,n,Math.PI/2,-Math.PI/2,!1),i.ellipse(s,r,u,n,0,-Math.PI/2,Math.PI/2,d)),i.fill(),i.restore(),new pr(e)}function TD(a){const t=document.createElement("canvas");t.width=128,t.height=128;const e=t.getContext("2d");return e.fillStyle="rgba(0, 0, 0, 0.55)",e.beginPath(),e.arc(64,64,60,0,Math.PI*2),e.fill(),e.fillStyle="#ffffff",e.font="bold 52px sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillText(a,64,68),new pr(t)}function Nf(a){let t=a;return function(){t|=0,t=t+1831565813|0;let i=Math.imul(t^t>>>15,1|t);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}class Wu{constructor(t,e){this.source=t,this.create=e}scene;wanted;pumping=!1;disposed=!1;static PATIENCE_FRAMES=600;static SCENE_WIDTH_PX=320;paint(t,e){this.disposed||(this.wanted={t,canvas:e},this.pumping||this.pump())}recordingChanged(t){this.scene&&(this.scene.sightingData=t)}dispose(){this.disposed=!0,this.scene?.remove(),this.scene=void 0}ensureScene(){if(this.scene)return this.scene;const t=this.create();return t.setAttribute("max-pixel-ratio","1"),Object.assign(t.style,{position:"fixed",left:"-10000px",top:"0",width:`${Wu.SCENE_WIDTH_PX}px`,visibility:"hidden",pointerEvents:"none"}),document.body.appendChild(t),t.documentUrl=this.source.documentUrl,t.accountInTheRound=this.source.accountInTheRound,t.sightingData=this.source.sightingData,this.scene=t,t}async pump(){this.pumping=!0;try{for(;this.wanted&&!this.disposed;){const{t,canvas:e}=this.wanted;this.wanted=void 0;const i=this.ensureScene();i.interpretation!==this.source.interpretation&&(i.interpretation=this.source.interpretation),i.compareAccount!==this.source.compareAccount&&(i.compareAccount=this.source.compareAccount),i.showAt(t);for(let n=0;n<Wu.PATIENCE_FRAMES&&!this.wanted&&!this.disposed&&(await new Promise(s=>requestAnimationFrame(()=>s())),!this.wanted);n++)if(i.snapshotTo(e)){e.dataset.ready="true";break}}}finally{this.pumping=!1}}}const kf=7.5,Ff=9;class _s{static cache=new Map;static load(t){let e=_s.cache.get(t);return e||(e=fetch(t).then(i=>i.arrayBuffer()).then(i=>_s.parse(i)),_s.cache.set(t,e)),e}static upTo(t,e){const i=t.filter((r,o)=>o===0||t[o-1].magnitudeLimit<e);if(i.length<=1)return _s.load(t[0].url);const n=i.map(r=>r.url).join(`
8760
- `);let s=_s.cache.get(n);return s||(s=Promise.all(i.map(r=>_s.load(r.url))).then(r=>r.reduce((o,c)=>_s.concat(o,c))),_s.cache.set(n,s)),s}static parse(t){const e=t.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),i=e*Float32Array.BYTES_PER_ELEMENT;return{count:e,ra:new Float32Array(t,0*i,e),dec:new Float32Array(t,1*i,e),mag:new Float32Array(t,2*i,e),ci:new Float32Array(t,3*i,e)}}static concat(t,e){const i=(n,s)=>{const r=new Float32Array(n.length+s.length);return r.set(n,0),r.set(s,n.length),r};return{count:t.count+e.count,ra:i(t.ra,e.ra),dec:i(t.dec,e.dec),mag:i(t.mag,e.mag),ci:i(t.ci,e.ci)}}}class Ie{constructor(t){if(this.heights=t,t.length!==Ie.WIDTH*Ie.HEIGHT)throw new Error(`a lunar relief has ${Ie.WIDTH*Ie.HEIGHT} samples, not ${t.length}`)}static SAMPLES_PER_DEGREE=16;static WIDTH=360*Ie.SAMPLES_PER_DEGREE;static HEIGHT=180*Ie.SAMPLES_PER_DEGREE;static UNIT_KM=.1;static REFERENCE_RADIUS_KM=1737.4;static BAND_FROM_DEG=74;static BAND_TO_DEG=106;heightKm(t,e){const i=Ie.SAMPLES_PER_DEGREE,n=(e%360+360)%360*i-.5,s=(90-t)*i-.5,r=Math.floor(n),o=Math.floor(s),c=n-r,l=s-o,h=(f,p)=>{const v=(f%Ie.WIDTH+Ie.WIDTH)%Ie.WIDTH,m=Math.min(Ie.HEIGHT-1,Math.max(0,p));return this.heights[m*Ie.WIDTH+v]},u=h(r,o)*(1-c)+h(r+1,o)*c,d=h(r,o+1)*(1-c)+h(r+1,o+1)*c;return(u*(1-l)+d*l)*Ie.UNIT_KM}static inBand(t,e){const i=Math.PI/180,n=Math.acos(Math.cos(t*i)*Math.cos(e*i))*180/Math.PI;return n>=Ie.BAND_FROM_DEG&&n<=Ie.BAND_TO_DEG}static withBump(t,e,i,n=.4){const s=new Int8Array(Ie.WIDTH*Ie.HEIGHT),r=Ie.SAMPLES_PER_DEGREE,o=Math.ceil(n*r),c=Math.floor(e*r),l=Math.floor((90-t)*r);for(let h=-o;h<=o;h++)for(let u=-o;u<=o;u++)Math.hypot(u,h)<=o&&(s[(l+h)*Ie.WIDTH+(c+u+Ie.WIDTH)%Ie.WIDTH]=Math.round(i/Ie.UNIT_KM));return new Ie(s)}static smooth(){return new Ie(new Int8Array(Ie.WIDTH*Ie.HEIGHT))}}class Vn{static SAMPLES=5760;static SEARCH_FROM_DEG=87;static SEARCH_TO_DEG=90.2;static SEARCH_STEP_DEG=.0625;static profile(t,e,i,n=Vn.SAMPLES){const{s,u:r,w:o,distanceKm:c}=Vn.frame(t,e),l=Math.PI/180,h=new Float32Array(n),u=Ie.REFERENCE_RADIUS_KM;for(let d=0;d<n;d++){const f=d/n*2*Math.PI,p=Math.cos(f),v=Math.sin(f),m=p*r[0]+v*o[0],g=p*r[1]+v*o[1],b=p*r[2]+v*o[2];let S=0;for(let M=Vn.SEARCH_FROM_DEG;M<=Vn.SEARCH_TO_DEG;M+=Vn.SEARCH_STEP_DEG){const x=Math.cos(M*l),_=Math.sin(M*l),E=x*s[0]+_*m,y=x*s[1]+_*g,T=x*s[2]+_*b,I=Math.asin(Math.max(-1,Math.min(1,T)))/l,C=Math.atan2(y,E)/l,P=u+i.heightKm(I,C),B=Math.atan2(P*_,c-P*x);B>S&&(S=B)}h[d]=S/l}return{radiusDeg:h,meanRadiusDeg:Math.asin(u/c)/l}}static frame(t,e){const i=new qr(e.lat,e.lng,e.elevationM),n=ur(t),s=np(t,i,!1),r=new ge(s.x-n.x,s.y-n.y,s.z-n.z,n.t),o=Math.hypot(r.x,r.y,r.z)*Vn.AU_KM,c=Vn.bodyFixed(t),l=c(r),h=Math.hypot(l[0],l[1],l[2]),u=[l[0]/h,l[1]/h,l[2]/h],d=h4(t,i),f=cm(d),p=cr(d,new ge(-r.x,-r.y,-r.z,n.t)),v=Math.asin(p.z/Math.hypot(p.x,p.y,p.z)),m=Math.atan2(-p.y,p.x),g=new ge(-Math.sin(v)*Math.cos(m),Math.sin(v)*Math.sin(m),Math.cos(v),n.t),b=new ge(-Math.sin(m),-Math.cos(m),0,n.t);return{s:u,u:c(cr(f,g)),w:c(cr(f,b)),distanceKm:o}}static surfacePoint(t,e,i,n){const{s,u:r,w:o}=Vn.frame(t,e),c=Math.PI/180,l=[0,1,2].map(u=>Math.cos(i*c)*r[u]+Math.sin(i*c)*o[u]),h=[0,1,2].map(u=>Math.cos(n*c)*s[u]+Math.sin(n*c)*l[u]);return{latDeg:Math.asin(h[2])/c,lonDeg:Math.atan2(h[1],h[0])/c}}static radiusAt(t,e){const i=t.radiusDeg.length,n=(e/360*i%i+i)%i,s=Math.floor(n),r=n-s;return t.radiusDeg[s]*(1-r)+t.radiusDeg[(s+1)%i]*r}static uncoveredFraction(t,e,i){const n=t.radiusDeg.length,s=i.upDeg*i.upDeg+i.rightDeg*i.rightDeg;let r=0;for(let o=0;o<n;o++){const c=o/n*2*Math.PI,l=Math.cos(c),h=Math.sin(c),u=l*i.upDeg+h*i.rightDeg,d=u*u-s+e*e;if(d<=0)continue;const f=Math.sqrt(d),p=u+f;if(p<=0)continue;const v=Math.max(0,u-f),m=Math.max(v,t.radiusDeg[o]);p>m&&(r+=.5*(p*p-m*m))}return Math.min(1,Math.max(0,r*(2*Math.PI/n)/(Math.PI*e*e)))}static AU_KM=1495978707e-1;static bodyFixed(t){const e=A4(ut.Moon,t),i=Math.PI/180,n=e.ra*15*i,s=e.dec*i,r=e.spin*i,o=(l,[h,u,d])=>[Math.cos(l)*h+Math.sin(l)*u,-Math.sin(l)*h+Math.cos(l)*u,d],c=(l,[h,u,d])=>[h,Math.cos(l)*u+Math.sin(l)*d,-Math.sin(l)*u+Math.cos(l)*d];return l=>o(r,c(Math.PI/2-s,o(Math.PI/2+n,[l.x,l.y,l.z])))}static subObserverPoint(t,e){const i=new qr(e.lat,e.lng,e.elevationM),n=ur(t),s=np(t,i,!1),r=Vn.bodyFixed(t)(new ge(s.x-n.x,s.y-n.y,s.z-n.z,n.t)),o=Math.hypot(r[0],r[1],r[2]);return{latDeg:Math.asin(r[2]/o)*180/Math.PI,lonDeg:Math.atan2(r[1],r[0])*180/Math.PI}}}class Qc{static cache=new Map;static load(t){let e=Qc.cache.get(t);return e||(e=Qc.fetchRelief(t).catch(()=>{}),Qc.cache.set(t,e)),e}static async fetchRelief(t){const e=await fetch(t);if(!e.ok)return;let i=new Uint8Array(await e.arrayBuffer());if(i[0]===31&&i[1]===139){if(typeof DecompressionStream>"u")return;const n=new Blob([i]).stream().pipeThrough(new DecompressionStream("gzip"));i=new Uint8Array(await new Response(n).arrayBuffer())}return new Ie(new Int8Array(i.buffer,i.byteOffset,i.length))}}class Xu{constructor(t){this.names=t}body(t,e){return this.names?.bodies[t]??e}star(t){return this.names?.stars[t.name]??t.name}comet(t){return this.names?.comets[t.id]??t.name}nova(t){return this.names?.novae[t.id]??t.name}satelliteClass(t){return this.names?.satelliteClasses[t.id]??t.name}shower(t){return this.names?.showers[t.id]??t.name}lightRig(t){return this.names?.lightRigs[t.id]??t.name}instrument(t){return this.names?.instruments[t.id]??t.name}decorKind(t,e){return this.names?.decorKinds[t]??e}point(t){return Na.point(t,this.names?.compassPoints)}towards(t){return Na.towards(t,this.names)}}const RD=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,DD=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,ID=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,CD=20,PD=1;class OD{context;buffers=new Map;ambientSource;ambientGain;ambientKey="none";ambientToken=0;ambientVolume=0;windSource;windGain;windActive=!1;windToken=0;windVolume=0;paused=!0;requested={type:"none",intensity:0,windSpeed:0};level=1;master;output(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",t);return}}Oa.unlock(this.context)}setAmbient(t,e,i){if(this.requested={type:t,intensity:e,windSpeed:i},!this.context)return;this.paused&&(t="none",e=0,i=0);const n=t==="rain"||t==="hail"?t:"none";if(this.ambientVolume=n==="hail"?Math.min(1,e*1.3+.2):n==="rain"?e:0,n!==this.ambientKey){this.ambientKey=n;const r=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,n!=="none"&&this.startLoop(RD,this.ambientVolume).then(o=>this.applyIfCurrent(o,r,()=>this.ambientToken,c=>{this.ambientSource=c?.source,this.ambientGain=c?.gain,c&&(c.gain.gain.value=this.ambientVolume)}))}else this.ambientGain&&(this.ambientGain.gain.value=this.ambientVolume);this.windVolume=Math.min(i/CD,1);const s=i>PD;if(s!==this.windActive){this.windActive=s;const r=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,s&&this.startLoop(DD,this.windVolume).then(o=>this.applyIfCurrent(o,r,()=>this.windToken,c=>{this.windSource=c?.source,this.windGain=c?.gain,c&&(c.gain.gain.value=this.windVolume)}))}else this.windGain&&(this.windGain.gain.value=this.windVolume)}setPaused(t){if(t===this.paused)return;this.paused=t;const{type:e,intensity:i,windSpeed:n}=this.requested;this.setAmbient(e,i,n)}playThunder(){!this.context||this.paused||this.playOneShot(ID,.9)}dispose(){this.ambientToken++,this.windToken++,this.stopSource(this.ambientSource,this.ambientGain),this.stopSource(this.windSource,this.windGain),this.ambientSource=void 0,this.ambientGain=void 0,this.windSource=void 0,this.windGain=void 0,this.context?.close(),this.context=void 0,this.master=void 0,this.buffers.clear()}applyIfCurrent(t,e,i,n){if(e!==i()){t?.source.stop();return}n(t)}async startLoop(t,e){const i=this.context;if(i)try{const n=await this.getBuffer(t),s=i.createBufferSource();s.buffer=n,s.loop=!0;const r=i.createGain();return r.gain.value=e,s.connect(r).connect(this.output(i)),s.start(),{source:s,gain:r}}catch(n){console.warn("Weather ambient sound failed to load, staying silent:",n);return}}async playOneShot(t,e){const i=this.context;if(i)try{const n=await this.getBuffer(t),s=i.createBufferSource();s.buffer=n;const r=i.createGain();r.gain.value=e,s.connect(r).connect(this.output(i)),s.start()}catch(n){console.warn("Thunder sound failed to load:",n)}}async getBuffer(t){const e=this.context;if(!e)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(t);return i||(i=fetch(t).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${t}`);return n.arrayBuffer()}).then(n=>e.decodeAudioData(n)),this.buffers.set(t,i)),i}stopSource(t,e){try{t?.stop()}catch{}t?.disconnect(),e?.disconnect()}}class nr{constructor(t){this.elements=t;const{eccentricity:e,perihelionAu:i}=t,[n,s]=this.perifocalAxes(),r=Math.sqrt(nr.SUN_GM_AU3_PER_DAY2*(1+e)/i);this.perihelionPosition=this.scale(n,i),this.perihelionVelocity=this.scale(s,r),this.inverseSemiMajorAxis=(1-e)/i}static SUN_GM_AU3_PER_DAY2=.0002959122082855911;static MAX_ITERATIONS=200;perihelionPosition;perihelionVelocity;inverseSemiMajorAxis;positionAt(t){const e=t-this.elements.perihelionJd,i=this.universalAnomaly(e),n=this.inverseSemiMajorAxis*i*i,s=this.elements.perihelionAu,r=1-i*i/s*nr.stumpffC(n),o=e-i*i*i/Math.sqrt(nr.SUN_GM_AU3_PER_DAY2)*nr.stumpffS(n);return{x:r*this.perihelionPosition.x+o*this.perihelionVelocity.x,y:r*this.perihelionPosition.y+o*this.perihelionVelocity.y,z:r*this.perihelionPosition.z+o*this.perihelionVelocity.z}}heliocentricDistanceAt(t){const e=this.positionAt(t);return Math.hypot(e.x,e.y,e.z)}universalAnomaly(t){if(t===0)return 0;const e=Math.sign(t),i=Math.sqrt(nr.SUN_GM_AU3_PER_DAY2)*Math.abs(t),n=o=>{const c=this.inverseSemiMajorAxis*o*o,l=this.elements.perihelionAu;return(1-this.inverseSemiMajorAxis*l)*o*o*o*nr.stumpffS(c)+l*o};let s=Math.max(1,i/this.elements.perihelionAu);for(;n(s)<i;)s*=2;let r=0;for(let o=0;o<nr.MAX_ITERATIONS&&s-r>1e-13*Math.max(1,s);o++){const c=(r+s)/2;n(c)<i?r=c:s=c}return e*(r+s)/2}perifocalAxes(){const t=this.elements.ascendingNodeDeg*Math.PI/180,e=this.elements.argumentOfPerihelionDeg*Math.PI/180,i=this.elements.inclinationDeg*Math.PI/180,n=Math.cos(t),s=Math.sin(t),r=Math.cos(e),o=Math.sin(e),c=Math.cos(i),l=Math.sin(i);return[{x:n*r-s*o*c,y:s*r+n*o*c,z:o*l},{x:-n*o-s*r*c,y:-s*o+n*r*c,z:r*l}]}scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}static stumpffC(t){if(Math.abs(t)<1e-6)return 1/2-t/24+t*t/720;if(t>0)return(1-Math.cos(Math.sqrt(t)))/t;const e=Math.sqrt(-t);return(Math.cosh(e)-1)/-t}static stumpffS(t){if(Math.abs(t)<1e-6)return 1/6-t/120+t*t/5040;if(t>0){const i=Math.sqrt(t);return(i-Math.sin(i))/(i*i*i)}const e=Math.sqrt(-t);return(Math.sinh(e)-e)/(e*e*e)}}const cy=[{id:"halley-1910",designation:"1P/Halley",name:"Halley's Comet",orbit:{eccentricity:.9672960498922706,perihelionAu:.5872100477652511,inclinationDeg:162.218798367122,ascendingNodeDeg:58.56208298700436,argumentOfPerihelionDeg:111.7366940639061,perihelionJd:2.4187816784171113e6},peakMagnitude:0,peakOn:"1910-05-20",absoluteMagnitude:4.72,activityExponent:4,tailLengthDeg:100,tailLengthAu:.1638,note:"Passed 0.15 au from Earth on 20 May 1910, and the Earth crossed the outer tail the day before — the apparition that produced a genuine public panic."},{id:"brooks-1911",designation:"C/1911 O1",name:"Comet Brooks",orbit:{eccentricity:.9876404970138669,perihelionAu:.4898172916113738,inclinationDeg:33.34043866978714,ascendingNodeDeg:293.7022074981857,argumentOfPerihelionDeg:153.5578007321686,perihelionJd:2.4193378856140426e6},peakMagnitude:2,peakOn:"1911-10-25",absoluteMagnitude:5.59,activityExponent:4},{id:"skjellerup-maristany-1927",designation:"C/1927 X1",name:"Comet Skjellerup-Maristany",orbit:{eccentricity:.999839726885059,perihelionAu:.1761569619628186,inclinationDeg:85.1125991950808,ascendingNodeDeg:78.24360172472711,argumentOfPerihelionDeg:47.15877857390136,perihelionJd:2.4252326808989984e6},peakMagnitude:-6,peakOn:"1927-12-15",absoluteMagnitude:1.19,activityExponent:4,note:"One of the few comets of the century seen in full daylight."},{id:"de-kock-paraskevopoulos-1941",designation:"C/1941 B2",name:"Comet de Kock-Paraskevopoulos",orbit:{eccentricity:.9991026715181549,perihelionAu:.7900329662827822,inclinationDeg:168.2039226531089,ascendingNodeDeg:43.10609347214336,argumentOfPerihelionDeg:268.6990344196369,perihelionJd:2430022157765061e-9},peakMagnitude:2,peakOn:"1941-02-05",absoluteMagnitude:5.01,activityExponent:4},{id:"southern-1947",designation:"C/1947 X1",name:"the Southern Comet",orbit:{eccentricity:.9998424430916737,perihelionAu:.1100045955093761,inclinationDeg:138.5113919632757,ascendingNodeDeg:337.3114969669252,argumentOfPerihelionDeg:196.1820121395961,perihelionJd:2.4325220864727003e6},peakMagnitude:-3,peakOn:"1947-12-08",absoluteMagnitude:3.01,activityExponent:4,note:"A bright southern-hemisphere comet of December 1947, the month the American sighting wave of that year was still being argued over."},{id:"eclipse-1948",designation:"C/1948 V1",name:"the Eclipse Comet",orbit:{eccentricity:.9999130678247334,perihelionAu:.1354437057263306,inclinationDeg:23.11668597152911,ascendingNodeDeg:211.0454985994762,argumentOfPerihelionDeg:107.2474157073104,perihelionJd:2.4328519265329437e6},peakMagnitude:-2,peakOn:"1948-11-01",absoluteMagnitude:4.79,activityExponent:4,note:"Found during the total solar eclipse of 1 November 1948, which is how a comet that bright had gone unnoticed: it had been hidden in the Sun's glare."},{id:"arend-roland-1957",designation:"C/1956 R1",name:"Comet Arend-Roland",orbit:{eccentricity:1.0002570255357,perihelionAu:.3160532361485914,inclinationDeg:119.9440863251822,ascendingNodeDeg:215.8548157717755,argumentOfPerihelionDeg:308.775920364167,perihelionJd:2.4359365327396123e6},peakMagnitude:.5,peakOn:"1957-04-25",absoluteMagnitude:3.96,activityExponent:4,note:"Showed a spike pointing back TOWARD the Sun in late April 1957 — a real anti-tail, and much reported at the time."},{id:"mrkos-1957",designation:"C/1957 P1",name:"Comet Mrkos",orbit:{eccentricity:.9993521583504134,perihelionAu:.3549238508212375,inclinationDeg:93.9433042053929,ascendingNodeDeg:68.32441518619923,argumentOfPerihelionDeg:40.31823675802871,perihelionJd:243605193752228e-8},peakMagnitude:1,peakOn:"1957-08-05",absoluteMagnitude:5.07,activityExponent:4,note:"The second bright naked-eye comet of 1957, four months after Arend-Roland."},{id:"seki-lines-1962",designation:"C/1962 C1",name:"Comet Seki-Lines",orbit:{eccentricity:1.000003791331562,perihelionAu:.03139689112215131,inclinationDeg:65.01487186102287,ascendingNodeDeg:304.6776602796538,argumentOfPerihelionDeg:11.47295326312573,perihelionJd:2437756163010178e-9},peakMagnitude:-2.5,peakOn:"1962-04-01",absoluteMagnitude:9.3,activityExponent:4},{id:"ikeya-seki-1965",designation:"C/1965 S1",name:"Comet Ikeya-Seki",orbit:{eccentricity:.9999141178248997,perihelionAu:.007785966366889336,inclinationDeg:141.8642315267051,ascendingNodeDeg:346.9951764632611,argumentOfPerihelionDeg:69.04909813996062,perihelionJd:2.4390546837018197e6},peakMagnitude:-10,peakOn:"1965-10-21",alsoRecordedMagnitude:2,alsoRecordedOn:"1965-10-30",absoluteMagnitude:5.26,activityExponent:4.002,tailLengthDeg:25,tailLengthAu:.5048,note:"A sungrazer that passed 450 000 km above the Sun's surface and was seen beside it in broad daylight — the brightest comet of the twentieth century. It then stood in the dawn sky for a fortnight with a tail some 25 degrees long, which is the second magnitude recorded here."},{id:"bennett-1970",designation:"C/1969 Y1",name:"Comet Bennett",orbit:{eccentricity:.9962979048768408,perihelionAu:.5376209981502136,inclinationDeg:90.03975717147327,ascendingNodeDeg:224.6576652531314,argumentOfPerihelionDeg:354.1494209173161,perihelionJd:2.4406655455270996e6},peakMagnitude:0,peakOn:"1970-03-26",absoluteMagnitude:3.36,activityExponent:4},{id:"white-ortiz-bolelli-1970",designation:"C/1970 K1",name:"Comet White-Ortiz-Bolelli",orbit:{eccentricity:.9999488875801225,perihelionAu:.00884411465256722,inclinationDeg:138.9520738221631,ascendingNodeDeg:336.8194095816687,argumentOfPerihelionDeg:61.10224765396615,perihelionJd:2.4407209807728203e6},peakMagnitude:1,peakOn:"1970-05-22",absoluteMagnitude:4.35,activityExponent:4},{id:"kohoutek-1973",designation:"C/1973 E1",name:"Comet Kohoutek",orbit:{eccentricity:1.000007152175185,perihelionAu:.1424250377812859,inclinationDeg:14.30414984159355,ascendingNodeDeg:258.4893339663974,argumentOfPerihelionDeg:37.79772760699667,perihelionJd:2442044930687027e-9},peakMagnitude:0,peakOn:"1974-01-05",absoluteMagnitude:4.89,activityExponent:4,note:"Announced in advance as the comet of the century and remembered for disappointing: it was an ordinary naked-eye object, not the spectacle the press had promised."},{id:"west-1976",designation:"C/1975 V1",name:"Comet West",orbit:{eccentricity:1.000017859625611,perihelionAu:.1966006188461085,inclinationDeg:43.07319920579427,ascendingNodeDeg:118.9189245655447,argumentOfPerihelionDeg:358.4315101259072,perihelionJd:2442833721841768e-9},peakMagnitude:-3,peakOn:"1976-02-25",absoluteMagnitude:4.41,activityExponent:4,tailLengthDeg:30,tailLengthAu:.4325,note:"Broke into four pieces at perihelion. Barely reported at the time — the press had been burned by Kohoutek two years earlier."},{id:"iras-araki-alcock-1983",designation:"C/1983 H1",name:"Comet IRAS-Araki-Alcock",orbit:{eccentricity:.9898409731606003,perihelionAu:.9913412593828502,inclinationDeg:73.25000846947029,ascendingNodeDeg:49.10235754476374,argumentOfPerihelionDeg:192.8506176754439,perihelionJd:2.4454757545235856e6},peakMagnitude:1.7,peakOn:"1983-05-11",absoluteMagnitude:9.04,activityExponent:4,note:"Passed 0.031 au from Earth on 11 May 1983, one of the closest cometary approaches on record: it crossed a quarter of the sky in a night, which no other comet in this list did."},{id:"halley-1986",designation:"1P/Halley",name:"Halley's Comet",orbit:{eccentricity:.9672792271749998,perihelionAu:.5871034488173393,inclinationDeg:162.2422242700916,ascendingNodeDeg:58.85993640671803,argumentOfPerihelionDeg:111.8655480539208,perihelionJd:2.4464709589610207e6},peakMagnitude:2.1,peakOn:"1986-03-10",absoluteMagnitude:2.71,activityExponent:4,note:"The worst-placed return in two thousand years — famous, expected, and for most observers a faint smudge."},{id:"hyakutake-1996",designation:"C/1996 B2",name:"Comet Hyakutake",orbit:{eccentricity:.9997295133739305,perihelionAu:.2302272039470452,inclinationDeg:124.923592343765,ascendingNodeDeg:188.0454295899424,argumentOfPerihelionDeg:130.1724036582639,perihelionJd:2.4502048946148166e6},peakMagnitude:0,peakOn:"1996-03-25",absoluteMagnitude:4.75,activityExponent:4,tailLengthDeg:80,tailLengthAu:1,note:"Passed 0.10 au from Earth in March 1996, five weeks BEFORE perihelion, with a tail measured at some 80 degrees — the longest of the modern era."},{id:"hale-bopp-1997",designation:"C/1995 O1",name:"Comet Hale-Bopp",orbit:{eccentricity:.9951314746156615,perihelionAu:.9141695067003724,inclinationDeg:89.43017155012492,ascendingNodeDeg:282.470602866853,argumentOfPerihelionDeg:130.5872524854533,perihelionJd:2450539633099368e-9},peakMagnitude:-.8,peakOn:"1997-04-01",absoluteMagnitude:-1.06,activityExponent:4,tailLengthDeg:20,tailLengthAu:.9938,note:"Visible to the naked eye for about eighteen months, longer than any comet on record."},{id:"mcnaught-2007",designation:"C/2006 P1",name:"Comet McNaught",orbit:{eccentricity:1.00001811603225,perihelionAu:.1707325614080681,inclinationDeg:77.83726446452654,ascendingNodeDeg:267.4149080498975,argumentOfPerihelionDeg:155.9756130642756,perihelionJd:2454113298753579e-9},peakMagnitude:-5.5,peakOn:"2007-01-13",absoluteMagnitude:2.53,activityExponent:4,tailLengthDeg:35,tailLengthAu:.5009,note:"The brightest comet since Ikeya-Seki, seen in daylight beside the Sun in January 2007."},{id:"lovejoy-2011",designation:"C/2011 W3",name:"Comet Lovejoy",orbit:{eccentricity:.999915056276912,perihelionAu:.005553783989325053,inclinationDeg:134.3558712062691,ascendingNodeDeg:326.3693517957772,argumentOfPerihelionDeg:53.50991655176601,perihelionJd:2455911511809431e-9},peakMagnitude:-3,peakOn:"2011-12-16",alsoRecordedMagnitude:1.5,alsoRecordedOn:"2011-12-22",absoluteMagnitude:3.51,activityExponent:1.194,note:"A sungrazer that was expected to be destroyed at perihelion and came out the other side, to stand in the southern dawn sky for the rest of December — which is the second magnitude recorded here."},{id:"panstarrs-2013",designation:"C/2011 L4",name:"Comet PANSTARRS",orbit:{eccentricity:1.000032542889696,perihelionAu:.301544229714915,inclinationDeg:84.2081978367921,ascendingNodeDeg:65.66588626213694,argumentOfPerihelionDeg:333.6516444379993,perihelionJd:2456361669960698e-9},peakMagnitude:1,peakOn:"2013-03-10",absoluteMagnitude:5.98,activityExponent:4},{id:"neowise-2020",designation:"C/2020 F3",name:"Comet NEOWISE",orbit:{eccentricity:.9991782081129224,perihelionAu:.2946512466331692,inclinationDeg:128.9375043020912,ascendingNodeDeg:61.01042991771634,argumentOfPerihelionDeg:37.2786526292898,perihelionJd:2.4590341788972816e6},peakMagnitude:.9,peakOn:"2020-07-08",absoluteMagnitude:5.79,activityExponent:4,tailLengthDeg:10,tailLengthAu:.1808,note:"The first comet since Hale-Bopp that ordinary observers in the northern hemisphere saw without being told where to look."},{id:"tsuchinshan-atlas-2024",designation:"C/2023 A3",name:"Comet Tsuchinshan-ATLAS",orbit:{eccentricity:1.000020192843226,perihelionAu:.3914228969475176,inclinationDeg:139.1105462619479,ascendingNodeDeg:21.55945689078845,argumentOfPerihelionDeg:308.4913086299446,perihelionJd:2460581242087108e-9},peakMagnitude:0,peakOn:"2024-10-14",absoluteMagnitude:3.97,activityExponent:4,tailLengthDeg:20,tailLengthAu:.1902,note:"Briefly reported far brighter around 9 October 2024, when it stood almost between the observer and the Sun and forward-scattered the light through its own dust — a geometry this catalog's brightness model does not attempt, so what is stored is the ordinary evening-sky peak a few days later."}];class LD{static WINDOW_DAYS=200;static TWILIGHT_ELONGATION_DEG=15;static LIGHT_SPEED_AU_PER_DAY=173.144632674;static orbits=new Map;static aroundDate(t){const e=this.julianDayOf(t);return cy.filter(i=>Math.abs(e-i.orbit.perihelionJd)<=this.WINDOW_DAYS)}static brightestAt(t,e){return this.aroundDate(t).map(i=>this.appearanceOf(i,t,e)).sort((i,n)=>i.magnitude-n.magnitude)[0]}static appearanceOf(t,e,i){const n=Ne(e),s=this.earthPositionAt(n),r=this.apparentPositionOf(t,2451545+n.tt,s),o=this.subtract(r,s),c=this.length(r),l=this.length(o),h=this.tailEndAt(t,r,s,c,n,e,i),u=this.horizontalOf(o,n,e,i);return{apparition:t,position:u,...h,heliocentricDistanceAu:c,earthDistanceAu:l,elongationDeg:this.angleBetween(o,this.subtract({x:0,y:0,z:0},s)),magnitude:this.magnitudeAt(t,c,l)}}static magnitudeAt(t,e,i){const n=t.absoluteMagnitude+5*Math.log10(i)+2.5*t.activityExponent*Math.log10(e);return Math.max(n,t.peakMagnitude)}static tailEndAt(t,e,i,n,s,r,o){if(t.tailLengthAu===void 0)return{};const c=1+t.tailLengthAu/n,l=this.subtract({x:e.x*c,y:e.y*c,z:e.z*c},i),h=this.subtract(e,i);return{tailEnd:this.horizontalOf(l,s,r,o),tailLengthDeg:this.angleBetween(h,l)}}static apparentPositionOf(t,e,i){const n=this.orbitOf(t);let s=n.positionAt(e);for(let r=0;r<2;r++){const o=this.length(this.subtract(s,i))/this.LIGHT_SPEED_AU_PER_DAY;s=n.positionAt(e-o)}return s}static horizontalOf(t,e,i,n){const s=cr(a4(),new ge(t.x,t.y,t.z,e)),r=cr(W2(e),s),o=np(e,new qr(n.lat,n.lng,n.elevationM),!0),c=new ge(r.x-o.x,r.y-o.y,r.z-o.z,e),l=fd(c);return um(l.ra,l.dec,i,n)}static earthPositionAt(t){return cr(r4(),Wr(ut.Earth,t))}static julianDayOf(t){return 2451545+Ne(t).tt}static orbitOf(t){const e=this.orbits.get(t.id);if(e)return e;const i=new nr(t.orbit);return this.orbits.set(t.id,i),i}static subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}static length(t){return Math.hypot(t.x,t.y,t.z)}static angleBetween(t,e){const i=(t.x*e.x+t.y*e.y+t.z*e.z)/(this.length(t)*this.length(e)||1);return Math.acos(Math.min(1,Math.max(-1,i)))*180/Math.PI}}const Uf=[{id:"sn-1006",kind:"supernova",designation:"SN 1006",name:"Supernova of 1006",raHours:15.03947,decDeg:-42.09694,peakMagnitude:-7.5,peakJd:2088620,startJd:2088620,lightCurve:[[0,-7.5],[29,-5.9],[60,-4.9],[106,-3.2],[166,-1.9],[258,-1],[350,.5],[364,.7],[411,1.2],[456,1.8],[484,2.5],[785.5,7]],source:"Winkler, Gupta & Long 2003 (peak); decline borrowed from SN 1572",note:"The brightest stellar event in recorded history, seen in daylight, low in the southern sky from Europe and the Near East. The decline is modelled, not recorded, and falls below the naked eye after about two years where the chronicles speak of three."},{id:"sn-1054",kind:"supernova",designation:"SN 1054",name:"Supernova of 1054",raHours:5.5755,decDeg:22.0175,peakMagnitude:-6,peakJd:2106216,startJd:2106216,lightCurve:[[0,-6],[23,-4],[642,6]],source:"Chinese chronicles (Song huiyao), via Stephenson & Green 2002",note:"The explosion that left the Crab Nebula. Its magnitude is an estimate; the two durations are recorded."},{id:"sn-1181",kind:"supernova",designation:"SN 1181",name:"Supernova of 1181",raHours:.88645,decDeg:67.50067,peakMagnitude:0,peakJd:2152636,startJd:2152636,lightCurve:[[0,0],[185,6]],source:"Chinese and Japanese chronicles, via Stephenson & Green 2002",note:"Circumpolar from Europe and China, so never set. Its peak magnitude is uncertain by at least a magnitude."},{id:"sn-1572",kind:"supernova",designation:"SN 1572",name:"Tycho's Supernova",raHours:.42264,decDeg:64.14083,peakMagnitude:-4,peakJd:2295551,startJd:2295546,lightCurve:[[0,-3],[5,-4],[34,-2.4],[65,-1.4],[111,.3],[171,1.6],[263,2.5],[355,4],[369,4.2],[416,4.7],[461,5.3],[489,6]],source:"Tycho Brahe and contemporaries, reduced by Ruiz-Lapuente 2004",note:"Circumpolar from northern Europe. Tycho showed it had no parallax, so it was not in the air: a new star, beyond the Moon."},{id:"sn-1604",kind:"supernova",designation:"SN 1604",name:"Kepler's Supernova",raHours:17.51125,decDeg:-21.48733,peakMagnitude:-2.95,peakJd:2307210,startJd:2307191,lightCurve:[[0,.23],[3,-1.3],[6,-2.08],[9,-2.17],[19,-2.95],[27,-2.95],[32,-1.95],[36,-1.52],[86,.9],[96,.45],[103,1],[114,1.2],[118,1.55],[133,1.95],[137,2.3],[170,2.25],[185,2.25],[194,2.4],[197,2.9],[308,4.45],[324,4.45],[339,4.95],[364,4.7]],source:"Kepler, Fabricius, Maestlin and the Korean court astronomers, reduced by Ruiz-Lapuente 2017",note:"The last supernova in our Galaxy seen with the naked eye. It went behind the Sun from mid-November 1604 to January 1605, which is the gap in its record."},{id:"t-crb-1866",kind:"nova",designation:"T CrB",name:"Nova Coronae Borealis 1866",raHours:15.99171,decDeg:25.92017,peakMagnitude:2,peakJd:2402734,startJd:2402734,lightCurve:[[0,2],[1.5,3],[2.5,3.11],[6.5,5.18],[8.5,5.75],[10.5,6.85],[11.5,6.8],[12.5,7.5],[16,8.18],[32,9.27],[38,9.2],[40,8.95],[44,9.4],[48,9.07],[54,9.4],[58,9.21],[79,9.44],[107,9.26],[111,9.01],[115,8.21],[119,7.96],[159,7.51],[179,7.57],[183,7.97],[191,7.66],[199,8.2],[207,8.31],[211,8.83],[215,8.65],[223,8.97],[297,8.9],[345,9.25],[377,9.07],[425,9.3],[537,9.3]],source:"Recorded peak (Birmingham); curve borrowed from its 1946 eruption",note:"The first eruption of the recurrent nova T CrB to be seen. The decline is its 1946 one."},{id:"t-aur-1891",kind:"nova",designation:"T Aur",name:"Nova Aurigae 1891",raHours:5.53309,decDeg:30.44583,peakMagnitude:4.49,peakJd:2412083,startJd:2412079,lightCurve:[[0,5.28],[4,4.49],[24,4.58],[40,4.97],[52,4.95],[56,4.5],[60,4.9],[68,4.88],[72,5.25],[76,4.93],[84,5.44],[88,7.23],[96,8.85],[100,10.44]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"gk-per-1901",kind:"nova",designation:"GK Per",name:"Nova Persei 1901",raHours:3.52,decDeg:43.90431,peakMagnitude:.19,peakJd:24154395e-1,startJd:24154377e-1,lightCurve:[[0,2.7],[.8,.86],[1.8,.19],[2.3,.2],[5.8,1.78],[11.8,2.54],[12.8,2.98],[17.8,3.62],[18.8,3.35],[19.8,3.77],[20.8,3.59],[22.8,3.95],[24.8,3.82],[25.6,4.99],[25.9,4.89],[26.6,3.69],[27.6,3.94],[27.9,4.61],[28.6,5.28],[28.9,4.46],[29.9,3.8],[30.9,4.27],[31.6,5.21],[31.9,5.22],[32.9,3.88],[33.9,4.19],[34.6,4.85],[35.6,4.8],[36.6,4.23],[37.6,4.44],[38.9,4.15],[39.7,5.19],[40.6,5.39],[40.9,5.35],[41.9,4.01],[42.6,4.5],[42.9,4.49],[43.6,5.53],[44,5.23],[44.6,5.61],[44.9,5.5],[45.9,4.17],[46.9,4.69],[47.6,5.5],[48.6,5.59],[49.6,5.14],[49.9,4.48],[50.6,4.45],[50.9,4.55],[51.6,5.47],[52.6,5.74],[53.7,5.66],[55.7,4.41],[56.7,5.43],[58.7,5.81],[58.9,5.58],[59.7,5.64],[59.9,4.76],[60.9,4.26],[61.9,5.62],[62.7,5.85],[62.9,5.53],[63.7,5.8],[64.9,4.28],[65.6,5.33],[66.7,5.87],[66.9,5.56],[68.7,5.7],[68.9,5.3],[69.7,4.47],[70.7,5.65],[72.9,5.98],[73.9,5.71],[74.7,4.98],[74.9,4.46],[75.7,4.87],[76.9,6.05],[77.6,5.76],[78,6],[78.7,5.95],[80.7,4.98],[81.9,5.85],[82.7,6.02],[84.7,5.41],[84.9,5.08],[85.7,5.17],[85.9,5.6],[87,6.1],[88.8,6.2],[89.7,4.96],[89.9,4.93],[90.7,5.9],[91.9,6.32],[92.7,5.86],[93.1,6.24],[93.7,5.38],[93.9,6.2],[96.1,6.12],[97.1,6.37],[97.6,5.12],[98,5.85],[99.3,6.35],[101.3,6.12],[101.7,5.25],[102.3,4.95],[102.7,6.12],[103.2,5.83],[104.7,6.37],[105,6.13],[106,6.22],[106.7,4.88],[107.7,6.3],[108.1,6.4],[109,6],[109.7,5.16],[110,5.82],[112.1,5.89],[113.1,5.5],[115.7,5.8],[116,6.11],[118.7,5.68],[119,6.23],[119.7,5.85],[120,6.12],[121,4.62],[121.8,5.9],[123,5.48],[125,6.05],[126,5.89],[130.9,6.11],[146.1,6.02],[155.6,6.26],[180.4,6.09],[190.4,6.39],[245.5,6.87],[266.2,6.77],[301.1,7.16],[321.5,7.07],[346.5,7.87],[375.7,7.86],[385.8,8.09],[389.8,8.55],[406.1,8.33],[416.5,8.59],[445.9,8.62],[472.1,9.24],[565.9,9.74],[571,9.4],[589.8,9.76]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"Discovered on 21 February 1901 by Thomas Anderson in Edinburgh, and the brightest nova of the century until V603 Aql."},{id:"dn-gem-1912",kind:"nova",designation:"DN Gem",name:"Nova Geminorum 1912",raHours:6.9151,decDeg:32.14108,peakMagnitude:3.58,peakJd:241947675e-2,startJd:241947275e-2,lightCurve:[[0,11.7],[1,4.5],[4,3.58],[5,4.45],[5.5,5.32],[6,5.53],[6.5,5.11],[8,5.43],[8.5,5.16],[11,5.53],[11.5,5.13],[12,5.18],[13.75,4.5],[15.75,5.3],[18.75,6],[19.75,5.55],[26.75,6],[28.75,5.9],[31.75,6.6],[32.75,6.2],[33.75,6.5],[36.75,6.55],[39.75,6.2],[40.75,6.75],[41.75,7],[44.75,6.75],[52.75,6.75],[54.75,7.23],[58.25,7.5],[62.25,7.3],[64.25,7.47],[66.25,8.1],[70.25,7.5],[72.25,8.1],[78.25,7.55],[80.25,8.2],[86.25,7.2],[90.25,7.3],[92.25,7.8],[152.25,7.2],[160.25,7.4],[166.25,8.2],[168.25,8.2],[170.25,7.3],[180.25,7.4],[182.25,8],[186.25,7.5],[190.25,7.6],[192.25,8],[211.25,7.75],[227.25,8],[275.25,7.78],[315.25,8.6],[331.25,7.79],[339.25,8.27],[363.25,8.61],[443.25,8.93],[451.25,9.2],[535.25,10.3],[567.25,9.9],[615.25,10.8],[631.25,10.63],[647.25,10.88],[679.25,10.8],[695.25,11.07],[727.25,11]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v603-aql-1918",kind:"nova",designation:"V603 Aql",name:"Nova Aquilae 1918",raHours:18.81518,decDeg:.58414,peakMagnitude:-.5,peakJd:242175475e-2,startJd:242174875e-2,lightCurve:[[0,11.3],[2,10.5],[4,6.6],[4.5,1.04],[6,-.5],[6.5,.18],[10,1.1],[10.5,.95],[12.75,1.89],[21.75,3.07],[23.75,3.76],[29.75,3.16],[34.75,3.5],[36.75,3.86],[44.75,3.79],[48.75,4.43],[52.75,3.84],[56.75,3.95],[57.75,4.04],[58.75,4.49],[59.75,4.42],[60.75,4.69],[62.75,4.6],[63.75,4.11],[64.75,3.97],[68.75,4.18],[70.75,4.65],[71.75,4.51],[73.75,4.73],[75.75,4.44],[79.75,4.85],[83.75,4.43],[89.75,4.88],[92.75,4.86],[94.75,4.58],[96.75,4.92],[99.75,5.05],[163.25,5.45],[167.25,5.7],[179.25,5.48],[191.25,5.8],[203.25,5.5],[247.25,5.9],[251.25,6.25],[257.25,5.5],[265.25,6.13],[281.25,6.33],[345.25,6.3],[385.25,6.73],[393.25,6.43],[425.25,6.71],[433.25,6.56],[461.25,7.27],[525.25,7.6],[541.25,7.47],[637.25,8.3],[669.25,8.17],[717.25,8.55],[749.25,8.4],[765.25,8.68],[885.25,8.75],[949.25,9.4],[1013.25,9.19],[1141.25,9.57],[1269.25,9.48],[1333.25,9.95],[1653.25,9.94],[1781.25,10.28],[1909.25,10.34],[2037.25,10.1],[2101.25,10.46],[2165.25,10.51],[2357.25,10.3],[2549.25,10.77],[2741.25,10.46],[2869.25,10.83],[3125.25,10.71],[3317.25,11.22],[3381.25,10.91],[3637.25,11.42],[3829.25,10.96],[3893.25,11.65],[3957.25,11.63],[4085.25,11.14],[4213.25,11.48],[4277.25,10.7],[4341.25,11.42],[4405.25,11.47],[4469.25,11.06],[4533.25,11.08],[4597.25,11.7],[4725.25,11.45],[4789.25,10.94]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"The brightest nova of the modern era, at magnitude -0.5 on 9-10 June 1918: as bright as Vega, in a summer evening sky, in wartime."},{id:"v476-cyg-1920",kind:"nova",designation:"V476 Cyg",name:"Nova Cygni 1920",raHours:19.97347,decDeg:53.61858,peakMagnitude:1.94,peakJd:242256025e-2,startJd:242255925e-2,lightCurve:[[0,2.7],[1,1.94],[3,2.07],[4.5,2.95],[8.25,4],[31.75,6.41],[35.75,7.23],[37.75,7.08],[41.75,7.33],[43.75,7.92],[45.75,8.2],[51.75,8.59],[63.75,8.82],[65.75,9.25],[71.75,8.93],[85.75,9.43],[87.75,9.05],[95.75,9.2],[97.75,8.67],[99.75,9.07],[112.75,8.78],[120.75,9.03],[128.75,8.67],[144.75,8.94],[152.75,8.73],[168.75,8.79],[176.75,9.28],[192.75,9],[216.75,9.6],[232.75,9.27],[240.75,9.5],[288.75,9.4],[296.75,9.6],[304.75,9.3],[320.75,9.73],[328.75,9.5],[336.75,9.8],[428.75,9.61],[476.75,10.01],[492.75,9.76],[508.75,9.87],[524.75,9.65],[556.75,9.87],[572.75,9.65],[620.75,10.22],[668.75,10.44],[684.75,10.23],[716.75,10.33],[756.75,10.66],[884.75,10.59],[948.75,10.96],[1108.75,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"rr-pic-1925",kind:"nova",designation:"RR Pic",name:"Nova Pictoris 1925",raHours:6.59335,decDeg:-62.64008,peakMagnitude:.95,peakJd:24243085e-1,startJd:24242995e-1,lightCurve:[[0,2.43],[5,2.35],[6,2.1],[7,2.4],[9,.95],[13,1.8],[14,1.7],[16,2.15],[18,2.2],[19,1.9],[23,3.1],[27,3.05],[31.5,3.58],[43.5,3.08],[47.5,3.15],[57.5,2.3],[59.5,1.65],[63.5,3.03],[65.5,2.84],[67.5,3.16],[69.5,2.4],[71.5,2.04],[73.5,2.05],[75.5,2.55],[79.5,3],[83.5,3.15],[116.5,3.54],[120.5,3.78],[124.5,3.67],[136.5,4.18],[148.5,4.34],[154.5,4.17],[194.5,4.43],[226.5,4.93],[234.5,4.8],[242.5,5.4],[250.5,5.5],[266.5,5.15],[298.5,5.6],[362.5,5.4],[414.5,5.7],[430.5,5.5],[494.5,6.2],[718.5,6.52],[830.5,6.3],[862.5,6.6],[878.5,6.4],[910.5,6.77],[958.5,6.67],[1062.5,7.07],[1318.5,7.35],[1590.5,8.12],[1718.5,8.25],[2486.5,8.59],[2614.5,8.47],[2742.5,8.7],[3382.5,8.6],[3766.5,8.97],[4022.5,8.79],[4150.5,9.22],[6710.5,10.29],[7414.5,11.03],[8438.5,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A slow nova, and a southern one: more than two months within two magnitudes of its peak."},{id:"dq-her-1934",kind:"nova",designation:"DQ Her",name:"Nova Herculis 1934",raHours:18.12507,decDeg:45.85906,peakMagnitude:1.56,peakJd:24277935e-1,startJd:242778675e-2,lightCurve:[[0,3.4],[1.5,2.4],[3,2.67],[5.75,2.01],[6.75,1.56],[7.75,1.59],[11.75,2.97],[12.75,2.31],[14.75,3.07],[15.75,2.56],[16.75,2.51],[19.75,2.68],[23.75,2.53],[24.75,2.27],[26.75,2.58],[30.75,2.24],[31.75,2.63],[32.75,2.66],[34.75,2.11],[39.75,2.71],[41.75,2.31],[43.75,2.37],[46.75,3.64],[47.75,3.21],[50.75,3.23],[52.75,2.66],[55.75,2.56],[58.75,2.97],[60.75,2.77],[61.75,3.36],[63.75,3.43],[64.75,2.89],[65.75,3.22],[68.75,3.52],[69.75,2.95],[70.75,3.06],[71.75,2.7],[76.75,3.65],[79.75,3.74],[81.75,3.21],[83.75,3.75],[87.75,3.69],[92.75,4.04],[94.75,4.8],[97.75,4.24],[98.75,4.52],[100.75,4.08],[101.75,4.43],[105.75,4.58],[106.75,4.33],[107.75,4.73],[108.75,6.57],[109.75,8.08],[110.75,8.15],[111.75,8.56],[113.75,8.45],[114.75,9.15],[115.75,9.15],[116.75,9.59],[117.75,9.43],[118.75,9.8],[122.75,10.5],[123.75,10.28],[124.75,10.93],[127.75,10.83],[129.75,11.87],[131.75,12.42],[135.75,12.5],[137.75,12.9],[138.75,12.77],[139.75,13],[143.75,12],[144.75,12.33],[146.75,12.35],[147.75,11.64],[148.75,11.83],[150.75,10.9],[151.75,10.78],[152.75,11.17],[154.75,10.32],[155.75,10.4],[165.25,9.24],[185.25,7.74],[225.25,6.8],[273.25,6.72],[321.25,6.97],[333.25,6.79],[353.25,7],[357.25,6.82],[377.25,6.88],[401.25,7.29],[409.25,6.8],[413.25,6.8],[419.25,7.1],[435.25,7.09],[451.25,7.4],[475.25,7],[555.25,7.48],[823.25,7.83],[855.25,8.18],[1135.25,8.43],[1823.25,9.98],[1887.25,9.71],[2015.25,10.55],[2335.25,10.95]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"Lost about ten magnitudes in a few weeks from April 1935, when dust condensed around it, then came back to naked-eye brightness."},{id:"cp-lac-1936",kind:"nova",designation:"CP Lac",name:"Nova Lacertae 1936",raHours:22.26142,decDeg:55.61703,peakMagnitude:2.02,peakJd:242834025e-2,startJd:242833825e-2,lightCurve:[[0,4.03],[.5,2.9],[1,2.45],[2,2.02],[2.5,2.61],[4,3],[4.5,3.35],[5,3.3],[9.25,4.59],[14.25,5.45],[22.25,6.03],[23.25,6.3],[26.25,6.23],[38.25,6.74],[41.25,6.61],[50.25,7.35],[53.25,7.27],[57.25,7.7],[58.25,7.54],[60.25,7.55],[61.25,7.79],[71.25,7.6],[74.25,7.81],[76.25,8.3],[77.25,7.79],[86.25,8.21],[87.25,8],[88.25,8.25],[92.25,8.17],[94.25,8.47],[102.25,8.27],[103.25,8.7],[104.25,8.4],[110.25,8.66],[116.75,8.55],[122.75,8.83],[126.75,8.7],[140.75,9.06],[154.75,9.01],[164.75,9.36],[170.75,9.18],[174.75,9.48],[186.75,9.42],[188.75,9.73],[192.75,9.53],[200.75,9.74],[202.75,9.5],[204.75,9.77],[208.75,9.6],[214.75,9.75],[216.75,10.05],[222.75,9.7],[232.75,10.03],[236.75,9.82],[250.75,10.1],[254.75,9.9],[260.75,10.1],[264.75,9.8],[266.75,10.15],[268.75,10],[274.75,10.2],[276.75,9.9],[292.75,10.6],[294.75,10.6],[298.75,10.1],[318.75,10.35],[320.75,10.6],[322.75,10.3],[328.75,10.65],[332.75,10.3],[338.75,10.7],[348.75,10.53],[350.75,10.7],[354.75,10.37],[358.75,10.58],[365.75,10.43],[373.75,10.85],[421.75,10.94]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"cp-pup-1942",kind:"nova",designation:"CP Pup",name:"Nova Puppis 1942",raHours:8.19613,decDeg:-35.35139,peakMagnitude:.73,peakJd:243067675e-2,startJd:243067275e-2,lightCurve:[[0,.95],[4,.73],[4.5,1.3],[5.5,1.47],[6,2.01],[7.75,2.88],[8.75,2.97],[10.75,3.5],[11.75,4.02],[13.75,4.4],[14.75,3.8],[17.75,5],[18.75,4.93],[19.75,5.48],[23.75,5.5],[25.75,5.65],[26.75,5.99],[33.25,6.28],[45.25,6.6],[57.25,6.41],[81.25,6.85],[89.25,6.5],[97.25,6.67],[101.25,7],[113.25,6.66],[125.25,7.1],[135.25,6.96],[231.25,7.86],[279.25,7.8],[327.25,8.33],[407.25,8.18],[423.25,8.59],[471.25,8.53],[503.25,8.99],[551.25,8.97],[567.25,8.7],[583.25,9.47],[615.25,8.95],[655.25,9.5],[751.25,9.55],[815.25,10.09],[847.25,10.02],[879.25,10.48],[911.25,10.34],[1023.25,10.79],[1279.25,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"One of the fastest bright novae: two magnitudes gone in four days."},{id:"t-crb-1946",kind:"nova",designation:"T CrB",name:"Nova Coronae Borealis 1946",raHours:15.99171,decDeg:25.92017,peakMagnitude:2.5,peakJd:2431860,startJd:2431860,lightCurve:[[0,2.5],[1.5,3.5],[2.5,3.61],[6.5,5.68],[8.5,6.25],[10.5,7.35],[11.5,7.3],[12.5,8],[16,8.68],[32,9.77],[38,9.7],[40,9.45],[44,9.9],[48,9.57],[54,9.9],[58,9.71],[79,9.94],[107,9.76],[111,9.51],[115,8.71],[119,8.46],[159,8.01],[179,8.07],[183,8.47],[191,8.16],[199,8.7],[207,8.81],[211,9.33],[215,9.15],[223,9.47],[297,9.4],[345,9.75],[377,9.57],[425,9.8],[537,9.8]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A recurrent nova. It erupted in 1866 and in 1946, and a third eruption was expected from 2024 on."},{id:"v446-her-1960",kind:"nova",designation:"V446 Her",name:"Nova Herculis 1960",raHours:18.956,decDeg:13.24147,peakMagnitude:4.83,peakJd:24370038e-1,startJd:24370033e-1,lightCurve:[[0,5.2],[.5,4.83],[2,4.9],[2.5,5.4],[3,5.05],[3.5,5.57],[4,5.25],[5,5.5],[6.5,5.4],[7.2,5.78],[8.2,5.6],[9.2,5.98],[10.2,5.92],[11.2,6.21],[16.2,6.1],[17.2,6.23],[18.2,7.2],[19.2,6.51],[20.2,6.78],[26.2,6.97],[27.2,7.24],[28.2,7.13],[29.2,7.45],[31.2,7.2],[40.7,7.57],[44.7,8.25],[46.7,7.84],[56.7,8.15],[60.7,8.9],[70.7,8.7],[72.7,8.14],[76.7,8.71],[80.7,8.47],[82.7,8.87],[86.7,8.57],[90.7,8.93],[107.7,9.11],[111.7,8.94],[115.7,9.27],[139.7,9.38],[151.7,9.91],[155.7,9.72],[173.7,10.51],[221.7,10.95]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v533-her-1963",kind:"nova",designation:"V533 Her",name:"Nova Herculis 1963",raHours:18.23902,decDeg:41.85614,peakMagnitude:3,peakJd:24380605e-1,startJd:24380565e-1,lightCurve:[[0,8],[4,3],[4.5,3],[8,4],[13,3.95],[15,4.6],[21,4.53],[24,5.05],[27,5.15],[32,4.76],[34,4.98],[35,5.39],[37,5.43],[41,6.04],[49,6.02],[56.5,6.34],[60.5,6.11],[74.5,6.72],[102.5,6.99],[137.5,7.81],[197.5,8.31],[217.5,8.8],[225.5,8.57],[233.5,9.03],[237.5,8.78],[277.5,9.44],[301.5,9.46],[315.5,9.86],[323.5,9.73],[339.5,10.05],[355.5,10.74],[363.5,10.32],[371.5,10.6],[387.5,10.69],[427.5,10.38],[435.5,10.84],[443.5,10.74],[451.5,11.33],[459.5,10.98],[467.5,11.17],[507.5,11.16],[539.5,11.66],[603.5,11.7],[619.5,12.05],[651.5,12.03],[659.5,11.74],[667.5,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"hr-del-1967",kind:"nova",designation:"HR Del",name:"Nova Delphini 1967",raHours:20.70565,decDeg:19.16092,peakMagnitude:3.58,peakJd:2439838,startJd:2439646,lightCurve:[[0,11.9],[6,11.8],[12,8.8],[16,8.3],[20,6.7],[30,5.8],[36,5.51],[66,5.55],[78,5.35],[86,4.89],[96,5],[108,4.75],[136,5.13],[152,4.83],[182,4.93],[186,4.59],[192,3.58],[202,5],[220,5.46],[226,5.14],[230,5.45],[232,5.14],[236,5],[242,5.08],[244,4.59],[246,4.45],[254,5.3],[256,4.75],[260,5.69],[268,4.8],[274,4.94],[276,5.45],[280,5.2],[282,5.51],[286,5.58],[292,4.95],[294,5.16],[298,4.94],[311,5.09],[335,4.4],[367,5.76],[407,6.16],[423,6.55],[603,7.43],[907,8.32],[1451,9.41],[2347,10.75]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"An exceptionally slow nova: rose over months and stayed near magnitude 4 to 5 for most of 1967 and 1968."},{id:"lv-vul-1968",kind:"nova",designation:"LV Vul",name:"Nova Vulpeculae 1968",raHours:19.80012,decDeg:27.1715,peakMagnitude:4.5,peakJd:243996425e-2,startJd:243996325e-2,lightCurve:[[0,5],[1,4.5],[2,5],[2.5,4.86],[3,5.1],[3.5,4.88],[4,5.1],[5,4.9],[7,5.4],[8,5.23],[10.5,5.42],[12,5.82],[13,5.4],[13.5,5.74],[14,5.7],[14.5,6.08],[15,5.75],[15.5,5.86],[16,5.6],[17,5.8],[18,5.6],[20.5,6.34],[21,6.2],[22.5,6.84],[23,6.57],[24,6.98],[24.5,6.3],[25,7.1],[26,6.65],[34.25,7.48],[35.25,7.23],[39.25,7.32],[44.25,7.76],[45.25,7.49],[46.25,7.78],[50.25,7.84],[51.25,8.1],[53.25,7.9],[54.25,8.13],[56.25,8],[57.75,8.24],[67.75,8.52],[75.75,8.38],[83.75,8.69],[89.75,8.59],[125.75,9.32],[127.75,9.33],[129.75,8.98],[131.75,9.29],[135.75,9.43],[212.75,9.9],[220.75,10.16],[228.75,10.03],[236.75,10.3],[244.75,10.16],[264.75,10.54],[280.75,10.45],[296.75,10.79],[328.75,10.78]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"fh-ser-1970",kind:"nova",designation:"FH Ser",name:"Nova Serpentis 1970",raHours:18.51307,decDeg:2.61444,peakMagnitude:4.5,peakJd:244063425e-2,startJd:244063125e-2,lightCurve:[[0,7],[2,5],[3,4.5],[3.5,5],[4.5,4.6],[5.5,5],[6.5,4.68],[12.25,4.66],[16.25,5.3],[17.25,5.72],[18.25,5.3],[19.25,5.2],[23.25,5.84],[24.25,5.68],[27.25,5.9],[30.25,5.47],[32.25,5.9],[34.25,5.7],[43.25,6.28],[45.25,6.1],[50.25,6.62],[52.25,6.47],[57.25,6.63],[60.25,7.08],[61.25,6.87],[62.25,7.2],[63.25,6.85],[64.25,7.68],[65.25,7.3],[66.25,8.3],[67.25,7.93],[69.25,9.15],[71.25,9.2],[72.25,9.63],[74.25,9.9],[76.25,9.7],[77.25,10.25],[78.25,10.1],[79.25,10.4],[80.25,10.23],[81.25,10.57],[83.25,10.64],[85.25,10.35],[86.25,11.2],[87.25,10.1],[89.25,11.2],[96.25,11.35],[100.25,11.95],[102.25,11.1],[104.25,11.65],[106.25,11.5],[108.25,12.07],[114.75,11.32],[118.75,11.28],[122.75,10.93],[130.75,10.85],[134.75,10.52],[154.75,10.65],[162.75,10.12],[174.75,9.98],[178.75,10.34],[186.75,9.98],[214.75,10.25],[224.75,10.02],[240.75,10.2],[264.75,10],[272.75,10.2],[280.75,10.05],[288.75,10.4],[296.75,10],[348.75,10.7],[396.75,10.3],[444.75,10.73],[460.75,10.59],[540.75,10.94],[556.75,10.82]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v1500-cyg-1975",kind:"nova",designation:"V1500 Cyg",name:"Nova Cygni 1975",raHours:21.19349,decDeg:48.15056,peakMagnitude:1.88,peakJd:244265525e-2,startJd:244265425e-2,lightCurve:[[0,2.44],[1,1.88],[1.5,1.88],[2.5,2.41],[3,3.38],[4,4.28],[8.25,5.81],[11.25,6.46],[22.25,7.35],[33.25,7.73],[34.25,7.97],[37.25,7.86],[40.25,8.3],[43.25,8.19],[48.25,8.6],[49.25,8.46],[66.25,9.04],[70.25,8.93],[75.25,9.23],[76.25,9.03],[80.25,9.39],[81.25,9.19],[83.25,9.35],[84.25,9.13],[86.25,9.39],[89.25,9.32],[90.25,9.54],[93.25,9.37],[105.75,9.86],[193.75,10.43],[201.75,10.7],[209.75,10.47],[257.75,10.94],[265.75,10.81]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"One of the fastest novae on record: discovered on 29 August 1975, at its peak of magnitude 1.9 within two days, and two magnitudes down again two days later."},{id:"v842-cen-1986",kind:"nova",designation:"V842 Cen",name:"Nova Centauri 1986",raHours:14.59794,decDeg:-57.6265,peakMagnitude:4.9,peakJd:244675975e-2,startJd:244675725e-2,lightCurve:[[0,5.6],[2.5,4.9],[3.5,5.1],[15.5,5.1],[17.5,5.75],[18.5,5.4],[20.5,5.5],[22.5,5.95],[30.5,6.15],[31.5,6.3],[32,7.5],[34.5,7.2],[38.5,7.5],[39,7],[41.5,7.15],[42.5,6.7],[44.5,7.23],[45.5,6.6],[53,9.3]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"sn-1987a",kind:"supernova",designation:"SN 1987A",name:"Supernova 1987A",raHours:5.59111,decDeg:-69.26975,peakMagnitude:2.98,peakJd:24469425e-1,startJd:24468495e-1,lightCurve:[[0,6.36],[1,6.11],[2,4.63],[4,4.45],[32,3.97],[56,3.15],[93,2.98],[105,3.35],[118,4.11],[134,4.43],[504,8.15],[617,10.27]],source:"V photometry compiled by the Open Supernova Catalog (Sternberg catalogue, IAU circulars, CTIO)",note:"In the Large Magellanic Cloud, 160 000 light years away: the nearest supernova since Kepler's, and invisible north of about 20° N."},{id:"v1974-cyg-1992",kind:"nova",designation:"V1974 Cyg",name:"Nova Cygni 1992",raHours:20.50879,decDeg:52.63078,peakMagnitude:4.27,peakJd:24486753e-1,startJd:24486718e-1,lightCurve:[[0,7.2],[1,5.23],[2,4.62],[3.5,4.27],[4.5,4.59],[6,4.5],[7,4.78],[7.5,4.52],[8,4.82],[10.7,5.25],[11.7,5.66],[16.7,5.85],[21.7,6.47],[22.7,6.3],[27.7,6.46],[29.7,6.83],[34.7,6.9],[35.7,7.25],[36.7,7],[37.7,7.16],[39.7,7.03],[43.7,7.41],[45.7,7.26],[50.7,7.45],[57.7,7.78],[58.7,8.13],[61.7,7.92],[64.7,8.19],[65.7,7.99],[71.7,8.22],[76.7,8.01],[128.2,8.72],[176.2,8.89],[192.2,9.15],[216.2,9.28],[232.2,9.07],[236.2,9.3],[390.2,10.99]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v382-vel-1999",kind:"nova",designation:"V382 Vel",name:"Nova Velorum 1999",raHours:10.74678,decDeg:-52.42533,peakMagnitude:2.88,peakJd:245132225e-2,startJd:245132075e-2,lightCurve:[[0,2.99],[1.5,2.88],[2.5,3.46],[4.5,3.98],[5,4.32],[5.5,4.23],[7.5,4.85],[21.75,6.67],[30.25,7.2],[40.25,7.41],[93.25,7.95],[97.25,8.25],[101.25,8],[113.25,7.96],[129.25,8.5],[155.25,8.47],[163.25,9.1],[179.25,9],[187.25,8.7],[195.25,9.15],[211.25,9.23],[235.25,9.8],[243.25,9.71],[299.25,10.42],[383.25,10.52],[415.25,10.81]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v1494-aql-1999",kind:"nova",designation:"V1494 Aql",name:"Nova Aquilae 1999",raHours:19.38482,decDeg:4.9555,peakMagnitude:4.11,peakJd:245151575e-2,startJd:245151425e-2,lightCurve:[[0,5.15],[.5,4.86],[1,4.27],[1.5,4.11],[2.5,4.35],[5,5.48],[10.5,6.26],[14.25,6.28],[20.25,7.43],[24.25,7.25],[25.25,7.63],[27.25,7.7],[29.25,7.42],[33.25,8.08],[35.25,8.03],[36.25,7.6],[37.25,7.6],[46.25,8.5],[54.25,8.28],[56.25,8.63],[58.25,8.4],[61.25,9.53],[62.25,9],[64.25,9.13],[69.25,8.58],[70.25,8.9],[72.25,8.88],[75.25,8.57],[77.25,9],[79.25,8.8],[81.25,9.7],[83.25,9.6],[85.25,9.8],[86.75,9.5],[88.75,9.54],[90.75,8.9],[92.75,8.85],[96.75,9.63],[102.75,9.7],[104.75,8.98],[106.75,8.73],[116.75,9.63],[118.75,9.6],[120.75,9.07],[122.75,9.26],[124.75,9.8],[128.75,9.36],[134.75,9.75],[147.75,9.92],[155.75,9.81],[259.75,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v4743-sgr-2002",kind:"nova",designation:"V4743 Sgr",name:"Nova Sagittarii 2002",raHours:19.01926,decDeg:-22.00167,peakMagnitude:5,peakJd:245253775e-2,startJd:245253675e-2,lightCurve:[[0,5.2],[1,5],[2,5.89],[2.5,5.91],[3.5,6.43],[5,6.45],[5.5,6.86],[6,6.59],[7,6.77],[7.5,7.31],[8.5,6.99],[9,7.09],[10.5,7.86],[11,7.58],[11.5,7.89],[15.75,8.33],[17.75,8.18],[18.75,8.58],[19.75,8.44],[22.75,8.83],[23.75,8.6],[24.75,8.85],[27.75,8.83],[30.75,9.4],[31.75,9.09],[36.25,9.08],[38.25,9.34],[62.25,9.75],[66.25,10.1],[70.25,9.7],[74.25,10],[171.25,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"rs-oph-2006",kind:"nova",designation:"RS Oph",name:"Nova Ophiuchi 2006",raHours:17.83699,decDeg:-6.70792,peakMagnitude:4.8,peakJd:2453779,startJd:2453779,lightCurve:[[0,4.8],[1.25,4.97],[2.75,5.78],[3.25,5.7],[3.75,6.24],[4.25,6.05],[4.75,6.38],[5.25,6.3],[8.5,7.25],[14.5,7.95],[24.5,8.55],[29.5,9.08],[48,9.87],[80,10.28],[107,11.54],[119,11.54],[139,11.98],[147,11.83],[163,12.03],[171,11.97],[175,11.65],[183,11.84],[195,11.64],[203,11.8],[207,12.13],[219,11.45],[277,11.68],[325,11],[341,11.53],[357,11.62],[373,11.3],[405,11.5],[421,11.17],[469,10.96],[501,11.22],[549,10.75],[581,11.08],[597,10.98]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A recurrent nova, erupting every twenty years or so (1898, 1907, 1933, 1945, 1958, 1967, 1985, 2006, 2021)."},{id:"v1280-sco-2007",kind:"nova",designation:"V1280 Sco",name:"Nova Scorpii 2007",raHours:16.96145,decDeg:-32.34325,peakMagnitude:3.8,peakJd:2454149,startJd:2454136,lightCurve:[[0,9.7],[13,3.8],[34,5.8],[103,15]],source:"AAVSO (discovery, peak, dust minimum); t2 from Das et al. 2008",note:"Faded from sight quickly when dust formed around it, three weeks after its peak."},{id:"v339-del-2013",kind:"nova",designation:"V339 Del",name:"Nova Delphini 2013",raHours:20.39186,decDeg:20.76772,peakMagnitude:4.4,peakJd:24565214e-1,startJd:24565214e-1,lightCurve:[[0,4.4],[11,6.4],[20,7.4]],source:"Gehrz et al. 2015 (peak, t2, t3)",note:"High in the summer evening sky of the northern hemisphere, and widely photographed."},{id:"v1369-cen-2013",kind:"nova",designation:"V1369 Cen",name:"Nova Centauri 2013",raHours:13.9126,decDeg:-59.15114,peakMagnitude:3.48,peakJd:245663965e-2,startJd:24566285e-1,lightCurve:[[0,5.33],[1.57,4.08],[2.75,3.73],[4.57,4.16],[5.96,4.15],[10.26,3.77],[11.15,3.48],[12.14,3.74],[14.17,4.78],[15.46,4.97],[23.16,4.22],[26.25,4.32],[27.31,4.82],[29.56,5.11],[32.66,4.71],[33.84,4.86],[36.05,4.46],[37.15,4.99],[41.42,4.59],[42.37,4.93],[43.37,4.82],[44.54,5.09],[49.95,5.38],[51.99,5.82],[54.21,5.77]],source:"AAVSO, binned by day, as plotted by Izzo 2017 (arXiv:1704.07214, figure 1)",note:"Discovered on 2 December 2013 by John Seach at magnitude 5.5, it flared several times, reaching about 3.3 around 14 December: the brightest nova of the century so far, and a southern one."},{id:"rs-oph-2021",kind:"nova",designation:"RS Oph",name:"Nova Ophiuchi 2021",raHours:17.83699,decDeg:-6.70792,peakMagnitude:4.6,peakJd:2459436,startJd:2459435,lightCurve:[[0,5],[1,4.6],[2.25,4.77],[3.75,5.58],[4.25,5.5],[4.75,6.04],[5.25,5.85],[5.75,6.18],[6.25,6.1],[9.5,7.05],[15.5,7.75],[25.5,8.35],[30.5,8.88],[49,9.67],[81,10.08],[108,11.34],[120,11.34],[140,11.78],[148,11.63],[164,11.83],[172,11.77],[176,11.45],[184,11.64],[196,11.44],[204,11.6],[208,11.93],[220,11.25],[278,11.48],[326,10.8],[342,11.33],[358,11.42],[374,11.1],[406,11.3],[422,10.97],[470,10.76],[502,11.02],[550,10.55],[582,10.88],[598,10.78]],source:"Recorded discovery and peak (8 and 9 August 2021); curve borrowed from its 2006 eruption",note:"RS Oph's latest eruption, discovered on 8 August 2021. The decline is its 2006 one."}];class qv{static UNIX_EPOCH_JD=24405875e-1;static aroundDate(t){const e=this.julianDayOf(t);return Uf.filter(i=>this.magnitudeAt(i,e)!==void 0)}static appearancesAt(t,e){const i=this.julianDayOf(t),n=[];for(const s of Uf){const r=this.magnitudeAt(s,i);r!==void 0&&n.push({outburst:s,position:os.ofJ2000(s.raHours,s.decDeg,t,e),magnitude:r})}return n.sort((s,r)=>s.magnitude-r.magnitude)}static brightestAt(t,e){return this.appearancesAt(t,e)[0]}static byId(t){return Uf.find(e=>e.id===t)}static magnitudeAt(t,e){const i=t.lightCurve,n=e-t.startJd;if(i.length===0||n<i[0][0]||n>i[i.length-1][0])return;let s=1;for(;s<i.length-1&&i[s][0]<n;)s++;const[r,o]=i[s-1]??i[0],[c,l]=i[s]??i[0];if(c===r)return o;const h=Math.min(1,Math.max(0,(n-r)/(c-r)));return o+h*(l-o)}static julianDayOf(t){return t.getTime()/864e5+this.UNIX_EPOCH_JD}}const ND=[{id:"quadrantids",code:"QUA",name:"Quadrantids",radiantRaHours:15.33,radiantDecDeg:49.7,start:{month:12,day:28},peak:{month:1,day:3},end:{month:1,day:12},peakZhr:110,velocityKmS:41,populationIndex:2.1},{id:"lyrids",code:"LYR",name:"April Lyrids",radiantRaHours:18.13,radiantDecDeg:33.3,start:{month:4,day:16},peak:{month:4,day:22},end:{month:4,day:25},peakZhr:18,velocityKmS:49,populationIndex:2.1},{id:"eta-aquariids",code:"ETA",name:"eta Aquariids",radiantRaHours:22.53,radiantDecDeg:-1,start:{month:4,day:19},peak:{month:5,day:6},end:{month:5,day:28},peakZhr:50,velocityKmS:66,populationIndex:2.4},{id:"alpha-capricornids",code:"CAP",name:"alpha Capricornids",radiantRaHours:20.47,radiantDecDeg:-9.2,start:{month:7,day:3},peak:{month:7,day:30},end:{month:8,day:15},peakZhr:5,velocityKmS:23,populationIndex:2.5},{id:"southern-delta-aquariids",code:"SDA",name:"Southern delta Aquariids",radiantRaHours:22.67,radiantDecDeg:-16.4,start:{month:7,day:12},peak:{month:7,day:30},end:{month:8,day:23},peakZhr:25,velocityKmS:41,populationIndex:3.2},{id:"perseids",code:"PER",name:"Perseids",radiantRaHours:3.22,radiantDecDeg:58,start:{month:7,day:17},peak:{month:8,day:12},end:{month:8,day:24},peakZhr:100,velocityKmS:59,populationIndex:2.2},{id:"southern-taurids",code:"STA",name:"Southern Taurids",radiantRaHours:3.47,radiantDecDeg:13,start:{month:9,day:10},peak:{month:10,day:10},end:{month:11,day:20},peakZhr:5,velocityKmS:27,populationIndex:2.3},{id:"draconids",code:"DRA",name:"October Draconids",radiantRaHours:17.47,radiantDecDeg:54,start:{month:10,day:6},peak:{month:10,day:8},end:{month:10,day:10},peakZhr:10,velocityKmS:20,populationIndex:2.6},{id:"orionids",code:"ORI",name:"Orionids",radiantRaHours:6.35,radiantDecDeg:15.6,start:{month:10,day:2},peak:{month:10,day:21},end:{month:11,day:7},peakZhr:20,velocityKmS:66,populationIndex:2.5},{id:"northern-taurids",code:"NTA",name:"Northern Taurids",radiantRaHours:3.87,radiantDecDeg:22,start:{month:10,day:20},peak:{month:11,day:12},end:{month:12,day:10},peakZhr:5,velocityKmS:29,populationIndex:2.3},{id:"leonids",code:"LEO",name:"Leonids",radiantRaHours:10.13,radiantDecDeg:21.6,start:{month:11,day:6},peak:{month:11,day:17},end:{month:11,day:30},peakZhr:15,velocityKmS:71,populationIndex:2.5},{id:"geminids",code:"GEM",name:"Geminids",radiantRaHours:7.47,radiantDecDeg:32.3,start:{month:12,day:4},peak:{month:12,day:14},end:{month:12,day:17},peakZhr:150,velocityKmS:35,populationIndex:2.6},{id:"ursids",code:"URS",name:"Ursids",radiantRaHours:14.47,radiantDecDeg:75.3,start:{month:12,day:17},peak:{month:12,day:22},end:{month:12,day:26},peakZhr:10,velocityKmS:33,populationIndex:3}],Yu=6.5;class zf{static activeAt(t){return ND.flatMap(e=>{const i=this.nearness(e,t);return i<=0?[]:[{shower:e,zhr:e.peakZhr*i,nearness:i}]})}static nearness(t,e){const i=this.dayOfYear(e),n=this.dayOfYear(this.asDate(t.start)),s=this.dayOfYear(this.asDate(t.peak)),r=this.dayOfYear(this.asDate(t.end)),o=this.wrappedDelta(i,s),c=this.wrappedDelta(s,n),l=this.wrappedDelta(r,s);return o<0?o<-c?0:1+o/c:o>0?o>l?0:1-o/l:1}static observedRatePerHour(t,e,i,n=Yu){if(e<=0)return 0;const s=Yu-n;return t*Math.sin(e*Math.PI/180)/Math.pow(i,s)}static radiantPosition(t,e,i){return os.ofJ2000(t.radiantRaHours,t.radiantDecDeg,e,i)}static dayOfYear(t){const e=Date.UTC(t.getUTCFullYear(),0,1);return Math.floor((Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-e)/864e5)+1}static asDate(t){return new Date(Date.UTC(2001,t.month-1,t.day))}static wrappedDelta(t,e){const i=t-e;return i>182?i-365:i<-182?i+365:i}}class fi{static QUIET_RATE_PER_HOUR=2;static APEX_RATE_PER_HOUR=8;static POPULATION_INDEX=3;static apexPosition(t,e){const i=Ne(t),n=new ld(0,FT(t).elon-90,1),s=cr(u4(i),hm(n,i)),r=fd(s);return um(r.ra,r.dec,t,e)}static observedRatePerHour(t,e=Yu){const i=fi.APEX_RATE_PER_HOUR*Math.max(0,Math.sin(t*Math.PI/180)),n=Yu-e;return(fi.QUIET_RATE_PER_HOUR+i)/Math.pow(fi.POPULATION_INDEX,n)}static schedule(t){const e=new pd(t.seed^1542469173);return ka.schedule(t).map(i=>{const n=fi.toCartesian({altitudeDeg:Math.asin(e.next())*180/Math.PI,azimuthDeg:e.between(0,360)}),s=i.fromRadiantDeg*Math.PI/180,r=fi.turnAround(n,e.between(0,360)),o={x:n.x*Math.cos(s)+r.x*Math.sin(s),y:n.y*Math.cos(s)+r.y*Math.sin(s),z:n.z*Math.cos(s)+r.z*Math.sin(s)};return{...i,radiant:fi.toHorizontal(o),bearingDeg:fi.bearingFrom(o,n)}})}static turnAround(t,e){const[i,n]=fi.basisAround(t),s=e*Math.PI/180;return{x:i.x*Math.cos(s)+n.x*Math.sin(s),y:i.y*Math.cos(s)+n.y*Math.sin(s),z:i.z*Math.cos(s)+n.z*Math.sin(s)}}static bearingFrom(t,e){const[i,n]=fi.basisAround(t),s=t.x*e.x+t.y*e.y+t.z*e.z,r=fi.normalise({x:e.x-t.x*s,y:e.y-t.y*s,z:e.z-t.z*s});return(Math.atan2(r.x*n.x+r.y*n.y+r.z*n.z,r.x*i.x+r.y*i.y+r.z*i.z)*180/Math.PI%360+360)%360}static basisAround(t){const e=Math.abs(t.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=fi.normalise(fi.cross(t,e));return[i,fi.normalise(fi.cross(t,i))]}static toHorizontal(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{altitudeDeg:Math.asin(Math.min(1,Math.max(-1,t.y/e)))*180/Math.PI,azimuthDeg:(Math.atan2(t.x,-t.z)*180/Math.PI%360+360)%360}}static appearanceOf(t){const e=fi.toCartesian(t.radiant??{altitudeDeg:90,azimuthDeg:0}),i=fi.turnAround(e,t.bearingDeg),n=t.fromRadiantDeg*Math.PI/180;return fi.toHorizontal({x:e.x*Math.cos(n)+i.x*Math.sin(n),y:e.y*Math.cos(n)+i.y*Math.sin(n),z:e.z*Math.cos(n)+i.z*Math.sin(n)})}static toCartesian(t){const e=t.altitudeDeg*Math.PI/180,i=t.azimuthDeg*Math.PI/180,n=Math.cos(e);return{x:n*Math.sin(i),y:Math.sin(e),z:-n*Math.cos(i)}}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}static TYPICAL_VELOCITY_KM_S=40}const $v="https://ufoathome.org/tle/index.json";class qi{static MAX_ELEMENT_AGE_DAYS=7;static DAY_MS=864e5;fetchImpl;indexUrls;index;files=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??qi.defaultIndexUrls()}static defaultIndexUrls(){const t=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&t.push(new URL("/tle/index.json",location.href).href),t.includes($v)||t.push($v),t}static FIRST_SNAPSHOT="2021-02-22";async covers(t){const e=Date.parse(`${qi.FIRST_SNAPSHOT}T00:00:00Z`)-qi.MAX_ELEMENT_AGE_DAYS*qi.DAY_MS;if(t.getTime()<e)return!1;const i=await this.loadIndex();return i?Object.values(i.index.kinds).some(n=>t.getTime()>=Date.parse(n.from)-qi.MAX_ELEMENT_AGE_DAYS*qi.DAY_MS&&t.getTime()<=Date.parse(n.to)+qi.MAX_ELEMENT_AGE_DAYS*qi.DAY_MS):!1}async at(t){const e=await this.loadIndex();if(!e)return;const{index:i,base:n}=e,s=[],r=[];for(const o of Object.keys(i.kinds)){const c=await this.kindAt(o,t,i,n);s.push(...c),r.push(this.coverageOf(o,t,i,c.length>0))}return{objects:s,coverage:r,credit:i.credit,creditUrl:i.source}}async kindAt(t,e,i,n){const s=e.getTime(),r=i.binDays*qi.DAY_MS,o=Math.floor(s/r),c=s-o*r<r/2?o-1:o+1,l=new Set(i.kinds[t].bins),h=[o,c].map(v=>new Date(v*r).toISOString().slice(0,10)).filter(v=>l.has(v));if(h.length===0)return[];const[u,...d]=await Promise.all([this.json(new URL(`objects-${t}.json`,n).href),...h.map(v=>this.binary(new URL(`${t}/${v}.bin`,n).href))]),f=new Map;for(const v of d)for(const m of qi.decode(v,i.recordBytes)){const g=f.get(m.norad);(!g||Math.abs(m.epochMs-s)<Math.abs(g.epochMs-s))&&f.set(m.norad,m)}const p=[];for(const v of f.values()){const m=Math.abs(v.epochMs-s)/qi.DAY_MS;if(m>qi.MAX_ELEMENT_AGE_DAYS)continue;const g=u[v.norad]??{name:String(v.norad)};g.launch&&Date.parse(`${g.launch}T00:00:00Z`)>s||p.push({norad:v.norad,name:g.name,kind:t,launch:g.launch,stdMag:g.stdMag,elements:v,ageDays:m})}return p}coverageOf(t,e,i,n){const{from:s,to:r}=i.kinds[t],o=e.getTime(),c=qi.MAX_ELEMENT_AGE_DAYS*qi.DAY_MS,l=n?"covered":o<Date.parse(s)-c?"before":o>Date.parse(r)+c?"after":"gap";return{kind:t,status:l,from:s,to:r}}static decode(t,e){const i=new DataView(t),n=[];for(let s=0;s+e<=t.byteLength;s+=e)n.push({norad:i.getUint32(s,!0),epochMs:i.getFloat64(s+4,!0),bstar:i.getFloat32(s+12,!0),inclinationDeg:i.getFloat32(s+16,!0),raanDeg:i.getFloat32(s+20,!0),eccentricity:i.getFloat32(s+24,!0),argOfPerigeeDeg:i.getFloat32(s+28,!0),meanAnomalyDeg:i.getFloat32(s+32,!0),meanMotion:i.getFloat64(s+36,!0)});return n}loadIndex(){return this.index??=(async()=>{for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(!e.ok)continue;return{index:await e.json(),base:t}}catch{}})(),this.index}json(t){return this.cached(t,async e=>e.json())}binary(t){return this.cached(t,async e=>e.arrayBuffer())}cached(t,e){let i=this.files.get(t);return i||(i=this.fetchImpl(t).then(n=>{if(!n.ok)throw new Error(`${t}: ${n.status}`);return e(n)}),i.catch(()=>this.files.delete(t)),this.files.set(t,i)),i}}class kD{lowerM;upperM;add(t,e){if(!(t<=0)){if(e.behindM!==void 0){const i=Fe.sizeMAt(e.behindM,t);this.lowerM=this.lowerM===void 0?i:Math.max(this.lowerM,i)}if(e.inFrontM!==void 0){const i=Fe.sizeMAt(e.inFrontM,t);this.upperM=this.upperM===void 0?i:Math.min(this.upperM,i)}}}get sizeRange(){return{minM:this.lowerM,maxM:this.upperM}}get empty(){return this.lowerM===void 0&&this.upperM===void 0}get contradictory(){return this.lowerM!==void 0&&this.upperM!==void 0&&this.lowerM>this.upperM}distanceRangeAt(t){return t<=0?{}:{minM:this.lowerM===void 0?void 0:Fe.distanceMAt(this.lowerM,t),maxM:this.upperM===void 0?void 0:Fe.distanceMAt(this.upperM,t)}}clear(){this.lowerM=void 0,this.upperM=void 0}}class Ua{static DEG_PER_SECOND=360/86164.0905;static degOver(t){return Math.max(0,t)*Ua.DEG_PER_SECOND}static instants(t,e){if(!(e>0))return 1;const i=Ua.degOver(t)/e;return i<1?1:Math.min(Ua.MAX_INSTANTS,Math.max(2,Math.ceil(i)))}static MAX_INSTANTS=64}class an{static EYE={apertureMm:7,exposureSeconds:.1,resolutionArcsec:60};static WAVELENGTH_M=55e-8;static ARCSEC_PER_RADIAN=180*3600/Math.PI;static UNKNOWN_CAMERA_FOCAL_MM=50;static UNKNOWN_CAMERA_DETAIL_UM=20;static get skyDriftArcsecPerSecond(){return Ua.DEG_PER_SECOND*3600}static graspOf(t,e={}){const i=e.exposureSeconds??t.exposureSeconds,n=e.fNumber??t.fNumber;if(i===void 0||n===void 0||!(i>0)||!(n>0))return an.EYE;const s=e.focalLengthMm??t.frame?.focalLengthMm??an.UNKNOWN_CAMERA_FOCAL_MM,r=s/n,o=an.resolutionArcsec(t,s,r);return{apertureMm:r,exposureSeconds:Math.min(i,an.trailLimitedSeconds(o)),resolutionArcsec:o}}static resolutionArcsec(t,e,i){const s=(t.detailUm??an.UNKNOWN_CAMERA_DETAIL_UM)/1e3/e*an.ARCSEC_PER_RADIAN,r=1.22*an.WAVELENGTH_M/(i/1e3)*an.ARCSEC_PER_RADIAN;return Math.max(s,r)}static trailLimitedSeconds(t){return t/an.skyDriftArcsecPerSecond}static gainOverEye(t,e={}){const i=an.graspOf(t,e),n=an.EYE,s=(i.apertureMm/n.apertureMm)**2,r=i.exposureSeconds/n.exposureSeconds,o=(n.resolutionArcsec/i.resolutionArcsec)**2;return 1.25*Math.log10(s*r*o)}static gainFor(t,e){const i=e.fieldOfViewDeg===void 0?void 0:bi.focalLengthMmFor(t,e.fieldOfViewDeg);return an.gainOverEye(t,{fNumber:e.fNumber,focalLengthMm:i,exposureSeconds:e.exposureSeconds})}}const Kv=111320,Pc=Math.PI/180,FD=1.02,UD=1;class tl{static of(t,e){const i=tl.sightings(t,e);if(i.length<2)return;const n=tl.baseline(i);if(!n)return;const{near:s,far:r,closedM:o}=n,c=Math.tan(r.widthDeg/2*Pc)===0?0:Math.tan(s.widthDeg/2*Pc)/Math.tan(r.widthDeg/2*Pc);if(c<FD)return;const l=o/(c-1),h=Fe.sizeMAt(l,s.widthDeg),u=i.map(d=>({t:d.t,m:Fe.distanceMAt(h,d.widthDeg)}));return{widthM:h,distanceM:u,nearestM:Math.min(...u.map(d=>d.m)),fromT:r.t,toT:s.t,closedM:o}}static sightings(t,e){return t.timeline.allKeyframes.flatMap(i=>{const n=i.shapes.find(o=>o.sourceId===e)?.shape,s=n?.angular?.widthDeg,r=Ze(t,i.t);return s===void 0||s<=0||r?.lat===void 0||r.lng===void 0?[]:[{t:i.t,widthDeg:s,lat:r.lat,lng:r.lng,sightAzimuthDeg:n?.aim?.azimuthDeg??r.headingDeg}]}).sort((i,n)=>i.t-n.t)}static baseline(t){let e;for(const i of t)for(const n of t){if(i.t>=n.t)continue;const s=tl.closedAlongSight(i,n),[r,o,c]=s>=0?[n,i,s]:[i,n,-s];c<UD||r.widthDeg<=o.widthDeg||(!e||c>e.closedM)&&(e={near:r,far:o,closedM:c})}return e}static closedAlongSight(t,e){const i=(e.lat-t.lat)*Kv,n=(e.lng-t.lng)*Kv*Math.cos(t.lat*Pc),s=(t.sightAzimuthDeg??0)*Pc;return i*Math.cos(s)+n*Math.sin(s)}}class sn{static CONVENTIONAL_M=5;static NEAREST_M=.2;static MARGIN=1.1;static resolve(t){if(t.statedM!==void 0&&t.statedM>0)return{distanceM:sn.atLeastNearest(t.statedM),basis:"stated"};if(t.hypothesisM!==void 0&&t.hypothesisM>0)return{distanceM:sn.atLeastNearest(t.hypothesisM),basis:"hypothesis"};if(t.derivedM!==void 0&&t.derivedM>0)return{distanceM:sn.atLeastNearest(t.derivedM),basis:"derived"};const e=sn.largest(t.range?.minM,t.crossing?.behindM),i=sn.smallest(t.range?.maxM,t.crossing?.inFrontM),n=e===void 0?void 0:e*sn.MARGIN,s=i===void 0?void 0:i/sn.MARGIN;return n!==void 0&&s!==void 0?{distanceM:sn.atLeastNearest(n<=s?Math.sqrt(n*s):n),basis:"bounded"}:n!==void 0?{distanceM:sn.atLeastNearest(n),basis:"bounded"}:s!==void 0&&s<sn.CONVENTIONAL_M?{distanceM:sn.atLeastNearest(s),basis:"bounded"}:{distanceM:sn.CONVENTIONAL_M,basis:"conventional"}}static atLeastNearest(t){return Math.max(sn.NEAREST_M,t)}static largest(...t){const e=t.filter(i=>i!==void 0&&i>0);return e.length===0?void 0:Math.max(...e)}static smallest(...t){const e=t.filter(i=>i!==void 0&&i>0);return e.length===0?void 0:Math.min(...e)}}const Bf=Math.PI/180;class ce{constructor(t,e,i){this.body=t,this.ground=e;const n=[...t.track].sort((s,r)=>s.t-r.t);this.keys=this.place(n,i);for(const s of n)ce.collect(this.motionKeys,s.t,s.motions),ce.collect(this.lightKeys,s.t,s.lights)}static EYE_HEIGHT_M=1.6;static MAX_RANGE_M=3e4;static DEFAULT_SIZE={widthM:1,lengthM:1,heightM:1};static DEFAULT_APPEARANCE={color:"#c8c8c8",albedo:.5,luminanceCdM2:0};keys;motionKeys=new Map;lightKeys=new Map;static collect(t,e,i){for(const[n,s]of Object.entries(i??{})){const r=t.get(n)??[];r.push({t:e,value:s}),t.set(n,r)}}motionsAt(t){return ce.channelsAt(this.motionKeys,t,0)}lightsAt(t){return this.lightKeys.size>0?ce.channelsAt(this.lightKeys,t,void 0):void 0}static channelsAt(t,e,i){const n={};for(const[s,r]of t){let o=r.length-1;for(;o>=0&&r[o].t>e;)o--;if(o<0){i!==void 0&&(n[s]=i);continue}const c=r[o],l=r[Math.min(o+1,r.length-1)],h=l===c||l.t===c.t?0:Math.min(1,(e-c.t)/(l.t-c.t));n[s]=ce.lerp(c.value,l.value,h)}return n}static eyeOf(t,e,i){const n=Ze(t,0),s=Ze(t,e),o=n?.lat!==void 0&&n.lng!==void 0&&s?.lat!==void 0&&s.lng!==void 0?si(s.lat,s.lng,n.lat,n.lng):void 0,c=o?o.x:0,l=o?-o.z:0;return{eastM:c,northM:l,upM:i.heightAt(c,l)+ce.EYE_HEIGHT_M+(s?.elevationM??0),headingDeg:s?.headingDeg}}static lineOfSightMeetsGround(t,e,i,n){const s=ce.directionOf(e,i),r=l=>t.upM+s.upM*l-n.heightAt(t.eastM+s.eastM*l,t.northM+s.northM*l);let o=0,c=0;for(;c<ce.MAX_RANGE_M;){if(c=o+Math.max(.5,o*.01),r(c)<=0){for(let l=0;l<30;l++){const h=(o+c)/2;r(h)<=0?c=h:o=h}return c}o=c}}static directionOf(t,e){const i=t*Bf,n=e*Bf;return{eastM:Math.sin(i)*Math.cos(n),northM:Math.cos(i)*Math.cos(n),upM:Math.sin(n)}}at(t){const e=this.keys;if(e.length===0||t<e[0].t)return;let i=e.length-1;for(;i>0&&e[i].t>t;)i--;const n=e[i];if(!n.present)return;const s=e[Math.min(i+1,e.length-1)],r=s===n||s.t===n.t?0:Math.min(1,(t-n.t)/(s.t-n.t)),o=ce.lerp(n.eastM,s.eastM,r),c=ce.lerp(n.northM,s.northM,r),l={widthM:ce.lerp(n.sizeM.widthM,s.sizeM.widthM,r),lengthM:ce.lerp(n.sizeM.lengthM,s.sizeM.lengthM,r),heightM:ce.lerp(n.sizeM.heightM,s.sizeM.heightM,r)},h={headingDeg:ce.lerpAngle(n.attitude.headingDeg,s.attitude.headingDeg,r),pitchDeg:ce.lerp(n.attitude.pitchDeg,s.attitude.pitchDeg,r),rollDeg:ce.lerp(n.attitude.rollDeg,s.attitude.rollDeg,r)};let u;if("aboveGroundM"in n.vertical&&"aboveGroundM"in s.vertical){const d=ce.lerp(n.vertical.aboveGroundM,s.vertical.aboveGroundM,r);u=this.groundUnderFootprint(o,c,l,h.headingDeg)+d+l.heightM/2}else u=ce.lerp(this.centreUpOf(n),this.centreUpOf(s),r);return{id:this.body.id,model:this.body.model,explains:this.body.explains??[],outlineNode:this.body.outlineNode,eastM:o,northM:c,upM:u,sizeM:l,attitude:h,appearance:{color:(r<1?n:s).appearance.color,albedo:ce.lerp(n.appearance.albedo,s.appearance.albedo,r),luminanceCdM2:ce.lerp(n.appearance.luminanceCdM2,s.appearance.luminanceCdM2,r)},flame:ce.flameBetween(n.flame,s.flame,r),motions:this.motionsAt(t),lights:this.lightsAt(t),throwsFlame:this.body.track.some(d=>d.flame!==void 0&&d.flame.luminanceCdM2>0)}}static flameBetween(t,e,i){if(!t||t.luminanceCdM2<=0)return i>=1&&e&&e.luminanceCdM2>0?e:void 0;const n=t,s=e??t,r={...i<1?n:s,lengthM:ce.lerp(n.lengthM,s.lengthM,i),widthM:ce.lerp(n.widthM,s.widthM,i),luminanceCdM2:ce.lerp(n.luminanceCdM2,s.luminanceCdM2,i)};return r.luminanceCdM2>0?r:void 0}centreUpOf(t){return"upM"in t.vertical?t.vertical.upM:this.groundUnderFootprint(t.eastM,t.northM,t.sizeM,t.attitude.headingDeg)+t.vertical.aboveGroundM+t.sizeM.heightM/2}groundUnderFootprint(t,e,i,n){const s=n*Bf,r={eastM:Math.cos(s),northM:-Math.sin(s)},o={eastM:Math.sin(s),northM:Math.cos(s)};let c=this.ground.heightAt(t,e);for(const[l,h]of[[-1,-1],[1,-1],[-1,1],[1,1]]){const u=l*i.widthM/2,d=h*i.lengthM/2;c=Math.max(c,this.ground.heightAt(t+r.eastM*u+o.eastM*d,e+r.northM*u+o.northM*d))}return c}place(t,e){const i=[];let n;for(const s of t){const r=s.sizeM??n?.sizeM??ce.DEFAULT_SIZE,o={headingDeg:s.attitude?.headingDeg??n?.attitude.headingDeg??0,pitchDeg:s.attitude?.pitchDeg??n?.attitude.pitchDeg??0,rollDeg:s.attitude?.rollDeg??n?.attitude.rollDeg??0},c={color:s.appearance?.color??n?.appearance.color??ce.DEFAULT_APPEARANCE.color,albedo:s.appearance?.albedo??n?.appearance.albedo??ce.DEFAULT_APPEARANCE.albedo,luminanceCdM2:s.appearance?.luminanceCdM2??n?.appearance.luminanceCdM2??ce.DEFAULT_APPEARANCE.luminanceCdM2},l=this.positionOf(s,r,e)??(n&&{eastM:n.eastM,northM:n.northM,vertical:this.verticalOf(s,r)??n.vertical});if(!l)continue;const h=s.flame??n?.flame,u=s.present??n?.present??!0;n={t:s.t,...l,sizeM:r,attitude:o,appearance:c,flame:h,present:u},i.push(n)}return i}verticalOf(t,e){if(t.onGround)return{aboveGroundM:0};if(t.altitudeAboveGroundM!==void 0)return{aboveGroundM:t.altitudeAboveGroundM};if(t.altitudeM!==void 0)return{upM:t.altitudeM+e.heightM/2}}positionOf(t,e,i){if(t.eastM!==void 0&&t.northM!==void 0)return{eastM:t.eastM,northM:t.northM,vertical:this.verticalOf(t,e)??{aboveGroundM:0}};if(t.azimuthDeg===void 0||t.altitudeDeg===void 0)return;const n=i(t.t);if(!n)return;const s=t.distanceM??(t.onGround?ce.lineOfSightMeetsGround(n,t.azimuthDeg,t.altitudeDeg,this.ground):void 0);if(s===void 0)return;const r=ce.directionOf(t.azimuthDeg,t.altitudeDeg),o=n.eastM+r.eastM*s,c=n.northM+r.northM*s;return{eastM:o,northM:c,vertical:this.verticalOf(t,e)??{upM:n.upM+r.upM*s}}}static lerp(t,e,i){return t+(e-t)*i}static lerpAngle(t,e,i){const n=((e-t)%360+540)%360-180;return((t+n*i)%360+360)%360}}class be{static A=6378137;static E2=.00669437999014;static DEG=Math.PI/180;static STANDARD_DISTANCE_KM=100;static DEFAULT_COLOR="#ffb347";static DEFAULT_TRAIN_S=1.5;static FADE_MS=600;static TRAIN_POINTS=8;static leadAt(t,e){const i=t.track;if(i.length<2||e<i[0].t||e>i[i.length-1].t)return;let n=0;for(;n<i.length-2&&i[n+1].t<e;)n++;const s=i[n],r=i[n+1],o=r.t-s.t,c=o>0?(e-s.t)/o:0,[l,h]=be.alongGreatCircle(s,r,c);return{lat:l,lng:h,heightM:(s.altitudeKm+(r.altitudeKm-s.altitudeKm)*c)*1e3}}static viewsAt(t,e,i){const n=[];for(const s of t){const r=s.track[0]?.t??0,o=s.track[s.track.length-1]?.t??0;s.fragments.forEach((c,l)=>{const h=c.fromT??r,u=c.untilT??o;if(e<h||e>u)return;const d=(c.lagS??0)*1e3,f=be.leadAt(s,e-d);if(!f)return;const p=be.seenFrom(i,f);if(p.altitudeDeg<0)return;const v=Math.min(be.FADE_MS,(u-h)/4),m=v>0?Math.min(1,(e-h)/v,(u-e)/v):1,g=-2.5*Math.log10(Math.max(m,.001)),b=c.absoluteMagnitude+5*Math.log10(p.distanceKm/be.STANDARD_DISTANCE_KM)+g,S=[p],M=(c.trainS??be.DEFAULT_TRAIN_S)*1e3;for(let x=1;x<=be.TRAIN_POINTS;x++){const _=Math.min(M*x/be.TRAIN_POINTS,e-h),E=be.leadAt(s,e-d-_);if(!E||(S.push(be.seenFrom(i,E)),_>=e-h))break}n.push({reentryId:s.id,fragmentId:c.id??String(l),head:p,magnitude:b,color:c.color??be.DEFAULT_COLOR,train:S})})}return n}static seenFrom(t,e){const i=be.ecef(t),n=be.ecef(e),s=n[0]-i[0],r=n[1]-i[1],o=n[2]-i[2],c=t.lat*be.DEG,l=t.lng*be.DEG,h=-Math.sin(l)*s+Math.cos(l)*r,u=-Math.sin(c)*Math.cos(l)*s-Math.sin(c)*Math.sin(l)*r+Math.cos(c)*o,d=Math.cos(c)*Math.cos(l)*s+Math.cos(c)*Math.sin(l)*r+Math.sin(c)*o,f=Math.hypot(h,u,d);return{altitudeDeg:Math.asin(d/f)/be.DEG,azimuthDeg:(Math.atan2(h,u)/be.DEG+360)%360,distanceKm:f/1e3}}static ecef(t){const e=t.lat*be.DEG,i=t.lng*be.DEG,n=Math.sin(e),s=be.A/Math.sqrt(1-be.E2*n*n);return[(s+t.heightM)*Math.cos(e)*Math.cos(i),(s+t.heightM)*Math.cos(e)*Math.sin(i),(s*(1-be.E2)+t.heightM)*n]}static alongGreatCircle(t,e,i){const n=h=>{const u=h.lat*be.DEG,d=h.lng*be.DEG;return[Math.cos(u)*Math.cos(d),Math.cos(u)*Math.sin(d),Math.sin(u)]},s=n(t),r=n(e),o=Math.max(-1,Math.min(1,s[0]*r[0]+s[1]*r[1]+s[2]*r[2])),c=Math.acos(o);let l;if(c<1e-12)l=s;else{const h=Math.sin((1-i)*c)/Math.sin(c),u=Math.sin(i*c)/Math.sin(c);l=[s[0]*h+r[0]*u,s[1]*h+r[1]*u,s[2]*h+r[2]*u]}return[Math.atan2(l[2],Math.hypot(l[0],l[1]))/be.DEG,Math.atan2(l[1],l[0])/be.DEG]}}class pm{static FIRST_DAY="2022-01-01";static mayCover(t){return new Date(t).toISOString().slice(0,10)>=pm.FIRST_DAY}}class zD{constructor(t,e,i){this.citation=t,this.covers=e,this.load=i}loading;mayCover(t){return this.covers(t)}async between(t,e,i,n){try{return await(await this.provider()).between(t,e,i,n)}catch{return{status:"failed"}}}async describe(t,e){try{return await(await this.provider()).describe?.(t,e)}catch{return}}provider(){if(!this.loading){const t=this.load();this.loading=t,t.catch(()=>{this.loading===t&&(this.loading=void 0)})}return this.loading}}const BD="Aircraft positions: adsb.lol feeders and contributors, Open Database License 1.0 (https://www.adsb.lol/docs/open-data/historical/)",HD=[{id:"adsb-lol",name:"adsb.lol",credit:"adsb.lol feeders and contributors, ODbL 1.0",creditUrl:"https://www.adsb.lol/docs/open-data/historical/",create:()=>new zD(BD,a=>pm.mayCover(a),async()=>new(await je(async()=>{const{AdsbLolArchiveProvider:a}=await import("./AdsbLolArchiveProvider-BXH71WVn.js");return{AdsbLolArchiveProvider:a}},[],import.meta.url)).AdsbLolArchiveProvider)}];class on{static MAX_GAP_S=60;static FT_TO_M=.3048;static EARTH_RADIUS_KM=6371;static seenFrom(t,e,i){const n=on.positionAt(t,i);if(!n)return;const s=be.seenFrom(e,n.geo);if(!(s.altitudeDeg<0))return{track:t,sky:s,altitudeFt:n.altitudeFt,groundSpeedKt:n.groundSpeedKt,trackDeg:n.trackDeg,angularRateDegPerS:on.angularRate(t,e,i)}}static viewsAt(t,e,i){return t.flatMap(n=>on.seenFrom(n,e,i)??[])}static groundDistanceKm(t,e){const i=Math.PI/180,n=Math.sin((e.lat-t.lat)*i/2)**2+Math.cos(t.lat*i)*Math.cos(e.lat*i)*Math.sin((e.lng-t.lng)*i/2)**2;return 2*on.EARTH_RADIUS_KM*Math.asin(Math.min(1,Math.sqrt(n)))}static wrapLongitude(t){return((t+180)%360+360)%360-180}static positionAt(t,e){const i=t.points;if(i.length===0||e<i[0].t||e>i[i.length-1].t)return;let n=0;for(;n<i.length-1&&i[n+1].t<=e;)n++;const s=i[n],r=i[n+1]??s,o=r.t-s.t;if(o>on.MAX_GAP_S*1e3)return;const c=o>0?(e-s.t)/o:0,l=s.altitudeFt+(r.altitudeFt-s.altitudeFt)*c,h=(r.lng-s.lng+540)%360-180;return{geo:{lat:s.lat+(r.lat-s.lat)*c,lng:on.wrapLongitude(s.lng+h*c),heightM:l*on.FT_TO_M},altitudeFt:l,groundSpeedKt:s.groundSpeedKt,trackDeg:s.trackDeg}}static angularRate(t,e,i){const n=on.positionAt(t,i-500),s=on.positionAt(t,i+500);if(!n||!s)return;const r=on.unit(be.seenFrom(e,n.geo)),o=on.unit(be.seenFrom(e,s.geo)),c=Math.min(1,Math.max(-1,r[0]*o[0]+r[1]*o[1]+r[2]*o[2]));return Math.acos(c)*180/Math.PI}static unit(t){const e=t.altitudeDeg*Math.PI/180,i=t.azimuthDeg*Math.PI/180;return[Math.cos(e)*Math.sin(i),Math.cos(e)*Math.cos(i),Math.sin(e)]}}const Zv="https://ufoathome.org/fireballs/index.json";class Ps{static FIRST_MONTH="2018-12";static STRIKING_MAGNITUDE=-1;static COLOR="#eef2ff";static TRAIN_S=.3;fetchImpl;indexUrls;index;months=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??Ps.defaultIndexUrls()}static defaultIndexUrls(){const t=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&t.push(new URL("/fireballs/index.json",location.href).href),t.includes(Zv)||t.push(Zv),t}static mayCover(t){return new Date(t).toISOString().slice(0,7)>=Ps.FIRST_MONTH}async credit(){return(await this.loadIndex())?.index.credit}async between(t,e){if(!Ps.mayCover(e))return;const i=await this.loadIndex();if(!i)return;const n=new Set([new Date(t).toISOString().slice(0,7),new Date(e).toISOString().slice(0,7)]);return[...n].some(r=>r>=i.index.from&&r<=i.index.to)?(await Promise.all([...n].filter(r=>i.index.months.includes(r)).map(r=>this.monthOf(r,i.base)))).flat().filter(r=>r.t>=t&&r.t<=e):void 0}static seenFrom(t,e){const i=Ps.peakFraction(t),n={lat:t.from[0]+(t.to[0]-t.from[0])*i,lng:t.from[1]+(t.to[1]-t.from[1])*i,heightM:t.peakHeightKm*1e3},s=be.seenFrom(e,n);if(!(s.altitudeDeg<0))return{record:t,peak:s,magnitude:t.peakMagnitude+5*Math.log10(s.distanceKm/be.STANDARD_DISTANCE_KM)}}static asReentry(t,e){const i=t.t-e,n=i+Math.max(t.durationS,.1)*1e3;return{id:`gmn-${t.id}`,track:[{t:i,lat:t.from[0],lng:t.from[1],altitudeKm:t.from[2]},{t:n,lat:t.to[0],lng:t.to[1],altitudeKm:t.to[2]}],fragments:[{absoluteMagnitude:t.peakMagnitude,color:Ps.COLOR,trainS:Ps.TRAIN_S}]}}static peakFraction(t){const e=t.from[2]-t.to[2];return Math.abs(e)<1e-6?.5:Math.min(1,Math.max(0,(t.from[2]-t.peakHeightKm)/e))}loadIndex(){return this.index??=(async()=>{for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(e.ok)return{index:await e.json(),base:t}}catch{}})(),this.index}monthOf(t,e){let i=this.months.get(t);return i||(i=this.fetchImpl(new URL(`${t}.json`,e).href).then(n=>n.ok?n.json():[]).catch(()=>[]),this.months.set(t,i)),i}}const _o=Math.PI/180,Oc=180/Math.PI;class di{constructor(t){this.timeline=t}static DIRECTION_TOLERANCE_DEG=1;static SIZE_TOLERANCE=1.5;static RINGS=12;static SEGMENTS=24;at(t,e,i,n){const s=[];for(const r of e){const o=di.projectionOf(r,i,n?.(r));if(o)for(const c of r.explains){const l=this.timeline.getInterpolatedShapeAt(t,c);!l||l.transparency>=1||s.push({...di.compare(c,r.id,{aim:l.aim,angular:l.angular},o),title:l.title})}}return s}static compare(t,e,i,n){const s=[],r=i.aim?di.separationDeg(i.aim,n.aim):void 0;if(r!==void 0){const l=Math.max(i.angular?.widthDeg??0,n.angular.widthDeg)/2;r>Math.max(di.DIRECTION_TOLERANCE_DEG,l)&&s.push("direction")}const o=i.angular&&i.angular.widthDeg>0?n.angular.widthDeg/i.angular.widthDeg:void 0,c=i.angular&&i.angular.heightDeg>0?n.angular.heightDeg/i.angular.heightDeg:void 0;return o!==void 0&&!di.withinSize(o)&&s.push("width"),c!==void 0&&!di.withinSize(c)&&s.push("height"),{sourceId:t,bodyId:e,stated:i,predicted:n,separationDeg:r,widthRatio:o,heightRatio:c,disagreements:s}}static projectionOf(t,e,i){const n=i&&i.length>0?i:di.outlineOf(t),s=i&&i.length>0?di.centreOf(i):t,r=di.normalized({eastM:s.eastM-e.eastM,northM:s.northM-e.northM,upM:s.upM-e.upM});if(!r)return;const o=di.normalized({eastM:r.northM,northM:-r.eastM,upM:0})??{eastM:1,northM:0,upM:0},c=di.cross(o,r);let l=1/0,h=-1/0,u=1/0,d=-1/0;for(const f of n){const p={eastM:f.eastM-e.eastM,northM:f.northM-e.northM,upM:f.upM-e.upM},v=di.dot(p,r);if(v<=0)return;const m=Math.atan2(di.dot(p,o),v),g=Math.atan2(di.dot(p,c),v);l=Math.min(l,m),h=Math.max(h,m),u=Math.min(u,g),d=Math.max(d,g)}return{aim:{azimuthDeg:(Math.atan2(r.eastM,r.northM)*Oc+360)%360,altitudeDeg:Math.asin(Math.max(-1,Math.min(1,r.upM)))*Oc},angular:{widthDeg:(h-l)*Oc,heightDeg:(d-u)*Oc}}}static centreOf(t){const e=i=>(Math.min(...t.map(n=>n[i]))+Math.max(...t.map(n=>n[i])))/2;return{eastM:e("eastM"),northM:e("northM"),upM:e("upM")}}static separationDeg(t,e){const i=t.altitudeDeg*_o,n=e.altitudeDeg*_o,s=Math.sin(i)*Math.sin(n)+Math.cos(i)*Math.cos(n)*Math.cos((t.azimuthDeg-e.azimuthDeg)*_o);return Math.acos(Math.max(-1,Math.min(1,s)))*Oc}static withinSize(t){return t<=di.SIZE_TOLERANCE&&t>=1/di.SIZE_TOLERANCE}static outlineOf(t){const e=t.sizeM.widthM/2,i=t.sizeM.lengthM/2,n=t.sizeM.heightM/2,s=[],r=t.model.url===void 0?t.model.id:void 0;if(r!==void 0&&r!=="box"&&sy.includes(r))for(let u=0;u<=di.RINGS;u++){const d=u/di.RINGS*Math.PI;for(let f=0;f<di.SEGMENTS;f++){const p=f/di.SEGMENTS*2*Math.PI;s.push([e*Math.sin(d)*Math.cos(p),i*Math.sin(d)*Math.sin(p),n*Math.cos(d)])}}else for(const u of[-e,e])for(const d of[-i,i])for(const f of[-n,n])s.push([u,d,f]);const c=t.attitude.headingDeg*_o,l=t.attitude.pitchDeg*_o,h=t.attitude.rollDeg*_o;return s.map(([u,d,f])=>{const p=u*Math.cos(h)+f*Math.sin(h),v=-u*Math.sin(h)+f*Math.cos(h),m=d*Math.cos(l)-v*Math.sin(l),g=d*Math.sin(l)+v*Math.cos(l);return{eastM:t.eastM+p*Math.cos(c)+m*Math.sin(c),northM:t.northM-p*Math.sin(c)+m*Math.cos(c),upM:t.upM+g}})}static dot(t,e){return t.eastM*e.eastM+t.northM*e.northM+t.upM*e.upM}static cross(t,e){return{eastM:t.northM*e.upM-t.upM*e.northM,northM:t.upM*e.eastM-t.eastM*e.upM,upM:t.eastM*e.northM-t.northM*e.eastM}}static normalized(t){const e=Math.hypot(t.eastM,t.northM,t.upM);return e>1e-9?{eastM:t.eastM/e,northM:t.northM/e,upM:t.upM/e}:void 0}}PM();const GD={sun:"Sun",moon:"Moon",Venus:"Venus",Mars:"Mars",Jupiter:"Jupiter",Saturn:"Saturn"},VD="{name} — mag {mag}, {alt}° above the horizon",WD="{name} — satellite, mag {mag}, {height} km up",XD="satellites-change",YD="fireballs-change",qD="aircraft-change",ly="rr0-confrontation",$D="{name} — mag {mag}, {alt}° below the horizontal",Hf="Credits",Jv="comet:",jv="nova:",Qv={building:"Building",tree:"Tree",shrub:"Shrub",bridge:"Bridge",wire:"Overhead line",crop:"Crop row",terrace:"Terrace (restanque)",mound:"Stone heap",streetlight:"Streetlight",vehicle:"Vehicle",observer:"Observer",aircraft:"Aircraft",entity:"Being"},KD=new URL(""+new URL("lunar-relief.bin-ByThqxUn.gz",import.meta.url).href,import.meta.url).href,ZD=new URL(""+new URL("stars-mag7.5-B43R6Wvg.bin",import.meta.url).href,import.meta.url).href,JD=new URL(""+new URL("stars-mag7.5-9-BLV2tFmZ.bin",import.meta.url).href,import.meta.url).href,jD=-18,QD={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Lh={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class $e extends HTMLElement{creditsButton;set ownCredits(t){this.creditsButton.hidden=!t}static get observedAttributes(){return["src","star-catalog-src","deep-star-catalog-src","show-compass","max-pixel-ratio",ks,Fs]}shadow;stageElement;frameElement;sceneCanvas;loaderNote;loaderNotVideo;ufoElement;sceneRenderer;hoverTooltip;resizeObserver;sizeEstimates=new Map;sizeEstimatesFor;distanceHypotheses=new Map;depths=new Map;directionScratch=new R;meteorScheduleFor;lightningScheduleFor;lightningFlashes=[];lastLightningT;lastTimeMs=0;interpretationShown;confrontationReadings=[];confrontationSignature="";comparing=!1;inTheRound=!0;lastSkyKey;starCatalog;starCatalogRequest=0;static tleArchive=new qi;satellitesFor;satelliteRequest=0;satelliteStatus="none";satellites;satellitePassesMemo;static fireballArchive=new Ps;fireballs;static aircraftProviders=new Map;static SOUND_LOOKBACK_MS=3e5;static NO_CONTRAILS=[];static upperAirProviders=new Map;static NO_PRESENCE=new Map;aircraftSource=HD[0];static trafficRuntimeLoading;static trafficRuntime;static loadTrafficRuntime(){return $e.trafficRuntimeLoading??=je(()=>import("./trafficRuntime-BhspObgN.js"),__vite__mapDeps([2,1]),import.meta.url).then(t=>$e.trafficRuntime=t),$e.trafficRuntimeLoading.catch(()=>{$e.trafficRuntimeLoading=void 0}),$e.trafficRuntimeLoading}traffic;lastSun;decorMemo;seatedMemo;starCatalogDepth=0;weatherAudio=new OD;vehicleAudio=new Wx;aircraftAudio;vehicleHearing=new xu;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=t=>{this.sceneRenderer.setCompassHovered(!0);const e=this.ufoElement.canvasElement,i=e.getBoundingClientRect();if(i.width===0||i.height===0)return;const n=(t.clientX-i.left)/i.width*e.width,s=(t.clientY-i.top)/i.height*e.height;if(this.ufoElement.hasVisibleShapeAt(n,s)){this.hoverTooltip.hidden=!0;return}const r=(t.clientX-i.left)/i.width*2-1,o=-((t.clientY-i.top)/i.height*2-1),c=this.naming,l=c.names,h=this.sceneRenderer.pickBodyAt(r,o);if(h){this.showHoverTooltip(t,this.bodyName(h));return}const u=this.interpretationShown?this.sceneRenderer.pickInterpretationBodyAt(r,o):void 0,d=u?this.interpretationShown?.bodies.find(S=>S.id===u):void 0,f=d?this.said.read(d.title)||(d.model.id==="figure"?c.decorKind("entity",Qv.entity):void 0):void 0;if(f){this.showHoverTooltip(t,f);return}const p=this.sceneRenderer.pickDecorAt(r,o),v=p?this.ufoElement.sighting.decor.find(S=>S.id===p):void 0;if(v){this.showHoverTooltip(t,this.said.read(v.title)||c.decorKind(v.kind,Qv[v.kind]));return}const m=this.trafficTooltipAt(r,o);if(m){this.showHoverTooltip(t,m);return}const g=this.sceneRenderer.pickSatelliteAt(r,o);if(g){this.showHoverTooltip(t,(l?.satelliteTooltip??WD).replace("{name}",g.name).replace("{mag}",g.magnitude.toLocaleString(void 0,{maximumFractionDigits:1})).replace("{height}",Math.round(g.heightKm).toLocaleString()));return}const b=this.sceneRenderer.pickStarAt(r,o);if(b){const S=b.star.mag,M=b.altitudeDeg,x=M<0?l?.starTooltipBelow??$D:l?.starTooltip??VD;this.showHoverTooltip(t,x.replace("{name}",c.star(b.star)).replace("{mag}",S.toLocaleString(void 0,{maximumFractionDigits:Math.abs(S)<1?2:1})).replace("{alt}",String(Math.round(Math.abs(M)))));return}this.hoverTooltip.hidden=!0};bodyName(t){const e=t.startsWith(Jv)?t.slice(Jv.length):void 0,i=e?cy.find(r=>r.id===e):void 0;if(i)return this.naming.comet(i);const n=t.startsWith(jv)?qv.byId(t.slice(jv.length)):void 0;if(n)return this.naming.nova(n);const s=GD[t];return s===void 0?t:this.naming.body(t,s)}get naming(){return this.sceneNaming}sceneNaming=new Xu;namesLanguage="en";async loadSceneNames(){const t=Ep(Gr.preferencesFor(this),Ap);if(t===this.namesLanguage)return;this.namesLanguage=t;const e=await bM(t);t===this.namesLanguage&&this.applySceneNaming(new Xu(e))}renderLoaderText(t,e){let i=0;const n=(s,r)=>{s.setAttribute("aria-label",r),s.replaceChildren(),r.split(" ").forEach((o,c)=>{c>0&&s.append(" ");const l=document.createElement("span");l.className="scene-loader-word",l.setAttribute("aria-hidden","true");for(const h of o){const u=document.createElement("span");u.className="scene-loader-letter",u.style.setProperty("--i",String(i++)),u.textContent=h,l.append(u)}s.append(l),i++})};n(this.loaderNotVideo,t),i+=6,n(this.loaderNote,e)}applySceneNaming(t){this.sceneNaming=t;const e=t.names?.credits??Hf;this.creditsButton.title=e,this.creditsButton.setAttribute("aria-label",e),t.names&&this.renderLoaderText(t.names.notAVideo,t.names.isASimulation),this.sceneRenderer.setCompassPoints(t.names?.compassPoints)}showHoverTooltip(t,e){this.hoverTooltip.textContent=e,this.hoverTooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${t.clientX-i.left+12}px`,this.hoverTooltip.style.top=`${t.clientY-i.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash(t){clearTimeout(this.thunderTimeoutId),this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),Ii.thunderDelayMs(t))}handleFirstInteraction=()=>{this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume(),!this.interacted&&(this.interacted=!0,this.setWeather(Dl(this.ufoElement.sighting,this.lastTimeMs)))};interacted=!1;applyLevel(){const t=this.ufoElement.level;this.weatherAudio.setLevel(t),this.vehicleAudio.setLevel(t),this.aircraftAudio?.setLevel(t)}handlePageGesture=()=>{this.ufoElement.playbackState==="playing"&&this.handleFirstInteraction()};unlockIfAlreadyActivated(){this.interacted||navigator.userActivation?.hasBeenActive&&this.handleFirstInteraction()}static GESTURES=["pointerdown","pointerup","touchend","click","keydown"];handleTimeUpdate=t=>{this.lastTimeMs=t.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.playbackState==="playing"&&this.sceneRenderer.frame(performance.now())};syncAnimationsToPlayback(){const t=this.ufoElement.playbackState==="playing";this.sceneRenderer.setAnimationsRunning(t,t),this.weatherAudio.setPaused(!t),this.vehicleAudio.setPaused(!t),this.aircraftAudio?.setPaused(!t),t&&this.unlockIfAlreadyActivated(),t||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=`<style>${qx}</style>${Yx}`,this.shadow.appendChild(t.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.frameElement=this.shadow.getElementById("frame"),this.sceneCanvas=this.shadow.getElementById("scene-canvas"),this.sceneRenderer=new le(this.sceneCanvas);const e=this.shadow.getElementById("scene-loader");this.loaderNote=this.shadow.getElementById("scene-loader-note"),this.loaderNotVideo=this.shadow.getElementById("scene-loader-not-video"),this.renderLoaderText("This is not a video","It is a real-time simulation."),this.sceneRenderer.onFirstFrameHold=s=>{e.hidden=!s,this.ufoElement.captionHeld=s,this.ufoElement.holdClock(s)},this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Kf),this.ufoElement.classList.add("ufo-overlay"),this.ufoElement.paintsShapes=!1,this.forwardPlayerAttributes(),this.ufoElement.addEventListener("lookat",s=>this.lookToward(s.detail)),this.ufoElement.style.setProperty("--ufo-canvas-background","transparent"),this.ufoElement.style.setProperty("--ufo-canvas-border","none"),this.ufoElement.fullscreenTarget=this.stageElement,this.shadow.getElementById("ufo-slot").replaceWith(this.ufoElement),this.ufoElement.creditShownExternally=!0,this.creditsButton=this.shadow.getElementById("credits-button");const i=this.shadow.getElementById("credits-panel"),n=this.shadow.getElementById("credits-list");i.addEventListener("beforetoggle",s=>{s.newState==="open"&&rn.fill(n,this)}),this.creditsButton.title=Hf,this.creditsButton.setAttribute("aria-label",Hf),this.sceneRenderer.onMapSubjectBounds=s=>this.ufoElement.setMapSubjectBounds(s),this.ufoElement.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.seekPreviewPainter=(s,r)=>this.seekPreviewOf(r).paint(s,r),this.ufoElement.addEventListener("mutedchange",()=>this.applyLevel()),this.ufoElement.ambientSound=s=>s.vehicle!==void 0||s.decor.some(r=>r.engine!==void 0)||s.weatherTrack.allKeyframes.some(r=>r.weather.precipitationType!=="none"||r.weather.windSpeed>1),this.ufoElement.addEventListener("referenceview",s=>this.applyReferenceView(s.detail)),this.ufoElement.addEventListener("traceview",s=>this.sceneRenderer.setTracesShown(s.detail.shown)),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave);for(const s of $e.GESTURES)this.addEventListener(s,this.handleFirstInteraction,!0)}get said(){return this.saidTexts??=new Yn(Gr.preferencesFor(this))}saidTexts;traceLabelsFor;traceLabels(t){const e=Gr.preferencesFor(this).join();if(this.traceLabelsFor?.traces!==t||this.traceLabelsFor.language!==e){const i=new Map;for(const n of t){const s=this.said.read(n.title);s&&i.set(n.id,s)}this.traceLabelsFor={traces:t,language:e,labels:i}}return this.traceLabelsFor.labels}connectedCallback(){this.saidTexts=void 0,this.loadSceneNames(),this.sceneRenderer.restoreContext(),this.resizeToStage(),this.updateAstronomy(this.lastTimeMs),this.loadStars(),this.resizeObserver=new ResizeObserver(()=>this.resizeToStage()),this.resizeObserver.observe(this.frameElement),this.watchVisibility(),document.addEventListener("fullscreenchange",this.handleFullscreenChange);for(const e of $e.GESTURES)document.addEventListener(e,this.handlePageGesture,!0);const t=this.getAttribute("src");t&&this.loadFromSrc(t)}watchVisibility(){this.visibilityObserver?.disconnect(),!(typeof IntersectionObserver>"u")&&(this.visibilityObserver=new IntersectionObserver(t=>{if(t[t.length-1].isIntersecting){this.sceneRenderer.resume();return}this.ufoElement.pause(),this.sceneRenderer.suspend()},{rootMargin:"100px"}),this.visibilityObserver.observe(this))}visibilityObserver;disconnectedCallback(){this.visibilityObserver?.disconnect(),this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange);for(const t of $e.GESTURES)document.removeEventListener(t,this.handlePageGesture,!0);this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose(),this.vehicleAudio.dispose(),this.aircraftAudio?.dispose(),this.seekPreview?.dispose(),this.seekPreview=void 0,queueMicrotask(()=>{this.isConnected||this.sceneRenderer.releaseContext()})}attributeChangedCallback(t,e,i){if(t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),(t==="star-catalog-src"||t==="deep-star-catalog-src")&&i!==e&&this.isConnected&&this.loadStars(),t==="show-compass"&&i!==e&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),t==="max-pixel-ratio"&&i!==e){const n=Number(i);this.sceneRenderer.setMaxPixelRatio(Number.isFinite(n)&&n>0?n:Math.min(window.devicePixelRatio||1,2))}(t===ks||t===Fs)&&i!==e&&this.forwardPlayerAttributes()}forwardPlayerAttributes(){for(const t of[ks,Fs]){const e=this.getAttribute(t);e===null?this.ufoElement.removeAttribute(t):this.ufoElement.setAttribute(t,e)}}setCompassForced(t){this.sceneRenderer.setCompassForced(t)}lookToward(t){const e=Ze(this.ufoElement.sighting,this.lastTimeMs);if(t.kind==="observer"||e?.lat===void 0||e.lng===void 0||e.headingDeg===void 0){this.setLookOffset(0,0);return}const{x:i,z:n}=si(t.lat,t.lng,e.lat,e.lng);if(Math.hypot(i,n)<1)return this.setLookOffset(0,0);const s=(Math.atan2(i,-n)*180/Math.PI+360)%360;this.setLookOffset(((s-e.headingDeg)%360+540)%360-180,-e.pitchDeg)}setLookOffset(t,e){this.sceneRenderer.setLookOffset(t,e),this.ufoElement.setLookOffset(t,e),this.updateAstronomy(this.lastTimeMs)}setIndoorLook(t,e){this.sceneRenderer.setIndoorLook(t,e)}setCloudRendering(t){this.sceneRenderer.setCloudRendering(t)}setWeather(t){this.sceneRenderer.setWeather(t),this.weatherAudio.setAmbient(t.precipitationType,t.precipitationIntensity*(t.precipitationAmount??1),t.windSpeed)}pickCloudAt(t,e){return this.sceneRenderer.pickCloudAt(t,e)}cloudDirectionAt(t,e){return this.sceneRenderer.cloudDirectionAt(t,e)}pickDecorAt(t,e){return this.sceneRenderer.pickDecorAt(t,e)}decorScreenBox(t){return this.sceneRenderer.decorScreenBox(t)}decorGroundPointAt(t,e,i,n=0){return this.sceneRenderer.decorGroundPointAt(t,e,i,n)}decorMetresPerNdcY(t){return this.sceneRenderer.decorMetresPerNdcY(t)}decorGrabHeightAt(t,e,i){return this.sceneRenderer.decorGrabHeightAt(t,e,i)}bodyScreenBox(t){return this.sceneRenderer.bodyScreenBox(t)}pickPlacedBodyAt(t,e){return this.sceneRenderer.pickPlacedBodyAt(t,e)}resumeWeatherAudio(){this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume()}async loadFromSrc(t){const e=Gc.json(t);this.holdForNewScene(e);const i=await e;this.documentUrl=new URL(t,location.href).href,this.sightingData=i}holdForNewScene(t){this.sceneRenderer.holdForNewScene(t)}get documentUrl(){return this.sceneRenderer.documentUrl}set documentUrl(t){this.sceneRenderer.documentUrl=t}get sightingData(){return this.ufoElement.sightingData}set sightingData(t){this.ufoElement.sightingData=t,this.seekPreview?.recordingChanged(t),this.interpretationShown=this.inTheRound?this.ufoElement.sighting.interpretation:void 0,this.syncAccountHidden(),this.applyFrameFormat(),this.lastTimeMs=0,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(0)}seekPreview;seekPreviewOf(t){const e=this.sceneCanvas.width>0&&this.sceneCanvas.height>0?this.sceneCanvas.width/this.sceneCanvas.height:1.7777777777777777,i=Math.round(t.width/e);return t.height!==i&&(t.height=i),this.seekPreview??=new Wu(this,()=>document.createElement(qu))}showAt(t){this.ufoElement.currentTime=t,this.framesAtAsk=this.sceneRenderer.framesDrawn}framesAtAsk=0;snapshotTo(t){if(this.sceneRenderer.frame(performance.now()),this.sceneRenderer.framesDrawn===this.framesAtAsk)return!1;const e=t.getContext("2d");return e?(e.drawImage(this.sceneCanvas,0,0,t.width,t.height),!0):!1}referenceAspect(t){return this.sceneRenderer.referenceAspect(t)}screenPointOf(t){return this.sceneRenderer.screenPointOf(t)}directionAt(t,e){return this.sceneRenderer.directionAt(t,e)}referenceFailedToLoad(t){return this.sceneRenderer.referenceFailedToLoad(t)}applyReferenceView(t){this.sceneRenderer.setReferencesShown(t.shown);for(const e of this.ufoElement.sighting.references){const i=t.views?.[e.id];this.sceneRenderer.setReferenceView(e.id,{opacity:i?i.shown?i.opacity:0:t.opacity})}}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}get currentRoadAttribution(){return this.sceneRenderer.currentRoadAttribution}setTerrainProviders(t){this.sceneRenderer.setTerrainProviders(t)}setDecorModelProvider(t){this.sceneRenderer.setDecorModelProvider(t)}get decorModelCredits(){return[...new Map(this.sceneRenderer.currentDecorModelCredits.map(e=>[`${e.title}|${e.author??""}|${e.license}|${e.sourceUrl??""}`,e])).values()]}applyFrameFormat(){const t=this.ufoElement.sighting.instrument,e=Fe.CANVAS_HEIGHT_PX,i=bi.frameWidthPx(t,e);this.frameElement.style.setProperty("--frame-aspect",`${i} / ${e}`)}resizeToStage(){const t=this.frameElement.getBoundingClientRect(),e=Math.max(1,Math.round(t.width)),i=Math.max(1,Math.round(t.height));this.sceneCanvas.width=e,this.sceneCanvas.height=i,this.sceneRenderer.resize(e,i)}async loadStars(){const t=[{magnitudeLimit:kf,url:this.getAttribute("star-catalog-src")??ZD},{magnitudeLimit:Ff,url:this.getAttribute("deep-star-catalog-src")??JD}],e=this.instrumentReach(),i=++this.starCatalogRequest;this.starCatalogDepth=e>kf?Ff:kf;const n=await _s.upTo(t,e);i===this.starCatalogRequest&&(this.starCatalog=n,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(this.lastTimeMs))}ensureStarsDeepEnough(){!this.starCatalog||this.starCatalogDepth>=Ff||this.instrumentReach()<=this.starCatalogDepth||this.loadStars()}instrumentReach(){const t=this.ufoElement.sighting,e=an.gainFor(t.instrument,{fNumber:Ze(t,0)?.fNumber,fieldOfViewDeg:xn.fovOf(t,0),exposureSeconds:t.exposure});return Kh(jD,e)}updateAstronomy(t){this.ensureStarsDeepEnough(),this.applySceneAt(t);const e=as.windowEndingAt(t,this.exposureSeconds()),i=e.seconds,n=this.degreesPerPixelAt(t),s=Ua.instants(i,n),r=Math.max(s,this.ufoElement.exposureTimes(t).length,as.instants(this.decorWithTraffic(this.ufoElement.sighting),Ze(this.ufoElement.sighting,t)?.elevationM??0,e.fromMs,i,n));if(r<=1){this.sceneRenderer.setExposure(1);return}this.sceneRenderer.setExposure(r,o=>this.applySceneAt(e.fromMs+e.ms*o/(r-1),{sky:Math.floor(o*s/r)!==Math.floor((o-1)*s/r),stepMs:e.ms/r}))}exposureSeconds(){return this.ufoElement.sighting.exposure??0}degreesPerPixelAt(t){const e=this.sceneCanvas.height;return e<=0?0:xn.fovOf(this.ufoElement.sighting,t)/e}roadGradeAt(t,e){return t.observerTrack.allKeyframes.length<2?0:Ro.at(t,e,this.sceneRenderer.bodyGround)}get roadGradeDeg(){return this.roadGradeAt(this.ufoElement.sighting,this.ufoElement.currentTime)}applySceneAt(t,e){const i=this.ufoElement.sighting;this.setWeather(Dl(i,t)),this.sceneRenderer.setInstrument(i.instrument),this.sceneRenderer.setLightPollution(i.lightPollution),e||this.vehicleAudio.setVoices(this.vehicleHearing.at(i,t)),e||this.pushAircraftSound(i,t),this.updateMeteorShower(i,t),this.updateLightning(i,t,e!==void 0),this.sceneRenderer.setDecor(this.seatedDecor(this.decorWithTraffic(i),t)),this.sceneRenderer.setDecorPresence(this.traffic?.set?.presence??$e.NO_PRESENCE),this.sceneRenderer.setDecorSunlight(this.trafficSunlight(t)),this.sceneRenderer.setContrails(this.traffic?.contrails??$e.NO_CONTRAILS),this.sceneRenderer.setContrailSunlight(this.contrailSunlight(t));const n=Ze(i,t);this.sceneRenderer.setReferences(i.references,n?.lat!==void 0&&n.lng!==void 0?{lat:n.lat,lng:n.lng}:void 0);const s=Ze(i,0),r=Eo(i,0),o=ra(i.event.time??{},n?.lng??Lh.lng,i.event.utcOffsetHours),c=i.weatherSource!==void 0&&o?Xx(o):void 0,l=Object.fromEntries(Qh(Eo(i,t)).map(T=>[T.id,eg(t,i.weatherTrack,r,s,n,T.id,T.instances?.length?void 0:c)]));this.sceneRenderer.setCloudOffset(eg(t,i.weatherTrack,r,s,n,void 0,c),l),this.sceneRenderer.setObserverPose(n?{...n,pitchDeg:n.pitchDeg+this.roadGradeAt(i,t)}:Lh),this.sceneRenderer.setLensOptics(this.lensOpticsAt(t)),this.sceneRenderer.setInstrumentGain(an.gainFor(i.instrument,{fNumber:n?.fNumber,fieldOfViewDeg:xn.fovOf(i,t),exposureSeconds:i.exposure}),i.instrument.detailUm!==void 0,ls.byId(n?.filter).opticalDensity),this.sceneRenderer.setMedium(i.instrument.medium,i.exposure,n?.fNumber??i.instrument.fNumber,i.iso),this.sceneRenderer.setGait(Ce.bodyAt(i,t,this.ufoElement.steadyBody)),this.sceneRenderer.updateDecorAnchoring(Ze(i,0),n,t),this.placeBodiesAt(t,e===void 0),this.sceneRenderer.updateDecorLitState(t,e?.stepMs??0),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng,()=>{this.placeBodiesAt(this.lastTimeMs,!0),this.sceneRenderer.render()}),this.sceneRenderer.setStatedRoads(i.roads),this.sceneRenderer.setTraces(i.traces,this.traceLabels(i.traces)),this.pushPhenomenaAt(t);const h=n?.lat??Lh.lat,u=n?.lng??Lh.lng,d=ra(i.event.time??{},u,i.event.utcOffsetHours),f={lat:h,lng:u,elevationM:n?.elevationM??0};this.pushSatellitesAt(d,t,f),this.ensureFireballs(d);const p=[...this.interpretationShown?.reentries??[],...this.fireballs?.reentries??[]];if(this.sceneRenderer.setReentries(p.length===0?[]:be.viewsAt(p,t,{lat:h,lng:u,heightM:f.elevationM})),e&&!e.sky)return;if(!d){this.sceneRenderer.setAstronomy(QD);return}const v=new Date(d.getTime()+t),m=Math.max(1,Math.round(.25*this.degreesPerPixelAt(t)/Ua.DEG_PER_SECOND*1e3)),g=Math.max(1e-8,this.degreesPerPixelAt(t)*.1),b=`${Math.floor(v.getTime()/m)}|${Math.round(h/g)}|${Math.round(u/g)}|${Math.round(f.elevationM)}|${this.starCatalog?this.starCatalogDepth:0}`;if(b===this.lastSkyKey){this.sceneRenderer.render();return}this.lastSkyKey=b;const S=xh("Sun",v,f),M=xh("Moon",v,f);let x=Mi.separationOf(S,M)<1?Mi.viewAt(v,f):void 0;if(x){const T=Mi.offsetOf(S,M,x.separationDeg);if(x.obscuration>$e.LIMB_FROM_OBSCURATION){const I=this.limbFor(v,f);I&&(x={...x,obscuration:1-Vn.uncoveredFraction(I,x.sunRadiusDeg,T),limb:I})}x={...x,horizonShare:Mi.horizonShare(x,T,S.altitudeDeg,S.azimuthDeg,Cs.distanceKm(v,f))}}const _={...S,magnitude:uf("Sun",v)-2.5*Math.log10(Mi.beamFraction(x))};this.lastSun={altitudeDeg:_.altitudeDeg,azimuthDeg:_.azimuthDeg};const E={...M,phase:R4(v),magnitude:uf("Moon",v),radiusDeg:Cs.apparentRadiusDeg(v,f)},y=T4.map(T=>({body:T,position:xh(T,v,f),magnitude:uf(T,v)}));this.sceneRenderer.setAstronomy({sun:_,moon:E,planets:y,comet:this.cometAt(v,f),novae:qv.appearancesAt(v,f).map(({outburst:T,position:I,magnitude:C})=>({id:T.id,position:I,magnitude:C})),stars:this.starCatalog?{catalog:this.starCatalog,date:v,observer:f}:void 0,frame:{date:v,observer:f},eclipse:x}),this.ufoElement.setSunAltitude(_.altitudeDeg)}static LIMB_FROM_OBSCURATION=.98;limbRelief;limbRequested=!1;limbCache;limbFor(t,e){if(!this.limbRelief){this.limbRequested||(this.limbRequested=!0,Qc.load(KD).then(s=>{this.limbRelief=s,this.lastSkyKey="",s&&this.isConnected&&this.updateAstronomy(this.lastTimeMs)}));return}const i=this.limbCache;if(i&&Math.abs(t.getTime()-i.atMs)<5e3&&i.lat===e.lat&&i.lng===e.lng&&i.elevationM===e.elevationM)return i.profile;const n=Vn.profile(t,e,this.limbRelief);return this.limbCache={profile:n,atMs:t.getTime(),lat:e.lat,lng:e.lng,elevationM:e.elevationM},n}pushSatellitesAt(t,e,i){if(this.ensureSatellites(t),!t||!this.satellites){this.sceneRenderer.setSatellites([]);return}const n=new Date(t.getTime()+e),s=[];for(const r of this.satellites.passes.positionsAt(n,i,-1))r.magnitude!==void 0&&s.push({norad:r.object.norad,name:r.object.name,position:{altitudeDeg:r.altitudeDeg,azimuthDeg:r.azimuthDeg},magnitude:r.magnitude,heightKm:r.heightKm});this.sceneRenderer.setSatellites(s)}ensureFireballs(t){const e=this.ufoElement.sighting,i=Math.max((e.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),n=t?.getTime(),s=n===void 0?"":`${n}+${i}`;if(this.fireballs?.key===s)return;if(n===void 0||!Ps.mayCover(n+i)){this.fireballs={key:s,status:"outside",reentries:[]};return}const r={key:s,status:"loading",reentries:[]};this.fireballs=r,$e.fireballArchive.between(n,n+i).then(o=>{r.status=o?"ready":"unavailable",r.records=o??[],r.reentries=r.records.map(c=>Ps.asReentry(c,n)),!(this.fireballs!==r||!this.isConnected)&&(this.dispatchEvent(new CustomEvent(YD)),r.reentries.length>0&&this.updateAstronomy(this.lastTimeMs))})}decorWithTraffic(t){const e=this.ensureTraffic(t);if(!e||e.objects.length===0)return t.decor;const i=this.decorMemo;if(i&&i.base===t.decor&&i.traffic===e.objects)return i.merged;const n=[...t.decor,...e.objects];return this.decorMemo={base:t.decor,traffic:e.objects,merged:n},n}seatedDecor(t,e){if(!t.some(r=>r.observerKeyframes?.length))return t;const i=t.map(r=>{if(!r.observerKeyframes?.length)return"";const o=Ym(r,e);return`${o.side??"-"}/${o.facing??"-"}`}).join("|"),n=this.seatedMemo;if(n&&n.base===t&&n.seats===i)return n.seated;const s=t.map(r=>{if(!r.observerKeyframes?.length)return r;const o=Ym(r,e);return{...r,observerSide:o.side,observerFacing:o.facing}});return this.seatedMemo={base:t,seats:i,seated:s},s}ensureTraffic(t){const e=Ze(t,0),i=e?.lng===void 0?void 0:ra(t.event.time??{},e.lng,t.event.utcOffsetHours),n=Math.max((t.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),s=i?.getTime(),r=s===void 0||e?.lat===void 0||e.lng===void 0?"":`${this.aircraftSource.id}|${s}+${n}|${e.lat.toFixed(3)},${e.lng.toFixed(3)}|${Math.round(e.elevationM??0)}`;if(this.traffic?.key===r)return this.traffic.set;if(r===""||s===void 0||e?.lat===void 0||e.lng===void 0){this.traffic={key:r,status:"outside"};return}let o=$e.aircraftProviders.get(this.aircraftSource.id);if(o||$e.aircraftProviders.set(this.aircraftSource.id,o=this.aircraftSource.create()),o.mayCover&&!o.mayCover(s+n)){this.traffic={key:r,status:"outside"};return}const c={key:r,status:"loading",startMs:s,observer:{lat:e.lat,lng:e.lng}};this.traffic=c;const l={lat:e.lat,lng:e.lng,heightM:e.elevationM??0},h=on.MAX_GAP_S*1e3,u=$e.SOUND_LOOKBACK_MS,d={lat:e.lat,lng:e.lng,elevationM:e.elevationM??0},f=(p,v)=>p.TrafficDecor.from(c.tracks??[],l,s,p.TrafficDecor.MAX_OBJECTS,{models:v,sunElevationAt:m=>this.sunElevationAt(m,d)});o.between(l,s-u,s+n+h).then(async p=>{if(this.traffic!==c)return;if(p.status!=="found"){c.status=p.status==="outside"?"outside":"unavailable",this.announceTraffic();return}let v;try{v=await $e.loadTrafficRuntime()}catch{this.traffic===c&&(c.status="unavailable",this.announceTraffic());return}this.traffic===c&&(c.status="ready",c.tracks=p.tracks,c.set=f(v),this.startAircraftSound(c,v),this.announceTraffic(),this.describeTraffic(o,c,v,f),c.set.shown>0&&this.readUpperAir(c,v,s-u,s+n+h))})}trafficSunlight(t){const e=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||i.startMs===void 0||!i.observer)return e;for(const[r,o]of n.presence){if(t<o.fromMs||t>o.untilMs)continue;const c=n.flights.get(r),l=c?on.positionAt(c,i.startMs+t):void 0;l&&e.set(r,{heightM:l.geo.heightM,sunElevationDeg:Pn.sunElevationDeg(s,i.observer,l.geo)})}return e}trafficTooltipAt(t,e){const i=this.sceneRenderer.pickTrafficAt(t,e),n=i?this.trafficInfoAt(i):void 0;if(!n)return;const s=this.naming,r=$e.trafficRuntime;return r?.TrafficTooltip.text(n,s.names?.trafficTooltip??r.TrafficTooltip.ENGLISH,o=>s.towards(o))}trafficInfoAt(t){const e=this.traffic,i=e?.set?.flights.get(t);if(!e||!i||e.startMs===void 0||!e.observer)return;const n=$e.trafficRuntime;if(!n)return;const s=e.descriptions?.get(Xn.keyOf(i)),r=Ze(this.ufoElement.sighting,this.lastTimeMs),o={lat:e.observer.lat,lng:e.observer.lng,heightM:r?.elevationM??0},c=n.AmbientNoise.dbA(Dl(this.ufoElement.sighting,this.lastTimeMs)),l=n.TrafficInfos.at(i,s,o,e.startMs+this.lastTimeMs,{ambientDbA:c}),h=l&&this.contrailAt(t,this.lastTimeMs);return l&&h?{...l,contrail:h}:l}contrailAt(t,e){const i=this.traffic?.contrails?.find(s=>s.id===t);if(!i)return;let n;for(const s of i.points){if(s.tMs>e)break;n=s}return n?.forms?{persistent:n.persistent,iceRelativeHumidity:n.iceRelativeHumidity}:void 0}startAircraftSound(t,e){this.aircraftAudio||(this.aircraftAudio=new e.AircraftAudio,this.aircraftAudio.setLevel(this.ufoElement.level),this.interacted&&this.aircraftAudio.resume(),this.aircraftAudio.setPaused(this.ufoElement.playbackState!=="playing")),this.sortOutAudible(t,e)}sortOutAudible(t,e){!t.set||!t.observer||(t.audible=e.TrafficSound.candidates(t.set.flights,t.descriptions??new Map,Xn.keyOf,{...t.observer,heightM:0},{ambientDbA:e.AmbientNoise.BASE_DB_A}))}pushAircraftSound(t,e){const i=this.aircraftAudio;if(!i)return;const n=$e.trafficRuntime,s=this.traffic,r=s?.set;if(!n||!s||!r||!s.audible||s.startMs===void 0||!s.observer){i.setVoices([]);return}const o=Ze(t,e),c={lat:s.observer.lat,lng:s.observer.lng,heightM:o?.elevationM??0},l=Dl(t,e),h=n.TrafficSound.voices(s.audible,r.flights,s.descriptions??new Map,Xn.keyOf,c,s.startMs+e,{ambientDbA:n.AmbientNoise.dbA(l),referenceAmplitude:n.AmbientNoise.referenceAmplitude(l)});i.setVoices(h,o?.headingDeg??0)}announceTraffic(){this.isConnected&&(this.dispatchEvent(new CustomEvent(qD)),this.updateAstronomy(this.lastTimeMs))}async describeTraffic(t,e,i,n){if(!t.describe||!e.set||!e.tracks)return;const s=new Set([...e.set.flights.values()].map(l=>Xn.keyOf(l))),r=e.tracks.filter(l=>s.has(Xn.keyOf(l))&&l.points.length>0),o=new Map,c=new Map;await Promise.all(r.map(async l=>{const h=new Date(l.points[0].t).toISOString().slice(0,10),u=await t.describe(l,h).catch(()=>{});u&&(c.set(Xn.keyOf(l),u),o.set(Xn.keyOf(l),i.AircraftModels.of(u)))})),!(this.traffic!==e||o.size===0)&&(e.descriptions=c,e.models=o,e.set=n(i,o),this.planContrails(e,i),this.sortOutAudible(e,i),this.announceTraffic())}async readUpperAir(t,e,i,n){if(!t.observer)return;const s=this.upperAirSource??e.UPPER_AIR_SOURCES[0];let r=$e.upperAirProviders.get(s.id);r||$e.upperAirProviders.set(s.id,r=s.create());const o=await r.between(t.observer,i,n);this.traffic!==t||o.status!=="found"||(t.air=o.samples,t.airSource=o.source,this.planContrails(t,e),this.announceTraffic())}planContrails(t,e){!t.set||!t.air||t.startMs===void 0||(t.contrails=e.AircraftContrails.plan(t.set,t.models,t.air,t.startMs))}contrailSunlight(t){const e=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||!i.contrails?.length||i.startMs===void 0||!i.observer)return e;for(const r of i.contrails){const o=n.presence.get(r.id),c=n.flights.get(r.id);if(!o||!c)continue;const l=on.positionAt(c,i.startMs+Math.min(o.untilMs,Math.max(o.fromMs,t)));l&&e.set(r.id,{heightM:l.geo.heightM,sunElevationDeg:Pn.sunElevationDeg(s,i.observer,l.geo)})}return e}sunElevationAt(t,e){const i=xh("Sun",new Date(t.t),e);return Pn.sunElevationDeg(i,e,t)}upperAirSource;setUpperAirSource(t){t.id!==this.upperAirSource?.id&&(this.upperAirSource=t,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}setAircraftSource(t){t.id!==this.aircraftSource.id&&(this.aircraftSource=t,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}get aircraftState(){const t=this.traffic?.contrails?.length?this.upperAirSource??$e.trafficRuntime?.UPPER_AIR_SOURCES[0]:void 0;return{trailCredit:t&&{credit:t.credit,creditUrl:t.creditUrl},status:this.traffic?.status??"none",total:this.traffic?.set?.total??0,shown:this.traffic?.set?.shown??0,credit:this.aircraftSource.credit,creditUrl:this.aircraftSource.creditUrl}}get fireballState(){return{status:this.fireballs?.status??"none",records:this.fireballs?.records??[]}}ensureSatellites(t){const e=t?String(t.getTime()):"";if(e===this.satellitesFor)return;this.satellitesFor=e,this.satellites=void 0,this.satellitePassesMemo=void 0;const i=++this.satelliteRequest;if(!t){this.satelliteStatus="none";return}this.satelliteStatus="loading";const n=r=>{i===this.satelliteRequest&&(this.satelliteStatus=r,this.isConnected&&this.dispatchEvent(new CustomEvent(XD)))},s=$e.tleArchive;(async()=>{if(!await s.covers(t))return n("outside");const[r,o]=await Promise.all([s.at(t),je(()=>import("./SatellitePasses-Pfro2-0Z.js"),[],import.meta.url)]);if(i===this.satelliteRequest){if(!r)return n("unavailable");this.satellites={snapshot:r,passes:new o.SatellitePasses(r.objects)},n("ready"),this.isConnected&&this.updateAstronomy(this.lastTimeMs)}})().catch(()=>n("unavailable"))}get satelliteState(){const t=this.satellites?.snapshot;return{status:this.satelliteStatus,coverage:t?.coverage,credit:t?.credit,creditUrl:t?.creditUrl}}satellitePassesDuring(t){const e=this.satellites,i=this.ufoElement.sighting,n=Ze(i,0),s=i.event.place?.[0],r=n?.lat??s?.lat,o=n?.lng??s?.lng;if(!e||r===void 0||o===void 0)return[];const c=ra(i.event.time??{},o,i.event.utcOffsetHours);if(!c)return[];const l=Math.min(Math.max(t,0),4*36e5),h={lat:r,lng:o,elevationM:n?.elevationM??0},u=JSON.stringify([this.satellitesFor,c.getTime(),r,o,h.elevationM,l]);if(this.satellitePassesMemo?.key===u)return this.satellitePassesMemo.passes;const d=Math.max(10,Math.ceil(l/1e3/600)),f=e.passes.passesDuring(c,new Date(c.getTime()+l),h,d);return this.satellitePassesMemo={key:u,passes:f},f}cometAt(t,e){const i=LD.brightestAt(t,e);if(i)return{id:i.apparition.id,position:i.position,tailEnd:i.tailEnd,magnitude:i.magnitude}}pushPhenomenaAt(t){const e=this.ufoElement.sighting;e!==this.sizeEstimatesFor&&(this.sizeEstimates.clear(),this.distanceHypotheses.clear(),this.sizeEstimatesFor=e);const i=e.timeline,n=this.ufoElement.canvasElement,s=this.ufoElement.frameShiftPx,r=this.projectionAt(t),o=new Map,c=new Map,l=new Set;for(const p of i.sourceIds){const v=i.getInterpolatedShapeAt(t,p);if(!v)continue;const m={...v,bounds:{...v.bounds,x:v.bounds.x+s.x,y:v.bounds.y+s.y}};o.set(p,m);const g=v.aim?this.sceneRenderer.screenPointOf(ss.directionOf(v.aim,this.directionScratch)):{ndcX:(m.bounds.x+m.bounds.width/2)/n.width*2-1,ndcY:-((m.bounds.y+m.bounds.height/2)/n.height*2-1)},b=g!==void 0&&Math.abs(g.ndcX)<=1&&Math.abs(g.ndcY)<=1,S=b?this.sceneRenderer.decorDistancesAt(g.ndcX,g.ndcY,p):{};l.add(p),(b||v.aim)&&l.delete(p);const M=v.angular?.widthDeg??r.pxToDeg(v.bounds.width),x=this.sizeEstimateOf(p);x.add(M,S);const _=tl.of(e,p);c.set(p,sn.resolve({hypothesisM:this.distanceHypotheses.get(p),derivedM:_&&M>0?Fe.distanceMAt(_.widthM,M):void 0,range:x.distanceRangeAt(M),crossing:S}))}for(const[p,v]of o)for(const[m,g]of o){if(m===p||g.transparency>=1||g.bounds.width*g.bounds.height<=v.bounds.width*v.bounds.height||!(v.bounds.x>=g.bounds.x&&v.bounds.y>=g.bounds.y&&v.bounds.x+v.bounds.width<=g.bounds.x+g.bounds.width&&v.bounds.y+v.bounds.height<=g.bounds.y+g.bounds.height))continue;const S=c.get(m);S&&c.set(p,{distanceM:S.distanceM*.999,basis:S.basis});break}this.depths=c;const h=i.sourceIds,u=[];for(const[p,v]of o)u.push({sourceId:p,shape:v,distanceM:c.get(p).distanceM,renderOrder:h.indexOf(p),aim:v.aim,hidden:l.has(p)||this.interpretationShown!==void 0&&(!this.comparing||v.transparency>=1),ghost:this.interpretationShown!==void 0&&this.comparing});const f=(Ze(e,t)?.rollDeg??0)+Ce.bodyAt(e,t,this.ufoElement.steadyBody).rollDeg;this.sceneRenderer.setPhenomena(u,{projection:r,canvasWidthPx:n.width,canvasHeightPx:n.height,scale:Math.max(1,this.sceneCanvas.height/Math.max(1,n.height)),starPoints:bi.starPointsOf(e.instrument),rollRad:f*Math.PI/180})}get interpretation(){return this.interpretationShown}set interpretation(t){this.interpretationShown=t,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs)}syncAccountHidden(){this.ufoElement.accountHidden=this.interpretationShown!==void 0&&!this.comparing}get accountInTheRound(){return this.inTheRound}set accountInTheRound(t){this.inTheRound=t}get compareAccount(){return this.comparing}set compareAccount(t){this.comparing=t,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs)}get confrontation(){return this.confrontationReadings}groundAlong(t,e,i){const n=this.sceneRenderer.bodyGround,s=ce.eyeOf(this.ufoElement.sighting,i,n);return s?ce.lineOfSightMeetsGround(s,t,e,n):void 0}bodyReading(t,e){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=d=>ce.eyeOf(n,d,i),r=new ce(t,i,s).at(e),o=s(e);if(!r||!o)return;const c=r.eastM-o.eastM,l=r.northM-o.northM,h=r.upM-o.upM,u=Math.hypot(c,l);return{azimuthDeg:(Math.atan2(c,l)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(h,u)*180/Math.PI,distanceM:Math.hypot(u,h),eastM:r.eastM,northM:r.northM,aboveGroundM:r.upM-r.sizeM.heightM/2-i.heightAt(r.eastM,r.northM),sizeM:r.sizeM,attitude:r.attitude,appearance:r.appearance}}directionToBody(t,e){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=p=>ce.eyeOf(n,p,i),r=new ce(t,i,s),o=r.at(e)?e:t.track[0]?.t,c=o===void 0?void 0:r.at(o),l=o===void 0?void 0:s(o);if(!c||!l)return;const h=c.eastM-l.eastM,u=c.northM-l.northM,d=c.upM-l.upM,f=Math.hypot(h,u);if(!(f===0&&d===0))return{azimuthDeg:(Math.atan2(h,u)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(d,f)*180/Math.PI}}placeBodiesAt(t,e){const i=this.interpretationShown,n=this.ufoElement.sighting;let s=[],r=[];const o=this.sceneRenderer.bodyGround,c=p=>ce.eyeOf(n,p,o);i&&(s=i.bodies.map(p=>new ce(p,o,c).at(t)).filter(p=>p!==void 0));const l=Eo(n,t),h=l.windDirectionDeg*Math.PI/180,u={x:l.windSpeed*Math.sin(h),z:-l.windSpeed*Math.cos(h)};this.sceneRenderer.setBodies(s,t/1e3,i?.bodies.map(p=>p.id)??[],i?.smoke??[],u);const d=i&&this.comparing?c(t):void 0;if(d&&(r=new di(n.timeline).at(t,s,d,p=>p.outlineNode?this.sceneRenderer.bodyOutline?.(p.id,p.outlineNode):void 0)),this.confrontationReadings=r,!e)return;const f=JSON.stringify(r);f!==this.confrontationSignature&&(this.confrontationSignature=f,this.dispatchEvent(new CustomEvent(ly,{detail:r})))}setDistanceHypothesis(t,e){e===void 0||!(e>0)?this.distanceHypotheses.delete(t):this.distanceHypotheses.set(t,e),this.updateAstronomy(this.lastTimeMs)}depthOf(t){return this.depths.get(t)}sizeRangeOf(t){return this.sizeEstimateOf(t).sizeRange}distanceRangeAt(t,e){const i=this.ufoElement.sighting.timeline.getInterpolatedShapeAt(e,t);if(!i)return{};const n=i.angular?.widthDeg??this.projectionAt(e).pxToDeg(i.bounds.width);return this.sizeEstimateOf(t).distanceRangeAt(n)}sizeContradictory(t){return this.sizeEstimateOf(t).contradictory}updateMeteorShower(t,e){this.ensureMeteorSchedule(t),this.sceneRenderer.updateMeteors(e)}updateLightning(t,e,i){if(this.ensureLightningSchedule(t),this.sceneRenderer.updateLightning(e),i)return;const n=this.lastLightningT;if(this.lastLightningT=e,n===void 0||e<n||this.ufoElement.playbackState!=="playing")return;const s=this.lightningFlashes.filter(r=>r.t>n&&r.t<=e).pop();s&&Eo(t,s.t).storm&&this.handleLightningFlash(s)}ensureLightningSchedule(t){const e=Eo(t,0).precipitationIntensity,i=`${this.meteorInputsOf(t)}|${e}`;if(i===this.lightningScheduleFor)return;this.lightningScheduleFor=i;const n=t.event.time,s=t.event.place?.[0],r=n?.year!==void 0?ra(n,s?.lng??0,t.event.utcOffsetHours):void 0,o=(t.event.durationSeconds??0)*1e3||t.timeline.duration||2e4,c=Math.round((r?.getTime()??0)/1e3)+Math.round((s?.lat??0)*1e3)+7;this.lightningFlashes=Ii.schedule({durationMs:o,seed:c,intensity:e}),this.sceneRenderer.setLightning(this.lightningFlashes)}ensureMeteorSchedule(t){const e=this.meteorInputsOf(t);e!==this.meteorScheduleFor&&(this.meteorScheduleFor=e,this.scheduleMeteors(t))}meteorInputsOf(t){const e=t.event.place?.[0],i=t.event.time;return JSON.stringify([e?.lat,e?.lng,i?.year,i?.month,i?.day,i?.hour,i?.minute,i?.second,t.event.utcOffsetHours,t.event.durationSeconds,t.timeline.duration])}scheduleMeteors(t){const e=t.event.place?.[0],i=t.event.time,n=e?.lat!==void 0&&e.lng!==void 0&&i?.year!==void 0?ra(i,e.lng,t.event.utcOffsetHours):void 0;if(!n||e?.lat===void 0||e.lng===void 0){this.sceneRenderer.setMeteorShower([],0,0);return}const s={lat:e.lat,lng:e.lng,elevationM:0},r=(t.event.durationSeconds??0)*1e3||t.timeline.duration||2e4,o=Math.round(n.getTime()/1e3)+Math.round(e.lat*1e3),c=fi.schedule({ratePerHour:fi.observedRatePerHour(fi.apexPosition(n,s).altitudeDeg),durationMs:r,velocityKmS:fi.TYPICAL_VELOCITY_KM_S,seed:o}),l=zf.activeAt(n).map(u=>{const d=zf.radiantPosition(u.shower,n,s);return{entry:u,position:d,rate:zf.observedRatePerHour(u.zhr,d.altitudeDeg,u.shower.populationIndex)}}).sort((u,d)=>d.rate-u.rate)[0];if(!l||l.rate<=0){this.sceneRenderer.setMeteorShower(c,0,0);return}const h=ka.schedule({ratePerHour:l.rate,durationMs:r,velocityKmS:l.entry.shower.velocityKmS,seed:o+1});this.sceneRenderer.setMeteorShower([...h,...c],l.position.altitudeDeg,l.position.azimuthDeg)}meteorByRank(t){this.ensureMeteorSchedule(this.ufoElement.sighting);const e=[...this.sceneRenderer.meteorSchedule].filter(s=>s.t+s.durationMs<=this.ufoElement.seekableDuration).sort((s,r)=>r.brightness-s.brightness);if(e.length===0)return;const i=e[t%e.length],n=this.sceneRenderer.meteorMidpoint(i);if(n)return{t:Math.round(i.t+i.durationMs*.45),...n}}lensOpticsAt(t){const e=this.ufoElement.sighting,i=e.instrument,n=i.frame,s=Ze(e,t),r=s?.fNumber??i.fNumber;if(!n||r===void 0)return;const o=bi.focalLengthMmFor(i,xn.fovOf(e,t));if(o!==void 0)return{focalLengthMm:o,fNumber:r,focusDistance:s?.focusDistanceM??0,frameHeightMm:n.heightMm}}projectionAt(t){const e=this.ufoElement.sighting;return rr.of(e.instrument,Fe.CANVAS_HEIGHT_PX,xn.fovOf(e,t))}sizeEstimateOf(t){let e=this.sizeEstimates.get(t);return e||(e=new kD,this.sizeEstimates.set(t,e)),e}}const qu="rr0-scene";function hy(){PM(),customElements.get(qu)||customElements.define(qu,$e)}const tI={color:"Color",transparency:"Transparency",halo:"Halo",blur:"Blur",brightness:"Brilliance",shapeTitle:"Name",utcOffset:"Time zone",cloudBase:"Cloud base",elevation:"Altitude",heightAboveGround:"Height above ground",duration:"Duration",placeName:"Place",latitude:"Latitude",longitude:"Longitude",heading:"Heading",pitch:"Tilt",roll:"Roll",sway:"Sway at rest",swayTitle:"How much the body holding the instrument moves the view when not walking: 1 for a person standing, 0 for a tripod. Blank: 1 (0 if the account says the observer was paralysed)",lightPollution:"Night sky",lightPollutionTitle:'The zenith of a moonless night at this place, in magnitudes per square arcsecond, as a Sky Quality Meter reads it or as the World Atlas of artificial sky brightness (Falchi et al. 2016, lightpollutionmap.info, "SQM") gives it. 22 is a natural sky; a suburb is about 19, a city centre 17. Blank: a natural sky',observationTime:"Observation start",observationEndTime:"Observation end",assessmentGroup:"Assessment",assessmentNames:{coverage:"Observer info"},assessmentVerdicts:{"hynek.nl":"NL — nocturnal light","hynek.dd":"DD — daylight disc","hynek.rv":"RV — radar-visual","hynek.ce1":"CE1 — close encounter","hynek.ce2":"CE2 — with a physical trace","hynek.ce3":"CE3 — with entities"},timeQualifierApproximate:"Approximate",timeQualifierUncertain:"Uncertain",timeQualifierBoth:"Uncertain and approximate",timeSeasonSpring:"Spring",timeSeasonSummer:"Summer",timeSeasonAutumn:"Autumn",timeSeasonWinter:"Winter",summaryGroups:{observation:"Observation",location:"Position",temporal:"Time",weather:"Weather",sound:"Sound"},summaryGroup:"Summary",summaryDescription:"Description",closeDescription:"Close the description",observerGroup:"Observer",observerId:"ID",observerTitle:"Title",observerLastName:"Last name",observerFirstNames:"First names",sightingId:"ID",tags:"Tags",cloudCover:"Cloud cover",highCloudCover:"Ice cloud (cirrus)",focalLength:"Focal length",fieldOfView:"Field of view",aperture:"Aperture",exposure:"Exposure",focusDistance:"Focused at",iceCrystalAlignment:"Crystal alignment",cloudDarkness:"Cloud darkness",precipitationType:"Precipitation",precipitationNone:"None",precipitationRain:"Rain",precipitationSnow:"Snow",precipitationHail:"Hail",precipitationIntensity:"Intensity",windDirection:"Wind direction",windSpeed:"Wind speed",storm:"Storm",cloudsGroup:"Clouds",precipitationGroup:"Precipitation",windGroup:"Wind",soundKind:"Sound",soundNone:"None (silent)",soundHum:"Hum",soundWhistle:"Whistle",soundRumble:"Rumble",soundCrackle:"Crackle",soundVolume:"Loudness",soundPitch:"Pitch",soundSrc:"Recording",instrument:"Observed through",filter:"In front of it",filterNone:"nothing",filterSolarVisual:"a solar filter for the eye (eclipse glasses, density 5)",filterSolarPhoto:"a solar film for a camera (density 3.8)",decorAircraft:"Aircraft",decorEntity:"Being",decorAltitude:"Altitude",decorLights:"Lights",decorLightsNone:"none",decor:"Environment",decorBuilding:"Building",decorTree:"Tree",decorShrub:"Shrub",decorBridge:"Bridge",decorWire:"Overhead line",decorCrop:"Crop row",decorTerrace:"Terrace (restanque)",decorMound:"Stone heap",decorStreetlight:"Streetlight",decorVehicle:"Vehicle",decorObserver:"Other observer",decorEast:"Distance east",decorNorth:"Distance north",decorHeading:"Heading",decorColor:"Colour",decorLit:"Lit",decorTitle:"Name",milestones:"Moments",milestoneLabel:"Label",milestoneNote:"What happens",addMilestone:"Name this moment",deleteMilestone:"Delete moment",goToMilestone:"Go to this moment",decorWidth:"Width",decorLength:"Length",decorHeight:"Height",decorModel:"3D model",decorModelNone:"Built-in shape",decorModelDefault:"Default model",decorModelAdvanced:"Model from an address",decorModelFromCatalogue:"From the catalogue, which the recording names it by. Change a field and it becomes this recording's own address.",decorModelUrl:"glTF/GLB address",decorModelTitle:"Model name",decorModelAuthor:"Author",decorModelLicense:"Licence",decorModelSource:"Where it came from",decorFloors:"Floors",decorOccupiedFloor:"Occupied floor",decorObserverSide:"Observer location",decorObserverSideNone:"Not present",decorWindows:"Windows",decorSideFront:"Front",decorSideBehind:"Behind",decorSideLeft:"Left",decorSideRight:"Right",decorSideFrontLeft:"Front-left",decorSideFrontRight:"Front-right",decorSideBehindLeft:"Behind-left",decorSideBehindRight:"Behind-right"},Hc={...tI,accountBy:"Account by",unnamedObserver:"Observer {n}",about:"About",close:"Close",observation:"Observation",date:"Date",location:"Location",case:"Case",description:"Description",source:"Source",basis:{stated:"stated",derived:"derived",assumed:"assumed"},credits:"Credits",editThisObservation:"Edit this observation",embed:"Embed",embedReplay:"Player",embedEdit:"Editor",share:"Share",embedObservation:"Embed the observation",back:"Back",embedCopy:"Copy",shareLink:"Link",shareStartAt:"Start at",shareOptionLabels:"Show summary chips",shareOptionMap:"Open map",shareOptionMilestones:"Show moments",shareOptionCompare:"Compare account",embedCopied:"Copied",showLabels:"Show what it states",interpretation:"Interpretation",account:"Account",interpretationBy:"{title}, by {by}",confrontation:"Against the account",confrontationDirection:"{deg}° off",confrontationWidth:"width ×{ratio}",confrontationHeight:"height ×{ratio}",showComparison:"Compare with the account",hideComparison:"Stop comparing with the account",hideLabels:"Hide what it states"},eI=Object.freeze(Object.defineProperty({__proto__:null,sightingMessages_en:Hc},Symbol.toStringTag,{value:"Module"}));hy();class $u{static PRODUCTION="https://ufoathome.org";static home(){try{const t=new URL(import.meta.url),e=new URL(location.href);return(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname==="[::1]"||e.hostname.endsWith(".localhost"))&&t.origin===e.origin?e.origin:$u.PRODUCTION}catch{return $u.PRODUCTION}}}const jh=$u.home(),Nh="compare-account",kh="start-time",Gf="account",Vf=`${jh}/edit/`;class qo extends HTMLElement{static get observedAttributes(){return["src","show-labels",kh,ks,Fs,Nh]}shadow;sceneElement;toolbarElement;accountElement;accountPrefix;observerText;observerSelect;infoButton;infoPanel;infoAppLink;editLink;infoObservationHeading;infoObservationList;infoCreditsToggle;infoCreditsList;infoCloseButton;shareButton;shareDialog;shareTitle;shareLinkOption;shareLinkLabel;shareLinkBox;shareEmbed;shareClose;shareEmbedOption;shareEmbedLabel;shareLink;shareReplayOptions;embedCode;shareCopy;shareStartOn;shareStart;shareStartLabel;shareOptions;embedReplayRadio;embedEditRadio;labelEmbedReplay;labelEmbedEdit;embedMarkup;embedCopyButton;labelsToggle;paramSummary;summaryBuilder=new sl(Hc,new Xu,new Yn(["en"]),new zh({}),{messages:Hc,locale:"en"});summarySignature="";assessmentEntries=[];assessmentToken=0;supportsPopover=typeof HTMLElement.prototype.showPopover=="function";entries=[];caseSource;interpretationChoice;interpretationLabel;interpretationSelect;confrontationElement;confrontationHeading;confrontationList;compareButton;interpretationLoaders=new Map;interpretationToken=0;offeredFor;currentSrc;infoOpen=!1;creditsOpen=!1;labelsShown=!1;language="en";messages=Hc;constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=`<style>${by}</style>${xy}`,this.shadow.appendChild(t.content.cloneNode(!0)),this.sceneElement=document.createElement(qu),this.forwardPlayerAttributes(),this.sceneElement.ufoElement.creditShownExternally=!0,this.sceneElement.ownCredits=!1,this.shadow.getElementById("ufo-slot").replaceWith(this.sceneElement),this.toolbarElement=this.shadow.getElementById("toolbar"),this.accountElement=this.shadow.getElementById("account"),this.accountPrefix=this.shadow.getElementById("account-prefix"),this.observerText=this.shadow.getElementById("observer-text"),this.observerSelect=this.shadow.getElementById("observer"),this.infoButton=this.shadow.getElementById("info-button"),this.infoPanel=this.shadow.getElementById("info-panel"),this.infoAppLink=this.shadow.getElementById("info-app-link"),this.editLink=this.shadow.getElementById("edit-link"),this.infoObservationHeading=this.shadow.getElementById("info-observation-heading"),this.infoObservationList=this.shadow.getElementById("info-observation-list"),this.infoCreditsToggle=this.shadow.getElementById("info-credits-toggle"),this.infoCreditsList=this.shadow.getElementById("info-credits-list"),this.infoCloseButton=this.shadow.getElementById("info-close"),this.labelsToggle=this.shadow.getElementById("info-labels-toggle"),this.paramSummary=this.shadow.getElementById("param-summary"),this.labelsToggle.addEventListener("click",()=>{this.showLabels=!this.showLabels}),this.shareButton=document.createElement("button"),this.shareButton.type="button",this.shareButton.id="share-button",this.shareButton.setAttribute("aria-haspopup","dialog"),this.shareButton.innerHTML=Gt.SHARE,this.sceneElement.ufoElement.addControl(this.shareButton),this.shareDialog=this.shadow.getElementById("share-dialog"),this.shareTitle=this.shadow.getElementById("share-title"),this.shareLinkOption=this.shadow.getElementById("share-link-option"),this.shareLinkLabel=this.shadow.getElementById("share-link-label"),this.shareLinkBox=this.shadow.querySelector(".share-link"),this.shareEmbed=this.shadow.getElementById("share-embed"),this.shareClose=this.shadow.getElementById("share-close"),this.shareEmbedOption=this.shadow.getElementById("share-embed-option"),this.shareEmbedLabel=this.shadow.getElementById("share-embed-label"),this.shareLink=this.shadow.getElementById("share-link"),this.shareReplayOptions=this.shadow.getElementById("share-replay-options"),this.embedCode=this.shadow.getElementById("embed-code"),this.shareCopy=this.shadow.getElementById("share-copy"),this.shareStartOn=this.shadow.getElementById("share-start-on"),this.shareStart=this.shadow.getElementById("share-start"),this.shareStartLabel=this.shadow.getElementById("share-start-label");const e=i=>({input:this.shadow.getElementById(`share-opt-${i}`),label:this.shadow.getElementById(`share-opt-${i}-label`)});this.shareOptions={labels:e("labels"),map:e("map"),milestones:e("milestones"),compare:e("compare")},this.embedReplayRadio=this.shadow.getElementById("embed-kind-replay"),this.embedEditRadio=this.shadow.getElementById("embed-kind-edit"),this.labelEmbedReplay=this.shadow.getElementById("label-embed-replay"),this.labelEmbedEdit=this.shadow.getElementById("label-embed-edit"),this.embedMarkup=this.shadow.getElementById("embed-markup"),this.embedCopyButton=this.shadow.getElementById("embed-copy"),this.interpretationChoice=this.shadow.getElementById("interpretation-choice"),this.interpretationLabel=this.shadow.getElementById("interpretation-label"),this.interpretationSelect=this.shadow.getElementById("interpretation"),this.confrontationElement=this.shadow.getElementById("confrontation"),this.confrontationHeading=this.shadow.getElementById("confrontation-heading"),this.confrontationList=this.shadow.getElementById("confrontation-list"),this.compareButton=this.shadow.getElementById("compare-account"),this.compareButton.addEventListener("click",()=>this.setComparing(!this.sceneElement.compareAccount)),this.observerSelect.addEventListener("change",()=>this.selectObserver(this.observerSelect.value)),this.interpretationSelect.addEventListener("change",()=>void this.chooseInterpretation(this.interpretationSelect.value)),this.sceneElement.addEventListener(ly,i=>this.showConfrontation(i.detail)),this.sceneElement.ufoElement.addEventListener("timeupdate",()=>this.refreshParamSummary()),this.supportsPopover?(this.infoPanel.setAttribute("popover","auto"),this.infoPanel.removeAttribute("hidden"),this.infoButton.setAttribute("popovertarget","info-panel"),this.infoPanel.addEventListener("beforetoggle",i=>{i.newState==="open"&&(this.populateInfoPanel(),this.bringInfoButtonIntoView())}),this.infoPanel.addEventListener("toggle",i=>this.syncInfoOpen(i.newState==="open"))):this.infoButton.addEventListener("click",()=>this.toggleInfoPanel()),this.infoCloseButton.addEventListener("click",()=>this.toggleInfoPanel()),this.infoCreditsToggle.addEventListener("click",()=>this.toggleCredits()),this.shareButton.addEventListener("click",()=>this.openShare()),this.shareClose.addEventListener("click",()=>this.closeShare()),this.shareLinkOption.addEventListener("click",()=>this.showShareView("link")),this.shareEmbedOption.addEventListener("click",()=>this.showShareView("embed"));for(const i of[this.shareStartOn,this.shareStart,...Object.values(this.shareOptions).map(n=>n.input)])i.addEventListener("input",()=>this.refreshShareLinks());this.shareCopy.addEventListener("click",()=>void this.copyText(this.shareLink.value,this.shareLink,this.shareCopy)),this.shareDialog.addEventListener("click",i=>{i.target===this.shareDialog&&this.closeShare()});for(const i of[this.embedReplayRadio,this.embedEditRadio])i.addEventListener("change",()=>this.refreshShareLinks());this.embedCopyButton.addEventListener("click",()=>void this.copyEmbedMarkup()),this.isConnected&&this.loadLocaleMessages()}get scene(){return this.sceneElement}async loadLocaleMessages(){const t=++this.localeToken,e=Gr.preferencesFor(this);this.preferences=e;const i=Ep(e,Ap),[n,s,r]=i==="en"?[Hc,{},void 0]:await Promise.all([ub(i),db(i),bM(i)]);if(t!==this.localeToken)return;const o=i!==this.language;this.language=i,this.messages=n,this.tags=new zh(s),this.said=new Yn(e),this.summaryBuilder=new sl(this.messages,new Xu(r),this.said,this.tags,{messages:this.messages,locale:i}),this.accountPrefix.textContent=this.messages.accountBy,this.interpretationLabel.textContent=this.messages.interpretation,this.confrontationHeading.textContent=this.messages.confrontation;const c=this.entries.find(l=>l.src===this.currentSrc);c&&this.offerInterpretations(c),this.updateCompareButton(),this.infoButton.title=this.messages.about,this.infoButton.setAttribute("aria-label",this.messages.about),this.editLink.title=this.messages.editThisObservation,this.editLink.setAttribute("aria-label",this.messages.editThisObservation),this.infoCloseButton.setAttribute("aria-label",this.messages.close),this.infoObservationHeading.textContent=this.messages.observation,this.infoCreditsToggle.textContent=this.messages.credits,this.syncLabelsToggle(),this.refreshParamSummary(),o&&this.currentSrc&&this.runAssessments(),this.shareButton.title=this.messages.share,this.shareButton.setAttribute("aria-label",this.messages.share),this.shareClose.setAttribute("aria-label",this.messages.close),this.shareCopy.textContent=this.messages.embedCopy,this.shareStartLabel.textContent=this.messages.shareStartAt,this.shareOptions.labels.label.textContent=this.messages.shareOptionLabels,this.shareOptions.map.label.textContent=this.messages.shareOptionMap,this.shareOptions.milestones.label.textContent=this.messages.shareOptionMilestones,this.shareOptions.compare.label.textContent=this.messages.shareOptionCompare,this.shareStart.setAttribute("aria-label",this.messages.shareStartAt),this.shareEmbedLabel.textContent=this.messages.embed,this.shareLinkLabel.textContent=this.messages.shareLink,this.shareTitle.textContent=this.messages.share,this.labelEmbedReplay.textContent=this.messages.embedReplay,this.labelEmbedEdit.textContent=this.messages.embedEdit,this.embedCopyButton.textContent=this.messages.embedCopy,this.infoOpen&&this.populateInfoPanel(),this.updateAccountLine()}preferences=[];localeToken=0;said=new Yn(["en"]);tags=new zh({});connectedCallback(){Gr.preferencesFor(this).join()!==this.preferences.join()&&this.loadLocaleMessages();const t=this.getAttribute("src");t&&this.loadFromSrc(t)}disconnectedCallback(){document.removeEventListener("click",this.handleOutsideClick)}attributeChangedCallback(t,e,i){t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),t==="show-labels"&&this.applyLabels(this.hasAttribute("show-labels")),(t===ks||t===Fs)&&this.forwardPlayerAttributes(),t===Nh&&this.setComparing(this.hasAttribute(Nh))}forwardPlayerAttributes(){for(const t of[ks,Fs]){const e=this.getAttribute(t);e===null?this.sceneElement.removeAttribute(t):this.sceneElement.setAttribute(t,e)}}async loadFromSrc(t){this.startPending=!0;const e=Gc.json(t);this.sceneElement.holdForNewScene(e);const i=await e;if(Array.isArray(i))throw new Error(`${t} is a bare list of recordings, which is no longer read: list them as the sighting events of a case.json`);if(cs.isCase(i)){const n=cs.sightingUrls(i,new URL(t,location.href).href);if(n.length===0)throw new Error(`${t} is a case with no sighting event: no recording to show`);await this.loadObserverUrls(n,{json:i,url:new URL(t,location.href).href})}else this.setEntries([{src:t,sighting:i}],void 0)}get sightingData(){return this.entries.find(t=>t.src===this.currentSrc)?.sighting}set sightingData(t){this.startPending=!0,this.currentSrc="",this.setEntries([{src:"",sighting:t}],void 0)}get observerUrls(){return this.entries.map(t=>t.src)}set observerUrls(t){this.loadObserverUrls(t)}async loadObserverUrls(t,e){const i=await Promise.all(t.map(async n=>({src:n,sighting:await Gc.json(n)})));this.setEntries(i,e)}setEntries(t,e){this.entries=t,this.caseSource=e,this.toolbarElement.hidden=t.length===0;const i=t.length>1;this.observerSelect.hidden=!i,this.observerText.hidden=i,this.observerSelect.innerHTML="";for(const s of t){const r=document.createElement("option");r.value=s.src,r.textContent=this.observerDisplayName(this.plain(s).observer)??this.messages.unnamedObserver.replace("{n}",String(t.indexOf(s)+1)),this.observerSelect.appendChild(r)}const n=t.find(s=>s.src===this.currentSrc)??t[0];n?this.selectObserver(n.src):this.updateAccountLine()}editorUrl(){if(!this.currentSrc)return Vf;const t=new URL(this.currentSrc,location.href),e=this.caseSource;return e?`${Vf}?file=${encodeURIComponent(e.url)}&track=${encodeURIComponent(this.shownTrackUrl()??t.href)}`:`${Vf}?file=${encodeURIComponent(t.href)}`}get editorHref(){return this.editorUrl()}shownTrackUrl(){const t=this.caseSource,e=this.entries.find(s=>s.src===this.currentSrc),i=/^case-(\d+)$/.exec(this.interpretationSelect.value);if(!t||!e||!i)return;const n=cs.interpretationEvents(t.json,this.plain(e).id)[Number(i[1])];return n?.url?new URL(n.url,t.url).href:void 0}embedMarkupFor(t){const e=t==="edit"?"rr0-sighting-editor":"rr0-sighting",i=new URL(`${e}.mjs`,import.meta.url).href,n=this.currentSrc?new URL(this.currentSrc,location.href).href:"",s=t==="replay"?this.replayAttributes().map(([r,o])=>o===""?` ${r}`:` ${r}="${o}"`).join(""):"";return`<script type="module" src="${i}"><\/script>
8761
- <${e} src="${n}"${s}></${e}>`}refreshEmbedMarkup(){const t=this.embedMarkupFor(this.embedEditRadio.checked?"edit":"replay");this.embedMarkup.value=t,this.shareCodeEditor&&(this.shareCodeEditor.text=t)}async copyText(t,e,i){try{await navigator.clipboard.writeText(t),i.textContent=this.messages.embedCopied,window.setTimeout(()=>i.textContent=this.messages.embedCopy,1500)}catch{e.select()}}async copyEmbedMarkup(){await this.copyText(this.shareCodeEditor?.text??this.embedMarkup.value,this.embedMarkup,this.embedCopyButton)}playUrl(){const t=this.replayQuery().join("&");return this.currentSrc?`${jh}/play/?file=${encodeURIComponent(new URL(this.currentSrc,location.href).href)}${t&&"&"+t}`:`${jh}/play/${t&&"?"+t}`}replayAttributes(){const t=this.shareOptions,e=[];return this.shareStartSeconds!==void 0&&e.push([kh,String(this.shareStartSeconds)]),t.labels.input.checked&&e.push(["show-labels",""]),t.map.input.checked&&e.push([ks,""]),t.milestones.input.checked||e.push([Fs,""]),t.compare.input.checked&&e.push([Nh,""]),e}replayQuery(){const t=this.shareOptions,e=[];return this.shareStartSeconds!==void 0&&e.push(`t=${this.shareStartSeconds}`),t.labels.input.checked||e.push("labels=0"),t.map.input.checked&&e.push("map=1"),t.milestones.input.checked||e.push("moments=0"),t.compare.input.checked&&e.push("compare=1"),e}get shareStartSeconds(){const t=Math.floor(Number(this.shareStart.value));return this.shareStartOn.checked&&Number.isFinite(t)&&t>=0?t:void 0}refreshShareLinks(){const t=this.embedEditRadio.checked;this.shareReplayOptions.disabled=t,this.shareLink.value=t?this.editorUrl():this.playUrl(),this.fitShareLink(),this.refreshEmbedMarkup()}fitShareLink(){this.shareLink.style.height="auto",this.shareLink.style.height=`${this.shareLink.scrollHeight}px`}shareCodeEditor;shareCodeLoading;loadShareCode(){this.shareCodeLoading??=je(async()=>{const{ShareCodeEditor:t}=await import("./ShareCodeEditor-C53SBK2N.js");return{ShareCodeEditor:t}},[],import.meta.url).then(({ShareCodeEditor:t})=>{this.shareCodeEditor=new t(this.embedCode,this.embedMarkup.value,e=>{this.embedMarkup.value=e},this.messages.embed),this.embedMarkup.hidden=!0}).catch(()=>{this.shareCodeLoading=void 0})}openShare(){const t=this.sceneElement.ufoElement;this.shareStart.max=String(Math.floor(t.seekableDuration/1e3)),this.shareStart.value=String(Math.floor(t.currentTime/1e3)),this.shareStartOn.checked=!1,this.shareOptions.labels.input.checked=this.labelsShown,this.shareOptions.map.input.checked=t.observerMapOpen,this.shareOptions.milestones.input.checked=t.milestonesVisible,this.shareOptions.compare.input.checked=this.sceneElement.compareAccount,this.refreshShareLinks(),this.showShareView("link"),typeof this.shareDialog.showModal=="function"?this.shareDialog.showModal():this.shareDialog.setAttribute("open",""),this.fitShareLink(),this.shareLink.select()}closeShare(){typeof this.shareDialog.close=="function"?this.shareDialog.close():this.shareDialog.removeAttribute("open")}showShareView(t){this.shareLinkBox.hidden=t!=="link",this.shareEmbed.hidden=t!=="embed",this.shareLinkOption.setAttribute("aria-pressed",String(t==="link")),this.shareEmbedOption.setAttribute("aria-pressed",String(t==="embed")),t==="embed"?this.loadShareCode():this.fitShareLink()}offerInterpretations(t){const e=this.offeredFor===t.sighting,i=this.interpretationSelect.value;this.offeredFor=t.sighting,this.interpretationToken++,this.interpretationLoaders=new Map,this.interpretationSelect.innerHTML="";const n=(l,h,u)=>{const d=document.createElement("option");d.value=l,d.textContent=h,this.interpretationSelect.appendChild(d),this.interpretationLoaders.set(l,u)},s=t===this.entries.find(l=>l.src===this.currentSrc)?this.sceneElement.ufoElement.sighting.interpretation:void 0;n(Gf,this.messages.account,()=>Promise.resolve(s));const r=this.caseSource;r&&cs.interpretationEvents(r.json,this.plain(t).id).forEach((l,h)=>{const u=this.said.read(l.title)??`#${h+1}`,d=(l.by??[]).map(f=>this.agentName(f)).filter(Boolean).join(", ");n(`case-${h}`,d?this.messages.interpretationBy.replace("{title}",u).replace("{by}",d):u,()=>cs.interpretationOf(l,r.url,f=>Gc.json(f)))});const c=e&&[...this.interpretationSelect.options].some(l=>l.value===i)?i:Gf;this.interpretationSelect.value=c,c===Gf?this.sceneElement.interpretation!==s&&(this.sceneElement.interpretation=s):this.sceneElement.interpretation||this.chooseInterpretation(c),this.interpretationChoice.hidden=this.interpretationSelect.options.length<2,this.showConfrontation(this.sceneElement.confrontation),this.updateCompareButton()}setComparing(t){this.sceneElement.compareAccount=t,this.updateCompareButton(),this.showConfrontation(this.sceneElement.confrontation)}updateCompareButton(){const t=this.sceneElement.compareAccount;this.compareButton.hidden=!this.sceneElement.interpretation,this.compareButton.setAttribute("aria-pressed",String(t));const e=t?this.messages.hideComparison:this.messages.showComparison;this.compareButton.title=e,this.compareButton.setAttribute("aria-label",e)}static DATE_LOCALES={en:"en-US",fr:"fr-FR",es:"es-ES",it:"it-IT"};get colon(){return this.language==="fr"?" : ":": "}async chooseInterpretation(t){const e=++this.interpretationToken,i=this.interpretationLoaders.get(t),n=i?await i().catch(s=>{console.warn(`<rr0-sighting>: could not read interpretation "${t}":`,s)}):void 0;e===this.interpretationToken&&(this.sceneElement.interpretation=n,this.editLink.href=this.editorUrl(),this.dispatchEvent(new CustomEvent("interpretationchange",{detail:{track:this.shownTrackUrl()}})),this.updateCompareButton(),this.showConfrontation(this.sceneElement.confrontation))}agentName(t){if("people"in t){const[e,...i]=t.people.replace(/([a-z])([A-Z])/g,"$1 $2").split(" ");return[...i,e].join(" ")}return"org"in t?t.org.replace(/([a-z])([A-Z])/g,"$1 $2"):this.observerDisplayName(t)??""}showConfrontation(t){this.confrontationList.innerHTML="",this.confrontationElement.hidden=!this.sceneElement.interpretation||!this.sceneElement.compareAccount;const e=new Intl.NumberFormat(this.language,{maximumFractionDigits:1,minimumFractionDigits:1}),i=new Intl.NumberFormat(this.language,{maximumFractionDigits:2,minimumFractionDigits:2});for(const n of t){const s=document.createElement("li");s.append(`${this.said.read(n.title)??n.sourceId}${this.colon}`);const r=[];n.separationDeg!==void 0&&r.push([this.messages.confrontationDirection.replace("{deg}",e.format(n.separationDeg)),n.disagreements.includes("direction")]),n.widthRatio!==void 0&&r.push([this.messages.confrontationWidth.replace("{ratio}",i.format(n.widthRatio)),n.disagreements.includes("width")]),n.heightRatio!==void 0&&r.push([this.messages.confrontationHeight.replace("{ratio}",i.format(n.heightRatio)),n.disagreements.includes("height")]),r.forEach(([o,c],l)=>{l>0&&s.append(" · ");const h=document.createElement("span");h.textContent=o,c&&(h.className="disagrees"),s.append(h)}),this.confrontationList.appendChild(s)}}startPending=!1;selectObserver(t){const e=this.entries.find(i=>i.src===t);if(e){if(this.currentSrc=t,this.observerSelect.value=t,this.sceneElement.documentUrl=e.src?new URL(e.src,location.href).href:void 0,this.sceneElement.holdForNewScene(),this.sceneElement.sightingData=e.sighting,this.startPending){this.startPending=!1;const i=Number(this.getAttribute(kh));this.hasAttribute(kh)&&Number.isFinite(i)&&(this.sceneElement.ufoElement.currentTime=Math.max(0,i)*1e3)}this.offerInterpretations(e),this.updateAccountLine(),this.refreshParamSummary(),this.runAssessments(),this.infoOpen&&this.populateInfoPanel(),this.dispatchEvent(new CustomEvent(iI,{detail:{src:t}}))}}async runAssessments(){const t=++this.assessmentToken,e=await new Hx(this.messages).read(this.sceneElement.ufoElement.sighting);t===this.assessmentToken&&(this.assessmentEntries=e.entries,this.refreshParamSummary())}updateAccountLine(){const t=this.entries.find(n=>n.src===this.currentSrc),e=t?this.observerDisplayName(this.plain(t).observer):void 0,i=e!==void 0||this.entries.length>1;this.accountElement.hidden=!i,this.observerText.textContent=e??"",this.editLink.hidden=!this.currentSrc,this.editLink.href=this.editorUrl(),this.editLink.title=this.messages.editThisObservation,this.editLink.setAttribute("aria-label",this.messages.editThisObservation)}observerDisplayName(t){if(!t)return;const e=[...t.firstNames??[],t.lastName].filter(Boolean).join(" ");return t.title||e||t.id}plainRecordings=new WeakMap;plain(t){return this.stripped(t).recording}stripped(t){let e=this.plainRecordings.get(t.sighting);return e||(e=hn.strip(t.sighting),this.plainRecordings.set(t.sighting,e)),e}basisOf(t,e){const i=this.stripped(t).provenance,n={stated:0,derived:1,assumed:2},s=i.paths().filter(c=>e.some(l=>c===l||c.startsWith(`${l}.`))).map(c=>i.at(c)),r=s.reduce((c,l)=>n[l.basis]>n[c]?l.basis:c,"stated"),o=s.filter(c=>c.basis===r&&c.rationale).map(c=>c.rationale);return{basis:r,rationales:o}}formatDate(t){const e=t.place?.[0],i=ra(t.time??{},e?.lng??0,t.utcOffsetHours);if(!i)return;const n=i.getTime()+this.utcOffsetHoursOf(t,e?.lng??0)*36e5;if(Number.isFinite(n))return new Intl.DateTimeFormat(qo.DATE_LOCALES[this.language],{dateStyle:"long",timeStyle:"short",timeZone:"UTC"}).format(new Date(n))}utcOffsetHoursOf(t,e){return t.utcOffsetHours??Math.round(e/15)}formatLocation(t){const e=t.place?.[0];if(e)return`${e.lat.toFixed(4)}, ${e.lng.toFixed(4)}`}toggleInfoPanel(){const t=!this.infoOpen;if(this.supportsPopover){const e=this.infoPanel.matches(":popover-open");t&&!e?this.infoPanel.showPopover():!t&&e&&this.infoPanel.hidePopover();return}t&&this.bringInfoButtonIntoView(),this.syncInfoOpen(t),this.infoPanel.hidden=!t,t?document.addEventListener("click",this.handleOutsideClick):document.removeEventListener("click",this.handleOutsideClick)}bringInfoButtonIntoView(){const t=this.infoButton.getBoundingClientRect(),e=window.innerHeight||document.documentElement.clientHeight;t.top>=0&&t.bottom<=e||this.infoButton.scrollIntoView({block:"center"})}syncInfoOpen(t){t!==this.infoOpen&&(this.infoOpen=t,this.infoButton.setAttribute("aria-expanded",String(t)),t?this.supportsPopover||this.populateInfoPanel():(this.creditsOpen=!1,this.infoCreditsList.hidden=!0,this.infoCreditsToggle.setAttribute("aria-expanded","false")))}handleOutsideClick=t=>{const e=t.composedPath();!e.includes(this.infoPanel)&&!e.includes(this.infoButton)&&this.toggleInfoPanel()};toggleCredits(){this.creditsOpen=!this.creditsOpen,this.infoCreditsList.hidden=!this.creditsOpen,this.infoCreditsToggle.setAttribute("aria-expanded",String(this.creditsOpen)),this.creditsOpen&&this.revealInPanel(this.infoCreditsList)}revealInPanel(t){t.scrollIntoView?.({block:"nearest"})}get showLabels(){return this.labelsShown}set showLabels(t){this.toggleAttribute("show-labels",t)}applyLabels(t){this.labelsShown=t,this.syncLabelsToggle(),this.refreshParamSummary(),this.populateInfoPanel()}syncLabelsToggle(){this.labelsToggle.textContent=this.labelsShown?this.messages.hideLabels:this.messages.showLabels,this.labelsToggle.setAttribute("aria-pressed",String(this.labelsShown))}refreshParamSummary(){if(this.paramSummary.hidden=!this.labelsShown,!this.labelsShown){this.paramSummary.replaceChildren(),this.summarySignature="";return}const t=this.sceneElement.ufoElement.sighting,e=[...this.summaryBuilder.entriesFor(t,this.sceneElement.ufoElement.currentTime,{roadGradeDeg:this.sceneElement.roadGradeDeg}),...this.assessmentEntries],i=e.map(r=>`${r.field}=${r.label}=${r.value}${r.unit}${r.full??""}${r.fromSource?"*":""}`).join("|");if(i===this.summarySignature)return;this.summarySignature=i;const n=[];let s;for(const r of e){s&&s.group!==r.group&&(s=void 0);const o=r.group==="summary"?this.messages.summaryGroup:r.group==="observer"?this.messages.observerGroup:r.group in this.messages.summaryGroups?this.messages.summaryGroups[r.group]:r.group==="assessment"?this.messages.assessmentGroup:void 0;if(o!==void 0&&!s){const l=document.createElement("span");l.className="param-nest";const h=document.createElement("span");h.className="param-nest-label",h.textContent=o,l.append(h),s={group:r.group,element:l},n.push(l)}const c=this.paramItem(r);s?s.element.append(c):n.push(c)}this.paramSummary.replaceChildren(...n),this.syncDescription(e)}openDescription;syncDescription(t){this.openDescription!==void 0&&!t.some(e=>e.full===this.openDescription)&&(this.openDescription=void 0),iM.sync(this.paramSummary,this.openDescription,this.messages.summaryDescription,this.messages.closeDescription,()=>{this.openDescription=void 0,this.syncDescription(t)})}paramItem(t){const e=document.createElement("span");if(e.className=t.fromSource?"param-label from-source":"param-label",t.full!==void 0){e.classList.add("describable"),e.tabIndex=0,e.setAttribute("role","button");const s=()=>{this.openDescription=t.full,this.syncDescription([t])};e.addEventListener("click",s),e.addEventListener("keydown",r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),s())})}const i=document.createElement("span");if(i.className="param-label-label",i.textContent=`${t.label} `,e.append(i),t.color!==void 0){const s=document.createElement("span");s.className="param-label-swatch",s.style.background=t.color,e.append(s)}const n=document.createElement("span");return n.className="param-label-value",n.textContent=t.unit===""?t.value:`${t.value} ${t.unit}`,e.append(n),e}populateInfoPanel(){const t=this.entries.find(e=>e.src===this.currentSrc);if(this.infoObservationList.innerHTML="",t){const e=this.caseSource&&(this.caseSource.json.title??this.caseSource.json.id);if(e&&this.appendInfoRow(this.infoObservationList,this.messages.case,e),!this.labelsShown){const s=this.formatDate(this.plain(t));s&&this.appendInfoRow(this.infoObservationList,this.messages.date,s,this.basisOf(t,qo.DATE_PATHS));const r=this.formatLocation(this.plain(t));r&&this.appendInfoRow(this.infoObservationList,this.messages.location,r,this.basisOf(t,qo.PLACE_PATHS))}const i=this.said.read(this.plain(t).description);i&&!this.labelsShown&&this.appendInfoRow(this.infoObservationList,this.messages.description,i);for(const s of this.plain(t).sources??[])this.appendInfoSource(this.infoObservationList,this.messages.source,s);const n=this.plain(t).tags;!this.labelsShown&&n&&n.length>0&&this.appendInfoRow(this.infoObservationList,this.messages.tags,n.map(s=>this.tags.name(s)).join(", "))}this.refreshEmbedMarkup(),this.infoAppLink.href=jh,this.infoAppLink.textContent="UFO@home v0.105.2",rn.fill(this.infoCreditsList,this.sceneElement)}appendInfoSource(t,e,i){const n=document.createElement("dt");n.textContent=e;const s=document.createElement("dd"),r=i.title??i.url??"";if(i.url&&/^https?:\/\//i.test(i.url)){const c=document.createElement("a");c.href=i.url,c.target="_blank",c.rel="noopener noreferrer",c.textContent=r,s.appendChild(c)}else s.append(r);const o=[i.authors?.join(", "),i.publication?.publisher,i.publication?.time,i.index].filter(Boolean);o.length>0&&s.append(`, ${o.join(", ")}`),t.append(n,s)}static DATE_PATHS=["time","utcOffsetHours","timeZone"];static PLACE_PATHS=["place.0"];appendInfoRow(t,e,i,n){const s=document.createElement("dt");s.textContent=e;const r=document.createElement("dd");if(r.textContent=i,n){const o=document.createElement("span");o.className=`basis basis-${n.basis}`,o.textContent=this.messages.basis[n.basis],n.rationales.length>0&&(o.title=n.rationales.join(`
8760
+ `);let s=_s.cache.get(n);return s||(s=Promise.all(i.map(r=>_s.load(r.url))).then(r=>r.reduce((o,c)=>_s.concat(o,c))),_s.cache.set(n,s)),s}static parse(t){const e=t.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),i=e*Float32Array.BYTES_PER_ELEMENT;return{count:e,ra:new Float32Array(t,0*i,e),dec:new Float32Array(t,1*i,e),mag:new Float32Array(t,2*i,e),ci:new Float32Array(t,3*i,e)}}static concat(t,e){const i=(n,s)=>{const r=new Float32Array(n.length+s.length);return r.set(n,0),r.set(s,n.length),r};return{count:t.count+e.count,ra:i(t.ra,e.ra),dec:i(t.dec,e.dec),mag:i(t.mag,e.mag),ci:i(t.ci,e.ci)}}}class Ie{constructor(t){if(this.heights=t,t.length!==Ie.WIDTH*Ie.HEIGHT)throw new Error(`a lunar relief has ${Ie.WIDTH*Ie.HEIGHT} samples, not ${t.length}`)}static SAMPLES_PER_DEGREE=16;static WIDTH=360*Ie.SAMPLES_PER_DEGREE;static HEIGHT=180*Ie.SAMPLES_PER_DEGREE;static UNIT_KM=.1;static REFERENCE_RADIUS_KM=1737.4;static BAND_FROM_DEG=74;static BAND_TO_DEG=106;heightKm(t,e){const i=Ie.SAMPLES_PER_DEGREE,n=(e%360+360)%360*i-.5,s=(90-t)*i-.5,r=Math.floor(n),o=Math.floor(s),c=n-r,l=s-o,h=(f,p)=>{const v=(f%Ie.WIDTH+Ie.WIDTH)%Ie.WIDTH,m=Math.min(Ie.HEIGHT-1,Math.max(0,p));return this.heights[m*Ie.WIDTH+v]},u=h(r,o)*(1-c)+h(r+1,o)*c,d=h(r,o+1)*(1-c)+h(r+1,o+1)*c;return(u*(1-l)+d*l)*Ie.UNIT_KM}static inBand(t,e){const i=Math.PI/180,n=Math.acos(Math.cos(t*i)*Math.cos(e*i))*180/Math.PI;return n>=Ie.BAND_FROM_DEG&&n<=Ie.BAND_TO_DEG}static withBump(t,e,i,n=.4){const s=new Int8Array(Ie.WIDTH*Ie.HEIGHT),r=Ie.SAMPLES_PER_DEGREE,o=Math.ceil(n*r),c=Math.floor(e*r),l=Math.floor((90-t)*r);for(let h=-o;h<=o;h++)for(let u=-o;u<=o;u++)Math.hypot(u,h)<=o&&(s[(l+h)*Ie.WIDTH+(c+u+Ie.WIDTH)%Ie.WIDTH]=Math.round(i/Ie.UNIT_KM));return new Ie(s)}static smooth(){return new Ie(new Int8Array(Ie.WIDTH*Ie.HEIGHT))}}class Vn{static SAMPLES=5760;static SEARCH_FROM_DEG=87;static SEARCH_TO_DEG=90.2;static SEARCH_STEP_DEG=.0625;static profile(t,e,i,n=Vn.SAMPLES){const{s,u:r,w:o,distanceKm:c}=Vn.frame(t,e),l=Math.PI/180,h=new Float32Array(n),u=Ie.REFERENCE_RADIUS_KM;for(let d=0;d<n;d++){const f=d/n*2*Math.PI,p=Math.cos(f),v=Math.sin(f),m=p*r[0]+v*o[0],g=p*r[1]+v*o[1],b=p*r[2]+v*o[2];let S=0;for(let M=Vn.SEARCH_FROM_DEG;M<=Vn.SEARCH_TO_DEG;M+=Vn.SEARCH_STEP_DEG){const x=Math.cos(M*l),_=Math.sin(M*l),E=x*s[0]+_*m,y=x*s[1]+_*g,T=x*s[2]+_*b,I=Math.asin(Math.max(-1,Math.min(1,T)))/l,C=Math.atan2(y,E)/l,P=u+i.heightKm(I,C),B=Math.atan2(P*_,c-P*x);B>S&&(S=B)}h[d]=S/l}return{radiusDeg:h,meanRadiusDeg:Math.asin(u/c)/l}}static frame(t,e){const i=new qr(e.lat,e.lng,e.elevationM),n=ur(t),s=np(t,i,!1),r=new ge(s.x-n.x,s.y-n.y,s.z-n.z,n.t),o=Math.hypot(r.x,r.y,r.z)*Vn.AU_KM,c=Vn.bodyFixed(t),l=c(r),h=Math.hypot(l[0],l[1],l[2]),u=[l[0]/h,l[1]/h,l[2]/h],d=h4(t,i),f=cm(d),p=cr(d,new ge(-r.x,-r.y,-r.z,n.t)),v=Math.asin(p.z/Math.hypot(p.x,p.y,p.z)),m=Math.atan2(-p.y,p.x),g=new ge(-Math.sin(v)*Math.cos(m),Math.sin(v)*Math.sin(m),Math.cos(v),n.t),b=new ge(-Math.sin(m),-Math.cos(m),0,n.t);return{s:u,u:c(cr(f,g)),w:c(cr(f,b)),distanceKm:o}}static surfacePoint(t,e,i,n){const{s,u:r,w:o}=Vn.frame(t,e),c=Math.PI/180,l=[0,1,2].map(u=>Math.cos(i*c)*r[u]+Math.sin(i*c)*o[u]),h=[0,1,2].map(u=>Math.cos(n*c)*s[u]+Math.sin(n*c)*l[u]);return{latDeg:Math.asin(h[2])/c,lonDeg:Math.atan2(h[1],h[0])/c}}static radiusAt(t,e){const i=t.radiusDeg.length,n=(e/360*i%i+i)%i,s=Math.floor(n),r=n-s;return t.radiusDeg[s]*(1-r)+t.radiusDeg[(s+1)%i]*r}static uncoveredFraction(t,e,i){const n=t.radiusDeg.length,s=i.upDeg*i.upDeg+i.rightDeg*i.rightDeg;let r=0;for(let o=0;o<n;o++){const c=o/n*2*Math.PI,l=Math.cos(c),h=Math.sin(c),u=l*i.upDeg+h*i.rightDeg,d=u*u-s+e*e;if(d<=0)continue;const f=Math.sqrt(d),p=u+f;if(p<=0)continue;const v=Math.max(0,u-f),m=Math.max(v,t.radiusDeg[o]);p>m&&(r+=.5*(p*p-m*m))}return Math.min(1,Math.max(0,r*(2*Math.PI/n)/(Math.PI*e*e)))}static AU_KM=1495978707e-1;static bodyFixed(t){const e=A4(ut.Moon,t),i=Math.PI/180,n=e.ra*15*i,s=e.dec*i,r=e.spin*i,o=(l,[h,u,d])=>[Math.cos(l)*h+Math.sin(l)*u,-Math.sin(l)*h+Math.cos(l)*u,d],c=(l,[h,u,d])=>[h,Math.cos(l)*u+Math.sin(l)*d,-Math.sin(l)*u+Math.cos(l)*d];return l=>o(r,c(Math.PI/2-s,o(Math.PI/2+n,[l.x,l.y,l.z])))}static subObserverPoint(t,e){const i=new qr(e.lat,e.lng,e.elevationM),n=ur(t),s=np(t,i,!1),r=Vn.bodyFixed(t)(new ge(s.x-n.x,s.y-n.y,s.z-n.z,n.t)),o=Math.hypot(r[0],r[1],r[2]);return{latDeg:Math.asin(r[2]/o)*180/Math.PI,lonDeg:Math.atan2(r[1],r[0])*180/Math.PI}}}class Qc{static cache=new Map;static load(t){let e=Qc.cache.get(t);return e||(e=Qc.fetchRelief(t).catch(()=>{}),Qc.cache.set(t,e)),e}static async fetchRelief(t){const e=await fetch(t);if(!e.ok)return;let i=new Uint8Array(await e.arrayBuffer());if(i[0]===31&&i[1]===139){if(typeof DecompressionStream>"u")return;const n=new Blob([i]).stream().pipeThrough(new DecompressionStream("gzip"));i=new Uint8Array(await new Response(n).arrayBuffer())}return new Ie(new Int8Array(i.buffer,i.byteOffset,i.length))}}class Xu{constructor(t){this.names=t}body(t,e){return this.names?.bodies[t]??e}star(t){return this.names?.stars[t.name]??t.name}comet(t){return this.names?.comets[t.id]??t.name}nova(t){return this.names?.novae[t.id]??t.name}satelliteClass(t){return this.names?.satelliteClasses[t.id]??t.name}shower(t){return this.names?.showers[t.id]??t.name}lightRig(t){return this.names?.lightRigs[t.id]??t.name}instrument(t){return this.names?.instruments[t.id]??t.name}decorKind(t,e){return this.names?.decorKinds[t]??e}point(t){return Na.point(t,this.names?.compassPoints)}towards(t){return Na.towards(t,this.names)}}const RD=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,DD=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,ID=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,CD=20,PD=1;class OD{context;buffers=new Map;ambientSource;ambientGain;ambientKey="none";ambientToken=0;ambientVolume=0;windSource;windGain;windActive=!1;windToken=0;windVolume=0;paused=!0;requested={type:"none",intensity:0,windSpeed:0};level=1;master;output(t){return this.master||(this.master=t.createGain(),this.master.gain.value=this.level,this.master.connect(t.destination)),this.master}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",t);return}}Oa.unlock(this.context)}setAmbient(t,e,i){if(this.requested={type:t,intensity:e,windSpeed:i},!this.context)return;this.paused&&(t="none",e=0,i=0);const n=t==="rain"||t==="hail"?t:"none";if(this.ambientVolume=n==="hail"?Math.min(1,e*1.3+.2):n==="rain"?e:0,n!==this.ambientKey){this.ambientKey=n;const r=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,n!=="none"&&this.startLoop(RD,this.ambientVolume).then(o=>this.applyIfCurrent(o,r,()=>this.ambientToken,c=>{this.ambientSource=c?.source,this.ambientGain=c?.gain,c&&(c.gain.gain.value=this.ambientVolume)}))}else this.ambientGain&&(this.ambientGain.gain.value=this.ambientVolume);this.windVolume=Math.min(i/CD,1);const s=i>PD;if(s!==this.windActive){this.windActive=s;const r=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,s&&this.startLoop(DD,this.windVolume).then(o=>this.applyIfCurrent(o,r,()=>this.windToken,c=>{this.windSource=c?.source,this.windGain=c?.gain,c&&(c.gain.gain.value=this.windVolume)}))}else this.windGain&&(this.windGain.gain.value=this.windVolume)}setPaused(t){if(t===this.paused)return;this.paused=t;const{type:e,intensity:i,windSpeed:n}=this.requested;this.setAmbient(e,i,n)}playThunder(){!this.context||this.paused||this.playOneShot(ID,.9)}dispose(){this.ambientToken++,this.windToken++,this.stopSource(this.ambientSource,this.ambientGain),this.stopSource(this.windSource,this.windGain),this.ambientSource=void 0,this.ambientGain=void 0,this.windSource=void 0,this.windGain=void 0,this.context?.close(),this.context=void 0,this.master=void 0,this.buffers.clear()}applyIfCurrent(t,e,i,n){if(e!==i()){t?.source.stop();return}n(t)}async startLoop(t,e){const i=this.context;if(i)try{const n=await this.getBuffer(t),s=i.createBufferSource();s.buffer=n,s.loop=!0;const r=i.createGain();return r.gain.value=e,s.connect(r).connect(this.output(i)),s.start(),{source:s,gain:r}}catch(n){console.warn("Weather ambient sound failed to load, staying silent:",n);return}}async playOneShot(t,e){const i=this.context;if(i)try{const n=await this.getBuffer(t),s=i.createBufferSource();s.buffer=n;const r=i.createGain();r.gain.value=e,s.connect(r).connect(this.output(i)),s.start()}catch(n){console.warn("Thunder sound failed to load:",n)}}async getBuffer(t){const e=this.context;if(!e)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let i=this.buffers.get(t);return i||(i=fetch(t).then(n=>{if(!n.ok)throw new Error(`Audio fetch failed (${n.status}): ${t}`);return n.arrayBuffer()}).then(n=>e.decodeAudioData(n)),this.buffers.set(t,i)),i}stopSource(t,e){try{t?.stop()}catch{}t?.disconnect(),e?.disconnect()}}class nr{constructor(t){this.elements=t;const{eccentricity:e,perihelionAu:i}=t,[n,s]=this.perifocalAxes(),r=Math.sqrt(nr.SUN_GM_AU3_PER_DAY2*(1+e)/i);this.perihelionPosition=this.scale(n,i),this.perihelionVelocity=this.scale(s,r),this.inverseSemiMajorAxis=(1-e)/i}static SUN_GM_AU3_PER_DAY2=.0002959122082855911;static MAX_ITERATIONS=200;perihelionPosition;perihelionVelocity;inverseSemiMajorAxis;positionAt(t){const e=t-this.elements.perihelionJd,i=this.universalAnomaly(e),n=this.inverseSemiMajorAxis*i*i,s=this.elements.perihelionAu,r=1-i*i/s*nr.stumpffC(n),o=e-i*i*i/Math.sqrt(nr.SUN_GM_AU3_PER_DAY2)*nr.stumpffS(n);return{x:r*this.perihelionPosition.x+o*this.perihelionVelocity.x,y:r*this.perihelionPosition.y+o*this.perihelionVelocity.y,z:r*this.perihelionPosition.z+o*this.perihelionVelocity.z}}heliocentricDistanceAt(t){const e=this.positionAt(t);return Math.hypot(e.x,e.y,e.z)}universalAnomaly(t){if(t===0)return 0;const e=Math.sign(t),i=Math.sqrt(nr.SUN_GM_AU3_PER_DAY2)*Math.abs(t),n=o=>{const c=this.inverseSemiMajorAxis*o*o,l=this.elements.perihelionAu;return(1-this.inverseSemiMajorAxis*l)*o*o*o*nr.stumpffS(c)+l*o};let s=Math.max(1,i/this.elements.perihelionAu);for(;n(s)<i;)s*=2;let r=0;for(let o=0;o<nr.MAX_ITERATIONS&&s-r>1e-13*Math.max(1,s);o++){const c=(r+s)/2;n(c)<i?r=c:s=c}return e*(r+s)/2}perifocalAxes(){const t=this.elements.ascendingNodeDeg*Math.PI/180,e=this.elements.argumentOfPerihelionDeg*Math.PI/180,i=this.elements.inclinationDeg*Math.PI/180,n=Math.cos(t),s=Math.sin(t),r=Math.cos(e),o=Math.sin(e),c=Math.cos(i),l=Math.sin(i);return[{x:n*r-s*o*c,y:s*r+n*o*c,z:o*l},{x:-n*o-s*r*c,y:-s*o+n*r*c,z:r*l}]}scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}static stumpffC(t){if(Math.abs(t)<1e-6)return 1/2-t/24+t*t/720;if(t>0)return(1-Math.cos(Math.sqrt(t)))/t;const e=Math.sqrt(-t);return(Math.cosh(e)-1)/-t}static stumpffS(t){if(Math.abs(t)<1e-6)return 1/6-t/120+t*t/5040;if(t>0){const i=Math.sqrt(t);return(i-Math.sin(i))/(i*i*i)}const e=Math.sqrt(-t);return(Math.sinh(e)-e)/(e*e*e)}}const cy=[{id:"halley-1910",designation:"1P/Halley",name:"Halley's Comet",orbit:{eccentricity:.9672960498922706,perihelionAu:.5872100477652511,inclinationDeg:162.218798367122,ascendingNodeDeg:58.56208298700436,argumentOfPerihelionDeg:111.7366940639061,perihelionJd:2.4187816784171113e6},peakMagnitude:0,peakOn:"1910-05-20",absoluteMagnitude:4.72,activityExponent:4,tailLengthDeg:100,tailLengthAu:.1638,note:"Passed 0.15 au from Earth on 20 May 1910, and the Earth crossed the outer tail the day before — the apparition that produced a genuine public panic."},{id:"brooks-1911",designation:"C/1911 O1",name:"Comet Brooks",orbit:{eccentricity:.9876404970138669,perihelionAu:.4898172916113738,inclinationDeg:33.34043866978714,ascendingNodeDeg:293.7022074981857,argumentOfPerihelionDeg:153.5578007321686,perihelionJd:2.4193378856140426e6},peakMagnitude:2,peakOn:"1911-10-25",absoluteMagnitude:5.59,activityExponent:4},{id:"skjellerup-maristany-1927",designation:"C/1927 X1",name:"Comet Skjellerup-Maristany",orbit:{eccentricity:.999839726885059,perihelionAu:.1761569619628186,inclinationDeg:85.1125991950808,ascendingNodeDeg:78.24360172472711,argumentOfPerihelionDeg:47.15877857390136,perihelionJd:2.4252326808989984e6},peakMagnitude:-6,peakOn:"1927-12-15",absoluteMagnitude:1.19,activityExponent:4,note:"One of the few comets of the century seen in full daylight."},{id:"de-kock-paraskevopoulos-1941",designation:"C/1941 B2",name:"Comet de Kock-Paraskevopoulos",orbit:{eccentricity:.9991026715181549,perihelionAu:.7900329662827822,inclinationDeg:168.2039226531089,ascendingNodeDeg:43.10609347214336,argumentOfPerihelionDeg:268.6990344196369,perihelionJd:2430022157765061e-9},peakMagnitude:2,peakOn:"1941-02-05",absoluteMagnitude:5.01,activityExponent:4},{id:"southern-1947",designation:"C/1947 X1",name:"the Southern Comet",orbit:{eccentricity:.9998424430916737,perihelionAu:.1100045955093761,inclinationDeg:138.5113919632757,ascendingNodeDeg:337.3114969669252,argumentOfPerihelionDeg:196.1820121395961,perihelionJd:2.4325220864727003e6},peakMagnitude:-3,peakOn:"1947-12-08",absoluteMagnitude:3.01,activityExponent:4,note:"A bright southern-hemisphere comet of December 1947, the month the American sighting wave of that year was still being argued over."},{id:"eclipse-1948",designation:"C/1948 V1",name:"the Eclipse Comet",orbit:{eccentricity:.9999130678247334,perihelionAu:.1354437057263306,inclinationDeg:23.11668597152911,ascendingNodeDeg:211.0454985994762,argumentOfPerihelionDeg:107.2474157073104,perihelionJd:2.4328519265329437e6},peakMagnitude:-2,peakOn:"1948-11-01",absoluteMagnitude:4.79,activityExponent:4,note:"Found during the total solar eclipse of 1 November 1948, which is how a comet that bright had gone unnoticed: it had been hidden in the Sun's glare."},{id:"arend-roland-1957",designation:"C/1956 R1",name:"Comet Arend-Roland",orbit:{eccentricity:1.0002570255357,perihelionAu:.3160532361485914,inclinationDeg:119.9440863251822,ascendingNodeDeg:215.8548157717755,argumentOfPerihelionDeg:308.775920364167,perihelionJd:2.4359365327396123e6},peakMagnitude:.5,peakOn:"1957-04-25",absoluteMagnitude:3.96,activityExponent:4,note:"Showed a spike pointing back TOWARD the Sun in late April 1957 — a real anti-tail, and much reported at the time."},{id:"mrkos-1957",designation:"C/1957 P1",name:"Comet Mrkos",orbit:{eccentricity:.9993521583504134,perihelionAu:.3549238508212375,inclinationDeg:93.9433042053929,ascendingNodeDeg:68.32441518619923,argumentOfPerihelionDeg:40.31823675802871,perihelionJd:243605193752228e-8},peakMagnitude:1,peakOn:"1957-08-05",absoluteMagnitude:5.07,activityExponent:4,note:"The second bright naked-eye comet of 1957, four months after Arend-Roland."},{id:"seki-lines-1962",designation:"C/1962 C1",name:"Comet Seki-Lines",orbit:{eccentricity:1.000003791331562,perihelionAu:.03139689112215131,inclinationDeg:65.01487186102287,ascendingNodeDeg:304.6776602796538,argumentOfPerihelionDeg:11.47295326312573,perihelionJd:2437756163010178e-9},peakMagnitude:-2.5,peakOn:"1962-04-01",absoluteMagnitude:9.3,activityExponent:4},{id:"ikeya-seki-1965",designation:"C/1965 S1",name:"Comet Ikeya-Seki",orbit:{eccentricity:.9999141178248997,perihelionAu:.007785966366889336,inclinationDeg:141.8642315267051,ascendingNodeDeg:346.9951764632611,argumentOfPerihelionDeg:69.04909813996062,perihelionJd:2.4390546837018197e6},peakMagnitude:-10,peakOn:"1965-10-21",alsoRecordedMagnitude:2,alsoRecordedOn:"1965-10-30",absoluteMagnitude:5.26,activityExponent:4.002,tailLengthDeg:25,tailLengthAu:.5048,note:"A sungrazer that passed 450 000 km above the Sun's surface and was seen beside it in broad daylight — the brightest comet of the twentieth century. It then stood in the dawn sky for a fortnight with a tail some 25 degrees long, which is the second magnitude recorded here."},{id:"bennett-1970",designation:"C/1969 Y1",name:"Comet Bennett",orbit:{eccentricity:.9962979048768408,perihelionAu:.5376209981502136,inclinationDeg:90.03975717147327,ascendingNodeDeg:224.6576652531314,argumentOfPerihelionDeg:354.1494209173161,perihelionJd:2.4406655455270996e6},peakMagnitude:0,peakOn:"1970-03-26",absoluteMagnitude:3.36,activityExponent:4},{id:"white-ortiz-bolelli-1970",designation:"C/1970 K1",name:"Comet White-Ortiz-Bolelli",orbit:{eccentricity:.9999488875801225,perihelionAu:.00884411465256722,inclinationDeg:138.9520738221631,ascendingNodeDeg:336.8194095816687,argumentOfPerihelionDeg:61.10224765396615,perihelionJd:2.4407209807728203e6},peakMagnitude:1,peakOn:"1970-05-22",absoluteMagnitude:4.35,activityExponent:4},{id:"kohoutek-1973",designation:"C/1973 E1",name:"Comet Kohoutek",orbit:{eccentricity:1.000007152175185,perihelionAu:.1424250377812859,inclinationDeg:14.30414984159355,ascendingNodeDeg:258.4893339663974,argumentOfPerihelionDeg:37.79772760699667,perihelionJd:2442044930687027e-9},peakMagnitude:0,peakOn:"1974-01-05",absoluteMagnitude:4.89,activityExponent:4,note:"Announced in advance as the comet of the century and remembered for disappointing: it was an ordinary naked-eye object, not the spectacle the press had promised."},{id:"west-1976",designation:"C/1975 V1",name:"Comet West",orbit:{eccentricity:1.000017859625611,perihelionAu:.1966006188461085,inclinationDeg:43.07319920579427,ascendingNodeDeg:118.9189245655447,argumentOfPerihelionDeg:358.4315101259072,perihelionJd:2442833721841768e-9},peakMagnitude:-3,peakOn:"1976-02-25",absoluteMagnitude:4.41,activityExponent:4,tailLengthDeg:30,tailLengthAu:.4325,note:"Broke into four pieces at perihelion. Barely reported at the time — the press had been burned by Kohoutek two years earlier."},{id:"iras-araki-alcock-1983",designation:"C/1983 H1",name:"Comet IRAS-Araki-Alcock",orbit:{eccentricity:.9898409731606003,perihelionAu:.9913412593828502,inclinationDeg:73.25000846947029,ascendingNodeDeg:49.10235754476374,argumentOfPerihelionDeg:192.8506176754439,perihelionJd:2.4454757545235856e6},peakMagnitude:1.7,peakOn:"1983-05-11",absoluteMagnitude:9.04,activityExponent:4,note:"Passed 0.031 au from Earth on 11 May 1983, one of the closest cometary approaches on record: it crossed a quarter of the sky in a night, which no other comet in this list did."},{id:"halley-1986",designation:"1P/Halley",name:"Halley's Comet",orbit:{eccentricity:.9672792271749998,perihelionAu:.5871034488173393,inclinationDeg:162.2422242700916,ascendingNodeDeg:58.85993640671803,argumentOfPerihelionDeg:111.8655480539208,perihelionJd:2.4464709589610207e6},peakMagnitude:2.1,peakOn:"1986-03-10",absoluteMagnitude:2.71,activityExponent:4,note:"The worst-placed return in two thousand years — famous, expected, and for most observers a faint smudge."},{id:"hyakutake-1996",designation:"C/1996 B2",name:"Comet Hyakutake",orbit:{eccentricity:.9997295133739305,perihelionAu:.2302272039470452,inclinationDeg:124.923592343765,ascendingNodeDeg:188.0454295899424,argumentOfPerihelionDeg:130.1724036582639,perihelionJd:2.4502048946148166e6},peakMagnitude:0,peakOn:"1996-03-25",absoluteMagnitude:4.75,activityExponent:4,tailLengthDeg:80,tailLengthAu:1,note:"Passed 0.10 au from Earth in March 1996, five weeks BEFORE perihelion, with a tail measured at some 80 degrees — the longest of the modern era."},{id:"hale-bopp-1997",designation:"C/1995 O1",name:"Comet Hale-Bopp",orbit:{eccentricity:.9951314746156615,perihelionAu:.9141695067003724,inclinationDeg:89.43017155012492,ascendingNodeDeg:282.470602866853,argumentOfPerihelionDeg:130.5872524854533,perihelionJd:2450539633099368e-9},peakMagnitude:-.8,peakOn:"1997-04-01",absoluteMagnitude:-1.06,activityExponent:4,tailLengthDeg:20,tailLengthAu:.9938,note:"Visible to the naked eye for about eighteen months, longer than any comet on record."},{id:"mcnaught-2007",designation:"C/2006 P1",name:"Comet McNaught",orbit:{eccentricity:1.00001811603225,perihelionAu:.1707325614080681,inclinationDeg:77.83726446452654,ascendingNodeDeg:267.4149080498975,argumentOfPerihelionDeg:155.9756130642756,perihelionJd:2454113298753579e-9},peakMagnitude:-5.5,peakOn:"2007-01-13",absoluteMagnitude:2.53,activityExponent:4,tailLengthDeg:35,tailLengthAu:.5009,note:"The brightest comet since Ikeya-Seki, seen in daylight beside the Sun in January 2007."},{id:"lovejoy-2011",designation:"C/2011 W3",name:"Comet Lovejoy",orbit:{eccentricity:.999915056276912,perihelionAu:.005553783989325053,inclinationDeg:134.3558712062691,ascendingNodeDeg:326.3693517957772,argumentOfPerihelionDeg:53.50991655176601,perihelionJd:2455911511809431e-9},peakMagnitude:-3,peakOn:"2011-12-16",alsoRecordedMagnitude:1.5,alsoRecordedOn:"2011-12-22",absoluteMagnitude:3.51,activityExponent:1.194,note:"A sungrazer that was expected to be destroyed at perihelion and came out the other side, to stand in the southern dawn sky for the rest of December — which is the second magnitude recorded here."},{id:"panstarrs-2013",designation:"C/2011 L4",name:"Comet PANSTARRS",orbit:{eccentricity:1.000032542889696,perihelionAu:.301544229714915,inclinationDeg:84.2081978367921,ascendingNodeDeg:65.66588626213694,argumentOfPerihelionDeg:333.6516444379993,perihelionJd:2456361669960698e-9},peakMagnitude:1,peakOn:"2013-03-10",absoluteMagnitude:5.98,activityExponent:4},{id:"neowise-2020",designation:"C/2020 F3",name:"Comet NEOWISE",orbit:{eccentricity:.9991782081129224,perihelionAu:.2946512466331692,inclinationDeg:128.9375043020912,ascendingNodeDeg:61.01042991771634,argumentOfPerihelionDeg:37.2786526292898,perihelionJd:2.4590341788972816e6},peakMagnitude:.9,peakOn:"2020-07-08",absoluteMagnitude:5.79,activityExponent:4,tailLengthDeg:10,tailLengthAu:.1808,note:"The first comet since Hale-Bopp that ordinary observers in the northern hemisphere saw without being told where to look."},{id:"tsuchinshan-atlas-2024",designation:"C/2023 A3",name:"Comet Tsuchinshan-ATLAS",orbit:{eccentricity:1.000020192843226,perihelionAu:.3914228969475176,inclinationDeg:139.1105462619479,ascendingNodeDeg:21.55945689078845,argumentOfPerihelionDeg:308.4913086299446,perihelionJd:2460581242087108e-9},peakMagnitude:0,peakOn:"2024-10-14",absoluteMagnitude:3.97,activityExponent:4,tailLengthDeg:20,tailLengthAu:.1902,note:"Briefly reported far brighter around 9 October 2024, when it stood almost between the observer and the Sun and forward-scattered the light through its own dust — a geometry this catalog's brightness model does not attempt, so what is stored is the ordinary evening-sky peak a few days later."}];class LD{static WINDOW_DAYS=200;static TWILIGHT_ELONGATION_DEG=15;static LIGHT_SPEED_AU_PER_DAY=173.144632674;static orbits=new Map;static aroundDate(t){const e=this.julianDayOf(t);return cy.filter(i=>Math.abs(e-i.orbit.perihelionJd)<=this.WINDOW_DAYS)}static brightestAt(t,e){return this.aroundDate(t).map(i=>this.appearanceOf(i,t,e)).sort((i,n)=>i.magnitude-n.magnitude)[0]}static appearanceOf(t,e,i){const n=Ne(e),s=this.earthPositionAt(n),r=this.apparentPositionOf(t,2451545+n.tt,s),o=this.subtract(r,s),c=this.length(r),l=this.length(o),h=this.tailEndAt(t,r,s,c,n,e,i),u=this.horizontalOf(o,n,e,i);return{apparition:t,position:u,...h,heliocentricDistanceAu:c,earthDistanceAu:l,elongationDeg:this.angleBetween(o,this.subtract({x:0,y:0,z:0},s)),magnitude:this.magnitudeAt(t,c,l)}}static magnitudeAt(t,e,i){const n=t.absoluteMagnitude+5*Math.log10(i)+2.5*t.activityExponent*Math.log10(e);return Math.max(n,t.peakMagnitude)}static tailEndAt(t,e,i,n,s,r,o){if(t.tailLengthAu===void 0)return{};const c=1+t.tailLengthAu/n,l=this.subtract({x:e.x*c,y:e.y*c,z:e.z*c},i),h=this.subtract(e,i);return{tailEnd:this.horizontalOf(l,s,r,o),tailLengthDeg:this.angleBetween(h,l)}}static apparentPositionOf(t,e,i){const n=this.orbitOf(t);let s=n.positionAt(e);for(let r=0;r<2;r++){const o=this.length(this.subtract(s,i))/this.LIGHT_SPEED_AU_PER_DAY;s=n.positionAt(e-o)}return s}static horizontalOf(t,e,i,n){const s=cr(a4(),new ge(t.x,t.y,t.z,e)),r=cr(W2(e),s),o=np(e,new qr(n.lat,n.lng,n.elevationM),!0),c=new ge(r.x-o.x,r.y-o.y,r.z-o.z,e),l=fd(c);return um(l.ra,l.dec,i,n)}static earthPositionAt(t){return cr(r4(),Wr(ut.Earth,t))}static julianDayOf(t){return 2451545+Ne(t).tt}static orbitOf(t){const e=this.orbits.get(t.id);if(e)return e;const i=new nr(t.orbit);return this.orbits.set(t.id,i),i}static subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}static length(t){return Math.hypot(t.x,t.y,t.z)}static angleBetween(t,e){const i=(t.x*e.x+t.y*e.y+t.z*e.z)/(this.length(t)*this.length(e)||1);return Math.acos(Math.min(1,Math.max(-1,i)))*180/Math.PI}}const Uf=[{id:"sn-1006",kind:"supernova",designation:"SN 1006",name:"Supernova of 1006",raHours:15.03947,decDeg:-42.09694,peakMagnitude:-7.5,peakJd:2088620,startJd:2088620,lightCurve:[[0,-7.5],[29,-5.9],[60,-4.9],[106,-3.2],[166,-1.9],[258,-1],[350,.5],[364,.7],[411,1.2],[456,1.8],[484,2.5],[785.5,7]],source:"Winkler, Gupta & Long 2003 (peak); decline borrowed from SN 1572",note:"The brightest stellar event in recorded history, seen in daylight, low in the southern sky from Europe and the Near East. The decline is modelled, not recorded, and falls below the naked eye after about two years where the chronicles speak of three."},{id:"sn-1054",kind:"supernova",designation:"SN 1054",name:"Supernova of 1054",raHours:5.5755,decDeg:22.0175,peakMagnitude:-6,peakJd:2106216,startJd:2106216,lightCurve:[[0,-6],[23,-4],[642,6]],source:"Chinese chronicles (Song huiyao), via Stephenson & Green 2002",note:"The explosion that left the Crab Nebula. Its magnitude is an estimate; the two durations are recorded."},{id:"sn-1181",kind:"supernova",designation:"SN 1181",name:"Supernova of 1181",raHours:.88645,decDeg:67.50067,peakMagnitude:0,peakJd:2152636,startJd:2152636,lightCurve:[[0,0],[185,6]],source:"Chinese and Japanese chronicles, via Stephenson & Green 2002",note:"Circumpolar from Europe and China, so never set. Its peak magnitude is uncertain by at least a magnitude."},{id:"sn-1572",kind:"supernova",designation:"SN 1572",name:"Tycho's Supernova",raHours:.42264,decDeg:64.14083,peakMagnitude:-4,peakJd:2295551,startJd:2295546,lightCurve:[[0,-3],[5,-4],[34,-2.4],[65,-1.4],[111,.3],[171,1.6],[263,2.5],[355,4],[369,4.2],[416,4.7],[461,5.3],[489,6]],source:"Tycho Brahe and contemporaries, reduced by Ruiz-Lapuente 2004",note:"Circumpolar from northern Europe. Tycho showed it had no parallax, so it was not in the air: a new star, beyond the Moon."},{id:"sn-1604",kind:"supernova",designation:"SN 1604",name:"Kepler's Supernova",raHours:17.51125,decDeg:-21.48733,peakMagnitude:-2.95,peakJd:2307210,startJd:2307191,lightCurve:[[0,.23],[3,-1.3],[6,-2.08],[9,-2.17],[19,-2.95],[27,-2.95],[32,-1.95],[36,-1.52],[86,.9],[96,.45],[103,1],[114,1.2],[118,1.55],[133,1.95],[137,2.3],[170,2.25],[185,2.25],[194,2.4],[197,2.9],[308,4.45],[324,4.45],[339,4.95],[364,4.7]],source:"Kepler, Fabricius, Maestlin and the Korean court astronomers, reduced by Ruiz-Lapuente 2017",note:"The last supernova in our Galaxy seen with the naked eye. It went behind the Sun from mid-November 1604 to January 1605, which is the gap in its record."},{id:"t-crb-1866",kind:"nova",designation:"T CrB",name:"Nova Coronae Borealis 1866",raHours:15.99171,decDeg:25.92017,peakMagnitude:2,peakJd:2402734,startJd:2402734,lightCurve:[[0,2],[1.5,3],[2.5,3.11],[6.5,5.18],[8.5,5.75],[10.5,6.85],[11.5,6.8],[12.5,7.5],[16,8.18],[32,9.27],[38,9.2],[40,8.95],[44,9.4],[48,9.07],[54,9.4],[58,9.21],[79,9.44],[107,9.26],[111,9.01],[115,8.21],[119,7.96],[159,7.51],[179,7.57],[183,7.97],[191,7.66],[199,8.2],[207,8.31],[211,8.83],[215,8.65],[223,8.97],[297,8.9],[345,9.25],[377,9.07],[425,9.3],[537,9.3]],source:"Recorded peak (Birmingham); curve borrowed from its 1946 eruption",note:"The first eruption of the recurrent nova T CrB to be seen. The decline is its 1946 one."},{id:"t-aur-1891",kind:"nova",designation:"T Aur",name:"Nova Aurigae 1891",raHours:5.53309,decDeg:30.44583,peakMagnitude:4.49,peakJd:2412083,startJd:2412079,lightCurve:[[0,5.28],[4,4.49],[24,4.58],[40,4.97],[52,4.95],[56,4.5],[60,4.9],[68,4.88],[72,5.25],[76,4.93],[84,5.44],[88,7.23],[96,8.85],[100,10.44]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"gk-per-1901",kind:"nova",designation:"GK Per",name:"Nova Persei 1901",raHours:3.52,decDeg:43.90431,peakMagnitude:.19,peakJd:24154395e-1,startJd:24154377e-1,lightCurve:[[0,2.7],[.8,.86],[1.8,.19],[2.3,.2],[5.8,1.78],[11.8,2.54],[12.8,2.98],[17.8,3.62],[18.8,3.35],[19.8,3.77],[20.8,3.59],[22.8,3.95],[24.8,3.82],[25.6,4.99],[25.9,4.89],[26.6,3.69],[27.6,3.94],[27.9,4.61],[28.6,5.28],[28.9,4.46],[29.9,3.8],[30.9,4.27],[31.6,5.21],[31.9,5.22],[32.9,3.88],[33.9,4.19],[34.6,4.85],[35.6,4.8],[36.6,4.23],[37.6,4.44],[38.9,4.15],[39.7,5.19],[40.6,5.39],[40.9,5.35],[41.9,4.01],[42.6,4.5],[42.9,4.49],[43.6,5.53],[44,5.23],[44.6,5.61],[44.9,5.5],[45.9,4.17],[46.9,4.69],[47.6,5.5],[48.6,5.59],[49.6,5.14],[49.9,4.48],[50.6,4.45],[50.9,4.55],[51.6,5.47],[52.6,5.74],[53.7,5.66],[55.7,4.41],[56.7,5.43],[58.7,5.81],[58.9,5.58],[59.7,5.64],[59.9,4.76],[60.9,4.26],[61.9,5.62],[62.7,5.85],[62.9,5.53],[63.7,5.8],[64.9,4.28],[65.6,5.33],[66.7,5.87],[66.9,5.56],[68.7,5.7],[68.9,5.3],[69.7,4.47],[70.7,5.65],[72.9,5.98],[73.9,5.71],[74.7,4.98],[74.9,4.46],[75.7,4.87],[76.9,6.05],[77.6,5.76],[78,6],[78.7,5.95],[80.7,4.98],[81.9,5.85],[82.7,6.02],[84.7,5.41],[84.9,5.08],[85.7,5.17],[85.9,5.6],[87,6.1],[88.8,6.2],[89.7,4.96],[89.9,4.93],[90.7,5.9],[91.9,6.32],[92.7,5.86],[93.1,6.24],[93.7,5.38],[93.9,6.2],[96.1,6.12],[97.1,6.37],[97.6,5.12],[98,5.85],[99.3,6.35],[101.3,6.12],[101.7,5.25],[102.3,4.95],[102.7,6.12],[103.2,5.83],[104.7,6.37],[105,6.13],[106,6.22],[106.7,4.88],[107.7,6.3],[108.1,6.4],[109,6],[109.7,5.16],[110,5.82],[112.1,5.89],[113.1,5.5],[115.7,5.8],[116,6.11],[118.7,5.68],[119,6.23],[119.7,5.85],[120,6.12],[121,4.62],[121.8,5.9],[123,5.48],[125,6.05],[126,5.89],[130.9,6.11],[146.1,6.02],[155.6,6.26],[180.4,6.09],[190.4,6.39],[245.5,6.87],[266.2,6.77],[301.1,7.16],[321.5,7.07],[346.5,7.87],[375.7,7.86],[385.8,8.09],[389.8,8.55],[406.1,8.33],[416.5,8.59],[445.9,8.62],[472.1,9.24],[565.9,9.74],[571,9.4],[589.8,9.76]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"Discovered on 21 February 1901 by Thomas Anderson in Edinburgh, and the brightest nova of the century until V603 Aql."},{id:"dn-gem-1912",kind:"nova",designation:"DN Gem",name:"Nova Geminorum 1912",raHours:6.9151,decDeg:32.14108,peakMagnitude:3.58,peakJd:241947675e-2,startJd:241947275e-2,lightCurve:[[0,11.7],[1,4.5],[4,3.58],[5,4.45],[5.5,5.32],[6,5.53],[6.5,5.11],[8,5.43],[8.5,5.16],[11,5.53],[11.5,5.13],[12,5.18],[13.75,4.5],[15.75,5.3],[18.75,6],[19.75,5.55],[26.75,6],[28.75,5.9],[31.75,6.6],[32.75,6.2],[33.75,6.5],[36.75,6.55],[39.75,6.2],[40.75,6.75],[41.75,7],[44.75,6.75],[52.75,6.75],[54.75,7.23],[58.25,7.5],[62.25,7.3],[64.25,7.47],[66.25,8.1],[70.25,7.5],[72.25,8.1],[78.25,7.55],[80.25,8.2],[86.25,7.2],[90.25,7.3],[92.25,7.8],[152.25,7.2],[160.25,7.4],[166.25,8.2],[168.25,8.2],[170.25,7.3],[180.25,7.4],[182.25,8],[186.25,7.5],[190.25,7.6],[192.25,8],[211.25,7.75],[227.25,8],[275.25,7.78],[315.25,8.6],[331.25,7.79],[339.25,8.27],[363.25,8.61],[443.25,8.93],[451.25,9.2],[535.25,10.3],[567.25,9.9],[615.25,10.8],[631.25,10.63],[647.25,10.88],[679.25,10.8],[695.25,11.07],[727.25,11]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v603-aql-1918",kind:"nova",designation:"V603 Aql",name:"Nova Aquilae 1918",raHours:18.81518,decDeg:.58414,peakMagnitude:-.5,peakJd:242175475e-2,startJd:242174875e-2,lightCurve:[[0,11.3],[2,10.5],[4,6.6],[4.5,1.04],[6,-.5],[6.5,.18],[10,1.1],[10.5,.95],[12.75,1.89],[21.75,3.07],[23.75,3.76],[29.75,3.16],[34.75,3.5],[36.75,3.86],[44.75,3.79],[48.75,4.43],[52.75,3.84],[56.75,3.95],[57.75,4.04],[58.75,4.49],[59.75,4.42],[60.75,4.69],[62.75,4.6],[63.75,4.11],[64.75,3.97],[68.75,4.18],[70.75,4.65],[71.75,4.51],[73.75,4.73],[75.75,4.44],[79.75,4.85],[83.75,4.43],[89.75,4.88],[92.75,4.86],[94.75,4.58],[96.75,4.92],[99.75,5.05],[163.25,5.45],[167.25,5.7],[179.25,5.48],[191.25,5.8],[203.25,5.5],[247.25,5.9],[251.25,6.25],[257.25,5.5],[265.25,6.13],[281.25,6.33],[345.25,6.3],[385.25,6.73],[393.25,6.43],[425.25,6.71],[433.25,6.56],[461.25,7.27],[525.25,7.6],[541.25,7.47],[637.25,8.3],[669.25,8.17],[717.25,8.55],[749.25,8.4],[765.25,8.68],[885.25,8.75],[949.25,9.4],[1013.25,9.19],[1141.25,9.57],[1269.25,9.48],[1333.25,9.95],[1653.25,9.94],[1781.25,10.28],[1909.25,10.34],[2037.25,10.1],[2101.25,10.46],[2165.25,10.51],[2357.25,10.3],[2549.25,10.77],[2741.25,10.46],[2869.25,10.83],[3125.25,10.71],[3317.25,11.22],[3381.25,10.91],[3637.25,11.42],[3829.25,10.96],[3893.25,11.65],[3957.25,11.63],[4085.25,11.14],[4213.25,11.48],[4277.25,10.7],[4341.25,11.42],[4405.25,11.47],[4469.25,11.06],[4533.25,11.08],[4597.25,11.7],[4725.25,11.45],[4789.25,10.94]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"The brightest nova of the modern era, at magnitude -0.5 on 9-10 June 1918: as bright as Vega, in a summer evening sky, in wartime."},{id:"v476-cyg-1920",kind:"nova",designation:"V476 Cyg",name:"Nova Cygni 1920",raHours:19.97347,decDeg:53.61858,peakMagnitude:1.94,peakJd:242256025e-2,startJd:242255925e-2,lightCurve:[[0,2.7],[1,1.94],[3,2.07],[4.5,2.95],[8.25,4],[31.75,6.41],[35.75,7.23],[37.75,7.08],[41.75,7.33],[43.75,7.92],[45.75,8.2],[51.75,8.59],[63.75,8.82],[65.75,9.25],[71.75,8.93],[85.75,9.43],[87.75,9.05],[95.75,9.2],[97.75,8.67],[99.75,9.07],[112.75,8.78],[120.75,9.03],[128.75,8.67],[144.75,8.94],[152.75,8.73],[168.75,8.79],[176.75,9.28],[192.75,9],[216.75,9.6],[232.75,9.27],[240.75,9.5],[288.75,9.4],[296.75,9.6],[304.75,9.3],[320.75,9.73],[328.75,9.5],[336.75,9.8],[428.75,9.61],[476.75,10.01],[492.75,9.76],[508.75,9.87],[524.75,9.65],[556.75,9.87],[572.75,9.65],[620.75,10.22],[668.75,10.44],[684.75,10.23],[716.75,10.33],[756.75,10.66],[884.75,10.59],[948.75,10.96],[1108.75,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"rr-pic-1925",kind:"nova",designation:"RR Pic",name:"Nova Pictoris 1925",raHours:6.59335,decDeg:-62.64008,peakMagnitude:.95,peakJd:24243085e-1,startJd:24242995e-1,lightCurve:[[0,2.43],[5,2.35],[6,2.1],[7,2.4],[9,.95],[13,1.8],[14,1.7],[16,2.15],[18,2.2],[19,1.9],[23,3.1],[27,3.05],[31.5,3.58],[43.5,3.08],[47.5,3.15],[57.5,2.3],[59.5,1.65],[63.5,3.03],[65.5,2.84],[67.5,3.16],[69.5,2.4],[71.5,2.04],[73.5,2.05],[75.5,2.55],[79.5,3],[83.5,3.15],[116.5,3.54],[120.5,3.78],[124.5,3.67],[136.5,4.18],[148.5,4.34],[154.5,4.17],[194.5,4.43],[226.5,4.93],[234.5,4.8],[242.5,5.4],[250.5,5.5],[266.5,5.15],[298.5,5.6],[362.5,5.4],[414.5,5.7],[430.5,5.5],[494.5,6.2],[718.5,6.52],[830.5,6.3],[862.5,6.6],[878.5,6.4],[910.5,6.77],[958.5,6.67],[1062.5,7.07],[1318.5,7.35],[1590.5,8.12],[1718.5,8.25],[2486.5,8.59],[2614.5,8.47],[2742.5,8.7],[3382.5,8.6],[3766.5,8.97],[4022.5,8.79],[4150.5,9.22],[6710.5,10.29],[7414.5,11.03],[8438.5,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A slow nova, and a southern one: more than two months within two magnitudes of its peak."},{id:"dq-her-1934",kind:"nova",designation:"DQ Her",name:"Nova Herculis 1934",raHours:18.12507,decDeg:45.85906,peakMagnitude:1.56,peakJd:24277935e-1,startJd:242778675e-2,lightCurve:[[0,3.4],[1.5,2.4],[3,2.67],[5.75,2.01],[6.75,1.56],[7.75,1.59],[11.75,2.97],[12.75,2.31],[14.75,3.07],[15.75,2.56],[16.75,2.51],[19.75,2.68],[23.75,2.53],[24.75,2.27],[26.75,2.58],[30.75,2.24],[31.75,2.63],[32.75,2.66],[34.75,2.11],[39.75,2.71],[41.75,2.31],[43.75,2.37],[46.75,3.64],[47.75,3.21],[50.75,3.23],[52.75,2.66],[55.75,2.56],[58.75,2.97],[60.75,2.77],[61.75,3.36],[63.75,3.43],[64.75,2.89],[65.75,3.22],[68.75,3.52],[69.75,2.95],[70.75,3.06],[71.75,2.7],[76.75,3.65],[79.75,3.74],[81.75,3.21],[83.75,3.75],[87.75,3.69],[92.75,4.04],[94.75,4.8],[97.75,4.24],[98.75,4.52],[100.75,4.08],[101.75,4.43],[105.75,4.58],[106.75,4.33],[107.75,4.73],[108.75,6.57],[109.75,8.08],[110.75,8.15],[111.75,8.56],[113.75,8.45],[114.75,9.15],[115.75,9.15],[116.75,9.59],[117.75,9.43],[118.75,9.8],[122.75,10.5],[123.75,10.28],[124.75,10.93],[127.75,10.83],[129.75,11.87],[131.75,12.42],[135.75,12.5],[137.75,12.9],[138.75,12.77],[139.75,13],[143.75,12],[144.75,12.33],[146.75,12.35],[147.75,11.64],[148.75,11.83],[150.75,10.9],[151.75,10.78],[152.75,11.17],[154.75,10.32],[155.75,10.4],[165.25,9.24],[185.25,7.74],[225.25,6.8],[273.25,6.72],[321.25,6.97],[333.25,6.79],[353.25,7],[357.25,6.82],[377.25,6.88],[401.25,7.29],[409.25,6.8],[413.25,6.8],[419.25,7.1],[435.25,7.09],[451.25,7.4],[475.25,7],[555.25,7.48],[823.25,7.83],[855.25,8.18],[1135.25,8.43],[1823.25,9.98],[1887.25,9.71],[2015.25,10.55],[2335.25,10.95]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"Lost about ten magnitudes in a few weeks from April 1935, when dust condensed around it, then came back to naked-eye brightness."},{id:"cp-lac-1936",kind:"nova",designation:"CP Lac",name:"Nova Lacertae 1936",raHours:22.26142,decDeg:55.61703,peakMagnitude:2.02,peakJd:242834025e-2,startJd:242833825e-2,lightCurve:[[0,4.03],[.5,2.9],[1,2.45],[2,2.02],[2.5,2.61],[4,3],[4.5,3.35],[5,3.3],[9.25,4.59],[14.25,5.45],[22.25,6.03],[23.25,6.3],[26.25,6.23],[38.25,6.74],[41.25,6.61],[50.25,7.35],[53.25,7.27],[57.25,7.7],[58.25,7.54],[60.25,7.55],[61.25,7.79],[71.25,7.6],[74.25,7.81],[76.25,8.3],[77.25,7.79],[86.25,8.21],[87.25,8],[88.25,8.25],[92.25,8.17],[94.25,8.47],[102.25,8.27],[103.25,8.7],[104.25,8.4],[110.25,8.66],[116.75,8.55],[122.75,8.83],[126.75,8.7],[140.75,9.06],[154.75,9.01],[164.75,9.36],[170.75,9.18],[174.75,9.48],[186.75,9.42],[188.75,9.73],[192.75,9.53],[200.75,9.74],[202.75,9.5],[204.75,9.77],[208.75,9.6],[214.75,9.75],[216.75,10.05],[222.75,9.7],[232.75,10.03],[236.75,9.82],[250.75,10.1],[254.75,9.9],[260.75,10.1],[264.75,9.8],[266.75,10.15],[268.75,10],[274.75,10.2],[276.75,9.9],[292.75,10.6],[294.75,10.6],[298.75,10.1],[318.75,10.35],[320.75,10.6],[322.75,10.3],[328.75,10.65],[332.75,10.3],[338.75,10.7],[348.75,10.53],[350.75,10.7],[354.75,10.37],[358.75,10.58],[365.75,10.43],[373.75,10.85],[421.75,10.94]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"cp-pup-1942",kind:"nova",designation:"CP Pup",name:"Nova Puppis 1942",raHours:8.19613,decDeg:-35.35139,peakMagnitude:.73,peakJd:243067675e-2,startJd:243067275e-2,lightCurve:[[0,.95],[4,.73],[4.5,1.3],[5.5,1.47],[6,2.01],[7.75,2.88],[8.75,2.97],[10.75,3.5],[11.75,4.02],[13.75,4.4],[14.75,3.8],[17.75,5],[18.75,4.93],[19.75,5.48],[23.75,5.5],[25.75,5.65],[26.75,5.99],[33.25,6.28],[45.25,6.6],[57.25,6.41],[81.25,6.85],[89.25,6.5],[97.25,6.67],[101.25,7],[113.25,6.66],[125.25,7.1],[135.25,6.96],[231.25,7.86],[279.25,7.8],[327.25,8.33],[407.25,8.18],[423.25,8.59],[471.25,8.53],[503.25,8.99],[551.25,8.97],[567.25,8.7],[583.25,9.47],[615.25,8.95],[655.25,9.5],[751.25,9.55],[815.25,10.09],[847.25,10.02],[879.25,10.48],[911.25,10.34],[1023.25,10.79],[1279.25,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"One of the fastest bright novae: two magnitudes gone in four days."},{id:"t-crb-1946",kind:"nova",designation:"T CrB",name:"Nova Coronae Borealis 1946",raHours:15.99171,decDeg:25.92017,peakMagnitude:2.5,peakJd:2431860,startJd:2431860,lightCurve:[[0,2.5],[1.5,3.5],[2.5,3.61],[6.5,5.68],[8.5,6.25],[10.5,7.35],[11.5,7.3],[12.5,8],[16,8.68],[32,9.77],[38,9.7],[40,9.45],[44,9.9],[48,9.57],[54,9.9],[58,9.71],[79,9.94],[107,9.76],[111,9.51],[115,8.71],[119,8.46],[159,8.01],[179,8.07],[183,8.47],[191,8.16],[199,8.7],[207,8.81],[211,9.33],[215,9.15],[223,9.47],[297,9.4],[345,9.75],[377,9.57],[425,9.8],[537,9.8]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A recurrent nova. It erupted in 1866 and in 1946, and a third eruption was expected from 2024 on."},{id:"v446-her-1960",kind:"nova",designation:"V446 Her",name:"Nova Herculis 1960",raHours:18.956,decDeg:13.24147,peakMagnitude:4.83,peakJd:24370038e-1,startJd:24370033e-1,lightCurve:[[0,5.2],[.5,4.83],[2,4.9],[2.5,5.4],[3,5.05],[3.5,5.57],[4,5.25],[5,5.5],[6.5,5.4],[7.2,5.78],[8.2,5.6],[9.2,5.98],[10.2,5.92],[11.2,6.21],[16.2,6.1],[17.2,6.23],[18.2,7.2],[19.2,6.51],[20.2,6.78],[26.2,6.97],[27.2,7.24],[28.2,7.13],[29.2,7.45],[31.2,7.2],[40.7,7.57],[44.7,8.25],[46.7,7.84],[56.7,8.15],[60.7,8.9],[70.7,8.7],[72.7,8.14],[76.7,8.71],[80.7,8.47],[82.7,8.87],[86.7,8.57],[90.7,8.93],[107.7,9.11],[111.7,8.94],[115.7,9.27],[139.7,9.38],[151.7,9.91],[155.7,9.72],[173.7,10.51],[221.7,10.95]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v533-her-1963",kind:"nova",designation:"V533 Her",name:"Nova Herculis 1963",raHours:18.23902,decDeg:41.85614,peakMagnitude:3,peakJd:24380605e-1,startJd:24380565e-1,lightCurve:[[0,8],[4,3],[4.5,3],[8,4],[13,3.95],[15,4.6],[21,4.53],[24,5.05],[27,5.15],[32,4.76],[34,4.98],[35,5.39],[37,5.43],[41,6.04],[49,6.02],[56.5,6.34],[60.5,6.11],[74.5,6.72],[102.5,6.99],[137.5,7.81],[197.5,8.31],[217.5,8.8],[225.5,8.57],[233.5,9.03],[237.5,8.78],[277.5,9.44],[301.5,9.46],[315.5,9.86],[323.5,9.73],[339.5,10.05],[355.5,10.74],[363.5,10.32],[371.5,10.6],[387.5,10.69],[427.5,10.38],[435.5,10.84],[443.5,10.74],[451.5,11.33],[459.5,10.98],[467.5,11.17],[507.5,11.16],[539.5,11.66],[603.5,11.7],[619.5,12.05],[651.5,12.03],[659.5,11.74],[667.5,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"hr-del-1967",kind:"nova",designation:"HR Del",name:"Nova Delphini 1967",raHours:20.70565,decDeg:19.16092,peakMagnitude:3.58,peakJd:2439838,startJd:2439646,lightCurve:[[0,11.9],[6,11.8],[12,8.8],[16,8.3],[20,6.7],[30,5.8],[36,5.51],[66,5.55],[78,5.35],[86,4.89],[96,5],[108,4.75],[136,5.13],[152,4.83],[182,4.93],[186,4.59],[192,3.58],[202,5],[220,5.46],[226,5.14],[230,5.45],[232,5.14],[236,5],[242,5.08],[244,4.59],[246,4.45],[254,5.3],[256,4.75],[260,5.69],[268,4.8],[274,4.94],[276,5.45],[280,5.2],[282,5.51],[286,5.58],[292,4.95],[294,5.16],[298,4.94],[311,5.09],[335,4.4],[367,5.76],[407,6.16],[423,6.55],[603,7.43],[907,8.32],[1451,9.41],[2347,10.75]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"An exceptionally slow nova: rose over months and stayed near magnitude 4 to 5 for most of 1967 and 1968."},{id:"lv-vul-1968",kind:"nova",designation:"LV Vul",name:"Nova Vulpeculae 1968",raHours:19.80012,decDeg:27.1715,peakMagnitude:4.5,peakJd:243996425e-2,startJd:243996325e-2,lightCurve:[[0,5],[1,4.5],[2,5],[2.5,4.86],[3,5.1],[3.5,4.88],[4,5.1],[5,4.9],[7,5.4],[8,5.23],[10.5,5.42],[12,5.82],[13,5.4],[13.5,5.74],[14,5.7],[14.5,6.08],[15,5.75],[15.5,5.86],[16,5.6],[17,5.8],[18,5.6],[20.5,6.34],[21,6.2],[22.5,6.84],[23,6.57],[24,6.98],[24.5,6.3],[25,7.1],[26,6.65],[34.25,7.48],[35.25,7.23],[39.25,7.32],[44.25,7.76],[45.25,7.49],[46.25,7.78],[50.25,7.84],[51.25,8.1],[53.25,7.9],[54.25,8.13],[56.25,8],[57.75,8.24],[67.75,8.52],[75.75,8.38],[83.75,8.69],[89.75,8.59],[125.75,9.32],[127.75,9.33],[129.75,8.98],[131.75,9.29],[135.75,9.43],[212.75,9.9],[220.75,10.16],[228.75,10.03],[236.75,10.3],[244.75,10.16],[264.75,10.54],[280.75,10.45],[296.75,10.79],[328.75,10.78]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"fh-ser-1970",kind:"nova",designation:"FH Ser",name:"Nova Serpentis 1970",raHours:18.51307,decDeg:2.61444,peakMagnitude:4.5,peakJd:244063425e-2,startJd:244063125e-2,lightCurve:[[0,7],[2,5],[3,4.5],[3.5,5],[4.5,4.6],[5.5,5],[6.5,4.68],[12.25,4.66],[16.25,5.3],[17.25,5.72],[18.25,5.3],[19.25,5.2],[23.25,5.84],[24.25,5.68],[27.25,5.9],[30.25,5.47],[32.25,5.9],[34.25,5.7],[43.25,6.28],[45.25,6.1],[50.25,6.62],[52.25,6.47],[57.25,6.63],[60.25,7.08],[61.25,6.87],[62.25,7.2],[63.25,6.85],[64.25,7.68],[65.25,7.3],[66.25,8.3],[67.25,7.93],[69.25,9.15],[71.25,9.2],[72.25,9.63],[74.25,9.9],[76.25,9.7],[77.25,10.25],[78.25,10.1],[79.25,10.4],[80.25,10.23],[81.25,10.57],[83.25,10.64],[85.25,10.35],[86.25,11.2],[87.25,10.1],[89.25,11.2],[96.25,11.35],[100.25,11.95],[102.25,11.1],[104.25,11.65],[106.25,11.5],[108.25,12.07],[114.75,11.32],[118.75,11.28],[122.75,10.93],[130.75,10.85],[134.75,10.52],[154.75,10.65],[162.75,10.12],[174.75,9.98],[178.75,10.34],[186.75,9.98],[214.75,10.25],[224.75,10.02],[240.75,10.2],[264.75,10],[272.75,10.2],[280.75,10.05],[288.75,10.4],[296.75,10],[348.75,10.7],[396.75,10.3],[444.75,10.73],[460.75,10.59],[540.75,10.94],[556.75,10.82]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v1500-cyg-1975",kind:"nova",designation:"V1500 Cyg",name:"Nova Cygni 1975",raHours:21.19349,decDeg:48.15056,peakMagnitude:1.88,peakJd:244265525e-2,startJd:244265425e-2,lightCurve:[[0,2.44],[1,1.88],[1.5,1.88],[2.5,2.41],[3,3.38],[4,4.28],[8.25,5.81],[11.25,6.46],[22.25,7.35],[33.25,7.73],[34.25,7.97],[37.25,7.86],[40.25,8.3],[43.25,8.19],[48.25,8.6],[49.25,8.46],[66.25,9.04],[70.25,8.93],[75.25,9.23],[76.25,9.03],[80.25,9.39],[81.25,9.19],[83.25,9.35],[84.25,9.13],[86.25,9.39],[89.25,9.32],[90.25,9.54],[93.25,9.37],[105.75,9.86],[193.75,10.43],[201.75,10.7],[209.75,10.47],[257.75,10.94],[265.75,10.81]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"One of the fastest novae on record: discovered on 29 August 1975, at its peak of magnitude 1.9 within two days, and two magnitudes down again two days later."},{id:"v842-cen-1986",kind:"nova",designation:"V842 Cen",name:"Nova Centauri 1986",raHours:14.59794,decDeg:-57.6265,peakMagnitude:4.9,peakJd:244675975e-2,startJd:244675725e-2,lightCurve:[[0,5.6],[2.5,4.9],[3.5,5.1],[15.5,5.1],[17.5,5.75],[18.5,5.4],[20.5,5.5],[22.5,5.95],[30.5,6.15],[31.5,6.3],[32,7.5],[34.5,7.2],[38.5,7.5],[39,7],[41.5,7.15],[42.5,6.7],[44.5,7.23],[45.5,6.6],[53,9.3]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"sn-1987a",kind:"supernova",designation:"SN 1987A",name:"Supernova 1987A",raHours:5.59111,decDeg:-69.26975,peakMagnitude:2.98,peakJd:24469425e-1,startJd:24468495e-1,lightCurve:[[0,6.36],[1,6.11],[2,4.63],[4,4.45],[32,3.97],[56,3.15],[93,2.98],[105,3.35],[118,4.11],[134,4.43],[504,8.15],[617,10.27]],source:"V photometry compiled by the Open Supernova Catalog (Sternberg catalogue, IAU circulars, CTIO)",note:"In the Large Magellanic Cloud, 160 000 light years away: the nearest supernova since Kepler's, and invisible north of about 20° N."},{id:"v1974-cyg-1992",kind:"nova",designation:"V1974 Cyg",name:"Nova Cygni 1992",raHours:20.50879,decDeg:52.63078,peakMagnitude:4.27,peakJd:24486753e-1,startJd:24486718e-1,lightCurve:[[0,7.2],[1,5.23],[2,4.62],[3.5,4.27],[4.5,4.59],[6,4.5],[7,4.78],[7.5,4.52],[8,4.82],[10.7,5.25],[11.7,5.66],[16.7,5.85],[21.7,6.47],[22.7,6.3],[27.7,6.46],[29.7,6.83],[34.7,6.9],[35.7,7.25],[36.7,7],[37.7,7.16],[39.7,7.03],[43.7,7.41],[45.7,7.26],[50.7,7.45],[57.7,7.78],[58.7,8.13],[61.7,7.92],[64.7,8.19],[65.7,7.99],[71.7,8.22],[76.7,8.01],[128.2,8.72],[176.2,8.89],[192.2,9.15],[216.2,9.28],[232.2,9.07],[236.2,9.3],[390.2,10.99]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v382-vel-1999",kind:"nova",designation:"V382 Vel",name:"Nova Velorum 1999",raHours:10.74678,decDeg:-52.42533,peakMagnitude:2.88,peakJd:245132225e-2,startJd:245132075e-2,lightCurve:[[0,2.99],[1.5,2.88],[2.5,3.46],[4.5,3.98],[5,4.32],[5.5,4.23],[7.5,4.85],[21.75,6.67],[30.25,7.2],[40.25,7.41],[93.25,7.95],[97.25,8.25],[101.25,8],[113.25,7.96],[129.25,8.5],[155.25,8.47],[163.25,9.1],[179.25,9],[187.25,8.7],[195.25,9.15],[211.25,9.23],[235.25,9.8],[243.25,9.71],[299.25,10.42],[383.25,10.52],[415.25,10.81]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v1494-aql-1999",kind:"nova",designation:"V1494 Aql",name:"Nova Aquilae 1999",raHours:19.38482,decDeg:4.9555,peakMagnitude:4.11,peakJd:245151575e-2,startJd:245151425e-2,lightCurve:[[0,5.15],[.5,4.86],[1,4.27],[1.5,4.11],[2.5,4.35],[5,5.48],[10.5,6.26],[14.25,6.28],[20.25,7.43],[24.25,7.25],[25.25,7.63],[27.25,7.7],[29.25,7.42],[33.25,8.08],[35.25,8.03],[36.25,7.6],[37.25,7.6],[46.25,8.5],[54.25,8.28],[56.25,8.63],[58.25,8.4],[61.25,9.53],[62.25,9],[64.25,9.13],[69.25,8.58],[70.25,8.9],[72.25,8.88],[75.25,8.57],[77.25,9],[79.25,8.8],[81.25,9.7],[83.25,9.6],[85.25,9.8],[86.75,9.5],[88.75,9.54],[90.75,8.9],[92.75,8.85],[96.75,9.63],[102.75,9.7],[104.75,8.98],[106.75,8.73],[116.75,9.63],[118.75,9.6],[120.75,9.07],[122.75,9.26],[124.75,9.8],[128.75,9.36],[134.75,9.75],[147.75,9.92],[155.75,9.81],[259.75,10.96]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"v4743-sgr-2002",kind:"nova",designation:"V4743 Sgr",name:"Nova Sagittarii 2002",raHours:19.01926,decDeg:-22.00167,peakMagnitude:5,peakJd:245253775e-2,startJd:245253675e-2,lightCurve:[[0,5.2],[1,5],[2,5.89],[2.5,5.91],[3.5,6.43],[5,6.45],[5.5,6.86],[6,6.59],[7,6.77],[7.5,7.31],[8.5,6.99],[9,7.09],[10.5,7.86],[11,7.58],[11.5,7.89],[15.75,8.33],[17.75,8.18],[18.75,8.58],[19.75,8.44],[22.75,8.83],[23.75,8.6],[24.75,8.85],[27.75,8.83],[30.75,9.4],[31.75,9.09],[36.25,9.08],[38.25,9.34],[62.25,9.75],[66.25,10.1],[70.25,9.7],[74.25,10],[171.25,10.9]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010"},{id:"rs-oph-2006",kind:"nova",designation:"RS Oph",name:"Nova Ophiuchi 2006",raHours:17.83699,decDeg:-6.70792,peakMagnitude:4.8,peakJd:2453779,startJd:2453779,lightCurve:[[0,4.8],[1.25,4.97],[2.75,5.78],[3.25,5.7],[3.75,6.24],[4.25,6.05],[4.75,6.38],[5.25,6.3],[8.5,7.25],[14.5,7.95],[24.5,8.55],[29.5,9.08],[48,9.87],[80,10.28],[107,11.54],[119,11.54],[139,11.98],[147,11.83],[163,12.03],[171,11.97],[175,11.65],[183,11.84],[195,11.64],[203,11.8],[207,12.13],[219,11.45],[277,11.68],[325,11],[341,11.53],[357,11.62],[373,11.3],[405,11.5],[421,11.17],[469,10.96],[501,11.22],[549,10.75],[581,11.08],[597,10.98]],source:"AAVSO, binned by Strope, Schaefer & Henden 2010",note:"A recurrent nova, erupting every twenty years or so (1898, 1907, 1933, 1945, 1958, 1967, 1985, 2006, 2021)."},{id:"v1280-sco-2007",kind:"nova",designation:"V1280 Sco",name:"Nova Scorpii 2007",raHours:16.96145,decDeg:-32.34325,peakMagnitude:3.8,peakJd:2454149,startJd:2454136,lightCurve:[[0,9.7],[13,3.8],[34,5.8],[103,15]],source:"AAVSO (discovery, peak, dust minimum); t2 from Das et al. 2008",note:"Faded from sight quickly when dust formed around it, three weeks after its peak."},{id:"v339-del-2013",kind:"nova",designation:"V339 Del",name:"Nova Delphini 2013",raHours:20.39186,decDeg:20.76772,peakMagnitude:4.4,peakJd:24565214e-1,startJd:24565214e-1,lightCurve:[[0,4.4],[11,6.4],[20,7.4]],source:"Gehrz et al. 2015 (peak, t2, t3)",note:"High in the summer evening sky of the northern hemisphere, and widely photographed."},{id:"v1369-cen-2013",kind:"nova",designation:"V1369 Cen",name:"Nova Centauri 2013",raHours:13.9126,decDeg:-59.15114,peakMagnitude:3.48,peakJd:245663965e-2,startJd:24566285e-1,lightCurve:[[0,5.33],[1.57,4.08],[2.75,3.73],[4.57,4.16],[5.96,4.15],[10.26,3.77],[11.15,3.48],[12.14,3.74],[14.17,4.78],[15.46,4.97],[23.16,4.22],[26.25,4.32],[27.31,4.82],[29.56,5.11],[32.66,4.71],[33.84,4.86],[36.05,4.46],[37.15,4.99],[41.42,4.59],[42.37,4.93],[43.37,4.82],[44.54,5.09],[49.95,5.38],[51.99,5.82],[54.21,5.77]],source:"AAVSO, binned by day, as plotted by Izzo 2017 (arXiv:1704.07214, figure 1)",note:"Discovered on 2 December 2013 by John Seach at magnitude 5.5, it flared several times, reaching about 3.3 around 14 December: the brightest nova of the century so far, and a southern one."},{id:"rs-oph-2021",kind:"nova",designation:"RS Oph",name:"Nova Ophiuchi 2021",raHours:17.83699,decDeg:-6.70792,peakMagnitude:4.6,peakJd:2459436,startJd:2459435,lightCurve:[[0,5],[1,4.6],[2.25,4.77],[3.75,5.58],[4.25,5.5],[4.75,6.04],[5.25,5.85],[5.75,6.18],[6.25,6.1],[9.5,7.05],[15.5,7.75],[25.5,8.35],[30.5,8.88],[49,9.67],[81,10.08],[108,11.34],[120,11.34],[140,11.78],[148,11.63],[164,11.83],[172,11.77],[176,11.45],[184,11.64],[196,11.44],[204,11.6],[208,11.93],[220,11.25],[278,11.48],[326,10.8],[342,11.33],[358,11.42],[374,11.1],[406,11.3],[422,10.97],[470,10.76],[502,11.02],[550,10.55],[582,10.88],[598,10.78]],source:"Recorded discovery and peak (8 and 9 August 2021); curve borrowed from its 2006 eruption",note:"RS Oph's latest eruption, discovered on 8 August 2021. The decline is its 2006 one."}];class qv{static UNIX_EPOCH_JD=24405875e-1;static aroundDate(t){const e=this.julianDayOf(t);return Uf.filter(i=>this.magnitudeAt(i,e)!==void 0)}static appearancesAt(t,e){const i=this.julianDayOf(t),n=[];for(const s of Uf){const r=this.magnitudeAt(s,i);r!==void 0&&n.push({outburst:s,position:os.ofJ2000(s.raHours,s.decDeg,t,e),magnitude:r})}return n.sort((s,r)=>s.magnitude-r.magnitude)}static brightestAt(t,e){return this.appearancesAt(t,e)[0]}static byId(t){return Uf.find(e=>e.id===t)}static magnitudeAt(t,e){const i=t.lightCurve,n=e-t.startJd;if(i.length===0||n<i[0][0]||n>i[i.length-1][0])return;let s=1;for(;s<i.length-1&&i[s][0]<n;)s++;const[r,o]=i[s-1]??i[0],[c,l]=i[s]??i[0];if(c===r)return o;const h=Math.min(1,Math.max(0,(n-r)/(c-r)));return o+h*(l-o)}static julianDayOf(t){return t.getTime()/864e5+this.UNIX_EPOCH_JD}}const ND=[{id:"quadrantids",code:"QUA",name:"Quadrantids",radiantRaHours:15.33,radiantDecDeg:49.7,start:{month:12,day:28},peak:{month:1,day:3},end:{month:1,day:12},peakZhr:110,velocityKmS:41,populationIndex:2.1},{id:"lyrids",code:"LYR",name:"April Lyrids",radiantRaHours:18.13,radiantDecDeg:33.3,start:{month:4,day:16},peak:{month:4,day:22},end:{month:4,day:25},peakZhr:18,velocityKmS:49,populationIndex:2.1},{id:"eta-aquariids",code:"ETA",name:"eta Aquariids",radiantRaHours:22.53,radiantDecDeg:-1,start:{month:4,day:19},peak:{month:5,day:6},end:{month:5,day:28},peakZhr:50,velocityKmS:66,populationIndex:2.4},{id:"alpha-capricornids",code:"CAP",name:"alpha Capricornids",radiantRaHours:20.47,radiantDecDeg:-9.2,start:{month:7,day:3},peak:{month:7,day:30},end:{month:8,day:15},peakZhr:5,velocityKmS:23,populationIndex:2.5},{id:"southern-delta-aquariids",code:"SDA",name:"Southern delta Aquariids",radiantRaHours:22.67,radiantDecDeg:-16.4,start:{month:7,day:12},peak:{month:7,day:30},end:{month:8,day:23},peakZhr:25,velocityKmS:41,populationIndex:3.2},{id:"perseids",code:"PER",name:"Perseids",radiantRaHours:3.22,radiantDecDeg:58,start:{month:7,day:17},peak:{month:8,day:12},end:{month:8,day:24},peakZhr:100,velocityKmS:59,populationIndex:2.2},{id:"southern-taurids",code:"STA",name:"Southern Taurids",radiantRaHours:3.47,radiantDecDeg:13,start:{month:9,day:10},peak:{month:10,day:10},end:{month:11,day:20},peakZhr:5,velocityKmS:27,populationIndex:2.3},{id:"draconids",code:"DRA",name:"October Draconids",radiantRaHours:17.47,radiantDecDeg:54,start:{month:10,day:6},peak:{month:10,day:8},end:{month:10,day:10},peakZhr:10,velocityKmS:20,populationIndex:2.6},{id:"orionids",code:"ORI",name:"Orionids",radiantRaHours:6.35,radiantDecDeg:15.6,start:{month:10,day:2},peak:{month:10,day:21},end:{month:11,day:7},peakZhr:20,velocityKmS:66,populationIndex:2.5},{id:"northern-taurids",code:"NTA",name:"Northern Taurids",radiantRaHours:3.87,radiantDecDeg:22,start:{month:10,day:20},peak:{month:11,day:12},end:{month:12,day:10},peakZhr:5,velocityKmS:29,populationIndex:2.3},{id:"leonids",code:"LEO",name:"Leonids",radiantRaHours:10.13,radiantDecDeg:21.6,start:{month:11,day:6},peak:{month:11,day:17},end:{month:11,day:30},peakZhr:15,velocityKmS:71,populationIndex:2.5},{id:"geminids",code:"GEM",name:"Geminids",radiantRaHours:7.47,radiantDecDeg:32.3,start:{month:12,day:4},peak:{month:12,day:14},end:{month:12,day:17},peakZhr:150,velocityKmS:35,populationIndex:2.6},{id:"ursids",code:"URS",name:"Ursids",radiantRaHours:14.47,radiantDecDeg:75.3,start:{month:12,day:17},peak:{month:12,day:22},end:{month:12,day:26},peakZhr:10,velocityKmS:33,populationIndex:3}],Yu=6.5;class zf{static activeAt(t){return ND.flatMap(e=>{const i=this.nearness(e,t);return i<=0?[]:[{shower:e,zhr:e.peakZhr*i,nearness:i}]})}static nearness(t,e){const i=this.dayOfYear(e),n=this.dayOfYear(this.asDate(t.start)),s=this.dayOfYear(this.asDate(t.peak)),r=this.dayOfYear(this.asDate(t.end)),o=this.wrappedDelta(i,s),c=this.wrappedDelta(s,n),l=this.wrappedDelta(r,s);return o<0?o<-c?0:1+o/c:o>0?o>l?0:1-o/l:1}static observedRatePerHour(t,e,i,n=Yu){if(e<=0)return 0;const s=Yu-n;return t*Math.sin(e*Math.PI/180)/Math.pow(i,s)}static radiantPosition(t,e,i){return os.ofJ2000(t.radiantRaHours,t.radiantDecDeg,e,i)}static dayOfYear(t){const e=Date.UTC(t.getUTCFullYear(),0,1);return Math.floor((Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-e)/864e5)+1}static asDate(t){return new Date(Date.UTC(2001,t.month-1,t.day))}static wrappedDelta(t,e){const i=t-e;return i>182?i-365:i<-182?i+365:i}}class fi{static QUIET_RATE_PER_HOUR=2;static APEX_RATE_PER_HOUR=8;static POPULATION_INDEX=3;static apexPosition(t,e){const i=Ne(t),n=new ld(0,FT(t).elon-90,1),s=cr(u4(i),hm(n,i)),r=fd(s);return um(r.ra,r.dec,t,e)}static observedRatePerHour(t,e=Yu){const i=fi.APEX_RATE_PER_HOUR*Math.max(0,Math.sin(t*Math.PI/180)),n=Yu-e;return(fi.QUIET_RATE_PER_HOUR+i)/Math.pow(fi.POPULATION_INDEX,n)}static schedule(t){const e=new pd(t.seed^1542469173);return ka.schedule(t).map(i=>{const n=fi.toCartesian({altitudeDeg:Math.asin(e.next())*180/Math.PI,azimuthDeg:e.between(0,360)}),s=i.fromRadiantDeg*Math.PI/180,r=fi.turnAround(n,e.between(0,360)),o={x:n.x*Math.cos(s)+r.x*Math.sin(s),y:n.y*Math.cos(s)+r.y*Math.sin(s),z:n.z*Math.cos(s)+r.z*Math.sin(s)};return{...i,radiant:fi.toHorizontal(o),bearingDeg:fi.bearingFrom(o,n)}})}static turnAround(t,e){const[i,n]=fi.basisAround(t),s=e*Math.PI/180;return{x:i.x*Math.cos(s)+n.x*Math.sin(s),y:i.y*Math.cos(s)+n.y*Math.sin(s),z:i.z*Math.cos(s)+n.z*Math.sin(s)}}static bearingFrom(t,e){const[i,n]=fi.basisAround(t),s=t.x*e.x+t.y*e.y+t.z*e.z,r=fi.normalise({x:e.x-t.x*s,y:e.y-t.y*s,z:e.z-t.z*s});return(Math.atan2(r.x*n.x+r.y*n.y+r.z*n.z,r.x*i.x+r.y*i.y+r.z*i.z)*180/Math.PI%360+360)%360}static basisAround(t){const e=Math.abs(t.y)<.9?{x:0,y:1,z:0}:{x:1,y:0,z:0},i=fi.normalise(fi.cross(t,e));return[i,fi.normalise(fi.cross(t,i))]}static toHorizontal(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{altitudeDeg:Math.asin(Math.min(1,Math.max(-1,t.y/e)))*180/Math.PI,azimuthDeg:(Math.atan2(t.x,-t.z)*180/Math.PI%360+360)%360}}static appearanceOf(t){const e=fi.toCartesian(t.radiant??{altitudeDeg:90,azimuthDeg:0}),i=fi.turnAround(e,t.bearingDeg),n=t.fromRadiantDeg*Math.PI/180;return fi.toHorizontal({x:e.x*Math.cos(n)+i.x*Math.sin(n),y:e.y*Math.cos(n)+i.y*Math.sin(n),z:e.z*Math.cos(n)+i.z*Math.sin(n)})}static toCartesian(t){const e=t.altitudeDeg*Math.PI/180,i=t.azimuthDeg*Math.PI/180,n=Math.cos(e);return{x:n*Math.sin(i),y:Math.sin(e),z:-n*Math.cos(i)}}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static normalise(t){const e=Math.hypot(t.x,t.y,t.z)||1;return{x:t.x/e,y:t.y/e,z:t.z/e}}static TYPICAL_VELOCITY_KM_S=40}const $v="https://ufoathome.org/tle/index.json";class qi{static MAX_ELEMENT_AGE_DAYS=7;static DAY_MS=864e5;fetchImpl;indexUrls;index;files=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??qi.defaultIndexUrls()}static defaultIndexUrls(){const t=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&t.push(new URL("/tle/index.json",location.href).href),t.includes($v)||t.push($v),t}static FIRST_SNAPSHOT="2021-02-22";async covers(t){const e=Date.parse(`${qi.FIRST_SNAPSHOT}T00:00:00Z`)-qi.MAX_ELEMENT_AGE_DAYS*qi.DAY_MS;if(t.getTime()<e)return!1;const i=await this.loadIndex();return i?Object.values(i.index.kinds).some(n=>t.getTime()>=Date.parse(n.from)-qi.MAX_ELEMENT_AGE_DAYS*qi.DAY_MS&&t.getTime()<=Date.parse(n.to)+qi.MAX_ELEMENT_AGE_DAYS*qi.DAY_MS):!1}async at(t){const e=await this.loadIndex();if(!e)return;const{index:i,base:n}=e,s=[],r=[];for(const o of Object.keys(i.kinds)){const c=await this.kindAt(o,t,i,n);s.push(...c),r.push(this.coverageOf(o,t,i,c.length>0))}return{objects:s,coverage:r,credit:i.credit,creditUrl:i.source}}async kindAt(t,e,i,n){const s=e.getTime(),r=i.binDays*qi.DAY_MS,o=Math.floor(s/r),c=s-o*r<r/2?o-1:o+1,l=new Set(i.kinds[t].bins),h=[o,c].map(v=>new Date(v*r).toISOString().slice(0,10)).filter(v=>l.has(v));if(h.length===0)return[];const[u,...d]=await Promise.all([this.json(new URL(`objects-${t}.json`,n).href),...h.map(v=>this.binary(new URL(`${t}/${v}.bin`,n).href))]),f=new Map;for(const v of d)for(const m of qi.decode(v,i.recordBytes)){const g=f.get(m.norad);(!g||Math.abs(m.epochMs-s)<Math.abs(g.epochMs-s))&&f.set(m.norad,m)}const p=[];for(const v of f.values()){const m=Math.abs(v.epochMs-s)/qi.DAY_MS;if(m>qi.MAX_ELEMENT_AGE_DAYS)continue;const g=u[v.norad]??{name:String(v.norad)};g.launch&&Date.parse(`${g.launch}T00:00:00Z`)>s||p.push({norad:v.norad,name:g.name,kind:t,launch:g.launch,stdMag:g.stdMag,elements:v,ageDays:m})}return p}coverageOf(t,e,i,n){const{from:s,to:r}=i.kinds[t],o=e.getTime(),c=qi.MAX_ELEMENT_AGE_DAYS*qi.DAY_MS,l=n?"covered":o<Date.parse(s)-c?"before":o>Date.parse(r)+c?"after":"gap";return{kind:t,status:l,from:s,to:r}}static decode(t,e){const i=new DataView(t),n=[];for(let s=0;s+e<=t.byteLength;s+=e)n.push({norad:i.getUint32(s,!0),epochMs:i.getFloat64(s+4,!0),bstar:i.getFloat32(s+12,!0),inclinationDeg:i.getFloat32(s+16,!0),raanDeg:i.getFloat32(s+20,!0),eccentricity:i.getFloat32(s+24,!0),argOfPerigeeDeg:i.getFloat32(s+28,!0),meanAnomalyDeg:i.getFloat32(s+32,!0),meanMotion:i.getFloat64(s+36,!0)});return n}loadIndex(){return this.index??=(async()=>{for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(!e.ok)continue;return{index:await e.json(),base:t}}catch{}})(),this.index}json(t){return this.cached(t,async e=>e.json())}binary(t){return this.cached(t,async e=>e.arrayBuffer())}cached(t,e){let i=this.files.get(t);return i||(i=this.fetchImpl(t).then(n=>{if(!n.ok)throw new Error(`${t}: ${n.status}`);return e(n)}),i.catch(()=>this.files.delete(t)),this.files.set(t,i)),i}}class kD{lowerM;upperM;add(t,e){if(!(t<=0)){if(e.behindM!==void 0){const i=Fe.sizeMAt(e.behindM,t);this.lowerM=this.lowerM===void 0?i:Math.max(this.lowerM,i)}if(e.inFrontM!==void 0){const i=Fe.sizeMAt(e.inFrontM,t);this.upperM=this.upperM===void 0?i:Math.min(this.upperM,i)}}}get sizeRange(){return{minM:this.lowerM,maxM:this.upperM}}get empty(){return this.lowerM===void 0&&this.upperM===void 0}get contradictory(){return this.lowerM!==void 0&&this.upperM!==void 0&&this.lowerM>this.upperM}distanceRangeAt(t){return t<=0?{}:{minM:this.lowerM===void 0?void 0:Fe.distanceMAt(this.lowerM,t),maxM:this.upperM===void 0?void 0:Fe.distanceMAt(this.upperM,t)}}clear(){this.lowerM=void 0,this.upperM=void 0}}class Ua{static DEG_PER_SECOND=360/86164.0905;static degOver(t){return Math.max(0,t)*Ua.DEG_PER_SECOND}static instants(t,e){if(!(e>0))return 1;const i=Ua.degOver(t)/e;return i<1?1:Math.min(Ua.MAX_INSTANTS,Math.max(2,Math.ceil(i)))}static MAX_INSTANTS=64}class an{static EYE={apertureMm:7,exposureSeconds:.1,resolutionArcsec:60};static WAVELENGTH_M=55e-8;static ARCSEC_PER_RADIAN=180*3600/Math.PI;static UNKNOWN_CAMERA_FOCAL_MM=50;static UNKNOWN_CAMERA_DETAIL_UM=20;static get skyDriftArcsecPerSecond(){return Ua.DEG_PER_SECOND*3600}static graspOf(t,e={}){const i=e.exposureSeconds??t.exposureSeconds,n=e.fNumber??t.fNumber;if(i===void 0||n===void 0||!(i>0)||!(n>0))return an.EYE;const s=e.focalLengthMm??t.frame?.focalLengthMm??an.UNKNOWN_CAMERA_FOCAL_MM,r=s/n,o=an.resolutionArcsec(t,s,r);return{apertureMm:r,exposureSeconds:Math.min(i,an.trailLimitedSeconds(o)),resolutionArcsec:o}}static resolutionArcsec(t,e,i){const s=(t.detailUm??an.UNKNOWN_CAMERA_DETAIL_UM)/1e3/e*an.ARCSEC_PER_RADIAN,r=1.22*an.WAVELENGTH_M/(i/1e3)*an.ARCSEC_PER_RADIAN;return Math.max(s,r)}static trailLimitedSeconds(t){return t/an.skyDriftArcsecPerSecond}static gainOverEye(t,e={}){const i=an.graspOf(t,e),n=an.EYE,s=(i.apertureMm/n.apertureMm)**2,r=i.exposureSeconds/n.exposureSeconds,o=(n.resolutionArcsec/i.resolutionArcsec)**2;return 1.25*Math.log10(s*r*o)}static gainFor(t,e){const i=e.fieldOfViewDeg===void 0?void 0:bi.focalLengthMmFor(t,e.fieldOfViewDeg);return an.gainOverEye(t,{fNumber:e.fNumber,focalLengthMm:i,exposureSeconds:e.exposureSeconds})}}const Kv=111320,Pc=Math.PI/180,FD=1.02,UD=1;class tl{static of(t,e){const i=tl.sightings(t,e);if(i.length<2)return;const n=tl.baseline(i);if(!n)return;const{near:s,far:r,closedM:o}=n,c=Math.tan(r.widthDeg/2*Pc)===0?0:Math.tan(s.widthDeg/2*Pc)/Math.tan(r.widthDeg/2*Pc);if(c<FD)return;const l=o/(c-1),h=Fe.sizeMAt(l,s.widthDeg),u=i.map(d=>({t:d.t,m:Fe.distanceMAt(h,d.widthDeg)}));return{widthM:h,distanceM:u,nearestM:Math.min(...u.map(d=>d.m)),fromT:r.t,toT:s.t,closedM:o}}static sightings(t,e){return t.timeline.allKeyframes.flatMap(i=>{const n=i.shapes.find(o=>o.sourceId===e)?.shape,s=n?.angular?.widthDeg,r=Ze(t,i.t);return s===void 0||s<=0||r?.lat===void 0||r.lng===void 0?[]:[{t:i.t,widthDeg:s,lat:r.lat,lng:r.lng,sightAzimuthDeg:n?.aim?.azimuthDeg??r.headingDeg}]}).sort((i,n)=>i.t-n.t)}static baseline(t){let e;for(const i of t)for(const n of t){if(i.t>=n.t)continue;const s=tl.closedAlongSight(i,n),[r,o,c]=s>=0?[n,i,s]:[i,n,-s];c<UD||r.widthDeg<=o.widthDeg||(!e||c>e.closedM)&&(e={near:r,far:o,closedM:c})}return e}static closedAlongSight(t,e){const i=(e.lat-t.lat)*Kv,n=(e.lng-t.lng)*Kv*Math.cos(t.lat*Pc),s=(t.sightAzimuthDeg??0)*Pc;return i*Math.cos(s)+n*Math.sin(s)}}class sn{static CONVENTIONAL_M=5;static NEAREST_M=.2;static MARGIN=1.1;static resolve(t){if(t.statedM!==void 0&&t.statedM>0)return{distanceM:sn.atLeastNearest(t.statedM),basis:"stated"};if(t.hypothesisM!==void 0&&t.hypothesisM>0)return{distanceM:sn.atLeastNearest(t.hypothesisM),basis:"hypothesis"};if(t.derivedM!==void 0&&t.derivedM>0)return{distanceM:sn.atLeastNearest(t.derivedM),basis:"derived"};const e=sn.largest(t.range?.minM,t.crossing?.behindM),i=sn.smallest(t.range?.maxM,t.crossing?.inFrontM),n=e===void 0?void 0:e*sn.MARGIN,s=i===void 0?void 0:i/sn.MARGIN;return n!==void 0&&s!==void 0?{distanceM:sn.atLeastNearest(n<=s?Math.sqrt(n*s):n),basis:"bounded"}:n!==void 0?{distanceM:sn.atLeastNearest(n),basis:"bounded"}:s!==void 0&&s<sn.CONVENTIONAL_M?{distanceM:sn.atLeastNearest(s),basis:"bounded"}:{distanceM:sn.CONVENTIONAL_M,basis:"conventional"}}static atLeastNearest(t){return Math.max(sn.NEAREST_M,t)}static largest(...t){const e=t.filter(i=>i!==void 0&&i>0);return e.length===0?void 0:Math.max(...e)}static smallest(...t){const e=t.filter(i=>i!==void 0&&i>0);return e.length===0?void 0:Math.min(...e)}}const Bf=Math.PI/180;class ce{constructor(t,e,i){this.body=t,this.ground=e;const n=[...t.track].sort((s,r)=>s.t-r.t);this.keys=this.place(n,i);for(const s of n)ce.collect(this.motionKeys,s.t,s.motions),ce.collect(this.lightKeys,s.t,s.lights)}static EYE_HEIGHT_M=1.6;static MAX_RANGE_M=3e4;static DEFAULT_SIZE={widthM:1,lengthM:1,heightM:1};static DEFAULT_APPEARANCE={color:"#c8c8c8",albedo:.5,luminanceCdM2:0};keys;motionKeys=new Map;lightKeys=new Map;static collect(t,e,i){for(const[n,s]of Object.entries(i??{})){const r=t.get(n)??[];r.push({t:e,value:s}),t.set(n,r)}}motionsAt(t){return ce.channelsAt(this.motionKeys,t,0)}lightsAt(t){return this.lightKeys.size>0?ce.channelsAt(this.lightKeys,t,void 0):void 0}static channelsAt(t,e,i){const n={};for(const[s,r]of t){let o=r.length-1;for(;o>=0&&r[o].t>e;)o--;if(o<0){i!==void 0&&(n[s]=i);continue}const c=r[o],l=r[Math.min(o+1,r.length-1)],h=l===c||l.t===c.t?0:Math.min(1,(e-c.t)/(l.t-c.t));n[s]=ce.lerp(c.value,l.value,h)}return n}static eyeOf(t,e,i){const n=Ze(t,0),s=Ze(t,e),o=n?.lat!==void 0&&n.lng!==void 0&&s?.lat!==void 0&&s.lng!==void 0?si(s.lat,s.lng,n.lat,n.lng):void 0,c=o?o.x:0,l=o?-o.z:0;return{eastM:c,northM:l,upM:i.heightAt(c,l)+ce.EYE_HEIGHT_M+(s?.elevationM??0),headingDeg:s?.headingDeg}}static lineOfSightMeetsGround(t,e,i,n){const s=ce.directionOf(e,i),r=l=>t.upM+s.upM*l-n.heightAt(t.eastM+s.eastM*l,t.northM+s.northM*l);let o=0,c=0;for(;c<ce.MAX_RANGE_M;){if(c=o+Math.max(.5,o*.01),r(c)<=0){for(let l=0;l<30;l++){const h=(o+c)/2;r(h)<=0?c=h:o=h}return c}o=c}}static directionOf(t,e){const i=t*Bf,n=e*Bf;return{eastM:Math.sin(i)*Math.cos(n),northM:Math.cos(i)*Math.cos(n),upM:Math.sin(n)}}at(t){const e=this.keys;if(e.length===0||t<e[0].t)return;let i=e.length-1;for(;i>0&&e[i].t>t;)i--;const n=e[i];if(!n.present)return;const s=e[Math.min(i+1,e.length-1)],r=s===n||s.t===n.t?0:Math.min(1,(t-n.t)/(s.t-n.t)),o=ce.lerp(n.eastM,s.eastM,r),c=ce.lerp(n.northM,s.northM,r),l={widthM:ce.lerp(n.sizeM.widthM,s.sizeM.widthM,r),lengthM:ce.lerp(n.sizeM.lengthM,s.sizeM.lengthM,r),heightM:ce.lerp(n.sizeM.heightM,s.sizeM.heightM,r)},h={headingDeg:ce.lerpAngle(n.attitude.headingDeg,s.attitude.headingDeg,r),pitchDeg:ce.lerp(n.attitude.pitchDeg,s.attitude.pitchDeg,r),rollDeg:ce.lerp(n.attitude.rollDeg,s.attitude.rollDeg,r)};let u;if("aboveGroundM"in n.vertical&&"aboveGroundM"in s.vertical){const d=ce.lerp(n.vertical.aboveGroundM,s.vertical.aboveGroundM,r);u=this.groundUnderFootprint(o,c,l,h.headingDeg)+d+l.heightM/2}else u=ce.lerp(this.centreUpOf(n),this.centreUpOf(s),r);return{id:this.body.id,model:this.body.model,explains:this.body.explains??[],outlineNode:this.body.outlineNode,eastM:o,northM:c,upM:u,sizeM:l,attitude:h,appearance:{color:(r<1?n:s).appearance.color,albedo:ce.lerp(n.appearance.albedo,s.appearance.albedo,r),luminanceCdM2:ce.lerp(n.appearance.luminanceCdM2,s.appearance.luminanceCdM2,r)},flame:ce.flameBetween(n.flame,s.flame,r),motions:this.motionsAt(t),lights:this.lightsAt(t),throwsFlame:this.body.track.some(d=>d.flame!==void 0&&d.flame.luminanceCdM2>0)}}static flameBetween(t,e,i){if(!t||t.luminanceCdM2<=0)return i>=1&&e&&e.luminanceCdM2>0?e:void 0;const n=t,s=e??t,r={...i<1?n:s,lengthM:ce.lerp(n.lengthM,s.lengthM,i),widthM:ce.lerp(n.widthM,s.widthM,i),luminanceCdM2:ce.lerp(n.luminanceCdM2,s.luminanceCdM2,i)};return r.luminanceCdM2>0?r:void 0}centreUpOf(t){return"upM"in t.vertical?t.vertical.upM:this.groundUnderFootprint(t.eastM,t.northM,t.sizeM,t.attitude.headingDeg)+t.vertical.aboveGroundM+t.sizeM.heightM/2}groundUnderFootprint(t,e,i,n){const s=n*Bf,r={eastM:Math.cos(s),northM:-Math.sin(s)},o={eastM:Math.sin(s),northM:Math.cos(s)};let c=this.ground.heightAt(t,e);for(const[l,h]of[[-1,-1],[1,-1],[-1,1],[1,1]]){const u=l*i.widthM/2,d=h*i.lengthM/2;c=Math.max(c,this.ground.heightAt(t+r.eastM*u+o.eastM*d,e+r.northM*u+o.northM*d))}return c}place(t,e){const i=[];let n;for(const s of t){const r=s.sizeM??n?.sizeM??ce.DEFAULT_SIZE,o={headingDeg:s.attitude?.headingDeg??n?.attitude.headingDeg??0,pitchDeg:s.attitude?.pitchDeg??n?.attitude.pitchDeg??0,rollDeg:s.attitude?.rollDeg??n?.attitude.rollDeg??0},c={color:s.appearance?.color??n?.appearance.color??ce.DEFAULT_APPEARANCE.color,albedo:s.appearance?.albedo??n?.appearance.albedo??ce.DEFAULT_APPEARANCE.albedo,luminanceCdM2:s.appearance?.luminanceCdM2??n?.appearance.luminanceCdM2??ce.DEFAULT_APPEARANCE.luminanceCdM2},l=this.positionOf(s,r,e)??(n&&{eastM:n.eastM,northM:n.northM,vertical:this.verticalOf(s,r)??n.vertical});if(!l)continue;const h=s.flame??n?.flame,u=s.present??n?.present??!0;n={t:s.t,...l,sizeM:r,attitude:o,appearance:c,flame:h,present:u},i.push(n)}return i}verticalOf(t,e){if(t.onGround)return{aboveGroundM:0};if(t.altitudeAboveGroundM!==void 0)return{aboveGroundM:t.altitudeAboveGroundM};if(t.altitudeM!==void 0)return{upM:t.altitudeM+e.heightM/2}}positionOf(t,e,i){if(t.eastM!==void 0&&t.northM!==void 0)return{eastM:t.eastM,northM:t.northM,vertical:this.verticalOf(t,e)??{aboveGroundM:0}};if(t.azimuthDeg===void 0||t.altitudeDeg===void 0)return;const n=i(t.t);if(!n)return;const s=t.distanceM??(t.onGround?ce.lineOfSightMeetsGround(n,t.azimuthDeg,t.altitudeDeg,this.ground):void 0);if(s===void 0)return;const r=ce.directionOf(t.azimuthDeg,t.altitudeDeg),o=n.eastM+r.eastM*s,c=n.northM+r.northM*s;return{eastM:o,northM:c,vertical:this.verticalOf(t,e)??{upM:n.upM+r.upM*s}}}static lerp(t,e,i){return t+(e-t)*i}static lerpAngle(t,e,i){const n=((e-t)%360+540)%360-180;return((t+n*i)%360+360)%360}}class be{static A=6378137;static E2=.00669437999014;static DEG=Math.PI/180;static STANDARD_DISTANCE_KM=100;static DEFAULT_COLOR="#ffb347";static DEFAULT_TRAIN_S=1.5;static FADE_MS=600;static TRAIN_POINTS=8;static leadAt(t,e){const i=t.track;if(i.length<2||e<i[0].t||e>i[i.length-1].t)return;let n=0;for(;n<i.length-2&&i[n+1].t<e;)n++;const s=i[n],r=i[n+1],o=r.t-s.t,c=o>0?(e-s.t)/o:0,[l,h]=be.alongGreatCircle(s,r,c);return{lat:l,lng:h,heightM:(s.altitudeKm+(r.altitudeKm-s.altitudeKm)*c)*1e3}}static viewsAt(t,e,i){const n=[];for(const s of t){const r=s.track[0]?.t??0,o=s.track[s.track.length-1]?.t??0;s.fragments.forEach((c,l)=>{const h=c.fromT??r,u=c.untilT??o;if(e<h||e>u)return;const d=(c.lagS??0)*1e3,f=be.leadAt(s,e-d);if(!f)return;const p=be.seenFrom(i,f);if(p.altitudeDeg<0)return;const v=Math.min(be.FADE_MS,(u-h)/4),m=v>0?Math.min(1,(e-h)/v,(u-e)/v):1,g=-2.5*Math.log10(Math.max(m,.001)),b=c.absoluteMagnitude+5*Math.log10(p.distanceKm/be.STANDARD_DISTANCE_KM)+g,S=[p],M=(c.trainS??be.DEFAULT_TRAIN_S)*1e3;for(let x=1;x<=be.TRAIN_POINTS;x++){const _=Math.min(M*x/be.TRAIN_POINTS,e-h),E=be.leadAt(s,e-d-_);if(!E||(S.push(be.seenFrom(i,E)),_>=e-h))break}n.push({reentryId:s.id,fragmentId:c.id??String(l),head:p,magnitude:b,color:c.color??be.DEFAULT_COLOR,train:S})})}return n}static seenFrom(t,e){const i=be.ecef(t),n=be.ecef(e),s=n[0]-i[0],r=n[1]-i[1],o=n[2]-i[2],c=t.lat*be.DEG,l=t.lng*be.DEG,h=-Math.sin(l)*s+Math.cos(l)*r,u=-Math.sin(c)*Math.cos(l)*s-Math.sin(c)*Math.sin(l)*r+Math.cos(c)*o,d=Math.cos(c)*Math.cos(l)*s+Math.cos(c)*Math.sin(l)*r+Math.sin(c)*o,f=Math.hypot(h,u,d);return{altitudeDeg:Math.asin(d/f)/be.DEG,azimuthDeg:(Math.atan2(h,u)/be.DEG+360)%360,distanceKm:f/1e3}}static ecef(t){const e=t.lat*be.DEG,i=t.lng*be.DEG,n=Math.sin(e),s=be.A/Math.sqrt(1-be.E2*n*n);return[(s+t.heightM)*Math.cos(e)*Math.cos(i),(s+t.heightM)*Math.cos(e)*Math.sin(i),(s*(1-be.E2)+t.heightM)*n]}static alongGreatCircle(t,e,i){const n=h=>{const u=h.lat*be.DEG,d=h.lng*be.DEG;return[Math.cos(u)*Math.cos(d),Math.cos(u)*Math.sin(d),Math.sin(u)]},s=n(t),r=n(e),o=Math.max(-1,Math.min(1,s[0]*r[0]+s[1]*r[1]+s[2]*r[2])),c=Math.acos(o);let l;if(c<1e-12)l=s;else{const h=Math.sin((1-i)*c)/Math.sin(c),u=Math.sin(i*c)/Math.sin(c);l=[s[0]*h+r[0]*u,s[1]*h+r[1]*u,s[2]*h+r[2]*u]}return[Math.atan2(l[2],Math.hypot(l[0],l[1]))/be.DEG,Math.atan2(l[1],l[0])/be.DEG]}}class pm{static FIRST_DAY="2022-01-01";static mayCover(t){return new Date(t).toISOString().slice(0,10)>=pm.FIRST_DAY}}class zD{constructor(t,e,i){this.citation=t,this.covers=e,this.load=i}loading;mayCover(t){return this.covers(t)}async between(t,e,i,n){try{return await(await this.provider()).between(t,e,i,n)}catch{return{status:"failed"}}}async describe(t,e){try{return await(await this.provider()).describe?.(t,e)}catch{return}}provider(){if(!this.loading){const t=this.load();this.loading=t,t.catch(()=>{this.loading===t&&(this.loading=void 0)})}return this.loading}}const BD="Aircraft positions: adsb.lol feeders and contributors, Open Database License 1.0 (https://www.adsb.lol/docs/open-data/historical/)",HD=[{id:"adsb-lol",name:"adsb.lol",credit:"adsb.lol feeders and contributors, ODbL 1.0",creditUrl:"https://www.adsb.lol/docs/open-data/historical/",create:()=>new zD(BD,a=>pm.mayCover(a),async()=>new(await je(async()=>{const{AdsbLolArchiveProvider:a}=await import("./AdsbLolArchiveProvider-BXH71WVn.js");return{AdsbLolArchiveProvider:a}},[],import.meta.url)).AdsbLolArchiveProvider)}];class on{static MAX_GAP_S=60;static FT_TO_M=.3048;static EARTH_RADIUS_KM=6371;static seenFrom(t,e,i){const n=on.positionAt(t,i);if(!n)return;const s=be.seenFrom(e,n.geo);if(!(s.altitudeDeg<0))return{track:t,sky:s,altitudeFt:n.altitudeFt,groundSpeedKt:n.groundSpeedKt,trackDeg:n.trackDeg,angularRateDegPerS:on.angularRate(t,e,i)}}static viewsAt(t,e,i){return t.flatMap(n=>on.seenFrom(n,e,i)??[])}static groundDistanceKm(t,e){const i=Math.PI/180,n=Math.sin((e.lat-t.lat)*i/2)**2+Math.cos(t.lat*i)*Math.cos(e.lat*i)*Math.sin((e.lng-t.lng)*i/2)**2;return 2*on.EARTH_RADIUS_KM*Math.asin(Math.min(1,Math.sqrt(n)))}static wrapLongitude(t){return((t+180)%360+360)%360-180}static positionAt(t,e){const i=t.points;if(i.length===0||e<i[0].t||e>i[i.length-1].t)return;let n=0;for(;n<i.length-1&&i[n+1].t<=e;)n++;const s=i[n],r=i[n+1]??s,o=r.t-s.t;if(o>on.MAX_GAP_S*1e3)return;const c=o>0?(e-s.t)/o:0,l=s.altitudeFt+(r.altitudeFt-s.altitudeFt)*c,h=(r.lng-s.lng+540)%360-180;return{geo:{lat:s.lat+(r.lat-s.lat)*c,lng:on.wrapLongitude(s.lng+h*c),heightM:l*on.FT_TO_M},altitudeFt:l,groundSpeedKt:s.groundSpeedKt,trackDeg:s.trackDeg}}static angularRate(t,e,i){const n=on.positionAt(t,i-500),s=on.positionAt(t,i+500);if(!n||!s)return;const r=on.unit(be.seenFrom(e,n.geo)),o=on.unit(be.seenFrom(e,s.geo)),c=Math.min(1,Math.max(-1,r[0]*o[0]+r[1]*o[1]+r[2]*o[2]));return Math.acos(c)*180/Math.PI}static unit(t){const e=t.altitudeDeg*Math.PI/180,i=t.azimuthDeg*Math.PI/180;return[Math.cos(e)*Math.sin(i),Math.cos(e)*Math.cos(i),Math.sin(e)]}}const Zv="https://ufoathome.org/fireballs/index.json";class Ps{static FIRST_MONTH="2018-12";static STRIKING_MAGNITUDE=-1;static COLOR="#eef2ff";static TRAIN_S=.3;fetchImpl;indexUrls;index;months=new Map;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.indexUrls=t.indexUrls??Ps.defaultIndexUrls()}static defaultIndexUrls(){const t=[];return typeof location<"u"&&/^https?:$/.test(location.protocol)&&t.push(new URL("/fireballs/index.json",location.href).href),t.includes(Zv)||t.push(Zv),t}static mayCover(t){return new Date(t).toISOString().slice(0,7)>=Ps.FIRST_MONTH}async credit(){return(await this.loadIndex())?.index.credit}async between(t,e){if(!Ps.mayCover(e))return;const i=await this.loadIndex();if(!i)return;const n=new Set([new Date(t).toISOString().slice(0,7),new Date(e).toISOString().slice(0,7)]);return[...n].some(r=>r>=i.index.from&&r<=i.index.to)?(await Promise.all([...n].filter(r=>i.index.months.includes(r)).map(r=>this.monthOf(r,i.base)))).flat().filter(r=>r.t>=t&&r.t<=e):void 0}static seenFrom(t,e){const i=Ps.peakFraction(t),n={lat:t.from[0]+(t.to[0]-t.from[0])*i,lng:t.from[1]+(t.to[1]-t.from[1])*i,heightM:t.peakHeightKm*1e3},s=be.seenFrom(e,n);if(!(s.altitudeDeg<0))return{record:t,peak:s,magnitude:t.peakMagnitude+5*Math.log10(s.distanceKm/be.STANDARD_DISTANCE_KM)}}static asReentry(t,e){const i=t.t-e,n=i+Math.max(t.durationS,.1)*1e3;return{id:`gmn-${t.id}`,track:[{t:i,lat:t.from[0],lng:t.from[1],altitudeKm:t.from[2]},{t:n,lat:t.to[0],lng:t.to[1],altitudeKm:t.to[2]}],fragments:[{absoluteMagnitude:t.peakMagnitude,color:Ps.COLOR,trainS:Ps.TRAIN_S}]}}static peakFraction(t){const e=t.from[2]-t.to[2];return Math.abs(e)<1e-6?.5:Math.min(1,Math.max(0,(t.from[2]-t.peakHeightKm)/e))}loadIndex(){return this.index??=(async()=>{for(const t of this.indexUrls)try{const e=await this.fetchImpl(t);if(e.ok)return{index:await e.json(),base:t}}catch{}})(),this.index}monthOf(t,e){let i=this.months.get(t);return i||(i=this.fetchImpl(new URL(`${t}.json`,e).href).then(n=>n.ok?n.json():[]).catch(()=>[]),this.months.set(t,i)),i}}const _o=Math.PI/180,Oc=180/Math.PI;class di{constructor(t){this.timeline=t}static DIRECTION_TOLERANCE_DEG=1;static SIZE_TOLERANCE=1.5;static RINGS=12;static SEGMENTS=24;at(t,e,i,n){const s=[];for(const r of e){const o=di.projectionOf(r,i,n?.(r));if(o)for(const c of r.explains){const l=this.timeline.getInterpolatedShapeAt(t,c);!l||l.transparency>=1||s.push({...di.compare(c,r.id,{aim:l.aim,angular:l.angular},o),title:l.title})}}return s}static compare(t,e,i,n){const s=[],r=i.aim?di.separationDeg(i.aim,n.aim):void 0;if(r!==void 0){const l=Math.max(i.angular?.widthDeg??0,n.angular.widthDeg)/2;r>Math.max(di.DIRECTION_TOLERANCE_DEG,l)&&s.push("direction")}const o=i.angular&&i.angular.widthDeg>0?n.angular.widthDeg/i.angular.widthDeg:void 0,c=i.angular&&i.angular.heightDeg>0?n.angular.heightDeg/i.angular.heightDeg:void 0;return o!==void 0&&!di.withinSize(o)&&s.push("width"),c!==void 0&&!di.withinSize(c)&&s.push("height"),{sourceId:t,bodyId:e,stated:i,predicted:n,separationDeg:r,widthRatio:o,heightRatio:c,disagreements:s}}static projectionOf(t,e,i){const n=i&&i.length>0?i:di.outlineOf(t),s=i&&i.length>0?di.centreOf(i):t,r=di.normalized({eastM:s.eastM-e.eastM,northM:s.northM-e.northM,upM:s.upM-e.upM});if(!r)return;const o=di.normalized({eastM:r.northM,northM:-r.eastM,upM:0})??{eastM:1,northM:0,upM:0},c=di.cross(o,r);let l=1/0,h=-1/0,u=1/0,d=-1/0;for(const f of n){const p={eastM:f.eastM-e.eastM,northM:f.northM-e.northM,upM:f.upM-e.upM},v=di.dot(p,r);if(v<=0)return;const m=Math.atan2(di.dot(p,o),v),g=Math.atan2(di.dot(p,c),v);l=Math.min(l,m),h=Math.max(h,m),u=Math.min(u,g),d=Math.max(d,g)}return{aim:{azimuthDeg:(Math.atan2(r.eastM,r.northM)*Oc+360)%360,altitudeDeg:Math.asin(Math.max(-1,Math.min(1,r.upM)))*Oc},angular:{widthDeg:(h-l)*Oc,heightDeg:(d-u)*Oc}}}static centreOf(t){const e=i=>(Math.min(...t.map(n=>n[i]))+Math.max(...t.map(n=>n[i])))/2;return{eastM:e("eastM"),northM:e("northM"),upM:e("upM")}}static separationDeg(t,e){const i=t.altitudeDeg*_o,n=e.altitudeDeg*_o,s=Math.sin(i)*Math.sin(n)+Math.cos(i)*Math.cos(n)*Math.cos((t.azimuthDeg-e.azimuthDeg)*_o);return Math.acos(Math.max(-1,Math.min(1,s)))*Oc}static withinSize(t){return t<=di.SIZE_TOLERANCE&&t>=1/di.SIZE_TOLERANCE}static outlineOf(t){const e=t.sizeM.widthM/2,i=t.sizeM.lengthM/2,n=t.sizeM.heightM/2,s=[],r=t.model.url===void 0?t.model.id:void 0;if(r!==void 0&&r!=="box"&&sy.includes(r))for(let u=0;u<=di.RINGS;u++){const d=u/di.RINGS*Math.PI;for(let f=0;f<di.SEGMENTS;f++){const p=f/di.SEGMENTS*2*Math.PI;s.push([e*Math.sin(d)*Math.cos(p),i*Math.sin(d)*Math.sin(p),n*Math.cos(d)])}}else for(const u of[-e,e])for(const d of[-i,i])for(const f of[-n,n])s.push([u,d,f]);const c=t.attitude.headingDeg*_o,l=t.attitude.pitchDeg*_o,h=t.attitude.rollDeg*_o;return s.map(([u,d,f])=>{const p=u*Math.cos(h)+f*Math.sin(h),v=-u*Math.sin(h)+f*Math.cos(h),m=d*Math.cos(l)-v*Math.sin(l),g=d*Math.sin(l)+v*Math.cos(l);return{eastM:t.eastM+p*Math.cos(c)+m*Math.sin(c),northM:t.northM-p*Math.sin(c)+m*Math.cos(c),upM:t.upM+g}})}static dot(t,e){return t.eastM*e.eastM+t.northM*e.northM+t.upM*e.upM}static cross(t,e){return{eastM:t.northM*e.upM-t.upM*e.northM,northM:t.upM*e.eastM-t.eastM*e.upM,upM:t.eastM*e.northM-t.northM*e.eastM}}static normalized(t){const e=Math.hypot(t.eastM,t.northM,t.upM);return e>1e-9?{eastM:t.eastM/e,northM:t.northM/e,upM:t.upM/e}:void 0}}PM();const GD={sun:"Sun",moon:"Moon",Venus:"Venus",Mars:"Mars",Jupiter:"Jupiter",Saturn:"Saturn"},VD="{name} — mag {mag}, {alt}° above the horizon",WD="{name} — satellite, mag {mag}, {height} km up",XD="satellites-change",YD="fireballs-change",qD="aircraft-change",ly="rr0-confrontation",$D="{name} — mag {mag}, {alt}° below the horizontal",Hf="Credits",Jv="comet:",jv="nova:",Qv={building:"Building",tree:"Tree",shrub:"Shrub",bridge:"Bridge",wire:"Overhead line",crop:"Crop row",terrace:"Terrace (restanque)",mound:"Stone heap",streetlight:"Streetlight",vehicle:"Vehicle",observer:"Observer",aircraft:"Aircraft",entity:"Being"},KD=new URL(""+new URL("lunar-relief.bin-ByThqxUn.gz",import.meta.url).href,import.meta.url).href,ZD=new URL(""+new URL("stars-mag7.5-B43R6Wvg.bin",import.meta.url).href,import.meta.url).href,JD=new URL(""+new URL("stars-mag7.5-9-BLV2tFmZ.bin",import.meta.url).href,import.meta.url).href,jD=-18,QD={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Lh={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class $e extends HTMLElement{creditsButton;set ownCredits(t){this.creditsButton.hidden=!t}static get observedAttributes(){return["src","star-catalog-src","deep-star-catalog-src","show-compass","max-pixel-ratio",ks,Fs]}shadow;stageElement;frameElement;sceneCanvas;loaderNote;loaderNotVideo;ufoElement;sceneRenderer;hoverTooltip;resizeObserver;sizeEstimates=new Map;sizeEstimatesFor;distanceHypotheses=new Map;depths=new Map;directionScratch=new R;meteorScheduleFor;lightningScheduleFor;lightningFlashes=[];lastLightningT;lastTimeMs=0;interpretationShown;confrontationReadings=[];confrontationSignature="";comparing=!1;inTheRound=!0;lastSkyKey;starCatalog;starCatalogRequest=0;static tleArchive=new qi;satellitesFor;satelliteRequest=0;satelliteStatus="none";satellites;satellitePassesMemo;static fireballArchive=new Ps;fireballs;static aircraftProviders=new Map;static SOUND_LOOKBACK_MS=3e5;static NO_CONTRAILS=[];static upperAirProviders=new Map;static NO_PRESENCE=new Map;aircraftSource=HD[0];static trafficRuntimeLoading;static trafficRuntime;static loadTrafficRuntime(){return $e.trafficRuntimeLoading??=je(()=>import("./trafficRuntime-BhspObgN.js"),__vite__mapDeps([2,1]),import.meta.url).then(t=>$e.trafficRuntime=t),$e.trafficRuntimeLoading.catch(()=>{$e.trafficRuntimeLoading=void 0}),$e.trafficRuntimeLoading}traffic;lastSun;decorMemo;seatedMemo;starCatalogDepth=0;weatherAudio=new OD;vehicleAudio=new Wx;aircraftAudio;vehicleHearing=new xu;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=t=>{this.sceneRenderer.setCompassHovered(!0);const e=this.ufoElement.canvasElement,i=e.getBoundingClientRect();if(i.width===0||i.height===0)return;const n=(t.clientX-i.left)/i.width*e.width,s=(t.clientY-i.top)/i.height*e.height;if(this.ufoElement.hasVisibleShapeAt(n,s)){this.hoverTooltip.hidden=!0;return}const r=(t.clientX-i.left)/i.width*2-1,o=-((t.clientY-i.top)/i.height*2-1),c=this.naming,l=c.names,h=this.sceneRenderer.pickBodyAt(r,o);if(h){this.showHoverTooltip(t,this.bodyName(h));return}const u=this.interpretationShown?this.sceneRenderer.pickInterpretationBodyAt(r,o):void 0,d=u?this.interpretationShown?.bodies.find(S=>S.id===u):void 0,f=d?this.said.read(d.title)||(d.model.id==="figure"?c.decorKind("entity",Qv.entity):void 0):void 0;if(f){this.showHoverTooltip(t,f);return}const p=this.sceneRenderer.pickDecorAt(r,o),v=p?this.ufoElement.sighting.decor.find(S=>S.id===p):void 0;if(v){this.showHoverTooltip(t,this.said.read(v.title)||c.decorKind(v.kind,Qv[v.kind]));return}const m=this.trafficTooltipAt(r,o);if(m){this.showHoverTooltip(t,m);return}const g=this.sceneRenderer.pickSatelliteAt(r,o);if(g){this.showHoverTooltip(t,(l?.satelliteTooltip??WD).replace("{name}",g.name).replace("{mag}",g.magnitude.toLocaleString(void 0,{maximumFractionDigits:1})).replace("{height}",Math.round(g.heightKm).toLocaleString()));return}const b=this.sceneRenderer.pickStarAt(r,o);if(b){const S=b.star.mag,M=b.altitudeDeg,x=M<0?l?.starTooltipBelow??$D:l?.starTooltip??VD;this.showHoverTooltip(t,x.replace("{name}",c.star(b.star)).replace("{mag}",S.toLocaleString(void 0,{maximumFractionDigits:Math.abs(S)<1?2:1})).replace("{alt}",String(Math.round(Math.abs(M)))));return}this.hoverTooltip.hidden=!0};bodyName(t){const e=t.startsWith(Jv)?t.slice(Jv.length):void 0,i=e?cy.find(r=>r.id===e):void 0;if(i)return this.naming.comet(i);const n=t.startsWith(jv)?qv.byId(t.slice(jv.length)):void 0;if(n)return this.naming.nova(n);const s=GD[t];return s===void 0?t:this.naming.body(t,s)}get naming(){return this.sceneNaming}sceneNaming=new Xu;namesLanguage="en";async loadSceneNames(){const t=Ep(Gr.preferencesFor(this),Ap);if(t===this.namesLanguage)return;this.namesLanguage=t;const e=await bM(t);t===this.namesLanguage&&this.applySceneNaming(new Xu(e))}renderLoaderText(t,e){let i=0;const n=(s,r)=>{s.setAttribute("aria-label",r),s.replaceChildren(),r.split(" ").forEach((o,c)=>{c>0&&s.append(" ");const l=document.createElement("span");l.className="scene-loader-word",l.setAttribute("aria-hidden","true");for(const h of o){const u=document.createElement("span");u.className="scene-loader-letter",u.style.setProperty("--i",String(i++)),u.textContent=h,l.append(u)}s.append(l),i++})};n(this.loaderNotVideo,t),i+=6,n(this.loaderNote,e)}applySceneNaming(t){this.sceneNaming=t;const e=t.names?.credits??Hf;this.creditsButton.title=e,this.creditsButton.setAttribute("aria-label",e),t.names&&this.renderLoaderText(t.names.notAVideo,t.names.isASimulation),this.sceneRenderer.setCompassPoints(t.names?.compassPoints)}showHoverTooltip(t,e){this.hoverTooltip.textContent=e,this.hoverTooltip.hidden=!1;const i=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${t.clientX-i.left+12}px`,this.hoverTooltip.style.top=`${t.clientY-i.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash(t){clearTimeout(this.thunderTimeoutId),this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),Ci.thunderDelayMs(t))}handleFirstInteraction=()=>{this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume(),!this.interacted&&(this.interacted=!0,this.setWeather(Dl(this.ufoElement.sighting,this.lastTimeMs)))};interacted=!1;applyLevel(){const t=this.ufoElement.level;this.weatherAudio.setLevel(t),this.vehicleAudio.setLevel(t),this.aircraftAudio?.setLevel(t)}handlePageGesture=()=>{this.ufoElement.playbackState==="playing"&&this.handleFirstInteraction()};unlockIfAlreadyActivated(){this.interacted||navigator.userActivation?.hasBeenActive&&this.handleFirstInteraction()}static GESTURES=["pointerdown","pointerup","touchend","click","keydown"];handleTimeUpdate=t=>{this.lastTimeMs=t.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.ufoElement.playbackState==="playing"&&this.sceneRenderer.frame(performance.now())};syncAnimationsToPlayback(){const t=this.ufoElement.playbackState==="playing";this.sceneRenderer.setAnimationsRunning(t,t),this.weatherAudio.setPaused(!t),this.vehicleAudio.setPaused(!t),this.aircraftAudio?.setPaused(!t),t&&this.unlockIfAlreadyActivated(),t||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=`<style>${qx}</style>${Yx}`,this.shadow.appendChild(t.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.frameElement=this.shadow.getElementById("frame"),this.sceneCanvas=this.shadow.getElementById("scene-canvas"),this.sceneRenderer=new le(this.sceneCanvas);const e=this.shadow.getElementById("scene-loader");this.loaderNote=this.shadow.getElementById("scene-loader-note"),this.loaderNotVideo=this.shadow.getElementById("scene-loader-not-video"),this.renderLoaderText("This is not a video","It is a real-time simulation."),this.sceneRenderer.onFirstFrameHold=s=>{e.hidden=!s,this.ufoElement.captionHeld=s,this.ufoElement.holdClock(s)},this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Kf),this.ufoElement.classList.add("ufo-overlay"),this.ufoElement.paintsShapes=!1,this.forwardPlayerAttributes(),this.ufoElement.addEventListener("lookat",s=>this.lookToward(s.detail)),this.ufoElement.style.setProperty("--ufo-canvas-background","transparent"),this.ufoElement.style.setProperty("--ufo-canvas-border","none"),this.ufoElement.fullscreenTarget=this.stageElement,this.shadow.getElementById("ufo-slot").replaceWith(this.ufoElement),this.ufoElement.creditShownExternally=!0,this.creditsButton=this.shadow.getElementById("credits-button");const i=this.shadow.getElementById("credits-panel"),n=this.shadow.getElementById("credits-list");i.addEventListener("beforetoggle",s=>{s.newState==="open"&&rn.fill(n,this)}),this.creditsButton.title=Hf,this.creditsButton.setAttribute("aria-label",Hf),this.sceneRenderer.onMapSubjectBounds=s=>this.ufoElement.setMapSubjectBounds(s),this.ufoElement.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.seekPreviewPainter=(s,r)=>this.seekPreviewOf(r).paint(s,r),this.ufoElement.addEventListener("mutedchange",()=>this.applyLevel()),this.ufoElement.ambientSound=s=>s.vehicle!==void 0||s.decor.some(r=>r.engine!==void 0)||s.weatherTrack.allKeyframes.some(r=>r.weather.precipitationType!=="none"||r.weather.windSpeed>1),this.ufoElement.addEventListener("referenceview",s=>this.applyReferenceView(s.detail)),this.ufoElement.addEventListener("traceview",s=>this.sceneRenderer.setTracesShown(s.detail.shown)),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave);for(const s of $e.GESTURES)this.addEventListener(s,this.handleFirstInteraction,!0)}get said(){return this.saidTexts??=new Yn(Gr.preferencesFor(this))}saidTexts;traceLabelsFor;traceLabels(t){const e=Gr.preferencesFor(this).join();if(this.traceLabelsFor?.traces!==t||this.traceLabelsFor.language!==e){const i=new Map;for(const n of t){const s=this.said.read(n.title);s&&i.set(n.id,s)}this.traceLabelsFor={traces:t,language:e,labels:i}}return this.traceLabelsFor.labels}connectedCallback(){this.saidTexts=void 0,this.loadSceneNames(),this.sceneRenderer.restoreContext(),this.resizeToStage(),this.updateAstronomy(this.lastTimeMs),this.loadStars(),this.resizeObserver=new ResizeObserver(()=>this.resizeToStage()),this.resizeObserver.observe(this.frameElement),this.watchVisibility(),document.addEventListener("fullscreenchange",this.handleFullscreenChange);for(const e of $e.GESTURES)document.addEventListener(e,this.handlePageGesture,!0);const t=this.getAttribute("src");t&&this.loadFromSrc(t)}watchVisibility(){this.visibilityObserver?.disconnect(),!(typeof IntersectionObserver>"u")&&(this.visibilityObserver=new IntersectionObserver(t=>{if(t[t.length-1].isIntersecting){this.sceneRenderer.resume();return}this.ufoElement.pause(),this.sceneRenderer.suspend()},{rootMargin:"100px"}),this.visibilityObserver.observe(this))}visibilityObserver;disconnectedCallback(){this.visibilityObserver?.disconnect(),this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange);for(const t of $e.GESTURES)document.removeEventListener(t,this.handlePageGesture,!0);this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose(),this.vehicleAudio.dispose(),this.aircraftAudio?.dispose(),this.seekPreview?.dispose(),this.seekPreview=void 0,queueMicrotask(()=>{this.isConnected||this.sceneRenderer.releaseContext()})}attributeChangedCallback(t,e,i){if(t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),(t==="star-catalog-src"||t==="deep-star-catalog-src")&&i!==e&&this.isConnected&&this.loadStars(),t==="show-compass"&&i!==e&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),t==="max-pixel-ratio"&&i!==e){const n=Number(i);this.sceneRenderer.setMaxPixelRatio(Number.isFinite(n)&&n>0?n:Math.min(window.devicePixelRatio||1,2))}(t===ks||t===Fs)&&i!==e&&this.forwardPlayerAttributes()}forwardPlayerAttributes(){for(const t of[ks,Fs]){const e=this.getAttribute(t);e===null?this.ufoElement.removeAttribute(t):this.ufoElement.setAttribute(t,e)}}setCompassForced(t){this.sceneRenderer.setCompassForced(t)}lookToward(t){const e=Ze(this.ufoElement.sighting,this.lastTimeMs);if(t.kind==="observer"||e?.lat===void 0||e.lng===void 0||e.headingDeg===void 0){this.setLookOffset(0,0);return}const{x:i,z:n}=si(t.lat,t.lng,e.lat,e.lng);if(Math.hypot(i,n)<1)return this.setLookOffset(0,0);const s=(Math.atan2(i,-n)*180/Math.PI+360)%360;this.setLookOffset(((s-e.headingDeg)%360+540)%360-180,-e.pitchDeg)}setLookOffset(t,e){this.sceneRenderer.setLookOffset(t,e),this.ufoElement.setLookOffset(t,e),this.updateAstronomy(this.lastTimeMs)}setIndoorLook(t,e){this.sceneRenderer.setIndoorLook(t,e)}setCloudRendering(t){this.sceneRenderer.setCloudRendering(t)}setWeather(t){this.sceneRenderer.setWeather(t),this.weatherAudio.setAmbient(t.precipitationType,t.precipitationIntensity*(t.precipitationAmount??1),t.windSpeed)}pickCloudAt(t,e){return this.sceneRenderer.pickCloudAt(t,e)}cloudDirectionAt(t,e){return this.sceneRenderer.cloudDirectionAt(t,e)}pickDecorAt(t,e){return this.sceneRenderer.pickDecorAt(t,e)}decorScreenBox(t){return this.sceneRenderer.decorScreenBox(t)}decorGroundPointAt(t,e,i,n=0){return this.sceneRenderer.decorGroundPointAt(t,e,i,n)}decorMetresPerNdcY(t){return this.sceneRenderer.decorMetresPerNdcY(t)}decorGrabHeightAt(t,e,i){return this.sceneRenderer.decorGrabHeightAt(t,e,i)}bodyScreenBox(t){return this.sceneRenderer.bodyScreenBox(t)}pickPlacedBodyAt(t,e){return this.sceneRenderer.pickPlacedBodyAt(t,e)}resumeWeatherAudio(){this.weatherAudio.resume(),this.vehicleAudio.resume(),this.aircraftAudio?.resume()}async loadFromSrc(t){const e=Gc.json(t);this.holdForNewScene(e);const i=await e;this.documentUrl=new URL(t,location.href).href,this.sightingData=i}holdForNewScene(t){this.sceneRenderer.holdForNewScene(t)}get documentUrl(){return this.sceneRenderer.documentUrl}set documentUrl(t){this.sceneRenderer.documentUrl=t}get sightingData(){return this.ufoElement.sightingData}set sightingData(t){this.ufoElement.sightingData=t,this.seekPreview?.recordingChanged(t),this.interpretationShown=this.inTheRound?this.ufoElement.sighting.interpretation:void 0,this.syncAccountHidden(),this.applyFrameFormat(),this.lastTimeMs=0,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(0)}seekPreview;seekPreviewOf(t){const e=this.sceneCanvas.width>0&&this.sceneCanvas.height>0?this.sceneCanvas.width/this.sceneCanvas.height:1.7777777777777777,i=Math.round(t.width/e);return t.height!==i&&(t.height=i),this.seekPreview??=new Wu(this,()=>document.createElement(qu))}showAt(t){this.ufoElement.currentTime=t,this.framesAtAsk=this.sceneRenderer.framesDrawn}framesAtAsk=0;snapshotTo(t){if(this.sceneRenderer.frame(performance.now()),this.sceneRenderer.framesDrawn===this.framesAtAsk)return!1;const e=t.getContext("2d");return e?(e.drawImage(this.sceneCanvas,0,0,t.width,t.height),!0):!1}referenceAspect(t){return this.sceneRenderer.referenceAspect(t)}screenPointOf(t){return this.sceneRenderer.screenPointOf(t)}directionAt(t,e){return this.sceneRenderer.directionAt(t,e)}referenceFailedToLoad(t){return this.sceneRenderer.referenceFailedToLoad(t)}applyReferenceView(t){this.sceneRenderer.setReferencesShown(t.shown);for(const e of this.ufoElement.sighting.references){const i=t.views?.[e.id];this.sceneRenderer.setReferenceView(e.id,{opacity:i?i.shown?i.opacity:0:t.opacity})}}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}get currentRoadAttribution(){return this.sceneRenderer.currentRoadAttribution}setTerrainProviders(t){this.sceneRenderer.setTerrainProviders(t)}setDecorModelProvider(t){this.sceneRenderer.setDecorModelProvider(t)}get decorModelCredits(){return[...new Map(this.sceneRenderer.currentDecorModelCredits.map(e=>[`${e.title}|${e.author??""}|${e.license}|${e.sourceUrl??""}`,e])).values()]}applyFrameFormat(){const t=this.ufoElement.sighting.instrument,e=Fe.CANVAS_HEIGHT_PX,i=bi.frameWidthPx(t,e);this.frameElement.style.setProperty("--frame-aspect",`${i} / ${e}`)}resizeToStage(){const t=this.frameElement.getBoundingClientRect(),e=Math.max(1,Math.round(t.width)),i=Math.max(1,Math.round(t.height));this.sceneCanvas.width=e,this.sceneCanvas.height=i,this.sceneRenderer.resize(e,i)}async loadStars(){const t=[{magnitudeLimit:kf,url:this.getAttribute("star-catalog-src")??ZD},{magnitudeLimit:Ff,url:this.getAttribute("deep-star-catalog-src")??JD}],e=this.instrumentReach(),i=++this.starCatalogRequest;this.starCatalogDepth=e>kf?Ff:kf;const n=await _s.upTo(t,e);i===this.starCatalogRequest&&(this.starCatalog=n,this.sceneRenderer.compileNextFrameOffThread(),this.updateAstronomy(this.lastTimeMs))}ensureStarsDeepEnough(){!this.starCatalog||this.starCatalogDepth>=Ff||this.instrumentReach()<=this.starCatalogDepth||this.loadStars()}instrumentReach(){const t=this.ufoElement.sighting,e=an.gainFor(t.instrument,{fNumber:Ze(t,0)?.fNumber,fieldOfViewDeg:xn.fovOf(t,0),exposureSeconds:t.exposure});return Kh(jD,e)}updateAstronomy(t){this.ensureStarsDeepEnough(),this.applySceneAt(t);const e=as.windowEndingAt(t,this.exposureSeconds()),i=e.seconds,n=this.degreesPerPixelAt(t),s=Ua.instants(i,n),r=Math.max(s,this.ufoElement.exposureTimes(t).length,as.instants(this.decorWithTraffic(this.ufoElement.sighting),Ze(this.ufoElement.sighting,t)?.elevationM??0,e.fromMs,i,n));if(r<=1){this.sceneRenderer.setExposure(1);return}this.sceneRenderer.setExposure(r,o=>this.applySceneAt(e.fromMs+e.ms*o/(r-1),{sky:Math.floor(o*s/r)!==Math.floor((o-1)*s/r),stepMs:e.ms/r}))}exposureSeconds(){return this.ufoElement.sighting.exposure??0}degreesPerPixelAt(t){const e=this.sceneCanvas.height;return e<=0?0:xn.fovOf(this.ufoElement.sighting,t)/e}roadGradeAt(t,e){return t.observerTrack.allKeyframes.length<2?0:Ro.at(t,e,this.sceneRenderer.bodyGround)}get roadGradeDeg(){return this.roadGradeAt(this.ufoElement.sighting,this.ufoElement.currentTime)}applySceneAt(t,e){const i=this.ufoElement.sighting;this.setWeather(Dl(i,t)),this.sceneRenderer.setInstrument(i.instrument),this.sceneRenderer.setLightPollution(i.lightPollution),e||this.vehicleAudio.setVoices(this.vehicleHearing.at(i,t)),e||this.pushAircraftSound(i,t),this.updateMeteorShower(i,t),this.updateLightning(i,t,e!==void 0),this.sceneRenderer.setDecor(this.seatedDecor(this.decorWithTraffic(i),t)),this.sceneRenderer.setDecorPresence(this.traffic?.set?.presence??$e.NO_PRESENCE),this.sceneRenderer.setDecorSunlight(this.trafficSunlight(t)),this.sceneRenderer.setContrails(this.traffic?.contrails??$e.NO_CONTRAILS),this.sceneRenderer.setContrailSunlight(this.contrailSunlight(t));const n=Ze(i,t);this.sceneRenderer.setReferences(i.references,n?.lat!==void 0&&n.lng!==void 0?{lat:n.lat,lng:n.lng}:void 0);const s=Ze(i,0),r=Eo(i,0),o=ra(i.event.time??{},n?.lng??Lh.lng,i.event.utcOffsetHours),c=i.weatherSource!==void 0&&o?Xx(o):void 0,l=Object.fromEntries(Qh(Eo(i,t)).map(T=>[T.id,eg(t,i.weatherTrack,r,s,n,T.id,T.instances?.length?void 0:c)]));this.sceneRenderer.setCloudOffset(eg(t,i.weatherTrack,r,s,n,void 0,c),l),this.sceneRenderer.setObserverPose(n?{...n,pitchDeg:n.pitchDeg+this.roadGradeAt(i,t)}:Lh),this.sceneRenderer.setLensOptics(this.lensOpticsAt(t)),this.sceneRenderer.setInstrumentGain(an.gainFor(i.instrument,{fNumber:n?.fNumber,fieldOfViewDeg:xn.fovOf(i,t),exposureSeconds:i.exposure}),i.instrument.detailUm!==void 0,ls.byId(n?.filter).opticalDensity),this.sceneRenderer.setMedium(i.instrument.medium,i.exposure,n?.fNumber??i.instrument.fNumber,i.iso),this.sceneRenderer.setGait(Ce.bodyAt(i,t,this.ufoElement.steadyBody)),this.sceneRenderer.updateDecorAnchoring(Ze(i,0),n,t),this.placeBodiesAt(t,e===void 0),this.sceneRenderer.updateDecorLitState(t,e?.stepMs??0),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng,()=>{this.placeBodiesAt(this.lastTimeMs,!0),this.sceneRenderer.render()}),this.sceneRenderer.setStatedRoads(i.roads),this.sceneRenderer.setTraces(i.traces,this.traceLabels(i.traces)),this.pushPhenomenaAt(t);const h=n?.lat??Lh.lat,u=n?.lng??Lh.lng,d=ra(i.event.time??{},u,i.event.utcOffsetHours),f={lat:h,lng:u,elevationM:n?.elevationM??0};this.pushSatellitesAt(d,t,f),this.ensureFireballs(d);const p=[...this.interpretationShown?.reentries??[],...this.fireballs?.reentries??[]];if(this.sceneRenderer.setReentries(p.length===0?[]:be.viewsAt(p,t,{lat:h,lng:u,heightM:f.elevationM})),e&&!e.sky)return;if(!d){this.sceneRenderer.setAstronomy(QD);return}const v=new Date(d.getTime()+t),m=Math.max(1,Math.round(.25*this.degreesPerPixelAt(t)/Ua.DEG_PER_SECOND*1e3)),g=Math.max(1e-8,this.degreesPerPixelAt(t)*.1),b=`${Math.floor(v.getTime()/m)}|${Math.round(h/g)}|${Math.round(u/g)}|${Math.round(f.elevationM)}|${this.starCatalog?this.starCatalogDepth:0}`;if(b===this.lastSkyKey){this.sceneRenderer.render();return}this.lastSkyKey=b;const S=xh("Sun",v,f),M=xh("Moon",v,f);let x=Mi.separationOf(S,M)<1?Mi.viewAt(v,f):void 0;if(x){const T=Mi.offsetOf(S,M,x.separationDeg);if(x.obscuration>$e.LIMB_FROM_OBSCURATION){const I=this.limbFor(v,f);I&&(x={...x,obscuration:1-Vn.uncoveredFraction(I,x.sunRadiusDeg,T),limb:I})}x={...x,horizonShare:Mi.horizonShare(x,T,S.altitudeDeg,S.azimuthDeg,Cs.distanceKm(v,f))}}const _={...S,magnitude:uf("Sun",v)-2.5*Math.log10(Mi.beamFraction(x))};this.lastSun={altitudeDeg:_.altitudeDeg,azimuthDeg:_.azimuthDeg};const E={...M,phase:R4(v),magnitude:uf("Moon",v),radiusDeg:Cs.apparentRadiusDeg(v,f)},y=T4.map(T=>({body:T,position:xh(T,v,f),magnitude:uf(T,v)}));this.sceneRenderer.setAstronomy({sun:_,moon:E,planets:y,comet:this.cometAt(v,f),novae:qv.appearancesAt(v,f).map(({outburst:T,position:I,magnitude:C})=>({id:T.id,position:I,magnitude:C})),stars:this.starCatalog?{catalog:this.starCatalog,date:v,observer:f}:void 0,frame:{date:v,observer:f},eclipse:x}),this.ufoElement.setSunAltitude(_.altitudeDeg)}static LIMB_FROM_OBSCURATION=.98;limbRelief;limbRequested=!1;limbCache;limbFor(t,e){if(!this.limbRelief){this.limbRequested||(this.limbRequested=!0,Qc.load(KD).then(s=>{this.limbRelief=s,this.lastSkyKey="",s&&this.isConnected&&this.updateAstronomy(this.lastTimeMs)}));return}const i=this.limbCache;if(i&&Math.abs(t.getTime()-i.atMs)<5e3&&i.lat===e.lat&&i.lng===e.lng&&i.elevationM===e.elevationM)return i.profile;const n=Vn.profile(t,e,this.limbRelief);return this.limbCache={profile:n,atMs:t.getTime(),lat:e.lat,lng:e.lng,elevationM:e.elevationM},n}pushSatellitesAt(t,e,i){if(this.ensureSatellites(t),!t||!this.satellites){this.sceneRenderer.setSatellites([]);return}const n=new Date(t.getTime()+e),s=[];for(const r of this.satellites.passes.positionsAt(n,i,-1))r.magnitude!==void 0&&s.push({norad:r.object.norad,name:r.object.name,position:{altitudeDeg:r.altitudeDeg,azimuthDeg:r.azimuthDeg},magnitude:r.magnitude,heightKm:r.heightKm});this.sceneRenderer.setSatellites(s)}ensureFireballs(t){const e=this.ufoElement.sighting,i=Math.max((e.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),n=t?.getTime(),s=n===void 0?"":`${n}+${i}`;if(this.fireballs?.key===s)return;if(n===void 0||!Ps.mayCover(n+i)){this.fireballs={key:s,status:"outside",reentries:[]};return}const r={key:s,status:"loading",reentries:[]};this.fireballs=r,$e.fireballArchive.between(n,n+i).then(o=>{r.status=o?"ready":"unavailable",r.records=o??[],r.reentries=r.records.map(c=>Ps.asReentry(c,n)),!(this.fireballs!==r||!this.isConnected)&&(this.dispatchEvent(new CustomEvent(YD)),r.reentries.length>0&&this.updateAstronomy(this.lastTimeMs))})}decorWithTraffic(t){const e=this.ensureTraffic(t);if(!e||e.objects.length===0)return t.decor;const i=this.decorMemo;if(i&&i.base===t.decor&&i.traffic===e.objects)return i.merged;const n=[...t.decor,...e.objects];return this.decorMemo={base:t.decor,traffic:e.objects,merged:n},n}seatedDecor(t,e){if(!t.some(r=>r.observerKeyframes?.length))return t;const i=t.map(r=>{if(!r.observerKeyframes?.length)return"";const o=Ym(r,e);return`${o.side??"-"}/${o.facing??"-"}`}).join("|"),n=this.seatedMemo;if(n&&n.base===t&&n.seats===i)return n.seated;const s=t.map(r=>{if(!r.observerKeyframes?.length)return r;const o=Ym(r,e);return{...r,observerSide:o.side,observerFacing:o.facing}});return this.seatedMemo={base:t,seats:i,seated:s},s}ensureTraffic(t){const e=Ze(t,0),i=e?.lng===void 0?void 0:ra(t.event.time??{},e.lng,t.event.utcOffsetHours),n=Math.max((t.event.durationSeconds??0)*1e3,this.ufoElement.seekableDuration),s=i?.getTime(),r=s===void 0||e?.lat===void 0||e.lng===void 0?"":`${this.aircraftSource.id}|${s}+${n}|${e.lat.toFixed(3)},${e.lng.toFixed(3)}|${Math.round(e.elevationM??0)}`;if(this.traffic?.key===r)return this.traffic.set;if(r===""||s===void 0||e?.lat===void 0||e.lng===void 0){this.traffic={key:r,status:"outside"};return}let o=$e.aircraftProviders.get(this.aircraftSource.id);if(o||$e.aircraftProviders.set(this.aircraftSource.id,o=this.aircraftSource.create()),o.mayCover&&!o.mayCover(s+n)){this.traffic={key:r,status:"outside"};return}const c={key:r,status:"loading",startMs:s,observer:{lat:e.lat,lng:e.lng}};this.traffic=c;const l={lat:e.lat,lng:e.lng,heightM:e.elevationM??0},h=on.MAX_GAP_S*1e3,u=$e.SOUND_LOOKBACK_MS,d={lat:e.lat,lng:e.lng,elevationM:e.elevationM??0},f=(p,v)=>p.TrafficDecor.from(c.tracks??[],l,s,p.TrafficDecor.MAX_OBJECTS,{models:v,sunElevationAt:m=>this.sunElevationAt(m,d)});o.between(l,s-u,s+n+h).then(async p=>{if(this.traffic!==c)return;if(p.status!=="found"){c.status=p.status==="outside"?"outside":"unavailable",this.announceTraffic();return}let v;try{v=await $e.loadTrafficRuntime()}catch{this.traffic===c&&(c.status="unavailable",this.announceTraffic());return}this.traffic===c&&(c.status="ready",c.tracks=p.tracks,c.set=f(v),this.startAircraftSound(c,v),this.announceTraffic(),this.describeTraffic(o,c,v,f),c.set.shown>0&&this.readUpperAir(c,v,s-u,s+n+h))})}trafficSunlight(t){const e=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||i.startMs===void 0||!i.observer)return e;for(const[r,o]of n.presence){if(t<o.fromMs||t>o.untilMs)continue;const c=n.flights.get(r),l=c?on.positionAt(c,i.startMs+t):void 0;l&&e.set(r,{heightM:l.geo.heightM,sunElevationDeg:Pn.sunElevationDeg(s,i.observer,l.geo)})}return e}trafficTooltipAt(t,e){const i=this.sceneRenderer.pickTrafficAt(t,e),n=i?this.trafficInfoAt(i):void 0;if(!n)return;const s=this.naming,r=$e.trafficRuntime;return r?.TrafficTooltip.text(n,s.names?.trafficTooltip??r.TrafficTooltip.ENGLISH,o=>s.towards(o))}trafficInfoAt(t){const e=this.traffic,i=e?.set?.flights.get(t);if(!e||!i||e.startMs===void 0||!e.observer)return;const n=$e.trafficRuntime;if(!n)return;const s=e.descriptions?.get(Xn.keyOf(i)),r=Ze(this.ufoElement.sighting,this.lastTimeMs),o={lat:e.observer.lat,lng:e.observer.lng,heightM:r?.elevationM??0},c=n.AmbientNoise.dbA(Dl(this.ufoElement.sighting,this.lastTimeMs)),l=n.TrafficInfos.at(i,s,o,e.startMs+this.lastTimeMs,{ambientDbA:c}),h=l&&this.contrailAt(t,this.lastTimeMs);return l&&h?{...l,contrail:h}:l}contrailAt(t,e){const i=this.traffic?.contrails?.find(s=>s.id===t);if(!i)return;let n;for(const s of i.points){if(s.tMs>e)break;n=s}return n?.forms?{persistent:n.persistent,iceRelativeHumidity:n.iceRelativeHumidity}:void 0}startAircraftSound(t,e){this.aircraftAudio||(this.aircraftAudio=new e.AircraftAudio,this.aircraftAudio.setLevel(this.ufoElement.level),this.interacted&&this.aircraftAudio.resume(),this.aircraftAudio.setPaused(this.ufoElement.playbackState!=="playing")),this.sortOutAudible(t,e)}sortOutAudible(t,e){!t.set||!t.observer||(t.audible=e.TrafficSound.candidates(t.set.flights,t.descriptions??new Map,Xn.keyOf,{...t.observer,heightM:0},{ambientDbA:e.AmbientNoise.BASE_DB_A}))}pushAircraftSound(t,e){const i=this.aircraftAudio;if(!i)return;const n=$e.trafficRuntime,s=this.traffic,r=s?.set;if(!n||!s||!r||!s.audible||s.startMs===void 0||!s.observer){i.setVoices([]);return}const o=Ze(t,e),c={lat:s.observer.lat,lng:s.observer.lng,heightM:o?.elevationM??0},l=Dl(t,e),h=n.TrafficSound.voices(s.audible,r.flights,s.descriptions??new Map,Xn.keyOf,c,s.startMs+e,{ambientDbA:n.AmbientNoise.dbA(l),referenceAmplitude:n.AmbientNoise.referenceAmplitude(l)});i.setVoices(h,o?.headingDeg??0)}announceTraffic(){this.isConnected&&(this.dispatchEvent(new CustomEvent(qD)),this.updateAstronomy(this.lastTimeMs))}async describeTraffic(t,e,i,n){if(!t.describe||!e.set||!e.tracks)return;const s=new Set([...e.set.flights.values()].map(l=>Xn.keyOf(l))),r=e.tracks.filter(l=>s.has(Xn.keyOf(l))&&l.points.length>0),o=new Map,c=new Map;await Promise.all(r.map(async l=>{const h=new Date(l.points[0].t).toISOString().slice(0,10),u=await t.describe(l,h).catch(()=>{});u&&(c.set(Xn.keyOf(l),u),o.set(Xn.keyOf(l),i.AircraftModels.of(u)))})),!(this.traffic!==e||o.size===0)&&(e.descriptions=c,e.models=o,e.set=n(i,o),this.planContrails(e,i),this.sortOutAudible(e,i),this.announceTraffic())}async readUpperAir(t,e,i,n){if(!t.observer)return;const s=this.upperAirSource??e.UPPER_AIR_SOURCES[0];let r=$e.upperAirProviders.get(s.id);r||$e.upperAirProviders.set(s.id,r=s.create());const o=await r.between(t.observer,i,n);this.traffic!==t||o.status!=="found"||(t.air=o.samples,t.airSource=o.source,this.planContrails(t,e),this.announceTraffic())}planContrails(t,e){!t.set||!t.air||t.startMs===void 0||(t.contrails=e.AircraftContrails.plan(t.set,t.models,t.air,t.startMs))}contrailSunlight(t){const e=new Map,i=this.traffic,n=i?.set,s=this.lastSun;if(!n||!s||!i.contrails?.length||i.startMs===void 0||!i.observer)return e;for(const r of i.contrails){const o=n.presence.get(r.id),c=n.flights.get(r.id);if(!o||!c)continue;const l=on.positionAt(c,i.startMs+Math.min(o.untilMs,Math.max(o.fromMs,t)));l&&e.set(r.id,{heightM:l.geo.heightM,sunElevationDeg:Pn.sunElevationDeg(s,i.observer,l.geo)})}return e}sunElevationAt(t,e){const i=xh("Sun",new Date(t.t),e);return Pn.sunElevationDeg(i,e,t)}upperAirSource;setUpperAirSource(t){t.id!==this.upperAirSource?.id&&(this.upperAirSource=t,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}setAircraftSource(t){t.id!==this.aircraftSource.id&&(this.aircraftSource=t,this.traffic=void 0,this.decorMemo=void 0,this.updateAstronomy(this.lastTimeMs))}get aircraftState(){const t=this.traffic?.contrails?.length?this.upperAirSource??$e.trafficRuntime?.UPPER_AIR_SOURCES[0]:void 0;return{trailCredit:t&&{credit:t.credit,creditUrl:t.creditUrl},status:this.traffic?.status??"none",total:this.traffic?.set?.total??0,shown:this.traffic?.set?.shown??0,credit:this.aircraftSource.credit,creditUrl:this.aircraftSource.creditUrl}}get fireballState(){return{status:this.fireballs?.status??"none",records:this.fireballs?.records??[]}}ensureSatellites(t){const e=t?String(t.getTime()):"";if(e===this.satellitesFor)return;this.satellitesFor=e,this.satellites=void 0,this.satellitePassesMemo=void 0;const i=++this.satelliteRequest;if(!t){this.satelliteStatus="none";return}this.satelliteStatus="loading";const n=r=>{i===this.satelliteRequest&&(this.satelliteStatus=r,this.isConnected&&this.dispatchEvent(new CustomEvent(XD)))},s=$e.tleArchive;(async()=>{if(!await s.covers(t))return n("outside");const[r,o]=await Promise.all([s.at(t),je(()=>import("./SatellitePasses-Pfro2-0Z.js"),[],import.meta.url)]);if(i===this.satelliteRequest){if(!r)return n("unavailable");this.satellites={snapshot:r,passes:new o.SatellitePasses(r.objects)},n("ready"),this.isConnected&&this.updateAstronomy(this.lastTimeMs)}})().catch(()=>n("unavailable"))}get satelliteState(){const t=this.satellites?.snapshot;return{status:this.satelliteStatus,coverage:t?.coverage,credit:t?.credit,creditUrl:t?.creditUrl}}satellitePassesDuring(t){const e=this.satellites,i=this.ufoElement.sighting,n=Ze(i,0),s=i.event.place?.[0],r=n?.lat??s?.lat,o=n?.lng??s?.lng;if(!e||r===void 0||o===void 0)return[];const c=ra(i.event.time??{},o,i.event.utcOffsetHours);if(!c)return[];const l=Math.min(Math.max(t,0),4*36e5),h={lat:r,lng:o,elevationM:n?.elevationM??0},u=JSON.stringify([this.satellitesFor,c.getTime(),r,o,h.elevationM,l]);if(this.satellitePassesMemo?.key===u)return this.satellitePassesMemo.passes;const d=Math.max(10,Math.ceil(l/1e3/600)),f=e.passes.passesDuring(c,new Date(c.getTime()+l),h,d);return this.satellitePassesMemo={key:u,passes:f},f}cometAt(t,e){const i=LD.brightestAt(t,e);if(i)return{id:i.apparition.id,position:i.position,tailEnd:i.tailEnd,magnitude:i.magnitude}}pushPhenomenaAt(t){const e=this.ufoElement.sighting;e!==this.sizeEstimatesFor&&(this.sizeEstimates.clear(),this.distanceHypotheses.clear(),this.sizeEstimatesFor=e);const i=e.timeline,n=this.ufoElement.canvasElement,s=this.ufoElement.frameShiftPx,r=this.projectionAt(t),o=new Map,c=new Map,l=new Set;for(const p of i.sourceIds){const v=i.getInterpolatedShapeAt(t,p);if(!v)continue;const m={...v,bounds:{...v.bounds,x:v.bounds.x+s.x,y:v.bounds.y+s.y}};o.set(p,m);const g=v.aim?this.sceneRenderer.screenPointOf(ss.directionOf(v.aim,this.directionScratch)):{ndcX:(m.bounds.x+m.bounds.width/2)/n.width*2-1,ndcY:-((m.bounds.y+m.bounds.height/2)/n.height*2-1)},b=g!==void 0&&Math.abs(g.ndcX)<=1&&Math.abs(g.ndcY)<=1,S=b?this.sceneRenderer.decorDistancesAt(g.ndcX,g.ndcY,p):{};l.add(p),(b||v.aim)&&l.delete(p);const M=v.angular?.widthDeg??r.pxToDeg(v.bounds.width),x=this.sizeEstimateOf(p);x.add(M,S);const _=tl.of(e,p);c.set(p,sn.resolve({hypothesisM:this.distanceHypotheses.get(p),derivedM:_&&M>0?Fe.distanceMAt(_.widthM,M):void 0,range:x.distanceRangeAt(M),crossing:S}))}for(const[p,v]of o)for(const[m,g]of o){if(m===p||g.transparency>=1||g.bounds.width*g.bounds.height<=v.bounds.width*v.bounds.height||!(v.bounds.x>=g.bounds.x&&v.bounds.y>=g.bounds.y&&v.bounds.x+v.bounds.width<=g.bounds.x+g.bounds.width&&v.bounds.y+v.bounds.height<=g.bounds.y+g.bounds.height))continue;const S=c.get(m);S&&c.set(p,{distanceM:S.distanceM*.999,basis:S.basis});break}this.depths=c;const h=i.sourceIds,u=[];for(const[p,v]of o)u.push({sourceId:p,shape:v,distanceM:c.get(p).distanceM,renderOrder:h.indexOf(p),aim:v.aim,hidden:l.has(p)||this.interpretationShown!==void 0&&(!this.comparing||v.transparency>=1),ghost:this.interpretationShown!==void 0&&this.comparing});const f=(Ze(e,t)?.rollDeg??0)+Ce.bodyAt(e,t,this.ufoElement.steadyBody).rollDeg;this.sceneRenderer.setPhenomena(u,{projection:r,canvasWidthPx:n.width,canvasHeightPx:n.height,scale:Math.max(1,this.sceneCanvas.height/Math.max(1,n.height)),starPoints:bi.starPointsOf(e.instrument),rollRad:f*Math.PI/180})}get interpretation(){return this.interpretationShown}set interpretation(t){this.interpretationShown=t,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs)}syncAccountHidden(){this.ufoElement.accountHidden=this.interpretationShown!==void 0&&!this.comparing}get accountInTheRound(){return this.inTheRound}set accountInTheRound(t){this.inTheRound=t}get compareAccount(){return this.comparing}set compareAccount(t){this.comparing=t,this.syncAccountHidden(),this.updateAstronomy(this.lastTimeMs)}get confrontation(){return this.confrontationReadings}groundAlong(t,e,i){const n=this.sceneRenderer.bodyGround,s=ce.eyeOf(this.ufoElement.sighting,i,n);return s?ce.lineOfSightMeetsGround(s,t,e,n):void 0}bodyReading(t,e){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=d=>ce.eyeOf(n,d,i),r=new ce(t,i,s).at(e),o=s(e);if(!r||!o)return;const c=r.eastM-o.eastM,l=r.northM-o.northM,h=r.upM-o.upM,u=Math.hypot(c,l);return{azimuthDeg:(Math.atan2(c,l)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(h,u)*180/Math.PI,distanceM:Math.hypot(u,h),eastM:r.eastM,northM:r.northM,aboveGroundM:r.upM-r.sizeM.heightM/2-i.heightAt(r.eastM,r.northM),sizeM:r.sizeM,attitude:r.attitude,appearance:r.appearance}}directionToBody(t,e){const i=this.sceneRenderer.bodyGround,n=this.ufoElement.sighting,s=p=>ce.eyeOf(n,p,i),r=new ce(t,i,s),o=r.at(e)?e:t.track[0]?.t,c=o===void 0?void 0:r.at(o),l=o===void 0?void 0:s(o);if(!c||!l)return;const h=c.eastM-l.eastM,u=c.northM-l.northM,d=c.upM-l.upM,f=Math.hypot(h,u);if(!(f===0&&d===0))return{azimuthDeg:(Math.atan2(h,u)*180/Math.PI+360)%360,altitudeDeg:Math.atan2(d,f)*180/Math.PI}}placeBodiesAt(t,e){const i=this.interpretationShown,n=this.ufoElement.sighting;let s=[],r=[];const o=this.sceneRenderer.bodyGround,c=p=>ce.eyeOf(n,p,o);i&&(s=i.bodies.map(p=>new ce(p,o,c).at(t)).filter(p=>p!==void 0));const l=Eo(n,t),h=l.windDirectionDeg*Math.PI/180,u={x:l.windSpeed*Math.sin(h),z:-l.windSpeed*Math.cos(h)};this.sceneRenderer.setBodies(s,t/1e3,i?.bodies.map(p=>p.id)??[],i?.smoke??[],u);const d=i&&this.comparing?c(t):void 0;if(d&&(r=new di(n.timeline).at(t,s,d,p=>p.outlineNode?this.sceneRenderer.bodyOutline?.(p.id,p.outlineNode):void 0)),this.confrontationReadings=r,!e)return;const f=JSON.stringify(r);f!==this.confrontationSignature&&(this.confrontationSignature=f,this.dispatchEvent(new CustomEvent(ly,{detail:r})))}setDistanceHypothesis(t,e){e===void 0||!(e>0)?this.distanceHypotheses.delete(t):this.distanceHypotheses.set(t,e),this.updateAstronomy(this.lastTimeMs)}depthOf(t){return this.depths.get(t)}sizeRangeOf(t){return this.sizeEstimateOf(t).sizeRange}distanceRangeAt(t,e){const i=this.ufoElement.sighting.timeline.getInterpolatedShapeAt(e,t);if(!i)return{};const n=i.angular?.widthDeg??this.projectionAt(e).pxToDeg(i.bounds.width);return this.sizeEstimateOf(t).distanceRangeAt(n)}sizeContradictory(t){return this.sizeEstimateOf(t).contradictory}updateMeteorShower(t,e){this.ensureMeteorSchedule(t),this.sceneRenderer.updateMeteors(e)}updateLightning(t,e,i){if(this.ensureLightningSchedule(t),this.sceneRenderer.updateLightning(e),i)return;const n=this.lastLightningT;if(this.lastLightningT=e,n===void 0||e<n||this.ufoElement.playbackState!=="playing")return;const s=this.lightningFlashes.filter(r=>r.t>n&&r.t<=e).pop();s&&Eo(t,s.t).storm&&this.handleLightningFlash(s)}ensureLightningSchedule(t){const e=Eo(t,0).precipitationIntensity,i=`${this.meteorInputsOf(t)}|${e}`;if(i===this.lightningScheduleFor)return;this.lightningScheduleFor=i;const n=t.event.time,s=t.event.place?.[0],r=n?.year!==void 0?ra(n,s?.lng??0,t.event.utcOffsetHours):void 0,o=(t.event.durationSeconds??0)*1e3||t.timeline.duration||2e4,c=Math.round((r?.getTime()??0)/1e3)+Math.round((s?.lat??0)*1e3)+7;this.lightningFlashes=Ci.schedule({durationMs:o,seed:c,intensity:e}),this.sceneRenderer.setLightning(this.lightningFlashes)}ensureMeteorSchedule(t){const e=this.meteorInputsOf(t);e!==this.meteorScheduleFor&&(this.meteorScheduleFor=e,this.scheduleMeteors(t))}meteorInputsOf(t){const e=t.event.place?.[0],i=t.event.time;return JSON.stringify([e?.lat,e?.lng,i?.year,i?.month,i?.day,i?.hour,i?.minute,i?.second,t.event.utcOffsetHours,t.event.durationSeconds,t.timeline.duration])}scheduleMeteors(t){const e=t.event.place?.[0],i=t.event.time,n=e?.lat!==void 0&&e.lng!==void 0&&i?.year!==void 0?ra(i,e.lng,t.event.utcOffsetHours):void 0;if(!n||e?.lat===void 0||e.lng===void 0){this.sceneRenderer.setMeteorShower([],0,0);return}const s={lat:e.lat,lng:e.lng,elevationM:0},r=(t.event.durationSeconds??0)*1e3||t.timeline.duration||2e4,o=Math.round(n.getTime()/1e3)+Math.round(e.lat*1e3),c=fi.schedule({ratePerHour:fi.observedRatePerHour(fi.apexPosition(n,s).altitudeDeg),durationMs:r,velocityKmS:fi.TYPICAL_VELOCITY_KM_S,seed:o}),l=zf.activeAt(n).map(u=>{const d=zf.radiantPosition(u.shower,n,s);return{entry:u,position:d,rate:zf.observedRatePerHour(u.zhr,d.altitudeDeg,u.shower.populationIndex)}}).sort((u,d)=>d.rate-u.rate)[0];if(!l||l.rate<=0){this.sceneRenderer.setMeteorShower(c,0,0);return}const h=ka.schedule({ratePerHour:l.rate,durationMs:r,velocityKmS:l.entry.shower.velocityKmS,seed:o+1});this.sceneRenderer.setMeteorShower([...h,...c],l.position.altitudeDeg,l.position.azimuthDeg)}meteorByRank(t){this.ensureMeteorSchedule(this.ufoElement.sighting);const e=[...this.sceneRenderer.meteorSchedule].filter(s=>s.t+s.durationMs<=this.ufoElement.seekableDuration).sort((s,r)=>r.brightness-s.brightness);if(e.length===0)return;const i=e[t%e.length],n=this.sceneRenderer.meteorMidpoint(i);if(n)return{t:Math.round(i.t+i.durationMs*.45),...n}}lensOpticsAt(t){const e=this.ufoElement.sighting,i=e.instrument,n=i.frame,s=Ze(e,t),r=s?.fNumber??i.fNumber;if(!n||r===void 0)return;const o=bi.focalLengthMmFor(i,xn.fovOf(e,t));if(o!==void 0)return{focalLengthMm:o,fNumber:r,focusDistance:s?.focusDistanceM??0,frameHeightMm:n.heightMm}}projectionAt(t){const e=this.ufoElement.sighting;return rr.of(e.instrument,Fe.CANVAS_HEIGHT_PX,xn.fovOf(e,t))}sizeEstimateOf(t){let e=this.sizeEstimates.get(t);return e||(e=new kD,this.sizeEstimates.set(t,e)),e}}const qu="rr0-scene";function hy(){PM(),customElements.get(qu)||customElements.define(qu,$e)}const tI={color:"Color",transparency:"Transparency",halo:"Halo",blur:"Blur",brightness:"Brilliance",shapeTitle:"Name",utcOffset:"Time zone",cloudBase:"Cloud base",elevation:"Altitude",heightAboveGround:"Height above ground",duration:"Duration",placeName:"Place",latitude:"Latitude",longitude:"Longitude",heading:"Heading",pitch:"Tilt",roll:"Roll",sway:"Sway at rest",swayTitle:"How much the body holding the instrument moves the view when not walking: 1 for a person standing, 0 for a tripod. Blank: 1 (0 if the account says the observer was paralysed)",lightPollution:"Night sky",lightPollutionTitle:'The zenith of a moonless night at this place, in magnitudes per square arcsecond, as a Sky Quality Meter reads it or as the World Atlas of artificial sky brightness (Falchi et al. 2016, lightpollutionmap.info, "SQM") gives it. 22 is a natural sky; a suburb is about 19, a city centre 17. Blank: a natural sky',observationTime:"Observation start",observationEndTime:"Observation end",assessmentGroup:"Assessment",assessmentNames:{coverage:"Observer info"},assessmentVerdicts:{"hynek.nl":"NL — nocturnal light","hynek.dd":"DD — daylight disc","hynek.rv":"RV — radar-visual","hynek.ce1":"CE1 — close encounter","hynek.ce2":"CE2 — with a physical trace","hynek.ce3":"CE3 — with entities"},timeQualifierApproximate:"Approximate",timeQualifierUncertain:"Uncertain",timeQualifierBoth:"Uncertain and approximate",timeSeasonSpring:"Spring",timeSeasonSummer:"Summer",timeSeasonAutumn:"Autumn",timeSeasonWinter:"Winter",summaryGroups:{observation:"Observation",location:"Position",temporal:"Time",weather:"Weather",sound:"Sound"},summaryGroup:"Summary",summaryDescription:"Description",closeDescription:"Close the description",observerGroup:"Observer",observerId:"ID",observerTitle:"Title",observerLastName:"Last name",observerFirstNames:"First names",sightingId:"ID",tags:"Tags",cloudCover:"Cloud cover",highCloudCover:"Ice cloud (cirrus)",focalLength:"Focal length",fieldOfView:"Field of view",aperture:"Aperture",exposure:"Exposure",focusDistance:"Focused at",iceCrystalAlignment:"Crystal alignment",cloudDarkness:"Cloud darkness",precipitationType:"Precipitation",precipitationNone:"None",precipitationRain:"Rain",precipitationSnow:"Snow",precipitationHail:"Hail",precipitationIntensity:"Intensity",windDirection:"Wind direction",windSpeed:"Wind speed",storm:"Storm",cloudsGroup:"Clouds",precipitationGroup:"Precipitation",windGroup:"Wind",soundKind:"Sound",soundNone:"None (silent)",soundHum:"Hum",soundWhistle:"Whistle",soundRumble:"Rumble",soundCrackle:"Crackle",soundVolume:"Loudness",soundPitch:"Pitch",soundSrc:"Recording",instrument:"Observed through",filter:"In front of it",filterNone:"nothing",filterSolarVisual:"a solar filter for the eye (eclipse glasses, density 5)",filterSolarPhoto:"a solar film for a camera (density 3.8)",decorAircraft:"Aircraft",decorEntity:"Being",decorAltitude:"Altitude",decorLights:"Lights",decorLightsNone:"none",decor:"Environment",decorBuilding:"Building",decorTree:"Tree",decorShrub:"Shrub",decorBridge:"Bridge",decorWire:"Overhead line",decorCrop:"Crop row",decorTerrace:"Terrace (restanque)",decorMound:"Stone heap",decorStreetlight:"Streetlight",decorVehicle:"Vehicle",decorObserver:"Other observer",decorEast:"Distance east",decorNorth:"Distance north",decorHeading:"Heading",decorColor:"Colour",decorLit:"Lit",decorTitle:"Name",milestones:"Moments",milestoneLabel:"Label",milestoneNote:"What happens",addMilestone:"Name this moment",deleteMilestone:"Delete moment",goToMilestone:"Go to this moment",decorWidth:"Width",decorLength:"Length",decorHeight:"Height",decorModel:"3D model",decorModelNone:"Built-in shape",decorModelDefault:"Default model",decorModelAdvanced:"Model from an address",decorModelFromCatalogue:"From the catalogue, which the recording names it by. Change a field and it becomes this recording's own address.",decorModelUrl:"glTF/GLB address",decorModelTitle:"Model name",decorModelAuthor:"Author",decorModelLicense:"Licence",decorModelSource:"Where it came from",decorFloors:"Floors",decorOccupiedFloor:"Occupied floor",decorObserverSide:"Observer location",decorObserverSideNone:"Not present",decorWindows:"Windows",decorSideFront:"Front",decorSideBehind:"Behind",decorSideLeft:"Left",decorSideRight:"Right",decorSideFrontLeft:"Front-left",decorSideFrontRight:"Front-right",decorSideBehindLeft:"Behind-left",decorSideBehindRight:"Behind-right"},Hc={...tI,accountBy:"Account by",unnamedObserver:"Observer {n}",about:"About",close:"Close",observation:"Observation",date:"Date",location:"Location",case:"Case",description:"Description",source:"Source",basis:{stated:"stated",derived:"derived",assumed:"assumed"},credits:"Credits",editThisObservation:"Edit this observation",embed:"Embed",embedReplay:"Player",embedEdit:"Editor",share:"Share",embedObservation:"Embed the observation",back:"Back",embedCopy:"Copy",shareLink:"Link",shareStartAt:"Start at",shareOptionLabels:"Show summary chips",shareOptionMap:"Open map",shareOptionMilestones:"Show moments",shareOptionCompare:"Compare account",embedCopied:"Copied",showLabels:"Show what it states",interpretation:"Interpretation",account:"Account",interpretationBy:"{title}, by {by}",confrontation:"Against the account",confrontationDirection:"{deg}° off",confrontationWidth:"width ×{ratio}",confrontationHeight:"height ×{ratio}",showComparison:"Compare with the account",hideComparison:"Stop comparing with the account",hideLabels:"Hide what it states"},eI=Object.freeze(Object.defineProperty({__proto__:null,sightingMessages_en:Hc},Symbol.toStringTag,{value:"Module"}));hy();class $u{static PRODUCTION="https://ufoathome.org";static home(){try{const t=new URL(import.meta.url),e=new URL(location.href);return(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname==="[::1]"||e.hostname.endsWith(".localhost"))&&t.origin===e.origin?e.origin:$u.PRODUCTION}catch{return $u.PRODUCTION}}}const jh=$u.home(),Nh="compare-account",kh="start-time",Gf="account",Vf=`${jh}/edit/`;class qo extends HTMLElement{static get observedAttributes(){return["src","show-labels",kh,ks,Fs,Nh]}shadow;sceneElement;toolbarElement;accountElement;accountPrefix;observerText;observerSelect;infoButton;infoPanel;infoAppLink;editLink;infoObservationHeading;infoObservationList;infoCreditsToggle;infoCreditsList;infoCloseButton;shareButton;shareDialog;shareTitle;shareLinkOption;shareLinkLabel;shareLinkBox;shareEmbed;shareClose;shareEmbedOption;shareEmbedLabel;shareLink;shareReplayOptions;embedCode;shareCopy;shareStartOn;shareStart;shareStartLabel;shareOptions;embedReplayRadio;embedEditRadio;labelEmbedReplay;labelEmbedEdit;embedMarkup;embedCopyButton;labelsToggle;paramSummary;summaryBuilder=new sl(Hc,new Xu,new Yn(["en"]),new zh({}),{messages:Hc,locale:"en"});summarySignature="";assessmentEntries=[];assessmentToken=0;supportsPopover=typeof HTMLElement.prototype.showPopover=="function";entries=[];caseSource;interpretationChoice;interpretationLabel;interpretationSelect;confrontationElement;confrontationHeading;confrontationList;compareButton;interpretationLoaders=new Map;interpretationToken=0;offeredFor;currentSrc;infoOpen=!1;creditsOpen=!1;labelsShown=!1;language="en";messages=Hc;constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=`<style>${by}</style>${xy}`,this.shadow.appendChild(t.content.cloneNode(!0)),this.sceneElement=document.createElement(qu),this.forwardPlayerAttributes(),this.sceneElement.ufoElement.creditShownExternally=!0,this.sceneElement.ownCredits=!1,this.shadow.getElementById("ufo-slot").replaceWith(this.sceneElement),this.toolbarElement=this.shadow.getElementById("toolbar"),this.accountElement=this.shadow.getElementById("account"),this.accountPrefix=this.shadow.getElementById("account-prefix"),this.observerText=this.shadow.getElementById("observer-text"),this.observerSelect=this.shadow.getElementById("observer"),this.infoButton=this.shadow.getElementById("info-button"),this.infoPanel=this.shadow.getElementById("info-panel"),this.infoAppLink=this.shadow.getElementById("info-app-link"),this.editLink=this.shadow.getElementById("edit-link"),this.infoObservationHeading=this.shadow.getElementById("info-observation-heading"),this.infoObservationList=this.shadow.getElementById("info-observation-list"),this.infoCreditsToggle=this.shadow.getElementById("info-credits-toggle"),this.infoCreditsList=this.shadow.getElementById("info-credits-list"),this.infoCloseButton=this.shadow.getElementById("info-close"),this.labelsToggle=this.shadow.getElementById("info-labels-toggle"),this.paramSummary=this.shadow.getElementById("param-summary"),this.labelsToggle.addEventListener("click",()=>{this.showLabels=!this.showLabels}),this.shareButton=document.createElement("button"),this.shareButton.type="button",this.shareButton.id="share-button",this.shareButton.setAttribute("aria-haspopup","dialog"),this.shareButton.innerHTML=Gt.SHARE,this.sceneElement.ufoElement.addControl(this.shareButton),this.shareDialog=this.shadow.getElementById("share-dialog"),this.shareTitle=this.shadow.getElementById("share-title"),this.shareLinkOption=this.shadow.getElementById("share-link-option"),this.shareLinkLabel=this.shadow.getElementById("share-link-label"),this.shareLinkBox=this.shadow.querySelector(".share-link"),this.shareEmbed=this.shadow.getElementById("share-embed"),this.shareClose=this.shadow.getElementById("share-close"),this.shareEmbedOption=this.shadow.getElementById("share-embed-option"),this.shareEmbedLabel=this.shadow.getElementById("share-embed-label"),this.shareLink=this.shadow.getElementById("share-link"),this.shareReplayOptions=this.shadow.getElementById("share-replay-options"),this.embedCode=this.shadow.getElementById("embed-code"),this.shareCopy=this.shadow.getElementById("share-copy"),this.shareStartOn=this.shadow.getElementById("share-start-on"),this.shareStart=this.shadow.getElementById("share-start"),this.shareStartLabel=this.shadow.getElementById("share-start-label");const e=i=>({input:this.shadow.getElementById(`share-opt-${i}`),label:this.shadow.getElementById(`share-opt-${i}-label`)});this.shareOptions={labels:e("labels"),map:e("map"),milestones:e("milestones"),compare:e("compare")},this.embedReplayRadio=this.shadow.getElementById("embed-kind-replay"),this.embedEditRadio=this.shadow.getElementById("embed-kind-edit"),this.labelEmbedReplay=this.shadow.getElementById("label-embed-replay"),this.labelEmbedEdit=this.shadow.getElementById("label-embed-edit"),this.embedMarkup=this.shadow.getElementById("embed-markup"),this.embedCopyButton=this.shadow.getElementById("embed-copy"),this.interpretationChoice=this.shadow.getElementById("interpretation-choice"),this.interpretationLabel=this.shadow.getElementById("interpretation-label"),this.interpretationSelect=this.shadow.getElementById("interpretation"),this.confrontationElement=this.shadow.getElementById("confrontation"),this.confrontationHeading=this.shadow.getElementById("confrontation-heading"),this.confrontationList=this.shadow.getElementById("confrontation-list"),this.compareButton=this.shadow.getElementById("compare-account"),this.compareButton.addEventListener("click",()=>this.setComparing(!this.sceneElement.compareAccount)),this.observerSelect.addEventListener("change",()=>this.selectObserver(this.observerSelect.value)),this.interpretationSelect.addEventListener("change",()=>void this.chooseInterpretation(this.interpretationSelect.value)),this.sceneElement.addEventListener(ly,i=>this.showConfrontation(i.detail)),this.sceneElement.ufoElement.addEventListener("timeupdate",()=>this.refreshParamSummary()),this.supportsPopover?(this.infoPanel.setAttribute("popover","auto"),this.infoPanel.removeAttribute("hidden"),this.infoButton.setAttribute("popovertarget","info-panel"),this.infoPanel.addEventListener("beforetoggle",i=>{i.newState==="open"&&(this.populateInfoPanel(),this.bringInfoButtonIntoView())}),this.infoPanel.addEventListener("toggle",i=>this.syncInfoOpen(i.newState==="open"))):this.infoButton.addEventListener("click",()=>this.toggleInfoPanel()),this.infoCloseButton.addEventListener("click",()=>this.toggleInfoPanel()),this.infoCreditsToggle.addEventListener("click",()=>this.toggleCredits()),this.shareButton.addEventListener("click",()=>this.openShare()),this.shareClose.addEventListener("click",()=>this.closeShare()),this.shareLinkOption.addEventListener("click",()=>this.showShareView("link")),this.shareEmbedOption.addEventListener("click",()=>this.showShareView("embed"));for(const i of[this.shareStartOn,this.shareStart,...Object.values(this.shareOptions).map(n=>n.input)])i.addEventListener("input",()=>this.refreshShareLinks());this.shareCopy.addEventListener("click",()=>void this.copyText(this.shareLink.value,this.shareLink,this.shareCopy)),this.shareDialog.addEventListener("click",i=>{i.target===this.shareDialog&&this.closeShare()});for(const i of[this.embedReplayRadio,this.embedEditRadio])i.addEventListener("change",()=>this.refreshShareLinks());this.embedCopyButton.addEventListener("click",()=>void this.copyEmbedMarkup()),this.isConnected&&this.loadLocaleMessages()}get scene(){return this.sceneElement}async loadLocaleMessages(){const t=++this.localeToken,e=Gr.preferencesFor(this);this.preferences=e;const i=Ep(e,Ap),[n,s,r]=i==="en"?[Hc,{},void 0]:await Promise.all([ub(i),db(i),bM(i)]);if(t!==this.localeToken)return;const o=i!==this.language;this.language=i,this.messages=n,this.tags=new zh(s),this.said=new Yn(e),this.summaryBuilder=new sl(this.messages,new Xu(r),this.said,this.tags,{messages:this.messages,locale:i}),this.accountPrefix.textContent=this.messages.accountBy,this.interpretationLabel.textContent=this.messages.interpretation,this.confrontationHeading.textContent=this.messages.confrontation;const c=this.entries.find(l=>l.src===this.currentSrc);c&&this.offerInterpretations(c),this.updateCompareButton(),this.infoButton.title=this.messages.about,this.infoButton.setAttribute("aria-label",this.messages.about),this.editLink.title=this.messages.editThisObservation,this.editLink.setAttribute("aria-label",this.messages.editThisObservation),this.infoCloseButton.setAttribute("aria-label",this.messages.close),this.infoObservationHeading.textContent=this.messages.observation,this.infoCreditsToggle.textContent=this.messages.credits,this.syncLabelsToggle(),this.refreshParamSummary(),o&&this.currentSrc&&this.runAssessments(),this.shareButton.title=this.messages.share,this.shareButton.setAttribute("aria-label",this.messages.share),this.shareClose.setAttribute("aria-label",this.messages.close),this.shareCopy.textContent=this.messages.embedCopy,this.shareStartLabel.textContent=this.messages.shareStartAt,this.shareOptions.labels.label.textContent=this.messages.shareOptionLabels,this.shareOptions.map.label.textContent=this.messages.shareOptionMap,this.shareOptions.milestones.label.textContent=this.messages.shareOptionMilestones,this.shareOptions.compare.label.textContent=this.messages.shareOptionCompare,this.shareStart.setAttribute("aria-label",this.messages.shareStartAt),this.shareEmbedLabel.textContent=this.messages.embed,this.shareLinkLabel.textContent=this.messages.shareLink,this.shareTitle.textContent=this.messages.share,this.labelEmbedReplay.textContent=this.messages.embedReplay,this.labelEmbedEdit.textContent=this.messages.embedEdit,this.embedCopyButton.textContent=this.messages.embedCopy,this.infoOpen&&this.populateInfoPanel(),this.updateAccountLine()}preferences=[];localeToken=0;said=new Yn(["en"]);tags=new zh({});connectedCallback(){Gr.preferencesFor(this).join()!==this.preferences.join()&&this.loadLocaleMessages();const t=this.getAttribute("src");t&&this.loadFromSrc(t)}disconnectedCallback(){document.removeEventListener("click",this.handleOutsideClick)}attributeChangedCallback(t,e,i){t==="src"&&i&&i!==e&&this.isConnected&&this.loadFromSrc(i),t==="show-labels"&&this.applyLabels(this.hasAttribute("show-labels")),(t===ks||t===Fs)&&this.forwardPlayerAttributes(),t===Nh&&this.setComparing(this.hasAttribute(Nh))}forwardPlayerAttributes(){for(const t of[ks,Fs]){const e=this.getAttribute(t);e===null?this.sceneElement.removeAttribute(t):this.sceneElement.setAttribute(t,e)}}async loadFromSrc(t){this.startPending=!0;const e=Gc.json(t);this.sceneElement.holdForNewScene(e);const i=await e;if(Array.isArray(i))throw new Error(`${t} is a bare list of recordings, which is no longer read: list them as the sighting events of a case.json`);if(cs.isCase(i)){const n=cs.sightingUrls(i,new URL(t,location.href).href);if(n.length===0)throw new Error(`${t} is a case with no sighting event: no recording to show`);await this.loadObserverUrls(n,{json:i,url:new URL(t,location.href).href})}else this.setEntries([{src:t,sighting:i}],void 0)}get sightingData(){return this.entries.find(t=>t.src===this.currentSrc)?.sighting}set sightingData(t){this.startPending=!0,this.currentSrc="",this.setEntries([{src:"",sighting:t}],void 0)}get observerUrls(){return this.entries.map(t=>t.src)}set observerUrls(t){this.loadObserverUrls(t)}async loadObserverUrls(t,e){const i=await Promise.all(t.map(async n=>({src:n,sighting:await Gc.json(n)})));this.setEntries(i,e)}setEntries(t,e){this.entries=t,this.caseSource=e,this.toolbarElement.hidden=t.length===0;const i=t.length>1;this.observerSelect.hidden=!i,this.observerText.hidden=i,this.observerSelect.innerHTML="";for(const s of t){const r=document.createElement("option");r.value=s.src,r.textContent=this.observerDisplayName(this.plain(s).observer)??this.messages.unnamedObserver.replace("{n}",String(t.indexOf(s)+1)),this.observerSelect.appendChild(r)}const n=t.find(s=>s.src===this.currentSrc)??t[0];n?this.selectObserver(n.src):this.updateAccountLine()}editorUrl(){if(!this.currentSrc)return Vf;const t=new URL(this.currentSrc,location.href),e=this.caseSource;return e?`${Vf}?file=${encodeURIComponent(e.url)}&track=${encodeURIComponent(this.shownTrackUrl()??t.href)}`:`${Vf}?file=${encodeURIComponent(t.href)}`}get editorHref(){return this.editorUrl()}shownTrackUrl(){const t=this.caseSource,e=this.entries.find(s=>s.src===this.currentSrc),i=/^case-(\d+)$/.exec(this.interpretationSelect.value);if(!t||!e||!i)return;const n=cs.interpretationEvents(t.json,this.plain(e).id)[Number(i[1])];return n?.url?new URL(n.url,t.url).href:void 0}embedMarkupFor(t){const e=t==="edit"?"rr0-sighting-editor":"rr0-sighting",i=new URL(`${e}.mjs`,import.meta.url).href,n=this.currentSrc?new URL(this.currentSrc,location.href).href:"",s=t==="replay"?this.replayAttributes().map(([r,o])=>o===""?` ${r}`:` ${r}="${o}"`).join(""):"";return`<script type="module" src="${i}"><\/script>
8761
+ <${e} src="${n}"${s}></${e}>`}refreshEmbedMarkup(){const t=this.embedMarkupFor(this.embedEditRadio.checked?"edit":"replay");this.embedMarkup.value=t,this.shareCodeEditor&&(this.shareCodeEditor.text=t)}async copyText(t,e,i){try{await navigator.clipboard.writeText(t),i.textContent=this.messages.embedCopied,window.setTimeout(()=>i.textContent=this.messages.embedCopy,1500)}catch{e.select()}}async copyEmbedMarkup(){await this.copyText(this.shareCodeEditor?.text??this.embedMarkup.value,this.embedMarkup,this.embedCopyButton)}playUrl(){const t=this.replayQuery().join("&");return this.currentSrc?`${jh}/play/?file=${encodeURIComponent(new URL(this.currentSrc,location.href).href)}${t&&"&"+t}`:`${jh}/play/${t&&"?"+t}`}replayAttributes(){const t=this.shareOptions,e=[];return this.shareStartSeconds!==void 0&&e.push([kh,String(this.shareStartSeconds)]),t.labels.input.checked&&e.push(["show-labels",""]),t.map.input.checked&&e.push([ks,""]),t.milestones.input.checked||e.push([Fs,""]),t.compare.input.checked&&e.push([Nh,""]),e}replayQuery(){const t=this.shareOptions,e=[];return this.shareStartSeconds!==void 0&&e.push(`t=${this.shareStartSeconds}`),t.labels.input.checked||e.push("labels=0"),t.map.input.checked&&e.push("map=1"),t.milestones.input.checked||e.push("moments=0"),t.compare.input.checked&&e.push("compare=1"),e}get shareStartSeconds(){const t=Math.floor(Number(this.shareStart.value));return this.shareStartOn.checked&&Number.isFinite(t)&&t>=0?t:void 0}refreshShareLinks(){const t=this.embedEditRadio.checked;this.shareReplayOptions.disabled=t,this.shareLink.value=t?this.editorUrl():this.playUrl(),this.fitShareLink(),this.refreshEmbedMarkup()}fitShareLink(){this.shareLink.style.height="auto",this.shareLink.style.height=`${this.shareLink.scrollHeight}px`}shareCodeEditor;shareCodeLoading;loadShareCode(){this.shareCodeLoading??=je(async()=>{const{ShareCodeEditor:t}=await import("./ShareCodeEditor-C53SBK2N.js");return{ShareCodeEditor:t}},[],import.meta.url).then(({ShareCodeEditor:t})=>{this.shareCodeEditor=new t(this.embedCode,this.embedMarkup.value,e=>{this.embedMarkup.value=e},this.messages.embed),this.embedMarkup.hidden=!0}).catch(()=>{this.shareCodeLoading=void 0})}openShare(){const t=this.sceneElement.ufoElement;this.shareStart.max=String(Math.floor(t.seekableDuration/1e3)),this.shareStart.value=String(Math.floor(t.currentTime/1e3)),this.shareStartOn.checked=!1,this.shareOptions.labels.input.checked=this.labelsShown,this.shareOptions.map.input.checked=t.observerMapOpen,this.shareOptions.milestones.input.checked=t.milestonesVisible,this.shareOptions.compare.input.checked=this.sceneElement.compareAccount,this.refreshShareLinks(),this.showShareView("link"),typeof this.shareDialog.showModal=="function"?this.shareDialog.showModal():this.shareDialog.setAttribute("open",""),this.fitShareLink(),this.shareLink.select()}closeShare(){typeof this.shareDialog.close=="function"?this.shareDialog.close():this.shareDialog.removeAttribute("open")}showShareView(t){this.shareLinkBox.hidden=t!=="link",this.shareEmbed.hidden=t!=="embed",this.shareLinkOption.setAttribute("aria-pressed",String(t==="link")),this.shareEmbedOption.setAttribute("aria-pressed",String(t==="embed")),t==="embed"?this.loadShareCode():this.fitShareLink()}offerInterpretations(t){const e=this.offeredFor===t.sighting,i=this.interpretationSelect.value;this.offeredFor=t.sighting,this.interpretationToken++,this.interpretationLoaders=new Map,this.interpretationSelect.innerHTML="";const n=(l,h,u)=>{const d=document.createElement("option");d.value=l,d.textContent=h,this.interpretationSelect.appendChild(d),this.interpretationLoaders.set(l,u)},s=t===this.entries.find(l=>l.src===this.currentSrc)?this.sceneElement.ufoElement.sighting.interpretation:void 0;n(Gf,this.messages.account,()=>Promise.resolve(s));const r=this.caseSource;r&&cs.interpretationEvents(r.json,this.plain(t).id).forEach((l,h)=>{const u=this.said.read(l.title)??`#${h+1}`,d=(l.by??[]).map(f=>this.agentName(f)).filter(Boolean).join(", ");n(`case-${h}`,d?this.messages.interpretationBy.replace("{title}",u).replace("{by}",d):u,()=>cs.interpretationOf(l,r.url,f=>Gc.json(f)))});const c=e&&[...this.interpretationSelect.options].some(l=>l.value===i)?i:Gf;this.interpretationSelect.value=c,c===Gf?this.sceneElement.interpretation!==s&&(this.sceneElement.interpretation=s):this.sceneElement.interpretation||this.chooseInterpretation(c),this.interpretationChoice.hidden=this.interpretationSelect.options.length<2,this.showConfrontation(this.sceneElement.confrontation),this.updateCompareButton()}setComparing(t){this.sceneElement.compareAccount=t,this.updateCompareButton(),this.showConfrontation(this.sceneElement.confrontation)}updateCompareButton(){const t=this.sceneElement.compareAccount;this.compareButton.hidden=!this.sceneElement.interpretation,this.compareButton.setAttribute("aria-pressed",String(t));const e=t?this.messages.hideComparison:this.messages.showComparison;this.compareButton.title=e,this.compareButton.setAttribute("aria-label",e)}static DATE_LOCALES={en:"en-US",fr:"fr-FR",es:"es-ES",it:"it-IT"};get colon(){return this.language==="fr"?" : ":": "}async chooseInterpretation(t){const e=++this.interpretationToken,i=this.interpretationLoaders.get(t),n=i?await i().catch(s=>{console.warn(`<rr0-sighting>: could not read interpretation "${t}":`,s)}):void 0;e===this.interpretationToken&&(this.sceneElement.interpretation=n,this.editLink.href=this.editorUrl(),this.dispatchEvent(new CustomEvent("interpretationchange",{detail:{track:this.shownTrackUrl()}})),this.updateCompareButton(),this.showConfrontation(this.sceneElement.confrontation))}agentName(t){if("people"in t){const[e,...i]=t.people.replace(/([a-z])([A-Z])/g,"$1 $2").split(" ");return[...i,e].join(" ")}return"org"in t?t.org.replace(/([a-z])([A-Z])/g,"$1 $2"):this.observerDisplayName(t)??""}showConfrontation(t){this.confrontationList.innerHTML="",this.confrontationElement.hidden=!this.sceneElement.interpretation||!this.sceneElement.compareAccount;const e=new Intl.NumberFormat(this.language,{maximumFractionDigits:1,minimumFractionDigits:1}),i=new Intl.NumberFormat(this.language,{maximumFractionDigits:2,minimumFractionDigits:2});for(const n of t){const s=document.createElement("li");s.append(`${this.said.read(n.title)??n.sourceId}${this.colon}`);const r=[];n.separationDeg!==void 0&&r.push([this.messages.confrontationDirection.replace("{deg}",e.format(n.separationDeg)),n.disagreements.includes("direction")]),n.widthRatio!==void 0&&r.push([this.messages.confrontationWidth.replace("{ratio}",i.format(n.widthRatio)),n.disagreements.includes("width")]),n.heightRatio!==void 0&&r.push([this.messages.confrontationHeight.replace("{ratio}",i.format(n.heightRatio)),n.disagreements.includes("height")]),r.forEach(([o,c],l)=>{l>0&&s.append(" · ");const h=document.createElement("span");h.textContent=o,c&&(h.className="disagrees"),s.append(h)}),this.confrontationList.appendChild(s)}}startPending=!1;selectObserver(t){const e=this.entries.find(i=>i.src===t);if(e){if(this.currentSrc=t,this.observerSelect.value=t,this.sceneElement.documentUrl=e.src?new URL(e.src,location.href).href:void 0,this.sceneElement.holdForNewScene(),this.sceneElement.sightingData=e.sighting,this.startPending){this.startPending=!1;const i=Number(this.getAttribute(kh));this.hasAttribute(kh)&&Number.isFinite(i)&&(this.sceneElement.ufoElement.currentTime=Math.max(0,i)*1e3)}this.offerInterpretations(e),this.updateAccountLine(),this.refreshParamSummary(),this.runAssessments(),this.infoOpen&&this.populateInfoPanel(),this.dispatchEvent(new CustomEvent(iI,{detail:{src:t}}))}}async runAssessments(){const t=++this.assessmentToken,e=await new Hx(this.messages).read(this.sceneElement.ufoElement.sighting);t===this.assessmentToken&&(this.assessmentEntries=e.entries,this.refreshParamSummary())}updateAccountLine(){const t=this.entries.find(n=>n.src===this.currentSrc),e=t?this.observerDisplayName(this.plain(t).observer):void 0,i=e!==void 0||this.entries.length>1;this.accountElement.hidden=!i,this.observerText.textContent=e??"",this.editLink.hidden=!this.currentSrc,this.editLink.href=this.editorUrl(),this.editLink.title=this.messages.editThisObservation,this.editLink.setAttribute("aria-label",this.messages.editThisObservation)}observerDisplayName(t){if(!t)return;const e=[...t.firstNames??[],t.lastName].filter(Boolean).join(" ");return t.title||e||t.id}plainRecordings=new WeakMap;plain(t){return this.stripped(t).recording}stripped(t){let e=this.plainRecordings.get(t.sighting);return e||(e=hn.strip(t.sighting),this.plainRecordings.set(t.sighting,e)),e}basisOf(t,e){const i=this.stripped(t).provenance,n={stated:0,derived:1,assumed:2},s=i.paths().filter(c=>e.some(l=>c===l||c.startsWith(`${l}.`))).map(c=>i.at(c)),r=s.reduce((c,l)=>n[l.basis]>n[c]?l.basis:c,"stated"),o=s.filter(c=>c.basis===r&&c.rationale).map(c=>c.rationale);return{basis:r,rationales:o}}formatDate(t){const e=t.place?.[0],i=ra(t.time??{},e?.lng??0,t.utcOffsetHours);if(!i)return;const n=i.getTime()+this.utcOffsetHoursOf(t,e?.lng??0)*36e5;if(Number.isFinite(n))return new Intl.DateTimeFormat(qo.DATE_LOCALES[this.language],{dateStyle:"long",timeStyle:"short",timeZone:"UTC"}).format(new Date(n))}utcOffsetHoursOf(t,e){return t.utcOffsetHours??Math.round(e/15)}formatLocation(t){const e=t.place?.[0];if(e)return`${e.lat.toFixed(4)}, ${e.lng.toFixed(4)}`}toggleInfoPanel(){const t=!this.infoOpen;if(this.supportsPopover){const e=this.infoPanel.matches(":popover-open");t&&!e?this.infoPanel.showPopover():!t&&e&&this.infoPanel.hidePopover();return}t&&this.bringInfoButtonIntoView(),this.syncInfoOpen(t),this.infoPanel.hidden=!t,t?document.addEventListener("click",this.handleOutsideClick):document.removeEventListener("click",this.handleOutsideClick)}bringInfoButtonIntoView(){const t=this.infoButton.getBoundingClientRect(),e=window.innerHeight||document.documentElement.clientHeight;t.top>=0&&t.bottom<=e||this.infoButton.scrollIntoView({block:"center"})}syncInfoOpen(t){t!==this.infoOpen&&(this.infoOpen=t,this.infoButton.setAttribute("aria-expanded",String(t)),t?this.supportsPopover||this.populateInfoPanel():(this.creditsOpen=!1,this.infoCreditsList.hidden=!0,this.infoCreditsToggle.setAttribute("aria-expanded","false")))}handleOutsideClick=t=>{const e=t.composedPath();!e.includes(this.infoPanel)&&!e.includes(this.infoButton)&&this.toggleInfoPanel()};toggleCredits(){this.creditsOpen=!this.creditsOpen,this.infoCreditsList.hidden=!this.creditsOpen,this.infoCreditsToggle.setAttribute("aria-expanded",String(this.creditsOpen)),this.creditsOpen&&this.revealInPanel(this.infoCreditsList)}revealInPanel(t){t.scrollIntoView?.({block:"nearest"})}get showLabels(){return this.labelsShown}set showLabels(t){this.toggleAttribute("show-labels",t)}applyLabels(t){this.labelsShown=t,this.syncLabelsToggle(),this.refreshParamSummary(),this.populateInfoPanel()}syncLabelsToggle(){this.labelsToggle.textContent=this.labelsShown?this.messages.hideLabels:this.messages.showLabels,this.labelsToggle.setAttribute("aria-pressed",String(this.labelsShown))}refreshParamSummary(){if(this.paramSummary.hidden=!this.labelsShown,!this.labelsShown){this.paramSummary.replaceChildren(),this.summarySignature="";return}const t=this.sceneElement.ufoElement.sighting,e=[...this.summaryBuilder.entriesFor(t,this.sceneElement.ufoElement.currentTime,{roadGradeDeg:this.sceneElement.roadGradeDeg}),...this.assessmentEntries],i=e.map(r=>`${r.field}=${r.label}=${r.value}${r.unit}${r.full??""}${r.fromSource?"*":""}`).join("|");if(i===this.summarySignature)return;this.summarySignature=i;const n=[];let s;for(const r of e){s&&s.group!==r.group&&(s=void 0);const o=r.group==="summary"?this.messages.summaryGroup:r.group==="observer"?this.messages.observerGroup:r.group in this.messages.summaryGroups?this.messages.summaryGroups[r.group]:r.group==="assessment"?this.messages.assessmentGroup:void 0;if(o!==void 0&&!s){const l=document.createElement("span");l.className="param-nest";const h=document.createElement("span");h.className="param-nest-label",h.textContent=o,l.append(h),s={group:r.group,element:l},n.push(l)}const c=this.paramItem(r);s?s.element.append(c):n.push(c)}this.paramSummary.replaceChildren(...n),this.syncDescription(e)}openDescription;syncDescription(t){this.openDescription!==void 0&&!t.some(e=>e.full===this.openDescription)&&(this.openDescription=void 0),iM.sync(this.paramSummary,this.openDescription,this.messages.summaryDescription,this.messages.closeDescription,()=>{this.openDescription=void 0,this.syncDescription(t)})}paramItem(t){const e=document.createElement("span");if(e.className=t.fromSource?"param-label from-source":"param-label",t.full!==void 0){e.classList.add("describable"),e.tabIndex=0,e.setAttribute("role","button");const s=()=>{this.openDescription=t.full,this.syncDescription([t])};e.addEventListener("click",s),e.addEventListener("keydown",r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),s())})}const i=document.createElement("span");if(i.className="param-label-label",i.textContent=`${t.label} `,e.append(i),t.color!==void 0){const s=document.createElement("span");s.className="param-label-swatch",s.style.background=t.color,e.append(s)}const n=document.createElement("span");return n.className="param-label-value",n.textContent=t.unit===""?t.value:`${t.value} ${t.unit}`,e.append(n),e}populateInfoPanel(){const t=this.entries.find(e=>e.src===this.currentSrc);if(this.infoObservationList.innerHTML="",t){const e=this.caseSource&&(this.caseSource.json.title??this.caseSource.json.id);if(e&&this.appendInfoRow(this.infoObservationList,this.messages.case,e),!this.labelsShown){const s=this.formatDate(this.plain(t));s&&this.appendInfoRow(this.infoObservationList,this.messages.date,s,this.basisOf(t,qo.DATE_PATHS));const r=this.formatLocation(this.plain(t));r&&this.appendInfoRow(this.infoObservationList,this.messages.location,r,this.basisOf(t,qo.PLACE_PATHS))}const i=this.said.read(this.plain(t).description);i&&!this.labelsShown&&this.appendInfoRow(this.infoObservationList,this.messages.description,i);for(const s of this.plain(t).sources??[])this.appendInfoSource(this.infoObservationList,this.messages.source,s);const n=this.plain(t).tags;!this.labelsShown&&n&&n.length>0&&this.appendInfoRow(this.infoObservationList,this.messages.tags,n.map(s=>this.tags.name(s)).join(", "))}this.refreshEmbedMarkup(),this.infoAppLink.href=jh,this.infoAppLink.textContent="UFO@home v0.105.3",rn.fill(this.infoCreditsList,this.sceneElement)}appendInfoSource(t,e,i){const n=document.createElement("dt");n.textContent=e;const s=document.createElement("dd"),r=i.title??i.url??"";if(i.url&&/^https?:\/\//i.test(i.url)){const c=document.createElement("a");c.href=i.url,c.target="_blank",c.rel="noopener noreferrer",c.textContent=r,s.appendChild(c)}else s.append(r);const o=[i.authors?.join(", "),i.publication?.publisher,i.publication?.time,i.index].filter(Boolean);o.length>0&&s.append(`, ${o.join(", ")}`),t.append(n,s)}static DATE_PATHS=["time","utcOffsetHours","timeZone"];static PLACE_PATHS=["place.0"];appendInfoRow(t,e,i,n){const s=document.createElement("dt");s.textContent=e;const r=document.createElement("dd");if(r.textContent=i,n){const o=document.createElement("span");o.className=`basis basis-${n.basis}`,o.textContent=this.messages.basis[n.basis],n.rationales.length>0&&(o.title=n.rationales.join(`
8762
8762
  `)),r.append(" ",o)}t.appendChild(s),t.appendChild(r)}}const tM="rr0-sighting",iI="observerchange",eM="rr0-eyeobserver";class nI extends qo{}function sI(){hy(),customElements.get(tM)||customElements.define(tM,qo),customElements.get(eM)||customElements.define(eM,nI)}sI();export{h1 as $,Oa as A,Qi as B,st as C,bb as D,rI as E,ve as F,Ee as G,oI as H,MI as I,aI as J,wl as K,Lx as L,At as M,vI as N,pI as O,F0 as P,uw as Q,be as R,tl as S,Xn as T,cw as U,R as V,fI as W,Au as X,un as Y,gI as Z,u2 as _,on as a,hI as a0,Sn as a1,Yg as a2,ti as a3,mI as a4,yI as a5,QM as a6,Aa as a7,kl as a8,wd as a9,Xr as aA,Sl as aB,Qb as aa,de as ab,Ue as ac,Qo as ad,s0 as ae,Bi as af,fr as ag,rw as ah,Nr as ai,Le as aj,lI as ak,uI as al,i2 as am,dI as an,yn as ao,ps as ap,e2 as aq,s1 as ar,QS as as,wu as at,N0 as au,Hi as av,l2 as aw,Yp as ax,qp as ay,me as az,xI as b,xh as c,Iu as d,dr as e,Me as f,As as g,bt as h,vt as i,ue as j,bI as k,ne as l,cI as m,ae as n,In as o,rb as p,Yh as q,pr as r,ra as s,Mc as t,si as u,te as v,wn as w,bn as x,BD as y,pm as z};