Class: Dommy::Internal::ShadowRootRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/internal/shadow_root_registry.rb

Overview

Manages ShadowRoot identity and shadow boundary traversal. Maps Nokogiri DocumentFragment (shadow tree backing) to ShadowRoot wrapper.

Instance Method Summary collapse

Constructor Details

#initializeShadowRootRegistry

Returns a new instance of ShadowRootRegistry.



10
11
12
# File 'lib/dommy/internal/shadow_root_registry.rb', line 10

def initialize
  @shadow_roots = {}
end

Instance Method Details

#find_enclosing(nokogiri_node) ⇒ Object

Find the enclosing ShadowRoot for a given node. Walks up the ancestor chain looking for a shadow root. Uses NodeTraversal to avoid duplication of tree walking logic.



28
29
30
31
32
# File 'lib/dommy/internal/shadow_root_registry.rb', line 28

def find_enclosing(nokogiri_node)
  NodeTraversal.find_ancestor(nokogiri_node) do |ancestor|
    find_for_fragment(ancestor)
  end
end

#find_for_fragment(fragment_node) ⇒ Object

Find the ShadowRoot for a given fragment (if any)



20
21
22
23
# File 'lib/dommy/internal/shadow_root_registry.rb', line 20

def find_for_fragment(fragment_node)
  return nil unless fragment_node
  @shadow_roots[fragment_node.object_id]
end

#register(fragment_node, shadow_root) ⇒ Object

Register a shadow root by its backing fragment node



15
16
17
# File 'lib/dommy/internal/shadow_root_registry.rb', line 15

def register(fragment_node, shadow_root)
  @shadow_roots[fragment_node.object_id] = shadow_root
end