functions.scss 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. @import './functions/calc-math';
  2. /*
  3. * Method which inserts a full background-image property for a theme image.
  4. * It checks if the file exists and if it doesn't, it'll throw an error.
  5. * By default it will not include the background-image property if it is not found,
  6. * but this can be changed by changing the default value of $enable-missing-images to
  7. * be true.
  8. */
  9. @function theme-background-image($path, $extension: $image-extension, $nocheck: false) {
  10. $path: file_join($relative-image-path-for-uis, $path + '.' + $extension);
  11. $background-image: none;
  12. @if $path {
  13. @if $nocheck {
  14. $background-image: $path;
  15. } @else if theme_image_exists($image-search-path, $path) {
  16. $background-image: $path;
  17. } @else {
  18. @warn "@theme-background-image: Theme image not found: #{$path}";
  19. @if $enable-missing-images {
  20. $background-image: $path;
  21. }
  22. }
  23. @if $background-image != none {
  24. $background-image: url(file_join($theme-resource-path, $path));
  25. }
  26. } @else {
  27. @warn "@theme-background-image: No arguments passed";
  28. }
  29. @return $background-image;
  30. }
  31. @function get-image-url($path, $extension: $image-extension, $nocheck: false) {
  32. @return theme-background-image($path, $extension, $nocheck);
  33. }
  34. @function x($position) {
  35. @return parsebox($position, 1);
  36. }
  37. @function y($position) {
  38. @return parsebox($position, 2);
  39. }
  40. @function before($position) {
  41. @return parsebox($position, 1);
  42. }
  43. @function after($position) {
  44. @return parsebox($position, 2);
  45. }
  46. @function top($box) {
  47. @return parsebox($box, 1);
  48. }
  49. @function right($box) {
  50. @return parsebox($box, 2);
  51. }
  52. @function bottom($box) {
  53. @return parsebox($box, 3);
  54. }
  55. @function left($box) {
  56. @return parsebox($box, 4);
  57. }
  58. @function vertical($box) {
  59. $top: top($box);
  60. $bottom: bottom($box);
  61. @if $top == null or $bottom == null {
  62. @return null;
  63. }
  64. @return $top + $bottom;
  65. }
  66. @function horizontal($box) {
  67. $left: left($box);
  68. $right: right($box);
  69. @if $left == null or $right == null {
  70. @return null;
  71. }
  72. @return $left + $right;
  73. }
  74. @function boxmax($box) {
  75. @return max(max(top($box), right($box)), max(bottom($box), left($box)));
  76. }
  77. @function boxmin($box) {
  78. @return min(min(top($box), right($box)), min(bottom($box), left($box)));
  79. }
  80. @function boxContainsNull($list) {
  81. @for $i from 1 through length($list) {
  82. @if nth($list, $i) == null {
  83. @return true;
  84. }
  85. }
  86. @return false;
  87. }
  88. @function box($top, $right, $bottom, $left) {
  89. @if type-of($top) == list {
  90. $right: right($top);
  91. $bottom: bottom($top);
  92. $left: left($top);
  93. $top: top($top);
  94. }
  95. @if $top == $bottom and $right == $left {
  96. @if $top == $right {
  97. @return $top;
  98. }
  99. @return ($top $right);
  100. }
  101. @if $left == $right {
  102. @return ($top $right $bottom);
  103. }
  104. @return ($top $right $bottom $left);
  105. }
  106. @function rotate90($box) {
  107. @return box(left($box), top($box), right($box), bottom($box));
  108. }
  109. @function rotate180($box) {
  110. @return box(bottom($box), left($box), top($box), right($box));
  111. }
  112. @function rotate270($box) {
  113. @return box(right($box), bottom($box), left($box), top($box));
  114. }
  115. @function flip-vertical($box) {
  116. @return box(bottom($box), right($box), top($box), left($box));
  117. }
  118. @function flip-horizontal($box) {
  119. @return box(top($box), left($box), bottom($box), right($box));
  120. }
  121. @function rtl($box) {
  122. @return box(top($box), left($box), bottom($box), right($box));
  123. }
  124. @function rtl-background-position($pos) {
  125. $x: parsebox($pos, 1);
  126. $new-x: null;
  127. @if $x == right or $x == 100% {
  128. $new-x: 0;
  129. } @else if $x == 0 or $x == left {
  130. $new-x: right;
  131. } @else {
  132. $new-x: $x;
  133. }
  134. @return $new-x parsebox($pos, 2);
  135. }
  136. @function nopx ($value) {
  137. @if $value == 0 {
  138. @return 0;
  139. }
  140. @return $value / 1px;
  141. }
  142. @function invert-shadow($shadow, $axis) {
  143. @if $axis != x and $axis != y {
  144. @error 'invalid value for $axis: #{$axis}';
  145. }
  146. $inverted-shadow: ();
  147. $counter: if($axis == x, 2, 1);
  148. @for $i from 1 through length($shadow) {
  149. $item: nth($shadow, $i);
  150. @if type-of($item) == number {
  151. @if $counter == 2 {
  152. // the first number in a box-shadow value is always the offset-x,
  153. // the second number is always offset-y
  154. $item: -$item;
  155. }
  156. $counter: $counter + 1;
  157. }
  158. $inverted-shadow: append($inverted-shadow, $item);
  159. }
  160. @return $inverted-shadow;
  161. }
  162. @function coalesce($values...) {
  163. $found: false;
  164. $ret: null;
  165. @for $i from 1 through length($values) {
  166. $value: nth($values, $i);
  167. @if $value != null and not $found {
  168. $ret: $value;
  169. $found: true;
  170. }
  171. }
  172. @return $ret;
  173. }