Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions apps/web/src/themePalette.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,26 @@ describe("standard painted theme colors", () => {
it("match the chip surfaces index.css paints", () => {
const root = document.documentElement;
try {
for (const redesign of [false, true, false]) {
root.toggleAttribute("data-redesign", redesign);
for (const appearance of ["light", "dark"] as const) {
root.classList.toggle("dark", appearance === "dark");
const colors = getStandardPaintedThemeColors(appearance, redesign);
const canvas = paintedChannels("--background");
for (const [variable, role] of [
["--background", "canvas"],
["--card", "surface"],
["--surface-raised", "surfaceRaised"],
["--message-surface", "messageSurface"],
] as const) {
const expected = toRgb(colors[role])!;
const painted = paintedChannels(variable, canvas);
[expected.r, expected.g, expected.b].forEach((channel, index) => {
expect(
Math.abs(channel * 255 - painted[index]!),
`${appearance} ${role}`,
).toBeLessThan(1.5);
});
}
for (const appearance of ["light", "dark"] as const) {
root.classList.toggle("dark", appearance === "dark");
const colors = getStandardPaintedThemeColors(appearance);
const canvas = paintedChannels("--background");
for (const [variable, role] of [
["--background", "canvas"],
["--card", "surface"],
["--surface-raised", "surfaceRaised"],
["--message-surface", "messageSurface"],
] as const) {
const expected = toRgb(colors[role])!;
const painted = paintedChannels(variable, canvas);
[expected.r, expected.g, expected.b].forEach((channel, index) => {
expect(Math.abs(channel * 255 - painted[index]!), `${appearance} ${role}`).toBeLessThan(
1.5,
);
});
}
}
} finally {
root.removeAttribute("data-redesign");
root.classList.remove("dark");
}
});
Expand Down
16 changes: 4 additions & 12 deletions apps/web/src/themePalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,12 @@ export function getStandardThemeColors(appearance: ThemeAppearance): ThemeColors
// index.css paints the light bubble a step darker than the shared palette mobile uses.
const STANDARD_WEB_PAINTED_COLORS: Record<ThemeAppearance, Partial<ThemeColors>> = {
light: { messageSurface: "#ebebed" },
dark: {},
dark: { canvas: "#000000", messageSurface: "#1e1e1e" },
};

/** The standard theme as index.css paints it, for solves that measure the page. */
export function getStandardPaintedThemeColors(
appearance: ThemeAppearance,
redesign = false,
): ThemeColors {
return {
...getStandardThemeColors(appearance),
...STANDARD_WEB_PAINTED_COLORS[appearance],
...(redesign && appearance === "dark" ? { canvas: "#000000", messageSurface: "#1e1e1e" } : {}),
};
export function getStandardPaintedThemeColors(appearance: ThemeAppearance): ThemeColors {
return { ...getStandardThemeColors(appearance), ...STANDARD_WEB_PAINTED_COLORS[appearance] };
}

type ThemeRgbColor = {
Expand Down Expand Up @@ -1636,8 +1629,7 @@ export function applyThemePalette(theme: ThemePreference, appearance?: ThemeAppe
for (const variable of Object.values(APP_THEME_VARIABLES)) {
root.style.removeProperty(variable);
}
// The redesign's lighter dark bubble is the stricter surface, so this ink also covers legacy UI.
applyContextChipVariables(root, getStandardPaintedThemeColors(appearance ?? "light", true));
applyContextChipVariables(root, getStandardPaintedThemeColors(appearance ?? "light"));
}

export function resolveThemeAppearance(
Expand Down
Loading