README

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

#
ImageIntrinsicSizeProvider

pub struct ImageIntrinsicSizeProvider {
func : (String) -> (Double, Double)?
}

Image intrinsic-size provider hook for integrating external image metadata resolvers.

#
ImageIntrinsicSizeProvider::new

fn ImageIntrinsicSizeProvider::new(func : (String) -> (Double, Double)?) -> ImageIntrinsicSizeProvider

#
PreparedExternalCss

pub struct PreparedExternalCss {
stylesheets : Array[
Stylesheet
]
indexed_stylesheets : Array[
IndexedStylesheet
]
before_rules : Array[PseudoRule]
after_rules : Array[PseudoRule]
before_index : PseudoRuleIndex
after_index : PseudoRuleIndex
total_rules : Int
}

#
PreparedRenderDocument

pub struct PreparedRenderDocument {
stylesheets : Array[
Stylesheet
]
indexed_stylesheets : Array[
IndexedStylesheet
]
css_vars : Map[String, String]
doc_root_selector :
Element

doc_root_style :
Style

render_root :
Element

render_root_tag : String
body_uses_document_root_style : Bool
suppress_quirks_body_ua_top_margin : Bool
before_index : PseudoRuleIndex
after_index : PseudoRuleIndex
}

#
PseudoRule

pub struct PseudoRule {
base_selector :
ComplexSelector
?
base_selector_text : String
declarations : Array[
Declaration
]
media_query :
MediaQueryList
?
}

#
PseudoRuleIndex

pub struct PseudoRuleIndex {
rules : Array[PseudoRule]
by_id : Map[String, Array[Int]]
by_class : Map[String, Array[Int]]
by_tag : Map[String, Array[Int]]
universal : Array[Int]
}

Indexed pseudo rules for fast lookup (same strategy as SelectorIndex)

#
RecordedImage

pub(all) struct RecordedImage {
src : String
has_size : Bool
width : Double
height : Double
}

A single recorded image intrinsic size lookup: the source and its result (has_size = false records a provider that returned "no intrinsic size").

#
RecordedMetric

pub(all) struct RecordedMetric {
key : String
min_width : Double
max_width : Double
min_height : Double
max_height : Double
}

A single recorded measurement: the encoded measurement key and its result.

#
RenderContext

pub(all) struct RenderContext {
viewport_width : Double
viewport_height : Double
root_font_size : Double
color_scheme :
ColorScheme

}

Render context with viewport dimensions

#
RenderContext::default

fn RenderContext::default() -> RenderContext

#
TextMetricsProvider

pub struct TextMetricsProvider {
func : (String, Double, Double,
WhiteSpace
,
WritingMode
, Double, String) ->
MeasureFunc

}

Text metrics provider hook for integrating external font engines.

#
apply_css_property_debug

fn apply_css_property_debug(style :
Style
, property : String, value : String) ->
Style

Apply a CSS property value to a style (public for testing)

#
build_render_root_node

#
cascade_reuse_begin

fn cascade_reuse_begin(prior_styles : Map[String,
Style
], prior_sigs : Map[String, String], uses_sibling? : Bool, uses_child_structure? : Bool) -> Unit

Start a cascade-reuse pass. prior_styles / prior_sigs are keyed by owner_id from the previous render (pass empty maps to record-only, i.e. no reuse). The build records the new styles + signatures; retrieve them with cascade_reuse_end to seed the next reflow. Only call around a build_render_root_node when the stylesheet is unchanged and reuse-safe.

#
cascade_reuse_end

fn cascade_reuse_end() -> (Map[String,
Style
], Map[String, String], Int)

End the pass: returns (new styles by owner_id, new signatures by owner_id, reused count) and clears the active context. The maps become the next reflow's prior maps.

#
clear_builtin_text_advance_ratio_override_for_test

fn clear_builtin_text_advance_ratio_override_for_test() -> Unit

Clear the deterministic built-in text measurement hook.

#
clear_image_intrinsic_record_replay

fn clear_image_intrinsic_record_replay() -> Unit

#
clear_image_intrinsic_size_provider

fn clear_image_intrinsic_size_provider() -> Unit

#
clear_text_metrics_provider

fn clear_text_metrics_provider() -> Unit

#
clear_text_metrics_record_replay

fn clear_text_metrics_record_replay() -> Unit

Disable both recording and replay.

#
compute_composed_shadow_styles

fn compute_composed_shadow_styles(tree :
DomTree
, ctx : RenderContext) -> Map[Int,
Style
]

Composed shadow-scoped styling for a whole DomTree (#285, PR 6).

Walks the light DOM from the document root and folds together every shadow host's contribution into one NodeId::to_int-keyed style map:

  • each host plus its shadow-subtree elements via compute_shadow_tree_styles (PR 3), threading inheritance across the boundary;
  • the host's slotted light children's ::slotted(...) contribution via compute_slotted_styles (PR 5);
  • nested shadow roots: a host living inside another host's shadow tree (or slotted into one) is composed too, inheriting from its own computed style.

The returned map covers shadow hosts, shadow-subtree elements, and slotted light nodes. Plain light nodes that are neither hosts nor slotted are absent: the DomTree has no document-scope cascade, so this is the shadow-scoped composition only. It is the capstone over the PR 1-5 building blocks.

#
compute_layout_from_render_root

fn compute_layout_from_render_root(root :
Node
, prepared : PreparedRenderDocument, ctx : RenderContext) ->
Layout

#
compute_shadow_element_style

Shadow-tree static styling (#285, PR 3).

Compute a concrete @style.Style for a node that lives inside a shadow tree (the host, a slotted light node, or an inner shadow node) by running that shadow root's <style> rules through DomTree::shadow_cascaded_values (PR 1, shadow-scoped matching) and folding the result through the renderer's shared post-cascade pipeline apply_cascaded_to_style (PR 2).

rules is the shadow root's parsed stylesheet, obtained once via DomTree::shadow_stylesheet_rules, so a caller styling many nodes does not re-parse <style> per node. parent_style carries inherited context across the shadow boundary (the host's style for top-level shadow nodes).

This is a building block; the composed-tree render entry (PR 4) walks the DomTree and calls it for shadow-scoped nodes.

#
compute_shadow_tree_styles

Compute @style.Style for the shadow host and every element in its shadow tree, keyed by node id (NodeId::to_int). The host is styled by its :host rules and inherits from host_parent_style (its light-DOM context); each shadow node inherits from its parent's computed style, threading inheritance across the shadow boundary (host -> top-level shadow nodes -> descendants).

<style> elements and non-element nodes are skipped. Returns an empty map when host has no shadow root. Slotted light nodes are styled from the light tree, not here.

#
compute_slotted_styles

Compute the shadow-scoped @style.Style contribution for the host's slotted light children, keyed by node id. A light child assigned to a slot in the host's shadow tree is matched against that shadow's ::slotted(...) rules (via compute_shadow_element_style, PR 3) and inherits from host_style (its light-DOM parent context).

Only element light children that are actually assigned to a slot are included; non-slotted children and non-elements are skipped. This is the shadow-side contribution only — a slotted node's document/light styles come from the light tree and are merged by the (deferred) composed-tree walk. Returns an empty map when host has no shadow root.

#
crater_dom_id_attr

let crater_dom_id_attr : String

Internal attribute the dynamic-rendering path stamps onto a render @html.Element to carry its originating @dom.DomTree node id through to the render @node.Node (see attach_dom_id). It lives only on the derived render document, never on the DomTree, so it is not serialized into html_content; the cascade ignores it (html_to_selector_element filters it out).

#
css_allows_cascade_reuse

fn css_allows_cascade_reuse(texts : Array[String]) -> Bool

Whether the given raw CSS texts are safe for scoped cascade reuse: they must use no selector whose match can flip without a change in an element's own inputs or its ancestors' inputs. Conservative and cheap: a substring scan for the disqualifying selector features. A false positive (e.g. + inside a calc() value) only disables the optimization — never a correctness risk.

#
css_uses_child_structure

fn css_uses_child_structure(texts : Array[String]) -> Bool

Whether any CSS text uses a selector whose match depends on child structure: :empty/:blank (own child/text presence) or positional-from-end / only / of-type (:last-child, :only-child, :nth-last-*, *-of-type — read the parent's child list). When true, each element's reuse signature includes a summary of its direct children. Conservative substring scan; a false positive only tightens reuse.

#
css_uses_sibling_combinator

fn css_uses_sibling_combinator(texts : Array[String]) -> Bool

Whether any CSS text uses a sibling combinator (+ or ~). Conservative: a substring match (so calc(a + b) or [attr~=v] also counts) — a false positive only tightens the preceding-sibling gate, never a correctness risk. When true, cascade reuse requires every preceding sibling to be clean.

#
deserialize_image_intrinsic_recording

fn deserialize_image_intrinsic_recording(data : String) -> Array[RecordedImage]

#
deserialize_text_metrics_recording

fn deserialize_text_metrics_recording(data : String) -> Array[RecordedMetric]

Parse a recording produced by serialize_text_metrics_recording.

#
element_to_node

Convert HTML Element to Node tree for layout computation

#
get_content_height

fn get_content_height(html : String, width : Int, height : Int) -> Int

Get content height from HTML

#
get_content_height_with_css

fn get_content_height_with_css(html : String, width : Int, height : Int, external_css : Array[String]) -> Int

Get content height with external CSS

#
get_content_height_with_document

fn get_content_height_with_document(doc :
Document
, width : Int, height : Int, external_css : Array[String]) -> Int

Get content height from a parsed Document with external CSS

#
get_force_monospace_metrics

fn get_force_monospace_metrics() -> Bool

#
install_image_intrinsic_replay

fn install_image_intrinsic_replay(images : Array[RecordedImage]) -> Unit

#
install_text_metrics_replay

fn install_text_metrics_replay(metrics : Array[RecordedMetric]) -> Unit

Serve text measurements from metrics (replay mode); a measurement not in the recording falls back to the live measure func. Clears any active recording.

#
layout_to_json

fn layout_to_json(layout :
Layout
) -> String

Convert layout to JSON string (with Box Model)

#
perf_child_loop_us

let perf_child_loop_us :
Ref
[Int64]

#
perf_clock_us

fn perf_clock_us() -> Int64

#
perf_node_build_us

let perf_node_build_us :
Ref
[Int64]

#
perf_pre_checks_us

let perf_pre_checks_us :
Ref
[Int64]

#
perf_pseudo_us

let perf_pseudo_us :
Ref
[Int64]

#
perf_selector_build_us

let perf_selector_build_us :
Ref
[Int64]

#
prepare_external_css

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

#
prepare_render_document

fn prepare_render_document(doc :
Document
, ctx : RenderContext, external_css : Array[String]) -> PreparedRenderDocument

#
prepare_render_document_with_prepared_external_css

fn prepare_render_document_with_prepared_external_css(doc :
Document
, ctx : RenderContext, external_css : PreparedExternalCss) -> PreparedRenderDocument

fn print_layout_tree(layout :
Layout
, indent : Int) -> Unit

Print layout tree for debugging
fn print_layout_tree_with_options(layout :
Layout
, indent : Int, show_box_model : Bool) -> Unit

Print layout tree with optional detailed box model info

#
render

fn render(html : String, ctx : RenderContext) ->
Layout

Render HTML string to Layout

#
render_document_with_external_css

fn render_document_with_external_css(doc :
Document
, ctx : RenderContext, external_css : Array[String]) ->
Layout

Render a parsed HTML Document to Layout with external CSS This is useful when you need to pre-process the document (e.g., add synthetic IDs)

#
render_document_with_prepared_external_css

fn render_document_with_prepared_external_css(doc :
Document
, ctx : RenderContext, external_css : PreparedExternalCss) ->
Layout

Render a parsed HTML Document to Layout with a prepared external CSS handle.

#
render_to_node

fn render_to_node(html : String, ctx : RenderContext) ->
Node

Render HTML to Node tree (for testing/debugging)

#
render_to_node_and_layout

fn render_to_node_and_layout(html : String, ctx : RenderContext) -> (
Node
,
Layout
)

Render HTML to Node tree and Layout in a shared pass.

#
render_to_node_and_layout_full_document

fn render_to_node_and_layout_full_document(html : String, ctx : RenderContext) -> (
Node
,
Layout
)

Render the whole document without viewport skeleton culling.

#
render_to_node_and_layout_with_document

fn render_to_node_and_layout_with_document(doc :
Document
, ctx : RenderContext, external_css : Array[String]) -> (
Node
,
Layout
)

Render a parsed HTML Document to Node tree and Layout with external CSS while sharing HTML/CSS preparation and node construction.

#
render_to_node_and_layout_with_external_css

fn render_to_node_and_layout_with_external_css(html : String, ctx : RenderContext, external_css : Array[String]) -> (
Node
,
Layout
)

Render HTML to Node tree and Layout with external CSS in a shared pass.

#
render_to_node_and_layout_with_prepared_external_css

fn render_to_node_and_layout_with_prepared_external_css(doc :
Document
, ctx : RenderContext, external_css : PreparedExternalCss) -> (
Node
,
Layout
)

Render a parsed HTML Document to Node tree and Layout with a prepared external CSS handle.

#
render_to_node_with_document

fn render_to_node_with_document(doc :
Document
, ctx : RenderContext, external_css : Array[String]) ->
Node

Render a parsed HTML Document to Node tree with external CSS This is useful when you need to use a pre-parsed document (e.g., from streaming parser)

#
render_to_node_with_external_css

fn render_to_node_with_external_css(html : String, ctx : RenderContext, external_css : Array[String]) ->
Node

Render HTML to Node tree with external CSS

#
render_to_node_with_prepared_external_css

fn render_to_node_with_prepared_external_css(doc :
Document
, ctx : RenderContext, external_css : PreparedExternalCss) ->
Node

Render a parsed HTML Document to Node tree with a prepared external CSS handle.

#
render_with_external_css

fn render_with_external_css(html : String, ctx : RenderContext, external_css : Array[String]) ->
Layout

Render HTML string to Layout with external CSS

#
serialize_image_intrinsic_recording

fn serialize_image_intrinsic_recording(images : Array[RecordedImage]) -> String

Serialize image recordings (length-prefixed src, so any URL round-trips).

#
serialize_text_metrics_recording

fn serialize_text_metrics_recording(metrics : Array[RecordedMetric]) -> String

Serialize a recording to a self-delimiting string (length-prefixed keys, so arbitrary text/newlines in keys round-trip safely).

#
set_builtin_text_advance_ratio_override_for_test

fn set_builtin_text_advance_ratio_override_for_test(ratio : Double) -> Unit

Test-only hook for deterministic built-in text measurement.

#
set_force_monospace_metrics

fn set_force_monospace_metrics(enabled : Bool) -> Unit

#
set_image_intrinsic_size_provider

fn set_image_intrinsic_size_provider(provider : ImageIntrinsicSizeProvider) -> Unit

#
set_text_metrics_provider

fn set_text_metrics_provider(provider : TextMetricsProvider) -> Unit

#
start_image_intrinsic_recording

fn start_image_intrinsic_recording() -> Unit

Begin recording image intrinsic sizes. Clears any active image replay.

#
start_text_metrics_recording

fn start_text_metrics_recording() -> Unit

Begin recording text measurements. Clears any active replay.

#
take_image_intrinsic_recording

fn take_image_intrinsic_recording() -> Array[RecordedImage]

#
take_text_metrics_recording

fn take_text_metrics_recording() -> Array[RecordedMetric]

Stop recording and return everything captured since start.