Welten: adaptive Abdunklung getrennt für oben (Banner+JETZT-Chips) und unten (Feature-Chips) — obere/untere Bildhälfte separat gemessen, SW v1131

This commit is contained in:
rene 2026-05-29 09:31:32 +02:00
parent ac5b26f767
commit cad34711b7
7 changed files with 57 additions and 43 deletions

View file

@ -3,7 +3,7 @@
Router, State-Management, Navigation, Initialisierung.
============================================================ */
const APP_VER = '1130'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VER = '1131'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt
window.APP_VER = APP_VER; // global verfügbar für andere Module (z.B. offline-indicator)
window.APP_VERSION = APP_VERSION;

View file

@ -981,7 +981,7 @@ window.Worlds = (() => {
}
let _bgUrl = null; // aktuell gesetztes Hintergrundbild
let _bgBrightness = null; // gemessene Roh-Helligkeit des Bildes (0255) für adaptive Abdunklung
let _bgBrightness = null; // { top, bottom } Roh-Helligkeit (0255) je Bildhälfte für adaptive Abdunklung
function _isDarkMode() {
const t = document.documentElement.getAttribute('data-theme');
@ -1025,37 +1025,49 @@ window.Worlds = (() => {
new MutationObserver(() => { _applyBgOrientation(); _applyAdaptiveDim(); })
.observe(document.documentElement, { attributeFilter: ['data-theme'] });
// Durchschnittliche Helligkeit (0255) eines geladenen Bildes via Mini-Canvas.
// Helligkeit (0255) der oberen und unteren Bildhälfte via Mini-Canvas.
// Oben = Begrüßungs-Banner + JETZT-Chip-Reihe, unten = Feature-Chips.
// Gibt null zurück bei CORS-Tainting oder Fehler (→ Fallback-Abdunklung).
function _measureBrightness(img) {
function _measureBrightnessRegions(img) {
try {
const c = document.createElement('canvas');
const w = c.width = 32, h = c.height = 32;
const ctx = c.getContext('2d', { willReadFrequently: true });
ctx.drawImage(img, 0, 0, w, h);
const data = ctx.getImageData(0, 0, w, h).data;
let sum = 0;
for (let i = 0; i < data.length; i += 4) {
sum += 0.299 * data[i] + 0.587 * data[i + 1] + 0.114 * data[i + 2];
const half = h / 2;
let sumTop = 0, sumBot = 0, nTop = 0, nBot = 0;
for (let y = 0; y < h; y++) {
for (let x = 0; x < w; x++) {
const i = (y * w + x) * 4;
const lum = 0.299 * data[i] + 0.587 * data[i + 1] + 0.114 * data[i + 2];
if (y < half) { sumTop += lum; nTop++; } else { sumBot += lum; nBot++; }
}
}
return sum / (data.length / 4);
return { top: sumTop / nTop, bottom: sumBot / nBot };
} catch { return null; }
}
// Setzt --wbg-dim adaptiv: helles Bild → mehr Abdunklung (Lesbarkeit),
// dunkles Bild → wenig. Im Dark Mode liegt zusätzlich ein 0.45-Overlay
// über dem Bild, daher wirkt es dort dunkler (effektive Helligkeit ↓).
// Helligkeit (0255) → Abdunklungs-Alpha. Im Dark Mode liegt zusätzlich
// ein 0.45-Overlay über dem Bild, daher wirkt es dort dunkler.
function _dimForBrightness(b) {
if (_isDarkMode()) b *= 0.55;
if (b <= 90) return 0.14;
if (b >= 190) return 0.48;
return 0.14 + (b - 90) / 100 * (0.48 - 0.14);
}
// Setzt --wbg-dim-top/-bottom adaptiv pro Bildbereich: heller Bereich →
// mehr Abdunklung (Lesbarkeit), dunkler → wenig.
function _applyAdaptiveDim() {
let b = _bgBrightness;
if (b == null) b = 110; // neutraler Default wenn Messung fehlschlug
if (_isDarkMode()) b *= 0.55; // 0.45-Bild-Overlay reduziert sichtbare Helligkeit
let dim;
if (b <= 90) dim = 0.14;
else if (b >= 190) dim = 0.48;
else dim = 0.14 + (b - 90) / 100 * (0.48 - 0.14);
const val = dim.toFixed(2);
const r = _bgBrightness || { top: 110, bottom: 110 };
const dimTop = _dimForBrightness(r.top).toFixed(2);
const dimBot = _dimForBrightness(r.bottom).toFixed(2);
['wp-jetzt', 'wp-hund', 'wp-welt'].forEach(id => {
document.getElementById(id)?.style.setProperty('--wbg-dim', val);
const el = document.getElementById(id);
if (!el) return;
el.style.setProperty('--wbg-dim-top', dimTop);
el.style.setProperty('--wbg-dim-bottom', dimBot);
});
}
@ -1068,7 +1080,7 @@ window.Worlds = (() => {
toLoad.onload = () => {
_hasBgPhoto = true;
_bgUrl = url;
_bgBrightness = _measureBrightness(toLoad);
_bgBrightness = _measureBrightnessRegions(toLoad);
_applyAdaptiveDim();
_applyBgOrientation();
const hint = document.getElementById('wh-photo-hint');
@ -1091,7 +1103,7 @@ window.Worlds = (() => {
} else {
_hasBgPhoto = false;
_bgUrl = null;
_bgBrightness = 20; // dunkler Fallback-Gradient → minimale Abdunklung
_bgBrightness = { top: 20, bottom: 20 }; // dunkler Fallback-Gradient → minimale Abdunklung
_applyAdaptiveDim();
track.style.backgroundImage = '';
ov.style.backgroundImage = 'linear-gradient(160deg,#1a1f35 0%,#16213e 33%,#1a2535 67%,#0f1921 100%)';