Animation Plugins

The reveal-animation driver interface, the built-in drivers, and how to write your own.

Driver interface

An animation driver defines how the preview pane’s title/content reveal, and how an optional header placeholder rotates:

interface HawkAnimationDriver {
  typeTitle(el, text, options?: { isAnchor?: boolean }): unknown;
  typeContent(el, html, options?): unknown;
  rotatePlaceholder(el, strings, options?): unknown;
  stop(controller): void;
}

typeTitle/typeContent/rotatePlaceholder may return a controller (anything with whatever shape the driver itself understands) or null. Hawk never inspects it — it only ever passes it back into stop(), which runs before every preview re-render and on destroy().

Built-in drivers

  • instant (default, zero dependencies) — direct textContent/innerHTML writes.
  • typeflow — wraps TypeFlow.type() / TypeFlow.rotate(). Page titles, anchor/section titles, HTML-aware preview content, and the rotating placeholder default to zoom-in-space, left direction, 2ms speed, and no cursor.
import { HawkSearch } from '@staticcanvas/hawk';
import { HawkAnimationTypeflow } from '@staticcanvas/hawk/animation-typeflow';

HawkSearch.registerAnimation('typeflow', HawkAnimationTypeflow);
new HawkSearch({ index: '/pagefind/', animation: 'typeflow' });

The adapter imports the released @staticcanvas/typeflow package directly. For advanced configuration, createHawkAnimationTypeflow(TypeFlow, options) remains available as a factory.

TypeFlow configuration groups

Each option is optional. Overrides apply to the named surface; omitted fields keep the built-in defaults. npm and JSR expose the same groups.

Option Type Default Surface
title TypeFlowConfig zoom-in-space, left, 2 ms, no cursor, reduced-motion support Page titles
anchorTitle TypeFlowConfig Same baseline as title Heading and section titles
content TypeFlowConfig Same reveal baseline, HTML enabled with the preview tag allow-list Preview content
rotate TypeFlowRotateConfig 3000 ms hold, 200 ms pause, baseline type reveal, end erase at 2 ms Placeholder overlay

rotate.typeConfig and rotate.eraseConfig are merged separately with their defaults. Controllers returned by any animated surface are passed back to the driver’s stop() before rerendering or destroying the search instance.

TypeFlow reveal styles

The factory accepts complete TypeFlow configuration objects for title, anchorTitle, content, and the rotating placeholder’s nested typeConfig and eraseConfig.

Style Supported surfaces Behaviour
char Type Character-by-character reveal.
word Type Word-by-word reveal.
scramble Type and erase Resolves text through a configurable glyph set.
fade-trail Type and erase Adds a trailing opacity ramp.
word-fade Type and erase Fades words without changing their final layout.
float-in-top, float-in-bottom Type and erase Moves words vertically while changing opacity.
float-in-left, float-in-right Type and erase Moves words horizontally while changing opacity.
zoom-in-space Type and erase Uses perspective depth and scale.
end, start, center, fade, instant Erase Additional erase-only strategies.

Titles and rotating placeholders use typeStyle: 'zoom-in-space', direction: 'left', speed: 2, and cursor: ''. A default preview renders its complete content as soon as it is available. A short reveal plays on the blocks already visible in the preview pane. Scrolling or interacting with the preview clears that effect, and reduced motion skips it.

Changing the preview’s content effect settings opts into TypeFlow’s full content animation. char and scramble are the most computationally expensive typeStyle values — char updates the DOM per character and scramble re-renders the full string on every tick — so both have a practical minimum speed below which frames start dropping, and neither is used by any of Hawk’s own defaults, the docs search, or the playground’s curated typeStyle pickers. Both remain fully available by passing typeStyle: 'char' / 'scramble' explicitly to createHawkAnimationTypeflow for anyone who wants that effect and is prepared to raise speed accordingly.

import TypeFlow from '@staticcanvas/typeflow';
import { createHawkAnimationTypeflow } from '@staticcanvas/hawk/animation-typeflow';

const animation = createHawkAnimationTypeflow(TypeFlow, {
  title: { typeStyle: 'word-fade', direction: 'center' },
  anchorTitle: { typeStyle: 'zoom-in-space', wordOrder: 'random' },
  content: { typeStyle: 'float-in-bottom', wordMotionDistance: 18 },
  rotate: {
    typeConfig: { typeStyle: 'fade-trail' },
    eraseConfig: { eraseStyle: 'float-in-top' },
  },
});

HawkSearch.registerAnimation('typeflow-spatial', animation);
new HawkSearch({ index: '/pagefind/', animation: 'typeflow-spatial' });

Omit animation to prefer 'typeflow' when it’s registered, falling back to 'instant' otherwise. Pass animation: false to force instant regardless.

Rotating placeholder text

rotatePlaceholder sat in the interface unused by core until config.rotatingPlaceholders wired it up:

new HawkSearch({
  index: '/pagefind/',
  rotatingPlaceholders: ['Try "getting started"...', 'Try "tabs"...', 'Try "theming"...'],
});

Cycles through the list in a .hawk-input-ghost overlay positioned over the search input — a native <input> placeholder attribute can’t be typed character-by-character by a driver, since it’s browser-rendered, not a DOM node. Only runs while the modal is open and the input is empty; never in the background while closed, and stops the instant there’s real input value. With the instant driver, “rotating” just shows the first string statically (no timers) — real cycling needs the typeflow driver.

Writing your own

Any object implementing the four methods works. A CSS-fade driver in a few lines:

HawkSearch.registerAnimation('fade', {
  typeTitle(el, text) {
    el.style.opacity = 0;
    el.textContent = text;
    requestAnimationFrame(() => {
      el.style.transition = 'opacity .2s';
      el.style.opacity = 1;
    });
    return null;
  },
  typeContent(el, html) {
    el.innerHTML = html;
    return null;
  },
  rotatePlaceholder(el, strings) {
    el.textContent = strings[0] ?? '';
    return null;
  },
  stop() {},
});