@awesome-fe/translate
Version:
Translation utils
119 lines • 3.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DomTreeAdapter = void 0;
const dom_models_1 = require("./dom-models");
class DomTreeAdapter {
constructor() {
}
static create() {
return new DomTreeAdapter();
}
adoptAttributes(recipient, attrs) {
recipient.setAttributes(...attrs);
}
appendChild(parentNode, newNode) {
parentNode.appendChild(newNode);
}
createCommentNode(data) {
return new dom_models_1.DomComment(data);
}
createDocument() {
return new dom_models_1.DomDocument();
}
createDocumentFragment() {
return new dom_models_1.DomDocumentFragment();
}
createElement(tagName, namespaceURI, attrs) {
switch (tagName) {
case 'table':
return new dom_models_1.DomTableElement(tagName, attrs, namespaceURI);
case 'tr':
return new dom_models_1.DomTableRowElement(tagName, attrs, namespaceURI);
case 'th':
case 'td':
return new dom_models_1.DomTableCellElement(tagName, attrs, namespaceURI);
default:
return new dom_models_1.DomElement(tagName, attrs, namespaceURI);
}
}
detachNode(node) {
if (node instanceof dom_models_1.DomChildNode) {
node.remove();
}
}
getAttrList(element) {
return element.attrs;
}
getChildNodes(node) {
return node.childNodes;
}
getCommentNodeContent(commentNode) {
return commentNode.data;
}
getDocumentMode(document) {
return document.mode;
}
getDocumentTypeNodeName(doctypeNode) {
return doctypeNode.name;
}
getDocumentTypeNodePublicId(doctypeNode) {
return doctypeNode.publicId;
}
getDocumentTypeNodeSystemId(doctypeNode) {
return doctypeNode.systemId;
}
getFirstChild(node) {
return node.childNodes?.[0];
}
getNamespaceURI(element) {
return element.namespaceURI;
}
getNodeSourceCodeLocation(node) {
return undefined;
}
getParentNode(node) {
return node.parentNode;
}
getTagName(element) {
return element.tagName;
}
getTemplateContent(templateElement) {
return templateElement.templateContent;
}
getTextNodeContent(textNode) {
return textNode.value;
}
insertBefore(parentNode, newNode, referenceNode) {
parentNode.insertBefore(newNode, referenceNode);
}
insertText(parentNode, text) {
parentNode.appendChild(new dom_models_1.DomText(text));
}
insertTextBefore(parentNode, text, referenceNode) {
this.insertBefore(parentNode, new dom_models_1.DomText(text), referenceNode);
}
isCommentNode(node) {
return node instanceof dom_models_1.DomComment;
}
isDocumentTypeNode(node) {
return node instanceof dom_models_1.DomDocumentType;
}
isElementNode(node) {
return node instanceof dom_models_1.DomElement;
}
isTextNode(node) {
return node instanceof dom_models_1.DomText;
}
setDocumentMode(document, mode) {
document.mode = mode;
}
setDocumentType(document, name, publicId, systemId) {
document.prepend(new dom_models_1.DomDocumentType(name, publicId, systemId));
}
setNodeSourceCodeLocation(node, location) {
}
setTemplateContent(templateElement, contentElement) {
}
}
exports.DomTreeAdapter = DomTreeAdapter;
//# sourceMappingURL=dom-tree-adapter.js.map