@tylerwarburton/sprite-core-client
v0.5.8
Published
TypeScript client SDK for the SpriteCore plugin — portable animation graph + sprite player for browsers, Node, and any JS runtime
Readme
@tylerwarburton/sprite-core-client
TypeScript client SDK for the SpriteCore plugin. Consumes the CharacterManifest
wire shape emitted by node.getCharacterManifest and drives a portable
animation graph + sprite player that any JS runtime (browser, Node, Electron,
React Native) can render.
This is the reference implementation — the Kotlin and Swift kits in sibling
packages are functional mirrors of this code, validated against the shared
fixtures/ suite at the repo root.
Install
npm install @tylerwarburton/sprite-core-clientPublished to the public npm registry under the @tylerwarburton scope.
Minimal usage
import {
AnimationGraph,
SpriteAnimationPlayer,
InMemorySpriteSource,
createAvatarMarkerParser,
} from "@tylerwarburton/sprite-core-client";
const envelope = await fetchCharacterManifest("my-agent");
const graph = AnimationGraph.fromManifest(envelope.manifest, "headshot");
const frameSource = new InMemorySpriteSource<ImageBitmap>((bytes) =>
createImageBitmap(new Blob([bytes])),
);
for (const [refKey, bytes] of Object.entries(assetBytes)) {
frameSource.put(refKey, bytes);
}
const player = new SpriteAnimationPlayer(graph);
player.currentRef.subscribe((ref) => {
if (!ref) return;
const bitmap = frameSource.frame(ref);
drawToCanvas(bitmap);
});
// When the model emits `<<<happy>>>`:
const parser = createAvatarMarkerParser();
const { markers, cleanedText } = parser.push(streamedChunk);
for (const m of markers) {
player.requestState(m.state, m.count);
}Surface
CharacterManifesttypes and TypeBox schemas (re-exported from@tylerwarburton/sprite-core-schema)AnimationGraph.fromManifest(manifest, mode)— projection + wildcard transition resolverSpriteAnimationPlayer— state machine, phases, play-count, ping-pongFrameSource<F>interface +InMemorySpriteSourceAssetSource— manifest + asset cache with revision checkscreateAvatarMarkerParser()/splitByMarkers()— streaming marker parserMutableObservable— minimal StateFlow equivalent forcurrentRef/currentState
