UNPKG

uhtml

Version:
30 lines (23 loc) • 768 B
'use strict'; const { DOCUMENT_FRAGMENT_NODE } = require('domconstants/constants'); const Parent = (require('./parent.js')); const { cloned } = require('./utils.js'); const { childNodes, nodeName, ownerDocument } = require('./symbols.js'); module.exports = class DocumentFragment extends Parent { constructor(owner = null) { super(DOCUMENT_FRAGMENT_NODE, owner)[nodeName] = '#document-fragment'; } get nodeName() { return this[nodeName]; } cloneNode(deep = false) { const fragment = new DocumentFragment(this[ownerDocument]); const { [childNodes]: nodes } = this; if (deep && nodes.length) fragment[childNodes] = nodes.map(cloned, fragment); return fragment; } toString() { return this[childNodes].join(''); } }