aispritejs
v0.5.9
Published
Input-driven, renderer-agnostic 2D sprite animation runtime — a tiny, Rive-like visual state machine driven by Number / Boolean / Trigger inputs. JSON transition graph, deterministic update(dt), zero runtime dependencies. Browser / Node / Bun / Deno / Web
Maintainers
Readme
aispritejs
Input-driven, renderer-agnostic 2D sprite animation runtime. A JSON graph maps Number/Boolean/Trigger inputs to visual states and frames; adapters bind the chosen frame to a renderer.
Status: 0.5.9 - stable family-aligned surface. Core, PixiJS adapter, atlas parser, and JSON Schema subpath are shipped.
Install
pnpm add aispritejs
pnpm add pixi.js # only when using aispritejs/pixiimport { createSpriteAnimator } from "aispritejs";Quick Start - Core
const anim = createSpriteAnimator({
inputs: {
speed: { type: "number", default: 0 },
jump: { type: "trigger" },
},
initial: "idle",
states: {
idle: { animation: "idle" },
run: { animation: "run", speed: 1 },
jump: { animation: "jump", loop: false, onEnd: "idle" },
},
transitions: [
{ from: "idle", to: "run", when: [{ input: "speed", op: "GreaterThan", value: 0 }] },
{ from: "*", to: "jump", when: [{ input: "jump", op: "Trigger" }] },
],
animations: {
idle: ["idle_0"],
run: ["run_0", "run_1"],
jump: ["jump_0", "jump_1"],
},
});
anim.setInput("speed", 1);
anim.fireTrigger("jump");
anim.update(16.7);
console.log(anim.activeState, anim.activeFrameKey);PixiJS Adapter
import { createPixiSpriteAnimator } from "aispritejs/pixi";
const view = createPixiSpriteAnimator(sprite, graph, spritesheet);
view.update(deltaMs);
view.dispose(); // disposes core animator; does not destroy the Pixi spritepixi.js is an optional peer dependency and is imported type-only by the adapter. The root package never imports Pixi, DOM, or canvas APIs.
Atlas and Schema
parseAtlas(atlas, control?)converts a PixiJS-v8 style atlas plus control block into aSpriteGraph.loadAtlas(atlas, control?)parses and creates aSpriteAnimator.aispritejs/schemaexportsschemas/aispritejs-graph.schema.jsonfor editor/CI validation.- Parser validation is structural (
InvalidAtlasError); compiler validation is semantic (InvalidGraphError).
Core API
createSpriteAnimator(graph)returns aSpriteAnimator.setInput(name, value)accepts Number/Boolean inputs.fireTrigger(name)consumes Trigger inputs on transition.update(deltaMs)advances time, transitions, frame index, andonEnd.reset()returns to the initial state.dispose()is idempotent; mutators throwSpriteAnimatorDisposedErrorafterward.onStateChange(handler, options?)andonComplete(handler, options?)supportonceandsignal.
Sharp Edges
- Non-looping states with
onEndtransition during the sameupdate()tick that completes the clip. AnimatedSpriteis accepted by the Pixi adapter because it extendsSprite, but playback is stopped on bind so it cannot fight the adapter.- Every reachable frame key must exist in the texture map/spritesheet; missing keys throw
MissingTextureError. duration,defaultFrameDuration, and statespeedmust be finite numbers greater than zero.
AI Context
- Short index:
llms.txt - Full generated context:
llms-full.txt - Stability contract:
STABILITY.md - Current review backlog:
REVIEW.md - Examples index:
examples/README.md - Release history:
CHANGELOG.md
License
MIT
