<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>https://wiki-data.rcsi.science/index.php?action=history&amp;feed=atom&amp;title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%3AColor_contrast</id>
	<title>Модуль:Color contrast - История изменений</title>
	<link rel="self" type="application/atom+xml" href="https://wiki-data.rcsi.science/index.php?action=history&amp;feed=atom&amp;title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%3AColor_contrast"/>
	<link rel="alternate" type="text/html" href="https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Color_contrast&amp;action=history"/>
	<updated>2026-04-03T20:57:16Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Color_contrast&amp;diff=738&amp;oldid=prev</id>
		<title>Admin: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Color_contrast&amp;diff=738&amp;oldid=prev"/>
		<updated>2021-11-15T13:18:34Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия 13:18, 15 ноября 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Color_contrast&amp;diff=737&amp;oldid=prev</id>
		<title>ru&gt;Johnuniq: fix unintended color2lum global error which is causing errors; clean whitespace</title>
		<link rel="alternate" type="text/html" href="https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Color_contrast&amp;diff=737&amp;oldid=prev"/>
		<updated>2019-01-06T22:38:25Z</updated>

		<summary type="html">&lt;p&gt;fix unintended color2lum global error which is causing errors; clean whitespace&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--&lt;br /&gt;
-- This module implements&lt;br /&gt;
--  {{Color contrast ratio}}&lt;br /&gt;
--  {{Greater color contrast ratio}}&lt;br /&gt;
--  {{ColorToLum}}&lt;br /&gt;
--  {{RGBColorToLum}}&lt;br /&gt;
--&lt;br /&gt;
local p = {}&lt;br /&gt;
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' )&lt;br /&gt;
&lt;br /&gt;
local function sRGB (v)&lt;br /&gt;
	if (v &amp;lt;= 0.03928) then&lt;br /&gt;
		v = v / 12.92&lt;br /&gt;
	else&lt;br /&gt;
		v = math.pow((v+0.055)/1.055, 2.4)&lt;br /&gt;
	end&lt;br /&gt;
	return v&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function rgbdec2lum(R, G, B)&lt;br /&gt;
	if ( 0 &amp;lt;= R and R &amp;lt; 256 and 0 &amp;lt;= G and G &amp;lt; 256 and 0 &amp;lt;= B and B &amp;lt; 256 ) then&lt;br /&gt;
		return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255)&lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function hsl2lum(h, s, l)&lt;br /&gt;
	if ( 0 &amp;lt;= h and h &amp;lt; 360 and 0 &amp;lt;= s and s &amp;lt;= 1 and 0 &amp;lt;= l and l &amp;lt;= 1 ) then&lt;br /&gt;
		local c = (1 - math.abs(2*l - 1))*s&lt;br /&gt;
		local x = c*(1 - math.abs( math.fmod(h/60, 2) - 1) )&lt;br /&gt;
		local m = l - c/2&lt;br /&gt;
&lt;br /&gt;
		local r, g, b = m, m, m&lt;br /&gt;
		if( 0 &amp;lt;= h and h &amp;lt; 60 ) then&lt;br /&gt;
			r = r + c&lt;br /&gt;
			g = g + x&lt;br /&gt;
		elseif( 60 &amp;lt;= h and h &amp;lt; 120 ) then&lt;br /&gt;
			r = r + x&lt;br /&gt;
			g = g + c&lt;br /&gt;
		elseif( 120 &amp;lt;= h and h &amp;lt; 180 ) then&lt;br /&gt;
			g = g + c&lt;br /&gt;
			b = b + x&lt;br /&gt;
		elseif( 180 &amp;lt;= h and h &amp;lt; 240 ) then&lt;br /&gt;
			g = g + x&lt;br /&gt;
			b = b + c&lt;br /&gt;
		elseif( 240 &amp;lt;= h and h &amp;lt; 300 ) then&lt;br /&gt;
			r = r + x&lt;br /&gt;
			b = b + c&lt;br /&gt;
		elseif( 300 &amp;lt;= h and h &amp;lt; 360 ) then&lt;br /&gt;
			r = r + c&lt;br /&gt;
			b = b + x&lt;br /&gt;
		end&lt;br /&gt;
		return rgbdec2lum(255*r, 255*g, 255*b)&lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function color2lum(c)&lt;br /&gt;
&lt;br /&gt;
	if (c == nil) then&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- html '#' entity&lt;br /&gt;
	c = c:gsub(&amp;quot;&amp;amp;#35;&amp;quot;, &amp;quot;#&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	-- whitespace&lt;br /&gt;
	c = c:match( '^%s*(.-)[%s;]*$' )&lt;br /&gt;
&lt;br /&gt;
	-- unstrip nowiki strip markers&lt;br /&gt;
	c = mw.text.unstripNoWiki(c)&lt;br /&gt;
&lt;br /&gt;
	-- lowercase&lt;br /&gt;
	c = c:lower()&lt;br /&gt;
&lt;br /&gt;
	-- first try to look it up&lt;br /&gt;
	local L = HTMLcolor[c]&lt;br /&gt;
	if (L ~= nil) then&lt;br /&gt;
		return L&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- convert from hsl&lt;br /&gt;
	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&lt;br /&gt;
		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]*%)$')&lt;br /&gt;
		return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- convert from rgb&lt;br /&gt;
	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&lt;br /&gt;
		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]*%)$')&lt;br /&gt;
		return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- convert from rgb percent&lt;br /&gt;
	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&lt;br /&gt;
		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]*%)$')&lt;br /&gt;
		return rgbdec2lum(255*tonumber(R)/100, 255*tonumber(G)/100, 255*tonumber(B)/100)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- remove leading # (if there is one) and whitespace&lt;br /&gt;
	c = mw.ustring.match(c, '^[%s#]*([a-f0-9]*)[%s]*$')&lt;br /&gt;
&lt;br /&gt;
	-- split into rgb&lt;br /&gt;
	local cs = mw.text.split(c or '', '')&lt;br /&gt;
	if( #cs == 6 ) then&lt;br /&gt;
		local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2])&lt;br /&gt;
		local G = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4])&lt;br /&gt;
		local B = 16*tonumber('0x' .. cs[5]) + tonumber('0x' .. cs[6])&lt;br /&gt;
&lt;br /&gt;
		return rgbdec2lum(R, G, B)&lt;br /&gt;
	elseif ( #cs == 3 ) then&lt;br /&gt;
		local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[1])&lt;br /&gt;
		local G = 16*tonumber('0x' .. cs[2]) + tonumber('0x' .. cs[2])&lt;br /&gt;
		local B = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[3])&lt;br /&gt;
&lt;br /&gt;
		return rgbdec2lum(R, G, B)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- failure, return blank&lt;br /&gt;
	return ''&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- This exports the function for use in other modules.&lt;br /&gt;
-- The colour is passed as a string.&lt;br /&gt;
function p._lum(color)&lt;br /&gt;
	return color2lum(color)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._greatercontrast(args)&lt;br /&gt;
	local bias = tonumber(args['bias'] or '0') or 0&lt;br /&gt;
	local css = (args['css'] and args['css'] ~= '') and true or false&lt;br /&gt;
	local v1 = color2lum(args[1] or '')&lt;br /&gt;
	local c2 = args[2] or '#FFFFFF'&lt;br /&gt;
	local v2 = color2lum(c2)&lt;br /&gt;
	local c3 = args[3] or '#000000'&lt;br /&gt;
	local v3 = color2lum(c3)&lt;br /&gt;
	local ratio1 = -1;&lt;br /&gt;
	local ratio2 = -1;&lt;br /&gt;
	if (type(v1) == 'number' and type(v2) == 'number') then&lt;br /&gt;
		ratio1 = (v2 + 0.05)/(v1 + 0.05)&lt;br /&gt;
		ratio1 = (ratio1 &amp;lt; 1) and 1/ratio1 or ratio1&lt;br /&gt;
	end&lt;br /&gt;
	if (type(v1) == 'number' and type(v3) == 'number') then&lt;br /&gt;
		ratio2 = (v3 + 0.05)/(v1 + 0.05)&lt;br /&gt;
		ratio2 = (ratio2 &amp;lt; 1) and 1/ratio2 or ratio2&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if css then&lt;br /&gt;
		local c1 = args[1] or ''&lt;br /&gt;
		if mw.ustring.match(c1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or&lt;br /&gt;
			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&lt;br /&gt;
				c1 = '#' .. c1&lt;br /&gt;
		end&lt;br /&gt;
		if mw.ustring.match(c2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or&lt;br /&gt;
			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&lt;br /&gt;
				c2 = '#' .. c2&lt;br /&gt;
		end&lt;br /&gt;
		if mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or&lt;br /&gt;
			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&lt;br /&gt;
				c3 = '#' .. c3&lt;br /&gt;
		end&lt;br /&gt;
		return 'background-color:' .. c1 .. '; color:' .. ((ratio1 &amp;gt; 0) and (ratio2 &amp;gt; 0) and ((ratio1 + bias &amp;gt; ratio2) and c2 or c3) or '') .. ';'&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return (ratio1 &amp;gt; 0) and (ratio2 &amp;gt; 0) and ((ratio1 + bias &amp;gt; ratio2) and c2 or c3) or ''&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._ratio(args)&lt;br /&gt;
	local v1 = color2lum(args[1])&lt;br /&gt;
	local v2 = color2lum(args[2])&lt;br /&gt;
	if (type(v1) == 'number' and type(v2) == 'number') then&lt;br /&gt;
		-- v1 should be the brighter of the two.&lt;br /&gt;
		if v2 &amp;gt; v1 then&lt;br /&gt;
			v1, v2 = v2, v1&lt;br /&gt;
		end&lt;br /&gt;
		return (v1 + 0.05)/(v2 + 0.05)&lt;br /&gt;
	else&lt;br /&gt;
		return args['error'] or '?'&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._styleratio(args)&lt;br /&gt;
	local style = (args[1] or ''):lower()&lt;br /&gt;
	local bg, fg = 'white', 'black'&lt;br /&gt;
	local lum_bg, lum_fg = 1, 0&lt;br /&gt;
&lt;br /&gt;
	if args[2] then&lt;br /&gt;
		local lum = color2lum(args[2])&lt;br /&gt;
		if lum ~= '' then bg, lum_bg = args[2], lum end&lt;br /&gt;
	end&lt;br /&gt;
	if args[3] then&lt;br /&gt;
		local lum = color2lum(args[3])&lt;br /&gt;
		if lum ~= '' then fg, lum_fg = args[3], lum end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local slist = mw.text.split(mw.ustring.gsub(mw.ustring.gsub(style or '', '&amp;amp;#[Xx]23;', '#'), '&amp;amp;#35;', '#'), ';')&lt;br /&gt;
	for k = 1,#slist do&lt;br /&gt;
		local s = slist[k]&lt;br /&gt;
		local k,v = s:match( '^[%s]*([^:]-):([^:]-)[%s;]*$' )&lt;br /&gt;
		k = k or ''&lt;br /&gt;
		v = v or ''&lt;br /&gt;
		if (k:match('^[%s]*(background)[%s]*$') or k:match('^[%s]*(background%-color)[%s]*$')) then&lt;br /&gt;
			local lum = color2lum(v)&lt;br /&gt;
			if( lum ~= '' ) then bg, lum_bg = v, lum end&lt;br /&gt;
		elseif (k:match('^[%s]*(color)[%s]*$')) then&lt;br /&gt;
			local lum = color2lum(v)&lt;br /&gt;
			if( lum ~= '' ) then bg, lum_fg = v, lum end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if lum_bg &amp;gt; lum_fg then&lt;br /&gt;
		return (lum_bg + 0.05)/(lum_fg + 0.05)&lt;br /&gt;
	else&lt;br /&gt;
		return (lum_fg + 0.05)/(lum_bg + 0.05)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Use {{#invoke:Color contrast|somecolor}} directly or&lt;br /&gt;
{{#invoke:Color contrast}} from a wrapper template.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
	-- |1=	— required; A color to check.&lt;br /&gt;
--]]&lt;br /&gt;
function p.lum(frame)&lt;br /&gt;
	local color = frame.args[1] or frame:getParent().args[1]&lt;br /&gt;
	return p._lum(color)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.ratio(frame)&lt;br /&gt;
	local args = frame.args[1] and frame.args or frame:getParent().args&lt;br /&gt;
	return p._ratio(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.styleratio(frame)&lt;br /&gt;
	local args = frame.args[1] and frame.args or frame:getParent().args&lt;br /&gt;
	return p._styleratio(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.greatercontrast(frame)&lt;br /&gt;
	local args = frame.args[1] and frame.args or frame:getParent().args&lt;br /&gt;
	return p._greatercontrast(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>ru&gt;Johnuniq</name></author>
	</entry>
</feed>