File tree Expand file tree Collapse file tree 2 files changed +39
-25
lines changed Expand file tree Collapse file tree 2 files changed +39
-25
lines changed Original file line number Diff line number Diff line change @@ -8612,33 +8612,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
8612
8612
*
8613
8613
* @param {string } name
8614
8614
* @param {string } url
8615
+ * @return {!Promise<void> }
8615
8616
* @export
8616
8617
*/
8617
- async addFont ( name , url ) {
8618
- if ( 'fonts' in document && 'FontFace' in window ) {
8619
- await document . fonts . ready ;
8620
- if ( ! ( 'entries' in document . fonts ) ) {
8621
- return ;
8622
- }
8623
- const fontFaceSetIteratorToArray = ( target ) => {
8624
- const iterable = target . entries ( ) ;
8625
- const results = [ ] ;
8626
- let iterator = iterable . next ( ) ;
8627
- while ( iterator . done === false ) {
8628
- results . push ( iterator . value ) ;
8629
- iterator = iterable . next ( ) ;
8630
- }
8631
- return results ;
8632
- } ;
8633
- for ( const fontFace of fontFaceSetIteratorToArray ( document . fonts ) ) {
8634
- if ( fontFace . family == name && fontFace . display == 'swap' ) {
8635
- // Font already loaded.
8636
- return ;
8637
- }
8638
- }
8639
- const fontFace = new FontFace ( name , `url(${ url } )` , { display : 'swap' } ) ;
8640
- document . fonts . add ( fontFace ) ;
8641
- }
8618
+ addFont ( name , url ) {
8619
+ return shaka . util . Dom . addFont ( name , url ) ;
8642
8620
}
8643
8621
8644
8622
/**
Original file line number Diff line number Diff line change @@ -158,5 +158,41 @@ shaka.util.Dom = class {
158
158
element . removeChild ( element . firstChild ) ;
159
159
}
160
160
}
161
+
162
+ /**
163
+ * Load a new font on the page. If the font was already loaded, it does
164
+ * nothing.
165
+ *
166
+ * @param {string } name
167
+ * @param {string } url
168
+ * @return {!Promise<void> }
169
+ */
170
+ static async addFont ( name , url ) {
171
+ if ( ! ( 'fonts' in document && 'FontFace' in window ) ) {
172
+ return ;
173
+ }
174
+ await document . fonts . ready ;
175
+ if ( ! ( 'entries' in document . fonts ) ) {
176
+ return ;
177
+ }
178
+ const fontFaceSetIteratorToArray = ( target ) => {
179
+ const iterable = target . entries ( ) ;
180
+ const results = [ ] ;
181
+ let iterator = iterable . next ( ) ;
182
+ while ( iterator . done === false ) {
183
+ results . push ( iterator . value ) ;
184
+ iterator = iterable . next ( ) ;
185
+ }
186
+ return results ;
187
+ } ;
188
+ for ( const fontFace of fontFaceSetIteratorToArray ( document . fonts ) ) {
189
+ if ( fontFace . family === name && fontFace . display === 'swap' ) {
190
+ // Font already loaded.
191
+ return ;
192
+ }
193
+ }
194
+ const fontFace = new FontFace ( name , `url(${ url } )` , { display : 'swap' } ) ;
195
+ document . fonts . add ( fontFace ) ;
196
+ }
161
197
} ;
162
198
You can’t perform that action at this time.
0 commit comments