Rust + RaTeX architecture#
LayMesh shares one Rust implementation of .lay parsing, LCSS, resources, physical layout, plotting and formulas across native CLI, Python/Jupyter and browser WebAssembly. Node.js, npm and embedded JavaScript engines are not required.
| Component | Responsibility |
|---|---|
| laymesh-core | Restricted DSL, units, layout, plots, fonts and RaTeX formulas |
| laymesh-render | Versioned DisplayList; Skia CPU rasters and SkPDF vector PDF, direct DrawingML PPTX and SVG file adapters |
| laymesh-language | Static completion, diagnostics, hover, signatures and imports |
| laymesh-cli | validate, render, inspect and stdio LSP |
| laymesh-wasm | Browser Worker bindings for rendering and language services |
Only KaTeX formula fonts are embedded. Body fonts come from the system or user files; browsers require permission or explicit font selection. Missing glyphs warn and render as vector boxes while export continues.
A Python wheel carries one native executable and preserves the existing bridge API, Notebook magic and saved-source workflow. The website uses locked static ESM editor modules. Python builds documentation and assets; Cargo and wasm-bindgen build WebAssembly.
The VS Code client uses its supplied extension-host interfaces to start laymesh lsp --stdio. It contains no npm dependency tree. An offline CanvasKit 0.42.0 standard build draws protocol 3 scenes using WebGL2. The website and extension share site/live/skia-renderer.mjs. Worker OffscreenCanvas is preferred; a main-thread adapter and Skia software surfaces provide fallbacks. Rust retains font selection, positioned glyph outlines, layout and animation sampling; CanvasKit does not reshape text.
The drawing pipeline is Scene → DisplayList v1 → output backend. Positioned glyphs retain font IDs, source character ranges and formula text. SVG parsing occurs at the import boundary; a separate serializer exports SVG files. Raster, PDF, PPTX and new previews never generate or parse internal SVG. Explicit preview protocols 1/2 and WASM svg() remain available for compatibility; new clients never fall back automatically.
Native drawing uses pinned skia-safe 0.153.3 without a GPU dependency. Skia CPU surfaces support the existing 100,000,000-pixel limit, including narrow images wider than 65535 pixels. PDF pages use SkPDF. Shadow/glow tiles are rendered with the same Skia filters; only effects become images, preserving vector subjects. A version-pinned object compatibility pass in pdf.rs replaces image markers with original 16-bit color/alpha samples, restores exact physical page bounds, and attaches ActualText to formula/art-text spans. Multipage joining rebases structure-parent trees. Raster policies still select JPEG passthrough, lossless compression, DPI and 16-bit preservation before drawing. SVG and editable DrawingML serializers remain format-specific.
Playback uses RetainedScene: node paths are stable within a scene generation and resources have independent IDs. WASM presentation_state() returns matrices, opacity, visibility and clip bounds for ordinary reveals, keeping unchanged paths in the renderer. frame_state() retains full-geometry sampling; stroke and plot-data reveals preserve its geometry semantics. A transform animation neither clones the scene nor generates RGBA. The adapter retains paths, paints, images and SkPictures by content; edits invalidate changed commands. Pages, drawing commands, text layouts and images are retained by the current document and live revisions, without byte, page-count or category quotas. Unchanged resources survive edits; replaced or deleted resources are released by ownership, and closing the document releases its resources. Static runs and moving groups use GPU tiles at actual display density; transforms and opacity are applied at draw time. Projected density covers the entire object and perspective changes, rebuilding when higher resolution is needed. Ordinary reveals update their clip while reusing retained content layers. Stroke/plot-reveal geometry and animated descendants retain their direct drawing paths. Presentation tracks installation, entry frames and animation warming separately: a prepared entry frame is displayed immediately. Windowed presentations with OffscreenCanvas use independent display and preparation workers. Each page stays in its owning renderer; navigation exchanges foreground roles and transfers only the previous ImageBitmap for cross-renderer transitions. The display buffer retains presented pixels, so handoff neither samples nor redraws the outgoing page. Background snapshots and layers use CPU surfaces at full display density, keeping whole-page warming off the active GPU queue. CPU/GPU edge antialiasing can differ; cross-backend cache comparisons retain their measured pixel differences rather than claiming bitwise equivalence. Compressed pages are unpacked in the worker instead of reconstructed on the UI thread. The first page does not wait for the second runtime, and closing the presentation releases both. Main-thread fallback and presenter mirroring still prepare neighbors only while animation is idle. CPU transitions also use actual display dimensions. Patches replace current scene properties; recovery keeps the current scene instead of accumulating historical transfer sizes. Perspective uses Skia's projective drawing and local saveLayers, with no CPU pixel projection loop. Layer bounds follow object ink when descendants are static; dynamic descendants retain conservative bounds. At most two animation draws remain in flight on the GPU; a busy GPU causes the next animation sample to be deferred, not an older frame to be queued. Static restoration and explicit seeks still render. Surface allocation failure is explicit; resolution never drops automatically.
Both WASM binaries and CanvasKit's standard JS module use same-origin content-hashed names. skia_assets.py verifies the vendored checksums and records raw/gzip/Brotli sizes. The preview server serves adjacent precompressed assets with Content-Encoding and immutable caching for hashed resources. VSIX archives exclude redundant .gz/.br copies and work offline. The original CPU/PDF outputs remain in Git history as regression baselines; neither vello_cpu nor krilla is a runtime dependency.
See animation validation for performance measurement boundaries. The 4K benchmark is copied to /skia-benchmark.html by the documentation build. It uses a fixed 3840×2160 buffer, active motion windows, ten progressive stress levels (or the original three animation scenes) and configurable measured rounds starting with the first real playback, with no warmup or discarded round. Submission timing and browser presentation estimates are separate; they do not establish physical scan-out. A hardware pass requires real GPU/compositor evidence on both target machines with an active 60 Hz display.
The benchmark offers a 60 fps submission cap and a display-refresh mode, both at the same 4K buffer size. A quick run takes one 10-second round per scene. Reports include the WebGL device string, refresh interval statistics, GPU cache usage and delivery shortfall relative to the selected rate. A cap on a 160 Hz display is useful for load comparisons but does not replace a 60 Hz presentation test. The external discrete-GPU measurement is retained as evidence, with integrated-GPU acceptance still pending.