popupable 1.0.2 → 1.1.0
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 +1 -0
- package/dist/popupable.min.css +3 -3
- package/dist/popupable.min.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@ A lightweight, zero-dependency lightbox library using modern JavaScript and CSS.
|
|
|
4
4
|
Just add `data-popupable` to any image!
|
|
5
5
|
|
|
6
6
|
[](https://www.npmjs.com/package/popupable)
|
|
7
|
+
[](https://www.jsdelivr.com/package/npm/popupable)
|
|
7
8
|
[](https://opensource.org/licenses/MIT)
|
|
8
9
|
|
|
9
10
|
[**Live Demo**](https://popupable.ewanhowell.com/)
|
package/dist/popupable.min.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* popupable
|
|
3
|
-
* Version : 1.0
|
|
3
|
+
* Version : 1.1.0
|
|
4
4
|
* License : MIT
|
|
5
|
-
* Copyright:
|
|
5
|
+
* Copyright: 2026 Ewan Howell
|
|
6
6
|
*/
|
|
7
|
-
@property --popupable-screen-padding{syntax:"<length>";inherits:true;initial-value:40px}@property --popupable-background{syntax:"<color>";inherits:true;initial-value:#000B}@property --popupable-ui-background{syntax:"<color>";inherits:true;initial-value:#0008}@property --popupable-blur{syntax:"<length>";inherits:true;initial-value:6px}@property --popupable-open-duration{syntax:"<time>";inherits:true;initial-value:.25s}@property --popupable-switch-duration{syntax:"<time>";inherits:true;initial-value:.25s}[data-popupable],[data-popupable] *{cursor:pointer!important}.popupable-hide{visibility:hidden!important}.popupable-container{position:fixed;inset:0;transition:background var(--popupable-open-duration),backdrop-filter var(--popupable-open-duration);z-index:2147483646;user-select:none;pointer-events:none}.popupable-container.popupable-active{z-index:2147483647;background:var(--popupable-background);backdrop-filter:blur(var(--popupable-blur))}.popupable-container>*{pointer-events:none}.popupable-viewport{position:fixed;left:var(--popupable-vv-left,0);top:var(--popupable-vv-top,0);width:calc(var(--popupable-vv-width,100vw) * var(--popupable-vv-scale,1));height:calc(var(--popupable-vv-height,100vh) * var(--popupable-vv-scale,1));transform-origin:top left;transform:scale(var(--popupable-vv-ui-scale,1));pointer-events:none!important}.popupable-container *{box-sizing:border-box}.popupable-container.popupable-open,.popupable-container.popupable-open>*{pointer-events:initial}.popupable-clones{transition:transform var(--popupable-switch-duration)}.popupable-clone-container{position:fixed;transition:all var(--popupable-open-duration);pointer-events:initial;overflow:hidden;transform:translateX(calc(var(--popupable-view-width) * var(--popupable-offset-multiplier)));transform-origin:0 0}.popupable-clone-container.popupable-transparent::before{content:"";position:absolute;inset:0;background-image:conic-gradient(#313131 .25turn,#1e1e1e .25turn .5turn,#313131 .5turn .75turn,#1e1e1e .75turn);background-size:32px 32px;background-attachment:fixed;z-index:-1;opacity:0;transition:opacity var(--popupable-open-duration);image-rendering:pixelated}.popupable-container.popupable-active .popupable-clone-container{border-radius:0!important}.popupable-container.popupable-active .popupable-clone-container.popupable-transparent::before{opacity:1}.popupable-container.popupable-open .popupable-clone-container{transition:transform var(--popupable-switch-duration),translate var(--popupable-switch-duration)}.popupable-clone,.popupable-clone-layer{width:100%;height:100%;position:absolute;inset:0;transition:opacity var(--popupable-open-duration)}.popupable-clone-layer{opacity:0;object-fit:cover}.popupable-container.popupable-open .popupable-clone:not(:last-child){opacity:0}.popupable-container.popupable-active .popupable-clone-layer{opacity:1}.popupable-button{width:40px;height:40px;display:flex;align-items:center;justify-content:center;transition:opacity var(--popupable-open-duration),transform var(--popupable-open-duration);cursor:pointer;position:relative}.popupable-button::before{content:"";position:absolute;inset:0;opacity:.5;background:var(--popupable-ui-background);transition:opacity .25s;border-radius:50%}.popupable-button svg{width:24px;height:24px;z-index:1}.popupable-container.popupable-open .popupable-button{transition:background .25s,opacity var(--popupable-open-duration),transform .25s}.popupable-button:hover::before,.popupable-next-container:hover .popupable-button::before,.popupable-prev-container:hover .popupable-button::before{opacity:1}.popupable-next-container,.popupable-prev-container{position:absolute;top:50%;transform:translateY(-50%);padding:40px;cursor:pointer;z-index:1;pointer-events:auto}.popupable-next-container{right:calc(var(--popupable-screen-padding)/ 2)}.popupable-prev-container{left:calc(var(--popupable-screen-padding)/ 2)}.popupable-nav-button{opacity:0}.popupable-next{transform:translateX(40px)}.popupable-prev{transform:translateX(-40px)}.popupable-container.popupable-active .popupable-nav-button{opacity:1;transform:translateX(0)}.popupable-next-container:hover .popupable-button{transform:translateX(4px)}.popupable-prev-container:hover .popupable-button{transform:translateX(-4px)}.popupable-locked .popupable-next-container,.popupable-locked .popupable-prev-container,.popupable-next-container.popupable-disabled,.popupable-next-container.popupable-nav-inactive,.popupable-prev-container.popupable-disabled,.popupable-prev-container.popupable-nav-inactive{pointer-events:none}.popupable-locked .popupable-next-container .popupable-next,.popupable-next-container.popupable-disabled .popupable-next,.popupable-next-container.popupable-nav-inactive .popupable-next{transform:translateX(40px);opacity:0}.popupable-locked .popupable-prev-container .popupable-prev,.popupable-prev-container.popupable-disabled .popupable-prev,.popupable-prev-container.popupable-nav-inactive .popupable-prev{transform:translateX(-40px);opacity:0}.popupable-container:not(.popupable-active) .popupable-clone-container:not(.popupable-clone-extra){transform:initial}.popupable-container:not(.popupable-active) .popupable-clone-extra{opacity:0;scale:0.75}.popupable-footer,.popupable-header{position:absolute;top:0;left:0;right:0;opacity:0;transition:opacity var(--popupable-open-duration),transform var(--popupable-open-duration);transform:translateY(-40px);color:#fff;background:var(--popupable-ui-background);pointer-events:auto}.popupable-footer{top:initial;bottom:0;transform:translateY(40px)}.popupable-container.popupable-active:not(.popupable-locked) .popupable-footer,.popupable-container.popupable-active:not(.popupable-locked) .popupable-header{opacity:1;transform:initial}.popupable-counter{padding:10px;text-align:center}.popupable-footer>*+*,.popupable-header>*+*{border-top:1px solid #fff3}.popupable-content-container{display:grid;align-items:flex-end;transition:height var(--popupable-switch-duration);overflow:hidden;position:relative}.popupable-thumbnails{display:flex;gap:10px;padding:10px;justify-content:safe center;overflow:hidden;scrollbar-width:none;touch-action:pan-x}.popupable-thumbnails.popupable-thumbnails-dragging{cursor:grabbing}.popupable-thumbnail{width:64px;height:64px;object-fit:cover;opacity:.65;cursor:pointer;transition:opacity .2s,outline-color .2s;outline:2px solid #0000;outline-offset:-2px;flex:0 0 auto}.popupable-thumbnail:hover{opacity:1}.popupable-thumbnail.popupable-thumbnail-active{opacity:1;outline-color:#fffa}.popupable-content{grid-column:1;grid-row:1;text-align:center;padding:16px;color:#fff;display:flex;flex-direction:column;gap:8px;user-select:text;transition:opacity var(--popupable-switch-duration),transform var(--popupable-switch-duration);position:absolute;bottom:0;left:50%;transform:translateX(-50%);max-width:100%;width:max-content}.popupable-title{font-size:32px;font-weight:600}.popupable-content-before{pointer-events:none;opacity:0;transform:translateX(calc(-50% - 80px))}.popupable-content-after{pointer-events:none;opacity:0;transform:translateX(calc(-50% + 80px))}.popupable-zoomable{cursor:zoom-in}.popupable-zoomed{cursor:zoom-out;touch-action:none}@media (max-width:768px){:root{--popupable-screen-padding:14px}.popupable-button{width:42px;height:42px}.popupable-next-container,.popupable-prev-container{padding:36px}.popupable-button svg{width:25px;height:25px}.popupable-counter{padding:8px}.popupable-content{padding:14px;gap:6px}.popupable-title{font-size:28px}.popupable-thumbnail{width:48px;height:48px}}
|
|
7
|
+
@property --popupable-screen-padding{syntax:"<length>";inherits:true;initial-value:40px}@property --popupable-background{syntax:"<color>";inherits:true;initial-value:#000B}@property --popupable-ui-background{syntax:"<color>";inherits:true;initial-value:#0008}@property --popupable-blur{syntax:"<length>";inherits:true;initial-value:6px}@property --popupable-open-duration{syntax:"<time>";inherits:true;initial-value:.25s}@property --popupable-switch-duration{syntax:"<time>";inherits:true;initial-value:.25s}[data-popupable],[data-popupable] *{cursor:pointer!important}.popupable-hide{visibility:hidden!important}.popupable-loading,.popupable-loading *{cursor:wait!important}.popupable-container{position:fixed;inset:0;transition:background var(--popupable-open-duration),backdrop-filter var(--popupable-open-duration);z-index:2147483646;user-select:none;pointer-events:none}.popupable-container.popupable-active{z-index:2147483647;background:var(--popupable-background);backdrop-filter:blur(var(--popupable-blur))}.popupable-container>*{pointer-events:none}.popupable-viewport{position:fixed;left:var(--popupable-vv-left,0);top:var(--popupable-vv-top,0);width:calc(var(--popupable-vv-width,100vw) * var(--popupable-vv-scale,1));height:calc(var(--popupable-vv-height,100vh) * var(--popupable-vv-scale,1));transform-origin:top left;transform:scale(var(--popupable-vv-ui-scale,1));pointer-events:none!important}.popupable-container *{box-sizing:border-box}.popupable-container.popupable-open,.popupable-container.popupable-open>*{pointer-events:initial}.popupable-clones{transition:transform var(--popupable-switch-duration)}.popupable-clone-container{position:fixed;transition:all var(--popupable-open-duration);pointer-events:initial;overflow:hidden;transform:translateX(calc(var(--popupable-view-width) * var(--popupable-offset-multiplier)));transform-origin:0 0}.popupable-clone-container.popupable-transparent::before{content:"";position:absolute;inset:0;background-image:conic-gradient(#313131 .25turn,#1e1e1e .25turn .5turn,#313131 .5turn .75turn,#1e1e1e .75turn);background-size:32px 32px;background-attachment:fixed;z-index:-1;opacity:0;transition:opacity var(--popupable-open-duration);image-rendering:pixelated}.popupable-container.popupable-active .popupable-clone-container{border-radius:0!important}.popupable-container.popupable-active .popupable-clone-container.popupable-transparent::before{opacity:1}.popupable-container.popupable-open .popupable-clone-container{transition:transform var(--popupable-switch-duration),translate var(--popupable-switch-duration)}.popupable-clone,.popupable-clone-layer{width:100%;height:100%;position:absolute;inset:0;transition:opacity var(--popupable-open-duration)}.popupable-clone-layer{opacity:0;object-fit:cover}.popupable-container.popupable-open .popupable-clone:not(:last-child){opacity:0}.popupable-container.popupable-active .popupable-clone-layer{opacity:1}.popupable-button{width:40px;height:40px;display:flex;align-items:center;justify-content:center;transition:opacity var(--popupable-open-duration),transform var(--popupable-open-duration);cursor:pointer;position:relative}.popupable-button::before{content:"";position:absolute;inset:0;opacity:.5;background:var(--popupable-ui-background);transition:opacity .25s;border-radius:50%}.popupable-button svg{width:24px;height:24px;z-index:1}.popupable-container.popupable-open .popupable-button{transition:background .25s,opacity var(--popupable-open-duration),transform .25s}.popupable-button:hover::before,.popupable-next-container:hover .popupable-button::before,.popupable-prev-container:hover .popupable-button::before{opacity:1}.popupable-next-container,.popupable-prev-container{position:absolute;top:50%;transform:translateY(-50%);padding:40px;cursor:pointer;z-index:1;pointer-events:auto}.popupable-next-container{right:calc(var(--popupable-screen-padding)/ 2)}.popupable-prev-container{left:calc(var(--popupable-screen-padding)/ 2)}.popupable-nav-button{opacity:0}.popupable-next{transform:translateX(40px)}.popupable-prev{transform:translateX(-40px)}.popupable-container.popupable-active .popupable-nav-button{opacity:1;transform:translateX(0)}.popupable-next-container:hover .popupable-button{transform:translateX(4px)}.popupable-prev-container:hover .popupable-button{transform:translateX(-4px)}.popupable-locked .popupable-next-container,.popupable-locked .popupable-prev-container,.popupable-next-container.popupable-disabled,.popupable-next-container.popupable-nav-inactive,.popupable-prev-container.popupable-disabled,.popupable-prev-container.popupable-nav-inactive{pointer-events:none}.popupable-locked .popupable-next-container .popupable-next,.popupable-next-container.popupable-disabled .popupable-next,.popupable-next-container.popupable-nav-inactive .popupable-next{transform:translateX(40px);opacity:0}.popupable-locked .popupable-prev-container .popupable-prev,.popupable-prev-container.popupable-disabled .popupable-prev,.popupable-prev-container.popupable-nav-inactive .popupable-prev{transform:translateX(-40px);opacity:0}.popupable-container:not(.popupable-active) .popupable-clone-container:not(.popupable-clone-extra){transform:initial}.popupable-container:not(.popupable-active) .popupable-clone-extra{opacity:0;scale:0.75}.popupable-footer,.popupable-header{position:absolute;top:0;left:0;right:0;opacity:0;transition:opacity var(--popupable-open-duration),transform var(--popupable-open-duration);transform:translateY(-40px);color:#fff;background:var(--popupable-ui-background);pointer-events:auto}.popupable-footer{top:initial;bottom:0;transform:translateY(40px)}.popupable-container.popupable-active:not(.popupable-locked) .popupable-footer,.popupable-container.popupable-active:not(.popupable-locked) .popupable-header{opacity:1;transform:initial}.popupable-counter{padding:10px;text-align:center}.popupable-footer>*+*,.popupable-header>*+*{border-top:1px solid #fff3}.popupable-content-container{display:grid;align-items:flex-end;transition:height var(--popupable-switch-duration);overflow:hidden;position:relative}.popupable-thumbnails{display:flex;gap:10px;padding:10px;justify-content:safe center;overflow:hidden;scrollbar-width:none;touch-action:pan-x}.popupable-thumbnails.popupable-thumbnails-dragging{cursor:grabbing}.popupable-thumbnail{width:64px;height:64px;object-fit:cover;opacity:.65;cursor:pointer;transition:opacity .2s,outline-color .2s;outline:2px solid #0000;outline-offset:-2px;flex:0 0 auto}.popupable-thumbnail:hover{opacity:1}.popupable-thumbnail.popupable-thumbnail-active{opacity:1;outline-color:#fffa}.popupable-content{grid-column:1;grid-row:1;text-align:center;padding:16px;color:#fff;display:flex;flex-direction:column;gap:8px;user-select:text;transition:opacity var(--popupable-switch-duration),transform var(--popupable-switch-duration);position:absolute;bottom:0;left:50%;transform:translateX(-50%);max-width:100%;width:max-content}.popupable-title{font-size:32px;font-weight:600}.popupable-content-before{pointer-events:none;opacity:0;transform:translateX(calc(-50% - 80px))}.popupable-content-after{pointer-events:none;opacity:0;transform:translateX(calc(-50% + 80px))}.popupable-zoomable{cursor:zoom-in}.popupable-zoomed{cursor:zoom-out;touch-action:none}@media (max-width:768px){:root{--popupable-screen-padding:14px}.popupable-button{width:42px;height:42px}.popupable-next-container,.popupable-prev-container{padding:36px}.popupable-button svg{width:25px;height:25px}.popupable-counter{padding:8px}.popupable-content{padding:14px;gap:6px}.popupable-title{font-size:28px}.popupable-thumbnail{width:48px;height:48px}}
|
package/dist/popupable.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* popupable
|
|
3
|
-
* Version : 1.0
|
|
3
|
+
* Version : 1.1.0
|
|
4
4
|
* License : MIT
|
|
5
|
-
* Copyright:
|
|
5
|
+
* Copyright: 2026 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)&&(!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)}
|
|
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(r.classList.remove("popupable-loading"),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),g=Math.max(0,n-b-v-2*l);let h=s,y=h/c;if(y>d&&(y=d,h=y*c),y>g&&(y=g,h=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/h,t/y);a<1&&(h*=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-h)/2+"px",t.cloneContainer.style.width=h+"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.decode().catch(()=>{}))),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 j=e.group?e.group[e.group.currentIndex]:e;j.cloneContainer.parentElement.style.transition=null,j.cloneContainer.parentElement.style.transform=null;const K=p.clientX-i,G=Math.abs(K),Z=p.clientY-l,J=Math.abs(Z);if("touch"===p.pointerType&&J>56&&J>1.1*G)return void closePopupable();if(e.group&&G>a){const Q=Math.max(0,Math.floor((G-window.innerWidth/2)/window.innerWidth));if(K>32)for(let ee=0;ee<=Q;ee++)e.goPrev();else if(K<-32)for(let te=0;te<=Q;te++)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:g,content:h}=b;let y;if(u.dataset.popupableGroup){const ne=document.querySelectorAll(`[data-popupable-group="${u.dataset.popupableGroup}"]`);if(ne.length){y=[];for(const[oe,ae]of ne.entries())if(ae===u)y.push(b),y.currentIndex=oe,m.append(v);else{const re=cloneElement(ae);re.cloneContainer.style.display="none",re.cloneContainer.classList.add("popupable-clone-extra"),y.push(re),m.append(re.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",h&&(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 ie=x.querySelector(".popupable-next-container"),le=x.querySelector(".popupable-prev-container");let se,pe,ce,ue;const de=!(navigator.maxTouchPoints>0||window.matchMedia("(hover: none)").matches);function S(){de&&(clearTimeout(se),ue||(se=setTimeout(()=>{ue||(ie.classList.add("popupable-nav-inactive"),le.classList.add("popupable-nav-inactive"))},1500)))}function Y(){ie.classList.remove("popupable-nav-inactive"),le.classList.remove("popupable-nav-inactive"),S()}async function R(){const e=y[y.currentIndex];await e.ready,y.currentIndex?le.classList.remove("popupable-disabled"):le.classList.add("popupable-disabled"),y.currentIndex===y.length-1?ie.classList.add("popupable-disabled"):ie.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(),de&&S(),e.listeners.push({target:ie,event:"click",func:()=>k()},{target:le,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 fe,me,be,ve,ge,he,ye,Le,xe;function B(){xe&&(cancelAnimationFrame(xe),xe=null)}function N(){if(B(),Math.abs(Le)<.01)return;let e=performance.now();xe=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+Le*a;r<0&&(r=0),r>o&&(r=o),I.scrollLeft=r,I.scrollLeft<=.1&&Le<0||I.scrollLeft>=o-.1&&Le>0?B():(Le*=Math.pow(.8,a/16.67),Math.abs(Le)<=.002?B():xe=requestAnimationFrame(t))})}e.listeners.push({target:I,event:"pointerdown",func:e=>{if(0!==e.button)return;const t=I.scrollWidth-I.clientWidth;be=t>0,B(),fe=!0,me=!1,ve=e.clientX,ge=I.scrollLeft,he=I.scrollLeft,ye=performance.now(),Le=0,be&&I.classList.add("popupable-thumbnails-dragging"),I.setPointerCapture(e.pointerId)}},{target:I,event:"pointermove",func:e=>{if(!fe)return;const t=e.clientX-ve;Math.abs(t)>a&&(me=!0);const n=performance.now(),o=n-ye,r=ge-t;if(I.scrollLeft=r,o>0){const e=(I.scrollLeft-he)/o;Le=.65*Le+.35*e,he=I.scrollLeft,ye=n}}},{target:I,event:"pointerup",func:e=>{if(!fe)return;if(fe=!1,be&&I.classList.remove("popupable-thumbnails-dragging"),I.hasPointerCapture(e.pointerId)&&I.releasePointerCapture(e.pointerId),me)return performance.now()-ye>10&&(Le=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=>{fe&&(fe=!1,be&&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&&Le<0&&(Le=0),a&&n<0&&Le>0&&(Le=0);Le=(Le||0)+.015*n,xe||N()},args:{passive:!1}})}de&&(e.listeners.push({target:ie,event:"pointerenter",func:()=>{ue=!0,Y()}},{target:le,event:"pointerenter",func:()=>{ue=!0,Y()}},{target:ie,event:"pointerleave",func:()=>{ue=!1,S()}},{target:le,event:"pointerleave",func:()=>{ue=!1,S()}}),e.listeners.push({target:L,event:"pointermove",func:t=>{if("zoomed"!==e.state)return null==pe||null==ce?(pe=t.clientX,void(ce=t.clientY)):void(Math.abs(t.clientX-pe)<a&&Math.abs(t.clientY-ce)<a||(pe=t.clientX,ce=t.clientY,Y()))},args:{passive:!0}}));for(const we of y)we.content&&w&&w.append(we.content)}else h&&w.append(h);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 Ce of D)H(C,Ce);for(const Pe of W)H(P,Pe);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});const O=setTimeout(()=>{d===o&&u.classList.add("popupable-loading")},250);if(await f.ready,clearTimeout(O),u.classList.remove("popupable-loading"),d!==o||e!==f||"close"===f.state)return;setCloneToOriginalRect(v,u),document.body.append(L),u.classList.add("popupable-hide"),disableScroll();const V=getComputedStyle(L);f.transition.duration=1e3*parseFloat(V.transitionDuration)+1e3*parseFloat(V.transitionDelay),L._state=f,requestAnimationFrame(()=>{requestAnimationFrame(()=>{openPopupable(L._state)})});let q,$=0;y&&L.addEventListener("dragstart",e=>e.preventDefault());const U=new Map;function _(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,g,h,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,g=e.y,h=null,y=null,void(w=null)}if(m.size>=2){b=null;const[e,t]=[...m.values()];return h=(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,g=null,h=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-g;if(!t&&!n)return;return u+=t,d+=n,v=e.clientX,g=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 h=n,y=o,void(w=a);u+=n-h,d+=o-y,A(f*(a/w),n,o),M=!0,h=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&&(U.set(e.pointerId,{id:e.pointerId,x:e.clientX,y:e.clientY}),U.size>=2&&(_(t,n,e,1,[...U.values()].slice(0,2)),U.clear(),e.preventDefault()))}},{target:L,event:"pointermove",func:e=>{const t=U.get(e.pointerId);t&&(t.x=e.clientX,t.y=e.clientY)}},{target:L,event:"pointerup",func:e=>{U.delete(e.pointerId)}},{target:L,event:"pointercancel",func:e=>{U.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(q&&o-$<250)return void($=o);if(a?(q=!0,$=o):(q=!1,$=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"))?_(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)}
|