pretty-color-picker 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/index.d.ts +87 -0
- package/dist/pretty-color-picker.js +3162 -0
- package/dist/pretty-color-picker.umd.cjs +77 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pretty Color Picker contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Pretty Color Picker
|
|
2
|
+
|
|
3
|
+
A perceptually accurate color picker for the modern web. Colors are stored internally as **OKLCH** (`picker.color`); Hex, RGB, HSL, and OKLCH are edit/display formats. The 2D plane is a classic **saturation × value** slice at the current hue (the layout every color picker uses), not an OKLCH chroma × lightness plane.
|
|
4
|
+
|
|
5
|
+
Native **Web Component**. Works in any framework or plain HTML.
|
|
6
|
+
|
|
7
|
+
**[Live demo](https://colors.kiira.in)** · **[GitHub](https://github.com/kiiradesign/pretty-color-picker)**
|
|
8
|
+
|
|
9
|
+
The design and interactions are inspired by [DialKit](https://joshpuckett.me/dialkit). I'm considering contributing this component upstream.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
Saturation × value color plane with hue and alpha sliders, format tabs (Hex / RGB / HSL / OKLCH), Last Used history, label scrubbing, **popover** mode (anchored to a trigger), draggable panel header, light / dark / system themes, Shadow DOM.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install pretty-color-picker
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import 'pretty-color-picker'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<pretty-color-picker value="#6366f1" theme="system" header-action="close"></pretty-color-picker>
|
|
29
|
+
|
|
30
|
+
<!-- Popover anchored to a trigger (click outside or Escape to close) -->
|
|
31
|
+
<button type="button" id="color-btn">Pick color</button>
|
|
32
|
+
<pretty-color-picker
|
|
33
|
+
value="#6366f1"
|
|
34
|
+
mode="popover"
|
|
35
|
+
anchor="#color-btn"
|
|
36
|
+
header-action="close"
|
|
37
|
+
></pretty-color-picker>
|
|
38
|
+
|
|
39
|
+
<!-- Centered floating panel (demo-style) -->
|
|
40
|
+
<pretty-color-picker value="#6366f1" movable header-action="close"></pretty-color-picker>
|
|
41
|
+
|
|
42
|
+
<!-- Without Last Used history -->
|
|
43
|
+
<pretty-color-picker value="#6366f1" history="false"></pretty-color-picker>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
| Attribute | Values | Description |
|
|
48
|
+
| --------------- | --------------------------- | ------------------------------------------------ |
|
|
49
|
+
| `value` | CSS color | Initial color |
|
|
50
|
+
| `theme` | `light` \| `dark` \| `system` | Chrome theme |
|
|
51
|
+
| `header-action` | `close` \| `theme` \| `none` | Close button, theme toggle, or no header button |
|
|
52
|
+
| `mode` | `inline` \| `popover` | `popover` = floating panel anchored to `anchor` |
|
|
53
|
+
| `anchor` | CSS selector | Trigger for popover mode (e.g. `#color-btn`) |
|
|
54
|
+
| `open` | present when visible | Popover visibility (also `show()` / `hide()`) |
|
|
55
|
+
| `movable` | present to enable | Draggable header (enabled by default in popover mode) |
|
|
56
|
+
| `history` | `false` to hide | Last Used swatch grid (on by default; hidden until the first color is committed) |
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
**Events:** `change` (`detail.color`, `detail.css`, `detail.hex`) fires while dragging sliders or scrubbing labels; field inputs commit on Enter/blur. Not fired on mount. `close` when the panel closes (`header-action="close"` or popover dismiss). `themechange` when the user clicks the built-in theme toggle (`header-action="theme"`).
|
|
60
|
+
|
|
61
|
+
**API:** `picker.value`, `picker.color` (OKLCH), `picker.theme`, `picker.headerAction`, `picker.mode`, `picker.anchor`, `picker.open`, `picker.show()`, `picker.hide()`, `picker.toggle()`, `picker.movable`, `picker.history`.
|
|
62
|
+
|
|
63
|
+
TypeScript types exported from `pretty-color-picker`.
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT. See [LICENSE](LICENSE). Icons from [Phosphor](https://phosphoricons.com) (MIT).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export declare interface ColorChangeDetail {
|
|
2
|
+
color: OklchColor;
|
|
3
|
+
css: string;
|
|
4
|
+
hex: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export declare type ColorFormat = 'hex' | 'rgb' | 'hsl' | 'oklch';
|
|
8
|
+
|
|
9
|
+
export declare const DEFAULT_COLOR: OklchColor;
|
|
10
|
+
|
|
11
|
+
export declare interface FormatField {
|
|
12
|
+
key: string;
|
|
13
|
+
label: string;
|
|
14
|
+
value: string;
|
|
15
|
+
min?: number;
|
|
16
|
+
max?: number;
|
|
17
|
+
step?: number;
|
|
18
|
+
/** Label-scrub sensitivity (value units per pixel). */
|
|
19
|
+
scrubStep?: number;
|
|
20
|
+
suffix?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export declare function formatFieldsFor(color: OklchColor, format: ColorFormat): FormatField[];
|
|
24
|
+
|
|
25
|
+
export declare function normalizeOklch(color: Partial<OklchColor>): OklchColor;
|
|
26
|
+
|
|
27
|
+
/** Internal color representation — always OKLCH (L, C, H, alpha). */
|
|
28
|
+
export declare interface OklchColor {
|
|
29
|
+
l: number;
|
|
30
|
+
c: number;
|
|
31
|
+
h: number;
|
|
32
|
+
alpha: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare function oklchFromCss(input: string): OklchColor | null;
|
|
36
|
+
|
|
37
|
+
export declare function oklchToCss(color: OklchColor): string;
|
|
38
|
+
|
|
39
|
+
export declare function oklchToHex(color: OklchColor): string;
|
|
40
|
+
|
|
41
|
+
export declare function oklchToRgbString(color: OklchColor): string;
|
|
42
|
+
|
|
43
|
+
export declare function parseFormatFields(format: ColorFormat, fields: Record<string, string>, current: OklchColor): OklchColor | null;
|
|
44
|
+
|
|
45
|
+
export declare type PickerHeaderAction = 'close' | 'theme' | 'none';
|
|
46
|
+
|
|
47
|
+
export declare type PickerTheme = 'dark' | 'light' | 'system';
|
|
48
|
+
|
|
49
|
+
export declare class PrettyColorPicker extends HTMLElement {
|
|
50
|
+
#private;
|
|
51
|
+
static get observedAttributes(): string[];
|
|
52
|
+
constructor();
|
|
53
|
+
connectedCallback(): void;
|
|
54
|
+
disconnectedCallback(): void;
|
|
55
|
+
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
56
|
+
get value(): string;
|
|
57
|
+
set value(v: string);
|
|
58
|
+
get color(): OklchColor;
|
|
59
|
+
set color(c: OklchColor);
|
|
60
|
+
get theme(): PickerTheme;
|
|
61
|
+
set theme(value: PickerTheme);
|
|
62
|
+
get headerAction(): PickerHeaderAction;
|
|
63
|
+
set headerAction(value: PickerHeaderAction);
|
|
64
|
+
get movable(): boolean;
|
|
65
|
+
set movable(value: boolean);
|
|
66
|
+
/** `inline` (default) or `popover` for a floating panel anchored to `anchor`. */
|
|
67
|
+
get mode(): 'inline' | 'popover';
|
|
68
|
+
set mode(value: 'inline' | 'popover');
|
|
69
|
+
get popoverMode(): boolean;
|
|
70
|
+
/** CSS selector or element id for the popover trigger (e.g. `#btn` or `.trigger`). */
|
|
71
|
+
get anchor(): string | null;
|
|
72
|
+
set anchor(value: string | null);
|
|
73
|
+
get open(): boolean;
|
|
74
|
+
set open(value: boolean);
|
|
75
|
+
show(): void;
|
|
76
|
+
hide(): void;
|
|
77
|
+
toggle(): void;
|
|
78
|
+
/** Last Used swatch grid — on by default; set `history="false"` to hide. */
|
|
79
|
+
get history(): boolean;
|
|
80
|
+
set history(value: boolean);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export declare interface ThemeChangeDetail {
|
|
84
|
+
theme: 'dark' | 'light';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { }
|