"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Node_js_1 = __importDefault(require("../node/Node.cjs")); const QuerySelector_js_1 = __importDefault(require("../../query-selector/QuerySelector.cjs")); const ParentNodeUtility_js_1 = __importDefault(require("../parent-node/ParentNodeUtility.cjs")); const ElementUtility_js_1 = __importDefault(require("../element/ElementUtility.cjs")); const HTMLCollection_js_1 = __importDefault(require("../element/HTMLCollection.cjs")); /** * DocumentFragment. */ class DocumentFragment extends Node_js_1.default { constructor() { super(...arguments); this.nodeType = Node_js_1.default.DOCUMENT_FRAGMENT_NODE; this.children = new HTMLCollection_js_1.default(); this._rootNode = this; } /** * Last element child. * * @returns Element. */ get childElementCount() { return this.children.length; } /** * First element child. * * @returns Element. */ get firstElementChild() { return this.children ? this.children[0] || null : null; } /** * Last element child. * * @returns Element. */ get lastElementChild() { return this.children ? this.children[this.children.length - 1] || null : null; } /** * Get text value of children. * * @returns Text content. */ get textContent() { let result = ''; for (const childNode of this.childNodes) { if (childNode.nodeType === Node_js_1.default.ELEMENT_NODE || childNode.nodeType === Node_js_1.default.TEXT_NODE) { result += childNode.textContent; } } return result; } /** * Sets text content. * * @param textContent Text content. */ set textContent(textContent) { for (const child of this.childNodes.slice()) { this.removeChild(child); } if (textContent) { this.appendChild(this.ownerDocument.createTextNode(textContent)); } } /** * Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes. * * @param nodes List of Node or DOMString. */ append(...nodes) { ParentNodeUtility_js_1.default.append(this, ...nodes); } /** * Inserts a set of Node objects or DOMString objects before the first child of the ParentNode. DOMString objects are inserted as equivalent Text nodes. * * @param nodes List of Node or DOMString. */ prepend(...nodes) { ParentNodeUtility_js_1.default.prepend(this, ...nodes); } /** * Replaces the existing children of a node with a specified new set of children. * * @param nodes List of Node or DOMString. */ replaceChildren(...nodes) { ParentNodeUtility_js_1.default.replaceChildren(this, ...nodes); } /** * Query CSS selector to find matching nodes. * * @param selector CSS selector. * @returns Matching elements. */ querySelectorAll(selector) { return QuerySelector_js_1.default.querySelectorAll(this, selector); } /** * Query CSS Selector to find matching node. * * @param selector CSS selector. * @returns Matching element. */ querySelector(selector) { return QuerySelector_js_1.default.querySelector(this, selector); } /** * Returns an element by ID. * * @param id ID. * @returns Matching element. */ getElementById(id) { return ParentNodeUtility_js_1.default.getElementById(this, id); } /** * Clones a node. * * @override * @param [deep=false] "true" to clone deep. * @returns Cloned node. */ cloneNode(deep = false) { const clone = super.cloneNode(deep); if (deep) { for (const node of clone.childNodes) { if (node.nodeType === Node_js_1.default.ELEMENT_NODE) { clone.children.push(node); } } } return clone; } /** * @override */ appendChild(node) { // We do not call super here as this will be handled by ElementUtility to improve performance by avoiding validation and other checks. return ElementUtility_js_1.default.appendChild(this, node); } /** * @override */ removeChild(node) { // We do not call super here as this will be handled by ElementUtility to improve performance by avoiding validation and other checks. return ElementUtility_js_1.default.removeChild(this, node); } /** * @override */ insertBefore(newNode, referenceNode) { if (arguments.length < 2) { throw new TypeError(`Failed to execute 'insertBefore' on 'Node': 2 arguments required, but only ${arguments.length} present.`); } // We do not call super here as this will be handled by ElementUtility to improve performance by avoiding validation and other checks. return ElementUtility_js_1.default.insertBefore(this, newNode, referenceNode); } } exports.default = DocumentFragment; //# sourceMappingURL=DocumentFragment.cjs.map