@charset "UTF-8"; /// Generates an `@font-face` declaration. You can choose the specific file /// formats you need to output; the mixin supports `eot`, `ttf`, `svg`, `woff2` /// and `woff`. /// /// @argument {string} $font-family /// /// @argument {string} $file-path /// /// @argument {string | list} $file-formats [("ttf", "woff2", "woff")] /// List of the font file formats to include. /// /// @content /// Any additional CSS properties that are included in the `@include` /// directive will be output within the `@font-face` declaration, e.g. you can /// pass in `font-weight`, `font-style` and/or `unicode-range`. /// /// @example scss /// @include font-face( /// "source-sans-pro", /// "fonts/source-sans-pro-regular", /// ("woff2", "woff") /// ) { /// font-style: normal; /// font-weight: 400; /// } /// /// // CSS Output /// @font-face { /// font-family: "source-sans-pro"; /// src: url("fonts/source-sans-pro-regular.woff2") format("woff2"), /// url("fonts/source-sans-pro-regular.woff") format("woff"); /// font-style: normal; /// font-weight: 400; /// } @mixin font-face( $font-family, $file-path, $file-formats, ) { @font-face { font-family: $font-family; src: _font-source-declaration( $font-family, $file-path, $file-formats ); @content; } } /// Builds the `src` list for an `@font-face` declaration. /// /// @link https://goo.gl/Ru1bKP /// /// @argument {string} $font-family /// /// @argument {string} $file-path /// /// @argument {list} $file-formats /// /// @return {list} /// /// @require {function} _contains /// /// @access private @function _font-source-declaration( $font-family, $file-path, $file-formats ) { $src: (); $formats-map: ( eot: "#{$file-path}.eot?#iefix" format("embedded-opentype"), woff2: "#{$file-path}.woff2" format("woff2"), woff: "#{$file-path}.woff" format("woff"), ttf: "#{$file-path}.ttf" format("truetype"), svg: "#{$file-path}.svg##{$font-family}" format("svg"), ); @each $key, $values in $formats-map { @if _contains($file-formats, $key) { $file-path: nth($values, 1); $font-format: nth($values, 2); $src: append($src, font-url($file-path) $font-format, comma); } } @return $src; }