@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
1 lines • 2.62 kB
Source Map (JSON)
{"version":3,"file":"preview-hooks.mjs","names":[],"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,WAAY,SAAoB,YAAa;CACjE,MAAM,CAAE,kBAAkB,WACzB,SAAoB,kBAAmB;CACxC,MAAM,CAAE,eAAe,aAAc,SACpC,wBACD;CACA,MAAM,CAAE,YAAY,gBAAiB,SACpC,0BACD;CACA,MAAM,CAAE,wBAAwB,aAAc,SAC7C,kCACD;CAEA,MAAM,CAAE,cAAe,WAAuB,oBAAqB,KAAK,CAAC;CACzE,MAAM,CAAE,eACP,WAAuB,qBAAsB,KAAK,CAAC;CACpD,MAAM,CAAE,gBACP,WAAuB,sBAAuB,KAAK,CAAC;CAErD,MAAM,gBAAgB,yBACnB,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"}