查看“︁Module:Lyrics/colors”︁的源代码
←
Module:Lyrics/colors
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local module = {} local getArgs = require('Module:Arguments').getArgs local rainbow = require('Module:rainbow')._main local genCharaBlock = require('Module:Lyrics/colors/sub')._charaBlock local buildLyrics = require('Module:Lyrics')._lyrics local initHandler = require('Module:HooksHandler').init local str_gsub = string.gsub local str_find = string.find function module.parseArgs(colorsStr, charasStr, charaBlock) local colors = mw.text.split(str_gsub(colorsStr, ';+$', ''), '%s*;+%s*') local aliases = {} for idx, val in ipairs(colors) do if str_find(val, '=', 1, true) then colors[idx], aliases[idx] = string.match(val, '^%s*([^=]+)%f[%s=]%s*=%s*(.+)%f[%s%z]%s*$') end end local charas = mw.text.split(mw.ustring.gsub(charasStr, ';+$', ''), '%s*;+%s*') for idx, val in ipairs(charas) do if charaBlock then charas[idx] = str_gsub(val, '%(.+%)', '') end end local map_aliases = {} for idx, val in pairs(aliases) do map_aliases[val] = idx end for idx, val in pairs(charas) do map_aliases[val] = idx end return colors, map_aliases, charas end function module.parse(colors, charas, chorusName, sentence) local count_colors = #colors -- 包裹节点 local chorus = '合唱' if #charas > count_colors then chorus = charas[#charas] end if chorusName ~='' then chorus = chorusName end for i=1, #sentence do local preParsed = str_gsub(sentence[i], '(@%d%d?)([^@\n]+)\n-', function(m1, m2) if m1:len() > 2 and tonumber(m1:sub(2)) > count_colors then m1 = m1:sub(1, 2) m2 = m1:sub(3) .. m2 end return string.format('<*span title="%s" style="color:%s">%s<*/span>', m1, m1, m2) end) if str_find(sentence[i], '^@d+.-@.') or str_find(sentence[i], '^[^@]') then preParsed = '<span class="NoTitlebox" title="'..chorus..'">'..preParsed..'</span>' end sentence[i] = preParsed end local mode = { lg = 'linear', rg = 'radial', rlg = 'repeating-linear', rrg = 'repeating-radial', rb = 'linear' } local special_color = {} for idx, val in ipairs(colors) do local match = val:match('^([lrc][lr]?[gbo])%(', 1) if match and (mode[match] or match == 'co') then special_color[idx] = match end end for i, material in ipairs(sentence) do local need_special = {} material = str_gsub(material, 'color:@(%d+)', function (m) m = tonumber(m) if special_color[m] then need_special[special_color[m]] = true end return 'color:' .. (colors[m] or '') end) material = str_gsub(material, 'title="@(%d+)"', function (m) m = tonumber(m) return charas[m] and ('title="' .. charas[m] ..'"') or '' end) -- 渐变色实现 for k, _ in pairs(need_special) do v = mode[k] if v then material = str_gsub(material, '<%*span ([^>]-)style="color:'..k..'(%(.-%))">(.-)<%*/span>', function(s1, s2, s3) if k == 'rb' then local pattern = '' s2 = str_gsub(s2, '%((.+)%)', '%1') local colors = mw.text.split(s2, ',', true) local quotient = 100 / #colors for i, v in ipairs(colors) do local color = mw.text.trim(v) if i == 1 then pattern = color..' '..quotient..'%' else pattern = pattern..', '..color..' '..(quotient * (i - 1))..'%'..', '..color..' '..(quotient * i)..'%' end end s2 = '('..pattern..')' end local style = 'background:-webkit-'..v..'-gradient'..s2..';-webkit-background-clip:text;-webkit-text-fill-color:transparent;-webkit-box-decoration-break:clone;' --[[ s3 = str_gsub(s3, '<rt%s*([^>]-)%s*>', function(s) if s ~= '' then local before, attr, after = string.match(s, '^(.-style=")([^"]*)(".*)$') if attr ~= nil and mw.text.trim(attr) == '' then attr = nil end if attr ~= nil then s = before..attr..'; '..style..after else s = (before or s..' style="')..style..(after or '"') end else s = ' style="'..style..'"' end return '<rt '..s..'>' end) ]]-- -- 额外套一层span,以免影响titlebox return '<span '..s1..'><span class="Lyrics-gradient" style="'..style..'">'..s3..'</span></span>' end) end end -- 交替色实现 if need_special['co'] then material = str_gsub(material, '<%*span ([^>]-)style="color:co%((.-)%)">(.-)<%*/span>', function(s1, s2, s3) local colors = mw.text.split(s2, ',') for idx, val in ipairs(colors) do colors[idx] = mw.text.trim(val) end return '<span '..s1..'>'..rainbow(colors, s3)..'</span>' end) end -- 整理节点 sentence[i] = str_gsub(str_gsub(material, '<%*(/?span)', '<%1'), '@', '') end return sentence end local preSplit = function (original, translated, customArgs) local ce = {} local deal = function (text) text = str_gsub(text, '%$([%d%$%[@])', function(s) if not ce[s] then ce[s] = mw.getCurrentFrame():expandTemplate{ title = 'ce', args = {s} } end return ce[s] end) text = str_gsub(text, '@%[([^%[]-)%]', function(match) return '@' .. (customArgs.map_aliases[match] and customArgs.map_aliases[match] or '['..match..']') end) return text end return deal(original), deal(translated) end local preParse = function (original, translated, customArgs) original = module.parse(customArgs.colors, customArgs.charas, customArgs.chorusName, original) if customArgs.traColors and translated then translated = module.parse(customArgs.colors, customArgs.charas, customArgs.chorusName, translated) end end local preOutput = function (html, customArgs) if customArgs.doCharaBlock then html = '<p>' .. genCharaBlock(customArgs.genCharaBlock) .. '</p>' .. html end local css = mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'Template:LyricsKai/colors/styles.css' } } return css .. html end function module.initHooks(args, hooksHandler, customArgs) customArgs.traColors = (args.traColors or '') == 'on' customArgs.doCharaBlock = (args.charaBlock or '') == 'on' customArgs.chorusName = args.chorusName or '' customArgs.colors, customArgs.map_aliases, customArgs.charas = module.parseArgs(args.colors or '', args.charas or '', customArgs.doCharaBlock) customArgs.genCharaBlock = { colors = args.colors or '', charas = args.charas or '', groupName = args.groupName, groupColor = args.lstyle } return hooksHandler({ preSplit = preSplit, preParse = preParse, preOutput = preOutput }) end function module.main(frame) local args = getArgs(frame, { wrappers = 'Template:LyricsKai/colors' }) local hooksHandler, customArgs = initHandler(), {} local hookTrigger = module.initHooks(args, hooksHandler, customArgs) return buildLyrics(args, hookTrigger, customArgs) end return module
该页面使用的模板:
Module:Lyrics/colors/doc
(
查看源代码
)
返回
Module:Lyrics/colors
。
导航菜单
个人工具
创建账号
登录
命名空间
模块
讨论
English
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
特殊页面
工具
链入页面
相关更改
页面信息
批量上传文件
友情链接
VCPedia
其他相关站点
vocaloid中文歌詞wiki
UTAU中华组wiki
初音ミク Wiki
VOCALOID Wiki
Vocaloid Lyrics Wiki
Vocaloid Database