README

mizchi/crater-renderer/vrt does not have a README file

#
ComputedStyleEntry

pub(all) struct ComputedStyleEntry {
id : String
index : Int
display : String
position : String
visibility : String
font_size : String
font_family : String
opacity : String
z_index : String
color : String
background_color : String
} derive(Eq, Show)

Resolved computed style of one element, in the form page JS getComputedStyle reads. index is the pre-order (document-order) position in the render node tree — the same key collect_layout_boxes assigns to the parallel layout tree, so a JS DOM built in the same order can join geometry and computed style by index. Values are serialized as CSS strings (display "flex", color "rgb(255, 0, 0)", font-size "20px"). This is the node-tree analogue of collect_layout_boxes: the data layer a getComputedStyle bridge would inject.

#
CssMutation

pub(all) struct CssMutation {
selector : String
property : String
action : CssMutationAction
} derive(Eq,
Debug
)

impl Show for CssMutation

#
CssMutation::is_paint_only

fn CssMutation::is_paint_only(self : CssMutation) -> Bool

Whether this mutation only affects paint (color/background/opacity/…), not box geometry — i.e. whether a branch carrying only such mutations can reuse the base layout.

#
CssMutationAction

pub(all) enum CssMutationAction {
Remove
Override(String)
} derive(Eq,
Debug
)

#
LayoutBox

pub(all) struct LayoutBox {
id : String
index : Int
x : Double
y : Double
width : Double
height : Double
} derive(Eq, Show)

Absolute geometry of one laid-out box, in the form page JS needs for getBoundingClientRect() / offsetWidth / offsetHeight. index is the pre-order (document-order) position in the layout tree — a stable key a JS DOM built in the same order can match. The crater layout tree already stores absolute viewport coordinates, so x/y are left/top directly.

#
RenderSession

A reusable render "snapshot" for VRT branching. open parses + cascades + lays out + paints the base document once; each branch applies a CSS-mutation delta. A branch can either re-layout fully (branch_full, for geometry- affecting changes) or reuse the base layout (branch_reusing_layout, valid when the delta is paint-only) — the latter skips the dominant layout cost.

#
RenderSession::base_paint_tree

The base (unmutated) paint tree captured at open().

#
RenderSession::branch

Branch with automatic strategy: if every mutation is paint-only the base layout is reused (fast path); otherwise a full re-layout is performed. This is the convenient default — correct for any delta, fast for recolor/theme variants (the common VRT case).

#
RenderSession::branch_diff

Paint-tree diff of an auto-strategy branch against the base.

#
RenderSession::branch_full

Branch with a full re-layout (correct for any mutation, including ones that change box geometry). Re-cascades + re-lays-out + paints from scratch, reusing only the parsed document.

#
RenderSession::branch_full_diff

Paint-tree diff of a full-relayout branch against the base.

#
RenderSession::branch_reusing_layout

Branch reusing the base layout: re-cascade the mutated document but paint it against the base layout, skipping re-layout. Valid only when the mutation is paint-only (it changes paint properties — color, background, opacity, … — not box geometry); for such a delta the layout is identical, so the painted result equals branch_full at a fraction of the cost.

#
RenderSession::branch_reusing_layout_diff

Paint-tree diff of a layout-reusing (paint-only) branch against the base.

#
RenderSession::element_boxes

fn RenderSession::element_boxes(self : RenderSession) -> Array[LayoutBox]

Per-box geometry of the session's base render — the geometry page JS would observe via getBoundingClientRect on the initial layout.

#
RenderSession::element_computed_styles

fn RenderSession::element_computed_styles(self : RenderSession) -> Array[ComputedStyleEntry]

Per-element computed style of the session's base render — what page JS would observe via getComputedStyle on the initial render.

#
RenderSession::layout_bridge_init_js

fn RenderSession::layout_bridge_init_js(self : RenderSession) -> String

The bridge-injection JS for the session's base render — the layout geometry and resolved styles page JS would observe on the initial layout. A host that drives the JS realm (the browser shell over the native V8 runtime) evaluates this before running page scripts so DOM measurement reads crater's real layout. See layout_bridge_init_js.

#
RenderSession::open

fn RenderSession::open(html : String, viewport :
Size
[Double], external_css : Array[String]) -> RenderSession

Parse + cascade + layout + paint the base document once, recording the external text-measurement side effect so branches (and a restored session) reproduce it without a font engine.

#
RenderSession::open_with_recording

Restore a session from a previously recorded measurement set (e.g. one serialized to disk). The base is rendered by replaying measurements, so no font engine is required; branches then reuse the same recording. This is the portable side of the snapshot: capture once with open(), persist session.measurements, reproduce anywhere.

#
RenderSession::recorded_images

The recorded image intrinsic sizes; serialize with @renderer.serialize_image_intrinsic_recording.

#
RenderSession::recorded_measurements

The recorded text measurements; serialize with @renderer.serialize_text_metrics_recording.

#
RenderVariant

pub(all) struct RenderVariant {
id : String
mutations : Array[CssMutation]
} derive(Eq,
Debug
)

#
RenderVariantResult

pub(all) struct RenderVariantResult {
id : String
paint_tree :
PaintNode

}

#
collect_computed_styles

fn collect_computed_styles(node :
Node
) -> Array[ComputedStyleEntry]

Flatten a render node tree into per-element computed style in document order. This is the parallel of collect_layout_boxes for the page-JS getComputedStyle bridge: the node tree carries the resolved @style.Style per element, and the indexes line up with the layout-box indexes so the two can be joined element-for-element.

#
collect_layout_boxes

fn collect_layout_boxes(layout :
Layout
) -> Array[LayoutBox]

Flatten a layout tree into per-box absolute geometry in document order. This is the data layer that connects crater's layout engine to page JS box measurement (the bridge would inject these and have getBoundingClientRect / offsetWidth / offsetHeight read them, keyed by index, instead of the inline-style heuristic the runtime uses today).

#
computed_style_by_id

fn computed_style_by_id(node :
Node
, id_fragment : String) -> ComputedStyleEntry?

The first element whose node id contains id_fragment, for getComputedStyle-by-element lookup.

#
diff_rendered_paint_trees

fn diff_rendered_paint_trees(baseline_html : String, current_html : String, viewport :
Size
[Double]) ->
PaintTreeDiff

#
layout_box_by_id

fn layout_box_by_id(layout :
Layout
, id_fragment : String) -> LayoutBox?

The first box whose layout id contains id_fragment (e.g. an element id like "main#content" or "#sidebar"), for getElementById-style measurement.

#
layout_bridge_init_js

fn layout_bridge_init_js(boxes : Array[LayoutBox], styles : Array[ComputedStyleEntry]) -> String

Serialize the layout-box geometry index and the computed-style index into the JS the dynamic-rendering bridge injects into the page realm before page JS runs. It defines two globals as document-order arrays:

  • globalThis.__craterLayoutBoxes{index, id, x, y, width, height}
  • globalThis.__craterComputedStyles{index, id, display, position,visibility, fontSize, fontFamily, opacity, zIndex, color, backgroundColor}

Each entry carries both the pre-order index and the tag#id id string so the mock DOM can join an element to its real geometry / resolved style by id (unique when the element has an id attribute) or, failing that, by document-order index. With these present, getBoundingClientRect / offsetWidth / offsetHeight / getComputedStyle read crater's real layout instead of the inline-style heuristic. This is the JS payload half of step (1) "expose real layout to page JS" in docs/dynamic-rendering-js-bridge-design.md; the mock-DOM consumer lives in browser/native/js_v8/mock_dom_full.mbt.

#
prepare_external_css

fn prepare_external_css(external_css : Array[String]) ->
PreparedExternalCss

#
prepare_vrt_page

fn prepare_vrt_page(html : String, viewport :
Size
[Double], external_css : Array[String]) -> PreparedVrtPage

#
prepare_vrt_page_with_prepared_external_css

fn prepare_vrt_page_with_prepared_external_css(html : String, viewport :
Size
[Double], external_css :
PreparedExternalCss
) -> PreparedVrtPage

#
render_html_batch_variants

fn render_html_batch_variants(html : String, viewport :
Size
[Double], variants : Array[RenderVariant]) -> Array[RenderVariantResult]

#
render_html_to_paint_tree

fn render_html_to_paint_tree(html : String, viewport :
Size
[Double]) ->
PaintNode

#
render_html_to_paint_tree_json

fn render_html_to_paint_tree_json(html : String, viewport :
Size
[Double]) -> String

#
render_html_to_paint_tree_with_external_css

fn render_html_to_paint_tree_with_external_css(html : String, viewport :
Size
[Double], external_css : Array[String]) ->
PaintNode

#
render_html_to_paint_tree_with_prepared_external_css

fn render_html_to_paint_tree_with_prepared_external_css(html : String, viewport :
Size
[Double], external_css :
PreparedExternalCss
) ->
PaintNode

#
render_prepared_vrt_page_to_paint_tree

fn render_prepared_vrt_page_to_paint_tree(page : PreparedVrtPage) ->
PaintNode

#
render_prepared_vrt_page_to_paint_tree_json

fn render_prepared_vrt_page_to_paint_tree_json(page : PreparedVrtPage) -> String

Source Files