2d3ca553 |
1 | @charset "UTF-8"; |
2 | |
3 | /// Builds the `src` list for an `@font-face` declaration. |
4 | /// |
5 | /// @link https://goo.gl/Ru1bKP |
6 | /// |
7 | /// @argument {string} $font-family |
8 | /// |
9 | /// @argument {string} $file-path |
10 | /// |
11 | /// @argument {boolean} $asset-pipeline |
12 | /// |
13 | /// @argument {list} $file-formats |
14 | /// |
15 | /// @return {list} |
16 | /// |
17 | /// @require {function} _contains |
18 | /// |
19 | /// @access private |
20 | |
21 | @function _font-source-declaration( |
22 | $font-family, |
23 | $file-path, |
24 | $asset-pipeline, |
25 | $file-formats |
26 | ) { |
27 | $src: (); |
28 | |
29 | $formats-map: ( |
30 | "woff2": "#{$file-path}.woff2" format("woff2"), |
31 | "woff": "#{$file-path}.woff" format("woff"), |
32 | ); |
33 | |
34 | @each $format in $file-formats { |
35 | @if _contains(map-keys($formats-map), $format) { |
36 | $value: map-get($formats-map, $format); |
37 | $file-path: nth($value, 1); |
38 | $font-format: nth($value, 2); |
39 | |
40 | @if $asset-pipeline == true { |
41 | $src: append($src, font-url($file-path) $font-format, comma); |
42 | } @else { |
43 | $src: append($src, url($file-path) $font-format, comma); |
44 | } |
45 | } @else { |
46 | @error "`#{$file-formats}` contains an unsupported font file format. " + |
47 | "Must be `woff` and/or `woff2`."; |
48 | } |
49 | } |
50 | |
51 | @return $src; |
52 | } |