"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _defaults2 = _interopRequireDefault(require("lodash/defaults"));

var PIXI = _interopRequireWildcard(require("pixi.js"));

var _default = require("../../constants/default");

var _color = require("../../utils/color");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * Text model
 * converts text model (editor) to Pixi properties
 */
var TextModel = function TextModel(props) {
  _classCallCheck(this, TextModel);

  _defineProperty(this, "text", void 0);

  _defineProperty(this, "style", void 0);

  _defineProperty(this, "backgroundColor", void 0);

  _defineProperty(this, "textDecoration", void 0);

  _defineProperty(this, "writingMode", void 0);

  _defineProperty(this, "width", void 0);

  _defineProperty(this, "height", void 0);

  _defineProperty(this, "wordBreak", 'break-all');

  var scale = new PIXI.Point(1 / _default.DEFAULT_SCALE, 1 / _default.DEFAULT_SCALE);
  var fontSize = props.fontSize * _default.DEFAULT_SCALE;
  var width = props.width;
  var height = props.height;
  Object.assign(this, {
    scale: scale,
    width: width,
    height: height,
    text: props.content,
    backgroundColor: props.backgroundColor === null ? null : (0, _color.colorToHexNumber)(props.backgroundColor),
    textDecoration: props.textDecoration || '',
    writingMode: props.writingMode || '',
    filters: null,
    style: (0, _defaults2.default)({
      fontSize: fontSize,
      fill: (0, _color.colorToHexNumber)(props.color),
      align: props.textAlign,
      // textBaseline: props.verticalAlign,
      fontFamily: props.fontFamily,
      // padding: props.padding,
      letterSpacing: props.letterSpacing,
      wordWrapWidth: width,
      fontWeight: props.fontWeight,
      fontStyle: props.fontStyle,
      lineHeight: props.lineHeight && fontSize * props.lineHeight,
      // disables PIXI word wrap, use custom word wrap logic
      // see /utils/wrap-word
      whiteSpace: 'normal',
      wordWrap: false
    }, _default.PIXI_TEXT_DEFAULT_STYLE)
  });
};

exports.default = TextModel;