@ruverse/waves
v0.2.0
Published
Deterministic, configurable animated canvas waves for the web.
Maintainers
Readme
Waves
A deterministic animated-wave renderer and visual editor. The reusable renderer is published as @ruverse/waves; the Svelte app is the source for portable configurations, images, and embeds.
Package
Install the package:
npm install @ruverse/wavesCopy a compact string from the editor's Share menu and mount it directly into any sized element:
import { mountWave } from '@ruverse/waves';
const compact = 'waves:v1:{"s":42,"a":52,"n":7,"bg":"transparent"}';
const handle = mountWave(document.querySelector('#waves'), compact);
// Compact strings are complete snapshots, so omitted values return to defaults.
handle.update('waves:v1:{"s":84}');
// Object updates remain partial merges with the mounted configuration.
handle.update({ waveCount: 5 });
handle.destroy();Create, encode, and decode compact strings programmatically:
import {
createWaveConfig,
decodeWaveConfig,
encodeWaveConfig,
mountWave
} from '@ruverse/waves';
const config = createWaveConfig({
seed: 42,
waveCount: 7,
amplitude: 52,
backgroundColor: 'transparent',
waveColor: 'rgba(255, 255, 255, 0.14)',
variations: {
amplitude: 0.2,
rotation: 0.04,
spacing: 0.08
}
});
const compact = encodeWaveConfig(config);
const normalized = decodeWaveConfig(compact);
mountWave(document.querySelector('#waves'), compact);The default configuration encodes as waves:v1:{}. The codec validates aliases
and payload types without evaluating code, and can be used during server
rendering. The container controls the rendered size and must have non-zero width
and height. The runtime has no dependencies, pauses while offscreen, respects
reduced-motion preferences, and accesses browser globals only after
mountWave() is called.
Build and test the publishable package:
bun run build:lib
bun run test:package
npm pack --dry-runRepository builds prepare and attest release artifacts but do not publish them automatically.
Releases
Package releases are prepared on dev and moved to the release-only main
branch through a release pull request. After the pull request is merged, an
exact numeric tag matching package.json triggers the GitHub Actions release
workflow.
The workflow runs the editor and package checks, creates and smoke-tests the npm
tarball, attests its provenance, and attaches it to a draft GitHub Release for
maintainer review. It does not publish to npm automatically. See
AGENTS.md for the complete release procedure.
Visual editor
The editor lets you customize amplitude, wavelength, frequency, period, rotation, curvature, glitch, spacing, thickness, taper, colors, variation, and wave count. Configurations can be saved locally or shared as a portable compact string, image, or self-contained web embed.
Run Locally
Prerequisites:
- Bun 1.3 or newer
Install dependencies:
bun install --frozen-lockfileStart the development server:
bun run devVite will print a local URL, usually http://localhost:5173/, where you can open the app in your browser.
To create a production build:
bun run buildTo preview the production build locally:
bun run previewRecommended IDE Setup
Need an official Svelte framework?
Check out SvelteKit, which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
Technical considerations
Why use this over SvelteKit?
- It brings its own routing solution which might not be preferable for some users.
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other create-vite templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
Why global.d.ts instead of compilerOptions.types inside jsconfig.json or tsconfig.json?
Setting compilerOptions.types shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding svelte and vite/client type information.
Why include .vscode/extensions.json?
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
Why enable allowJs in the TS template?
While allowJs: false would indeed prevent the use of .js files in the project, it does not prevent the use of JavaScript syntax in .svelte files. In addition, it would force checkJs: false, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant.
Why is HMR not preserving my local component state?
HMR state preservation comes with a number of gotchas! It has been disabled by default in both svelte-hmr and @sveltejs/vite-plugin-svelte due to its often surprising behavior. You can read the details here.
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
// store.ts
// An extremely simple external store
import { writable } from 'svelte/store'
export default writable(0)