File: _vertical-rhythm.scss

package info (click to toggle)
compass-normalize-plugin 7.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,012 kB
  • sloc: javascript: 151; ruby: 15; makefile: 4; sh: 1
file content (61 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Vertical Rhythm
//
// This is the minimal amount of code needed to create vertical rhythm in our
// CSS. If you are looking for a robust solution, look at the excellent Typey
// library. @see https://github.com/jptaranto/typey

@function normalize-rhythm($value, $relative-to: $base-font-size, $unit: $base-unit) {
  @if unit($value) != px {
    @error "The normalize vertical-rhythm module only supports px inputs. The typey library is better.";
  }
  @if $unit == rem {
    @return ($value / $base-font-size) * 1rem;
  }
  @else if $unit == em {
    @return ($value / $relative-to) * 1em;
  }
  @else { // $unit == px
    @return $value;
  }
}

@mixin normalize-font-size($value, $relative-to: $base-font-size) {
  @if unit($value) != 'px' {
    @error "normalize-font-size() only supports px inputs. The typey library is better.";
  }
  font-size: normalize-rhythm($value, $relative-to);
}

@mixin normalize-rhythm($property, $values, $relative-to: $base-font-size) {
  $value-list: $values;
  $sep: space;
  @if type-of($values) == 'list' {
    $sep: list-separator($values);
  }
  @else {
    $value-list: append((), $values);
  }

  $normalized-values: ();
  @each $value in $value-list {
    @if unitless($value) and $value != 0 {
      $value: $value * normalize-rhythm($base-line-height, $relative-to);
    }
    $normalized-values: append($normalized-values, $value, $sep);
  }
  #{$property}: $normalized-values;
}

@mixin normalize-margin($values, $relative-to: $base-font-size) {
  @include normalize-rhythm(margin, $values, $relative-to);
}

@mixin normalize-line-height($font-size, $min-line-padding: 2px) {
  $lines: ceil($font-size / $base-line-height);
  // If lines are cramped include some extra leading.
  @if ($lines * $base-line-height - $font-size) < ($min-line-padding * 2) {
    $lines: $lines + 1;
  }
  @include normalize-rhythm(line-height, $lines, $font-size);
}