{"size": 1585, "ext": "js", "max_stars_repo_path": "src/util/sketch.js", "max_stars_repo_name": "reinvanoyen/typex", "max_stars_repo_stars_event_min_datetime": "2018-08-27T19:56:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T04:35:01.000Z", "max_issues_repo_path": "src/util/sketch.js", "max_issues_repo_name": "reinvanoyen/typex", "max_issues_repo_issues_event_min_datetime": "2018-09-21T11:57:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T16:12:06.000Z", "max_forks_repo_path": "src/util/sketch.js", "max_forks_repo_name": "reinvanoyen/typex", "max_forks_repo_forks_event_min_datetime": "2019-06-23T14:25:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-03T15:59:41.000Z"}
{"max_stars_count": 47, "max_issues_count": 7, "max_forks_count": 2, "avg_line_length": 25.9836065574, "max_line_length": 119, "alphanum_fraction": 0.632807571}
"use strict";

const sketch = {
  getTextStyles(context) {

    let texts = context.document.documentData().layerTextStyles().objects();
    let rawTextStyles = [];

    texts.forEach((text, i) => {

      rawTextStyles.push({
        attributes: text.style().textStyle().attributes(),
        textStyle: text,
        name: text.name()
      });
    });

    let textStyles = [];

    rawTextStyles.forEach(rawTextStyle => {

      let textStyle = {};

      textStyle.name = rawTextStyle.name;
      textStyle.fontFamily = String(rawTextStyle.attributes.NSFont.fontDescriptor().objectForKey(NSFontNameAttribute));
      textStyle.fontSize = rawTextStyle.attributes.NSFont.fontDescriptor().objectForKey(NSFontSizeAttribute);
      textStyle.paragraph = rawTextStyle.attributes.NSParagraphStyle;

      if (textStyle.paragraph) {
        textStyle.lineHeight = textStyle.paragraph.maximumLineHeight();
      }

      let color = rawTextStyle.attributes.MSAttributedStringColorAttribute;

      if (color) {
        let r = color.red();
        let g = color.green();
        let b = color.blue();
        let a = color.alpha();

        textStyle.color = {
          r: r,
          g: g,
          b: b,
          a: a
        };
      }

      textStyle.letterSpacing = rawTextStyle.attributes.NSKern || 0;
      textStyle.textTransform = parseInt(rawTextStyle.attributes.MSAttributedStringTextTransformAttribute || 0);

      // @TODO strikethrough & underline, or is this not needed?

      textStyles.push(textStyle);
    });

    return textStyles;
  }
};

export default sketch;