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/lib/defaults.d.ts.map +1 -1
- package/dist/lib/vista-view.d.ts +4 -3
- package/dist/lib/vista-view.d.ts.map +1 -1
- package/dist/vistaview.cjs +4 -4
- package/dist/vistaview.css +1 -1
- package/dist/vistaview.js +252 -242
- package/dist/vistaview.umd.js +4 -4
- package/package.json +1 -1
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
|
|
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
|
|
19
|
+
let P = null;
|
|
20
20
|
function V() {
|
|
21
|
-
return
|
|
21
|
+
return P || (window.trustedTypes || (window.trustedTypes = {
|
|
22
22
|
createPolicy: (s, t) => t
|
|
23
|
-
}),
|
|
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
|
-
}),
|
|
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
|
|
44
|
-
const i = window.getComputedStyle(s).objectFit || "", { width: n, height: e } = s.getBoundingClientRect(),
|
|
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 (!
|
|
47
|
+
if (!r || !d)
|
|
48
48
|
return { width: n, height: e };
|
|
49
|
-
const o =
|
|
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:
|
|
54
|
+
return { width: r, height: d };
|
|
55
55
|
case "contain":
|
|
56
|
-
return o >
|
|
56
|
+
return o > a ? { width: n, height: n / o } : { width: e * o, height: e };
|
|
57
57
|
case "cover":
|
|
58
|
-
return o <
|
|
58
|
+
return o < a ? { width: n, height: n / o } : { width: e * o, height: e };
|
|
59
59
|
case "scale-down": {
|
|
60
|
-
const
|
|
61
|
-
return
|
|
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
|
|
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
|
|
76
|
-
let o,
|
|
77
|
-
return
|
|
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:
|
|
79
|
+
height: a
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
function
|
|
83
|
-
const i = window.innerHeight, n = window.innerWidth, e = s,
|
|
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:
|
|
86
|
+
minDiffY: c,
|
|
87
87
|
maxDiffY: o,
|
|
88
|
-
minDiffX:
|
|
88
|
+
minDiffX: a
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
const
|
|
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
|
|
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 = ((
|
|
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
|
|
123
|
-
const i = s.imageElm ? getComputedStyle(s.imageElm) : null, n = (i == null ? void 0 : i.objectFit) || "", e = ((
|
|
124
|
-
|
|
125
|
-
const
|
|
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
|
-
${
|
|
130
|
+
${r ? `height="${r}"` : ""}
|
|
131
131
|
/>
|
|
132
132
|
<img class="vistaview-image-highres" src="${s.src}" alt="${s.alt || ""}" />`);
|
|
133
|
-
return
|
|
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>${
|
|
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,
|
|
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,
|
|
158
|
-
A = (
|
|
159
|
-
|
|
160
|
-
},
|
|
161
|
-
if (
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
},
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"),
|
|
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 = (
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
const
|
|
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
|
-
),
|
|
177
|
-
function
|
|
178
|
-
|
|
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
|
|
183
|
-
|
|
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 (
|
|
187
|
+
if (u < -g || u > g) {
|
|
188
188
|
let E = function() {
|
|
189
|
-
|
|
189
|
+
h[0].removeEventListener("transitionend", E), setTimeout(() => {
|
|
190
190
|
const L = s.isReducedMotion;
|
|
191
|
-
s.isReducedMotion = !0,
|
|
192
|
-
|
|
191
|
+
s.isReducedMotion = !0, p(), s.view(
|
|
192
|
+
u < -g ? (I + 1) % i : (I - 1 + i) % i,
|
|
193
193
|
{
|
|
194
|
-
next:
|
|
195
|
-
prev:
|
|
194
|
+
next: u < -g,
|
|
195
|
+
prev: u > g
|
|
196
196
|
}
|
|
197
197
|
), s.isReducedMotion = L;
|
|
198
198
|
}, 100);
|
|
199
199
|
};
|
|
200
|
-
|
|
201
|
-
} else
|
|
202
|
-
}, t.addEventListener("pointermove",
|
|
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 && (
|
|
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:
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
234
|
+
l(new S("Transition aborted"));
|
|
233
235
|
return;
|
|
234
236
|
}
|
|
235
|
-
const m = (
|
|
236
|
-
if (o.aborted)
|
|
237
|
-
|
|
238
|
-
|
|
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 (!
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
270
|
-
|
|
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
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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 (
|
|
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),
|
|
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:
|
|
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.
|
|
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.
|
|
379
|
-
} catch (
|
|
380
|
-
|
|
375
|
+
await this.userTransition(o, this.transitionAbortControllers[a].signal);
|
|
376
|
+
} catch (v) {
|
|
377
|
+
v instanceof S || console.warn(v);
|
|
381
378
|
}
|
|
382
|
-
this.
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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,
|
|
398
|
+
var i, n, e, r, d, o;
|
|
394
399
|
if (this.isZoomed !== t) {
|
|
395
400
|
if (this.isZoomed) {
|
|
396
|
-
let
|
|
397
|
-
if (
|
|
398
|
-
|
|
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
|
|
404
|
-
this.onZoomedPointerDown = (
|
|
405
|
-
|
|
406
|
-
}, this.onZoomedPointerMove = (
|
|
407
|
-
if (!
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
), E = Math.min(
|
|
413
|
-
|
|
414
|
-
}, this.onZoomedPointerUp = (
|
|
415
|
-
|
|
416
|
-
}, (
|
|
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
|
|
423
|
-
const t = (
|
|
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
|
|
430
|
-
t.style.width = `${
|
|
431
|
-
const
|
|
432
|
-
t.style.height = `${
|
|
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,
|
|
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,
|
|
440
|
-
|
|
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",
|
|
443
|
-
const
|
|
444
|
-
t.style.width = `${
|
|
445
|
-
const m =
|
|
446
|
-
t.style.height = `${m}px`, (
|
|
447
|
-
const { maxDiffX:
|
|
448
|
-
let
|
|
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
|
-
),
|
|
455
|
+
), b = parseInt(
|
|
451
456
|
(t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-y").replace("px", "")) || "0"
|
|
452
457
|
);
|
|
453
|
-
|
|
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
|
|
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:
|
|
466
|
-
alt:
|
|
467
|
-
thumb:
|
|
468
|
-
imageElm: e instanceof HTMLImageElement ? e :
|
|
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
|
|
481
|
+
var c, l;
|
|
477
482
|
if (!this.rootElm) return;
|
|
478
|
-
const t = (
|
|
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,
|
|
481
|
-
this.rootElm.style.setProperty("--vistaview-container-initial-width",
|
|
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
|
|
495
|
-
const
|
|
499
|
+
var l, h;
|
|
500
|
+
const r = (l = i.rootElm) == null ? void 0 : l.querySelector(
|
|
496
501
|
"button.vistaview-zoom-in-btn"
|
|
497
|
-
), d = (
|
|
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,
|
|
500
|
-
|
|
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:
|
|
512
|
-
o.w = Math.min(d.width,
|
|
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
|
|
515
|
-
var
|
|
516
|
-
|
|
517
|
-
|
|
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
|
|
520
|
-
|
|
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
|
|
523
|
-
|
|
524
|
-
};
|
|
525
|
-
e.addEventListener("transitionend", f);
|
|
526
|
-
|
|
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 ((
|
|
531
|
-
|
|
537
|
+
if ((h = this.rootElm) != null && h.classList.contains("vistaview--opened"))
|
|
538
|
+
c();
|
|
532
539
|
else {
|
|
533
|
-
const
|
|
534
|
-
var
|
|
535
|
-
(
|
|
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 ?
|
|
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
|
-
],
|
|
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:
|
|
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:
|
|
594
|
-
e.classList.contains("vistaview-image--zooming") ? (e.dataset.vistaviewInitialWidth =
|
|
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,
|
|
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((
|
|
621
|
+
const e = this.currentImages.map((p, x) => q(p, n[x]));
|
|
615
622
|
this.currentItems = e;
|
|
616
|
-
const
|
|
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(
|
|
629
|
-
this.imageContainerElm.appendChild(
|
|
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", (
|
|
633
|
-
var
|
|
634
|
-
|
|
635
|
-
}), (
|
|
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((
|
|
643
|
-
typeof
|
|
644
|
-
}), this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach((
|
|
645
|
-
|
|
646
|
-
const E = this.customControls[
|
|
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" ? (
|
|
650
|
-
|
|
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 && ((
|
|
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,
|
|
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
|
|
672
|
+
var a;
|
|
666
673
|
let o;
|
|
667
|
-
(
|
|
668
|
-
|
|
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), (
|
|
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
|
-
|
|
751
|
+
S as VistaViewTransitionAbortedError,
|
|
742
752
|
st as defaultClose,
|
|
743
753
|
et as defaultInit,
|
|
744
754
|
it as defaultSetup,
|