UNPKG

@zougui/common.furaffinity

Version:

47 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getElementNode = exports.getTextAlign = exports.getNodeName = exports.getElementStyle = exports.areChildNodesText = exports.isTextNode = void 0; const reTextAlign = /(left)|(right)|(center)/; const defaultTextAlign = 'left'; const isTextNode = (node) => { return (0, exports.getNodeName)(node) === '#text'; }; exports.isTextNode = isTextNode; const areChildNodesText = (node) => { return Array.from(node.childNodes).every((node) => (0, exports.isTextNode)(node)); }; exports.areChildNodesText = areChildNodesText; const getElementStyle = (element) => { var _a; return (_a = element.attributes.getNamedItem('style')) === null || _a === void 0 ? void 0 : _a.value; }; exports.getElementStyle = getElementStyle; const getNodeName = (node) => { return node.nodeName.toLowerCase(); }; exports.getNodeName = getNodeName; const getTextAlign = (element) => { var _a; const className = (_a = element.attributes.getNamedItem('class')) === null || _a === void 0 ? void 0 : _a.value; const textAlignMatches = className === null || className === void 0 ? void 0 : className.match(reTextAlign); const textAlign = ((textAlignMatches === null || textAlignMatches === void 0 ? void 0 : textAlignMatches[0]) || defaultTextAlign); return textAlign; }; exports.getTextAlign = getTextAlign; const getElementNode = (node, element, parseElement) => { const nodeName = (0, exports.getNodeName)(node); const text = node.textContent || ''; const style = element && (0, exports.getElementStyle)(element); const isTextOnly = (0, exports.areChildNodesText)(node); const baseNode = { type: nodeName, text, style, }; if (isTextOnly) { return baseNode; } return Object.assign(Object.assign({}, baseNode), { children: element && parseElement(element) }); }; exports.getElementNode = getElementNode; //# sourceMappingURL=dom.js.map