popupable 1.0.0 → 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/README.md CHANGED
@@ -27,16 +27,14 @@ Just add `data-popupable` to any image!
27
27
  npm install popupable
28
28
  ```
29
29
 
30
- ### Or use via CDN
31
- https://www.jsdelivr.com/package/npm/popupable
32
-
33
- ### Import
34
-
35
30
  ```js
36
31
  import "popupable/styles.css"
37
32
  import "popupable"
38
33
  ```
39
34
 
35
+ ### Or use via CDN
36
+ https://www.jsdelivr.com/package/npm/popupable
37
+
40
38
  ### Add popups to your images
41
39
 
42
40
  ```html
@@ -118,7 +116,7 @@ Group multiple images together with `data-popupable-group`. Users can navigate w
118
116
  <img src="photo3.jpg" data-popupable data-popupable-group="holiday">
119
117
  ```
120
118
 
121
- #### Counter and thumbnails
119
+ ###Counter and thumbnails
122
120
 
123
121
  Add `data-popupable-counter` and/or `data-popupable-thumbnails` to individual group members. The attributes are read from whichever image is clicked to open the gallery, so add them to every image that should show these elements:
124
122
 
@@ -128,7 +126,7 @@ Add `data-popupable-counter` and/or `data-popupable-thumbnails` to individual gr
128
126
  <img src="photo3.jpg" data-popupable data-popupable-group="holiday" data-popupable-counter data-popupable-thumbnails>
129
127
  ```
130
128
 
131
- #### Custom UI order
129
+ ###Custom UI order
132
130
 
133
131
  Control the order of UI elements around the image with `data-popupable-order`. The `image` token marks where the image sits; everything before it goes in the header, everything after goes in the footer.
134
132
 
@@ -139,7 +137,7 @@ Control the order of UI elements around the image with `data-popupable-order`. T
139
137
 
140
138
  Default order: `counter,image,content,thumbnails`
141
139
 
142
- #### Keyboard navigation
140
+ ###Keyboard navigation
143
141
 
144
142
  | Keys | Action |
145
143
  |---|---|
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * popupable
3
- * Version : 1.0.0
3
+ * Version : 1.0.2
4
4
  * License : MIT
5
5
  * Copyright: 2025 Ewan Howell
6
6
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * popupable
3
- * Version : 1.0.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;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 a,r,i,l=0;function handleMove(t){if("open"!==e?.state||!e.group||!a)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)-r}px)`}document.addEventListener("pointerdown",t=>{0===t.button&&("touch"===t.pointerType&&l++,a||(n=t.target),a||"open"!==e?.state||t.target.closest(".popupable-header, .popupable-footer")||(a=!0,r=t.clientX,i=t.clientY))}),document.addEventListener("mousemove",handleMove),document.addEventListener("touchmove",handleMove,{passive:!0}),document.addEventListener("pointerup",async s=>{if(0!==s.button)return;if("touch"===s.pointerType&&(l=Math.max(0,l-1),a&&l>=1))return;if(a){a=!1;const U=e.group?e.group[e.group.currentIndex]:e;U.cloneContainer.parentElement.style.transition=null,U.cloneContainer.parentElement.style.transform=null;const _=s.clientX-r,j=Math.abs(_),K=s.clientY-i,G=Math.abs(K);if("touch"===s.pointerType&&G>56&&G>1.1*j)return void closePopupable();if(e.group&&j>3){const Z=Math.max(0,Math.floor((j-window.innerWidth/2)/window.innerWidth));if(_>32)for(let J=0;J<=Z;J++)e.goPrev();else if(_<-32)for(let Q=0;Q<=Z;Q++)e.goNext();return void(e.blocked=!0)}}const p=s.target.closest(".popupable-viewport")&&!n.closest(".popupable-viewport");if(!(p||s.target==n||n.classList.contains("popupable-clone-container")&&s.target===t?.original))return;const c=(p?n.closest("[data-popupable]"):null)||s.target.closest("[data-popupable]");if(!c){if(p)return void closePopupable();if(s.target.closest(".popupable-container"))return;return void(e&&("zoomed"===e.state?e.unzoom():closePopupable()))}if(s.preventDefault(),e?.original===c&&e.popup&&!e.popup.isConnected&&"close"!==e.state)return;const u=++o;e&&closePopupable(),e={transition:{},listeners:[]};const d=e,f=document.createElement("div");f.className="popupable-clones";const m=cloneElement(c),{cloneContainer:b,clone:v,content:h}=m;let g;if(c.dataset.popupableGroup){const ee=document.querySelectorAll(`[data-popupable-group="${c.dataset.popupableGroup}"]`);if(ee.length){g=[];for(const[te,ne]of ee.entries())if(ne===c)g.push(m),g.currentIndex=te,f.append(b);else{const oe=cloneElement(ne);oe.cloneContainer.style.display="none",oe.cloneContainer.classList.add("popupable-clone-extra"),g.push(oe),f.append(oe.cloneContainer)}}}else f.append(b);const y=document.createElement("div");y.className="popupable-container",m.id&&(y.id=m.id);const L=document.createElement("div");let x,w,C,P,E,I,M,z,k,T;L.className="popupable-viewport",h&&(x=document.createElement("div"),x.classList="popupable-content-container");const X={};if(g){m.counter&&(w=document.createElement("div"),w.className="popupable-header",P=document.createElement("div"),P.className="popupable-counter",w.append(P)),m.thumbnails&&(E=document.createElement("div"),E.className="popupable-thumbnails",I=g.map((e,t)=>{const n=new Image;return n.className="popupable-thumbnail",n.src=e.original.currentSrc??e.original.src,n.dataset.thumbnailIndex=t,E.append(n),n})),L.innerHTML=`\n <div class="popupable-prev-container${g.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${g.currentIndex===g.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 ae=L.querySelector(".popupable-next-container"),re=L.querySelector(".popupable-prev-container");let ie,le,se,pe;const ce=!(navigator.maxTouchPoints>0||window.matchMedia("(hover: none)").matches);function A(){ce&&(clearTimeout(ie),pe||(ie=setTimeout(()=>{pe||(ae.classList.add("popupable-nav-inactive"),re.classList.add("popupable-nav-inactive"))},1500)))}function S(){ae.classList.remove("popupable-nav-inactive"),re.classList.remove("popupable-nav-inactive"),A()}async function Y(){const e=g[g.currentIndex];await e.ready,g.currentIndex?re.classList.remove("popupable-disabled"):re.classList.add("popupable-disabled"),g.currentIndex===g.length-1?ae.classList.add("popupable-disabled"):ae.classList.remove("popupable-disabled");for(const[e,t]of g.entries()){const n=e-g.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?y.id=e.id:y.removeAttribute("id"),P&&(P.textContent=`${g.currentIndex+1} / ${g.length}`),I){for(const[e,t]of I.entries())t.classList.toggle("popupable-thumbnail-active",e===g.currentIndex);const e=I[g.currentIndex];requestAnimationFrame(()=>{if(!e||!E?.isConnected)return;const t=getComputedStyle(E),n=parseFloat(t.paddingLeft)||0,o=parseFloat(t.paddingRight)||0,a=E.scrollLeft+n,r=E.scrollLeft+E.clientWidth-o,i=e.offsetLeft,l=i+e.offsetWidth;let s=E.scrollLeft;i<a?s=Math.max(0,i-n):l>r&&(s=l-E.clientWidth+o),s!==E.scrollLeft&&(M?E.scrollTo({left:s,behavior:"smooth"}):E.scrollLeft=s),M=!0})}updateExpandedSize()}if(z=()=>{g.currentIndex>=g.length-1||(g.currentIndex++,Y())},k=()=>{g.currentIndex<=0||(g.currentIndex--,Y())},Y(),ce&&A(),e.listeners.push({target:ae,event:"click",func:()=>z()},{target:re,event:"click",func:()=>k()},{target:document,event:"keydown",func:t=>{if("zoomed"!==e.state)switch(t.key){case"ArrowRight":case"ArrowDown":case"PageDown":case"d":case"s":z();break;case"ArrowLeft":case"ArrowUp":case"PageUp":case"a":case"w":k();break;case"Home":g.currentIndex=0,Y();break;case"End":g.currentIndex=g.length-1,Y();break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":g.currentIndex=Math.min(Math.max(Number(t.key),1)-1,g.length-1),Y()}}},{target:document,event:"wheel",func:t=>{if("zoomed"===e.state)return;const n=performance.now();n-(T||0)<80||(t.deltaY>50?(T=n,z()):t.deltaY<-50&&(T=n,k()))},args:{passive:!0}}),E){let ue,de,fe,me,be,ve,he,ge,ye;function R(){ye&&(cancelAnimationFrame(ye),ye=null)}function B(){if(R(),Math.abs(ge)<.01)return;let e=performance.now();ye=requestAnimationFrame(function t(n){if(!E.isConnected)return void R();const o=E.scrollWidth-E.clientWidth;if(o<=0)return void R();const a=Math.min(32,n-e);e=n;let r=E.scrollLeft+ge*a;r<0&&(r=0),r>o&&(r=o),E.scrollLeft=r,E.scrollLeft<=.1&&ge<0||E.scrollLeft>=o-.1&&ge>0?R():(ge*=Math.pow(.8,a/16.67),Math.abs(ge)<=.002?R():ye=requestAnimationFrame(t))})}e.listeners.push({target:E,event:"pointerdown",func:e=>{if(0!==e.button)return;const t=E.scrollWidth-E.clientWidth;fe=t>0,R(),ue=!0,de=!1,me=e.clientX,be=E.scrollLeft,ve=E.scrollLeft,he=performance.now(),ge=0,fe&&E.classList.add("popupable-thumbnails-dragging"),E.setPointerCapture(e.pointerId)}},{target:E,event:"pointermove",func:e=>{if(!ue)return;const t=e.clientX-me;Math.abs(t)>3&&(de=!0);const n=performance.now(),o=n-he,a=be-t;if(E.scrollLeft=a,o>0){const e=(E.scrollLeft-ve)/o;ge=.65*ge+.35*e,ve=E.scrollLeft,he=n}}},{target:E,event:"pointerup",func:e=>{if(!ue)return;if(ue=!1,fe&&E.classList.remove("popupable-thumbnails-dragging"),E.hasPointerCapture(e.pointerId)&&E.releasePointerCapture(e.pointerId),de)return performance.now()-he>10&&(ge=0),void B();const t=document.elementFromPoint(e.clientX,e.clientY)?.closest?.(".popupable-thumbnail");t&&(g.currentIndex=Number(t.dataset.thumbnailIndex),Y())}},{target:E,event:"pointercancel",func:e=>{ue&&(ue=!1,fe&&E.classList.remove("popupable-thumbnails-dragging"),E.hasPointerCapture(e.pointerId)&&E.releasePointerCapture(e.pointerId),R())}},{target:E,event:"wheel",func:e=>{e.stopPropagation(),e.preventDefault();const t=E.scrollWidth-E.clientWidth;if(t<=0)return;const n=Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX:e.deltaY,o=E.scrollLeft<=.1,a=E.scrollLeft>=t-.1;if(o&&n<0||a&&n>0)return;o&&n>0&&ge<0&&(ge=0),a&&n<0&&ge>0&&(ge=0);ge=(ge||0)+.015*n,ye||B()},args:{passive:!1}})}ce&&(e.listeners.push({target:ae,event:"pointerenter",func:()=>{pe=!0,S()}},{target:re,event:"pointerenter",func:()=>{pe=!0,S()}},{target:ae,event:"pointerleave",func:()=>{pe=!1,A()}},{target:re,event:"pointerleave",func:()=>{pe=!1,A()}}),e.listeners.push({target:y,event:"pointermove",func:t=>{if("zoomed"!==e.state)return null==le||null==se?(le=t.clientX,void(se=t.clientY)):void(Math.abs(t.clientX-le)<3&&Math.abs(t.clientY-se)<3||(le=t.clientX,se=t.clientY,S()))},args:{passive:!0}}));for(const Le of g)Le.content&&x&&x.append(Le.content)}else h&&x.append(h);const N={counter:!!P,content:!!x,thumbnails:!!E},F=m.order.top.filter(e=>N[e]),D=m.order.bottom.filter(e=>N[e]);function W(e,t){e&&("counter"===t&&P?(X[e===w?"counterTop":"counterBottom"]=!0,e.append(P)):"content"===t&&x?(X[e===w?"contentTop":"contentBottom"]=!0,e.append(x)):"thumbnails"===t&&E&&(X[e===w?"thumbnailsTop":"thumbnailsBottom"]=!0,e.append(E)))}F.length&&(w=document.createElement("div"),w.className="popupable-header"),D.length&&(C=document.createElement("div"),C.className="popupable-footer");for(const xe of F)W(w,xe);for(const we of D)W(C,we);if(w&&L.append(w),C&&L.append(C),y.append(f,L),Object.assign(d,m,{popup:y,group:g,contentContainer:x,thumbnailsContainer:E,orderPlacement:X,goNext:z,goPrev:k}),await d.ready,u!==o||e!==d||"close"===d.state)return;setCloneToOriginalRect(b,c),document.body.append(y),c.classList.add("popupable-hide"),disableScroll();const H=getComputedStyle(y);d.transition.duration=1e3*parseFloat(H.transitionDuration)+1e3*parseFloat(H.transitionDelay),y._state=d,requestAnimationFrame(()=>{requestAnimationFrame(()=>{openPopupable(y._state)})});let O,V=0;g&&y.addEventListener("dragstart",e=>e.preventDefault());const q=new Map;function $(e,t,n,o,r=[]){if("open"!==e.state)return;let i=0;const l=t.cloneContainer.parentElement,s=l.style.transform;if(s){const e=s.match(/translateX\((-?\d+(?:\.\d+)?)px\)/);e&&(i=Number(e[1])||0)}const p=Math.abs(i)>.5;a=!1,p?(t.cloneContainer.style.translate="0 0",t.cloneContainer.style.transition="translate var(--popupable-switch-duration), transform 0s",l.style.transition=null,l.style.transform=null,t.cloneContainer.style.translate=`${i}px 0`):(l.style.transition=null,l.style.transform=null),e.state="zoomed",y.classList.add("popupable-locked");let c,u,d=o;const f=new Map;let m,b,v,h,g,x,w,C,P,E,I=!1;const M=t.cloneContainer.getBoundingClientRect(),z=n?.clientX??M.left+M.width/2,k=n?.clientY??M.top+M.height/2;c=(z-M.left)*(1-d),u=(k-M.top)*(1-d);const T=()=>t.cloneContainer.style.transform=`translate(${c}px, ${u}px) scale(${d})`;function X(e,n,o){const a=d;var r;if(r=e,d=Math.min(6,Math.max(1,r)),d===a)return!1;const i=t.cloneContainer.getBoundingClientRect(),l=d/a,s=n-i.left,p=o-i.top;return c+=s*(1-l),u+=p*(1-l),!0}function A(){if(1===f.size){const e=f.values().next().value;return m=e.id,b=e.x,v=e.y,h=null,g=null,void(x=null)}if(f.size>=2){m=null;const[e,t]=[...f.values()];return h=(e.x+t.x)/2,g=(e.y+t.y)/2,void(x=Math.hypot(t.x-e.x,t.y-e.y))}m=null,b=null,v=null,h=null,g=null,x=null}if(t.cloneContainer.classList.add("popupable-zoomed"),T(),r.length){p||(t.cloneContainer.style.transition="none"),E=!0;for(const e of r)f.set(e.id,{id:e.id,x:e.x,y:e.y}),y.setPointerCapture(e.id);A()}e.unzoom=()=>{e.state="open",y.classList.remove("popupable-locked");for(const e of f.keys())y.hasPointerCapture(e)&&y.releasePointerCapture(e);f.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:y,event:"pointerdown",func:e=>{0===e.button&&(t.cloneContainer.style.transition="none",y.setPointerCapture(e.pointerId),f.set(e.pointerId,{id:e.pointerId,x:e.clientX,y:e.clientY}),1===f.size?(w=e.target,C=e.clientX,P=e.clientY,E=!1):E=!0,A(),e.preventDefault())}},{target:y,event:"pointermove",func:e=>{const t=f.get(e.pointerId);if(t){if(t.x=e.clientX,t.y=e.clientY,!E&&(Math.abs(e.clientX-C)>3||Math.abs(e.clientY-P)>3)&&(E=!0),1===f.size&&m===e.pointerId){const t=e.clientX-b,n=e.clientY-v;if(!t&&!n)return;return c+=t,u+=n,b=e.clientX,v=e.clientY,void T()}if(f.size>=2){const[e,t]=[...f.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(!x)return h=n,g=o,void(x=a);c+=n-h,u+=o-g,X(d*(a/x),n,o),I=!0,h=n,g=o,x=a,T()}}}},{target:y,event:"pointerup",func:n=>{if(f.has(n.pointerId)){if(f.delete(n.pointerId),y.hasPointerCapture(n.pointerId)&&y.releasePointerCapture(n.pointerId),I&&d<=1.01&&f.size<2)return e.skipOpenTouchPointerUps=f.size,void e.unzoom();if(!f.size&&!E&&Math.abs(n.clientX-C)<3&&Math.abs(n.clientY-P)<3){if(w?.closest?.(".popupable-clone-container")===t.cloneContainer||(w===y||w===L))return void e.unzoom()}A()}}},{target:y,event:"pointercancel",func:e=>{f.has(e.pointerId)&&(f.delete(e.pointerId),y.hasPointerCapture(e.pointerId)&&y.releasePointerCapture(e.pointerId),A())}},{target:y,event:"wheel",func:e=>{t.cloneContainer.style.transition="none",X(d*Math.exp(.002*-e.deltaY),e.clientX,e.clientY)&&T()},args:{passive:!0}}];for(const t of e.zoomListeners)t.target.addEventListener(t.event,t.func,t.args)}e.listeners.push({target:y,event:"pointerdown",func:e=>{if("open"!==y._state.state||"touch"!==e.pointerType)return;const t=y._state,n=t.group?t.group[t.group.currentIndex]:t;e.target.closest(".popupable-clone-container")===n.cloneContainer&&(q.set(e.pointerId,{id:e.pointerId,x:e.clientX,y:e.clientY}),q.size>=2&&($(t,n,e,1,[...q.values()].slice(0,2)),q.clear(),e.preventDefault()))}},{target:y,event:"pointermove",func:e=>{const t=q.get(e.pointerId);t&&(t.x=e.clientX,t.y=e.clientY)}},{target:y,event:"pointerup",func:e=>{q.delete(e.pointerId)}},{target:y,event:"pointercancel",func:e=>{q.delete(e.pointerId)}}),y.addEventListener("pointerup",t=>{if("zoomed"===y._state.state)return;if("touch"===t.pointerType&&l>1)return;if("touch"===t.pointerType&&(y._state.skipOpenTouchPointerUps||0)>0)return void y._state.skipOpenTouchPointerUps--;const o=performance.now(),a=null!=t.target.closest(".popupable-next-container, .popupable-prev-container");if(O&&o-V<250)return void(V=o);if(a?(O=!0,V=o):(O=!1,V=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=y._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"))?$(r,i,t,2):closePopupable()})})}),document.addEventListener("pointercancel",e=>{"touch"===e.pointerType&&(l=Math.max(0,l-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)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "popupable",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A lightweight, zero-dependency lightbox library using modern JavaScript and CSS.",
5
5
  "author": "Ewan Howell <ewanhowell5195>",
6
6
  "license": "MIT",