feat(core): add render-function adapter for time-driven compositions#1640
Open
iret77 wants to merge 1 commit into
Open
feat(core): add render-function adapter for time-driven compositions#1640iret77 wants to merge 1 commit into
iret77 wants to merge 1 commit into
Conversation
Compositions whose visual state is a pure function of time — a hand-rolled clock, a framework state timeline, or a canvas/demoscene loop — register no GSAP timeline and use none of the existing library adapters, so __hf.seek(t) has nothing to drive and capture yields blank frames. The requestAnimationFrame loop they use for live playback does not advance under deterministic capture. Add a render-function adapter: the composition pushes render(timeSeconds) callbacks onto window.__hfRender and the runtime invokes them with the exact composition time for every captured frame. Mirrors the current time onto window.__hfTime for poll-style draw helpers. Follows the existing registry-array pattern (__hfLottie/__hfAnime/__hfMapbox): lazy discover, per-callback error isolation on seek, no-op pause, and a snapshot of the callback list before iteration. Pure no-op when no callback is registered, so existing compositions are unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a render-function adapter (
render-fn) so compositions whose visualstate is a pure function of time can render deterministically without an
animation library.
Today's adapters cover GSAP, WAAPI/CSS, anime.js, Lottie, and the GPU/map
libraries. A composition that draws each frame from a single clock value — a
hand-rolled clock, a React (or other framework) state timeline, or a
<canvas>/ demoscene loop — registers no timeline and uses none of thoselibraries, so
__hf.seek(t)has nothing to drive and capture yields blank orfrozen frames. The
requestAnimationFrameloop such compositions use for liveplayback does not advance under deterministic capture.
This adapter is the lowest-common-denominator path: the composition registers a
render(timeSeconds)callback and the runtime calls it with the exactcomposition time for every captured frame — the seek-driven replacement for the
requestAnimationFrameloop.Contract
order, for every captured frame.
window.__hfTimefor draw helpers thatprefer to read it instead of
performance.now().argument — no
Date.now(), noperformance.now(), no unseeded randomness.unaffected.
It mirrors the existing registry-array pattern (
__hfLottie,__hfAnime,__hfMapbox, …):discoverreads lazily,seekdrives all callbacks withper-callback error isolation,
pauseis a no-op (a render function has norunning clock to stop). The callback list is snapshotted before iteration so a
callback registering another callback can't be invoked mid-seek or loop.
Changes
packages/core/src/runtime/adapters/render-fn.ts— the adapterpackages/core/src/runtime/adapters/render-fn.test.ts— unit tests(repeatability, arbitrary seek order, bounds/clamping, error isolation,
snapshot safety, no-op when empty)
packages/core/src/runtime/init.ts— register the adapterpackages/core/src/runtime/window.d.ts—__hfRender/__hfTimetypesdocs/concepts/frame-adapters.mdx— Supported Runtimes row + sectionskills/hyperframes-animation/— routing entry +adapters/render-fn.mdTest plan