vistaview 0.1.0 → 0.2.0
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 +31 -1
- package/dist/lib/vista-view.d.ts +1 -0
- package/dist/lib/vista-view.d.ts.map +1 -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-B7UMydz4.cjs +14 -0
- package/dist/vistaview-D-ZOkDpV.js +452 -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 +48 -4
- package/dist/vistaview.umd.cjs +0 -14
package/dist/vistaview.js
CHANGED
|
@@ -1,433 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
import { n as DefaultOptions, r as getDownloadButton, t as vistaView } from "./vistaview-D-ZOkDpV.js";
|
|
433
2
|
export { DefaultOptions, getDownloadButton, vistaView };
|
package/dist/vue.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./vistaview-B7UMydz4.cjs`);let t=require(`vue`);function n(n={}){let r=(0,t.ref)(null),i=null;return(0,t.onMounted)(()=>{r.value&&(i=e.t({parent:r.value,...n}))}),(0,t.onUnmounted)(()=>{i?.destroy(),i=null}),{container:r,open:e=>i?.open(e),close:()=>i?.close(),next:()=>i?.next(),prev:()=>i?.prev(),getCurrentIndex:()=>i?.getCurrentIndex()??-1,view:e=>i?.view(e)}}exports.useVistaView=n;
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { VistaViewOptions, VistaViewInterface, VistaViewImage } from './vistaview';
|
|
3
|
+
export type { VistaViewOptions, VistaViewInterface, VistaViewImage };
|
|
4
|
+
type UseVistaViewOptions = Omit<VistaViewOptions, 'parent'>;
|
|
5
|
+
export declare function useVistaView(options?: UseVistaViewOptions): {
|
|
6
|
+
container: Ref<HTMLElement | null, HTMLElement | null>;
|
|
7
|
+
open: (i?: number) => void | undefined;
|
|
8
|
+
close: () => void | undefined;
|
|
9
|
+
next: () => void | undefined;
|
|
10
|
+
prev: () => void | undefined;
|
|
11
|
+
getCurrentIndex: () => number;
|
|
12
|
+
view: (i: number) => void | undefined;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAE5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExF,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC;AAErE,KAAK,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAE5D,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB;;eAiB/C,MAAM;;;;;cAKP,MAAM;EAEnB"}
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { t as vistaView } from "./vistaview-D-ZOkDpV.js";
|
|
2
|
+
import { onMounted, onUnmounted, ref } from "vue";
|
|
3
|
+
function useVistaView(i = {}) {
|
|
4
|
+
let a = ref(null), o = null;
|
|
5
|
+
return onMounted(() => {
|
|
6
|
+
a.value && (o = vistaView({
|
|
7
|
+
parent: a.value,
|
|
8
|
+
...i
|
|
9
|
+
}));
|
|
10
|
+
}), onUnmounted(() => {
|
|
11
|
+
o?.destroy(), o = null;
|
|
12
|
+
}), {
|
|
13
|
+
container: a,
|
|
14
|
+
open: (e) => o?.open(e),
|
|
15
|
+
close: () => o?.close(),
|
|
16
|
+
next: () => o?.next(),
|
|
17
|
+
prev: () => o?.prev(),
|
|
18
|
+
getCurrentIndex: () => o?.getCurrentIndex() ?? -1,
|
|
19
|
+
view: (e) => o?.view(e)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export { useVistaView };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vistaview",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A lightweight, zero-dependency image lightbox library with smooth animations and touch support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image",
|
|
@@ -19,17 +19,57 @@
|
|
|
19
19
|
"responsive"
|
|
20
20
|
],
|
|
21
21
|
"type": "module",
|
|
22
|
-
"main": "./dist/vistaview.
|
|
22
|
+
"main": "./dist/vistaview.cjs",
|
|
23
23
|
"module": "./dist/vistaview.js",
|
|
24
24
|
"types": "./dist/vistaview.d.ts",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
27
|
"types": "./dist/vistaview.d.ts",
|
|
28
28
|
"import": "./dist/vistaview.js",
|
|
29
|
-
"require": "./dist/vistaview.
|
|
29
|
+
"require": "./dist/vistaview.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./react": {
|
|
32
|
+
"types": "./dist/react.d.ts",
|
|
33
|
+
"import": "./dist/react.js",
|
|
34
|
+
"require": "./dist/react.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./vue": {
|
|
37
|
+
"types": "./dist/vue.d.ts",
|
|
38
|
+
"import": "./dist/vue.js",
|
|
39
|
+
"require": "./dist/vue.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./svelte": {
|
|
42
|
+
"types": "./dist/svelte.d.ts",
|
|
43
|
+
"import": "./dist/svelte.js",
|
|
44
|
+
"require": "./dist/svelte.cjs"
|
|
45
|
+
},
|
|
46
|
+
"./solid": {
|
|
47
|
+
"types": "./dist/solid.d.ts",
|
|
48
|
+
"import": "./dist/solid.js",
|
|
49
|
+
"require": "./dist/solid.cjs"
|
|
30
50
|
},
|
|
31
51
|
"./style.css": "./dist/vistaview.css"
|
|
32
52
|
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": ">=17.0.0",
|
|
55
|
+
"solid-js": ">=1.0.0",
|
|
56
|
+
"svelte": ">=4.0.0",
|
|
57
|
+
"vue": ">=3.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"vue": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"svelte": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"solid-js": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
},
|
|
33
73
|
"files": [
|
|
34
74
|
"dist"
|
|
35
75
|
],
|
|
@@ -44,14 +84,18 @@
|
|
|
44
84
|
"*.{js,ts,css,json,md}": "prettier --write"
|
|
45
85
|
},
|
|
46
86
|
"devDependencies": {
|
|
87
|
+
"@types/react": "^19.2.7",
|
|
47
88
|
"@types/trusted-types": "^2.0.7",
|
|
48
89
|
"husky": "^9.1.7",
|
|
49
90
|
"lint-staged": "^16.2.7",
|
|
50
91
|
"prettier": "^3.7.4",
|
|
51
92
|
"sharp": "^0.34.5",
|
|
93
|
+
"solid-js": "^1.9.10",
|
|
94
|
+
"svelte": "^5.45.6",
|
|
52
95
|
"typescript": "~5.9.3",
|
|
53
96
|
"vite": "npm:rolldown-vite@7.2.5",
|
|
54
|
-
"vite-plugin-dts": "^4.5.4"
|
|
97
|
+
"vite-plugin-dts": "^4.5.4",
|
|
98
|
+
"vue": "^3.5.25"
|
|
55
99
|
},
|
|
56
100
|
"overrides": {
|
|
57
101
|
"vite": "npm:rolldown-vite@7.2.5"
|
package/dist/vistaview.umd.cjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.VistaView={}))})(this,function(e){var t=`<svg viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>`,n=`<svg viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>`,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="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/></svg>`,i=`<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>`,a=`<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>`,o=`<svg viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`;function s(){return{name:`download`,icon:a,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 c(e){if(typeof e==`string`)switch(e){case`zoomIn`:return`<button class="vistaview-zoom-in-button">${r}</button>`;case`zoomOut`:return`<button disabled class="vistaview-zoom-out-button">${i}</button>`;case`close`:return`<button class="vistaview-close-button">${o}</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 l(e,r){let i=e=>e?e.map(c).join(``):``;return`<div class="vistaview-root" id="vistaview-root">
|
|
2
|
-
<div class="vistaview-container">
|
|
3
|
-
<div class="vistaview-image-container">
|
|
4
|
-
${e.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>${t}</button></div>
|
|
12
|
-
<div class="vistaview-next-btn vistaview-ui"><button>${n}</button></div>
|
|
13
|
-
</div>
|
|
14
|
-
</div>`}function u(e){let t=getComputedStyle(e);return{objectFit:t.objectFit,borderRadius:t.borderRadius,objectPosition:t.objectPosition,overflow:t.overflow}}var d=null;function f(){return d||(window.trustedTypes||(window.trustedTypes={createPolicy:(e,t)=>t}),d=window.trustedTypes.createPolicy(`vistaView-policy`,{createHTML:e=>e,createScript:()=>{throw Error(`Not implemented`)},createScriptURL:()=>{throw Error(`Not implemented`)}}),d)}function p(e){let t=f().createHTML(e),n=document.createElement(`template`);n.innerHTML=t;let r=n.content;return n.remove(),r}function m(e){return e&&!/^0(px|%|r?em|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ex|ch)?$/i.test(e.trim())&&e}function h(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 g(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 _(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 v={somethingOpened:!1};let y={detectReducedMotion:!0,zoomStep:500,maxZoomLevel:2,touchSpeedThreshold:1,controls:{topLeft:[`indexDisplay`],topRight:[`zoomIn`,`zoomOut`,s(),`close`],bottomCenter:[`description`]}};var b=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;constructor(e,t){this.elements=e,this.options={...y,...t||{},controls:{...y.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}=_(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`))}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}=_(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(v.somethingOpened)return;if(v.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=l(this.elements,this.options.controls);if(document.body.prepend(p(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?u(this.elements[e].image):void 0,r=this.elements[e].anchor?u(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`,m(n?.borderRadius)||m(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}=h(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`)}function i(){n.classList.add(`vistaview-image-loaded`),setTimeout(()=>{g(n)},100),setTimeout(()=>{n.parentElement?.querySelector(`.vistaview-image-lowres`)?.classList.add(`vistaview-image--hidden`)},500)}n.complete?i():n.onload=i}),this.setFullScreenContain=()=>{this.isActive&&(this.containerElement?.querySelectorAll(`.vistaview-image-highres`))?.forEach(e=>{let t=e;g(t,t.classList.contains(`vistaview-image--zooming`))})},window.addEventListener(`resize`,this.setFullScreenContain),this.setTouchActions(),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),v.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.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}},x=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 S({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(x)}else if(typeof t==`string`)r=Array.from(document.querySelectorAll(t)).map(x);else if(t instanceof NodeList)r=Array.from(t).map(x);else if(Array.isArray(t))r=t;else throw Error(`Invalid elements`);if(!r.length)throw Error(`No elements found`);let i=new b(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)}}}e.DefaultOptions=y,e.getDownloadButton=s,e.vistaView=S});
|