Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

style(email): Better background and theme handling (#1455)

Evan Hutnik83989511d493
diff --git a/js/app/packages/block-email/component/EmailMessageBody.tsx b/js/app/packages/block-email/component/EmailMessageBody.tsx
index df70d2ebd2..4661b09571 100644
--- a/js/app/packages/block-email/component/EmailMessageBody.tsx
+++ b/js/app/packages/block-email/component/EmailMessageBody.tsx
@@ -106,9 +106,8 @@ export function EmailMessageBody(props: EmailMessageBodyProps) {
// TODO it might be nice to do some additional checks here, e.g. check if this message was sent from a user that the user has sent a message to before.
const isPersonal = createMemo(() => {
return (
- (props.message.from?.email === userEmail() ||
- props.message.labels.some((l) => l.name === 'CATEGORY_PERSONAL')) &&
- !parsedBodyHtml()?.hasTable
+ props.message.from?.email === userEmail() ||
+ props.message.labels.some((l) => l.name === 'CATEGORY_PERSONAL')
);
});
diff --git a/js/app/packages/core/email/transform-email-colors.ts b/js/app/packages/core/email/transform-email-colors.ts
index 716b7a8087..e4f6f5ead3 100644
--- a/js/app/packages/core/email/transform-email-colors.ts
+++ b/js/app/packages/core/email/transform-email-colors.ts
@@ -18,6 +18,9 @@ export interface ThemeColorParams {
const CONTRAST_THRESHOLD = 0.5;
const EPSILON = 0.0001;
+// Chroma threshold for distinguishing grey-ish colors (e.g. #3c4043)
+// from intentionally chromatic colors (e.g. #1a73e8)
+const CHROMATIC_THRESHOLD = 0.04;
type RGBA = { r: number; g: number; b: number; a: number };
type OKLCH = { l: number; c: number; h: number; a?: number };
@@ -36,18 +39,18 @@ export function processEmailColors(root: Node, theme: ThemeColorParams) {
// if the text has a background color set, trust that the email sender's choices and don't change anything
if ((textNodeColor.bg?.a ?? 0) > 0) return;
if (!textNodeColor.fg) return;
- // if the text is inside an anchor tag, set the color to the accent ink color
- if (textNodeColor.insideAnchor) {
- setAnchorStyle(
- textNodeColor.node,
- 'color',
- `oklch(${accentL} ${accentC} ${accentH})`
- );
- setAnchorStyle(
- textNodeColor.node,
- 'text-decoration-color',
- `oklch(${accentL} ${accentC} ${accentH})`
- );
+ // if the text is inside an anchor tag with a chromatic color, use the accent color;
+ // grey/monochrome links fall through to normal text processing
+ if (
+ textNodeColor.insideAnchor &&
+ textNodeColor.fg.c > CHROMATIC_THRESHOLD
+ ) {
+ const accentColor = `oklch(${accentL} ${accentC} ${accentH})`;
+ setAnchorStyle(textNodeColor.node, 'color', accentColor);
+ setAnchorStyle(textNodeColor.node, 'text-decoration-color', accentColor);
+ // Also set color on the text node's parent to override intermediate elements
+ // (e.g. <a><font color="#000000">text</font></a>)
+ setNodeColor(textNodeColor.node, accentColor);
return;
}
@@ -87,7 +90,7 @@ export function processEmailColors(root: Node, theme: ThemeColorParams) {
function setNodeColor(node: Node, color: string) {
const parentElement = node.parentElement;
if (parentElement) {
- parentElement.style.color = color;
+ parentElement.style.setProperty('color', color, 'important');
}
}
@@ -95,7 +98,7 @@ function setAnchorStyle(node: Node, style: string, value: string) {
const parentElement = node.parentElement;
const anchorElement = parentElement?.closest('a');
if (anchorElement) {
- anchorElement.style.setProperty(style, value);
+ anchorElement.style.setProperty(style, value, 'important');
}
}
@@ -197,12 +200,24 @@ export function computeTextNodeColor(root: Node): TextNodeContrast[] {
const fg = cs.color.startsWith('rgb')
? normalizeRGBA(parseRGBA(cs.color))
: null;
- const bg = cs.backgroundColor.startsWith('rgb')
- ? normalizeRGBA(parseRGBA(cs.backgroundColor))
- : null;
+ // Walk up ancestors to find the effective background color,
+ // since background-color doesn't inherit in CSS
+ let bgRgba: RGBA | null = null;
+ let bgEl: Element | null = el;
+ while (bgEl && bgEl !== root) {
+ const bgCs = getComputedStyle(bgEl);
+ const parsed = bgCs.backgroundColor.startsWith('rgb')
+ ? normalizeRGBA(parseRGBA(bgCs.backgroundColor))
+ : null;
+ if (parsed && parsed.a > 0) {
+ bgRgba = parsed;
+ break;
+ }
+ bgEl = bgEl.parentElement;
+ }
if (fg) {
const fgOklch = rgbaToOklch(fg);
- const bgOklch = rgbaToOklch(bg);
+ const bgOklch = rgbaToOklch(bgRgba);
const insideAnchor = el.closest('a') !== null;
out.push({
text: n.textContent || '',