WissensdatenbankPrüfungszentrum
DEDeutsch
Sprache wählen13

CKTIS / CSS

paint() — Bild aus einem Paint Worklet

`paint()` verweist auf eine registrierte JavaScript-Malroutine, die ein an Boxgröße und berechneten Stil angepasstes `<image>` erzeugt.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

paint( <ident> [, <declaration-value>]? )

paint() verweist auf eine registrierte JavaScript-Malroutine, die ein an Boxgröße und berechneten Stil angepasstes <image> erzeugt.

In diesem Chromium meldet paint(cktis-grid) Unterstützung false, CSS.paintWorklet fehlt und das berechnete Bild ist none. Deshalb bleibt die Ersatzfarbe als Pixel 0,128,0,255 sichtbar; das Beispiel behauptet nicht, ein Paint Worklet ausgeführt zu haben.

Grammatik: paint( <ident> [, <declaration-value>]? ).

Das erste Argument ist ein Bezeichner, der dem an registerPaint() übergebenen Namen entspricht; das Modul wird mit CSS.paintWorklet.addModule() geladen. Optionale Argumente werden beim Zeichnen gegen deklarierte inputArguments geprüft; fehlende Registrierung, falsche Anzahl oder falscher Typ ergeben ein ungültiges Bild. Eine Malroutine kann beobachtete Eigenschaften deklarieren und erhält die Ausgabegröße, ersetzt aber keine zugänglichen Inhalte; bei cursor ist die Funktion immer ein ungültiges Bild und der nächste Fallback gilt.

Beispiele

const probe=document.createElement('div');probe.style.cssText='width:8px;height:8px;background-color:rgb(0 128 0);background-image:paint(cktis-grid)';document.body.append(probe);
const supported=CSS.supports('background-image','paint(cktis-grid)');
const worklet=Boolean(CSS.paintWorklet);
const computed=getComputedStyle(probe).backgroundImage;
const svg='<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><foreignObject width="8" height="8"><div xmlns="http://www.w3.org/1999/xhtml" style="width:8px;height:8px;background-color:rgb(0 128 0);background-image:paint(cktis-grid)"></div></foreignObject></svg>';
const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=canvas.height=8;const context=canvas.getContext('2d');context.drawImage(image,0,0);const pixel=[...context.getImageData(4,4,1,1).data].join(',');
console.log('supported='+supported+'; paint-worklet='+worklet+'; computed-image='+computed+'; fallback-pixel='+pixel);

Ergebnis

supported=false; paint-worklet=false; computed-image=none; fallback-pixel=0,128,0,255

`paint()` verweist auf eine registrierte JavaScript-Malroutine, die ein an Boxgröße und berechneten Stil angepasstes `<image>` erzeugt.

Quellen