{"version":3,"file":"use-deprecated-props.mjs","names":[],"sources":["../../src/color-picker/use-deprecated-props.ts"],"sourcesContent":["import { colord } from 'colord';\nimport memoize from 'memize';\nimport { useCallback } from '@wordpress/element';\nimport type { ColorPickerProps, LegacyColor, LegacyProps } from './types';\n\nfunction isLegacyProps( props: any ): props is LegacyProps {\n\treturn (\n\t\ttypeof props.onChangeComplete !== 'undefined' ||\n\t\ttypeof props.disableAlpha !== 'undefined' ||\n\t\ttypeof props.color?.hex === 'string'\n\t);\n}\n\nfunction getColorFromLegacyProps(\n\tcolor: LegacyProps[ 'color' ]\n): string | undefined {\n\tif ( color === undefined ) {\n\t\treturn;\n\t}\n\n\tif ( typeof color === 'string' ) {\n\t\treturn color;\n\t}\n\n\tif ( color.hex ) {\n\t\treturn color.hex;\n\t}\n\n\treturn undefined;\n}\n\nconst transformColorStringToLegacyColor = memoize(\n\t( color: string ): LegacyColor => {\n\t\tconst colordColor = colord( color );\n\t\tconst hex = colordColor.toHex();\n\t\tconst rgb = colordColor.toRgb();\n\t\tconst hsv = colordColor.toHsv();\n\t\tconst hsl = colordColor.toHsl();\n\n\t\treturn {\n\t\t\thex,\n\t\t\trgb,\n\t\t\thsv,\n\t\t\thsl,\n\t\t\tsource: 'hex',\n\t\t\toldHue: hsl.h,\n\t\t};\n\t}\n);\n\nexport function useDeprecatedProps(\n\tprops: LegacyProps | ColorPickerProps\n): ColorPickerProps {\n\tconst { onChangeComplete } = props as LegacyProps;\n\tconst legacyChangeHandler = useCallback(\n\t\t( color: string ) => {\n\t\t\tonChangeComplete( transformColorStringToLegacyColor( color ) );\n\t\t},\n\t\t[ onChangeComplete ]\n\t);\n\tif ( isLegacyProps( props ) ) {\n\t\treturn {\n\t\t\tcolor: getColorFromLegacyProps( props.color ),\n\t\t\tenableAlpha: ! props.disableAlpha,\n\t\t\tonChange: legacyChangeHandler,\n\t\t};\n\t}\n\treturn {\n\t\t...props,\n\t\tcolor: props.color as ColorPickerProps[ 'color' ],\n\t\tenableAlpha: ( props as ColorPickerProps ).enableAlpha,\n\t\tonChange: ( props as ColorPickerProps ).onChange,\n\t};\n}\n"],"mappings":";;;;AAKA,SAAS,cAAe,OAAmC;CAC1D,OACC,OAAO,MAAM,qBAAqB,eAClC,OAAO,MAAM,iBAAiB,eAC9B,OAAO,MAAM,OAAO,QAAQ;AAE9B;AAEA,SAAS,wBACR,OACqB;CACrB,IAAK,UAAU,KAAA,GACd;CAGD,IAAK,OAAO,UAAU,UACrB,OAAO;CAGR,IAAK,MAAM,KACV,OAAO,MAAM;AAIf;AAEA,MAAM,oCAAoC,SACvC,UAAgC;CACjC,MAAM,cAAc,OAAQ,KAAM;CAClC,MAAM,MAAM,YAAY,MAAM;CAC9B,MAAM,MAAM,YAAY,MAAM;CAC9B,MAAM,MAAM,YAAY,MAAM;CAC9B,MAAM,MAAM,YAAY,MAAM;CAE9B,OAAO;EACN;EACA;EACA;EACA;EACA,QAAQ;EACR,QAAQ,IAAI;CACb;AACD,CACD;AAEA,SAAgB,mBACf,OACmB;CACnB,MAAM,EAAE,qBAAqB;CAC7B,MAAM,sBAAsB,aACzB,UAAmB;EACpB,iBAAkB,kCAAmC,KAAM,CAAE;CAC9D,GACA,CAAE,gBAAiB,CACpB;CACA,IAAK,cAAe,KAAM,GACzB,OAAO;EACN,OAAO,wBAAyB,MAAM,KAAM;EAC5C,aAAa,CAAE,MAAM;EACrB,UAAU;CACX;CAED,OAAO;EACN,GAAG;EACH,OAAO,MAAM;EACb,aAAe,MAA4B;EAC3C,UAAY,MAA4B;CACzC;AACD"}