Module:Card

require('Module:WikiLink') require('Module:CommonReplacements')

local p = {} local metahtml = getmetatable(mw.html.create).__index local params = { colBack = "#17111b"; colBorder = "#000000"; colLight = "#70547c"; cardHeight = 150; } function metahtml:_card(args) local size = tonumber(args.size:match'(%d+)') or 144 local box = self:tag('div') box:addClass('loliCard') :cssText('position:relative;display:inline-flex;flex-direction:column;margin-left:8px;margin-bottom:8px;font-size:15px;font-family:"Franklin Gothic";line-height:100%;padding-right:' .. tonumber((params.cardHeight / 2)+5) ..'px') box:tag('div'):addClass('card-left') :cssText('position:absolute;top:30px;left:5px;display:flex;flex-flow:column wrap') :wikitext(args.left) box:tag('div'):addClass('card-right') :cssText('position:absolute;top:30px;right:5px;display:flex;flex-flow:column wrap;align-items:flex-end') :wikitext(args.right)

box:tag('div'):addClass('card-rightSeries') :cssText(args.seriesLen .. 'box-sizing:border-box;padding: 0px 2px 0px 2px;display:flex;flex-direction:column;overflow:hidden;outline:2px solid' .. params.colBorder .. ';position:absolute;top:0%;right:0%;width:' .. tonumber((params.cardHeight / 2)+5) ..'px;height:50%; align-items:center;justify-content:center; text-align:center;background:' .. params.colBack .. ';color:#eee;') :wikitext(args.rightSeries)

box:tag('div'):addClass('card-rightName') :cssText(args.nameLen .. 'display:flex;overflow:hidden;outline:2px solid' .. params.colBorder .. ';position:absolute;top:50%;right:0%;width:' .. tonumber((params.cardHeight / 2)+5) ..'px;height:50%;align-items:center;justify-content:center;text-align:center;background:' .. params.colBack .. ';color:#eee;') :wikitext(args.rightName)

if args.bottom and args.bottom~='' then box:tag('div'):addClass('card-bottom') :cssText('outline:2px solid' .. params.colBorder .. ';text-align:center;color:#17111b;background:#eee;object-fit:cover;height:150px;width:105px;overflow:hidden;display:flex;align-items:center;justify-content:center') :wikitext(args.bottom) end return self end

function wikilink(strArg) local str = strArg mw.logObject(str) local table = strSplit(str,",\n") mw.logObject(table)

local res = "" local ind = table[1] local customLink = ind:match("%{.*%}") local wikiTerm = ind:match("%[.*%]") local indSub = ind:gsub("&#8203;", "") :gsub("&shy;", "") :gsub("&#8288;", "") :gsub("­","") :gsub(" - -","") :gsub(" - -","") :gsub(" -%(.*%) -","") local wikiString = " ".. commonReplacements(ind) .." " if (wikiTerm ~= nil) then mw.logObject("wikiterm: " .. wikiTerm) --indTemp = wikiTerm:gsub("[%[%]]","") --ind = ind:gsub(" ?%[.*%] ?","") wikiString = "wikipedia:".. wikiTerm:gsub("[%[%","") .."| ".. commonReplacements(ind):gsub(" ?%[.*%] ?","") .." ]]" elseif (customLink ~= nil) then mw.logObject("customLink: " .. customLink) ind = ind:gsub(" ?%{.*%} ?",""):gsub(" ?%[.*%] ?","") wikiString = " [".. customLink:gsub("[%{%}]","") .." ".. commonReplacements(ind):gsub("[%[%]]","") .." ] " end mw.logObject("wikistring: "..wikiString) res = res .. wikiString mw.logObject("res: "..res) return res end

function fontAdj(str) local str = str:gsub(" ?%{.*%} ?",""):gsub(" ?%(.*%) ?",""):gsub(" ?%[.*%] ?",""):gsub("&shy;",""):gsub("&#8203;","") local out = "" local strlength = string.len(str) local lenAdj = strlength - 30 if (lenAdj >= 0) then lenAdjTimes = math.floor(lenAdj / 10) adjSize = 15 - lenAdjTimes out = "line-height: 100%; font-size: " .. adjSize .. "px;" end return out end

function metahtml:Card(args, style) local arg2 = {} style = style or {} arg2.size = style.Size or '144px' arg2.rightSeries = wikilink(args.Series) arg2.seriesLen = fontAdj(strSplit(args.Series,",\n")[1]) arg2.rightName = ' '.. args.Name:gsub(" ?%(.*%) ?","") ..' ' arg2.nameLen = fontAdj(args.Name) arg2.right = args.Right~='' and args.Right or nil arg2.bottom = args.Image~='' and " " or "" return self:_card(arg2) end

function p.Card(args, style) return mw.html.create:Card(args, style) end