# `ixfx-xy-pad`

A 2D touch-friendly XY pad for controlling two parameters simultaneously. Each axis supports independent linear/logarithmic scaling.

```html
<ixfx-xy-pad></ixfx-xy-pad>
<ixfx-xy-pad x-min="0" x-max="1" y-min="0" y-max="1" x-label="Volume" y-label="Pan"></ixfx-xy-pad>
```

```js
const pad = document.querySelector('ixfx-xy-pad');
pad.xMin = 0;
pad.xMax = 100;
pad.yMin = 0;
pad.yMax = 100;
pad.xScale = 'linear';
pad.yScale = 'log'; // logarithmic scaling for y axis

pad.addEventListener('input', e => {
  console.log(`x: ${e.detail.x.toFixed(2)}, y: ${e.detail.y.toFixed(2)}`);
});

pad.addEventListener('change', e => {
  console.log('drag ended:', e.detail);
});
```

### Properties / attributes

| Attribute / Property  | Type                   | Default    | Description                                  |
|-----------------------|------------------------|------------|----------------------------------------------|
| `xMin`                | `number`               | `1`        | Minimum X value                              |
| `xMax`                | `number`               | `100`      | Maximum X value                              |
| `x`                   | `number`               | `50`       | Current X value                              |
| `yMin`                | `number`               | `1`        | Minimum Y value                              |
| `yMax`                | `number`               | `100`      | Maximum Y value                              |
| `y`                   | `number`               | `50`       | Current Y value                              |
| `xScale`              | `'linear' \| 'log'`    | `'linear'` | X axis scaling                               |
| `yScale`              | `'linear' \| 'log'`    | `'linear'` | Y axis scaling                               |
| `xSnapStep`           | `number \| undefined`  | `undefined`| X axis snap granularity (`x-snap-step`)     |
| `ySnapStep`           | `number \| undefined`  | `undefined`| Y axis snap granularity (`y-snap-step`)     |
| `xLabel`              | `string`               | `'X'`      | X axis label text                            |
| `yLabel`              | `string`               | `'Y'`      | Y axis label text                            |
| `showCrosshairs`      | `boolean`              | `false`    | Show crosshair lines                         |
| `showGrid`            | `boolean`              | `false`    | Show background grid                         |
| `hideCursor`           | `boolean`              | `false`    | Hide cursor during drag                     |
| `disabled`            | `boolean`              | `false`    | Disable all interaction                     |
| `stops`               | `number \| undefined`  | `undefined`| Quantized stops for both axes               |
| `stopsX`              | `number \| undefined`  | `undefined`| Quantized stops for X axis only             |
| `stopsY`              | `number \| undefined`  | `undefined`| Quantized stops for Y axis only             |

### Events

| Event    | Detail                    | Description                            |
|----------|---------------------------|----------------------------------------|
| `input`  | `{ x: number, y: number }` | Continuously during drag               |
| `change` | `{ x: number, y: number }` | When drag ends (pointer release)       |

### Methods

| Method           | Returns                      | Description                                      |
|------------------|------------------------------|--------------------------------------------------|
| `getRelativeX()` | `number` (0–1)              | X position as fraction                           |
| `getRelativeY()` | `number` (0–1)              | Y position as fraction                           |
| `getPolar()`     | `{ radius: number, angle: number }` | Polar coordinates (radius 0–1, angle 0–2π radians, 0 = right, clockwise) |

### Keyboard navigation

Arrow keys move the position. Hold Shift for finer control (step divisor).

### CSS custom properties

| Property              | Default              | Description                           |
|-----------------------|----------------------|---------------------------------------|
| `--marker-size`       | `10cqb`             | Position marker diameter              |
| `--crosshair-color`   | `var(--surface-6)`  | Crosshair line color                  |
| `--crosshair-width`   | `2px`               | Crosshair line thickness              |
| `--crosshair-x-color` | `var(--crosshair-color)` | Vertical crosshair color        |
| `--crosshair-x-width` | `var(--crosshair-width)` | Vertical crosshair thickness   |
| `--crosshair-y-color` | `var(--crosshair-color)` | Horizontal crosshair color      |
| `--crosshair-y-width` | `var(--crosshair-width)` | Horizontal crosshair thickness |
| `--grid-color`        | `var(--surface-6)`  | Grid line color                       |
| `--grid-width`        | `1px`               | Grid line thickness                   |
| `--xy-pad-bg`         | `var(--surface-3)`  | Pad background colour                 |

### CSS properties set on host (for external use)

The component sets these custom properties on its host element during drag:

| Property   | Description                                  |
|------------|----------------------------------------------|
| `--x-pct`  | X position as 0–100 percentage              |
| `--y-pct`  | Y position as 0–100 percentage              |
| `--radius-pct` | Distance from centre as 0–100 percentage |
