vistaview 0.3.10 → 0.3.11
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 +9 -9
- package/dist/lib/vista-view.d.ts +1 -0
- package/dist/lib/vista-view.d.ts.map +1 -1
- package/dist/vistaview.cjs +1 -1
- package/dist/vistaview.js +103 -89
- package/dist/vistaview.umd.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -113,7 +113,7 @@ vistaView({
|
|
|
113
113
|
detectReducedMotion: true, // Respect prefers-reduced-motion (default: true)
|
|
114
114
|
zoomStep: 500, // Pixels to zoom per step (default: 500)
|
|
115
115
|
maxZoomLevel: 2, // Maximum zoom multiplier (default: 2)
|
|
116
|
-
touchSpeedThreshold: 0.
|
|
116
|
+
touchSpeedThreshold: 0.5, // Swipe speed threshold for navigation (default: 0.5)
|
|
117
117
|
preloads: 1, // Number of adjacent images to preload on each side (default: 1)
|
|
118
118
|
keyboardListeners: true, // Enable keyboard navigation (default: true)
|
|
119
119
|
|
|
@@ -135,7 +135,7 @@ vistaView({
|
|
|
135
135
|
// Custom behavior functions (advanced)
|
|
136
136
|
initFunction: (vistaView) => {}, // Custom initialization
|
|
137
137
|
setupFunction: (data) => {}, // Custom setup when navigating
|
|
138
|
-
transitionFunction: (data) =>
|
|
138
|
+
transitionFunction: (data, abortSignal) => void, // Custom transition animation
|
|
139
139
|
closeFunction: (vistaView) => {}, // Custom cleanup on close
|
|
140
140
|
});
|
|
141
141
|
```
|
|
@@ -290,25 +290,25 @@ dist/svelte.js 0.54 kB │ gzip: 0.27 kB
|
|
|
290
290
|
dist/solid.js 1.11 kB │ gzip: 0.52 kB
|
|
291
291
|
dist/vue.js 1.29 kB │ gzip: 0.56 kB
|
|
292
292
|
dist/react.js 1.54 kB │ gzip: 0.57 kB
|
|
293
|
-
dist/vistaview.js 38.
|
|
294
|
-
[vite:dts] Declaration files built in
|
|
293
|
+
dist/vistaview.js 38.96 kB │ gzip: 9.65 kB
|
|
294
|
+
[vite:dts] Declaration files built in 670ms.
|
|
295
295
|
|
|
296
296
|
dist/vistaview.css 10.11 kB │ gzip: 1.78 kB
|
|
297
297
|
dist/svelte.cjs 0.48 kB │ gzip: 0.29 kB
|
|
298
298
|
dist/solid.cjs 0.92 kB │ gzip: 0.50 kB
|
|
299
299
|
dist/vue.cjs 1.00 kB │ gzip: 0.51 kB
|
|
300
300
|
dist/react.cjs 1.25 kB │ gzip: 0.52 kB
|
|
301
|
-
dist/vistaview.cjs 30.
|
|
302
|
-
✓ built in
|
|
301
|
+
dist/vistaview.cjs 30.99 kB │ gzip: 8.58 kB
|
|
302
|
+
✓ built in 788ms
|
|
303
303
|
vite v6.4.1 building for production...
|
|
304
304
|
✓ 6 modules transformed.
|
|
305
305
|
|
|
306
306
|
[vite:dts] Start generate declaration files...
|
|
307
307
|
dist/vistaview.css 10.11 kB │ gzip: 1.78 kB
|
|
308
|
-
dist/vistaview.umd.js
|
|
309
|
-
[vite:dts] Declaration files built in
|
|
308
|
+
dist/vistaview.umd.js 31.14 kB │ gzip: 8.68 kB
|
|
309
|
+
[vite:dts] Declaration files built in 665ms.
|
|
310
310
|
|
|
311
|
-
✓ built in
|
|
311
|
+
✓ built in 753ms
|
|
312
312
|
```
|
|
313
313
|
|
|
314
314
|
## License
|
package/dist/lib/vista-view.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export declare class VistaView {
|
|
|
57
57
|
private transitionAbortControllers;
|
|
58
58
|
constructor(elements: NodeListOf<HTMLElement> | VistaViewImage[], options?: VistaViewOptions);
|
|
59
59
|
private loadImageTimeout;
|
|
60
|
+
private setFullSizeImageDim;
|
|
60
61
|
private swap;
|
|
61
62
|
private setZoomed;
|
|
62
63
|
zoomIn(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vista-view.d.ts","sourceRoot":"","sources":["../../src/lib/vista-view.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAIV,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAIjB,qBAAa,+BAAgC,SAAQ,KAAK;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,cAAc;;;;;;;;;cAepB,gBAAgB,CAAC,UAAU,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE;IAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAA;CAEjE,CAAC;AAEF,qBAAa,SAAS;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,EAAE,CAAC;IACrD,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY;gBACM,MAAM,GAAG,IAAI;oBACT,SAAS,GAAG,IAAI;;;;;qBAUvB,MAAM,GAAG,IAAI;qBARb,MAAM;aAcR;YAAE,IAAI,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE;MAG3C;IAEF,OAAO,EAAE,WAAW,GAAG,IAAI,CAAQ;IACnC,iBAAiB,EAAE,WAAW,GAAG,IAAI,CAAQ;IAC7C,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB,CAAA;KAAE,CAAM;IAC/D,aAAa,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAQ;IACrD,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,CAAQ;IAC7C,SAAS,UAAQ;IACjB,QAAQ,EAAE,gBAAgB,GAAG,KAAK,CAAS;IAE3C,OAAO,CAAC,eAAe,CAIrB;IACF,OAAO,CAAC,qBAAqB,CAAwD;IAErF,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,SAAS,CAA6C;IAE9D,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,cAAc,CAAkD;IACxE,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,QAAQ,CAAsC;IAEtD,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,iBAAiB,CAA4C;IAErE,OAAO,CAAC,0BAA0B,CAA0C;gBAEhE,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB;IA2C5F,OAAO,CAAC,gBAAgB,CAA8C;
|
|
1
|
+
{"version":3,"file":"vista-view.d.ts","sourceRoot":"","sources":["../../src/lib/vista-view.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAIV,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAIjB,qBAAa,+BAAgC,SAAQ,KAAK;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,cAAc;;;;;;;;;cAepB,gBAAgB,CAAC,UAAU,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE;IAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAA;CAEjE,CAAC;AAEF,qBAAa,SAAS;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,EAAE,CAAC;IACrD,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY;gBACM,MAAM,GAAG,IAAI;oBACT,SAAS,GAAG,IAAI;;;;;qBAUvB,MAAM,GAAG,IAAI;qBARb,MAAM;aAcR;YAAE,IAAI,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE;MAG3C;IAEF,OAAO,EAAE,WAAW,GAAG,IAAI,CAAQ;IACnC,iBAAiB,EAAE,WAAW,GAAG,IAAI,CAAQ;IAC7C,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB,CAAA;KAAE,CAAM;IAC/D,aAAa,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAQ;IACrD,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,CAAQ;IAC7C,SAAS,UAAQ;IACjB,QAAQ,EAAE,gBAAgB,GAAG,KAAK,CAAS;IAE3C,OAAO,CAAC,eAAe,CAIrB;IACF,OAAO,CAAC,qBAAqB,CAAwD;IAErF,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,SAAS,CAA6C;IAE9D,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,cAAc,CAAkD;IACxE,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,QAAQ,CAAsC;IAEtD,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,iBAAiB,CAA4C;IAErE,OAAO,CAAC,0BAA0B,CAA0C;gBAEhE,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB;IA2C5F,OAAO,CAAC,gBAAgB,CAA8C;IAEtE,OAAO,CAAC,mBAAmB;YA4Bb,IAAI;IAsHlB,OAAO,CAAC,SAAS;IAiGjB,MAAM,IAAI,IAAI;IAsCd,OAAO,IAAI,IAAI;IA2Df,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,gBAAgB;IA8BxB,OAAO,CAAC,2BAA2B;IAqCnC,OAAO,CAAC,UAAU;IA2ElB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,iBAAiB;IA2BzB,OAAO,CAAC,oBAAoB;IA6B5B,OAAO,CAAC,kBAAkB;IAqB1B,IAAI,CAAC,UAAU,GAAE,MAAU,GAAG,IAAI;IA6J5B,KAAK,CAAC,IAAI,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAqEvC,OAAO,IAAI,IAAI;IAWf,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAYnE,IAAI,IAAI,IAAI;IAKZ,IAAI,IAAI,IAAI;IAKZ,eAAe,IAAI,MAAM;CAG1B"}
|
package/dist/vistaview.cjs
CHANGED
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
<div class="vistaview-prev-btn vistaview-ui"><button>${G}</button></div>
|
|
14
14
|
<div class="vistaview-next-btn vistaview-ui"><button>${J}</button></div>
|
|
15
15
|
</div>
|
|
16
|
-
</div>`)}let A=null,M=null,Z=null,$=null;function X(s){T(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,r=0,d=0,o=null,a=0,c=!1;A=l=>{l.preventDefault(),l.stopPropagation(),s.isZoomed===!1&&(c=!0,n=l.pageX,e=l.pageY,r=l.pageX,d=l.pageY,a=Date.now(),o=null,t.setPointerCapture(l.pointerId))},M=l=>{if(l.preventDefault(),l.stopPropagation(),s.isZoomed!==!1||!c)return;const h=l.pageX-n,m=l.pageY-e;r=l.pageX,d=l.pageY,Math.abs(h)>=Math.abs(m)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),o=!0):Math.abs(m)>Math.abs(h)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${m}px`),o=!1)},$=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1,o=null;const h=Array.from(t.querySelectorAll(".vistaview-item"));t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(m=>{m.style.transition="",m.style.translate=""})},Z=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),m=r-n,v=d-e,f=Date.now()-a,u=m/f,y=v/f,w=s.options.touchSpeedThreshold||.5,b=h.find(E=>E.dataset.vistaviewPos==="0"),I=Number(b.dataset.vistaviewIndex);function p(){h[0].removeEventListener("transitionend",p),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(E=>{E.style.transition="",E.style.translate=""})}function x(E="0%",L="0%"){h.forEach(S=>{S.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,S.style.translate=`${E} ${L}`})}if(u<-w||u>w){let E=function(){h[0].removeEventListener("transitionend",E),setTimeout(()=>{const L=s.isReducedMotion;s.isReducedMotion=!0,p(),s.view(u<-w?(I+1)%i:(I-1+i)%i,{next:u<-w,prev:u>w}),s.isReducedMotion=L},100)};x(u<-w?"-100%":"100%"),h[0].addEventListener("transitionend",E)}else y<-w||y>w?(s.close(),x("0%","0%")):(h[0].addEventListener("transitionend",p),x("0%"),u===0&&y===0&&s.zoomIn())},t.addEventListener("pointermove",M),t.addEventListener("pointerup",Z),t.addEventListener("pointerdown",A),t.addEventListener("pointercancel",$)}function T(s){const t=s.imageContainerElm;t&&(M&&t.removeEventListener("pointermove",M),Z&&t.removeEventListener("pointerup",Z),A&&t.removeEventListener("pointerdown",A),$&&t.removeEventListener("pointercancel",$))}const Y=s=>{X(s)},_=({htmlElements:{to:s},index:{to:t},elements:i})=>{i instanceof NodeList&&t!==null&&(i.forEach(n=>n.style.opacity="1"),i[t].style.opacity="0"),s&&s.forEach(n=>{const e=Number(n.dataset.vistaviewPos);e!==0?(n.style.zIndex="1",n.style.left=100*e+"%"):n.style.zIndex="2"})},B=async({htmlElements:{from:s,to:t},images:{to:i},via:{next:n,prev:e},options:r,isReducedMotion:d},o)=>{if(!i)throw new Error("VistaView: images is null in defaultTransition()");if(d)return;const a=s.filter(c=>c.dataset.vistaviewPos==="0"||(n?c.dataset.vistaviewPos==="1":c.dataset.vistaviewPos==="-1"));await new Promise((c,l)=>{let h=0;if(o.aborted){l(new D("Transition aborted"));return}const m=v=>{if(o.aborted)return l(new D("Transition aborted"));if(v.currentTarget.removeEventListener("transitionend",m),h++,h<a.length)return;const f=t==null?void 0:t.find(p=>p.dataset.vistaviewPos==="0"),u=f?Number(f.dataset.vistaviewIndex):0,y=a.find(p=>Number(p.dataset.vistaviewIndex)===u),w=y==null?void 0:y.querySelector(".vistaview-image-highres");if(!w)return l(new Error("current image element not found"));if(!w.classList.contains("vistaview-image-loaded")||w.classList.contains("vistaview-image-settled"))return c(0);let b=0;const I=setInterval(()=>{if(o.aborted)return clearInterval(I),l(new D("Transition aborted"));if(b++,b>r.animationDurationBase/20*1.5)return clearInterval(I),c(0);if(w.classList.contains("vistaview-image-settled"))return f==null||f.classList.add("vistaview-image-settled"),clearInterval(I),c(0)},20)};a.forEach(v=>{v.style.transition=`translate ${r.animationDurationBase*.5}ms ease-out`,v.style.translate=n?"-100%":e?"100%":"0%",v.addEventListener("transitionend",m)})})},F=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),T(s)};class D extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const z={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",V(),"close"],bottomCenter:["description"]}},C={somethingOpened:null};class ot{constructor(t,i){g(this,"options");g(this,"elements");g(this,"isReducedMotion");g(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n,e,r;const i=this._value;this._value=t;for(const d in(n=this._vistaView)==null?void 0:n.transitionAbortControllers)(e=this._vistaView)==null||e.transitionAbortControllers[d].abort();(r=this._vistaView)==null||r.swap(i,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});g(this,"rootElm",null);g(this,"imageContainerElm",null);g(this,"customControls",{});g(this,"currentImages",null);g(this,"currentItems",null);g(this,"navActive",!0);g(this,"isZoomed",!1);g(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});g(this,"defaultOnClickHandler",t=>t.preventDefault());g(this,"onResizeHandler",null);g(this,"onKeyDown",null);g(this,"userSetup",_);g(this,"userTransition",B);g(this,"userClose",F);g(this,"userInit",Y);g(this,"onZoomedPointerDown",null);g(this,"onZoomedPointerMove",null);g(this,"onZoomedPointerUp",null);g(this,"transitionAbortControllers",{});g(this,"loadImageTimeout",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...z,...i||{},controls:{...z.controls,...(i==null?void 0:i.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,e)=>{n.dataset.vistaviewIndex=e.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}async swap(t,i){var l,h,m;if(!C.somethingOpened||t===i||t===null)return;if(!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:e}=this.getCurrentIndexes(i),r=this.getImages(n),d=r.map((v,f)=>W(v,e[f])),o={htmlElements:{from:this.currentItems,to:d},images:{from:this.currentImages,to:r},index:{from:t,to:i},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),(l=this.currentItems)==null||l.forEach(v=>{v.classList.add("vistaview-image--ending")});const a=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15);this.transitionAbortControllers[a]=new AbortController;try{await this.userTransition(o,this.transitionAbortControllers[a].signal)}catch(v){v instanceof D||console.warn(v)}delete this.transitionAbortControllers[a];const c=d.find(v=>v.dataset.vistaviewPos==="0");if(c){const v=c.dataset.vistaviewIndex,f=this.currentItems.find(y=>y.dataset.vistaviewIndex===v),u=f==null?void 0:f.querySelector(".vistaview-image-highres");if(u){const y=c.querySelector(".vistaview-image-highres");y.setAttribute("class",u.getAttribute("class")||""),y.setAttribute("style",u.getAttribute("style")||""),y.classList.remove("vistaview-image--zooming")}}this.imageContainerElm.innerHTML="",d.forEach(v=>{this.imageContainerElm.appendChild(v)}),this.setInitialDimPos(),this.currentImages=r,this.currentItems=d,this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(m=(h=this.options).onImageView)==null||m.call(h,o),this.loadImageTimeout&&clearTimeout(this.loadImageTimeout),this.loadImageTimeout=setTimeout(()=>{this.loadImages()},333)}setZoomed(t){var i,n,e,r,d,o;if(this.isZoomed!==t){if(this.isZoomed){let a=this.isZoomed;if(a.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((i=a.parentElement)==null||i.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=a.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((e=a.parentElement)==null||e.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,h=0,m=0,v=0,f=0;this.onZoomedPointerDown=u=>{u.preventDefault(),u.stopPropagation(),a=!0,c=u.pageX,l=u.pageY,t.setPointerCapture(u.pointerId)},this.onZoomedPointerMove=u=>{if(!a)return;u.preventDefault(),v=u.pageX-c,f=u.pageY-l;const y=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),w=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:b,minDiffY:I,maxDiffY:p,minDiffX:x}=k(y,w),E=Math.min(b,Math.max(x,h+v)),L=Math.min(p,Math.max(I,m+f));v=E-h,f=L-m,t==null||t.style.setProperty("--pointer-diff-x",`${E}px`),t==null||t.style.setProperty("--pointer-diff-y",`${L}px`)},this.onZoomedPointerUp=u=>{a=!1,t.releasePointerCapture(u.pointerId),h+=v,m+=f,v=0,f=0},(r=t==null?void 0:t.parentElement)==null||r.addEventListener("pointerdown",this.onZoomedPointerDown),(d=t==null?void 0:t.parentElement)==null||d.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var r,d,o,a,c;const t=(r=this.rootElm)==null?void 0:r.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height;t.dataset.vistaviewInitialWidth||(t.dataset.vistaviewInitialWidth=i.toString()),t.dataset.vistaviewInitialHeight||(t.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(t);const e=(t.naturalWidth||0)*this.options.maxZoomLevel;if(i&&e&&i<e){const l=Math.min(i+this.options.zoomStep,e);t.style.width=`${l}px`;const h=l/i*n;t.style.height=`${h}px`,(o=(d=this.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=l.toString(),t.dataset.vistaviewCurrentHeight=h.toString(),l===e&&((c=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-in-btn"))==null||c.setAttribute("disabled","true"))}}zoomOut(){var d,o,a,c,l;const t=(d=this.rootElm)==null?void 0:d.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height,e=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,r=h=>{h.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",r))};if(t.addEventListener("transitionend",r),t.classList.add("vistaview-image--zooming-out"),i&&e&&i>e){const h=Math.max(i-this.options.zoomStep,e);t.style.width=`${h}px`;const m=h/i*n;t.style.height=`${m}px`,(a=(o=this.rootElm)==null?void 0:o.querySelector("button.vistaview-zoom-in-btn"))==null||a.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=h.toString(),t.dataset.vistaviewCurrentHeight=m.toString();const{maxDiffX:v,minDiffY:f,maxDiffY:u,minDiffX:y}=k(h,m);let w=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),b=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");w=Math.min(v,Math.max(y,w)),b=Math.min(u,Math.max(f,b)),t==null||t.style.setProperty("--pointer-diff-x",`${w}px`),t==null||t.style.setProperty("--pointer-diff-y",`${b}px`),h===e&&((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((i,n)=>{const e=this.elements[i];if(e instanceof HTMLElement){const r=e.querySelector("img"),d=e.getAttribute("href")||"",o=e.getAttribute("src")||"",a=e.dataset.vistaviewSrc||d||o||(r==null?void 0:r.src)||"",c=e.dataset.vistaviewAlt||e.getAttribute("alt")||(r==null?void 0:r.alt)||"",l=e.dataset.vistaviewThumb||(r==null?void 0:r.src)||d||o||"";return{index:t[n],src:a,alt:c,thumb:l,imageElm:e instanceof HTMLImageElement?e:r,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var c,l;if(!this.rootElm)return;const t=(c=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:c.dataset.vistaviewIndex,i=((l=this.currentImages)==null?void 0:l.find(h=>h.index===Number(t)))||null;if(!i)return;const n=i.imageElm?R(i.imageElm):void 0,e=i.anchorElm?R(i.anchorElm):void 0,r=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,d=(e==null?void 0:e.height)||(n==null?void 0:n.height)||0,o=((e==null?void 0:e.left)||(n==null?void 0:n.left)||0)+r/2,a=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+d/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",r+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",d+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-left",o+"px"),this.rootElm.style.setProperty("--vistaview-image-border-radius",H(e==null?void 0:e.borderRadius)||H(n==null?void 0:n.borderRadius)||"0px")}updateZoomButtonsVisibility(){var e;const t=(e=this.rootElm)==null?void 0:e.querySelector('[data-vistaview-pos="0"] img.vistaview-image-highres');if(!t)return;const i=this;function n(){var l,h;const r=(l=i.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"),d=(h=i.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,a=t.naturalWidth*i.options.maxZoomLevel,c=o<a&&a>0;r&&(r.style.display=c?"":"none"),d&&(d.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((i,n)=>{const e=i,d=this.currentImages[n].imageElm,o={w:0,h:0};if(d){const{width:c,height:l}=j(d);o.w=Math.min(d.width,c),o.h=Math.min(d.height,l)}const a=()=>{var l,h;if((l=e.parentElement)!=null&&l.classList.contains("vistaview-image--ending"))return;const c=()=>{var m;o.w&&o.h&&(e.style.width=`${o.w}px`,e.style.height=`${o.h}px`,e.style.setProperty("--vistaview-fitted-width",`${o.w}px`),e.style.setProperty("--vistaview-fitted-height",`${o.h}px`)),e.classList.add("vistaview-image-loaded"),e.width=e.naturalWidth,e.height=e.naturalHeight,setTimeout(()=>{var w,b,I;if((w=e.parentElement)!=null&&w.classList.contains("vistaview-image--ending"))return;let v=0;const f=()=>{var p,x;v++,!(v<3)&&(e.removeEventListener("transitionend",f),(x=(p=e.parentElement)==null?void 0:p.querySelector(".vistaview-image-lowres"))==null||x.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled"))},{width:u,height:y}=q(e);o.w&&o.h&&u===o.w&&y===o.h?((I=(b=e.parentElement)==null?void 0:b.querySelector(".vistaview-image-lowres"))==null||I.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled")):(e.addEventListener("transitionend",f),e.style.width=`${u}px`,e.style.height=`${y}px`)},100),(m=i.parentElement)!=null&&m.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((h=this.rootElm)!=null&&h.classList.contains("vistaview--opened"))c();else{const m=setInterval(()=>{var v;(v=this.rootElm)!=null&&v.classList.contains("vistaview--opened")&&(clearInterval(m),c())},50)}};e.complete&&e.naturalWidth>0?a():e.onload=a})}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 i=this.options.preloads,n=this.elements.length,e=n<1||!i?[t]:[...new Set([...Array.from({length:i},(d,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(d,o)=>(t+1+o)%n)])],r=n<1||!i?[0]:e.map((d,o)=>o-Math.floor(e.length/2));return{images:e,positions:r}}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 i;this.setInitialDimPos();const t=(i=this.rootElm)==null?void 0:i.querySelectorAll(".vistaview-image-highres.vistaview-image-loaded");t==null||t.forEach(n=>{const e=n,{width:r,height:d}=q(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=r.toString(),e.dataset.vistaviewInitialHeight=d.toString()):(e.style.width=`${r}px`,e.style.height=`${d}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,a,c,l,h,m,v,f,u,y,w,b,I;if(C.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(C.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(st({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((o=this.rootElm)==null?void 0:o.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw C.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:i,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(i);const e=this.currentImages.map((p,x)=>W(p,n[x]));this.currentItems=e;const r={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(r),this.imageContainerElm.innerHTML="",this.currentItems.forEach(p=>{this.imageContainerElm.appendChild(p)});let d=0;this.rootElm.addEventListener("animationend",p=>{var x;p.currentTarget===this.rootElm&&(d++,d>=2&&((x=this.rootElm)==null||x.classList.add("vistaview--opened")))}),(a=this.rootElm.querySelector(".vistaview-close-btn"))==null||a.addEventListener("click",()=>this.close()),(c=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||c.addEventListener("click",()=>this.zoomIn()),(l=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||l.addEventListener("click",()=>this.zoomOut()),(h=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||h.addEventListener("click",()=>this.prev()),(m=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||m.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(p=>{typeof p!="string"&&(this.customControls[p.name]=p)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(p=>{p.addEventListener("click",x=>{const E=this.customControls[x.currentTarget.dataset.vistaviewCustomControl],L=this.currentImages.find(S=>S.index===this.currentIndex.value);E&&L&&(E.onClick.constructor.name==="AsyncFunction"?(p.classList.add("vistaview-button--loading"),E.onClick(L).finally(()=>{p.classList.remove("vistaview-button--loading")})):E.onClick(L))})}),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.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((v=this.rootElm.querySelector(".vistaview-prev-btn"))==null||v.classList.add("vistaview-ui--none"),(f=this.rootElm.querySelector(".vistaview-next-btn"))==null||f.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-index-display"))==null||u.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(w=(y=this.options).onOpen)==null||w.call(y,r),(I=(b=this.options).onImageView)==null||I.call(b,r)}async close(t=!0){var n,e,r;if(C.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(d=>{var a;let o;(a=this.rootElm)==null||a.addEventListener("transitionend",c=>{c.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{d()},333))})}));const i={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),(r=(e=this.options).onClose)==null||r.call(e,i),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);for(const d in this.transitionAbortControllers)this.transitionAbortControllers[d].abort();this.transitionAbortControllers={},C.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.dataset.vistaviewIndex&&delete t.dataset.vistaviewIndex,t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}view(t,i){C.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=i||{next:!1,prev:!1},this.currentIndex.value=t)}next(){C.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){C.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return C.somethingOpened===this?this.currentIndex.value:-1}}function rt(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let i=0;i<t.length;i++){const n=t[i];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${i} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const i=s;for(let n=0;n<i.length;n++)if(!i[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function at({elements:s,...t}){if(!s)throw new Error("No elements");let i=rt(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new ot(i,t);return{open:(e=0)=>n.open(e),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:e=>{n.view(e)}}}exports.DefaultOptions=z;exports.VistaViewTransitionAbortedError=D;exports.defaultClose=F;exports.defaultInit=Y;exports.defaultSetup=_;exports.defaultTransition=B;exports.removeTouchActions=T;exports.setTouchActions=X;exports.vistaView=at;exports.vistaViewDownload=V;
|
|
16
|
+
</div>`)}let A=null,M=null,$=null,Z=null;function X(s){T(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,r=0,d=0,o=null,a=0,c=!1;A=l=>{l.preventDefault(),l.stopPropagation(),s.isZoomed===!1&&(c=!0,n=l.pageX,e=l.pageY,r=l.pageX,d=l.pageY,a=Date.now(),o=null,t.setPointerCapture(l.pointerId))},M=l=>{if(l.preventDefault(),l.stopPropagation(),s.isZoomed!==!1||!c)return;const h=l.pageX-n,m=l.pageY-e;r=l.pageX,d=l.pageY,Math.abs(h)>=Math.abs(m)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),o=!0):Math.abs(m)>Math.abs(h)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${m}px`),o=!1)},Z=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1,o=null;const h=Array.from(t.querySelectorAll(".vistaview-item"));t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(m=>{m.style.transition="",m.style.translate=""})},$=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),m=r-n,v=d-e,w=Date.now()-a,u=m/w,p=v/w,f=s.options.touchSpeedThreshold||.5,b=h.find(E=>E.dataset.vistaviewPos==="0"),I=Number(b.dataset.vistaviewIndex);function y(){h[0].removeEventListener("transitionend",y),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(E=>{E.style.transition="",E.style.translate=""})}function x(E="0%",L="0%"){h.forEach(D=>{D.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,D.style.translate=`${E} ${L}`})}if(u<-f||u>f){let E=function(){h[0].removeEventListener("transitionend",E),setTimeout(()=>{const L=s.isReducedMotion;s.isReducedMotion=!0,y(),s.view(u<-f?(I+1)%i:(I-1+i)%i,{next:u<-f,prev:u>f}),s.isReducedMotion=L},100)};x(u<-f?"-100%":"100%"),h[0].addEventListener("transitionend",E)}else p<-f||p>f?(s.close(),x("0%","0%")):(h[0].addEventListener("transitionend",y),x("0%"),u===0&&p===0&&s.zoomIn())},t.addEventListener("pointermove",M),t.addEventListener("pointerup",$),t.addEventListener("pointerdown",A),t.addEventListener("pointercancel",Z)}function T(s){const t=s.imageContainerElm;t&&(M&&t.removeEventListener("pointermove",M),$&&t.removeEventListener("pointerup",$),A&&t.removeEventListener("pointerdown",A),Z&&t.removeEventListener("pointercancel",Z))}const Y=s=>{X(s)},B=({htmlElements:{to:s},index:{to:t},elements:i})=>{i instanceof NodeList&&t!==null&&(i.forEach(n=>n.style.opacity="1"),i[t].style.opacity="0"),s&&s.forEach(n=>{const e=Number(n.dataset.vistaviewPos);e!==0?(n.style.zIndex="1",n.style.left=100*e+"%"):n.style.zIndex="2"})},F=async({htmlElements:{from:s,to:t},images:{to:i},via:{next:n,prev:e},options:r,isReducedMotion:d},o)=>{if(!i)throw new Error("VistaView: images is null in defaultTransition()");if(d)return;const a=s.filter(c=>c.dataset.vistaviewPos==="0"||(n?c.dataset.vistaviewPos==="1":c.dataset.vistaviewPos==="-1"));await new Promise((c,l)=>{let h=0;if(o.aborted){l(new S("Transition aborted"));return}const m=v=>{if(o.aborted)return l(new S("Transition aborted"));if(v.currentTarget.removeEventListener("transitionend",m),h++,h<a.length)return;const w=t==null?void 0:t.find(y=>y.dataset.vistaviewPos==="0"),u=w?Number(w.dataset.vistaviewIndex):0,p=a.find(y=>Number(y.dataset.vistaviewIndex)===u),f=p==null?void 0:p.querySelector(".vistaview-image-highres");if(!f)return l(new Error("current image element not found"));if(!f.classList.contains("vistaview-image-loaded")||f.classList.contains("vistaview-image-settled"))return c(0);let b=0;const I=setInterval(()=>{if(o.aborted)return clearInterval(I),l(new S("Transition aborted"));if(b++,b>r.animationDurationBase/20*1.5)return clearInterval(I),c(0);if(f.classList.contains("vistaview-image-settled"))return w==null||w.classList.add("vistaview-image-settled"),clearInterval(I),c(0)},20)};a.forEach(v=>{v.style.transition=`translate ${r.animationDurationBase*.5}ms ease-out`,v.style.translate=n?"-100%":e?"100%":"0%",v.addEventListener("transitionend",m)})})},_=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),T(s)};class S extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const z={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",V(),"close"],bottomCenter:["description"]}},C={somethingOpened:null};class ot{constructor(t,i){g(this,"options");g(this,"elements");g(this,"isReducedMotion");g(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n,e,r;const i=this._value;this._value=t;for(const d in(n=this._vistaView)==null?void 0:n.transitionAbortControllers)(e=this._vistaView)==null||e.transitionAbortControllers[d].abort();(r=this._vistaView)==null||r.swap(i,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});g(this,"rootElm",null);g(this,"imageContainerElm",null);g(this,"customControls",{});g(this,"currentImages",null);g(this,"currentItems",null);g(this,"navActive",!0);g(this,"isZoomed",!1);g(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});g(this,"defaultOnClickHandler",t=>t.preventDefault());g(this,"onResizeHandler",null);g(this,"onKeyDown",null);g(this,"userSetup",B);g(this,"userTransition",F);g(this,"userClose",_);g(this,"userInit",Y);g(this,"onZoomedPointerDown",null);g(this,"onZoomedPointerMove",null);g(this,"onZoomedPointerUp",null);g(this,"transitionAbortControllers",{});g(this,"loadImageTimeout",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...z,...i||{},controls:{...z.controls,...(i==null?void 0:i.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,e)=>{n.dataset.vistaviewIndex=e.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}setFullSizeImageDim(t){var r,d;const i=t.getBoundingClientRect(),{width:n,height:e}=q(t);if(n===i.width&&e===i.height)(d=(r=t.parentElement)==null?void 0:r.querySelector(".vistaview-image-lowres"))==null||d.classList.add("vistaview-image--hidden"),t.classList.add("vistaview-image-settled");else{let o=0;const a=()=>{var c,l;o++,!(o<3)&&(t.removeEventListener("transitionend",a),(l=(c=t.parentElement)==null?void 0:c.querySelector(".vistaview-image-lowres"))==null||l.classList.add("vistaview-image--hidden"),t.classList.add("vistaview-image-settled"))};requestAnimationFrame(()=>{t.addEventListener("transitionend",a),t.style.width=`${n}px`,t.style.height=`${e}px`})}}async swap(t,i){var l,h,m;if(!C.somethingOpened||t===i||t===null)return;if(!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:e}=this.getCurrentIndexes(i),r=this.getImages(n),d=r.map((v,w)=>W(v,e[w])),o={htmlElements:{from:this.currentItems,to:d},images:{from:this.currentImages,to:r},index:{from:t,to:i},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),(l=this.currentItems)==null||l.forEach(v=>{v.classList.add("vistaview-image--ending")});const a=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15);this.transitionAbortControllers[a]=new AbortController;try{await this.userTransition(o,this.transitionAbortControllers[a].signal)}catch(v){v instanceof S||console.warn(v)}delete this.transitionAbortControllers[a];const c=d.find(v=>v.dataset.vistaviewPos==="0");if(c){const v=c.dataset.vistaviewIndex,w=this.currentItems.find(p=>p.dataset.vistaviewIndex===v),u=w==null?void 0:w.querySelector(".vistaview-image-highres");if(u){const p=c.querySelector(".vistaview-image-highres");if(p.setAttribute("class",u.getAttribute("class")||""),p.setAttribute("style",u.getAttribute("style")||""),p.classList.remove("vistaview-image--zooming"),u.classList.contains("vistaview-image-loaded")&&!u.classList.contains("vistaview-image-settled")){const f=u.getBoundingClientRect();p.dataset.vistaviewCurrentWidth=f.width.toString(),p.dataset.vistaviewCurrentHeight=f.height.toString(),p.style.width=`${f.width}px`,p.style.height=`${f.height}px`}}}this.imageContainerElm.innerHTML="",d.forEach(v=>{var f;const w=v.querySelector(".vistaview-image-highres"),u=!!w.classList.contains("vistaview-image-loaded"),p=!!w.classList.contains("vistaview-image-settled");this.imageContainerElm.appendChild(v),u&&!p?this.setFullSizeImageDim(w):u&&p&&((f=v==null?void 0:v.querySelector(".vistaview-image-lowres"))==null||f.classList.add("vistaview-image--hidden"))}),this.setInitialDimPos(),this.currentImages=r,this.currentItems=d,this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(m=(h=this.options).onImageView)==null||m.call(h,o),this.loadImageTimeout&&clearTimeout(this.loadImageTimeout),this.loadImageTimeout=setTimeout(()=>{this.loadImages()},333)}setZoomed(t){var i,n,e,r,d,o;if(this.isZoomed!==t){if(this.isZoomed){let a=this.isZoomed;if(a.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((i=a.parentElement)==null||i.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=a.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((e=a.parentElement)==null||e.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,h=0,m=0,v=0,w=0;this.onZoomedPointerDown=u=>{u.preventDefault(),u.stopPropagation(),a=!0,c=u.pageX,l=u.pageY,t.setPointerCapture(u.pointerId)},this.onZoomedPointerMove=u=>{if(!a)return;u.preventDefault(),v=u.pageX-c,w=u.pageY-l;const p=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),f=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:b,minDiffY:I,maxDiffY:y,minDiffX:x}=k(p,f),E=Math.min(b,Math.max(x,h+v)),L=Math.min(y,Math.max(I,m+w));v=E-h,w=L-m,t==null||t.style.setProperty("--pointer-diff-x",`${E}px`),t==null||t.style.setProperty("--pointer-diff-y",`${L}px`)},this.onZoomedPointerUp=u=>{a=!1,t.releasePointerCapture(u.pointerId),h+=v,m+=w,v=0,w=0},(r=t==null?void 0:t.parentElement)==null||r.addEventListener("pointerdown",this.onZoomedPointerDown),(d=t==null?void 0:t.parentElement)==null||d.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var r,d,o,a,c;const t=(r=this.rootElm)==null?void 0:r.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height;t.dataset.vistaviewInitialWidth||(t.dataset.vistaviewInitialWidth=i.toString()),t.dataset.vistaviewInitialHeight||(t.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(t);const e=(t.naturalWidth||0)*this.options.maxZoomLevel;if(i&&e&&i<e){const l=Math.min(i+this.options.zoomStep,e);t.style.width=`${l}px`;const h=l/i*n;t.style.height=`${h}px`,(o=(d=this.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=l.toString(),t.dataset.vistaviewCurrentHeight=h.toString(),l===e&&((c=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-in-btn"))==null||c.setAttribute("disabled","true"))}}zoomOut(){var d,o,a,c,l;const t=(d=this.rootElm)==null?void 0:d.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height,e=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,r=h=>{h.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",r))};if(t.addEventListener("transitionend",r),t.classList.add("vistaview-image--zooming-out"),i&&e&&i>e){const h=Math.max(i-this.options.zoomStep,e);t.style.width=`${h}px`;const m=h/i*n;t.style.height=`${m}px`,(a=(o=this.rootElm)==null?void 0:o.querySelector("button.vistaview-zoom-in-btn"))==null||a.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=h.toString(),t.dataset.vistaviewCurrentHeight=m.toString();const{maxDiffX:v,minDiffY:w,maxDiffY:u,minDiffX:p}=k(h,m);let f=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),b=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");f=Math.min(v,Math.max(p,f)),b=Math.min(u,Math.max(w,b)),t==null||t.style.setProperty("--pointer-diff-x",`${f}px`),t==null||t.style.setProperty("--pointer-diff-y",`${b}px`),h===e&&((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((i,n)=>{const e=this.elements[i];if(e instanceof HTMLElement){const r=e.querySelector("img"),d=e.getAttribute("href")||"",o=e.getAttribute("src")||"",a=e.dataset.vistaviewSrc||d||o||(r==null?void 0:r.src)||"",c=e.dataset.vistaviewAlt||e.getAttribute("alt")||(r==null?void 0:r.alt)||"",l=e.dataset.vistaviewThumb||(r==null?void 0:r.src)||d||o||"";return{index:t[n],src:a,alt:c,thumb:l,imageElm:e instanceof HTMLImageElement?e:r,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var c,l;if(!this.rootElm)return;const t=(c=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:c.dataset.vistaviewIndex,i=((l=this.currentImages)==null?void 0:l.find(h=>h.index===Number(t)))||null;if(!i)return;const n=i.imageElm?R(i.imageElm):void 0,e=i.anchorElm?R(i.anchorElm):void 0,r=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,d=(e==null?void 0:e.height)||(n==null?void 0:n.height)||0,o=((e==null?void 0:e.left)||(n==null?void 0:n.left)||0)+r/2,a=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+d/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",r+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",d+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-left",o+"px"),this.rootElm.style.setProperty("--vistaview-image-border-radius",H(e==null?void 0:e.borderRadius)||H(n==null?void 0:n.borderRadius)||"0px")}updateZoomButtonsVisibility(){var e;const t=(e=this.rootElm)==null?void 0:e.querySelector('[data-vistaview-pos="0"] img.vistaview-image-highres');if(!t)return;const i=this;function n(){var l,h;const r=(l=i.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"),d=(h=i.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,a=t.naturalWidth*i.options.maxZoomLevel,c=o<a&&a>0;r&&(r.style.display=c?"":"none"),d&&(d.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((i,n)=>{const e=i,d=this.currentImages[n].imageElm,o={w:0,h:0};if(d){const{width:c,height:l}=j(d);o.w=Math.min(d.width,c),o.h=Math.min(d.height,l)}const a=()=>{var l,h;if((l=e.parentElement)!=null&&l.classList.contains("vistaview-image--ending"))return;const c=()=>{var m;o.w&&o.h&&(e.style.width=`${o.w}px`,e.style.height=`${o.h}px`,e.style.setProperty("--vistaview-fitted-width",`${o.w}px`),e.style.setProperty("--vistaview-fitted-height",`${o.h}px`)),e.classList.add("vistaview-image-loaded"),e.width=e.naturalWidth,e.height=e.naturalHeight,setTimeout(()=>{var v;(v=e.parentElement)!=null&&v.classList.contains("vistaview-image--ending")||this.setFullSizeImageDim(e)},100),(m=i.parentElement)!=null&&m.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((h=this.rootElm)!=null&&h.classList.contains("vistaview--opened"))c();else{const m=setInterval(()=>{var v;(v=this.rootElm)!=null&&v.classList.contains("vistaview--opened")&&(clearInterval(m),c())},50)}};e.complete&&e.naturalWidth>0?a():e.onload=a})}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 i=this.options.preloads,n=this.elements.length,e=n<1||!i?[t]:[...new Set([...Array.from({length:i},(d,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(d,o)=>(t+1+o)%n)])],r=n<1||!i?[0]:e.map((d,o)=>o-Math.floor(e.length/2));return{images:e,positions:r}}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 i;this.setInitialDimPos();const t=(i=this.rootElm)==null?void 0:i.querySelectorAll(".vistaview-image-highres.vistaview-image-loaded");t==null||t.forEach(n=>{const e=n,{width:r,height:d}=q(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=r.toString(),e.dataset.vistaviewInitialHeight=d.toString()):(e.style.width=`${r}px`,e.style.height=`${d}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,a,c,l,h,m,v,w,u,p,f,b,I;if(C.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(C.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(st({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((o=this.rootElm)==null?void 0:o.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw C.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:i,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(i);const e=this.currentImages.map((y,x)=>W(y,n[x]));this.currentItems=e;const r={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(r),this.imageContainerElm.innerHTML="",this.currentItems.forEach(y=>{this.imageContainerElm.appendChild(y)});let d=0;this.rootElm.addEventListener("animationend",y=>{var x;y.currentTarget===this.rootElm&&(d++,d>=2&&((x=this.rootElm)==null||x.classList.add("vistaview--opened")))}),(a=this.rootElm.querySelector(".vistaview-close-btn"))==null||a.addEventListener("click",()=>this.close()),(c=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||c.addEventListener("click",()=>this.zoomIn()),(l=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||l.addEventListener("click",()=>this.zoomOut()),(h=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||h.addEventListener("click",()=>this.prev()),(m=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||m.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(y=>{typeof y!="string"&&(this.customControls[y.name]=y)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(y=>{y.addEventListener("click",x=>{const E=this.customControls[x.currentTarget.dataset.vistaviewCustomControl],L=this.currentImages.find(D=>D.index===this.currentIndex.value);E&&L&&(E.onClick.constructor.name==="AsyncFunction"?(y.classList.add("vistaview-button--loading"),E.onClick(L).finally(()=>{y.classList.remove("vistaview-button--loading")})):E.onClick(L))})}),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.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((v=this.rootElm.querySelector(".vistaview-prev-btn"))==null||v.classList.add("vistaview-ui--none"),(w=this.rootElm.querySelector(".vistaview-next-btn"))==null||w.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-index-display"))==null||u.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(f=(p=this.options).onOpen)==null||f.call(p,r),(I=(b=this.options).onImageView)==null||I.call(b,r)}async close(t=!0){var n,e,r;if(C.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(d=>{var a;let o;(a=this.rootElm)==null||a.addEventListener("transitionend",c=>{c.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{d()},333))})}));const i={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),(r=(e=this.options).onClose)==null||r.call(e,i),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);for(const d in this.transitionAbortControllers)this.transitionAbortControllers[d].abort();this.transitionAbortControllers={},C.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.dataset.vistaviewIndex&&delete t.dataset.vistaviewIndex,t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}view(t,i){C.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=i||{next:!1,prev:!1},this.currentIndex.value=t)}next(){C.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){C.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return C.somethingOpened===this?this.currentIndex.value:-1}}function rt(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let i=0;i<t.length;i++){const n=t[i];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${i} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const i=s;for(let n=0;n<i.length;n++)if(!i[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function at({elements:s,...t}){if(!s)throw new Error("No elements");let i=rt(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new ot(i,t);return{open:(e=0)=>n.open(e),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:e=>{n.view(e)}}}exports.DefaultOptions=z;exports.VistaViewTransitionAbortedError=S;exports.defaultClose=_;exports.defaultInit=Y;exports.defaultSetup=B;exports.defaultTransition=F;exports.removeTouchActions=T;exports.setTouchActions=X;exports.vistaView=at;exports.vistaViewDownload=V;
|
package/dist/vistaview.js
CHANGED
|
@@ -16,11 +16,11 @@ function z(s) {
|
|
|
16
16
|
naturalHeight: s.naturalHeight
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
let
|
|
20
|
-
function
|
|
21
|
-
return
|
|
19
|
+
let D = null;
|
|
20
|
+
function B() {
|
|
21
|
+
return D || (window.trustedTypes || (window.trustedTypes = {
|
|
22
22
|
createPolicy: (s, t) => t
|
|
23
|
-
}),
|
|
23
|
+
}), D = window.trustedTypes.createPolicy("vistaView-policy", {
|
|
24
24
|
createHTML: (s) => s,
|
|
25
25
|
// HTML is generated by us, not user input
|
|
26
26
|
createScript: () => {
|
|
@@ -29,10 +29,10 @@ function V() {
|
|
|
29
29
|
createScriptURL: () => {
|
|
30
30
|
throw new Error("Not implemented");
|
|
31
31
|
}
|
|
32
|
-
}),
|
|
32
|
+
}), D);
|
|
33
33
|
}
|
|
34
34
|
function W(s) {
|
|
35
|
-
const i =
|
|
35
|
+
const i = B().createHTML(s), n = document.createElement("template");
|
|
36
36
|
n.innerHTML = i;
|
|
37
37
|
const e = n.content;
|
|
38
38
|
return n.remove(), e;
|
|
@@ -40,7 +40,7 @@ function W(s) {
|
|
|
40
40
|
function R(s) {
|
|
41
41
|
return s && !/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim()) && s;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function F(s) {
|
|
44
44
|
const i = window.getComputedStyle(s).objectFit || "", { width: n, height: e } = s.getBoundingClientRect(), r = s.naturalWidth, d = s.naturalHeight;
|
|
45
45
|
if (!i)
|
|
46
46
|
return { width: n, height: e };
|
|
@@ -63,7 +63,7 @@ function _(s) {
|
|
|
63
63
|
}
|
|
64
64
|
return { width: n, height: e };
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function H(s) {
|
|
67
67
|
const t = window.innerWidth, i = window.innerHeight, n = s.naturalWidth, e = s.naturalHeight;
|
|
68
68
|
if (!n || !e)
|
|
69
69
|
throw console.error("Error", s), new Error("Image natural dimensions are zero");
|
|
@@ -79,7 +79,7 @@ function T(s) {
|
|
|
79
79
|
height: a
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function T(s, t) {
|
|
83
83
|
const i = window.innerHeight, n = window.innerWidth, e = s, r = t, d = Math.max(0, (e - n) / 2) + n / 2, o = Math.max(0, (r - i) / 2) + i / 2, a = -d, c = -o;
|
|
84
84
|
return {
|
|
85
85
|
maxDiffX: d,
|
|
@@ -88,7 +88,7 @@ function H(s, t) {
|
|
|
88
88
|
minDiffX: a
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
const
|
|
91
|
+
const V = '<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>', _ = '<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>', U = '<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>', K = '<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>';
|
|
92
92
|
function G() {
|
|
93
93
|
return {
|
|
94
94
|
name: "download",
|
|
@@ -143,13 +143,13 @@ function Q({
|
|
|
143
143
|
<div class="vistaview-image-container"></div>
|
|
144
144
|
<div class="vistaview-top-bar vistaview-ui"><div>${i(s == null ? void 0 : s.topLeft)}</div><div>${i(s == null ? void 0 : s.topCenter)}</div><div>${i(s == null ? void 0 : s.topRight)}</div></div>
|
|
145
145
|
<div class="vistaview-bottom-bar vistaview-ui"><div>${i(s == null ? void 0 : s.bottomLeft)}</div><div>${i(s == null ? void 0 : s.bottomCenter)}</div><div>${i(s == null ? void 0 : s.bottomRight)}</div></div>
|
|
146
|
-
<div class="vistaview-prev-btn vistaview-ui"><button>${
|
|
147
|
-
<div class="vistaview-next-btn vistaview-ui"><button>${
|
|
146
|
+
<div class="vistaview-prev-btn vistaview-ui"><button>${V}</button></div>
|
|
147
|
+
<div class="vistaview-next-btn vistaview-ui"><button>${_}</button></div>
|
|
148
148
|
</div>
|
|
149
149
|
</div>`
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
|
-
let A = null,
|
|
152
|
+
let A = null, $ = null, M = null, Z = null;
|
|
153
153
|
function tt(s) {
|
|
154
154
|
O(s);
|
|
155
155
|
const t = s.imageContainerElm, i = s.elements.length;
|
|
@@ -157,53 +157,53 @@ function tt(s) {
|
|
|
157
157
|
let n = 0, e = 0, r = 0, d = 0, o = null, a = 0, c = !1;
|
|
158
158
|
A = (l) => {
|
|
159
159
|
l.preventDefault(), l.stopPropagation(), s.isZoomed === !1 && (c = !0, n = l.pageX, e = l.pageY, r = l.pageX, d = l.pageY, a = Date.now(), o = null, t.setPointerCapture(l.pointerId));
|
|
160
|
-
},
|
|
160
|
+
}, $ = (l) => {
|
|
161
161
|
if (l.preventDefault(), l.stopPropagation(), s.isZoomed !== !1 || !c) return;
|
|
162
162
|
const h = l.pageX - n, m = l.pageY - e;
|
|
163
163
|
r = l.pageX, d = l.pageY, Math.abs(h) >= Math.abs(m) && (o === null || o === !0) ? (t.style.setProperty("--vistaview-pointer-diff-x", `${h}px`), o = !0) : Math.abs(m) > Math.abs(h) && (o === null || o === !1) && (t.style.setProperty("--vistaview-pointer-diff-y", `${m}px`), o = !1);
|
|
164
|
-
},
|
|
164
|
+
}, Z = (l) => {
|
|
165
165
|
if (l.preventDefault(), l.stopPropagation(), t.releasePointerCapture(l.pointerId), s.isZoomed !== !1 || !c) return;
|
|
166
166
|
c = !1, o = null;
|
|
167
167
|
const h = Array.from(t.querySelectorAll(".vistaview-item"));
|
|
168
168
|
t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), h.forEach((m) => {
|
|
169
169
|
m.style.transition = "", m.style.translate = "";
|
|
170
170
|
});
|
|
171
|
-
},
|
|
171
|
+
}, M = (l) => {
|
|
172
172
|
if (l.preventDefault(), l.stopPropagation(), t.releasePointerCapture(l.pointerId), s.isZoomed !== !1 || !c) return;
|
|
173
173
|
c = !1;
|
|
174
|
-
const h = Array.from(t.querySelectorAll(".vistaview-item")), m = r - n, v = d - e,
|
|
174
|
+
const h = Array.from(t.querySelectorAll(".vistaview-item")), m = r - n, v = d - e, w = Date.now() - a, u = m / w, p = v / w, f = s.options.touchSpeedThreshold || 0.5, x = h.find(
|
|
175
175
|
(E) => E.dataset.vistaviewPos === "0"
|
|
176
|
-
), I = Number(
|
|
177
|
-
function
|
|
178
|
-
h[0].removeEventListener("transitionend",
|
|
176
|
+
), I = Number(x.dataset.vistaviewIndex);
|
|
177
|
+
function y() {
|
|
178
|
+
h[0].removeEventListener("transitionend", y), t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), h.forEach((E) => {
|
|
179
179
|
E.style.transition = "", E.style.translate = "";
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
|
-
function
|
|
183
|
-
h.forEach((
|
|
184
|
-
|
|
182
|
+
function b(E = "0%", L = "0%") {
|
|
183
|
+
h.forEach((S) => {
|
|
184
|
+
S.style.transition = `translate ${s.options.animationDurationBase * 0.5}ms ease-out`, S.style.translate = `${E} ${L}`;
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
if (u < -
|
|
187
|
+
if (u < -f || u > f) {
|
|
188
188
|
let E = function() {
|
|
189
189
|
h[0].removeEventListener("transitionend", E), setTimeout(() => {
|
|
190
190
|
const L = s.isReducedMotion;
|
|
191
|
-
s.isReducedMotion = !0,
|
|
192
|
-
u < -
|
|
191
|
+
s.isReducedMotion = !0, y(), s.view(
|
|
192
|
+
u < -f ? (I + 1) % i : (I - 1 + i) % i,
|
|
193
193
|
{
|
|
194
|
-
next: u < -
|
|
195
|
-
prev: u >
|
|
194
|
+
next: u < -f,
|
|
195
|
+
prev: u > f
|
|
196
196
|
}
|
|
197
197
|
), s.isReducedMotion = L;
|
|
198
198
|
}, 100);
|
|
199
199
|
};
|
|
200
|
-
|
|
201
|
-
} else
|
|
202
|
-
}, t.addEventListener("pointermove",
|
|
200
|
+
b(u < -f ? "-100%" : "100%"), h[0].addEventListener("transitionend", E);
|
|
201
|
+
} else p < -f || p > f ? (s.close(), b("0%", "0%")) : (h[0].addEventListener("transitionend", y), b("0%"), u === 0 && p === 0 && s.zoomIn());
|
|
202
|
+
}, t.addEventListener("pointermove", $), t.addEventListener("pointerup", M), t.addEventListener("pointerdown", A), t.addEventListener("pointercancel", Z);
|
|
203
203
|
}
|
|
204
204
|
function O(s) {
|
|
205
205
|
const t = s.imageContainerElm;
|
|
206
|
-
t && (
|
|
206
|
+
t && ($ && t.removeEventListener("pointermove", $), M && t.removeEventListener("pointerup", M), A && t.removeEventListener("pointerdown", A), Z && t.removeEventListener("pointercancel", Z));
|
|
207
207
|
}
|
|
208
208
|
const et = (s) => {
|
|
209
209
|
tt(s);
|
|
@@ -231,28 +231,28 @@ const et = (s) => {
|
|
|
231
231
|
await new Promise((c, l) => {
|
|
232
232
|
let h = 0;
|
|
233
233
|
if (o.aborted) {
|
|
234
|
-
l(new
|
|
234
|
+
l(new P("Transition aborted"));
|
|
235
235
|
return;
|
|
236
236
|
}
|
|
237
237
|
const m = (v) => {
|
|
238
238
|
if (o.aborted)
|
|
239
|
-
return l(new
|
|
239
|
+
return l(new P("Transition aborted"));
|
|
240
240
|
if (v.currentTarget.removeEventListener("transitionend", m), h++, h < a.length) return;
|
|
241
|
-
const
|
|
241
|
+
const w = t == null ? void 0 : t.find((y) => y.dataset.vistaviewPos === "0"), u = w ? Number(w.dataset.vistaviewIndex) : 0, p = a.find((y) => Number(y.dataset.vistaviewIndex) === u), f = p == null ? void 0 : p.querySelector(
|
|
242
242
|
".vistaview-image-highres"
|
|
243
243
|
);
|
|
244
|
-
if (!
|
|
244
|
+
if (!f)
|
|
245
245
|
return l(new Error("current image element not found"));
|
|
246
|
-
if (!
|
|
246
|
+
if (!f.classList.contains("vistaview-image-loaded") || f.classList.contains("vistaview-image-settled"))
|
|
247
247
|
return c(0);
|
|
248
|
-
let
|
|
248
|
+
let x = 0;
|
|
249
249
|
const I = setInterval(() => {
|
|
250
250
|
if (o.aborted)
|
|
251
|
-
return clearInterval(I), l(new
|
|
252
|
-
if (
|
|
251
|
+
return clearInterval(I), l(new P("Transition aborted"));
|
|
252
|
+
if (x++, x > r.animationDurationBase / 20 * 1.5)
|
|
253
253
|
return clearInterval(I), c(0);
|
|
254
|
-
if (
|
|
255
|
-
return
|
|
254
|
+
if (f.classList.contains("vistaview-image-settled"))
|
|
255
|
+
return w == null || w.classList.add("vistaview-image-settled"), clearInterval(I), c(0);
|
|
256
256
|
}, 20);
|
|
257
257
|
};
|
|
258
258
|
a.forEach((v) => {
|
|
@@ -262,7 +262,7 @@ const et = (s) => {
|
|
|
262
262
|
}, st = (s) => {
|
|
263
263
|
s.elements instanceof NodeList && s.elements.forEach((t) => t.style.opacity = "1"), O(s);
|
|
264
264
|
};
|
|
265
|
-
class
|
|
265
|
+
class P extends Error {
|
|
266
266
|
constructor(t) {
|
|
267
267
|
super(t), this.name = "VistaViewTransitionAbortedError";
|
|
268
268
|
}
|
|
@@ -348,13 +348,29 @@ class ot {
|
|
|
348
348
|
n.dataset.vistaviewIndex = e.toString(), n.addEventListener("click", this.defaultOnClickHandler), n.addEventListener("pointerup", this.onClickElements);
|
|
349
349
|
});
|
|
350
350
|
}
|
|
351
|
+
setFullSizeImageDim(t) {
|
|
352
|
+
var r, d;
|
|
353
|
+
const i = t.getBoundingClientRect(), { width: n, height: e } = H(t);
|
|
354
|
+
if (n === i.width && e === i.height)
|
|
355
|
+
(d = (r = t.parentElement) == null ? void 0 : r.querySelector(".vistaview-image-lowres")) == null || d.classList.add("vistaview-image--hidden"), t.classList.add("vistaview-image-settled");
|
|
356
|
+
else {
|
|
357
|
+
let o = 0;
|
|
358
|
+
const a = () => {
|
|
359
|
+
var c, l;
|
|
360
|
+
o++, !(o < 3) && (t.removeEventListener("transitionend", a), (l = (c = t.parentElement) == null ? void 0 : c.querySelector(".vistaview-image-lowres")) == null || l.classList.add("vistaview-image--hidden"), t.classList.add("vistaview-image-settled"));
|
|
361
|
+
};
|
|
362
|
+
requestAnimationFrame(() => {
|
|
363
|
+
t.addEventListener("transitionend", a), t.style.width = `${n}px`, t.style.height = `${e}px`;
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
351
367
|
async swap(t, i) {
|
|
352
368
|
var l, h, m;
|
|
353
369
|
if (!C.somethingOpened || t === i || t === null) return;
|
|
354
370
|
if (!this.imageContainerElm)
|
|
355
371
|
throw new Error("VistaView: imageContainerElm is null in swap()");
|
|
356
372
|
this.setIndexDisplay(), this.clearZoom();
|
|
357
|
-
const { images: n, positions: e } = this.getCurrentIndexes(i), r = this.getImages(n), d = r.map((v,
|
|
373
|
+
const { images: n, positions: e } = this.getCurrentIndexes(i), r = this.getImages(n), d = r.map((v, w) => q(v, e[w])), o = {
|
|
358
374
|
htmlElements: { from: this.currentItems, to: d },
|
|
359
375
|
images: { from: this.currentImages, to: r },
|
|
360
376
|
index: { from: t, to: i },
|
|
@@ -374,21 +390,26 @@ class ot {
|
|
|
374
390
|
try {
|
|
375
391
|
await this.userTransition(o, this.transitionAbortControllers[a].signal);
|
|
376
392
|
} catch (v) {
|
|
377
|
-
v instanceof
|
|
393
|
+
v instanceof P || console.warn(v);
|
|
378
394
|
}
|
|
379
395
|
delete this.transitionAbortControllers[a];
|
|
380
396
|
const c = d.find((v) => v.dataset.vistaviewPos === "0");
|
|
381
397
|
if (c) {
|
|
382
|
-
const v = c.dataset.vistaviewIndex,
|
|
398
|
+
const v = c.dataset.vistaviewIndex, w = this.currentItems.find((p) => p.dataset.vistaviewIndex === v), u = w == null ? void 0 : w.querySelector(".vistaview-image-highres");
|
|
383
399
|
if (u) {
|
|
384
|
-
const
|
|
400
|
+
const p = c.querySelector(
|
|
385
401
|
".vistaview-image-highres"
|
|
386
402
|
);
|
|
387
|
-
|
|
403
|
+
if (p.setAttribute("class", u.getAttribute("class") || ""), p.setAttribute("style", u.getAttribute("style") || ""), p.classList.remove("vistaview-image--zooming"), u.classList.contains("vistaview-image-loaded") && !u.classList.contains("vistaview-image-settled")) {
|
|
404
|
+
const f = u.getBoundingClientRect();
|
|
405
|
+
p.dataset.vistaviewCurrentWidth = f.width.toString(), p.dataset.vistaviewCurrentHeight = f.height.toString(), p.style.width = `${f.width}px`, p.style.height = `${f.height}px`;
|
|
406
|
+
}
|
|
388
407
|
}
|
|
389
408
|
}
|
|
390
409
|
this.imageContainerElm.innerHTML = "", d.forEach((v) => {
|
|
391
|
-
|
|
410
|
+
var f;
|
|
411
|
+
const w = v.querySelector(".vistaview-image-highres"), u = !!w.classList.contains("vistaview-image-loaded"), p = !!w.classList.contains("vistaview-image-settled");
|
|
412
|
+
this.imageContainerElm.appendChild(v), u && !p ? this.setFullSizeImageDim(w) : u && p && ((f = v == null ? void 0 : v.querySelector(".vistaview-image-lowres")) == null || f.classList.add("vistaview-image--hidden"));
|
|
392
413
|
}), this.setInitialDimPos(), this.currentImages = r, this.currentItems = d, this.setCurrentDescription(), this.updateZoomButtonsVisibility(), (m = (h = this.options).onImageView) == null || m.call(h, o), this.loadImageTimeout && clearTimeout(this.loadImageTimeout), this.loadImageTimeout = setTimeout(() => {
|
|
393
414
|
this.loadImages();
|
|
394
415
|
}, 333);
|
|
@@ -405,19 +426,19 @@ class ot {
|
|
|
405
426
|
}
|
|
406
427
|
if (t) {
|
|
407
428
|
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");
|
|
408
|
-
let a = !1, c = 0, l = 0, h = 0, m = 0, v = 0,
|
|
429
|
+
let a = !1, c = 0, l = 0, h = 0, m = 0, v = 0, w = 0;
|
|
409
430
|
this.onZoomedPointerDown = (u) => {
|
|
410
431
|
u.preventDefault(), u.stopPropagation(), a = !0, c = u.pageX, l = u.pageY, t.setPointerCapture(u.pointerId);
|
|
411
432
|
}, this.onZoomedPointerMove = (u) => {
|
|
412
433
|
if (!a) return;
|
|
413
|
-
u.preventDefault(), v = u.pageX - c,
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
), E = Math.min(
|
|
418
|
-
v = E - h,
|
|
434
|
+
u.preventDefault(), v = u.pageX - c, w = u.pageY - l;
|
|
435
|
+
const p = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentWidth) || "0"), f = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentHeight) || "0"), { maxDiffX: x, minDiffY: I, maxDiffY: y, minDiffX: b } = T(
|
|
436
|
+
p,
|
|
437
|
+
f
|
|
438
|
+
), E = Math.min(x, Math.max(b, h + v)), L = Math.min(y, Math.max(I, m + w));
|
|
439
|
+
v = E - h, w = L - m, t == null || t.style.setProperty("--pointer-diff-x", `${E}px`), t == null || t.style.setProperty("--pointer-diff-y", `${L}px`);
|
|
419
440
|
}, this.onZoomedPointerUp = (u) => {
|
|
420
|
-
a = !1, t.releasePointerCapture(u.pointerId), h += v, m +=
|
|
441
|
+
a = !1, t.releasePointerCapture(u.pointerId), h += v, m += w, v = 0, w = 0;
|
|
421
442
|
}, (r = t == null ? void 0 : t.parentElement) == null || r.addEventListener("pointerdown", this.onZoomedPointerDown), (d = t == null ? void 0 : t.parentElement) == null || d.addEventListener("pointermove", this.onZoomedPointerMove), (o = t == null ? void 0 : t.parentElement) == null || o.addEventListener("pointerup", this.onZoomedPointerUp);
|
|
422
443
|
return;
|
|
423
444
|
}
|
|
@@ -449,13 +470,13 @@ class ot {
|
|
|
449
470
|
t.style.width = `${h}px`;
|
|
450
471
|
const m = h / i * n;
|
|
451
472
|
t.style.height = `${m}px`, (a = (o = this.rootElm) == null ? void 0 : o.querySelector("button.vistaview-zoom-in-btn")) == null || a.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = h.toString(), t.dataset.vistaviewCurrentHeight = m.toString();
|
|
452
|
-
const { maxDiffX: v, minDiffY:
|
|
453
|
-
let
|
|
473
|
+
const { maxDiffX: v, minDiffY: w, maxDiffY: u, minDiffX: p } = T(h, m);
|
|
474
|
+
let f = parseInt(
|
|
454
475
|
(t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-x").replace("px", "")) || "0"
|
|
455
|
-
),
|
|
476
|
+
), x = parseInt(
|
|
456
477
|
(t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-y").replace("px", "")) || "0"
|
|
457
478
|
);
|
|
458
|
-
|
|
479
|
+
f = Math.min(v, Math.max(p, f)), x = Math.min(u, Math.max(w, x)), t == null || t.style.setProperty("--pointer-diff-x", `${f}px`), t == null || t.style.setProperty("--pointer-diff-y", `${x}px`), h === e && ((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));
|
|
459
480
|
}
|
|
460
481
|
}
|
|
461
482
|
clearZoom() {
|
|
@@ -513,7 +534,7 @@ class ot {
|
|
|
513
534
|
).forEach((i, n) => {
|
|
514
535
|
const e = i, d = this.currentImages[n].imageElm, o = { w: 0, h: 0 };
|
|
515
536
|
if (d) {
|
|
516
|
-
const { width: c, height: l } =
|
|
537
|
+
const { width: c, height: l } = F(d);
|
|
517
538
|
o.w = Math.min(d.width, c), o.h = Math.min(d.height, l);
|
|
518
539
|
}
|
|
519
540
|
const a = () => {
|
|
@@ -523,15 +544,8 @@ class ot {
|
|
|
523
544
|
const c = () => {
|
|
524
545
|
var m;
|
|
525
546
|
o.w && o.h && (e.style.width = `${o.w}px`, e.style.height = `${o.h}px`, e.style.setProperty("--vistaview-fitted-width", `${o.w}px`), e.style.setProperty("--vistaview-fitted-height", `${o.h}px`)), e.classList.add("vistaview-image-loaded"), e.width = e.naturalWidth, e.height = e.naturalHeight, setTimeout(() => {
|
|
526
|
-
var
|
|
527
|
-
|
|
528
|
-
return;
|
|
529
|
-
let v = 0;
|
|
530
|
-
const f = () => {
|
|
531
|
-
var p, x;
|
|
532
|
-
v++, !(v < 3) && (e.removeEventListener("transitionend", f), (x = (p = e.parentElement) == null ? void 0 : p.querySelector(".vistaview-image-lowres")) == null || x.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled"));
|
|
533
|
-
}, { width: u, height: y } = T(e);
|
|
534
|
-
o.w && o.h && u === o.w && y === o.h ? ((I = (b = e.parentElement) == null ? void 0 : b.querySelector(".vistaview-image-lowres")) == null || I.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled")) : (e.addEventListener("transitionend", f), e.style.width = `${u}px`, e.style.height = `${y}px`);
|
|
547
|
+
var v;
|
|
548
|
+
(v = e.parentElement) != null && v.classList.contains("vistaview-image--ending") || this.setFullSizeImageDim(e);
|
|
535
549
|
}, 100), (m = i.parentElement) != null && m.matches('[data-vistaview-pos="0"]') && this.updateZoomButtonsVisibility();
|
|
536
550
|
};
|
|
537
551
|
if ((h = this.rootElm) != null && h.classList.contains("vistaview--opened"))
|
|
@@ -597,13 +611,13 @@ class ot {
|
|
|
597
611
|
".vistaview-image-highres.vistaview-image-loaded"
|
|
598
612
|
);
|
|
599
613
|
t == null || t.forEach((n) => {
|
|
600
|
-
const e = n, { width: r, height: d } =
|
|
614
|
+
const e = n, { width: r, height: d } = H(e);
|
|
601
615
|
e.classList.contains("vistaview-image--zooming") ? (e.dataset.vistaviewInitialWidth = r.toString(), e.dataset.vistaviewInitialHeight = d.toString()) : (e.style.width = `${r}px`, e.style.height = `${d}px`);
|
|
602
616
|
});
|
|
603
617
|
}, window.addEventListener("resize", this.onResizeHandler);
|
|
604
618
|
}
|
|
605
619
|
open(t = 0) {
|
|
606
|
-
var o, a, c, l, h, m, v,
|
|
620
|
+
var o, a, c, l, h, m, v, w, u, p, f, x, I;
|
|
607
621
|
if (C.somethingOpened) {
|
|
608
622
|
console.error("VistaView: another instance is already opened. Returning.");
|
|
609
623
|
return;
|
|
@@ -618,7 +632,7 @@ class ot {
|
|
|
618
632
|
this.options.arrowOnSmallScreens || this.rootElm.classList.add("vistaview-no-arrows-sm");
|
|
619
633
|
const { images: i, positions: n } = this.getCurrentIndexes(t);
|
|
620
634
|
this.currentImages = this.getImages(i);
|
|
621
|
-
const e = this.currentImages.map((
|
|
635
|
+
const e = this.currentImages.map((y, b) => q(y, n[b]));
|
|
622
636
|
this.currentItems = e;
|
|
623
637
|
const r = {
|
|
624
638
|
htmlElements: { from: null, to: this.currentItems },
|
|
@@ -632,13 +646,13 @@ class ot {
|
|
|
632
646
|
isZoomed: this.isZoomed,
|
|
633
647
|
options: this.options
|
|
634
648
|
};
|
|
635
|
-
this.userSetup(r), this.imageContainerElm.innerHTML = "", this.currentItems.forEach((
|
|
636
|
-
this.imageContainerElm.appendChild(
|
|
649
|
+
this.userSetup(r), this.imageContainerElm.innerHTML = "", this.currentItems.forEach((y) => {
|
|
650
|
+
this.imageContainerElm.appendChild(y);
|
|
637
651
|
});
|
|
638
652
|
let d = 0;
|
|
639
|
-
this.rootElm.addEventListener("animationend", (
|
|
640
|
-
var
|
|
641
|
-
|
|
653
|
+
this.rootElm.addEventListener("animationend", (y) => {
|
|
654
|
+
var b;
|
|
655
|
+
y.currentTarget === this.rootElm && (d++, d >= 2 && ((b = this.rootElm) == null || b.classList.add("vistaview--opened")));
|
|
642
656
|
}), (a = this.rootElm.querySelector(".vistaview-close-btn")) == null || a.addEventListener("click", () => this.close()), (c = this.rootElm.querySelector(".vistaview-zoom-in-btn")) == null || c.addEventListener("click", () => this.zoomIn()), (l = this.rootElm.querySelector(".vistaview-zoom-out-btn")) == null || l.addEventListener("click", () => this.zoomOut()), (h = this.rootElm.querySelector(".vistaview-prev-btn>button")) == null || h.addEventListener("click", () => this.prev()), (m = this.rootElm.querySelector(".vistaview-next-btn>button")) == null || m.addEventListener("click", () => this.next()), [
|
|
643
657
|
...this.options.controls.topLeft || [],
|
|
644
658
|
...this.options.controls.topRight || [],
|
|
@@ -646,15 +660,15 @@ class ot {
|
|
|
646
660
|
...this.options.controls.bottomCenter || [],
|
|
647
661
|
...this.options.controls.bottomLeft || [],
|
|
648
662
|
...this.options.controls.bottomRight || []
|
|
649
|
-
].forEach((
|
|
650
|
-
typeof
|
|
651
|
-
}), this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach((
|
|
652
|
-
|
|
653
|
-
const E = this.customControls[
|
|
654
|
-
(
|
|
663
|
+
].forEach((y) => {
|
|
664
|
+
typeof y != "string" && (this.customControls[y.name] = y);
|
|
665
|
+
}), this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach((y) => {
|
|
666
|
+
y.addEventListener("click", (b) => {
|
|
667
|
+
const E = this.customControls[b.currentTarget.dataset.vistaviewCustomControl], L = this.currentImages.find(
|
|
668
|
+
(S) => S.index === this.currentIndex.value
|
|
655
669
|
);
|
|
656
|
-
E && L && (E.onClick.constructor.name === "AsyncFunction" ? (
|
|
657
|
-
|
|
670
|
+
E && L && (E.onClick.constructor.name === "AsyncFunction" ? (y.classList.add("vistaview-button--loading"), E.onClick(L).finally(() => {
|
|
671
|
+
y.classList.remove("vistaview-button--loading");
|
|
658
672
|
})) : E.onClick(L));
|
|
659
673
|
});
|
|
660
674
|
}), this.options.animationDurationBase && this.rootElm.style.setProperty(
|
|
@@ -663,7 +677,7 @@ class ot {
|
|
|
663
677
|
), this.options.initialZIndex !== void 0 && this.rootElm.style.setProperty(
|
|
664
678
|
"--vistaview-initial-z-index",
|
|
665
679
|
`${this.options.initialZIndex}`
|
|
666
|
-
), this.setInitialDimPos(), 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"), (
|
|
680
|
+
), this.setInitialDimPos(), 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"), (w = this.rootElm.querySelector(".vistaview-next-btn")) == null || w.classList.add("vistaview-ui--none"), (u = this.rootElm.querySelector(".vistaview-index-display")) == null || u.classList.add("vistaview-ui--none")), this.rootElm && this.rootElm.classList.add("vistaview--initialized"), this.loadImages(), this.setCurrentDescription(), this.setIndexDisplay(), this.userInit(this), (f = (p = this.options).onOpen) == null || f.call(p, r), (I = (x = this.options).onImageView) == null || I.call(x, r);
|
|
667
681
|
}
|
|
668
682
|
async close(t = !0) {
|
|
669
683
|
var n, e, r;
|
|
@@ -748,7 +762,7 @@ function lt({ elements: s, ...t }) {
|
|
|
748
762
|
}
|
|
749
763
|
export {
|
|
750
764
|
k as DefaultOptions,
|
|
751
|
-
|
|
765
|
+
P as VistaViewTransitionAbortedError,
|
|
752
766
|
st as defaultClose,
|
|
753
767
|
et as defaultInit,
|
|
754
768
|
it as defaultSetup,
|
package/dist/vistaview.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(E,
|
|
1
|
+
(function(E,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(E=typeof globalThis<"u"?globalThis:E||self,x(E.VistaView={}))})(this,(function(E){"use strict";var at=Object.defineProperty;var lt=(E,x,P)=>x in E?at(E,x,{enumerable:!0,configurable:!0,writable:!0,value:P}):E[x]=P;var g=(E,x,P)=>lt(E,typeof x!="symbol"?x+"":x,P);function x(s){const t=getComputedStyle(s),i=s.getBoundingClientRect();return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow,top:i.top,left:i.left,width:i.width,height:i.height,naturalWidth:s.naturalWidth,naturalHeight:s.naturalHeight}}let P=null;function U(){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 q(s){const i=U().createHTML(s),n=document.createElement("template");n.innerHTML=i;const e=n.content;return n.remove(),e}function k(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function j(s){const i=window.getComputedStyle(s).objectFit||"",{width:n,height:e}=s.getBoundingClientRect(),r=s.naturalWidth,d=s.naturalHeight;if(!i)return{width:n,height:e};if(!r||!d)return{width:n,height:e};const o=r/d,a=n/e;switch(i){case"fill":return{width:n,height:e};case"none":return{width:r,height:d};case"contain":return o>a?{width:n,height:n/o}:{width:e*o,height:e};case"cover":return o<a?{width:n,height:n/o}:{width:e*o,height:e};case"scale-down":{const c={width:r,height:d},l=o>a?{width:n,height:n/o}:{width:e*o,height:e};return l.width<=c.width&&l.height<=c.height?l:c}}return{width:n,height:e}}function W(s){const t=window.innerWidth,i=window.innerHeight,n=s.naturalWidth,e=s.naturalHeight;if(!n||!e)throw console.error("Error",s),new Error("Image natural dimensions are zero");if(n<t&&e<i)return{width:n,height:e};const r=n/e,d=t/i;let o,a;return r>d?(o=t,a=t/r):(a=i,o=i*r),{width:o,height:a}}function O(s,t){const i=window.innerHeight,n=window.innerWidth,e=s,r=t,d=Math.max(0,(e-n)/2)+n/2,o=Math.max(0,(r-i)/2)+i/2,a=-d,c=-o;return{maxDiffX:d,minDiffY:c,maxDiffY:o,minDiffX:a}}const K='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',G='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></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="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',Q='<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>',tt='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',et='<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 V(){return{name:"download",icon:et,onClick:async s=>{var r;const t=await fetch(s.src),i=await t.blob(),n=t.url,e=document.createElement("a");e.href=URL.createObjectURL(i),e.download=((r=n.split("/").pop())==null?void 0:r.split("?")[0].split("#")[0])||"download",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}}function it(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${J}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${Q}</button>`;case"close":return`<button class="vistaview-close-btn">${tt}</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,h;const i=s.imageElm?getComputedStyle(s.imageElm):null,n=(i==null?void 0:i.objectFit)||"",e=((l=s.imageElm)==null?void 0:l.naturalWidth)||"",r=((h=s.imageElm)==null?void 0:h.naturalHeight)||"",d=(i==null?void 0:i.width)||"",o=(i==null?void 0:i.height)||"",a=document.createElement("div");a.className="vistaview-item",a.dataset.vistaviewPos=`${t!==void 0?t:""}`,a.dataset.vistaviewIndex=s.index.toString();const c=q(`<img class="vistaview-image-lowres"
|
|
2
2
|
style="${n?`object-fit:${n};`:""}${d?`width:${d};`:""}${o?`height:${o};`:""}"
|
|
3
3
|
src="${s.thumb||s.src}"
|
|
4
4
|
alt="${s.alt||""}"
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
<div class="vistaview-prev-btn vistaview-ui"><button>${K}</button></div>
|
|
14
14
|
<div class="vistaview-next-btn vistaview-ui"><button>${G}</button></div>
|
|
15
15
|
</div>
|
|
16
|
-
</div>`)}let M=null,Z=null,$=null,z=null;function Y(s){R(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,r=0,d=0,o=null,a=0,c=!1;M=l=>{l.preventDefault(),l.stopPropagation(),s.isZoomed===!1&&(c=!0,n=l.pageX,e=l.pageY,r=l.pageX,d=l.pageY,a=Date.now(),o=null,t.setPointerCapture(l.pointerId))},Z=l=>{if(l.preventDefault(),l.stopPropagation(),s.isZoomed!==!1||!c)return;const h=l.pageX-n,m=l.pageY-e;r=l.pageX,d=l.pageY,Math.abs(h)>=Math.abs(m)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),o=!0):Math.abs(m)>Math.abs(h)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${m}px`),o=!1)},z=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1,o=null;const h=Array.from(t.querySelectorAll(".vistaview-item"));t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(m=>{m.style.transition="",m.style.translate=""})},$=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),m=r-n,v=d-e,f=Date.now()-a,u=m/f,y=v/f,p=s.options.touchSpeedThreshold||.5,x=h.find(b=>b.dataset.vistaviewPos==="0"),C=Number(x.dataset.vistaviewIndex);function w(){h[0].removeEventListener("transitionend",w),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(b=>{b.style.transition="",b.style.translate=""})}function I(b="0%",S="0%"){h.forEach(T=>{T.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,T.style.translate=`${b} ${S}`})}if(u<-p||u>p){let b=function(){h[0].removeEventListener("transitionend",b),setTimeout(()=>{const S=s.isReducedMotion;s.isReducedMotion=!0,w(),s.view(u<-p?(C+1)%i:(C-1+i)%i,{next:u<-p,prev:u>p}),s.isReducedMotion=S},100)};I(u<-p?"-100%":"100%"),h[0].addEventListener("transitionend",b)}else y<-p||y>p?(s.close(),I("0%","0%")):(h[0].addEventListener("transitionend",w),I("0%"),u===0&&y===0&&s.zoomIn())},t.addEventListener("pointermove",Z),t.addEventListener("pointerup",$),t.addEventListener("pointerdown",M),t.addEventListener("pointercancel",z)}function R(s){const t=s.imageContainerElm;t&&(Z&&t.removeEventListener("pointermove",Z),$&&t.removeEventListener("pointerup",$),M&&t.removeEventListener("pointerdown",M),z&&t.removeEventListener("pointercancel",z))}const _=s=>{Y(s)},B=({htmlElements:{to:s},index:{to:t},elements:i})=>{i instanceof NodeList&&t!==null&&(i.forEach(n=>n.style.opacity="1"),i[t].style.opacity="0"),s&&s.forEach(n=>{const e=Number(n.dataset.vistaviewPos);e!==0?(n.style.zIndex="1",n.style.left=100*e+"%"):n.style.zIndex="2"})},F=async({htmlElements:{from:s,to:t},images:{to:i},via:{next:n,prev:e},options:r,isReducedMotion:d},o)=>{if(!i)throw new Error("VistaView: images is null in defaultTransition()");if(d)return;const a=s.filter(c=>c.dataset.vistaviewPos==="0"||(n?c.dataset.vistaviewPos==="1":c.dataset.vistaviewPos==="-1"));await new Promise((c,l)=>{let h=0;if(o.aborted){l(new A("Transition aborted"));return}const m=v=>{if(o.aborted)return l(new A("Transition aborted"));if(v.currentTarget.removeEventListener("transitionend",m),h++,h<a.length)return;const f=t==null?void 0:t.find(w=>w.dataset.vistaviewPos==="0"),u=f?Number(f.dataset.vistaviewIndex):0,y=a.find(w=>Number(w.dataset.vistaviewIndex)===u),p=y==null?void 0:y.querySelector(".vistaview-image-highres");if(!p)return l(new Error("current image element not found"));if(!p.classList.contains("vistaview-image-loaded")||p.classList.contains("vistaview-image-settled"))return c(0);let x=0;const C=setInterval(()=>{if(o.aborted)return clearInterval(C),l(new A("Transition aborted"));if(x++,x>r.animationDurationBase/20*1.5)return clearInterval(C),c(0);if(p.classList.contains("vistaview-image-settled"))return f==null||f.classList.add("vistaview-image-settled"),clearInterval(C),c(0)},20)};a.forEach(v=>{v.style.transition=`translate ${r.animationDurationBase*.5}ms ease-out`,v.style.translate=n?"-100%":e?"100%":"0%",v.addEventListener("transitionend",m)})})},N=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),R(s)};class A extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const H={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",V(),"close"],bottomCenter:["description"]}},D={somethingOpened:null};class st{constructor(t,i){g(this,"options");g(this,"elements");g(this,"isReducedMotion");g(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n,e,r;const i=this._value;this._value=t;for(const d in(n=this._vistaView)==null?void 0:n.transitionAbortControllers)(e=this._vistaView)==null||e.transitionAbortControllers[d].abort();(r=this._vistaView)==null||r.swap(i,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});g(this,"rootElm",null);g(this,"imageContainerElm",null);g(this,"customControls",{});g(this,"currentImages",null);g(this,"currentItems",null);g(this,"navActive",!0);g(this,"isZoomed",!1);g(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});g(this,"defaultOnClickHandler",t=>t.preventDefault());g(this,"onResizeHandler",null);g(this,"onKeyDown",null);g(this,"userSetup",B);g(this,"userTransition",F);g(this,"userClose",N);g(this,"userInit",_);g(this,"onZoomedPointerDown",null);g(this,"onZoomedPointerMove",null);g(this,"onZoomedPointerUp",null);g(this,"transitionAbortControllers",{});g(this,"loadImageTimeout",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...H,...i||{},controls:{...H.controls,...(i==null?void 0:i.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,e)=>{n.dataset.vistaviewIndex=e.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}async swap(t,i){var l,h,m;if(!D.somethingOpened||t===i||t===null)return;if(!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:e}=this.getCurrentIndexes(i),r=this.getImages(n),d=r.map((v,f)=>X(v,e[f])),o={htmlElements:{from:this.currentItems,to:d},images:{from:this.currentImages,to:r},index:{from:t,to:i},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),(l=this.currentItems)==null||l.forEach(v=>{v.classList.add("vistaview-image--ending")});const a=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15);this.transitionAbortControllers[a]=new AbortController;try{await this.userTransition(o,this.transitionAbortControllers[a].signal)}catch(v){v instanceof A||console.warn(v)}delete this.transitionAbortControllers[a];const c=d.find(v=>v.dataset.vistaviewPos==="0");if(c){const v=c.dataset.vistaviewIndex,f=this.currentItems.find(y=>y.dataset.vistaviewIndex===v),u=f==null?void 0:f.querySelector(".vistaview-image-highres");if(u){const y=c.querySelector(".vistaview-image-highres");y.setAttribute("class",u.getAttribute("class")||""),y.setAttribute("style",u.getAttribute("style")||""),y.classList.remove("vistaview-image--zooming")}}this.imageContainerElm.innerHTML="",d.forEach(v=>{this.imageContainerElm.appendChild(v)}),this.setInitialDimPos(),this.currentImages=r,this.currentItems=d,this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(m=(h=this.options).onImageView)==null||m.call(h,o),this.loadImageTimeout&&clearTimeout(this.loadImageTimeout),this.loadImageTimeout=setTimeout(()=>{this.loadImages()},333)}setZoomed(t){var i,n,e,r,d,o;if(this.isZoomed!==t){if(this.isZoomed){let a=this.isZoomed;if(a.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((i=a.parentElement)==null||i.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=a.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((e=a.parentElement)==null||e.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,h=0,m=0,v=0,f=0;this.onZoomedPointerDown=u=>{u.preventDefault(),u.stopPropagation(),a=!0,c=u.pageX,l=u.pageY,t.setPointerCapture(u.pointerId)},this.onZoomedPointerMove=u=>{if(!a)return;u.preventDefault(),v=u.pageX-c,f=u.pageY-l;const y=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),p=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:x,minDiffY:C,maxDiffY:w,minDiffX:I}=O(y,p),b=Math.min(x,Math.max(I,h+v)),S=Math.min(w,Math.max(C,m+f));v=b-h,f=S-m,t==null||t.style.setProperty("--pointer-diff-x",`${b}px`),t==null||t.style.setProperty("--pointer-diff-y",`${S}px`)},this.onZoomedPointerUp=u=>{a=!1,t.releasePointerCapture(u.pointerId),h+=v,m+=f,v=0,f=0},(r=t==null?void 0:t.parentElement)==null||r.addEventListener("pointerdown",this.onZoomedPointerDown),(d=t==null?void 0:t.parentElement)==null||d.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var r,d,o,a,c;const t=(r=this.rootElm)==null?void 0:r.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height;t.dataset.vistaviewInitialWidth||(t.dataset.vistaviewInitialWidth=i.toString()),t.dataset.vistaviewInitialHeight||(t.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(t);const e=(t.naturalWidth||0)*this.options.maxZoomLevel;if(i&&e&&i<e){const l=Math.min(i+this.options.zoomStep,e);t.style.width=`${l}px`;const h=l/i*n;t.style.height=`${h}px`,(o=(d=this.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=l.toString(),t.dataset.vistaviewCurrentHeight=h.toString(),l===e&&((c=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-in-btn"))==null||c.setAttribute("disabled","true"))}}zoomOut(){var d,o,a,c,l;const t=(d=this.rootElm)==null?void 0:d.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height,e=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,r=h=>{h.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",r))};if(t.addEventListener("transitionend",r),t.classList.add("vistaview-image--zooming-out"),i&&e&&i>e){const h=Math.max(i-this.options.zoomStep,e);t.style.width=`${h}px`;const m=h/i*n;t.style.height=`${m}px`,(a=(o=this.rootElm)==null?void 0:o.querySelector("button.vistaview-zoom-in-btn"))==null||a.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=h.toString(),t.dataset.vistaviewCurrentHeight=m.toString();const{maxDiffX:v,minDiffY:f,maxDiffY:u,minDiffX:y}=O(h,m);let p=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");p=Math.min(v,Math.max(y,p)),x=Math.min(u,Math.max(f,x)),t==null||t.style.setProperty("--pointer-diff-x",`${p}px`),t==null||t.style.setProperty("--pointer-diff-y",`${x}px`),h===e&&((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((i,n)=>{const e=this.elements[i];if(e instanceof HTMLElement){const r=e.querySelector("img"),d=e.getAttribute("href")||"",o=e.getAttribute("src")||"",a=e.dataset.vistaviewSrc||d||o||(r==null?void 0:r.src)||"",c=e.dataset.vistaviewAlt||e.getAttribute("alt")||(r==null?void 0:r.alt)||"",l=e.dataset.vistaviewThumb||(r==null?void 0:r.src)||d||o||"";return{index:t[n],src:a,alt:c,thumb:l,imageElm:e instanceof HTMLImageElement?e:r,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var c,l;if(!this.rootElm)return;const t=(c=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:c.dataset.vistaviewIndex,i=((l=this.currentImages)==null?void 0:l.find(h=>h.index===Number(t)))||null;if(!i)return;const n=i.imageElm?L(i.imageElm):void 0,e=i.anchorElm?L(i.anchorElm):void 0,r=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,d=(e==null?void 0:e.height)||(n==null?void 0:n.height)||0,o=((e==null?void 0:e.left)||(n==null?void 0:n.left)||0)+r/2,a=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+d/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",r+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",d+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-left",o+"px"),this.rootElm.style.setProperty("--vistaview-image-border-radius",k(e==null?void 0:e.borderRadius)||k(n==null?void 0:n.borderRadius)||"0px")}updateZoomButtonsVisibility(){var e;const t=(e=this.rootElm)==null?void 0:e.querySelector('[data-vistaview-pos="0"] img.vistaview-image-highres');if(!t)return;const i=this;function n(){var l,h;const r=(l=i.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"),d=(h=i.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,a=t.naturalWidth*i.options.maxZoomLevel,c=o<a&&a>0;r&&(r.style.display=c?"":"none"),d&&(d.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((i,n)=>{const e=i,d=this.currentImages[n].imageElm,o={w:0,h:0};if(d){const{width:c,height:l}=j(d);o.w=Math.min(d.width,c),o.h=Math.min(d.height,l)}const a=()=>{var l,h;if((l=e.parentElement)!=null&&l.classList.contains("vistaview-image--ending"))return;const c=()=>{var m;o.w&&o.h&&(e.style.width=`${o.w}px`,e.style.height=`${o.h}px`,e.style.setProperty("--vistaview-fitted-width",`${o.w}px`),e.style.setProperty("--vistaview-fitted-height",`${o.h}px`)),e.classList.add("vistaview-image-loaded"),e.width=e.naturalWidth,e.height=e.naturalHeight,setTimeout(()=>{var p,x,C;if((p=e.parentElement)!=null&&p.classList.contains("vistaview-image--ending"))return;let v=0;const f=()=>{var w,I;v++,!(v<3)&&(e.removeEventListener("transitionend",f),(I=(w=e.parentElement)==null?void 0:w.querySelector(".vistaview-image-lowres"))==null||I.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled"))},{width:u,height:y}=W(e);o.w&&o.h&&u===o.w&&y===o.h?((C=(x=e.parentElement)==null?void 0:x.querySelector(".vistaview-image-lowres"))==null||C.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled")):(e.addEventListener("transitionend",f),e.style.width=`${u}px`,e.style.height=`${y}px`)},100),(m=i.parentElement)!=null&&m.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((h=this.rootElm)!=null&&h.classList.contains("vistaview--opened"))c();else{const m=setInterval(()=>{var v;(v=this.rootElm)!=null&&v.classList.contains("vistaview--opened")&&(clearInterval(m),c())},50)}};e.complete&&e.naturalWidth>0?a():e.onload=a})}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 i=this.options.preloads,n=this.elements.length,e=n<1||!i?[t]:[...new Set([...Array.from({length:i},(d,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(d,o)=>(t+1+o)%n)])],r=n<1||!i?[0]:e.map((d,o)=>o-Math.floor(e.length/2));return{images:e,positions:r}}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 i;this.setInitialDimPos();const t=(i=this.rootElm)==null?void 0:i.querySelectorAll(".vistaview-image-highres.vistaview-image-loaded");t==null||t.forEach(n=>{const e=n,{width:r,height:d}=W(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=r.toString(),e.dataset.vistaviewInitialHeight=d.toString()):(e.style.width=`${r}px`,e.style.height=`${d}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,a,c,l,h,m,v,f,u,y,p,x,C;if(D.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(D.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(nt({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((o=this.rootElm)==null?void 0:o.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw D.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:i,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(i);const e=this.currentImages.map((w,I)=>X(w,n[I]));this.currentItems=e;const r={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(r),this.imageContainerElm.innerHTML="",this.currentItems.forEach(w=>{this.imageContainerElm.appendChild(w)});let d=0;this.rootElm.addEventListener("animationend",w=>{var I;w.currentTarget===this.rootElm&&(d++,d>=2&&((I=this.rootElm)==null||I.classList.add("vistaview--opened")))}),(a=this.rootElm.querySelector(".vistaview-close-btn"))==null||a.addEventListener("click",()=>this.close()),(c=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||c.addEventListener("click",()=>this.zoomIn()),(l=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||l.addEventListener("click",()=>this.zoomOut()),(h=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||h.addEventListener("click",()=>this.prev()),(m=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||m.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(w=>{typeof w!="string"&&(this.customControls[w.name]=w)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(w=>{w.addEventListener("click",I=>{const b=this.customControls[I.currentTarget.dataset.vistaviewCustomControl],S=this.currentImages.find(T=>T.index===this.currentIndex.value);b&&S&&(b.onClick.constructor.name==="AsyncFunction"?(w.classList.add("vistaview-button--loading"),b.onClick(S).finally(()=>{w.classList.remove("vistaview-button--loading")})):b.onClick(S))})}),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.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((v=this.rootElm.querySelector(".vistaview-prev-btn"))==null||v.classList.add("vistaview-ui--none"),(f=this.rootElm.querySelector(".vistaview-next-btn"))==null||f.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-index-display"))==null||u.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(p=(y=this.options).onOpen)==null||p.call(y,r),(C=(x=this.options).onImageView)==null||C.call(x,r)}async close(t=!0){var n,e,r;if(D.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(d=>{var a;let o;(a=this.rootElm)==null||a.addEventListener("transitionend",c=>{c.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{d()},333))})}));const i={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),(r=(e=this.options).onClose)==null||r.call(e,i),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);for(const d in this.transitionAbortControllers)this.transitionAbortControllers[d].abort();this.transitionAbortControllers={},D.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.dataset.vistaviewIndex&&delete t.dataset.vistaviewIndex,t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}view(t,i){D.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=i||{next:!1,prev:!1},this.currentIndex.value=t)}next(){D.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){D.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return D.somethingOpened===this?this.currentIndex.value:-1}}function ot(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let i=0;i<t.length;i++){const n=t[i];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${i} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const i=s;for(let n=0;n<i.length;n++)if(!i[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function rt({elements:s,...t}){if(!s)throw new Error("No elements");let i=ot(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new st(i,t);return{open:(e=0)=>n.open(e),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:e=>{n.view(e)}}}E.DefaultOptions=H,E.VistaViewTransitionAbortedError=A,E.defaultClose=N,E.defaultInit=_,E.defaultSetup=B,E.defaultTransition=F,E.removeTouchActions=R,E.setTouchActions=Y,E.vistaView=rt,E.vistaViewDownload=V,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
|
16
|
+
</div>`)}let M=null,$=null,Z=null,z=null;function Y(s){R(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,r=0,d=0,o=null,a=0,c=!1;M=l=>{l.preventDefault(),l.stopPropagation(),s.isZoomed===!1&&(c=!0,n=l.pageX,e=l.pageY,r=l.pageX,d=l.pageY,a=Date.now(),o=null,t.setPointerCapture(l.pointerId))},$=l=>{if(l.preventDefault(),l.stopPropagation(),s.isZoomed!==!1||!c)return;const h=l.pageX-n,m=l.pageY-e;r=l.pageX,d=l.pageY,Math.abs(h)>=Math.abs(m)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),o=!0):Math.abs(m)>Math.abs(h)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${m}px`),o=!1)},z=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1,o=null;const h=Array.from(t.querySelectorAll(".vistaview-item"));t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(m=>{m.style.transition="",m.style.translate=""})},Z=l=>{if(l.preventDefault(),l.stopPropagation(),t.releasePointerCapture(l.pointerId),s.isZoomed!==!1||!c)return;c=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),m=r-n,v=d-e,w=Date.now()-a,u=m/w,p=v/w,f=s.options.touchSpeedThreshold||.5,I=h.find(b=>b.dataset.vistaviewPos==="0"),C=Number(I.dataset.vistaviewIndex);function y(){h[0].removeEventListener("transitionend",y),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(b=>{b.style.transition="",b.style.translate=""})}function L(b="0%",D="0%"){h.forEach(T=>{T.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,T.style.translate=`${b} ${D}`})}if(u<-f||u>f){let b=function(){h[0].removeEventListener("transitionend",b),setTimeout(()=>{const D=s.isReducedMotion;s.isReducedMotion=!0,y(),s.view(u<-f?(C+1)%i:(C-1+i)%i,{next:u<-f,prev:u>f}),s.isReducedMotion=D},100)};L(u<-f?"-100%":"100%"),h[0].addEventListener("transitionend",b)}else p<-f||p>f?(s.close(),L("0%","0%")):(h[0].addEventListener("transitionend",y),L("0%"),u===0&&p===0&&s.zoomIn())},t.addEventListener("pointermove",$),t.addEventListener("pointerup",Z),t.addEventListener("pointerdown",M),t.addEventListener("pointercancel",z)}function R(s){const t=s.imageContainerElm;t&&($&&t.removeEventListener("pointermove",$),Z&&t.removeEventListener("pointerup",Z),M&&t.removeEventListener("pointerdown",M),z&&t.removeEventListener("pointercancel",z))}const B=s=>{Y(s)},F=({htmlElements:{to:s},index:{to:t},elements:i})=>{i instanceof NodeList&&t!==null&&(i.forEach(n=>n.style.opacity="1"),i[t].style.opacity="0"),s&&s.forEach(n=>{const e=Number(n.dataset.vistaviewPos);e!==0?(n.style.zIndex="1",n.style.left=100*e+"%"):n.style.zIndex="2"})},_=async({htmlElements:{from:s,to:t},images:{to:i},via:{next:n,prev:e},options:r,isReducedMotion:d},o)=>{if(!i)throw new Error("VistaView: images is null in defaultTransition()");if(d)return;const a=s.filter(c=>c.dataset.vistaviewPos==="0"||(n?c.dataset.vistaviewPos==="1":c.dataset.vistaviewPos==="-1"));await new Promise((c,l)=>{let h=0;if(o.aborted){l(new A("Transition aborted"));return}const m=v=>{if(o.aborted)return l(new A("Transition aborted"));if(v.currentTarget.removeEventListener("transitionend",m),h++,h<a.length)return;const w=t==null?void 0:t.find(y=>y.dataset.vistaviewPos==="0"),u=w?Number(w.dataset.vistaviewIndex):0,p=a.find(y=>Number(y.dataset.vistaviewIndex)===u),f=p==null?void 0:p.querySelector(".vistaview-image-highres");if(!f)return l(new Error("current image element not found"));if(!f.classList.contains("vistaview-image-loaded")||f.classList.contains("vistaview-image-settled"))return c(0);let I=0;const C=setInterval(()=>{if(o.aborted)return clearInterval(C),l(new A("Transition aborted"));if(I++,I>r.animationDurationBase/20*1.5)return clearInterval(C),c(0);if(f.classList.contains("vistaview-image-settled"))return w==null||w.classList.add("vistaview-image-settled"),clearInterval(C),c(0)},20)};a.forEach(v=>{v.style.transition=`translate ${r.animationDurationBase*.5}ms ease-out`,v.style.translate=n?"-100%":e?"100%":"0%",v.addEventListener("transitionend",m)})})},N=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),R(s)};class A extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const H={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",V(),"close"],bottomCenter:["description"]}},S={somethingOpened:null};class st{constructor(t,i){g(this,"options");g(this,"elements");g(this,"isReducedMotion");g(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n,e,r;const i=this._value;this._value=t;for(const d in(n=this._vistaView)==null?void 0:n.transitionAbortControllers)(e=this._vistaView)==null||e.transitionAbortControllers[d].abort();(r=this._vistaView)==null||r.swap(i,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});g(this,"rootElm",null);g(this,"imageContainerElm",null);g(this,"customControls",{});g(this,"currentImages",null);g(this,"currentItems",null);g(this,"navActive",!0);g(this,"isZoomed",!1);g(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});g(this,"defaultOnClickHandler",t=>t.preventDefault());g(this,"onResizeHandler",null);g(this,"onKeyDown",null);g(this,"userSetup",F);g(this,"userTransition",_);g(this,"userClose",N);g(this,"userInit",B);g(this,"onZoomedPointerDown",null);g(this,"onZoomedPointerMove",null);g(this,"onZoomedPointerUp",null);g(this,"transitionAbortControllers",{});g(this,"loadImageTimeout",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...H,...i||{},controls:{...H.controls,...(i==null?void 0:i.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,e)=>{n.dataset.vistaviewIndex=e.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}setFullSizeImageDim(t){var r,d;const i=t.getBoundingClientRect(),{width:n,height:e}=W(t);if(n===i.width&&e===i.height)(d=(r=t.parentElement)==null?void 0:r.querySelector(".vistaview-image-lowres"))==null||d.classList.add("vistaview-image--hidden"),t.classList.add("vistaview-image-settled");else{let o=0;const a=()=>{var c,l;o++,!(o<3)&&(t.removeEventListener("transitionend",a),(l=(c=t.parentElement)==null?void 0:c.querySelector(".vistaview-image-lowres"))==null||l.classList.add("vistaview-image--hidden"),t.classList.add("vistaview-image-settled"))};requestAnimationFrame(()=>{t.addEventListener("transitionend",a),t.style.width=`${n}px`,t.style.height=`${e}px`})}}async swap(t,i){var l,h,m;if(!S.somethingOpened||t===i||t===null)return;if(!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:e}=this.getCurrentIndexes(i),r=this.getImages(n),d=r.map((v,w)=>X(v,e[w])),o={htmlElements:{from:this.currentItems,to:d},images:{from:this.currentImages,to:r},index:{from:t,to:i},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),(l=this.currentItems)==null||l.forEach(v=>{v.classList.add("vistaview-image--ending")});const a=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15);this.transitionAbortControllers[a]=new AbortController;try{await this.userTransition(o,this.transitionAbortControllers[a].signal)}catch(v){v instanceof A||console.warn(v)}delete this.transitionAbortControllers[a];const c=d.find(v=>v.dataset.vistaviewPos==="0");if(c){const v=c.dataset.vistaviewIndex,w=this.currentItems.find(p=>p.dataset.vistaviewIndex===v),u=w==null?void 0:w.querySelector(".vistaview-image-highres");if(u){const p=c.querySelector(".vistaview-image-highres");if(p.setAttribute("class",u.getAttribute("class")||""),p.setAttribute("style",u.getAttribute("style")||""),p.classList.remove("vistaview-image--zooming"),u.classList.contains("vistaview-image-loaded")&&!u.classList.contains("vistaview-image-settled")){const f=u.getBoundingClientRect();p.dataset.vistaviewCurrentWidth=f.width.toString(),p.dataset.vistaviewCurrentHeight=f.height.toString(),p.style.width=`${f.width}px`,p.style.height=`${f.height}px`}}}this.imageContainerElm.innerHTML="",d.forEach(v=>{var f;const w=v.querySelector(".vistaview-image-highres"),u=!!w.classList.contains("vistaview-image-loaded"),p=!!w.classList.contains("vistaview-image-settled");this.imageContainerElm.appendChild(v),u&&!p?this.setFullSizeImageDim(w):u&&p&&((f=v==null?void 0:v.querySelector(".vistaview-image-lowres"))==null||f.classList.add("vistaview-image--hidden"))}),this.setInitialDimPos(),this.currentImages=r,this.currentItems=d,this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(m=(h=this.options).onImageView)==null||m.call(h,o),this.loadImageTimeout&&clearTimeout(this.loadImageTimeout),this.loadImageTimeout=setTimeout(()=>{this.loadImages()},333)}setZoomed(t){var i,n,e,r,d,o;if(this.isZoomed!==t){if(this.isZoomed){let a=this.isZoomed;if(a.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((i=a.parentElement)==null||i.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=a.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((e=a.parentElement)==null||e.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,h=0,m=0,v=0,w=0;this.onZoomedPointerDown=u=>{u.preventDefault(),u.stopPropagation(),a=!0,c=u.pageX,l=u.pageY,t.setPointerCapture(u.pointerId)},this.onZoomedPointerMove=u=>{if(!a)return;u.preventDefault(),v=u.pageX-c,w=u.pageY-l;const p=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),f=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:I,minDiffY:C,maxDiffY:y,minDiffX:L}=O(p,f),b=Math.min(I,Math.max(L,h+v)),D=Math.min(y,Math.max(C,m+w));v=b-h,w=D-m,t==null||t.style.setProperty("--pointer-diff-x",`${b}px`),t==null||t.style.setProperty("--pointer-diff-y",`${D}px`)},this.onZoomedPointerUp=u=>{a=!1,t.releasePointerCapture(u.pointerId),h+=v,m+=w,v=0,w=0},(r=t==null?void 0:t.parentElement)==null||r.addEventListener("pointerdown",this.onZoomedPointerDown),(d=t==null?void 0:t.parentElement)==null||d.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var r,d,o,a,c;const t=(r=this.rootElm)==null?void 0:r.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height;t.dataset.vistaviewInitialWidth||(t.dataset.vistaviewInitialWidth=i.toString()),t.dataset.vistaviewInitialHeight||(t.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(t);const e=(t.naturalWidth||0)*this.options.maxZoomLevel;if(i&&e&&i<e){const l=Math.min(i+this.options.zoomStep,e);t.style.width=`${l}px`;const h=l/i*n;t.style.height=`${h}px`,(o=(d=this.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=l.toString(),t.dataset.vistaviewCurrentHeight=h.toString(),l===e&&((c=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-in-btn"))==null||c.setAttribute("disabled","true"))}}zoomOut(){var d,o,a,c,l;const t=(d=this.rootElm)==null?void 0:d.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height,e=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,r=h=>{h.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",r))};if(t.addEventListener("transitionend",r),t.classList.add("vistaview-image--zooming-out"),i&&e&&i>e){const h=Math.max(i-this.options.zoomStep,e);t.style.width=`${h}px`;const m=h/i*n;t.style.height=`${m}px`,(a=(o=this.rootElm)==null?void 0:o.querySelector("button.vistaview-zoom-in-btn"))==null||a.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=h.toString(),t.dataset.vistaviewCurrentHeight=m.toString();const{maxDiffX:v,minDiffY:w,maxDiffY:u,minDiffX:p}=O(h,m);let f=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),I=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");f=Math.min(v,Math.max(p,f)),I=Math.min(u,Math.max(w,I)),t==null||t.style.setProperty("--pointer-diff-x",`${f}px`),t==null||t.style.setProperty("--pointer-diff-y",`${I}px`),h===e&&((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((i,n)=>{const e=this.elements[i];if(e instanceof HTMLElement){const r=e.querySelector("img"),d=e.getAttribute("href")||"",o=e.getAttribute("src")||"",a=e.dataset.vistaviewSrc||d||o||(r==null?void 0:r.src)||"",c=e.dataset.vistaviewAlt||e.getAttribute("alt")||(r==null?void 0:r.alt)||"",l=e.dataset.vistaviewThumb||(r==null?void 0:r.src)||d||o||"";return{index:t[n],src:a,alt:c,thumb:l,imageElm:e instanceof HTMLImageElement?e:r,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var c,l;if(!this.rootElm)return;const t=(c=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:c.dataset.vistaviewIndex,i=((l=this.currentImages)==null?void 0:l.find(h=>h.index===Number(t)))||null;if(!i)return;const n=i.imageElm?x(i.imageElm):void 0,e=i.anchorElm?x(i.anchorElm):void 0,r=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,d=(e==null?void 0:e.height)||(n==null?void 0:n.height)||0,o=((e==null?void 0:e.left)||(n==null?void 0:n.left)||0)+r/2,a=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+d/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",r+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",d+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-left",o+"px"),this.rootElm.style.setProperty("--vistaview-image-border-radius",k(e==null?void 0:e.borderRadius)||k(n==null?void 0:n.borderRadius)||"0px")}updateZoomButtonsVisibility(){var e;const t=(e=this.rootElm)==null?void 0:e.querySelector('[data-vistaview-pos="0"] img.vistaview-image-highres');if(!t)return;const i=this;function n(){var l,h;const r=(l=i.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"),d=(h=i.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,a=t.naturalWidth*i.options.maxZoomLevel,c=o<a&&a>0;r&&(r.style.display=c?"":"none"),d&&(d.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((i,n)=>{const e=i,d=this.currentImages[n].imageElm,o={w:0,h:0};if(d){const{width:c,height:l}=j(d);o.w=Math.min(d.width,c),o.h=Math.min(d.height,l)}const a=()=>{var l,h;if((l=e.parentElement)!=null&&l.classList.contains("vistaview-image--ending"))return;const c=()=>{var m;o.w&&o.h&&(e.style.width=`${o.w}px`,e.style.height=`${o.h}px`,e.style.setProperty("--vistaview-fitted-width",`${o.w}px`),e.style.setProperty("--vistaview-fitted-height",`${o.h}px`)),e.classList.add("vistaview-image-loaded"),e.width=e.naturalWidth,e.height=e.naturalHeight,setTimeout(()=>{var v;(v=e.parentElement)!=null&&v.classList.contains("vistaview-image--ending")||this.setFullSizeImageDim(e)},100),(m=i.parentElement)!=null&&m.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((h=this.rootElm)!=null&&h.classList.contains("vistaview--opened"))c();else{const m=setInterval(()=>{var v;(v=this.rootElm)!=null&&v.classList.contains("vistaview--opened")&&(clearInterval(m),c())},50)}};e.complete&&e.naturalWidth>0?a():e.onload=a})}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 i=this.options.preloads,n=this.elements.length,e=n<1||!i?[t]:[...new Set([...Array.from({length:i},(d,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(d,o)=>(t+1+o)%n)])],r=n<1||!i?[0]:e.map((d,o)=>o-Math.floor(e.length/2));return{images:e,positions:r}}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 i;this.setInitialDimPos();const t=(i=this.rootElm)==null?void 0:i.querySelectorAll(".vistaview-image-highres.vistaview-image-loaded");t==null||t.forEach(n=>{const e=n,{width:r,height:d}=W(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=r.toString(),e.dataset.vistaviewInitialHeight=d.toString()):(e.style.width=`${r}px`,e.style.height=`${d}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,a,c,l,h,m,v,w,u,p,f,I,C;if(S.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(S.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(nt({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((o=this.rootElm)==null?void 0:o.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw S.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:i,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(i);const e=this.currentImages.map((y,L)=>X(y,n[L]));this.currentItems=e;const r={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(r),this.imageContainerElm.innerHTML="",this.currentItems.forEach(y=>{this.imageContainerElm.appendChild(y)});let d=0;this.rootElm.addEventListener("animationend",y=>{var L;y.currentTarget===this.rootElm&&(d++,d>=2&&((L=this.rootElm)==null||L.classList.add("vistaview--opened")))}),(a=this.rootElm.querySelector(".vistaview-close-btn"))==null||a.addEventListener("click",()=>this.close()),(c=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||c.addEventListener("click",()=>this.zoomIn()),(l=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||l.addEventListener("click",()=>this.zoomOut()),(h=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||h.addEventListener("click",()=>this.prev()),(m=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||m.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(y=>{typeof y!="string"&&(this.customControls[y.name]=y)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(y=>{y.addEventListener("click",L=>{const b=this.customControls[L.currentTarget.dataset.vistaviewCustomControl],D=this.currentImages.find(T=>T.index===this.currentIndex.value);b&&D&&(b.onClick.constructor.name==="AsyncFunction"?(y.classList.add("vistaview-button--loading"),b.onClick(D).finally(()=>{y.classList.remove("vistaview-button--loading")})):b.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.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((v=this.rootElm.querySelector(".vistaview-prev-btn"))==null||v.classList.add("vistaview-ui--none"),(w=this.rootElm.querySelector(".vistaview-next-btn"))==null||w.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-index-display"))==null||u.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(f=(p=this.options).onOpen)==null||f.call(p,r),(C=(I=this.options).onImageView)==null||C.call(I,r)}async close(t=!0){var n,e,r;if(S.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(d=>{var a;let o;(a=this.rootElm)==null||a.addEventListener("transitionend",c=>{c.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{d()},333))})}));const i={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),(r=(e=this.options).onClose)==null||r.call(e,i),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);for(const d in this.transitionAbortControllers)this.transitionAbortControllers[d].abort();this.transitionAbortControllers={},S.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.dataset.vistaviewIndex&&delete t.dataset.vistaviewIndex,t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}view(t,i){S.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=i||{next:!1,prev:!1},this.currentIndex.value=t)}next(){S.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){S.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return S.somethingOpened===this?this.currentIndex.value:-1}}function ot(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let i=0;i<t.length;i++){const n=t[i];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${i} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const i=s;for(let n=0;n<i.length;n++)if(!i[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function rt({elements:s,...t}){if(!s)throw new Error("No elements");let i=ot(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new st(i,t);return{open:(e=0)=>n.open(e),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:e=>{n.view(e)}}}E.DefaultOptions=H,E.VistaViewTransitionAbortedError=A,E.defaultClose=N,E.defaultInit=B,E.defaultSetup=F,E.defaultTransition=_,E.removeTouchActions=R,E.setTouchActions=Y,E.vistaView=rt,E.vistaViewDownload=V,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|