Upload 5 files
Browse files
custom_nodes/media_gallery/js/gallery.js
CHANGED
|
@@ -65,15 +65,22 @@ class Lightbox {
|
|
| 65 |
/**
|
| 66 |
* @param {(item: object) => void} onRatingChange called when the user rates
|
| 67 |
* an image from the lightbox; receives the mutated file object.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
*/
|
| 69 |
-
constructor(onRatingChange) {
|
| 70 |
this._items = [];
|
| 71 |
this._idx = 0;
|
| 72 |
this._onRatingChange = onRatingChange ?? null;
|
|
|
|
|
|
|
| 73 |
this._build();
|
| 74 |
}
|
| 75 |
|
| 76 |
_build() {
|
|
|
|
| 77 |
this._overlay = $el("div", {
|
| 78 |
style: {
|
| 79 |
display: "none",
|
|
@@ -90,15 +97,130 @@ class Lightbox {
|
|
| 90 |
},
|
| 91 |
});
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
this._wrap = $el("div", {
|
| 94 |
style: {
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
display: "flex",
|
| 98 |
alignItems: "center",
|
| 99 |
justifyContent: "center",
|
|
|
|
|
|
|
|
|
|
| 100 |
},
|
| 101 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
const closeBtn = $el("button", {
|
| 104 |
textContent: "β",
|
|
@@ -119,6 +241,25 @@ class Lightbox {
|
|
| 119 |
},
|
| 120 |
});
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
this._prevBtn = this._arrow("βΉ", "left", () => this._move(-1));
|
| 123 |
this._nextBtn = this._arrow("βΊ", "right", () => this._move(+1));
|
| 124 |
|
|
@@ -148,6 +289,27 @@ class Lightbox {
|
|
| 148 |
},
|
| 149 |
});
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
// ββ Star rating widget ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 152 |
this._lbStars = [];
|
| 153 |
this._lbStarBar = $el("div", {
|
|
@@ -202,6 +364,29 @@ class Lightbox {
|
|
| 202 |
this._lbStarBar.addEventListener("mouseleave", () => refreshLbStars());
|
| 203 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
const infoBar = $el(
|
| 206 |
"div",
|
| 207 |
{
|
|
@@ -223,12 +408,18 @@ class Lightbox {
|
|
| 223 |
this._nameEl,
|
| 224 |
this._metaEl,
|
| 225 |
this._lbStarBar,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
this._dlBtn,
|
| 227 |
this._countEl,
|
| 228 |
);
|
| 229 |
|
| 230 |
this._overlay.append(
|
| 231 |
this._wrap,
|
|
|
|
|
|
|
| 232 |
closeBtn,
|
| 233 |
this._prevBtn,
|
| 234 |
this._nextBtn,
|
|
@@ -238,9 +429,21 @@ class Lightbox {
|
|
| 238 |
|
| 239 |
document.addEventListener("keydown", (e) => {
|
| 240 |
if (this._overlay.style.display === "none") return;
|
| 241 |
-
|
| 242 |
-
if (e.key === "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
if (e.key === "Escape") this.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
});
|
| 245 |
}
|
| 246 |
|
|
@@ -267,6 +470,17 @@ class Lightbox {
|
|
| 267 |
});
|
| 268 |
}
|
| 269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
open(items, index) {
|
| 271 |
this._items = items;
|
| 272 |
this._idx = index;
|
|
@@ -275,7 +489,9 @@ class Lightbox {
|
|
| 275 |
|
| 276 |
close() {
|
| 277 |
this._overlay.style.display = "none";
|
| 278 |
-
this.
|
|
|
|
|
|
|
| 279 |
}
|
| 280 |
|
| 281 |
_move(dir) {
|
|
@@ -294,14 +510,16 @@ class Lightbox {
|
|
| 294 |
this._nameEl.textContent = item.filename;
|
| 295 |
this._metaEl.textContent = `${fmtDate(item.mtime)} β’ ${fmtBytes(item.size)}`;
|
| 296 |
this._refreshLbStars();
|
|
|
|
|
|
|
| 297 |
|
| 298 |
const src = viewURL(item.filename, item.subfolder);
|
| 299 |
this._dlBtn.href = src;
|
| 300 |
this._dlBtn.download = item.filename;
|
| 301 |
|
| 302 |
-
this.
|
| 303 |
if (item.kind === "video") {
|
| 304 |
-
this.
|
| 305 |
$el("video", {
|
| 306 |
src,
|
| 307 |
controls: true,
|
|
@@ -310,9 +528,10 @@ class Lightbox {
|
|
| 310 |
}),
|
| 311 |
);
|
| 312 |
} else {
|
| 313 |
-
this.
|
| 314 |
$el("img", {
|
| 315 |
src,
|
|
|
|
| 316 |
style: {
|
| 317 |
maxWidth: "90vw",
|
| 318 |
maxHeight: "80vh",
|
|
@@ -323,6 +542,102 @@ class Lightbox {
|
|
| 323 |
);
|
| 324 |
}
|
| 325 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
}
|
| 327 |
|
| 328 |
// βββ Gallery Panel ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -342,10 +657,19 @@ class GalleryPanel {
|
|
| 342 |
this._selectMode = false;
|
| 343 |
this._selected = new Set();
|
| 344 |
this._loading = false;
|
| 345 |
-
this._lightbox = new Lightbox(
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
|
| 350 |
this._build();
|
| 351 |
this.refresh();
|
|
@@ -808,6 +1132,8 @@ class GalleryPanel {
|
|
| 808 |
}
|
| 809 |
this._tileRefs.get(key)?.applySelection(this._selected.has(key), true);
|
| 810 |
this._updateSelectBar();
|
|
|
|
|
|
|
| 811 |
}
|
| 812 |
|
| 813 |
_selectAll() {
|
|
@@ -1033,15 +1359,15 @@ class GalleryPanel {
|
|
| 1033 |
position: "absolute",
|
| 1034 |
top: "5px",
|
| 1035 |
right: "5px",
|
| 1036 |
-
width: "
|
| 1037 |
-
height: "
|
| 1038 |
borderRadius: "50%",
|
| 1039 |
-
border: "
|
| 1040 |
-
background: "rgba(20,20,20,0.
|
| 1041 |
display: "none",
|
| 1042 |
alignItems: "center",
|
| 1043 |
justifyContent: "center",
|
| 1044 |
-
fontSize: "
|
| 1045 |
fontWeight: "bold",
|
| 1046 |
color: "#fff",
|
| 1047 |
zIndex: "3",
|
|
|
|
| 65 |
/**
|
| 66 |
* @param {(item: object) => void} onRatingChange called when the user rates
|
| 67 |
* an image from the lightbox; receives the mutated file object.
|
| 68 |
+
* @param {(item: object) => void} onToggleSelect called when the user selects
|
| 69 |
+
* or deselects the current item from inside the lightbox.
|
| 70 |
+
* @param {(item: object) => boolean} isSelected returns whether the item is
|
| 71 |
+
* currently selected in the gallery.
|
| 72 |
*/
|
| 73 |
+
constructor(onRatingChange, onToggleSelect, isSelected) {
|
| 74 |
this._items = [];
|
| 75 |
this._idx = 0;
|
| 76 |
this._onRatingChange = onRatingChange ?? null;
|
| 77 |
+
this._onToggleSelect = onToggleSelect ?? null;
|
| 78 |
+
this._isSelected = isSelected ?? (() => false);
|
| 79 |
this._build();
|
| 80 |
}
|
| 81 |
|
| 82 |
_build() {
|
| 83 |
+
this._bgSolid = false; // false = semi-transparent, true = solid
|
| 84 |
this._overlay = $el("div", {
|
| 85 |
style: {
|
| 86 |
display: "none",
|
|
|
|
| 97 |
},
|
| 98 |
});
|
| 99 |
|
| 100 |
+
// zoom / pan state
|
| 101 |
+
this._zoom = 1;
|
| 102 |
+
this._panX = 0;
|
| 103 |
+
this._panY = 0;
|
| 104 |
+
this._isPanning = false;
|
| 105 |
+
this._panStart = null; // { x, y, panX, panY }
|
| 106 |
+
this._pinchDist = null; // last pinch distance
|
| 107 |
+
this._pinchMid = null; // last pinch midpoint in wrap-local coords
|
| 108 |
+
|
| 109 |
this._wrap = $el("div", {
|
| 110 |
style: {
|
| 111 |
+
width: "90vw",
|
| 112 |
+
height: "80vh",
|
| 113 |
+
display: "flex",
|
| 114 |
+
alignItems: "center",
|
| 115 |
+
justifyContent: "center",
|
| 116 |
+
overflow: "hidden",
|
| 117 |
+
position: "relative",
|
| 118 |
+
cursor: "default",
|
| 119 |
+
},
|
| 120 |
+
});
|
| 121 |
+
|
| 122 |
+
// Inner element that receives CSS transform for zoom/pan
|
| 123 |
+
this._zoomEl = $el("div", {
|
| 124 |
+
style: {
|
| 125 |
display: "flex",
|
| 126 |
alignItems: "center",
|
| 127 |
justifyContent: "center",
|
| 128 |
+
transformOrigin: "center center",
|
| 129 |
+
userSelect: "none",
|
| 130 |
+
willChange: "transform",
|
| 131 |
},
|
| 132 |
});
|
| 133 |
+
this._wrap.appendChild(this._zoomEl);
|
| 134 |
+
|
| 135 |
+
// Zoom level badge (fades in/out)
|
| 136 |
+
this._zoomBadge = $el("div", {
|
| 137 |
+
style: {
|
| 138 |
+
position: "absolute",
|
| 139 |
+
top: "54px",
|
| 140 |
+
left: "50%",
|
| 141 |
+
transform: "translateX(-50%)",
|
| 142 |
+
background: "rgba(0,0,0,0.7)",
|
| 143 |
+
color: "#ddd",
|
| 144 |
+
borderRadius: "20px",
|
| 145 |
+
padding: "3px 12px",
|
| 146 |
+
fontSize: "12px",
|
| 147 |
+
pointerEvents: "none",
|
| 148 |
+
opacity: "0",
|
| 149 |
+
transition: "opacity 0.25s",
|
| 150 |
+
zIndex: "2",
|
| 151 |
+
whiteSpace: "nowrap",
|
| 152 |
+
},
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
// ββ Mouse drag (pan) ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 156 |
+
this._wrap.addEventListener("mousedown", (e) => {
|
| 157 |
+
if (e.button !== 0 || this._zoom <= 1) return;
|
| 158 |
+
e.preventDefault();
|
| 159 |
+
this._isPanning = true;
|
| 160 |
+
this._panStart = { x: e.clientX, y: e.clientY, panX: this._panX, panY: this._panY };
|
| 161 |
+
this._wrap.style.cursor = "grabbing";
|
| 162 |
+
});
|
| 163 |
+
window.addEventListener("mousemove", (e) => {
|
| 164 |
+
if (!this._isPanning) return;
|
| 165 |
+
this._panX = this._panStart.panX + (e.clientX - this._panStart.x);
|
| 166 |
+
this._panY = this._panStart.panY + (e.clientY - this._panStart.y);
|
| 167 |
+
this._applyTransform();
|
| 168 |
+
});
|
| 169 |
+
window.addEventListener("mouseup", () => {
|
| 170 |
+
if (!this._isPanning) return;
|
| 171 |
+
this._isPanning = false;
|
| 172 |
+
this._wrap.style.cursor = this._zoom > 1 ? "grab" : "default";
|
| 173 |
+
});
|
| 174 |
+
|
| 175 |
+
// ββ Wheel zoom (pinch on trackpad = ctrlKey, regular scroll ignored) βββββ
|
| 176 |
+
this._wrap.addEventListener("wheel", (e) => {
|
| 177 |
+
if (!e.ctrlKey) return; // only respond to pinch, not scroll
|
| 178 |
+
e.preventDefault();
|
| 179 |
+
const factor = e.deltaY < 0 ? 1.12 : 1 / 1.12;
|
| 180 |
+
this._zoomAt(factor, e.clientX, e.clientY);
|
| 181 |
+
}, { passive: false });
|
| 182 |
+
|
| 183 |
+
// ββ Double-click to reset ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 184 |
+
this._wrap.addEventListener("dblclick", () => this._resetZoom());
|
| 185 |
+
|
| 186 |
+
// ββ Touch: pinch + pan ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 187 |
+
this._wrap.addEventListener("touchstart", (e) => {
|
| 188 |
+
e.preventDefault();
|
| 189 |
+
if (e.touches.length === 2) {
|
| 190 |
+
this._pinchDist = this._touchDist(e.touches);
|
| 191 |
+
this._pinchMid = this._touchMidLocal(e.touches);
|
| 192 |
+
} else if (e.touches.length === 1) {
|
| 193 |
+
this._isPanning = true;
|
| 194 |
+
this._panStart = {
|
| 195 |
+
x: e.touches[0].clientX, y: e.touches[0].clientY,
|
| 196 |
+
panX: this._panX, panY: this._panY,
|
| 197 |
+
};
|
| 198 |
+
}
|
| 199 |
+
}, { passive: false });
|
| 200 |
+
|
| 201 |
+
this._wrap.addEventListener("touchmove", (e) => {
|
| 202 |
+
e.preventDefault();
|
| 203 |
+
if (e.touches.length === 2) {
|
| 204 |
+
const newDist = this._touchDist(e.touches);
|
| 205 |
+
const newMid = this._touchMidLocal(e.touches);
|
| 206 |
+
if (this._pinchDist && newDist > 0) {
|
| 207 |
+
const factor = newDist / this._pinchDist;
|
| 208 |
+
const midClient = this._touchMidClient(e.touches);
|
| 209 |
+
this._zoomAt(factor, midClient.x, midClient.y);
|
| 210 |
+
}
|
| 211 |
+
this._pinchDist = newDist;
|
| 212 |
+
this._pinchMid = newMid;
|
| 213 |
+
} else if (e.touches.length === 1 && this._isPanning) {
|
| 214 |
+
this._panX = this._panStart.panX + (e.touches[0].clientX - this._panStart.x);
|
| 215 |
+
this._panY = this._panStart.panY + (e.touches[0].clientY - this._panStart.y);
|
| 216 |
+
this._applyTransform();
|
| 217 |
+
}
|
| 218 |
+
}, { passive: false });
|
| 219 |
+
|
| 220 |
+
this._wrap.addEventListener("touchend", (e) => {
|
| 221 |
+
if (e.touches.length < 2) this._pinchDist = null;
|
| 222 |
+
if (e.touches.length === 0) this._isPanning = false;
|
| 223 |
+
});
|
| 224 |
|
| 225 |
const closeBtn = $el("button", {
|
| 226 |
textContent: "β",
|
|
|
|
| 241 |
},
|
| 242 |
});
|
| 243 |
|
| 244 |
+
this._bgBtn = $el("button", {
|
| 245 |
+
textContent: "β",
|
| 246 |
+
title: "Toggle background: solid / transparent (B)",
|
| 247 |
+
onclick: (e) => { e.stopPropagation(); this._toggleBg(); },
|
| 248 |
+
style: {
|
| 249 |
+
position: "absolute",
|
| 250 |
+
top: "14px",
|
| 251 |
+
left: "16px",
|
| 252 |
+
background: "rgba(50,50,50,0.85)",
|
| 253 |
+
color: "#ddd",
|
| 254 |
+
border: "none",
|
| 255 |
+
borderRadius: "6px",
|
| 256 |
+
padding: "5px 10px",
|
| 257 |
+
fontSize: "15px",
|
| 258 |
+
cursor: "pointer",
|
| 259 |
+
zIndex: "1",
|
| 260 |
+
},
|
| 261 |
+
});
|
| 262 |
+
|
| 263 |
this._prevBtn = this._arrow("βΉ", "left", () => this._move(-1));
|
| 264 |
this._nextBtn = this._arrow("βΊ", "right", () => this._move(+1));
|
| 265 |
|
|
|
|
| 289 |
},
|
| 290 |
});
|
| 291 |
|
| 292 |
+
// ββ Select button βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 293 |
+
this._selectBtn = $el("button", {
|
| 294 |
+
textContent: "β Select",
|
| 295 |
+
title: "Select this image (S / Space)",
|
| 296 |
+
onclick: (e) => {
|
| 297 |
+
e.stopPropagation();
|
| 298 |
+
this._toggleCurrentSelect();
|
| 299 |
+
},
|
| 300 |
+
style: {
|
| 301 |
+
background: "#2c2c2c",
|
| 302 |
+
color: "#bbb",
|
| 303 |
+
border: "1px solid #444",
|
| 304 |
+
borderRadius: "5px",
|
| 305 |
+
padding: "3px 10px",
|
| 306 |
+
fontSize: "12px",
|
| 307 |
+
cursor: "pointer",
|
| 308 |
+
flexShrink: "0",
|
| 309 |
+
transition: "background 0.15s, color 0.15s, border-color 0.15s",
|
| 310 |
+
},
|
| 311 |
+
});
|
| 312 |
+
|
| 313 |
// ββ Star rating widget ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 314 |
this._lbStars = [];
|
| 315 |
this._lbStarBar = $el("div", {
|
|
|
|
| 364 |
this._lbStarBar.addEventListener("mouseleave", () => refreshLbStars());
|
| 365 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 366 |
|
| 367 |
+
// ββ Zoom in / out / reset buttons ββββββββββββββββββββββββββββββββββββββββ
|
| 368 |
+
const mkZoomBtn = (label, title, action) => $el("button", {
|
| 369 |
+
textContent: label,
|
| 370 |
+
title,
|
| 371 |
+
onclick: (e) => { e.stopPropagation(); action(); },
|
| 372 |
+
style: {
|
| 373 |
+
background: "#2c2c2c",
|
| 374 |
+
color: "#bbb",
|
| 375 |
+
border: "1px solid #444",
|
| 376 |
+
borderRadius: "5px",
|
| 377 |
+
padding: "3px 9px",
|
| 378 |
+
fontSize: "13px",
|
| 379 |
+
lineHeight: "1",
|
| 380 |
+
cursor: "pointer",
|
| 381 |
+
flexShrink: "0",
|
| 382 |
+
transition: "background 0.12s",
|
| 383 |
+
},
|
| 384 |
+
});
|
| 385 |
+
|
| 386 |
+
this._zoomInBtn = mkZoomBtn("+", "Zoom in (+)", () => this._zoomAt(1.3, null, null));
|
| 387 |
+
this._zoomOutBtn = mkZoomBtn("β", "Zoom out (β)", () => this._zoomAt(1 / 1.3, null, null));
|
| 388 |
+
this._resetZoomBtn = mkZoomBtn("β 1Γ", "Reset zoom (0)", () => this._resetZoom());
|
| 389 |
+
|
| 390 |
const infoBar = $el(
|
| 391 |
"div",
|
| 392 |
{
|
|
|
|
| 408 |
this._nameEl,
|
| 409 |
this._metaEl,
|
| 410 |
this._lbStarBar,
|
| 411 |
+
this._selectBtn,
|
| 412 |
+
this._zoomOutBtn,
|
| 413 |
+
this._resetZoomBtn,
|
| 414 |
+
this._zoomInBtn,
|
| 415 |
this._dlBtn,
|
| 416 |
this._countEl,
|
| 417 |
);
|
| 418 |
|
| 419 |
this._overlay.append(
|
| 420 |
this._wrap,
|
| 421 |
+
this._zoomBadge,
|
| 422 |
+
this._bgBtn,
|
| 423 |
closeBtn,
|
| 424 |
this._prevBtn,
|
| 425 |
this._nextBtn,
|
|
|
|
| 429 |
|
| 430 |
document.addEventListener("keydown", (e) => {
|
| 431 |
if (this._overlay.style.display === "none") return;
|
| 432 |
+
// Zoom keys
|
| 433 |
+
if (e.key === "+" || e.key === "=") { e.preventDefault(); this._zoomAt(1.3, null, null); return; }
|
| 434 |
+
if (e.key === "-") { e.preventDefault(); this._zoomAt(1 / 1.3, null, null); return; }
|
| 435 |
+
if (e.key === "0") { e.preventDefault(); this._resetZoom(); return; }
|
| 436 |
+
// Nav β skip when panning to avoid conflict
|
| 437 |
+
if (!this._isPanning) {
|
| 438 |
+
if (e.key === "ArrowLeft" || e.key === "a") this._move(-1);
|
| 439 |
+
if (e.key === "ArrowRight" || e.key === "d") this._move(+1);
|
| 440 |
+
}
|
| 441 |
if (e.key === "Escape") this.close();
|
| 442 |
+
if (e.key === "s" || e.key === "S" || e.key === " ") {
|
| 443 |
+
e.preventDefault();
|
| 444 |
+
this._toggleCurrentSelect();
|
| 445 |
+
}
|
| 446 |
+
if (e.key === "b" || e.key === "B") this._toggleBg();
|
| 447 |
});
|
| 448 |
}
|
| 449 |
|
|
|
|
| 470 |
});
|
| 471 |
}
|
| 472 |
|
| 473 |
+
_toggleBg() {
|
| 474 |
+
this._bgSolid = !this._bgSolid;
|
| 475 |
+
this._overlay.style.background = this._bgSolid
|
| 476 |
+
? "#000"
|
| 477 |
+
: "rgba(0,0,0,0.92)";
|
| 478 |
+
this._bgBtn.textContent = this._bgSolid ? "β" : "β";
|
| 479 |
+
this._bgBtn.title = this._bgSolid
|
| 480 |
+
? "Background: solid β click or press B for transparent"
|
| 481 |
+
: "Background: transparent β click or press B for solid";
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
open(items, index) {
|
| 485 |
this._items = items;
|
| 486 |
this._idx = index;
|
|
|
|
| 489 |
|
| 490 |
close() {
|
| 491 |
this._overlay.style.display = "none";
|
| 492 |
+
this._zoomEl.innerHTML = "";
|
| 493 |
+
this._isPanning = false;
|
| 494 |
+
this._pinchDist = null;
|
| 495 |
}
|
| 496 |
|
| 497 |
_move(dir) {
|
|
|
|
| 510 |
this._nameEl.textContent = item.filename;
|
| 511 |
this._metaEl.textContent = `${fmtDate(item.mtime)} β’ ${fmtBytes(item.size)}`;
|
| 512 |
this._refreshLbStars();
|
| 513 |
+
this._syncSelectBtn();
|
| 514 |
+
this._resetZoom(false); // reset zoom without the badge flash on navigation
|
| 515 |
|
| 516 |
const src = viewURL(item.filename, item.subfolder);
|
| 517 |
this._dlBtn.href = src;
|
| 518 |
this._dlBtn.download = item.filename;
|
| 519 |
|
| 520 |
+
this._zoomEl.innerHTML = "";
|
| 521 |
if (item.kind === "video") {
|
| 522 |
+
this._zoomEl.appendChild(
|
| 523 |
$el("video", {
|
| 524 |
src,
|
| 525 |
controls: true,
|
|
|
|
| 528 |
}),
|
| 529 |
);
|
| 530 |
} else {
|
| 531 |
+
this._zoomEl.appendChild(
|
| 532 |
$el("img", {
|
| 533 |
src,
|
| 534 |
+
draggable: false,
|
| 535 |
style: {
|
| 536 |
maxWidth: "90vw",
|
| 537 |
maxHeight: "80vh",
|
|
|
|
| 542 |
);
|
| 543 |
}
|
| 544 |
}
|
| 545 |
+
|
| 546 |
+
// ββ Zoom helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 547 |
+
|
| 548 |
+
/** Apply current zoom + pan as a CSS transform. */
|
| 549 |
+
_applyTransform() {
|
| 550 |
+
this._zoomEl.style.transform =
|
| 551 |
+
`translate(${this._panX}px, ${this._panY}px) scale(${this._zoom})`;
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
/**
|
| 555 |
+
* Zoom by `factor` centered on client point (cx, cy).
|
| 556 |
+
* Pass null for cx/cy to zoom around the wrap centre.
|
| 557 |
+
*/
|
| 558 |
+
_zoomAt(factor, cx, cy) {
|
| 559 |
+
const rect = this._wrap.getBoundingClientRect();
|
| 560 |
+
const ox = cx != null ? cx - (rect.left + rect.width / 2) : 0;
|
| 561 |
+
const oy = cy != null ? cy - (rect.top + rect.height / 2) : 0;
|
| 562 |
+
|
| 563 |
+
const newZoom = Math.max(0.5, Math.min(12, this._zoom * factor));
|
| 564 |
+
const ratio = newZoom / this._zoom;
|
| 565 |
+
|
| 566 |
+
// Keep the pointer position fixed under the cursor
|
| 567 |
+
this._panX = ox + (this._panX - ox) * ratio;
|
| 568 |
+
this._panY = oy + (this._panY - oy) * ratio;
|
| 569 |
+
this._zoom = newZoom;
|
| 570 |
+
|
| 571 |
+
this._applyTransform();
|
| 572 |
+
this._wrap.style.cursor = this._zoom > 1 ? "grab" : "default";
|
| 573 |
+
this._showZoomBadge();
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
/** Reset zoom and pan to 1Γ identity. */
|
| 577 |
+
_resetZoom(showBadge = true) {
|
| 578 |
+
this._zoom = 1;
|
| 579 |
+
this._panX = 0;
|
| 580 |
+
this._panY = 0;
|
| 581 |
+
this._applyTransform();
|
| 582 |
+
this._wrap.style.cursor = "default";
|
| 583 |
+
if (showBadge) this._showZoomBadge();
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
/** Briefly show the current zoom level in a badge. */
|
| 587 |
+
_showZoomBadge() {
|
| 588 |
+
clearTimeout(this._zoomBadgeTimer);
|
| 589 |
+
this._zoomBadge.textContent =
|
| 590 |
+
this._zoom === 1 ? "1Γ (reset)" : `${this._zoom.toFixed(2)}Γ`;
|
| 591 |
+
this._zoomBadge.style.opacity = "1";
|
| 592 |
+
this._zoomBadgeTimer = setTimeout(() => {
|
| 593 |
+
this._zoomBadge.style.opacity = "0";
|
| 594 |
+
}, 900);
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
// ββ Touch utilities βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 598 |
+
|
| 599 |
+
_touchDist(touches) {
|
| 600 |
+
const dx = touches[0].clientX - touches[1].clientX;
|
| 601 |
+
const dy = touches[0].clientY - touches[1].clientY;
|
| 602 |
+
return Math.hypot(dx, dy);
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
_touchMidClient(touches) {
|
| 606 |
+
return {
|
| 607 |
+
x: (touches[0].clientX + touches[1].clientX) / 2,
|
| 608 |
+
y: (touches[0].clientY + touches[1].clientY) / 2,
|
| 609 |
+
};
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
_touchMidLocal(touches) {
|
| 613 |
+
const rect = this._wrap.getBoundingClientRect();
|
| 614 |
+
const mid = this._touchMidClient(touches);
|
| 615 |
+
return { x: mid.x - rect.left, y: mid.y - rect.top };
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
/** Update the Select button to reflect current item's selection state. */
|
| 619 |
+
_syncSelectBtn() {
|
| 620 |
+
const item = this._items[this._idx];
|
| 621 |
+
if (!item) return;
|
| 622 |
+
const sel = this._isSelected(item);
|
| 623 |
+
this._selectBtn.textContent = sel ? "β Selected" : "β Select";
|
| 624 |
+
this._selectBtn.style.background = sel ? "#0e2a4a" : "#2c2c2c";
|
| 625 |
+
this._selectBtn.style.color = sel ? "#5b9bd5" : "#bbb";
|
| 626 |
+
this._selectBtn.style.borderColor = sel ? "#1a4a7a" : "#444";
|
| 627 |
+
}
|
| 628 |
+
|
| 629 |
+
/** Toggle selection for the currently viewed item and refresh UI. */
|
| 630 |
+
_toggleCurrentSelect() {
|
| 631 |
+
const item = this._items[this._idx];
|
| 632 |
+
if (!item || !this._onToggleSelect) return;
|
| 633 |
+
this._onToggleSelect(item);
|
| 634 |
+
this._syncSelectBtn();
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
/** Called by GalleryPanel when external selection state changes. */
|
| 638 |
+
syncSelectState() {
|
| 639 |
+
if (this._overlay.style.display !== "none") this._syncSelectBtn();
|
| 640 |
+
}
|
| 641 |
}
|
| 642 |
|
| 643 |
// βββ Gallery Panel ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 657 |
this._selectMode = false;
|
| 658 |
this._selected = new Set();
|
| 659 |
this._loading = false;
|
| 660 |
+
this._lightbox = new Lightbox(
|
| 661 |
+
(file) => {
|
| 662 |
+
this._saveRating(file);
|
| 663 |
+
this._tileRefs.get(fileKey(file))?.syncRating();
|
| 664 |
+
},
|
| 665 |
+
(file) => {
|
| 666 |
+
// Auto-enter select mode on first selection from lightbox
|
| 667 |
+
if (!this._selectMode) this._enterSelectMode();
|
| 668 |
+
this._toggleSelect(fileKey(file));
|
| 669 |
+
this._lightbox.syncSelectState();
|
| 670 |
+
},
|
| 671 |
+
(file) => this._selected.has(fileKey(file)),
|
| 672 |
+
);
|
| 673 |
|
| 674 |
this._build();
|
| 675 |
this.refresh();
|
|
|
|
| 1132 |
}
|
| 1133 |
this._tileRefs.get(key)?.applySelection(this._selected.has(key), true);
|
| 1134 |
this._updateSelectBar();
|
| 1135 |
+
// Auto-exit select mode when the last selection is cleared
|
| 1136 |
+
if (this._selected.size === 0) this._exitSelectMode();
|
| 1137 |
}
|
| 1138 |
|
| 1139 |
_selectAll() {
|
|
|
|
| 1359 |
position: "absolute",
|
| 1360 |
top: "5px",
|
| 1361 |
right: "5px",
|
| 1362 |
+
width: "26px",
|
| 1363 |
+
height: "26px",
|
| 1364 |
borderRadius: "50%",
|
| 1365 |
+
border: "2px solid rgba(200,200,200,0.45)",
|
| 1366 |
+
background: "rgba(20,20,20,0.65)",
|
| 1367 |
display: "none",
|
| 1368 |
alignItems: "center",
|
| 1369 |
justifyContent: "center",
|
| 1370 |
+
fontSize: "14px",
|
| 1371 |
fontWeight: "bold",
|
| 1372 |
color: "#fff",
|
| 1373 |
zIndex: "3",
|