| <!DOCTYPE HTML> |
| |
| <html> |
| <head> |
| <meta name="viewport" content="initial-scale=1"> |
| <title>PaintWorklet with basic draw and transform operations</title> |
| <style type="text/css"> |
| .nomargin { |
| margin: 0px auto; |
| width:300px; |
| height:300px; |
| background-image:paint(basic); |
| } |
| </style> |
| |
| <script id="code" type="text/worklet"> |
| registerPaint('basic', class { |
| paint(ctx, geom) { |
| ctx.fillStyle = 'green'; |
| ctx.transform(1, 0.5, 0, 1, 20, 20); |
| ctx.fillRect(0, 0, 50, 50); |
| |
| ctx.resetTransform(); |
| |
| ctx.fillStyle = 'blue'; |
| ctx.translate(150, 60); |
| ctx.rotate(60 * Math.PI / 180); |
| ctx.scale(1.5, 1); |
| ctx.fillRect(0, 0, 50, 50); |
| } |
| }); |
| </script> |
| |
| <script> |
| async function main() |
| { |
| var code = document.getElementById('code').textContent; |
| var blob = new Blob([code], {type: 'text/javascript'}); |
| await CSS.paintWorklet.addModule(URL.createObjectURL(blob)); |
| const animation = |
| document.body.animate({ opacity: [ 0, 1 ] }, {duration: 1 }); |
| await animation.finished; |
| domAutomationController.send("SUCCESS"); |
| } |
| </script> |
| </head> |
| <body onload="main()"> |
| <div style="position:relative; width:300px; height:300px; background-color:white"> |
| </div> |
| <div id="container" style="position:absolute; top:0px; left:0px"> |
| <div id="target" class="nomargin"></div> |
| </div> |
| </body> |
| </html> |