change the format of font faces to something closer to the css
This commit is contained in:
parent
3b13a623cd
commit
b3fd1eda03
1 changed files with 38 additions and 7 deletions
45
src/theme.js
45
src/theme.js
|
@ -49,15 +49,46 @@ function clearCustomTheme() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const allowedFontFaceProps = [
|
||||||
|
"font-display",
|
||||||
|
"font-family",
|
||||||
|
"font-stretch",
|
||||||
|
"font-style",
|
||||||
|
"font-weight",
|
||||||
|
"font-variant",
|
||||||
|
"font-feature-settings",
|
||||||
|
"font-variation-settings",
|
||||||
|
"src",
|
||||||
|
"unicode-range"
|
||||||
|
];
|
||||||
|
|
||||||
function generateCustomFontFaceCSS(faces) {
|
function generateCustomFontFaceCSS(faces) {
|
||||||
return Object.entries(faces).map(([fontName, face]) => {
|
return faces.map(face => {
|
||||||
const src = Object.entries(face.src).map(([format, url]) => {
|
const src = face.src && face.src.map(srcElement => {
|
||||||
return `url('${url}') format('${format}')`;
|
let format;
|
||||||
|
if (srcElement.format) {
|
||||||
|
format = `format("${srcElement.format}")`;
|
||||||
|
}
|
||||||
|
if (srcElement.url) {
|
||||||
|
return `url("${srcElement.url}") ${format}`;
|
||||||
|
} else if (srcElement.local) {
|
||||||
|
return `local("${srcElement.local}") ${format}`;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}).join(", ");
|
}).join(", ");
|
||||||
return `@font-face {` +
|
const props = Object.keys(face).filter(prop => allowedFontFaceProps.includes(prop));
|
||||||
` font-family: '${fontName}';` +
|
const body = props.map(prop => {
|
||||||
` src: ${src};` +
|
let value;
|
||||||
`}`;
|
if (prop === "src") {
|
||||||
|
value = src;
|
||||||
|
} else if (prop === "font-family") {
|
||||||
|
value = `"${face[prop]}"`;
|
||||||
|
} else {
|
||||||
|
value = face[prop];
|
||||||
|
}
|
||||||
|
return `${prop}: ${value}`;
|
||||||
|
}).join(";");
|
||||||
|
return `@font-face {${body}}`;
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue