Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/embed-webfonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -210,7 +212,8 @@ function getUsedFonts(node: HTMLElement) {
const fonts = new Set<string>()
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))
})
Expand All @@ -234,7 +237,11 @@ export async function getWebFontCSS<T extends HTMLElement>(
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
Expand Down