File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/static/views/spiral.js
(function(){"use strict";const c=document.getElementById("canvas"),e=c.getContext("2d"),L=document.getElementById("loading");let f=[],S=new Map,m=[],h=0,g=0,d=1,T=0,p=0,v=90,b=25,y=.4;const P=100,z=12;let w=!1,C=0,I=0,u=null;function B(){c.width=window.innerWidth,c.height=window.innerHeight,T=c.width/2,p=c.height/2}window.addEventListener("resize",B),B();async function A(){try{f=(await(await fetch(ViewLib.Thumbnail.buildThumbnailListUrl(0,200))).json()).items;const l=f.map(t=>new Promise(a=>{const o=new Image;o.onload=()=>{S.set(t.thumbnailId,o),a()},o.onerror=()=>a(),o.src=ViewLib.Thumbnail.buildThumbnailUrl(t.thumbnailId)}));await Promise.all(l),x(),M(),L.classList.add("hidden")}catch(i){console.error("Failed to load photos:",i),L.textContent="Failed to load photos"}}function x(){m=[];let i=0;for(let n=0;n<f.length;n++){const l=P+z*i,t=l*Math.cos(i),a=l*Math.sin(i),o=n/Math.max(1,f.length-1),s=v-o*(v-b);m.push({x:t,y:a,r:l,theta:i,size:s,photo:f[n]}),i+=y}}function M(){if(m.length===0)return;let i=0;for(const t of m)t.r>i&&(i=t.r);const n=i*.7;d=Math.min(c.width,c.height)*.8/(n*2),d=Math.max(.15,Math.min(4,d)),h=0,g=0}function E(i,n){const l=(i-T-h)/d,t=(n-p-g)/d;return{x:l,y:t}}function V(){if(m.length===0)return;e.strokeStyle="#333",e.lineWidth=1,e.beginPath();const i=500,n=m[m.length-1].theta+y;for(let l=0;l<=i;l++){const t=n*l/i,a=P+z*t,o=a*Math.cos(t),s=a*Math.sin(t);l===0?e.moveTo(o,s):e.lineTo(o,s)}e.stroke()}function W(){e.fillStyle="#555",e.beginPath(),e.arc(0,0,8,0,Math.PI*2),e.fill(),e.strokeStyle="#777",e.lineWidth=2,e.stroke()}function R(){e.fillStyle="#666",e.font='11px -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif',e.textAlign="center",e.textBaseline="middle";let i=null;for(const n of m){if(!n.photo.takenDateTime)continue;const l=Od4Shared.DateFormat.parseAsRecorded(n.photo.takenDateTime);if(!l)continue;const t=l.getFullYear();if(t!==i){i=t;const a=n.x+15*Math.cos(n.theta+Math.PI/2),o=n.y+15*Math.sin(n.theta+Math.PI/2);e.fillText(t.toString(),a,o)}}}function U(){for(let i=m.length-1;i>=0;i--){const n=m[i],l=S.get(n.photo.thumbnailId);if(!l)continue;const t=n.size,a=t/2;e.save();const o=4,s=n.x-a,r=n.y-a;e.beginPath(),e.moveTo(s+o,r),e.lineTo(s+t-o,r),e.quadraticCurveTo(s+t,r,s+t,r+o),e.lineTo(s+t,r+t-o),e.quadraticCurveTo(s+t,r+t,s+t-o,r+t),e.lineTo(s+o,r+t),e.quadraticCurveTo(s,r+t,s,r+t-o),e.lineTo(s,r+o),e.quadraticCurveTo(s,r,s+o,r),e.closePath(),e.clip(),e.drawImage(l,s,r,t,t),e.restore(),e.strokeStyle="rgba(255, 255, 255, 0.15)",e.lineWidth=1,e.beginPath(),e.moveTo(s+o,r),e.lineTo(s+t-o,r),e.quadraticCurveTo(s+t,r,s+t,r+o),e.lineTo(s+t,r+t-o),e.quadraticCurveTo(s+t,r+t,s+t-o,r+t),e.lineTo(s+o,r+t),e.quadraticCurveTo(s,r+t,s,r+t-o),e.lineTo(s,r+o),e.quadraticCurveTo(s,r,s+o,r),e.closePath(),e.stroke()}}function $(){if(!u)return;const i=S.get(u.photo.thumbnailId);if(!i)return;const n=u.size*1.5,l=n/2,t=u.x-l,a=u.y-l,o=6;e.save(),e.shadowColor="rgba(0, 0, 0, 0.5)",e.shadowBlur=20,e.shadowOffsetX=0,e.shadowOffsetY=4,e.beginPath(),e.moveTo(t+o,a),e.lineTo(t+n-o,a),e.quadraticCurveTo(t+n,a,t+n,a+o),e.lineTo(t+n,a+n-o),e.quadraticCurveTo(t+n,a+n,t+n-o,a+n),e.lineTo(t+o,a+n),e.quadraticCurveTo(t,a+n,t,a+n-o),e.lineTo(t,a+o),e.quadraticCurveTo(t,a,t+o,a),e.closePath(),e.clip(),e.drawImage(i,t,a,n,n),e.restore(),e.strokeStyle="#7b9dff",e.lineWidth=3,e.beginPath(),e.moveTo(t+o,a),e.lineTo(t+n-o,a),e.quadraticCurveTo(t+n,a,t+n,a+o),e.lineTo(t+n,a+n-o),e.quadraticCurveTo(t+n,a+n,t+n-o,a+n),e.lineTo(t+o,a+n),e.quadraticCurveTo(t,a+n,t,a+n-o),e.lineTo(t,a+o),e.quadraticCurveTo(t,a,t+o,a),e.closePath(),e.stroke(),e.save(),e.setTransform(1,0,0,1,0,0);const s=T+h+u.x*d,r=p+g+u.y*d+n*d/2+20;e.fillStyle="rgba(20, 20, 20, 0.9)",e.font='13px -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif',e.textAlign="center";const Z=u.photo.name||"Unknown",G=u.photo.takenDateTime?new Date(u.photo.takenDateTime.replace(/Z$/i,"").replace(/\.\d+$/,"").replace(/-/g,"/").replace("T"," ")).toLocaleDateString():"No date",X=`${Z} - ${G}`,D=e.measureText(X),F=8;e.fillRect(s-D.width/2-F,r-10,D.width+F*2,20),e.fillStyle="#e0e0e0",e.fillText(X,s,r),e.restore()}function k(){e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,c.width,c.height),e.translate(T+h,p+g),e.scale(d,d),V(),W(),R(),U(),$(),requestAnimationFrame(k)}c.addEventListener("mousedown",i=>{w=!0,C=i.clientX,I=i.clientY,c.classList.add("grabbing")}),c.addEventListener("mousemove",i=>{if(w){const n=i.clientX-C,l=i.clientY-I;h+=n,g+=l,C=i.clientX,I=i.clientY}else{const n=E(i.clientX,i.clientY);u=null;for(const l of m){const t=l.size/2;if(n.x>=l.x-t&&n.x<=l.x+t&&n.y>=l.y-t&&n.y<=l.y+t){u=l;break}}}}),c.addEventListener("mouseup",()=>{w=!1,c.classList.remove("grabbing")}),c.addEventListener("mouseleave",()=>{w=!1,c.classList.remove("grabbing"),u=null}),c.addEventListener("wheel",i=>{i.preventDefault();const n=i.clientX,l=i.clientY,t=E(n,l),a=i.deltaY<0?1.1:.9;d*=a,d=Math.max(.15,Math.min(4,d));const o=E(n,l);h+=(o.x-t.x)*d,g+=(o.y-t.y)*d});const H=document.getElementById("maxSize"),O=document.getElementById("minSize"),j=document.getElementById("spacing"),N=document.getElementById("resetBtn"),q=document.getElementById("toggleBtn"),Y=document.getElementById("controls");H.addEventListener("input",i=>{v=parseFloat(i.target.value),document.getElementById("maxSizeValue").textContent=v,x()}),O.addEventListener("input",i=>{b=parseFloat(i.target.value),document.getElementById("minSizeValue").textContent=b,x()}),j.addEventListener("input",i=>{y=parseFloat(i.target.value),document.getElementById("spacingValue").textContent=y.toFixed(2),x()}),N.addEventListener("click",()=>{M()}),q.addEventListener("click",()=>{Y.classList.toggle("collapsed"),q.textContent=Y.classList.contains("collapsed")?"Show Controls":"Hide Controls"}),A(),k()})();