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