Skip to content

Frame recording types

Read as Markdown

PibblFrameRecordingOptions requires duration in milliseconds and accepts frameRate, memoryHeadroom, and an optional cancellation signal. The optional onRenderComplete callback observes each root render after render-owned state has published. It receives a committed event with a committed generation or a failed event for an attempted generation. Failed attempts never yield pixel frames; a failed capture rejects. onFrameCaptured observes the exact generation after its RGBA bytes are copied, which can occur later than the render-completion callback when capture coalesces renders.

PibblRenderCompletion distinguishes committed generations from failed attempts. Only committed generations can identify recorded pixel evidence.

PibblFrameRecordingSession exposes ready, finished, stop(), and cancel(). Stop preserves captured frames. Cancel discards an active session.

PibblFrameRecording exposes actual duration, immutable frames metadata, readFrame(index), and idempotent dispose(). Each read returns a caller-owned copy; disposal releases worker-owned pixels and cancels pending operations.

PibblRecordedFrameInfo contains renderGeneration, the committed root render generation whose pixels were copied; timestamp in milliseconds from capture start; and physical backing width and height. Timestamps measure wall-clock capture time, can coalesce multiple renders, and are not generation identifiers.

PibblRecordedFrame adds data, a Uint8ClampedArray of RGBA8 bytes.

PibblGifExportOptions accepts frameRate (default 25, maximum 100), repeatCount (omitted plays once, zero loops forever, positive values repeat), an opaque CSS background, an abort signal, and onProgress(progress) from zero to one.

Export quality and size controls:

  • width and height: integer output dimensions from 1 to 65535. One dimension preserves aspect ratio; both specify the exact size. Omitted dimensions keep the original bitmap size. Resizing uses premultiplied-alpha bilinear sampling.
  • maxColors: integer 2–256, default 256. Includes the transparency entry when background is omitted. GIF color tables round up to a power of two.
  • palette: optional array of opaque CSS colors, used exactly instead of an automatically selected palette. Its length must fit maxColors, allowing one extra entry for transparent export. Unrepresented pixels use the nearest RGB palette color. Partial-alpha colors are rejected.
  • dithering: boolean, default false. Enables Floyd–Steinberg error diffusion.
  • quantizationSampleFactor: integer 1–30, default 10. One spends most NeuQuant training effort; larger factors sample less and run faster.
  • paletteSampleCount: integer 1–16777216, default 262144. Caps pixels sampled across up to 32 representative output frames for palette selection.

A supplied palette bypasses both automatic sampling controls. All exports keep recorded pixels unchanged, so a recording can be exported repeatedly with different settings. GIF compression itself is lossless over the resulting palette indexes; color reduction, binary transparency, resizing and frame sampling may lose detail.

See recordFrames and exportGif.

Options for capturing committed renders of one live Pibbl root.

interface PibblFrameRecordingOptions

Related API: PibblFrameRecordingOptions.

PibblFrameRecordingSession

View source — packages/core/src/lib/recording/types.ts:4

duration
duration: number

Recording length in milliseconds, measured after initialization.

View source — packages/core/src/lib/recording/types.ts:6

frameRate (optional)
frameRate?: number | undefined

Maximum capture frequency; defaults to 60 frames per second.

View source — packages/core/src/lib/recording/types.ts:8

memoryHeadroom (optional)
memoryHeadroom?: number | undefined

Initial estimated memory multiplier; defaults to 1.15. Memory may grow.

View source — packages/core/src/lib/recording/types.ts:10

signal (optional)
signal?: AbortSignal | undefined

Related API: signal.

Aborting discards the recording, including during initialization.

View source — packages/core/src/lib/recording/types.ts:12

onRenderComplete (optional)
onRenderComplete?: ((completion: PibblRenderCompletion) => void) | undefined

Related API: PibblRenderCompletion.

Observe each root render after its committed application state is published. Failed attempts are reported separately and never produce recorded frames.

  • completion — The committed or failed root render attempt.

View source — packages/core/src/lib/recording/types.ts:18

onFrameCaptured (optional)
onFrameCaptured?: ((frame: PibblRecordedFrameInfo) => void) | undefined

Related API: PibblRecordedFrameInfo.

Observe the exact committed generation after its RGBA pixels were copied.

  • frame — Metadata identifying the captured root bitmap.

View source — packages/core/src/lib/recording/types.ts:22

An active capture; stop keeps frames and cancel discards them.

interface PibblFrameRecordingSession

Related API: PibblFrameRecordingSession.

PibblFrameRecording

View source — packages/core/src/lib/recording/types.ts:46

ready
readonly ready: Promise<void>

Resolves after frame zero has been captured and capture has started.

View source — packages/core/src/lib/recording/types.ts:48

finished
readonly finished: Promise<PibblFrameRecording>

Related API: PibblFrameRecording.

Resolves when retained frames are ready, or rejects on cancellation/failure.

View source — packages/core/src/lib/recording/types.ts:50

stop
stop: () => void

Finish at the current elapsed time, retaining captured frames. Idempotent.

View source — packages/core/src/lib/recording/types.ts:52

cancel
cancel: () => void

Discard an active recording and release its resources. Idempotent.

View source — packages/core/src/lib/recording/types.ts:54

Metadata for one immutable RGBA bitmap in physical backing pixels.

interface PibblRecordedFrameInfo

Related API: PibblRecordedFrameInfo.

PibblRecordedFrame

View source — packages/core/src/lib/recording/types.ts:60

renderGeneration
readonly renderGeneration: number

Root render generation whose committed bitmap was copied.

View source — packages/core/src/lib/recording/types.ts:62

timestamp
readonly timestamp: number

Milliseconds since capture began; the initial frame is timestamp zero.

View source — packages/core/src/lib/recording/types.ts:64

width
readonly width: number

Bitmap width in physical backing pixels.

View source — packages/core/src/lib/recording/types.ts:66

height
readonly height: number

Bitmap height in physical backing pixels.

View source — packages/core/src/lib/recording/types.ts:68

A caller-owned copy of one frame’s RGBA8 bytes.

interface PibblRecordedFrame extends PibblRecordedFrameInfo

Related API: PibblRecordedFrame, PibblRecordedFrameInfo.

PibblRecordedFrameInfo

View source — packages/core/src/lib/recording/types.ts:74

data
readonly data: Uint8ClampedArray<ArrayBuffer>

Independent RGBA8 bytes; mutations never affect retained pixels.

View source — packages/core/src/lib/recording/types.ts:76

renderGeneration
readonly renderGeneration: number

Root render generation whose committed bitmap was copied.

View source — packages/core/src/lib/recording/types.ts:62

timestamp
readonly timestamp: number

Milliseconds since capture began; the initial frame is timestamp zero.

View source — packages/core/src/lib/recording/types.ts:64

width
readonly width: number

Bitmap width in physical backing pixels.

View source — packages/core/src/lib/recording/types.ts:66

height
readonly height: number

Bitmap height in physical backing pixels.

View source — packages/core/src/lib/recording/types.ts:68

Retained worker-owned frames; explicitly dispose after use.

interface PibblFrameRecording

Related API: PibblFrameRecording.

PibblFrameRecordingSession

View source — packages/core/src/lib/recording/types.ts:82

duration
readonly duration: number

Actual recording length in milliseconds, including the final still hold.

View source — packages/core/src/lib/recording/types.ts:84

frames
readonly frames: readonly PibblRecordedFrameInfo[]

Related API: PibblRecordedFrameInfo.

Immutable metadata ordered by ascending timestamp.

View source — packages/core/src/lib/recording/types.ts:86

readFrame
readFrame: (index: number) => Promise<PibblRecordedFrame>

Related API: PibblRecordedFrame.

Copy one frame without transferring ownership of stored pixels.

  • index — Zero-based recorded frame index.

A caller-owned pixel copy and its metadata.

View source — packages/core/src/lib/recording/types.ts:91

dispose
dispose: () => void

Release the worker, stored pixels, and pending reads/exports. Idempotent.

View source — packages/core/src/lib/recording/types.ts:93

GIF encoding options; encoding never changes the retained recording.

interface PibblGifExportOptions

Related API: PibblGifExportOptions.

PibblFrameRecording

View source — packages/core/src/lib/recording/types.ts:99

width (optional)
width?: number | undefined

Output width in pixels; omitted preserves source width or the specified height’s aspect ratio.

View source — packages/core/src/lib/recording/types.ts:101

height (optional)
height?: number | undefined

Output height in pixels; omitted preserves source height or the specified width’s aspect ratio.

View source — packages/core/src/lib/recording/types.ts:103

maxColors (optional)
maxColors?: number | undefined

Maximum palette entries, including transparency when no background is supplied; integer 2–256, default 256.

View source — packages/core/src/lib/recording/types.ts:105

palette (optional)
palette?: readonly string[] | undefined

Exact opaque CSS palette colors. Replaces automatic palette selection; must fit maxColors.

View source — packages/core/src/lib/recording/types.ts:107

dithering (optional)
dithering?: boolean | undefined

Apply Floyd–Steinberg error diffusion; defaults to false.

View source — packages/core/src/lib/recording/types.ts:109

quantizationSampleFactor (optional)
quantizationSampleFactor?: number | undefined

NeuQuant sampling factor, integer 1–30; 1 spends most effort, default 10. Ignored with a supplied palette.

View source — packages/core/src/lib/recording/types.ts:111

paletteSampleCount (optional)
paletteSampleCount?: number | undefined

Maximum pixels sampled for automatic palette selection across up to 32 frames; default 262144. Ignored with a supplied palette.

View source — packages/core/src/lib/recording/types.ts:113

frameRate (optional)
frameRate?: number | undefined

Output sampling frequency; defaults to 25. Must be at most 100.

View source — packages/core/src/lib/recording/types.ts:115

repeatCount (optional)
repeatCount?: number | undefined

Zero loops forever; omitted plays once; positive values repeat that many times.

View source — packages/core/src/lib/recording/types.ts:117

background (optional)
background?: string | undefined

Optional opaque CSS color used to flatten partial alpha before quantization.

View source — packages/core/src/lib/recording/types.ts:119

signal (optional)
signal?: AbortSignal | undefined

Related API: signal.

Abort encoding while preserving the recording for another export.

View source — packages/core/src/lib/recording/types.ts:121

onProgress (optional)
onProgress?: ((progress: number) => void) | undefined

Progress from zero to one, delivered between bounded worker batches.

  • progress — Fraction of output frames encoded.

View source — packages/core/src/lib/recording/types.ts:125

A completed root-render attempt. Failed generations were attempted, not committed. Generations identify renders of one mounted root; they are not global IDs.

type PibblRenderCompletion = | {
/** The root bitmap and render-owned state committed successfully. */
readonly status: "committed";
/** Monotonically increasing generation of this root's committed render. */
readonly generation: number;
}
| {
/** The attempted render failed and supplies no committed pixel evidence. */
readonly status: "failed";
/** Attempted generation of this root; it must not identify recorded pixels. */
readonly generation: number;
}

Related API: PibblRenderCompletion.

PibblFrameRecordingOptions

View source — packages/core/src/lib/recording/types.ts:29

status
readonly status: "committed" | "failed"

The root bitmap and render-owned state committed successfully. The attempted render failed and supplies no committed pixel evidence.

View source — packages/core/src/lib/recording/types.ts:32

generation
readonly generation: number

Monotonically increasing generation of this root’s committed render. Attempted generation of this root; it must not identify recorded pixels.

View source — packages/core/src/lib/recording/types.ts:34

Read the Authoring, signals, and lifecycle companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

Documentation built with @pibbl/core 0.0.2, revision a1dcf8e. ALPHA — NOT FOR PRODUCTION USE.