fix(app): don't bundle fonts (#19329)
This commit is contained in:
parent
98a31e30cc
commit
b8fb75a94a
86 changed files with 418 additions and 549 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +0,0 @@
|
|||
CaskaydiaCoveNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
CaskaydiaCoveNerdFontMono-Regular.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
FiraCodeNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
FiraCodeNerdFontMono-Regular.woff2
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +0,0 @@
|
|||
GeistMonoNerdFontMono-Bold.woff2
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1 +0,0 @@
|
|||
GeistMonoNerdFontMono-Medium.woff2
|
||||
Binary file not shown.
|
|
@ -1 +0,0 @@
|
|||
GeistMonoNerdFontMono-Regular.woff2
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +0,0 @@
|
|||
HackNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
HackNerdFontMono-Regular.woff2
|
||||
Binary file not shown.
|
|
@ -1 +0,0 @@
|
|||
InconsolataNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
InconsolataNerdFontMono-Regular.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
IntoneMonoNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
IntoneMonoNerdFontMono-Regular.woff2
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +0,0 @@
|
|||
JetBrainsMonoNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
JetBrainsMonoNerdFontMono-Regular.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
MesloLGSNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
MesloLGSNerdFontMono-Regular.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
RobotoMonoNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
RobotoMonoNerdFontMono-Regular.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
SauceCodeProNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
SauceCodeProNerdFontMono-Regular.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
UbuntuMonoNerdFontMono-Bold.woff2
|
||||
|
|
@ -1 +0,0 @@
|
|||
UbuntuMonoNerdFontMono-Regular.woff2
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
type MonoFont = {
|
||||
id: string
|
||||
family: string
|
||||
regular: string
|
||||
bold: string
|
||||
}
|
||||
|
||||
let files: Record<string, () => Promise<string>> | undefined
|
||||
|
||||
function getFiles() {
|
||||
if (files) return files
|
||||
files = import.meta.glob("./assets/fonts/*.woff2", { import: "default" }) as Record<string, () => Promise<string>>
|
||||
return files
|
||||
}
|
||||
|
||||
export const MONO_NERD_FONTS = [
|
||||
{
|
||||
id: "jetbrains-mono",
|
||||
family: "JetBrains Mono Nerd Font",
|
||||
regular: "./assets/fonts/jetbrains-mono-nerd-font.woff2",
|
||||
bold: "./assets/fonts/jetbrains-mono-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "fira-code",
|
||||
family: "Fira Code Nerd Font",
|
||||
regular: "./assets/fonts/fira-code-nerd-font.woff2",
|
||||
bold: "./assets/fonts/fira-code-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "cascadia-code",
|
||||
family: "Cascadia Code Nerd Font",
|
||||
regular: "./assets/fonts/cascadia-code-nerd-font.woff2",
|
||||
bold: "./assets/fonts/cascadia-code-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "hack",
|
||||
family: "Hack Nerd Font",
|
||||
regular: "./assets/fonts/hack-nerd-font.woff2",
|
||||
bold: "./assets/fonts/hack-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "source-code-pro",
|
||||
family: "Source Code Pro Nerd Font",
|
||||
regular: "./assets/fonts/source-code-pro-nerd-font.woff2",
|
||||
bold: "./assets/fonts/source-code-pro-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "inconsolata",
|
||||
family: "Inconsolata Nerd Font",
|
||||
regular: "./assets/fonts/inconsolata-nerd-font.woff2",
|
||||
bold: "./assets/fonts/inconsolata-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "roboto-mono",
|
||||
family: "Roboto Mono Nerd Font",
|
||||
regular: "./assets/fonts/roboto-mono-nerd-font.woff2",
|
||||
bold: "./assets/fonts/roboto-mono-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "ubuntu-mono",
|
||||
family: "Ubuntu Mono Nerd Font",
|
||||
regular: "./assets/fonts/ubuntu-mono-nerd-font.woff2",
|
||||
bold: "./assets/fonts/ubuntu-mono-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "intel-one-mono",
|
||||
family: "Intel One Mono Nerd Font",
|
||||
regular: "./assets/fonts/intel-one-mono-nerd-font.woff2",
|
||||
bold: "./assets/fonts/intel-one-mono-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "meslo-lgs",
|
||||
family: "Meslo LGS Nerd Font",
|
||||
regular: "./assets/fonts/meslo-lgs-nerd-font.woff2",
|
||||
bold: "./assets/fonts/meslo-lgs-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "iosevka",
|
||||
family: "Iosevka Nerd Font",
|
||||
regular: "./assets/fonts/iosevka-nerd-font.woff2",
|
||||
bold: "./assets/fonts/iosevka-nerd-font-bold.woff2",
|
||||
},
|
||||
{
|
||||
id: "geist-mono",
|
||||
family: "GeistMono Nerd Font",
|
||||
regular: "./assets/fonts/GeistMonoNerdFontMono-Regular.woff2",
|
||||
bold: "./assets/fonts/GeistMonoNerdFontMono-Bold.woff2",
|
||||
},
|
||||
] satisfies MonoFont[]
|
||||
|
||||
const mono = Object.fromEntries(MONO_NERD_FONTS.map((font) => [font.id, font])) as Record<string, MonoFont>
|
||||
const loads = new Map<string, Promise<void>>()
|
||||
|
||||
function css(font: { family: string; regular: string; bold: string }) {
|
||||
return `
|
||||
@font-face {
|
||||
font-family: "${font.family}";
|
||||
src: url("${font.regular}") format("woff2");
|
||||
font-display: swap;
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "${font.family}";
|
||||
src: url("${font.bold}") format("woff2");
|
||||
font-display: swap;
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
export function ensureMonoFont(id: string | undefined) {
|
||||
if (!id || id === "ibm-plex-mono") return Promise.resolve()
|
||||
if (typeof document !== "object") return Promise.resolve()
|
||||
const font = mono[id]
|
||||
if (!font) return Promise.resolve()
|
||||
const styleId = `oc-font-${font.id}`
|
||||
if (document.getElementById(styleId)) return Promise.resolve()
|
||||
const hit = loads.get(font.id)
|
||||
if (hit) return hit
|
||||
const files = getFiles()
|
||||
const load = Promise.all([files[font.regular]?.(), files[font.bold]?.()]).then(([regular, bold]) => {
|
||||
if (!regular || !bold) return
|
||||
if (document.getElementById(styleId)) return
|
||||
const style = document.createElement("style")
|
||||
style.id = styleId
|
||||
style.textContent = css({ family: font.family, regular, bold })
|
||||
document.head.appendChild(style)
|
||||
})
|
||||
loads.set(font.id, load)
|
||||
return load
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue