| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- const doc = document
- const svgNS = 'http://www.w3.org/2000/svg'
- export const nodeOps = {
- 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 =>
- isSVG ? doc.createElementNS(svgNS, tag) : doc.createElement(tag),
- createText: (text: string): Text => doc.createTextNode(text),
- createComment: (text: string): Comment => doc.createComment(text),
- setText: (node: Text, text: string) => {
- node.nodeValue = text
- },
- setElementText: (el: HTMLElement, text: string) => {
- el.textContent = text
- },
- parentNode: (node: Node): HTMLElement | null =>
- node.parentNode as HTMLElement,
- nextSibling: (node: Node): Node | null => node.nextSibling,
- querySelector: (selector: string): Element | null =>
- doc.querySelector(selector)
- }
|