Vote screen: ring keeps the wider column and title shares a line with the entry qr; camera zoom button where the phone supports it

This commit is contained in:
2026-11-17 12:08:25 +01:00
parent fbc12f84d9
commit 3efb80b802
3 changed files with 33 additions and 13 deletions
+17 -3
View File
@@ -104,14 +104,28 @@ function makeScanner(video, onToken, onOther) {
setTimeout(loop, Math.max(0, 66 - (performance.now() - t0)));
}
const swap = h("button", { class: "cam-switch", type: "button", "aria-label": "Changer de caméra", hidden: true }, icon("swap", 20));
video.parentElement.append(swap);
// sensor zoom (mostly android): a far ring gets real pixels instead of an upscaled 720p crop
const zoom = h("button", { class: "cam-zoom", type: "button", "aria-label": "Zoom", hidden: true }, "1×");
video.parentElement.append(swap, zoom);
let zooms = [1];
async function attach(s) {
stream = s;
const track = s.getVideoTracks()[0];
// not every browser knows focusMode, those ignore it
s.getVideoTracks()[0]?.applyConstraints({ advanced: [{ focusMode: "continuous" }] }).catch(() => {});
track?.applyConstraints({ advanced: [{ focusMode: "continuous" }] }).catch(() => {});
const cap = track?.getCapabilities?.().zoom;
zooms = cap && cap.max >= 1.5 ? [1, 2, 3].filter((z) => z >= cap.min && z <= cap.max) : [1];
zoom.hidden = zooms.length < 2;
zoom.textContent = "1×";
video.srcObject = s;
await video.play();
}
zoom.onclick = async () => {
const track = stream?.getVideoTracks()[0];
if (!track) return;
const next = zooms[(zooms.indexOf(+zoom.textContent.replace("×", "")) + 1) % zooms.length];
try { await track.applyConstraints({ advanced: [{ zoom: next }] }); zoom.textContent = `${next}×`; } catch { zoom.hidden = true; }
};
swap.onclick = async () => {
const cams = rankCameras(await videoInputs());
if (cams.length < 2) return;
@@ -146,7 +160,7 @@ function makeScanner(video, onToken, onOther) {
stream?.getTracks().forEach((t) => t.stop());
video.srcObject = null;
},
destroy() { swap.remove(); },
destroy() { swap.remove(); zoom.remove(); },
};
}