{"version":3,"file":"duotone-palette-panel.cjs","names":["useSetting","useMemo","useViewportMatch","Stack","PaletteEdit","__"],"sources":["../src/duotone-palette-panel.tsx"],"sourcesContent":["import { useViewportMatch } from '@wordpress/compose';\nimport { useMemo } from '@wordpress/element';\nimport { __experimentalPaletteEdit as PaletteEdit } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { Color, Duotone } from '@wordpress/global-styles-engine';\nimport { useSetting } from './hooks';\n\nconst mobilePopoverProps = { placement: 'bottom-start' as const, offset: 8 };\n\n// Presets come from `theme.json`, so they are not guaranteed to be arrays.\nconst asArray = < T, >( value: T[] | undefined ) =>\n\tArray.isArray( value ) ? value : [];\n\ninterface DuotonePalettePanelProps {\n\tname?: string;\n}\n\nexport default function DuotonePalettePanel( {\n\tname,\n}: DuotonePalettePanelProps ) {\n\tconst [ themeDuotone, setThemeDuotone ] = useSetting< Duotone[] >(\n\t\t'color.duotone.theme',\n\t\tname\n\t);\n\tconst [ baseThemeDuotone ] = useSetting< Duotone[] >(\n\t\t'color.duotone.theme',\n\t\tname,\n\t\t'base'\n\t);\n\tconst [ defaultDuotone, setDefaultDuotone ] = useSetting< Duotone[] >(\n\t\t'color.duotone.default',\n\t\tname\n\t);\n\tconst [ baseDefaultDuotone ] = useSetting< Duotone[] >(\n\t\t'color.duotone.default',\n\t\tname,\n\t\t'base'\n\t);\n\tconst [ customDuotone, setCustomDuotone ] = useSetting< Duotone[] >(\n\t\t'color.duotone.custom',\n\t\tname\n\t);\n\n\tconst [ defaultDuotoneEnabled ] = useSetting< boolean >(\n\t\t'color.defaultDuotone',\n\t\tname\n\t);\n\n\t// The colors offered when picking a duotone's shadows and highlights, and\n\t// from which the value of a newly added duotone is derived.\n\tconst [ themeColors ] = useSetting< Color[] >(\n\t\t'color.palette.theme',\n\t\tname\n\t);\n\tconst [ defaultColors ] = useSetting< Color[] >(\n\t\t'color.palette.default',\n\t\tname\n\t);\n\tconst [ customColors ] = useSetting< Color[] >(\n\t\t'color.palette.custom',\n\t\tname\n\t);\n\tconst [ defaultPaletteEnabled ] = useSetting< boolean >(\n\t\t'color.defaultPalette',\n\t\tname\n\t);\n\n\t// A stable array, so the filtering and darkest/lightest lookups that\n\t// `PaletteEdit` and `DuotonePicker` memoize on it are not redone on every\n\t// render.\n\tconst colorPalette = useMemo(\n\t\t() => [\n\t\t\t...asArray( customColors ),\n\t\t\t...asArray( themeColors ),\n\t\t\t...( defaultPaletteEnabled ? asArray( defaultColors ) : [] ),\n\t\t],\n\t\t[ customColors, themeColors, defaultColors, defaultPaletteEnabled ]\n\t);\n\n\tconst isMobileViewport = useViewportMatch( 'small', '<' );\n\tconst popoverProps = isMobileViewport ? mobilePopoverProps : undefined;\n\n\treturn (\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tclassName=\"global-styles-ui-duotone-palette-panel\"\n\t\t\tgap=\"2xl\"\n\t\t>\n\t\t\t{ !! asArray( themeDuotone ).length && (\n\t\t\t\t<PaletteEdit\n\t\t\t\t\tcanReset={ themeDuotone !== baseThemeDuotone }\n\t\t\t\t\tcanOnlyChangeValues\n\t\t\t\t\tduotones={ asArray( themeDuotone ) }\n\t\t\t\t\tcolorPalette={ colorPalette }\n\t\t\t\t\tonChange={ setThemeDuotone }\n\t\t\t\t\tpaletteLabel={ __( 'Theme' ) }\n\t\t\t\t\tpaletteLabelHeadingLevel={ 3 }\n\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! asArray( defaultDuotone ).length &&\n\t\t\t\t!! defaultDuotoneEnabled && (\n\t\t\t\t\t<PaletteEdit\n\t\t\t\t\t\tcanReset={ defaultDuotone !== baseDefaultDuotone }\n\t\t\t\t\t\tcanOnlyChangeValues\n\t\t\t\t\t\tduotones={ asArray( defaultDuotone ) }\n\t\t\t\t\t\tcolorPalette={ colorPalette }\n\t\t\t\t\t\tonChange={ setDefaultDuotone }\n\t\t\t\t\t\tpaletteLabel={ __( 'Default' ) }\n\t\t\t\t\t\tpaletteLabelHeadingLevel={ 3 }\n\t\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t<PaletteEdit\n\t\t\t\tduotones={ asArray( customDuotone ) }\n\t\t\t\tcolorPalette={ colorPalette }\n\t\t\t\tonChange={ setCustomDuotone }\n\t\t\t\tpaletteLabel={ __( 'Custom' ) }\n\t\t\t\tpaletteLabelHeadingLevel={ 3 }\n\t\t\t\tslugPrefix=\"custom-\"\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t/>\n\t\t</Stack>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,MAAM,qBAAqB;CAAE,WAAW;CAAyB,QAAQ;AAAE;AAG3E,MAAM,WAAkB,UACvB,MAAM,QAAS,KAAM,IAAI,QAAQ,CAAC;AAMnC,SAAwB,oBAAqB,EAC5C,QAC6B;CAC7B,MAAM,CAAE,cAAc,oBAAA,GAAoBA,WAAAA,WAAAA,CACzC,uBACA,IACD;CACA,MAAM,CAAE,qBAAA,GAAqBA,WAAAA,WAAAA,CAC5B,uBACA,MACA,MACD;CACA,MAAM,CAAE,gBAAgB,sBAAA,GAAsBA,WAAAA,WAAAA,CAC7C,yBACA,IACD;CACA,MAAM,CAAE,uBAAA,GAAuBA,WAAAA,WAAAA,CAC9B,yBACA,MACA,MACD;CACA,MAAM,CAAE,eAAe,qBAAA,GAAqBA,WAAAA,WAAAA,CAC3C,wBACA,IACD;CAEA,MAAM,CAAE,0BAAA,GAA0BA,WAAAA,WAAAA,CACjC,wBACA,IACD;CAIA,MAAM,CAAE,gBAAA,GAAgBA,WAAAA,WAAAA,CACvB,uBACA,IACD;CACA,MAAM,CAAE,kBAAA,GAAkBA,WAAAA,WAAAA,CACzB,yBACA,IACD;CACA,MAAM,CAAE,iBAAA,GAAiBA,WAAAA,WAAAA,CACxB,wBACA,IACD;CACA,MAAM,CAAE,0BAAA,GAA0BA,WAAA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