| 1 | import defaultThemeVariables from "../../generated-uniwind-default-theme-variables.json"; |
| 2 | import { |
| 3 | DEFAULT_MOBILE_THEME_ID, |
| 4 | getMobileThemeVariables, |
| 5 | themeColorWithAlpha, |
| 6 | type MobileThemeAppearance, |
| 7 | type MobileThemeId, |
| 8 | type MobileThemeVariables, |
| 9 | } from "./mobileTheme"; |
| 10 | |
| 11 | const defaults = defaultThemeVariables as Readonly< |
| 12 | Record<MobileThemeAppearance, MobileThemeVariables> |
| 13 | >; |
| 14 | |
| 15 | /** |
| 16 | * Complete palette for native and third-party APIs that cannot consume a |
| 17 | * Uniwind className. Every palette shares the source that generates its |
| 18 | * registered CSS theme. |
| 19 | */ |
| 20 | export function getMobileThemeRuntimeVariables( |
| 21 | themeId: MobileThemeId, |
| 22 | appearance: MobileThemeAppearance, |
| 23 | platform: string, |
| 24 | ): MobileThemeVariables { |
| 25 | const usesDefaultPalette = themeId === DEFAULT_MOBILE_THEME_ID || themeId === "material-you"; |
| 26 | const variables = usesDefaultPalette |
| 27 | ? defaults[appearance] |
| 28 | : getMobileThemeVariables(themeId, appearance); |
| 29 | // Android's frame surrounds the sidebar and chat panes. Light iPad sidebars |
| 30 | // reuse that stronger tonal fill; dark sidebars retain the shared black pane |
| 31 | // beneath the near-black chat canvas. System colors replace these roles later. |
| 32 | const frame = themeColorWithAlpha( |
| 33 | variables[usesDefaultPalette ? "--color-row-hover" : "--color-drawer"], |
| 34 | 1, |
| 35 | ); |
| 36 | if (platform === "ios" && usesDefaultPalette && appearance === "light") { |
| 37 | return { |
| 38 | ...variables, |
| 39 | "--color-header": frame, |
| 40 | "--color-header-foreground": variables["--color-drawer-foreground"], |
| 41 | "--color-drawer": frame, |
| 42 | "--color-drawer-foreground-muted": variables["--color-foreground-muted"], |
| 43 | }; |
| 44 | } |
| 45 | if (platform !== "android") return variables; |
| 46 | |
| 47 | return { |
| 48 | ...variables, |
| 49 | "--color-header": frame, |
| 50 | "--color-header-foreground": variables["--color-drawer-foreground"], |
| 51 | "--color-drawer": variables["--color-screen"], |
| 52 | }; |
| 53 | } |