File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/static/views/slideshow.js
(function(){"use strict";var q=ViewLib.Filters,re=ViewLib.Messages,v=ViewLib.Thumbnail,L=0,g=document.getElementById("c"),o=g.getContext("2d"),h,f;function oe(){h=g.width=window.innerWidth,f=g.height=window.innerHeight}oe();var Ee=q.parseUrlFilterState(),le=q.buildApiQueryString(Ee),ae=(new URLSearchParams(window.location.search).get("peopleThumbnailIds")||"").split(",").map(function(e){return e.trim()}).filter(Boolean),Y=50,l=[],u=0,y=0,A=0,se=ae.slice(),ue=ae.length>0,de=!1,s=0,w=!0,F=!1,d=5,c=0,m=null,T=null,S=null,z=null,Q=0,p=!1,M=0,ce=1.5,P=0,me=0,W=0,I={},b={},G=document.createElement("canvas"),Te=G.getContext("2d"),J=document.createElement("canvas"),De=J.getContext("2d"),_=null,C=null,X=0,j=!1;function K(e,n){var t=A;return v.fetchThumbnailPage(e,n,le).then(function(i){if(t===A){u=i.total;for(var r=v.filterValidThumbnails(i.items),a=0;a<r.length;a++)l.push(r[a]);y=e+r.length}})}function Z(e){function n(){return e>=y&&y<u?K(y,Y).then(n):Promise.resolve()}return n()}function R(e){return new Promise(function(n){if(e<0||e>=l.length){n(null);return}var t=new Image;t.onload=function(){n(t)},t.onerror=function(){n(null)},t.dataset.od4ApiName="thumbnail.single",t.src=v.buildThumbnailUrl(l[e].thumbnailId)})}function U(e){if(e<0||e>=l.length)return Promise.resolve(null);if(I[e])return Promise.resolve(I[e]);if(b[e])return b[e];var n=new Promise(function(t){var i=new Image;i.onload=function(){I[e]=i,delete b[e],t(i)},i.onerror=function(){delete b[e],R(e).then(function(r){r&&(I[e]=r),t(r)})},i.dataset.od4ApiName="photo.content",i.src=v.buildPhotoUrl(l[e].thumbnailId)});return b[e]=n,n}function $(e,n){for(var t=1;t<=n;t++){var i=(e+t)%u;i<l.length&&function(r){Z(r).then(function(){U(r)})}(i)}}function fe(e,n,t){n.width=Math.round(h/4),n.height=Math.round(f/4);var i=n.width,r=n.height,a=window.OD4SlideshowKenBurns.coverFit(e,i/2,r/2,i+20,r+20,1.15,0,0);t.filter="blur(10px) saturate(1.2)",t.drawImage(e,a.x,a.y,a.w,a.h),t.filter="none"}function Oe(e,n){n===1?_!==e&&(fe(e,G,Te),_=e):C!==e&&(fe(e,J,De),C=e)}function x(e,n,t,i){if(e){i=i||1,Oe(e,i);var r=i===1?G:J;o.save(),o.globalAlpha=n*.6,o.drawImage(r,0,0,h,f),o.restore(),t||(o.save(),o.globalAlpha=.3,o.fillStyle="#000",o.fillRect(0,0,h,f),o.restore())}}function ee(e,n,t,i){if(!(!e||!n)){var r=window.OD4SlideshowKenBurns.lerpKB(n,t),a=window.OD4SlideshowKenBurns.coverFit(e,h/2,f/2,h,f,r.scale,r.dx,r.dy);o.save(),o.globalAlpha=i,o.drawImage(e,a.x,a.y,a.w,a.h),o.restore()}}var k=!1;function N(e,n){u===0||k||(L>0&&window.OD4SlideshowTelemetry.vpScenario("slideshowMomentView",Date.now()-L,void 0,{recommendationType:"moj",source:"memories",subScenario:"momentview",tileIndex:s}),L=Date.now(),k=!0,e<0&&(e=u-1),e>=u&&(e=0),Z(e+2).then(function(){if(e>=l.length){k=!1;return}T=m,z=S,Q=c;var t=Math.min(1,c/d),i=S?window.OD4SlideshowKenBurns.lerpKB(S,t):null;s=e;var r=I[e];r||(r=window.OD4SlideshowFilmStrip.getImage(e),r||R(e).then(function(E){E&&s===e&&!I[e]&&(m=E)}),U(e).then(function(E){E&&s===e&&(m=E)})),r&&(m=r),S=window.OD4SlideshowKenBurns.randomKB(i),c=0,p=!0,M=0,P=0,W=.8,window.OD4SlideshowStatusOverlay.updatePageInfo(s,u),$(e,2);for(var a=1;a<=3;a++){var V=(e+a)%u;V<l.length&&window.OD4SlideshowFilmStrip.loadThumb(V,l,v)}k=!1}).catch(function(){k=!1}))}function ne(){if(F&&l.length>1){var e;do e=Math.floor(Math.random()*l.length);while(e===s);N(e,1)}else N(s+1,1)}function he(){N(s-1,-1)}var te=0;function ve(e){var n=te?Math.min((e-te)/1e3,.1):.016;te=e,c+=n,p&&(Q+=n,M+=n,M>=ce&&(p=!1,T=null,z=null)),w&&!p&&c>=d&&ne(),W>0?W-=n:me=1,P+=(me-P)*Math.min(1,n*4),X+=n;var t=document.getElementById("controlsBar");X>3&&!j&&t.classList.remove("visible"),o.fillStyle="#000",o.fillRect(0,0,h,f);var i=Math.min(1,c/d),r=p?Math.min(1,M/ce):1,a=r*r*(3-2*r);if(p&&T){var V=Math.min(1,Q/d);x(T,1,!0,1),x(m,a,!0,2),o.save(),o.globalAlpha=.3,o.fillStyle="#000",o.fillRect(0,0,h,f),o.restore(),ee(T,z,V,1),ee(m,S,i,a)}else x(m,1,!1,1),ee(m,S,i,1);if(window.OD4SlideshowFilmStrip.draw(o,h,f,s,u,Z,l,v),window.OD4SlideshowStatusOverlay.drawInfo(o,f,s,l,window.OD4SlideshowFilmStrip.STRIP_Y_OFFSET,P*(p?Math.max(0,a*2-1):1)),w&&!p){var E=c/d,Pe=f-window.OD4SlideshowFilmStrip.STRIP_Y_OFFSET-10;o.save(),o.globalAlpha=.2,o.fillStyle="#7baeff",o.fillRect(24,Pe,(h-48)*E,2),o.restore()}requestAnimationFrame(ve)}var ie=document.getElementById("playBtn");document.getElementById("prevBtn").addEventListener("click",function(){window.OD4SlideshowTelemetry.vpAction("seekSlideshow","back",{direction:"back"}),c=0,he()}),document.getElementById("nextBtn").addEventListener("click",function(){window.OD4SlideshowTelemetry.vpAction("seekSlideshow","forward",{direction:"forward"}),c=0,ne()}),ie.addEventListener("click",function(){w=!w,ie.innerHTML=w?"❚❚":"▶",window.OD4SlideshowTelemetry.vpAction("playPauseSlideshow",w?"play":"pause")});function H(){document.getElementById("speedVal").textContent=d+"s"}document.getElementById("speedDown").addEventListener("click",function(){d=Math.max(3,d-1),H()}),document.getElementById("speedUp").addEventListener("click",function(){d=Math.min(8,d+1),H()});var we=document.getElementById("shuffleBtn");function pe(){F=!F,we.classList.toggle("on",F)}we.addEventListener("click",pe);var ge=document.getElementById("fullscreenBtn");function ye(){document.fullscreenElement?document.exitFullscreen():document.documentElement.requestFullscreen().catch(function(){})}ge.addEventListener("click",ye),document.addEventListener("fullscreenchange",function(){ge.classList.toggle("on",!!document.fullscreenElement)}),document.addEventListener("keydown",function(e){e.key===" "?(e.preventDefault(),w=!w,ie.innerHTML=w?"❚❚":"▶",window.OD4SlideshowTelemetry.vpAction("playPauseSlideshow",w?"play":"pause")):e.key==="ArrowLeft"?(e.preventDefault(),window.OD4SlideshowTelemetry.vpAction("seekSlideshow","back",{direction:"back"}),c=0,he()):e.key==="ArrowRight"?(e.preventDefault(),window.OD4SlideshowTelemetry.vpAction("seekSlideshow","forward",{direction:"forward"}),c=0,ne()):e.key==="ArrowUp"?(e.preventDefault(),d=Math.min(8,d+1),H()):e.key==="ArrowDown"?(e.preventDefault(),d=Math.max(3,d-1),H()):e.key==="s"||e.key==="S"?pe():(e.key==="f"||e.key==="F")&&ye(),Se()}),g.addEventListener("click",function(e){var n=g.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top,r=window.OD4SlideshowFilmStrip.getClickIndex(t,i,h,f,s,u);r>=0&&r!==s&&(window.OD4SlideshowTelemetry.vpAction("seekSlideshow","strip",{direction:"strip"}),c=0,N(r,r>s?1:-1))}),g.addEventListener("mousemove",function(){Se()}),g.addEventListener("mousedown",function(){j=!0}),g.addEventListener("mouseup",function(){j=!1});function Se(){X=0,document.getElementById("controlsBar").classList.add("visible")}window.addEventListener("resize",function(){oe(),_=null,C=null});function Ie(){var e=A;function n(){return y<u&&e===A?K(y,200).then(n):Promise.resolve()}return n()}function Be(){if(!ue)return Promise.resolve(null);var e={};return se.forEach(function(n){e[String(n)]=!0}),Promise.resolve(e)}function be(e){var n=Object.keys(e).map(Number);return fetch("/api/thumbnails?limit=999999"+le,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({thumbnailIds:n}),_od4ApiName:"thumbnail.batch"}).then(function(t){return t.json()}).then(function(t){l=v.filterValidThumbnails(t.items||[]),u=l.length,y=u})}function Ae(){if(de){A++,l=[],u=0,y=0;var e;for(e in I)delete I[e];for(e in b)delete b[e];window.OD4SlideshowFilmStrip.reset(),_=null,C=null,m=null,T=null,s=0,p=!1,c=0;var n=document.getElementById("loading");n.textContent="Loading...",n.classList.remove("hidden"),Be().then(function(t){return t?be(t):K(0,Y).then(function(){Ie()})}).then(function(){if(!l.length){document.getElementById("pageInfo").textContent="0 / 0",n.textContent="No photos match current filters.";return}return R(0).then(function(t){m=t,s=0,S=window.OD4SlideshowKenBurns.randomKB(),window.OD4SlideshowStatusOverlay.updatePageInfo(s,u);for(var i=0;i<Math.min(6,l.length);i++)window.OD4SlideshowFilmStrip.loadThumb(i,l,v);n.classList.add("hidden"),U(0).then(function(r){r&&s===0&&(m=r)}),$(0,2)})})}}var B=new Audio;B.loop=!0,B.volume=.5;var D=!1;function ke(e){var n=document.getElementById("musicIndicator"),t=document.getElementById("muteBtn"),i=document.getElementById("musicSep");n.style.display="",n.textContent="\u266B "+(e||"Playing"),n.title=e||"",t.style.display="",i.style.display="",t.innerHTML=D?"🔈":"🔊"}function Le(){document.getElementById("musicIndicator").style.display="none",document.getElementById("muteBtn").style.display="none",document.getElementById("musicSep").style.display="none"}document.getElementById("muteBtn").addEventListener("click",function(){D=!D,B.muted=D,document.getElementById("muteBtn").innerHTML=D?"🔈":"🔊",window.OD4SlideshowTelemetry.vpAction("toggleMuteSlideshow",D?"mute":"unmute")});function Fe(e){switch(e.action){case"slideshow_play_music":B.src=e.url,B.play().catch(function(){}),ke(e.title);break;case"slideshow_stop_music":B.pause(),B.src="",Le();break;case"slideshow_set_volume":B.volume=Math.max(0,Math.min(1,e.volume));break}}var O=q.parseInitialActions();re.setupSpotlightResponder(function(){return v.extractThumbnailIds(l)}),re.onFiltersChanged(function(e){se=e.peopleThumbnailIds||[],ue=e.peopleFilterActive||!1,Ae()});function Me(){Be().then(function(e){return e?be(e):K(0,Y).then(function(){Ie()})}).then(function(){if(de=!0,!l.length){document.getElementById("loading").textContent="No photos found.";return}return R(0).then(function(e){m=e,s=0,S=window.OD4SlideshowKenBurns.randomKB(),window.OD4SlideshowStatusOverlay.updatePageInfo(s,u);for(var n=0;n<Math.min(6,l.length);n++)window.OD4SlideshowFilmStrip.loadThumb(n,l,v);if(document.getElementById("loading").classList.add("hidden"),L=Date.now(),requestAnimationFrame(ve),U(0).then(function(i){i&&s===0&&(m=i)}),$(0,2),O&&O.length>0)for(var t=0;t<O.length;t++)O[t].action&&O[t].action.indexOf("slideshow_")===0&&Fe(O[t])})})}Me()})();