A SvelteKit 5 application demonstrating CalcMark syntax highlighting, evaluation, and diagnostics with server-side WASM processing.
- Server-side WASM: CalcMark WASM runs on the Node.js server (no 3MB client download)
- Real-time processing: Syntax highlighting, evaluation, and diagnostics as you type
- Svelte 5 runes: Modern reactive patterns with
$state,$derived,$effect - Block-based markdown rendering: Proper rendering of markdown structures (lists, blockquotes, etc.)
- Token-based highlighting: Color-coded tokens with contextual styling
- Live diagnostics: Errors, warnings, and hints displayed inline
- Evaluation results: See calculated values for each line
- Interactive tooltips: Hover over calculation lines to see results and diagnostics
- Node.js 18+ (for running the SvelteKit dev server)
- Go 1.21+ (for building the WASM module)
IMPORTANT: The demo requires WASM files to be built first. These files are NOT in git and must be generated locally.
# From the go-calcmark project root, build the calcmark CLI tool first
cd /Users/bitsbyme/projects/go-calcmark
go build -o calcmark ./impl/cmd/calcmark
# Then use it to build WASM files directly into this project's static/ directory
./calcmark wasm /Users/bitsbyme/projects/calcdown/static/This creates two files in static/ (both are git-ignored):
calcmark.wasm- The compiled WASM binary (~3MB)wasm_exec.js- Go's WASM runtime loader
Why these aren't in git: The WASM file is large (~3MB) and should be built locally for your Go version.
npm installnpm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --openThen open http://localhost:5173 in your browser.
To create a production version of your app:
npm run buildYou can preview the production build with npm run preview.
To deploy your app, you may need to install an adapter for your target environment.
The demo uses server-side WASM processing to avoid sending 3MB of WASM to every client:
-
WASM Initialization (
src/lib/server/calcmark.ts)- Loads WASM once when server starts
- Initializes
global.calcmarkAPI - Single-pass evaluation for O(n) performance
-
API Endpoint (
src/routes/api/process/+server.ts)- POST
/api/processwith{ input: string } - Returns: classifications, tokens, evaluationResults, diagnostics
- POST
-
Client Components (Svelte 5 with runes)
- Editor calls API on input change (debounced 150ms)
- Receives processed data and updates UI reactively
- Uses
$state,$derived,$effectfor reactivity
User types in editor
↓
CalcMarkEditor.svelte (debounced)
↓
POST /api/process
↓
Server: processCalcMark() in Node.js
├── classifyLines()
├── tokenize()
├── evaluate() (single pass)
└── validate()
↓
Response: { classifications, tokens, evaluationResults, diagnostics }
↓
SyntaxHighlighter.svelte ($derived.by)
↓
CalcMarkBlock.svelte (groups lines into blocks)
├── Markdown blocks → {@html marked.parse(...)}
└── Calculation blocks → CalculationLine components
Error: ENOENT: no such file or directory, open 'static/calcmark.wasm'
Solution:
# From go-calcmark project root
go build -o calcmark ./impl/cmd/calcmark
./calcmark wasm /Users/bitsbyme/projects/calcdown/static/This builds and copies both calcmark.wasm and wasm_exec.js to the correct location.
Error: CalcMark API not initialized
Solution:
- Ensure Go WASM was built with correct Go version:
go version - The
calcmark wasmcommand automatically uses the correctwasm_exec.jsfor your Go version - Rebuild if needed
Check server logs for errors. Common issues:
- WASM files missing or corrupted
- Go runtime version mismatch
- Invalid input format
- No client WASM download: Server processes everything
- Single-pass evaluation: O(n) instead of O(n²)
- Debounced input: 150ms delay prevents excessive API calls
- Block-based rendering: Efficient markdown parsing
- Caching: Server maintains WASM instance across requests
Works in all modern browsers:
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+