1 |
|
2 |
|
3 | CSS.registerProperty({
|
4 | name: '--extra-crossColor',
|
5 | syntax: '<color>',
|
6 | inherits: true,
|
7 | initialValue: 'black'
|
8 | });
|
9 |
|
10 | CSS.registerProperty({
|
11 | name: '--extra-crossSpread',
|
12 | syntax: '<number>',
|
13 | inherits: false,
|
14 | initialValue: 100
|
15 | });
|
16 |
|
17 | CSS.registerProperty({
|
18 | name: '--extra-crossWidth',
|
19 | syntax: '<number>',
|
20 | inherits: false,
|
21 | initialValue: 1
|
22 | });
|
23 |
|
24 | const worklet = `
|
25 | if (typeof registerPaint !== 'undefined') {
|
26 | class CrossOut {
|
27 | static get inputProperties() {
|
28 | return ['--extra-crossNumber', '--extra-crossColor', '--extra-crossSpread', '--extra-crossWidth']
|
29 | }
|
30 |
|
31 | paint(ctx, size, properties) {
|
32 | const lineWidth = properties.get('--extra-crossWidth')
|
33 | const color = properties.get('--extra-crossColor')
|
34 | const spread = properties.get('--extra-crossSpread')
|
35 | const spreadPercent = (spread - 1) / 100
|
36 | const verticalStart = (size.height - lineWidth) * spreadPercent + lineWidth
|
37 |
|
38 | ctx.lineWidth = lineWidth
|
39 | ctx.strokeStyle = color
|
40 |
|
41 | ctx.beginPath()
|
42 | ctx.moveTo(lineWidth, lineWidth)
|
43 | ctx.lineTo(size.width - lineWidth, verticalStart)
|
44 | ctx.moveTo(size.width - lineWidth, lineWidth)
|
45 | ctx.lineTo(lineWidth, verticalStart + size.height)
|
46 | ctx.stroke()
|
47 | }
|
48 | }
|
49 |
|
50 | registerPaint('extra-crossOut', CrossOut)
|
51 | }`
|
52 |
|
53 | const workletBlob = URL.createObjectURL(new Blob([worklet], { type: 'application/javascript' }))
|
54 |
|
55 | window.CSS.paintWorklet.addModule(workletBlob) |
\ | No newline at end of file |