{"version":3,"file":"use-deprecated-opacity.cjs","names":["useState","usePrevious"],"sources":["../../src/separator/use-deprecated-opacity.js"],"sourcesContent":["import { useEffect, useState } from '@wordpress/element';\nimport { usePrevious } from '@wordpress/compose';\n\nexport default function useDeprecatedOpacity(\n\topacity,\n\tcurrentColor,\n\tsetAttributes\n) {\n\tconst [ deprecatedOpacityWithNoColor, setDeprecatedOpacityWithNoColor ] =\n\t\tuseState( false );\n\tconst previousColor = usePrevious( currentColor );\n\n\t// A separator with no color set will always have previousColor set to undefined,\n\t// and we need to differentiate these from those with color set that will return\n\t// previousColor as undefined on the first render.\n\tuseEffect( () => {\n\t\tif ( opacity === 'css' && ! currentColor && ! previousColor ) {\n\t\t\tsetDeprecatedOpacityWithNoColor( true );\n\t\t}\n\t}, [ currentColor, previousColor, opacity ] );\n\n\t// For deprecated blocks, that have a default 0.4 css opacity set, we\n\t// need to remove this if the current color is changed, or a color is added.\n\t// In these instances the opacity attribute is set back to the default of\n\t// alpha-channel which allows a new custom opacity to be set via the color picker.\n\tuseEffect( () => {\n\t\tif (\n\t\t\topacity === 'css' &&\n\t\t\t( ( deprecatedOpacityWithNoColor && currentColor ) ||\n\t\t\t\t( previousColor && currentColor !== previousColor ) )\n\t\t) {\n\t\t\tsetAttributes( { opacity: 'alpha-channel' } );\n\t\t\tsetDeprecatedOpacityWithNoColor( false );\n\t\t}\n\t}, [ deprecatedOpacityWithNoColor, currentColor, previousColor ] );\n}\n"],"mappings":";;;;;;;;AAGA,SAAwB,qBACvB,SACA,cACA,eACC;CACD,MAAM,CAAE,8BAA8B,oCAAA,GACrCA,mBAAAA,SAAAA,CAAU,KAAM;CACjB,MAAM,iBAAA,GAAgBC,mBAAAA,YAAAA,CAAa,YAAa;CAKhD,CAAA,GAAA,mBAAA,UAAA,OAAiB;EAChB,IAAK,YAAY,SAAS,CAAE,gBAAgB,CAAE,eAC7C,gCAAiC,IAAK;CAExC,GAAG;EAAE;EAAc;EAAe;CAAQ,CAAE;CAM5C,CAAA,GAAA,mBAAA,UAAA,OAAiB;EAChB,IACC,YAAY,UACR,gCAAgC,gBACjC,iBAAiB,iBAAiB,gBACpC;GACD,cAAe,EAAE,SAAS,gBAAgB,CAAE;GAC5C,gCAAiC,KAAM;EACxC;CACD,GAAG;EAAE;EAA8B;EAAc;CAAc,CAAE;AAClE"}