Исправить белый текст и попап контакта
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
595d6c9c6a
commit
91b36b9dde
2 changed files with 46 additions and 56 deletions
|
|
@ -8,62 +8,53 @@ const props = defineProps<{
|
|||
|
||||
const iframeRef = ref<HTMLIFrameElement | null>(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<HTMLElement>('[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<HTMLElement>('*')
|
||||
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 `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue