import '@fontsource/outfit/latin-400.css'; import '@fontsource/outfit/latin-500.css'; import '@fontsource/manrope/latin-400.css'; import '@fontsource/manrope/latin-500.css'; import '@fontsource/manrope/latin-700.css'; import './style.css'; import { siteConfig } from './site.config.js'; import { films } from './media.config.js'; import { mountFilm } from './film-player.js'; import { configurePublicLinks } from './public-links.js'; import { initHeroVisualizer } from './hero-visualizer.js'; configurePublicLinks(); // Load offscreen posters near the viewport, including stills for reduced motion. const posterObserver = new IntersectionObserver((entries) => { for (const entry of entries) { if (!entry.isIntersecting) continue; entry.target.poster = entry.target.dataset.poster; posterObserver.unobserve(entry.target); } }, { rootMargin: '250px 0px' }); document.querySelectorAll('video[data-poster]').forEach((player) => posterObserver.observe(player)); const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)'); const mediaBase = (publicUrl(siteConfig.visualizerMediaBaseUrl) || '/media').replace(/\/$/, ''); const loopSource = (name, size) => `${mediaBase}/loops/${name}-${size}.mp4`; const header = document.querySelector('#site-header'); const updateHeader = () => header.classList.toggle('scrolled', window.scrollY > 24); updateHeader(); window.addEventListener('scroll', updateHeader, { passive: true }); initHeroVisualizer(reducedMotion); // Silent visualizer loops elsewhere on the page play only while on screen. const loopVideos = new Set(); const loopObserver = new IntersectionObserver( (entries) => { entries.forEach((entry) => { const loop = entry.target; // Decode only loops that are meaningfully on screen to keep playback smooth. loop.dataset.visible = String(entry.intersectionRatio >= 0.3); syncLoop(loop); }); }, { threshold: [0, 0.3] }, ); function syncLoop(loop) { const shouldPlay = loop.dataset.visible === 'true' && !reducedMotion.matches && !document.hidden; if (!shouldPlay) { loop.pause(); return; } if (!loop.getAttribute('src')) { loop.preload = 'auto'; loop.src = loopSource(loop.dataset.loop, loop.dataset.size || 720); } loop.play().catch(() => {}); } document.querySelectorAll('video.loop').forEach((loop) => { loop.muted = true; loopVideos.add(loop); loopObserver.observe(loop); }); document.addEventListener('visibilitychange', () => loopVideos.forEach(syncLoop)); reducedMotion.addEventListener('change', () => loopVideos.forEach(syncLoop)); if (!reducedMotion.matches && 'IntersectionObserver' in window) { const revealObserver = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (!entry.isIntersecting) return; entry.target.classList.add('is-visible'); revealObserver.unobserve(entry.target); }); }, { threshold: 0.12 }, ); document .querySelectorAll( '.section-heading, .film-heading, .film-frame, .workflow-grid article, .app-shot, .studio-notes article, .style-media, .style-copy, .world, .export-copy, .format-demo, .walkthrough-media, .faq-intro, .faq-list, .download-inner', ) .forEach((element) => { element.classList.add('reveal'); revealObserver.observe(element); }); } const formats = { '16:9': { ratio: 16 / 9, label: 'Wide', dimensions: '3840 × 2160' }, '4:3': { ratio: 4 / 3, label: 'Landscape', dimensions: '2880 × 2160' }, '3:4': { ratio: 3 / 4, label: 'Portrait', dimensions: '2160 × 2880' }, '9:16': { ratio: 9 / 16, label: 'Phone', dimensions: '2160 × 3840' }, '1:1': { ratio: 1, label: 'Square', dimensions: '2160 × 2160' }, }; let activeFormat = '16:9'; const canvas = document.querySelector('#format-canvas'); const formatStage = document.querySelector('.format-stage'); function resizeCanvas() { const { ratio } = formats[activeFormat]; const style = getComputedStyle(formatStage); const horizontalPadding = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight); const verticalPadding = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom); const width = Math.min( formatStage.clientWidth - horizontalPadding, (formatStage.clientHeight - verticalPadding) * ratio, ); canvas.style.width = `${width}px`; canvas.style.aspectRatio = `${ratio}`; } new ResizeObserver(resizeCanvas).observe(formatStage); document.querySelectorAll('[data-format]').forEach((button) => { button.addEventListener('click', () => { activeFormat = button.dataset.format; const format = formats[activeFormat]; document .querySelectorAll('[data-format]') .forEach((item) => item.setAttribute('aria-pressed', String(item === button)), ); document.querySelector('#format-overlay').textContent = activeFormat; document.querySelector('#format-output').textContent = `${format.label} · ${format.dimensions} pixels at the 4K setting`; resizeCanvas(); }); }); const menuButton = document.querySelector('.menu-toggle'); const navigation = document.querySelector('#navigation'); function closeMenu() { navigation.classList.remove('open'); menuButton.setAttribute('aria-expanded', 'false'); menuButton.setAttribute('aria-label', 'Open navigation'); } menuButton.addEventListener('click', () => { const open = menuButton.getAttribute('aria-expanded') !== 'true'; menuButton.setAttribute('aria-expanded', String(open)); menuButton.setAttribute( 'aria-label', open ? 'Close navigation' : 'Open navigation', ); navigation.classList.toggle('open', open); }); navigation .querySelectorAll('a') .forEach((link) => link.addEventListener('click', closeMenu)); document.addEventListener('keydown', (event) => { if ( event.key === 'Escape' && menuButton.getAttribute('aria-expanded') === 'true' ) { closeMenu(); menuButton.focus(); } }); document.addEventListener('click', (event) => { if (!navigation.contains(event.target) && !menuButton.contains(event.target)) closeMenu(); }); const dialog = document.querySelector('#image-dialog'); document.querySelectorAll('[data-image]').forEach((button) => { button.addEventListener('click', () => { document.querySelector('#dialog-image').src = button.dataset.image; document.querySelector('#dialog-image').alt = button.querySelector('img').alt; document.querySelector('#image-dialog-caption').textContent = button.dataset.caption; dialog.showModal(); }); }); document .querySelector('.dialog-close') .addEventListener('click', () => dialog.close()); dialog.addEventListener('click', (event) => { if (event.target === dialog) dialog.close(); }); dialog.addEventListener('keydown', (event) => { if (event.key === 'Tab') { event.preventDefault(); dialog.querySelector('.dialog-close').focus(); } }); function publicUrl(value) { if (!value) return ''; // Only web URLs and site-relative media are usable public destinations. if ( value.startsWith('/') && !value.startsWith('//') && !/^\/(Users|Volumes|home|tmp)\//.test(value) ) return value; try { const url = new URL(value); return url.protocol === 'https:' ? url.href : ''; } catch { return ''; } } // 3D octagons behind the download section load only when it approaches the viewport. const octagonScene = document.querySelector('#octagon-scene'); let octagons; let octagonsVisible = false; const octagonObserver = new IntersectionObserver( async (entries) => { const visible = entries[0].isIntersecting; octagonsVisible = visible; if (visible && !octagons) { const { mountOctagons, supportsWebGL } = await import('./octagons.js'); if (!supportsWebGL()) { octagonObserver.disconnect(); octagonScene.remove(); return; } octagons = mountOctagons(octagonScene, { animate: () => !reducedMotion.matches && !document.hidden, }); const fallback = document.querySelector('.download-backdrop'); loopObserver.unobserve(fallback); loopVideos.delete(fallback); fallback.pause(); fallback.remove(); octagonScene.classList.add('ready'); } octagons?.setRunning(visible); }, { rootMargin: '300px 0px' }, ); octagonObserver.observe(octagonScene); document.addEventListener('visibilitychange', () => octagons?.setRunning(octagonsVisible), ); reducedMotion.addEventListener('change', () => { octagons?.setRunning(octagonsVisible); octagons?.renderStill(); }); // The films play from R2: a poster and play button first, the video on click. function configureFilms() { for (const selector of ['#feature-media', '#short-film-media']) { const placeholder = document.querySelector(`${selector} .film-placeholder`); if (placeholder) { loopObserver.unobserve(placeholder); loopVideos.delete(placeholder); placeholder.pause(); } } mountFilm(document.querySelector('#feature-media'), films.song, { buttonText: 'Play the music video' }); mountFilm(document.querySelector('#short-film-media'), films.short, { buttonText: 'Play the short film' }); mountFilm(document.querySelector('#walkthrough-media'), films.walkthrough, { buttonText: 'Watch the tutorial' }); document.querySelector('#walkthrough-transcript').hidden = false; } configureFilms();