1// Uses the Font Loading API to load/add fonts. 2// When all fonts are loaded it will apply the 'fonts-loaded' class to the document to apply the font styles. 3 4activateWebFontStylesheet( loadFonts ); 5 6/** 7 * Apply the non-render-blocking Google Fonts stylesheet only after it has downloaded. 8 * Its initial print media keeps it out of the render-blocking critical path. 9 * 10 * @param {Function} onReady Continue loading fonts after the stylesheet is active. 11 */ 12function activateWebFontStylesheet( onReady ) { 13 let stylesheet = document.getElementById( 'achilles-web-fonts-css' ); 14 15 if ( ! stylesheet ) { 16 onReady(); 17 return; 18 } 19 20 let activate = function() { 21 stylesheet.media = 'all'; 22 globalThis.requestAnimationFrame( onReady ); 23 }; 24 25 if ( stylesheet.sheet ) { 26 activate(); 27 return; 28 } 29 30 stylesheet.addEventListener( 'load', activate, { once: true }); 31} 32 33function loadFonts() { 34 35 loadFontsArr.forEach( async function( font ) { 36 if ( 'google-font' === font.type ) { 37 await document.fonts.load( '400 1em ' + font.name ); 38 await document.fonts.load( '700 1em ' + font.name ); 39 } else { 40 let fontWeight = font.weight ? font.weight : 'normal'; 41 let newFont = new FontFace( font.name, font.src, { display: 'swap', weight: fontWeight}); 42 43 await newFont.load(); 44 document.fonts.add( newFont ); 45 } 46 }); 47 48 // When fonts are loaded and ready apply the Font Styles. 49 document.fonts.ready.then( function() { 50 document.documentElement.classList.add( 'fonts-loaded' ); 51 }); 52}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.