Skip to content

Commit

Permalink
fix: cssRule.style.fontFamily null safe (close #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Mar 18, 2023
1 parent 13247fc commit b8ca4d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/clone-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ export async function cloneNode<T extends Node>(
applyCssStyleWithOptions(cloneStyle, context)
}

if (cloneStyle.fontFamily) {
cloneStyle.fontFamily.split(',').forEach(val => fontFamilies.add(val))
}
cloneStyle.getPropertyValue('font-family')
.split(',')
.filter(Boolean)
.forEach(val => fontFamilies.add(val))

copyPseudoContent(node, clone, ownerWindow)

Expand Down
5 changes: 4 additions & 1 deletion src/embed-web-font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export async function embedWebFont<T extends Element>(
.filter(cssRule => (
isCssFontFaceRule(cssRule)
&& hasCssUrl(cssRule.style.getPropertyValue('src'))
&& cssRule.style.fontFamily.split(',').some(val => fontFamilies.has(val))
&& cssRule.style.getPropertyValue('font-family')
.split(',')
.filter(Boolean)
.some(val => fontFamilies.has(val))
))
.forEach((value) => {
const rule = value as CSSFontFaceRule
Expand Down

1 comment on commit b8ca4d4

@vercel
Copy link

@vercel vercel bot commented on b8ca4d4 Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

modern-screenshot – ./

modern-screenshot-qq15725.vercel.app
modern-screenshot-git-main-qq15725.vercel.app
modern-screenshot.vercel.app

Please sign in to comment.