https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AColor_contrast
Modul:Color contrast - Versionsgeschichte
2025-06-07T14:17:03Z
Versionsgeschichte dieser Seite in Wikipedia
MediaWiki 1.45.0-wmf.4
https://de.wikipedia.org/w/index.php?title=Modul:Color_contrast&diff=175231250&oldid=prev
Abu-Dun: fix
2018-03-21T07:57:40Z
<p>fix</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="de">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Nächstältere Version</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Version vom 21. März 2018, 09:57 Uhr</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Zeile 1:</td>
<td colspan="2" class="diff-lineno">Zeile 1:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local p = {}</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local p = {}</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>local HTMLcolor = mw.loadData( '<del style="font-weight: bold; text-decoration: none;">Module</del>:Color contrast/colors' )</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>local HTMLcolor = mw.loadData( '<ins style="font-weight: bold; text-decoration: none;">Modul</ins>:Color contrast/colors' )</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local function sRGB ( v ) </div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local function sRGB ( v ) </div></td>
</tr>
</table>
Abu-Dun
https://de.wikipedia.org/w/index.php?title=Modul:Color_contrast&diff=175231177&oldid=prev
Abu-Dun: Für Wikipedia:WikiProjekt Vorlagen/Werkstatt#Vorlage:Zuschauerzahlen und Modul:Zuschauerzahlen
2018-03-21T07:53:43Z
<p>Für <a href="/wiki/Wikipedia:WikiProjekt_Vorlagen/Werkstatt#Vorlage:Zuschauerzahlen_und_Modul:Zuschauerzahlen" title="Wikipedia:WikiProjekt Vorlagen/Werkstatt">Wikipedia:WikiProjekt Vorlagen/Werkstatt#Vorlage:Zuschauerzahlen und Modul:Zuschauerzahlen</a></p>
<p><b>Neue Seite</b></p><div>local p = {}<br />
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' )<br />
<br />
local function sRGB ( v ) <br />
if (v <= 0.03928) then <br />
v = v / 12.92<br />
else<br />
v = math.pow((v+0.055)/1.055, 2.4)<br />
end<br />
return v<br />
end<br />
<br />
local function rgbdec2lum( R, G, B )<br />
if ( 0 <= R and R < 256 and 0 <= G and G < 256 and 0 <= B and B < 256 ) then<br />
return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255)<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
local function hsl2lum( h, s, l )<br />
if ( 0 <= h and h < 360 and 0 <= s and s <= 1 and 0 <= l and l <= 1 ) then<br />
local c = (1 - math.abs(2*l - 1))*s<br />
local x = c*(1 - math.abs( math.fmod(h/60, 2) - 1) )<br />
local m = l - c/2<br />
<br />
local r, g, b = m, m, m<br />
if( 0 <= h and h < 60 ) then<br />
r = r + c<br />
g = g + x<br />
elseif( 60 <= h and h < 120 ) then<br />
r = r + x<br />
g = g + c<br />
elseif( 120 <= h and h < 180 ) then<br />
g = g + c<br />
b = b + x<br />
elseif( 180 <= h and h < 240 ) then<br />
g = g + x<br />
b = b + c<br />
elseif( 240 <= h and h < 300 ) then<br />
r = r + x<br />
b = b + c<br />
elseif( 300 <= h and h < 360 ) then<br />
r = r + c<br />
b = b + x<br />
end<br />
return rgbdec2lum(255*r, 255*g, 255*b)<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
local function color2lum( c )<br />
<br />
if (c == nil) then<br />
return ''<br />
end<br />
-- whitespace<br />
c = c:match( '^%s*(.-)[%s;]*$' )<br />
<br />
-- unstrip nowiki strip markers<br />
c = mw.text.unstripNoWiki(c)<br />
<br />
-- lowercase<br />
c = c:lower()<br />
<br />
-- first try to look it up<br />
local L = HTMLcolor[c]<br />
if (L ~= nil) then<br />
return L<br />
end<br />
<br />
-- convert from hsl<br />
if mw.ustring.match(c,'^hsl%([%s]*[0-9][0-9%.]*[%s]*,[%s]*[0-9][0-9%.]*%%[%s]*,[%s]*[0-9][0-9%.]*%%[%s]*%)$') then<br />
local h, s, l = mw.ustring.match(c,'^hsl%([%s]*([0-9][0-9%.]*)[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*%)$')<br />
return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)<br />
end<br />
<br />
-- convert from rgb<br />
if mw.ustring.match(c,'^rgb%([%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*[%s]*%)$') then<br />
local R, G, B = mw.ustring.match(c,'^rgb%([%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*%)$')<br />
return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))<br />
end<br />
<br />
-- convert from rgb percent<br />
if mw.ustring.match(c,'^rgb%([%s]*[0-9][0-9%.]*%%[%s]*,[%s]*[0-9][0-9%.]*%%[%s]*,[%s]*[0-9][0-9%.]*%%[%s]*%)$') then<br />
local R, G, B = mw.ustring.match(c,'^rgb%([%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*%)$')<br />
return rgbdec2lum(255*tonumber(R)/100, 255*tonumber(G)/100, 255*tonumber(B)/100)<br />
end<br />
<br />
-- remove leading # (if there is one) and whitespace<br />
c = mw.ustring.match(c, '^[%s#]*([a-f0-9]*)[%s]*$')<br />
<br />
-- split into rgb<br />
local cs = mw.text.split(c or '', '')<br />
if( #cs == 6 ) then<br />
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2])<br />
local G = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4])<br />
local B = 16*tonumber('0x' .. cs[5]) + tonumber('0x' .. cs[6])<br />
<br />
return rgbdec2lum(R, G, B)<br />
elseif ( #cs == 3 ) then<br />
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[1])<br />
local G = 16*tonumber('0x' .. cs[2]) + tonumber('0x' .. cs[2])<br />
local B = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[3])<br />
<br />
return rgbdec2lum(R, G, B)<br />
end<br />
<br />
-- failure, return blank<br />
return ''<br />
end<br />
<br />
function p._greatercontrast(args)<br />
local bias = tonumber(args['bias'] or '0') or 0<br />
local css = (args['css'] and args['css'] ~= '') and true or false<br />
local v1 = color2lum(args[1] or '')<br />
local c2 = args[2] or '#FFFFFF'<br />
local v2 = color2lum(c2)<br />
local c3 = args[3] or '#000000'<br />
local v3 = color2lum(c3)<br />
local ratio1 = -1;<br />
local ratio2 = -1;<br />
if (type(v1) == 'number' and type(v2) == 'number') then<br />
ratio1 = (v2 + 0.05)/(v1 + 0.05)<br />
ratio1 = (ratio1 < 1) and 1/ratio1 or ratio1<br />
end<br />
if (type(v1) == 'number' and type(v3) == 'number') then<br />
ratio2 = (v3 + 0.05)/(v1 + 0.05)<br />
ratio2 = (ratio2 < 1) and 1/ratio2 or ratio2<br />
end<br />
<br />
if css then<br />
local c1 = args[1] or ''<br />
if mw.ustring.match(c1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or<br />
mw.ustring.match(c1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then<br />
c1 = '#' .. c1<br />
end<br />
if mw.ustring.match(c2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or<br />
mw.ustring.match(c2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then<br />
c2 = '#' .. c2<br />
end<br />
if mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or<br />
mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then<br />
c3 = '#' .. c3<br />
end<br />
return 'background-color:' .. c1 .. '; color:' .. ((ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or '') .. ';'<br />
end<br />
<br />
return (ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or ''<br />
end<br />
<br />
function p._ratio(args)<br />
local v1 = color2lum(args[1])<br />
local v2 = color2lum(args[2])<br />
if (type(v1) == 'number' and type(v2) == 'number') then<br />
-- v1 should be the brighter of the two.<br />
if v2 > v1 then<br />
v1, v2 = v2, v1<br />
end<br />
return (v1 + 0.05)/(v2 + 0.05)<br />
else<br />
return args['error'] or '?'<br />
end<br />
end<br />
<br />
function p._styleratio(args)<br />
local style = (args[1] or ''):lower()<br />
local bg, fg = 'white', 'black'<br />
local lum_bg, lum_fg = 1, 0<br />
<br />
if args[2] then<br />
local lum = color2lum(args[2])<br />
if lum ~= '' then bg, lum_bg = args[2], lum end<br />
end<br />
if args[3] then<br />
local lum = color2lum(args[3])<br />
if lum ~= '' then fg, lum_fg = args[3], lum end<br />
end<br />
<br />
local slist = mw.text.split(mw.ustring.gsub(mw.ustring.gsub(style or '', '&#[Xx]23;', '#'), '&#35;', '#'), ';')<br />
for k = 1,#slist do<br />
local s = slist[k]<br />
local k,v = s:match( '^[%s]*([^:]-):([^:]-)[%s;]*$' )<br />
k = k or ''<br />
v = v or ''<br />
if (k:match('^[%s]*(background)[%s]*$') or k:match('^[%s]*(background%-color)[%s]*$')) then<br />
local lum = color2lum(v)<br />
if( lum ~= '' ) then bg, lum_bg = v, lum end<br />
elseif (k:match('^[%s]*(color)[%s]*$')) then<br />
local lum = color2lum(v)<br />
if( lum ~= '' ) then bg, lum_fg = v, lum end<br />
end<br />
end<br />
if lum_bg > lum_fg then<br />
return (lum_bg + 0.05)/(lum_fg + 0.05)<br />
else<br />
return (lum_fg + 0.05)/(lum_bg + 0.05)<br />
end<br />
end<br />
<br />
function p.lum(frame)<br />
return color2lum(frame.args[1] or frame:getParent().args[1])<br />
end<br />
<br />
function p.ratio(frame)<br />
local args = frame.args[1] and frame.args or frame:getParent().args<br />
return p._ratio(args)<br />
end<br />
<br />
function p.styleratio(frame)<br />
local args = frame.args[1] and frame.args or frame:getParent().args<br />
return p._styleratio(args)<br />
end<br />
<br />
function p.greatercontrast(frame)<br />
local args = frame.args[1] and frame.args or frame:getParent().args<br />
return p._greatercontrast(args)<br />
end<br />
<br />
return p</div>
Abu-Dun