Mail dark: pagina #080b10 / card #2b3648 met subtiele rand alleen in de dark-regels; licht zonder rand; conversiesimulatie en kleurconflict-test
Continuous Integration / config (pull_request) Successful in 10s
Continuous Integration / changes (pull_request) Successful in 23s
Continuous Integration / config-asf (pull_request) Successful in 9s
Continuous Integration / backend-build (pull_request) Successful in 5m11s
Continuous Integration / vulnerability-scan (pull_request) Successful in 4m22s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m27s
Continuous Integration / backend-test (pull_request) Successful in 7m43s
Continuous Integration / frontend-build (pull_request) Successful in 2m3s
Continuous Integration / frontend-test (pull_request) Successful in 6m5s
Continuous Integration / frontend-lint (pull_request) Successful in 1m52s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 6m7s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / config (pull_request) Successful in 10s
Continuous Integration / changes (pull_request) Successful in 23s
Continuous Integration / config-asf (pull_request) Successful in 9s
Continuous Integration / backend-build (pull_request) Successful in 5m11s
Continuous Integration / vulnerability-scan (pull_request) Successful in 4m22s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m27s
Continuous Integration / backend-test (pull_request) Successful in 7m43s
Continuous Integration / frontend-build (pull_request) Successful in 2m3s
Continuous Integration / frontend-test (pull_request) Successful in 6m5s
Continuous Integration / frontend-lint (pull_request) Successful in 1m52s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 6m7s
Continuous Integration / deploy-test (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -197,15 +197,16 @@ public class MailTemplateRendererTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InDarkMode_TheCardStandsOutFromThePage_AndHasABorder()
|
||||
public void InDarkMode_TheCardStandsOutFromThePage_AndHasASubtleBorderOnlyInTheDarkRules()
|
||||
{
|
||||
var html = _renderer.Render(MailKind.Invitation, "nl", Model()).Html;
|
||||
|
||||
MailTemplateRenderer.DarkCard.Should().NotBe(MailTemplateRenderer.DarkPage);
|
||||
// clearly lighter than the page, not the near-identical shades it used to be
|
||||
MailColours.Contrast(MailTemplateRenderer.DarkCard, MailTemplateRenderer.DarkPage).Should().BeGreaterThanOrEqualTo(1.4);
|
||||
MailColours.Contrast(MailTemplateRenderer.DarkCard, MailTemplateRenderer.DarkPage).Should().BeGreaterThanOrEqualTo(1.6);
|
||||
html.Should().Contain($".mail-page{{background:{MailTemplateRenderer.DarkPage} !important;}}")
|
||||
.And.Contain($".mail-card{{background:{MailTemplateRenderer.DarkCard} !important;color:#f3f4f6 !important;border:1px solid #475569 !important;}}");
|
||||
.And.Contain($".mail-card{{background:{MailTemplateRenderer.DarkCard} !important;color:#f3f4f6 !important;border:1px solid {MailTemplateRenderer.DarkCardBorder} !important;}}");
|
||||
MailTemplateRenderer.DarkCardBorder.Should().Be("#394457");
|
||||
// light mode is untouched: white card on the light grey page
|
||||
html.Should().Contain("bgcolor=\"#f3f4f6\"").And.Contain("bgcolor=\"#ffffff\"");
|
||||
}
|
||||
@@ -270,16 +271,17 @@ public class MailTemplateRendererTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheCard_HasAnInlineBorder_ThatSurvivesClientsThatStripTheStyleBlock_AndOutlookHasItsOwnRules()
|
||||
public void LightMode_HasNoBorder_AndOutlookHasItsOwnDarkRules()
|
||||
{
|
||||
var html = _renderer.Render(MailKind.Invitation, "nl", Model()).Html;
|
||||
|
||||
// inline, so it also exists where <style> is removed (Gmail app on non-Gmail accounts) and a client's own
|
||||
// dark conversion still leaves an edge between card and page
|
||||
html.Should().MatchRegex("class=\"mail-card\"[^>]*border:1px solid #d1d5db;border-collapse:separate;");
|
||||
// the light card has no border of any kind (the border only appears in the dark rules)
|
||||
html.Should().NotContain("border:1px solid #d1d5db");
|
||||
var cardTag = System.Text.RegularExpressions.Regex.Match(html, "<table[^>]*class=\"mail-card\"[^>]*>").Value;
|
||||
cardTag.Should().NotContain("border:").And.Contain("border-collapse:separate").And.Contain("border-radius:8px");
|
||||
// Outlook.com / Outlook apps mark their dark mode with data-ogsb / data-ogsc, outside the media query
|
||||
html.Should().Contain($"[data-ogsb] .mail-page{{background-color:{MailTemplateRenderer.DarkPage} !important;}}")
|
||||
.And.Contain($"[data-ogsb] .mail-card{{background-color:{MailTemplateRenderer.DarkCard} !important;")
|
||||
.And.Contain($"[data-ogsb] .mail-card{{background-color:{MailTemplateRenderer.DarkCard} !important;border:1px solid {MailTemplateRenderer.DarkCardBorder} !important;}}")
|
||||
.And.Contain("[data-ogsc] .mail-card{color:#f3f4f6 !important;}");
|
||||
// the media query stays for the clients that do support it
|
||||
html.Should().Contain("@media (prefers-color-scheme: dark)");
|
||||
@@ -287,6 +289,70 @@ public class MailTemplateRendererTests
|
||||
html.Should().Contain("bgcolor=\"#f3f4f6\"").And.Contain("bgcolor=\"#ffffff\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ForAClientThatAppliesTheDarkRules_ThereIsNoColourClash_EveryLightTextColourHasADarkOverride()
|
||||
{
|
||||
// Thunderbird (and Apple Mail) apply prefers-color-scheme: dark. Text that keeps a fixed dark inline colour on the dark
|
||||
// card would be unreadable, so every element with an inline colour must carry a class the dark block overrides.
|
||||
var html = _renderer.Render(MailKind.Invitation, "nl", Model(name: "Bryan")).Html;
|
||||
var darkBlock = html[html.IndexOf("@media (prefers-color-scheme: dark){", StringComparison.Ordinal)..html.IndexOf("</style>", StringComparison.Ordinal)];
|
||||
|
||||
foreach (System.Text.RegularExpressions.Match tag in System.Text.RegularExpressions.Regex.Matches(html, "<(?<name>[a-z0-9]+)(?<attrs>[^>]*style=\"[^\"]*[^-]color:[^\"]*\"[^>]*)>"))
|
||||
{
|
||||
var attrs = tag.Groups["attrs"].Value;
|
||||
var classes = System.Text.RegularExpressions.Regex.Match(attrs, "class=\"(?<c>[^\"]*)\"").Groups["c"].Value
|
||||
.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
// the button link and the logo/site-name cells are handled by their own classes; the card itself by .mail-card
|
||||
var overridden = classes.Any(c => darkBlock.Contains("." + c + "{") || darkBlock.Contains("." + c + " a{"))
|
||||
|| (tag.Groups["name"].Value == "a" && darkBlock.Contains(".mail-btn a{")); // the button link, via its cell
|
||||
overridden.Should().BeTrue($"<{tag.Groups["name"].Value}{attrs}> keeps a fixed colour in dark mode");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClientConversionSimulation_DocumentsWhatSurvives_TheLightPairLosesItsDifferenceButTheDarkRulesKeepIt()
|
||||
{
|
||||
// A client that converts colours itself (Gmail app, non-Gmail account) ignores our dark rules. Model: invert the HSL
|
||||
// lightness of the inline light colours. It is an approximation, written down so nobody expects more of the
|
||||
// light pair; the real clients cannot be tested in code.
|
||||
static string Invert(string hex)
|
||||
{
|
||||
int R(int i) => Convert.ToInt32(hex.Substring(i, 2), 16);
|
||||
var (r, g, b) = (R(1) / 255.0, R(3) / 255.0, R(5) / 255.0);
|
||||
double max = Math.Max(r, Math.Max(g, b)), min = Math.Min(r, Math.Min(g, b)), l = (max + min) / 2, d = max - min;
|
||||
double h = 0, sat = 0;
|
||||
if (d > 0)
|
||||
{
|
||||
sat = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
||||
h = max == r ? ((g - b) / d + (g < b ? 6 : 0)) : max == g ? (b - r) / d + 2 : (r - g) / d + 4;
|
||||
h /= 6;
|
||||
}
|
||||
var l2 = 1 - l;
|
||||
double Hue(double p, double q, double t)
|
||||
{
|
||||
if (t < 0) t += 1; if (t > 1) t -= 1;
|
||||
return t < 1.0 / 6 ? p + (q - p) * 6 * t : t < 0.5 ? q : t < 2.0 / 3 ? p + (q - p) * (2.0 / 3 - t) * 6 : p;
|
||||
}
|
||||
double r2, g2, b2;
|
||||
if (sat == 0) r2 = g2 = b2 = l2;
|
||||
else
|
||||
{
|
||||
var q = l2 < 0.5 ? l2 * (1 + sat) : l2 + sat - l2 * sat;
|
||||
var p = 2 * l2 - q;
|
||||
r2 = Hue(p, q, h + 1.0 / 3); g2 = Hue(p, q, h); b2 = Hue(p, q, h - 1.0 / 3);
|
||||
}
|
||||
return $"#{(int)Math.Round(r2 * 255):x2}{(int)Math.Round(g2 * 255):x2}{(int)Math.Round(b2 * 255):x2}";
|
||||
}
|
||||
|
||||
var light = MailColours.Contrast("#f3f4f6", "#ffffff");
|
||||
var converted = MailColours.Contrast(Invert("#f3f4f6"), Invert("#ffffff"));
|
||||
var darkRules = MailColours.Contrast(MailTemplateRenderer.DarkCard, MailTemplateRenderer.DarkPage);
|
||||
|
||||
light.Should().BeApproximately(1.10, 0.02);
|
||||
converted.Should().BeLessThan(light); // ~1.06: the conversion removes the difference
|
||||
darkRules.Should().BeGreaterThan(light * 1.4); // 1.62: our own dark rules keep a clearly visible difference
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheCard_HasAGutterOnNarrowScreens_InlineOnTheOuterCell_SoThePageColourShowsAtTheSides()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user