### Install color2k Source: https://context7.com/ricokahler/color2k/llms.txt Installation instructions for the color2k library using npm. ```bash npm install color2k ``` -------------------------------- ### Install color2k using npm Source: https://github.com/ricokahler/color2k/blob/main/README.md This snippet shows the command to install the color2k library using npm, a popular package manager for Node.js and front-end projects. It's the standard way to add color2k as a dependency to your project. ```bash npm i color2k ``` -------------------------------- ### Import color2k functions Source: https://context7.com/ricokahler/color2k/llms.txt Example of importing core manipulation functions from the color2k library. ```javascript import { darken, lighten, transparentize } from 'color2k'; ``` -------------------------------- ### Import color2k functions via Skypack CDN Source: https://github.com/ricokahler/color2k/blob/main/README.md Demonstrates how to import specific functions from color2k directly from Skypack CDN. This method is useful for modern browsers or environments like Deno that support ES module imports from URLs, allowing for direct usage without a local installation. ```javascript import { darken, transparentize } from 'https://cdn.skypack.dev/color2k?min'; ``` -------------------------------- ### Import and use color2k functions in JavaScript Source: https://github.com/ricokahler/color2k/blob/main/README.md Illustrates the basic usage of color2k by importing functions like 'darken' and 'transparentize' from the library. These functions can then be called with color strings and adjustment values to manipulate colors, outputting results in formats like rgba or hsla. ```javascript import { darken, transparentize } from 'color2k'; // e.g. darken('blue', 0.1); transparentize('red', 0.5); ``` -------------------------------- ### Color Construction Functions Source: https://context7.com/ricokahler/color2k/llms.txt Functions for constructing CSS color strings from color components. ```APIDOC ## rgba ### Description Constructs an RGBA color string from individual red (0-255), green (0-255), blue (0-255), and alpha (0-1) values. Values are automatically clamped to valid ranges. ### Method Import ### Endpoint N/A ### Parameters - **red** (number) - Required - Red component (0-255). - **green** (number) - Required - Green component (0-255). - **blue** (number) - Required - Blue component (0-255). - **alpha** (number) - Required - Alpha component (0-1). ### Request Example ```javascript import { rgba } from 'color2k'; rgba(255, 0, 0, 1); // 'rgba(255, 0, 0, 1)' rgba(0, 128, 255, 0.5); // 'rgba(0, 128, 255, 0.5)' rgba(255, 255, 255, 0); // 'rgba(255, 255, 255, 0)' // Values are clamped to valid ranges rgba(300, -10, 128, 1.5); // 'rgba(255, 0, 128, 1)' ``` ### Response #### Success Response (200) - **String** (string) - An RGBA CSS color string. #### Response Example ```html 'rgba(255, 0, 0, 1)' ``` ## hsla ### Description Constructs an HSLA color string from hue (0-360, wraps), saturation (0-1), lightness (0-1), and alpha (0-1) values. Saturation, lightness, and alpha are clamped to valid ranges. ### Method Import ### Endpoint N/A ### Parameters - **hue** (number) - Required - Hue component (0-360, wraps). - **saturation** (number) - Required - Saturation component (0-1). - **lightness** (number) - Required - Lightness component (0-1). - **alpha** (number) - Required - Alpha component (0-1). ### Request Example ```javascript import { hsla } from 'color2k'; hsla(0, 1, 0.5, 1); // 'hsla(0, 100%, 50%, 1)' hsla(120, 0.5, 0.75, 0.8); // 'hsla(120, 50%, 75%, 0.8)' hsla(240, 1, 0.5, 0.5); // 'hsla(240, 100%, 50%, 0.5)' // Hue wraps around at 360 hsla(400, 1, 0.5, 1); // 'hsla(40, 100%, 50%, 1)' ``` ### Response #### Success Response (200) - **String** (string) - An HSLA CSS color string. #### Response Example ```html 'hsla(0, 100%, 50%, 1)' ``` ``` -------------------------------- ### Calculate Contrast Ratios Source: https://context7.com/ricokahler/color2k/llms.txt Computes the contrast ratio between two colors to determine accessibility. Returns a value between 1 and 21. ```javascript import { getContrast } from 'color2k'; const isAccessible = (fg, bg) => getContrast(fg, bg) >= 4.5; isAccessible('#333', 'white'); // true ``` -------------------------------- ### Utility Functions Source: https://context7.com/ricokahler/color2k/llms.txt General utility functions used within the library. ```APIDOC ## guard ### Description A clamping utility function that constrains a value between a minimum and maximum. Used internally for validating color values. ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript import { guard } from 'color2k'; guard(0, 255, 128); // 128 (within range) guard(0, 255, -10); // 0 (clamped to min) guard(0, 255, 300); // 255 (clamped to max) guard(0, 1, 0.5); // 0.5 // Use for custom color calculations const clampedAlpha = guard(0, 1, userInput); ``` ### Response #### Success Response (200) - **clampedValue** (number) - The input value, clamped within the min and max range. #### Response Example ```json 128 ``` ``` -------------------------------- ### Create Color Scales with getScale Source: https://context7.com/ricokahler/color2k/llms.txt Generates a color interpolation function that maps a decimal value (0-1) to a specific color along a defined spectrum. This is useful for creating data visualizations or dynamic color transitions. ```javascript import { getScale } from 'color2k'; const trafficLight = getScale('green', 'yellow', 'red'); trafficLight(0); // 'rgba(0, 128, 0, 1)' trafficLight(0.5); // 'rgba(255, 255, 0, 1)' trafficLight(1); // 'rgba(255, 0, 0, 1)' ``` -------------------------------- ### Color Conversion Functions Source: https://context7.com/ricokahler/color2k/llms.txt Functions for converting colors between different formats. ```APIDOC ## toHex ### Description Converts any valid CSS color to a hex color code. Includes alpha channel as 8-digit hex when alpha is less than 1. ### Method Import ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { toHex } from 'color2k'; toHex('red'); // '#ff0000' toHex('rgb(0, 128, 255)'); // '#0080ff' toHex('hsl(120, 100%, 50%)'); // '#00ff00' toHex('rgba(255, 0, 0, 0.5)'); // '#ff000080' toHex('cornflowerblue'); // '#6495ed' ``` ### Response #### Success Response (200) - **String** (string) - A hex color code. #### Response Example ```html '#ff0000' ``` ## toRgba ### Description Converts any valid CSS color to an RGBA string format. ### Method Import ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { toRgba } from 'color2k'; toRgba('#ff0000'); // 'rgba(255, 0, 0, 1)' toRgba('hsl(120, 100%, 50%)'); // 'rgba(0, 255, 0, 1)' toRgba('blue'); // 'rgba(0, 0, 255, 1)' toRgba('transparent'); // 'rgba(0, 0, 0, 0)' ``` ### Response #### Success Response (200) - **String** (string) - An RGBA CSS color string. #### Response Example ```html 'rgba(255, 0, 0, 1)' ``` ## toHsla ### Description Converts any valid CSS color to an HSLA string format. ### Method Import ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { toHsla } from 'color2k'; toHsla('#ff0000'); // 'hsla(0, 100%, 50%, 1)' toHsla('rgb(0, 255, 0)'); // 'hsla(120, 100%, 50%, 1)' toHsla('blue'); // 'hsla(240, 100%, 50%, 1)' toHsla('rgba(128, 128, 128, 0.5)'); // 'hsla(0, 0%, 50%, 0.5)' ``` ### Response #### Success Response (200) - **String** (string) - An HSLA CSS color string. #### Response Example ```html 'hsla(0, 100%, 50%, 1)' ``` ``` -------------------------------- ### Accessibility Functions Source: https://context7.com/ricokahler/color2k/llms.txt Functions to help ensure color accessibility according to WCAG guidelines. ```APIDOC ## getLuminance ### Description Calculates the relative luminance of a color as defined by WCAG, returning a value between 0 (darkest) and 1 (lightest). ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript import { getLuminance } from 'color2k'; getLuminance('white'); // 1 getLuminance('black'); // 0 getLuminance('#808080'); // 0.2158 (approximately) getLuminance('red'); // 0.2126 getLuminance('lime'); // 0.7152 getLuminance('blue'); // 0.0722 getLuminance('transparent'); // 0 ``` ### Response #### Success Response (200) - **luminance** (number) - The relative luminance of the color (0-1). #### Response Example ```json 1 ``` ``` ```APIDOC ## getContrast ### Description Calculates the contrast ratio between two colors according to WCAG guidelines. Returns a value between 1 (no contrast) and 21 (maximum contrast). ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript import { getContrast } from 'color2k'; getContrast('white', 'black'); // 21 (maximum) getContrast('white', 'white'); // 1 (minimum) getContrast('#333', 'white'); // ~12.6 getContrast('blue', 'white'); // ~8.6 // WCAG requirements: // - AA normal text: 4.5:1 // - AA large text: 3:1 // - AAA normal text: 7:1 // - AAA large text: 4.5:1 const isAccessible = (fg, bg) => getContrast(fg, bg) >= 4.5; isAccessible('#333', 'white'); // true isAccessible('yellow', 'white'); // false ``` ### Response #### Success Response (200) - **contrastRatio** (number) - The contrast ratio between the two colors (1-21). #### Response Example ```json 21 ``` ``` ```APIDOC ## hasBadContrast ### Description Checks if a foreground color has insufficient contrast against a background according to WCAG standards. Returns true if contrast is inadequate. ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript import { hasBadContrast } from 'color2k'; // Standards: 'decorative' (1.5), 'readable' (3), 'aa' (4.5), 'aaa' (7) hasBadContrast('blue', 'aa', 'white'); // false (passes AA) hasBadContrast('yellow', 'aa', 'white'); // true (fails AA) hasBadContrast('gray', 'aaa', 'white'); // true (fails AAA) hasBadContrast('#333', 'aaa', 'white'); // false (passes AAA) // Default is 'aa' standard against white hasBadContrast('red'); // false hasBadContrast('lightgray'); // true // Validate color choices const validateTextColor = (textColor, bgColor) => { if (hasBadContrast(textColor, 'aa', bgColor)) { console.warn('Text color does not meet WCAG AA standards'); } }; ``` ### Response #### Success Response (200) - **isBadContrast** (boolean) - True if the contrast is insufficient, false otherwise. #### Response Example ```json true ``` ``` ```APIDOC ## readableColor ### Description Returns either black (#000) or white (#fff) depending on which provides better contrast against the given background color. ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript import { readableColor } from 'color2k'; readableColor('white'); // '#000' readableColor('black'); // '#fff' readableColor('yellow'); // '#000' readableColor('navy'); // '#fff' readableColor('#3498db'); // '#fff' readableColor('#ecf0f1'); // '#000' // Automatic text color for any background const getTextStyle = (bgColor) => ({ backgroundColor: bgColor, color: readableColor(bgColor) }); ``` ### Response #### Success Response (200) - **contrastingColor** (string) - Either '#000' or '#fff'. #### Response Example ```json "#000" ``` ``` ```APIDOC ## readableColorIsBlack ### Description Returns a boolean indicating whether black text should be used for readable contrast (true) or white text (false). Useful for conditional logic. ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript import { readableColorIsBlack } from 'color2k'; readableColorIsBlack('white'); // true (use black text) readableColorIsBlack('black'); // false (use white text) readableColorIsBlack('yellow'); // true readableColorIsBlack('#333'); // false // Conditional styling const getButtonClass = (bgColor) => readableColorIsBlack(bgColor) ? 'dark-text' : 'light-text'; // Dynamic theming const theme = { primary: '#3498db', get primaryText() { return readableColorIsBlack(this.primary) ? '#000000' : '#ffffff'; } }; ``` ### Response #### Success Response (200) - **useBlackText** (boolean) - True if black text provides better contrast, false if white text does. #### Response Example ```json true ``` ``` -------------------------------- ### Construct RGBA Color String - color2k Source: https://context7.com/ricokahler/color2k/llms.txt Constructs an RGBA color string from individual red, green, blue, and alpha values. Values are automatically clamped to valid ranges (0-255 for RGB, 0-1 for alpha). ```javascript import { rgba } from 'color2k'; rgba(255, 0, 0, 1); // 'rgba(255, 0, 0, 1)' rgba(0, 128, 255, 0.5); // 'rgba(0, 128, 255, 0.5)' rgba(255, 255, 255, 0); // 'rgba(255, 255, 255, 0)' // Values are clamped to valid ranges rgba(300, -10, 128, 1.5); // 'rgba(255, 0, 128, 1)' ``` -------------------------------- ### Color Parsing Functions Source: https://context7.com/ricokahler/color2k/llms.txt Functions for parsing various CSS color formats into structured color components. ```APIDOC ## parseToRgba ### Description Parses any valid CSS color string into its red, green, blue, and alpha components. ### Method Import ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { parseToRgba } from 'color2k'; // Hex colors parseToRgba('#ff0000'); // [255, 0, 0, 1] parseToRgba('#f00'); // [255, 0, 0, 1] parseToRgba('#ff000080'); // [255, 0, 0, 0.502] // RGB/RGBA parseToRgba('rgb(255, 128, 0)'); // [255, 128, 0, 1] parseToRgba('rgba(255, 128, 0, 0.5)'); // [255, 128, 0, 0.5] // HSL/HSLA parseToRgba('hsl(120, 100%, 50%)'); // [0, 255, 0, 1] parseToRgba('hsla(120, 100%, 50%, 0.5)'); // [0, 255, 0, 0.5] // Named colors parseToRgba('red'); // [255, 0, 0, 1] parseToRgba('cornflowerblue'); // [100, 149, 237, 1] parseToRgba('transparent'); // [0, 0, 0, 0] ``` ### Response #### Success Response (200) - **Array** (Array) - An array containing [red, green, blue, alpha] components. #### Response Example ```json [255, 0, 0, 1] ``` ## parseToHsla ### Description Parses any valid CSS color string into hue (0-360), saturation (0-1), lightness (0-1), and alpha (0-1) components. ### Method Import ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { parseToHsla } from 'color2k'; // Parse various color formats to HSLA parseToHsla('red'); // [0, 1, 0.5, 1] parseToHsla('#00ff00'); // [120, 1, 0.5, 1] parseToHsla('rgb(0, 0, 255)'); // [240, 1, 0.5, 1] parseToHsla('hsl(180, 50%, 50%)'); // [180, 0.5, 0.5, 1] parseToHsla('rgba(255, 0, 0, 0.5)'); // [0, 1, 0.5, 0.5] ``` ### Response #### Success Response (200) - **Array** (Array) - An array containing [hue, saturation, lightness, alpha] components. #### Response Example ```json [0, 1, 0.5, 1] ``` ``` -------------------------------- ### Check Readable Text Color Preference Source: https://context7.com/ricokahler/color2k/llms.txt Returns a boolean indicating whether black text is preferred for readability on a background. Useful for conditional UI styling. ```javascript import { readableColorIsBlack } from 'color2k'; const getButtonClass = (bgColor) => readableColorIsBlack(bgColor) ? 'dark-text' : 'light-text'; ``` -------------------------------- ### Handle Color Parsing Errors with ColorError in JavaScript Source: https://context7.com/ricokahler/color2k/llms.txt Demonstrates how to catch and handle specific ColorError exceptions thrown by the parseToRgba function when invalid color strings are provided. It also includes a utility function to validate color formats before use. ```javascript import { parseToRgba, ColorError } from 'color2k'; try { parseToRgba('not-a-color'); } catch (error) { if (error instanceof ColorError) { console.error(error.message); // 'Failed to parse color: "not-a-color"' } } // Validate colors before use const isValidColor = (color) => { try { parseToRgba(color); return true; } catch { return false; } }; ``` -------------------------------- ### Construct HSLA Color String - color2k Source: https://context7.com/ricokahler/color2k/llms.txt Constructs an HSLA color string from hue, saturation, lightness, and alpha values. Hue wraps around 360 degrees. Saturation, lightness, and alpha are clamped to the 0-1 range. ```javascript import { hsla } from 'color2k'; hsla(0, 1, 0.5, 1); // 'hsla(0, 100%, 50%, 1)' hsla(120, 0.5, 0.75, 0.8); // 'hsla(120, 50%, 75%, 0.8)' hsla(240, 1, 0.5, 0.5); // 'hsla(240, 100%, 50%, 0.5)' // Hue wraps around at 360 hsla(400, 1, 0.5, 1); // 'hsla(40, 100%, 50%, 1)' ``` -------------------------------- ### Color Scale Functions Source: https://context7.com/ricokahler/color2k/llms.txt Functions for creating and utilizing color scales based on provided colors. ```APIDOC ## getScale ### Description Creates a color scale function from multiple colors. Returns a function that accepts a decimal (0-1) and returns the interpolated color at that position. ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript import { getScale } from 'color2k'; // Create a traffic light scale const trafficLight = getScale('green', 'yellow', 'red'); trafficLight(0); // 'rgba(0, 128, 0, 1)' (green) trafficLight(0.5); // 'rgba(255, 255, 0, 1)' (yellow) trafficLight(1); // 'rgba(255, 0, 0, 1)' (red) trafficLight(0.25); // interpolated green-yellow // Create a temperature scale const tempScale = getScale('blue', 'white', 'red'); const getTemperatureColor = (temp) => { const normalized = (temp + 20) / 60; // -20 to 40 degrees return tempScale(Math.max(0, Math.min(1, normalized))); }; // Custom domain wrapper const percentScale = getScale('red', 'yellow', 'green'); const gradeColor = (percent) => percentScale(percent / 100); gradeColor(0); // red (failing) gradeColor(70); // yellow-ish (passing) gradeColor(100); // green (perfect) ``` ### Response #### Success Response (200) N/A (Returns a function) #### Response Example N/A ``` -------------------------------- ### Parse CSS Colors to HSLA - color2k Source: https://context7.com/ricokahler/color2k/llms.txt Parses various CSS color formats into HSLA components [hue, saturation, lightness, alpha]. Hue is 0-360, others are 0-1. Supports hex, rgb, hsl, named colors, and 'transparent'. ```javascript import { parseToHsla } from 'color2k'; // Parse various color formats to HSLA parseToHsla('red'); // [0, 1, 0.5, 1] parseToHsla('#00ff00'); // [120, 1, 0.5, 1] parseToHsla('rgb(0, 0, 255)'); // [240, 1, 0.5, 1] parseToHsla('hsl(180, 50%, 50%)'); // [180, 0.5, 0.5, 1] parseToHsla('rgba(255, 0, 0, 0.5)'); // [0, 1, 0.5, 0.5] ``` -------------------------------- ### Validate Contrast Standards Source: https://context7.com/ricokahler/color2k/llms.txt Checks if a foreground color meets specific WCAG contrast standards against a background. Supports 'decorative', 'readable', 'aa', and 'aaa' levels. ```javascript import { hasBadContrast } from 'color2k'; hasBadContrast('blue', 'aa', 'white'); // false hasBadContrast('yellow', 'aa', 'white'); // true ``` -------------------------------- ### Mix Colors Source: https://context7.com/ricokahler/color2k/llms.txt Blends two colors together based on a weight factor. This is commonly used to create tints (mixing with white) or shades (mixing with black). ```javascript import { mix } from 'color2k'; mix('red', 'blue', 0.5); // 'rgba(128, 0, 128, 1)' mix('white', 'black', 0.5); // 'rgba(128, 128, 128, 1)' ``` -------------------------------- ### Transparency Manipulation Source: https://context7.com/ricokahler/color2k/llms.txt Functions to adjust the alpha channel of a color. transparentize decreases opacity, while opacify increases it. ```javascript import { transparentize, opacify } from 'color2k'; transparentize('red', 0.5); // 'rgba(255, 0, 0, 0.5)' opacify('rgba(255, 0, 0, 0.5)', 0.3); // 'rgba(255, 0, 0, 0.8)' ``` -------------------------------- ### Darken and Lighten Colors Source: https://context7.com/ricokahler/color2k/llms.txt Functions to adjust the lightness of a color in the HSL color space. Both functions accept a color string and a decimal value between 0 and 1 to modify the lightness component. ```javascript import { darken, lighten } from 'color2k'; // Darken darken('white', 0.1); // 'hsla(0, 0%, 90%, 1)' // Lighten lighten('black', 0.1); // 'hsla(0, 0%, 10%, 1)' ``` -------------------------------- ### Parse CSS Colors to RGBA - color2k Source: https://context7.com/ricokahler/color2k/llms.txt Parses various CSS color formats (hex, rgb, hsl, named colors) into RGBA components [red, green, blue, alpha]. Supports 3/4/6/8 digit hex codes and the 'transparent' keyword. Output is always an array of four numbers. ```javascript import { parseToRgba } from 'color2k'; // Hex colors parseToRgba('#ff0000'); // [255, 0, 0, 1] parseToRgba('#f00'); // [255, 0, 0, 1] parseToRgba('#ff000080'); // [255, 0, 0, 0.502] // RGB/RGBA parseToRgba('rgb(255, 128, 0)'); // [255, 128, 0, 1] parseToRgba('rgba(255, 128, 0, 0.5)'); // [255, 128, 0, 0.5] // HSL/HSLA parseToRgba('hsl(120, 100%, 50%)'); // [0, 255, 0, 1] parseToRgba('hsla(120, 100%, 50%, 0.5)'); // [0, 255, 0, 0.5] // Named colors parseToRgba('red'); // [255, 0, 0, 1] parseToRgba('cornflowerblue'); // [100, 149, 237, 1] parseToRgba('transparent'); // [0, 0, 0, 0] ``` -------------------------------- ### Saturate and Desaturate Colors Source: https://context7.com/ricokahler/color2k/llms.txt Functions to modify the saturation level of a color. These are useful for creating vibrant or muted versions of existing colors. ```javascript import { saturate, desaturate } from 'color2k'; // Increase saturation saturate('hsl(0, 50%, 50%)', 0.2); // 'hsla(0, 70%, 50%, 1)' // Decrease saturation desaturate('red', 0.5); // 'hsla(0, 50%, 50%, 1)' ``` -------------------------------- ### Convert Color to Hex - color2k Source: https://context7.com/ricokahler/color2k/llms.txt Converts any valid CSS color string to its hex representation. Includes an 8-digit hex code if the alpha channel is less than 1. ```javascript import { toHex } from 'color2k'; toHex('red'); // '#ff0000' toHex('rgb(0, 128, 255)'); // '#0080ff' toHex('hsl(120, 100%, 50%)'); // '#00ff00' toHex('rgba(255, 0, 0, 0.5)'); // '#ff000080' toHex('cornflowerblue'); // '#6495ed' ``` -------------------------------- ### Determine Readable Text Color Source: https://context7.com/ricokahler/color2k/llms.txt Automatically selects either black or white text based on which provides better contrast against a given background color. ```javascript import { readableColor } from 'color2k'; const getTextStyle = (bgColor) => ({ backgroundColor: bgColor, color: readableColor(bgColor) }); ``` -------------------------------- ### Clamp Values with guard Source: https://context7.com/ricokahler/color2k/llms.txt Constrains a numeric value within a specified minimum and maximum range, commonly used for validating color channels. ```javascript import { guard } from 'color2k'; guard(0, 255, 128); // 128 guard(0, 255, -10); // 0 guard(0, 255, 300); // 255 ``` -------------------------------- ### Convert Color to RGBA String - color2k Source: https://context7.com/ricokahler/color2k/llms.txt Converts any valid CSS color string into the 'rgba(r, g, b, a)' string format. Handles hex, hsl, named colors, and 'transparent'. ```javascript import { toRgba } from 'color2k'; toRgba('#ff0000'); // 'rgba(255, 0, 0, 1)' toRgba('hsl(120, 100%, 50%)'); // 'rgba(0, 255, 0, 1)' toRgba('blue'); // 'rgba(0, 0, 255, 1)' toRgba('transparent'); // 'rgba(0, 0, 0, 0)' ``` -------------------------------- ### Calculate Relative Luminance Source: https://context7.com/ricokahler/color2k/llms.txt Determines the relative luminance of a color based on WCAG standards, returning a value between 0 (darkest) and 1 (lightest). ```javascript import { getLuminance } from 'color2k'; getLuminance('white'); // 1 getLuminance('black'); // 0 getLuminance('red'); // 0.2126 ``` -------------------------------- ### Convert Color to HSLA String - color2k Source: https://context7.com/ricokahler/color2k/llms.txt Converts any valid CSS color string into the 'hsla(h, s%, l%, a)' string format. Handles hex, rgb, named colors, and transparent colors. ```javascript import { toHsla } from 'color2k'; toHsla('#ff0000'); // 'hsla(0, 100%, 50%, 1)' toHsla('rgb(0, 255, 0)'); // 'hsla(120, 100%, 50%, 1)' toHsla('blue'); // 'hsla(240, 100%, 50%, 1)' toHsla('rgba(128, 128, 128, 0.5)'); // 'hsla(0, 0%, 50%, 0.5)' ``` -------------------------------- ### Adjust Hue Source: https://context7.com/ricokahler/color2k/llms.txt Rotates the hue of a color by a specified degree (0-360). This is useful for generating color palettes such as complementary or triadic schemes. ```javascript import { adjustHue } from 'color2k'; adjustHue('red', 120); // 'hsla(120, 100%, 50%, 1)' adjustHue('red', 180); // 'hsla(180, 100%, 50%, 1)' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.