All files / lib/properties azimuth.js

0% Statements 0/34
0% Branches 0/42
0% Functions 0/2
0% Lines 0/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                                                                                                                       
'use strict';
 
var parsers = require('../parsers');
 
module.exports.definition = {
  set: function(v) {
    var valueType = parsers.valueType(v);
    if (valueType === parsers.TYPES.ANGLE) {
      return this._setProperty('azimuth', parsers.parseAngle(v));
    }
    if (valueType === parsers.TYPES.KEYWORD) {
      var keywords = v
        .toLowerCase()
        .trim()
        .split(/\s+/);
      var hasBehind = false;
      if (keywords.length > 2) {
        return;
      }
      var behindIndex = keywords.indexOf('behind');
      hasBehind = behindIndex !== -1;
 
      if (keywords.length === 2) {
        if (!hasBehind) {
          return;
        }
        keywords.splice(behindIndex, 1);
      }
      if (keywords[0] === 'leftwards' || keywords[0] === 'rightwards') {
        if (hasBehind) {
          return;
        }
        return this._setProperty('azimuth', keywords[0]);
      }
      if (keywords[0] === 'behind') {
        return this._setProperty('azimuth', '180deg');
      }
      switch (keywords[0]) {
        case 'left-side':
          return this._setProperty('azimuth', '270deg');
        case 'far-left':
          return this._setProperty('azimuth', (hasBehind ? 240 : 300) + 'deg');
        case 'left':
          return this._setProperty('azimuth', (hasBehind ? 220 : 320) + 'deg');
        case 'center-left':
          return this._setProperty('azimuth', (hasBehind ? 200 : 340) + 'deg');
        case 'center':
          return this._setProperty('azimuth', (hasBehind ? 180 : 0) + 'deg');
        case 'center-right':
          return this._setProperty('azimuth', (hasBehind ? 160 : 20) + 'deg');
        case 'right':
          return this._setProperty('azimuth', (hasBehind ? 140 : 40) + 'deg');
        case 'far-right':
          return this._setProperty('azimuth', (hasBehind ? 120 : 60) + 'deg');
        case 'right-side':
          return this._setProperty('azimuth', '90deg');
        default:
          return;
      }
    }
  },
  get: function() {
    return this.getPropertyValue('azimuth');
  },
  enumerable: true,
  configurable: true,
};