diff --git a/src/embed-webfonts.ts b/src/embed-webfonts.ts index a84a699d..39bce8bb 100644 --- a/src/embed-webfonts.ts +++ b/src/embed-webfonts.ts @@ -3,6 +3,8 @@ import { toArray } from './util' import { fetchAsDataURL } from './dataurl' import { shouldEmbed, embedResources } from './embed-resources' +const PROPERTY_FONT_FAMILY = 'font-family' + interface Metadata { url: string cssText: string @@ -210,7 +212,8 @@ function getUsedFonts(node: HTMLElement) { const fonts = new Set() function traverse(node: HTMLElement) { const fontFamily = - node.style.fontFamily || getComputedStyle(node).fontFamily + node.style.getPropertyValue(PROPERTY_FONT_FAMILY) || + getComputedStyle(node).getPropertyValue(PROPERTY_FONT_FAMILY) fontFamily.split(',').forEach((font) => { fonts.add(normalizeFontFamily(font)) }) @@ -234,7 +237,11 @@ export async function getWebFontCSS( const cssTexts = await Promise.all( rules .filter((rule) => - usedFonts.has(normalizeFontFamily(rule.style.fontFamily)), + usedFonts.has( + normalizeFontFamily( + rule.style.getPropertyValue(PROPERTY_FONT_FAMILY), + ), + ), ) .map((rule) => { const baseUrl = rule.parentStyleSheet