Files
LuPhoto/internal/site/static/app.js
T
2026-11-04 04:22:20 -08:00

2 lines
25 KiB
JavaScript

"use strict";(()=>{function _(){let t=navigator.deviceMemory,e=typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches,i=Math.min(screen.width,screen.height)<=820;return t!==void 0&&t<=4||e&&i?120*1048576:250*1048576}var L=class{constructor(t){this.budget=t;this.entries=new Map;this.used=0}get(t){let e=this.entries.get(t);return e&&(this.entries.delete(t),this.entries.set(t,e)),e}has(t){return this.entries.has(t)}put(t,e){let i=this.entries.get(t);if(i){i.bitmap!==e&&e.close();return}let n=e.width*e.height*4;this.entries.set(t,{bitmap:e,bytes:n,at:performance.now()}),this.used+=n,this.evict()}evict(){for(;this.used>this.budget&&this.entries.size>1;){let t=this.entries.keys().next();if(t.done)return;let e=this.entries.get(t.value);this.entries.delete(t.value),e&&(this.used-=e.bytes,e.bitmap.close())}}};var P=class extends Error{constructor(){super("aborted"),this.name="AbortError"}},R=class{constructor(t,e){this.concurrency=t;this.byId=new Map;this.byKey=new Map;this.queue=[];this.workers=[];this.running=0;this.nextKey=1;this.nextSeq=1;this.nextWorker=0;if(typeof Worker>"u"||e==="")return;let i=(navigator.hardwareConcurrency??2)>=4?2:1;for(let n=0;n<i;n++)try{let s=new Worker(e),o=this.workers.length;s.onmessage=h=>this.onReply(h.data),s.onerror=()=>this.dropWorker(o),this.workers.push(s)}catch{break}}request(t,e,i,n){return n.aborted?Promise.reject(new P):new Promise((s,o)=>{let h=this.byId.get(t);h?i<h.priority&&(h.priority=i):(h={key:this.nextKey++,id:t,url:e,priority:i,seq:this.nextSeq++,waiters:new Set,running:!1,worker:-1,controller:null},this.byId.set(t,h),this.byKey.set(h.key,h),this.queue.push(h));let c={resolve:s,reject:o};h.waiters.add(c);let a=h;n.addEventListener("abort",()=>{a.waiters.delete(c)&&(o(new P),a.waiters.size===0&&setTimeout(()=>{a.waiters.size===0&&this.byKey.get(a.key)===a&&this.cancel(a)},0))},{once:!0}),this.pump()})}cancel(t){if(this.forget(t),!t.running){let e=this.queue.indexOf(t);e>=0&&this.queue.splice(e,1);return}t.running=!1,this.running--,t.controller?t.controller.abort():t.worker>=0&&this.workers[t.worker]&&this.workers[t.worker].postMessage({type:"abort",key:t.key}),this.pump()}forget(t){this.byId.get(t.id)===t&&this.byId.delete(t.id),this.byKey.delete(t.key)}pump(){for(;this.running<this.concurrency&&this.queue.length>0;){let t=0;for(let i=1;i<this.queue.length;i++){let n=this.queue[i],s=this.queue[t];(n.priority<s.priority||n.priority===s.priority&&n.seq<s.seq)&&(t=i)}let e=this.queue.splice(t,1)[0];e.running=!0,this.running++,this.start(e)}}start(t){let e=this.liveWorkers();if(e.length>0){let i=e[this.nextWorker++%e.length];t.worker=i,this.workers[i].postMessage({type:"fetch",key:t.key,url:t.url});return}t.worker=-1,t.controller=new AbortController,this.fetchOnMainThread(t,t.controller.signal)}liveWorkers(){let t=[];return this.workers.forEach((e,i)=>{e&&t.push(i)}),t}dropWorker(t){let e=this.workers[t];if(e){e.terminate(),delete this.workers[t];for(let i of this.byKey.values())i.running&&i.worker===t&&(i.worker=-1,i.controller=new AbortController,this.fetchOnMainThread(i,i.controller.signal))}}async fetchOnMainThread(t,e){let i=performance.now();try{let n=await fetch(t.url,{signal:e,credentials:"same-origin"});if(!n.ok)throw new Error("HTTP "+n.status);let s=await n.blob(),o=performance.now()-i,h=await createImageBitmap(s);this.onReply({key:t.key,ok:!0,bitmap:h,bytes:s.size,ms:o})}catch(n){this.onReply({key:t.key,ok:!1,bytes:0,ms:0,error:String(n)})}}onReply(t){let e=this.byKey.get(t.key);if(!e||!e.running){t.bitmap?.close();return}e.running=!1,this.running--,this.forget(e);let i=[...e.waiters];if(e.waiters.clear(),t.ok&&t.bitmap){let n={bitmap:t.bitmap,bytes:t.bytes,ms:t.ms};for(let s of i)s.resolve(n);i.length===0&&t.bitmap.close()}else{let n=new Error(t.error??"tile failed");for(let s of i)s.reject(n)}this.pump()}};function X(r){let t=r.dataset,e=(i,n)=>{let s=Number(i);return Number.isFinite(s)&&s>0?s:n};return{page:t.page??"",build:t.build??"",slug:t.album??"",manifestUrl:t.manifest??"",indexUrl:t.index??"",workerUrl:t.worker??"",budgetMs:e(t.budgetMs,3e3),maxDpr:e(t.maxDpr,2),concurrency:Math.max(1,Math.round(e(t.concurrency,6))),blockContextMenu:t.blockContextMenu!=="false"}}function Y(r){return r<10?"0"+r:String(r)}function it(r){let t=(r.model??"").trim(),e=(r.make??"").trim(),i=e.split(/\s+/)[0]??"";i&&t.toLowerCase().startsWith(i.toLowerCase()+" ")&&(t=t.slice(i.length+1).trim());let n=/^([A-Za-z]{1,3}) (\d+[A-Za-z0-9]*)$/.exec(t);return n&&(t=n[1]+n[2]),t||e}function nt(r){let t=/(\d+(?:\.\d+)?(?:-\d+(?:\.\d+)?)?)\s*mm\s*(?:F|f\/?)\s*([\d.]+(?:-[\d.]+)?)/.exec(r);return t?t[1]+" f/"+t[2]:r.trim()}function K(r){return String(Math.round(r*10)/10)}function st(r,t,e,i){let n=[Y(r+1)+" / "+Y(t)],s=e.exif;if(i&&s){let o=it(s);o&&n.push(o),s.lens&&n.push(nt(s.lens)),s.focal_length&&n.push(K(s.focal_length)+"mm"),s.f_number&&n.push("f/"+K(s.f_number)),s.exposure&&n.push(s.exposure.includes("/")?s.exposure:s.exposure+"s"),s.iso&&n.push("ISO "+s.iso)}return n.join(" \xB7 ")}function rt(r,t){r.textContent="",t.split(/\r?\n/).forEach((e,i)=>{i>0&&r.appendChild(document.createElement("br"));let n=e.split("*"),s=(n.length-1)%2===0;n.forEach((o,h)=>{let c=h%2===1;if(c&&(s||h!==n.length-1)){let a=document.createElement("em");a.textContent=o,r.appendChild(a)}else r.appendChild(document.createTextNode((c?"*":"")+o))})})}var S=class{constructor(t){this.visible=!1;this.placement="";this.element=document.createElement("section"),this.element.className="caption",this.element.setAttribute("aria-live","polite"),this.meta=document.createElement("p"),this.meta.className="caption-meta",this.title=document.createElement("h2"),this.title.className="caption-title",this.text=document.createElement("p"),this.text.className="caption-text",this.alt=document.createElement("p"),this.alt.className="visually-hidden",this.element.append(this.meta,this.title,this.text,this.alt),t.appendChild(this.element)}set(t,e,i,n){this.meta.textContent=st(e,i,t,n),this.title.textContent=t.title??"",this.title.hidden=!t.title,rt(this.text,t.caption??""),this.text.hidden=!t.caption,this.alt.textContent=t.alt??""}show(t){t!==this.visible&&(this.visible=t,this.element.classList.toggle("is-visible",t))}place(t,e,i){let n=Math.round(t)+","+Math.round(e)+","+Math.round(i);if(n===this.placement)return;this.placement=n;let s=this.element.style;s.width=Math.round(e)+"px",s.transform="translate3d("+Math.round(t)+"px,"+-Math.round(i)+"px,0)"}};function I(r,t,e){let i=t*e;for(let n=0;n<r.levels.length;n++)if(r.levels[n].width>=i)return n;return r.levels.length-1}function A(r,t,e){let i=Math.max(0,t.u0*r.width),n=Math.min(r.width,t.u1*r.width),s=Math.max(0,t.v0*r.height),o=Math.min(r.height,t.v1*r.height);return n<=i||o<=s?null:{x0:Math.min(r.cols-1,Math.floor(i/e)),x1:Math.min(r.cols-1,Math.ceil(n/e)-1),y0:Math.min(r.rows-1,Math.floor(s/e)),y1:Math.min(r.rows-1,Math.ceil(o/e)-1)}}function V(r,t,e,i){let n=r.levels[t],s=A(n,e,i);if(!s)return[];let o=(e.u0+e.u1)/2*n.width,h=(e.v0+e.v1)/2*n.height,c=[];for(let a=s.y0;a<=s.y1;a++)for(let u=s.x0;u<=s.x1;u++){let m=(u*i+Math.min((u+1)*i,n.width))/2,d=(a*i+Math.min((a+1)*i,n.height))/2;c.push({level:t,x:u,y:a,index:a*n.cols+u,distance:(m-o)**2+(d-h)**2})}return c.sort((a,u)=>a.distance-u.distance),c.map(({level:a,x:u,y:m,index:d})=>({level:a,x:u,y:m,index:d}))}function O(r,t,e,i,n,s,o,h,c,a){let u=i*s,m=Math.min((i+1)*s,e.width),d=n*s,l=Math.min((n+1)*s,e.height),p=i>0?u-o:0,g=n>0?d-o:0,y=Math.round(h+u*a),f=Math.round(h+m*a),b=Math.round(c+d*a),M=Math.round(c+l*a);if(f<=y||M<=b)return;let C=Math.max(p,(y-h)/a),w=Math.min(p+t.width,(f-h)/a),v=Math.max(g,(b-c)/a),x=Math.min(g+t.height,(M-c)/a);w<=C||x<=v||r.drawImage(t,C-p,v-g,w-C,x-v,y,b,f-y,M-b)}var F="luphoto.throughput";function z(){try{let r=Number(sessionStorage.getItem(F));return Number.isFinite(r)&&r>0?r:null}catch{return null}}function J(){return z()??1e3}function Z(r){let t=z(),e=t===null?r:t*(1-.5)+r*.5;try{sessionStorage.setItem(F,String(e))}catch{return e}return e}var U=180,G=3,q=4,D=class{constructor(t,e){this.pyramid=t;this.env=e;this.seedImage=null;this.seedPromise=null;this.session=null;this.prefetchController=null;this.finalLevel=-1}tileUrl(t){let e=this.env.tiles;return e.path+this.pyramid.hash+"/"+t+"."+e.format}ensureSeed(){return this.seedPromise||(this.seedPromise=this.decodeSeed().then(()=>this.env.requestDraw(),()=>{})),this.seedPromise}async decodeSeed(){if(!this.pyramid.seed)return;let t=atob(this.pyramid.seed),e=new Uint8Array(t.length);for(let h=0;h<t.length;h++)e[h]=t.charCodeAt(h);let i=await createImageBitmap(new Blob([e],{type:"image/"+this.env.tiles.format})),n=document.createElement("canvas");n.width=i.width*q,n.height=i.height*q;let s=n.getContext("2d");if(!s){this.seedImage=i;return}s.imageSmoothingEnabled=!0,s.imageSmoothingQuality="high","filter"in s&&(s.filter="blur("+q*.75+"px)");let o=q*2;s.drawImage(i,-o,-o,n.width+o*2,n.height+o*2),i.close(),this.seedImage=n}fetchTile(t,e,i){let n=this.pyramid.levels[t.level].tiles[t.index];return this.env.scheduler.request(n,this.tileUrl(n),e,i).then(s=>(this.env.cache.put(n,s.bitmap),this.env.requestDraw(),s))}uncached(t,e){let i=this.pyramid.levels[t].tiles;return V(this.pyramid,t,e,this.env.tiles.tile_size).filter(n=>!this.env.cache.has(i[n.index]))}uncachedBytes(t,e){let i=this.pyramid.levels[t].bytes,n=0;for(let s of this.uncached(t,e))n+=i[s.index];return n}fetchAll(t,e,i){return Promise.allSettled(t.map(n=>this.fetchTile(n,e,i)))}probeLevel(t,e){return Math.max(0,I(this.pyramid,t.displayWidth,e)-G)}start(t,e,i){this.stopSession();let n=new AbortController;this.session=n,this.run(t,e,n).then(()=>{this.session===n&&(this.session=null),(!n.signal.aborted||n.signal.reason==="deadline")&&i()})}async run(t,e,i){let n=i.signal,s=performance.now(),o=this.env.settings.budgetMs,h=setTimeout(()=>i.abort("deadline"),o);try{if(await this.ensureSeed(),n.aborted)return;let c=I(this.pyramid,t.displayWidth,e),a=Math.max(0,c-G),u=this.uncached(a,t).slice(0,2);if(u.length>0){let g=await this.fetchAll(u,0,n),y=0,f=0;for(let b of g)b.status==="fulfilled"&&(y+=b.value.bytes,f=Math.max(f,b.value.ms));y>0&&f>0&&Z(y/f)}if(n.aborted)return;this.finalLevel=Math.max(this.finalLevel,a);let m=J(),d=o-(performance.now()-s),l=a;for(let g=c;g>a;g--)if(this.uncachedBytes(g,t)/m<=d*.8){l=g;break}let p=[];l-a>=2&&p.push(Math.floor((a+l)/2)),l>a&&p.push(l),this.finalLevel=l;for(let g of p)if(await this.fetchAll(this.uncached(g,t),0,n),n.aborted)return}finally{clearTimeout(h)}}prefetchProbe(t,e){let i=this.resetPrefetch();this.ensureSeed().then(()=>{i.signal.aborted||this.fetchAll(this.uncached(this.probeLevel(t,e),t),1,i.signal)})}prefetchLevel(t,e){if(e<0)return;let i=this.resetPrefetch();this.fetchAll(this.uncached(e,t),1,i.signal)}resetPrefetch(){return this.prefetchController?.abort(),this.prefetchController=new AbortController,this.prefetchController}stopPrefetch(){this.prefetchController?.abort(),this.prefetchController=null}stopSession(){this.session?.abort("superseded"),this.session=null}stop(){this.stopSession(),this.stopPrefetch()}draw(t){let{g:e,originX:i,originY:n,width:s,height:o,canvasWidth:h,canvasHeight:c}=t,a=Math.max(0,i),u=Math.max(0,n),m=Math.min(h,i+s),d=Math.min(c,n+o);if(m<=a||d<=u)return!1;this.seedPromise||this.ensureSeed();let l={displayWidth:t.displayWidth,u0:(a-i)/s,u1:(m-i)/s,v0:(u-n)/o,v1:(d-n)/o},p=this.env.tiles.tile_size,g=this.env.tiles.overlap,y=this.env.cache,f=this.pyramid.levels,b=I(this.pyramid,t.displayWidth,t.dpr),M=-1;for(let w=b;w>=0&&M<0;w--){let v=A(f[w],l,p);if(!v)continue;let x=!0;for(let k=v.y0;k<=v.y1&&x;k++)for(let T=v.x0;T<=v.x1;T++){let E=y.get(f[w].tiles[k*f[w].cols+T]);if(!E||t.now-E.at<U){x=!1;break}}x&&(M=w)}M<0&&this.seedImage&&(e.save(),e.beginPath(),e.rect(a,u,m-a,d-u),e.clip(),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality="low",e.drawImage(this.seedImage,i,n,s,o),e.restore());let C=!1;for(let w=Math.max(0,M);w<=b;w++){let v=f[w],x=A(v,l,p);if(!x)continue;let k=s/v.width;e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=k<1?"high":"medium";for(let T=x.y0;T<=x.y1;T++)for(let E=x.x0;E<=x.x1;E++){let H=y.get(v.tiles[T*v.cols+E]);if(!H)continue;let B=t.now-H.at;B<U&&(e.globalAlpha=Math.max(0,B/U),C=!0),O(e,H.bitmap,v,E,T,p,g,i,n,k),e.globalAlpha=1}}return C}};var N=24,j=10,ot=300,at=.35,tt=.35,ht=.2;function lt(r,t,e,i){let n=3*r,s=3*(e-r)-n,o=1-n-s,h=3*t,c=3*(i-t)-h,a=1-h-c,u=l=>((o*l+s)*l+n)*l,m=l=>((a*l+c)*l+h)*l,d=l=>(3*o*l+2*s)*l+n;return l=>{if(l<=0)return 0;if(l>=1)return 1;let p=l;for(let f=0;f<8;f++){let b=u(p)-l,M=d(p);if(Math.abs(b)<1e-5)return m(p);if(Math.abs(M)<1e-6)break;p-=b/M}let g=0,y=1;p=l;for(let f=0;f<24;f++){let b=u(p);if(Math.abs(b-l)<1e-5)break;b<l?g=p:y=p,p=(g+y)/2}return m(p)}}var ct=lt(.16,1,.3,1),W=class{constructor(t,e,i,n){this.stage=t;this.manifest=e;this.settings=i;this.env=n;this.layouts=[];this.stops=[];this.endLeft=0;this.vw=0;this.vh=0;this.dpr=1;this.camera=0;this.current=0;this.tween=null;this.frame=0;this.pointerId=null;this.pointerType="";this.dragging=!1;this.downX=0;this.downY=0;this.downT=0;this.downCamera=0;this.samples=[];this.hover=!1;this.pinned=!1;this.resizeTimer=0;this.indexRequested=!1;this.canvas=document.createElement("canvas"),this.canvas.className="stage-canvas",this.canvas.setAttribute("aria-hidden","true"),this.fade=document.createElement("canvas"),this.fade.className="stage-fade",this.fade.setAttribute("aria-hidden","true"),this.fade.width=1,this.fade.height=1;let s=this.canvas.getContext("2d",{alpha:!1});if(!s)throw new Error("canvas 2d unavailable");this.g=s,this.endCard=this.buildEndCard(),this.nextLink=this.endCard.querySelector("a.next-album"),t.prepend(this.canvas,this.fade),t.appendChild(this.endCard),this.caption=new S(t),this.loaders=new Array(e.photos.length),this.reducedMotion=matchMedia("(prefers-reduced-motion: reduce)"),this.measure(),this.current=this.stopForHash(),this.camera=this.stops[this.current].camera,this.bind(),this.activate(-1),this.requestDraw()}buildEndCard(){let t=document.createElement("section");t.className="end-card",t.setAttribute("aria-label","End of album");let e=document.createElement("div");e.className="chop",e.setAttribute("aria-hidden","true"),e.textContent="\u9648";let i=document.createElement("p");i.className="signature",i.textContent="\u2014 Lucio";let n=document.createElement("a");n.className="next-album",n.href="/";let s=document.createElement("span");s.className="next-eyebrow",s.textContent="All albums";let o=document.createElement("span");return o.className="next-title",n.append(s,o),t.append(e,i,n),t}loader(t){let e=this.loaders[t];return e||(e=new D(this.manifest.photos[t],{...this.env,requestDraw:()=>this.requestDraw()}),this.loaders[t]=e),e}measure(){let t=this.stage.getBoundingClientRect();this.vw=Math.max(1,t.width),this.vh=Math.max(1,t.height),this.dpr=Math.min(window.devicePixelRatio||1,this.settings.maxDpr);let e=Math.max(1,Math.round(this.vw*this.dpr)),i=Math.max(1,Math.round(this.vh*this.dpr));(this.canvas.width!==e||this.canvas.height!==i)&&(this.canvas.width=e,this.canvas.height=i),this.layouts=[],this.stops=[];let n=0;this.manifest.photos.forEach((s,o)=>{let h=Math.max(1,s.slides||1),c=Math.min(this.vw/(s.width/h),this.vh/s.height),a=s.width*c,u=s.height*c,m=a/h,d=n+N/2+(this.vw-m)/2;this.layouts.push({scale:c,width:a,height:u,section:m,slides:h,start:n,left:d,top:(this.vh-u)/2});for(let l=0;l<h;l++)this.stops.push({photo:o,slide:l,camera:n+N/2+this.vw/2+l*m});n+=this.vw+(h-1)*m+N}),this.endLeft=n+N/2,this.stops.push({photo:-1,slide:0,camera:this.endLeft+this.vw/2}),this.endCard.style.width=this.vw+"px"}stopForHash(){let t=/^#(\d+)$/.exec(location.hash);if(!t)return 0;let e=Math.min(this.manifest.photos.length,Math.max(1,Number(t[1])))-1,i=this.stops.findIndex(n=>n.photo===e);return i<0?0:i}bind(){let t=this.stage;t.addEventListener("pointerdown",e=>this.onPointerDown(e)),t.addEventListener("pointermove",e=>this.onPointerMove(e)),t.addEventListener("pointerup",e=>this.onPointerUp(e,!1)),t.addEventListener("pointercancel",e=>this.onPointerUp(e,!0)),t.addEventListener("pointerleave",e=>{e.pointerType==="mouse"&&this.pointerId===null&&(this.hover=!1,this.updateCaption())}),t.addEventListener("dragstart",e=>e.preventDefault()),t.addEventListener("selectstart",e=>e.preventDefault()),this.settings.blockContextMenu&&t.addEventListener("contextmenu",e=>e.preventDefault()),window.addEventListener("keydown",e=>this.onKey(e)),window.addEventListener("hashchange",()=>{let e=this.stopForHash();this.stops[e].photo!==this.stops[this.current].photo&&this.jump(e)}),new ResizeObserver(()=>this.onResize()).observe(t),this.fade.addEventListener("transitionend",()=>{this.fade.style.opacity==="0"&&(this.fade.width=1,this.fade.height=1)})}onResize(){let t=this.vw+"x"+this.vh+"@"+this.dpr;this.measure(),t!==this.vw+"x"+this.vh+"@"+this.dpr&&(this.tween=null,this.camera=this.stops[this.current].camera,this.requestDraw(),clearTimeout(this.resizeTimer),this.resizeTimer=window.setTimeout(()=>this.startSession(),200))}onKey(t){if(t.altKey||t.ctrlKey||t.metaKey)return;let e=t.target;if(!(e&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)))){switch(t.key){case"ArrowRight":this.go(this.current+1);break;case"ArrowLeft":this.go(this.current-1);break;case"Home":this.go(0);break;case"End":this.go(this.stops.length-2);break;case"Escape":location.assign("/");break;case"i":case"I":this.pinned=!this.pinned,this.updateCaption();break;default:return}t.preventDefault()}}onPointerDown(t){this.pointerId!==null||t.pointerType==="mouse"&&t.button!==0||t.target.closest("a, button")||(this.pointerId=t.pointerId,this.pointerType=t.pointerType,this.dragging=!1,this.downX=t.clientX,this.downY=t.clientY,this.downT=t.timeStamp,this.tween=null,this.downCamera=this.camera,this.samples=[{t:t.timeStamp,x:t.clientX}],this.stage.setPointerCapture(t.pointerId))}onPointerMove(t){if(this.pointerId===null){t.pointerType==="mouse"&&(this.hover=this.inCaptionZone(t.clientX,t.clientY),this.updateCaption());return}if(t.pointerId!==this.pointerId)return;let e=t.clientX-this.downX,i=t.clientY-this.downY;if(!this.dragging&&Math.hypot(e,i)>=j&&(this.dragging=!0,this.stage.classList.add("is-dragging"),this.updateCaption()),!!this.dragging){for(this.samples.push({t:t.timeStamp,x:t.clientX});this.samples.length>2&&t.timeStamp-this.samples[0].t>100;)this.samples.shift();this.camera=this.rubber(this.downCamera-e),this.requestDraw()}}onPointerUp(t,e){if(t.pointerId!==this.pointerId)return;this.stage.hasPointerCapture(t.pointerId)&&this.stage.releasePointerCapture(t.pointerId),this.pointerId=null;let i=this.dragging;this.dragging=!1,this.stage.classList.remove("is-dragging");let n=Math.hypot(t.clientX-this.downX,t.clientY-this.downY);if(!e&&!i&&n<j&&t.timeStamp-this.downT<ot){this.onTap(t);return}if(!i)return;let s=0,o=this.samples[0],h=this.samples[this.samples.length-1];o&&h&&h.t>o.t&&t.timeStamp-h.t<100&&(s=(h.x-o.x)/(h.t-o.t));let c=this.nearestStop(this.camera);if(!e&&Math.abs(s)>at)if(s<0){let a=this.stops.findIndex(u=>u.camera>this.camera+1);c=a<0?this.stops.length-1:a}else{let a=0;this.stops.forEach((u,m)=>{u.camera<this.camera-1&&(a=m)}),c=a}this.pointerType==="mouse"&&(this.hover=this.inCaptionZone(t.clientX,t.clientY)),this.go(c)}onTap(t){let e=this.stops[this.current];if(e.photo<0)return;let i=this.photoRect(e.photo);t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom&&(this.pinned=!this.pinned,this.updateCaption())}rubber(t){let e=this.stops[0].camera,i=this.stops[this.stops.length-1].camera;return t<e?e-(e-t)*tt:t>i?i+(t-i)*tt:t}nearestStop(t){let e=0;return this.stops.forEach((i,n)=>{Math.abs(i.camera-t)<Math.abs(this.stops[e].camera-t)&&(e=n)}),e}go(t){let e=Math.max(0,Math.min(this.stops.length-1,t)),i=this.current,n=this.stops[e].camera;if(this.reducedMotion.matches)this.crossfade(()=>{this.current=e,this.camera=n});else{let s=Math.abs(n-this.camera);s>.5?this.tween={from:this.camera,to:n,start:performance.now(),duration:240+200*Math.min(1,s/this.vw)}:this.camera=n,this.current=e}e!==i?this.activate(i):this.updateCaption(),this.requestDraw()}jump(t){let e=this.current;this.tween=null,this.crossfade(()=>{this.current=t,this.camera=this.stops[t].camera}),this.activate(e),this.requestDraw()}crossfade(t){let e=this.fade;(e.width!==this.canvas.width||e.height!==this.canvas.height)&&(e.width=this.canvas.width,e.height=this.canvas.height);let i=e.getContext("2d");i&&i.drawImage(this.canvas,0,0),e.style.transition="none",e.style.opacity="1",t(),this.render(performance.now()),requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.style.transition="",e.style.opacity="0"})})}activate(t){let e=this.stops[this.current],i=t>=0?this.stops[t]:null;if(i&&i.photo>=0&&i.photo!==e.photo&&this.loaders[i.photo]?.stop(),this.loaders.forEach((n,s)=>{n&&s!==e.photo&&s!==e.photo+1&&n.stopPrefetch()}),e.photo>=0){let n=this.manifest.photos[e.photo];this.caption.set(n,e.photo,this.manifest.photos.length,this.manifest.show_exif),(t>=0||location.hash!=="")&&location.hash!=="#"+(e.photo+1)&&history.replaceState(history.state,"","#"+(e.photo+1)),this.startSession()}(e.photo<0||e.photo===this.manifest.photos.length-1)&&this.loadNextAlbum(),this.updateCaption()}startSession(){let t=this.stops[this.current];if(t.photo<0)return;let e=this.current;this.loader(t.photo).start(this.viewAt(t),this.dpr,()=>{this.current===e&&this.prefetchAround(e)})}prefetchAround(t){let e=this.stops[t],i=this.stops[t+1];if(!(!i||i.photo<0)){if(i.photo===e.photo){let n=this.loader(e.photo);n.prefetchLevel(this.viewAt(i),n.finalLevel);let s=this.stops.find(o=>o.photo===e.photo+1);s&&this.loader(s.photo).prefetchProbe(this.viewAt(s),this.dpr);return}this.loader(i.photo).prefetchProbe(this.viewAt(i),this.dpr)}}viewAt(t){let e=this.layouts[t.photo],i=t.camera-this.vw/2,n=Math.max(i,e.left),s=Math.min(i+this.vw,e.left+e.width),o=Math.max(0,e.top),h=Math.min(this.vh,e.top+e.height);return{displayWidth:e.width,u0:(n-e.left)/e.width,u1:(s-e.left)/e.width,v0:(o-e.top)/e.height,v1:(h-e.top)/e.height}}photoRect(t){let e=this.layouts[t],i=e.left-(this.camera-this.vw/2);return{left:Math.max(0,i),right:Math.min(this.vw,i+e.width),top:Math.max(0,e.top),bottom:Math.min(this.vh,e.top+e.height)}}inCaptionZone(t,e){let i=this.stops[this.current];if(i.photo<0)return!1;let n=this.stage.getBoundingClientRect(),s=t-n.left,o=e-n.top,h=this.layouts[i.photo],c=this.photoRect(i.photo),a=h.top+h.height*(1-ht);return s>=c.left&&s<=c.right&&o>=a&&o<=c.bottom}updateCaption(){let t=this.stops[this.current],e=t.photo>=0&&!this.dragging&&(this.pinned||this.hover);if(e){let i=this.photoRect(t.photo);this.caption.place(i.left,i.right-i.left,this.vh-i.bottom)}this.caption.show(e)}loadNextAlbum(){this.indexRequested||!this.settings.indexUrl||(this.indexRequested=!0,fetch(this.settings.indexUrl,{credentials:"same-origin"}).then(t=>t.ok?t.json():Promise.reject(new Error("index"))).then(t=>{let e=t.albums;if(e.length===0)return;let i=e.findIndex(h=>h.slug===this.manifest.slug),n=e[(i+1)%e.length];if(!n||n.slug===this.manifest.slug)return;this.nextLink.href="/a/"+encodeURIComponent(n.slug)+"/";let s=this.nextLink.querySelector(".next-eyebrow"),o=this.nextLink.querySelector(".next-title");s&&(s.textContent="Next album"+(n.date?" \xB7 "+n.date:"")),o&&(o.textContent=n.title)}).catch(()=>{this.indexRequested=!1}))}requestDraw(){this.frame===0&&(this.frame=requestAnimationFrame(t=>{this.frame=0,this.render(t)}))}render(t){let e=!1;if(this.tween){let d=Math.min(1,(t-this.tween.start)/this.tween.duration);this.camera=this.tween.from+(this.tween.to-this.tween.from)*ct(d),d>=1?(this.tween=null,this.updateCaption()):e=!0}let i=this.g,n=this.canvas.width,s=this.canvas.height;i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.fillStyle="#111114",i.fillRect(0,0,n,s);let o=this.camera-this.vw/2,h=o+this.vw,c=this.dpr,a=this.stops[this.current].photo,u=Math.max(0,(a<0?this.layouts.length-1:a)-2),m=Math.min(this.layouts.length-1,(a<0?this.layouts.length-1:a)+2);for(let d=u;d<=m;d++){let l=this.layouts[d];l.left+l.width<o||l.left>h||this.loader(d).draw({g:i,originX:(l.left-o)*c,originY:l.top*c,width:l.width*c,height:l.height*c,canvasWidth:n,canvasHeight:s,displayWidth:l.width,dpr:c,now:t})&&(e=!0)}this.endCard.style.transform="translate3d("+Math.round(this.endLeft-o)+"px,0,0)",this.caption.element.classList.contains("is-visible")&&this.tween&&this.updateCaption(),e&&this.requestDraw()}};async function ut(r){let t=X(document.body),e=await fetch(t.manifestUrl,{credentials:"same-origin"});if(!e.ok)throw new Error("manifest "+e.status);let i=await e.json();if(i.photos.length===0)return;let n=new R(t.concurrency,t.workerUrl),s=new L(_());document.documentElement.classList.add("has-viewer"),new W(r,i,t,{scheduler:n,cache:s,settings:t,tiles:i.tiles})}function et(){let r=document.getElementById("stage");document.body.dataset.page==="album"&&r&&ut(r).catch(t=>{r.dataset.error=String(t),document.documentElement.classList.remove("has-viewer")})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",et,{once:!0}):et();})();