AVIS Engine
Framework-free canvas/scene engine with optional native React and React Flow
compatibility adapters. ESM only. Public beta on npmjs.com, MIT licensed.
Why AVIS Engine
AVIS is an AI film studio: its canvas holds hundreds to thousands of media
nodes (images, clips, scripts, prompts) wired into pipelines. It started on
React Flow and outgrew it:
- Every node is DOM. React Flow renders each node as React components in
the page. With many media nodes, layout, React reconciliation and the browser's
painting become the bottleneck while panning and zooming.
- React only, graph only. React Flow is a React library for node graphs.
An editor also needs a scene graph (frames with nested, rotated children),
undo/redo, a document format with migrations, styling and accessibility that
don't depend on a UI framework.
AVIS Engine keeps what React Flow gets right (its graph model, drag, connect,
select and viewport rules, ported from xyflow, MIT) and adds the editor around
it:
|
React Flow (xyflow) |
AVIS Engine |
| Rendering |
Each node is DOM (React components) |
Native API: one canvas drawn by WebGL2 or WebGPU (Canvas2D fallback), only visible nodes (spatial index), only after a change; images share atlas pages. Flow API: DOM nodes like React Flow, plus dom/paint to draw node DOM onto a canvas and keep live DOM only for the node being hovered or edited |
| Framework |
React (Svelte Flow is a separate package) |
Framework-free core; React, Vue 3 and Svelte adapters on top; runs in Node without a DOM |
| Model |
Nodes and edges in a store |
Scene graph (parents, world transforms, bounds) + relations; previews compose without touching the document |
| Changes |
Your setNodes / onNodesChange |
Commands in copy-on-write transactions with rollback; built-in undo/redo with merging |
| Save / load |
toObject(); persistence is yours |
Versioned, byte-stable JSON with migrations; /sync save queue (one write at a time, retries, no lost edit, drafts kept across a crash) |
| Transform |
Position and resize |
Position, resize, rotate, reparent keeping the world position, grid snap |
| Styling |
CSS on your DOM nodes |
Tailwind-like classes and design tokens compiled for the canvas; variants() matching CVA; rich text; frames and overflow-hidden clip |
| Accessibility |
ARIA on DOM nodes, keyboard moves |
Same roles plus a focus manager (focus apart from selection), spatial keyboard navigation, announcements |
| Heavy maths |
JavaScript |
Rust / WebAssembly kernels (spatial index, geometry) with a JS fallback |
| Scale |
Fine for typical graphs |
Budget tests at 10,000 nodes: create 199 ms, build a frame 42 ms, drag 1,000 nodes 85 ms, save/load 89 ms |
Moving from React Flow: change @xyflow/react to
@avis-studio/engine/react/flow (same component, hook and prop names) and import
@avis-studio/engine/react/flow/style.css. Then move to the native API at your
own pace for canvas rendering.
When React Flow is still the better choice: a small diagram whose nodes are
ordinary React components, where full React Flow behaviour and its ecosystem
matter more than scale. AVIS Engine is a beta; the Flow API is compatible, not
a promise of identical behaviour in every case (see "For Flow" below).
Install
npm install @avis-studio/engine@beta
Then import … from "@avis-studio/engine/react/canvas" works as in the
prototype. A local tarball (npm run engine:pack) installs the same way:
npm install /path/to/avis-studio-engine-<version>.tgz.
| Import |
Contents |
@avis-studio/engine |
Core, scene, commands/history, vanilla SDK, kernel loader |
@avis-studio/engine/react |
Native React canvas, elements and hooks |
@avis-studio/engine/react/canvas |
The graph canvas API under AVIS names (GraphCanvas, useGraph, useGraphSelect, useNodeBox, HandleSide, NodeOverlay…), with mountNode / mountEdges |
@avis-studio/engine/react/flow |
The same API under React Flow's names |
@avis-studio/engine/vue |
Native Vue 3 canvas, elements and composables |
@avis-studio/engine/svelte |
Svelte action (use:avis) and stores (Svelte 4 and 5) |
@avis-studio/engine/sync |
Backend-neutral coalescing save queue with failure and crash recovery |
@avis-studio/engine/react/flow/style.css |
Flow stylesheet; import once in the application |
The core has zero runtime dependencies. Node 20+ can import it without a DOM;
rendering and createAvis require a browser. The package targets ES2023 browsers.
React (react, react-dom 19) and Vue (vue 3.5) are optional peers; the
Svelte adapter needs none.
Type declarations support TypeScript's NodeNext and Bundler module resolution.
CommonJS require and private dist/* imports are not supported entrypoints.
Vanilla
Create theme.ts (or pass your application's equivalent token CSS):
export const tokens = [`:root {
--spacing: 4px; --radius-lg: 8px; --text-lg: 18px; --text-lg--line-height: 1.5; --font-sans: Arial;
--color-background: #f5f5f5; --color-card: #fff; --color-border: #ddd;
--color-foreground: #111; --color-muted-foreground: #737373;
--color-muted: #e6e6e6; --color-ring: #007bff; --color-destructive: #ef4444;
}`]
Then mount the canvas:
import { createAvis } from "@avis-studio/engine"
import { tokens } from "./theme.js"
const avis = await createAvis({ container: "#editor", renderer: "canvas2d", tokens })
const id = avis.createNode({
className: "flex flex-col gap-2 p-4 bg-card rounded-lg text-foreground",
text: "Hello AVIS",
position: { x: 80, y: 80 },
size: { width: 240, height: 120 },
})
avis.selection.select([id])
// Dispose when the editor unmounts:
// avis.dispose()
Give the container an explicit height. Pass your theme's CSS token sources to
enable styled content (the example includes minimal tokens). Styled nodes use the engine's supported
class subset; they do not implement the browser's full CSS layout engine.
Renderers: renderer: "webgl" (default, WebGL2), "webgpu" (falls back to
WebGL2, then Canvas2D), or "canvas2d". All draw the same commands; the GPU
backends match Canvas2D within a mean 0.5 / 255 per pixel.
Clipping: a frame node clips its children to its rounded box (set
props.clip: false to let them overflow); any node can clip with props.clip: true;
a styled element clips with overflow-hidden.
Rich text: a text node takes props.spans; a styled element takes spans
with classes:
avis.engine.createNode({
type: "text",
size: { w: 320, h: 80 },
props: { fontSize: 16, spans: [{ text: "Render " }, { text: "v2", bold: true, color: "#1d4ed8" }, { text: " is ready", italic: true, underline: true }] },
})
avis.createNode({
position: { x: 0, y: 120 },
size: { width: 320, height: 60 },
children: [{ className: "text-sm", spans: [{ text: "Status: " }, { text: "done", className: "font-bold text-primary" }] }],
})
React
Install both optional peers when using either React adapter:
npm install react@^19 react-dom@^19
npm install -D @types/react@^19 @types/react-dom@^19
React 19 is the supported peer major; the package verification records the exact
versions tested. Optional peers let vanilla projects install without React.
import { AvisCanvas, Frame, Text } from "@avis-studio/engine/react"
import { tokens } from "./theme.js"
export function Editor() {
return (
<AvisCanvas style={{ height: 480 }} options={{ tokens }}>
<Frame className="p-4 bg-card rounded-lg text-foreground" position={{ x: 80, y: 80 }} size={{ width: 240, height: 120 }}>
<Text className="text-lg">Hello AVIS</Text>
</Frame>
</AvisCanvas>
)
}
For Flow:
import { ReactFlow, Background, Controls } from "@avis-studio/engine/react/flow"
import "@avis-studio/engine/react/flow/style.css"
export function FlowEditor() {
return (
<div style={{ height: 480 }}>
<ReactFlow defaultNodes={[{ id: "hello", position: { x: 80, y: 80 }, data: { label: "Hello AVIS" } }]}>
<Background />
<Controls />
</ReactFlow>
</div>
)
}
The Flow entry is an implementation of the familiar API, not a promise of full
behavioral parity. Audited reconnection, viewport, resize and dataflow cases
have regression coverage; full prop/default combinations and some popup/painter behavior
remain outside that evidence. The app's custom media nodes, UI kit, registry
and CLI are not included in this package.
Vue
Install the optional peer: npm install vue@^3.5. The adapter is plain
TypeScript (render functions, no SFC compiler needed); use it from templates or h().
<script setup lang="ts">
import { AvisCanvas, Frame, Text, Button, NodeToolbar } from "@avis-studio/engine/vue"
import { tokens } from "./theme.js"
</script>
<template>
<AvisCanvas :options="{ tokens }" style="height: 480px" @ready="(avis) => {}">
<Frame class="p-4 bg-card rounded-lg text-foreground" :position="{ x: 80, y: 80 }" :size="{ width: 240, height: 120 }" @press="(action) => {}">
<Text class="text-lg">Hello AVIS</Text>
<Button action="like" class="rounded-md bg-primary px-3 py-1 text-xs">Like</Button>
</Frame>
<NodeToolbar class="toolbar"><button>Delete</button></NodeToolbar>
</AvisCanvas>
</template>
Like React, Vue never renders frames: <Frame> / <Node> create their node
with a command on mount, push only changed props, and delete it on unmount;
<Box> / <Rect> / <Text> / <Button> are read from the slot. class
works as well as className. <AvisProvider :avis> provides an instance you
created yourself. Composables return read-only refs that update only when
their slice changes and unsubscribe with the component: useAvis,
useEngineSelector(selector, equals?), useSelection, useViewport,
useNode(idRefOrGetter), useHistory (canUndo / canRedo refs, undo,
redo), useThemeMode.
Svelte
No extra dependency: the action and stores follow Svelte's contracts without
importing svelte, so they work with Svelte 4 and 5 ($store, fromStore).
<script lang="ts">
import { avis, selection, history } from "@avis-studio/engine/svelte"
import type { Avis } from "@avis-studio/engine"
import { tokens } from "./theme.js"
let canvas: Avis | null = null
$: selected = canvas && selection(canvas)
$: steps = canvas && history(canvas)
</script>
<div style="height: 480px" use:avis={{ tokens, onReady: (instance) => (canvas = instance) }}></div>
{#if steps}
<button disabled={!$steps?.canUndo} on:click={() => steps?.undo()}>Undo</button>
<p>{$selected?.length ?? 0} selected</p>
{/if}
use:avis creates the instance on the element and disposes it on destroy;
onReady, onError and instance (a store set to the instance, then null)
hand it over. Engine options are read once; an update applies mode and the
callbacks. Stores: engineStore(avis, selector, equals?), selection(avis),
viewport(avis), nodeStore(avis, id), history(avis) (with undo /
redo), themeMode(avis) (writable: set switches the mode). Each one
subscribes to the engine only while it has subscribers.
Connect a backend
The host supplies transport, authentication, schema validation and revision/conflict
policy. The SDK never embeds AVIS credentials or calls generation APIs.
import { createSaveQueue } from "@avis-studio/engine/sync"
import type { ReactFlowJsonObject } from "@avis-studio/engine/react/flow"
export function autosave(save: (graph: ReactFlowJsonObject) => Promise<void>) {
return createSaveQueue({ save, debounceMs: 800 })
}
// After a graph edit: queue.enqueue({ nodes, edges, viewport }).
// Before leaving the route: await queue.flush().
// On failure: queue.getSnapshot().pending retains the latest value; flush retries.
Writes run one at a time. An old acknowledgement cannot clear a newer edit.
subscribe / getSnapshot work with React's useSyncExternalStore or plain JS.
pause(error) retains a draft without sending it; resume() schedules it again.
dispose() cancels scheduled work/subscriptions and ignores a late acknowledgement;
it cannot reverse a server commit. Enqueued values must be treated as immutable.
Before disposing, let the host retain/export pending data or obtain an explicit discard.