vistaview 0.0.1 → 0.1.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/README.md +21 -1
- package/dist/react.cjs +1 -0
- package/dist/react.d.ts +20 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +32 -0
- package/dist/solid.cjs +1 -0
- package/dist/solid.d.ts +14 -0
- package/dist/solid.d.ts.map +1 -0
- package/dist/solid.js +22 -0
- package/dist/svelte.cjs +1 -0
- package/dist/svelte.d.ts +14 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +22 -0
- package/dist/vistaview-DcqJLxF6.cjs +14 -0
- package/dist/vistaview-dor4TcfU.js +433 -0
- package/dist/vistaview.cjs +1 -0
- package/dist/vistaview.js +1 -432
- package/dist/vue.cjs +1 -0
- package/dist/vue.d.ts +14 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +22 -0
- package/package.json +64 -4
- package/dist/vistaview.umd.cjs +0 -14
|
@@ -0,0 +1,433 @@
|
|
|
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
|
+
constructor(e, c) {
|
|
179
|
+
this.elements = e, this.options = {
|
|
180
|
+
...DefaultOptions,
|
|
181
|
+
...c || {},
|
|
182
|
+
controls: {
|
|
183
|
+
...DefaultOptions.controls,
|
|
184
|
+
...c?.controls || {}
|
|
185
|
+
}
|
|
186
|
+
}, this.isReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches, this.elements.forEach((e, c) => {
|
|
187
|
+
let l = e.anchor || e.image;
|
|
188
|
+
l && (e.onClick = (e) => {
|
|
189
|
+
e.preventDefault(), this.open(c);
|
|
190
|
+
}, l.addEventListener("click", e.onClick));
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
setZoomed(e) {
|
|
194
|
+
if (this.isZoomed === e) return;
|
|
195
|
+
let c = this.isZoomed === !1 ? null : this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.isZoomed];
|
|
196
|
+
if (this.isZoomed = e, this.isZoomed === !1 && c) {
|
|
197
|
+
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(() => {
|
|
198
|
+
c?.classList.remove("vistaview-image--zooming");
|
|
199
|
+
}, 500);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.isZoomed !== !1) {
|
|
203
|
+
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");
|
|
204
|
+
let e = !1, l = 0, u = 0, d = 0, f = 0, p = 0, m = 0;
|
|
205
|
+
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) => {
|
|
206
|
+
d.preventDefault(), d.stopPropagation(), e = !0, l = d.pageX, u = d.pageY, c.setPointerCapture(d.pointerId);
|
|
207
|
+
}, this.onZoomedPointerMove = (h) => {
|
|
208
|
+
if (!e) return;
|
|
209
|
+
h.preventDefault(), p = h.pageX - l, m = h.pageY - u;
|
|
210
|
+
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));
|
|
211
|
+
p = b - d, m = x - f, c?.style.setProperty("--pointer-diff-x", `${b}px`), c?.style.setProperty("--pointer-diff-y", `${x}px`);
|
|
212
|
+
}, this.onZoomedPointerUp = (l) => {
|
|
213
|
+
e = !1, c.releasePointerCapture(l.pointerId), d += p, f += m, p = 0, m = 0;
|
|
214
|
+
}, c?.parentElement?.addEventListener("pointerdown", this.onZoomedPointerDown), c?.parentElement?.addEventListener("pointermove", this.onZoomedPointerMove), c?.parentElement?.addEventListener("pointerup", this.onZoomedPointerUp);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
setIndexDisplay() {
|
|
218
|
+
this.indexDisplayElement && (this.indexDisplayElement.textContent = `${this.currentIndex + 1} / ${this.elements.length}`);
|
|
219
|
+
}
|
|
220
|
+
setCurrentDescription() {
|
|
221
|
+
this.descriptionElement && (this.currentDescription = this.elements[this.currentIndex].alt || "", this.descriptionElement && (this.descriptionElement.textContent = this.currentDescription));
|
|
222
|
+
}
|
|
223
|
+
getAnimationDurationBase() {
|
|
224
|
+
let e = window.getComputedStyle(this.rootElement);
|
|
225
|
+
return parseInt(e.getPropertyValue("--vistaview-animation-duration"));
|
|
226
|
+
}
|
|
227
|
+
zoomIn() {
|
|
228
|
+
let e = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.currentIndex], c = e.width, l = e.height;
|
|
229
|
+
e.dataset.vistaviewInitialWidth || (e.dataset.vistaviewInitialWidth = c.toString()), e.dataset.vistaviewInitialHeight || (e.dataset.vistaviewInitialHeight = l.toString()), this.setZoomed(this.currentIndex);
|
|
230
|
+
let u = (e.naturalWidth || 0) * this.options.maxZoomLevel;
|
|
231
|
+
if (c && u && c < u) {
|
|
232
|
+
let d = Math.min(c + this.options.zoomStep, u);
|
|
233
|
+
e.style.width = `${d}px`;
|
|
234
|
+
let f = d / c * l;
|
|
235
|
+
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");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
zoomOut() {
|
|
239
|
+
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;
|
|
240
|
+
if (e.classList.add("vistaview-image--zooming-out"), setTimeout(() => {
|
|
241
|
+
e.classList.remove("vistaview-image--zooming-out");
|
|
242
|
+
}, 333), c && u && c > u) {
|
|
243
|
+
let d = Math.max(c - this.options.zoomStep, u);
|
|
244
|
+
e.style.width = `${d}px`;
|
|
245
|
+
let f = d / c * l;
|
|
246
|
+
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();
|
|
247
|
+
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");
|
|
248
|
+
_ = 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));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
clearZoom() {
|
|
252
|
+
let e = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.currentIndex];
|
|
253
|
+
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);
|
|
254
|
+
}
|
|
255
|
+
resetImageOpacity(e = !1) {
|
|
256
|
+
this.elements.forEach((c, l) => {
|
|
257
|
+
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);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
setTouchActions() {
|
|
261
|
+
this.removeTouchActions();
|
|
262
|
+
let e = this.containerElement?.querySelector(".vistaview-image-container");
|
|
263
|
+
if (!e) return;
|
|
264
|
+
let c = 0, l = 0, u = 0, d = 0, f = !1, p = this.currentIndex, m;
|
|
265
|
+
this.onPointerDown = (h) => {
|
|
266
|
+
if (h.preventDefault(), h.stopPropagation(), this.isZoomed !== !1) return;
|
|
267
|
+
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");
|
|
268
|
+
let g = this.containerElement?.querySelector(".vistaview-image-container"), _ = Array.from(g.querySelectorAll(".vistaview-item"));
|
|
269
|
+
m = new IntersectionObserver((e) => {
|
|
270
|
+
e.forEach((e) => {
|
|
271
|
+
e.isIntersecting && (p = _.indexOf(e.target));
|
|
272
|
+
});
|
|
273
|
+
}, {
|
|
274
|
+
threshold: .5,
|
|
275
|
+
root: this.containerElement
|
|
276
|
+
}), _.forEach((e) => {
|
|
277
|
+
m.observe(e);
|
|
278
|
+
});
|
|
279
|
+
}, this.onPointerMove = (d) => {
|
|
280
|
+
if (d.preventDefault(), d.stopPropagation(), this.isZoomed !== !1 || !f) return;
|
|
281
|
+
let p = d.pageX - c, m = d.pageY - l;
|
|
282
|
+
u = d.pageX, e.style.setProperty("--vistaview-pointer-diff-x", `${p}px`), e.style.setProperty("--vistaview-pointer-diff-y", `${m}px`);
|
|
283
|
+
}, this.onPointerUp = (l) => {
|
|
284
|
+
if (l.preventDefault(), l.stopPropagation(), this.isZoomed !== !1 || !f) return;
|
|
285
|
+
f = !1, m.disconnect();
|
|
286
|
+
let h = (u - c) / (Date.now() - d), g = this.options.touchSpeedThreshold || 1;
|
|
287
|
+
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);
|
|
288
|
+
}, e.addEventListener("pointermove", this.onPointerMove), e.addEventListener("pointerup", this.onPointerUp), e.addEventListener("pointerdown", this.onPointerDown);
|
|
289
|
+
}
|
|
290
|
+
removeTouchActions() {
|
|
291
|
+
let e = this.containerElement?.querySelector(".vistaview-image-container");
|
|
292
|
+
e && (this.onPointerMove && e.removeEventListener("pointermove", this.onPointerMove), this.onPointerUp && e.removeEventListener("pointerup", this.onPointerUp), this.onPointerDown && e.removeEventListener("pointerdown", this.onPointerDown));
|
|
293
|
+
}
|
|
294
|
+
open(e) {
|
|
295
|
+
if (GlobalVistaState.somethingOpened) return;
|
|
296
|
+
if (GlobalVistaState.somethingOpened = !0, this.isActive = !0, e ||= 0, e < 0 || e >= this.elements.length) throw Error("VistaView: Index out of bounds:" + e);
|
|
297
|
+
this.currentIndex = e;
|
|
298
|
+
let c = vistaViewComponent(this.elements, this.options.controls);
|
|
299
|
+
if (document.body.prepend(createTrustedHtml(c)), this.rootElement = document.querySelector("#vistaview-root"), !this.rootElement) throw Error("VistaView: Failed to create root element.");
|
|
300
|
+
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.");
|
|
301
|
+
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}`);
|
|
302
|
+
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;
|
|
303
|
+
if (d) {
|
|
304
|
+
let e = d.getBoundingClientRect();
|
|
305
|
+
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`);
|
|
306
|
+
}
|
|
307
|
+
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 = () => {
|
|
308
|
+
if (!this.isActive) return;
|
|
309
|
+
let e = this.elements[this.currentIndex].anchor ? this.elements[this.currentIndex].anchor : this.elements[this.currentIndex].image;
|
|
310
|
+
if (!e) return;
|
|
311
|
+
let c = e.getBoundingClientRect();
|
|
312
|
+
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`);
|
|
313
|
+
}, window.addEventListener("resize", this.setInitialProperties);
|
|
314
|
+
let f = [
|
|
315
|
+
...this.options.controls.topLeft || [],
|
|
316
|
+
...this.options.controls.topCenter || [],
|
|
317
|
+
...this.options.controls.topRight || [],
|
|
318
|
+
...this.options.controls.bottomLeft || [],
|
|
319
|
+
...this.options.controls.bottomCenter || [],
|
|
320
|
+
...this.options.controls.bottomRight || []
|
|
321
|
+
].filter((e) => typeof e != "string");
|
|
322
|
+
this.containerElement.querySelectorAll("button").forEach((e) => {
|
|
323
|
+
let c = e.getAttribute("data-vistaview-custom-control");
|
|
324
|
+
if (c) {
|
|
325
|
+
let l = f.find((e) => e.name === c);
|
|
326
|
+
l && e.addEventListener("click", () => {
|
|
327
|
+
l.onClick(this.elements[this.currentIndex]);
|
|
328
|
+
});
|
|
329
|
+
} else e.classList.contains("vistaview-zoom-in-button") ? e.addEventListener("click", () => {
|
|
330
|
+
this.zoomIn();
|
|
331
|
+
}) : e.classList.contains("vistaview-zoom-out-button") ? e.addEventListener("click", () => {
|
|
332
|
+
this.zoomOut();
|
|
333
|
+
}) : e.classList.contains("vistaview-close-button") ? e.addEventListener("click", () => {
|
|
334
|
+
this.close();
|
|
335
|
+
}) : e.parentElement?.classList.contains("vistaview-prev-btn") ? e.addEventListener("click", () => {
|
|
336
|
+
this.prev();
|
|
337
|
+
}) : e.parentElement?.classList.contains("vistaview-next-btn") && e.addEventListener("click", () => {
|
|
338
|
+
this.next();
|
|
339
|
+
});
|
|
340
|
+
}), this.setIndexDisplay(), this.setCurrentDescription(), this.rootElement?.style.setProperty("--vistaview-current-index", `${this.currentIndex}`), this.containerElement.querySelectorAll(".vistaview-image-highres").forEach((e, c) => {
|
|
341
|
+
let l = e, u = this.elements[c].image;
|
|
342
|
+
if (u) {
|
|
343
|
+
let { width: e, height: c } = getFittedSize(u), d = Math.min(u.width, e), f = Math.min(u.height, c);
|
|
344
|
+
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`);
|
|
345
|
+
}
|
|
346
|
+
function d() {
|
|
347
|
+
l.classList.add("vistaview-image-loaded"), setTimeout(() => {
|
|
348
|
+
makeFullScreenContain(l);
|
|
349
|
+
}, 100), setTimeout(() => {
|
|
350
|
+
l.parentElement?.querySelector(".vistaview-image-lowres")?.classList.add("vistaview-image--hidden");
|
|
351
|
+
}, 500);
|
|
352
|
+
}
|
|
353
|
+
l.complete ? d() : l.onload = d;
|
|
354
|
+
}), this.setFullScreenContain = () => {
|
|
355
|
+
this.isActive && (this.containerElement?.querySelectorAll(".vistaview-image-highres"))?.forEach((e) => {
|
|
356
|
+
let c = e;
|
|
357
|
+
makeFullScreenContain(c, c.classList.contains("vistaview-image--zooming"));
|
|
358
|
+
});
|
|
359
|
+
}, window.addEventListener("resize", this.setFullScreenContain), this.setTouchActions(), setTimeout(() => {
|
|
360
|
+
this.rootElement && this.rootElement.classList.add("vistaview--initialized"), this.resetImageOpacity();
|
|
361
|
+
}, 33);
|
|
362
|
+
}
|
|
363
|
+
async close(e = !0) {
|
|
364
|
+
if (this.isActive) {
|
|
365
|
+
if (this.isActive = !1, e) {
|
|
366
|
+
let e = this.getAnimationDurationBase();
|
|
367
|
+
this.rootElement?.classList.add("vistaview--closing"), this.options.detectReducedMotion && this.isReducedMotion || await new Promise((c) => {
|
|
368
|
+
setTimeout(() => {
|
|
369
|
+
c(!0);
|
|
370
|
+
}, e * 1.5);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
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), GlobalVistaState.somethingOpened = !1;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
destroy() {
|
|
377
|
+
this.isActive && (this.close(!1), this.elements.forEach((e) => {
|
|
378
|
+
let c = e.anchor || e.image;
|
|
379
|
+
c && e.onClick && c.removeEventListener("click", e.onClick);
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
view(e) {
|
|
383
|
+
if (this.isActive) {
|
|
384
|
+
if (e < 0 || e >= this.elements.length) throw Error("VistaView: Index out of bounds:" + e);
|
|
385
|
+
this.clearZoom(), this.currentIndex = e, this.resetImageOpacity(), this.setIndexDisplay(), this.setCurrentDescription(), this.setInitialProperties && this.setInitialProperties(), this.rootElement?.style.setProperty("--vistaview-current-index", `${this.currentIndex}`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
next() {
|
|
389
|
+
this.isActive && this.view((this.currentIndex + 1) % this.elements.length);
|
|
390
|
+
}
|
|
391
|
+
prev() {
|
|
392
|
+
this.isActive && this.view((this.currentIndex - 1 + this.elements.length) % this.elements.length);
|
|
393
|
+
}
|
|
394
|
+
getCurrentIndex() {
|
|
395
|
+
return this.isActive ? this.currentIndex : -1;
|
|
396
|
+
}
|
|
397
|
+
}, toImage = (e) => {
|
|
398
|
+
let c = e instanceof HTMLImageElement ? e : e.querySelector("img");
|
|
399
|
+
return {
|
|
400
|
+
src: e.dataset.vistaviewSrc || e.getAttribute("href") || e.getAttribute("src") || "",
|
|
401
|
+
width: +(e.dataset.vistaviewWidth || c?.naturalWidth || 0),
|
|
402
|
+
height: +(e.dataset.vistaviewHeight || c?.naturalHeight || 0),
|
|
403
|
+
smallSrc: c?.src || e.dataset.vistaviewSmallsrc || e.getAttribute("src") || "",
|
|
404
|
+
alt: c?.alt || e.dataset.vistaviewAlt || e.getAttribute("alt") || "",
|
|
405
|
+
anchor: e instanceof HTMLAnchorElement ? e : void 0,
|
|
406
|
+
image: c || void 0
|
|
407
|
+
};
|
|
408
|
+
};
|
|
409
|
+
function vistaView({ parent: e, elements: c, ...l }) {
|
|
410
|
+
if (!e && !c) throw Error("No parent or elements");
|
|
411
|
+
let u;
|
|
412
|
+
if (e) {
|
|
413
|
+
let c = e.querySelector("img[data-vistaview-src]") ? "img[data-vistaview-src]" : "a[href]";
|
|
414
|
+
u = Array.from(e.querySelectorAll(c)).map(toImage);
|
|
415
|
+
} else if (typeof c == "string") u = Array.from(document.querySelectorAll(c)).map(toImage);
|
|
416
|
+
else if (c instanceof NodeList) u = Array.from(c).map(toImage);
|
|
417
|
+
else if (Array.isArray(c)) u = c;
|
|
418
|
+
else throw Error("Invalid elements");
|
|
419
|
+
if (!u.length) throw Error("No elements found");
|
|
420
|
+
let d = new VistaView(u, l);
|
|
421
|
+
return {
|
|
422
|
+
open: (e = 0) => d.open(e),
|
|
423
|
+
close: () => d.close(),
|
|
424
|
+
next: () => d.next(),
|
|
425
|
+
prev: () => d.prev(),
|
|
426
|
+
destroy: () => d.destroy(),
|
|
427
|
+
getCurrentIndex: () => d.getCurrentIndex(),
|
|
428
|
+
view: (e) => {
|
|
429
|
+
d.view(e);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
export { DefaultOptions as n, getDownloadButton as r, vistaView as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./vistaview-DcqJLxF6.cjs`);exports.DefaultOptions=e.n,exports.getDownloadButton=e.r,exports.vistaView=e.t;
|