Getting Started with Titan
Titan Engine is an ultra-fast, WebAssembly-compiled spreadsheet calculation engine. It is completely UI-agnostic, meaning you can plug it into any frontend data grid, canvas renderer, or custom UI.
Installation
Add the package to your modern web project:
npm install titan-engine
Or use it directly from a CDN (ES Modules):
import { initTitan } from 'https://unpkg.com/titan-engine/titan.js';
Basic Usage
Because Titan runs in WebAssembly, it requires an asynchronous initialization step before use.
// 1. Initialize the WASM module
import { initTitan } from 'titan-engine';
const Titan = await initTitan();
const engine = new Titan();
// 2. Add a Sheet
// Creates a sheet object. No more tracking integer IDs!
const sheet1 = engine.addSheet("Dashboard");
// 3. Set data (supports A1 notation or {row, col} objects)
sheet1.set("B2", "=SUM(A1:A100) * 2");
sheet1.set({ row: 0, col: 0 }, "15");
// 4. Batch Operations (suspends topological sort until complete)
sheet1.setRange("A1", [
["ID", "Name", "Sales"],
["1", "Alice", 500],
["2", "Bob", "=C2*1.5"]
]);
// Scattershot cross-sheet updates
engine.setCells([
{ sheet: "Dashboard", cell: "Z1", value: 100 },
{ sheet: 0, cell: {row: 5, col: 5}, value: "=Dashboard!Z1" }
]);
// 5. Read computed result directly from WASM memory
const cell = sheet1.get("A1");
console.log(cell.display); // "ID"
// Or use zero-copy Viewports for React grid rendering
const viewport = sheet1.createViewport();
const { type, value } = viewport.getCell(0, 0);
Architecture: The Data Grid Agnostic Engine
Titan provides the Model layer of your spreadsheet. It handles:
- Parsing and compiling formula ASTs.
- Managing a topological dependency graph (Kahn's Algorithm).
- Executing fast bytecode in a custom Rust VM.
- Maintaining strict O(1) History states for Undo/Redo.
It does not draw pixels, handle DOM events, or provide a UI. To build a full spreadsheet, you pair Titan with a rendering layer. For high performance, we highly recommend Glide Data Grid.