API Reference: Hooks
Three callbacks and signals. They are all attached at call sites, not on objects: there is no "subscribe to an object" API, and progress information can only come in through these parameters.
Environment-level readiness (capabilities / runtime / KaTeX / package fetching) does not attach at call sites; see Environment Status.
onLoading(names)
Progress callback while third-party packages are fetched for an import. Three mounting points, in increasing precedence:
createManimRenderer({ onLoading })createSurface(container, { onLoading })run(code, { onLoading })
onLoading?: (names: string[]) => voidParameters names: the package names being fetched; called once more with an empty array when done.
Example
const surface = await renderer.createSurface(container, {
onLoading: (names) => {
if (names.length === 0) return hideLoading()
// Bundled packages and cache hits are fast; showing it immediately makes it flash. Delay ~300 ms.
window.setTimeout(() => showLoading(names), 300)
},
})Notes
- Covers package fetching only, not render progress. "Rendering now" has to be tracked at the call site around
run(). printfrom user code does not come through here; the core writes it toconsole.info.
onProgress(note)
Stage updates during an export; attached on the request passed to exporter.run().
onProgress?: (note: string) => voidParameters note: one line of progress text, e.g. "playing from the top and recording…" or "recorded 32 KB".
Example
await recorder.run({ python, controller, onProgress: (note) => setStatus(note) })signal
Cancels one export. Only exporter.run() accepts it; surface.run() does not.
run(request: ExportRequest, signal?: AbortSignal): Promise<ExportResult>Example
const abort = new AbortController()
stopButton.onclick = () => abort.abort()
await recorder.run({ python, controller }, abort.signal)After an abort the recorder stops and returns { ok: false, reason: 'error', error: 'cancelled' }.
Notes
- It cancels the export action, not the render in flight. Cancelling "the piece that is running right now" has no corresponding capability in this version; see the gap table at the end of Low-Level Exports.