@rr0/ufoathome 0.19.0 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -290,7 +290,7 @@ input[type=range] {
|
|
|
290
290
|
pointer-events: none;
|
|
291
291
|
white-space: nowrap;
|
|
292
292
|
}
|
|
293
|
-
`;class Kl{static MOON_ANGULAR_WIDTH_DEG=.5237;static angularWidthDeg(e){return 2*Math.atan(e.sizeM/(2*e.distanceM))*180/Math.PI}static widthPx(e,t,n){return t*e.sizeM/(2*e.distanceM*Math.tan(n*Math.PI/360))}static pxToDeg(e,t,n){return 2*Math.atan(e*Math.tan(n*Math.PI/360)/t)*180/Math.PI}static inMoons(e){return e/Kl.MOON_ANGULAR_WIDTH_DEG}static lerp(e,t,n){if(!(!e||!t))return{sizeM:e.sizeM+(t.sizeM-e.sizeM)*n,distanceM:e.distanceM+(t.distanceM-e.distanceM)*n}}}function fd(i,e,t){const{bounds:n}=i;return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function jt(i,e,t){return i+(e-i)*t}function Cc(i){const e=/^#([0-9a-f]{6})$/i.exec(i);if(!e)return;const t=parseInt(e[1],16);return[t>>16&255,t>>8&255,t&255]}function pd(i){return`#${i.map(e=>Math.round(e).toString(16).padStart(2,"0")).join("")}`}function md(i,e,t){const n=Cc(i),s=Cc(e);return!n||!s?t<1?i:e:pd([jt(n[0],s[0],t),jt(n[1],s[1],t),jt(n[2],s[2],t)])}function gd(i,e,t){const n={x:jt(i.bounds.x,e.bounds.x,t),y:jt(i.bounds.y,e.bounds.y,t),width:jt(i.bounds.width,e.bounds.width,t),height:jt(i.bounds.height,e.bounds.height,t)},s=jt(i.angle,e.angle,t),r=jt(i.transparency,e.transparency,t),a=jt(i.haloScale,e.haloScale,t),o=md(i.color,e.color,t),l=Kl.lerp(i.physical,e.physical,t);return i.kind==="polygon"&&e.kind==="polygon"&&i.points.length===e.points.length?{...i,bounds:n,angle:s,transparency:r,haloScale:a,color:o,physical:l,behindCloud:t<1?i.behindCloud:e.behindCloud,points:i.points.map((c,h)=>({x:jt(c.x,e.points[h].x,t),y:jt(c.y,e.points[h].y,t)}))}:{...t<1?i:e,bounds:n,angle:s,transparency:r,haloScale:a,color:o,physical:l}}class xa{keyframes=[];order=[];groups=[];addKeyframe(e,t){const n=this.findInsertIndex(e);if(this.keyframes[n]?.t===e){const s=new Set(t.map(r=>r.sourceId));this.keyframes[n]={t:e,shapes:[...this.keyframes[n].shapes.filter(r=>!s.has(r.sourceId)),...t]}}else this.keyframes.splice(n,0,{t:e,shapes:[...t]});for(const s of t)this.order.includes(s.sourceId)||this.order.push(s.sourceId)}findInsertIndex(e){let t=0,n=this.keyframes.length;for(;t<n;){const s=t+n>>>1;this.keyframes[s].t<e?t=s+1:n=s}return t}getKeyframeAt(e){const t=this.findInsertIndex(e),n=this.keyframes[t];return n?.t===e?n:void 0}getShapeAt(e,t){return this.getKeyframeAt(e)?.shapes.find(n=>n.sourceId===t)?.shape}getLatestShapeAt(e,t){let n=this.findInsertIndex(e);for(this.keyframes[n]?.t!==e&&(n-=1);n>=0;n--){const s=this.keyframes[n].shapes.find(r=>r.sourceId===t);if(s)return s.shape}}getInterpolatedShapeAt(e,t){const n=this.findShapeAtOrBefore(e,t);if(n?.t===e)return n.shape;const s=this.findShapeAtOrAfter(e,t);return n?s?gd(n.shape,s.shape,(e-n.t)/(s.t-n.t)):n.shape:s?.shape}findShapeAtOrBefore(e,t){let n=this.findInsertIndex(e);for(this.keyframes[n]?.t!==e&&(n-=1);n>=0;n--){const s=this.keyframes[n].shapes.find(r=>r.sourceId===t);if(s)return{t:this.keyframes[n].t,shape:s.shape}}}findShapeAtOrAfter(e,t){for(let n=this.findInsertIndex(e);n<this.keyframes.length;n++){const s=this.keyframes[n].shapes.find(r=>r.sourceId===t);if(s)return{t:this.keyframes[n].t,shape:s.shape}}}hitTest(e,t,n,s){const r=this.sourceIds;for(let a=r.length-1;a>=0;a--){if(s?.has(r[a]))continue;const o=this.getInterpolatedShapeAt(e,r[a]);if(o&&fd(o,t,n))return{sourceId:r[a],shape:o}}}removeSource(e){for(let t=this.keyframes.length-1;t>=0;t--){const n=this.keyframes[t].shapes.filter(s=>s.sourceId!==e);n.length===0?this.keyframes.splice(t,1):n.length!==this.keyframes[t].shapes.length&&(this.keyframes[t]={t:this.keyframes[t].t,shapes:n})}this.order=this.order.filter(t=>t!==e),this.removeFromGroup(e)}group(e){if(!(e.length<2)){for(const t of e)this.removeFromGroup(t);this.groups.push([...e])}}ungroup(e){const t=this.groups.findIndex(n=>n.includes(e));t!==-1&&this.groups.splice(t,1)}groupMembers(e){return this.groups.find(t=>t.includes(e))}removeFromGroup(e){const t=this.groups.findIndex(s=>s.includes(e));if(t===-1)return;const n=this.groups[t].filter(s=>s!==e);n.length<2?this.groups.splice(t,1):this.groups[t]=n}bringToFront(e){const t=this.order.indexOf(e);t!==-1&&(this.order.splice(t,1),this.order.push(e))}sendToBack(e){const t=this.order.indexOf(e);t!==-1&&(this.order.splice(t,1),this.order.unshift(e))}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(e){const t=new xa;for(const n of e.keyframes)t.addKeyframe(n.t,n.shapes);if(e.order){const n=t.order.filter(s=>!e.order.includes(s));t.order=[...e.order,...n]}return e.groups&&(t.groups=e.groups.map(n=>n.filter(s=>t.order.includes(s))).filter(n=>n.length>=2)),t}}function _d(i,e,t){return Math.max(e,Math.min(t,i))}function vd(i,e,t){const n=((e-i)%360+540)%360-180;return((i+n*t)%360+360)%360}function Ss(i,e,t){return i+(e-i)*t}function xd(i,e,t){return{lat:i.lat===void 0||e.lat===void 0?void 0:Ss(i.lat,e.lat,t),lng:i.lng===void 0||e.lng===void 0?void 0:Ss(i.lng,e.lng,t),elevationM:Ss(i.elevationM,e.elevationM,t),headingDeg:i.headingDeg===void 0||e.headingDeg===void 0?void 0:vd(i.headingDeg,e.headingDeg,t),pitchDeg:Ss(i.pitchDeg,e.pitchDeg,t),fovDeg:Ss(i.fovDeg,e.fovDeg,t)}}class Ys{keyframes=[];addKeyframe(e,t){const n=this.findInsertIndex(e);this.keyframes[n]?.t===e?this.keyframes[n]={t:e,pose:t}:this.keyframes.splice(n,0,{t:e,pose:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}findInsertIndex(e){let t=0,n=this.keyframes.length;for(;t<n;){const s=t+n>>>1;this.keyframes[s].t<e?t=s+1:n=s}return t}getLatestPoseAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].pose:void 0}getInterpolatedPoseAt(e){const t=this.findInsertIndex(e),n=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(n?.t===e)return n.pose;const s=this.keyframes[t]?.t===e?void 0:this.keyframes[t];return n?s?xd(n.pose,s.pose,_d((e-n.t)/(s.t-n.t),0,1)):n.pose:s?.pose}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(e){const t=new Ys;for(const n of e.keyframes)t.addKeyframe(n.t,n.pose);return t}}function ys(i,e,t){return i+(e-i)*t}function Md(i,e,t){const n=((e-i)%360+540)%360-180;return((i+n*t)%360+360)%360}function Sd(i,e,t){return Math.max(e,Math.min(t,i))}function yd(i,e,t){return{cloudCover:ys(i.cloudCover,e.cloudCover,t),cloudDarkness:ys(i.cloudDarkness,e.cloudDarkness,t),cloudBaseM:i.cloudBaseM===void 0||e.cloudBaseM===void 0?void 0:ys(i.cloudBaseM,e.cloudBaseM,t),precipitationType:t<1?i.precipitationType:e.precipitationType,precipitationIntensity:ys(i.precipitationIntensity,e.precipitationIntensity,t),windDirectionDeg:Md(i.windDirectionDeg,e.windDirectionDeg,t),windSpeed:ys(i.windSpeed,e.windSpeed,t),storm:t<1?i.storm:e.storm}}class Zs{keyframes=[];addKeyframe(e,t){const n=this.findInsertIndex(e);this.keyframes[n]?.t===e?this.keyframes[n]={t:e,weather:t}:this.keyframes.splice(n,0,{t:e,weather:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}findInsertIndex(e){let t=0,n=this.keyframes.length;for(;t<n;){const s=t+n>>>1;this.keyframes[s].t<e?t=s+1:n=s}return t}getLatestWeatherAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].weather:void 0}getInterpolatedWeatherAt(e){const t=this.findInsertIndex(e),n=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(n?.t===e)return n.weather;const s=this.keyframes[t]?.t===e?void 0:this.keyframes[t];return n?s?yd(n.weather,s.weather,Sd((e-n.t)/(s.t-n.t),0,1)):n.weather:s?.weather}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(e){const t=new Zs;for(const n of e.keyframes)t.addKeyframe(n.t,n.weather);return t}}class $s{keyframes=[];addKeyframe(e,t){const n=this.findInsertIndex(e);this.keyframes[n]?.t===e?this.keyframes[n]={t:e,sound:t}:this.keyframes.splice(n,0,{t:e,sound:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}getLatestSoundAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].sound:void 0}getInterpolatedSoundAt(e){const t=this.findInsertIndex(e),n=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(n?.t===e)return n.sound;const s=this.keyframes[t]?.t===e?void 0:this.keyframes[t];if(!n)return s?.sound;if(!s)return n.sound;const r=(e-n.t)/(s.t-n.t);return this.lerp(n.sound,s.sound,Math.max(0,Math.min(1,r)))}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(e){const t=new $s;for(const n of e.keyframes)t.addKeyframe(n.t,n.sound);return t}lerp(e,t,n){return{kind:n<1?e.kind:t.kind,volume:e.volume+(t.volume-e.volume)*n,pitchHz:e.pitchHz+(t.pitchHz-e.pitchHz)*n,src:n<1?e.src:t.src}}findInsertIndex(e){let t=0,n=this.keyframes.length;for(;t<n;){const s=t+n>>>1;this.keyframes[s].t<e?t=s+1:n=s}return t}}const Po=1e3,Nu={cloudCover:0,cloudDarkness:0,precipitationType:"none",precipitationIntensity:0,windDirectionDeg:0,windSpeed:0,storm:!1},Ed=100,bd={kind:"none",volume:0,pitchHz:Ed};function Io(i){if(i.year!==void 0)return Date.UTC(i.year,(i.month??1)-1,i.day??1,i.hour??0,i.minute??0,i.second??0)}function Pc(i){return(((i.day??0)*24+(i.hour??0))*60+(i.minute??0))*6e4+(i.second??0)*1e3}const Td=["year","month","day","hour","minute"],Ad=["day","hour","minute"];function Ic(i,e){return e.filter(t=>i[t]!==void 0).join(",")}function wd(i){if(i.durationSeconds!==void 0)return i.durationSeconds*1e3;if(!i.time||!i.endTime)return;const e=i.time.year!==void 0&&i.endTime.year!==void 0,t=e?Td:Ad,n=Ic(i.time,t);if(!(n===""||n!==Ic(i.endTime,t)))return e?Io(i.endTime)-Io(i.time):Pc(i.endTime)-Pc(i.time)}class Ma{constructor(e,t,n,s,r,a,o,l,c=[],h){this.event=e,this.timeline=t,this.witnessTrack=n,this.weatherTrack=s,this.soundTrack=r,this.witness=a,this.caseId=o,this.weather=l,this.decor=c,this.weatherSource=h}static create(e,t,n){return new Ma({eventType:"sighting",time:e,place:t},new xa,new Ys,new Zs,new $s,n)}}const Rd=0,Cd=0,Pd=60;function Dc(i,e){const t=i.witnessTrack.getInterpolatedPoseAt(e);if(t)return t;const n=i.event.place?.[0];if(n)return{lat:n.lat,lng:n.lng,elevationM:Rd,headingDeg:void 0,pitchDeg:Cd,fovDeg:Pd}}function Lc(i,e){return i.weatherTrack.getInterpolatedWeatherAt(e)??i.weather??Nu}function Id(i,e){return i.soundTrack.getInterpolatedSoundAt(e)??bd}class Dd{constructor(e,t){this.timeline=e,this.onFrame=t}rafId=null;state="stopped";currentT=0;lastWallTime=0;playbackRate=1;loop=!1;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 e=()=>{if(this.state!=="playing")return;const t=performance.now();if(this.currentT+=(t-this.lastWallTime)*this.playbackRate,this.lastWallTime=t,this.currentT>=this.seekableDuration){if(this.loop&&this.seekableDuration>0){this.currentT%=this.seekableDuration,this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e);return}this.currentT=this.seekableDuration,this.stop(),this.resolveFrame(this.currentT);return}this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}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(e){this.currentT=Math.max(0,Math.min(e,this.seekableDuration)),this.resolveFrame(this.currentT)}get playbackState(){return this.state}get time(){return this.currentT}resolveFrame(e){const t=new Map;for(const n of this.timeline.sourceIds){const s=this.timeline.getInterpolatedShapeAt(e,n);s&&t.set(n,s)}this.onFrame(e,t)}}const Uu=["nw","n","ne","e","se","s","sw","w"],Ld=24,ar=8,Nd=3,Ud=8;function or(i,e,t){const n=i.x-e.x,s=i.y-e.y,r=Math.cos(t),a=Math.sin(t);return{x:e.x+n*r-s*a,y:e.y+n*a+s*r}}function Es(i){return{x:i.x+i.width/2,y:i.y+i.height/2}}const Fd={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 qt{static handlePointsFor(e){const{x:t,y:n,width:s,height:r}=e.bounds,a={nw:{x:t,y:n},n:{x:t+s/2,y:n},ne:{x:t+s,y:n},e:{x:t+s,y:n+r/2},se:{x:t+s,y:n+r},s:{x:t+s/2,y:n+r},sw:{x:t,y:n+r},w:{x:t,y:n+r/2},rotate:{x:t+s/2,y:n-Ld}},o=Es(e.bounds),l={};for(const c of Object.keys(a))l[c]=or(a[c],o,e.angle);return l}static hitTestHandle(e,t,n=8,s=[...Uu,"rotate"]){const r=qt.handlePointsFor(e);for(const a of s)if(Math.hypot(t.x-r[a].x,t.y-r[a].y)<=n)return a}static HANDLE_DIRECTION_DEG={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315};static resizeAxisFor(e,t){const s=((qt.HANDLE_DIRECTION_DEG[e]+t*180/Math.PI)%180+180)%180/45,r=["ew","nwse","ns","nesw"];return r[Math.round(s)%r.length]}static resizeBounds(e,t,n,s){const r=Es(e),a=or(s,r,-t),{x:o,y:l,width:c,height:h}=e,d=Fd[n];let u=o,p=l,g=o+c,x=l+h;return d.left&&(u=Math.min(a.x,g-ar)),d.right&&(g=Math.max(a.x,u+ar)),d.top&&(p=Math.min(a.y,x-ar)),d.bottom&&(x=Math.max(a.y,p+ar)),{x:u,y:p,width:g-u,height:x-p}}static resizeShape(e,t,n){if(t==="rotate")throw new Error("resizeShape does not accept the rotate handle");const{width:s,height:r}=e.bounds,a=qt.resizeBounds(e.bounds,e.angle,t,n);if(e.kind==="oval")return{...e,bounds:a};const o=s===0?1:a.width/s,l=r===0?1:a.height/r;return{...e,bounds:a,points:e.points.map(c=>({x:c.x*o,y:c.y*l}))}}static rotateShape(e,t){const n=Es(e.bounds),s=Math.atan2(t.y-n.y,t.x-n.x)+Math.PI/2;return{...e,angle:s}}static groupBoundsFor(e){const t=Math.min(...e.map(a=>a.x)),n=Math.min(...e.map(a=>a.y)),s=Math.max(...e.map(a=>a.x+a.width)),r=Math.max(...e.map(a=>a.y+a.height));return{x:t,y:n,width:s-t,height:r-n}}static vertexPointsFor(e){const t=Es(e.bounds);return e.points.map(n=>or({x:e.bounds.x+n.x,y:e.bounds.y+n.y},t,e.angle))}static hitTestVertex(e,t,n=Ud){const s=qt.vertexPointsFor(e);let r,a=n;return s.forEach((o,l)=>{const c=Math.hypot(t.x-o.x,t.y-o.y);c<=a&&(a=c,r=l)}),r}static toLocalPoint(e,t){const n=Es(e.bounds),s=or(t,n,-e.angle);return{x:s.x-e.bounds.x,y:s.y-e.bounds.y}}static moveVertex(e,t,n){const s=e.points.map((d,u)=>u===t?qt.toLocalPoint(e,n):d),r=Math.min(...s.map(d=>d.x)),a=Math.min(...s.map(d=>d.y)),o=Math.max(...s.map(d=>d.x)),l=Math.max(...s.map(d=>d.y)),c={x:e.bounds.x+r,y:e.bounds.y+a,width:o-r,height:l-a},h=s.map(d=>({x:d.x-r,y:d.y-a}));return{...e,bounds:c,points:h}}static insertVertexNear(e,t){const n=qt.toLocalPoint(e,t),{points:s}=e;let r=s.length-1,a=1/0;for(let l=0;l<s.length;l++){const c=s[l],h=s[(l+1)%s.length],d=qt.distanceToSegment(n,c,h);d<a&&(a=d,r=l)}const o=[...s.slice(0,r+1),n,...s.slice(r+1)];return{...e,points:o}}static distanceToSegment(e,t,n){const s=n.x-t.x,r=n.y-t.y,a=s*s+r*r,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*s+(e.y-t.y)*r)/a)),l=t.x+o*s,c=t.y+o*r;return Math.hypot(e.x-l,e.y-c)}static deleteVertex(e,t){return e.points.length<=Nd?e:{...e,points:e.points.filter((n,s)=>s!==t)}}}const Do=6,lr=Do/2,Od=20,Nc=4;class Bd{constructor(e){this.ctx=e}clear(e,t){this.ctx.clearRect(0,0,e,t)}paintShape(e){this.ctx.save(),this.ctx.globalAlpha=1-e.transparency,e.haloScale>0&&this.paintHalo(e),this.paintBase(e),this.ctx.restore(),e.selected&&this.paintSelectionHandles(e)}paintBase(e){if(this.ctx.fillStyle=e.color,this.ctx.beginPath(),e.kind==="oval"){const{x:t,y:n,width:s,height:r}=e.bounds,a=s/2,o=r/2;this.ctx.ellipse(t+a,n+o,a,o,e.angle,0,2*Math.PI)}else{const{x:t,y:n,width:s,height:r}=e.bounds;this.ctx.save(),this.ctx.translate(t+s/2,n+r/2),this.ctx.rotate(e.angle),this.ctx.translate(-s/2,-r/2),e.points.forEach((a,o)=>{o===0?this.ctx.moveTo(a.x,a.y):this.ctx.lineTo(a.x,a.y)}),this.ctx.closePath(),this.ctx.restore()}this.ctx.fill()}paintHalo(e){this.ctx.save(),this.ctx.shadowColor=e.color,this.ctx.shadowBlur=Od*e.haloScale,this.paintBase(e),this.ctx.restore()}paintSelectionHandles(e){this.paintHandleFrame(qt.handlePointsFor(e),{includeRotate:!0}),e.kind==="polygon"&&this.paintVertexHandles(e)}paintVertexHandles(e){this.ctx.fillStyle="#39f";for(const t of qt.vertexPointsFor(e))this.ctx.beginPath(),this.ctx.ellipse(t.x,t.y,Nc,Nc,0,0,2*Math.PI),this.ctx.fill()}paintMemberOutline(e){this.paintOutline(qt.handlePointsFor(e))}paintGroupHandles(e){this.paintHandleFrame(qt.handlePointsFor({bounds:e,angle:0}),{includeRotate:!0})}paintOutline(e){this.ctx.strokeStyle="lightgray",this.ctx.beginPath(),this.ctx.moveTo(e.nw.x,e.nw.y),this.ctx.lineTo(e.ne.x,e.ne.y),this.ctx.lineTo(e.se.x,e.se.y),this.ctx.lineTo(e.sw.x,e.sw.y),this.ctx.closePath(),this.ctx.stroke()}paintHandleFrame(e,{includeRotate:t}){this.paintOutline(e),this.ctx.fillStyle="lightgray";for(const n of Uu){const s=e[n];this.ctx.fillRect(s.x-lr,s.y-lr,Do,Do)}t&&(this.ctx.beginPath(),this.ctx.moveTo(e.n.x,e.n.y),this.ctx.lineTo(e.rotate.x,e.rotate.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.ellipse(e.rotate.x,e.rotate.y,lr+1,lr+1,0,0,2*Math.PI),this.ctx.fill())}}const Uc=.05,Fc=.08,Oc=2,Bc=3,zd=14,kd=.02;class Gd{context;voice;voiceToken=0;buffers=new Map;noiseBuffer;crackleBuffer;requested;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("SightingAudio: Web Audio unavailable, the sighting stays silent:",e);return}}this.context.state==="suspended"&&this.context.resume()}setSound(e){if(this.requested=e,!this.context)return;const t=this.keyFor(e);if(!t){this.silence();return}if(this.voice?.key!==t){this.stopVoice();const n=++this.voiceToken;t.startsWith("src:")?this.buildRecordedVoice(e.src,t,n):this.voice=this.buildSynthesizedVoice(e,t)}this.applyTo(this.voice,e)}silence(){this.voiceToken++,this.stopVoice()}dispose(){this.silence(),this.context?.close(),this.context=void 0,this.buffers.clear(),this.noiseBuffer=void 0,this.crackleBuffer=void 0}keyFor(e){if(!(e.volume<=0))return e.src?`src:${e.src}`:e.kind==="none"?void 0:e.kind}applyTo(e,t){const n=this.context;if(!e||!n)return;const s=n.currentTime;e.volumeParam.setTargetAtTime(Math.max(0,Math.min(1,t.volume))*e.gainScale,s,Uc);for(const{param:r,ratio:a}of e.pitch)r.setTargetAtTime(Math.min(t.pitchHz*a,n.sampleRate/2-1),s,Uc)}buildSynthesizedVoice(e,t){const n=this.context;if(n)switch(e.kind){case"hum":return this.buildHum(n,t);case"whistle":return this.buildWhistle(n,t);case"rumble":return this.buildRumble(n,t);case"crackle":return this.buildCrackle(n,t);default:return}}buildHum(e,t){const n=e.createOscillator();n.type="sawtooth";const s=e.createOscillator();s.type="sawtooth";const r=e.createBiquadFilter();r.type="lowpass",r.Q.value=1;const a=e.createGain();return a.gain.value=0,n.connect(r),s.connect(r),r.connect(a).connect(e.destination),n.start(),s.start(),{key:t,nodes:[r,a],sources:[n,s],volumeParam:a.gain,gainScale:.16,pitch:[{param:n.frequency,ratio:1},{param:s.frequency,ratio:1.006},{param:r.frequency,ratio:6}]}}buildWhistle(e,t){const n=e.createOscillator();n.type="sine";const s=e.createOscillator();s.type="sine",s.frequency.value=5;const r=e.createGain(),a=e.createGain();return a.gain.value=0,s.connect(r).connect(n.frequency),n.connect(a).connect(e.destination),n.start(),s.start(),{key:t,nodes:[r,a],sources:[n,s],volumeParam:a.gain,gainScale:.22,pitch:[{param:n.frequency,ratio:1},{param:r.gain,ratio:.012}]}}buildRumble(e,t){const n=e.createBufferSource();n.buffer=this.brownNoise(e),n.loop=!0;const s=e.createBiquadFilter();s.type="lowpass",s.Q.value=.8;const r=e.createGain();return r.gain.value=0,n.connect(s).connect(r).connect(e.destination),n.start(),{key:t,nodes:[s,r],sources:[n],volumeParam:r.gain,gainScale:1.4,pitch:[{param:s.frequency,ratio:1}]}}buildCrackle(e,t){const n=e.createBufferSource();n.buffer=this.whiteNoise(e),n.loop=!0;const s=e.createBiquadFilter();s.type="bandpass",s.Q.value=1.2;const r=e.createGain();r.gain.value=0;const a=e.createBufferSource();a.buffer=this.crackleEnvelope(e),a.loop=!0;const o=e.createGain();return o.gain.value=0,a.connect(o).connect(r.gain),n.connect(s).connect(r).connect(e.destination),n.start(),a.start(),{key:t,nodes:[s,r,o],sources:[n,a],volumeParam:o.gain,gainScale:.9,pitch:[{param:s.frequency,ratio:4}]}}async buildRecordedVoice(e,t,n){const s=this.context;if(!s)return;let r;try{r=await this.getBuffer(e)}catch(l){console.warn("SightingAudio: the recorded sound failed to load, staying silent:",l);return}if(n!==this.voiceToken||!this.context)return;const a=s.createBufferSource();a.buffer=r,a.loop=!0;const o=s.createGain();o.gain.value=0,a.connect(o).connect(s.destination),a.start(),this.voice={key:t,nodes:[o],sources:[a],volumeParam:o.gain,gainScale:1,pitch:[]},this.requested&&this.applyTo(this.voice,this.requested)}async getBuffer(e){const t=this.context;if(!t)throw new Error("SightingAudio: AudioContext not ready — resume() must be called first");let n=this.buffers.get(e);return n||(n=fetch(e).then(s=>{if(!s.ok)throw new Error(`Audio fetch failed (${s.status}): ${e}`);return s.arrayBuffer()}).then(s=>t.decodeAudioData(s)),this.buffers.set(e,n)),n}whiteNoise(e){if(!this.noiseBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*Oc),e.sampleRate),n=t.getChannelData(0);for(let s=0;s<n.length;s++)n[s]=Math.random()*2-1;this.noiseBuffer=t}return this.noiseBuffer}brownNoise(e){const t=e.createBuffer(1,Math.floor(e.sampleRate*Oc),e.sampleRate),n=t.getChannelData(0);let s=0,r=0;for(let a=0;a<n.length;a++)s=(s+.02*(Math.random()*2-1))/1.02,n[a]=s,r=Math.max(r,Math.abs(s));if(r>0)for(let a=0;a<n.length;a++)n[a]/=r;return t}crackleEnvelope(e){if(!this.crackleBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*Bc),e.sampleRate),n=t.getChannelData(0),s=Math.max(1,Math.floor(kd*e.sampleRate)),r=Math.round(Bc*zd);for(let a=0;a<r;a++){const o=Math.floor(Math.random()*n.length),l=.4+Math.random()*.6;for(let c=0;c<s&&o+c<n.length;c++)n[o+c]=Math.max(n[o+c],l*(1-c/s))}this.crackleBuffer=t}return this.crackleBuffer}stopVoice(){const e=this.voice,t=this.context;if(this.voice=void 0,!e||!t)return;const n=t.currentTime;e.volumeParam.cancelScheduledValues(n),e.volumeParam.setTargetAtTime(0,n,Fc/3);const s=n+Fc;for(const r of e.sources){r.onended=()=>{r.disconnect();for(const a of e.nodes)a.disconnect()};try{r.stop(s)}catch{r.disconnect();for(const a of e.nodes)a.disconnect()}}}}function Hd(i){return{version:1,time:i.event.time,endTime:i.event.endTime,durationSeconds:i.event.durationSeconds,utcOffsetHours:i.event.utcOffsetHours,timeZone:i.event.timeZone,place:i.event.place,witness:i.witness,caseId:i.caseId,description:i.event.description,tags:i.event.tags,timeline:i.timeline.toJSON(),witnessTrack:i.witnessTrack.toJSON(),weatherTrack:i.weatherTrack.toJSON(),soundTrack:i.soundTrack.toJSON(),weather:i.weather,decor:i.decor,weatherSource:i.weatherSource}}function Vd(i){return new Ma({eventType:"sighting",time:i.time,endTime:i.endTime,durationSeconds:i.durationSeconds,utcOffsetHours:i.utcOffsetHours,timeZone:i.timeZone,place:i.place,description:i.description,tags:i.tags},xa.fromJSON(i.timeline),i.witnessTrack?Ys.fromJSON(i.witnessTrack):new Ys,i.weatherTrack?Zs.fromJSON(i.weatherTrack):new Zs,i.soundTrack?$s.fromJSON(i.soundTrack):new $s,i.witness,i.caseId,i.weather,i.decor??[],i.weatherSource)}function Jl(i,e){for(const t of i){const n=t.toLowerCase().split("-")[0];if(e.includes(n))return n}return"en"}const Wd="modulepreload",Xd=function(i,e){return new URL(i,e).href},zc={},kc=function(e,t,n){let s=Promise.resolve();if(t&&t.length>0){let a=function(h){return Promise.all(h.map(d=>Promise.resolve(d).then(u=>({status:"fulfilled",value:u}),u=>({status:"rejected",reason:u}))))};const o=document.getElementsByTagName("link"),l=document.querySelector("meta[property=csp-nonce]"),c=l?.nonce||l?.getAttribute("nonce");s=a(t.map(h=>{if(h=Xd(h,n),h in zc)return;zc[h]=!0;const d=h.endsWith(".css"),u=d?'[rel="stylesheet"]':"";if(!!n)for(let x=o.length-1;x>=0;x--){const m=o[x];if(m.href===h&&(!d||m.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${h}"]${u}`))return;const g=document.createElement("link");if(g.rel=d?"stylesheet":Wd,d||(g.as="script"),g.crossOrigin="",g.href=h,c&&g.setAttribute("nonce",c),document.head.appendChild(g),d)return new Promise((x,m)=>{g.addEventListener("load",x),g.addEventListener("error",()=>m(new Error(`Unable to preload CSS for ${h}`)))})}))}function r(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return s.then(a=>{for(const o of a||[])o.status==="rejected"&&r(o.reason);return e().catch(r)})},qd=["en","fr"],Yd={en:()=>kc(()=>Promise.resolve().then(()=>$d),void 0,import.meta.url).then(i=>i.ufoMessages_en),fr:()=>kc(()=>import("./UfoMessages_fr-NZrwNFCQ.js"),[],import.meta.url).then(i=>i.ufoMessages_fr)};function Zd(i){return Yd[i]()}const Fu={play:"Play",pause:"Pause",noDuration:"No observation duration",autoReplay:"Auto-replay",currentPosition:"Current position",duration:"Duration",fullscreen:"Fullscreen",exitFullscreen:"Exit fullscreen"},$d=Object.freeze(Object.defineProperty({__proto__:null,ufoMessages_en:Fu},Symbol.toStringTag,{value:"Module"})),Gc=new Set;class Kd extends HTMLElement{static get observedAttributes(){return["src"]}shadow;stageElement;canvas;canvasRenderer;tooltip;toolbar;playPauseButton;loopButton;fullscreenButton;seekInput;timeStartLabel;timeEndLabel;currentSighting=Ma.create();sightingAudio=new Gd;player;loopEnabled=!0;highlightedSourceIds=new Set;occludedSourceIds=Gc;enableClickToPlay=!0;fullscreenTarget;messages=Fu;realDurationMs;realStartMs;handleFullscreenChange=()=>this.updateFullscreenButton();handlePointerMove=e=>{const t=this.canvasPointFromEvent(e),n=t&&this.currentSighting.timeline.hitTest(this.currentTime,t.x,t.y,this.occludedSourceIds);if(!n?.shape.title){this.tooltip.hidden=!0;return}this.tooltip.textContent=n.shape.title,this.tooltip.hidden=!1;const s=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-s.left+12}px`,this.tooltip.style.top=`${e.clientY-s.top+12}px`};handlePointerLeave=()=>{this.tooltip.hidden=!0};constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${dd}</style>${ud}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new Bd(this.canvas.getContext("2d")),this.tooltip=this.shadow.getElementById("tooltip"),this.toolbar=this.shadow.getElementById("toolbar"),this.playPauseButton=this.shadow.getElementById("play-pause"),this.loopButton=this.shadow.getElementById("loop"),this.fullscreenButton=this.shadow.getElementById("fullscreen"),this.seekInput=this.shadow.getElementById("seek"),this.timeStartLabel=this.shadow.getElementById("time-start"),this.timeEndLabel=this.shadow.getElementById("time-end"),this.fullscreenTarget=this.stageElement,this.playPauseButton.addEventListener("click",()=>this.togglePlayPause()),this.loopButton.addEventListener("click",()=>this.toggleLoop()),this.fullscreenButton.addEventListener("click",()=>this.toggleFullscreen()),this.seekInput.addEventListener("input",()=>this.player.seek(Number(this.seekInput.value))),this.canvas.addEventListener("click",()=>{this.enableClickToPlay&&this.togglePlayPause()}),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerleave",this.handlePointerLeave),document.addEventListener("fullscreenchange",this.handleFullscreenChange),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.refresh(),this.loadLocaleMessages()}connectedCallback(){const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.sightingAudio.dispose()}attributeChangedCallback(e,t,n){e==="src"&&n&&n!==t&&this.isConnected&&this.loadFromSrc(n)}async loadFromSrc(e){const t=await fetch(e);this.sightingData=await t.json()}get sightingData(){return Hd(this.currentSighting)}set sightingData(e){this.player.stop(),this.sightingAudio.silence(),this.currentSighting=Vd(e),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh()}get sighting(){return this.currentSighting}previewSound(e){this.sightingAudio.resume(),this.sightingAudio.setSound(e)}stopSoundPreview(){this.sightingAudio.silence()}get canvasElement(){return this.canvas}get renderer(){return this.canvasRenderer}get currentTime(){return this.player.time}set currentTime(e){this.player.seek(e)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}get positionLabel(){return this.timeStartLabel.textContent??""}get durationLabel(){return this.timeEndLabel.textContent??""}set showToolbar(e){this.toolbar.classList.toggle("hidden",!e)}get playbackState(){return this.player.playbackState}get selectedSourceIds(){return this.highlightedSourceIds}get durationSeconds(){return this.currentSighting.event.durationSeconds}set durationSeconds(e){this.currentSighting.event.durationSeconds=e,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(e){const t=new Set(e);t.size===this.highlightedSourceIds.size&&[...t].every(s=>this.highlightedSourceIds.has(s))||(this.highlightedSourceIds=t,this.refresh())}setOccludedSourceIds(e){e.size===this.occludedSourceIds.size&&[...e].every(n=>this.occludedSourceIds.has(n))||(this.occludedSourceIds=e,this.refresh())}hasVisibleShapeAt(e,t){return this.currentSighting.timeline.hitTest(this.currentTime,e,t,this.occludedSourceIds)!==void 0}refresh(){this.updateTimeLabels(),this.seekInput.max=String(this.player.seekableDuration),this.player.seek(this.player.time)}canvasPointFromEvent(e){const t=this.canvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return{x:(e.clientX-t.left)/t.width*this.canvas.width,y:(e.clientY-t.top)/t.height*this.canvas.height}}onFrame(e,t){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const n=this.playbackState!=="playing"?this.highlightedSourceIds:Gc;for(const[s,r]of t){if(this.occludedSourceIds.has(s))continue;const a=n.has(s);a&&n.size===1?this.canvasRenderer.paintShape({...r,selected:!0}):(this.canvasRenderer.paintShape(r),a&&this.canvasRenderer.paintMemberOutline(r))}if(n.size>1){const s=qt.groupBoundsFor([...t].filter(([r])=>n.has(r)).map(([,r])=>r.bounds));this.canvasRenderer.paintGroupHandles(s)}this.seekInput.value=String(e),this.timeStartLabel.textContent=this.formatPosition(e),this.playbackState==="playing"?this.sightingAudio.setSound(Id(this.currentSighting,e)):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:e}}))}createPlayer(){const e=new Dd(this.currentSighting.timeline,(t,n)=>this.onFrame(t,n));return e.loop=this.loopEnabled,e}togglePlayPause(){this.player.seekableDuration<=0||(this.player.playbackState==="playing"?(this.player.pause(),this.sightingAudio.silence(),this.refresh()):(this.sightingAudio.resume(),this.player.play()),this.updatePlayPauseButton())}updatePlayPauseButton(){const e=this.player.playbackState==="playing";this.playPauseButton.textContent=e?"⏸":"▶";const t=this.player.seekableDuration>0;this.playPauseButton.disabled=!t;const n=t?e?this.messages.pause:this.messages.play:this.messages.noDuration;this.playPauseButton.title=n,this.playPauseButton.setAttribute("aria-label",n),this.toolbar.classList.toggle("auto-hide",e),this.fullscreenButton.classList.toggle("auto-hide",e)}toggleLoop(){this.loopEnabled=!this.loopEnabled,this.loopButton.setAttribute("aria-pressed",String(this.loopEnabled)),this.player.loop=this.loopEnabled}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.fullscreenTarget.requestFullscreen().catch(e=>{console.error("<rr0-ufo>: requestFullscreen() failed —",e)})}updateFullscreenButton(){const e=document.fullscreenElement===this.fullscreenTarget;this.fullscreenButton.title=e?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}async loadLocaleMessages(){const e=Jl(navigator.languages,qd);e!=="en"&&this.applyMessages(await Zd(e))}applyMessages(e){this.messages=e,this.timeStartLabel.title=e.currentPosition,this.timeEndLabel.title=e.duration,this.loopButton.title=e.autoReplay,this.loopButton.setAttribute("aria-label",e.autoReplay),this.updatePlayPauseButton(),this.updateFullscreenButton()}updateTimeLabels(){const e=this.currentSighting.event,t=wd(e);this.realDurationMs=t!==void 0&&t>0?t:void 0,this.realStartMs=e.time?Io(e.time):void 0;const n=this.currentSighting.timeline.duration;this.player.playbackRate=this.realDurationMs!==void 0&&n>0?n/this.realDurationMs:1,this.player.durationOverrideMs=n>0?0:this.realDurationMs??0,this.timeEndLabel.textContent=this.formatEndOfTimeline(),this.timeStartLabel.textContent=this.formatPosition(this.player.time)}formatPosition(e){if(this.realDurationMs===void 0)return cr(e);const t=this.currentSighting.timeline.duration,n=t>0&&e<=t?e/t*this.realDurationMs:e;return this.realStartMs!==void 0?Vc(Hc(this.realStartMs+n)):cr(n)}formatEndOfTimeline(){return this.realDurationMs===void 0?cr(this.currentSighting.timeline.duration):this.realStartMs!==void 0?Vc(Hc(this.realStartMs+this.realDurationMs)):cr(this.realDurationMs)}}function Hc(i){const e=new Date(i);return{hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds()}}function Vc(i){if(i.hour===void 0)return"0:00";const e=t=>String(t).padStart(2,"0");return i.second?`${e(i.hour)}:${e(i.minute??0)}:${e(i.second)}`:`${e(i.hour)}:${e(i.minute??0)}`}function cr(i){const e=Math.round(i/1e3),t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,"0")}`}const Lo="rr0-ufo";function Ou(){customElements.get(Lo)||customElements.define(Lo,Kd)}/**
|
|
293
|
+
`;class Kl{static MOON_ANGULAR_WIDTH_DEG=.5237;static angularWidthDeg(e){return 2*Math.atan(e.sizeM/(2*e.distanceM))*180/Math.PI}static widthPx(e,t,n){return t*e.sizeM/(2*e.distanceM*Math.tan(n*Math.PI/360))}static pxToDeg(e,t,n){return 2*Math.atan(e*Math.tan(n*Math.PI/360)/t)*180/Math.PI}static inMoons(e){return e/Kl.MOON_ANGULAR_WIDTH_DEG}static lerp(e,t,n){if(!(!e||!t))return{sizeM:e.sizeM+(t.sizeM-e.sizeM)*n,distanceM:e.distanceM+(t.distanceM-e.distanceM)*n}}}function fd(i,e,t){const{bounds:n}=i;return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function jt(i,e,t){return i+(e-i)*t}function Cc(i){const e=/^#([0-9a-f]{6})$/i.exec(i);if(!e)return;const t=parseInt(e[1],16);return[t>>16&255,t>>8&255,t&255]}function pd(i){return`#${i.map(e=>Math.round(e).toString(16).padStart(2,"0")).join("")}`}function md(i,e,t){const n=Cc(i),s=Cc(e);return!n||!s?t<1?i:e:pd([jt(n[0],s[0],t),jt(n[1],s[1],t),jt(n[2],s[2],t)])}function gd(i,e,t){const n={x:jt(i.bounds.x,e.bounds.x,t),y:jt(i.bounds.y,e.bounds.y,t),width:jt(i.bounds.width,e.bounds.width,t),height:jt(i.bounds.height,e.bounds.height,t)},s=jt(i.angle,e.angle,t),r=jt(i.transparency,e.transparency,t),a=jt(i.haloScale,e.haloScale,t),o=md(i.color,e.color,t),l=Kl.lerp(i.physical,e.physical,t);return i.kind==="polygon"&&e.kind==="polygon"&&i.points.length===e.points.length?{...i,bounds:n,angle:s,transparency:r,haloScale:a,color:o,physical:l,behindCloud:t<1?i.behindCloud:e.behindCloud,points:i.points.map((c,h)=>({x:jt(c.x,e.points[h].x,t),y:jt(c.y,e.points[h].y,t)}))}:{...t<1?i:e,bounds:n,angle:s,transparency:r,haloScale:a,color:o,physical:l}}class xa{keyframes=[];order=[];groups=[];addKeyframe(e,t){const n=this.findInsertIndex(e);if(this.keyframes[n]?.t===e){const s=new Set(t.map(r=>r.sourceId));this.keyframes[n]={t:e,shapes:[...this.keyframes[n].shapes.filter(r=>!s.has(r.sourceId)),...t]}}else this.keyframes.splice(n,0,{t:e,shapes:[...t]});for(const s of t)this.order.includes(s.sourceId)||this.order.push(s.sourceId)}findInsertIndex(e){let t=0,n=this.keyframes.length;for(;t<n;){const s=t+n>>>1;this.keyframes[s].t<e?t=s+1:n=s}return t}getKeyframeAt(e){const t=this.findInsertIndex(e),n=this.keyframes[t];return n?.t===e?n:void 0}getShapeAt(e,t){return this.getKeyframeAt(e)?.shapes.find(n=>n.sourceId===t)?.shape}getLatestShapeAt(e,t){let n=this.findInsertIndex(e);for(this.keyframes[n]?.t!==e&&(n-=1);n>=0;n--){const s=this.keyframes[n].shapes.find(r=>r.sourceId===t);if(s)return s.shape}}getInterpolatedShapeAt(e,t){const n=this.findShapeAtOrBefore(e,t);if(n?.t===e)return n.shape;const s=this.findShapeAtOrAfter(e,t);return n?s?gd(n.shape,s.shape,(e-n.t)/(s.t-n.t)):n.shape:s?.shape}findShapeAtOrBefore(e,t){let n=this.findInsertIndex(e);for(this.keyframes[n]?.t!==e&&(n-=1);n>=0;n--){const s=this.keyframes[n].shapes.find(r=>r.sourceId===t);if(s)return{t:this.keyframes[n].t,shape:s.shape}}}findShapeAtOrAfter(e,t){for(let n=this.findInsertIndex(e);n<this.keyframes.length;n++){const s=this.keyframes[n].shapes.find(r=>r.sourceId===t);if(s)return{t:this.keyframes[n].t,shape:s.shape}}}hitTest(e,t,n,s){const r=this.sourceIds;for(let a=r.length-1;a>=0;a--){if(s?.has(r[a]))continue;const o=this.getInterpolatedShapeAt(e,r[a]);if(o&&fd(o,t,n))return{sourceId:r[a],shape:o}}}removeSource(e){for(let t=this.keyframes.length-1;t>=0;t--){const n=this.keyframes[t].shapes.filter(s=>s.sourceId!==e);n.length===0?this.keyframes.splice(t,1):n.length!==this.keyframes[t].shapes.length&&(this.keyframes[t]={t:this.keyframes[t].t,shapes:n})}this.order=this.order.filter(t=>t!==e),this.removeFromGroup(e)}group(e){if(!(e.length<2)){for(const t of e)this.removeFromGroup(t);this.groups.push([...e])}}ungroup(e){const t=this.groups.findIndex(n=>n.includes(e));t!==-1&&this.groups.splice(t,1)}groupMembers(e){return this.groups.find(t=>t.includes(e))}removeFromGroup(e){const t=this.groups.findIndex(s=>s.includes(e));if(t===-1)return;const n=this.groups[t].filter(s=>s!==e);n.length<2?this.groups.splice(t,1):this.groups[t]=n}bringToFront(e){const t=this.order.indexOf(e);t!==-1&&(this.order.splice(t,1),this.order.push(e))}sendToBack(e){const t=this.order.indexOf(e);t!==-1&&(this.order.splice(t,1),this.order.unshift(e))}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(e){const t=new xa;for(const n of e.keyframes)t.addKeyframe(n.t,n.shapes);if(e.order){const n=t.order.filter(s=>!e.order.includes(s));t.order=[...e.order,...n]}return e.groups&&(t.groups=e.groups.map(n=>n.filter(s=>t.order.includes(s))).filter(n=>n.length>=2)),t}}function _d(i,e,t){return Math.max(e,Math.min(t,i))}function vd(i,e,t){const n=((e-i)%360+540)%360-180;return((i+n*t)%360+360)%360}function Ss(i,e,t){return i+(e-i)*t}function xd(i,e,t){return{lat:i.lat===void 0||e.lat===void 0?void 0:Ss(i.lat,e.lat,t),lng:i.lng===void 0||e.lng===void 0?void 0:Ss(i.lng,e.lng,t),elevationM:Ss(i.elevationM,e.elevationM,t),headingDeg:i.headingDeg===void 0||e.headingDeg===void 0?void 0:vd(i.headingDeg,e.headingDeg,t),pitchDeg:Ss(i.pitchDeg,e.pitchDeg,t),fovDeg:Ss(i.fovDeg,e.fovDeg,t)}}class Ys{keyframes=[];addKeyframe(e,t){const n=this.findInsertIndex(e);this.keyframes[n]?.t===e?this.keyframes[n]={t:e,pose:t}:this.keyframes.splice(n,0,{t:e,pose:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}findInsertIndex(e){let t=0,n=this.keyframes.length;for(;t<n;){const s=t+n>>>1;this.keyframes[s].t<e?t=s+1:n=s}return t}getLatestPoseAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].pose:void 0}getInterpolatedPoseAt(e){const t=this.findInsertIndex(e),n=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(n?.t===e)return n.pose;const s=this.keyframes[t]?.t===e?void 0:this.keyframes[t];return n?s?xd(n.pose,s.pose,_d((e-n.t)/(s.t-n.t),0,1)):n.pose:s?.pose}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(e){const t=new Ys;for(const n of e.keyframes)t.addKeyframe(n.t,n.pose);return t}}function ys(i,e,t){return i+(e-i)*t}function Md(i,e,t){const n=((e-i)%360+540)%360-180;return((i+n*t)%360+360)%360}function Sd(i,e,t){return Math.max(e,Math.min(t,i))}function yd(i,e,t){return{cloudCover:ys(i.cloudCover,e.cloudCover,t),cloudDarkness:ys(i.cloudDarkness,e.cloudDarkness,t),cloudBaseM:i.cloudBaseM===void 0||e.cloudBaseM===void 0?void 0:ys(i.cloudBaseM,e.cloudBaseM,t),precipitationType:t<1?i.precipitationType:e.precipitationType,precipitationIntensity:ys(i.precipitationIntensity,e.precipitationIntensity,t),windDirectionDeg:Md(i.windDirectionDeg,e.windDirectionDeg,t),windSpeed:ys(i.windSpeed,e.windSpeed,t),storm:t<1?i.storm:e.storm}}class Zs{keyframes=[];addKeyframe(e,t){const n=this.findInsertIndex(e);this.keyframes[n]?.t===e?this.keyframes[n]={t:e,weather:t}:this.keyframes.splice(n,0,{t:e,weather:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}findInsertIndex(e){let t=0,n=this.keyframes.length;for(;t<n;){const s=t+n>>>1;this.keyframes[s].t<e?t=s+1:n=s}return t}getLatestWeatherAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].weather:void 0}getInterpolatedWeatherAt(e){const t=this.findInsertIndex(e),n=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(n?.t===e)return n.weather;const s=this.keyframes[t]?.t===e?void 0:this.keyframes[t];return n?s?yd(n.weather,s.weather,Sd((e-n.t)/(s.t-n.t),0,1)):n.weather:s?.weather}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(e){const t=new Zs;for(const n of e.keyframes)t.addKeyframe(n.t,n.weather);return t}}class $s{keyframes=[];addKeyframe(e,t){const n=this.findInsertIndex(e);this.keyframes[n]?.t===e?this.keyframes[n]={t:e,sound:t}:this.keyframes.splice(n,0,{t:e,sound:t})}clear(){this.keyframes.length=0}removeKeyframeAt(e){const t=this.findInsertIndex(e);this.keyframes[t]?.t===e&&this.keyframes.splice(t,1)}getLatestSoundAt(e){let t=this.findInsertIndex(e);return this.keyframes[t]?.t!==e&&(t-=1),t>=0?this.keyframes[t].sound:void 0}getInterpolatedSoundAt(e){const t=this.findInsertIndex(e),n=this.keyframes[t]?.t===e?this.keyframes[t]:this.keyframes[t-1];if(n?.t===e)return n.sound;const s=this.keyframes[t]?.t===e?void 0:this.keyframes[t];if(!n)return s?.sound;if(!s)return n.sound;const r=(e-n.t)/(s.t-n.t);return this.lerp(n.sound,s.sound,Math.max(0,Math.min(1,r)))}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(e){const t=new $s;for(const n of e.keyframes)t.addKeyframe(n.t,n.sound);return t}lerp(e,t,n){return{kind:n<1?e.kind:t.kind,volume:e.volume+(t.volume-e.volume)*n,pitchHz:e.pitchHz+(t.pitchHz-e.pitchHz)*n,src:n<1?e.src:t.src}}findInsertIndex(e){let t=0,n=this.keyframes.length;for(;t<n;){const s=t+n>>>1;this.keyframes[s].t<e?t=s+1:n=s}return t}}const Po=1e3,Nu={cloudCover:0,cloudDarkness:0,precipitationType:"none",precipitationIntensity:0,windDirectionDeg:0,windSpeed:0,storm:!1},Ed=100,bd={kind:"none",volume:0,pitchHz:Ed};function Io(i){if(i.year!==void 0)return Date.UTC(i.year,(i.month??1)-1,i.day??1,i.hour??0,i.minute??0,i.second??0)}function Pc(i){return(((i.day??0)*24+(i.hour??0))*60+(i.minute??0))*6e4+(i.second??0)*1e3}const Td=["year","month","day","hour","minute"],Ad=["day","hour","minute"];function Ic(i,e){return e.filter(t=>i[t]!==void 0).join(",")}function wd(i){if(i.durationSeconds!==void 0)return i.durationSeconds*1e3;if(!i.time||!i.endTime)return;const e=i.time.year!==void 0&&i.endTime.year!==void 0,t=e?Td:Ad,n=Ic(i.time,t);if(!(n===""||n!==Ic(i.endTime,t)))return e?Io(i.endTime)-Io(i.time):Pc(i.endTime)-Pc(i.time)}class Ma{constructor(e,t,n,s,r,a,o,l,c=[],h){this.event=e,this.timeline=t,this.witnessTrack=n,this.weatherTrack=s,this.soundTrack=r,this.witness=a,this.caseId=o,this.weather=l,this.decor=c,this.weatherSource=h}static create(e,t,n){return new Ma({eventType:"sighting",time:e,place:t},new xa,new Ys,new Zs,new $s,n)}}const Rd=0,Cd=0,Pd=60;function Dc(i,e){const t=i.witnessTrack.getInterpolatedPoseAt(e);if(t)return t;const n=i.event.place?.[0];if(n)return{lat:n.lat,lng:n.lng,elevationM:Rd,headingDeg:void 0,pitchDeg:Cd,fovDeg:Pd}}function Lc(i,e){return i.weatherTrack.getInterpolatedWeatherAt(e)??i.weather??Nu}function Id(i,e){return i.soundTrack.getInterpolatedSoundAt(e)??bd}class Dd{constructor(e,t){this.timeline=e,this.onFrame=t}rafId=null;state="stopped";currentT=0;lastWallTime=0;playbackRate=1;loop=!1;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 e=()=>{if(this.state!=="playing")return;const t=performance.now();if(this.currentT+=(t-this.lastWallTime)*this.playbackRate,this.lastWallTime=t,this.currentT>=this.seekableDuration){if(this.loop&&this.seekableDuration>0){this.currentT%=this.seekableDuration,this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e);return}this.currentT=this.seekableDuration,this.stop(),this.resolveFrame(this.currentT);return}this.resolveFrame(this.currentT),this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}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(e){this.currentT=Math.max(0,Math.min(e,this.seekableDuration)),this.resolveFrame(this.currentT)}get playbackState(){return this.state}get time(){return this.currentT}resolveFrame(e){const t=new Map;for(const n of this.timeline.sourceIds){const s=this.timeline.getInterpolatedShapeAt(e,n);s&&t.set(n,s)}this.onFrame(e,t)}}const Uu=["nw","n","ne","e","se","s","sw","w"],Ld=24,ar=8,Nd=3,Ud=8;function or(i,e,t){const n=i.x-e.x,s=i.y-e.y,r=Math.cos(t),a=Math.sin(t);return{x:e.x+n*r-s*a,y:e.y+n*a+s*r}}function Es(i){return{x:i.x+i.width/2,y:i.y+i.height/2}}const Fd={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 qt{static handlePointsFor(e){const{x:t,y:n,width:s,height:r}=e.bounds,a={nw:{x:t,y:n},n:{x:t+s/2,y:n},ne:{x:t+s,y:n},e:{x:t+s,y:n+r/2},se:{x:t+s,y:n+r},s:{x:t+s/2,y:n+r},sw:{x:t,y:n+r},w:{x:t,y:n+r/2},rotate:{x:t+s/2,y:n-Ld}},o=Es(e.bounds),l={};for(const c of Object.keys(a))l[c]=or(a[c],o,e.angle);return l}static hitTestHandle(e,t,n=8,s=[...Uu,"rotate"]){const r=qt.handlePointsFor(e);for(const a of s)if(Math.hypot(t.x-r[a].x,t.y-r[a].y)<=n)return a}static HANDLE_DIRECTION_DEG={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315};static resizeAxisFor(e,t){const s=((qt.HANDLE_DIRECTION_DEG[e]+t*180/Math.PI)%180+180)%180/45,r=["ew","nwse","ns","nesw"];return r[Math.round(s)%r.length]}static resizeBounds(e,t,n,s){const r=Es(e),a=or(s,r,-t),{x:o,y:l,width:c,height:h}=e,d=Fd[n];let u=o,p=l,g=o+c,x=l+h;return d.left&&(u=Math.min(a.x,g-ar)),d.right&&(g=Math.max(a.x,u+ar)),d.top&&(p=Math.min(a.y,x-ar)),d.bottom&&(x=Math.max(a.y,p+ar)),{x:u,y:p,width:g-u,height:x-p}}static resizeShape(e,t,n){if(t==="rotate")throw new Error("resizeShape does not accept the rotate handle");const{width:s,height:r}=e.bounds,a=qt.resizeBounds(e.bounds,e.angle,t,n);if(e.kind==="oval")return{...e,bounds:a};const o=s===0?1:a.width/s,l=r===0?1:a.height/r;return{...e,bounds:a,points:e.points.map(c=>({x:c.x*o,y:c.y*l}))}}static rotateShape(e,t){const n=Es(e.bounds),s=Math.atan2(t.y-n.y,t.x-n.x)+Math.PI/2;return{...e,angle:s}}static groupBoundsFor(e){const t=Math.min(...e.map(a=>a.x)),n=Math.min(...e.map(a=>a.y)),s=Math.max(...e.map(a=>a.x+a.width)),r=Math.max(...e.map(a=>a.y+a.height));return{x:t,y:n,width:s-t,height:r-n}}static vertexPointsFor(e){const t=Es(e.bounds);return e.points.map(n=>or({x:e.bounds.x+n.x,y:e.bounds.y+n.y},t,e.angle))}static hitTestVertex(e,t,n=Ud){const s=qt.vertexPointsFor(e);let r,a=n;return s.forEach((o,l)=>{const c=Math.hypot(t.x-o.x,t.y-o.y);c<=a&&(a=c,r=l)}),r}static toLocalPoint(e,t){const n=Es(e.bounds),s=or(t,n,-e.angle);return{x:s.x-e.bounds.x,y:s.y-e.bounds.y}}static moveVertex(e,t,n){const s=e.points.map((d,u)=>u===t?qt.toLocalPoint(e,n):d),r=Math.min(...s.map(d=>d.x)),a=Math.min(...s.map(d=>d.y)),o=Math.max(...s.map(d=>d.x)),l=Math.max(...s.map(d=>d.y)),c={x:e.bounds.x+r,y:e.bounds.y+a,width:o-r,height:l-a},h=s.map(d=>({x:d.x-r,y:d.y-a}));return{...e,bounds:c,points:h}}static insertVertexNear(e,t){const n=qt.toLocalPoint(e,t),{points:s}=e;let r=s.length-1,a=1/0;for(let l=0;l<s.length;l++){const c=s[l],h=s[(l+1)%s.length],d=qt.distanceToSegment(n,c,h);d<a&&(a=d,r=l)}const o=[...s.slice(0,r+1),n,...s.slice(r+1)];return{...e,points:o}}static distanceToSegment(e,t,n){const s=n.x-t.x,r=n.y-t.y,a=s*s+r*r,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*s+(e.y-t.y)*r)/a)),l=t.x+o*s,c=t.y+o*r;return Math.hypot(e.x-l,e.y-c)}static deleteVertex(e,t){return e.points.length<=Nd?e:{...e,points:e.points.filter((n,s)=>s!==t)}}}const Do=6,lr=Do/2,Od=20,Nc=4;class Bd{constructor(e){this.ctx=e}clear(e,t){this.ctx.clearRect(0,0,e,t)}paintShape(e){this.ctx.save(),this.ctx.globalAlpha=1-e.transparency,e.haloScale>0&&this.paintHalo(e),this.paintBase(e),this.ctx.restore(),e.selected&&this.paintSelectionHandles(e)}paintBase(e){if(this.ctx.fillStyle=e.color,this.ctx.beginPath(),e.kind==="oval"){const{x:t,y:n,width:s,height:r}=e.bounds,a=s/2,o=r/2;this.ctx.ellipse(t+a,n+o,a,o,e.angle,0,2*Math.PI)}else{const{x:t,y:n,width:s,height:r}=e.bounds;this.ctx.save(),this.ctx.translate(t+s/2,n+r/2),this.ctx.rotate(e.angle),this.ctx.translate(-s/2,-r/2),e.points.forEach((a,o)=>{o===0?this.ctx.moveTo(a.x,a.y):this.ctx.lineTo(a.x,a.y)}),this.ctx.closePath(),this.ctx.restore()}this.ctx.fill()}paintHalo(e){this.ctx.save(),this.ctx.shadowColor=e.color,this.ctx.shadowBlur=Od*e.haloScale,this.paintBase(e),this.ctx.restore()}paintSelectionHandles(e){this.paintHandleFrame(qt.handlePointsFor(e),{includeRotate:!0}),e.kind==="polygon"&&this.paintVertexHandles(e)}paintVertexHandles(e){this.ctx.fillStyle="#39f";for(const t of qt.vertexPointsFor(e))this.ctx.beginPath(),this.ctx.ellipse(t.x,t.y,Nc,Nc,0,0,2*Math.PI),this.ctx.fill()}paintMemberOutline(e){this.paintOutline(qt.handlePointsFor(e))}paintGroupHandles(e){this.paintHandleFrame(qt.handlePointsFor({bounds:e,angle:0}),{includeRotate:!0})}paintOutline(e){this.ctx.strokeStyle="lightgray",this.ctx.beginPath(),this.ctx.moveTo(e.nw.x,e.nw.y),this.ctx.lineTo(e.ne.x,e.ne.y),this.ctx.lineTo(e.se.x,e.se.y),this.ctx.lineTo(e.sw.x,e.sw.y),this.ctx.closePath(),this.ctx.stroke()}paintHandleFrame(e,{includeRotate:t}){this.paintOutline(e),this.ctx.fillStyle="lightgray";for(const n of Uu){const s=e[n];this.ctx.fillRect(s.x-lr,s.y-lr,Do,Do)}t&&(this.ctx.beginPath(),this.ctx.moveTo(e.n.x,e.n.y),this.ctx.lineTo(e.rotate.x,e.rotate.y),this.ctx.stroke(),this.ctx.beginPath(),this.ctx.ellipse(e.rotate.x,e.rotate.y,lr+1,lr+1,0,0,2*Math.PI),this.ctx.fill())}}const Uc=.05,Fc=.08,Oc=2,Bc=3,zd=14,kd=.02;class Gd{context;voice;voiceToken=0;buffers=new Map;noiseBuffer;crackleBuffer;requested;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("SightingAudio: Web Audio unavailable, the sighting stays silent:",e);return}}this.context.state==="suspended"&&this.context.resume()}setSound(e){if(this.requested=e,!this.context)return;const t=this.keyFor(e);if(!t){this.silence();return}if(this.voice?.key!==t){this.stopVoice();const n=++this.voiceToken;t.startsWith("src:")?this.buildRecordedVoice(e.src,t,n):this.voice=this.buildSynthesizedVoice(e,t)}this.applyTo(this.voice,e)}silence(){this.voiceToken++,this.stopVoice()}dispose(){this.silence(),this.context?.close(),this.context=void 0,this.buffers.clear(),this.noiseBuffer=void 0,this.crackleBuffer=void 0}keyFor(e){if(!(e.volume<=0))return e.src?`src:${e.src}`:e.kind==="none"?void 0:e.kind}applyTo(e,t){const n=this.context;if(!e||!n)return;const s=n.currentTime;e.volumeParam.setTargetAtTime(Math.max(0,Math.min(1,t.volume))*e.gainScale,s,Uc);for(const{param:r,ratio:a}of e.pitch)r.setTargetAtTime(Math.min(t.pitchHz*a,n.sampleRate/2-1),s,Uc)}buildSynthesizedVoice(e,t){const n=this.context;if(n)switch(e.kind){case"hum":return this.buildHum(n,t);case"whistle":return this.buildWhistle(n,t);case"rumble":return this.buildRumble(n,t);case"crackle":return this.buildCrackle(n,t);default:return}}buildHum(e,t){const n=e.createOscillator();n.type="sawtooth";const s=e.createOscillator();s.type="sawtooth";const r=e.createBiquadFilter();r.type="lowpass",r.Q.value=1;const a=e.createGain();return a.gain.value=0,n.connect(r),s.connect(r),r.connect(a).connect(e.destination),n.start(),s.start(),{key:t,nodes:[r,a],sources:[n,s],volumeParam:a.gain,gainScale:.16,pitch:[{param:n.frequency,ratio:1},{param:s.frequency,ratio:1.006},{param:r.frequency,ratio:6}]}}buildWhistle(e,t){const n=e.createOscillator();n.type="sine";const s=e.createOscillator();s.type="sine",s.frequency.value=5;const r=e.createGain(),a=e.createGain();return a.gain.value=0,s.connect(r).connect(n.frequency),n.connect(a).connect(e.destination),n.start(),s.start(),{key:t,nodes:[r,a],sources:[n,s],volumeParam:a.gain,gainScale:.22,pitch:[{param:n.frequency,ratio:1},{param:r.gain,ratio:.012}]}}buildRumble(e,t){const n=e.createBufferSource();n.buffer=this.brownNoise(e),n.loop=!0;const s=e.createBiquadFilter();s.type="lowpass",s.Q.value=.8;const r=e.createGain();return r.gain.value=0,n.connect(s).connect(r).connect(e.destination),n.start(),{key:t,nodes:[s,r],sources:[n],volumeParam:r.gain,gainScale:1.4,pitch:[{param:s.frequency,ratio:1}]}}buildCrackle(e,t){const n=e.createBufferSource();n.buffer=this.whiteNoise(e),n.loop=!0;const s=e.createBiquadFilter();s.type="bandpass",s.Q.value=1.2;const r=e.createGain();r.gain.value=0;const a=e.createBufferSource();a.buffer=this.crackleEnvelope(e),a.loop=!0;const o=e.createGain();return o.gain.value=0,a.connect(o).connect(r.gain),n.connect(s).connect(r).connect(e.destination),n.start(),a.start(),{key:t,nodes:[s,r,o],sources:[n,a],volumeParam:o.gain,gainScale:.9,pitch:[{param:s.frequency,ratio:4}]}}async buildRecordedVoice(e,t,n){const s=this.context;if(!s)return;let r;try{r=await this.getBuffer(e)}catch(l){console.warn("SightingAudio: the recorded sound failed to load, staying silent:",l);return}if(n!==this.voiceToken||!this.context)return;const a=s.createBufferSource();a.buffer=r,a.loop=!0;const o=s.createGain();o.gain.value=0,a.connect(o).connect(s.destination),a.start(),this.voice={key:t,nodes:[o],sources:[a],volumeParam:o.gain,gainScale:1,pitch:[]},this.requested&&this.applyTo(this.voice,this.requested)}async getBuffer(e){const t=this.context;if(!t)throw new Error("SightingAudio: AudioContext not ready — resume() must be called first");let n=this.buffers.get(e);return n||(n=fetch(e).then(s=>{if(!s.ok)throw new Error(`Audio fetch failed (${s.status}): ${e}`);return s.arrayBuffer()}).then(s=>t.decodeAudioData(s)),this.buffers.set(e,n)),n}whiteNoise(e){if(!this.noiseBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*Oc),e.sampleRate),n=t.getChannelData(0);for(let s=0;s<n.length;s++)n[s]=Math.random()*2-1;this.noiseBuffer=t}return this.noiseBuffer}brownNoise(e){const t=e.createBuffer(1,Math.floor(e.sampleRate*Oc),e.sampleRate),n=t.getChannelData(0);let s=0,r=0;for(let a=0;a<n.length;a++)s=(s+.02*(Math.random()*2-1))/1.02,n[a]=s,r=Math.max(r,Math.abs(s));if(r>0)for(let a=0;a<n.length;a++)n[a]/=r;return t}crackleEnvelope(e){if(!this.crackleBuffer){const t=e.createBuffer(1,Math.floor(e.sampleRate*Bc),e.sampleRate),n=t.getChannelData(0),s=Math.max(1,Math.floor(kd*e.sampleRate)),r=Math.round(Bc*zd);for(let a=0;a<r;a++){const o=Math.floor(Math.random()*n.length),l=.4+Math.random()*.6;for(let c=0;c<s&&o+c<n.length;c++)n[o+c]=Math.max(n[o+c],l*(1-c/s))}this.crackleBuffer=t}return this.crackleBuffer}stopVoice(){const e=this.voice,t=this.context;if(this.voice=void 0,!e||!t)return;const n=t.currentTime;e.volumeParam.cancelScheduledValues(n),e.volumeParam.setTargetAtTime(0,n,Fc/3);const s=n+Fc;for(const r of e.sources){r.onended=()=>{r.disconnect();for(const a of e.nodes)a.disconnect()};try{r.stop(s)}catch{r.disconnect();for(const a of e.nodes)a.disconnect()}}}}function Hd(i){return{version:1,time:i.event.time,endTime:i.event.endTime,durationSeconds:i.event.durationSeconds,utcOffsetHours:i.event.utcOffsetHours,timeZone:i.event.timeZone,place:i.event.place,witness:i.witness,caseId:i.caseId,description:i.event.description,tags:i.event.tags,timeline:i.timeline.toJSON(),witnessTrack:i.witnessTrack.toJSON(),weatherTrack:i.weatherTrack.toJSON(),soundTrack:i.soundTrack.toJSON(),weather:i.weather,decor:i.decor,weatherSource:i.weatherSource}}function Vd(i){return new Ma({eventType:"sighting",time:i.time,endTime:i.endTime,durationSeconds:i.durationSeconds,utcOffsetHours:i.utcOffsetHours,timeZone:i.timeZone,place:i.place,description:i.description,tags:i.tags},xa.fromJSON(i.timeline),i.witnessTrack?Ys.fromJSON(i.witnessTrack):new Ys,i.weatherTrack?Zs.fromJSON(i.weatherTrack):new Zs,i.soundTrack?$s.fromJSON(i.soundTrack):new $s,i.witness,i.caseId,i.weather,i.decor??[],i.weatherSource)}function Jl(i,e){for(const t of i){const n=t.toLowerCase().split("-")[0];if(e.includes(n))return n}return"en"}const Wd="modulepreload",Xd=function(i,e){return new URL(i,e).href},zc={},kc=function(e,t,n){let s=Promise.resolve();if(t&&t.length>0){let a=function(h){return Promise.all(h.map(d=>Promise.resolve(d).then(u=>({status:"fulfilled",value:u}),u=>({status:"rejected",reason:u}))))};const o=document.getElementsByTagName("link"),l=document.querySelector("meta[property=csp-nonce]"),c=l?.nonce||l?.getAttribute("nonce");s=a(t.map(h=>{if(h=Xd(h,n),h in zc)return;zc[h]=!0;const d=h.endsWith(".css"),u=d?'[rel="stylesheet"]':"";if(!!n)for(let x=o.length-1;x>=0;x--){const m=o[x];if(m.href===h&&(!d||m.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${h}"]${u}`))return;const g=document.createElement("link");if(g.rel=d?"stylesheet":Wd,d||(g.as="script"),g.crossOrigin="",g.href=h,c&&g.setAttribute("nonce",c),document.head.appendChild(g),d)return new Promise((x,m)=>{g.addEventListener("load",x),g.addEventListener("error",()=>m(new Error(`Unable to preload CSS for ${h}`)))})}))}function r(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return s.then(a=>{for(const o of a||[])o.status==="rejected"&&r(o.reason);return e().catch(r)})},qd=["en","fr"],Yd={en:()=>kc(()=>Promise.resolve().then(()=>$d),void 0,import.meta.url).then(i=>i.ufoMessages_en),fr:()=>kc(()=>import("./UfoMessages_fr-NZrwNFCQ.js"),[],import.meta.url).then(i=>i.ufoMessages_fr)};function Zd(i){return Yd[i]()}const Fu={play:"Play",pause:"Pause",noDuration:"No observation duration",autoReplay:"Auto-replay",currentPosition:"Current position",duration:"Duration",fullscreen:"Fullscreen",exitFullscreen:"Exit fullscreen"},$d=Object.freeze(Object.defineProperty({__proto__:null,ufoMessages_en:Fu},Symbol.toStringTag,{value:"Module"})),Gc=new Set;class Kd extends HTMLElement{static get observedAttributes(){return["src"]}shadow;stageElement;canvas;canvasRenderer;tooltip;toolbar;playPauseButton;loopButton;fullscreenButton;seekInput;timeStartLabel;timeEndLabel;currentSighting=Ma.create();sightingAudio=new Gd;soundPreview;player;loopEnabled=!0;highlightedSourceIds=new Set;occludedSourceIds=Gc;enableClickToPlay=!0;fullscreenTarget;messages=Fu;realDurationMs;realStartMs;handleFullscreenChange=()=>this.updateFullscreenButton();handlePointerMove=e=>{const t=this.canvasPointFromEvent(e),n=t&&this.currentSighting.timeline.hitTest(this.currentTime,t.x,t.y,this.occludedSourceIds);if(!n?.shape.title){this.tooltip.hidden=!0;return}this.tooltip.textContent=n.shape.title,this.tooltip.hidden=!1;const s=this.stageElement.getBoundingClientRect();this.tooltip.style.left=`${e.clientX-s.left+12}px`,this.tooltip.style.top=`${e.clientY-s.top+12}px`};handlePointerLeave=()=>{this.tooltip.hidden=!0};constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${dd}</style>${ud}`,this.shadow.appendChild(e.content.cloneNode(!0)),this.stageElement=this.shadow.getElementById("stage"),this.canvas=this.shadow.getElementById("canvas"),this.canvasRenderer=new Bd(this.canvas.getContext("2d")),this.tooltip=this.shadow.getElementById("tooltip"),this.toolbar=this.shadow.getElementById("toolbar"),this.playPauseButton=this.shadow.getElementById("play-pause"),this.loopButton=this.shadow.getElementById("loop"),this.fullscreenButton=this.shadow.getElementById("fullscreen"),this.seekInput=this.shadow.getElementById("seek"),this.timeStartLabel=this.shadow.getElementById("time-start"),this.timeEndLabel=this.shadow.getElementById("time-end"),this.fullscreenTarget=this.stageElement,this.playPauseButton.addEventListener("click",()=>this.togglePlayPause()),this.loopButton.addEventListener("click",()=>this.toggleLoop()),this.fullscreenButton.addEventListener("click",()=>this.toggleFullscreen()),this.seekInput.addEventListener("input",()=>this.player.seek(Number(this.seekInput.value))),this.canvas.addEventListener("click",()=>{this.enableClickToPlay&&this.togglePlayPause()}),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerleave",this.handlePointerLeave),document.addEventListener("fullscreenchange",this.handleFullscreenChange),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.updateFullscreenButton(),this.refresh(),this.loadLocaleMessages()}connectedCallback(){const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.sightingAudio.dispose()}attributeChangedCallback(e,t,n){e==="src"&&n&&n!==t&&this.isConnected&&this.loadFromSrc(n)}async loadFromSrc(e){const t=await fetch(e);this.sightingData=await t.json()}get sightingData(){return Hd(this.currentSighting)}set sightingData(e){this.player.stop(),this.soundPreview=void 0,this.sightingAudio.silence(),this.currentSighting=Vd(e),this.player=this.createPlayer(),this.updateTimeLabels(),this.updatePlayPauseButton(),this.refresh()}get sighting(){return this.currentSighting}previewSound(e){this.soundPreview=e,this.sightingAudio.resume(),this.sightingAudio.setSound(e)}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(e){this.player.seek(e)}get seekableDuration(){return this.player.seekableDuration}get autoReplayEnabled(){return this.loopEnabled}get positionLabel(){return this.timeStartLabel.textContent??""}get durationLabel(){return this.timeEndLabel.textContent??""}set showToolbar(e){this.toolbar.classList.toggle("hidden",!e)}get playbackState(){return this.player.playbackState}get selectedSourceIds(){return this.highlightedSourceIds}get durationSeconds(){return this.currentSighting.event.durationSeconds}set durationSeconds(e){this.currentSighting.event.durationSeconds=e,this.updateTimeLabels(),this.refresh(),this.updatePlayPauseButton()}set selectedSourceIds(e){const t=new Set(e);t.size===this.highlightedSourceIds.size&&[...t].every(s=>this.highlightedSourceIds.has(s))||(this.highlightedSourceIds=t,this.refresh())}setOccludedSourceIds(e){e.size===this.occludedSourceIds.size&&[...e].every(n=>this.occludedSourceIds.has(n))||(this.occludedSourceIds=e,this.refresh())}hasVisibleShapeAt(e,t){return this.currentSighting.timeline.hitTest(this.currentTime,e,t,this.occludedSourceIds)!==void 0}refresh(){this.updateTimeLabels(),this.seekInput.max=String(this.player.seekableDuration),this.player.seek(this.player.time)}canvasPointFromEvent(e){const t=this.canvas.getBoundingClientRect();if(!(t.width===0||t.height===0))return{x:(e.clientX-t.left)/t.width*this.canvas.width,y:(e.clientY-t.top)/t.height*this.canvas.height}}onFrame(e,t){this.canvasRenderer.clear(this.canvas.width,this.canvas.height);const n=this.playbackState!=="playing"?this.highlightedSourceIds:Gc;for(const[s,r]of t){if(this.occludedSourceIds.has(s))continue;const a=n.has(s);a&&n.size===1?this.canvasRenderer.paintShape({...r,selected:!0}):(this.canvasRenderer.paintShape(r),a&&this.canvasRenderer.paintMemberOutline(r))}if(n.size>1){const s=qt.groupBoundsFor([...t].filter(([r])=>n.has(r)).map(([,r])=>r.bounds));this.canvasRenderer.paintGroupHandles(s)}this.seekInput.value=String(e),this.timeStartLabel.textContent=this.formatPosition(e),this.playbackState==="playing"?(this.soundPreview=void 0,this.sightingAudio.setSound(Id(this.currentSighting,e))):this.soundPreview?this.sightingAudio.setSound(this.soundPreview):this.sightingAudio.silence(),this.updatePlayPauseButton(),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{time:e}}))}createPlayer(){const e=new Dd(this.currentSighting.timeline,(t,n)=>this.onFrame(t,n));return e.loop=this.loopEnabled,e}togglePlayPause(){this.player.seekableDuration<=0||(this.player.playbackState==="playing"?(this.player.pause(),this.soundPreview=void 0,this.sightingAudio.silence(),this.refresh()):(this.sightingAudio.resume(),this.player.play()),this.updatePlayPauseButton())}updatePlayPauseButton(){const e=this.player.playbackState==="playing";this.playPauseButton.textContent=e?"⏸":"▶";const t=this.player.seekableDuration>0;this.playPauseButton.disabled=!t;const n=t?e?this.messages.pause:this.messages.play:this.messages.noDuration;this.playPauseButton.title=n,this.playPauseButton.setAttribute("aria-label",n),this.toolbar.classList.toggle("auto-hide",e),this.fullscreenButton.classList.toggle("auto-hide",e)}toggleLoop(){this.loopEnabled=!this.loopEnabled,this.loopButton.setAttribute("aria-pressed",String(this.loopEnabled)),this.player.loop=this.loopEnabled}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.fullscreenTarget.requestFullscreen().catch(e=>{console.error("<rr0-ufo>: requestFullscreen() failed —",e)})}updateFullscreenButton(){const e=document.fullscreenElement===this.fullscreenTarget;this.fullscreenButton.title=e?this.messages.exitFullscreen:this.messages.fullscreen,this.fullscreenButton.setAttribute("aria-label",this.fullscreenButton.title)}async loadLocaleMessages(){const e=Jl(navigator.languages,qd);e!=="en"&&this.applyMessages(await Zd(e))}applyMessages(e){this.messages=e,this.timeStartLabel.title=e.currentPosition,this.timeEndLabel.title=e.duration,this.loopButton.title=e.autoReplay,this.loopButton.setAttribute("aria-label",e.autoReplay),this.updatePlayPauseButton(),this.updateFullscreenButton()}updateTimeLabels(){const e=this.currentSighting.event,t=wd(e);this.realDurationMs=t!==void 0&&t>0?t:void 0,this.realStartMs=e.time?Io(e.time):void 0;const n=this.currentSighting.timeline.duration;this.player.playbackRate=this.realDurationMs!==void 0&&n>0?n/this.realDurationMs:1,this.player.durationOverrideMs=n>0?0:this.realDurationMs??0,this.timeEndLabel.textContent=this.formatEndOfTimeline(),this.timeStartLabel.textContent=this.formatPosition(this.player.time)}formatPosition(e){if(this.realDurationMs===void 0)return cr(e);const t=this.currentSighting.timeline.duration,n=t>0&&e<=t?e/t*this.realDurationMs:e;return this.realStartMs!==void 0?Vc(Hc(this.realStartMs+n)):cr(n)}formatEndOfTimeline(){return this.realDurationMs===void 0?cr(this.currentSighting.timeline.duration):this.realStartMs!==void 0?Vc(Hc(this.realStartMs+this.realDurationMs)):cr(this.realDurationMs)}}function Hc(i){const e=new Date(i);return{hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds()}}function Vc(i){if(i.hour===void 0)return"0:00";const e=t=>String(t).padStart(2,"0");return i.second?`${e(i.hour)}:${e(i.minute??0)}:${e(i.second)}`:`${e(i.hour)}:${e(i.minute??0)}`}function cr(i){const e=Math.round(i/1e3),t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,"0")}`}const Lo="rr0-ufo";function Ou(){customElements.get(Lo)||customElements.define(Lo,Kd)}/**
|
|
294
294
|
* @license
|
|
295
295
|
* Copyright 2010-2026 Three.js Authors
|
|
296
296
|
* SPDX-License-Identifier: MIT
|
|
@@ -5034,7 +5034,7 @@ void main()
|
|
|
5034
5034
|
|
|
5035
5035
|
gl_FragColor = vec4(finalColor, max(dazzleAlpha, artifactsAlpha));
|
|
5036
5036
|
}
|
|
5037
|
-
`;let Wr;function _x(){if(Wr)return Wr;const i=256,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d");t.fillStyle="rgba(60,60,60,1)",t.fillRect(0,0,i,i);const n=[[.3,.35,.22,.5],[.7,.6,.16,.35],[.55,.8,.3,.4],[.15,.7,.12,.3],[.85,.2,.18,.3]];for(const[s,r,a,o]of n){const l=t.createRadialGradient(s*i,r*i,0,s*i,r*i,a*i);l.addColorStop(0,`rgba(200,200,200,${o})`),l.addColorStop(1,"rgba(200,200,200,0)"),t.fillStyle=l,t.fillRect(0,0,i,i)}return Wr=new Wn(e),Wr}function vx(){const i={uTime:{value:0},uResolution:{value:new Ue(1,1)},uLensPosition:{value:new Ue(0,0)},uColorGain:{value:new Me(55,55,51)},uOpacity:{value:.5},uFlareIntensity:{value:0},uStarPoints:{value:6},uGlareSize:{value:.55},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:_x()}},e=new Gt({uniforms:i,vertexShader:mx,fragmentShader:gx,transparent:!0,depthWrite:!1,depthTest:!1,blending:ra,fog:!1,name:"LensFlareShader"}),t=new Mt(new tr(2,2),e);return t.frustumCulled=!1,t.renderOrder=20,{mesh:t,uniforms:i}}const xx=2;function Mx(i){return i==="building"||i==="vehicle"}function Sx(i,e){const t=i.litKeyframes;if(!t||t.length===0)return i.lit??!1;let n=t[0];for(const s of t){if(s.t>e)break;n=s}return n.lit}const hu=Math.PI/180;function nn(i,e,t,n,s=!1){const r=s?new js({color:new Me(...t)}):new nr({color:new Me(...t)}),a=new Mt(e,r);return a.position.y=n,a.userData={emissive:s},a.castShadow=!s,a.receiveShadow=!s,i.add(a),a}const X0=[.32,.32,.3],q0=[1,.85,.5],Y0=[.25,.25,.25],Z0=[1,.97,.85],yx=[.55,.68,.72],vn=.03,xn=.05,$0={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 kt(i,e){return i?.[e]}function Mn(i,e,t,n,s,r,a,o){if(o===void 0)return;const l=new nr({color:new Me(...yx),transparent:!0,opacity:o/100}),c=new Mt(new Cn(e,t,n),l);c.position.set(s,r,a),i.add(c)}const Qt=.05,vo=[.6,.58,.53],uu=[.5,.5,.48];function ls(i,e,t,n,s,r,a,o){const l=new nr({color:new Me(...o),side:It}),c=new Mt(new Cn(e,t,n),l);c.position.set(s,r,a),i.add(c)}function Ex(i,e,t,n,s,r,a,o,l){const c=(n-r)/2,h=(g,x,m,f)=>{g<=0||(e?ls(i,g,x,Qt,m,o+f,a,l):ls(i,Qt,x,g,a,o+f,m,l))};h(t,c,0,n/2-c/2),h(t,c,0,-(n/2-c/2));const d=[...s].sort((g,x)=>g.center-x.center);let u=-t/2;for(const g of d){const m=g.center-g.main/2-u;h(m,r,u+m/2,0),u=g.center+g.main/2}const p=t/2-u;h(p,r,u+p/2,0)}function K0(i,e,t,n,s,r,a,o,l,c){const h=(n+s)/2,d=s-n,u=(p,g,x,m)=>{p.length===0?g?ls(i,x,d,Qt,0,h,m,vo):ls(i,Qt,d,x,m,h,0,vo):Ex(i,g,x,d,p,r,m,h,vo)};u(a,!0,e*2,-t+Qt),u(o,!0,e*2,t-Qt),u(l,!1,t*2,-e+Qt),u(c,!1,t*2,e-Qt),ls(i,e*2,Qt,t*2,0,n+Qt,0,uu),ls(i,e*2,Qt,t*2,0,s-Qt,0,uu)}function ql(i,e,t,n){switch(i){case"front":return{x:0,z:-(t-n)};case"behind":return{x:0,z:t-n};case"left":return{x:-(e-n),z:0};case"right":return{x:e-n,z:0};case"front-left":return{x:-(e-n),z:-Sn};case"front-right":return{x:e-n,z:-Sn};case"behind-left":return{x:-(e-n),z:Sn};case"behind-right":return{x:e-n,z:Sn}}}function J0(i,e,t,n,s,r,a){const o=ed();o.scale.setScalar(n),o.rotation.y=$0[e];const{x:l,z:c}=ql(e,s,r,a);o.position.set(l,t,c),i.add(o)}const Yl=6,Zl=6,ii=3,Us=1.4,Fs=ii*.5,Q0=1.2,j0=.35,bx=.75,Tx=1.6;function Ax(i,e,t,n){const s=new Tn,r=Math.max(1,i+1),a=r*ii;nn(s,new Cn(Yl,a,Zl),[.55,.54,.5],a/2);const o=Yl/2,l=Zl/2;for(let c=0;c<r;c++){const h=c*ii+ii/2;Mn(s,Us,Fs,xn,0,h,-l-vn,kt(e,"front")),Mn(s,Us,Fs,xn,0,h,l+vn,kt(e,"behind")),Mn(s,xn,Fs,Us,-o-vn,h,0,kt(e,"left")),Mn(s,xn,Fs,Us,o+vn,h,0,kt(e,"right"))}if(t){const c=Math.min(Math.max(n??0,0),r-1);J0(s,t,c*ii,.72,o,l,Q0);const h=d=>kt(e,d)!==void 0?[{main:Us,center:0}]:[];K0(s,o,l,c*ii,(c+1)*ii,Fs,h("front"),h("behind"),h("left"),h("right"))}return s}function wx(){const i=new Tn;return nn(i,new Di(.15,.22,2,8),[.32,.22,.14],1),nn(i,new Ea(1.4,3,8),[.16,.32,.14],3.5),i}function Rx(i){const e=new Tn;return nn(e,new Di(.05,.08,5,8),[.28,.28,.3],2.5),nn(e,new ui(.25,12,8),i?q0:X0,5.1,!0),e}const Cx=[.08,.08,.08],ni=.8,ss=1,gn=1.7,xo=.6,_i=.4,Xr=1.2,ts=.7,Sn=.5,Px=gn;function Ix(i,e,t){const n=new Tn;nn(n,new Cn(1.8,1.4,4.2),[.45,.14,.14],.7),nn(n,new Cn(ni*2,xo,ss*2),[.4,.12,.12],gn);for(const r of[-1.4,1.4])for(const a of[-.95,.95]){const o=nn(n,new Di(.4,.4,.3,12),Cx,.4);o.rotation.z=Math.PI/2,o.position.x=a,o.position.z=r}const s=i?Z0:Y0;for(const r of[-.7,.7])nn(n,new ui(.15,8,6),s,.7,!0).position.set(r,.7,-2.1);if(Mn(n,Xr,_i,xn,0,gn,-ss-vn,kt(e,"front")),Mn(n,Xr,_i,xn,0,gn,ss+vn,kt(e,"behind")),Mn(n,xn,_i,ts,-ni-vn,gn,-Sn,kt(e,"front-left")),Mn(n,xn,_i,ts,-ni-vn,gn,Sn,kt(e,"behind-left")),Mn(n,xn,_i,ts,ni+vn,gn,-Sn,kt(e,"front-right")),Mn(n,xn,_i,ts,ni+vn,gn,Sn,kt(e,"behind-right")),t){J0(n,t,bx,.5,ni,ss,j0);const r=(l,c)=>{const h=[];return kt(e,l)!==void 0&&h.push({main:ts,center:-Sn}),kt(e,c)!==void 0&&h.push({main:ts,center:Sn}),h},a=kt(e,"front")!==void 0?[{main:Xr,center:0}]:[],o=kt(e,"behind")!==void 0?[{main:Xr,center:0}]:[];K0(n,ni,ss,gn-xo/2,gn+xo/2,_i,a,o,r("front-left","behind-left"),r("front-right","behind-right"))}return n}const Dx=[.95,.9,.82];function ed(){const i=new Tn;nn(i,new Di(.25,.3,1.5,10),[.3,.3,.35],.75),nn(i,new ui(.22,10,8),[.62,.52,.46],1.72);const e=nn(i,new Ea(.07,.16,8),Dx,1.72);return e.rotation.x=-Math.PI/2,e.position.z=-.2,i}class Os{static occupantView(e){const t=e.witnessSide;if(!t)throw new Error("occupantView requires object.witnessSide to be set");const{x:n,z:s}=e.kind==="vehicle"?ql(t,ni,ss,j0):ql(t,Yl/2,Zl/2,Q0),r=e.kind==="vehicle"?Px:(e.occupiedFloor??0)*ii+Tx,a=(e.headingDeg??0)-$0[t]/hu;return{x:n,z:s,eyeY:r,headingDeg:a}}static build(e,t){const n=e.kind==="building"?Ax(e.floors??xx,e.windows,e.witnessSide,e.occupiedFloor):e.kind==="tree"?wx():e.kind==="streetlight"?Rx(t):e.kind==="vehicle"?Ix(t,e.windows,e.witnessSide):ed();return e.headingDeg!==void 0&&(n.rotation.y=-e.headingDeg*hu),n}static setLit(e,t,n){const s=t==="streetlight"?n?q0:X0:n?Z0:Y0;for(const r of e.children)!(r instanceof Mt)||!r.userData.emissive||r.material.color.setRGB(...s)}static dispose(e){for(const t of e.children)t instanceof Mt&&(t.geometry.dispose(),t.material.dispose())}}function Lx(i,e){return i.cloudCover===e.cloudCover&&i.cloudDarkness===e.cloudDarkness&&i.cloudBaseM===e.cloudBaseM&&i.precipitationType===e.precipitationType&&i.precipitationIntensity===e.precipitationIntensity&&i.windDirectionDeg===e.windDirectionDeg&&i.windSpeed===e.windSpeed&&i.storm===e.storm}const Mo=900,Nx=.5,Ws=900,Ux=6371e3,Fx=3e4;function du(i){const e=Math.sqrt(2*Ux*Math.max(i,0));return Math.max(Ws,Math.min(e,Fx))}const So=.5,Ox=850,yo=850,Eo=4,Bx=1.5,zx=-1,kx=6,$l=-4,fu=$l,Gx=3,Hx=.15,Vx=.6,Wx=40,Xx=30,qx=[0,45,90,135,180,225,270,315],Yx={en:["N","NE","E","SE","S","SW","W","NW"],fr:["N","NE","E","SE","S","SO","O","NO"]},Zx=["en","fr"],$x=880,pu=40,Kx=10,Jx=1,Qx=150,bo=55,mu=.5,jx=700,e3=250/Po,t3=12,n3=.5,i3=5,To=6,ns=[.92,.92,.95],Ao=[.15,.15,.19],gu={snow:{fallSpeedMPerS:2,size:.3,color:new Me(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new Me(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},rs=0,s3=0,_u=3e3,Bs=20,r3=15,vu=rs,a3=40,xu=1,o3=9;function l3(i){return xu+(o3-xu)*i}const c3=new Me(.75,.82,.92),h3=10,u3=.5;function d3(i){return td(i/h3,u3,1)}const is=200,Mu=.18,Su=.32,f3=.35,p3=new Me(.85,.9,.98),yu=5,Eu=.85,bu=.01;function wo(i,e){return Math.round(i*(bu+(1-bu)*e))}const Tu=230,Au=.7,wu=.05,m3=.6,g3=.7,_3=.15,Ru=.35,v3=3,x3=1/12,M3=.5,Cu=8,Pu=25,Iu=.12,S3={Venus:new Me(1,.96,.85),Mars:new Me(1,.55,.4),Jupiter:new Me(.95,.87,.72),Saturn:new Me(.92,.86,.68)};class y3{renderer;scene=new Zf;camera;celestialGroup=new Tn;skyMesh;groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];decorGroups=new Map;celestialLight=new _p(16777215,0);celestialLightTarget=new St;skyLight=new fp(16777215,0,0);streetlightLights=new Map;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;raycaster=new ro;weather=Nu;observerElevationM=0;groundRadius=Ws;terrainRadius=Ws;cloudMesh;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new U;rainLastVerticalFacing=-1;lightningArmed=!1;nextLightningAtS=null;lightningFlashRemainingS=0;baseFogColor=[0,0,0];lastSunPosition;lensFlare;dazzleIntensity=1;lensFlareArtifactIntensity=0;sunWorldPosition=new U;sunVisible=!1;lensFlareScratch=new U;sunOcclusionRaycaster=new ro;sunOcclusionDirectionScratch=new U;ufoOcclusionRaycaster=new ro;onLightningFlash;constructor(e,t=Z2(),n){this.renderer=new mv({canvas:e,antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Xs,this.camera=new Yt(60,e.width/Math.max(e.height,1),.1,Mo*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=t,this.onLightningFlash=n,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-120,this.celestialLight.shadow.camera.right=120,this.celestialLight.shadow.camera.top=120,this.celestialLight.shadow.camera.bottom=-120,this.celestialLight.shadow.camera.near=1,this.celestialLight.shadow.camera.far=1e3,this.celestialLight.shadow.bias=-.0015,this.celestialLight.target=this.celestialLightTarget,this.scene.add(this.celestialLight,this.celestialLightTarget,this.skyLight),this.scene.add(this.celestialGroup)}get currentTerrainAttribution(){return this.terrainAttribution}resize(e,t){this.renderer.setSize(e,t,!1),this.camera.aspect=e/Math.max(t,1),this.camera.updateProjectionMatrix(),this.render()}setObserverPose(e){e.headingDeg!==void 0?this.camera.rotation.set(e.pitchDeg*mn,-e.headingDeg*mn,0,"YXZ"):this.camera.rotation.set(e.pitchDeg*mn,this.camera.rotation.y,0,"YXZ"),e.elevationM!==this.observerElevationM&&(this.observerElevationM=e.elevationM,this.syncCloudLayer(),Math.abs(du(e.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/Ws),this.camera.far=Math.max(Mo*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.camera.position.y=1.6+e.elevationM,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==e.fovDeg&&(this.camera.fov=e.fovDeg,this.camera.updateProjectionMatrix())}setTerrainProviders(e){this.terrainProviders=e,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.terrainBuildToken++}setTerrainOrigin(e,t,n){if(e===void 0||t===void 0)return;const s=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-s)<s*.1){const{x:a,z:o}=Ci(e,t,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(a*a+o*o)<Qx*(s/Ws))return}this.terrainOrigin={lat:e,lng:t},this.terrainRadius=s;const r=++this.terrainBuildToken;ex(e,t,this.terrainProviders,s).then(({mesh:a,attribution:o})=>{r===this.terrainBuildToken&&(this.disposeMesh(this.terrainMesh),a.renderOrder=Jx,this.terrainMesh=a,this.terrainAttribution=o,this.scene.add(a),this.render(),n?.())}).catch(a=>{console.warn("Terrain build failed, keeping the flat ground fallback:",a),n?.()})}setShowCompass(e){this.showCompass!==e&&(this.showCompass=e,this.disposeCompassLabels(),e&&this.buildCompassLabels(),this.render())}setDazzleIntensity(e){this.dazzleIntensity!==e&&(this.dazzleIntensity=e,this.lensFlare&&(this.lensFlare.uniforms.uOpacity.value=mu*e,this.lastSunPosition&&this.applyLensFlareTint(Ls(this.lastSunPosition.altitudeDeg))),this.render())}setLensFlareArtifactIntensity(e){this.lensFlareArtifactIntensity!==e&&(this.lensFlareArtifactIntensity=e,this.lensFlare&&(this.lensFlare.uniforms.uFlareIntensity.value=e),this.render())}applyLensFlareTint(e){this.lensFlare&&this.lensFlare.uniforms.uColorGain.value.setRGB(bo*this.dazzleIntensity*e[0],bo*this.dazzleIntensity*e[1],bo*this.dazzleIntensity*e[2])}setCompassHovered(e){this.compassHovered!==e&&(this.compassHovered=e,this.updateCompassVisibility())}setCompassForced(e){this.compassForced!==e&&(this.compassForced=e,this.updateCompassVisibility())}updateCompassVisibility(){const e=this.compassHovered||this.compassForced;for(const t of this.compassSprites)t.visible=e;this.render()}setWeather(e){Lx(this.weather,e)||(this.weather=e,this.buildClouds(),this.buildPrecipitation(),this.lightningArmed=e.storm&&e.cloudDarkness>=M3,this.lightningArmed||(this.nextLightningAtS=null,this.lightningFlashRemainingS=0,this.scene.fog&&this.scene.fog.color.setRGB(...this.baseFogColor)),this.syncAnimationLoop(),this.render())}setDecor(e){if(this.decorObjects!==e){this.decorObjects=e;for(const t of this.decorGroups.values())t.removeFromParent(),Os.dispose(t);this.decorGroups.clear(),this.streetlightLights.clear();for(const t of e){const n=Os.build(t,t.lit??!1);this.scene.add(n),this.decorGroups.set(t.id,n),t.kind==="streetlight"&&this.addStreetlightLight(t.id,n)}this.celestialLight.castShadow=this.decorGroups.size>0}}updateDecorAnchoring(e,t){const n=e?.lat!==void 0&&e.lng!==void 0&&t?.lat!==void 0&&t?.lng!==void 0?Ci(e.lat,e.lng,t.lat,t.lng):{x:0,z:0},s=this.decorObjects.find(a=>a.witnessSide!==void 0&&Mx(a.kind)),r={x:0,z:0};if(s){const a=Os.occupantView(s),o=-(s.headingDeg??0)*mn,l=a.x*Math.cos(o)+a.z*Math.sin(o),c=-a.x*Math.sin(o)+a.z*Math.cos(o),h=s.eastM+n.x,d=-s.northM+n.z;r.x=-(h+l),r.z=-(d+c),this.camera.position.y=a.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*mn,-(a.headingDeg+this.indoorLookYawDeg)*mn,0,"YXZ")}for(const a of this.decorObjects){const o=this.decorGroups.get(a.id);o&&o.position.set(a.eastM+n.x+r.x,s3,-a.northM+n.z+r.z)}}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(e,t){this.indoorLookYawDeg=e,this.indoorLookPitchDeg=t}updateDecorLitState(e){for(const t of this.decorObjects){if(t.kind!=="streetlight"&&t.kind!=="vehicle")continue;const n=this.decorGroups.get(t.id);if(!n)continue;const s=Sx(t,e);Os.setLit(n,t.kind,s);const r=this.streetlightLights.get(t.id);r&&(r.visible=s)}}addStreetlightLight(e,t){const n=t.children.find(r=>r.userData.emissive);if(!n)return;const s=new mp(16764006,Wx,Xx);s.position.copy(n.position),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,t.add(s),this.streetlightLights.set(e,s)}setAstronomy(e){const t=M0(e.sun.altitudeDeg),n=t.horizon;this.baseFogColor=n,this.lastSunPosition=e.sun,this.buildSky(e.sun),this.buildGround(),this.updateCloudLighting(e.sun,n),this.updateCelestialLight(e,t.zenith,n),this.buildStars(e.stars,e.sun.altitudeDeg),this.setBodyMesh("sun",e.sun,Eo,new Me(1,.96,.88),e.sun.magnitude),this.setMoonMesh(e.moon),this.buildPlanets(e.planets),this.scene.fog=new hc(new Me(...n),this.groundRadius*.2,this.groundRadius),this.syncAnimationLoop(),this.render()}updateCelestialLight(e,t,n){this.skyLight.color.setRGB(t[0],t[1],t[2]),this.skyLight.groundColor.setRGB(n[0],n[1],n[2]),this.skyLight.intensity=Vx;const s=e.sun.altitudeDeg>=fu,r=!s&&e.moon.altitudeDeg>=fu;if(!s&&!r){this.celestialLight.intensity=0;return}const a=s?e.sun:e.moon,{x:o,y:l,z:c}=ji(a.altitudeDeg,a.azimuthDeg,yo);this.celestialLight.position.set(o,l,c);const h=Ls(a.altitudeDeg);this.celestialLight.color.setRGB(h[0],h[1],h[2]);const d=Math.max(0,Math.sin(Math.max(a.altitudeDeg,0)*mn));this.celestialLight.intensity=(s?Gx:Hx)*d,this.celestialLight.castShadow=this.decorGroups.size>0}render(){this.updateLensFlarePosition(),this.renderer.render(this.scene,this.camera)}updateLensFlarePosition(){const e=this.lensFlare;if(!e)return;if(!this.sunVisible){e.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){e.mesh.visible=!1;return}if(this.isSunOccluded()){e.mesh.visible=!1;return}e.mesh.visible=!0;const t=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);e.uniforms.uLensPosition.value.set(t.x,t.y),e.uniforms.uResolution.value.set(this.renderer.domElement.width,this.renderer.domElement.height)}isSunOccluded(){const e=[];this.groundMesh&&e.push(this.groundMesh),this.terrainMesh&&e.push(this.terrainMesh);for(const r of this.decorGroups.values())e.push(r);if(e.length===0)return!1;const t=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),n=t.length();t.normalize(),this.sunOcclusionRaycaster.set(this.camera.position,t);const s=this.sunOcclusionRaycaster.intersectObjects(e,!0)[0];return s!==void 0&&s.distance<n}isScreenPointOccluded(e,t,n,s){if(this.isBehindCloudLayer(e,t,s))return!0;const r=[];for(const a of this.decorObjects){if(!a.occludesSourceIds?.includes(n))continue;const o=this.decorGroups.get(a.id);o&&r.push(o)}return r.length===0?!1:(this.ufoOcclusionRaycaster.setFromCamera(new Ue(e,t),this.camera),this.ufoOcclusionRaycaster.near=Nx,this.ufoOcclusionRaycaster.intersectObjects(r,!0).length>0)}isBehindCloudLayer(e,t,n){if(!n||!this.cloudMesh||this.weather.cloudCover<=0)return!1;if(n.declared)return!0;const s=n.distanceM;if(s===void 0)return!1;const r=this.cloudLayerOffset();this.ufoOcclusionRaycaster.setFromCamera(new Ue(e,t),this.camera);const a=this.ufoOcclusionRaycaster.ray.direction;return Math.sign(a.y||1)!==Math.sign(r)||Math.abs(this.cloudLayerHeightM())/Math.max(Math.abs(a.y),.026)>=s?!1:yt.alphaAt(a,Math.abs(r),this.weather.cloudCover)>=n3}cloudLayerHeightM(){return(this.weather.cloudBaseM??Po)-this.observerElevationM}pickBodyAt(e,t){this.raycaster.setFromCamera(new Ue(e,t),this.camera);const n=[...this.hitAreas.entries()],s=this.raycaster.intersectObjects(n.map(([,r])=>r))[0];if(s)return n.find(([,r])=>r===s.object)?.[0]}pickDecorAt(e,t){this.raycaster.setFromCamera(new Ue(e,t),this.camera);const n=[...this.decorGroups.entries()],s=this.raycaster.intersectObjects(n.map(([,a])=>a),!0)[0];if(!s)return;let r=s.object;for(;r&&!n.some(([,a])=>a===r);)r=r.parent;return n.find(([,a])=>a===r)?.[0]}dispose(){this.stopTwinkle(),this.terrainBuildToken++,this.disposeMesh(this.skyMesh),this.disposeMesh(this.groundMesh),this.disposeMesh(this.terrainMesh),this.disposeCloudSystem(),this.disposePrecipitationPoints(),this.disposeRain(),this.disposeStarTiers();for(const e of this.bodyMeshes.values())this.disposeMesh(e);this.bodyMeshes.clear();for(const e of[...this.hitAreas.keys()])this.disposeHitArea(e);for(const e of[...this.glareSprites.keys()])this.disposeGlare(e);this.disposeCompassLabels();for(const e of this.decorGroups.values())Os.dispose(e);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()}startTwinkle(){if(this.animationFrameId!==null||!this.needsAnimationLoop())return;let e;const t=n=>{const s=e===void 0?0:Math.min((n-e)/1e3,x3);e=n,this.updateTwinkle(n/1e3),this.updatePrecipitation(n/1e3,s),this.updateRain(s),this.updateLightning(n/1e3,s),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=n/1e3),this.render(),this.animationFrameId=requestAnimationFrame(t)};this.animationFrameId=requestAnimationFrame(t)}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}needsAnimationLoop(){return this.starTiers.length>0||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.lightningArmed||this.lensFlare!==void 0&&this.sunVisible}syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(e){this.disposeMesh(this.skyMesh);const t=new ui(Mo,32,16),n=t.attributes.position,s=[];for(let a=0;a<n.count;a++){const{altitudeDeg:o,azimuthDeg:l}=xv(n.getX(a),n.getY(a),n.getZ(a)),c=yv(o,l,e.azimuthDeg,e.altitudeDeg);s.push(c[0],c[1],c[2])}t.setAttribute("color",new Et(s,3));const r=new js({vertexColors:!0,side:It,fog:!1});this.skyMesh=new Mt(t,r),this.celestialGroup.add(this.skyMesh)}buildGround(){this.disposeMesh(this.groundMesh),this.groundRadius=du(this.observerElevationM);const e=new fc(this.groundRadius,48),t=new nr({color:new Me(So,So,So),fog:!0});this.groundMesh=new Mt(e,t),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh)}setBodyMesh(e,t,n,s,r){if(this.disposeMesh(this.bodyMeshes.get(e)),this.disposeHitArea(e),this.disposeGlare(e),t.altitudeDeg<$l){this.bodyMeshes.delete(e),e==="sun"&&(this.sunVisible=!1);return}const{x:a,y:o,z:l}=ji(t.altitudeDeg,t.azimuthDeg,yo),c=Ls(t.altitudeDeg),h=new Me(s.r*c[0],s.g*c[1],s.b*c[2]),d=new ui(n,16,16),u=new js({color:h,fog:!1}),p=new Mt(d,u);if(p.position.set(a,o,l),this.celestialGroup.add(p),this.bodyMeshes.set(e,p),this.setHitArea(e,a,o,l,n),e!=="sun"&&this.setGlare(e,a,o,l,r,h),e==="sun"){this.sunVisible=!0;const g=this.celestialGroup.scale.x;this.sunWorldPosition.set(a*g,o*g+this.celestialGroup.position.y,l*g),this.lensFlare||(this.lensFlare=vx(),this.lensFlare.uniforms.uOpacity.value=mu*this.dazzleIntensity,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(c)}}setMoonMesh(e){const t="moon";if(this.disposeMesh(this.bodyMeshes.get(t)),this.disposeHitArea(t),this.disposeGlare(t),e.altitudeDeg<$l){this.bodyMeshes.delete(t);return}const{x:n,y:s,z:r}=ji(e.altitudeDeg,e.azimuthDeg,yo),a=Ls(e.altitudeDeg),o=new Me(a[0],a[1],a[2]),l=new ks({map:D3(e.phase),color:o,fog:!1}),c=new Mr(l);c.position.set(n,s,r);const h=Eo*2;c.scale.set(h,h,1),this.celestialGroup.add(c),this.bodyMeshes.set(t,c),this.setHitArea(t,n,s,r,Eo),this.setGlare(t,n,s,r,e.magnitude,o)}setHitArea(e,t,n,s,r){const a=new ks({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1}),o=new Mr(a);o.position.set(t,n,s);const l=r*kx;o.scale.set(l,l,1),this.celestialGroup.add(o),this.hitAreas.set(e,o)}disposeHitArea(e){const t=this.hitAreas.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.hitAreas.delete(e))}setGlare(e,t,n,s,r,a){this.disposeGlare(e);const o=bv(r);if(o<=0)return;const l=wv(o),c=new ks({map:I3(),color:a,transparent:!0,opacity:Pv(o),blending:ra,depthWrite:!1,fog:!1}),h=new Mr(c);h.position.set(t,n,s),h.scale.set(l*2,l*2,1),this.celestialGroup.add(h),this.glareSprites.set(e,h)}disposeGlare(e){const t=this.glareSprites.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.glareSprites.delete(e))}buildPlanets(e){const t=new Set(["sun","moon"]);for(const n of e){t.add(n.body);const s=Yh(n.magnitude),r=Zh(s),a=S3[n.body]??new Me(1,1,1),o=new Me(a.r*r,a.g*r,a.b*r),l=Bx*(.5+.5*s);this.setBodyMesh(n.body,n.position,l,o,n.magnitude)}for(const n of[...this.bodyMeshes.keys()])t.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n))}buildStars(e,t){if(this.disposeStarTiers(),!e||e.catalog.count===0){this.syncAnimationLoop();return}const{catalog:n,date:s,observer:r}=e,a=gv(t),o=Ro(1337),l=[];for(let c=0;c<n.count;c++){const h=n.mag[c];if(h>a)continue;const{altitudeDeg:d,azimuthDeg:u}=I2(n.ra[c],n.dec[c],s,r);if(d<zx)continue;const{x:p,y:g,z:x}=ji(d,u,Ox);l.push({x:p,y:g,z:x,brightness:Yh(h),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}this.starTiers=y0.map((c,h)=>{const d=l.filter(M=>Dv(M.brightness)===h),u=new Float32Array(d.length*3),p=new Float32Array(d.length),g=new Float32Array(d.length),x=new Float32Array(d.length);d.forEach((M,y)=>{u[y*3]=M.x,u[y*3+1]=M.y,u[y*3+2]=M.z,p[y]=M.brightness,g[y]=M.phase,x[y]=M.speedFactor});const m=new bt;m.setAttribute("position",new pt(u,3));const f=new pt(new Float32Array(d.length*3),3);m.setAttribute("color",f);const A=new r0({vertexColors:!0,size:c.size,sizeAttenuation:!1,fog:!1}),w=new na(m,A);return this.celestialGroup.add(w),{points:w,colorAttribute:f,brightness:p,phase:g,speedFactor:x}}),this.updateTwinkle(0),this.startTwinkle()}updateTwinkle(e){for(const t of this.starTiers){const n=t.colorAttribute.array;for(let s=0;s<t.brightness.length;s++){const r=Uv(t.brightness[s],{phase:t.phase[s],speedFactor:t.speedFactor[s]},e),a=Zh(t.brightness[s])*r;n[s*3]=a,n[s*3+1]=a,n[s*3+2]=a}t.colorAttribute.needsUpdate=!0}}buildClouds(){if(this.disposeCloudSystem(),this.weather.cloudCover<=0)return;const e=this.weather.cloudDarkness,t=new Me(ns[0]+(Ao[0]-ns[0])*e,ns[1]+(Ao[1]-ns[1])*e,ns[2]+(Ao[2]-ns[2])*e),{material:n,uniforms:s}=dx(t,this.weather.cloudCover,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const r=px(jx);this.cloudMesh=new Mt(r,n),this.cloudLayerOffset()<0&&(this.cloudMesh.scale.y=-1),this.cloudMesh.renderOrder=i3,this.celestialGroup.add(this.cloudMesh)}syncCloudLayer(){const e=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(e)),this.cloudMesh&&(this.cloudMesh.scale.y=e<0?-1:1)}cloudLayerOffset(){const t=((this.weather.cloudBaseM??Po)-this.observerElevationM)*e3;return Math.sign(t||1)*Math.max(Math.abs(t),t3)}updateCloudLighting(e,t){if(!this.cloudUniforms)return;const{x:n,y:s,z:r}=ji(e.altitudeDeg,e.azimuthDeg,1),a=Ls(e.altitudeDeg),o=Math.max(0,Math.sin(Math.max(e.altitudeDeg,0)*mn));this.cloudUniforms.sunDir.value.set(n,s,r),this.cloudUniforms.sunColor.value.setRGB(a[0]*o,.96*a[1]*o,.88*a[2]*o),this.cloudUniforms.ambientColor.value.setRGB(t[0],t[1],t[2])}disposeCloudSystem(){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}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const e=this.weather.precipitationType;if(e==="none")return;if(e==="rain"){this.buildRain();return}const t=gu[e],n=t.poolSize,s=Ro(9001),r=new Float32Array(n*3),a=new Float32Array(n),o=new Float32Array(n),l=new Float32Array(n),c=new Float32Array(n),h=new Float32Array(n),d=new Float32Array(n),u=new Float32Array(n),p=new Float32Array(n),g=new Float32Array(n);for(let w=0;w<n;w++){const M=s()*Math.PI*2,y=s()*t.radiusM;r[w*3]=Math.cos(M)*y,r[w*3+1]=rs+s()*(t.topYM-rs),r[w*3+2]=Math.sin(M)*y,a[w]=s()*Math.PI*2,o[w]=.7+s()*.6,l[w]=.6+s()*.8,c[w]=.4+s()*1.2}const x=new bt;x.setAttribute("position",new pt(r,3)),x.setDrawRange(0,wo(n,this.weather.precipitationIntensity));const m={uSize:{value:t.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:t.opacity},uColor:{value:t.color},uHazeColor:{value:new Me(...this.baseFogColor)},uTexture:{value:E3(e)},uNearFocusDistance:{value:yu},uHazeDistance:{value:t.radiusM*Eu}},f=new Gt({uniforms:m,vertexShader:C3,fragmentShader:P3,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const A=new na(x,f);A.renderOrder=To,this.scene.add(A),this.precipitationPoints=A,this.precipitationPositions=r,this.precipitationPhase=a,this.precipitationSpeedJitter=o,this.precipitationWobbleFreqJitter=l,this.precipitationWobbleAmpJitter=c,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=d,this.precipitationBounceDuration=u,this.precipitationBounceVelX=p,this.precipitationBounceVelZ=g}updatePrecipitation(e,t){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter||(this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor),t<=0))return;const n=this.weather.precipitationType;if(n==="none"||n==="rain")return;const s=gu[n],r=this.weather.windDirectionDeg*mn,a=Math.sin(r)*this.weather.windSpeed*s.driftSensitivity,o=-Math.cos(r)*this.weather.windSpeed*s.driftSensitivity,l=this.precipitationPositions,c=this.precipitationPhase,h=this.precipitationSpeedJitter,d=this.precipitationWobbleFreqJitter,u=this.precipitationWobbleAmpJitter,p=this.precipitationBounceRemaining,g=this.precipitationBounceHeight,x=this.precipitationBounceDuration,m=this.precipitationBounceVelX,f=this.precipitationBounceVelZ,A=n==="snow"&&d&&u,w=n==="hail"&&p&&g&&x&&m&&f;for(let M=0,y=0;M<l.length;M+=3,y++){if(w&&p[y]>0){if(p[y]-=t,p[y]<=0){const v=Math.random()*Math.PI*2,E=Math.sqrt(Math.random())*s.radiusM;l[M]=Math.cos(v)*E,l[M+1]=s.topYM,l[M+2]=Math.sin(v)*E,p[y]=0}else{const v=1-p[y]/x[y];l[M+1]=rs+Math.sin(Math.PI*v)*g[y],l[M]=Yr(l[M]+(a+m[y])*t,s.radiusM),l[M+2]=Yr(l[M+2]+(o+f[y])*t,s.radiusM)}continue}let b=0,R=0;if(A){const v=m3*d[y],E=g3*u[y];b=Math.sin(e*v*Math.PI*2+c[y])*E,R=Math.sin(e*v*Math.PI*2+c[y]+Math.PI/2)*E}if(l[M]+=(a+b)*t,l[M+1]-=s.fallSpeedMPerS*h[y]*t,l[M+2]+=(o+R)*t,l[M]=Yr(l[M],s.radiusM),l[M+2]=Yr(l[M+2],s.radiusM),l[M+1]<rs){if(w){g[y]=Ru*(.2+Math.random()*1.6),x[y]=_3*(.5+Math.random()),p[y]=x[y];const P=Math.random()*Math.PI*2,C=v3*(g[y]/Ru);m[y]=Math.cos(P)*C,f[y]=Math.sin(P)*C,l[M+1]=rs;continue}const v=Math.random()*Math.PI*2,E=Math.sqrt(Math.random())*s.radiusM;l[M]=Math.cos(v)*E,l[M+1]=s.topYM,l[M+2]=Math.sin(v)*E}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const e=l3(this.weather.precipitationIntensity);this.rainSystem=cx({count:_u,radiusM:Bs,heightM:r3,bottomYM:vu,overallSpeed:a3,color:c3,opacity:.85,visibleCount:wo(_u,this.weather.precipitationIntensity),speedStreak:d3(e),pixelSize:Tu,seed:9001,nearFocusDistanceM:yu,hazeDistanceM:Bs*Eu,hazeColor:new Me(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.rainSystem.points.renderOrder=To,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const e=Ro(4242),t=new Float32Array(is*3),n=new Float32Array(is),s=new Float32Array(is),r=new Float32Array(is);for(let h=0;h<is;h++){const d=e()*Math.PI*2,u=Math.sqrt(e())*Bs;t[h*3]=Math.cos(d)*u,t[h*3+1]=vu,t[h*3+2]=Math.sin(d)*u,s[h]=qr(Mu,Su),n[h]=e()*s[h],r[h]=n[h]/s[h]}const a=new bt;a.setAttribute("position",new pt(t,3));const o=new pt(r,1);a.setAttribute("aLife",o),a.setDrawRange(0,wo(is,this.weather.precipitationIntensity));const l=new Gt({uniforms:{uMaxSize:{value:f3},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:p3},uTexture:{value:A3()}},vertexShader:w3,fragmentShader:R3,transparent:!0,depthWrite:!1}),c=new na(a,l);c.renderOrder=To,this.scene.add(c),this.rainSplashSystem={points:c,positions:t,life:n,duration:s,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}updateRain(e){const t=this.rainSystem;if(!t)return;t.uniforms.uTime.value+=e,t.uniforms.uHazeColor.value.setRGB(...this.baseFogColor);const n=this.weather.windDirectionDeg*mn,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,a=Bs,o=c=>(c%(a*2)+a*3)%(a*2)-a;t.uniforms.uWindOffset.value.set(o(t.uniforms.uWindOffset.value.x+s*e),o(t.uniforms.uWindOffset.value.y+r*e)),this.camera.getWorldDirection(this.rainCameraDirection);const l=Math.abs(this.rainCameraDirection.y);if(Math.abs(l-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=l;const c=Au+(1-Au)*(1-l),h=wu+(1-wu)*(1-l);t.uniforms.uUvSquash.value=h,t.uniforms.uPixelSize.value=Tu*c*(.5+.5*h)}this.updateRainSplashes(e)}updateRainSplashes(e){const t=this.rainSplashSystem;if(!t||e<=0)return;const{positions:n,life:s,duration:r,lifeAttribute:a}=t,o=a.array;for(let l=0,c=0;l<n.length;l+=3,c++){if(s[c]+=e,s[c]>=r[c]){const h=Math.random()*Math.PI*2,d=Math.sqrt(Math.random())*Bs;n[l]=Math.cos(h)*d,n[l+2]=Math.sin(h)*d,r[c]=qr(Mu,Su),s[c]=0}o[c]=s[c]/r[c]}t.points.geometry.attributes.position.needsUpdate=!0,a.needsUpdate=!0}updateLightning(e,t){if(this.lightningArmed){if(this.lightningFlashRemainingS>0){this.lightningFlashRemainingS=Math.max(0,this.lightningFlashRemainingS-t);const n=this.lightningFlashRemainingS/Iu;this.scene.fog&&this.scene.fog.color.setRGB(this.baseFogColor[0]+(1-this.baseFogColor[0])*n,this.baseFogColor[1]+(1-this.baseFogColor[1])*n,this.baseFogColor[2]+(1-this.baseFogColor[2])*n);return}if(this.nextLightningAtS===null){this.nextLightningAtS=e+qr(Cu,Pu);return}e>=this.nextLightningAtS&&(this.lightningFlashRemainingS=Iu,this.nextLightningAtS=e+qr(Cu,Pu),this.onLightningFlash?.())}}buildCompassLabels(){const e=Jl(navigator.languages,Zx),t=Yx[e];this.compassSprites=qx.map((n,s)=>{const r=t[s],a=new ks({map:L3(r),depthTest:!1,fog:!1}),o=new Mr(a),{x:l,y:c,z:h}=ji(0,n,$x);return o.position.set(l,c,h),o.scale.set(pu,pu,1),o.renderOrder=Kx,o.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(o),o})}disposeCompassLabels(){for(const e of this.compassSprites)e.removeFromParent(),e.material.map?.dispose(),e.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const e of this.starTiers)this.disposeMesh(e.points);this.starTiers=[]}disposeMesh(e){if(!e)return;e.removeFromParent(),"geometry"in e&&e.geometry.dispose();const t=e.material;for(const n of Array.isArray(t)?t:[t]){const s=n.map;s&&s.dispose(),n.dispose()}}}const mn=Math.PI/180;function td(i,e,t){return Math.max(e,Math.min(t,i))}function qr(i,e){return i+Math.random()*(e-i)}function Yr(i,e){return(i%(e*2)+e*3)%(e*2)-e}let Zr,$r;function E3(i){switch(i){case"snow":return b3();case"hail":return T3()}}function b3(){if(Zr)return Zr;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,0.95)"),n.addColorStop(.5,"rgba(255,255,255,0.55)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Zr=new Wn(e),Zr}function T3(){if($r)return $r;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,1)"),n.addColorStop(.55,"rgba(255,255,255,0.95)"),n.addColorStop(.8,"rgba(255,255,255,0.4)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),$r=new Wn(e),$r}let Kr;function A3(){if(Kr)return Kr;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,0)"),n.addColorStop(.4,"rgba(255,255,255,0)"),n.addColorStop(.6,"rgba(255,255,255,0.9)"),n.addColorStop(.8,"rgba(255,255,255,0.25)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Kr=new Wn(e),Kr}const w3=`
|
|
5037
|
+
`;let Wr;function _x(){if(Wr)return Wr;const i=256,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d");t.fillStyle="rgba(60,60,60,1)",t.fillRect(0,0,i,i);const n=[[.3,.35,.22,.5],[.7,.6,.16,.35],[.55,.8,.3,.4],[.15,.7,.12,.3],[.85,.2,.18,.3]];for(const[s,r,a,o]of n){const l=t.createRadialGradient(s*i,r*i,0,s*i,r*i,a*i);l.addColorStop(0,`rgba(200,200,200,${o})`),l.addColorStop(1,"rgba(200,200,200,0)"),t.fillStyle=l,t.fillRect(0,0,i,i)}return Wr=new Wn(e),Wr}function vx(){const i={uTime:{value:0},uResolution:{value:new Ue(1,1)},uLensPosition:{value:new Ue(0,0)},uColorGain:{value:new Me(55,55,51)},uOpacity:{value:.5},uFlareIntensity:{value:0},uStarPoints:{value:6},uGlareSize:{value:.55},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:_x()}},e=new Gt({uniforms:i,vertexShader:mx,fragmentShader:gx,transparent:!0,depthWrite:!1,depthTest:!1,blending:ra,fog:!1,name:"LensFlareShader"}),t=new Mt(new tr(2,2),e);return t.frustumCulled=!1,t.renderOrder=20,{mesh:t,uniforms:i}}const xx=2;function Mx(i){return i==="building"||i==="vehicle"}function Sx(i,e){const t=i.litKeyframes;if(!t||t.length===0)return i.lit??!1;let n=t[0];for(const s of t){if(s.t>e)break;n=s}return n.lit}const hu=Math.PI/180;function nn(i,e,t,n,s=!1){const r=s?new js({color:new Me(...t)}):new nr({color:new Me(...t)}),a=new Mt(e,r);return a.position.y=n,a.userData={emissive:s},a.castShadow=!s,a.receiveShadow=!s,i.add(a),a}const X0=[.32,.32,.3],q0=[1,.85,.5],Y0=[.25,.25,.25],Z0=[1,.97,.85],yx=[.55,.68,.72],vn=.03,xn=.05,$0={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 kt(i,e){return i?.[e]}function Mn(i,e,t,n,s,r,a,o){if(o===void 0)return;const l=new nr({color:new Me(...yx),transparent:!0,opacity:o/100}),c=new Mt(new Cn(e,t,n),l);c.position.set(s,r,a),i.add(c)}const Qt=.05,vo=[.6,.58,.53],uu=[.5,.5,.48];function ls(i,e,t,n,s,r,a,o){const l=new nr({color:new Me(...o),side:It}),c=new Mt(new Cn(e,t,n),l);c.position.set(s,r,a),i.add(c)}function Ex(i,e,t,n,s,r,a,o,l){const c=(n-r)/2,h=(g,x,m,f)=>{g<=0||(e?ls(i,g,x,Qt,m,o+f,a,l):ls(i,Qt,x,g,a,o+f,m,l))};h(t,c,0,n/2-c/2),h(t,c,0,-(n/2-c/2));const d=[...s].sort((g,x)=>g.center-x.center);let u=-t/2;for(const g of d){const m=g.center-g.main/2-u;h(m,r,u+m/2,0),u=g.center+g.main/2}const p=t/2-u;h(p,r,u+p/2,0)}function K0(i,e,t,n,s,r,a,o,l,c){const h=(n+s)/2,d=s-n,u=(p,g,x,m)=>{p.length===0?g?ls(i,x,d,Qt,0,h,m,vo):ls(i,Qt,d,x,m,h,0,vo):Ex(i,g,x,d,p,r,m,h,vo)};u(a,!0,e*2,-t+Qt),u(o,!0,e*2,t-Qt),u(l,!1,t*2,-e+Qt),u(c,!1,t*2,e-Qt),ls(i,e*2,Qt,t*2,0,n+Qt,0,uu),ls(i,e*2,Qt,t*2,0,s-Qt,0,uu)}function ql(i,e,t,n){switch(i){case"front":return{x:0,z:-(t-n)};case"behind":return{x:0,z:t-n};case"left":return{x:-(e-n),z:0};case"right":return{x:e-n,z:0};case"front-left":return{x:-(e-n),z:-Sn};case"front-right":return{x:e-n,z:-Sn};case"behind-left":return{x:-(e-n),z:Sn};case"behind-right":return{x:e-n,z:Sn}}}function J0(i,e,t,n,s,r,a){const o=ed();o.scale.setScalar(n),o.rotation.y=$0[e];const{x:l,z:c}=ql(e,s,r,a);o.position.set(l,t,c),i.add(o)}const Yl=6,Zl=6,ii=3,Us=1.4,Fs=ii*.5,Q0=1.2,j0=.35,bx=.75,Tx=1.6;function Ax(i,e,t,n){const s=new Tn,r=Math.max(1,i+1),a=r*ii;nn(s,new Cn(Yl,a,Zl),[.55,.54,.5],a/2);const o=Yl/2,l=Zl/2;for(let c=0;c<r;c++){const h=c*ii+ii/2;Mn(s,Us,Fs,xn,0,h,-l-vn,kt(e,"front")),Mn(s,Us,Fs,xn,0,h,l+vn,kt(e,"behind")),Mn(s,xn,Fs,Us,-o-vn,h,0,kt(e,"left")),Mn(s,xn,Fs,Us,o+vn,h,0,kt(e,"right"))}if(t){const c=Math.min(Math.max(n??0,0),r-1);J0(s,t,c*ii,.72,o,l,Q0);const h=d=>kt(e,d)!==void 0?[{main:Us,center:0}]:[];K0(s,o,l,c*ii,(c+1)*ii,Fs,h("front"),h("behind"),h("left"),h("right"))}return s}function wx(){const i=new Tn;return nn(i,new Di(.15,.22,2,8),[.32,.22,.14],1),nn(i,new Ea(1.4,3,8),[.16,.32,.14],3.5),i}function Rx(i){const e=new Tn;return nn(e,new Di(.05,.08,5,8),[.28,.28,.3],2.5),nn(e,new ui(.25,12,8),i?q0:X0,5.1,!0),e}const Cx=[.08,.08,.08],ni=.8,ss=1,gn=1.7,xo=.6,_i=.4,Xr=1.2,ts=.7,Sn=.5,Px=gn;function Ix(i,e,t){const n=new Tn;nn(n,new Cn(1.8,1.4,4.2),[.45,.14,.14],.7),nn(n,new Cn(ni*2,xo,ss*2),[.4,.12,.12],gn);for(const r of[-1.4,1.4])for(const a of[-.95,.95]){const o=nn(n,new Di(.4,.4,.3,12),Cx,.4);o.rotation.z=Math.PI/2,o.position.x=a,o.position.z=r}const s=i?Z0:Y0;for(const r of[-.7,.7])nn(n,new ui(.15,8,6),s,.7,!0).position.set(r,.7,-2.1);if(Mn(n,Xr,_i,xn,0,gn,-ss-vn,kt(e,"front")),Mn(n,Xr,_i,xn,0,gn,ss+vn,kt(e,"behind")),Mn(n,xn,_i,ts,-ni-vn,gn,-Sn,kt(e,"front-left")),Mn(n,xn,_i,ts,-ni-vn,gn,Sn,kt(e,"behind-left")),Mn(n,xn,_i,ts,ni+vn,gn,-Sn,kt(e,"front-right")),Mn(n,xn,_i,ts,ni+vn,gn,Sn,kt(e,"behind-right")),t){J0(n,t,bx,.5,ni,ss,j0);const r=(l,c)=>{const h=[];return kt(e,l)!==void 0&&h.push({main:ts,center:-Sn}),kt(e,c)!==void 0&&h.push({main:ts,center:Sn}),h},a=kt(e,"front")!==void 0?[{main:Xr,center:0}]:[],o=kt(e,"behind")!==void 0?[{main:Xr,center:0}]:[];K0(n,ni,ss,gn-xo/2,gn+xo/2,_i,a,o,r("front-left","behind-left"),r("front-right","behind-right"))}return n}const Dx=[.95,.9,.82];function ed(){const i=new Tn;nn(i,new Di(.25,.3,1.5,10),[.3,.3,.35],.75),nn(i,new ui(.22,10,8),[.62,.52,.46],1.72);const e=nn(i,new Ea(.07,.16,8),Dx,1.72);return e.rotation.x=-Math.PI/2,e.position.z=-.2,i}class Os{static occupantView(e){const t=e.witnessSide;if(!t)throw new Error("occupantView requires object.witnessSide to be set");const{x:n,z:s}=e.kind==="vehicle"?ql(t,ni,ss,j0):ql(t,Yl/2,Zl/2,Q0),r=e.kind==="vehicle"?Px:(e.occupiedFloor??0)*ii+Tx,a=(e.headingDeg??0)-$0[t]/hu;return{x:n,z:s,eyeY:r,headingDeg:a}}static build(e,t){const n=e.kind==="building"?Ax(e.floors??xx,e.windows,e.witnessSide,e.occupiedFloor):e.kind==="tree"?wx():e.kind==="streetlight"?Rx(t):e.kind==="vehicle"?Ix(t,e.windows,e.witnessSide):ed();return e.headingDeg!==void 0&&(n.rotation.y=-e.headingDeg*hu),n}static setLit(e,t,n){const s=t==="streetlight"?n?q0:X0:n?Z0:Y0;for(const r of e.children)!(r instanceof Mt)||!r.userData.emissive||r.material.color.setRGB(...s)}static dispose(e){for(const t of e.children)t instanceof Mt&&(t.geometry.dispose(),t.material.dispose())}}function Lx(i,e){return i.cloudCover===e.cloudCover&&i.cloudDarkness===e.cloudDarkness&&i.cloudBaseM===e.cloudBaseM&&i.precipitationType===e.precipitationType&&i.precipitationIntensity===e.precipitationIntensity&&i.windDirectionDeg===e.windDirectionDeg&&i.windSpeed===e.windSpeed&&i.storm===e.storm}const Mo=900,Nx=.5,Ws=900,Ux=6371e3,Fx=3e4;function du(i){const e=Math.sqrt(2*Ux*Math.max(i,0));return Math.max(Ws,Math.min(e,Fx))}const So=.5,Ox=850,yo=850,Eo=4,Bx=1.5,zx=-1,kx=6,$l=-4,fu=$l,Gx=3,Hx=.15,Vx=.6,Wx=40,Xx=30,qx=[0,45,90,135,180,225,270,315],Yx={en:["N","NE","E","SE","S","SW","W","NW"],fr:["N","NE","E","SE","S","SO","O","NO"]},Zx=["en","fr"],$x=880,pu=40,Kx=10,Jx=1,Qx=150,bo=55,mu=.5,jx=700,e3=250/Po,t3=12,n3=.5,i3=5,To=6,ns=[.92,.92,.95],Ao=[.15,.15,.19],gu={snow:{fallSpeedMPerS:2,size:.3,color:new Me(1,1,1),driftSensitivity:1,radiusM:25,topYM:20,opacity:.75,poolSize:2400},hail:{fallSpeedMPerS:14,size:.5,color:new Me(.95,.98,1),driftSensitivity:.25,radiusM:25,topYM:10,opacity:.95,poolSize:1200}},rs=0,s3=0,_u=3e3,Bs=20,r3=15,vu=rs,a3=40,xu=1,o3=9;function l3(i){return xu+(o3-xu)*i}const c3=new Me(.75,.82,.92),h3=10,u3=.5;function d3(i){return td(i/h3,u3,1)}const is=200,Mu=.18,Su=.32,f3=.35,p3=new Me(.85,.9,.98),yu=5,Eu=.85,bu=.01;function wo(i,e){return Math.round(i*(bu+(1-bu)*e))}const Tu=230,Au=.7,wu=.05,m3=.6,g3=.7,_3=.15,Ru=.35,v3=3,x3=1/12,M3=.5,Cu=8,Pu=25,Iu=.12,S3={Venus:new Me(1,.96,.85),Mars:new Me(1,.55,.4),Jupiter:new Me(.95,.87,.72),Saturn:new Me(.92,.86,.68)};class y3{renderer;scene=new Zf;camera;celestialGroup=new Tn;skyMesh;groundMesh;terrainMesh;terrainProviders;terrainOrigin;terrainBuildToken=0;terrainAttribution;starTiers=[];bodyMeshes=new Map;hitAreas=new Map;glareSprites=new Map;decorObjects=[];decorGroups=new Map;celestialLight=new _p(16777215,0);celestialLightTarget=new St;skyLight=new fp(16777215,0,0);streetlightLights=new Map;compassSprites=[];showCompass=!1;compassHovered=!1;compassForced=!1;animationFrameId=null;raycaster=new ro;weather=Nu;observerElevationM=0;groundRadius=Ws;terrainRadius=Ws;cloudMesh;cloudMaterial;cloudUniforms;precipitationPoints;precipitationPositions;precipitationPhase;precipitationSpeedJitter;precipitationWobbleFreqJitter;precipitationWobbleAmpJitter;precipitationBounceRemaining;precipitationBounceHeight;precipitationBounceDuration;precipitationBounceVelX;precipitationBounceVelZ;precipitationUniforms;rainSystem;rainSplashSystem;rainCameraDirection=new U;rainLastVerticalFacing=-1;lightningArmed=!1;nextLightningAtS=null;lightningFlashRemainingS=0;baseFogColor=[0,0,0];lastSunPosition;lensFlare;dazzleIntensity=1;lensFlareArtifactIntensity=0;sunWorldPosition=new U;sunVisible=!1;lensFlareScratch=new U;sunOcclusionRaycaster=new ro;sunOcclusionDirectionScratch=new U;ufoOcclusionRaycaster=new ro;onLightningFlash;constructor(e,t=Z2(),n){this.renderer=new mv({canvas:e,antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Xs,this.camera=new Yt(60,e.width/Math.max(e.height,1),.1,Mo*1.2),this.camera.position.set(0,1.6,0),this.terrainProviders=t,this.onLightningFlash=n,this.celestialLight.shadow.mapSize.set(1024,1024),this.celestialLight.shadow.camera.left=-120,this.celestialLight.shadow.camera.right=120,this.celestialLight.shadow.camera.top=120,this.celestialLight.shadow.camera.bottom=-120,this.celestialLight.shadow.camera.near=1,this.celestialLight.shadow.camera.far=1e3,this.celestialLight.shadow.bias=-.0015,this.celestialLight.target=this.celestialLightTarget,this.scene.add(this.celestialLight,this.celestialLightTarget,this.skyLight),this.scene.add(this.celestialGroup)}get currentTerrainAttribution(){return this.terrainAttribution}resize(e,t){this.renderer.setSize(e,t,!1),this.camera.aspect=e/Math.max(t,1),this.camera.updateProjectionMatrix(),this.render()}setObserverPose(e){e.headingDeg!==void 0?this.camera.rotation.set(e.pitchDeg*mn,-e.headingDeg*mn,0,"YXZ"):this.camera.rotation.set(e.pitchDeg*mn,this.camera.rotation.y,0,"YXZ"),e.elevationM!==this.observerElevationM&&(this.observerElevationM=e.elevationM,this.syncCloudLayer(),Math.abs(du(e.elevationM)-this.groundRadius)>1&&(this.buildGround(),this.celestialGroup.scale.setScalar(this.groundRadius/Ws),this.camera.far=Math.max(Mo*1.2,this.groundRadius*2.5),this.camera.updateProjectionMatrix())),this.camera.position.y=1.6+e.elevationM,this.celestialGroup.position.y=this.camera.position.y,this.camera.fov!==e.fovDeg&&(this.camera.fov=e.fovDeg,this.camera.updateProjectionMatrix())}setTerrainProviders(e){this.terrainProviders=e,this.disposeMesh(this.terrainMesh),this.terrainMesh=void 0,this.terrainOrigin=void 0,this.terrainAttribution=void 0,this.terrainBuildToken++}setTerrainOrigin(e,t,n){if(e===void 0||t===void 0)return;const s=this.groundRadius;if(this.terrainOrigin&&Math.abs(this.terrainRadius-s)<s*.1){const{x:a,z:o}=Ci(e,t,this.terrainOrigin.lat,this.terrainOrigin.lng);if(Math.sqrt(a*a+o*o)<Qx*(s/Ws))return}this.terrainOrigin={lat:e,lng:t},this.terrainRadius=s;const r=++this.terrainBuildToken;ex(e,t,this.terrainProviders,s).then(({mesh:a,attribution:o})=>{r===this.terrainBuildToken&&(this.disposeMesh(this.terrainMesh),a.renderOrder=Jx,this.terrainMesh=a,this.terrainAttribution=o,this.scene.add(a),this.render(),n?.())}).catch(a=>{console.warn("Terrain build failed, keeping the flat ground fallback:",a),n?.()})}setShowCompass(e){this.showCompass!==e&&(this.showCompass=e,this.disposeCompassLabels(),e&&this.buildCompassLabels(),this.render())}setDazzleIntensity(e){this.dazzleIntensity!==e&&(this.dazzleIntensity=e,this.lensFlare&&(this.lensFlare.uniforms.uOpacity.value=mu*e,this.lastSunPosition&&this.applyLensFlareTint(Ls(this.lastSunPosition.altitudeDeg))),this.render())}setLensFlareArtifactIntensity(e){this.lensFlareArtifactIntensity!==e&&(this.lensFlareArtifactIntensity=e,this.lensFlare&&(this.lensFlare.uniforms.uFlareIntensity.value=e),this.render())}applyLensFlareTint(e){this.lensFlare&&this.lensFlare.uniforms.uColorGain.value.setRGB(bo*this.dazzleIntensity*e[0],bo*this.dazzleIntensity*e[1],bo*this.dazzleIntensity*e[2])}setCompassHovered(e){this.compassHovered!==e&&(this.compassHovered=e,this.updateCompassVisibility())}setCompassForced(e){this.compassForced!==e&&(this.compassForced=e,this.updateCompassVisibility())}updateCompassVisibility(){const e=this.compassHovered||this.compassForced;for(const t of this.compassSprites)t.visible=e;this.render()}setWeather(e){Lx(this.weather,e)||(this.weather=e,this.buildClouds(),this.buildPrecipitation(),this.lightningArmed=e.storm&&e.cloudDarkness>=M3,this.lightningArmed||(this.nextLightningAtS=null,this.lightningFlashRemainingS=0,this.restoreFogColor()),this.syncAnimationLoop(),this.render())}setDecor(e){if(this.decorObjects!==e){this.decorObjects=e;for(const t of this.decorGroups.values())t.removeFromParent(),Os.dispose(t);this.decorGroups.clear(),this.streetlightLights.clear();for(const t of e){const n=Os.build(t,t.lit??!1);this.scene.add(n),this.decorGroups.set(t.id,n),t.kind==="streetlight"&&this.addStreetlightLight(t.id,n)}this.celestialLight.castShadow=this.decorGroups.size>0}}updateDecorAnchoring(e,t){const n=e?.lat!==void 0&&e.lng!==void 0&&t?.lat!==void 0&&t?.lng!==void 0?Ci(e.lat,e.lng,t.lat,t.lng):{x:0,z:0},s=this.decorObjects.find(a=>a.witnessSide!==void 0&&Mx(a.kind)),r={x:0,z:0};if(s){const a=Os.occupantView(s),o=-(s.headingDeg??0)*mn,l=a.x*Math.cos(o)+a.z*Math.sin(o),c=-a.x*Math.sin(o)+a.z*Math.cos(o),h=s.eastM+n.x,d=-s.northM+n.z;r.x=-(h+l),r.z=-(d+c),this.camera.position.y=a.eyeY,this.camera.rotation.set(this.indoorLookPitchDeg*mn,-(a.headingDeg+this.indoorLookYawDeg)*mn,0,"YXZ")}for(const a of this.decorObjects){const o=this.decorGroups.get(a.id);o&&o.position.set(a.eastM+n.x+r.x,s3,-a.northM+n.z+r.z)}}indoorLookYawDeg=0;indoorLookPitchDeg=0;setIndoorLook(e,t){this.indoorLookYawDeg=e,this.indoorLookPitchDeg=t}updateDecorLitState(e){for(const t of this.decorObjects){if(t.kind!=="streetlight"&&t.kind!=="vehicle")continue;const n=this.decorGroups.get(t.id);if(!n)continue;const s=Sx(t,e);Os.setLit(n,t.kind,s);const r=this.streetlightLights.get(t.id);r&&(r.visible=s)}}addStreetlightLight(e,t){const n=t.children.find(r=>r.userData.emissive);if(!n)return;const s=new mp(16764006,Wx,Xx);s.position.copy(n.position),s.castShadow=!0,s.shadow.mapSize.set(512,512),s.shadow.bias=-.002,t.add(s),this.streetlightLights.set(e,s)}setAstronomy(e){const t=M0(e.sun.altitudeDeg),n=t.horizon;this.baseFogColor=n,this.lastSunPosition=e.sun,this.buildSky(e.sun),this.buildGround(),this.updateCloudLighting(e.sun,n),this.updateCelestialLight(e,t.zenith,n),this.buildStars(e.stars,e.sun.altitudeDeg),this.setBodyMesh("sun",e.sun,Eo,new Me(1,.96,.88),e.sun.magnitude),this.setMoonMesh(e.moon),this.buildPlanets(e.planets),this.scene.fog=new hc(new Me(...n),this.groundRadius*.2,this.groundRadius),this.syncAnimationLoop(),this.render()}updateCelestialLight(e,t,n){this.skyLight.color.setRGB(t[0],t[1],t[2]),this.skyLight.groundColor.setRGB(n[0],n[1],n[2]),this.skyLight.intensity=Vx;const s=e.sun.altitudeDeg>=fu,r=!s&&e.moon.altitudeDeg>=fu;if(!s&&!r){this.celestialLight.intensity=0;return}const a=s?e.sun:e.moon,{x:o,y:l,z:c}=ji(a.altitudeDeg,a.azimuthDeg,yo);this.celestialLight.position.set(o,l,c);const h=Ls(a.altitudeDeg);this.celestialLight.color.setRGB(h[0],h[1],h[2]);const d=Math.max(0,Math.sin(Math.max(a.altitudeDeg,0)*mn));this.celestialLight.intensity=(s?Gx:Hx)*d,this.celestialLight.castShadow=this.decorGroups.size>0}render(){this.updateLensFlarePosition(),this.renderer.render(this.scene,this.camera)}updateLensFlarePosition(){const e=this.lensFlare;if(!e)return;if(!this.sunVisible){e.mesh.visible=!1;return}if(this.camera.updateMatrixWorld(),this.lensFlareScratch.copy(this.sunWorldPosition).applyMatrix4(this.camera.matrixWorldInverse),this.lensFlareScratch.z>0){e.mesh.visible=!1;return}if(this.isSunOccluded()){e.mesh.visible=!1;return}e.mesh.visible=!0;const t=this.lensFlareScratch.copy(this.sunWorldPosition).project(this.camera);e.uniforms.uLensPosition.value.set(t.x,t.y),e.uniforms.uResolution.value.set(this.renderer.domElement.width,this.renderer.domElement.height)}isSunOccluded(){const e=[];this.groundMesh&&e.push(this.groundMesh),this.terrainMesh&&e.push(this.terrainMesh);for(const r of this.decorGroups.values())e.push(r);if(e.length===0)return!1;const t=this.sunOcclusionDirectionScratch.copy(this.sunWorldPosition).sub(this.camera.position),n=t.length();t.normalize(),this.sunOcclusionRaycaster.set(this.camera.position,t);const s=this.sunOcclusionRaycaster.intersectObjects(e,!0)[0];return s!==void 0&&s.distance<n}isScreenPointOccluded(e,t,n,s){if(this.isBehindCloudLayer(e,t,s))return!0;const r=[];for(const a of this.decorObjects){if(!a.occludesSourceIds?.includes(n))continue;const o=this.decorGroups.get(a.id);o&&r.push(o)}return r.length===0?!1:(this.ufoOcclusionRaycaster.setFromCamera(new Ue(e,t),this.camera),this.ufoOcclusionRaycaster.near=Nx,this.ufoOcclusionRaycaster.intersectObjects(r,!0).length>0)}isBehindCloudLayer(e,t,n){if(!n||!this.cloudMesh||this.weather.cloudCover<=0)return!1;if(n.declared)return!0;const s=n.distanceM;if(s===void 0)return!1;const r=this.cloudLayerOffset();this.ufoOcclusionRaycaster.setFromCamera(new Ue(e,t),this.camera);const a=this.ufoOcclusionRaycaster.ray.direction;return Math.sign(a.y||1)!==Math.sign(r)||Math.abs(this.cloudLayerHeightM())/Math.max(Math.abs(a.y),.026)>=s?!1:yt.alphaAt(a,Math.abs(r),this.weather.cloudCover)>=n3}cloudLayerHeightM(){return(this.weather.cloudBaseM??Po)-this.observerElevationM}pickBodyAt(e,t){this.raycaster.setFromCamera(new Ue(e,t),this.camera);const n=[...this.hitAreas.entries()],s=this.raycaster.intersectObjects(n.map(([,r])=>r))[0];if(s)return n.find(([,r])=>r===s.object)?.[0]}pickDecorAt(e,t){this.raycaster.setFromCamera(new Ue(e,t),this.camera);const n=[...this.decorGroups.entries()],s=this.raycaster.intersectObjects(n.map(([,a])=>a),!0)[0];if(!s)return;let r=s.object;for(;r&&!n.some(([,a])=>a===r);)r=r.parent;return n.find(([,a])=>a===r)?.[0]}dispose(){this.stopTwinkle(),this.terrainBuildToken++,this.disposeMesh(this.skyMesh),this.disposeMesh(this.groundMesh),this.disposeMesh(this.terrainMesh),this.disposeCloudSystem(),this.disposePrecipitationPoints(),this.disposeRain(),this.disposeStarTiers();for(const e of this.bodyMeshes.values())this.disposeMesh(e);this.bodyMeshes.clear();for(const e of[...this.hitAreas.keys()])this.disposeHitArea(e);for(const e of[...this.glareSprites.keys()])this.disposeGlare(e);this.disposeCompassLabels();for(const e of this.decorGroups.values())Os.dispose(e);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;let e;const t=n=>{const s=e===void 0?0:Math.min((n-e)/1e3,x3);e=n,this.updateTwinkle(n/1e3),this.updatePrecipitation(n/1e3,s),this.updateRain(s),this.updateLightning(n/1e3,s),this.lensFlare&&(this.lensFlare.uniforms.uTime.value=n/1e3),this.render(),this.animationFrameId=requestAnimationFrame(t)};this.animationFrameId=requestAnimationFrame(t)}setAnimationsRunning(e){e!==this.animationsRunning&&(this.animationsRunning=e,e?this.nextLightningAtS=null:this.lightningFlashRemainingS>0&&(this.lightningFlashRemainingS=0,this.restoreFogColor()),this.syncAnimationLoop(),e||this.render())}stopTwinkle(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}restoreFogColor(){this.scene.fog&&this.scene.fog.color.setRGB(...this.baseFogColor)}needsAnimationLoop(){return this.animationsRunning&&(this.starTiers.length>0||this.precipitationPoints!==void 0||this.rainSystem!==void 0||this.lightningArmed||this.lensFlare!==void 0&&this.sunVisible)}syncAnimationLoop(){this.needsAnimationLoop()?this.startTwinkle():this.stopTwinkle()}buildSky(e){this.disposeMesh(this.skyMesh);const t=new ui(Mo,32,16),n=t.attributes.position,s=[];for(let a=0;a<n.count;a++){const{altitudeDeg:o,azimuthDeg:l}=xv(n.getX(a),n.getY(a),n.getZ(a)),c=yv(o,l,e.azimuthDeg,e.altitudeDeg);s.push(c[0],c[1],c[2])}t.setAttribute("color",new Et(s,3));const r=new js({vertexColors:!0,side:It,fog:!1});this.skyMesh=new Mt(t,r),this.celestialGroup.add(this.skyMesh)}buildGround(){this.disposeMesh(this.groundMesh),this.groundRadius=du(this.observerElevationM);const e=new fc(this.groundRadius,48),t=new nr({color:new Me(So,So,So),fog:!0});this.groundMesh=new Mt(e,t),this.groundMesh.rotation.x=-Math.PI/2,this.groundMesh.position.y=0,this.groundMesh.receiveShadow=!0,this.scene.add(this.groundMesh)}setBodyMesh(e,t,n,s,r){if(this.disposeMesh(this.bodyMeshes.get(e)),this.disposeHitArea(e),this.disposeGlare(e),t.altitudeDeg<$l){this.bodyMeshes.delete(e),e==="sun"&&(this.sunVisible=!1);return}const{x:a,y:o,z:l}=ji(t.altitudeDeg,t.azimuthDeg,yo),c=Ls(t.altitudeDeg),h=new Me(s.r*c[0],s.g*c[1],s.b*c[2]),d=new ui(n,16,16),u=new js({color:h,fog:!1}),p=new Mt(d,u);if(p.position.set(a,o,l),this.celestialGroup.add(p),this.bodyMeshes.set(e,p),this.setHitArea(e,a,o,l,n),e!=="sun"&&this.setGlare(e,a,o,l,r,h),e==="sun"){this.sunVisible=!0;const g=this.celestialGroup.scale.x;this.sunWorldPosition.set(a*g,o*g+this.celestialGroup.position.y,l*g),this.lensFlare||(this.lensFlare=vx(),this.lensFlare.uniforms.uOpacity.value=mu*this.dazzleIntensity,this.lensFlare.uniforms.uFlareIntensity.value=this.lensFlareArtifactIntensity,this.scene.add(this.lensFlare.mesh)),this.applyLensFlareTint(c)}}setMoonMesh(e){const t="moon";if(this.disposeMesh(this.bodyMeshes.get(t)),this.disposeHitArea(t),this.disposeGlare(t),e.altitudeDeg<$l){this.bodyMeshes.delete(t);return}const{x:n,y:s,z:r}=ji(e.altitudeDeg,e.azimuthDeg,yo),a=Ls(e.altitudeDeg),o=new Me(a[0],a[1],a[2]),l=new ks({map:D3(e.phase),color:o,fog:!1}),c=new Mr(l);c.position.set(n,s,r);const h=Eo*2;c.scale.set(h,h,1),this.celestialGroup.add(c),this.bodyMeshes.set(t,c),this.setHitArea(t,n,s,r,Eo),this.setGlare(t,n,s,r,e.magnitude,o)}setHitArea(e,t,n,s,r){const a=new ks({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,fog:!1}),o=new Mr(a);o.position.set(t,n,s);const l=r*kx;o.scale.set(l,l,1),this.celestialGroup.add(o),this.hitAreas.set(e,o)}disposeHitArea(e){const t=this.hitAreas.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.hitAreas.delete(e))}setGlare(e,t,n,s,r,a){this.disposeGlare(e);const o=bv(r);if(o<=0)return;const l=wv(o),c=new ks({map:I3(),color:a,transparent:!0,opacity:Pv(o),blending:ra,depthWrite:!1,fog:!1}),h=new Mr(c);h.position.set(t,n,s),h.scale.set(l*2,l*2,1),this.celestialGroup.add(h),this.glareSprites.set(e,h)}disposeGlare(e){const t=this.glareSprites.get(e);t&&(t.removeFromParent(),t.material.dispose(),this.glareSprites.delete(e))}buildPlanets(e){const t=new Set(["sun","moon"]);for(const n of e){t.add(n.body);const s=Yh(n.magnitude),r=Zh(s),a=S3[n.body]??new Me(1,1,1),o=new Me(a.r*r,a.g*r,a.b*r),l=Bx*(.5+.5*s);this.setBodyMesh(n.body,n.position,l,o,n.magnitude)}for(const n of[...this.bodyMeshes.keys()])t.has(n)||(this.disposeMesh(this.bodyMeshes.get(n)),this.bodyMeshes.delete(n),this.disposeHitArea(n),this.disposeGlare(n))}buildStars(e,t){if(this.disposeStarTiers(),!e||e.catalog.count===0){this.syncAnimationLoop();return}const{catalog:n,date:s,observer:r}=e,a=gv(t),o=Ro(1337),l=[];for(let c=0;c<n.count;c++){const h=n.mag[c];if(h>a)continue;const{altitudeDeg:d,azimuthDeg:u}=I2(n.ra[c],n.dec[c],s,r);if(d<zx)continue;const{x:p,y:g,z:x}=ji(d,u,Ox);l.push({x:p,y:g,z:x,brightness:Yh(h),phase:o()*Math.PI*2,speedFactor:.7+o()*.6})}this.starTiers=y0.map((c,h)=>{const d=l.filter(M=>Dv(M.brightness)===h),u=new Float32Array(d.length*3),p=new Float32Array(d.length),g=new Float32Array(d.length),x=new Float32Array(d.length);d.forEach((M,y)=>{u[y*3]=M.x,u[y*3+1]=M.y,u[y*3+2]=M.z,p[y]=M.brightness,g[y]=M.phase,x[y]=M.speedFactor});const m=new bt;m.setAttribute("position",new pt(u,3));const f=new pt(new Float32Array(d.length*3),3);m.setAttribute("color",f);const A=new r0({vertexColors:!0,size:c.size,sizeAttenuation:!1,fog:!1}),w=new na(m,A);return this.celestialGroup.add(w),{points:w,colorAttribute:f,brightness:p,phase:g,speedFactor:x}}),this.updateTwinkle(0),this.startTwinkle()}updateTwinkle(e){for(const t of this.starTiers){const n=t.colorAttribute.array;for(let s=0;s<t.brightness.length;s++){const r=Uv(t.brightness[s],{phase:t.phase[s],speedFactor:t.speedFactor[s]},e),a=Zh(t.brightness[s])*r;n[s*3]=a,n[s*3+1]=a,n[s*3+2]=a}t.colorAttribute.needsUpdate=!0}}buildClouds(){if(this.disposeCloudSystem(),this.weather.cloudCover<=0)return;const e=this.weather.cloudDarkness,t=new Me(ns[0]+(Ao[0]-ns[0])*e,ns[1]+(Ao[1]-ns[1])*e,ns[2]+(Ao[2]-ns[2])*e),{material:n,uniforms:s}=dx(t,this.weather.cloudCover,Math.abs(this.cloudLayerOffset()));this.cloudMaterial=n,this.cloudUniforms=s,this.lastSunPosition&&this.updateCloudLighting(this.lastSunPosition,this.baseFogColor);const r=px(jx);this.cloudMesh=new Mt(r,n),this.cloudLayerOffset()<0&&(this.cloudMesh.scale.y=-1),this.cloudMesh.renderOrder=i3,this.celestialGroup.add(this.cloudMesh)}syncCloudLayer(){const e=this.cloudLayerOffset();this.cloudUniforms&&(this.cloudUniforms.layerHeight.value=Math.abs(e)),this.cloudMesh&&(this.cloudMesh.scale.y=e<0?-1:1)}cloudLayerOffset(){const t=((this.weather.cloudBaseM??Po)-this.observerElevationM)*e3;return Math.sign(t||1)*Math.max(Math.abs(t),t3)}updateCloudLighting(e,t){if(!this.cloudUniforms)return;const{x:n,y:s,z:r}=ji(e.altitudeDeg,e.azimuthDeg,1),a=Ls(e.altitudeDeg),o=Math.max(0,Math.sin(Math.max(e.altitudeDeg,0)*mn));this.cloudUniforms.sunDir.value.set(n,s,r),this.cloudUniforms.sunColor.value.setRGB(a[0]*o,.96*a[1]*o,.88*a[2]*o),this.cloudUniforms.ambientColor.value.setRGB(t[0],t[1],t[2])}disposeCloudSystem(){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}buildPrecipitation(){this.disposePrecipitationPoints(),this.disposeRain();const e=this.weather.precipitationType;if(e==="none")return;if(e==="rain"){this.buildRain();return}const t=gu[e],n=t.poolSize,s=Ro(9001),r=new Float32Array(n*3),a=new Float32Array(n),o=new Float32Array(n),l=new Float32Array(n),c=new Float32Array(n),h=new Float32Array(n),d=new Float32Array(n),u=new Float32Array(n),p=new Float32Array(n),g=new Float32Array(n);for(let w=0;w<n;w++){const M=s()*Math.PI*2,y=s()*t.radiusM;r[w*3]=Math.cos(M)*y,r[w*3+1]=rs+s()*(t.topYM-rs),r[w*3+2]=Math.sin(M)*y,a[w]=s()*Math.PI*2,o[w]=.7+s()*.6,l[w]=.6+s()*.8,c[w]=.4+s()*1.2}const x=new bt;x.setAttribute("position",new pt(r,3)),x.setDrawRange(0,wo(n,this.weather.precipitationIntensity));const m={uSize:{value:t.size},uScale:{value:.5*this.renderer.domElement.height},uOpacity:{value:t.opacity},uColor:{value:t.color},uHazeColor:{value:new Me(...this.baseFogColor)},uTexture:{value:E3(e)},uNearFocusDistance:{value:yu},uHazeDistance:{value:t.radiusM*Eu}},f=new Gt({uniforms:m,vertexShader:C3,fragmentShader:P3,transparent:!0,depthWrite:!1});this.precipitationUniforms=m;const A=new na(x,f);A.renderOrder=To,this.scene.add(A),this.precipitationPoints=A,this.precipitationPositions=r,this.precipitationPhase=a,this.precipitationSpeedJitter=o,this.precipitationWobbleFreqJitter=l,this.precipitationWobbleAmpJitter=c,this.precipitationBounceRemaining=h,this.precipitationBounceHeight=d,this.precipitationBounceDuration=u,this.precipitationBounceVelX=p,this.precipitationBounceVelZ=g}updatePrecipitation(e,t){if(!this.precipitationPoints||!this.precipitationPositions||!this.precipitationPhase||!this.precipitationSpeedJitter||(this.precipitationUniforms?.uHazeColor.value.setRGB(...this.baseFogColor),t<=0))return;const n=this.weather.precipitationType;if(n==="none"||n==="rain")return;const s=gu[n],r=this.weather.windDirectionDeg*mn,a=Math.sin(r)*this.weather.windSpeed*s.driftSensitivity,o=-Math.cos(r)*this.weather.windSpeed*s.driftSensitivity,l=this.precipitationPositions,c=this.precipitationPhase,h=this.precipitationSpeedJitter,d=this.precipitationWobbleFreqJitter,u=this.precipitationWobbleAmpJitter,p=this.precipitationBounceRemaining,g=this.precipitationBounceHeight,x=this.precipitationBounceDuration,m=this.precipitationBounceVelX,f=this.precipitationBounceVelZ,A=n==="snow"&&d&&u,w=n==="hail"&&p&&g&&x&&m&&f;for(let M=0,y=0;M<l.length;M+=3,y++){if(w&&p[y]>0){if(p[y]-=t,p[y]<=0){const v=Math.random()*Math.PI*2,E=Math.sqrt(Math.random())*s.radiusM;l[M]=Math.cos(v)*E,l[M+1]=s.topYM,l[M+2]=Math.sin(v)*E,p[y]=0}else{const v=1-p[y]/x[y];l[M+1]=rs+Math.sin(Math.PI*v)*g[y],l[M]=Yr(l[M]+(a+m[y])*t,s.radiusM),l[M+2]=Yr(l[M+2]+(o+f[y])*t,s.radiusM)}continue}let b=0,R=0;if(A){const v=m3*d[y],E=g3*u[y];b=Math.sin(e*v*Math.PI*2+c[y])*E,R=Math.sin(e*v*Math.PI*2+c[y]+Math.PI/2)*E}if(l[M]+=(a+b)*t,l[M+1]-=s.fallSpeedMPerS*h[y]*t,l[M+2]+=(o+R)*t,l[M]=Yr(l[M],s.radiusM),l[M+2]=Yr(l[M+2],s.radiusM),l[M+1]<rs){if(w){g[y]=Ru*(.2+Math.random()*1.6),x[y]=_3*(.5+Math.random()),p[y]=x[y];const P=Math.random()*Math.PI*2,C=v3*(g[y]/Ru);m[y]=Math.cos(P)*C,f[y]=Math.sin(P)*C,l[M+1]=rs;continue}const v=Math.random()*Math.PI*2,E=Math.sqrt(Math.random())*s.radiusM;l[M]=Math.cos(v)*E,l[M+1]=s.topYM,l[M+2]=Math.sin(v)*E}}this.precipitationPoints.geometry.attributes.position.needsUpdate=!0}buildRain(){const e=l3(this.weather.precipitationIntensity);this.rainSystem=cx({count:_u,radiusM:Bs,heightM:r3,bottomYM:vu,overallSpeed:a3,color:c3,opacity:.85,visibleCount:wo(_u,this.weather.precipitationIntensity),speedStreak:d3(e),pixelSize:Tu,seed:9001,nearFocusDistanceM:yu,hazeDistanceM:Bs*Eu,hazeColor:new Me(...this.baseFogColor)}),this.rainLastVerticalFacing=-1,this.rainSystem.points.renderOrder=To,this.scene.add(this.rainSystem.points),this.buildRainSplashes()}buildRainSplashes(){const e=Ro(4242),t=new Float32Array(is*3),n=new Float32Array(is),s=new Float32Array(is),r=new Float32Array(is);for(let h=0;h<is;h++){const d=e()*Math.PI*2,u=Math.sqrt(e())*Bs;t[h*3]=Math.cos(d)*u,t[h*3+1]=vu,t[h*3+2]=Math.sin(d)*u,s[h]=qr(Mu,Su),n[h]=e()*s[h],r[h]=n[h]/s[h]}const a=new bt;a.setAttribute("position",new pt(t,3));const o=new pt(r,1);a.setAttribute("aLife",o),a.setDrawRange(0,wo(is,this.weather.precipitationIntensity));const l=new Gt({uniforms:{uMaxSize:{value:f3},uScale:{value:.5*this.renderer.domElement.height},uColor:{value:p3},uTexture:{value:A3()}},vertexShader:w3,fragmentShader:R3,transparent:!0,depthWrite:!1}),c=new na(a,l);c.renderOrder=To,this.scene.add(c),this.rainSplashSystem={points:c,positions:t,life:n,duration:s,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}updateRain(e){const t=this.rainSystem;if(!t)return;t.uniforms.uTime.value+=e,t.uniforms.uHazeColor.value.setRGB(...this.baseFogColor);const n=this.weather.windDirectionDeg*mn,s=Math.sin(n)*this.weather.windSpeed,r=-Math.cos(n)*this.weather.windSpeed,a=Bs,o=c=>(c%(a*2)+a*3)%(a*2)-a;t.uniforms.uWindOffset.value.set(o(t.uniforms.uWindOffset.value.x+s*e),o(t.uniforms.uWindOffset.value.y+r*e)),this.camera.getWorldDirection(this.rainCameraDirection);const l=Math.abs(this.rainCameraDirection.y);if(Math.abs(l-this.rainLastVerticalFacing)>.001){this.rainLastVerticalFacing=l;const c=Au+(1-Au)*(1-l),h=wu+(1-wu)*(1-l);t.uniforms.uUvSquash.value=h,t.uniforms.uPixelSize.value=Tu*c*(.5+.5*h)}this.updateRainSplashes(e)}updateRainSplashes(e){const t=this.rainSplashSystem;if(!t||e<=0)return;const{positions:n,life:s,duration:r,lifeAttribute:a}=t,o=a.array;for(let l=0,c=0;l<n.length;l+=3,c++){if(s[c]+=e,s[c]>=r[c]){const h=Math.random()*Math.PI*2,d=Math.sqrt(Math.random())*Bs;n[l]=Math.cos(h)*d,n[l+2]=Math.sin(h)*d,r[c]=qr(Mu,Su),s[c]=0}o[c]=s[c]/r[c]}t.points.geometry.attributes.position.needsUpdate=!0,a.needsUpdate=!0}updateLightning(e,t){if(this.lightningArmed){if(this.lightningFlashRemainingS>0){this.lightningFlashRemainingS=Math.max(0,this.lightningFlashRemainingS-t);const n=this.lightningFlashRemainingS/Iu;this.scene.fog&&this.scene.fog.color.setRGB(this.baseFogColor[0]+(1-this.baseFogColor[0])*n,this.baseFogColor[1]+(1-this.baseFogColor[1])*n,this.baseFogColor[2]+(1-this.baseFogColor[2])*n);return}if(this.nextLightningAtS===null){this.nextLightningAtS=e+qr(Cu,Pu);return}e>=this.nextLightningAtS&&(this.lightningFlashRemainingS=Iu,this.nextLightningAtS=e+qr(Cu,Pu),this.onLightningFlash?.())}}buildCompassLabels(){const e=Jl(navigator.languages,Zx),t=Yx[e];this.compassSprites=qx.map((n,s)=>{const r=t[s],a=new ks({map:L3(r),depthTest:!1,fog:!1}),o=new Mr(a),{x:l,y:c,z:h}=ji(0,n,$x);return o.position.set(l,c,h),o.scale.set(pu,pu,1),o.renderOrder=Kx,o.visible=this.compassHovered||this.compassForced,this.celestialGroup.add(o),o})}disposeCompassLabels(){for(const e of this.compassSprites)e.removeFromParent(),e.material.map?.dispose(),e.material.dispose();this.compassSprites=[]}disposeStarTiers(){for(const e of this.starTiers)this.disposeMesh(e.points);this.starTiers=[]}disposeMesh(e){if(!e)return;e.removeFromParent(),"geometry"in e&&e.geometry.dispose();const t=e.material;for(const n of Array.isArray(t)?t:[t]){const s=n.map;s&&s.dispose(),n.dispose()}}}const mn=Math.PI/180;function td(i,e,t){return Math.max(e,Math.min(t,i))}function qr(i,e){return i+Math.random()*(e-i)}function Yr(i,e){return(i%(e*2)+e*3)%(e*2)-e}let Zr,$r;function E3(i){switch(i){case"snow":return b3();case"hail":return T3()}}function b3(){if(Zr)return Zr;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,0.95)"),n.addColorStop(.5,"rgba(255,255,255,0.55)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Zr=new Wn(e),Zr}function T3(){if($r)return $r;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,1)"),n.addColorStop(.55,"rgba(255,255,255,0.95)"),n.addColorStop(.8,"rgba(255,255,255,0.4)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),$r=new Wn(e),$r}let Kr;function A3(){if(Kr)return Kr;const i=64,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,0)"),n.addColorStop(.4,"rgba(255,255,255,0)"),n.addColorStop(.6,"rgba(255,255,255,0.9)"),n.addColorStop(.8,"rgba(255,255,255,0.25)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Kr=new Wn(e),Kr}const w3=`
|
|
5038
5038
|
uniform float uMaxSize;
|
|
5039
5039
|
uniform float uScale;
|
|
5040
5040
|
attribute float aLife;
|
|
@@ -5099,4 +5099,4 @@ void main() {
|
|
|
5099
5099
|
float blur = max(vNearBlur, vHaze);
|
|
5100
5100
|
gl_FragColor = vec4(color, tex.a * uOpacity * (1.0 - blur * 0.5));
|
|
5101
5101
|
}
|
|
5102
|
-
`;let Jr;function I3(){if(Jr)return Jr;const i=128,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,1)"),n.addColorStop(.4,"rgba(255,255,255,0.35)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Jr=new Wn(e),Jr}function D3(i){const t=document.createElement("canvas");t.width=128,t.height=128;const n=t.getContext("2d"),s=128/2-2,r=128/2,a=128/2,o="#2e2b26",l="#f4f1e2";n.fillStyle=o,n.beginPath(),n.arc(r,a,s,0,Math.PI*2),n.fill();const c=td(i.illuminatedFraction,0,1),h=i.phaseFraction<.5,d=s*Math.abs(1-2*c),u=c<.5;return n.save(),n.beginPath(),n.arc(r,a,s,0,Math.PI*2),n.clip(),n.fillStyle=l,n.beginPath(),h?(n.arc(r,a,s,-Math.PI/2,Math.PI/2,!1),n.ellipse(r,a,d,s,0,Math.PI/2,-Math.PI/2,u)):(n.arc(r,a,s,Math.PI/2,-Math.PI/2,!1),n.ellipse(r,a,d,s,0,-Math.PI/2,Math.PI/2,u)),n.fill(),n.restore(),new Wn(t)}function L3(i){const e=document.createElement("canvas");e.width=128,e.height=128;const t=e.getContext("2d");return t.fillStyle="rgba(0, 0, 0, 0.55)",t.beginPath(),t.arc(64,64,60,0,Math.PI*2),t.fill(),t.fillStyle="#ffffff",t.font="bold 52px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(i,64,68),new Wn(e)}function Ro(i){let e=i;return function(){e|=0,e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const Du=new Map;function N3(i){const e=i.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),t=e,n=t*Float32Array.BYTES_PER_ELEMENT;return{count:e,ra:new Float32Array(i,0*n,t),dec:new Float32Array(i,1*n,t),mag:new Float32Array(i,2*n,t),ci:new Float32Array(i,3*n,t)}}function U3(i){let e=Du.get(i);return e||(e=fetch(i).then(t=>t.arrayBuffer()).then(N3),Du.set(i,e)),e}const F3=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,O3=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,B3=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,z3=20,k3=1;class G3{context;buffers=new Map;ambientSource;ambientGain;ambientKey="none";ambientToken=0;ambientVolume=0;windSource;windGain;windActive=!1;windToken=0;windVolume=0;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",e);return}}this.context.state==="suspended"&&this.context.resume()}setAmbient(e,t,n){if(!this.context)return;const s=e==="rain"||e==="hail"?e:"none";if(this.ambientVolume=s==="hail"?Math.min(1,t*1.3+.2):s==="rain"?t:0,s!==this.ambientKey){this.ambientKey=s;const a=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,s!=="none"&&this.startLoop(F3,this.ambientVolume).then(o=>this.applyIfCurrent(o,a,()=>this.ambientToken,l=>{this.ambientSource=l?.source,this.ambientGain=l?.gain,l&&(l.gain.gain.value=this.ambientVolume)}))}else this.ambientGain&&(this.ambientGain.gain.value=this.ambientVolume);this.windVolume=Math.min(n/z3,1);const r=n>k3;if(r!==this.windActive){this.windActive=r;const a=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,r&&this.startLoop(O3,this.windVolume).then(o=>this.applyIfCurrent(o,a,()=>this.windToken,l=>{this.windSource=l?.source,this.windGain=l?.gain,l&&(l.gain.gain.value=this.windVolume)}))}else this.windGain&&(this.windGain.gain.value=this.windVolume)}playThunder(){this.context&&this.playOneShot(B3,.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.buffers.clear()}applyIfCurrent(e,t,n,s){if(t!==n()){e?.source.stop();return}s(e)}async startLoop(e,t){const n=this.context;if(n)try{const s=await this.getBuffer(e),r=n.createBufferSource();r.buffer=s,r.loop=!0;const a=n.createGain();return a.gain.value=t,r.connect(a).connect(n.destination),r.start(),{source:r,gain:a}}catch(s){console.warn("Weather ambient sound failed to load, staying silent:",s);return}}async playOneShot(e,t){const n=this.context;if(n)try{const s=await this.getBuffer(e),r=n.createBufferSource();r.buffer=s;const a=n.createGain();a.gain.value=t,r.connect(a).connect(n.destination),r.start()}catch(s){console.warn("Thunder sound failed to load:",s)}}async getBuffer(e){const t=this.context;if(!t)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let n=this.buffers.get(e);return n||(n=fetch(e).then(s=>{if(!s.ok)throw new Error(`Audio fetch failed (${s.status}): ${e}`);return s.arrayBuffer()}).then(s=>t.decodeAudioData(s)),this.buffers.set(e,n)),n}stopSource(e,t){try{e?.stop()}catch{}e?.disconnect(),t?.disconnect()}}Ou();const H3={sun:{en:"Sun",fr:"Soleil"},moon:{en:"Moon",fr:"Lune"},Venus:{en:"Venus",fr:"Vénus"},Mars:{en:"Mars",fr:"Mars"},Jupiter:{en:"Jupiter",fr:"Jupiter"},Saturn:{en:"Saturn",fr:"Saturne"}},V3=["en","fr"],W3={building:{en:"Building",fr:"Bâtiment"},tree:{en:"Tree",fr:"Arbre"},streetlight:{en:"Streetlight",fr:"Lampadaire"},vehicle:{en:"Vehicle",fr:"Véhicule"},witness:{en:"Witness",fr:"Témoin"}},X3=new URL(""+new URL("stars-mag7.5-DDr9QasD.bin",import.meta.url).href,import.meta.url).href,q3={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Co={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class Y3 extends HTMLElement{static get observedAttributes(){return["src","star-catalog-src","show-compass","lens-flare-intensity","lens-flare-brightness"]}shadow;stageElement;frameElement;sceneCanvas;ufoElement;sceneRenderer;hoverTooltip;resizeObserver;lastTimeMs=0;starCatalog;weatherAudio=new G3;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=e=>{this.sceneRenderer.setCompassHovered(!0);const t=this.ufoElement.canvasElement,n=t.getBoundingClientRect();if(n.width===0||n.height===0)return;const s=(e.clientX-n.left)/n.width*t.width,r=(e.clientY-n.top)/n.height*t.height;if(this.ufoElement.hasVisibleShapeAt(s,r)){this.hoverTooltip.hidden=!0;return}const a=(e.clientX-n.left)/n.width*2-1,o=-((e.clientY-n.top)/n.height*2-1),l=Jl(navigator.languages,V3),c=this.sceneRenderer.pickBodyAt(a,o);if(c){this.showHoverTooltip(e,H3[c]?.[l]??c);return}const h=this.sceneRenderer.pickDecorAt(a,o),d=h?this.ufoElement.sighting.decor.find(u=>u.id===h):void 0;if(d){this.showHoverTooltip(e,d.title||W3[d.kind][l]);return}this.hoverTooltip.hidden=!0};showHoverTooltip(e,t){this.hoverTooltip.textContent=t,this.hoverTooltip.hidden=!1;const n=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${e.clientX-n.left+12}px`,this.hoverTooltip.style.top=`${e.clientY-n.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash=()=>{clearTimeout(this.thunderTimeoutId);const e=(.5+Math.random()*3.5)*1e3;this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),e)};handleFirstInteraction=()=>{this.weatherAudio.resume(),this.setWeather(Lc(this.ufoElement.sighting,this.lastTimeMs))};handleTimeUpdate=e=>{this.lastTimeMs=e.detail.time,this.updateAstronomy(this.lastTimeMs),this.updateUfoOcclusion(this.lastTimeMs)};constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${hd}</style>${cd}`,this.shadow.appendChild(e.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 y3(this.sceneCanvas,void 0,this.handleLightningFlash),this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Lo),this.ufoElement.classList.add("ufo-overlay"),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.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave),this.ufoElement.canvasElement.addEventListener("pointerdown",this.handleFirstInteraction,{once:!0})}connectedCallback(){this.resizeToStage(),this.updateAstronomy(this.lastTimeMs),this.loadStars(),this.resizeObserver=new ResizeObserver(()=>this.resizeToStage()),this.resizeObserver.observe(this.frameElement),document.addEventListener("fullscreenchange",this.handleFullscreenChange);const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose()}attributeChangedCallback(e,t,n){if(e==="src"&&n&&n!==t&&this.isConnected&&this.loadFromSrc(n),e==="star-catalog-src"&&n!==t&&this.isConnected&&this.loadStars(),e==="show-compass"&&n!==t&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),e==="lens-flare-intensity"&&n!==t){const s=n===null?NaN:parseFloat(n);this.sceneRenderer.setLensFlareArtifactIntensity(Number.isFinite(s)?s:0)}if(e==="lens-flare-brightness"&&n!==t){const s=n===null?NaN:parseFloat(n);this.sceneRenderer.setDazzleIntensity(Number.isFinite(s)?s:1)}}setCompassForced(e){this.sceneRenderer.setCompassForced(e)}setIndoorLook(e,t){this.sceneRenderer.setIndoorLook(e,t)}setWeather(e){this.sceneRenderer.setWeather(e),this.weatherAudio.setAmbient(e.precipitationType,e.precipitationIntensity,e.windSpeed)}pickDecorAt(e,t){return this.sceneRenderer.pickDecorAt(e,t)}resumeWeatherAudio(){this.weatherAudio.resume()}async loadFromSrc(e){const t=await fetch(e);this.sightingData=await t.json()}get sightingData(){return this.ufoElement.sightingData}set sightingData(e){this.ufoElement.sightingData=e,this.lastTimeMs=0,this.updateAstronomy(0)}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}setTerrainProviders(e){this.sceneRenderer.setTerrainProviders(e)}resizeToStage(){const e=this.frameElement.getBoundingClientRect(),t=Math.max(1,Math.round(e.width)),n=Math.max(1,Math.round(e.height));this.sceneCanvas.width=t,this.sceneCanvas.height=n,this.sceneRenderer.resize(t,n)}async loadStars(){const e=this.getAttribute("star-catalog-src")??X3;this.starCatalog=await U3(e),this.updateAstronomy(this.lastTimeMs)}updateAstronomy(e){const t=this.ufoElement.sighting;this.setWeather(Lc(t,e)),this.sceneRenderer.setDecor(t.decor);const n=Dc(t,e);this.sceneRenderer.setObserverPose(n??Co),this.sceneRenderer.updateDecorAnchoring(Dc(t,0),n),this.sceneRenderer.updateDecorLitState(e),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng);const s=n?.lat??Co.lat,r=n?.lng??Co.lng,a=F2(t.event.time??{},r,t.event.utcOffsetHours);if(!a){this.sceneRenderer.setAstronomy(q3);return}const o=new Date(a.getTime()+e),l={lat:s,lng:r,elevationM:n?.elevationM??0},c={...mo("Sun",o,l),magnitude:go("Sun",o)},h={...mo("Moon",o,l),phase:D2(o),magnitude:go("Moon",o)},d=P2.map(u=>({body:u,position:mo(u,o,l),magnitude:go(u,o)}));this.sceneRenderer.setAstronomy({sun:c,moon:h,planets:d,stars:this.starCatalog?{catalog:this.starCatalog,date:o,observer:l}:void 0})}updateUfoOcclusion(e){const t=this.ufoElement.sighting.timeline,n=this.ufoElement.canvasElement,s=new Set;for(const r of t.sourceIds){const a=t.getInterpolatedShapeAt(e,r);if(!a)continue;const o=(a.bounds.x+a.bounds.width/2)/n.width*2-1,l=-((a.bounds.y+a.bounds.height/2)/n.height*2-1),c={declared:a.behindCloud,distanceM:a.physical?.distanceM};this.sceneRenderer.isScreenPointOccluded(o,l,r,c)&&s.add(r)}this.ufoElement.setOccludedSourceIds(s)}}const Lu="rr0-scene";function Z3(){Ou(),customElements.get(Lu)||customElements.define(Lu,Y3)}Z3();
|
|
5102
|
+
`;let Jr;function I3(){if(Jr)return Jr;const i=128,e=document.createElement("canvas");e.width=i,e.height=i;const t=e.getContext("2d"),n=t.createRadialGradient(i/2,i/2,0,i/2,i/2,i/2);return n.addColorStop(0,"rgba(255,255,255,1)"),n.addColorStop(.4,"rgba(255,255,255,0.35)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,i,i),Jr=new Wn(e),Jr}function D3(i){const t=document.createElement("canvas");t.width=128,t.height=128;const n=t.getContext("2d"),s=128/2-2,r=128/2,a=128/2,o="#2e2b26",l="#f4f1e2";n.fillStyle=o,n.beginPath(),n.arc(r,a,s,0,Math.PI*2),n.fill();const c=td(i.illuminatedFraction,0,1),h=i.phaseFraction<.5,d=s*Math.abs(1-2*c),u=c<.5;return n.save(),n.beginPath(),n.arc(r,a,s,0,Math.PI*2),n.clip(),n.fillStyle=l,n.beginPath(),h?(n.arc(r,a,s,-Math.PI/2,Math.PI/2,!1),n.ellipse(r,a,d,s,0,Math.PI/2,-Math.PI/2,u)):(n.arc(r,a,s,Math.PI/2,-Math.PI/2,!1),n.ellipse(r,a,d,s,0,-Math.PI/2,Math.PI/2,u)),n.fill(),n.restore(),new Wn(t)}function L3(i){const e=document.createElement("canvas");e.width=128,e.height=128;const t=e.getContext("2d");return t.fillStyle="rgba(0, 0, 0, 0.55)",t.beginPath(),t.arc(64,64,60,0,Math.PI*2),t.fill(),t.fillStyle="#ffffff",t.font="bold 52px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(i,64,68),new Wn(e)}function Ro(i){let e=i;return function(){e|=0,e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const Du=new Map;function N3(i){const e=i.byteLength/(4*Float32Array.BYTES_PER_ELEMENT),t=e,n=t*Float32Array.BYTES_PER_ELEMENT;return{count:e,ra:new Float32Array(i,0*n,t),dec:new Float32Array(i,1*n,t),mag:new Float32Array(i,2*n,t),ci:new Float32Array(i,3*n,t)}}function U3(i){let e=Du.get(i);return e||(e=fetch(i).then(t=>t.arrayBuffer()).then(N3),Du.set(i,e)),e}const F3=new URL(""+new URL("rain-BvWZrB9h.ogg",import.meta.url).href,import.meta.url).href,O3=new URL(""+new URL("wind-BjklexY7.ogg",import.meta.url).href,import.meta.url).href,B3=new URL(""+new URL("thunder-DA48qs_v.wav",import.meta.url).href,import.meta.url).href,z3=20,k3=1;class G3{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};resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(e){console.warn("WeatherAudio: Web Audio unavailable, weather sounds disabled:",e);return}}this.context.state==="suspended"&&this.context.resume()}setAmbient(e,t,n){if(this.requested={type:e,intensity:t,windSpeed:n},!this.context)return;this.paused&&(e="none",t=0,n=0);const s=e==="rain"||e==="hail"?e:"none";if(this.ambientVolume=s==="hail"?Math.min(1,t*1.3+.2):s==="rain"?t:0,s!==this.ambientKey){this.ambientKey=s;const a=++this.ambientToken;this.stopSource(this.ambientSource,this.ambientGain),this.ambientSource=void 0,this.ambientGain=void 0,s!=="none"&&this.startLoop(F3,this.ambientVolume).then(o=>this.applyIfCurrent(o,a,()=>this.ambientToken,l=>{this.ambientSource=l?.source,this.ambientGain=l?.gain,l&&(l.gain.gain.value=this.ambientVolume)}))}else this.ambientGain&&(this.ambientGain.gain.value=this.ambientVolume);this.windVolume=Math.min(n/z3,1);const r=n>k3;if(r!==this.windActive){this.windActive=r;const a=++this.windToken;this.stopSource(this.windSource,this.windGain),this.windSource=void 0,this.windGain=void 0,r&&this.startLoop(O3,this.windVolume).then(o=>this.applyIfCurrent(o,a,()=>this.windToken,l=>{this.windSource=l?.source,this.windGain=l?.gain,l&&(l.gain.gain.value=this.windVolume)}))}else this.windGain&&(this.windGain.gain.value=this.windVolume)}setPaused(e){if(e===this.paused)return;this.paused=e;const{type:t,intensity:n,windSpeed:s}=this.requested;this.setAmbient(t,n,s)}playThunder(){!this.context||this.paused||this.playOneShot(B3,.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.buffers.clear()}applyIfCurrent(e,t,n,s){if(t!==n()){e?.source.stop();return}s(e)}async startLoop(e,t){const n=this.context;if(n)try{const s=await this.getBuffer(e),r=n.createBufferSource();r.buffer=s,r.loop=!0;const a=n.createGain();return a.gain.value=t,r.connect(a).connect(n.destination),r.start(),{source:r,gain:a}}catch(s){console.warn("Weather ambient sound failed to load, staying silent:",s);return}}async playOneShot(e,t){const n=this.context;if(n)try{const s=await this.getBuffer(e),r=n.createBufferSource();r.buffer=s;const a=n.createGain();a.gain.value=t,r.connect(a).connect(n.destination),r.start()}catch(s){console.warn("Thunder sound failed to load:",s)}}async getBuffer(e){const t=this.context;if(!t)throw new Error("WeatherAudio: AudioContext not ready — resume() must be called first");let n=this.buffers.get(e);return n||(n=fetch(e).then(s=>{if(!s.ok)throw new Error(`Audio fetch failed (${s.status}): ${e}`);return s.arrayBuffer()}).then(s=>t.decodeAudioData(s)),this.buffers.set(e,n)),n}stopSource(e,t){try{e?.stop()}catch{}e?.disconnect(),t?.disconnect()}}Ou();const H3={sun:{en:"Sun",fr:"Soleil"},moon:{en:"Moon",fr:"Lune"},Venus:{en:"Venus",fr:"Vénus"},Mars:{en:"Mars",fr:"Mars"},Jupiter:{en:"Jupiter",fr:"Jupiter"},Saturn:{en:"Saturn",fr:"Saturne"}},V3=["en","fr"],W3={building:{en:"Building",fr:"Bâtiment"},tree:{en:"Tree",fr:"Arbre"},streetlight:{en:"Streetlight",fr:"Lampadaire"},vehicle:{en:"Vehicle",fr:"Véhicule"},witness:{en:"Witness",fr:"Témoin"}},X3=new URL(""+new URL("stars-mag7.5-DDr9QasD.bin",import.meta.url).href,import.meta.url).href,q3={sun:{altitudeDeg:-3,azimuthDeg:180,magnitude:-26.7},moon:{altitudeDeg:-90,azimuthDeg:0,phase:{phaseFraction:0,illuminatedFraction:0},magnitude:-12.7},planets:[]},Co={lat:0,lng:0,elevationM:0,headingDeg:void 0,pitchDeg:0,fovDeg:60};class Y3 extends HTMLElement{static get observedAttributes(){return["src","star-catalog-src","show-compass","lens-flare-intensity","lens-flare-brightness"]}shadow;stageElement;frameElement;sceneCanvas;ufoElement;sceneRenderer;hoverTooltip;resizeObserver;lastTimeMs=0;starCatalog;weatherAudio=new G3;thunderTimeoutId;handleFullscreenChange=()=>this.resizeToStage();handlePointerMove=e=>{this.sceneRenderer.setCompassHovered(!0);const t=this.ufoElement.canvasElement,n=t.getBoundingClientRect();if(n.width===0||n.height===0)return;const s=(e.clientX-n.left)/n.width*t.width,r=(e.clientY-n.top)/n.height*t.height;if(this.ufoElement.hasVisibleShapeAt(s,r)){this.hoverTooltip.hidden=!0;return}const a=(e.clientX-n.left)/n.width*2-1,o=-((e.clientY-n.top)/n.height*2-1),l=Jl(navigator.languages,V3),c=this.sceneRenderer.pickBodyAt(a,o);if(c){this.showHoverTooltip(e,H3[c]?.[l]??c);return}const h=this.sceneRenderer.pickDecorAt(a,o),d=h?this.ufoElement.sighting.decor.find(u=>u.id===h):void 0;if(d){this.showHoverTooltip(e,d.title||W3[d.kind][l]);return}this.hoverTooltip.hidden=!0};showHoverTooltip(e,t){this.hoverTooltip.textContent=t,this.hoverTooltip.hidden=!1;const n=this.stageElement.getBoundingClientRect();this.hoverTooltip.style.left=`${e.clientX-n.left+12}px`,this.hoverTooltip.style.top=`${e.clientY-n.top+12}px`}handlePointerLeave=()=>{this.hoverTooltip.hidden=!0,this.sceneRenderer.setCompassHovered(!1)};handleLightningFlash=()=>{clearTimeout(this.thunderTimeoutId);const e=(.5+Math.random()*3.5)*1e3;this.thunderTimeoutId=window.setTimeout(()=>this.weatherAudio.playThunder(),e)};handleFirstInteraction=()=>{this.weatherAudio.resume(),this.setWeather(Lc(this.ufoElement.sighting,this.lastTimeMs))};handleTimeUpdate=e=>{this.lastTimeMs=e.detail.time,this.syncAnimationsToPlayback(),this.updateAstronomy(this.lastTimeMs),this.updateUfoOcclusion(this.lastTimeMs)};syncAnimationsToPlayback(){const e=this.ufoElement.playbackState==="playing";this.sceneRenderer.setAnimationsRunning(e),this.weatherAudio.setPaused(!e),e||clearTimeout(this.thunderTimeoutId)}constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>${hd}</style>${cd}`,this.shadow.appendChild(e.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 y3(this.sceneCanvas,void 0,this.handleLightningFlash),this.hoverTooltip=this.shadow.getElementById("hover-tooltip"),this.ufoElement=document.createElement(Lo),this.ufoElement.classList.add("ufo-overlay"),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.addEventListener("timeupdate",this.handleTimeUpdate),this.ufoElement.canvasElement.addEventListener("pointermove",this.handlePointerMove),this.ufoElement.canvasElement.addEventListener("pointerleave",this.handlePointerLeave),this.ufoElement.canvasElement.addEventListener("pointerdown",this.handleFirstInteraction,{once:!0})}connectedCallback(){this.resizeToStage(),this.updateAstronomy(this.lastTimeMs),this.loadStars(),this.resizeObserver=new ResizeObserver(()=>this.resizeToStage()),this.resizeObserver.observe(this.frameElement),document.addEventListener("fullscreenchange",this.handleFullscreenChange);const e=this.getAttribute("src");e&&this.loadFromSrc(e)}disconnectedCallback(){this.resizeObserver?.disconnect(),document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.sceneRenderer.stopTwinkle(),clearTimeout(this.thunderTimeoutId),this.weatherAudio.dispose()}attributeChangedCallback(e,t,n){if(e==="src"&&n&&n!==t&&this.isConnected&&this.loadFromSrc(n),e==="star-catalog-src"&&n!==t&&this.isConnected&&this.loadStars(),e==="show-compass"&&n!==t&&this.sceneRenderer.setShowCompass(this.hasAttribute("show-compass")),e==="lens-flare-intensity"&&n!==t){const s=n===null?NaN:parseFloat(n);this.sceneRenderer.setLensFlareArtifactIntensity(Number.isFinite(s)?s:0)}if(e==="lens-flare-brightness"&&n!==t){const s=n===null?NaN:parseFloat(n);this.sceneRenderer.setDazzleIntensity(Number.isFinite(s)?s:1)}}setCompassForced(e){this.sceneRenderer.setCompassForced(e)}setIndoorLook(e,t){this.sceneRenderer.setIndoorLook(e,t)}setWeather(e){this.sceneRenderer.setWeather(e),this.weatherAudio.setAmbient(e.precipitationType,e.precipitationIntensity,e.windSpeed)}pickDecorAt(e,t){return this.sceneRenderer.pickDecorAt(e,t)}resumeWeatherAudio(){this.weatherAudio.resume()}async loadFromSrc(e){const t=await fetch(e);this.sightingData=await t.json()}get sightingData(){return this.ufoElement.sightingData}set sightingData(e){this.ufoElement.sightingData=e,this.lastTimeMs=0,this.updateAstronomy(0)}get currentTerrainAttribution(){return this.sceneRenderer.currentTerrainAttribution}setTerrainProviders(e){this.sceneRenderer.setTerrainProviders(e)}resizeToStage(){const e=this.frameElement.getBoundingClientRect(),t=Math.max(1,Math.round(e.width)),n=Math.max(1,Math.round(e.height));this.sceneCanvas.width=t,this.sceneCanvas.height=n,this.sceneRenderer.resize(t,n)}async loadStars(){const e=this.getAttribute("star-catalog-src")??X3;this.starCatalog=await U3(e),this.updateAstronomy(this.lastTimeMs)}updateAstronomy(e){const t=this.ufoElement.sighting;this.setWeather(Lc(t,e)),this.sceneRenderer.setDecor(t.decor);const n=Dc(t,e);this.sceneRenderer.setObserverPose(n??Co),this.sceneRenderer.updateDecorAnchoring(Dc(t,0),n),this.sceneRenderer.updateDecorLitState(e),this.sceneRenderer.setTerrainOrigin(n?.lat,n?.lng);const s=n?.lat??Co.lat,r=n?.lng??Co.lng,a=F2(t.event.time??{},r,t.event.utcOffsetHours);if(!a){this.sceneRenderer.setAstronomy(q3);return}const o=new Date(a.getTime()+e),l={lat:s,lng:r,elevationM:n?.elevationM??0},c={...mo("Sun",o,l),magnitude:go("Sun",o)},h={...mo("Moon",o,l),phase:D2(o),magnitude:go("Moon",o)},d=P2.map(u=>({body:u,position:mo(u,o,l),magnitude:go(u,o)}));this.sceneRenderer.setAstronomy({sun:c,moon:h,planets:d,stars:this.starCatalog?{catalog:this.starCatalog,date:o,observer:l}:void 0})}updateUfoOcclusion(e){const t=this.ufoElement.sighting.timeline,n=this.ufoElement.canvasElement,s=new Set;for(const r of t.sourceIds){const a=t.getInterpolatedShapeAt(e,r);if(!a)continue;const o=(a.bounds.x+a.bounds.width/2)/n.width*2-1,l=-((a.bounds.y+a.bounds.height/2)/n.height*2-1),c={declared:a.behindCloud,distanceM:a.physical?.distanceM};this.sceneRenderer.isScreenPointOccluded(o,l,r,c)&&s.add(r)}this.ufoElement.setOccludedSourceIds(s)}}const Lu="rr0-scene";function Z3(){Ou(),customElements.get(Lu)||customElements.define(Lu,Y3)}Z3();
|