vistaview 0.7.6 → 0.7.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/dist/lib/vista-view.d.ts.map +1 -1
- package/dist/vistaview.js +21 -19
- package/dist/vistaview.umd.js +3 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vista-view.d.ts","sourceRoot":"","sources":["../../src/lib/vista-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,QAAQ,EAGR,QAAQ,EAIR,gCAAgC,EACjC,MAAM,SAAS,CAAC;AAajB,eAAO,MAAM,gBAAgB,EAAE;IAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAA;CAEjE,CAAC;AAEF,qBAAa,SAAS;IACpB,OAAO,EAAE,QAAQ,CAAC;IAClB,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,QAAQ,EAAE,CAAC;IAC/C,eAAe,EAAE,OAAO,CAAC;IAEzB,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,eAAe,CAAmE;IAE1F,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,kBAAkB,CAAiC;IAC3D,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,gBAAgB,CAMV;IAEd,IAAI,EAAE,WAAW,GAAG,IAAI,CAAQ;IAChC,cAAc,EAAE,WAAW,GAAG,IAAI,CAAQ;IAC1C,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAIrD,OAAO,CAAC,eAAe,CAIrB;IAEF,OAAO,CAAC,qBAAqB,CAAwD;IAErF,OAAO,CAAC,eAAe,CAAgC;IAEvD,OAAO,CAAC,QAAQ,CAAkB;gBAEtB,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,QAAQ,EAAE,EAAE,OAAO,GAAE,QAAa;IA8DlF,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,iBAAiB,CAA6B;YACxC,IAAI;IAyIlB,OAAO,CAAC,gBAAgB;IAkDxB,UAAU,EAAE,OAAO,CAAS;IAC5B,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,kBAAkB;IAmC1B,OAAO,CAAC,eAAe;IA4CvB,OAAO,CAAC,mBAAmB;IAiE3B,OAAO,CAAC,SAAS,CAuBf;IAEF,OAAO,CAAC,QAAQ,CAYd;IAEF,OAAO,CAAC,eAAe,CAkBrB;IAGF,OAAO,CAAC,gBAAgB,CAAyD;IACjF,uBAAuB,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,gCAAgC,KAAK,IAAI,GAAG,IAAI;IAGtF,OAAO,CAAC,0BAA0B;IAIlC,OAAO,CAAC,0BAA0B,CAmEhC;IAGF,IAAI,CAAC,UAAU,GAAE,MAAU,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"vista-view.d.ts","sourceRoot":"","sources":["../../src/lib/vista-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,QAAQ,EAGR,QAAQ,EAIR,gCAAgC,EACjC,MAAM,SAAS,CAAC;AAajB,eAAO,MAAM,gBAAgB,EAAE;IAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAA;CAEjE,CAAC;AAEF,qBAAa,SAAS;IACpB,OAAO,EAAE,QAAQ,CAAC;IAClB,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,QAAQ,EAAE,CAAC;IAC/C,eAAe,EAAE,OAAO,CAAC;IAEzB,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,eAAe,CAAmE;IAE1F,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,kBAAkB,CAAiC;IAC3D,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,gBAAgB,CAMV;IAEd,IAAI,EAAE,WAAW,GAAG,IAAI,CAAQ;IAChC,cAAc,EAAE,WAAW,GAAG,IAAI,CAAQ;IAC1C,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAIrD,OAAO,CAAC,eAAe,CAIrB;IAEF,OAAO,CAAC,qBAAqB,CAAwD;IAErF,OAAO,CAAC,eAAe,CAAgC;IAEvD,OAAO,CAAC,QAAQ,CAAkB;gBAEtB,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,QAAQ,EAAE,EAAE,OAAO,GAAE,QAAa;IA8DlF,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,iBAAiB,CAA6B;YACxC,IAAI;IAyIlB,OAAO,CAAC,gBAAgB;IAkDxB,UAAU,EAAE,OAAO,CAAS;IAC5B,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,kBAAkB;IAmC1B,OAAO,CAAC,eAAe;IA4CvB,OAAO,CAAC,mBAAmB;IAiE3B,OAAO,CAAC,SAAS,CAuBf;IAEF,OAAO,CAAC,QAAQ,CAYd;IAEF,OAAO,CAAC,eAAe,CAkBrB;IAGF,OAAO,CAAC,gBAAgB,CAAyD;IACjF,uBAAuB,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,gCAAgC,KAAK,IAAI,GAAG,IAAI;IAGtF,OAAO,CAAC,0BAA0B;IAIlC,OAAO,CAAC,0BAA0B,CAmEhC;IAGF,IAAI,CAAC,UAAU,GAAE,MAAU,GAAG,IAAI;IA+I5B,KAAK,CAAC,OAAO,GAAE,OAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DnD,IAAI,IAAI,IAAI;IASZ,IAAI,IAAI,IAAI;IASZ,OAAO,IAAI,IAAI;IAcf,eAAe,IAAI,MAAM;IAOzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAoBlE"}
|
package/dist/vistaview.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var F = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var h = (s, t, e) =>
|
|
2
|
+
var A = (s, t, e) => t in s ? F(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var h = (s, t, e) => A(s, typeof t != "symbol" ? t + "" : t, e);
|
|
4
4
|
function T(s) {
|
|
5
5
|
return s && !/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim()) && s;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function R(s) {
|
|
8
8
|
const e = window.getComputedStyle(s).objectFit || "", { width: i, height: n } = s.getBoundingClientRect(), r = s.naturalWidth, a = s.naturalHeight;
|
|
9
9
|
if (!e)
|
|
10
10
|
return { width: i, height: n };
|
|
@@ -72,7 +72,7 @@ function W(s, t, e, i = !1) {
|
|
|
72
72
|
left: p
|
|
73
73
|
} = z(s), x = Math.min(Math.max(p, -r), window.innerWidth + r) - window.innerWidth / 2 + r / 2, g = Math.min(Math.max(d, -a), window.innerHeight + a) - window.innerHeight / 2 + a / 2, m = e.style;
|
|
74
74
|
m.width = `${r}px`, m.height = `${a}px`, m.objectFit = n, e.width = o, e.height = l, m.setProperty("--vvw-init-radius", `${c}`), m.setProperty("--vvw-pulse-radius", `calc(1.3 * ${c})`), m.setProperty("--vvw-init-x", `${x}px`), m.setProperty("--vvw-init-y", `${g}px`), i && (m.setProperty("--vvw-current-x", `${x}px`), m.setProperty("--vvw-current-y", `${g}px`));
|
|
75
|
-
const u =
|
|
75
|
+
const u = R(s.imageElm), b = Math.min(r, u.width), f = Math.min(a, u.height), v = t.style;
|
|
76
76
|
v.setProperty("--vvw-init-radius", `${c}`), v.setProperty("--vvw-init-w", `${b}px`), v.setProperty("--vvw-init-h", `${f}px`), i && (v.setProperty("--vvw-current-radius", `${c}`), v.setProperty("--vvw-current-w", `${b}px`), v.setProperty("--vvw-current-h", `${f}px`), t.dataset.vvwWidth = b.toString(), t.dataset.vvwHeight = f.toString());
|
|
77
77
|
}
|
|
78
78
|
function H(s) {
|
|
@@ -91,14 +91,14 @@ function H(s) {
|
|
|
91
91
|
height: l
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function q(s, t, e) {
|
|
95
95
|
return Math.min(Math.max(s, t), e);
|
|
96
96
|
}
|
|
97
97
|
function L(s, t = 2) {
|
|
98
98
|
const e = Math.pow(10, t);
|
|
99
99
|
return Math.round(s * e) / e;
|
|
100
100
|
}
|
|
101
|
-
const
|
|
101
|
+
const k = '<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>', O = '<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>', Z = '<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>', N = '<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="8" x2="14" y1="11" y2="11"/></svg>', X = '<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>', Y = '<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>';
|
|
102
102
|
let $ = null;
|
|
103
103
|
function B() {
|
|
104
104
|
return $ || (window.trustedTypes || (window.trustedTypes = {
|
|
@@ -171,7 +171,7 @@ function _({
|
|
|
171
171
|
<div class="vvw-image-container"></div>
|
|
172
172
|
<div class="vvw-top-bar"><div>${t(s == null ? void 0 : s.topLeft)}</div><div>${t(s == null ? void 0 : s.topCenter)}</div><div>${t(s == null ? void 0 : s.topRight)}</div></div>
|
|
173
173
|
<div class="vvw-bottom-bar"><div>${t(s == null ? void 0 : s.bottomLeft)}</div><div>${t(s == null ? void 0 : s.bottomCenter)}</div><div>${t(s == null ? void 0 : s.bottomRight)}</div></div>
|
|
174
|
-
<div class="vvw-prev vvw-ui"><button aria-label="Previous">${
|
|
174
|
+
<div class="vvw-prev vvw-ui"><button aria-label="Previous">${k}</button></div>
|
|
175
175
|
<div class="vvw-next vvw-ui"><button aria-label="Next">${O}</button></div>
|
|
176
176
|
</div>
|
|
177
177
|
</div>`
|
|
@@ -425,7 +425,7 @@ class it {
|
|
|
425
425
|
if (!this.image) return;
|
|
426
426
|
this.rect || (this.rect = this.image.getBoundingClientRect()), e || (e = this.initialCenter);
|
|
427
427
|
const i = this.snapToTargetIfClose(
|
|
428
|
-
|
|
428
|
+
q(this.rect.width * t, this.minDimension.minWidth, this.maxDimension.width),
|
|
429
429
|
this.minDimension.initialWidth
|
|
430
430
|
);
|
|
431
431
|
this.onScale && this.onScale({
|
|
@@ -845,17 +845,19 @@ class st {
|
|
|
845
845
|
u.classList.remove("vvw--loading");
|
|
846
846
|
})) : v.onClick(E, this));
|
|
847
847
|
});
|
|
848
|
-
}), this.initFunction(this),
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
848
|
+
}), this.initFunction(this), requestAnimationFrame(() => {
|
|
849
|
+
requestAnimationFrame(() => {
|
|
850
|
+
var m;
|
|
851
|
+
(m = this.root) == null || m.addEventListener(
|
|
852
|
+
"transitionend",
|
|
853
|
+
() => {
|
|
854
|
+
var u;
|
|
855
|
+
(u = this.root) == null || u.classList.add("vvw--settled"), this.imageState.reset(), this.waitForImagesToLoad();
|
|
856
|
+
},
|
|
857
|
+
{ once: !0 }
|
|
858
|
+
), this.root.classList.add("vvw--active"), this.displayActiveIndex(), this.options.onOpen && this.options.onOpen(this), this.options.onImageView && this.options.onImageView(o);
|
|
859
|
+
});
|
|
860
|
+
});
|
|
859
861
|
}
|
|
860
862
|
/// CLOSE
|
|
861
863
|
async close(t = !0) {
|
package/dist/vistaview.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(v,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(v=typeof globalThis<"u"?globalThis:v||self,w(v.VistaView={}))})(this,(function(v){"use strict";var rt=Object.defineProperty;var at=(v,w,$)=>w in v?rt(v,w,{enumerable:!0,configurable:!0,writable:!0,value:$}):v[w]=$;var h=(v,w,$)=>at(v,typeof w!="symbol"?w+"":w,$);function w(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function $(s){const e=window.getComputedStyle(s).objectFit||"",{width:i,height:n}=s.getBoundingClientRect(),r=s.naturalWidth,a=s.naturalHeight;if(!e)return{width:i,height:n};if(!r||!a)return{width:i,height:n};const o=r/a,l=i/n;switch(e){case"fill":return{width:i,height:n};case"none":return{width:r,height:a};case"contain":return o>l?{width:i,height:i/o}:{width:n*o,height:n};case"cover":return o<l?{width:i,height:i/o}:{width:n*o,height:n};case"scale-down":{const c={width:r,height:a},d=o>l?{width:i,height:i/o}:{width:n*o,height:n};return d.width<=c.width&&d.height<=c.height?d:c}}return{width:i,height:n}}function W(s){const t=getComputedStyle(s),e=s.getBoundingClientRect();return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow,top:e.top,left:e.left,width:e.width,height:e.height,naturalWidth:s.naturalWidth,naturalHeight:s.naturalHeight}}function Z(s){const t=s.imageElm?W(s.imageElm):null,e=s.anchorElm?W(s.anchorElm):null,i=w(t==null?void 0:t.borderRadius),n=e&&w(e==null?void 0:e.borderRadius),r=(n?e==null?void 0:e.borderRadius:i?t==null?void 0:t.borderRadius:"")||"";return{fit:(t==null?void 0:t.objectFit)||(e==null?void 0:e.objectFit)||"",pos:(t==null?void 0:t.objectPosition)||"",br:r,overflow:n?e.overflow:i?t.overflow:"",nw:(t==null?void 0:t.naturalWidth)||0,nh:(t==null?void 0:t.naturalHeight)||0,w:(e==null?void 0:e.width)||(t==null?void 0:t.width)||0,h:(e==null?void 0:e.height)||(t==null?void 0:t.height)||0,top:(e==null?void 0:e.top)||(t==null?void 0:t.top)||0,left:(e==null?void 0:e.left)||(t==null?void 0:t.left)||0}}function P(s,t,e,i=!1){const{fit:n,w:r,h:a,nw:o,nh:l,br:c,top:d,left:f}=Z(s),L=Math.min(Math.max(f,-r),window.innerWidth+r)-window.innerWidth/2+r/2,y=Math.min(Math.max(d,-a),window.innerHeight+a)-window.innerHeight/2+a/2,m=e.style;m.width=`${r}px`,m.height=`${a}px`,m.objectFit=n,e.width=o,e.height=l,m.setProperty("--vvw-init-radius",`${c}`),m.setProperty("--vvw-pulse-radius",`calc(1.3 * ${c})`),m.setProperty("--vvw-init-x",`${L}px`),m.setProperty("--vvw-init-y",`${y}px`),i&&(m.setProperty("--vvw-current-x",`${L}px`),m.setProperty("--vvw-current-y",`${y}px`));const u=$(s.imageElm),E=Math.min(r,u.width),x=Math.min(a,u.height),p=t.style;p.setProperty("--vvw-init-radius",`${c}`),p.setProperty("--vvw-init-w",`${E}px`),p.setProperty("--vvw-init-h",`${x}px`),i&&(p.setProperty("--vvw-current-radius",`${c}`),p.setProperty("--vvw-current-w",`${E}px`),p.setProperty("--vvw-current-h",`${x}px`),t.dataset.vvwWidth=E.toString(),t.dataset.vvwHeight=x.toString())}function F(s){const t=window.innerWidth,e=window.innerHeight,i=s.naturalWidth,n=s.naturalHeight;if(!i||!n)throw new Error("Image natural dimensions are zero");if(i<t&&n<e)return{width:i,height:n};const r=i/n,a=t/e;let o,l;return r>a?(o=t,l=t/r):(l=e,o=e*r),{width:o,height:l}}function N(s,t,e){return Math.min(Math.max(s,t),e)}function I(s,t=2){const e=Math.pow(10,t);return Math.round(s*e)/e}const X='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',Y='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',B='<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>',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="8" x2="14" y1="11" y2="11"/></svg>',V='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',U='<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>';let D=null;function _(){return D||(window.trustedTypes||(window.trustedTypes={createPolicy:(s,t)=>t}),D=window.trustedTypes.createPolicy("vistaView-policy",{createHTML:s=>s,createScript:()=>{throw new Error("Not implemented")},createScriptURL:()=>{throw new Error("Not implemented")}}),D)}function
|
|
2
|
-
<img class="vvw-img-hi" src="${s.src}" alt="${s.alt||""}" />`));const i=e.querySelector("img.vvw-img-lo"),n=e.querySelector("img.vvw-img-hi");return P(s,n,i,t===0),e}function J({controls:s}){const t=i=>i?i.map(K).join(""):"";return
|
|
1
|
+
(function(v,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(v=typeof globalThis<"u"?globalThis:v||self,w(v.VistaView={}))})(this,(function(v){"use strict";var rt=Object.defineProperty;var at=(v,w,$)=>w in v?rt(v,w,{enumerable:!0,configurable:!0,writable:!0,value:$}):v[w]=$;var h=(v,w,$)=>at(v,typeof w!="symbol"?w+"":w,$);function w(s){return s&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim())&&s}function $(s){const e=window.getComputedStyle(s).objectFit||"",{width:i,height:n}=s.getBoundingClientRect(),r=s.naturalWidth,a=s.naturalHeight;if(!e)return{width:i,height:n};if(!r||!a)return{width:i,height:n};const o=r/a,l=i/n;switch(e){case"fill":return{width:i,height:n};case"none":return{width:r,height:a};case"contain":return o>l?{width:i,height:i/o}:{width:n*o,height:n};case"cover":return o<l?{width:i,height:i/o}:{width:n*o,height:n};case"scale-down":{const c={width:r,height:a},d=o>l?{width:i,height:i/o}:{width:n*o,height:n};return d.width<=c.width&&d.height<=c.height?d:c}}return{width:i,height:n}}function W(s){const t=getComputedStyle(s),e=s.getBoundingClientRect();return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow,top:e.top,left:e.left,width:e.width,height:e.height,naturalWidth:s.naturalWidth,naturalHeight:s.naturalHeight}}function Z(s){const t=s.imageElm?W(s.imageElm):null,e=s.anchorElm?W(s.anchorElm):null,i=w(t==null?void 0:t.borderRadius),n=e&&w(e==null?void 0:e.borderRadius),r=(n?e==null?void 0:e.borderRadius:i?t==null?void 0:t.borderRadius:"")||"";return{fit:(t==null?void 0:t.objectFit)||(e==null?void 0:e.objectFit)||"",pos:(t==null?void 0:t.objectPosition)||"",br:r,overflow:n?e.overflow:i?t.overflow:"",nw:(t==null?void 0:t.naturalWidth)||0,nh:(t==null?void 0:t.naturalHeight)||0,w:(e==null?void 0:e.width)||(t==null?void 0:t.width)||0,h:(e==null?void 0:e.height)||(t==null?void 0:t.height)||0,top:(e==null?void 0:e.top)||(t==null?void 0:t.top)||0,left:(e==null?void 0:e.left)||(t==null?void 0:t.left)||0}}function P(s,t,e,i=!1){const{fit:n,w:r,h:a,nw:o,nh:l,br:c,top:d,left:f}=Z(s),L=Math.min(Math.max(f,-r),window.innerWidth+r)-window.innerWidth/2+r/2,y=Math.min(Math.max(d,-a),window.innerHeight+a)-window.innerHeight/2+a/2,m=e.style;m.width=`${r}px`,m.height=`${a}px`,m.objectFit=n,e.width=o,e.height=l,m.setProperty("--vvw-init-radius",`${c}`),m.setProperty("--vvw-pulse-radius",`calc(1.3 * ${c})`),m.setProperty("--vvw-init-x",`${L}px`),m.setProperty("--vvw-init-y",`${y}px`),i&&(m.setProperty("--vvw-current-x",`${L}px`),m.setProperty("--vvw-current-y",`${y}px`));const u=$(s.imageElm),E=Math.min(r,u.width),x=Math.min(a,u.height),p=t.style;p.setProperty("--vvw-init-radius",`${c}`),p.setProperty("--vvw-init-w",`${E}px`),p.setProperty("--vvw-init-h",`${x}px`),i&&(p.setProperty("--vvw-current-radius",`${c}`),p.setProperty("--vvw-current-w",`${E}px`),p.setProperty("--vvw-current-h",`${x}px`),t.dataset.vvwWidth=E.toString(),t.dataset.vvwHeight=x.toString())}function F(s){const t=window.innerWidth,e=window.innerHeight,i=s.naturalWidth,n=s.naturalHeight;if(!i||!n)throw new Error("Image natural dimensions are zero");if(i<t&&n<e)return{width:i,height:n};const r=i/n,a=t/e;let o,l;return r>a?(o=t,l=t/r):(l=e,o=e*r),{width:o,height:l}}function N(s,t,e){return Math.min(Math.max(s,t),e)}function I(s,t=2){const e=Math.pow(10,t);return Math.round(s*e)/e}const X='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',Y='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',B='<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>',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="8" x2="14" y1="11" y2="11"/></svg>',V='<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',U='<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>';let D=null;function _(){return D||(window.trustedTypes||(window.trustedTypes={createPolicy:(s,t)=>t}),D=window.trustedTypes.createPolicy("vistaView-policy",{createHTML:s=>s,createScript:()=>{throw new Error("Not implemented")},createScriptURL:()=>{throw new Error("Not implemented")}}),D)}function A(s){const e=_().createHTML(s),i=document.createElement("template");i.innerHTML=e;const n=i.content;return i.remove(),n}function R(){return{name:"download",icon:U,onClick:async s=>{var r;const t=await fetch(s.src),e=await t.blob(),i=t.url,n=document.createElement("a");n.href=URL.createObjectURL(e),n.download=((r=i.split("/").pop())==null?void 0:r.split("?")[0].split("#")[0])||"download",document.body.appendChild(n),n.click(),document.body.removeChild(n)}}}function K(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button aria-label="Zoom In" class="vvw-zoom-in vvw-ui">${B}</button>`;case"zoomOut":return`<button aria-label="Zoom Out" disabled class="vvw-zoom-out vvw-ui">${j}</button>`;case"close":return`<button aria-label="Close" class="vvw-close vvw-ui">${V}</button>`;case"indexDisplay":return'<div class="vvw-index vvw-ui" aria-hidden="true"></div>';case"description":return'<div class="vvw-desc vvw-ui" role="status" aria-live="polite" aria-atomic="true"></div>';default:return""}return`<button class="vvw-ui" aria-label="${s.description||s.name}" data-vvw-control="${s.name}">${s.icon}</button>`}function G(s,t){const e=document.createElement("div");e.className="vvw-item",e.dataset.vvwPos=`${t!==void 0?t:""}`,e.dataset.vvwIdx=s.index.toString(),e.appendChild(A(`<img class="vvw-img-lo" src="${s.thumb||s.src}" alt="${s.alt||""}" />
|
|
2
|
+
<img class="vvw-img-hi" src="${s.src}" alt="${s.alt||""}" />`));const i=e.querySelector("img.vvw-img-lo"),n=e.querySelector("img.vvw-img-hi");return P(s,n,i,t===0),e}function J({controls:s}){const t=i=>i?i.map(K).join(""):"";return A(`<div class="vvw-root" id="vvw-root">
|
|
3
3
|
<div class="vvw-container">
|
|
4
4
|
<div class="vvw-bg"></div>
|
|
5
5
|
<div class="vvw-image-container"></div>
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
<div class="vvw-prev vvw-ui"><button aria-label="Previous">${X}</button></div>
|
|
9
9
|
<div class="vvw-next vvw-ui"><button aria-label="Next">${Y}</button></div>
|
|
10
10
|
</div>
|
|
11
|
-
</div>`)}const M={animationDurationBase:333,maxZoomLevel:2,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,rapidLimit:222,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",A(),"close"],bottomLeft:["description"]}};function z(s){}function k(s){const t=s.options.preloads;s.imageContainer.style.width=`${(t*2+1)*100}vw`,s.imageContainer.style.left=`-${t*100}vw`,s.imageContainer.style.display="flex",Q(s)}function Q(s){let t={x:0,y:0},e={x:0,y:0},i=null;s.registerPointerListener(n=>{var r;if(!n.hasInternalExecution&&!(n.pointers.length>1)){if(n.event==="down"&&(t={x:n.pointer.x,y:n.pointer.y},e={x:n.pointer.x,y:n.pointer.y},(r=n.abortController)==null||r.abort()),n.event==="move"){e={x:n.pointer.x,y:n.pointer.y};const a=e.x-t.x,o=e.y-t.y;if(!i&&Math.abs(o)>Math.abs(a)||i==="y"){const l=o/window.innerHeight*100;s.imageContainer.style.transition="none",s.imageContainer.style.transform=`translateY(${l}vh)`,i="y"}else if(!i&&Math.abs(a)>Math.abs(o)||i==="x"){const l=a/window.innerWidth*100;s.imageContainer.style.transition="none",s.imageContainer.style.transform=`translateX(${l}vw)`,i="x"}}if(n.event==="up"||n.event==="cancel"){let a=function(o){var l;(l=s.imageContainer)==null||l.addEventListener("transitionend",function c(){var d;(d=s.imageContainer)==null||d.removeEventListener("transitionend",c),s.imageContainer.style.transition="",s.imageContainer.style.transform=""}),s.imageContainer.style.transition="transform 222ms ease",s.imageContainer.style.transform=o};if(i==="y"){const o=e.y-t.y;Math.abs(o)>144?(s.imageContainer.style.transition="transform 222ms ease",s.imageContainer.style.transform="translateY(0vh)",s.close()):a("translateY(0vh)")}if(i==="x"){const o=e.x-t.x,l=n.pointer.movementX,c=1;s.imageContainer.style.transition="",o>0&&Math.abs(l)>c?s.prev():o<0&&Math.abs(l)>c?s.next():a("translateX(0vw)")}i=null,t={x:0,y:0},e={x:0,y:0}}}})}function q(s){}function O({vistaView:{isReducedMotion:s},htmlElements:{to:t},index:{from:e,to:i},vistaView:{elements:n,imageContainer:r,options:a}},o){if(!(!t||o.aborted||s||!(Math.abs(i-e)===1||e===0&&i===n.length-1||e===n.length-1&&i===0)))return{cleanup:()=>{r.style.transition="",r.style.transform=""},transitionEnded:new Promise(c=>{r.addEventListener("transitionend",()=>{c()},{once:!0}),r.addEventListener("transitioncancel",()=>{o.aborted&&c()},{once:!0});const d=Math.round(a.animationDurationBase*100)/100,f=i===e+1||e===n.length-1&&i===0?"translateX(-100vw)":"translateX(100vw)";r.style.transition=`transform ${d}ms ease`,r.style.transform=f})}}class tt{constructor({elm:t,listeners:e}){h(this,"pointers",[]);h(this,"elm");h(this,"listeners",[]);h(this,"lastPointerDownId",null);h(this,"removeLastPointer",()=>{if(this.pointers.length&&this.lastPointerDownId!==null){const t=this.pointers.findIndex(e=>e.id===this.lastPointerDownId);t!==-1&&this.pointers.splice(t,1)}});h(this,"onPointerDown",t=>{if(!this.listeners.length||t.button!==0)return;t.preventDefault(),this.lastPointerDownId=t.pointerId,window.addEventListener("contextmenu",this.removeLastPointer,{once:!0}),window.addEventListener("auxclick",this.removeLastPointer,{once:!0});let e={x:t.clientX,y:t.clientY,movementX:0,movementY:0,id:t.pointerId};this.pointers.push(e),this.listeners.forEach(i=>i({event:"down",pointer:e,pointers:this.pointers,lastPointerLen:this.pointers.length-1}))});h(this,"onPointerMove",t=>{if(!this.listeners.length)return;t.preventDefault();const e=this.pointers.find(i=>i.id===t.pointerId);e&&(e.movementX=t.movementX,e.movementY=t.movementY,e.x=t.clientX,e.y=t.clientY,this.listeners.forEach(i=>i({event:"move",pointer:e,pointers:this.pointers,lastPointerLen:this.pointers.length-1})))});h(this,"onPointerUp",t=>{if(!this.listeners.length||t.button!==0||(window.removeEventListener("contextmenu",this.removeLastPointer),window.removeEventListener("auxclick",this.removeLastPointer),t.target instanceof Node&&!this.elm.contains(t.target)&&t.target!==document.querySelector("html")&&t.target!==document))return;t.preventDefault();const e=this.pointers.findIndex(r=>r.id===t.pointerId);if(e===-1)return;const i=this.pointers[e];i.x=t.clientX,i.y=t.clientY;const n=this.pointers.length;this.pointers.splice(e,1),this.listeners.forEach(r=>r({event:"up",pointer:i,pointers:this.pointers,lastPointerLen:n}))});h(this,"onPointerCancel",t=>{if(!this.listeners.length||t.target instanceof Node&&!this.elm.contains(t.target)&&t.target!==document.querySelector("html")&&t.target!==document)return;t.preventDefault();const e=this.pointers.findIndex(r=>r.id===t.pointerId);if(e===-1)return;const i=this.pointers[e];i.x=t.clientX,i.y=t.clientY;const n=this.pointers.length;this.pointers.splice(e,1),this.listeners.forEach(r=>r({event:"cancel",pointer:i,pointers:this.pointers,lastPointerLen:n}))});this.elm=t??document,e&&(this.listeners=e),this.startListeners()}startListeners(){this.elm.addEventListener("pointerdown",this.onPointerDown),this.elm.addEventListener("pointermove",this.onPointerMove),document.addEventListener("pointerup",this.onPointerUp),document.addEventListener("pointercancel",this.onPointerCancel)}removeListeners(){this.elm.removeEventListener("pointerdown",this.onPointerDown),this.elm.removeEventListener("pointermove",this.onPointerMove),document.removeEventListener("pointerup",this.onPointerUp),document.removeEventListener("pointercancel",this.onPointerCancel),this.pointers=[]}addEventListener(t){this.listeners.push(t)}removeEventListener(t){this.listeners=this.listeners.filter(e=>e!==t)}getPointerDistance(t,e){const i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)}getCentroid(){if(this.pointers.length===0)return null;const t=this.pointers.reduce((e,i)=>(e.x+=i.x,e.y+=i.y,e),{x:0,y:0});return{x:t.x/this.pointers.length,y:t.y/this.pointers.length}}}class et{constructor(t,e){h(this,"maxZoomLevel");h(this,"image",null);h(this,"rect",null);h(this,"initialCenter",{x:0,y:0});h(this,"maxDimension",{width:0});h(this,"minDimension",{initialWidth:0,initialHeight:0,minWidth:0,closingWidth:0});h(this,"accumulatedTranslate",{x:0,y:0});h(this,"scale",1);h(this,"translate",{x:0,y:0});h(this,"onScale",null);h(this,"animationTimestamp",0);this.maxZoomLevel=t,this.onScale=e}clean(){this.image&&(this.image.style.transform="",this.image.style.width="",this.image.style.height="",this.image.style.top="",this.image.style.left="",this.image.style.opacity="")}reset(){this.clean(),this.image=null,this.rect=null,this.initialCenter={x:window.innerWidth/2,y:window.innerHeight/2},this.maxDimension={width:0},this.minDimension={initialWidth:0,initialHeight:0,minWidth:0,closingWidth:0},this.accumulatedTranslate={x:0,y:0},this.scale=1,this.translate={x:0,y:0}}setCurrentImage(t){if(this.rect=null,this.image=t,this.maxDimension={width:t.naturalWidth*this.maxZoomLevel},!t.dataset.vvwWidth||!t.dataset.vvwHeight)throw new Error("VistaImageState: Image dataset vvwWidth or vvwHeight not set.");const e=parseFloat(t.dataset.vvwWidth),i=parseFloat(t.dataset.vvwHeight);this.minDimension={initialWidth:e,initialHeight:i,minWidth:e*.1,closingWidth:e*.5},this.accumulatedTranslate={x:0,y:0}}setInitialCenter(t){this.initialCenter=t||{x:window.innerWidth/2,y:window.innerHeight/2}}move(t){this.image&&(this.rect||(this.rect=this.image.getBoundingClientRect()),this.translate.x=I(t.x-this.initialCenter.x),this.translate.y=I(t.y-this.initialCenter.y),this.image.style.transform=`translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`)}snapToTargetIfClose(t,e,i=1){return Math.abs(t-e)<=i&&(t=e),t}scaleMove(t,e){if(!this.image)return;this.rect||(this.rect=this.image.getBoundingClientRect()),e||(e=this.initialCenter);const i=this.snapToTargetIfClose(N(this.rect.width*t,this.minDimension.minWidth,this.maxDimension.width),this.minDimension.initialWidth);this.onScale&&this.onScale({scale:i/(this.maxDimension.width/this.maxZoomLevel),isMax:i>=this.maxDimension.width,isMin:i<=this.minDimension.initialWidth}),this.scale=I(i/this.rect.width);const n=this.rect.left+this.rect.width/2,r=this.rect.top+this.rect.height/2,a=this.initialCenter.x-n,o=this.initialCenter.y-r,l=a*(1-this.scale),c=o*(1-this.scale),d=e.x-this.initialCenter.x,f=e.y-this.initialCenter.y;this.translate.x=I(l+d),this.translate.y=I(c+f),this.image.style.transform=`translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`,i<=this.minDimension.closingWidth?this.image.style.opacity="0.5":this.image.style.opacity=""}moveAndNormalize(t){let e=0,i=!1;const n=({x:r,y:a})=>{if(i)return;if(Math.abs(r)<.001&&Math.abs(a)<.001)return this.normalize();r*=.9,a*=.9;const o=this.image.getBoundingClientRect();this.translate.x=I(this.translate.x+r),this.translate.y=I(this.translate.y+a),o.right<window.innerWidth/2&&(this.translate.x+=(window.innerWidth/2-o.right)*.1,r*=.7),o.left>window.innerWidth/2&&(this.translate.x-=(o.left-window.innerWidth/2)*.1,r*=.7),o.bottom<window.innerHeight/2&&(this.translate.y+=(window.innerHeight/2-o.bottom)*.1,a*=.7),o.top>window.innerHeight/2&&(this.translate.y-=(o.top-window.innerHeight/2)*.1,a*=.7),this.image.style.transform=`translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`,e=requestAnimationFrame(()=>n({x:r,y:a}))};return n({x:t.movementX,y:t.movementY}),()=>{i=!0,cancelAnimationFrame(e),this.normalize(!1)}}animateZoom(t){if(!this.image)return;this.rect||(this.rect=this.image.getBoundingClientRect());const e=Date.now(),i=this.image;this.rect.width*t<this.minDimension.closingWidth||i.width<Math.floor(this.minDimension.initialWidth)||(i.addEventListener("transitionend",()=>{this.animationTimestamp===e&&i&&(i.style.transition="",this.normalize())},{once:!0}),i.style.transition||(i.style.transition="all 222ms ease"),this.animationTimestamp=e,this.scaleMove(t))}normalize(t=!0){if(!this.image||!this.rect)return;const e=this.rect.width*this.scale,i=e<=this.minDimension.closingWidth,n=i?e:this.snapToTargetIfClose(this.rect.width*this.scale,this.minDimension.initialWidth),r=i?this.rect.height*this.scale:this.snapToTargetIfClose(this.rect.height*this.scale,this.minDimension.initialHeight);if(this.image.style.width=`${n}px`,this.image.style.height=`${r}px`,this.scale=1,this.image.style.opacity="",this.accumulatedTranslate.x+=this.translate.x,this.accumulatedTranslate.y+=this.translate.y,this.image.style.left=`calc(50% + ${this.accumulatedTranslate.x}px)`,this.image.style.top=`calc(50% + ${this.accumulatedTranslate.y}px)`,this.translate={x:0,y:0},this.image.style.transform="",this.rect=this.image.getBoundingClientRect(),i)return!0;if(n<this.minDimension.initialWidth)this.accumulatedTranslate.x=0,this.accumulatedTranslate.y=0,requestAnimationFrame(()=>{const a=this.image;a&&(a.addEventListener("transitionend",()=>{a&&(this.clean(),this.rect=null)},{once:!0}),a.style.transition="all 222ms ease",a.style.width=`${this.minDimension.initialWidth}px`,a.style.height=`${this.minDimension.initialHeight}px`,a.style.left="50%",a.style.top="50%")});else if(t){let a=!1;if(this.rect.right<window.innerWidth/2&&(a=!0,this.accumulatedTranslate.x+=window.innerWidth/2-this.rect.right),this.rect.left>window.innerWidth/2&&(a=!0,this.accumulatedTranslate.x-=this.rect.left-window.innerWidth/2),this.rect.bottom<window.innerHeight/2&&(a=!0,this.accumulatedTranslate.y+=window.innerHeight/2-this.rect.bottom),this.rect.top>window.innerHeight/2&&(a=!0,this.accumulatedTranslate.y-=this.rect.top-window.innerHeight/2),a){const o=this.image;o.addEventListener("transitionend",()=>{o&&(o.style.transition="",this.rect=null)},{once:!0}),o.style.transition="all 222ms ease",o.style.left=`calc(50% + ${this.accumulatedTranslate.x}px)`,o.style.top=`calc(50% + ${this.accumulatedTranslate.y}px)`}else this.rect=null}}}class it{constructor(){h(this,"fiolast",{})}fio(t,e,i=50){const r=Date.now()-(this.fiolast[e]??0),a=()=>{this.fiolast[e]=Date.now(),t()};if(!this.fiolast[e]){a();return}r>=i&&a()}}const C={somethingOpened:null};class nt{constructor(t,e={}){h(this,"options");h(this,"elements");h(this,"isReducedMotion");h(this,"currentIndex",-1);h(this,"currentChildren",null);h(this,"setupFunction",z);h(this,"initFunction",k);h(this,"closeFunction",q);h(this,"transitionFunction",O);h(this,"pointers",null);h(this,"imageState");h(this,"imageTransitions",new Map);h(this,"root",null);h(this,"imageContainer",null);h(this,"onClickElements",t=>{t.preventDefault();const e=t.currentTarget;e.dataset.vistaIdx&&this.open(parseInt(e.dataset.vistaIdx))});h(this,"defaultOnClickHandler",t=>t.preventDefault());h(this,"abortController",null);h(this,"throttle",new it);h(this,"lastSwapTime",0);h(this,"isRapidSwap",!1);h(this,"isRapidSwapRelease",0);h(this,"transitionCleanup",null);h(this,"isZoomedIn",!1);h(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}});h(this,"onScroll",t=>{t.preventDefault();const e=t.deltaY;this.imageState.setInitialCenter({x:t.clientX,y:t.clientY}),e<0?this.zoomIn():e>0&&this.zoomOut()});h(this,"onResizeHandler",()=>{this.currentChildren.htmls.forEach((t,e)=>{const i=this.currentChildren.images[e],n=t.querySelector("img.vvw-img-hi"),r=t.querySelector("img.vvw-img-lo");if(P(i,n,r,!1),n.classList.contains("vvw--loaded")){const{width:a,height:o}=F(n);n.style.setProperty("--vvw-current-w",`${a}px`),n.style.setProperty("--vvw-current-h",`${o}px`),n.dataset.vvwWidth=a.toString(),n.dataset.vvwHeight=o.toString()}})});h(this,"pointerListeners",[]);h(this,"getInternalPointerListener",()=>{const t=this.imageState;let e=0,i=!1,n=0;const r=33;let a=()=>{};function o(){return i||performance.now()-n<r}return l=>{if(l.event==="down"){if(a(),this.isZoomedIn&&l.pointers.length===1&&!o()){const c=this.pointers.getCentroid();t.setInitialCenter(c)}if(l.pointers.length>=2){i=!0;const c=this.pointers.getCentroid();e=this.pointers.getPointerDistance(l.pointers[0],l.pointers[1]),t.setInitialCenter(c)}}else if(l.event==="move"){if(this.isZoomedIn&&l.pointers.length===1&&l.lastPointerLen===0&&!o()){const c=this.pointers.getCentroid();t.move(c)}if(l.pointers.length>=2&&i){const c=this.pointers.getCentroid(),d=this.pointers.getPointerDistance(l.pointers[0],l.pointers[1]);t.scaleMove(d/e,c)}}else(l.event==="up"||l.event==="cancel")&&(i||this.isZoomedIn)&&(i?(n=performance.now(),i=!1,t.normalize()&&requestAnimationFrame(()=>{this.close()})):this.isZoomedIn&&l.pointers.length===0&&!o()&&(a=t.moveAndNormalize(l.pointer)));this.pointerListeners.forEach(c=>c({...l,hasInternalExecution:this.isZoomedIn||o(),abortController:this.abortController}))}});this.elements=t,this.options={...M,...e,controls:{...M.controls,...e.controls}},this.imageState=new et(this.options.maxZoomLevel,i=>{var n,r,a,o;i.isMin?(this.isZoomedIn=!1,(n=this.qs(".vvw-zoom-out"))==null||n.setAttribute("disabled","true")):(this.isZoomedIn=!0,(r=this.qs(".vvw-zoom-out"))==null||r.removeAttribute("disabled")),i.isMax?(a=this.qs(".vvw-zoom-in"))==null||a.setAttribute("disabled","true"):(o=this.qs(".vvw-zoom-in"))==null||o.removeAttribute("disabled")}),this.options.setupFunction&&(this.setupFunction=this.options.setupFunction),this.options.closeFunction&&(this.closeFunction=this.options.closeFunction),this.options.initFunction&&(this.initFunction=this.options.initFunction),this.options.transitionFunction&&(this.transitionFunction=this.options.transitionFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((i,n)=>{i.dataset.vistaIdx=n.toString(),i.addEventListener("click",this.defaultOnClickHandler),i.addEventListener("pointerup",this.onClickElements)})}qs(t){return this.root?this.root.querySelector(t):null}async swap(t,e){const i=this.options.preloads||0,n=this.currentIndex,{htmls:r,images:a}=this.getChildElements(i,n),o=this.imageContainer,l=this.currentChildren,c={htmlElements:{from:l.htmls,to:r},images:{from:l.images,to:a},index:{from:t,to:this.currentIndex},via:e||{next:!1,prev:!1},vistaView:this};this.setupFunction(c),this.currentChildren={htmls:r,images:a},this.displayActiveIndex();const d=this.abortController.signal,L=performance.now()-this.lastSwapTime<this.options.rapidLimit;if(this.isRapidSwap=L,o.querySelectorAll(".vvw-item img.vvw-img-hi").forEach(b=>b.classList.add("vvw--load-cancelled")),L){this.imageState.reset(),o.innerHTML="",this.transitionCleanup&&this.transitionCleanup(),r.forEach(b=>{o.appendChild(b)}),this.lastSwapTime=performance.now(),this.waitForImagesToLoad(),this.options.onImageView&&this.options.onImageView(c),this.isRapidSwapRelease&&clearTimeout(this.isRapidSwapRelease),this.isRapidSwapRelease=setTimeout(()=>{this.isRapidSwap=!1},333);return}const y=this.transitionFunction(c,d);y&&(this.transitionCleanup=y.cleanup,await y.transitionEnded),this.lastSwapTime=performance.now();const m=r[Math.floor(r.length/2)].dataset.vvwIdx,u=o.querySelector(`.vvw-item[data-vvw-idx="${m}"] img.vvw-img-hi`),E=this.imageTransitions.get(u);this.imageTransitions.delete(u);const x=u.getAttribute("style")||"",p=u.classList.contains("vvw--loaded"),S=u.classList.contains("vvw--ready"),T=u.width,H=u.height;this.imageState.reset(),o.innerHTML="",this.transitionCleanup&&this.transitionCleanup(),r.forEach(b=>{const g=b.querySelector("img.vvw-img-hi");b.dataset.vvwPos==="0"&&!d.aborted&&x&&T&&H&&(p&&(g.classList.add("vvw--loaded"),g.dataset.vvwWidth=u.dataset.vvwWidth||"",g.dataset.vvwHeight=u.dataset.vvwHeight||""),S&&(g.classList.add("vvw--ready"),g.width=T,g.height=H),g.setAttribute("style",x)),o.appendChild(b),b.dataset.vvwPos==="0"&&!d.aborted&&S?(this.imageState.setCurrentImage(g),this.imageState.setInitialCenter()):b.dataset.vvwPos==="0"&&!d.aborted&&x&&T&&H&&p&&E&&(this.imageTransitions.set(g,E),this.transitionImage(g,()=>{this.imageState.setCurrentImage(g),this.imageState.setInitialCenter(),g.classList.add("vvw--ready")}))}),this.isRapidSwap=!1,this.waitForImagesToLoad(),this.options.onImageView&&this.options.onImageView(c)}getChildElements(t,e){const i=[],n=[];for(let r=-t;r<=t;r++){const a=(e+r+this.elements.length)%this.elements.length,o=this.elements[a],l=o instanceof HTMLImageElement?o:o instanceof HTMLAnchorElement&&o.querySelector("img")||void 0,c=o instanceof HTMLElement?{index:a,imageElm:l instanceof HTMLImageElement?l:void 0,anchorElm:o instanceof HTMLAnchorElement?o:void 0,src:o.dataset.vistaviewSrc||o.getAttribute("href")||o.getAttribute("src")||"",thumb:o.dataset.vistaviewThumb||(l instanceof HTMLImageElement?l.getAttribute("src"):void 0)||o.getAttribute("href")||void 0,alt:l instanceof HTMLImageElement&&l.getAttribute("alt")||void 0}:{index:a,...o};n.push(c),i.push(G(c,r))}return{htmls:i,images:n}}zoomIn(){this.throttle.fio(()=>{this.imageState.animateZoom(1.68)},"zoom",222)}zoomOut(){this.throttle.fio(()=>{this.imageState.animateZoom(.68)},"zoom",222)}displayActiveIndex(){var a;const t=this.currentIndex;this.elements instanceof NodeList&&this.elements.forEach((o,l)=>{o.style.opacity="",l===t&&(o.style.opacity="0")});const e=this.qs(".vvw-index"),i=`${t+1}`,n=`${this.elements.length}`;e&&(e.textContent=`${i} / ${n}`);const r=this.qs(".vvw-desc");if(r){const o=(a=this.currentChildren)==null?void 0:a.images.find(c=>c.index===t),l=(o==null?void 0:o.alt)||"";l?(r.textContent=l,r.setAttribute("aria-label",`Image ${i} of ${n}: ${l}`)):(r.textContent="",r.setAttribute("aria-label",`Image ${i} of ${n}`))}}transitionImage(t,e){if(t.classList.contains("vvw--load-cancelled"))return;if(this.isRapidSwap){requestAnimationFrame(()=>{this.transitionImage(t,e)});return}const i=this.imageTransitions.get(t);i&&requestAnimationFrame(()=>{if(t.classList.contains("vvw--load-cancelled"))return;const{current:n,target:r}=i,a={width:n.width+(r.width-n.width)*.2,height:n.height+(r.height-n.height)*.2,radius:n.radius+(r.radius-n.radius)*.2};Math.abs(a.width-r.width)<1&&Math.abs(a.height-r.height)<1&&Math.abs(a.radius-r.radius)<1?(t.style.setProperty("--vvw-current-w",`${r.width}px`),t.style.setProperty("--vvw-current-h",`${r.height}px`),t.style.setProperty("--vvw-current-radius",`${r.radius}px`),this.imageTransitions.delete(t),e()):(t.style.setProperty("--vvw-current-w",`${a.width}px`),t.style.setProperty("--vvw-current-h",`${a.height}px`),t.style.setProperty("--vvw-current-radius",`${a.radius}px`),this.imageTransitions.set(t,{current:a,target:r}),this.transitionImage(t,e))})}waitForImagesToLoad(){this.imageContainer.querySelectorAll("img.vvw-img-hi:not(.vvw--loaded)").forEach(i=>{const n=i;if(n.classList.contains("vvw--load-cancelled"))return;const r=()=>{if(n.classList.contains("vvw--load-cancelled"))return;n.width=n.naturalWidth,n.height=n.naturalHeight;const{width:a,height:o}=F(n);n.dataset.vvwWidth=a.toString(),n.dataset.vvwHeight=o.toString(),n.classList.add("vvw--loaded"),this.imageTransitions.set(n,{current:{width:n.style.getPropertyValue("--vvw-current-w")?parseFloat(n.style.getPropertyValue("--vvw-current-w")):0,height:n.style.getPropertyValue("--vvw-current-h")?parseFloat(n.style.getPropertyValue("--vvw-current-h")):0,radius:n.style.getPropertyValue("--vvw-current-radius")?parseFloat(n.style.getPropertyValue("--vvw-current-radius")):0},target:{width:a,height:o,radius:0}}),this.transitionImage(n,()=>{var c;if(n.classList.contains("vvw--load-cancelled"))return;((c=n.parentElement)==null?void 0:c.matches(`[data-vvw-idx="${this.currentIndex}"][data-vvw-pos="0"]`))&&(this.imageState.setCurrentImage(n),this.imageState.setInitialCenter()),n.classList.add("vvw--ready")})};if(n.complete&&n.naturalWidth!==0){r();return}n.addEventListener("load",()=>{r()}),n.addEventListener("error",()=>{var o;n.classList.add("vvw--loaderror");const a=document.createElement("p");a.className="vvw-img-err",a.setAttribute("role","alert"),a.textContent="Error loading image",(o=n.parentNode)==null||o.appendChild(a)})})}registerPointerListener(t){this.pointerListeners.push(t)}unregisterPointerListeners(){this.pointerListeners=[]}open(t=0){var c,d,f,L,y;if(C.somethingOpened)return;C.somethingOpened=this,this.currentIndex=t,document.body.style.overflow="hidden";const e=J({controls:this.options.controls});if(document.body.prepend(e),this.root=document.body.querySelector("#vvw-root"),!this.root)throw new Error("Failed to setup VistaView root element.");this.imageContainer=this.qs(".vvw-image-container"),this.options.animationDurationBase&&this.root.style.setProperty("--vvw-anim-dur",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.root.style.setProperty("--vvw-init-z",`${this.options.initialZIndex??0}`),this.options.arrowOnSmallScreens&&this.root.classList.add("vvw-arrow-sm");const i=this.options.preloads||0,n=t,{images:r,htmls:a}=this.getChildElements(i,n),o={htmlElements:{from:null,to:a},images:{from:null,to:r},index:{from:null,to:this.currentIndex},via:{next:!1,prev:!1},vistaView:this};this.setupFunction(o),this.currentChildren={htmls:a,images:r},a.forEach(m=>{this.imageContainer.appendChild(m)}),(c=this.qs(".vvw-close"))==null||c.addEventListener("click",()=>this.close()),(d=this.qs(".vvw-zoom-in"))==null||d.addEventListener("click",()=>this.zoomIn()),(f=this.qs(".vvw-zoom-out"))==null||f.addEventListener("click",()=>this.zoomOut()),(L=this.qs(".vvw-prev>button"))==null||L.addEventListener("click",()=>this.prev()),(y=this.qs(".vvw-next>button"))==null||y.addEventListener("click",()=>this.next()),this.options.keyboardListeners&&window.addEventListener("keydown",this.onKeyDown),window.addEventListener("wheel",this.onScroll,{passive:!1}),window.addEventListener("resize",this.onResizeHandler),this.pointers=new tt({elm:this.imageContainer,listeners:[this.getInternalPointerListener()]});const l={};[...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(m=>{typeof m!="string"&&(l[m.name]=m)}),this.root.querySelectorAll("button[data-vvw-control]").forEach(m=>{const u=m;u.addEventListener("click",E=>{const x=E.currentTarget.dataset.vvwControl,p=l[x],S=this.currentChildren.images.find(T=>T.index===this.currentIndex);p&&S&&(p.onClick.constructor.name==="AsyncFunction"?(u.classList.add("vvw--loading"),p.onClick(S,this).finally(()=>{u.classList.remove("vvw--loading")})):p.onClick(S,this))})}),this.initFunction(this),setTimeout(()=>{var m;(m=this.root)==null||m.addEventListener("transitionend",()=>{var u;(u=this.root)==null||u.classList.add("vvw--settled"),this.imageState.reset(),this.waitForImagesToLoad()},{once:!0}),this.root.classList.add("vvw--active"),this.displayActiveIndex(),this.options.onOpen&&this.options.onOpen(this),this.options.onImageView&&this.options.onImageView(o)},0)}async close(t=!0){C.somethingOpened===this&&this.root&&(t?await new Promise(e=>{let n=0;this.root.addEventListener("transitionend",r=>{r.target===this.root&&(n++,n===2&&this.elements instanceof NodeList&&this.elements.forEach(a=>{a.style.opacity=""}),n===3&&e(null))}),this.root.classList.add("vvw--closing")}):this.elements instanceof NodeList&&this.elements.forEach(e=>{e.style.opacity=""}),this.options.keyboardListeners&&window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("resize",this.onResizeHandler),window.removeEventListener("wheel",this.onScroll),this.unregisterPointerListeners(),this.pointers.removeListeners(),this.root.remove(),this.root=null,this.imageContainer=null,this.currentChildren=null,this.currentIndex=-1,document.body.style.overflow="",C.somethingOpened=null,this.closeFunction(this),this.options.onClose&&this.options.onClose(this))}next(){if(C.somethingOpened!==this)return;const t=(this.currentIndex+1)%this.elements.length;this.view(t,{next:!0,prev:!1})}prev(){if(C.somethingOpened!==this)return;const t=(this.currentIndex-1+this.elements.length)%this.elements.length;this.view(t,{next:!1,prev:!0})}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.removeAttribute("data-vista-idx"),t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}getCurrentIndex(){return C.somethingOpened!==this?-1:this.currentIndex}view(t,e){if(C.somethingOpened!==this||t<0||t>=this.elements.length)return;const i=this.currentIndex;this.currentIndex=t;const n=this.abortController;n==null||n.abort(),this.abortController=new AbortController,this.swap(i,e)}}function st(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let e=0;e<t.length;e++){const i=t[e];if(!(i.dataset.vistaviewSrc||i.getAttribute("href")||i.getAttribute("src")||""))return`Element at index ${e} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const e=s;for(let i=0;i<e.length;i++)if(!e[i].src)return`Element at index ${i} is missing 'src' attribute.`}return t||s}function ot({elements:s,...t}){if(!s)throw new Error("No elements");let e=st(s);if(typeof e=="string")return null;const i=new nt(e,t);return{open:(n=0)=>i.open(n),close:()=>i.close(),next:()=>i.next(),prev:()=>i.prev(),destroy:()=>i.destroy(),getCurrentIndex:()=>i.getCurrentIndex(),view:n=>{i.view(n)}}}v.DefaultOptions=M,v.close=q,v.init=k,v.setup=z,v.transition=O,v.vistaView=ot,v.vistaViewDownload=A,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
|
11
|
+
</div>`)}const M={animationDurationBase:333,maxZoomLevel:2,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,rapidLimit:222,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",R(),"close"],bottomLeft:["description"]}};function z(s){}function q(s){const t=s.options.preloads;s.imageContainer.style.width=`${(t*2+1)*100}vw`,s.imageContainer.style.left=`-${t*100}vw`,s.imageContainer.style.display="flex",Q(s)}function Q(s){let t={x:0,y:0},e={x:0,y:0},i=null;s.registerPointerListener(n=>{var r;if(!n.hasInternalExecution&&!(n.pointers.length>1)){if(n.event==="down"&&(t={x:n.pointer.x,y:n.pointer.y},e={x:n.pointer.x,y:n.pointer.y},(r=n.abortController)==null||r.abort()),n.event==="move"){e={x:n.pointer.x,y:n.pointer.y};const a=e.x-t.x,o=e.y-t.y;if(!i&&Math.abs(o)>Math.abs(a)||i==="y"){const l=o/window.innerHeight*100;s.imageContainer.style.transition="none",s.imageContainer.style.transform=`translateY(${l}vh)`,i="y"}else if(!i&&Math.abs(a)>Math.abs(o)||i==="x"){const l=a/window.innerWidth*100;s.imageContainer.style.transition="none",s.imageContainer.style.transform=`translateX(${l}vw)`,i="x"}}if(n.event==="up"||n.event==="cancel"){let a=function(o){var l;(l=s.imageContainer)==null||l.addEventListener("transitionend",function c(){var d;(d=s.imageContainer)==null||d.removeEventListener("transitionend",c),s.imageContainer.style.transition="",s.imageContainer.style.transform=""}),s.imageContainer.style.transition="transform 222ms ease",s.imageContainer.style.transform=o};if(i==="y"){const o=e.y-t.y;Math.abs(o)>144?(s.imageContainer.style.transition="transform 222ms ease",s.imageContainer.style.transform="translateY(0vh)",s.close()):a("translateY(0vh)")}if(i==="x"){const o=e.x-t.x,l=n.pointer.movementX,c=1;s.imageContainer.style.transition="",o>0&&Math.abs(l)>c?s.prev():o<0&&Math.abs(l)>c?s.next():a("translateX(0vw)")}i=null,t={x:0,y:0},e={x:0,y:0}}}})}function k(s){}function O({vistaView:{isReducedMotion:s},htmlElements:{to:t},index:{from:e,to:i},vistaView:{elements:n,imageContainer:r,options:a}},o){if(!(!t||o.aborted||s||!(Math.abs(i-e)===1||e===0&&i===n.length-1||e===n.length-1&&i===0)))return{cleanup:()=>{r.style.transition="",r.style.transform=""},transitionEnded:new Promise(c=>{r.addEventListener("transitionend",()=>{c()},{once:!0}),r.addEventListener("transitioncancel",()=>{o.aborted&&c()},{once:!0});const d=Math.round(a.animationDurationBase*100)/100,f=i===e+1||e===n.length-1&&i===0?"translateX(-100vw)":"translateX(100vw)";r.style.transition=`transform ${d}ms ease`,r.style.transform=f})}}class tt{constructor({elm:t,listeners:e}){h(this,"pointers",[]);h(this,"elm");h(this,"listeners",[]);h(this,"lastPointerDownId",null);h(this,"removeLastPointer",()=>{if(this.pointers.length&&this.lastPointerDownId!==null){const t=this.pointers.findIndex(e=>e.id===this.lastPointerDownId);t!==-1&&this.pointers.splice(t,1)}});h(this,"onPointerDown",t=>{if(!this.listeners.length||t.button!==0)return;t.preventDefault(),this.lastPointerDownId=t.pointerId,window.addEventListener("contextmenu",this.removeLastPointer,{once:!0}),window.addEventListener("auxclick",this.removeLastPointer,{once:!0});let e={x:t.clientX,y:t.clientY,movementX:0,movementY:0,id:t.pointerId};this.pointers.push(e),this.listeners.forEach(i=>i({event:"down",pointer:e,pointers:this.pointers,lastPointerLen:this.pointers.length-1}))});h(this,"onPointerMove",t=>{if(!this.listeners.length)return;t.preventDefault();const e=this.pointers.find(i=>i.id===t.pointerId);e&&(e.movementX=t.movementX,e.movementY=t.movementY,e.x=t.clientX,e.y=t.clientY,this.listeners.forEach(i=>i({event:"move",pointer:e,pointers:this.pointers,lastPointerLen:this.pointers.length-1})))});h(this,"onPointerUp",t=>{if(!this.listeners.length||t.button!==0||(window.removeEventListener("contextmenu",this.removeLastPointer),window.removeEventListener("auxclick",this.removeLastPointer),t.target instanceof Node&&!this.elm.contains(t.target)&&t.target!==document.querySelector("html")&&t.target!==document))return;t.preventDefault();const e=this.pointers.findIndex(r=>r.id===t.pointerId);if(e===-1)return;const i=this.pointers[e];i.x=t.clientX,i.y=t.clientY;const n=this.pointers.length;this.pointers.splice(e,1),this.listeners.forEach(r=>r({event:"up",pointer:i,pointers:this.pointers,lastPointerLen:n}))});h(this,"onPointerCancel",t=>{if(!this.listeners.length||t.target instanceof Node&&!this.elm.contains(t.target)&&t.target!==document.querySelector("html")&&t.target!==document)return;t.preventDefault();const e=this.pointers.findIndex(r=>r.id===t.pointerId);if(e===-1)return;const i=this.pointers[e];i.x=t.clientX,i.y=t.clientY;const n=this.pointers.length;this.pointers.splice(e,1),this.listeners.forEach(r=>r({event:"cancel",pointer:i,pointers:this.pointers,lastPointerLen:n}))});this.elm=t??document,e&&(this.listeners=e),this.startListeners()}startListeners(){this.elm.addEventListener("pointerdown",this.onPointerDown),this.elm.addEventListener("pointermove",this.onPointerMove),document.addEventListener("pointerup",this.onPointerUp),document.addEventListener("pointercancel",this.onPointerCancel)}removeListeners(){this.elm.removeEventListener("pointerdown",this.onPointerDown),this.elm.removeEventListener("pointermove",this.onPointerMove),document.removeEventListener("pointerup",this.onPointerUp),document.removeEventListener("pointercancel",this.onPointerCancel),this.pointers=[]}addEventListener(t){this.listeners.push(t)}removeEventListener(t){this.listeners=this.listeners.filter(e=>e!==t)}getPointerDistance(t,e){const i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)}getCentroid(){if(this.pointers.length===0)return null;const t=this.pointers.reduce((e,i)=>(e.x+=i.x,e.y+=i.y,e),{x:0,y:0});return{x:t.x/this.pointers.length,y:t.y/this.pointers.length}}}class et{constructor(t,e){h(this,"maxZoomLevel");h(this,"image",null);h(this,"rect",null);h(this,"initialCenter",{x:0,y:0});h(this,"maxDimension",{width:0});h(this,"minDimension",{initialWidth:0,initialHeight:0,minWidth:0,closingWidth:0});h(this,"accumulatedTranslate",{x:0,y:0});h(this,"scale",1);h(this,"translate",{x:0,y:0});h(this,"onScale",null);h(this,"animationTimestamp",0);this.maxZoomLevel=t,this.onScale=e}clean(){this.image&&(this.image.style.transform="",this.image.style.width="",this.image.style.height="",this.image.style.top="",this.image.style.left="",this.image.style.opacity="")}reset(){this.clean(),this.image=null,this.rect=null,this.initialCenter={x:window.innerWidth/2,y:window.innerHeight/2},this.maxDimension={width:0},this.minDimension={initialWidth:0,initialHeight:0,minWidth:0,closingWidth:0},this.accumulatedTranslate={x:0,y:0},this.scale=1,this.translate={x:0,y:0}}setCurrentImage(t){if(this.rect=null,this.image=t,this.maxDimension={width:t.naturalWidth*this.maxZoomLevel},!t.dataset.vvwWidth||!t.dataset.vvwHeight)throw new Error("VistaImageState: Image dataset vvwWidth or vvwHeight not set.");const e=parseFloat(t.dataset.vvwWidth),i=parseFloat(t.dataset.vvwHeight);this.minDimension={initialWidth:e,initialHeight:i,minWidth:e*.1,closingWidth:e*.5},this.accumulatedTranslate={x:0,y:0}}setInitialCenter(t){this.initialCenter=t||{x:window.innerWidth/2,y:window.innerHeight/2}}move(t){this.image&&(this.rect||(this.rect=this.image.getBoundingClientRect()),this.translate.x=I(t.x-this.initialCenter.x),this.translate.y=I(t.y-this.initialCenter.y),this.image.style.transform=`translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`)}snapToTargetIfClose(t,e,i=1){return Math.abs(t-e)<=i&&(t=e),t}scaleMove(t,e){if(!this.image)return;this.rect||(this.rect=this.image.getBoundingClientRect()),e||(e=this.initialCenter);const i=this.snapToTargetIfClose(N(this.rect.width*t,this.minDimension.minWidth,this.maxDimension.width),this.minDimension.initialWidth);this.onScale&&this.onScale({scale:i/(this.maxDimension.width/this.maxZoomLevel),isMax:i>=this.maxDimension.width,isMin:i<=this.minDimension.initialWidth}),this.scale=I(i/this.rect.width);const n=this.rect.left+this.rect.width/2,r=this.rect.top+this.rect.height/2,a=this.initialCenter.x-n,o=this.initialCenter.y-r,l=a*(1-this.scale),c=o*(1-this.scale),d=e.x-this.initialCenter.x,f=e.y-this.initialCenter.y;this.translate.x=I(l+d),this.translate.y=I(c+f),this.image.style.transform=`translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`,i<=this.minDimension.closingWidth?this.image.style.opacity="0.5":this.image.style.opacity=""}moveAndNormalize(t){let e=0,i=!1;const n=({x:r,y:a})=>{if(i)return;if(Math.abs(r)<.001&&Math.abs(a)<.001)return this.normalize();r*=.9,a*=.9;const o=this.image.getBoundingClientRect();this.translate.x=I(this.translate.x+r),this.translate.y=I(this.translate.y+a),o.right<window.innerWidth/2&&(this.translate.x+=(window.innerWidth/2-o.right)*.1,r*=.7),o.left>window.innerWidth/2&&(this.translate.x-=(o.left-window.innerWidth/2)*.1,r*=.7),o.bottom<window.innerHeight/2&&(this.translate.y+=(window.innerHeight/2-o.bottom)*.1,a*=.7),o.top>window.innerHeight/2&&(this.translate.y-=(o.top-window.innerHeight/2)*.1,a*=.7),this.image.style.transform=`translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`,e=requestAnimationFrame(()=>n({x:r,y:a}))};return n({x:t.movementX,y:t.movementY}),()=>{i=!0,cancelAnimationFrame(e),this.normalize(!1)}}animateZoom(t){if(!this.image)return;this.rect||(this.rect=this.image.getBoundingClientRect());const e=Date.now(),i=this.image;this.rect.width*t<this.minDimension.closingWidth||i.width<Math.floor(this.minDimension.initialWidth)||(i.addEventListener("transitionend",()=>{this.animationTimestamp===e&&i&&(i.style.transition="",this.normalize())},{once:!0}),i.style.transition||(i.style.transition="all 222ms ease"),this.animationTimestamp=e,this.scaleMove(t))}normalize(t=!0){if(!this.image||!this.rect)return;const e=this.rect.width*this.scale,i=e<=this.minDimension.closingWidth,n=i?e:this.snapToTargetIfClose(this.rect.width*this.scale,this.minDimension.initialWidth),r=i?this.rect.height*this.scale:this.snapToTargetIfClose(this.rect.height*this.scale,this.minDimension.initialHeight);if(this.image.style.width=`${n}px`,this.image.style.height=`${r}px`,this.scale=1,this.image.style.opacity="",this.accumulatedTranslate.x+=this.translate.x,this.accumulatedTranslate.y+=this.translate.y,this.image.style.left=`calc(50% + ${this.accumulatedTranslate.x}px)`,this.image.style.top=`calc(50% + ${this.accumulatedTranslate.y}px)`,this.translate={x:0,y:0},this.image.style.transform="",this.rect=this.image.getBoundingClientRect(),i)return!0;if(n<this.minDimension.initialWidth)this.accumulatedTranslate.x=0,this.accumulatedTranslate.y=0,requestAnimationFrame(()=>{const a=this.image;a&&(a.addEventListener("transitionend",()=>{a&&(this.clean(),this.rect=null)},{once:!0}),a.style.transition="all 222ms ease",a.style.width=`${this.minDimension.initialWidth}px`,a.style.height=`${this.minDimension.initialHeight}px`,a.style.left="50%",a.style.top="50%")});else if(t){let a=!1;if(this.rect.right<window.innerWidth/2&&(a=!0,this.accumulatedTranslate.x+=window.innerWidth/2-this.rect.right),this.rect.left>window.innerWidth/2&&(a=!0,this.accumulatedTranslate.x-=this.rect.left-window.innerWidth/2),this.rect.bottom<window.innerHeight/2&&(a=!0,this.accumulatedTranslate.y+=window.innerHeight/2-this.rect.bottom),this.rect.top>window.innerHeight/2&&(a=!0,this.accumulatedTranslate.y-=this.rect.top-window.innerHeight/2),a){const o=this.image;o.addEventListener("transitionend",()=>{o&&(o.style.transition="",this.rect=null)},{once:!0}),o.style.transition="all 222ms ease",o.style.left=`calc(50% + ${this.accumulatedTranslate.x}px)`,o.style.top=`calc(50% + ${this.accumulatedTranslate.y}px)`}else this.rect=null}}}class it{constructor(){h(this,"fiolast",{})}fio(t,e,i=50){const r=Date.now()-(this.fiolast[e]??0),a=()=>{this.fiolast[e]=Date.now(),t()};if(!this.fiolast[e]){a();return}r>=i&&a()}}const C={somethingOpened:null};class nt{constructor(t,e={}){h(this,"options");h(this,"elements");h(this,"isReducedMotion");h(this,"currentIndex",-1);h(this,"currentChildren",null);h(this,"setupFunction",z);h(this,"initFunction",q);h(this,"closeFunction",k);h(this,"transitionFunction",O);h(this,"pointers",null);h(this,"imageState");h(this,"imageTransitions",new Map);h(this,"root",null);h(this,"imageContainer",null);h(this,"onClickElements",t=>{t.preventDefault();const e=t.currentTarget;e.dataset.vistaIdx&&this.open(parseInt(e.dataset.vistaIdx))});h(this,"defaultOnClickHandler",t=>t.preventDefault());h(this,"abortController",null);h(this,"throttle",new it);h(this,"lastSwapTime",0);h(this,"isRapidSwap",!1);h(this,"isRapidSwapRelease",0);h(this,"transitionCleanup",null);h(this,"isZoomedIn",!1);h(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}});h(this,"onScroll",t=>{t.preventDefault();const e=t.deltaY;this.imageState.setInitialCenter({x:t.clientX,y:t.clientY}),e<0?this.zoomIn():e>0&&this.zoomOut()});h(this,"onResizeHandler",()=>{this.currentChildren.htmls.forEach((t,e)=>{const i=this.currentChildren.images[e],n=t.querySelector("img.vvw-img-hi"),r=t.querySelector("img.vvw-img-lo");if(P(i,n,r,!1),n.classList.contains("vvw--loaded")){const{width:a,height:o}=F(n);n.style.setProperty("--vvw-current-w",`${a}px`),n.style.setProperty("--vvw-current-h",`${o}px`),n.dataset.vvwWidth=a.toString(),n.dataset.vvwHeight=o.toString()}})});h(this,"pointerListeners",[]);h(this,"getInternalPointerListener",()=>{const t=this.imageState;let e=0,i=!1,n=0;const r=33;let a=()=>{};function o(){return i||performance.now()-n<r}return l=>{if(l.event==="down"){if(a(),this.isZoomedIn&&l.pointers.length===1&&!o()){const c=this.pointers.getCentroid();t.setInitialCenter(c)}if(l.pointers.length>=2){i=!0;const c=this.pointers.getCentroid();e=this.pointers.getPointerDistance(l.pointers[0],l.pointers[1]),t.setInitialCenter(c)}}else if(l.event==="move"){if(this.isZoomedIn&&l.pointers.length===1&&l.lastPointerLen===0&&!o()){const c=this.pointers.getCentroid();t.move(c)}if(l.pointers.length>=2&&i){const c=this.pointers.getCentroid(),d=this.pointers.getPointerDistance(l.pointers[0],l.pointers[1]);t.scaleMove(d/e,c)}}else(l.event==="up"||l.event==="cancel")&&(i||this.isZoomedIn)&&(i?(n=performance.now(),i=!1,t.normalize()&&requestAnimationFrame(()=>{this.close()})):this.isZoomedIn&&l.pointers.length===0&&!o()&&(a=t.moveAndNormalize(l.pointer)));this.pointerListeners.forEach(c=>c({...l,hasInternalExecution:this.isZoomedIn||o(),abortController:this.abortController}))}});this.elements=t,this.options={...M,...e,controls:{...M.controls,...e.controls}},this.imageState=new et(this.options.maxZoomLevel,i=>{var n,r,a,o;i.isMin?(this.isZoomedIn=!1,(n=this.qs(".vvw-zoom-out"))==null||n.setAttribute("disabled","true")):(this.isZoomedIn=!0,(r=this.qs(".vvw-zoom-out"))==null||r.removeAttribute("disabled")),i.isMax?(a=this.qs(".vvw-zoom-in"))==null||a.setAttribute("disabled","true"):(o=this.qs(".vvw-zoom-in"))==null||o.removeAttribute("disabled")}),this.options.setupFunction&&(this.setupFunction=this.options.setupFunction),this.options.closeFunction&&(this.closeFunction=this.options.closeFunction),this.options.initFunction&&(this.initFunction=this.options.initFunction),this.options.transitionFunction&&(this.transitionFunction=this.options.transitionFunction),this.isReducedMotion=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.elements instanceof NodeList&&this.elements.forEach((i,n)=>{i.dataset.vistaIdx=n.toString(),i.addEventListener("click",this.defaultOnClickHandler),i.addEventListener("pointerup",this.onClickElements)})}qs(t){return this.root?this.root.querySelector(t):null}async swap(t,e){const i=this.options.preloads||0,n=this.currentIndex,{htmls:r,images:a}=this.getChildElements(i,n),o=this.imageContainer,l=this.currentChildren,c={htmlElements:{from:l.htmls,to:r},images:{from:l.images,to:a},index:{from:t,to:this.currentIndex},via:e||{next:!1,prev:!1},vistaView:this};this.setupFunction(c),this.currentChildren={htmls:r,images:a},this.displayActiveIndex();const d=this.abortController.signal,L=performance.now()-this.lastSwapTime<this.options.rapidLimit;if(this.isRapidSwap=L,o.querySelectorAll(".vvw-item img.vvw-img-hi").forEach(b=>b.classList.add("vvw--load-cancelled")),L){this.imageState.reset(),o.innerHTML="",this.transitionCleanup&&this.transitionCleanup(),r.forEach(b=>{o.appendChild(b)}),this.lastSwapTime=performance.now(),this.waitForImagesToLoad(),this.options.onImageView&&this.options.onImageView(c),this.isRapidSwapRelease&&clearTimeout(this.isRapidSwapRelease),this.isRapidSwapRelease=setTimeout(()=>{this.isRapidSwap=!1},333);return}const y=this.transitionFunction(c,d);y&&(this.transitionCleanup=y.cleanup,await y.transitionEnded),this.lastSwapTime=performance.now();const m=r[Math.floor(r.length/2)].dataset.vvwIdx,u=o.querySelector(`.vvw-item[data-vvw-idx="${m}"] img.vvw-img-hi`),E=this.imageTransitions.get(u);this.imageTransitions.delete(u);const x=u.getAttribute("style")||"",p=u.classList.contains("vvw--loaded"),S=u.classList.contains("vvw--ready"),T=u.width,H=u.height;this.imageState.reset(),o.innerHTML="",this.transitionCleanup&&this.transitionCleanup(),r.forEach(b=>{const g=b.querySelector("img.vvw-img-hi");b.dataset.vvwPos==="0"&&!d.aborted&&x&&T&&H&&(p&&(g.classList.add("vvw--loaded"),g.dataset.vvwWidth=u.dataset.vvwWidth||"",g.dataset.vvwHeight=u.dataset.vvwHeight||""),S&&(g.classList.add("vvw--ready"),g.width=T,g.height=H),g.setAttribute("style",x)),o.appendChild(b),b.dataset.vvwPos==="0"&&!d.aborted&&S?(this.imageState.setCurrentImage(g),this.imageState.setInitialCenter()):b.dataset.vvwPos==="0"&&!d.aborted&&x&&T&&H&&p&&E&&(this.imageTransitions.set(g,E),this.transitionImage(g,()=>{this.imageState.setCurrentImage(g),this.imageState.setInitialCenter(),g.classList.add("vvw--ready")}))}),this.isRapidSwap=!1,this.waitForImagesToLoad(),this.options.onImageView&&this.options.onImageView(c)}getChildElements(t,e){const i=[],n=[];for(let r=-t;r<=t;r++){const a=(e+r+this.elements.length)%this.elements.length,o=this.elements[a],l=o instanceof HTMLImageElement?o:o instanceof HTMLAnchorElement&&o.querySelector("img")||void 0,c=o instanceof HTMLElement?{index:a,imageElm:l instanceof HTMLImageElement?l:void 0,anchorElm:o instanceof HTMLAnchorElement?o:void 0,src:o.dataset.vistaviewSrc||o.getAttribute("href")||o.getAttribute("src")||"",thumb:o.dataset.vistaviewThumb||(l instanceof HTMLImageElement?l.getAttribute("src"):void 0)||o.getAttribute("href")||void 0,alt:l instanceof HTMLImageElement&&l.getAttribute("alt")||void 0}:{index:a,...o};n.push(c),i.push(G(c,r))}return{htmls:i,images:n}}zoomIn(){this.throttle.fio(()=>{this.imageState.animateZoom(1.68)},"zoom",222)}zoomOut(){this.throttle.fio(()=>{this.imageState.animateZoom(.68)},"zoom",222)}displayActiveIndex(){var a;const t=this.currentIndex;this.elements instanceof NodeList&&this.elements.forEach((o,l)=>{o.style.opacity="",l===t&&(o.style.opacity="0")});const e=this.qs(".vvw-index"),i=`${t+1}`,n=`${this.elements.length}`;e&&(e.textContent=`${i} / ${n}`);const r=this.qs(".vvw-desc");if(r){const o=(a=this.currentChildren)==null?void 0:a.images.find(c=>c.index===t),l=(o==null?void 0:o.alt)||"";l?(r.textContent=l,r.setAttribute("aria-label",`Image ${i} of ${n}: ${l}`)):(r.textContent="",r.setAttribute("aria-label",`Image ${i} of ${n}`))}}transitionImage(t,e){if(t.classList.contains("vvw--load-cancelled"))return;if(this.isRapidSwap){requestAnimationFrame(()=>{this.transitionImage(t,e)});return}const i=this.imageTransitions.get(t);i&&requestAnimationFrame(()=>{if(t.classList.contains("vvw--load-cancelled"))return;const{current:n,target:r}=i,a={width:n.width+(r.width-n.width)*.2,height:n.height+(r.height-n.height)*.2,radius:n.radius+(r.radius-n.radius)*.2};Math.abs(a.width-r.width)<1&&Math.abs(a.height-r.height)<1&&Math.abs(a.radius-r.radius)<1?(t.style.setProperty("--vvw-current-w",`${r.width}px`),t.style.setProperty("--vvw-current-h",`${r.height}px`),t.style.setProperty("--vvw-current-radius",`${r.radius}px`),this.imageTransitions.delete(t),e()):(t.style.setProperty("--vvw-current-w",`${a.width}px`),t.style.setProperty("--vvw-current-h",`${a.height}px`),t.style.setProperty("--vvw-current-radius",`${a.radius}px`),this.imageTransitions.set(t,{current:a,target:r}),this.transitionImage(t,e))})}waitForImagesToLoad(){this.imageContainer.querySelectorAll("img.vvw-img-hi:not(.vvw--loaded)").forEach(i=>{const n=i;if(n.classList.contains("vvw--load-cancelled"))return;const r=()=>{if(n.classList.contains("vvw--load-cancelled"))return;n.width=n.naturalWidth,n.height=n.naturalHeight;const{width:a,height:o}=F(n);n.dataset.vvwWidth=a.toString(),n.dataset.vvwHeight=o.toString(),n.classList.add("vvw--loaded"),this.imageTransitions.set(n,{current:{width:n.style.getPropertyValue("--vvw-current-w")?parseFloat(n.style.getPropertyValue("--vvw-current-w")):0,height:n.style.getPropertyValue("--vvw-current-h")?parseFloat(n.style.getPropertyValue("--vvw-current-h")):0,radius:n.style.getPropertyValue("--vvw-current-radius")?parseFloat(n.style.getPropertyValue("--vvw-current-radius")):0},target:{width:a,height:o,radius:0}}),this.transitionImage(n,()=>{var c;if(n.classList.contains("vvw--load-cancelled"))return;((c=n.parentElement)==null?void 0:c.matches(`[data-vvw-idx="${this.currentIndex}"][data-vvw-pos="0"]`))&&(this.imageState.setCurrentImage(n),this.imageState.setInitialCenter()),n.classList.add("vvw--ready")})};if(n.complete&&n.naturalWidth!==0){r();return}n.addEventListener("load",()=>{r()}),n.addEventListener("error",()=>{var o;n.classList.add("vvw--loaderror");const a=document.createElement("p");a.className="vvw-img-err",a.setAttribute("role","alert"),a.textContent="Error loading image",(o=n.parentNode)==null||o.appendChild(a)})})}registerPointerListener(t){this.pointerListeners.push(t)}unregisterPointerListeners(){this.pointerListeners=[]}open(t=0){var c,d,f,L,y;if(C.somethingOpened)return;C.somethingOpened=this,this.currentIndex=t,document.body.style.overflow="hidden";const e=J({controls:this.options.controls});if(document.body.prepend(e),this.root=document.body.querySelector("#vvw-root"),!this.root)throw new Error("Failed to setup VistaView root element.");this.imageContainer=this.qs(".vvw-image-container"),this.options.animationDurationBase&&this.root.style.setProperty("--vvw-anim-dur",`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.root.style.setProperty("--vvw-init-z",`${this.options.initialZIndex??0}`),this.options.arrowOnSmallScreens&&this.root.classList.add("vvw-arrow-sm");const i=this.options.preloads||0,n=t,{images:r,htmls:a}=this.getChildElements(i,n),o={htmlElements:{from:null,to:a},images:{from:null,to:r},index:{from:null,to:this.currentIndex},via:{next:!1,prev:!1},vistaView:this};this.setupFunction(o),this.currentChildren={htmls:a,images:r},a.forEach(m=>{this.imageContainer.appendChild(m)}),(c=this.qs(".vvw-close"))==null||c.addEventListener("click",()=>this.close()),(d=this.qs(".vvw-zoom-in"))==null||d.addEventListener("click",()=>this.zoomIn()),(f=this.qs(".vvw-zoom-out"))==null||f.addEventListener("click",()=>this.zoomOut()),(L=this.qs(".vvw-prev>button"))==null||L.addEventListener("click",()=>this.prev()),(y=this.qs(".vvw-next>button"))==null||y.addEventListener("click",()=>this.next()),this.options.keyboardListeners&&window.addEventListener("keydown",this.onKeyDown),window.addEventListener("wheel",this.onScroll,{passive:!1}),window.addEventListener("resize",this.onResizeHandler),this.pointers=new tt({elm:this.imageContainer,listeners:[this.getInternalPointerListener()]});const l={};[...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(m=>{typeof m!="string"&&(l[m.name]=m)}),this.root.querySelectorAll("button[data-vvw-control]").forEach(m=>{const u=m;u.addEventListener("click",E=>{const x=E.currentTarget.dataset.vvwControl,p=l[x],S=this.currentChildren.images.find(T=>T.index===this.currentIndex);p&&S&&(p.onClick.constructor.name==="AsyncFunction"?(u.classList.add("vvw--loading"),p.onClick(S,this).finally(()=>{u.classList.remove("vvw--loading")})):p.onClick(S,this))})}),this.initFunction(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{var m;(m=this.root)==null||m.addEventListener("transitionend",()=>{var u;(u=this.root)==null||u.classList.add("vvw--settled"),this.imageState.reset(),this.waitForImagesToLoad()},{once:!0}),this.root.classList.add("vvw--active"),this.displayActiveIndex(),this.options.onOpen&&this.options.onOpen(this),this.options.onImageView&&this.options.onImageView(o)})})}async close(t=!0){C.somethingOpened===this&&this.root&&(t?await new Promise(e=>{let n=0;this.root.addEventListener("transitionend",r=>{r.target===this.root&&(n++,n===2&&this.elements instanceof NodeList&&this.elements.forEach(a=>{a.style.opacity=""}),n===3&&e(null))}),this.root.classList.add("vvw--closing")}):this.elements instanceof NodeList&&this.elements.forEach(e=>{e.style.opacity=""}),this.options.keyboardListeners&&window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("resize",this.onResizeHandler),window.removeEventListener("wheel",this.onScroll),this.unregisterPointerListeners(),this.pointers.removeListeners(),this.root.remove(),this.root=null,this.imageContainer=null,this.currentChildren=null,this.currentIndex=-1,document.body.style.overflow="",C.somethingOpened=null,this.closeFunction(this),this.options.onClose&&this.options.onClose(this))}next(){if(C.somethingOpened!==this)return;const t=(this.currentIndex+1)%this.elements.length;this.view(t,{next:!0,prev:!1})}prev(){if(C.somethingOpened!==this)return;const t=(this.currentIndex-1+this.elements.length)%this.elements.length;this.view(t,{next:!1,prev:!0})}destroy(){this.close(!1),this.elements instanceof NodeList&&this.elements.forEach(t=>{t.removeAttribute("data-vista-idx"),t.removeEventListener("click",this.defaultOnClickHandler),t.removeEventListener("pointerup",this.onClickElements)})}getCurrentIndex(){return C.somethingOpened!==this?-1:this.currentIndex}view(t,e){if(C.somethingOpened!==this||t<0||t>=this.elements.length)return;const i=this.currentIndex;this.currentIndex=t;const n=this.abortController;n==null||n.abort(),this.abortController=new AbortController,this.swap(i,e)}}function st(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let e=0;e<t.length;e++){const i=t[e];if(!(i.dataset.vistaviewSrc||i.getAttribute("href")||i.getAttribute("src")||""))return`Element at index ${e} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const e=s;for(let i=0;i<e.length;i++)if(!e[i].src)return`Element at index ${i} is missing 'src' attribute.`}return t||s}function ot({elements:s,...t}){if(!s)throw new Error("No elements");let e=st(s);if(typeof e=="string")return null;const i=new nt(e,t);return{open:(n=0)=>i.open(n),close:()=>i.close(),next:()=>i.next(),prev:()=>i.prev(),destroy:()=>i.destroy(),getCurrentIndex:()=>i.getCurrentIndex(),view:n=>{i.view(n)}}}v.DefaultOptions=M,v.close=k,v.init=q,v.setup=z,v.transition=O,v.vistaView=ot,v.vistaViewDownload=R,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|