UNPKG

991 BJavaScriptView Raw
1const getRandom = (min, max) => {
2 return Math.floor(Math.random() * (max - min + 1)) + min
3}
4
5if (typeof registerPaint !== 'undefined') {
6 class SuperUnderline {
7 static get inputProperties() {
8 return ['--extra-underlineNumber', '--extra-underlineColor', '--extra-underlineSpread', '--extra-underlineWidth']
9 }
10
11 paint(ctx, size, properties) {
12 const numUnderlines = properties.get('--extra-underlineNumber')
13 const lineWidth = properties.get('--extra-underlineWidth')
14 const color = properties.get('--extra-underlineColor')
15 const spread = properties.get('--extra-underlineSpread')
16
17 ctx.lineWidth = lineWidth
18 ctx.strokeStyle = color
19
20 for (let i = 0; i < numUnderlines; i++) {
21 ctx.beginPath()
22 ctx.moveTo(0, getRandom(0, spread) + size.height/1.4)
23 ctx.lineTo(size.width, getRandom(0, spread) + size.height/1.4)
24 ctx.stroke()
25 }
26 }
27 }
28
29 registerPaint('extra-superUnderline', SuperUnderline)
30}
\No newline at end of file