2020-01-26 03:31:29 +00:00
|
|
|
const doc = (typeof document !== 'undefined' ? document : null) as Document
|
2019-05-26 07:19:44 +00:00
|
|
|
const svgNS = 'http://www.w3.org/2000/svg'
|
|
|
|
|
2019-06-20 13:28:37 +00:00
|
|
|
export const nodeOps = {
|
2019-05-26 07:38:55 +00:00
|
|
|
insert: (child: Node, parent: Node, anchor?: Node) => {
|
2019-05-26 07:19:44 +00:00
|
|
|
if (anchor != null) {
|
2019-10-10 19:37:17 +00:00
|
|
|
parent.insertBefore(child, anchor)
|
2019-05-26 07:19:44 +00:00
|
|
|
} else {
|
|
|
|
parent.appendChild(child)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: (child: Node) => {
|
|
|
|
const parent = child.parentNode
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeChild(child)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
createElement: (tag: string, isSVG?: boolean): Element =>
|
2019-05-29 08:10:25 +00:00
|
|
|
isSVG ? doc.createElementNS(svgNS, tag) : doc.createElement(tag),
|
2019-05-26 07:19:44 +00:00
|
|
|
|
2019-05-29 08:10:25 +00:00
|
|
|
createText: (text: string): Text => doc.createTextNode(text),
|
2019-05-26 07:19:44 +00:00
|
|
|
|
2019-05-29 08:10:25 +00:00
|
|
|
createComment: (text: string): Comment => doc.createComment(text),
|
2019-05-26 07:19:44 +00:00
|
|
|
|
|
|
|
setText: (node: Text, text: string) => {
|
|
|
|
node.nodeValue = text
|
|
|
|
},
|
|
|
|
|
|
|
|
setElementText: (el: HTMLElement, text: string) => {
|
|
|
|
el.textContent = text
|
|
|
|
},
|
|
|
|
|
2019-10-10 18:49:35 +00:00
|
|
|
parentNode: (node: Node): HTMLElement | null =>
|
|
|
|
node.parentNode as HTMLElement,
|
2019-05-28 05:27:31 +00:00
|
|
|
|
2019-05-29 08:10:25 +00:00
|
|
|
nextSibling: (node: Node): Node | null => node.nextSibling,
|
|
|
|
|
2019-09-06 20:58:32 +00:00
|
|
|
querySelector: (selector: string): Element | null =>
|
2019-12-16 18:33:10 +00:00
|
|
|
doc.querySelector(selector),
|
|
|
|
|
|
|
|
setScopeId(el: Element, id: string) {
|
|
|
|
el.setAttribute(id, '')
|
|
|
|
}
|
2019-05-26 07:19:44 +00:00
|
|
|
}
|