https://wiki.ahlolbait.com/index.php?title=%D9%BE%D9%88%D8%AF%D9%85%D8%A7%D9%86:Color_contrast&feed=atom&action=history
پودمان:Color contrast - تاریخچهٔ ویرایشها
2024-03-28T20:26:58Z
تاریخچهٔ ویرایشهای این صفحه در ویکی
MediaWiki 1.32.0
https://wiki.ahlolbait.com/index.php?title=%D9%BE%D9%88%D8%AF%D9%85%D8%A7%D9%86:Color_contrast&diff=105009&oldid=prev
Zamani: «پودمان:Color contrast» را محافظت کرد ([ویرایش=تنها مدیران] (بیپایان) [انتقال=تنها مدیران] (بیپایان))
2019-05-30T06:11:01Z
<p>«<a href="/%D9%BE%D9%88%D8%AF%D9%85%D8%A7%D9%86:Color_contrast" title="پودمان:Color contrast">پودمان:Color contrast</a>» را محافظت کرد ([ویرایش=تنها مدیران] (بیپایان) [انتقال=تنها مدیران] (بیپایان))</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr class="diff-title" lang="fa">
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">→ نسخهٔ قدیمیتر</td>
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">نسخهٔ ۳۰ مهٔ ۲۰۱۹، ساعت ۰۶:۱۱</td>
</tr><tr><td colspan="2" class="diff-notice" lang="fa"><div class="mw-diff-empty">(بدون تفاوت)</div>
</td></tr></table>
Zamani
https://wiki.ahlolbait.com/index.php?title=%D9%BE%D9%88%D8%AF%D9%85%D8%A7%D9%86:Color_contrast&diff=104685&oldid=prev
Zamani: صفحهای تازه حاوی «-- -- This module implements -- {{Color contrast ratio}} -- {{Greater color contrast ratio}} -- {{ColorToLum}} -- {{RGBColorToLum}} --...» ایجاد کرد
2019-05-26T10:31:03Z
<p>صفحهای تازه حاوی «-- -- This module implements -- {{Color contrast ratio}} -- {{Greater color contrast ratio}} -- {{ColorToLum}} -- {{RGBColorToLum}} --...» ایجاد کرد</p>
<p><b>صفحهٔ تازه</b></p><div>--<br />
-- This module implements <br />
-- {{Color contrast ratio}}<br />
-- {{Greater color contrast ratio}}<br />
-- {{ColorToLum}}<br />
-- {{RGBColorToLum}}<br />
--<br />
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 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 = 0;<br />
local ratio2 = 0;<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 />
return (ratio1 + bias > ratio2) and c2 or c3<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 />
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>
Zamani