|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- // Sass Utilities
- // ==============
- // - Susy Error Output Override [variable]
- // - Susy Error [function]
-
-
-
- // Susy Error Output Override
- // --------------------------
- /// Turn off error output for testing
- /// @group x-utility
- /// @access private
- $_susy-error-output-override: false !default;
-
-
-
- // Susy Error
- // ----------
- /// Optionally return error messages without failing,
- /// as a way to test error cases
- ///
- /// @group x-utility
- /// @access private
- ///
- /// @param {string} $message -
- /// A useful error message, explaining the problem
- /// @param {string} $source -
- /// The original source of the error for debugging
- /// @param {bool} $override [$_susy-error-output-override] -
- /// Optionally return the error rather than failing
- /// @return {string} -
- /// Combined error with source and message
- /// @throws When `$override == true`
- @function _susy-error(
- $message,
- $source,
- $override: $_susy-error-output-override
- ) {
- @if $override {
- @return 'ERROR [#{$source}] #{$message}';
- }
-
- @error '[#{$source}] #{$message}';
- }
-
-
- // Su Is Comparable
- // ----------------
- /// Check that the units in a grid are comparable
- ///
- /// @group _validation
- /// @access private
- ///
- /// @param {numbers} $lengths… -
- /// Arglist of all the number values to compare
- /// (columns, gutters, span, etc)
- ///
- /// @return {'fluid' | 'static' | false} -
- /// The type of span (fluid or static) when units match,
- /// or `false` for mismatched units
- @function _su-is-comparable(
- $lengths...
- ) {
- $first: nth($lengths, 1);
-
- @if (length($lengths) == 1) {
- @return if(unitless($first), 'fluid', 'static');
- }
-
- @for $i from 2 through length($lengths) {
- $comp: nth($lengths, $i);
-
- $fail: not comparable($first, $comp);
- $fail: $fail or (unitless($first) and not unitless($comp));
- $fail: $fail or (unitless($comp) and not unitless($first));
-
- @if $fail {
- @return false;
- }
- }
-
- @return if(unitless($first), 'fluid', 'static');
- }
-
-
- // Su Map Add Units
- // ----------------
- /// The calc features use a map of units and values
- /// to compile the proper algorythm.
- /// This function adds a new value to any comparable existing unit/value,
- /// or adds a new unit/value pair to the map
- ///
- /// @group x-utility
- /// @access private
- ///
- /// @param {map} $map -
- /// A map of unit/value pairs, e.g. ('px': 120px)
- /// @param {length} $value -
- /// A new length to be added to the map
- /// @return {map} -
- /// The updated map, with new value added
- ///
- /// @example scss -
- /// $map: (0px: 120px);
- /// $map: _su-map-add-units($map, 1in); // add a comparable unit
- /// $map: _su-map-add-units($map, 3vw); // add a new unit
- ///
- /// @each $units, $value in $map {
- /// /* #{$units}: #{$value} */
- /// }
- @function _su-map-add-units(
- $map,
- $value
- ) {
- $unit: $value * 0;
- $has: map-get($map, $unit) or 0;
-
- @if ($has == 0) {
- @each $try, $could in $map {
- $match: comparable($try, $value);
- $unit: if($match, $try, $unit);
- $has: if($match, $could, $has);
- }
- }
-
- @return map-merge($map, ($unit: $has + $value));
- }
-
-
- // Susy Flatten
- // ------------
- /// Flatten a multidimensional list
- ///
- /// @group x-utility
- /// @access private
- ///
- /// @param {list} $list -
- /// The list to be flattened
- /// @return {list} -
- /// The flattened list
- ///
- /// @example scss -
- /// $list: 120px (30em 30em) 120px;
- /// /* #{_susy-flatten($list)} */
- @function _susy-flatten(
- $list
- ) {
- $flat: ();
-
- // Don't iterate over maps
- @if (type-of($list) == 'map') {
- @return $list;
- }
-
- // Iterate over lists (or single items)
- @each $item in $list {
- @if (type-of($item) == 'list') {
- $item: _susy-flatten($item);
- $flat: join($flat, $item);
- } @else {
- $flat: append($flat, $item);
- }
- }
-
- // Return flattened list
- @return $flat;
- }
|