vistaview 0.3.7 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vistaview.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var X = Object.defineProperty;
2
2
  var Y = (s, t, i) => t in s ? X(s, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[t] = i;
3
- var w = (s, t, i) => Y(s, typeof t != "symbol" ? t + "" : t, i);
3
+ var y = (s, t, i) => Y(s, typeof t != "symbol" ? t + "" : t, i);
4
4
  function z(s) {
5
5
  const t = getComputedStyle(s), i = s.getBoundingClientRect();
6
6
  return {
@@ -16,11 +16,11 @@ function z(s) {
16
16
  naturalHeight: s.naturalHeight
17
17
  };
18
18
  }
19
- let S = null;
19
+ let P = null;
20
20
  function V() {
21
- return S || (window.trustedTypes || (window.trustedTypes = {
21
+ return P || (window.trustedTypes || (window.trustedTypes = {
22
22
  createPolicy: (s, t) => t
23
- }), S = window.trustedTypes.createPolicy("vistaView-policy", {
23
+ }), P = window.trustedTypes.createPolicy("vistaView-policy", {
24
24
  createHTML: (s) => s,
25
25
  // HTML is generated by us, not user input
26
26
  createScript: () => {
@@ -29,7 +29,7 @@ function V() {
29
29
  createScriptURL: () => {
30
30
  throw new Error("Not implemented");
31
31
  }
32
- }), S);
32
+ }), P);
33
33
  }
34
34
  function W(s) {
35
35
  const i = V().createHTML(s), n = document.createElement("template");
@@ -40,30 +40,30 @@ function W(s) {
40
40
  function R(s) {
41
41
  return s && !/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(s.trim()) && s;
42
42
  }
43
- function B(s) {
44
- const i = window.getComputedStyle(s).objectFit || "", { width: n, height: e } = s.getBoundingClientRect(), a = s.naturalWidth, d = s.naturalHeight;
43
+ function _(s) {
44
+ const i = window.getComputedStyle(s).objectFit || "", { width: n, height: e } = s.getBoundingClientRect(), r = s.naturalWidth, d = s.naturalHeight;
45
45
  if (!i)
46
46
  return { width: n, height: e };
47
- if (!a || !d)
47
+ if (!r || !d)
48
48
  return { width: n, height: e };
49
- const o = a / d, l = n / e;
49
+ const o = r / d, a = n / e;
50
50
  switch (i) {
51
51
  case "fill":
52
52
  return { width: n, height: e };
53
53
  case "none":
54
- return { width: a, height: d };
54
+ return { width: r, height: d };
55
55
  case "contain":
56
- return o > l ? { width: n, height: n / o } : { width: e * o, height: e };
56
+ return o > a ? { width: n, height: n / o } : { width: e * o, height: e };
57
57
  case "cover":
58
- return o < l ? { width: n, height: n / o } : { width: e * o, height: e };
58
+ return o < a ? { width: n, height: n / o } : { width: e * o, height: e };
59
59
  case "scale-down": {
60
- const h = { width: a, height: d }, r = o > l ? { width: n, height: n / o } : { width: e * o, height: e };
61
- return r.width <= h.width && r.height <= h.height ? r : h;
60
+ const c = { width: r, height: d }, l = o > a ? { width: n, height: n / o } : { width: e * o, height: e };
61
+ return l.width <= c.width && l.height <= c.height ? l : c;
62
62
  }
63
63
  }
64
64
  return { width: n, height: e };
65
65
  }
66
- function H(s) {
66
+ function T(s) {
67
67
  const t = window.innerWidth, i = window.innerHeight, n = s.naturalWidth, e = s.naturalHeight;
68
68
  if (!n || !e)
69
69
  throw console.error("Error", s), new Error("Image natural dimensions are zero");
@@ -72,31 +72,31 @@ function H(s) {
72
72
  width: n,
73
73
  height: e
74
74
  };
75
- const a = n / e, d = t / i;
76
- let o, l;
77
- return a > d ? (o = t, l = t / a) : (l = i, o = i * a), {
75
+ const r = n / e, d = t / i;
76
+ let o, a;
77
+ return r > d ? (o = t, a = t / r) : (a = i, o = i * r), {
78
78
  width: o,
79
- height: l
79
+ height: a
80
80
  };
81
81
  }
82
- function T(s, t) {
83
- const i = window.innerHeight, n = window.innerWidth, e = s, a = t, d = Math.max(0, (e - n) / 2) + n / 2, o = Math.max(0, (a - i) / 2) + i / 2, l = -d, h = -o;
82
+ function H(s, t) {
83
+ const i = window.innerHeight, n = window.innerWidth, e = s, r = t, d = Math.max(0, (e - n) / 2) + n / 2, o = Math.max(0, (r - i) / 2) + i / 2, a = -d, c = -o;
84
84
  return {
85
85
  maxDiffX: d,
86
- minDiffY: h,
86
+ minDiffY: c,
87
87
  maxDiffY: o,
88
- minDiffX: l
88
+ minDiffX: a
89
89
  };
90
90
  }
91
- const _ = '<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>', F = '<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>', N = '<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>', U = '<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>', K = '<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>', j = '<svg viewBox="0 0 24 24"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';
91
+ const B = '<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>', F = '<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>', N = '<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>', U = '<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>', K = '<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>', j = '<svg viewBox="0 0 24 24"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';
92
92
  function G() {
93
93
  return {
94
94
  name: "download",
95
95
  icon: j,
96
96
  onClick: async (s) => {
97
- var a;
97
+ var r;
98
98
  const t = await fetch(s.src), i = await t.blob(), n = t.url, e = document.createElement("a");
99
- e.href = URL.createObjectURL(i), e.download = ((a = n.split("/").pop()) == null ? void 0 : a.split("?")[0].split("#")[0]) || "download", document.body.appendChild(e), e.click(), document.body.removeChild(e);
99
+ e.href = URL.createObjectURL(i), e.download = ((r = n.split("/").pop()) == null ? void 0 : r.split("?")[0].split("#")[0]) || "download", document.body.appendChild(e), e.click(), document.body.removeChild(e);
100
100
  }
101
101
  };
102
102
  }
@@ -119,18 +119,18 @@ function J(s) {
119
119
  return `<button data-vistaview-custom-control="${s.name}">${s.icon}</button>`;
120
120
  }
121
121
  function q(s, t) {
122
- var r, c;
123
- const i = s.imageElm ? getComputedStyle(s.imageElm) : null, n = (i == null ? void 0 : i.objectFit) || "", e = ((r = s.imageElm) == null ? void 0 : r.naturalWidth) || "", a = ((c = s.imageElm) == null ? void 0 : c.naturalHeight) || "", d = (i == null ? void 0 : i.width) || "", o = (i == null ? void 0 : i.height) || "", l = document.createElement("div");
124
- l.className = "vistaview-item", l.dataset.vistaviewPos = `${t !== void 0 ? t : ""}`, l.dataset.vistaviewIndex = s.index.toString();
125
- const h = W(`<img class="vistaview-image-lowres"
122
+ var l, h;
123
+ const i = s.imageElm ? getComputedStyle(s.imageElm) : null, n = (i == null ? void 0 : i.objectFit) || "", e = ((l = s.imageElm) == null ? void 0 : l.naturalWidth) || "", r = ((h = s.imageElm) == null ? void 0 : h.naturalHeight) || "", d = (i == null ? void 0 : i.width) || "", o = (i == null ? void 0 : i.height) || "", a = document.createElement("div");
124
+ a.className = "vistaview-item", a.dataset.vistaviewPos = `${t !== void 0 ? t : ""}`, a.dataset.vistaviewIndex = s.index.toString();
125
+ const c = W(`<img class="vistaview-image-lowres"
126
126
  style="${n ? `object-fit:${n};` : ""}${d ? `width:${d};` : ""}${o ? `height:${o};` : ""}"
127
127
  src="${s.thumb || s.src}"
128
128
  alt="${s.alt || ""}"
129
129
  ${e ? `width="${e}"` : ""}
130
- ${a ? `height="${a}"` : ""}
130
+ ${r ? `height="${r}"` : ""}
131
131
  />
132
132
  <img class="vistaview-image-highres" src="${s.src}" alt="${s.alt || ""}" />`);
133
- return l.appendChild(h), l;
133
+ return a.appendChild(c), a;
134
134
  }
135
135
  function Q({
136
136
  controls: s,
@@ -143,67 +143,67 @@ function Q({
143
143
  <div class="vistaview-image-container"></div>
144
144
  <div class="vistaview-top-bar vistaview-ui"><div>${i(s == null ? void 0 : s.topLeft)}</div><div>${i(s == null ? void 0 : s.topCenter)}</div><div>${i(s == null ? void 0 : s.topRight)}</div></div>
145
145
  <div class="vistaview-bottom-bar vistaview-ui"><div>${i(s == null ? void 0 : s.bottomLeft)}</div><div>${i(s == null ? void 0 : s.bottomCenter)}</div><div>${i(s == null ? void 0 : s.bottomRight)}</div></div>
146
- <div class="vistaview-prev-btn vistaview-ui"><button>${_}</button></div>
146
+ <div class="vistaview-prev-btn vistaview-ui"><button>${B}</button></div>
147
147
  <div class="vistaview-next-btn vistaview-ui"><button>${F}</button></div>
148
148
  </div>
149
149
  </div>`
150
150
  );
151
151
  }
152
- let A = null, $ = null, Z = null, M = null;
152
+ let A = null, M = null, Z = null, $ = null;
153
153
  function tt(s) {
154
154
  O(s);
155
155
  const t = s.imageContainerElm, i = s.elements.length;
156
156
  if (!t) return;
157
- let n = 0, e = 0, a = 0, d = 0, o = null, l = 0, h = !1;
158
- A = (r) => {
159
- r.preventDefault(), r.stopPropagation(), s.isZoomed === !1 && (h = !0, n = r.pageX, e = r.pageY, a = r.pageX, d = r.pageY, l = Date.now(), o = null, t.setPointerCapture(r.pointerId));
160
- }, $ = (r) => {
161
- if (r.preventDefault(), r.stopPropagation(), s.isZoomed !== !1 || !h) return;
162
- const c = r.pageX - n, m = r.pageY - e;
163
- a = r.pageX, d = r.pageY, Math.abs(c) >= Math.abs(m) && (o === null || o === !0) ? (t.style.setProperty("--vistaview-pointer-diff-x", `${c}px`), o = !0) : Math.abs(m) > Math.abs(c) && (o === null || o === !1) && (t.style.setProperty("--vistaview-pointer-diff-y", `${m}px`), o = !1);
164
- }, M = (r) => {
165
- if (r.preventDefault(), r.stopPropagation(), t.releasePointerCapture(r.pointerId), s.isZoomed !== !1 || !h) return;
166
- h = !1, o = null;
167
- const c = Array.from(t.querySelectorAll(".vistaview-item"));
168
- t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), c.forEach((m) => {
157
+ let n = 0, e = 0, r = 0, d = 0, o = null, a = 0, c = !1;
158
+ A = (l) => {
159
+ l.preventDefault(), l.stopPropagation(), s.isZoomed === !1 && (c = !0, n = l.pageX, e = l.pageY, r = l.pageX, d = l.pageY, a = Date.now(), o = null, t.setPointerCapture(l.pointerId));
160
+ }, M = (l) => {
161
+ if (l.preventDefault(), l.stopPropagation(), s.isZoomed !== !1 || !c) return;
162
+ const h = l.pageX - n, m = l.pageY - e;
163
+ r = l.pageX, d = l.pageY, Math.abs(h) >= Math.abs(m) && (o === null || o === !0) ? (t.style.setProperty("--vistaview-pointer-diff-x", `${h}px`), o = !0) : Math.abs(m) > Math.abs(h) && (o === null || o === !1) && (t.style.setProperty("--vistaview-pointer-diff-y", `${m}px`), o = !1);
164
+ }, $ = (l) => {
165
+ if (l.preventDefault(), l.stopPropagation(), t.releasePointerCapture(l.pointerId), s.isZoomed !== !1 || !c) return;
166
+ c = !1, o = null;
167
+ const h = Array.from(t.querySelectorAll(".vistaview-item"));
168
+ t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), h.forEach((m) => {
169
169
  m.style.transition = "", m.style.translate = "";
170
170
  });
171
- }, Z = (r) => {
172
- if (r.preventDefault(), r.stopPropagation(), t.releasePointerCapture(r.pointerId), s.isZoomed !== !1 || !h) return;
173
- h = !1;
174
- const c = Array.from(t.querySelectorAll(".vistaview-item")), m = a - n, f = d - e, u = Date.now() - l, v = m / u, y = f / u, p = s.options.touchSpeedThreshold || 0.5, x = c.find(
171
+ }, Z = (l) => {
172
+ if (l.preventDefault(), l.stopPropagation(), t.releasePointerCapture(l.pointerId), s.isZoomed !== !1 || !c) return;
173
+ c = !1;
174
+ const h = Array.from(t.querySelectorAll(".vistaview-item")), m = r - n, v = d - e, f = Date.now() - a, u = m / f, w = v / f, g = s.options.touchSpeedThreshold || 0.5, b = h.find(
175
175
  (E) => E.dataset.vistaviewPos === "0"
176
- ), b = Number(x.dataset.vistaviewIndex);
177
- function g() {
178
- c[0].removeEventListener("transitionend", g), t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), c.forEach((E) => {
176
+ ), I = Number(b.dataset.vistaviewIndex);
177
+ function p() {
178
+ h[0].removeEventListener("transitionend", p), t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), h.forEach((E) => {
179
179
  E.style.transition = "", E.style.translate = "";
180
180
  });
181
181
  }
182
- function I(E = "0%", L = "0%") {
183
- c.forEach((D) => {
182
+ function x(E = "0%", L = "0%") {
183
+ h.forEach((D) => {
184
184
  D.style.transition = `translate ${s.options.animationDurationBase * 0.5}ms ease-out`, D.style.translate = `${E} ${L}`;
185
185
  });
186
186
  }
187
- if (v < -p || v > p) {
187
+ if (u < -g || u > g) {
188
188
  let E = function() {
189
- c[0].removeEventListener("transitionend", E), setTimeout(() => {
189
+ h[0].removeEventListener("transitionend", E), setTimeout(() => {
190
190
  const L = s.isReducedMotion;
191
- s.isReducedMotion = !0, g(), s.view(
192
- v < -p ? (b + 1) % i : (b - 1 + i) % i,
191
+ s.isReducedMotion = !0, p(), s.view(
192
+ u < -g ? (I + 1) % i : (I - 1 + i) % i,
193
193
  {
194
- next: v < -p,
195
- prev: v > p
194
+ next: u < -g,
195
+ prev: u > g
196
196
  }
197
197
  ), s.isReducedMotion = L;
198
198
  }, 100);
199
199
  };
200
- I(v < -p ? "-100%" : "100%"), c[0].addEventListener("transitionend", E);
201
- } else y < -p || y > p ? (s.close(), I("0%", "0%")) : (c[0].addEventListener("transitionend", g), I("0%"));
202
- }, t.addEventListener("pointermove", $), t.addEventListener("pointerup", Z), t.addEventListener("pointerdown", A), t.addEventListener("pointercancel", M);
200
+ x(u < -g ? "-100%" : "100%"), h[0].addEventListener("transitionend", E);
201
+ } else w < -g || w > g ? (s.close(), x("0%", "0%")) : (h[0].addEventListener("transitionend", p), x("0%"), u === 0 && w === 0 && s.zoomIn());
202
+ }, t.addEventListener("pointermove", M), t.addEventListener("pointerup", Z), t.addEventListener("pointerdown", A), t.addEventListener("pointercancel", $);
203
203
  }
204
204
  function O(s) {
205
205
  const t = s.imageContainerElm;
206
- t && ($ && t.removeEventListener("pointermove", $), Z && t.removeEventListener("pointerup", Z), A && t.removeEventListener("pointerdown", A), M && t.removeEventListener("pointercancel", M));
206
+ t && (M && t.removeEventListener("pointermove", M), Z && t.removeEventListener("pointerup", Z), A && t.removeEventListener("pointerdown", A), $ && t.removeEventListener("pointercancel", $));
207
207
  }
208
208
  const et = (s) => {
209
209
  tt(s);
@@ -220,60 +220,49 @@ const et = (s) => {
220
220
  htmlElements: { from: s, to: t },
221
221
  images: { to: i },
222
222
  via: { next: n, prev: e },
223
- options: a,
223
+ options: r,
224
224
  isReducedMotion: d
225
225
  // index: { from: fromIndex, to: toIndex },
226
226
  }, o) => {
227
227
  if (!i) throw new Error("VistaView: images is null in defaultTransition()");
228
- const l = s.filter((h) => h.dataset.vistaviewPos === "0" || (n ? h.dataset.vistaviewPos === "1" : h.dataset.vistaviewPos === "-1"));
229
- d || await new Promise((h, r) => {
230
- let c = 0;
228
+ if (d)
229
+ return;
230
+ const a = s.filter((c) => c.dataset.vistaviewPos === "0" || (n ? c.dataset.vistaviewPos === "1" : c.dataset.vistaviewPos === "-1"));
231
+ await new Promise((c, l) => {
232
+ let h = 0;
231
233
  if (o.aborted) {
232
- r(new P("Transition aborted"));
234
+ l(new S("Transition aborted"));
233
235
  return;
234
236
  }
235
- const m = (f) => {
236
- if (o.aborted) {
237
- r(new P("Transition aborted"));
238
- return;
239
- }
240
- if (f.currentTarget.removeEventListener("transitionend", m), c++, c < l.length) return;
241
- const u = t == null ? void 0 : t.find((g) => g.dataset.vistaviewPos === "0"), v = u ? Number(u.dataset.vistaviewIndex) : 0, y = l.find((g) => Number(g.dataset.vistaviewIndex) === v), p = y == null ? void 0 : y.querySelector(
237
+ const m = (v) => {
238
+ if (o.aborted)
239
+ return l(new S("Transition aborted"));
240
+ if (v.currentTarget.removeEventListener("transitionend", m), h++, h < a.length) return;
241
+ const f = t == null ? void 0 : t.find((p) => p.dataset.vistaviewPos === "0"), u = f ? Number(f.dataset.vistaviewIndex) : 0, w = a.find((p) => Number(p.dataset.vistaviewIndex) === u), g = w == null ? void 0 : w.querySelector(
242
242
  ".vistaview-image-highres"
243
243
  );
244
- if (!p) {
245
- r(new Error("current image element not found"));
246
- return;
247
- }
248
- if (!p.classList.contains("vistaview-image-loaded")) {
249
- h(0);
250
- return;
251
- }
252
- if (u == null || u.classList.add("vistaview-image-loaded"), p.classList.contains("vistaview-image-settled")) {
253
- u == null || u.classList.add("vistaview-image-settled"), h(0);
254
- return;
255
- }
256
- let x = 0;
257
- const b = setInterval(() => {
258
- if (o.aborted) {
259
- clearInterval(b), r(new P("Transition aborted"));
260
- return;
261
- }
262
- if (x++, x > a.animationDurationBase / 20 * 1.5) {
263
- clearInterval(b), h(0);
264
- return;
265
- }
266
- p.classList.contains("vistaview-image-settled") && (u == null || u.classList.add("vistaview-image-settled"), clearInterval(b), h(0));
244
+ if (!g)
245
+ return l(new Error("current image element not found"));
246
+ if (!g.classList.contains("vistaview-image-loaded") || g.classList.contains("vistaview-image-settled"))
247
+ return c(0);
248
+ let b = 0;
249
+ const I = setInterval(() => {
250
+ if (o.aborted)
251
+ return clearInterval(I), l(new S("Transition aborted"));
252
+ if (b++, b > r.animationDurationBase / 20 * 1.5)
253
+ return clearInterval(I), c(0);
254
+ if (g.classList.contains("vistaview-image-settled"))
255
+ return f == null || f.classList.add("vistaview-image-settled"), clearInterval(I), c(0);
267
256
  }, 20);
268
257
  };
269
- l.forEach((f) => {
270
- f.style.transition = `translate ${a.animationDurationBase * 0.5}ms ease-out`, f.style.translate = n ? "-100%" : e ? "100%" : "0%", f.addEventListener("transitionend", m);
258
+ a.forEach((v) => {
259
+ v.style.transition = `translate ${r.animationDurationBase * 0.5}ms ease-out`, v.style.translate = n ? "-100%" : e ? "100%" : "0%", v.addEventListener("transitionend", m);
271
260
  });
272
261
  });
273
262
  }, st = (s) => {
274
263
  s.elements instanceof NodeList && s.elements.forEach((t) => t.style.opacity = "1"), O(s);
275
264
  };
276
- class P extends Error {
265
+ class S extends Error {
277
266
  constructor(t) {
278
267
  super(t), this.name = "VistaViewTransitionAbortedError";
279
268
  }
@@ -299,17 +288,20 @@ const k = {
299
288
  };
300
289
  class ot {
301
290
  constructor(t, i) {
302
- w(this, "options");
303
- w(this, "elements");
304
- w(this, "isReducedMotion");
305
- w(this, "currentIndex", {
291
+ y(this, "options");
292
+ y(this, "elements");
293
+ y(this, "isReducedMotion");
294
+ y(this, "currentIndex", {
306
295
  _value: null,
307
296
  _vistaView: null,
308
297
  _via: { next: !1, prev: !1 },
309
298
  set value(t) {
310
- var n;
299
+ var n, e, r;
311
300
  const i = this._value;
312
- this._value = t, (n = this._vistaView) == null || n.swap(i, this._value);
301
+ this._value = t;
302
+ for (const d in (n = this._vistaView) == null ? void 0 : n.transitionAbortControllers)
303
+ (e = this._vistaView) == null || e.transitionAbortControllers[d].abort();
304
+ (r = this._vistaView) == null || r.swap(i, this._value);
313
305
  },
314
306
  get value() {
315
307
  return this._value;
@@ -321,29 +313,30 @@ class ot {
321
313
  this._via = t;
322
314
  }
323
315
  });
324
- w(this, "rootElm", null);
325
- w(this, "imageContainerElm", null);
326
- w(this, "customControls", {});
327
- w(this, "currentImages", null);
328
- w(this, "currentItems", null);
329
- w(this, "navActive", !0);
330
- w(this, "isZoomed", !1);
331
- w(this, "onClickElements", (t) => {
316
+ y(this, "rootElm", null);
317
+ y(this, "imageContainerElm", null);
318
+ y(this, "customControls", {});
319
+ y(this, "currentImages", null);
320
+ y(this, "currentItems", null);
321
+ y(this, "navActive", !0);
322
+ y(this, "isZoomed", !1);
323
+ y(this, "onClickElements", (t) => {
332
324
  t.preventDefault();
333
325
  const i = t.currentTarget;
334
326
  i.dataset.vistaviewIndex && this.open(parseInt(i.dataset.vistaviewIndex));
335
327
  });
336
- w(this, "defaultOnClickHandler", (t) => t.preventDefault());
337
- w(this, "onResizeHandler", null);
338
- w(this, "onKeyDown", null);
339
- w(this, "userSetup", it);
340
- w(this, "userTransition", nt);
341
- w(this, "userClose", st);
342
- w(this, "userInit", et);
343
- w(this, "onZoomedPointerDown", null);
344
- w(this, "onZoomedPointerMove", null);
345
- w(this, "onZoomedPointerUp", null);
346
- w(this, "transitionAbortController", null);
328
+ y(this, "defaultOnClickHandler", (t) => t.preventDefault());
329
+ y(this, "onResizeHandler", null);
330
+ y(this, "onKeyDown", null);
331
+ y(this, "userSetup", it);
332
+ y(this, "userTransition", nt);
333
+ y(this, "userClose", st);
334
+ y(this, "userInit", et);
335
+ y(this, "onZoomedPointerDown", null);
336
+ y(this, "onZoomedPointerMove", null);
337
+ y(this, "onZoomedPointerUp", null);
338
+ y(this, "transitionAbortControllers", {});
339
+ y(this, "loadImageTimeout", null);
347
340
  this.elements = t, this.currentIndex._vistaView = this, this.options = {
348
341
  ...k,
349
342
  ...i || {},
@@ -356,14 +349,14 @@ class ot {
356
349
  });
357
350
  }
358
351
  async swap(t, i) {
359
- var l, h;
352
+ var l, h, m;
360
353
  if (!C.somethingOpened || t === i || t === null) return;
361
- if (this.transitionAbortController && this.transitionAbortController.abort(), !this.imageContainerElm)
354
+ if (!this.imageContainerElm)
362
355
  throw new Error("VistaView: imageContainerElm is null in swap()");
363
356
  this.setIndexDisplay(), this.clearZoom();
364
- const { images: n, positions: e } = this.getCurrentIndexes(i), a = this.getImages(n), d = a.map((r, c) => q(r, e[c])), o = {
357
+ const { images: n, positions: e } = this.getCurrentIndexes(i), r = this.getImages(n), d = r.map((v, f) => q(v, e[f])), o = {
365
358
  htmlElements: { from: this.currentItems, to: d },
366
- images: { from: this.currentImages, to: a },
359
+ images: { from: this.currentImages, to: r },
367
360
  index: { from: t, to: i },
368
361
  via: this.currentIndex.via,
369
362
  container: this.imageContainerElm,
@@ -373,84 +366,96 @@ class ot {
373
366
  isZoomed: this.isZoomed,
374
367
  options: this.options
375
368
  };
376
- this.userSetup(o), this.transitionAbortController = new AbortController();
369
+ this.userSetup(o), (l = this.currentItems) == null || l.forEach((v) => {
370
+ v.classList.add("vistaview-image--ending");
371
+ });
372
+ const a = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
373
+ this.transitionAbortControllers[a] = new AbortController();
377
374
  try {
378
- await this.userTransition(o, this.transitionAbortController.signal);
379
- } catch (r) {
380
- r instanceof P || console.error(r);
375
+ await this.userTransition(o, this.transitionAbortControllers[a].signal);
376
+ } catch (v) {
377
+ v instanceof S || console.warn(v);
381
378
  }
382
- this.imageContainerElm.innerHTML = "", d.forEach((r) => {
383
- const c = r.dataset.vistaviewPos, m = r.dataset.vistaviewIndex;
384
- if (c === "0") {
385
- const f = this.currentItems.find((y) => y.dataset.vistaviewIndex === m), u = r.querySelector(".vistaview-image-highres"), v = f == null ? void 0 : f.querySelector(".vistaview-image-highres");
386
- v && (u.setAttribute("class", v.getAttribute("class") || ""), u.setAttribute("style", v.getAttribute("style") || "")), this.imageContainerElm.appendChild(r);
387
- } else
388
- this.imageContainerElm.appendChild(r);
389
- }), this.setInitialDimPos(), this.currentImages = a, this.currentItems = d, this.loadImages(), this.setCurrentDescription(), this.updateZoomButtonsVisibility(), (h = (l = this.options).onImageView) == null || h.call(l, o);
379
+ delete this.transitionAbortControllers[a];
380
+ const c = d.find((v) => v.dataset.vistaviewPos === "0");
381
+ if (c) {
382
+ const v = c.dataset.vistaviewIndex, f = this.currentItems.find((w) => w.dataset.vistaviewIndex === v), u = f == null ? void 0 : f.querySelector(".vistaview-image-highres");
383
+ if (u) {
384
+ const w = c.querySelector(
385
+ ".vistaview-image-highres"
386
+ );
387
+ w.setAttribute("class", u.getAttribute("class") || ""), w.setAttribute("style", u.getAttribute("style") || ""), w.classList.remove("vistaview-image--zooming"), w.classList.remove("vistaview-image-settled"), u.classList.contains("vistaview-image-loaded") && !u.classList.contains("vistaview-image-settled") && w.classList.remove("vistaview-image-loaded");
388
+ }
389
+ }
390
+ this.imageContainerElm.innerHTML = "", d.forEach((v) => {
391
+ this.imageContainerElm.appendChild(v);
392
+ }), this.setInitialDimPos(), this.currentImages = r, this.currentItems = d, this.setCurrentDescription(), this.updateZoomButtonsVisibility(), (m = (h = this.options).onImageView) == null || m.call(h, o), this.loadImageTimeout && clearTimeout(this.loadImageTimeout), this.loadImageTimeout = setTimeout(() => {
393
+ this.loadImages();
394
+ }, 333);
390
395
  }
391
396
  //
392
397
  setZoomed(t) {
393
- var i, n, e, a, d, o;
398
+ var i, n, e, r, d, o;
394
399
  if (this.isZoomed !== t) {
395
400
  if (this.isZoomed) {
396
- let l = this.isZoomed;
397
- if (l.classList.remove("vistaview-image--zooming"), this.onZoomedPointerDown && ((i = l.parentElement) == null || i.removeEventListener("pointerdown", this.onZoomedPointerDown), this.onZoomedPointerDown = null), this.onZoomedPointerMove && ((n = l.parentElement) == null || n.removeEventListener("pointermove", this.onZoomedPointerMove), this.onZoomedPointerMove = null), this.onZoomedPointerUp && ((e = l.parentElement) == null || e.removeEventListener("pointerup", this.onZoomedPointerUp), this.onZoomedPointerUp = null), l == null || l.style.removeProperty("--pointer-diff-x"), l == null || l.style.removeProperty("--pointer-diff-y"), setTimeout(() => {
398
- l == null || l.classList.remove("vistaview-image--zooming");
401
+ let a = this.isZoomed;
402
+ if (a.classList.remove("vistaview-image--zooming"), this.onZoomedPointerDown && ((i = a.parentElement) == null || i.removeEventListener("pointerdown", this.onZoomedPointerDown), this.onZoomedPointerDown = null), this.onZoomedPointerMove && ((n = a.parentElement) == null || n.removeEventListener("pointermove", this.onZoomedPointerMove), this.onZoomedPointerMove = null), this.onZoomedPointerUp && ((e = a.parentElement) == null || e.removeEventListener("pointerup", this.onZoomedPointerUp), this.onZoomedPointerUp = null), a == null || a.style.removeProperty("--pointer-diff-x"), a == null || a.style.removeProperty("--pointer-diff-y"), setTimeout(() => {
403
+ a == null || a.classList.remove("vistaview-image--zooming");
399
404
  }, 500), this.isZoomed = !1, !t) return;
400
405
  }
401
406
  if (t) {
402
407
  this.isZoomed = t, t.classList.add("vistaview-image--zooming"), t == null || t.style.setProperty("--pointer-diff-x", "0px"), t == null || t.style.setProperty("--pointer-diff-y", "0px");
403
- let l = !1, h = 0, r = 0, c = 0, m = 0, f = 0, u = 0;
404
- this.onZoomedPointerDown = (v) => {
405
- v.preventDefault(), v.stopPropagation(), l = !0, h = v.pageX, r = v.pageY, t.setPointerCapture(v.pointerId);
406
- }, this.onZoomedPointerMove = (v) => {
407
- if (!l) return;
408
- v.preventDefault(), f = v.pageX - h, u = v.pageY - r;
409
- const y = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentWidth) || "0"), p = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentHeight) || "0"), { maxDiffX: x, minDiffY: b, maxDiffY: g, minDiffX: I } = T(
410
- y,
411
- p
412
- ), E = Math.min(x, Math.max(I, c + f)), L = Math.min(g, Math.max(b, m + u));
413
- f = E - c, u = L - m, t == null || t.style.setProperty("--pointer-diff-x", `${E}px`), t == null || t.style.setProperty("--pointer-diff-y", `${L}px`);
414
- }, this.onZoomedPointerUp = (v) => {
415
- l = !1, t.releasePointerCapture(v.pointerId), c += f, m += u, f = 0, u = 0;
416
- }, (a = t == null ? void 0 : t.parentElement) == null || a.addEventListener("pointerdown", this.onZoomedPointerDown), (d = t == null ? void 0 : t.parentElement) == null || d.addEventListener("pointermove", this.onZoomedPointerMove), (o = t == null ? void 0 : t.parentElement) == null || o.addEventListener("pointerup", this.onZoomedPointerUp);
408
+ let a = !1, c = 0, l = 0, h = 0, m = 0, v = 0, f = 0;
409
+ this.onZoomedPointerDown = (u) => {
410
+ u.preventDefault(), u.stopPropagation(), a = !0, c = u.pageX, l = u.pageY, t.setPointerCapture(u.pointerId);
411
+ }, this.onZoomedPointerMove = (u) => {
412
+ if (!a) return;
413
+ u.preventDefault(), v = u.pageX - c, f = u.pageY - l;
414
+ const w = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentWidth) || "0"), g = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentHeight) || "0"), { maxDiffX: b, minDiffY: I, maxDiffY: p, minDiffX: x } = H(
415
+ w,
416
+ g
417
+ ), E = Math.min(b, Math.max(x, h + v)), L = Math.min(p, Math.max(I, m + f));
418
+ v = E - h, f = L - m, t == null || t.style.setProperty("--pointer-diff-x", `${E}px`), t == null || t.style.setProperty("--pointer-diff-y", `${L}px`);
419
+ }, this.onZoomedPointerUp = (u) => {
420
+ a = !1, t.releasePointerCapture(u.pointerId), h += v, m += f, v = 0, f = 0;
421
+ }, (r = t == null ? void 0 : t.parentElement) == null || r.addEventListener("pointerdown", this.onZoomedPointerDown), (d = t == null ? void 0 : t.parentElement) == null || d.addEventListener("pointermove", this.onZoomedPointerMove), (o = t == null ? void 0 : t.parentElement) == null || o.addEventListener("pointerup", this.onZoomedPointerUp);
417
422
  return;
418
423
  }
419
424
  }
420
425
  }
421
426
  zoomIn() {
422
- var a, d, o, l, h;
423
- const t = (a = this.rootElm) == null ? void 0 : a.querySelector(
427
+ var r, d, o, a, c;
428
+ const t = (r = this.rootElm) == null ? void 0 : r.querySelector(
424
429
  '[data-vistaview-pos="0"] .vistaview-image-highres'
425
430
  ), i = t.width, n = t.height;
426
431
  t.dataset.vistaviewInitialWidth || (t.dataset.vistaviewInitialWidth = i.toString()), t.dataset.vistaviewInitialHeight || (t.dataset.vistaviewInitialHeight = n.toString()), this.setZoomed(t);
427
432
  const e = (t.naturalWidth || 0) * this.options.maxZoomLevel;
428
433
  if (i && e && i < e) {
429
- const r = Math.min(i + this.options.zoomStep, e);
430
- t.style.width = `${r}px`;
431
- const c = r / i * n;
432
- t.style.height = `${c}px`, (o = (d = this.rootElm) == null ? void 0 : d.querySelector("button.vistaview-zoom-out-btn")) == null || o.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = r.toString(), t.dataset.vistaviewCurrentHeight = c.toString(), r === e && ((h = (l = this.rootElm) == null ? void 0 : l.querySelector("button.vistaview-zoom-in-btn")) == null || h.setAttribute("disabled", "true"));
434
+ const l = Math.min(i + this.options.zoomStep, e);
435
+ t.style.width = `${l}px`;
436
+ const h = l / i * n;
437
+ t.style.height = `${h}px`, (o = (d = this.rootElm) == null ? void 0 : d.querySelector("button.vistaview-zoom-out-btn")) == null || o.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = l.toString(), t.dataset.vistaviewCurrentHeight = h.toString(), l === e && ((c = (a = this.rootElm) == null ? void 0 : a.querySelector("button.vistaview-zoom-in-btn")) == null || c.setAttribute("disabled", "true"));
433
438
  }
434
439
  }
435
440
  zoomOut() {
436
- var d, o, l, h, r;
441
+ var d, o, a, c, l;
437
442
  const t = (d = this.rootElm) == null ? void 0 : d.querySelector(
438
443
  '[data-vistaview-pos="0"] .vistaview-image-highres'
439
- ), i = t.width, n = t.height, e = t.dataset.vistaviewInitialWidth ? parseInt(t.dataset.vistaviewInitialWidth) : 0, a = (c) => {
440
- c.target === t && (t.classList.remove("vistaview-image--zooming-out"), t.removeEventListener("transitionend", a));
444
+ ), i = t.width, n = t.height, e = t.dataset.vistaviewInitialWidth ? parseInt(t.dataset.vistaviewInitialWidth) : 0, r = (h) => {
445
+ h.target === t && (t.classList.remove("vistaview-image--zooming-out"), t.removeEventListener("transitionend", r));
441
446
  };
442
- if (t.addEventListener("transitionend", a), t.classList.add("vistaview-image--zooming-out"), i && e && i > e) {
443
- const c = Math.max(i - this.options.zoomStep, e);
444
- t.style.width = `${c}px`;
445
- const m = c / i * n;
446
- t.style.height = `${m}px`, (l = (o = this.rootElm) == null ? void 0 : o.querySelector("button.vistaview-zoom-in-btn")) == null || l.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = c.toString(), t.dataset.vistaviewCurrentHeight = m.toString();
447
- const { maxDiffX: f, minDiffY: u, maxDiffY: v, minDiffX: y } = T(c, m);
448
- let p = parseInt(
447
+ if (t.addEventListener("transitionend", r), t.classList.add("vistaview-image--zooming-out"), i && e && i > e) {
448
+ const h = Math.max(i - this.options.zoomStep, e);
449
+ t.style.width = `${h}px`;
450
+ const m = h / i * n;
451
+ t.style.height = `${m}px`, (a = (o = this.rootElm) == null ? void 0 : o.querySelector("button.vistaview-zoom-in-btn")) == null || a.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = h.toString(), t.dataset.vistaviewCurrentHeight = m.toString();
452
+ const { maxDiffX: v, minDiffY: f, maxDiffY: u, minDiffX: w } = H(h, m);
453
+ let g = parseInt(
449
454
  (t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-x").replace("px", "")) || "0"
450
- ), x = parseInt(
455
+ ), b = parseInt(
451
456
  (t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-y").replace("px", "")) || "0"
452
457
  );
453
- p = Math.min(f, Math.max(y, p)), x = Math.min(v, Math.max(u, x)), t == null || t.style.setProperty("--pointer-diff-x", `${p}px`), t == null || t.style.setProperty("--pointer-diff-y", `${x}px`), c === e && ((r = (h = this.rootElm) == null ? void 0 : h.querySelector("button.vistaview-zoom-out-btn")) == null || r.setAttribute("disabled", "true"), t.removeAttribute("data-vistaview-current-width"), t.removeAttribute("data-vistaview-current-height"), t.removeAttribute("data-vistaview-initial-width"), t.removeAttribute("data-vistaview-initial-height"), this.setZoomed(!1));
458
+ g = Math.min(v, Math.max(w, g)), b = Math.min(u, Math.max(f, b)), t == null || t.style.setProperty("--pointer-diff-x", `${g}px`), t == null || t.style.setProperty("--pointer-diff-y", `${b}px`), h === e && ((l = (c = this.rootElm) == null ? void 0 : c.querySelector("button.vistaview-zoom-out-btn")) == null || l.setAttribute("disabled", "true"), t.removeAttribute("data-vistaview-current-width"), t.removeAttribute("data-vistaview-current-height"), t.removeAttribute("data-vistaview-initial-width"), t.removeAttribute("data-vistaview-initial-height"), this.setZoomed(!1));
454
459
  }
455
460
  }
456
461
  clearZoom() {
@@ -459,13 +464,13 @@ class ot {
459
464
  return t.map((i, n) => {
460
465
  const e = this.elements[i];
461
466
  if (e instanceof HTMLElement) {
462
- const a = e.querySelector("img"), d = e.getAttribute("href") || "", o = e.getAttribute("src") || "", l = e.dataset.vistaviewSrc || d || o || (a == null ? void 0 : a.src) || "", h = e.dataset.vistaviewAlt || e.getAttribute("alt") || (a == null ? void 0 : a.alt) || "", r = e.dataset.vistaviewThumb || (a == null ? void 0 : a.src) || d || o || "";
467
+ const r = e.querySelector("img"), d = e.getAttribute("href") || "", o = e.getAttribute("src") || "", a = e.dataset.vistaviewSrc || d || o || (r == null ? void 0 : r.src) || "", c = e.dataset.vistaviewAlt || e.getAttribute("alt") || (r == null ? void 0 : r.alt) || "", l = e.dataset.vistaviewThumb || (r == null ? void 0 : r.src) || d || o || "";
463
468
  return {
464
469
  index: t[n],
465
- src: l,
466
- alt: h,
467
- thumb: r,
468
- imageElm: e instanceof HTMLImageElement ? e : a,
470
+ src: a,
471
+ alt: c,
472
+ thumb: l,
473
+ imageElm: e instanceof HTMLImageElement ? e : r,
469
474
  anchorElm: e instanceof HTMLAnchorElement ? e : void 0
470
475
  };
471
476
  } else
@@ -473,12 +478,12 @@ class ot {
473
478
  });
474
479
  }
475
480
  setInitialDimPos() {
476
- var h, r;
481
+ var c, l;
477
482
  if (!this.rootElm) return;
478
- const t = (h = this.rootElm.querySelector('[data-vistaview-pos="0"]')) == null ? void 0 : h.dataset.vistaviewIndex, i = ((r = this.currentImages) == null ? void 0 : r.find((c) => c.index === Number(t))) || null;
483
+ const t = (c = this.rootElm.querySelector('[data-vistaview-pos="0"]')) == null ? void 0 : c.dataset.vistaviewIndex, i = ((l = this.currentImages) == null ? void 0 : l.find((h) => h.index === Number(t))) || null;
479
484
  if (!i) return;
480
- const n = i.imageElm ? z(i.imageElm) : void 0, e = i.anchorElm ? z(i.anchorElm) : void 0, a = (e == null ? void 0 : e.width) || (n == null ? void 0 : n.width) || 0, d = (e == null ? void 0 : e.height) || (n == null ? void 0 : n.height) || 0, o = ((e == null ? void 0 : e.left) || (n == null ? void 0 : n.left) || 0) + a / 2, l = ((e == null ? void 0 : e.top) || (n == null ? void 0 : n.top) || 0) + d / 2;
481
- this.rootElm.style.setProperty("--vistaview-container-initial-width", a + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-height", d + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-top", l + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-left", o + "px"), this.rootElm.style.setProperty(
485
+ const n = i.imageElm ? z(i.imageElm) : void 0, e = i.anchorElm ? z(i.anchorElm) : void 0, r = (e == null ? void 0 : e.width) || (n == null ? void 0 : n.width) || 0, d = (e == null ? void 0 : e.height) || (n == null ? void 0 : n.height) || 0, o = ((e == null ? void 0 : e.left) || (n == null ? void 0 : n.left) || 0) + r / 2, a = ((e == null ? void 0 : e.top) || (n == null ? void 0 : n.top) || 0) + d / 2;
486
+ this.rootElm.style.setProperty("--vistaview-container-initial-width", r + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-height", d + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-top", a + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-left", o + "px"), this.rootElm.style.setProperty(
482
487
  "--vistaview-image-border-radius",
483
488
  R(e == null ? void 0 : e.borderRadius) || R(n == null ? void 0 : n.borderRadius) || "0px"
484
489
  );
@@ -491,13 +496,13 @@ class ot {
491
496
  if (!t) return;
492
497
  const i = this;
493
498
  function n() {
494
- var r, c;
495
- const a = (r = i.rootElm) == null ? void 0 : r.querySelector(
499
+ var l, h;
500
+ const r = (l = i.rootElm) == null ? void 0 : l.querySelector(
496
501
  "button.vistaview-zoom-in-btn"
497
- ), d = (c = i.rootElm) == null ? void 0 : c.querySelector(
502
+ ), d = (h = i.rootElm) == null ? void 0 : h.querySelector(
498
503
  "button.vistaview-zoom-out-btn"
499
- ), o = parseInt(t.style.width) || t.width, l = t.naturalWidth * i.options.maxZoomLevel, h = o < l && l > 0;
500
- a && (a.style.display = h ? "" : "none"), d && (d.style.display = h ? "" : "none");
504
+ ), o = parseInt(t.style.width) || t.width, a = t.naturalWidth * i.options.maxZoomLevel, c = o < a && a > 0;
505
+ r && (r.style.display = c ? "" : "none"), d && (d.style.display = c ? "" : "none");
501
506
  }
502
507
  t.complete && t.naturalWidth > 0 ? n() : t.addEventListener("load", n);
503
508
  }
@@ -508,35 +513,37 @@ class ot {
508
513
  ).forEach((i, n) => {
509
514
  const e = i, d = this.currentImages[n].imageElm, o = { w: 0, h: 0 };
510
515
  if (d) {
511
- const { width: h, height: r } = B(d);
512
- o.w = Math.min(d.width, h), o.h = Math.min(d.height, r);
516
+ const { width: c, height: l } = _(d);
517
+ o.w = Math.min(d.width, c), o.h = Math.min(d.height, l);
513
518
  }
514
- const l = () => {
515
- var r;
516
- const h = () => {
517
- var c;
519
+ const a = () => {
520
+ var l, h;
521
+ if ((l = e.parentElement) != null && l.classList.contains("vistaview-image--ending"))
522
+ return;
523
+ const c = () => {
524
+ var m;
518
525
  o.w && o.h && (e.style.width = `${o.w}px`, e.style.height = `${o.h}px`, e.style.setProperty("--vistaview-fitted-width", `${o.w}px`), e.style.setProperty("--vistaview-fitted-height", `${o.h}px`)), e.classList.add("vistaview-image-loaded"), e.width = e.naturalWidth, e.height = e.naturalHeight, setTimeout(() => {
519
- var y, p;
520
- let m = 0;
526
+ var g, b, I;
527
+ if ((g = e.parentElement) != null && g.classList.contains("vistaview-image--ending"))
528
+ return;
529
+ let v = 0;
521
530
  const f = () => {
522
- var x, b;
523
- m++, !(m < 3) && (e.removeEventListener("transitionend", f), (b = (x = e.parentElement) == null ? void 0 : x.querySelector(".vistaview-image-lowres")) == null || b.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled"));
524
- };
525
- e.addEventListener("transitionend", f);
526
- const { width: u, height: v } = H(e);
527
- e.style.width = `${u}px`, e.style.height = `${v}px`, o.w && o.h && u === o.w && v === o.h ? ((p = (y = e.parentElement) == null ? void 0 : y.querySelector(".vistaview-image-lowres")) == null || p.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled")) : (e.style.width = `${u}px`, e.style.height = `${v}px`);
528
- }, 100), (c = i.parentElement) != null && c.matches('[data-vistaview-pos="0"]') && this.updateZoomButtonsVisibility();
531
+ var p, x;
532
+ v++, !(v < 3) && (e.removeEventListener("transitionend", f), (x = (p = e.parentElement) == null ? void 0 : p.querySelector(".vistaview-image-lowres")) == null || x.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled"));
533
+ }, { width: u, height: w } = T(e);
534
+ o.w && o.h && u === o.w && w === o.h ? ((I = (b = e.parentElement) == null ? void 0 : b.querySelector(".vistaview-image-lowres")) == null || I.classList.add("vistaview-image--hidden"), e.classList.add("vistaview-image-settled")) : (e.addEventListener("transitionend", f), e.style.width = `${u}px`, e.style.height = `${w}px`);
535
+ }, 100), (m = i.parentElement) != null && m.matches('[data-vistaview-pos="0"]') && this.updateZoomButtonsVisibility();
529
536
  };
530
- if ((r = this.rootElm) != null && r.classList.contains("vistaview--opened"))
531
- h();
537
+ if ((h = this.rootElm) != null && h.classList.contains("vistaview--opened"))
538
+ c();
532
539
  else {
533
- const c = setInterval(() => {
534
- var m;
535
- (m = this.rootElm) != null && m.classList.contains("vistaview--opened") && (clearInterval(c), h());
540
+ const m = setInterval(() => {
541
+ var v;
542
+ (v = this.rootElm) != null && v.classList.contains("vistaview--opened") && (clearInterval(m), c());
536
543
  }, 50);
537
544
  }
538
545
  };
539
- e.complete && e.naturalWidth > 0 ? l() : e.onload = l;
546
+ e.complete && e.naturalWidth > 0 ? a() : e.onload = a;
540
547
  });
541
548
  }
542
549
  setIndexDisplay() {
@@ -555,10 +562,10 @@ class ot {
555
562
  t,
556
563
  ...Array.from({ length: i }, (d, o) => (t + 1 + o) % n)
557
564
  ])
558
- ], a = n < 1 || !i ? [0] : e.map((d, o) => o - Math.floor(e.length / 2));
565
+ ], r = n < 1 || !i ? [0] : e.map((d, o) => o - Math.floor(e.length / 2));
559
566
  return {
560
567
  images: e,
561
- positions: a
568
+ positions: r
562
569
  };
563
570
  }
564
571
  setKeyboardListeners() {
@@ -590,13 +597,13 @@ class ot {
590
597
  ".vistaview-image-highres.vistaview-image-loaded"
591
598
  );
592
599
  t == null || t.forEach((n) => {
593
- const e = n, { width: a, height: d } = H(e);
594
- e.classList.contains("vistaview-image--zooming") ? (e.dataset.vistaviewInitialWidth = a.toString(), e.dataset.vistaviewInitialHeight = d.toString()) : (e.style.width = `${a}px`, e.style.height = `${d}px`);
600
+ const e = n, { width: r, height: d } = T(e);
601
+ e.classList.contains("vistaview-image--zooming") ? (e.dataset.vistaviewInitialWidth = r.toString(), e.dataset.vistaviewInitialHeight = d.toString()) : (e.style.width = `${r}px`, e.style.height = `${d}px`);
595
602
  });
596
603
  }, window.addEventListener("resize", this.onResizeHandler);
597
604
  }
598
605
  open(t = 0) {
599
- var o, l, h, r, c, m, f, u, v, y, p, x, b;
606
+ var o, a, c, l, h, m, v, f, u, w, g, b, I;
600
607
  if (C.somethingOpened) {
601
608
  console.error("VistaView: another instance is already opened. Returning.");
602
609
  return;
@@ -611,9 +618,9 @@ class ot {
611
618
  this.options.arrowOnSmallScreens || this.rootElm.classList.add("vistaview-no-arrows-sm");
612
619
  const { images: i, positions: n } = this.getCurrentIndexes(t);
613
620
  this.currentImages = this.getImages(i);
614
- const e = this.currentImages.map((g, I) => q(g, n[I]));
621
+ const e = this.currentImages.map((p, x) => q(p, n[x]));
615
622
  this.currentItems = e;
616
- const a = {
623
+ const r = {
617
624
  htmlElements: { from: null, to: this.currentItems },
618
625
  images: { from: null, to: this.currentImages },
619
626
  index: { from: null, to: t },
@@ -625,29 +632,29 @@ class ot {
625
632
  isZoomed: this.isZoomed,
626
633
  options: this.options
627
634
  };
628
- this.userSetup(a), this.imageContainerElm.innerHTML = "", this.currentItems.forEach((g) => {
629
- this.imageContainerElm.appendChild(g);
635
+ this.userSetup(r), this.imageContainerElm.innerHTML = "", this.currentItems.forEach((p) => {
636
+ this.imageContainerElm.appendChild(p);
630
637
  });
631
638
  let d = 0;
632
- this.rootElm.addEventListener("animationend", (g) => {
633
- var I;
634
- g.currentTarget === this.rootElm && (d++, d >= 2 && ((I = this.rootElm) == null || I.classList.add("vistaview--opened")));
635
- }), (l = this.rootElm.querySelector(".vistaview-close-btn")) == null || l.addEventListener("click", () => this.close()), (h = this.rootElm.querySelector(".vistaview-zoom-in-btn")) == null || h.addEventListener("click", () => this.zoomIn()), (r = this.rootElm.querySelector(".vistaview-zoom-out-btn")) == null || r.addEventListener("click", () => this.zoomOut()), (c = this.rootElm.querySelector(".vistaview-prev-btn>button")) == null || c.addEventListener("click", () => this.prev()), (m = this.rootElm.querySelector(".vistaview-next-btn>button")) == null || m.addEventListener("click", () => this.next()), [
639
+ this.rootElm.addEventListener("animationend", (p) => {
640
+ var x;
641
+ p.currentTarget === this.rootElm && (d++, d >= 2 && ((x = this.rootElm) == null || x.classList.add("vistaview--opened")));
642
+ }), (a = this.rootElm.querySelector(".vistaview-close-btn")) == null || a.addEventListener("click", () => this.close()), (c = this.rootElm.querySelector(".vistaview-zoom-in-btn")) == null || c.addEventListener("click", () => this.zoomIn()), (l = this.rootElm.querySelector(".vistaview-zoom-out-btn")) == null || l.addEventListener("click", () => this.zoomOut()), (h = this.rootElm.querySelector(".vistaview-prev-btn>button")) == null || h.addEventListener("click", () => this.prev()), (m = this.rootElm.querySelector(".vistaview-next-btn>button")) == null || m.addEventListener("click", () => this.next()), [
636
643
  ...this.options.controls.topLeft || [],
637
644
  ...this.options.controls.topRight || [],
638
645
  ...this.options.controls.topCenter || [],
639
646
  ...this.options.controls.bottomCenter || [],
640
647
  ...this.options.controls.bottomLeft || [],
641
648
  ...this.options.controls.bottomRight || []
642
- ].forEach((g) => {
643
- typeof g != "string" && (this.customControls[g.name] = g);
644
- }), this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach((g) => {
645
- g.addEventListener("click", (I) => {
646
- const E = this.customControls[I.currentTarget.dataset.vistaviewCustomControl], L = this.currentImages.find(
649
+ ].forEach((p) => {
650
+ typeof p != "string" && (this.customControls[p.name] = p);
651
+ }), this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach((p) => {
652
+ p.addEventListener("click", (x) => {
653
+ const E = this.customControls[x.currentTarget.dataset.vistaviewCustomControl], L = this.currentImages.find(
647
654
  (D) => D.index === this.currentIndex.value
648
655
  );
649
- E && L && (E.onClick.constructor.name === "AsyncFunction" ? (g.classList.add("vistaview-button--loading"), E.onClick(L).finally(() => {
650
- g.classList.remove("vistaview-button--loading");
656
+ E && L && (E.onClick.constructor.name === "AsyncFunction" ? (p.classList.add("vistaview-button--loading"), E.onClick(L).finally(() => {
657
+ p.classList.remove("vistaview-button--loading");
651
658
  })) : E.onClick(L));
652
659
  });
653
660
  }), this.options.animationDurationBase && this.rootElm.style.setProperty(
@@ -656,16 +663,16 @@ class ot {
656
663
  ), this.options.initialZIndex !== void 0 && this.rootElm.style.setProperty(
657
664
  "--vistaview-initial-z-index",
658
665
  `${this.options.initialZIndex}`
659
- ), this.setInitialDimPos(), this.setResizeListeners(), this.options.keyboardListeners && this.setKeyboardListeners(), this.elements.length === 1 && ((f = this.rootElm.querySelector(".vistaview-prev-btn")) == null || f.classList.add("vistaview-ui--none"), (u = this.rootElm.querySelector(".vistaview-next-btn")) == null || u.classList.add("vistaview-ui--none"), (v = this.rootElm.querySelector(".vistaview-index-display")) == null || v.classList.add("vistaview-ui--none")), this.rootElm && this.rootElm.classList.add("vistaview--initialized"), this.loadImages(), this.setCurrentDescription(), this.setIndexDisplay(), this.userInit(this), (p = (y = this.options).onOpen) == null || p.call(y, a), (b = (x = this.options).onImageView) == null || b.call(x, a);
666
+ ), this.setInitialDimPos(), this.setResizeListeners(), this.options.keyboardListeners && this.setKeyboardListeners(), this.elements.length === 1 && ((v = this.rootElm.querySelector(".vistaview-prev-btn")) == null || v.classList.add("vistaview-ui--none"), (f = this.rootElm.querySelector(".vistaview-next-btn")) == null || f.classList.add("vistaview-ui--none"), (u = this.rootElm.querySelector(".vistaview-index-display")) == null || u.classList.add("vistaview-ui--none")), this.rootElm && this.rootElm.classList.add("vistaview--initialized"), this.loadImages(), this.setCurrentDescription(), this.setIndexDisplay(), this.userInit(this), (g = (w = this.options).onOpen) == null || g.call(w, r), (I = (b = this.options).onImageView) == null || I.call(b, r);
660
667
  }
661
668
  async close(t = !0) {
662
- var n, e, a;
669
+ var n, e, r;
663
670
  if (C.somethingOpened !== this) return;
664
671
  t && ((n = this.rootElm) == null || n.classList.add("vistaview--closing"), await new Promise((d) => {
665
- var l;
672
+ var a;
666
673
  let o;
667
- (l = this.rootElm) == null || l.addEventListener("transitionend", (h) => {
668
- h.currentTarget === this.rootElm && (o && clearTimeout(o), o = setTimeout(() => {
674
+ (a = this.rootElm) == null || a.addEventListener("transitionend", (c) => {
675
+ c.currentTarget === this.rootElm && (o && clearTimeout(o), o = setTimeout(() => {
669
676
  d();
670
677
  }, 333));
671
678
  });
@@ -682,7 +689,10 @@ class ot {
682
689
  isZoomed: this.isZoomed,
683
690
  options: this.options
684
691
  };
685
- this.userClose(this), (a = (e = this.options).onClose) == null || a.call(e, i), document.body.removeChild(this.rootElm), this.currentIndex._value = null, this.currentIndex._via = { next: !1, prev: !1 }, this.rootElm = null, this.imageContainerElm = null, this.currentImages = null, this.currentItems = null, this.navActive = !0, this.onResizeHandler && (window.removeEventListener("resize", this.onResizeHandler), this.onResizeHandler = null), this.onKeyDown && (window.removeEventListener("keydown", this.onKeyDown), this.onKeyDown = null), (this.onZoomedPointerDown || this.onZoomedPointerMove || this.onZoomedPointerUp) && (this.setZoomed(!1), this.onZoomedPointerDown = null, this.onZoomedPointerMove = null, this.onZoomedPointerUp = null), this.transitionAbortController && (this.transitionAbortController.abort(), this.transitionAbortController = null), C.somethingOpened = null;
692
+ this.userClose(this), (r = (e = this.options).onClose) == null || r.call(e, i), document.body.removeChild(this.rootElm), this.currentIndex._value = null, this.currentIndex._via = { next: !1, prev: !1 }, this.rootElm = null, this.imageContainerElm = null, this.currentImages = null, this.currentItems = null, this.navActive = !0, this.onResizeHandler && (window.removeEventListener("resize", this.onResizeHandler), this.onResizeHandler = null), this.onKeyDown && (window.removeEventListener("keydown", this.onKeyDown), this.onKeyDown = null), (this.onZoomedPointerDown || this.onZoomedPointerMove || this.onZoomedPointerUp) && (this.setZoomed(!1), this.onZoomedPointerDown = null, this.onZoomedPointerMove = null, this.onZoomedPointerUp = null);
693
+ for (const d in this.transitionAbortControllers)
694
+ this.transitionAbortControllers[d].abort();
695
+ this.transitionAbortControllers = {}, C.somethingOpened = null;
686
696
  }
687
697
  destroy() {
688
698
  this.close(!1), this.elements instanceof NodeList && this.elements.forEach((t) => {
@@ -738,7 +748,7 @@ function lt({ elements: s, ...t }) {
738
748
  }
739
749
  export {
740
750
  k as DefaultOptions,
741
- P as VistaViewTransitionAbortedError,
751
+ S as VistaViewTransitionAbortedError,
742
752
  st as defaultClose,
743
753
  et as defaultInit,
744
754
  it as defaultSetup,