Distortion waves
A coloured wave that leaves a button, an edge or an icon and carries one view into another, bending the page as it passes.
Send to Maya Chen
$240.00
- From
- Checking ··42
- Arrives
- Today
- Fee
- Free
$240.00
Sent to Maya Chen
Add 500 credits
$5.00, charged to Visa ··18
500 credits added
Your balance is 1,240
These run on a timer. Press a card’s button to run its wave yourself.
Playground
Press the button in the card.
Send to Maya Chen
$240.00
- From
- Checking ··42
- Arrives
- Today
- Fee
- Free
$240.00
Sent to Maya Chen
<script>
import { DistortionWave } from 'runeglow/distortion-waves';
let done = $state(false);
</script>
<DistortionWave
revealed={done}
style="width: 300px; border-radius: 28px; overflow: hidden;"
>
<Review />
{#snippet revealedContent()}
<Receipt />
{/snippet}
{#snippet overlay()}
<button onclick={() => (done = !done)}>Confirm</button>
{/snippet}
</DistortionWave>Install
pnpm add runeglow Or copy just this library’s source into your project, with the shadcn-svelte CLI:
npx shadcn-svelte@latest add https://runeglow.dev/r/distortion-waves.json import { DistortionWave } from 'runeglow/distortion-waves';Usage
Put the first view in the component and the second in revealedContent. Both are your own markup, laid on top of each other;
the element takes the size of the larger. Changing revealed runs the
wave, and setting it back collapses the wave into its source.
<script>
import { DistortionWave } from 'runeglow/distortion-waves';
let sent = $state(false);
</script>
<DistortionWave revealed={sent} style="width: 320px; border-radius: 28px; overflow: hidden;">
<Review />
{#snippet revealedContent()}
<Receipt />
{/snippet}
{#snippet overlay()}
<button onclick={() => (sent = true)}>Confirm</button>
{/snippet}
</DistortionWave>A center wave rings out from an element you name with source. waveStyle changes any of its numbers.
<script>
import { DistortionWave } from 'runeglow/distortion-waves';
let token = $state(null);
let bought = $state(false);
</script>
<DistortionWave type="center" palette="ocean" revealed={bought} source={token} waveStyle={{ travel: 2.8 }}>
<Credits bind:token onbuy={() => (bought = true)} />
{#snippet revealedContent()}
<Credits added />
{/snippet}
</DistortionWave>Without a second view the wave passes over the content and leaves it as it was. Bind the component to run it yourself.
<script>
import { DistortionWave } from 'runeglow/distortion-waves';
let wave; // the component
</script>
<!-- No second view: the wave passes over the content and leaves it as it was. -->
<DistortionWave bind:this={wave} type="horizontal" palette="mono">
<Article />
</DistortionWave>
<button onclick={(e) => wave.play({ source: e.currentTarget })}>Refresh</button>Props
children Snippet – The view that shows first. Give it an opaque background.revealedContent Snippet – The view the wave leaves behind. Without one the wave passes over the first view and leaves it as it was.overlay Snippet – Stays above the wave, unbent and uncoloured, over both views: the button that starts it, a spinner, a video.revealed boolean – Which view shows. Changing it runs the wave. Leave it out to drive the wave with play().type 'vertical' | 'horizontal' | 'center' 'vertical' Up from a button at the bottom, across from a source at the left, or a ring out from an icon.source Element | { x, y, w, h } the control last pressed Where the wave starts.focus { x, y } | null the last press The point the front leans toward, in the element’s CSS pixels.palette 'colorful' | 'green' | 'ocean' | 'sunset' | 'mono' | '#RRGGBB' | Palette the type’s own The colours.waveStyle Partial<WaveStyle> the type’s own Any of the wave’s numbers: travel, swell, blur, aberration, edge, particles.scale number | 'auto' 'auto' CSS pixels per point. auto sizes the wave to the element.cornerRadius number the element’s The radius the edge colour follows.scrub number | null – Holds the wave at this point of its run, 0 to 1, instead of playing.capture boolean | CaptureFunction true How the element is pictured. false draws the colour alone.live boolean | 'animations' true Whether the picture follows the element while the wave is out.prewarm boolean true Takes the first picture when the browser is idle after mounting.resolution number the display’s Canvas pixels per CSS pixel.reducedMotion 'system' | 'always' | 'never' 'system' When to crossfade instead.onFinish (revealed: boolean) => void – Called when a wave ends.ref HTMLDivElement | null – The wave’s element. Bindable with bind:ref....rest HTMLAttributes<HTMLDivElement> – class, style and other attributes go to the element.Functions
Bind the component with bind:this and call these on it.
play(options?) { source?, focus? } – Runs the wave from the start.reverse() – Runs it back to the first view.reset() – Straight back to the first view, with no wave.prepare() () => Promise<void> – Pictures the element now, so the next wave starts with its lens.getController() () => WaveController | null – The engine behind it.Notes
- The wave bends a picture of your markup, taken ahead of the run. What animates inside a view
stands still while the wave passes; anything that must stay live goes in
overlay. - The picture can hold text, same-origin or CORS images, SVG, gradients, shadows and web fonts.
It cannot see cross-origin images or fonts without CORS, closed shadow roots or iframes. Add
data-dw-skipto leave an element out. - A
<canvas data-dw-live>inside a view is read every frame, so the wave bends it as it animates. Keep these small. - It needs WebGL 2. Without it, or when the visitor asks for reduced motion, it crossfades.
WaveControlleris the same wave without a component, for any element. The model and the renderer are exported too.