/* Mailspring 2.0 launch page. * * - .demo-video figures (#views-demo, #cal-demo): screen recordings of the real app, made with * the app-mocking skill (.claude/skills/app-mocking, scenes/views-hero.mjs and * scenes/calendar.mjs), with captions cued to them from data-cues. * - The gallery's prompt tabs. * * All names and mail in the recordings are invented. */ (function () { "use strict"; var reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; /* ------------------------------------------------------------------ */ /* Demos: screen recordings of the real app */ /* ------------------------------------------------------------------ */ /* The recording plays only while it's on screen and the tab is visible. Captions follow * cue times logged while recording (data-cues: [[seconds, text], ...]). With reduced * motion it doesn't autoplay: it shows the finished Board and a Play button. */ function VideoDemo(figure) { var video = figure.querySelector("video"); var caption = figure.querySelector(".demo-caption-text"); var toggle = figure.querySelector(".demo-toggle"); var cues = JSON.parse(video.getAttribute("data-cues") || "[]"); var paused = reduceMotion; var visible = false; var current = -1; if (reduceMotion && video.getAttribute("data-poster-still")) { // Show the finished result, captioned for that moment, until someone presses Play. video.poster = video.getAttribute("data-poster-still"); var stillAt = Number(video.getAttribute("data-poster-still-time")) || 0; for (var c = 0; c < cues.length; c++) if (cues[c][0] <= stillAt) caption.textContent = cues[c][1]; } function sync() { var shouldPlay = visible && !paused && !document.hidden; if (shouldPlay && video.paused) { var played = video.play(); if (played && played.catch) played.catch(function () {}); } else if (!shouldPlay && !video.paused) { video.pause(); } toggle.textContent = paused ? "Play" : "Pause"; toggle.setAttribute("aria-pressed", String(paused)); figure.classList.toggle("is-paused", paused); } function updateCaption() { var t = video.currentTime; var index = 0; for (var i = 0; i < cues.length; i++) if (cues[i][0] <= t + 0.05) index = i; if (index === current || !cues.length) return; current = index; caption.style.opacity = "0"; setTimeout(function () { caption.textContent = cues[current][1]; caption.style.opacity = "1"; }, 180); } video.addEventListener("timeupdate", updateCaption); video.addEventListener("seeked", updateCaption); toggle.addEventListener("click", function () { paused = !paused; sync(); }); new IntersectionObserver( function (entries) { visible = entries[0].isIntersecting; sync(); }, { threshold: 0.25 } ).observe(video); document.addEventListener("visibilitychange", sync); sync(); } /* ------------------------------------------------------------------ */ /* Gallery tabs */ /* ------------------------------------------------------------------ */ function initGallery() { var tabs = Array.prototype.slice.call(document.querySelectorAll(".prompts [role=tab]")); var panel = document.getElementById("gallery-panel"); if (!tabs.length || !panel) return; var img = panel.querySelector("img"); var title = panel.querySelector(".gw-title"); // Warm the cache so switching feels instant. tabs.forEach(function (t) { new Image().src = "static/img/mailspring-2/views/" + t.dataset.view + ".webp"; }); function select(tab, focus) { tabs.forEach(function (t) { var on = t === tab; t.setAttribute("aria-selected", String(on)); t.tabIndex = on ? 0 : -1; }); if (focus) tab.focus(); panel.setAttribute("aria-labelledby", tab.id); title.textContent = tab.dataset.name; var src = "static/img/mailspring-2/views/" + tab.dataset.view + ".webp"; if (img.getAttribute("src") === src) return; img.classList.add("is-swapping"); setTimeout( function () { img.src = src; img.alt = "The " + tab.dataset.name + " View"; img.classList.remove("is-swapping"); }, reduceMotion ? 0 : 200 ); } tabs.forEach(function (tab, i) { tab.tabIndex = i === 0 ? 0 : -1; tab.addEventListener("click", function () { select(tab, false); }); tab.addEventListener("keydown", function (e) { var idx = tabs.indexOf(tab); var next = null; if (e.key === "ArrowDown" || e.key === "ArrowRight") next = tabs[(idx + 1) % tabs.length]; if (e.key === "ArrowUp" || e.key === "ArrowLeft") next = tabs[(idx - 1 + tabs.length) % tabs.length]; if (e.key === "Home") next = tabs[0]; if (e.key === "End") next = tabs[tabs.length - 1]; if (next) { e.preventDefault(); select(next, true); } }); }); } /* ------------------------------------------------------------------ */ function start() { initGallery(); var demos = document.querySelectorAll(".demo-video"); for (var i = 0; i < demos.length; i++) new VideoDemo(demos[i]); } if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start); else start(); })();