A professional-grade, canvas-based paginated rich text editor built with Svelte 5, TypeScript, and a Rust/WASM layout and rendering engine. This editor provides a document editing experience similar to Google Docs or Microsoft Word, with support for multiple pages, columns, images, tables, and rich text formatting.
| Technology | Version | Purpose |
|---|---|---|
| Rust | 1.70+ | Layout engine, document model |
| wasm-bindgen | 0.2+ | Rust/WASM interop |
| Svelte | 5.46+ | UI Framework with runes |
| TypeScript | 5.9+ | Type safety |
| Vite | 7.3+ | Build tool and dev server |
| Canvas API | - | High-performance rendering |
cargo install wasm-pack)# Clone the repository
git clone https://github.com/Pterygoidien/wysiwyg-rich-text-editor-rust-wasm.git
cd wysiwyg-rich-text-editor-rust-wasm
# Install dependencies
npm install
# Build the WASM engine
npm run build:wasm
# Start development server
npm run dev
| Command | Description |
|---|---|
npm run dev |
Start development server with HMR |
npm run build:wasm |
Build the Rust/WASM engine |
npm run build |
Build everything for production |
npm run preview |
Preview production build locally |
src/
├── App.svelte # Root application component
├── main.ts # Application entry point
└── lib/
├── EditorWasm.svelte # Main WASM-powered editor component
├── Editor.svelte # Pure JS editor component (fallback)
├── Toolbar.svelte # Formatting toolbar with all controls
├── Sidebar.svelte # Document outline navigation
├── engine-bridge.ts # TypeScript/WASM bridge
├── engine-wasm/ # Generated WASM bindings
├── stores.ts # Svelte stores for shared state
└── types.ts # Page configuration types
engine/
├── Cargo.toml # Rust project configuration
└── src/
├── lib.rs # WASM entry point and API
├── document.rs # Document model (paragraphs, images, tables)
├── layout.rs # Layout engine (line wrapping, pagination)
└── render.rs # Render command generation
The editor uses a hybrid architecture with Rust handling the compute-intensive layout and document operations, while Svelte manages the UI and user interactions.
Document Model (Rust)
↓
Layout Engine (Rust) → Display Lines
↓
Render Commands (Rust→JS via WASM)
↓
Canvas Renderer (TypeScript)
↓
Pixels on Screen
| Module | Responsibility |
|---|---|
document.rs |
Document model: paragraphs, styles, images, tables |
layout.rs |
Converts document to display lines with text wrapping |
render.rs |
Generates canvas drawing commands |
lib.rs |
WASM-bindgen API for JavaScript interop |
Tables use a special marker paragraph (U+FFFB + table_id) and store cell data separately:
pub struct TableCell {
pub text: String,
pub align: TextAlign,
pub background: Option<String>,
pub col_span: usize,
pub row_span: usize,
pub covered: bool, // Part of a merged cell
}
| Shortcut | Action |
|---|---|
Ctrl/Cmd + B |
Bold |
Ctrl/Cmd + I |
Italic |
Ctrl/Cmd + U |
Underline |
Ctrl/Cmd + A |
Select all |
Ctrl/Cmd + C |
Copy |
Ctrl/Cmd + V |
Paste |
Ctrl/Cmd + Z |
Undo |
Ctrl/Cmd + Y |
Redo |
Enter |
New paragraph |
Alt + Enter |
Page break |
Tab (in table) |
Next cell |
Shift + Tab (in table) |
Previous cell |
Cell Operations:
Requires WebAssembly support and modern JavaScript features.
The Rust/WASM engine provides significant performance benefits:
Contributions are welcome! Please:
cargo test for Rust testsnpm run build to ensure everything compilesMIT License - see LICENSE file for details.