UNPKG

@wordpress/global-styles-ui

Version:
1 lines • 2.83 kB
{"version":3,"file":"preview-hooks.cjs","names":["useStyle","useSetting","prioritizePaletteColors"],"sources":["../src/preview-hooks.tsx"],"sourcesContent":["import type { Color } from '@wordpress/global-styles-engine';\nimport { useSetting, useStyle } from './hooks';\nimport { prioritizePaletteColors } from './palette-colors';\n\nexport function useStylesPreviewColors(): {\n\tpaletteColors: Color[];\n\thighlightedColors: Color[];\n} {\n\tconst [ textColor = 'black' ] = useStyle< string >( 'color.text' );\n\tconst [ backgroundColor = 'white' ] =\n\t\tuseStyle< string >( 'color.background' );\n\tconst [ headingColor = textColor ] = useStyle< string >(\n\t\t'elements.h1.color.text'\n\t);\n\tconst [ linkColor = headingColor ] = useStyle< string >(\n\t\t'elements.link.color.text'\n\t);\n\tconst [ buttonBackgroundColor = linkColor ] = useStyle< string >(\n\t\t'elements.button.color.background'\n\t);\n\n\tconst [ coreColors ] = useSetting< Color[] >( 'color.palette.core' ) || [];\n\tconst [ themeColors ] =\n\t\tuseSetting< Color[] >( 'color.palette.theme' ) || [];\n\tconst [ customColors ] =\n\t\tuseSetting< Color[] >( 'color.palette.custom' ) || [];\n\n\tconst paletteColors = prioritizePaletteColors(\n\t\t( themeColors ?? [] )\n\t\t\t.concat( customColors ?? [] )\n\t\t\t.concat( coreColors ?? [] ),\n\t\tbackgroundColor,\n\t\ttextColor\n\t);\n\n\tconst textColorObject = paletteColors.filter(\n\t\t( { color } ) => color === textColor\n\t);\n\tconst buttonBackgroundColorObject = paletteColors.filter(\n\t\t( { color } ) => color === buttonBackgroundColor\n\t);\n\n\tconst highlightedColors = textColorObject\n\t\t.concat( buttonBackgroundColorObject )\n\t\t.concat( paletteColors )\n\t\t.filter(\n\t\t\t// we exclude these background color because it is already visible in the preview.\n\t\t\t( { color } ) => color !== backgroundColor\n\t\t)\n\t\t.slice( 0, 2 );\n\n\treturn {\n\t\tpaletteColors,\n\t\thighlightedColors,\n\t};\n}\n"],"mappings":";;;;;;;;AAIA,SAAgB,yBAGd;CACD,MAAM,CAAE,YAAY,YAAA,GAAYA,WAAAA,SAAAA,CAAoB,YAAa;CACjE,MAAM,CAAE,kBAAkB,YAAA,GACzBA,WAAAA,SAAAA,CAAoB,kBAAmB;CACxC,MAAM,CAAE,eAAe,cAAA,GAAcA,WAAAA,SAAAA,CACpC,wBACD;CACA,MAAM,CAAE,YAAY,iBAAA,GAAiBA,WAAAA,SAAAA,CACpC,0BACD;CACA,MAAM,CAAE,wBAAwB,cAAA,GAAcA,WAAAA,SAAAA,CAC7C,kCACD;CAEA,MAAM,CAAE,eAAA,GAAeC,WAAAA,WAAAA,CAAuB,oBAAqB,KAAK,CAAC;CACzE,MAAM,CAAE,gBAAA,GACPA,WAAAA,WAAAA,CAAuB,qBAAsB,KAAK,CAAC;CACpD,MAAM,CAAE,iBAAA,GACPA,WAAAA,WAAAA,CAAuB,sBAAuB,KAAK,CAAC;CAErD,MAAM,iBAAA,GAAgBC,oBAAAA,wBAAAA,EACnB,eAAe,CAAC,EAAA,CAChB,OAAQ,gBAAgB,CAAC,CAAE,CAAC,CAC5B,OAAQ,cAAc,CAAC,CAAE,GAC3B,iBACA,SACD;CAEA,MAAM,kBAAkB,cAAc,QACnC,EAAE,YAAa,UAAU,SAC5B;CACA,MAAM,8BAA8B,cAAc,QAC/C,EAAE,YAAa,UAAU,qBAC5B;CAWA,OAAO;EACN;EACA,mBAXyB,gBACxB,OAAQ,2BAA4B,CAAC,CACrC,OAAQ,aAAc,CAAC,CACvB,QAEE,EAAE,YAAa,UAAU,eAC5B,CAAC,CACA,MAAO,GAAG,CAIK;CACjB;AACD"}