{"version":3,"file":"utils.cjs","names":["extend","namesPlugin"],"sources":["../../src/duotone-picker/utils.ts"],"sourcesContent":["import { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\nimport type { DuotonePickerProps } from './types';\n\nextend( [ namesPlugin ] );\n\n/**\n * Object representation for a color.\n *\n * @typedef {Object} RGBColor\n * @property {number} r Red component of the color in the range [0,1].\n * @property {number} g Green component of the color in the range [0,1].\n * @property {number} b Blue component of the color in the range [0,1].\n */\n\n/**\n * Calculate the brightest and darkest values from a color palette.\n *\n * @param palette Color palette for the theme.\n *\n * @return Tuple of the darkest color and brightest color.\n */\nexport function getDefaultColors(\n\tpalette: DuotonePickerProps[ 'colorPalette' ]\n) {\n\t// A default dark and light color are required.\n\tif ( ! palette || palette.length < 2 ) {\n\t\treturn [ '#000', '#fff' ];\n\t}\n\n\treturn palette\n\t\t.map( ( { color } ) => ( {\n\t\t\tcolor,\n\t\t\tbrightness: colord( color ).brightness(),\n\t\t} ) )\n\t\t.reduce(\n\t\t\t( [ min, max ], current ) => {\n\t\t\t\treturn [\n\t\t\t\t\tcurrent.brightness <= min.brightness ? current : min,\n\t\t\t\t\tcurrent.brightness >= max.brightness ? current : max,\n\t\t\t\t];\n\t\t\t},\n\t\t\t[\n\t\t\t\t{ brightness: 1, color: '' },\n\t\t\t\t{ brightness: 0, color: '' },\n\t\t\t]\n\t\t)\n\t\t.map( ( { color } ) => color );\n}\n\n/**\n * Generate a duotone gradient from a list of colors.\n *\n * @param colors CSS color strings.\n * @param angle  CSS gradient angle.\n *\n * @return  CSS gradient string for the duotone swatch.\n */\nexport function getGradientFromCSSColors(\n\tcolors: string[] = [],\n\tangle = '90deg'\n) {\n\tconst l = 100 / colors.length;\n\n\tconst stops = colors\n\t\t.map( ( c, i ) => `${ c } ${ i * l }%, ${ c } ${ ( i + 1 ) * l }%` )\n\t\t.join( ', ' );\n\n\treturn `linear-gradient( ${ angle }, ${ stops } )`;\n}\n\n/**\n * Convert a color array to an array of color stops.\n *\n * @param colors CSS colors array\n *\n * @return Color stop information.\n */\nexport function getColorStopsFromColors( colors: string[] ) {\n\treturn colors.map( ( color, i ) => ( {\n\t\tposition: ( i * 100 ) / ( colors.length - 1 ),\n\t\tcolor,\n\t} ) );\n}\n\n/**\n * Convert a color stop array to an array colors.\n *\n * @param colorStops Color stop information.\n *\n * @return CSS colors array.\n */\nexport function getColorsFromColorStops(\n\tcolorStops: { position: number; color: string }[] = []\n) {\n\treturn colorStops.map( ( { color } ) => color );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIAA,GAAAA,OAAAA,OAAAA,CAAQ,CAAEC,qBAAAA,OAAY,CAAE;;;;;;;;;;;;;;;;AAkBxB,SAAgB,iBACf,SACC;CAED,IAAK,CAAE,WAAW,QAAQ,SAAS,GAClC,OAAO,CAAE,QAAQ,MAAO;CAGzB,OAAO,QACL,KAAO,EAAE,aAAe;EACxB;EACA,aAAA,GAAY,OAAA,OAAA,CAAQ,KAAM,CAAC,CAAC,WAAW;CACxC,EAAI,CAAC,CACJ,QACE,CAAE,KAAK,MAAO,YAAa;EAC5B,OAAO,CACN,QAAQ,cAAc,IAAI,aAAa,UAAU,KACjD,QAAQ,cAAc,IAAI,aAAa,UAAU,GAClD;CACD,GACA,CACC;EAAE,YAAY;EAAG,OAAO;CAAG,GAC3B;EAAE,YAAY;EAAG,OAAO;CAAG,CAC5B,CACD,CAAC,CACA,KAAO,EAAE,YAAa,KAAM;AAC/B;;;;;;;;;AAUA,SAAgB,yBACf,SAAmB,CAAC,GACpB,QAAQ,SACP;CACD,MAAM,IAAI,MAAM,OAAO;CAMvB,OAAO,oBAAqB,MAAO,IAJrB,OACZ,KAAO,GAAG,MAAO,GAAI,EAAG,GAAI,IAAI,EAAG,KAAM,EAAG,IAAM,IAAI,KAAM,EAAG,EAAG,CAAC,CACnE,KAAM,IAEoC,EAAG;AAChD;;;;;;;;AASA,SAAgB,wBAAyB,QAAmB;CAC3D,OAAO,OAAO,KAAO,OAAO,OAAS;EACpC,UAAY,IAAI,OAAU,OAAO,SAAS;EAC1C;CACD,EAAI;AACL;;;;;;;;AASA,SAAgB,wBACf,aAAoD,CAAC,GACpD;CACD,OAAO,WAAW,KAAO,EAAE,YAAa,KAAM;AAC/C"}