UNPKG

@aurigma/design-atoms

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

58 lines 2.13 kB
import { StringUtils } from "./StringUtils"; var TextProcessor = /** @class */ (function () { function TextProcessor() { } TextProcessor.prototype.getTextForFrameMeasure = function (text) { if (text === "" || text == null) return "X"; if (this._isEmptyFirstLine(text)) { text = this._insertIntoFirstLine(text, "X"); } if (this._isEmptyLastLine(text)) { text = this._insertIntoLastLine(text, "X"); } return text; }; TextProcessor.prototype._isEmptyFirstLine = function (text) { text = this._normalizeTags(text); if (text.startsWith("<p></p>")) return true; if (text.startsWith("<p><span><br/>")) return true; if (text.startsWith("<p><br/>")) return true; return false; }; TextProcessor.prototype._insertIntoFirstLine = function (text, value) { if (text.startsWith("<p></p>") || text.startsWith("<p><br/>")) return StringUtils.insert(text, 3, "X"); if (text.startsWith("<p><span>")) return StringUtils.insert(text, 9, "X"); return text; }; TextProcessor.prototype._isEmptyLastLine = function (text) { text = this._normalizeTags(text); if (text.endsWith("<p></p>")) return true; if (text.endsWith("<p><span><br/></span></p>")) return true; if (text.endsWith("<p><br/></p>")) return true; return false; }; TextProcessor.prototype._insertIntoLastLine = function (text, value) { var index = text.lastIndexOf("<p>"); text = text.substring(0, index) + "<p><span>X</span></p>"; return text; }; TextProcessor.prototype._normalizeTags = function (text) { text = text .replace("<br />", "<br/>") .replace("<br>", "<br/>") .replace("<br >", "<br/>"); return text; }; return TextProcessor; }()); export { TextProcessor }; //# sourceMappingURL=TextProcessor.js.map