@@ -623,41 +623,56 @@ Example 1: A colored circle. {#example-1}
623623-----------------------------------------
624624
625625<pre class='lang-markup'>
626- <div id="myElement">
627- CSS is awesome.
628- </div>
629-
626+ <!DOCTYPE html>
630627<style>
631- #myElement {
632- --circle-color: red;
628+ #example {
629+ --circle-color: deepskyblue;
630+
633631 background-image: paint(circle);
634- }
632+ font-family: sans-serif;
633+ font-size: 36px;
634+ transition: --circle-color 1s;
635+ }
636+
637+ #example:focus {
638+ --circle-color: purple;
639+ }
635640</style>
636641
642+ <textarea id="example">
643+ CSS is awesome.
644+ </textarea>
645+
637646<script>
647+ CSS.registerProperty({
648+ name: '--circle-color' ,
649+ syntax: '<color>' ,
650+ initialValue: 'black' ,
651+ inherit: false
652+ });
638653 CSS.paintWorklet.import('circle.js' );
639654</script>
640655</pre>
641656
642657<pre class='lang-javascript'>
643658// circle.js
644659registerPaint('circle' , class {
645- static get inputProperties() { return ['--circle-color'] ; }
646- paint(ctx, geom, properties) {
647- // Change the fill color.
648- const color = properties.get('--circle-color' );
649- ctx.fillStyle = color;
650-
651- // Determine the center point and radius.
652- const x = geom.width / 2;
653- const y = geom.height / 2;
654- const radius = Math.min(x, y);
655-
656- // Draw the circle \o/
657- ctx.beginPath();
658- ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
659- ctx.fill();
660- }
660+ static get inputProperties() { return ['--circle-color'] ; }
661+ paint(ctx, geom, properties) {
662+ // Change the fill color.
663+ const color = properties.get('--circle-color' );
664+ ctx.fillStyle = color.cssText ;
665+
666+ // Determine the center point and radius.
667+ const x = geom.width / 2;
668+ const y = geom.height / 2;
669+ const radius = Math.min(x, y);
670+
671+ // Draw the circle \o/
672+ ctx.beginPath();
673+ ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
674+ ctx.fill();
675+ }
661676});
662677</pre>
663678
0 commit comments