Skip to content

Commit 1279ece

Browse files
committed
[css-paint-api] Add importing code into paintWorklet for examples.
Fixes #331.
1 parent c96c9d1 commit 1279ece

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

css-paint-api/Overview.bs

+37-28
Original file line numberDiff line numberDiff line change
@@ -442,20 +442,24 @@ Example 1: A colored circle. {#example-1}
442442
-----------------------------------------
443443

444444
<pre class='lang-markup'>
445-
&lt;div id="myElement"&gt;
445+
&lt;div id="myElement">
446446
CSS is awesome.
447-
&lt;/div&gt;
447+
&lt;/div>
448448

449-
&lt;style&gt;
449+
&lt;style>
450450
#myElement {
451451
--circle-color: red;
452452
background-image: paint(circle);
453453
}
454-
&lt;/style&gt;
454+
&lt;/style>
455+
456+
&lt;script>
457+
paintWorklet.import('circle.js');
458+
&lt;/script>
455459
</pre>
456460

457461
<pre class='lang-javascript'>
458-
// Inside PaintWorkletGlobalScope.
462+
// circle.js
459463
registerPaint('circle', class {
460464
static get inputProperties() { return ['--circle-color']; }
461465
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
483487
loaded.
484488

485489
<pre class='lang-markup'>
486-
&lt;div id="myElement"&gt;
487-
&lt;/div&gt;
490+
&lt;div id="myElement">
491+
&lt;/div>
488492

489-
&lt;style&gt;
493+
&lt;style>
490494
#myElement {
491495
--image: url('#someUrlWhichIsLoading');
492496
background-image: paint(image-with-placeholder);
493497
}
494-
&lt;/style&gt;
495-
496-
&lt;script&gt;
497-
document.registerProperty({
498-
name: '--image',
499-
syntax: '&lt;image&gt;'
500-
});
501-
&lt;/script&gt;
498+
&lt;/style>
499+
500+
&lt;script>
501+
document.registerProperty({
502+
name: '--image',
503+
syntax: '&lt;image&gt;'
504+
});
505+
paintWorklet.import('image-placeholder.js');
506+
&lt;/script>
502507
</pre>
503508

504509
<pre class='lang-javascript'>
505-
// Inside PaintWorkletGlobalScope.
506-
registerPaint('circle', class {
510+
// image-placeholder.js
511+
registerPaint('image-with-placeholder', class {
507512
static get inputProperties() { return ['--image']; }
508513
paint(ctx, geom, properties) {
509514
const img = properties.get('--image');
@@ -536,22 +541,26 @@ Example 4: Different color based on size {#example-4}
536541
-----------------------------------------------------
537542

538543
<pre class='lang-markup'>
539-
&lt;h1&gt;
540-
Heading 1
541-
&lt;/h1&gt;
542-
&lt;h1&gt;
543-
Another heading
544-
&lt;/h1&gt;
545-
546-
&lt;style&gt;
544+
&lt;h1>
545+
Heading 1
546+
&lt;/h1>
547+
&lt;h1>
548+
Another heading
549+
&lt;/h1>
550+
551+
&lt;style>
547552
h1 {
548553
background-image: paint(heading-color);
549554
}
550-
&lt;/style&gt;
555+
&lt;/style>
556+
557+
&lt;script>
558+
paintWorklet.import('heading-color.js');
559+
&lt;/script>
551560
</pre>
552561

553562
<pre class='lang-javascript'>
554-
// Inside PaintWorkletGlobalScope.
563+
// heading-color.js
555564
registerPaint('heading-color', class {
556565
static get inputProperties() { return []; }
557566
paint(ctx, geom, properties) {

0 commit comments

Comments
 (0)