package com.peachpasswords.ui.theme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.compositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.Density import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp /** Current accent color, available to any composable under [PeachTheme]. */ val LocalPeachAccent = compositionLocalOf { DEFAULT_ACCENT } /** When true, decorative/long-running animations should be skipped or shortened. */ val LocalReduceMotion = staticCompositionLocalOf { false } @Composable fun PeachTheme( accent: Color = DEFAULT_ACCENT, reduceMotion: Boolean = false, textSize: String = "medium", content: @Composable () -> Unit, ) { // V3 text size (browser's data-text-size parity): scale the ambient font // scale. small=0.92 matches the extension's intent (its CSS ships no small // rule); large=1.08 matches the extension's zoom exactly. Only ROOT themes // should pass a non-default textSize — nested PeachTheme calls keep the // 1.0 factor so the scale is applied exactly once. val textScale = when (textSize) { "small" -> 0.92f "large" -> 1.08f else -> 1f } val baseDensity = LocalDensity.current val scaledDensity = if (textScale == 1f) { baseDensity } else { Density(baseDensity.density, baseDensity.fontScale * textScale) } val colors = darkColorScheme( primary = accent, onPrimary = PeachColors.Bg, secondary = PeachColors.SyncBusy, onSecondary = PeachColors.Bg, background = PeachColors.Bg, onBackground = PeachColors.T0, surface = PeachColors.S1, onSurface = PeachColors.T0, surfaceVariant = PeachColors.S2, onSurfaceVariant = PeachColors.T1, outline = PeachColors.T3, error = PeachColors.Breach, onError = PeachColors.Bg, ) val typography = androidx.compose.material3.Typography( bodyLarge = TextStyle( fontFamily = PeachType.Body, fontSize = 16.sp, fontWeight = FontWeight.Normal, ), titleLarge = TextStyle( fontFamily = PeachType.Display, fontSize = 24.sp, fontStyle = FontStyle.Italic, fontWeight = FontWeight.Light, ), labelLarge = TextStyle( fontFamily = PeachType.Body, fontSize = 12.sp, fontWeight = FontWeight.Medium, ), ) CompositionLocalProvider( LocalDensity provides scaledDensity, LocalPeachAccent provides accent, LocalReduceMotion provides reduceMotion, LocalPeachColors provides peachDark(accent), ) { MaterialTheme(colorScheme = colors, typography = typography, content = content) } }