Skip to content

Commit

Permalink
fix(font): update fallback font
Browse files Browse the repository at this point in the history
  • Loading branch information
ThornWalli committed Sep 13, 2023
1 parent 315e2fe commit b49fa7c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/runtime/classes/Font.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand All @@ -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(', ')};
Expand Down Expand Up @@ -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 '';
}
4 changes: 2 additions & 2 deletions src/runtime/classes/FontCollection.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
]);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/fonts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function writeHead(isCritical, fontCollection, runtimeConfig) {
return fontCollection.getStyleDescriptions(options);
}),
noscript: computed(() => {
return fontCollection.getNoScriptStyleDescriptions(options);
return fontCollection.getNoScriptStyleDescriptions();
})
});
}

0 comments on commit b49fa7c

Please sign in to comment.