File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/static/views/starfield.js
(function(){"use strict";const F=document.getElementById("c"),t=F.getContext("2d");let V=120,O=80,W=260,Q=1,_=50,$=!1,D=!1;const U=350,tt=32*Math.PI/180,ht=Math.cos(tt),mt=Math.sin(tt),k=80,H=3200,et=2400,ft=40,j=["rgba(255,255,255,","rgba(255,250,240,","rgba(235,245,255,","rgba(255,220,200,","rgba(200,220,255,"];let Z=2e3;const nt=3e3,N=5e3,z=[];function ot(){return{x:(Math.random()-.5)*N,y:(Math.random()-.5)*N,z:Math.random()*nt+20,tint:Math.floor(Math.random()*j.length),prevSx:0,prevSy:0,hasPrev:!1}}function ut(){for(;z.length<Z;)z.push(ot());for(;z.length>Z;)z.pop()}for(let e=0;e<Z;e++)z.push(ot());const S=[];let G=!1,w=[];function at(){return O+Math.random()*(W-O)}function lt(e){const l=S.length>0?Math.floor(Math.random()*S.length):0;return{planeX:(Math.random()-.5)*et,planeY:e?k+Math.random()*(H-k):H+Math.random()*200,size:at(),speedMult:.6+Math.random()*.8,imgIdx:l,opacity:1}}function gt(){w=[];for(let e=0;e<_;e++)w.push(lt(!0))}function pt(){for(;w.length<_;)w.push(lt(!0));for(;w.length>_;)w.pop()}async function Mt(){try{const l=await(await fetch(ViewLib.Thumbnail.buildThumbnailListUrl(0,200))).json();let d=0;const r=l.items.filter(h=>h.thumbnailId).length;for(const h of l.items){if(!h.thumbnailId)continue;const m={img:new Image,loaded:!1};m.img.onload=()=>{m.loaded=!0,d++,d>=Math.min(20,r)&&(G=!0,document.getElementById("loading").classList.add("hidden"))},m.img.src=ViewLib.Thumbnail.buildThumbnailUrl(h.thumbnailId),S.push(m)}r===0&&(G=!0,document.getElementById("loading").classList.add("hidden"))}catch{document.getElementById("loading").textContent="Failed to load photos"}}function it(){F.width=window.innerWidth,F.height=window.innerHeight}window.addEventListener("resize",it),it();let A=0;function yt(e){const l=e*.12;return Math.sin(A*.13)*l+Math.sin(A*.07+1.5)*l*.6+Math.sin(A*.03+3)*l*.3}function bt(e){const l=e*.03;return Math.sin(A*.09+2)*l+Math.sin(A*.05+.7)*l*.5}let X=0;function st(e){requestAnimationFrame(st);const l=X?Math.min((e-X)/1e3,.1):0;if(X=e,D)return;A+=l;const d=F.width,r=F.height,h=d/2+yt(d),m=r*.88+bt(r);t.clearRect(0,0,d,r),wt(l,d,r,h,m),G&&S.length>0&&Tt(l,d,r,h,m)}function wt(e,l,d,r,h){const m=V*Q*.6,o=h*.5;for(const n of z){const C=n.z;if(n.z-=m*e,n.z<1){n.z=nt+Math.random()*500,n.x=(Math.random()-.5)*N,n.y=(Math.random()-.5)*N,n.tint=Math.floor(Math.random()*j.length),n.hasPrev=!1;continue}const L=U/n.z,p=r+n.x*L,g=o+n.y*L;if(p<-50||p>l+50||g<-50||g>d+50){n.hasPrev=!1;continue}const b=Math.min(1,200/n.z),I=j[n.tint];if(n.hasPrev&&m>10){const a=U/C,q=r+n.x*a,f=o+n.y*a;Math.sqrt((p-q)**2+(g-f)**2)>1.5&&(t.beginPath(),t.moveTo(q,f),t.lineTo(p,g),t.strokeStyle=I+b*.5+")",t.lineWidth=Math.max(.5,Math.min(1.5,.8*L*10)),t.stroke())}const E=Math.max(.5,1.4*L);E<1?(t.globalAlpha=b*.7,t.fillStyle=I+"1)",t.fillRect(p-.5,g-.5,1,1)):(t.globalAlpha=b,t.fillStyle=I+"1)",t.beginPath(),t.arc(p,g,Math.min(E,2),0,Math.PI*2),t.fill(),b>.4&&(t.globalAlpha=b*.15,t.beginPath(),t.arc(p,g,E*3,0,Math.PI*2),t.fill())),n.prevSx=p,n.prevSy=g,n.hasPrev=!0}t.globalAlpha=1}function Tt(e,l,d,r,h){for(const o of w)o.planeY-=V*o.speedMult*e,o.planeY<k*.2&&(o.planeY=H+Math.random()*300,o.planeX=(Math.random()-.5)*et,o.size=at(),o.speedMult=.6+Math.random()*.8,o.imgIdx=Math.floor(Math.random()*S.length));const m=[...w].sort((o,n)=>n.planeY-o.planeY);for(const o of m){const n=S[o.imgIdx%S.length];if(!n||!n.loaded)continue;const C=o.planeY,L=o.planeX,p=-C*ht,g=C*mt+ft;if(g<10)continue;const b=U/g,I=r+L*b,E=h+p*b,a=o.size*b,q=n.img.naturalHeight/n.img.naturalWidth||.75,f=a*q;if(a<3||I+a<0||I-a>l||E+f<-20||E-f>d+20)continue;const ct=Math.min(1,(C-k*.2)/(k*.8)),Pt=Math.min(1,(H+300-C)/400),K=Math.max(0,Math.min(1,ct*Pt));if(K<=0)continue;t.save(),t.globalAlpha=K;const R=I-a/2,Y=E-f/2;if($&&a>12){const u=Math.max(3,a*.08),T=Math.max(2,a*.06),c=Math.max(1,u*.25),i=R-T-u,s=Y-T-u,M=a+(T+u)*2,y=f+(T+u)*2;t.shadowColor="rgba(0,0,0,0.6)",t.shadowBlur=Math.max(6,a*.1),t.shadowOffsetY=Math.max(2,a*.02),t.fillStyle="#1a1208",t.fillRect(i,s,M,y),t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetY=0,t.fillStyle="rgba(255,240,200,0.12)",t.beginPath(),t.moveTo(i,s),t.lineTo(i+M,s),t.lineTo(i+M-c,s+c),t.lineTo(i+c,s+c),t.closePath(),t.fill(),t.beginPath(),t.moveTo(i,s),t.lineTo(i+c,s+c),t.lineTo(i+c,s+y-c),t.lineTo(i,s+y),t.closePath(),t.fill(),t.fillStyle="rgba(0,0,0,0.25)",t.beginPath(),t.moveTo(i,s+y),t.lineTo(i+M,s+y),t.lineTo(i+M-c,s+y-c),t.lineTo(i+c,s+y-c),t.closePath(),t.fill(),t.beginPath(),t.moveTo(i+M,s),t.lineTo(i+M,s+y),t.lineTo(i+M-c,s+y-c),t.lineTo(i+M-c,s+c),t.closePath(),t.fill();const x=i+u,v=s+u,rt=M-u*2,dt=y-u*2,P=Math.max(1,c*.6);t.fillStyle="rgba(0,0,0,0.2)",t.beginPath(),t.moveTo(x,v),t.lineTo(x+rt,v),t.lineTo(x+rt-P,v+P),t.lineTo(x+P,v+P),t.closePath(),t.fill(),t.beginPath(),t.moveTo(x,v),t.lineTo(x+P,v+P),t.lineTo(x+P,v+dt-P),t.lineTo(x,v+dt),t.closePath(),t.fill(),t.fillStyle="#f5f0e8",t.fillRect(R-T,Y-T,a+T*2,f+T*2),t.drawImage(n.img,R,Y,a,f)}else{t.shadowColor="rgba(80, 130, 255, 0.25)",t.shadowBlur=Math.max(4,a*.08);const u=Math.max(2,a*.03);t.beginPath(),window.OD4StarfieldCanvasPath.roundRect(t,R,Y,a,f,u),t.clip(),t.drawImage(n.img,R,Y,a,f),t.shadowColor="transparent",t.globalAlpha=K*.35,t.strokeStyle="#fff",t.lineWidth=Math.max(1,a*.015),t.beginPath(),window.OD4StarfieldCanvasPath.roundRect(t,R,Y,a,f,u),t.stroke()}t.restore()}}const xt=document.getElementById("panel"),vt=document.getElementById("toggle-btn");let J=!0;vt.addEventListener("click",()=>{J=!J,xt.classList.toggle("hidden",!J)});function B(e,l,d,r){const h=document.getElementById(e),m=document.getElementById(l);h.addEventListener("input",()=>{const o=parseFloat(h.value);d(o),m.textContent=r?r(o):o})}B("speed","speed-val",e=>{V=e}),B("min-size","min-size-val",e=>{O=e,W<e&&(W=e,document.getElementById("max-size").value=e,document.getElementById("max-size-val").textContent=e)}),B("max-size","max-size-val",e=>{W=e,O>e&&(O=e,document.getElementById("min-size").value=e,document.getElementById("min-size-val").textContent=e)}),B("star-speed","star-speed-val",e=>{Q=e/10},e=>(e/10).toFixed(1)),B("star-count","star-count-val",e=>{Z=Math.round(e),ut()}),B("photo-count","count-val",e=>{_=Math.round(e),pt()}),document.getElementById("frames-toggle").addEventListener("change",e=>{$=e.target.checked}),window.addEventListener("keydown",e=>{e.code==="Space"&&e.target===document.body&&(e.preventDefault(),D=!D,D||(X=0))}),Mt().then(()=>{gt()}),requestAnimationFrame(st)})();