@@ -89,6 +89,22 @@ const [adobeCleanRegular, adobeCleanBold] = await Promise.all([
89
89
loadFont ( 'https://use.typekit.net/af/eaf09c/000000000000000000017703/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3' )
90
90
] ) ;
91
91
92
+ // Detect font MIME type and CSS format for inlining
93
+ function detectFontFormatAndMime ( bytes ) {
94
+ const buf = Buffer . isBuffer ( bytes ) ? bytes : Buffer . from ( bytes ) ;
95
+ const header = buf . subarray ( 0 , 4 ) . toString ( 'ascii' ) ;
96
+ if ( header === 'wOF2' ) {
97
+ return { mime : 'font/woff2' , format : 'woff2' } ;
98
+ }
99
+ if ( header === 'wOFF' ) {
100
+ return { mime : 'font/woff' , format : 'woff' } ;
101
+ }
102
+ if ( header === 'OTTO' ) {
103
+ return { mime : 'font/otf' , format : 'opentype' } ;
104
+ }
105
+ return { mime : 'font/woff2' , format : 'woff2' } ;
106
+ }
107
+
92
108
// Mappings for components that don't match their SVG file names
93
109
const componentSvgExceptions = {
94
110
'Accordion' : 'DisclosureGroup.svg' ,
@@ -271,6 +287,14 @@ async function getComponentSvg(title) {
271
287
svgContent = svgContent . replace ( / b a c k g r o u n d : \s * # f 4 f 6 f c / g, 'background: #f8f8f8' ) ;
272
288
svgContent = svgContent . replace ( / v a r \( - - a n a t o m y - f o n t \) / g, 'adobe-clean' ) ;
273
289
290
+ // Inline fonts so text within illustration renders in CI
291
+ const regMeta = detectFontFormatAndMime ( adobeCleanRegular ) ;
292
+ const boldMeta = detectFontFormatAndMime ( adobeCleanBold ) ;
293
+ const regB64 = Buffer . from ( adobeCleanRegular ) . toString ( 'base64' ) ;
294
+ const boldB64 = Buffer . from ( adobeCleanBold ) . toString ( 'base64' ) ;
295
+ const fontCss = `<style>@font-face{font-family:'adobe-clean';src:url(data:${ regMeta . mime } ;base64,${ regB64 } ) format('${ regMeta . format } ');font-weight:400;font-style:normal;font-display:block}@font-face{font-family:'adobe-clean';src:url(data:${ boldMeta . mime } ;base64,${ boldB64 } ) format('${ boldMeta . format } ');font-weight:700;font-style:normal;font-display:block}</style>` ;
296
+ svgContent = svgContent . replace ( / < s v g \b [ ^ > ] * > / i, ( m ) => m + fontCss ) ;
297
+
274
298
// Convert SVG to data URI for use as image source
275
299
const svgBase64 = Buffer . from ( svgContent ) . toString ( 'base64' ) ;
276
300
return `data:image/svg+xml;base64,${ svgBase64 } ` ;
0 commit comments