How poxk/falco works
Purpose and entry points
Falco is a Rust browser engine that renders local HTML or HTTP URLs to PNG, or runs an interactive desktop browser window. The CLI is src/main.rs; reusable rendering APIs and the primary render orchestration are in src/lib.rs. Cargo defines the Rust package and feature boundaries in Cargo.toml.
Active rendering pipeline
The active path is legacy HTML/CSS/DOM compatibility code:
1. Parse HTML into a legacy DOM.
2. Extract/merge document and optional external CSS, then cascade styles.
3. Build layout boxes and paint into a canvas.
4. Encode PNG or present the canvas in a window.
Core stages: src/html/mod.rs, src/dom/mod.rs, src/css/mod.rs, src/style/mod.rs, src/layout/mod.rs, src/paint/mod.rs, src/png/mod.rs.
JavaScript mutation bridge
Before final layout, inline scripts execute in Falco’s custom JS runtime. The renderer converts the legacy DOM to the newer spec DOM, attaches it to the JS context, runs scripts, serializes mutated spec DOM back to HTML, then reparses it through the legacy rendering path. This is the key compatibility boundary between JS mutation and legacy layout. Relevant paths: src/js_runner.rs, src/js_tjs.rs, src/tjs/mod.rs, src/html/spec/serializer.rs.
Styling and geometry
style applies UA defaults, inheritance, and cascade results to DOM nodes. layout consumes styled nodes and handles block/inline flow plus flex, grid, table, float, and absolute positioning; specialized algorithms are split by layout mode. Painting consumes layout output for text, box decoration, gradients, shadows, alpha compositing, and SVG content. Paths: src/style/mod.rs, src/layout/mod.rs, src/layout/grid.rs, src/layout/table.rs, src/paint/mod.rs, src/svg/renderer.rs.
Resource loading and outputs
Inputs can be local files, HTTP URLs, data URLs, and image resources. HTTP/1.1 loading currently uses ureq; images are decoded/scaled and incorporated into paint. PNG is emitted by an in-repo encoder. Interactive mode owns navigation, history, input/focus, scrolling, and cached incremental redraw. Paths: src/net/mod.rs, src/image/mod.rs, src/png/mod.rs, src/window/mod.rs.
Alternate/spec and runtime subsystems
Spec-compliant HTML parsing, DOM features, and CSS Selectors 4 exist but are mostly not wired into the renderer; serializer/spec DOM are exceptions used by the JS bridge. Async web APIs and security algorithms are similarly largely scaffolded or unenforced. Key paths: src/html/spec/tokenizer.rs, src/html/spec/tree_builder.rs, src/dom/spec/mod.rs, src/css/spec/mod.rs, src/web_runtime/event_loop.rs, src/security/mod.rs.
Runtime and platform boundaries
The engine is a Rust native binary/library. The JS engine is in-process, with interpreter/VM and a Linux x86_64-specific JIT path. Desktop window mode requires a display and falls back to PNG headlessly. Network access uses HTTP/1.1 through ureq; HTTP/2, WebSocket, caching, cookies, TLS/security validation, WebGL/video, and sandbox facilities exist in separate modules but are not all active in rendering. Paths: src/tjs/interpreter.rs, src/tjs/jit.rs, src/net/cookies.rs, src/net/websocket.rs, src/security/cert.rs.
Main entry points: net/mod.rs Resource loader · spec/mod.rs Spec DOM · dom/mod.rs Legacy DOM · paint/mod.rs Painter
Components 21
Host & output
- Cargo package · Defines package and feature boundaries.
Cargo.toml - CLI entry point · Renders URLs to PNG or starts desktop mode.
src/main.rs - Render orchestration · Coordinates loading, scripting, layout, and output.
src/lib.rs - PNG encoder · In-repository PNG emission.
src/png/mod.rs - Interactive window · Owns navigation, input, scrolling, history, and redraw cache.
src/window/mod.rs
Active render pipeline
- Legacy HTML parser
src/html/mod.rs - Legacy DOM
src/dom/mod.rs - CSS extraction & parse · Merges document and external stylesheets.
src/css/mod.rs - Style cascade · Applies UA defaults, inheritance, and cascade.
src/style/mod.rs - Layout engine · Handles flow, flex, grid, tables, floats, and positioning.
src/layout/mod.rs - Painter · Draws text, decorations, compositing, and SVG.
src/paint/mod.rs
JavaScript bridge
- Script mutation bridge · Converts between legacy rendering and script-visible spec DOM.
src/js_runner.rs - Custom JS runtime · Interpreter with Linux x86_64 JIT path.
src/tjs/mod.rs - Spec DOM serializer · Returns mutated script DOM as HTML for legacy reparse.
src/html/spec/serializer.rs
Resources
- Resource loader · Loads local, HTTP, data URL, and external resources via ureq.
src/net/mod.rs - Image decode & scale
src/image/mod.rs
Alternate/spec subsystems
Mostly scaffolded outside the active renderer.
- Spec DOM · Used by the JavaScript bridge; otherwise not the active render DOM.
src/dom/spec/mod.rs - Spec HTML parser · Tokenizer and tree builder are mostly unwired to rendering.
src/html/spec/tokenizer.rs - Spec CSS/selectors · Selectors 4 subsystem is mostly outside active rendering.
src/css/spec/mod.rs - Web runtime · Event-loop APIs are largely scaffolded.
src/web_runtime/event_loop.rs - Security subsystem · Validation and sandbox facilities are not fully enforced.
src/security/mod.rs
Connections 25
- Cargo package → CLI entry point: builds
- CLI entry point → Render orchestration: invokes
- Render orchestration → Resource loader: loads input/resources
- Resource loader → Legacy HTML parser: HTML source
- Legacy HTML parser → Legacy DOM: parses to
- Legacy DOM → Script mutation bridge: before final layout
- Script mutation bridge → Spec DOM: converts to
- Script mutation bridge → Custom JS runtime: executes inline scripts
- Custom JS runtime → Spec DOM: mutates
- Spec DOM → Spec DOM serializer: serializes
- Spec DOM serializer → Legacy HTML parser: reparse mutated HTML
- Legacy DOM → CSS extraction & parse: extracts styles
- Resource loader → CSS extraction & parse: external CSS
- CSS extraction & parse → Style cascade: cascade input
- Legacy DOM → Style cascade: nodes
- Style cascade → Layout engine: styled nodes
- Layout engine → Painter: layout boxes
- Resource loader → Image decode & scale: image resources
- Image decode & scale → Painter: decoded images
- Painter → PNG encoder: canvas
- Painter → Interactive window: canvas
- Spec HTML parser → Spec DOM: builds
- Spec CSS/selectors → Spec DOM: selector support
- Web runtime → Custom JS runtime: runtime APIs
- Security subsystem → Resource loader: security support