|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @function su-span(
- $span,
- $columns,
- $gutters,
- $spread,
- $container-spread: $spread,
- $location: 1
- ) {
- $span: su-valid-span($span);
- $columns: su-valid-columns($columns);
- $gutters: su-valid-gutters($gutters);
- $spread: su-valid-spread($spread);
-
- @if (type-of($span) == 'number') {
- @if (not unitless($span)) {
- @return $span;
- }
-
- $location: su-valid-location($span, $location, $columns);
- $span: su-slice($span, $columns, $location, $validate: false);
- }
-
- @if _su-needs-calc-output($span, $columns, $gutters, $spread, not 'validate') {
- @return _su-calc-span($span, $columns, $gutters, $spread, $container-spread, not 'validate');
- }
-
- $span-width: _su-sum($span, $gutters, $spread, $validate: false);
-
- @if unitless($span-width) {
- $container-spread: su-valid-spread($container-spread);
- $container: _su-sum($columns, $gutters, $container-spread, $validate: false);
- @return percentage($span-width / $container);
- }
-
- @return $span-width;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @function su-gutter(
- $columns,
- $gutters,
- $container-spread
- ) {
- @if (type-of($gutters) == 'number') {
- @if ($gutters == 0) or (not unitless($gutters)) {
- @return $gutters;
- }
- }
-
- @if _su-needs-calc-output($gutters, $columns, $gutters, -1, not 'validate') {
- @return _su-calc-span($gutters, $columns, $gutters, -1, $container-spread, not 'validate');
- }
-
- $container: _su-sum($columns, $gutters, $container-spread);
- @return percentage($gutters / $container);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @function su-slice(
- $span,
- $columns,
- $location: 1,
- $validate: true
- ) {
- @if $validate {
- $columns: su-valid-columns($columns);
- $location: su-valid-location($span, $location, $columns);
- }
-
- $floor: floor($span);
- $sub-columns: ();
-
- @for $i from $location to ($location + $floor) {
- $sub-columns: append($sub-columns, nth($columns, $i));
- }
-
- @if $floor != $span {
- $remainder: $span - $floor;
- $column: $location + $floor;
- $sub-columns: append($sub-columns, nth($columns, $column) * $remainder);
- }
-
- @return $sub-columns;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @function _su-sum(
- $columns,
- $gutters,
- $spread,
- $validate: true
- ) {
- @if $validate {
- $columns: su-valid-span($columns);
- $gutters: su-valid-gutters($gutters);
- $spread: su-valid-spread($spread);
- }
-
-
- $column-sum: 0;
- @each $column in $columns {
- $column-sum: $column-sum + $column;
- }
-
- $gutter-sum: (ceil(length($columns)) + $spread) * $gutters;
- $total: if(($gutter-sum > 0), $column-sum + $gutter-sum, $column-sum);
-
- @return $total;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @function _su-calc-span(
- $span,
- $columns,
- $gutters,
- $spread,
- $container-spread: $spread,
- $validate: true
- ) {
- @if $validate {
- $span: su-valid-span($span);
- $columns: su-valid-columns($columns);
- $gutters: su-valid-gutters($gutters);
- $spread: su-valid-spread($spread);
- $container-spread: su-valid-spread($container-spread);
- }
-
-
- $span: _su-calc-sum($span, $gutters, $spread, not 'validate');
- $context: _su-calc-sum($columns, $gutters, $container-spread, not 'validate');
-
-
- $fixed-span: map-get($span, 'fixed');
- $fluid-span: map-get($span, 'fluid');
- $fixed-context: map-get($context, 'fixed');
- $fluid-context: map-get($context, 'fluid');
-
- $calc: '#{$fixed-span}';
- $fluid-calc: '(100% - #{$fixed-context})';
-
-
- @if (not $fluid-span) {
- $fluid-calc: null;
- } @else if ($fluid-span != $fluid-context) {
- $fluid-span: '* #{$fluid-span}';
- $fluid-context: if($fluid-context, '/ #{$fluid-context}', '');
- $fluid-calc: '(#{$fluid-calc $fluid-context $fluid-span})';
- }
-
- @if $fluid-calc {
- $calc: if(($calc != ''), '#{$calc} + ', '');
- $calc: '#{$calc + $fluid-calc}';
- }
-
- @return calc(#{unquote($calc)});
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @function _su-calc-sum(
- $columns,
- $gutters,
- $spread,
- $validate: true
- ) {
- @if $validate {
- $columns: su-valid-span($columns);
- $gutters: su-valid-gutters($gutters);
- $spread: su-valid-spread($spread);
- }
-
- $fluid: 0;
- $fixed: ();
- $calc: null;
-
-
- $gutters: $gutters * (length($columns) + $spread);
-
-
- @each $col in append($columns, $gutters) {
- @if unitless($col) {
- $fluid: $fluid + $col;
- } @else {
- $fixed: _su-map-add-units($fixed, $col);
- }
- }
-
-
- @each $unit, $total in $fixed {
- @if ($total != (0 * $total)) {
- $calc: if($calc, '#{$calc} + #{$total}', '#{$total}');
- }
- }
-
-
- @if $calc {
- $calc: if(str-index($calc, '+'), '(#{$calc})', '#{$calc}');
- }
-
-
- $fluid: if(($fluid == 0), null, $fluid);
-
-
-
- $return: (
- 'fixed': $calc,
- 'fluid': $fluid,
- );
-
- @return $return;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @function _su-needs-calc-output(
- $span,
- $columns,
- $gutters,
- $spread,
- $validate: true
- ) {
- @if $validate {
- $span: su-valid-span($span);
- $columns: su-valid-columns($columns);
- $gutters: su-valid-gutters($gutters);
- }
-
- $has-gutter: if((length($span) > 1) or ($spread >= 0), true, false);
- $check: if($has-gutter, append($span, $gutters), $span);
- $safe-span: _su-is-comparable($check...);
-
- @if ($safe-span == 'static') {
- @return false;
- } @else if (not $safe-span) {
- @return true;
- }
-
- $safe-fluid: _su-is-comparable($gutters, $columns...);
-
- @return not $safe-fluid;
- }
|