Node / Gif Animation · guide
Programmatic frames (onStart)
Current Apexify.js 6.0.0 documentation for Programmatic frames (onStart).
Use GIFOptions.onStart when frames are generated programmatically instead of supplied as a static GIFInputFrame[].
The modes are exclusive: if onStart is present, pass undefined for gifFrames. Supplying a non-empty static frame list and onStart together is rejected.
Callback shape
The runtime passes the active ApexPainter instance as the second argument.
frameCountHint is advisory and always bounded by the configured maxGifFrames. It is derived from:
options.frameCount, when provided- otherwise
ceil(options.duration / options.delay)when a positive delay makes that calculation possible - otherwise
30
The hint does not weaken the actual generated-frame limit. The creator checks the real number of frames independently.
GIFEncodedFrame
buffer is required but is a GIFFrameSource, so it is not limited to an in-memory Buffer. The same central media/network policy used for static frames applies.
duration falls back to options.delay, then 100 ms.
Array mode
Returning GIFEncodedFrame[] materializes the generated source list before encoding. Apexify validates every generated frame and rejects an array that exceeds the applicable generated-frame bound.
Use this mode for small/generated sets where keeping the source list in memory is acceptable.
True AsyncIterable streaming
Returning AsyncIterable<GIFEncodedFrame> is the memory-bounded Phase 7 path.
The consumer sequence is intentionally:
There is no prefetch from the generated async iterator and no conversion to an array. Backpressure therefore reaches the producer: Apexify does not ask it for frame N + 1 until frame N has completed the per-frame encode path.
Generated streams are still bounded. If the iterator produces more frames than the configured/declared limit, creation fails rather than continuing indefinitely. An iterator that yields zero frames is also rejected.
Streaming example
For long animations, prefer yielding frames as they are produced instead of first building a separate Buffer[] and then yielding that array.
Cancellation and producer errors
Pass options.signal to cancel generated work. Apexify checks cancellation between frame pulls and propagates the signal into remote media resolution. It stops requesting additional frames after cancellation/failure.
Errors already represented by Apexify's structured error classes retain their type. Other failures thrown by the onStart callback or iterator are wrapped as GIF decode/generation errors with the original cause attached.