-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
nodeapi.js
56 lines (55 loc) · 1.23 KB
/
nodeapi.js
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
52
53
54
55
56
import {createNode, BaseSprite} from 'spritejs'
export function createElement(tagName) {
return createNode(tagName)
}
export function createElementNS(namespaceURI, qualifiedName) {
return createNode(qualifiedName)
}
export function createTextNode(text) {
return text
}
export function createComment(text) {
// no def
}
export function insertBefore(parentNode, newNode, referenceNode) {
if(parentNode) {
parentNode.insertBefore(newNode, referenceNode)
}
}
export function removeChild(node, child) {
node.removeChild(child)
}
export function appendChild(node, child) {
if(typeof child === 'string') {
node.text = child
} else {
node.appendChild(child)
}
}
export function parentNode(node) {
return node.parent
}
export function nextSibling(node) {
if(node.parent) {
const idx = node.parent.children.indexOf(node)
return node.parent[idx + 1]
}
}
export function tagName(elm) {
return elm.tagName
}
export function setTextContent(node, text) {
node.text = text
}
export function getTextContent(node) {
return node.text
}
export function isElement(node) {
return node instanceof BaseSprite
}
export function isText(node) {
return typeof node === 'string'
}
export function isComment(node) {
return false
}