1
- package domx
1
+ package dom
2
2
3
3
import (
4
4
"bytes"
5
5
"strings"
6
6
7
7
"golang.org/x/net/html"
8
8
9
- "github.com/crhntr/dom"
9
+ "github.com/crhntr/dom/spec "
10
10
)
11
11
12
12
type Element struct {
@@ -15,16 +15,16 @@ type Element struct {
15
15
16
16
// NewNode
17
17
18
- func (e * Element ) NodeType () dom .NodeType { return nodeType (e .node .Type ) }
19
- func (e * Element ) IsConnected () bool { return isConnected (e .node ) }
20
- func (e * Element ) OwnerDocument () dom .Document { return ownerDocument (e .node ) }
21
- func (e * Element ) ParentNode () dom .Node { return parentNode (e .node ) }
22
- func (e * Element ) ParentElement () dom .Element { return parentElement (e .node ) }
23
- func (e * Element ) PreviousSibling () dom .ChildNode { return previousSibling (e .node ) }
24
- func (e * Element ) NextSibling () dom .ChildNode { return nextSibling (e .node ) }
25
- func (e * Element ) TextContent () string { return textContent (e .node ) }
26
- func (e * Element ) CloneNode (deep bool ) dom .Node { return NewNode (cloneNode (e .node , deep )) }
27
- func (e * Element ) IsSameNode (other dom .Node ) bool { return isSameNode (e .node , other ) }
18
+ func (e * Element ) NodeType () spec .NodeType { return nodeType (e .node .Type ) }
19
+ func (e * Element ) IsConnected () bool { return isConnected (e .node ) }
20
+ func (e * Element ) OwnerDocument () spec .Document { return ownerDocument (e .node ) }
21
+ func (e * Element ) ParentNode () spec .Node { return parentNode (e .node ) }
22
+ func (e * Element ) ParentElement () spec .Element { return parentElement (e .node ) }
23
+ func (e * Element ) PreviousSibling () spec .ChildNode { return previousSibling (e .node ) }
24
+ func (e * Element ) NextSibling () spec .ChildNode { return nextSibling (e .node ) }
25
+ func (e * Element ) TextContent () string { return textContent (e .node ) }
26
+ func (e * Element ) CloneNode (deep bool ) spec .Node { return NewNode (cloneNode (e .node , deep )) }
27
+ func (e * Element ) IsSameNode (other spec .Node ) bool { return isSameNode (e .node , other ) }
28
28
func (e * Element ) Length () int {
29
29
c := e .node .FirstChild
30
30
result := 0
@@ -37,41 +37,41 @@ func (e *Element) Length() int {
37
37
38
38
// ParentNode
39
39
40
- func (e * Element ) Children () dom .ElementCollection { return children (e .node ) }
41
- func (e * Element ) FirstElementChild () dom .Element { return firstElementChild (e .node ) }
42
- func (e * Element ) LastElementChild () dom .Element { return lastElementChild (e .node ) }
43
- func (e * Element ) ChildElementCount () int { return childElementCount (e .node ) }
44
- func (e * Element ) Prepend (nodes ... dom .ChildNode ) { prependNodes (e .node , nodes ) }
45
- func (e * Element ) Append (nodes ... dom .ChildNode ) { appendNodes (e .node , nodes ) }
46
- func (e * Element ) ReplaceChildren (nodes ... dom .ChildNode ) { replaceChildren (e .node , nodes ) }
47
- func (e * Element ) GetElementsByTagName (name string ) dom .ElementCollection {
40
+ func (e * Element ) Children () spec .ElementCollection { return children (e .node ) }
41
+ func (e * Element ) FirstElementChild () spec .Element { return firstElementChild (e .node ) }
42
+ func (e * Element ) LastElementChild () spec .Element { return lastElementChild (e .node ) }
43
+ func (e * Element ) ChildElementCount () int { return childElementCount (e .node ) }
44
+ func (e * Element ) Prepend (nodes ... spec .ChildNode ) { prependNodes (e .node , nodes ) }
45
+ func (e * Element ) Append (nodes ... spec .ChildNode ) { appendNodes (e .node , nodes ) }
46
+ func (e * Element ) ReplaceChildren (nodes ... spec .ChildNode ) { replaceChildren (e .node , nodes ) }
47
+ func (e * Element ) GetElementsByTagName (name string ) spec .ElementCollection {
48
48
return getElementsByTagName (e .node , name )
49
49
}
50
50
51
- func (e * Element ) GetElementsByClassName (name string ) dom .ElementCollection {
51
+ func (e * Element ) GetElementsByClassName (name string ) spec .ElementCollection {
52
52
return getElementsByClassName (e .node , name )
53
53
}
54
54
55
- func (e * Element ) QuerySelector (query string ) dom .Element { return querySelector (e .node , query ) }
56
- func (e * Element ) QuerySelectorAll (query string ) dom .NodeList [dom .Element ] {
55
+ func (e * Element ) QuerySelector (query string ) spec .Element { return querySelector (e .node , query ) }
56
+ func (e * Element ) QuerySelectorAll (query string ) spec .NodeList [spec .Element ] {
57
57
return querySelectorAll (e .node , query )
58
58
}
59
- func (e * Element ) Closest (selector string ) dom .Element { return closest (e .node , selector ) }
60
- func (e * Element ) Matches (selector string ) bool { return matches (e .node , selector ) }
59
+ func (e * Element ) Closest (selector string ) spec .Element { return closest (e .node , selector ) }
60
+ func (e * Element ) Matches (selector string ) bool { return matches (e .node , selector ) }
61
61
62
- func (e * Element ) HasChildNodes () bool { return hasChildNodes (e .node ) }
63
- func (e * Element ) ChildNodes () dom .NodeList [dom .Node ] { return childNodes (e .node ) }
64
- func (e * Element ) FirstChild () dom .ChildNode { return firstChild (e .node ) }
65
- func (e * Element ) LastChild () dom .ChildNode { return lastChild (e .node ) }
66
- func (e * Element ) Contains (other dom .Node ) bool { return contains (e .node , other ) }
67
- func (e * Element ) InsertBefore (node , child dom .ChildNode ) dom .ChildNode {
62
+ func (e * Element ) HasChildNodes () bool { return hasChildNodes (e .node ) }
63
+ func (e * Element ) ChildNodes () spec .NodeList [spec .Node ] { return childNodes (e .node ) }
64
+ func (e * Element ) FirstChild () spec .ChildNode { return firstChild (e .node ) }
65
+ func (e * Element ) LastChild () spec .ChildNode { return lastChild (e .node ) }
66
+ func (e * Element ) Contains (other spec .Node ) bool { return contains (e .node , other ) }
67
+ func (e * Element ) InsertBefore (node , child spec .ChildNode ) spec .ChildNode {
68
68
return insertBefore (e .node , node , child )
69
69
}
70
- func (e * Element ) AppendChild (node dom .ChildNode ) dom .ChildNode { return appendChild (e .node , node ) }
71
- func (e * Element ) ReplaceChild (node , child dom .ChildNode ) dom .ChildNode {
70
+ func (e * Element ) AppendChild (node spec .ChildNode ) spec .ChildNode { return appendChild (e .node , node ) }
71
+ func (e * Element ) ReplaceChild (node , child spec .ChildNode ) spec .ChildNode {
72
72
return replaceChild (e .node , node , child )
73
73
}
74
- func (e * Element ) RemoveChild (node dom .ChildNode ) dom .ChildNode { return removeChild (e .node , node ) }
74
+ func (e * Element ) RemoveChild (node spec .ChildNode ) spec .ChildNode { return removeChild (e .node , node ) }
75
75
76
76
// Element
77
77
@@ -193,7 +193,7 @@ func (list SiblingElements) Length() int {
193
193
return result
194
194
}
195
195
196
- func (list SiblingElements ) Item (index int ) dom .Element {
196
+ func (list SiblingElements ) Item (index int ) spec .Element {
197
197
childIndex := 0
198
198
for c := list .firstChild ; c != nil ; c = c .NextSibling {
199
199
if c .Type != html .ElementNode {
@@ -207,7 +207,7 @@ func (list SiblingElements) Item(index int) dom.Element {
207
207
return nil
208
208
}
209
209
210
- func (list SiblingElements ) NamedItem (name string ) dom .Element {
210
+ func (list SiblingElements ) NamedItem (name string ) spec .Element {
211
211
for c := list .firstChild ; c != nil ; c = c .NextSibling {
212
212
if c .Type != html .ElementNode {
213
213
continue
@@ -223,14 +223,14 @@ type ElementList []*html.Node
223
223
224
224
func (list ElementList ) Length () int { return len (list ) }
225
225
226
- func (list ElementList ) Item (index int ) dom .Element {
226
+ func (list ElementList ) Item (index int ) spec .Element {
227
227
if index < 0 || index >= len (list ) {
228
228
return nil
229
229
}
230
230
return & Element {node : list [index ]}
231
231
}
232
232
233
- func (list ElementList ) NamedItem (name string ) dom .Element {
233
+ func (list ElementList ) NamedItem (name string ) spec .Element {
234
234
for _ , el := range list {
235
235
if isNamed (el , name ) {
236
236
return & Element {node : el }
0 commit comments