File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/static/views/tagcloud.js
(function(){var j=["#4fc3f7","#81c784","#ffb74d","#e57373","#ba68c8","#4dd0e1"],Z=14,he=72,me="-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",q=3e3,ye=new URLSearchParams(window.location.search),Se=ye.get("collection")||"",_=[],r=new Set,T=[],h=[],W=document.getElementById("cloud-container"),S=document.getElementById("cloud-world"),s=document.getElementById("cloud-panel"),b=document.getElementById("split-handle"),J=document.getElementById("status-text"),K=document.getElementById("clear-btn"),Q=document.getElementById("gallery-panel"),$=document.getElementById("active-tags"),B=document.getElementById("gallery-count"),pe=document.getElementById("gallery-scroll"),O=document.getElementById("gallery-grid"),X=document.getElementById("loading"),be=document.getElementById("measure-canvas"),ee=be.getContext("2d"),d=1,m=0,y=0,te=.3,ne=3;function F(){S.style.transform="translate("+m+"px, "+y+"px) scale("+d+")"}function L(){if(h.length){var e=W.getBoundingClientRect(),t=e.width,n=e.height;if(!(!t||!n)){for(var a=1/0,i=1/0,o=-1/0,c=-1/0,I=0;I<h.length;I++){var l=h[I],u=ie(l.tag,l.fontSize);l.x<a&&(a=l.x),l.y<i&&(i=l.y),l.x+u.w>o&&(o=l.x+u.w),l.y+u.h>c&&(c=l.y+u.h)}var x=o-a,M=c-i;if(!(x<=0||M<=0)){var g=40;d=Math.max(te,Math.min(ne,Math.min((t-g*2)/x,(n-g*2)/M))),m=t/2-(a+x/2)*d,y=n/2-(i+M/2)*d,F()}}}}s.addEventListener("wheel",function(e){e.preventDefault();var t=W.getBoundingClientRect(),n=e.clientX-t.left,a=e.clientY-t.top,i=(n-m)/d,o=(a-y)/d,c=e.deltaY<0?1.15:1/1.15;d=Math.max(te,Math.min(ne,d*c)),m=n-i*d,y=a-o*d,F()},{passive:!1});var N=!1,w=!1,ae=0,re=0,oe=0,le=0,R=!1;s.addEventListener("mousedown",function(e){e.button===0&&(N=!0,R=!1,ae=e.clientX,re=e.clientY,oe=m,le=y,s.classList.add("dragging"))}),window.addEventListener("mousemove",function(e){if(!(!N||w)){var t=e.clientX-ae,n=e.clientY-re;(Math.abs(t)>3||Math.abs(n)>3)&&(R=!0),m=oe+t,y=le+n,F()}}),window.addEventListener("mouseup",function(){N&&(N=!1,s.classList.remove("dragging"))}),b.addEventListener("mousedown",function(e){e.button===0&&(e.preventDefault(),w=!0,b.classList.add("active"),s.classList.add("no-transition"),document.body.style.cursor="row-resize",document.body.style.userSelect="none")}),window.addEventListener("mousemove",function(e){if(w){var t=document.body.clientHeight,n=Math.max(80,Math.min(t-120,e.clientY));s.style.flex="0 0 "+n+"px",L()}}),window.addEventListener("mouseup",function(){w&&(w=!1,b.classList.remove("active"),s.classList.remove("no-transition"),document.body.style.cursor="",document.body.style.userSelect="")});function ie(e,t){ee.font="600 "+t+"px "+me;var n=ee.measureText(e);return{w:Math.ceil(n.width)+6,h:Math.ceil(t*1.25)+4}}function Le(e,t,n){if(!e.length)return[];for(var a=e[0].count,i=e[e.length-1].count,o=Math.log(a+1),c=Math.log(i+1),I=o-c||1,l=[],u=[],x=t/2,M=n/2,g=0;g<e.length;g++){for(var A=e[g],Ce=(Math.log(A.count+1)-c)/I,ve=Math.round(Z+Ce*(he-Z)),Te=j[g%j.length],v=ie(A.tag,ve),Y=null,V=null,D=0;D<2e3;D++){var G=D*.3,fe=2*G,E=Math.round(x+fe*Math.cos(G)-v.w/2),C=Math.round(M+fe*Math.sin(G)-v.h/2);if(!(E<0||C<0||E+v.w>t||C+v.h>n)){for(var ge=!1,U=0;U<u.length;U++){var p=u[U];if(E<p.x+p.w&&E+v.w>p.x&&C<p.y+p.h&&C+v.h>p.y){ge=!0;break}}if(!ge){Y=E,V=C;break}}}Y!==null&&(u.push({x:Y,y:V,w:v.w,h:v.h}),l.push({tag:A.tag,count:A.count,x:Y,y:V,fontSize:ve,color:Te}))}return l}function we(){S.innerHTML="",h=Le(_,q,q);for(var e=0;e<h.length;e++)(function(t){var n=document.createElement("span");n.className="tag-span",n.textContent=t.tag,n.style.left=t.x+"px",n.style.top=t.y+"px",n.style.fontSize=t.fontSize+"px",n.style.fontWeight="600",n.style.color=t.color,n.title=t.tag+" ("+t.count+")",n.dataset.tag=t.tag,n.dataset.originalCount=t.count,n.addEventListener("click",function(){R||se(t.tag)}),S.appendChild(n)})(h[e]);L(),k()}var f=null;function k(){S.querySelectorAll(".tag-span").forEach(function(e){var t=e.dataset.tag,n=r.has(t);e.classList.remove("selected","dimmed","unavailable"),n?e.classList.add("selected"):r.size>0&&f?f[t]!=null&&f[t]>0?e.title=t+" ("+f[t]+")":e.classList.add("unavailable"):r.size>0?e.classList.add("dimmed"):e.title=t+" ("+e.dataset.originalCount+")"})}function se(e){r.has(e)?r.delete(e):r.add(e),r.size===0&&(f=null),z()}window.clearSelection=function(){r.clear(),f=null,z()};function Ie(){$.innerHTML="",r.forEach(function(e){var t=document.createElement("span");t.className="tag-pill",t.textContent=e;var n=document.createElement("button");n.className="remove-tag",n.textContent="\xD7",n.title='Remove "'+e+'"',n.addEventListener("click",function(){se(e)}),t.appendChild(n),$.appendChild(t)})}var de=0;function z(){k(),Ie(),r.size===0?(J.textContent=_.length+" tags from "+de+" photos",K.style.display="none",Q.classList.remove("visible"),b.classList.remove("visible"),s.style.flex="",s.classList.add("expanded"),setTimeout(L,320)):(J.textContent=r.size+" tag"+(r.size>1?"s":"")+" selected",K.style.display="inline-block",s.classList.remove("expanded"),b.classList.add("visible"),setTimeout(L,320),xe())}var P=null,H=Object.create(null);function xe(){P&&P.abort(),P=new AbortController;var e=Array.from(r);B.textContent="Loading\u2026",O.innerHTML="",H={},Q.classList.add("visible"),fetch("/api/tags/photos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tags:e,limit:2e6}),signal:P.signal,_od4ApiName:"tags.photos"}).then(function(t){return t.json()}).then(function(t){if(t.error){B.textContent="Error: "+t.error;return}if(T=t.thumbnailIds||[],t.photos)for(var n=0;n<t.photos.length;n++){var a=t.photos[n];H[a.tid]={driveItemId:a.driveItemId,driveId:a.driveId}}B.textContent=t.count+" photo"+(t.count!==1?"s":"")+" matching: "+e.join(" + "),Me(T),t.available_tags&&(f=t.available_tags,k())}).catch(function(t){t.name!=="AbortError"&&(B.textContent="Error loading photos")})}function Me(e){O.innerHTML="";for(var t=0;t<e.length;t++)(function(n){var a=document.createElement("div");a.className="gallery-thumb";var i=ViewLib.Thumbnail.createLazyImage(n,{onLoad:function(o){o.classList.add("loaded")}});i.alt="",i.dataset.id=n,a.appendChild(i),a.addEventListener("click",function(){var o=H[n]||{};ViewLib.Messages.sendToShell({type:"photo-selected",photo:{id:n,thumbnailId:Od4Shared.NumericUtils.toPositiveInt(n),driveItemId:o.driveItemId||null,driveId:o.driveId||null,isFavorite:o.isFavorite||0}})}),O.appendChild(a)})(e[t]);ce=ViewLib.Thumbnail.observeLazyImages(O,{scrollRoot:pe,previousObserver:ce})}var ce=null;ViewLib.Messages.onGetVisiblePhotosRequest(function(){ViewLib.Messages.sendVisiblePhotosToShell(T.length?T:[])});var ue;window.addEventListener("resize",function(){clearTimeout(ue),ue=setTimeout(L,200)});function Ee(){fetch("/api/tags",{_od4ApiName:"tags.list"}).then(function(e){return e.json()}).then(function(e){if(e.error){X.textContent="Error: "+e.error;return}_=e.tags||[],de=e.total_tagged_photos||0,X.classList.add("hidden"),we(),z()}).catch(function(){X.textContent="Failed to load tags"})}Ee()})();