@@ -271,9 +271,39 @@ async function getComponentSvg(title) {
271271 svgContent = svgContent . replace ( / b a c k g r o u n d : \s * # f 4 f 6 f c / g, 'background: #f8f8f8' ) ;
272272 svgContent = svgContent . replace ( / v a r \( - - a n a t o m y - f o n t \) / g, 'adobe-clean' ) ;
273273
274- // Convert SVG to data URI for use as image source
275- const svgBase64 = Buffer . from ( svgContent ) . toString ( 'base64' ) ;
276- return `data:image/svg+xml;base64,${ svgBase64 } ` ;
274+ const adobeCleanRegularBase64 = Buffer . from ( adobeCleanRegular ) . toString ( 'base64' ) ;
275+ const adobeCleanBoldBase64 = Buffer . from ( adobeCleanBold ) . toString ( 'base64' ) ;
276+
277+ const fontFaceStyle = `
278+ @font-face {
279+ font-family: 'adobe-clean';
280+ font-style: normal;
281+ font-weight: 400;
282+ src: url(data:font/woff2;base64,${ adobeCleanRegularBase64 } ) format('woff2');
283+ }
284+ @font-face {
285+ font-family: 'adobe-clean';
286+ font-style: normal;
287+ font-weight: 700;
288+ src: url(data:font/woff2;base64,${ adobeCleanBoldBase64 } ) format('woff2');
289+ }
290+ ` ;
291+
292+ // Inject style tag into SVG
293+ if ( svgContent . includes ( '<defs>' ) ) {
294+ svgContent = svgContent . replace ( '<defs>' , `<defs><style>${ fontFaceStyle } </style>` ) ;
295+ } else if ( svgContent . includes ( '<svg' ) ) {
296+ svgContent = svgContent . replace ( / < s v g ( [ ^ > ] * ) > / , `<svg$1><defs><style>${ fontFaceStyle } </style></defs>` ) ;
297+ }
298+
299+ // Convert SVG to PNG
300+ const pngBuffer = await sharp ( Buffer . from ( svgContent ) )
301+ . png ( )
302+ . toBuffer ( ) ;
303+
304+ // Convert PNG to data URI to use as image source
305+ const pngBase64 = pngBuffer . toString ( 'base64' ) ;
306+ return `data:image/png;base64,${ pngBase64 } ` ;
277307 } catch ( error ) {
278308 console . warn ( `Could not load SVG for ${ title } : ${ error . message } ` ) ;
279309 return null ;
0 commit comments