@@ -27,7 +27,7 @@ function fetchCSS(url: string): Promise<void | Metadata> {
27
27
return deferred
28
28
}
29
29
30
- async function embedFonts ( meta : Metadata ) : Promise < string > {
30
+ async function embedFonts ( meta : Metadata , options : Options ) : Promise < string > {
31
31
return meta . cssText . then ( ( raw : string ) => {
32
32
let cssText = raw
33
33
const regexUrl = / u r l \( [ " ' ] ? ( [ ^ " ' ) ] + ) [ " ' ] ? \) / g
@@ -40,7 +40,7 @@ async function embedFonts(meta: Metadata): Promise<string> {
40
40
41
41
// eslint-disable-next-line promise/no-nesting
42
42
return window
43
- . fetch ( url )
43
+ . fetch ( url , options . fetchRequestInit )
44
44
. then ( ( res ) => res . blob ( ) )
45
45
. then (
46
46
( blob ) =>
@@ -116,6 +116,7 @@ function parseCSS(source: string) {
116
116
117
117
async function getCSSRules (
118
118
styleSheets : CSSStyleSheet [ ] ,
119
+ options : Options ,
119
120
) : Promise < CSSStyleRule [ ] > {
120
121
const ret : CSSStyleRule [ ] = [ ]
121
122
const deferreds : Promise < number | void > [ ] = [ ]
@@ -130,7 +131,9 @@ async function getCSSRules(
130
131
let importIndex = index + 1
131
132
const url = ( item as CSSImportRule ) . href
132
133
const deferred = fetchCSS ( url )
133
- . then ( ( metadata ) => ( metadata ? embedFonts ( metadata ) : '' ) )
134
+ . then ( ( metadata ) =>
135
+ metadata ? embedFonts ( metadata , options ) : '' ,
136
+ )
134
137
. then ( ( cssText ) =>
135
138
parseCSS ( cssText ) . forEach ( ( rule ) => {
136
139
try {
@@ -162,7 +165,9 @@ async function getCSSRules(
162
165
if ( sheet . href != null ) {
163
166
deferreds . push (
164
167
fetchCSS ( sheet . href )
165
- . then ( ( metadata ) => ( metadata ? embedFonts ( metadata ) : '' ) )
168
+ . then ( ( metadata ) =>
169
+ metadata ? embedFonts ( metadata , options ) : '' ,
170
+ )
166
171
. then ( ( cssText ) =>
167
172
parseCSS ( cssText ) . forEach ( ( rule ) => {
168
173
inline . insertRule ( rule , sheet . cssRules . length )
@@ -209,22 +214,23 @@ function getWebFontRules(cssRules: CSSStyleRule[]): CSSStyleRule[] {
209
214
210
215
async function parseWebFontRules < T extends HTMLElement > (
211
216
node : T ,
217
+ options : Options ,
212
218
) : Promise < CSSRule [ ] > {
213
219
return new Promise ( ( resolve , reject ) => {
214
220
if ( node . ownerDocument == null ) {
215
221
reject ( new Error ( 'Provided element is not within a Document' ) )
216
222
}
217
223
resolve ( toArray ( node . ownerDocument . styleSheets ) )
218
224
} )
219
- . then ( ( styleSheets : CSSStyleSheet [ ] ) => getCSSRules ( styleSheets ) )
225
+ . then ( ( styleSheets : CSSStyleSheet [ ] ) => getCSSRules ( styleSheets , options ) )
220
226
. then ( getWebFontRules )
221
227
}
222
228
223
229
export async function getWebFontCSS < T extends HTMLElement > (
224
230
node : T ,
225
231
options : Options ,
226
232
) : Promise < string > {
227
- return parseWebFontRules ( node )
233
+ return parseWebFontRules ( node , options )
228
234
. then ( ( rules ) =>
229
235
Promise . all (
230
236
rules . map ( ( rule ) => {
0 commit comments