<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pt-BR">
	<id>https://wiki.tokusatsus.com/index.php?action=history&amp;feed=atom&amp;title=M%C3%B3dulo%3AColor_contrast</id>
	<title>Módulo:Color contrast - Histórico de revisão</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.tokusatsus.com/index.php?action=history&amp;feed=atom&amp;title=M%C3%B3dulo%3AColor_contrast"/>
	<link rel="alternate" type="text/html" href="https://wiki.tokusatsus.com/index.php?title=M%C3%B3dulo:Color_contrast&amp;action=history"/>
	<updated>2026-09-06T14:30:15Z</updated>
	<subtitle>Histórico de revisões para esta página neste wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.tokusatsus.com/index.php?title=M%C3%B3dulo:Color_contrast&amp;diff=6343&amp;oldid=prev</id>
		<title>Tavoraadmin: Importando predefinição/módulo da Wikipédia em português para manter layout</title>
		<link rel="alternate" type="text/html" href="https://wiki.tokusatsus.com/index.php?title=M%C3%B3dulo:Color_contrast&amp;diff=6343&amp;oldid=prev"/>
		<updated>2026-09-06T05:33:23Z</updated>

		<summary type="html">&lt;p&gt;Importando predefinição/módulo da Wikipédia em português para manter layout&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Página nova&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( &amp;#039;Módulo:Color contrast/colors&amp;#039; )&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 &amp;#039;&amp;#039;&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 &amp;#039;&amp;#039;&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 &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- html &amp;#039;#&amp;#039; 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( &amp;#039;^%s*(.-)[%s;]*$&amp;#039; )&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 / hsla (accepts comma or space delimiters)&lt;br /&gt;
	if mw.ustring.match(c,&amp;#039;^hsla?%([%s]*[0-9][0-9%.]*[%s]*[,%s][%s]*[0-9][0-9%.]*%%[%s]*[,%s][%s]*[0-9][0-9%.]*%%.*%)$&amp;#039;) then&lt;br /&gt;
		local h, s, l = mw.ustring.match(c,&amp;#039;^hsla?%([%s]*([0-9][0-9%.]*)[%s]*[,%s][%s]*([0-9][0-9%.]*)%%[%s]*[,%s][%s]*([0-9][0-9%.]*)%%.*%)$&amp;#039;)&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 / rgba (numeric values 0 to 255)&lt;br /&gt;
	if mw.ustring.match(c,&amp;#039;^rgba?%([%s]*[0-9][0-9]*[%s]*[,%s][%s]*[0-9][0-9]*[%s]*[,%s][%s]*[0-9][0-9]*.*%)$&amp;#039;) then&lt;br /&gt;
		local R, G, B = mw.ustring.match(c,&amp;#039;^rgba?%([%s]*([0-9][0-9]*)[%s]*[,%s][%s]*([0-9][0-9]*)[%s]*[,%s][%s]*([0-9][0-9]*).*%)$&amp;#039;)&lt;br /&gt;
		return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- convert from rgb / rgba percent&lt;br /&gt;
	if mw.ustring.match(c,&amp;#039;^rgba?%([%s]*[0-9][0-9%.]*%%[%s]*[,%s][%s]*[0-9][0-9%.]*%%[%s]*[,%s][%s]*[0-9][0-9%.]*%%.*%)$&amp;#039;) then&lt;br /&gt;
		local R, G, B = mw.ustring.match(c,&amp;#039;^rgba?%([%s]*([0-9][0-9%.]*)%%[%s]*[,%s][%s]*([0-9][0-9%.]*)%%[%s]*[,%s][%s]*([0-9][0-9%.]*)%%.*%)$&amp;#039;)&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, &amp;#039;^[%s#]*([a-f0-9]*)[%s]*$&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
	-- split into rgb&lt;br /&gt;
	local cs = mw.text.split(c or &amp;#039;&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
	if( #cs == 6 or #cs == 8 ) then -- Accepts 6 digits (#RRGGBB) or 8 digits (#RRGGBBAA)&lt;br /&gt;
		local R = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[1]) + tonumber(&amp;#039;0x&amp;#039; .. cs[2])&lt;br /&gt;
		local G = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[3]) + tonumber(&amp;#039;0x&amp;#039; .. cs[4])&lt;br /&gt;
		local B = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[5]) + tonumber(&amp;#039;0x&amp;#039; .. cs[6])&lt;br /&gt;
&lt;br /&gt;
		return rgbdec2lum(R, G, B)&lt;br /&gt;
	elseif ( #cs == 3 or #cs == 4 ) then -- Accepts 3 digits (#RGB) or 4 digits (#RGBA)&lt;br /&gt;
		local R = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[1]) + tonumber(&amp;#039;0x&amp;#039; .. cs[1])&lt;br /&gt;
		local G = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[2]) + tonumber(&amp;#039;0x&amp;#039; .. cs[2])&lt;br /&gt;
		local B = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[3]) + tonumber(&amp;#039;0x&amp;#039; .. 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 &amp;#039;&amp;#039;&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[&amp;#039;bias&amp;#039;] or &amp;#039;0&amp;#039;) or 0&lt;br /&gt;
	local css = (args[&amp;#039;css&amp;#039;] and args[&amp;#039;css&amp;#039;] ~= &amp;#039;&amp;#039;) and true or false&lt;br /&gt;
	local v1 = color2lum(args[1] or &amp;#039;&amp;#039;)&lt;br /&gt;
	local c2 = args[2] or &amp;#039;white&amp;#039;&lt;br /&gt;
	local v2 = color2lum(c2)&lt;br /&gt;
	local c3 = args[3] or &amp;#039;black&amp;#039;&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) == &amp;#039;number&amp;#039; and type(v2) == &amp;#039;number&amp;#039;) 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) == &amp;#039;number&amp;#039; and type(v3) == &amp;#039;number&amp;#039;) 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 &amp;#039;&amp;#039;&lt;br /&gt;
		if string.match(c1, &amp;#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?$&amp;#039;) or&lt;br /&gt;
			string.match(c1, &amp;#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][A-Fa-f0-9]?[A-Fa-f0-9]?$&amp;#039;) then&lt;br /&gt;
				c1 = &amp;#039;#&amp;#039; .. c1&lt;br /&gt;
		end&lt;br /&gt;
		if string.match(c2, &amp;#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?$&amp;#039;) or&lt;br /&gt;
			string.match(c2, &amp;#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][A-Fa-f0-9]?[A-Fa-f0-9]?$&amp;#039;) then&lt;br /&gt;
				c2 = &amp;#039;#&amp;#039; .. c2&lt;br /&gt;
		end&lt;br /&gt;
		if string.match(c3, &amp;#039;^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?$&amp;#039;) or&lt;br /&gt;
			string.match(c3, &amp;#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][A-Fa-f0-9]?[A-Fa-f0-9]?$&amp;#039;) then&lt;br /&gt;
				c3 = &amp;#039;#&amp;#039; .. c3&lt;br /&gt;
		end&lt;br /&gt;
		return &amp;#039;background-color:&amp;#039; .. c1 .. &amp;#039;; color:&amp;#039; .. ((ratio1 &amp;gt; 0) and (ratio2 &amp;gt; 0) and ((ratio1 + bias &amp;gt; ratio2) and c2 or c3) or &amp;#039;&amp;#039;) .. &amp;#039;;&amp;#039;&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 &amp;#039;&amp;#039;&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) == &amp;#039;number&amp;#039; and type(v2) == &amp;#039;number&amp;#039;) 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[&amp;#039;error&amp;#039;] or &amp;#039;?&amp;#039;&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 &amp;#039;&amp;#039;):lower()&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 ~= &amp;#039;&amp;#039; then lum_bg = 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 ~= &amp;#039;&amp;#039; then lum_fg = 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;#039;&amp;#039;, &amp;#039;&amp;amp;#[Xx]23;&amp;#039;, &amp;#039;#&amp;#039;), &amp;#039;&amp;amp;#35;&amp;#039;, &amp;#039;#&amp;#039;), &amp;#039;;&amp;#039;)&lt;br /&gt;
	for k = 1,#slist do&lt;br /&gt;
		local s = slist[k]&lt;br /&gt;
		local prop, val = s:match( &amp;#039;^[%s]*([^:]-):([^:]-)[%s;]*$&amp;#039; )&lt;br /&gt;
		prop = prop or &amp;#039;&amp;#039;&lt;br /&gt;
		val = val or &amp;#039;&amp;#039;&lt;br /&gt;
		if (prop:match(&amp;#039;^[%s]*(background)[%s]*$&amp;#039;) or prop:match(&amp;#039;^[%s]*(background%-color)[%s]*$&amp;#039;)) then&lt;br /&gt;
			local lum = color2lum(val)&lt;br /&gt;
			if( lum ~= &amp;#039;&amp;#039; ) then lum_bg = lum end&lt;br /&gt;
		elseif (prop:match(&amp;#039;^[%s]*(color)[%s]*$&amp;#039;)) then&lt;br /&gt;
			local lum = color2lum(val)&lt;br /&gt;
			if( lum ~= &amp;#039;&amp;#039; ) then lum_fg = 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>Tavoraadmin</name></author>
	</entry>
</feed>