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( &#039;Module:Color contrast/colors&#039; )<br /> <br /> local function sRGB ( v ) <br /> if (v &lt;= 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 &lt;= R and R &lt; 256 and 0 &lt;= G and G &lt; 256 and 0 &lt;= B and B &lt; 256 ) then<br /> return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255)<br /> else<br /> return &#039;&#039;<br /> end<br /> end<br /> <br /> local function hsl2lum( h, s, l )<br /> if ( 0 &lt;= h and h &lt; 360 and 0 &lt;= s and s &lt;= 1 and 0 &lt;= l and l &lt;= 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 &lt;= h and h &lt; 60 ) then<br /> r = r + c<br /> g = g + x<br /> elseif( 60 &lt;= h and h &lt; 120 ) then<br /> r = r + x<br /> g = g + c<br /> elseif( 120 &lt;= h and h &lt; 180 ) then<br /> g = g + c<br /> b = b + x<br /> elseif( 180 &lt;= h and h &lt; 240 ) then<br /> g = g + x<br /> b = b + c<br /> elseif( 240 &lt;= h and h &lt; 300 ) then<br /> r = r + x<br /> b = b + c<br /> elseif( 300 &lt;= h and h &lt; 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 &#039;&#039;<br /> end<br /> end<br /> <br /> local function color2lum( c )<br /> <br /> if (c == nil) then<br /> return &#039;&#039;<br /> end<br /> -- whitespace<br /> c = c:match( &#039;^%s*(.-)[%s;]*$&#039; )<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,&#039;^hsl%([%s]*[0-9][0-9%.]*[%s]*,[%s]*[0-9][0-9%.]*%%[%s]*,[%s]*[0-9][0-9%.]*%%[%s]*%)$&#039;) then<br /> local h, s, l = mw.ustring.match(c,&#039;^hsl%([%s]*([0-9][0-9%.]*)[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*%)$&#039;)<br /> return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)<br /> end<br /> <br /> -- convert from rgb<br /> if mw.ustring.match(c,&#039;^rgb%([%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*[%s]*%)$&#039;) then<br /> local R, G, B = mw.ustring.match(c,&#039;^rgb%([%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*%)$&#039;)<br /> return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))<br /> end<br /> <br /> -- convert from rgb percent<br /> if mw.ustring.match(c,&#039;^rgb%([%s]*[0-9][0-9%.]*%%[%s]*,[%s]*[0-9][0-9%.]*%%[%s]*,[%s]*[0-9][0-9%.]*%%[%s]*%)$&#039;) then<br /> local R, G, B = mw.ustring.match(c,&#039;^rgb%([%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*%)$&#039;)<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, &#039;^[%s#]*([a-f0-9]*)[%s]*$&#039;)<br /> <br /> -- split into rgb<br /> local cs = mw.text.split(c or &#039;&#039;, &#039;&#039;)<br /> if( #cs == 6 ) then<br /> local R = 16*tonumber(&#039;0x&#039; .. cs[1]) + tonumber(&#039;0x&#039; .. cs[2])<br /> local G = 16*tonumber(&#039;0x&#039; .. cs[3]) + tonumber(&#039;0x&#039; .. cs[4])<br /> local B = 16*tonumber(&#039;0x&#039; .. cs[5]) + tonumber(&#039;0x&#039; .. cs[6])<br /> <br /> return rgbdec2lum(R, G, B)<br /> elseif ( #cs == 3 ) then<br /> local R = 16*tonumber(&#039;0x&#039; .. cs[1]) + tonumber(&#039;0x&#039; .. cs[1])<br /> local G = 16*tonumber(&#039;0x&#039; .. cs[2]) + tonumber(&#039;0x&#039; .. cs[2])<br /> local B = 16*tonumber(&#039;0x&#039; .. cs[3]) + tonumber(&#039;0x&#039; .. cs[3])<br /> <br /> return rgbdec2lum(R, G, B)<br /> end<br /> <br /> -- failure, return blank<br /> return &#039;&#039;<br /> end<br /> <br /> function p._greatercontrast(args)<br /> local bias = tonumber(args[&#039;bias&#039;] or &#039;0&#039;) or 0<br /> local css = (args[&#039;css&#039;] and args[&#039;css&#039;] ~= &#039;&#039;) and true or false<br /> local v1 = color2lum(args[1] or &#039;&#039;)<br /> local c2 = args[2] or &#039;#FFFFFF&#039;<br /> local v2 = color2lum(c2)<br /> local c3 = args[3] or &#039;#000000&#039;<br /> local v3 = color2lum(c3)<br /> local ratio1 = -1;<br /> local ratio2 = -1;<br /> if (type(v1) == &#039;number&#039; and type(v2) == &#039;number&#039;) then<br /> ratio1 = (v2 + 0.05)/(v1 + 0.05)<br /> ratio1 = (ratio1 &lt; 1) and 1/ratio1 or ratio1<br /> end<br /> if (type(v1) == &#039;number&#039; and type(v3) == &#039;number&#039;) then<br /> ratio2 = (v3 + 0.05)/(v1 + 0.05)<br /> ratio2 = (ratio2 &lt; 1) and 1/ratio2 or ratio2<br /> end<br /> <br /> if css then<br /> local c1 = args[1] or &#039;&#039;<br /> if mw.ustring.match(c1, &#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$&#039;) or<br /> mw.ustring.match(c1, &#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$&#039;) then<br /> c1 = &#039;#&#039; .. c1<br /> end<br /> if mw.ustring.match(c2, &#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$&#039;) or<br /> mw.ustring.match(c2, &#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$&#039;) then<br /> c2 = &#039;#&#039; .. c2<br /> end<br /> if mw.ustring.match(v3, &#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$&#039;) or<br /> mw.ustring.match(v3, &#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$&#039;) then<br /> c3 = &#039;#&#039; .. c3<br /> end<br /> return &#039;background-color:&#039; .. c1 .. &#039;; color:&#039; .. ((ratio1 &gt; 0) and (ratio2 &gt; 0) and ((ratio1 + bias &gt; ratio2) and c2 or c3) or &#039;&#039;) .. &#039;;&#039;<br /> end<br /> <br /> return (ratio1 &gt; 0) and (ratio2 &gt; 0) and ((ratio1 + bias &gt; ratio2) and c2 or c3) or &#039;&#039;<br /> end<br /> <br /> function p._ratio(args)<br /> local v1 = color2lum(args[1])<br /> local v2 = color2lum(args[2])<br /> if (type(v1) == &#039;number&#039; and type(v2) == &#039;number&#039;) then<br /> -- v1 should be the brighter of the two.<br /> if v2 &gt; v1 then<br /> v1, v2 = v2, v1<br /> end<br /> return (v1 + 0.05)/(v2 + 0.05)<br /> else<br /> return args[&#039;error&#039;] or &#039;?&#039;<br /> end<br /> end<br /> <br /> function p._styleratio(args)<br /> local style = (args[1] or &#039;&#039;):lower()<br /> local bg, fg = &#039;white&#039;, &#039;black&#039;<br /> local lum_bg, lum_fg = 1, 0<br /> <br /> if args[2] then<br /> local lum = color2lum(args[2])<br /> if lum ~= &#039;&#039; then bg, lum_bg = args[2], lum end<br /> end<br /> if args[3] then<br /> local lum = color2lum(args[3])<br /> if lum ~= &#039;&#039; 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 &#039;&#039;, &#039;&amp;#[Xx]23;&#039;, &#039;#&#039;), &#039;&amp;#35;&#039;, &#039;#&#039;), &#039;;&#039;)<br /> for k = 1,#slist do<br /> local s = slist[k]<br /> local k,v = s:match( &#039;^[%s]*([^:]-):([^:]-)[%s;]*$&#039; )<br /> k = k or &#039;&#039;<br /> v = v or &#039;&#039;<br /> if (k:match(&#039;^[%s]*(background)[%s]*$&#039;) or k:match(&#039;^[%s]*(background%-color)[%s]*$&#039;)) then<br /> local lum = color2lum(v)<br /> if( lum ~= &#039;&#039; ) then bg, lum_bg = v, lum end<br /> elseif (k:match(&#039;^[%s]*(color)[%s]*$&#039;)) then<br /> local lum = color2lum(v)<br /> if( lum ~= &#039;&#039; ) then bg, lum_fg = v, lum end<br /> end<br /> end<br /> if lum_bg &gt; 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