vistaview 0.2.1 → 0.3.2
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 +89 -39
- package/dist/lib/components.d.ts +7 -3
- package/dist/lib/components.d.ts.map +1 -1
- package/dist/lib/defaults.d.ts +9 -0
- package/dist/lib/defaults.d.ts.map +1 -0
- package/dist/lib/types.d.ts +83 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +4 -5
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/vista-view.d.ts +57 -66
- package/dist/lib/vista-view.d.ts.map +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +6 -7
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +55 -30
- package/dist/solid.cjs +1 -1
- package/dist/solid.d.ts +11 -5
- package/dist/solid.d.ts.map +1 -1
- package/dist/solid.js +37 -21
- package/dist/svelte.cjs +1 -1
- package/dist/svelte.d.ts +3 -5
- package/dist/svelte.d.ts.map +1 -1
- package/dist/svelte.js +17 -21
- package/dist/vistaview.cjs +16 -1
- package/dist/vistaview.css +1 -2
- package/dist/vistaview.d.ts +11 -9
- package/dist/vistaview.d.ts.map +1 -1
- package/dist/vistaview.js +680 -2
- package/dist/vistaview.umd.js +16 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +19 -6
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +48 -21
- package/package.json +3 -9
- package/dist/types.d.ts +0 -2
- package/dist/types.d.ts.map +0 -1
- package/dist/vistaview-Btvas1MP.js +0 -458
- package/dist/vistaview-Xzefo28o.cjs +0 -14
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
var chevronLeft = "<svg viewBox=\"0 0 24 24\"><path d=\"m15 18-6-6 6-6\"/></svg>", chevronRight = "<svg viewBox=\"0 0 24 24\"><path d=\"m9 18 6-6-6-6\"/></svg>", zoomInIcon = "<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>", zoomOutIcon = "<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>", downloadIcon = "<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>", closeIcon = "<svg viewBox=\"0 0 24 24\"><path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/></svg>";
|
|
2
|
-
function getDownloadButton() {
|
|
3
|
-
return {
|
|
4
|
-
name: "download",
|
|
5
|
-
icon: downloadIcon,
|
|
6
|
-
onClick: (e) => {
|
|
7
|
-
let c = document.createElement("a");
|
|
8
|
-
c.href = e.src, c.download = e.src.split("/").pop() || "download", document.body.appendChild(c), c.click(), document.body.removeChild(c);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function convertControlToHtml(e) {
|
|
13
|
-
if (typeof e == "string") switch (e) {
|
|
14
|
-
case "zoomIn": return `<button class="vistaview-zoom-in-button">${zoomInIcon}</button>`;
|
|
15
|
-
case "zoomOut": return `<button disabled class="vistaview-zoom-out-button">${zoomOutIcon}</button>`;
|
|
16
|
-
case "close": return `<button class="vistaview-close-button">${closeIcon}</button>`;
|
|
17
|
-
case "indexDisplay": return "<div class=\"vistaview-index-display\"></div>";
|
|
18
|
-
case "description": return "<div class=\"vistaview-image-description\"></div>";
|
|
19
|
-
default: return "";
|
|
20
|
-
}
|
|
21
|
-
return `<button data-vistaview-custom-control="${e.name}">${e.icon}</button>`;
|
|
22
|
-
}
|
|
23
|
-
function vistaViewComponent(l, u) {
|
|
24
|
-
let d = (e) => e ? e.map(convertControlToHtml).join("") : "";
|
|
25
|
-
return `<div class="vistaview-root" id="vistaview-root">
|
|
26
|
-
<div class="vistaview-container">
|
|
27
|
-
<div class="vistaview-image-container">
|
|
28
|
-
${l.map((e) => {
|
|
29
|
-
let c = e.image ? getComputedStyle(e.image).objectFit : "", l = e.image?.width, u = e.image?.height;
|
|
30
|
-
return `<div class="vistaview-item">
|
|
31
|
-
<img class="vistaview-image-lowres"${c ? ` style="object-fit:${c}"` : ""} src="${e.smallSrc || e.src}" alt="${e.alt || ""}" width="${l}" height="${u}">
|
|
32
|
-
<img class="vistaview-image-highres" loading="lazy" style="width:${l}px;height:${u}px" src="${e.src}" alt="${e.alt || ""}" width="${e.width}" height="${e.height}">
|
|
33
|
-
</div>`;
|
|
34
|
-
}).join("")}
|
|
35
|
-
</div>
|
|
36
|
-
<div class="vistaview-top-bar vistaview-ui"><div>${d(u?.topLeft)}</div><div>${d(u?.topCenter)}</div><div>${d(u?.topRight)}</div></div>
|
|
37
|
-
<div class="vistaview-bottom-bar vistaview-ui"><div>${d(u?.bottomLeft)}</div><div>${d(u?.bottomCenter)}</div><div>${d(u?.bottomRight)}</div></div>
|
|
38
|
-
<div class="vistaview-prev-btn vistaview-ui"><button>${chevronLeft}</button></div>
|
|
39
|
-
<div class="vistaview-next-btn vistaview-ui"><button>${chevronRight}</button></div>
|
|
40
|
-
</div>
|
|
41
|
-
</div>`;
|
|
42
|
-
}
|
|
43
|
-
function getElmProperties(e) {
|
|
44
|
-
let c = getComputedStyle(e);
|
|
45
|
-
return {
|
|
46
|
-
objectFit: c.objectFit,
|
|
47
|
-
borderRadius: c.borderRadius,
|
|
48
|
-
objectPosition: c.objectPosition,
|
|
49
|
-
overflow: c.overflow
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
var cachedPolicy = null;
|
|
53
|
-
function getPolicy() {
|
|
54
|
-
return cachedPolicy || (window.trustedTypes || (window.trustedTypes = { createPolicy: (e, c) => c }), cachedPolicy = window.trustedTypes.createPolicy("vistaView-policy", {
|
|
55
|
-
createHTML: (e) => e,
|
|
56
|
-
createScript: () => {
|
|
57
|
-
throw Error("Not implemented");
|
|
58
|
-
},
|
|
59
|
-
createScriptURL: () => {
|
|
60
|
-
throw Error("Not implemented");
|
|
61
|
-
}
|
|
62
|
-
}), cachedPolicy);
|
|
63
|
-
}
|
|
64
|
-
function createTrustedHtml(e) {
|
|
65
|
-
let c = getPolicy().createHTML(e), l = document.createElement("template");
|
|
66
|
-
l.innerHTML = c;
|
|
67
|
-
let u = l.content;
|
|
68
|
-
return l.remove(), u;
|
|
69
|
-
}
|
|
70
|
-
function isNotZeroCssValue(e) {
|
|
71
|
-
return e && !/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(e.trim()) && e;
|
|
72
|
-
}
|
|
73
|
-
function getFittedSize(e) {
|
|
74
|
-
let c = window.getComputedStyle(e).objectFit || "", { width: l, height: u } = e.getBoundingClientRect(), d = e.naturalWidth, f = e.naturalHeight;
|
|
75
|
-
if (!c || !d || !f) return {
|
|
76
|
-
width: l,
|
|
77
|
-
height: u
|
|
78
|
-
};
|
|
79
|
-
let p = d / f, m = l / u;
|
|
80
|
-
switch (c) {
|
|
81
|
-
case "fill": return {
|
|
82
|
-
width: l,
|
|
83
|
-
height: u
|
|
84
|
-
};
|
|
85
|
-
case "none": return {
|
|
86
|
-
width: d,
|
|
87
|
-
height: f
|
|
88
|
-
};
|
|
89
|
-
case "contain": return p > m ? {
|
|
90
|
-
width: l,
|
|
91
|
-
height: l / p
|
|
92
|
-
} : {
|
|
93
|
-
width: u * p,
|
|
94
|
-
height: u
|
|
95
|
-
};
|
|
96
|
-
case "cover": return p < m ? {
|
|
97
|
-
width: l,
|
|
98
|
-
height: l / p
|
|
99
|
-
} : {
|
|
100
|
-
width: u * p,
|
|
101
|
-
height: u
|
|
102
|
-
};
|
|
103
|
-
case "scale-down": {
|
|
104
|
-
let e = {
|
|
105
|
-
width: d,
|
|
106
|
-
height: f
|
|
107
|
-
}, c = p > m ? {
|
|
108
|
-
width: l,
|
|
109
|
-
height: l / p
|
|
110
|
-
} : {
|
|
111
|
-
width: u * p,
|
|
112
|
-
height: u
|
|
113
|
-
};
|
|
114
|
-
return c.width <= e.width && c.height <= e.height ? c : e;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
width: l,
|
|
119
|
-
height: u
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
function makeFullScreenContain(e, c = !1) {
|
|
123
|
-
let l = window.innerWidth, u = window.innerHeight, d = e.naturalWidth, f = e.naturalHeight;
|
|
124
|
-
if (!d || !f) return;
|
|
125
|
-
if (d < l && f < u) {
|
|
126
|
-
e.style.width = d + "px", e.style.height = f + "px";
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
let p = d / f, m = l / u, h, g;
|
|
130
|
-
p > m ? (h = l, g = l / p) : (g = u, h = u * p), c ? (e.dataset.vistaviewInitialWidth = h.toString(), e.dataset.vistaviewInitialHeight = g.toString()) : (e.style.width = h + "px", e.style.height = g + "px");
|
|
131
|
-
}
|
|
132
|
-
function getMaxMinZoomLevels(e, c) {
|
|
133
|
-
let l = window.innerHeight, u = window.innerWidth, d = e, f = c, p = Math.max(0, (d - u) / 2) + u / 2, m = Math.max(0, (f - l) / 2) + l / 2, h = -p;
|
|
134
|
-
return {
|
|
135
|
-
maxDiffX: p,
|
|
136
|
-
minDiffY: -m,
|
|
137
|
-
maxDiffY: m,
|
|
138
|
-
minDiffX: h
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
var GlobalVistaState = { somethingOpened: !1 };
|
|
142
|
-
const DefaultOptions = {
|
|
143
|
-
detectReducedMotion: !0,
|
|
144
|
-
zoomStep: 500,
|
|
145
|
-
maxZoomLevel: 2,
|
|
146
|
-
touchSpeedThreshold: 1,
|
|
147
|
-
controls: {
|
|
148
|
-
topLeft: ["indexDisplay"],
|
|
149
|
-
topRight: [
|
|
150
|
-
"zoomIn",
|
|
151
|
-
"zoomOut",
|
|
152
|
-
getDownloadButton(),
|
|
153
|
-
"close"
|
|
154
|
-
],
|
|
155
|
-
bottomCenter: ["description"]
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
var VistaView = class {
|
|
159
|
-
options;
|
|
160
|
-
elements;
|
|
161
|
-
currentIndex = 0;
|
|
162
|
-
currentDescription = "";
|
|
163
|
-
rootElement = null;
|
|
164
|
-
containerElement = null;
|
|
165
|
-
indexDisplayElement = null;
|
|
166
|
-
descriptionElement = null;
|
|
167
|
-
isActive = !1;
|
|
168
|
-
isZoomed = !1;
|
|
169
|
-
isReducedMotion;
|
|
170
|
-
setInitialProperties = null;
|
|
171
|
-
setFullScreenContain = null;
|
|
172
|
-
onZoomedPointerDown = null;
|
|
173
|
-
onZoomedPointerMove = null;
|
|
174
|
-
onZoomedPointerUp = null;
|
|
175
|
-
onPointerDown = null;
|
|
176
|
-
onPointerMove = null;
|
|
177
|
-
onPointerUp = null;
|
|
178
|
-
onKeyDown = null;
|
|
179
|
-
constructor(e, c) {
|
|
180
|
-
this.elements = e, this.options = {
|
|
181
|
-
...DefaultOptions,
|
|
182
|
-
...c || {},
|
|
183
|
-
controls: {
|
|
184
|
-
...DefaultOptions.controls,
|
|
185
|
-
...c?.controls || {}
|
|
186
|
-
}
|
|
187
|
-
}, this.isReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches, this.elements.forEach((e, c) => {
|
|
188
|
-
let l = e.anchor || e.image;
|
|
189
|
-
l && (e.onClick = (e) => {
|
|
190
|
-
e.preventDefault(), this.open(c);
|
|
191
|
-
}, l.addEventListener("click", e.onClick));
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
setZoomed(e) {
|
|
195
|
-
if (this.isZoomed === e) return;
|
|
196
|
-
let c = this.isZoomed === !1 ? null : this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.isZoomed];
|
|
197
|
-
if (this.isZoomed = e, this.isZoomed === !1 && c) {
|
|
198
|
-
this.onZoomedPointerDown &&= (c.parentElement?.removeEventListener("pointerdown", this.onZoomedPointerDown), null), this.onZoomedPointerMove &&= (c.parentElement?.removeEventListener("pointermove", this.onZoomedPointerMove), null), this.onZoomedPointerUp &&= (c.parentElement?.removeEventListener("pointerup", this.onZoomedPointerUp), null), c?.style.removeProperty("--pointer-diff-x"), c?.style.removeProperty("--pointer-diff-y"), setTimeout(() => {
|
|
199
|
-
c?.classList.remove("vistaview-image--zooming");
|
|
200
|
-
}, 500);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (this.isZoomed !== !1) {
|
|
204
|
-
c = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.isZoomed], c.classList.add("vistaview-image--zooming"), c?.style.setProperty("--pointer-diff-x", "0px"), c?.style.setProperty("--pointer-diff-y", "0px");
|
|
205
|
-
let e = !1, l = 0, u = 0, d = 0, f = 0, p = 0, m = 0;
|
|
206
|
-
this.onZoomedPointerDown &&= (c.parentElement?.removeEventListener("pointerdown", this.onZoomedPointerDown), null), this.onZoomedPointerMove &&= (c.parentElement?.removeEventListener("pointermove", this.onZoomedPointerMove), null), this.onZoomedPointerUp &&= (c.parentElement?.removeEventListener("pointerup", this.onZoomedPointerUp), null), this.onZoomedPointerDown = (d) => {
|
|
207
|
-
d.preventDefault(), d.stopPropagation(), e = !0, l = d.pageX, u = d.pageY, c.setPointerCapture(d.pointerId);
|
|
208
|
-
}, this.onZoomedPointerMove = (h) => {
|
|
209
|
-
if (!e) return;
|
|
210
|
-
h.preventDefault(), p = h.pageX - l, m = h.pageY - u;
|
|
211
|
-
let { maxDiffX: g, minDiffY: _, maxDiffY: v, minDiffX: y } = getMaxMinZoomLevels(parseInt(c?.dataset.vistaviewCurrentWidth || "0"), parseInt(c?.dataset.vistaviewCurrentHeight || "0")), b = Math.min(g, Math.max(y, d + p)), x = Math.min(v, Math.max(_, f + m));
|
|
212
|
-
p = b - d, m = x - f, c?.style.setProperty("--pointer-diff-x", `${b}px`), c?.style.setProperty("--pointer-diff-y", `${x}px`);
|
|
213
|
-
}, this.onZoomedPointerUp = (l) => {
|
|
214
|
-
e = !1, c.releasePointerCapture(l.pointerId), d += p, f += m, p = 0, m = 0;
|
|
215
|
-
}, c?.parentElement?.addEventListener("pointerdown", this.onZoomedPointerDown), c?.parentElement?.addEventListener("pointermove", this.onZoomedPointerMove), c?.parentElement?.addEventListener("pointerup", this.onZoomedPointerUp);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
setIndexDisplay() {
|
|
219
|
-
this.indexDisplayElement && (this.indexDisplayElement.textContent = `${this.currentIndex + 1} / ${this.elements.length}`);
|
|
220
|
-
}
|
|
221
|
-
setCurrentDescription() {
|
|
222
|
-
this.descriptionElement && (this.currentDescription = this.elements[this.currentIndex].alt || "", this.descriptionElement && (this.descriptionElement.textContent = this.currentDescription));
|
|
223
|
-
}
|
|
224
|
-
getAnimationDurationBase() {
|
|
225
|
-
let e = window.getComputedStyle(this.rootElement);
|
|
226
|
-
return parseInt(e.getPropertyValue("--vistaview-animation-duration"));
|
|
227
|
-
}
|
|
228
|
-
updateZoomButtonsVisibility() {
|
|
229
|
-
let e = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.currentIndex];
|
|
230
|
-
if (!e) return;
|
|
231
|
-
let c = this.containerElement?.querySelector("button.vistaview-zoom-in-button"), l = this.containerElement?.querySelector("button.vistaview-zoom-out-button"), u = e.width, d = (e.naturalWidth || 0) * this.options.maxZoomLevel, f = u < d && d > 0;
|
|
232
|
-
c && (c.style.display = f ? "" : "none"), l && (l.style.display = f ? "" : "none");
|
|
233
|
-
}
|
|
234
|
-
zoomIn() {
|
|
235
|
-
let e = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.currentIndex], c = e.width, l = e.height;
|
|
236
|
-
e.dataset.vistaviewInitialWidth || (e.dataset.vistaviewInitialWidth = c.toString()), e.dataset.vistaviewInitialHeight || (e.dataset.vistaviewInitialHeight = l.toString()), this.setZoomed(this.currentIndex);
|
|
237
|
-
let u = (e.naturalWidth || 0) * this.options.maxZoomLevel;
|
|
238
|
-
if (c && u && c < u) {
|
|
239
|
-
let d = Math.min(c + this.options.zoomStep, u);
|
|
240
|
-
e.style.width = `${d}px`;
|
|
241
|
-
let f = d / c * l;
|
|
242
|
-
e.style.height = `${f}px`, this.containerElement?.querySelector("button.vistaview-zoom-out-button")?.removeAttribute("disabled"), e.dataset.vistaviewCurrentWidth = d.toString(), e.dataset.vistaviewCurrentHeight = f.toString(), d === u && this.containerElement?.querySelector("button.vistaview-zoom-in-button")?.setAttribute("disabled", "true");
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
zoomOut() {
|
|
246
|
-
let e = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.currentIndex], c = e.width, l = e.height, u = e.dataset.vistaviewInitialWidth ? parseInt(e.dataset.vistaviewInitialWidth) : 0;
|
|
247
|
-
if (e.classList.add("vistaview-image--zooming-out"), setTimeout(() => {
|
|
248
|
-
e.classList.remove("vistaview-image--zooming-out");
|
|
249
|
-
}, 333), c && u && c > u) {
|
|
250
|
-
let d = Math.max(c - this.options.zoomStep, u);
|
|
251
|
-
e.style.width = `${d}px`;
|
|
252
|
-
let f = d / c * l;
|
|
253
|
-
e.style.height = `${f}px`, this.containerElement?.querySelector("button.vistaview-zoom-in-button")?.removeAttribute("disabled"), e.dataset.vistaviewCurrentWidth = d.toString(), e.dataset.vistaviewCurrentHeight = f.toString();
|
|
254
|
-
let { maxDiffX: p, minDiffY: m, maxDiffY: h, minDiffX: g } = getMaxMinZoomLevels(d, f), _ = parseInt(e?.style.getPropertyValue("--pointer-diff-x").replace("px", "") || "0"), v = parseInt(e?.style.getPropertyValue("--pointer-diff-y").replace("px", "") || "0");
|
|
255
|
-
_ = Math.min(p, Math.max(g, _)), v = Math.min(h, Math.max(m, v)), e?.style.setProperty("--pointer-diff-x", `${_}px`), e?.style.setProperty("--pointer-diff-y", `${v}px`), d === u && (this.containerElement?.querySelector("button.vistaview-zoom-out-button")?.setAttribute("disabled", "true"), e.removeAttribute("data-vistaview-current-width"), e.removeAttribute("data-vistaview-current-height"), e.removeAttribute("data-vistaview-initial-width"), e.removeAttribute("data-vistaview-initial-height"), this.setZoomed(!1));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
clearZoom() {
|
|
259
|
-
let e = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.currentIndex];
|
|
260
|
-
e.dataset.vistaviewInitialWidth && (e.style.width = `${e.dataset.vistaviewInitialWidth}px`), e.dataset.vistaviewInitialHeight && (e.style.height = `${e.dataset.vistaviewInitialHeight}px`), this.containerElement?.querySelector("button.vistaview-zoom-in-button")?.removeAttribute("disabled"), this.containerElement?.querySelector("button.vistaview-zoom-out-button")?.setAttribute("disabled", "true"), e.removeAttribute("data-vistaview-current-width"), e.removeAttribute("data-vistaview-current-height"), e.removeAttribute("data-vistaview-initial-width"), e.removeAttribute("data-vistaview-initial-height"), this.setZoomed(!1);
|
|
261
|
-
}
|
|
262
|
-
resetImageOpacity(e = !1) {
|
|
263
|
-
this.elements.forEach((c, l) => {
|
|
264
|
-
c.image && (c.image?.dataset.vistaviewInitialOpacity || (c.image.dataset.vistaviewInitialOpacity = c.image.style.opacity || "1"), l === this.currentIndex && !e ? c.image.style.opacity = "0" : c.image.style.opacity = c.image.dataset.vistaviewInitialOpacity);
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
setTouchActions() {
|
|
268
|
-
this.removeTouchActions();
|
|
269
|
-
let e = this.containerElement?.querySelector(".vistaview-image-container");
|
|
270
|
-
if (!e) return;
|
|
271
|
-
let c = 0, l = 0, u = 0, d = 0, f = !1, p = this.currentIndex, m;
|
|
272
|
-
this.onPointerDown = (h) => {
|
|
273
|
-
if (h.preventDefault(), h.stopPropagation(), this.isZoomed !== !1) return;
|
|
274
|
-
p = this.currentIndex, f = !0, c = h.pageX, l = h.pageY, u = h.pageX, d = Date.now(), e.classList.add("vistaview-image-container--pointer-down");
|
|
275
|
-
let g = this.containerElement?.querySelector(".vistaview-image-container"), _ = Array.from(g.querySelectorAll(".vistaview-item"));
|
|
276
|
-
m = new IntersectionObserver((e) => {
|
|
277
|
-
e.forEach((e) => {
|
|
278
|
-
e.isIntersecting && (p = _.indexOf(e.target));
|
|
279
|
-
});
|
|
280
|
-
}, {
|
|
281
|
-
threshold: .5,
|
|
282
|
-
root: this.containerElement
|
|
283
|
-
}), _.forEach((e) => {
|
|
284
|
-
m.observe(e);
|
|
285
|
-
});
|
|
286
|
-
}, this.onPointerMove = (d) => {
|
|
287
|
-
if (d.preventDefault(), d.stopPropagation(), this.isZoomed !== !1 || !f) return;
|
|
288
|
-
let p = d.pageX - c, m = d.pageY - l;
|
|
289
|
-
u = d.pageX, e.style.setProperty("--vistaview-pointer-diff-x", `${p}px`), e.style.setProperty("--vistaview-pointer-diff-y", `${m}px`);
|
|
290
|
-
}, this.onPointerUp = (l) => {
|
|
291
|
-
if (l.preventDefault(), l.stopPropagation(), this.isZoomed !== !1 || !f) return;
|
|
292
|
-
f = !1, m.disconnect();
|
|
293
|
-
let h = (u - c) / (Date.now() - d), g = this.options.touchSpeedThreshold || 1;
|
|
294
|
-
h < -g && p === this.currentIndex ? p = Math.min(this.currentIndex + 1, this.elements.length - 1) : h > g && p === this.currentIndex && (p = Math.max(this.currentIndex - 1, 0)), e.style.setProperty("--vistaview-pointer-diff-x", "0px"), e.style.setProperty("--vistaview-pointer-diff-y", "0px"), e.classList.remove("vistaview-image-container--pointer-down"), p !== this.currentIndex && this.view(p);
|
|
295
|
-
}, e.addEventListener("pointermove", this.onPointerMove), e.addEventListener("pointerup", this.onPointerUp), e.addEventListener("pointerdown", this.onPointerDown);
|
|
296
|
-
}
|
|
297
|
-
removeTouchActions() {
|
|
298
|
-
let e = this.containerElement?.querySelector(".vistaview-image-container");
|
|
299
|
-
e && (this.onPointerMove && e.removeEventListener("pointermove", this.onPointerMove), this.onPointerUp && e.removeEventListener("pointerup", this.onPointerUp), this.onPointerDown && e.removeEventListener("pointerdown", this.onPointerDown));
|
|
300
|
-
}
|
|
301
|
-
open(e) {
|
|
302
|
-
if (GlobalVistaState.somethingOpened) return;
|
|
303
|
-
if (GlobalVistaState.somethingOpened = !0, this.isActive = !0, e ||= 0, e < 0 || e >= this.elements.length) throw Error("VistaView: Index out of bounds:" + e);
|
|
304
|
-
this.currentIndex = e;
|
|
305
|
-
let c = vistaViewComponent(this.elements, this.options.controls);
|
|
306
|
-
if (document.body.prepend(createTrustedHtml(c)), this.rootElement = document.querySelector("#vistaview-root"), !this.rootElement) throw Error("VistaView: Failed to create root element.");
|
|
307
|
-
if (this.options.detectReducedMotion && this.isReducedMotion && this.rootElement.classList.add("vistaview--reduced-motion"), this.containerElement = this.rootElement.querySelector(".vistaview-container"), !this.containerElement) throw Error("VistaView: Failed to create container element.");
|
|
308
|
-
this.indexDisplayElement = this.containerElement.querySelector(".vistaview-index-display"), this.descriptionElement = this.containerElement.querySelector(".vistaview-image-description"), this.options.animationDurationBase && this.rootElement.style.setProperty("--vistaview-animation-duration", `${this.options.animationDurationBase}`), this.options.initialZIndex !== void 0 && this.rootElement.style.setProperty("--vistaview-initial-z-index", `${this.options.initialZIndex}`);
|
|
309
|
-
let l = this.elements[e].image ? getElmProperties(this.elements[e].image) : void 0, u = this.elements[e].anchor ? getElmProperties(this.elements[e].anchor) : void 0, d = this.elements[e].anchor ? this.elements[e].anchor : this.elements[e].image;
|
|
310
|
-
if (d) {
|
|
311
|
-
let e = d.getBoundingClientRect();
|
|
312
|
-
this.rootElement.style.setProperty("--vistaview-container-initial-width", `${e?.width}px`), this.rootElement.style.setProperty("--vistaview-container-initial-height", `${e?.height}px`), this.rootElement.style.setProperty("--vistaview-container-initial-top", `${e.top + e.height / 2}px`), this.rootElement.style.setProperty("--vistaview-container-initial-left", `${e.left + e.width / 2}px`);
|
|
313
|
-
}
|
|
314
|
-
this.rootElement.style.setProperty("--vistaview-number-elements", `${this.elements.length}`), this.rootElement.style.setProperty("--vistaview-image-border-radius", isNotZeroCssValue(l?.borderRadius) || isNotZeroCssValue(u?.borderRadius) || "0px"), this.setInitialProperties = () => {
|
|
315
|
-
if (!this.isActive) return;
|
|
316
|
-
let e = this.elements[this.currentIndex].anchor ? this.elements[this.currentIndex].anchor : this.elements[this.currentIndex].image;
|
|
317
|
-
if (!e) return;
|
|
318
|
-
let c = e.getBoundingClientRect();
|
|
319
|
-
this.rootElement?.style.setProperty("--vistaview-container-initial-width", `${c?.width}px`), this.rootElement?.style.setProperty("--vistaview-container-initial-height", `${c?.height}px`), this.rootElement?.style.setProperty("--vistaview-container-initial-top", `${c.top + c.height / 2}px`), this.rootElement?.style.setProperty("--vistaview-container-initial-left", `${c.left + c.width / 2}px`);
|
|
320
|
-
}, window.addEventListener("resize", this.setInitialProperties);
|
|
321
|
-
let f = [
|
|
322
|
-
...this.options.controls.topLeft || [],
|
|
323
|
-
...this.options.controls.topCenter || [],
|
|
324
|
-
...this.options.controls.topRight || [],
|
|
325
|
-
...this.options.controls.bottomLeft || [],
|
|
326
|
-
...this.options.controls.bottomCenter || [],
|
|
327
|
-
...this.options.controls.bottomRight || []
|
|
328
|
-
].filter((e) => typeof e != "string");
|
|
329
|
-
this.containerElement.querySelectorAll("button").forEach((e) => {
|
|
330
|
-
let c = e.getAttribute("data-vistaview-custom-control");
|
|
331
|
-
if (c) {
|
|
332
|
-
let l = f.find((e) => e.name === c);
|
|
333
|
-
l && e.addEventListener("click", () => {
|
|
334
|
-
l.onClick(this.elements[this.currentIndex]);
|
|
335
|
-
});
|
|
336
|
-
} else e.classList.contains("vistaview-zoom-in-button") ? e.addEventListener("click", () => {
|
|
337
|
-
this.zoomIn();
|
|
338
|
-
}) : e.classList.contains("vistaview-zoom-out-button") ? e.addEventListener("click", () => {
|
|
339
|
-
this.zoomOut();
|
|
340
|
-
}) : e.classList.contains("vistaview-close-button") ? e.addEventListener("click", () => {
|
|
341
|
-
this.close();
|
|
342
|
-
}) : e.parentElement?.classList.contains("vistaview-prev-btn") ? e.addEventListener("click", () => {
|
|
343
|
-
this.prev();
|
|
344
|
-
}) : e.parentElement?.classList.contains("vistaview-next-btn") && e.addEventListener("click", () => {
|
|
345
|
-
this.next();
|
|
346
|
-
});
|
|
347
|
-
}), this.setIndexDisplay(), this.setCurrentDescription(), this.rootElement?.style.setProperty("--vistaview-current-index", `${this.currentIndex}`), this.containerElement.querySelectorAll(".vistaview-image-highres").forEach((e, c) => {
|
|
348
|
-
let l = e, u = this.elements[c].image;
|
|
349
|
-
if (u) {
|
|
350
|
-
let { width: e, height: c } = getFittedSize(u), d = Math.min(u.width, e), f = Math.min(u.height, c);
|
|
351
|
-
l.style.width = `${d}px`, l.style.height = `${f}px`, l.style.setProperty("--vistaview-fitted-width", `${d}px`), l.style.setProperty("--vistaview-fitted-height", `${f}px`);
|
|
352
|
-
}
|
|
353
|
-
let d = () => {
|
|
354
|
-
l.classList.add("vistaview-image-loaded"), setTimeout(() => {
|
|
355
|
-
makeFullScreenContain(l);
|
|
356
|
-
}, 100), setTimeout(() => {
|
|
357
|
-
l.parentElement?.querySelector(".vistaview-image-lowres")?.classList.add("vistaview-image--hidden");
|
|
358
|
-
}, 500), c === this.currentIndex && this.updateZoomButtonsVisibility();
|
|
359
|
-
};
|
|
360
|
-
l.complete ? d() : l.onload = d;
|
|
361
|
-
}), this.setFullScreenContain = () => {
|
|
362
|
-
this.isActive && (this.containerElement?.querySelectorAll(".vistaview-image-highres"))?.forEach((e) => {
|
|
363
|
-
let c = e;
|
|
364
|
-
makeFullScreenContain(c, c.classList.contains("vistaview-image--zooming"));
|
|
365
|
-
});
|
|
366
|
-
}, window.addEventListener("resize", this.setFullScreenContain), this.setTouchActions(), this.onKeyDown = (e) => {
|
|
367
|
-
if (this.isActive) switch (e.key) {
|
|
368
|
-
case "ArrowLeft":
|
|
369
|
-
e.preventDefault(), this.prev();
|
|
370
|
-
break;
|
|
371
|
-
case "ArrowRight":
|
|
372
|
-
e.preventDefault(), this.next();
|
|
373
|
-
break;
|
|
374
|
-
case "ArrowUp":
|
|
375
|
-
e.preventDefault(), this.zoomIn();
|
|
376
|
-
break;
|
|
377
|
-
case "ArrowDown":
|
|
378
|
-
e.preventDefault(), this.zoomOut();
|
|
379
|
-
break;
|
|
380
|
-
case "Escape":
|
|
381
|
-
e.preventDefault(), this.close();
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
}, window.addEventListener("keydown", this.onKeyDown), setTimeout(() => {
|
|
385
|
-
this.rootElement && this.rootElement.classList.add("vistaview--initialized"), this.resetImageOpacity();
|
|
386
|
-
}, 33);
|
|
387
|
-
}
|
|
388
|
-
async close(e = !0) {
|
|
389
|
-
if (this.isActive) {
|
|
390
|
-
if (this.isActive = !1, e) {
|
|
391
|
-
let e = this.getAnimationDurationBase();
|
|
392
|
-
this.rootElement?.classList.add("vistaview--closing"), this.options.detectReducedMotion && this.isReducedMotion || await new Promise((c) => {
|
|
393
|
-
setTimeout(() => {
|
|
394
|
-
c(!0);
|
|
395
|
-
}, e * 1.5);
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
this.removeTouchActions(), this.rootElement?.remove(), this.rootElement = null, this.containerElement = null, this.resetImageOpacity(!0), this.setInitialProperties && window.removeEventListener("resize", this.setInitialProperties), this.setFullScreenContain && window.removeEventListener("resize", this.setFullScreenContain), this.onKeyDown && window.removeEventListener("keydown", this.onKeyDown), GlobalVistaState.somethingOpened = !1;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
destroy() {
|
|
402
|
-
this.isActive && (this.close(!1), this.elements.forEach((e) => {
|
|
403
|
-
let c = e.anchor || e.image;
|
|
404
|
-
c && e.onClick && c.removeEventListener("click", e.onClick);
|
|
405
|
-
}));
|
|
406
|
-
}
|
|
407
|
-
view(e) {
|
|
408
|
-
if (this.isActive) {
|
|
409
|
-
if (e < 0 || e >= this.elements.length) throw Error("VistaView: Index out of bounds:" + e);
|
|
410
|
-
this.clearZoom(), this.currentIndex = e, this.resetImageOpacity(), this.setIndexDisplay(), this.setCurrentDescription(), this.updateZoomButtonsVisibility(), this.setInitialProperties && this.setInitialProperties(), this.rootElement?.style.setProperty("--vistaview-current-index", `${this.currentIndex}`);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
next() {
|
|
414
|
-
this.isActive && this.view((this.currentIndex + 1) % this.elements.length);
|
|
415
|
-
}
|
|
416
|
-
prev() {
|
|
417
|
-
this.isActive && this.view((this.currentIndex - 1 + this.elements.length) % this.elements.length);
|
|
418
|
-
}
|
|
419
|
-
getCurrentIndex() {
|
|
420
|
-
return this.isActive ? this.currentIndex : -1;
|
|
421
|
-
}
|
|
422
|
-
}, toImage = (e) => {
|
|
423
|
-
let c = e instanceof HTMLImageElement ? e : e.querySelector("img");
|
|
424
|
-
return {
|
|
425
|
-
src: e.dataset.vistaviewSrc || e.getAttribute("href") || e.getAttribute("src") || "",
|
|
426
|
-
width: +(e.dataset.vistaviewWidth || c?.naturalWidth || 0),
|
|
427
|
-
height: +(e.dataset.vistaviewHeight || c?.naturalHeight || 0),
|
|
428
|
-
smallSrc: c?.src || e.dataset.vistaviewSmallsrc || e.getAttribute("src") || "",
|
|
429
|
-
alt: c?.alt || e.dataset.vistaviewAlt || e.getAttribute("alt") || "",
|
|
430
|
-
anchor: e instanceof HTMLAnchorElement ? e : void 0,
|
|
431
|
-
image: c || void 0
|
|
432
|
-
};
|
|
433
|
-
};
|
|
434
|
-
function vistaView({ parent: e, elements: c, ...l }) {
|
|
435
|
-
if (!e && !c) throw Error("No parent or elements");
|
|
436
|
-
let u;
|
|
437
|
-
if (e) {
|
|
438
|
-
let c = e.querySelector("img[data-vistaview-src]") ? "img[data-vistaview-src]" : "a[href]";
|
|
439
|
-
u = Array.from(e.querySelectorAll(c)).map(toImage);
|
|
440
|
-
} else if (typeof c == "string") u = Array.from(document.querySelectorAll(c)).map(toImage);
|
|
441
|
-
else if (c instanceof NodeList) u = Array.from(c).map(toImage);
|
|
442
|
-
else if (Array.isArray(c)) u = c;
|
|
443
|
-
else throw Error("Invalid elements");
|
|
444
|
-
if (!u.length) throw Error("No elements found");
|
|
445
|
-
let d = new VistaView(u, l);
|
|
446
|
-
return {
|
|
447
|
-
open: (e = 0) => d.open(e),
|
|
448
|
-
close: () => d.close(),
|
|
449
|
-
next: () => d.next(),
|
|
450
|
-
prev: () => d.prev(),
|
|
451
|
-
destroy: () => d.destroy(),
|
|
452
|
-
getCurrentIndex: () => d.getCurrentIndex(),
|
|
453
|
-
view: (e) => {
|
|
454
|
-
d.view(e);
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
export { DefaultOptions as n, getDownloadButton as r, vistaView as t };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var e=`<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>`,t=`<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>`,r=`<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="8" x2="14" y1="11" y2="11"/></svg>`,i=`<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>`,a=`<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`;function o(){return{name:`download`,icon:i,onClick:e=>{let t=document.createElement(`a`);t.href=e.src,t.download=e.src.split(`/`).pop()||`download`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}}}function s(e){if(typeof e==`string`)switch(e){case`zoomIn`:return`<button class="vistaview-zoom-in-button">${n}</button>`;case`zoomOut`:return`<button disabled class="vistaview-zoom-out-button">${r}</button>`;case`close`:return`<button class="vistaview-close-button">${a}</button>`;case`indexDisplay`:return`<div class="vistaview-index-display"></div>`;case`description`:return`<div class="vistaview-image-description"></div>`;default:return``}return`<button data-vistaview-custom-control="${e.name}">${e.icon}</button>`}function c(n,r){let i=e=>e?e.map(s).join(``):``;return`<div class="vistaview-root" id="vistaview-root">
|
|
2
|
-
<div class="vistaview-container">
|
|
3
|
-
<div class="vistaview-image-container">
|
|
4
|
-
${n.map(e=>{let t=e.image?getComputedStyle(e.image).objectFit:``,n=e.image?.width,r=e.image?.height;return`<div class="vistaview-item">
|
|
5
|
-
<img class="vistaview-image-lowres"${t?` style="object-fit:${t}"`:``} src="${e.smallSrc||e.src}" alt="${e.alt||``}" width="${n}" height="${r}">
|
|
6
|
-
<img class="vistaview-image-highres" loading="lazy" style="width:${n}px;height:${r}px" src="${e.src}" alt="${e.alt||``}" width="${e.width}" height="${e.height}">
|
|
7
|
-
</div>`}).join(``)}
|
|
8
|
-
</div>
|
|
9
|
-
<div class="vistaview-top-bar vistaview-ui"><div>${i(r?.topLeft)}</div><div>${i(r?.topCenter)}</div><div>${i(r?.topRight)}</div></div>
|
|
10
|
-
<div class="vistaview-bottom-bar vistaview-ui"><div>${i(r?.bottomLeft)}</div><div>${i(r?.bottomCenter)}</div><div>${i(r?.bottomRight)}</div></div>
|
|
11
|
-
<div class="vistaview-prev-btn vistaview-ui"><button>${e}</button></div>
|
|
12
|
-
<div class="vistaview-next-btn vistaview-ui"><button>${t}</button></div>
|
|
13
|
-
</div>
|
|
14
|
-
</div>`}function l(e){let t=getComputedStyle(e);return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow}}var u=null;function d(){return u||(window.trustedTypes||(window.trustedTypes={createPolicy:(e,t)=>t}),u=window.trustedTypes.createPolicy(`vistaView-policy`,{createHTML:e=>e,createScript:()=>{throw Error(`Not implemented`)},createScriptURL:()=>{throw Error(`Not implemented`)}}),u)}function f(e){let t=d().createHTML(e),n=document.createElement(`template`);n.innerHTML=t;let r=n.content;return n.remove(),r}function p(e){return e&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(e.trim())&&e}function m(e){let t=window.getComputedStyle(e).objectFit||``,{width:n,height:r}=e.getBoundingClientRect(),i=e.naturalWidth,a=e.naturalHeight;if(!t||!i||!a)return{width:n,height:r};let o=i/a,s=n/r;switch(t){case`fill`:return{width:n,height:r};case`none`:return{width:i,height:a};case`contain`:return o>s?{width:n,height:n/o}:{width:r*o,height:r};case`cover`:return o<s?{width:n,height:n/o}:{width:r*o,height:r};case`scale-down`:{let e={width:i,height:a},t=o>s?{width:n,height:n/o}:{width:r*o,height:r};return t.width<=e.width&&t.height<=e.height?t:e}}return{width:n,height:r}}function h(e,t=!1){let n=window.innerWidth,r=window.innerHeight,i=e.naturalWidth,a=e.naturalHeight;if(!i||!a)return;if(i<n&&a<r){e.style.width=i+`px`,e.style.height=a+`px`;return}let o=i/a,s=n/r,c,l;o>s?(c=n,l=n/o):(l=r,c=r*o),t?(e.dataset.vistaviewInitialWidth=c.toString(),e.dataset.vistaviewInitialHeight=l.toString()):(e.style.width=c+`px`,e.style.height=l+`px`)}function g(e,t){let n=window.innerHeight,r=window.innerWidth,i=e,a=t,o=Math.max(0,(i-r)/2)+r/2,s=Math.max(0,(a-n)/2)+n/2,c=-o;return{maxDiffX:o,minDiffY:-s,maxDiffY:s,minDiffX:c}}var _={somethingOpened:!1};const v={detectReducedMotion:!0,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:1,controls:{topLeft:[`indexDisplay`],topRight:[`zoomIn`,`zoomOut`,o(),`close`],bottomCenter:[`description`]}};var y=class{options;elements;currentIndex=0;currentDescription=``;rootElement=null;containerElement=null;indexDisplayElement=null;descriptionElement=null;isActive=!1;isZoomed=!1;isReducedMotion;setInitialProperties=null;setFullScreenContain=null;onZoomedPointerDown=null;onZoomedPointerMove=null;onZoomedPointerUp=null;onPointerDown=null;onPointerMove=null;onPointerUp=null;onKeyDown=null;constructor(e,t){this.elements=e,this.options={...v,...t||{},controls:{...v.controls,...t?.controls||{}}},this.isReducedMotion=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,this.elements.forEach((e,t)=>{let n=e.anchor||e.image;n&&(e.onClick=e=>{e.preventDefault(),this.open(t)},n.addEventListener(`click`,e.onClick))})}setZoomed(e){if(this.isZoomed===e)return;let t=this.isZoomed===!1?null:this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.isZoomed];if(this.isZoomed=e,this.isZoomed===!1&&t){this.onZoomedPointerDown&&=(t.parentElement?.removeEventListener(`pointerdown`,this.onZoomedPointerDown),null),this.onZoomedPointerMove&&=(t.parentElement?.removeEventListener(`pointermove`,this.onZoomedPointerMove),null),this.onZoomedPointerUp&&=(t.parentElement?.removeEventListener(`pointerup`,this.onZoomedPointerUp),null),t?.style.removeProperty(`--pointer-diff-x`),t?.style.removeProperty(`--pointer-diff-y`),setTimeout(()=>{t?.classList.remove(`vistaview-image--zooming`)},500);return}if(this.isZoomed!==!1){t=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.isZoomed],t.classList.add(`vistaview-image--zooming`),t?.style.setProperty(`--pointer-diff-x`,`0px`),t?.style.setProperty(`--pointer-diff-y`,`0px`);let e=!1,n=0,r=0,i=0,a=0,o=0,s=0;this.onZoomedPointerDown&&=(t.parentElement?.removeEventListener(`pointerdown`,this.onZoomedPointerDown),null),this.onZoomedPointerMove&&=(t.parentElement?.removeEventListener(`pointermove`,this.onZoomedPointerMove),null),this.onZoomedPointerUp&&=(t.parentElement?.removeEventListener(`pointerup`,this.onZoomedPointerUp),null),this.onZoomedPointerDown=i=>{i.preventDefault(),i.stopPropagation(),e=!0,n=i.pageX,r=i.pageY,t.setPointerCapture(i.pointerId)},this.onZoomedPointerMove=c=>{if(!e)return;c.preventDefault(),o=c.pageX-n,s=c.pageY-r;let{maxDiffX:l,minDiffY:u,maxDiffY:d,minDiffX:f}=g(parseInt(t?.dataset.vistaviewCurrentWidth||`0`),parseInt(t?.dataset.vistaviewCurrentHeight||`0`)),p=Math.min(l,Math.max(f,i+o)),m=Math.min(d,Math.max(u,a+s));o=p-i,s=m-a,t?.style.setProperty(`--pointer-diff-x`,`${p}px`),t?.style.setProperty(`--pointer-diff-y`,`${m}px`)},this.onZoomedPointerUp=n=>{e=!1,t.releasePointerCapture(n.pointerId),i+=o,a+=s,o=0,s=0},t?.parentElement?.addEventListener(`pointerdown`,this.onZoomedPointerDown),t?.parentElement?.addEventListener(`pointermove`,this.onZoomedPointerMove),t?.parentElement?.addEventListener(`pointerup`,this.onZoomedPointerUp)}}setIndexDisplay(){this.indexDisplayElement&&(this.indexDisplayElement.textContent=`${this.currentIndex+1} / ${this.elements.length}`)}setCurrentDescription(){this.descriptionElement&&(this.currentDescription=this.elements[this.currentIndex].alt||``,this.descriptionElement&&(this.descriptionElement.textContent=this.currentDescription))}getAnimationDurationBase(){let e=window.getComputedStyle(this.rootElement);return parseInt(e.getPropertyValue(`--vistaview-animation-duration`))}updateZoomButtonsVisibility(){let e=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.currentIndex];if(!e)return;let t=this.containerElement?.querySelector(`button.vistaview-zoom-in-button`),n=this.containerElement?.querySelector(`button.vistaview-zoom-out-button`),r=e.width,i=(e.naturalWidth||0)*this.options.maxZoomLevel,a=r<i&&i>0;t&&(t.style.display=a?``:`none`),n&&(n.style.display=a?``:`none`)}zoomIn(){let e=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.currentIndex],t=e.width,n=e.height;e.dataset.vistaviewInitialWidth||(e.dataset.vistaviewInitialWidth=t.toString()),e.dataset.vistaviewInitialHeight||(e.dataset.vistaviewInitialHeight=n.toString()),this.setZoomed(this.currentIndex);let r=(e.naturalWidth||0)*this.options.maxZoomLevel;if(t&&r&&t<r){let i=Math.min(t+this.options.zoomStep,r);e.style.width=`${i}px`;let a=i/t*n;e.style.height=`${a}px`,this.containerElement?.querySelector(`button.vistaview-zoom-out-button`)?.removeAttribute(`disabled`),e.dataset.vistaviewCurrentWidth=i.toString(),e.dataset.vistaviewCurrentHeight=a.toString(),i===r&&this.containerElement?.querySelector(`button.vistaview-zoom-in-button`)?.setAttribute(`disabled`,`true`)}}zoomOut(){let e=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.currentIndex],t=e.width,n=e.height,r=e.dataset.vistaviewInitialWidth?parseInt(e.dataset.vistaviewInitialWidth):0;if(e.classList.add(`vistaview-image--zooming-out`),setTimeout(()=>{e.classList.remove(`vistaview-image--zooming-out`)},333),t&&r&&t>r){let i=Math.max(t-this.options.zoomStep,r);e.style.width=`${i}px`;let a=i/t*n;e.style.height=`${a}px`,this.containerElement?.querySelector(`button.vistaview-zoom-in-button`)?.removeAttribute(`disabled`),e.dataset.vistaviewCurrentWidth=i.toString(),e.dataset.vistaviewCurrentHeight=a.toString();let{maxDiffX:o,minDiffY:s,maxDiffY:c,minDiffX:l}=g(i,a),u=parseInt(e?.style.getPropertyValue(`--pointer-diff-x`).replace(`px`,``)||`0`),d=parseInt(e?.style.getPropertyValue(`--pointer-diff-y`).replace(`px`,``)||`0`);u=Math.min(o,Math.max(l,u)),d=Math.min(c,Math.max(s,d)),e?.style.setProperty(`--pointer-diff-x`,`${u}px`),e?.style.setProperty(`--pointer-diff-y`,`${d}px`),i===r&&(this.containerElement?.querySelector(`button.vistaview-zoom-out-button`)?.setAttribute(`disabled`,`true`),e.removeAttribute(`data-vistaview-current-width`),e.removeAttribute(`data-vistaview-current-height`),e.removeAttribute(`data-vistaview-initial-width`),e.removeAttribute(`data-vistaview-initial-height`),this.setZoomed(!1))}}clearZoom(){let e=this.containerElement?.querySelectorAll(`.vistaview-image-highres`)[this.currentIndex];e.dataset.vistaviewInitialWidth&&(e.style.width=`${e.dataset.vistaviewInitialWidth}px`),e.dataset.vistaviewInitialHeight&&(e.style.height=`${e.dataset.vistaviewInitialHeight}px`),this.containerElement?.querySelector(`button.vistaview-zoom-in-button`)?.removeAttribute(`disabled`),this.containerElement?.querySelector(`button.vistaview-zoom-out-button`)?.setAttribute(`disabled`,`true`),e.removeAttribute(`data-vistaview-current-width`),e.removeAttribute(`data-vistaview-current-height`),e.removeAttribute(`data-vistaview-initial-width`),e.removeAttribute(`data-vistaview-initial-height`),this.setZoomed(!1)}resetImageOpacity(e=!1){this.elements.forEach((t,n)=>{t.image&&(t.image?.dataset.vistaviewInitialOpacity||(t.image.dataset.vistaviewInitialOpacity=t.image.style.opacity||`1`),n===this.currentIndex&&!e?t.image.style.opacity=`0`:t.image.style.opacity=t.image.dataset.vistaviewInitialOpacity)})}setTouchActions(){this.removeTouchActions();let e=this.containerElement?.querySelector(`.vistaview-image-container`);if(!e)return;let t=0,n=0,r=0,i=0,a=!1,o=this.currentIndex,s;this.onPointerDown=c=>{if(c.preventDefault(),c.stopPropagation(),this.isZoomed!==!1)return;o=this.currentIndex,a=!0,t=c.pageX,n=c.pageY,r=c.pageX,i=Date.now(),e.classList.add(`vistaview-image-container--pointer-down`);let l=this.containerElement?.querySelector(`.vistaview-image-container`),u=Array.from(l.querySelectorAll(`.vistaview-item`));s=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting&&(o=u.indexOf(e.target))})},{threshold:.5,root:this.containerElement}),u.forEach(e=>{s.observe(e)})},this.onPointerMove=i=>{if(i.preventDefault(),i.stopPropagation(),this.isZoomed!==!1||!a)return;let o=i.pageX-t,s=i.pageY-n;r=i.pageX,e.style.setProperty(`--vistaview-pointer-diff-x`,`${o}px`),e.style.setProperty(`--vistaview-pointer-diff-y`,`${s}px`)},this.onPointerUp=n=>{if(n.preventDefault(),n.stopPropagation(),this.isZoomed!==!1||!a)return;a=!1,s.disconnect();let c=(r-t)/(Date.now()-i),l=this.options.touchSpeedThreshold||1;c<-l&&o===this.currentIndex?o=Math.min(this.currentIndex+1,this.elements.length-1):c>l&&o===this.currentIndex&&(o=Math.max(this.currentIndex-1,0)),e.style.setProperty(`--vistaview-pointer-diff-x`,`0px`),e.style.setProperty(`--vistaview-pointer-diff-y`,`0px`),e.classList.remove(`vistaview-image-container--pointer-down`),o!==this.currentIndex&&this.view(o)},e.addEventListener(`pointermove`,this.onPointerMove),e.addEventListener(`pointerup`,this.onPointerUp),e.addEventListener(`pointerdown`,this.onPointerDown)}removeTouchActions(){let e=this.containerElement?.querySelector(`.vistaview-image-container`);e&&(this.onPointerMove&&e.removeEventListener(`pointermove`,this.onPointerMove),this.onPointerUp&&e.removeEventListener(`pointerup`,this.onPointerUp),this.onPointerDown&&e.removeEventListener(`pointerdown`,this.onPointerDown))}open(e){if(_.somethingOpened)return;if(_.somethingOpened=!0,this.isActive=!0,e||=0,e<0||e>=this.elements.length)throw Error(`VistaView: Index out of bounds:`+e);this.currentIndex=e;let t=c(this.elements,this.options.controls);if(document.body.prepend(f(t)),this.rootElement=document.querySelector(`#vistaview-root`),!this.rootElement)throw Error(`VistaView: Failed to create root element.`);if(this.options.detectReducedMotion&&this.isReducedMotion&&this.rootElement.classList.add(`vistaview--reduced-motion`),this.containerElement=this.rootElement.querySelector(`.vistaview-container`),!this.containerElement)throw Error(`VistaView: Failed to create container element.`);this.indexDisplayElement=this.containerElement.querySelector(`.vistaview-index-display`),this.descriptionElement=this.containerElement.querySelector(`.vistaview-image-description`),this.options.animationDurationBase&&this.rootElement.style.setProperty(`--vistaview-animation-duration`,`${this.options.animationDurationBase}`),this.options.initialZIndex!==void 0&&this.rootElement.style.setProperty(`--vistaview-initial-z-index`,`${this.options.initialZIndex}`);let n=this.elements[e].image?l(this.elements[e].image):void 0,r=this.elements[e].anchor?l(this.elements[e].anchor):void 0,i=this.elements[e].anchor?this.elements[e].anchor:this.elements[e].image;if(i){let e=i.getBoundingClientRect();this.rootElement.style.setProperty(`--vistaview-container-initial-width`,`${e?.width}px`),this.rootElement.style.setProperty(`--vistaview-container-initial-height`,`${e?.height}px`),this.rootElement.style.setProperty(`--vistaview-container-initial-top`,`${e.top+e.height/2}px`),this.rootElement.style.setProperty(`--vistaview-container-initial-left`,`${e.left+e.width/2}px`)}this.rootElement.style.setProperty(`--vistaview-number-elements`,`${this.elements.length}`),this.rootElement.style.setProperty(`--vistaview-image-border-radius`,p(n?.borderRadius)||p(r?.borderRadius)||`0px`),this.setInitialProperties=()=>{if(!this.isActive)return;let e=this.elements[this.currentIndex].anchor?this.elements[this.currentIndex].anchor:this.elements[this.currentIndex].image;if(!e)return;let t=e.getBoundingClientRect();this.rootElement?.style.setProperty(`--vistaview-container-initial-width`,`${t?.width}px`),this.rootElement?.style.setProperty(`--vistaview-container-initial-height`,`${t?.height}px`),this.rootElement?.style.setProperty(`--vistaview-container-initial-top`,`${t.top+t.height/2}px`),this.rootElement?.style.setProperty(`--vistaview-container-initial-left`,`${t.left+t.width/2}px`)},window.addEventListener(`resize`,this.setInitialProperties);let a=[...this.options.controls.topLeft||[],...this.options.controls.topCenter||[],...this.options.controls.topRight||[],...this.options.controls.bottomLeft||[],...this.options.controls.bottomCenter||[],...this.options.controls.bottomRight||[]].filter(e=>typeof e!=`string`);this.containerElement.querySelectorAll(`button`).forEach(e=>{let t=e.getAttribute(`data-vistaview-custom-control`);if(t){let n=a.find(e=>e.name===t);n&&e.addEventListener(`click`,()=>{n.onClick(this.elements[this.currentIndex])})}else e.classList.contains(`vistaview-zoom-in-button`)?e.addEventListener(`click`,()=>{this.zoomIn()}):e.classList.contains(`vistaview-zoom-out-button`)?e.addEventListener(`click`,()=>{this.zoomOut()}):e.classList.contains(`vistaview-close-button`)?e.addEventListener(`click`,()=>{this.close()}):e.parentElement?.classList.contains(`vistaview-prev-btn`)?e.addEventListener(`click`,()=>{this.prev()}):e.parentElement?.classList.contains(`vistaview-next-btn`)&&e.addEventListener(`click`,()=>{this.next()})}),this.setIndexDisplay(),this.setCurrentDescription(),this.rootElement?.style.setProperty(`--vistaview-current-index`,`${this.currentIndex}`),this.containerElement.querySelectorAll(`.vistaview-image-highres`).forEach((e,t)=>{let n=e,r=this.elements[t].image;if(r){let{width:e,height:t}=m(r),i=Math.min(r.width,e),a=Math.min(r.height,t);n.style.width=`${i}px`,n.style.height=`${a}px`,n.style.setProperty(`--vistaview-fitted-width`,`${i}px`),n.style.setProperty(`--vistaview-fitted-height`,`${a}px`)}let i=()=>{n.classList.add(`vistaview-image-loaded`),setTimeout(()=>{h(n)},100),setTimeout(()=>{n.parentElement?.querySelector(`.vistaview-image-lowres`)?.classList.add(`vistaview-image--hidden`)},500),t===this.currentIndex&&this.updateZoomButtonsVisibility()};n.complete?i():n.onload=i}),this.setFullScreenContain=()=>{this.isActive&&(this.containerElement?.querySelectorAll(`.vistaview-image-highres`))?.forEach(e=>{let t=e;h(t,t.classList.contains(`vistaview-image--zooming`))})},window.addEventListener(`resize`,this.setFullScreenContain),this.setTouchActions(),this.onKeyDown=e=>{if(this.isActive)switch(e.key){case`ArrowLeft`:e.preventDefault(),this.prev();break;case`ArrowRight`:e.preventDefault(),this.next();break;case`ArrowUp`:e.preventDefault(),this.zoomIn();break;case`ArrowDown`:e.preventDefault(),this.zoomOut();break;case`Escape`:e.preventDefault(),this.close();break}},window.addEventListener(`keydown`,this.onKeyDown),setTimeout(()=>{this.rootElement&&this.rootElement.classList.add(`vistaview--initialized`),this.resetImageOpacity()},33)}async close(e=!0){if(this.isActive){if(this.isActive=!1,e){let e=this.getAnimationDurationBase();this.rootElement?.classList.add(`vistaview--closing`),this.options.detectReducedMotion&&this.isReducedMotion||await new Promise(t=>{setTimeout(()=>{t(!0)},e*1.5)})}this.removeTouchActions(),this.rootElement?.remove(),this.rootElement=null,this.containerElement=null,this.resetImageOpacity(!0),this.setInitialProperties&&window.removeEventListener(`resize`,this.setInitialProperties),this.setFullScreenContain&&window.removeEventListener(`resize`,this.setFullScreenContain),this.onKeyDown&&window.removeEventListener(`keydown`,this.onKeyDown),_.somethingOpened=!1}}destroy(){this.isActive&&(this.close(!1),this.elements.forEach(e=>{let t=e.anchor||e.image;t&&e.onClick&&t.removeEventListener(`click`,e.onClick)}))}view(e){if(this.isActive){if(e<0||e>=this.elements.length)throw Error(`VistaView: Index out of bounds:`+e);this.clearZoom(),this.currentIndex=e,this.resetImageOpacity(),this.setIndexDisplay(),this.setCurrentDescription(),this.updateZoomButtonsVisibility(),this.setInitialProperties&&this.setInitialProperties(),this.rootElement?.style.setProperty(`--vistaview-current-index`,`${this.currentIndex}`)}}next(){this.isActive&&this.view((this.currentIndex+1)%this.elements.length)}prev(){this.isActive&&this.view((this.currentIndex-1+this.elements.length)%this.elements.length)}getCurrentIndex(){return this.isActive?this.currentIndex:-1}},b=e=>{let t=e instanceof HTMLImageElement?e:e.querySelector(`img`);return{src:e.dataset.vistaviewSrc||e.getAttribute(`href`)||e.getAttribute(`src`)||``,width:+(e.dataset.vistaviewWidth||t?.naturalWidth||0),height:+(e.dataset.vistaviewHeight||t?.naturalHeight||0),smallSrc:t?.src||e.dataset.vistaviewSmallsrc||e.getAttribute(`src`)||``,alt:t?.alt||e.dataset.vistaviewAlt||e.getAttribute(`alt`)||``,anchor:e instanceof HTMLAnchorElement?e:void 0,image:t||void 0}};function x({parent:e,elements:t,...n}){if(!e&&!t)throw Error(`No parent or elements`);let r;if(e){let t=e.querySelector(`img[data-vistaview-src]`)?`img[data-vistaview-src]`:`a[href]`;r=Array.from(e.querySelectorAll(t)).map(b)}else if(typeof t==`string`)r=Array.from(document.querySelectorAll(t)).map(b);else if(t instanceof NodeList)r=Array.from(t).map(b);else if(Array.isArray(t))r=t;else throw Error(`Invalid elements`);if(!r.length)throw Error(`No elements found`);let i=new y(r,n);return{open:(e=0)=>i.open(e),close:()=>i.close(),next:()=>i.next(),prev:()=>i.prev(),destroy:()=>i.destroy(),getCurrentIndex:()=>i.getCurrentIndex(),view:e=>{i.view(e)}}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return x}});
|