Monotonically increasing version. Snapshot for useSyncExternalStore.
Read-only snapshot of every history entry currently reachable from the present state. Oldest applied first, then redoable entries in the order they'd be re-applied. Each entry id is stable.
Index of the "current state". Equals the count of applied entries;
0 means "nothing applied" (initial).
Jump to the given history index by calling undo/redo repeatedly. Clamps to [0, total]. Returns true if any movement occurred.
Replace this scene's entire node + layer state in place from a snapshot
produced by toJSON(). Unlike sceneFromJSON, the existing Scene
instance is preserved — holders such as <SceneCanvas> keep their
reference. History (undo/redo) is cleared, matching sceneFromJSON.
Bumps getVersion() and notifies subscribers exactly once.
Throws on an unsupported version or unknown registry/layer ids; on a
malformed snapshot the scene is left empty or partially populated (callers should treat a
loadState throw as fatal and reload). Snapshots from toJSON() are
always well-formed.
Reparent id under parent (or to a root when parent is null) at
index within the new sibling list, appending when index is omitted.
Siblings are reindexed. Recorded as one undoable step.
Rejected (throws) when:
parent exists but is a leaf, not a container;parent is id itself or one of
id's own descendants;id below its new parent's layer (child may not
render below its parent).move(id, null) — detaching to a root — is always allowed regardless of
layer, since a root has no parent to render beneath.
Delete id and its entire subtree — every descendant is removed in
the same operation. Recorded as one undoable step; undo() restores the
whole subtree (root + descendants, child order intact).
Replace the undo/redo history from a serializeHistory() snapshot.
Call on a scene whose node/layer state already matches the snapshot's
head state (i.e. right after loadState from the paired scene
snapshot); node state is NOT mutated. Ops re-registered via
registerOp before this call round-trip; unknown kinds become no-op
placeholders; external ops rebuild via the global op-factory registry
and replay against the setHistoryAdapter accessor. Restored entries
never coalesce with new ones. Notifies once. Do not call mid-batch:
the stacks are replaced underneath the open batch, whose eventual
flush would graft onto (and evict against) the restored stacks.
Snapshot the undo/redo history in a JSON-serializable form (the
engine's SerializedHistory). Entries containing any nameless op are
dropped (hand-rolled anonymous ops passed to applyBatch); kit and
consumer-registered ops always carry names. Payload JSON-safety
(e.g. typed arrays inside poses) is the caller's concern. Do not call
mid-batch — the open batch's ops are not yet recorded.
Install (or clear) the active-journal accessor after scene construction.
Useful when the journal source (typically a mode machine) is built
with scene.history as a dependency — a chicken-and-egg situation
where the accessor can't be passed in via UseSceneOptions.
Pass null to detach. Overrides any getActiveJournal set in
UseSceneOptions.
Install (or clear with null) the accessor for the adapter that
RESTORED external ops (recorded via applyBatch, rebuilt from a
restoreHistory snapshot) apply against on undo/redo. Resolved lazily
at each apply, so wiring order relative to restoreHistory doesn't
matter. Live applyBatch entries are unaffected (they bind their
call-site adapter). If unset when a restored op applies, the op is a
debug-warned no-op.
Retag id to layer. On a container this cascades: every descendant
is moved to the same layer, recorded as a single undo step.
Invariants:
Snapshot the current scene state to a JSON-serializable shape.
History (undo/redo stacks) is NOT captured. Function fields like
ContainerNode.clipFromPose are translated to string keys via the
scene's registry; throws if any function field has no matching key.
Apply a batch of ops with journal-aware routing.
getActiveJournalin options): the ops themselves are recorded as one undo entry on the scene's own history, rebound toadapter— undo replays each op'sinvert()against that same adapter. ConsecutiveapplyBatchentries can coalesce via matching opcoalesceKeys when the scene opts intocoalesceWindowMs.journal.applyBatch(ops, label). The scene's history recording is suppressed for the duration so the journal's inner history — not the scene's undo stack — tracks the batch. Mutations still happen onadapter/ scene state.adaptermust be the same adapter the ops expect (typically aSceneCanvasAdapter). PassthisfromsceneToAdapteror a compatible adapter.