061f95ddee
Backend (typst-leaf-backend) - REST API for multi-project file management under PROJECTS_ROOT (list/create projects, get file tree, read/write files; zod-validated sandbox prevents path traversal). - LSP thin proxy: spawns a single tinymist lsp process, pipes one active WebSocket straight to its stdio via vscode-ws-jsonrpc. New connections trigger a takeover (old session disposed, fresh tinymist spawned). - Live preview pipeline: the frontend sends tinymist.startDefaultPreview over the LSP wire, reads the returned data-plane port, and relays it to the backend. The backend proxies /preview (WS, with retry and an Origin header for typst-preview) and /preview-app (HTTP, injecting a script that rewrites the webview's WS path to /preview and forces light mode). - Graceful SIGTERM/SIGINT shutdown. - Auto-seeds a hello project on first boot. - Removed execa dependency (no longer needed). Frontend (typst-leaf-frontend) - Monaco editor with typst syntax highlighting (Monarch tokenizer) and live LSP diagnostics (markers), completion, hover, definitions, and formatting — all driven by a raw JSON-RPC WebSocket client (no monaco-languageclient or vscode-api dependency). - Project picker and file tree sidebar. - Live preview pane: iframes the typst-preview webview through the backend's /preview-app proxy, so the pipedepeline works remotely. - Monaco bundled locally (no CDN) with a Vite worker setup. - Vite dev proxy so relative /api, /lsp, /preview, and /preVIEW-app URLs reach the backend on port 4000. - Light-mode UI (editor 'vs' theme, white chrome). - Prevent esbuild from tree-shaking monaco.editor services (optimizeDeps.esbuildOptions.treeShaking: false). Infrastructure - Added vscode-ws-jsonrpc to backend dependencies. - Removed monaco-languageclient and vscode-ws-jsonrpc from frontend dependencies (replaced by the raw JSON-RPC client). - Added monaco-editor as a direct frontend dependency. - Updated README (correct frontend port 1420, tinymist install command, environment variables, architecture). - Added projects/ to .gitignore. - Renamed Tauri productName and page title to typst-leaf.
68 lines
2.5 KiB
Markdown
68 lines
2.5 KiB
Markdown
# typst-leaf 🍂
|
|
|
|
A completely self-hostable, high-performance editor for [Typst](https://typst.app/), built on the philosophy of "Git as the Database."
|
|
|
|
**Features:**
|
|
* **Instant Preview:** Sub-50ms incremental compilation using `tinymist`.
|
|
* **Live diagnostics & autocomplete** from the Typst language server.
|
|
* **Git Native:** No hidden databases. Your projects are just folders.
|
|
* **Hybrid:** Run it in a browser, or as a native desktop app via Tauri.
|
|
|
|
## 📂 Repository Structure
|
|
|
|
```text
|
|
typst-leaf/
|
|
├── typst-leaf-backend/ # Node.js/TS server (spawns tinymist, REST + WS)
|
|
├── typst-leaf-frontend/ # React + Monaco frontend (includes Tauri)
|
|
├── VISION.md # Project philosophy and architecture
|
|
└── AGENTS.md # Guidelines for AI coding assistants
|
|
```
|
|
|
|
## Prerequisites
|
|
|
|
* **Node.js 20+**
|
|
* **pnpm** (10+)
|
|
* **Rust** (only required for the Tauri desktop wrapper)
|
|
* **`tinymist`** on your `PATH` — the Typst language server & preview engine:
|
|
```bash
|
|
cargo install --git https://github.com/Myriad-Dreamin/tinymist --bin tinymist --locked tinymist-cli
|
|
```
|
|
|
|
## 🚀 Quick Start (Development)
|
|
|
|
```bash
|
|
# 1. Install workspace dependencies
|
|
pnpm install
|
|
|
|
# 2. Start the backend (port 4000)
|
|
pnpm --filter typst-leaf-backend dev
|
|
|
|
# 3. Start the web frontend (port 1420 — mandated by Tauri)
|
|
pnpm --filter typst-leaf-frontend dev
|
|
|
|
# 4. (Optional) Launch the Tauri desktop wrapper
|
|
pnpm --filter typst-leaf-frontend tauri dev
|
|
```
|
|
|
|
Then open <http://localhost:1420> in your browser. A `hello` project is auto-seeded on first run.
|
|
|
|
### Environment variables
|
|
|
|
| Var | Default | Description |
|
|
| --- | --- | --- |
|
|
| `PROJECTS_ROOT` | `<repo>/projects` | Directory under which project folders live. The backend refuses to read or write outside this root. |
|
|
| `TINYMIST_PREVIEW_HOST` | `127.0.0.1` | Host the tinymist preview server binds to. |
|
|
| `TINYMIST_PREVIEW_PORT` | `23635` | Port the tinymist preview server binds to. |
|
|
| `PORT` (backend) | `4000` | Backend HTTP/WS port. |
|
|
| `FRONTEND_ORIGIN` (backend) | `http://localhost:1420` | CORS origin allowed to call the REST API. |
|
|
|
|
## 🏗️ Architecture
|
|
|
|
* **Editor:** Monaco Editor
|
|
* **LSP:** `tinymist` over a WebSocket thin proxy
|
|
* **Preview:** Backend spawns `tinymist preview <file>` on demand; the frontend iframes its webview for live SVG updates.
|
|
* **Data plane:**
|
|
* `ws://localhost:4000/lsp` → `tinymist lsp` (single active connection, takeover on reconnect)
|
|
* `GET /api/projects`, `GET/PUT /api/projects/:p/file?path=…`, `POST /api/projects/:p/focus?path=…`
|
|
|