### Install Dependencies Source: https://github.com/gilbarbara/colorizr/blob/main/CLAUDE.md Installs project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Install Colorizr Source: https://github.com/gilbarbara/colorizr/blob/main/README.md Install the colorizr package using npm. ```bash npm i colorizr ``` -------------------------------- ### Colorizr Example Usage Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/class.mdx Demonstrates common use cases for the Colorizr class. ```APIDOC ## Example Usage ### Description Demonstrates common use cases for the Colorizr class. ### Request Example ```typescript const color = new Colorizr('#ff0044'); console.log(color.luminance); // 0.2168 console.log(color.contrast('#fff')); // 3.94 console.log(color.compare('#fff')); // { contrast: 3.94, normalAA: false, ... } console.log(color.lighten(20)); // '#ff668f' console.log(color.mix('#0066ff')); // '#bc34d7' console.log(color.format('oklch')); // 'oklch(63.269% 0.25404 19.902)' ``` ``` -------------------------------- ### OkLab() Color Examples Source: https://github.com/gilbarbara/colorizr/blob/main/docs/references/css-color-spec.md Examples of defining colors in the OkLab color space using numbers, percentages, and the 'none' keyword, including alpha values. ```css oklab(0.5 0.1 0.2) ``` ```css oklab(50% 25% 50%) ``` ```css oklab(0.5 0.1 0.2 / 0.8) ``` ```css oklab(none 0.1 -0.1) ``` -------------------------------- ### OkLCH() Color Examples Source: https://github.com/gilbarbara/colorizr/blob/main/docs/references/css-color-spec.md Examples of OkLCH colors, demonstrating the use of numbers, percentages, hue angle units, and the 'none' keyword for chroma. ```css oklch(0.5 0.15 120) ``` ```css oklch(50% 37.5% 120deg) ``` ```css oklch(0.5 0.15 0.33turn) ``` ```css oklch(0.5 0.15 2.09rad) ``` ```css oklch(0.5 none 180) ``` -------------------------------- ### Colorizr Example Usage Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/class.mdx Demonstrates common operations like accessing luminance, calculating contrast, comparing colors, lightening, mixing, and formatting. ```typescript const color = new Colorizr('#ff0044'); color.luminance; // 0.2168 color.contrast('#fff'); // 3.94 color.compare('#fff'); // { contrast: 3.94, normalAA: false, ... } color.lighten(20); // '#ff668f' color.mix('#0066ff'); // '#bc34d7' color.format('oklch'); // 'oklch(63.269% 0.25404 19.902)' ``` -------------------------------- ### Instantiate Colorizr with a Specific Format Source: https://context7.com/gilbarbara/colorizr/llms.txt Example of creating a Colorizr instance by specifying the desired output format directly in the constructor options. ```typescript // With format option in constructor const oklchColor = new Colorizr('#ff0044', { format: 'oklch' }); console.log(oklchColor.css); // 'oklch(63.269% 0.24899 20.057)' ``` -------------------------------- ### RGB() Color Examples Source: https://github.com/gilbarbara/colorizr/blob/main/docs/references/css-color-spec.md Demonstrates various ways to define RGB colors using both modern and legacy syntaxes, including the 'none' keyword and alpha channel. ```css rgb(255 0 0) /* Modern */ ``` ```css rgb(255 0 0 / 0.5) /* Modern with alpha */ ``` ```css rgb(none 128 255) /* none keyword */ ``` ```css rgb(255, 0, 0) /* Legacy */ ``` ```css rgba(255, 0, 0, 0.5) /* Legacy with alpha */ ``` -------------------------------- ### Instantiate and Access Color Properties with Colorizr Class Source: https://context7.com/gilbarbara/colorizr/llms.txt Demonstrates creating a Colorizr instance from various formats and accessing its properties like hex, RGB, HSL, OkLab, and OkLCH. Also shows how to get computed properties and individual color components. ```typescript import Colorizr from 'colorizr'; // Create a color instance from any format const color = new Colorizr('#ff0044'); // Access color properties console.log(color.hex); // '#ff0044' console.log(color.rgb); // { r: 255, g: 0, b: 68 } console.log(color.hsl); // { h: 344, s: 100, l: 50 } console.log(color.oklab); // { l: 0.63269, a: 0.23389, b: 0.08538 } console.log(color.oklch); // { l: 0.63269, c: 0.24899, h: 20.057 } // Get computed properties console.log(color.luminance); // 0.2168 console.log(color.chroma); // 1 console.log(color.readableColor); // '#ffffff' console.log(color.css); // '#ff0044' // Access individual components console.log(color.red); // 255 console.log(color.green); // 0 console.log(color.blue); // 68 console.log(color.hue); // 344 console.log(color.saturation); // 100 console.log(color.lightness); // 50 ``` -------------------------------- ### Importing Colorizr Constants Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/exports/constants.mdx Import necessary constants from the colorizr library. Ensure colorizr is installed and imported correctly in your project. ```typescript import { LRGB_TO_LMS, DEG2RAD, GAMUT_EPSILON } from 'colorizr'; ``` -------------------------------- ### Get Scale Step Keys Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/utilities.mdx Generates an array of step keys for a given number of steps. This is helpful for understanding the output structure of the `scale()` function. ```typescript import { getScaleStepKeys } from 'colorizr'; getScaleStepKeys(11); // [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] getScaleStepKeys(5); // [100, 300, 500, 700, 900] getScaleStepKeys(3); // [100, 500, 900] ``` -------------------------------- ### HSL() Color Examples with Hue Units Source: https://github.com/gilbarbara/colorizr/blob/main/docs/references/css-color-spec.md Illustrates HSL color definitions using different hue angle units (degrees, turns, radians, gradians) and the 'none' keyword. ```css hsl(120 100% 50%) /* Modern */ ``` ```css hsl(120deg 100% 50%) /* Explicit degrees */ ``` ```css hsl(0.33turn 100% 50%) /* Turns */ ``` ```css hsl(2.094rad 100% 50%) /* Radians */ ``` ```css hsl(133.33grad 100% 50%) /* Gradians */ ``` ```css hsl(none 50% 50%) /* none keyword */ ``` ```css hsl(120, 100%, 50%) /* Legacy */ ``` -------------------------------- ### Calculate WCAG 2.x Contrast Ratio Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/accessibility.mdx Get the WCAG 2.x contrast ratio between two colors. The ratio ranges from 1 (no contrast) to 21 (maximum contrast). ```typescript import { contrast } from 'colorizr'; contrast('#000000', '#ffffff'); // 21 contrast('#ff0044', '#ffffff'); // 3.94 contrast('#1a1a2e', '#ffffff'); // 17.05 ``` -------------------------------- ### Build Project Source: https://github.com/gilbarbara/colorizr/blob/main/CLAUDE.md Cleans and builds the project using tsup. ```bash pnpm build ``` -------------------------------- ### HEX Type Definition Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/exports/types.mdx Defines a type for hexadecimal color strings, starting with a '#'. ```typescript type HEX = `#${string}`; ``` -------------------------------- ### Get Opacity Source: https://context7.com/gilbarbara/colorizr/llms.txt Retrieves the opacity/alpha value of a color, ranging from 0 to 1. ```APIDOC ## opacity ### Description Get the opacity/alpha value of a color (0-1). ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { opacity } from 'colorizr'; console.log(opacity('#ff0044')); // 1 console.log(opacity('#ff004480')); // 0.502 console.log(opacity('rgba(255 0 68 / 50%)')); // 0.5 console.log(opacity('hsl(344 100% 50% / 0.75)')); // 0.75 ``` ### Response #### Success Response (200) Returns a number representing the opacity of the color. #### Response Example ```json 0.502 ``` ``` -------------------------------- ### Colorizr Constructor Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/class.mdx Initializes a new Colorizr instance with a given color string or model and optional format. ```APIDOC ## Constructor ### Description Initializes a new Colorizr instance with a given color string or model and optional format. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import Colorizr from 'colorizr'; const color = new Colorizr(color: string | ColorModel, options?: ColorizrOptions); // Examples: const a = new Colorizr('#ff0044'); const b = new Colorizr('rgb(255 0 68)'); const c = new Colorizr({ h: 344, s: 100, l: 50 }); const d = new Colorizr('#ff0044', { format: 'oklch' }); ``` ### Response #### Success Response (200) None #### Response Example None ### Parameters Table | Parameter | Description | Type | |----------------|----------------------------------------------------------------------------|------------------------| | color | Any CSS color string or a color model object (`HSL`, `RGB`, `LAB`, `LCH`). | `string \| ColorModel` | | options.format | Output format. Defaults to the input format. | `ColorType` | ``` -------------------------------- ### Get Chroma Source: https://context7.com/gilbarbara/colorizr/llms.txt Retrieves the chroma (color intensity) of a color, returning a value between 0 and 1. ```APIDOC ## chroma ### Description Get the chroma (color intensity) of a color (0-1). ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { chroma } from 'colorizr'; console.log(chroma('#ff0000')); // 1 (pure red, maximum chroma) console.log(chroma('#ff8080')); // 0.498 (pink, reduced chroma) console.log(chroma('#808080')); // 0 (gray, no chroma) console.log(chroma('#ffffff')); // 0 (white, no chroma) ``` ### Response #### Success Response (200) Returns a number representing the chroma of the color. #### Response Example ```json 1 ``` ``` -------------------------------- ### getP3MaxColor Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/gamut.mdx Get the OkLCH color string with the maximum P3 chroma for a given lightness and hue. ```APIDOC ## getP3MaxColor ### Description Get the OkLCH color string with the maximum P3 chroma for a given lightness and hue. ### Method Not specified (likely a utility function, not a direct HTTP method) ### Endpoint Not applicable (client-side function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "input": "string | LCH" } ``` ### Response #### Success Response (200) - **result** (string) - The OkLCH color string with maximum P3 chroma. #### Response Example ```json { "result": "oklch(0.63269 0.28643 19.902)" } ``` ``` -------------------------------- ### Watch Mode Build Source: https://github.com/gilbarbara/colorizr/blob/main/CLAUDE.md Builds the project in watch mode using pnpm. ```bash pnpm watch ``` -------------------------------- ### getP3MaxChroma Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/gamut.mdx Get the maximum chroma value within the P3 gamut for a given lightness and hue. ```APIDOC ## getP3MaxChroma ### Description Get the maximum chroma value within the P3 gamut for a given lightness and hue. ### Method Not specified (likely a utility function, not a direct HTTP method) ### Endpoint Not applicable (client-side function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "input": "string | LCH", "precision": "number (optional)" } ``` ### Response #### Success Response (200) - **result** (number) - The maximum chroma value. #### Response Example ```json { "result": 0.28643 } ``` ``` -------------------------------- ### Get Luminance Source: https://context7.com/gilbarbara/colorizr/llms.txt Calculates the relative luminance of a color according to WCAG definition, returning a value between 0 and 1. ```APIDOC ## luminance ### Description Get the relative luminance of a color according to WCAG definition (0-1). ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { luminance } from 'colorizr'; console.log(luminance('#ffffff')); // 1 console.log(luminance('#000000')); // 0 console.log(luminance('#ff0044')); // 0.2168 console.log(luminance('#808080')); // 0.2159 ``` ### Response #### Success Response (200) Returns a number representing the relative luminance of the color. #### Response Example ```json 0.2168 ``` ``` -------------------------------- ### Instantiate Colorizr Class Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/class.mdx Import and create a new Colorizr instance with a color string or model. Options can specify the output format. ```typescript import Colorizr from 'colorizr'; const color = new Colorizr(color: string | ColorModel, options?: ColorizrOptions); ``` ```typescript const a = new Colorizr('#ff0044'); const b = new Colorizr('rgb(255 0 68)'); const c = new Colorizr({ h: 344, s: 100, l: 50 }); const d = new Colorizr('#ff0044', { format: 'oklch' }); ``` -------------------------------- ### Run Single Test File Source: https://github.com/gilbarbara/colorizr/blob/main/CLAUDE.md Executes a specific test file. ```bash pnpm test filename.spec ``` -------------------------------- ### Lint Project Source: https://github.com/gilbarbara/colorizr/blob/main/CLAUDE.md Runs ESLint on the source and test files. ```bash pnpm lint ``` -------------------------------- ### Get Opacity of a Color Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/info.mdx Extracts the opacity value from a color string, supporting hex and RGBA formats. Requires importing the `opacity` function. ```typescript import { opacity } from 'colorizr'; opacity('#ff0044'); // 1 opacity('#ff004480'); // 0.5 opacity('rgb(255 0 68 / 50%)'); // 0.5 ``` -------------------------------- ### Run All Tests Source: https://github.com/gilbarbara/colorizr/blob/main/CLAUDE.md Executes all tests in the project. ```bash pnpm test ``` -------------------------------- ### Format Colors to Different String Representations with Colorizr Source: https://context7.com/gilbarbara/colorizr/llms.txt Shows how to format a Colorizr instance into various string representations such as CSS, RGB, HSL, and OkLCH using the `format` method. ```typescript // Format to different types console.log(color.format('rgb')); // 'rgb(255 0 68)' console.log(color.format('hsl')); // 'hsl(344 100% 50%)' console.log(color.format('oklch')); // 'oklch(63.269% 0.24899 20.057)' ``` -------------------------------- ### Get Color Opacity with opacity Source: https://context7.com/gilbarbara/colorizr/llms.txt Use `opacity` to retrieve the opacity/alpha value of a color, ranging from 0 to 1. This function supports various color formats. ```typescript import { opacity } from 'colorizr'; console.log(opacity('#ff0044')); // 1 console.log(opacity('#ff004480')); // 0.502 console.log(opacity('rgba(255 0 68 / 50%)')); // 0.5 console.log(opacity('hsl(344 100% 50% / 0.75)')); // 0.75 ``` -------------------------------- ### Mix and Adjust Opacity with Colorizr Class Source: https://context7.com/gilbarbara/colorizr/llms.txt Illustrates how to mix colors using the `mix` method and adjust the opacity of a color using `opacify` and `transparentize` methods in Colorizr. ```typescript // Mix with another color console.log(color.mix('#0066ff')); // '#bc34d7' console.log(color.mix('#0066ff', 0.75)); // '#7b4ef3' // Adjust opacity console.log(color.opacify(0.5)); // '#ff004480' console.log(color.transparentize(0.3)); // '#ff0044b3' ``` -------------------------------- ### Create and Use Colorizr Class Instance Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/getting-started.mdx Create a Colorizr instance to chain operations on a single color. Access properties like hex, hsl, oklch, and methods for manipulation and contrast calculation. ```typescript import Colorizr from 'colorizr'; const color = new Colorizr('#ff0044'); color.hex; // '#ff0044' color.hsl; // { h: 344, s: 100, l: 50 } color.oklch; // { l: 0.63269, c: 0.25404, h: 19.90224 } color.luminance; // 0.2168 color.chroma; // 1 color.opacity; // 1 color.readableColor; // '#ffffff' color.lighten(20); // '#ff668f' color.contrast('#fff'); // 3.94 ``` -------------------------------- ### Get Luminance of a Color Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/info.mdx Calculates the WCAG relative luminance of a color. Returns a value from 0 (black) to 1 (white). Requires importing the `luminance` function. ```typescript import { luminance } from 'colorizr'; luminance('#000000'); // 0 luminance('#ff0044'); // 0.2168 luminance('#ffffff'); // 1 ``` -------------------------------- ### Get Color Chroma with chroma Source: https://context7.com/gilbarbara/colorizr/llms.txt The `chroma` function returns the chroma (color intensity) of a color, with values ranging from 0 to 1. It indicates how vivid or saturated a color is. ```typescript import { chroma } from 'colorizr'; console.log(chroma('#ff0000')); // 1 (pure red, maximum chroma) console.log(chroma('#ff8080')); // 0.498 (pink, reduced chroma) console.log(chroma('#808080')); // 0 (gray, no chroma) console.log(chroma('#ffffff')); // 0 (white, no chroma) ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/gilbarbara/colorizr/blob/main/CLAUDE.md Executes all tests and generates a code coverage report. ```bash pnpm test:coverage ``` -------------------------------- ### Get Chroma of a Color Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/info.mdx Calculates color intensity from RGB channels. Returns 0 for grayscale and 1 for fully saturated colors. Requires importing the `chroma` function. ```typescript import { chroma } from 'colorizr'; chroma('#ff0044'); // 1 chroma('#808080'); // 0 chroma('#bf4060'); // 0.498 ``` -------------------------------- ### Import colorizr helper functions Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/exports/helpers.mdx Import necessary color math functions from the colorizr library. ```typescript import { srgbGammaDecode, oklabToLinearSRGB, isInGamut } from 'colorizr'; ``` -------------------------------- ### Generate Color Scale, Readable Text, and Contrast Ratio Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/index.mdx Use the `scale` function to generate a color scale from a base color. Employ `readableColor` to find accessible text colors for a given background and `contrast` to check WCAG contrast ratios between two colors. Ensure the 'colorizr' library is imported. ```typescript import { scale, readableColor, contrast } from 'colorizr'; // Generate a full color scale const swatches = scale('#ff0044'); // { // 50: '#fff0f0', 100: '#ffe4e3', 200: '#ffcdcc', 300: '#ffaeae', // 400: '#ff8488', 500: '#ff3d5a', 600: '#f7003e', 700: '#cd0029', // 800: '#9a001c', 900: '#66000f', 950: '#350004', // } // Find readable text color for a background readableColor('#1a1a2e'); // '#ffffff' // Check contrast ratio contrast('#1a1a2e', '#ffffff'); // 17.05 ``` -------------------------------- ### OkLab() Color Syntax (Modern Only) Source: https://github.com/gilbarbara/colorizr/blob/main/docs/references/css-color-spec.md Syntax for the OkLab color space, which is modern only. It uses space-separated components and supports an optional alpha channel. ```css oklab([ | | none]{3} [/ [ | none]]?) ``` -------------------------------- ### Calculate Brightness Difference Between Colors Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/comparison.mdx Use this function to get the brightness difference between two colors using the RGB brightness formula. Requires the 'colorizr' library to be imported. ```typescript import { brightnessDifference } from 'colorizr'; brightnessDifference('#ff0044', '#ffffff'); // 171.003 ``` -------------------------------- ### Compare Colors and Calculate Differences with Colorizr Source: https://context7.com/gilbarbara/colorizr/llms.txt Demonstrates comparing colors using methods like `contrast`, `deltaE`, and `brightnessDifference`, and obtaining a detailed comparison object with `compare`. ```typescript // Compare with other colors console.log(color.contrast('#ffffff')); // 3.94 console.log(color.deltaE('#ff0066')); // 0.02156 console.log(color.brightnessDifference('#000')); // 107.266 console.log(color.compare('#ffffff')); // { contrast: 3.94, normalAA: false, largeAA: true, normalAAA: false, largeAAA: false, ... } ``` -------------------------------- ### Get CSS Named Color Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/info.mdx Retrieves the CSS named color that matches the input. If no exact match is found, it returns the hex value. Requires importing the `name` function. ```typescript import { name } from 'colorizr'; name('#ff0000'); // 'red' name('#ff0044'); // '#ff0044' (no exact CSS name match) name('#ffa500'); // 'orange' ``` -------------------------------- ### compare Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/comparison.mdx Performs a full WCAG compliance analysis between two colors. ```APIDOC ## compare ### Description Run a full WCAG compliance analysis between two colors. ### Method `compare` ### Parameters - **left** (string) - Required - The first color string (e.g., '#ffffff'). - **right** (string) - Required - The second color string (e.g., '#000000'). ### Response - **Analysis** (object) - An object containing the WCAG compliance results. - **brightnessDifference** (number) - The brightness difference. - **colorDifference** (number) - The sum of maximum RGB channel differences. - **compliant** (number) - Number of compliance levels passed (0-2). - **contrast** (number) - WCAG contrast ratio. - **largeAA** (boolean) - Compliance for large text with AA level. - **largeAAA** (boolean) - Compliance for large text with AAA level. - **normalAA** (boolean) - Compliance for normal text with AA level. - **normalAAA** (boolean) - Compliance for normal text with AAA level. ### Request Example ```typescript import { compare } from 'colorizr'; compare('#ff0044', '#ffffff'); ``` ### Response Example ```json { "brightnessDifference": 171.003, "colorDifference": 442, "compliant": 1, "contrast": 3.94, "largeAA": true, "largeAAA": false, "normalAA": false, "normalAAA": false } ``` ``` -------------------------------- ### Calculate WCAG 2.x Contrast Ratio with Colorizr Function Source: https://context7.com/gilbarbara/colorizr/llms.txt Demonstrates using the standalone `contrast` function from Colorizr to calculate the WCAG 2.x contrast ratio between two colors, supporting various color formats. ```typescript import { contrast } from 'colorizr'; // Basic contrast calculation console.log(contrast('#1a1a2e', '#ffffff')); // 17.05 (excellent) console.log(contrast('#ff0044', '#ffffff')); // 3.94 console.log(contrast('#000000', '#ffffff')); // 21 (maximum) console.log(contrast('#777777', '#ffffff')); // 4.48 // Works with any color format console.log(contrast('rgb(255 0 68)', 'hsl(0 0% 100%)')); // 3.94 console.log(contrast('oklch(63% 0.25 20)', '#fff')); // 3.94 // WCAG requirements reference: // - Normal text AA: >= 4.5 // - Normal text AAA: >= 7 // - Large text AA: >= 3 // - Large text AAA: >= 4.5 ``` -------------------------------- ### Get Maximum P3 Color Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/gamut.mdx Retrieve the OkLCH color string with the maximum P3 chroma for a specified lightness and hue using `getP3MaxColor`. Accepts string or LCH color input. ```typescript import { getP3MaxColor } from 'colorizr'; P3MaxColor({ l: 0.63269, c: 0.25404, h: 19.90218 }); // 'oklch(0.63269 0.28643 19.902)' P3MaxColor('#00ff44'); // 'oklch(0.86876 0.30921 144.66)' ``` -------------------------------- ### ColorizrOptions Interface Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/exports/types.mdx Options for initializing or configuring the Colorizr instance, primarily for setting the output format. ```typescript interface ColorizrOptions { format?: ColorType; } ``` -------------------------------- ### Get CSS Color Name Source: https://context7.com/gilbarbara/colorizr/llms.txt Retrieves the CSS color name for a given color string. If no named match is found, the original hex value is returned. Works with any input color format. ```typescript import { name } from 'colorizr'; console.log(name('#ff0000')); // 'red' console.log(name('#663399')); // 'rebeccapurple' console.log(name('#000080')); // 'navy' console.log(name('#ff0044')); // '#ff0044' (no matching name) // Works with any input format console.log(name('rgb(255 0 0)')); // 'red' console.log(name('hsl(0 100% 50%)')); // 'red' ``` -------------------------------- ### Calculate APCA Contrast Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/accessibility.mdx Get the APCA (Accessible Perceptual Contrast Algorithm) contrast value between a background and foreground. APCA is directional, so the order of colors matters. The `APCA_VERSION` constant is also exported. ```typescript import { apcaContrast } from 'colorizr'; apcaContrast('#000000', '#ffffff'); // 106.04067 apcaContrast('#ffffff', '#000000'); // -107.88473 apcaContrast('#ff0044', '#ffffff'); // -69.23659 ``` -------------------------------- ### Full Project Validation Source: https://github.com/gilbarbara/colorizr/blob/main/CLAUDE.md Runs a comprehensive validation including linting, type checking, testing, building, and size checks. ```bash pnpm validate ``` -------------------------------- ### Get Maximum P3 Chroma Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/gamut.mdx Use `getP3MaxChroma` to find the maximum chroma within the P3 gamut for a given lightness and hue. Accepts string or LCH color input. Precision can be optionally specified. ```typescript import { getP3MaxChroma } from 'colorizr'; getP3MaxChroma({ l: 0.63269, c: 0.25404, h: 19.90218 }); // 0.28643 P3MaxChroma('#00ff44'); // 0.30921 ``` -------------------------------- ### Scale Output Formats Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/generators/scale.mdx Shows how to specify the output color format for the generated scale. ```APIDOC ## Scale Output Formats ### Description Specify the desired color format for the output scale. ### Method `scale(input: string, options?: ScaleOptions) ### Parameters #### Query Parameters - **format** (ColorType) - Optional - The desired output color format (e.g., 'oklch', 'hex', 'rgb'). ### Request Example ```typescript import { scale } from 'colorizr'; // Generate a scale with colors in 'oklch' format scale('#3366ff', { format: 'oklch' }); // Expected output structure: { 50: 'oklch(0.97 0.02 264)', 100: 'oklch(0.91 0.05 264)', ... } ``` ``` -------------------------------- ### Generate Readable Text Color Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/accessibility.mdx Get the most readable text color (light or dark) for a given background color. You can specify custom dark and light colors, or choose a method ('yiq', 'wcag', 'contrast', 'oklab', 'apca') and a threshold. ```typescript import { readableColor } from 'colorizr'; readableColor('#ff0044'); // '#ffffff' readableColor('#ffffff'); // '#000000' readableColor('#ff0044', 'apca'); // '#ffffff' readableColor('#ff0044', { method: 'apca', darkColor: '#1a1a2e' }); // '#1a1a2e' ``` -------------------------------- ### Import and Use Standalone Functions Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/getting-started.mdx Import individual functions like lighten, contrast, and scale from colorizr for tree-shaking. These functions accept various CSS color string formats. ```typescript import { lighten, contrast, scale } from 'colorizr'; lighten('#ff0044', 20); // '#ff668f' contrast('#000000', '#ffffff'); // 21 scale('#3366ff'); // { 50: '...', 100: '...', ..., 950: '...' } ``` ```typescript import { lighten } from 'colorizr'; lighten('#ff0044', 10); lighten('rgb(255 0 68)', 10); lighten('hsl(344 100% 50%)', 10); lighten('oklch(0.63 0.25 19.9)', 10); lighten('red', 10); ``` -------------------------------- ### Mix with Different Interpolation Spaces Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/generators/mix.mdx Shows how to specify the color space for interpolation. OkLCH is the default and provides perceptually uniform results. ```typescript mix('#ff0044', '#0066ff', 0.5, { space: 'oklch' }); // default mix('#ff0044', '#0066ff', 0.5, { space: 'hsl' }); mix('#ff0044', '#0066ff', 0.5, { space: 'rgb' }); mix('#ff0044', '#0066ff', 0.5, { space: 'oklab' }); ``` -------------------------------- ### Scale Variants Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/generators/scale.mdx Demonstrates how to generate color scales using different predefined variants. ```APIDOC ## Scale Variants ### Description Generate color scales with different aesthetic presets. ### Method `scale(input: string, options?: ScaleOptions) ### Parameters #### Query Parameters - **variant** (ScaleVariant) - Required - Preset: `'deep'`, `'neutral'`, `'pastel'`, `'subtle'`, `'vibrant'`. ### Request Example ```typescript import { scale } from 'colorizr'; // Using predefined variants scale('#3366ff', { variant: 'vibrant' }); scale('#3366ff', { variant: 'pastel' }); scale('#3366ff', { variant: 'neutral' }); scale('#3366ff', { variant: 'deep' }); scale('#3366ff', { variant: 'subtle' }); ``` ``` -------------------------------- ### Basic Mix Usage Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/generators/mix.mdx Demonstrates basic interpolation between two hex color strings. The ratio parameter controls the interpolation point. ```typescript import { mix } from 'colorizr'; mix('#ff0044', '#0066ff'); // '#bc34d7' mix('#ff0044', '#0066ff', 0.2); // '#ed068a' mix('#ff0044', '#0066ff', 0.8); // '#7351ff' ``` -------------------------------- ### OkLab() Color Parsing Source: https://github.com/gilbarbara/colorizr/blob/main/docs/references/css-color-spec.md Parses OkLab color values using modern syntax. Supports percentage, number, and 'none' keyword for components, along with an optional alpha channel. ```APIDOC ## OkLab() ### Description Parses OkLab color values. ### Syntax (Modern Only) ```css oklab([ | | none]{3} [/ [ | none]]?) ``` ### Value Mappings | Component | Number Range | Percentage Mapping | |-----------|--------------|-------------------| | L (Lightness) | 0-1 | 100% = 1 | | a (Green/Red) | -0.4 to 0.4 | 100% = 0.4 | | b (Blue/Yellow) | -0.4 to 0.4 | 100% = 0.4 | ### Examples ```css oklab(0.5 0.1 0.2) oklab(50% 25% 50%) oklab(0.5 0.1 0.2 / 0.8) oklab(none 0.1 -0.1) ``` ``` -------------------------------- ### Manipulate Colors with Colorizr Class Methods Source: https://context7.com/gilbarbara/colorizr/llms.txt Shows how to perform various color manipulations using methods of the Colorizr class, including lightening, darkening, saturating, desaturating, rotating, converting to grayscale, and inverting colors. ```typescript // Manipulate the color console.log(color.lighten(20)); // '#ff668f' console.log(color.darken(10)); // '#cc0036' console.log(color.saturate(10)); // '#ff0044' console.log(color.desaturate(30)); // '#d9335f' console.log(color.rotate(180)); // '#00ffbb' console.log(color.grayscale()); // '#808080' console.log(color.invert()); // '#00ffbb' ``` -------------------------------- ### Scale API Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/generators/scale.mdx Generates a perceptually uniform color scale in OkLCH space, producing step-keyed objects similar to Tailwind's color palette format. Each step is visually equidistant. ```APIDOC ## Scale Function ### Description Generates a perceptually uniform color scale in OkLCH space, producing step-keyed objects like Tailwind's color palette format. Each step is visually equidistant. ### Method `scale(input: string, options?: ScaleOptions): Record` ### Parameters #### Query Parameters - **chromaCurve** (number) - Optional - Controls chroma distribution (0-1). Default: 0 - **format** (ColorType) - Optional - Output format. - **lightnessCurve** (number) - Optional - Controls lightness distribution. Default: 1.5 - **lock** (number) - Optional - Anchor input color at this step. - **maxLightness** (number) - Optional - Maximum lightness (0-1). Default: 0.97 - **minLightness** (number) - Optional - Minimum lightness (0-1). Default: 0.2 - **mode** (ScaleMode) - Optional - `'light'` or `'dark'`. Default: 'light' - **saturation** (number) - Optional - Override variant saturation (0-100). - **steps** (number) - Optional - Number of steps (3-20). Default: 11 - **variant** (ScaleVariant) - Optional - Preset: `'deep'`, `'neutral'`, `'pastel'`, `'subtle'`, `'vibrant'`. ### Request Example ```typescript import { scale } from 'colorizr'; scale('#3366ff'); ``` ### Response #### Success Response (200) - **Record** - An object where keys are step numbers (e.g., 50, 100, 200) and values are color strings in the specified format. #### Response Example ```json { "50": "#f0f5ff", "100": "#e4edff", "200": "#cedfff", "300": "#b1cbff", "400": "#90b4ff", "500": "#6a98ff", "600": "#4075ff", "700": "#2554ec", "800": "#0f2fc9", "900": "#06009a", "950": "#020052" } ``` ``` -------------------------------- ### Scale Helpers Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/utilities.mdx Functions for generating scale step keys. ```APIDOC ## getScaleStepKeys ### Description Get the step keys that will be generated for a given number of steps. Useful for understanding the output shape of `scale()`. ### Method N/A (Utility function) ### Endpoint N/A (Utility function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { getScaleStepKeys } from 'colorizr'; getScaleStepKeys(11); // [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] getScaleStepKeys(5); // [100, 300, 500, 700, 900] getScaleStepKeys(3); // [100, 500, 900] ``` ### Response #### Success Response (200) - **number[]** - An array of numbers representing the scale step keys. ``` -------------------------------- ### ScaleOptions Interface Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/exports/types.mdx Options for generating color scales, controlling steps, variant, saturation, lightness, and curves. ```typescript interface ScaleOptions { steps?: number; // 3-20 variant?: ScaleVariant; saturation?: number; // 0-100 mode?: 'light' | 'dark'; lightnessCurve?: number; chromaCurve?: number; // 0-1 minLightness?: number; // 0-1 maxLightness?: number; // 0-1 lock?: number; format?: ColorType; } type ScaleVariant = 'deep' | 'neutral' | 'pastel' | 'subtle' | 'vibrant'; ``` -------------------------------- ### Generate Color Scale with Custom Steps Source: https://context7.com/gilbarbara/colorizr/llms.txt Generates a color scale with a specified number of steps. Use `getScaleStepKeys` to retrieve the keys corresponding to the custom step count. ```typescript // Custom step count const scale5 = scale('#3366ff', { steps: 5 }); console.log(getScaleStepKeys(5)); // [100, 300, 500, 700, 900] ``` -------------------------------- ### The 'none' Keyword Source: https://github.com/gilbarbara/colorizr/blob/main/docs/references/css-color-spec.md Explains the 'none' keyword used in modern CSS Color Level 4 syntax for representing missing or powerless color components. ```APIDOC ## The `none` Keyword ### Description Explains the usage and behavior of the 'none' keyword in CSS Color Level 4. - Available in **modern syntax only** (space-separated) - Treated as `0` for rendering purposes - Indicates a missing/powerless component ### Powerless Components - **HSL/OkLCH hue**: powerless when saturation/chroma = 0 - Automatically treated as `none` in interpolation ``` -------------------------------- ### MixOptions Interface Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/exports/types.mdx Options for mixing colors, specifying the output format, color space, and hue adjustment strategy. ```typescript interface MixOptions { format?: ColorType; space?: ColorModelKey; hue?: 'shorter' | 'longer' | 'increasing' | 'decreasing'; } ``` -------------------------------- ### Generate a basic color palette Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/generators/palette.mdx Use the palette function with a base hex color to generate a default palette of 6 colors. Ensure the 'colorizr' library is imported. ```typescript import { palette } from 'colorizr'; palette('#ff0044'); // ['#ff0044', '#ffbb00', '#44ff00', '#00ffbb', '#0044ff', '#bb00ff'] ``` -------------------------------- ### Scale Step Count Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/generators/scale.mdx Illustrates how to control the number of steps in the generated color scale. ```APIDOC ## Scale Step Count ### Description Customize the number of color steps generated in the scale. ### Method `scale(input: string, options?: ScaleOptions) ### Parameters #### Query Parameters - **steps** (number) - Optional - Number of steps (3-20). Default: 11 ### Request Example ```typescript import { scale } from 'colorizr'; // Generate a scale with 5 steps scale('#3366ff', { steps: 5 }); // Expected output structure: { 100: '...', 300: '...', 500: '...', 700: '...', 900: '...' } // Generate a scale with 3 steps scale('#3366ff', { steps: 3 }); // Expected output structure: { 100: '...', 500: '...', 900: '...' } // Note: Use getScaleStepKeys(steps) from utilities to determine exact step keys. ``` ``` -------------------------------- ### Contrast Calculation Function Source: https://context7.com/gilbarbara/colorizr/llms.txt The `contrast` function calculates the WCAG 2.x contrast ratio between two colors, useful for accessibility checks. ```APIDOC ## contrast Function ### Description Calculate the WCAG 2.x contrast ratio between two colors. Returns a value between 1 and 21, where higher values indicate better contrast. ### Parameters - **color1** (string | object) - The first color. - **color2** (string | object) - The second color. ### Returns - **number** - The contrast ratio between the two colors (1 to 21). ### Request Example ```typescript import { contrast } from 'colorizr'; console.log(contrast('#1a1a2e', '#ffffff')); console.log(contrast('rgb(255 0 68)', 'hsl(0 0% 100%)')); ``` ### Response Example ```typescript // For contrast('#1a1a2e', '#ffffff') 17.05 // For contrast('rgb(255 0 68)', 'hsl(0 0% 100%)') 3.94 ``` ``` -------------------------------- ### Options Interfaces Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/exports/types.mdx Interfaces for various options used in colorizr functions. ```APIDOC ## Options Interfaces ### ColorizrOptions ```typescript interface ColorizrOptions { format?: ColorType; } ``` ### FormatCSSOptions ```typescript interface FormatCSSOptions { alpha?: number; format?: ColorType; precision?: number; separator?: string; } ``` ### MixOptions ```typescript interface MixOptions { format?: ColorType; space?: ColorModelKey; hue?: 'shorter' | 'longer' | 'increasing' | 'decreasing'; } ``` ### ScaleOptions ```typescript interface ScaleOptions { steps?: number; // 3-20 variant?: ScaleVariant; saturation?: number; // 0-100 mode?: 'light' | 'dark'; lightnessCurve?: number; chromaCurve?: number; // 0-1 minLightness?: number; // 0-1 maxLightness?: number; // 0-1 lock?: number; format?: ColorType; } type ScaleVariant = 'deep' | 'neutral' | 'pastel' | 'subtle' | 'vibrant'; ``` ### PaletteOptions ```typescript interface PaletteOptions { size?: number; monochromatic?: boolean; lightness?: number; saturation?: number; format?: ColorType; } ``` ### SchemeOptions ```typescript interface SchemeOptions { scheme?: Scheme; format?: ColorType; } type Scheme = 'analogous' | 'complementary' | 'rectangle' | 'split' | 'split-complementary' | 'square' | 'tetradic' | 'triadic'; ``` ### ReadableColorOptions ```typescript interface ReadableColorOptions { method?: 'yiq' | 'wcag' | 'contrast' | 'oklab' | 'apca'; darkColor?: string; lightColor?: string; threshold?: number; } ``` ### RandomOptions ```typescript interface RandomOptions { format?: ColorType; minHue?: number; maxHue?: number; minSaturation?: number; maxSaturation?: number; minLightness?: number; maxLightness?: number; } ``` ``` -------------------------------- ### Import Colorizr Types Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/exports/types.mdx Import all necessary types from the colorizr library for use in your TypeScript project. ```typescript import type { HSL, RGB, LAB, LCH, ColorType, Analysis } from 'colorizr'; ``` -------------------------------- ### Color Comparison Methods Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/class.mdx Utilize methods to compare the current color with another color, calculating differences and contrast ratios. ```typescript color.brightnessDifference(input: string): number color.colorDifference(input: string): number color.compare(input: string): Analysis color.contrast(input: string): number color.deltaE(input: string): number ``` -------------------------------- ### Colorizr Methods - Mixing & Conversion Source: https://github.com/gilbarbara/colorizr/blob/main/docs/src/content/docs/class.mdx Methods for mixing colors or converting to different formats. ```APIDOC ## Methods - Mixing & Conversion ### Description Methods for mixing colors or converting to different formats. ### Method Signatures - `mix(color: string, ratio?: number, options?: MixOptions): string` - `format(type: ColorType, precision?: number): string` - `toGamut(format?: ColorType): string` ```