Component({
  properties: {
    // mj-lanmao | mj-heimao | mj--astonished | mj--angel | mj--devil | mj--in-love | mj--mute | mj--sad | mj--sad- | mj--scared | mj--secret | mj--scared- | mj--shocked | mj--sick | mj--smile | mj--smile- | mj--sleeping | mj--smiling- | mj--smiling | mj--sweat | mj--surprised | mj--smirking | mj--thinking | mj--tired | mj--tongue | mj--tongue- | mj--tongue-1 | mj--unamused | mj--wink | mj--vomiting | mj--zombie | mj--vomiting- | mj--newastonished- | mj--cool | mj--confused | mj--angry | mj--cool- | mj--dizzy | mj--cry | mj--cry- | mj--expressionless | mj--flushed | mj--happy- | mj--happy-1 | mj--happy | mj--injury | mj--joy | mj--kiss | mj--kiss- | mj--kiss-1 | mj--mask | mj--neutral
    name: {
      type: String,
    },
    // string | string[]
    color: {
      type: null,
      observer: function(color) {
        this.setData({
          colors: this.fixColor(),
          isStr: typeof color === 'string',
        });
      }
    },
    size: {
      type: Number,
      value: 18,
      observer: function(size) {
        this.setData({
          svgSize: size,
        });
      },
    },
  },
  data: {
    colors: '',
    svgSize: 18,
    quot: '"',
    isStr: true,
  },
  methods: {
    fixColor: function() {
      var color = this.data.color;
      var hex2rgb = this.hex2rgb;

      if (typeof color === 'string') {
        return color.indexOf('#') === 0 ? hex2rgb(color) : color;
      }

      return color.map(function (item) {
        return item.indexOf('#') === 0 ? hex2rgb(item) : item;
      });
    },
    hex2rgb: function(hex) {
      var rgb = [];

      hex = hex.substr(1);

      if (hex.length === 3) {
        hex = hex.replace(/(.)/g, '$1$1');
      }

      hex.replace(/../g, function(color) {
        rgb.push(parseInt(color, 0x10));
        return color;
      });

      return 'rgb(' + rgb.join(',') + ')';
    }
  }
});
