### Import and Initialize Color Parsing Source: https://github.com/myndex/colorparsley/blob/master/src/test.html Imports necessary functions from the colorparsley library and sets up an output element for displaying test results. This is the initial setup for running the color parsing tests. ```javascript import { colorParsley, colorToHex, colorToRGB } from './colorparsley.js'; let outputText = document.getElementById('test'); outputText.innerHTML = '

TEST COLORS

'; outputText.innerHTML += '

Colors may be a hex string, a named color, an rgb(), or just a number

' ``` -------------------------------- ### Color Pipeline Example with colorParsley, colorToHex, and colorToRGB Source: https://context7.com/myndex/colorparsley/llms.txt Demonstrates a common use case for Color Parsley by creating a `normalizeColor` function that parses input, converts it to hex and rgb strings, and returns an object with the color details and colorspace. Handles invalid inputs by returning null. ```javascript import { colorParsley, colorToHex, colorToRGB } from 'colorparsley'; // Building a color pipeline function normalizeColor(input) { const parsed = colorParsley(input); if (!parsed[4]) return null; // isValid === false return { hex: colorToHex(parsed), // e.g. '5f9ea0' rgb: colorToRGB(parsed), // e.g. 'rgb(95,158,160)' array: parsed, // e.g. [95, 158, 160, 1, true, 'sRGB'] colorspace: parsed[5], // e.g. 'sRGB' }; } normalizeColor('cadetblue'); // { hex: '5f9ea0', rgb: 'rgb(95,158,160)', array: [...], colorspace: 'sRGB' } normalizeColor('invalid!!'); // null ``` -------------------------------- ### Check Color Validity using colorParsley Result Source: https://context7.com/myndex/colorparsley/llms.txt Provides an example of how to check the validity of a parsed color and access its components or error information. ```javascript const result = colorParsley(userInput); if (!result[4]) { console.error('Invalid color:', result[5]); // 'parsleyError' or 'inputError' } else { const [r, g, b, a, , colorspace] = result; console.log(`Parsed: r=${r} g=${g} b=${b} a=${a} space=${colorspace}`); } ``` -------------------------------- ### Parse Greyscale Shorthands with colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Illustrates parsing of greyscale shorthand notations, including integer + comma, percentage, and 2-digit hex. ```javascript colorParsley('123,'); // [123, 123, 123, 1, true, 'sRGB'] (INT + comma → grey) colorParsley('87%'); // [221.85, 221.85, 221.85, 1, true, 'sRGB'] (% → grey) colorParsley('#a7'); // [167, 167, 167, 1, true, 'sRGB'] (2-digit hex → grey) ``` -------------------------------- ### Parse RGB/RGBA Color Strings with colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Shows how to parse standard rgb() and rgba() color notations, including percentage values and floating-point RGB. ```javascript colorParsley('rgb(123,45,67)'); // [123, 45, 67, 1, true, 'sRGB'] colorParsley('rgba(123,45,67,0.5)'); // [123, 45, 67, 0.5, true, 'sRGB'] colorParsley('rgb(170.0, 187.0, 205.201, 0.7)'); // [170, 187, 205.201, 0.7, true, 'sRGB'] colorParsley('rgba(0,0,0,0)'); // [0, 0, 0, 0, true, 'sRGB'] colorParsley('100%,50%,25%'); // percentage rgb values → 0–255 scaled ``` -------------------------------- ### Parse Hex Color Strings with colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Demonstrates parsing of various hex string formats, including shorthand, with and without alpha, and optional hash. ```javascript import { colorParsley } from 'colorparsley'; // --- Hex strings --- colorParsley('#123456cc'); // [18, 52, 86, 0.8, true, 'sRGB'] colorParsley('#abc'); // [170, 187, 204, 1, true, 'sRGB'] (expands to #aabbcc) colorParsley('#fa'); // [250, 250, 250, 1, true, 'sRGB'] (greyscale shorthand) colorParsley('abcdef'); // [171, 205, 239, 1, true, 'sRGB'] (hash optional) ``` -------------------------------- ### Passthrough Array Input for colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Demonstrates that colorParsley will return a valid six-element array input as-is without modification. ```javascript colorParsley([255, 0, 128, 1, true, 'sRGB']); // [255, 0, 128, 1, true, 'sRGB'] (returned as-is) ``` -------------------------------- ### CSS 4 Color Compositing Formulas Source: https://github.com/myndex/colorparsley/blob/master/docs/ColorParsleyRegexChart.html Formulas for simple alpha compositing, including both premultiplied and straight (not premultiplied) color calculations. ```plaintext Er, Eg, Eb - Element color value Ea - Element alpha value Cr, Cg, Cb - Canvas color value (before blending) Ca - Canvas alpha value (before blending) Cr', Cg', Cb' - Canvas color value (after blending) Ca' - Canvas alpha value (after blending) Ca' = 1 - (1 - Ea) * (1 - Ca) Premultiplied colors Cr' = (1 - Ea) * Cr + Er Cg' = (1 - Ea) * Cg + Eg Cb' = (1 - Ea) * Cb + Eb Straight not Premultiplied Cr' = (1 - Ea) * Cr*Ca + Er*Ea Cg' = (1 - Ea) * Cg*Ca + Eg*Ea Cb' = (1 - Ea) * Cb*Ca + Eb*Ea ``` -------------------------------- ### Parse HSL and HWB Colors with colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Demonstrates parsing of HSL and HWB color formats, with and without alpha values. ```javascript colorParsley('hsl(112, 22.8%, 66.5%)'); // [155, 189, 150, 1, true, 'sRGB'] colorParsley('hsl(112, 22.8%, 66.5%, 0.8)'); // [155, 189, 150, 0.8, true, 'sRGB'] colorParsley('hwb(194, 0%, 0%)'); // converted to sRGB array ``` -------------------------------- ### Initialize Color Parsing Source: https://github.com/myndex/colorparsley/blob/master/docs/versionHistory.md Use the colorParsley function to parse a color string. The output format may vary based on the version and input type. ```javascript let rgbaArray = colorParsley('colorString') ` ``` -------------------------------- ### HTML Input for Real-time Color Entry Source: https://github.com/myndex/colorparsley/blob/master/README.md This HTML input element is configured to use the `entryKeys` JavaScript function for real-time color parsing and display updates as the user types. The `onclick` event selects all text on focus, improving usability. ```html ``` -------------------------------- ### Handle Invalid Color Inputs with colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Illustrates how colorParsley handles various invalid color inputs, returning specific error codes. ```javascript colorParsley('hello'); // [0, 0, 0, 0, false, 'parsleyError'] colorParsley('rgb(123, 255.7, 123)'); // [0, 0, 0, 0, false, 'parsleyError'] (out of range) colorParsley('rgb(123, 88%, 123)'); // [0, 0, 0, 0, false, 'parsleyError'] (mixed types) colorParsley({ fred: 1, bob: 20 }); // [0, 0, 0, 0, false, 'inputError'] (missing r/g/b) ``` -------------------------------- ### colorToHex Source: https://context7.com/myndex/colorparsley/llms.txt Converts a parsed RGBA array back into a compact hex string. Supports 3-character shorthand and omits alpha when it equals 1. ```APIDOC ## `colorToHex(rgba, allow3)` — RGBA Array to Hex String Converts a parsed RGBA array back into a compact hex string (without `#` prefix). If all channel values are divisible by 17 (i.e., `aa`, `bb`, etc.) and `allow3` is `true` (default), a 3-character shorthand is returned. Alpha is omitted when it equals `1` or is empty. RGB values are rounded before conversion. ### Parameters - **rgba** (Array | ParsedColor) - The RGBA array or parsed color object to convert. - **allow3** (boolean) - Optional. If true (default), allows 3-character shorthand hex output when possible. ### Returns - (string) - The hex string representation of the color. ### Example ```js import { colorParsley, colorToHex } from 'colorparsley'; // Basic round-trip colorToHex(colorParsley('abc')); // 'abc' colorToHex(colorParsley('#aabbcc')); // 'abc' colorToHex(colorParsley('#123456')); // '123456' colorToHex(colorParsley('#123456cc')); // '123456cc' colorToHex(colorParsley('#abcd')); // 'abcd' // Force 6-char output colorToHex(colorParsley('#abc'), false); // 'aabbcc' // Alpha of 1 is dropped colorToHex([255, 255, 255, 1]); // 'fff' colorToHex([255, 255, 255, 0.5]); // 'ffffff80' // Rounding is applied automatically colorToHex([170.4, 187.6, 204.1, 1]); // 'abc' ``` ``` -------------------------------- ### Parse CSS color() with Color Spaces using colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Shows parsing of the CSS `color()` function, specifying different color spaces like display-P3 and sRGB. ```javascript colorParsley('color(display-p3 0.234 0.876 0.656 / 0.8)'); // [59.67, 223.38, 167.28, 0.8, true, 'display-p3'] // RGB values multiplied by 255 for consistency with all other array types colorParsley('color(srgb 0.765 0.89 0.556)'); // [195.075, 226.95, 141.78, 1, true, 'srgb'] ``` -------------------------------- ### Parse Hexadecimal Numbers with colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Demonstrates parsing of hexadecimal numbers (e.g., 0x808080) and their decimal equivalents. ```javascript colorParsley(0x808080); // [128, 128, 128, 1, true, 'unknown'] colorParsley(0xabcdef); // [171, 205, 239, 1, true, 'unknown'] colorParsley(11259375); // [171, 205, 239, 1, true, 'unknown'] (decimal equiv.) ``` -------------------------------- ### colorParsley(colorIn) Source: https://context7.com/myndex/colorparsley/llms.txt Accepts a color value in any supported format and returns a six-element array `[R, G, B, A, isValid, colorspace]`. RGB values are in the `0–255` range. Alpha is `0.0–1.0`. On parse failure, it returns `[0,0,0,0,false,'parsleyError']` or `[0,0,0,0,false,'inputError']`. ```APIDOC ## `colorParsley(colorIn)` — Universal Color Parser ### Description Accepts a color value in any supported format and returns a six-element array `[R, G, B, A, isValid, colorspace]`. RGB values are in the `0–255` range. Alpha is `0.0–1.0`. On parse failure the array `[0,0,0,0,false,'parsleyError']` or `[0,0,0,0,false,'inputError']` is returned so callers never receive an exception. ### Parameters #### Path Parameters - **colorIn** (string | number | object | array) - Required - The color value to parse. Can be in various formats like hex strings, rgb(), rgba(), CSS4 named colors, HSL, HWB, CSS color() with color space, hexadecimal numbers, greyscale shorthands, plain objects with r/g/b keys, or a passthrough array. ### Response #### Success Response (200) - **R** (number) - The red component of the color (0-255). - **G** (number) - The green component of the color (0-255). - **B** (number) - The blue component of the color (0-255). - **A** (number) - The alpha component of the color (0.0-1.0). - **isValid** (boolean) - True if the color was parsed successfully, false otherwise. - **colorspace** (string) - The identified color space (e.g., 'sRGB', 'display-p3', 'unknown'). #### Error Response (on failure) - **R** (0) - **G** (0) - **B** (0) - **A** (0) - **isValid** (false) - **colorspace** (string) - Either 'parsleyError' or 'inputError'. ### Request Example ```js import { colorParsley } from 'colorparsley'; // --- Hex strings --- colorParsley('#123456cc'); // [18, 52, 86, 0.8, true, 'sRGB'] colorParsley('#abc'); // [170, 187, 204, 1, true, 'sRGB'] (expands to #aabbcc) // --- rgb() / rgba() --- colorParsley('rgb(123,45,67)'); // [123, 45, 67, 1, true, 'sRGB'] colorParsley('rgba(123,45,67,0.5)'); // [123, 45, 67, 0.5, true, 'sRGB'] // --- CSS4 named colors --- colorParsley('cadetblue'); // [95, 158, 160, 1, true, 'sRGB'] // --- HSL --- colorParsley('hsl(112, 22.8%, 66.5%)'); // [155, 189, 150, 1, true, 'sRGB'] // --- CSS color() with color space --- colorParsley('color(display-p3 0.234 0.876 0.656 / 0.8)'); // [59.67, 223.38, 167.28, 0.8, true, 'display-p3'] // --- Plain object with r/g/b keys --- colorParsley({ r: 123, g: 77, b: 200 }); // [123, 77, 200, 1, true, 'unknown'] // --- Passthrough array --- colorParsley([255, 0, 128, 1, true, 'sRGB']); // [255, 0, 128, 1, true, 'sRGB'] (returned as-is) // --- Error handling --- colorParsley('hello'); // [0, 0, 0, 0, false, 'parsleyError'] colorParsley({ fred: 1, bob: 20 }); // [0, 0, 0, 0, false, 'inputError'] (missing r/g/b) ``` ``` -------------------------------- ### Entry Key Cleanup for UX Source: https://github.com/myndex/colorparsley/blob/master/README.md This JavaScript function is designed for real-time input field cleanup. It processes color strings as the user types, providing instant feedback by calling colorParsley and updating the display. Adjust the allowed keys and the `showMeTheColor` function to fit your specific interface needs. ```javascript function entryKeys(colorString,e) { if ( ( ((e.which >= 48 && e.which <= 57 && event.shiftKey == false) || // 0-9 (e.which >= 65 && e.which <= 90) || // a-z (e.which >= 96 && e.which <= 105) // num keypad ) || e.which === 13 || // enter e.which === 9 || // tab key e.which === 188 || // comma key e.which === 194 || // comma num keypad key //e.which === 8 || // backspace //e.which === 17 || // ctrl //e.which === 46 || // delete //(e.which >= 91 && e.which <= 93) || // OS key (e.which === 48 && event.shiftKey == true) // close parenthesis ) ) { let myNewColor = colorParsley(colorString); showMeTheColor(myNewColor); // the function to do on entry. } } ``` -------------------------------- ### Parse CSS4 Named Colors with colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Illustrates parsing of CSS4 named colors, including common aliases like 'midgray'. ```javascript colorParsley('cadetblue'); // [95, 158, 160, 1, true, 'sRGB'] colorParsley('magenta'); // [255, 0, 255, 1, true, 'sRGB'] colorParsley('midgray'); // [160, 160, 160, 1, true, 'sRGB'] (bonus grey shortcuts) ``` -------------------------------- ### Parse Plain Objects with RGB Keys using colorParsley Source: https://context7.com/myndex/colorparsley/llms.txt Shows parsing of plain JavaScript objects with 'r', 'g', 'b' keys, optionally including 'alpha' and 'space'. ```javascript colorParsley({ r: 123, g: 77, b: 200 }); // [123, 77, 200, 1, true, 'unknown'] colorParsley({ red: 255, green: 128, blue: 0, alpha: 0.9 }); // [255, 128, 0, 0.9, true, 'unknown'] colorParsley({ r: 10, g: 20, b: 30, space: 'sRGB' }); // [10, 20, 30, 1, true, 'sRGB'] ``` -------------------------------- ### Convert RGBA Array to CSS rgb()/rgba() String with colorToRGB Source: https://context7.com/myndex/colorparsley/llms.txt Converts a parsed RGBA array to a CSS rgb() or rgba() string. Alpha of 1 results in rgb(), others in rgba(). By default, RGB channels are rounded and alpha is truncated to 3 decimal places. Set `round` to `false` to preserve raw float values. ```javascript import { colorParsley, colorToRGB } from 'colorparsley'; // Basic round-trip colorToRGB(colorParsley('abc')); // 'rgb(170,187,204)' colorToRGB(colorParsley('rgba(123,45,67,0.5)')); // 'rgba(123,45,67,0.5)' colorToRGB(colorParsley('#123456cc')); // 'rgba(18,52,86,0.8)' // Fully transparent → rgba with 0 alpha colorToRGB(colorParsley('rgba(0,0,0,0)')); // 'rgba(0,0,0,0)' // CSS color() with wide-gamut color space colorToRGB(colorParsley('color(display-p3 0.234 0.876 0.656 / 0.8)')); // 'rgba(60,223,167,0.8)' // Disable rounding to keep float precision colorToRGB(colorParsley('rgb(170.4, 187.6, 204.9)'), false); // 'rgb(170.4,187.6,204.9)' // Named color → rgb string colorToRGB(colorParsley('cadetblue')); // 'rgb(95,158,160)' ``` -------------------------------- ### colorToRGB Source: https://context7.com/myndex/colorparsley/llms.txt Converts a parsed RGBA array into a CSS rgb() or rgba() string. Alpha 1 produces rgb(), other values produce rgba(). ```APIDOC ## `colorToRGB(rgba, round)` — RGBA Array to `rgb()`/`rgba()` String Converts a parsed RGBA array into a CSS `rgb()` or `rgba()` string. Alpha `1` (or empty) produces `rgb()`; any other alpha produces `rgba()`. By default (`round = true`) RGB channels are rounded to integers, while alpha is truncated to 3 decimal places for precision. Pass `round = false` to preserve raw float values. ### Parameters - **rgba** (Array | ParsedColor) - The RGBA array or parsed color object to convert. - **round** (boolean) - Optional. If true (default), rounds RGB channels to integers and truncates alpha. If false, preserves raw float values. ### Returns - (string) - The CSS rgb() or rgba() string representation of the color. ### Example ```js import { colorParsley, colorToRGB } from 'colorparsley'; // Basic round-trip colorToRGB(colorParsley('abc')); // 'rgb(170,187,204)' colorToRGB(colorParsley('rgba(123,45,67,0.5)')); // 'rgba(123,45,67,0.5)' colorToRGB(colorParsley('#123456cc')); // 'rgba(18,52,86,0.8)' // Fully transparent → rgba with 0 alpha colorToRGB(colorParsley('rgba(0,0,0,0)')); // 'rgba(0,0,0,0)' // Disable rounding to keep float precision colorToRGB(colorParsley('rgb(170.4, 187.6, 204.9)'), false); // 'rgb(170.4,187.6,204.9)' ``` ``` -------------------------------- ### Convert RGBA Array to Hex String with colorToHex Source: https://context7.com/myndex/colorparsley/llms.txt Converts a parsed RGBA array to a hex string. Supports 3-character shorthand when possible and includes alpha if not 1. RGB values are rounded before conversion. Use `allow3` parameter to force 6-character output. ```javascript import { colorParsley, colorToHex } from 'colorparsley'; // Basic round-trip: parse then convert back to hex colorToHex(colorParsley('abc')); // 'abc' (3-char shorthand preserved) colorToHex(colorParsley('#aabbcc')); // 'abc' (collapses to 3-char) colorToHex(colorParsley('#123456')); // '123456' colorToHex(colorParsley('#123456cc')); // '123456cc' (alpha included) colorToHex(colorParsley('#abcd')); // 'abcd' (4-char with alpha) // Force 6-char output even when 3-char is possible colorToHex(colorParsley('#abc'), false); // 'aabbcc' // Alpha of 1 is dropped colorToHex([255, 255, 255, 1]); // 'fff' colorToHex([255, 255, 255, 0.5]); // 'ffffff80' // Rounding is applied automatically colorToHex([170.4, 187.6, 204.1, 1]); // 'abc' (rounds to 170,188,204 → aabbcc → abc) // Using with CSS color() output (values are 0–255 range after colorParsley) const p3Color = colorParsley('color(display-p3 0.234 0.876 0.656 / 0.8)'); colorToHex(p3Color); // '3bdfa7cc' (example — exact values depend on rounding) ``` -------------------------------- ### Convert Color to Hex String Source: https://github.com/myndex/colorparsley/blob/master/README.md Converts a color object parsed by colorParsley into a hex string. Ensure the input is a valid color object. ```javascript colorToHex(colorParsley('rgb(170,187,204)')) ``` -------------------------------- ### Convert Color to RGB String Source: https://github.com/myndex/colorparsley/blob/master/README.md Converts a color object parsed by colorParsley into an RGB string. Handles various input formats including hex. ```javascript colorToRGB(colorParsley('abc')) ``` -------------------------------- ### Test Various Color Formats with colorParsley Source: https://github.com/myndex/colorparsley/blob/master/src/test.html Tests the colorParsley function with a wide range of color input formats including RGBA, hex with alpha, named colors, RGB with alpha, hex numbers, HSL with alpha, comma-separated values, short hex, percentage RGB, and display-p3 colors. Also tests parsing of an object and invalid inputs. ```javascript let colorObject = {r: 123, g: 77, b: 200, fred: 'hello', nothing: 0,}; let color0='rgba(0,0,0,0)', color1 = '#123456cc', color2 = 'cadetblue', color3 = 'rgb(170.0, 187.0, 205.0,0.7)', color4 = 0x808080, color5 = 'hsl(112,22.8%,66.5%,0.8)', color6 = '123,', color7 = 'DEF', color10 = 'color("display-p3" 0.234 0.876 0.656 / 0.8)', color11 = '#abcd', color12 = 'rgba(123.5,74.2,255 0.8)', color14 = 'rgba(170.2,187.3,203.7,0.8)'; outputText.innerHTML +='
color 0: ' + color0 + ' \t array: \[' + colorParsley(color0) + '\]' + ' 
color 1: ' + color1 + ' \t array: \[' + colorParsley(color1) + '\]' + '
color 2: ' + color2 + ' \t array: \[' + colorParsley(color2) + '\]' + '
color 3: ' + color3 + '\t array: \[' + colorParsley(color3) + '\]' + '
color 4: ' + color4 + '(0x808080) \t array: \[' + colorParsley(color4) + '\]' + '
color 5: ' + color5 + ' \t array: \[' + colorParsley(color5) + '\]' + '
color 6: ' + color6 + ' \t array: \[' + colorParsley(color6) + '\]' + '
color 7: ' + color7 + ' \t array: \[' + colorParsley(color7) + '\]' + '
color 8: ' + '#fa' + ' \t array: \[' + colorParsley('#fa') + '\]' + '
color 9: ' + '60%' + ' \t array: \[' + colorParsley('60%') + '\]' + '
color 9b: ' + 'rgb(77%,87%,46%)' + ' \t array: \[' + colorParsley('rgb(77%,87%,46%)') + '\]' + '
color 9c: ' + 'deeppink' + ' \t array: \[' + colorParsley('deeppink') + '\]' + '
color 9cc: ' + '#ff1493' + ' \t array: \[' + colorParsley('#ff1493') + '\]' + '
color10:
' + color10 + ' array: \[' + colorParsley(color10) + '\]' + '
colorObj: ' + colorObject + ' \t array: \[' + colorParsley(colorObject) + '\]' + '
ToHex: ' + color3 + '\t string: ' + colorToHex(colorParsley(color3)) + '
ToHex: ' + 'ABC' + ' \t string: ' + colorToHex(colorParsley('abc')) + '
ToHEX: ' + color10 + ' string: ' + colorToHex(colorParsley(color10)) + '
ToHEX: ' + color11 + ' \t string: ' + colorToHex(colorParsley(color11)) + '
ToHEX: ' + color12 + ' \t string: ' + colorToHex(colorParsley(color12)) + '
ToHEX: ' + color14 + ' \t string: ' + colorToHex(colorParsley(color14)) + '
ToRGB: ' + color10 + ' string: ' + colorToRGB(colorParsley(color10)) + '
ToRGB: ' + color11 + ' \t string: ' + colorToRGB(colorParsley(color11)) + '
ToRGB: ' + color4 + ' \t string: ' + colorToRGB(colorParsley(color4)) + '
ToRGB: ' + 'abc' + ' \t string: ' + colorToRGB(colorParsley('abc')) + '

Fail: ' + 'rgb(123,88%,79)' + ' \t array: \[' + colorParsley('rgb(123,88%,79)') + '\]' + '
Fail: ' + 'hello' + ' \t array: \[' + colorParsley('hello') + '\]' + '
Fail: ' + '{fred: 1, bob: 20, grace: 9,}' + '\t array: \[' + colorParsley({fred: 1, bob: 20, alice: 9,}) + '\]' ; ``` -------------------------------- ### Color Parsing Regex Source: https://github.com/myndex/colorparsley/blob/master/docs/ColorParsleyRegexChart.html This regex handles hex strings (3-6 digits, with optional alpha), RGB(A) values (numbers or percentages), CSS4 color tags (like sRGB, P3), and other color functions (HSL, HWB, LCH) with optional alpha. It includes validation for number ranges and percentage formats. ```regex /(?:^(?:#|0x|) (?:(?:([\da-f])([\da-f])([\da-f])([\da-f])?)(?!\S)| (?:([\da-f]{2})(?:([\da-f]{2})([\da-f]{2})([\da-f]{2})?)?))| (?:(?:^(?:rgba?|)\( ? (?:(?:(?:(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?)))(?:,[^\S]?$| (?:(?:, ?| )(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?) (?:, ?| )(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?)))| (100%|\d{1,2}(?:\.\d{1,24})?%)(?:,?[^\S]?$|(?:(?:, ?| ) ((?:100%|\d{1,2}(?:\.\d{1,24})?%)(?:, ?| ) ((?:100%|\d{1,2}(?:\.\d{1,24})?%)))))| (^(?:color\((srgb|srgb-linear|display-p3|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65) (?: (100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])) (?: (100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])) (?: (100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])))| (^(?:((?:r(?!gb)|c(?!olor)|[abd-qs-z])[a-z]{2,5})\( ? ((?:\d{0,3}\.|)\d{1,24}%?)(?:, ?| ) ((?:\d{0,3}\.|)\d{1,24}%?)(?:, ?| ) ((?:\d{0,3}\.|)\d{1,24}%?)))) (?:(?:,| \/| ) ? (?:(100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])))? (?:\)| |))[^\S]?$/ ``` -------------------------------- ### JavaScript hwbToRgb Reference Function Source: https://github.com/myndex/colorparsley/blob/master/README.md Reference implementation of hwbToRgb from CSS4. Converts HWB color values to RGB. Hue is expected in degrees, white and black in percentage (0-100). This function utilizes hslToRgb internally. Returns an array of RGB values between 0.0 and 1.0. ```javascript function hwbToRgb(hue, white, black) { // CSS4 reference implementation white /= 100.0; black /= 100.0; if (white + black >= 1) { let gray = white / (white + black); return [gray, gray, gray]; } let rgb = hslToRgb(hue, 100.0, 50.0); for (let i = 0; i < 3; i++) { rgb[i] *= (1 - white - black); rgb[i] += white; } return rgb; // returns 0.0 - 1.0 }; ``` -------------------------------- ### Parse Color String to RGBA Array Source: https://github.com/myndex/colorparsley/blob/master/README.md Use colorParsley() to convert color strings into a standardized RGBA integer array. The output array includes validity and colorspace information. Handles HEX, RGB, and named colors. ```javascript let textColor = colorParsley('#111111'); let backgroundColor = colorParsley('rgb(123,23,233,1.0)'); console.log(textColor); // [17,17,17,1,true,'sRGB'] console.log(backgroundColor); // [123,23,233,1,true,'sRGB'] // STRUCTURE returnedArray = [R,G,B,A,isValidBool,colorspaceString] ``` -------------------------------- ### JavaScript hslToRgb Reference Function Source: https://github.com/myndex/colorparsley/blob/master/README.md Reference implementation of hslToRgb from CSS4. Converts HSL color values to RGB. Hue is expected in degrees (0-360), saturation and lightness in percentage (0-100). Returns an array of RGB values between 0.0 and 1.0. ```javascript function hslToRgb (hue, sat, light) { hue = hue % 360; if (hue < 0) { hue += 360; } sat /= 100.0; light /= 100.0; function f(n) { let k = (n + hue/30) % 12; let a = sat * Math.min(light, 1 - light); return light - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)); } return [f(0), f(8), f(4)]; // returns 0.0 - 1.0 }; ``` -------------------------------- ### ColorParsley Regex String Source: https://github.com/myndex/colorparsley/blob/master/docs/ColorParsleyRegexChart.html This is the primary regular expression used by colorParsley for parsing color values. It supports hex, rgb, rgba, and CSS color() function formats. ```regex // colorParsley regex string 0.1.6 /(?:^(?:#|0x|)(?:(?:([\da-f])([\da-f])([\da-f])([\da-f])?)(?!\S)|(?:([\da-f]{2})(?:([\da-f]{2})([\da-f]{2})([\da-f]{2})?)?))|(?:(?:^(?:rgba?|)\( ?(?:(?:(?:(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?)))(?:,[^\S]?$|(?:(?:, ?| )(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?)(?:, ?| )(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?)))|(100%|\d{1,2}(?:\.\d{1,24})?%)(?:,?[^\S]?$|(?:(?:, ?| )(?:(100%|\d{1,2}(?:\.\d{1,24})?%)(?:, ?| )(100%|\d{1,2}(?:\.\d{1,24})?%)))))|^(?:color\((srgb|srgb-linear|display-p3|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65) (?:(100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])) (?:(100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])) (?:(100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])))|^(?:((?:r(?!gb)|c(?!olor)|[abd-qs-z])[a-z]{2,5})\( ?((?:\d{0,3}\.|)\d{1,24}%?)(?:, ?| )((?:\d{0,3}\.|)\d{1,24}%?)(?:, ?| )((?:\d{0,3}\.|)\d{1,24}%?))))(?:(?:,| \/| ) ?(?:(100%|\d{1,2}(?:\.\d{1,24})?%|0?\.\d{1,24}|[01])))?(?:\)| |))[^\S]?$/ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.