<commit_before>import { NodeAssembler } from './node'
import { element } from './element'

const DEFAULT_NAMESPACE_URI = ''
const DEFAULT_QUALIFIED_NAME = 'document'

const impl = window.document.implementation

export class DocumentAssembler extends NodeAssembler {
    /**
     * Instantiate a new Document node
     * @param {*} [descriptor]
     * @returns {Document}
     */
    create(descriptor = {}) {
        const constructor = this.constructor
        return this.node = typeof descriptor === 'string'?
            impl.createDocument(constructor.namespaceURI, descriptor, null) :
            impl.createDocument(
                descriptor.namespaceURI || constructor.namespaceURI,
                descriptor.qualifiedName || constructor.qualifiedName,
                descriptor.doctype || null)
    }

    /**
     * Set the document type declaration of the document
     * @param {DocumentType} doctype
     */
    set doctype(doctype) {
        const node = this.node
        const child = this.doctype
        if(child) node.replaceChild(doctype, child)
        else node.prepend(doctype)
    }

    /**
     * Get the document type declaration of the document
     * @returns {DocumentType}
     */
    get doctype() {
        return this.node.doctype
    }

    /**
     * Set the root document element
     * @param {Element|{}} documentElement node or descriptor
     */
    set documentElement(documentElement) {
        const node = this.node
        const root = this.documentElement
        if(documentElement instanceof Element) {
            if(root) node.replaceChild(documentElement, root)
            else node.append(documentElement)
        }
        else {
            if(root) element(root, documentElement)
            else node.append(document({}, documentElement))
        }
    }

    /**
     * Get the root document element
     * @returns {Element|{}} Element
     */
    get documentElement() {
        return this.node.documentElement
    }

    /**
     * Get the default namespace URI
     * @returns {String}
     */<commit_msg>create documentElement from init<commit_after>import { NodeAssembler } from './node'
import { element } from './element'

const DEFAULT_NAMESPACE_URI = ''
const DEFAULT_QUALIFIED_NAME = 'document'

const impl = window.document.implementation

export class DocumentAssembler extends NodeAssembler {
    /**
     * Instantiate a new Document node
     * @param {*} [descriptor]
     * @returns {Document}
     */
    create(descriptor = {}) {
        const constructor = this.constructor
        return this.node = typeof descriptor === 'string'?
            impl.createDocument(constructor.namespaceURI, descriptor, null) :
            impl.createDocument(
                descriptor.namespaceURI || constructor.namespaceURI,
                descriptor.qualifiedName || constructor.qualifiedName,
                descriptor.doctype || null)
    }

    /**
     * Set the document type declaration of the document
     * @param {DocumentType} doctype
     */
    set doctype(doctype) {
        const node = this.node
        const child = this.doctype
        if(child) node.replaceChild(doctype, child)
        else node.prepend(doctype)
    }

    /**
     * Get the document type declaration of the document
     * @returns {DocumentType}
     */
    get doctype() {
        return this.node.doctype
    }

    /**
     * Set the root document element
     * @param {Element|{}} documentElement node or descriptor
     */
    set documentElement(documentElement) {
        const node = this.node
        const root = this.documentElement
        if(documentElement instanceof Element) {
            if(root) node.replaceChild(documentElement, root)
            else node.append(documentElement)
        }
        else {
            if(root) element(root, documentElement)
            else {
                const tagName = documentElement.tagName
                const init = { documentElement }
                const doc = element(tagName, init)
                node.append(doc)
            }
        }
    }

    /**
     * Get the root document element
     * @returns {Element|{}} Element
     */
    get documentElement() {
        return this.node.documentElement
    }

    /**
     * Get the default namespace URI
     * @returns {String}
     */
{'fraction_non_alphanumeric': 0.09517209517209517, 'fraction_numerical': 0.0, 'mean_word_length': 2.1399564902102974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '569741', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1092, 'n_words': 292}