vistaview 0.1.0 → 0.1.1

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 CHANGED
@@ -8,7 +8,7 @@ A lightweight, modern image lightbox library for the web. Zero dependencies, fra
8
8
  - 📱 **Mobile-first** — Touch gestures, smooth animations, responsive design
9
9
  - 🎨 **Customizable** — Configurable controls, animations, and styling
10
10
  - ♿ **Accessible** — Keyboard navigation, reduced motion support
11
- - 🔧 **Framework-agnostic** — Works with vanilla JS, React, Vue, or any framework
11
+ - 🔧 **Framework-agnostic** — Works with vanilla JS, React, Vue, Svelte, Solid, or any framework
12
12
  - 🖼️ **Progressive loading** — Low-res thumbnails → high-res images with smooth transitions
13
13
  - 🔍 **Zoom support** — Zoom in/out with buttons, respects actual image resolution
14
14
 
@@ -177,6 +177,26 @@ VistaView uses CSS custom properties for easy theming:
177
177
 
178
178
  VistaView works in all modern browsers (Chrome, Firefox, Safari, Edge).
179
179
 
180
+ ## Framework Integration
181
+
182
+ VistaView provides official bindings for popular frameworks:
183
+
184
+ ```tsx
185
+ // React
186
+ import { useVistaView, VistaView } from 'vistaview/react';
187
+
188
+ // Vue
189
+ import { useVistaView } from 'vistaview/vue';
190
+
191
+ // Svelte
192
+ import { useVistaView } from 'vistaview/svelte';
193
+
194
+ // Solid
195
+ import { useVistaView } from 'vistaview/solid';
196
+ ```
197
+
198
+ See [framework-integration.md](./framework-integration.md) for detailed examples.
199
+
180
200
  ## License
181
201
 
182
202
  MIT
package/dist/react.cjs ADDED
@@ -0,0 +1 @@
1
+ const e=require(`./vistaview-DcqJLxF6.cjs`);let t=require(`react`),n=require(`react/jsx-runtime`);function r(n={}){let r=(0,t.useRef)(null),i=(0,t.useRef)(null);return(0,t.useEffect)(()=>{if(r.current)return i.current=e.t({parent:r.current,...n}),()=>{i.current?.destroy(),i.current=null}},[]),{ref:r,open:(0,t.useCallback)((e=0)=>i.current?.open(e),[]),close:(0,t.useCallback)(()=>i.current?.close(),[]),next:(0,t.useCallback)(()=>i.current?.next(),[]),prev:(0,t.useCallback)(()=>i.current?.prev(),[]),getCurrentIndex:(0,t.useCallback)(()=>i.current?.getCurrentIndex()??-1,[]),view:(0,t.useCallback)(e=>i.current?.view(e),[])}}function i({children:e,className:t,style:i,...a}){let{ref:o}=r(a);return(0,n.jsx)(`div`,{ref:o,className:t,style:i,children:e})}exports.VistaView=i,exports.useVistaView=r;
@@ -0,0 +1,20 @@
1
+ import { VistaViewOptions, VistaViewInterface, VistaViewImage } from './vistaview';
2
+ export type { VistaViewOptions, VistaViewInterface, VistaViewImage };
3
+ type UseVistaViewOptions = Omit<VistaViewOptions, 'parent'>;
4
+ type UseVistaViewReturn = {
5
+ ref: React.RefObject<HTMLDivElement | null>;
6
+ open: (startIndex?: number) => void;
7
+ close: () => void;
8
+ next: () => void;
9
+ prev: () => void;
10
+ getCurrentIndex: () => number;
11
+ view: (index: number) => void;
12
+ };
13
+ export declare function useVistaView(options?: UseVistaViewOptions): UseVistaViewReturn;
14
+ type VistaViewProps = UseVistaViewOptions & {
15
+ children: React.ReactNode;
16
+ className?: string;
17
+ style?: React.CSSProperties;
18
+ };
19
+ export declare function VistaView({ children, className, style, ...options }: VistaViewProps): React.ReactElement;
20
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExF,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC;AAErE,KAAK,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAE5D,KAAK,kBAAkB,GAAG;IACxB,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC5C,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,eAAe,EAAE,MAAM,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,kBAAkB,CAsBlF;AAED,KAAK,cAAc,GAAG,mBAAmB,GAAG;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B,CAAC;AAEF,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,GAAG,OAAO,EACX,EAAE,cAAc,GAAG,KAAK,CAAC,YAAY,CAOrC"}
package/dist/react.js ADDED
@@ -0,0 +1,32 @@
1
+ import { t as vistaView } from "./vistaview-dor4TcfU.js";
2
+ import { useCallback, useEffect, useRef } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ function useVistaView(i = {}) {
5
+ let a = useRef(null), o = useRef(null);
6
+ return useEffect(() => {
7
+ if (a.current) return o.current = vistaView({
8
+ parent: a.current,
9
+ ...i
10
+ }), () => {
11
+ o.current?.destroy(), o.current = null;
12
+ };
13
+ }, []), {
14
+ ref: a,
15
+ open: useCallback((e = 0) => o.current?.open(e), []),
16
+ close: useCallback(() => o.current?.close(), []),
17
+ next: useCallback(() => o.current?.next(), []),
18
+ prev: useCallback(() => o.current?.prev(), []),
19
+ getCurrentIndex: useCallback(() => o.current?.getCurrentIndex() ?? -1, []),
20
+ view: useCallback((e) => o.current?.view(e), [])
21
+ };
22
+ }
23
+ function VistaView({ children: e, className: t, style: n, ...r }) {
24
+ let { ref: o } = useVistaView(r);
25
+ return /* @__PURE__ */ jsx("div", {
26
+ ref: o,
27
+ className: t,
28
+ style: n,
29
+ children: e
30
+ });
31
+ }
32
+ export { VistaView, useVistaView };
package/dist/solid.cjs ADDED
@@ -0,0 +1 @@
1
+ const e=require(`./vistaview-DcqJLxF6.cjs`);let t=require(`solid-js`);function n(n={}){let r=null;return(0,t.onCleanup)(()=>{r?.destroy(),r=null}),{init:t=>{r=e.t({parent:t,...n})},open:(e=0)=>r?.open(e),close:()=>r?.close(),next:()=>r?.next(),prev:()=>r?.prev(),getCurrentIndex:()=>r?.getCurrentIndex()??-1,view:e=>r?.view(e)}}exports.useVistaView=n;
@@ -0,0 +1,14 @@
1
+ import { VistaViewOptions, VistaViewInterface, VistaViewImage } from './vistaview';
2
+ export type { VistaViewOptions, VistaViewInterface, VistaViewImage };
3
+ type UseVistaViewOptions = Omit<VistaViewOptions, 'parent'>;
4
+ type UseVistaViewReturn = {
5
+ init: (container: HTMLElement) => void;
6
+ open: (startIndex?: number) => void;
7
+ close: () => void;
8
+ next: () => void;
9
+ prev: () => void;
10
+ getCurrentIndex: () => number;
11
+ view: (index: number) => void;
12
+ };
13
+ export declare function useVistaView(options?: UseVistaViewOptions): UseVistaViewReturn;
14
+ //# sourceMappingURL=solid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solid.d.ts","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExF,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC;AAErE,KAAK,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAE5D,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,CAAC,SAAS,EAAE,WAAW,KAAK,IAAI,CAAC;IACvC,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,eAAe,EAAE,MAAM,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,kBAAkB,CAmBlF"}
package/dist/solid.js ADDED
@@ -0,0 +1,22 @@
1
+ import { t as vistaView } from "./vistaview-dor4TcfU.js";
2
+ import { onCleanup } from "solid-js";
3
+ function useVistaView(n = {}) {
4
+ let r = null;
5
+ return onCleanup(() => {
6
+ r?.destroy(), r = null;
7
+ }), {
8
+ init: (t) => {
9
+ r = vistaView({
10
+ parent: t,
11
+ ...n
12
+ });
13
+ },
14
+ open: (e = 0) => r?.open(e),
15
+ close: () => r?.close(),
16
+ next: () => r?.next(),
17
+ prev: () => r?.prev(),
18
+ getCurrentIndex: () => r?.getCurrentIndex() ?? -1,
19
+ view: (e) => r?.view(e)
20
+ };
21
+ }
22
+ export { useVistaView };
@@ -0,0 +1 @@
1
+ const e=require(`./vistaview-DcqJLxF6.cjs`);let t=require(`svelte`);function n(n={}){let r=null;return(0,t.onDestroy)(()=>{r?.destroy(),r=null}),{init:t=>{r=e.t({parent:t,...n})},open:(e=0)=>r?.open(e),close:()=>r?.close(),next:()=>r?.next(),prev:()=>r?.prev(),getCurrentIndex:()=>r?.getCurrentIndex()??-1,view:e=>r?.view(e)}}exports.useVistaView=n;
@@ -0,0 +1,14 @@
1
+ import { VistaViewOptions, VistaViewInterface, VistaViewImage } from './vistaview';
2
+ export type { VistaViewOptions, VistaViewInterface, VistaViewImage };
3
+ type UseVistaViewOptions = Omit<VistaViewOptions, 'parent'>;
4
+ type UseVistaViewReturn = {
5
+ init: (container: HTMLElement) => void;
6
+ open: (startIndex?: number) => void;
7
+ close: () => void;
8
+ next: () => void;
9
+ prev: () => void;
10
+ getCurrentIndex: () => number;
11
+ view: (index: number) => void;
12
+ };
13
+ export declare function useVistaView(options?: UseVistaViewOptions): UseVistaViewReturn;
14
+ //# sourceMappingURL=svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svelte.d.ts","sourceRoot":"","sources":["../src/svelte.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExF,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC;AAErE,KAAK,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAE5D,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,CAAC,SAAS,EAAE,WAAW,KAAK,IAAI,CAAC;IACvC,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,eAAe,EAAE,MAAM,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,kBAAkB,CAmBlF"}
package/dist/svelte.js ADDED
@@ -0,0 +1,22 @@
1
+ import { t as vistaView } from "./vistaview-dor4TcfU.js";
2
+ import { onDestroy } from "svelte";
3
+ function useVistaView(n = {}) {
4
+ let r = null;
5
+ return onDestroy(() => {
6
+ r?.destroy(), r = null;
7
+ }), {
8
+ init: (t) => {
9
+ r = vistaView({
10
+ parent: t,
11
+ ...n
12
+ });
13
+ },
14
+ open: (e = 0) => r?.open(e),
15
+ close: () => r?.close(),
16
+ next: () => r?.next(),
17
+ prev: () => r?.prev(),
18
+ getCurrentIndex: () => r?.getCurrentIndex() ?? -1,
19
+ view: (e) => r?.view(e)
20
+ };
21
+ }
22
+ export { useVistaView };
@@ -0,0 +1,14 @@
1
+ var e=`<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>`,t=`<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>`,r=`<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>`,i=`<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>`,a=`<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`;function o(){return{name:`download`,icon:i,onClick:e=>{let t=document.createElement(`a`);t.href=e.src,t.download=e.src.split(`/`).pop()||`download`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}}}function s(e){if(typeof e==`string`)switch(e){case`zoomIn`:return`<button class="vistaview-zoom-in-button">${n}</button>`;case`zoomOut`:return`<button disabled class="vistaview-zoom-out-button">${r}</button>`;case`close`:return`<button class="vistaview-close-button">${a}</button>`;case`indexDisplay`:return`<div class="vistaview-index-display"></div>`;case`description`:return`<div class="vistaview-image-description"></div>`;default:return``}return`<button data-vistaview-custom-control="${e.name}">${e.icon}</button>`}function c(n,r){let i=e=>e?e.map(s).join(``):``;return`<div class="vistaview-root" id="vistaview-root">
2
+ <div class="vistaview-container">
3
+ <div class="vistaview-image-container">
4
+ ${n.map(e=>{let t=e.image?getComputedStyle(e.image).objectFit:``,n=e.image?.width,r=e.image?.height;return`<div class="vistaview-item">
5
+ <img class="vistaview-image-lowres"${t?` style="object-fit:${t}"`:``} src="${e.smallSrc||e.src}" alt="${e.alt||``}" width="${n}" height="${r}">
6
+ <img class="vistaview-image-highres" loading="lazy" style="width:${n}px;height:${r}px" src="${e.src}" alt="${e.alt||``}" width="${e.width}" height="${e.height}">
7
+ </div>`}).join(``)}
8
+ </div>
9
+ <div class="vistaview-top-bar vistaview-ui"><div>${i(r?.topLeft)}</div><div>${i(r?.topCenter)}</div><div>${i(r?.topRight)}</div></div>
10
+ <div class="vistaview-bottom-bar vistaview-ui"><div>${i(r?.bottomLeft)}</div><div>${i(r?.bottomCenter)}</div><div>${i(r?.bottomRight)}</div></div>
11
+ <div class="vistaview-prev-btn vistaview-ui"><button>${e}</button></div>
12
+ <div class="vistaview-next-btn vistaview-ui"><button>${t}</button></div>
13
+ </div>
14
+ </div>`}function l(e){let t=getComputedStyle(e);return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow}}var u=null;function d(){return u||(window.trustedTypes||(window.trustedTypes={createPolicy:(e,t)=>t}),u=window.trustedTypes.createPolicy(`vistaView-policy`,{createHTML:e=>e,createScript:()=>{throw Error(`Not implemented`)},createScriptURL:()=>{throw Error(`Not implemented`)}}),u)}function f(e){let t=d().createHTML(e),n=document.createElement(`template`);n.innerHTML=t;let r=n.content;return n.remove(),r}function p(e){return e&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(e.trim())&&e}function m(e){let t=window.getComputedStyle(e).objectFit||``,{width:n,height:r}=e.getBoundingClientRect(),i=e.naturalWidth,a=e.naturalHeight;if(!t||!i||!a)return{width:n,height:r};let o=i/a,s=n/r;switch(t){case`fill`:return{width:n,height:r};case`none`:return{width:i,height:a};case`contain`:return o>s?{width:n,height:n/o}:{width:r*o,height:r};case`cover`:return o<s?{width:n,height:n/o}:{width:r*o,height:r};case`scale-down`:{let e={width:i,height:a},t=o>s?{width:n,height:n/o}:{width:r*o,height:r};return t.width<=e.width&&t.height<=e.height?t:e}}return{width:n,height:r}}function h(e,t=!1){let n=window.innerWidth,r=window.innerHeight,i=e.naturalWidth,a=e.naturalHeight;if(!i||!a)return;if(i<n&&a<r){e.style.width=i+`px`,e.style.height=a+`px`;return}let o=i/a,s=n/r,c,l;o>s?(c=n,l=n/o):(l=r,c=r*o),t?(e.dataset.vistaviewInitialWidth=c.toString(),e.dataset.vistaviewInitialHeight=l.toString()):(e.style.width=c+`px`,e.style.height=l+`px`)}function g(e,t){let n=window.innerHeight,r=window.innerWidth,i=e,a=t,o=Math.max(0,(i-r)/2)+r/2,s=Math.max(0,(a-n)/2)+n/2,c=-o;return{maxDiffX:o,minDiffY:-s,maxDiffY:s,minDiffX:c}}var _={somethingOpened:!1};const v={detectReducedMotion:!0,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:1,controls:{topLeft:[`indexDisplay`],topRight:[`zoomIn`,`zoomOut`,o(),`close`],bottomCenter:[`description`]}};var y=class{options;elements;currentIndex=0;currentDescription=``;rootElement=null;containerElement=null;indexDisplayElement=null;descriptionElement=null;isActive=!1;isZoomed=!1;isReducedMotion;setInitialProperties=null;setFullScreenContain=null;onZoomedPointerDown=null;onZoomedPointerMove=null;onZoomedPointerUp=null;onPointerDown=null;onPointerMove=null;onPointerUp=null;constructor(e,t){this.elements=e,this.options={...v,...t||{},controls:{...v.controls,...t?.controls||{}}},this.isReducedMotion=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,this.elements.forEach((e,t)=>{let n=e.anchor||e.image;n&&(e.onClick=e=>{e.preventDefault(),this.open(t)},n.addEventListener(`click`,e.onClick))})}setZoomed(e){if(this.isZoomed===e)return;let t=this.isZoomed===!1?null:this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.isZoomed];if(this.isZoomed=e,this.isZoomed===!1&&t){this.onZoomedPointerDown&&=(t.parentElement?.removeEventListener(`pointerdown`,this.onZoomedPointerDown),null),this.onZoomedPointerMove&&=(t.parentElement?.removeEventListener(`pointermove`,this.onZoomedPointerMove),null),this.onZoomedPointerUp&&=(t.parentElement?.removeEventListener(`pointerup`,this.onZoomedPointerUp),null),t?.style.removeProperty(`--pointer-diff-x`),t?.style.removeProperty(`--pointer-diff-y`),setTimeout(()=>{t?.classList.remove(`vistaview-image--zooming`)},500);return}if(this.isZoomed!==!1){t=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.isZoomed],t.classList.add(`vistaview-image--zooming`),t?.style.setProperty(`--pointer-diff-x`,`0px`),t?.style.setProperty(`--pointer-diff-y`,`0px`);let e=!1,n=0,r=0,i=0,a=0,o=0,s=0;this.onZoomedPointerDown&&=(t.parentElement?.removeEventListener(`pointerdown`,this.onZoomedPointerDown),null),this.onZoomedPointerMove&&=(t.parentElement?.removeEventListener(`pointermove`,this.onZoomedPointerMove),null),this.onZoomedPointerUp&&=(t.parentElement?.removeEventListener(`pointerup`,this.onZoomedPointerUp),null),this.onZoomedPointerDown=i=>{i.preventDefault(),i.stopPropagation(),e=!0,n=i.pageX,r=i.pageY,t.setPointerCapture(i.pointerId)},this.onZoomedPointerMove=c=>{if(!e)return;c.preventDefault(),o=c.pageX-n,s=c.pageY-r;let{maxDiffX:l,minDiffY:u,maxDiffY:d,minDiffX:f}=g(parseInt(t?.dataset.vistaviewCurrentWidth||`0`),parseInt(t?.dataset.vistaviewCurrentHeight||`0`)),p=Math.min(l,Math.max(f,i+o)),m=Math.min(d,Math.max(u,a+s));o=p-i,s=m-a,t?.style.setProperty(`--pointer-diff-x`,`${p}px`),t?.style.setProperty(`--pointer-diff-y`,`${m}px`)},this.onZoomedPointerUp=n=>{e=!1,t.releasePointerCapture(n.pointerId),i+=o,a+=s,o=0,s=0},t?.parentElement?.addEventListener(`pointerdown`,this.onZoomedPointerDown),t?.parentElement?.addEventListener(`pointermove`,this.onZoomedPointerMove),t?.parentElement?.addEventListener(`pointerup`,this.onZoomedPointerUp)}}setIndexDisplay(){this.indexDisplayElement&&(this.indexDisplayElement.textContent=`${this.currentIndex+1} / ${this.elements.length}`)}setCurrentDescription(){this.descriptionElement&&(this.currentDescription=this.elements[this.currentIndex].alt||``,this.descriptionElement&&(this.descriptionElement.textContent=this.currentDescription))}getAnimationDurationBase(){let e=window.getComputedStyle(this.rootElement);return parseInt(e.getPropertyValue(`--vistaview-animation-duration`))}zoomIn(){let e=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.currentIndex],t=e.width,n=e.height;e.dataset.vistaviewInitialWidth||(e.dataset.vistaviewInitialWidth=t.toString()),e.dataset.vistaviewInitialHeight||(e.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(this.currentIndex);let r=(e.naturalWidth||0)*this.options.maxZoomLevel;if(t&&r&&t<r){let i=Math.min(t+this.options.zoomStep,r);e.style.width=`${i}px`;let a=i/t*n;e.style.height=`${a}px`,this.containerElement?.querySelector(`button.vistaview-zoom-out-button`)?.removeAttribute(`disabled`),e.dataset.vistaviewCurrentWidth=i.toString(),e.dataset.vistaviewCurrentHeight=a.toString(),i===r&&this.containerElement?.querySelector(`button.vistaview-zoom-in-button`)?.setAttribute(`disabled`,`true`)}}zoomOut(){let e=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.currentIndex],t=e.width,n=e.height,r=e.dataset.vistaviewInitialWidth?parseInt(e.dataset.vistaviewInitialWidth):0;if(e.classList.add(`vistaview-image--zooming-out`),setTimeout(()=>{e.classList.remove(`vistaview-image--zooming-out`)},333),t&&r&&t>r){let i=Math.max(t-this.options.zoomStep,r);e.style.width=`${i}px`;let a=i/t*n;e.style.height=`${a}px`,this.containerElement?.querySelector(`button.vistaview-zoom-in-button`)?.removeAttribute(`disabled`),e.dataset.vistaviewCurrentWidth=i.toString(),e.dataset.vistaviewCurrentHeight=a.toString();let{maxDiffX:o,minDiffY:s,maxDiffY:c,minDiffX:l}=g(i,a),u=parseInt(e?.style.getPropertyValue(`--pointer-diff-x`).replace(`px`,``)||`0`),d=parseInt(e?.style.getPropertyValue(`--pointer-diff-y`).replace(`px`,``)||`0`);u=Math.min(o,Math.max(l,u)),d=Math.min(c,Math.max(s,d)),e?.style.setProperty(`--pointer-diff-x`,`${u}px`),e?.style.setProperty(`--pointer-diff-y`,`${d}px`),i===r&&(this.containerElement?.querySelector(`button.vistaview-zoom-out-button`)?.setAttribute(`disabled`,`true`),e.removeAttribute(`data-vistaview-current-width`),e.removeAttribute(`data-vistaview-current-height`),e.removeAttribute(`data-vistaview-initial-width`),e.removeAttribute(`data-vistaview-initial-height`),this.setZoomed(!1))}}clearZoom(){let e=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.currentIndex];e.dataset.vistaviewInitialWidth&&(e.style.width=`${e.dataset.vistaviewInitialWidth}px`),e.dataset.vistaviewInitialHeight&&(e.style.height=`${e.dataset.vistaviewInitialHeight}px`),this.containerElement?.querySelector(`button.vistaview-zoom-in-button`)?.removeAttribute(`disabled`),this.containerElement?.querySelector(`button.vistaview-zoom-out-button`)?.setAttribute(`disabled`,`true`),e.removeAttribute(`data-vistaview-current-width`),e.removeAttribute(`data-vistaview-current-height`),e.removeAttribute(`data-vistaview-initial-width`),e.removeAttribute(`data-vistaview-initial-height`),this.setZoomed(!1)}resetImageOpacity(e=!1){this.elements.forEach((t,n)=>{t.image&&(t.image?.dataset.vistaviewInitialOpacity||(t.image.dataset.vistaviewInitialOpacity=t.image.style.opacity||`1`),n===this.currentIndex&&!e?t.image.style.opacity=`0`:t.image.style.opacity=t.image.dataset.vistaviewInitialOpacity)})}setTouchActions(){this.removeTouchActions();let e=this.containerElement?.querySelector(`.vistaview-image-container`);if(!e)return;let t=0,n=0,r=0,i=0,a=!1,o=this.currentIndex,s;this.onPointerDown=c=>{if(c.preventDefault(),c.stopPropagation(),this.isZoomed!==!1)return;o=this.currentIndex,a=!0,t=c.pageX,n=c.pageY,r=c.pageX,i=Date.now(),e.classList.add(`vistaview-image-container--pointer-down`);let l=this.containerElement?.querySelector(`.vistaview-image-container`),u=Array.from(l.querySelectorAll(`.vistaview-item`));s=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting&&(o=u.indexOf(e.target))})},{threshold:.5,root:this.containerElement}),u.forEach(e=>{s.observe(e)})},this.onPointerMove=i=>{if(i.preventDefault(),i.stopPropagation(),this.isZoomed!==!1||!a)return;let o=i.pageX-t,s=i.pageY-n;r=i.pageX,e.style.setProperty(`--vistaview-pointer-diff-x`,`${o}px`),e.style.setProperty(`--vistaview-pointer-diff-y`,`${s}px`)},this.onPointerUp=n=>{if(n.preventDefault(),n.stopPropagation(),this.isZoomed!==!1||!a)return;a=!1,s.disconnect();let c=(r-t)/(Date.now()-i),l=this.options.touchSpeedThreshold||1;c<-l&&o===this.currentIndex?o=Math.min(this.currentIndex+1,this.elements.length-1):c>l&&o===this.currentIndex&&(o=Math.max(this.currentIndex-1,0)),e.style.setProperty(`--vistaview-pointer-diff-x`,`0px`),e.style.setProperty(`--vistaview-pointer-diff-y`,`0px`),e.classList.remove(`vistaview-image-container--pointer-down`),o!==this.currentIndex&&this.view(o)},e.addEventListener(`pointermove`,this.onPointerMove),e.addEventListener(`pointerup`,this.onPointerUp),e.addEventListener(`pointerdown`,this.onPointerDown)}removeTouchActions(){let e=this.containerElement?.querySelector(`.vistaview-image-container`);e&&(this.onPointerMove&&e.removeEventListener(`pointermove`,this.onPointerMove),this.onPointerUp&&e.removeEventListener(`pointerup`,this.onPointerUp),this.onPointerDown&&e.removeEventListener(`pointerdown`,this.onPointerDown))}open(e){if(_.somethingOpened)return;if(_.somethingOpened=!0,this.isActive=!0,e||=0,e<0||e>=this.elements.length)throw Error(`VistaView: Index out of bounds:`+e);this.currentIndex=e;let t=c(this.elements,this.options.controls);if(document.body.prepend(f(t)),this.rootElement=document.querySelector(`#vistaview-root`),!this.rootElement)throw Error(`VistaView: Failed to create root element.`);if(this.options.detectReducedMotion&&this.isReducedMotion&&this.rootElement.classList.add(`vistaview--reduced-motion`),this.containerElement=this.rootElement.querySelector(`.vistaview-container`),!this.containerElement)throw Error(`VistaView: Failed to create container element.`);this.indexDisplayElement=this.containerElement.querySelector(`.vistaview-index-display`),this.descriptionElement=this.containerElement.querySelector(`.vistaview-image-description`),this.options.animationDurationBase&&this.rootElement.style.setProperty(`--vistaview-animation-duration`,`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElement.style.setProperty(`--vistaview-initial-z-index`,`${this.options.initialZIndex}`);let n=this.elements[e].image?l(this.elements[e].image):void 0,r=this.elements[e].anchor?l(this.elements[e].anchor):void 0,i=this.elements[e].anchor?this.elements[e].anchor:this.elements[e].image;if(i){let e=i.getBoundingClientRect();this.rootElement.style.setProperty(`--vistaview-container-initial-width`,`${e?.width}px`),this.rootElement.style.setProperty(`--vistaview-container-initial-height`,`${e?.height}px`),this.rootElement.style.setProperty(`--vistaview-container-initial-top`,`${e.top+e.height/2}px`),this.rootElement.style.setProperty(`--vistaview-container-initial-left`,`${e.left+e.width/2}px`)}this.rootElement.style.setProperty(`--vistaview-number-elements`,`${this.elements.length}`),this.rootElement.style.setProperty(`--vistaview-image-border-radius`,p(n?.borderRadius)||p(r?.borderRadius)||`0px`),this.setInitialProperties=()=>{if(!this.isActive)return;let e=this.elements[this.currentIndex].anchor?this.elements[this.currentIndex].anchor:this.elements[this.currentIndex].image;if(!e)return;let t=e.getBoundingClientRect();this.rootElement?.style.setProperty(`--vistaview-container-initial-width`,`${t?.width}px`),this.rootElement?.style.setProperty(`--vistaview-container-initial-height`,`${t?.height}px`),this.rootElement?.style.setProperty(`--vistaview-container-initial-top`,`${t.top+t.height/2}px`),this.rootElement?.style.setProperty(`--vistaview-container-initial-left`,`${t.left+t.width/2}px`)},window.addEventListener(`resize`,this.setInitialProperties);let a=[...this.options.controls.topLeft||[],...this.options.controls.topCenter||[],...this.options.controls.topRight||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomRight||[]].filter(e=>typeof e!=`string`);this.containerElement.querySelectorAll(`button`).forEach(e=>{let t=e.getAttribute(`data-vistaview-custom-control`);if(t){let n=a.find(e=>e.name===t);n&&e.addEventListener(`click`,()=>{n.onClick(this.elements[this.currentIndex])})}else e.classList.contains(`vistaview-zoom-in-button`)?e.addEventListener(`click`,()=>{this.zoomIn()}):e.classList.contains(`vistaview-zoom-out-button`)?e.addEventListener(`click`,()=>{this.zoomOut()}):e.classList.contains(`vistaview-close-button`)?e.addEventListener(`click`,()=>{this.close()}):e.parentElement?.classList.contains(`vistaview-prev-btn`)?e.addEventListener(`click`,()=>{this.prev()}):e.parentElement?.classList.contains(`vistaview-next-btn`)&&e.addEventListener(`click`,()=>{this.next()})}),this.setIndexDisplay(),this.setCurrentDescription(),this.rootElement?.style.setProperty(`--vistaview-current-index`,`${this.currentIndex}`),this.containerElement.querySelectorAll(`.vistaview-image-highres`).forEach((e,t)=>{let n=e,r=this.elements[t].image;if(r){let{width:e,height:t}=m(r),i=Math.min(r.width,e),a=Math.min(r.height,t);n.style.width=`${i}px`,n.style.height=`${a}px`,n.style.setProperty(`--vistaview-fitted-width`,`${i}px`),n.style.setProperty(`--vistaview-fitted-height`,`${a}px`)}function i(){n.classList.add(`vistaview-image-loaded`),setTimeout(()=>{h(n)},100),setTimeout(()=>{n.parentElement?.querySelector(`.vistaview-image-lowres`)?.classList.add(`vistaview-image--hidden`)},500)}n.complete?i():n.onload=i}),this.setFullScreenContain=()=>{this.isActive&&(this.containerElement?.querySelectorAll(`.vistaview-image-highres`))?.forEach(e=>{let t=e;h(t,t.classList.contains(`vistaview-image--zooming`))})},window.addEventListener(`resize`,this.setFullScreenContain),this.setTouchActions(),setTimeout(()=>{this.rootElement&&this.rootElement.classList.add(`vistaview--initialized`),this.resetImageOpacity()},33)}async close(e=!0){if(this.isActive){if(this.isActive=!1,e){let e=this.getAnimationDurationBase();this.rootElement?.classList.add(`vistaview--closing`),this.options.detectReducedMotion&&this.isReducedMotion||await new Promise(t=>{setTimeout(()=>{t(!0)},e*1.5)})}this.removeTouchActions(),this.rootElement?.remove(),this.rootElement=null,this.containerElement=null,this.resetImageOpacity(!0),this.setInitialProperties&&window.removeEventListener(`resize`,this.setInitialProperties),this.setFullScreenContain&&window.removeEventListener(`resize`,this.setFullScreenContain),_.somethingOpened=!1}}destroy(){this.isActive&&(this.close(!1),this.elements.forEach(e=>{let t=e.anchor||e.image;t&&e.onClick&&t.removeEventListener(`click`,e.onClick)}))}view(e){if(this.isActive){if(e<0||e>=this.elements.length)throw Error(`VistaView: Index out of bounds:`+e);this.clearZoom(),this.currentIndex=e,this.resetImageOpacity(),this.setIndexDisplay(),this.setCurrentDescription(),this.setInitialProperties&&this.setInitialProperties(),this.rootElement?.style.setProperty(`--vistaview-current-index`,`${this.currentIndex}`)}}next(){this.isActive&&this.view((this.currentIndex+1)%this.elements.length)}prev(){this.isActive&&this.view((this.currentIndex-1+this.elements.length)%this.elements.length)}getCurrentIndex(){return this.isActive?this.currentIndex:-1}},b=e=>{let t=e instanceof HTMLImageElement?e:e.querySelector(`img`);return{src:e.dataset.vistaviewSrc||e.getAttribute(`href`)||e.getAttribute(`src`)||``,width:+(e.dataset.vistaviewWidth||t?.naturalWidth||0),height:+(e.dataset.vistaviewHeight||t?.naturalHeight||0),smallSrc:t?.src||e.dataset.vistaviewSmallsrc||e.getAttribute(`src`)||``,alt:t?.alt||e.dataset.vistaviewAlt||e.getAttribute(`alt`)||``,anchor:e instanceof HTMLAnchorElement?e:void 0,image:t||void 0}};function x({parent:e,elements:t,...n}){if(!e&&!t)throw Error(`No parent or elements`);let r;if(e){let t=e.querySelector(`img[data-vistaview-src]`)?`img[data-vistaview-src]`:`a[href]`;r=Array.from(e.querySelectorAll(t)).map(b)}else if(typeof t==`string`)r=Array.from(document.querySelectorAll(t)).map(b);else if(t instanceof NodeList)r=Array.from(t).map(b);else if(Array.isArray(t))r=t;else throw Error(`Invalid elements`);if(!r.length)throw Error(`No elements found`);let i=new y(r,n);return{open:(e=0)=>i.open(e),close:()=>i.close(),next:()=>i.next(),prev:()=>i.prev(),destroy:()=>i.destroy(),getCurrentIndex:()=>i.getCurrentIndex(),view:e=>{i.view(e)}}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return x}});