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/dist/vistaview.umd.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
style="${n?`object-fit:${n};`:""}${
|
|
1
|
+
(function(y,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(y=typeof globalThis<"u"?globalThis:y||self,L(y.VistaView={}))})(this,(function(y){"use strict";var vt=Object.defineProperty;var mt=(y,L,A)=>L in y?vt(y,L,{enumerable:!0,configurable:!0,writable:!0,value:A}):y[L]=A;var p=(y,L,A)=>mt(y,typeof L!="symbol"?L+"":L,A);function L(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 A=null;function j(){return A||(window.trustedTypes||(window.trustedTypes={createPolicy:(s,t)=>t}),A=window.trustedTypes.createPolicy("vistaView-policy",{createHTML:s=>s,createScript:()=>{throw new Error("Not implemented")},createScriptURL:()=>{throw new Error("Not implemented")}}),A)}function O(s){const i=j().createHTML(s),n=document.createElement("template");n.innerHTML=i;const e=n.content;return n.remove(),e}function W(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function K(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 F(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 G(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 J='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',Q='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',tt='<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>',et='<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>',it='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',nt='<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:nt,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 st(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${tt}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${et}</button>`;case"close":return`<button class="vistaview-close-btn">${it}</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 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=O(`<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 ot({controls:s,isReducedMotion:t}){const i=e=>e?e.map(st).join(""):"";return O(`<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>${J}</button></div>
|
|
14
|
+
<div class="vistaview-next-btn vistaview-ui"><button>${Q}</button></div>
|
|
15
15
|
</div>
|
|
16
|
-
</div>`)}let z=null,A=null,T=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,a=0,o=null,l=0,h=!1;z=d=>{d.preventDefault(),d.stopPropagation(),s.isZoomed===!1&&(h=!0,n=d.pageX,e=d.pageY,r=d.pageX,a=d.pageY,l=Date.now(),o=null,t.setPointerCapture(d.pointerId))},A=d=>{if(d.preventDefault(),d.stopPropagation(),s.isZoomed!==!1||!h)return;const c=d.pageX-n,u=d.pageY-e;r=d.pageX,a=d.pageY,Math.abs(c)>=Math.abs(u)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${c}px`),o=!0):Math.abs(u)>Math.abs(c)&&(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||!h)return;h=!1,o=null;const c=Array.from(t.querySelectorAll(".vistaview-item"));t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),c.forEach(u=>{u.style.transition="",u.style.translate=""})},T=d=>{if(d.preventDefault(),d.stopPropagation(),t.releasePointerCapture(d.pointerId),s.isZoomed!==!1||!h)return;h=!1;const c=Array.from(t.querySelectorAll(".vistaview-item")),u=r-n,p=a-e,f=Date.now()-l,v=u/f,b=p/f,y=s.options.touchSpeedThreshold||.5,C=c.find(E=>E.dataset.vistaviewPos==="0"),P=Number(C.dataset.vistaviewIndex);function g(){c[0].removeEventListener("transitionend",g),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),c.forEach(E=>{E.style.transition="",E.style.translate=""})}function I(E="0%",S="0%"){c.forEach(M=>{M.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,M.style.translate=`${E} ${S}`})}if(v<-y||v>y){let E=function(){c[0].removeEventListener("transitionend",E),setTimeout(()=>{const S=s.isReducedMotion,M=s.options.detectReducedMotion;s.isReducedMotion=!0,s.options.detectReducedMotion=!0,g(),s.view(v<-y?(P+1)%i:(P-1+i)%i,{next:v<-y,prev:v>y}),s.isReducedMotion=S,s.options.detectReducedMotion=M},100)};I(v<-y?"-100%":"100%"),c[0].addEventListener("transitionend",E)}else b<-y||b>y?(s.close(),I("0%","0%")):(c[0].addEventListener("transitionend",g),I("0%"),v===0&&b===0&&s.zoomIn())},t.addEventListener("pointermove",A),t.addEventListener("pointerup",T),t.addEventListener("pointerdown",z),t.addEventListener("pointercancel",Z)}function R(s){const t=s.imageContainerElm;t&&(A&&t.removeEventListener("pointermove",A),T&&t.removeEventListener("pointerup",T),z&&t.removeEventListener("pointerdown",z),Z&&t.removeEventListener("pointercancel",Z))}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,h=!1;if(e.aborted){o(new $("Transition aborted"));return}const d=c=>{if(h)return o(new $("Transition aborted"));if(e.aborted)return h||(h=!0),o(new $("Transition aborted"));c.currentTarget.removeEventListener("transitionend",d),l++,l>=r.length&&a(0)};r.forEach(c=>{c.style.transition=`translate ${n.options.animationDurationBase*.5}ms ease-out`,c.style.translate=t?"-100%":i?"100%":"0%",c.addEventListener("transitionend",d)})})},N=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),R(s)};class $ 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"]}},L={somethingOpened:null};class st{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",N);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={...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,a;const i=t.getBoundingClientRect(),{width:n,height:e}=O(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 h,d;o++,!(o<3)&&(t.removeEventListener("transitionend",l),(d=(h=t.parentElement)==null?void 0:h.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,c;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)=>X(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 $||console.warn(u)}const h=a.find(u=>u.dataset.vistaviewPos==="0");if(h){const u=h.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=h.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 b=f.getBoundingClientRect();v.style.width=`${b.width}px`,v.style.height=`${b.height}px`}}}delete this.transitionAbortControllers[l],this.imageContainerElm.innerHTML="",a.forEach(u=>{var b;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&&((b=u==null?void 0:u.querySelector(".vistaview-image-lowres"))==null||b.classList.add("vistaview-image--hidden"))}),this.setInitialDimPos(),this.currentImages=r,this.currentItems=a,this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(c=(d=this.options).onImageView)==null||c.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,h=0,d=0,c=0,u=0,p=0,f=0;this.onZoomedPointerDown=v=>{v.preventDefault(),v.stopPropagation(),l=!0,h=v.pageX,d=v.pageY,t.setPointerCapture(v.pointerId)},this.onZoomedPointerMove=v=>{if(!l)return;v.preventDefault(),p=v.pageX-h,f=v.pageY-d;const b=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),y=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:C,minDiffY:P,maxDiffY:g,minDiffX:I}=W(b,y),E=Math.min(C,Math.max(I,c+p)),S=Math.min(g,Math.max(P,u+f));p=E-c,f=S-u,t==null||t.style.setProperty("--pointer-diff-x",`${E}px`),t==null||t.style.setProperty("--pointer-diff-y",`${S}px`)},this.onZoomedPointerUp=v=>{l=!1,t.releasePointerCapture(v.pointerId),c+=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,h;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 c=d/i*n;t.style.height=`${c}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=c.toString(),d===e&&((h=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"))==null||h.setAttribute("disabled","true"))}}zoomOut(){var a,o,l,h,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=c=>{c.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 c=Math.max(i-this.options.zoomStep,e);t.style.width=`${c}px`;const u=c/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=c.toString(),t.dataset.vistaviewCurrentHeight=u.toString();const{maxDiffX:p,minDiffY:f,maxDiffY:v,minDiffX:b}=W(c,u);let y=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),C=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");y=Math.min(p,Math.max(b,y)),C=Math.min(v,Math.max(f,C)),t==null||t.style.setProperty("--pointer-diff-x",`${y}px`),t==null||t.style.setProperty("--pointer-diff-y",`${C}px`),c===e&&((d=(h=this.rootElm)==null?void 0:h.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)||"",h=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:h,thumb:d,imageElm:e instanceof HTMLImageElement?e:r,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var h,d;if(!this.rootElm)return;const t=(h=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:h.dataset.vistaviewIndex,i=((d=this.currentImages)==null?void 0:d.find(c=>c.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,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",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,c;const r=(d=i.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-in-btn"),a=(c=i.rootElm)==null?void 0:c.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,l=t.naturalWidth*i.options.maxZoomLevel,h=o<l&&l>0;r&&(r.style.display=h?"":"none"),a&&(a.style.display=h?"":"none")}t.complete&&t.naturalWidth>0?n():t.addEventListener("load",n)}loadImages(){if(!this.rootElm)return;this.rootElm.querySelectorAll(".vistaview-image-highres:not(.vistaview-image-loaded)").forEach((i,n)=>{const e=i,a=this.currentImages[n].imageElm,o={w:0,h:0};if(a){const{width:h,height:d}=j(a);o.w=Math.min(a.width,h),o.h=Math.min(a.height,d)}const l=()=>{var d;const h=()=>{var c;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),(c=i.parentElement)!=null&&c.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((d=this.rootElm)!=null&&d.classList.contains("vistaview--opened"))h();else{const c=setInterval(()=>{var u;(u=this.rootElm)!=null&&u.classList.contains("vistaview--opened")&&(clearInterval(c),h())},50)}};e.complete&&e.naturalWidth>0?l():(e.onload=l,e.onerror=()=>{var h;console.error("VistaView: failed to load image "+e.src),(h=e.parentElement)==null||h.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}=O(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,h,d,c,u,p,f,v,b,y,C,P;if(L.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(L.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 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((g,I)=>X(g,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,vistaView:this};this.userSetup(r),this.imageContainerElm.innerHTML="",this.currentItems.forEach(g=>{this.imageContainerElm.appendChild(g)});let a=0;this.rootElm.addEventListener("animationend",g=>{var I;g.currentTarget===this.rootElm&&(a++,a>=2&&((I=this.rootElm)==null||I.classList.add("vistaview--opened")))}),(l=this.rootElm.querySelector(".vistaview-close-btn"))==null||l.addEventListener("click",()=>this.close()),(h=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||h.addEventListener("click",()=>this.zoomIn()),(d=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||d.addEventListener("click",()=>this.zoomOut()),(c=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||c.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(g=>{typeof g!="string"&&(this.customControls[g.name]=g)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(g=>{g.addEventListener("click",I=>{const E=this.customControls[I.currentTarget.dataset.vistaviewCustomControl],S=this.currentImages.find(M=>M.index===this.currentIndex.value);E&&S&&(E.onClick.constructor.name==="AsyncFunction"?(g.classList.add("vistaview-button--loading"),E.onClick(S).finally(()=>{g.classList.remove("vistaview-button--loading")})):E.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&&((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),(y=(b=this.options).onOpen)==null||y.call(b,r),(P=(C=this.options).onImageView)==null||P.call(C,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",h=>{h.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 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)}}}w.DefaultOptions=H,w.VistaViewTransitionAbortedError=$,w.defaultClose=N,w.defaultInit=F,w.defaultSetup=_,w.defaultTransition=B,w.removeTouchActions=R,w.setTouchActions=Y,w.vistaView=rt,w.vistaViewDownload=V,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));
|
|
16
|
+
</div>`)}let M=null,T=null,Z=null,R=null;function Y(s){q(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;M=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))},T=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)},R=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=""})},Z=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,E=w/f,x=s.options.touchSpeedThreshold||.5,S=h.find(g=>g.dataset.vistaviewPos==="0"),P=Number(S.dataset.vistaviewIndex);function b(){h[0].removeEventListener("transitionend",b),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%",I="0%"){h.forEach(C=>{C.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,C.style.translate=`${g} ${I}`})}if(v<-x||v>x){let g=function(){h[0].removeEventListener("transitionend",g),setTimeout(()=>{const I=s.isReducedMotion,C=s.options.detectReducedMotion;s.isReducedMotion=!0,s.options.detectReducedMotion=!0,b(),s.view(v<-x?(P+1)%i:(P-1+i)%i,{next:v<-x,prev:v>x}),s.isReducedMotion=I,s.options.detectReducedMotion=C},100)};m(v<-x?"-100%":"100%"),h[0].addEventListener("transitionend",g)}else E<-x||E>x?(s.close(),m("0%","0%")):(h[0].addEventListener("transitionend",b),m("0%"),v===0&&E===0&&s.zoomIn())},t.addEventListener("pointermove",T),t.addEventListener("pointerup",Z),t.addEventListener("pointerdown",M),t.addEventListener("pointercancel",R)}function q(s){const t=s.imageContainerElm;t&&(T&&t.removeEventListener("pointermove",T),Z&&t.removeEventListener("pointerup",Z),M&&t.removeEventListener("pointerdown",M),R&&t.removeEventListener("pointercancel",R))}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"})},N=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 z("Transition aborted"));return}const d=h=>{if(a)return o(new z("Transition aborted"));if(e.aborted)return a||(a=!0),o(new z("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)})})},U=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),q(s)};class z extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const k={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 rt{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",N);p(this,"userClose",U);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={...k,...i||{},controls:{...k.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}=F(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(!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),l=r.map((u,w)=>X(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 z||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 E=f.getBoundingClientRect();v.style.width=`${E.width}px`,v.style.height=`${E.height}px`}}}delete this.transitionAbortControllers[c],this.imageContainerElm.innerHTML="",l.forEach(u=>{var E;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&&((E=u==null?void 0:u.querySelector(".vistaview-image-lowres"))==null||E.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 I=t,C=window.innerWidth/2,H=window.innerHeight/2,$=I.getBoundingClientRect(),dt=$.bottom<H,ct=$.top>H,ht=$.right<C,ut=$.left>C;w+=m,f+=g,dt&&(f+=(H-$.bottom)/P),ct&&(f-=($.top-H)/P),ht&&(w+=(C-$.right)/P),ut&&(w-=($.left-C)/P),I==null||I.style.setProperty("--pointer-diff-x",`${w}px`),I==null||I.style.setProperty("--pointer-diff-y",`${f}px`),a({speedX:m*(1-b),speedY:g*(1-b)})})};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,E=0,x=0,S=15,P=5,b=.1;this.onZoomedPointerDown=m=>{i&&cancelAnimationFrame(i),m.preventDefault(),m.stopPropagation(),d=!0,h=m.pageX,u=m.pageY,x=performance.now(),t.setPointerCapture(m.pointerId)},this.onZoomedPointerMove=m=>{d&&(m.preventDefault(),v=m.pageX-h,E=m.pageY-u,t==null||t.style.setProperty("--pointer-diff-x",`${v+w}px`),t==null||t.style.setProperty("--pointer-diff-y",`${E+f}px`))},this.onZoomedPointerUp=m=>{if(d=!1,t.releasePointerCapture(m.pointerId),w+=v,f+=E,v===0&&E===0)this.zoomIn();else{let g=performance.now()-x;if(g===0)return;let I=(m.pageY-u)/g,C=(m.pageX-h)/g;a({speedX:C*S,speedY:I*S})}v=0,E=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:E}=G(h,u);let x=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),S=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");x=Math.min(w,Math.max(E,x)),S=Math.min(v,Math.max(f,S)),t==null||t.style.setProperty("--pointer-diff-x",`${x}px`),t==null||t.style.setProperty("--pointer-diff-y",`${S}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?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,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",W(e==null?void 0:e.borderRadius)||W(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}=K(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}=F(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,E,x,S,P;if(D.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(D.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(ot({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((b,m)=>X(b,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(b=>{this.imageContainerElm.appendChild(b)});let l=0;this.rootElm.addEventListener("animationend",b=>{var m;b.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(b=>{typeof b!="string"&&(this.customControls[b.name]=b)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(b=>{b.addEventListener("click",m=>{const g=this.customControls[m.currentTarget.dataset.vistaviewCustomControl],I=this.currentImages.find(C=>C.index===this.currentIndex.value);g&&I&&(g.onClick.constructor.name==="AsyncFunction"?(b.classList.add("vistaview-button--loading"),g.onClick(I).finally(()=>{b.classList.remove("vistaview-button--loading")})):g.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&&((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),(x=(E=this.options).onOpen)==null||x.call(E,r),(P=(S=this.options).onImageView)==null||P.call(S,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(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={},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&&(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 at(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 lt({elements:s,...t}){if(!s)throw new Error("No elements");let i=at(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new rt(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)}}}y.DefaultOptions=k,y.VistaViewTransitionAbortedError=z,y.defaultClose=U,y.defaultInit=B,y.defaultSetup=_,y.defaultTransition=N,y.removeTouchActions=q,y.setTouchActions=Y,y.vistaView=lt,y.vistaViewDownload=V,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vistaview",
|
|
3
|
-
"version": "0.3
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "A lightweight, zero-dependency image lightbox library with smooth animations and touch support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image",
|
|
@@ -97,5 +97,8 @@
|
|
|
97
97
|
"vite": "^6.4.1",
|
|
98
98
|
"vite-plugin-dts": "^4.5.4",
|
|
99
99
|
"vue": "^3.5.25"
|
|
100
|
+
},
|
|
101
|
+
"repository": {
|
|
102
|
+
"url": "https://github.com/juji/vistaview"
|
|
100
103
|
}
|
|
101
104
|
}
|