Module:Stonecutting: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ||
-- main entry | -- main entry | ||
------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ||
function p.carousel(frame) | function p.carousel(frame) | ||
local args = getArgs(frame, {removeBlanks = false}) | |||
--─── STATIC SHEET ──────────────────────────────────────────────── | |||
-- pass nil, not '', or MW emits src="" and shows the warning | |||
outer:wikitext(frame:extensionTag( | |||
'templatestyles', -- name | |||
nil, -- no inline content | |||
{src = 'Stonecutting/styles.css'} -- external stylesheet page | |||
)) | |||
------------------------------------------------------------------ | |||
-- DYNAMIC SHEET: duration & delays | |||
------------------------------------------------------------------ | |||
local dur = count * 4 -- 4 s per recipe | |||
local pct = 100 / count | |||
local vis = pct - 0.01 -- stay visible *almost* to the slice end | |||
local css = {} | |||
-- every frame runs the same animation; | |||
-- *step-start* guarantees an instant flip with zero “off” gap | |||
css[#css+1] = string.format( | |||
'.stonecutting-carousel .sc-frame{animation:sc-cycle %ds step-start infinite;}', | |||
dur | |||
) | |||
-- individual start offsets | |||
for i = 1, count do | |||
css[#css+1] = string.format( | |||
'.stonecutting-carousel .sc-frame:nth-child(%d){animation-delay:%ds;}', | |||
i, (i - 1) * 4 | |||
) | |||
end | |||
-- keyframes: visible → invisible in the last 0.01 %% of the slice | |||
css[#css+1] = string.format( | |||
'@keyframes sc-cycle{0%%{opacity:1;} %.2f%%{opacity:1;} %.2f%%{opacity:0;} 100%%{opacity:0;}}', | |||
vis, pct | |||
) | |||
outer:wikitext(frame:extensionTag( | |||
'templatestyles', | |||
table.concat(css), -- inline CSS | |||
{lang = 'css'} | |||
)) | |||
return tostring(outer) | |||
end | end | ||
Revision as of 02:11, 14 June 2025
Documentation for this module may be created at Module:Stonecutting/doc
------------------------------------------------------------------------
-- main entry
------------------------------------------------------------------------
function p.carousel(frame)
local args = getArgs(frame, {removeBlanks = false})
--─── STATIC SHEET ────────────────────────────────────────────────
-- pass nil, not '', or MW emits src="" and shows the warning
outer:wikitext(frame:extensionTag(
'templatestyles', -- name
nil, -- no inline content
{src = 'Stonecutting/styles.css'} -- external stylesheet page
))
------------------------------------------------------------------
-- DYNAMIC SHEET: duration & delays
------------------------------------------------------------------
local dur = count * 4 -- 4 s per recipe
local pct = 100 / count
local vis = pct - 0.01 -- stay visible *almost* to the slice end
local css = {}
-- every frame runs the same animation;
-- *step-start* guarantees an instant flip with zero “off” gap
css[#css+1] = string.format(
'.stonecutting-carousel .sc-frame{animation:sc-cycle %ds step-start infinite;}',
dur
)
-- individual start offsets
for i = 1, count do
css[#css+1] = string.format(
'.stonecutting-carousel .sc-frame:nth-child(%d){animation-delay:%ds;}',
i, (i - 1) * 4
)
end
-- keyframes: visible → invisible in the last 0.01 %% of the slice
css[#css+1] = string.format(
'@keyframes sc-cycle{0%%{opacity:1;} %.2f%%{opacity:1;} %.2f%%{opacity:0;} 100%%{opacity:0;}}',
vis, pct
)
outer:wikitext(frame:extensionTag(
'templatestyles',
table.concat(css), -- inline CSS
{lang = 'css'}
))
return tostring(outer)
end