Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Existing images remain owned static assets with provenance. Replacing a photo in

The neutral ASCII earth sits directly on bone with Indonesia in SPE blue. Click/tap the globe or use Enter/Space to pause/resume; no visible caption or Pause footer remains. It stops offscreen/in background tabs and freezes under reduced motion. The same renderer generates the complete static no-JS frame during the build. Geography is derived from public-domain [Natural Earth](https://www.naturalearthdata.com/about/terms-of-use/) data supplied in the design handoff. Glyph dividers and arrow feedback remain in place. The header is sticky on every page; menus, skip links and anchors retain clearance.

Designer’s v3 text streams from 0–100% with a four-character alphanumeric tail, using final glyph rectangles without changing source layout. Designer’s v5 images in view start together: authentic prewarmed, paused Libraries.dev `pixels-mechanic` mosaics fade in for 400ms, then the final photos crossfade over 350ms. This is a 750ms compositor reveal, not a shortened native GPU dissolve. If a mosaic is not ready on entry, a concurrent 600ms clean fade prevents an invisible queue. Exact-pinned img-fx/Three packages load locally only for eligible viewport/nearby images (900px prewarm margin), sharing one WebGL renderer. Completed layers stay paused/hidden without replay. Semantic images and source text remain accessible beneath decorative overlays. Reduced motion, no JS, missing WebGL/observers, dependency failure, slow bootstrap and font failure show final plain content. Major-performance-caveat contexts and known software renderers (SwiftShader, llvmpipe, softpipe and Basic Render Driver) also show originals without loading the SDK: synchronous software-GPU compilation can block the page beyond any JavaScript safety timer. No video autoplays. Fonts are self-hosted Geist and Geist Mono.
Designer’s v3 text streams from 0–100% with a four-character alphanumeric tail, using final glyph rectangles without changing source layout. Designer’s v5 images in view reveal concurrently: each in-view image runs the real Libraries.dev `pixels-mechanic` GPU dissolve from img-fx, tuned from the stock ~2.6s down to 0.85s at 30fps, and every image starts the moment it enters the viewport (no queue, no waiting for the previous one). All instances share one WebGL renderer, so they render in the same frame loop. Mosaics prewarm within 320px of the viewport; if one isn't ready 320ms after entering view, that image does a concurrent 460ms clean fade instead. When the dissolve ends the real photo sits underneath and the overlay fades out over 150ms. Exact-pinned img-fx/Three packages load locally only for eligible images. Semantic images and source text remain accessible beneath decorative overlays. Reduced motion, no JS, missing WebGL/observers, dependency failure, slow bootstrap and font failure show final plain content. Major-performance-caveat contexts and known software renderers (SwiftShader, llvmpipe, softpipe and Basic Render Driver) also show originals without loading the SDK: synchronous software-GPU compilation can block the page beyond any JavaScript safety timer. No video autoplays. Fonts are self-hosted Geist and Geist Mono.

## Cloudflare deployment

Expand Down
214 changes: 109 additions & 105 deletions src/motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@
const running = new Map(),
seen = new WeakSet(),
stats = (window.__speMotion = { text: [], images: [], activeImages: 0 })
let frame = 0,
let imageObserver,
frame = 0,
textObserver,
imageObserver,
textEpoch = 0,
fontTimer = 0
const automated = () =>
navigator.webdriver === true || /HeadlessChrome/i.test(navigator.userAgent)
window.__speForceImageFx !== true &&
(navigator.webdriver === true || /HeadlessChrome/i.test(navigator.userAgent))
const enabled = () =>
!preference.matches &&
!automated() &&
Expand Down Expand Up @@ -431,6 +432,16 @@
})
.catch(stopText)
}
// ---- In-view image reveal -------------------------------------------
// Every image that enters the viewport gets its own Libraries.dev
// `pixels-mechanic` mosaic. All of them share one WebGL renderer inside
// img-fx and render in the same frame loop, so reveals run concurrently:
// nothing waits for a previous image. The dissolve itself is the library's
// real GPU reveal, just tuned to REVEAL_SECONDS (stock is ~2.6s).
const REVEAL_SECONDS = 0.85,
FRAME_RATE = 30,
PREWARM_MARGIN = '320px 0px',
READY_GRACE = 320
const images = [...document.querySelectorAll('main img')].filter(
(img) => !img.closest('.chapter,.chapter-emblem,.org-chart'),
),
Expand All @@ -439,6 +450,7 @@
inView = new Set(),
roots = new Set()
let capable, modules, prewarmObserver

function imageEnabled() {
if (
!enabled() ||
Expand Down Expand Up @@ -466,17 +478,32 @@
capable = false
}
}
return capable
return capable || window.__speForceImageFx === true
}
function loadImages() {
return (modules ??= Promise.all([
import('react'),
import('react-dom/client'),
import('img-fx'),
]).catch((error) => {
stopImages('unavailable')
throw error
}))
])
.then((loaded) => {
const fx = loaded[2]
// Tune once: shorter dissolve, smoother frame rate, cheap DPR.
fx.setMaxDpr(1)
fx.setFrameRate(FRAME_RATE)
Object.values(fx.PRESETS).forEach((preset) =>
Object.values(preset.modes).forEach((mode) => {
const reveal = mode.revealConfig
reveal.duration = reveal.pixDuration = reveal.dotDuration =
REVEAL_SECONDS
}),
)
return loaded
})
.catch((error) => {
stopImages('unavailable')
throw error
}))
}
function finishImage(img, state = 'final') {
const job = active.get(img)
Expand All @@ -485,15 +512,24 @@
revealed.add(img)
clearTimeout(job.timer)
clearTimeout(job.poll)
clearTimeout(job.warmTimer)
job.pause?.()
if (job.host) job.host.hidden = true
clearTimeout(job.grace)
active.delete(img)
stats.activeImages--
// Real photo goes in under the overlay first, then the overlay fades.
img.classList.remove('stream-image-pending', 'stream-image-enter')
if (job.host) {
job.host.classList.add('imgfx-leaving')
job.pause?.()
setTimeout(() => {
job.host.remove()
job.root?.unmount()
roots.delete(job)
}, 160)
}
stats.images.push({
src: img.src,
state,
native: !!job.native,
native: !!job.triggered && !!job.host,
revealStart: job.triggered,
completed: performance.now(),
preparation: Math.round(
Expand All @@ -518,57 +554,47 @@
finishImage(img, state)
})
}
// Start one image's reveal. Called for every in-view image at once.
function fire(job) {
if (job.done || job.triggered) return
const { img, host } = job
if (!imageEnabled() || document.hidden) return finishImage(img, 'static')
job.triggered = performance.now()
clearTimeout(job.grace)
clearTimeout(job.timer)
img.dataset.streamImage = 'revealing'
if (job.ready && job.trigger) {
const rect = img.getBoundingClientRect()
host.style.left = rect.left + scrollX + 'px'
host.style.top = rect.top + scrollY + 'px'
host.classList.add('imgfx-live')
job.resume?.()
// Let the unpaused instance render once before the reveal starts.
requestAnimationFrame(() => !job.done && job.trigger())
job.timer = setTimeout(
() => finishImage(img),
REVEAL_SECONDS * 1000 + 700,
)
} else {
// Mosaic not warm yet: a concurrent clean fade, never a queue.
job.skipped = true
job.pause?.()
if (host) host.hidden = true
img.classList.remove('stream-image-pending')
img.classList.add('stream-image-enter')
job.timer = setTimeout(() => finishImage(img), 460)
}
}
function pumpImages() {
if (!images.length || !imageEnabled() || document.hidden) return
const batch = [...inView]
.filter((img) => !revealed.has(img))
.sort((a, b) => {
const x = a.getBoundingClientRect(),
y = b.getBoundingClientRect()
return Math.abs(x.top - y.top) > 8 ? x.top - y.top : x.left - y.left
})
const jobs = batch.map((img) => {
inView.forEach((img) => {
if (revealed.has(img)) return
prepareImage(img)
revealed.add(img)
const job = active.get(img)
if (!job) return null
job.native = !!job.readyToReveal
if (!job.native) {
job.skipped = true
clearTimeout(job.poll)
clearTimeout(job.warmTimer)
job.pause?.()
if (job.host) job.host.hidden = true
}
return job
if (!job || job.triggered) return
if (job.ready) fire(job)
else if (!job.grace) job.grace = setTimeout(() => fire(job), READY_GRACE)
})
if (!jobs.length) return
requestAnimationFrame(() =>
jobs.forEach((job) => {
if (!job || job.done) return
const { img, host, photo } = job
if (!imageEnabled() || !inView.has(img) || document.hidden) {
finishImage(img, 'static')
return
}
job.triggered = performance.now()
img.dataset.streamImage = 'revealing'
if (job.native) {
const rect = img.getBoundingClientRect()
host.style.left = rect.left + scrollX + 'px'
host.style.top = rect.top + scrollY + 'px'
host.classList.add('imgfx-fading')
photo.addEventListener('animationend', () => finishImage(img), {
once: true,
})
} else {
img.classList.remove('stream-image-pending')
img.classList.add('stream-image-enter')
}
clearTimeout(job.timer)
job.timer = setTimeout(() => finishImage(img), job.native ? 750 : 600)
}),
)
}
function prepareImage(img) {
if (active.has(img)) return
Expand All @@ -579,57 +605,36 @@
const job = { img, start: performance.now(), done: false }
active.set(img, job)
stats.activeImages++
job.timer = setTimeout(() => finishImage(img, 'timeout'), 12000)
try {
const [react, dom, fx] = await loadImages()
await img.decode()
if (job.done || job.skipped) return
if (!imageEnabled() || document.hidden) {
finishImage(img, 'static')
return
}
if (!imageEnabled() || document.hidden) return finishImage(img, 'static')
const rect = img.getBoundingClientRect()
if (!rect.width || !rect.height) {
finishImage(img, 'static')
return
}
const React = react.default
fx.setMaxDpr(1)
const host = document.createElement('div')
const stage = document.createElement('div')
if (!rect.width || !rect.height) return finishImage(img, 'static')
const React = react.default,
style = getComputedStyle(img),
host = document.createElement('div'),
stage = document.createElement('div')
job.host = host
host.className = 'ascii-image-effect imgfx-reveal-host'
host.setAttribute('aria-hidden', 'true')
host.style.cssText = `left:${rect.left + scrollX}px;top:${scrollY + 100}px;width:${rect.width}px;height:${rect.height}px;border-radius:${getComputedStyle(img).borderRadius}`
host.style.cssText = `left:${rect.left + scrollX}px;top:${rect.top + scrollY}px;width:${rect.width}px;height:${rect.height}px;border-radius:${style.borderRadius}`
stage.className = 'ascii-image-stage'
stage.style.setProperty('--fx-width', rect.width + 'px')
stage.style.setProperty('--fx-height', rect.height + 'px')
host.append(stage)
document.body.append(host)
const photo = img.cloneNode()
photo.removeAttribute('id')
photo.removeAttribute('data-doop-id')
photo.removeAttribute('data-stream-image')
photo.className = 'imgfx-final-image'
photo.alt = ''
photo.loading = 'eager'
photo.style.cssText = `object-fit:${getComputedStyle(img).objectFit};object-position:${getComputedStyle(img).objectPosition}`
host.append(photo)
job.photo = photo
img.dataset.streamImage = 'preparing'
const width = Math.min(96, rect.width)
const height = (width * rect.height) / rect.width
// A small canvas is plenty for a pixel mosaic and keeps many
// concurrent reveals cheap; CSS scales it to the real box.
const width = Math.min(120, rect.width),
height = (width * rect.height) / rect.width
function Picture() {
const ref = React.useRef(null)
const [paused, pause] = React.useState(job.done || job.skipped)
const [paused, pause] = React.useState(false)
job.pause = () => pause(true)
React.useEffect(() => {
if (paused && job.warmed && !job.done && !job.skipped) {
job.readyToReveal = true
host.dataset.prepared = 'true'
clearTimeout(job.timer)
}
}, [paused])
job.resume = () => pause(false)
React.useEffect(() => {
job.trigger = () => ref.current?.triggerReveal({ hold: 'manual' })
}, [])
Expand All @@ -641,6 +646,9 @@
images: [img.currentSrc || img.src],
revealInitialDelay: 0,
paused,
onCycle: ({ phase }) => {
if (phase === 'visible' && job.triggered) finishImage(img)
},
},
React.createElement('div', { style: { width, height } }),
)
Expand All @@ -665,7 +673,7 @@
job.root.render(
React.createElement(Boundary, null, React.createElement(Picture)),
)
function ready() {
const ready = () => {
if (job.done || job.skipped) return
const shader = stage.querySelector('.image-gen-shader')
let painted = false
Expand All @@ -678,19 +686,12 @@
.data.some((value, index) => index % 4 === 3 && value > 0)
} catch {}
if (!painted || !job.trigger) {
job.poll = setTimeout(ready, 50)
return
}
if (!imageEnabled() || document.hidden) {
finishImage(img, 'static')
job.poll = setTimeout(ready, 40)
return
}
job.trigger()
job.warmTimer = setTimeout(() => {
if (job.done || job.skipped) return
job.warmed = true
job.pause?.()
}, 120)
job.ready = true
if (!inView.has(img)) job.pause?.()
if (inView.has(img)) fire(job)
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
}
ready()
} catch {
Expand All @@ -715,6 +716,9 @@
if (isIntersecting) inView.add(target)
else {
inView.delete(target)
const idle = active.get(target)
if (idle?.ready && !idle.triggered) idle.pause?.()
// Scrolled past mid-reveal: show the photo, drop the overlay.
if (active.get(target)?.triggered) finishImage(target, 'offscreen')
}
})
Expand All @@ -730,7 +734,7 @@
prewarmObserver.unobserve(target)
}
}),
{ rootMargin: '900px 0px', threshold: 0 },
{ rootMargin: PREWARM_MARGIN, threshold: 0 },
)
images
.filter((img) => !revealed.has(img))
Expand Down
33 changes: 10 additions & 23 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2184,12 +2184,12 @@ dt,
.button,
.chip,
.motion-pause {
transition: transform var(--motion-fast) var(--motion-ease);
transition: transform 150ms ease-out;
}
.button:active,
.chip:active,
.button:active:not(:disabled, [aria-disabled='true']),
.chip:active:not(:disabled, [aria-disabled='true']),
.motion-pause:active {
transform: scale(0.97);
transform: scale(0.96);
}
a:not(.brand):not(.button):not(.event-go):not(.skip) {
text-decoration: none;
Expand Down Expand Up @@ -2456,28 +2456,15 @@ body span.response-glyph {
}
.imgfx-reveal-host {
opacity: 0;
contain: layout paint;
}
.imgfx-reveal-host.imgfx-fading {
animation: imgfx-fade-in 400ms var(--motion-ease) both;
.imgfx-reveal-host.imgfx-live {
opacity: 1;
transition: opacity 80ms linear;
}
.imgfx-final-image {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
.imgfx-reveal-host.imgfx-leaving {
opacity: 0;
z-index: 2;
}
.imgfx-fading .imgfx-final-image {
animation: imgfx-fade-in 350ms var(--motion-ease) 400ms both;
}
@keyframes imgfx-fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
transition: opacity 150ms var(--motion-ease);
}
.ascii-image-stage .image-gen-root {
overflow: visible !important;
Expand Down
Loading