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