1- const _ = require ( 'lodash' ) ;
21const { toPx } = require ( './utils' ) ;
32const Inter = require ( '../inter.json' ) ;
43
5- const mapObject = ( obj , cb ) => _ . fromPairs ( _ . toPairs ( obj ) . map ( val => cb ( ...val ) ) ) ;
6- const filterObject = ( obj , cb ) => _ . fromPairs ( _ . toPairs ( obj ) . filter ( val => cb ( ...val ) ) ) ;
4+ const isPlainObject = val => ! ! val && typeof val === 'object' && val . constructor === Object ;
5+ const isArrayLike = obj => obj != null && typeof obj [ Symbol . iterator ] === 'function' ;
6+ const isBoolean = val => typeof val === 'boolean' ;
7+ const isString = val => typeof val === 'string' ;
8+ const entries = obj => Object . keys ( obj ) . map ( key => [ key , obj [ key ] ] ) ;
9+ const fromEntries = iterable =>
10+ [ ...iterable ] . reduce ( ( obj , [ key , val ] ) => {
11+ obj [ key ] = val ;
12+ return obj ;
13+ } , { } ) ;
14+ const mapObject = ( obj , cb ) => fromEntries ( ( Array . isArray ( obj ) ? obj : entries ( obj ) ) . map ( val => cb ( ...val ) ) ) ;
15+ const filterObject = ( obj , cb ) => fromEntries ( ( Array . isArray ( obj ) ? obj : entries ( obj ) ) . filter ( val => cb ( ...val ) ) ) ;
16+ const defaults = ( obj , ...defs ) => Object . assign ( { } , obj , ...defs . reverse ( ) , obj ) ;
717const round = ( num , prec = 3 ) => parseFloat ( num . toFixed ( prec ) ) ;
818const unquote = str => str . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' ) . trim ( ) ;
919const tracking = ( fontSize , a , b , c ) => a + b * Math . pow ( Math . E , c * fontSize ) ;
1020
1121const normalizeEntry = ( key , value ) => {
12- value = _ . isBoolean ( value ) ? '' + 1 * value : '' + value ;
22+ value = isBoolean ( value ) ? '' + 1 * value : '' + value ;
1323 value = value !== '1' && value !== 'undefined' ? value : '1' ;
1424
1525 return [ unquote ( key ) , value ] ;
1626} ;
1727
1828const generateFeatures = ( features , available ) => {
19- if ( _ . isPlainObject ( features ) ) {
29+ if ( isPlainObject ( features ) ) {
2030 features = mapObject ( features , ( key , value = '1' ) => normalizeEntry ( key , value ) ) ;
2131 } else {
22- if ( _ . isString ( features ) ) {
23- features = _ . fromPairs ( features . split ( ',' ) . map ( f => f . trim ( ) . split ( ' ' ) ) ) ;
32+ if ( isString ( features ) ) {
33+ features = fromEntries ( features . split ( ',' ) . map ( f => f . trim ( ) . split ( ' ' ) ) ) ;
2434 }
2535
26- features = _ . fromPairs (
36+ features = fromEntries (
2737 features . map ( feature => {
2838 let key , value ;
2939
30- if ( _ . isString ( feature ) ) {
40+ if ( isString ( feature ) ) {
3141 [ key , value = '1' ] = feature . replace ( / \s \s + / g, ' ' ) . split ( ' ' , 2 ) ;
32- } else if ( _ . isArrayLike ( feature ) ) {
42+ } else if ( isArrayLike ( feature ) ) {
3343 [ key , value = '1' ] = feature ;
34- } else if ( _ . isPlainObject ( feature ) ) {
35- [ key , value = '1' ] = _ . toPairs ( feature ) [ 0 ] ;
44+ } else if ( isPlainObject ( feature ) ) {
45+ [ key , value = '1' ] = entries ( feature ) [ 0 ] ;
3646 }
3747
3848 return normalizeEntry ( key , value ) ;
@@ -42,7 +52,7 @@ const generateFeatures = (features, available) => {
4252
4353 features = filterObject ( features , key => available . includes ( key ) ) ;
4454
45- return _ . toPairs ( features )
55+ return entries ( features )
4656 . map ( ( [ key , value ] ) => `"${ key } " ${ value } ` )
4757 . filter ( val => ! ! val )
4858 . sort ( )
@@ -54,7 +64,7 @@ module.exports = function (options = {}) {
5464 return ( { addBase, addUtilities, variants, e, theme } ) => {
5565 const { availableFeatures, utilities, base } = Inter ;
5666
57- const defaultConfig = _ . defaults ( options , {
67+ const defaultConfig = defaults ( options , {
5868 a : - 0.0223 ,
5969 b : 0.185 ,
6070 c : - 0.1745 ,
@@ -69,10 +79,7 @@ module.exports = function (options = {}) {
6979 const fontSizeVariants = variants ( 'fontSize' , defaultFontSizeVariants ) ;
7080 const fontFeaturesTheme = theme ( 'interFontFeatures' , defaultFontFeaturesTheme ) ;
7181
72- const fontFeatures = {
73- ...defaultFontFeaturesTheme ,
74- ...fontFeaturesTheme
75- } ;
82+ const fontFeatures = defaults ( fontFeaturesTheme , defaultFontFeaturesTheme ) ;
7683 const baseStyles = {
7784 ...( defaultConfig . importFontFace ? base : { } )
7885 } ;
@@ -88,40 +95,37 @@ module.exports = function (options = {}) {
8895 } ;
8996
9097 const fontFeatureStyles = value => {
91- return {
92- fontFeatureSettings : _ . isArray ( value ) ? value . join ( ', ' ) : value
93- } ;
98+ return value . length ? { fontFeatureSettings : Array . isArray ( value ) ? value . join ( ', ' ) : value } : null ;
9499 } ;
95100
96- const fontFeatureUtilities = _ . fromPairs (
97- _ . chain ( fontFeatures )
98- . map ( ( value , modifier ) => {
99- const features = generateFeatures ( value , availableFeatures ) ;
100- if ( ! features . length ) return [ null ] ;
101-
102- return [
103- `.font-inter .${ e ( `font-feature-${ modifier } ` ) } , .font-inter.${ e ( `font-feature-${ modifier } ` ) } ` ,
104- {
105- ...fontFeatureStyles ( features )
106- }
107- ] ;
108- } )
109- . filter ( ( [ key ] ) => key !== null )
110- . value ( )
111- ) ;
112-
113- const fontSizeUtilities = _ . fromPairs (
114- _ . map ( fontSizeTheme , ( value , modifier ) => {
115- const { a, b, c } = defaultConfig ;
101+ const fontFeatureUtilities = {
102+ ...{
103+ '.font-inter .font-feature-normal, .font-inter.font-feature-normal' : {
104+ ...fontFeatureStyles ( 'normal' )
105+ }
106+ } ,
107+ ...mapObject ( fontFeatures , ( modifier , value ) => {
108+ const features = generateFeatures ( value , availableFeatures ) ;
116109
117110 return [
118- `.font-inter .${ e ( `text- ${ modifier } ` ) } , .font-inter.${ e ( `text -${ modifier } ` ) } ` ,
111+ `.font-inter .${ e ( `font-feature- ${ modifier } ` ) } ,.font-inter.${ e ( `font-feature -${ modifier } ` ) } ` ,
119112 {
120- ...fontSizeStyles ( value , { a , b , c } )
113+ ...fontFeatureStyles ( features )
121114 }
122115 ] ;
123116 } )
124- ) ;
117+ } ;
118+
119+ const fontSizeUtilities = mapObject ( fontSizeTheme , ( modifier , value ) => {
120+ const { a, b, c } = defaultConfig ;
121+
122+ return [
123+ `.font-inter .${ e ( `text-${ modifier } ` ) } , .font-inter.${ e ( `text-${ modifier } ` ) } ` ,
124+ {
125+ ...fontSizeStyles ( value , { a, b, c } )
126+ }
127+ ] ;
128+ } ) ;
125129
126130 // Add @font -face if importFontFace: true
127131 // see https://rsms.me/inter/inter.css
0 commit comments