You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

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