File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/static/views/darkroom.js
(function(){"use strict";var P=document.getElementById("canvas"),e=P.getContext("2d"),H=document.getElementById("loading"),A=document.getElementById("lightbox"),x=document.getElementById("lightbox-img"),B=document.getElementById("pageInfo"),M=3,I=140,v=8,ee=2.5*Math.PI/180,te=2.5,U=.18,G=20,R=16,p=14,q=10,i,u,m=0,S=0,y=!1,b=0,d=[],T=null,k=!1,D=-1e3,W=-1e3,z=performance.now()/1e3;function _(){var t=i-100;return Math.max(3,Math.min(7,Math.floor(t/(I*.75+v*2+30))))}function E(){return _()*M}function F(){i=window.innerWidth,u=window.innerHeight,P.width=i,P.height=u}F(),window.addEventListener("resize",function(){F(),d.length>0&&X()});function O(t){var a=u*.1,n=u*.18,r=u-a-n;return a+t*(r/(M-1||1))}function Y(t,a){var n=(a-40)/(i-80);return t+G*4*n*(1-n)}function X(){for(var t=_(),a=0;a<d.length;a++){var n=d[a],r=Math.floor(a/t);if(!(r>=M)){var h=a%t,o=O(r),s=60,f=i-s*2,l=f/t,c=s+l*.5+l*h,g=(n._jitterSeed-.5)*l*.35,L=c+g,w=I*.75;n.img&&n.img.naturalWidth&&(w=I*(n.img.naturalWidth/n.img.naturalHeight)),n.x=L,n.y=Y(o,L)+R+4,n.w=w+v*2,n.h=I+v*2,n.photoW=w,n.lineIndex=r}}}function J(t,a){d=[];for(var n=_(),r=Math.min(t.length,n*M),h=0;h<r;h++){var o=(Math.random()-.5)*10*Math.PI/180,s=[];if(Math.random()<.3)for(var f=Math.floor(Math.random()*3)+1,l=0;l<f;l++)s.push({rx:Math.random()*.8+.1,ry:Math.random()*.3+.7,size:Math.random()*2+1,brightness:Math.random()*.3+.3});d.push({x:0,y:0,w:0,h:0,photoW:0,rotation:o,baseRotation:o,swayPhase:Math.random()*Math.PI*2,swaySpeed:.4+Math.random()*.3,developProgress:0,developDelay:h*U+Math.random()*.1,developStartTime:-1,img:t[h],thumbnailId:a[h],lineIndex:0,drips:s,_jitterSeed:Math.random()})}X()}function C(){for(var t=performance.now()/1e3-z,a=0;a<d.length;a++)d[a].developProgress=0,d[a].developDelay=a*U+Math.random()*.08,d[a].developStartTime=t}function ae(){if(m===0){B.textContent="";return}var t=E(),a=Math.floor(S/t)+1;B.textContent="Page "+a+" of "+Math.ceil(m/t)}function N(t){if(!y){y=!0;var a=++b,n=E();ViewLib.Thumbnail.fetchThumbnailPage(t,n).then(function(r){if(a===b){m=r.total,S=t,ae();var h=ViewLib.Thumbnail.filterValidThumbnails(r.items),o=[],s=[];return Promise.all(h.map(function(f,l){return new Promise(function(c){var g=new Image;g.onload=function(){a===b&&(o[l]=g,s[l]=f.thumbnailId),c()},g.onerror=function(){c()},g.dataset.od4ApiName="thumbnail.single",g.src=ViewLib.Thumbnail.buildThumbnailUrl(f.thumbnailId)})})).then(function(){if(a===b){for(var f=[],l=[],c=0;c<o.length;c++)o[c]&&(f.push(o[c]),l.push(s[c]));J(f,l),C(),H.classList.add("hidden")}})}}).catch(function(r){console.error("Failed to load photos:",r)}).then(function(){y=!1})}}function K(){if(!y){y=!0;var t=++b,a=E(),n=m===0?ViewLib.Thumbnail.fetchThumbnailPage(0,1).then(function(r){t===b&&(m=r.total)}):Promise.resolve();n.then(function(){for(var r=[],h=0;h<a;h++)r.push(Math.floor(Math.random()*m));var o=[],s=[];return Promise.all(r.map(function(f,l){return ViewLib.Thumbnail.fetchThumbnailPage(f,1).then(function(c){if(t===b){var g=c.items[0];if(g&&g.thumbnailId)return new Promise(function(L){var w=new Image;w.onload=function(){t===b&&(o[l]=w,s[l]=g.thumbnailId),L()},w.onerror=function(){L()},w.src=ViewLib.Thumbnail.buildThumbnailUrl(g.thumbnailId)})}})})).then(function(){if(t===b){for(var f=[],l=[],c=0;c<o.length;c++)o[c]&&(f.push(o[c]),l.push(s[c]));J(f,l),C(),S=-1,B.textContent="shuffled / "+m,H.classList.add("hidden")}})}).catch(function(r){console.error("Failed to shuffle:",r)}).then(function(){y=!1})}}function Q(){if(m){var t=E(),a=S===-1?0:S+t;a>=m&&(a=0),N(a)}}function Z(){if(m){var t=E(),a=S===-1?0:S-t;a<0&&(a=Math.max(0,m-t)),N(a)}}function $(t,a){for(var n=d.length-1;n>=0;n--){var r=d[n];if(!(r.developProgress<.05)&&t>=r.x-r.w/2&&t<=r.x+r.w/2&&a>=r.y&&a<=r.y+r.h)return r}return null}function ne(){var t=e.createRadialGradient(i*.08,u*.02,10,i*.08,u*.02,i*.55);t.addColorStop(0,"rgba(90, 25, 15, 0.35)"),t.addColorStop(.3,"rgba(60, 18, 12, 0.15)"),t.addColorStop(1,"transparent"),e.fillStyle=t,e.fillRect(0,0,i,u);var a=e.createRadialGradient(i*.92,u*.02,10,i*.92,u*.02,i*.55);a.addColorStop(0,"rgba(80, 30, 10, 0.3)"),a.addColorStop(.3,"rgba(55, 15, 10, 0.12)"),a.addColorStop(1,"transparent"),e.fillStyle=a,e.fillRect(0,0,i,u),[[i*.08,u*.02+8],[i*.92,u*.02+8]].forEach(function(n){e.fillStyle="rgba(120, 35, 20, 0.6)",e.beginPath(),e.arc(n[0],n[1],12,0,Math.PI*2),e.fill(),e.fillStyle="rgba(180, 60, 30, 0.7)",e.beginPath(),e.arc(n[0],n[1],5,0,Math.PI*2),e.fill()})}function re(){var t=i*.85,a=u-10;e.fillStyle="rgba(25, 15, 12, 0.7)",e.strokeStyle="rgba(40, 25, 20, 0.35)",e.lineWidth=1.5,e.fillRect(t-50,a-15,100,15),e.strokeRect(t-50,a-15,100,15),e.fillRect(t+20,a-130,10,115),e.strokeRect(t+20,a-130,10,115),e.beginPath(),e.moveTo(t-10,a-110),e.lineTo(t+25,a-130),e.lineTo(t+25,a-95),e.closePath(),e.fill(),e.stroke(),e.fillRect(t-5,a-95,20,25),e.strokeRect(t-5,a-95,20,25),e.beginPath(),e.moveTo(t,a-70),e.lineTo(t+10,a-70),e.lineTo(t+14,a-50),e.lineTo(t-4,a-50),e.closePath(),e.fill(),e.stroke();var n=i*.1,r=u-10;e.fillStyle="rgba(22, 14, 10, 0.6)",e.fillRect(n-80,r-20,200,20),e.strokeRect(n-80,r-20,200,20),e.strokeStyle="rgba(50, 30, 25, 0.35)";for(var h=0;h<3;h++){var o=n-65+h*60;e.strokeRect(o,r-30,50,12),e.strokeStyle="rgba(60, 35, 28, 0.2)",e.beginPath(),e.moveTo(o+3,r-24),e.lineTo(o+47,r-24),e.stroke(),e.strokeStyle="rgba(50, 30, 25, 0.35)"}e.strokeStyle="rgba(55, 35, 25, 0.3)",e.lineWidth=1.5,e.beginPath(),e.moveTo(n+140,r-25),e.lineTo(n+155,r-55),e.stroke(),e.beginPath(),e.moveTo(n+143,r-25),e.lineTo(n+152,r-55),e.stroke()}function oe(){e.strokeStyle="#444",e.lineWidth=1.5;for(var t=0;t<M;t++){var a=O(t),n=30,r=i-30;e.beginPath(),e.moveTo(n,a),e.quadraticCurveTo(i/2,a+G,r,a),e.stroke(),e.fillStyle="#555",e.beginPath(),e.arc(n,a,3,0,Math.PI*2),e.fill(),e.beginPath(),e.arc(r,a,3,0,Math.PI*2),e.fill()}}function le(t,a){e.fillStyle="#777",e.strokeStyle="#555",e.lineWidth=.5,e.beginPath(),e.moveTo(t-p/2,a),e.lineTo(t+p/2,a),e.lineTo(t+q/2,a+R),e.lineTo(t-q/2,a+R),e.closePath(),e.fill(),e.stroke(),e.fillStyle="rgba(180, 180, 180, 0.3)",e.fillRect(t-2,a+2,4,R-4),e.strokeStyle="#999",e.lineWidth=1.2,e.beginPath(),e.moveTo(t-2,a+3),e.lineTo(t-p/2-4,a-4),e.stroke(),e.beginPath(),e.moveTo(t+2,a+3),e.lineTo(t+p/2+4,a-4),e.stroke()}function ie(t,a,n){if(!(t.developProgress<=0)){e.save();var r=n?t.baseRotation:t.baseRotation+Math.sin(a*t.swaySpeed+t.swayPhase)*ee;t.rotation=r;var h=n?1.05:1;e.translate(t.x,t.y),e.rotate(r),e.scale(h,h);var o=-t.w/2,s=0;if(e.fillStyle="#f0ece4",e.globalAlpha=Math.min(1,t.developProgress*3),e.fillRect(o,s,t.w,t.h),t.img&&(e.globalAlpha=t.developProgress,e.drawImage(t.img,o+v,s+v,t.photoW,I),e.globalAlpha=.08*(1-(n?.7:0)),e.fillStyle="rgba(120, 30, 15, 1)",e.fillRect(o+v,s+v,t.photoW,I)),t.drips.length>0&&t.developProgress>.5){e.globalAlpha=t.developProgress*.6;for(var f=0;f<t.drips.length;f++){var l=t.drips[f];e.fillStyle="rgba(200, 200, 210, "+l.brightness+")",e.beginPath(),e.arc(o+v+l.rx*t.photoW,s+v+l.ry*I,l.size,0,Math.PI*2),e.fill()}}if(n){e.globalAlpha=.12;var c=e.createRadialGradient(0,t.h/2,10,0,t.h/2,t.w);c.addColorStop(0,"rgba(255, 220, 180, 1)"),c.addColorStop(1,"transparent"),e.fillStyle=c,e.fillRect(o-20,s-20,t.w+40,t.h+40)}e.globalAlpha=1,e.restore(),le(t.x,Y(O(t.lineIndex),t.x)-2)}}function j(){var t=performance.now()/1e3,a=t-z;if(e.clearRect(0,0,i,u),e.fillStyle="#0a0808",e.fillRect(0,0,i,u),re(),ne(),T){var n=T.x,r=T.y+T.h/2,h=e.createRadialGradient(n,r,20,n,r,250);h.addColorStop(0,"rgba(100, 35, 20, 0.15)"),h.addColorStop(1,"transparent"),e.fillStyle=h,e.fillRect(0,0,i,u)}oe();for(var o=0;o<d.length;o++)if(d[o].developStartTime>=0&&d[o].developProgress<1){var s=a-d[o].developStartTime-d[o].developDelay;s>0&&(d[o].developProgress=Math.min(1,s/te))}for(var f=0;f<d.length;f++)ie(d[f],a,d[f]===T);if(Math.random()<.3){e.fillStyle="rgba(255, 240, 220, 0.008)";for(var l=0;l<30;l++)e.fillRect(Math.random()*i,Math.random()*u,1,1)}requestAnimationFrame(j)}P.addEventListener("mousemove",function(t){D=t.clientX,W=t.clientY,T=$(D,W),P.style.cursor=T?"pointer":"default"}),P.addEventListener("mouseleave",function(){D=-1e3,W=-1e3,T=null,P.style.cursor="default"}),P.addEventListener("click",function(t){if(!k){var a=$(t.clientX,t.clientY);a&&a.thumbnailId&&he(a)}});function he(t){k=!0,x.dataset.od4ApiName="thumbnail.single",x.src=ViewLib.Thumbnail.buildThumbnailUrl(t.thumbnailId),A.classList.add("active")}function V(){k=!1,A.classList.remove("active"),x.src=""}A.addEventListener("click",V),document.getElementById("prevBtn").addEventListener("click",Z),document.getElementById("nextBtn").addEventListener("click",Q),document.getElementById("shuffleBtn").addEventListener("click",K),document.getElementById("developBtn").addEventListener("click",C),document.addEventListener("keydown",function(t){if(k&&t.key==="Escape"){V();return}if(!(t.target.tagName==="INPUT"||t.target.tagName==="TEXTAREA"))switch(t.key){case"ArrowLeft":t.preventDefault(),Z();break;case"ArrowRight":t.preventDefault(),Q();break;case"r":case"R":K();break;case"d":case"D":C();break;case"Escape":k&&V();break}}),requestAnimationFrame(j),N(0)})();