useWatermark
Headless watermark composable. Builds a repeating SVG tile from text or an image URL and exposes it as a CSS `background-image` data URL. Provides `install()` / `uninstall()` helpers for programmatic use. Optionally watches the DOM via MutationObserver to re-inject the layer if it is removed (anti-tamper mode). SSR-safe — no DOM access in the reactive core.
API
Signature
Signature TypeScript complète extraite du fichier du composable.
useWatermark escapes all XML metacharacters before embedding text or image URLs in the SVG data URL, preventing attribute injection. Enable `antiTamper: true` to activate MutationObserver re-injection — note that this is a deterrent, not a security boundary, as a motivated user can still disable JS.
Interfaces consommées
API
Paramètres
Paramètres d'entrée acceptés par ce composable.
- optionsMaybeRefOrGetter<IUseWatermarkOptions>{}
- Options bag (static object, reactive ref, or getter function). Reads: `text`, `image` (URL), `opacity` (default 0.15), `angle` (degrees, default -30), `gap` (tile spacing in px, default 100), `fontSize` (px, default 16), `fontFamily`, `color`, `fontWeight`, `pointerEvents` ("none" | "auto"), `zIndex`, `antiTamper` (enable MutationObserver re-injection). Passing a ref makes patternUrl update reactively when options change.
API
Valeurs de retour
Propriétés et méthodes exposées par l'objet retourné par le composable.
- patternUrl
- CSS `url("data:image/svg+xml,…")` string. Bind to `background-image` on any container element, or pass to `install()`. Recomputes reactively when options change.
- install
- Inject a full-cover `<div>` layer with `position: absolute; inset: 0` and the pattern as background-image into `target` (defaults to document.body). Sets `position: relative` on the target if it is `static`. Returns the created layer element, or null during SSR.
- uninstall
- Remove the injected layer and disconnect the MutationObserver if active. Called automatically on scope dispose.
Usage
Exemples
Extraits de code prêts à coller.
Text watermark on a document container
Reactive options + patternUrl binding