-
Notifications
You must be signed in to change notification settings - Fork 78
/
DocumentNode.ts
51 lines (41 loc) · 1.36 KB
/
DocumentNode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import CommentNode from './CommentNode'
import ElementNode from './ElementNode'
import ViewNode, { elementIterator } from './ViewNode'
import TextNode from './TextNode'
import PropertyNode from './PropertyNode';
import { createElement } from './element-registry';
export default class DocumentNode extends ViewNode {
constructor() {
super()
this.tagName = "docNode"
this.nodeType = 9
}
createComment(text: string): CommentNode {
return new CommentNode(text)
}
createPropertyNode(tagName: string, propertyName: string): PropertyNode {
return new PropertyNode(tagName, propertyName)
}
createElement(tagName: string): ElementNode {
if (tagName.indexOf(".") >= 0) {
let bits = tagName.split(".", 2);
return this.createPropertyNode(bits[0], bits[1]);
}
return createElement(tagName, this);
}
createElementNS(namespace: string, tagName: string): ElementNode {
return this.createElement(tagName)
}
createTextNode(text: string) {
return new TextNode(text)
}
getElementById(id: string) {
for (let el of elementIterator(this)) {
if (el.nodeType === 1 && (el as ElementNode).id === id)
return el;
}
}
dispatchEvent(event: any) {
//Svelte dev fires these for tool support
}
}