popupable 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/popupable.min.css +1 -1
- package/dist/popupable.min.js +2 -2
- package/package.json +1 -1
package/dist/popupable.min.css
CHANGED
package/dist/popupable.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* popupable
|
|
3
|
-
* Version : 1.0.
|
|
3
|
+
* Version : 1.0.2
|
|
4
4
|
* License : MIT
|
|
5
5
|
* Copyright: 2025 Ewan Howell
|
|
6
6
|
*/
|
|
7
|
-
{let e,t,n,o=0;const a=3;function disableScroll(){window.addEventListener("wheel",prevent,{passive:!1}),window.addEventListener("touchmove",prevent,{passive:!1}),window.addEventListener("keydown",blockKeys,!0)}function enableScroll(){window.removeEventListener("wheel",prevent),window.removeEventListener("touchmove",prevent),window.removeEventListener("keydown",blockKeys,!0)}function prevent(e){e.preventDefault()}function blockKeys(e){["ArrowUp","ArrowDown","PageUp","PageDown","Home","End"," "].includes(e.key)&&e.preventDefault()}function setCloneToOriginalRect(e,t){const n=t.getBoundingClientRect();e.style.top=visualViewport.offsetTop+n.top+"px",e.style.left=visualViewport.offsetLeft+n.left+"px",e.style.width=n.width+"px",e.style.height=n.height+"px"}function openPopupable(e){if("open"===e.state)return;e.state="open";const{cloneContainer:t,popup:n,transition:o,group:a,listeners:r}=e;n.classList.add("popupable-active"),updateExpandedSize(),t.removeEventListener("transitionend",o.listener),o.listener=e=>{if(!e||e.target===e.currentTarget){if(t.removeEventListener("transitionend",o.listener),n.classList.add("popupable-open"),a)for(const e of a)e.cloneContainer.style.display=null;for(const e of r)e.target.addEventListener(e.event,e.func,e.args)}},o.duration?t.addEventListener("transitionend",o.listener):o.listener()}function closePopupable(){if(!e||"close"===e.state)return;o++,e.state="close";const{cloneContainer:n,clone:a,original:r,popup:i,transition:l,group:s,listeners:p}=e;if(i.classList.remove("popupable-active"),i.classList.remove("popupable-open"),setCloneToOriginalRect(n,r),s)for(const[e,t]of s.entries())t.clone!==a&&e!==s.currentIndex&&(t.cloneContainer.style.display="none");for(const e of p)e.target.removeEventListener(e.event,e.func);n.removeEventListener("transitionend",l.listener);const c=e;l.listener=o=>{o&&o.target!==o.currentTarget||(n.removeEventListener("transitionend",l.listener),r.classList.remove("popupable-hide"),i.remove(),c===e&&(enableScroll(),t=e,e=null))},l.duration?n.addEventListener("transitionend",l.listener):l.listener()}function updateExpandedSize(){if(!e||"close"===e.state)return;const t=visualViewport?.width||window.innerWidth,n=visualViewport?.height||window.innerHeight,o=visualViewport?.offsetTop||0,a=visualViewport?.offsetLeft||0,r=visualViewport?.scale||1;document.documentElement.style.setProperty("--popupable-view-width",t+"px"),e.popup.style.setProperty("--popupable-vv-width",t+"px"),e.popup.style.setProperty("--popupable-vv-height",n+"px"),e.popup.style.setProperty("--popupable-vv-top",o+"px"),e.popup.style.setProperty("--popupable-vv-left",a+"px"),e.popup.style.setProperty("--popupable-vv-scale",r),e.popup.style.setProperty("--popupable-vv-ui-scale",1/r);const i=parseFloat(getComputedStyle(e.popup).getPropertyValue("--popupable-vv-ui-scale"))||1,l=(parseFloat(getComputedStyle(e.popup).getPropertyValue("--popupable-screen-padding"))||0)/r,s=Math.max(0,t-2*l),p=n-2*l,c=e.popup.querySelector(".popupable-counter"),u=c?c.getBoundingClientRect().height/i:0;let d;d=e.group?e.group:[e];for(const t of d){let c;if(t.maintainAspect){const e=t.original.getBoundingClientRect();c=e.width/e.height}else c=t.cloneLayer?t.cloneLayer.naturalWidth/t.cloneLayer.naturalHeight:t.original.naturalWidth/t.original.naturalHeight;const d=Math.max(0,p),f=t.content?t.content.getBoundingClientRect().height/i:0,m=e.thumbnailsContainer?e.thumbnailsContainer.getBoundingClientRect().height/i:0,b=(e.orderPlacement.counterTop?u:0)+(e.orderPlacement.contentTop?f:0)+(e.orderPlacement.thumbnailsTop?m:0),v=(e.orderPlacement.counterBottom?u:0)+(e.orderPlacement.contentBottom?f:0)+(e.orderPlacement.thumbnailsBottom?m:0),h=Math.max(0,n-b-v-2*l);let g=s,y=g/c;if(y>d&&(y=d,g=y*c),y>h&&(y=h,g=y*c),t.noUpscale){const e=t.cloneLayer||t.original,n=e.naturalWidth,o=e.naturalHeight;if(n&&o){const e=n/r,t=o/r,a=Math.min(1,e/g,t/y);a<1&&(g*=a,y*=a)}}let L=o+l+(d-y)/2;const x=o+n-v-l-y;L=Math.min(L,x),L=Math.max(L,o+b+l),t.cloneContainer.style.top=L+"px",t.cloneContainer.style.left=a+l+(s-g)/2+"px",t.cloneContainer.style.width=g+"px",t.cloneContainer.style.height=y+"px"}if(e.contentContainer){let t;t=e.group?e.group[e.group.currentIndex]:e;const n=t.content.getBoundingClientRect();e.contentContainer.style.height=n.height/i+"px"}}function parsePopupableOrder(e){const t=["counter","image","content","thumbnails"],n=new Set(t),o=[];if(e)for(const t of e.split(",")){const e=t.trim().toLowerCase();e&&n.has(e)&&!o.includes(e)&&o.push(e)}for(const e of t)o.includes(e)||o.push(e);const a=o.indexOf("image");return{top:o.slice(0,a),bottom:o.slice(a+1)}}function cloneElement(e){const t=document.createElement("div");t.className="popupable-clone-container",e.hasAttribute("data-popupable-transparent")&&t.classList.add("popupable-transparent");const n=new Image;n.className="popupable-clone",n.src=e.currentSrc??e.src;const o=getComputedStyle(e);let a,r,i;if(t.style.borderRadius=o.borderRadius,n.style.objectFit=o.objectFit,n.style.objectPosition=o.objectPosition,n.style.imageRendering=o.imageRendering,n.style.background=o.background,t.append(n),e.dataset.popupableSrc&&(a=new Image,a.className="popupable-clone-layer",a.src=e.dataset.popupableSrc,a.style.imageRendering=o.imageRendering,t.append(a),"fill"===n.style.objectFit)){const t=e.getBoundingClientRect();e.naturalWidth&&e.naturalHeight&&Math.abs(t.width/t.height-e.naturalWidth/e.naturalHeight)<.01&&(n.style.objectFit="cover")}if(e.dataset.popupableTitle||e.dataset.popupableDescription){if(r=document.createElement("div"),r.classList="popupable-content",e.dataset.popupableTitle){const t=document.createElement("div");t.className="popupable-title",t.textContent=e.dataset.popupableTitle,r.append(t)}if(e.dataset.popupableDescription){const t=document.createElement("div");t.className="popupable-description",t.textContent=e.dataset.popupableDescription,r.append(t)}}return e.hasAttribute("data-popupable-zoomable")&&(i=!0,t.classList.add("popupable-zoomable")),{id:e.dataset.popupable,original:e,cloneContainer:t,clone:n,cloneLayer:a,maintainAspect:e.hasAttribute("data-popupable-maintain-aspect"),noUpscale:e.hasAttribute("data-popupable-no-upscale"),counter:e.hasAttribute("data-popupable-counter"),thumbnails:e.hasAttribute("data-popupable-thumbnails"),order:parsePopupableOrder(e.dataset.popupableOrder),ready:Promise.all([n,a].filter(Boolean).map(e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener("load",t,{once:!0}),e.addEventListener("error",t,{once:!0})}))),content:r,zoomable:i}}let r,i,l,s=0;function handleMove(t){if("open"!==e?.state||!e.group||!r)return;const n=e.group[e.group.currentIndex];n.cloneContainer.parentElement.style.transition="initial",n.cloneContainer.parentElement.style.transform=`translateX(${(t.touches?.[0].clientX??t.clientX)-i}px)`}document.addEventListener("pointerdown",t=>{0===t.button&&("touch"===t.pointerType&&s++,r||(n=t.target,i=t.clientX,l=t.clientY),r||"open"!==e?.state||t.target.closest(".popupable-header, .popupable-footer")||(r=!0))}),document.addEventListener("mousemove",handleMove),document.addEventListener("touchmove",handleMove,{passive:!0}),document.addEventListener("pointerup",async p=>{if(0!==p.button)return;if("touch"===p.pointerType&&(s=Math.max(0,s-1),r&&s>=1))return;if(r){r=!1;const _=e.group?e.group[e.group.currentIndex]:e;_.cloneContainer.parentElement.style.transition=null,_.cloneContainer.parentElement.style.transform=null;const j=p.clientX-i,K=Math.abs(j),G=p.clientY-l,Z=Math.abs(G);if("touch"===p.pointerType&&Z>56&&Z>1.1*K)return void closePopupable();if(e.group&&K>a){const J=Math.max(0,Math.floor((K-window.innerWidth/2)/window.innerWidth));if(j>32)for(let Q=0;Q<=J;Q++)e.goPrev();else if(j<-32)for(let ee=0;ee<=J;ee++)e.goNext();return void(e.blocked=!0)}}const c=p.target.closest(".popupable-viewport")&&!n.closest(".popupable-viewport");if(!(c||p.target==n||n.classList.contains("popupable-clone-container")&&p.target===t?.original))return;const u=(c?n.closest("[data-popupable]"):null)||p.target.closest("[data-popupable]");if(!u){if(c)return void closePopupable();if(p.target.closest(".popupable-container"))return;return void(e&&("zoomed"===e.state?e.unzoom():closePopupable()))}if(p.preventDefault(),Math.abs(p.clientX-i)>a||Math.abs(p.clientY-l)>a)return;if(e?.original===u&&e.popup&&!e.popup.isConnected&&"close"!==e.state)return;const d=++o;e&&closePopupable(),e={transition:{},listeners:[]};const f=e,m=document.createElement("div");m.className="popupable-clones";const b=cloneElement(u),{cloneContainer:v,clone:h,content:g}=b;let y;if(u.dataset.popupableGroup){const te=document.querySelectorAll(`[data-popupable-group="${u.dataset.popupableGroup}"]`);if(te.length){y=[];for(const[ne,oe]of te.entries())if(oe===u)y.push(b),y.currentIndex=ne,m.append(v);else{const ae=cloneElement(oe);ae.cloneContainer.style.display="none",ae.cloneContainer.classList.add("popupable-clone-extra"),y.push(ae),m.append(ae.cloneContainer)}}}else m.append(v);const L=document.createElement("div");L.className="popupable-container",b.id&&(L.id=b.id);const x=document.createElement("div");let w,C,P,E,I,M,z,k,T,X;x.className="popupable-viewport",g&&(w=document.createElement("div"),w.classList="popupable-content-container");const A={};if(y){b.counter&&(C=document.createElement("div"),C.className="popupable-header",E=document.createElement("div"),E.className="popupable-counter",C.append(E)),b.thumbnails&&(I=document.createElement("div"),I.className="popupable-thumbnails",M=y.map((e,t)=>{const n=new Image;return n.className="popupable-thumbnail",n.src=e.original.currentSrc??e.original.src,n.dataset.thumbnailIndex=t,I.append(n),n})),x.innerHTML=`\n <div class="popupable-prev-container${y.currentIndex?"":" popupable-disabled"}">\n <div class="popupable-button popupable-nav-button popupable-prev">\n <svg width="24px" height="24px" viewBox="0 -960 960 960" fill="#fff">\n <path d="m313-440 224 224-57 56-320-320 320-320 57 56-224 224h487v80H313Z"/>\n </svg>\n </div>\n </div>\n <div class="popupable-next-container${y.currentIndex===y.length-1?" popupable-disabled":""}">\n <div class="popupable-button popupable-nav-button popupable-next">\n <svg width="24px" height="24px" viewBox="0 -960 960 960" fill="#fff">\n <path d="M647-440H160v-80h487L423-744l57-56 320 320-320 320-57-56 224-224Z"/>\n </svg>\n </div>\n </div>\n `;const re=x.querySelector(".popupable-next-container"),ie=x.querySelector(".popupable-prev-container");let le,se,pe,ce;const ue=!(navigator.maxTouchPoints>0||window.matchMedia("(hover: none)").matches);function S(){ue&&(clearTimeout(le),ce||(le=setTimeout(()=>{ce||(re.classList.add("popupable-nav-inactive"),ie.classList.add("popupable-nav-inactive"))},1500)))}function Y(){re.classList.remove("popupable-nav-inactive"),ie.classList.remove("popupable-nav-inactive"),S()}async function R(){const e=y[y.currentIndex];await e.ready,y.currentIndex?ie.classList.remove("popupable-disabled"):ie.classList.add("popupable-disabled"),y.currentIndex===y.length-1?re.classList.add("popupable-disabled"):re.classList.remove("popupable-disabled");for(const[e,t]of y.entries()){const n=e-y.currentIndex;t.cloneContainer.style.setProperty("--popupable-offset-multiplier",n),t.cloneContainer.style.zIndex=-1*Math.abs(n),t.content&&(n?n>0?(t.content.classList.add("popupable-content-after"),t.content.classList.remove("popupable-content-before")):(t.content.classList.add("popupable-content-before"),t.content.classList.remove("popupable-content-after")):(t.content.classList.remove("popupable-content-before"),t.content.classList.remove("popupable-content-after")))}if(e.id?L.id=e.id:L.removeAttribute("id"),E&&(E.textContent=`${y.currentIndex+1} / ${y.length}`),M){for(const[e,t]of M.entries())t.classList.toggle("popupable-thumbnail-active",e===y.currentIndex);const e=M[y.currentIndex];requestAnimationFrame(()=>{if(!e||!I?.isConnected)return;const t=getComputedStyle(I),n=parseFloat(t.paddingLeft)||0,o=parseFloat(t.paddingRight)||0,a=I.scrollLeft+n,r=I.scrollLeft+I.clientWidth-o,i=e.offsetLeft,l=i+e.offsetWidth;let s=I.scrollLeft;i<a?s=Math.max(0,i-n):l>r&&(s=l-I.clientWidth+o),s!==I.scrollLeft&&(z?I.scrollTo({left:s,behavior:"smooth"}):I.scrollLeft=s),z=!0})}updateExpandedSize()}if(k=()=>{y.currentIndex>=y.length-1||(y.currentIndex++,R())},T=()=>{y.currentIndex<=0||(y.currentIndex--,R())},R(),ue&&S(),e.listeners.push({target:re,event:"click",func:()=>k()},{target:ie,event:"click",func:()=>T()},{target:document,event:"keydown",func:t=>{if("zoomed"!==e.state)switch(t.key){case"ArrowRight":case"ArrowDown":case"PageDown":case"d":case"s":k();break;case"ArrowLeft":case"ArrowUp":case"PageUp":case"a":case"w":T();break;case"Home":y.currentIndex=0,R();break;case"End":y.currentIndex=y.length-1,R();break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":y.currentIndex=Math.min(Math.max(Number(t.key),1)-1,y.length-1),R()}}},{target:document,event:"wheel",func:t=>{if("zoomed"===e.state)return;const n=performance.now();n-(X||0)<80||(t.deltaY>50?(X=n,k()):t.deltaY<-50&&(X=n,T()))},args:{passive:!0}}),I){let de,fe,me,be,ve,he,ge,ye,Le;function B(){Le&&(cancelAnimationFrame(Le),Le=null)}function N(){if(B(),Math.abs(ye)<.01)return;let e=performance.now();Le=requestAnimationFrame(function t(n){if(!I.isConnected)return void B();const o=I.scrollWidth-I.clientWidth;if(o<=0)return void B();const a=Math.min(32,n-e);e=n;let r=I.scrollLeft+ye*a;r<0&&(r=0),r>o&&(r=o),I.scrollLeft=r,I.scrollLeft<=.1&&ye<0||I.scrollLeft>=o-.1&&ye>0?B():(ye*=Math.pow(.8,a/16.67),Math.abs(ye)<=.002?B():Le=requestAnimationFrame(t))})}e.listeners.push({target:I,event:"pointerdown",func:e=>{if(0!==e.button)return;const t=I.scrollWidth-I.clientWidth;me=t>0,B(),de=!0,fe=!1,be=e.clientX,ve=I.scrollLeft,he=I.scrollLeft,ge=performance.now(),ye=0,me&&I.classList.add("popupable-thumbnails-dragging"),I.setPointerCapture(e.pointerId)}},{target:I,event:"pointermove",func:e=>{if(!de)return;const t=e.clientX-be;Math.abs(t)>a&&(fe=!0);const n=performance.now(),o=n-ge,r=ve-t;if(I.scrollLeft=r,o>0){const e=(I.scrollLeft-he)/o;ye=.65*ye+.35*e,he=I.scrollLeft,ge=n}}},{target:I,event:"pointerup",func:e=>{if(!de)return;if(de=!1,me&&I.classList.remove("popupable-thumbnails-dragging"),I.hasPointerCapture(e.pointerId)&&I.releasePointerCapture(e.pointerId),fe)return performance.now()-ge>10&&(ye=0),void N();const t=document.elementFromPoint(e.clientX,e.clientY)?.closest?.(".popupable-thumbnail");t&&(y.currentIndex=Number(t.dataset.thumbnailIndex),R())}},{target:I,event:"pointercancel",func:e=>{de&&(de=!1,me&&I.classList.remove("popupable-thumbnails-dragging"),I.hasPointerCapture(e.pointerId)&&I.releasePointerCapture(e.pointerId),B())}},{target:I,event:"wheel",func:e=>{e.stopPropagation(),e.preventDefault();const t=I.scrollWidth-I.clientWidth;if(t<=0)return;const n=Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX:e.deltaY,o=I.scrollLeft<=.1,a=I.scrollLeft>=t-.1;if(o&&n<0||a&&n>0)return;o&&n>0&&ye<0&&(ye=0),a&&n<0&&ye>0&&(ye=0);ye=(ye||0)+.015*n,Le||N()},args:{passive:!1}})}ue&&(e.listeners.push({target:re,event:"pointerenter",func:()=>{ce=!0,Y()}},{target:ie,event:"pointerenter",func:()=>{ce=!0,Y()}},{target:re,event:"pointerleave",func:()=>{ce=!1,S()}},{target:ie,event:"pointerleave",func:()=>{ce=!1,S()}}),e.listeners.push({target:L,event:"pointermove",func:t=>{if("zoomed"!==e.state)return null==se||null==pe?(se=t.clientX,void(pe=t.clientY)):void(Math.abs(t.clientX-se)<a&&Math.abs(t.clientY-pe)<a||(se=t.clientX,pe=t.clientY,Y()))},args:{passive:!0}}));for(const xe of y)xe.content&&w&&w.append(xe.content)}else g&&w.append(g);const F={counter:!!E,content:!!w,thumbnails:!!I},D=b.order.top.filter(e=>F[e]),W=b.order.bottom.filter(e=>F[e]);function H(e,t){e&&("counter"===t&&E?(A[e===C?"counterTop":"counterBottom"]=!0,e.append(E)):"content"===t&&w?(A[e===C?"contentTop":"contentBottom"]=!0,e.append(w)):"thumbnails"===t&&I&&(A[e===C?"thumbnailsTop":"thumbnailsBottom"]=!0,e.append(I)))}D.length&&(C=document.createElement("div"),C.className="popupable-header"),W.length&&(P=document.createElement("div"),P.className="popupable-footer");for(const we of D)H(C,we);for(const Ce of W)H(P,Ce);if(C&&x.append(C),P&&x.append(P),L.append(m,x),Object.assign(f,b,{popup:L,group:y,contentContainer:w,thumbnailsContainer:I,orderPlacement:A,goNext:k,goPrev:T}),await f.ready,d!==o||e!==f||"close"===f.state)return;setCloneToOriginalRect(v,u),document.body.append(L),u.classList.add("popupable-hide"),disableScroll();const O=getComputedStyle(L);f.transition.duration=1e3*parseFloat(O.transitionDuration)+1e3*parseFloat(O.transitionDelay),L._state=f,requestAnimationFrame(()=>{requestAnimationFrame(()=>{openPopupable(L._state)})});let V,q=0;y&&L.addEventListener("dragstart",e=>e.preventDefault());const $=new Map;function U(e,t,n,o,i=[]){if("open"!==e.state)return;let l=0;const s=t.cloneContainer.parentElement,p=s.style.transform;if(p){const e=p.match(/translateX\((-?\d+(?:\.\d+)?)px\)/);e&&(l=Number(e[1])||0)}const c=Math.abs(l)>.5;r=!1,c?(t.cloneContainer.style.translate="0 0",t.cloneContainer.style.transition="translate var(--popupable-switch-duration), transform 0s",s.style.transition=null,s.style.transform=null,t.cloneContainer.style.translate=`${l}px 0`):(s.style.transition=null,s.style.transform=null),e.state="zoomed",L.classList.add("popupable-locked");let u,d,f=o;const m=new Map;let b,v,h,g,y,w,C,P,E,I,M=!1;const z=t.cloneContainer.getBoundingClientRect(),k=n?.clientX??z.left+z.width/2,T=n?.clientY??z.top+z.height/2;u=(k-z.left)*(1-f),d=(T-z.top)*(1-f);const X=()=>t.cloneContainer.style.transform=`translate(${u}px, ${d}px) scale(${f})`;function A(e,n,o){const a=f;var r;if(r=e,f=Math.min(6,Math.max(1,r)),f===a)return!1;const i=t.cloneContainer.getBoundingClientRect(),l=f/a,s=n-i.left,p=o-i.top;return u+=s*(1-l),d+=p*(1-l),!0}function S(){if(1===m.size){const e=m.values().next().value;return b=e.id,v=e.x,h=e.y,g=null,y=null,void(w=null)}if(m.size>=2){b=null;const[e,t]=[...m.values()];return g=(e.x+t.x)/2,y=(e.y+t.y)/2,void(w=Math.hypot(t.x-e.x,t.y-e.y))}b=null,v=null,h=null,g=null,y=null,w=null}if(t.cloneContainer.classList.add("popupable-zoomed"),X(),i.length){c||(t.cloneContainer.style.transition="none"),I=!0;for(const e of i)m.set(e.id,{id:e.id,x:e.x,y:e.y}),L.setPointerCapture(e.id);S()}e.unzoom=()=>{e.state="open",L.classList.remove("popupable-locked");for(const e of m.keys())L.hasPointerCapture(e)&&L.releasePointerCapture(e);m.clear(),t.cloneContainer.classList.remove("popupable-zoomed"),t.cloneContainer.style.transition=null,t.cloneContainer.style.transform=null,t.cloneContainer.style.translate=null;for(const t of e.zoomListeners)t.target.removeEventListener(t.event,t.func)},e.zoomListeners=[{target:L,event:"pointerdown",func:e=>{0===e.button&&(t.cloneContainer.style.transition="none",L.setPointerCapture(e.pointerId),m.set(e.pointerId,{id:e.pointerId,x:e.clientX,y:e.clientY}),1===m.size?(C=e.target,P=e.clientX,E=e.clientY,I=!1):I=!0,S(),e.preventDefault())}},{target:L,event:"pointermove",func:e=>{const t=m.get(e.pointerId);if(t){if(t.x=e.clientX,t.y=e.clientY,!I&&(Math.abs(e.clientX-P)>a||Math.abs(e.clientY-E)>a)&&(I=!0),1===m.size&&b===e.pointerId){const t=e.clientX-v,n=e.clientY-h;if(!t&&!n)return;return u+=t,d+=n,v=e.clientX,h=e.clientY,void X()}if(m.size>=2){const[e,t]=[...m.values()],n=(e.x+t.x)/2,o=(e.y+t.y)/2,a=Math.hypot(t.x-e.x,t.y-e.y);if(!w)return g=n,y=o,void(w=a);u+=n-g,d+=o-y,A(f*(a/w),n,o),M=!0,g=n,y=o,w=a,X()}}}},{target:L,event:"pointerup",func:n=>{if(m.has(n.pointerId)){if(m.delete(n.pointerId),L.hasPointerCapture(n.pointerId)&&L.releasePointerCapture(n.pointerId),M&&f<=1.01&&m.size<2)return e.skipOpenTouchPointerUps=m.size,void e.unzoom();if(!m.size&&!I&&Math.abs(n.clientX-P)<a&&Math.abs(n.clientY-E)<a){if(C?.closest?.(".popupable-clone-container")===t.cloneContainer||(C===L||C===x))return void e.unzoom()}S()}}},{target:L,event:"pointercancel",func:e=>{m.has(e.pointerId)&&(m.delete(e.pointerId),L.hasPointerCapture(e.pointerId)&&L.releasePointerCapture(e.pointerId),S())}},{target:L,event:"wheel",func:e=>{t.cloneContainer.style.transition="none",A(f*Math.exp(.002*-e.deltaY),e.clientX,e.clientY)&&X()},args:{passive:!0}}];for(const t of e.zoomListeners)t.target.addEventListener(t.event,t.func,t.args)}e.listeners.push({target:L,event:"pointerdown",func:e=>{if("open"!==L._state.state||"touch"!==e.pointerType)return;const t=L._state,n=t.group?t.group[t.group.currentIndex]:t;e.target.closest(".popupable-clone-container")===n.cloneContainer&&($.set(e.pointerId,{id:e.pointerId,x:e.clientX,y:e.clientY}),$.size>=2&&(U(t,n,e,1,[...$.values()].slice(0,2)),$.clear(),e.preventDefault()))}},{target:L,event:"pointermove",func:e=>{const t=$.get(e.pointerId);t&&(t.x=e.clientX,t.y=e.clientY)}},{target:L,event:"pointerup",func:e=>{$.delete(e.pointerId)}},{target:L,event:"pointercancel",func:e=>{$.delete(e.pointerId)}}),L.addEventListener("pointerup",t=>{if("zoomed"===L._state.state)return;if("touch"===t.pointerType&&s>1)return;if("touch"===t.pointerType&&(L._state.skipOpenTouchPointerUps||0)>0)return void L._state.skipOpenTouchPointerUps--;const o=performance.now(),a=null!=t.target.closest(".popupable-next-container, .popupable-prev-container");if(V&&o-q<250)return void(q=o);if(a?(V=!0,q=o):(V=!1,q=o),0!==t.button||!((t.target.classList.contains("popupable-clone")||t.target.classList.contains("popupable-clone-layer"))&&n.classList.contains("popupable-clone-container")||t.target==n&&(t.target.closest(".popupable-clone-container")||t.target.classList.contains("popupable-viewport")||t.target.classList.contains("popupable-container"))||t.target.classList.contains("popupable-container")&&n===e.original.parentElement))return;const r=L._state,i=r.group?r.group[r.group.currentIndex]:r;r.blocked&&(r.blocked=!1),"open"!==r.state?(t.stopPropagation(),e!==r&&(closePopupable(),e=r),openPopupable(e)):requestAnimationFrame(()=>{r.blocked?r.blocked=!1:i.zoomable&&(t.target.classList.contains("popupable-clone")||t.target.classList.contains("popupable-clone-layer"))?U(r,i,t,2):closePopupable()})})}),document.addEventListener("pointercancel",e=>{"touch"===e.pointerType&&(s=Math.max(0,s-1))}),document.addEventListener("keydown",t=>{if("Escape"===t.key||"Backspace"===t.key||" "===t.key||"Delete"===t.key){if("zoomed"===e.state)return void e.unzoom();closePopupable()}}),window.addEventListener("resize",updateExpandedSize),visualViewport&&visualViewport.addEventListener("resize",updateExpandedSize)}
|
|
7
|
+
{let e,t,n,o=0;const a=3;function disableScroll(){window.addEventListener("wheel",prevent,{passive:!1}),window.addEventListener("touchmove",prevent,{passive:!1}),window.addEventListener("keydown",blockKeys,!0)}function enableScroll(){window.removeEventListener("wheel",prevent),window.removeEventListener("touchmove",prevent),window.removeEventListener("keydown",blockKeys,!0)}function prevent(e){e.preventDefault()}function blockKeys(e){["ArrowUp","ArrowDown","PageUp","PageDown","Home","End"," "].includes(e.key)&&e.preventDefault()}function setCloneToOriginalRect(e,t){const n=t.getBoundingClientRect();e.style.top=visualViewport.offsetTop+n.top+"px",e.style.left=visualViewport.offsetLeft+n.left+"px",e.style.width=n.width+"px",e.style.height=n.height+"px"}function openPopupable(e){if("open"===e.state)return;e.state="open";const{cloneContainer:t,popup:n,transition:o,group:a,listeners:r}=e;n.classList.add("popupable-active"),updateExpandedSize(),t.removeEventListener("transitionend",o.listener),o.listener=e=>{if(!e||e.target===e.currentTarget){if(t.removeEventListener("transitionend",o.listener),n.classList.add("popupable-open"),a)for(const e of a)e.cloneContainer.style.display=null;for(const e of r)e.target.addEventListener(e.event,e.func,e.args)}},o.duration?t.addEventListener("transitionend",o.listener):o.listener()}function closePopupable(){if(!e||"close"===e.state)return;o++,e.state="close";const{cloneContainer:n,clone:a,original:r,popup:i,transition:l,group:s,listeners:p}=e;if(i.classList.remove("popupable-active"),i.classList.remove("popupable-open"),setCloneToOriginalRect(n,r),s)for(const[e,t]of s.entries())t.clone!==a&&e!==s.currentIndex&&(t.cloneContainer.style.display="none");for(const e of p)e.target.removeEventListener(e.event,e.func);n.removeEventListener("transitionend",l.listener);const c=e;l.listener=o=>{o&&o.target!==o.currentTarget||(n.removeEventListener("transitionend",l.listener),r.classList.remove("popupable-hide"),i.remove(),c===e&&(enableScroll(),t=e,e=null))},l.duration?n.addEventListener("transitionend",l.listener):l.listener()}function updateExpandedSize(){if(!e||"close"===e.state)return;const t=visualViewport?.width||window.innerWidth,n=visualViewport?.height||window.innerHeight,o=visualViewport?.offsetTop||0,a=visualViewport?.offsetLeft||0,r=visualViewport?.scale||1;document.documentElement.style.setProperty("--popupable-view-width",t+"px"),e.popup.style.setProperty("--popupable-vv-width",t+"px"),e.popup.style.setProperty("--popupable-vv-height",n+"px"),e.popup.style.setProperty("--popupable-vv-top",o+"px"),e.popup.style.setProperty("--popupable-vv-left",a+"px"),e.popup.style.setProperty("--popupable-vv-scale",r),e.popup.style.setProperty("--popupable-vv-ui-scale",1/r);const i=parseFloat(getComputedStyle(e.popup).getPropertyValue("--popupable-vv-ui-scale"))||1,l=(parseFloat(getComputedStyle(e.popup).getPropertyValue("--popupable-screen-padding"))||0)/r,s=Math.max(0,t-2*l),p=n-2*l,c=e.popup.querySelector(".popupable-counter"),u=c?c.getBoundingClientRect().height/i:0;let d;d=e.group?e.group:[e];for(const t of d){let c;if(t.maintainAspect){const e=t.original.getBoundingClientRect();c=e.width/e.height}else c=t.cloneLayer?t.cloneLayer.naturalWidth/t.cloneLayer.naturalHeight:t.original.naturalWidth/t.original.naturalHeight;const d=Math.max(0,p),f=t.content?t.content.getBoundingClientRect().height/i:0,m=e.thumbnailsContainer?e.thumbnailsContainer.getBoundingClientRect().height/i:0,b=(e.orderPlacement.counterTop?u:0)+(e.orderPlacement.contentTop?f:0)+(e.orderPlacement.thumbnailsTop?m:0),v=(e.orderPlacement.counterBottom?u:0)+(e.orderPlacement.contentBottom?f:0)+(e.orderPlacement.thumbnailsBottom?m:0),h=Math.max(0,n-b-v-2*l);let g=s,y=g/c;if(y>d&&(y=d,g=y*c),y>h&&(y=h,g=y*c),t.noUpscale){const e=t.cloneLayer||t.original,n=e.naturalWidth,o=e.naturalHeight;if(n&&o){const e=n/r,t=o/r,a=Math.min(1,e/g,t/y);a<1&&(g*=a,y*=a)}}let L=o+l+(d-y)/2;const x=o+n-v-l-y;L=Math.min(L,x),L=Math.max(L,o+b+l),t.cloneContainer.style.top=L+"px",t.cloneContainer.style.left=a+l+(s-g)/2+"px",t.cloneContainer.style.width=g+"px",t.cloneContainer.style.height=y+"px"}if(e.contentContainer){let t;t=e.group?e.group[e.group.currentIndex]:e;const n=t.content.getBoundingClientRect();e.contentContainer.style.height=n.height/i+"px"}}function parsePopupableOrder(e){const t=["counter","image","content","thumbnails"],n=new Set(t),o=[];if(e)for(const t of e.split(",")){const e=t.trim().toLowerCase();e&&n.has(e)&&!o.includes(e)&&o.push(e)}for(const e of t)o.includes(e)||o.push(e);const a=o.indexOf("image");return{top:o.slice(0,a),bottom:o.slice(a+1)}}function cloneElement(e){const t=document.createElement("div");t.className="popupable-clone-container",e.hasAttribute("data-popupable-transparent")&&t.classList.add("popupable-transparent");const n=new Image;n.className="popupable-clone",n.src=e.currentSrc??e.src;const o=getComputedStyle(e);let a,r,i;if(t.style.borderRadius=o.borderRadius,n.style.objectFit=o.objectFit,n.style.objectPosition=o.objectPosition,n.style.imageRendering=o.imageRendering,n.style.background=o.background,t.append(n),e.dataset.popupableSrc&&(a=new Image,a.className="popupable-clone-layer",a.src=e.dataset.popupableSrc,a.style.imageRendering=o.imageRendering,t.append(a),"fill"===n.style.objectFit)){const t=e.getBoundingClientRect();e.naturalWidth&&e.naturalHeight&&Math.abs(t.width/t.height-e.naturalWidth/e.naturalHeight)<.01&&(n.style.objectFit="cover")}if(e.dataset.popupableTitle||e.dataset.popupableDescription){if(r=document.createElement("div"),r.classList="popupable-content",e.dataset.popupableTitle){const t=document.createElement("div");t.className="popupable-title",t.textContent=e.dataset.popupableTitle,r.append(t)}if(e.dataset.popupableDescription){const t=document.createElement("div");t.className="popupable-description",t.textContent=e.dataset.popupableDescription,r.append(t)}}return e.hasAttribute("data-popupable-zoomable")&&(i=!0,t.classList.add("popupable-zoomable")),{id:e.dataset.popupable,original:e,cloneContainer:t,clone:n,cloneLayer:a,maintainAspect:e.hasAttribute("data-popupable-maintain-aspect"),noUpscale:e.hasAttribute("data-popupable-no-upscale"),counter:e.hasAttribute("data-popupable-counter"),thumbnails:e.hasAttribute("data-popupable-thumbnails"),order:parsePopupableOrder(e.dataset.popupableOrder),ready:Promise.all([n,a].filter(Boolean).map(e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener("load",t,{once:!0}),e.addEventListener("error",t,{once:!0})}))),content:r,zoomable:i}}let r,i,l,s=0;function handleMove(t){if("open"!==e?.state||!e.group||!r)return;const n=e.group[e.group.currentIndex];n.cloneContainer.parentElement.style.transition="initial",n.cloneContainer.parentElement.style.transform=`translateX(${(t.touches?.[0].clientX??t.clientX)-i}px)`}document.addEventListener("pointerdown",t=>{0===t.button&&("touch"===t.pointerType&&s++,r||(n=t.target,i=t.clientX,l=t.clientY),r||"open"!==e?.state||t.target.closest(".popupable-header, .popupable-footer")||(r=!0))}),document.addEventListener("mousemove",handleMove),document.addEventListener("touchmove",handleMove,{passive:!0}),document.addEventListener("pointerup",async p=>{if(0!==p.button)return;if("touch"===p.pointerType&&(s=Math.max(0,s-1),r&&s>=1))return;if(r){r=!1;const _=e.group?e.group[e.group.currentIndex]:e;_.cloneContainer.parentElement.style.transition=null,_.cloneContainer.parentElement.style.transform=null;const j=p.clientX-i,K=Math.abs(j),G=p.clientY-l,Z=Math.abs(G);if("touch"===p.pointerType&&Z>56&&Z>1.1*K)return void closePopupable();if(e.group&&K>a){const J=Math.max(0,Math.floor((K-window.innerWidth/2)/window.innerWidth));if(j>32)for(let Q=0;Q<=J;Q++)e.goPrev();else if(j<-32)for(let ee=0;ee<=J;ee++)e.goNext();return void(e.blocked=!0)}}const c=p.target.closest(".popupable-viewport")&&!n.closest(".popupable-viewport");if(!c&&p.target!=n&&(!n.classList.contains("popupable-clone-container")||p.target!==t?.original)&&(!n.closest(".popupable-container")||p.target.closest(".popupable-container"))||Math.abs(p.clientX-i)>a||Math.abs(p.clientY-l)>a)return;const u=(c?n.closest("[data-popupable]"):null)||p.target.closest("[data-popupable]");if(!u){if(c)return void closePopupable();if(p.target.closest(".popupable-container"))return;return void(e&&("zoomed"===e.state?e.unzoom():closePopupable()))}if(p.preventDefault(),e?.original===u&&e.popup&&!e.popup.isConnected&&"close"!==e.state)return;const d=++o;e&&closePopupable(),e={transition:{},listeners:[]};const f=e,m=document.createElement("div");m.className="popupable-clones";const b=cloneElement(u),{cloneContainer:v,clone:h,content:g}=b;let y;if(u.dataset.popupableGroup){const te=document.querySelectorAll(`[data-popupable-group="${u.dataset.popupableGroup}"]`);if(te.length){y=[];for(const[ne,oe]of te.entries())if(oe===u)y.push(b),y.currentIndex=ne,m.append(v);else{const ae=cloneElement(oe);ae.cloneContainer.style.display="none",ae.cloneContainer.classList.add("popupable-clone-extra"),y.push(ae),m.append(ae.cloneContainer)}}}else m.append(v);const L=document.createElement("div");L.className="popupable-container",b.id&&(L.id=b.id);const x=document.createElement("div");let w,C,P,E,I,M,z,k,T,X;x.className="popupable-viewport",g&&(w=document.createElement("div"),w.classList="popupable-content-container");const A={};if(y){b.counter&&(C=document.createElement("div"),C.className="popupable-header",E=document.createElement("div"),E.className="popupable-counter",C.append(E)),b.thumbnails&&(I=document.createElement("div"),I.className="popupable-thumbnails",M=y.map((e,t)=>{const n=new Image;return n.className="popupable-thumbnail",n.src=e.original.currentSrc??e.original.src,n.dataset.thumbnailIndex=t,I.append(n),n})),x.innerHTML=`\n <div class="popupable-prev-container${y.currentIndex?"":" popupable-disabled"}">\n <div class="popupable-button popupable-nav-button popupable-prev">\n <svg width="24px" height="24px" viewBox="0 -960 960 960" fill="#fff">\n <path d="m313-440 224 224-57 56-320-320 320-320 57 56-224 224h487v80H313Z"/>\n </svg>\n </div>\n </div>\n <div class="popupable-next-container${y.currentIndex===y.length-1?" popupable-disabled":""}">\n <div class="popupable-button popupable-nav-button popupable-next">\n <svg width="24px" height="24px" viewBox="0 -960 960 960" fill="#fff">\n <path d="M647-440H160v-80h487L423-744l57-56 320 320-320 320-57-56 224-224Z"/>\n </svg>\n </div>\n </div>\n `;const re=x.querySelector(".popupable-next-container"),ie=x.querySelector(".popupable-prev-container");let le,se,pe,ce;const ue=!(navigator.maxTouchPoints>0||window.matchMedia("(hover: none)").matches);function S(){ue&&(clearTimeout(le),ce||(le=setTimeout(()=>{ce||(re.classList.add("popupable-nav-inactive"),ie.classList.add("popupable-nav-inactive"))},1500)))}function Y(){re.classList.remove("popupable-nav-inactive"),ie.classList.remove("popupable-nav-inactive"),S()}async function R(){const e=y[y.currentIndex];await e.ready,y.currentIndex?ie.classList.remove("popupable-disabled"):ie.classList.add("popupable-disabled"),y.currentIndex===y.length-1?re.classList.add("popupable-disabled"):re.classList.remove("popupable-disabled");for(const[e,t]of y.entries()){const n=e-y.currentIndex;t.cloneContainer.style.setProperty("--popupable-offset-multiplier",n),t.cloneContainer.style.zIndex=-1*Math.abs(n),t.content&&(n?n>0?(t.content.classList.add("popupable-content-after"),t.content.classList.remove("popupable-content-before")):(t.content.classList.add("popupable-content-before"),t.content.classList.remove("popupable-content-after")):(t.content.classList.remove("popupable-content-before"),t.content.classList.remove("popupable-content-after")))}if(e.id?L.id=e.id:L.removeAttribute("id"),E&&(E.textContent=`${y.currentIndex+1} / ${y.length}`),M){for(const[e,t]of M.entries())t.classList.toggle("popupable-thumbnail-active",e===y.currentIndex);const e=M[y.currentIndex];requestAnimationFrame(()=>{if(!e||!I?.isConnected)return;const t=getComputedStyle(I),n=parseFloat(t.paddingLeft)||0,o=parseFloat(t.paddingRight)||0,a=I.scrollLeft+n,r=I.scrollLeft+I.clientWidth-o,i=e.offsetLeft,l=i+e.offsetWidth;let s=I.scrollLeft;i<a?s=Math.max(0,i-n):l>r&&(s=l-I.clientWidth+o),s!==I.scrollLeft&&(z?I.scrollTo({left:s,behavior:"smooth"}):I.scrollLeft=s),z=!0})}updateExpandedSize()}if(k=()=>{y.currentIndex>=y.length-1||(y.currentIndex++,R())},T=()=>{y.currentIndex<=0||(y.currentIndex--,R())},R(),ue&&S(),e.listeners.push({target:re,event:"click",func:()=>k()},{target:ie,event:"click",func:()=>T()},{target:document,event:"keydown",func:t=>{if("zoomed"!==e.state)switch(t.key){case"ArrowRight":case"ArrowDown":case"PageDown":case"d":case"s":k();break;case"ArrowLeft":case"ArrowUp":case"PageUp":case"a":case"w":T();break;case"Home":y.currentIndex=0,R();break;case"End":y.currentIndex=y.length-1,R();break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":y.currentIndex=Math.min(Math.max(Number(t.key),1)-1,y.length-1),R()}}},{target:document,event:"wheel",func:t=>{if("zoomed"===e.state)return;const n=performance.now();n-(X||0)<80||(t.deltaY>50?(X=n,k()):t.deltaY<-50&&(X=n,T()))},args:{passive:!0}}),I){let de,fe,me,be,ve,he,ge,ye,Le;function B(){Le&&(cancelAnimationFrame(Le),Le=null)}function N(){if(B(),Math.abs(ye)<.01)return;let e=performance.now();Le=requestAnimationFrame(function t(n){if(!I.isConnected)return void B();const o=I.scrollWidth-I.clientWidth;if(o<=0)return void B();const a=Math.min(32,n-e);e=n;let r=I.scrollLeft+ye*a;r<0&&(r=0),r>o&&(r=o),I.scrollLeft=r,I.scrollLeft<=.1&&ye<0||I.scrollLeft>=o-.1&&ye>0?B():(ye*=Math.pow(.8,a/16.67),Math.abs(ye)<=.002?B():Le=requestAnimationFrame(t))})}e.listeners.push({target:I,event:"pointerdown",func:e=>{if(0!==e.button)return;const t=I.scrollWidth-I.clientWidth;me=t>0,B(),de=!0,fe=!1,be=e.clientX,ve=I.scrollLeft,he=I.scrollLeft,ge=performance.now(),ye=0,me&&I.classList.add("popupable-thumbnails-dragging"),I.setPointerCapture(e.pointerId)}},{target:I,event:"pointermove",func:e=>{if(!de)return;const t=e.clientX-be;Math.abs(t)>a&&(fe=!0);const n=performance.now(),o=n-ge,r=ve-t;if(I.scrollLeft=r,o>0){const e=(I.scrollLeft-he)/o;ye=.65*ye+.35*e,he=I.scrollLeft,ge=n}}},{target:I,event:"pointerup",func:e=>{if(!de)return;if(de=!1,me&&I.classList.remove("popupable-thumbnails-dragging"),I.hasPointerCapture(e.pointerId)&&I.releasePointerCapture(e.pointerId),fe)return performance.now()-ge>10&&(ye=0),void N();const t=document.elementFromPoint(e.clientX,e.clientY)?.closest?.(".popupable-thumbnail");t&&(y.currentIndex=Number(t.dataset.thumbnailIndex),R())}},{target:I,event:"pointercancel",func:e=>{de&&(de=!1,me&&I.classList.remove("popupable-thumbnails-dragging"),I.hasPointerCapture(e.pointerId)&&I.releasePointerCapture(e.pointerId),B())}},{target:I,event:"wheel",func:e=>{e.stopPropagation(),e.preventDefault();const t=I.scrollWidth-I.clientWidth;if(t<=0)return;const n=Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX:e.deltaY,o=I.scrollLeft<=.1,a=I.scrollLeft>=t-.1;if(o&&n<0||a&&n>0)return;o&&n>0&&ye<0&&(ye=0),a&&n<0&&ye>0&&(ye=0);ye=(ye||0)+.015*n,Le||N()},args:{passive:!1}})}ue&&(e.listeners.push({target:re,event:"pointerenter",func:()=>{ce=!0,Y()}},{target:ie,event:"pointerenter",func:()=>{ce=!0,Y()}},{target:re,event:"pointerleave",func:()=>{ce=!1,S()}},{target:ie,event:"pointerleave",func:()=>{ce=!1,S()}}),e.listeners.push({target:L,event:"pointermove",func:t=>{if("zoomed"!==e.state)return null==se||null==pe?(se=t.clientX,void(pe=t.clientY)):void(Math.abs(t.clientX-se)<a&&Math.abs(t.clientY-pe)<a||(se=t.clientX,pe=t.clientY,Y()))},args:{passive:!0}}));for(const xe of y)xe.content&&w&&w.append(xe.content)}else g&&w.append(g);const F={counter:!!E,content:!!w,thumbnails:!!I},D=b.order.top.filter(e=>F[e]),W=b.order.bottom.filter(e=>F[e]);function H(e,t){e&&("counter"===t&&E?(A[e===C?"counterTop":"counterBottom"]=!0,e.append(E)):"content"===t&&w?(A[e===C?"contentTop":"contentBottom"]=!0,e.append(w)):"thumbnails"===t&&I&&(A[e===C?"thumbnailsTop":"thumbnailsBottom"]=!0,e.append(I)))}D.length&&(C=document.createElement("div"),C.className="popupable-header"),W.length&&(P=document.createElement("div"),P.className="popupable-footer");for(const we of D)H(C,we);for(const Ce of W)H(P,Ce);if(C&&x.append(C),P&&x.append(P),L.append(m,x),Object.assign(f,b,{popup:L,group:y,contentContainer:w,thumbnailsContainer:I,orderPlacement:A,goNext:k,goPrev:T}),await f.ready,d!==o||e!==f||"close"===f.state)return;setCloneToOriginalRect(v,u),document.body.append(L),u.classList.add("popupable-hide"),disableScroll();const O=getComputedStyle(L);f.transition.duration=1e3*parseFloat(O.transitionDuration)+1e3*parseFloat(O.transitionDelay),L._state=f,requestAnimationFrame(()=>{requestAnimationFrame(()=>{openPopupable(L._state)})});let V,q=0;y&&L.addEventListener("dragstart",e=>e.preventDefault());const $=new Map;function U(e,t,n,o,i=[]){if("open"!==e.state)return;let l=0;const s=t.cloneContainer.parentElement,p=s.style.transform;if(p){const e=p.match(/translateX\((-?\d+(?:\.\d+)?)px\)/);e&&(l=Number(e[1])||0)}const c=Math.abs(l)>.5;r=!1,c?(t.cloneContainer.style.translate="0 0",t.cloneContainer.style.transition="translate var(--popupable-switch-duration), transform 0s",s.style.transition=null,s.style.transform=null,t.cloneContainer.style.translate=`${l}px 0`):(s.style.transition=null,s.style.transform=null),e.state="zoomed",L.classList.add("popupable-locked");let u,d,f=o;const m=new Map;let b,v,h,g,y,w,C,P,E,I,M=!1;const z=t.cloneContainer.getBoundingClientRect(),k=n?.clientX??z.left+z.width/2,T=n?.clientY??z.top+z.height/2;u=(k-z.left)*(1-f),d=(T-z.top)*(1-f);const X=()=>t.cloneContainer.style.transform=`translate(${u}px, ${d}px) scale(${f})`;function A(e,n,o){const a=f;var r;if(r=e,f=Math.min(6,Math.max(1,r)),f===a)return!1;const i=t.cloneContainer.getBoundingClientRect(),l=f/a,s=n-i.left,p=o-i.top;return u+=s*(1-l),d+=p*(1-l),!0}function S(){if(1===m.size){const e=m.values().next().value;return b=e.id,v=e.x,h=e.y,g=null,y=null,void(w=null)}if(m.size>=2){b=null;const[e,t]=[...m.values()];return g=(e.x+t.x)/2,y=(e.y+t.y)/2,void(w=Math.hypot(t.x-e.x,t.y-e.y))}b=null,v=null,h=null,g=null,y=null,w=null}if(t.cloneContainer.classList.add("popupable-zoomed"),X(),i.length){c||(t.cloneContainer.style.transition="none"),I=!0;for(const e of i)m.set(e.id,{id:e.id,x:e.x,y:e.y}),L.setPointerCapture(e.id);S()}e.unzoom=()=>{e.state="open",L.classList.remove("popupable-locked");for(const e of m.keys())L.hasPointerCapture(e)&&L.releasePointerCapture(e);m.clear(),t.cloneContainer.classList.remove("popupable-zoomed"),t.cloneContainer.style.transition=null,t.cloneContainer.style.transform=null,t.cloneContainer.style.translate=null;for(const t of e.zoomListeners)t.target.removeEventListener(t.event,t.func)},e.zoomListeners=[{target:L,event:"pointerdown",func:e=>{0===e.button&&(t.cloneContainer.style.transition="none",L.setPointerCapture(e.pointerId),m.set(e.pointerId,{id:e.pointerId,x:e.clientX,y:e.clientY}),1===m.size?(C=e.target,P=e.clientX,E=e.clientY,I=!1):I=!0,S(),e.preventDefault())}},{target:L,event:"pointermove",func:e=>{const t=m.get(e.pointerId);if(t){if(t.x=e.clientX,t.y=e.clientY,!I&&(Math.abs(e.clientX-P)>a||Math.abs(e.clientY-E)>a)&&(I=!0),1===m.size&&b===e.pointerId){const t=e.clientX-v,n=e.clientY-h;if(!t&&!n)return;return u+=t,d+=n,v=e.clientX,h=e.clientY,void X()}if(m.size>=2){const[e,t]=[...m.values()],n=(e.x+t.x)/2,o=(e.y+t.y)/2,a=Math.hypot(t.x-e.x,t.y-e.y);if(!w)return g=n,y=o,void(w=a);u+=n-g,d+=o-y,A(f*(a/w),n,o),M=!0,g=n,y=o,w=a,X()}}}},{target:L,event:"pointerup",func:n=>{if(m.has(n.pointerId)){if(m.delete(n.pointerId),L.hasPointerCapture(n.pointerId)&&L.releasePointerCapture(n.pointerId),M&&f<=1.01&&m.size<2)return e.skipOpenTouchPointerUps=m.size,void e.unzoom();if(!m.size&&!I&&Math.abs(n.clientX-P)<a&&Math.abs(n.clientY-E)<a){if(C?.closest?.(".popupable-clone-container")===t.cloneContainer||(C===L||C===x))return void e.unzoom()}S()}}},{target:L,event:"pointercancel",func:e=>{m.has(e.pointerId)&&(m.delete(e.pointerId),L.hasPointerCapture(e.pointerId)&&L.releasePointerCapture(e.pointerId),S())}},{target:L,event:"wheel",func:e=>{t.cloneContainer.style.transition="none",A(f*Math.exp(.002*-e.deltaY),e.clientX,e.clientY)&&X()},args:{passive:!0}}];for(const t of e.zoomListeners)t.target.addEventListener(t.event,t.func,t.args)}e.listeners.push({target:L,event:"pointerdown",func:e=>{if("open"!==L._state.state||"touch"!==e.pointerType)return;const t=L._state,n=t.group?t.group[t.group.currentIndex]:t;e.target.closest(".popupable-clone-container")===n.cloneContainer&&($.set(e.pointerId,{id:e.pointerId,x:e.clientX,y:e.clientY}),$.size>=2&&(U(t,n,e,1,[...$.values()].slice(0,2)),$.clear(),e.preventDefault()))}},{target:L,event:"pointermove",func:e=>{const t=$.get(e.pointerId);t&&(t.x=e.clientX,t.y=e.clientY)}},{target:L,event:"pointerup",func:e=>{$.delete(e.pointerId)}},{target:L,event:"pointercancel",func:e=>{$.delete(e.pointerId)}}),L.addEventListener("pointerup",t=>{if("zoomed"===L._state.state)return;if("touch"===t.pointerType&&s>1)return;if("touch"===t.pointerType&&(L._state.skipOpenTouchPointerUps||0)>0)return void L._state.skipOpenTouchPointerUps--;const o=performance.now(),a=null!=t.target.closest(".popupable-next-container, .popupable-prev-container");if(V&&o-q<250)return void(q=o);if(a?(V=!0,q=o):(V=!1,q=o),0!==t.button||!((t.target.classList.contains("popupable-clone")||t.target.classList.contains("popupable-clone-layer"))&&n.classList.contains("popupable-clone-container")||t.target==n&&(t.target.closest(".popupable-clone-container")||t.target.classList.contains("popupable-viewport")||t.target.classList.contains("popupable-container"))||t.target.classList.contains("popupable-container")&&n===e.original.parentElement))return;const r=L._state,i=r.group?r.group[r.group.currentIndex]:r;r.blocked&&(r.blocked=!1),"open"!==r.state?(t.stopPropagation(),e!==r&&(closePopupable(),e=r),openPopupable(e)):requestAnimationFrame(()=>{r.blocked?r.blocked=!1:i.zoomable&&(t.target.classList.contains("popupable-clone")||t.target.classList.contains("popupable-clone-layer"))?U(r,i,t,2):closePopupable()})})}),document.addEventListener("pointercancel",e=>{"touch"===e.pointerType&&(s=Math.max(0,s-1))}),document.addEventListener("keydown",t=>{if("Escape"===t.key||"Backspace"===t.key||" "===t.key||"Delete"===t.key){if("zoomed"===e.state)return void e.unzoom();closePopupable()}}),window.addEventListener("resize",updateExpandedSize),visualViewport&&visualViewport.addEventListener("resize",updateExpandedSize)}
|