vistaview 0.2.0 → 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 -65
- 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-B7UMydz4.cjs +0 -14
- package/dist/vistaview-D-ZOkDpV.js +0 -452
|
@@ -1,452 +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
|
-
zoomIn() {
|
|
229
|
-
let e = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.currentIndex], c = e.width, l = e.height;
|
|
230
|
-
e.dataset.vistaviewInitialWidth || (e.dataset.vistaviewInitialWidth = c.toString()), e.dataset.vistaviewInitialHeight || (e.dataset.vistaviewInitialHeight = l.toString()), this.setZoomed(this.currentIndex);
|
|
231
|
-
let u = (e.naturalWidth || 0) * this.options.maxZoomLevel;
|
|
232
|
-
if (c && u && c < u) {
|
|
233
|
-
let d = Math.min(c + this.options.zoomStep, u);
|
|
234
|
-
e.style.width = `${d}px`;
|
|
235
|
-
let f = d / c * l;
|
|
236
|
-
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");
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
zoomOut() {
|
|
240
|
-
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;
|
|
241
|
-
if (e.classList.add("vistaview-image--zooming-out"), setTimeout(() => {
|
|
242
|
-
e.classList.remove("vistaview-image--zooming-out");
|
|
243
|
-
}, 333), c && u && c > u) {
|
|
244
|
-
let d = Math.max(c - this.options.zoomStep, u);
|
|
245
|
-
e.style.width = `${d}px`;
|
|
246
|
-
let f = d / c * l;
|
|
247
|
-
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();
|
|
248
|
-
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");
|
|
249
|
-
_ = 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));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
clearZoom() {
|
|
253
|
-
let e = this.containerElement?.querySelectorAll(".vistaview-image-highres")[this.currentIndex];
|
|
254
|
-
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);
|
|
255
|
-
}
|
|
256
|
-
resetImageOpacity(e = !1) {
|
|
257
|
-
this.elements.forEach((c, l) => {
|
|
258
|
-
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);
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
setTouchActions() {
|
|
262
|
-
this.removeTouchActions();
|
|
263
|
-
let e = this.containerElement?.querySelector(".vistaview-image-container");
|
|
264
|
-
if (!e) return;
|
|
265
|
-
let c = 0, l = 0, u = 0, d = 0, f = !1, p = this.currentIndex, m;
|
|
266
|
-
this.onPointerDown = (h) => {
|
|
267
|
-
if (h.preventDefault(), h.stopPropagation(), this.isZoomed !== !1) return;
|
|
268
|
-
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");
|
|
269
|
-
let g = this.containerElement?.querySelector(".vistaview-image-container"), _ = Array.from(g.querySelectorAll(".vistaview-item"));
|
|
270
|
-
m = new IntersectionObserver((e) => {
|
|
271
|
-
e.forEach((e) => {
|
|
272
|
-
e.isIntersecting && (p = _.indexOf(e.target));
|
|
273
|
-
});
|
|
274
|
-
}, {
|
|
275
|
-
threshold: .5,
|
|
276
|
-
root: this.containerElement
|
|
277
|
-
}), _.forEach((e) => {
|
|
278
|
-
m.observe(e);
|
|
279
|
-
});
|
|
280
|
-
}, this.onPointerMove = (d) => {
|
|
281
|
-
if (d.preventDefault(), d.stopPropagation(), this.isZoomed !== !1 || !f) return;
|
|
282
|
-
let p = d.pageX - c, m = d.pageY - l;
|
|
283
|
-
u = d.pageX, e.style.setProperty("--vistaview-pointer-diff-x", `${p}px`), e.style.setProperty("--vistaview-pointer-diff-y", `${m}px`);
|
|
284
|
-
}, this.onPointerUp = (l) => {
|
|
285
|
-
if (l.preventDefault(), l.stopPropagation(), this.isZoomed !== !1 || !f) return;
|
|
286
|
-
f = !1, m.disconnect();
|
|
287
|
-
let h = (u - c) / (Date.now() - d), g = this.options.touchSpeedThreshold || 1;
|
|
288
|
-
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);
|
|
289
|
-
}, e.addEventListener("pointermove", this.onPointerMove), e.addEventListener("pointerup", this.onPointerUp), e.addEventListener("pointerdown", this.onPointerDown);
|
|
290
|
-
}
|
|
291
|
-
removeTouchActions() {
|
|
292
|
-
let e = this.containerElement?.querySelector(".vistaview-image-container");
|
|
293
|
-
e && (this.onPointerMove && e.removeEventListener("pointermove", this.onPointerMove), this.onPointerUp && e.removeEventListener("pointerup", this.onPointerUp), this.onPointerDown && e.removeEventListener("pointerdown", this.onPointerDown));
|
|
294
|
-
}
|
|
295
|
-
open(e) {
|
|
296
|
-
if (GlobalVistaState.somethingOpened) return;
|
|
297
|
-
if (GlobalVistaState.somethingOpened = !0, this.isActive = !0, e ||= 0, e < 0 || e >= this.elements.length) throw Error("VistaView: Index out of bounds:" + e);
|
|
298
|
-
this.currentIndex = e;
|
|
299
|
-
let c = vistaViewComponent(this.elements, this.options.controls);
|
|
300
|
-
if (document.body.prepend(createTrustedHtml(c)), this.rootElement = document.querySelector("#vistaview-root"), !this.rootElement) throw Error("VistaView: Failed to create root element.");
|
|
301
|
-
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.");
|
|
302
|
-
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}`);
|
|
303
|
-
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;
|
|
304
|
-
if (d) {
|
|
305
|
-
let e = d.getBoundingClientRect();
|
|
306
|
-
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`);
|
|
307
|
-
}
|
|
308
|
-
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 = () => {
|
|
309
|
-
if (!this.isActive) return;
|
|
310
|
-
let e = this.elements[this.currentIndex].anchor ? this.elements[this.currentIndex].anchor : this.elements[this.currentIndex].image;
|
|
311
|
-
if (!e) return;
|
|
312
|
-
let c = e.getBoundingClientRect();
|
|
313
|
-
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`);
|
|
314
|
-
}, window.addEventListener("resize", this.setInitialProperties);
|
|
315
|
-
let f = [
|
|
316
|
-
...this.options.controls.topLeft || [],
|
|
317
|
-
...this.options.controls.topCenter || [],
|
|
318
|
-
...this.options.controls.topRight || [],
|
|
319
|
-
...this.options.controls.bottomLeft || [],
|
|
320
|
-
...this.options.controls.bottomCenter || [],
|
|
321
|
-
...this.options.controls.bottomRight || []
|
|
322
|
-
].filter((e) => typeof e != "string");
|
|
323
|
-
this.containerElement.querySelectorAll("button").forEach((e) => {
|
|
324
|
-
let c = e.getAttribute("data-vistaview-custom-control");
|
|
325
|
-
if (c) {
|
|
326
|
-
let l = f.find((e) => e.name === c);
|
|
327
|
-
l && e.addEventListener("click", () => {
|
|
328
|
-
l.onClick(this.elements[this.currentIndex]);
|
|
329
|
-
});
|
|
330
|
-
} else e.classList.contains("vistaview-zoom-in-button") ? e.addEventListener("click", () => {
|
|
331
|
-
this.zoomIn();
|
|
332
|
-
}) : e.classList.contains("vistaview-zoom-out-button") ? e.addEventListener("click", () => {
|
|
333
|
-
this.zoomOut();
|
|
334
|
-
}) : e.classList.contains("vistaview-close-button") ? e.addEventListener("click", () => {
|
|
335
|
-
this.close();
|
|
336
|
-
}) : e.parentElement?.classList.contains("vistaview-prev-btn") ? e.addEventListener("click", () => {
|
|
337
|
-
this.prev();
|
|
338
|
-
}) : e.parentElement?.classList.contains("vistaview-next-btn") && e.addEventListener("click", () => {
|
|
339
|
-
this.next();
|
|
340
|
-
});
|
|
341
|
-
}), this.setIndexDisplay(), this.setCurrentDescription(), this.rootElement?.style.setProperty("--vistaview-current-index", `${this.currentIndex}`), this.containerElement.querySelectorAll(".vistaview-image-highres").forEach((e, c) => {
|
|
342
|
-
let l = e, u = this.elements[c].image;
|
|
343
|
-
if (u) {
|
|
344
|
-
let { width: e, height: c } = getFittedSize(u), d = Math.min(u.width, e), f = Math.min(u.height, c);
|
|
345
|
-
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`);
|
|
346
|
-
}
|
|
347
|
-
function d() {
|
|
348
|
-
l.classList.add("vistaview-image-loaded"), setTimeout(() => {
|
|
349
|
-
makeFullScreenContain(l);
|
|
350
|
-
}, 100), setTimeout(() => {
|
|
351
|
-
l.parentElement?.querySelector(".vistaview-image-lowres")?.classList.add("vistaview-image--hidden");
|
|
352
|
-
}, 500);
|
|
353
|
-
}
|
|
354
|
-
l.complete ? d() : l.onload = d;
|
|
355
|
-
}), this.setFullScreenContain = () => {
|
|
356
|
-
this.isActive && (this.containerElement?.querySelectorAll(".vistaview-image-highres"))?.forEach((e) => {
|
|
357
|
-
let c = e;
|
|
358
|
-
makeFullScreenContain(c, c.classList.contains("vistaview-image--zooming"));
|
|
359
|
-
});
|
|
360
|
-
}, window.addEventListener("resize", this.setFullScreenContain), this.setTouchActions(), this.onKeyDown = (e) => {
|
|
361
|
-
if (this.isActive) switch (e.key) {
|
|
362
|
-
case "ArrowLeft":
|
|
363
|
-
e.preventDefault(), this.prev();
|
|
364
|
-
break;
|
|
365
|
-
case "ArrowRight":
|
|
366
|
-
e.preventDefault(), this.next();
|
|
367
|
-
break;
|
|
368
|
-
case "ArrowUp":
|
|
369
|
-
e.preventDefault(), this.zoomIn();
|
|
370
|
-
break;
|
|
371
|
-
case "ArrowDown":
|
|
372
|
-
e.preventDefault(), this.zoomOut();
|
|
373
|
-
break;
|
|
374
|
-
case "Escape":
|
|
375
|
-
e.preventDefault(), this.close();
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
}, window.addEventListener("keydown", this.onKeyDown), setTimeout(() => {
|
|
379
|
-
this.rootElement && this.rootElement.classList.add("vistaview--initialized"), this.resetImageOpacity();
|
|
380
|
-
}, 33);
|
|
381
|
-
}
|
|
382
|
-
async close(e = !0) {
|
|
383
|
-
if (this.isActive) {
|
|
384
|
-
if (this.isActive = !1, e) {
|
|
385
|
-
let e = this.getAnimationDurationBase();
|
|
386
|
-
this.rootElement?.classList.add("vistaview--closing"), this.options.detectReducedMotion && this.isReducedMotion || await new Promise((c) => {
|
|
387
|
-
setTimeout(() => {
|
|
388
|
-
c(!0);
|
|
389
|
-
}, e * 1.5);
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
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;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
destroy() {
|
|
396
|
-
this.isActive && (this.close(!1), this.elements.forEach((e) => {
|
|
397
|
-
let c = e.anchor || e.image;
|
|
398
|
-
c && e.onClick && c.removeEventListener("click", e.onClick);
|
|
399
|
-
}));
|
|
400
|
-
}
|
|
401
|
-
view(e) {
|
|
402
|
-
if (this.isActive) {
|
|
403
|
-
if (e < 0 || e >= this.elements.length) throw Error("VistaView: Index out of bounds:" + e);
|
|
404
|
-
this.clearZoom(), this.currentIndex = e, this.resetImageOpacity(), this.setIndexDisplay(), this.setCurrentDescription(), this.setInitialProperties && this.setInitialProperties(), this.rootElement?.style.setProperty("--vistaview-current-index", `${this.currentIndex}`);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
next() {
|
|
408
|
-
this.isActive && this.view((this.currentIndex + 1) % this.elements.length);
|
|
409
|
-
}
|
|
410
|
-
prev() {
|
|
411
|
-
this.isActive && this.view((this.currentIndex - 1 + this.elements.length) % this.elements.length);
|
|
412
|
-
}
|
|
413
|
-
getCurrentIndex() {
|
|
414
|
-
return this.isActive ? this.currentIndex : -1;
|
|
415
|
-
}
|
|
416
|
-
}, toImage = (e) => {
|
|
417
|
-
let c = e instanceof HTMLImageElement ? e : e.querySelector("img");
|
|
418
|
-
return {
|
|
419
|
-
src: e.dataset.vistaviewSrc || e.getAttribute("href") || e.getAttribute("src") || "",
|
|
420
|
-
width: +(e.dataset.vistaviewWidth || c?.naturalWidth || 0),
|
|
421
|
-
height: +(e.dataset.vistaviewHeight || c?.naturalHeight || 0),
|
|
422
|
-
smallSrc: c?.src || e.dataset.vistaviewSmallsrc || e.getAttribute("src") || "",
|
|
423
|
-
alt: c?.alt || e.dataset.vistaviewAlt || e.getAttribute("alt") || "",
|
|
424
|
-
anchor: e instanceof HTMLAnchorElement ? e : void 0,
|
|
425
|
-
image: c || void 0
|
|
426
|
-
};
|
|
427
|
-
};
|
|
428
|
-
function vistaView({ parent: e, elements: c, ...l }) {
|
|
429
|
-
if (!e && !c) throw Error("No parent or elements");
|
|
430
|
-
let u;
|
|
431
|
-
if (e) {
|
|
432
|
-
let c = e.querySelector("img[data-vistaview-src]") ? "img[data-vistaview-src]" : "a[href]";
|
|
433
|
-
u = Array.from(e.querySelectorAll(c)).map(toImage);
|
|
434
|
-
} else if (typeof c == "string") u = Array.from(document.querySelectorAll(c)).map(toImage);
|
|
435
|
-
else if (c instanceof NodeList) u = Array.from(c).map(toImage);
|
|
436
|
-
else if (Array.isArray(c)) u = c;
|
|
437
|
-
else throw Error("Invalid elements");
|
|
438
|
-
if (!u.length) throw Error("No elements found");
|
|
439
|
-
let d = new VistaView(u, l);
|
|
440
|
-
return {
|
|
441
|
-
open: (e = 0) => d.open(e),
|
|
442
|
-
close: () => d.close(),
|
|
443
|
-
next: () => d.next(),
|
|
444
|
-
prev: () => d.prev(),
|
|
445
|
-
destroy: () => d.destroy(),
|
|
446
|
-
getCurrentIndex: () => d.getCurrentIndex(),
|
|
447
|
-
view: (e) => {
|
|
448
|
-
d.view(e);
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
export { DefaultOptions as n, getDownloadButton as r, vistaView as t };
|