pub struct Dom { /* private fields */ }Expand description
Arena-allocated DOM tree. All nodes live in a flat Vec, referenced by NodeId.
Implementations§
Source§impl Dom
impl Dom
Sourcepub fn get_mut(&mut self, id: NodeId) -> Option<&mut Node>
pub fn get_mut(&mut self, id: NodeId) -> Option<&mut Node>
Get a mutable reference to a node by ID.
pub fn is_empty(&self) -> bool
pub fn create_element( &mut self, name: QualName, attrs: Vec<Attribute>, ) -> NodeId
pub fn create_text(&mut self, text: String) -> NodeId
pub fn create_comment(&mut self, text: String) -> NodeId
pub fn create_document_fragment(&mut self) -> NodeId
Sourcepub fn create_shadow_root(
&mut self,
host: NodeId,
mode: ShadowRootMode,
) -> NodeId
pub fn create_shadow_root( &mut self, host: NodeId, mode: ShadowRootMode, ) -> NodeId
Create a shadow root and attach it to the given host element.
pub fn allocate_pi(&mut self, target: String, data: String) -> NodeId
pub fn create_doctype( &mut self, name: String, public_id: String, system_id: String, ) -> NodeId
Sourcepub fn append_child(&mut self, parent: NodeId, child: NodeId)
pub fn append_child(&mut self, parent: NodeId, child: NodeId)
Append child as the last child of parent.
Cycle-safe: if child is an ancestor of parent, the mutation is a no-op.
Sourcepub fn insert_before(
&mut self,
parent: NodeId,
child: NodeId,
reference: NodeId,
)
pub fn insert_before( &mut self, parent: NodeId, child: NodeId, reference: NodeId, )
Insert child before reference (which must be a child of parent).
Sourcepub fn remove(&mut self, id: NodeId)
pub fn remove(&mut self, id: NodeId)
Remove a node from the arena entirely (recycles its slot).
Sourcepub fn reparent_children(&mut self, source: NodeId, target: NodeId)
pub fn reparent_children(&mut self, source: NodeId, target: NodeId)
Move all children of source to become children of target.
Sourcepub fn child_elements(&self, parent: NodeId) -> Vec<NodeId>
pub fn child_elements(&self, parent: NodeId) -> Vec<NodeId>
Iterate over child element node IDs (skip text/comment nodes).
Sourcepub fn text_content(&self, id: NodeId) -> String
pub fn text_content(&self, id: NodeId) -> String
Get text content of a subtree.
Sourcepub fn set_text_content(&mut self, id: NodeId, text: &str)
pub fn set_text_content(&mut self, id: NodeId, text: &str)
Set text content: remove all children, add a single text node.
Sourcepub fn get_element_by_id(&self, id_value: &str) -> Option<NodeId>
pub fn get_element_by_id(&self, id_value: &str) -> Option<NodeId>
Find an element by ID attribute (tree walk from document root).
Sourcepub fn get_elements_by_tag_name(&self, root: NodeId, tag: &str) -> Vec<NodeId>
pub fn get_elements_by_tag_name(&self, root: NodeId, tag: &str) -> Vec<NodeId>
Find elements by tag name (case-insensitive).
Sourcepub fn get_elements_by_class_name(
&self,
root: NodeId,
class: &str,
) -> Vec<NodeId>
pub fn get_elements_by_class_name( &self, root: NodeId, class: &str, ) -> Vec<NodeId>
Find elements by class name.
Sourcepub fn serialize_html(&self, id: NodeId) -> String
pub fn serialize_html(&self, id: NodeId) -> String
Serialize a subtree as HTML.
Sourcepub fn serialize_inner_html(&self, id: NodeId) -> String
pub fn serialize_inner_html(&self, id: NodeId) -> String
Serialize children of a node as HTML (for innerHTML getter).
Sourcepub fn merge_subtree(&mut self, source: &Dom, source_root: NodeId) -> NodeId
pub fn merge_subtree(&mut self, source: &Dom, source_root: NodeId) -> NodeId
Copy a subtree from another Dom into this one. Returns the new root NodeId.