vistaview 0.3.6 → 0.3.7

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
@@ -290,23 +290,23 @@ dist/svelte.js 0.54 kB │ gzip: 0.27 kB
290
290
  dist/solid.js 1.11 kB │ gzip: 0.52 kB
291
291
  dist/vue.js 1.29 kB │ gzip: 0.56 kB
292
292
  dist/react.js 1.54 kB │ gzip: 0.57 kB
293
- dist/vistaview.js 38.13 kB │ gzip: 9.48 kB
294
- [vite:dts] Declaration files built in 650ms.
293
+ dist/vistaview.js 37.52 kB │ gzip: 9.32 kB
294
+ [vite:dts] Declaration files built in 660ms.
295
295
 
296
296
  dist/vistaview.css 9.76 kB │ gzip: 1.69 kB
297
297
  dist/svelte.cjs 0.48 kB │ gzip: 0.29 kB
298
298
  dist/solid.cjs 0.92 kB │ gzip: 0.50 kB
299
299
  dist/vue.cjs 1.00 kB │ gzip: 0.51 kB
300
300
  dist/react.cjs 1.25 kB │ gzip: 0.52 kB
301
- dist/vistaview.cjs 30.30 kB │ gzip: 8.42 kB
302
- ✓ built in 771ms
301
+ dist/vistaview.cjs 29.74 kB │ gzip: 8.28 kB
302
+ ✓ built in 772ms
303
303
  vite v6.4.1 building for production...
304
304
  ✓ 6 modules transformed.
305
305
 
306
306
  [vite:dts] Start generate declaration files...
307
307
  dist/vistaview.css 9.76 kB │ gzip: 1.69 kB
308
- dist/vistaview.umd.js 30.45 kB │ gzip: 8.53 kB
309
- [vite:dts] Declaration files built in 654ms.
308
+ dist/vistaview.umd.js 29.89 kB │ gzip: 8.38 kB
309
+ [vite:dts] Declaration files built in 653ms.
310
310
 
311
311
  ✓ built in 740ms
312
312
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/lib/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAkJ1D;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAQ7D;AAMD,eAAO,MAAM,WAAW,GAAI,WAAW,SAAS,SAE/C,CAAC;AAKF,eAAO,MAAM,YAAY,EAAE,sBAsB1B,CAAC;AAIF,eAAO,MAAM,iBAAiB,EAAE,2BA2H/B,CAAC;AAIF,eAAO,MAAM,YAAY,EAAE,sBAK1B,CAAC"}
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/lib/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAkJ1D;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAQ7D;AAMD,eAAO,MAAM,WAAW,GAAI,WAAW,SAAS,SAE/C,CAAC;AAKF,eAAO,MAAM,YAAY,EAAE,sBAsB1B,CAAC;AAIF,eAAO,MAAM,iBAAiB,EAAE,2BAiH/B,CAAC;AAKF,eAAO,MAAM,YAAY,EAAE,sBAK1B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"vista-view.d.ts","sourceRoot":"","sources":["../../src/lib/vista-view.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAIV,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAIjB,qBAAa,+BAAgC,SAAQ,KAAK;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,cAAc;;;;;;;;;cAepB,gBAAgB,CAAC,UAAU,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE;IAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAA;CAEjE,CAAC;AAEF,qBAAa,SAAS;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,EAAE,CAAC;IACrD,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY;gBACM,MAAM,GAAG,IAAI;oBACT,SAAS,GAAG,IAAI;;;;;qBAOvB,MAAM,GAAG,IAAI;qBALb,MAAM;aAWR;YAAE,IAAI,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE;MAG3C;IAEF,OAAO,EAAE,WAAW,GAAG,IAAI,CAAQ;IACnC,iBAAiB,EAAE,WAAW,GAAG,IAAI,CAAQ;IAC7C,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB,CAAA;KAAE,CAAM;IAC/D,aAAa,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAQ;IACrD,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,CAAQ;IAC7C,SAAS,UAAQ;IACjB,QAAQ,EAAE,gBAAgB,GAAG,KAAK,CAAS;IAE3C,OAAO,CAAC,eAAe,CAIrB;IACF,OAAO,CAAC,qBAAqB,CAAwD;IAErF,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,SAAS,CAA6C;IAE9D,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,cAAc,CAAkD;IACxE,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,QAAQ,CAAsC;IAEtD,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,iBAAiB,CAA4C;IAErE,OAAO,CAAC,yBAAyB,CAAgC;gBAErD,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB;YA2C9E,IAAI;IA8FlB,OAAO,CAAC,SAAS;IAiGjB,OAAO,CAAC,MAAM;IAsCd,OAAO,CAAC,OAAO;IA2Df,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,gBAAgB;IA8BxB,OAAO,CAAC,2BAA2B;IAqCnC,OAAO,CAAC,UAAU;IAyFlB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,iBAAiB;IA2BzB,OAAO,CAAC,oBAAoB;IA6B5B,OAAO,CAAC,kBAAkB;IAqB1B,IAAI,CAAC,UAAU,GAAE,MAAU,GAAG,IAAI;IA6J5B,KAAK,CAAC,IAAI,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAqEvC,OAAO,IAAI,IAAI;IAWf,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAYnE,IAAI,IAAI,IAAI;IAKZ,IAAI,IAAI,IAAI;IAKZ,eAAe,IAAI,MAAM;CAG1B"}
1
+ {"version":3,"file":"vista-view.d.ts","sourceRoot":"","sources":["../../src/lib/vista-view.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAIV,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAIjB,qBAAa,+BAAgC,SAAQ,KAAK;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,cAAc;;;;;;;;;cAepB,gBAAgB,CAAC,UAAU,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE;IAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAA;CAEjE,CAAC;AAEF,qBAAa,SAAS;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,EAAE,CAAC;IACrD,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY;gBACM,MAAM,GAAG,IAAI;oBACT,SAAS,GAAG,IAAI;;;;;qBAOvB,MAAM,GAAG,IAAI;qBALb,MAAM;aAWR;YAAE,IAAI,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE;MAG3C;IAEF,OAAO,EAAE,WAAW,GAAG,IAAI,CAAQ;IACnC,iBAAiB,EAAE,WAAW,GAAG,IAAI,CAAQ;IAC7C,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB,CAAA;KAAE,CAAM;IAC/D,aAAa,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAQ;IACrD,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,CAAQ;IAC7C,SAAS,UAAQ;IACjB,QAAQ,EAAE,gBAAgB,GAAG,KAAK,CAAS;IAE3C,OAAO,CAAC,eAAe,CAIrB;IACF,OAAO,CAAC,qBAAqB,CAAwD;IAErF,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,SAAS,CAA6C;IAE9D,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,cAAc,CAAkD;IACxE,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,QAAQ,CAAsC;IAEtD,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,iBAAiB,CAA4C;IAErE,OAAO,CAAC,yBAAyB,CAAgC;gBAErD,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB;YA2C9E,IAAI;IAuFlB,OAAO,CAAC,SAAS;IAiGjB,OAAO,CAAC,MAAM;IAsCd,OAAO,CAAC,OAAO;IA2Df,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,gBAAgB;IA8BxB,OAAO,CAAC,2BAA2B;IAqCnC,OAAO,CAAC,UAAU;IAyFlB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,iBAAiB;IA2BzB,OAAO,CAAC,oBAAoB;IA6B5B,OAAO,CAAC,kBAAkB;IAqB1B,IAAI,CAAC,UAAU,GAAE,MAAU,GAAG,IAAI;IA6J5B,KAAK,CAAC,IAAI,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAqEvC,OAAO,IAAI,IAAI;IAWf,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAYnE,IAAI,IAAI,IAAI;IAKZ,IAAI,IAAI,IAAI;IAKZ,eAAe,IAAI,MAAM;CAG1B"}
@@ -1,11 +1,11 @@
1
- "use strict";var N=Object.defineProperty;var U=(s,t,i)=>t in s?N(s,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[t]=i;var w=(s,t,i)=>U(s,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function T(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 H(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(),a=s.naturalWidth,d=s.naturalHeight;if(!i)return{width:n,height:e};if(!a||!d)return{width:n,height:e};const o=a/d,l=n/e;switch(i){case"fill":return{width:n,height:e};case"none":return{width:a,height:d};case"contain":return o>l?{width:n,height:n/o}:{width:e*o,height:e};case"cover":return o<l?{width:n,height:n/o}:{width:e*o,height:e};case"scale-down":{const c={width:a,height:d},r=o>l?{width:n,height:n/o}:{width:e*o,height:e};return r.width<=c.width&&r.height<=c.height?r:c}}return{width:n,height:e}}function q(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 a=n/e,d=t/i;let o,l;return a>d?(o=t,l=t/a):(l=i,o=i*a),{width:o,height:l}}function k(s,t){const i=window.innerHeight,n=window.innerWidth,e=s,a=t,d=Math.max(0,(e-n)/2)+n/2,o=Math.max(0,(a-i)/2)+i/2,l=-d,c=-o;return{maxDiffX:d,minDiffY:c,maxDiffY:o,minDiffX:l}}const G='<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>',Q='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></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="8" x2="14" y1="11" y2="11"/></svg>',et='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',it='<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:it,onClick:async s=>{var a;const t=await fetch(s.src),i=await t.blob(),n=t.url,e=document.createElement("a");e.href=URL.createObjectURL(i),e.download=((a=n.split("/").pop())==null?void 0:a.split("?")[0].split("#")[0])||"download",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}}function nt(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${Q}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${tt}</button>`;case"close":return`<button class="vistaview-close-btn">${et}</button>`;case"indexDisplay":return'<div class="vistaview-index-display"></div>';case"description":return'<div class="vistaview-description"></div>';default:return""}return`<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`}function W(s,t){var r,h;const i=s.imageElm?getComputedStyle(s.imageElm):null,n=(i==null?void 0:i.objectFit)||"",e=((r=s.imageElm)==null?void 0:r.naturalWidth)||"",a=((h=s.imageElm)==null?void 0:h.naturalHeight)||"",d=(i==null?void 0:i.width)||"",o=(i==null?void 0:i.height)||"",l=document.createElement("div");l.className="vistaview-item",l.dataset.vistaviewPos=`${t!==void 0?t:""}`,l.dataset.vistaviewIndex=s.index.toString();const c=O(`<img class="vistaview-image-lowres"
1
+ "use strict";var N=Object.defineProperty;var U=(s,t,i)=>t in s?N(s,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[t]=i;var w=(s,t,i)=>U(s,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function H(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 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 K(s){const i=window.getComputedStyle(s).objectFit||"",{width:n,height:e}=s.getBoundingClientRect(),a=s.naturalWidth,d=s.naturalHeight;if(!i)return{width:n,height:e};if(!a||!d)return{width:n,height:e};const o=a/d,l=n/e;switch(i){case"fill":return{width:n,height:e};case"none":return{width:a,height:d};case"contain":return o>l?{width:n,height:n/o}:{width:e*o,height:e};case"cover":return o<l?{width:n,height:n/o}:{width:e*o,height:e};case"scale-down":{const h={width:a,height:d},r=o>l?{width:n,height:n/o}:{width:e*o,height:e};return r.width<=h.width&&r.height<=h.height?r:h}}return{width:n,height:e}}function q(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 a=n/e,d=t/i;let o,l;return a>d?(o=t,l=t/a):(l=i,o=i*a),{width:o,height:l}}function k(s,t){const i=window.innerHeight,n=window.innerWidth,e=s,a=t,d=Math.max(0,(e-n)/2)+n/2,o=Math.max(0,(a-i)/2)+i/2,l=-d,h=-o;return{maxDiffX:d,minDiffY:h,maxDiffY:o,minDiffX:l}}const G='<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>',Q='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></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="8" x2="14" y1="11" y2="11"/></svg>',et='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',it='<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:it,onClick:async s=>{var a;const t=await fetch(s.src),i=await t.blob(),n=t.url,e=document.createElement("a");e.href=URL.createObjectURL(i),e.download=((a=n.split("/").pop())==null?void 0:a.split("?")[0].split("#")[0])||"download",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}}function nt(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${Q}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${tt}</button>`;case"close":return`<button class="vistaview-close-btn">${et}</button>`;case"indexDisplay":return'<div class="vistaview-index-display"></div>';case"description":return'<div class="vistaview-description"></div>';default:return""}return`<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`}function W(s,t){var r,c;const i=s.imageElm?getComputedStyle(s.imageElm):null,n=(i==null?void 0:i.objectFit)||"",e=((r=s.imageElm)==null?void 0:r.naturalWidth)||"",a=((c=s.imageElm)==null?void 0:c.naturalHeight)||"",d=(i==null?void 0:i.width)||"",o=(i==null?void 0:i.height)||"",l=document.createElement("div");l.className="vistaview-item",l.dataset.vistaviewPos=`${t!==void 0?t:""}`,l.dataset.vistaviewIndex=s.index.toString();const h=O(`<img class="vistaview-image-lowres"
2
2
  style="${n?`object-fit:${n};`:""}${d?`width:${d};`:""}${o?`height:${o};`:""}"
3
3
  src="${s.thumb||s.src}"
4
4
  alt="${s.alt||""}"
5
5
  ${e?`width="${e}"`:""}
6
6
  ${a?`height="${a}"`:""}
7
7
  />
8
- <img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return l.appendChild(c),l}function st({controls:s,isReducedMotion:t}){const i=e=>e?e.map(nt).join(""):"";return O(`<div class="vistaview-root${t?" vistaview--reduced-motion":""}" id="vistaview-root">
8
+ <img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return l.appendChild(h),l}function st({controls:s,isReducedMotion:t}){const i=e=>e?e.map(nt).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>
@@ -13,4 +13,4 @@
13
13
  <div class="vistaview-prev-btn vistaview-ui"><button>${G}</button></div>
14
14
  <div class="vistaview-next-btn vistaview-ui"><button>${J}</button></div>
15
15
  </div>
16
- </div>`)}let P=null,$=null,M=null,Z=null;function X(s){R(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,a=0,d=0,o=null,l=0,c=!1;P=r=>{r.preventDefault(),r.stopPropagation(),s.isZoomed===!1&&(c=!0,n=r.pageX,e=r.pageY,a=r.pageX,d=r.pageY,l=Date.now(),o=null,t.setPointerCapture(r.pointerId))},$=r=>{if(r.preventDefault(),r.stopPropagation(),s.isZoomed!==!1||!c)return;const h=r.pageX-n,m=r.pageY-e;a=r.pageX,d=r.pageY,Math.abs(h)>=Math.abs(m)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),o=!0):Math.abs(m)>Math.abs(h)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${m}px`),o=!1)},Z=r=>{if(r.preventDefault(),r.stopPropagation(),t.releasePointerCapture(r.pointerId),s.isZoomed!==!1||!c)return;c=!1,o=null;const h=Array.from(t.querySelectorAll(".vistaview-item"));t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(m=>{m.style.transition="",m.style.translate=""})},M=r=>{if(r.preventDefault(),r.stopPropagation(),t.releasePointerCapture(r.pointerId),s.isZoomed!==!1||!c)return;c=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),m=a-n,f=d-e,u=Date.now()-l,v=m/u,y=f/u,p=s.options.touchSpeedThreshold||.5,b=h.find(E=>E.dataset.vistaviewPos==="0"),x=Number(b.dataset.vistaviewIndex);function g(){h[0].removeEventListener("transitionend",g),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(E=>{E.style.transition="",E.style.translate=""})}function I(E="0%",L="0%"){h.forEach(S=>{S.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,S.style.translate=`${E} ${L}`})}if(v<-p||v>p){let E=function(){h[0].removeEventListener("transitionend",E),setTimeout(()=>{const L=s.isReducedMotion;s.isReducedMotion=!0,g(),s.view(v<-p?(x+1)%i:(x-1+i)%i,{next:v<-p,prev:v>p}),s.isReducedMotion=L},100)};I(v<-p?"-100%":"100%"),h[0].addEventListener("transitionend",E)}else y<-p||y>p?(s.close(),I("0%","0%")):(h[0].addEventListener("transitionend",g),I("0%"))},t.addEventListener("pointermove",$),t.addEventListener("pointerup",M),t.addEventListener("pointerdown",P),t.addEventListener("pointercancel",Z)}function R(s){const t=s.imageContainerElm;t&&($&&t.removeEventListener("pointermove",$),M&&t.removeEventListener("pointerup",M),P&&t.removeEventListener("pointerdown",P),Z&&t.removeEventListener("pointercancel",Z))}const Y=s=>{X(s)},B=({htmlElements:{to:s},index:{to:t},elements:i})=>{i instanceof NodeList&&t!==null&&(i.forEach(n=>n.style.opacity="1"),i[t].style.opacity="0"),s&&s.forEach(n=>{const e=Number(n.dataset.vistaviewPos);e!==0?(n.style.zIndex="1",n.style.left=100*e+"%"):n.style.zIndex="2"})},_=async({htmlElements:{from:s,to:t},images:{to:i},via:{next:n,prev:e},options:a,isReducedMotion:d},o)=>{if(console.log("defaultTransition called"),!i)throw new Error("VistaView: images is null in defaultTransition()");const l=s.filter(c=>c.dataset.vistaviewPos==="0"||(n?c.dataset.vistaviewPos==="1":c.dataset.vistaviewPos==="-1"));if(d){console.log("reduced motion, no transition");return}await new Promise((c,r)=>{let h=0;if(o.aborted){console.log("transition aborted before start"),r(new D("Transition aborted"));return}const m=f=>{if(o.aborted){console.log("transition aborted before start"),r(new D("Transition aborted"));return}if(f.currentTarget.removeEventListener("transitionend",m),h++,h<l.length)return;const u=t==null?void 0:t.find(g=>g.dataset.vistaviewPos==="0"),v=u?Number(u.dataset.vistaviewIndex):0,y=l.find(g=>Number(g.dataset.vistaviewIndex)===v),p=y==null?void 0:y.querySelector(".vistaview-image-highres");if(!p){r(new Error("current image element not found"));return}if(!p.classList.contains("vistaview-image-loaded")){console.log("current image not loaded yet"),c(0);return}if(u==null||u.classList.add("vistaview-image-loaded"),p.classList.contains("vistaview-image-settled")){console.log("current image already settled"),u==null||u.classList.add("vistaview-image-settled"),c(0);return}let b=0;console.log("waiting for image to be settled...");const x=setInterval(()=>{if(o.aborted){console.log("transition aborted during wait"),clearInterval(x),r(new D("Transition aborted"));return}if(b++,b>a.animationDurationBase/20*1.5){console.log("timeout waiting for image to be settled"),clearInterval(x),c(0);return}p.classList.contains("vistaview-image-settled")&&(console.log("image settled"),u==null||u.classList.add("vistaview-image-settled"),clearInterval(x),c(0))},20)};l.forEach(f=>{f.style.transition=`translate ${a.animationDurationBase*.5}ms ease-out`,f.style.translate=n?"-100%":e?"100%":"0%",f.addEventListener("transitionend",m)})})},F=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),R(s)};class D extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const z={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",V(),"close"],bottomCenter:["description"]}},C={somethingOpened:null};class ot{constructor(t,i){w(this,"options");w(this,"elements");w(this,"isReducedMotion");w(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n;const i=this._value;this._value=t,(n=this._vistaView)==null||n.swap(i,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});w(this,"rootElm",null);w(this,"imageContainerElm",null);w(this,"customControls",{});w(this,"currentImages",null);w(this,"currentItems",null);w(this,"navActive",!0);w(this,"isZoomed",!1);w(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});w(this,"defaultOnClickHandler",t=>t.preventDefault());w(this,"onResizeHandler",null);w(this,"onKeyDown",null);w(this,"userSetup",B);w(this,"userTransition",_);w(this,"userClose",F);w(this,"userInit",Y);w(this,"onZoomedPointerDown",null);w(this,"onZoomedPointerMove",null);w(this,"onZoomedPointerUp",null);w(this,"transitionAbortController",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...z,...i||{},controls:{...z.controls,...(i==null?void 0:i.controls)||{}}},this.options.initFunction&&(this.userInit=this.options.initFunction),this.options.transitionFunction&&(this.userTransition=this.options.transitionFunction),this.options.closeFunction&&(this.userClose=this.options.closeFunction),this.options.initFunction&&(this.userInit=this.options.initFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((n,e)=>{n.dataset.vistaviewIndex=e.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}async swap(t,i){var l,c;if(!C.somethingOpened||t===i||t===null)return;if(console.log("Swapping from",t,"to",i),this.transitionAbortController&&this.transitionAbortController.abort(),!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:e}=this.getCurrentIndexes(i),a=this.getImages(n),d=a.map((r,h)=>W(r,e[h]));console.log("swap prepared");const o={htmlElements:{from:this.currentItems,to:d},images:{from:this.currentImages,to:a},index:{from:t,to:i},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(o),this.transitionAbortController=new AbortController;try{await this.userTransition(o,this.transitionAbortController.signal)}catch(r){r instanceof D||console.error(r)}console.log("swap completed"),this.imageContainerElm.innerHTML="",d.forEach(r=>{const h=r.dataset.vistaviewPos,m=r.dataset.vistaviewIndex;if(h==="0"){const f=this.currentItems.find(y=>y.dataset.vistaviewIndex===m),u=r.querySelector(".vistaview-image-highres"),v=f==null?void 0:f.querySelector(".vistaview-image-highres");v&&(u.setAttribute("class",v.getAttribute("class")||""),u.setAttribute("style",v.getAttribute("style")||"")),this.imageContainerElm.appendChild(r)}else this.imageContainerElm.appendChild(r)}),this.setInitialDimPos(),this.currentImages=a,this.currentItems=d,this.loadImages(),this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(c=(l=this.options).onImageView)==null||c.call(l,o)}setZoomed(t){var i,n,e,a,d,o;if(this.isZoomed!==t){if(this.isZoomed){let l=this.isZoomed;if(l.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((i=l.parentElement)==null||i.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=l.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((e=l.parentElement)==null||e.removeEventListener("pointerup",this.onZoomedPointerUp),this.onZoomedPointerUp=null),l==null||l.style.removeProperty("--pointer-diff-x"),l==null||l.style.removeProperty("--pointer-diff-y"),setTimeout(()=>{l==null||l.classList.remove("vistaview-image--zooming")},500),this.isZoomed=!1,!t)return}if(t){this.isZoomed=t,t.classList.add("vistaview-image--zooming"),t==null||t.style.setProperty("--pointer-diff-x","0px"),t==null||t.style.setProperty("--pointer-diff-y","0px");let l=!1,c=0,r=0,h=0,m=0,f=0,u=0;this.onZoomedPointerDown=v=>{v.preventDefault(),v.stopPropagation(),l=!0,c=v.pageX,r=v.pageY,t.setPointerCapture(v.pointerId)},this.onZoomedPointerMove=v=>{if(!l)return;v.preventDefault(),f=v.pageX-c,u=v.pageY-r;const y=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),p=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:b,minDiffY:x,maxDiffY:g,minDiffX:I}=k(y,p),E=Math.min(b,Math.max(I,h+f)),L=Math.min(g,Math.max(x,m+u));f=E-h,u=L-m,t==null||t.style.setProperty("--pointer-diff-x",`${E}px`),t==null||t.style.setProperty("--pointer-diff-y",`${L}px`)},this.onZoomedPointerUp=v=>{l=!1,t.releasePointerCapture(v.pointerId),h+=f,m+=u,f=0,u=0},(a=t==null?void 0:t.parentElement)==null||a.addEventListener("pointerdown",this.onZoomedPointerDown),(d=t==null?void 0:t.parentElement)==null||d.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var a,d,o,l,c;const t=(a=this.rootElm)==null?void 0:a.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 r=Math.min(i+this.options.zoomStep,e);t.style.width=`${r}px`;const h=r/i*n;t.style.height=`${h}px`,(o=(d=this.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=r.toString(),t.dataset.vistaviewCurrentHeight=h.toString(),r===e&&((c=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"))==null||c.setAttribute("disabled","true"))}}zoomOut(){var d,o,l,c,r;const t=(d=this.rootElm)==null?void 0:d.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height,e=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,a=h=>{h.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",a))};if(t.addEventListener("transitionend",a),t.classList.add("vistaview-image--zooming-out"),i&&e&&i>e){const h=Math.max(i-this.options.zoomStep,e);t.style.width=`${h}px`;const m=h/i*n;t.style.height=`${m}px`,(l=(o=this.rootElm)==null?void 0:o.querySelector("button.vistaview-zoom-in-btn"))==null||l.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=h.toString(),t.dataset.vistaviewCurrentHeight=m.toString();const{maxDiffX:f,minDiffY:u,maxDiffY:v,minDiffX:y}=k(h,m);let p=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),b=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");p=Math.min(f,Math.max(y,p)),b=Math.min(v,Math.max(u,b)),t==null||t.style.setProperty("--pointer-diff-x",`${p}px`),t==null||t.style.setProperty("--pointer-diff-y",`${b}px`),h===e&&((r=(c=this.rootElm)==null?void 0:c.querySelector("button.vistaview-zoom-out-btn"))==null||r.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 a=e.querySelector("img"),d=e.getAttribute("href")||"",o=e.getAttribute("src")||"",l=e.dataset.vistaviewSrc||d||o||(a==null?void 0:a.src)||"",c=e.dataset.vistaviewAlt||e.getAttribute("alt")||(a==null?void 0:a.alt)||"",r=e.dataset.vistaviewThumb||(a==null?void 0:a.src)||d||o||"";return{index:t[n],src:l,alt:c,thumb:r,imageElm:e instanceof HTMLImageElement?e:a,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var c,r;if(!this.rootElm)return;const t=(c=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:c.dataset.vistaviewIndex,i=((r=this.currentImages)==null?void 0:r.find(h=>h.index===Number(t)))||null;if(!i)return;const n=i.imageElm?T(i.imageElm):void 0,e=i.anchorElm?T(i.anchorElm):void 0,a=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,d=(e==null?void 0:e.height)||(n==null?void 0:n.height)||0,o=((e==null?void 0:e.left)||(n==null?void 0:n.left)||0)+a/2,l=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+d/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",d+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-top",l+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-left",o+"px"),this.rootElm.style.setProperty("--vistaview-image-border-radius",H(e==null?void 0:e.borderRadius)||H(n==null?void 0:n.borderRadius)||"0px")}updateZoomButtonsVisibility(){var e;const t=(e=this.rootElm)==null?void 0:e.querySelector('[data-vistaview-pos="0"] img.vistaview-image-highres');if(!t)return;const i=this;function n(){var r,h;const a=(r=i.rootElm)==null?void 0:r.querySelector("button.vistaview-zoom-in-btn"),d=(h=i.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,l=t.naturalWidth*i.options.maxZoomLevel,c=o<l&&l>0;a&&(a.style.display=c?"":"none"),d&&(d.style.display=c?"":"none")}t.complete&&t.naturalWidth>0?n():t.addEventListener("load",n)}loadImages(){if(!this.rootElm)return;this.rootElm.querySelectorAll(".vistaview-image-highres:not(.vistaview-image-loaded)").forEach((i,n)=>{const e=i,d=this.currentImages[n].imageElm,o={w:0,h:0};if(d){const{width:c,height:r}=K(d);o.w=Math.min(d.width,c),o.h=Math.min(d.height,r)}const l=()=>{var r;const c=()=>{var h;o.w&&o.h&&(e.style.width=`${o.w}px`,e.style.height=`${o.h}px`,e.style.setProperty("--vistaview-fitted-width",`${o.w}px`),e.style.setProperty("--vistaview-fitted-height",`${o.h}px`)),e.classList.add("vistaview-image-loaded"),e.width=e.naturalWidth,e.height=e.naturalHeight,setTimeout(()=>{var y,p;let m=0;const f=()=>{var b,x;m++,!(m<3)&&(e.removeEventListener("transitionend",f),(x=(b=e.parentElement)==null?void 0:b.querySelector(".vistaview-image-lowres"))==null||x.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled"))};e.addEventListener("transitionend",f);const{width:u,height:v}=q(e);e.style.width=`${u}px`,e.style.height=`${v}px`,o.w&&o.h&&u===o.w&&v===o.h?((p=(y=e.parentElement)==null?void 0:y.querySelector(".vistaview-image-lowres"))==null||p.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled")):(e.style.width=`${u}px`,e.style.height=`${v}px`)},100),(h=i.parentElement)!=null&&h.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((r=this.rootElm)!=null&&r.classList.contains("vistaview--opened"))c();else{const h=setInterval(()=>{var m;(m=this.rootElm)!=null&&m.classList.contains("vistaview--opened")&&(clearInterval(h),c())},50)}};e.complete&&e.naturalWidth>0?l():e.onload=l})}setIndexDisplay(){this.elements.length!==1&&(this.rootElm.querySelector(".vistaview-index-display").textContent=`${this.currentIndex.value+1} / ${this.elements.length}`)}setCurrentDescription(){this.rootElm.querySelector(".vistaview-description").textContent=(this.currentImages[1]||this.currentImages[0]).alt||""}getCurrentIndexes(t){const i=this.options.preloads,n=this.elements.length,e=n<1||!i?[t]:[...new Set([...Array.from({length:i},(d,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(d,o)=>(t+1+o)%n)])],a=n<1||!i?[0]:e.map((d,o)=>o-Math.floor(e.length/2));return{images:e,positions:a}}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:a,height:d}=q(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=a.toString(),e.dataset.vistaviewInitialHeight=d.toString()):(e.style.width=`${a}px`,e.style.height=`${d}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,l,c,r,h,m,f,u,v,y,p,b,x;if(C.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(C.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(st({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((o=this.rootElm)==null?void 0:o.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw C.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:i,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(i);const e=this.currentImages.map((g,I)=>W(g,n[I]));this.currentItems=e;const a={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(a),this.imageContainerElm.innerHTML="",this.currentItems.forEach(g=>{this.imageContainerElm.appendChild(g)});let d=0;this.rootElm.addEventListener("animationend",g=>{var I;g.currentTarget===this.rootElm&&(d++,d>=2&&((I=this.rootElm)==null||I.classList.add("vistaview--opened")))}),(l=this.rootElm.querySelector(".vistaview-close-btn"))==null||l.addEventListener("click",()=>this.close()),(c=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||c.addEventListener("click",()=>this.zoomIn()),(r=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||r.addEventListener("click",()=>this.zoomOut()),(h=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||h.addEventListener("click",()=>this.prev()),(m=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||m.addEventListener("click",()=>this.next()),[...this.options.controls.topLeft||[],...this.options.controls.topRight||[],...this.options.controls.topCenter||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomRight||[]].forEach(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],L=this.currentImages.find(S=>S.index===this.currentIndex.value);E&&L&&(E.onClick.constructor.name==="AsyncFunction"?(g.classList.add("vistaview-button--loading"),E.onClick(L).finally(()=>{g.classList.remove("vistaview-button--loading")})):E.onClick(L))})}),this.options.animationDurationBase&&this.rootElm.style.setProperty("--vistaview-animation-duration",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElm.style.setProperty("--vistaview-initial-z-index",`${this.options.initialZIndex}`),this.setInitialDimPos(),this.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((f=this.rootElm.querySelector(".vistaview-prev-btn"))==null||f.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-next-btn"))==null||u.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),(p=(y=this.options).onOpen)==null||p.call(y,a),(x=(b=this.options).onImageView)==null||x.call(b,a)}async close(t=!0){var n,e,a;if(C.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(d=>{var l;let o;(l=this.rootElm)==null||l.addEventListener("transitionend",c=>{c.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{d()},333))})}));const i={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},container:this.imageContainerElm,elements:this.elements,via:{prev:!1,next:!1},isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userClose(this),(a=(e=this.options).onClose)==null||a.call(e,i),document.body.removeChild(this.rootElm),this.currentIndex._value=null,this.currentIndex._via={next:!1,prev:!1},this.rootElm=null,this.imageContainerElm=null,this.currentImages=null,this.currentItems=null,this.navActive=!0,this.onResizeHandler&&(window.removeEventListener("resize",this.onResizeHandler),this.onResizeHandler=null),this.onKeyDown&&(window.removeEventListener("keydown",this.onKeyDown),this.onKeyDown=null),(this.onZoomedPointerDown||this.onZoomedPointerMove||this.onZoomedPointerUp)&&(this.setZoomed(!1),this.onZoomedPointerDown=null,this.onZoomedPointerMove=null,this.onZoomedPointerUp=null),this.transitionAbortController&&(this.transitionAbortController.abort(),this.transitionAbortController=null),C.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.dataset.vistaviewIndex&&delete t.dataset.vistaviewIndex,t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}view(t,i){C.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=i||{next:!1,prev:!1},this.currentIndex.value=t)}next(){C.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){C.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return C.somethingOpened===this?this.currentIndex.value:-1}}function rt(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let i=0;i<t.length;i++){const n=t[i];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${i} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const i=s;for(let n=0;n<i.length;n++)if(!i[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function at({elements:s,...t}){if(!s)throw new Error("No elements");let i=rt(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new ot(i,t);return{open:(e=0)=>n.open(e),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:e=>{n.view(e)}}}exports.DefaultOptions=z;exports.VistaViewTransitionAbortedError=D;exports.defaultClose=F;exports.defaultInit=Y;exports.defaultSetup=B;exports.defaultTransition=_;exports.removeTouchActions=R;exports.setTouchActions=X;exports.vistaView=at;exports.vistaViewDownload=V;
16
+ </div>`)}let P=null,$=null,M=null,Z=null;function X(s){R(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,a=0,d=0,o=null,l=0,h=!1;P=r=>{r.preventDefault(),r.stopPropagation(),s.isZoomed===!1&&(h=!0,n=r.pageX,e=r.pageY,a=r.pageX,d=r.pageY,l=Date.now(),o=null,t.setPointerCapture(r.pointerId))},$=r=>{if(r.preventDefault(),r.stopPropagation(),s.isZoomed!==!1||!h)return;const c=r.pageX-n,m=r.pageY-e;a=r.pageX,d=r.pageY,Math.abs(c)>=Math.abs(m)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${c}px`),o=!0):Math.abs(m)>Math.abs(c)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${m}px`),o=!1)},Z=r=>{if(r.preventDefault(),r.stopPropagation(),t.releasePointerCapture(r.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(m=>{m.style.transition="",m.style.translate=""})},M=r=>{if(r.preventDefault(),r.stopPropagation(),t.releasePointerCapture(r.pointerId),s.isZoomed!==!1||!h)return;h=!1;const c=Array.from(t.querySelectorAll(".vistaview-item")),m=a-n,f=d-e,u=Date.now()-l,v=m/u,y=f/u,p=s.options.touchSpeedThreshold||.5,x=c.find(E=>E.dataset.vistaviewPos==="0"),b=Number(x.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%",L="0%"){c.forEach(S=>{S.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,S.style.translate=`${E} ${L}`})}if(v<-p||v>p){let E=function(){c[0].removeEventListener("transitionend",E),setTimeout(()=>{const L=s.isReducedMotion;s.isReducedMotion=!0,g(),s.view(v<-p?(b+1)%i:(b-1+i)%i,{next:v<-p,prev:v>p}),s.isReducedMotion=L},100)};I(v<-p?"-100%":"100%"),c[0].addEventListener("transitionend",E)}else y<-p||y>p?(s.close(),I("0%","0%")):(c[0].addEventListener("transitionend",g),I("0%"))},t.addEventListener("pointermove",$),t.addEventListener("pointerup",M),t.addEventListener("pointerdown",P),t.addEventListener("pointercancel",Z)}function R(s){const t=s.imageContainerElm;t&&($&&t.removeEventListener("pointermove",$),M&&t.removeEventListener("pointerup",M),P&&t.removeEventListener("pointerdown",P),Z&&t.removeEventListener("pointercancel",Z))}const Y=s=>{X(s)},B=({htmlElements:{to:s},index:{to:t},elements:i})=>{i instanceof NodeList&&t!==null&&(i.forEach(n=>n.style.opacity="1"),i[t].style.opacity="0"),s&&s.forEach(n=>{const e=Number(n.dataset.vistaviewPos);e!==0?(n.style.zIndex="1",n.style.left=100*e+"%"):n.style.zIndex="2"})},_=async({htmlElements:{from:s,to:t},images:{to:i},via:{next:n,prev:e},options:a,isReducedMotion:d},o)=>{if(!i)throw new Error("VistaView: images is null in defaultTransition()");const l=s.filter(h=>h.dataset.vistaviewPos==="0"||(n?h.dataset.vistaviewPos==="1":h.dataset.vistaviewPos==="-1"));d||await new Promise((h,r)=>{let c=0;if(o.aborted){r(new D("Transition aborted"));return}const m=f=>{if(o.aborted){r(new D("Transition aborted"));return}if(f.currentTarget.removeEventListener("transitionend",m),c++,c<l.length)return;const u=t==null?void 0:t.find(g=>g.dataset.vistaviewPos==="0"),v=u?Number(u.dataset.vistaviewIndex):0,y=l.find(g=>Number(g.dataset.vistaviewIndex)===v),p=y==null?void 0:y.querySelector(".vistaview-image-highres");if(!p){r(new Error("current image element not found"));return}if(!p.classList.contains("vistaview-image-loaded")){h(0);return}if(u==null||u.classList.add("vistaview-image-loaded"),p.classList.contains("vistaview-image-settled")){u==null||u.classList.add("vistaview-image-settled"),h(0);return}let x=0;const b=setInterval(()=>{if(o.aborted){clearInterval(b),r(new D("Transition aborted"));return}if(x++,x>a.animationDurationBase/20*1.5){clearInterval(b),h(0);return}p.classList.contains("vistaview-image-settled")&&(u==null||u.classList.add("vistaview-image-settled"),clearInterval(b),h(0))},20)};l.forEach(f=>{f.style.transition=`translate ${a.animationDurationBase*.5}ms ease-out`,f.style.translate=n?"-100%":e?"100%":"0%",f.addEventListener("transitionend",m)})})},F=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),R(s)};class D extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const z={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",V(),"close"],bottomCenter:["description"]}},C={somethingOpened:null};class ot{constructor(t,i){w(this,"options");w(this,"elements");w(this,"isReducedMotion");w(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n;const i=this._value;this._value=t,(n=this._vistaView)==null||n.swap(i,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});w(this,"rootElm",null);w(this,"imageContainerElm",null);w(this,"customControls",{});w(this,"currentImages",null);w(this,"currentItems",null);w(this,"navActive",!0);w(this,"isZoomed",!1);w(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});w(this,"defaultOnClickHandler",t=>t.preventDefault());w(this,"onResizeHandler",null);w(this,"onKeyDown",null);w(this,"userSetup",B);w(this,"userTransition",_);w(this,"userClose",F);w(this,"userInit",Y);w(this,"onZoomedPointerDown",null);w(this,"onZoomedPointerMove",null);w(this,"onZoomedPointerUp",null);w(this,"transitionAbortController",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...z,...i||{},controls:{...z.controls,...(i==null?void 0:i.controls)||{}}},this.options.initFunction&&(this.userInit=this.options.initFunction),this.options.transitionFunction&&(this.userTransition=this.options.transitionFunction),this.options.closeFunction&&(this.userClose=this.options.closeFunction),this.options.initFunction&&(this.userInit=this.options.initFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((n,e)=>{n.dataset.vistaviewIndex=e.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}async swap(t,i){var l,h;if(!C.somethingOpened||t===i||t===null)return;if(this.transitionAbortController&&this.transitionAbortController.abort(),!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:e}=this.getCurrentIndexes(i),a=this.getImages(n),d=a.map((r,c)=>W(r,e[c])),o={htmlElements:{from:this.currentItems,to:d},images:{from:this.currentImages,to:a},index:{from:t,to:i},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(o),this.transitionAbortController=new AbortController;try{await this.userTransition(o,this.transitionAbortController.signal)}catch(r){r instanceof D||console.error(r)}this.imageContainerElm.innerHTML="",d.forEach(r=>{const c=r.dataset.vistaviewPos,m=r.dataset.vistaviewIndex;if(c==="0"){const f=this.currentItems.find(y=>y.dataset.vistaviewIndex===m),u=r.querySelector(".vistaview-image-highres"),v=f==null?void 0:f.querySelector(".vistaview-image-highres");v&&(u.setAttribute("class",v.getAttribute("class")||""),u.setAttribute("style",v.getAttribute("style")||"")),this.imageContainerElm.appendChild(r)}else this.imageContainerElm.appendChild(r)}),this.setInitialDimPos(),this.currentImages=a,this.currentItems=d,this.loadImages(),this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(h=(l=this.options).onImageView)==null||h.call(l,o)}setZoomed(t){var i,n,e,a,d,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,r=0,c=0,m=0,f=0,u=0;this.onZoomedPointerDown=v=>{v.preventDefault(),v.stopPropagation(),l=!0,h=v.pageX,r=v.pageY,t.setPointerCapture(v.pointerId)},this.onZoomedPointerMove=v=>{if(!l)return;v.preventDefault(),f=v.pageX-h,u=v.pageY-r;const y=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),p=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:x,minDiffY:b,maxDiffY:g,minDiffX:I}=k(y,p),E=Math.min(x,Math.max(I,c+f)),L=Math.min(g,Math.max(b,m+u));f=E-c,u=L-m,t==null||t.style.setProperty("--pointer-diff-x",`${E}px`),t==null||t.style.setProperty("--pointer-diff-y",`${L}px`)},this.onZoomedPointerUp=v=>{l=!1,t.releasePointerCapture(v.pointerId),c+=f,m+=u,f=0,u=0},(a=t==null?void 0:t.parentElement)==null||a.addEventListener("pointerdown",this.onZoomedPointerDown),(d=t==null?void 0:t.parentElement)==null||d.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var a,d,o,l,h;const t=(a=this.rootElm)==null?void 0:a.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 r=Math.min(i+this.options.zoomStep,e);t.style.width=`${r}px`;const c=r/i*n;t.style.height=`${c}px`,(o=(d=this.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=r.toString(),t.dataset.vistaviewCurrentHeight=c.toString(),r===e&&((h=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"))==null||h.setAttribute("disabled","true"))}}zoomOut(){var d,o,l,h,r;const t=(d=this.rootElm)==null?void 0:d.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height,e=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,a=c=>{c.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",a))};if(t.addEventListener("transitionend",a),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 m=c/i*n;t.style.height=`${m}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=m.toString();const{maxDiffX:f,minDiffY:u,maxDiffY:v,minDiffX:y}=k(c,m);let p=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),x=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");p=Math.min(f,Math.max(y,p)),x=Math.min(v,Math.max(u,x)),t==null||t.style.setProperty("--pointer-diff-x",`${p}px`),t==null||t.style.setProperty("--pointer-diff-y",`${x}px`),c===e&&((r=(h=this.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"))==null||r.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 a=e.querySelector("img"),d=e.getAttribute("href")||"",o=e.getAttribute("src")||"",l=e.dataset.vistaviewSrc||d||o||(a==null?void 0:a.src)||"",h=e.dataset.vistaviewAlt||e.getAttribute("alt")||(a==null?void 0:a.alt)||"",r=e.dataset.vistaviewThumb||(a==null?void 0:a.src)||d||o||"";return{index:t[n],src:l,alt:h,thumb:r,imageElm:e instanceof HTMLImageElement?e:a,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var h,r;if(!this.rootElm)return;const t=(h=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:h.dataset.vistaviewIndex,i=((r=this.currentImages)==null?void 0:r.find(c=>c.index===Number(t)))||null;if(!i)return;const n=i.imageElm?H(i.imageElm):void 0,e=i.anchorElm?H(i.anchorElm):void 0,a=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,d=(e==null?void 0:e.height)||(n==null?void 0:n.height)||0,o=((e==null?void 0:e.left)||(n==null?void 0:n.left)||0)+a/2,l=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+d/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",d+"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",T(e==null?void 0:e.borderRadius)||T(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 r,c;const a=(r=i.rootElm)==null?void 0:r.querySelector("button.vistaview-zoom-in-btn"),d=(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;a&&(a.style.display=h?"":"none"),d&&(d.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,d=this.currentImages[n].imageElm,o={w:0,h:0};if(d){const{width:h,height:r}=K(d);o.w=Math.min(d.width,h),o.h=Math.min(d.height,r)}const l=()=>{var r;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(()=>{var y,p;let m=0;const f=()=>{var x,b;m++,!(m<3)&&(e.removeEventListener("transitionend",f),(b=(x=e.parentElement)==null?void 0:x.querySelector(".vistaview-image-lowres"))==null||b.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled"))};e.addEventListener("transitionend",f);const{width:u,height:v}=q(e);e.style.width=`${u}px`,e.style.height=`${v}px`,o.w&&o.h&&u===o.w&&v===o.h?((p=(y=e.parentElement)==null?void 0:y.querySelector(".vistaview-image-lowres"))==null||p.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled")):(e.style.width=`${u}px`,e.style.height=`${v}px`)},100),(c=i.parentElement)!=null&&c.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((r=this.rootElm)!=null&&r.classList.contains("vistaview--opened"))h();else{const c=setInterval(()=>{var m;(m=this.rootElm)!=null&&m.classList.contains("vistaview--opened")&&(clearInterval(c),h())},50)}};e.complete&&e.naturalWidth>0?l():e.onload=l})}setIndexDisplay(){this.elements.length!==1&&(this.rootElm.querySelector(".vistaview-index-display").textContent=`${this.currentIndex.value+1} / ${this.elements.length}`)}setCurrentDescription(){this.rootElm.querySelector(".vistaview-description").textContent=(this.currentImages[1]||this.currentImages[0]).alt||""}getCurrentIndexes(t){const i=this.options.preloads,n=this.elements.length,e=n<1||!i?[t]:[...new Set([...Array.from({length:i},(d,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(d,o)=>(t+1+o)%n)])],a=n<1||!i?[0]:e.map((d,o)=>o-Math.floor(e.length/2));return{images:e,positions:a}}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:a,height:d}=q(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=a.toString(),e.dataset.vistaviewInitialHeight=d.toString()):(e.style.width=`${a}px`,e.style.height=`${d}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,l,h,r,c,m,f,u,v,y,p,x,b;if(C.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(C.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(st({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((o=this.rootElm)==null?void 0:o.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw C.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:i,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(i);const e=this.currentImages.map((g,I)=>W(g,n[I]));this.currentItems=e;const a={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(a),this.imageContainerElm.innerHTML="",this.currentItems.forEach(g=>{this.imageContainerElm.appendChild(g)});let d=0;this.rootElm.addEventListener("animationend",g=>{var I;g.currentTarget===this.rootElm&&(d++,d>=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()),(r=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||r.addEventListener("click",()=>this.zoomOut()),(c=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||c.addEventListener("click",()=>this.prev()),(m=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||m.addEventListener("click",()=>this.next()),[...this.options.controls.topLeft||[],...this.options.controls.topRight||[],...this.options.controls.topCenter||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomRight||[]].forEach(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],L=this.currentImages.find(S=>S.index===this.currentIndex.value);E&&L&&(E.onClick.constructor.name==="AsyncFunction"?(g.classList.add("vistaview-button--loading"),E.onClick(L).finally(()=>{g.classList.remove("vistaview-button--loading")})):E.onClick(L))})}),this.options.animationDurationBase&&this.rootElm.style.setProperty("--vistaview-animation-duration",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElm.style.setProperty("--vistaview-initial-z-index",`${this.options.initialZIndex}`),this.setInitialDimPos(),this.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((f=this.rootElm.querySelector(".vistaview-prev-btn"))==null||f.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-next-btn"))==null||u.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),(p=(y=this.options).onOpen)==null||p.call(y,a),(b=(x=this.options).onImageView)==null||b.call(x,a)}async close(t=!0){var n,e,a;if(C.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(d=>{var l;let o;(l=this.rootElm)==null||l.addEventListener("transitionend",h=>{h.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{d()},333))})}));const i={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},container:this.imageContainerElm,elements:this.elements,via:{prev:!1,next:!1},isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userClose(this),(a=(e=this.options).onClose)==null||a.call(e,i),document.body.removeChild(this.rootElm),this.currentIndex._value=null,this.currentIndex._via={next:!1,prev:!1},this.rootElm=null,this.imageContainerElm=null,this.currentImages=null,this.currentItems=null,this.navActive=!0,this.onResizeHandler&&(window.removeEventListener("resize",this.onResizeHandler),this.onResizeHandler=null),this.onKeyDown&&(window.removeEventListener("keydown",this.onKeyDown),this.onKeyDown=null),(this.onZoomedPointerDown||this.onZoomedPointerMove||this.onZoomedPointerUp)&&(this.setZoomed(!1),this.onZoomedPointerDown=null,this.onZoomedPointerMove=null,this.onZoomedPointerUp=null),this.transitionAbortController&&(this.transitionAbortController.abort(),this.transitionAbortController=null),C.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.dataset.vistaviewIndex&&delete t.dataset.vistaviewIndex,t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}view(t,i){C.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=i||{next:!1,prev:!1},this.currentIndex.value=t)}next(){C.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){C.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return C.somethingOpened===this?this.currentIndex.value:-1}}function rt(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let i=0;i<t.length;i++){const n=t[i];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${i} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const i=s;for(let n=0;n<i.length;n++)if(!i[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function at({elements:s,...t}){if(!s)throw new Error("No elements");let i=rt(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new ot(i,t);return{open:(e=0)=>n.open(e),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:e=>{n.view(e)}}}exports.DefaultOptions=z;exports.VistaViewTransitionAbortedError=D;exports.defaultClose=F;exports.defaultInit=Y;exports.defaultSetup=B;exports.defaultTransition=_;exports.removeTouchActions=R;exports.setTouchActions=X;exports.vistaView=at;exports.vistaViewDownload=V;
package/dist/vistaview.js CHANGED
@@ -57,8 +57,8 @@ function B(s) {
57
57
  case "cover":
58
58
  return o < l ? { width: n, height: n / o } : { width: e * o, height: e };
59
59
  case "scale-down": {
60
- const c = { width: a, height: d }, r = o > l ? { width: n, height: n / o } : { width: e * o, height: e };
61
- return r.width <= c.width && r.height <= c.height ? r : c;
60
+ const h = { width: a, height: d }, r = o > l ? { width: n, height: n / o } : { width: e * o, height: e };
61
+ return r.width <= h.width && r.height <= h.height ? r : h;
62
62
  }
63
63
  }
64
64
  return { width: n, height: e };
@@ -80,10 +80,10 @@ function H(s) {
80
80
  };
81
81
  }
82
82
  function T(s, t) {
83
- const i = window.innerHeight, n = window.innerWidth, e = s, a = t, d = Math.max(0, (e - n) / 2) + n / 2, o = Math.max(0, (a - i) / 2) + i / 2, l = -d, c = -o;
83
+ const i = window.innerHeight, n = window.innerWidth, e = s, a = t, d = Math.max(0, (e - n) / 2) + n / 2, o = Math.max(0, (a - i) / 2) + i / 2, l = -d, h = -o;
84
84
  return {
85
85
  maxDiffX: d,
86
- minDiffY: c,
86
+ minDiffY: h,
87
87
  maxDiffY: o,
88
88
  minDiffX: l
89
89
  };
@@ -119,10 +119,10 @@ function J(s) {
119
119
  return `<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`;
120
120
  }
121
121
  function q(s, t) {
122
- var r, h;
123
- const i = s.imageElm ? getComputedStyle(s.imageElm) : null, n = (i == null ? void 0 : i.objectFit) || "", e = ((r = s.imageElm) == null ? void 0 : r.naturalWidth) || "", a = ((h = s.imageElm) == null ? void 0 : h.naturalHeight) || "", d = (i == null ? void 0 : i.width) || "", o = (i == null ? void 0 : i.height) || "", l = document.createElement("div");
122
+ var r, c;
123
+ const i = s.imageElm ? getComputedStyle(s.imageElm) : null, n = (i == null ? void 0 : i.objectFit) || "", e = ((r = s.imageElm) == null ? void 0 : r.naturalWidth) || "", a = ((c = s.imageElm) == null ? void 0 : c.naturalHeight) || "", d = (i == null ? void 0 : i.width) || "", o = (i == null ? void 0 : i.height) || "", l = document.createElement("div");
124
124
  l.className = "vistaview-item", l.dataset.vistaviewPos = `${t !== void 0 ? t : ""}`, l.dataset.vistaviewIndex = s.index.toString();
125
- const c = W(`<img class="vistaview-image-lowres"
125
+ const h = W(`<img class="vistaview-image-lowres"
126
126
  style="${n ? `object-fit:${n};` : ""}${d ? `width:${d};` : ""}${o ? `height:${o};` : ""}"
127
127
  src="${s.thumb || s.src}"
128
128
  alt="${s.alt || ""}"
@@ -130,7 +130,7 @@ function q(s, t) {
130
130
  ${a ? `height="${a}"` : ""}
131
131
  />
132
132
  <img class="vistaview-image-highres" src="${s.src}" alt="${s.alt || ""}" />`);
133
- return l.appendChild(c), l;
133
+ return l.appendChild(h), l;
134
134
  }
135
135
  function Q({
136
136
  controls: s,
@@ -154,42 +154,42 @@ function tt(s) {
154
154
  O(s);
155
155
  const t = s.imageContainerElm, i = s.elements.length;
156
156
  if (!t) return;
157
- let n = 0, e = 0, a = 0, d = 0, o = null, l = 0, c = !1;
157
+ let n = 0, e = 0, a = 0, d = 0, o = null, l = 0, h = !1;
158
158
  A = (r) => {
159
- r.preventDefault(), r.stopPropagation(), s.isZoomed === !1 && (c = !0, n = r.pageX, e = r.pageY, a = r.pageX, d = r.pageY, l = Date.now(), o = null, t.setPointerCapture(r.pointerId));
159
+ r.preventDefault(), r.stopPropagation(), s.isZoomed === !1 && (h = !0, n = r.pageX, e = r.pageY, a = r.pageX, d = r.pageY, l = Date.now(), o = null, t.setPointerCapture(r.pointerId));
160
160
  }, $ = (r) => {
161
- if (r.preventDefault(), r.stopPropagation(), s.isZoomed !== !1 || !c) return;
162
- const h = r.pageX - n, m = r.pageY - e;
163
- a = r.pageX, d = r.pageY, Math.abs(h) >= Math.abs(m) && (o === null || o === !0) ? (t.style.setProperty("--vistaview-pointer-diff-x", `${h}px`), o = !0) : Math.abs(m) > Math.abs(h) && (o === null || o === !1) && (t.style.setProperty("--vistaview-pointer-diff-y", `${m}px`), o = !1);
161
+ if (r.preventDefault(), r.stopPropagation(), s.isZoomed !== !1 || !h) return;
162
+ const c = r.pageX - n, m = r.pageY - e;
163
+ a = r.pageX, d = r.pageY, Math.abs(c) >= Math.abs(m) && (o === null || o === !0) ? (t.style.setProperty("--vistaview-pointer-diff-x", `${c}px`), o = !0) : Math.abs(m) > Math.abs(c) && (o === null || o === !1) && (t.style.setProperty("--vistaview-pointer-diff-y", `${m}px`), o = !1);
164
164
  }, M = (r) => {
165
- if (r.preventDefault(), r.stopPropagation(), t.releasePointerCapture(r.pointerId), s.isZoomed !== !1 || !c) return;
166
- c = !1, o = null;
167
- const h = Array.from(t.querySelectorAll(".vistaview-item"));
168
- t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), h.forEach((m) => {
165
+ if (r.preventDefault(), r.stopPropagation(), t.releasePointerCapture(r.pointerId), s.isZoomed !== !1 || !h) return;
166
+ h = !1, o = null;
167
+ const c = Array.from(t.querySelectorAll(".vistaview-item"));
168
+ t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), c.forEach((m) => {
169
169
  m.style.transition = "", m.style.translate = "";
170
170
  });
171
171
  }, Z = (r) => {
172
- if (r.preventDefault(), r.stopPropagation(), t.releasePointerCapture(r.pointerId), s.isZoomed !== !1 || !c) return;
173
- c = !1;
174
- const h = Array.from(t.querySelectorAll(".vistaview-item")), m = a - n, f = d - e, u = Date.now() - l, v = m / u, y = f / u, p = s.options.touchSpeedThreshold || 0.5, b = h.find(
172
+ if (r.preventDefault(), r.stopPropagation(), t.releasePointerCapture(r.pointerId), s.isZoomed !== !1 || !h) return;
173
+ h = !1;
174
+ const c = Array.from(t.querySelectorAll(".vistaview-item")), m = a - n, f = d - e, u = Date.now() - l, v = m / u, y = f / u, p = s.options.touchSpeedThreshold || 0.5, x = c.find(
175
175
  (E) => E.dataset.vistaviewPos === "0"
176
- ), x = Number(b.dataset.vistaviewIndex);
176
+ ), b = Number(x.dataset.vistaviewIndex);
177
177
  function g() {
178
- h[0].removeEventListener("transitionend", g), t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), h.forEach((E) => {
178
+ c[0].removeEventListener("transitionend", g), t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), c.forEach((E) => {
179
179
  E.style.transition = "", E.style.translate = "";
180
180
  });
181
181
  }
182
182
  function I(E = "0%", L = "0%") {
183
- h.forEach((D) => {
183
+ c.forEach((D) => {
184
184
  D.style.transition = `translate ${s.options.animationDurationBase * 0.5}ms ease-out`, D.style.translate = `${E} ${L}`;
185
185
  });
186
186
  }
187
187
  if (v < -p || v > p) {
188
188
  let E = function() {
189
- h[0].removeEventListener("transitionend", E), setTimeout(() => {
189
+ c[0].removeEventListener("transitionend", E), setTimeout(() => {
190
190
  const L = s.isReducedMotion;
191
191
  s.isReducedMotion = !0, g(), s.view(
192
- v < -p ? (x + 1) % i : (x - 1 + i) % i,
192
+ v < -p ? (b + 1) % i : (b - 1 + i) % i,
193
193
  {
194
194
  next: v < -p,
195
195
  prev: v > p
@@ -197,8 +197,8 @@ function tt(s) {
197
197
  ), s.isReducedMotion = L;
198
198
  }, 100);
199
199
  };
200
- I(v < -p ? "-100%" : "100%"), h[0].addEventListener("transitionend", E);
201
- } else y < -p || y > p ? (s.close(), I("0%", "0%")) : (h[0].addEventListener("transitionend", g), I("0%"));
200
+ I(v < -p ? "-100%" : "100%"), c[0].addEventListener("transitionend", E);
201
+ } else y < -p || y > p ? (s.close(), I("0%", "0%")) : (c[0].addEventListener("transitionend", g), I("0%"));
202
202
  }, t.addEventListener("pointermove", $), t.addEventListener("pointerup", Z), t.addEventListener("pointerdown", A), t.addEventListener("pointercancel", M);
203
203
  }
204
204
  function O(s) {
@@ -224,24 +224,20 @@ const et = (s) => {
224
224
  isReducedMotion: d
225
225
  // index: { from: fromIndex, to: toIndex },
226
226
  }, o) => {
227
- if (console.log("defaultTransition called"), !i) throw new Error("VistaView: images is null in defaultTransition()");
228
- const l = s.filter((c) => c.dataset.vistaviewPos === "0" || (n ? c.dataset.vistaviewPos === "1" : c.dataset.vistaviewPos === "-1"));
229
- if (d) {
230
- console.log("reduced motion, no transition");
231
- return;
232
- }
233
- await new Promise((c, r) => {
234
- let h = 0;
227
+ if (!i) throw new Error("VistaView: images is null in defaultTransition()");
228
+ const l = s.filter((h) => h.dataset.vistaviewPos === "0" || (n ? h.dataset.vistaviewPos === "1" : h.dataset.vistaviewPos === "-1"));
229
+ d || await new Promise((h, r) => {
230
+ let c = 0;
235
231
  if (o.aborted) {
236
- console.log("transition aborted before start"), r(new P("Transition aborted"));
232
+ r(new P("Transition aborted"));
237
233
  return;
238
234
  }
239
235
  const m = (f) => {
240
236
  if (o.aborted) {
241
- console.log("transition aborted before start"), r(new P("Transition aborted"));
237
+ r(new P("Transition aborted"));
242
238
  return;
243
239
  }
244
- if (f.currentTarget.removeEventListener("transitionend", m), h++, h < l.length) return;
240
+ if (f.currentTarget.removeEventListener("transitionend", m), c++, c < l.length) return;
245
241
  const u = t == null ? void 0 : t.find((g) => g.dataset.vistaviewPos === "0"), v = u ? Number(u.dataset.vistaviewIndex) : 0, y = l.find((g) => Number(g.dataset.vistaviewIndex) === v), p = y == null ? void 0 : y.querySelector(
246
242
  ".vistaview-image-highres"
247
243
  );
@@ -250,25 +246,24 @@ const et = (s) => {
250
246
  return;
251
247
  }
252
248
  if (!p.classList.contains("vistaview-image-loaded")) {
253
- console.log("current image not loaded yet"), c(0);
249
+ h(0);
254
250
  return;
255
251
  }
256
252
  if (u == null || u.classList.add("vistaview-image-loaded"), p.classList.contains("vistaview-image-settled")) {
257
- console.log("current image already settled"), u == null || u.classList.add("vistaview-image-settled"), c(0);
253
+ u == null || u.classList.add("vistaview-image-settled"), h(0);
258
254
  return;
259
255
  }
260
- let b = 0;
261
- console.log("waiting for image to be settled...");
262
- const x = setInterval(() => {
256
+ let x = 0;
257
+ const b = setInterval(() => {
263
258
  if (o.aborted) {
264
- console.log("transition aborted during wait"), clearInterval(x), r(new P("Transition aborted"));
259
+ clearInterval(b), r(new P("Transition aborted"));
265
260
  return;
266
261
  }
267
- if (b++, b > a.animationDurationBase / 20 * 1.5) {
268
- console.log("timeout waiting for image to be settled"), clearInterval(x), c(0);
262
+ if (x++, x > a.animationDurationBase / 20 * 1.5) {
263
+ clearInterval(b), h(0);
269
264
  return;
270
265
  }
271
- p.classList.contains("vistaview-image-settled") && (console.log("image settled"), u == null || u.classList.add("vistaview-image-settled"), clearInterval(x), c(0));
266
+ p.classList.contains("vistaview-image-settled") && (u == null || u.classList.add("vistaview-image-settled"), clearInterval(b), h(0));
272
267
  }, 20);
273
268
  };
274
269
  l.forEach((f) => {
@@ -361,14 +356,12 @@ class ot {
361
356
  });
362
357
  }
363
358
  async swap(t, i) {
364
- var l, c;
359
+ var l, h;
365
360
  if (!C.somethingOpened || t === i || t === null) return;
366
- if (console.log("Swapping from", t, "to", i), this.transitionAbortController && this.transitionAbortController.abort(), !this.imageContainerElm)
361
+ if (this.transitionAbortController && this.transitionAbortController.abort(), !this.imageContainerElm)
367
362
  throw new Error("VistaView: imageContainerElm is null in swap()");
368
363
  this.setIndexDisplay(), this.clearZoom();
369
- const { images: n, positions: e } = this.getCurrentIndexes(i), a = this.getImages(n), d = a.map((r, h) => q(r, e[h]));
370
- console.log("swap prepared");
371
- const o = {
364
+ const { images: n, positions: e } = this.getCurrentIndexes(i), a = this.getImages(n), d = a.map((r, c) => q(r, e[c])), o = {
372
365
  htmlElements: { from: this.currentItems, to: d },
373
366
  images: { from: this.currentImages, to: a },
374
367
  index: { from: t, to: i },
@@ -386,14 +379,14 @@ class ot {
386
379
  } catch (r) {
387
380
  r instanceof P || console.error(r);
388
381
  }
389
- console.log("swap completed"), this.imageContainerElm.innerHTML = "", d.forEach((r) => {
390
- const h = r.dataset.vistaviewPos, m = r.dataset.vistaviewIndex;
391
- if (h === "0") {
382
+ this.imageContainerElm.innerHTML = "", d.forEach((r) => {
383
+ const c = r.dataset.vistaviewPos, m = r.dataset.vistaviewIndex;
384
+ if (c === "0") {
392
385
  const f = this.currentItems.find((y) => y.dataset.vistaviewIndex === m), u = r.querySelector(".vistaview-image-highres"), v = f == null ? void 0 : f.querySelector(".vistaview-image-highres");
393
386
  v && (u.setAttribute("class", v.getAttribute("class") || ""), u.setAttribute("style", v.getAttribute("style") || "")), this.imageContainerElm.appendChild(r);
394
387
  } else
395
388
  this.imageContainerElm.appendChild(r);
396
- }), this.setInitialDimPos(), this.currentImages = a, this.currentItems = d, this.loadImages(), this.setCurrentDescription(), this.updateZoomButtonsVisibility(), (c = (l = this.options).onImageView) == null || c.call(l, o);
389
+ }), this.setInitialDimPos(), this.currentImages = a, this.currentItems = d, this.loadImages(), this.setCurrentDescription(), this.updateZoomButtonsVisibility(), (h = (l = this.options).onImageView) == null || h.call(l, o);
397
390
  }
398
391
  //
399
392
  setZoomed(t) {
@@ -407,26 +400,26 @@ class ot {
407
400
  }
408
401
  if (t) {
409
402
  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");
410
- let l = !1, c = 0, r = 0, h = 0, m = 0, f = 0, u = 0;
403
+ let l = !1, h = 0, r = 0, c = 0, m = 0, f = 0, u = 0;
411
404
  this.onZoomedPointerDown = (v) => {
412
- v.preventDefault(), v.stopPropagation(), l = !0, c = v.pageX, r = v.pageY, t.setPointerCapture(v.pointerId);
405
+ v.preventDefault(), v.stopPropagation(), l = !0, h = v.pageX, r = v.pageY, t.setPointerCapture(v.pointerId);
413
406
  }, this.onZoomedPointerMove = (v) => {
414
407
  if (!l) return;
415
- v.preventDefault(), f = v.pageX - c, u = v.pageY - r;
416
- const y = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentWidth) || "0"), p = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentHeight) || "0"), { maxDiffX: b, minDiffY: x, maxDiffY: g, minDiffX: I } = T(
408
+ v.preventDefault(), f = v.pageX - h, u = v.pageY - r;
409
+ const y = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentWidth) || "0"), p = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentHeight) || "0"), { maxDiffX: x, minDiffY: b, maxDiffY: g, minDiffX: I } = T(
417
410
  y,
418
411
  p
419
- ), E = Math.min(b, Math.max(I, h + f)), L = Math.min(g, Math.max(x, m + u));
420
- f = E - h, u = L - m, t == null || t.style.setProperty("--pointer-diff-x", `${E}px`), t == null || t.style.setProperty("--pointer-diff-y", `${L}px`);
412
+ ), E = Math.min(x, Math.max(I, c + f)), L = Math.min(g, Math.max(b, m + u));
413
+ f = E - c, u = L - m, t == null || t.style.setProperty("--pointer-diff-x", `${E}px`), t == null || t.style.setProperty("--pointer-diff-y", `${L}px`);
421
414
  }, this.onZoomedPointerUp = (v) => {
422
- l = !1, t.releasePointerCapture(v.pointerId), h += f, m += u, f = 0, u = 0;
415
+ l = !1, t.releasePointerCapture(v.pointerId), c += f, m += u, f = 0, u = 0;
423
416
  }, (a = t == null ? void 0 : t.parentElement) == null || a.addEventListener("pointerdown", this.onZoomedPointerDown), (d = t == null ? void 0 : t.parentElement) == null || d.addEventListener("pointermove", this.onZoomedPointerMove), (o = t == null ? void 0 : t.parentElement) == null || o.addEventListener("pointerup", this.onZoomedPointerUp);
424
417
  return;
425
418
  }
426
419
  }
427
420
  }
428
421
  zoomIn() {
429
- var a, d, o, l, c;
422
+ var a, d, o, l, h;
430
423
  const t = (a = this.rootElm) == null ? void 0 : a.querySelector(
431
424
  '[data-vistaview-pos="0"] .vistaview-image-highres'
432
425
  ), i = t.width, n = t.height;
@@ -435,29 +428,29 @@ class ot {
435
428
  if (i && e && i < e) {
436
429
  const r = Math.min(i + this.options.zoomStep, e);
437
430
  t.style.width = `${r}px`;
438
- const h = r / i * n;
439
- t.style.height = `${h}px`, (o = (d = this.rootElm) == null ? void 0 : d.querySelector("button.vistaview-zoom-out-btn")) == null || o.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = r.toString(), t.dataset.vistaviewCurrentHeight = h.toString(), r === e && ((c = (l = this.rootElm) == null ? void 0 : l.querySelector("button.vistaview-zoom-in-btn")) == null || c.setAttribute("disabled", "true"));
431
+ const c = r / i * n;
432
+ t.style.height = `${c}px`, (o = (d = this.rootElm) == null ? void 0 : d.querySelector("button.vistaview-zoom-out-btn")) == null || o.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = r.toString(), t.dataset.vistaviewCurrentHeight = c.toString(), r === e && ((h = (l = this.rootElm) == null ? void 0 : l.querySelector("button.vistaview-zoom-in-btn")) == null || h.setAttribute("disabled", "true"));
440
433
  }
441
434
  }
442
435
  zoomOut() {
443
- var d, o, l, c, r;
436
+ var d, o, l, h, r;
444
437
  const t = (d = this.rootElm) == null ? void 0 : d.querySelector(
445
438
  '[data-vistaview-pos="0"] .vistaview-image-highres'
446
- ), i = t.width, n = t.height, e = t.dataset.vistaviewInitialWidth ? parseInt(t.dataset.vistaviewInitialWidth) : 0, a = (h) => {
447
- h.target === t && (t.classList.remove("vistaview-image--zooming-out"), t.removeEventListener("transitionend", a));
439
+ ), i = t.width, n = t.height, e = t.dataset.vistaviewInitialWidth ? parseInt(t.dataset.vistaviewInitialWidth) : 0, a = (c) => {
440
+ c.target === t && (t.classList.remove("vistaview-image--zooming-out"), t.removeEventListener("transitionend", a));
448
441
  };
449
442
  if (t.addEventListener("transitionend", a), t.classList.add("vistaview-image--zooming-out"), i && e && i > e) {
450
- const h = Math.max(i - this.options.zoomStep, e);
451
- t.style.width = `${h}px`;
452
- const m = h / i * n;
453
- t.style.height = `${m}px`, (l = (o = this.rootElm) == null ? void 0 : o.querySelector("button.vistaview-zoom-in-btn")) == null || l.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = h.toString(), t.dataset.vistaviewCurrentHeight = m.toString();
454
- const { maxDiffX: f, minDiffY: u, maxDiffY: v, minDiffX: y } = T(h, m);
443
+ const c = Math.max(i - this.options.zoomStep, e);
444
+ t.style.width = `${c}px`;
445
+ const m = c / i * n;
446
+ t.style.height = `${m}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 = m.toString();
447
+ const { maxDiffX: f, minDiffY: u, maxDiffY: v, minDiffX: y } = T(c, m);
455
448
  let p = parseInt(
456
449
  (t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-x").replace("px", "")) || "0"
457
- ), b = parseInt(
450
+ ), x = parseInt(
458
451
  (t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-y").replace("px", "")) || "0"
459
452
  );
460
- p = Math.min(f, Math.max(y, p)), b = Math.min(v, Math.max(u, b)), t == null || t.style.setProperty("--pointer-diff-x", `${p}px`), t == null || t.style.setProperty("--pointer-diff-y", `${b}px`), h === e && ((r = (c = this.rootElm) == null ? void 0 : c.querySelector("button.vistaview-zoom-out-btn")) == null || r.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));
453
+ p = Math.min(f, Math.max(y, p)), x = Math.min(v, Math.max(u, x)), t == null || t.style.setProperty("--pointer-diff-x", `${p}px`), t == null || t.style.setProperty("--pointer-diff-y", `${x}px`), c === e && ((r = (h = this.rootElm) == null ? void 0 : h.querySelector("button.vistaview-zoom-out-btn")) == null || r.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));
461
454
  }
462
455
  }
463
456
  clearZoom() {
@@ -466,11 +459,11 @@ class ot {
466
459
  return t.map((i, n) => {
467
460
  const e = this.elements[i];
468
461
  if (e instanceof HTMLElement) {
469
- const a = e.querySelector("img"), d = e.getAttribute("href") || "", o = e.getAttribute("src") || "", l = e.dataset.vistaviewSrc || d || o || (a == null ? void 0 : a.src) || "", c = e.dataset.vistaviewAlt || e.getAttribute("alt") || (a == null ? void 0 : a.alt) || "", r = e.dataset.vistaviewThumb || (a == null ? void 0 : a.src) || d || o || "";
462
+ const a = e.querySelector("img"), d = e.getAttribute("href") || "", o = e.getAttribute("src") || "", l = e.dataset.vistaviewSrc || d || o || (a == null ? void 0 : a.src) || "", h = e.dataset.vistaviewAlt || e.getAttribute("alt") || (a == null ? void 0 : a.alt) || "", r = e.dataset.vistaviewThumb || (a == null ? void 0 : a.src) || d || o || "";
470
463
  return {
471
464
  index: t[n],
472
465
  src: l,
473
- alt: c,
466
+ alt: h,
474
467
  thumb: r,
475
468
  imageElm: e instanceof HTMLImageElement ? e : a,
476
469
  anchorElm: e instanceof HTMLAnchorElement ? e : void 0
@@ -480,9 +473,9 @@ class ot {
480
473
  });
481
474
  }
482
475
  setInitialDimPos() {
483
- var c, r;
476
+ var h, r;
484
477
  if (!this.rootElm) return;
485
- const t = (c = this.rootElm.querySelector('[data-vistaview-pos="0"]')) == null ? void 0 : c.dataset.vistaviewIndex, i = ((r = this.currentImages) == null ? void 0 : r.find((h) => h.index === Number(t))) || null;
478
+ const t = (h = this.rootElm.querySelector('[data-vistaview-pos="0"]')) == null ? void 0 : h.dataset.vistaviewIndex, i = ((r = this.currentImages) == null ? void 0 : r.find((c) => c.index === Number(t))) || null;
486
479
  if (!i) return;
487
480
  const n = i.imageElm ? z(i.imageElm) : void 0, e = i.anchorElm ? z(i.anchorElm) : void 0, a = (e == null ? void 0 : e.width) || (n == null ? void 0 : n.width) || 0, d = (e == null ? void 0 : e.height) || (n == null ? void 0 : n.height) || 0, o = ((e == null ? void 0 : e.left) || (n == null ? void 0 : n.left) || 0) + a / 2, l = ((e == null ? void 0 : e.top) || (n == null ? void 0 : n.top) || 0) + d / 2;
488
481
  this.rootElm.style.setProperty("--vistaview-container-initial-width", a + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-height", d + "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(
@@ -498,13 +491,13 @@ class ot {
498
491
  if (!t) return;
499
492
  const i = this;
500
493
  function n() {
501
- var r, h;
494
+ var r, c;
502
495
  const a = (r = i.rootElm) == null ? void 0 : r.querySelector(
503
496
  "button.vistaview-zoom-in-btn"
504
- ), d = (h = i.rootElm) == null ? void 0 : h.querySelector(
497
+ ), d = (c = i.rootElm) == null ? void 0 : c.querySelector(
505
498
  "button.vistaview-zoom-out-btn"
506
- ), o = parseInt(t.style.width) || t.width, l = t.naturalWidth * i.options.maxZoomLevel, c = o < l && l > 0;
507
- a && (a.style.display = c ? "" : "none"), d && (d.style.display = c ? "" : "none");
499
+ ), o = parseInt(t.style.width) || t.width, l = t.naturalWidth * i.options.maxZoomLevel, h = o < l && l > 0;
500
+ a && (a.style.display = h ? "" : "none"), d && (d.style.display = h ? "" : "none");
508
501
  }
509
502
  t.complete && t.naturalWidth > 0 ? n() : t.addEventListener("load", n);
510
503
  }
@@ -515,31 +508,31 @@ class ot {
515
508
  ).forEach((i, n) => {
516
509
  const e = i, d = this.currentImages[n].imageElm, o = { w: 0, h: 0 };
517
510
  if (d) {
518
- const { width: c, height: r } = B(d);
519
- o.w = Math.min(d.width, c), o.h = Math.min(d.height, r);
511
+ const { width: h, height: r } = B(d);
512
+ o.w = Math.min(d.width, h), o.h = Math.min(d.height, r);
520
513
  }
521
514
  const l = () => {
522
515
  var r;
523
- const c = () => {
524
- var h;
516
+ const h = () => {
517
+ var c;
525
518
  o.w && o.h && (e.style.width = `${o.w}px`, e.style.height = `${o.h}px`, e.style.setProperty("--vistaview-fitted-width", `${o.w}px`), e.style.setProperty("--vistaview-fitted-height", `${o.h}px`)), e.classList.add("vistaview-image-loaded"), e.width = e.naturalWidth, e.height = e.naturalHeight, setTimeout(() => {
526
519
  var y, p;
527
520
  let m = 0;
528
521
  const f = () => {
529
- var b, x;
530
- m++, !(m < 3) && (e.removeEventListener("transitionend", f), (x = (b = e.parentElement) == null ? void 0 : b.querySelector(".vistaview-image-lowres")) == null || x.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled"));
522
+ var x, b;
523
+ m++, !(m < 3) && (e.removeEventListener("transitionend", f), (b = (x = e.parentElement) == null ? void 0 : x.querySelector(".vistaview-image-lowres")) == null || b.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled"));
531
524
  };
532
525
  e.addEventListener("transitionend", f);
533
526
  const { width: u, height: v } = H(e);
534
527
  e.style.width = `${u}px`, e.style.height = `${v}px`, o.w && o.h && u === o.w && v === o.h ? ((p = (y = e.parentElement) == null ? void 0 : y.querySelector(".vistaview-image-lowres")) == null || p.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled")) : (e.style.width = `${u}px`, e.style.height = `${v}px`);
535
- }, 100), (h = i.parentElement) != null && h.matches('[data-vistaview-pos="0"]') && this.updateZoomButtonsVisibility();
528
+ }, 100), (c = i.parentElement) != null && c.matches('[data-vistaview-pos="0"]') && this.updateZoomButtonsVisibility();
536
529
  };
537
530
  if ((r = this.rootElm) != null && r.classList.contains("vistaview--opened"))
538
- c();
531
+ h();
539
532
  else {
540
- const h = setInterval(() => {
533
+ const c = setInterval(() => {
541
534
  var m;
542
- (m = this.rootElm) != null && m.classList.contains("vistaview--opened") && (clearInterval(h), c());
535
+ (m = this.rootElm) != null && m.classList.contains("vistaview--opened") && (clearInterval(c), h());
543
536
  }, 50);
544
537
  }
545
538
  };
@@ -603,7 +596,7 @@ class ot {
603
596
  }, window.addEventListener("resize", this.onResizeHandler);
604
597
  }
605
598
  open(t = 0) {
606
- var o, l, c, r, h, m, f, u, v, y, p, b, x;
599
+ var o, l, h, r, c, m, f, u, v, y, p, x, b;
607
600
  if (C.somethingOpened) {
608
601
  console.error("VistaView: another instance is already opened. Returning.");
609
602
  return;
@@ -639,7 +632,7 @@ class ot {
639
632
  this.rootElm.addEventListener("animationend", (g) => {
640
633
  var I;
641
634
  g.currentTarget === this.rootElm && (d++, d >= 2 && ((I = this.rootElm) == null || I.classList.add("vistaview--opened")));
642
- }), (l = this.rootElm.querySelector(".vistaview-close-btn")) == null || l.addEventListener("click", () => this.close()), (c = this.rootElm.querySelector(".vistaview-zoom-in-btn")) == null || c.addEventListener("click", () => this.zoomIn()), (r = this.rootElm.querySelector(".vistaview-zoom-out-btn")) == null || r.addEventListener("click", () => this.zoomOut()), (h = this.rootElm.querySelector(".vistaview-prev-btn>button")) == null || h.addEventListener("click", () => this.prev()), (m = this.rootElm.querySelector(".vistaview-next-btn>button")) == null || m.addEventListener("click", () => this.next()), [
635
+ }), (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()), (r = this.rootElm.querySelector(".vistaview-zoom-out-btn")) == null || r.addEventListener("click", () => this.zoomOut()), (c = this.rootElm.querySelector(".vistaview-prev-btn>button")) == null || c.addEventListener("click", () => this.prev()), (m = this.rootElm.querySelector(".vistaview-next-btn>button")) == null || m.addEventListener("click", () => this.next()), [
643
636
  ...this.options.controls.topLeft || [],
644
637
  ...this.options.controls.topRight || [],
645
638
  ...this.options.controls.topCenter || [],
@@ -663,7 +656,7 @@ class ot {
663
656
  ), this.options.initialZIndex !== void 0 && this.rootElm.style.setProperty(
664
657
  "--vistaview-initial-z-index",
665
658
  `${this.options.initialZIndex}`
666
- ), this.setInitialDimPos(), this.setResizeListeners(), this.options.keyboardListeners && this.setKeyboardListeners(), this.elements.length === 1 && ((f = this.rootElm.querySelector(".vistaview-prev-btn")) == null || f.classList.add("vistaview-ui--none"), (u = this.rootElm.querySelector(".vistaview-next-btn")) == null || u.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), (p = (y = this.options).onOpen) == null || p.call(y, a), (x = (b = this.options).onImageView) == null || x.call(b, a);
659
+ ), this.setInitialDimPos(), this.setResizeListeners(), this.options.keyboardListeners && this.setKeyboardListeners(), this.elements.length === 1 && ((f = this.rootElm.querySelector(".vistaview-prev-btn")) == null || f.classList.add("vistaview-ui--none"), (u = this.rootElm.querySelector(".vistaview-next-btn")) == null || u.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), (p = (y = this.options).onOpen) == null || p.call(y, a), (b = (x = this.options).onImageView) == null || b.call(x, a);
667
660
  }
668
661
  async close(t = !0) {
669
662
  var n, e, a;
@@ -671,8 +664,8 @@ class ot {
671
664
  t && ((n = this.rootElm) == null || n.classList.add("vistaview--closing"), await new Promise((d) => {
672
665
  var l;
673
666
  let o;
674
- (l = this.rootElm) == null || l.addEventListener("transitionend", (c) => {
675
- c.currentTarget === this.rootElm && (o && clearTimeout(o), o = setTimeout(() => {
667
+ (l = this.rootElm) == null || l.addEventListener("transitionend", (h) => {
668
+ h.currentTarget === this.rootElm && (o && clearTimeout(o), o = setTimeout(() => {
676
669
  d();
677
670
  }, 333));
678
671
  });
@@ -1,11 +1,11 @@
1
- (function(y,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(y=typeof globalThis<"u"?globalThis:y||self,I(y.VistaView={}))})(this,(function(y){"use strict";var at=Object.defineProperty;var lt=(y,I,A)=>I in y?at(y,I,{enumerable:!0,configurable:!0,writable:!0,value:A}):y[I]=A;var w=(y,I,A)=>lt(y,typeof I!="symbol"?I+"":I,A);function I(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 U(){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 q(s){const i=U().createHTML(s),n=document.createElement("template");n.innerHTML=i;const e=n.content;return n.remove(),e}function k(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function j(s){const i=window.getComputedStyle(s).objectFit||"",{width:n,height:e}=s.getBoundingClientRect(),a=s.naturalWidth,d=s.naturalHeight;if(!i)return{width:n,height:e};if(!a||!d)return{width:n,height:e};const o=a/d,l=n/e;switch(i){case"fill":return{width:n,height:e};case"none":return{width:a,height:d};case"contain":return o>l?{width:n,height:n/o}:{width:e*o,height:e};case"cover":return o<l?{width:n,height:n/o}:{width:e*o,height:e};case"scale-down":{const c={width:a,height:d},r=o>l?{width:n,height:n/o}:{width:e*o,height:e};return r.width<=c.width&&r.height<=c.height?r:c}}return{width:n,height:e}}function W(s){const t=window.innerWidth,i=window.innerHeight,n=s.naturalWidth,e=s.naturalHeight;if(!n||!e)throw console.error("Error",s),new Error("Image natural dimensions are zero");if(n<t&&e<i)return{width:n,height:e};const a=n/e,d=t/i;let o,l;return a>d?(o=t,l=t/a):(l=i,o=i*a),{width:o,height:l}}function O(s,t){const i=window.innerHeight,n=window.innerWidth,e=s,a=t,d=Math.max(0,(e-n)/2)+n/2,o=Math.max(0,(a-i)/2)+i/2,l=-d,c=-o;return{maxDiffX:d,minDiffY:c,maxDiffY:o,minDiffX:l}}const K='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',G='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',J='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',Q='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',tt='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',et='<svg viewBox="0 0 24 24"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';function V(){return{name:"download",icon:et,onClick:async s=>{var a;const t=await fetch(s.src),i=await t.blob(),n=t.url,e=document.createElement("a");e.href=URL.createObjectURL(i),e.download=((a=n.split("/").pop())==null?void 0:a.split("?")[0].split("#")[0])||"download",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}}function it(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${J}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${Q}</button>`;case"close":return`<button class="vistaview-close-btn">${tt}</button>`;case"indexDisplay":return'<div class="vistaview-index-display"></div>';case"description":return'<div class="vistaview-description"></div>';default:return""}return`<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`}function X(s,t){var r,h;const i=s.imageElm?getComputedStyle(s.imageElm):null,n=(i==null?void 0:i.objectFit)||"",e=((r=s.imageElm)==null?void 0:r.naturalWidth)||"",a=((h=s.imageElm)==null?void 0:h.naturalHeight)||"",d=(i==null?void 0:i.width)||"",o=(i==null?void 0:i.height)||"",l=document.createElement("div");l.className="vistaview-item",l.dataset.vistaviewPos=`${t!==void 0?t:""}`,l.dataset.vistaviewIndex=s.index.toString();const c=q(`<img class="vistaview-image-lowres"
1
+ (function(y,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(y=typeof globalThis<"u"?globalThis:y||self,I(y.VistaView={}))})(this,(function(y){"use strict";var at=Object.defineProperty;var lt=(y,I,A)=>I in y?at(y,I,{enumerable:!0,configurable:!0,writable:!0,value:A}):y[I]=A;var w=(y,I,A)=>lt(y,typeof I!="symbol"?I+"":I,A);function I(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 U(){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 q(s){const i=U().createHTML(s),n=document.createElement("template");n.innerHTML=i;const e=n.content;return n.remove(),e}function k(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function j(s){const i=window.getComputedStyle(s).objectFit||"",{width:n,height:e}=s.getBoundingClientRect(),a=s.naturalWidth,d=s.naturalHeight;if(!i)return{width:n,height:e};if(!a||!d)return{width:n,height:e};const o=a/d,l=n/e;switch(i){case"fill":return{width:n,height:e};case"none":return{width:a,height:d};case"contain":return o>l?{width:n,height:n/o}:{width:e*o,height:e};case"cover":return o<l?{width:n,height:n/o}:{width:e*o,height:e};case"scale-down":{const h={width:a,height:d},r=o>l?{width:n,height:n/o}:{width:e*o,height:e};return r.width<=h.width&&r.height<=h.height?r:h}}return{width:n,height:e}}function W(s){const t=window.innerWidth,i=window.innerHeight,n=s.naturalWidth,e=s.naturalHeight;if(!n||!e)throw console.error("Error",s),new Error("Image natural dimensions are zero");if(n<t&&e<i)return{width:n,height:e};const a=n/e,d=t/i;let o,l;return a>d?(o=t,l=t/a):(l=i,o=i*a),{width:o,height:l}}function O(s,t){const i=window.innerHeight,n=window.innerWidth,e=s,a=t,d=Math.max(0,(e-n)/2)+n/2,o=Math.max(0,(a-i)/2)+i/2,l=-d,h=-o;return{maxDiffX:d,minDiffY:h,maxDiffY:o,minDiffX:l}}const K='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',G='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',J='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',Q='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',tt='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',et='<svg viewBox="0 0 24 24"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';function V(){return{name:"download",icon:et,onClick:async s=>{var a;const t=await fetch(s.src),i=await t.blob(),n=t.url,e=document.createElement("a");e.href=URL.createObjectURL(i),e.download=((a=n.split("/").pop())==null?void 0:a.split("?")[0].split("#")[0])||"download",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}}function it(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button class="vistaview-zoom-in-btn">${J}</button>`;case"zoomOut":return`<button disabled class="vistaview-zoom-out-btn">${Q}</button>`;case"close":return`<button class="vistaview-close-btn">${tt}</button>`;case"indexDisplay":return'<div class="vistaview-index-display"></div>';case"description":return'<div class="vistaview-description"></div>';default:return""}return`<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`}function X(s,t){var r,c;const i=s.imageElm?getComputedStyle(s.imageElm):null,n=(i==null?void 0:i.objectFit)||"",e=((r=s.imageElm)==null?void 0:r.naturalWidth)||"",a=((c=s.imageElm)==null?void 0:c.naturalHeight)||"",d=(i==null?void 0:i.width)||"",o=(i==null?void 0:i.height)||"",l=document.createElement("div");l.className="vistaview-item",l.dataset.vistaviewPos=`${t!==void 0?t:""}`,l.dataset.vistaviewIndex=s.index.toString();const h=q(`<img class="vistaview-image-lowres"
2
2
  style="${n?`object-fit:${n};`:""}${d?`width:${d};`:""}${o?`height:${o};`:""}"
3
3
  src="${s.thumb||s.src}"
4
4
  alt="${s.alt||""}"
5
5
  ${e?`width="${e}"`:""}
6
6
  ${a?`height="${a}"`:""}
7
7
  />
8
- <img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return l.appendChild(c),l}function nt({controls:s,isReducedMotion:t}){const i=e=>e?e.map(it).join(""):"";return q(`<div class="vistaview-root${t?" vistaview--reduced-motion":""}" id="vistaview-root">
8
+ <img class="vistaview-image-highres" src="${s.src}" alt="${s.alt||""}" />`);return l.appendChild(h),l}function nt({controls:s,isReducedMotion:t}){const i=e=>e?e.map(it).join(""):"";return q(`<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>
@@ -13,4 +13,4 @@
13
13
  <div class="vistaview-prev-btn vistaview-ui"><button>${K}</button></div>
14
14
  <div class="vistaview-next-btn vistaview-ui"><button>${G}</button></div>
15
15
  </div>
16
- </div>`)}let $=null,M=null,Z=null,z=null;function Y(s){R(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,a=0,d=0,o=null,l=0,c=!1;$=r=>{r.preventDefault(),r.stopPropagation(),s.isZoomed===!1&&(c=!0,n=r.pageX,e=r.pageY,a=r.pageX,d=r.pageY,l=Date.now(),o=null,t.setPointerCapture(r.pointerId))},M=r=>{if(r.preventDefault(),r.stopPropagation(),s.isZoomed!==!1||!c)return;const h=r.pageX-n,m=r.pageY-e;a=r.pageX,d=r.pageY,Math.abs(h)>=Math.abs(m)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${h}px`),o=!0):Math.abs(m)>Math.abs(h)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${m}px`),o=!1)},z=r=>{if(r.preventDefault(),r.stopPropagation(),t.releasePointerCapture(r.pointerId),s.isZoomed!==!1||!c)return;c=!1,o=null;const h=Array.from(t.querySelectorAll(".vistaview-item"));t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(m=>{m.style.transition="",m.style.translate=""})},Z=r=>{if(r.preventDefault(),r.stopPropagation(),t.releasePointerCapture(r.pointerId),s.isZoomed!==!1||!c)return;c=!1;const h=Array.from(t.querySelectorAll(".vistaview-item")),m=a-n,f=d-e,u=Date.now()-l,v=m/u,E=f/u,p=s.options.touchSpeedThreshold||.5,x=h.find(b=>b.dataset.vistaviewPos==="0"),L=Number(x.dataset.vistaviewIndex);function g(){h[0].removeEventListener("transitionend",g),t.style.removeProperty("--vistaview-pointer-diff-x"),t.style.removeProperty("--vistaview-pointer-diff-y"),h.forEach(b=>{b.style.transition="",b.style.translate=""})}function C(b="0%",S="0%"){h.forEach(T=>{T.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,T.style.translate=`${b} ${S}`})}if(v<-p||v>p){let b=function(){h[0].removeEventListener("transitionend",b),setTimeout(()=>{const S=s.isReducedMotion;s.isReducedMotion=!0,g(),s.view(v<-p?(L+1)%i:(L-1+i)%i,{next:v<-p,prev:v>p}),s.isReducedMotion=S},100)};C(v<-p?"-100%":"100%"),h[0].addEventListener("transitionend",b)}else E<-p||E>p?(s.close(),C("0%","0%")):(h[0].addEventListener("transitionend",g),C("0%"))},t.addEventListener("pointermove",M),t.addEventListener("pointerup",Z),t.addEventListener("pointerdown",$),t.addEventListener("pointercancel",z)}function R(s){const t=s.imageContainerElm;t&&(M&&t.removeEventListener("pointermove",M),Z&&t.removeEventListener("pointerup",Z),$&&t.removeEventListener("pointerdown",$),z&&t.removeEventListener("pointercancel",z))}const B=s=>{Y(s)},_=({htmlElements:{to:s},index:{to:t},elements:i})=>{i instanceof NodeList&&t!==null&&(i.forEach(n=>n.style.opacity="1"),i[t].style.opacity="0"),s&&s.forEach(n=>{const e=Number(n.dataset.vistaviewPos);e!==0?(n.style.zIndex="1",n.style.left=100*e+"%"):n.style.zIndex="2"})},F=async({htmlElements:{from:s,to:t},images:{to:i},via:{next:n,prev:e},options:a,isReducedMotion:d},o)=>{if(console.log("defaultTransition called"),!i)throw new Error("VistaView: images is null in defaultTransition()");const l=s.filter(c=>c.dataset.vistaviewPos==="0"||(n?c.dataset.vistaviewPos==="1":c.dataset.vistaviewPos==="-1"));if(d){console.log("reduced motion, no transition");return}await new Promise((c,r)=>{let h=0;if(o.aborted){console.log("transition aborted before start"),r(new P("Transition aborted"));return}const m=f=>{if(o.aborted){console.log("transition aborted before start"),r(new P("Transition aborted"));return}if(f.currentTarget.removeEventListener("transitionend",m),h++,h<l.length)return;const u=t==null?void 0:t.find(g=>g.dataset.vistaviewPos==="0"),v=u?Number(u.dataset.vistaviewIndex):0,E=l.find(g=>Number(g.dataset.vistaviewIndex)===v),p=E==null?void 0:E.querySelector(".vistaview-image-highres");if(!p){r(new Error("current image element not found"));return}if(!p.classList.contains("vistaview-image-loaded")){console.log("current image not loaded yet"),c(0);return}if(u==null||u.classList.add("vistaview-image-loaded"),p.classList.contains("vistaview-image-settled")){console.log("current image already settled"),u==null||u.classList.add("vistaview-image-settled"),c(0);return}let x=0;console.log("waiting for image to be settled...");const L=setInterval(()=>{if(o.aborted){console.log("transition aborted during wait"),clearInterval(L),r(new P("Transition aborted"));return}if(x++,x>a.animationDurationBase/20*1.5){console.log("timeout waiting for image to be settled"),clearInterval(L),c(0);return}p.classList.contains("vistaview-image-settled")&&(console.log("image settled"),u==null||u.classList.add("vistaview-image-settled"),clearInterval(L),c(0))},20)};l.forEach(f=>{f.style.transition=`translate ${a.animationDurationBase*.5}ms ease-out`,f.style.translate=n?"-100%":e?"100%":"0%",f.addEventListener("transitionend",m)})})},N=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),R(s)};class P extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const H={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",V(),"close"],bottomCenter:["description"]}},D={somethingOpened:null};class st{constructor(t,i){w(this,"options");w(this,"elements");w(this,"isReducedMotion");w(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n;const i=this._value;this._value=t,(n=this._vistaView)==null||n.swap(i,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});w(this,"rootElm",null);w(this,"imageContainerElm",null);w(this,"customControls",{});w(this,"currentImages",null);w(this,"currentItems",null);w(this,"navActive",!0);w(this,"isZoomed",!1);w(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});w(this,"defaultOnClickHandler",t=>t.preventDefault());w(this,"onResizeHandler",null);w(this,"onKeyDown",null);w(this,"userSetup",_);w(this,"userTransition",F);w(this,"userClose",N);w(this,"userInit",B);w(this,"onZoomedPointerDown",null);w(this,"onZoomedPointerMove",null);w(this,"onZoomedPointerUp",null);w(this,"transitionAbortController",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...H,...i||{},controls:{...H.controls,...(i==null?void 0:i.controls)||{}}},this.options.initFunction&&(this.userInit=this.options.initFunction),this.options.transitionFunction&&(this.userTransition=this.options.transitionFunction),this.options.closeFunction&&(this.userClose=this.options.closeFunction),this.options.initFunction&&(this.userInit=this.options.initFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((n,e)=>{n.dataset.vistaviewIndex=e.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}async swap(t,i){var l,c;if(!D.somethingOpened||t===i||t===null)return;if(console.log("Swapping from",t,"to",i),this.transitionAbortController&&this.transitionAbortController.abort(),!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:e}=this.getCurrentIndexes(i),a=this.getImages(n),d=a.map((r,h)=>X(r,e[h]));console.log("swap prepared");const o={htmlElements:{from:this.currentItems,to:d},images:{from:this.currentImages,to:a},index:{from:t,to:i},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(o),this.transitionAbortController=new AbortController;try{await this.userTransition(o,this.transitionAbortController.signal)}catch(r){r instanceof P||console.error(r)}console.log("swap completed"),this.imageContainerElm.innerHTML="",d.forEach(r=>{const h=r.dataset.vistaviewPos,m=r.dataset.vistaviewIndex;if(h==="0"){const f=this.currentItems.find(E=>E.dataset.vistaviewIndex===m),u=r.querySelector(".vistaview-image-highres"),v=f==null?void 0:f.querySelector(".vistaview-image-highres");v&&(u.setAttribute("class",v.getAttribute("class")||""),u.setAttribute("style",v.getAttribute("style")||"")),this.imageContainerElm.appendChild(r)}else this.imageContainerElm.appendChild(r)}),this.setInitialDimPos(),this.currentImages=a,this.currentItems=d,this.loadImages(),this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(c=(l=this.options).onImageView)==null||c.call(l,o)}setZoomed(t){var i,n,e,a,d,o;if(this.isZoomed!==t){if(this.isZoomed){let l=this.isZoomed;if(l.classList.remove("vistaview-image--zooming"),this.onZoomedPointerDown&&((i=l.parentElement)==null||i.removeEventListener("pointerdown",this.onZoomedPointerDown),this.onZoomedPointerDown=null),this.onZoomedPointerMove&&((n=l.parentElement)==null||n.removeEventListener("pointermove",this.onZoomedPointerMove),this.onZoomedPointerMove=null),this.onZoomedPointerUp&&((e=l.parentElement)==null||e.removeEventListener("pointerup",this.onZoomedPointerUp),this.onZoomedPointerUp=null),l==null||l.style.removeProperty("--pointer-diff-x"),l==null||l.style.removeProperty("--pointer-diff-y"),setTimeout(()=>{l==null||l.classList.remove("vistaview-image--zooming")},500),this.isZoomed=!1,!t)return}if(t){this.isZoomed=t,t.classList.add("vistaview-image--zooming"),t==null||t.style.setProperty("--pointer-diff-x","0px"),t==null||t.style.setProperty("--pointer-diff-y","0px");let l=!1,c=0,r=0,h=0,m=0,f=0,u=0;this.onZoomedPointerDown=v=>{v.preventDefault(),v.stopPropagation(),l=!0,c=v.pageX,r=v.pageY,t.setPointerCapture(v.pointerId)},this.onZoomedPointerMove=v=>{if(!l)return;v.preventDefault(),f=v.pageX-c,u=v.pageY-r;const E=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),p=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:x,minDiffY:L,maxDiffY:g,minDiffX:C}=O(E,p),b=Math.min(x,Math.max(C,h+f)),S=Math.min(g,Math.max(L,m+u));f=b-h,u=S-m,t==null||t.style.setProperty("--pointer-diff-x",`${b}px`),t==null||t.style.setProperty("--pointer-diff-y",`${S}px`)},this.onZoomedPointerUp=v=>{l=!1,t.releasePointerCapture(v.pointerId),h+=f,m+=u,f=0,u=0},(a=t==null?void 0:t.parentElement)==null||a.addEventListener("pointerdown",this.onZoomedPointerDown),(d=t==null?void 0:t.parentElement)==null||d.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var a,d,o,l,c;const t=(a=this.rootElm)==null?void 0:a.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 r=Math.min(i+this.options.zoomStep,e);t.style.width=`${r}px`;const h=r/i*n;t.style.height=`${h}px`,(o=(d=this.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=r.toString(),t.dataset.vistaviewCurrentHeight=h.toString(),r===e&&((c=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"))==null||c.setAttribute("disabled","true"))}}zoomOut(){var d,o,l,c,r;const t=(d=this.rootElm)==null?void 0:d.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height,e=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,a=h=>{h.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",a))};if(t.addEventListener("transitionend",a),t.classList.add("vistaview-image--zooming-out"),i&&e&&i>e){const h=Math.max(i-this.options.zoomStep,e);t.style.width=`${h}px`;const m=h/i*n;t.style.height=`${m}px`,(l=(o=this.rootElm)==null?void 0:o.querySelector("button.vistaview-zoom-in-btn"))==null||l.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=h.toString(),t.dataset.vistaviewCurrentHeight=m.toString();const{maxDiffX:f,minDiffY:u,maxDiffY:v,minDiffX:E}=O(h,m);let p=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),x=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");p=Math.min(f,Math.max(E,p)),x=Math.min(v,Math.max(u,x)),t==null||t.style.setProperty("--pointer-diff-x",`${p}px`),t==null||t.style.setProperty("--pointer-diff-y",`${x}px`),h===e&&((r=(c=this.rootElm)==null?void 0:c.querySelector("button.vistaview-zoom-out-btn"))==null||r.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 a=e.querySelector("img"),d=e.getAttribute("href")||"",o=e.getAttribute("src")||"",l=e.dataset.vistaviewSrc||d||o||(a==null?void 0:a.src)||"",c=e.dataset.vistaviewAlt||e.getAttribute("alt")||(a==null?void 0:a.alt)||"",r=e.dataset.vistaviewThumb||(a==null?void 0:a.src)||d||o||"";return{index:t[n],src:l,alt:c,thumb:r,imageElm:e instanceof HTMLImageElement?e:a,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var c,r;if(!this.rootElm)return;const t=(c=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:c.dataset.vistaviewIndex,i=((r=this.currentImages)==null?void 0:r.find(h=>h.index===Number(t)))||null;if(!i)return;const n=i.imageElm?I(i.imageElm):void 0,e=i.anchorElm?I(i.anchorElm):void 0,a=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,d=(e==null?void 0:e.height)||(n==null?void 0:n.height)||0,o=((e==null?void 0:e.left)||(n==null?void 0:n.left)||0)+a/2,l=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+d/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",d+"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 r,h;const a=(r=i.rootElm)==null?void 0:r.querySelector("button.vistaview-zoom-in-btn"),d=(h=i.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"),o=parseInt(t.style.width)||t.width,l=t.naturalWidth*i.options.maxZoomLevel,c=o<l&&l>0;a&&(a.style.display=c?"":"none"),d&&(d.style.display=c?"":"none")}t.complete&&t.naturalWidth>0?n():t.addEventListener("load",n)}loadImages(){if(!this.rootElm)return;this.rootElm.querySelectorAll(".vistaview-image-highres:not(.vistaview-image-loaded)").forEach((i,n)=>{const e=i,d=this.currentImages[n].imageElm,o={w:0,h:0};if(d){const{width:c,height:r}=j(d);o.w=Math.min(d.width,c),o.h=Math.min(d.height,r)}const l=()=>{var r;const c=()=>{var h;o.w&&o.h&&(e.style.width=`${o.w}px`,e.style.height=`${o.h}px`,e.style.setProperty("--vistaview-fitted-width",`${o.w}px`),e.style.setProperty("--vistaview-fitted-height",`${o.h}px`)),e.classList.add("vistaview-image-loaded"),e.width=e.naturalWidth,e.height=e.naturalHeight,setTimeout(()=>{var E,p;let m=0;const f=()=>{var x,L;m++,!(m<3)&&(e.removeEventListener("transitionend",f),(L=(x=e.parentElement)==null?void 0:x.querySelector(".vistaview-image-lowres"))==null||L.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled"))};e.addEventListener("transitionend",f);const{width:u,height:v}=W(e);e.style.width=`${u}px`,e.style.height=`${v}px`,o.w&&o.h&&u===o.w&&v===o.h?((p=(E=e.parentElement)==null?void 0:E.querySelector(".vistaview-image-lowres"))==null||p.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled")):(e.style.width=`${u}px`,e.style.height=`${v}px`)},100),(h=i.parentElement)!=null&&h.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((r=this.rootElm)!=null&&r.classList.contains("vistaview--opened"))c();else{const h=setInterval(()=>{var m;(m=this.rootElm)!=null&&m.classList.contains("vistaview--opened")&&(clearInterval(h),c())},50)}};e.complete&&e.naturalWidth>0?l():e.onload=l})}setIndexDisplay(){this.elements.length!==1&&(this.rootElm.querySelector(".vistaview-index-display").textContent=`${this.currentIndex.value+1} / ${this.elements.length}`)}setCurrentDescription(){this.rootElm.querySelector(".vistaview-description").textContent=(this.currentImages[1]||this.currentImages[0]).alt||""}getCurrentIndexes(t){const i=this.options.preloads,n=this.elements.length,e=n<1||!i?[t]:[...new Set([...Array.from({length:i},(d,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(d,o)=>(t+1+o)%n)])],a=n<1||!i?[0]:e.map((d,o)=>o-Math.floor(e.length/2));return{images:e,positions:a}}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:a,height:d}=W(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=a.toString(),e.dataset.vistaviewInitialHeight=d.toString()):(e.style.width=`${a}px`,e.style.height=`${d}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,l,c,r,h,m,f,u,v,E,p,x,L;if(D.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(D.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(nt({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((o=this.rootElm)==null?void 0:o.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw D.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:i,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(i);const e=this.currentImages.map((g,C)=>X(g,n[C]));this.currentItems=e;const a={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(a),this.imageContainerElm.innerHTML="",this.currentItems.forEach(g=>{this.imageContainerElm.appendChild(g)});let d=0;this.rootElm.addEventListener("animationend",g=>{var C;g.currentTarget===this.rootElm&&(d++,d>=2&&((C=this.rootElm)==null||C.classList.add("vistaview--opened")))}),(l=this.rootElm.querySelector(".vistaview-close-btn"))==null||l.addEventListener("click",()=>this.close()),(c=this.rootElm.querySelector(".vistaview-zoom-in-btn"))==null||c.addEventListener("click",()=>this.zoomIn()),(r=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||r.addEventListener("click",()=>this.zoomOut()),(h=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||h.addEventListener("click",()=>this.prev()),(m=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||m.addEventListener("click",()=>this.next()),[...this.options.controls.topLeft||[],...this.options.controls.topRight||[],...this.options.controls.topCenter||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomRight||[]].forEach(g=>{typeof g!="string"&&(this.customControls[g.name]=g)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(g=>{g.addEventListener("click",C=>{const b=this.customControls[C.currentTarget.dataset.vistaviewCustomControl],S=this.currentImages.find(T=>T.index===this.currentIndex.value);b&&S&&(b.onClick.constructor.name==="AsyncFunction"?(g.classList.add("vistaview-button--loading"),b.onClick(S).finally(()=>{g.classList.remove("vistaview-button--loading")})):b.onClick(S))})}),this.options.animationDurationBase&&this.rootElm.style.setProperty("--vistaview-animation-duration",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElm.style.setProperty("--vistaview-initial-z-index",`${this.options.initialZIndex}`),this.setInitialDimPos(),this.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((f=this.rootElm.querySelector(".vistaview-prev-btn"))==null||f.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-next-btn"))==null||u.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),(p=(E=this.options).onOpen)==null||p.call(E,a),(L=(x=this.options).onImageView)==null||L.call(x,a)}async close(t=!0){var n,e,a;if(D.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(d=>{var l;let o;(l=this.rootElm)==null||l.addEventListener("transitionend",c=>{c.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{d()},333))})}));const i={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},container:this.imageContainerElm,elements:this.elements,via:{prev:!1,next:!1},isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userClose(this),(a=(e=this.options).onClose)==null||a.call(e,i),document.body.removeChild(this.rootElm),this.currentIndex._value=null,this.currentIndex._via={next:!1,prev:!1},this.rootElm=null,this.imageContainerElm=null,this.currentImages=null,this.currentItems=null,this.navActive=!0,this.onResizeHandler&&(window.removeEventListener("resize",this.onResizeHandler),this.onResizeHandler=null),this.onKeyDown&&(window.removeEventListener("keydown",this.onKeyDown),this.onKeyDown=null),(this.onZoomedPointerDown||this.onZoomedPointerMove||this.onZoomedPointerUp)&&(this.setZoomed(!1),this.onZoomedPointerDown=null,this.onZoomedPointerMove=null,this.onZoomedPointerUp=null),this.transitionAbortController&&(this.transitionAbortController.abort(),this.transitionAbortController=null),D.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.dataset.vistaviewIndex&&delete t.dataset.vistaviewIndex,t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}view(t,i){D.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=i||{next:!1,prev:!1},this.currentIndex.value=t)}next(){D.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){D.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return D.somethingOpened===this?this.currentIndex.value:-1}}function ot(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let i=0;i<t.length;i++){const n=t[i];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${i} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const i=s;for(let n=0;n<i.length;n++)if(!i[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function rt({elements:s,...t}){if(!s)throw new Error("No elements");let i=ot(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new st(i,t);return{open:(e=0)=>n.open(e),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:e=>{n.view(e)}}}y.DefaultOptions=H,y.VistaViewTransitionAbortedError=P,y.defaultClose=N,y.defaultInit=B,y.defaultSetup=_,y.defaultTransition=F,y.removeTouchActions=R,y.setTouchActions=Y,y.vistaView=rt,y.vistaViewDownload=V,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
16
+ </div>`)}let $=null,M=null,Z=null,z=null;function Y(s){R(s);const t=s.imageContainerElm,i=s.elements.length;if(!t)return;let n=0,e=0,a=0,d=0,o=null,l=0,h=!1;$=r=>{r.preventDefault(),r.stopPropagation(),s.isZoomed===!1&&(h=!0,n=r.pageX,e=r.pageY,a=r.pageX,d=r.pageY,l=Date.now(),o=null,t.setPointerCapture(r.pointerId))},M=r=>{if(r.preventDefault(),r.stopPropagation(),s.isZoomed!==!1||!h)return;const c=r.pageX-n,m=r.pageY-e;a=r.pageX,d=r.pageY,Math.abs(c)>=Math.abs(m)&&(o===null||o===!0)?(t.style.setProperty("--vistaview-pointer-diff-x",`${c}px`),o=!0):Math.abs(m)>Math.abs(c)&&(o===null||o===!1)&&(t.style.setProperty("--vistaview-pointer-diff-y",`${m}px`),o=!1)},z=r=>{if(r.preventDefault(),r.stopPropagation(),t.releasePointerCapture(r.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(m=>{m.style.transition="",m.style.translate=""})},Z=r=>{if(r.preventDefault(),r.stopPropagation(),t.releasePointerCapture(r.pointerId),s.isZoomed!==!1||!h)return;h=!1;const c=Array.from(t.querySelectorAll(".vistaview-item")),m=a-n,f=d-e,u=Date.now()-l,v=m/u,E=f/u,p=s.options.touchSpeedThreshold||.5,x=c.find(b=>b.dataset.vistaviewPos==="0"),L=Number(x.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(b=>{b.style.transition="",b.style.translate=""})}function C(b="0%",S="0%"){c.forEach(T=>{T.style.transition=`translate ${s.options.animationDurationBase*.5}ms ease-out`,T.style.translate=`${b} ${S}`})}if(v<-p||v>p){let b=function(){c[0].removeEventListener("transitionend",b),setTimeout(()=>{const S=s.isReducedMotion;s.isReducedMotion=!0,g(),s.view(v<-p?(L+1)%i:(L-1+i)%i,{next:v<-p,prev:v>p}),s.isReducedMotion=S},100)};C(v<-p?"-100%":"100%"),c[0].addEventListener("transitionend",b)}else E<-p||E>p?(s.close(),C("0%","0%")):(c[0].addEventListener("transitionend",g),C("0%"))},t.addEventListener("pointermove",M),t.addEventListener("pointerup",Z),t.addEventListener("pointerdown",$),t.addEventListener("pointercancel",z)}function R(s){const t=s.imageContainerElm;t&&(M&&t.removeEventListener("pointermove",M),Z&&t.removeEventListener("pointerup",Z),$&&t.removeEventListener("pointerdown",$),z&&t.removeEventListener("pointercancel",z))}const B=s=>{Y(s)},_=({htmlElements:{to:s},index:{to:t},elements:i})=>{i instanceof NodeList&&t!==null&&(i.forEach(n=>n.style.opacity="1"),i[t].style.opacity="0"),s&&s.forEach(n=>{const e=Number(n.dataset.vistaviewPos);e!==0?(n.style.zIndex="1",n.style.left=100*e+"%"):n.style.zIndex="2"})},F=async({htmlElements:{from:s,to:t},images:{to:i},via:{next:n,prev:e},options:a,isReducedMotion:d},o)=>{if(!i)throw new Error("VistaView: images is null in defaultTransition()");const l=s.filter(h=>h.dataset.vistaviewPos==="0"||(n?h.dataset.vistaviewPos==="1":h.dataset.vistaviewPos==="-1"));d||await new Promise((h,r)=>{let c=0;if(o.aborted){r(new P("Transition aborted"));return}const m=f=>{if(o.aborted){r(new P("Transition aborted"));return}if(f.currentTarget.removeEventListener("transitionend",m),c++,c<l.length)return;const u=t==null?void 0:t.find(g=>g.dataset.vistaviewPos==="0"),v=u?Number(u.dataset.vistaviewIndex):0,E=l.find(g=>Number(g.dataset.vistaviewIndex)===v),p=E==null?void 0:E.querySelector(".vistaview-image-highres");if(!p){r(new Error("current image element not found"));return}if(!p.classList.contains("vistaview-image-loaded")){h(0);return}if(u==null||u.classList.add("vistaview-image-loaded"),p.classList.contains("vistaview-image-settled")){u==null||u.classList.add("vistaview-image-settled"),h(0);return}let x=0;const L=setInterval(()=>{if(o.aborted){clearInterval(L),r(new P("Transition aborted"));return}if(x++,x>a.animationDurationBase/20*1.5){clearInterval(L),h(0);return}p.classList.contains("vistaview-image-settled")&&(u==null||u.classList.add("vistaview-image-settled"),clearInterval(L),h(0))},20)};l.forEach(f=>{f.style.transition=`translate ${a.animationDurationBase*.5}ms ease-out`,f.style.translate=n?"-100%":e?"100%":"0%",f.addEventListener("transitionend",m)})})},N=s=>{s.elements instanceof NodeList&&s.elements.forEach(t=>t.style.opacity="1"),R(s)};class P extends Error{constructor(t){super(t),this.name="VistaViewTransitionAbortedError"}}const H={detectReducedMotion:!0,animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",V(),"close"],bottomCenter:["description"]}},D={somethingOpened:null};class st{constructor(t,i){w(this,"options");w(this,"elements");w(this,"isReducedMotion");w(this,"currentIndex",{_value:null,_vistaView:null,_via:{next:!1,prev:!1},set value(t){var n;const i=this._value;this._value=t,(n=this._vistaView)==null||n.swap(i,this._value)},get value(){return this._value},get via(){return this._via},set via(t){this._via=t}});w(this,"rootElm",null);w(this,"imageContainerElm",null);w(this,"customControls",{});w(this,"currentImages",null);w(this,"currentItems",null);w(this,"navActive",!0);w(this,"isZoomed",!1);w(this,"onClickElements",t=>{t.preventDefault();const i=t.currentTarget;i.dataset.vistaviewIndex&&this.open(parseInt(i.dataset.vistaviewIndex))});w(this,"defaultOnClickHandler",t=>t.preventDefault());w(this,"onResizeHandler",null);w(this,"onKeyDown",null);w(this,"userSetup",_);w(this,"userTransition",F);w(this,"userClose",N);w(this,"userInit",B);w(this,"onZoomedPointerDown",null);w(this,"onZoomedPointerMove",null);w(this,"onZoomedPointerUp",null);w(this,"transitionAbortController",null);this.elements=t,this.currentIndex._vistaView=this,this.options={...H,...i||{},controls:{...H.controls,...(i==null?void 0:i.controls)||{}}},this.options.initFunction&&(this.userInit=this.options.initFunction),this.options.transitionFunction&&(this.userTransition=this.options.transitionFunction),this.options.closeFunction&&(this.userClose=this.options.closeFunction),this.options.initFunction&&(this.userInit=this.options.initFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((n,e)=>{n.dataset.vistaviewIndex=e.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}async swap(t,i){var l,h;if(!D.somethingOpened||t===i||t===null)return;if(this.transitionAbortController&&this.transitionAbortController.abort(),!this.imageContainerElm)throw new Error("VistaView: imageContainerElm is null in swap()");this.setIndexDisplay(),this.clearZoom();const{images:n,positions:e}=this.getCurrentIndexes(i),a=this.getImages(n),d=a.map((r,c)=>X(r,e[c])),o={htmlElements:{from:this.currentItems,to:d},images:{from:this.currentImages,to:a},index:{from:t,to:i},via:this.currentIndex.via,container:this.imageContainerElm,elements:this.elements,isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userSetup(o),this.transitionAbortController=new AbortController;try{await this.userTransition(o,this.transitionAbortController.signal)}catch(r){r instanceof P||console.error(r)}this.imageContainerElm.innerHTML="",d.forEach(r=>{const c=r.dataset.vistaviewPos,m=r.dataset.vistaviewIndex;if(c==="0"){const f=this.currentItems.find(E=>E.dataset.vistaviewIndex===m),u=r.querySelector(".vistaview-image-highres"),v=f==null?void 0:f.querySelector(".vistaview-image-highres");v&&(u.setAttribute("class",v.getAttribute("class")||""),u.setAttribute("style",v.getAttribute("style")||"")),this.imageContainerElm.appendChild(r)}else this.imageContainerElm.appendChild(r)}),this.setInitialDimPos(),this.currentImages=a,this.currentItems=d,this.loadImages(),this.setCurrentDescription(),this.updateZoomButtonsVisibility(),(h=(l=this.options).onImageView)==null||h.call(l,o)}setZoomed(t){var i,n,e,a,d,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,r=0,c=0,m=0,f=0,u=0;this.onZoomedPointerDown=v=>{v.preventDefault(),v.stopPropagation(),l=!0,h=v.pageX,r=v.pageY,t.setPointerCapture(v.pointerId)},this.onZoomedPointerMove=v=>{if(!l)return;v.preventDefault(),f=v.pageX-h,u=v.pageY-r;const E=parseInt((t==null?void 0:t.dataset.vistaviewCurrentWidth)||"0"),p=parseInt((t==null?void 0:t.dataset.vistaviewCurrentHeight)||"0"),{maxDiffX:x,minDiffY:L,maxDiffY:g,minDiffX:C}=O(E,p),b=Math.min(x,Math.max(C,c+f)),S=Math.min(g,Math.max(L,m+u));f=b-c,u=S-m,t==null||t.style.setProperty("--pointer-diff-x",`${b}px`),t==null||t.style.setProperty("--pointer-diff-y",`${S}px`)},this.onZoomedPointerUp=v=>{l=!1,t.releasePointerCapture(v.pointerId),c+=f,m+=u,f=0,u=0},(a=t==null?void 0:t.parentElement)==null||a.addEventListener("pointerdown",this.onZoomedPointerDown),(d=t==null?void 0:t.parentElement)==null||d.addEventListener("pointermove",this.onZoomedPointerMove),(o=t==null?void 0:t.parentElement)==null||o.addEventListener("pointerup",this.onZoomedPointerUp);return}}}zoomIn(){var a,d,o,l,h;const t=(a=this.rootElm)==null?void 0:a.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 r=Math.min(i+this.options.zoomStep,e);t.style.width=`${r}px`;const c=r/i*n;t.style.height=`${c}px`,(o=(d=this.rootElm)==null?void 0:d.querySelector("button.vistaview-zoom-out-btn"))==null||o.removeAttribute("disabled"),t.dataset.vistaviewCurrentWidth=r.toString(),t.dataset.vistaviewCurrentHeight=c.toString(),r===e&&((h=(l=this.rootElm)==null?void 0:l.querySelector("button.vistaview-zoom-in-btn"))==null||h.setAttribute("disabled","true"))}}zoomOut(){var d,o,l,h,r;const t=(d=this.rootElm)==null?void 0:d.querySelector('[data-vistaview-pos="0"] .vistaview-image-highres'),i=t.width,n=t.height,e=t.dataset.vistaviewInitialWidth?parseInt(t.dataset.vistaviewInitialWidth):0,a=c=>{c.target===t&&(t.classList.remove("vistaview-image--zooming-out"),t.removeEventListener("transitionend",a))};if(t.addEventListener("transitionend",a),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 m=c/i*n;t.style.height=`${m}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=m.toString();const{maxDiffX:f,minDiffY:u,maxDiffY:v,minDiffX:E}=O(c,m);let p=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-x").replace("px",""))||"0"),x=parseInt((t==null?void 0:t.style.getPropertyValue("--pointer-diff-y").replace("px",""))||"0");p=Math.min(f,Math.max(E,p)),x=Math.min(v,Math.max(u,x)),t==null||t.style.setProperty("--pointer-diff-x",`${p}px`),t==null||t.style.setProperty("--pointer-diff-y",`${x}px`),c===e&&((r=(h=this.rootElm)==null?void 0:h.querySelector("button.vistaview-zoom-out-btn"))==null||r.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 a=e.querySelector("img"),d=e.getAttribute("href")||"",o=e.getAttribute("src")||"",l=e.dataset.vistaviewSrc||d||o||(a==null?void 0:a.src)||"",h=e.dataset.vistaviewAlt||e.getAttribute("alt")||(a==null?void 0:a.alt)||"",r=e.dataset.vistaviewThumb||(a==null?void 0:a.src)||d||o||"";return{index:t[n],src:l,alt:h,thumb:r,imageElm:e instanceof HTMLImageElement?e:a,anchorElm:e instanceof HTMLAnchorElement?e:void 0}}else return{index:t[n],...e}})}setInitialDimPos(){var h,r;if(!this.rootElm)return;const t=(h=this.rootElm.querySelector('[data-vistaview-pos="0"]'))==null?void 0:h.dataset.vistaviewIndex,i=((r=this.currentImages)==null?void 0:r.find(c=>c.index===Number(t)))||null;if(!i)return;const n=i.imageElm?I(i.imageElm):void 0,e=i.anchorElm?I(i.anchorElm):void 0,a=(e==null?void 0:e.width)||(n==null?void 0:n.width)||0,d=(e==null?void 0:e.height)||(n==null?void 0:n.height)||0,o=((e==null?void 0:e.left)||(n==null?void 0:n.left)||0)+a/2,l=((e==null?void 0:e.top)||(n==null?void 0:n.top)||0)+d/2;this.rootElm.style.setProperty("--vistaview-container-initial-width",a+"px"),this.rootElm.style.setProperty("--vistaview-container-initial-height",d+"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 r,c;const a=(r=i.rootElm)==null?void 0:r.querySelector("button.vistaview-zoom-in-btn"),d=(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;a&&(a.style.display=h?"":"none"),d&&(d.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,d=this.currentImages[n].imageElm,o={w:0,h:0};if(d){const{width:h,height:r}=j(d);o.w=Math.min(d.width,h),o.h=Math.min(d.height,r)}const l=()=>{var r;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(()=>{var E,p;let m=0;const f=()=>{var x,L;m++,!(m<3)&&(e.removeEventListener("transitionend",f),(L=(x=e.parentElement)==null?void 0:x.querySelector(".vistaview-image-lowres"))==null||L.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled"))};e.addEventListener("transitionend",f);const{width:u,height:v}=W(e);e.style.width=`${u}px`,e.style.height=`${v}px`,o.w&&o.h&&u===o.w&&v===o.h?((p=(E=e.parentElement)==null?void 0:E.querySelector(".vistaview-image-lowres"))==null||p.classList.add("vistaview-image--hidden"),e.classList.add("vistaview-image-settled")):(e.style.width=`${u}px`,e.style.height=`${v}px`)},100),(c=i.parentElement)!=null&&c.matches('[data-vistaview-pos="0"]')&&this.updateZoomButtonsVisibility()};if((r=this.rootElm)!=null&&r.classList.contains("vistaview--opened"))h();else{const c=setInterval(()=>{var m;(m=this.rootElm)!=null&&m.classList.contains("vistaview--opened")&&(clearInterval(c),h())},50)}};e.complete&&e.naturalWidth>0?l():e.onload=l})}setIndexDisplay(){this.elements.length!==1&&(this.rootElm.querySelector(".vistaview-index-display").textContent=`${this.currentIndex.value+1} / ${this.elements.length}`)}setCurrentDescription(){this.rootElm.querySelector(".vistaview-description").textContent=(this.currentImages[1]||this.currentImages[0]).alt||""}getCurrentIndexes(t){const i=this.options.preloads,n=this.elements.length,e=n<1||!i?[t]:[...new Set([...Array.from({length:i},(d,o)=>((t-i+o)%n+n)%n),t,...Array.from({length:i},(d,o)=>(t+1+o)%n)])],a=n<1||!i?[0]:e.map((d,o)=>o-Math.floor(e.length/2));return{images:e,positions:a}}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:a,height:d}=W(e);e.classList.contains("vistaview-image--zooming")?(e.dataset.vistaviewInitialWidth=a.toString(),e.dataset.vistaviewInitialHeight=d.toString()):(e.style.width=`${a}px`,e.style.height=`${d}px`)})},window.addEventListener("resize",this.onResizeHandler)}open(t=0){var o,l,h,r,c,m,f,u,v,E,p,x,L;if(D.somethingOpened){console.error("VistaView: another instance is already opened. Returning.");return}if(D.somethingOpened=this,this.currentIndex._value=t,document.body.prepend(nt({controls:this.options.controls,isReducedMotion:this.isReducedMotion})),this.rootElm=document.querySelector("#vistaview-root"),this.imageContainerElm=((o=this.rootElm)==null?void 0:o.querySelector(".vistaview-image-container"))||null,!this.rootElm||!this.imageContainerElm)throw D.somethingOpened=null,new Error("Failed to create VistaView element");this.options.arrowOnSmallScreens||this.rootElm.classList.add("vistaview-no-arrows-sm");const{images:i,positions:n}=this.getCurrentIndexes(t);this.currentImages=this.getImages(i);const e=this.currentImages.map((g,C)=>X(g,n[C]));this.currentItems=e;const a={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(a),this.imageContainerElm.innerHTML="",this.currentItems.forEach(g=>{this.imageContainerElm.appendChild(g)});let d=0;this.rootElm.addEventListener("animationend",g=>{var C;g.currentTarget===this.rootElm&&(d++,d>=2&&((C=this.rootElm)==null||C.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()),(r=this.rootElm.querySelector(".vistaview-zoom-out-btn"))==null||r.addEventListener("click",()=>this.zoomOut()),(c=this.rootElm.querySelector(".vistaview-prev-btn>button"))==null||c.addEventListener("click",()=>this.prev()),(m=this.rootElm.querySelector(".vistaview-next-btn>button"))==null||m.addEventListener("click",()=>this.next()),[...this.options.controls.topLeft||[],...this.options.controls.topRight||[],...this.options.controls.topCenter||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomRight||[]].forEach(g=>{typeof g!="string"&&(this.customControls[g.name]=g)}),this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach(g=>{g.addEventListener("click",C=>{const b=this.customControls[C.currentTarget.dataset.vistaviewCustomControl],S=this.currentImages.find(T=>T.index===this.currentIndex.value);b&&S&&(b.onClick.constructor.name==="AsyncFunction"?(g.classList.add("vistaview-button--loading"),b.onClick(S).finally(()=>{g.classList.remove("vistaview-button--loading")})):b.onClick(S))})}),this.options.animationDurationBase&&this.rootElm.style.setProperty("--vistaview-animation-duration",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElm.style.setProperty("--vistaview-initial-z-index",`${this.options.initialZIndex}`),this.setInitialDimPos(),this.setResizeListeners(),this.options.keyboardListeners&&this.setKeyboardListeners(),this.elements.length===1&&((f=this.rootElm.querySelector(".vistaview-prev-btn"))==null||f.classList.add("vistaview-ui--none"),(u=this.rootElm.querySelector(".vistaview-next-btn"))==null||u.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),(p=(E=this.options).onOpen)==null||p.call(E,a),(L=(x=this.options).onImageView)==null||L.call(x,a)}async close(t=!0){var n,e,a;if(D.somethingOpened!==this)return;t&&((n=this.rootElm)==null||n.classList.add("vistaview--closing"),await new Promise(d=>{var l;let o;(l=this.rootElm)==null||l.addEventListener("transitionend",h=>{h.currentTarget===this.rootElm&&(o&&clearTimeout(o),o=setTimeout(()=>{d()},333))})}));const i={htmlElements:{from:this.currentItems,to:null},images:{from:this.currentImages,to:null},index:{from:this.currentIndex.value,to:null},container:this.imageContainerElm,elements:this.elements,via:{prev:!1,next:!1},isReducedMotion:this.isReducedMotion,navActive:this.navActive,isZoomed:this.isZoomed,options:this.options};this.userClose(this),(a=(e=this.options).onClose)==null||a.call(e,i),document.body.removeChild(this.rootElm),this.currentIndex._value=null,this.currentIndex._via={next:!1,prev:!1},this.rootElm=null,this.imageContainerElm=null,this.currentImages=null,this.currentItems=null,this.navActive=!0,this.onResizeHandler&&(window.removeEventListener("resize",this.onResizeHandler),this.onResizeHandler=null),this.onKeyDown&&(window.removeEventListener("keydown",this.onKeyDown),this.onKeyDown=null),(this.onZoomedPointerDown||this.onZoomedPointerMove||this.onZoomedPointerUp)&&(this.setZoomed(!1),this.onZoomedPointerDown=null,this.onZoomedPointerMove=null,this.onZoomedPointerUp=null),this.transitionAbortController&&(this.transitionAbortController.abort(),this.transitionAbortController=null),D.somethingOpened=null}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.dataset.vistaviewIndex&&delete t.dataset.vistaviewIndex,t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}view(t,i){D.somethingOpened===this&&this.navActive&&(t<0&&(t=this.elements.length-1),t>=this.elements.length&&(t=0),this.currentIndex.via=i||{next:!1,prev:!1},this.currentIndex.value=t)}next(){D.somethingOpened===this&&this.view(this.currentIndex.value+1,{next:!0,prev:!1})}prev(){D.somethingOpened===this&&this.view(this.currentIndex.value-1,{next:!1,prev:!0})}getCurrentIndex(){return D.somethingOpened===this?this.currentIndex.value:-1}}function ot(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let i=0;i<t.length;i++){const n=t[i];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${i} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const i=s;for(let n=0;n<i.length;n++)if(!i[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function rt({elements:s,...t}){if(!s)throw new Error("No elements");let i=ot(s);if(typeof i=="string")return console.error(i),console.warn("VistaView: silently returning."),null;const n=new st(i,t);return{open:(e=0)=>n.open(e),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:e=>{n.view(e)}}}y.DefaultOptions=H,y.VistaViewTransitionAbortedError=P,y.defaultClose=N,y.defaultInit=B,y.defaultSetup=_,y.defaultTransition=F,y.removeTouchActions=R,y.setTouchActions=Y,y.vistaView=rt,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.6",
3
+ "version": "0.3.7",
4
4
  "description": "A lightweight, zero-dependency image lightbox library with smooth animations and touch support",
5
5
  "keywords": [
6
6
  "image",