_linear-positions-parser.scss 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. @function _linear-positions-parser($pos) {
  2. $type: type-of(nth($pos, 1));
  3. $spec: null;
  4. $degree: null;
  5. $side: null;
  6. $corner: null;
  7. $length: length($pos);
  8. // Parse Side and corner positions
  9. @if ($length > 1) {
  10. @if nth($pos, 1) == "to" { // Newer syntax
  11. $side: nth($pos, 2);
  12. @if $length == 2 { // eg. to top
  13. // Swap for backwards compatability
  14. $degree: _position-flipper(nth($pos, 2));
  15. }
  16. @else if $length == 3 { // eg. to top left
  17. $corner: nth($pos, 3);
  18. }
  19. }
  20. @else if $length == 2 { // Older syntax ("top left")
  21. $side: _position-flipper(nth($pos, 1));
  22. $corner: _position-flipper(nth($pos, 2));
  23. }
  24. @if ("#{$side} #{$corner}" == "left top") or ("#{$side} #{$corner}" == "top left") {
  25. $degree: _position-flipper(#{$side}) _position-flipper(#{$corner});
  26. }
  27. @else if ("#{$side} #{$corner}" == "right top") or ("#{$side} #{$corner}" == "top right") {
  28. $degree: _position-flipper(#{$side}) _position-flipper(#{$corner});
  29. }
  30. @else if ("#{$side} #{$corner}" == "right bottom") or ("#{$side} #{$corner}" == "bottom right") {
  31. $degree: _position-flipper(#{$side}) _position-flipper(#{$corner});
  32. }
  33. @else if ("#{$side} #{$corner}" == "left bottom") or ("#{$side} #{$corner}" == "bottom left") {
  34. $degree: _position-flipper(#{$side}) _position-flipper(#{$corner});
  35. }
  36. $spec: to $side $corner;
  37. }
  38. @else if $length == 1 {
  39. // Swap for backwards compatability
  40. @if $type == string {
  41. $degree: $pos;
  42. $spec: to _position-flipper($pos);
  43. }
  44. @else {
  45. $degree: -270 - $pos; //rotate the gradient opposite from spec
  46. $spec: $pos;
  47. }
  48. }
  49. $degree: unquote($degree + ",");
  50. $spec: unquote($spec + ",");
  51. @return $degree $spec;
  52. }
  53. @function _position-flipper($pos) {
  54. @return if($pos == left, right, null)
  55. if($pos == right, left, null)
  56. if($pos == top, bottom, null)
  57. if($pos == bottom, top, null);
  58. }