Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 190 additions & 0 deletions cm_colors/colors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
Color Engine (Internal)
=======================
Everything you can do with CM-Colors’ internal color classes

This module provides CM-Colors' internal color engine, including
the Color and ColorPair classes.

Color
=====
Represents a single color in any supported format.

.. autoclass:: cm_colors.color.Color
:members: __init__, is_valid, rgb, error, to_hex, to_rgb_string, to_oklch
:show-inheritance:
Comment on lines +12 to +14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify autoclass directive paths match actual module structure.

The autoclass directives reference cm_colors.color.Color and cm_colors.color.ColorPair. Ensure these paths are correct and match the actual import paths in the codebase. If the classes are exported from a different location (e.g., from cm_colors import Color, ColorPair), the autoclass paths may need adjustment for Sphinx autodoc to find them correctly.

Also applies to: 71-73


🏁 Script executed:

#!/bin/bash
# Check if cm_colors/color.py exists and contains the classes
if [ -f "cm_colors/color.py" ]; then
  echo "=== cm_colors/color.py exists ==="
  rg "^class (Color|ColorPair)" cm_colors/color.py
else
  echo "=== Searching for Color and ColorPair class definitions ==="
  fd -e py | xargs rg "^class (Color|ColorPair)" | head -10
fi

# Check __init__.py to see what's exported
echo "=== Checking exports from cm_colors __init__.py ==="
if [ -f "cm_colors/__init__.py" ]; then
  cat cm_colors/__init__.py | head -30
fi

Length of output: 111


I need to investigate the project structure more thoroughly since the initial searches returned no results.


🏁 Script executed:

#!/bin/bash
# Find all Python files in the repo
echo "=== All Python files in repository ==="
fd -e py | head -20

echo -e "\n=== Project structure (first 3 levels) ==="
find . -maxdepth 3 -type d | grep -v '^\./\.' | sort | head -30

echo -e "\n=== Search for Color class definition anywhere ==="
rg "class Color" -A 2 | head -30

echo -e "\n=== Check if colors.rst exists ==="
fd -e rst colors.rst

echo -e "\n=== All .rst files ==="
fd -e rst | head -10

Length of output: 358


Let me examine the actual documentation files to understand the context.


🏁 Script executed:

#!/bin/bash
# Check the colors.rst file mentioned in the review
echo "=== Contents of cm_colors/colors.rst ==="
cat cm_colors/colors.rst

echo -e "\n=== Contents of root colors.rst ==="
cat colors.rst

echo -e "\n=== Contents of cm_colors/api.rst ==="
cat cm_colors/api.rst

echo -e "\n=== Check for any Python files or imports in cm_colors/ ==="
ls -la cm_colors/

Length of output: 12438


The autoclass directives reference Python classes that do not exist in this repository.

The repository contains only documentation files. The autoclass directives in cm_colors/colors.rst (lines 12-14 and 71-73) and cm_colors/api.rst attempt to autodocument Python classes (cm_colors.color.Color, cm_colors.color.ColorPair, and cm_colors.CMColors) that are not present in the codebase. Sphinx will fail to resolve these imports during the documentation build.

Either add the corresponding Python source files to the repository, or convert these sections to manual documentation instead of using autoclass directives.

🤖 Prompt for AI Agents
In cm_colors/colors.rst around lines 12-14 (and similarly 71-73) and in
cm_colors/api.rst, the Sphinx autoclass directives reference Python classes
(cm_colors.color.Color, cm_colors.color.ColorPair, cm_colors.CMColors) that do
not exist in the repository and will break the doc build; fix by either adding
the corresponding Python modules with those class definitions to the repo
(ensuring module paths and names match the autoclass targets and exporting the
documented members), or replace the autoclass directives with manual
documentation: remove the autoclass blocks and write explicit rst class
descriptions and member lists (methods/attributes and example usage) so the docs
no longer attempt to import missing Python code.


What it does
------------
* Parses color input: hex, rgb(), rgba(), HSL, tuples, lists…
* Converts everything into a clean RGB tuple
* Handles RGBA compositing if you pass a background
* Provides helpers (hex, CSS rgb string, OKLCH conversion)

Examples
--------

Simple parsing:

.. code-block:: python

from cm_colors.color import Color

c = Color("#7B2DC8")
print(c.rgb) # (123, 45, 200)
print(c.to_hex()) # "#7b2dc8"
print(c.to_rgb_string()) # "rgb(123, 45, 200)"

RGBA with background:

.. code-block:: python

c = Color("rgba(100, 150, 200, 0.5)", background_context=Color("#000"))
print(c.rgb) # composited RGB
Comment on lines +41 to +42
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify background_context parameter name for Color class.

The example at line 41 uses background_context as a parameter name, but this parameter name has not been verified in the codebase or official documentation. Verify whether this parameter actually exists and whether it's named correctly (e.g., could it be just background instead?).


🏁 Script executed:

#!/bin/bash
# Verify the Color class __init__ signature and background parameter
fd -e py | xargs rg "class Color" -A 20 | grep -E "(def __init__|background)" | head -20

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check repository structure and find any Python files
echo "=== Repository root contents ==="
ls -la

echo ""
echo "=== Looking for any Python files ==="
find . -name "*.py" -type f 2>/dev/null | head -20

echo ""
echo "=== Looking for cm_colors directory ==="
find . -name "cm_colors" -type d 2>/dev/null

echo ""
echo "=== Directory structure if cm_colors exists ==="
find ./cm_colors -type f 2>/dev/null | head -20

Length of output: 1103


🏁 Script executed:

#!/bin/bash
# Check for package references and configuration
echo "=== requirements.txt contents ==="
cat requirements.txt

echo ""
echo "=== conf.py - looking for autodoc and cm_colors config ==="
grep -n "cm_colors\|autodoc\|extensions" conf.py

echo ""
echo "=== Check .readthedocs.yaml for package info ==="
cat .readthedocs.yaml

Length of output: 550


🌐 Web query:

cm-colors Color class background_context parameter site:github.com

💡 Result:

Do you want me to (pick one)

  1. search GitHub for occurrences of a Color class with a background_context parameter and list matching repos/files, or
  2. explain what a background_context parameter typically does in a Color/CM-colors implementation, or
  3. show how to add/use such a parameter in your code?

🌐 Web query:

cm-colors Color class API documentation

💡 Result:

Here are the cm-colors API docs (Color-related API is exposed on the CMColors class):

  • CM-Colors API reference (CMColors class, methods like tune_colors, contrast_ratio, wcag_level, conversions, etc.). [1]
  • Main CM-Colors docs / getting started. [2]
  • PyPI package page for cm-colors (install info and releases). [3]

References
[1] CM-Colors API Reference — Comfort Mode Toolkit. (comfort-mode-toolkit.readthedocs.io)
[2] CM-Colors Library — Comfort Mode Toolkit (getting started). (comfort-mode-toolkit.readthedocs.io)
[3] cm-colors · PyPI. (pypi.org)

Would you like a brief summary of any specific method (e.g., tune_colors or parse_to_rgb)?

Citations:


🌐 Web query:

cm-colors rgba background compositing parameter

💡 Result:

Do you mean the Python package "cm-colors" and how to pass an RGBA background / compositing parameter to it — or something else (e.g., CodeMirror CSS class cm‑colors or general RGBA alpha compositing math)? Which one should I look up?


🌐 Web query:

comfort-mode-toolkit cm-colors Color class GitHub

💡 Result:

I found the CM‑Colors project (part of the Comfort Mode Toolkit) and its docs; the GitHub repo is at github.com/comfort-mode-toolkit/cm-colors (referenced from the package changelog and documentation). Key sources:

  • Project documentation / API (includes CMColors and color utilities). [1]
  • PyPI/package changelog pointing to the GitHub repo (comfort-mode-toolkit/cm-colors). [2]

If you want, I can open the GitHub repo and find the exact Color class/file path and paste the source or link to the file.

Sources:
[1] Comfort Mode Toolkit — CM‑Colors API & docs (ReadTheDocs).
[2] cm‑colors changelog / package page (references github.com/comfort-mode-toolkit/cm-colors).


🌐 Web query:

cm-colors "Color" class "rgba" python implementation

💡 Result:

Do you mean the cmap package's Color (has rgba) or the CM-Colors (cm-colors) library? Both exist:

  • cmap: its Color class stores RGBA as floats (0–1) and exposes .rgba / .rgba8 / .hex / .rgba_string etc. See the cmap docs. [1]

  • CM-Colors (cm-colors): a separate accessibility/tuning library (pip package cm-colors) — its API centers on CMColors and parse/tune functions (parse_to_rgb, contrast, conversions); it does not expose the same cmap.Color API. See the cm-colors docs and PyPI page. [2][3]

If you want, I can:

  • show the cmap.Color implementation code or example usage, or
  • show how to get an RGBA tuple from cm-colors (using parse_to_rgb) and convert to float 0–1 rgba.

References:
[1] cmap docs — Color class (RGBA properties).
[2] CM-Colors API reference (comfort-mode-toolkit.readthedocs.io).
[3] cm-colors on PyPI.


🌐 Web query:

cm-colors v0.2 Color class new

💡 Result:

I couldn't find a cm-colors v0.2 release. The latest published cm‑colors (cm_colors) release on PyPI is 0.1.0 (Aug 5, 2025); changelogs/listings show earlier 0.0.x releases but no 0.2. So there is no documented "new Color class" in v0.2. [1][2]

Sources:

  • PyPI project page (release history showing latest 0.1.0). [1]
  • Changelog/package listings (0.0.* entries; no 0.2). [2]

The documented Color and ColorPair classes do not exist in the current cm-colors package.

The latest cm-colors version on PyPI is 0.1.0, and the package uses CMColors class and utility functions like parse_to_rgb, not a Color class. The examples in this file (lines 32–42, 91–102) will fail because the Color and ColorPair classes do not exist in the actual package.

Verify whether:

  1. This documentation is for an unreleased v0.2 API that still needs implementation, or
  2. The documentation should describe the actual v0.1.0 API (CMColors, parse_to_rgb, etc.)

If documenting a v0.2 feature under development, ensure the implementation exists before merging this documentation.

🤖 Prompt for AI Agents
In cm_colors/colors.rst around lines 41–42 (and other examples at lines 32–42
and 91–102), the docs reference non-existent Color/ColorPair classes from a v0.2
API while the published package (v0.1.0) exposes CMColors and utility functions
like parse_to_rgb; update the docs to match the actual v0.1 API OR implement and
export the new Color/ColorPair classes in the codebase before landing the docs.
Specifically, either replace the example snippets with working
CMColors/parse_to_rgb usage and add a version note that examples target v0.1, or
add the missing classes (with tests) and bump the package version/release notes
so the documentation and implementation stay in sync.



Property Reference
------------------

**is_valid**
``True`` if parsing succeeded.

**rgb**
Returns ``(r, g, b)`` or ``None``.

**error**
Returns an error message if invalid.

**to_hex()**
Returns lowercase ``"#rrggbb"``.

**to_rgb_string()**
CSS-style ``"rgb(r, g, b)"``.

**to_oklch()**
Converts to OKLCH color space.


ColorPair
=========
Holds a text color and a background color, and evaluates readability.

.. autoclass:: cm_colors.color.ColorPair
:members: __init__, is_valid, errors, contrast_ratio, wcag_level, delta_e, tune_colors
:show-inheritance:

What it does
------------
* Parses both text and background colors
* Computes readability metrics:
- WCAG contrast ratio
- WCAG level (AA, AAA, FAIL)
- Delta E (visual difference)
* Fixes colors automatically using ``tune_colors()``

Examples
--------

Check readability:

.. code-block:: python

pair = ColorPair("#777", "#fff")
print(pair.contrast_ratio)
print(pair.wcag_level)

Tune colors automatically:

.. code-block:: python

pair = ColorPair("rgba(100, 100, 100, 0.5)", "white")
tuned, is_ok = pair.tune_colors()
print(tuned, is_ok)


Property Reference
------------------

**is_valid**
True if both text/background colors are valid.

**errors**
List of error messages.

**contrast_ratio**
Float value — higher = more readable.

**wcag_level**
"FAIL", "AA", "AAA", or "AA Large".

**delta_e**
CIEDE2000 difference between text + background.

**tune_colors(details=False)**
Automatically fixes colors.

Returns:

*Simple mode*::

(tuned_rgb_tuple, success_boolean)

*Details mode*::

{
"status": True/False,
"tuned_text": (r, g, b),
"wcag_level": "AA" | "AAA" | "FAIL",
"message": "...",
}


Quick Reference Card
====================

Parse any color:

.. code-block:: python

c = Color("#fa0")

Check if valid:

.. code-block:: python

if not c.is_valid:
print(c.error)

Get color formats:

.. code-block:: python

c.rgb
c.to_hex()
c.to_rgb_string()

Check color contrast:

.. code-block:: python

pair = ColorPair("#777", "#fff")
pair.contrast_ratio
pair.wcag_level

Fix colors:

.. code-block:: python

tuned, ok = pair.tune_colors()

Calculate perceptual difference:

.. code-block:: python

pair.delta_e

Convert to OKLCH:

.. code-block:: python

Color("#ff8040").to_oklch()