@@ -442,20 +442,24 @@ Example 1: A colored circle. {#example-1}
442
442
-----------------------------------------
443
443
444
444
<pre class='lang-markup'>
445
- <div id="myElement">
445
+ <div id="myElement">
446
446
CSS is awesome.
447
- </div>
447
+ </div>
448
448
449
- <style>
449
+ <style>
450
450
#myElement {
451
451
--circle-color: red;
452
452
background-image: paint(circle);
453
453
}
454
- </style>
454
+ </style>
455
+
456
+ <script>
457
+ paintWorklet.import('circle.js' );
458
+ </script>
455
459
</pre>
456
460
457
461
<pre class='lang-javascript'>
458
- // Inside PaintWorkletGlobalScope.
462
+ // circle.js
459
463
registerPaint('circle' , class {
460
464
static get inputProperties() { return ['--circle-color'] ; }
461
465
paint(ctx, geom, properties) {
@@ -483,27 +487,28 @@ It is possible for an author to use paint to draw a placeholder image while an i
483
487
loaded.
484
488
485
489
<pre class='lang-markup'>
486
- <div id="myElement">
487
- </div>
490
+ <div id="myElement">
491
+ </div>
488
492
489
- <style>
493
+ <style>
490
494
#myElement {
491
495
--image: url('#someUrlWhichIsLoading' );
492
496
background-image: paint(image-with-placeholder);
493
497
}
494
- </style>
495
-
496
- <script>
497
- document.registerProperty({
498
- name: '--image' ,
499
- syntax: '<image>'
500
- });
501
- </script>
498
+ </style>
499
+
500
+ <script>
501
+ document.registerProperty({
502
+ name: '--image' ,
503
+ syntax: '<image>'
504
+ });
505
+ paintWorklet.import('image-placeholder.js' );
506
+ </script>
502
507
</pre>
503
508
504
509
<pre class='lang-javascript'>
505
- // Inside PaintWorkletGlobalScope.
506
- registerPaint('circle ' , class {
510
+ // image-placeholder.js
511
+ registerPaint('image-with-placeholder ' , class {
507
512
static get inputProperties() { return ['--image'] ; }
508
513
paint(ctx, geom, properties) {
509
514
const img = properties.get('--image' );
@@ -536,22 +541,26 @@ Example 4: Different color based on size {#example-4}
536
541
-----------------------------------------------------
537
542
538
543
<pre class='lang-markup'>
539
- <h1>
540
- Heading 1
541
- </h1>
542
- <h1>
543
- Another heading
544
- </h1>
545
-
546
- <style>
544
+ <h1>
545
+ Heading 1
546
+ </h1>
547
+ <h1>
548
+ Another heading
549
+ </h1>
550
+
551
+ <style>
547
552
h1 {
548
553
background-image: paint(heading-color);
549
554
}
550
- </style>
555
+ </style>
556
+
557
+ <script>
558
+ paintWorklet.import('heading-color.js' );
559
+ </script>
551
560
</pre>
552
561
553
562
<pre class='lang-javascript'>
554
- // Inside PaintWorkletGlobalScope.
563
+ // heading-color.js
555
564
registerPaint('heading-color' , class {
556
565
static get inputProperties() { return []; }
557
566
paint(ctx, geom, properties) {
0 commit comments