Created
August 5, 2014 11:37
-
-
Save KittyGiraudel/cabc6a779ccf15eee0d6 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ---- | |
| // Sass (v3.3.14) | |
| // Compass (v1.0.0.rc.1) | |
| // ---- | |
| // Global direction | |
| // @type String | |
| $global-direction: "ltr" !default; | |
| // Global configuration | |
| // @requires direction-configuration | |
| // @type Map | |
| $direction-configuration: direction-configuration(); | |
| // Returns the opposite value of `$value` | |
| // @param {*} $value | |
| // @return {*} | |
| @function opposite-value($value) { | |
| @return if(index(left right, $value), if($value == left, right, left), $value); | |
| } | |
| @function define-value($value) { | |
| $global-direction: map-get($direction-configuration, "direction"); | |
| @if $value == "start" { | |
| @return if($global-direction == "ltr", left, right); | |
| } | |
| @else if $value == "end" { | |
| @return if($global-direction == "rtl", right, left); | |
| } | |
| @return $value; | |
| } | |
| // Set up the global configuration | |
| // @requires $global-direction | |
| // @requires opposite-value | |
| // @return Map | |
| @function direction-configuration() { | |
| $global-side: if($global-direction == "rtl", right, left); | |
| $opposite-global-side: opposite-value($global-side); | |
| @return ( | |
| direction: $global-direction, | |
| side: $global-side, | |
| opposite-side: $opposite-global-side | |
| ); | |
| } | |
| // Define a directional value | |
| // @requires $direction-configuration | |
| // @param {*} $value | |
| // @return {*} | |
| @function directional-side($value) { | |
| $global-side: map-get($direction-configuration, "side"); | |
| @return if($global-side == $value, $value, opposite-value($value)); | |
| } | |
| // Output text align | |
| // @param {String} $value | |
| @mixin text-align($value) { | |
| @if index(left right, $value) { | |
| text-align: directional-side($value); | |
| @warn "Use native `text-align: start` or `text-align: end` native CSS declarations."; | |
| } | |
| @else { | |
| text-align: $value; | |
| } | |
| } | |
| // Output float | |
| // @param {String} $value | |
| @mixin float($value) { | |
| float: directional-side(define-value($value)); | |
| } | |
| // Output clear | |
| // @param {String} $value | |
| @mixin clear($value) { | |
| @if index(left right, $value) { | |
| clear: directional-side($value); | |
| } | |
| @else if index(start end, $value) { | |
| clear: if($global-direction == "ltr" and $value == "start", left, right); | |
| } | |
| @else { | |
| clear: $value; | |
| } | |
| } | |
| // Output left/right border | |
| // @requires $direction-configuration | |
| // @param {List} $value | |
| @mixin border-start($value) { | |
| $global-side: map-get($direction-configuration, "side"); | |
| border-#{$global-side}: $value; | |
| } | |
| // Output left/right border | |
| // @requires $direction-configuration | |
| // @param {List} $value | |
| @mixin border-end($value) { | |
| $opposite-global-side: map-get($direction-configuration, "opposite-side"); | |
| border-#{$opposite-global-side}: $value; | |
| } | |
| // Output left/right padding | |
| // @requires $direction-configuration | |
| // @param {Number} $value | |
| @mixin padding-start($value) { | |
| $global-side: map-get($direction-configuration, "side"); | |
| padding-#{$global-side}: $value; | |
| } | |
| // Output left/right padding | |
| // @requires $direction-configuration | |
| // @param {Number} $value | |
| @mixin padding-end($value) { | |
| $opposite-global-side: map-get($direction-configuration, "opposite-side"); | |
| padding-#{$opposite-global-side}: $value; | |
| } | |
| // Output left/right margin | |
| // @requires $direction-configuration | |
| // @param {Number} $value | |
| @mixin margin-start($value) { | |
| $global-side: map-get($direction-configuration, "side"); | |
| margin-#{$global-side}: $value; | |
| } | |
| // Output left/right margin | |
| // @requires $direction-configuration | |
| // @param {Number} $value | |
| @mixin margin-end($value) { | |
| $opposite-global-side: map-get($direction-configuration, "opposite-side"); | |
| margin-#{$opposite-global-side}: $value; | |
| } | |
| // Output direction | |
| // @requires $global-direction | |
| @mixin direction() { | |
| direction: unquote($global-direction); | |
| } | |
| // Direction content | |
| // @requires $direction-configuration | |
| // @requires $global-direction | |
| // @access private | |
| // @param {String} $direction | |
| @mixin directional-content($direction) { | |
| $tmp: $global-direction; | |
| $global-direction: $direction !global; | |
| $direction-configuration: direction-configuration() !global; | |
| @content; | |
| $global-direction: $tmp !global; | |
| $direction-configuration: direction-configuration() !global; | |
| } | |
| // Local left-to-right | |
| // @requires {mixin} directional-content | |
| @mixin ltr { | |
| @include directional-content(ltr) { @content; } | |
| } | |
| // Local right-to-left | |
| // @requires {mixin} directional-content | |
| @mixin rtl { | |
| @include directional-content(rtl) { @content; } | |
| } | |
| .test-ltr { | |
| @include ltr { | |
| @include direction; | |
| @include clear(start); | |
| @include text-align(start); | |
| @include float(start); | |
| @include border-start(1px solid red); | |
| @include border-end(1px solid blue); | |
| @include padding-start(1em); | |
| @include padding-end(2em); | |
| @include margin-start(1em); | |
| @include margin-end(2em); | |
| } | |
| } | |
| .test-rtl { | |
| @include rtl { | |
| @include direction; | |
| @include clear(start); | |
| @include text-align(start); | |
| @include float(start); | |
| @include border-start(1px solid red); | |
| @include border-end(1px solid blue); | |
| @include padding-start(1em); | |
| @include padding-end(2em); | |
| @include margin-start(1em); | |
| @include margin-end(2em); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .test-ltr { | |
| direction: ltr; | |
| clear: left; | |
| text-align: start; | |
| float: left; | |
| border-left: 1px solid red; | |
| border-right: 1px solid blue; | |
| padding-left: 1em; | |
| padding-right: 2em; | |
| margin-left: 1em; | |
| margin-right: 2em; | |
| } | |
| .test-rtl { | |
| direction: rtl; | |
| clear: right; | |
| text-align: start; | |
| float: right; | |
| border-right: 1px solid red; | |
| border-left: 1px solid blue; | |
| padding-right: 1em; | |
| padding-left: 2em; | |
| margin-right: 1em; | |
| margin-left: 2em; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment