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

38 lines
960 B
TypeScript
Raw Normal View History

2018-11-01 05:58:06 +08:00
import { NodeOps } from '@vue/runtime-core'
2018-09-19 23:35:38 +08:00
const svgNS = 'http://www.w3.org/2000/svg'
2018-11-01 05:58:06 +08:00
export const nodeOps: NodeOps = {
2018-09-19 23:35:38 +08:00
createElement: (tag: string, isSVG?: boolean): Element =>
isSVG ? document.createElementNS(svgNS, tag) : document.createElement(tag),
createText: (text: string): Text => document.createTextNode(text),
setText: (node: Text, text: string) => {
node.nodeValue = text
},
appendChild: (parent: Node, child: Node) => {
parent.appendChild(child)
},
insertBefore: (parent: Node, child: Node, ref: Node) => {
parent.insertBefore(child, ref)
},
removeChild: (parent: Node, child: Node) => {
parent.removeChild(child)
},
clearContent: (node: Node) => {
node.textContent = ''
},
parentNode: (node: Node): Node | null => node.parentNode,
nextSibling: (node: Node): Node | null => node.nextSibling,
querySelector: (selector: string): Node | null =>
document.querySelector(selector)
}