@e-llm-studio/citation 0.0.154 → 0.0.156
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/README.md +93 -0
- package/dist/cjs/features/PdfViewer/usePdfHighlight.js +1 -1
- package/dist/cjs/features/ScannedDocCitation/ScannedDocCitation.js +1 -1
- package/dist/features/PdfViewer/usePdfHighlight.js +1 -1
- package/dist/features/ScannedDocCitation/ScannedDocCitation.js +1 -1
- package/dist/types/src/features/PdfViewer/usePdfHighlight.d.ts.map +1 -1
- package/dist/types/src/features/ScannedDocCitation/ScannedDocCitation.d.ts +26 -3
- package/dist/types/src/features/ScannedDocCitation/ScannedDocCitation.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -994,6 +994,8 @@ ScannedDocCitation is a React component for displaying scanned document pages wi
|
|
|
994
994
|
- **Fullscreen modal** — Expand to a larger view for detailed examination
|
|
995
995
|
- **Customizable highlight colors** — Control highlight color, active color, and border color
|
|
996
996
|
- **Lazy highlight rendering** — Highlights only appear after the image has fully loaded, preventing bounding boxes from showing on blank pages
|
|
997
|
+
- **Pass citationPage** - You can now pass citationPage instead of passing images and highlights as seprate
|
|
998
|
+
- **Control citation label** - You can now use citation lable and control it behaviour by props
|
|
997
999
|
|
|
998
1000
|
### Usage
|
|
999
1001
|
```tsx
|
|
@@ -1047,6 +1049,69 @@ const highlights = BACKEND_CITATIONS.flatMap((c) =>
|
|
|
1047
1049
|
height="700px"
|
|
1048
1050
|
/>
|
|
1049
1051
|
```
|
|
1052
|
+
### New usage based on pages prop :
|
|
1053
|
+
```tsx
|
|
1054
|
+
import ScannedDocCitation from "./features/ScannedDocCitation/ScannedDocCitation";
|
|
1055
|
+
|
|
1056
|
+
const BACKEND_CITATIONS = [
|
|
1057
|
+
{
|
|
1058
|
+
agent_name: "ContextFileAgent",
|
|
1059
|
+
title: "ECG_Brainstorming_Integration.pdf",
|
|
1060
|
+
url: "https://storage.googleapis.com/...png",
|
|
1061
|
+
description: "",
|
|
1062
|
+
metadata: {},
|
|
1063
|
+
citation_number: 1,
|
|
1064
|
+
filter: false,
|
|
1065
|
+
artifact_id: "019cfac1-e92e-792b-bdea-960e954d6912",
|
|
1066
|
+
customMetaData: {
|
|
1067
|
+
citation_number: 1,
|
|
1068
|
+
value: [
|
|
1069
|
+
{
|
|
1070
|
+
gs_url: "https://storage.googleapis.com/...png",
|
|
1071
|
+
page_no: 1,
|
|
1072
|
+
dimensions: { unit: "pixels", width: 1241, height: 1754 },
|
|
1073
|
+
highlighted_coordinates: [
|
|
1074
|
+
{ xmin: 0.5246, ymin: 0.5547, xmax: 0.6567, ymax: 0.5678 },
|
|
1075
|
+
],
|
|
1076
|
+
highlighted_text: [
|
|
1077
|
+
{
|
|
1078
|
+
text: "stormee x eCG",
|
|
1079
|
+
excerpt_from_document: "...",
|
|
1080
|
+
page_no: 1,
|
|
1081
|
+
reasoning: ["..."],
|
|
1082
|
+
gap: ["..."],
|
|
1083
|
+
score: 50,
|
|
1084
|
+
},
|
|
1085
|
+
],
|
|
1086
|
+
},
|
|
1087
|
+
],
|
|
1088
|
+
},
|
|
1089
|
+
},
|
|
1090
|
+
];
|
|
1091
|
+
|
|
1092
|
+
// Flatten all citation pages
|
|
1093
|
+
const allPages = BACKEND_CITATIONS.flatMap(
|
|
1094
|
+
(c) => c?.customMetaData?.value || []
|
|
1095
|
+
);
|
|
1096
|
+
|
|
1097
|
+
export default function ScannedDocCitationTest() {
|
|
1098
|
+
return (
|
|
1099
|
+
<div style={{ padding: 16, maxWidth: 720 }}>
|
|
1100
|
+
<h3
|
|
1101
|
+
style={{
|
|
1102
|
+
fontFamily: "Plus Jakarta Sans, sans-serif",
|
|
1103
|
+
marginBottom: 12,
|
|
1104
|
+
}}
|
|
1105
|
+
>
|
|
1106
|
+
Scanned Doc Citation Test
|
|
1107
|
+
</h3>
|
|
1108
|
+
|
|
1109
|
+
<ScannedDocCitation pages={allPages} />
|
|
1110
|
+
</div>
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
```
|
|
1114
|
+
|
|
1050
1115
|
|
|
1051
1116
|
**With custom highlight colors:**
|
|
1052
1117
|
```tsx
|
|
@@ -1080,9 +1145,12 @@ return <ScannedDocCitation images={images} highlights={highlights} />;
|
|
|
1080
1145
|
|
|
1081
1146
|
| Prop | Type | Required | Default | Description |
|
|
1082
1147
|
|------|------|----------|---------|-------------|
|
|
1148
|
+
| `pages` | `CitationPage[]` | ✅ | — | Ordered array of `CitationPage` objects containing:<br>• `gs_url`: `string`<br>• `page_no?`: `number`<br>• `highlighted_coordinates?`: `BBox[]`<br>• `dimensions?`: `Dimensions`<br>• `highlighted_text?`: `HighlightedText[]` |
|
|
1083
1149
|
| `images` | `string[]` | ✅ | — | Array of pre-signed GCS image URLs, one per page |
|
|
1084
1150
|
| `highlights` | `PageHighlight[]` | ✅ | — | Array of highlight groups with bounding boxes per page |
|
|
1085
1151
|
| `highlightColor` | `string` | ❌ | `rgba(255, 220, 0, 0.15)` | Background color of inactive highlights |
|
|
1152
|
+
| `citationLabelColor` | `string` | ❌ | `#FFFF2E` | Background color of the citation label. |
|
|
1153
|
+
| `showCitationLabelOnHover` | `boolean` | ❌ | `true` | Show label only on hover (if `false` → always visible). |
|
|
1086
1154
|
| `highlightActiveColor` | `string` | ❌ | `rgba(255, 220, 0, 0.35)` | Background color of the currently active highlight |
|
|
1087
1155
|
| `highlightBorderColor` | `string` | ❌ | `rgba(200, 160, 0, 0.4)` | Border color of the active highlight |
|
|
1088
1156
|
| `height` | `string \| number` | ❌ | `"700px"` | Maximum height of the scrollable container. Shrinks to fit content if content is shorter. |
|
|
@@ -1100,10 +1168,35 @@ interface PageHighlight {
|
|
|
1100
1168
|
pageIndex: number; // zero-based index matching the images array
|
|
1101
1169
|
bboxes: BBox[];
|
|
1102
1170
|
}
|
|
1171
|
+
export interface Dimensions {
|
|
1172
|
+
unit: string;
|
|
1173
|
+
width: number;
|
|
1174
|
+
height: number;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
export interface HighlightedText {
|
|
1178
|
+
text: string;
|
|
1179
|
+
excerpt_from_document: string;
|
|
1180
|
+
page_no: number;
|
|
1181
|
+
reasoning: string[];
|
|
1182
|
+
gap: string[];
|
|
1183
|
+
score: number;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
export interface CitationPage {
|
|
1187
|
+
gs_url: string;
|
|
1188
|
+
page_no?: number;
|
|
1189
|
+
highlighted_coordinates?: BBox[];
|
|
1190
|
+
dimensions?: Dimensions;
|
|
1191
|
+
highlighted_text?: HighlightedText[];
|
|
1192
|
+
}
|
|
1103
1193
|
|
|
1104
1194
|
interface ScannedDocCitationProps {
|
|
1105
1195
|
images: string[];
|
|
1106
1196
|
highlights: PageHighlight[];
|
|
1197
|
+
pages?: CitationPage[];
|
|
1198
|
+
citationLabelColor?: string;
|
|
1199
|
+
showCitationLabelOnHover?: boolean;
|
|
1107
1200
|
highlightColor?: string;
|
|
1108
1201
|
highlightActiveColor?: string;
|
|
1109
1202
|
highlightBorderColor?: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@react-pdf-viewer/search"),t=require("@react-pdf-viewer/page-navigation"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@react-pdf-viewer/search"),t=require("@react-pdf-viewer/page-navigation"),n=require("@react-pdf-viewer/zoom");exports.PdfHighlightControls=function(o,i,u){var a=e.useState(0),c=a[0],l=a[1],s=e.useRef(!1),g=e.useState(0),f=g[0],p=g[1],v=function(e){if(!e)return[];var r=new Set(["the","is","and","of","in","to","for","on","at","by","with","as","an","a","or","if","be","are","was"]);return e.replace(/\]\s*\n\s*\(/g,"](").split(/\n+/).map(function(e){var r=e.trim(),t=(r=r.replace(/^[-•]\s+/,"")).match(/^((\d+(\.\d+)*[.)])|([a-zA-Z][.)])|(\([a-zA-Z0-9]+\))|((i|ii|iii|iv|v|vi|vii|viii|ix|x)[.)]))\s+/i);return t?r.slice(t[0].length).trim():r}).flatMap(function(e){var r=e.match(/^\s*\|(.+)\|\s*$/);return r?r[1].split("|").map(function(e){return e.trim()}).filter(Boolean):[e]}).map(function(e){return e.replace(/&[#\w]+;/g,function(e){return r=e,(t=document.createElement("textarea")).innerHTML=r,t.value;var r,t}).replace(/<br\s*\/?>/gi,"\n").replace(/\[([^\]]+)\]\(([^)]+)\)/g,"$1").replace(/[\u201C\u201D]/g,'"').replace(/[\u2013\u2014]/g,"-").replace(/[.,;:!\u201C\u201D]+$/,"").replace(/"$/,"").replace(/^[.,;:!\u201C\u201D]+/,"").replace(/[*_]{1,3}([^*_]+)[*_]{1,3}/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/\s+/g," ").trim()}).filter(function(e){return e.toLowerCase().split(/\s+/).filter(function(e){return!r.has(e)&&e.length>2}).join(" ").length>=13})},h=Object.keys(i).map(Number).sort(function(e,r){return e-r}),d=Object.values(i).filter(function(e){return e>0}).length,m=function(e){u.current&&u.current.querySelectorAll(".rpv-search__highlights").forEach(function(r){var t=r.getAttribute("data-testid"),n=parseInt((null==t?void 0:t.replace("search__highlights-",""))||"-1");r.querySelectorAll(".rpv-search__highlight").forEach(function(r){r.style.display=n===e?"":"none"})})},_=o.map(function(e){return v(e)}).flat(),y=r.searchPlugin({keyword:_}),T=t.pageNavigationPlugin(),b=n.zoomPlugin(),q=y.jumpToMatch,x=T.jumpToPage,P=b.zoomTo,w=b.ZoomInButton,j=b.ZoomOutButton,S=b.ZoomPopover,C=function(){if(!s.current)try{q(0),s.current=!0}catch(e){requestAnimationFrame(C)}},O=function(e,r){if(u.current&&u.current.querySelector(".rpv-core__viewer")){var t=-1,n=function(){var o,i,a=null===(o=u.current)||void 0===o?void 0:o.querySelector(".rpv-core__inner-pages");if(a){if(a.scrollTop!==t)return t=a.scrollTop,void setTimeout(n,100);var c=null===(i=u.current)||void 0===i?void 0:i.querySelector('[data-testid="core__page-layer-'.concat(e,'"]'));if(c){var l=c.querySelectorAll(".rpv-search__highlight")[r];if(l){var s=a.getBoundingClientRect(),g=l.getBoundingClientRect(),f=a.scrollTop+(g.top-s.top)-a.clientHeight/2+g.height/2;a.scrollTo({top:f,behavior:"smooth"})}}}};setTimeout(n,300)}},Z=e.useMemo(function(){var e={};return h.forEach(function(r,t){var n=i[r];n>0&&(e[n]||(e[n]=[]),e[n].push(t))}),e},[h,i]),A=function(e){var r=i[h[e]];return(Z[r]||[]).indexOf(e)};return{setHighlightIndex:l,highlightIndex:c,cursorIndex:f,setCursorIndex:p,orderedKeys:h,totalHighlights:d,getValidPosition:function(e){for(var r=0,t=0;t<=e;t++){var n=h[t];i[n]>0&&r++}return r},tryJump:C,jumpToPage:x,zoomTo:P,hideNonTargetHighlights:m,plugins:[y,T,b],controls:{ZoomInButton:w,ZoomOutButton:j,ZoomPopover:S,goToNext:function(){for(var e=f+1;e<h.length;e++){var r=h[e];if(i[r]>0){var t=i[r]-1,n=A(e);return p(e),x(i[r]-1),O(t,n),void(1===Object.keys(i).length&&m(t))}}},goToPrevious:function(){for(var e=f-1;e>=0;e--){var r=h[e];if(i[r]>0){var t=i[r]-1,n=A(e);return p(e),x(i[r]-1),O(t,n),void(1===Object.keys(i).length&&m(t))}}}}}};
|
|
2
2
|
//# sourceMappingURL=usePdfHighlight.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),i=require("react"),t=require("lucide-react"),o=require("../ChatCitation/components/wrappers/Modal.js");exports.default=function(r){var s=r.images,a=r.highlights,l=r.pages,d=r.citationLabelColor,c=void 0===d?"#FFFF2E":d,u=r.showCitationLabelOnHover,p=void 0!==u&&u,x=r.highlightColor,g=void 0===x?"rgba(255, 220, 0, 0.15)":x,h=r.highlightActiveColor,f=void 0===h?"rgba(255, 220, 0, 0.35)":h,b=r.highlightBorderColor,_=void 0===b?"rgba(200, 160, 0, 0.4)":b,v=r.height,m=void 0===v?"700px":v,y=[],j=[];(null==l?void 0:l.length)?l.forEach(function(e,n){var i;e.gs_url&&y.push(e.gs_url),null===(i=e.highlighted_coordinates)||void 0===i||i.forEach(function(e){j.push({pageIndex:n,bboxes:[e]})})}):(y.push.apply(y,s||[]),j.push.apply(j,a||[]));var C=j.flatMap(function(e,n){return e.bboxes.map(function(i,t){return{bbox:i,pageIndex:e.pageIndex,key:"".concat(n,"-").concat(t)}})}).length,k=i.useState(null),w=k[0],I=k[1],R=i.useState(0),z=R[0],M=R[1],S=i.useState(!1),F=S[0],B=S[1],q=i.useState({}),L=q[0],D=q[1],E=i.useRef(null),H=i.useRef(null),O=i.useRef([]),P=i.useRef([]),T=i.useCallback(function(e,n){void 0===n&&(n=!1);var i=Math.max(0,Math.min(C-1,e));M(i),requestAnimationFrame(function(){var e=n?H.current:E.current,t=(n?P:O).current[i];if(e&&t){var o=e.getBoundingClientRect(),r=t.getBoundingClientRect(),s=r.top-o.top+e.scrollTop-e.clientHeight/2+r.height/2;e.scrollTo({top:s,behavior:"smooth"})}})},[C]),A=function(i){return void 0===i&&(i=!1),C>0&&n.jsx("div",e.__assign({style:{display:"flex",alignItems:"center",marginBottom:"6px"}},{children:n.jsxs("div",e.__assign({style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:"4px"}},{children:[n.jsxs("span",e.__assign({style:{fontSize:"12px",color:"#888"}},{children:[z+1," / ",C]})),n.jsx("button",e.__assign({onClick:function(){return T(z-1,i)},disabled:z<=0,style:{padding:"2px 4px",cursor:z<=0?"not-allowed":"pointer",opacity:z<=0?.4:1,border:"1px solid #ddd",borderRadius:"3px",background:"white",display:"flex",alignItems:"center"}},{children:n.jsx(t.ChevronUp,{size:14,color:"#64748b"})})),n.jsx("button",e.__assign({onClick:function(){return T(z+1,i)},disabled:z>=C-1,style:{padding:"2px 4px",cursor:z>=C-1?"not-allowed":"pointer",opacity:z>=C-1?.4:1,border:"1px solid #ddd",borderRadius:"3px",background:"white",display:"flex",alignItems:"center"}},{children:n.jsx(t.ChevronDown,{size:14,color:"#64748b"})})),n.jsx("span",{style:{width:"1px",height:"16px",background:"#e2e8f0",margin:"0 2px"}}),i?n.jsx(t.X,{size:16,color:"#64748b",style:{cursor:"pointer"},onClick:function(){return B(!1)}}):n.jsx(t.Maximize2,{size:16,color:"#64748b",style:{cursor:"pointer"},onClick:function(){return B(!0)}})]}))}))},U=function(i){void 0===i&&(i=!1);var t=i?P:O,o=-1;return y.map(function(i,r){var s=j.filter(function(e){return e.pageIndex===r}).flatMap(function(e,n){return e.bboxes.map(function(e,i){return o++,{bbox:e,key:"".concat(r,"-").concat(n,"-").concat(i),globalIndex:o}})});return n.jsxs("div",e.__assign({style:{marginBottom:"8px"}},{children:[n.jsxs("div",e.__assign({style:{fontSize:"12px",color:"#888",marginBottom:"4px"}},{children:["Page ",r+1]})),n.jsx("div",e.__assign({style:{position:"relative",width:"100%",paddingTop:"129%",flexShrink:0}},{children:n.jsxs("div",e.__assign({style:{position:"absolute",inset:0}},{children:[n.jsx("img",{src:i,alt:"Page ".concat(r+1),style:{display:"block",width:"100%",height:"100%",objectFit:"fill"},draggable:!1,ref:function(n){n&&n.complete&&!L[r]&&D(function(n){var i;return e.__assign(e.__assign({},n),((i={})[r]=!0,i))})},onLoad:function(){return D(function(n){var i;return e.__assign(e.__assign({},n),((i={})[r]=!0,i))})}}),L[r]&&s.map(function(i){var o=i.bbox,r=i.key,s=i.globalIndex,a=z===s;return n.jsx("div",e.__assign({ref:function(e){t.current[s]=e},onMouseEnter:function(){return I(s)},onMouseLeave:function(){return I(null)},style:{position:"absolute",left:"".concat(100*o.xmin,"%"),top:"".concat(100*o.ymin,"%"),width:"".concat(100*(o.xmax-o.xmin),"%"),height:"".concat(100*(o.ymax-o.ymin),"%"),background:a?f:g,border:a?"1.5px solid ".concat(_):"none",borderRadius:"2px",zIndex:2}},{children:p&&w===s&&n.jsxs("div",e.__assign({style:{position:"absolute",top:"-18px",right:"0",fontSize:"10px",background:c,color:"black",padding:"2px 6px",borderRadius:"3px",whiteSpace:"nowrap"}},{children:["Citation ",s+1]}))}),r)})]}))}))]}),r)})},W={overflowY:"auto",border:"1px solid #ddd",borderRadius:"4px",padding:"8px",paddingBottom:0,display:"flex",flexDirection:"column",boxSizing:"border-box"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",e.__assign({style:{width:"100%",maxWidth:"800px",fontFamily:"inherit",display:"flex",flexDirection:"column"}},{children:[A(!1),n.jsx("div",e.__assign({ref:E,style:e.__assign(e.__assign({},W),{maxHeight:m})},{children:U(!1)}))]})),n.jsx(o.Modal,e.__assign({isOpen:F,onClose:function(){return B(!1)}},{children:n.jsxs("div",e.__assign({style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"}},{children:[A(!0),n.jsx("div",e.__assign({ref:H,style:e.__assign(e.__assign({},W),{flex:1})},{children:F&&U(!0)}))]}))}))]})};
|
|
2
2
|
//# sourceMappingURL=ScannedDocCitation.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as r,useRef as e,useMemo as t}from"react";import{searchPlugin as o}from"@react-pdf-viewer/search";import{pageNavigationPlugin as
|
|
1
|
+
import{useState as r,useRef as e,useMemo as t}from"react";import{searchPlugin as o}from"@react-pdf-viewer/search";import{pageNavigationPlugin as n}from"@react-pdf-viewer/page-navigation";import{zoomPlugin as i}from"@react-pdf-viewer/zoom";var a=function(a,u,c){var l=r(0),f=l[0],s=l[1],p=e(!1),v=r(0),g=v[0],h=v[1],m=function(r){if(!r)return[];var e=new Set(["the","is","and","of","in","to","for","on","at","by","with","as","an","a","or","if","be","are","was"]);return r.replace(/\]\s*\n\s*\(/g,"](").split(/\n+/).map(function(r){var e=r.trim(),t=(e=e.replace(/^[-•]\s+/,"")).match(/^((\d+(\.\d+)*[.)])|([a-zA-Z][.)])|(\([a-zA-Z0-9]+\))|((i|ii|iii|iv|v|vi|vii|viii|ix|x)[.)]))\s+/i);return t?e.slice(t[0].length).trim():e}).flatMap(function(r){var e=r.match(/^\s*\|(.+)\|\s*$/);return e?e[1].split("|").map(function(r){return r.trim()}).filter(Boolean):[r]}).map(function(r){return r.replace(/&[#\w]+;/g,function(r){return e=r,(t=document.createElement("textarea")).innerHTML=e,t.value;var e,t}).replace(/<br\s*\/?>/gi,"\n").replace(/\[([^\]]+)\]\(([^)]+)\)/g,"$1").replace(/[\u201C\u201D]/g,'"').replace(/[\u2013\u2014]/g,"-").replace(/[.,;:!\u201C\u201D]+$/,"").replace(/"$/,"").replace(/^[.,;:!\u201C\u201D]+/,"").replace(/[*_]{1,3}([^*_]+)[*_]{1,3}/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/\s+/g," ").trim()}).filter(function(r){return r.toLowerCase().split(/\s+/).filter(function(r){return!e.has(r)&&r.length>2}).join(" ").length>=13})},d=Object.keys(u).map(Number).sort(function(r,e){return r-e}),y=Object.values(u).filter(function(r){return r>0}).length,_=function(r){c.current&&c.current.querySelectorAll(".rpv-search__highlights").forEach(function(e){var t=e.getAttribute("data-testid"),o=parseInt((null==t?void 0:t.replace("search__highlights-",""))||"-1");e.querySelectorAll(".rpv-search__highlight").forEach(function(e){e.style.display=o===r?"":"none"})})},T=a.map(function(r){return m(r)}).flat(),b=o({keyword:T}),w=n(),x=i(),j=b.jumpToMatch,Z=w.jumpToPage,q=x.zoomTo,A=x.ZoomInButton,B=x.ZoomOutButton,C=x.ZoomPopover,I=function(){if(!p.current)try{j(0),p.current=!0}catch(r){requestAnimationFrame(I)}},O=function(r,e){if(c.current&&c.current.querySelector(".rpv-core__viewer")){var t=-1,o=function(){var n,i,a=null===(n=c.current)||void 0===n?void 0:n.querySelector(".rpv-core__inner-pages");if(a){if(a.scrollTop!==t)return t=a.scrollTop,void setTimeout(o,100);var u=null===(i=c.current)||void 0===i?void 0:i.querySelector('[data-testid="core__page-layer-'.concat(r,'"]'));if(u){var l=u.querySelectorAll(".rpv-search__highlight")[e];if(l){var f=a.getBoundingClientRect(),s=l.getBoundingClientRect(),p=a.scrollTop+(s.top-f.top)-a.clientHeight/2+s.height/2;a.scrollTo({top:p,behavior:"smooth"})}}}};setTimeout(o,300)}},S=t(function(){var r={};return d.forEach(function(e,t){var o=u[e];o>0&&(r[o]||(r[o]=[]),r[o].push(t))}),r},[d,u]),P=function(r){var e=u[d[r]];return(S[e]||[]).indexOf(r)};return{setHighlightIndex:s,highlightIndex:f,cursorIndex:g,setCursorIndex:h,orderedKeys:d,totalHighlights:y,getValidPosition:function(r){for(var e=0,t=0;t<=r;t++){var o=d[t];u[o]>0&&e++}return e},tryJump:I,jumpToPage:Z,zoomTo:q,hideNonTargetHighlights:_,plugins:[b,w,x],controls:{ZoomInButton:A,ZoomOutButton:B,ZoomPopover:C,goToNext:function(){for(var r=g+1;r<d.length;r++){var e=d[r];if(u[e]>0){var t=u[e]-1,o=P(r);return h(r),Z(u[e]-1),O(t,o),void(1===Object.keys(u).length&&_(t))}}},goToPrevious:function(){for(var r=g-1;r>=0;r--){var e=d[r];if(u[e]>0){var t=u[e]-1,o=P(r);return h(r),Z(u[e]-1),O(t,o),void(1===Object.keys(u).length&&_(t))}}}}}};export{a as PdfHighlightControls};
|
|
2
2
|
//# sourceMappingURL=usePdfHighlight.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as
|
|
1
|
+
import{__assign as n}from"tslib";import{jsxs as o,Fragment as i,jsx as e}from"react/jsx-runtime";import{useState as t,useRef as r,useCallback as l}from"react";import{ChevronUp as a,ChevronDown as d,X as c,Maximize2 as p}from"lucide-react";import{Modal as u}from"../ChatCitation/components/wrappers/Modal.js";function s(s){var h=s.images,x=s.highlights,g=s.pages,f=s.citationLabelColor,b=void 0===f?"#FFFF2E":f,m=s.showCitationLabelOnHover,v=void 0!==m&&m,y=s.highlightColor,k=void 0===y?"rgba(255, 220, 0, 0.15)":y,w=s.highlightActiveColor,C=void 0===w?"rgba(255, 220, 0, 0.35)":w,I=s.highlightBorderColor,z=void 0===I?"rgba(200, 160, 0, 0.4)":I,B=s.height,F=void 0===B?"700px":B,M=[],R=[];(null==g?void 0:g.length)?g.forEach(function(n,o){var i;n.gs_url&&M.push(n.gs_url),null===(i=n.highlighted_coordinates)||void 0===i||i.forEach(function(n){R.push({pageIndex:o,bboxes:[n]})})}):(M.push.apply(M,h||[]),R.push.apply(R,x||[]));var S=R.flatMap(function(n,o){return n.bboxes.map(function(i,e){return{bbox:i,pageIndex:n.pageIndex,key:"".concat(o,"-").concat(e)}})}).length,L=t(null),E=L[0],j=L[1],D=t(0),H=D[0],T=D[1],_=t(!1),A=_[0],O=_[1],P=t({}),q=P[0],W=P[1],Y=r(null),G=r(null),J=r([]),K=r([]),N=l(function(n,o){void 0===o&&(o=!1);var i=Math.max(0,Math.min(S-1,n));T(i),requestAnimationFrame(function(){var n=o?G.current:Y.current,e=(o?K:J).current[i];if(n&&e){var t=n.getBoundingClientRect(),r=e.getBoundingClientRect(),l=r.top-t.top+n.scrollTop-n.clientHeight/2+r.height/2;n.scrollTo({top:l,behavior:"smooth"})}})},[S]),Q=function(i){return void 0===i&&(i=!1),S>0&&e("div",n({style:{display:"flex",alignItems:"center",marginBottom:"6px"}},{children:o("div",n({style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:"4px"}},{children:[o("span",n({style:{fontSize:"12px",color:"#888"}},{children:[H+1," / ",S]})),e("button",n({onClick:function(){return N(H-1,i)},disabled:H<=0,style:{padding:"2px 4px",cursor:H<=0?"not-allowed":"pointer",opacity:H<=0?.4:1,border:"1px solid #ddd",borderRadius:"3px",background:"white",display:"flex",alignItems:"center"}},{children:e(a,{size:14,color:"#64748b"})})),e("button",n({onClick:function(){return N(H+1,i)},disabled:H>=S-1,style:{padding:"2px 4px",cursor:H>=S-1?"not-allowed":"pointer",opacity:H>=S-1?.4:1,border:"1px solid #ddd",borderRadius:"3px",background:"white",display:"flex",alignItems:"center"}},{children:e(d,{size:14,color:"#64748b"})})),e("span",{style:{width:"1px",height:"16px",background:"#e2e8f0",margin:"0 2px"}}),i?e(c,{size:16,color:"#64748b",style:{cursor:"pointer"},onClick:function(){return O(!1)}}):e(p,{size:16,color:"#64748b",style:{cursor:"pointer"},onClick:function(){return O(!0)}})]}))}))},U=function(i){void 0===i&&(i=!1);var t=i?K:J,r=-1;return M.map(function(i,l){var a=R.filter(function(n){return n.pageIndex===l}).flatMap(function(n,o){return n.bboxes.map(function(n,i){return r++,{bbox:n,key:"".concat(l,"-").concat(o,"-").concat(i),globalIndex:r}})});return o("div",n({style:{marginBottom:"8px"}},{children:[o("div",n({style:{fontSize:"12px",color:"#888",marginBottom:"4px"}},{children:["Page ",l+1]})),e("div",n({style:{position:"relative",width:"100%",paddingTop:"129%",flexShrink:0}},{children:o("div",n({style:{position:"absolute",inset:0}},{children:[e("img",{src:i,alt:"Page ".concat(l+1),style:{display:"block",width:"100%",height:"100%",objectFit:"fill"},draggable:!1,ref:function(o){o&&o.complete&&!q[l]&&W(function(o){var i;return n(n({},o),((i={})[l]=!0,i))})},onLoad:function(){return W(function(o){var i;return n(n({},o),((i={})[l]=!0,i))})}}),q[l]&&a.map(function(i){var r=i.bbox,l=i.key,a=i.globalIndex,d=H===a;return e("div",n({ref:function(n){t.current[a]=n},onMouseEnter:function(){return j(a)},onMouseLeave:function(){return j(null)},style:{position:"absolute",left:"".concat(100*r.xmin,"%"),top:"".concat(100*r.ymin,"%"),width:"".concat(100*(r.xmax-r.xmin),"%"),height:"".concat(100*(r.ymax-r.ymin),"%"),background:d?C:k,border:d?"1.5px solid ".concat(z):"none",borderRadius:"2px",zIndex:2}},{children:v&&E===a&&o("div",n({style:{position:"absolute",top:"-18px",right:"0",fontSize:"10px",background:b,color:"black",padding:"2px 6px",borderRadius:"3px",whiteSpace:"nowrap"}},{children:["Citation ",a+1]}))}),l)})]}))}))]}),l)})},V={overflowY:"auto",border:"1px solid #ddd",borderRadius:"4px",padding:"8px",paddingBottom:0,display:"flex",flexDirection:"column",boxSizing:"border-box"};return o(i,{children:[o("div",n({style:{width:"100%",maxWidth:"800px",fontFamily:"inherit",display:"flex",flexDirection:"column"}},{children:[Q(!1),e("div",n({ref:Y,style:n(n({},V),{maxHeight:F})},{children:U(!1)}))]})),e(u,n({isOpen:A,onClose:function(){return O(!1)}},{children:o("div",n({style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"}},{children:[Q(!0),e("div",n({ref:G,style:n(n({},V),{flex:1})},{children:A&&U(!0)}))]}))}))]})}export{s as default};
|
|
2
2
|
//# sourceMappingURL=ScannedDocCitation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePdfHighlight.d.ts","sourceRoot":"","sources":["../../../../../src/features/PdfViewer/usePdfHighlight.tsx"],"names":[],"mappings":";AAKA,eAAO,MAAM,oBAAoB,kBAChB,MAAM,EAAE,kBACP,OAAO,MAAM,EAAE,MAAM,CAAC,aAC3B,MAAM,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC;;;;;;;+
|
|
1
|
+
{"version":3,"file":"usePdfHighlight.d.ts","sourceRoot":"","sources":["../../../../../src/features/PdfViewer/usePdfHighlight.tsx"],"names":[],"mappings":";AAKA,eAAO,MAAM,oBAAoB,kBAChB,MAAM,EAAE,kBACP,OAAO,MAAM,EAAE,MAAM,CAAC,aAC3B,MAAM,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC;;;;;;;+BAwGf,MAAM;;;;0CASK,MAAM;;;;;;;;;CAgLpD,CAAC"}
|
|
@@ -8,13 +8,36 @@ export interface PageHighlight {
|
|
|
8
8
|
pageIndex: number;
|
|
9
9
|
bboxes: BBox[];
|
|
10
10
|
}
|
|
11
|
+
export interface Dimensions {
|
|
12
|
+
unit: string;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}
|
|
16
|
+
export interface HighlightedText {
|
|
17
|
+
text: string;
|
|
18
|
+
excerpt_from_document: string;
|
|
19
|
+
page_no: number;
|
|
20
|
+
reasoning: string[];
|
|
21
|
+
gap: string[];
|
|
22
|
+
score: number;
|
|
23
|
+
}
|
|
24
|
+
export interface CitationPage {
|
|
25
|
+
gs_url: string;
|
|
26
|
+
page_no?: number;
|
|
27
|
+
highlighted_coordinates?: BBox[];
|
|
28
|
+
dimensions?: Dimensions;
|
|
29
|
+
highlighted_text?: HighlightedText[];
|
|
30
|
+
}
|
|
11
31
|
export interface ScannedDocCitationProps {
|
|
12
|
-
images
|
|
13
|
-
highlights
|
|
32
|
+
images?: string[];
|
|
33
|
+
highlights?: PageHighlight[];
|
|
34
|
+
pages?: CitationPage[];
|
|
35
|
+
citationLabelColor?: string;
|
|
36
|
+
showCitationLabelOnHover?: boolean;
|
|
14
37
|
highlightColor?: string;
|
|
15
38
|
highlightActiveColor?: string;
|
|
16
39
|
highlightBorderColor?: string;
|
|
17
40
|
height?: string | number;
|
|
18
41
|
}
|
|
19
|
-
export default function ScannedDocCitation({ images, highlights, highlightColor, highlightActiveColor, highlightBorderColor, height, }: ScannedDocCitationProps): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
export default function ScannedDocCitation({ images, highlights, pages, citationLabelColor, showCitationLabelOnHover, highlightColor, highlightActiveColor, highlightBorderColor, height, }: ScannedDocCitationProps): import("react/jsx-runtime").JSX.Element;
|
|
20
43
|
//# sourceMappingURL=ScannedDocCitation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScannedDocCitation.d.ts","sourceRoot":"","sources":["../../../../../src/features/ScannedDocCitation/ScannedDocCitation.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,IAAI,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"ScannedDocCitation.d.ts","sourceRoot":"","sources":["../../../../../src/features/ScannedDocCitation/ScannedDocCitation.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,IAAI,EAAE,CAAC;CAChB;AACD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB,EAAE,MAAM,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uBAAuB,CAAC,EAAE,IAAI,EAAE,CAAC;IACjC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,MAAM,EACN,UAAU,EACV,KAAK,EACL,kBAA8B,EAC9B,wBAAgC,EAChC,cAA0C,EAC1C,oBAAgD,EAChD,oBAA+C,EAC/C,MAAgB,GACjB,EAAE,uBAAuB,2CAgNzB"}
|