badgen/lib/index.js

32 wiersze
1.3 KiB
JavaScript
Czysty Zwykły widok Historia

2018-07-10 17:51:32 +00:00
const calcWidth = require('./calc-text-width.js').Verdana11
2018-06-22 17:42:12 +00:00
const colorPresets = require('./color-presets.js')
module.exports = function ({subject, status, color}) {
2018-07-01 08:13:34 +00:00
color = colorPresets[color] || color || colorPresets['blue']
2018-05-29 08:53:54 +00:00
2018-07-14 18:09:01 +00:00
const sbRectWidth = calcWidth(subject) + 11
const stRectWidth = calcWidth(status) + 11
2018-05-29 08:53:54 +00:00
const width = sbRectWidth + stRectWidth
return `
2018-07-01 06:43:16 +00:00
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="20">
2018-05-29 10:13:52 +00:00
<linearGradient id="a" x2="0" y2="100%">
2018-05-29 08:53:54 +00:00
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
2018-07-14 18:09:01 +00:00
<mask id="m"><rect width="${width}" height="20" rx="3" fill="#FFF"/></mask>
<g mask="url(#m)">
<rect width="${sbRectWidth}" height="20" fill="#555"/>
<rect x="${sbRectWidth}" width="${stRectWidth}" height="20" fill="#${color}"/>
<rect width="${width}" height="20" fill="url(#a)"/>
</g>
<g fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11">
<text x="7" y="14.8" fill="#000" opacity="0.25">${subject}</text>
<text x="6" y="13.8">${subject}</text>
<text x="${sbRectWidth + 6}" y="14.8" fill="#000" opacity="0.25">${status}</text>
<text x="${sbRectWidth + 5}" y="13.8">${status}</text>
</g>
2018-05-29 08:53:54 +00:00
</svg>
`
}