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
const sbRectWidth = calcWidth(subject) + 10
const stRectWidth = calcWidth(status) + 11
2018-07-01 08:11:12 +00:00
const stTextStart = sbRectWidth + 5
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>
<rect rx="3" width="${width}" height="20" fill="#${color}"/>
<rect rx="3" x="0" width="${sbRectWidth}" height="20" fill="#555"/>
<path fill="#555" d="M${sbRectWidth} 0v20h-4v-20h4z"/>
2018-05-29 10:13:52 +00:00
<rect rx="3" width="${width}" height="20" fill="url(#a)"/>
2018-07-10 17:51:32 +00:00
<g fill="#fff" text-anchor="start" font-family="DejaVu Sans,Verdana,sans-serif" font-size="11">
2018-07-11 03:04:12 +00:00
<text x="6" y="14.8" fill="#000" opacity="0.2">${subject}</text>
<text x="5" y="13.8">${subject}</text>
<text x="${stTextStart + 1}" y="14.8" fill="#000" opacity="0.2">${status}</text>
<text x="${stTextStart}" y="13.8">${status}</text>
2018-07-01 06:43:16 +00:00
</g><script/>
2018-05-29 08:53:54 +00:00
</svg>
`
}