@hyperframes/sdk when an application must inspect or change composition
HTML without opening Studio. If you only need playback, use the
Player. If you only need a rendered file, use the
CLI or Producer.
The core loop is open, query, edit, and serialize. The SDK adds stable
data-hf-id values where they are missing so later edits target the same
elements.
Open, edit, serialize
1
Install the package
2
Open a composition
openComposition parses the HTML, stamps any elements that lack data-hf-id attributes, and returns a Composition session.3
Find elements
Use
getElements() for a flat snapshot of everything in the composition, or find() to filter by tag, text content, data-name attribute, track index, or sub-composition host.find() returns an array of scopedId strings. For top-level elements, scopedId === id. For elements inside inlined sub-compositions, it is "hf-HOST/hf-LEAF".4
Edit elements with typed methods
Typed methods are the most readable way to mutate a composition. Each one translates directly into a dispatched Use
EditOp and emits a patch event.batch() when several mutations should collapse into one undo entry, one persist write, and one change event:5
Serialize and dispose
serialize() returns the full updated HTML string. Call dispose() when you are done to release event handlers and any internal state.Add a persistence adapter
The headless pattern above is fine for one-shot transforms. When you want the SDK to persist edits, pass aPersistAdapter. Rapid changes are coalesced and written in order, with the latest state
winning rather than one disk write per UI event.
The filesystem adapter (@hyperframes/sdk/adapters/fs) writes to a local directory and keeps a rolling version history.
./project/index.html after every mutation and keeps up to 20 version snapshots under ./project/.hf-versions/.
Disabling undo (
history: false) does not disable autosave. The two are independent. Passing
history: false is only necessary when you are managing the undo stack yourself.Related topics
Querying & Editing Elements
FindQuery fields, scopedId for sub-compositions, batch semantics, and element handles.
Undo, Redo & Patches
History module, patch events for host sync, and applyPatches loop prevention.
Persistence
Adapter selection, version history, and implementing a custom adapter.
openComposition reference
Full option reference — adapters, overrides, coalesce window, and more.