You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: css-paint-api/EXPLAINER.md
+48-1
Original file line number
Diff line number
Diff line change
@@ -127,7 +127,54 @@ In this example `performPathPreInit` is doing CPU intensive work which should on
127
127
Drawing Images
128
128
--------------
129
129
130
-
TODO
130
+
The API works in conjunction with the [CSS Properties and Values](https://drafts.css-houdini.org/css-properties-values-api/) proposal and the [CSS Typed OM](https://drafts.css-houdini.org/css-typed-om/) proposal.
131
+
132
+
Using the Properties and Values `registerProperty` method, developers can create a custom CSS property with the `<image>` type. E.g.
133
+
134
+
```js
135
+
registerProperty({
136
+
name:'--profile-image',
137
+
syntax:'<image>'
138
+
});
139
+
```
140
+
141
+
This tells the rendering engine to treat the CSS property `--profile-image` as an image; and as a result the style engine will parse and begin loading that image.
142
+
143
+
You can then directly draw this image from within your paint method:
144
+
145
+
```js
146
+
registerPaint('avatar', class {
147
+
static inputProperties = ['--profile-image'];
148
+
149
+
paint(ctx, size, styleMap) {
150
+
// Determine the center point and radius.
151
+
constx=size.width/2;
152
+
consty=size.height/2;
153
+
constradius=Math.min(x, y);
154
+
155
+
ctx.save();
156
+
// Set up a round clipping path for the profile image.
0 commit comments