vistaview 0.6.2 → 0.6.4

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.
@@ -27,6 +27,7 @@ export declare class VistaImageState {
27
27
  x: number;
28
28
  y: number;
29
29
  }): void;
30
+ private snapToTargetIfClose;
30
31
  scaleMove(ratio: number, center?: {
31
32
  x: number;
32
33
  y: number;
@@ -1 +1 @@
1
- {"version":3,"file":"image-state.d.ts","sourceRoot":"","sources":["../../src/lib/image-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,qBAAa,eAAe;IAC1B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,aAAa,CAA4C;IACjE,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,YAAY,CAAuE;IAC3F,OAAO,CAAC,oBAAoB,CAAkB;IAG9C,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,OAAO,CAA4D;gBAE/D,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,0BAA0B,KAAK,IAAI;IAKpF,KAAK;IAUL,KAAK;IAYL,eAAe,CAAC,KAAK,EAAE,gBAAgB;IAsBvC,gBAAgB,CAAC,MAAM,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;IAIlD,IAAI,CAAC,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;IAcrC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;IAyE1D,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,IAAI;IAsDnD,OAAO,CAAC,kBAAkB,CAAa;IACvC,WAAW,CAAC,WAAW,EAAE,MAAM;IA+B/B,SAAS,CAAC,UAAU,GAAE,OAAc,GAAG,OAAO,GAAG,IAAI;CAoGtD"}
1
+ {"version":3,"file":"image-state.d.ts","sourceRoot":"","sources":["../../src/lib/image-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,qBAAa,eAAe;IAC1B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,aAAa,CAA4C;IACjE,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,YAAY,CAAuE;IAC3F,OAAO,CAAC,oBAAoB,CAAkB;IAG9C,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,OAAO,CAA4D;gBAE/D,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,0BAA0B,KAAK,IAAI;IAKpF,KAAK;IAUL,KAAK;IAYL,eAAe,CAAC,KAAK,EAAE,gBAAgB;IAsBvC,gBAAgB,CAAC,MAAM,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;IAIlD,IAAI,CAAC,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;IAcrC,OAAO,CAAC,mBAAmB;IAO3B,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;IA0D1D,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,IAAI;IAqDnD,OAAO,CAAC,kBAAkB,CAAa;IACvC,WAAW,CAAC,WAAW,EAAE,MAAM;IA+B/B,SAAS,CAAC,UAAU,GAAE,OAAc,GAAG,OAAO,GAAG,IAAI;CAsGtD"}
package/dist/vistaview.js CHANGED
@@ -1,33 +1,33 @@
1
- var T = Object.defineProperty;
2
- var z = (s, t, e) => t in s ? T(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var l = (s, t, e) => z(s, typeof t != "symbol" ? t + "" : t, e);
1
+ var W = Object.defineProperty;
2
+ var A = (s, t, e) => t in s ? W(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var l = (s, t, e) => A(s, typeof t != "symbol" ? t + "" : t, e);
4
4
  function $(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 A(s) {
8
- const e = window.getComputedStyle(s).objectFit || "", { width: n, height: i } = s.getBoundingClientRect(), o = s.naturalWidth, a = s.naturalHeight;
7
+ function F(s) {
8
+ const e = window.getComputedStyle(s).objectFit || "", { width: i, height: n } = s.getBoundingClientRect(), o = s.naturalWidth, a = s.naturalHeight;
9
9
  if (!e)
10
- return { width: n, height: i };
10
+ return { width: i, height: n };
11
11
  if (!o || !a)
12
- return { width: n, height: i };
13
- const r = o / a, h = n / i;
12
+ return { width: i, height: n };
13
+ const r = o / a, h = i / n;
14
14
  switch (e) {
15
15
  case "fill":
16
- return { width: n, height: i };
16
+ return { width: i, height: n };
17
17
  case "none":
18
18
  return { width: o, height: a };
19
19
  case "contain":
20
- return r > h ? { width: n, height: n / r } : { width: i * r, height: i };
20
+ return r > h ? { width: i, height: i / r } : { width: n * r, height: n };
21
21
  case "cover":
22
- return r < h ? { width: n, height: n / r } : { width: i * r, height: i };
22
+ return r < h ? { width: i, height: i / r } : { width: n * r, height: n };
23
23
  case "scale-down": {
24
- const c = { width: o, height: a }, m = r > h ? { width: n, height: n / r } : { width: i * r, height: i };
24
+ const c = { width: o, height: a }, m = r > h ? { width: i, height: i / r } : { width: n * r, height: n };
25
25
  return m.width <= c.width && m.height <= c.height ? m : c;
26
26
  }
27
27
  }
28
- return { width: n, height: i };
28
+ return { width: i, height: n };
29
29
  }
30
- function S(s) {
30
+ function D(s) {
31
31
  const t = getComputedStyle(s), e = s.getBoundingClientRect();
32
32
  return {
33
33
  objectFit: t.objectFit,
@@ -42,13 +42,13 @@ function S(s) {
42
42
  naturalHeight: s.naturalHeight
43
43
  };
44
44
  }
45
- function F(s) {
46
- const t = s.imageElm ? S(s.imageElm) : null, e = s.anchorElm ? S(s.anchorElm) : null, n = $(t == null ? void 0 : t.borderRadius), i = e && $(e == null ? void 0 : e.borderRadius), o = (i ? e == null ? void 0 : e.borderRadius : n ? t == null ? void 0 : t.borderRadius : "") || "";
45
+ function P(s) {
46
+ const t = s.imageElm ? D(s.imageElm) : null, e = s.anchorElm ? D(s.anchorElm) : null, i = $(t == null ? void 0 : t.borderRadius), n = e && $(e == null ? void 0 : e.borderRadius), o = (n ? e == null ? void 0 : e.borderRadius : i ? t == null ? void 0 : t.borderRadius : "") || "";
47
47
  return {
48
48
  fit: (t == null ? void 0 : t.objectFit) || (e == null ? void 0 : e.objectFit) || "",
49
49
  pos: (t == null ? void 0 : t.objectPosition) || "",
50
50
  br: o,
51
- overflow: i ? e.overflow : n ? t.overflow : "",
51
+ overflow: n ? e.overflow : i ? t.overflow : "",
52
52
  nw: (t == null ? void 0 : t.naturalWidth) || 0,
53
53
  nh: (t == null ? void 0 : t.naturalHeight) || 0,
54
54
  w: (e == null ? void 0 : e.width) || (t == null ? void 0 : t.width) || 0,
@@ -57,9 +57,9 @@ function F(s) {
57
57
  left: (e == null ? void 0 : e.left) || (t == null ? void 0 : t.left) || 0
58
58
  };
59
59
  }
60
- function M(s, t, e, n = !1) {
60
+ function H(s, t, e, i = !1) {
61
61
  const {
62
- fit: i,
62
+ fit: n,
63
63
  w: o,
64
64
  h: a,
65
65
  // this ones makes things hard. not used.
@@ -70,31 +70,31 @@ function M(s, t, e, n = !1) {
70
70
  br: c,
71
71
  top: m,
72
72
  left: w
73
- } = F(s), b = Math.min(Math.max(w, -o), window.innerWidth + o) - window.innerWidth / 2 + o / 2, p = Math.min(Math.max(m, -a), window.innerHeight + a) - window.innerHeight / 2 + a / 2, d = e.style;
74
- d.width = `${o}px`, d.height = `${a}px`, d.objectFit = i, e.width = r, e.height = h, d.setProperty("--vvw-init-radius", `${c}`), d.setProperty("--vvw-pulse-radius", `calc(1.3 * ${c})`), d.setProperty("--vvw-init-x", `${b}px`), d.setProperty("--vvw-init-y", `${p}px`), n && (d.setProperty("--vvw-current-x", `${b}px`), d.setProperty("--vvw-current-y", `${p}px`));
75
- const v = A(s.imageElm), g = Math.min(o, v.width), f = Math.min(a, v.height), u = t.style;
76
- u.setProperty("--vvw-init-radius", `${c}`), u.setProperty("--vvw-init-w", `${g}px`), u.setProperty("--vvw-init-h", `${f}px`), n && (u.setProperty("--vvw-current-radius", `${c}`), u.setProperty("--vvw-current-w", `${g}px`), u.setProperty("--vvw-current-h", `${f}px`), t.dataset.vvwWidth = g.toString(), t.dataset.vvwHeight = f.toString());
73
+ } = P(s), b = Math.min(Math.max(w, -o), window.innerWidth + o) - window.innerWidth / 2 + o / 2, p = Math.min(Math.max(m, -a), window.innerHeight + a) - window.innerHeight / 2 + a / 2, d = e.style;
74
+ d.width = `${o}px`, d.height = `${a}px`, d.objectFit = n, e.width = r, e.height = h, d.setProperty("--vvw-init-radius", `${c}`), d.setProperty("--vvw-pulse-radius", `calc(1.3 * ${c})`), d.setProperty("--vvw-init-x", `${b}px`), d.setProperty("--vvw-init-y", `${p}px`), i && (d.setProperty("--vvw-current-x", `${b}px`), d.setProperty("--vvw-current-y", `${p}px`));
75
+ const v = F(s.imageElm), g = Math.min(o, v.width), f = Math.min(a, v.height), u = t.style;
76
+ u.setProperty("--vvw-init-radius", `${c}`), u.setProperty("--vvw-init-w", `${g}px`), u.setProperty("--vvw-init-h", `${f}px`), i && (u.setProperty("--vvw-current-radius", `${c}`), u.setProperty("--vvw-current-w", `${g}px`), u.setProperty("--vvw-current-h", `${f}px`), t.dataset.vvwWidth = g.toString(), t.dataset.vvwHeight = f.toString());
77
77
  }
78
- function D(s) {
79
- const t = window.innerWidth, e = window.innerHeight, n = s.naturalWidth, i = s.naturalHeight;
80
- if (!n || !i)
78
+ function S(s) {
79
+ const t = window.innerWidth, e = window.innerHeight, i = s.naturalWidth, n = s.naturalHeight;
80
+ if (!i || !n)
81
81
  throw new Error("Image natural dimensions are zero");
82
- if (n < t && i < e)
82
+ if (i < t && n < e)
83
83
  return {
84
- width: n,
85
- height: i
84
+ width: i,
85
+ height: n
86
86
  };
87
- const o = n / i, a = t / e;
87
+ const o = i / n, a = t / e;
88
88
  let r, h;
89
89
  return o > a ? (r = t, h = t / o) : (h = e, r = e * o), {
90
90
  width: r,
91
91
  height: h
92
92
  };
93
93
  }
94
- function P(s, t, e) {
94
+ function z(s, t, e) {
95
95
  return Math.min(Math.max(s, t), e);
96
96
  }
97
- function C(s, t = 2) {
97
+ function L(s, t = 2) {
98
98
  const e = Math.pow(10, t);
99
99
  return Math.round(s * e) / e;
100
100
  }
@@ -114,11 +114,11 @@ function X() {
114
114
  }
115
115
  }), I);
116
116
  }
117
- function W(s) {
118
- const e = X().createHTML(s), n = document.createElement("template");
119
- n.innerHTML = e;
120
- const i = n.content;
121
- return n.remove(), i;
117
+ function M(s) {
118
+ const e = X().createHTML(s), i = document.createElement("template");
119
+ i.innerHTML = e;
120
+ const n = i.content;
121
+ return i.remove(), n;
122
122
  }
123
123
  function N() {
124
124
  return {
@@ -126,8 +126,8 @@ function N() {
126
126
  icon: Y,
127
127
  onClick: async (s) => {
128
128
  var o;
129
- const t = await fetch(s.src), e = await t.blob(), n = t.url, i = document.createElement("a");
130
- i.href = URL.createObjectURL(e), i.download = ((o = n.split("/").pop()) == null ? void 0 : o.split("?")[0].split("#")[0]) || "download", document.body.appendChild(i), i.click(), document.body.removeChild(i);
129
+ const t = await fetch(s.src), e = await t.blob(), i = t.url, n = document.createElement("a");
130
+ n.href = URL.createObjectURL(e), n.download = ((o = i.split("/").pop()) == null ? void 0 : o.split("?")[0].split("#")[0]) || "download", document.body.appendChild(n), n.click(), document.body.removeChild(n);
131
131
  }
132
132
  };
133
133
  }
@@ -152,19 +152,19 @@ function B(s) {
152
152
  function j(s, t) {
153
153
  const e = document.createElement("div");
154
154
  e.className = "vvw-item", e.dataset.vvwPos = `${t !== void 0 ? t : ""}`, e.dataset.vvwIdx = s.index.toString(), e.appendChild(
155
- W(
155
+ M(
156
156
  `<img class="vvw-img-lo" src="${s.thumb || s.src}" alt="${s.alt || ""}" />
157
157
  <img class="vvw-img-hi" src="${s.src}" alt="${s.alt || ""}" />`
158
158
  )
159
159
  );
160
- const n = e.querySelector("img.vvw-img-lo"), i = e.querySelector("img.vvw-img-hi");
161
- return M(s, i, n, t === 0), e;
160
+ const i = e.querySelector("img.vvw-img-lo"), n = e.querySelector("img.vvw-img-hi");
161
+ return H(s, n, i, t === 0), e;
162
162
  }
163
163
  function U({
164
164
  controls: s
165
165
  }) {
166
- const t = (n) => n ? n.map(B).join("") : "";
167
- return W(
166
+ const t = (i) => i ? i.map(B).join("") : "";
167
+ return M(
168
168
  `<div class="vvw-root" id="vvw-root">
169
169
  <div class="vvw-container">
170
170
  <div class="vvw-bg"></div>
@@ -177,7 +177,7 @@ function U({
177
177
  </div>`
178
178
  );
179
179
  }
180
- const H = {
180
+ const T = {
181
181
  // debug, don't remove
182
182
  // animationDurationBase: 1000,
183
183
  animationDurationBase: 333,
@@ -201,21 +201,21 @@ function _(s) {
201
201
  s.imageContainer.style.width = `${(t * 2 + 1) * 100}vw`, s.imageContainer.style.left = `-${t * 100}vw`, s.imageContainer.style.display = "flex", G(s);
202
202
  }
203
203
  function G(s) {
204
- let t = { x: 0, y: 0 }, e = { x: 0, y: 0 }, n = null;
205
- s.registerPointerListener((i) => {
206
- if (!i.hasInternalExecution && !(i.pointers.length > 1)) {
207
- if (i.event === "down" && (t = { x: i.pointer.x, y: i.pointer.y }, e = { x: i.pointer.x, y: i.pointer.y }), i.event === "move") {
208
- e = { x: i.pointer.x, y: i.pointer.y };
204
+ let t = { x: 0, y: 0 }, e = { x: 0, y: 0 }, i = null;
205
+ s.registerPointerListener((n) => {
206
+ if (!n.hasInternalExecution && !(n.pointers.length > 1)) {
207
+ if (n.event === "down" && (t = { x: n.pointer.x, y: n.pointer.y }, e = { x: n.pointer.x, y: n.pointer.y }), n.event === "move") {
208
+ e = { x: n.pointer.x, y: n.pointer.y };
209
209
  const o = e.x - t.x, a = e.y - t.y;
210
- if (!n && Math.abs(a) > Math.abs(o) || n === "y") {
210
+ if (!i && Math.abs(a) > Math.abs(o) || i === "y") {
211
211
  const r = a / window.innerHeight * 100;
212
- s.imageContainer.style.transition = "none", s.imageContainer.style.transform = `translateY(${r}vh)`, n = "y";
213
- } else if (!n && Math.abs(o) > Math.abs(a) || n === "x") {
212
+ s.imageContainer.style.transition = "none", s.imageContainer.style.transform = `translateY(${r}vh)`, i = "y";
213
+ } else if (!i && Math.abs(o) > Math.abs(a) || i === "x") {
214
214
  const r = o / window.innerWidth * 100;
215
- s.imageContainer.style.transition = "none", s.imageContainer.style.transform = `translateX(${r}vw)`, n = "x";
215
+ s.imageContainer.style.transition = "none", s.imageContainer.style.transform = `translateX(${r}vw)`, i = "x";
216
216
  }
217
217
  }
218
- if (i.event === "up" || i.event === "cancel") {
218
+ if (n.event === "up" || n.event === "cancel") {
219
219
  let o = function(a) {
220
220
  var r;
221
221
  (r = s.imageContainer) == null || r.addEventListener("transitionend", function h() {
@@ -223,15 +223,15 @@ function G(s) {
223
223
  (c = s.imageContainer) == null || c.removeEventListener("transitionend", h), s.imageContainer.style.transition = "", s.imageContainer.style.transform = "";
224
224
  }), s.imageContainer.style.transition = "transform 222ms ease", s.imageContainer.style.transform = a;
225
225
  };
226
- if (n === "y") {
227
- const a = e.y - t.y, r = i.pointer.movementY, h = 8;
226
+ if (i === "y") {
227
+ const a = e.y - t.y, r = n.pointer.movementY, h = 8;
228
228
  s.imageContainer.style.transition = "", a > 0 && Math.abs(r) > h || a < 0 && Math.abs(r) > h ? (s.imageContainer.style.transition = "transform 222ms ease", s.imageContainer.style.transform = "translateY(0vh)", s.close()) : o("translateY(0vh)");
229
229
  }
230
- if (n === "x") {
231
- const a = e.x - t.x, r = i.pointer.movementX, h = 8;
230
+ if (i === "x") {
231
+ const a = e.x - t.x, r = n.pointer.movementX, h = 8;
232
232
  s.imageContainer.style.transition = "", a > 0 && Math.abs(r) > h ? s.prev() : a < 0 && Math.abs(r) > h ? s.next() : o("translateX(0vw)");
233
233
  }
234
- n = null;
234
+ i = null, t = { x: 0, y: 0 }, e = { x: 0, y: 0 };
235
235
  }
236
236
  }
237
237
  });
@@ -241,12 +241,12 @@ function J(s) {
241
241
  async function Q({
242
242
  vistaView: { isReducedMotion: s },
243
243
  htmlElements: { to: t },
244
- index: { from: e, to: n },
245
- vistaView: { elements: i, imageContainer: o, options: a }
244
+ index: { from: e, to: i },
245
+ vistaView: { elements: n, imageContainer: o, options: a }
246
246
  }, r) {
247
- if (!t || r.aborted || s || !(Math.abs(n - e) === 1 || e === 0 && n === i.length - 1 || e === i.length - 1 && n === 0))
247
+ if (!t || r.aborted || s || !(Math.abs(i - e) === 1 || e === 0 && i === n.length - 1 || e === n.length - 1 && i === 0))
248
248
  return;
249
- const c = Math.round(a.animationDurationBase * 1.5 * 100) / 100;
249
+ const c = Math.round(a.animationDurationBase * 100) / 100;
250
250
  return new Promise((m) => {
251
251
  o.addEventListener(
252
252
  "transitionend",
@@ -257,7 +257,7 @@ async function Q({
257
257
  },
258
258
  { once: !0 }
259
259
  );
260
- const w = n === e + 1 || e === i.length - 1 && n === 0 ? "translateX(-100vw)" : "translateX(100vw)";
260
+ const w = i === e + 1 || e === n.length - 1 && i === 0 ? "translateX(-100vw)" : "translateX(100vw)";
261
261
  o.style.transition = `transform ${c}ms ease`, o.style.transform = w;
262
262
  });
263
263
  }
@@ -284,7 +284,7 @@ class V {
284
284
  id: t.pointerId
285
285
  };
286
286
  this.pointers.push(e), this.listeners.forEach(
287
- (n) => n({
287
+ (i) => i({
288
288
  event: "down",
289
289
  pointer: e,
290
290
  pointers: this.pointers,
@@ -295,9 +295,9 @@ class V {
295
295
  l(this, "onPointerMove", (t) => {
296
296
  if (!this.listeners.length) return;
297
297
  t.preventDefault();
298
- const e = this.pointers.find((n) => n.id === t.pointerId);
298
+ const e = this.pointers.find((i) => i.id === t.pointerId);
299
299
  e && (e.movementX = t.movementX, e.movementY = t.movementY, e.x = t.clientX, e.y = t.clientY, this.listeners.forEach(
300
- (n) => n({
300
+ (i) => i({
301
301
  event: "move",
302
302
  pointer: e,
303
303
  pointers: this.pointers,
@@ -311,15 +311,15 @@ class V {
311
311
  t.preventDefault();
312
312
  const e = this.pointers.findIndex((o) => o.id === t.pointerId);
313
313
  if (e === -1) return;
314
- const n = this.pointers[e];
315
- n.x = t.clientX, n.y = t.clientY;
316
- const i = this.pointers.length;
314
+ const i = this.pointers[e];
315
+ i.x = t.clientX, i.y = t.clientY;
316
+ const n = this.pointers.length;
317
317
  this.pointers.splice(e, 1), this.listeners.forEach(
318
318
  (o) => o({
319
319
  event: "up",
320
- pointer: n,
320
+ pointer: i,
321
321
  pointers: this.pointers,
322
- lastPointerLen: i
322
+ lastPointerLen: n
323
323
  })
324
324
  );
325
325
  });
@@ -329,15 +329,15 @@ class V {
329
329
  t.preventDefault();
330
330
  const e = this.pointers.findIndex((o) => o.id === t.pointerId);
331
331
  if (e === -1) return;
332
- const n = this.pointers[e];
333
- n.x = t.clientX, n.y = t.clientY;
334
- const i = this.pointers.length;
332
+ const i = this.pointers[e];
333
+ i.x = t.clientX, i.y = t.clientY;
334
+ const n = this.pointers.length;
335
335
  this.pointers.splice(e, 1), this.listeners.forEach(
336
336
  (o) => o({
337
337
  event: "cancel",
338
- pointer: n,
338
+ pointer: i,
339
339
  pointers: this.pointers,
340
- lastPointerLen: i
340
+ lastPointerLen: n
341
341
  })
342
342
  );
343
343
  });
@@ -356,13 +356,13 @@ class V {
356
356
  this.listeners = this.listeners.filter((e) => e !== t);
357
357
  }
358
358
  getPointerDistance(t, e) {
359
- const n = t.x - e.x, i = t.y - e.y;
360
- return Math.sqrt(n * n + i * i);
359
+ const i = t.x - e.x, n = t.y - e.y;
360
+ return Math.sqrt(i * i + n * n);
361
361
  }
362
362
  getCentroid() {
363
363
  if (this.pointers.length === 0) return null;
364
364
  const t = this.pointers.reduce(
365
- (e, n) => (e.x += n.x, e.y += n.y, e),
365
+ (e, i) => (e.x += i.x, e.y += i.y, e),
366
366
  { x: 0, y: 0 }
367
367
  );
368
368
  return {
@@ -398,10 +398,10 @@ class tt {
398
398
  width: t.naturalWidth * this.maxZoomLevel
399
399
  }, !t.dataset.vvwWidth || !t.dataset.vvwHeight)
400
400
  throw new Error("VistaImageState: Image dataset vvwWidth or vvwHeight not set.");
401
- const e = parseFloat(t.dataset.vvwWidth), n = parseFloat(t.dataset.vvwHeight);
401
+ const e = parseFloat(t.dataset.vvwWidth), i = parseFloat(t.dataset.vvwHeight);
402
402
  this.minDimension = {
403
403
  initialWidth: e,
404
- initialHeight: n,
404
+ initialHeight: i,
405
405
  minWidth: e * 0.1,
406
406
  closingWidth: e * 0.5
407
407
  }, this.accumulatedTranslate = { x: 0, y: 0 };
@@ -410,73 +410,81 @@ class tt {
410
410
  this.initialCenter = t || { x: window.innerWidth / 2, y: window.innerHeight / 2 };
411
411
  }
412
412
  move(t) {
413
- this.image && (this.rect || (this.rect = this.image.getBoundingClientRect()), this.translate.x = C(t.x - this.initialCenter.x), this.translate.y = C(t.y - this.initialCenter.y), this.image.style.transform = `translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`);
413
+ this.image && (this.rect || (this.rect = this.image.getBoundingClientRect()), this.translate.x = L(t.x - this.initialCenter.x), this.translate.y = L(t.y - this.initialCenter.y), this.image.style.transform = `translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`);
414
+ }
415
+ snapToTargetIfClose(t, e, i = 1) {
416
+ return Math.abs(t - e) <= i && (t = e), t;
414
417
  }
415
418
  scaleMove(t, e) {
416
419
  if (!this.image) return;
417
420
  this.rect || (this.rect = this.image.getBoundingClientRect()), e || (e = this.initialCenter);
418
- const n = P(
419
- this.rect.width * t,
420
- this.minDimension.minWidth,
421
- this.maxDimension.width
421
+ const i = this.snapToTargetIfClose(
422
+ z(this.rect.width * t, this.minDimension.minWidth, this.maxDimension.width),
423
+ this.minDimension.initialWidth
422
424
  );
423
425
  this.onScale && this.onScale({
424
- scale: n / (this.maxDimension.width / this.maxZoomLevel),
425
- isMax: n >= this.maxDimension.width,
426
- isMin: n <= this.minDimension.initialWidth
427
- }), this.scale = C(n / this.rect.width);
428
- const i = this.rect.left + this.rect.width / 2, o = this.rect.top + this.rect.height / 2, a = this.initialCenter.x - i, r = this.initialCenter.y - o, h = a * (1 - this.scale), c = r * (1 - this.scale), m = e.x - this.initialCenter.x, w = e.y - this.initialCenter.y;
429
- this.translate.x = C(h + m), this.translate.y = C(c + w), this.image.style.transform = `translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`, n <= this.minDimension.closingWidth ? this.image.style.opacity = "0.5" : this.image.style.opacity = "";
426
+ scale: i / (this.maxDimension.width / this.maxZoomLevel),
427
+ isMax: i >= this.maxDimension.width,
428
+ isMin: i <= this.minDimension.initialWidth
429
+ }), this.scale = L(i / this.rect.width);
430
+ const n = this.rect.left + this.rect.width / 2, o = this.rect.top + this.rect.height / 2, a = this.initialCenter.x - n, r = this.initialCenter.y - o, h = a * (1 - this.scale), c = r * (1 - this.scale), m = e.x - this.initialCenter.x, w = e.y - this.initialCenter.y;
431
+ this.translate.x = L(h + m), this.translate.y = L(c + w), 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 = "";
430
432
  }
431
433
  moveAndNormalize(t) {
432
- let e = 0, n = !1;
433
- const i = ({ x: o, y: a }) => {
434
- if (n)
434
+ let e = 0, i = !1;
435
+ const n = ({ x: o, y: a }) => {
436
+ if (i)
435
437
  return;
436
438
  if (Math.abs(o) < 1e-3 && Math.abs(a) < 1e-3)
437
439
  return this.normalize();
438
440
  o *= 0.9, a *= 0.9;
439
441
  const r = this.image.getBoundingClientRect();
440
- this.translate.x = C(this.translate.x + o), this.translate.y = C(this.translate.y + a), r.right < window.innerWidth / 2 && (this.translate.x += (window.innerWidth / 2 - r.right) * 0.1, o *= 0.7), r.left > window.innerWidth / 2 && (this.translate.x -= (r.left - window.innerWidth / 2) * 0.1, o *= 0.7), r.bottom < window.innerHeight / 2 && (this.translate.y += (window.innerHeight / 2 - r.bottom) * 0.1, a *= 0.7), r.top > window.innerHeight / 2 && (this.translate.y -= (r.top - window.innerHeight / 2) * 0.1, a *= 0.7), this.image.style.transform = `translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`, e = requestAnimationFrame(() => i({ x: o, y: a }));
442
+ this.translate.x = L(this.translate.x + o), this.translate.y = L(this.translate.y + a), r.right < window.innerWidth / 2 && (this.translate.x += (window.innerWidth / 2 - r.right) * 0.1, o *= 0.7), r.left > window.innerWidth / 2 && (this.translate.x -= (r.left - window.innerWidth / 2) * 0.1, o *= 0.7), r.bottom < window.innerHeight / 2 && (this.translate.y += (window.innerHeight / 2 - r.bottom) * 0.1, a *= 0.7), r.top > window.innerHeight / 2 && (this.translate.y -= (r.top - window.innerHeight / 2) * 0.1, a *= 0.7), this.image.style.transform = `translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`, e = requestAnimationFrame(() => n({ x: o, y: a }));
441
443
  };
442
- return i({
444
+ return n({
443
445
  x: t.movementX,
444
446
  y: t.movementY
445
447
  }), () => {
446
- n = !0, cancelAnimationFrame(e), this.normalize(!1);
448
+ i = !0, cancelAnimationFrame(e), this.normalize(!1);
447
449
  };
448
450
  }
449
451
  animateZoom(t) {
450
452
  if (!this.image) return;
451
453
  this.rect || (this.rect = this.image.getBoundingClientRect());
452
- const e = Date.now(), n = this.image;
453
- this.rect.width * t < this.minDimension.closingWidth || n.width < Math.floor(this.minDimension.initialWidth) || (n.addEventListener(
454
+ const e = Date.now(), i = this.image;
455
+ this.rect.width * t < this.minDimension.closingWidth || i.width < Math.floor(this.minDimension.initialWidth) || (i.addEventListener(
454
456
  "transitionend",
455
457
  () => {
456
- this.animationTimestamp === e && n && (n.style.transition = "", this.normalize());
458
+ this.animationTimestamp === e && i && (i.style.transition = "", this.normalize());
457
459
  },
458
460
  { once: !0 }
459
- ), n.style.transition || (n.style.transition = "all 222ms ease"), this.animationTimestamp = e, this.scaleMove(t));
461
+ ), i.style.transition || (i.style.transition = "all 222ms ease"), this.animationTimestamp = e, this.scaleMove(t));
460
462
  }
461
463
  normalize(t = !0) {
462
464
  if (!this.image || !this.rect) return;
463
- let e = this.rect.width * this.scale, n = this.rect.height * this.scale;
464
- if (Math.round(e) === Math.round(this.minDimension.initialWidth) && (e = this.minDimension.initialWidth, n = this.minDimension.initialHeight), this.image.style.width = `${e}px`, this.image.style.height = `${n}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(), e <= this.minDimension.closingWidth)
465
+ const e = this.snapToTargetIfClose(
466
+ this.rect.width * this.scale,
467
+ this.minDimension.initialWidth
468
+ ), i = this.snapToTargetIfClose(
469
+ this.rect.height * this.scale,
470
+ this.minDimension.initialHeight
471
+ );
472
+ if (this.image.style.width = `${e}px`, this.image.style.height = `${i}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(), e <= this.minDimension.closingWidth)
465
473
  return this.clean(), !0;
466
474
  if (e < this.minDimension.initialWidth)
467
475
  this.accumulatedTranslate.x = 0, this.accumulatedTranslate.y = 0, requestAnimationFrame(() => {
468
- const i = this.image;
469
- i && (i.addEventListener(
476
+ const n = this.image;
477
+ n && (n.addEventListener(
470
478
  "transitionend",
471
479
  () => {
472
- i && (this.clean(), this.rect = null);
480
+ n && (this.clean(), this.rect = null);
473
481
  },
474
482
  { once: !0 }
475
- ), i.style.transition = "all 222ms ease", i.style.width = `${this.minDimension.initialWidth}px`, i.style.height = `${this.minDimension.initialHeight}px`, i.style.left = "50%", i.style.top = "50%");
483
+ ), n.style.transition = "all 222ms ease", n.style.width = `${this.minDimension.initialWidth}px`, n.style.height = `${this.minDimension.initialHeight}px`, n.style.left = "50%", n.style.top = "50%");
476
484
  });
477
485
  else if (t) {
478
- let i = !1;
479
- if (this.rect.right < window.innerWidth / 2 && (i = !0, this.accumulatedTranslate.x += window.innerWidth / 2 - this.rect.right), this.rect.left > window.innerWidth / 2 && (i = !0, this.accumulatedTranslate.x -= this.rect.left - window.innerWidth / 2), this.rect.bottom < window.innerHeight / 2 && (i = !0, this.accumulatedTranslate.y += window.innerHeight / 2 - this.rect.bottom), this.rect.top > window.innerHeight / 2 && (i = !0, this.accumulatedTranslate.y -= this.rect.top - window.innerHeight / 2), i) {
486
+ let n = !1;
487
+ if (this.rect.right < window.innerWidth / 2 && (n = !0, this.accumulatedTranslate.x += window.innerWidth / 2 - this.rect.right), this.rect.left > window.innerWidth / 2 && (n = !0, this.accumulatedTranslate.x -= this.rect.left - window.innerWidth / 2), this.rect.bottom < window.innerHeight / 2 && (n = !0, this.accumulatedTranslate.y += window.innerHeight / 2 - this.rect.bottom), this.rect.top > window.innerHeight / 2 && (n = !0, this.accumulatedTranslate.y -= this.rect.top - window.innerHeight / 2), n) {
480
488
  const o = this.image;
481
489
  o.addEventListener(
482
490
  "transitionend",
@@ -495,7 +503,7 @@ class et {
495
503
  l(this, "fiolast", {});
496
504
  }
497
505
  // first in out
498
- fio(t, e, n = 50) {
506
+ fio(t, e, i = 50) {
499
507
  const o = Date.now() - (this.fiolast[e] ?? 0), a = () => {
500
508
  this.fiolast[e] = Date.now(), t();
501
509
  };
@@ -503,7 +511,7 @@ class et {
503
511
  a();
504
512
  return;
505
513
  }
506
- o >= n && a();
514
+ o >= i && a();
507
515
  }
508
516
  }
509
517
  const x = {
@@ -563,10 +571,10 @@ class it {
563
571
  });
564
572
  l(this, "onResizeHandler", () => {
565
573
  this.currentChildren.htmls.forEach((t, e) => {
566
- const n = this.currentChildren.images[e], i = t.querySelector("img.vvw-img-hi"), o = t.querySelector("img.vvw-img-lo");
567
- if (M(n, i, o, !1), i.classList.contains("vvw--loaded")) {
568
- const { width: a, height: r } = D(i);
569
- i.style.setProperty("--vvw-current-w", `${a}px`), i.style.setProperty("--vvw-current-h", `${r}px`), i.dataset.vvwWidth = a.toString(), i.dataset.vvwHeight = r.toString();
574
+ const i = this.currentChildren.images[e], n = t.querySelector("img.vvw-img-hi"), o = t.querySelector("img.vvw-img-lo");
575
+ if (H(i, n, o, !1), n.classList.contains("vvw--loaded")) {
576
+ const { width: a, height: r } = S(n);
577
+ n.style.setProperty("--vvw-current-w", `${a}px`), n.style.setProperty("--vvw-current-h", `${r}px`), n.dataset.vvwWidth = a.toString(), n.dataset.vvwHeight = r.toString();
570
578
  }
571
579
  });
572
580
  });
@@ -574,16 +582,16 @@ class it {
574
582
  l(this, "pointerListeners", []);
575
583
  l(this, "getInternalPointerListener", () => {
576
584
  const t = this.imageState;
577
- let e = 0, n = !1, i = () => {
585
+ let e = 0, i = !1, n = () => {
578
586
  };
579
587
  return (o) => {
580
588
  if (o.event === "down") {
581
- if (i(), this.isZoomedIn && o.pointers.length === 1) {
589
+ if (n(), this.isZoomedIn && o.pointers.length === 1) {
582
590
  const a = this.pointers.getCentroid();
583
591
  t.setInitialCenter(a);
584
592
  }
585
593
  if (o.pointers.length >= 2) {
586
- n = !0;
594
+ i = !0;
587
595
  const a = this.pointers.getCentroid();
588
596
  e = this.pointers.getPointerDistance(o.pointers[0], o.pointers[1]), t.setInitialCenter(a);
589
597
  }
@@ -592,49 +600,49 @@ class it {
592
600
  const a = this.pointers.getCentroid();
593
601
  t.move(a);
594
602
  }
595
- if (o.pointers.length >= 2 && n) {
603
+ if (o.pointers.length >= 2 && i) {
596
604
  const a = this.pointers.getCentroid(), r = this.pointers.getPointerDistance(o.pointers[0], o.pointers[1]);
597
605
  t.scaleMove(r / e, a);
598
606
  }
599
- } else (o.event === "up" || o.event === "cancel") && (n || this.isZoomedIn) && (n ? (n = !1, t.normalize() && requestAnimationFrame(() => {
607
+ } else (o.event === "up" || o.event === "cancel") && (i || this.isZoomedIn) && (i ? (i = !1, t.normalize() && requestAnimationFrame(() => {
600
608
  this.close();
601
- })) : this.isZoomedIn && o.pointers.length === 0 && (i = t.moveAndNormalize(o.pointer)));
609
+ })) : this.isZoomedIn && o.pointers.length === 0 && (n = t.moveAndNormalize(o.pointer)));
602
610
  this.pointerListeners.forEach(
603
611
  (a) => a({
604
612
  ...o,
605
- hasInternalExecution: this.isZoomedIn || n
613
+ hasInternalExecution: this.isZoomedIn || i
606
614
  })
607
615
  );
608
616
  };
609
617
  });
610
618
  this.elements = t, this.options = {
611
- ...H,
619
+ ...T,
612
620
  ...e,
613
621
  controls: {
614
- ...H.controls,
622
+ ...T.controls,
615
623
  ...e.controls
616
624
  }
617
625
  }, this.imageState = new tt(
618
626
  this.options.maxZoomLevel,
619
- (n) => {
620
- var i, o, a, r, h, c;
621
- n.isMin ? (this.isZoomedIn = !1, (i = this.qs(".vvw-zoom-out")) == null || i.setAttribute("disabled", "true"), (o = this.qs('.vvw-item[data-vvw-idx="' + this.currentIndex + '"]')) == null || o.style.setProperty(
627
+ (i) => {
628
+ var n, o, a, r, h, c;
629
+ i.isMin ? (this.isZoomedIn = !1, (n = this.qs(".vvw-zoom-out")) == null || n.setAttribute("disabled", "true"), (o = this.qs('.vvw-item[data-vvw-idx="' + this.currentIndex + '"]')) == null || o.style.setProperty(
622
630
  "pointer-events",
623
631
  "none"
624
632
  )) : (this.isZoomedIn = !0, (a = this.qs(".vvw-zoom-out")) == null || a.removeAttribute("disabled"), (r = this.qs('.vvw-item[data-vvw-idx="' + this.currentIndex + '"]')) == null || r.style.setProperty(
625
633
  "pointer-events",
626
634
  "auto"
627
- )), n.isMax ? (h = this.qs(".vvw-zoom-in")) == null || h.setAttribute("disabled", "true") : (c = this.qs(".vvw-zoom-in")) == null || c.removeAttribute("disabled");
635
+ )), i.isMax ? (h = this.qs(".vvw-zoom-in")) == null || h.setAttribute("disabled", "true") : (c = this.qs(".vvw-zoom-in")) == null || c.removeAttribute("disabled");
628
636
  }
629
- ), 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((n, i) => {
630
- n.dataset.vistaIdx = i.toString(), n.addEventListener("click", this.defaultOnClickHandler), n.addEventListener("pointerup", this.onClickElements);
637
+ ), 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) => {
638
+ i.dataset.vistaIdx = n.toString(), i.addEventListener("click", this.defaultOnClickHandler), i.addEventListener("pointerup", this.onClickElements);
631
639
  });
632
640
  }
633
641
  qs(t) {
634
642
  return this.root ? this.root.querySelector(t) : null;
635
643
  }
636
644
  async swap(t, e) {
637
- const n = this.options.preloads || 0, i = this.currentIndex, { htmls: o, images: a } = this.getChildElements(n, i), r = this.imageContainer, h = this.currentChildren, c = {
645
+ const i = this.options.preloads || 0, n = this.currentIndex, { htmls: o, images: a } = this.getChildElements(i, n), r = this.imageContainer, h = this.currentChildren, c = {
638
646
  htmlElements: { from: h.htmls, to: o },
639
647
  images: { from: h.images, to: a },
640
648
  index: { from: t, to: this.currentIndex },
@@ -647,15 +655,15 @@ class it {
647
655
  b || (p = await this.transitionFunction(c, m)), this.lastSwapTime = w;
648
656
  const d = o[Math.floor(o.length / 2)].dataset.vvwIdx, v = r.querySelector(
649
657
  `.vvw-item[data-vvw-idx="${d}"] img.vvw-img-hi`
650
- ), g = v.getAttribute("style") || "", f = v.classList.contains("vvw--loaded"), u = v.width, L = v.height;
658
+ ), g = v.getAttribute("style") || "", f = v.classList.contains("vvw--loaded"), u = v.width, C = v.height;
651
659
  this.imageState.reset(), r.innerHTML = "", p instanceof Function && p(), o.forEach((E) => {
652
660
  const y = E.querySelector("img.vvw-img-hi");
653
661
  E.dataset.vvwPos === "0" && !m.aborted && g && f && // ready &&
654
- u && L && (y.classList.add("vvw--loaded"), y.classList.add("vvw--ready"), y.setAttribute("style", g), y.width = u, y.height = L, y.dataset.vvwWidth = u.toString(), y.dataset.vvwHeight = L.toString()), r.appendChild(E), y.classList.contains("vvw--ready") && (this.imageState.setCurrentImage(y), this.imageState.setInitialCenter());
662
+ u && C && (y.classList.add("vvw--loaded"), y.classList.add("vvw--ready"), y.setAttribute("style", g), y.width = u, y.height = C, y.dataset.vvwWidth = u.toString(), y.dataset.vvwHeight = C.toString()), r.appendChild(E), y.classList.contains("vvw--ready") && (this.imageState.setCurrentImage(y), this.imageState.setInitialCenter());
655
663
  }), this.waitForImagesToLoad(), this.options.onImageView && this.options.onImageView(c);
656
664
  }
657
665
  getChildElements(t, e) {
658
- const n = [], i = [];
666
+ const i = [], n = [];
659
667
  for (let o = -t; o <= t; o++) {
660
668
  const a = (e + o + this.elements.length) % this.elements.length, r = this.elements[a], h = r instanceof HTMLImageElement ? r : r instanceof HTMLAnchorElement && r.querySelector("img") || void 0, c = r instanceof HTMLElement ? {
661
669
  index: a,
@@ -668,11 +676,11 @@ class it {
668
676
  index: a,
669
677
  ...r
670
678
  };
671
- i.push(c), n.push(j(c, o));
679
+ n.push(c), i.push(j(c, o));
672
680
  }
673
681
  return {
674
- htmls: n,
675
- images: i
682
+ htmls: i,
683
+ images: n
676
684
  };
677
685
  }
678
686
  zoomIn() {
@@ -699,42 +707,42 @@ class it {
699
707
  this.elements instanceof NodeList && this.elements.forEach((r, h) => {
700
708
  r.style.opacity = "", h === t && (r.style.opacity = "0");
701
709
  });
702
- const e = this.qs(".vvw-index"), n = `${t + 1}`, i = `${this.elements.length}`;
703
- e && (e.textContent = `${n} / ${i}`);
710
+ const e = this.qs(".vvw-index"), i = `${t + 1}`, n = `${this.elements.length}`;
711
+ e && (e.textContent = `${i} / ${n}`);
704
712
  const o = this.qs(".vvw-desc");
705
713
  if (o) {
706
714
  const r = (a = this.currentChildren) == null ? void 0 : a.images.find((c) => c.index === t), h = (r == null ? void 0 : r.alt) || "";
707
- h ? (o.textContent = h, o.setAttribute("aria-label", `Image ${n} of ${i}: ${h}`)) : (o.textContent = "", o.setAttribute("aria-label", `Image ${n} of ${i}`));
715
+ h ? (o.textContent = h, o.setAttribute("aria-label", `Image ${i} of ${n}: ${h}`)) : (o.textContent = "", o.setAttribute("aria-label", `Image ${i} of ${n}`));
708
716
  }
709
717
  }
710
718
  waitForImagesToLoad() {
711
- this.imageContainer.querySelectorAll("img.vvw-img-hi:not(.vvw--loaded)").forEach((n) => {
712
- const i = n, o = () => {
719
+ this.imageContainer.querySelectorAll("img.vvw-img-hi:not(.vvw--loaded)").forEach((i) => {
720
+ const n = i, o = () => {
713
721
  var r;
714
- i.width = i.naturalWidth, i.height = i.naturalHeight;
715
- const a = (r = i.parentElement) == null ? void 0 : r.matches(`[data-vvw-idx="${this.currentIndex}"]`);
716
- i.addEventListener(
722
+ n.width = n.naturalWidth, n.height = n.naturalHeight;
723
+ const a = (r = n.parentElement) == null ? void 0 : r.matches(`[data-vvw-idx="${this.currentIndex}"]`);
724
+ n.addEventListener(
717
725
  "transitionend",
718
726
  () => {
719
- a && (this.imageState.setCurrentImage(i), this.imageState.setInitialCenter()), i.classList.add("vvw--ready");
727
+ a && (this.imageState.setCurrentImage(n), this.imageState.setInitialCenter()), n.classList.add("vvw--ready");
720
728
  },
721
729
  { once: !0 }
722
- ), i.classList.add("vvw--loaded"), requestAnimationFrame(() => {
723
- const { width: h, height: c } = D(i);
724
- i.style.setProperty("--vvw-current-w", `${h}px`), i.style.setProperty("--vvw-current-h", `${c}px`), i.dataset.vvwWidth = h.toString(), i.dataset.vvwHeight = c.toString(), i.style.setProperty("--vvw-current-radius", "0px");
730
+ ), n.classList.add("vvw--loaded"), requestAnimationFrame(() => {
731
+ const { width: h, height: c } = S(n);
732
+ n.style.setProperty("--vvw-current-w", `${h}px`), n.style.setProperty("--vvw-current-h", `${c}px`), n.dataset.vvwWidth = h.toString(), n.dataset.vvwHeight = c.toString(), n.style.setProperty("--vvw-current-radius", "0px");
725
733
  });
726
734
  };
727
- if (i.complete && i.naturalWidth !== 0) {
735
+ if (n.complete && n.naturalWidth !== 0) {
728
736
  o();
729
737
  return;
730
738
  }
731
- i.addEventListener("load", () => {
739
+ n.addEventListener("load", () => {
732
740
  o();
733
- }), i.addEventListener("error", () => {
741
+ }), n.addEventListener("error", () => {
734
742
  var r;
735
- i.classList.add("vvw--loaderror");
743
+ n.classList.add("vvw--loaderror");
736
744
  const a = document.createElement("p");
737
- a.className = "vvw-img-err", a.setAttribute("role", "alert"), a.textContent = "Error loading image", (r = i.parentNode) == null || r.appendChild(a);
745
+ a.className = "vvw-img-err", a.setAttribute("role", "alert"), a.textContent = "Error loading image", (r = n.parentNode) == null || r.appendChild(a);
738
746
  });
739
747
  });
740
748
  }
@@ -756,7 +764,7 @@ class it {
756
764
  if (document.body.prepend(e), this.root = document.body.querySelector("#vvw-root"), !this.root)
757
765
  throw new Error("Failed to setup VistaView root element.");
758
766
  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}`);
759
- const n = this.options.preloads || 0, i = t, { images: o, htmls: a } = this.getChildElements(n, i), r = {
767
+ const i = this.options.preloads || 0, n = t, { images: o, htmls: a } = this.getChildElements(i, n), r = {
760
768
  htmlElements: { from: null, to: a },
761
769
  images: { from: null, to: o },
762
770
  index: { from: null, to: this.currentIndex },
@@ -782,12 +790,12 @@ class it {
782
790
  }), this.root.querySelectorAll("button[data-vvw-control]").forEach((d) => {
783
791
  const v = d;
784
792
  v.addEventListener("click", (g) => {
785
- const f = g.currentTarget.dataset.vvwControl, u = h[f], L = this.currentChildren.images.find(
793
+ const f = g.currentTarget.dataset.vvwControl, u = h[f], C = this.currentChildren.images.find(
786
794
  (E) => E.index === this.currentIndex
787
795
  );
788
- u && L && (u.onClick.constructor.name === "AsyncFunction" ? (v.classList.add("vvw--loading"), u.onClick(L, this).finally(() => {
796
+ u && C && (u.onClick.constructor.name === "AsyncFunction" ? (v.classList.add("vvw--loading"), u.onClick(C, this).finally(() => {
789
797
  v.classList.remove("vvw--loading");
790
- })) : u.onClick(L, this));
798
+ })) : u.onClick(C, this));
791
799
  });
792
800
  }), this.initFunction(this), requestAnimationFrame(() => {
793
801
  var d;
@@ -806,11 +814,11 @@ class it {
806
814
  /// CLOSE
807
815
  async close(t = !0) {
808
816
  x.somethingOpened === this && this.root && (t ? await new Promise((e) => {
809
- let i = 0;
817
+ let n = 0;
810
818
  this.root.addEventListener("transitionend", (o) => {
811
- o.target === this.root && (i++, i === 2 && this.elements instanceof NodeList && this.elements.forEach((a) => {
819
+ o.target === this.root && (n++, n === 2 && this.elements instanceof NodeList && this.elements.forEach((a) => {
812
820
  a.style.opacity = "";
813
- }), i === 3 && e(null));
821
+ }), n === 3 && e(null));
814
822
  }), this.root.classList.add("vvw--closing");
815
823
  }) : this.elements instanceof NodeList && this.elements.forEach((e) => {
816
824
  e.style.opacity = "";
@@ -839,25 +847,25 @@ class it {
839
847
  view(t, e) {
840
848
  if (x.somethingOpened !== this || t < 0 || t >= this.elements.length)
841
849
  return;
842
- const n = this.currentIndex;
850
+ const i = this.currentIndex;
843
851
  this.currentIndex = t;
844
- const i = this.abortController;
845
- i == null || i.abort(), this.abortController = new AbortController(), this.swap(n, e);
852
+ const n = this.abortController;
853
+ n == null || n.abort(), this.abortController = new AbortController(), this.swap(i, e);
846
854
  }
847
855
  }
848
856
  function nt(s) {
849
857
  let t = null;
850
858
  if (typeof s == "string" ? t = document.querySelectorAll(s) : s instanceof NodeList && (t = s), t)
851
859
  for (let e = 0; e < t.length; e++) {
852
- const n = t[e];
853
- if (!(n.dataset.vistaviewSrc || n.getAttribute("href") || n.getAttribute("src") || ""))
860
+ const i = t[e];
861
+ if (!(i.dataset.vistaviewSrc || i.getAttribute("href") || i.getAttribute("src") || ""))
854
862
  return `Element at index ${e} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`;
855
863
  }
856
864
  else {
857
865
  const e = s;
858
- for (let n = 0; n < e.length; n++)
859
- if (!e[n].src)
860
- return `Element at index ${n} is missing 'src' attribute.`;
866
+ for (let i = 0; i < e.length; i++)
867
+ if (!e[i].src)
868
+ return `Element at index ${i} is missing 'src' attribute.`;
861
869
  }
862
870
  return t || s;
863
871
  }
@@ -866,21 +874,21 @@ function ot({ elements: s, ...t }) {
866
874
  let e = nt(s);
867
875
  if (typeof e == "string")
868
876
  return null;
869
- const n = new it(e, t);
877
+ const i = new it(e, t);
870
878
  return {
871
- open: (i = 0) => n.open(i),
872
- close: () => n.close(),
873
- next: () => n.next(),
874
- prev: () => n.prev(),
875
- destroy: () => n.destroy(),
876
- getCurrentIndex: () => n.getCurrentIndex(),
877
- view: (i) => {
878
- n.view(i);
879
+ open: (n = 0) => i.open(n),
880
+ close: () => i.close(),
881
+ next: () => i.next(),
882
+ prev: () => i.prev(),
883
+ destroy: () => i.destroy(),
884
+ getCurrentIndex: () => i.getCurrentIndex(),
885
+ view: (n) => {
886
+ i.view(n);
879
887
  }
880
888
  };
881
889
  }
882
890
  export {
883
- H as DefaultOptions,
891
+ T as DefaultOptions,
884
892
  ot as vistaView,
885
893
  N as vistaViewDownload
886
894
  };
@@ -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 st=Object.defineProperty;var ot=(v,w,$)=>w in v?st(v,w,{enumerable:!0,configurable:!0,writable:!0,value:$}):v[w]=$;var l=(v,w,$)=>ot(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:n,height:i}=s.getBoundingClientRect(),o=s.naturalWidth,a=s.naturalHeight;if(!e)return{width:n,height:i};if(!o||!a)return{width:n,height:i};const r=o/a,h=n/i;switch(e){case"fill":return{width:n,height:i};case"none":return{width:o,height:a};case"contain":return r>h?{width:n,height:n/r}:{width:i*r,height:i};case"cover":return r<h?{width:n,height:n/r}:{width:i*r,height:i};case"scale-down":{const c={width:o,height:a},m=r>h?{width:n,height:n/r}:{width:i*r,height:i};return m.width<=c.width&&m.height<=c.height?m:c}}return{width:n,height:i}}function H(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 F(s){const t=s.imageElm?H(s.imageElm):null,e=s.anchorElm?H(s.anchorElm):null,n=w(t==null?void 0:t.borderRadius),i=e&&w(e==null?void 0:e.borderRadius),o=(i?e==null?void 0:e.borderRadius:n?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:o,overflow:i?e.overflow:n?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 W(s,t,e,n=!1){const{fit:i,w:o,h:a,nw:r,nh:h,br:c,top:m,left:f}=F(s),E=Math.min(Math.max(f,-o),window.innerWidth+o)-window.innerWidth/2+o/2,y=Math.min(Math.max(m,-a),window.innerHeight+a)-window.innerHeight/2+a/2,d=e.style;d.width=`${o}px`,d.height=`${a}px`,d.objectFit=i,e.width=r,e.height=h,d.setProperty("--vvw-init-radius",`${c}`),d.setProperty("--vvw-pulse-radius",`calc(1.3 * ${c})`),d.setProperty("--vvw-init-x",`${E}px`),d.setProperty("--vvw-init-y",`${y}px`),n&&(d.setProperty("--vvw-current-x",`${E}px`),d.setProperty("--vvw-current-y",`${y}px`));const g=$(s.imageElm),p=Math.min(o,g.width),x=Math.min(a,g.height),u=t.style;u.setProperty("--vvw-init-radius",`${c}`),u.setProperty("--vvw-init-w",`${p}px`),u.setProperty("--vvw-init-h",`${x}px`),n&&(u.setProperty("--vvw-current-radius",`${c}`),u.setProperty("--vvw-current-w",`${p}px`),u.setProperty("--vvw-current-h",`${x}px`),t.dataset.vvwWidth=p.toString(),t.dataset.vvwHeight=x.toString())}function T(s){const t=window.innerWidth,e=window.innerHeight,n=s.naturalWidth,i=s.naturalHeight;if(!n||!i)throw new Error("Image natural dimensions are zero");if(n<t&&i<e)return{width:n,height:i};const o=n/i,a=t/e;let r,h;return o>a?(r=t,h=t/o):(h=e,r=e*o),{width:r,height:h}}function P(s,t,e){return Math.min(Math.max(s,t),e)}function C(s,t=2){const e=Math.pow(10,t);return Math.round(s*e)/e}const q='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',k='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',R='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',O='<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>',Z='<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>';let D=null;function X(){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 z(s){const e=X().createHTML(s),n=document.createElement("template");n.innerHTML=e;const i=n.content;return n.remove(),i}function A(){return{name:"download",icon:Y,onClick:async s=>{var o;const t=await fetch(s.src),e=await t.blob(),n=t.url,i=document.createElement("a");i.href=URL.createObjectURL(e),i.download=((o=n.split("/").pop())==null?void 0:o.split("?")[0].split("#")[0])||"download",document.body.appendChild(i),i.click(),document.body.removeChild(i)}}}function N(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button aria-label="Zoom In" class="vvw-zoom-in vvw-ui">${R}</button>`;case"zoomOut":return`<button aria-label="Zoom Out" disabled class="vvw-zoom-out vvw-ui">${O}</button>`;case"close":return`<button aria-label="Close" class="vvw-close vvw-ui">${Z}</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 aria-label="${s.description||s.name}" data-vvw-control="${s.name}">${s.icon}</button>`}function B(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(z(`<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 n=e.querySelector("img.vvw-img-lo"),i=e.querySelector("img.vvw-img-hi");return W(s,i,n,t===0),e}function j({controls:s}){const t=n=>n?n.map(N).join(""):"";return z(`<div class="vvw-root" id="vvw-root">
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 st=Object.defineProperty;var ot=(v,w,$)=>w in v?st(v,w,{enumerable:!0,configurable:!0,writable:!0,value:$}):v[w]=$;var l=(v,w,$)=>ot(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(),o=s.naturalWidth,a=s.naturalHeight;if(!e)return{width:i,height:n};if(!o||!a)return{width:i,height:n};const r=o/a,h=i/n;switch(e){case"fill":return{width:i,height:n};case"none":return{width:o,height:a};case"contain":return r>h?{width:i,height:i/r}:{width:n*r,height:n};case"cover":return r<h?{width:i,height:i/r}:{width:n*r,height:n};case"scale-down":{const c={width:o,height:a},m=r>h?{width:i,height:i/r}:{width:n*r,height:n};return m.width<=c.width&&m.height<=c.height?m:c}}return{width:i,height:n}}function H(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 P(s){const t=s.imageElm?H(s.imageElm):null,e=s.anchorElm?H(s.anchorElm):null,i=w(t==null?void 0:t.borderRadius),n=e&&w(e==null?void 0:e.borderRadius),o=(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:o,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 M(s,t,e,i=!1){const{fit:n,w:o,h:a,nw:r,nh:h,br:c,top:m,left:f}=P(s),E=Math.min(Math.max(f,-o),window.innerWidth+o)-window.innerWidth/2+o/2,y=Math.min(Math.max(m,-a),window.innerHeight+a)-window.innerHeight/2+a/2,d=e.style;d.width=`${o}px`,d.height=`${a}px`,d.objectFit=n,e.width=r,e.height=h,d.setProperty("--vvw-init-radius",`${c}`),d.setProperty("--vvw-pulse-radius",`calc(1.3 * ${c})`),d.setProperty("--vvw-init-x",`${E}px`),d.setProperty("--vvw-init-y",`${y}px`),i&&(d.setProperty("--vvw-current-x",`${E}px`),d.setProperty("--vvw-current-y",`${y}px`));const g=$(s.imageElm),p=Math.min(o,g.width),x=Math.min(a,g.height),u=t.style;u.setProperty("--vvw-init-radius",`${c}`),u.setProperty("--vvw-init-w",`${p}px`),u.setProperty("--vvw-init-h",`${x}px`),i&&(u.setProperty("--vvw-current-radius",`${c}`),u.setProperty("--vvw-current-w",`${p}px`),u.setProperty("--vvw-current-h",`${x}px`),t.dataset.vvwWidth=p.toString(),t.dataset.vvwHeight=x.toString())}function W(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 o=i/n,a=t/e;let r,h;return o>a?(r=t,h=t/o):(h=e,r=e*o),{width:r,height:h}}function z(s,t,e){return Math.min(Math.max(s,t),e)}function L(s,t=2){const e=Math.pow(10,t);return Math.round(s*e)/e}const q='<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>',k='<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>',R='<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>',O='<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>',Z='<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>';let S=null;function X(){return S||(window.trustedTypes||(window.trustedTypes={createPolicy:(s,t)=>t}),S=window.trustedTypes.createPolicy("vistaView-policy",{createHTML:s=>s,createScript:()=>{throw new Error("Not implemented")},createScriptURL:()=>{throw new Error("Not implemented")}}),S)}function A(s){const e=X().createHTML(s),i=document.createElement("template");i.innerHTML=e;const n=i.content;return i.remove(),n}function F(){return{name:"download",icon:Y,onClick:async s=>{var o;const t=await fetch(s.src),e=await t.blob(),i=t.url,n=document.createElement("a");n.href=URL.createObjectURL(e),n.download=((o=i.split("/").pop())==null?void 0:o.split("?")[0].split("#")[0])||"download",document.body.appendChild(n),n.click(),document.body.removeChild(n)}}}function N(s){if(typeof s=="string")switch(s){case"zoomIn":return`<button aria-label="Zoom In" class="vvw-zoom-in vvw-ui">${R}</button>`;case"zoomOut":return`<button aria-label="Zoom Out" disabled class="vvw-zoom-out vvw-ui">${O}</button>`;case"close":return`<button aria-label="Close" class="vvw-close vvw-ui">${Z}</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 aria-label="${s.description||s.name}" data-vvw-control="${s.name}">${s.icon}</button>`}function B(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 M(s,n,i,t===0),e}function j({controls:s}){const t=i=>i?i.map(N).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">${q}</button></div>
9
9
  <div class="vvw-next vvw-ui"><button aria-label="Next">${k}</button></div>
10
10
  </div>
11
- </div>`)}const M={animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,rapidLimit:222,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",A(),"close"],bottomLeft:["description"]}};function U(s){}function V(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",K(s)}function K(s){let t={x:0,y:0},e={x:0,y:0},n=null;s.registerPointerListener(i=>{if(!i.hasInternalExecution&&!(i.pointers.length>1)){if(i.event==="down"&&(t={x:i.pointer.x,y:i.pointer.y},e={x:i.pointer.x,y:i.pointer.y}),i.event==="move"){e={x:i.pointer.x,y:i.pointer.y};const o=e.x-t.x,a=e.y-t.y;if(!n&&Math.abs(a)>Math.abs(o)||n==="y"){const r=a/window.innerHeight*100;s.imageContainer.style.transition="none",s.imageContainer.style.transform=`translateY(${r}vh)`,n="y"}else if(!n&&Math.abs(o)>Math.abs(a)||n==="x"){const r=o/window.innerWidth*100;s.imageContainer.style.transition="none",s.imageContainer.style.transform=`translateX(${r}vw)`,n="x"}}if(i.event==="up"||i.event==="cancel"){let o=function(a){var r;(r=s.imageContainer)==null||r.addEventListener("transitionend",function h(){var c;(c=s.imageContainer)==null||c.removeEventListener("transitionend",h),s.imageContainer.style.transition="",s.imageContainer.style.transform=""}),s.imageContainer.style.transition="transform 222ms ease",s.imageContainer.style.transform=a};if(n==="y"){const a=e.y-t.y,r=i.pointer.movementY,h=8;s.imageContainer.style.transition="",a>0&&Math.abs(r)>h||a<0&&Math.abs(r)>h?(s.imageContainer.style.transition="transform 222ms ease",s.imageContainer.style.transform="translateY(0vh)",s.close()):o("translateY(0vh)")}if(n==="x"){const a=e.x-t.x,r=i.pointer.movementX,h=8;s.imageContainer.style.transition="",a>0&&Math.abs(r)>h?s.prev():a<0&&Math.abs(r)>h?s.next():o("translateX(0vw)")}n=null}}})}function _(s){}async function G({vistaView:{isReducedMotion:s},htmlElements:{to:t},index:{from:e,to:n},vistaView:{elements:i,imageContainer:o,options:a}},r){if(!t||r.aborted||s||!(Math.abs(n-e)===1||e===0&&n===i.length-1||e===i.length-1&&n===0))return;const c=Math.round(a.animationDurationBase*1.5*100)/100;return new Promise(m=>{o.addEventListener("transitionend",()=>{m(()=>{o.style.transition="",o.style.transform=""})},{once:!0});const f=n===e+1||e===i.length-1&&n===0?"translateX(-100vw)":"translateX(100vw)";o.style.transition=`transform ${c}ms ease`,o.style.transform=f})}class J{constructor({elm:t,listeners:e}){l(this,"pointers",[]);l(this,"elm");l(this,"listeners",[]);l(this,"lastPointerDownId",null);l(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)}});l(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(n=>n({event:"down",pointer:e,pointers:this.pointers,lastPointerLen:this.pointers.length-1}))});l(this,"onPointerMove",t=>{if(!this.listeners.length)return;t.preventDefault();const e=this.pointers.find(n=>n.id===t.pointerId);e&&(e.movementX=t.movementX,e.movementY=t.movementY,e.x=t.clientX,e.y=t.clientY,this.listeners.forEach(n=>n({event:"move",pointer:e,pointers:this.pointers,lastPointerLen:this.pointers.length-1})))});l(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(o=>o.id===t.pointerId);if(e===-1)return;const n=this.pointers[e];n.x=t.clientX,n.y=t.clientY;const i=this.pointers.length;this.pointers.splice(e,1),this.listeners.forEach(o=>o({event:"up",pointer:n,pointers:this.pointers,lastPointerLen:i}))});l(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(o=>o.id===t.pointerId);if(e===-1)return;const n=this.pointers[e];n.x=t.clientX,n.y=t.clientY;const i=this.pointers.length;this.pointers.splice(e,1),this.listeners.forEach(o=>o({event:"cancel",pointer:n,pointers:this.pointers,lastPointerLen:i}))});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 n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)}getCentroid(){if(this.pointers.length===0)return null;const t=this.pointers.reduce((e,n)=>(e.x+=n.x,e.y+=n.y,e),{x:0,y:0});return{x:t.x/this.pointers.length,y:t.y/this.pointers.length}}}class Q{constructor(t,e){l(this,"maxZoomLevel");l(this,"image",null);l(this,"rect",null);l(this,"initialCenter",{x:0,y:0});l(this,"maxDimension",{width:0});l(this,"minDimension",{initialWidth:0,initialHeight:0,minWidth:0,closingWidth:0});l(this,"accumulatedTranslate",{x:0,y:0});l(this,"scale",1);l(this,"translate",{x:0,y:0});l(this,"onScale",null);l(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),n=parseFloat(t.dataset.vvwHeight);this.minDimension={initialWidth:e,initialHeight:n,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=C(t.x-this.initialCenter.x),this.translate.y=C(t.y-this.initialCenter.y),this.image.style.transform=`translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`)}scaleMove(t,e){if(!this.image)return;this.rect||(this.rect=this.image.getBoundingClientRect()),e||(e=this.initialCenter);const n=P(this.rect.width*t,this.minDimension.minWidth,this.maxDimension.width);this.onScale&&this.onScale({scale:n/(this.maxDimension.width/this.maxZoomLevel),isMax:n>=this.maxDimension.width,isMin:n<=this.minDimension.initialWidth}),this.scale=C(n/this.rect.width);const i=this.rect.left+this.rect.width/2,o=this.rect.top+this.rect.height/2,a=this.initialCenter.x-i,r=this.initialCenter.y-o,h=a*(1-this.scale),c=r*(1-this.scale),m=e.x-this.initialCenter.x,f=e.y-this.initialCenter.y;this.translate.x=C(h+m),this.translate.y=C(c+f),this.image.style.transform=`translate3d(${this.translate.x}px, ${this.translate.y}px, 0px) scale(${this.scale})`,n<=this.minDimension.closingWidth?this.image.style.opacity="0.5":this.image.style.opacity=""}moveAndNormalize(t){let e=0,n=!1;const i=({x:o,y:a})=>{if(n)return;if(Math.abs(o)<.001&&Math.abs(a)<.001)return this.normalize();o*=.9,a*=.9;const r=this.image.getBoundingClientRect();this.translate.x=C(this.translate.x+o),this.translate.y=C(this.translate.y+a),r.right<window.innerWidth/2&&(this.translate.x+=(window.innerWidth/2-r.right)*.1,o*=.7),r.left>window.innerWidth/2&&(this.translate.x-=(r.left-window.innerWidth/2)*.1,o*=.7),r.bottom<window.innerHeight/2&&(this.translate.y+=(window.innerHeight/2-r.bottom)*.1,a*=.7),r.top>window.innerHeight/2&&(this.translate.y-=(r.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(()=>i({x:o,y:a}))};return i({x:t.movementX,y:t.movementY}),()=>{n=!0,cancelAnimationFrame(e),this.normalize(!1)}}animateZoom(t){if(!this.image)return;this.rect||(this.rect=this.image.getBoundingClientRect());const e=Date.now(),n=this.image;this.rect.width*t<this.minDimension.closingWidth||n.width<Math.floor(this.minDimension.initialWidth)||(n.addEventListener("transitionend",()=>{this.animationTimestamp===e&&n&&(n.style.transition="",this.normalize())},{once:!0}),n.style.transition||(n.style.transition="all 222ms ease"),this.animationTimestamp=e,this.scaleMove(t))}normalize(t=!0){if(!this.image||!this.rect)return;let e=this.rect.width*this.scale,n=this.rect.height*this.scale;if(Math.round(e)===Math.round(this.minDimension.initialWidth)&&(e=this.minDimension.initialWidth,n=this.minDimension.initialHeight),this.image.style.width=`${e}px`,this.image.style.height=`${n}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(),e<=this.minDimension.closingWidth)return this.clean(),!0;if(e<this.minDimension.initialWidth)this.accumulatedTranslate.x=0,this.accumulatedTranslate.y=0,requestAnimationFrame(()=>{const i=this.image;i&&(i.addEventListener("transitionend",()=>{i&&(this.clean(),this.rect=null)},{once:!0}),i.style.transition="all 222ms ease",i.style.width=`${this.minDimension.initialWidth}px`,i.style.height=`${this.minDimension.initialHeight}px`,i.style.left="50%",i.style.top="50%")});else if(t){let i=!1;if(this.rect.right<window.innerWidth/2&&(i=!0,this.accumulatedTranslate.x+=window.innerWidth/2-this.rect.right),this.rect.left>window.innerWidth/2&&(i=!0,this.accumulatedTranslate.x-=this.rect.left-window.innerWidth/2),this.rect.bottom<window.innerHeight/2&&(i=!0,this.accumulatedTranslate.y+=window.innerHeight/2-this.rect.bottom),this.rect.top>window.innerHeight/2&&(i=!0,this.accumulatedTranslate.y-=this.rect.top-window.innerHeight/2),i){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 tt{constructor(){l(this,"fiolast",{})}fio(t,e,n=50){const o=Date.now()-(this.fiolast[e]??0),a=()=>{this.fiolast[e]=Date.now(),t()};if(!this.fiolast[e]){a();return}o>=n&&a()}}const L={somethingOpened:null};class et{constructor(t,e={}){l(this,"options");l(this,"elements");l(this,"isReducedMotion");l(this,"currentIndex",-1);l(this,"currentChildren",null);l(this,"setupFunction",U);l(this,"initFunction",V);l(this,"closeFunction",_);l(this,"transitionFunction",G);l(this,"pointers",null);l(this,"imageState");l(this,"root",null);l(this,"imageContainer",null);l(this,"onClickElements",t=>{t.preventDefault();const e=t.currentTarget;e.dataset.vistaIdx&&this.open(parseInt(e.dataset.vistaIdx))});l(this,"defaultOnClickHandler",t=>t.preventDefault());l(this,"abortController",null);l(this,"throttle",new tt);l(this,"lastSwapTime",0);l(this,"isZoomedIn",!1);l(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}});l(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()});l(this,"onResizeHandler",()=>{this.currentChildren.htmls.forEach((t,e)=>{const n=this.currentChildren.images[e],i=t.querySelector("img.vvw-img-hi"),o=t.querySelector("img.vvw-img-lo");if(W(n,i,o,!1),i.classList.contains("vvw--loaded")){const{width:a,height:r}=T(i);i.style.setProperty("--vvw-current-w",`${a}px`),i.style.setProperty("--vvw-current-h",`${r}px`),i.dataset.vvwWidth=a.toString(),i.dataset.vvwHeight=r.toString()}})});l(this,"pointerListeners",[]);l(this,"getInternalPointerListener",()=>{const t=this.imageState;let e=0,n=!1,i=()=>{};return o=>{if(o.event==="down"){if(i(),this.isZoomedIn&&o.pointers.length===1){const a=this.pointers.getCentroid();t.setInitialCenter(a)}if(o.pointers.length>=2){n=!0;const a=this.pointers.getCentroid();e=this.pointers.getPointerDistance(o.pointers[0],o.pointers[1]),t.setInitialCenter(a)}}else if(o.event==="move"){if(this.isZoomedIn&&o.pointers.length===1&&o.lastPointerLen===0){const a=this.pointers.getCentroid();t.move(a)}if(o.pointers.length>=2&&n){const a=this.pointers.getCentroid(),r=this.pointers.getPointerDistance(o.pointers[0],o.pointers[1]);t.scaleMove(r/e,a)}}else(o.event==="up"||o.event==="cancel")&&(n||this.isZoomedIn)&&(n?(n=!1,t.normalize()&&requestAnimationFrame(()=>{this.close()})):this.isZoomedIn&&o.pointers.length===0&&(i=t.moveAndNormalize(o.pointer)));this.pointerListeners.forEach(a=>a({...o,hasInternalExecution:this.isZoomedIn||n}))}});this.elements=t,this.options={...M,...e,controls:{...M.controls,...e.controls}},this.imageState=new Q(this.options.maxZoomLevel,n=>{var i,o,a,r,h,c;n.isMin?(this.isZoomedIn=!1,(i=this.qs(".vvw-zoom-out"))==null||i.setAttribute("disabled","true"),(o=this.qs('.vvw-item[data-vvw-idx="'+this.currentIndex+'"]'))==null||o.style.setProperty("pointer-events","none")):(this.isZoomedIn=!0,(a=this.qs(".vvw-zoom-out"))==null||a.removeAttribute("disabled"),(r=this.qs('.vvw-item[data-vvw-idx="'+this.currentIndex+'"]'))==null||r.style.setProperty("pointer-events","auto")),n.isMax?(h=this.qs(".vvw-zoom-in"))==null||h.setAttribute("disabled","true"):(c=this.qs(".vvw-zoom-in"))==null||c.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((n,i)=>{n.dataset.vistaIdx=i.toString(),n.addEventListener("click",this.defaultOnClickHandler),n.addEventListener("pointerup",this.onClickElements)})}qs(t){return this.root?this.root.querySelector(t):null}async swap(t,e){const n=this.options.preloads||0,i=this.currentIndex,{htmls:o,images:a}=this.getChildElements(n,i),r=this.imageContainer,h=this.currentChildren,c={htmlElements:{from:h.htmls,to:o},images:{from:h.images,to:a},index:{from:t,to:this.currentIndex},via:e||{next:!1,prev:!1},vistaView:this};this.setupFunction(c),this.currentChildren={htmls:o,images:a},this.displayActiveIndex();const m=this.abortController.signal,f=performance.now(),E=f-this.lastSwapTime<this.options.rapidLimit;let y=null;E||(y=await this.transitionFunction(c,m)),this.lastSwapTime=f;const d=o[Math.floor(o.length/2)].dataset.vvwIdx,g=r.querySelector(`.vvw-item[data-vvw-idx="${d}"] img.vvw-img-hi`),p=g.getAttribute("style")||"",x=g.classList.contains("vvw--loaded"),u=g.width,I=g.height;this.imageState.reset(),r.innerHTML="",y instanceof Function&&y(),o.forEach(S=>{const b=S.querySelector("img.vvw-img-hi");S.dataset.vvwPos==="0"&&!m.aborted&&p&&x&&u&&I&&(b.classList.add("vvw--loaded"),b.classList.add("vvw--ready"),b.setAttribute("style",p),b.width=u,b.height=I,b.dataset.vvwWidth=u.toString(),b.dataset.vvwHeight=I.toString()),r.appendChild(S),b.classList.contains("vvw--ready")&&(this.imageState.setCurrentImage(b),this.imageState.setInitialCenter())}),this.waitForImagesToLoad(),this.options.onImageView&&this.options.onImageView(c)}getChildElements(t,e){const n=[],i=[];for(let o=-t;o<=t;o++){const a=(e+o+this.elements.length)%this.elements.length,r=this.elements[a],h=r instanceof HTMLImageElement?r:r instanceof HTMLAnchorElement&&r.querySelector("img")||void 0,c=r instanceof HTMLElement?{index:a,imageElm:h instanceof HTMLImageElement?h:void 0,anchorElm:r instanceof HTMLAnchorElement?r:void 0,src:r.dataset.vistaviewSrc||r.getAttribute("href")||r.getAttribute("src")||"",thumb:r.dataset.vistaviewThumb||(h instanceof HTMLImageElement?h.getAttribute("src"):void 0)||r.getAttribute("href")||void 0,alt:h instanceof HTMLImageElement&&h.getAttribute("alt")||void 0}:{index:a,...r};i.push(c),n.push(B(c,o))}return{htmls:n,images:i}}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((r,h)=>{r.style.opacity="",h===t&&(r.style.opacity="0")});const e=this.qs(".vvw-index"),n=`${t+1}`,i=`${this.elements.length}`;e&&(e.textContent=`${n} / ${i}`);const o=this.qs(".vvw-desc");if(o){const r=(a=this.currentChildren)==null?void 0:a.images.find(c=>c.index===t),h=(r==null?void 0:r.alt)||"";h?(o.textContent=h,o.setAttribute("aria-label",`Image ${n} of ${i}: ${h}`)):(o.textContent="",o.setAttribute("aria-label",`Image ${n} of ${i}`))}}waitForImagesToLoad(){this.imageContainer.querySelectorAll("img.vvw-img-hi:not(.vvw--loaded)").forEach(n=>{const i=n,o=()=>{var r;i.width=i.naturalWidth,i.height=i.naturalHeight;const a=(r=i.parentElement)==null?void 0:r.matches(`[data-vvw-idx="${this.currentIndex}"]`);i.addEventListener("transitionend",()=>{a&&(this.imageState.setCurrentImage(i),this.imageState.setInitialCenter()),i.classList.add("vvw--ready")},{once:!0}),i.classList.add("vvw--loaded"),requestAnimationFrame(()=>{const{width:h,height:c}=T(i);i.style.setProperty("--vvw-current-w",`${h}px`),i.style.setProperty("--vvw-current-h",`${c}px`),i.dataset.vvwWidth=h.toString(),i.dataset.vvwHeight=c.toString(),i.style.setProperty("--vvw-current-radius","0px")})};if(i.complete&&i.naturalWidth!==0){o();return}i.addEventListener("load",()=>{o()}),i.addEventListener("error",()=>{var r;i.classList.add("vvw--loaderror");const a=document.createElement("p");a.className="vvw-img-err",a.setAttribute("role","alert"),a.textContent="Error loading image",(r=i.parentNode)==null||r.appendChild(a)})})}registerPointerListener(t){this.pointerListeners.push(t)}unregisterPointerListeners(){this.pointerListeners=[]}open(t=0){var c,m,f,E,y;if(L.somethingOpened)return;L.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}`);const n=this.options.preloads||0,i=t,{images:o,htmls:a}=this.getChildElements(n,i),r={htmlElements:{from:null,to:a},images:{from:null,to:o},index:{from:null,to:this.currentIndex},via:{next:!1,prev:!1},vistaView:this};this.setupFunction(r),this.currentChildren={htmls:a,images:o},a.forEach(d=>{this.imageContainer.appendChild(d)}),(c=this.qs(".vvw-close"))==null||c.addEventListener("click",()=>this.close()),(m=this.qs(".vvw-zoom-in"))==null||m.addEventListener("click",()=>this.zoomIn()),(f=this.qs(".vvw-zoom-out"))==null||f.addEventListener("click",()=>this.zoomOut()),(E=this.qs(".vvw-prev>button"))==null||E.addEventListener("click",()=>this.prev()),(y=this.qs(".vvw-next>button"))==null||y.addEventListener("click",()=>this.next()),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("wheel",this.onScroll,{passive:!1}),window.addEventListener("resize",this.onResizeHandler),this.pointers=new J({elm:this.imageContainer,listeners:[this.getInternalPointerListener()]});const h={};[...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(d=>{typeof d!="string"&&(h[d.name]=d)}),this.root.querySelectorAll("button[data-vvw-control]").forEach(d=>{const g=d;g.addEventListener("click",p=>{const x=p.currentTarget.dataset.vvwControl,u=h[x],I=this.currentChildren.images.find(S=>S.index===this.currentIndex);u&&I&&(u.onClick.constructor.name==="AsyncFunction"?(g.classList.add("vvw--loading"),u.onClick(I,this).finally(()=>{g.classList.remove("vvw--loading")})):u.onClick(I,this))})}),this.initFunction(this),requestAnimationFrame(()=>{var d;(d=this.root)==null||d.addEventListener("transitionend",()=>{var g,p;(g=this.root)==null||g.classList.add("vvw--settled"),this.waitForImagesToLoad(),(p=this.qs(".vvw-bg"))==null||p.addEventListener("click",x=>{x.preventDefault(),this.close()}),this.imageState.reset()},{once:!0}),this.root.classList.add("vvw--active"),this.displayActiveIndex(),this.options.onOpen&&this.options.onOpen(this),this.options.onImageView&&this.options.onImageView(r)})}async close(t=!0){L.somethingOpened===this&&this.root&&(t?await new Promise(e=>{let i=0;this.root.addEventListener("transitionend",o=>{o.target===this.root&&(i++,i===2&&this.elements instanceof NodeList&&this.elements.forEach(a=>{a.style.opacity=""}),i===3&&e(null))}),this.root.classList.add("vvw--closing")}):this.elements instanceof NodeList&&this.elements.forEach(e=>{e.style.opacity=""}),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="",L.somethingOpened=null,this.closeFunction(this),this.options.onClose&&this.options.onClose(this))}next(){if(L.somethingOpened!==this)return;const t=(this.currentIndex+1)%this.elements.length;this.view(t,{next:!0,prev:!1})}prev(){if(L.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 L.somethingOpened!==this?-1:this.currentIndex}view(t,e){if(L.somethingOpened!==this||t<0||t>=this.elements.length)return;const n=this.currentIndex;this.currentIndex=t;const i=this.abortController;i==null||i.abort(),this.abortController=new AbortController,this.swap(n,e)}}function it(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let e=0;e<t.length;e++){const n=t[e];if(!(n.dataset.vistaviewSrc||n.getAttribute("href")||n.getAttribute("src")||""))return`Element at index ${e} is missing 'src' / 'data-vistaview-src' / 'href' attribute.`}else{const e=s;for(let n=0;n<e.length;n++)if(!e[n].src)return`Element at index ${n} is missing 'src' attribute.`}return t||s}function nt({elements:s,...t}){if(!s)throw new Error("No elements");let e=it(s);if(typeof e=="string")return null;const n=new et(e,t);return{open:(i=0)=>n.open(i),close:()=>n.close(),next:()=>n.next(),prev:()=>n.prev(),destroy:()=>n.destroy(),getCurrentIndex:()=>n.getCurrentIndex(),view:i=>{n.view(i)}}}v.DefaultOptions=M,v.vistaView=nt,v.vistaViewDownload=A,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
11
+ </div>`)}const T={animationDurationBase:333,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:.5,preloads:1,keyboardListeners:!0,arrowOnSmallScreens:!1,rapidLimit:222,controls:{topLeft:["indexDisplay"],topRight:["zoomIn","zoomOut",F(),"close"],bottomLeft:["description"]}};function U(s){}function V(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",K(s)}function K(s){let t={x:0,y:0},e={x:0,y:0},i=null;s.registerPointerListener(n=>{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}),n.event==="move"){e={x:n.pointer.x,y:n.pointer.y};const o=e.x-t.x,a=e.y-t.y;if(!i&&Math.abs(a)>Math.abs(o)||i==="y"){const r=a/window.innerHeight*100;s.imageContainer.style.transition="none",s.imageContainer.style.transform=`translateY(${r}vh)`,i="y"}else if(!i&&Math.abs(o)>Math.abs(a)||i==="x"){const r=o/window.innerWidth*100;s.imageContainer.style.transition="none",s.imageContainer.style.transform=`translateX(${r}vw)`,i="x"}}if(n.event==="up"||n.event==="cancel"){let o=function(a){var r;(r=s.imageContainer)==null||r.addEventListener("transitionend",function h(){var c;(c=s.imageContainer)==null||c.removeEventListener("transitionend",h),s.imageContainer.style.transition="",s.imageContainer.style.transform=""}),s.imageContainer.style.transition="transform 222ms ease",s.imageContainer.style.transform=a};if(i==="y"){const a=e.y-t.y,r=n.pointer.movementY,h=8;s.imageContainer.style.transition="",a>0&&Math.abs(r)>h||a<0&&Math.abs(r)>h?(s.imageContainer.style.transition="transform 222ms ease",s.imageContainer.style.transform="translateY(0vh)",s.close()):o("translateY(0vh)")}if(i==="x"){const a=e.x-t.x,r=n.pointer.movementX,h=8;s.imageContainer.style.transition="",a>0&&Math.abs(r)>h?s.prev():a<0&&Math.abs(r)>h?s.next():o("translateX(0vw)")}i=null,t={x:0,y:0},e={x:0,y:0}}}})}function _(s){}async function G({vistaView:{isReducedMotion:s},htmlElements:{to:t},index:{from:e,to:i},vistaView:{elements:n,imageContainer:o,options:a}},r){if(!t||r.aborted||s||!(Math.abs(i-e)===1||e===0&&i===n.length-1||e===n.length-1&&i===0))return;const c=Math.round(a.animationDurationBase*100)/100;return new Promise(m=>{o.addEventListener("transitionend",()=>{m(()=>{o.style.transition="",o.style.transform=""})},{once:!0});const f=i===e+1||e===n.length-1&&i===0?"translateX(-100vw)":"translateX(100vw)";o.style.transition=`transform ${c}ms ease`,o.style.transform=f})}class J{constructor({elm:t,listeners:e}){l(this,"pointers",[]);l(this,"elm");l(this,"listeners",[]);l(this,"lastPointerDownId",null);l(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)}});l(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}))});l(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})))});l(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(o=>o.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(o=>o({event:"up",pointer:i,pointers:this.pointers,lastPointerLen:n}))});l(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(o=>o.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(o=>o({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 Q{constructor(t,e){l(this,"maxZoomLevel");l(this,"image",null);l(this,"rect",null);l(this,"initialCenter",{x:0,y:0});l(this,"maxDimension",{width:0});l(this,"minDimension",{initialWidth:0,initialHeight:0,minWidth:0,closingWidth:0});l(this,"accumulatedTranslate",{x:0,y:0});l(this,"scale",1);l(this,"translate",{x:0,y:0});l(this,"onScale",null);l(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=L(t.x-this.initialCenter.x),this.translate.y=L(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(z(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=L(i/this.rect.width);const n=this.rect.left+this.rect.width/2,o=this.rect.top+this.rect.height/2,a=this.initialCenter.x-n,r=this.initialCenter.y-o,h=a*(1-this.scale),c=r*(1-this.scale),m=e.x-this.initialCenter.x,f=e.y-this.initialCenter.y;this.translate.x=L(h+m),this.translate.y=L(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:o,y:a})=>{if(i)return;if(Math.abs(o)<.001&&Math.abs(a)<.001)return this.normalize();o*=.9,a*=.9;const r=this.image.getBoundingClientRect();this.translate.x=L(this.translate.x+o),this.translate.y=L(this.translate.y+a),r.right<window.innerWidth/2&&(this.translate.x+=(window.innerWidth/2-r.right)*.1,o*=.7),r.left>window.innerWidth/2&&(this.translate.x-=(r.left-window.innerWidth/2)*.1,o*=.7),r.bottom<window.innerHeight/2&&(this.translate.y+=(window.innerHeight/2-r.bottom)*.1,a*=.7),r.top>window.innerHeight/2&&(this.translate.y-=(r.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:o,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.snapToTargetIfClose(this.rect.width*this.scale,this.minDimension.initialWidth),i=this.snapToTargetIfClose(this.rect.height*this.scale,this.minDimension.initialHeight);if(this.image.style.width=`${e}px`,this.image.style.height=`${i}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(),e<=this.minDimension.closingWidth)return this.clean(),!0;if(e<this.minDimension.initialWidth)this.accumulatedTranslate.x=0,this.accumulatedTranslate.y=0,requestAnimationFrame(()=>{const n=this.image;n&&(n.addEventListener("transitionend",()=>{n&&(this.clean(),this.rect=null)},{once:!0}),n.style.transition="all 222ms ease",n.style.width=`${this.minDimension.initialWidth}px`,n.style.height=`${this.minDimension.initialHeight}px`,n.style.left="50%",n.style.top="50%")});else if(t){let n=!1;if(this.rect.right<window.innerWidth/2&&(n=!0,this.accumulatedTranslate.x+=window.innerWidth/2-this.rect.right),this.rect.left>window.innerWidth/2&&(n=!0,this.accumulatedTranslate.x-=this.rect.left-window.innerWidth/2),this.rect.bottom<window.innerHeight/2&&(n=!0,this.accumulatedTranslate.y+=window.innerHeight/2-this.rect.bottom),this.rect.top>window.innerHeight/2&&(n=!0,this.accumulatedTranslate.y-=this.rect.top-window.innerHeight/2),n){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 tt{constructor(){l(this,"fiolast",{})}fio(t,e,i=50){const o=Date.now()-(this.fiolast[e]??0),a=()=>{this.fiolast[e]=Date.now(),t()};if(!this.fiolast[e]){a();return}o>=i&&a()}}const C={somethingOpened:null};class et{constructor(t,e={}){l(this,"options");l(this,"elements");l(this,"isReducedMotion");l(this,"currentIndex",-1);l(this,"currentChildren",null);l(this,"setupFunction",U);l(this,"initFunction",V);l(this,"closeFunction",_);l(this,"transitionFunction",G);l(this,"pointers",null);l(this,"imageState");l(this,"root",null);l(this,"imageContainer",null);l(this,"onClickElements",t=>{t.preventDefault();const e=t.currentTarget;e.dataset.vistaIdx&&this.open(parseInt(e.dataset.vistaIdx))});l(this,"defaultOnClickHandler",t=>t.preventDefault());l(this,"abortController",null);l(this,"throttle",new tt);l(this,"lastSwapTime",0);l(this,"isZoomedIn",!1);l(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}});l(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()});l(this,"onResizeHandler",()=>{this.currentChildren.htmls.forEach((t,e)=>{const i=this.currentChildren.images[e],n=t.querySelector("img.vvw-img-hi"),o=t.querySelector("img.vvw-img-lo");if(M(i,n,o,!1),n.classList.contains("vvw--loaded")){const{width:a,height:r}=W(n);n.style.setProperty("--vvw-current-w",`${a}px`),n.style.setProperty("--vvw-current-h",`${r}px`),n.dataset.vvwWidth=a.toString(),n.dataset.vvwHeight=r.toString()}})});l(this,"pointerListeners",[]);l(this,"getInternalPointerListener",()=>{const t=this.imageState;let e=0,i=!1,n=()=>{};return o=>{if(o.event==="down"){if(n(),this.isZoomedIn&&o.pointers.length===1){const a=this.pointers.getCentroid();t.setInitialCenter(a)}if(o.pointers.length>=2){i=!0;const a=this.pointers.getCentroid();e=this.pointers.getPointerDistance(o.pointers[0],o.pointers[1]),t.setInitialCenter(a)}}else if(o.event==="move"){if(this.isZoomedIn&&o.pointers.length===1&&o.lastPointerLen===0){const a=this.pointers.getCentroid();t.move(a)}if(o.pointers.length>=2&&i){const a=this.pointers.getCentroid(),r=this.pointers.getPointerDistance(o.pointers[0],o.pointers[1]);t.scaleMove(r/e,a)}}else(o.event==="up"||o.event==="cancel")&&(i||this.isZoomedIn)&&(i?(i=!1,t.normalize()&&requestAnimationFrame(()=>{this.close()})):this.isZoomedIn&&o.pointers.length===0&&(n=t.moveAndNormalize(o.pointer)));this.pointerListeners.forEach(a=>a({...o,hasInternalExecution:this.isZoomedIn||i}))}});this.elements=t,this.options={...T,...e,controls:{...T.controls,...e.controls}},this.imageState=new Q(this.options.maxZoomLevel,i=>{var n,o,a,r,h,c;i.isMin?(this.isZoomedIn=!1,(n=this.qs(".vvw-zoom-out"))==null||n.setAttribute("disabled","true"),(o=this.qs('.vvw-item[data-vvw-idx="'+this.currentIndex+'"]'))==null||o.style.setProperty("pointer-events","none")):(this.isZoomedIn=!0,(a=this.qs(".vvw-zoom-out"))==null||a.removeAttribute("disabled"),(r=this.qs('.vvw-item[data-vvw-idx="'+this.currentIndex+'"]'))==null||r.style.setProperty("pointer-events","auto")),i.isMax?(h=this.qs(".vvw-zoom-in"))==null||h.setAttribute("disabled","true"):(c=this.qs(".vvw-zoom-in"))==null||c.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:o,images:a}=this.getChildElements(i,n),r=this.imageContainer,h=this.currentChildren,c={htmlElements:{from:h.htmls,to:o},images:{from:h.images,to:a},index:{from:t,to:this.currentIndex},via:e||{next:!1,prev:!1},vistaView:this};this.setupFunction(c),this.currentChildren={htmls:o,images:a},this.displayActiveIndex();const m=this.abortController.signal,f=performance.now(),E=f-this.lastSwapTime<this.options.rapidLimit;let y=null;E||(y=await this.transitionFunction(c,m)),this.lastSwapTime=f;const d=o[Math.floor(o.length/2)].dataset.vvwIdx,g=r.querySelector(`.vvw-item[data-vvw-idx="${d}"] img.vvw-img-hi`),p=g.getAttribute("style")||"",x=g.classList.contains("vvw--loaded"),u=g.width,I=g.height;this.imageState.reset(),r.innerHTML="",y instanceof Function&&y(),o.forEach(D=>{const b=D.querySelector("img.vvw-img-hi");D.dataset.vvwPos==="0"&&!m.aborted&&p&&x&&u&&I&&(b.classList.add("vvw--loaded"),b.classList.add("vvw--ready"),b.setAttribute("style",p),b.width=u,b.height=I,b.dataset.vvwWidth=u.toString(),b.dataset.vvwHeight=I.toString()),r.appendChild(D),b.classList.contains("vvw--ready")&&(this.imageState.setCurrentImage(b),this.imageState.setInitialCenter())}),this.waitForImagesToLoad(),this.options.onImageView&&this.options.onImageView(c)}getChildElements(t,e){const i=[],n=[];for(let o=-t;o<=t;o++){const a=(e+o+this.elements.length)%this.elements.length,r=this.elements[a],h=r instanceof HTMLImageElement?r:r instanceof HTMLAnchorElement&&r.querySelector("img")||void 0,c=r instanceof HTMLElement?{index:a,imageElm:h instanceof HTMLImageElement?h:void 0,anchorElm:r instanceof HTMLAnchorElement?r:void 0,src:r.dataset.vistaviewSrc||r.getAttribute("href")||r.getAttribute("src")||"",thumb:r.dataset.vistaviewThumb||(h instanceof HTMLImageElement?h.getAttribute("src"):void 0)||r.getAttribute("href")||void 0,alt:h instanceof HTMLImageElement&&h.getAttribute("alt")||void 0}:{index:a,...r};n.push(c),i.push(B(c,o))}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((r,h)=>{r.style.opacity="",h===t&&(r.style.opacity="0")});const e=this.qs(".vvw-index"),i=`${t+1}`,n=`${this.elements.length}`;e&&(e.textContent=`${i} / ${n}`);const o=this.qs(".vvw-desc");if(o){const r=(a=this.currentChildren)==null?void 0:a.images.find(c=>c.index===t),h=(r==null?void 0:r.alt)||"";h?(o.textContent=h,o.setAttribute("aria-label",`Image ${i} of ${n}: ${h}`)):(o.textContent="",o.setAttribute("aria-label",`Image ${i} of ${n}`))}}waitForImagesToLoad(){this.imageContainer.querySelectorAll("img.vvw-img-hi:not(.vvw--loaded)").forEach(i=>{const n=i,o=()=>{var r;n.width=n.naturalWidth,n.height=n.naturalHeight;const a=(r=n.parentElement)==null?void 0:r.matches(`[data-vvw-idx="${this.currentIndex}"]`);n.addEventListener("transitionend",()=>{a&&(this.imageState.setCurrentImage(n),this.imageState.setInitialCenter()),n.classList.add("vvw--ready")},{once:!0}),n.classList.add("vvw--loaded"),requestAnimationFrame(()=>{const{width:h,height:c}=W(n);n.style.setProperty("--vvw-current-w",`${h}px`),n.style.setProperty("--vvw-current-h",`${c}px`),n.dataset.vvwWidth=h.toString(),n.dataset.vvwHeight=c.toString(),n.style.setProperty("--vvw-current-radius","0px")})};if(n.complete&&n.naturalWidth!==0){o();return}n.addEventListener("load",()=>{o()}),n.addEventListener("error",()=>{var r;n.classList.add("vvw--loaderror");const a=document.createElement("p");a.className="vvw-img-err",a.setAttribute("role","alert"),a.textContent="Error loading image",(r=n.parentNode)==null||r.appendChild(a)})})}registerPointerListener(t){this.pointerListeners.push(t)}unregisterPointerListeners(){this.pointerListeners=[]}open(t=0){var c,m,f,E,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}`);const i=this.options.preloads||0,n=t,{images:o,htmls:a}=this.getChildElements(i,n),r={htmlElements:{from:null,to:a},images:{from:null,to:o},index:{from:null,to:this.currentIndex},via:{next:!1,prev:!1},vistaView:this};this.setupFunction(r),this.currentChildren={htmls:a,images:o},a.forEach(d=>{this.imageContainer.appendChild(d)}),(c=this.qs(".vvw-close"))==null||c.addEventListener("click",()=>this.close()),(m=this.qs(".vvw-zoom-in"))==null||m.addEventListener("click",()=>this.zoomIn()),(f=this.qs(".vvw-zoom-out"))==null||f.addEventListener("click",()=>this.zoomOut()),(E=this.qs(".vvw-prev>button"))==null||E.addEventListener("click",()=>this.prev()),(y=this.qs(".vvw-next>button"))==null||y.addEventListener("click",()=>this.next()),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("wheel",this.onScroll,{passive:!1}),window.addEventListener("resize",this.onResizeHandler),this.pointers=new J({elm:this.imageContainer,listeners:[this.getInternalPointerListener()]});const h={};[...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(d=>{typeof d!="string"&&(h[d.name]=d)}),this.root.querySelectorAll("button[data-vvw-control]").forEach(d=>{const g=d;g.addEventListener("click",p=>{const x=p.currentTarget.dataset.vvwControl,u=h[x],I=this.currentChildren.images.find(D=>D.index===this.currentIndex);u&&I&&(u.onClick.constructor.name==="AsyncFunction"?(g.classList.add("vvw--loading"),u.onClick(I,this).finally(()=>{g.classList.remove("vvw--loading")})):u.onClick(I,this))})}),this.initFunction(this),requestAnimationFrame(()=>{var d;(d=this.root)==null||d.addEventListener("transitionend",()=>{var g,p;(g=this.root)==null||g.classList.add("vvw--settled"),this.waitForImagesToLoad(),(p=this.qs(".vvw-bg"))==null||p.addEventListener("click",x=>{x.preventDefault(),this.close()}),this.imageState.reset()},{once:!0}),this.root.classList.add("vvw--active"),this.displayActiveIndex(),this.options.onOpen&&this.options.onOpen(this),this.options.onImageView&&this.options.onImageView(r)})}async close(t=!0){C.somethingOpened===this&&this.root&&(t?await new Promise(e=>{let n=0;this.root.addEventListener("transitionend",o=>{o.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=""}),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 it(s){let t=null;if(typeof s=="string"?t=document.querySelectorAll(s):s instanceof NodeList&&(t=s),t)for(let e=0;e<t.length;e++){const 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 nt({elements:s,...t}){if(!s)throw new Error("No elements");let e=it(s);if(typeof e=="string")return null;const i=new et(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=T,v.vistaView=nt,v.vistaViewDownload=F,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vistaview",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "A lightweight, zero-dependency image lightbox library with smooth animations and touch support",
5
5
  "keywords": [
6
6
  "image",