diff --git a/app/globals.css b/app/globals.css index b96ab4c9..a8a44a15 100644 --- a/app/globals.css +++ b/app/globals.css @@ -205,6 +205,7 @@ /* Scope custom fonts to document content only (not sidebar/UI chrome) */ .pageScrollWrapper { font-family: var(--theme-font, var(--font-quattro)); + font-size: var(--theme-font-base-size, 16px); } .pageScrollWrapper h1, @@ -214,6 +215,18 @@ font-family: var(--theme-heading-font, var(--theme-font, var(--font-quattro))); } + /* Scale heading sizes relative to the custom base font size */ + .pageScrollWrapper h1 { font-size: 2em; } + .pageScrollWrapper h2 { font-size: 1.625em; } + .pageScrollWrapper h3 { font-size: 1.125em; } + .pageScrollWrapper h4 { font-size: 1em; } + + /* Scale text size classes relative to the custom base font size. + Tailwind's text-sm/text-base/text-lg compile to fixed rem values + which ignore the custom base size set on .pageScrollWrapper. */ + .pageScrollWrapper .textSizeSmall { font-size: 0.875em; } + .pageScrollWrapper .textSizeLarge { font-size: 1.125em; } + .pageScrollWrapper pre { font-family: var(--theme-font, var(--font-quattro)); } diff --git a/app/lish/[did]/[publication]/[rkey]/Blocks/PublishedPageBlock.tsx b/app/lish/[did]/[publication]/[rkey]/Blocks/PublishedPageBlock.tsx index 938ec530..964cb6ed 100644 --- a/app/lish/[did]/[publication]/[rkey]/Blocks/PublishedPageBlock.tsx +++ b/app/lish/[did]/[publication]/[rkey]/Blocks/PublishedPageBlock.tsx @@ -111,7 +111,7 @@ export function DocLinkBlock(props: {
{title && (
+ diff --git a/app/lish/[did]/[publication]/[rkey]/PostContent.tsx b/app/lish/[did]/[publication]/[rkey]/PostContent.tsx index 16cf239d..76e58acc 100644 --- a/app/lish/[did]/[publication]/[rkey]/PostContent.tsx +++ b/app/lish/[did]/[publication]/[rkey]/PostContent.tsx @@ -263,7 +263,7 @@ export let Block = ({
+

-

+ ); if (b.block.level === 2) return ( -

+

-

+ ); if (b.block.level === 3) return ( -

+

-

+ ); // if (b.block.level === 4) return

{b.block.plaintext}

; // if (b.block.level === 5) return
{b.block.plaintext}
; diff --git a/components/Blocks/ExternalLinkBlock.tsx b/components/Blocks/ExternalLinkBlock.tsx index 33eb17ac..ea9d8670 100644 --- a/components/Blocks/ExternalLinkBlock.tsx +++ b/components/Blocks/ExternalLinkBlock.tsx @@ -78,7 +78,7 @@ export const ExternalLinkBlock = (
{leafletMetadata[0] && (
{leafletMetadata[0].listData && ( s.editorStates[props.entityID], diff --git a/components/FontLoader.tsx b/components/FontLoader.tsx index 00e1f1bb..3de78a07 100644 --- a/components/FontLoader.tsx +++ b/components/FontLoader.tsx @@ -10,6 +10,7 @@ import { getFontPreloadLinks, getGoogleFontsUrl, getFontFamilyValue, + getFontBaseSize, } from "src/fonts"; type FontLoaderProps = { @@ -53,12 +54,14 @@ export function FontLoader({ headingFontId, bodyFontId }: FontLoaderProps) { const headingFontValue = getFontFamilyValue(headingFont); const bodyFontValue = getFontFamilyValue(bodyFont); + const bodyFontBaseSize = getFontBaseSize(bodyFont); // Set font CSS variables scoped to .leafletWrapper so they don't affect app UI const fontVariableCSS = ` .leafletWrapper { --theme-heading-font: ${headingFontValue}; --theme-font: ${bodyFontValue}; + --theme-font-base-size: ${bodyFontBaseSize}px; } `.trim(); diff --git a/components/ThemeManager/PublicationThemeProvider.tsx b/components/ThemeManager/PublicationThemeProvider.tsx index 71bb8173..aa6ba027 100644 --- a/components/ThemeManager/PublicationThemeProvider.tsx +++ b/components/ThemeManager/PublicationThemeProvider.tsx @@ -141,6 +141,9 @@ export const usePubTheme = ( let highlight2 = useColorAttribute(null, "theme/highlight-2"); let highlight3 = useColorAttribute(null, "theme/highlight-3"); + let headingFontId = theme?.headingFont; + let bodyFontId = theme?.bodyFont; + return { bgLeaflet, bgPage, @@ -152,6 +155,8 @@ export const usePubTheme = ( highlight3, showPageBackground, pageWidth, + headingFontId, + bodyFontId, }; }; diff --git a/components/ThemeManager/ThemeProvider.tsx b/components/ThemeManager/ThemeProvider.tsx index 55b28751..a133c8f5 100644 --- a/components/ThemeManager/ThemeProvider.tsx +++ b/components/ThemeManager/ThemeProvider.tsx @@ -22,7 +22,7 @@ import { PublicationThemeProvider, } from "./PublicationThemeProvider"; import { getColorDifference } from "./themeUtils"; -import { getFontConfig, getGoogleFontsUrl, getFontFamilyValue, generateFontFaceCSS } from "src/fonts"; +import { getFontConfig, getGoogleFontsUrl, getFontFamilyValue, generateFontFaceCSS, getFontBaseSize } from "src/fonts"; // define a function to set an Aria Color to a CSS Variable in RGB function setCSSVariableToColor( @@ -186,6 +186,7 @@ export const BaseThemeProvider = ({ const bodyFontConfig = getFontConfig(bodyFontId); const headingFontValue = getFontFamilyValue(headingFontConfig); const bodyFontValue = getFontFamilyValue(bodyFontConfig); + const bodyFontBaseSize = getFontBaseSize(bodyFontConfig); const headingGoogleFontsUrl = getGoogleFontsUrl(headingFontConfig); const bodyGoogleFontsUrl = getGoogleFontsUrl(bodyFontConfig); @@ -313,6 +314,7 @@ export const BaseThemeProvider = ({ "--page-width-units": `min(${pageWidth || 624}px, calc(100vw - 12px))`, "--theme-heading-font": headingFontValue, "--theme-font": bodyFontValue, + "--theme-font-base-size": `${bodyFontBaseSize}px`, } as CSSProperties } > diff --git a/src/fonts.ts b/src/fonts.ts index 694f22a0..5e9eed24 100644 --- a/src/fonts.ts +++ b/src/fonts.ts @@ -113,6 +113,7 @@ export const fonts: Record = { }; export const defaultFontId = "quattro"; +export const defaultBaseSize = 16; // Parse a Google Fonts URL or string to extract the font name and family parameter // Supports various formats: @@ -237,6 +238,11 @@ export function getGoogleFontsUrl(font: FontConfig): string | null { return `https://fonts.googleapis.com/css2?family=${font.googleFontsFamily}&display=swap`; } +// Get the base font size for a font config +export function getFontBaseSize(font: FontConfig): number { + return font.baseSize ?? defaultBaseSize; +} + // Get the CSS font-family value with fallbacks export function getFontFamilyValue(font: FontConfig): string { const family = font.fontFamily.includes(" ")