# Color Picker

> A real colour input with a proper panel: saturation square, hue slider, hex field, presets, eyedropper and copy. Pick a preset and the handles glide to it.

Forms · color, picker, form, hex · HTML, CSS, vanilla JS · no dependencies · updated 2026-10-16
Demo: https://kodza.dev/components/color-picker/

## Files

The code below, served as files: byte for byte what the Kodza site copies (the CSS includes its theme guard).

- [`kodza-color-picker.css`](https://kodza.dev/registry/color-picker/kodza-color-picker.css) · 20.0 KB
- [`kodza-color-picker.js`](https://kodza.dev/registry/color-picker/kodza-color-picker.js) · 14.2 KB
- [`kodza-color-picker.html`](https://kodza.dev/registry/color-picker/kodza-color-picker.html) · 0.2 KB · the markup, to adapt and paste into your page

**Can you run shell commands? Download the CSS and the JS, don't retype them.** Retyping costs thousands of tokens and can drop or change lines of the CSS. Put the files where your stack expects them (Use it says where: change the `-o` paths):

```bash
curl -fsSL --create-dirs -o kodza/kodza-color-picker.css https://kodza.dev/registry/color-picker/kodza-color-picker.css
curl -fsSL --create-dirs -o kodza/kodza-color-picker.js https://kodza.dev/registry/color-picker/kodza-color-picker.js
```

Then load the files from your page as Use it shows, instead of pasting the content. The HTML is the part you adapt (text, links, modifiers): paste it from the Code section. Copy the CSS and the JS from the Code section only if you can't run commands, exactly as they are. (Windows PowerShell: `curl.exe`.)

## API

- Root: `.kodza-color`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-color-bg: #ffffff`
  - `--kz-color-fg: #0a0a0a`
  - `--kz-color-muted: rgba(10, 10, 10, 0.6)`
  - `--kz-color-line: rgba(10, 10, 10, 0.14)`
  - `--kz-color-line-hover: rgba(10, 10, 10, 0.3)`
  - `--kz-color-soft: rgba(10, 10, 10, 0.06)`
  - `--kz-color-shadow: 0 18px 40px -16px rgba(10, 10, 10, 0.3)`
  - `--kz-color-height: 56px`
  - `--kz-color-radius: 12px`
  - `--kz-color-pad: 16px`
  - `--kz-color-ease: cubic-bezier(0.22, 1, 0.36, 1)`
- Attributes:
  - `data-hex`
  - `data-presets`
- Lifecycle: `kodza:init` / `kodza:destroy` on `document`, with `{ detail: { root } }` to target a container.

## Keyboard

What each key does, by where the focus is. Keep it working when you adapt the HTML: same elements, same classes.

- On the colour square (focus in `.kodza-color__area`):
  - `ArrowLeft` / `ArrowRight`: Less or more saturation, Shift for bigger steps
  - `ArrowUp` / `ArrowDown`: Brighter or darker, Shift for bigger steps
- On the hue slider (focus in `.kodza-color__hue`):
  - `ArrowLeft` / `ArrowDown`: Hue one degree lower
  - `ArrowRight` / `ArrowUp`: Hue one degree higher
- In the hex code field (focus in `.kodza-color__input`):
  - a letter: Types a #rgb or #rrggbb code, applied once valid
- On the field (focus in `.kodza-color__trigger`):
  - `Enter` / `Space`: Opens the panel, focus on the colour square
- Anywhere in it, while it's open (focus in `.kodza-color`, while `.kodza-color.is-open` is on the page):
  - `Escape`: Closes it, focus back on the field

## Dark mode

The values Kodza uses on a dark background (`#0a0a0a`). For a page that follows the system theme, add them after the component's CSS:

```css
@media (prefers-color-scheme: dark) {
  .kodza-color {
    --kz-color-bg: #161616;
    --kz-color-fg: #f2f2f0;
    --kz-color-muted: rgba(242, 242, 240, 0.62);
    --kz-color-line: rgba(255, 255, 255, 0.14);
    --kz-color-line-hover: rgba(255, 255, 255, 0.3);
    --kz-color-soft: rgba(255, 255, 255, 0.08);
    --kz-color-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.8);
  }
}
```

A site with its own theme switch puts the same rules under its dark selector instead (`[data-theme="dark"] .kodza-color { … }`); a single dark section, under that section's class.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-color-picker.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-color-picker.css">`. Without a shell, paste it in a `<style>` in `<head>` instead. It only touches `kodza-` classes.
- HTML: where the component goes. Paste it as many times as you need: instances never interfere.
- JS: `kodza/kodza-color-picker.js`, loaded with `<script src="kodza/kodza-color-picker.js" defer></script>` in `<head>`. Without a shell, paste it in a `<script>` before `</body>` (or in `<head>`: it waits for the page). One copy per page, whatever the number of instances.
- Restyle with the `--kz-…` variables, set on the component's root element itself (the root declares its own defaults, so a value on an ancestor is ignored), and with the modifiers / attributes listed under API.
- Font: it takes the page's own. The Kodza look is Geist: `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Content added later (AJAX navigation, a SPA route, a builder preview): start it with `document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: container } }))`; before removing it, the same call with `'kodza:destroy'` stops it and puts the original markup back.

### Claude artifact (claude.ai)

- Paste the CSS in a `<style>` and the JS in a `<script>` at the end, in the artifact itself: it loads stylesheets only from Google Fonts and scripts only from a few CDNs, so no `<link>` or `<script src>` to Kodza.
- Writing the artifact file with a shell? Insert the downloaded files (Files) with a command instead of retyping them: a line `KODZA-CSS` alone inside the `<style>`, `KODZA-JS` inside the `<script>`, then `sed -e '/^KODZA-CSS$/{r kodza/kodza-color-picker.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-color-picker.js' -e 'd' -e '}' page.html > artifact.html`.
- Font: load Geist from Google Fonts (allowed): `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Dark mode: the viewer sets `data-theme="dark"` or `"light"` on `<html>`, or nothing when it follows the system. Write the Dark mode rules twice: inside `@media (prefers-color-scheme: dark)` with `:root:not([data-theme="light"])` in front of each selector, and with `:root[data-theme="dark"]` in front of each selector.
- Forms: there is nowhere to send them. Handle `submit` in your script with `event.preventDefault()` and show the result in the page.

### WordPress

- HTML: a **Custom HTML** block (or a pattern / template part). WordPress keeps this markup as it is only for users allowed to post unfiltered HTML (Administrators; Super Admins on multisite): for anyone else it strips tags such as `<svg>`, `<input>` or `<dialog>`, so add it from the theme (a pattern or template part) instead.
- CSS and JS: the downloaded files go in the theme, under `wp-content/themes/<your-theme>/kodza/` (the child theme if there is one), enqueued from its functions.php (or a code-snippets plugin):
  ```php
  add_action('wp_enqueue_scripts', function () {
    $dir = get_stylesheet_directory() . '/kodza/';
    $uri = get_stylesheet_directory_uri() . '/kodza/';
    wp_enqueue_style('kodza-color-picker', $uri . 'kodza-color-picker.css', [], filemtime($dir . 'kodza-color-picker.css'));
    wp_enqueue_script('kodza-color-picker', $uri . 'kodza-color-picker.js', [], filemtime($dir . 'kodza-color-picker.js'), true);
  });
  ```
  Scoped to `kodza-` classes, the CSS never touches the theme. One copy of the JS, whatever the number of blocks.
- No access to the theme files? The CSS can also go, as it is, in **Appearance → Customize → Additional CSS** (classic theme) or **Styles → Additional CSS** in the Site Editor (block theme).
- Theme with AJAX page transitions: fire `kodza:init` on the new content after each swap (and `kodza:destroy` on the old one).
- Performance plugin (WP Rocket, LiteSpeed Cache, Perfmatters…) with **Delay JavaScript execution** turned on: add `kodza` to the scripts it must not delay. Otherwise the component waits for the visitor's first scroll, tap or mouse move, and that first click can be lost.
- Colours: by default, match the theme's palette. After the component's CSS, point these variables at the theme's colours, on the component root, Kodza's value as the fallback:
  `.kodza-color { --kz-color-fg: var(TEXT, #0a0a0a); --kz-color-bg: var(BACKGROUND, #ffffff); }`
  TEXT, BACKGROUND and ACCENT (the colour the theme fills its own buttons with) are the theme's own colour variables — block themes (theme.json, like Twenty Twenty-Five): `--wp--preset--color--contrast`, `--wp--preset--color--base`, `--wp--preset--color--contrast` (they fill their buttons with it; their accent-1… colours are decorative); Astra: `--ast-global-color-2`, `--ast-global-color-4`, `--ast-global-color-0`; Kadence: `--global-palette3`, `--global-palette9`, `--global-palette1`; GeneratePress: `--contrast`, `--base-3`, `--accent`; Blocksy: `--theme-palette-color-4`, `--theme-palette-color-8`, `--theme-palette-color-1`. Use only these names, and only if the site really has them (the theme's CSS, or Styles → Colors): the `--wp--preset--color--black`, `--white`, `--vivid-…` that WordPress adds everywhere are not the theme's palette. Another theme, or one without these variables (Hello Elementor, OceanWP): leave the variables alone, it keeps Kodza's monochrome; same when the developer asks for monochrome or the Kodza look. Leave the translucent greys (`rgba(10, 10, 10, …)`) as they are: they suit any light background. On a dark palette, set the other variables from Dark mode too.
- WordPress turns straight quotes and `--` into typographic ones in the text of a Custom HTML block (not inside `<code>` or `<pre>`).

#### With Elementor

- HTML: an **HTML** widget (Elementor shows it to administrators only). It keeps the code exactly as pasted, straight quotes included.
- CSS and JS: as above. Elementor's Site Settings → Theme Style styles every button, field, link and image of the page, components included; the theme guard at the end of the CSS keeps the component's buttons, fields and link colours as they are.
- The Elementor editor redraws each widget after the page has loaded: without the script below, the component stays still in the editor preview (the published page works). Add it once per site, in the footer like the component's script (`kodza/elementor-editor.js`, or a code-snippets plugin):

```js
// Kodza in the Elementor editor: the editor redraws each HTML widget after the page has loaded.
// Start Kodza in what it draws, stop it in what it replaces or removes. Once per site.
window.addEventListener('elementor/frontend/init', () => {
  if (!elementorFrontend.isEditMode()) return;
  class KodzaWidget extends elementorModules.frontend.handlers.Base {
    onInit() {
      super.onInit();
      this.kodza = [...this.$element[0].children];
      document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: this.$element[0] } }));
    }
    onDestroy() {
      super.onDestroy();
      this.kodza.forEach((root) => document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } })));
    }
  }
  elementorFrontend.elementsHandler.attachHandler('html', KodzaWidget);
});
```

- No child theme: everything can go in the HTML widget instead, `<style>` with the CSS, the HTML, then `<script>` with the JS. It works on the page and in the editor without the script above.

### Shopify

- Files: `assets/kodza-color-picker.css` and `assets/kodza-color-picker.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-color-picker.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-color-picker.js' | asset_url }}" defer></script>`, then the HTML.
- The theme editor re-renders sections: restart them with
  `document.addEventListener('shopify:section:load', (e) => document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: e.target } })));`
  and the same with `shopify:section:unload` → `kodza:destroy`.

### React / Next.js

- Files, side by side (e.g. in `components/kodza/`): `ColorPicker.tsx` (below), the CSS block under Code saved as `color-picker.css` and the JS block as `color-picker.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { ColorPicker } from '@/components/kodza/ColorPicker';` then `<ColorPicker>Brand colour</ColorPicker>`. Props: `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-color-bg': … }}`), `children` (the text, plain), `className`, `style` and the other props of its `<label>` (`onClick`, `aria-…`).
- Next.js App Router: it is a Client Component already (`'use client'`). Pages Router: Next.js takes global CSS only in `pages/_app`, so move the `import './color-picker.css'` line there.
- Safe under StrictMode, client-side navigation and prop changes: when a prop changes, the `key` gives React a fresh element, `kodza:destroy` stops the script on the old one and `kodza:init` starts it on the new one.

```tsx
'use client';
// Kodza — Color Picker, for React. From https://kodza.dev/components/color-picker/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: color-picker.css and color-picker.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './color-picker.css';

export type ColorPickerProps = Omit<ComponentPropsWithoutRef<'label'>, "children" | "vars"> & {
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #ffffff */
    "--kz-color-bg"?: string | number;
    /** default: #0a0a0a */
    "--kz-color-fg"?: string | number;
    /** default: rgba(10, 10, 10, 0.6) */
    "--kz-color-muted"?: string | number;
    /** default: rgba(10, 10, 10, 0.14) */
    "--kz-color-line"?: string | number;
    /** default: rgba(10, 10, 10, 0.3) */
    "--kz-color-line-hover"?: string | number;
    /** default: rgba(10, 10, 10, 0.06) */
    "--kz-color-soft"?: string | number;
    /** default: 0 18px 40px -16px rgba(10, 10, 10, 0.3) */
    "--kz-color-shadow"?: string | number;
    /** default: 56px */
    "--kz-color-height"?: string | number;
    /** default: 12px */
    "--kz-color-radius"?: string | number;
    /** default: 16px */
    "--kz-color-pad"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-color-ease"?: string | number;
  };
  /** The text, plain: the script reads it and rebuilds the markup around it */
  children?: string;
  className?: string;
};

export function ColorPicker({ vars, children = "Brand colour", className, style, ...rest }: ColorPickerProps) {
  const ref = useRef<ComponentRef<'label'>>(null);
  const classes = ["kodza-color", className].filter(Boolean).join(' ');
  // Everything the markup is made of: when it changes, React gets a fresh element (see the top)
  const key = JSON.stringify([classes, vars, children, style, rest]);

  // Starts the script on this element once React has rendered it, stops it when it goes
  useEffect(() => {
    const root = ref.current;
    let live = true;
    // @ts-ignore: a plain script, no types to find
    import('./color-picker.js').then(() => {
      if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
    });
    return () => {
      live = false;
      document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
    };
  }, [key]);

  return (
    <label key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <span className="kodza-color__label">{children}</span>
      {' '}
      <input className="kodza-color__native" type="color" name="brand" defaultValue="#ff5c35" />
    </label>
  );
}
```

## Code

```html
<label class="kodza-color">
  <span class="kodza-color__label">Brand colour</span>
  <input class="kodza-color__native" type="color" name="brand" value="#ff5c35">
</label>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Color Picker
   A real colour input, dressed up: the field shows a swatch and the hex code, and a
   panel opens with a saturation / brightness square, a hue slider, a hex field, presets, the
   browser's eyedropper (where it exists) and a copy button. Pick a preset and the colour
   travels there: both handles glide and the square turns with them. The real input stays in step.
   The panel itself stays monochrome. Same box as Select.
   Everything is tuned with the --kz-color-* variables. */
.kodza-color {
  --kz-color-bg: #ffffff;
  --kz-color-fg: #0a0a0a;
  --kz-color-muted: rgba(10, 10, 10, 0.6);
  --kz-color-line: rgba(10, 10, 10, 0.14);
  --kz-color-line-hover: rgba(10, 10, 10, 0.3);
  --kz-color-soft: rgba(10, 10, 10, 0.06);
  --kz-color-shadow: 0 18px 40px -16px rgba(10, 10, 10, 0.3);
  --kz-color-height: 56px;
  --kz-color-radius: 12px;
  --kz-color-pad: 16px;
  --kz-color-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --kz-color-value: #ff5c35;
  --kz-color-hue: #ff3300;

  position: relative;
  display: block;
  width: 100%;
  max-width: 280px;
  /* The closed panel keeps its size, ready to unroll, but never lengthens the page */
  contain: layout;
  /* A number, not auto, so it can wait for the panel to roll up before dropping back */
  z-index: 0;
  transition: z-index 0s linear 0.4s;
  color: var(--kz-color-fg);
}

/* Open, the field rises above what follows it (its panel included) */
.kodza-color.is-open {
  z-index: 20;
  transition-delay: 0s;
}

.kodza-color__label {
  position: absolute;
  top: 10px;
  left: 52px;
  z-index: 1;
  color: var(--kz-color-muted);
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
}

.kodza-color:not(.is-ready) .kodza-color__label {
  left: var(--kz-color-pad);
}

/* Without JS: the native colour input, in the box */
.kodza-color__native {
  display: block;
  width: 100%;
  height: var(--kz-color-height);
  padding: 26px var(--kz-color-pad) 8px;
  border: 0;
  border-radius: var(--kz-color-radius);
  background: var(--kz-color-bg);
  box-shadow: inset 0 0 0 1px var(--kz-color-line);
  box-sizing: border-box;
  cursor: pointer;
}

.kodza-color.is-ready .kodza-color__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  clip-path: inset(50%);
}

.kodza-color__trigger {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  width: 100%;
  height: var(--kz-color-height);
  padding: 0 var(--kz-color-pad) 9px 52px;
  border: 0;
  border-radius: var(--kz-color-radius);
  background: var(--kz-color-bg);
  box-shadow: inset 0 0 0 1px var(--kz-color-line);
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 22px;
  text-align: left;
  cursor: pointer;
  transition: box-shadow 0.25s ease;
}

.kodza-color__trigger:hover {
  box-shadow: inset 0 0 0 1px var(--kz-color-line-hover);
}

.kodza-color__trigger:focus-visible,
.kodza-color.is-open .kodza-color__trigger {
  outline: none;
  box-shadow: inset 0 0 0 1.5px var(--kz-color-fg), 0 0 0 4px var(--kz-color-soft);
}

/* The swatch blends into the new colour */
.kodza-color__swatch {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--kz-color-value);
  box-shadow: inset 0 0 0 1px var(--kz-color-line);
  transition: background-color 0.35s ease;
}

.kodza-color__hex {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* The panel */
.kodza-color__pop {
  position: absolute;
  top: calc(var(--kz-color-height) + 8px);
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  width: 260px;
  padding: 12px;
  border-radius: 16px;
  background: var(--kz-color-bg);
  box-shadow: 0 0 0 1px var(--kz-color-line), var(--kz-color-shadow);
  box-sizing: border-box;
  visibility: hidden;
  opacity: 0;
  clip-path: inset(0 0 100% 0 round 16px);
  transform: translateY(-4px);
  transition:
    clip-path 0.4s var(--kz-color-ease),
    opacity 0.2s ease,
    transform 0.4s var(--kz-color-ease),
    visibility 0s linear 0.4s;
}

.kodza-color.is-open .kodza-color__pop {
  visibility: visible;
  opacity: 1;
  clip-path: inset(-40px -40px -60px -40px round 16px);
  transform: none;
  transition-delay: 0s;
}

/* Not enough room below: it unrolls upwards, from the top of the field */
.kodza-color.is-above .kodza-color__pop {
  top: auto;
  bottom: calc(var(--kz-color-height) + 8px);
  clip-path: inset(100% 0 0 0 round 16px);
  transform: translateY(4px);
}

.kodza-color.is-above.is-open .kodza-color__pop {
  clip-path: inset(-60px -40px -40px -40px round 16px);
  transform: none;
}

/* Saturation (left to right) and brightness (bottom to top) over the hue */
.kodza-color__area {
  position: relative;
  height: 150px;
  border-radius: 10px;
  background:
    linear-gradient(to top, #000, transparent),
    linear-gradient(to right, #fff, var(--kz-color-hue));
  cursor: crosshair;
  touch-action: none;
}

.kodza-color__area:focus-visible,
.kodza-color__hue:focus-visible {
  outline: 2px solid var(--kz-color-fg);
  outline-offset: 2px;
}

.kodza-color__handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: var(--kz-color-value);
  box-shadow: 0 0 0 2.5px #ffffff, 0 1px 6px rgba(10, 10, 10, 0.4);
  pointer-events: none;
  /* translate, not transform: scale then grows the handle in place instead of
     stretching its offset (it would drift away from the pointer while dragging) */
  translate: var(--kz-x, 0) var(--kz-y, 0);
  transition: scale 0.2s var(--kz-color-ease);
}

.kodza-color.is-dragging .kodza-color__handle {
  scale: 1.25;
}

/* The hue: a real range input, restyled */
.kodza-color__hue {
  width: 100%;
  height: 14px;
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  cursor: pointer;
  appearance: none;
}

.kodza-color__hue::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--kz-color-hue);
  box-shadow: 0 0 0 2.5px #ffffff, 0 1px 6px rgba(10, 10, 10, 0.4);
  appearance: none;
}

.kodza-color__hue::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: var(--kz-color-hue);
  box-shadow: 0 0 0 2.5px #ffffff, 0 1px 6px rgba(10, 10, 10, 0.4);
}

.kodza-color__row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.kodza-color__input {
  box-sizing: border-box;
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: var(--kz-color-soft);
  color: inherit;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  text-transform: uppercase;
  outline: none;
}

.kodza-color__input:focus-visible {
  box-shadow: inset 0 0 0 1.5px var(--kz-color-fg);
}

.kodza-color__tool {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--kz-color-soft);
  color: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.kodza-color__tool:hover {
  background: var(--kz-color-line);
}

.kodza-color__tool:focus-visible,
.kodza-color__preset:focus-visible {
  outline: 2px solid var(--kz-color-fg);
  outline-offset: 2px;
}

.kodza-color__tool svg {
  grid-area: 1 / 1;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.2s ease, transform 0.3s var(--kz-color-ease);
}

/* Copied: the copy icon gives way to a tick */
.kodza-color__tool .kodza-color__done {
  opacity: 0;
  transform: scale(0.6);
}

.kodza-color__tool.is-done .kodza-color__done {
  opacity: 1;
  transform: none;
}

.kodza-color__tool.is-done .kodza-color__idle {
  opacity: 0;
  transform: scale(0.6);
}

/* minmax(0, 1fr): an empty button has a minimum width of its own, and eight of them would
   push the row (and everything above it) past the panel's edge */
.kodza-color__presets {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}

.kodza-color__preset {
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px var(--kz-color-line);
  cursor: pointer;
  transition: transform 0.2s var(--kz-color-ease);
}

.kodza-color__preset:hover {
  transform: scale(1.12);
}

.kodza-color__preset[aria-pressed="true"] {
  box-shadow: inset 0 0 0 1px var(--kz-color-line), 0 0 0 2px var(--kz-color-bg), 0 0 0 3.5px var(--kz-color-fg);
}

@media (prefers-reduced-motion: reduce) {
  .kodza-color__trigger,
  .kodza-color__swatch,
  .kodza-color__handle,
  .kodza-color__pop,
  .kodza-color__tool svg,
  .kodza-color__preset {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

/* Theming example — on a dark background:
.dark-section .kodza-color {
  --kz-color-bg: #161616;
  --kz-color-fg: #f2f2f0;
  --kz-color-muted: rgba(242, 242, 240, 0.62);
  --kz-color-line: rgba(255, 255, 255, 0.14);
  --kz-color-line-hover: rgba(255, 255, 255, 0.3);
  --kz-color-soft: rgba(255, 255, 255, 0.08);
  --kz-color-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.8);
}
*/

/* kodza-guard daf21f55ce9a — generated by Kodza, do not edit.
   Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
   component. :not(#_) is always true and weighs as much as an id, so these lines win over
   theme rules made of classes and tags. Customise the component through its --kz-* variables. */

/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */

:where(.kodza-color__native):not(#_) {
  position: revert;
}

:where(.kodza-color__trigger):not(#_) {
  outline: revert;
}

:where(.kodza-color__area):not(#_),
:where(.kodza-color__hue):not(#_),
:where(.kodza-color__tool):not(#_),
:where(.kodza-color__preset):not(#_) {
  outline: revert;
  outline-offset: revert;
}

:where(.kodza-color__input):not(#_) {
  box-shadow: revert;
}

/* What the browser gives, on everything the component leaves to it */

.kodza-color:not(#_) {
  border: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-height: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-color__label:not(#_),
.kodza-color__swatch:not(#_),
.kodza-color__hex:not(#_),
.kodza-color__handle:not(#_),
.kodza-color__row:not(#_),
.kodza-color__presets:not(#_) {
  box-sizing: revert;
}

.kodza-color__native:not(#_) {
  margin: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  float: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-color__trigger:not(#_) {
  margin: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-color__area:not(#_) {
  box-sizing: revert;
  box-shadow: revert;
}

.kodza-color__hue:not(#_) {
  border: revert;
  padding: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  box-shadow: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-color__input:not(#_) {
  margin: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  float: revert;
  position: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-color__tool:not(#_) {
  margin: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  box-shadow: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-color__idle:not(#_),
.kodza-color__done:not(#_),
.kodza-color__tool svg:where(:not([class*="kodza-"])):not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-color__preset:not(#_) {
  margin: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-color__hue:not(#_):where(:not([hidden])),
.kodza-color__input:not(#_):where(:not([hidden])),
.kodza-color__idle:not(#_):where(:not([hidden])),
.kodza-color__done:not(#_):where(:not([hidden])),
.kodza-color__preset:not(#_):where(:not([hidden])),
.kodza-color__tool svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-color__hue:not(#_):where([hidden]),
.kodza-color__input:not(#_):where([hidden]),
.kodza-color__idle:not(#_):where([hidden]),
.kodza-color__done:not(#_):where([hidden]),
.kodza-color__preset:not(#_):where([hidden]),
.kodza-color__tool svg:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
  display: none;
}

/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */

.kodza-color:not(#_) {
  position: relative;
  display: block;
  transition: z-index 0s linear 0.4s;
  color: var(--kz-color-fg);
}

.kodza-color:not(#_) {
  width: min(100%, 280px);
}

.kodza-color.is-open:not(#_) {
  transition-delay: 0s;
}

.kodza-color__native:not(#_) {
  display: block;
  width: 100%;
  height: var(--kz-color-height);
  padding: 26px var(--kz-color-pad) 8px;
  border: 0;
  border-radius: var(--kz-color-radius);
  background: var(--kz-color-bg);
  box-shadow: inset 0 0 0 1px var(--kz-color-line);
  box-sizing: border-box;
  cursor: pointer;
}

.kodza-color.is-ready .kodza-color__native:not(#_) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  clip-path: inset(50%);
}

.kodza-color__trigger:not(#_) {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  width: 100%;
  height: var(--kz-color-height);
  padding: 0 var(--kz-color-pad) 9px 52px;
  border: 0;
  border-radius: var(--kz-color-radius);
  background: var(--kz-color-bg);
  box-shadow: inset 0 0 0 1px var(--kz-color-line);
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 22px;
  text-align: left;
  cursor: pointer;
  transition: box-shadow 0.25s ease;
}

.kodza-color__trigger:hover:not(#_) {
  box-shadow: inset 0 0 0 1px var(--kz-color-line-hover);
}

.kodza-color__trigger:focus-visible:not(#_),
.kodza-color.is-open .kodza-color__trigger:not(#_) {
  outline: none;
  box-shadow: inset 0 0 0 1.5px var(--kz-color-fg), 0 0 0 4px var(--kz-color-soft);
}

.kodza-color__area:focus-visible:not(#_) {
  outline: 2px solid var(--kz-color-fg);
  outline-offset: 2px;
}

.kodza-color__hue:focus-visible:not(#_) {
  outline: 2px solid var(--kz-color-fg);
  outline-offset: 2px;
}

.kodza-color__hue:not(#_) {
  width: 100%;
  height: 14px;
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  cursor: pointer;
  appearance: none;
}

.kodza-color__hue:not(#_)::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--kz-color-hue);
  box-shadow: 0 0 0 2.5px #ffffff, 0 1px 6px rgba(10, 10, 10, 0.4);
  appearance: none;
}

.kodza-color__input:not(#_) {
  box-sizing: border-box;
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: var(--kz-color-soft);
  color: inherit;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  text-transform: uppercase;
  outline: none;
}

.kodza-color__input:focus-visible:not(#_) {
  box-shadow: inset 0 0 0 1.5px var(--kz-color-fg);
}

.kodza-color__tool:not(#_) {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--kz-color-soft);
  color: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.kodza-color__tool:hover:not(#_) {
  background: var(--kz-color-line);
}

.kodza-color__tool:focus-visible:not(#_),
.kodza-color__preset:focus-visible:not(#_) {
  outline: 2px solid var(--kz-color-fg);
  outline-offset: 2px;
}

.kodza-color__tool svg:not(#_) {
  transition: opacity 0.2s ease, transform 0.3s var(--kz-color-ease);
}

.kodza-color__preset:not(#_) {
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px var(--kz-color-line);
  cursor: pointer;
  transition: transform 0.2s var(--kz-color-ease);
}

.kodza-color__preset:hover:not(#_) {
  transform: scale(1.12);
}

.kodza-color__preset[aria-pressed="true"]:not(#_) {
  box-shadow: inset 0 0 0 1px var(--kz-color-line), 0 0 0 2px var(--kz-color-bg), 0 0 0 3.5px var(--kz-color-fg);
}

@media (prefers-reduced-motion: reduce) {
  .kodza-color__trigger:not(#_),
  .kodza-color__preset:not(#_) {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kodza-color__tool svg:not(#_) {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}
```

```js
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Color Picker
// Builds a field and a panel over the real <input type="color"> and keeps it in step (firing
// "input" while you drag and "change" when you let go). The square sets saturation and
// brightness (drag, or arrows: Shift for bigger steps), the slider sets the hue, the hex field
// takes any #rgb or #rrggbb. Presets come from data-presets (comma-separated hex codes).
(() => {
  const SELECTOR = '.kodza-color';
  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  const PRESETS = ['#0a0a0a', '#f2f2f0', '#ff5c35', '#f5b700', '#12b76a', '#14b8a6', '#2f6bff', '#a855f7'];
  const clamp = (v, a, b) => Math.min(b, Math.max(a, v));

  const hexToRgb = (hex) => {
    let h = hex.replace('#', '').trim();
    if (h.length === 3) h = [...h].map((c) => c + c).join('');
    if (!/^[0-9a-f]{6}$/i.test(h)) return null;
    return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
  };
  const rgbToHex = (rgb) => `#${rgb.map((v) => Math.round(v).toString(16).padStart(2, '0')).join('')}`;
  const rgbToHsv = ([r, g, b]) => {
    r /= 255; g /= 255; b /= 255;
    const max = Math.max(r, g, b);
    const d = max - Math.min(r, g, b);
    let h = 0;
    if (d) h = max === r ? ((g - b) / d) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
    return [(h * 60 + 360) % 360, max ? d / max : 0, max];
  };
  const hsvToRgb = ([h, s, v]) => {
    const f = (n) => {
      const k = (n + h / 60) % 6;
      return (v - v * s * clamp(Math.min(k, 4 - k), 0, 1)) * 255;
    };
    return [f(5), f(3), f(1)];
  };
  const copy = '<svg class="kodza-color__idle" viewBox="0 0 16 16" aria-hidden="true"><rect x="5.5" y="5.5" width="8" height="8" rx="1.5"/><path d="M10.5 5.5V3.8c0-.7-.6-1.3-1.3-1.3H3.8c-.7 0-1.3.6-1.3 1.3v5.4c0 .7.6 1.3 1.3 1.3h1.7"/></svg><svg class="kodza-color__done" viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7"/></svg>';
  const dropper = '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10.5 2.5l3 3-1.5 1.5-3-3zM9 4l3 3-6 6H3v-3z"/></svg>';
  let uid = 0;

  // One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
  function mount(root, signal) {
    const native = root.querySelector('.kodza-color__native');
    const label = root.querySelector('.kodza-color__label');
    if (!native) return;
    const id = `kodza-color-${++uid}`;
    const presets = (root.dataset.presets || '').split(',').map((s) => s.trim()).filter((s) => hexToRgb(s));

    const trigger = document.createElement('button');
    trigger.type = 'button';
    trigger.className = 'kodza-color__trigger';
    trigger.setAttribute('aria-haspopup', 'dialog');
    trigger.setAttribute('aria-expanded', 'false');
    if (label) {
      label.id = `${id}-label`;
      trigger.setAttribute('aria-labelledby', `${id}-label ${id}-hex`);
    }
    trigger.innerHTML = `<span class="kodza-color__swatch" aria-hidden="true"></span><span class="kodza-color__hex" id="${id}-hex"></span>`;

    const pop = document.createElement('div');
    pop.className = 'kodza-color__pop';
    pop.setAttribute('role', 'dialog');
    pop.setAttribute('aria-label', label ? `${label.textContent}: pick a colour` : 'Pick a colour');
    pop.innerHTML = `
      <div class="kodza-color__area" tabindex="0" role="slider" aria-valuemin="0" aria-valuemax="100" aria-label="Saturation and brightness"><span class="kodza-color__handle"></span></div>
      <input class="kodza-color__hue" type="range" min="0" max="359" step="1" aria-label="Hue">
      <div class="kodza-color__row">
        <input class="kodza-color__input" type="text" maxlength="7" spellcheck="false" autocomplete="off" aria-label="Hex code">
        ${'EyeDropper' in window ? `<button class="kodza-color__tool" type="button" data-tool="drop" aria-label="Pick a colour from the screen">${dropper}</button>` : ''}
        <button class="kodza-color__tool" type="button" data-tool="copy" aria-label="Copy the hex code">${copy}</button>
      </div>
      <div class="kodza-color__presets"></div>`;
    native.after(trigger, pop);
    native.tabIndex = -1;
    native.setAttribute('aria-hidden', 'true');
    const area = pop.querySelector('.kodza-color__area');
    const handle = pop.querySelector('.kodza-color__handle');
    const hue = pop.querySelector('.kodza-color__hue');
    const input = pop.querySelector('.kodza-color__input');
    const hexText = trigger.querySelector('.kodza-color__hex');
    const presetBox = pop.querySelector('.kodza-color__presets');
    const presetButtons = (presets.length ? presets : PRESETS).map((hex) => {
      const button = document.createElement('button');
      button.type = 'button';
      button.className = 'kodza-color__preset';
      button.style.background = hex;
      button.dataset.hex = hex.toLowerCase();
      button.setAttribute('aria-label', hex);
      presetBox.append(button);
      return button;
    });

    let hsv = rgbToHsv(hexToRgb(native.value) || [0, 0, 0]);

    // Everything follows the current colour
    const paint = ({ fromInput = false } = {}) => {
      const hex = rgbToHex(hsvToRgb(hsv));
      root.style.setProperty('--kz-color-value', hex);
      root.style.setProperty('--kz-color-hue', rgbToHex(hsvToRgb([hsv[0], 1, 1])));
      handle.style.setProperty('--kz-x', `${hsv[1] * area.clientWidth}px`);
      handle.style.setProperty('--kz-y', `${(1 - hsv[2]) * area.clientHeight}px`);
      hue.value = Math.round(hsv[0]);
      hexText.textContent = hex;
      if (!fromInput) input.value = hex;
      area.setAttribute('aria-valuenow', Math.round(hsv[2] * 100));
      area.setAttribute('aria-valuetext', `Saturation ${Math.round(hsv[1] * 100)}%, brightness ${Math.round(hsv[2] * 100)}%`);
      presetButtons.forEach((button) => button.setAttribute('aria-pressed', String(button.dataset.hex === hex)));
      return hex;
    };
    const commit = (kind) => {
      native.value = rgbToHex(hsvToRgb(hsv));
      native.dispatchEvent(new Event(kind, { bubbles: true }));
    };

    // A preset or a typed code: the colour itself travels there (hue by the shortest way), so
    // both handles and the square glide together instead of jumping
    let glide = 0;
    const glideTo = (hex) => {
      const rgb = hexToRgb(hex);
      if (!rgb) return;
      const next = rgbToHsv(rgb);
      // Greys keep the current hue, so the hue handle does not fly away for nothing
      if (next[1] === 0) next[0] = hsv[0];
      cancelAnimationFrame(glide);
      const from = [...hsv];
      const turn = ((next[0] - from[0] + 540) % 360) - 180;
      const done = () => {
        hsv = next;
        paint();
        commit('input');
        commit('change');
      };
      if (reduceMotion) return done();
      const start = performance.now();
      const step = (now) => {
        if (signal.aborted) return;
        const t = Math.min(1, (now - start) / 450);
        const e = 1 - Math.pow(1 - t, 3);
        hsv = [(from[0] + turn * e + 360) % 360, from[1] + (next[1] - from[1]) * e, from[2] + (next[2] - from[2]) * e];
        paint();
        if (t < 1) glide = requestAnimationFrame(step);
        else done();
      };
      glide = requestAnimationFrame(step);
    };

    // Dragging in the square
    const fromPointer = (event) => {
      const box = area.getBoundingClientRect();
      hsv = [hsv[0], clamp((event.clientX - box.left) / box.width, 0, 1), 1 - clamp((event.clientY - box.top) / box.height, 0, 1)];
      paint();
      commit('input');
    };
    area.addEventListener('pointerdown', (event) => {
      area.setPointerCapture(event.pointerId);
      root.classList.add('is-dragging');
      cancelAnimationFrame(glide);
      fromPointer(event);
    }, { signal });
    area.addEventListener('pointermove', (event) => area.hasPointerCapture(event.pointerId) && fromPointer(event), { signal });
    const stop = (event) => {
      if (!area.hasPointerCapture(event.pointerId)) return;
      area.releasePointerCapture(event.pointerId);
      root.classList.remove('is-dragging');
      commit('change');
    };
    area.addEventListener('pointerup', stop, { signal });
    area.addEventListener('pointercancel', stop, { signal });
    area.addEventListener('keydown', (event) => {
      const step = event.shiftKey ? 0.1 : 0.01;
      const moves = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, step], ArrowDown: [0, -step] };
      if (!moves[event.key]) return;
      event.preventDefault();
      hsv = [hsv[0], clamp(hsv[1] + moves[event.key][0], 0, 1), clamp(hsv[2] + moves[event.key][1], 0, 1)];
      paint();
      commit('input');
      commit('change');
    }, { signal });

    hue.addEventListener('input', () => {
      hsv = [Number(hue.value), hsv[1], hsv[2]];
      paint();
      commit('input');
    }, { signal });
    hue.addEventListener('change', () => commit('change'), { signal });

    input.addEventListener('input', () => {
      const value = input.value.startsWith('#') ? input.value : `#${input.value}`;
      if (hexToRgb(value) && (value.length === 4 || value.length === 7)) {
        hsv = rgbToHsv(hexToRgb(value));
        paint({ fromInput: true });
        commit('input');
      }
    }, { signal });
    input.addEventListener('change', () => {
      paint();
      commit('change');
    }, { signal });

    presetButtons.forEach((button) => button.addEventListener('click', () => glideTo(button.dataset.hex), { signal }));
    pop.querySelector('[data-tool="copy"]')?.addEventListener('click', async (event) => {
      const button = event.currentTarget;
      try {
        await navigator.clipboard.writeText(rgbToHex(hsvToRgb(hsv)));
        button.classList.add('is-done');
        button.setAttribute('aria-label', 'Copied');
        setTimeout(() => {
          button.classList.remove('is-done');
          button.setAttribute('aria-label', 'Copy the hex code');
        }, 1400);
      } catch {
        input.select();
      }
    }, { signal });
    pop.querySelector('[data-tool="drop"]')?.addEventListener('click', async () => {
      try {
        const { sRGBHex } = await new window.EyeDropper().open({ signal });
        glideTo(sRGBHex);
      } catch {
        /* cancelled */
      }
    }, { signal });

    // Opening and closing
    const isOpen = () => root.classList.contains('is-open');
    // Opened from the keyboard, the focus goes into the panel; with a click, it stays put
    let viaKeyboard = false;
    trigger.addEventListener('keydown', (event) => (viaKeyboard = event.key === 'Enter' || event.key === ' '), { signal });
    trigger.addEventListener('pointerdown', () => (viaKeyboard = false), { signal });
    const open = () => {
      // Not enough room below and enough above: the panel opens upwards. A closed panel that
      // changes side gets there at once, so it always unrolls from the field
      const box = trigger.getBoundingClientRect();
      const room = pop.offsetHeight + 16;
      const above = box.bottom + room > innerHeight && box.top > room;
      if (above !== root.classList.contains('is-above')) {
        pop.style.transition = 'none';
        root.classList.toggle('is-above', above);
        void pop.offsetWidth;
        pop.style.transition = '';
      }
      root.classList.add('is-open');
      trigger.setAttribute('aria-expanded', 'true');
      paint();
      if (viaKeyboard) requestAnimationFrame(() => area.focus({ preventScroll: true }));
    };
    const close = (refocus = true) => {
      if (!isOpen()) return;
      root.classList.remove('is-open');
      trigger.setAttribute('aria-expanded', 'false');
      if (refocus) trigger.focus({ preventScroll: true });
    };
    trigger.addEventListener('click', () => (isOpen() ? close() : open()), { signal });
    // Escape closes it from the field too (opened with a click, the focus stays there)
    root.addEventListener('keydown', (event) => {
      if (event.key !== 'Escape' || !isOpen()) return;
      event.preventDefault();
      close();
    }, { signal });
    root.addEventListener('click', (event) => {
      if (trigger.contains(event.target) || pop.contains(event.target)) return;
      event.preventDefault();
      trigger.focus();
    }, { signal });
    pop.addEventListener('click', (event) => event.target.closest('button') && event.preventDefault(), { signal });
    document.addEventListener('pointerdown', (event) => !root.contains(event.target) && close(false), { signal });
    root.addEventListener('focusout', (event) => {
      if (isOpen() && event.relatedTarget && !root.contains(event.relatedTarget)) close(false);
    }, { signal });
    native.addEventListener('change', () => {
      const rgb = hexToRgb(native.value);
      if (rgb && native.value.toLowerCase() !== rgbToHex(hsvToRgb(hsv))) glideTo(native.value);
    }, { signal });

    paint();
  }

  // Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
  // event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
  // markup back. For themes and apps that swap content without a page load.
  const instances = new WeakMap();
  const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
  const init = (scope) => find(scope).forEach((root) => {
    if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
    const controller = new AbortController();
    instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
    mount(root, controller.signal);
    root.classList.add('is-ready');
  });
  const destroy = (scope) => find(scope).forEach((root) => {
    const instance = instances.get(root);
    if (!instance) return;
    instances.delete(root);
    instance.controller.abort();
    [...root.attributes].forEach((a) => root.removeAttribute(a.name));
    instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
    root.innerHTML = instance.html;
  });
  document.addEventListener('kodza:init', (event) => init(event.detail?.root));
  document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
  init();
  // Loaded in <head>, the script runs before the markup exists: once more when it is parsed
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
```

Free to use, from Kodza (https://kodza.dev).
