Naar inhoud springen

Module:ColorBanner

Uit CostaSano-Wiki
Versie door Mngr (overleg | bijdragen) op 16 dec 2025 om 15:25 (Nieuwe pagina aangemaakt met '-- Module:ColorBanner local p = {} -- Helper: choose text color based on background brightness local function getTextColor(bg) -- crude luminance check: convert hex to RGB local r = tonumber(bg:sub(2,3),16) local g = tonumber(bg:sub(4,5),16) local b = tonumber(bg:sub(6,7),16) local luminance = (0.299*r + 0.587*g + 0.114*b) if luminance > 128 then return "#000000" -- dark text for light background else return "#FFFF…')
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)

Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:ColorBanner/doc

-- Module:ColorBanner
local p = {}

-- Helper: choose text color based on background brightness
local function getTextColor(bg)
    -- crude luminance check: convert hex to RGB
    local r = tonumber(bg:sub(2,3),16)
    local g = tonumber(bg:sub(4,5),16)
    local b = tonumber(bg:sub(6,7),16)
    local luminance = (0.299*r + 0.587*g + 0.114*b)

    if luminance > 128 then
        return "#000000" -- dark text for light background
    else
        return "#FFFFFF" -- white text for dark background
    end
end

function p.banner(frame)
    local args = frame:getParent().args
    local bg = args.bg or "#333333" -- default dark gray
    local fg = args.fg or getTextColor(bg)
    local text = args.text or "Example banner"

    return string.format(
        '<div style="background:%s; color:%s; padding:0.5em; text-align:center;">%s</div>',
        bg, fg, text
    )
end

return p