### Install Colord Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Install the Colord library using npm. ```bash npm install colord ``` -------------------------------- ### Setup with All Plugins Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Extends the Colord library with all available plugins for comprehensive color manipulation capabilities. ```typescript import { colord, extend } from "colord"; import a11yPlugin from "colord/plugins/a11y"; import cmykPlugin from "colord/plugins/cmyk"; import harmoniesPlugin from "colord/plugins/harmonies"; import hwbPlugin from "colord/plugins/hwb"; import labPlugin from "colord/plugins/lab"; import lchPlugin from "colord/plugins/lch"; import minifyPlugin from "colord/plugins/minify"; import mixPlugin from "colord/plugins/mix"; import namesPlugin from "colord/plugins/names"; import xyzPlugin from "colord/plugins/xyz"; extend([ a11yPlugin, cmykPlugin, harmoniesPlugin, hwbPlugin, labPlugin, lchPlugin, minifyPlugin, mixPlugin, namesPlugin, xyzPlugin, ]); ``` -------------------------------- ### Colord Accessibility Plugin Usage Example Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md An example demonstrating how to use the a11y plugin to check color accessibility and find the best contrast option. It registers the plugin and then uses isReadable() and contrast(). ```typescript import { colord, extend } from "colord"; import a11yPlugin from "colord/plugins/a11y"; extend([a11yPlugin]); // Check if color combination is accessible const textColor = "#333"; const bgColor = "#fff"; if (colord(textColor).isReadable(bgColor)) { console.log("✓ Color combination meets WCAG AA standards"); } // Find best contrast option const colors = ["#666", "#999", "#ccc"]; const best = colors.reduce((a, b) => colord(a).contrast(bgColor) > colord(b).contrast(bgColor) ? a : b ); console.log(`Best contrast: ${best} with ratio ${colord(best).contrast(bgColor)}`); ``` -------------------------------- ### Plugin Loading Pattern Source: https://github.com/omgovich/colord/blob/master/_autodocs/README.md Illustrates how to load and use plugins to extend Colord's functionality, providing examples for accessibility and color mixing. ```APIDOC ## Plugin Loading Pattern ### Loading Multiple Plugins ```typescript import { colord, extend } from "colord"; import a11yPlugin from "colord/plugins/a11y"; import mixPlugin from "colord/plugins/mix"; extend([a11yPlugin, mixPlugin]); // Plugin methods now available colord("#000").luminance() colord("#f00").mix("#00f") ``` ``` -------------------------------- ### Basic Setup - Core Library Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Demonstrates creating color instances, detecting input formats, and generating random colors using the core Colord library without any plugins. ```typescript import { colord, getFormat, random } from "colord"; // Create color instances const red = colord("#ff0000"); const blue = colord({ r: 0, g: 0, b: 255 }); const hsl = colord("hsl(180, 50%, 50%)"); // Detect input format getFormat("#aabbcc"); // "hex" getFormat({ r: 0, g: 0, b: 0 }); // "rgb" // Random color const randomColor = random(); ``` -------------------------------- ### Plugin Documentation Source: https://github.com/omgovich/colord/blob/master/_autodocs/COMPLETION_SUMMARY.txt Information on all plugins available for the Colord library, including their purpose, added methods, parameter tables, return types, and usage examples. ```APIDOC ## Plugin Documentation This section covers all plugins compatible with the Colord library. For each plugin, an overview of its purpose is provided, along with details on the methods it adds to the Colord API. This includes method signatures, parameter/option tables, return type descriptions, and at least one usage example per method. An integration or setup example is also included for each plugin. ### Plugin Details * **Overview and Purpose**: Explains what the plugin does and its use case. * **Methods Added**: Lists and describes new methods provided by the plugin. * **Parameter/Option Tables**: Details parameters or options for plugin methods. * **Return Type Descriptions**: Explains the return values of plugin methods. * **Usage Example**: Demonstrates how to use each method provided by the plugin. * **Integration/Setup Example**: Shows how to integrate or set up the plugin. ``` -------------------------------- ### Basic Colord Usage Source: https://github.com/omgovich/colord/blob/master/README.md Demonstrates basic color manipulation and conversion using the colord library. Includes examples of grayscale conversion, alpha adjustment, checking lightness, and color darkening. ```javascript import { colord } from "colord"; colord("#ff0000").grayscale().alpha(0.25).toRgbString(); // "rgba(128, 128, 128, 0.25)" colord("rgb(192, 192, 192)").isLight(); // true colord("hsl(0, 50%, 50%)").darken(0.25).toHex(); // "#602020" ``` -------------------------------- ### Colord Core API Skeleton Source: https://github.com/omgovich/colord/blob/master/_autodocs/README.md Demonstrates creating color instances, getting format, generating random colors, extending with plugins, and performing conversions, manipulations, and analyses. Chaining multiple operations is also shown. ```typescript import { colord, getFormat, random, extend, Colord } from "colord"; // Create instances const color: Colord = colord("#ff0000"); const format: Format | undefined = getFormat("#ff0000"); const random: Colord = random(); // Extend with plugins extend([pluginA, pluginB]); // Conversion color.toHex() // "#ff0000" color.toRgb() // { r: 255, g: 0, b: 0, a: 1 } color.toHsl() // { h: 0, s: 100, l: 50, a: 1 } // Manipulation color.alpha(0.5) // Returns new Colord color.lighten(0.2) // Returns new Colord color.rotate(90) // Returns new Colord // Analysis color.brightness() // 0-1 color.isLight() // boolean color.isValid() // boolean // Chaining color.lighten(0.1).saturate(0.2).alpha(0.8).toHex() ``` -------------------------------- ### Colord Mix Plugin Usage Examples Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md Demonstrates practical applications of the Colord mix plugin, such as creating color scales for data visualization and generating UI design system palettes. ```typescript import { colord, extend } from "colord"; import mixPlugin from "colord/plugins/mix"; extend([mixPlugin]); // Create a color scale for data visualization const dataColors = { high: colord("#2ecc71"), // Green medium: colord("#f39c12").mix("#2ecc71", 0.5), // Orange-green mix low: colord("#e74c3c"), // Red }; // Generate palette for UI design system const brandColor = colord("#3498db"); const colorScale = [ ...brandColor.tints(3), brandColor, ...brandColor.shades(3), ]; ``` -------------------------------- ### Adjust Saturation of a Color Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Provides examples for increasing saturation, decreasing saturation, and converting a color to grayscale. Returns a new Colord object. ```typescript const color = colord("hsl(0, 50%, 50%)"); color.saturate(0.25).toHslString(); // Increase saturation by 25% color.desaturate(0.25).toHslString(); // Decrease saturation by 25% color.grayscale().toHslString(); // Remove all saturation ``` -------------------------------- ### Usage Example: Find Closest Color Match Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md Demonstrates how to find the perceptually closest color in a palette to a target color using the delta method. ```typescript import { colord, extend } from "colord"; import labPlugin from "colord/plugins/lab"; extend([labPlugin]); // Find perceptually similar colors function findClosestMatch(color, palette) { const target = colord(color); return palette.reduce((closest, current) => { const targetDelta = target.delta(closest); const currentDelta = target.delta(current); return currentDelta < targetDelta ? current : closest; }); } ``` -------------------------------- ### HSL Object Input Formats Source: https://github.com/omgovich/colord/blob/master/_autodocs/color-models.md Examples of how to represent HSL colors using object literals, including standard HSL, HSLA with alpha, and values with arbitrary precision. ```typescript { h: 0, s: 100, l: 50 } // Standard HSL { h: 0, s: 100, l: 50, a: 1 } // HSLA { h: 180.5, s: 75.3, l: 48.2, a: 0.7 } // Any precision values ``` -------------------------------- ### Usage Example: Check Color Contrast Sufficiency Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md Provides a function to check if the contrast between two colors is sufficient based on a minimum Delta E value. ```typescript import { colord, extend } from "colord"; import labPlugin from "colord/plugins/lab"; extend([labPlugin]); // Ensure color difference in interface function isContrastSufficient(color1, color2, minDelta = 0.3) { return colord(color1).delta(color2) >= minDelta; } ``` -------------------------------- ### Extend Colord with Mix Plugin Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Before using mix, tints, shades, or tones, extend the Colord instance with the mix plugin. This setup is required for all subsequent plugin method calls. ```typescript import { colord, extend } from "colord"; import mixPlugin from "colord/plugins/mix"; extend([mixPlugin]); ``` -------------------------------- ### HSL String Input Formats Source: https://github.com/omgovich/colord/blob/master/_autodocs/color-models.md Examples of HSL color representation using various string formats, including legacy functional syntax and modern CSS syntaxes with and without alpha. ```typescript "hsl(0, 100%, 50%)" // Legacy functional "hsla(0, 100%, 50%, 1)" // Legacy with alpha "hsl(0deg 100% 50%)" // Modern syntax "hsl(0 100% 50%)" // Whitespace-separated "hsla(0deg 100% 50% / 1)" // Modern with alpha ``` -------------------------------- ### Colord Parsing Examples Source: https://github.com/omgovich/colord/blob/master/README.md Illustrates various input formats accepted by the colord() function, including hexadecimal, RGB, RGBA, HSL, HSLA strings, and color objects. Requires the 'names' plugin for color names. ```javascript import { colord } from "colord"; // String input examples colord("#FFF"); colord("#ffffff"); colord("#ffffffff"); colord("rgb(255, 255, 255)"); colord("rgba(255, 255, 255, 0.5)"); colord("rgba(100% 100% 100% / 50%)"); colord("hsl(90, 100%, 100%)"); colord("hsla(90, 100%, 100%, 0.5)"); colord("hsla(90deg 100% 100% / 50%)"); colord("tomato"); // requires "names" plugin // Object input examples colord({ r: 255, g: 255, b: 255 }); colord({ r: 255, g: 255, b: 255, a: 1 }); colord({ h: 360, s: 100, l: 100 }); colord({ h: 360, s: 100, l: 100, a: 1 }); colord({ h: 360, s: 100, v: 100 }); colord({ h: 360, s: 100, v: 100, a: 1 }); ``` -------------------------------- ### API Reference Source: https://github.com/omgovich/colord/blob/master/_autodocs/COMPLETION_SUMMARY.txt Detailed documentation for all exported functions and methods available in the Colord library. This includes TypeScript signatures, parameter tables, return types, error information, and practical code examples. ```APIDOC ## API Reference This section details all exported functions and methods within the Colord library. Each entry includes a full TypeScript signature, a parameter table with name, type, required status, default value, and description, return type documentation, and error/exception information where applicable. At least one practical code example is provided for each function/method, along with its source file path and line reference. ### Functions/Methods * **Full TypeScript signature**: Exact signature from the source code. * **Parameter Table**: Includes `name`, `type`, `required`, `default`, and `description` for each parameter. * **Return Type Documentation**: Specifies the type and description of the returned value. * **Error/Exception Information**: Details any errors or exceptions that may be thrown. * **Code Example**: A practical, copy-paste-ready code snippet demonstrating usage. * **Source File Reference**: Path and line number in the source code for easy lookup. ``` -------------------------------- ### Get or Set Alpha Channel Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Use the alpha() method to get the current alpha value (0-1) or set a new alpha value on a Colord instance. Setting alpha returns a new Colord instance. ```typescript colord("#ffffff").alpha(); // 1 colord("rgba(50, 100, 150, 0.5)").alpha(); // 0.5 colord("rgb(0, 0, 0)").alpha(0.5).toRgbString(); // "rgba(0, 0, 0, 0.5)" ``` -------------------------------- ### Core API Skeleton Source: https://github.com/omgovich/colord/blob/master/_autodocs/README.md Demonstrates the basic usage of the Colord library, including creating color instances, extending with plugins, and performing conversions and manipulations. ```APIDOC ## Core API Skeleton ### Creating Instances ```typescript import { colord, getFormat, random, extend, Colord } from "colord"; const color: Colord = colord("#ff0000"); const format: Format | undefined = getFormat("#ff0000"); const randomColor: Colord = random(); ``` ### Extending with Plugins ```typescript import { colord, extend } from "colord"; // Assuming pluginA and pluginB are imported plugins // extend([pluginA, pluginB]); ``` ### Conversions ```typescript color.toHex() // "#ff0000" color.toRgb() // { r: 255, g: 0, b: 0, a: 1 } color.toHsl() // { h: 0, s: 100, l: 50, a: 1 } ``` ### Manipulations ```typescript color.alpha(0.5) // Returns new Colord color.lighten(0.2) // Returns new Colord color.rotate(90) // Returns new Colord ``` ### Analysis ```typescript color.brightness() // 0-1 color.isLight() // boolean color.isValid() // boolean ``` ### Chaining Operations ```typescript color.lighten(0.1).saturate(0.2).alpha(0.8).toHex() ``` ``` -------------------------------- ### rgba Property Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Gets the internal RGBA representation of the color. RGB channels are 0-255, and the alpha channel is 0-1. ```APIDOC ## rgba ### Description Gets the internal RGBA representation of the color (0-255 for RGB channels, 0-1 for alpha). ### Response #### Success Response (200) - **rgba** (RgbaColor) - The RGBA representation of the color. ### Response Example ```typescript const color = colord("rgb(255, 0, 0)"); console.log(color.rgba); // { r: 255, g: 0, b: 0, a: 1 } ``` ``` -------------------------------- ### Convert to CMYK String Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md Use the `toCmykString()` method to get a CSS `device-cmyk()` functional notation string. This is useful for CSS color definitions. ```typescript colord("#ffffff").toCmykString(); // "device-cmyk(0% 0% 0% 0%)" colord("#99ffff").toCmykString(); // "device-cmyk(40% 0% 0% 0%)" colord("#00336680").toCmykString(); // "device-cmyk(100% 50% 0% 60% / 0.5)" ``` -------------------------------- ### Colord Supported Input Formats Source: https://github.com/omgovich/colord/blob/master/_autodocs/README.md Illustrates the various ways to initialize Colord instances, including string representations (hex, rgb, hsl), color objects, and formats enabled by plugins. ```typescript // Strings colord("#ff0000") colord("#f00") colord("rgb(255, 0, 0)") colord("hsl(0, 100%, 50%)") // Objects colord({ r: 255, g: 0, b: 0 }) colord({ h: 0, s: 100, l: 50 }) // With plugins colord("tomato") // names plugin colord({ h: 0, w: 0, b: 0 }) // hwb plugin colord("device-cmyk(0% 100% 100% 0%)") // cmyk plugin ``` -------------------------------- ### Generate Random Color Source: https://github.com/omgovich/colord/blob/master/README.md Returns a new Colord instance with a random color value. Use `.toHex()` or `.toRgb()` to get the color value. ```javascript import { random } from "colord"; random().toHex(); // "#01c8ec" random().alpha(0.5).toRgb(); // { r: 13, g: 237, b: 162, a: 0.5 } ``` -------------------------------- ### Supported Output Formats Source: https://github.com/omgovich/colord/blob/master/_autodocs/README.md Lists the available methods for converting Colord instances to different color representations, including hex, RGB, HSL, and formats provided by plugins. ```APIDOC ## Supported Output Formats ### Standard Conversions ```typescript .toHex() .toHexString() // "#ff0000" .toRgb() .toRgbString() // { r, g, b, a } or "rgb(...)" .toHsl() .toHslString() // { h, s, l, a } or "hsl(...)" .toHsv() // { h, s, v, a } ``` ### Plugin-Based Conversions ```typescript .toHwb() .toHwbString() // hwb plugin .toLab() // lab plugin .toLch() .toLchString() // lch plugin .toCmyk() .toCmykString() // cmyk plugin .toXyz() // xyz plugin .toName() // names plugin .minify() // minify plugin ``` ``` -------------------------------- ### Get the hue value of a color Source: https://github.com/omgovich/colord/blob/master/README.md Returns the hue of a color in degrees. Handles both positive and negative hue values by normalizing them to the 0-360 range. ```javascript colord("hsl(90, 50%, 50%)").hue(); // 90 colord("hsl(-10, 50%, 50%)").hue(); // 350 ``` -------------------------------- ### Convert to LAB Color Object Source: https://github.com/omgovich/colord/blob/master/_autodocs/color-models.md Use the `.toLab()` method to get the LAB color representation. Alpha is stored as `alpha` in the returned object. ```typescript .toLab() // Returns LabaColor object { l, a, b, alpha } ``` -------------------------------- ### Convert Color to Different Output Formats Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Demonstrates converting a Colord object to various standard and plugin-specific color formats including Hex, RGB, HSL, HSV, HWB, Lab, Lch, CMYK, XYZ, and color names. Also shows how to minify hex codes. ```typescript const color = colord("#ff0000"); // Hex color.toHex(); // "#ff0000" // RGB color.toRgb(); // { r: 255, g: 0, b: 0, a: 1 } color.toRgbString(); // "rgb(255, 0, 0)" // HSL color.toHsl(); // { h: 0, s: 100, l: 50, a: 1 } color.toHslString(); // "hsl(0, 100%, 50%)" // HSV color.toHsv(); // { h: 0, s: 100, v: 100, a: 1 } // Plugin formats color.toHwb(); // { h: 0, w: 0, b: 0, a: 1 } color.toHwbString(); // "hwb(0 0% 0%)" color.toLab(); // { l: 53.24, a: 80.09, b: 67.2, alpha: 1 } color.toLch(); // { l: 53.24, c: 104.55, h: 39.99, a: 1 } color.toCmyk(); // { c: 0, m: 100, y: 100, k: 0, a: 1 } color.toXyz(); // { x: 41.246, y: 21.267, z: 1.933, a: 1 } color.toName(); // "red" color.minify(); // "#f00" ``` -------------------------------- ### Generate Tints, Shades, and Tones with mix Plugin Source: https://github.com/omgovich/colord/blob/master/README.md The mix plugin also provides utilities to generate tints, shades, and tones of a given color. ```javascript const color = colord("#ff0000"); color.tints(3).map((c) => c.toHex()); // ["#ff0000", "#ff9f80", "#ffffff"]; color.shades(3).map((c) => c.toHex()); // ["#ff0000", "#7a1b0b", "#000000"]; color.tones(3).map((c) => c.toHex()); // ["#ff0000", "#c86147", "#808080"]; ``` -------------------------------- ### Get the alpha channel value of a color Source: https://github.com/omgovich/colord/blob/master/README.md Extracts the alpha (transparency) value of a color, ranging from 0 (fully transparent) to 1 (fully opaque). ```javascript colord("#ffffff").alpha(); // 1 colord("rgba(50, 100, 150, 0.5)").alpha(); // 0.5 ``` -------------------------------- ### Colord Plugin Loading Pattern Source: https://github.com/omgovich/colord/blob/master/_autodocs/README.md Shows how to import and extend Colord with external plugins like a11y and mix. Plugin methods become available on Colord instances after extending. ```typescript import { colord, extend } from "colord"; import a11yPlugin from "colord/plugins/a11y"; import mixPlugin from "colord/plugins/mix"; extend([a11yPlugin, mixPlugin]); // Plugin methods now available colord("#000").luminance() colord("#f00").mix("#00f") ``` -------------------------------- ### Generate Color Tones with Mix Plugin Source: https://github.com/omgovich/colord/blob/master/README.md Use the `mix` plugin to generate color tones. Ensure the plugin is extended before use. The output is an array of Colord instances. ```javascript import { colord, extend } from "colord"; import mixPlugin from "colord/plugins/mix"; extend([mixPlugin]); const color = colord("#ff0000"); color.tones(3).map((c) => c.toHex()); // ["#ff0000", "#c86147", "#808080"]; ``` -------------------------------- ### Get Color Format Source: https://github.com/omgovich/colord/blob/master/README.md Determines the color model of a given input string or object using the getFormat function. Returns undefined for unrecognized formats. ```javascript import { getFormat } from "colord"; getFormat("#aabbcc"); // "hex" getFormat({ r: 13, g: 237, b: 162, a: 0.5 }); // "rgb" getFormat("hsl(180deg, 50%, 50%)"); // "hsl" getFormat("WUT?"); // undefined ``` -------------------------------- ### Register Colord Plugins Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md Demonstrates how to import and register a Colord plugin using the extend() function. Ensure the plugin is imported correctly. ```typescript import { colord, extend } from "colord"; import myPlugin from "colord/plugins/my-plugin"; extend([myPlugin]); // Plugin methods now available on all Colord instances ``` -------------------------------- ### Get Color Brightness Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Calculates the perceived brightness of a color, returning a value between 0 (black) and 1 (white). This calculation adheres to WCAG standards. ```typescript colord("#000000").brightness(); // 0 ``` ```typescript colord("#808080").brightness(); // 0.5 ``` ```typescript colord("#ffffff").brightness(); // 1 ``` -------------------------------- ### Convert to CIE XYZ Color Source: https://github.com/omgovich/colord/blob/master/_autodocs/color-models.md Use the `.toXyz()` method to get an XyzaColor object. Parse XYZ objects directly using the colord constructor. ```typescript .toXyz() // Returns XyzaColor object colord({ x: 95.047, y: 100, z: 108.883 }) // Parse XYZ object ``` -------------------------------- ### .mix(color2, ratio = 0.5) (mix plugin) Source: https://github.com/omgovich/colord/blob/master/README.md Produces a mixture of two colors and returns the result of mixing them. ```APIDOC ## .mix(color2, ratio = 0.5) (mix plugin) ### Description Produces a mixture of two colors and returns the result of mixing them (new Colord instance). Colord mixes colors through [LAB color space](https://en.wikipedia.org/wiki/CIELAB_color_space). ### Method `mix(color2, ratio)` ### Parameters #### Path Parameters - **color2** (string | Colord) - Required - The second color to mix. - **ratio** (number) - Optional - The mixing ratio. Defaults to 0.5. ### Request Example ```js import { colord, extend } from "colord"; import mixPlugin from "colord/plugins/mix"; extend([mixPlugin]); colord("#ffffff").mix("#000000").toHex(); // "#777777" colord("#800080").mix("#dda0dd").toHex(); // "#af5cae" colord("#cd853f").mix("#eee8aa", 0.6).toHex(); // "#e3c07e" colord("#008080").mix("#808000", 0.35).toHex(); // "#50805d" ``` ``` -------------------------------- ### Get Color Brightness and Lightness Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Calculate the brightness of a color and determine if it's light or dark. Brightness is a value between 0 (black) and 1 (white). ```typescript const color = colord("#808080"); color.brightness(); // 0.5 (0-1) color.isLight(); // true if brightness >= 0.5 color.isDark(); // true if brightness < 0.5 ``` -------------------------------- ### Mix Colors and Generate Palettes Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Requires the `mix` plugin. Shows how to mix two colors with a specified ratio to create intermediate colors and generate color palettes like shades, tints, and tones. ```typescript extend([mixPlugin]); // Mix two colors with custom ratio const mixed = colord("#ff0000").mix("#0000ff", 0.5).toHex(); // "#7a007a" (50/50 mix) const oneThird = colord("#ff0000").mix("#0000ff", 0.33).toHex(); // "#a80055" (33% mix towards blue) // Generate palettes const shades = colord("#ff0000").shades(5).map(c => c.toHex()); const tints = colord("#ff0000").tints(5).map(c => c.toHex()); const tones = colord("#ff0000").tones(5).map(c => c.toHex()); ``` -------------------------------- ### .toName(options?) (names plugin) Source: https://github.com/omgovich/colord/blob/master/README.md Converts a color to a CSS keyword. Returns `undefined` if the color is not specified in the specs. ```APIDOC ## .toName(options?) (names plugin) ### Description Converts a color to a [CSS keyword](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#color_keywords). Returns `undefined` if the color is not specified in the specs. ### Method `.toName(options?) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```js // Requires the "names" plugin to be loaded // import { colord } from "colord"; // import namesPlugin from "colord/plugins/names"; // colord.extend([namesPlugin]); colord("red").toName(); // "red" colord("#ff0000").toName(); // "red" colord("#f00").toName(); // "red" colord("#ff000000").toName(); // undefined ``` ``` -------------------------------- ### Manipulate Alpha Channel of a Color Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Shows how to get the current alpha value of a color and how to set a new alpha value, returning a new Colord object. ```typescript const color = colord("rgb(255, 0, 0)"); // Get alpha color.alpha(); // 1 // Set alpha color.alpha(0.5); // Returns new Colord with a: 0.5 ``` -------------------------------- ### Import HWB Plugin Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md Import the HWB plugin for Colord to enable HWB color space functionality. ```typescript import hwbPlugin from "colord/plugins/hwb"; ``` -------------------------------- ### Use Minify Plugin for Compact Output Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md For CSS output, use the minify plugin to obtain the shortest possible string representation of a color. ```typescript // Use minify plugin for CSS extend([minifyPlugin]); color.minify(); // Returns shortest representation ``` -------------------------------- ### Get RGBA Representation Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Access the internal RGBA representation of a Colord instance. The alpha channel ranges from 0 to 1, while RGB channels range from 0 to 255. ```typescript const color = colord("rgb(255, 0, 0)"); console.log(color.rgba); // { r: 255, g: 0, b: 0, a: 1 } ``` -------------------------------- ### Load All Colord Plugins Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md Import and extend Colord with all available plugins. This makes all plugin methods accessible globally after the extension. ```typescript import { colord, extend } from "colord"; import a11yPlugin from "colord/plugins/a11y"; import cmykPlugin from "colord/plugins/cmyk"; import harmoniesPlugin from "colord/plugins/harmonies"; import hwbPlugin from "colord/plugins/hwb"; import labPlugin from "colord/plugins/lab"; import lchPlugin from "colord/plugins/lch"; import minifyPlugin from "colord/plugins/minify"; import mixPlugin from "colord/plugins/mix"; import namesPlugin from "colord/plugins/names"; import xyzPlugin from "colord/plugins/xyz"; extend([ a11yPlugin, cmykPlugin, harmoniesPlugin, hwbPlugin, labPlugin, lchPlugin, minifyPlugin, mixPlugin, namesPlugin, xyzPlugin, ]); // All plugin methods now available ``` -------------------------------- ### Convert to LCH String Source: https://github.com/omgovich/colord/blob/master/_autodocs/color-models.md Use the `.toLchString()` method to get a string representation of the LCH color, formatted as 'lch(...)' or 'lch(.../ %)' depending on the alpha value. ```typescript .toLchString() // Returns "lch(...)" or "lch(.../ %)" string ``` -------------------------------- ### Chaining Color Manipulations Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Demonstrates chaining multiple color manipulation methods like saturate, lighten, and alpha. Ensure Colord is imported before use. ```typescript colord("#ff0000") .saturate(0.25) .lighten(0.1) .alpha(0.5) .toRgbString(); // "rgba(255, 76, 76, 0.5)" ``` -------------------------------- ### Manipulate Hue of a Color Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Shows how to get the current hue value, set a specific hue, and rotate the hue by a given degree. Returns a new Colord object. ```typescript const color = colord("hsl(0, 100%, 50%)"); color.hue(); // Get hue: 0 color.hue(180); // Set hue: returns new Colord color.rotate(90); // Rotate hue by 90°: returns new Colord ``` -------------------------------- ### .contrast(color2 = "#FFF") (a11y plugin) Source: https://github.com/omgovich/colord/blob/master/README.md Calculates a contrast ratio for a color pair. ```APIDOC ## .contrast(color2 = "#FFF") ### Description Calculates a contrast ratio for a color pair. This luminance difference is expressed as a ratio ranging from 1 (e.g. white on white) to 21 (e.g., black on a white). [WCAG Accessibility Level AA requires](https://webaim.org/articles/contrast/) a ratio of at least 4.5 for normal text and 3 for large text. ### Method `contrast(color2 = "#FFF")` ### Parameters - **color2** (string, optional): The color to compare against. Defaults to "#FFF" (white). ### Response - **number**: The contrast ratio between the two colors. ### Request Example ```js colord("#000000").contrast(); // 21 (black on white) colord("#ffffff").contrast("#000000"); // 21 (white on black) colord("#777777").contrast(); // 4.47 (gray on white) colord("#ff0000").contrast(); // 3.99 (red on white) colord("#0000ff").contrast("#ff000"); // 2.14 (blue on red) ``` ``` -------------------------------- ### Extend Colord with CMYK Plugin Source: https://github.com/omgovich/colord/blob/master/_autodocs/plugins.md Import and extend Colord with the CMYK plugin to enable CMYK color space support. This setup is required before using CMYK-specific methods. ```typescript import { colord, extend } from "colord"; import cmykPlugin from "colord/plugins/cmyk"; extend([cmykPlugin]); ``` -------------------------------- ### Add HWB Color Model Support with hwb Plugin Source: https://github.com/omgovich/colord/blob/master/README.md Enable support for the Hue-Whiteness-Blackness (HWB) color model. Includes conversion to and from HWB. ```javascript import { colord, extend } from "colord"; import hwbPlugin from "colord/plugins/hwb"; extend([hwbPlugin]); colord("#999966").toHwb(); // { h: 60, w: 40, b: 40, a: 1 } colord("#003366").toHwbString(); // "hwb(210 0% 60%)" colord({ h: 60, w: 40, b: 40 }).toHex(); // "#999966" colord("hwb(210 0% 60% / 50%)").toHex(); // "#00336680" ``` -------------------------------- ### Colord Constructor Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Creates a new Colord instance from a color input. The input can be in various formats like hex, RGB object, or CSS string. ```APIDOC ## new Colord(input: AnyColor) ### Description Creates a new Colord instance from a color input. ### Parameters #### Path Parameters - **input** (AnyColor) - Required - Color in any supported format ### Request Example ```typescript import { Colord } from "colord"; const color1 = new Colord("#ff0000"); const color2 = new Colord({ r: 255, g: 0, b: 0 }); const color3 = new Colord("rgb(255, 0, 0)"); ``` ``` -------------------------------- ### .tints(count = 5) (mix plugin) Source: https://github.com/omgovich/colord/blob/master/README.md Provides functionality to generate tints of a color. ```APIDOC ## .tints(count = 5) (mix plugin) ### Description Provides functionality to generate [tints](https://en.wikipedia.org/wiki/Tints_and_shades) of a color. Returns an array of `Colord` instances, including the original color. ### Method `tints(count)` ### Parameters #### Query Parameters - **count** (number) - Optional - The number of tints to generate. Defaults to 5. ### Request Example ```js import { colord, extend } from "colord"; import mixPlugin from "colord/plugins/mix"; extend([mixPlugin]); const color = colord("#ff0000"); color.tints(3).map((c) => c.toHex()); // ["#ff0000", "#ff9f80", "#ffffff"]; ``` ``` -------------------------------- ### HWB Color Model Methods Source: https://github.com/omgovich/colord/blob/master/_autodocs/color-models.md Use these methods to convert to and from the HWB color format. The plugin `hwb` must be imported. ```typescript .toHwb() .toHwbString() colord({ h: 0, w: 100, b: 0 }) colord("hwb(0 100% 0%)") ``` -------------------------------- ### Add CIE LAB Color Space Support with lab Plugin Source: https://github.com/omgovich/colord/blob/master/README.md Integrate support for the CIE LAB color space, including conversions and delta E calculations for perceived color difference. ```javascript import { colord, extend } from "colord"; import labPlugin from "colord/plugins/lab"; extend([labPlugin]); colord({ l: 53.24, a: 80.09, b: 67.2 }).toHex(); // "#ff0000" colord("#ffffff").toLab(); // { l: 100, a: 0, b: 0, alpha: 1 } colord("#afafaf").delta("#b4b4b4"); // 0.014 colord("#000000").delta("#ffffff"); // 1 ``` -------------------------------- ### Plugins Source: https://github.com/omgovich/colord/blob/master/_autodocs/INDEX.md Colord supports extensibility through plugins. Ten plugins are provided, covering functionalities like accessibility checks, color model conversions (CMYK, HWB, LAB, LCH, XYZ), color name lookups, and more. ```APIDOC ## Plugins ### Description Colord's plugin system allows for extending its capabilities with new color models, utilities, and functionalities. ### Available Plugins: - **a11y**: Accessibility related color checks. - **cmyk**: Support for CMYK color model. - **harmonies**: Generate color harmonies. - **hwb**: Support for HWB color model. - **lab**: Support for LAB color model. - **lch**: Support for LCH color model. - **minify**: Minify color string representations. - **mix**: Mix two colors. - **names**: Convert colors to/from CSS color names. - **xyz**: Support for XYZ color model. ### Usage Example (Conceptual) ```javascript // Assuming 'cmyk' plugin is imported and registered via extend() // const color = colord('cyan'); // console.log(color.toCmyk()); // { c: 100, m: 0, y: 0, k: 0 } ``` *(Note: Detailed documentation for each plugin and its methods can be found in `plugins.md`.)* ``` -------------------------------- ### Generate Color Palette with Tints and Shades Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Create a color palette by generating tints (lighter variations) and shades (darker variations) of a base color using the `mix` plugin. ```typescript extend([mixPlugin]); function generateColorPalette(baseColor) { const base = colord(baseColor); return { // Tints (lighter variations) tint10: base.mix("#ffffff", 0.1).toHex(), tint20: base.mix("#ffffff", 0.2).toHex(), tint30: base.mix("#ffffff", 0.3).toHex(), // Base base: base.toHex(), // Shades (darker variations) shade10: base.mix("#000000", 0.1).toHex(), shade20: base.mix("#000000", 0.2).toHex(), shade30: base.mix("#000000", 0.3).toHex(), }; } const blues = generateColorPalette("#0066ff"); ``` -------------------------------- ### Colord Type Imports and Usage Source: https://github.com/omgovich/colord/blob/master/_autodocs/types.md Demonstrates how to import various color types from the 'colord' library and how to declare variables with these types. Ensure you import the specific types you intend to use. ```typescript import { RgbColor, RgbaColor, HslColor, HslaColor, HsvColor, HsvaColor, AnyColor, } from "colord"; const myColor: HslColor = { h: 0, s: 50, l: 50 }; const rgba: RgbaColor = { r: 255, g: 0, b: 0, a: 1 }; ``` -------------------------------- ### Get or Set Hue Value Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md The hue() method retrieves the current hue (0-360) or sets a new hue value. Setting the hue returns a new Colord instance. Values outside the 0-360 range are normalized. ```typescript colord("hsl(90, 50%, 50%)").hue(); // 90 colord("hsl(90, 50%, 50%)").hue(180).toHslString(); // "hsl(180, 50%, 50%)" colord("hsl(90, 50%, 50%)").hue(370).toHslString(); // "hsl(10, 50%, 50%)" ``` -------------------------------- ### .toRgb() Source: https://github.com/omgovich/colord/blob/master/README.md Converts a color to RGB color space and returns an object. ```APIDOC ## .toRgb() ### Description Converts a color to RGB color space and returns an object. ### Method `.toRgb()` ### Parameters None ### Request Example ```js colord("#ff0000").toRgb(); // { r: 255, g: 0, b: 0, a: 1 } colord({ h: 180, s: 100, l: 50, a: 0.5 }).toRgb(); // { r: 0, g: 255, b: 255, a: 0.5 } ``` ``` -------------------------------- ### Convert Color to Name with Names Plugin Source: https://github.com/omgovich/colord/blob/master/README.md Converts a color to its CSS color name. Requires the 'names' plugin. If a color is not specified in CSS specs, it returns undefined. Use `closest: true` to get the nearest CSS color name. ```javascript import { colord, extend } from "colord"; import namesPlugin from "colord/plugins/names"; extend([namesPlugin]); colord("#ff6347").toName(); // "tomato" colord("#00ffff").toName(); // "cyan" colord("rgba(0, 0, 0, 0)").toName(); // "transparent" colord("#fe0000").toName(); // undefined (the color is not specified in CSS specs) colord("#fe0000").toName({ closest: true }); // "red" (closest color available) ``` -------------------------------- ### Create Colord Instances Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Instantiate Colord objects from various color formats like hex, RGB objects, or RGB strings. Ensure you import Colord from the 'colord' package. ```typescript import { Colord } from "colord"; const color1 = new Colord("#ff0000"); const color2 = new Colord({ r: 255, g: 0, b: 0 }); const color3 = new Colord("rgb(255, 0, 0)"); ``` -------------------------------- ### Object Inputs - Plugin Color Spaces Source: https://github.com/omgovich/colord/blob/master/_autodocs/usage-guide.md Create color instances from objects representing HWB, CMYK, LAB, LCH, and XYZ color spaces, requiring their respective plugins. ```typescript // HWB colord({ h: 60, w: 40, b: 40 }); // CMYK colord({ c: 0, m: 100, y: 100, k: 0, a: 1 }); // LAB colord({ l: 53.24, a: 80.09, b: 67.2, alpha: 1 }); // LCH colord({ l: 50, c: 30, h: 180, a: 1 }); // XYZ colord({ x: 41.246, y: 21.267, z: 1.933, a: 1 }); ``` -------------------------------- ### tints(count = 5) Source: https://github.com/omgovich/colord/blob/master/_autodocs/api-reference.md Generates an array of tints (mixing with white) from the color, including the original. ```APIDOC ## tints(count = 5) ### Description Generates an array of tints (mixing with white) from the color, including the original. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Signature ```typescript tints(count?: number): Colord[] ``` ### Parameters - **count** (number) - Optional - Number of tints to generate. Defaults to 5. ### Return Type `Colord[]` ### Examples ```typescript const color = colord("#ff0000"); color.tints(3).map((c) => c.toHex()); // ["#ff0000", "#ff9f80", "#ffffff"] ``` ``` -------------------------------- ### Convert Color to HWB with HWB Plugin Source: https://github.com/omgovich/colord/blob/master/README.md Converts a color to HWB (Hue-Whiteness-Blackness) color space. Requires the 'hwb' plugin. ```javascript import { colord, extend } from "colord"; import hwbPlugin from "colord/plugins/hwb"; extend([hwbPlugin]); colord("#ffffff").toHwb(); // { h: 0, w: 100, b: 0, a: 1 } colord("#555aaa").toHwb(); // { h: 236, w: 33, b: 33, a: 1 } ```