# Searchlight

https://docs.kleaver.ie/sfx/searchlight/

SFX

Zero dependencies

# A light that *shows your mark.*

A cone of light rises from below and ends in a bright disc on the cloud, with your logo cut out of it. It switches on a moment after the page has loaded.

## Markup

Three things carry the wiring: data-searchlight on the section, an empty .searchlight layer inside it, and data-searchlight-src, the image the light is cut by. The layer is decorative: it is hidden from assistive tech.

```
<section class="hero hero--center" data-searchlight data-searchlight-src="logo.svg"
         data-searchlight-at="0.14,0.3" data-searchlight-source="0.1,1.08" data-searchlight-size="0.1"
         data-searchlight-at-narrow="0.5,0.15" data-searchlight-source-narrow="0.5,0.4" data-searchlight-size-narrow="0.24">
  <div class="searchlight" aria-hidden="true"></div>
  <div class="container hero__content"> … </div>
</section>

<script defer src="scripts/searchlight.js"></script>   <!-- only on pages that use it -->
```

## Attributes

All on the section. Positions are fractions of the section: x from the left, y from the top.

| Attribute | Values | Default |
| --- | --- | --- |
| data-searchlight-src | the silhouette: an image whose transparency is the shape (an opaque image is used by darkness). Without it, or if it fails to load, the disc is plain. | none |
| data-searchlight-at | the disc centre, x,y | 0.8,0.26 |
| data-searchlight-source | the lamp, x,y (y above 1 is below the section) | 0.12,1.06 |
| data-searchlight-size | the disc radius as a fraction of the section's width | 0.13 |
| data-searchlight-at-narrow, -source-narrow, -size-narrow | the same three, used below 640px. Any left out falls back to its wide value. | the wide values |
| data-searchlight-delay | milliseconds after the page has loaded | 2000 |

## Tokens

The look is a token, set in the client's theme.css. Numbers are unitless.

| Token | Default | What it does |
| --- | --- | --- |
| --searchlight-color | var(--color-brand) | The colour of the light |
| --searchlight-intensity | 0.8 | 0 = off, 1 = bright, 2 = blazing |
| --searchlight-fog | 0.8 | The haze around the cone |
| --searchlight-haze | 0.6 | The cloud the disc lands on |
| --searchlight-flicker | 0.5 | The switch-on stutter and slow shimmer. 0 = steady. |
| --searchlight-pace | 1 | How fast the cloud drifts. 0 = frozen. |
| --searchlight-logo-scale | 0.62 | The silhouette's size inside the disc |
| --searchlight-logo-dark | 0.9 | How dark the silhouette is cut |
| --searchlight-focus | 0.35 | Edge softness of the disc and silhouette |
| --searchlight-fade | 1400ms | How long the static glow takes to appear |

## Placement

Light adds light, so it can wash out any text it crosses. The effect does not move out of the way of your copy: **you place it where there is none.**

- **Put the disc and the cone in empty space.** On a centred hero the margin beside the copy is clear: this page puts the disc at the left with the lamp just below it, so the cone runs up the margin and never touches a word.
- **Check it on a phone.** The copy fills the width, so there is no clear margin. Make room instead: add padding above the copy (this page does) and use -at-narrow, -source-narrow and -size-narrow to put the disc in that space with a short cone.
- **Lower the intensity** if it has to cross a heading: --searchlight-intensity: 0.4 keeps the shape and leaves the words readable.
- **Check the subtitle.** It is the text most often crossed, because it sits where the cone passes.

## Behaviour and limits

- **Opt-in.** A site whose pages have no data-searchlight gets none of its CSS or JavaScript. The script is not part of the shared bundle.
- **Reduced motion.** One lit still frame, on at once: no delay, no fade, no shimmer.
- **Without WebGL2 or JavaScript.** A static cone and disc (no silhouette) appear instead, in the same place and colour. With JavaScript they fade in at the switch-on; without it they are simply there.
- **It pauses** when it is off screen or the tab is hidden, and renders at 60% resolution.
- **Dark themes.** It adds light, so on a light background it will barely show.
- **One per page.** Only the first [data-searchlight] is drawn.
- **Decorative.** The layer is aria-hidden; anything the silhouette says must also be said in text.

## Catalog

Searchlight (in `components.css`)  ·  SFX #4  ·  see **`searchlight.html`**

| Component | Markup | Use for |
|---|---|---|
| Searchlight | `[data-searchlight]` host (usually a hero) > `.searchlight` layer (`aria-hidden`), with `data-searchlight-src` naming the silhouette image | A cone of light that rises from a lamp point and ends in a bright disc on hazy cloud, with a logo (or any silhouette) cut out of the disc. For dark themes. |

- **Attributes** (on the host): `data-searchlight-src` (the silhouette: its transparency is the shape; none = a plain disc), `data-searchlight-at="x,y"` (disc centre, default `0.8,0.26`), `-source="x,y"` (the lamp, default `0.12,1.06`; `y` above 1 is below the host), `-size` (disc radius as a fraction of the host's width, `0.13`), `-delay` (ms, `2000`), and `-at-narrow`, `-source-narrow`, `-size-narrow` used below 640px (each falls back to its wide value).
- **Tokens** (in `theme.css`): `--searchlight-color`, `-intensity`, `-fog`, `-haze`, `-flicker`, `-pace`, `-logo-scale`, `-logo-dark`, `-focus`, `-fade` (see `THEMING.md`).
- **Script:** `<script defer src="scripts/searchlight.js"></script>` on the page. WebGL2, one fullscreen triangle at 60% resolution; pauses off screen and in a hidden tab; one lit still frame with reduced motion. Without WebGL2 or JavaScript a static CSS cone and disc show instead (placed from `--sl-*` properties the script writes; the defaults without JS).
- **Placement is yours:** the light adds light and can wash out text it crosses. Put the disc and cone where there is no text, check it on a phone and use the `-narrow` attributes. There is no automatic text avoidance.
- **Limits:** dark themes only; one per page (only the first is drawn); decorative (`aria-hidden`).
- **Events:** `searchlight:refresh` on the host re-reads the attributes and tokens; `searchlight:replay` restarts the switch-on (the docs panel uses both).
- **Tuning:** `searchlight.html` has a live panel; **Copy** gives the attributes and the CSS for `theme.css`.

---
