//  -----------------------------------
//  Core - Utilities | Typography - Mixins
//  -----------------------------------


// @addepar-font-face()
//
// Creates Addepar specific font face declaration, based on Compass font-face mixin
// Assumes all font types have the same base file name (Addepar standard)
// For best results, declare type in this order: woff2, woff, otf/ttf, svg, eot
//
// ### Example Usage:
//
//   `@include addepar-font-face('Univers-Next',
//     '/fonts/UniversNextW01Regular', ('woff2', 'ttf'), $font-normal);`
//
// ### Parameters:
//
// * $name = Font name
// * $font-file = File name
// * $file-types = Array of different font file types
// * $weight = 400 - Font weight
// * $style = normal - Font style
// * $post-fix = false - Add a custom string to the end of the font file, usually used for cross browser fixes
//
// ### Example Output:
//   ```
//   @font-face {
//     font-family: "Univers-Next";
//     src: url("/ice-box/fonts/UniversNextW01Regular.woff") format("woff"), url("/ice-box/fonts/UniversNextW01Regular.ttf") format("ttf");
//     font-weight: 400;
//     font-style: normal;
//   }
//   ```
//
// Styleguide: Style Toolbox - Mixins - Typography - @addepar-font-face()

@mixin addepar-font-face($name, $font-file, $file-types, $weight: 400, $style: normal, $post-fix: false) {
  $font-files: null; // concatenated string of font declarations
  $format: null; // used when type format is not the same as its extension
  $pf: null; // used for optional post-fix, usually for svg
  @if $post-fix {
    $pf: '?#{$post-fix}';
  }

  @font-face {
    font-family: $name;
    @each $type in $file-types {
      // Need to add special rules for IE for eot files
      @if $type == 'eot' {
        src: url('#{$font-file}.#{$type}#{$pf}');
        $font-files: url('#{$font-file}.#{$type}?#iefix#{$pf}') format('embedded-opentype'), $font-files;
      } @else {
        // ttf and otf have to be written out as truetype/opentype
        // for the format (but still stay ttf/otf for the file extentions)
        @if $type == 'ttf' { $format: 'truetype'; }
        @if $type == 'otf' { $format: 'opentype'; }
        @else { $format: $type; }
        $font-files: $font-files, url('#{$font-file}.#{$type}#{$pf}') format($format);
      }
    }
    src: $font-files;
    font-weight: $weight;
    font-style: $style;
  }
}

// @font-settings()
//
// Addepar specific font rendering settings
//
// Example Usage:
//
//   ```
//   body {
//     @include @font-settings();
//   }
//   ```
//
// Parameters:
//
// * none
//
// Example Output:
//   ```
//   * {
//     text-rendering: optimizeLegibility;
//
//     font-smoothing: antialiased;
//     -webkit-font-smoothing: antialiased;
//     -moz-osx-font-smoothing: grayscale;
//   }
//   ```
//
// Styleguide: Style Toolbox - Mixins - Typography - @font-settings()

@mixin font-settings() {
  * {
    text-rendering: optimizeLegibility;

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

// @ellipsis-overflow()
//
// Standard setup to make text in an element ellipsize.
// Element must have some kind of width applied.
//
// Example Usage:
//
//   ```
//   .element {
//     @include @ellipsis-overflow();
//   }
//   ```
//
// Parameters:
//
// * none
//
// Example Output:
//   ```
//   .element {
//     display: block;
//     overflow: hidden;
//     white-space: nowrap;
//     word-wrap: break-word;
//     text-overflow: ellipsis;
//   }
//   ```
//
// Styleguide: Style Toolbox - Mixins - Typography - @ellipsis-overflow()

@mixin ellipsis-overflow() {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  word-wrap: break-word;
  text-overflow: ellipsis;
}
