diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c15aa9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +.sass-cache/ \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..98bcbaa --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Dmitry Artemov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8711aa8 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# SCSS mixins + +## Usage + +1. `git clone https://github.com/beliarh/scss-mixins.git` +2. `@import 'scss-mixins/all';` + +## Required Sass version + +Sass 3.4.0+ \ No newline at end of file diff --git a/_all.scss b/_all.scss new file mode 100644 index 0000000..61cecc5 --- /dev/null +++ b/_all.scss @@ -0,0 +1,24 @@ +@import "mixins/align"; +@import "mixins/animation"; +@import "mixins/backface"; +@import "mixins/background"; +@import "mixins/border"; +@import "mixins/box"; +@import "mixins/clearfix"; +@import "mixins/column"; +@import "mixins/filter"; +@import "mixins/flex"; +@import "mixins/fullscreen"; +@import "mixins/gradient"; +@import "mixins/justify"; +@import "mixins/keyframes"; +@import "mixins/order"; +@import "mixins/perspective"; +@import "mixins/placeholder"; +@import "mixins/reset"; +@import "mixins/selection"; +@import "mixins/tab"; +@import "mixins/transform"; +@import "mixins/transition"; +@import "mixins/triangle"; +@import "mixins/user"; \ No newline at end of file diff --git a/functions/_base-functions.scss b/functions/_base-functions.scss new file mode 100644 index 0000000..b034fde --- /dev/null +++ b/functions/_base-functions.scss @@ -0,0 +1,120 @@ +@function is-string($value) { + @return type-of($value) == string; +} + +@function is-number($value) { + @return type-of($value) == number; +} + +@function is-color($value) { + @return type-of($value) == color or (is-string($value) and to-lower-case($value) == currentcolor); +} + +@function is-list($value) { + @return type-of($value) == list; +} + +@function is-arglist($value) { + @return type-of($value) == arglist; +} + +@function is-list-like($value) { + @return is-list($value) or is-arglist($value); +} + +@function is-comma-separated($value) { + @return list-separator($value) == comma; +} + +@function is-space-separated($value) { + @return list-separator($value) == space; +} + +@function is-comma-list($value) { + @return is-list($value) and is-comma-separated($value); +} + +@function is-space-list($value) { + @return is-list($value) and is-space-separated($value); +} + +@function is-map($value) { + @return type-of($value) == map; +} + +@function is-percentage($value) { + @return is-number($value) and unit($value) == '%'; +} + +@function is-length($value) { + @return is-number($value) and not not index(em ex ch rem vh vw vmin vmax px mm cm in pt pc, unit($value)); +} + +@function is-angle($value) { + @if is-number($value) and index(deg grad rad turn, unit($value)) { + @return true; + } + @return false; +} + +@function is-width($value) { + @return $value == auto or is-length($value) or is-percentage($value); +} + +@function is-side-or-corner($value) { + @if is-space-separated($value) { + $length: length($value); + $arg1: nth($value, 1); + @if $length == 1 { + @return not not index(left right top bottom, $arg1); + } + @if $length == 2 { + @if index(left right, $arg1) { + @return not not index(top bottom, nth($value, 2)); + } + @if index(top bottom, $arg1) { + @return not not index(left right, nth($value, 2)); + } + } + } + @return false; +} + +@function is-extent-keyword($value) { + @return not not index(closest-corner closest-side farthest-corner farthest-side, $value); +} + +@function is-time($value) { + @return is-number($value) and not not index(ms s, unit($value)); +} + +@function is-timing-function($value) { + @if is-string($value) { + @if index(ease linear ease-in ease-out ease-in-out step-start step-end, $value) { + @return true; + } + @if str-slice($value, 1, 6) == 'steps(' and str-slice($value, -1) == ')' { + @return true; + } + @if str-slice($value, 1, 13) == 'cubic-bezier(' and str-slice($value, -1) == ')' { + @return true; + } + } + @return false; +} + +@function slice-list($list, $from: 1, $to: length($list)) { + $slice: join((), (), list-separator($list)); + @for $i from $from through $to { + $slice: append($slice, nth($list, $i)); + } + @return $slice; +} + +@function unwrap-list($list, $arglist-only: false) { + $list-types: if($arglist-only, arglist, list arglist); + @while index($list-types, type-of($list)) and length($list) == 1 { + $list: nth($list, 1); + } + @return $list; +} \ No newline at end of file diff --git a/functions/_helpers.scss b/functions/_helpers.scss new file mode 100644 index 0000000..b5910ab --- /dev/null +++ b/functions/_helpers.scss @@ -0,0 +1,147 @@ +@import "base-functions"; + +@function __angle-to-webkit-gradient-direction($angle) { + $angle: $angle % 360deg; + $one-sixteenth: 360deg / 16; + @if $angle >= $one-sixteenth * 15 or $angle < $one-sixteenth * 1 { + @return (center bottom, center top); + } + @if $angle >= $one-sixteenth * 1 and $angle < $one-sixteenth * 3 { + @return (left bottom, right top); + } + @if $angle >= $one-sixteenth * 3 and $angle < $one-sixteenth * 5 { + @return (left center, right center); + } + @if $angle >= $one-sixteenth * 5 and $angle < $one-sixteenth * 7 { + @return (left top, right bottom); + } + @if $angle >= $one-sixteenth * 7 and $angle < $one-sixteenth * 9 { + @return (center top, center bottom); + } + @if $angle >= $one-sixteenth * 9 and $angle < $one-sixteenth * 11 { + @return (right top, left bottom); + } + @if $angle >= $one-sixteenth * 11 and $angle < $one-sixteenth * 13 { + @return (right center, left center); + } + @if $angle >= $one-sixteenth * 13 and $angle < $one-sixteenth * 15 { + @return (right bottom, left top); + } +} + +@function __parsed-color-stops-to-list($parsed-color-stops) { + $color-stops: (); + @each $parsed-color-stop in $parsed-color-stops { + $color: map-get($parsed-color-stop, 'color'); + $position: map-get($parsed-color-stop, 'position'); + $color-stop: if($position, $color $position, $color); + $color-stops: append($color-stops, $color-stop, comma); + } + @return $color-stops; +} + +@function __parsed-color-stops-to-webkit-color-stops($parsed-color-stops) { + $length: length($parsed-color-stops); + @if $length < 2 { + @return null; + } + $color-stops: (); + $color-stop-maps: (); + $colors-buffer: (); + @for $i from 1 through $length { + $parsed-color-stop: nth($parsed-color-stops, $i); + $color: map-get($parsed-color-stop, 'color'); + $position: map-get($parsed-color-stop, 'position'); + @if $position == null { + @if $i == 1 { + $position: 0%; + } @else if $i == $length { + $position: 100%; + } + } + @if ($i == $length or is-percentage($position)) and length($colors-buffer) > 0 { + $last-index: length($color-stop-maps); + $last-color-stop: nth($color-stop-maps, $last-index); + $last-position: map-get($last-color-stop, 'position'); + $increment: ($position - $last-position) / ($i - $last-index); + @each $buffered-color in $colors-buffer { + $last-position: $last-position + $increment; + $color-stop: unquote('color-stop(#{$last-position}, #{$buffered-color})'); + $color-stops: append($color-stops, $color-stop, comma); + $color-stop-map: ('color': $buffered-color, 'position': $last-position); + $color-stop-maps: append($color-stop-maps, $color-stop-map); + } + $colors-buffer: (); + } + @if $position == null { + $colors-buffer: append($colors-buffer, $color); + } @else if is-percentage($position) { + $color-stop: unquote('color-stop(#{$position}, #{$color})'); + $color-stops: append($color-stops, $color-stop, comma); + $color-stop-map: ('color': $color, 'position': $position); + $color-stop-maps: append($color-stop-maps, $color-stop-map); + } @else { + @return null; + } + } + @return $color-stops; +} + +@function __prefix-transition-properties($properties...) { + $properties: unwrap-list($properties); + $webkit-properties: (); + $moz-properties: (); + $o-properties: (); + @each $property in $properties { + $webkit-property: $property; + $moz-property: $property; + $o-property: $property; + $prefixes: map-get(( + 'transform': -webkit -moz -o, + 'transform-origin': -webkit -moz -o, + 'perspective': -webkit -moz, + 'perspective-origin': -webkit -moz, + 'column-width': -webkit -moz, + 'column-count': -webkit -moz, + 'column-gap': -webkit -moz, + 'column-rule': -webkit -moz, + 'column-rule-color': -webkit -moz, + 'column-rule-width': -webkit -moz, + 'flex': -webkit, + 'flex-basis': -webkit, + 'background-size': -webkit -moz -o, + 'border-radius': -webkit -moz, + 'box-shadow': -webkit -moz, + ), $property); + @if $prefixes { + @if index($prefixes, -webkit) { + $webkit-property: -webkit-#{$property}; + } + @if index($prefixes, -moz) { + $moz-property: -moz-#{$property}; + } + @if index($prefixes, -o) { + $o-property: -o-#{$property}; + } + } @else { + $moz-single-border-radius: map-get(( + 'border-top-left-radius': -moz-border-radius-topleft, + 'border-top-right-radius': -moz-border-radius-topright, + 'border-bottom-left-radius': -moz-border-radius-bottomleft, + 'border-bottom-right-radius': -moz-border-radius-bottomright, + ), $property); + @if $moz-single-border-radius { + $webkit-property: -webkit-#{$property}; + $moz-property: $moz-single-border-radius; + } + } + $webkit-properties: append($webkit-properties, $webkit-property, comma); + $moz-properties: append($moz-properties, $moz-property, comma); + $o-properties: append($o-properties, $o-property, comma); + } + @return ( + '-webkit': $webkit-properties, + '-moz': $moz-properties, + '-o': $o-properties, + ); +} \ No newline at end of file diff --git a/functions/_parse-background-position.scss b/functions/_parse-background-position.scss new file mode 100644 index 0000000..de7a3b7 --- /dev/null +++ b/functions/_parse-background-position.scss @@ -0,0 +1,49 @@ +@import "base-functions"; + +@function __parse-background-position($background-position) { + @if is-comma-separated($background-position) { + // + @return null; + } + $length: length($background-position); + @if not ($length >= 1 and $length <= 2) { + // Incorrect arguments count + @return null; + } + $arg1: unquote(nth($background-position, 1)); + @if is-length($arg1) or is-percentage($arg1) or index(left center right, $arg1) { + // [ | | left | center | right] ... + @if $length == 1 { + // [ | | left | center | right] + @return ('x': $arg1, 'y': center); + } + $arg2: unquote(nth($background-position, 2)); + @if is-length($arg2) or is-percentage($arg2) or index(top center bottom, $arg2) { + // [ | | left | center | right] [ | | top | center | bottom] + @return ('x': $arg1, 'y': $arg2); + } @else if $arg1 == center and index(left right, $arg2) { + // center [left | right] + @return ('x': $arg2, 'y': $arg1); + } @else { + // [ | | left | center | right] + @return null; + } + } @else if index(top center bottom, $arg1) { + // [top | center | bottom] ... + @if $length == 1 { + // [top | center | bottom] + @return ('x': center, 'y': $arg1); + } + $arg2: unquote(nth($background-position, 2)); + @if index(left center right, $arg2) { + // [top | center | bottom] [left | center | right] + @return ('x': $arg2, 'y': $arg1); + } @else { + // [top | center | bottom] + @return null; + } + } @else { + // + @return null; + } +} \ No newline at end of file diff --git a/functions/_parse-color-stop.scss b/functions/_parse-color-stop.scss new file mode 100644 index 0000000..a0ff7ef --- /dev/null +++ b/functions/_parse-color-stop.scss @@ -0,0 +1,43 @@ +@import "base-functions"; + +@function __parse-color-stop($color-stop) { + @if is-comma-separated($color-stop) { + // + @return null; + } + $length: length($color-stop); + @if not ($length >= 1 and $length <= 2) { + // Incorrect arguments count. + @return null; + } + $arg1: unquote(nth($color-stop, 1)); + @if not is-color($arg1) { + // ... + @return null; + } + // ... + @if $length == 1 { + // + @return ( + 'color': $arg1, + 'position': null + ); + } + $arg2: nth($color-stop, 2); + @if is-length($arg2) or is-percentage($arg2) { + // [ | ] + @return ( + 'color': $arg1, + 'position': $arg2 + ); + } @else if is-number($arg2) and unitless($arg2) { + // + @return ( + 'color': $arg1, + 'position': $arg2 * 1px + ); + } @else { + // + @return null; + } +} \ No newline at end of file diff --git a/functions/_parse-flex.scss b/functions/_parse-flex.scss new file mode 100644 index 0000000..ca62929 --- /dev/null +++ b/functions/_parse-flex.scss @@ -0,0 +1,110 @@ +@import "base-functions"; + +@function __parse-flex($flex) { + @if is-comma-separated($flex) { + // + @return null; + } + $length: length($flex); + @if not ($length >= 1 and $length <= 3) { + // Incorrect arguments count. + @return null; + } + $arg1: nth($flex, 1); + @if $arg1 == none { + // none ... + @if $length == 1 { + // none + @return none; + } + // none + @return null; + } + @if is-number($arg1) and unitless($arg1) { + // ... + @if $length == 1 { + // + @return ( + 'grow': $arg1, + 'shrink': 1, + 'basis': auto + ); + } + $arg2: nth($flex, 2); + @if is-number($arg2) and unitless($arg2) { + // ... + @if $length == 2 { + // + @return ( + 'grow': $arg1, + 'shrink': $arg2, + 'basis': auto + ); + } + $arg3: nth($flex, 3); + @if is-width($arg3) { + // + @return ( + 'grow': $arg1, + 'shrink': $arg2, + 'basis': $arg3 + ); + } + // + @return null; + } + @if is-width($arg2) { + // ... + @if $length == 2 { + // + @return ( + 'grow': $arg1, + 'shrink': 1, + 'basis': $arg2 + ); + } + // + @return null; + } + // + @return null; + } + @if is-width($arg1) { + // ... + @if $length == 1 { + // + @return ( + 'grow': 0, + 'shrink': 1, + 'basis': $arg1 + ); + } + $arg2: nth($flex, 2); + @if is-number($arg2) and unitless($arg2) { + // ... + @if $length == 2 { + // + @return ( + 'grow': $arg2, + 'shrink': 1, + 'basis': $arg1 + ); + } + $arg3: nth($flex, 3); + @if is-number($arg3) and unitless($arg3) { + // + @return ( + 'grow': $arg2, + 'shrink': $arg3, + 'basis': $arg1 + ); + } + // + @return null; + } + // + @return null; + } + // + @return null; +} \ No newline at end of file diff --git a/functions/_parse-linear-gradient.scss b/functions/_parse-linear-gradient.scss new file mode 100644 index 0000000..29ec2af --- /dev/null +++ b/functions/_parse-linear-gradient.scss @@ -0,0 +1,89 @@ +@import "base-functions"; +@import "parse-color-stop"; + +@function __parse-linear-gradient($linear-gradient...) { + $linear-gradient: unwrap-list($linear-gradient); + @if length($linear-gradient) == 0 { + // + @return null; + } + @if is-space-separated($linear-gradient) { + $linear-gradient: ($linear-gradient,); + } + $arg1: nth($linear-gradient, 1); + $length_arg1: length($arg1); + @if is-comma-separated($arg1) { + // , ... + @return null; + } + @if $length_arg1 == 0 { + // , ... + @return null; + } + $angle: null; + $color-stops: (); + $color-stop: __parse-color-stop($arg1); + @if $color-stop { + // , ... + $angle: 180deg; // to bottom + $color-stops: append($color-stops, $color-stop, comma); + } @else { + @if length($linear-gradient) < 2 { + // Incorrect arguments count + @return null; + } + @if is-angle($arg1) { + // , ... + $angle: $arg1; + } @else if nth($arg1, 1) == to { + // to ... , ... + @if $length_arg1 == 1 { + // to , ... + @return null; + } + $side-or-corner: slice-list($arg1, 2, $length_arg1); + @if not is-side-or-corner($side-or-corner) { + // to , ... + @return null; + } + // to , ... + $angle: map-get(( + 'top': 0deg, + 'top right': 45deg, + 'right top': 45deg, + 'right': 90deg, + 'right bottom': 135deg, + 'bottom right': 135deg, + 'bottom': 180deg, + 'bottom left': 225deg, + 'left bottom': 225deg, + 'left': 270deg, + 'left top': 315deg, + 'top left': 315deg + ), inspect($side-or-corner)); + } @else { + // , ... + @return null; + } + } + @if length($linear-gradient) >= 2 { + @each $color-stop in slice-list($linear-gradient, 2) { + $color-stop: __parse-color-stop($color-stop); + @if not $color-stop { + // Incorrect color-stop + @return null; + } + $color-stops: append($color-stops, $color-stop, comma); + } + } + @if length($color-stops) == 1 { + $color-stops: append($color-stops, ( + 'color': transparent, + 'position': null + ), comma); + } + @return ( + 'angle': $angle, + 'color-stops': $color-stops + ); +} \ No newline at end of file diff --git a/functions/_parse-linear-gradients.scss b/functions/_parse-linear-gradients.scss new file mode 100644 index 0000000..4092f1c --- /dev/null +++ b/functions/_parse-linear-gradients.scss @@ -0,0 +1,23 @@ +@import "base-functions"; +@import "parse-linear-gradient"; + +@function __parse-linear-gradients($linear-gradients...) { + $linear-gradients: unwrap-list($linear-gradients, true); + @if length($linear-gradients) == 0 { + // + @return null; + } + @if is-space-separated(nth($linear-gradients, 1)) { + $linear-gradients: ($linear-gradients,); + } + $parsed-linear-gradients: (); + @each $linear-gradient in $linear-gradients { + $parsed-linear-gradient: __parse-linear-gradient($linear-gradient); + @if not $parsed-linear-gradient { + // Incorrect linear-gradient + @return null; + } + $parsed-linear-gradients: append($parsed-linear-gradients, $parsed-linear-gradient, comma); + } + @return $parsed-linear-gradients; +} \ No newline at end of file diff --git a/functions/_parse-radial-gradient.scss b/functions/_parse-radial-gradient.scss new file mode 100644 index 0000000..8cbfe0d --- /dev/null +++ b/functions/_parse-radial-gradient.scss @@ -0,0 +1,470 @@ +@import "base-functions"; +@import "parse-background-position"; +@import "parse-color-stop"; + +@function __parse-radial-gradient($radial-gradient...) { + $radial-gradient: unwrap-list($radial-gradient); + @if length($radial-gradient) == 0 { + // + @return null; + } + @if is-space-separated($radial-gradient) { + $radial-gradient: ($radial-gradient,); + } + $arg1: nth($radial-gradient, 1); + $length_arg1: length($arg1); + @if is-comma-separated($arg1) { + // , ... + @return null; + } + @if $length_arg1 == 0 { + // , ... + @return null; + } + $shape: null; + $size: null; + $position: null; + $color-stops: (); + $color-stop: __parse-color-stop($arg1); + @if $color-stop { + // , ... + $shape: ellipse; + $size: farthest-corner; + $position: ('x': center, 'y': center); + $color-stops: append($color-stops, $color-stop, comma); + } @else { + @if length($radial-gradient) < 2 { + // Incorrect arguments count + @return null; + } + $arg1_1: unquote(nth($arg1, 1)); + @if $arg1_1 == circle { + // circle ... , ... + @if $length_arg1 == 1 { + // circle , ... + $shape: $arg1_1; + $size: farthest-corner; + $position: ('x': center, 'y': center); + } @else { + $arg1_2: unquote(nth($arg1, 2)); + @if $arg1_2 == at { + // circle at ... , ... + @if $length_arg1 == 2 { + // circle at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 3, $length_arg1)); + @if not $position { + // circle at ... , ... + @return null; + } + // circle at , ... + $shape: $arg1_1; + $size: farthest-corner; + //$position: $position; + } @else if is-length($arg1_2) or is-extent-keyword($arg1_2) { + // circle [ | ] ... , ... + @if $length_arg1 == 2 { + // circle [ | ] , ... + $shape: $arg1_1; + $size: $arg1_2; + $position: ('x': center, 'y': center); + } @else { + @if nth($arg1, 3) != at { + // circle [ | ] ... , ... + @return null; + } + // circle [ | ] at ... , ... + @if $length_arg1 == 3 { + // circle [ | ] at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 4, $length_arg1)); + @if not $position { + // circle [ | ] at ... , ... + @return null; + } + // circle [ | ] at , ... + $shape: $arg1_1; + $size: $arg1_2; + //$position: $position; + } + } @else { + // circle ... , ... + @return null; + } + } + } @else if is-length($arg1_1) { + // ... , ... + @if $length_arg1 == 1 { + // , ... + $shape: circle; + $size: $arg1_1; + $position: ('x': center, 'y': center); + } @else { + $arg1_2: unquote(nth($arg1, 2)); + @if $arg1_2 == at { + // at ... , ... + @if $length_arg1 == 2 { + // at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 3, $length_arg1)); + @if not $position { + // at ... , ... + @return null; + } + // at , ... + $shape: circle; + $size: $arg1_1; + //$position: $position; + } @else if $arg1_2 == circle { + // circle ... , ... + @if $length_arg1 == 2 { + // circle , ... + $shape: $arg1_2; + $size: $arg1_1; + $position: ('x': center, 'y': center); + } @else { + @if nth($arg1, 3) != at { + // circle ... , ... + @return null; + } + // circle at ... , ... + @if $length_arg1 == 3 { + // circle at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 4, $length_arg1)); + @if not $position { + // circle at ... , ... + @return null; + } + // circle at , ... + $shape: $arg1_2; + $size: $arg1_1; + //$position: $position; + } + } @else if is-length($arg1_2) or is-percentage($arg1_2) { + // [ | ] ... , ... + @if $length_arg1 == 2 { + // [ | ] , ... + $shape: ellipse; + $size: $arg1_1 $arg1_2; + $position: ('x': center, 'y': center); + } @else { + $arg1_3: unquote(nth($arg1, 3)); + @if $arg1_3 == at { + // [ | ] at ... , ... + @if $length_arg1 == 3 { + // [ | ] at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 4, $length_arg1)); + @if not $position { + // [ | ] at ... , ... + @return null; + } + // [ | ] at , ... + $shape: ellipse; + $size: $arg1_1 $arg1_2; + //$position: $position; + } @else if $arg1_3 == ellipse { + // [ | ] ellipse ... , ... + @if $length_arg1 == 3 { + // [ | ] ellipse , ... + $shape: $arg1_3; + $size: $arg1_1 $arg1_2; + $position: ('x': center, 'y': center); + } @else { + @if nth($arg1, 4) != at { + // [ | ] ellipse ... , ... + @return null; + } + // [ | ] ellipse at ... , ... + @if $length_arg1 == 4 { + // [ | ] ellipse at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 5, $length_arg1)); + @if not $position { + // [ | ] ellipse at ... , ... + @return null; + } + // [ | ] ellipse at , ... + $shape: $arg1_3; + $size: $arg1_1 $arg1_2; + //$position: $position; + } + } @else { + // [ | ] ... , ... + @return null; + } + } + } @else { + // ... , ... + @return null; + } + } + } @else if $arg1_1 == ellipse { + // ellipse ... , ... + @if $length_arg1 == 1 { + // ellipse , ... + $shape: $arg1_1; + $size: farthest-corner; + $position: ('x': center, 'y': center); + } @else { + $arg1_2: unquote(nth($arg1, 2)); + @if $arg1_2 == at { + // ellipse at ... , ... + @if $length_arg1 == 2 { + // ellipse at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 3, $length_arg1)); + @if not $position { + // ellipse at ... , ... + @return null; + } + // ellipse at , ... + $shape: $arg1_1; + $size: farthest-corner; + //$position: $position; + } @else if is-length($arg1_2) or is-percentage($arg1_2) { + // ellipse [ | ] ... , ... + @if $length_arg1 >= 3 { + $arg1_3: unquote(nth($arg1, 3)); + @if is-length($arg1_3) or is-percentage($arg1_3) { + // ellipse [ | ] [ | ] ... , ... + @if $length_arg1 == 3 { + // ellipse [ | ] [ | ] , ... + $shape: $arg1_1; + $size: $arg1_2 $arg1_3; + $position: ('x': center, 'y': center); + } @else { + @if nth($arg1, 4) != at { + // ellipse [ | ] [ | ] ... , ... + @return null; + } + // ellipse [ | ] [ | ] at ... , ... + @if $length_arg1 == 4 { + // ellipse [ | ] [ | ] at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 5, $length_arg1)); + @if not $position { + // ellipse [ | ] [ | ] at ... , ... + @return null; + } + // ellipse [ | ] [ | ] at , ... + $shape: $arg1_1; + $size: $arg1_2 $arg1_3; + //$position: $position; + } + } @else { + // ellipse [ | ] ... , ... + @return null; + } + } @else { + // ellipse [ | ] , ... + @return null; + } + } @else if is-extent-keyword($arg1_2) { + // ellipse ... , ... + @if $length_arg1 == 2 { + // ellipse , ... + $shape: $arg1_1; + $size: $arg1_2; + $position: ('x': center, 'y': center); + } @else { + @if nth($arg1, 3) != at { + // ellipse ... , ... + @return null; + } + // ellipse at ... , ... + @if $length_arg1 == 3 { + // ellipse at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 4, $length_arg1)); + @if not $position { + // ellipse at ... , ... + @return null; + } + // ellipse at , ... + $shape: $arg1_1; + $size: $arg1_2; + //$position: $position; + } + } @else { + // ellipse ... , ... + @return null; + } + } + } @else if is-percentage($arg1_1) { + // ... , ... + @if $length_arg1 >= 2 { + $arg1_2: unquote(nth($arg1, 2)); + @if is-length($arg1_2) or is-percentage($arg1_2) { + // [ | ] ... , ... + @if $length_arg1 == 2 { + // [ | ] , ... + $shape: ellipse; + $size: $arg1_1 $arg1_2; + $position: ('x': center, 'y': center); + } @else { + $arg1_3: unquote(nth($arg1, 3)); + @if $arg1_3 == at { + // [ | ] at ... , ... + @if $length_arg1 == 3 { + // [ | ] at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 4, $length_arg1)); + @if not $position { + // [ | ] at ... , ... + @return null; + } + // [ | ] at , ... + $shape: ellipse; + $size: $arg1_1 $arg1_2; + //$position: $position; + } @else if $arg1_3 == ellipse { + // [ | ] ellipse ... , ... + @if $length_arg1 == 3 { + // [ | ] ellipse , ... + $shape: $arg1_3; + $size: $arg1_1 $arg1_2; + $position: ('x': center, 'y': center); + } @else { + @if nth($arg1, 4) != at { + // [ | ] ellipse ... , ... + @return null; + } + // [ | ] ellipse at ... , ... + @if $length_arg1 == 4 { + // [ | ] ellipse at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 5, $length_arg1)); + @if not $position { + // [ | ellipse at ... , ... + @return null; + } + // [ | ] ellipse at , ... + $shape: $arg1_3; + $size: $arg1_1 $arg1_2; + //$position: $position; + } + } @else { + // [ | ] ... , ... + @return null; + } + } + } @else { + // ... , ... + @return null; + } + } @else { + // , ... + @return null; + } + } @else if is-extent-keyword($arg1_1) { + // ... , ... + @if $length_arg1 == 1 { + // , ... + $shape: ellipse; + $size: $arg1_1; + $position: ('x': center, 'y': center); + } @else { + $arg1_2: unquote(nth($arg1, 2)); + @if $arg1_2 == at { + // at ... , ... + @if $length_arg1 == 2 { + // at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 3, $length_arg1)); + @if not $position { + // at ... , ... + @return null; + } + // at , ... + $shape: ellipse; + $size: $arg1_1; + //$position: $position; + } @else if $arg1_2 == circle or $arg1_2 == ellipse { + // [circle | ellipse] ... , ... + @if $length_arg1 == 2 { + // [circle | ellipse] , ... + $shape: $arg1_2; + $size: $arg1_1; + $position: ('x': center, 'y': center); + } @else { + @if nth($arg1, 3) != at { + // [circle | ellipse] ... , ... + @return null; + } + // [circle | ellipse] at ... , ... + @if $length_arg1 == 3 { + // [circle | ellipse] at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 4, $length_arg1)); + @if not $position { + // [circle | ellipse] at ... , ... + @return null; + } + // [circle | ellipse] at , ... + $shape: $arg1_2; + $size: $arg1_1; + //$position: $position; + } + } @else { + // ... , ... + @return null; + } + } + } @else if $arg1_1 == at { + // at ... , ... + @if $length_arg1 == 1 { + // at , ... + @return null; + } + $position: __parse-background-position(slice-list($arg1, 2, $length_arg1)); + @if not $position { + // at ... , ... + @return null; + } + // at , ... + $shape: ellipse; + $size: farthest-corner; + //$position: $position; + } @else { + // ... , ... + @return null; + } + } + @if length($radial-gradient) >=2 { + @each $color-stop in slice-list($radial-gradient, 2) { + $color-stop: __parse-color-stop($color-stop); + @if not $color-stop { + // Incorrect color-stop + @return null; + } + $color-stops: append($color-stops, $color-stop, comma); + } + } + @if length($color-stops) == 1 { + $color-stops: append($color-stops, ( + 'color': transparent, + 'position': null + ), comma); + } + @return ( + 'shape': $shape, + 'size': $size, + 'position': $position, + 'color-stops': $color-stops + ); +} \ No newline at end of file diff --git a/functions/_parse-radial-gradients.scss b/functions/_parse-radial-gradients.scss new file mode 100644 index 0000000..94dc174 --- /dev/null +++ b/functions/_parse-radial-gradients.scss @@ -0,0 +1,23 @@ +@import "base-functions"; +@import "parse-radial-gradient"; + +@function __parse-radial-gradients($radial-gradients...) { + $radial-gradients: unwrap-list($radial-gradients, true); + @if length($radial-gradients) == 0 { + // + @return null; + } + @if is-space-separated(nth($radial-gradients, 1)) { + $radial-gradients: ($radial-gradients,); + } + $parsed-radial-gradients: (); + @each $radial-gradient in $radial-gradients { + $parsed-radial-gradient: __parse-radial-gradient($radial-gradient); + @if not $parsed-radial-gradient { + // Incorrect radial-gradient + @return null; + } + $parsed-radial-gradients: append($parsed-radial-gradients, $parsed-radial-gradient, comma); + } + @return $parsed-radial-gradients; +} \ No newline at end of file diff --git a/functions/_parse-transition.scss b/functions/_parse-transition.scss new file mode 100644 index 0000000..9b28985 --- /dev/null +++ b/functions/_parse-transition.scss @@ -0,0 +1,56 @@ +@import "base-functions"; + +// Based on Compass transition-map function +// https://github.com/Compass/compass/blob/stable/core/stylesheets/compass/css3/_transition.scss#L60-L78 +@function __parse-transition($transition) { + $property: null; + $duration: null; + $function: null; + $delay: null; + @if is-comma-separated($transition) { + // + @return null; + } + $length: length($transition); + @if not ($length >= 1 and $length <= 4) { + // Incorrect arguments count + @return null; + } + @each $item in $transition { + @if is-time($item) { + @if $duration == null { + $duration: $item; + } @else { + @if $delay == null { + $delay: $item; + } @else { + // Third