{"ast":null,"code":"'use client';\n\nimport React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react';\nimport makeCancellable from 'make-cancellable-promise';\nimport clsx from 'clsx';\nimport invariant from 'tiny-invariant';\nimport warning from 'warning';\nimport pdfjs from '../pdfjs.js';\nimport usePageContext from '../shared/hooks/usePageContext.js';\nimport useResolver from '../shared/hooks/useResolver.js';\nimport { cancelRunningTask } from '../shared/utils.js';\nfunction isTextItem(item) {\n  return 'str' in item;\n}\nexport default function TextLayer() {\n  const pageContext = usePageContext();\n  invariant(pageContext, 'Unable to find Page context.');\n  const {\n    customTextRenderer,\n    onGetTextError,\n    onGetTextSuccess,\n    onRenderTextLayerError,\n    onRenderTextLayerSuccess,\n    page,\n    pageIndex,\n    pageNumber,\n    rotate,\n    scale\n  } = pageContext;\n  invariant(page, 'Attempted to load page text content, but no page was specified.');\n  const [textContentState, textContentDispatch] = useResolver();\n  const {\n    value: textContent,\n    error: textContentError\n  } = textContentState;\n  const layerElement = useRef(null);\n  const endElement = useRef();\n  warning(parseInt(window.getComputedStyle(document.body).getPropertyValue('--react-pdf-text-layer'), 10) === 1, 'TextLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-text-layer');\n  /**\n   * Called when a page text content is read successfully\n   */\n  function onLoadSuccess() {\n    if (!textContent) {\n      // Impossible, but TypeScript doesn't know that\n      return;\n    }\n    if (onGetTextSuccess) {\n      onGetTextSuccess(textContent);\n    }\n  }\n  /**\n   * Called when a page text content failed to read successfully\n   */\n  function onLoadError() {\n    if (!textContentError) {\n      // Impossible, but TypeScript doesn't know that\n      return;\n    }\n    warning(false, textContentError.toString());\n    if (onGetTextError) {\n      onGetTextError(textContentError);\n    }\n  }\n  function resetTextContent() {\n    textContentDispatch({\n      type: 'RESET'\n    });\n  }\n  useEffect(resetTextContent, [page, textContentDispatch]);\n  function loadTextContent() {\n    if (!page) {\n      return;\n    }\n    const cancellable = makeCancellable(page.getTextContent());\n    const runningTask = cancellable;\n    cancellable.promise.then(nextTextContent => {\n      textContentDispatch({\n        type: 'RESOLVE',\n        value: nextTextContent\n      });\n    }).catch(error => {\n      textContentDispatch({\n        type: 'REJECT',\n        error\n      });\n    });\n    return () => cancelRunningTask(runningTask);\n  }\n  useEffect(loadTextContent, [page, textContentDispatch]);\n  useEffect(() => {\n    if (textContent === undefined) {\n      return;\n    }\n    if (textContent === false) {\n      onLoadError();\n      return;\n    }\n    onLoadSuccess();\n  },\n  // Ommitted callbacks so they are not called every time they change\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  [textContent]);\n  /**\n   * Called when a text layer is rendered successfully\n   */\n  const onRenderSuccess = useCallback(() => {\n    if (onRenderTextLayerSuccess) {\n      onRenderTextLayerSuccess();\n    }\n  }, [onRenderTextLayerSuccess]);\n  /**\n   * Called when a text layer failed to render successfully\n   */\n  const onRenderError = useCallback(error => {\n    warning(false, error.toString());\n    if (onRenderTextLayerError) {\n      onRenderTextLayerError(error);\n    }\n  }, [onRenderTextLayerError]);\n  function onMouseDown() {\n    const end = endElement.current;\n    if (!end) {\n      return;\n    }\n    end.classList.add('active');\n  }\n  function onMouseUp() {\n    const end = endElement.current;\n    if (!end) {\n      return;\n    }\n    end.classList.remove('active');\n  }\n  const viewport = useMemo(() => page.getViewport({\n    scale,\n    rotation: rotate\n  }), [page, rotate, scale]);\n  function renderTextLayer() {\n    if (!page || !textContent) {\n      return;\n    }\n    const {\n      current: layer\n    } = layerElement;\n    if (!layer) {\n      return;\n    }\n    layer.innerHTML = '';\n    const textContentSource = page.streamTextContent({\n      includeMarkedContent: true\n    });\n    const parameters = {\n      container: layer,\n      textContentSource,\n      viewport\n    };\n    const cancellable = pdfjs.renderTextLayer(parameters);\n    const runningTask = cancellable;\n    cancellable.promise.then(() => {\n      const end = document.createElement('div');\n      end.className = 'endOfContent';\n      layer.append(end);\n      endElement.current = end;\n      const layerChildren = layer.querySelectorAll('[role=\"presentation\"]');\n      if (customTextRenderer) {\n        let index = 0;\n        textContent.items.forEach((item, itemIndex) => {\n          if (!isTextItem(item)) {\n            return;\n          }\n          const child = layerChildren[index];\n          if (!child) {\n            return;\n          }\n          const content = customTextRenderer(Object.assign({\n            pageIndex,\n            pageNumber,\n            itemIndex\n          }, item));\n          child.innerHTML = content;\n          index += item.str && item.hasEOL ? 2 : 1;\n        });\n      }\n      // Intentional immediate callback\n      onRenderSuccess();\n    }).catch(onRenderError);\n    return () => cancelRunningTask(runningTask);\n  }\n  useLayoutEffect(renderTextLayer, [customTextRenderer, onRenderError, onRenderSuccess, page, pageIndex, pageNumber, textContent, viewport]);\n  return (\n    // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n    React.createElement(\"div\", {\n      className: clsx('react-pdf__Page__textContent', 'textLayer'),\n      onMouseUp: onMouseUp,\n      onMouseDown: onMouseDown,\n      ref: layerElement\n    })\n  );\n}","map":{"version":3,"names":["React","useCallback","useEffect","useLayoutEffect","useMemo","useRef","makeCancellable","clsx","invariant","warning","pdfjs","usePageContext","useResolver","cancelRunningTask","isTextItem","item","TextLayer","pageContext","customTextRenderer","onGetTextError","onGetTextSuccess","onRenderTextLayerError","onRenderTextLayerSuccess","page","pageIndex","pageNumber","rotate","scale","textContentState","textContentDispatch","value","textContent","error","textContentError","layerElement","endElement","parseInt","window","getComputedStyle","document","body","getPropertyValue","onLoadSuccess","onLoadError","toString","resetTextContent","type","loadTextContent","cancellable","getTextContent","runningTask","promise","then","nextTextContent","catch","undefined","onRenderSuccess","onRenderError","onMouseDown","end","current","classList","add","onMouseUp","remove","viewport","getViewport","rotation","renderTextLayer","layer","innerHTML","textContentSource","streamTextContent","includeMarkedContent","parameters","container","createElement","className","append","layerChildren","querySelectorAll","index","items","forEach","itemIndex","child","content","Object","assign","str","hasEOL","ref"],"sources":["/var/www/gavt/node_modules/react-pdf/dist/esm/Page/TextLayer.js"],"sourcesContent":["'use client';\nimport React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react';\nimport makeCancellable from 'make-cancellable-promise';\nimport clsx from 'clsx';\nimport invariant from 'tiny-invariant';\nimport warning from 'warning';\nimport pdfjs from '../pdfjs.js';\nimport usePageContext from '../shared/hooks/usePageContext.js';\nimport useResolver from '../shared/hooks/useResolver.js';\nimport { cancelRunningTask } from '../shared/utils.js';\nfunction isTextItem(item) {\n    return 'str' in item;\n}\nexport default function TextLayer() {\n    const pageContext = usePageContext();\n    invariant(pageContext, 'Unable to find Page context.');\n    const { customTextRenderer, onGetTextError, onGetTextSuccess, onRenderTextLayerError, onRenderTextLayerSuccess, page, pageIndex, pageNumber, rotate, scale, } = pageContext;\n    invariant(page, 'Attempted to load page text content, but no page was specified.');\n    const [textContentState, textContentDispatch] = useResolver();\n    const { value: textContent, error: textContentError } = textContentState;\n    const layerElement = useRef(null);\n    const endElement = useRef();\n    warning(parseInt(window.getComputedStyle(document.body).getPropertyValue('--react-pdf-text-layer'), 10) === 1, 'TextLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-text-layer');\n    /**\n     * Called when a page text content is read successfully\n     */\n    function onLoadSuccess() {\n        if (!textContent) {\n            // Impossible, but TypeScript doesn't know that\n            return;\n        }\n        if (onGetTextSuccess) {\n            onGetTextSuccess(textContent);\n        }\n    }\n    /**\n     * Called when a page text content failed to read successfully\n     */\n    function onLoadError() {\n        if (!textContentError) {\n            // Impossible, but TypeScript doesn't know that\n            return;\n        }\n        warning(false, textContentError.toString());\n        if (onGetTextError) {\n            onGetTextError(textContentError);\n        }\n    }\n    function resetTextContent() {\n        textContentDispatch({ type: 'RESET' });\n    }\n    useEffect(resetTextContent, [page, textContentDispatch]);\n    function loadTextContent() {\n        if (!page) {\n            return;\n        }\n        const cancellable = makeCancellable(page.getTextContent());\n        const runningTask = cancellable;\n        cancellable.promise\n            .then((nextTextContent) => {\n            textContentDispatch({ type: 'RESOLVE', value: nextTextContent });\n        })\n            .catch((error) => {\n            textContentDispatch({ type: 'REJECT', error });\n        });\n        return () => cancelRunningTask(runningTask);\n    }\n    useEffect(loadTextContent, [page, textContentDispatch]);\n    useEffect(() => {\n        if (textContent === undefined) {\n            return;\n        }\n        if (textContent === false) {\n            onLoadError();\n            return;\n        }\n        onLoadSuccess();\n    }, \n    // Ommitted callbacks so they are not called every time they change\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [textContent]);\n    /**\n     * Called when a text layer is rendered successfully\n     */\n    const onRenderSuccess = useCallback(() => {\n        if (onRenderTextLayerSuccess) {\n            onRenderTextLayerSuccess();\n        }\n    }, [onRenderTextLayerSuccess]);\n    /**\n     * Called when a text layer failed to render successfully\n     */\n    const onRenderError = useCallback((error) => {\n        warning(false, error.toString());\n        if (onRenderTextLayerError) {\n            onRenderTextLayerError(error);\n        }\n    }, [onRenderTextLayerError]);\n    function onMouseDown() {\n        const end = endElement.current;\n        if (!end) {\n            return;\n        }\n        end.classList.add('active');\n    }\n    function onMouseUp() {\n        const end = endElement.current;\n        if (!end) {\n            return;\n        }\n        end.classList.remove('active');\n    }\n    const viewport = useMemo(() => page.getViewport({ scale, rotation: rotate }), [page, rotate, scale]);\n    function renderTextLayer() {\n        if (!page || !textContent) {\n            return;\n        }\n        const { current: layer } = layerElement;\n        if (!layer) {\n            return;\n        }\n        layer.innerHTML = '';\n        const textContentSource = page.streamTextContent({ includeMarkedContent: true });\n        const parameters = {\n            container: layer,\n            textContentSource,\n            viewport,\n        };\n        const cancellable = pdfjs.renderTextLayer(parameters);\n        const runningTask = cancellable;\n        cancellable.promise\n            .then(() => {\n            const end = document.createElement('div');\n            end.className = 'endOfContent';\n            layer.append(end);\n            endElement.current = end;\n            const layerChildren = layer.querySelectorAll('[role=\"presentation\"]');\n            if (customTextRenderer) {\n                let index = 0;\n                textContent.items.forEach((item, itemIndex) => {\n                    if (!isTextItem(item)) {\n                        return;\n                    }\n                    const child = layerChildren[index];\n                    if (!child) {\n                        return;\n                    }\n                    const content = customTextRenderer(Object.assign({ pageIndex,\n                        pageNumber,\n                        itemIndex }, item));\n                    child.innerHTML = content;\n                    index += item.str && item.hasEOL ? 2 : 1;\n                });\n            }\n            // Intentional immediate callback\n            onRenderSuccess();\n        })\n            .catch(onRenderError);\n        return () => cancelRunningTask(runningTask);\n    }\n    useLayoutEffect(renderTextLayer, [\n        customTextRenderer,\n        onRenderError,\n        onRenderSuccess,\n        page,\n        pageIndex,\n        pageNumber,\n        textContent,\n        viewport,\n    ]);\n    return (\n    // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n    React.createElement(\"div\", { className: clsx('react-pdf__Page__textContent', 'textLayer'), onMouseUp: onMouseUp, onMouseDown: onMouseDown, ref: layerElement }));\n}\n"],"mappings":"AAAA,YAAY;;AACZ,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AACvF,OAAOC,eAAe,MAAM,0BAA0B;AACtD,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,SAAS,MAAM,gBAAgB;AACtC,OAAOC,OAAO,MAAM,SAAS;AAC7B,OAAOC,KAAK,MAAM,aAAa;AAC/B,OAAOC,cAAc,MAAM,mCAAmC;AAC9D,OAAOC,WAAW,MAAM,gCAAgC;AACxD,SAASC,iBAAiB,QAAQ,oBAAoB;AACtD,SAASC,UAAUA,CAACC,IAAI,EAAE;EACtB,OAAO,KAAK,IAAIA,IAAI;AACxB;AACA,eAAe,SAASC,SAASA,CAAA,EAAG;EAChC,MAAMC,WAAW,GAAGN,cAAc,CAAC,CAAC;EACpCH,SAAS,CAACS,WAAW,EAAE,8BAA8B,CAAC;EACtD,MAAM;IAAEC,kBAAkB;IAAEC,cAAc;IAAEC,gBAAgB;IAAEC,sBAAsB;IAAEC,wBAAwB;IAAEC,IAAI;IAAEC,SAAS;IAAEC,UAAU;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGV,WAAW;EAC3KT,SAAS,CAACe,IAAI,EAAE,iEAAiE,CAAC;EAClF,MAAM,CAACK,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGjB,WAAW,C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