@antv/t8
Version:
T8 is a text visualization solution for unstructured data within the AntV technology stack, and it is a declarative JSON Schema syntax that can be used to describe the content of data interpretation reports.
37 lines (34 loc) • 1.33 kB
JavaScript
;
/**
* add element to original element, this function is used to add element to Phrase element,
* @param element - element to add, type: HTMLElement, string or number.
* @param value - original string from spec, type: string, make sure it only contains text node.
* @param position - position to add element, type: 'suffix' | 'prefix', default: 'suffix'.
* @returns - new container element, type: HTMLSpanElement.
* use function `addElement` to add element to original element.
*/
var createInlineDocument = function (element, value, position) {
if (position === void 0) { position = 'suffix'; }
var span = document.createElement('span');
var originalElementSpan = value;
span.textContent = originalElementSpan;
var newElement = undefined;
if (typeof element === 'string' || typeof element === 'number') {
newElement = document.createElement('span');
newElement.textContent = element.toString();
}
else {
newElement = element;
}
if (newElement) {
if (position === 'suffix') {
span.appendChild(newElement);
}
else {
span.insertBefore(newElement, span.firstChild);
}
}
return span;
};
exports.createInlineDocument = createInlineDocument;
//# sourceMappingURL=createInlineDocument.js.map