diff --git a/public/pages/calendar.js b/public/pages/calendar.js index b022744..dc591b4 100644 --- a/public/pages/calendar.js +++ b/public/pages/calendar.js @@ -9,7 +9,7 @@ import { renderRRuleFields, bindRRuleEvents, getRRuleValues } from '/rrule-ui.js import { openModal as openSharedModal, closeModal, confirmModal } from '/components/modal.js'; import { stagger } from '/utils/ux.js'; import { t, formatTime } from '/i18n.js'; -import { esc } from '/utils/html.js'; +import { esc, fmtLocation } from '/utils/html.js'; import { refresh as refreshReminders } from '/reminders.js'; // -------------------------------------------------------- @@ -48,6 +48,22 @@ const EVENT_COLORS = [ const HOUR_HEIGHT = 56; // px pro Stunde in Wochen-/Tagesansicht +/** + * Gibt eine lesbare Textfarbe für eine Hintergrundfarbe zurück. + * Helle Hintergründe (z.B. Hellgelb, Hellgrün) → dunkles Grau statt Weiß. + */ +function getContrastColor(hex) { + if (!hex || hex.length < 7) return null; + try { + const r = parseInt(hex.slice(1, 3), 16) / 255; + const g = parseInt(hex.slice(3, 5), 16) / 255; + const b = parseInt(hex.slice(5, 7), 16) / 255; + const lin = (c) => c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); + const L = 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b); + return L > 0.30 ? '#3D3D3D' : null; // null → CSS-Standard (weiß) bleibt + } catch { return null; } +} + // -------------------------------------------------------- // State // -------------------------------------------------------- @@ -379,13 +395,17 @@ function renderMonthDay(date, inMonth) { const shown = evs.slice(0, MAX_SHOW); const extra = evs.length - MAX_SHOW; - const evHtml = shown.map((ev) => ` + const evHtml = shown.map((ev) => { + const bg = ev.cal_color || ev.color; + const fg = getContrastColor(bg); + return `