From b8ca4d491c3ca9e830476e903b4e86a674e8153b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=A0=E6=89=8B=E6=8D=A7=E9=B2=9C=E8=8A=B1?= <157215725@qq.com> Date: Sat, 18 Mar 2023 22:54:57 +0800 Subject: [PATCH] fix: `cssRule.style.fontFamily` null safe (close #14) --- src/clone-node.ts | 7 ++++--- src/embed-web-font.ts | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/clone-node.ts b/src/clone-node.ts index 09236ab..37bf0fc 100644 --- a/src/clone-node.ts +++ b/src/clone-node.ts @@ -97,9 +97,10 @@ export async function cloneNode( 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) diff --git a/src/embed-web-font.ts b/src/embed-web-font.ts index cf5b93a..e7487a3 100644 --- a/src/embed-web-font.ts +++ b/src/embed-web-font.ts @@ -78,7 +78,10 @@ export async function embedWebFont( .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