@e-llm-studio/citation 0.0.252 → 0.0.254
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/features/ChatDrawer/ChatDrawer.js +1 -1
- package/dist/cjs/features/ChatDrawer/ChatDrawer.js.map +1 -1
- package/dist/cjs/features/IngestionStatus/IngestionStatusComponent.js +1 -1
- package/dist/cjs/features/IngestionStatus/IngestionStatusComponent.js.map +1 -1
- package/dist/cjs/features/IngestionStatus/useIngestionStatus.js +1 -1
- package/dist/cjs/features/IngestionStatus/useIngestionStatus.js.map +1 -1
- package/dist/cjs/features/PdfViewer/PdfContainer.js +1 -1
- package/dist/cjs/features/PdfViewer/PdfContainer.js.map +1 -1
- package/dist/cjs/features/PdfViewer/PdfViewer.js +1 -1
- package/dist/cjs/features/PdfViewer/PdfViewer.js.map +1 -1
- package/dist/cjs/features/PdfViewer/usePdfHighlight.js +1 -1
- package/dist/cjs/features/PdfViewer/usePdfHighlight.js.map +1 -1
- package/dist/cjs/features/SegmentReviewComponents/ApprovalDescriptionBanner.js +2 -0
- package/dist/cjs/features/SegmentReviewComponents/ApprovalDescriptionBanner.js.map +1 -0
- package/dist/cjs/features/SegmentReviewComponents/CognitiveIntegrity.js +1 -1
- package/dist/cjs/features/SegmentReviewComponents/CognitiveIntegrity.js.map +1 -1
- package/dist/cjs/features/SegmentReviewComponents/RevertCard.js +1 -1
- package/dist/cjs/features/SegmentReviewComponents/RevertCard.js.map +1 -1
- package/dist/cjs/features/SegmentReviewComponents/SaveAsLearningCard.js +2 -0
- package/dist/cjs/features/SegmentReviewComponents/SaveAsLearningCard.js.map +1 -0
- package/dist/cjs/features/SegmentReviewComponents/SegmentReviewPdfWrapper.js +1 -1
- package/dist/cjs/features/SegmentReviewComponents/SegmentReviewPdfWrapper.js.map +1 -1
- package/dist/cjs/hooks/useOnDemandCitationFetch.js +1 -1
- package/dist/cjs/hooks/useOnDemandCitationFetch.js.map +1 -1
- package/dist/cjs/service/onDemandApi.js +1 -1
- package/dist/cjs/service/onDemandApi.js.map +1 -1
- package/dist/features/ChatDrawer/ChatDrawer.js +1 -1
- package/dist/features/ChatDrawer/ChatDrawer.js.map +1 -1
- package/dist/features/IngestionStatus/IngestionStatusComponent.js +1 -1
- package/dist/features/IngestionStatus/IngestionStatusComponent.js.map +1 -1
- package/dist/features/IngestionStatus/useIngestionStatus.js +1 -1
- package/dist/features/IngestionStatus/useIngestionStatus.js.map +1 -1
- package/dist/features/PdfViewer/PdfContainer.js +1 -1
- package/dist/features/PdfViewer/PdfContainer.js.map +1 -1
- package/dist/features/PdfViewer/PdfViewer.js +1 -1
- package/dist/features/PdfViewer/PdfViewer.js.map +1 -1
- package/dist/features/PdfViewer/usePdfHighlight.js +1 -1
- package/dist/features/PdfViewer/usePdfHighlight.js.map +1 -1
- package/dist/features/SegmentReviewComponents/ApprovalDescriptionBanner.js +2 -0
- package/dist/features/SegmentReviewComponents/ApprovalDescriptionBanner.js.map +1 -0
- package/dist/features/SegmentReviewComponents/CognitiveIntegrity.js +1 -1
- package/dist/features/SegmentReviewComponents/CognitiveIntegrity.js.map +1 -1
- package/dist/features/SegmentReviewComponents/RevertCard.js +1 -1
- package/dist/features/SegmentReviewComponents/RevertCard.js.map +1 -1
- package/dist/features/SegmentReviewComponents/SaveAsLearningCard.js +2 -0
- package/dist/features/SegmentReviewComponents/SaveAsLearningCard.js.map +1 -0
- package/dist/features/SegmentReviewComponents/SegmentReviewPdfWrapper.js +1 -1
- package/dist/features/SegmentReviewComponents/SegmentReviewPdfWrapper.js.map +1 -1
- package/dist/hooks/useOnDemandCitationFetch.js +1 -1
- package/dist/hooks/useOnDemandCitationFetch.js.map +1 -1
- package/dist/service/onDemandApi.js +1 -1
- package/dist/service/onDemandApi.js.map +1 -1
- package/dist/types/features/ChatDrawer/ChatDrawer.d.ts.map +1 -1
- package/dist/types/features/IngestionStatus/IngestionStatusComponent.d.ts +1 -0
- package/dist/types/features/IngestionStatus/IngestionStatusComponent.d.ts.map +1 -1
- package/dist/types/features/IngestionStatus/useIngestionStatus.d.ts +1 -1
- package/dist/types/features/IngestionStatus/useIngestionStatus.d.ts.map +1 -1
- package/dist/types/features/PdfViewer/PdfContainer.d.ts +3 -2
- package/dist/types/features/PdfViewer/PdfContainer.d.ts.map +1 -1
- package/dist/types/features/PdfViewer/PdfViewer.d.ts +3 -2
- package/dist/types/features/PdfViewer/PdfViewer.d.ts.map +1 -1
- package/dist/types/features/PdfViewer/usePdfHighlight.d.ts +1 -0
- package/dist/types/features/PdfViewer/usePdfHighlight.d.ts.map +1 -1
- package/dist/types/features/SegmentReviewComponents/ApprovalDescriptionBanner.d.ts +11 -0
- package/dist/types/features/SegmentReviewComponents/ApprovalDescriptionBanner.d.ts.map +1 -0
- package/dist/types/features/SegmentReviewComponents/CognitiveIntegrity.d.ts +6 -1
- package/dist/types/features/SegmentReviewComponents/CognitiveIntegrity.d.ts.map +1 -1
- package/dist/types/features/SegmentReviewComponents/RevertCard.d.ts +9 -1
- package/dist/types/features/SegmentReviewComponents/RevertCard.d.ts.map +1 -1
- package/dist/types/features/SegmentReviewComponents/SaveAsLearningCard.d.ts +16 -0
- package/dist/types/features/SegmentReviewComponents/SaveAsLearningCard.d.ts.map +1 -0
- package/dist/types/features/SegmentReviewComponents/SegmentReviewPdfWrapper.d.ts +19 -1
- package/dist/types/features/SegmentReviewComponents/SegmentReviewPdfWrapper.d.ts.map +1 -1
- package/dist/types/hooks/useOnDemandCitationFetch.d.ts.map +1 -1
- package/dist/types/service/onDemandApi.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PdfViewer.js","sources":["../../../src/features/PdfViewer/PdfViewer.tsx"],"sourcesContent":["import { DocumentLoadEvent, PageChangeEvent, RenderPage, SetRenderRange, SpecialZoomLevel } from \"@react-pdf-viewer/core\";\nimport PdfContainer from \"./PdfContainer\";\nimport PdfToolbar from \"./PdfToolbar\";\nimport { pdfStyles } from \"./PdfStyle\";\nimport { PdfHighlightControls } from \"./usePdfHighlight\";\nimport { rotationManager } from \"./rotationManager\";\nimport \"@react-pdf-viewer/zoom/lib/styles/index.css\";\nimport \"@react-pdf-viewer/page-navigation/lib/styles/index.css\";\nimport \"@react-pdf-viewer/core/lib/styles/index.css\";\nimport \"@react-pdf-viewer/search/lib/styles/index.css\";\nimport React, { useMemo, useRef, useEffect, useState } from \"react\";\nimport ScannedDocCitation, { CitationPage } from \"../ScannedDocCitation/ScannedDocCitation\";\nimport \"./PdfViewer.css\";\n\nexport type CustomIconsType = {\n pdfIcon?: React.ReactNode;\n fullScreenIcon?: React.ReactNode;\n downloadIcon?: React.ReactNode;\n closeIcon?: React.ReactNode;\n};\n\nexport type CustomStylesType = {\n pdfViewer?: React.CSSProperties;\n header?: React.CSSProperties;\n pdfIconWrapper?: React.CSSProperties;\n pdfName?: React.CSSProperties;\n pdfContainer?: React.CSSProperties;\n emptyState?: React.CSSProperties;\n};\n\nexport type CustomClassesType = {\n header?: string;\n pdfName?: string;\n actionButton?: string;\n pdfViewerWrapper?: string;\n};\n\nexport type PdfSegment = {\n title: string;\n start_page: number;\n end_page: number;\n page_count: number;\n};\n\ntype PdfScaleOption =\n | \"ActualSize\"\n | \"PageFit\"\n | \"PageWidth\"\n | number;\nexport interface PdfNavigationRequest {\n pageNumber: number;\n /** Change this value to navigate to the same page more than once. */\n requestId?: string | number;\n}\n\nexport interface PdfNavigationSettledEvent extends PdfNavigationRequest {\n pageNumber: number;\n}\n\nexport interface PdfViewerProps {\n pdfUrl?: string;\n highlightText: string[];\n highlightPages?: any;\n highlightCordinatePages: HighlightArea[];\n highlightColor?: string;\n activeHighlightColor?: string;\n jumpToPageValue?: number;\n pdfName?: string;\n onClose?: () => void;\n item?: any;\n customStyles?: CustomStylesType;\n customClasses?: CustomClassesType;\n customIcons?: CustomIconsType;\n useCoordinates: boolean;\n fallbackPages?: CitationPage[];\n activeCitationIndex?: number;\n onActiveCitationChange?: (index: number) => void;\n headerAction?: {\n icon?: React.ReactNode;\n onClick?: () => void;\n tooltip?: string;\n };\n isZoomEnabled?: boolean;\n showHighlightsAction?: boolean;\n defaultScale?: PdfScaleOption;\n useRange?: boolean; //\n rangeOfPages?: number[] | null;\n showFullScreenAction?: boolean;\n showRotateButton?: boolean;\n segments?: PdfSegment[];\n segmentTooltipText?: string;\n onCurrentPageChange?: (pageNumber: number) => void;\n navigationRequest?: PdfNavigationRequest | null;\n onNavigationSettled?: (event: PdfNavigationSettledEvent) => void;\n disablePdfAnnotations?: boolean;\n disablePdfTextLayer?: boolean;\n renderPage?: RenderPage;\n setRenderRange?: SetRenderRange;\n}\n\nconst getResolvedScale = (\n scale?: PdfScaleOption\n): SpecialZoomLevel | number => {\n switch (scale) {\n case \"ActualSize\":\n return SpecialZoomLevel.ActualSize;\n\n case \"PageFit\":\n return SpecialZoomLevel.PageFit;\n\n case \"PageWidth\":\n return SpecialZoomLevel.PageWidth;\n\n default:\n return scale ?? SpecialZoomLevel.PageWidth;\n }\n};\n\nexport type HighlightArea = {\n pageIndex: number;\n left: number;\n top: number;\n width: number;\n height: number;\n pageNumber?: number;\n};\n\nconst PdfViewer = ({\n pdfUrl,\n highlightText,\n highlightPages,\n highlightCordinatePages,\n highlightColor = \"yellow\",\n activeHighlightColor = \"#f7dc51\",\n jumpToPageValue = 0,\n pdfName,\n onClose,\n customStyles,\n customClasses,\n customIcons,\n useCoordinates,\n fallbackPages,\n activeCitationIndex,\n onActiveCitationChange,\n headerAction,\n isZoomEnabled = true,\n showHighlightsAction = true,\n defaultScale = SpecialZoomLevel.ActualSize,\n useRange = false,\n rangeOfPages = null,\n showFullScreenAction=true,\n showRotateButton = false,\n segments = [\n {\n title: \"Document 2\",\n start_page: 52,\n end_page: 52,\n page_count: 1,\n },\n ],\n segmentTooltipText,\n onCurrentPageChange,\n navigationRequest,\n onNavigationSettled,\n disablePdfAnnotations = false,\n disablePdfTextLayer = false,\n renderPage,\n setRenderRange,\n}: PdfViewerProps) => {\n\n const viewerRef = useRef<HTMLDivElement | null>(null);\n const resolvedDefaultScale = getResolvedScale(defaultScale);\n const [currentPage, setCurrentPage] = useState(0);\n const [totalPages, setTotalPages] = useState(0);\n const [currentPageRotation, setCurrentPageRotation] = useState(0);\n const lastNavigationRequestRef = useRef<string | null>(null);\n const navigationSettleTimerRef = useRef<number | null>(null);\n const navigationSettleSequenceRef = useRef(0);\n const mutationObserverRef = useRef<MutationObserver | null>(null);\n\n // Generate PDF identifier for localStorage from URL\n const pdfIdentifier = useMemo(() => {\n if (!pdfUrl) return '';\n // Use last part of URL or hash it\n try {\n const url = new URL(pdfUrl, window.location.origin);\n return url.pathname.split('/').pop() || 'default';\n } catch {\n return 'default';\n }\n }, [pdfUrl]);\n\n // Set up rotation manager with PDF identifier\n useEffect(() => {\n if (pdfIdentifier) {\n rotationManager.setPdfIdentifier(pdfIdentifier);\n }\n }, [pdfIdentifier]);\n\n // Handler for rotating current page (no state update)\n const handleRotatePage = () => {\n const pageNumber = currentPage + 1;\n rotationManager.rotatePageBy90(pageNumber);\n // Manually update state to reflect rotation in UI\n setCurrentPageRotation(rotationManager.getRotation(pageNumber));\n };\n\n // Subscribe to rotation changes to sync UI state\n useEffect(() => {\n const unsubscribe = rotationManager.onRotationChange((pageNum, angle) => {\n // Only update state if current page rotated\n if (pageNum === currentPage + 1) {\n setCurrentPageRotation(angle);\n }\n });\n\n return unsubscribe;\n }, [currentPage]);\n\n // Register page elements with rotation manager\n useEffect(() => {\n const observer = new MutationObserver(() => {\n // Find all newly rendered page elements\n const pageElements = viewerRef.current?.querySelectorAll(\n '[data-testid^=\"core__page-layer-\"]'\n );\n\n const registeredPages = new Set<number>();\n\n pageElements?.forEach((pageElement) => {\n const match = (pageElement as HTMLElement)\n .getAttribute('data-testid')\n ?.match(/core__page-layer-(\\d+)/);\n if (match && match.length >= 2) {\n const pageIndex = parseInt(match[1], 10);\n const pageNumber = pageIndex + 1;\n\n // Only register once per page\n if (!registeredPages.has(pageNumber)) {\n rotationManager.registerPageElement(pageNumber, pageElement as HTMLElement);\n registeredPages.add(pageNumber);\n }\n }\n });\n });\n\n if (viewerRef.current) {\n observer.observe(viewerRef.current, {\n childList: true,\n subtree: true,\n attributes: false,\n });\n mutationObserverRef.current = observer;\n }\n\n return () => {\n observer.disconnect();\n mutationObserverRef.current = null;\n };\n }, []);\n\n // Clean up when unmounting\n useEffect(() => {\n return () => {\n rotationManager.clearAll();\n if (mutationObserverRef.current) {\n mutationObserverRef.current.disconnect();\n }\n };\n }, []);\n\n // Update current page rotation when page changes\n useEffect(() => {\n const pageNumber = currentPage + 1;\n setCurrentPageRotation(rotationManager.getRotation(pageNumber));\n }, [currentPage]);\n const resolvedRenderPage = useMemo<RenderPage | undefined>(() => {\n if (!disablePdfAnnotations && !disablePdfTextLayer) return renderPage;\n\n return (props) => {\n const resolvedTextLayerChildren = disablePdfTextLayer ? (\n <div aria-hidden=\"true\" style={{ display: \"none\" }}>\n {props.textLayer.children}\n </div>\n ) : props.textLayer.children;\n const resolvedProps = {\n ...props,\n annotationLayer: {\n ...props.annotationLayer,\n children: disablePdfAnnotations ? null : props.annotationLayer.children,\n },\n textLayer: {\n ...props.textLayer,\n children: resolvedTextLayerChildren,\n },\n };\n\n const renderedPage = renderPage\n ? renderPage(resolvedProps)\n : (\n <>\n {props.canvasLayer.children}\n {resolvedTextLayerChildren}\n {!disablePdfAnnotations && props.annotationLayer.children}\n </>\n );\n\n return renderedPage;\n };\n }, [disablePdfAnnotations, disablePdfTextLayer, renderPage]);\n\n const cleanHighlightTexts = (texts: string[]): string[] => {\n if (!texts || texts.length === 0) return texts;\n return texts.filter((text) => {\n return !texts.some(\n (otherText) => otherText !== text && otherText.includes(text)\n );\n });\n };\n\n const highlightPageSet = useMemo(() => {\n if (useCoordinates) {\n return new Set(highlightCordinatePages.map((h: any) => h.pageIndex));\n } else {\n const set = new Set<number>();\n Object.values(highlightPages).forEach((p: any) => {\n if (p > 0) set.add(p - 1);\n });\n return set;\n }\n }, [highlightCordinatePages, highlightPages, useCoordinates]);\n\n const removeRedundantHighlightTexts = cleanHighlightTexts(highlightText);\n\n const {\n highlightIndex,\n setHighlightIndex,\n cursorIndex,\n setCursorIndex,\n orderedKeys,\n totalHighlights,\n getValidPosition,\n tryJump,\n jumpToPage,\n zoomTo,\n plugins,\n controls,\n hideNonTargetHighlights,\n deduplicateHighlights,\n scrollToCoord,\n } = PdfHighlightControls(\n removeRedundantHighlightTexts,\n !useCoordinates ? highlightPages : {},\n viewerRef,\n highlightPageSet,\n useCoordinates,\n useCoordinates ? highlightCordinatePages : [],\n highlightColor,\n activeHighlightColor\n );\n\n const currentPosition = getValidPosition(cursorIndex);\n const currentSegment = useMemo(() => {\n const pageNumber = currentPage + 1;\n return segments.find(\n (segment) =>\n pageNumber >= segment.start_page && pageNumber <= segment.end_page\n );\n }, [currentPage, segments]);\n\n // sync external activeCitationIndex → cursorIndex\n useEffect(() => {\n if (activeCitationIndex === undefined) return;\n if (activeCitationIndex === cursorIndex) return;\n setCursorIndex(activeCitationIndex);\n }, [activeCitationIndex]);\n\n // wrap controls to fire onActiveCitationChange\n const handleGoToNext = () => {\n if (cursorIndex >= totalHighlights - 1) return;\n controls.goToNext();\n if (onActiveCitationChange) onActiveCitationChange(cursorIndex + 1);\n };\n\n const handleGoToPrevious = () => {\n if (cursorIndex <= 0) return;\n controls.goToPrevious();\n if (onActiveCitationChange) onActiveCitationChange(cursorIndex - 1);\n };\n\n const modifiedControls = {\n ...controls,\n goToNext: handleGoToNext,\n goToPrevious: handleGoToPrevious,\n };\n\n const handlePageNavigate = (pageNumber: number) => {\n const nextPage = Math.min(Math.max(pageNumber, 1), totalPages || pageNumber);\n setCurrentPage(nextPage - 1);\n jumpToPage(nextPage - 1);\n };\n\n const waitForNavigationToSettle = React.useCallback((\n request: PdfNavigationRequest,\n pageNumber: number\n ) => {\n navigationSettleSequenceRef.current += 1;\n const settleSequence = navigationSettleSequenceRef.current;\n if (navigationSettleTimerRef.current != null) {\n window.clearTimeout(navigationSettleTimerRef.current);\n }\n\n let previousScrollTop: number | null = null;\n let stableChecks = 0;\n let attempts = 0;\n\n const checkScrollPosition = () => {\n if (navigationSettleSequenceRef.current !== settleSequence) return;\n\n attempts += 1;\n\n const scrollContainer = viewerRef.current?.querySelector(\n '.rpv-core__inner-pages'\n ) as HTMLElement | null;\n const targetPage = viewerRef.current?.querySelector(\n `[data-testid=\"core__page-layer-${pageNumber - 1}\"]`\n ) as HTMLElement | null;\n\n // Virtualized page layers are not guaranteed to be mounted on the first\n // check after jumpToPage. Keep polling so navigation completion is not\n // lost while React PDF Viewer is creating the target page DOM.\n if (!scrollContainer || !targetPage) {\n if (attempts >= 40) {\n navigationSettleTimerRef.current = null;\n onNavigationSettled?.({\n pageNumber,\n requestId: request.requestId,\n });\n return;\n }\n\n navigationSettleTimerRef.current = window.setTimeout(checkScrollPosition, 50);\n return;\n }\n\n if (previousScrollTop === scrollContainer.scrollTop) {\n stableChecks += 1;\n } else {\n previousScrollTop = scrollContainer.scrollTop;\n stableChecks = 0;\n }\n\n const scrollRect = scrollContainer.getBoundingClientRect();\n const pageRect = targetPage.getBoundingClientRect();\n const isTargetVisible = Boolean(\n scrollRect &&\n pageRect &&\n pageRect.bottom > scrollRect.top &&\n pageRect.top < scrollRect.bottom\n );\n const hasSettled = stableChecks >= 2 && isTargetVisible;\n const reachedTimeout = attempts >= 40;\n\n if (hasSettled || reachedTimeout) {\n navigationSettleTimerRef.current = null;\n onNavigationSettled?.({\n pageNumber,\n requestId: request.requestId,\n });\n return;\n }\n\n navigationSettleTimerRef.current = window.setTimeout(checkScrollPosition, 50);\n };\n\n navigationSettleTimerRef.current = window.setTimeout(checkScrollPosition, 50);\n }, [onNavigationSettled]);\n\n useEffect(() => () => {\n navigationSettleSequenceRef.current += 1;\n if (navigationSettleTimerRef.current != null) {\n window.clearTimeout(navigationSettleTimerRef.current);\n }\n }, []);\n\n useEffect(() => {\n if (!navigationRequest || totalPages <= 0) return;\n\n const nextPage = Math.min(\n Math.max(Math.trunc(navigationRequest.pageNumber), 1),\n totalPages\n );\n const requestKey = `${navigationRequest.requestId ?? nextPage}:${nextPage}`;\n if (lastNavigationRequestRef.current === requestKey) return;\n\n lastNavigationRequestRef.current = requestKey;\n setCurrentPage(nextPage - 1);\n jumpToPage(nextPage - 1);\n waitForNavigationToSettle(navigationRequest, nextPage);\n }, [jumpToPage, navigationRequest, totalPages, waitForNavigationToSettle]);\n\n if (!pdfUrl) {\n return (\n <ScannedDocCitation\n pages={fallbackPages}\n activeCitationIndex={activeCitationIndex}\n onActiveCitationChange={onActiveCitationChange}\n headerAction={headerAction}\n />\n );\n }\n\n const defaultViewerStyles: React.CSSProperties = {\n display: \"flex\",\n flexDirection: \"column\",\n height: \"100%\",\n width: \"100%\",\n backgroundColor: \"#FAFAFA\",\n };\n\n const scrollToHighlight = () => {\n if (!viewerRef.current) return;\n\n const index = jumpToPageValue - 1;\n const key = orderedKeys[index];\n const page = highlightPages[key];\n const targetPage = page > 0 ? page - 1 : 0;\n\n const pageVisitMap: Record<number, number[]> = {};\n orderedKeys.forEach((k, i) => {\n const p = highlightPages[k];\n if (p > 0) {\n if (!pageVisitMap[p]) pageVisitMap[p] = [];\n pageVisitMap[p].push(i);\n }\n });\n const visits = pageVisitMap[page] || [];\n const occurrence = visits.indexOf(index);\n\n let attempts = 0;\n const maxAttempts = 40;\n\n const doScrollToHighlight = () => {\n attempts++;\n if (attempts > maxAttempts) return;\n\n const scrollContainer = viewerRef.current?.querySelector(\n \".rpv-core__inner-pages\"\n ) as HTMLElement;\n if (!scrollContainer) {\n setTimeout(doScrollToHighlight, 100);\n return;\n }\n\n const pageElement = viewerRef.current?.querySelector(\n `[data-testid=\"core__page-layer-${targetPage}\"]`\n );\n if (!pageElement) {\n setTimeout(doScrollToHighlight, 100);\n return;\n }\n\n const scrollContainerRect = scrollContainer.getBoundingClientRect();\n const pageRect = pageElement.getBoundingClientRect();\n const isPageVisible =\n pageRect.top < scrollContainerRect.bottom &&\n pageRect.bottom > scrollContainerRect.top;\n\n if (!isPageVisible) {\n setTimeout(doScrollToHighlight, 100);\n return;\n }\n\n const allHighlights = pageElement.querySelectorAll(\".rpv-search__highlight\");\n const target = allHighlights[occurrence] as HTMLElement;\n\n if (!target) {\n setTimeout(doScrollToHighlight, 100);\n return;\n }\n\n const highlightRect = target.getBoundingClientRect();\n const scrollTop =\n scrollContainer.scrollTop +\n (highlightRect.top - scrollContainerRect.top) -\n scrollContainer.clientHeight / 2 +\n highlightRect.height / 2;\n\n scrollContainer.scrollTo({ top: scrollTop, behavior: \"smooth\" });\n };\n\n setTimeout(doScrollToHighlight, 500);\n };\n\n return (\n <div\n ref={viewerRef}\n className={[\"citation-pdf-viewer\", customClasses?.pdfViewerWrapper]\n .filter(Boolean)\n .join(\" \")}\n data-disable-pdf-annotations={\n disablePdfAnnotations ? \"true\" : undefined\n }\n data-pdf-page-fit={\n resolvedDefaultScale === SpecialZoomLevel.PageFit ? \"true\" : undefined\n }\n style={{\n height: \"100%\",\n minHeight: 0,\n minWidth: 0,\n overflow: \"hidden\",\n display: \"flex\",\n flexDirection: \"column\",\n ...pdfStyles.pdfViewer,\n ...defaultViewerStyles,\n ...customStyles?.pdfViewer,\n backgroundColor: \"#F1F5F9\",\n }}\n >\n <PdfToolbar\n highlightIndex={highlightIndex}\n totalHighlights={totalHighlights}\n controls={modifiedControls}\n currentPosition={currentPosition}\n pdfName={pdfName}\n onClose={onClose}\n pdfUrl={pdfUrl}\n viewerRef={viewerRef}\n customStyles={customStyles}\n customClasses={customClasses}\n customIcons={customIcons}\n headerAction={headerAction}\n isZoomEnabled={isZoomEnabled}\n showHighlightsAction={showHighlightsAction}\n showFullScreenAction={showFullScreenAction} \n currentSegment={currentSegment}\n segmentTooltipText={segmentTooltipText}\n currentPage={currentPage + 1}\n totalPages={totalPages}\n onPageNavigate={handlePageNavigate}\n onRotatePage={handleRotatePage}\n currentPageRotation={currentPageRotation}\n showRotateButton={showRotateButton}\n />\n <PdfContainer\n defaultScale={resolvedDefaultScale}\n pdfUrl={pdfUrl}\n plugins={plugins}\n customStyles={customStyles}\n onLoad={(e: DocumentLoadEvent) => {\n setTotalPages(e.doc.numPages);\n\n const shouldAutoJumpToFirstMatch =\n !useCoordinates && !useRange && jumpToPageValue <= 0;\n\n if (jumpToPageValue > 0 && !useRange) {\n const index = jumpToPageValue - 1;\n const key = orderedKeys[index];\n const page = highlightPages[key];\n const cordinateTargetHighlight = highlightCordinatePages[index];\n setCursorIndex(index);\n\n console.log(cordinateTargetHighlight, \"cordinateTargetHighlight\");\n if (useCoordinates && cordinateTargetHighlight.pageIndex > 0)\n jumpToPage(cordinateTargetHighlight.pageIndex);\n\n if (page > 0) {\n setTimeout(() => {\n hideNonTargetHighlights(highlightPageSet);\n deduplicateHighlights(page - 1);\n }, 1000);\n if (!useCoordinates) {\n jumpToPage(page - 1);\n }\n }\n } else if (useRange && rangeOfPages && rangeOfPages.length === 2) {\n \n // Async function to handle sequential jumping and waiting\n const scanRangeSequence = async () => {\n const [startPage, endPage] = rangeOfPages;\n \n for (let p = startPage; p <= endPage; p++) {\n const targetPageIndex = p - 1;\n \n jumpToPage(targetPageIndex);\n \n // Pause execution for 1 second to let the DOM render the highlights\n await new Promise((resolve) => setTimeout(resolve, 1000));\n \n hideNonTargetHighlights(highlightPageSet);\n const matchSize = deduplicateHighlights(targetPageIndex);\n \n // If the returned size is greater than 0, a match was found. Stop the loop.\n if (matchSize && matchSize > 0) {\n break; \n }\n }\n };\n\n scanRangeSequence();\n\n } else if (!useCoordinates && highlightPages) {\n const firstKey = orderedKeys.find(k => highlightPages[k] > 0);\n if (firstKey !== undefined) {\n const firstPage = highlightPages[firstKey] - 1;\n jumpToPage(firstPage);\n setTimeout(() => {\n hideNonTargetHighlights(highlightPageSet);\n deduplicateHighlights(firstPage);\n }, 1000);\n }\n }\n\n requestAnimationFrame(() => {\n if (shouldAutoJumpToFirstMatch) {\n tryJump();\n }\n if (!useCoordinates && jumpToPageValue > 0 && !useRange) {\n scrollToHighlight();\n }\n });\n }}\n onPageChange={(e: PageChangeEvent) => {\n const currentPage = e.currentPage;\n setCurrentPage(currentPage);\n onCurrentPageChange?.(currentPage + 1);\n if (!highlightPageSet.has(currentPage)) {\n hideNonTargetHighlights(highlightPageSet);\n return;\n }\n deduplicateHighlights(currentPage);\n hideNonTargetHighlights(highlightPageSet);\n }}\n renderPage={resolvedRenderPage}\n setRenderRange={setRenderRange}\n />\n </div>\n );\n};\n\nexport default PdfViewer;\n"],"names":["PdfViewer","pdfUrl","highlightText","highlightPages","highlightCordinatePages","highlightColor","activeHighlightColor","jumpToPageValue","pdfName","onClose","customStyles","customClasses","customIcons","useCoordinates","fallbackPages","activeCitationIndex","onActiveCitationChange","headerAction","isZoomEnabled","showHighlightsAction","defaultScale","SpecialZoomLevel","ActualSize","useRange","rangeOfPages","showFullScreenAction","showRotateButton","segments","title","start_page","end_page","page_count","segmentTooltipText","onCurrentPageChange","navigationRequest","onNavigationSettled","disablePdfAnnotations","disablePdfTextLayer","renderPage","setRenderRange","viewerRef","useRef","resolvedDefaultScale","scale","PageFit","PageWidth","getResolvedScale","currentPage","setCurrentPage","useState","totalPages","setTotalPages","currentPageRotation","setCurrentPageRotation","lastNavigationRequestRef","navigationSettleTimerRef","navigationSettleSequenceRef","mutationObserverRef","pdfIdentifier","useMemo","URL","window","location","origin","pathname","split","pop","useEffect","rotationManager","setPdfIdentifier","onRotationChange","pageNum","angle","observer","MutationObserver","pageElements","current","querySelectorAll","registeredPages","Set","forEach","pageElement","match","getAttribute","length","pageNumber","parseInt","has","registerPageElement","add","observe","childList","subtree","attributes","disconnect","clearAll","getRotation","resolvedRenderPage","props","resolvedTextLayerChildren","jsx","style","display","children","textLayer","resolvedProps","annotationLayer","jsxs","Fragment","canvasLayer","highlightPageSet","map","h","pageIndex","set","Object","values","p","removeRedundantHighlightTexts","texts","filter","text","some","otherText","includes","highlightIndex","setHighlightIndex","cursorIndex","setCursorIndex","orderedKeys","totalHighlights","getValidPosition","tryJump","jumpToPage","zoomTo","plugins","controls","hideNonTargetHighlights","deduplicateHighlights","scrollToCoord","PdfHighlightControls","currentPosition","currentSegment","find","segment","modifiedControls","goToNext","goToPrevious","waitForNavigationToSettle","React","useCallback","request","settleSequence","clearTimeout","previousScrollTop","stableChecks","attempts","checkScrollPosition","scrollContainer","querySelector","targetPage","requestId","setTimeout","scrollTop","scrollRect","getBoundingClientRect","pageRect","isTargetVisible","Boolean","bottom","top","nextPage","Math","min","max","trunc","requestKey","ScannedDocCitation","pages","ref","className","pdfViewerWrapper","join","height","minHeight","minWidth","overflow","flexDirection","pdfStyles","pdfViewer","width","backgroundColor","PdfToolbar","onPageNavigate","onRotatePage","rotatePageBy90","PdfContainer","onLoad","e","doc","numPages","shouldAutoJumpToFirstMatch","index","key","page","cordinateTargetHighlight","console","log","async","startPage","endPage","targetPageIndex","Promise","resolve","matchSize","scanRangeSequence","firstKey","k","firstPage","requestAnimationFrame","pageVisitMap","i","push","occurrence","indexOf","doScrollToHighlight","scrollContainerRect","target","highlightRect","clientHeight","scrollTo","behavior","scrollToHighlight","onPageChange"],"mappings":"stBAoGA,MA2BMA,EAAY,EAChBC,SACAC,gBACAC,iBACAC,0BACAC,iBAAiB,SACjBC,uBAAuB,UACvBC,kBAAkB,EAClBC,UACAC,UACAC,eACAC,gBACAC,cACAC,iBACAC,gBACAC,sBACAC,yBACAC,eACAC,iBAAgB,EAChBC,wBAAuB,EACvBC,eAAeC,EAAiBC,WAChCC,YAAW,EACXC,eAAe,KACfC,wBAAqB,EACrBC,oBAAmB,EACnBC,WAAW,CACT,CACEC,MAAO,aACPC,WAAY,GACZC,SAAU,GACVC,WAAY,IAGhBC,qBACAC,sBACAC,oBACAC,sBACAC,yBAAwB,EACxBC,uBAAsB,EACtBC,aACAC,qBAGM,MAAAC,EAAYC,EAA8B,MAC1CC,EAvEiB,CACvBC,IAEA,OAAQA,GACN,IAAK,aACH,OAAOtB,EAAiBC,WAE1B,IAAK,UACH,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AqB,KAI5B,MAAAG,EAAgBD,EAAO9D,wBACvBF,EACJL,EAAgBK,WACfiE,EAAc1D,IAAMwD,EAAoBxD,KACzCZ,EAAgBuE,aAAe,EAC/BD,EAAc7C,OAAS,EAEzBzB,EAAgBwE,SAAS,CAAE5D,IAAKP,EAAWoE,SAAU,YAGvDrE,WAAW+D,EAAqB,MA+HJO,MAIxBC,aAAenC,IACb,MAAMvJ,EAAcuJ,EAAEvJ,YACtBC,EAAeD,GACfd,IAAsBc,EAAc,GAC/B+D,GAAiBvB,IAAIxC,IAI1B2F,GAAsB3F,GACtB0F,GAAwB3B,KAJtB2B,GAAwB3B,KAM5BxE,WAAY2D,GACZ1D"}
|
|
1
|
+
{"version":3,"file":"PdfViewer.js","sources":["../../../src/features/PdfViewer/PdfViewer.tsx"],"sourcesContent":["import { DocumentLoadEvent, PageChangeEvent, RenderPage, SetRenderRange, SpecialZoomLevel, type LoadError } from \"@react-pdf-viewer/core\";\nimport PdfContainer from \"./PdfContainer\";\nimport PdfToolbar from \"./PdfToolbar\";\nimport { pdfStyles } from \"./PdfStyle\";\nimport { PdfHighlightControls } from \"./usePdfHighlight\";\nimport { rotationManager } from \"./rotationManager\";\nimport \"@react-pdf-viewer/zoom/lib/styles/index.css\";\nimport \"@react-pdf-viewer/page-navigation/lib/styles/index.css\";\nimport \"@react-pdf-viewer/core/lib/styles/index.css\";\nimport \"@react-pdf-viewer/search/lib/styles/index.css\";\nimport React, { useMemo, useRef, useEffect, useState } from \"react\";\nimport ScannedDocCitation, { CitationPage } from \"../ScannedDocCitation/ScannedDocCitation\";\nimport \"./PdfViewer.css\";\n\nexport type CustomIconsType = {\n pdfIcon?: React.ReactNode;\n fullScreenIcon?: React.ReactNode;\n downloadIcon?: React.ReactNode;\n closeIcon?: React.ReactNode;\n};\n\nexport type CustomStylesType = {\n pdfViewer?: React.CSSProperties;\n header?: React.CSSProperties;\n pdfIconWrapper?: React.CSSProperties;\n pdfName?: React.CSSProperties;\n pdfContainer?: React.CSSProperties;\n emptyState?: React.CSSProperties;\n};\n\nexport type CustomClassesType = {\n header?: string;\n pdfName?: string;\n actionButton?: string;\n pdfViewerWrapper?: string;\n};\n\nexport type PdfSegment = {\n title: string;\n start_page: number;\n end_page: number;\n page_count: number;\n};\n\ntype PdfScaleOption =\n | \"ActualSize\"\n | \"PageFit\"\n | \"PageWidth\"\n | number;\nexport interface PdfNavigationRequest {\n pageNumber: number;\n /** Change this value to navigate to the same page more than once. */\n requestId?: string | number;\n}\n\nexport interface PdfNavigationSettledEvent extends PdfNavigationRequest {\n pageNumber: number;\n}\n\nexport interface PdfViewerProps {\n pdfUrl?: string;\n highlightText: string[];\n highlightPages?: any;\n highlightCordinatePages: HighlightArea[];\n highlightColor?: string;\n activeHighlightColor?: string;\n jumpToPageValue?: number;\n pdfName?: string;\n onClose?: () => void;\n item?: any;\n customStyles?: CustomStylesType;\n customClasses?: CustomClassesType;\n customIcons?: CustomIconsType;\n useCoordinates: boolean;\n fallbackPages?: CitationPage[];\n activeCitationIndex?: number;\n onActiveCitationChange?: (index: number) => void;\n headerAction?: {\n icon?: React.ReactNode;\n onClick?: () => void;\n tooltip?: string;\n };\n isZoomEnabled?: boolean;\n showHighlightsAction?: boolean;\n defaultScale?: PdfScaleOption;\n useRange?: boolean; //\n rangeOfPages?: number[] | null;\n showFullScreenAction?: boolean;\n showRotateButton?: boolean;\n segments?: PdfSegment[];\n segmentTooltipText?: string;\n onCurrentPageChange?: (pageNumber: number) => void;\n navigationRequest?: PdfNavigationRequest | null;\n onNavigationSettled?: (event: PdfNavigationSettledEvent) => void;\n disablePdfAnnotations?: boolean;\n disablePdfTextLayer?: boolean;\n renderPage?: RenderPage;\n setRenderRange?: SetRenderRange;\n onError?: (error: LoadError) => void;\n}\n\nconst getResolvedScale = (\n scale?: PdfScaleOption\n): SpecialZoomLevel | number => {\n switch (scale) {\n case \"ActualSize\":\n return SpecialZoomLevel.ActualSize;\n\n case \"PageFit\":\n return SpecialZoomLevel.PageFit;\n\n case \"PageWidth\":\n return SpecialZoomLevel.PageWidth;\n\n default:\n return scale ?? SpecialZoomLevel.PageWidth;\n }\n};\n\nexport type HighlightArea = {\n pageIndex: number;\n left: number;\n top: number;\n width: number;\n height: number;\n pageNumber?: number;\n};\n\nconst PdfViewer = ({\n pdfUrl,\n highlightText,\n highlightPages,\n highlightCordinatePages,\n highlightColor = \"yellow\",\n activeHighlightColor = \"#f7dc51\",\n jumpToPageValue,\n pdfName,\n onClose,\n customStyles,\n customClasses,\n customIcons,\n useCoordinates,\n fallbackPages,\n activeCitationIndex,\n onActiveCitationChange,\n headerAction,\n isZoomEnabled = true,\n showHighlightsAction = true,\n defaultScale = SpecialZoomLevel.ActualSize,\n useRange = false,\n rangeOfPages = null,\n showFullScreenAction=true,\n showRotateButton = false,\n segments = [\n {\n title: \"Document 2\",\n start_page: 52,\n end_page: 52,\n page_count: 1,\n },\n ],\n segmentTooltipText,\n onCurrentPageChange,\n navigationRequest,\n onNavigationSettled,\n disablePdfAnnotations = false,\n disablePdfTextLayer = false,\n renderPage,\n setRenderRange,\n onError\n}: PdfViewerProps) => {\n\n const viewerRef = useRef<HTMLDivElement | null>(null);\n const resolvedDefaultScale = getResolvedScale(defaultScale);\n const resolvedJumpToPageValue =\n jumpToPageValue ??\n (useCoordinates && highlightCordinatePages.length > 0 ? 1 : 0);\n const [currentPage, setCurrentPage] = useState(0);\n const [totalPages, setTotalPages] = useState(0);\n const [loadedPdfUrl, setLoadedPdfUrl] = useState<string | null>(null);\n const [currentPageRotation, setCurrentPageRotation] = useState(0);\n const lastNavigationRequestRef = useRef<string | null>(null);\n const navigationSettleTimerRef = useRef<number | null>(null);\n const navigationSettleSequenceRef = useRef(0);\n const mutationObserverRef = useRef<MutationObserver | null>(null);\n const coordinateAutoJumpKeyRef = useRef<string | null>(null);\n\n // Generate PDF identifier for localStorage from URL\n const pdfIdentifier = useMemo(() => {\n if (!pdfUrl) return '';\n // Use last part of URL or hash it\n try {\n const url = new URL(pdfUrl, window.location.origin);\n return url.pathname.split('/').pop() || 'default';\n } catch {\n return 'default';\n }\n }, [pdfUrl]);\n\n // Set up rotation manager with PDF identifier\n useEffect(() => {\n if (pdfIdentifier) {\n rotationManager.setPdfIdentifier(pdfIdentifier);\n }\n }, [pdfIdentifier]);\n\n // Handler for rotating current page (no state update)\n const handleRotatePage = () => {\n const pageNumber = currentPage + 1;\n rotationManager.rotatePageBy90(pageNumber);\n // Manually update state to reflect rotation in UI\n setCurrentPageRotation(rotationManager.getRotation(pageNumber));\n };\n\n // Subscribe to rotation changes to sync UI state\n useEffect(() => {\n const unsubscribe = rotationManager.onRotationChange((pageNum, angle) => {\n // Only update state if current page rotated\n if (pageNum === currentPage + 1) {\n setCurrentPageRotation(angle);\n }\n });\n\n return unsubscribe;\n }, [currentPage]);\n\n // Register page elements with rotation manager\n useEffect(() => {\n const observer = new MutationObserver(() => {\n // Find all newly rendered page elements\n const pageElements = viewerRef.current?.querySelectorAll(\n '[data-testid^=\"core__page-layer-\"]'\n );\n\n const registeredPages = new Set<number>();\n\n pageElements?.forEach((pageElement) => {\n const match = (pageElement as HTMLElement)\n .getAttribute('data-testid')\n ?.match(/core__page-layer-(\\d+)/);\n if (match && match.length >= 2) {\n const pageIndex = parseInt(match[1], 10);\n const pageNumber = pageIndex + 1;\n\n // Only register once per page\n if (!registeredPages.has(pageNumber)) {\n rotationManager.registerPageElement(pageNumber, pageElement as HTMLElement);\n registeredPages.add(pageNumber);\n }\n }\n });\n });\n\n if (viewerRef.current) {\n observer.observe(viewerRef.current, {\n childList: true,\n subtree: true,\n attributes: false,\n });\n mutationObserverRef.current = observer;\n }\n\n return () => {\n observer.disconnect();\n mutationObserverRef.current = null;\n };\n }, []);\n\n // Clean up when unmounting\n useEffect(() => {\n return () => {\n rotationManager.clearAll();\n if (mutationObserverRef.current) {\n mutationObserverRef.current.disconnect();\n }\n };\n }, []);\n\n // Update current page rotation when page changes\n useEffect(() => {\n const pageNumber = currentPage + 1;\n setCurrentPageRotation(rotationManager.getRotation(pageNumber));\n }, [currentPage]);\n const resolvedRenderPage = useMemo<RenderPage | undefined>(() => {\n if (!disablePdfAnnotations && !disablePdfTextLayer) return renderPage;\n\n return (props) => {\n const resolvedTextLayerChildren = disablePdfTextLayer ? (\n <div aria-hidden=\"true\" style={{ display: \"none\" }}>\n {props.textLayer.children}\n </div>\n ) : props.textLayer.children;\n const resolvedProps = {\n ...props,\n annotationLayer: {\n ...props.annotationLayer,\n children: disablePdfAnnotations ? null : props.annotationLayer.children,\n },\n textLayer: {\n ...props.textLayer,\n children: resolvedTextLayerChildren,\n },\n };\n\n const renderedPage = renderPage\n ? renderPage(resolvedProps)\n : (\n <>\n {props.canvasLayer.children}\n {resolvedTextLayerChildren}\n {!disablePdfAnnotations && props.annotationLayer.children}\n </>\n );\n\n return renderedPage;\n };\n }, [disablePdfAnnotations, disablePdfTextLayer, renderPage]);\n\n const cleanHighlightTexts = (texts: string[]): string[] => {\n if (!texts || texts.length === 0) return texts;\n return texts.filter((text) => {\n return !texts.some(\n (otherText) => otherText !== text && otherText.includes(text)\n );\n });\n };\n\n const highlightPageSet = useMemo(() => {\n if (useCoordinates) {\n return new Set(highlightCordinatePages.map((h: any) => h.pageIndex));\n } else {\n const set = new Set<number>();\n Object.values(highlightPages).forEach((p: any) => {\n if (p > 0) set.add(p - 1);\n });\n return set;\n }\n }, [highlightCordinatePages, highlightPages, useCoordinates]);\n\n const removeRedundantHighlightTexts = cleanHighlightTexts(highlightText);\n\n const {\n highlightIndex,\n setHighlightIndex,\n cursorIndex,\n setCursorIndex,\n orderedKeys,\n totalHighlights,\n getValidPosition,\n tryJump,\n jumpToPage,\n zoomTo,\n plugins,\n controls,\n hideNonTargetHighlights,\n deduplicateHighlights,\n scrollToCoordAfterNav,\n } = PdfHighlightControls(\n removeRedundantHighlightTexts,\n !useCoordinates ? highlightPages : {},\n viewerRef,\n highlightPageSet,\n useCoordinates,\n useCoordinates ? highlightCordinatePages : [],\n highlightColor,\n activeHighlightColor\n );\n\n useEffect(() => {\n if (\n !useCoordinates ||\n useRange ||\n totalPages <= 0 ||\n loadedPdfUrl !== (pdfUrl ?? null)\n ) {\n return;\n }\n\n const index = resolvedJumpToPageValue - 1;\n const target = highlightCordinatePages[index];\n if (!target || target.pageIndex < 0 || target.pageIndex >= totalPages) return;\n\n const jumpKey = [\n pdfUrl,\n index,\n target.pageIndex,\n target.top,\n target.height,\n ].join(\":\");\n if (coordinateAutoJumpKeyRef.current === jumpKey) return;\n coordinateAutoJumpKeyRef.current = jumpKey;\n\n setCursorIndex(index);\n jumpToPage(target.pageIndex);\n scrollToCoordAfterNav(target.pageIndex, target.top, target.height);\n }, [\n highlightCordinatePages,\n jumpToPage,\n loadedPdfUrl,\n pdfUrl,\n resolvedJumpToPageValue,\n scrollToCoordAfterNav,\n setCursorIndex,\n totalPages,\n useCoordinates,\n useRange,\n ]);\n\n const currentPosition = getValidPosition(cursorIndex);\n const currentSegment = useMemo(() => {\n const pageNumber = currentPage + 1;\n return segments.find(\n (segment) =>\n pageNumber >= segment.start_page && pageNumber <= segment.end_page\n );\n }, [currentPage, segments]);\n\n // sync external activeCitationIndex → cursorIndex\n useEffect(() => {\n if (activeCitationIndex === undefined) return;\n if (activeCitationIndex === cursorIndex) return;\n setCursorIndex(activeCitationIndex);\n }, [activeCitationIndex]);\n\n // wrap controls to fire onActiveCitationChange\n const handleGoToNext = () => {\n if (cursorIndex >= totalHighlights - 1) return;\n const nextIndex = cursorIndex + 1;\n\n if (useCoordinates) {\n const target = highlightCordinatePages[nextIndex];\n\n if (!target) return;\n\n setCursorIndex(nextIndex);\n jumpToPage(target.pageIndex);\n scrollToCoordAfterNav(\n target.pageIndex,\n Number.isFinite(target.top) ? target.top : 0,\n Number.isFinite(target.height) ? target.height : 0\n );\n } else {\n controls.goToNext();\n }\n\n onActiveCitationChange?.(nextIndex);\n };\n\n const handleGoToPrevious = () => {\n if (cursorIndex <= 0) return;\n const previousIndex = cursorIndex - 1;\n\n if (useCoordinates) {\n const target = highlightCordinatePages[previousIndex];\n\n if (!target) return;\n\n setCursorIndex(previousIndex);\n jumpToPage(target.pageIndex);\n scrollToCoordAfterNav(\n target.pageIndex,\n Number.isFinite(target.top) ? target.top : 0,\n Number.isFinite(target.height) ? target.height : 0\n );\n } else {\n controls.goToPrevious();\n }\n\n onActiveCitationChange?.(previousIndex);\n };\n\n const modifiedControls = {\n ...controls,\n goToNext: handleGoToNext,\n goToPrevious: handleGoToPrevious,\n };\n\n const handlePageNavigate = (pageNumber: number) => {\n const nextPage = Math.min(Math.max(pageNumber, 1), totalPages || pageNumber);\n setCurrentPage(nextPage - 1);\n jumpToPage(nextPage - 1);\n };\n\n const waitForNavigationToSettle = React.useCallback((\n request: PdfNavigationRequest,\n pageNumber: number\n ) => {\n navigationSettleSequenceRef.current += 1;\n const settleSequence = navigationSettleSequenceRef.current;\n if (navigationSettleTimerRef.current != null) {\n window.clearTimeout(navigationSettleTimerRef.current);\n }\n\n let previousScrollTop: number | null = null;\n let stableChecks = 0;\n let attempts = 0;\n\n const checkScrollPosition = () => {\n if (navigationSettleSequenceRef.current !== settleSequence) return;\n\n attempts += 1;\n\n const scrollContainer = viewerRef.current?.querySelector(\n '.rpv-core__inner-pages'\n ) as HTMLElement | null;\n const targetPage = viewerRef.current?.querySelector(\n `[data-testid=\"core__page-layer-${pageNumber - 1}\"]`\n ) as HTMLElement | null;\n\n // Virtualized page layers are not guaranteed to be mounted on the first\n // check after jumpToPage. Keep polling so navigation completion is not\n // lost while React PDF Viewer is creating the target page DOM.\n if (!scrollContainer || !targetPage) {\n if (attempts >= 40) {\n navigationSettleTimerRef.current = null;\n onNavigationSettled?.({\n pageNumber,\n requestId: request.requestId,\n });\n return;\n }\n\n navigationSettleTimerRef.current = window.setTimeout(checkScrollPosition, 50);\n return;\n }\n\n if (previousScrollTop === scrollContainer.scrollTop) {\n stableChecks += 1;\n } else {\n previousScrollTop = scrollContainer.scrollTop;\n stableChecks = 0;\n }\n\n const scrollRect = scrollContainer.getBoundingClientRect();\n const pageRect = targetPage.getBoundingClientRect();\n const isTargetVisible = Boolean(\n scrollRect &&\n pageRect &&\n pageRect.bottom > scrollRect.top &&\n pageRect.top < scrollRect.bottom\n );\n const hasSettled = stableChecks >= 2 && isTargetVisible;\n const reachedTimeout = attempts >= 40;\n\n if (hasSettled || reachedTimeout) {\n navigationSettleTimerRef.current = null;\n onNavigationSettled?.({\n pageNumber,\n requestId: request.requestId,\n });\n return;\n }\n\n navigationSettleTimerRef.current = window.setTimeout(checkScrollPosition, 50);\n };\n\n navigationSettleTimerRef.current = window.setTimeout(checkScrollPosition, 50);\n }, [onNavigationSettled]);\n\n useEffect(() => () => {\n navigationSettleSequenceRef.current += 1;\n if (navigationSettleTimerRef.current != null) {\n window.clearTimeout(navigationSettleTimerRef.current);\n }\n }, []);\n\n useEffect(() => {\n if (!navigationRequest || totalPages <= 0) return;\n\n const nextPage = Math.min(\n Math.max(Math.trunc(navigationRequest.pageNumber), 1),\n totalPages\n );\n const requestKey = `${navigationRequest.requestId ?? nextPage}:${nextPage}`;\n if (lastNavigationRequestRef.current === requestKey) return;\n\n lastNavigationRequestRef.current = requestKey;\n setCurrentPage(nextPage - 1);\n jumpToPage(nextPage - 1);\n waitForNavigationToSettle(navigationRequest, nextPage);\n }, [jumpToPage, navigationRequest, totalPages, waitForNavigationToSettle]);\n\n if (!pdfUrl) {\n return (\n <ScannedDocCitation\n pages={fallbackPages}\n activeCitationIndex={activeCitationIndex}\n onActiveCitationChange={onActiveCitationChange}\n headerAction={headerAction}\n />\n );\n }\n\n const defaultViewerStyles: React.CSSProperties = {\n display: \"flex\",\n flexDirection: \"column\",\n height: \"100%\",\n width: \"100%\",\n backgroundColor: \"#FAFAFA\",\n };\n\n const scrollToHighlight = () => {\n if (!viewerRef.current) return;\n\n const index = resolvedJumpToPageValue - 1;\n const key = orderedKeys[index];\n const page = highlightPages[key];\n const targetPage = page > 0 ? page - 1 : 0;\n\n const pageVisitMap: Record<number, number[]> = {};\n orderedKeys.forEach((k, i) => {\n const p = highlightPages[k];\n if (p > 0) {\n if (!pageVisitMap[p]) pageVisitMap[p] = [];\n pageVisitMap[p].push(i);\n }\n });\n const visits = pageVisitMap[page] || [];\n const occurrence = visits.indexOf(index);\n\n let attempts = 0;\n const maxAttempts = 40;\n\n const doScrollToHighlight = () => {\n attempts++;\n if (attempts > maxAttempts) return;\n\n const scrollContainer = viewerRef.current?.querySelector(\n \".rpv-core__inner-pages\"\n ) as HTMLElement;\n if (!scrollContainer) {\n setTimeout(doScrollToHighlight, 100);\n return;\n }\n\n const pageElement = viewerRef.current?.querySelector(\n `[data-testid=\"core__page-layer-${targetPage}\"]`\n );\n if (!pageElement) {\n setTimeout(doScrollToHighlight, 100);\n return;\n }\n\n const scrollContainerRect = scrollContainer.getBoundingClientRect();\n const pageRect = pageElement.getBoundingClientRect();\n const isPageVisible =\n pageRect.top < scrollContainerRect.bottom &&\n pageRect.bottom > scrollContainerRect.top;\n\n if (!isPageVisible) {\n setTimeout(doScrollToHighlight, 100);\n return;\n }\n\n const allHighlights = pageElement.querySelectorAll(\".rpv-search__highlight\");\n const target = allHighlights[occurrence] as HTMLElement;\n\n if (!target) {\n setTimeout(doScrollToHighlight, 100);\n return;\n }\n\n const highlightRect = target.getBoundingClientRect();\n const scrollTop =\n scrollContainer.scrollTop +\n (highlightRect.top - scrollContainerRect.top) -\n scrollContainer.clientHeight / 2 +\n highlightRect.height / 2;\n\n scrollContainer.scrollTo({ top: scrollTop, behavior: \"smooth\" });\n };\n\n setTimeout(doScrollToHighlight, 500);\n };\n\n return (\n <div\n ref={viewerRef}\n className={[\"citation-pdf-viewer\", customClasses?.pdfViewerWrapper]\n .filter(Boolean)\n .join(\" \")}\n data-disable-pdf-annotations={\n disablePdfAnnotations ? \"true\" : undefined\n }\n data-pdf-page-fit={\n resolvedDefaultScale === SpecialZoomLevel.PageFit ? \"true\" : undefined\n }\n style={{\n height: \"100%\",\n minHeight: 0,\n minWidth: 0,\n overflow: \"hidden\",\n display: \"flex\",\n flexDirection: \"column\",\n ...pdfStyles.pdfViewer,\n ...defaultViewerStyles,\n ...customStyles?.pdfViewer,\n backgroundColor: \"#F1F5F9\",\n }}\n >\n <PdfToolbar\n highlightIndex={highlightIndex}\n totalHighlights={totalHighlights}\n controls={modifiedControls}\n currentPosition={currentPosition}\n pdfName={pdfName}\n onClose={onClose}\n pdfUrl={pdfUrl}\n viewerRef={viewerRef}\n customStyles={customStyles}\n customClasses={customClasses}\n customIcons={customIcons}\n headerAction={headerAction}\n isZoomEnabled={isZoomEnabled}\n showHighlightsAction={showHighlightsAction}\n showFullScreenAction={showFullScreenAction} \n currentSegment={currentSegment}\n segmentTooltipText={segmentTooltipText}\n currentPage={currentPage + 1}\n totalPages={totalPages}\n onPageNavigate={handlePageNavigate}\n onRotatePage={handleRotatePage}\n currentPageRotation={currentPageRotation}\n showRotateButton={showRotateButton}\n />\n <PdfContainer\n defaultScale={resolvedDefaultScale}\n pdfUrl={pdfUrl}\n plugins={plugins}\n customStyles={customStyles}\n onError={onError}\n onLoad={(e: DocumentLoadEvent) => {\n setTotalPages(e.doc.numPages);\n setLoadedPdfUrl(pdfUrl ?? null);\n\n const shouldAutoJumpToFirstMatch =\n !useCoordinates && !useRange && resolvedJumpToPageValue <= 0;\n\n if (\n !useCoordinates &&\n resolvedJumpToPageValue > 0 &&\n !useRange\n ) {\n const index = resolvedJumpToPageValue - 1;\n const key = orderedKeys[index];\n const page = key !== undefined ? highlightPages?.[key] : undefined;\n setCursorIndex(index);\n\n if (page > 0) {\n setTimeout(() => {\n hideNonTargetHighlights(highlightPageSet);\n deduplicateHighlights(page - 1);\n }, 1000);\n jumpToPage(page - 1);\n }\n } else if (useRange && rangeOfPages && rangeOfPages.length === 2) {\n \n // Async function to handle sequential jumping and waiting\n const scanRangeSequence = async () => {\n const [startPage, endPage] = rangeOfPages;\n \n for (let p = startPage; p <= endPage; p++) {\n const targetPageIndex = p - 1;\n \n jumpToPage(targetPageIndex);\n \n // Pause execution for 1 second to let the DOM render the highlights\n await new Promise((resolve) => setTimeout(resolve, 1000));\n \n hideNonTargetHighlights(highlightPageSet);\n const matchSize = deduplicateHighlights(targetPageIndex);\n \n // If the returned size is greater than 0, a match was found. Stop the loop.\n if (matchSize && matchSize > 0) {\n break; \n }\n }\n };\n\n scanRangeSequence();\n\n } else if (!useCoordinates && highlightPages) {\n const firstKey = orderedKeys.find(k => highlightPages[k] > 0);\n if (firstKey !== undefined) {\n const firstPage = highlightPages[firstKey] - 1;\n jumpToPage(firstPage);\n setTimeout(() => {\n hideNonTargetHighlights(highlightPageSet);\n deduplicateHighlights(firstPage);\n }, 1000);\n }\n }\n\n requestAnimationFrame(() => {\n if (shouldAutoJumpToFirstMatch) {\n tryJump();\n }\n if (!useCoordinates && resolvedJumpToPageValue > 0 && !useRange) {\n scrollToHighlight();\n }\n });\n }}\n onPageChange={(e: PageChangeEvent) => {\n const currentPage = e.currentPage;\n setCurrentPage(currentPage);\n onCurrentPageChange?.(currentPage + 1);\n if (!highlightPageSet.has(currentPage)) {\n hideNonTargetHighlights(highlightPageSet);\n return;\n }\n deduplicateHighlights(currentPage);\n hideNonTargetHighlights(highlightPageSet);\n }}\n renderPage={resolvedRenderPage}\n setRenderRange={setRenderRange}\n />\n </div>\n );\n};\n\nexport default PdfViewer;\n"],"names":["PdfViewer","pdfUrl","highlightText","highlightPages","highlightCordinatePages","highlightColor","activeHighlightColor","jumpToPageValue","pdfName","onClose","customStyles","customClasses","customIcons","useCoordinates","fallbackPages","activeCitationIndex","onActiveCitationChange","headerAction","isZoomEnabled","showHighlightsAction","defaultScale","SpecialZoomLevel","ActualSize","useRange","rangeOfPages","showFullScreenAction","showRotateButton","segments","title","start_page","end_page","page_count","segmentTooltipText","onCurrentPageChange","navigationRequest","onNavigationSettled","disablePdfAnnotations","disablePdfTextLayer","renderPage","setRenderRange","onError","viewerRef","useRef","resolvedDefaultScale","scale","PageFit","PageWidth","getResolvedScale","resolvedJumpToPageValue","length","currentPage","setCurrentPage","useState","totalPages","setTotalPages","loadedPdfUrl","setLoadedPdfUrl","currentPageRotation","setCurrentPageRotation","lastNavigationRequestRef","navigationSettleTimerRef","navigationSettleSequenceRef","mutationObserverRef","coordinateAutoJumpKeyRef","pdfIdentifier","useMemo","URL","window","location","origin","pathname","split","pop","useEffect","rotationManager","setPdfIdentifier","onRotationChange","pageNum","angle","observer","MutationObserver","pageElements","current","querySelectorAll","registeredPages","Set","forEach","pageElement","match","getAttribute","pageNumber","parseInt","has","registerPageElement","add","observe","childList","subtree","attributes","disconnect","clearAll","getRotation","resolvedRenderPage","props","resolvedTextLayerChildren","jsx","style","display","children","textLayer","resolvedProps","annotationLayer","jsxs","Fragment","canvasLayer","highlightPageSet","map","h","pageIndex","set","Object","values","p","removeRedundantHighlightTexts","texts","filter","text","some","otherText","includes","highlightIndex","setHighlightIndex","cursorIndex","setCursorIndex","orderedKeys","totalHighlights","getValidPosition","tryJump","jumpToPage","zoomTo","plugins","controls","hideNonTargetHighlights","deduplicateHighlights","scrollToCoordAfterNav","PdfHighlightControls","index","target","jumpKey","top","height","join","currentPosition","currentSegment","find","segment","modifiedControls","goToNext","nextIndex","Number","isFinite","goToPrevious","previousIndex","waitForNavigationToSettle","React","useCallback","request","settleSequence","clearTimeout","previousScrollTop","stableChecks","attempts","checkScrollPosition","scrollContainer","querySelector","targetPage","requestId","setTimeout","scrollTop","scrollRect","getBoundingClientRect","pageRect","isTargetVisible","Boolean","bottom","nextPage","Math","min","max","trunc","requestKey","ScannedDocCitation","pages","ref","className","pdfViewerWrapper","minHeight","minWidth","overflow","flexDirection","pdfStyles","pdfViewer","width","backgroundColor","PdfToolbar","onPageNavigate","onRotatePage","rotatePageBy90","PdfContainer","onLoad","e","doc","numPages","shouldAutoJumpToFirstMatch","key","page","async","startPage","endPage","targetPageIndex","Promise","resolve","matchSize","scanRangeSequence","firstKey","k","firstPage","requestAnimationFrame","pageVisitMap","i","push","occurrence","indexOf","doScrollToHighlight","scrollContainerRect","highlightRect","clientHeight","scrollTo","behavior","scrollToHighlight","onPageChange"],"mappings":"stBAqGA,MA2BMA,EAAY,EAChBC,SACAC,gBACAC,iBACAC,0BACAC,iBAAiB,SACjBC,uBAAuB,UACvBC,kBACAC,UACAC,UACAC,eACAC,gBACAC,cACAC,iBACAC,gBACAC,sBACAC,yBACAC,eACAC,iBAAgB,EAChBC,wBAAuB,EACvBC,eAAeC,EAAiBC,WAChCC,YAAW,EACXC,eAAe,KACfC,wBAAqB,EACrBC,oBAAmB,EACnBC,WAAW,CACT,CACEC,MAAO,aACPC,WAAY,GACZC,SAAU,GACVC,WAAY,IAGhBC,qBACAC,sBACAC,oBACAC,sBACAC,yBAAwB,EACxBC,uBAAsB,EACtBC,aACAC,iBACAC,cAGM,MAAAC,EAAYC,EAA8B,MAC1CC,EAxEiB,CACvBC,IAEA,OAAQA,GACN,IAAK,aACH,OAAOvB,EAAiBC,WAE1B,IAAK,UACH,OAAOD,EAAiBwB,QAE1B,IAAK,YACH,OAAOxB,EAAiByB,UAE1B,QACE,OAAOF,GAASvB,EAAiByB,YA0DRC,CAAiB3B,GACxC4B,EACJzC,IACCM,GAAkBT,EAAwB6C,OAAS,EAAI,EAAI,IACvDC,EAAaC,GAAkBC,EAAS,IACxCC,GAAYC,IAAiBF,EAAS,IACtCG,GAAcC,IAAmBJ,EAAwB,OACzDK,GAAqBC,IAA0BN,EAAS,GACzDO,GAA2BjB,EAAsB,MACjDkB,GAA2BlB,EAAsB,MACjDmB,GAA8BnB,EAAO,GACrCoB,GAAsBpB,EAAgC,MACtDqB,GAA2BrB,EAAsB,MAGjDsB,GAAgBC,EAAQ,KACxB,IAAChE,EAAe,MAAA,GAEhB,IAEF,OADY,IAAIiE,IAAIjE,EAAQkE,OAAOC,SAASC,QACjCC,SAASC,MAAM,KAAKC,OAAS,SAAA,CAClC,MACC,MAAA,SACT,GACC,CAACvE,IAGJwE,EAAU,KACJT,IACFU,EAAgBC,iBAAiBX,KAElC,CAACA,KAWJS,EAAU,IACYC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EAAW,EACf,MAEM8D,EAAsB,KAE1B,GADA9D,IACIA,EAJc,GAIU,OAEtB,MAAAE,EAAkBpI,EAAUyC,SAAS4F,cACzC,0BAEF,IAAKD,EAEH,YADAI,WAAWwD,EAAqB,KAI5B,MAAAlJ,EAAc9C,EAAUyC,SAAS4F,cACrC,kCAAkCC,OAEpC,IAAKxF,EAEH,YADA0F,WAAWwD,EAAqB,KAI5B,MAAAC,EAAsB7D,EAAgBO,wBACtCC,EAAW9F,EAAY6F,wBAK7B,KAHEC,EAAShC,IAAMqF,EAAoBlD,QACnCH,EAASG,OAASkD,EAAoBrF,KAItC,YADA4B,WAAWwD,EAAqB,KAI5B,MACAtF,EADgB5D,EAAYJ,iBAAiB,0BACtBoJ,GAE7B,IAAKpF,EAEH,YADA8B,WAAWwD,EAAqB,KAI5B,MAAAE,EAAgBxF,EAAOiC,wBACvBF,EACJL,EAAgBK,WACfyD,EAActF,IAAMqF,EAAoBrF,KACzCwB,EAAgB+D,aAAe,EAC/BD,EAAcrF,OAAS,EAEzBuB,EAAgBgE,SAAS,CAAExF,IAAK6B,EAAW4D,SAAU,YAGvD7D,WAAWwD,EAAqB,MA8HJM,MAIxBC,aAAe9B,IACb,MAAMhK,EAAcgK,EAAEhK,YACtBC,EAAeD,GACfjB,IAAsBiB,EAAc,GAC/BiE,GAAiBvB,IAAI1C,IAI1B6F,GAAsB7F,GACtB4F,GAAwB3B,KAJtB2B,GAAwB3B,KAM5B7E,WAAYgE,GACZ/D"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,Fragment as t}from"react/jsx-runtime";import{useState as r,useRef as n,useMemo as o}from"react";import{searchPlugin as l}from"@react-pdf-viewer/search";import{pageNavigationPlugin as i}from"@react-pdf-viewer/page-navigation";import{zoomPlugin as s}from"@react-pdf-viewer/zoom";import{highlightPlugin as c}from"@react-pdf-viewer/highlight";const a=(a,h,g,u,p,f,d="yellow",m="#F6D739")=>{const[x,T]=r(0),v=n(!1),[y,w]=r(0);n([]);const M=e=>e.replace(/[^\S\n]+/g," ").trim(),b=e=>(e||"").toLowerCase().replace(/\u00ad/g,"").replace(/[""]/g,'"').replace(/['']/g,"'").replace(/[\u2013\u2014]/g,"-").replace(/-/g," ").replace(/[^\w\s]/g,"").replace(/\s+/g," ").trim(),_=e=>{let t=e.trim();t=t.replace(/[\u200B-\u200D\uFEFF]/g,"").replace(/[\u00A0\u2009\u202F]/g," "),t=t.replace(/^[-•]\s+/,"");const r=t.match(/^((\d+(?:\.\d+)*[.)]?)|[A-Za-z][.)]|\([A-Za-z0-9]+\)|(?:i|ii|iii|iv|v|vi|vii|viii|ix|x)[.)])\s*/i);return r?t.slice(r[0].length).trim():t},I=e=>{const t=b(e),r=t.replace(/\s+/g,""),n=new Set;return t&&n.add(t),r&&n.add(r),n},S=e=>e.replace(/\\([''])/g,"$1").replace(/\]\s*\n\s*\(/g,"](").replace(/&[#\w]+;/g,e=>(e=>{const t=document.createElement("textarea");return t.innerHTML=e,t.value})(e)).replace(/<br\s*\/?>/gi,"\n").replace(/\[([^\]]+)\]\(([^)]+)\)/g,"$1").replace(/`([^`]+)`/g,"$1"),$=e=>{if(!e)return[];return S(e).split(/\n+/).map(_).flatMap(e=>{const t=e.match(/^\s*\|(.+)\|\s*$/);return t?t[1].split("|").map(e=>e.trim()).filter(Boolean):[e]}).map(e=>M((e=>e.replace(/(^|\W)[*_]{1,3}([^*_]+)[*_]{1,3}(?=\W|$)/g,"$1$2"))(e))).filter(Boolean)},E=Object.keys(h).map(Number).sort((e,t)=>e-t),A=o(()=>p?f.length:p?0:Object.values(h).filter(e=>e>0).length,[f,h]),k=e=>{if(!g.current)return;const t=g.current.querySelector(`[data-testid="search__highlights-${e}"]`);if(!t)return;const r=Array.from(t.querySelectorAll(".rpv-search__highlight"));if(0===r.length)return;const n=j.map(I),o=R.map(I);if(0===n.length&&0===o.length)return;const l=r.map(e=>{const t=(e=>{const t=e.getBoundingClientRect();if(t.height>0||t.width>0)return{top:t.top,left:t.left,right:t.right};const r=e.offsetTop,n=e.offsetLeft;return{top:r,left:n,right:n+e.offsetWidth}})(e),r=(e.textContent||"").trim(),n=(e.getAttribute("title")||"").trim();return{el:e,text:r||n,...t}}).filter(e=>e.text.length>0).sort((e,t)=>e.top-t.top||e.left-t.left);if(0===l.length)return;const i=[];let s=null,c=[];const h=()=>{if(!s)return;const e=c.join(" ");s.title=b(e),s.title&&i.push(s),s=null,c=[]};if(l.forEach(e=>{if(!s)return s={title:"",elements:[e.el],lastTop:e.top,lastRight:e.right},void(c=[e.text]);const t=Math.abs(e.top-s.lastTop)<=5,r=e.left<=s.lastRight+28;t&&r?(s.elements.push(e.el),s.lastTop=e.top,s.lastRight=Math.max(s.lastRight,e.right),c.push(e.text)):(h(),s={title:"",elements:[e.el],lastTop:e.top,lastRight:e.right},c=[e.text])}),h(),0===i.length)return;const u=(e,t)=>{if(!e)return!1;if(t.has(e))return!0;const r=e.replace(/\s+/g,"");for(const n of Array.from(t)){if(!n)continue;const t=n.replace(/\s+/g,"");if(t===r)return!0;if(n.length>=8&&e.length>=5&&n.includes(e))return!0;if(t.length>=8&&r.length>=5&&t.includes(r))return!0;if(e.length>=10&&n.length>=8&&e.includes(n))return!0;if(r.length>=10&&t.length>=8&&r.includes(t))return!0}return!1};let p=0,f=new Set;const d=Array.from(new Set([...j,...R].map(b).filter(e=>e.length>=8))).sort((e,t)=>t.length-e.length),m=e=>{if(!e||e.length<8)return null;const t=e.replace(/\s+/g,"");for(let r=0;r<i.length;r++){let n="",o="";const l=new Set;for(let s=r;s<i.length&&s<r+20;s++){const r=i[s].title;if(n=n?`${n} ${r}`:r,o=o?`${o}${r.replace(/\s+/g,"")}`:r.replace(/\s+/g,""),l.add(s),n.includes(e)||o.includes(t))return l;if(n.length>=15&&(e.includes(n)||t.includes(o)))return l;if(n.length>e.length+150)break}}return null};for(const e of d){const t=m(e);t&&t.size>0&&(t.forEach(e=>f.add(e)),p=f.size)}if(0===p){const e=(e=>{if(0===e.length)return null;let t=null;for(const r of e)for(const e of Array.from(r)){if(!e||e.length<5)continue;const r=e.replace(/\s+/g,"");for(let n=0;n<i.length;n++){let o="",l="";const s=new Set;for(let c=n;c<i.length&&c<n+15;c++){const n=i[c].title;if(o=o?`${o} ${n}`:n,l=l?`${l}${n.replace(/\s+/g,"")}`:n.replace(/\s+/g,""),s.add(c),o.includes(e)||l.includes(r)){const r=Math.max(0,o.length-e.length);(!t||r<t.extra)&&(t={blocks:new Set(s),extra:r});break}if(o.length>e.length+120)break}}}return t?t.blocks:null})(n);e&&e.size>0&&(e.forEach(e=>f.add(e)),p=f.size)}const x=(e=>{if(e.length<2)return 40;const t=[];for(let r=1;r<e.length;r++){const n=Math.abs(e[r].lastTop-e[r-1].lastTop);n>0&&t.push(n)}if(0===t.length)return 40;t.sort((e,t)=>e-t);const r=t[Math.floor(t.length/2)],n=Math.round(2.25*r);return Math.min(60,Math.max(24,n))})(i),T=R.map(b).filter(e=>e.length>=8),v=T.map(e=>e.split(/\s+/).filter(e=>e.length>=2));if(0===p){const e=o;for(let t=0;t<i.length;t++){const r=i[t].title;for(let n=0;n<e.length;n++){if(!u(r,e[n]))continue;let o=0;const l=new Set;let s=n,c=t-1;for(let r=t;r<i.length&&s<e.length;r++){if(u(i[r].title,e[s])){if(c>=0){const e=i[c].lastTop,t=i[r].lastTop;if(Math.abs(t-e)>x)break}o++,l.add(r),c=r,s++}else if(s>0&&u(i[r].title,e[s-1])){const e=i[c].lastTop,t=i[r].lastTop;Math.abs(t-e)<=3&&(l.add(r),c=r)}if(r-c>6)break}o>p&&(p=o,f=l)}}}if(p<Math.min(3,T.length)&&T.length>0){const e=new Set;i.forEach((t,r)=>{const n=t.title.split(/\s+/).filter(e=>e.length>=2);if(n.length<2)return;const o=new Set(n);for(const t of v){if(t.length<2)continue;let n=0;for(const e of t)o.has(e)&&n++;const l=n/t.length;if(n>=3||l>=.5){e.add(r);break}}}),e.size>0&&(f=e,p=Math.max(p,e.size))}const y=new Set;if(F.forEach(e=>{const t=b(e);t&&(y.add(t),y.add(t.replace(/\s+/g,"")))}),0===p){const e=new Set;if(i.forEach((t,r)=>{const n=t.title.replace(/\s+/g,"");if(y.has(t.title)||y.has(n))return void e.add(r);const o=Array.from(y);for(let n=0;n<o.length;n++){const l=o[n];if(l.length>=10&&l.includes(t.title)&&t.title.length>=5){e.add(r);break}}}),0===e.size)return 0;f=e}i.forEach((e,t)=>{const r=f.has(t);e.elements.forEach(e=>{r?(e.classList.add("verified-match"),e.style.display=""):(e.style.display="none",e.classList.remove("verified-match"))})});const w=[];return i.forEach((e,t)=>{f.has(t)&&e.elements.forEach(e=>w.push(e))}),requestAnimationFrame(()=>{const e=w.map(e=>({el:e,rect:e.getBoundingClientRect()})).filter(e=>e.rect.width>0&&e.rect.height>0).sort((e,t)=>t.rect.width*t.rect.height-e.rect.width*e.rect.height),t=[];e.forEach(({el:e,rect:r})=>{t.some(e=>((e,t)=>{const r=Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top)),n=Math.min(e.width*e.height,t.width*t.height);return n>0?r/n:0})(e.rect,r)>.5)?(e.style.display="none",e.classList.remove("verified-match")):t.push({el:e,rect:r})})}),console.groupCollapsed(`[debug: PDF ordered matching - Page ${e}]`),console.log("input->",a),console.log("processed sentences->",j),console.log("processed lines->",R),console.log("Expected sentence count:",n.length),console.log("Expected line count:",o.length),console.log("Matched sequence length:",p),console.log("blocksToKeep",f,"size",f.size),console.groupEnd(),f.size},z=e=>{if(!g.current)return;g.current.querySelectorAll(".rpv-search__highlights").forEach(t=>{const r=t.getAttribute("data-testid"),n=parseInt(r?.replace(/search__highlights-/g,"")||"-1"),o=t.querySelectorAll(".rpv-search__highlight");e.has(n)||o.forEach(e=>{e.style.display="none"})})},q=a.map(e=>(e=>e?S(e).split(/\n{2,}/).map(e=>$(e).join(" ")).map(e=>M(e)).filter(Boolean):[])(e)).flat(),B=a.map(e=>$(e)).flat(),C=q.some(e=>e.length>=3)?3:1,j=q.filter(e=>e.length>=C),R=B.filter(e=>e.length>=C),H=R.flatMap(e=>((e,t=6,r=4)=>{const n=e.split(/\s+/).filter(Boolean);if(n.length<=t)return[];const o=[];for(let e=0;e+t<=n.length;e+=r)o.push(n.slice(e,e+t).join(" "));return n.length>t&&(n.length-t)%r!==0&&o.push(n.slice(n.length-t).join(" ")),o})(e)),F=Array.from(new Set([...j,...R,...H].flatMap(e=>{const t=M(e.replace(/[\u00A0\u2009\u202F]/g," ").replace(/\u00ad/g,"").replace(/[""]/g,'"').replace(/['']/g,"'"));if(!t)return[];const r=t.replace(/[\u2013\u2014]/g,"-"),n=M(r.replace(/(\w)-\s+(\w)/g,"$1$2")),o=M(r.replace(/-/g," ")),l=M(r.replace(/-/g,"")),i=M(t.replace(/[^\w\s]/g,"")),s=new Set([t,r,n,o,l,i]);return Array.from(s).filter(Boolean)}))).filter(e=>{const t=e.split(/\s+/).filter(Boolean);return!(e.length<C)&&(t.length>=3||e.length>=12)}),N=l({keyword:F}),P=i(),L=s(),{jumpToMatch:O}=N,{jumpToPage:Z}=P,{zoomTo:D,CurrentScale:W,ZoomPopover:K}=L,J=o(()=>(e=>{if(0===e.length)return[];const t=new Map;e.forEach((e,r)=>{const n=null!=e.pageNumber?e.pageNumber-1:e.pageIndex;t.has(n)||t.set(n,[]),t.get(n).push({...e,originalIndex:r})});const r=[];return t.forEach(e=>{const t=[...e].sort((e,t)=>e.top!==t.top?e.top-t.top:e.left-t.left),n=new Array(t.length).fill(!1);for(let e=0;e<t.length;e++){if(n[e])continue;let{left:o,top:l,width:i,height:s,pageIndex:c,pageNumber:a}=t[e],h=o+i,g=l+s;const u=[t[e].originalIndex];n[e]=!0;let p=!0;for(;p;){p=!1;for(let r=e+1;r<t.length;r++){if(n[r])continue;const e=t[r],c=e.left+e.width,a=e.top+e.height,f=Math.max(0,Math.min(h,c)-Math.max(o,e.left))*Math.max(0,Math.min(g,a)-Math.max(l,e.top)),d=Math.max(i*s,1e-4),m=Math.max(e.width*e.height,1e-4),x=Math.min(d,m);(x>0?f/x:0)>=.8&&(o=Math.min(o,e.left),l=Math.min(l,e.top),h=Math.max(h,c),g=Math.max(g,a),i=h-o,s=g-l,u.push(e.originalIndex),n[r]=!0,p=!0)}}r.push({pageIndex:c,pageNumber:a,left:o,top:l,width:i,height:s,originalIndexes:u})}}),r})(f),[f]),V=c({renderHighlights:r=>e(t,{children:J.filter(e=>null!=e.pageNumber?e.pageNumber-1===r.pageIndex:e.pageIndex===r.pageIndex).map(t=>{const r=t.originalIndexes.includes(y);return e("div",{style:{position:"absolute",left:`${t.left}%`,top:`${t.top+.08*t.height}%`,width:`${t.width}%`,height:.95*t.height+"%",background:r?m:d,opacity:r?.7:.4,transition:"background 0.2s, opacity 0.2s",border:r?"1px solid red":"1px solid transparent"}},t.originalIndexes.join("-"))})})}),G=()=>{if(!v.current)try{O(0),v.current=!0;const e=f[0];e&&p&&U(e.pageIndex,e.top)}catch{requestAnimationFrame(G)}},Q=(e,t)=>{if(!g.current)return;if(!g.current.querySelector(".rpv-core__viewer"))return;let r=-1;const n=()=>{const o=g.current?.querySelector(".rpv-core__inner-pages");if(!o)return;if(o.scrollTop!==r)return r=o.scrollTop,void setTimeout(n,100);const l=g.current?.querySelector(`[data-testid="core__page-layer-${e}"]`);if(!l)return;const i=l.querySelectorAll(".rpv-search__highlight")[t];if(!i)return;const s=o.getBoundingClientRect(),c=i.getBoundingClientRect(),a=o.scrollTop+(c.top-s.top)-o.clientHeight/2+c.height/2;o.scrollTo({top:a,behavior:"smooth"})};setTimeout(n,300)},U=(e,t,r=0)=>{if(!g.current)return;let n=0;const o=()=>{if(++n>60)return;const l=g.current?.querySelector(".rpv-core__inner-pages");if(!l)return void setTimeout(o,100);const i=g.current?.querySelector(`[data-testid="core__page-layer-${e}"]`);if(!i)return void setTimeout(o,100);const s=i.getBoundingClientRect();if(0===s.height)return void setTimeout(o,100);const c=l.getBoundingClientRect(),a=t/100*s.height,h=r/100*s.height,u=s.top-c.top+a,p=u+h;if(u>=80&&p<=l.clientHeight-80)return;const f=u<80?l.scrollTop+u-80:l.scrollTop+p-l.clientHeight+80;l.scrollTo({top:f,behavior:"smooth"})};setTimeout(o,100)},X=o(()=>{const e={};return E.forEach((t,r)=>{const n=h[t];n>0&&(e[n]||(e[n]=[]),e[n].push(r))}),e},[E,h]),Y=e=>{const t=h[E[e]];return(X[t]||[]).indexOf(e)},ee=(e,t,r=0)=>{if(!g.current)return;let n=-1,o=0;const l=()=>{if(++o>60)return;const i=g.current?.querySelector(".rpv-core__inner-pages");if(!i)return void setTimeout(l,100);if(i.scrollTop!==n)return n=i.scrollTop,void setTimeout(l,100);const s=g.current?.querySelector(`[data-testid="core__page-layer-${e}"]`);if(!s)return void setTimeout(l,100);const c=s.getBoundingClientRect();if(0===c.height)return void setTimeout(l,100);const a=i.getBoundingClientRect(),h=t/100*c.height,u=r/100*c.height,p=c.top-a.top+h,f=p+u;if(p>=80&&f<=i.clientHeight-80)return;const d=p<80?i.scrollTop+p-80:i.scrollTop+f-i.clientHeight+80;i.scrollTo({top:d,behavior:"instant"})};setTimeout(l,100)};return{setHighlightIndex:T,highlightIndex:x,cursorIndex:y,setCursorIndex:w,orderedKeys:E,totalHighlights:A,getValidPosition:e=>{if(p)return e+1;if(!h)return 0;let t=0;for(let r=0;r<=e;r++)h[E[r]]>0&&t++;return t},tryJump:G,jumpToPage:Z,zoomTo:D,hideNonTargetHighlights:z,deduplicateHighlights:k,scrollToCoord:U,plugins:[p?V:N,P,L],controls:{CurrentScale:W,ZoomPopover:K,zoomTo:D,goToNext:()=>{if(p&&f)for(let e=y+1;e<f.length;e++){const t=f[e],r=f[y];return w(e),void(t.pageIndex!==r.pageIndex?(Z(t.pageIndex),ee(t.pageIndex,t.top,t.height)):U(t.pageIndex,t.top,t.height))}else{for(let e=y+1;e<E.length;e++){const t=E[e];if(h[t]>0){const r=h[t]-1,n=Y(e);return w(e),Z(h[t]-1),Q(r,n),setTimeout(()=>{k(r)},500),void(1===Object.keys(h).length&&z(u))}}}},goToPrevious:()=>{if(p&&f)for(let e=y-1;e>=0;e--){const t=f[e],r=f[y];return w(e),void(t.pageIndex!==r.pageIndex?(Z(t.pageIndex),ee(t.pageIndex,t.top,t.height)):U(t.pageIndex,t.top,t.height))}else{for(let e=y-1;e>=0;e--){const t=E[e];if(h[t]>0){const r=h[t]-1,n=Y(e);return w(e),Z(h[t]-1),Q(r,n),setTimeout(()=>{k(r)},500),void(1===Object.keys(h).length&&z(u))}}}}}}};export{a as PdfHighlightControls};
|
|
1
|
+
import{jsx as e,Fragment as t}from"react/jsx-runtime";import{useState as r,useRef as n,useMemo as o}from"react";import{searchPlugin as l}from"@react-pdf-viewer/search";import{pageNavigationPlugin as i}from"@react-pdf-viewer/page-navigation";import{zoomPlugin as s}from"@react-pdf-viewer/zoom";import{highlightPlugin as c}from"@react-pdf-viewer/highlight";const a=(a,h,g,u,p,f,d="yellow",m="#F6D739")=>{const[x,v]=r(0),T=n(!1),[y,b]=r(0);n([]);const w=n(0),M=e=>e.replace(/[^\S\n]+/g," ").trim(),_=e=>(e||"").toLowerCase().replace(/\u00ad/g,"").replace(/[""]/g,'"').replace(/['']/g,"'").replace(/[\u2013\u2014]/g,"-").replace(/-/g," ").replace(/[^\w\s]/g,"").replace(/\s+/g," ").trim(),I=e=>{let t=e.trim();t=t.replace(/[\u200B-\u200D\uFEFF]/g,"").replace(/[\u00A0\u2009\u202F]/g," "),t=t.replace(/^[-•]\s+/,"");const r=t.match(/^((\d+(?:\.\d+)*[.)]?)|[A-Za-z][.)]|\([A-Za-z0-9]+\)|(?:i|ii|iii|iv|v|vi|vii|viii|ix|x)[.)])\s*/i);return r?t.slice(r[0].length).trim():t},S=e=>{const t=_(e),r=t.replace(/\s+/g,""),n=new Set;return t&&n.add(t),r&&n.add(r),n},$=e=>e.replace(/\\([''])/g,"$1").replace(/\]\s*\n\s*\(/g,"](").replace(/&[#\w]+;/g,e=>(e=>{const t=document.createElement("textarea");return t.innerHTML=e,t.value})(e)).replace(/<br\s*\/?>/gi,"\n").replace(/\[([^\]]+)\]\(([^)]+)\)/g,"$1").replace(/`([^`]+)`/g,"$1"),A=e=>{if(!e)return[];return $(e).split(/\n+/).map(I).flatMap(e=>{const t=e.match(/^\s*\|(.+)\|\s*$/);return t?t[1].split("|").map(e=>e.trim()).filter(Boolean):[e]}).map(e=>M((e=>e.replace(/(^|\W)[*_]{1,3}([^*_]+)[*_]{1,3}(?=\W|$)/g,"$1$2"))(e))).filter(Boolean)},E=Object.keys(h).map(Number).sort((e,t)=>e-t),k=o(()=>p?f.length:p?0:Object.values(h).filter(e=>e>0).length,[f,h]),z=e=>{if(!g.current)return;const t=g.current.querySelector(`[data-testid="search__highlights-${e}"]`);if(!t)return;const r=Array.from(t.querySelectorAll(".rpv-search__highlight"));if(0===r.length)return;const n=R.map(S),o=H.map(S);if(0===n.length&&0===o.length)return;const l=r.map(e=>{const t=(e=>{const t=e.getBoundingClientRect();if(t.height>0||t.width>0)return{top:t.top,left:t.left,right:t.right};const r=e.offsetTop,n=e.offsetLeft;return{top:r,left:n,right:n+e.offsetWidth}})(e),r=(e.textContent||"").trim(),n=(e.getAttribute("title")||"").trim();return{el:e,text:r||n,...t}}).filter(e=>e.text.length>0).sort((e,t)=>e.top-t.top||e.left-t.left);if(0===l.length)return;const i=[];let s=null,c=[];const h=()=>{if(!s)return;const e=c.join(" ");s.title=_(e),s.title&&i.push(s),s=null,c=[]};if(l.forEach(e=>{if(!s)return s={title:"",elements:[e.el],lastTop:e.top,lastRight:e.right},void(c=[e.text]);const t=Math.abs(e.top-s.lastTop)<=5,r=e.left<=s.lastRight+28;t&&r?(s.elements.push(e.el),s.lastTop=e.top,s.lastRight=Math.max(s.lastRight,e.right),c.push(e.text)):(h(),s={title:"",elements:[e.el],lastTop:e.top,lastRight:e.right},c=[e.text])}),h(),0===i.length)return;const u=(e,t)=>{if(!e)return!1;if(t.has(e))return!0;const r=e.replace(/\s+/g,"");for(const n of Array.from(t)){if(!n)continue;const t=n.replace(/\s+/g,"");if(t===r)return!0;if(n.length>=8&&e.length>=5&&n.includes(e))return!0;if(t.length>=8&&r.length>=5&&t.includes(r))return!0;if(e.length>=10&&n.length>=8&&e.includes(n))return!0;if(r.length>=10&&t.length>=8&&r.includes(t))return!0}return!1};let p=0,f=new Set;const d=Array.from(new Set([...R,...H].map(_).filter(e=>e.length>=8))).sort((e,t)=>t.length-e.length),m=e=>{if(!e||e.length<8)return null;const t=e.replace(/\s+/g,"");for(let r=0;r<i.length;r++){let n="",o="";const l=new Set;for(let s=r;s<i.length&&s<r+20;s++){const r=i[s].title;if(n=n?`${n} ${r}`:r,o=o?`${o}${r.replace(/\s+/g,"")}`:r.replace(/\s+/g,""),l.add(s),n.includes(e)||o.includes(t))return l;if(n.length>=15&&(e.includes(n)||t.includes(o)))return l;if(n.length>e.length+150)break}}return null};for(const e of d){const t=m(e);t&&t.size>0&&(t.forEach(e=>f.add(e)),p=f.size)}if(0===p){const e=(e=>{if(0===e.length)return null;let t=null;for(const r of e)for(const e of Array.from(r)){if(!e||e.length<5)continue;const r=e.replace(/\s+/g,"");for(let n=0;n<i.length;n++){let o="",l="";const s=new Set;for(let c=n;c<i.length&&c<n+15;c++){const n=i[c].title;if(o=o?`${o} ${n}`:n,l=l?`${l}${n.replace(/\s+/g,"")}`:n.replace(/\s+/g,""),s.add(c),o.includes(e)||l.includes(r)){const r=Math.max(0,o.length-e.length);(!t||r<t.extra)&&(t={blocks:new Set(s),extra:r});break}if(o.length>e.length+120)break}}}return t?t.blocks:null})(n);e&&e.size>0&&(e.forEach(e=>f.add(e)),p=f.size)}const x=(e=>{if(e.length<2)return 40;const t=[];for(let r=1;r<e.length;r++){const n=Math.abs(e[r].lastTop-e[r-1].lastTop);n>0&&t.push(n)}if(0===t.length)return 40;t.sort((e,t)=>e-t);const r=t[Math.floor(t.length/2)],n=Math.round(2.25*r);return Math.min(60,Math.max(24,n))})(i),v=H.map(_).filter(e=>e.length>=8),T=v.map(e=>e.split(/\s+/).filter(e=>e.length>=2));if(0===p){const e=o;for(let t=0;t<i.length;t++){const r=i[t].title;for(let n=0;n<e.length;n++){if(!u(r,e[n]))continue;let o=0;const l=new Set;let s=n,c=t-1;for(let r=t;r<i.length&&s<e.length;r++){if(u(i[r].title,e[s])){if(c>=0){const e=i[c].lastTop,t=i[r].lastTop;if(Math.abs(t-e)>x)break}o++,l.add(r),c=r,s++}else if(s>0&&u(i[r].title,e[s-1])){const e=i[c].lastTop,t=i[r].lastTop;Math.abs(t-e)<=3&&(l.add(r),c=r)}if(r-c>6)break}o>p&&(p=o,f=l)}}}if(p<Math.min(3,v.length)&&v.length>0){const e=new Set;i.forEach((t,r)=>{const n=t.title.split(/\s+/).filter(e=>e.length>=2);if(n.length<2)return;const o=new Set(n);for(const t of T){if(t.length<2)continue;let n=0;for(const e of t)o.has(e)&&n++;const l=n/t.length;if(n>=3||l>=.5){e.add(r);break}}}),e.size>0&&(f=e,p=Math.max(p,e.size))}const y=new Set;if(F.forEach(e=>{const t=_(e);t&&(y.add(t),y.add(t.replace(/\s+/g,"")))}),0===p){const e=new Set;if(i.forEach((t,r)=>{const n=t.title.replace(/\s+/g,"");if(y.has(t.title)||y.has(n))return void e.add(r);const o=Array.from(y);for(let n=0;n<o.length;n++){const l=o[n];if(l.length>=10&&l.includes(t.title)&&t.title.length>=5){e.add(r);break}}}),0===e.size)return 0;f=e}i.forEach((e,t)=>{const r=f.has(t);e.elements.forEach(e=>{r?(e.classList.add("verified-match"),e.style.display=""):(e.style.display="none",e.classList.remove("verified-match"))})});const b=[];return i.forEach((e,t)=>{f.has(t)&&e.elements.forEach(e=>b.push(e))}),requestAnimationFrame(()=>{const e=b.map(e=>({el:e,rect:e.getBoundingClientRect()})).filter(e=>e.rect.width>0&&e.rect.height>0).sort((e,t)=>t.rect.width*t.rect.height-e.rect.width*e.rect.height),t=[];e.forEach(({el:e,rect:r})=>{t.some(e=>((e,t)=>{const r=Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top)),n=Math.min(e.width*e.height,t.width*t.height);return n>0?r/n:0})(e.rect,r)>.5)?(e.style.display="none",e.classList.remove("verified-match")):t.push({el:e,rect:r})})}),console.groupCollapsed(`[debug: PDF ordered matching - Page ${e}]`),console.log("input->",a),console.log("processed sentences->",R),console.log("processed lines->",H),console.log("Expected sentence count:",n.length),console.log("Expected line count:",o.length),console.log("Matched sequence length:",p),console.log("blocksToKeep",f,"size",f.size),console.groupEnd(),f.size},C=e=>{if(!g.current)return;g.current.querySelectorAll(".rpv-search__highlights").forEach(t=>{const r=t.getAttribute("data-testid"),n=parseInt(r?.replace(/search__highlights-/g,"")||"-1"),o=t.querySelectorAll(".rpv-search__highlight");e.has(n)||o.forEach(e=>{e.style.display="none"})})},q=a.map(e=>(e=>e?$(e).split(/\n{2,}/).map(e=>A(e).join(" ")).map(e=>M(e)).filter(Boolean):[])(e)).flat(),B=a.map(e=>A(e)).flat(),j=q.some(e=>e.length>=3)?3:1,R=q.filter(e=>e.length>=j),H=B.filter(e=>e.length>=j),N=H.flatMap(e=>((e,t=6,r=4)=>{const n=e.split(/\s+/).filter(Boolean);if(n.length<=t)return[];const o=[];for(let e=0;e+t<=n.length;e+=r)o.push(n.slice(e,e+t).join(" "));return n.length>t&&(n.length-t)%r!==0&&o.push(n.slice(n.length-t).join(" ")),o})(e)),F=Array.from(new Set([...R,...H,...N].flatMap(e=>{const t=M(e.replace(/[\u00A0\u2009\u202F]/g," ").replace(/\u00ad/g,"").replace(/[""]/g,'"').replace(/['']/g,"'"));if(!t)return[];const r=t.replace(/[\u2013\u2014]/g,"-"),n=M(r.replace(/(\w)-\s+(\w)/g,"$1$2")),o=M(r.replace(/-/g," ")),l=M(r.replace(/-/g,"")),i=M(t.replace(/[^\w\s]/g,"")),s=new Set([t,r,n,o,l,i]);return Array.from(s).filter(Boolean)}))).filter(e=>{const t=e.split(/\s+/).filter(Boolean);return!(e.length<j)&&(t.length>=3||e.length>=12)}),P=l({keyword:F}),L=i(),O=s(),{jumpToMatch:Z}=P,{jumpToPage:D}=L,{zoomTo:W,CurrentScale:K,ZoomPopover:J}=O,V=o(()=>(e=>{if(0===e.length)return[];const t=new Map;e.forEach((e,r)=>{const n=null!=e.pageNumber?e.pageNumber-1:e.pageIndex;t.has(n)||t.set(n,[]),t.get(n).push({...e,originalIndex:r})});const r=[];return t.forEach(e=>{const t=[...e].sort((e,t)=>e.top!==t.top?e.top-t.top:e.left-t.left),n=new Array(t.length).fill(!1);for(let e=0;e<t.length;e++){if(n[e])continue;let{left:o,top:l,width:i,height:s,pageIndex:c,pageNumber:a}=t[e],h=o+i,g=l+s;const u=[t[e].originalIndex];n[e]=!0;let p=!0;for(;p;){p=!1;for(let r=e+1;r<t.length;r++){if(n[r])continue;const e=t[r],c=e.left+e.width,a=e.top+e.height,f=Math.max(0,Math.min(h,c)-Math.max(o,e.left))*Math.max(0,Math.min(g,a)-Math.max(l,e.top)),d=Math.max(i*s,1e-4),m=Math.max(e.width*e.height,1e-4),x=Math.min(d,m);(x>0?f/x:0)>=.8&&(o=Math.min(o,e.left),l=Math.min(l,e.top),h=Math.max(h,c),g=Math.max(g,a),i=h-o,s=g-l,u.push(e.originalIndex),n[r]=!0,p=!0)}}r.push({pageIndex:c,pageNumber:a,left:o,top:l,width:i,height:s,originalIndexes:u})}}),r})(f),[f]),G=c({renderHighlights:r=>e(t,{children:V.filter(e=>null!=e.pageNumber?e.pageNumber-1===r.pageIndex:e.pageIndex===r.pageIndex).map(t=>{const r=t.originalIndexes.includes(y);return e("div",{style:{position:"absolute",left:`${t.left}%`,top:`${t.top+.08*t.height}%`,width:`${t.width}%`,height:.95*t.height+"%",background:r?m:d,opacity:r?.7:.4,transition:"background 0.2s, opacity 0.2s",border:r?"1px solid red":"1px solid transparent"}},t.originalIndexes.join("-"))})})}),Q=()=>{if(!T.current)try{Z(0),T.current=!0;const e=f[0];e&&p&&X(e.pageIndex,e.top)}catch{requestAnimationFrame(Q)}},U=(e,t)=>{if(!g.current)return;if(!g.current.querySelector(".rpv-core__viewer"))return;let r=-1;const n=()=>{const o=g.current?.querySelector(".rpv-core__inner-pages");if(!o)return;if(o.scrollTop!==r)return r=o.scrollTop,void setTimeout(n,100);const l=g.current?.querySelector(`[data-testid="core__page-layer-${e}"]`);if(!l)return;const i=l.querySelectorAll(".rpv-search__highlight")[t];if(!i)return;const s=o.getBoundingClientRect(),c=i.getBoundingClientRect(),a=o.scrollTop+(c.top-s.top)-o.clientHeight/2+c.height/2;o.scrollTo({top:a,behavior:"smooth"})};setTimeout(n,300)},X=(e,t,r=0)=>{if(!g.current)return;w.current+=1;let n=0;const o=()=>{if(++n>60)return;const l=g.current?.querySelector(".rpv-core__inner-pages");if(!l)return void setTimeout(o,100);const i=g.current?.querySelector(`[data-testid="core__page-layer-${e}"]`);if(!i)return void setTimeout(o,100);const s=i.getBoundingClientRect();if(0===s.height)return void setTimeout(o,100);const c=l.getBoundingClientRect(),a=t/100*s.height,h=r/100*s.height,u=s.top-c.top+a,p=u+h;if(u>=80&&p<=l.clientHeight-80)return;const f=u<80?l.scrollTop+u-80:l.scrollTop+p-l.clientHeight+80;l.scrollTo({top:f,behavior:"smooth"})};setTimeout(o,100)},Y=o(()=>{const e={};return E.forEach((t,r)=>{const n=h[t];n>0&&(e[n]||(e[n]=[]),e[n].push(r))}),e},[E,h]),ee=e=>{const t=h[E[e]];return(Y[t]||[]).indexOf(e)},te=(e,t,r=0)=>{if(!g.current)return;const n=++w.current;let o=null,l=0,i=0;const s=()=>{if(w.current!==n)return;if(++i>60)return;const c=g.current?.querySelector(".rpv-core__inner-pages");if(!c)return void setTimeout(s,100);const a=g.current?.querySelector(`[data-testid="core__page-layer-${e}"]`);if(!a)return void setTimeout(s,100);const h=a.getBoundingClientRect();if(0===h.height)return void setTimeout(s,100);const u=c.getBoundingClientRect(),p=h.bottom>u.top&&h.top<u.bottom;if(o===c.scrollTop?l+=1:(o=c.scrollTop,l=0),!p||l<2)return void setTimeout(s,100);const f=t/100*h.height,d=r/100*h.height,m=h.top-u.top+f+d/2,x=c.scrollTop+m-c.clientHeight/2;c.scrollTo({top:x,behavior:"smooth"})};setTimeout(s,100)};return{setHighlightIndex:v,highlightIndex:x,cursorIndex:y,setCursorIndex:b,orderedKeys:E,totalHighlights:k,getValidPosition:e=>{if(p)return e+1;if(!h)return 0;let t=0;for(let r=0;r<=e;r++)h[E[r]]>0&&t++;return t},tryJump:Q,jumpToPage:D,zoomTo:W,hideNonTargetHighlights:C,deduplicateHighlights:z,scrollToCoord:X,scrollToCoordAfterNav:te,plugins:[p?G:P,L,O],controls:{CurrentScale:K,ZoomPopover:J,zoomTo:W,goToNext:()=>{if(p&&f)for(let e=y+1;e<f.length;e++){const t=f[e],r=f[y];return b(e),void(t.pageIndex!==r.pageIndex?(D(t.pageIndex),te(t.pageIndex,t.top,t.height)):X(t.pageIndex,t.top,t.height))}else{for(let e=y+1;e<E.length;e++){const t=E[e];if(h[t]>0){const r=h[t]-1,n=ee(e);return b(e),D(h[t]-1),U(r,n),setTimeout(()=>{z(r)},500),void(1===Object.keys(h).length&&C(u))}}}},goToPrevious:()=>{if(p&&f)for(let e=y-1;e>=0;e--){const t=f[e],r=f[y];return b(e),void(t.pageIndex!==r.pageIndex?(D(t.pageIndex),te(t.pageIndex,t.top,t.height)):X(t.pageIndex,t.top,t.height))}else{for(let e=y-1;e>=0;e--){const t=E[e];if(h[t]>0){const r=h[t]-1,n=ee(e);return b(e),D(h[t]-1),U(r,n),setTimeout(()=>{z(r)},500),void(1===Object.keys(h).length&&C(u))}}}}}}};export{a as PdfHighlightControls};
|
|
2
2
|
//# sourceMappingURL=usePdfHighlight.js.map
|