{
  "version": 3,
  "sources": ["../../src/hook/use-anchor-ref.js"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { getActiveFormat } from '../get-active-format';\n\n/**\n * @template T\n * @typedef {import('@wordpress/element').RefObject<T>} RefObject<T>\n */\n/** @typedef {import('../register-format-type').WPFormat} WPFormat */\n/** @typedef {import('../types').RichTextValue} RichTextValue */\n\n/**\n * This hook, to be used in a format type's Edit component, returns the active\n * element that is formatted, or the selection range if no format is active.\n * The returned value is meant to be used for positioning UI, e.g. by passing it\n * to the `Popover` component.\n *\n * @param {Object}                 $1          Named parameters.\n * @param {RefObject<HTMLElement>} $1.ref      React ref of the element\n *                                             containing  the editable content.\n * @param {RichTextValue}          $1.value    Value to check for selection.\n * @param {WPFormat}               $1.settings The format type's settings.\n *\n * @return {Element|Range} The active element or selection range.\n */\nexport function useAnchorRef( { ref, value, settings = {} } ) {\n\tdeprecated( '`useAnchorRef` hook', {\n\t\tsince: '6.1',\n\t\talternative: '`useAnchor` hook',\n\t} );\n\n\tconst { tagName, className, name } = settings;\n\tconst activeFormat = name ? getActiveFormat( value, name ) : undefined;\n\n\treturn useMemo( () => {\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\t\tconst {\n\t\t\townerDocument: { defaultView },\n\t\t} = ref.current;\n\t\tconst selection = defaultView.getSelection();\n\n\t\tif ( ! selection.rangeCount ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst range = selection.getRangeAt( 0 );\n\n\t\tif ( ! activeFormat ) {\n\t\t\treturn range;\n\t\t}\n\n\t\tlet element = range.startContainer;\n\n\t\t// If the caret is right before the element, select the next element.\n\t\telement = element.nextElementSibling || element;\n\n\t\twhile ( element.nodeType !== element.ELEMENT_NODE ) {\n\t\t\telement = element.parentNode;\n\t\t}\n\n\t\treturn element.closest(\n\t\t\ttagName + ( className ? '.' + className : '' )\n\t\t);\n\t}, [ activeFormat, value.start, value.end, tagName, className ] );\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwB;AACxB,wBAAuB;AAKvB,+BAAgC;AAuBzB,SAAS,aAAc,EAAE,KAAK,OAAO,WAAW,CAAC,EAAE,GAAI;AAC7D,wBAAAA,SAAY,uBAAuB;AAAA,IAClC,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,QAAM,EAAE,SAAS,WAAW,KAAK,IAAI;AACrC,QAAM,eAAe,WAAO,0CAAiB,OAAO,IAAK,IAAI;AAE7D,aAAO,wBAAS,MAAM;AACrB,QAAK,CAAE,IAAI,SAAU;AACpB;AAAA,IACD;AACA,UAAM;AAAA,MACL,eAAe,EAAE,YAAY;AAAA,IAC9B,IAAI,IAAI;AACR,UAAM,YAAY,YAAY,aAAa;AAE3C,QAAK,CAAE,UAAU,YAAa;AAC7B;AAAA,IACD;AAEA,UAAM,QAAQ,UAAU,WAAY,CAAE;AAEtC,QAAK,CAAE,cAAe;AACrB,aAAO;AAAA,IACR;AAEA,QAAI,UAAU,MAAM;AAGpB,cAAU,QAAQ,sBAAsB;AAExC,WAAQ,QAAQ,aAAa,QAAQ,cAAe;AACnD,gBAAU,QAAQ;AAAA,IACnB;AAEA,WAAO,QAAQ;AAAA,MACd,WAAY,YAAY,MAAM,YAAY;AAAA,IAC3C;AAAA,EACD,GAAG,CAAE,cAAc,MAAM,OAAO,MAAM,KAAK,SAAS,SAAU,CAAE;AACjE;",
  "names": ["deprecated"]
}
