Email for professionals and teams
Improve email color in dark/light mode
Hieu Nguyen (Jack)e7df653f39ef
diff --git a/src/app/(dashboard)/inbox/[messageId]/quote-collapse-utils.ts b/src/app/(dashboard)/inbox/[messageId]/quote-collapse-utils.tsindex e377c12..a63c1ae 100644--- a/src/app/(dashboard)/inbox/[messageId]/quote-collapse-utils.ts+++ b/src/app/(dashboard)/inbox/[messageId]/quote-collapse-utils.ts@@ -4,17 +4,20 @@ export function collapseQuotedEmailHtml(html: string | null, preserveLeadingQuottemplate.innerHTML = html;const document = { body: template.content, createElement: window.document.createElement.bind(window.document) };+ let skippedLeading = false;for (const blockquote of Array.from(document.body.querySelectorAll("blockquote"))) {const introduction = blockquote.previousElementSibling;if (!(introduction instanceof HTMLElement) ||!/^On\b[\s\S]*\bwrote:\s*$/i.test(introduction.textContent?.trim() ?? "")) continue;- if (- preserveLeadingQuote &&- introduction === document.body.firstElementChild &&- blockquote === introduction.nextElementSibling- ) continue;+ // The outer toggle already folded this quote, so its first attribution+ // stays open. It need not be the first element: sanitising can leave+ // a leading <br> or wrapper before it.+ if (preserveLeadingQuote && !skippedLeading) {+ skippedLeading = true;+ continue;+ }const details = document.createElement("details");details.className = "email-quote-toggle";diff --git a/src/components/messages/email-html-renderer.tsx b/src/components/messages/email-html-renderer.tsxindex 598f0d0..e89c3e1 100644--- a/src/components/messages/email-html-renderer.tsx+++ b/src/components/messages/email-html-renderer.tsx@@ -7,6 +7,8 @@ import { collapseQuotedEmailHtml } from "@/app/(dashboard)/inbox/[messageId]/quoconst BASE_STYLE = `:host { display:block; min-width:0; isolation:isolate; contain:paint; }+:host(.mf-dark) { filter:invert(1) hue-rotate(180deg); }+:host(.mf-dark) img, :host(.mf-dark) video, :host(.mf-dark) picture { filter:invert(1) hue-rotate(180deg); }.email-quote-toggle { margin-top:1.4em; }.email-quote-toggle > summary { cursor:pointer; list-style:none; width:26px; border-radius:20px; background:#ececec; text-align:center; }.email-quote-toggle > summary::-webkit-details-marker { display:none; }@@ -23,6 +25,16 @@ export function EmailHtmlRenderer({ html, className, preserveLeadingQuote = falsconst [allowedSource, setAllowedSource] = useState<string | null>(null);const [hasRemote, setHasRemote] = useState(false);const allowRemote = allowedSource === html;+ // Mail is authored for white paper. Under the dark theme it is inverted+ // (images inverted back) instead of glaring as a white slab.+ useEffect(() => {+ const root = document.documentElement;+ const sync = () => host.current?.classList.toggle("mf-dark", root.classList.contains("dark"));+ sync();+ const observer = new MutationObserver(sync);+ observer.observe(root, { attributes: true, attributeFilter: ["class"] });+ return () => observer.disconnect();+ }, []);useEffect(() => {if (!host.current) return;host.current.dir = document.documentElement.dir || "ltr";@@ -30,7 +42,7 @@ export function EmailHtmlRenderer({ html, className, preserveLeadingQuote = falsconst prepared = prepareEmailHtml(html, { reader: true, allowRemote });setHasRemote(prepared.hasRemote);const base = document.createElement("style");- base.textContent = `${BASE_STYLE}\n${prepared.rootTag} { display:block; font:14px/1.5 Arial,sans-serif; color:#202124; background:#fff; color-scheme:light; }\n${prepared.bodyTag} { display:block; }`;+ base.textContent = `${BASE_STYLE}\n${prepared.rootTag} { display:block; font:14px/1.5 Arial,sans-serif; color:#202124; background:#fff; color-scheme:light; }\n${prepared.bodyTag} { display:block; }\n:host(.mf-dark) ${prepared.rootTag} { background:transparent; }`;const content = document.createElement("template");content.innerHTML = collapseQuotedEmailHtml(prepared.html, preserveLeadingQuote, quoteToggleLabel) ?? "";root.replaceChildren(base, content.content);