模組:Shuangpin
外观
function split(inputstr, sep)
if sep == nil then
return {inputstr}
end
local t = {}
local x = 1
local y = inputstr:find(sep)
while y ~= nil do
table.insert(t, inputstr:sub(x, y - 1))
x = y + 1
y = inputstr:find(sep, x)
end
table.insert(t, inputstr:sub(x))
return t
end
local latinss = { --
{'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'}, --
{'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';'}, --
{'Z', 'X', 'C', 'V', 'B', 'N', 'M'} --
}
local latinxy = {{
x = 30,
y = 30
}, {
x = 40,
y = 85
}, {
x = 68,
y = 140
}}
local latindata = {{}, {}, {}}
local divdata = {
w = 615,
h = 218
}
function buildkeyzone()
local ss = ''
for i, latins in ipairs(latinss) do
for j, latin in ipairs(latins) do
ss = ss .. '<div style="'
ss = ss .. 'left:' .. latinxy[i].x + (j - 1) * 55 .. 'px;'
ss = ss .. 'top:' .. latinxy[i].y .. 'px;'
ss = ss .. '">'
-- 美式鍵盤拉丁字母
ss = ss .. '<div>' .. latin .. '</div>'
-- 雙拼
local t = split(latindata[i][j]:gsub(' ', ''), ',')
ss = ss .. '<div>'
for k, v in ipairs(t) do
if v == '' then
v = ' '
end
ss = ss .. '<div>' .. v .. '</div>'
end
ss = ss .. '</div></div>'
end
end
return ss
end
function buildkey(name, width, height, amplification, align)
local ss = ''
ss = ss .. '<div class="' .. align .. ' shuangpin">'
ss = ss .. '<div style="'
ss = ss .. 'width:' .. width .. 'px;'
ss = ss .. 'height:' .. height .. 'px;'
ss = ss .. '"><div style="'
ss = ss .. 'left:' .. (divdata.w - width) / -2 .. 'px;'
ss = ss .. 'top:' .. (divdata.h - height) / -2 .. 'px;'
ss = ss .. 'transform:scale(' .. amplification .. ',' .. amplification .. ');'
ss = ss .. '">'
ss = ss .. buildkeyzone()
ss = ss .. '<div>' .. name .. '</div>'
ss = ss .. '</div></div></div>'
return ss
end
local p = {}
function p.keymain(frame)
local args = require('Module:Arguments').getArgs(frame)
local name = args.name or ''
local width
local height
local amplification
local align = args.align or 'tright'
if args.amplification ~= nil then
amplification = args.amplification
width = amplification * divdata.w
height = amplification * divdata.h
elseif args.width ~= nil then
width = args.width
amplification = width / divdata.w
height = amplification * divdata.h
elseif args.height ~= nil then
height = args.height
amplification = height / divdata.h
width = amplification * divdata.w
else
amplification = 1
width = divdata.w
height = divdata.h
end
for i, latins in ipairs(latinss) do
for j, latin in ipairs(latins) do
latindata[i][j] = args[latin] or ''
end
end
latindata[2][10] = args.semicolon or ''
return buildkey(name, width, height, amplification, align)
end
return p