@its-thepoe/better-colors 1.0.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 ADDED
@@ -0,0 +1,9 @@
1
+ # @its-thepoe/better-colors
2
+
3
+ **Agent Skill** for better-colors.
4
+
5
+ Install:
6
+
7
+ ```bash
8
+ npx @its-thepoe/skills@latest install better-colors
9
+ ```
package/SKILL.md ADDED
@@ -0,0 +1,91 @@
1
+ ---
2
+ name: better-colors
3
+ description: OKLCH color space for web projects. Convert hex/rgb/hsl to oklch, generate palettes, check contrast, handle gamut boundaries, and theme with Tailwind v4. Triggers on oklch, color conversion, palette generation, contrast ratio, gamut, display p3, design tokens, hue drift, chroma, dark mode colors.
4
+ ---
5
+
6
+ # OKLCH Colors
7
+
8
+ OKLCH is a perceptually uniform color space where the numbers actually mean what you think they mean. Most color problems in CSS (broken palettes, failing contrast, hue drift) come from using color spaces that don't match how we see. OKLCH fixes the model so the tools work. To explore interactively, visit [oklch.fyi](https://oklch.fyi).
9
+
10
+ ## Quick Reference
11
+
12
+ | Category | When to use | Reference |
13
+ | --- | --- | --- |
14
+ | Conversion | Hex/rgb/hsl to oklch | [color-conversion.md](color-conversion.md) |
15
+ | Palettes | Generate scales, multi-hue, dark mode | [palette-generation.md](palette-generation.md) |
16
+ | Contrast | APCA/WCAG checks, fixing failing contrast | [accessibility-contrast.md](accessibility-contrast.md) |
17
+ | Gamut & Tailwind | P3 fallbacks, `@theme` scales, gamut clamping | [gamut-and-tailwind.md](gamut-and-tailwind.md) |
18
+
19
+ ## Why OKLCH
20
+
21
+ - **Perceptual uniformity.** Equal L steps = equal brightness. `oklch(0.5 ...)` is visually mid. HSL's `lightness: 50%` varies wildly by hue.
22
+ - **Stable hue.** HSL blue shifts toward purple as lightness changes. OKLCH hue stays constant across the full lightness range.
23
+ - **Independent chroma.** Chroma is an absolute measure of colorfulness that doesn't depend on lightness. HSL saturation does.
24
+ - **Finite gamut.** Not every oklch value maps to a displayable sRGB color. High-chroma values at certain hues will clip; gamut awareness is required.
25
+
26
+ ## OKLCH Syntax
27
+
28
+ ```
29
+ oklch(L C H)
30
+ oklch(L C H / alpha)
31
+ ```
32
+
33
+ | Channel | Range | Description |
34
+ | --- | --- | --- |
35
+ | L (Lightness) | 0–1 | 0 = black, 1 = white. Perceptually uniform. |
36
+ | C (Chroma) | 0–~0.4 | Colorfulness. 0 = gray. Max depends on L and H. |
37
+ | H (Hue) | 0–360 | Hue angle in degrees. |
38
+ | alpha | 0–1 | Optional transparency. Slash syntax. |
39
+
40
+ ```css
41
+ oklch(0.637 0.237 25.331)
42
+ oklch(0.8 0.05 200 / 0.5)
43
+ ```
44
+
45
+ **Formatting:** L and C use 3 decimal places, H uses up to 3. Drop trailing zeros. Format `-0` as `0`. Browser support: Baseline 2023, 96%+ global coverage.
46
+
47
+ ## Key Thresholds
48
+
49
+ | Rule | Value |
50
+ | --- | --- |
51
+ | Light/dark boundary | L > 0.6 = light background → use dark text |
52
+ | Lightness gap (light bg) | Foreground L < 0.35 when background L > 0.9 |
53
+ | Lightness gap (dark bg) | Foreground L > 0.9 when background L < 0.25 |
54
+ | Hue drift threshold | > 10° spread across palette steps = visible drift |
55
+ | APCA body text | \|Lc\| >= 75 minimum, >= 90 preferred |
56
+ | APCA non-body text | \|Lc\| >= 60 minimum |
57
+ | WCAG 2 normal text | 4.5:1 AA, 7:1 AAA |
58
+ | Contrast fix | Adjust L only; chroma has negligible effect |
59
+
60
+ ## Review Output Format
61
+
62
+ Always present color changes as a markdown table with **Before** and **After** columns. Include **every color that was changed**, not just a subset. Never list findings as separate "Before:" / "After:" lines outside of a table.
63
+
64
+ | Before | After |
65
+ | --- | --- |
66
+ | `color: #3b82f6` | `color: oklch(0.623 0.188 259.815)` |
67
+ | Same absolute C across hues | Same C% of each hue's max chroma |
68
+ | No sRGB fallback for P3 color | `@media (color-gamut: p3)` wrapper |
69
+
70
+ This keeps feedback scannable and diff-friendly. Each row is a self-contained change the developer can act on independently.
71
+
72
+ ## Common Mistakes
73
+
74
+ | Issue | Fix |
75
+ | --- | --- |
76
+ | Hex/rgb/hsl color in new code | Convert to `oklch()` |
77
+ | HSL palette ramp with hue drift | Rebuild with constant oklch hue |
78
+ | Failing contrast (check foreground vs its background using APCA) | Adjust oklch L channel, keep C and H |
79
+ | High chroma without gamut check | Clamp to max chroma for the L/H in sRGB |
80
+ | Same absolute C across different hues | Use same C% (percentage of max) for consistent vividness |
81
+ | P3 color without sRGB fallback | Add `@media (color-gamut: p3)` pattern |
82
+ | Dark mode with hand-picked colors | Derive from light palette by reversing L mapping |
83
+ | Hex in Tailwind v4 `@theme` | Convert to oklch values |
84
+ | Alpha with comma syntax | Use slash: `oklch(L C H / alpha)` |
85
+
86
+ ## Reference Files
87
+
88
+ - [color-conversion.md](color-conversion.md): Supported formats, conversion examples, bulk conversion rules, what to leave alone
89
+ - [palette-generation.md](palette-generation.md): Scale convention, generation algorithm, multi-hue palettes, dark mode, why not HSL
90
+ - [accessibility-contrast.md](accessibility-contrast.md): APCA and WCAG 2 thresholds, fixing contrast with L, lightness gap guide, hue drift detection
91
+ - [gamut-and-tailwind.md](gamut-and-tailwind.md): sRGB vs P3, gamut clamping, CSS fallback patterns, Tailwind v4 @theme and migration
@@ -0,0 +1,79 @@
1
+ # Accessibility & Contrast
2
+
3
+ Contrast is always measured between a **foreground color** (text, icon, or UI element) and the **background color** it sits on. When checking contrast, identify the background the element will be rendered against, typically the nearest parent's background color.
4
+
5
+ ## APCA thresholds (recommended)
6
+
7
+ APCA (Accessible Perceptual Contrast Algorithm) is more perceptually accurate than WCAG 2 and pairs naturally with oklch since both are grounded in perceptual lightness. Use APCA as the default.
8
+
9
+ Lc (Lightness Contrast) measures the perceived contrast between foreground and background. These levels are simplified from APCA's full font-size/weight lookup table:
10
+
11
+ | Content Type | Minimum | Preferred |
12
+ | --- | --- | --- |
13
+ | Body text (columns/blocks of text) | Lc 75 | Lc 90 |
14
+ | Non-body text (labels, headlines) | Lc 60 | Lc 75 |
15
+ | Large text (≥36px) | Lc 45 | Lc 60 |
16
+ | UI components | Lc 30 | n/a |
17
+
18
+ APCA's Lc value is signed: positive means dark text on a light background, negative means light text on a dark background. Use the absolute value for threshold comparison.
19
+
20
+ ## WCAG 2 thresholds (for legal compliance)
21
+
22
+ WCAG 2 is still required when making formal WCAG 2.x conformance claims. It uses a luminance ratio that can be both too strict and too lenient depending on the color pair.
23
+
24
+ | Content Type | AA | AAA |
25
+ | --- | --- | --- |
26
+ | Normal text (<18px / <14px bold) | 4.5:1 | 7:1 |
27
+ | Large text (>=18px / >=14px bold) | 3:1 | 4.5:1 |
28
+ | UI components & graphical objects | 3:1 | n/a |
29
+
30
+ ## Fixing contrast with oklch
31
+
32
+ In hex/rgb, fixing contrast means trial and error across three channels. In oklch, contrast is controlled by **lightness (L) alone**: adjust the L distance between the foreground and its background:
33
+
34
+ ```css
35
+ /* Failing: text too close in lightness to its background (Lc ≈ 50) */
36
+ color: oklch(0.65 0.08 250); /* foreground */
37
+ background: oklch(0.95 0.02 250); /* background */
38
+
39
+ /* Fix: darken the text, keep C and H unchanged (Lc ≈ 90) */
40
+ color: oklch(0.3 0.08 250); /* foreground: more L distance */
41
+ background: oklch(0.95 0.02 250); /* background: unchanged */
42
+ ```
43
+
44
+ Note that mid-lightness backgrounds cap the achievable contrast: on a background of L 0.75, even pure black text only reaches about Lc 60; body text needs a background near the light or dark extreme.
45
+
46
+ Chroma has negligible effect on contrast: always adjust L, never C.
47
+
48
+ ## Quick lightness gap guide
49
+
50
+ For body text (targeting |Lc| >= 75):
51
+
52
+ - **Light background (L > 0.9):** foreground L should be below 0.35
53
+ - **Dark background (L < 0.25):** foreground L should be above 0.9
54
+
55
+ The gap is asymmetric because APCA scores light-on-dark lower than the mirrored dark-on-light pair. These are approximations; always verify with an actual contrast calculation.
56
+
57
+ ## Light vs dark color detection
58
+
59
+ A color is considered light when its oklch lightness exceeds 0.6:
60
+
61
+ ```
62
+ if L > 0.6 → use dark text on this background
63
+ if L <= 0.6 → use light text on this background
64
+ ```
65
+
66
+ ## Hue drift detection
67
+
68
+ To detect hue drift in an existing HSL palette:
69
+
70
+ 1. Convert each step to oklch
71
+ 2. Compare the H values across steps
72
+ 3. If the hue spread is greater than 10°, the palette has visible drift
73
+
74
+ ```css
75
+ /* HSL blue ramp: hue shifts toward purple */
76
+ hsl(240, 80%, 20%) → oklch H ≈ 269
77
+ hsl(240, 80%, 50%) → oklch H ≈ 267
78
+ hsl(240, 80%, 90%) → oklch H ≈ 285 /* shifted 18° */
79
+ ```
@@ -0,0 +1,53 @@
1
+ # Color Conversion
2
+
3
+ When converting existing colors to oklch, convert the color values but leave everything else unchanged: don't change gradient interpolation, don't restructure the CSS.
4
+
5
+ ## Supported input formats
6
+
7
+ | Format | Examples |
8
+ | --- | --- |
9
+ | Hex (3/6/8-digit) | `#f00`, `#ff0000`, `#ff000080` |
10
+ | `rgb()` / `rgba()` | `rgb(255, 0, 0)`, `rgba(255, 0, 0, 0.5)` |
11
+ | `hsl()` / `hsla()` | `hsl(0, 100%, 50%)`, `hsla(0, 100%, 50%, 0.5)` |
12
+
13
+ ## Conversion examples
14
+
15
+ ```css
16
+ /* Before */
17
+ color: #3b82f6;
18
+ background: #1e293b;
19
+ border-color: #e2e8f0;
20
+
21
+ /* After */
22
+ color: oklch(0.623 0.188 259.815);
23
+ background: oklch(0.279 0.037 260.031);
24
+ border-color: oklch(0.929 0.013 255.508);
25
+ ```
26
+
27
+ ```css
28
+ /* Before */
29
+ color: rgb(59, 130, 246);
30
+ border: 1px solid rgba(0, 0, 0, 0.1);
31
+
32
+ /* After */
33
+ color: oklch(0.623 0.188 259.815);
34
+ border: 1px solid oklch(0 0 0 / 0.1);
35
+ ```
36
+
37
+ Alpha uses the forward-slash syntax. Omit alpha when it's 1.
38
+
39
+ ## What to leave alone
40
+
41
+ - CSS keywords: `currentColor`, `inherit`, `initial`, `unset`, `transparent`
42
+ - Gradient interpolation methods: only convert the color stops, not the function itself
43
+ - Colors in third-party library configs that expect hex input
44
+
45
+ ## Bulk conversion
46
+
47
+ When converting an entire file:
48
+
49
+ 1. Replace all hex colors with their oklch equivalents
50
+ 2. Replace all `rgb()`, `rgba()`, `hsl()`, `hsla()` function calls
51
+ 3. Leave gradient functions unchanged; only convert the color stops within them
52
+ 4. Leave `currentColor`, `inherit`, `transparent`, and CSS keywords as-is
53
+ 5. Preserve comments and formatting
@@ -0,0 +1,103 @@
1
+ # Gamut Awareness & Tailwind v4
2
+
3
+ ## sRGB vs Display P3
4
+
5
+ Every sRGB color exists within Display P3, but not every P3 color exists within sRGB. Display P3 covers ~50% more colors.
6
+
7
+ ## Max chroma varies by lightness and hue
8
+
9
+ The gamut boundary is irregular. At L=0.5 in sRGB:
10
+
11
+ - Highest chroma: purple (H ≈ 285) at C ≈ 0.29
12
+ - Red-orange (H ≈ 0-30): C ≈ 0.20
13
+ - Lowest chroma: cyan (H ≈ 195) at C ≈ 0.09
14
+
15
+ The peak hue shifts with lightness. At L=0.7 magenta peaks, at L=0.9 green peaks. Cyan consistently has the lowest max chroma.
16
+
17
+ ## Gamut checking
18
+
19
+ If a color's chroma exceeds the maximum for its L/H/space, it clips. The fix: reduce chroma while keeping L and H constant.
20
+
21
+ ```css
22
+ /* Out of sRGB gamut */
23
+ oklch(0.7 0.35 150)
24
+
25
+ /* Clamped to max chroma */
26
+ oklch(0.7 0.22 150)
27
+ ```
28
+
29
+ ## CSS fallback patterns
30
+
31
+ ```css
32
+ /* sRGB fallback for all browsers */
33
+ .accent {
34
+ color: oklch(0.7 0.2 150);
35
+ }
36
+
37
+ /* P3 enhancement for wider gamut displays */
38
+ @media (color-gamut: p3) {
39
+ .accent {
40
+ color: oklch(0.7 0.3 150);
41
+ }
42
+ }
43
+ ```
44
+
45
+ For browsers without oklch support:
46
+
47
+ ```css
48
+ .accent {
49
+ color: #4ade80;
50
+ }
51
+
52
+ @supports (color: oklch(0 0 0)) {
53
+ .accent {
54
+ color: oklch(0.7 0.2 150);
55
+ }
56
+
57
+ @media (color-gamut: p3) {
58
+ .accent {
59
+ color: oklch(0.7 0.3 150);
60
+ }
61
+ }
62
+ }
63
+ ```
64
+
65
+ ## Tailwind v4
66
+
67
+ Tailwind CSS v4 defines its default palette in oklch. Custom themes should follow the same convention.
68
+
69
+ ### Custom color scale with @theme
70
+
71
+ ```css
72
+ @theme {
73
+ --color-brand-50: oklch(0.971 0.012 250);
74
+ --color-brand-100: oklch(0.932 0.028 250);
75
+ --color-brand-200: oklch(0.882 0.048 250);
76
+ --color-brand-300: oklch(0.812 0.078 250);
77
+ --color-brand-400: oklch(0.722 0.148 250);
78
+ --color-brand-500: oklch(0.623 0.188 250);
79
+ --color-brand-600: oklch(0.535 0.168 250);
80
+ --color-brand-700: oklch(0.445 0.138 250);
81
+ --color-brand-800: oklch(0.362 0.108 250);
82
+ --color-brand-900: oklch(0.289 0.078 250);
83
+ --color-brand-950: oklch(0.215 0.048 250);
84
+ }
85
+ ```
86
+
87
+ This gives you `bg-brand-500`, `text-brand-200`, etc. automatically.
88
+
89
+ ### Opacity modifiers
90
+
91
+ Tailwind's opacity modifier syntax works with oklch:
92
+
93
+ ```html
94
+ <div class="bg-brand-500/50"></div>
95
+ <!-- Compiles to: oklch(0.623 0.188 250 / 0.5) -->
96
+ ```
97
+
98
+ ### Migrating existing themes
99
+
100
+ 1. Convert all hex values in `@theme` to oklch
101
+ 2. Replace any `theme()` references that used hex
102
+ 3. Test dark mode: oklch values may look slightly different due to perceptual accuracy
103
+ 4. Check for hardcoded hex in component code and convert those too
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@its-thepoe/better-colors",
3
+ "version": "1.0.0",
4
+ "description": "Agent Skill: better-colors.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "agent-skills",
8
+ "better-colors",
9
+ "design",
10
+ "ui"
11
+ ],
12
+ "files": [
13
+ "README.md",
14
+ "SKILL.md",
15
+ "*.md",
16
+ "package.json"
17
+ ],
18
+ "exports": {
19
+ ".": "./SKILL.md",
20
+ "./SKILL.md": "./SKILL.md"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/its-thepoe/skills.git",
25
+ "directory": "design/better-colors"
26
+ }
27
+ }
@@ -0,0 +1,93 @@
1
+ # Palette Generation
2
+
3
+ ## The scale convention
4
+
5
+ Design system palettes use a numeric scale from 50 (lightest) to 950 (darkest). The standard labels by palette size:
6
+
7
+ | Size | Labels |
8
+ | --- | --- |
9
+ | 5 | 100, 300, 500, 700, 900 |
10
+ | 9 | 50, 100, 200, 300, 500, 700, 800, 900, 950 |
11
+ | 11 | 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950 |
12
+
13
+ 9 steps is the standard default (matches Tailwind).
14
+
15
+ ## Algorithm
16
+
17
+ Given a base color with lightness (L), chroma percentage, and hue (H):
18
+
19
+ **Step 1. Lightness bounds:**
20
+
21
+ ```
22
+ delta = 0.4
23
+ minL = max(0.05, baseL - delta)
24
+ maxL = min(0.95, baseL + delta)
25
+ ```
26
+
27
+ Lightness is clamped to [0.05, 0.95] to avoid pure black/white which have zero chroma.
28
+
29
+ **Step 2. Distribute lightness** evenly from maxL (lightest, label 50) to minL (darkest, label 950).
30
+
31
+ **Step 3. Clamp chroma per step.** Each lightness level has a different maximum chroma for a given hue and color space:
32
+
33
+ ```
34
+ maxChroma = findMaxChroma(step[i].L, hue, colorSpace)
35
+ step[i].C = (chromaPercentage / 100) * maxChroma
36
+ ```
37
+
38
+ This ensures every step is within gamut. High-chroma base colors will have lower chroma at the lightest and darkest ends; this is correct and expected.
39
+
40
+ ## CSS variable output
41
+
42
+ ```css
43
+ :root {
44
+ --color-50: oklch(0.971 0.012 250);
45
+ --color-100: oklch(0.932 0.028 250);
46
+ --color-200: oklch(0.882 0.048 250);
47
+ --color-300: oklch(0.812 0.078 250);
48
+ --color-500: oklch(0.623 0.188 250);
49
+ --color-700: oklch(0.445 0.138 250);
50
+ --color-800: oklch(0.362 0.108 250);
51
+ --color-900: oklch(0.289 0.078 250);
52
+ --color-950: oklch(0.215 0.048 250);
53
+ }
54
+ ```
55
+
56
+ ## Multi-hue palettes
57
+
58
+ When generating palettes for multiple hues, use the same **lightness** and **chroma percentage** for all. Same L guarantees equal perceived brightness. Same chroma percentage (not absolute chroma) guarantees equal vividness relative to each hue's maximum.
59
+
60
+ ```css
61
+ :root {
62
+ /* Same L, same C% (80% of max): different absolute C per hue */
63
+ --blue-500: oklch(0.623 0.141 250); /* 80% of max 0.176 */
64
+ --green-500: oklch(0.623 0.157 145); /* 80% of max 0.196 */
65
+ --red-500: oklch(0.623 0.202 25); /* 80% of max 0.253 */
66
+ }
67
+ ```
68
+
69
+ Different hues have different max chroma at the same lightness. Using the same absolute C value across hues would make some appear more vivid than others.
70
+
71
+ ## Dark mode
72
+
73
+ Reverse the palette mapping so that the lightest step becomes the darkest and vice versa:
74
+
75
+ ```css
76
+ :root {
77
+ --color-bg: var(--color-50);
78
+ --color-text: var(--color-950);
79
+ }
80
+
81
+ .dark {
82
+ --color-bg: var(--color-950);
83
+ --color-text: var(--color-50);
84
+ }
85
+ ```
86
+
87
+ This works because oklch's perceptual uniformity means equal L steps in both directions produce equally readable results.
88
+
89
+ ## Why not HSL palettes?
90
+
91
+ **Hue drift:** `hsl(240, 80%, 20%)` and `hsl(240, 80%, 90%)` are not the same perceptual hue. The light variant shifts ~16° toward purple. OKLCH hue is stable.
92
+
93
+ **Brightness inconsistency:** `hsl(60, 100%, 50%)` (yellow) and `hsl(240, 100%, 50%)` (blue) have the same HSL lightness but wildly different perceived brightness.