local p = {}
local getArgs = require('Module:Arguments').getArgs
local function isNonEmpty(val)
return val and val ~= ''
end
function p._main(args, frame)
local size = tonumber(args.iw) or (args.text and 30 or 40)
local link = args.l or
(isNonEmpty(args[1]) and args[1]) or
(isNonEmpty(args[2]) and args[2]) or ''
local nameText = (isNonEmpty(args[1]) and args[1]) or
(isNonEmpty(args[2]) and args[2]) or ''
local containerStyle = string.format(
'display:inline-block;width:%dpx;height:%dpx;overflow:hidden;',
size, size
)
if args.text then
containerStyle = containerStyle .. string.format(
'background:%s;border-radius:50%%;vertical-align:middle;',
args.k or '#fff'
)
end
local h = tonumber(args.h) or 1
local n = tonumber(args.n) or 1
local marginTop = (size + 2) * (1 - h) - 1
local marginLeft = (size + 2) * (1 - n) - 1
local innerStyle = string.format(
'display:block;pointer-events:none;margin-top:%dpx;margin-left:%dpx;',
marginTop, marginLeft
)
local imgSrc = args.i and '{{filepath:'..args.i..'}}' or '{{彩虹社/sprite}}'
local scale = tonumber(args.c) or (args.i and 1 or 13)
local imgWidth = (size + 2) * scale
local imgTag = string.format(
'<img src="%s" width="%d">',
imgSrc, imgWidth
)
local avatar = string.format(
'<span class="image-clip" style="%s">' ..
'<span style="%s">%s</span>' ..
'</span>',
containerStyle, innerStyle, imgTag
)
local linkedAvatar = string.format('[[%s|%s]]', link, avatar)
if args.text == 'name' then
return linkedAvatar .. ' ' .. string.format('[[%s|%s]]', link, nameText)
end
return linkedAvatar
end
function p.main(frame)
local args = getArgs(frame, {
parentFirst = true,
removeBlanks = false
})
return frame:preprocess(p._main(args, frame))
end
return p