import { BaseNode } from "./basenode.js"; export class SwapNode extends BaseNode { constructor(node, swapNode) { super(node); if (!(swapNode instanceof Node)) throw TypeError("swapNode must be instance of Node"); this.swapNode = swapNode; this.hasReplaceNodes = false; } replaceNodes() { if (this.hasReplaceNodes) return false; // Copy id and classes to new node if (this.node.id) this.swapNode.id = this.node.id; if (this.node.classList.length) this.swapNode.classList = this.node.classList; this.linker(this.node, this.swapNode); this.node.parentNode.replaceChild(this.swapNode, this.node); this.node = this.swapNode; delete this.swapNode; return this.hasReplaceNodes = true; } /** * Override this to have access to the script tag that gets converted to the new node inplace * @param {Node} node Node of the original script tag * @param {Node} swapNode Node of the new element that replaces the script tag inline */ linker(node, swapNode) {} }