Sign in

    mizchi/crater/dom does not have a README file

    CoreError

    pub enum CoreError {
    NodeNotFound(NodeId)
    InvalidOperation(String)
    }

    Core error types
    impl Show for CoreError

    DomNode

    type DomNode

    Internal DOM node representation

    DomTree

    pub struct DomTree {
    next_id : Int
    nodes : Map[Int, DomNode]
    root_id : Int
    focused_node : Int?
    mutations : MutationQueue
    }

    DOM Tree - the core document structure This is the single source of truth for all DOM operations

    DomTree::append_child

    fn DomTree::append_child(self : DomTree, parent : NodeId, child : NodeId) -> Result[Unit, CoreError]

    Append child to parent

    DomTree::clear_mutations

    fn DomTree::clear_mutations(self : DomTree) -> Unit

    Clear all pending mutations without processing

    DomTree::create_comment

    fn DomTree::create_comment(self : DomTree, content : String) -> NodeId

    Create a comment node

    DomTree::create_element

    fn DomTree::create_element(self : DomTree, tag_name : String) -> NodeId

    Create an element node

    DomTree::create_text

    fn DomTree::create_text(self : DomTree, content : String) -> NodeId

    Create a text node

    DomTree::flush_mutations

    fn DomTree::flush_mutations(self : DomTree) -> (Array[MutationRecord], FlushResult)

    Flush pending mutations and return optimized records Returns (records, result) where records is the optimized mutation list and result contains statistics about the flush operation

    DomTree::flush_mutations_with

    fn[T] DomTree::flush_mutations_with(self : DomTree, handler : (MutationRecord) -> T) -> (Array[T], FlushResult)

    Flush mutations with a custom handler for each record Useful for applying mutations to other systems (e.g., LayoutTree)

    DomTree::get_attribute

    fn DomTree::get_attribute(self : DomTree, node : NodeId, name : String) -> Result[String?, CoreError]

    Get attribute from element

    DomTree::get_attributes

    fn DomTree::get_attributes(self : DomTree, node : NodeId) -> Result[Array[(String, String)], CoreError]

    Get all attributes

    DomTree::get_cached_rect

    fn DomTree::get_cached_rect(self : DomTree, node : NodeId) -> Rect?

    Get cached rect

    DomTree::get_children

    fn DomTree::get_children(self : DomTree, node : NodeId) -> Result[Array[NodeId], CoreError]

    Get child nodes

    DomTree::get_document

    fn DomTree::get_document(self : DomTree) -> NodeId

    Get document root

    DomTree::get_first_child

    fn DomTree::get_first_child(self : DomTree, node : NodeId) -> Result[NodeId?, CoreError]

    Get first child

    DomTree::get_focus

    fn DomTree::get_focus(self : DomTree) -> NodeId?

    Get focused element

    DomTree::get_mutation_queue

    fn DomTree::get_mutation_queue(self : DomTree) -> MutationQueue

    Get direct access to the mutation queue (for advanced use cases)

    DomTree::get_next_sibling

    fn DomTree::get_next_sibling(self : DomTree, node : NodeId) -> Result[NodeId?, CoreError]

    Get next sibling

    DomTree::get_node_info

    fn DomTree::get_node_info(self : DomTree, node : NodeId) -> Result[NodeInfo, CoreError]

    Get node info

    DomTree::get_parent

    fn DomTree::get_parent(self : DomTree, node : NodeId) -> Result[NodeId?, CoreError]

    Get parent node

    DomTree::get_tag_name

    fn DomTree::get_tag_name(self : DomTree, node : NodeId) -> Result[String, CoreError]

    Get tag name

    DomTree::get_text_content

    fn DomTree::get_text_content(self : DomTree, node : NodeId) -> Result[String, CoreError]

    Get text content

    DomTree::has_pending_mutations

    fn DomTree::has_pending_mutations(self : DomTree) -> Bool

    Check if there are pending mutations

    DomTree::insert_before

    fn DomTree::insert_before(self : DomTree, parent : NodeId, child : NodeId, reference : NodeId?) -> Result[Unit, CoreError]

    Insert child before reference node

    DomTree::new

    fn DomTree::new() -> DomTree

    Create a new empty DOM tree

    DomTree::pending_mutation_count

    fn DomTree::pending_mutation_count(self : DomTree) -> Int

    Get number of pending mutations

    DomTree::query_selector

    fn DomTree::query_selector(self : DomTree, root : NodeId, selector : String) -> Result[NodeId?, CoreError]

    Query selector (simple CSS selector support) Returns first matching node

    DomTree::query_selector_all

    fn DomTree::query_selector_all(self : DomTree, root : NodeId, selector : String) -> Result[Array[NodeId], CoreError]

    Query selector all Returns all matching nodes

    DomTree::remove_attribute

    fn DomTree::remove_attribute(self : DomTree, node : NodeId, name : String) -> Result[Unit, CoreError]

    Remove attribute from element

    DomTree::remove_child

    fn DomTree::remove_child(self : DomTree, parent : NodeId, child : NodeId) -> Result[Unit, CoreError]

    Remove child from parent

    DomTree::set_attribute

    fn DomTree::set_attribute(self : DomTree, node : NodeId, name : String, value : String) -> Result[Unit, CoreError]

    Set attribute on element

    DomTree::set_cached_rect

    fn DomTree::set_cached_rect(self : DomTree, node : NodeId, rect : Rect) -> Unit

    Set cached rect (called by layout engine)

    DomTree::set_focus

    fn DomTree::set_focus(self : DomTree, node : NodeId?) -> Unit

    Set focused element

    DomTree::set_text_content

    fn DomTree::set_text_content(self : DomTree, node : NodeId, content : String) -> Result[Unit, CoreError]

    Set text content

    FlushResult

    pub struct FlushResult {
    processed : Int
    nodes_affected : Int
    needs_layout : Bool
    }

    Result of flushing the mutation queue
    impl Show for FlushResult

    MutationQueue

    pub struct MutationQueue {
    records : Array[MutationRecord]
    dirty_nodes : Map[Int, Bool]
    is_flushing : Bool
    deferred : Array[MutationRecord]
    }

    Queue for batching mutations

    MutationQueue::clear

    fn MutationQueue::clear(self : MutationQueue) -> Unit

    Clear all pending mutations without processing

    MutationQueue::flush

    Flush the queue and return optimized records for processing The caller is responsible for applying these to the layout tree

    MutationQueue::flush_with

    fn[T] MutationQueue::flush_with(self : MutationQueue, handler : (MutationRecord) -> T) -> (Array[T], FlushResult)

    Process mutations with a callback for each record Returns the flush result

    MutationQueue::has_pending

    fn MutationQueue::has_pending(self : MutationQueue, node : NodeId) -> Bool

    Check if a node has pending mutations

    MutationQueue::is_empty

    fn MutationQueue::is_empty(self : MutationQueue) -> Bool

    Check if queue is empty

    MutationQueue::length

    fn MutationQueue::length(self : MutationQueue) -> Int

    Get number of pending mutations

    MutationQueue::new

    Create a new empty mutation queue

    MutationQueue::optimize

    Optimize the queue by merging related mutations

    MutationQueue::push

    fn MutationQueue::push(self : MutationQueue, record : MutationRecord) -> Unit

    Add a mutation record to the queue

    MutationRecord

    pub struct MutationRecord {
    type_ : MutationType
    target : NodeId
    added_nodes : Array[NodeId]
    removed_nodes : Array[NodeId]
    attribute_name : String?
    old_value : String?
    new_value : String?
    changed_properties : Array[String]
    }

    Record of a single DOM mutation

    MutationRecord::affects_layout

    fn MutationRecord::affects_layout(self : MutationRecord) -> Bool

    Check if this mutation affects layout (vs paint-only)

    MutationRecord::attribute

    fn MutationRecord::attribute(target : NodeId, name : String, old_value? : String?, new_value? : String?) -> MutationRecord

    Create an Attributes mutation record

    MutationRecord::character_data

    fn MutationRecord::character_data(target : NodeId, old_value? : String?, new_value? : String?) -> MutationRecord

    Create a CharacterData mutation record

    MutationRecord::child_list

    fn MutationRecord::child_list(target : NodeId, added? : Array[NodeId], removed? : Array[NodeId]) -> MutationRecord

    Create a ChildList mutation record

    MutationRecord::style_change

    fn MutationRecord::style_change(target : NodeId, properties : Array[String]) -> MutationRecord

    Create a StyleChange mutation record

    MutationType

    pub enum MutationType {
    ChildList
    Attributes
    CharacterData
    StyleChange
    }

    Type of DOM mutation
    impl Eq for MutationType

    NodeId

    pub type NodeId Int

    Node identifier - opaque handle to a DOM node
    impl Eq for NodeId
    impl Hash for NodeId
    impl Show for NodeId

    NodeId::from_int

    fn NodeId::from_int(id : Int) -> NodeId

    Create NodeId from Int

    NodeId::inner

    #deprecated("Use `struct T(A)` to declare a newtype and use `.0` access the underlying type instead.")
    fn NodeId::inner(self : NodeId) -> Int
    Convert newtype to its underlying type, automatically derived.

    NodeId::to_int

    fn NodeId::to_int(self : NodeId) -> Int

    Get Int value from NodeId

    NodeInfo

    pub struct NodeInfo {
    node_id : NodeId
    node_type : NodeType
    node_name : String
    node_value : String
    child_count : Int
    }

    Basic node information
    impl Show for NodeInfo

    NodeType

    pub enum NodeType {
    Document
    DocumentType
    Element
    Text
    Comment
    }

    Node type enumeration
    impl Eq for NodeType
    impl Show for NodeType

    NodeType::from_dom_constant

    fn NodeType::from_dom_constant(value : Int) -> NodeType?

    Convert DOM node type constant to NodeType See: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType

    Point

    pub struct Point {
    x : Double
    y : Double
    }

    2D Point
    impl Eq for Point
    impl Show for Point

    Rect

    pub struct Rect {
    x : Double
    y : Double
    width : Double
    height : Double
    }

    Rectangle with position and size
    impl Eq for Rect
    impl Show for Rect

    Rect::center

    fn Rect::center(self : Rect) -> Point

    Convert Rect to center point

    Rect::new

    fn Rect::new(x : Double, y : Double, width : Double, height : Double) -> Rect

    Create a new Rect