text-container.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var text_transform_1 = require("../css/property-descriptors/text-transform");
  4. var text_1 = require("../css/layout/text");
  5. var TextContainer = /** @class */ (function () {
  6. function TextContainer(node, styles) {
  7. this.text = transform(node.data, styles.textTransform);
  8. this.textBounds = text_1.parseTextBounds(this.text, styles, node);
  9. }
  10. return TextContainer;
  11. }());
  12. exports.TextContainer = TextContainer;
  13. var transform = function (text, transform) {
  14. switch (transform) {
  15. case text_transform_1.TEXT_TRANSFORM.LOWERCASE:
  16. return text.toLowerCase();
  17. case text_transform_1.TEXT_TRANSFORM.CAPITALIZE:
  18. return text.replace(CAPITALIZE, capitalize);
  19. case text_transform_1.TEXT_TRANSFORM.UPPERCASE:
  20. return text.toUpperCase();
  21. default:
  22. return text;
  23. }
  24. };
  25. var CAPITALIZE = /(^|\s|:|-|\(|\))([a-z])/g;
  26. var capitalize = function (m, p1, p2) {
  27. if (m.length > 0) {
  28. return p1 + p2.toUpperCase();
  29. }
  30. return m;
  31. };
  32. //# sourceMappingURL=text-container.js.map