-- compute the contrast with white and black
local wcontrast = (1 + 0.05)/(lum + 0.05)
local bcontrast = (lum + 0.05)/(0 + 0.05)
-- select the text color with the best contrast
if( bcontrast > wcontrast + 1.25 ) then
fontcolor = '000000'
else
fontcolor = 'FFFFFF'
end
end  
-- finally build the style string
local
if (borderwidth > 0) then
-- use the primary as the if the is white or close to white
local bordercontrast = (1 + 0.05)/(color2lum(bordercolor) + 0.05)
if (bordercontrast < 1.25) then
bordercolor = background
local fontcontrast = (1 + 0.05)/(color2lum(colors[2] or 'FFFFFF') + 0.05)
if (fontcontrast < 1.25) then
fontcolor = colors[2] or 'FFFFFF'
end
end
style = style .. ' :' .. borderwidth .. 'px solid #' .. bordercolor .. ';'
style = style .. ' -: ; -: ;'
style = style .. ' box-shadow: inset 0 0 #FEFEFE, inset 0 - 0 #FEFEFE;'
end .. background .. ';color:#' .. fontcolor .. ';' .. style  
return style
end  
local function team_boxes(, team, order, sep)
local function colorbox( h )
local r = mw.html.create('')
r:tag('span')
:css('background-color', '#' .. (h or ''))
:css('', ' solid #000')
:wikitext('&nbsp;&nbsp;&nbsp;&nbsp;')
return tostring(r)
end  
local colors = get_colors(team, 'unknown')  
if type(colors) ~= 'table' then
return ''
end  
local colorboxes = {}
local colororder = {'1','2','3','4','5'}
local namecheck = 0
if order == '' then
order = colors['order'] or ''
namecheck = 1
end
if order ~= '' then
colororder = mw.text.split(order, '')
end
for k,v in pairs(colororder) do
local i = tonumber(v) or 0
if( namecheck == 0 or colors['name' .. i]) then
if colors[i] then
table.insert(colorboxes,colorbox(colors[i]))
end
end
end  
if (#colorboxes > 0) then
return table.concat(colorboxes, sep)
end  
return ''
end  
local function team_list(, team, num1, num2, num3, num4, num5, sep)
local function colorbox( h )
local r = mw.html.create('')
r:tag('span')
:css('background-color', '#' .. (h or ''))
:css('', ' solid #000')
:wikitext('&nbsp;&nbsp;&nbsp;&nbsp;')
return tostring(r)
end  
local colors = get_colors(team, 'unknown')  
if type(colors) ~= 'table' then
return ''
end  
local nums = {
tonumber(num1:match('[1-5]') or '0') or 0,
tonumber(num2:match('[1-5]') or '0') or 0,
tonumber(num3:match('[1-5]') or '0') or 0,
tonumber(num4:match('[1-5]') or '0') or 0,
tonumber(num5:match('[1-5]') or '0') or 0}  
local colorboxes = {}
local colornames = {}
local colororder = {'1','2','3','4','5'}
local order = colors['order'] or ''
if(order ~= '') then
colororder = mw.text.split(order, '')
end
for k,v in pairs(colororder) do
local i = tonumber(v) or 0
if ( nums[i] > 0 ) then
if( colors['name' .. nums[i]]) then
table.insert(colornames,colors['name' .. nums[i]])
table.insert(colorboxes,colorbox(colors[nums[i]] or ''))
end
end
end  
local res = ''
if (#colornames == 1) then
res = colornames[1]
elseif (#colornames == 2) then
res = colornames[1] .. '&nbsp;and&nbsp;' .. colornames[2]
elseif (#colornames > 2) then
res = colornames[1]
for i=2,#colornames do
if( i < #colornames ) then
res = res .. ',&nbsp;' .. colornames[i]
else
res = res .. ',&nbsp;and&nbsp;' .. colornames[i]
end
end
end  
if (colors['cite']) then
res = res .. :preprocess('')
end
if (colors['ref']) then
res = res .. '[' .. colors['ref'] .. ']'
end
if (colors['ref2']) then
res = res .. '[' .. colors['ref2'] .. ']'
end  
if (#colornames > 0) then
res = res .. sep
end  
if (#colorboxes > 0) then
res = res .. table.concat(colorboxes, '&nbsp;')
end  
return res
end  
local function team_check(team, unknown)
local colors = get_colors(team, unknown)
if type(colors) == 'table' then
return 'known'
else
return unknown
end
end  
function p.color
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_color(remove_sport(args[1] or *), args[2] or *, args[3] or '')
end  
function p.color1
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_color(remove_sport(args[1] or *), '1', *)
end  
function p.color32
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_color(remove_sport(args[1] or ''), '3', '2')
end  
function p.style1
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_style1(remove_sport(args[1] or *), args[*], args['color'])
end  
function p.style2
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_style2(remove_sport(args[1] or *), args[*], args['color'])
end  
function p.header1
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_header1(remove_sport(args[1] or *), args[*])
end  
function p.header2
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_header2(remove_sport(args[1] or ''))
end  
function p.tablehead1
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_table_head(args, remove_sport(args['team'] or ''), 'p')
end  
function p.tablehead2
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_table_head(args, remove_sport(args['team'] or ''), 's')
end  
function p.stripe1
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_stripe1(remove_sport(args[1] or *), args[*])
end  
function p.boxes
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_boxes(, remove_sport(args[1] or ''),
args['order'] or '', args['sep'] or '&nbsp;')
end  
function p.list
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_list(, remove_sport(args[1] or ''),
args[2] or '1', args[3] or '2', args[4] or '3', args[5] or '4', args[6] or '5', args['sep'] or '')
end  
function p.check
local args = (.args[1] ~= nil) and .args or :getParent.args
return team_check(remove_sport(args[1] or *), args[2] or *)
end  
function p.check_data
-- In a sandbox, preview
local results = {'Problems in Module:College color/data:'}
local function problems(msg)
if msg then
table.insert(results, msg)
elseif results[2] then
return table.concat(results, '\n*')
else
return 'No problems detected.'
end
end
local data = require(data_module)
local keys = {}
for k, _ in pairs(data) do
table.insert(keys, k)
end
table.sort(keys)
for _, key in ipairs(keys) do
local val = data[key]
if not (type(key) == 'string' and (type(val) == 'table' or type(val) == 'string')) then
problems('Invalid type for "' .. tostring(key) .. '"')
end
if type(val) == 'table' then
if not (2 <= #val and #val <= 4) then
problems('Invalid number of numbered parameters for "' .. tostring(key) .. '"')
end
for i, v in ipairs(val) do
if not tostring(v):match('^%x%x%x%x%x%x$') then
problems('Parameter [' .. i .. '] should be a 6-hex-digit color but is "' .. tostring(v) .. '" for "' .. tostring(key) .. '"')
end
end
for k, v in pairs(val) do
if type(k) == 'number' then
if not (1 <= k and k <= 4) then
problems('Invalid numbered parameter for "' .. tostring(key) .. '"')
end
elseif type(k) == 'string' then
if not (
k:match('^name[1-4]$') or
k:match('^cite2?$') or
k:match('^order$')
) then
problems('Unexpected key in table for "' .. tostring(key) .. '"')
end
else
problems('Invalid key type in table for "' .. tostring(key) .. '"')
end
end
elseif data[val] == nil then
problems('Undefined alias for "' .. tostring(key) .. '"')
elseif type(data[val]) ~= 'table' then
problems('Alias is not a table for "' .. tostring(key) .. '"')
end
end
return problems
end  
function p.testtable
local contrasttable_mod = require("Module:College color/contrast")
return contrasttable_mod._testtable(.args)
end  
return p