vue3-yuanma/packages/runtime-dom/src/nodeOps.ts

41 lines
1.0 KiB
TypeScript
Raw Normal View History

2019-05-29 08:10:25 +00:00
const doc = document
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) => {
if (anchor != null) {
parent.insertBefore(child, anchor)
} 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-29 08:10:25 +00:00
createText: (text: string): Text => doc.createTextNode(text),
2019-05-29 08:10:25 +00:00
createComment: (text: string): Comment => doc.createComment(text),
setText: (node: Text, text: string) => {
node.nodeValue = text
},
setElementText: (el: HTMLElement, text: string) => {
el.textContent = text
},
2019-05-28 05:27:31 +00:00
parentNode: (node: Node): Node | null => node.parentNode,
2019-05-29 08:10:25 +00:00
nextSibling: (node: Node): Node | null => node.nextSibling,
querySelector: (selector: string): Node | null => doc.querySelector(selector)
}