{
  "version": 3,
  "sources": ["../../src/text/utils.ts"],
  "sourcesContent": ["/**\n * External dependencies\n */\nimport memoize from 'memize';\nimport { findAll } from 'highlight-words-core';\n\n/**\n * WordPress dependencies\n */\nimport { createElement } from '@wordpress/element';\n\n/**\n * Source:\n * https://github.com/bvaughn/react-highlight-words/blob/HEAD/src/Highlighter.js\n */\n\n/**\n * @typedef Options\n * @property {string}                            [activeClassName='']      Classname for active highlighted areas.\n * @property {number}                            [activeIndex=-1]          The index of the active highlighted area.\n * @property {React.CSSProperties}               [activeStyle]             Styles to apply to the active highlighted area.\n * @property {boolean}                           [autoEscape]              Whether to automatically escape text.\n * @property {boolean}                           [caseSensitive=false]     Whether to highlight in a case-sensitive manner.\n * @property {string}                            children                  Children to highlight.\n * @property {FindAllArgs['findChunks']}         [findChunks]              Custom `findChunks` function to pass to `highlight-words-core`.\n * @property {string | Record<string, unknown>}  [highlightClassName='']   Classname to apply to highlighted text or a Record of classnames to apply to given text (which should be the key).\n * @property {React.CSSProperties}               [highlightStyle={}]       Styles to apply to highlighted text.\n * @property {keyof React.JSX.IntrinsicElements} [highlightTag='mark']     Tag to use for the highlighted text.\n * @property {FindAllArgs['sanitize']}           [sanitize]                Custom `sanitize` function to pass to `highlight-words-core`.\n * @property {string[]}                          [searchWords=[]]          Words to search for and highlight.\n * @property {string}                            [unhighlightClassName=''] Classname to apply to unhighlighted text.\n * @property {React.CSSProperties}               [unhighlightStyle]        Style to apply to unhighlighted text.\n */\n\n/**\n * Maps props to lowercase names.\n *\n * @param object Props to map.\n * @return The mapped props.\n */\nconst lowercaseProps = object => {\n  const mapped = {};\n  for (const key in object) {\n    mapped[key.toLowerCase()] = object[key];\n  }\n  return mapped;\n};\nconst memoizedLowercaseProps = memoize(lowercaseProps);\n\n/**\n * @param options\n * @param options.activeClassName\n * @param options.activeIndex\n * @param options.activeStyle\n * @param options.autoEscape\n * @param options.caseSensitive\n * @param options.children\n * @param options.findChunks\n * @param options.highlightClassName\n * @param options.highlightStyle\n * @param options.highlightTag\n * @param options.sanitize\n * @param options.searchWords\n * @param options.unhighlightClassName\n * @param options.unhighlightStyle\n */\nexport function createHighlighterText({\n  activeClassName = '',\n  activeIndex = -1,\n  activeStyle,\n  autoEscape,\n  caseSensitive = false,\n  children,\n  findChunks,\n  highlightClassName = '',\n  highlightStyle = {},\n  highlightTag = 'mark',\n  sanitize,\n  searchWords = [],\n  unhighlightClassName = '',\n  unhighlightStyle\n}) {\n  if (!children) {\n    return null;\n  }\n  if (typeof children !== 'string') {\n    return children;\n  }\n  const textToHighlight = children;\n  const chunks = findAll({\n    autoEscape,\n    caseSensitive,\n    findChunks,\n    sanitize,\n    searchWords,\n    textToHighlight\n  });\n  const HighlightTag = highlightTag;\n  let highlightIndex = -1;\n  let highlightClassNames = '';\n  let highlightStyles;\n  const textContent = chunks.map((chunk, index) => {\n    const text = textToHighlight.substr(chunk.start, chunk.end - chunk.start);\n    if (chunk.highlight) {\n      highlightIndex++;\n      let highlightClass;\n      if (typeof highlightClassName === 'object') {\n        if (!caseSensitive) {\n          highlightClassName = memoizedLowercaseProps(highlightClassName);\n          highlightClass = highlightClassName[text.toLowerCase()];\n        } else {\n          highlightClass = highlightClassName[text];\n        }\n      } else {\n        highlightClass = highlightClassName;\n      }\n      const isActive = highlightIndex === +activeIndex;\n      highlightClassNames = `${highlightClass} ${isActive ? activeClassName : ''}`;\n      highlightStyles = isActive === true && activeStyle !== null ? Object.assign({}, highlightStyle, activeStyle) : highlightStyle;\n      const props = {\n        children: text,\n        className: highlightClassNames,\n        key: index,\n        style: highlightStyles\n      };\n\n      // Don't attach arbitrary props to DOM elements; this triggers React DEV warnings (https://fb.me/react-unknown-prop)\n      // Only pass through the highlightIndex attribute for custom components.\n      if (typeof HighlightTag !== 'string') {\n        props.highlightIndex = highlightIndex;\n      }\n      return createElement(HighlightTag, props);\n    }\n    return createElement('span', {\n      children: text,\n      className: unhighlightClassName,\n      key: index,\n      style: unhighlightStyle\n    });\n  });\n  return textContent;\n}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