From 91b36b9dde45b22ee0cd8aa78b5cff28328ca291 Mon Sep 17 00:00:00 2001 From: "d.a.kolesov" Date: Wed, 1 Apr 2026 14:17:10 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B1=D0=B5=D0=BB=D1=8B=D0=B9=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D1=82=20=D0=B8=20=D0=BF=D0=BE=D0=BF=D0=B0=D0=BF=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MessageBody: заменить DOMParser-подход на post-load fix через getComputedStyle — теперь ловятся CSS-классовые цвета, не только inline styles; effectiveBg обходит дерево вверх для поиска реального фона - MessageHeader: убрать backdrop-filter из попапа (не работает внутри блюренного родителя), заменить непрозрачным тёмным фоном rgb(18,18,30) + specular border Co-Authored-By: Claude Sonnet 4.6 --- .../src/components/preview/MessageBody.vue | 87 ++++++++----------- .../src/components/preview/MessageHeader.vue | 15 ++-- 2 files changed, 46 insertions(+), 56 deletions(-) diff --git a/src/renderer/src/components/preview/MessageBody.vue b/src/renderer/src/components/preview/MessageBody.vue index 1c05b03..0895a60 100644 --- a/src/renderer/src/components/preview/MessageBody.vue +++ b/src/renderer/src/components/preview/MessageBody.vue @@ -8,62 +8,53 @@ const props = defineProps<{ const iframeRef = ref(null) -// ── Исправление цветов HTML-писем ───────────────────────── -// Некоторые письма используют белый текст в секциях с белым фоном. -// Обходим DOM и убираем явный белый цвет текста там, где фон тоже светлый. +// ── Исправление цветов HTML-писем (после загрузки iframe) ─ +// postProcessHtml на DOMParser не видит CSS-классы. +// Правим ПОСЛЕ загрузки через getComputedStyle — он знает всё. -function isNearWhite(s: string): boolean { - s = s.trim().toLowerCase().replace(/\s+/g, '') - if (!s || s === 'transparent' || s === 'rgba(0,0,0,0)') return false - if (s === 'white' || s === '#fff' || s === '#ffffff') return true - const h6 = s.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) - if (h6) return parseInt(h6[1], 16) >= 200 && parseInt(h6[2], 16) >= 200 && parseInt(h6[3], 16) >= 200 - const h3 = s.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/) - if (h3) return parseInt(h3[1] + h3[1], 16) >= 200 && parseInt(h3[2] + h3[2], 16) >= 200 && parseInt(h3[3] + h3[3], 16) >= 200 - const rgb = s.match(/^rgb\((\d+),(\d+),(\d+)\)$/) - if (rgb) return +rgb[1] >= 200 && +rgb[2] >= 200 && +rgb[3] >= 200 - const rgba = s.match(/^rgba\((\d+),(\d+),(\d+),([\d.]+)\)$/) - if (rgba) return +rgba[1] >= 200 && +rgba[2] >= 200 && +rgba[3] >= 200 && +rgba[4] > 0.3 - return false +function rgbMatch(s: string): [number, number, number, number] | null { + const m = s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/) + if (!m) return null + return [+m[1], +m[2], +m[3], m[4] !== undefined ? parseFloat(m[4]) : 1] } -function getExplicitBg(el: HTMLElement): string { - return el.style.backgroundColor || el.style.background || el.getAttribute('bgcolor') || '' +function isNearWhiteRgb(r: number, g: number, b: number): boolean { + return r >= 200 && g >= 200 && b >= 200 } -function findNearestBg(el: HTMLElement): string { - let node: HTMLElement | null = el - while (node) { - const bg = getExplicitBg(node) - if (bg && bg !== 'transparent' && bg !== 'rgba(0, 0, 0, 0)' && bg !== 'rgba(0,0,0,0)') return bg - node = node.parentElement - } - return '' -} - -function postProcessHtml(html: string): string { +function fixIframeColors(): void { try { - const parser = new DOMParser() - const doc = parser.parseFromString(html, 'text/html') + const doc = iframeRef.value?.contentDocument + const view = iframeRef.value?.contentWindow + if (!doc?.body || !view) return - const candidates = doc.querySelectorAll('[style*="color"], [color], font[color]') - for (const el of candidates) { - const fg = el.style.color || el.getAttribute('color') || '' - if (!fg || !isNearWhite(fg)) continue - - // Белый текст — проверяем фон в контексте элемента - const bg = findNearestBg(el) - // Если фон тоже светлый или не задан (дефолт белый) → убираем белый цвет - if (!bg || isNearWhite(bg)) { - if (el.style.color) el.style.removeProperty('color') - el.removeAttribute('color') + // Для каждого элемента: если getComputedStyle говорит что цвет текста + // близок к белому — ищем эффективный фон вверх по дереву. + // Если фон тоже светлый или прозрачный (дефолт белый) → делаем текст тёмным. + function effectiveBg(el: HTMLElement): [number, number, number] | null { + let node: HTMLElement | null = el + while (node) { + const c = rgbMatch(view.getComputedStyle(node).backgroundColor) + if (c && c[3] > 0.05) return [c[0], c[1], c[2]] + node = node.parentElement } + return null } - return doc.documentElement.outerHTML - } catch { - return html - } + const all = doc.body.querySelectorAll('*') + for (const el of all) { + const fg = rgbMatch(view.getComputedStyle(el).color) + if (!fg || fg[3] < 0.3) continue + if (!isNearWhiteRgb(fg[0], fg[1], fg[2])) continue + + // Текст белый — проверяем эффективный фон + const bg = effectiveBg(el) + if (!bg || isNearWhiteRgb(bg[0], bg[1], bg[2])) { + // Белый на белом/прозрачном → тёмный текст + el.style.setProperty('color', 'rgba(20, 20, 30, 0.88)', 'important') + } + } + } catch { /* sandbox или cross-origin */ } } // ── Вычисленный HTML ─────────────────────────────────────── @@ -78,9 +69,6 @@ const processedHtml = computed(() => { html = html.replaceAll(`cid:${img.cid}`, `data:${img.contentType};base64,${img.data}`) } - // Фиксируем белый текст на белом фоне - html = postProcessHtml(html) - return ` @@ -204,6 +192,7 @@ const resizeObserver = new ResizeObserver(updateGlowPosition) function onIframeLoad(): void { updateGlowPosition() if (iframeRef.value) resizeObserver.observe(iframeRef.value) + fixIframeColors() try { const doc = iframeRef.value?.contentDocument const view = iframeRef.value?.contentWindow diff --git a/src/renderer/src/components/preview/MessageHeader.vue b/src/renderer/src/components/preview/MessageHeader.vue index 8ce6389..296fc64 100644 --- a/src/renderer/src/components/preview/MessageHeader.vue +++ b/src/renderer/src/components/preview/MessageHeader.vue @@ -290,16 +290,17 @@ onUnmounted(() => { .contact-popup { position: absolute; width: 272px; + /* Непрозрачный тёмный фон — backdrop-filter не работает внутри блюренного родителя */ background: - linear-gradient(135deg, rgba(255,255,255,0.10) 0%, rgba(255,255,255,0.05) 100%); - backdrop-filter: blur(32px) saturate(1.9); - -webkit-backdrop-filter: blur(32px) saturate(1.9); - border: 1px solid rgba(255, 255, 255, 0.14); + linear-gradient(135deg, rgba(255,255,255,0.07) 0%, rgba(255,255,255,0.02) 100%), + rgb(18, 18, 30); + border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 10px; box-shadow: - inset 0 1px 0 rgba(255, 255, 255, 0.18), - 0 8px 32px rgba(0, 0, 0, 0.40), - 0 2px 8px rgba(0, 0, 0, 0.25); + inset 0 1px 0 rgba(255, 255, 255, 0.22), + 0 0 0 1px rgba(0, 0, 0, 0.4), + 0 12px 40px rgba(0, 0, 0, 0.55), + 0 4px 12px rgba(0, 0, 0, 0.35); padding: 12px 14px; z-index: 100; }