useWatermark

Watermark
stable

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

Full TypeScript signature sourced from the composable file.

typescript

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.

Consumed interfaces

IUseWatermarkOptions

API

Parameters

Input parameters accepted by this composable.

options
MaybeRefOrGetter<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

Return values

Properties and methods exposed by the composable return object.

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

Examples

Ready-to-paste usage snippets.

Text watermark on a document container

vue

Reactive options + patternUrl binding

vue