UNPKG

@trap_stevo/loml

Version:

Unleash the power of a language crafted for dynamic text styling. Loml transforms your words into code—bold, italic, colorful, and linkable. Turn plain text into expressive, richly formatted messages with simple, elegant commands. Loml empowers you with a

164 lines 6.23 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; var Loml = /*#__PURE__*/function () { function Loml() { _classCallCheck(this, Loml); this.message = ""; } return _createClass(Loml, [{ key: "text", value: function text(_text) { var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var styleString = Loml.styleToString(styles); this.message += "<span style=\"".concat(styleString, "\">").concat(_text, "</span>"); return this; } }, { key: "bold", value: function bold(text) { var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var styleString = Loml.styleToString(styles); this.message += "<strong style=\"".concat(styleString, "\">").concat(text, "</strong>"); return this; } }, { key: "italic", value: function italic(text) { var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var styleString = Loml.styleToString(styles); this.message += "<em style=\"".concat(styleString, "\">").concat(text, "</em>"); return this; } }, { key: "br", value: function br() { this.message += "<br>"; return this; } }, { key: "link", value: function link(text, href) { var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var styleString = Loml.styleToString(styles); this.message += "<a href=\"".concat(href, "\" style=\"").concat(styleString, "\" target=\"_blank\">").concat(text, "</a>"); return this; } }, { key: "color", value: function color(text, _color) { var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; styles.color = _color; var styleString = Loml.styleToString(styles); this.message += "<span style=\"".concat(styleString, "\">").concat(text, "</span>"); return this; } }, { key: "gradientText", value: function gradientText(text) { var colors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "to right"; var styles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; if (colors.length === 0) { return this; } var gradient = "linear-gradient(".concat(direction, ", ").concat(colors.join(", "), ")"); styles.backgroundImage = gradient; styles.WebkitBackgroundClip = "text"; styles.color = "transparent"; var styleString = Loml.styleToString(styles); this.message += "<span style=\"".concat(styleString, "\">").concat(text, "</span>"); return this; } }, { key: "element", value: function element(tag, text) { var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var styleString = Loml.styleToString(styles); this.message += "<".concat(tag, " style=\"").concat(styleString, "\">").concat(text, "</").concat(tag, ">"); return this; } }, { key: "build", value: function build() { return this.message; } }, { key: "clear", value: function clear() { this.message = ""; return this; } }], [{ key: "styleToString", value: function styleToString() { var styles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var camelCaseToKebabCase = function camelCaseToKebabCase(str) { return str.replace(/[A-Z]/g, function (match) { return "-".concat(match.toLowerCase()); }); }; var styleString = Object.entries(styles).map(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1]; var kebabKey = camelCaseToKebabCase(key); if (kebabKey.startsWith("webkit")) { return "-webkit-".concat(kebabKey.slice(6), " : ").concat(value); } return "".concat(kebabKey, " : ").concat(value); }).join("; "); return styleString ? styleString + ";" : ""; } }, { key: "quickText", value: function quickText(text) { var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return new Loml().text(text, styles).build(); } }, { key: "quickBold", value: function quickBold(text) { var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return new Loml().bold(text, styles).build(); } }, { key: "quickItalic", value: function quickItalic(text) { var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return new Loml().italic(text, styles).build(); } }, { key: "quickLink", value: function quickLink(text, href) { var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return new Loml().link(text, href, styles).build(); } }, { key: "quickColor", value: function quickColor(text, color) { var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return new Loml().color(text, color, styles).build(); } }, { key: "quickGradientText", value: function quickGradientText(text) { var colors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "to right"; var styles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; return new Loml().gradientText(text, colors, direction, styles).build(); } }, { key: "quickElement", value: function quickElement(tag, text) { var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return new Loml().element(tag, text, styles).build(); } }, { key: "quickBr", value: function quickBr() { return "<br>"; } }]); }(); export default Loml;