@@ -345,19 +345,30 @@ export function getCustomizationURL(partial: DeepPartial<SiteCustomizationSettin
345
345
*/
346
346
async function waitForIcons ( page : Page ) {
347
347
await page . waitForFunction ( ( ) => {
348
- const urlStates : Record < string , 'pending' | 'loaded' > =
349
- ( window as any ) . __ICONS_STATES__ || { } ;
348
+ const urlStates : Record <
349
+ string ,
350
+ { state : 'pending' ; uri : null } | { state : 'loaded' ; uri : string }
351
+ > = ( window as any ) . __ICONS_STATES__ || { } ;
350
352
( window as any ) . __ICONS_STATES__ = urlStates ;
351
353
354
+ const fetchSvgAsDataUri = async ( url : string ) : Promise < string > => {
355
+ const response = await fetch ( url ) ;
356
+ if ( ! response . ok ) {
357
+ throw new Error ( `Failed to fetch SVG: ${ response . status } ` ) ;
358
+ }
359
+
360
+ const svgText = await response . text ( ) ;
361
+ const encoded = encodeURIComponent ( svgText ) . replace ( / ' / g, '%27' ) . replace ( / " / g, '%22' ) ;
362
+
363
+ return `data:image/svg+xml;charset=utf-8,${ encoded } ` ;
364
+ } ;
365
+
352
366
const loadUrl = ( url : string ) => {
353
367
// Mark the URL as pending.
354
- urlStates [ url ] = 'pending' ;
355
-
356
- const img = new Image ( ) ;
357
- img . onload = ( ) => {
358
- urlStates [ url ] = 'loaded' ;
359
- } ;
360
- img . src = url ;
368
+ urlStates [ url ] = { state : 'pending' , uri : null } ;
369
+ fetchSvgAsDataUri ( url ) . then ( ( uri ) => {
370
+ urlStates [ url ] = { state : 'loaded' , uri } ;
371
+ } ) ;
361
372
} ;
362
373
363
374
const icons = Array . from ( document . querySelectorAll ( 'svg.gb-icon' ) ) ;
@@ -393,18 +404,11 @@ async function waitForIcons(page: Page) {
393
404
394
405
// If the URL is already queued for loading, we return the state.
395
406
if ( urlStates [ url ] ) {
396
- if ( urlStates [ url ] === 'loaded' ) {
407
+ if ( urlStates [ url ] . state === 'loaded' ) {
397
408
icon . setAttribute ( 'data-argos-state' , 'pending' ) ;
398
- const bckMaskImage = icon . style . maskImage ;
399
- const bckDisplay = icon . style . display ;
400
- icon . style . maskImage = '' ;
401
- icon . style . display = 'none' ;
409
+ icon . style . maskImage = `url("${ urlStates [ url ] . uri } ")` ;
402
410
requestAnimationFrame ( ( ) => {
403
- icon . style . maskImage = bckMaskImage ;
404
- icon . style . display = bckDisplay ;
405
- requestAnimationFrame ( ( ) => {
406
- icon . setAttribute ( 'data-argos-state' , 'loaded' ) ;
407
- } ) ;
411
+ icon . setAttribute ( 'data-argos-state' , 'loaded' ) ;
408
412
} ) ;
409
413
return false ;
410
414
}
0 commit comments