MCPcopy Create free account
hub / github.com/ampproject/amphtml / timeoutFontFaces

Function timeoutFontFaces

src/font-stylesheet-timeout.js:112–135  ·  view source on GitHub ↗

* Sets font faces that haven't been loaded by the time this was called to * `font-display: swap` in supported browsers. * See https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display * for details on behavior. * Swap effectively leads to immediate display of the fallback font wit

(win)

Source from the content-addressed store, hash-verified

110 * @param {!Window} win
111 */
112function timeoutFontFaces(win) {
113 const doc = win.document;
114 // TODO(@cramforce) Switch to .values when FontFaceSet extern supports it.
115 if (!doc.fonts || !doc.fonts['values']) {
116 return;
117 }
118 const it = doc.fonts['values']();
119 let entry;
120 while ((entry = it.next())) {
121 const fontFace = entry.value;
122 if (!fontFace) {
123 return;
124 }
125 if (fontFace.status != 'loading') {
126 continue;
127 }
128 // Not supported or non-default value.
129 // If the publisher specified a non-default, we respect that, of course.
130 if (!('display' in fontFace) || fontFace.display != 'auto') {
131 continue;
132 }
133 fontFace.display = 'swap';
134 }
135}

Callers 1

maybeTimeoutFontsFunction · 0.85

Calls 1

nextMethod · 0.45

Tested by

no test coverage detected