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): Normalize font and spacing, remove text background (#1465)

Evan Hutnik552ca62fa76b
diff --git a/js/app/packages/block-email/component/EmailMessageBody.tsx b/js/app/packages/block-email/component/EmailMessageBody.tsx
index 4661b09571..57df803ce6 100644
--- a/js/app/packages/block-email/component/EmailMessageBody.tsx
+++ b/js/app/packages/block-email/component/EmailMessageBody.tsx
@@ -117,7 +117,11 @@ export function EmailMessageBody(props: EmailMessageBodyProps) {
const shadow = hostContainer.attachShadow({ mode: 'open' });
// Style that uses a CSS variable to control image visibility
const styleEl = document.createElement('style');
- styleEl.textContent = `img{display: var(--macro-email-img-display, initial); max-width: 100% !important; height: auto !important;}`;
+ // Normalize font in email
+ const fontOverride = isPersonal()
+ ? `*:not(code):not(pre):not(code *):not(pre *){font-family: system-ui, sans-serif !important; font-size: inherit !important; line-height: 1.5 !important;}`
+ : '';
+ styleEl.textContent = `img{display: var(--macro-email-img-display, initial); max-width: 100% !important; height: auto !important;}${fontOverride}`;
shadow.appendChild(styleEl);
const messageDiv = document.createElement('div');
messageDiv.innerHTML = source()?.mainContent ?? '';
@@ -166,7 +170,7 @@ export function EmailMessageBody(props: EmailMessageBodyProps) {
showFullHTML();
const root = host().shadowRoot;
if (root) {
- if (isPersonal()) {
+ if (isPersonal() || !source()?.hasTable) {
queueMicrotask(() => {
untrack(() => {
const theme: ThemeColorParams = {
@@ -181,7 +185,7 @@ export function EmailMessageBody(props: EmailMessageBodyProps) {
processEmailColors(root, theme);
});
});
- } else if (source()?.hasTable) {
+ } else {
const contentWrapper = root.querySelector('div');
if (contentWrapper instanceof HTMLElement) {
contentWrapper.style.setProperty(
diff --git a/js/app/packages/core/email/transform-email-colors.ts b/js/app/packages/core/email/transform-email-colors.ts
index e4f6f5ead3..15b7a6ee08 100644
--- a/js/app/packages/core/email/transform-email-colors.ts
+++ b/js/app/packages/core/email/transform-email-colors.ts
@@ -34,6 +34,7 @@ export function processEmailColors(root: Node, theme: ThemeColorParams) {
const { inkL, inkC, inkH, panelL, accentL, accentC, accentH } = theme;
const themeIsDarkModish = inkL > panelL;
+ stripContentBackgrounds(root);
const textNodeColors = computeTextNodeColor(root);
textNodeColors.forEach((textNodeColor) => {
// if the text has a background color set, trust that the email sender's choices and don't change anything
@@ -102,6 +103,35 @@ function setAnchorStyle(node: Node, style: string, value: string) {
}
}
+const LIGHT_BG_THRESHOLD = 0.85;
+
+/** Remove light/white backgrounds from all elements, preserving colored/dark backgrounds (buttons, banners).
+ * Uses getComputedStyle to resolve all color formats (named colors, hex, rgb, etc.) */
+function stripContentBackgrounds(root: Node) {
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
+ let el = walker.nextNode();
+ while (el) {
+ if (el instanceof HTMLElement) {
+ const bgColor = getComputedStyle(el).backgroundColor;
+ if (bgColor && bgColor.startsWith('rgb')) {
+ const rgba = normalizeRGBA(parseRGBA(bgColor));
+ if (rgba && rgba.a > 0) {
+ const oklch = rgbaToOklch(rgba);
+ if (oklch && oklch.l > LIGHT_BG_THRESHOLD) {
+ el.style.setProperty(
+ 'background-color',
+ 'transparent',
+ 'important'
+ );
+ el.removeAttribute('bgcolor');
+ }
+ }
+ }
+ }
+ el = walker.nextNode();
+ }
+}
+
export function rgbaToOklch(rgba: RGBA | null): OKLCH | null {
if (!rgba) return null;
const { r, g, b, a } = rgba;