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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
@use 'sass:list';
@use 'sass:map';
@use 'sass:math';
@use 'sass:meta';
@use 'sass:string';
@use 'metadata';
$metadata: metadata.$metadata !default;
$directory: null !default;
$family: null !default;
$display: null !default;
$formats: null !default;
$subsets: null !default;
$weights: null !default;
$styles: null !default;
$axes: null !default;
// Deprecated
$displayVar: null !default;
@mixin generator(
$metadata: $metadata,
$directory: $directory,
$family: $family,
$display: $display,
$formats: $formats,
$subsets: $subsets,
$weights: $weights,
$styles: $styles,
$axes: $axes,
// Deprecated
$displayVar: $displayVar
) {
@warn "Importing mixins via the fontsource package is deprecated and will be removed in the next major release. Please use the @fontsource-utils/scss package instead.";
@if $displayVar != null {
@warn "$displayVar is deprecated due to the limitation of using css variables in @font-face (https://github.com/fontsource/fontsource/issues/726).";
}
$isVariable: map.get($metadata, axes) != null;
$directory: if(
$directory,
$directory,
'~@fontsource#{if($isVariable, '-variable', '')}/#{map.get($metadata, id)}/files'
);
$family: if($family, $family, map.get($metadata, family) + if($isVariable, ' Variable', ''));
$display: if($display, $display, swap);
$formats: if(not $formats or $formats == all, if($isVariable, woff2, (woff2, woff)), $formats);
$subsets: if(
$subsets,
if($subsets == all, map.get($metadata, subsets), $subsets),
map.get($metadata, subsets)
);
$weights: if(
$weights,
if($weights == all, map.get($metadata, weights), $weights),
map.get($metadata, defaults, weight)
);
$styles: if(
$styles,
if($styles == all, map.get($metadata, styles), $styles),
map.get($metadata, defaults, style)
);
$axes: if(
$axes,
if($axes == all, full, $axes),
if($isVariable, if(map.has-key($metadata, axes, wght), wght, full), null)
);
@each $subset in $subsets {
@each $unicodeSubset, $unicodeRange in map.get($metadata, unicode) {
// If condition is true, generate faces for the current subset
@if (
// If there is no unicode information for the font or
($unicodeSubset == null) or
// If the subset match a unicode subset or
($subset == $unicodeSubset) or
(
// If $unicodeSubset is a numeric unicode subset
// and current subset exists in the list of font subsets but does not match any unicode subset
// then generate faces for this numeric unicode subset as it is representing part of the current subset
list.index(map.get($metadata, subsets), $subset) and not
map.has-key($metadata, unicode, $subset) and not
list.index(map.get($metadata, subsets), $unicodeSubset)
)
) {
@each $weight in if($axes, null, $weights) {
@each $axis in $axes {
@each $style in $styles {
$variant: '#{map.get($metadata, id)}-#{if($unicodeSubset, $unicodeSubset, $subset)}-#{if($axis, $axis, $weight)}-#{$style}';
$src: ();
@each $format in $formats {
$src: append(
$src,
url('#{$directory}/#{$variant}.#{$format}')
format('#{$format}#{if($axis, '-variations', '')}'),
comma
);
}
@content ((
metadata: $metadata,
directory: $directory,
family: $family,
display: $display,
formats: $formats,
subsets: $subsets,
weights: $weights,
styles: $styles,
axes: $axes,
variant: $variant,
subset: $subset,
unicodeSubset: $unicodeSubset,
unicodeRange: $unicodeRange,
weight: $weight,
axis: $axis,
style: $style,
font-family: string.quote($family),
font-style: if(
(($axis == full) or ($axis == slnt)) and map.has-key($metadata, axes, slnt),
oblique map.get($metadata, axes, slnt, min) + deg map.get($metadata, axes, slnt, max) + deg,
$style
),
font-display: $display,
font-weight: if(
(($axis == full) or ($axis == wght)) and map.has-key($metadata, axes, wght),
map.get($metadata, axes, wght, min) map.get($metadata, axes, wght, max),
$weight
),
font-stretch: if(
(($axis == full) or ($axis == wdth)) and map.has-key($metadata, axes, wdth),
'#{map.get($metadata, axes, wdth, min)}% #{map.get($metadata, axes, wdth, max)}%',
null
),
src: $src,
unicode-range: $unicodeRange,
));
}
}
}
}
}
}
}
@mixin faces(
$metadata: $metadata,
$directory: $directory,
$family: $family,
$display: $display,
$formats: $formats,
$subsets: $subsets,
$weights: $weights,
$styles: $styles,
$axes: $axes,
// Deprecated
$displayVar: $displayVar
) {
@include generator(
$metadata: $metadata,
$directory: $directory,
$family: $family,
$display: $display,
$formats: $formats,
$subsets: $subsets,
$weights: $weights,
$styles: $styles,
$axes: $axes,
$displayVar: $displayVar
)
using ($props) {
/* #{map.get($props, variant)} */
@font-face {
font-family: map.get($props, font-family);
font-style: map.get($props, font-style);
font-display: map.get($props, font-display);
font-weight: map.get($props, font-weight);
font-stretch: map.get($props, font-stretch);
unicode-range: map.get($props, unicode-range);
src: map.get($props, src);
}
}
}
|