Scene
A retained scene built from SceneNodes - the imperative counterpart
of <Canvas>, with no React anywhere.
Structural mutations (add, remove, ...) batch per microtask into one
compile; flush() commits now. Value mutation goes through node handles
(createHandle), which patch slots without re-encoding - do not rebuild the
tree per frame.
Methods
add()
add(node: Node): void;Append a root node.
Parameters
node
Node
Returns
void
attach()
attach(target: SceneTarget): () => void;Drive a target from this scene. The new target receives the full current program; every later commit and slot push fans out to all attached targets. Returns a detach function.
Parameters
target
Returns
() => void
clear()
clear(): void;Returns
void
compileForExport()
compileForExport(what: string): object;The current program, for the offscreen renderers. Recompiles without reseeding, so live handle writes are baked in as literals rather than reset to their construction-time props. Internal to the package.
Parameters
what
string
Returns
object
buffer
buffer: ArrayBuffer;strings
strings: string[];dispose()
dispose(): void;Detach every target and stop committing. Targets keep their last frame.
Returns
void
flush()
flush(): void;Commit pending structural changes now instead of at the microtask.
Returns
void
handlesAt()
handlesAt(flat: number[]): (NodeHandle | null)[];Name the nodes behind a flat hit-test answer - what surface.hitTest and
view.hitTest return raw. Topmost first, null for a node with no
handle; feed the result to dispatchPress.
Parameters
flat
number[]
Returns
(NodeHandle | null)[]
insert()
insert(node: Node, before: number): void;Insert a root node before the given index (z-order).
Parameters
node
Node
before
number
Returns
void
remove()
remove(node: Node): boolean;Detach a root node by identity. Returns whether it was present.
Parameters
node
Node
Returns
boolean
replaceChildren()
replaceChildren(roots: Node[]): void;Swap the whole root list.
Parameters
roots
Node[]
Returns
void
save()
save(path: string, options?: SceneStillOptions): Promise<void>;Render this scene and write the still to path - the full headless loop
in one call. Size comes from options, then Scene.create's options,
then an attached offscreen surface. Format from the file extension unless
given. Resolves once the file is on disk; the bytes never enter JS.
Parameters
path
string
options?
Returns
Promise<void>
toImage()
toImage(options?: SceneStillOptions): Promise<TgfxImage>;Render this scene to a registered image handle. Caller disposes it.
Parameters
options?
Returns
Promise<TgfxImage>
toPdf()
toPdf(path: string, options?: SceneVectorOptions): Promise<void>;Write this scene as a one-page vector PDF. Size in points; A4 by naming it.
Parameters
path
string
options?
Returns
Promise<void>
toSvg()
toSvg(options?: SceneVectorOptions): Promise<string>;Render this scene to SVG markup. Vectors stay vectors.
Parameters
options?
Returns
Promise<string>
create()
static create(options?: SceneOptions): Scene;Parameters
options?
Returns
Scene
from()
static from(roots: Node[], options?: SceneOptions): Scene;Parameters
roots
Node[]
options?
Returns
Scene