diff --git a/templates/reader.templ b/templates/reader.templ index 8828f00..d83e006 100644 --- a/templates/reader.templ +++ b/templates/reader.templ @@ -10,6 +10,7 @@ templ Reader(user User, metadata ReaderMetadata, progress ReadingProgress, bookm { metadata.Title } - Bookhoard Reader + @@ -56,7 +57,7 @@ templ ReaderChrome(user User, metadata ReaderMetadata, progress ReadingProgress)
- + ← Back

{ metadata.Title }

@@ -79,6 +80,17 @@ templ ReaderChrome(user User, metadata ReaderMetadata, progress ReadingProgress) + +
diff --git a/web/src/reader/ebook/font-loader.ts b/web/src/reader/ebook/font-loader.ts new file mode 100644 index 0000000..40f4256 --- /dev/null +++ b/web/src/reader/ebook/font-loader.ts @@ -0,0 +1,73 @@ +// Font loading with performance optimization + +const READING_FONTS = [ + { + id: "literata", + name: "Literata", + stack: "Literata, serif", + description: "Designed for Google Play Books", + }, + { + id: "crimson", + name: "Crimson Text", + stack: "Crimson Text, serif", + description: "Optimized for screen reading", + }, + { + id: "source-serif", + name: "Source Serif 4", + stack: "Source Serif 4, serif", + description: "Professional Adobe quality", + }, + { + id: "eb-garamond", + name: "EB Garamond", + stack: "EB Garamond, serif", + description: "Classic elegance", + }, + { + id: "libertinus", + name: "Libertinus Serif", + stack: "Libertinus Serif, serif", + description: "Excellent for technical content", + }, + { + id: "noto-serif", + name: "Noto Serif", + stack: "Noto Serif, serif", + description: "Maximum language support", + }, + { + id: "charis-sil", + name: "Charis SIL", + stack: "Charis SIL, serif", + description: "Multilingual specialist", + }, + { + id: "ibm-plex", + name: "IBM Plex Serif", + stack: "IBM Plex Serif, serif", + description: "Modern & versatile", + }, +]; + +// Preload critical fonts (default font + user's last choice) +async function preloadFonts(userPreferredFont: string): Promise { + const fontsToPreload = new Set(["literata", userPreferredFont]); + + for (const fontId of fontsToPreload) { + const font = READING_FONTS.find((f) => f.id === fontId); + if (font) { + document.fonts.load(`16px "${font.stack}"`); + } + } +} + +// Get font stack for CSS +function getFontStack(fontId: string): string { + const font = READING_FONTS.find((f) => f.id === fontId); + return font?.stack || "Literata, serif"; +} + +// All fonts bundled - no network requests needed +export { READING_FONTS, preloadFonts, getFontStack };