From b49fa7c2fb8a6b02285f191b2bcc2c0f61f6161b Mon Sep 17 00:00:00 2001 From: Thorn Walli Date: Wed, 13 Sep 2023 13:34:50 +0200 Subject: [PATCH] fix(font): update fallback font --- src/runtime/classes/Font.mjs | 18 ++++++++++-------- src/runtime/classes/FontCollection.mjs | 4 ++-- src/runtime/composables/fonts.mjs | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/runtime/classes/Font.mjs b/src/runtime/classes/Font.mjs index c1406bc3df..f929daa090 100644 --- a/src/runtime/classes/Font.mjs +++ b/src/runtime/classes/Font.mjs @@ -50,10 +50,12 @@ export default class Font { getCSSText({ usedFontaine = false } = {}) { const selector = createSelector(this.rootSelector, this.selector); - const family = prepareFamily(this.family, { usedFontaine }); + const family = `"${this.family}"`; return wrapByMedia( `${selector} { - font-family: ${this.fallbackFamily.join(', ')}; + font-family: ${[getFontaineFallback(this.family, usedFontaine)] + .filter(Boolean) + .concat(this.fallbackFamily.join(', '))}; font-weight: ${this.weight}; font-style: ${this.style}; } @@ -64,9 +66,9 @@ export default class Font { ); } - getNoScriptCSSText({ usedFontaine = false } = {}) { + getNoScriptCSSText() { const selector = createSelector(this.rootSelector, this.selector); - const family = prepareFamily(this.family, { usedFontaine }); + const family = `"${this.family}"`; return wrapByMedia( `${selector} { font-family: ${[family].concat(this.fallbackFamily).join(', ')}; @@ -123,9 +125,9 @@ function weightNormalize(weight) { } } -function prepareFamily(family, { usedFontaine = false } = {}) { - if (!usedFontaine) { - return `"${family}"`; +function getFontaineFallback(family, usedFontaine) { + if (usedFontaine) { + return `"${family} fallback"`; } - return `"${family}", "${family} fallback"`; + return ''; } diff --git a/src/runtime/classes/FontCollection.mjs b/src/runtime/classes/FontCollection.mjs index 46c95eb02a..93a937b31e 100644 --- a/src/runtime/classes/FontCollection.mjs +++ b/src/runtime/classes/FontCollection.mjs @@ -50,10 +50,10 @@ export default class FontCollection { ]); } - getNoScriptStyleDescriptions(options) { + getNoScriptStyleDescriptions() { return getRelevantDescriptions([ getStyleDescription( - this.list.map(font => font.getNoScriptCSSText(options)).join(' '), + this.list.map(font => font.getNoScriptCSSText()).join(' '), true ) ]); diff --git a/src/runtime/composables/fonts.mjs b/src/runtime/composables/fonts.mjs index 9a7605ab63..a3238cd0c0 100644 --- a/src/runtime/composables/fonts.mjs +++ b/src/runtime/composables/fonts.mjs @@ -40,7 +40,7 @@ function writeHead(isCritical, fontCollection, runtimeConfig) { return fontCollection.getStyleDescriptions(options); }), noscript: computed(() => { - return fontCollection.getNoScriptStyleDescriptions(options); + return fontCollection.getNoScriptStyleDescriptions(); }) }); }