123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- // breakpoints.scss v1.0 | @ajlkn | MIT licensed */
-
- // Vars.
-
- /// Breakpoints.
- /// @var {list}
- $breakpoints: () !global;
-
- // Mixins.
-
- /// Sets breakpoints.
- /// @param {map} $x Breakpoints.
- @mixin breakpoints($x: ()) {
- $breakpoints: $x !global;
- }
-
- /// Wraps @content in a @media block targeting a specific orientation.
- /// @param {string} $orientation Orientation.
- @mixin orientation($orientation) {
- @media screen and (orientation: #{$orientation}) {
- @content;
- }
- }
-
- /// Wraps @content in a @media block using a given query.
- /// @param {string} $query Query.
- @mixin breakpoint($query: null) {
-
- $breakpoint: null;
- $op: null;
- $media: null;
-
- // Determine operator, breakpoint.
-
- // Greater than or equal.
- @if (str-slice($query, 0, 2) == '>=') {
-
- $op: 'gte';
- $breakpoint: str-slice($query, 3);
-
- }
-
- // Less than or equal.
- @elseif (str-slice($query, 0, 2) == '<=') {
-
- $op: 'lte';
- $breakpoint: str-slice($query, 3);
-
- }
-
- // Greater than.
- @elseif (str-slice($query, 0, 1) == '>') {
-
- $op: 'gt';
- $breakpoint: str-slice($query, 2);
-
- }
-
- // Less than.
- @elseif (str-slice($query, 0, 1) == '<') {
-
- $op: 'lt';
- $breakpoint: str-slice($query, 2);
-
- }
-
- // Not.
- @elseif (str-slice($query, 0, 1) == '!') {
-
- $op: 'not';
- $breakpoint: str-slice($query, 2);
-
- }
-
- // Equal.
- @else {
-
- $op: 'eq';
- $breakpoint: $query;
-
- }
-
- // Build media.
- @if ($breakpoint and map-has-key($breakpoints, $breakpoint)) {
-
- $a: map-get($breakpoints, $breakpoint);
-
- // Range.
- @if (type-of($a) == 'list') {
-
- $x: nth($a, 1);
- $y: nth($a, 2);
-
- // Max only.
- @if ($x == null) {
-
- // Greater than or equal (>= 0 / anything)
- @if ($op == 'gte') {
- $media: 'screen';
- }
-
- // Less than or equal (<= y)
- @elseif ($op == 'lte') {
- $media: 'screen and (max-width: ' + $y + ')';
- }
-
- // Greater than (> y)
- @elseif ($op == 'gt') {
- $media: 'screen and (min-width: ' + ($y + 1) + ')';
- }
-
- // Less than (< 0 / invalid)
- @elseif ($op == 'lt') {
- $media: 'screen and (max-width: -1px)';
- }
-
- // Not (> y)
- @elseif ($op == 'not') {
- $media: 'screen and (min-width: ' + ($y + 1) + ')';
- }
-
- // Equal (<= y)
- @else {
- $media: 'screen and (max-width: ' + $y + ')';
- }
-
- }
-
- // Min only.
- @else if ($y == null) {
-
- // Greater than or equal (>= x)
- @if ($op == 'gte') {
- $media: 'screen and (min-width: ' + $x + ')';
- }
-
- // Less than or equal (<= inf / anything)
- @elseif ($op == 'lte') {
- $media: 'screen';
- }
-
- // Greater than (> inf / invalid)
- @elseif ($op == 'gt') {
- $media: 'screen and (max-width: -1px)';
- }
-
- // Less than (< x)
- @elseif ($op == 'lt') {
- $media: 'screen and (max-width: ' + ($x - 1) + ')';
- }
-
- // Not (< x)
- @elseif ($op == 'not') {
- $media: 'screen and (max-width: ' + ($x - 1) + ')';
- }
-
- // Equal (>= x)
- @else {
- $media: 'screen and (min-width: ' + $x + ')';
- }
-
- }
-
- // Min and max.
- @else {
-
- // Greater than or equal (>= x)
- @if ($op == 'gte') {
- $media: 'screen and (min-width: ' + $x + ')';
- }
-
- // Less than or equal (<= y)
- @elseif ($op == 'lte') {
- $media: 'screen and (max-width: ' + $y + ')';
- }
-
- // Greater than (> y)
- @elseif ($op == 'gt') {
- $media: 'screen and (min-width: ' + ($y + 1) + ')';
- }
-
- // Less than (< x)
- @elseif ($op == 'lt') {
- $media: 'screen and (max-width: ' + ($x - 1) + ')';
- }
-
- // Not (< x and > y)
- @elseif ($op == 'not') {
- $media: 'screen and (max-width: ' + ($x - 1) + '), screen and (min-width: ' + ($y + 1) + ')';
- }
-
- // Equal (>= x and <= y)
- @else {
- $media: 'screen and (min-width: ' + $x + ') and (max-width: ' + $y + ')';
- }
-
- }
-
- }
-
- // String.
- @else {
-
- // Missing a media type? Prefix with "screen".
- @if (str-slice($a, 0, 1) == '(') {
- $media: 'screen and ' + $a;
- }
-
- // Otherwise, use as-is.
- @else {
- $media: $a;
- }
-
- }
-
- }
-
- // Output.
- @media #{$media} {
- @content;
- }
-
- }
|