1 |
|
2 |
|
3 | CSS.registerProperty({
|
4 | name: '--extra-underlineNumber',
|
5 | syntax: '<number>',
|
6 | inherits: false,
|
7 | initialValue: 3
|
8 | });
|
9 |
|
10 | CSS.registerProperty({
|
11 | name: '--extra-underlineColor',
|
12 | syntax: '<color>',
|
13 | inherits: true,
|
14 | initialValue: 'black'
|
15 | });
|
16 |
|
17 | CSS.registerProperty({
|
18 | name: '--extra-underlineSpread',
|
19 | syntax: '<number>',
|
20 | inherits: false,
|
21 | initialValue: 20
|
22 | });
|
23 |
|
24 | CSS.registerProperty({
|
25 | name: '--extra-underlineWidth',
|
26 | syntax: '<number>',
|
27 | inherits: false,
|
28 | initialValue: 2
|
29 | });
|
30 |
|
31 | (() => { const worklet = `
|
32 | const getRandom = (min, max) => {
|
33 | return Math.floor(Math.random() * (max - min + 1)) + min
|
34 | }
|
35 |
|
36 | if (typeof registerPaint !== 'undefined') {
|
37 | class SuperUnderline {
|
38 | static get inputProperties() {
|
39 | return ['--extra-underlineNumber', '--extra-underlineColor', '--extra-underlineSpread', '--extra-underlineWidth']
|
40 | }
|
41 |
|
42 | paint(ctx, size, properties) {
|
43 | const numUnderlines = properties.get('--extra-underlineNumber')
|
44 | const lineWidth = properties.get('--extra-underlineWidth')
|
45 | const color = properties.get('--extra-underlineColor')
|
46 | const spread = properties.get('--extra-underlineSpread')
|
47 |
|
48 | ctx.lineWidth = lineWidth
|
49 | ctx.strokeStyle = color
|
50 |
|
51 | for (let i = 0; i < numUnderlines; i++) {
|
52 | ctx.beginPath()
|
53 | ctx.moveTo(0, getRandom(0, spread) + size.height/1.4)
|
54 | ctx.lineTo(size.width, getRandom(0, spread) + size.height/1.4)
|
55 | ctx.stroke()
|
56 | }
|
57 | }
|
58 | }
|
59 |
|
60 | registerPaint('extra-superUnderline', SuperUnderline)
|
61 | }`
|
62 |
|
63 | const workletBlob = URL.createObjectURL(new Blob([worklet], { type: 'application/javascript' }))
|
64 |
|
65 | window.CSS.paintWorklet.addModule(workletBlob)
|
66 | })() |
\ | No newline at end of file |