vistaview 0.2.1 → 0.3.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 +110 -39
- package/dist/lib/components.d.ts +7 -3
- package/dist/lib/components.d.ts.map +1 -1
- package/dist/lib/defaults.d.ts +9 -0
- package/dist/lib/defaults.d.ts.map +1 -0
- package/dist/lib/types.d.ts +83 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +4 -5
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/vista-view.d.ts +57 -66
- package/dist/lib/vista-view.d.ts.map +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +6 -7
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +55 -30
- package/dist/solid.cjs +1 -1
- package/dist/solid.d.ts +11 -5
- package/dist/solid.d.ts.map +1 -1
- package/dist/solid.js +37 -21
- package/dist/svelte.cjs +1 -1
- package/dist/svelte.d.ts +3 -5
- package/dist/svelte.d.ts.map +1 -1
- package/dist/svelte.js +17 -21
- package/dist/vistaview.cjs +16 -1
- package/dist/vistaview.css +1 -2
- package/dist/vistaview.d.ts +11 -9
- package/dist/vistaview.d.ts.map +1 -1
- package/dist/vistaview.js +680 -2
- package/dist/vistaview.umd.js +16 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +19 -6
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +48 -21
- package/package.json +3 -9
- package/dist/types.d.ts +0 -2
- package/dist/types.d.ts.map +0 -1
- package/dist/vistaview-Btvas1MP.js +0 -458
- package/dist/vistaview-Xzefo28o.cjs +0 -14
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
(function(w,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(w=typeof globalThis<"u"?globalThis:w||self,y(w.VistaView={}))})(this,(function(w){"use strict";var st=Object.defineProperty;var ot=(w,y,C)=>y in w?st(w,y,{enumerable:!0,configurable:!0,writable:!0,value:C}):w[y]=C;var p=(w,y,C)=>ot(w,typeof y!="symbol"?y+"":y,C);function y(s){const t=getComputedStyle(s),e=s.getBoundingClientRect();return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow,top:e.top,left:e.left,width:e.width,height:e.height,naturalWidth:s.naturalWidth,naturalHeight:s.naturalHeight}}let C=null;function Y(){return C||(window.trustedTypes||(window.trustedTypes={createPolicy:(s,t)=>t}),C=window.trustedTypes.createPolicy("vistaView-policy",{createHTML:s=>s,createScript:()=>{throw new Error("Not implemented")},createScriptURL:()=>{throw new Error("Not implemented")}}),C)}function H(s){const e=Y().createHTML(s),n=document.createElement("template");n.innerHTML=e;const i=n.content;return n.remove(),i}function T(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function W(s){const e=window.getComputedStyle(s).objectFit||"",{width:n,height:i}=s.getBoundingClientRect(),o=s.naturalWidth,l=s.naturalHeight;if(!e)return{width:n,height:i};if(!o||!l)return{width:n,height:i};const a=o/l,r=n/i;switch(e){case"fill":return{width:n,height:i};case"none":return{width:o,height:l};case"contain":return a>r?{width:n,height:n/a}:{width:i*a,height:i};case"cover":return a<r?{width:n,height:n/a}:{width:i*a,height:i};case"scale-down":{const h={width:o,height:l},c=a>r?{width:n,height:n/a}:{width:i*a,height:i};return c.width<=h.width&&c.height<=h.height?c:h}}return{width:n,height:i}}function S(s){const t=window.innerWidth,e=window.innerHeight,n=s.naturalWidth,i=s.naturalHeight;if(!n||!i)throw console.error("Error",s),new Error("Image natural dimensions are zero");if(n<t&&i<e)return{width:n,height:i};const o=n/i,l=t/e;let a,r;return o>l?(a=t,r=t/o):(r=e,a=e*o),{width:a,height:r}}function q(s,t){const e=window.innerHeight,n=window.innerWidth,i=s,o=t,l=Math.max(0,(i-n)/2)+n/2,a=Math.max(0,(o-e)/2)+e/2,r=-l,h=-a;return{maxDiffX:l,minDiffY:h,maxDiffY:a,minDiffX:r}}const U='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',j='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',N='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',K='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',G='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',J='<svg viewBox="0 0 24 24"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';function k(){return{name:"download",icon:J,onClick:async s=>{var o;const t=await fetch(s.src),e=await t.blob(),n=t.url,i=document.createElement("a");i.href=URL.createObjectURL(e),i.download=((o=n.split("/").pop())==null?void 0:o.split("?")[0].split("#")[0])||"download",document.body.appendChild(i),i.click(),document.body.removeChild(i)}}}function Q(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${N}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${K}</button>`;case"close":return`<button class="vistaview-close-btn">${G}</button>`;case"indexDisplay":return'<div class="vistaview-index-display"></div>';case"description":return'<div class="vistaview-description"></div>';default:return""}return`<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`}function O(s,t){var c,d;const e=s.imageElm?getComputedStyle(s.imageElm):null,n=(e==null?void 0:e.objectFit)||"",i=((c=s.imageElm)==null?void 0:c.naturalWidth)||"",o=((d=s.imageElm)==null?void 0:d.naturalHeight)||"",l=(e==null?void 0:e.width)||"",a=(e==null?void 0:e.height)||"",r=document.createElement("div");r.className="vistaview-item",r.dataset.vistaviewPos=`${t!==void 0?t:""}`,r.dataset.vistaviewIndex=s.index.toString();const h=H(`<img class="vistaview-image-lowres"
|
|
2
|
+
style="${n?`object-fit:${n};`:""}${l?`width:${l};`:""}${a?`height:${a};`:""}"
|
|
3
|
+
src="${s.thumb||s.src}"
|
|
4
|
+
alt="${s.alt||""}"
|
|
5
|
+
${i?`width="${i}"`:""}
|
|
6
|
+
${o?`height="${o}"`:""}
|
|
7
|
+
/>
|
|
8
|
+
<img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return r.appendChild(h),r}function tt({controls:s,isReducedMotion:t}){const e=i=>i?i.map(Q).join(""):"";return H(`<div class="vistaview-root${t?" vistaview--reduced-motion":""}" id="vistaview-root">
|
|
9
|
+
<div class="vistaview-container">
|
|
10
|
+
<div class="vistaview-image-container"></div>
|
|
11
|
+
<div class="vistaview-top-bar vistaview-ui"><div>${e(s==null?void 0:s.topLeft)}</div><div>${e(s==null?void 0:s.topCenter)}</div><div>${e(s==null?void 0:s.topRight)}</div></div>
|
|
12
|
+
<div class="vistaview-bottom-bar vistaview-ui"><div>${e(s==null?void 0:s.bottomLeft)}</div><div>${e(s==null?void 0:s.bottomCenter)}</div><div>${e(s==null?void 0:s.bottomRight)}</div></div>
|
|
13
|
+
<div class="vistaview-prev-btn vistaview-ui"><button>${U}</button></div>
|
|
14
|
+
<div class="vistaview-next-btn vistaview-ui"><button>${j}</button></div>
|
|
15
|
+
</div>
|
|
16
|
+
</div>`)}let $=null,M=null,Z=null;function V(s){A(s);const t=s.imageContainerElm,e=s.elements.length;if(!t)return;let n=0,i=0,o=0,l=0,a=!1;$=r=>{r.preventDefault(),r.stopPropagation(),s.isZoomed===!1&&(a=!0,n=r.pageX,i=r.pageY,o=r.pageX,l=Date.now())},M=r=>{if(r.preventDefault(),r.stopPropagation(),s.isZoomed!==!1||!a)return;const h=r.pageX-n,c=r.pageY-i;o=r.pageX,t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),t.style.setProperty("--vistaview-pointer-diff-y",`${c}px`)},Z=r=>{if(r.preventDefault(),r.stopPropagation(),s.isZoomed!==!1||!a)return;a=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),c=o-n,d=Date.now()-l,v=c/d,u=s.options.touchSpeedThreshold||.7,E=h.find(f=>f.dataset.vistaviewPos==="0"),m=Number(E.dataset.vistaviewIndex),b=s.isReducedMotion;function g(){h[0].removeEventListener("transitionend",g),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(f=>{f.style.transition="",f.style.translate=""})}function x(f){h.forEach(L=>{L.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,L.style.translate=f})}v<-u||v>u?(h[0].addEventListener("transitionend",()=>{s.isReducedMotion=!0,g(),s.view(v<-u?(m+1)%e:(m-1+e)%e,{next:v<-u,prev:v>u}),s.isReducedMotion=b}),x(v<-u?"-100%":"100%")):(h[0].addEventListener("transitionend",g),x("0%"))},t.addEventListener("pointermove",M),t.addEventListener("pointerup",Z),t.addEventListener("pointerdown",$)}function A(s){const t=s.imageContainerElm;t&&(M&&t.removeEventListener("pointermove",M),Z&&t.removeEventListener("pointerup",Z),$&&t.removeEventListener("pointerdown",$))}const X=s=>{V(s)},_=({htmlElements:{to:s},index:{to:t},elements:e})=>{e instanceof NodeList&&t!==null&&(e.forEach(n=>n.style.opacity="1"),e[t].style.opacity="0"),s&&s.forEach(n=>{const i=Number(n.dataset.vistaviewPos);i!==0?(n.style.zIndex="1",n.style.left=100*i+"%"):n.style.zIndex="2"})},B=async({htmlElements:{from:s,to:t},images:{to:e},via:{next:n,prev:i},container:o,options:l,isReducedMotion:a})=>{if(!e)throw new Error("VistaView: images is null in defaultTransition()");if(a)return o.innerHTML="",t.forEach(h=>{o.appendChild(h)}),e[e.length===1?0:Math.floor(e.length/2)];const r=s.filter(h=>h.dataset.vistaviewPos==="0"||(n?h.dataset.vistaviewPos==="1":h.dataset.vistaviewPos==="-1"));return await new Promise(h=>{function c(){o.innerHTML="",t.forEach(d=>{o.appendChild(d)}),h(0)}r[r.length-1].addEventListener("transitionend",c),r.forEach(d=>{d.style.transition=`translate ${l.animationDurationBase*.5}ms ease-out`,d.style.translate=n?"-100%":i?"100%":"0%"})}),e[e.length===1?0:Math.floor(e.length/2)]},F=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),A(s)},R={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.7,preloads:1,keyboardListeners:!0,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",k(),"close"],bottomCenter:["description"]}},I={somethingOpened:null};class et{constructor(t,e){p(this,"options");p(this,"elements");p(this,"isReducedMotion");p(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n;const e=this._value;this._value=t,(n=this._vistaView)==null||n.swap(e,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});p(this,"rootElm",null);p(this,"imageContainerElm",null);p(this,"customControls",{});p(this,"currentImages",null);p(this,"currentItems",null);p(this,"navActive",!0);p(this,"isZoomed",!1);p(this,"onClickElements",[]);p(this,"onResizeHandler",null);p(this,"onKeyDown",null);p(this,"userSetup",_);p(this,"userTransition",B);p(this,"userClose",F);p(this,"userInit",X);p(this,"onZoomedPointerDown",null);p(this,"onZoomedPointerMove",null);p(this,"onZoomedPointerUp",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...R,...e||{},controls:{...R.controls,...(e==null?void 0:e.controls)||{}}},this.options.initFunction&&(this.userInit=this.options.initFunction),this.options.transitionFunction&&(this.userTransition=this.options.transitionFunction),this.options.closeFunction&&(this.userClose=this.options.closeFunction),this.options.initFunction&&(this.userInit=this.options.initFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((n,i)=>{this.onClickElements.push(o=>{o.preventDefault(),this.open(i)}),n.addEventListener("click",this.onClickElements[i])})}async swap(t,e){var h,c;if(!I.somethingOpened||t===e||t===null||this.elements.length===1)return;if(!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:i}=this.getCurrentIndexes(e),o=this.getImages(n),l=o.map((d,v)=>O(d,i[v]));l.forEach((d,v)=>{var m,b;const u=d.querySelector(".vistaview-image-highres"),E=o[v].imageElm;if(u.complete&&u.naturalWidth>0){const{width:g,height:x}=W(E);g&&x&&(u.style.setProperty("--vistaview-fitted-width",`${g}px`),u.style.setProperty("--vistaview-fitted-height",`${x}px`)),u.classList.add("vistaview-image-loaded"),(m=d.querySelector(".vistaview-image-lowres"))==null||m.classList.add("vistaview-image--hidden");const{width:f,height:L}=S(u);u.style.width=`${f}px`,u.style.height=`${L}px`,u.width=u.naturalWidth,u.height=u.naturalHeight,(b=u.parentElement)!=null&&b.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()}}),this.navActive=!1;const a={htmlElements:{from:this.currentItems,to:l},images:{from:this.currentImages,to:o},index:{from:t,to:e},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(a);const r=await this.userTransition(a);this.navActive=!0,this.setInitialDimPos(r),this.currentImages=o,this.currentItems=l,this.loadImages(),this.setCurrentDescription(),(c=(h=this.options).onImageView)==null||c.call(h,a)}setZoomed(t){var e,n,i,o,l,a;if(this.isZoomed!==t){if(this.isZoomed){let r=this.isZoomed;if(r.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((e=r.parentElement)==null||e.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=r.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((i=r.parentElement)==null||i.removeEventListener("pointerup",this.onZoomedPointerUp),this.onZoomedPointerUp=null),r==null||r.style.removeProperty("--pointer-diff-x"),r==null||r.style.removeProperty("--pointer-diff-y"),setTimeout(()=>{r==null||r.classList.remove("vistaview-image--zooming")},500),this.isZoomed=!1,!t)return}if(t){this.isZoomed=t,t.classList.add("vistaview-image--zooming"),t==null||t.style.setProperty("--pointer-diff-x","0px"),t==null||t.style.setProperty("--pointer-diff-y","0px");let r=!1,h=0,c=0,d=0,v=0,u=0,E=0;this.onZoomedPointerDown=m=>{m.preventDefault(),m.stopPropagation(),r=!0,h=m.pageX,c=m.pageY,t.setPointerCapture(m.pointerId)},this.onZoomedPointerMove=m=>{if(!r)return;m.preventDefault(),u=m.pageX-h,E=m.pageY-c;const b=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),g=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:x,minDiffY:f,maxDiffY:L,minDiffX:D}=q(b,g),P=Math.min(x,Math.max(D,d+u)),z=Math.min(L,Math.max(f,v+E));u=P-d,E=z-v,t==null||t.style.setProperty("--pointer-diff-x",`${P}px`),t==null||t.style.setProperty("--pointer-diff-y",`${z}px`)},this.onZoomedPointerUp=m=>{r=!1,t.releasePointerCapture(m.pointerId),d+=u,v+=E,u=0,E=0},(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerdown",this.onZoomedPointerDown),(l=t==null?void 0:t.parentElement)==null||l.addEventListener("pointermove",this.onZoomedPointerMove),(a=t==null?void 0:t.parentElement)==null||a.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var o,l,a,r,h;const t=(o=this.rootElm)==null?void 0:o.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),e=t.width,n=t.height;t.dataset.vistaviewInitialWidth||(t.dataset.vistaviewInitialWidth=e.toString()),t.dataset.vistaviewInitialHeight||(t.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(t);const i=(t.naturalWidth||0)*this.options.maxZoomLevel;if(e&&i&&e<i){const c=Math.min(e+this.options.zoomStep,i);t.style.width=`${c}px`;const d=c/e*n;t.style.height=`${d}px`,(a=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-out-btn"))==null||a.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=c.toString(),t.dataset.vistaviewCurrentHeight=d.toString(),c===i&&((h=(r=this.rootElm)==null?void 0:r.querySelector("button.vistaview-zoom-in-btn"))==null||h.setAttribute("disabled","true"))}}zoomOut(){var l,a,r,h,c;const t=(l=this.rootElm)==null?void 0:l.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),e=t.width,n=t.height,i=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,o=d=>{d.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",o))};if(t.addEventListener("transitionend",o),t.classList.add("vistaview-image--zooming-out"),e&&i&&e>i){const d=Math.max(e-this.options.zoomStep,i);t.style.width=`${d}px`;const v=d/e*n;t.style.height=`${v}px`,(r=(a=this.rootElm)==null?void 0:a.querySelector("button.vistaview-zoom-in-btn"))==null||r.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=d.toString(),t.dataset.vistaviewCurrentHeight=v.toString();const{maxDiffX:u,minDiffY:E,maxDiffY:m,minDiffX:b}=q(d,v);let g=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),x=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");g=Math.min(u,Math.max(b,g)),x=Math.min(m,Math.max(E,x)),t==null||t.style.setProperty("--pointer-diff-x",`${g}px`),t==null||t.style.setProperty("--pointer-diff-y",`${x}px`),d===i&&((c=(h=this.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"))==null||c.setAttribute("disabled","true"),t.removeAttribute("data-vistaview-current-width"),t.removeAttribute("data-vistaview-current-height"),t.removeAttribute("data-vistaview-initial-width"),t.removeAttribute("data-vistaview-initial-height"),this.setZoomed(!1))}}clearZoom(){}getImages(t){return t.map((e,n)=>{const i=this.elements[e];if(i instanceof HTMLElement){const o=i.querySelector("img"),l=i.getAttribute("href")||"",a=i.getAttribute("src")||"",r=i.dataset.vistaviewSrc||l||a||(o==null?void 0:o.src)||"",h=i.dataset.vistaviewAlt||i.getAttribute("alt")||(o==null?void 0:o.alt)||"",c=i.dataset.vistaviewThumb||(o==null?void 0:o.src)||l||a||"";return{index:t[n],src:r,alt:h,thumb:c,imageElm:i instanceof HTMLImageElement?i:o,anchorElm:i instanceof HTMLAnchorElement?i:void 0}}else return{index:t[n],...i}})}setInitialDimPos(t){if(!this.rootElm)return;const e=t.imageElm?y(t.imageElm):void 0,n=t.anchorElm?y(t.anchorElm):void 0,i=(n==null?void 0:n.width)||(e==null?void 0:e.width)||0,o=(n==null?void 0:n.height)||(e==null?void 0:e.height)||0,l=((n==null?void 0:n.left)||(e==null?void 0:e.left)||0)+i/2,a=((n==null?void 0:n.top)||(e==null?void 0:e.top)||0)+o/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",i+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",o+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-left",l+"px"),this.rootElm.style.setProperty("--vistaview-image-border-radius",T(n==null?void 0:n.borderRadius)||T(e==null?void 0:e.borderRadius)||"0px")}updateZoomButtonsVisibility(){var i;const t=(i=this.rootElm)==null?void 0:i.querySelector('[data-vistaview-pos="0"] img.vistaview-image-highres');if(!t)return;const e=this;function n(){var c,d;const o=(c=e.rootElm)==null?void 0:c.querySelector("button.vistaview-zoom-in-btn"),l=(d=e.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"),a=parseInt(t.style.width)||t.width,r=t.naturalWidth*e.options.maxZoomLevel,h=a<r&&r>0;o&&(o.style.display=h?"":"none"),l&&(l.style.display=h?"":"none")}t.complete&&t.naturalWidth>0?n():t.addEventListener("load",n)}loadImages(){if(!this.rootElm)return;this.rootElm.querySelectorAll(".vistaview-image-highres:not(.vistaview-image-loaded)").forEach((e,n)=>{const i=e,l=this.currentImages[n].imageElm,a={w:0,h:0};if(l){const{width:h,height:c}=W(l);a.w=Math.min(l.width,h),a.h=Math.min(l.height,c)}const r=(h=!1)=>()=>{var c;if(a.w&&a.h&&(i.style.width=`${a.w}px`,i.style.height=`${a.h}px`,i.style.setProperty("--vistaview-fitted-width",`${a.w}px`),i.style.setProperty("--vistaview-fitted-height",`${a.h}px`)),i.classList.add("vistaview-image-loaded"),i.width=i.naturalWidth,i.height=i.naturalHeight,h){const{width:d,height:v}=S(i);i.style.width=`${d}px`,i.style.height=`${v}px`}else setTimeout(()=>{const{width:d,height:v}=S(i);i.style.width=`${d}px`,i.style.height=`${v}px`},333);setTimeout(()=>{var d,v;(v=(d=i.parentElement)==null?void 0:d.querySelector(".vistaview-image-lowres"))==null||v.classList.add("vistaview-image--hidden")},500),(c=e.parentElement)!=null&&c.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};i.complete&&i.naturalWidth>0?r(!0)():i.onload=r(!1)})}setIndexDisplay(){this.elements.length!==1&&(this.rootElm.querySelector(".vistaview-index-display").textContent=`${this.currentIndex.value+1} / ${this.elements.length}`)}setCurrentDescription(){this.rootElm.querySelector(".vistaview-description").textContent=(this.currentImages[1]||this.currentImages[0]).alt||""}getCurrentIndexes(t){const e=this.options.preloads,n=this.elements.length,i=n<1||!e?[t]:[...new Set([...Array.from({length:e},(l,a)=>((t-e+a)%n+n)%n),t,...Array.from({length:e},(l,a)=>(t+1+a)%n)])],o=n<1||!e?[0]:i.map((l,a)=>a-Math.floor(i.length/2));return{images:i,positions:o}}setKeyboardListeners(){this.onKeyDown=t=>{switch(t.key){case"ArrowLeft":t.preventDefault(),this.prev();break;case"ArrowRight":t.preventDefault(),this.next();break;case"ArrowUp":t.preventDefault(),this.zoomIn();break;case"ArrowDown":t.preventDefault(),this.zoomOut();break;case"Escape":t.preventDefault(),this.close();break}},window.addEventListener("keydown",this.onKeyDown)}setResizeListeners(){this.onResizeHandler=()=>{var n;const t=this.currentImages[this.currentImages.length===1?0:Math.floor(this.currentImages.length/2)];this.setInitialDimPos(t);const e=(n=this.rootElm)==null?void 0:n.querySelectorAll(".vistaview-image-highres.vistaview-image-loaded");e==null||e.forEach(i=>{const o=i,{width:l,height:a}=S(o);o.classList.contains("vistaview-image--zooming")?(o.dataset.vistaviewInitialWidth=l.toString(),o.dataset.vistaviewInitialHeight=a.toString()):(o.style.width=`${l}px`,o.style.height=`${a}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var l,a,r,h,c,d,v,u,E,m,b,g,x;if(I.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(I.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(tt({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((l=this.rootElm)==null?void 0:l.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw I.somethingOpened=null,new Error("Failed to create VistaView element");const{images:e,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(e);const i=this.currentImages.map((f,L)=>O(f,n[L]));this.currentItems=i;const o={htmlElements:{from:null,to:this.currentItems},images:{from:null,to:this.currentImages},index:{from:null,to:t},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(o),this.imageContainerElm.innerHTML="",this.currentItems.forEach(f=>{this.imageContainerElm.appendChild(f)}),(a=this.rootElm.querySelector(".vistaview-close-btn"))==null||a.addEventListener("click",()=>this.close()),(r=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||r.addEventListener("click",()=>this.zoomIn()),(h=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||h.addEventListener("click",()=>this.zoomOut()),(c=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||c.addEventListener("click",()=>this.prev()),(d=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||d.addEventListener("click",()=>this.next()),[...this.options.controls.topLeft||[],...this.options.controls.topRight||[],...this.options.controls.topCenter||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomRight||[]].forEach(f=>{typeof f!="string"&&(this.customControls[f.name]=f)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(f=>{f.addEventListener("click",L=>{const D=this.customControls[L.currentTarget.dataset.vistaviewCustomControl],P=this.currentImages.find(z=>z.index===this.currentIndex.value);D&&P&&(D.onClick.constructor.name==="AsyncFunction"?(f.classList.add("vistaview-button--loading"),D.onClick(P).finally(()=>{f.classList.remove("vistaview-button--loading")})):D.onClick(P))})}),this.options.animationDurationBase&&this.rootElm.style.setProperty("--vistaview-animation-duration",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElm.style.setProperty("--vistaview-initial-z-index",`${this.options.initialZIndex}`),this.setInitialDimPos(this.currentImages[this.currentImages.length===1?0:Math.floor(this.currentImages.length/2)]),this.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((v=this.rootElm.querySelector(".vistaview-prev-btn"))==null||v.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-next-btn"))==null||u.classList.add("vistaview-ui--none"),(E=this.rootElm.querySelector(".vistaview-index-display"))==null||E.classList.add("vistaview-ui--none")),this.rootElm&&this.rootElm.classList.add("vistaview--initialized"),this.loadImages(),this.setCurrentDescription(),this.setIndexDisplay(),this.userInit(this),(b=(m=this.options).onOpen)==null||b.call(m,o),(x=(g=this.options).onImageView)==null||x.call(g,o)}async close(t=!0){var n,i,o;if(I.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(l=>{var r;let a;(r=this.rootElm)==null||r.addEventListener("transitionend",h=>{h.currentTarget===this.rootElm&&(a&&clearTimeout(a),a=setTimeout(()=>{l()},333))})}));const e={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},container:this.imageContainerElm,elements:this.elements,via:{prev:!1,next:!1},isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userClose(this),(o=(i=this.options).onClose)==null||o.call(i,e),document.body.removeChild(this.rootElm),this.currentIndex._value=null,this.currentIndex._via={next:!1,prev:!1},this.rootElm=null,this.imageContainerElm=null,this.currentImages=null,this.currentItems=null,this.navActive=!0,this.onResizeHandler&&(window.removeEventListener("resize",this.onResizeHandler),this.onResizeHandler=null),this.onKeyDown&&(window.removeEventListener("keydown",this.onKeyDown),this.onKeyDown=null),(this.onZoomedPointerDown||this.onZoomedPointerMove||this.onZoomedPointerUp)&&(this.setZoomed(!1),this.onZoomedPointerDown=null,this.onZoomedPointerMove=null,this.onZoomedPointerUp=null),I.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach((t,e)=>{t.removeEventListener("click",this.onClickElements[e])})}view(t,e){I.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=e||{next:!1,prev:!1},this.currentIndex.value=t)}next(){I.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){I.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return I.somethingOpened===this?this.currentIndex.value:-1}}function it(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let e=0;e<t.length;e++){const n=t[e];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${e} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const e=s;for(let n=0;n<e.length;n++)if(!e[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function nt({elements:s,...t}){if(!s)throw new Error("No elements");let e=it(s);if(typeof e=="string")return console.error(e),console.warn("VistaView: silently returning."),null;const n=new et(e,t);return{open:(i=0)=>n.open(i),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:i=>{n.view(i)}}}w.DefaultOptions=R,w.defaultClose=F,w.defaultInit=X,w.defaultSetup=_,w.defaultTransition=B,w.removeTouchActions=A,w.setTouchActions=V,w.vistaView=nt,w.vistaViewDownload=k,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),n=require("./vistaview.cjs");function d(t){let e=null;return r.onMounted(()=>{e=n.vistaView(t)}),r.onUnmounted(()=>{e==null||e.destroy(),e=null}),{open:u=>e==null?void 0:e.open(u),close:()=>e==null?void 0:e.close(),next:()=>e==null?void 0:e.next(),prev:()=>e==null?void 0:e.prev(),getCurrentIndex:()=>(e==null?void 0:e.getCurrentIndex())??-1,view:u=>e==null?void 0:e.view(u)}}const V=r.defineComponent({name:"VistaView",props:{selector:{type:String,required:!0},class:String},setup(t,{slots:e,attrs:u}){const l=r.ref(null);let o=null;return r.onMounted(()=>{if(l.value){if(!t.selector)throw new Error("VistaView: selector is required");o=n.vistaView({...u,elements:l.value.querySelectorAll(t.selector)})}}),r.onUnmounted(()=>{o==null||o.destroy(),o=null}),()=>{var i;return r.h("div",{ref:l,class:t.class},(i=e.default)==null?void 0:i.call(e))}}});exports.VistaView=V;exports.useVistaView=d;
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export type {
|
|
4
|
-
|
|
5
|
-
export declare function useVistaView(options?: UseVistaViewOptions): {
|
|
6
|
-
container: Ref<HTMLElement | null, HTMLElement | null>;
|
|
1
|
+
import { PropType } from 'vue';
|
|
2
|
+
import { VistaViewParams, VistaViewInterface, VistaViewImage } from './vistaview';
|
|
3
|
+
export type { VistaViewParams, VistaViewInterface, VistaViewImage };
|
|
4
|
+
export declare function useVistaView(options: VistaViewParams): {
|
|
7
5
|
open: (i?: number) => void | undefined;
|
|
8
6
|
close: () => void | undefined;
|
|
9
7
|
next: () => void | undefined;
|
|
@@ -11,4 +9,19 @@ export declare function useVistaView(options?: UseVistaViewOptions): {
|
|
|
11
9
|
getCurrentIndex: () => number;
|
|
12
10
|
view: (i: number) => void | undefined;
|
|
13
11
|
};
|
|
12
|
+
export declare const VistaView: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
13
|
+
selector: {
|
|
14
|
+
type: PropType<string>;
|
|
15
|
+
required: true;
|
|
16
|
+
};
|
|
17
|
+
class: StringConstructor;
|
|
18
|
+
}>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
21
|
+
selector: {
|
|
22
|
+
type: PropType<string>;
|
|
23
|
+
required: true;
|
|
24
|
+
};
|
|
25
|
+
class: StringConstructor;
|
|
26
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
14
27
|
//# sourceMappingURL=vue.d.ts.map
|
package/dist/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,KAAK,QAAQ,EAAE,MAAM,KAAK,CAAC;AAErF,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEvF,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC;AAEpE,wBAAgB,YAAY,CAAC,OAAO,EAAE,eAAe;eAatC,MAAM;;;;;cAKP,MAAM;EAEnB;AAED,eAAO,MAAM,SAAS;;cAIA,QAAQ,CAAC,MAAM,CAAC;;;;;;;;cAAhB,QAAQ,CAAC,MAAM,CAAC;;;;iGAyBpC,CAAC"}
|
package/dist/vue.js
CHANGED
|
@@ -1,22 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
prev: () => o?.prev(),
|
|
18
|
-
getCurrentIndex: () => o?.getCurrentIndex() ?? -1,
|
|
19
|
-
view: (e) => o?.view(e)
|
|
20
|
-
};
|
|
1
|
+
import { defineComponent as w, ref as V, onMounted as d, onUnmounted as i, h as m } from "vue";
|
|
2
|
+
import { vistaView as f } from "./vistaview.js";
|
|
3
|
+
function n(r) {
|
|
4
|
+
let e = null;
|
|
5
|
+
return d(() => {
|
|
6
|
+
e = f(r);
|
|
7
|
+
}), i(() => {
|
|
8
|
+
e == null || e.destroy(), e = null;
|
|
9
|
+
}), {
|
|
10
|
+
open: (l) => e == null ? void 0 : e.open(l),
|
|
11
|
+
close: () => e == null ? void 0 : e.close(),
|
|
12
|
+
next: () => e == null ? void 0 : e.next(),
|
|
13
|
+
prev: () => e == null ? void 0 : e.prev(),
|
|
14
|
+
getCurrentIndex: () => (e == null ? void 0 : e.getCurrentIndex()) ?? -1,
|
|
15
|
+
view: (l) => e == null ? void 0 : e.view(l)
|
|
16
|
+
};
|
|
21
17
|
}
|
|
22
|
-
|
|
18
|
+
const x = w({
|
|
19
|
+
name: "VistaView",
|
|
20
|
+
props: {
|
|
21
|
+
selector: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: !0
|
|
24
|
+
},
|
|
25
|
+
class: String
|
|
26
|
+
},
|
|
27
|
+
setup(r, { slots: e, attrs: l }) {
|
|
28
|
+
const t = V(null);
|
|
29
|
+
let o = null;
|
|
30
|
+
return d(() => {
|
|
31
|
+
if (t.value) {
|
|
32
|
+
if (!r.selector) throw new Error("VistaView: selector is required");
|
|
33
|
+
o = f({
|
|
34
|
+
...l,
|
|
35
|
+
elements: t.value.querySelectorAll(r.selector)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}), i(() => {
|
|
39
|
+
o == null || o.destroy(), o = null;
|
|
40
|
+
}), () => {
|
|
41
|
+
var u;
|
|
42
|
+
return m("div", { ref: t, class: r.class }, (u = e.default) == null ? void 0 : u.call(e));
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
export {
|
|
47
|
+
x as VistaView,
|
|
48
|
+
n as useVistaView
|
|
49
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vistaview",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A lightweight, zero-dependency image lightbox library with smooth animations and touch support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
],
|
|
76
76
|
"scripts": {
|
|
77
77
|
"dev": "vite",
|
|
78
|
-
"build": "tsc && vite build",
|
|
78
|
+
"build": "tsc && vite build && BUILD_UMD=true vite build",
|
|
79
79
|
"preview": "vite preview",
|
|
80
80
|
"prepare": "husky",
|
|
81
81
|
"test": "echo \"no test specified\""
|
|
@@ -93,14 +93,8 @@
|
|
|
93
93
|
"solid-js": "^1.9.10",
|
|
94
94
|
"svelte": "^5.45.6",
|
|
95
95
|
"typescript": "~5.9.3",
|
|
96
|
-
"vite": "
|
|
96
|
+
"vite": "^6.4.1",
|
|
97
97
|
"vite-plugin-dts": "^4.5.4",
|
|
98
98
|
"vue": "^3.5.25"
|
|
99
|
-
},
|
|
100
|
-
"overrides": {
|
|
101
|
-
"vite": "npm:rolldown-vite@7.2.5"
|
|
102
|
-
},
|
|
103
|
-
"dependencies": {
|
|
104
|
-
"isomorphic-dompurify": "^2.33.0"
|
|
105
99
|
}
|
|
106
100
|
}
|
package/dist/types.d.ts
DELETED
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|