Open History to see the last commit
1import { HTML_RENDER_DEFAULT_FONTS, htmlRenderTheme } from "@t3tools/shared/htmlRender";
2
3import {
4 DEFAULT_MOBILE_THEME_ID,
5 getMobileThemeColors,
6 nativeColors,
7 type MobileThemeAppearance,
8 type MobileThemeId,
9 type MobileThemeVariables,
10} from "./mobileTheme";
11
12/**
13 * WebViews cannot load the app's bundled fonts, so renders use system stacks.
14 */
15export function mobileHtmlRenderTheme(input: {
16 readonly themeId: MobileThemeId;
17 readonly appearance: MobileThemeAppearance;
18 readonly variables: MobileThemeVariables;
19 readonly systemColors: boolean;
20 readonly platform: string;
21}) {
22 const { variables: v } = input;
23 const palette = getMobileThemeColors(
24 input.themeId === "material-you" ? DEFAULT_MOBILE_THEME_ID : input.themeId,
25 input.appearance,
26 );
27 const colors = nativeColors(
28 input.systemColors
29 ? {
30 ...palette,
31 text: v["--color-foreground"],
32 textMuted: v["--color-foreground-secondary"],
33 muted: v["--color-subtle"],
34 mutedForeground: v["--color-foreground-muted"],
35 surface: v["--color-card"],
36 surfaceRaised: v["--color-card-alt"],
37 surfaceOverlay: v["--color-card-alt"],
38 border: v["--color-border"],
39 input: v["--color-input-border"],
40 focus: v["--color-focus"],
41 accent: v["--color-primary"],
42 accentForeground: v["--color-primary-foreground"],
43 accentSurface: v["--color-inline-skill-background"],
44 accentSurfaceForeground: v["--color-inline-skill-foreground"],
45 messageAction: v["--color-primary"],
46 messageActionForeground: v["--color-primary-foreground"],
47 secondary: v["--color-secondary"],
48 secondaryForeground: v["--color-secondary-foreground"],
49 errorSurface: v["--color-danger"],
50 errorForeground: v["--color-danger-foreground"],
51 codeBackground: v["--color-md-code-bg"],
52 codeForeground: v["--color-md-code-text"],
53 }
54 : palette,
55 );
56 const canvas = v[input.platform === "android" ? "--color-thread-canvas" : "--color-screen"];
57 return htmlRenderTheme({ ...colors, canvas }, input.appearance, HTML_RENDER_DEFAULT_FONTS);
58}