# `ixfx-led`

An LED indicator component with color mixing and brightness, blink, and pulse modes.

```html
<ixfx-led></ixfx-led>
<ixfx-led lit color="oklch(60% 0.2 120)"></ixfx-led>
<ixfx-led glow lit color="oklch(60% 0.2 120)"></ixfx-led>
<ixfx-led mode="blink" rate="300"></ixfx-led>
<ixfx-led mode="pulse" value="1" attack-time="40" release-time="400"></ixfx-led>
```

### Properties / attributes

| Attribute / Property | Type     | Default                  | Description                            |
|----------------------|----------|--------------------------|----------------------------------------|
| `mode`               | `'brightness' \| 'blink' \| 'pulse'` | `'brightness'` | Operating mode (see below) |
| `lit`                | `boolean`| `false`                  | Whether the LED is illuminated (shortcut for `value` 0/1) |
| `value`              | `number` | `0`                      | Value 0-1. In `brightness` mode sets brightness directly; in `pulse` mode it is the envelope peak |
| `color`              | `string` | `'oklch(50% 0.15 25)'`   | LED color (oklch recommended)          |
| `glow`               | `boolean`| `false`                  | Render a domed LED with a specular highlight and a coloured bloom that grows with `value` |
| `blinking`           | `boolean`| `false`                  | Legacy alias for `mode="blink"`        |
| `rate`               | `number` | `500`                    | `blink` mode interval in milliseconds  |
| `attackTime` / `attack-time`   | `number` | `40`  | `pulse` mode rise time in milliseconds (0 → instant) |
| `releaseTime` / `release-time` | `number` | `400` | `pulse` mode decay time in milliseconds (0 → instant) |
| `pulseRetrigger` / `pulse-retrigger` | `boolean` | `false` | When set, a re-`pulse()` restarts the envelope from 0; when unset, the attack ramps from the envelope's current level |

### Modes

- **`brightness`** (default) — `value` sets the brightness.
- **`blink`** — the LED toggles on/off every `rate` ms. Setting the legacy `blinking` attribute selects this mode.
- **`pulse`** — the LED sits unlit until `pulse()` is called. Each call runs a linear attack/release envelope up to `value` (over `attack-time`) and back down to 0 (over `release-time`). Calling `pulse()` again restarts the envelope: from 0 if `pulse-retrigger` is set, otherwise the attack ramps up from wherever the envelope currently sits (a seamless retrigger mid-decay).

### Methods

| Method    | Description |
|-----------|-------------|
| `pulse()` | Trigger the `pulse`-mode envelope. No-op unless `mode` is `pulse`. |

### CSS custom properties

| Property | Default | Description       |
|----------|---------|-------------------|
| `--size` | `1ex`   | LED diameter      |
| `--colour` | `oklch(50% 0.15 25)` | LED colour (overrides the `color` attribute) |

Colour resolves as `--colour` → `color` attribute → default. The `glow` bloom uses the same resolved colour.

### Usage notes

The LED brightness is calculated as `color-mix(color, white, (1 - value) * 50%)`. Set `value` to 0 for off and 1 for fully lit.

For blinking, setting `rate` below 300ms adjusts the transition duration automatically for smoother animation.

### TypeScript types

```ts
import type { LedMode } from './led.js';

// LED color is a CSS color string
led.color = 'oklch(70% 0.15 200)';
led.value = 0.75; // 75% lit

// Pulse mode
led.mode = 'pulse';
led.value = 1;
led.attackTime = 20;
led.releaseTime = 600;
led.pulse(); // fire the envelope
```