{
  "version": 3,
  "sources": ["../../src/hook/use-boundary-style.js"],
  "sourcesContent": ["/**\n * External dependencies\n */\nimport { colord } from 'colord';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\n\n/*\n * Calculates and renders the format boundary style when the active formats\n * change.\n */\nexport function useBoundaryStyle( { record } ) {\n\tconst ref = useRef();\n\tconst { activeFormats = [], replacements, start } = record.current;\n\tconst activeReplacement = replacements[ start ];\n\tuseEffect( () => {\n\t\t// There's no need to recalculate the boundary styles if no formats are\n\t\t// active, because no boundary styles will be visible.\n\t\tif (\n\t\t\t( ! activeFormats || ! activeFormats.length ) &&\n\t\t\t! activeReplacement\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst boundarySelector = '*[data-rich-text-format-boundary]';\n\t\tconst element = ref.current.querySelector( boundarySelector );\n\n\t\tif ( ! element ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { ownerDocument } = element;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst computedStyle = defaultView.getComputedStyle( element );\n\t\tconst newColor = colord( computedStyle.color )\n\t\t\t.alpha( 0.2 )\n\t\t\t.toRgbString();\n\t\tconst selector = `.rich-text:focus ${ boundarySelector }`;\n\t\tconst rule = `background-color: ${ newColor }`;\n\t\tconst style = `${ selector } {${ rule }}`;\n\t\tconst globalStyleId = 'rich-text-boundary-style';\n\n\t\tlet globalStyle = ownerDocument.getElementById( globalStyleId );\n\n\t\tif ( ! globalStyle ) {\n\t\t\tglobalStyle = ownerDocument.createElement( 'style' );\n\t\t\tglobalStyle.id = globalStyleId;\n\t\t\townerDocument.head.appendChild( globalStyle );\n\t\t}\n\n\t\tif ( globalStyle.innerHTML !== style ) {\n\t\t\tglobalStyle.innerHTML = style;\n\t\t}\n\t}, [ activeFormats, activeReplacement ] );\n\treturn ref;\n}\n"],
  "mappings": ";AAGA,SAAS,cAAc;AAKvB,SAAS,WAAW,cAAc;AAM3B,SAAS,iBAAkB,EAAE,OAAO,GAAI;AAC9C,QAAM,MAAM,OAAO;AACnB,QAAM,EAAE,gBAAgB,CAAC,GAAG,cAAc,MAAM,IAAI,OAAO;AAC3D,QAAM,oBAAoB,aAAc,KAAM;AAC9C,YAAW,MAAM;AAGhB,SACG,CAAE,iBAAiB,CAAE,cAAc,WACrC,CAAE,mBACD;AACD;AAAA,IACD;AAEA,UAAM,mBAAmB;AACzB,UAAM,UAAU,IAAI,QAAQ,cAAe,gBAAiB;AAE5D,QAAK,CAAE,SAAU;AAChB;AAAA,IACD;AAEA,UAAM,EAAE,cAAc,IAAI;AAC1B,UAAM,EAAE,YAAY,IAAI;AACxB,UAAM,gBAAgB,YAAY,iBAAkB,OAAQ;AAC5D,UAAM,WAAW,OAAQ,cAAc,KAAM,EAC3C,MAAO,GAAI,EACX,YAAY;AACd,UAAM,WAAW,oBAAqB,gBAAiB;AACvD,UAAM,OAAO,qBAAsB,QAAS;AAC5C,UAAM,QAAQ,GAAI,QAAS,KAAM,IAAK;AACtC,UAAM,gBAAgB;AAEtB,QAAI,cAAc,cAAc,eAAgB,aAAc;AAE9D,QAAK,CAAE,aAAc;AACpB,oBAAc,cAAc,cAAe,OAAQ;AACnD,kBAAY,KAAK;AACjB,oBAAc,KAAK,YAAa,WAAY;AAAA,IAC7C;AAEA,QAAK,YAAY,cAAc,OAAQ;AACtC,kBAAY,YAAY;AAAA,IACzB;AAAA,EACD,GAAG,CAAE,eAAe,iBAAkB,CAAE;AACxC,SAAO;AACR;",
  "names": []
}
