palette-shader 0.6.0 → 0.7.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/README.md +83 -31
- package/dist/palette-shader.d.ts +2 -2
- package/dist/palette-shader.js +296 -156
- package/dist/palette-shader.js.map +1 -1
- package/dist/palette-shader.umd.cjs +170 -47
- package/dist/palette-shader.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +93 -15
- package/src/shaders/cielab2rgb.frag.glsl +95 -0
- package/src/shaders/closestColor.frag.glsl +11 -1
- package/src/shaders/deltaE.frag.glsl +1 -32
- package/src/shaders/hwb2rgb.frag.glsl +8 -0
- package/src/types.ts +15 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# palette-shader
|
|
2
2
|
|
|
3
|
-
A dependency-free WebGL2 shader that maps any colour palette across a 3-D perceptual colour space and snaps each pixel to the nearest palette colour. Visualise how a palette distributes across
|
|
3
|
+
A dependency-free WebGL2 shader that maps any colour palette across a 3-D perceptual colour space and snaps each pixel to the nearest palette colour. Visualise how a palette distributes across more than twenty colour models — OKHsl, OKHsv, OKLab, OKLrab, OKLch, CIELab, CIELch, HSL, HSV, HWB, RGB and their D50 / polar variants — and compare results across eight distance metrics from plain RGB to CIEDE2000, all on the GPU.
|
|
4
4
|
|
|
5
5
|
[**Live demo →**](https://meodai.github.io/color-palette-shader/)
|
|
6
6
|
|
|
@@ -56,19 +56,19 @@ new PaletteViz(options?: PaletteVizOptions)
|
|
|
56
56
|
|
|
57
57
|
All options are optional. The palette defaults to a random 20-colour set.
|
|
58
58
|
|
|
59
|
-
| Option | Type | Default | Description
|
|
60
|
-
| ---------------- | ------------------- | ------------------ |
|
|
61
|
-
| `palette` | `string[]` | random | CSS colour strings (`#hex`, `rgb()`, `hsl()`, …)
|
|
62
|
-
| `container` | `HTMLElement` | `undefined` | Element the canvas is appended to. Omit and use `viz.canvas` to place it yourself
|
|
63
|
-
| `width` | `number` | `512` | Canvas width in CSS pixels
|
|
64
|
-
| `height` | `number` | `512` | Canvas height in CSS pixels
|
|
65
|
-
| `pixelRatio` | `number` | `devicePixelRatio` | Renderer pixel ratio
|
|
66
|
-
| `colorModel` | `string` | `'okhsv'` | Colour space for the visualisation (see [Colour models](#colour-models))
|
|
67
|
-
| `distanceMetric` | `string` | `'oklab'` | Distance function for nearest-colour matching (see [Distance metrics](#distance-metrics))
|
|
68
|
-
| `axis` | `'x' \| 'y' \| 'z'` | `'y'` | Which axis the `position` value controls
|
|
69
|
-
| `position` | `number` | `0` | 0–1 position along the chosen axis
|
|
70
|
-
| `invertZ` | `boolean` | `false` | Flip the lightness/value axis
|
|
71
|
-
| `showRaw` | `boolean` | `false` | Bypass nearest-colour matching (shows the raw colour space)
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
| ---------------- | ------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------ |
|
|
61
|
+
| `palette` | `string[]` | random | CSS colour strings (`#hex`, `rgb()`, `hsl()`, …) |
|
|
62
|
+
| `container` | `HTMLElement` | `undefined` | Element the canvas is appended to. Omit and use `viz.canvas` to place it yourself |
|
|
63
|
+
| `width` | `number` | `512` | Canvas width in CSS pixels |
|
|
64
|
+
| `height` | `number` | `512` | Canvas height in CSS pixels |
|
|
65
|
+
| `pixelRatio` | `number` | `devicePixelRatio` | Renderer pixel ratio |
|
|
66
|
+
| `colorModel` | `string` | `'okhsv'` | Colour space for the visualisation (see [Colour models](#colour-models)) |
|
|
67
|
+
| `distanceMetric` | `string` | `'oklab'` | Distance function for nearest-colour matching (see [Distance metrics](#distance-metrics)) |
|
|
68
|
+
| `axis` | `'x' \| 'y' \| 'z'` | `'y'` | Which axis the `position` value controls |
|
|
69
|
+
| `position` | `number` | `0` | 0–1 position along the chosen axis |
|
|
70
|
+
| `invertZ` | `boolean` | `false` | Flip the lightness/value axis |
|
|
71
|
+
| `showRaw` | `boolean` | `false` | Bypass nearest-colour matching (shows the raw colour space) |
|
|
72
72
|
| `outlineWidth` | `number` | `0` | Draw a transparent outline where palette regions meet. Width in physical pixels. `0` disables (no overhead). |
|
|
73
73
|
|
|
74
74
|
---
|
|
@@ -143,20 +143,53 @@ Cancel the animation frame, release all WebGL resources (programs, textures, fra
|
|
|
143
143
|
|
|
144
144
|
Controls the 3-D colour space the visualisation is rendered in. Polar variants (`*Polar`) map hue to angle and show a circular wheel; non-polar variants show a rectangular slice.
|
|
145
145
|
|
|
146
|
+
**OK — hue-based**
|
|
147
|
+
|
|
146
148
|
| Value | Shape | Description |
|
|
147
149
|
| -------------- | ----- | --------------------------------------------------------------------------------------------------------- |
|
|
148
150
|
| `'okhsv'` | cube | **Default.** Hue–Saturation–Value built on OKLab. Gamut-aware with perceptually uniform saturation steps. |
|
|
149
|
-
| `'okhsvPolar'` | wheel | Polar
|
|
151
|
+
| `'okhsvPolar'` | wheel | Polar form of OKHsv. |
|
|
150
152
|
| `'okhsl'` | cube | Hue–Saturation–Lightness built on OKLab. Better lightness uniformity across hues. |
|
|
151
153
|
| `'okhslPolar'` | wheel | Polar form of OKHsl. |
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
|
156
|
-
|
|
|
157
|
-
| `'
|
|
158
|
-
| `'
|
|
159
|
-
| `'
|
|
154
|
+
|
|
155
|
+
**OK — Lab / LCH**
|
|
156
|
+
|
|
157
|
+
| Value | Shape | Description |
|
|
158
|
+
| --------------- | ----- | ------------------------------------------------------------------------------------ |
|
|
159
|
+
| `'oklab'` | cube | Raw OKLab: x→a, y→b, z→L. |
|
|
160
|
+
| `'oklch'` | cube | OKLab in cylindrical LCH coordinates. Ideal for chroma or lightness slices. |
|
|
161
|
+
| `'oklchPolar'` | wheel | Polar form of OKLch. |
|
|
162
|
+
| `'oklrab'` | cube | OKLab with toe-corrected lightness (Lr). Better perceptual uniformity in dark tones. |
|
|
163
|
+
| `'oklrch'` | cube | OKLrab in cylindrical LCH coordinates. |
|
|
164
|
+
| `'oklrchPolar'` | wheel | Polar form of OKLrch. |
|
|
165
|
+
|
|
166
|
+
**CIE Lab / LCH — D65**
|
|
167
|
+
|
|
168
|
+
| Value | Shape | Description |
|
|
169
|
+
| --------------- | ----- | --------------------------------------------------------------- |
|
|
170
|
+
| `'cielab'` | cube | CIELab D65: x→a, y→b, z→L. The classic perceptual colour space. |
|
|
171
|
+
| `'cielch'` | cube | CIELab D65 in cylindrical LCH coordinates. |
|
|
172
|
+
| `'cielchPolar'` | wheel | Polar form of CIELch D65. |
|
|
173
|
+
|
|
174
|
+
**CIE Lab / LCH — D50**
|
|
175
|
+
|
|
176
|
+
| Value | Shape | Description |
|
|
177
|
+
| ------------------ | ----- | -------------------------------------------------------- |
|
|
178
|
+
| `'cielabD50'` | cube | CIELab adapted to D50 illuminant (ICC / print standard). |
|
|
179
|
+
| `'cielchD50'` | cube | CIELab D50 in cylindrical LCH coordinates. |
|
|
180
|
+
| `'cielchD50Polar'` | wheel | Polar form of CIELch D50. |
|
|
181
|
+
|
|
182
|
+
**Classic**
|
|
183
|
+
|
|
184
|
+
| Value | Shape | Description |
|
|
185
|
+
| ------------ | ----- | ---------------------------------------------------- |
|
|
186
|
+
| `'hsv'` | cube | Classic HSV. Not perceptually uniform, but familiar. |
|
|
187
|
+
| `'hsvPolar'` | wheel | Polar form of HSV. |
|
|
188
|
+
| `'hsl'` | cube | Classic HSL. |
|
|
189
|
+
| `'hslPolar'` | wheel | Polar form of HSL. |
|
|
190
|
+
| `'hwb'` | cube | HWB (Hue–Whiteness–Blackness). CSS Color 4 model. |
|
|
191
|
+
| `'hwbPolar'` | wheel | Polar form of HWB. |
|
|
192
|
+
| `'rgb'` | cube | Raw sRGB cube. Useful as a baseline. |
|
|
160
193
|
|
|
161
194
|
The OK-variants rely on Björn Ottosson's gamut-aware implementation and produce significantly more even hue distributions than the classic variants at the same GPU cost.
|
|
162
195
|
|
|
@@ -176,14 +209,33 @@ A practical starting point: use a **polar** model to get an intuitive read on hu
|
|
|
176
209
|
|
|
177
210
|
Controls how "nearest palette colour" is determined per pixel.
|
|
178
211
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
|
182
|
-
|
|
|
183
|
-
| `'
|
|
184
|
-
| `'
|
|
185
|
-
|
|
186
|
-
|
|
212
|
+
**OK**
|
|
213
|
+
|
|
214
|
+
| Value | Description | Cost |
|
|
215
|
+
| ---------- | ------------------------------------------------------------------------------------------------------- | ---- |
|
|
216
|
+
| `'oklab'` | **Default.** Euclidean distance in OKLab. Fast, perceptually uniform, excellent general-purpose choice. | low |
|
|
217
|
+
| `'oklrab'` | Euclidean in OKLab with toe-corrected lightness. Slightly better uniformity in dark tones than OKLab. | low |
|
|
218
|
+
|
|
219
|
+
**CIE — D65**
|
|
220
|
+
|
|
221
|
+
| Value | Description | Cost |
|
|
222
|
+
| -------------- | ---------------------------------------------------------------------------------------------------------- | ------ |
|
|
223
|
+
| `'deltaE76'` | Euclidean distance in CIELab D65. Identical to ΔE76. Classic standard, decent uniformity. | medium |
|
|
224
|
+
| `'deltaE94'` | CIE 1994: adds chroma and hue weighting. Better than ΔE76, cheaper than ΔE2000. | medium |
|
|
225
|
+
| `'deltaE2000'` | CIEDE2000: per-channel corrections for hue, chroma and lightness. Most accurate CIE formula, most complex. | high |
|
|
226
|
+
|
|
227
|
+
**CIE — D50**
|
|
228
|
+
|
|
229
|
+
| Value | Description | Cost |
|
|
230
|
+
| ------------- | ------------------------------------------------------------------------------- | ------ |
|
|
231
|
+
| `'cielabD50'` | Euclidean distance in CIELab D50. Useful when working in print / ICC workflows. | medium |
|
|
232
|
+
|
|
233
|
+
**Heuristic / simple**
|
|
234
|
+
|
|
235
|
+
| Value | Description | Cost |
|
|
236
|
+
| ------------------- | -------------------------------------------------------------------------------------------------------- | ------ |
|
|
237
|
+
| `'kotsarenkoRamos'` | Weighted Euclidean in sRGB. Weights R and B by mean red for quick perceptual improvement over plain RGB. | lowest |
|
|
238
|
+
| `'rgb'` | Plain Euclidean in sRGB. Not perceptually uniform. Useful as a baseline. | lowest |
|
|
187
239
|
|
|
188
240
|
---
|
|
189
241
|
|
package/dist/palette-shader.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare type ColorList = ColorString[];
|
|
|
4
4
|
|
|
5
5
|
declare type ColorString = string;
|
|
6
6
|
|
|
7
|
-
declare type DistanceMetric = 'rgb' | 'oklab' | 'deltaE76' | 'deltaE94' | 'deltaE2000' | 'kotsarenkoRamos';
|
|
7
|
+
declare type DistanceMetric = 'rgb' | 'oklab' | 'deltaE76' | 'deltaE94' | 'deltaE2000' | 'kotsarenkoRamos' | 'oklrab' | 'cielabD50';
|
|
8
8
|
|
|
9
9
|
export declare const fragmentShader: string;
|
|
10
10
|
|
|
@@ -62,6 +62,6 @@ declare type PaletteVizOptions = {
|
|
|
62
62
|
|
|
63
63
|
export declare const randomPalette: (size?: number) => ColorList;
|
|
64
64
|
|
|
65
|
-
declare type SupportedColorModels = 'rgb' | 'oklab' | 'okhsv' | 'okhsvPolar' | 'okhsl' | 'okhslPolar' | 'oklch' | 'oklchPolar' | 'hsv' | 'hsvPolar' | 'hsl' | 'hslPolar';
|
|
65
|
+
declare type SupportedColorModels = 'rgb' | 'oklab' | 'okhsv' | 'okhsvPolar' | 'okhsl' | 'okhslPolar' | 'oklch' | 'oklchPolar' | 'hsv' | 'hsvPolar' | 'hsl' | 'hslPolar' | 'hwb' | 'hwbPolar' | 'oklrab' | 'oklrch' | 'oklrchPolar' | 'cielab' | 'cielch' | 'cielchPolar' | 'cielabD50' | 'cielchD50' | 'cielchD50Polar';
|
|
66
66
|
|
|
67
67
|
export { }
|