11module Browser ; module DOM
22
33class Document < Element
4+ include DocumentOrShadowRoot
5+
46 # Get the first element matching the given ID, CSS selector or XPath.
57 #
68 # @param what [String] ID, CSS selector or XPath
@@ -29,14 +31,24 @@ def body
2931 # Create a new element for the document.
3032 #
3133 # @param name [String] the node name
32- # @param options [Hash] optional `:namespace` name
34+ # @param options [String] :namespace optional namespace name
35+ # @param options [String] :is optional WebComponents is parameter
36+ # @param options [String] :id optional id to set
37+ # @param options [Array<String>] :classes optional classes to set
38+ # @param options [Hash] :attrs optional attributes to set
3339 #
3440 # @return [Element]
3541 def create_element ( name , **options )
42+ opts = { }
43+
44+ if options [ :is ] ||= ( options . dig ( :attrs , :fragment ) )
45+ opts [ :is ] = options [ :is ]
46+ end
47+
3648 if ns = options [ :namespace ]
37- elem = `#@native .createElementNS(#{ ns } , #{ name } )`
49+ elem = `#@native .createElementNS(#{ ns } , #{ name } , #{ opts . to_n } )`
3850 else
39- elem = `#@native .createElement(name)`
51+ elem = `#@native .createElement(name, #{ opts . to_n } )`
4052 end
4153
4254 if options [ :classes ]
@@ -60,6 +72,13 @@ def create_element(name, **options)
6072 DOM ( elem )
6173 end
6274
75+ # Create a new document fragment.
76+ #
77+ # @return [DocumentFragment]
78+ def create_document_fragment
79+ DOM ( `#@native .createDocumentFragment()` )
80+ end
81+
6382 # Create a new text node for the document.
6483 #
6584 # @param content [String] the text content
@@ -131,14 +150,6 @@ def root=(element)
131150 `#@native .documentElement = #{ Native . convert ( element ) } `
132151 end
133152
134- # @!attribute [r] style_sheets
135- # @return [Array<CSS::StyleSheet>] the style sheets for the document
136- def style_sheets
137- Native ::Array . new ( `#@native .styleSheets` ) { |e |
138- CSS ::StyleSheet . new ( e )
139- }
140- end
141-
142153 # @!attribute title
143154 # @return [String] the document title
144155 def title
0 commit comments