vistaview 0.6.6 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vistaview.js CHANGED
@@ -1,27 +1,27 @@
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
- function $(s) {
1
+ var F = Object.defineProperty;
2
+ var A = (s, t, e) => t in s ? F(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var h = (s, t, e) => A(s, typeof t != "symbol" ? t + "" : t, e);
4
+ function S(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 F(s) {
8
- const e = window.getComputedStyle(s).objectFit || "", { width: i, height: n } = s.getBoundingClientRect(), o = s.naturalWidth, a = s.naturalHeight;
7
+ function z(s) {
8
+ const e = window.getComputedStyle(s).objectFit || "", { width: i, height: n } = s.getBoundingClientRect(), o = s.naturalWidth, r = s.naturalHeight;
9
9
  if (!e)
10
10
  return { width: i, height: n };
11
- if (!o || !a)
11
+ if (!o || !r)
12
12
  return { width: i, height: n };
13
- const r = o / a, h = i / n;
13
+ const a = o / r, l = i / n;
14
14
  switch (e) {
15
15
  case "fill":
16
16
  return { width: i, height: n };
17
17
  case "none":
18
- return { width: o, height: a };
18
+ return { width: o, height: r };
19
19
  case "contain":
20
- return r > h ? { width: i, height: i / r } : { width: n * r, height: n };
20
+ return a > l ? { width: i, height: i / a } : { width: n * a, height: n };
21
21
  case "cover":
22
- return r < h ? { width: i, height: i / r } : { width: n * r, height: n };
22
+ return a < l ? { width: i, height: i / a } : { width: n * a, height: n };
23
23
  case "scale-down": {
24
- const c = { width: o, height: a }, m = r > h ? { width: i, height: i / r } : { width: n * r, height: n };
24
+ const c = { width: o, height: r }, m = a > l ? { width: i, height: i / a } : { width: n * a, height: n };
25
25
  return m.width <= c.width && m.height <= c.height ? m : c;
26
26
  }
27
27
  }
@@ -42,8 +42,8 @@ function D(s) {
42
42
  naturalHeight: s.naturalHeight
43
43
  };
44
44
  }
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 : "") || "";
45
+ function k(s) {
46
+ const t = s.imageElm ? D(s.imageElm) : null, e = s.anchorElm ? D(s.anchorElm) : null, i = S(t == null ? void 0 : t.borderRadius), n = e && S(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) || "",
@@ -57,25 +57,25 @@ function P(s) {
57
57
  left: (e == null ? void 0 : e.left) || (t == null ? void 0 : t.left) || 0
58
58
  };
59
59
  }
60
- function H(s, t, e, i = !1) {
60
+ function W(s, t, e, i = !1) {
61
61
  const {
62
62
  fit: n,
63
63
  w: o,
64
- h: a,
64
+ h: r,
65
65
  // this ones makes things hard. not used.
66
66
  // pos,
67
67
  // overflow,
68
- nw: r,
69
- nh: h,
68
+ nw: a,
69
+ nh: l,
70
70
  br: c,
71
71
  top: m,
72
- left: w
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());
72
+ left: p
73
+ } = k(s), L = Math.min(Math.max(p, -o), window.innerWidth + o) - window.innerWidth / 2 + o / 2, g = Math.min(Math.max(m, -r), window.innerHeight + r) - window.innerHeight / 2 + r / 2, d = e.style;
74
+ d.width = `${o}px`, d.height = `${r}px`, d.objectFit = n, e.width = a, e.height = l, d.setProperty("--vvw-init-radius", `${c}`), d.setProperty("--vvw-pulse-radius", `calc(1.3 * ${c})`), d.setProperty("--vvw-init-x", `${L}px`), d.setProperty("--vvw-init-y", `${g}px`), i && (d.setProperty("--vvw-current-x", `${L}px`), d.setProperty("--vvw-current-y", `${g}px`));
75
+ const u = z(s.imageElm), y = Math.min(o, u.width), f = Math.min(r, u.height), v = t.style;
76
+ v.setProperty("--vvw-init-radius", `${c}`), v.setProperty("--vvw-init-w", `${y}px`), v.setProperty("--vvw-init-h", `${f}px`), i && (v.setProperty("--vvw-current-radius", `${c}`), v.setProperty("--vvw-current-w", `${y}px`), v.setProperty("--vvw-current-h", `${f}px`), t.dataset.vvwWidth = y.toString(), t.dataset.vvwHeight = f.toString());
77
77
  }
78
- function S(s) {
78
+ function M(s) {
79
79
  const t = window.innerWidth, e = window.innerHeight, i = s.naturalWidth, n = s.naturalHeight;
80
80
  if (!i || !n)
81
81
  throw new Error("Image natural dimensions are zero");
@@ -84,26 +84,26 @@ function S(s) {
84
84
  width: i,
85
85
  height: n
86
86
  };
87
- const o = i / n, a = t / e;
88
- let r, h;
89
- return o > a ? (r = t, h = t / o) : (h = e, r = e * o), {
90
- width: r,
91
- height: h
87
+ const o = i / n, r = t / e;
88
+ let a, l;
89
+ return o > r ? (a = t, l = t / o) : (l = e, a = e * o), {
90
+ width: a,
91
+ height: l
92
92
  };
93
93
  }
94
- function z(s, t, e) {
94
+ function q(s, t, e) {
95
95
  return Math.min(Math.max(s, t), e);
96
96
  }
97
97
  function C(s, t = 2) {
98
98
  const e = Math.pow(10, t);
99
99
  return Math.round(s * e) / e;
100
100
  }
101
- const k = '<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>', q = '<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>';
102
- let I = null;
103
- function X() {
104
- return I || (window.trustedTypes || (window.trustedTypes = {
101
+ const R = '<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>', O = '<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>', Z = '<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>', X = '<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>', N = '<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>', Y = '<svg viewBox="0 0 24 24"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';
102
+ let $ = null;
103
+ function B() {
104
+ return $ || (window.trustedTypes || (window.trustedTypes = {
105
105
  createPolicy: (s, t) => t
106
- }), I = window.trustedTypes.createPolicy("vistaView-policy", {
106
+ }), $ = window.trustedTypes.createPolicy("vistaView-policy", {
107
107
  createHTML: (s) => s,
108
108
  // HTML is generated by us, not user input
109
109
  createScript: () => {
@@ -112,15 +112,15 @@ function X() {
112
112
  createScriptURL: () => {
113
113
  throw new Error("Not implemented");
114
114
  }
115
- }), I);
115
+ }), $);
116
116
  }
117
- function M(s) {
118
- const e = X().createHTML(s), i = document.createElement("template");
117
+ function P(s) {
118
+ const e = B().createHTML(s), i = document.createElement("template");
119
119
  i.innerHTML = e;
120
120
  const n = i.content;
121
121
  return i.remove(), n;
122
122
  }
123
- function N() {
123
+ function j() {
124
124
  return {
125
125
  name: "download",
126
126
  icon: Y,
@@ -131,15 +131,15 @@ function N() {
131
131
  }
132
132
  };
133
133
  }
134
- function B(s) {
134
+ function V(s) {
135
135
  if (typeof s == "string")
136
136
  switch (s) {
137
137
  case "zoomIn":
138
- return `<button aria-label="Zoom In" class="vvw-zoom-in vvw-ui">${R}</button>`;
138
+ return `<button aria-label="Zoom In" class="vvw-zoom-in vvw-ui">${Z}</button>`;
139
139
  case "zoomOut":
140
- return `<button aria-label="Zoom Out" disabled class="vvw-zoom-out vvw-ui">${O}</button>`;
140
+ return `<button aria-label="Zoom Out" disabled class="vvw-zoom-out vvw-ui">${X}</button>`;
141
141
  case "close":
142
- return `<button aria-label="Close" class="vvw-close vvw-ui">${Z}</button>`;
142
+ return `<button aria-label="Close" class="vvw-close vvw-ui">${N}</button>`;
143
143
  case "indexDisplay":
144
144
  return '<div class="vvw-index vvw-ui" aria-hidden="true"></div>';
145
145
  case "description":
@@ -149,35 +149,35 @@ function B(s) {
149
149
  }
150
150
  return `<button class="vvw-ui" aria-label="${s.description || s.name}" data-vvw-control="${s.name}">${s.icon}</button>`;
151
151
  }
152
- function j(s, t) {
152
+ function U(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
- M(
155
+ P(
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
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;
161
+ return W(s, n, i, t === 0), e;
162
162
  }
163
- function U({
163
+ function K({
164
164
  controls: s
165
165
  }) {
166
- const t = (i) => i ? i.map(B).join("") : "";
167
- return M(
166
+ const t = (i) => i ? i.map(V).join("") : "";
167
+ return P(
168
168
  `<div class="vvw-root" id="vvw-root">
169
169
  <div class="vvw-container">
170
170
  <div class="vvw-bg"></div>
171
171
  <div class="vvw-image-container"></div>
172
172
  <div class="vvw-top-bar"><div>${t(s == null ? void 0 : s.topLeft)}</div><div>${t(s == null ? void 0 : s.topCenter)}</div><div>${t(s == null ? void 0 : s.topRight)}</div></div>
173
173
  <div class="vvw-bottom-bar"><div>${t(s == null ? void 0 : s.bottomLeft)}</div><div>${t(s == null ? void 0 : s.bottomCenter)}</div><div>${t(s == null ? void 0 : s.bottomRight)}</div></div>
174
- <div class="vvw-prev vvw-ui"><button aria-label="Previous">${k}</button></div>
175
- <div class="vvw-next vvw-ui"><button aria-label="Next">${q}</button></div>
174
+ <div class="vvw-prev vvw-ui"><button aria-label="Previous">${R}</button></div>
175
+ <div class="vvw-next vvw-ui"><button aria-label="Next">${O}</button></div>
176
176
  </div>
177
177
  </div>`
178
178
  );
179
179
  }
180
- const T = {
180
+ const H = {
181
181
  // debug, don't remove
182
182
  // animationDurationBase: 1000,
183
183
  animationDurationBase: 333,
@@ -188,90 +188,98 @@ const T = {
188
188
  rapidLimit: 222,
189
189
  controls: {
190
190
  topLeft: ["indexDisplay"],
191
- topRight: ["zoomIn", "zoomOut", N(), "close"],
191
+ topRight: ["zoomIn", "zoomOut", j(), "close"],
192
192
  bottomLeft: ["description"]
193
193
  }
194
194
  };
195
- function K(s) {
196
- }
197
195
  function _(s) {
198
- const t = s.options.preloads;
199
- s.imageContainer.style.width = `${(t * 2 + 1) * 100}vw`, s.imageContainer.style.left = `-${t * 100}vw`, s.imageContainer.style.display = "flex", G(s);
200
196
  }
201
197
  function G(s) {
198
+ const t = s.options.preloads;
199
+ s.imageContainer.style.width = `${(t * 2 + 1) * 100}vw`, s.imageContainer.style.left = `-${t * 100}vw`, s.imageContainer.style.display = "flex", J(s);
200
+ }
201
+ function J(s) {
202
202
  let t = { x: 0, y: 0 }, e = { x: 0, y: 0 }, i = null;
203
203
  s.registerPointerListener((n) => {
204
+ var o;
204
205
  if (!n.hasInternalExecution && !(n.pointers.length > 1)) {
205
- 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") {
206
+ if (n.event === "down" && (t = { x: n.pointer.x, y: n.pointer.y }, e = { x: n.pointer.x, y: n.pointer.y }, (o = n.abortController) == null || o.abort()), n.event === "move") {
206
207
  e = { x: n.pointer.x, y: n.pointer.y };
207
- const o = e.x - t.x, a = e.y - t.y;
208
- if (!i && Math.abs(a) > Math.abs(o) || i === "y") {
209
- const r = a / window.innerHeight * 100;
210
- s.imageContainer.style.transition = "none", s.imageContainer.style.transform = `translateY(${r}vh)`, i = "y";
211
- } else if (!i && Math.abs(o) > Math.abs(a) || i === "x") {
212
- const r = o / window.innerWidth * 100;
213
- s.imageContainer.style.transition = "none", s.imageContainer.style.transform = `translateX(${r}vw)`, i = "x";
208
+ const r = e.x - t.x, a = e.y - t.y;
209
+ if (!i && Math.abs(a) > Math.abs(r) || i === "y") {
210
+ const l = a / window.innerHeight * 100;
211
+ s.imageContainer.style.transition = "none", s.imageContainer.style.transform = `translateY(${l}vh)`, i = "y";
212
+ } else if (!i && Math.abs(r) > Math.abs(a) || i === "x") {
213
+ const l = r / window.innerWidth * 100;
214
+ s.imageContainer.style.transition = "none", s.imageContainer.style.transform = `translateX(${l}vw)`, i = "x";
214
215
  }
215
216
  }
216
217
  if (n.event === "up" || n.event === "cancel") {
217
- let o = function(a) {
218
- var r;
219
- (r = s.imageContainer) == null || r.addEventListener("transitionend", function h() {
220
- var c;
221
- (c = s.imageContainer) == null || c.removeEventListener("transitionend", h), s.imageContainer.style.transition = "", s.imageContainer.style.transform = "";
218
+ let r = function(a) {
219
+ var l;
220
+ (l = s.imageContainer) == null || l.addEventListener("transitionend", function c() {
221
+ var m;
222
+ (m = s.imageContainer) == null || m.removeEventListener("transitionend", c), s.imageContainer.style.transition = "", s.imageContainer.style.transform = "";
222
223
  }), s.imageContainer.style.transition = "transform 222ms ease", s.imageContainer.style.transform = a;
223
224
  };
224
225
  if (i === "y") {
225
- const a = e.y - t.y, r = n.pointer.movementY, h = 8;
226
- 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)");
226
+ const a = e.y - t.y;
227
+ Math.abs(a) > 144 ? (s.imageContainer.style.transition = "transform 222ms ease", s.imageContainer.style.transform = "translateY(0vh)", s.close()) : r("translateY(0vh)");
227
228
  }
228
229
  if (i === "x") {
229
- const a = e.x - t.x, r = n.pointer.movementX, h = 8;
230
- s.imageContainer.style.transition = "", a > 0 && Math.abs(r) > h ? s.prev() : a < 0 && Math.abs(r) > h ? s.next() : o("translateX(0vw)");
230
+ const a = e.x - t.x, l = n.pointer.movementX, c = 1;
231
+ s.imageContainer.style.transition = "", a > 0 && Math.abs(l) > c ? s.prev() : a < 0 && Math.abs(l) > c ? s.next() : r("translateX(0vw)");
231
232
  }
232
233
  i = null, t = { x: 0, y: 0 }, e = { x: 0, y: 0 };
233
234
  }
234
235
  }
235
236
  });
236
237
  }
237
- function J(s) {
238
+ function Q(s) {
238
239
  }
239
- async function Q({
240
+ function tt({
240
241
  vistaView: { isReducedMotion: s },
241
242
  htmlElements: { to: t },
242
243
  index: { from: e, to: i },
243
- vistaView: { elements: n, imageContainer: o, options: a }
244
- }, r) {
245
- if (!t || r.aborted || s || !(Math.abs(i - e) === 1 || e === 0 && i === n.length - 1 || e === n.length - 1 && i === 0))
246
- return;
247
- const c = Math.round(a.animationDurationBase * 100) / 100;
248
- return new Promise((m) => {
249
- o.addEventListener(
250
- "transitionend",
251
- () => {
252
- m(() => {
253
- o.style.transition = "", o.style.transform = "";
254
- });
244
+ vistaView: { elements: n, imageContainer: o, options: r }
245
+ }, a) {
246
+ if (!(!t || a.aborted || s || !(Math.abs(i - e) === 1 || e === 0 && i === n.length - 1 || e === n.length - 1 && i === 0)))
247
+ return {
248
+ cleanup: () => {
249
+ o.style.transition = "", o.style.transform = "";
255
250
  },
256
- { once: !0 }
257
- );
258
- const w = i === e + 1 || e === n.length - 1 && i === 0 ? "translateX(-100vw)" : "translateX(100vw)";
259
- o.style.transition = `transform ${c}ms ease`, o.style.transform = w;
260
- });
251
+ transitionEnded: new Promise((c) => {
252
+ o.addEventListener(
253
+ "transitionend",
254
+ () => {
255
+ c();
256
+ },
257
+ { once: !0 }
258
+ ), o.addEventListener(
259
+ "transitioncancel",
260
+ () => {
261
+ a.aborted && c();
262
+ },
263
+ { once: !0 }
264
+ );
265
+ const m = Math.round(r.animationDurationBase * 100) / 100, p = i === e + 1 || e === n.length - 1 && i === 0 ? "translateX(-100vw)" : "translateX(100vw)";
266
+ o.style.transition = `transform ${m}ms ease`, o.style.transform = p;
267
+ })
268
+ };
261
269
  }
262
- class V {
270
+ class et {
263
271
  constructor({ elm: t, listeners: e }) {
264
- l(this, "pointers", []);
265
- l(this, "elm");
266
- l(this, "listeners", []);
267
- l(this, "lastPointerDownId", null);
268
- l(this, "removeLastPointer", () => {
272
+ h(this, "pointers", []);
273
+ h(this, "elm");
274
+ h(this, "listeners", []);
275
+ h(this, "lastPointerDownId", null);
276
+ h(this, "removeLastPointer", () => {
269
277
  if (this.pointers.length && this.lastPointerDownId !== null) {
270
278
  const t = this.pointers.findIndex((e) => e.id === this.lastPointerDownId);
271
279
  t !== -1 && this.pointers.splice(t, 1);
272
280
  }
273
281
  });
274
- l(this, "onPointerDown", (t) => {
282
+ h(this, "onPointerDown", (t) => {
275
283
  if (!this.listeners.length || t.button !== 0) return;
276
284
  t.preventDefault(), this.lastPointerDownId = t.pointerId, window.addEventListener("contextmenu", this.removeLastPointer, { once: !0 }), window.addEventListener("auxclick", this.removeLastPointer, { once: !0 });
277
285
  let e = {
@@ -290,7 +298,7 @@ class V {
290
298
  })
291
299
  );
292
300
  });
293
- l(this, "onPointerMove", (t) => {
301
+ h(this, "onPointerMove", (t) => {
294
302
  if (!this.listeners.length) return;
295
303
  t.preventDefault();
296
304
  const e = this.pointers.find((i) => i.id === t.pointerId);
@@ -303,7 +311,7 @@ class V {
303
311
  })
304
312
  ));
305
313
  });
306
- l(this, "onPointerUp", (t) => {
314
+ h(this, "onPointerUp", (t) => {
307
315
  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))
308
316
  return;
309
317
  t.preventDefault();
@@ -321,7 +329,7 @@ class V {
321
329
  })
322
330
  );
323
331
  });
324
- l(this, "onPointerCancel", (t) => {
332
+ h(this, "onPointerCancel", (t) => {
325
333
  if (!this.listeners.length || t.target instanceof Node && !this.elm.contains(t.target) && t.target !== document.querySelector("html") && t.target !== document)
326
334
  return;
327
335
  t.preventDefault();
@@ -369,20 +377,20 @@ class V {
369
377
  };
370
378
  }
371
379
  }
372
- class tt {
380
+ class it {
373
381
  constructor(t, e) {
374
- l(this, "maxZoomLevel");
375
- l(this, "image", null);
376
- l(this, "rect", null);
377
- l(this, "initialCenter", { x: 0, y: 0 });
378
- l(this, "maxDimension", { width: 0 });
379
- l(this, "minDimension", { initialWidth: 0, initialHeight: 0, minWidth: 0, closingWidth: 0 });
380
- l(this, "accumulatedTranslate", { x: 0, y: 0 });
382
+ h(this, "maxZoomLevel");
383
+ h(this, "image", null);
384
+ h(this, "rect", null);
385
+ h(this, "initialCenter", { x: 0, y: 0 });
386
+ h(this, "maxDimension", { width: 0 });
387
+ h(this, "minDimension", { initialWidth: 0, initialHeight: 0, minWidth: 0, closingWidth: 0 });
388
+ h(this, "accumulatedTranslate", { x: 0, y: 0 });
381
389
  // state
382
- l(this, "scale", 1);
383
- l(this, "translate", { x: 0, y: 0 });
384
- l(this, "onScale", null);
385
- l(this, "animationTimestamp", 0);
390
+ h(this, "scale", 1);
391
+ h(this, "translate", { x: 0, y: 0 });
392
+ h(this, "onScale", null);
393
+ h(this, "animationTimestamp", 0);
386
394
  this.maxZoomLevel = t, this.onScale = e;
387
395
  }
388
396
  clean() {
@@ -417,7 +425,7 @@ class tt {
417
425
  if (!this.image) return;
418
426
  this.rect || (this.rect = this.image.getBoundingClientRect()), e || (e = this.initialCenter);
419
427
  const i = this.snapToTargetIfClose(
420
- z(this.rect.width * t, this.minDimension.minWidth, this.maxDimension.width),
428
+ q(this.rect.width * t, this.minDimension.minWidth, this.maxDimension.width),
421
429
  this.minDimension.initialWidth
422
430
  );
423
431
  this.onScale && this.onScale({
@@ -425,19 +433,19 @@ class tt {
425
433
  isMax: i >= this.maxDimension.width,
426
434
  isMin: i <= this.minDimension.initialWidth
427
435
  }), this.scale = C(i / this.rect.width);
428
- 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;
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})`, i <= this.minDimension.closingWidth ? this.image.style.opacity = "0.5" : this.image.style.opacity = "";
436
+ const n = this.rect.left + this.rect.width / 2, o = this.rect.top + this.rect.height / 2, r = this.initialCenter.x - n, a = this.initialCenter.y - o, l = r * (1 - this.scale), c = a * (1 - this.scale), m = e.x - this.initialCenter.x, p = e.y - this.initialCenter.y;
437
+ this.translate.x = C(l + m), this.translate.y = C(c + p), 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
438
  }
431
439
  moveAndNormalize(t) {
432
440
  let e = 0, i = !1;
433
- const n = ({ x: o, y: a }) => {
441
+ const n = ({ x: o, y: r }) => {
434
442
  if (i)
435
443
  return;
436
- if (Math.abs(o) < 1e-3 && Math.abs(a) < 1e-3)
444
+ if (Math.abs(o) < 1e-3 && Math.abs(r) < 1e-3)
437
445
  return this.normalize();
438
- o *= 0.9, a *= 0.9;
439
- 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(() => n({ x: o, y: a }));
446
+ o *= 0.9, r *= 0.9;
447
+ const a = this.image.getBoundingClientRect();
448
+ this.translate.x = C(this.translate.x + o), this.translate.y = C(this.translate.y + r), a.right < window.innerWidth / 2 && (this.translate.x += (window.innerWidth / 2 - a.right) * 0.1, o *= 0.7), a.left > window.innerWidth / 2 && (this.translate.x -= (a.left - window.innerWidth / 2) * 0.1, o *= 0.7), a.bottom < window.innerHeight / 2 && (this.translate.y += (window.innerHeight / 2 - a.bottom) * 0.1, r *= 0.7), a.top > window.innerHeight / 2 && (this.translate.y -= (a.top - window.innerHeight / 2) * 0.1, r *= 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: r }));
441
449
  };
442
450
  return n({
443
451
  x: t.movementX,
@@ -460,87 +468,83 @@ class tt {
460
468
  }
461
469
  normalize(t = !0) {
462
470
  if (!this.image || !this.rect) return;
463
- const e = this.snapToTargetIfClose(
464
- this.rect.width * this.scale,
465
- this.minDimension.initialWidth
466
- ), i = this.snapToTargetIfClose(
467
- this.rect.height * this.scale,
468
- this.minDimension.initialHeight
469
- );
470
- 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)
471
- return this.clean(), !0;
472
- if (e < this.minDimension.initialWidth)
471
+ const e = this.rect.width * this.scale, i = e <= this.minDimension.closingWidth, n = i ? e : this.snapToTargetIfClose(this.rect.width * this.scale, this.minDimension.initialWidth), o = i ? this.rect.height * this.scale : this.snapToTargetIfClose(this.rect.height * this.scale, this.minDimension.initialHeight);
472
+ if (this.image.style.width = `${n}px`, this.image.style.height = `${o}px`, this.scale = 1, this.image.style.opacity = "", this.accumulatedTranslate.x += this.translate.x, this.accumulatedTranslate.y += this.translate.y, this.image.style.left = `calc(50% + ${this.accumulatedTranslate.x}px)`, this.image.style.top = `calc(50% + ${this.accumulatedTranslate.y}px)`, this.translate = { x: 0, y: 0 }, this.image.style.transform = "", this.rect = this.image.getBoundingClientRect(), i)
473
+ return !0;
474
+ if (n < this.minDimension.initialWidth)
473
475
  this.accumulatedTranslate.x = 0, this.accumulatedTranslate.y = 0, requestAnimationFrame(() => {
474
- const n = this.image;
475
- n && (n.addEventListener(
476
+ const r = this.image;
477
+ r && (r.addEventListener(
476
478
  "transitionend",
477
479
  () => {
478
- n && (this.clean(), this.rect = null);
480
+ r && (this.clean(), this.rect = null);
479
481
  },
480
482
  { once: !0 }
481
- ), 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%");
483
+ ), r.style.transition = "all 222ms ease", r.style.width = `${this.minDimension.initialWidth}px`, r.style.height = `${this.minDimension.initialHeight}px`, r.style.left = "50%", r.style.top = "50%");
482
484
  });
483
485
  else if (t) {
484
- let n = !1;
485
- 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) {
486
- const o = this.image;
487
- o.addEventListener(
486
+ let r = !1;
487
+ if (this.rect.right < window.innerWidth / 2 && (r = !0, this.accumulatedTranslate.x += window.innerWidth / 2 - this.rect.right), this.rect.left > window.innerWidth / 2 && (r = !0, this.accumulatedTranslate.x -= this.rect.left - window.innerWidth / 2), this.rect.bottom < window.innerHeight / 2 && (r = !0, this.accumulatedTranslate.y += window.innerHeight / 2 - this.rect.bottom), this.rect.top > window.innerHeight / 2 && (r = !0, this.accumulatedTranslate.y -= this.rect.top - window.innerHeight / 2), r) {
488
+ const a = this.image;
489
+ a.addEventListener(
488
490
  "transitionend",
489
491
  () => {
490
- o && (o.style.transition = "", this.rect = null);
492
+ a && (a.style.transition = "", this.rect = null);
491
493
  },
492
494
  { once: !0 }
493
- ), o.style.transition = "all 222ms ease", o.style.left = `calc(50% + ${this.accumulatedTranslate.x}px)`, o.style.top = `calc(50% + ${this.accumulatedTranslate.y}px)`;
495
+ ), a.style.transition = "all 222ms ease", a.style.left = `calc(50% + ${this.accumulatedTranslate.x}px)`, a.style.top = `calc(50% + ${this.accumulatedTranslate.y}px)`;
494
496
  } else
495
497
  this.rect = null;
496
498
  }
497
499
  }
498
500
  }
499
- class et {
501
+ class nt {
500
502
  constructor() {
501
- l(this, "fiolast", {});
503
+ h(this, "fiolast", {});
502
504
  }
503
505
  // first in out
504
506
  fio(t, e, i = 50) {
505
- const o = Date.now() - (this.fiolast[e] ?? 0), a = () => {
507
+ const o = Date.now() - (this.fiolast[e] ?? 0), r = () => {
506
508
  this.fiolast[e] = Date.now(), t();
507
509
  };
508
510
  if (!this.fiolast[e]) {
509
- a();
511
+ r();
510
512
  return;
511
513
  }
512
- o >= i && a();
514
+ o >= i && r();
513
515
  }
514
516
  }
515
517
  const x = {
516
518
  somethingOpened: null
517
519
  };
518
- class it {
520
+ class st {
519
521
  constructor(t, e = {}) {
520
- l(this, "options");
521
- l(this, "elements");
522
- l(this, "isReducedMotion");
523
- l(this, "currentIndex", -1);
524
- l(this, "currentChildren", null);
525
- l(this, "setupFunction", K);
526
- l(this, "initFunction", _);
527
- l(this, "closeFunction", J);
528
- l(this, "transitionFunction", Q);
529
- l(this, "pointers", null);
530
- l(this, "imageState");
531
- l(this, "root", null);
532
- l(this, "imageContainer", null);
533
- l(this, "onClickElements", (t) => {
522
+ h(this, "options");
523
+ h(this, "elements");
524
+ h(this, "isReducedMotion");
525
+ h(this, "currentIndex", -1);
526
+ h(this, "currentChildren", null);
527
+ h(this, "setupFunction", _);
528
+ h(this, "initFunction", G);
529
+ h(this, "closeFunction", Q);
530
+ h(this, "transitionFunction", tt);
531
+ h(this, "pointers", null);
532
+ h(this, "imageState");
533
+ h(this, "imageTransitions", /* @__PURE__ */ new Map());
534
+ h(this, "root", null);
535
+ h(this, "imageContainer", null);
536
+ h(this, "onClickElements", (t) => {
534
537
  t.preventDefault();
535
538
  const e = t.currentTarget;
536
539
  e.dataset.vistaIdx && this.open(parseInt(e.dataset.vistaIdx));
537
540
  });
538
- l(this, "defaultOnClickHandler", (t) => t.preventDefault());
539
- l(this, "abortController", null);
540
- l(this, "throttle", new et());
541
- l(this, "lastSwapTime", 0);
542
- l(this, "isZoomedIn", !1);
543
- l(this, "onKeyDown", (t) => {
541
+ h(this, "defaultOnClickHandler", (t) => t.preventDefault());
542
+ h(this, "abortController", null);
543
+ h(this, "throttle", new nt());
544
+ h(this, "lastSwapTime", 0);
545
+ h(this, "transitionCleanup", null);
546
+ h(this, "isZoomedIn", !1);
547
+ h(this, "onKeyDown", (t) => {
544
548
  switch (t.key) {
545
549
  case "ArrowLeft":
546
550
  t.preventDefault(), this.prev();
@@ -559,7 +563,7 @@ class it {
559
563
  break;
560
564
  }
561
565
  });
562
- l(this, "onScroll", (t) => {
566
+ h(this, "onScroll", (t) => {
563
567
  t.preventDefault();
564
568
  const e = t.deltaY;
565
569
  this.imageState.setInitialCenter({
@@ -567,70 +571,71 @@ class it {
567
571
  y: t.clientY
568
572
  }), e < 0 ? this.zoomIn() : e > 0 && this.zoomOut();
569
573
  });
570
- l(this, "onResizeHandler", () => {
574
+ h(this, "onResizeHandler", () => {
571
575
  this.currentChildren.htmls.forEach((t, e) => {
572
576
  const i = this.currentChildren.images[e], n = t.querySelector("img.vvw-img-hi"), o = t.querySelector("img.vvw-img-lo");
573
- if (H(i, n, o, !1), n.classList.contains("vvw--loaded")) {
574
- const { width: a, height: r } = S(n);
575
- 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();
577
+ if (W(i, n, o, !1), n.classList.contains("vvw--loaded")) {
578
+ const { width: r, height: a } = M(n);
579
+ n.style.setProperty("--vvw-current-w", `${r}px`), n.style.setProperty("--vvw-current-h", `${a}px`), n.dataset.vvwWidth = r.toString(), n.dataset.vvwHeight = a.toString();
576
580
  }
577
581
  });
578
582
  });
579
583
  /// POINTERS
580
- l(this, "pointerListeners", []);
581
- l(this, "getInternalPointerListener", () => {
584
+ h(this, "pointerListeners", []);
585
+ h(this, "getInternalPointerListener", () => {
582
586
  const t = this.imageState;
583
587
  let e = 0, i = !1, n = () => {
584
588
  };
585
589
  return (o) => {
586
590
  if (o.event === "down") {
587
591
  if (n(), this.isZoomedIn && o.pointers.length === 1) {
588
- const a = this.pointers.getCentroid();
589
- t.setInitialCenter(a);
592
+ const r = this.pointers.getCentroid();
593
+ t.setInitialCenter(r);
590
594
  }
591
595
  if (o.pointers.length >= 2) {
592
596
  i = !0;
593
- const a = this.pointers.getCentroid();
594
- e = this.pointers.getPointerDistance(o.pointers[0], o.pointers[1]), t.setInitialCenter(a);
597
+ const r = this.pointers.getCentroid();
598
+ e = this.pointers.getPointerDistance(o.pointers[0], o.pointers[1]), t.setInitialCenter(r);
595
599
  }
596
600
  } else if (o.event === "move") {
597
601
  if (this.isZoomedIn && o.pointers.length === 1 && o.lastPointerLen === 0) {
598
- const a = this.pointers.getCentroid();
599
- t.move(a);
602
+ const r = this.pointers.getCentroid();
603
+ t.move(r);
600
604
  }
601
605
  if (o.pointers.length >= 2 && i) {
602
- const a = this.pointers.getCentroid(), r = this.pointers.getPointerDistance(o.pointers[0], o.pointers[1]);
603
- t.scaleMove(r / e, a);
606
+ const r = this.pointers.getCentroid(), a = this.pointers.getPointerDistance(o.pointers[0], o.pointers[1]);
607
+ t.scaleMove(a / e, r);
604
608
  }
605
609
  } else (o.event === "up" || o.event === "cancel") && (i || this.isZoomedIn) && (i ? (i = !1, t.normalize() && requestAnimationFrame(() => {
606
610
  this.close();
607
611
  })) : this.isZoomedIn && o.pointers.length === 0 && (n = t.moveAndNormalize(o.pointer)));
608
612
  this.pointerListeners.forEach(
609
- (a) => a({
613
+ (r) => r({
610
614
  ...o,
611
- hasInternalExecution: this.isZoomedIn || i
615
+ hasInternalExecution: this.isZoomedIn || i,
616
+ abortController: this.abortController
612
617
  })
613
618
  );
614
619
  };
615
620
  });
616
621
  this.elements = t, this.options = {
617
- ...T,
622
+ ...H,
618
623
  ...e,
619
624
  controls: {
620
- ...T.controls,
625
+ ...H.controls,
621
626
  ...e.controls
622
627
  }
623
- }, this.imageState = new tt(
628
+ }, this.imageState = new it(
624
629
  this.options.maxZoomLevel,
625
630
  (i) => {
626
- var n, o, a, r, h, c;
631
+ var n, o, r, a, l, c;
627
632
  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(
628
633
  "pointer-events",
629
634
  "none"
630
- )) : (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(
635
+ )) : (this.isZoomedIn = !0, (r = this.qs(".vvw-zoom-out")) == null || r.removeAttribute("disabled"), (a = this.qs('.vvw-item[data-vvw-idx="' + this.currentIndex + '"]')) == null || a.style.setProperty(
631
636
  "pointer-events",
632
637
  "auto"
633
- )), i.isMax ? (h = this.qs(".vvw-zoom-in")) == null || h.setAttribute("disabled", "true") : (c = this.qs(".vvw-zoom-in")) == null || c.removeAttribute("disabled");
638
+ )), i.isMax ? (l = this.qs(".vvw-zoom-in")) == null || l.setAttribute("disabled", "true") : (c = this.qs(".vvw-zoom-in")) == null || c.removeAttribute("disabled");
634
639
  }
635
640
  ), 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) => {
636
641
  i.dataset.vistaIdx = n.toString(), i.addEventListener("click", this.defaultOnClickHandler), i.addEventListener("pointerup", this.onClickElements);
@@ -640,41 +645,50 @@ class it {
640
645
  return this.root ? this.root.querySelector(t) : null;
641
646
  }
642
647
  async swap(t, e) {
643
- const i = this.options.preloads || 0, n = this.currentIndex, { htmls: o, images: a } = this.getChildElements(i, n), r = this.imageContainer, h = this.currentChildren, c = {
644
- htmlElements: { from: h.htmls, to: o },
645
- images: { from: h.images, to: a },
648
+ const i = this.options.preloads || 0, n = this.currentIndex, { htmls: o, images: r } = this.getChildElements(i, n), a = this.imageContainer, l = this.currentChildren, c = {
649
+ htmlElements: { from: l.htmls, to: o },
650
+ images: { from: l.images, to: r },
646
651
  index: { from: t, to: this.currentIndex },
647
652
  via: e || { next: !1, prev: !1 },
648
653
  vistaView: this
649
654
  };
650
- this.setupFunction(c), this.currentChildren = { htmls: o, images: a }, this.displayActiveIndex();
651
- const m = this.abortController.signal, w = performance.now(), b = w - this.lastSwapTime < this.options.rapidLimit;
652
- let p = null;
653
- b || (p = await this.transitionFunction(c, m)), this.lastSwapTime = w;
654
- const d = o[Math.floor(o.length / 2)].dataset.vvwIdx, v = r.querySelector(
655
+ this.setupFunction(c), this.currentChildren = { htmls: o, images: r }, this.displayActiveIndex();
656
+ const m = this.abortController.signal;
657
+ if (performance.now() - this.lastSwapTime < this.options.rapidLimit) {
658
+ a.innerHTML = "", this.transitionCleanup && this.transitionCleanup(), o.forEach((b) => {
659
+ a.appendChild(b);
660
+ }), this.lastSwapTime = performance.now(), this.waitForImagesToLoad(), this.options.onImageView && this.options.onImageView(c);
661
+ return;
662
+ }
663
+ const g = this.transitionFunction(c, m);
664
+ g && (this.transitionCleanup = g.cleanup, await g.transitionEnded), this.lastSwapTime = performance.now();
665
+ const d = o[Math.floor(o.length / 2)].dataset.vvwIdx, u = a.querySelector(
655
666
  `.vvw-item[data-vvw-idx="${d}"] img.vvw-img-hi`
656
- ), g = v.getAttribute("style") || "", f = v.classList.contains("vvw--loaded"), u = v.width, L = v.height;
657
- this.imageState.reset(), r.innerHTML = "", p instanceof Function && p(), o.forEach((E) => {
658
- const y = E.querySelector("img.vvw-img-hi");
659
- E.dataset.vvwPos === "0" && !m.aborted && g && f && // ready &&
660
- 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());
667
+ ), y = this.imageTransitions.get(u);
668
+ this.imageTransitions.delete(u);
669
+ const f = u.getAttribute("style") || "", v = u.classList.contains("vvw--loaded"), E = u.classList.contains("vvw--ready"), I = u.width, T = u.height;
670
+ this.imageState.reset(), a.innerHTML = "", this.transitionCleanup && this.transitionCleanup(), o.forEach((b) => {
671
+ const w = b.querySelector("img.vvw-img-hi");
672
+ b.dataset.vvwPos === "0" && !m.aborted && f && I && T && (v && (w.classList.add("vvw--loaded"), w.dataset.vvwWidth = u.dataset.vvwWidth || "", w.dataset.vvwHeight = u.dataset.vvwHeight || ""), E && (w.classList.add("vvw--ready"), w.width = I, w.height = T), w.setAttribute("style", f)), a.appendChild(b), b.dataset.vvwPos === "0" && !m.aborted && E ? (this.imageState.setCurrentImage(w), this.imageState.setInitialCenter()) : b.dataset.vvwPos === "0" && !m.aborted && f && I && T && v && y && (this.imageTransitions.set(w, y), this.transitionImage(w, () => {
673
+ this.imageState.setCurrentImage(w), this.imageState.setInitialCenter(), w.classList.add("vvw--ready");
674
+ }));
661
675
  }), this.waitForImagesToLoad(), this.options.onImageView && this.options.onImageView(c);
662
676
  }
663
677
  getChildElements(t, e) {
664
678
  const i = [], n = [];
665
679
  for (let o = -t; o <= t; o++) {
666
- 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 ? {
667
- index: a,
668
- imageElm: h instanceof HTMLImageElement ? h : void 0,
669
- anchorElm: r instanceof HTMLAnchorElement ? r : void 0,
670
- src: r.dataset.vistaviewSrc || r.getAttribute("href") || r.getAttribute("src") || "",
671
- thumb: r.dataset.vistaviewThumb || (h instanceof HTMLImageElement ? h.getAttribute("src") : void 0) || r.getAttribute("href") || void 0,
672
- alt: h instanceof HTMLImageElement && h.getAttribute("alt") || void 0
680
+ const r = (e + o + this.elements.length) % this.elements.length, a = this.elements[r], l = a instanceof HTMLImageElement ? a : a instanceof HTMLAnchorElement && a.querySelector("img") || void 0, c = a instanceof HTMLElement ? {
681
+ index: r,
682
+ imageElm: l instanceof HTMLImageElement ? l : void 0,
683
+ anchorElm: a instanceof HTMLAnchorElement ? a : void 0,
684
+ src: a.dataset.vistaviewSrc || a.getAttribute("href") || a.getAttribute("src") || "",
685
+ thumb: a.dataset.vistaviewThumb || (l instanceof HTMLImageElement ? l.getAttribute("src") : void 0) || a.getAttribute("href") || void 0,
686
+ alt: l instanceof HTMLImageElement && l.getAttribute("alt") || void 0
673
687
  } : {
674
- index: a,
675
- ...r
688
+ index: r,
689
+ ...a
676
690
  };
677
- n.push(c), i.push(j(c, o));
691
+ n.push(c), i.push(U(c, o));
678
692
  }
679
693
  return {
680
694
  htmls: i,
@@ -700,34 +714,45 @@ class it {
700
714
  );
701
715
  }
702
716
  displayActiveIndex() {
703
- var a;
717
+ var r;
704
718
  const t = this.currentIndex;
705
- this.elements instanceof NodeList && this.elements.forEach((r, h) => {
706
- r.style.opacity = "", h === t && (r.style.opacity = "0");
719
+ this.elements instanceof NodeList && this.elements.forEach((a, l) => {
720
+ a.style.opacity = "", l === t && (a.style.opacity = "0");
707
721
  });
708
722
  const e = this.qs(".vvw-index"), i = `${t + 1}`, n = `${this.elements.length}`;
709
723
  e && (e.textContent = `${i} / ${n}`);
710
724
  const o = this.qs(".vvw-desc");
711
725
  if (o) {
712
- const r = (a = this.currentChildren) == null ? void 0 : a.images.find((c) => c.index === t), h = (r == null ? void 0 : r.alt) || "";
713
- h ? (o.textContent = h, o.setAttribute("aria-label", `Image ${i} of ${n}: ${h}`)) : (o.textContent = "", o.setAttribute("aria-label", `Image ${i} of ${n}`));
726
+ const a = (r = this.currentChildren) == null ? void 0 : r.images.find((c) => c.index === t), l = (a == null ? void 0 : a.alt) || "";
727
+ l ? (o.textContent = l, o.setAttribute("aria-label", `Image ${i} of ${n}: ${l}`)) : (o.textContent = "", o.setAttribute("aria-label", `Image ${i} of ${n}`));
714
728
  }
715
729
  }
730
+ transitionImage(t, e) {
731
+ const i = this.imageTransitions.get(t);
732
+ i && requestAnimationFrame(() => {
733
+ const { current: n, target: o } = i, r = {
734
+ width: n.width + (o.width - n.width) * 0.1,
735
+ height: n.height + (o.height - n.height) * 0.1,
736
+ radius: n.radius + (o.radius - n.radius) * 0.1
737
+ };
738
+ Math.abs(r.width - o.width) < 0.5 && Math.abs(r.height - o.height) < 0.5 && Math.abs(r.radius - o.radius) < 0.5 ? (t.style.setProperty("--vvw-current-w", `${o.width}px`), t.style.setProperty("--vvw-current-h", `${o.height}px`), t.style.setProperty("--vvw-current-radius", `${o.radius}px`), this.imageTransitions.delete(t), e()) : (t.style.setProperty("--vvw-current-w", `${r.width}px`), t.style.setProperty("--vvw-current-h", `${r.height}px`), t.style.setProperty("--vvw-current-radius", `${r.radius}px`), this.imageTransitions.set(t, { current: r, target: o }), this.transitionImage(t, e));
739
+ });
740
+ }
716
741
  waitForImagesToLoad() {
717
742
  this.imageContainer.querySelectorAll("img.vvw-img-hi:not(.vvw--loaded)").forEach((i) => {
718
743
  const n = i, o = () => {
719
- var r;
744
+ var c;
720
745
  n.width = n.naturalWidth, n.height = n.naturalHeight;
721
- const a = (r = n.parentElement) == null ? void 0 : r.matches(`[data-vvw-idx="${this.currentIndex}"]`);
722
- n.addEventListener(
723
- "transitionend",
724
- () => {
725
- a && (this.imageState.setCurrentImage(n), this.imageState.setInitialCenter()), n.classList.add("vvw--ready");
746
+ const r = (c = n.parentElement) == null ? void 0 : c.matches(`[data-vvw-idx="${this.currentIndex}"]`), { width: a, height: l } = M(n);
747
+ n.dataset.vvwWidth = a.toString(), n.dataset.vvwHeight = l.toString(), n.classList.add("vvw--loaded"), this.imageTransitions.set(n, {
748
+ current: {
749
+ width: n.style.getPropertyValue("--vvw-current-w") ? parseFloat(n.style.getPropertyValue("--vvw-current-w")) : 0,
750
+ height: n.style.getPropertyValue("--vvw-current-h") ? parseFloat(n.style.getPropertyValue("--vvw-current-h")) : 0,
751
+ radius: n.style.getPropertyValue("--vvw-current-radius") ? parseFloat(n.style.getPropertyValue("--vvw-current-radius")) : 0
726
752
  },
727
- { once: !0 }
728
- ), n.classList.add("vvw--loaded"), requestAnimationFrame(() => {
729
- const { width: h, height: c } = S(n);
730
- 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");
753
+ target: { width: a, height: l, radius: 0 }
754
+ }), this.transitionImage(n, () => {
755
+ r && (this.imageState.setCurrentImage(n), this.imageState.setInitialCenter()), n.classList.add("vvw--ready");
731
756
  });
732
757
  };
733
758
  if (n.complete && n.naturalWidth !== 0) {
@@ -737,10 +762,10 @@ class it {
737
762
  n.addEventListener("load", () => {
738
763
  o();
739
764
  }), n.addEventListener("error", () => {
740
- var r;
765
+ var a;
741
766
  n.classList.add("vvw--loaderror");
742
- const a = document.createElement("p");
743
- a.className = "vvw-img-err", a.setAttribute("role", "alert"), a.textContent = "Error loading image", (r = n.parentNode) == null || r.appendChild(a);
767
+ const r = document.createElement("p");
768
+ r.className = "vvw-img-err", r.setAttribute("role", "alert"), r.textContent = "Error loading image", (a = n.parentNode) == null || a.appendChild(r);
744
769
  });
745
770
  });
746
771
  }
@@ -752,30 +777,30 @@ class it {
752
777
  }
753
778
  /// OPEN
754
779
  open(t = 0) {
755
- var c, m, w, b, p;
780
+ var c, m, p, L, g;
756
781
  if (x.somethingOpened)
757
782
  return;
758
783
  x.somethingOpened = this, this.currentIndex = t, document.body.style.overflow = "hidden";
759
- const e = U({
784
+ const e = K({
760
785
  controls: this.options.controls
761
786
  });
762
787
  if (document.body.prepend(e), this.root = document.body.querySelector("#vvw-root"), !this.root)
763
788
  throw new Error("Failed to setup VistaView root element.");
764
789
  this.imageContainer = this.qs(".vvw-image-container"), this.options.animationDurationBase && this.root.style.setProperty("--vvw-anim-dur", `${this.options.animationDurationBase}`), this.options.initialZIndex !== void 0 && this.root.style.setProperty("--vvw-init-z", `${this.options.initialZIndex ?? 0}`), this.options.arrowOnSmallScreens && this.root.classList.add("vvw-arrow-sm");
765
- const i = this.options.preloads || 0, n = t, { images: o, htmls: a } = this.getChildElements(i, n), r = {
766
- htmlElements: { from: null, to: a },
790
+ const i = this.options.preloads || 0, n = t, { images: o, htmls: r } = this.getChildElements(i, n), a = {
791
+ htmlElements: { from: null, to: r },
767
792
  images: { from: null, to: o },
768
793
  index: { from: null, to: this.currentIndex },
769
794
  via: { next: !1, prev: !1 },
770
795
  vistaView: this
771
796
  };
772
- this.setupFunction(r), this.currentChildren = { htmls: a, images: o }, a.forEach((d) => {
797
+ this.setupFunction(a), this.currentChildren = { htmls: r, images: o }, r.forEach((d) => {
773
798
  this.imageContainer.appendChild(d);
774
- }), (c = this.qs(".vvw-close")) == null || c.addEventListener("click", () => this.close()), (m = this.qs(".vvw-zoom-in")) == null || m.addEventListener("click", () => this.zoomIn()), (w = this.qs(".vvw-zoom-out")) == null || w.addEventListener("click", () => this.zoomOut()), (b = this.qs(".vvw-prev>button")) == null || b.addEventListener("click", () => this.prev()), (p = this.qs(".vvw-next>button")) == null || p.addEventListener("click", () => this.next()), this.options.keyboardListeners && window.addEventListener("keydown", this.onKeyDown), window.addEventListener("wheel", this.onScroll, { passive: !1 }), window.addEventListener("resize", this.onResizeHandler), this.pointers = new V({
799
+ }), (c = this.qs(".vvw-close")) == null || c.addEventListener("click", () => this.close()), (m = this.qs(".vvw-zoom-in")) == null || m.addEventListener("click", () => this.zoomIn()), (p = this.qs(".vvw-zoom-out")) == null || p.addEventListener("click", () => this.zoomOut()), (L = this.qs(".vvw-prev>button")) == null || L.addEventListener("click", () => this.prev()), (g = this.qs(".vvw-next>button")) == null || g.addEventListener("click", () => this.next()), this.options.keyboardListeners && window.addEventListener("keydown", this.onKeyDown), window.addEventListener("wheel", this.onScroll, { passive: !1 }), window.addEventListener("resize", this.onResizeHandler), this.pointers = new et({
775
800
  elm: this.imageContainer,
776
801
  listeners: [this.getInternalPointerListener()]
777
802
  });
778
- const h = {};
803
+ const l = {};
779
804
  [
780
805
  ...this.options.controls.topLeft || [],
781
806
  ...this.options.controls.topRight || [],
@@ -784,29 +809,27 @@ class it {
784
809
  ...this.options.controls.bottomLeft || [],
785
810
  ...this.options.controls.bottomRight || []
786
811
  ].forEach((d) => {
787
- typeof d != "string" && (h[d.name] = d);
812
+ typeof d != "string" && (l[d.name] = d);
788
813
  }), this.root.querySelectorAll("button[data-vvw-control]").forEach((d) => {
789
- const v = d;
790
- v.addEventListener("click", (g) => {
791
- const f = g.currentTarget.dataset.vvwControl, u = h[f], L = this.currentChildren.images.find(
792
- (E) => E.index === this.currentIndex
814
+ const u = d;
815
+ u.addEventListener("click", (y) => {
816
+ const f = y.currentTarget.dataset.vvwControl, v = l[f], E = this.currentChildren.images.find(
817
+ (I) => I.index === this.currentIndex
793
818
  );
794
- u && L && (u.onClick.constructor.name === "AsyncFunction" ? (v.classList.add("vvw--loading"), u.onClick(L, this).finally(() => {
795
- v.classList.remove("vvw--loading");
796
- })) : u.onClick(L, this));
819
+ v && E && (v.onClick.constructor.name === "AsyncFunction" ? (u.classList.add("vvw--loading"), v.onClick(E, this).finally(() => {
820
+ u.classList.remove("vvw--loading");
821
+ })) : v.onClick(E, this));
797
822
  });
798
823
  }), this.initFunction(this), requestAnimationFrame(() => {
799
824
  var d;
800
825
  (d = this.root) == null || d.addEventListener(
801
826
  "transitionend",
802
827
  () => {
803
- var v, g;
804
- (v = this.root) == null || v.classList.add("vvw--settled"), this.waitForImagesToLoad(), (g = this.qs(".vvw-bg")) == null || g.addEventListener("click", (f) => {
805
- f.preventDefault(), this.close();
806
- }), this.imageState.reset();
828
+ var u;
829
+ (u = this.root) == null || u.classList.add("vvw--settled"), this.waitForImagesToLoad(), this.imageState.reset();
807
830
  },
808
831
  { once: !0 }
809
- ), this.root.classList.add("vvw--active"), this.displayActiveIndex(), this.options.onOpen && this.options.onOpen(this), this.options.onImageView && this.options.onImageView(r);
832
+ ), this.root.classList.add("vvw--active"), this.displayActiveIndex(), this.options.onOpen && this.options.onOpen(this), this.options.onImageView && this.options.onImageView(a);
810
833
  });
811
834
  }
812
835
  /// CLOSE
@@ -814,8 +837,8 @@ class it {
814
837
  x.somethingOpened === this && this.root && (t ? await new Promise((e) => {
815
838
  let n = 0;
816
839
  this.root.addEventListener("transitionend", (o) => {
817
- o.target === this.root && (n++, n === 2 && this.elements instanceof NodeList && this.elements.forEach((a) => {
818
- a.style.opacity = "";
840
+ o.target === this.root && (n++, n === 2 && this.elements instanceof NodeList && this.elements.forEach((r) => {
841
+ r.style.opacity = "";
819
842
  }), n === 3 && e(null));
820
843
  }), this.root.classList.add("vvw--closing");
821
844
  }) : this.elements instanceof NodeList && this.elements.forEach((e) => {
@@ -851,7 +874,7 @@ class it {
851
874
  n == null || n.abort(), this.abortController = new AbortController(), this.swap(i, e);
852
875
  }
853
876
  }
854
- function nt(s) {
877
+ function ot(s) {
855
878
  let t = null;
856
879
  if (typeof s == "string" ? t = document.querySelectorAll(s) : s instanceof NodeList && (t = s), t)
857
880
  for (let e = 0; e < t.length; e++) {
@@ -867,12 +890,12 @@ function nt(s) {
867
890
  }
868
891
  return t || s;
869
892
  }
870
- function ot({ elements: s, ...t }) {
893
+ function at({ elements: s, ...t }) {
871
894
  if (!s) throw new Error("No elements");
872
- let e = nt(s);
895
+ let e = ot(s);
873
896
  if (typeof e == "string")
874
897
  return null;
875
- const i = new it(e, t);
898
+ const i = new st(e, t);
876
899
  return {
877
900
  open: (n = 0) => i.open(n),
878
901
  close: () => i.close(),
@@ -886,7 +909,7 @@ function ot({ elements: s, ...t }) {
886
909
  };
887
910
  }
888
911
  export {
889
- T as DefaultOptions,
890
- ot as vistaView,
891
- N as vistaViewDownload
912
+ H as DefaultOptions,
913
+ at as vistaView,
914
+ j as vistaViewDownload
892
915
  };