2020-02-12 17:12:53 +00:00
|
|
|
import { RendererOptions } from '@vue/runtime-core'
|
2020-02-12 16:56:42 +00:00
|
|
|
|
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'
|
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
let tempContainer: HTMLElement
|
|
|
|
let tempSVGContainer: SVGElement
|
|
|
|
|
|
|
|
export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
|
|
|
|
insert: (child, parent, anchor) => {
|
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)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
remove: child => {
|
2019-05-26 07:19:44 +00:00
|
|
|
const parent = child.parentNode
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeChild(child)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
createElement: (tag, isSVG): 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
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
createText: text => doc.createTextNode(text),
|
2019-05-26 07:19:44 +00:00
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
createComment: text => doc.createComment(text),
|
2019-05-26 07:19:44 +00:00
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
setText: (node, text) => {
|
2019-05-26 07:19:44 +00:00
|
|
|
node.nodeValue = text
|
|
|
|
},
|
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
setElementText: (el, text) => {
|
2019-05-26 07:19:44 +00:00
|
|
|
el.textContent = text
|
|
|
|
},
|
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
parentNode: node => node.parentNode as Element | null,
|
2019-05-28 05:27:31 +00:00
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
nextSibling: node => node.nextSibling,
|
2019-05-29 08:10:25 +00:00
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
querySelector: selector => doc.querySelector(selector),
|
2019-12-16 18:33:10 +00:00
|
|
|
|
2020-02-12 16:56:42 +00:00
|
|
|
setScopeId(el, id) {
|
2019-12-16 18:33:10 +00:00
|
|
|
el.setAttribute(id, '')
|
2020-02-12 16:56:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
cloneNode(el) {
|
|
|
|
return el.cloneNode(true)
|
|
|
|
},
|
|
|
|
|
2020-02-12 20:00:32 +00:00
|
|
|
// __UNSAFE__
|
|
|
|
// Reason: innerHTML.
|
|
|
|
// Static content here can only come from compiled templates.
|
|
|
|
// As long as the user only uses trusted templates, this is safe.
|
2020-02-12 16:56:42 +00:00
|
|
|
insertStaticContent(content, parent, anchor, isSVG) {
|
|
|
|
const temp = isSVG
|
|
|
|
? tempSVGContainer ||
|
|
|
|
(tempSVGContainer = doc.createElementNS(svgNS, 'svg'))
|
|
|
|
: tempContainer || (tempContainer = doc.createElement('div'))
|
|
|
|
temp.innerHTML = content
|
|
|
|
const node = temp.children[0]
|
|
|
|
nodeOps.insert(node, parent, anchor)
|
|
|
|
return node
|
2019-12-16 18:33:10 +00:00
|
|
|
}
|
2019-05-26 07:19:44 +00:00
|
|
|
}
|