vistaview 0.3.12 → 0.3.13
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/README.md +7 -7
- package/dist/lib/defaults.d.ts.map +1 -1
- package/dist/lib/types.d.ts +1 -6
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/vista-view.d.ts +0 -1
- package/dist/lib/vista-view.d.ts.map +1 -1
- package/dist/vistaview.cjs +4 -4
- package/dist/vistaview.js +234 -268
- package/dist/vistaview.umd.js +4 -4
- package/package.json +1 -1
package/dist/vistaview.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
|
4
|
-
function
|
|
3
|
+
var m = (s, t, i) => Y(s, typeof t != "symbol" ? t + "" : t, i);
|
|
4
|
+
function Z(s) {
|
|
5
5
|
const t = getComputedStyle(s), i = s.getBoundingClientRect();
|
|
6
6
|
return {
|
|
7
7
|
objectFit: t.objectFit,
|
|
@@ -17,7 +17,7 @@ function z(s) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
let S = null;
|
|
20
|
-
function
|
|
20
|
+
function F() {
|
|
21
21
|
return S || (window.trustedTypes || (window.trustedTypes = {
|
|
22
22
|
createPolicy: (s, t) => t
|
|
23
23
|
}), S = window.trustedTypes.createPolicy("vistaView-policy", {
|
|
@@ -32,38 +32,38 @@ function B() {
|
|
|
32
32
|
}), S);
|
|
33
33
|
}
|
|
34
34
|
function W(s) {
|
|
35
|
-
const i =
|
|
35
|
+
const i = F().createHTML(s), n = document.createElement("template");
|
|
36
36
|
n.innerHTML = i;
|
|
37
37
|
const e = n.content;
|
|
38
38
|
return n.remove(), e;
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function T(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(), r = s.naturalWidth,
|
|
43
|
+
function _(s) {
|
|
44
|
+
const i = window.getComputedStyle(s).objectFit || "", { width: n, height: e } = s.getBoundingClientRect(), r = s.naturalWidth, a = s.naturalHeight;
|
|
45
45
|
if (!i)
|
|
46
46
|
return { width: n, height: e };
|
|
47
|
-
if (!r || !
|
|
47
|
+
if (!r || !a)
|
|
48
48
|
return { width: n, height: e };
|
|
49
|
-
const o = r /
|
|
49
|
+
const o = r / a, l = n / e;
|
|
50
50
|
switch (i) {
|
|
51
51
|
case "fill":
|
|
52
52
|
return { width: n, height: e };
|
|
53
53
|
case "none":
|
|
54
|
-
return { width: r, height:
|
|
54
|
+
return { width: r, height: a };
|
|
55
55
|
case "contain":
|
|
56
|
-
return o >
|
|
56
|
+
return o > l ? { width: n, height: n / o } : { width: e * o, height: e };
|
|
57
57
|
case "cover":
|
|
58
|
-
return o <
|
|
58
|
+
return o < l ? { width: n, height: n / o } : { width: e * o, height: e };
|
|
59
59
|
case "scale-down": {
|
|
60
|
-
const c = { width: r, height:
|
|
61
|
-
return
|
|
60
|
+
const c = { width: r, height: a }, d = o > l ? { width: n, height: n / o } : { width: e * o, height: e };
|
|
61
|
+
return d.width <= c.width && d.height <= c.height ? d : c;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
return { width: n, height: e };
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function R(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,23 +72,23 @@ function T(s) {
|
|
|
72
72
|
width: n,
|
|
73
73
|
height: e
|
|
74
74
|
};
|
|
75
|
-
const r = n / e,
|
|
76
|
-
let o,
|
|
77
|
-
return r >
|
|
75
|
+
const r = n / e, a = t / i;
|
|
76
|
+
let o, l;
|
|
77
|
+
return r > a ? (o = t, l = t / r) : (l = i, o = i * r), {
|
|
78
78
|
width: o,
|
|
79
|
-
height:
|
|
79
|
+
height: l
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
function H(s, t) {
|
|
83
|
-
const i = window.innerHeight, n = window.innerWidth, e = s, r = t,
|
|
83
|
+
const i = window.innerHeight, n = window.innerWidth, e = s, r = t, a = Math.max(0, (e - n) / 2) + n / 2, o = Math.max(0, (r - i) / 2) + i / 2, l = -a, c = -o;
|
|
84
84
|
return {
|
|
85
|
-
maxDiffX:
|
|
85
|
+
maxDiffX: a,
|
|
86
86
|
minDiffY: c,
|
|
87
87
|
maxDiffY: o,
|
|
88
|
-
minDiffX:
|
|
88
|
+
minDiffX: l
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
const
|
|
91
|
+
const B = '<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>', N = '<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></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="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>', V = '<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",
|
|
@@ -104,9 +104,9 @@ function J(s) {
|
|
|
104
104
|
if (typeof s == "string")
|
|
105
105
|
switch (s) {
|
|
106
106
|
case "zoomIn":
|
|
107
|
-
return `<button class="vistaview-zoom-in-btn">${
|
|
107
|
+
return `<button class="vistaview-zoom-in-btn">${U}</button>`;
|
|
108
108
|
case "zoomOut":
|
|
109
|
-
return `<button disabled class="vistaview-zoom-out-btn">${
|
|
109
|
+
return `<button disabled class="vistaview-zoom-out-btn">${V}</button>`;
|
|
110
110
|
case "close":
|
|
111
111
|
return `<button class="vistaview-close-btn">${K}</button>`;
|
|
112
112
|
case "indexDisplay":
|
|
@@ -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
|
-
|
|
122
|
+
var d, h;
|
|
123
|
+
const i = s.imageElm ? getComputedStyle(s.imageElm) : null, n = (i == null ? void 0 : i.objectFit) || "", e = ((d = s.imageElm) == null ? void 0 : d.naturalWidth) || "", r = ((h = s.imageElm) == null ? void 0 : h.naturalHeight) || "", a = (i == null ? void 0 : i.width) || "", o = (i == null ? void 0 : i.height) || "", l = document.createElement("div");
|
|
124
|
+
l.className = "vistaview-item", l.dataset.vistaviewPos = `${t !== void 0 ? t : ""}`, l.dataset.vistaviewIndex = s.index.toString();
|
|
125
125
|
const c = W(`<img class="vistaview-image-lowres"
|
|
126
|
-
style="${n ? `object-fit:${n};` : ""}${
|
|
126
|
+
style="${n ? `object-fit:${n};` : ""}${a ? `width:${a};` : ""}${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 l.appendChild(c), l;
|
|
134
134
|
}
|
|
135
135
|
function Q({
|
|
136
136
|
controls: s,
|
|
@@ -143,120 +143,102 @@ 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>${
|
|
147
|
-
<div class="vistaview-next-btn vistaview-ui"><button>${
|
|
146
|
+
<div class="vistaview-prev-btn vistaview-ui"><button>${B}</button></div>
|
|
147
|
+
<div class="vistaview-next-btn vistaview-ui"><button>${N}</button></div>
|
|
148
148
|
</div>
|
|
149
149
|
</div>`
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
|
-
let
|
|
152
|
+
let $ = null, z = null, M = null, A = 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, r = 0,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
},
|
|
161
|
-
if (
|
|
162
|
-
const h =
|
|
163
|
-
r =
|
|
164
|
-
},
|
|
165
|
-
if (
|
|
157
|
+
let n = 0, e = 0, r = 0, a = 0, o = null, l = 0, c = !1;
|
|
158
|
+
$ = (d) => {
|
|
159
|
+
d.preventDefault(), d.stopPropagation(), s.isZoomed === !1 && (c = !0, n = d.pageX, e = d.pageY, r = d.pageX, a = d.pageY, l = Date.now(), o = null, t.setPointerCapture(d.pointerId));
|
|
160
|
+
}, z = (d) => {
|
|
161
|
+
if (d.preventDefault(), d.stopPropagation(), s.isZoomed !== !1 || !c) return;
|
|
162
|
+
const h = d.pageX - n, u = d.pageY - e;
|
|
163
|
+
r = d.pageX, a = d.pageY, Math.abs(h) >= Math.abs(u) && (o === null || o === !0) ? (t.style.setProperty("--vistaview-pointer-diff-x", `${h}px`), o = !0) : Math.abs(u) > Math.abs(h) && (o === null || o === !1) && (t.style.setProperty("--vistaview-pointer-diff-y", `${u}px`), o = !1);
|
|
164
|
+
}, A = (d) => {
|
|
165
|
+
if (d.preventDefault(), d.stopPropagation(), t.releasePointerCapture(d.pointerId), s.isZoomed !== !1 || !c) return;
|
|
166
166
|
c = !1, o = null;
|
|
167
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((
|
|
169
|
-
|
|
168
|
+
t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), h.forEach((u) => {
|
|
169
|
+
u.style.transition = "", u.style.translate = "";
|
|
170
170
|
});
|
|
171
|
-
}, M = (
|
|
172
|
-
if (
|
|
171
|
+
}, M = (d) => {
|
|
172
|
+
if (d.preventDefault(), d.stopPropagation(), t.releasePointerCapture(d.pointerId), s.isZoomed !== !1 || !c) return;
|
|
173
173
|
c = !1;
|
|
174
|
-
const h = Array.from(t.querySelectorAll(".vistaview-item")),
|
|
175
|
-
(
|
|
176
|
-
),
|
|
177
|
-
function
|
|
178
|
-
h[0].removeEventListener("transitionend",
|
|
179
|
-
|
|
174
|
+
const h = Array.from(t.querySelectorAll(".vistaview-item")), u = r - n, p = a - e, f = Date.now() - l, v = u / f, E = p / f, g = s.options.touchSpeedThreshold || 0.5, b = h.find(
|
|
175
|
+
(y) => y.dataset.vistaviewPos === "0"
|
|
176
|
+
), C = Number(b.dataset.vistaviewIndex);
|
|
177
|
+
function w() {
|
|
178
|
+
h[0].removeEventListener("transitionend", w), t.style.removeProperty("--vistaview-pointer-diff-x"), t.style.removeProperty("--vistaview-pointer-diff-y"), h.forEach((y) => {
|
|
179
|
+
y.style.transition = "", y.style.translate = "";
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function x(y = "0%", I = "0%") {
|
|
183
183
|
h.forEach((D) => {
|
|
184
|
-
D.style.transition = `translate ${s.options.animationDurationBase * 0.5}ms ease-out`, D.style.translate = `${
|
|
184
|
+
D.style.transition = `translate ${s.options.animationDurationBase * 0.5}ms ease-out`, D.style.translate = `${y} ${I}`;
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
if (
|
|
188
|
-
let
|
|
189
|
-
h[0].removeEventListener("transitionend",
|
|
190
|
-
const
|
|
191
|
-
s.isReducedMotion = !0,
|
|
192
|
-
|
|
187
|
+
if (v < -g || v > g) {
|
|
188
|
+
let y = function() {
|
|
189
|
+
h[0].removeEventListener("transitionend", y), setTimeout(() => {
|
|
190
|
+
const I = s.isReducedMotion, D = s.options.detectReducedMotion;
|
|
191
|
+
s.isReducedMotion = !0, s.options.detectReducedMotion = !0, w(), s.view(
|
|
192
|
+
v < -g ? (C + 1) % i : (C - 1 + i) % i,
|
|
193
193
|
{
|
|
194
|
-
next:
|
|
195
|
-
prev:
|
|
194
|
+
next: v < -g,
|
|
195
|
+
prev: v > g
|
|
196
196
|
}
|
|
197
|
-
), s.isReducedMotion =
|
|
197
|
+
), s.isReducedMotion = I, s.options.detectReducedMotion = D;
|
|
198
198
|
}, 100);
|
|
199
199
|
};
|
|
200
|
-
|
|
201
|
-
} else
|
|
202
|
-
}, t.addEventListener("pointermove",
|
|
200
|
+
x(v < -g ? "-100%" : "100%"), h[0].addEventListener("transitionend", y);
|
|
201
|
+
} else E < -g || E > g ? (s.close(), x("0%", "0%")) : (h[0].addEventListener("transitionend", w), x("0%"), v === 0 && E === 0 && s.zoomIn());
|
|
202
|
+
}, t.addEventListener("pointermove", z), t.addEventListener("pointerup", M), t.addEventListener("pointerdown", $), t.addEventListener("pointercancel", A);
|
|
203
203
|
}
|
|
204
204
|
function O(s) {
|
|
205
205
|
const t = s.imageContainerElm;
|
|
206
|
-
t && (
|
|
206
|
+
t && (z && t.removeEventListener("pointermove", z), M && t.removeEventListener("pointerup", M), $ && t.removeEventListener("pointerdown", $), A && t.removeEventListener("pointercancel", A));
|
|
207
207
|
}
|
|
208
208
|
const et = (s) => {
|
|
209
209
|
tt(s);
|
|
210
210
|
}, it = ({
|
|
211
211
|
htmlElements: { to: s },
|
|
212
212
|
index: { to: t },
|
|
213
|
-
|
|
213
|
+
vistaView: i
|
|
214
214
|
}) => {
|
|
215
|
-
i instanceof NodeList && t !== null && (i.forEach((n) => n.style.opacity = "1"), i[t].style.opacity = "0"), s && s.forEach((n) => {
|
|
215
|
+
i.elements instanceof NodeList && t !== null && (i.elements.forEach((n) => n.style.opacity = "1"), i.elements[t].style.opacity = "0"), s && s.forEach((n) => {
|
|
216
216
|
const e = Number(n.dataset.vistaviewPos);
|
|
217
217
|
e !== 0 ? (n.style.zIndex = "1", n.style.left = 100 * e + "%") : n.style.zIndex = "2";
|
|
218
218
|
});
|
|
219
219
|
}, nt = async ({
|
|
220
|
-
htmlElements: { from: s
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
options: r,
|
|
224
|
-
isReducedMotion: d
|
|
220
|
+
htmlElements: { from: s },
|
|
221
|
+
via: { next: t, prev: i },
|
|
222
|
+
vistaView: n
|
|
225
223
|
// index: { from: fromIndex, to: toIndex },
|
|
226
|
-
},
|
|
227
|
-
if (
|
|
228
|
-
if (d)
|
|
224
|
+
}, e) => {
|
|
225
|
+
if (n.options.detectReducedMotion && n.isReducedMotion)
|
|
229
226
|
return;
|
|
230
|
-
const
|
|
231
|
-
await new Promise((
|
|
232
|
-
let
|
|
233
|
-
if (
|
|
234
|
-
|
|
227
|
+
const r = s.filter((a) => a.dataset.vistaviewPos === "0" || (t ? a.dataset.vistaviewPos === "1" : a.dataset.vistaviewPos === "-1"));
|
|
228
|
+
await new Promise((a, o) => {
|
|
229
|
+
let l = 0, c = !1;
|
|
230
|
+
if (e.aborted) {
|
|
231
|
+
o(new P("Transition aborted"));
|
|
235
232
|
return;
|
|
236
233
|
}
|
|
237
|
-
const
|
|
238
|
-
if (o
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
".vistaview-image-highres"
|
|
243
|
-
);
|
|
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 x = 0;
|
|
249
|
-
const I = setInterval(() => {
|
|
250
|
-
if (o.aborted)
|
|
251
|
-
return clearInterval(I), l(new P("Transition aborted"));
|
|
252
|
-
if (x++, x > r.animationDurationBase / 20 * 1.5)
|
|
253
|
-
return clearInterval(I), c(0);
|
|
254
|
-
if (g.classList.contains("vistaview-image-settled"))
|
|
255
|
-
return m == null || m.classList.add("vistaview-image-settled"), clearInterval(I), c(0);
|
|
256
|
-
}, 20);
|
|
234
|
+
const d = (h) => {
|
|
235
|
+
if (c) return o(new P("Transition aborted"));
|
|
236
|
+
if (e.aborted)
|
|
237
|
+
return c || (c = !0), o(new P("Transition aborted"));
|
|
238
|
+
h.currentTarget.removeEventListener("transitionend", d), l++, l >= r.length && a(0);
|
|
257
239
|
};
|
|
258
|
-
|
|
259
|
-
|
|
240
|
+
r.forEach((h) => {
|
|
241
|
+
h.style.transition = `translate ${n.options.animationDurationBase * 0.5}ms ease-out`, h.style.translate = t ? "-100%" : i ? "100%" : "0%", h.addEventListener("transitionend", d);
|
|
260
242
|
});
|
|
261
243
|
});
|
|
262
244
|
}, st = (s) => {
|
|
@@ -283,15 +265,15 @@ const k = {
|
|
|
283
265
|
topRight: ["zoomIn", "zoomOut", G(), "close"],
|
|
284
266
|
bottomCenter: ["description"]
|
|
285
267
|
}
|
|
286
|
-
},
|
|
268
|
+
}, L = {
|
|
287
269
|
somethingOpened: null
|
|
288
270
|
};
|
|
289
271
|
class ot {
|
|
290
272
|
constructor(t, i) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
273
|
+
m(this, "options");
|
|
274
|
+
m(this, "elements");
|
|
275
|
+
m(this, "isReducedMotion");
|
|
276
|
+
m(this, "currentIndex", {
|
|
295
277
|
_value: null,
|
|
296
278
|
_vistaView: null,
|
|
297
279
|
_via: { next: !1, prev: !1 },
|
|
@@ -299,8 +281,8 @@ class ot {
|
|
|
299
281
|
var n, e, r;
|
|
300
282
|
const i = this._value;
|
|
301
283
|
this._value = t;
|
|
302
|
-
for (const
|
|
303
|
-
(e = this._vistaView) == null || e.transitionAbortControllers[
|
|
284
|
+
for (const a in (n = this._vistaView) == null ? void 0 : n.transitionAbortControllers)
|
|
285
|
+
(e = this._vistaView) == null || e.transitionAbortControllers[a].abort();
|
|
304
286
|
(r = this._vistaView) == null || r.swap(i, this._value);
|
|
305
287
|
},
|
|
306
288
|
get value() {
|
|
@@ -313,29 +295,28 @@ class ot {
|
|
|
313
295
|
this._via = t;
|
|
314
296
|
}
|
|
315
297
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
w(this, "onClickElements", (t) => {
|
|
298
|
+
m(this, "rootElm", null);
|
|
299
|
+
m(this, "imageContainerElm", null);
|
|
300
|
+
m(this, "customControls", {});
|
|
301
|
+
m(this, "currentImages", null);
|
|
302
|
+
m(this, "currentItems", null);
|
|
303
|
+
m(this, "isZoomed", !1);
|
|
304
|
+
m(this, "onClickElements", (t) => {
|
|
324
305
|
t.preventDefault();
|
|
325
306
|
const i = t.currentTarget;
|
|
326
307
|
i.dataset.vistaviewIndex && this.open(parseInt(i.dataset.vistaviewIndex));
|
|
327
308
|
});
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
309
|
+
m(this, "defaultOnClickHandler", (t) => t.preventDefault());
|
|
310
|
+
m(this, "onResizeHandler", null);
|
|
311
|
+
m(this, "onKeyDown", null);
|
|
312
|
+
m(this, "userSetup", it);
|
|
313
|
+
m(this, "userTransition", nt);
|
|
314
|
+
m(this, "userClose", st);
|
|
315
|
+
m(this, "userInit", et);
|
|
316
|
+
m(this, "onZoomedPointerDown", null);
|
|
317
|
+
m(this, "onZoomedPointerMove", null);
|
|
318
|
+
m(this, "onZoomedPointerUp", null);
|
|
319
|
+
m(this, "transitionAbortControllers", {});
|
|
339
320
|
// weird on iphones
|
|
340
321
|
// private loadImageWaiting = (img: HTMLImageElement): Promise<void> => {
|
|
341
322
|
// return new Promise((resolve) => {
|
|
@@ -359,7 +340,7 @@ class ot {
|
|
|
359
340
|
// });
|
|
360
341
|
// });
|
|
361
342
|
// };
|
|
362
|
-
|
|
343
|
+
m(this, "loadImageTimeout", null);
|
|
363
344
|
this.elements = t, this.currentIndex._vistaView = this, this.options = {
|
|
364
345
|
...k,
|
|
365
346
|
...i || {},
|
|
@@ -372,115 +353,110 @@ class ot {
|
|
|
372
353
|
});
|
|
373
354
|
}
|
|
374
355
|
setFullSizeImageDim(t) {
|
|
375
|
-
var r,
|
|
376
|
-
const i = t.getBoundingClientRect(), { width: n, height: e } =
|
|
356
|
+
var r, a;
|
|
357
|
+
const i = t.getBoundingClientRect(), { width: n, height: e } = R(t);
|
|
377
358
|
if (n === i.width && e === i.height)
|
|
378
|
-
(
|
|
359
|
+
(a = (r = t.parentElement) == null ? void 0 : r.querySelector(".vistaview-image-lowres")) == null || a.classList.add("vistaview-image--hidden"), t.classList.add("vistaview-image-settled");
|
|
379
360
|
else {
|
|
380
361
|
let o = 0;
|
|
381
|
-
const
|
|
382
|
-
var c,
|
|
383
|
-
o++, !(o < 3) && (t.removeEventListener("transitionend",
|
|
362
|
+
const l = () => {
|
|
363
|
+
var c, d;
|
|
364
|
+
o++, !(o < 3) && (t.removeEventListener("transitionend", l), (d = (c = t.parentElement) == null ? void 0 : c.querySelector(".vistaview-image-lowres")) == null || d.classList.add("vistaview-image--hidden"), t.classList.add("vistaview-image-settled"));
|
|
384
365
|
};
|
|
385
366
|
requestAnimationFrame(() => {
|
|
386
|
-
t.addEventListener("transitionend",
|
|
367
|
+
t.addEventListener("transitionend", l), t.style.width = `${n}px`, t.style.height = `${e}px`;
|
|
387
368
|
});
|
|
388
369
|
}
|
|
389
370
|
}
|
|
390
371
|
async swap(t, i) {
|
|
391
|
-
var
|
|
392
|
-
if (!
|
|
372
|
+
var d, h;
|
|
373
|
+
if (!L.somethingOpened || t === i || t === null) return;
|
|
393
374
|
if (!this.imageContainerElm)
|
|
394
375
|
throw new Error("VistaView: imageContainerElm is null in swap()");
|
|
395
376
|
this.setIndexDisplay(), this.clearZoom();
|
|
396
|
-
const { images: n, positions: e } = this.getCurrentIndexes(i), r = this.getImages(n),
|
|
397
|
-
htmlElements: { from: this.currentItems, to:
|
|
377
|
+
const { images: n, positions: e } = this.getCurrentIndexes(i), r = this.getImages(n), a = r.map((u, p) => q(u, e[p])), o = {
|
|
378
|
+
htmlElements: { from: this.currentItems, to: a },
|
|
398
379
|
images: { from: this.currentImages, to: r },
|
|
399
380
|
index: { from: t, to: i },
|
|
400
381
|
via: this.currentIndex.via,
|
|
401
|
-
|
|
402
|
-
elements: this.elements,
|
|
403
|
-
isReducedMotion: this.isReducedMotion,
|
|
404
|
-
navActive: this.navActive,
|
|
405
|
-
isZoomed: this.isZoomed,
|
|
406
|
-
options: this.options
|
|
382
|
+
vistaView: this
|
|
407
383
|
};
|
|
408
384
|
this.userSetup(o);
|
|
409
|
-
const
|
|
410
|
-
this.transitionAbortControllers[
|
|
385
|
+
const l = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
386
|
+
this.transitionAbortControllers[l] = new AbortController();
|
|
411
387
|
try {
|
|
412
|
-
await this.userTransition(o, this.transitionAbortControllers[
|
|
413
|
-
} catch (
|
|
414
|
-
|
|
388
|
+
await this.userTransition(o, this.transitionAbortControllers[l].signal);
|
|
389
|
+
} catch (u) {
|
|
390
|
+
u instanceof P || console.warn(u);
|
|
415
391
|
}
|
|
416
|
-
const c =
|
|
392
|
+
const c = a.find((u) => u.dataset.vistaviewPos === "0");
|
|
417
393
|
if (c) {
|
|
418
|
-
const
|
|
419
|
-
if (
|
|
420
|
-
const
|
|
394
|
+
const u = c.dataset.vistaviewIndex, p = this.currentItems.find((v) => v.dataset.vistaviewIndex === u), f = p == null ? void 0 : p.querySelector(".vistaview-image-highres");
|
|
395
|
+
if (f) {
|
|
396
|
+
const v = c.querySelector(
|
|
421
397
|
".vistaview-image-highres"
|
|
422
398
|
);
|
|
423
|
-
if (
|
|
424
|
-
const
|
|
425
|
-
|
|
399
|
+
if (v.setAttribute("class", f.getAttribute("class") || ""), v.setAttribute("style", f.getAttribute("style") || ""), v.classList.remove("vistaview-image--zooming"), f.classList.contains("vistaview-image-loaded") && !f.classList.contains("vistaview-image-settled")) {
|
|
400
|
+
const E = f.getBoundingClientRect();
|
|
401
|
+
v.style.width = `${E.width}px`, v.style.height = `${E.height}px`;
|
|
426
402
|
}
|
|
427
403
|
}
|
|
428
404
|
}
|
|
429
|
-
delete this.transitionAbortControllers[
|
|
430
|
-
var
|
|
431
|
-
const
|
|
432
|
-
this.imageContainerElm.appendChild(
|
|
433
|
-
}), this.setInitialDimPos(), this.currentImages = r, this.currentItems =
|
|
405
|
+
delete this.transitionAbortControllers[l], this.imageContainerElm.innerHTML = "", a.forEach((u) => {
|
|
406
|
+
var E;
|
|
407
|
+
const p = u.querySelector(".vistaview-image-highres"), f = !!p.classList.contains("vistaview-image-loaded"), v = !!p.classList.contains("vistaview-image-settled");
|
|
408
|
+
this.imageContainerElm.appendChild(u), f && !v ? this.setFullSizeImageDim(p) : f && v && ((E = u == null ? void 0 : u.querySelector(".vistaview-image-lowres")) == null || E.classList.add("vistaview-image--hidden"));
|
|
409
|
+
}), this.setInitialDimPos(), this.currentImages = r, this.currentItems = a, this.setCurrentDescription(), this.updateZoomButtonsVisibility(), (h = (d = this.options).onImageView) == null || h.call(d, o), this.loadImageTimeout && clearTimeout(this.loadImageTimeout), this.loadImageTimeout = setTimeout(() => {
|
|
434
410
|
this.loadImages();
|
|
435
411
|
}, 333);
|
|
436
412
|
}
|
|
437
413
|
//
|
|
438
414
|
setZoomed(t) {
|
|
439
|
-
var i, n, e, r,
|
|
415
|
+
var i, n, e, r, a, o;
|
|
440
416
|
if (this.isZoomed !== t) {
|
|
441
417
|
if (this.isZoomed) {
|
|
442
|
-
let
|
|
443
|
-
if (
|
|
444
|
-
|
|
418
|
+
let l = this.isZoomed;
|
|
419
|
+
if (l.classList.remove("vistaview-image--zooming"), this.onZoomedPointerDown && ((i = l.parentElement) == null || i.removeEventListener("pointerdown", this.onZoomedPointerDown), this.onZoomedPointerDown = null), this.onZoomedPointerMove && ((n = l.parentElement) == null || n.removeEventListener("pointermove", this.onZoomedPointerMove), this.onZoomedPointerMove = null), this.onZoomedPointerUp && ((e = l.parentElement) == null || e.removeEventListener("pointerup", this.onZoomedPointerUp), this.onZoomedPointerUp = null), l == null || l.style.removeProperty("--pointer-diff-x"), l == null || l.style.removeProperty("--pointer-diff-y"), setTimeout(() => {
|
|
420
|
+
l == null || l.classList.remove("vistaview-image--zooming");
|
|
445
421
|
}, 500), this.isZoomed = !1, !t) return;
|
|
446
422
|
}
|
|
447
423
|
if (t) {
|
|
448
424
|
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");
|
|
449
|
-
let
|
|
450
|
-
this.onZoomedPointerDown = (
|
|
451
|
-
|
|
452
|
-
}, this.onZoomedPointerMove = (
|
|
453
|
-
if (!
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
|
|
425
|
+
let l = !1, c = 0, d = 0, h = 0, u = 0, p = 0, f = 0;
|
|
426
|
+
this.onZoomedPointerDown = (v) => {
|
|
427
|
+
v.preventDefault(), v.stopPropagation(), l = !0, c = v.pageX, d = v.pageY, t.setPointerCapture(v.pointerId);
|
|
428
|
+
}, this.onZoomedPointerMove = (v) => {
|
|
429
|
+
if (!l) return;
|
|
430
|
+
v.preventDefault(), p = v.pageX - c, f = v.pageY - d;
|
|
431
|
+
const E = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentWidth) || "0"), g = parseInt((t == null ? void 0 : t.dataset.vistaviewCurrentHeight) || "0"), { maxDiffX: b, minDiffY: C, maxDiffY: w, minDiffX: x } = H(
|
|
432
|
+
E,
|
|
457
433
|
g
|
|
458
|
-
),
|
|
459
|
-
|
|
460
|
-
}, this.onZoomedPointerUp = (
|
|
461
|
-
|
|
462
|
-
}, (r = t == null ? void 0 : t.parentElement) == null || r.addEventListener("pointerdown", this.onZoomedPointerDown), (
|
|
434
|
+
), y = Math.min(b, Math.max(x, h + p)), I = Math.min(w, Math.max(C, u + f));
|
|
435
|
+
p = y - h, f = I - u, t == null || t.style.setProperty("--pointer-diff-x", `${y}px`), t == null || t.style.setProperty("--pointer-diff-y", `${I}px`);
|
|
436
|
+
}, this.onZoomedPointerUp = (v) => {
|
|
437
|
+
l = !1, t.releasePointerCapture(v.pointerId), h += p, u += f, p = 0, f = 0;
|
|
438
|
+
}, (r = t == null ? void 0 : t.parentElement) == null || r.addEventListener("pointerdown", this.onZoomedPointerDown), (a = t == null ? void 0 : t.parentElement) == null || a.addEventListener("pointermove", this.onZoomedPointerMove), (o = t == null ? void 0 : t.parentElement) == null || o.addEventListener("pointerup", this.onZoomedPointerUp);
|
|
463
439
|
return;
|
|
464
440
|
}
|
|
465
441
|
}
|
|
466
442
|
}
|
|
467
443
|
zoomIn() {
|
|
468
|
-
var r,
|
|
444
|
+
var r, a, o, l, c;
|
|
469
445
|
const t = (r = this.rootElm) == null ? void 0 : r.querySelector(
|
|
470
446
|
'[data-vistaview-pos="0"] .vistaview-image-highres'
|
|
471
447
|
), i = t.width, n = t.height;
|
|
472
448
|
t.dataset.vistaviewInitialWidth || (t.dataset.vistaviewInitialWidth = i.toString()), t.dataset.vistaviewInitialHeight || (t.dataset.vistaviewInitialHeight = n.toString()), this.setZoomed(t);
|
|
473
449
|
const e = (t.naturalWidth || 0) * this.options.maxZoomLevel;
|
|
474
450
|
if (i && e && i < e) {
|
|
475
|
-
const
|
|
476
|
-
t.style.width = `${
|
|
477
|
-
const h =
|
|
478
|
-
t.style.height = `${h}px`, (o = (
|
|
451
|
+
const d = Math.min(i + this.options.zoomStep, e);
|
|
452
|
+
t.style.width = `${d}px`;
|
|
453
|
+
const h = d / i * n;
|
|
454
|
+
t.style.height = `${h}px`, (o = (a = this.rootElm) == null ? void 0 : a.querySelector("button.vistaview-zoom-out-btn")) == null || o.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = d.toString(), t.dataset.vistaviewCurrentHeight = h.toString(), d === e && ((c = (l = this.rootElm) == null ? void 0 : l.querySelector("button.vistaview-zoom-in-btn")) == null || c.setAttribute("disabled", "true"));
|
|
479
455
|
}
|
|
480
456
|
}
|
|
481
457
|
zoomOut() {
|
|
482
|
-
var
|
|
483
|
-
const t = (
|
|
458
|
+
var a, o, l, c, d;
|
|
459
|
+
const t = (a = this.rootElm) == null ? void 0 : a.querySelector(
|
|
484
460
|
'[data-vistaview-pos="0"] .vistaview-image-highres'
|
|
485
461
|
), i = t.width, n = t.height, e = t.dataset.vistaviewInitialWidth ? parseInt(t.dataset.vistaviewInitialWidth) : 0, r = (h) => {
|
|
486
462
|
h.target === t && (t.classList.remove("vistaview-image--zooming-out"), t.removeEventListener("transitionend", r));
|
|
@@ -488,15 +464,15 @@ class ot {
|
|
|
488
464
|
if (t.addEventListener("transitionend", r), t.classList.add("vistaview-image--zooming-out"), i && e && i > e) {
|
|
489
465
|
const h = Math.max(i - this.options.zoomStep, e);
|
|
490
466
|
t.style.width = `${h}px`;
|
|
491
|
-
const
|
|
492
|
-
t.style.height = `${
|
|
493
|
-
const { maxDiffX:
|
|
467
|
+
const u = h / i * n;
|
|
468
|
+
t.style.height = `${u}px`, (l = (o = this.rootElm) == null ? void 0 : o.querySelector("button.vistaview-zoom-in-btn")) == null || l.removeAttribute("disabled"), t.dataset.vistaviewCurrentWidth = h.toString(), t.dataset.vistaviewCurrentHeight = u.toString();
|
|
469
|
+
const { maxDiffX: p, minDiffY: f, maxDiffY: v, minDiffX: E } = H(h, u);
|
|
494
470
|
let g = parseInt(
|
|
495
471
|
(t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-x").replace("px", "")) || "0"
|
|
496
|
-
),
|
|
472
|
+
), b = parseInt(
|
|
497
473
|
(t == null ? void 0 : t.style.getPropertyValue("--pointer-diff-y").replace("px", "")) || "0"
|
|
498
474
|
);
|
|
499
|
-
g = Math.min(
|
|
475
|
+
g = Math.min(p, Math.max(E, g)), b = Math.min(v, 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 && ((d = (c = this.rootElm) == null ? void 0 : c.querySelector("button.vistaview-zoom-out-btn")) == null || d.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));
|
|
500
476
|
}
|
|
501
477
|
}
|
|
502
478
|
clearZoom() {
|
|
@@ -505,12 +481,12 @@ class ot {
|
|
|
505
481
|
return t.map((i, n) => {
|
|
506
482
|
const e = this.elements[i];
|
|
507
483
|
if (e instanceof HTMLElement) {
|
|
508
|
-
const r = e.querySelector("img"),
|
|
484
|
+
const r = e.querySelector("img"), a = e.getAttribute("href") || "", o = e.getAttribute("src") || "", l = e.dataset.vistaviewSrc || a || o || (r == null ? void 0 : r.src) || "", c = e.dataset.vistaviewAlt || e.getAttribute("alt") || (r == null ? void 0 : r.alt) || "", d = e.dataset.vistaviewThumb || (r == null ? void 0 : r.src) || a || o || "";
|
|
509
485
|
return {
|
|
510
486
|
index: t[n],
|
|
511
|
-
src:
|
|
487
|
+
src: l,
|
|
512
488
|
alt: c,
|
|
513
|
-
thumb:
|
|
489
|
+
thumb: d,
|
|
514
490
|
imageElm: e instanceof HTMLImageElement ? e : r,
|
|
515
491
|
anchorElm: e instanceof HTMLAnchorElement ? e : void 0
|
|
516
492
|
};
|
|
@@ -519,14 +495,14 @@ class ot {
|
|
|
519
495
|
});
|
|
520
496
|
}
|
|
521
497
|
setInitialDimPos() {
|
|
522
|
-
var c,
|
|
498
|
+
var c, d;
|
|
523
499
|
if (!this.rootElm) return;
|
|
524
|
-
const t = (c = this.rootElm.querySelector('[data-vistaview-pos="0"]')) == null ? void 0 : c.dataset.vistaviewIndex, i = ((
|
|
500
|
+
const t = (c = this.rootElm.querySelector('[data-vistaview-pos="0"]')) == null ? void 0 : c.dataset.vistaviewIndex, i = ((d = this.currentImages) == null ? void 0 : d.find((h) => h.index === Number(t))) || null;
|
|
525
501
|
if (!i) return;
|
|
526
|
-
const n = i.imageElm ?
|
|
527
|
-
this.rootElm.style.setProperty("--vistaview-container-initial-width", r + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-height",
|
|
502
|
+
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, a = (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, l = ((e == null ? void 0 : e.top) || (n == null ? void 0 : n.top) || 0) + a / 2;
|
|
503
|
+
this.rootElm.style.setProperty("--vistaview-container-initial-width", r + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-height", a + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-top", l + "px"), this.rootElm.style.setProperty("--vistaview-container-initial-left", o + "px"), this.rootElm.style.setProperty(
|
|
528
504
|
"--vistaview-image-border-radius",
|
|
529
|
-
|
|
505
|
+
T(e == null ? void 0 : e.borderRadius) || T(n == null ? void 0 : n.borderRadius) || "0px"
|
|
530
506
|
);
|
|
531
507
|
}
|
|
532
508
|
updateZoomButtonsVisibility() {
|
|
@@ -537,13 +513,13 @@ class ot {
|
|
|
537
513
|
if (!t) return;
|
|
538
514
|
const i = this;
|
|
539
515
|
function n() {
|
|
540
|
-
var
|
|
541
|
-
const r = (
|
|
516
|
+
var d, h;
|
|
517
|
+
const r = (d = i.rootElm) == null ? void 0 : d.querySelector(
|
|
542
518
|
"button.vistaview-zoom-in-btn"
|
|
543
|
-
),
|
|
519
|
+
), a = (h = i.rootElm) == null ? void 0 : h.querySelector(
|
|
544
520
|
"button.vistaview-zoom-out-btn"
|
|
545
|
-
), o = parseInt(t.style.width) || t.width,
|
|
546
|
-
r && (r.style.display = c ? "" : "none"),
|
|
521
|
+
), o = parseInt(t.style.width) || t.width, l = t.naturalWidth * i.options.maxZoomLevel, c = o < l && l > 0;
|
|
522
|
+
r && (r.style.display = c ? "" : "none"), a && (a.style.display = c ? "" : "none");
|
|
547
523
|
}
|
|
548
524
|
t.complete && t.naturalWidth > 0 ? n() : t.addEventListener("load", n);
|
|
549
525
|
}
|
|
@@ -552,29 +528,29 @@ class ot {
|
|
|
552
528
|
this.rootElm.querySelectorAll(
|
|
553
529
|
".vistaview-image-highres:not(.vistaview-image-loaded)"
|
|
554
530
|
).forEach((i, n) => {
|
|
555
|
-
const e = i,
|
|
556
|
-
if (
|
|
557
|
-
const { width: c, height:
|
|
558
|
-
o.w = Math.min(
|
|
531
|
+
const e = i, a = this.currentImages[n].imageElm, o = { w: 0, h: 0 };
|
|
532
|
+
if (a) {
|
|
533
|
+
const { width: c, height: d } = _(a);
|
|
534
|
+
o.w = Math.min(a.width, c), o.h = Math.min(a.height, d);
|
|
559
535
|
}
|
|
560
|
-
const
|
|
561
|
-
var
|
|
536
|
+
const l = () => {
|
|
537
|
+
var d;
|
|
562
538
|
const c = () => {
|
|
563
539
|
var h;
|
|
564
540
|
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(() => {
|
|
565
541
|
this.setFullSizeImageDim(e);
|
|
566
542
|
}, 100), (h = i.parentElement) != null && h.matches('[data-vistaview-pos="0"]') && this.updateZoomButtonsVisibility();
|
|
567
543
|
};
|
|
568
|
-
if ((
|
|
544
|
+
if ((d = this.rootElm) != null && d.classList.contains("vistaview--opened"))
|
|
569
545
|
c();
|
|
570
546
|
else {
|
|
571
547
|
const h = setInterval(() => {
|
|
572
|
-
var
|
|
573
|
-
(
|
|
548
|
+
var u;
|
|
549
|
+
(u = this.rootElm) != null && u.classList.contains("vistaview--opened") && (clearInterval(h), c());
|
|
574
550
|
}, 50);
|
|
575
551
|
}
|
|
576
552
|
};
|
|
577
|
-
e.complete && e.naturalWidth > 0 ?
|
|
553
|
+
e.complete && e.naturalWidth > 0 ? l() : e.onload = l;
|
|
578
554
|
});
|
|
579
555
|
}
|
|
580
556
|
setIndexDisplay() {
|
|
@@ -588,12 +564,12 @@ class ot {
|
|
|
588
564
|
.../* @__PURE__ */ new Set([
|
|
589
565
|
...Array.from(
|
|
590
566
|
{ length: i },
|
|
591
|
-
(
|
|
567
|
+
(a, o) => ((t - i + o) % n + n) % n
|
|
592
568
|
),
|
|
593
569
|
t,
|
|
594
|
-
...Array.from({ length: i }, (
|
|
570
|
+
...Array.from({ length: i }, (a, o) => (t + 1 + o) % n)
|
|
595
571
|
])
|
|
596
|
-
], r = n < 1 || !i ? [0] : e.map((
|
|
572
|
+
], r = n < 1 || !i ? [0] : e.map((a, o) => o - Math.floor(e.length / 2));
|
|
597
573
|
return {
|
|
598
574
|
images: e,
|
|
599
575
|
positions: r
|
|
@@ -628,65 +604,60 @@ class ot {
|
|
|
628
604
|
".vistaview-image-highres.vistaview-image-loaded"
|
|
629
605
|
);
|
|
630
606
|
t == null || t.forEach((n) => {
|
|
631
|
-
const e = n, { width: r, height:
|
|
632
|
-
e.classList.contains("vistaview-image--zooming") ? (e.dataset.vistaviewInitialWidth = r.toString(), e.dataset.vistaviewInitialHeight =
|
|
607
|
+
const e = n, { width: r, height: a } = R(e);
|
|
608
|
+
e.classList.contains("vistaview-image--zooming") ? (e.dataset.vistaviewInitialWidth = r.toString(), e.dataset.vistaviewInitialHeight = a.toString()) : (e.style.width = `${r}px`, e.style.height = `${a}px`);
|
|
633
609
|
});
|
|
634
610
|
}, window.addEventListener("resize", this.onResizeHandler);
|
|
635
611
|
}
|
|
636
612
|
open(t = 0) {
|
|
637
|
-
var o,
|
|
638
|
-
if (
|
|
613
|
+
var o, l, c, d, h, u, p, f, v, E, g, b, C;
|
|
614
|
+
if (L.somethingOpened) {
|
|
639
615
|
console.error("VistaView: another instance is already opened. Returning.");
|
|
640
616
|
return;
|
|
641
617
|
}
|
|
642
|
-
if (
|
|
618
|
+
if (L.somethingOpened = this, this.currentIndex._value = t, document.body.prepend(
|
|
643
619
|
Q({
|
|
644
620
|
controls: this.options.controls,
|
|
645
621
|
isReducedMotion: this.isReducedMotion
|
|
646
622
|
})
|
|
647
623
|
), this.rootElm = document.querySelector("#vistaview-root"), this.imageContainerElm = ((o = this.rootElm) == null ? void 0 : o.querySelector(".vistaview-image-container")) || null, !this.rootElm || !this.imageContainerElm)
|
|
648
|
-
throw
|
|
624
|
+
throw L.somethingOpened = null, new Error("Failed to create VistaView element");
|
|
649
625
|
this.options.arrowOnSmallScreens || this.rootElm.classList.add("vistaview-no-arrows-sm");
|
|
650
626
|
const { images: i, positions: n } = this.getCurrentIndexes(t);
|
|
651
627
|
this.currentImages = this.getImages(i);
|
|
652
|
-
const e = this.currentImages.map((
|
|
628
|
+
const e = this.currentImages.map((w, x) => q(w, n[x]));
|
|
653
629
|
this.currentItems = e;
|
|
654
630
|
const r = {
|
|
655
631
|
htmlElements: { from: null, to: this.currentItems },
|
|
656
632
|
images: { from: null, to: this.currentImages },
|
|
657
633
|
index: { from: null, to: t },
|
|
658
634
|
via: this.currentIndex.via,
|
|
659
|
-
|
|
660
|
-
elements: this.elements,
|
|
661
|
-
isReducedMotion: this.isReducedMotion,
|
|
662
|
-
navActive: this.navActive,
|
|
663
|
-
isZoomed: this.isZoomed,
|
|
664
|
-
options: this.options
|
|
635
|
+
vistaView: this
|
|
665
636
|
};
|
|
666
|
-
this.userSetup(r), this.imageContainerElm.innerHTML = "", this.currentItems.forEach((
|
|
667
|
-
this.imageContainerElm.appendChild(
|
|
637
|
+
this.userSetup(r), this.imageContainerElm.innerHTML = "", this.currentItems.forEach((w) => {
|
|
638
|
+
this.imageContainerElm.appendChild(w);
|
|
668
639
|
});
|
|
669
|
-
let
|
|
670
|
-
this.rootElm.addEventListener("animationend", (
|
|
671
|
-
var
|
|
672
|
-
|
|
673
|
-
}), (
|
|
640
|
+
let a = 0;
|
|
641
|
+
this.rootElm.addEventListener("animationend", (w) => {
|
|
642
|
+
var x;
|
|
643
|
+
w.currentTarget === this.rootElm && (a++, a >= 2 && ((x = this.rootElm) == null || x.classList.add("vistaview--opened")));
|
|
644
|
+
}), (l = this.rootElm.querySelector(".vistaview-close-btn")) == null || l.addEventListener("click", () => this.close()), (c = this.rootElm.querySelector(".vistaview-zoom-in-btn")) == null || c.addEventListener("click", () => this.zoomIn()), (d = this.rootElm.querySelector(".vistaview-zoom-out-btn")) == null || d.addEventListener("click", () => this.zoomOut()), (h = this.rootElm.querySelector(".vistaview-prev-btn>button")) == null || h.addEventListener("click", () => this.prev()), (u = this.rootElm.querySelector(".vistaview-next-btn>button")) == null || u.addEventListener("click", () => this.next()), [
|
|
674
645
|
...this.options.controls.topLeft || [],
|
|
675
646
|
...this.options.controls.topRight || [],
|
|
676
647
|
...this.options.controls.topCenter || [],
|
|
677
648
|
...this.options.controls.bottomCenter || [],
|
|
678
649
|
...this.options.controls.bottomLeft || [],
|
|
679
650
|
...this.options.controls.bottomRight || []
|
|
680
|
-
].forEach((
|
|
681
|
-
typeof
|
|
682
|
-
}), this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach((
|
|
683
|
-
|
|
684
|
-
const
|
|
651
|
+
].forEach((w) => {
|
|
652
|
+
typeof w != "string" && (this.customControls[w.name] = w);
|
|
653
|
+
}), this.rootElm.querySelectorAll("button[data-vistaview-custom-control]").forEach((w) => {
|
|
654
|
+
w.addEventListener("click", (x) => {
|
|
655
|
+
const y = this.customControls[x.currentTarget.dataset.vistaviewCustomControl], I = this.currentImages.find(
|
|
685
656
|
(D) => D.index === this.currentIndex.value
|
|
686
657
|
);
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
})) :
|
|
658
|
+
y && I && (y.onClick.constructor.name === "AsyncFunction" ? (w.classList.add("vistaview-button--loading"), y.onClick(I).finally(() => {
|
|
659
|
+
w.classList.remove("vistaview-button--loading");
|
|
660
|
+
})) : y.onClick(I));
|
|
690
661
|
});
|
|
691
662
|
}), this.options.animationDurationBase && this.rootElm.style.setProperty(
|
|
692
663
|
"--vistaview-animation-duration",
|
|
@@ -694,17 +665,17 @@ class ot {
|
|
|
694
665
|
), this.options.initialZIndex !== void 0 && this.rootElm.style.setProperty(
|
|
695
666
|
"--vistaview-initial-z-index",
|
|
696
667
|
`${this.options.initialZIndex}`
|
|
697
|
-
), this.setInitialDimPos(), this.setResizeListeners(), this.options.keyboardListeners && this.setKeyboardListeners(), this.elements.length === 1 && ((
|
|
668
|
+
), this.setInitialDimPos(), this.setResizeListeners(), this.options.keyboardListeners && this.setKeyboardListeners(), this.elements.length === 1 && ((p = this.rootElm.querySelector(".vistaview-prev-btn")) == null || p.classList.add("vistaview-ui--none"), (f = this.rootElm.querySelector(".vistaview-next-btn")) == null || f.classList.add("vistaview-ui--none"), (v = this.rootElm.querySelector(".vistaview-index-display")) == null || v.classList.add("vistaview-ui--none")), this.rootElm && this.rootElm.classList.add("vistaview--initialized"), this.loadImages(), this.setCurrentDescription(), this.setIndexDisplay(), this.userInit(this), (g = (E = this.options).onOpen) == null || g.call(E, r), (C = (b = this.options).onImageView) == null || C.call(b, r);
|
|
698
669
|
}
|
|
699
670
|
async close(t = !0) {
|
|
700
671
|
var n, e, r;
|
|
701
|
-
if (
|
|
702
|
-
t && ((n = this.rootElm) == null || n.classList.add("vistaview--closing"), await new Promise((
|
|
703
|
-
var
|
|
672
|
+
if (L.somethingOpened !== this) return;
|
|
673
|
+
t && ((n = this.rootElm) == null || n.classList.add("vistaview--closing"), await new Promise((a) => {
|
|
674
|
+
var l;
|
|
704
675
|
let o;
|
|
705
|
-
(
|
|
676
|
+
(l = this.rootElm) == null || l.addEventListener("transitionend", (c) => {
|
|
706
677
|
c.currentTarget === this.rootElm && (o && clearTimeout(o), o = setTimeout(() => {
|
|
707
|
-
|
|
678
|
+
a();
|
|
708
679
|
}, 333));
|
|
709
680
|
});
|
|
710
681
|
}));
|
|
@@ -712,18 +683,13 @@ class ot {
|
|
|
712
683
|
htmlElements: { from: this.currentItems, to: null },
|
|
713
684
|
images: { from: this.currentImages, to: null },
|
|
714
685
|
index: { from: this.currentIndex.value, to: null },
|
|
715
|
-
container: this.imageContainerElm,
|
|
716
|
-
elements: this.elements,
|
|
717
686
|
via: { prev: !1, next: !1 },
|
|
718
|
-
|
|
719
|
-
navActive: this.navActive,
|
|
720
|
-
isZoomed: this.isZoomed,
|
|
721
|
-
options: this.options
|
|
687
|
+
vistaView: this
|
|
722
688
|
};
|
|
723
|
-
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.
|
|
724
|
-
for (const
|
|
725
|
-
this.transitionAbortControllers[
|
|
726
|
-
this.transitionAbortControllers = {},
|
|
689
|
+
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.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);
|
|
690
|
+
for (const a in this.transitionAbortControllers)
|
|
691
|
+
this.transitionAbortControllers[a].abort();
|
|
692
|
+
this.transitionAbortControllers = {}, L.somethingOpened = null;
|
|
727
693
|
}
|
|
728
694
|
destroy() {
|
|
729
695
|
this.close(!1), this.elements instanceof NodeList && this.elements.forEach((t) => {
|
|
@@ -731,16 +697,16 @@ class ot {
|
|
|
731
697
|
});
|
|
732
698
|
}
|
|
733
699
|
view(t, i) {
|
|
734
|
-
|
|
700
|
+
L.somethingOpened === this && (t < 0 && (t = this.elements.length - 1), t >= this.elements.length && (t = 0), this.currentIndex.via = i || { next: !1, prev: !1 }, this.currentIndex.value = t);
|
|
735
701
|
}
|
|
736
702
|
next() {
|
|
737
|
-
|
|
703
|
+
L.somethingOpened === this && this.view(this.currentIndex.value + 1, { next: !0, prev: !1 });
|
|
738
704
|
}
|
|
739
705
|
prev() {
|
|
740
|
-
|
|
706
|
+
L.somethingOpened === this && this.view(this.currentIndex.value - 1, { next: !1, prev: !0 });
|
|
741
707
|
}
|
|
742
708
|
getCurrentIndex() {
|
|
743
|
-
return
|
|
709
|
+
return L.somethingOpened === this ? this.currentIndex.value : -1;
|
|
744
710
|
}
|
|
745
711
|
}
|
|
746
712
|
function rt(s) {
|