No JavaScript here
This card leans toward your pointer because its parent says effect="tilt". Clicks land where the tilted card is drawn.
Add effect="tilt" to <canvas-slot> and you don't write a render loop or any canvas code. Each slot becomes a GPU texture and is drawn through the fragment shader that the effect names. The content is still DOM. Move the pointer over
the cards, click the blue one, type in the field.
This card leans toward your pointer because its parent says effect="tilt". Clicks land where the tilted card is drawn.
“Select this sentence. It's text in the page, drawn through a shader.”
<script type="module" src="/lib/canvas-slot.js"></script>
<canvas-slot effect="tilt">
<article slot="note">…</article>
<form slot="form" effect="ripple">…</form>
<blockquote slot="quote">…</blockquote>
</canvas-slot>
<canvas-slot>, or on one slot.--fx-progress, --fx-x and --fx-y (used by the cards further down).backend="webgpu": the same thing for a GPU texture. device.queue.drawElementImageToTexture({ source: el }, { texture }).The attribute can change at any time. --fx-progress, --fx-amount, --fx-x and --fx-y are registered custom properties, so sliders, transitions, keyframes and :hover all drive the shader.
Change the effect above, then drag the sliders. The value goes straight into a CSS variable on this element.
A CSS transition on --fx-progress. On a phone, use the button.
[slot] { transition: --fx-progress 800ms; }
canvas-slot:hover [slot] { --fx-progress: 1; }
@keyframes sway {
from { --fx-x: -0.9 } to { --fx-x: 0.9 }
}
effect also takes #id of a <script> or url(file.frag). The shader is one function:
p is in CSS pixels from the slot's top-left and tex(p) samples the slot. It's a CSS filter that you write yourself.
Edit the one on the left.
Real text and a real link.
This shader is a file next to the page.
<script type="x-shader/x-fragment" id="wobble">
vec4 fx(vec2 p) { return tex(p + vec2(sin(p.y * 0.08 + u_time * 3.0) * 6.0, 0.0)); }
</script>
<canvas-slot effect="#wobble">…</canvas-slot>
<canvas-slot effect="url(scanlines.frag)">…</canvas-slot>
effect at a <script> by id, or at a file. The shader is one function.effect="shared-tint" and fx="shared-tint" can use it.fx attribute
<canvas-slot effect> and the fx attribute share one list of effects, one shader contract
and the same CSS properties. Use fx to shade one element where it already sits in your layout; use
<canvas-slot> when several pieces share a canvas and you want to place them. An effect defined once works in both.
Defined once with defineEffect().
The same effect on a plain element.
import { defineEffect } from '/lib/effects.js';
defineEffect('shared-tint', { glsl: `vec4 fx(vec2 p) { … }` });
Every effect slot on this page uses WebGPU by itself when the page has a usable device (a real adapter that passes a self-test) and each
of its effects has WGSL source; the switch under the first demo names a route by hand and says why WebGPU isn't in use.
backend="webgpu", as below, asks for it outright. It draws each slot with queue.drawElementImageToTexture() and a WGSL version of the effect
(fn fx(p: vec2f) -> vec4f). Built-in WGSL: tilt, ripple, dissolve, glass, haze, crt, page-curl. If WebGPU can't start, rejects the first frame or loses the device, the element
falls back to WebGL by itself.
Click for ripples.
<canvas-slot> without effect behaves as before (2D context, onrender). With it, the canvas gets a WebGPU or WebGL2 context instead and the shader code is loaded on demand.texElementSubImage2D() uploads a slot only when the browser says it repainted. One full-canvas quad per slot runs the effect's fragment shader and is blended over the last.onrender only if you want to place them. The element repaints itself while an effect is moving and sleeps when nothing changes.--fx-* properties are read from each slotted element every frame while it is on screen. A paint happens only when one changed.geometry, a DOMMatrix). The shader gets the inverse to sample with, and updateElementGeometry() gets the matrix so clicks, focus rings and selection land on the tilted card. Displacement effects (ripple, curl) are visual only, like a CSS filter.effect later swaps in a new canvas and moves the slots across. Content, focus and form state aren't affected, because they were never in the canvas.| Result | Experiment | Detail |
|---|