vistaview 0.3.15 → 0.5.3
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 -7
- package/dist/lib/pinch-detector.d.ts +33 -0
- package/dist/lib/pinch-detector.d.ts.map +1 -0
- package/dist/lib/vista-view.d.ts.map +1 -1
- package/dist/vistaview.cjs +6 -6
- package/dist/vistaview.js +301 -287
- package/dist/vistaview.umd.js +6 -6
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# VistaView
|
|
2
2
|
|
|
3
|
+
⚠️ **This is still in development, do not use**
|
|
4
|
+
|
|
3
5
|
A lightweight, modern image lightbox library for the web. Zero dependencies, framework-agnostic, and highly customizable.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
@@ -290,25 +292,25 @@ dist/svelte.js 0.54 kB │ gzip: 0.27 kB
|
|
|
290
292
|
dist/solid.js 1.11 kB │ gzip: 0.52 kB
|
|
291
293
|
dist/vue.js 1.29 kB │ gzip: 0.56 kB
|
|
292
294
|
dist/react.js 1.54 kB │ gzip: 0.57 kB
|
|
293
|
-
dist/vistaview.js 38.
|
|
294
|
-
[vite:dts] Declaration files built in
|
|
295
|
+
dist/vistaview.js 38.86 kB │ gzip: 9.90 kB
|
|
296
|
+
[vite:dts] Declaration files built in 694ms.
|
|
295
297
|
|
|
296
298
|
dist/vistaview.css 10.34 kB │ gzip: 1.85 kB
|
|
297
299
|
dist/svelte.cjs 0.48 kB │ gzip: 0.29 kB
|
|
298
300
|
dist/solid.cjs 0.92 kB │ gzip: 0.50 kB
|
|
299
301
|
dist/vue.cjs 1.00 kB │ gzip: 0.51 kB
|
|
300
302
|
dist/react.cjs 1.25 kB │ gzip: 0.52 kB
|
|
301
|
-
dist/vistaview.cjs
|
|
302
|
-
✓ built in
|
|
303
|
+
dist/vistaview.cjs 30.20 kB │ gzip: 8.55 kB
|
|
304
|
+
✓ built in 811ms
|
|
303
305
|
vite v6.4.1 building for production...
|
|
304
306
|
✓ 6 modules transformed.
|
|
305
307
|
|
|
306
308
|
[vite:dts] Start generate declaration files...
|
|
307
309
|
dist/vistaview.css 10.34 kB │ gzip: 1.85 kB
|
|
308
|
-
dist/vistaview.umd.js
|
|
309
|
-
[vite:dts] Declaration files built in
|
|
310
|
+
dist/vistaview.umd.js 30.35 kB │ gzip: 8.67 kB
|
|
311
|
+
[vite:dts] Declaration files built in 649ms.
|
|
310
312
|
|
|
311
|
-
✓ built in
|
|
313
|
+
✓ built in 738ms
|
|
312
314
|
```
|
|
313
315
|
|
|
314
316
|
## License
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface PinchGestureState {
|
|
2
|
+
isActive: boolean;
|
|
3
|
+
startDistance: number;
|
|
4
|
+
currentDistance: number;
|
|
5
|
+
scale: number;
|
|
6
|
+
center: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
10
|
+
direction: 'in' | 'out' | null;
|
|
11
|
+
touches: TouchList | null;
|
|
12
|
+
}
|
|
13
|
+
export declare class PinchDetector {
|
|
14
|
+
private pinchState;
|
|
15
|
+
private element;
|
|
16
|
+
private pinchStartListeners;
|
|
17
|
+
private pinchMoveListeners;
|
|
18
|
+
private pinchEndListeners;
|
|
19
|
+
constructor(element: HTMLElement);
|
|
20
|
+
private getTouchDistance;
|
|
21
|
+
private getTouchCenter;
|
|
22
|
+
private onTouchStart;
|
|
23
|
+
private onTouchMove;
|
|
24
|
+
private onTouchEnd;
|
|
25
|
+
private attachEventListeners;
|
|
26
|
+
cleanup(): void;
|
|
27
|
+
isPinching(): boolean;
|
|
28
|
+
getState(): PinchGestureState;
|
|
29
|
+
onPinchStart(listener: (state: PinchGestureState) => void): () => void;
|
|
30
|
+
onPinchMove(listener: (state: PinchGestureState) => void): () => void;
|
|
31
|
+
onPinchEnd(listener: (state: PinchGestureState) => void): () => void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=pinch-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5B,KAAK,CAAC,IAAI,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA+DvC,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;IAWnE,IAAI,IAAI,IAAI;IAKZ,IAAI,IAAI,IAAI;IAKZ,eAAe,IAAI,MAAM;CAG1B"}
|
package/dist/vistaview.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
style="${n?`object-fit:${n};`:""}${
|
|
1
|
+
"use strict";var J=Object.defineProperty;var Q=(s,t,i)=>t in s?J(s,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[t]=i;var p=(s,t,i)=>Q(s,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function q(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 $=null;function tt(){return $||(window.trustedTypes||(window.trustedTypes={createPolicy:(s,t)=>t}),$=window.trustedTypes.createPolicy("vistaView-policy",{createHTML:s=>s,createScript:()=>{throw new Error("Not implemented")},createScriptURL:()=>{throw new Error("Not implemented")}}),$)}function F(s){const i=tt().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 et(s){const i=window.getComputedStyle(s).objectFit||"",{width:n,height:e}=s.getBoundingClientRect(),r=s.naturalWidth,l=s.naturalHeight;if(!i)return{width:n,height:e};if(!r||!l)return{width:n,height:e};const o=r/l,c=n/e;switch(i){case"fill":return{width:n,height:e};case"none":return{width:r,height:l};case"contain":return o>c?{width:n,height:n/o}:{width:e*o,height:e};case"cover":return o<c?{width:n,height:n/o}:{width:e*o,height:e};case"scale-down":{const a={width:r,height:l},d=o>c?{width:n,height:n/o}:{width:e*o,height:e};return d.width<=a.width&&d.height<=a.height?d:a}}return{width:n,height:e}}function O(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,l=t/i;let o,c;return r>l?(o=t,c=t/r):(c=i,o=i*r),{width:o,height:c}}function it(s,t){const i=window.innerHeight,n=window.innerWidth,e=s,r=t,l=Math.max(0,(e-n)/2)+n/2,o=Math.max(0,(r-i)/2)+i/2,c=-l,a=-o;return{maxDiffX:l,minDiffY:a,maxDiffY:o,minDiffX:c}}const nt='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',st='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',ot='<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>',rt='<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>',at='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',lt='<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 X(){return{name:"download",icon:lt,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 dt(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${ot}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${rt}</button>`;case"close":return`<button class="vistaview-close-btn">${at}</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 W(s,t){var d,h;const i=s.imageElm?getComputedStyle(s.imageElm):null,n=(i==null?void 0:i.objectFit)||"",e=((d=s.imageElm)==null?void 0:d.naturalWidth)||"",r=((h=s.imageElm)==null?void 0:h.naturalHeight)||"",l=(i==null?void 0:i.width)||"",o=(i==null?void 0:i.height)||"",c=document.createElement("div");c.className="vistaview-item",c.dataset.vistaviewPos=`${t!==void 0?t:""}`,c.dataset.vistaviewIndex=s.index.toString();const a=F(`<img class="vistaview-image-lowres"
|
|
2
|
+
style="${n?`object-fit:${n};`:""}${l?`width:${l};`:""}${o?`height:${o};`:""}"
|
|
3
3
|
src="${s.thumb||s.src}"
|
|
4
4
|
alt="${s.alt||""}"
|
|
5
5
|
${e?`width="${e}"`:""}
|
|
6
6
|
${r?`height="${r}"`:""}
|
|
7
7
|
/>
|
|
8
|
-
<img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return
|
|
8
|
+
<img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return c.appendChild(a),c}function ct({controls:s,isReducedMotion:t}){const i=e=>e?e.map(dt).join(""):"";return F(`<div class="vistaview-root${t?" vistaview--reduced-motion":""}" id="vistaview-root">
|
|
9
9
|
<div class="vistaview-container">
|
|
10
10
|
<div class="vistaview-image-container"></div>
|
|
11
11
|
<div class="vistaview-top-bar vistaview-ui"><div>${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>
|
|
12
12
|
<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>
|
|
13
|
-
<div class="vistaview-prev-btn vistaview-ui"><button>${
|
|
14
|
-
<div class="vistaview-next-btn vistaview-ui"><button>${
|
|
13
|
+
<div class="vistaview-prev-btn vistaview-ui"><button>${nt}</button></div>
|
|
14
|
+
<div class="vistaview-next-btn vistaview-ui"><button>${st}</button></div>
|
|
15
15
|
</div>
|
|
16
|
-
</div>`)}let M=null,$=null,z=null,A=null;function Y(s){T(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,r=0,a=0,o=null,l=0,c=!1;M=d=>{d.preventDefault(),d.stopPropagation(),s.isZoomed===!1&&(c=!0,n=d.pageX,e=d.pageY,r=d.pageX,a=d.pageY,l=Date.now(),o=null,t.setPointerCapture(d.pointerId))},$=d=>{if(d.preventDefault(),d.stopPropagation(),s.isZoomed!==!1||!c)return;const h=d.pageX-n,u=d.pageY-e;r=d.pageX,a=d.pageY,Math.abs(h)>=Math.abs(u)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),o=!0):Math.abs(u)>Math.abs(h)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${u}px`),o=!1)},A=d=>{if(d.preventDefault(),d.stopPropagation(),t.releasePointerCapture(d.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(u=>{u.style.transition="",u.style.translate=""})},z=d=>{if(d.preventDefault(),d.stopPropagation(),t.releasePointerCapture(d.pointerId),s.isZoomed!==!1||!c)return;c=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),u=r-n,p=a-e,f=Date.now()-l,v=u/f,E=p/f,g=s.options.touchSpeedThreshold||.5,x=h.find(y=>y.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(y=>{y.style.transition="",y.style.translate=""})}function b(y="0%",I="0%"){h.forEach(S=>{S.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,S.style.translate=`${y} ${I}`})}if(v<-g||v>g){let y=function(){h[0].removeEventListener("transitionend",y),setTimeout(()=>{const I=s.isReducedMotion,S=s.options.detectReducedMotion;s.isReducedMotion=!0,s.options.detectReducedMotion=!0,w(),s.view(v<-g?(C+1)%i:(C-1+i)%i,{next:v<-g,prev:v>g}),s.isReducedMotion=I,s.options.detectReducedMotion=S},100)};b(v<-g?"-100%":"100%"),h[0].addEventListener("transitionend",y)}else E<-g||E>g?(s.close(),b("0%","0%")):(h[0].addEventListener("transitionend",w),b("0%"),v===0&&E===0&&s.zoomIn())},t.addEventListener("pointermove",$),t.addEventListener("pointerup",z),t.addEventListener("pointerdown",M),t.addEventListener("pointercancel",A)}function T(s){const t=s.imageContainerElm;t&&($&&t.removeEventListener("pointermove",$),z&&t.removeEventListener("pointerup",z),M&&t.removeEventListener("pointerdown",M),A&&t.removeEventListener("pointercancel",A))}const F=s=>{Y(s)},_=({htmlElements:{to:s},index:{to:t},vistaView:i})=>{i.elements instanceof NodeList&&t!==null&&(i.elements.forEach(n=>n.style.opacity="1"),i.elements[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},via:{next:t,prev:i},vistaView:n},e)=>{if(n.options.detectReducedMotion&&n.isReducedMotion)return;const r=s.filter(a=>a.dataset.vistaviewPos==="0"||(t?a.dataset.vistaviewPos==="1":a.dataset.vistaviewPos==="-1"));await new Promise((a,o)=>{let l=0,c=!1;if(e.aborted){o(new D("Transition aborted"));return}const d=h=>{if(c)return o(new D("Transition aborted"));if(e.aborted)return c||(c=!0),o(new D("Transition aborted"));h.currentTarget.removeEventListener("transitionend",d),l++,l>=r.length&&a(0)};r.forEach(h=>{h.style.transition=`translate ${n.options.animationDurationBase*.5}ms ease-out`,h.style.translate=t?"-100%":i?"100%":"0%",h.addEventListener("transitionend",d)})})},V=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",X(),"close"],bottomCenter:["description"]}},L={somethingOpened:null};class ot{constructor(t,i){m(this,"options");m(this,"elements");m(this,"isReducedMotion");m(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 a in(n=this._vistaView)==null?void 0:n.transitionAbortControllers)(e=this._vistaView)==null||e.transitionAbortControllers[a].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}});m(this,"rootElm",null);m(this,"imageContainerElm",null);m(this,"customControls",{});m(this,"currentImages",null);m(this,"currentItems",null);m(this,"isZoomed",!1);m(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});m(this,"defaultOnClickHandler",t=>t.preventDefault());m(this,"onResizeHandler",null);m(this,"onKeyDown",null);m(this,"userSetup",_);m(this,"userTransition",B);m(this,"userClose",V);m(this,"userInit",F);m(this,"onZoomedPointerDown",null);m(this,"onZoomedPointerMove",null);m(this,"onZoomedPointerUp",null);m(this,"transitionAbortControllers",{});m(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,a;const i=t.getBoundingClientRect(),{width:n,height:e}=q(t);if(n===i.width&&e===i.height)(a=(r=t.parentElement)==null?void 0:r.querySelector(".vistaview-image-lowres"))==null||a.classList.add("vistaview-image--hidden"),t.classList.add("vistaview-image-settled");else{let o=0;const l=()=>{var c,d;o++,!(o<3)&&(t.removeEventListener("transitionend",l),(d=(c=t.parentElement)==null?void 0:c.querySelector(".vistaview-image-lowres"))==null||d.classList.add("vistaview-image--hidden"),t.classList.add("vistaview-image-settled"))};requestAnimationFrame(()=>{t.addEventListener("transitionend",l),t.style.width=`${n}px`,t.style.height=`${e}px`})}}async swap(t,i){var d,h;if(!L.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),a=r.map((u,p)=>O(u,e[p])),o={htmlElements:{from:this.currentItems,to:a},images:{from:this.currentImages,to:r},index:{from:t,to:i},via:this.currentIndex.via,vistaView:this};this.userSetup(o);const l=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15);this.transitionAbortControllers[l]=new AbortController;try{await this.userTransition(o,this.transitionAbortControllers[l].signal)}catch(u){u instanceof D||console.warn(u)}const c=a.find(u=>u.dataset.vistaviewPos==="0");if(c){const u=c.dataset.vistaviewIndex,p=this.currentItems.find(v=>v.dataset.vistaviewIndex===u),f=p==null?void 0:p.querySelector(".vistaview-image-highres");if(f){const v=c.querySelector(".vistaview-image-highres");if(v.setAttribute("class",f.getAttribute("class")||""),v.setAttribute("style",f.getAttribute("style")||""),v.classList.remove("vistaview-image--zooming"),f.classList.contains("vistaview-image-loaded")&&!f.classList.contains("vistaview-image-settled")){const E=f.getBoundingClientRect();v.style.width=`${E.width}px`,v.style.height=`${E.height}px`}}}delete this.transitionAbortControllers[l],this.imageContainerElm.innerHTML="",a.forEach(u=>{var E;const p=u.querySelector(".vistaview-image-highres"),f=!!p.classList.contains("vistaview-image-loaded"),v=!!p.classList.contains("vistaview-image-settled");this.imageContainerElm.appendChild(u),f&&!v?this.setFullSizeImageDim(p):f&&v&&((E=u==null?void 0:u.querySelector(".vistaview-image-lowres"))==null||E.classList.add("vistaview-image--hidden"))}),this.setInitialDimPos(),this.currentImages=r,this.currentItems=a,this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(h=(d=this.options).onImageView)==null||h.call(d,o),this.loadImageTimeout&&clearTimeout(this.loadImageTimeout),this.loadImageTimeout=setTimeout(()=>{this.loadImages()},333)}setZoomed(t){var i,n,e,r,a,o;if(this.isZoomed!==t){if(this.isZoomed){let l=this.isZoomed;if(l.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((i=l.parentElement)==null||i.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=l.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((e=l.parentElement)==null||e.removeEventListener("pointerup",this.onZoomedPointerUp),this.onZoomedPointerUp=null),l==null||l.style.removeProperty("--pointer-diff-x"),l==null||l.style.removeProperty("--pointer-diff-y"),setTimeout(()=>{l==null||l.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 l=!1,c=0,d=0,h=0,u=0,p=0,f=0;this.onZoomedPointerDown=v=>{v.preventDefault(),v.stopPropagation(),l=!0,c=v.pageX,d=v.pageY,t.setPointerCapture(v.pointerId)},this.onZoomedPointerMove=v=>{if(!l)return;v.preventDefault(),p=v.pageX-c,f=v.pageY-d;const E=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),g=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:x,minDiffY:C,maxDiffY:w,minDiffX:b}=k(E,g),y=Math.min(x,Math.max(b,h+p)),I=Math.min(w,Math.max(C,u+f));p=y-h,f=I-u,t==null||t.style.setProperty("--pointer-diff-x",`${y}px`),t==null||t.style.setProperty("--pointer-diff-y",`${I}px`)},this.onZoomedPointerUp=v=>{l=!1,t.releasePointerCapture(v.pointerId),h+=p,u+=f,p=0,f=0},(r=t==null?void 0:t.parentElement)==null||r.addEventListener("pointerdown",this.onZoomedPointerDown),(a=t==null?void 0:t.parentElement)==null||a.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var r,a,o,l,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 d=Math.min(i+this.options.zoomStep,e);t.style.width=`${d}px`;const h=d/i*n;t.style.height=`${h}px`,(o=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=d.toString(),t.dataset.vistaviewCurrentHeight=h.toString(),d===e&&((c=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"))==null||c.setAttribute("disabled","true"))}}zoomOut(){var a,o,l,c,d;const t=(a=this.rootElm)==null?void 0:a.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 u=h/i*n;t.style.height=`${u}px`,(l=(o=this.rootElm)==null?void 0:o.querySelector("button.vistaview-zoom-in-btn"))==null||l.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=h.toString(),t.dataset.vistaviewCurrentHeight=u.toString();const{maxDiffX:p,minDiffY:f,maxDiffY:v,minDiffX:E}=k(h,u);let g=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),x=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");g=Math.min(p,Math.max(E,g)),x=Math.min(v,Math.max(f,x)),t==null||t.style.setProperty("--pointer-diff-x",`${g}px`),t==null||t.style.setProperty("--pointer-diff-y",`${x}px`),h===e&&((d=(c=this.rootElm)==null?void 0:c.querySelector("button.vistaview-zoom-out-btn"))==null||d.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"),a=e.getAttribute("href")||"",o=e.getAttribute("src")||"",l=e.dataset.vistaviewSrc||a||o||(r==null?void 0:r.src)||"",c=e.dataset.vistaviewAlt||e.getAttribute("alt")||(r==null?void 0:r.alt)||"",d=e.dataset.vistaviewThumb||(r==null?void 0:r.src)||a||o||"";return{index:t[n],src:l,alt:c,thumb:d,imageElm:e instanceof HTMLImageElement?e:r,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var c,d;if(!this.rootElm)return;const t=(c=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:c.dataset.vistaviewIndex,i=((d=this.currentImages)==null?void 0:d.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,a=(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,l=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+a/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",r+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",l+"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 d,h;const r=(d=i.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-in-btn"),a=(h=i.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,l=t.naturalWidth*i.options.maxZoomLevel,c=o<l&&l>0;r&&(r.style.display=c?"":"none"),a&&(a.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,a=this.currentImages[n].imageElm,o={w:0,h:0};if(a){const{width:c,height:d}=K(a);o.w=Math.min(a.width,c),o.h=Math.min(a.height,d)}const l=()=>{var d;const c=()=>{var h;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(()=>{this.setFullSizeImageDim(e)},100),(h=i.parentElement)!=null&&h.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((d=this.rootElm)!=null&&d.classList.contains("vistaview--opened"))c();else{const h=setInterval(()=>{var u;(u=this.rootElm)!=null&&u.classList.contains("vistaview--opened")&&(clearInterval(h),c())},50)}};e.complete&&e.naturalWidth>0?l():(e.onload=l,e.onerror=()=>{var c;console.error("VistaView: failed to load image "+e.src),(c=e.parentElement)==null||c.classList.add("vistaview-image-load-failed")})})}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},(a,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(a,o)=>(t+1+o)%n)])],r=n<1||!i?[0]:e.map((a,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:a}=q(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=r.toString(),e.dataset.vistaviewInitialHeight=a.toString()):(e.style.width=`${r}px`,e.style.height=`${a}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,l,c,d,h,u,p,f,v,E,g,x,C;if(L.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(L.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 L.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,b)=>O(w,n[b]));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,vistaView:this};this.userSetup(r),this.imageContainerElm.innerHTML="",this.currentItems.forEach(w=>{this.imageContainerElm.appendChild(w)});let a=0;this.rootElm.addEventListener("animationend",w=>{var b;w.currentTarget===this.rootElm&&(a++,a>=2&&((b=this.rootElm)==null||b.classList.add("vistaview--opened")))}),(l=this.rootElm.querySelector(".vistaview-close-btn"))==null||l.addEventListener("click",()=>this.close()),(c=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||c.addEventListener("click",()=>this.zoomIn()),(d=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||d.addEventListener("click",()=>this.zoomOut()),(h=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||h.addEventListener("click",()=>this.prev()),(u=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||u.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",b=>{const y=this.customControls[b.currentTarget.dataset.vistaviewCustomControl],I=this.currentImages.find(S=>S.index===this.currentIndex.value);y&&I&&(y.onClick.constructor.name==="AsyncFunction"?(w.classList.add("vistaview-button--loading"),y.onClick(I).finally(()=>{w.classList.remove("vistaview-button--loading")})):y.onClick(I))})}),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&&((p=this.rootElm.querySelector(".vistaview-prev-btn"))==null||p.classList.add("vistaview-ui--none"),(f=this.rootElm.querySelector(".vistaview-next-btn"))==null||f.classList.add("vistaview-ui--none"),(v=this.rootElm.querySelector(".vistaview-index-display"))==null||v.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(g=(E=this.options).onOpen)==null||g.call(E,r),(C=(x=this.options).onImageView)==null||C.call(x,r)}async close(t=!0){var n,e,r;if(L.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(a=>{var l;let o;(l=this.rootElm)==null||l.addEventListener("transitionend",c=>{c.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{a()},333))})}));const i={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},via:{prev:!1,next:!1},vistaView:this};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.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 a in this.transitionAbortControllers)this.transitionAbortControllers[a].abort();this.transitionAbortControllers={},L.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){L.somethingOpened===this&&(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(){L.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){L.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return L.somethingOpened===this?this.currentIndex.value:-1}}function 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=V;exports.defaultInit=F;exports.defaultSetup=_;exports.defaultTransition=B;exports.removeTouchActions=T;exports.setTouchActions=Y;exports.vistaView=at;exports.vistaViewDownload=X;
|
|
16
|
+
</div>`)}let z=null,M=null,T=null,Z=null;function Y(s){H(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,r=0,l=0,o=null,c=0,a=!1;z=d=>{d.preventDefault(),d.stopPropagation(),s.isZoomed===!1&&(a=!0,n=d.pageX,e=d.pageY,r=d.pageX,l=d.pageY,c=Date.now(),o=null,t.setPointerCapture(d.pointerId))},M=d=>{if(d.preventDefault(),d.stopPropagation(),s.isZoomed!==!1||!a)return;const h=d.pageX-n,u=d.pageY-e;r=d.pageX,l=d.pageY,Math.abs(h)>=Math.abs(u)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),o=!0):Math.abs(u)>Math.abs(h)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${u}px`),o=!1)},Z=d=>{if(d.preventDefault(),d.stopPropagation(),t.releasePointerCapture(d.pointerId),s.isZoomed!==!1||!a)return;a=!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(u=>{u.style.transition="",u.style.translate=""})},T=d=>{if(d.preventDefault(),d.stopPropagation(),t.releasePointerCapture(d.pointerId),s.isZoomed!==!1||!a)return;a=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),u=r-n,w=l-e,f=Date.now()-c,v=u/f,y=w/f,b=s.options.touchSpeedThreshold||.5,L=h.find(g=>g.dataset.vistaviewPos==="0"),C=Number(L.dataset.vistaviewIndex);function E(){h[0].removeEventListener("transitionend",E),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(g=>{g.style.transition="",g.style.translate=""})}function m(g="0%",x="0%"){h.forEach(I=>{I.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,I.style.translate=`${g} ${x}`})}if(v<-b||v>b){let g=function(){h[0].removeEventListener("transitionend",g),setTimeout(()=>{const x=s.isReducedMotion,I=s.options.detectReducedMotion;s.isReducedMotion=!0,s.options.detectReducedMotion=!0,E(),s.view(v<-b?(C+1)%i:(C-1+i)%i,{next:v<-b,prev:v>b}),s.isReducedMotion=x,s.options.detectReducedMotion=I},100)};m(v<-b?"-100%":"100%"),h[0].addEventListener("transitionend",g)}else y<-b||y>b?(s.close(),m("0%","0%")):(h[0].addEventListener("transitionend",E),m("0%"),v===0&&y===0&&s.zoomIn())},t.addEventListener("pointermove",M),t.addEventListener("pointerup",T),t.addEventListener("pointerdown",z),t.addEventListener("pointercancel",Z)}function H(s){const t=s.imageContainerElm;t&&(M&&t.removeEventListener("pointermove",M),T&&t.removeEventListener("pointerup",T),z&&t.removeEventListener("pointerdown",z),Z&&t.removeEventListener("pointercancel",Z))}const B=s=>{Y(s)},_=({htmlElements:{to:s},index:{to:t},vistaView:i})=>{i.elements instanceof NodeList&&t!==null&&(i.elements.forEach(n=>n.style.opacity="1"),i.elements[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"})},V=async({htmlElements:{from:s},via:{next:t,prev:i},vistaView:n},e)=>{if(n.options.detectReducedMotion&&n.isReducedMotion)return;const r=s.filter(l=>l.dataset.vistaviewPos==="0"||(t?l.dataset.vistaviewPos==="1":l.dataset.vistaviewPos==="-1"));await new Promise((l,o)=>{let c=0,a=!1;if(e.aborted){o(new P("Transition aborted"));return}const d=h=>{if(a)return o(new P("Transition aborted"));if(e.aborted)return a||(a=!0),o(new P("Transition aborted"));h.currentTarget.removeEventListener("transitionend",d),c++,c>=r.length&&l(0)};r.forEach(h=>{h.style.transition=`translate ${n.options.animationDurationBase*.5}ms ease-out`,h.style.translate=t?"-100%":i?"100%":"0%",h.addEventListener("transitionend",d)})})},N=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),H(s)};class P extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const R={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",X(),"close"],bottomCenter:["description"]}},S={somethingOpened:null};class ht{constructor(t,i){p(this,"options");p(this,"elements");p(this,"isReducedMotion");p(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n,e,r;const i=this._value;this._value=t;for(const l in(n=this._vistaView)==null?void 0:n.transitionAbortControllers)(e=this._vistaView)==null||e.transitionAbortControllers[l].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}});p(this,"rootElm",null);p(this,"imageContainerElm",null);p(this,"customControls",{});p(this,"currentImages",null);p(this,"currentItems",null);p(this,"isZoomed",!1);p(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});p(this,"defaultOnClickHandler",t=>t.preventDefault());p(this,"onResizeHandler",null);p(this,"onKeyDown",null);p(this,"userSetup",_);p(this,"userTransition",V);p(this,"userClose",N);p(this,"userInit",B);p(this,"onZoomedPointerDown",null);p(this,"onZoomedPointerMove",null);p(this,"onZoomedPointerUp",null);p(this,"transitionAbortControllers",{});p(this,"loadImageTimeout",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...R,...i||{},controls:{...R.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,l;const i=t.getBoundingClientRect(),{width:n,height:e}=O(t);if(n===i.width&&e===i.height)(l=(r=t.parentElement)==null?void 0:r.querySelector(".vistaview-image-lowres"))==null||l.classList.add("vistaview-image--hidden"),t.classList.add("vistaview-image-settled");else{let o=0;const c=()=>{var a,d;o++,!(o<3)&&(t.removeEventListener("transitionend",c),(d=(a=t.parentElement)==null?void 0:a.querySelector(".vistaview-image-lowres"))==null||d.classList.add("vistaview-image--hidden"),t.classList.add("vistaview-image-settled"))};requestAnimationFrame(()=>{t.addEventListener("transitionend",c),t.style.width=`${n}px`,t.style.height=`${e}px`})}}async swap(t,i){var d,h;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),l=r.map((u,w)=>W(u,e[w])),o={htmlElements:{from:this.currentItems,to:l},images:{from:this.currentImages,to:r},index:{from:t,to:i},via:this.currentIndex.via,vistaView:this};this.userSetup(o);const c=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15);this.transitionAbortControllers[c]=new AbortController;try{await this.userTransition(o,this.transitionAbortControllers[c].signal)}catch(u){u instanceof P||console.warn(u)}const a=l.find(u=>u.dataset.vistaviewPos==="0");if(a){const u=a.dataset.vistaviewIndex,w=this.currentItems.find(v=>v.dataset.vistaviewIndex===u),f=w==null?void 0:w.querySelector(".vistaview-image-highres");if(f){const v=a.querySelector(".vistaview-image-highres");if(v.setAttribute("class",f.getAttribute("class")||""),v.setAttribute("style",f.getAttribute("style")||""),v.classList.remove("vistaview-image--zooming"),f.classList.contains("vistaview-image-loaded")&&!f.classList.contains("vistaview-image-settled")){const y=f.getBoundingClientRect();v.style.width=`${y.width}px`,v.style.height=`${y.height}px`}}}delete this.transitionAbortControllers[c],this.imageContainerElm.innerHTML="",l.forEach(u=>{var y;const w=u.querySelector(".vistaview-image-highres"),f=!!w.classList.contains("vistaview-image-loaded"),v=!!w.classList.contains("vistaview-image-settled");this.imageContainerElm.appendChild(u),f&&!v?this.setFullSizeImageDim(w):f&&v&&((y=u==null?void 0:u.querySelector(".vistaview-image-lowres"))==null||y.classList.add("vistaview-image--hidden"))}),this.setInitialDimPos(),this.currentImages=r,this.currentItems=l,this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(h=(d=this.options).onImageView)==null||h.call(d,o),this.loadImageTimeout&&clearTimeout(this.loadImageTimeout),this.loadImageTimeout=setTimeout(()=>{this.loadImages()},333)}setZoomed(t){var n,e,r,l,o,c;if(this.isZoomed===t)return;let i=null;if(this.isZoomed){i&&cancelAnimationFrame(i);let a=this.isZoomed;if(a.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((n=a.parentElement)==null||n.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((e=a.parentElement)==null||e.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((r=a.parentElement)==null||r.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){let a=function({speedX:m,speedY:g}){i=requestAnimationFrame(()=>{if(Math.abs(m)<.01&&Math.abs(g)<.01)return;const x=t,I=window.innerWidth/2,A=window.innerHeight/2,D=x.getBoundingClientRect(),U=D.bottom<A,j=D.top>A,K=D.right<I,G=D.left>I;w+=m,f+=g,U&&(f+=(A-D.bottom)/C),j&&(f-=(D.top-A)/C),K&&(w+=(I-D.right)/C),G&&(w-=(D.left-I)/C),x==null||x.style.setProperty("--pointer-diff-x",`${w}px`),x==null||x.style.setProperty("--pointer-diff-y",`${f}px`),a({speedX:m*(1-E),speedY:g*(1-E)})})};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 d=!1,h=0,u=0,w=0,f=0,v=0,y=0,b=0,L=15,C=5,E=.1;this.onZoomedPointerDown=m=>{i&&cancelAnimationFrame(i),m.preventDefault(),m.stopPropagation(),d=!0,h=m.pageX,u=m.pageY,b=performance.now(),t.setPointerCapture(m.pointerId)},this.onZoomedPointerMove=m=>{d&&(m.preventDefault(),v=m.pageX-h,y=m.pageY-u,t==null||t.style.setProperty("--pointer-diff-x",`${v+w}px`),t==null||t.style.setProperty("--pointer-diff-y",`${y+f}px`))},this.onZoomedPointerUp=m=>{if(d=!1,t.releasePointerCapture(m.pointerId),w+=v,f+=y,v===0&&y===0)this.zoomIn();else{let g=performance.now()-b;if(g===0)return;let x=(m.pageY-u)/g,I=(m.pageX-h)/g;a({speedX:I*L,speedY:x*L})}v=0,y=0},(l=t==null?void 0:t.parentElement)==null||l.addEventListener("pointerdown",this.onZoomedPointerDown),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointermove",this.onZoomedPointerMove),(c=t==null?void 0:t.parentElement)==null||c.addEventListener("pointerup",this.onZoomedPointerUp);return}}zoomIn(){var r,l,o,c,a;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 d=Math.min(i+this.options.zoomStep,e);t.style.width=`${d}px`;const h=d/i*n;t.style.height=`${h}px`,(o=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=d.toString(),t.dataset.vistaviewCurrentHeight=h.toString(),d===e&&((a=(c=this.rootElm)==null?void 0:c.querySelector("button.vistaview-zoom-in-btn"))==null||a.setAttribute("disabled","true"))}}zoomOut(){var l,o,c,a,d;const t=(l=this.rootElm)==null?void 0:l.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 u=h/i*n;t.style.height=`${u}px`,(c=(o=this.rootElm)==null?void 0:o.querySelector("button.vistaview-zoom-in-btn"))==null||c.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=h.toString(),t.dataset.vistaviewCurrentHeight=u.toString();const{maxDiffX:w,minDiffY:f,maxDiffY:v,minDiffX:y}=it(h,u);let b=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),L=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");b=Math.min(w,Math.max(y,b)),L=Math.min(v,Math.max(f,L)),t==null||t.style.setProperty("--pointer-diff-x",`${b}px`),t==null||t.style.setProperty("--pointer-diff-y",`${L}px`),h===e&&((d=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-out-btn"))==null||d.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"),l=e.getAttribute("href")||"",o=e.getAttribute("src")||"",c=e.dataset.vistaviewSrc||l||o||(r==null?void 0:r.src)||"",a=e.dataset.vistaviewAlt||e.getAttribute("alt")||(r==null?void 0:r.alt)||"",d=e.dataset.vistaviewThumb||(r==null?void 0:r.src)||l||o||"";return{index:t[n],src:c,alt:a,thumb:d,imageElm:e instanceof HTMLImageElement?e:r,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var a,d;if(!this.rootElm)return;const t=(a=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:a.dataset.vistaviewIndex,i=((d=this.currentImages)==null?void 0:d.find(h=>h.index===Number(t)))||null;if(!i)return;const n=i.imageElm?q(i.imageElm):void 0,e=i.anchorElm?q(i.anchorElm):void 0,r=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,l=(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,c=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+l/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",r+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",l+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",c+"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 d,h;const r=(d=i.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-in-btn"),l=(h=i.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,c=t.naturalWidth*i.options.maxZoomLevel,a=o<c&&c>0;r&&(r.style.display=a?"":"none"),l&&(l.style.display=a?"":"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,l=this.currentImages[n].imageElm,o={w:0,h:0};if(l){const{width:a,height:d}=et(l);o.w=Math.min(l.width,a),o.h=Math.min(l.height,d)}const c=()=>{var d;const a=()=>{var h;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(()=>{this.setFullSizeImageDim(e)},100),(h=i.parentElement)!=null&&h.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((d=this.rootElm)!=null&&d.classList.contains("vistaview--opened"))a();else{const h=setInterval(()=>{var u;(u=this.rootElm)!=null&&u.classList.contains("vistaview--opened")&&(clearInterval(h),a())},50)}};e.complete&&e.naturalWidth>0?c():(e.onload=c,e.onerror=()=>{var a;console.error("VistaView: failed to load image "+e.src),(a=e.parentElement)==null||a.classList.add("vistaview-image-load-failed")})})}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},(l,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(l,o)=>(t+1+o)%n)])],r=n<1||!i?[0]:e.map((l,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:l}=O(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=r.toString(),e.dataset.vistaviewInitialHeight=l.toString()):(e.style.width=`${r}px`,e.style.height=`${l}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,c,a,d,h,u,w,f,v,y,b,L,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(ct({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((E,m)=>W(E,n[m]));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,vistaView:this};this.userSetup(r),this.imageContainerElm.innerHTML="",this.currentItems.forEach(E=>{this.imageContainerElm.appendChild(E)});let l=0;this.rootElm.addEventListener("animationend",E=>{var m;E.currentTarget===this.rootElm&&(l++,l>=2&&((m=this.rootElm)==null||m.classList.add("vistaview--opened")))}),(c=this.rootElm.querySelector(".vistaview-close-btn"))==null||c.addEventListener("click",()=>this.close()),(a=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||a.addEventListener("click",()=>this.zoomIn()),(d=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||d.addEventListener("click",()=>this.zoomOut()),(h=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||h.addEventListener("click",()=>this.prev()),(u=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||u.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(E=>{typeof E!="string"&&(this.customControls[E.name]=E)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(E=>{E.addEventListener("click",m=>{const g=this.customControls[m.currentTarget.dataset.vistaviewCustomControl],x=this.currentImages.find(I=>I.index===this.currentIndex.value);g&&x&&(g.onClick.constructor.name==="AsyncFunction"?(E.classList.add("vistaview-button--loading"),g.onClick(x).finally(()=>{E.classList.remove("vistaview-button--loading")})):g.onClick(x))})}),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&&((w=this.rootElm.querySelector(".vistaview-prev-btn"))==null||w.classList.add("vistaview-ui--none"),(f=this.rootElm.querySelector(".vistaview-next-btn"))==null||f.classList.add("vistaview-ui--none"),(v=this.rootElm.querySelector(".vistaview-index-display"))==null||v.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(b=(y=this.options).onOpen)==null||b.call(y,r),(C=(L=this.options).onImageView)==null||C.call(L,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(l=>{var c;let o;(c=this.rootElm)==null||c.addEventListener("transitionend",a=>{a.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{l()},333))})}));const i={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},via:{prev:!1,next:!1},vistaView:this};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.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 l in this.transitionAbortControllers)this.transitionAbortControllers[l].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&&(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 ut(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 vt({elements:s,...t}){if(!s)throw new Error("No elements");let i=ut(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new ht(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=R;exports.VistaViewTransitionAbortedError=P;exports.defaultClose=N;exports.defaultInit=B;exports.defaultSetup=_;exports.defaultTransition=V;exports.removeTouchActions=H;exports.setTouchActions=Y;exports.vistaView=vt;exports.vistaViewDownload=X;
|