vistaview 0.3.4 → 0.3.5

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.
@@ -1,16 +1,16 @@
1
- (function(w,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(w=typeof globalThis<"u"?globalThis:w||self,y(w.VistaView={}))})(this,(function(w){"use strict";var st=Object.defineProperty;var ot=(w,y,C)=>y in w?st(w,y,{enumerable:!0,configurable:!0,writable:!0,value:C}):w[y]=C;var p=(w,y,C)=>ot(w,typeof y!="symbol"?y+"":y,C);function y(s){const t=getComputedStyle(s),e=s.getBoundingClientRect();return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow,top:e.top,left:e.left,width:e.width,height:e.height,naturalWidth:s.naturalWidth,naturalHeight:s.naturalHeight}}let C=null;function Y(){return C||(window.trustedTypes||(window.trustedTypes={createPolicy:(s,t)=>t}),C=window.trustedTypes.createPolicy("vistaView-policy",{createHTML:s=>s,createScript:()=>{throw new Error("Not implemented")},createScriptURL:()=>{throw new Error("Not implemented")}}),C)}function H(s){const e=Y().createHTML(s),n=document.createElement("template");n.innerHTML=e;const i=n.content;return n.remove(),i}function T(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function W(s){const e=window.getComputedStyle(s).objectFit||"",{width:n,height:i}=s.getBoundingClientRect(),o=s.naturalWidth,l=s.naturalHeight;if(!e)return{width:n,height:i};if(!o||!l)return{width:n,height:i};const a=o/l,r=n/i;switch(e){case"fill":return{width:n,height:i};case"none":return{width:o,height:l};case"contain":return a>r?{width:n,height:n/a}:{width:i*a,height:i};case"cover":return a<r?{width:n,height:n/a}:{width:i*a,height:i};case"scale-down":{const h={width:o,height:l},c=a>r?{width:n,height:n/a}:{width:i*a,height:i};return c.width<=h.width&&c.height<=h.height?c:h}}return{width:n,height:i}}function S(s){const t=window.innerWidth,e=window.innerHeight,n=s.naturalWidth,i=s.naturalHeight;if(!n||!i)throw console.error("Error",s),new Error("Image natural dimensions are zero");if(n<t&&i<e)return{width:n,height:i};const o=n/i,l=t/e;let a,r;return o>l?(a=t,r=t/o):(r=e,a=e*o),{width:a,height:r}}function q(s,t){const e=window.innerHeight,n=window.innerWidth,i=s,o=t,l=Math.max(0,(i-n)/2)+n/2,a=Math.max(0,(o-e)/2)+e/2,r=-l,h=-a;return{maxDiffX:l,minDiffY:h,maxDiffY:a,minDiffX:r}}const U='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',j='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',N='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',K='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',G='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',J='<svg viewBox="0 0 24 24"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';function k(){return{name:"download",icon:J,onClick:async s=>{var o;const t=await fetch(s.src),e=await t.blob(),n=t.url,i=document.createElement("a");i.href=URL.createObjectURL(e),i.download=((o=n.split("/").pop())==null?void 0:o.split("?")[0].split("#")[0])||"download",document.body.appendChild(i),i.click(),document.body.removeChild(i)}}}function Q(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${N}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${K}</button>`;case"close":return`<button class="vistaview-close-btn">${G}</button>`;case"indexDisplay":return'<div class="vistaview-index-display"></div>';case"description":return'<div class="vistaview-description"></div>';default:return""}return`<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`}function O(s,t){var c,d;const e=s.imageElm?getComputedStyle(s.imageElm):null,n=(e==null?void 0:e.objectFit)||"",i=((c=s.imageElm)==null?void 0:c.naturalWidth)||"",o=((d=s.imageElm)==null?void 0:d.naturalHeight)||"",l=(e==null?void 0:e.width)||"",a=(e==null?void 0:e.height)||"",r=document.createElement("div");r.className="vistaview-item",r.dataset.vistaviewPos=`${t!==void 0?t:""}`,r.dataset.vistaviewIndex=s.index.toString();const h=H(`<img class="vistaview-image-lowres"
2
- style="${n?`object-fit:${n};`:""}${l?`width:${l};`:""}${a?`height:${a};`:""}"
1
+ (function(p,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(p=typeof globalThis<"u"?globalThis:p||self,E(p.VistaView={}))})(this,(function(p){"use strict";var at=Object.defineProperty;var lt=(p,E,P)=>E in p?at(p,E,{enumerable:!0,configurable:!0,writable:!0,value:P}):p[E]=P;var f=(p,E,P)=>lt(p,typeof E!="symbol"?E+"":E,P);function E(s){const t=getComputedStyle(s),e=s.getBoundingClientRect();return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow,top:e.top,left:e.left,width:e.width,height:e.height,naturalWidth:s.naturalWidth,naturalHeight:s.naturalHeight}}let P=null;function j(){return P||(window.trustedTypes||(window.trustedTypes={createPolicy:(s,t)=>t}),P=window.trustedTypes.createPolicy("vistaView-policy",{createHTML:s=>s,createScript:()=>{throw new Error("Not implemented")},createScriptURL:()=>{throw new Error("Not implemented")}}),P)}function T(s){const e=j().createHTML(s),n=document.createElement("template");n.innerHTML=e;const i=n.content;return n.remove(),i}function W(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function q(s){const e=window.getComputedStyle(s).objectFit||"",{width:n,height:i}=s.getBoundingClientRect(),o=s.naturalWidth,h=s.naturalHeight;if(!e)return{width:n,height:i};if(!o||!h)return{width:n,height:i};const r=o/h,a=n/i;switch(e){case"fill":return{width:n,height:i};case"none":return{width:o,height:h};case"contain":return r>a?{width:n,height:n/r}:{width:i*r,height:i};case"cover":return r<a?{width:n,height:n/r}:{width:i*r,height:i};case"scale-down":{const c={width:o,height:h},l=r>a?{width:n,height:n/r}:{width:i*r,height:i};return l.width<=c.width&&l.height<=c.height?l:c}}return{width:n,height:i}}function $(s){const t=window.innerWidth,e=window.innerHeight,n=s.naturalWidth,i=s.naturalHeight;if(!n||!i)throw console.error("Error",s),new Error("Image natural dimensions are zero");if(n<t&&i<e)return{width:n,height:i};const o=n/i,h=t/e;let r,a;return o>h?(r=t,a=t/o):(a=e,r=e*o),{width:r,height:a}}function k(s,t){const e=window.innerHeight,n=window.innerWidth,i=s,o=t,h=Math.max(0,(i-n)/2)+n/2,r=Math.max(0,(o-e)/2)+e/2,a=-h,c=-r;return{maxDiffX:h,minDiffY:c,maxDiffY:r,minDiffX:a}}const N='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',K='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',G='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',J='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',Q='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',tt='<svg viewBox="0 0 24 24"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';function O(){return{name:"download",icon:tt,onClick:async s=>{var o;const t=await fetch(s.src),e=await t.blob(),n=t.url,i=document.createElement("a");i.href=URL.createObjectURL(e),i.download=((o=n.split("/").pop())==null?void 0:o.split("?")[0].split("#")[0])||"download",document.body.appendChild(i),i.click(),document.body.removeChild(i)}}}function et(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${G}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${J}</button>`;case"close":return`<button class="vistaview-close-btn">${Q}</button>`;case"indexDisplay":return'<div class="vistaview-index-display"></div>';case"description":return'<div class="vistaview-description"></div>';default:return""}return`<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`}function X(s,t){var l,d;const e=s.imageElm?getComputedStyle(s.imageElm):null,n=(e==null?void 0:e.objectFit)||"",i=((l=s.imageElm)==null?void 0:l.naturalWidth)||"",o=((d=s.imageElm)==null?void 0:d.naturalHeight)||"",h=(e==null?void 0:e.width)||"",r=(e==null?void 0:e.height)||"",a=document.createElement("div");a.className="vistaview-item",a.dataset.vistaviewPos=`${t!==void 0?t:""}`,a.dataset.vistaviewIndex=s.index.toString();const c=T(`<img class="vistaview-image-lowres"
2
+ style="${n?`object-fit:${n};`:""}${h?`width:${h};`:""}${r?`height:${r};`:""}"
3
3
  src="${s.thumb||s.src}"
4
4
  alt="${s.alt||""}"
5
5
  ${i?`width="${i}"`:""}
6
6
  ${o?`height="${o}"`:""}
7
7
  />
8
- <img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return r.appendChild(h),r}function tt({controls:s,isReducedMotion:t}){const e=i=>i?i.map(Q).join(""):"";return H(`<div class="vistaview-root${t?" vistaview--reduced-motion":""}" id="vistaview-root">
8
+ <img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return a.appendChild(c),a}function it({controls:s,isReducedMotion:t}){const e=i=>i?i.map(et).join(""):"";return T(`<div class="vistaview-root${t?" vistaview--reduced-motion":""}" id="vistaview-root">
9
9
  <div class="vistaview-container">
10
10
  <div class="vistaview-image-container"></div>
11
11
  <div class="vistaview-top-bar vistaview-ui"><div>${e(s==null?void 0:s.topLeft)}</div><div>${e(s==null?void 0:s.topCenter)}</div><div>${e(s==null?void 0:s.topRight)}</div></div>
12
12
  <div class="vistaview-bottom-bar vistaview-ui"><div>${e(s==null?void 0:s.bottomLeft)}</div><div>${e(s==null?void 0:s.bottomCenter)}</div><div>${e(s==null?void 0:s.bottomRight)}</div></div>
13
- <div class="vistaview-prev-btn vistaview-ui"><button>${U}</button></div>
14
- <div class="vistaview-next-btn vistaview-ui"><button>${j}</button></div>
13
+ <div class="vistaview-prev-btn vistaview-ui"><button>${N}</button></div>
14
+ <div class="vistaview-next-btn vistaview-ui"><button>${K}</button></div>
15
15
  </div>
16
- </div>`)}let $=null,M=null,Z=null;function V(s){A(s);const t=s.imageContainerElm,e=s.elements.length;if(!t)return;let n=0,i=0,o=0,l=0,a=!1;$=r=>{r.preventDefault(),r.stopPropagation(),s.isZoomed===!1&&(a=!0,n=r.pageX,i=r.pageY,o=r.pageX,l=Date.now())},M=r=>{if(r.preventDefault(),r.stopPropagation(),s.isZoomed!==!1||!a)return;const h=r.pageX-n,c=r.pageY-i;o=r.pageX,t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),t.style.setProperty("--vistaview-pointer-diff-y",`${c}px`)},Z=r=>{if(r.preventDefault(),r.stopPropagation(),s.isZoomed!==!1||!a)return;a=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),c=o-n,d=Date.now()-l,v=c/d,u=s.options.touchSpeedThreshold||.7,E=h.find(f=>f.dataset.vistaviewPos==="0"),m=Number(E.dataset.vistaviewIndex),b=s.isReducedMotion;function g(){h[0].removeEventListener("transitionend",g),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(f=>{f.style.transition="",f.style.translate=""})}function x(f){h.forEach(L=>{L.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,L.style.translate=f})}v<-u||v>u?(h[0].addEventListener("transitionend",()=>{s.isReducedMotion=!0,g(),s.view(v<-u?(m+1)%e:(m-1+e)%e,{next:v<-u,prev:v>u}),s.isReducedMotion=b}),x(v<-u?"-100%":"100%")):(h[0].addEventListener("transitionend",g),x("0%"))},t.addEventListener("pointermove",M),t.addEventListener("pointerup",Z),t.addEventListener("pointerdown",$)}function A(s){const t=s.imageContainerElm;t&&(M&&t.removeEventListener("pointermove",M),Z&&t.removeEventListener("pointerup",Z),$&&t.removeEventListener("pointerdown",$))}const X=s=>{V(s)},_=({htmlElements:{to:s},index:{to:t},elements:e})=>{e instanceof NodeList&&t!==null&&(e.forEach(n=>n.style.opacity="1"),e[t].style.opacity="0"),s&&s.forEach(n=>{const i=Number(n.dataset.vistaviewPos);i!==0?(n.style.zIndex="1",n.style.left=100*i+"%"):n.style.zIndex="2"})},B=async({htmlElements:{from:s,to:t},images:{to:e},via:{next:n,prev:i},container:o,options:l,isReducedMotion:a})=>{if(!e)throw new Error("VistaView: images is null in defaultTransition()");if(a)return o.innerHTML="",t.forEach(h=>{o.appendChild(h)}),e[e.length===1?0:Math.floor(e.length/2)];const r=s.filter(h=>h.dataset.vistaviewPos==="0"||(n?h.dataset.vistaviewPos==="1":h.dataset.vistaviewPos==="-1"));return await new Promise(h=>{function c(){o.innerHTML="",t.forEach(d=>{o.appendChild(d)}),h(0)}r[r.length-1].addEventListener("transitionend",c),r.forEach(d=>{d.style.transition=`translate ${l.animationDurationBase*.5}ms ease-out`,d.style.translate=n?"-100%":i?"100%":"0%"})}),e[e.length===1?0:Math.floor(e.length/2)]},F=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),A(s)},R={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.7,preloads:1,keyboardListeners:!0,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",k(),"close"],bottomCenter:["description"]}},I={somethingOpened:null};class et{constructor(t,e){p(this,"options");p(this,"elements");p(this,"isReducedMotion");p(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n;const e=this._value;this._value=t,(n=this._vistaView)==null||n.swap(e,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});p(this,"rootElm",null);p(this,"imageContainerElm",null);p(this,"customControls",{});p(this,"currentImages",null);p(this,"currentItems",null);p(this,"navActive",!0);p(this,"isZoomed",!1);p(this,"onClickElements",[]);p(this,"onResizeHandler",null);p(this,"onKeyDown",null);p(this,"userSetup",_);p(this,"userTransition",B);p(this,"userClose",F);p(this,"userInit",X);p(this,"onZoomedPointerDown",null);p(this,"onZoomedPointerMove",null);p(this,"onZoomedPointerUp",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...R,...e||{},controls:{...R.controls,...(e==null?void 0:e.controls)||{}}},this.options.initFunction&&(this.userInit=this.options.initFunction),this.options.transitionFunction&&(this.userTransition=this.options.transitionFunction),this.options.closeFunction&&(this.userClose=this.options.closeFunction),this.options.initFunction&&(this.userInit=this.options.initFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((n,i)=>{this.onClickElements.push(o=>{o.preventDefault(),this.open(i)}),n.addEventListener("click",this.onClickElements[i])})}async swap(t,e){var h,c;if(!I.somethingOpened||t===e||t===null||this.elements.length===1)return;if(!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:i}=this.getCurrentIndexes(e),o=this.getImages(n),l=o.map((d,v)=>O(d,i[v]));l.forEach((d,v)=>{var m,b;const u=d.querySelector(".vistaview-image-highres"),E=o[v].imageElm;if(u.complete&&u.naturalWidth>0){const{width:g,height:x}=W(E);g&&x&&(u.style.setProperty("--vistaview-fitted-width",`${g}px`),u.style.setProperty("--vistaview-fitted-height",`${x}px`)),u.classList.add("vistaview-image-loaded"),(m=d.querySelector(".vistaview-image-lowres"))==null||m.classList.add("vistaview-image--hidden");const{width:f,height:L}=S(u);u.style.width=`${f}px`,u.style.height=`${L}px`,u.width=u.naturalWidth,u.height=u.naturalHeight,(b=u.parentElement)!=null&&b.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()}}),this.navActive=!1;const a={htmlElements:{from:this.currentItems,to:l},images:{from:this.currentImages,to:o},index:{from:t,to:e},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(a);const r=await this.userTransition(a);this.navActive=!0,this.setInitialDimPos(r),this.currentImages=o,this.currentItems=l,this.loadImages(),this.setCurrentDescription(),(c=(h=this.options).onImageView)==null||c.call(h,a)}setZoomed(t){var e,n,i,o,l,a;if(this.isZoomed!==t){if(this.isZoomed){let r=this.isZoomed;if(r.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((e=r.parentElement)==null||e.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=r.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((i=r.parentElement)==null||i.removeEventListener("pointerup",this.onZoomedPointerUp),this.onZoomedPointerUp=null),r==null||r.style.removeProperty("--pointer-diff-x"),r==null||r.style.removeProperty("--pointer-diff-y"),setTimeout(()=>{r==null||r.classList.remove("vistaview-image--zooming")},500),this.isZoomed=!1,!t)return}if(t){this.isZoomed=t,t.classList.add("vistaview-image--zooming"),t==null||t.style.setProperty("--pointer-diff-x","0px"),t==null||t.style.setProperty("--pointer-diff-y","0px");let r=!1,h=0,c=0,d=0,v=0,u=0,E=0;this.onZoomedPointerDown=m=>{m.preventDefault(),m.stopPropagation(),r=!0,h=m.pageX,c=m.pageY,t.setPointerCapture(m.pointerId)},this.onZoomedPointerMove=m=>{if(!r)return;m.preventDefault(),u=m.pageX-h,E=m.pageY-c;const b=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),g=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:x,minDiffY:f,maxDiffY:L,minDiffX:D}=q(b,g),P=Math.min(x,Math.max(D,d+u)),z=Math.min(L,Math.max(f,v+E));u=P-d,E=z-v,t==null||t.style.setProperty("--pointer-diff-x",`${P}px`),t==null||t.style.setProperty("--pointer-diff-y",`${z}px`)},this.onZoomedPointerUp=m=>{r=!1,t.releasePointerCapture(m.pointerId),d+=u,v+=E,u=0,E=0},(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerdown",this.onZoomedPointerDown),(l=t==null?void 0:t.parentElement)==null||l.addEventListener("pointermove",this.onZoomedPointerMove),(a=t==null?void 0:t.parentElement)==null||a.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var o,l,a,r,h;const t=(o=this.rootElm)==null?void 0:o.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),e=t.width,n=t.height;t.dataset.vistaviewInitialWidth||(t.dataset.vistaviewInitialWidth=e.toString()),t.dataset.vistaviewInitialHeight||(t.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(t);const i=(t.naturalWidth||0)*this.options.maxZoomLevel;if(e&&i&&e<i){const c=Math.min(e+this.options.zoomStep,i);t.style.width=`${c}px`;const d=c/e*n;t.style.height=`${d}px`,(a=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-out-btn"))==null||a.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=c.toString(),t.dataset.vistaviewCurrentHeight=d.toString(),c===i&&((h=(r=this.rootElm)==null?void 0:r.querySelector("button.vistaview-zoom-in-btn"))==null||h.setAttribute("disabled","true"))}}zoomOut(){var l,a,r,h,c;const t=(l=this.rootElm)==null?void 0:l.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),e=t.width,n=t.height,i=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,o=d=>{d.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",o))};if(t.addEventListener("transitionend",o),t.classList.add("vistaview-image--zooming-out"),e&&i&&e>i){const d=Math.max(e-this.options.zoomStep,i);t.style.width=`${d}px`;const v=d/e*n;t.style.height=`${v}px`,(r=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-in-btn"))==null||r.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=d.toString(),t.dataset.vistaviewCurrentHeight=v.toString();const{maxDiffX:u,minDiffY:E,maxDiffY:m,minDiffX:b}=q(d,v);let g=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),x=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");g=Math.min(u,Math.max(b,g)),x=Math.min(m,Math.max(E,x)),t==null||t.style.setProperty("--pointer-diff-x",`${g}px`),t==null||t.style.setProperty("--pointer-diff-y",`${x}px`),d===i&&((c=(h=this.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"))==null||c.setAttribute("disabled","true"),t.removeAttribute("data-vistaview-current-width"),t.removeAttribute("data-vistaview-current-height"),t.removeAttribute("data-vistaview-initial-width"),t.removeAttribute("data-vistaview-initial-height"),this.setZoomed(!1))}}clearZoom(){}getImages(t){return t.map((e,n)=>{const i=this.elements[e];if(i instanceof HTMLElement){const o=i.querySelector("img"),l=i.getAttribute("href")||"",a=i.getAttribute("src")||"",r=i.dataset.vistaviewSrc||l||a||(o==null?void 0:o.src)||"",h=i.dataset.vistaviewAlt||i.getAttribute("alt")||(o==null?void 0:o.alt)||"",c=i.dataset.vistaviewThumb||(o==null?void 0:o.src)||l||a||"";return{index:t[n],src:r,alt:h,thumb:c,imageElm:i instanceof HTMLImageElement?i:o,anchorElm:i instanceof HTMLAnchorElement?i:void 0}}else return{index:t[n],...i}})}setInitialDimPos(t){if(!this.rootElm)return;const e=t.imageElm?y(t.imageElm):void 0,n=t.anchorElm?y(t.anchorElm):void 0,i=(n==null?void 0:n.width)||(e==null?void 0:e.width)||0,o=(n==null?void 0:n.height)||(e==null?void 0:e.height)||0,l=((n==null?void 0:n.left)||(e==null?void 0:e.left)||0)+i/2,a=((n==null?void 0:n.top)||(e==null?void 0:e.top)||0)+o/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",i+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",o+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-left",l+"px"),this.rootElm.style.setProperty("--vistaview-image-border-radius",T(n==null?void 0:n.borderRadius)||T(e==null?void 0:e.borderRadius)||"0px")}updateZoomButtonsVisibility(){var i;const t=(i=this.rootElm)==null?void 0:i.querySelector('[data-vistaview-pos="0"] img.vistaview-image-highres');if(!t)return;const e=this;function n(){var c,d;const o=(c=e.rootElm)==null?void 0:c.querySelector("button.vistaview-zoom-in-btn"),l=(d=e.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"),a=parseInt(t.style.width)||t.width,r=t.naturalWidth*e.options.maxZoomLevel,h=a<r&&r>0;o&&(o.style.display=h?"":"none"),l&&(l.style.display=h?"":"none")}t.complete&&t.naturalWidth>0?n():t.addEventListener("load",n)}loadImages(){if(!this.rootElm)return;this.rootElm.querySelectorAll(".vistaview-image-highres:not(.vistaview-image-loaded)").forEach((e,n)=>{const i=e,l=this.currentImages[n].imageElm,a={w:0,h:0};if(l){const{width:h,height:c}=W(l);a.w=Math.min(l.width,h),a.h=Math.min(l.height,c)}const r=(h=!1)=>()=>{var c;if(a.w&&a.h&&(i.style.width=`${a.w}px`,i.style.height=`${a.h}px`,i.style.setProperty("--vistaview-fitted-width",`${a.w}px`),i.style.setProperty("--vistaview-fitted-height",`${a.h}px`)),i.classList.add("vistaview-image-loaded"),i.width=i.naturalWidth,i.height=i.naturalHeight,h){const{width:d,height:v}=S(i);i.style.width=`${d}px`,i.style.height=`${v}px`}else setTimeout(()=>{const{width:d,height:v}=S(i);i.style.width=`${d}px`,i.style.height=`${v}px`},333);setTimeout(()=>{var d,v;(v=(d=i.parentElement)==null?void 0:d.querySelector(".vistaview-image-lowres"))==null||v.classList.add("vistaview-image--hidden")},500),(c=e.parentElement)!=null&&c.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};i.complete&&i.naturalWidth>0?r(!0)():i.onload=r(!1)})}setIndexDisplay(){this.elements.length!==1&&(this.rootElm.querySelector(".vistaview-index-display").textContent=`${this.currentIndex.value+1} / ${this.elements.length}`)}setCurrentDescription(){this.rootElm.querySelector(".vistaview-description").textContent=(this.currentImages[1]||this.currentImages[0]).alt||""}getCurrentIndexes(t){const e=this.options.preloads,n=this.elements.length,i=n<1||!e?[t]:[...new Set([...Array.from({length:e},(l,a)=>((t-e+a)%n+n)%n),t,...Array.from({length:e},(l,a)=>(t+1+a)%n)])],o=n<1||!e?[0]:i.map((l,a)=>a-Math.floor(i.length/2));return{images:i,positions:o}}setKeyboardListeners(){this.onKeyDown=t=>{switch(t.key){case"ArrowLeft":t.preventDefault(),this.prev();break;case"ArrowRight":t.preventDefault(),this.next();break;case"ArrowUp":t.preventDefault(),this.zoomIn();break;case"ArrowDown":t.preventDefault(),this.zoomOut();break;case"Escape":t.preventDefault(),this.close();break}},window.addEventListener("keydown",this.onKeyDown)}setResizeListeners(){this.onResizeHandler=()=>{var n;const t=this.currentImages[this.currentImages.length===1?0:Math.floor(this.currentImages.length/2)];this.setInitialDimPos(t);const e=(n=this.rootElm)==null?void 0:n.querySelectorAll(".vistaview-image-highres.vistaview-image-loaded");e==null||e.forEach(i=>{const o=i,{width:l,height:a}=S(o);o.classList.contains("vistaview-image--zooming")?(o.dataset.vistaviewInitialWidth=l.toString(),o.dataset.vistaviewInitialHeight=a.toString()):(o.style.width=`${l}px`,o.style.height=`${a}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var l,a,r,h,c,d,v,u,E,m,b,g,x;if(I.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(I.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(tt({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((l=this.rootElm)==null?void 0:l.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw I.somethingOpened=null,new Error("Failed to create VistaView element");const{images:e,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(e);const i=this.currentImages.map((f,L)=>O(f,n[L]));this.currentItems=i;const o={htmlElements:{from:null,to:this.currentItems},images:{from:null,to:this.currentImages},index:{from:null,to:t},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(o),this.imageContainerElm.innerHTML="",this.currentItems.forEach(f=>{this.imageContainerElm.appendChild(f)}),(a=this.rootElm.querySelector(".vistaview-close-btn"))==null||a.addEventListener("click",()=>this.close()),(r=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||r.addEventListener("click",()=>this.zoomIn()),(h=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||h.addEventListener("click",()=>this.zoomOut()),(c=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||c.addEventListener("click",()=>this.prev()),(d=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||d.addEventListener("click",()=>this.next()),[...this.options.controls.topLeft||[],...this.options.controls.topRight||[],...this.options.controls.topCenter||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomRight||[]].forEach(f=>{typeof f!="string"&&(this.customControls[f.name]=f)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(f=>{f.addEventListener("click",L=>{const D=this.customControls[L.currentTarget.dataset.vistaviewCustomControl],P=this.currentImages.find(z=>z.index===this.currentIndex.value);D&&P&&(D.onClick.constructor.name==="AsyncFunction"?(f.classList.add("vistaview-button--loading"),D.onClick(P).finally(()=>{f.classList.remove("vistaview-button--loading")})):D.onClick(P))})}),this.options.animationDurationBase&&this.rootElm.style.setProperty("--vistaview-animation-duration",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElm.style.setProperty("--vistaview-initial-z-index",`${this.options.initialZIndex}`),this.setInitialDimPos(this.currentImages[this.currentImages.length===1?0:Math.floor(this.currentImages.length/2)]),this.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((v=this.rootElm.querySelector(".vistaview-prev-btn"))==null||v.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-next-btn"))==null||u.classList.add("vistaview-ui--none"),(E=this.rootElm.querySelector(".vistaview-index-display"))==null||E.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(b=(m=this.options).onOpen)==null||b.call(m,o),(x=(g=this.options).onImageView)==null||x.call(g,o)}async close(t=!0){var n,i,o;if(I.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(l=>{var r;let a;(r=this.rootElm)==null||r.addEventListener("transitionend",h=>{h.currentTarget===this.rootElm&&(a&&clearTimeout(a),a=setTimeout(()=>{l()},333))})}));const e={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},container:this.imageContainerElm,elements:this.elements,via:{prev:!1,next:!1},isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userClose(this),(o=(i=this.options).onClose)==null||o.call(i,e),document.body.removeChild(this.rootElm),this.currentIndex._value=null,this.currentIndex._via={next:!1,prev:!1},this.rootElm=null,this.imageContainerElm=null,this.currentImages=null,this.currentItems=null,this.navActive=!0,this.onResizeHandler&&(window.removeEventListener("resize",this.onResizeHandler),this.onResizeHandler=null),this.onKeyDown&&(window.removeEventListener("keydown",this.onKeyDown),this.onKeyDown=null),(this.onZoomedPointerDown||this.onZoomedPointerMove||this.onZoomedPointerUp)&&(this.setZoomed(!1),this.onZoomedPointerDown=null,this.onZoomedPointerMove=null,this.onZoomedPointerUp=null),I.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach((t,e)=>{t.removeEventListener("click",this.onClickElements[e])})}view(t,e){I.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=e||{next:!1,prev:!1},this.currentIndex.value=t)}next(){I.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){I.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return I.somethingOpened===this?this.currentIndex.value:-1}}function it(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let e=0;e<t.length;e++){const n=t[e];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${e} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const e=s;for(let n=0;n<e.length;n++)if(!e[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function nt({elements:s,...t}){if(!s)throw new Error("No elements");let e=it(s);if(typeof e=="string")return console.error(e),console.warn("VistaView: silently returning."),null;const n=new et(e,t);return{open:(i=0)=>n.open(i),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:i=>{n.view(i)}}}w.DefaultOptions=R,w.defaultClose=F,w.defaultInit=X,w.defaultSetup=_,w.defaultTransition=B,w.removeTouchActions=A,w.setTouchActions=V,w.vistaView=nt,w.vistaViewDownload=k,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));
16
+ </div>`)}let M=null,Z=null,z=null,A=null;function Y(s){R(s);const t=s.imageContainerElm,e=s.elements.length;if(!t)return;let n=0,i=0,o=0,h=0,r=null,a=0,c=!1;M=l=>{l.preventDefault(),l.stopPropagation(),s.isZoomed===!1&&(c=!0,n=l.pageX,i=l.pageY,o=l.pageX,h=l.pageY,a=Date.now(),r=null,t.setPointerCapture(l.pointerId))},Z=l=>{if(l.preventDefault(),l.stopPropagation(),s.isZoomed!==!1||!c)return;const d=l.pageX-n,u=l.pageY-i;o=l.pageX,h=l.pageY,Math.abs(d)>=Math.abs(u)&&(r===null||r===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${d}px`),r=!0):Math.abs(u)>Math.abs(d)&&(r===null||r===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${u}px`),r=!1)},A=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1,r=null;const d=Array.from(t.querySelectorAll(".vistaview-item"));t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),d.forEach(u=>{u.style.transition="",u.style.translate=""})},z=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1;const d=Array.from(t.querySelectorAll(".vistaview-item")),u=o-n,v=h-i,y=Date.now()-a,m=u/y,b=v/y,w=s.options.touchSpeedThreshold||.5,x=d.find(I=>I.dataset.vistaviewPos==="0"),g=Number(x.dataset.vistaviewIndex),S=s.isReducedMotion;function C(){d[0].removeEventListener("transitionend",C),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),d.forEach(I=>{I.style.transition="",I.style.translate=""})}function D(I="0%",rt="0%"){d.forEach(U=>{U.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,U.style.translate=`${I} ${rt}`})}m<-w||m>w?(d[0].addEventListener("transitionend",()=>{s.isReducedMotion=!0,C(),s.view(m<-w?(g+1)%e:(g-1+e)%e,{next:m<-w,prev:m>w}),s.isReducedMotion=S}),D(m<-w?"-100%":"100%")):b<-w||b>w?(s.close(),D("0%","0%")):(d[0].addEventListener("transitionend",C),D("0%"))},t.addEventListener("pointermove",Z),t.addEventListener("pointerup",z),t.addEventListener("pointerdown",M),t.addEventListener("pointercancel",A)}function R(s){const t=s.imageContainerElm;t&&(Z&&t.removeEventListener("pointermove",Z),z&&t.removeEventListener("pointerup",z),M&&t.removeEventListener("pointerdown",M),A&&t.removeEventListener("pointercancel",A))}const V=s=>{Y(s)},_=({htmlElements:{to:s},index:{to:t},elements:e})=>{e instanceof NodeList&&t!==null&&(e.forEach(n=>n.style.opacity="1"),e[t].style.opacity="0"),s&&s.forEach(n=>{const i=Number(n.dataset.vistaviewPos);i!==0?(n.style.zIndex="1",n.style.left=100*i+"%"):n.style.zIndex="2"})},B=async({htmlElements:{from:s,to:t},images:{to:e},via:{next:n,prev:i},container:o,options:h,isReducedMotion:r})=>{if(!e)throw new Error("VistaView: images is null in defaultTransition()");if(r)return o.innerHTML="",t.forEach(c=>{o.appendChild(c)}),e[e.length===1?0:Math.floor(e.length/2)];const a=s.filter(c=>c.dataset.vistaviewPos==="0"||(n?c.dataset.vistaviewPos==="1":c.dataset.vistaviewPos==="-1"));return await new Promise(c=>{function l(){o.innerHTML="",t.forEach(d=>{o.appendChild(d)}),c(0)}a[a.length-1].addEventListener("transitionend",l),a.forEach(d=>{d.style.transition=`translate ${h.animationDurationBase*.5}ms ease-out`,d.style.translate=n?"-100%":i?"100%":"0%"})}),e[e.length===1?0:Math.floor(e.length/2)]},F=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),R(s)},H={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",O(),"close"],bottomCenter:["description"]}},L={somethingOpened:null};class nt{constructor(t,e){f(this,"options");f(this,"elements");f(this,"isReducedMotion");f(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n;const e=this._value;this._value=t,(n=this._vistaView)==null||n.swap(e,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});f(this,"rootElm",null);f(this,"imageContainerElm",null);f(this,"customControls",{});f(this,"currentImages",null);f(this,"currentItems",null);f(this,"navActive",!0);f(this,"isZoomed",!1);f(this,"onClickElements",[]);f(this,"onResizeHandler",null);f(this,"onKeyDown",null);f(this,"userSetup",_);f(this,"userTransition",B);f(this,"userClose",F);f(this,"userInit",V);f(this,"onZoomedPointerDown",null);f(this,"onZoomedPointerMove",null);f(this,"onZoomedPointerUp",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...H,...e||{},controls:{...H.controls,...(e==null?void 0:e.controls)||{}}},this.options.initFunction&&(this.userInit=this.options.initFunction),this.options.transitionFunction&&(this.userTransition=this.options.transitionFunction),this.options.closeFunction&&(this.userClose=this.options.closeFunction),this.options.initFunction&&(this.userInit=this.options.initFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((n,i)=>{this.onClickElements.push(o=>{o.preventDefault(),this.open(i)}),n.addEventListener("click",this.onClickElements[i])})}async swap(t,e){var c,l;if(!L.somethingOpened||t===e||t===null||this.elements.length===1)return;if(!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:i}=this.getCurrentIndexes(e),o=this.getImages(n),h=o.map((d,u)=>X(d,i[u]));h.forEach((d,u)=>{var m,b;const v=d.querySelector(".vistaview-image-highres"),y=o[u].imageElm;if(v.complete&&v.naturalWidth>0){const{width:w,height:x}=q(y);w&&x&&(v.style.setProperty("--vistaview-fitted-width",`${w}px`),v.style.setProperty("--vistaview-fitted-height",`${x}px`)),v.classList.add("vistaview-image-loaded"),(m=d.querySelector(".vistaview-image-lowres"))==null||m.classList.add("vistaview-image--hidden");const{width:g,height:S}=$(v);v.style.width=`${g}px`,v.style.height=`${S}px`,v.width=v.naturalWidth,v.height=v.naturalHeight,(b=v.parentElement)!=null&&b.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()}}),this.navActive=!1;const r={htmlElements:{from:this.currentItems,to:h},images:{from:this.currentImages,to:o},index:{from:t,to:e},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(r);const a=await this.userTransition(r);this.navActive=!0,this.setInitialDimPos(a),this.currentImages=o,this.currentItems=h,this.loadImages(),this.setCurrentDescription(),(l=(c=this.options).onImageView)==null||l.call(c,r)}setZoomed(t){var e,n,i,o,h,r;if(this.isZoomed!==t){if(this.isZoomed){let a=this.isZoomed;if(a.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((e=a.parentElement)==null||e.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=a.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((i=a.parentElement)==null||i.removeEventListener("pointerup",this.onZoomedPointerUp),this.onZoomedPointerUp=null),a==null||a.style.removeProperty("--pointer-diff-x"),a==null||a.style.removeProperty("--pointer-diff-y"),setTimeout(()=>{a==null||a.classList.remove("vistaview-image--zooming")},500),this.isZoomed=!1,!t)return}if(t){this.isZoomed=t,t.classList.add("vistaview-image--zooming"),t==null||t.style.setProperty("--pointer-diff-x","0px"),t==null||t.style.setProperty("--pointer-diff-y","0px");let a=!1,c=0,l=0,d=0,u=0,v=0,y=0;this.onZoomedPointerDown=m=>{m.preventDefault(),m.stopPropagation(),a=!0,c=m.pageX,l=m.pageY,t.setPointerCapture(m.pointerId)},this.onZoomedPointerMove=m=>{if(!a)return;m.preventDefault(),v=m.pageX-c,y=m.pageY-l;const b=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),w=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:x,minDiffY:g,maxDiffY:S,minDiffX:C}=k(b,w),D=Math.min(x,Math.max(C,d+v)),I=Math.min(S,Math.max(g,u+y));v=D-d,y=I-u,t==null||t.style.setProperty("--pointer-diff-x",`${D}px`),t==null||t.style.setProperty("--pointer-diff-y",`${I}px`)},this.onZoomedPointerUp=m=>{a=!1,t.releasePointerCapture(m.pointerId),d+=v,u+=y,v=0,y=0},(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerdown",this.onZoomedPointerDown),(h=t==null?void 0:t.parentElement)==null||h.addEventListener("pointermove",this.onZoomedPointerMove),(r=t==null?void 0:t.parentElement)==null||r.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var o,h,r,a,c;const t=(o=this.rootElm)==null?void 0:o.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),e=t.width,n=t.height;t.dataset.vistaviewInitialWidth||(t.dataset.vistaviewInitialWidth=e.toString()),t.dataset.vistaviewInitialHeight||(t.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(t);const i=(t.naturalWidth||0)*this.options.maxZoomLevel;if(e&&i&&e<i){const l=Math.min(e+this.options.zoomStep,i);t.style.width=`${l}px`;const d=l/e*n;t.style.height=`${d}px`,(r=(h=this.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"))==null||r.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=l.toString(),t.dataset.vistaviewCurrentHeight=d.toString(),l===i&&((c=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-in-btn"))==null||c.setAttribute("disabled","true"))}}zoomOut(){var h,r,a,c,l;const t=(h=this.rootElm)==null?void 0:h.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),e=t.width,n=t.height,i=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,o=d=>{d.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",o))};if(t.addEventListener("transitionend",o),t.classList.add("vistaview-image--zooming-out"),e&&i&&e>i){const d=Math.max(e-this.options.zoomStep,i);t.style.width=`${d}px`;const u=d/e*n;t.style.height=`${u}px`,(a=(r=this.rootElm)==null?void 0:r.querySelector("button.vistaview-zoom-in-btn"))==null||a.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=d.toString(),t.dataset.vistaviewCurrentHeight=u.toString();const{maxDiffX:v,minDiffY:y,maxDiffY:m,minDiffX:b}=k(d,u);let w=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),x=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");w=Math.min(v,Math.max(b,w)),x=Math.min(m,Math.max(y,x)),t==null||t.style.setProperty("--pointer-diff-x",`${w}px`),t==null||t.style.setProperty("--pointer-diff-y",`${x}px`),d===i&&((l=(c=this.rootElm)==null?void 0:c.querySelector("button.vistaview-zoom-out-btn"))==null||l.setAttribute("disabled","true"),t.removeAttribute("data-vistaview-current-width"),t.removeAttribute("data-vistaview-current-height"),t.removeAttribute("data-vistaview-initial-width"),t.removeAttribute("data-vistaview-initial-height"),this.setZoomed(!1))}}clearZoom(){}getImages(t){return t.map((e,n)=>{const i=this.elements[e];if(i instanceof HTMLElement){const o=i.querySelector("img"),h=i.getAttribute("href")||"",r=i.getAttribute("src")||"",a=i.dataset.vistaviewSrc||h||r||(o==null?void 0:o.src)||"",c=i.dataset.vistaviewAlt||i.getAttribute("alt")||(o==null?void 0:o.alt)||"",l=i.dataset.vistaviewThumb||(o==null?void 0:o.src)||h||r||"";return{index:t[n],src:a,alt:c,thumb:l,imageElm:i instanceof HTMLImageElement?i:o,anchorElm:i instanceof HTMLAnchorElement?i:void 0}}else return{index:t[n],...i}})}setInitialDimPos(t){if(!this.rootElm)return;const e=t.imageElm?E(t.imageElm):void 0,n=t.anchorElm?E(t.anchorElm):void 0,i=(n==null?void 0:n.width)||(e==null?void 0:e.width)||0,o=(n==null?void 0:n.height)||(e==null?void 0:e.height)||0,h=((n==null?void 0:n.left)||(e==null?void 0:e.left)||0)+i/2,r=((n==null?void 0:n.top)||(e==null?void 0:e.top)||0)+o/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",i+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",o+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",r+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-left",h+"px"),this.rootElm.style.setProperty("--vistaview-image-border-radius",W(n==null?void 0:n.borderRadius)||W(e==null?void 0:e.borderRadius)||"0px")}updateZoomButtonsVisibility(){var i;const t=(i=this.rootElm)==null?void 0:i.querySelector('[data-vistaview-pos="0"] img.vistaview-image-highres');if(!t)return;const e=this;function n(){var l,d;const o=(l=e.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"),h=(d=e.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"),r=parseInt(t.style.width)||t.width,a=t.naturalWidth*e.options.maxZoomLevel,c=r<a&&a>0;o&&(o.style.display=c?"":"none"),h&&(h.style.display=c?"":"none")}t.complete&&t.naturalWidth>0?n():t.addEventListener("load",n)}loadImages(){if(!this.rootElm)return;this.rootElm.querySelectorAll(".vistaview-image-highres:not(.vistaview-image-loaded)").forEach((e,n)=>{const i=e,h=this.currentImages[n].imageElm,r={w:0,h:0};if(h){const{width:c,height:l}=q(h);r.w=Math.min(h.width,c),r.h=Math.min(h.height,l)}const a=(c=!1)=>()=>{var l;if(r.w&&r.h&&(i.style.width=`${r.w}px`,i.style.height=`${r.h}px`,i.style.setProperty("--vistaview-fitted-width",`${r.w}px`),i.style.setProperty("--vistaview-fitted-height",`${r.h}px`)),i.classList.add("vistaview-image-loaded"),i.width=i.naturalWidth,i.height=i.naturalHeight,c){const{width:d,height:u}=$(i);i.style.width=`${d}px`,i.style.height=`${u}px`}else setTimeout(()=>{const{width:d,height:u}=$(i);i.style.width=`${d}px`,i.style.height=`${u}px`},333);setTimeout(()=>{var d,u;(u=(d=i.parentElement)==null?void 0:d.querySelector(".vistaview-image-lowres"))==null||u.classList.add("vistaview-image--hidden")},500),(l=e.parentElement)!=null&&l.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};i.complete&&i.naturalWidth>0?a(!0)():i.onload=a(!1)})}setIndexDisplay(){this.elements.length!==1&&(this.rootElm.querySelector(".vistaview-index-display").textContent=`${this.currentIndex.value+1} / ${this.elements.length}`)}setCurrentDescription(){this.rootElm.querySelector(".vistaview-description").textContent=(this.currentImages[1]||this.currentImages[0]).alt||""}getCurrentIndexes(t){const e=this.options.preloads,n=this.elements.length,i=n<1||!e?[t]:[...new Set([...Array.from({length:e},(h,r)=>((t-e+r)%n+n)%n),t,...Array.from({length:e},(h,r)=>(t+1+r)%n)])],o=n<1||!e?[0]:i.map((h,r)=>r-Math.floor(i.length/2));return{images:i,positions:o}}setKeyboardListeners(){this.onKeyDown=t=>{switch(t.key){case"ArrowLeft":t.preventDefault(),this.prev();break;case"ArrowRight":t.preventDefault(),this.next();break;case"ArrowUp":t.preventDefault(),this.zoomIn();break;case"ArrowDown":t.preventDefault(),this.zoomOut();break;case"Escape":t.preventDefault(),this.close();break}},window.addEventListener("keydown",this.onKeyDown)}setResizeListeners(){this.onResizeHandler=()=>{var n;const t=this.currentImages[this.currentImages.length===1?0:Math.floor(this.currentImages.length/2)];this.setInitialDimPos(t);const e=(n=this.rootElm)==null?void 0:n.querySelectorAll(".vistaview-image-highres.vistaview-image-loaded");e==null||e.forEach(i=>{const o=i,{width:h,height:r}=$(o);o.classList.contains("vistaview-image--zooming")?(o.dataset.vistaviewInitialWidth=h.toString(),o.dataset.vistaviewInitialHeight=r.toString()):(o.style.width=`${h}px`,o.style.height=`${r}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var h,r,a,c,l,d,u,v,y,m,b,w,x;if(L.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(L.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(it({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((h=this.rootElm)==null?void 0:h.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw L.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:e,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(e);const i=this.currentImages.map((g,S)=>X(g,n[S]));this.currentItems=i;const o={htmlElements:{from:null,to:this.currentItems},images:{from:null,to:this.currentImages},index:{from:null,to:t},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(o),this.imageContainerElm.innerHTML="",this.currentItems.forEach(g=>{this.imageContainerElm.appendChild(g)}),(r=this.rootElm.querySelector(".vistaview-close-btn"))==null||r.addEventListener("click",()=>this.close()),(a=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||a.addEventListener("click",()=>this.zoomIn()),(c=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||c.addEventListener("click",()=>this.zoomOut()),(l=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||l.addEventListener("click",()=>this.prev()),(d=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||d.addEventListener("click",()=>this.next()),[...this.options.controls.topLeft||[],...this.options.controls.topRight||[],...this.options.controls.topCenter||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomRight||[]].forEach(g=>{typeof g!="string"&&(this.customControls[g.name]=g)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(g=>{g.addEventListener("click",S=>{const C=this.customControls[S.currentTarget.dataset.vistaviewCustomControl],D=this.currentImages.find(I=>I.index===this.currentIndex.value);C&&D&&(C.onClick.constructor.name==="AsyncFunction"?(g.classList.add("vistaview-button--loading"),C.onClick(D).finally(()=>{g.classList.remove("vistaview-button--loading")})):C.onClick(D))})}),this.options.animationDurationBase&&this.rootElm.style.setProperty("--vistaview-animation-duration",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElm.style.setProperty("--vistaview-initial-z-index",`${this.options.initialZIndex}`),this.setInitialDimPos(this.currentImages[this.currentImages.length===1?0:Math.floor(this.currentImages.length/2)]),this.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((u=this.rootElm.querySelector(".vistaview-prev-btn"))==null||u.classList.add("vistaview-ui--none"),(v=this.rootElm.querySelector(".vistaview-next-btn"))==null||v.classList.add("vistaview-ui--none"),(y=this.rootElm.querySelector(".vistaview-index-display"))==null||y.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(b=(m=this.options).onOpen)==null||b.call(m,o),(x=(w=this.options).onImageView)==null||x.call(w,o)}async close(t=!0){var n,i,o;if(L.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(h=>{var a;let r;(a=this.rootElm)==null||a.addEventListener("transitionend",c=>{c.currentTarget===this.rootElm&&(r&&clearTimeout(r),r=setTimeout(()=>{h()},333))})}));const e={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},container:this.imageContainerElm,elements:this.elements,via:{prev:!1,next:!1},isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userClose(this),(o=(i=this.options).onClose)==null||o.call(i,e),document.body.removeChild(this.rootElm),this.currentIndex._value=null,this.currentIndex._via={next:!1,prev:!1},this.rootElm=null,this.imageContainerElm=null,this.currentImages=null,this.currentItems=null,this.navActive=!0,this.onResizeHandler&&(window.removeEventListener("resize",this.onResizeHandler),this.onResizeHandler=null),this.onKeyDown&&(window.removeEventListener("keydown",this.onKeyDown),this.onKeyDown=null),(this.onZoomedPointerDown||this.onZoomedPointerMove||this.onZoomedPointerUp)&&(this.setZoomed(!1),this.onZoomedPointerDown=null,this.onZoomedPointerMove=null,this.onZoomedPointerUp=null),L.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach((t,e)=>{t.removeEventListener("click",this.onClickElements[e])})}view(t,e){L.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=e||{next:!1,prev:!1},this.currentIndex.value=t)}next(){L.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){L.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return L.somethingOpened===this?this.currentIndex.value:-1}}function st(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let e=0;e<t.length;e++){const n=t[e];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${e} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const e=s;for(let n=0;n<e.length;n++)if(!e[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function ot({elements:s,...t}){if(!s)throw new Error("No elements");let e=st(s);if(typeof e=="string")return console.error(e),console.warn("VistaView: silently returning."),null;const n=new nt(e,t);return{open:(i=0)=>n.open(i),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:i=>{n.view(i)}}}p.DefaultOptions=H,p.defaultClose=F,p.defaultInit=V,p.defaultSetup=_,p.defaultTransition=B,p.removeTouchActions=R,p.setTouchActions=Y,p.vistaView=ot,p.vistaViewDownload=O,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vistaview",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "A lightweight, zero-dependency image lightbox library with smooth animations and touch support",
5
5
  "keywords": [
6
6
  "image",
@@ -78,7 +78,8 @@
78
78
  "build": "tsc && vite build && BUILD_UMD=true vite build",
79
79
  "preview": "vite preview",
80
80
  "prepare": "husky",
81
- "test": "echo \"no test specified\""
81
+ "test": "echo \"no test specified\"",
82
+ "tunnel": "cloudflared tunnel --url http://localhost:5173"
82
83
  },
83
84
  "lint-staged": {
84
85
  "*.{js,ts,css,json,md}": "prettier --write"