@researai/deepscientist 1.5.16 → 1.5.17

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.
Files changed (82) hide show
  1. package/README.md +66 -23
  2. package/bin/ds.js +550 -19
  3. package/docs/en/00_QUICK_START.md +65 -5
  4. package/docs/en/01_SETTINGS_REFERENCE.md +1 -1
  5. package/docs/en/09_DOCTOR.md +14 -3
  6. package/docs/en/15_CODEX_PROVIDER_SETUP.md +12 -3
  7. package/docs/en/21_LOCAL_MODEL_BACKENDS_GUIDE.md +283 -0
  8. package/docs/en/91_DEVELOPMENT.md +237 -0
  9. package/docs/en/README.md +7 -3
  10. package/docs/zh/00_QUICK_START.md +54 -5
  11. package/docs/zh/01_SETTINGS_REFERENCE.md +1 -1
  12. package/docs/zh/09_DOCTOR.md +15 -4
  13. package/docs/zh/15_CODEX_PROVIDER_SETUP.md +12 -3
  14. package/docs/zh/21_LOCAL_MODEL_BACKENDS_GUIDE.md +281 -0
  15. package/docs/zh/README.md +7 -3
  16. package/install.sh +46 -4
  17. package/package.json +2 -1
  18. package/pyproject.toml +1 -1
  19. package/src/deepscientist/__init__.py +1 -1
  20. package/src/deepscientist/bridges/connectors.py +8 -2
  21. package/src/deepscientist/codex_cli_compat.py +185 -72
  22. package/src/deepscientist/config/service.py +154 -6
  23. package/src/deepscientist/daemon/api/handlers.py +130 -25
  24. package/src/deepscientist/daemon/api/router.py +5 -0
  25. package/src/deepscientist/daemon/app.py +446 -22
  26. package/src/deepscientist/diagnostics/__init__.py +6 -0
  27. package/src/deepscientist/diagnostics/runner_failures.py +130 -0
  28. package/src/deepscientist/doctor.py +207 -3
  29. package/src/deepscientist/prompts/builder.py +22 -4
  30. package/src/deepscientist/quest/service.py +413 -13
  31. package/src/deepscientist/runners/codex.py +59 -14
  32. package/src/deepscientist/shared.py +19 -0
  33. package/src/prompts/contracts/shared_interaction.md +3 -2
  34. package/src/prompts/system.md +13 -0
  35. package/src/prompts/system_copilot.md +13 -0
  36. package/src/tui/package.json +1 -1
  37. package/src/ui/dist/assets/{AiManusChatView-COFACy7V.js → AiManusChatView-Bv-Z8YpU.js} +44 -44
  38. package/src/ui/dist/assets/{AnalysisPlugin-DnSm0GZn.js → AnalysisPlugin-BCKAfjba.js} +1 -1
  39. package/src/ui/dist/assets/{CliPlugin-CvwCmDQ5.js → CliPlugin-BCKcpc35.js} +4 -4
  40. package/src/ui/dist/assets/{CodeEditorPlugin-cOqSa0xq.js → CodeEditorPlugin-DbOfSJ8K.js} +1 -1
  41. package/src/ui/dist/assets/{CodeViewerPlugin-itb0tltR.js → CodeViewerPlugin-CbaFRrUU.js} +3 -3
  42. package/src/ui/dist/assets/{DocViewerPlugin-DqKkiCI6.js → DocViewerPlugin-DAjLVeQD.js} +3 -3
  43. package/src/ui/dist/assets/{GitCommitViewerPlugin-DVgNHBCS.js → GitCommitViewerPlugin-CIUqbUDO.js} +1 -1
  44. package/src/ui/dist/assets/{GitDiffViewerPlugin-DxL2ezFG.js → GitDiffViewerPlugin-CQACjoAA.js} +1 -1
  45. package/src/ui/dist/assets/{GitSnapshotViewer-B_RQm1YZ.js → GitSnapshotViewer-0r4nLPke.js} +1 -1
  46. package/src/ui/dist/assets/{ImageViewerPlugin-tHqlXY3n.js → ImageViewerPlugin-nBOmI2v_.js} +3 -3
  47. package/src/ui/dist/assets/{LabCopilotPanel-ClMbq5Yu.js → LabCopilotPanel-BHxOxF4z.js} +1 -1
  48. package/src/ui/dist/assets/{LabPlugin-L_SuE8ow.js → LabPlugin-BKoZGs95.js} +1 -1
  49. package/src/ui/dist/assets/{LatexPlugin-B495DTXC.js → LatexPlugin-ZwtV8pIp.js} +1 -1
  50. package/src/ui/dist/assets/{MarkdownViewerPlugin-DG28-61B.js → MarkdownViewerPlugin-DKqVfKyW.js} +3 -3
  51. package/src/ui/dist/assets/{MarketplacePlugin-BiOGT-Kj.js → MarketplacePlugin-BwxStZ9D.js} +1 -1
  52. package/src/ui/dist/assets/{NotebookEditor-C-4Kt1p9.js → NotebookEditor-BEQhaQbt.js} +1 -1
  53. package/src/ui/dist/assets/{NotebookEditor-CVsj8h_T.js → NotebookEditor-DB9N_T9q.js} +23 -23
  54. package/src/ui/dist/assets/{PdfLoader-CASDQmxJ.js → PdfLoader-eWBONbQP.js} +1 -1
  55. package/src/ui/dist/assets/{PdfMarkdownPlugin-BFhwoKsY.js → PdfMarkdownPlugin-D22YOZL3.js} +1 -1
  56. package/src/ui/dist/assets/{PdfViewerPlugin-DcOzU9vd.js → PdfViewerPlugin-c-RK9DLM.js} +3 -3
  57. package/src/ui/dist/assets/{SearchPlugin-CHj7M58O.js → SearchPlugin-CxF9ytAx.js} +1 -1
  58. package/src/ui/dist/assets/{TextViewerPlugin-CB4DYfWO.js → TextViewerPlugin-C5xqeeUH.js} +2 -2
  59. package/src/ui/dist/assets/{VNCViewer-CjlbyCB3.js → VNCViewer-BoLGLnHz.js} +1 -1
  60. package/src/ui/dist/assets/{bot-CFkZY-JP.js → bot-DREQOxzP.js} +1 -1
  61. package/src/ui/dist/assets/{chevron-up-Dq5ofbht.js → chevron-up-C9Qpx4DE.js} +1 -1
  62. package/src/ui/dist/assets/{code-DLC6G24T.js → code-WlFHE7z_.js} +1 -1
  63. package/src/ui/dist/assets/{file-content-Dv4LoZec.js → file-content-BZMz3RYp.js} +1 -1
  64. package/src/ui/dist/assets/{file-diff-panel-Denq-lC3.js → file-diff-panel-CQhw0jS2.js} +1 -1
  65. package/src/ui/dist/assets/{file-socket-Cu4Qln7Y.js → file-socket-CfQPKQKj.js} +1 -1
  66. package/src/ui/dist/assets/{git-commit-horizontal-BUh6G52n.js → git-commit-horizontal-DxZ8DCZh.js} +1 -1
  67. package/src/ui/dist/assets/{image-B9HUUddG.js → image-Bgl4VIyx.js} +1 -1
  68. package/src/ui/dist/assets/{index-Cgla8biy.css → index-BpV6lusQ.css} +1 -1
  69. package/src/ui/dist/assets/{index-Gbl53BNp.js → index-CBNVuWcP.js} +363 -363
  70. package/src/ui/dist/assets/{index-wQ7RIIRd.js → index-CwNu1aH4.js} +1 -1
  71. package/src/ui/dist/assets/{index-B2B1sg-M.js → index-DrUnlf6K.js} +1 -1
  72. package/src/ui/dist/assets/{index-DRyx7vAc.js → index-NW-h8VzN.js} +1 -1
  73. package/src/ui/dist/assets/{pdf-effect-queue-ZtnHFCAi.js → pdf-effect-queue-J8OnM0jE.js} +1 -1
  74. package/src/ui/dist/assets/{popover-DL6h35vr.js → popover-CLc0pPP8.js} +1 -1
  75. package/src/ui/dist/assets/{project-sync-CsX08Qno.js → project-sync-C9IdzdZW.js} +1 -1
  76. package/src/ui/dist/assets/{select-DvmXt1yY.js → select-Cs2PmzwL.js} +1 -1
  77. package/src/ui/dist/assets/{sigma-7jpXazui.js → sigma-ClKcHAXm.js} +1 -1
  78. package/src/ui/dist/assets/{trash-xA7kFt8i.js → trash-DwpbFr3w.js} +1 -1
  79. package/src/ui/dist/assets/{useCliAccess-DsMwDjOp.js → useCliAccess-NQ8m0Let.js} +1 -1
  80. package/src/ui/dist/assets/{wrap-text-CwMn-iqb.js → wrap-text-BC-Hltpd.js} +1 -1
  81. package/src/ui/dist/assets/{zoom-out-R-GWEhzS.js → zoom-out-E_gaeAxL.js} +1 -1
  82. package/src/ui/dist/index.html +2 -2
@@ -1,4 +1,4 @@
1
- import{j as L,_ as he,ca as ce}from"./index-Gbl53BNp.js";import{r as z,R as st}from"./plugin-monaco-C8UgLomw.js";import{a as ue,g as pe}from"./plugin-terminal-MXFIPun8.js";import{r as dt}from"./plugin-notebook-HbW2K-1c.js";import{p as de,_ as fe,a as ge}from"./plugin-pdf-CR8hgQBV.js";const an={A4_WIDTH:595},ln=[.5,.75,1,1.25,1.5,2],me=de,ve=void 0,be=!1;function Mt(i,t){let e;return(...n)=>{e&&clearTimeout(e),e=setTimeout(()=>i(...n),t)}}const Dt=(i,{width:t,height:e})=>({x1:i.left,y1:i.top,x2:i.left+i.width,y2:i.top+i.height,width:t,height:e,pageNumber:i.pageNumber}),we=(i,t)=>{const[e,n,o,r]=t.convertToViewportRectangle([i.x1,i.y1,i.x2,i.y2]);return{left:Math.min(e,o),top:Math.min(n,r),width:Math.abs(o-e),height:Math.abs(n-r),pageNumber:i.pageNumber}},bt=(i,t,e=!1)=>{const{width:n,height:o}=t;if(e)return we(i,t);if(i.x1===void 0)throw new Error("You are using old position format, please update");const r=n*i.x1/i.width,s=o*i.y1/i.height,a=n*i.x2/i.width,h=o*i.y2/i.height;return{left:r,top:s,width:a-r,height:h-s,pageNumber:i.pageNumber}},jt=i=>i.ownerDocument||document,rt=i=>jt(i).defaultView||window,Z=i=>i!=null&&(i instanceof HTMLElement||i instanceof rt(i).HTMLElement),ye=i=>i instanceof HTMLCanvasElement||i instanceof rt(i).HTMLCanvasElement,pt=i=>{const t=i.closest(".page");if(!Z(t))return null;const e=Number(t.dataset.pageNumber);return{node:t,number:e}},Et=i=>{const t=i.startContainer.parentElement,e=i.endContainer.parentElement;if(!Z(t)||!Z(e))return[];const n=pt(t),o=pt(e);if(!n?.number||!o?.number)return[];if(n.number===o.number)return[n];if(n.number===o.number-1)return[n,o];const r=[];let s=n.number;const a=n.node.ownerDocument;for(;s<=o.number;){const h=pt(a.querySelector(`[data-page-number='${s}'`));h&&r.push(h),s++}return r},Se=(i,t,e)=>{const n=jt(i);let o=i.querySelector(e);return o||(o=n.createElement("div"),o.className=t,i.appendChild(o)),o},xe=(i,t)=>{const{left:e,top:n,width:o,height:r}=t,a=(i?i.ownerDocument:null)?.createElement("canvas");if(!a||!ye(a))return"";a.width=o,a.height=r;const h=a.getContext("2d");if(!h||!i)return"";const l=window.devicePixelRatio;return h.drawImage(i,e*l,n*l,o*l,r*l,0,0,o,r),a.toDataURL("image/png")},Ht=i=>{const t=Array.from(i).map(u=>{const{left:g,top:w,width:b,height:y,pageNumber:S}=u,P=g,x=g+b,f=w,p=w+y;return{X0:P,X1:x,Y0:f,Y1:p,pageNumber:S}});let e=Number.MAX_SAFE_INTEGER;for(const u of t)e=Math.min(e,u.pageNumber??e);const n=t.filter(u=>(u.X0>0||u.X1>0||u.Y0>0||u.Y1>0)&&u.pageNumber===e),o=n.reduce((u,g)=>({X0:Math.min(u.X0,g.X0),X1:Math.max(u.X1,g.X1),Y0:Math.min(u.Y0,g.Y0),Y1:Math.max(u.Y1,g.Y1),pageNumber:e}),n[0]),{X0:r,X1:s,Y0:a,Y1:h,pageNumber:l}=o;return{left:r,top:a,width:s-r,height:h-a,pageNumber:l}},Pe=i=>i.sort((t,e)=>{const n=(t.pageNumber||0)*t.top-(e.pageNumber||0)*e.top;return n===0?t.left-e.left:n}),Re=(i,t)=>i.pageNumber===t.pageNumber&&i.left<=t.left&&t.left<=i.left+i.width,ze=(i,t,e=5)=>i.pageNumber===t.pageNumber&&Math.abs(i.top-t.top)<e&&Math.abs(i.height-t.height)<e,De=(i,t)=>i.pageNumber===t.pageNumber&&i.top>t.top&&i.left>t.left&&i.top+i.height<t.top+t.height&&i.left+i.width<t.left+t.width,Te=(i,t,e=10)=>{const n=i.left+i.width,o=t.left+t.width;return i.pageNumber===t.pageNumber&&i.left<=t.left&&n<=o&&t.left-n<=e},Lt=(i,t)=>{i.width=Math.max(t.width-i.left+t.left,i.width)},_e=i=>{const t=Pe(i),e=new Set,n=t.filter(r=>t.every(s=>!De(r,s)));let o=0;for(;o<=2;){for(const r of n)for(const s of n)r===s||e.has(r)||e.has(s)||ze(r,s)&&(Re(r,s)&&(Lt(r,s),r.height=Math.max(r.height,s.height),e.add(s)),Te(r,s)&&(Lt(r,s),e.add(s)));o+=1}return n.filter(r=>!e.has(r))},Ne=(i,t)=>!(i.top<t.top||i.bottom>t.bottom||i.right>t.right||i.left<t.left),Wt=(i,t,e=!0)=>{const n=Array.from(i.getClientRects()),o=[];for(const r of n)for(const s of t){const a=s.node.getBoundingClientRect();if(Ne(r,a)&&r.width>0&&r.height>0&&r.width<a.width&&r.height<a.height){const h={top:r.top+s.node.scrollTop-a.top,left:r.left+s.node.scrollLeft-a.left,width:r.width,height:r.height,pageNumber:s.number};o.push(h)}}return e?_e(o):o},Ce="_container_1vvir_1",Me="_highlightLayer_1vvir_8",Ee="_disableSelection_1vvir_20",wt={container:Ce,highlightLayer:Me,disableSelection:Ee},Ot=10,yt=12,It=8,He=14,Le=17,We=62,Oe=22;function St(i,t,e){return Math.min(Math.max(i,t),e)}function $t(i){return String(i||"").normalize("NFKC").replace(/\uFFFD/g," ").replace(/\s+/g," ").trim()}function Ie(i,t){const e=i.position?.rects?.[0]||i.position?.boundingRect||null;if(!e)return 0;const n=Number(e.top||0),o=Number(e.height||0);return Number.isFinite(n)?Number.isFinite(o)?Math.max(0,n+o*.5-t*.5):Math.max(0,n):0}function Ae(i,t){const e=$t(i);if(!e)return"";const n=e.split(/\s+/).filter(Boolean);return n.length<=t?n.join(" "):`${n.slice(0,t).join(" ")} …`}function Fe(i){const t=i.previewSummary;if(typeof t=="string"&&t.trim())return $t(t);const e=typeof i.comment?.text=="string"?i.comment.text:"";return Ae(e,8)}function Ve(i,t){const e=Fe(i),n=e.length>0,o=Math.max(120,t-Oe),s=Math.max(14,Math.floor(o/6.1)),a=n?Math.max(1,Math.ceil(e.length/s)):0,h=14,l=n?4:0,u=h+He+l+a*Le;return Math.max(We,Math.ceil(u))}function Be(i,t,e){const n=Number.isFinite(t)&&t>0?t:0,o=Number.isFinite(e)&&e>0?e:0,r=Math.max(140,n-yt*2),s=St(n*.34,190,320),a=Math.min(r,s),h=Math.max(yt,n-a-yt),l=i.filter(c=>!c.content?.image).filter(c=>!c.__dsGhost).map(c=>{const m=c,v=Ve(m,a);return{id:String(c.id),cardHeightPx:v,anchorTop:Ie(m,v)}}).sort((c,m)=>c.anchorTop===m.anchorTop?c.id.localeCompare(m.id):c.anchorTop-m.anchorTop),u={};if(l.length===0)return{hintTopById:u,hintLeftPx:h,hintWidthPx:a};const g=It,w=Math.max(g,o-It),b=Math.max(0,w-g),y=l.reduce((c,m)=>c+m.cardHeightPx,0);let S=Ot;if(l.length>1){const c=Math.floor((b-y)/(l.length-1));Number.isFinite(c)&&(S=Math.max(0,Math.min(Ot,c)))}else S=0;const P=new Array(l.length).fill(0);for(let c=l.length-1;c>=0;c-=1){const m=c+1<l.length?P[c+1]:0;P[c]=l[c].cardHeightPx+m}const x=[];let f=g;for(let c=0;c<l.length;c+=1){const m=l[c],v=l.length-c-1,R=P[c]+Math.max(0,v)*Math.max(0,S),_=Math.max(g,w-R),D=St(m.anchorTop,g,_),N=Math.max(D,f);x.push({id:m.id,top:N,cardHeightPx:m.cardHeightPx}),f=N+m.cardHeightPx+S}const p=x[x.length-1],d=p?p.top+p.cardHeightPx:g;if(d>w){const c=d-w;for(let m=0;m<x.length;m+=1)x[m].top=Math.max(g,x[m].top-c)}for(let c=1;c<x.length;c+=1){const m=x[c-1],v=x[c],R=m.top+m.cardHeightPx+S;v.top<R&&(v.top=R)}for(const c of x){const m=Math.max(g,w-c.cardHeightPx);u[c.id]=Math.round(St(c.top,g,m))}return{hintTopById:u,hintLeftPx:h,hintWidthPx:a}}function ke({highlightsByPage:i,scaledPositionToViewport:t,pageNumber:e,scrolledToHighlightId:n,highlightTransform:o,tip:r,hideTipAndSelection:s,viewer:a,screenshot:h,showTip:l,setTip:u}){const g=i[String(e)]||[],w=Number.parseInt(e,10),b=a.getPageView(w-1),y=b?.div?.offsetWidth||b?.div?.getBoundingClientRect().width||b?.viewport?.width||0,S=b?.div?.offsetHeight||b?.div?.getBoundingClientRect().height||b?.viewport?.height||0,P=g.map(f=>({...f,position:t(f.position)})),x=Be(P,y,S);return L.jsx("div",{children:P.map((f,p)=>{const d=f;r&&r.highlight.id===String(d.id)&&l(f,r.callback(f));const c=n===d.id;return o(f,p,(m,v)=>{u({highlight:m,callback:v}),l(m,v(m))},s,m=>{const v=a.getPageView((m.pageNumber||Number.parseInt(e))-1).viewport;return Dt(m,v)},m=>h(m,Number.parseInt(e)),c,{width:y,height:S,pageNumber:w,overlayHintTopById:x.hintTopById,overlayHintLeftPx:x.hintLeftPx,overlayHintWidthPx:x.hintWidthPx})})})}const Xe="_mouseSelection_1p43j_1",Ye={mouseSelection:Xe},At=(i,t)=>({left:Math.min(t.x,i.x),top:Math.min(t.y,i.y),width:Math.abs(t.x-i.x),height:Math.abs(t.y-i.y)}),Ue=i=>i.width>=1&&i.height>=1;function Ge({onSelection:i,onDragStart:t,onDragEnd:e,shouldStart:n,onChange:o}){const[r,s]=z.useState(!1),[a,h]=z.useState(null),[l,u]=z.useState(null),g=z.useRef(null),w=z.useRef(a),b=z.useRef(r);z.useEffect(()=>{w.current=a},[a]),z.useEffect(()=>{b.current=r},[r]);const y=z.useCallback(()=>{e(),h(null),u(null),s(!1)},[e]);return z.useEffect(()=>{o(!!(a&&l))},[a,l,o]),z.useEffect(()=>{const S=g.current;if(!S)return;const P=S.parentElement;if(!P||!Z(P))return;const x=(d,c)=>{const m=P.getBoundingClientRect();return{x:d-m.left+P.scrollLeft,y:c-m.top+P.scrollTop-window.scrollY}},f=d=>{!w.current||b.current||u(x(d.pageX,d.pageY))},p=d=>{if(!n(d)){y();return}const c=d.target;if(!(c instanceof Element)||!Z(c))return;t(),h(x(d.pageX,d.pageY)),u(null),s(!1);const m=R=>{R.currentTarget?.removeEventListener("mouseup",m);const _=w.current;if(!_||!(R instanceof MouseEvent))return;const D=x(R.pageX,R.pageY),N=At(_,D);if(!(R.target instanceof Element)||!Z(R.target)||!P.contains(R.target)||!Ue(N)){y();return}u(D),s(!0),i(c,N,y),e()},v=P.ownerDocument;v?.body&&v.body.addEventListener("mouseup",m)};return P.addEventListener("mousemove",f),P.addEventListener("mousedown",p),()=>{P.removeEventListener("mousemove",f),P.removeEventListener("mousedown",p)}},[n,t,e,i,y]),L.jsx("div",{ref:g,children:a&&l&&L.jsx("div",{className:Ye.mouseSelection,style:At(a,l)})})}const je="_tipContainer_f56kr_1",$e={tipContainer:je};function nt(i,t,e){return Math.min(Math.max(i,t),e)}function qe({children:i,style:t,scrollTop:e,pageBoundingRect:n,pageOffset:o,tipPlacementMode:r="auto"}){const[s,a]=z.useState(0),[h,l]=z.useState(0),u=z.useRef(null),g=z.useCallback(()=>{if(!u.current)return;const{offsetHeight:M,offsetWidth:$}=u.current;a(M),l($)},[]);z.useEffect(()=>{setTimeout(g,0)},[g]),z.useEffect(()=>{if(!u.current||typeof ResizeObserver>"u")return;const M=new ResizeObserver(()=>{g()});return M.observe(u.current),()=>M.disconnect()},[g]);const w=h===0&&s===0,b=12,y=o.left,S=o.top,P=y+b,x=y+n.width-h-b,f=S+b,p=S+n.height-s-b,d=(t.selectionLeft+t.selectionRight)/2,c=y+n.width-t.selectionRight-b,m=t.selectionLeft-y-b;let v=nt(d-h/2,P,x),R=nt(t.selectionTop,f,p);const _=c>=h,D=m>=h,N=r==="overlay",T=r==="right",O=t.selectionTop-s-b<e;if(T){v=x;const M=t.selectionTop+(t.selectionBottom-t.selectionTop)/2-s/2;R=nt(M,f,p)}else!N&&_?v=t.selectionRight+b:!N&&D?v=t.selectionLeft-h-b:(R=O?t.selectionBottom+b:t.selectionTop-s-b,R=nt(R,f,p),v=nt(d-h/2,P,x));const B=z.useCallback(()=>{l(0),a(0),setTimeout(g,0)},[g]),Y=st.Children.map(i,M=>M!=null?st.cloneElement(M,{onUpdate:B,popup:{position:O?"below":"above"}}):null);return L.jsx("div",{id:"PdfHighlighter__tip-container",className:$e.tipContainer,style:{visibility:w?"hidden":"visible",top:R,left:v},ref:u,children:Y})}const Ft="empty-id",Ke="__ds_ghost__";class hn extends z.PureComponent{static defaultProps={pdfScaleValue:"auto"};state={ghostHighlight:null,isCollapsed:!0,range:null,scrolledToHighlightId:Ft,isAreaSelectionInProgress:!1,tip:null,tipPosition:null,tipChildren:null,pinnedTipHighlightId:null};viewer;resizeObserver=null;containerNode=null;containerNodeRef;highlightRoots={};highlightRootByContainer=new WeakMap;unsubscribe=()=>{};selectionRafId=null;scrollPageIntoViewPatched=!1;scrollMatchIntoViewPatched=!1;constructor(t){super(t),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(this.debouncedScaleValue)),this.containerNodeRef=st.createRef()}componentDidMount(){this.init()}onPageChanging=t=>{const e=t?.pageNumber;typeof e=="number"&&this.props.onPageChange?.(e)};attachRef=t=>{const{resizeObserver:e}=this;if(this.containerNode=this.containerNodeRef.current,this.unsubscribe(),this.containerNode){const{ownerDocument:n}=this.containerNode;t.on("textlayerrendered",this.onTextLayerRendered),t.on("pagesinit",this.onDocumentReady),t.on("pagechanging",this.onPageChanging),n.addEventListener("selectionchange",this.onSelectionChange),n.addEventListener("keydown",this.handleKeyDown),n.defaultView?.addEventListener("resize",this.debouncedScaleValue),e&&e.observe(this.containerNode),this.unsubscribe=()=>{t.off("pagesinit",this.onDocumentReady),t.off("textlayerrendered",this.onTextLayerRendered),t.off("pagechanging",this.onPageChanging),n.removeEventListener("selectionchange",this.onSelectionChange),n.removeEventListener("keydown",this.handleKeyDown),n.defaultView?.removeEventListener("resize",this.debouncedScaleValue),e&&e.disconnect()}}};componentDidUpdate(t){if(t.pdfDocument!==this.props.pdfDocument){this.init();return}if(t.pdfScaleValue!==this.props.pdfScaleValue&&this.handleScaleValue(),t.highlights!==this.props.highlights){this.renderHighlightLayers();const e=this.state.pinnedTipHighlightId;if(e){const n=this.state.tip&&String(this.state.tip.highlight.id)===e?this.state.tip.callback:void 0;this.setPinnedTipForHighlight(e,n)}}}findViewportHighlightById(t){const e=this.props.highlights.find(n=>String(n.id)===String(t));return e?{...e,position:this.scaledPositionToViewport(e.position)}:null}setPinnedTipForHighlight=(t,e)=>{if(!t){this.setState({pinnedTipHighlightId:null,tip:null,tipPosition:null,tipChildren:null},()=>this.renderHighlightLayers());return}const n=this.findViewportHighlightById(t);if(!n){this.setState({pinnedTipHighlightId:null,tip:null,tipPosition:null,tipChildren:null},()=>this.renderHighlightLayers());return}const o=e||(this.state.tip&&String(this.state.tip.highlight.id)===String(t)?this.state.tip.callback:void 0);o&&this.setState({pinnedTipHighlightId:String(t),tip:{highlight:n,callback:o}},()=>{this.setTip(n.position,o(n)),this.renderHighlightLayers()})};async init(){const{pdfDocument:t,pdfViewerOptions:e}=this.props,n=await he(()=>import("./plugin-pdf-CR8hgQBV.js").then(s=>s.b),[]),o=new n.EventBus,r=new n.PDFLinkService({eventBus:o,externalLinkTarget:2});this.containerNodeRef.current&&(this.viewer=this.viewer||new n.PDFViewer({container:this.containerNodeRef.current,eventBus:o,textLayerMode:2,removePageBorders:!0,linkService:r,...e}),this.patchScrollPageIntoView(),this.patchScrollMatchIntoView(n),r.setDocument(t),r.setViewer(this.viewer),this.viewer.setDocument(t),this.attachRef(o))}patchScrollPageIntoView(){if(this.scrollPageIntoViewPatched||!this.viewer)return;const t=this.viewer.scrollPageIntoView.bind(this.viewer);this.viewer.scrollPageIntoView=e=>{if(!this.isViewerScrollable())return;const n=e?.pageNumber;if(typeof n=="number"){const o=this.viewer.getPageView(n-1);if(!o?.div||!o.div.offsetParent)return}t(e)},this.scrollPageIntoViewPatched=!0}patchScrollMatchIntoView(t){if(this.scrollMatchIntoViewPatched)return;const e=t?.PDFFindController?.prototype;if(!e||typeof e.scrollMatchIntoView!="function")return;const n=e.scrollMatchIntoView;e.scrollMatchIntoView=function(o={}){const r=o.element;if(!(!r||!r.isConnected||!r.offsetParent))return n.call(this,o)},this.scrollMatchIntoViewPatched=!0}componentWillUnmount(){Object.values(this.highlightRoots).forEach(t=>{try{t.reactRoot.unmount()}catch{}}),this.highlightRoots={},this.highlightRootByContainer=new WeakMap,this.unsubscribe()}findOrCreateHighlightLayer(t){if(!this.viewer)return null;const{textLayer:e}=this.viewer.getPageView(t-1)||{};return e?Se(e.div,`PdfHighlighter__highlight-layer ${wt.highlightLayer}`,".PdfHighlighter__highlight-layer"):null}groupHighlightsByPage(t){const{ghostHighlight:e}=this.state,n=[...t,e].filter(Boolean),o=new Set;for(const s of n){o.add(s.position.pageNumber);for(const a of s.position.rects)a.pageNumber&&o.add(a.pageNumber)}const r={};for(const s of o){r[s]=r[s]||[];for(const a of n){const h={...a,position:{pageNumber:s,boundingRect:a.position.boundingRect,rects:[],usePdfCoordinates:a.position.usePdfCoordinates}};let l=!1;for(const u of a.position.rects)s===(u.pageNumber||a.position.pageNumber)&&(h.position.rects.push(u),l=!0);(l||s===a.position.pageNumber)&&r[s].push(h)}}return r}showTip(t,e){const{isCollapsed:n,ghostHighlight:o,isAreaSelectionInProgress:r,pinnedTipHighlightId:s}=this.state;s&&String(t.id)!==String(s)||!n||o||r||this.setTip(t.position,e)}scaledPositionToViewport({pageNumber:t,boundingRect:e,rects:n,usePdfCoordinates:o}){const r=this.viewer.getPageView(t-1).viewport;return{boundingRect:bt(e,r,o),rects:(n||[]).map(s=>bt(s,r,o)),pageNumber:t}}viewportPositionToScaled({pageNumber:t,boundingRect:e,rects:n}){const o=this.viewer.getPageView(t-1).viewport;return{boundingRect:Dt(e,o),rects:(n||[]).map(r=>Dt(r,o)),pageNumber:t}}screenshot(t,e){const n=this.viewer.getPageView(e-1).canvas;return xe(n,t)}hideTipAndSelection=()=>{if(this.state.pinnedTipHighlightId)return;this.selectionRafId!=null&&(cancelAnimationFrame(this.selectionRafId),this.selectionRafId=null);const t=this.containerNode;t&&rt(t).getSelection()?.removeAllRanges(),this.setState({tipPosition:null,tipChildren:null,ghostHighlight:null,tip:null,range:null,isCollapsed:!0},()=>this.renderHighlightLayers())};buildGhostHighlight(t,e){return{__dsGhost:!0,id:Ke,position:t,content:e?{text:e}:void 0,comment:{text:"",emoji:"note"}}}scheduleGhostHighlightUpdate(t){this.selectionRafId!=null&&cancelAnimationFrame(this.selectionRafId),this.selectionRafId=requestAnimationFrame(()=>{this.selectionRafId=null;const{isAreaSelectionInProgress:e}=this.state;if(e)return;const n=Et(t);if(!n||n.length===0)return;const o=Wt(t,n);if(o.length===0)return;const s={boundingRect:Ht(o),rects:o,pageNumber:n[0].number},a=this.viewportPositionToScaled(s),h=this.buildGhostHighlight(a,t.toString());this.setState({ghostHighlight:h},()=>this.renderHighlightLayers())})}setTip(t,e){this.setState({tipPosition:t,tipChildren:e})}renderTip=()=>{const{tipPosition:t,tipChildren:e}=this.state;if(!t)return null;const{boundingRect:n,pageNumber:o}=t,r={node:this.viewer.getPageView((n.pageNumber||o)-1).div,pageNumber:n.pageNumber||o},s=r.node.getBoundingClientRect(),a={bottom:s.bottom,height:s.height,left:s.left,right:s.right,top:s.top,width:s.width,x:s.x,y:s.y,pageNumber:r.pageNumber},h=r.node.offsetLeft+n.left,l=h+n.width,u=n.top+r.node.offsetTop,g=u+n.height;return L.jsx(qe,{scrollTop:this.viewer.container.scrollTop,pageBoundingRect:a,pageOffset:{left:r.node.offsetLeft,top:r.node.offsetTop},tipPlacementMode:this.props.tipPlacementMode,style:{selectionLeft:h,selectionRight:l,selectionTop:u,selectionBottom:g},children:e})};onTextLayerRendered=()=>{this.renderHighlightLayers()};isViewerScrollable=()=>{const t=this.viewer?.container;return!t||!t.isConnected?!1:!!t.offsetParent};scrollTo=t=>{const{pageNumber:e,boundingRect:n,usePdfCoordinates:o}=t.position;if(!this.isViewerScrollable()){this.setState({scrolledToHighlightId:t.id},()=>this.renderHighlightLayers());return}const r=this.viewer.getPageView(e-1);if(!r?.div||!r.div.offsetParent)return;this.viewer.container.removeEventListener("scroll",this.onScroll);const s=r.viewport;this.viewer.scrollPageIntoView({pageNumber:e,destArray:[null,{name:"XYZ"},...s.convertToPdfPoint(0,bt(n,s,o).top-10),0]}),this.setState({scrolledToHighlightId:t.id},()=>this.renderHighlightLayers()),setTimeout(()=>{this.viewer.container.addEventListener("scroll",this.onScroll)},100)};scrollToPage=t=>{this.viewer&&this.isViewerScrollable()&&(this.viewer.currentPageNumber=t)};onDocumentReady=()=>{const{scrollRef:t}=this.props;this.handleScaleValue(),t(this.scrollTo),this.props.onPageChange?.(this.viewer.currentPageNumber||1)};onSelectionChange=()=>{const t=this.containerNode;if(!t)return;const e=rt(t).getSelection();if(!e)return;const n=e.rangeCount>0?e.getRangeAt(0):null;if(e.isCollapsed){this.setState({isCollapsed:!0,range:null,ghostHighlight:null},()=>this.renderHighlightLayers());return}if(!n||!t||!t.contains(n.commonAncestorContainer))return;const o=n.cloneRange();this.setState({isCollapsed:!1,range:o}),this.scheduleGhostHighlightUpdate(o),this.debouncedAfterSelection()};onScroll=()=>{const{onScrollChange:t}=this.props;t(),this.setState({scrolledToHighlightId:Ft},()=>this.renderHighlightLayers()),this.viewer.container.removeEventListener("scroll",this.onScroll)};onMouseDown=t=>{this.state.pinnedTipHighlightId||!(t.target instanceof Element)||!Z(t.target)||t.target.closest("#PdfHighlighter__tip-container")||this.hideTipAndSelection()};handleKeyDown=t=>{this.state.pinnedTipHighlightId||t.code==="Escape"&&this.hideTipAndSelection()};afterSelection=()=>{const{onSelectionFinished:t}=this.props,e=this.containerNode;if(!e)return;const n=rt(e).getSelection(),o=n&&n.rangeCount>0?n.getRangeAt(0):null,{isCollapsed:r}=this.state;if(!o||r||n?.isCollapsed)return;const s=o.cloneRange(),a=Et(s);if(!a||a.length===0)return;const h=Wt(s,a);if(h.length===0)return;const u={boundingRect:Ht(h),rects:h,pageNumber:a[0].number},g={text:s.toString()},w=this.viewportPositionToScaled(u);this.setTip(u,t(w,g,()=>this.hideTipAndSelection(),()=>this.setState({ghostHighlight:this.buildGhostHighlight(w,g.text)},()=>this.renderHighlightLayers())))};debouncedAfterSelection=Mt(this.afterSelection,320);toggleTextSelection(t){this.viewer.viewer&&this.viewer.viewer.classList.toggle(wt.disableSelection,t)}handleScaleValue=()=>{if(!this.viewer)return;const t=this.props.pdfScaleValue,e="page-width:";if(t.startsWith(e)){const n=Number.parseFloat(t.slice(e.length));if(!Number.isFinite(n)||n<=0){this.viewer.currentScaleValue="page-width";return}this.viewer.currentScaleValue="page-width";const o=this.viewer.currentScale;if(!Number.isFinite(o)||o<=0)return;this.viewer.currentScaleValue=String(o*n);return}this.viewer.currentScaleValue=t};debouncedScaleValue=Mt(this.handleScaleValue,500);render(){const{onSelectionFinished:t,enableAreaSelection:e}=this.props;return L.jsx("div",{onPointerDown:this.onMouseDown,children:L.jsxs("div",{ref:this.containerNodeRef,className:wt.container,style:{position:"absolute",width:"100%",height:"100%",overflow:"auto"},onContextMenu:n=>n.preventDefault(),children:[L.jsx("div",{className:"pdfViewer"}),this.renderTip(),typeof e=="function"?L.jsx(Ge,{onDragStart:()=>this.toggleTextSelection(!0),onDragEnd:()=>this.toggleTextSelection(!1),onChange:n=>this.setState({isAreaSelectionInProgress:n}),shouldStart:n=>e(n)&&n.target instanceof Element&&Z(n.target)&&!!n.target.closest(".page"),onSelection:(n,o,r)=>{const s=pt(n);if(!s)return;const a={...o,top:o.top-s.node.offsetTop,left:o.left-s.node.offsetLeft,pageNumber:s.number},h={boundingRect:a,rects:[],pageNumber:s.number},l=this.viewportPositionToScaled(h),u=this.screenshot(a,a.pageNumber);this.setTip(h,t(l,{image:u},()=>this.hideTipAndSelection(),()=>{console.log("setting ghost highlight",l),this.setState({ghostHighlight:{position:l,content:{image:u}}},()=>{r(),this.renderHighlightLayers()})}))}}):null]})})}renderHighlightLayers(){const{pdfDocument:t}=this.props;if(this.viewer)for(let e=1;e<=t.numPages;e++){const n=this.highlightRoots[e];if(n?.container.isConnected)this.renderHighlightLayer(n.reactRoot,e);else{const o=this.findOrCreateHighlightLayer(e);if(o){const r=this.getOrCreateHighlightRoot(o);this.highlightRoots[e]={reactRoot:r,container:o},this.renderHighlightLayer(r,e)}}}}getOrCreateHighlightRoot(t){const e=this.highlightRootByContainer.get(t);if(e)return e;const n=ce(t);return this.highlightRootByContainer.set(t,n),n}renderHighlightLayer(t,e){const{highlightTransform:n,highlights:o}=this.props,{tip:r,scrolledToHighlightId:s}=this.state;t.render(L.jsx(ke,{highlightsByPage:this.groupHighlightsByPage(o),pageNumber:e.toString(),scrolledToHighlightId:s,highlightTransform:n,tip:r,scaledPositionToViewport:this.scaledPositionToViewport.bind(this),hideTipAndSelection:this.hideTipAndSelection.bind(this),viewer:this.viewer,screenshot:this.screenshot.bind(this),showTip:this.showTip.bind(this),setTip:a=>{this.state.pinnedTipHighlightId&&String(a.highlight.id)!==String(this.state.pinnedTipHighlightId)||this.setState({tip:a})}}))}}var ft={exports:{}},qt={},Kt={exports:{}},Ze="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",Je=Ze,Qe=Je;function Zt(){}function Jt(){}Jt.resetWarningCache=Zt;var ti=function(){function i(n,o,r,s,a,h){if(h!==Qe){var l=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw l.name="Invariant Violation",l}}i.isRequired=i;function t(){return i}var e={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:t,element:i,elementType:i,instanceOf:t,node:i,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:Jt,resetWarningCache:Zt};return e.PropTypes=e,e};Kt.exports=ti();var Qt=Kt.exports;function te(i){var t,e,n="";if(typeof i=="string"||typeof i=="number")n+=i;else if(typeof i=="object")if(Array.isArray(i))for(t=0;t<i.length;t++)i[t]&&(e=te(i[t]))&&(n&&(n+=" "),n+=e);else for(t in i)i[t]&&(n&&(n+=" "),n+=t);return n}function Vt(){for(var i,t,e=0,n="";e<arguments.length;)(i=arguments[e++])&&(t=te(i))&&(n&&(n+=" "),n+=t);return n}const ei=Object.freeze(Object.defineProperty({__proto__:null,clsx:Vt,default:Vt},Symbol.toStringTag,{value:"Module"})),ii=ue(ei);var C={},G={};Object.defineProperty(G,"__esModule",{value:!0});G.dontSetMe=ai;G.findInArray=ni;G.int=si;G.isFunction=oi;G.isNum=ri;function ni(i,t){for(let e=0,n=i.length;e<n;e++)if(t.apply(t,[i[e],e,i]))return i[e]}function oi(i){return typeof i=="function"||Object.prototype.toString.call(i)==="[object Function]"}function ri(i){return typeof i=="number"&&!isNaN(i)}function si(i){return parseInt(i,10)}function ai(i,t,e){if(i[t])return new Error("Invalid prop ".concat(t," passed to ").concat(e," - do not set this, set it on the child."))}var J={};Object.defineProperty(J,"__esModule",{value:!0});J.browserPrefixToKey=ie;J.browserPrefixToStyle=li;J.default=void 0;J.getPrefix=ee;const xt=["Moz","Webkit","O","ms"];function ee(){var i;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"transform";if(typeof window>"u")return"";const e=(i=window.document)===null||i===void 0||(i=i.documentElement)===null||i===void 0?void 0:i.style;if(!e||t in e)return"";for(let n=0;n<xt.length;n++)if(ie(t,xt[n])in e)return xt[n];return""}function ie(i,t){return t?"".concat(t).concat(hi(i)):i}function li(i,t){return t?"-".concat(t.toLowerCase(),"-").concat(i):i}function hi(i){let t="",e=!0;for(let n=0;n<i.length;n++)e?(t+=i[n].toUpperCase(),e=!1):i[n]==="-"?e=!0:t+=i[n];return t}J.default=ee();Object.defineProperty(C,"__esModule",{value:!0});C.addClassName=re;C.addEvent=pi;C.addUserSelectStyles=Pi;C.createCSSTransform=wi;C.createSVGTransform=yi;C.getTouch=Si;C.getTouchIdentifier=xi;C.getTranslation=_t;C.innerHeight=mi;C.innerWidth=vi;C.matchesSelector=oe;C.matchesSelectorAndParentsTo=ui;C.offsetXYFromParent=bi;C.outerHeight=fi;C.outerWidth=gi;C.removeClassName=se;C.removeEvent=di;C.removeUserSelectStyles=Ri;var V=G,Bt=ci(J);function ne(i){if(typeof WeakMap!="function")return null;var t=new WeakMap,e=new WeakMap;return(ne=function(n){return n?e:t})(i)}function ci(i,t){if(i&&i.__esModule)return i;if(i===null||typeof i!="object"&&typeof i!="function")return{default:i};var e=ne(t);if(e&&e.has(i))return e.get(i);var n={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in i)if(r!=="default"&&Object.prototype.hasOwnProperty.call(i,r)){var s=o?Object.getOwnPropertyDescriptor(i,r):null;s&&(s.get||s.set)?Object.defineProperty(n,r,s):n[r]=i[r]}return n.default=i,e&&e.set(i,n),n}let at="";function oe(i,t){return at||(at=(0,V.findInArray)(["matches","webkitMatchesSelector","mozMatchesSelector","msMatchesSelector","oMatchesSelector"],function(e){return(0,V.isFunction)(i[e])})),(0,V.isFunction)(i[at])?i[at](t):!1}function ui(i,t,e){let n=i;do{if(oe(n,t))return!0;if(n===e)return!1;n=n.parentNode}while(n);return!1}function pi(i,t,e,n){if(!i)return;const o={capture:!0,...n};i.addEventListener?i.addEventListener(t,e,o):i.attachEvent?i.attachEvent("on"+t,e):i["on"+t]=e}function di(i,t,e,n){if(!i)return;const o={capture:!0,...n};i.removeEventListener?i.removeEventListener(t,e,o):i.detachEvent?i.detachEvent("on"+t,e):i["on"+t]=null}function fi(i){let t=i.clientHeight;const e=i.ownerDocument.defaultView.getComputedStyle(i);return t+=(0,V.int)(e.borderTopWidth),t+=(0,V.int)(e.borderBottomWidth),t}function gi(i){let t=i.clientWidth;const e=i.ownerDocument.defaultView.getComputedStyle(i);return t+=(0,V.int)(e.borderLeftWidth),t+=(0,V.int)(e.borderRightWidth),t}function mi(i){let t=i.clientHeight;const e=i.ownerDocument.defaultView.getComputedStyle(i);return t-=(0,V.int)(e.paddingTop),t-=(0,V.int)(e.paddingBottom),t}function vi(i){let t=i.clientWidth;const e=i.ownerDocument.defaultView.getComputedStyle(i);return t-=(0,V.int)(e.paddingLeft),t-=(0,V.int)(e.paddingRight),t}function bi(i,t,e){const o=t===t.ownerDocument.body?{left:0,top:0}:t.getBoundingClientRect(),r=(i.clientX+t.scrollLeft-o.left)/e,s=(i.clientY+t.scrollTop-o.top)/e;return{x:r,y:s}}function wi(i,t){const e=_t(i,t,"px");return{[(0,Bt.browserPrefixToKey)("transform",Bt.default)]:e}}function yi(i,t){return _t(i,t,"")}function _t(i,t,e){let{x:n,y:o}=i,r="translate(".concat(n).concat(e,",").concat(o).concat(e,")");if(t){const s="".concat(typeof t.x=="string"?t.x:t.x+e),a="".concat(typeof t.y=="string"?t.y:t.y+e);r="translate(".concat(s,", ").concat(a,")")+r}return r}function Si(i,t){return i.targetTouches&&(0,V.findInArray)(i.targetTouches,e=>t===e.identifier)||i.changedTouches&&(0,V.findInArray)(i.changedTouches,e=>t===e.identifier)}function xi(i){if(i.targetTouches&&i.targetTouches[0])return i.targetTouches[0].identifier;if(i.changedTouches&&i.changedTouches[0])return i.changedTouches[0].identifier}function Pi(i){if(!i)return;let t=i.getElementById("react-draggable-style-el");t||(t=i.createElement("style"),t.type="text/css",t.id="react-draggable-style-el",t.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;}
1
+ import{j as L,_ as he,ca as ce}from"./index-CBNVuWcP.js";import{r as z,R as st}from"./plugin-monaco-C8UgLomw.js";import{a as ue,g as pe}from"./plugin-terminal-MXFIPun8.js";import{r as dt}from"./plugin-notebook-HbW2K-1c.js";import{p as de,_ as fe,a as ge}from"./plugin-pdf-CR8hgQBV.js";const an={A4_WIDTH:595},ln=[.5,.75,1,1.25,1.5,2],me=de,ve=void 0,be=!1;function Mt(i,t){let e;return(...n)=>{e&&clearTimeout(e),e=setTimeout(()=>i(...n),t)}}const Dt=(i,{width:t,height:e})=>({x1:i.left,y1:i.top,x2:i.left+i.width,y2:i.top+i.height,width:t,height:e,pageNumber:i.pageNumber}),we=(i,t)=>{const[e,n,o,r]=t.convertToViewportRectangle([i.x1,i.y1,i.x2,i.y2]);return{left:Math.min(e,o),top:Math.min(n,r),width:Math.abs(o-e),height:Math.abs(n-r),pageNumber:i.pageNumber}},bt=(i,t,e=!1)=>{const{width:n,height:o}=t;if(e)return we(i,t);if(i.x1===void 0)throw new Error("You are using old position format, please update");const r=n*i.x1/i.width,s=o*i.y1/i.height,a=n*i.x2/i.width,h=o*i.y2/i.height;return{left:r,top:s,width:a-r,height:h-s,pageNumber:i.pageNumber}},jt=i=>i.ownerDocument||document,rt=i=>jt(i).defaultView||window,Z=i=>i!=null&&(i instanceof HTMLElement||i instanceof rt(i).HTMLElement),ye=i=>i instanceof HTMLCanvasElement||i instanceof rt(i).HTMLCanvasElement,pt=i=>{const t=i.closest(".page");if(!Z(t))return null;const e=Number(t.dataset.pageNumber);return{node:t,number:e}},Et=i=>{const t=i.startContainer.parentElement,e=i.endContainer.parentElement;if(!Z(t)||!Z(e))return[];const n=pt(t),o=pt(e);if(!n?.number||!o?.number)return[];if(n.number===o.number)return[n];if(n.number===o.number-1)return[n,o];const r=[];let s=n.number;const a=n.node.ownerDocument;for(;s<=o.number;){const h=pt(a.querySelector(`[data-page-number='${s}'`));h&&r.push(h),s++}return r},Se=(i,t,e)=>{const n=jt(i);let o=i.querySelector(e);return o||(o=n.createElement("div"),o.className=t,i.appendChild(o)),o},xe=(i,t)=>{const{left:e,top:n,width:o,height:r}=t,a=(i?i.ownerDocument:null)?.createElement("canvas");if(!a||!ye(a))return"";a.width=o,a.height=r;const h=a.getContext("2d");if(!h||!i)return"";const l=window.devicePixelRatio;return h.drawImage(i,e*l,n*l,o*l,r*l,0,0,o,r),a.toDataURL("image/png")},Ht=i=>{const t=Array.from(i).map(u=>{const{left:g,top:w,width:b,height:y,pageNumber:S}=u,P=g,x=g+b,f=w,p=w+y;return{X0:P,X1:x,Y0:f,Y1:p,pageNumber:S}});let e=Number.MAX_SAFE_INTEGER;for(const u of t)e=Math.min(e,u.pageNumber??e);const n=t.filter(u=>(u.X0>0||u.X1>0||u.Y0>0||u.Y1>0)&&u.pageNumber===e),o=n.reduce((u,g)=>({X0:Math.min(u.X0,g.X0),X1:Math.max(u.X1,g.X1),Y0:Math.min(u.Y0,g.Y0),Y1:Math.max(u.Y1,g.Y1),pageNumber:e}),n[0]),{X0:r,X1:s,Y0:a,Y1:h,pageNumber:l}=o;return{left:r,top:a,width:s-r,height:h-a,pageNumber:l}},Pe=i=>i.sort((t,e)=>{const n=(t.pageNumber||0)*t.top-(e.pageNumber||0)*e.top;return n===0?t.left-e.left:n}),Re=(i,t)=>i.pageNumber===t.pageNumber&&i.left<=t.left&&t.left<=i.left+i.width,ze=(i,t,e=5)=>i.pageNumber===t.pageNumber&&Math.abs(i.top-t.top)<e&&Math.abs(i.height-t.height)<e,De=(i,t)=>i.pageNumber===t.pageNumber&&i.top>t.top&&i.left>t.left&&i.top+i.height<t.top+t.height&&i.left+i.width<t.left+t.width,Te=(i,t,e=10)=>{const n=i.left+i.width,o=t.left+t.width;return i.pageNumber===t.pageNumber&&i.left<=t.left&&n<=o&&t.left-n<=e},Lt=(i,t)=>{i.width=Math.max(t.width-i.left+t.left,i.width)},_e=i=>{const t=Pe(i),e=new Set,n=t.filter(r=>t.every(s=>!De(r,s)));let o=0;for(;o<=2;){for(const r of n)for(const s of n)r===s||e.has(r)||e.has(s)||ze(r,s)&&(Re(r,s)&&(Lt(r,s),r.height=Math.max(r.height,s.height),e.add(s)),Te(r,s)&&(Lt(r,s),e.add(s)));o+=1}return n.filter(r=>!e.has(r))},Ne=(i,t)=>!(i.top<t.top||i.bottom>t.bottom||i.right>t.right||i.left<t.left),Wt=(i,t,e=!0)=>{const n=Array.from(i.getClientRects()),o=[];for(const r of n)for(const s of t){const a=s.node.getBoundingClientRect();if(Ne(r,a)&&r.width>0&&r.height>0&&r.width<a.width&&r.height<a.height){const h={top:r.top+s.node.scrollTop-a.top,left:r.left+s.node.scrollLeft-a.left,width:r.width,height:r.height,pageNumber:s.number};o.push(h)}}return e?_e(o):o},Ce="_container_1vvir_1",Me="_highlightLayer_1vvir_8",Ee="_disableSelection_1vvir_20",wt={container:Ce,highlightLayer:Me,disableSelection:Ee},Ot=10,yt=12,It=8,He=14,Le=17,We=62,Oe=22;function St(i,t,e){return Math.min(Math.max(i,t),e)}function $t(i){return String(i||"").normalize("NFKC").replace(/\uFFFD/g," ").replace(/\s+/g," ").trim()}function Ie(i,t){const e=i.position?.rects?.[0]||i.position?.boundingRect||null;if(!e)return 0;const n=Number(e.top||0),o=Number(e.height||0);return Number.isFinite(n)?Number.isFinite(o)?Math.max(0,n+o*.5-t*.5):Math.max(0,n):0}function Ae(i,t){const e=$t(i);if(!e)return"";const n=e.split(/\s+/).filter(Boolean);return n.length<=t?n.join(" "):`${n.slice(0,t).join(" ")} …`}function Fe(i){const t=i.previewSummary;if(typeof t=="string"&&t.trim())return $t(t);const e=typeof i.comment?.text=="string"?i.comment.text:"";return Ae(e,8)}function Ve(i,t){const e=Fe(i),n=e.length>0,o=Math.max(120,t-Oe),s=Math.max(14,Math.floor(o/6.1)),a=n?Math.max(1,Math.ceil(e.length/s)):0,h=14,l=n?4:0,u=h+He+l+a*Le;return Math.max(We,Math.ceil(u))}function Be(i,t,e){const n=Number.isFinite(t)&&t>0?t:0,o=Number.isFinite(e)&&e>0?e:0,r=Math.max(140,n-yt*2),s=St(n*.34,190,320),a=Math.min(r,s),h=Math.max(yt,n-a-yt),l=i.filter(c=>!c.content?.image).filter(c=>!c.__dsGhost).map(c=>{const m=c,v=Ve(m,a);return{id:String(c.id),cardHeightPx:v,anchorTop:Ie(m,v)}}).sort((c,m)=>c.anchorTop===m.anchorTop?c.id.localeCompare(m.id):c.anchorTop-m.anchorTop),u={};if(l.length===0)return{hintTopById:u,hintLeftPx:h,hintWidthPx:a};const g=It,w=Math.max(g,o-It),b=Math.max(0,w-g),y=l.reduce((c,m)=>c+m.cardHeightPx,0);let S=Ot;if(l.length>1){const c=Math.floor((b-y)/(l.length-1));Number.isFinite(c)&&(S=Math.max(0,Math.min(Ot,c)))}else S=0;const P=new Array(l.length).fill(0);for(let c=l.length-1;c>=0;c-=1){const m=c+1<l.length?P[c+1]:0;P[c]=l[c].cardHeightPx+m}const x=[];let f=g;for(let c=0;c<l.length;c+=1){const m=l[c],v=l.length-c-1,R=P[c]+Math.max(0,v)*Math.max(0,S),_=Math.max(g,w-R),D=St(m.anchorTop,g,_),N=Math.max(D,f);x.push({id:m.id,top:N,cardHeightPx:m.cardHeightPx}),f=N+m.cardHeightPx+S}const p=x[x.length-1],d=p?p.top+p.cardHeightPx:g;if(d>w){const c=d-w;for(let m=0;m<x.length;m+=1)x[m].top=Math.max(g,x[m].top-c)}for(let c=1;c<x.length;c+=1){const m=x[c-1],v=x[c],R=m.top+m.cardHeightPx+S;v.top<R&&(v.top=R)}for(const c of x){const m=Math.max(g,w-c.cardHeightPx);u[c.id]=Math.round(St(c.top,g,m))}return{hintTopById:u,hintLeftPx:h,hintWidthPx:a}}function ke({highlightsByPage:i,scaledPositionToViewport:t,pageNumber:e,scrolledToHighlightId:n,highlightTransform:o,tip:r,hideTipAndSelection:s,viewer:a,screenshot:h,showTip:l,setTip:u}){const g=i[String(e)]||[],w=Number.parseInt(e,10),b=a.getPageView(w-1),y=b?.div?.offsetWidth||b?.div?.getBoundingClientRect().width||b?.viewport?.width||0,S=b?.div?.offsetHeight||b?.div?.getBoundingClientRect().height||b?.viewport?.height||0,P=g.map(f=>({...f,position:t(f.position)})),x=Be(P,y,S);return L.jsx("div",{children:P.map((f,p)=>{const d=f;r&&r.highlight.id===String(d.id)&&l(f,r.callback(f));const c=n===d.id;return o(f,p,(m,v)=>{u({highlight:m,callback:v}),l(m,v(m))},s,m=>{const v=a.getPageView((m.pageNumber||Number.parseInt(e))-1).viewport;return Dt(m,v)},m=>h(m,Number.parseInt(e)),c,{width:y,height:S,pageNumber:w,overlayHintTopById:x.hintTopById,overlayHintLeftPx:x.hintLeftPx,overlayHintWidthPx:x.hintWidthPx})})})}const Xe="_mouseSelection_1p43j_1",Ye={mouseSelection:Xe},At=(i,t)=>({left:Math.min(t.x,i.x),top:Math.min(t.y,i.y),width:Math.abs(t.x-i.x),height:Math.abs(t.y-i.y)}),Ue=i=>i.width>=1&&i.height>=1;function Ge({onSelection:i,onDragStart:t,onDragEnd:e,shouldStart:n,onChange:o}){const[r,s]=z.useState(!1),[a,h]=z.useState(null),[l,u]=z.useState(null),g=z.useRef(null),w=z.useRef(a),b=z.useRef(r);z.useEffect(()=>{w.current=a},[a]),z.useEffect(()=>{b.current=r},[r]);const y=z.useCallback(()=>{e(),h(null),u(null),s(!1)},[e]);return z.useEffect(()=>{o(!!(a&&l))},[a,l,o]),z.useEffect(()=>{const S=g.current;if(!S)return;const P=S.parentElement;if(!P||!Z(P))return;const x=(d,c)=>{const m=P.getBoundingClientRect();return{x:d-m.left+P.scrollLeft,y:c-m.top+P.scrollTop-window.scrollY}},f=d=>{!w.current||b.current||u(x(d.pageX,d.pageY))},p=d=>{if(!n(d)){y();return}const c=d.target;if(!(c instanceof Element)||!Z(c))return;t(),h(x(d.pageX,d.pageY)),u(null),s(!1);const m=R=>{R.currentTarget?.removeEventListener("mouseup",m);const _=w.current;if(!_||!(R instanceof MouseEvent))return;const D=x(R.pageX,R.pageY),N=At(_,D);if(!(R.target instanceof Element)||!Z(R.target)||!P.contains(R.target)||!Ue(N)){y();return}u(D),s(!0),i(c,N,y),e()},v=P.ownerDocument;v?.body&&v.body.addEventListener("mouseup",m)};return P.addEventListener("mousemove",f),P.addEventListener("mousedown",p),()=>{P.removeEventListener("mousemove",f),P.removeEventListener("mousedown",p)}},[n,t,e,i,y]),L.jsx("div",{ref:g,children:a&&l&&L.jsx("div",{className:Ye.mouseSelection,style:At(a,l)})})}const je="_tipContainer_f56kr_1",$e={tipContainer:je};function nt(i,t,e){return Math.min(Math.max(i,t),e)}function qe({children:i,style:t,scrollTop:e,pageBoundingRect:n,pageOffset:o,tipPlacementMode:r="auto"}){const[s,a]=z.useState(0),[h,l]=z.useState(0),u=z.useRef(null),g=z.useCallback(()=>{if(!u.current)return;const{offsetHeight:M,offsetWidth:$}=u.current;a(M),l($)},[]);z.useEffect(()=>{setTimeout(g,0)},[g]),z.useEffect(()=>{if(!u.current||typeof ResizeObserver>"u")return;const M=new ResizeObserver(()=>{g()});return M.observe(u.current),()=>M.disconnect()},[g]);const w=h===0&&s===0,b=12,y=o.left,S=o.top,P=y+b,x=y+n.width-h-b,f=S+b,p=S+n.height-s-b,d=(t.selectionLeft+t.selectionRight)/2,c=y+n.width-t.selectionRight-b,m=t.selectionLeft-y-b;let v=nt(d-h/2,P,x),R=nt(t.selectionTop,f,p);const _=c>=h,D=m>=h,N=r==="overlay",T=r==="right",O=t.selectionTop-s-b<e;if(T){v=x;const M=t.selectionTop+(t.selectionBottom-t.selectionTop)/2-s/2;R=nt(M,f,p)}else!N&&_?v=t.selectionRight+b:!N&&D?v=t.selectionLeft-h-b:(R=O?t.selectionBottom+b:t.selectionTop-s-b,R=nt(R,f,p),v=nt(d-h/2,P,x));const B=z.useCallback(()=>{l(0),a(0),setTimeout(g,0)},[g]),Y=st.Children.map(i,M=>M!=null?st.cloneElement(M,{onUpdate:B,popup:{position:O?"below":"above"}}):null);return L.jsx("div",{id:"PdfHighlighter__tip-container",className:$e.tipContainer,style:{visibility:w?"hidden":"visible",top:R,left:v},ref:u,children:Y})}const Ft="empty-id",Ke="__ds_ghost__";class hn extends z.PureComponent{static defaultProps={pdfScaleValue:"auto"};state={ghostHighlight:null,isCollapsed:!0,range:null,scrolledToHighlightId:Ft,isAreaSelectionInProgress:!1,tip:null,tipPosition:null,tipChildren:null,pinnedTipHighlightId:null};viewer;resizeObserver=null;containerNode=null;containerNodeRef;highlightRoots={};highlightRootByContainer=new WeakMap;unsubscribe=()=>{};selectionRafId=null;scrollPageIntoViewPatched=!1;scrollMatchIntoViewPatched=!1;constructor(t){super(t),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(this.debouncedScaleValue)),this.containerNodeRef=st.createRef()}componentDidMount(){this.init()}onPageChanging=t=>{const e=t?.pageNumber;typeof e=="number"&&this.props.onPageChange?.(e)};attachRef=t=>{const{resizeObserver:e}=this;if(this.containerNode=this.containerNodeRef.current,this.unsubscribe(),this.containerNode){const{ownerDocument:n}=this.containerNode;t.on("textlayerrendered",this.onTextLayerRendered),t.on("pagesinit",this.onDocumentReady),t.on("pagechanging",this.onPageChanging),n.addEventListener("selectionchange",this.onSelectionChange),n.addEventListener("keydown",this.handleKeyDown),n.defaultView?.addEventListener("resize",this.debouncedScaleValue),e&&e.observe(this.containerNode),this.unsubscribe=()=>{t.off("pagesinit",this.onDocumentReady),t.off("textlayerrendered",this.onTextLayerRendered),t.off("pagechanging",this.onPageChanging),n.removeEventListener("selectionchange",this.onSelectionChange),n.removeEventListener("keydown",this.handleKeyDown),n.defaultView?.removeEventListener("resize",this.debouncedScaleValue),e&&e.disconnect()}}};componentDidUpdate(t){if(t.pdfDocument!==this.props.pdfDocument){this.init();return}if(t.pdfScaleValue!==this.props.pdfScaleValue&&this.handleScaleValue(),t.highlights!==this.props.highlights){this.renderHighlightLayers();const e=this.state.pinnedTipHighlightId;if(e){const n=this.state.tip&&String(this.state.tip.highlight.id)===e?this.state.tip.callback:void 0;this.setPinnedTipForHighlight(e,n)}}}findViewportHighlightById(t){const e=this.props.highlights.find(n=>String(n.id)===String(t));return e?{...e,position:this.scaledPositionToViewport(e.position)}:null}setPinnedTipForHighlight=(t,e)=>{if(!t){this.setState({pinnedTipHighlightId:null,tip:null,tipPosition:null,tipChildren:null},()=>this.renderHighlightLayers());return}const n=this.findViewportHighlightById(t);if(!n){this.setState({pinnedTipHighlightId:null,tip:null,tipPosition:null,tipChildren:null},()=>this.renderHighlightLayers());return}const o=e||(this.state.tip&&String(this.state.tip.highlight.id)===String(t)?this.state.tip.callback:void 0);o&&this.setState({pinnedTipHighlightId:String(t),tip:{highlight:n,callback:o}},()=>{this.setTip(n.position,o(n)),this.renderHighlightLayers()})};async init(){const{pdfDocument:t,pdfViewerOptions:e}=this.props,n=await he(()=>import("./plugin-pdf-CR8hgQBV.js").then(s=>s.b),[]),o=new n.EventBus,r=new n.PDFLinkService({eventBus:o,externalLinkTarget:2});this.containerNodeRef.current&&(this.viewer=this.viewer||new n.PDFViewer({container:this.containerNodeRef.current,eventBus:o,textLayerMode:2,removePageBorders:!0,linkService:r,...e}),this.patchScrollPageIntoView(),this.patchScrollMatchIntoView(n),r.setDocument(t),r.setViewer(this.viewer),this.viewer.setDocument(t),this.attachRef(o))}patchScrollPageIntoView(){if(this.scrollPageIntoViewPatched||!this.viewer)return;const t=this.viewer.scrollPageIntoView.bind(this.viewer);this.viewer.scrollPageIntoView=e=>{if(!this.isViewerScrollable())return;const n=e?.pageNumber;if(typeof n=="number"){const o=this.viewer.getPageView(n-1);if(!o?.div||!o.div.offsetParent)return}t(e)},this.scrollPageIntoViewPatched=!0}patchScrollMatchIntoView(t){if(this.scrollMatchIntoViewPatched)return;const e=t?.PDFFindController?.prototype;if(!e||typeof e.scrollMatchIntoView!="function")return;const n=e.scrollMatchIntoView;e.scrollMatchIntoView=function(o={}){const r=o.element;if(!(!r||!r.isConnected||!r.offsetParent))return n.call(this,o)},this.scrollMatchIntoViewPatched=!0}componentWillUnmount(){Object.values(this.highlightRoots).forEach(t=>{try{t.reactRoot.unmount()}catch{}}),this.highlightRoots={},this.highlightRootByContainer=new WeakMap,this.unsubscribe()}findOrCreateHighlightLayer(t){if(!this.viewer)return null;const{textLayer:e}=this.viewer.getPageView(t-1)||{};return e?Se(e.div,`PdfHighlighter__highlight-layer ${wt.highlightLayer}`,".PdfHighlighter__highlight-layer"):null}groupHighlightsByPage(t){const{ghostHighlight:e}=this.state,n=[...t,e].filter(Boolean),o=new Set;for(const s of n){o.add(s.position.pageNumber);for(const a of s.position.rects)a.pageNumber&&o.add(a.pageNumber)}const r={};for(const s of o){r[s]=r[s]||[];for(const a of n){const h={...a,position:{pageNumber:s,boundingRect:a.position.boundingRect,rects:[],usePdfCoordinates:a.position.usePdfCoordinates}};let l=!1;for(const u of a.position.rects)s===(u.pageNumber||a.position.pageNumber)&&(h.position.rects.push(u),l=!0);(l||s===a.position.pageNumber)&&r[s].push(h)}}return r}showTip(t,e){const{isCollapsed:n,ghostHighlight:o,isAreaSelectionInProgress:r,pinnedTipHighlightId:s}=this.state;s&&String(t.id)!==String(s)||!n||o||r||this.setTip(t.position,e)}scaledPositionToViewport({pageNumber:t,boundingRect:e,rects:n,usePdfCoordinates:o}){const r=this.viewer.getPageView(t-1).viewport;return{boundingRect:bt(e,r,o),rects:(n||[]).map(s=>bt(s,r,o)),pageNumber:t}}viewportPositionToScaled({pageNumber:t,boundingRect:e,rects:n}){const o=this.viewer.getPageView(t-1).viewport;return{boundingRect:Dt(e,o),rects:(n||[]).map(r=>Dt(r,o)),pageNumber:t}}screenshot(t,e){const n=this.viewer.getPageView(e-1).canvas;return xe(n,t)}hideTipAndSelection=()=>{if(this.state.pinnedTipHighlightId)return;this.selectionRafId!=null&&(cancelAnimationFrame(this.selectionRafId),this.selectionRafId=null);const t=this.containerNode;t&&rt(t).getSelection()?.removeAllRanges(),this.setState({tipPosition:null,tipChildren:null,ghostHighlight:null,tip:null,range:null,isCollapsed:!0},()=>this.renderHighlightLayers())};buildGhostHighlight(t,e){return{__dsGhost:!0,id:Ke,position:t,content:e?{text:e}:void 0,comment:{text:"",emoji:"note"}}}scheduleGhostHighlightUpdate(t){this.selectionRafId!=null&&cancelAnimationFrame(this.selectionRafId),this.selectionRafId=requestAnimationFrame(()=>{this.selectionRafId=null;const{isAreaSelectionInProgress:e}=this.state;if(e)return;const n=Et(t);if(!n||n.length===0)return;const o=Wt(t,n);if(o.length===0)return;const s={boundingRect:Ht(o),rects:o,pageNumber:n[0].number},a=this.viewportPositionToScaled(s),h=this.buildGhostHighlight(a,t.toString());this.setState({ghostHighlight:h},()=>this.renderHighlightLayers())})}setTip(t,e){this.setState({tipPosition:t,tipChildren:e})}renderTip=()=>{const{tipPosition:t,tipChildren:e}=this.state;if(!t)return null;const{boundingRect:n,pageNumber:o}=t,r={node:this.viewer.getPageView((n.pageNumber||o)-1).div,pageNumber:n.pageNumber||o},s=r.node.getBoundingClientRect(),a={bottom:s.bottom,height:s.height,left:s.left,right:s.right,top:s.top,width:s.width,x:s.x,y:s.y,pageNumber:r.pageNumber},h=r.node.offsetLeft+n.left,l=h+n.width,u=n.top+r.node.offsetTop,g=u+n.height;return L.jsx(qe,{scrollTop:this.viewer.container.scrollTop,pageBoundingRect:a,pageOffset:{left:r.node.offsetLeft,top:r.node.offsetTop},tipPlacementMode:this.props.tipPlacementMode,style:{selectionLeft:h,selectionRight:l,selectionTop:u,selectionBottom:g},children:e})};onTextLayerRendered=()=>{this.renderHighlightLayers()};isViewerScrollable=()=>{const t=this.viewer?.container;return!t||!t.isConnected?!1:!!t.offsetParent};scrollTo=t=>{const{pageNumber:e,boundingRect:n,usePdfCoordinates:o}=t.position;if(!this.isViewerScrollable()){this.setState({scrolledToHighlightId:t.id},()=>this.renderHighlightLayers());return}const r=this.viewer.getPageView(e-1);if(!r?.div||!r.div.offsetParent)return;this.viewer.container.removeEventListener("scroll",this.onScroll);const s=r.viewport;this.viewer.scrollPageIntoView({pageNumber:e,destArray:[null,{name:"XYZ"},...s.convertToPdfPoint(0,bt(n,s,o).top-10),0]}),this.setState({scrolledToHighlightId:t.id},()=>this.renderHighlightLayers()),setTimeout(()=>{this.viewer.container.addEventListener("scroll",this.onScroll)},100)};scrollToPage=t=>{this.viewer&&this.isViewerScrollable()&&(this.viewer.currentPageNumber=t)};onDocumentReady=()=>{const{scrollRef:t}=this.props;this.handleScaleValue(),t(this.scrollTo),this.props.onPageChange?.(this.viewer.currentPageNumber||1)};onSelectionChange=()=>{const t=this.containerNode;if(!t)return;const e=rt(t).getSelection();if(!e)return;const n=e.rangeCount>0?e.getRangeAt(0):null;if(e.isCollapsed){this.setState({isCollapsed:!0,range:null,ghostHighlight:null},()=>this.renderHighlightLayers());return}if(!n||!t||!t.contains(n.commonAncestorContainer))return;const o=n.cloneRange();this.setState({isCollapsed:!1,range:o}),this.scheduleGhostHighlightUpdate(o),this.debouncedAfterSelection()};onScroll=()=>{const{onScrollChange:t}=this.props;t(),this.setState({scrolledToHighlightId:Ft},()=>this.renderHighlightLayers()),this.viewer.container.removeEventListener("scroll",this.onScroll)};onMouseDown=t=>{this.state.pinnedTipHighlightId||!(t.target instanceof Element)||!Z(t.target)||t.target.closest("#PdfHighlighter__tip-container")||this.hideTipAndSelection()};handleKeyDown=t=>{this.state.pinnedTipHighlightId||t.code==="Escape"&&this.hideTipAndSelection()};afterSelection=()=>{const{onSelectionFinished:t}=this.props,e=this.containerNode;if(!e)return;const n=rt(e).getSelection(),o=n&&n.rangeCount>0?n.getRangeAt(0):null,{isCollapsed:r}=this.state;if(!o||r||n?.isCollapsed)return;const s=o.cloneRange(),a=Et(s);if(!a||a.length===0)return;const h=Wt(s,a);if(h.length===0)return;const u={boundingRect:Ht(h),rects:h,pageNumber:a[0].number},g={text:s.toString()},w=this.viewportPositionToScaled(u);this.setTip(u,t(w,g,()=>this.hideTipAndSelection(),()=>this.setState({ghostHighlight:this.buildGhostHighlight(w,g.text)},()=>this.renderHighlightLayers())))};debouncedAfterSelection=Mt(this.afterSelection,320);toggleTextSelection(t){this.viewer.viewer&&this.viewer.viewer.classList.toggle(wt.disableSelection,t)}handleScaleValue=()=>{if(!this.viewer)return;const t=this.props.pdfScaleValue,e="page-width:";if(t.startsWith(e)){const n=Number.parseFloat(t.slice(e.length));if(!Number.isFinite(n)||n<=0){this.viewer.currentScaleValue="page-width";return}this.viewer.currentScaleValue="page-width";const o=this.viewer.currentScale;if(!Number.isFinite(o)||o<=0)return;this.viewer.currentScaleValue=String(o*n);return}this.viewer.currentScaleValue=t};debouncedScaleValue=Mt(this.handleScaleValue,500);render(){const{onSelectionFinished:t,enableAreaSelection:e}=this.props;return L.jsx("div",{onPointerDown:this.onMouseDown,children:L.jsxs("div",{ref:this.containerNodeRef,className:wt.container,style:{position:"absolute",width:"100%",height:"100%",overflow:"auto"},onContextMenu:n=>n.preventDefault(),children:[L.jsx("div",{className:"pdfViewer"}),this.renderTip(),typeof e=="function"?L.jsx(Ge,{onDragStart:()=>this.toggleTextSelection(!0),onDragEnd:()=>this.toggleTextSelection(!1),onChange:n=>this.setState({isAreaSelectionInProgress:n}),shouldStart:n=>e(n)&&n.target instanceof Element&&Z(n.target)&&!!n.target.closest(".page"),onSelection:(n,o,r)=>{const s=pt(n);if(!s)return;const a={...o,top:o.top-s.node.offsetTop,left:o.left-s.node.offsetLeft,pageNumber:s.number},h={boundingRect:a,rects:[],pageNumber:s.number},l=this.viewportPositionToScaled(h),u=this.screenshot(a,a.pageNumber);this.setTip(h,t(l,{image:u},()=>this.hideTipAndSelection(),()=>{console.log("setting ghost highlight",l),this.setState({ghostHighlight:{position:l,content:{image:u}}},()=>{r(),this.renderHighlightLayers()})}))}}):null]})})}renderHighlightLayers(){const{pdfDocument:t}=this.props;if(this.viewer)for(let e=1;e<=t.numPages;e++){const n=this.highlightRoots[e];if(n?.container.isConnected)this.renderHighlightLayer(n.reactRoot,e);else{const o=this.findOrCreateHighlightLayer(e);if(o){const r=this.getOrCreateHighlightRoot(o);this.highlightRoots[e]={reactRoot:r,container:o},this.renderHighlightLayer(r,e)}}}}getOrCreateHighlightRoot(t){const e=this.highlightRootByContainer.get(t);if(e)return e;const n=ce(t);return this.highlightRootByContainer.set(t,n),n}renderHighlightLayer(t,e){const{highlightTransform:n,highlights:o}=this.props,{tip:r,scrolledToHighlightId:s}=this.state;t.render(L.jsx(ke,{highlightsByPage:this.groupHighlightsByPage(o),pageNumber:e.toString(),scrolledToHighlightId:s,highlightTransform:n,tip:r,scaledPositionToViewport:this.scaledPositionToViewport.bind(this),hideTipAndSelection:this.hideTipAndSelection.bind(this),viewer:this.viewer,screenshot:this.screenshot.bind(this),showTip:this.showTip.bind(this),setTip:a=>{this.state.pinnedTipHighlightId&&String(a.highlight.id)!==String(this.state.pinnedTipHighlightId)||this.setState({tip:a})}}))}}var ft={exports:{}},qt={},Kt={exports:{}},Ze="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",Je=Ze,Qe=Je;function Zt(){}function Jt(){}Jt.resetWarningCache=Zt;var ti=function(){function i(n,o,r,s,a,h){if(h!==Qe){var l=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw l.name="Invariant Violation",l}}i.isRequired=i;function t(){return i}var e={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:t,element:i,elementType:i,instanceOf:t,node:i,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:Jt,resetWarningCache:Zt};return e.PropTypes=e,e};Kt.exports=ti();var Qt=Kt.exports;function te(i){var t,e,n="";if(typeof i=="string"||typeof i=="number")n+=i;else if(typeof i=="object")if(Array.isArray(i))for(t=0;t<i.length;t++)i[t]&&(e=te(i[t]))&&(n&&(n+=" "),n+=e);else for(t in i)i[t]&&(n&&(n+=" "),n+=t);return n}function Vt(){for(var i,t,e=0,n="";e<arguments.length;)(i=arguments[e++])&&(t=te(i))&&(n&&(n+=" "),n+=t);return n}const ei=Object.freeze(Object.defineProperty({__proto__:null,clsx:Vt,default:Vt},Symbol.toStringTag,{value:"Module"})),ii=ue(ei);var C={},G={};Object.defineProperty(G,"__esModule",{value:!0});G.dontSetMe=ai;G.findInArray=ni;G.int=si;G.isFunction=oi;G.isNum=ri;function ni(i,t){for(let e=0,n=i.length;e<n;e++)if(t.apply(t,[i[e],e,i]))return i[e]}function oi(i){return typeof i=="function"||Object.prototype.toString.call(i)==="[object Function]"}function ri(i){return typeof i=="number"&&!isNaN(i)}function si(i){return parseInt(i,10)}function ai(i,t,e){if(i[t])return new Error("Invalid prop ".concat(t," passed to ").concat(e," - do not set this, set it on the child."))}var J={};Object.defineProperty(J,"__esModule",{value:!0});J.browserPrefixToKey=ie;J.browserPrefixToStyle=li;J.default=void 0;J.getPrefix=ee;const xt=["Moz","Webkit","O","ms"];function ee(){var i;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"transform";if(typeof window>"u")return"";const e=(i=window.document)===null||i===void 0||(i=i.documentElement)===null||i===void 0?void 0:i.style;if(!e||t in e)return"";for(let n=0;n<xt.length;n++)if(ie(t,xt[n])in e)return xt[n];return""}function ie(i,t){return t?"".concat(t).concat(hi(i)):i}function li(i,t){return t?"-".concat(t.toLowerCase(),"-").concat(i):i}function hi(i){let t="",e=!0;for(let n=0;n<i.length;n++)e?(t+=i[n].toUpperCase(),e=!1):i[n]==="-"?e=!0:t+=i[n];return t}J.default=ee();Object.defineProperty(C,"__esModule",{value:!0});C.addClassName=re;C.addEvent=pi;C.addUserSelectStyles=Pi;C.createCSSTransform=wi;C.createSVGTransform=yi;C.getTouch=Si;C.getTouchIdentifier=xi;C.getTranslation=_t;C.innerHeight=mi;C.innerWidth=vi;C.matchesSelector=oe;C.matchesSelectorAndParentsTo=ui;C.offsetXYFromParent=bi;C.outerHeight=fi;C.outerWidth=gi;C.removeClassName=se;C.removeEvent=di;C.removeUserSelectStyles=Ri;var V=G,Bt=ci(J);function ne(i){if(typeof WeakMap!="function")return null;var t=new WeakMap,e=new WeakMap;return(ne=function(n){return n?e:t})(i)}function ci(i,t){if(i&&i.__esModule)return i;if(i===null||typeof i!="object"&&typeof i!="function")return{default:i};var e=ne(t);if(e&&e.has(i))return e.get(i);var n={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in i)if(r!=="default"&&Object.prototype.hasOwnProperty.call(i,r)){var s=o?Object.getOwnPropertyDescriptor(i,r):null;s&&(s.get||s.set)?Object.defineProperty(n,r,s):n[r]=i[r]}return n.default=i,e&&e.set(i,n),n}let at="";function oe(i,t){return at||(at=(0,V.findInArray)(["matches","webkitMatchesSelector","mozMatchesSelector","msMatchesSelector","oMatchesSelector"],function(e){return(0,V.isFunction)(i[e])})),(0,V.isFunction)(i[at])?i[at](t):!1}function ui(i,t,e){let n=i;do{if(oe(n,t))return!0;if(n===e)return!1;n=n.parentNode}while(n);return!1}function pi(i,t,e,n){if(!i)return;const o={capture:!0,...n};i.addEventListener?i.addEventListener(t,e,o):i.attachEvent?i.attachEvent("on"+t,e):i["on"+t]=e}function di(i,t,e,n){if(!i)return;const o={capture:!0,...n};i.removeEventListener?i.removeEventListener(t,e,o):i.detachEvent?i.detachEvent("on"+t,e):i["on"+t]=null}function fi(i){let t=i.clientHeight;const e=i.ownerDocument.defaultView.getComputedStyle(i);return t+=(0,V.int)(e.borderTopWidth),t+=(0,V.int)(e.borderBottomWidth),t}function gi(i){let t=i.clientWidth;const e=i.ownerDocument.defaultView.getComputedStyle(i);return t+=(0,V.int)(e.borderLeftWidth),t+=(0,V.int)(e.borderRightWidth),t}function mi(i){let t=i.clientHeight;const e=i.ownerDocument.defaultView.getComputedStyle(i);return t-=(0,V.int)(e.paddingTop),t-=(0,V.int)(e.paddingBottom),t}function vi(i){let t=i.clientWidth;const e=i.ownerDocument.defaultView.getComputedStyle(i);return t-=(0,V.int)(e.paddingLeft),t-=(0,V.int)(e.paddingRight),t}function bi(i,t,e){const o=t===t.ownerDocument.body?{left:0,top:0}:t.getBoundingClientRect(),r=(i.clientX+t.scrollLeft-o.left)/e,s=(i.clientY+t.scrollTop-o.top)/e;return{x:r,y:s}}function wi(i,t){const e=_t(i,t,"px");return{[(0,Bt.browserPrefixToKey)("transform",Bt.default)]:e}}function yi(i,t){return _t(i,t,"")}function _t(i,t,e){let{x:n,y:o}=i,r="translate(".concat(n).concat(e,",").concat(o).concat(e,")");if(t){const s="".concat(typeof t.x=="string"?t.x:t.x+e),a="".concat(typeof t.y=="string"?t.y:t.y+e);r="translate(".concat(s,", ").concat(a,")")+r}return r}function Si(i,t){return i.targetTouches&&(0,V.findInArray)(i.targetTouches,e=>t===e.identifier)||i.changedTouches&&(0,V.findInArray)(i.changedTouches,e=>t===e.identifier)}function xi(i){if(i.targetTouches&&i.targetTouches[0])return i.targetTouches[0].identifier;if(i.changedTouches&&i.changedTouches[0])return i.changedTouches[0].identifier}function Pi(i){if(!i)return;let t=i.getElementById("react-draggable-style-el");t||(t=i.createElement("style"),t.type="text/css",t.id="react-draggable-style-el",t.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;}
2
2
  `,t.innerHTML+=`.react-draggable-transparent-selection *::selection {all: inherit;}
3
3
  `,i.getElementsByTagName("head")[0].appendChild(t)),i.body&&re(i.body,"react-draggable-transparent-selection")}function Ri(i){if(i)try{if(i.body&&se(i.body,"react-draggable-transparent-selection"),i.selection)i.selection.empty();else{const t=(i.defaultView||window).getSelection();t&&t.type!=="Caret"&&t.removeAllRanges()}}catch{}}function re(i,t){i.classList?i.classList.add(t):i.className.match(new RegExp("(?:^|\\s)".concat(t,"(?!\\S)")))||(i.className+=" ".concat(t))}function se(i,t){i.classList?i.classList.remove(t):i.className=i.className.replace(new RegExp("(?:^|\\s)".concat(t,"(?!\\S)"),"g"),"")}var j={};Object.defineProperty(j,"__esModule",{value:!0});j.canDragX=Ti;j.canDragY=_i;j.createCoreData=Ci;j.createDraggableData=Mi;j.getBoundPosition=zi;j.getControlPosition=Ni;j.snapToGrid=Di;var F=G,it=C;function zi(i,t,e){if(!i.props.bounds)return[t,e];let{bounds:n}=i.props;n=typeof n=="string"?n:Ei(n);const o=Nt(i);if(typeof n=="string"){const{ownerDocument:r}=o,s=r.defaultView;let a;if(n==="parent"?a=o.parentNode:a=r.querySelector(n),!(a instanceof s.HTMLElement))throw new Error('Bounds selector "'+n+'" could not find an element.');const h=a,l=s.getComputedStyle(o),u=s.getComputedStyle(h);n={left:-o.offsetLeft+(0,F.int)(u.paddingLeft)+(0,F.int)(l.marginLeft),top:-o.offsetTop+(0,F.int)(u.paddingTop)+(0,F.int)(l.marginTop),right:(0,it.innerWidth)(h)-(0,it.outerWidth)(o)-o.offsetLeft+(0,F.int)(u.paddingRight)-(0,F.int)(l.marginRight),bottom:(0,it.innerHeight)(h)-(0,it.outerHeight)(o)-o.offsetTop+(0,F.int)(u.paddingBottom)-(0,F.int)(l.marginBottom)}}return(0,F.isNum)(n.right)&&(t=Math.min(t,n.right)),(0,F.isNum)(n.bottom)&&(e=Math.min(e,n.bottom)),(0,F.isNum)(n.left)&&(t=Math.max(t,n.left)),(0,F.isNum)(n.top)&&(e=Math.max(e,n.top)),[t,e]}function Di(i,t,e){const n=Math.round(t/i[0])*i[0],o=Math.round(e/i[1])*i[1];return[n,o]}function Ti(i){return i.props.axis==="both"||i.props.axis==="x"}function _i(i){return i.props.axis==="both"||i.props.axis==="y"}function Ni(i,t,e){const n=typeof t=="number"?(0,it.getTouch)(i,t):null;if(typeof t=="number"&&!n)return null;const o=Nt(e),r=e.props.offsetParent||o.offsetParent||o.ownerDocument.body;return(0,it.offsetXYFromParent)(n||i,r,e.props.scale)}function Ci(i,t,e){const n=!(0,F.isNum)(i.lastX),o=Nt(i);return n?{node:o,deltaX:0,deltaY:0,lastX:t,lastY:e,x:t,y:e}:{node:o,deltaX:t-i.lastX,deltaY:e-i.lastY,lastX:i.lastX,lastY:i.lastY,x:t,y:e}}function Mi(i,t){const e=i.props.scale;return{node:t.node,x:i.state.x+t.deltaX/e,y:i.state.y+t.deltaY/e,deltaX:t.deltaX/e,deltaY:t.deltaY/e,lastX:i.state.x,lastY:i.state.y}}function Ei(i){return{left:i.left,top:i.top,right:i.right,bottom:i.bottom}}function Nt(i){const t=i.findDOMNode();if(!t)throw new Error("<DraggableCore>: Unmounted during event!");return t}var gt={},mt={};Object.defineProperty(mt,"__esModule",{value:!0});mt.default=Hi;function Hi(){}Object.defineProperty(gt,"__esModule",{value:!0});gt.default=void 0;var Pt=Wi(z),A=Ct(Qt),Li=Ct(dt),W=C,q=j,Rt=G,ot=Ct(mt);function Ct(i){return i&&i.__esModule?i:{default:i}}function ae(i){if(typeof WeakMap!="function")return null;var t=new WeakMap,e=new WeakMap;return(ae=function(n){return n?e:t})(i)}function Wi(i,t){if(i&&i.__esModule)return i;if(i===null||typeof i!="object"&&typeof i!="function")return{default:i};var e=ae(t);if(e&&e.has(i))return e.get(i);var n={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in i)if(r!=="default"&&Object.prototype.hasOwnProperty.call(i,r)){var s=o?Object.getOwnPropertyDescriptor(i,r):null;s&&(s.get||s.set)?Object.defineProperty(n,r,s):n[r]=i[r]}return n.default=i,e&&e.set(i,n),n}function I(i,t,e){return t=Oi(t),t in i?Object.defineProperty(i,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):i[t]=e,i}function Oi(i){var t=Ii(i,"string");return typeof t=="symbol"?t:String(t)}function Ii(i,t){if(typeof i!="object"||i===null)return i;var e=i[Symbol.toPrimitive];if(e!==void 0){var n=e.call(i,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(i)}const X={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}};let K=X.mouse,vt=class extends Pt.Component{constructor(){super(...arguments),I(this,"dragging",!1),I(this,"lastX",NaN),I(this,"lastY",NaN),I(this,"touchIdentifier",null),I(this,"mounted",!1),I(this,"handleDragStart",t=>{if(this.props.onMouseDown(t),!this.props.allowAnyClick&&typeof t.button=="number"&&t.button!==0)return!1;const e=this.findDOMNode();if(!e||!e.ownerDocument||!e.ownerDocument.body)throw new Error("<DraggableCore> not mounted on DragStart!");const{ownerDocument:n}=e;if(this.props.disabled||!(t.target instanceof n.defaultView.Node)||this.props.handle&&!(0,W.matchesSelectorAndParentsTo)(t.target,this.props.handle,e)||this.props.cancel&&(0,W.matchesSelectorAndParentsTo)(t.target,this.props.cancel,e))return;t.type==="touchstart"&&t.preventDefault();const o=(0,W.getTouchIdentifier)(t);this.touchIdentifier=o;const r=(0,q.getControlPosition)(t,o,this);if(r==null)return;const{x:s,y:a}=r,h=(0,q.createCoreData)(this,s,a);(0,ot.default)("DraggableCore: handleDragStart: %j",h),(0,ot.default)("calling",this.props.onStart),!(this.props.onStart(t,h)===!1||this.mounted===!1)&&(this.props.enableUserSelectHack&&(0,W.addUserSelectStyles)(n),this.dragging=!0,this.lastX=s,this.lastY=a,(0,W.addEvent)(n,K.move,this.handleDrag),(0,W.addEvent)(n,K.stop,this.handleDragStop))}),I(this,"handleDrag",t=>{const e=(0,q.getControlPosition)(t,this.touchIdentifier,this);if(e==null)return;let{x:n,y:o}=e;if(Array.isArray(this.props.grid)){let a=n-this.lastX,h=o-this.lastY;if([a,h]=(0,q.snapToGrid)(this.props.grid,a,h),!a&&!h)return;n=this.lastX+a,o=this.lastY+h}const r=(0,q.createCoreData)(this,n,o);if((0,ot.default)("DraggableCore: handleDrag: %j",r),this.props.onDrag(t,r)===!1||this.mounted===!1){try{this.handleDragStop(new MouseEvent("mouseup"))}catch{const h=document.createEvent("MouseEvents");h.initMouseEvent("mouseup",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),this.handleDragStop(h)}return}this.lastX=n,this.lastY=o}),I(this,"handleDragStop",t=>{if(!this.dragging)return;const e=(0,q.getControlPosition)(t,this.touchIdentifier,this);if(e==null)return;let{x:n,y:o}=e;if(Array.isArray(this.props.grid)){let h=n-this.lastX||0,l=o-this.lastY||0;[h,l]=(0,q.snapToGrid)(this.props.grid,h,l),n=this.lastX+h,o=this.lastY+l}const r=(0,q.createCoreData)(this,n,o);if(this.props.onStop(t,r)===!1||this.mounted===!1)return!1;const a=this.findDOMNode();a&&this.props.enableUserSelectHack&&(0,W.removeUserSelectStyles)(a.ownerDocument),(0,ot.default)("DraggableCore: handleDragStop: %j",r),this.dragging=!1,this.lastX=NaN,this.lastY=NaN,a&&((0,ot.default)("DraggableCore: Removing handlers"),(0,W.removeEvent)(a.ownerDocument,K.move,this.handleDrag),(0,W.removeEvent)(a.ownerDocument,K.stop,this.handleDragStop))}),I(this,"onMouseDown",t=>(K=X.mouse,this.handleDragStart(t))),I(this,"onMouseUp",t=>(K=X.mouse,this.handleDragStop(t))),I(this,"onTouchStart",t=>(K=X.touch,this.handleDragStart(t))),I(this,"onTouchEnd",t=>(K=X.touch,this.handleDragStop(t)))}componentDidMount(){this.mounted=!0;const t=this.findDOMNode();t&&(0,W.addEvent)(t,X.touch.start,this.onTouchStart,{passive:!1})}componentWillUnmount(){this.mounted=!1;const t=this.findDOMNode();if(t){const{ownerDocument:e}=t;(0,W.removeEvent)(e,X.mouse.move,this.handleDrag),(0,W.removeEvent)(e,X.touch.move,this.handleDrag),(0,W.removeEvent)(e,X.mouse.stop,this.handleDragStop),(0,W.removeEvent)(e,X.touch.stop,this.handleDragStop),(0,W.removeEvent)(t,X.touch.start,this.onTouchStart,{passive:!1}),this.props.enableUserSelectHack&&(0,W.removeUserSelectStyles)(e)}}findDOMNode(){var t,e;return(t=this.props)!==null&&t!==void 0&&t.nodeRef?(e=this.props)===null||e===void 0||(e=e.nodeRef)===null||e===void 0?void 0:e.current:Li.default.findDOMNode(this)}render(){return Pt.cloneElement(Pt.Children.only(this.props.children),{onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}};gt.default=vt;I(vt,"displayName","DraggableCore");I(vt,"propTypes",{allowAnyClick:A.default.bool,children:A.default.node.isRequired,disabled:A.default.bool,enableUserSelectHack:A.default.bool,offsetParent:function(i,t){if(i[t]&&i[t].nodeType!==1)throw new Error("Draggable's offsetParent must be a DOM Node.")},grid:A.default.arrayOf(A.default.number),handle:A.default.string,cancel:A.default.string,nodeRef:A.default.object,onStart:A.default.func,onDrag:A.default.func,onStop:A.default.func,onMouseDown:A.default.func,scale:A.default.number,className:Rt.dontSetMe,style:Rt.dontSetMe,transform:Rt.dontSetMe});I(vt,"defaultProps",{allowAnyClick:!1,disabled:!1,enableUserSelectHack:!0,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){},scale:1});(function(i){Object.defineProperty(i,"__esModule",{value:!0}),Object.defineProperty(i,"DraggableCore",{enumerable:!0,get:function(){return h.default}}),i.default=void 0;var t=w(z),e=u(Qt),n=u(dt),o=u(ii),r=C,s=j,a=G,h=u(gt),l=u(mt);function u(f){return f&&f.__esModule?f:{default:f}}function g(f){if(typeof WeakMap!="function")return null;var p=new WeakMap,d=new WeakMap;return(g=function(c){return c?d:p})(f)}function w(f,p){if(f&&f.__esModule)return f;if(f===null||typeof f!="object"&&typeof f!="function")return{default:f};var d=g(p);if(d&&d.has(f))return d.get(f);var c={},m=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var v in f)if(v!=="default"&&Object.prototype.hasOwnProperty.call(f,v)){var R=m?Object.getOwnPropertyDescriptor(f,v):null;R&&(R.get||R.set)?Object.defineProperty(c,v,R):c[v]=f[v]}return c.default=f,d&&d.set(f,c),c}function b(){return b=Object.assign?Object.assign.bind():function(f){for(var p=1;p<arguments.length;p++){var d=arguments[p];for(var c in d)Object.prototype.hasOwnProperty.call(d,c)&&(f[c]=d[c])}return f},b.apply(this,arguments)}function y(f,p,d){return p=S(p),p in f?Object.defineProperty(f,p,{value:d,enumerable:!0,configurable:!0,writable:!0}):f[p]=d,f}function S(f){var p=P(f,"string");return typeof p=="symbol"?p:String(p)}function P(f,p){if(typeof f!="object"||f===null)return f;var d=f[Symbol.toPrimitive];if(d!==void 0){var c=d.call(f,p);if(typeof c!="object")return c;throw new TypeError("@@toPrimitive must return a primitive value.")}return(p==="string"?String:Number)(f)}class x extends t.Component{static getDerivedStateFromProps(p,d){let{position:c}=p,{prevPropsPosition:m}=d;return c&&(!m||c.x!==m.x||c.y!==m.y)?((0,l.default)("Draggable: getDerivedStateFromProps %j",{position:c,prevPropsPosition:m}),{x:c.x,y:c.y,prevPropsPosition:{...c}}):null}constructor(p){super(p),y(this,"onDragStart",(d,c)=>{if((0,l.default)("Draggable: onDragStart: %j",c),this.props.onStart(d,(0,s.createDraggableData)(this,c))===!1)return!1;this.setState({dragging:!0,dragged:!0})}),y(this,"onDrag",(d,c)=>{if(!this.state.dragging)return!1;(0,l.default)("Draggable: onDrag: %j",c);const m=(0,s.createDraggableData)(this,c),v={x:m.x,y:m.y,slackX:0,slackY:0};if(this.props.bounds){const{x:_,y:D}=v;v.x+=this.state.slackX,v.y+=this.state.slackY;const[N,T]=(0,s.getBoundPosition)(this,v.x,v.y);v.x=N,v.y=T,v.slackX=this.state.slackX+(_-v.x),v.slackY=this.state.slackY+(D-v.y),m.x=v.x,m.y=v.y,m.deltaX=v.x-this.state.x,m.deltaY=v.y-this.state.y}if(this.props.onDrag(d,m)===!1)return!1;this.setState(v)}),y(this,"onDragStop",(d,c)=>{if(!this.state.dragging||this.props.onStop(d,(0,s.createDraggableData)(this,c))===!1)return!1;(0,l.default)("Draggable: onDragStop: %j",c);const v={dragging:!1,slackX:0,slackY:0};if(!!this.props.position){const{x:_,y:D}=this.props.position;v.x=_,v.y=D}this.setState(v)}),this.state={dragging:!1,dragged:!1,x:p.position?p.position.x:p.defaultPosition.x,y:p.position?p.position.y:p.defaultPosition.y,prevPropsPosition:{...p.position},slackX:0,slackY:0,isElementSVG:!1},p.position&&!(p.onDrag||p.onStop)&&console.warn("A `position` was applied to this <Draggable>, without drag handlers. This will make this component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the `position` of this element.")}componentDidMount(){typeof window.SVGElement<"u"&&this.findDOMNode()instanceof window.SVGElement&&this.setState({isElementSVG:!0})}componentWillUnmount(){this.setState({dragging:!1})}findDOMNode(){var p,d;return(p=(d=this.props)===null||d===void 0||(d=d.nodeRef)===null||d===void 0?void 0:d.current)!==null&&p!==void 0?p:n.default.findDOMNode(this)}render(){const{axis:p,bounds:d,children:c,defaultPosition:m,defaultClassName:v,defaultClassNameDragging:R,defaultClassNameDragged:_,position:D,positionOffset:N,scale:T,...O}=this.props;let B={},Y=null;const $=!!!D||this.state.dragging,Q=D||m,tt={x:(0,s.canDragX)(this)&&$?this.state.x:Q.x,y:(0,s.canDragY)(this)&&$?this.state.y:Q.y};this.state.isElementSVG?Y=(0,r.createSVGTransform)(tt,N):B=(0,r.createCSSTransform)(tt,N);const k=(0,o.default)(c.props.className||"",v,{[R]:this.state.dragging,[_]:this.state.dragged});return t.createElement(h.default,b({},O,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),t.cloneElement(t.Children.only(c),{className:k,style:{...c.props.style,...B},transform:Y}))}}i.default=x,y(x,"displayName","Draggable"),y(x,"propTypes",{...h.default.propTypes,axis:e.default.oneOf(["both","x","y","none"]),bounds:e.default.oneOfType([e.default.shape({left:e.default.number,right:e.default.number,top:e.default.number,bottom:e.default.number}),e.default.string,e.default.oneOf([!1])]),defaultClassName:e.default.string,defaultClassNameDragging:e.default.string,defaultClassNameDragged:e.default.string,defaultPosition:e.default.shape({x:e.default.number,y:e.default.number}),positionOffset:e.default.shape({x:e.default.oneOfType([e.default.number,e.default.string]),y:e.default.oneOfType([e.default.number,e.default.string])}),position:e.default.shape({x:e.default.number,y:e.default.number}),className:a.dontSetMe,style:a.dontSetMe,transform:a.dontSetMe}),y(x,"defaultProps",{...h.default.defaultProps,axis:"both",bounds:!1,defaultClassName:"react-draggable",defaultClassNameDragging:"react-draggable-dragging",defaultClassNameDragged:"react-draggable-dragged",defaultPosition:{x:0,y:0},scale:1})})(qt);const{default:le,DraggableCore:Ai}=qt;ft.exports=le;ft.exports.default=le;ft.exports.DraggableCore=Ai;var Fi=ft.exports;const Vi=pe(Fi);var E=function(){return E=Object.assign||function(i){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(i[o]=t[o])}return i},E.apply(this,arguments)},kt={width:"100%",height:"10px",top:"0px",left:"0px",cursor:"row-resize"},Xt={width:"10px",height:"100%",top:"0px",left:"0px",cursor:"col-resize"},lt={width:"20px",height:"20px",position:"absolute",zIndex:1},Bi={top:E(E({},kt),{top:"-5px"}),right:E(E({},Xt),{left:void 0,right:"-5px"}),bottom:E(E({},kt),{top:void 0,bottom:"-5px"}),left:E(E({},Xt),{left:"-5px"}),topRight:E(E({},lt),{right:"-10px",top:"-10px",cursor:"ne-resize"}),bottomRight:E(E({},lt),{right:"-10px",bottom:"-10px",cursor:"se-resize"}),bottomLeft:E(E({},lt),{left:"-10px",bottom:"-10px",cursor:"sw-resize"}),topLeft:E(E({},lt),{left:"-10px",top:"-10px",cursor:"nw-resize"})},ki=z.memo(function(i){var t=i.onResizeStart,e=i.direction,n=i.children,o=i.replaceStyles,r=i.className,s=z.useCallback(function(l){t(l,e)},[t,e]),a=z.useCallback(function(l){t(l,e)},[t,e]),h=z.useMemo(function(){return E(E({position:"absolute",userSelect:"none"},Bi[e]),o??{})},[o,e]);return L.jsx("div",{className:r||void 0,style:h,onMouseDown:s,onTouchStart:a,children:n})}),Xi=function(){var i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(n[r]=o[r])},i(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");i(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}}(),U=function(){return U=Object.assign||function(i){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(i[o]=t[o])}return i},U.apply(this,arguments)},Yi={width:"auto",height:"auto"},ht=function(i,t,e){return Math.max(Math.min(i,e),t)},Yt=function(i,t,e){var n=Math.round(i/t);return n*t+e*(n-1)},et=function(i,t){return new RegExp(i,"i").test(t)},ct=function(i){return!!(i.touches&&i.touches.length)},Ui=function(i){return!!((i.clientX||i.clientX===0)&&(i.clientY||i.clientY===0))},Ut=function(i,t,e){e===void 0&&(e=0);var n=t.reduce(function(r,s,a){return Math.abs(s-i)<Math.abs(t[r]-i)?a:r},0),o=Math.abs(t[n]-i);return e===0||o<e?t[n]:i},zt=function(i){return i=i.toString(),i==="auto"||i.endsWith("px")||i.endsWith("%")||i.endsWith("vh")||i.endsWith("vw")||i.endsWith("vmax")||i.endsWith("vmin")?i:"".concat(i,"px")},ut=function(i,t,e,n){if(i&&typeof i=="string"){if(i.endsWith("px"))return Number(i.replace("px",""));if(i.endsWith("%")){var o=Number(i.replace("%",""))/100;return t*o}if(i.endsWith("vw")){var o=Number(i.replace("vw",""))/100;return e*o}if(i.endsWith("vh")){var o=Number(i.replace("vh",""))/100;return n*o}}return i},Gi=function(i,t,e,n,o,r,s){return n=ut(n,i.width,t,e),o=ut(o,i.height,t,e),r=ut(r,i.width,t,e),s=ut(s,i.height,t,e),{maxWidth:typeof n>"u"?void 0:Number(n),maxHeight:typeof o>"u"?void 0:Number(o),minWidth:typeof r>"u"?void 0:Number(r),minHeight:typeof s>"u"?void 0:Number(s)}},ji=function(i){return Array.isArray(i)?i:[i,i]},$i=["as","ref","style","className","grid","gridGap","snap","bounds","boundsByDirection","size","defaultSize","minWidth","minHeight","maxWidth","maxHeight","lockAspectRatio","lockAspectRatioExtraWidth","lockAspectRatioExtraHeight","enable","handleStyles","handleClasses","handleWrapperStyle","handleWrapperClass","children","onResizeStart","onResize","onResizeStop","handleComponent","scale","resizeRatio","snapGap"],Gt="__resizable_base__",qi=function(i){Xi(t,i);function t(e){var n,o,r,s,a=i.call(this,e)||this;return a.ratio=1,a.resizable=null,a.parentLeft=0,a.parentTop=0,a.resizableLeft=0,a.resizableRight=0,a.resizableTop=0,a.resizableBottom=0,a.targetLeft=0,a.targetTop=0,a.delta={width:0,height:0},a.appendBase=function(){if(!a.resizable||!a.window)return null;var h=a.parentNode;if(!h)return null;var l=a.window.document.createElement("div");return l.style.width="100%",l.style.height="100%",l.style.position="absolute",l.style.transform="scale(0, 0)",l.style.left="0",l.style.flex="0 0 100%",l.classList?l.classList.add(Gt):l.className+=Gt,h.appendChild(l),l},a.removeBase=function(h){var l=a.parentNode;l&&l.removeChild(h)},a.state={isResizing:!1,width:(o=(n=a.propsSize)===null||n===void 0?void 0:n.width)!==null&&o!==void 0?o:"auto",height:(s=(r=a.propsSize)===null||r===void 0?void 0:r.height)!==null&&s!==void 0?s:"auto",direction:"right",original:{x:0,y:0,width:0,height:0},backgroundStyle:{height:"100%",width:"100%",backgroundColor:"rgba(0,0,0,0)",cursor:"auto",opacity:0,position:"fixed",zIndex:9999,top:"0",left:"0",bottom:"0",right:"0"},flexBasis:void 0},a.onResizeStart=a.onResizeStart.bind(a),a.onMouseMove=a.onMouseMove.bind(a),a.onMouseUp=a.onMouseUp.bind(a),a}return Object.defineProperty(t.prototype,"parentNode",{get:function(){return this.resizable?this.resizable.parentNode:null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"window",{get:function(){return!this.resizable||!this.resizable.ownerDocument?null:this.resizable.ownerDocument.defaultView},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"propsSize",{get:function(){return this.props.size||this.props.defaultSize||Yi},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){var e=0,n=0;if(this.resizable&&this.window){var o=this.resizable.offsetWidth,r=this.resizable.offsetHeight,s=this.resizable.style.position;s!=="relative"&&(this.resizable.style.position="relative"),e=this.resizable.style.width!=="auto"?this.resizable.offsetWidth:o,n=this.resizable.style.height!=="auto"?this.resizable.offsetHeight:r,this.resizable.style.position=s}return{width:e,height:n}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeStyle",{get:function(){var e=this,n=this.props.size,o=function(a){var h;if(typeof e.state[a]>"u"||e.state[a]==="auto")return"auto";if(e.propsSize&&e.propsSize[a]&&(!((h=e.propsSize[a])===null||h===void 0)&&h.toString().endsWith("%"))){if(e.state[a].toString().endsWith("%"))return e.state[a].toString();var l=e.getParentSize(),u=Number(e.state[a].toString().replace("px","")),g=u/l[a]*100;return"".concat(g,"%")}return zt(e.state[a])},r=n&&typeof n.width<"u"&&!this.state.isResizing?zt(n.width):o("width"),s=n&&typeof n.height<"u"&&!this.state.isResizing?zt(n.height):o("height");return{width:r,height:s}},enumerable:!1,configurable:!0}),t.prototype.getParentSize=function(){if(!this.parentNode)return this.window?{width:this.window.innerWidth,height:this.window.innerHeight}:{width:0,height:0};var e=this.appendBase();if(!e)return{width:0,height:0};var n=!1,o=this.parentNode.style.flexWrap;o!=="wrap"&&(n=!0,this.parentNode.style.flexWrap="wrap"),e.style.position="relative",e.style.minWidth="100%",e.style.minHeight="100%";var r={width:e.offsetWidth,height:e.offsetHeight};return n&&(this.parentNode.style.flexWrap=o),this.removeBase(e),r},t.prototype.bindEvents=function(){this.window&&(this.window.addEventListener("mouseup",this.onMouseUp),this.window.addEventListener("mousemove",this.onMouseMove),this.window.addEventListener("mouseleave",this.onMouseUp),this.window.addEventListener("touchmove",this.onMouseMove,{capture:!0,passive:!1}),this.window.addEventListener("touchend",this.onMouseUp))},t.prototype.unbindEvents=function(){this.window&&(this.window.removeEventListener("mouseup",this.onMouseUp),this.window.removeEventListener("mousemove",this.onMouseMove),this.window.removeEventListener("mouseleave",this.onMouseUp),this.window.removeEventListener("touchmove",this.onMouseMove,!0),this.window.removeEventListener("touchend",this.onMouseUp))},t.prototype.componentDidMount=function(){if(!(!this.resizable||!this.window)){var e=this.window.getComputedStyle(this.resizable);this.setState({width:this.state.width||this.size.width,height:this.state.height||this.size.height,flexBasis:e.flexBasis!=="auto"?e.flexBasis:void 0})}},t.prototype.componentWillUnmount=function(){this.window&&this.unbindEvents()},t.prototype.createSizeForCssProperty=function(e,n){var o=this.propsSize&&this.propsSize[n];return this.state[n]==="auto"&&this.state.original[n]===e&&(typeof o>"u"||o==="auto")?"auto":e},t.prototype.calculateNewMaxFromBoundary=function(e,n){var o=this.props.boundsByDirection,r=this.state.direction,s=o&&et("left",r),a=o&&et("top",r),h,l;if(this.props.bounds==="parent"){var u=this.parentNode;u&&(h=s?this.resizableRight-this.parentLeft:u.offsetWidth+(this.parentLeft-this.resizableLeft),l=a?this.resizableBottom-this.parentTop:u.offsetHeight+(this.parentTop-this.resizableTop))}else this.props.bounds==="window"?this.window&&(h=s?this.resizableRight:this.window.innerWidth-this.resizableLeft,l=a?this.resizableBottom:this.window.innerHeight-this.resizableTop):this.props.bounds&&(h=s?this.resizableRight-this.targetLeft:this.props.bounds.offsetWidth+(this.targetLeft-this.resizableLeft),l=a?this.resizableBottom-this.targetTop:this.props.bounds.offsetHeight+(this.targetTop-this.resizableTop));return h&&Number.isFinite(h)&&(e=e&&e<h?e:h),l&&Number.isFinite(l)&&(n=n&&n<l?n:l),{maxWidth:e,maxHeight:n}},t.prototype.calculateNewSizeFromDirection=function(e,n){var o=this.props.scale||1,r=ji(this.props.resizeRatio||1),s=r[0],a=r[1],h=this.state,l=h.direction,u=h.original,g=this.props,w=g.lockAspectRatio,b=g.lockAspectRatioExtraHeight,y=g.lockAspectRatioExtraWidth,S=u.width,P=u.height,x=b||0,f=y||0;return et("right",l)&&(S=u.width+(e-u.x)*s/o,w&&(P=(S-f)/this.ratio+x)),et("left",l)&&(S=u.width-(e-u.x)*s/o,w&&(P=(S-f)/this.ratio+x)),et("bottom",l)&&(P=u.height+(n-u.y)*a/o,w&&(S=(P-x)*this.ratio+f)),et("top",l)&&(P=u.height-(n-u.y)*a/o,w&&(S=(P-x)*this.ratio+f)),{newWidth:S,newHeight:P}},t.prototype.calculateNewSizeFromAspectRatio=function(e,n,o,r){var s=this.props,a=s.lockAspectRatio,h=s.lockAspectRatioExtraHeight,l=s.lockAspectRatioExtraWidth,u=typeof r.width>"u"?10:r.width,g=typeof o.width>"u"||o.width<0?e:o.width,w=typeof r.height>"u"?10:r.height,b=typeof o.height>"u"||o.height<0?n:o.height,y=h||0,S=l||0;if(a){var P=(w-y)*this.ratio+S,x=(b-y)*this.ratio+S,f=(u-S)/this.ratio+y,p=(g-S)/this.ratio+y,d=Math.max(u,P),c=Math.min(g,x),m=Math.max(w,f),v=Math.min(b,p);e=ht(e,d,c),n=ht(n,m,v)}else e=ht(e,u,g),n=ht(n,w,b);return{newWidth:e,newHeight:n}},t.prototype.setBoundingClientRect=function(){var e=1/(this.props.scale||1);if(this.props.bounds==="parent"){var n=this.parentNode;if(n){var o=n.getBoundingClientRect();this.parentLeft=o.left*e,this.parentTop=o.top*e}}if(this.props.bounds&&typeof this.props.bounds!="string"){var r=this.props.bounds.getBoundingClientRect();this.targetLeft=r.left*e,this.targetTop=r.top*e}if(this.resizable){var s=this.resizable.getBoundingClientRect(),a=s.left,h=s.top,l=s.right,u=s.bottom;this.resizableLeft=a*e,this.resizableRight=l*e,this.resizableTop=h*e,this.resizableBottom=u*e}},t.prototype.onResizeStart=function(e,n){if(!(!this.resizable||!this.window)){var o=0,r=0;if(e.nativeEvent&&Ui(e.nativeEvent)?(o=e.nativeEvent.clientX,r=e.nativeEvent.clientY):e.nativeEvent&&ct(e.nativeEvent)&&(o=e.nativeEvent.touches[0].clientX,r=e.nativeEvent.touches[0].clientY),this.props.onResizeStart&&this.resizable){var s=this.props.onResizeStart(e,n,this.resizable);if(s===!1)return}this.props.size&&(typeof this.props.size.height<"u"&&this.props.size.height!==this.state.height&&this.setState({height:this.props.size.height}),typeof this.props.size.width<"u"&&this.props.size.width!==this.state.width&&this.setState({width:this.props.size.width})),this.ratio=typeof this.props.lockAspectRatio=="number"?this.props.lockAspectRatio:this.size.width/this.size.height;var a,h=this.window.getComputedStyle(this.resizable);if(h.flexBasis!=="auto"){var l=this.parentNode;if(l){var u=this.window.getComputedStyle(l).flexDirection;this.flexDir=u.startsWith("row")?"row":"column",a=h.flexBasis}}this.setBoundingClientRect(),this.bindEvents();var g={original:{x:o,y:r,width:this.size.width,height:this.size.height},isResizing:!0,backgroundStyle:U(U({},this.state.backgroundStyle),{cursor:this.window.getComputedStyle(e.target).cursor||"auto"}),direction:n,flexBasis:a};this.setState(g)}},t.prototype.onMouseMove=function(e){var n=this;if(!(!this.state.isResizing||!this.resizable||!this.window)){if(this.window.TouchEvent&&ct(e))try{e.preventDefault(),e.stopPropagation()}catch{}var o=this.props,r=o.maxWidth,s=o.maxHeight,a=o.minWidth,h=o.minHeight,l=ct(e)?e.touches[0].clientX:e.clientX,u=ct(e)?e.touches[0].clientY:e.clientY,g=this.state,w=g.direction,b=g.original,y=g.width,S=g.height,P=this.getParentSize(),x=Gi(P,this.window.innerWidth,this.window.innerHeight,r,s,a,h);r=x.maxWidth,s=x.maxHeight,a=x.minWidth,h=x.minHeight;var f=this.calculateNewSizeFromDirection(l,u),p=f.newHeight,d=f.newWidth,c=this.calculateNewMaxFromBoundary(r,s);this.props.snap&&this.props.snap.x&&(d=Ut(d,this.props.snap.x,this.props.snapGap)),this.props.snap&&this.props.snap.y&&(p=Ut(p,this.props.snap.y,this.props.snapGap));var m=this.calculateNewSizeFromAspectRatio(d,p,{width:c.maxWidth,height:c.maxHeight},{width:a,height:h});if(d=m.newWidth,p=m.newHeight,this.props.grid){var v=Yt(d,this.props.grid[0],this.props.gridGap?this.props.gridGap[0]:0),R=Yt(p,this.props.grid[1],this.props.gridGap?this.props.gridGap[1]:0),_=this.props.snapGap||0,D=_===0||Math.abs(v-d)<=_?v:d,N=_===0||Math.abs(R-p)<=_?R:p;d=D,p=N}var T={width:d-b.width,height:p-b.height};if(this.delta=T,y&&typeof y=="string"){if(y.endsWith("%")){var O=d/P.width*100;d="".concat(O,"%")}else if(y.endsWith("vw")){var B=d/this.window.innerWidth*100;d="".concat(B,"vw")}else if(y.endsWith("vh")){var Y=d/this.window.innerHeight*100;d="".concat(Y,"vh")}}if(S&&typeof S=="string"){if(S.endsWith("%")){var O=p/P.height*100;p="".concat(O,"%")}else if(S.endsWith("vw")){var B=p/this.window.innerWidth*100;p="".concat(B,"vw")}else if(S.endsWith("vh")){var Y=p/this.window.innerHeight*100;p="".concat(Y,"vh")}}var M={width:this.createSizeForCssProperty(d,"width"),height:this.createSizeForCssProperty(p,"height")};this.flexDir==="row"?M.flexBasis=M.width:this.flexDir==="column"&&(M.flexBasis=M.height);var $=this.state.width!==M.width,Q=this.state.height!==M.height,tt=this.state.flexBasis!==M.flexBasis,k=$||Q||tt;k&&dt.flushSync(function(){n.setState(M)}),this.props.onResize&&k&&this.props.onResize(e,w,this.resizable,T)}},t.prototype.onMouseUp=function(e){var n,o,r=this.state,s=r.isResizing,a=r.direction;r.original,!(!s||!this.resizable)&&(this.props.onResizeStop&&this.props.onResizeStop(e,a,this.resizable,this.delta),this.props.size&&this.setState({width:(n=this.props.size.width)!==null&&n!==void 0?n:"auto",height:(o=this.props.size.height)!==null&&o!==void 0?o:"auto"}),this.unbindEvents(),this.setState({isResizing:!1,backgroundStyle:U(U({},this.state.backgroundStyle),{cursor:"auto"})}))},t.prototype.updateSize=function(e){var n,o;this.setState({width:(n=e.width)!==null&&n!==void 0?n:"auto",height:(o=e.height)!==null&&o!==void 0?o:"auto"})},t.prototype.renderResizer=function(){var e=this,n=this.props,o=n.enable,r=n.handleStyles,s=n.handleClasses,a=n.handleWrapperStyle,h=n.handleWrapperClass,l=n.handleComponent;if(!o)return null;var u=Object.keys(o).map(function(g){return o[g]!==!1?L.jsx(ki,{direction:g,onResizeStart:e.onResizeStart,replaceStyles:r&&r[g],className:s&&s[g],children:l&&l[g]?l[g]:null},g):null});return L.jsx("div",{className:h,style:a,children:u})},t.prototype.render=function(){var e=this,n=Object.keys(this.props).reduce(function(s,a){return $i.indexOf(a)!==-1||(s[a]=e.props[a]),s},{}),o=U(U(U({position:"relative",userSelect:this.state.isResizing?"none":"auto"},this.props.style),this.sizeStyle),{maxWidth:this.props.maxWidth,maxHeight:this.props.maxHeight,minWidth:this.props.minWidth,minHeight:this.props.minHeight,boxSizing:"border-box",flexShrink:0});this.state.flexBasis&&(o.flexBasis=this.state.flexBasis);var r=this.props.as||"div";return L.jsxs(r,U({style:o,className:this.props.className},n,{ref:function(s){s&&(e.resizable=s)},children:[this.state.isResizing&&L.jsx("div",{style:this.state.backgroundStyle}),this.props.children,this.renderResizer()]}))},t.defaultProps={as:"div",onResizeStart:function(){},onResize:function(){},onResizeStop:function(){},enable:{top:!0,right:!0,bottom:!0,left:!0,topRight:!0,bottomRight:!0,bottomLeft:!0,topLeft:!0},style:{},grid:[1,1],gridGap:[0,0],lockAspectRatio:!1,lockAspectRatioExtraWidth:0,lockAspectRatioExtraHeight:0,scale:1,resizeRatio:1,snapGap:0},t}(z.PureComponent);/*! *****************************************************************************
4
4
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1 +1 @@
1
- import{m as ee,a as re,n as te,o as X,p as se,q as oe,c as ae,r as _,s as ne,j as e,h as k,I as q,b as c,M as V,A as G,R as E}from"./index-Gbl53BNp.js";import{r as s}from"./plugin-monaco-C8UgLomw.js";import{d as ie,s as le,U as de,I as ce,r as ue}from"./NotebookEditor-CVsj8h_T.js";import"./plugin-notebook-HbW2K-1c.js";import"./plugin-terminal-MXFIPun8.js";function fe(a,u){if(!a)return a;const p=`/api/v1/pdf/markdown/${u}/assets/`;return a.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(m,t,n)=>{const f=String(n||"").trim();if(!f||f.startsWith("http")||f.startsWith("data:")||f.startsWith("/api/"))return m;const y=f.replace(/^\.?\//,"");return`![${t}](${p}${y})`})}function me(a){return a&&a.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(u,p,m)=>{const t=String(m||"").trim();if(!t)return u;const n=ue(t);return n?`![${p}](${n})`:u})}function ve({context:a,tabId:u,setTitle:p}){const m=a.resourceId??(typeof a.customData?.fileId=="string"?a.customData.fileId:null),t=m?String(m):"",n=a.resourceName||"PDF Markdown",f=ee(r=>r.updateTabPlugin),y=re(r=>r.updateTabState),{addToast:D}=te(),R=X(r=>r.items),K=X(r=>r.errors),[v,z]=s.useState(null),[b,F]=s.useState(""),[i,x]=s.useState("idle"),[g,N]=s.useState("novel"),[$,S]=s.useState(null),[H,w]=s.useState(null),[l,B]=s.useState(!1),[A,M]=s.useState(!1),P=s.useRef(!1),J=s.useMemo(()=>[...ie],[]),I=s.useMemo(()=>a.customData?.arxiv??null,[a.customData]),o=s.useMemo(()=>I||t&&R.find(r=>r.fileId===t)||null,[I,R,t]),U=o?K[o.arxivId]:void 0,j=!!o,Q=s.useMemo(()=>se(o),[o]),O=s.useCallback(async()=>{if(!o)return;const r=oe(o),d=await ae(r);D({type:d?"success":"error",title:d?"BibTeX copied":"Copy failed",description:d?o.title||o.arxivId:"Please try again.",duration:1800})},[D,o]),W=s.useCallback(()=>{o?.arxivId&&window.open(`https://arxiv.org/abs/${o.arxivId}`,"_blank","noopener,noreferrer")},[o]);s.useEffect(()=>{p(j?`${n} Summary`:n)},[n,j,p]),s.useEffect(()=>{P.current=!1,N("novel"),S(null)},[t]);const C=s.useCallback(async(r=!1)=>{if(!t)return!1;w(null);try{const d=r?"?force=1":"";return await _.post(`/api/v1/pdf/parse/${t}${d}`),x("processing"),!0}catch(d){return w(d?.response?.data?.detail||d?.message||"Failed to start MinerU parsing"),x("error"),!1}},[t]),h=s.useCallback(async()=>{if(t){x("loading"),w(null);try{const r=await _.get(`/api/v1/pdf/markdown/${t}`,{responseType:"text"}),d=typeof r.data=="string"?r.data:String(r.data??""),Z=fe(d,t);F(Z),N("novel"),S(null),x("ready")}catch(r){if(r?.response?.status===409){x("processing"),P.current||(P.current=!0,await C());return}w(r?.response?.data?.detail||r?.message||"Failed to load PDF markdown"),x("error")}}},[t,C]),T=s.useCallback(async()=>{if(!t||l)return;B(!0),P.current=!0,await C(!0)&&await h(),B(!1)},[t,l,h,C]);s.useEffect(()=>{if(j){x("idle"),F(""),w(null);return}t&&h()},[t,j,h]),s.useEffect(()=>{y(u,{contentKind:"pdf",documentMode:"markdown",isReadOnly:!0})},[u,y]),s.useEffect(()=>{if(i!=="processing")return;const r=window.setTimeout(()=>{h()},5e3);return()=>window.clearTimeout(r)},[i,h]),s.useEffect(()=>{if(!(!v||i!=="ready"||g!=="novel"))try{le(v,b),v.setEditable(!1),!(v.state.doc.textContent.trim().length>0)&&b.trim().length>0&&N("markdown")}catch(r){S(r?.message||"Markdown parse failed"),N("markdown")}},[v,b,g,i]);const Y=s.useMemo(()=>g==="markdown"?me(b):b,[b,g]),L=s.useCallback(()=>{t&&f(u,ne.PDF_VIEWER,{...a,resourceId:a.resourceId??t,resourceName:a.resourceName??n,customData:{...a.customData||{},pdfView:"pdf",fileId:t}})},[a,t,n,u,f]);return t?j?e.jsxs("div",{className:"flex flex-col h-full bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-foreground",children:n}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground uppercase",children:"Summary"}),e.jsx("button",{type:"button",onClick:()=>M(!0),className:c("flex h-7 w-7 items-center justify-center rounded-full","text-muted-foreground transition-colors","hover:bg-muted hover:text-foreground"),title:"Paper info","aria-label":"Paper info",children:e.jsx(q,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{type:"button",onClick:L,className:c("flex items-center gap-2 px-3 py-1.5 rounded-full border transition-colors text-sm","bg-background hover:bg-muted/60 border-border"),title:"Back to PDF view",children:[e.jsx(k,{className:"w-4 h-4"}),"PDF"]})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex justify-center px-4 py-4 bg-muted/10",children:e.jsx("div",{className:"relative h-full w-[min(62.5vw,100%)] max-w-[70rem]",children:e.jsx("div",{className:"notebook-editor-container relative h-full overflow-hidden rounded-2xl border border-border bg-background shadow-soft-card",children:e.jsx("div",{className:"notebook-doc-editor relative h-full w-full overflow-y-auto p-8",children:e.jsx(V,{content:Q,className:"prose prose-lg dark:prose-invert max-w-full"})})})})}),e.jsx(G,{open:A,onClose:()=>M(!1),paper:o,errorCode:U,onCopyBibtex:o?O:void 0,onOpenArxiv:o?W:void 0})]}):e.jsxs("div",{className:"flex flex-col h-full bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-foreground",children:n}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground uppercase",children:"Markdown"}),o?e.jsx("button",{type:"button",onClick:()=>M(!0),className:c("flex h-7 w-7 items-center justify-center rounded-full","text-muted-foreground transition-colors","hover:bg-muted hover:text-foreground"),title:"Paper info","aria-label":"Paper info",children:e.jsx(q,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t?e.jsxs("button",{type:"button",onClick:L,className:c("flex items-center gap-2 px-3 py-1.5 rounded-full border transition-colors text-sm","bg-background hover:bg-muted/60 border-border"),title:"Back to PDF view",children:[e.jsx(k,{className:"w-4 h-4"}),"PDF"]}):null,i==="error"&&e.jsxs("button",{onClick:T,disabled:l,className:c("inline-flex items-center gap-2 text-xs transition-colors","text-muted-foreground hover:text-foreground",l&&"opacity-60 cursor-not-allowed"),children:[e.jsx(E,{className:c("w-3.5 h-3.5",l&&"animate-spin")}),"Retry parse"]}),i==="processing"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Parsing..."}),e.jsxs("button",{onClick:T,disabled:l,className:c("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 transition-colors","border-border bg-background hover:bg-muted/60",l&&"opacity-60 cursor-not-allowed"),children:[e.jsx(E,{className:c("h-3 w-3",l&&"animate-spin")}),"Retry"]})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex justify-center px-4 py-4 bg-muted/10",children:e.jsx("div",{className:"relative h-full w-[min(62.5vw,100%)] max-w-[70rem]",children:e.jsxs("div",{className:c("notebook-editor-container relative h-full overflow-hidden rounded-2xl border border-border bg-background shadow-soft-card",i!=="ready"&&"flex items-center justify-center"),children:[i==="loading"&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading Markdown..."}),i==="processing"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 text-sm text-muted-foreground",children:[e.jsx("span",{children:"MinerU parsing in progress..."}),e.jsxs("button",{onClick:T,disabled:l,className:c("inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-xs transition-colors","border-border bg-background hover:bg-muted/60",l&&"opacity-60 cursor-not-allowed"),children:[e.jsx(E,{className:c("h-3.5 w-3.5",l&&"animate-spin")}),"Retry MinerU"]})]}),i==="error"&&e.jsx("div",{className:"text-sm text-destructive px-6 text-center",children:H||"Failed to load PDF markdown"}),i==="ready"&&g==="novel"&&e.jsx(de,{children:e.jsx(ce,{extensions:J,className:"notebook-doc-editor relative h-full w-full overflow-y-auto",editorProps:{attributes:{class:"prose prose-lg dark:prose-invert prose-headings:font-title font-default focus:outline-none max-w-full"}},onCreate:({editor:r})=>{z(r)}})}),i==="ready"&&g==="markdown"&&e.jsxs("div",{className:"notebook-doc-editor relative h-full w-full overflow-y-auto p-8",children:[$?e.jsxs("div",{className:"text-xs text-muted-foreground mb-3",children:[$,". Rendering with Markdown viewer."]}):null,e.jsx(V,{content:Y,className:"prose prose-lg dark:prose-invert max-w-full"})]})]})})}),e.jsx(G,{open:A,onClose:()=>M(!1),paper:o,errorCode:U,onCopyBibtex:o?O:void 0,onOpenArxiv:o?W:void 0})]}):e.jsx("div",{className:"flex h-full items-center justify-center bg-background",children:e.jsxs("div",{className:"max-w-md text-center space-y-3",children:[e.jsx(k,{className:"mx-auto h-10 w-10 text-muted-foreground"}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Open a PDF to view Markdown"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a PDF in the file tree or import one from arXiv, then open the Markdown view to see MinerU output."})]})})}export{ve as default};
1
+ import{m as ee,a as re,n as te,o as X,p as se,q as oe,c as ae,r as _,s as ne,j as e,h as k,I as q,b as c,M as V,A as G,R as E}from"./index-CBNVuWcP.js";import{r as s}from"./plugin-monaco-C8UgLomw.js";import{d as ie,s as le,U as de,I as ce,r as ue}from"./NotebookEditor-DB9N_T9q.js";import"./plugin-notebook-HbW2K-1c.js";import"./plugin-terminal-MXFIPun8.js";function fe(a,u){if(!a)return a;const p=`/api/v1/pdf/markdown/${u}/assets/`;return a.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(m,t,n)=>{const f=String(n||"").trim();if(!f||f.startsWith("http")||f.startsWith("data:")||f.startsWith("/api/"))return m;const y=f.replace(/^\.?\//,"");return`![${t}](${p}${y})`})}function me(a){return a&&a.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(u,p,m)=>{const t=String(m||"").trim();if(!t)return u;const n=ue(t);return n?`![${p}](${n})`:u})}function ve({context:a,tabId:u,setTitle:p}){const m=a.resourceId??(typeof a.customData?.fileId=="string"?a.customData.fileId:null),t=m?String(m):"",n=a.resourceName||"PDF Markdown",f=ee(r=>r.updateTabPlugin),y=re(r=>r.updateTabState),{addToast:D}=te(),R=X(r=>r.items),K=X(r=>r.errors),[v,z]=s.useState(null),[b,F]=s.useState(""),[i,x]=s.useState("idle"),[g,N]=s.useState("novel"),[$,S]=s.useState(null),[H,w]=s.useState(null),[l,B]=s.useState(!1),[A,M]=s.useState(!1),P=s.useRef(!1),J=s.useMemo(()=>[...ie],[]),I=s.useMemo(()=>a.customData?.arxiv??null,[a.customData]),o=s.useMemo(()=>I||t&&R.find(r=>r.fileId===t)||null,[I,R,t]),U=o?K[o.arxivId]:void 0,j=!!o,Q=s.useMemo(()=>se(o),[o]),O=s.useCallback(async()=>{if(!o)return;const r=oe(o),d=await ae(r);D({type:d?"success":"error",title:d?"BibTeX copied":"Copy failed",description:d?o.title||o.arxivId:"Please try again.",duration:1800})},[D,o]),W=s.useCallback(()=>{o?.arxivId&&window.open(`https://arxiv.org/abs/${o.arxivId}`,"_blank","noopener,noreferrer")},[o]);s.useEffect(()=>{p(j?`${n} Summary`:n)},[n,j,p]),s.useEffect(()=>{P.current=!1,N("novel"),S(null)},[t]);const C=s.useCallback(async(r=!1)=>{if(!t)return!1;w(null);try{const d=r?"?force=1":"";return await _.post(`/api/v1/pdf/parse/${t}${d}`),x("processing"),!0}catch(d){return w(d?.response?.data?.detail||d?.message||"Failed to start MinerU parsing"),x("error"),!1}},[t]),h=s.useCallback(async()=>{if(t){x("loading"),w(null);try{const r=await _.get(`/api/v1/pdf/markdown/${t}`,{responseType:"text"}),d=typeof r.data=="string"?r.data:String(r.data??""),Z=fe(d,t);F(Z),N("novel"),S(null),x("ready")}catch(r){if(r?.response?.status===409){x("processing"),P.current||(P.current=!0,await C());return}w(r?.response?.data?.detail||r?.message||"Failed to load PDF markdown"),x("error")}}},[t,C]),T=s.useCallback(async()=>{if(!t||l)return;B(!0),P.current=!0,await C(!0)&&await h(),B(!1)},[t,l,h,C]);s.useEffect(()=>{if(j){x("idle"),F(""),w(null);return}t&&h()},[t,j,h]),s.useEffect(()=>{y(u,{contentKind:"pdf",documentMode:"markdown",isReadOnly:!0})},[u,y]),s.useEffect(()=>{if(i!=="processing")return;const r=window.setTimeout(()=>{h()},5e3);return()=>window.clearTimeout(r)},[i,h]),s.useEffect(()=>{if(!(!v||i!=="ready"||g!=="novel"))try{le(v,b),v.setEditable(!1),!(v.state.doc.textContent.trim().length>0)&&b.trim().length>0&&N("markdown")}catch(r){S(r?.message||"Markdown parse failed"),N("markdown")}},[v,b,g,i]);const Y=s.useMemo(()=>g==="markdown"?me(b):b,[b,g]),L=s.useCallback(()=>{t&&f(u,ne.PDF_VIEWER,{...a,resourceId:a.resourceId??t,resourceName:a.resourceName??n,customData:{...a.customData||{},pdfView:"pdf",fileId:t}})},[a,t,n,u,f]);return t?j?e.jsxs("div",{className:"flex flex-col h-full bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-foreground",children:n}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground uppercase",children:"Summary"}),e.jsx("button",{type:"button",onClick:()=>M(!0),className:c("flex h-7 w-7 items-center justify-center rounded-full","text-muted-foreground transition-colors","hover:bg-muted hover:text-foreground"),title:"Paper info","aria-label":"Paper info",children:e.jsx(q,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{type:"button",onClick:L,className:c("flex items-center gap-2 px-3 py-1.5 rounded-full border transition-colors text-sm","bg-background hover:bg-muted/60 border-border"),title:"Back to PDF view",children:[e.jsx(k,{className:"w-4 h-4"}),"PDF"]})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex justify-center px-4 py-4 bg-muted/10",children:e.jsx("div",{className:"relative h-full w-[min(62.5vw,100%)] max-w-[70rem]",children:e.jsx("div",{className:"notebook-editor-container relative h-full overflow-hidden rounded-2xl border border-border bg-background shadow-soft-card",children:e.jsx("div",{className:"notebook-doc-editor relative h-full w-full overflow-y-auto p-8",children:e.jsx(V,{content:Q,className:"prose prose-lg dark:prose-invert max-w-full"})})})})}),e.jsx(G,{open:A,onClose:()=>M(!1),paper:o,errorCode:U,onCopyBibtex:o?O:void 0,onOpenArxiv:o?W:void 0})]}):e.jsxs("div",{className:"flex flex-col h-full bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-foreground",children:n}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground uppercase",children:"Markdown"}),o?e.jsx("button",{type:"button",onClick:()=>M(!0),className:c("flex h-7 w-7 items-center justify-center rounded-full","text-muted-foreground transition-colors","hover:bg-muted hover:text-foreground"),title:"Paper info","aria-label":"Paper info",children:e.jsx(q,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t?e.jsxs("button",{type:"button",onClick:L,className:c("flex items-center gap-2 px-3 py-1.5 rounded-full border transition-colors text-sm","bg-background hover:bg-muted/60 border-border"),title:"Back to PDF view",children:[e.jsx(k,{className:"w-4 h-4"}),"PDF"]}):null,i==="error"&&e.jsxs("button",{onClick:T,disabled:l,className:c("inline-flex items-center gap-2 text-xs transition-colors","text-muted-foreground hover:text-foreground",l&&"opacity-60 cursor-not-allowed"),children:[e.jsx(E,{className:c("w-3.5 h-3.5",l&&"animate-spin")}),"Retry parse"]}),i==="processing"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Parsing..."}),e.jsxs("button",{onClick:T,disabled:l,className:c("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 transition-colors","border-border bg-background hover:bg-muted/60",l&&"opacity-60 cursor-not-allowed"),children:[e.jsx(E,{className:c("h-3 w-3",l&&"animate-spin")}),"Retry"]})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex justify-center px-4 py-4 bg-muted/10",children:e.jsx("div",{className:"relative h-full w-[min(62.5vw,100%)] max-w-[70rem]",children:e.jsxs("div",{className:c("notebook-editor-container relative h-full overflow-hidden rounded-2xl border border-border bg-background shadow-soft-card",i!=="ready"&&"flex items-center justify-center"),children:[i==="loading"&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading Markdown..."}),i==="processing"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 text-sm text-muted-foreground",children:[e.jsx("span",{children:"MinerU parsing in progress..."}),e.jsxs("button",{onClick:T,disabled:l,className:c("inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-xs transition-colors","border-border bg-background hover:bg-muted/60",l&&"opacity-60 cursor-not-allowed"),children:[e.jsx(E,{className:c("h-3.5 w-3.5",l&&"animate-spin")}),"Retry MinerU"]})]}),i==="error"&&e.jsx("div",{className:"text-sm text-destructive px-6 text-center",children:H||"Failed to load PDF markdown"}),i==="ready"&&g==="novel"&&e.jsx(de,{children:e.jsx(ce,{extensions:J,className:"notebook-doc-editor relative h-full w-full overflow-y-auto",editorProps:{attributes:{class:"prose prose-lg dark:prose-invert prose-headings:font-title font-default focus:outline-none max-w-full"}},onCreate:({editor:r})=>{z(r)}})}),i==="ready"&&g==="markdown"&&e.jsxs("div",{className:"notebook-doc-editor relative h-full w-full overflow-y-auto p-8",children:[$?e.jsxs("div",{className:"text-xs text-muted-foreground mb-3",children:[$,". Rendering with Markdown viewer."]}):null,e.jsx(V,{content:Y,className:"prose prose-lg dark:prose-invert max-w-full"})]})]})})}),e.jsx(G,{open:A,onClose:()=>M(!1),paper:o,errorCode:U,onCopyBibtex:o?O:void 0,onOpenArxiv:o?W:void 0})]}):e.jsx("div",{className:"flex h-full items-center justify-center bg-background",children:e.jsxs("div",{className:"max-w-md text-center space-y-3",children:[e.jsx(k,{className:"mx-auto h-10 w-10 text-muted-foreground"}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Open a PDF to view Markdown"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a PDF in the file tree or import one from arXiv, then open the Markdown view to see MinerU output."})]})})}export{ve as default};
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Gbl53BNp.js","assets/plugin-monaco-C8UgLomw.js","assets/plugin-terminal-MXFIPun8.js","assets/plugin-notebook-HbW2K-1c.js","assets/index-Cgla8biy.css"])))=>i.map(i=>d[i]);
2
- import{y as zt,u as ne,j as n,a3 as Pn,I as Fn,b as M,h as On,k as Ln,X as Kt,l as Hn,aa as $n,r as ce,aQ as Gt,H as Bn,bO as nt,bP as Un,J as pe,bQ as it,bR as at,bS as ct,bT as lt,bU as dt,bV as Vn,bo as mt,bW as Xt,i as Qn,bX as qn,bY as Wn,m as zn,f as Kn,a as ot,n as Gn,o as Ft,x as Xn,q as Zn,c as Jn,U as Ot,s as Lt,bZ as Yn,b_ as eo,_ as Ht,A as to,b$ as no,O as Zt,T as oo,c0 as ro,c1 as rt,c2 as so}from"./index-Gbl53BNp.js";import{r as c}from"./plugin-monaco-C8UgLomw.js";import{a as io}from"./file-socket-Cu4Qln7Y.js";import{M as ao,i as co,m as lo,c as uo}from"./pdf-effect-queue-ZtnHFCAi.js";import{Z as K,R as fo,g as mo,a as po,e as go,b as bo,c as ho,d as xo}from"./PdfLoader-CASDQmxJ.js";import{Z as yo,a as vo}from"./zoom-out-R-GWEhzS.js";import{C as wo}from"./chevron-up-Dq5ofbht.js";import{S as Jt}from"./index-wQ7RIIRd.js";import"./plugin-notebook-HbW2K-1c.js";import"./plugin-terminal-MXFIPun8.js";import"./plugin-pdf-CR8hgQBV.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CBNVuWcP.js","assets/plugin-monaco-C8UgLomw.js","assets/plugin-terminal-MXFIPun8.js","assets/plugin-notebook-HbW2K-1c.js","assets/index-BpV6lusQ.css"])))=>i.map(i=>d[i]);
2
+ import{y as zt,u as ne,j as n,a3 as Pn,I as Fn,b as M,h as On,k as Ln,X as Kt,l as Hn,aa as $n,r as ce,aQ as Gt,H as Bn,bO as nt,bP as Un,J as pe,bQ as it,bR as at,bS as ct,bT as lt,bU as dt,bV as Vn,bo as mt,bW as Xt,i as Qn,bX as qn,bY as Wn,m as zn,f as Kn,a as ot,n as Gn,o as Ft,x as Xn,q as Zn,c as Jn,U as Ot,s as Lt,bZ as Yn,b_ as eo,_ as Ht,A as to,b$ as no,O as Zt,T as oo,c0 as ro,c1 as rt,c2 as so}from"./index-CBNVuWcP.js";import{r as c}from"./plugin-monaco-C8UgLomw.js";import{a as io}from"./file-socket-CfQPKQKj.js";import{M as ao,i as co,m as lo,c as uo}from"./pdf-effect-queue-J8OnM0jE.js";import{Z as K,R as fo,g as mo,a as po,e as go,b as bo,c as ho,d as xo}from"./PdfLoader-eWBONbQP.js";import{Z as yo,a as vo}from"./zoom-out-E_gaeAxL.js";import{C as wo}from"./chevron-up-C9Qpx4DE.js";import{S as Jt}from"./index-CwNu1aH4.js";import"./plugin-notebook-HbW2K-1c.js";import"./plugin-terminal-MXFIPun8.js";import"./plugin-pdf-CR8hgQBV.js";/**
3
3
  * @license lucide-react v0.511.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -14,4 +14,4 @@ import{y as zt,u as ne,j as n,a3 as Pn,I as Fn,b as M,h as On,k as Ln,X as Kt,l
14
14
  ${g}
15
15
  $$`:""}),b=b.replace(pr,(d,v)=>{const g=String(v||"").trim();return g?`$${g}$`:""});const s=qt(b,m,Vt);return qt(s,r,Ut)}const br=[".md",".markdown",".mdx"];function hr(e){const o=e.toLowerCase();return br.some(r=>o.endsWith(r))}function Wt(e){return String(e||"").replace(/[\u2010-\u2015]/g,"-").replace(/\s+/g," ").trim()}function xr(e,o){const r=Wt(e),i=Wt(o);if(!r||!i||i.length<12)return null;const m=r.indexOf(i);if(m>=0){const f=Math.max(0,m-160),x=Math.min(r.length,m+i.length+160);return r.slice(f,x).trim()}const b=i.split(" ").filter(Boolean).slice(0,8);if(b.length<3)return null;const s=b.map(f=>f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*?"),d=r.match(new RegExp(s,"i"));if(!d||typeof d.index!="number")return null;const v=Math.max(0,d.index-160),g=Math.min(r.length,d.index+d[0].length+160);return r.slice(v,g).trim()}function st(){const{t:e}=ne("pdf_viewer");return n.jsx("div",{className:"flex h-full items-center justify-center bg-muted/20",children:n.jsxs("div",{className:"flex flex-col items-center gap-3 text-muted-foreground",children:[n.jsx("div",{className:"h-8 w-8 rounded-full border-2 border-primary/60 border-t-transparent animate-spin"}),n.jsx("span",{className:"text-sm",children:e("loading_pdf")})]})})}function yr({highlight:e,selected:o,followed:r,flash:i,onSelect:m,onDelete:b,onUpdateKind:s,onUpdateComment:d,readOnly:v,registerItemRef:g}){const{t:f}=ne("pdf_viewer"),x=nn(e),j=x.kind,R=on(x,f),D=tn(e.tags)||String(e.id||"").slice(0,8),S=D.length>10?`${D.slice(0,10)}…`:D,C=e.author?.color||e.color||"#F1E9D0",k=e.author?.handle||"user",E=e.tags?.some(h=>h.toLowerCase()==="ai"),u=e.content?.text?String(e.content.text).trim():e.content?.image?f("area_highlight"):"",y=e.content?.text?rn(u,20):u,a=c.useRef(null),[p,_]=c.useState(!1),[A,I]=c.useState(e.comment?.text||"");return c.useEffect(()=>{p||I(e.comment?.text||"")},[e.comment?.text,p]),c.useEffect(()=>{i&&a.current?.scrollIntoView({block:"nearest",behavior:"smooth"})},[i]),c.useEffect(()=>{o&&a.current?.scrollIntoView({block:"nearest",behavior:"smooth"})},[o]),n.jsxs("div",{ref:h=>{a.current=h,g?.(e.id,h)},className:M("group relative p-3 rounded-lg border transition-all cursor-pointer",o?"border-primary bg-primary/5":r?"border-border bg-muted/30 hover:bg-muted/45":"border-border/60 hover:bg-muted/40",i?"ring-2 ring-primary/30 bg-primary/10 shadow-soft-card":null),onClick:m,children:[n.jsx("span",{className:M("absolute left-2 top-2 h-2 w-2 rounded-full",x.dotClass),"aria-hidden":!0}),n.jsxs(it,{children:[n.jsx(at,{asChild:!0,children:n.jsx("button",{type:"button",className:"absolute right-2 top-2 h-5 w-5 rounded-md border border-border bg-background/70 backdrop-blur flex items-center justify-center shadow-soft-sm",onClick:h=>h.stopPropagation(),title:k,children:n.jsx("span",{className:"h-2.5 w-2.5 rounded-full border border-border",style:{backgroundColor:C}})})}),n.jsxs(ct,{align:"end",children:[n.jsx(lt,{children:f("author")}),n.jsx(dt,{disabled:!0,children:k})]})]}),n.jsxs("div",{className:"flex items-start gap-3",children:[v?n.jsx("div",{className:M("mt-0.5 h-8 w-8 rounded-lg border border-border bg-background","flex items-center justify-center flex-shrink-0 shadow-soft-sm"),title:f("type_label"),children:n.jsx(x.Icon,{className:M("h-4 w-4",x.iconClass)})}):n.jsxs(it,{children:[n.jsx(at,{asChild:!0,children:n.jsx("button",{type:"button",className:M("mt-0.5 h-8 w-8 rounded-lg border border-border bg-background","flex items-center justify-center flex-shrink-0 shadow-soft-sm"),title:f("change_type"),onClick:h=>h.stopPropagation(),children:n.jsx(x.Icon,{className:M("h-4 w-4",x.iconClass)})})}),n.jsxs(ct,{align:"start",children:[n.jsx(lt,{children:f("type_label")}),n.jsxs(ro,{value:j,onValueChange:h=>s(Me(h)),children:[n.jsx(rt,{value:"note",children:f("type_note")}),n.jsx(rt,{value:"question",children:f("type_question")}),n.jsx(rt,{value:"task",children:f("type_task")})]})]})]}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[11px] font-medium text-foreground/90",children:R}),E?n.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-[9px] uppercase tracking-wide text-foreground/70",children:[n.jsx(Zt,{className:"h-3 w-3"}),"AI"]}):null,typeof e.position?.pageNumber=="number"?n.jsx("span",{className:"text-[9px] text-muted-foreground/70",children:f("page",{page:e.position.pageNumber})}):null,S?n.jsxs("span",{className:"text-[9px] text-muted-foreground/60",title:`ID ${D}`,children:["ID ",S]}):null]}),p?n.jsx(Xt,{value:A,onChange:h=>I(h.target.value),onClick:h=>h.stopPropagation(),className:"mt-2 min-h-[84px] text-[11px] leading-5",placeholder:f("add_comment_placeholder")}):n.jsx("div",{className:"mt-1 rounded-md border border-border/60 bg-background/70 px-2.5 py-2",children:e.comment?.text?.trim()?n.jsx(so,{content:gr(e.comment.text),rewriteDocsImages:!1,rewriteDocsLinks:!1,className:M("review-annotation-markdown text-[11px] leading-5 text-foreground/85 break-words","[&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0.5","[&_pre]:my-1 [&_pre]:max-w-full [&_pre]:overflow-x-auto","[&_pre]:whitespace-pre-wrap [&_code]:break-words","[&_.katex]:[word-break:normal] [&_.katex]:[overflow-wrap:normal]","[&_.katex]:whitespace-nowrap [&_.katex-display]:whitespace-normal","[&_.katex-display]:my-1 [&_.katex-display]:overflow-x-auto","[&_.katex-display]:overflow-y-hidden")}):n.jsx("p",{className:"review-annotation-text-fallback text-[11px] text-foreground/80 whitespace-pre-wrap break-words",children:f("no_comment_yet")})}),n.jsxs("div",{className:"mt-2 flex items-start justify-between gap-2",children:[n.jsx("p",{className:"review-annotation-text-fallback text-[9px] text-muted-foreground/60 whitespace-pre-wrap break-words",title:u||void 0,children:y}),v?n.jsx("div",{className:"text-[9px] text-muted-foreground",children:f("read_only")}):n.jsxs("div",{className:"flex items-center gap-1",children:[p?n.jsxs(n.Fragment,{children:[n.jsx(pe,{type:"button",variant:"secondary",size:"sm",className:"h-7 px-2 text-[10px]",onClick:h=>{h.stopPropagation(),_(!1),I(e.comment?.text||"")},children:"Cancel"}),n.jsx(pe,{type:"button",size:"sm",className:"h-7 px-2 text-[10px]",onClick:h=>{h.stopPropagation(),d(A.trim()),_(!1)},children:"Save"})]}):n.jsx(pe,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-[10px]",onClick:h=>{h.stopPropagation(),_(!0)},children:"Edit"}),n.jsx(pe,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-[10px] text-muted-foreground hover:text-foreground",onClick:h=>{h.stopPropagation(),b()},children:f("delete")})]})]})]})]})]})}function vr({highlights:e,selectedId:o,currentPage:r,flashId:i,onSelect:m,onDelete:b,onUpdateKind:s,onUpdateComment:d,showOverlayHints:v,readOnly:g}){const{t:f}=ne("pdf_viewer"),[x,j]=c.useState("all"),R=c.useRef(new Map),P=c.useRef(o),D=c.useRef(!1),S=c.useCallback((a,p)=>{const _=Number(a.position?.pageNumber||0),A=Number(p.position?.pageNumber||0),I=Number.isFinite(_)&&_>0?_:Number.MAX_SAFE_INTEGER,h=Number.isFinite(A)&&A>0?A:Number.MAX_SAFE_INTEGER;if(I!==h)return I-h;const H=Number(a.position?.boundingRect?.y1??a.position?.rects?.[0]?.y1??Number.MAX_SAFE_INTEGER),U=Number(p.position?.boundingRect?.y1??p.position?.rects?.[0]?.y1??Number.MAX_SAFE_INTEGER),F=Number.isFinite(H)?H:Number.MAX_SAFE_INTEGER,G=Number.isFinite(U)?U:Number.MAX_SAFE_INTEGER;if(F!==G)return F-G;const se=Number(a.position?.boundingRect?.x1??a.position?.rects?.[0]?.x1??Number.MAX_SAFE_INTEGER),X=Number(p.position?.boundingRect?.x1??p.position?.rects?.[0]?.x1??Number.MAX_SAFE_INTEGER),Z=Number.isFinite(se)?se:Number.MAX_SAFE_INTEGER,W=Number.isFinite(X)?X:Number.MAX_SAFE_INTEGER;return Z!==W?Z-W:a.id.localeCompare(p.id)},[]),C=c.useMemo(()=>{const a={all:e.length,issue:0,suggestion:0,verification:0,note:0,question:0,task:0};for(const p of e){const _=ut(p.tags);if(_){a[_]+=1;continue}const A=Me(p.comment?.emoji||ft(p.tags)||void 0);a[A]+=1}return a},[e]),k=c.useMemo(()=>{const a=[{key:"all",label:f("filter_all"),count:C.all}],p=[{key:"issue",label:f("review_type_issue"),count:C.issue},{key:"suggestion",label:f("review_type_suggestion"),count:C.suggestion},{key:"verification",label:f("review_type_verification"),count:C.verification}],_=[{key:"note",label:f("type_note"),count:C.note},{key:"question",label:f("type_question"),count:C.question},{key:"task",label:f("type_task"),count:C.task}],A=p.some(h=>h.count>0),I=_.some(h=>h.count>0);return A&&a.push(...p.filter(h=>h.count>0)),I&&a.push(..._.filter(h=>h.count>0)),a},[C,f]);c.useEffect(()=>{x!=="all"&&(k.some(a=>a.key===x)||j("all"))},[k,x]),c.useEffect(()=>{P.current&&!o&&(D.current=!0),P.current=o},[o]);const E=c.useMemo(()=>[...e.filter(p=>{if(x==="all")return!0;const _=ut(p.tags);return x==="issue"||x==="suggestion"||x==="verification"?_===x:_?!1:Me(p.comment?.emoji||ft(p.tags)||void 0)===x})].sort(S),[e,x,S]),u=c.useMemo(()=>{if(o||E.length===0)return null;const a=E.map(I=>({id:I.id,page:Number(I.position?.pageNumber||0)})).filter(I=>Number.isFinite(I.page)&&I.page>0);if(a.length===0)return null;const p=a.find(I=>I.page===r);if(p)return p.id;let _=a[0],A=Math.abs(a[0].page-r);for(let I=1;I<a.length;I+=1){const h=a[I],H=Math.abs(h.page-r);if(H<A){_=h,A=H;continue}H===A&&h.page<_.page&&(_=h)}return _.id},[r,E,o]);c.useEffect(()=>{if(!u)return;if(D.current){D.current=!1;return}const a=R.current.get(u);a&&a.scrollIntoView({block:"nearest",behavior:"smooth"})},[u]);const y=c.useCallback((a,p)=>{if(a){if(!p){R.current.delete(a);return}R.current.set(a,p)}},[]);return e.length===0?n.jsxs("div",{className:"flex flex-col items-center justify-center h-full p-4 text-center",children:[n.jsx("div",{className:"text-4xl mb-2 opacity-30",children:"📝"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:f("no_annotations")}),n.jsx("p",{className:"text-[11px] text-muted-foreground/60 mt-1",children:f(g?"read_only_annotation_desc":"select_text_to_highlight")})]}):n.jsxs("div",{className:"flex flex-col h-full",children:[n.jsxs("div",{className:"p-3 border-b space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("h3",{className:"font-medium text-xs",children:[f("annotations")," (",E.length,"/",e.length,")"]}),n.jsx("span",{className:M("inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-medium tracking-wide",v?"border-black/10 bg-white text-foreground/70":"border-border bg-background text-muted-foreground"),title:f("all_markers_shown"),children:f("markers_on")})]}),n.jsx("div",{className:"flex items-center gap-1",children:k.map(a=>{const p=x===a.key;return n.jsxs("button",{type:"button",onClick:()=>j(a.key),className:M("inline-flex min-w-0 flex-1 items-center justify-center rounded-md border px-2 py-1 text-[10px] transition-colors",p?"border-primary/40 bg-primary/10 text-foreground":"border-border/70 bg-background text-muted-foreground hover:text-foreground"),title:f("filter_annotations_title",{label:a.label}),children:[a.label," (",a.count,")"]},a.key)})})]}),E.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center px-4 text-center text-xs text-muted-foreground",children:"No annotations for current filter."}):n.jsx("div",{className:"flex-1 overflow-auto p-2 space-y-2",children:E.map(a=>n.jsx(yr,{highlight:a,selected:o===a.id,followed:!!(u&&u===a.id),flash:!!(i&&i===a.id),onSelect:()=>m(a.id),onDelete:()=>b(a.id),onUpdateKind:p=>s(a.id,p),onUpdateComment:p=>d(a.id,p),readOnly:g,registerItemRef:y},a.id))})]})}function wr({pdfDocument:e,scale:o,highlights:r,selectedId:i,onSelect:m,onAdd:b,onUpdate:s,onScrollRef:d,onPageChange:v,pdfHighlighterRef:g,authorColor:f,authorHandle:x,showOverlayHints:j,tipPlacementMode:R,readOnly:P,onAskCopilot:D}){const{t:S}=ne("pdf_viewer"),{setTotalPages:C}=en(),[k,E]=c.useState(null),u=o===1?"page-width":`page-width:${o}`,y=k||i||null;return c.useEffect(()=>{C(e.numPages)},[e.numPages,C]),n.jsx(xo,{ref:g,pdfDocument:e,pdfScaleValue:u,tipPlacementMode:R,onPageChange:v,enableAreaSelection:a=>P?!1:a.altKey,onScrollChange:()=>{},scrollRef:d,highlights:r,onSelectionFinished:(a,p,_,A)=>P?null:n.jsx(Fo,{onOpen:A,onCancel:_,onConfirm:I=>{b({content:p,position:a,comment:I}),_()},onAskCopilot:()=>{D?.(p,a),_()},authorColor:f,authorHandle:x,showAuthorHandle:!1}),highlightTransform:(a,p,_,A,I,h,H,U)=>{const F=!!a.__dsGhost,G=a.__dsGhostOpacity??1,se=a.__dsGhostMode,X=!a.content?.image,Z=nn({comment:a.comment,tags:a.tags}),W=String(on(Z,S)||S("annotation_label")),J=tn(a.tags),ge=L(a.previewSummary),be=J?`#${J} · ${W}`:`P${a.position.pageNumber} · ${W}`,ie=ge||rn(a.comment?.text||"",8),ke=J?ie?`${be}
16
16
  ${ie}`:be:ie?`${be}
17
- ${ie}`:be,Ne=`${W} · ${S("page",{page:a.position.pageNumber})} · ${S("open_details_hint")}`,de=dr(),he=y===a.id,je=!!(y&&!he),Se=X?n.jsx(Jo,{isScrolledTo:H||a.id===i,position:a.position,comment:a.comment,color:a.color,hidden:je,emphasized:he,onHoverStart:F?void 0:()=>E(a.id),onHoverEnd:F?void 0:()=>E(Y=>Y===a.id?null:Y),onClick:F?void 0:()=>m(a.id,{allowToggleClose:!1,skipAutoScroll:!0}),showOverlayHint:!F&&j&&!je,overlayHintText:ke,overlayHintTitle:Ne,overlayHintBorderColor:de.borderColor,overlayHintTextColor:de.textColor,overlayHintBackgroundColor:de.backgroundColor,overlayHintTopPx:U.overlayHintTopById?.[a.id],overlayHintLeftPx:U.overlayHintLeftPx,overlayHintWidthPx:U.overlayHintWidthPx,overlayHintPageHeightPx:U.height,onOverlayHintClick:F?void 0:()=>{m(a.id,{skipAutoScroll:!0})}}):n.jsx(or,{isScrolledTo:H||a.id===i,highlight:a,hidden:je,emphasized:he,onHoverStart:F?void 0:()=>E(a.id),onHoverEnd:F?void 0:()=>E(Y=>Y===a.id?null:Y),onSelect:F?void 0:()=>m(a.id,{allowToggleClose:!1,skipAutoScroll:!0}),onChange:Y=>{P||s(a.id,{boundingRect:I(Y)},{image:h(Y)})}});return F?n.jsx("div",{className:M("pointer-events-none",se==="annotate"?"ds-pdf-ghost-annotate":"ds-pdf-ghost-guide"),style:{opacity:G,transition:"opacity 0.8s ease"},children:Se},`ghost-${p}`):Se}})}function Dr({context:e,tabId:o,setDirty:r,setTitle:i}){const{t:m}=ne("pdf_viewer"),b=e.resourceId??(typeof e.customData?.fileId=="string"?e.customData.fileId:null),s=b?String(b):"",d=Qn(s),v=typeof e.customData?.reviewRouteId=="string"?e.customData.reviewRouteId.trim():"",g=typeof e.customData?.rebuttalRouteId=="string"?e.customData.rebuttalRouteId.trim():"",f=v.length>0,x=g.length>0,j=f||x,P=(f?v:g).startsWith("shared-"),D=P?.8:1,S=x?P?"ds:rebuttal:pdf:annotation-sidebar-width:shared:v1":"ds:rebuttal:pdf:annotation-sidebar-width:v1":P?"ds:review:pdf:annotation-sidebar-width:shared:v1":"ds:review:pdf:annotation-sidebar-width:v4",C=Math.round(336*D),k=Math.round(816*D),E=Math.round(673*D),u=!!(typeof e.customData?.readOnlyMode=="boolean"&&e.customData.readOnlyMode),y=c.useMemo(()=>{if(!u)return[];const t=e.customData?.readOnlyAnnotations;return Array.isArray(t)?t.map(l=>sr(l)).filter(l=>!!l):[]},[e.customData?.readOnlyAnnotations,u]),a=c.useRef(!1),p=e.resourceName||"Untitled.pdf",_=typeof e.customData?.externalPdfUrl=="string"?e.customData.externalPdfUrl.trim():"",A=_.length>0,I=(ce.defaults.baseURL||"").replace(/\/$/,""),h=qn(s),H=c.useMemo(()=>s&&h?Wn(s):null,[s,h]),U=c.useMemo(()=>(typeof e.customData?.projectId=="string"?e.customData.projectId.trim():"")||null,[e.customData]),[F,G]=c.useState(null),[se,X]=c.useState(!1),[Z,W]=c.useState(null),[J,ge]=c.useState(null),[be,ie]=c.useState(!1),[ke,Ne]=c.useState(null),de=A?_:d?F||"":h?J||"":s?`${I}/api/v1/files/${s}/content`:"https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf",he=typeof window<"u"?localStorage.getItem("ds_access_token"):null,je=he&&(A||!d&&!h&&s)?{Authorization:`Bearer ${he}`}:void 0,{scale:Se,setScale:Y,currentPage:De,setCurrentPage:ue,totalPages:sn,sidebarVisible:B,toggleSidebar:V,selectedAnnotationId:ae,selectAnnotation:oe}=en(),Pe=zn(t=>t.updateTabPlugin),pt=Kn(t=>t.findNode),gt=ot(t=>t.updateTabState),bt=ot(t=>t.addReference),Xe=ot(t=>t.updateReference),Fe=typeof e.customData?.onOpenMarkdownView=="function"?e.customData.onOpenMarkdownView:null,ht=typeof e.customData?.onOpenReviewOpinionView=="function"?e.customData.onOpenReviewOpinionView:null,an=!!(typeof e.customData?.reviewOpinionAvailable=="boolean"&&e.customData.reviewOpinionAvailable),cn=(typeof e.customData?.reviewViewMode=="string"?e.customData.reviewViewMode:"")==="ai_review",ln=typeof e.customData?.reviewOpinionLabel=="string"?e.customData.reviewOpinionLabel:void 0,dn=typeof e.customData?.reviewOpinionTitle=="string"?e.customData.reviewOpinionTitle:void 0,Re=Gt(),{addToast:xt}=Gn(),Ze=Ft(t=>t.items),un=Ft(t=>t.errors),Oe=c.useMemo(()=>e.customData?.arxiv??null,[e.customData]),Q=!!Oe||!!(s&&Ze.some(t=>t.fileId===s)),fn=d||!s||u?"":s,{annotations:Le,createAnnotation:yt,updateAnnotation:xe,deleteAnnotation:vt}=Ao(fn),He=Xn(t=>t.user),[fe,wt]=c.useState(null),[mn,pn]=c.useState("#F1E9D0"),[gn,_t]=c.useState(!1),kt=c.useRef({}),Je=c.useRef({}),Nt=!0,[jt,Ye]=c.useState([]),Ie=c.useRef(new Map),Ee=c.useRef(null),[bn,St]=c.useState(null),[ye,hn]=c.useState(()=>{if(typeof window>"u")return E;const t=window.localStorage.getItem(S),l=t?Number(t):NaN;return Number.isFinite(l)?Math.max(C,Math.min(k,l)):E}),Rt=c.useRef(ye),Ce=c.useRef(null),It=c.useRef(B),Et=c.useRef(V),et=c.useRef(()=>{}),ve=c.useRef(null),Ct=c.useRef(null),we=c.useRef(!1),tt=hr(p);c.useEffect(()=>{Rt.current=ye},[ye]),c.useEffect(()=>{!j||typeof window>"u"||window.localStorage.setItem(S,String(ye))},[S,j,ye]);const At=c.useCallback(t=>{const l=typeof window<"u"?Math.max(C,Math.min(k,Math.floor(window.innerWidth*.75))):k;return Math.max(C,Math.min(l,t))},[k,C]),xn=c.useCallback(t=>{if(!j||t.button!==0)return;t.preventDefault(),t.stopPropagation();const l=t.clientX,N=Rt.current;document.body.style.cursor="col-resize",document.body.style.userSelect="none";const w=O=>{const q=l-O.clientX;hn(At(N+q))},T=()=>{document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",T)};document.addEventListener("mousemove",w),document.addEventListener("mouseup",T)},[At,j]),$=c.useMemo(()=>Oe||s&&Ze.find(t=>t.fileId===s)||null,[Oe,Ze,s]),yn=$?un[$.arxivId]:void 0,vn=!!(s&&!d&&(!Q||$?.overview?.trim()||$?.abstract?.trim())),wn=m(Q?"summary":"markdown"),_n=m(Q?"open_summary":"open_markdown");c.useEffect(()=>{It.current=B},[B]),c.useEffect(()=>{Et.current=V},[V]);const kn=c.useCallback(async()=>{if(!$)return;const t=Zn($),l=await Jn(t);xt({type:l?"success":"error",title:m(l?"toast_bibtex_copied_title":"toast_copy_failed_title"),description:l?$.title||$.arxivId:m("try_again"),duration:1800})},[xt,$,m]),Nn=c.useCallback(()=>{$?.arxivId&&window.open(`https://arxiv.org/abs/${$.arxivId}`,"_blank","noopener,noreferrer")},[$]),Tt=c.useCallback(()=>{const t=String(e.resourcePath||"").trim();if(t.startsWith("/FILES"))return t;if(s){const l=pt(s);if(l?.path)return Ot(l.path)}if(t)return Ot(t)},[e.resourcePath,s,pt]),$e=c.useCallback(async()=>{if(!s||d||Q)return null;const t=kt.current[s];if(t)return t;const l=Je.current[s];if(l)return l;const N=ce.get(`/api/v1/pdf/markdown/${s}`,{responseType:"text",transformResponse:[w=>w]}).then(w=>{const T=typeof w.data=="string"?w.data:String(w.data||"");return T?(kt.current[s]=T,T):null}).finally(()=>{delete Je.current[s]});return Je.current[s]=N,N},[s,Q,d]),Mt=c.useCallback(async(t,l)=>{if(!(!s||d||Q))try{const N=await $e(),w=xr(N||"",l);Xe(t,{markdownExcerpt:w||void 0,excerptStatus:w?"ready":"error"})}catch{Xe(t,{excerptStatus:"error"})}},[s,Q,d,$e,Xe]);c.useEffect(()=>{!s||d||Q||$e().catch(()=>{})},[s,Q,d,$e]);const jn=c.useCallback((t,l)=>{const N=String(t?.text||"").trim();if(!N)return;const w=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`pdf-ref-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,T=l.boundingRect?[{left:l.boundingRect.x1,top:l.boundingRect.y1,width:l.boundingRect.width,height:l.boundingRect.height,pageNumber:l.boundingRect.pageNumber}]:[];bt({id:w,kind:"pdf_text",tabId:o,fileId:s||void 0,resourceId:s||void 0,resourcePath:Tt(),resourceName:p,pageNumber:l.pageNumber,selectedText:N,markdownExcerpt:void 0,excerptStatus:s&&!d&&!Q?"loading":"idle",rects:l.rects?.map(O=>({left:O.x1,top:O.y1,width:O.width,height:O.height,pageNumber:O.pageNumber}))||T,createdAt:new Date().toISOString()}),window.dispatchEvent(new CustomEvent("ds:copilot:focus",{detail:{focus:!0}})),s&&!d&&!Q&&Mt(w,N)},[bt,Mt,s,p,Q,d,Tt,o]);c.useEffect(()=>{tt&&Pe(o,Lt.NOTEBOOK,{...e,resourceId:s,resourceName:p,mimeType:e.mimeType??"text/markdown",customData:{...e.customData||{},docKind:"markdown"}})},[e,s,p,tt,o,Pe]),c.useEffect(()=>{i(p)},[p,i]),c.useEffect(()=>{r(!1)},[r]),c.useEffect(()=>{gt(o,{contentKind:"pdf",documentMode:"pdf",pageNumber:De,isReadOnly:u})},[De,u,o,gt]),c.useEffect(()=>{const t=U||H;if(t){wt(t);return}!s||d||Yn(s).then(l=>{l?.project_id&&wt(String(l.project_id))}).catch(()=>{})},[s,A,d,U,H]),c.useEffect(()=>{if(!s||!d){G(null),X(!1),W(null);return}let t=!1,l=null;return X(!0),W(null),(async()=>{try{const{createFileObjectUrl:w}=await Ht(async()=>{const{createFileObjectUrl:T}=await import("./index-Gbl53BNp.js").then(O=>O.el);return{createFileObjectUrl:T}},__vite__mapDeps([0,1,2,3,4]));if(l=await w(s),t){URL.revokeObjectURL(l);return}G(l)}catch{t||W("Failed to load PDF from CLI server.")}finally{t||X(!1)}})(),()=>{t=!0,l&&URL.revokeObjectURL(l)}},[s,d]),c.useEffect(()=>{if(!s||!h||d){ge(null),ie(!1),Ne(null);return}let t=!1,l=null;return ie(!0),Ne(null),(async()=>{try{if(l=await no(s),t){URL.revokeObjectURL(l);return}ge(l)}catch{t||Ne("Failed to load PDF document.")}finally{t||ie(!1)}})(),()=>{t=!0,l&&URL.revokeObjectURL(l)}},[s,d,h]),c.useEffect(()=>{if(!fe)return;const t=He?.id;t&&eo(fe).then(l=>{const N=l.find(w=>w.user_id===t);N?.annotation_color&&pn(String(N.annotation_color))}).catch(()=>{})},[fe,He?.id]),c.useEffect(()=>{if(!fe||!s||d||u)return;const{socket:t,release:l}=io();Ct.current={socket:t,release:l};const N=async()=>{if(!we.current&&t.connected)try{we.current=!0,await t.emitWithAck("file:join",{projectId:fe,fileId:s,clientVersion:"1.0.0"})}catch{we.current=!1}},w=()=>void N(),T=()=>{we.current=!1},O=q=>{if(q?.fileId&&String(q.fileId)!==String(s))return;Re.invalidateQueries({queryKey:le.list(s)});const qe=typeof q?.annotationId=="string"&&q.annotationId.trim()?q.annotationId.trim():null;qe&&(Ee.current=qe,It.current||Et.current?.())};return t.on("connect",w),t.on("disconnect",T),t.on("annotation:created",O),t.on("annotation:updated",O),t.on("annotation:deleted",O),t.connected&&N(),()=>{try{t.off("connect",w),t.off("disconnect",T),t.off("annotation:created",O),t.off("annotation:updated",O),t.off("annotation:deleted",O),we.current&&t.emit("file:leave",{projectId:fe,fileId:s})}finally{we.current=!1,Ct.current=null,l()}}},[fe,s,d,u]);const re=c.useMemo(()=>u?y:Le.map(t=>({id:t.id,position:t.position,content:t.content,comment:{text:t.comment||"",emoji:t.kind},color:t.color,author:t.author??null,tags:t.tags,previewSummary:typeof t.content?.summary=="string"&&String(t.content.summary||"").trim()||null})),[Le,u,y]),Sn=c.useMemo(()=>[...re,...jt],[re,jt]);c.useEffect(()=>{const t=Ee.current;if(!t)return;const l=re.find(N=>N.id===t);l&&(oe(l.id),ue(l.position.pageNumber),et.current(l),Ee.current=null,St(l.id),Ce.current&&clearTimeout(Ce.current),Ce.current=setTimeout(()=>St(null),2200))},[re,oe,ue]),c.useEffect(()=>{const t=ve.current;return()=>{t?.setPinnedTipForHighlight(null),Ce.current&&clearTimeout(Ce.current)}},[]),c.useEffect(()=>{if(!u){a.current=!1;return}a.current||re.length!==0&&(a.current=!0,B||V())},[re.length,u,B,V]);const Ae=c.useCallback(t=>{ue(t),ve.current?.scrollToPage(t)},[ue]),Dt=c.useCallback(t=>{const l=`ai-ghost-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,N=t.rects.map(ee=>({...ee,width:ee.width??100,height:ee.height??100,pageNumber:ee.pageNumber??t.page})),w={...t.boundingRect,width:t.boundingRect.width??100,height:t.boundingRect.height??100,pageNumber:t.boundingRect.pageNumber??t.page},T={id:l,position:{boundingRect:w,rects:N,pageNumber:t.page},content:{text:t.text||""},comment:{text:"",emoji:"note"},color:t.color||"#3F5A6B",__dsGhost:!0,__dsGhostOpacity:1,__dsGhostMode:t.mode||"guide"};Ye(ee=>[...ee,T]);const O=t.durationMs??3e3,q=setTimeout(()=>{Ye(ee=>ee.map(Te=>Te.id===l?{...Te,__dsGhostOpacity:0}:Te))},O),qe=setTimeout(()=>{Ye(ee=>ee.filter(Te=>Te.id!==l)),Ie.current.delete(l),Ie.current.delete(`${l}:fade`)},O+800);Ie.current.set(l,qe),Ie.current.set(`${l}:fade`,q)},[]);c.useEffect(()=>{const t=Ie.current;return()=>{t.forEach(l=>clearTimeout(l)),t.clear()}},[]);const Be=c.useCallback(t=>{const l=typeof t?.__dsEffectId=="string"?t.__dsEffectId:null;return l?co(l)?!0:(lo(l),!1):!1},[]),Ue=c.useCallback(t=>{!t||t.fileId!==s||Be(t)||(Re.invalidateQueries({queryKey:le.list(s)}),t.page&&Ae(t.page),t.rects&&t.boundingRect&&Dt({page:t.page||1,rects:t.rects,boundingRect:t.boundingRect,color:t.color,mode:t.mode||"guide",durationMs:t.durationMs,text:t.text}),t.annotationId&&(Ee.current=t.annotationId),(t.annotationId||t.__dsEffectId)&&!B&&V())},[Dt,s,Re,Ae,B,V,Be]),Ve=c.useCallback(t=>{!t||t.fileId!==s||Be(t)||(Re.invalidateQueries({queryKey:le.list(s)}),t.page&&Ae(t.page),t.annotationId&&(Ee.current=t.annotationId,B||V()))},[s,Re,Ae,B,V,Be]),Qe=c.useCallback(()=>{if(!s)return;const t=uo(s);t.length!==0&&t.forEach(l=>{l.name==="pdf:jump"?Ue(l.data):Ve(l.data)})},[Ve,Ue,s]);c.useEffect(()=>{s&&Qe()},[s,Qe]),c.useEffect(()=>{if(typeof window>"u"||!s)return;const t=w=>{const T=w.detail;Ue(T)},l=w=>{const T=w.detail;Ve(T)},N=w=>{const T=w.detail;!T||T.fileId!==s||Qe()};return window.addEventListener("pdf:navigate",t),window.addEventListener("pdf:annotation_created",l),window.addEventListener("ds:pdf:queue",N),()=>{window.removeEventListener("pdf:navigate",t),window.removeEventListener("pdf:annotation_created",l),window.removeEventListener("ds:pdf:queue",N)}},[Ve,Ue,s,Qe]);const Rn=c.useCallback(async t=>{if(!(u||d||!s))try{const l=Me(t.comment?.emoji);(await yt({fileId:s,position:t.position,content:t.content,comment:t.comment?.text||"",kind:l,tags:[]}))?.id&&!B&&V()}catch(l){console.warn("[PdfViewerPlugin] Failed to create annotation:",l)}},[yt,s,d,u,B,V]),In=c.useCallback(async(t,l,N)=>{if(!(u||d||!s))try{const w=Le.find(q=>q.id===t);if(!w)return;const T={...w.position,...l,boundingRect:{...w.position.boundingRect,...l.boundingRect}},O={...w.content,...N};await xe(t,{position:T,content:O})}catch(w){console.warn("[PdfViewerPlugin] Failed to update annotation position/content:",w)}},[Le,s,d,u,xe]),Pt=c.useCallback((t,l)=>{const N=re.find(q=>q.id===t);if(!N)return;const w=l?.allowToggleClose!==!1,T=l?.skipAutoScroll===!0;if(w&&ae===t){oe(null),ve.current?.setPinnedTipForHighlight(null);return}B||V(),oe(t),ve.current?.setPinnedTipForHighlight(null),T||(ue(N.position.pageNumber),et.current(N))},[re,ae,B,oe,ue,V]),En=c.useCallback(t=>{const l=t.target;l&&(l.closest("[data-ds-highlight-target='true']")||l.closest("[data-ds-overlay-hint='true']")||ae&&(oe(null),ve.current?.setPinnedTipForHighlight(null)))},[ae,oe]),Cn=c.useCallback(async t=>{if(!(u||d||!s))try{await vt(t),ae===t&&oe(null)}catch(l){console.warn("[PdfViewerPlugin] Failed to delete annotation:",l)}},[vt,s,d,u,ae,oe]),An=c.useCallback(async(t,l)=>{if(!(u||d||!s))try{await xe(t,{kind:l})}catch(N){console.warn("[PdfViewerPlugin] Failed to update annotation kind:",N)}},[s,d,u,xe]),Tn=c.useCallback(async(t,l)=>{if(!(u||d||!s))try{await xe(t,{comment:l})}catch(N){console.warn("[PdfViewerPlugin] Failed to update annotation comment:",N)}},[s,d,u,xe]),Mn=c.useCallback(()=>{if(!s){window.open(de,"_blank");return}(async()=>{const{downloadFileById:t}=await Ht(async()=>{const{downloadFileById:l}=await import("./index-Gbl53BNp.js").then(N=>N.el);return{downloadFileById:l}},__vite__mapDeps([0,1,2,3,4]));await t(s,p)})()},[s,p,de]),Dn=c.useCallback(()=>{if(Fe){Fe();return}!s||d||Pe(o,Lt.PDF_MARKDOWN,{...e,customData:{...e.customData||{},pdfView:Q?"summary":"markdown"}})},[e,s,Q,d,Fe,o,Pe]);return tt?n.jsx("div",{className:"flex h-full items-center justify-center bg-muted/20",children:n.jsx("div",{className:"text-sm text-muted-foreground",children:"Switching to Markdown editor..."})}):d&&(se||Z)&&!F?n.jsx("div",{className:"h-full flex items-center justify-center bg-background",children:Z?n.jsx("div",{className:"text-sm text-muted-foreground",children:Z}):n.jsx(st,{})}):h&&(be||ke)&&!J?n.jsx("div",{className:"h-full flex items-center justify-center bg-background",children:ke?n.jsx("div",{className:"text-sm text-muted-foreground",children:ke}):n.jsx(st,{})}):n.jsxs("div",{className:"h-full flex flex-col bg-background",children:[n.jsx(Io,{scale:Se,onScaleChange:Y,currentPage:De,totalPages:sn,onPageChange:Ae,sidebarVisible:B,onSidebarToggle:V,onDownload:Mn,onInfo:$?()=>_t(!0):void 0,onMarkdownToggle:Fe||vn?Dn:void 0,markdownLabel:wn,markdownTitle:_n,reviewOpinionActive:cn,onReviewOpinionToggle:an&&ht?ht:void 0,reviewOpinionLabel:ln,reviewOpinionTitle:dn}),n.jsxs("div",{className:"flex-1 flex overflow-hidden bg-muted/10",children:[n.jsx("div",{className:"flex-1 overflow-hidden flex",children:n.jsx("div",{className:"relative h-full w-full",children:n.jsx("div",{className:"relative h-full overflow-hidden border border-border bg-background shadow-soft-card",onPointerDown:En,children:n.jsx(po,{url:de,httpHeaders:je,workerSrc:ho,cMapUrl:bo,cMapPacked:go,beforeLoad:n.jsx(st,{}),children:t=>n.jsx(wr,{pdfDocument:t,scale:Se,highlights:Sn,selectedId:ae,onSelect:Pt,onAdd:Rn,onUpdate:In,onScrollRef:l=>{et.current=l},onPageChange:l=>ue(l),pdfHighlighterRef:ve,authorColor:mn,authorHandle:(He?.email?He.email.split("@",1)[0]:"")||"user",showOverlayHints:Nt,tipPlacementMode:j?"right":"auto",readOnly:u,onAskCopilot:jn})})})})}),B&&n.jsxs("div",{className:M("relative border-l bg-background/60 backdrop-blur flex-shrink-0",j?"":"w-72"),style:j?{width:ye}:void 0,children:[j?n.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":m("resize_annotation_sidebar"),tabIndex:0,className:"group absolute inset-y-0 left-0 z-20 w-3 -translate-x-1/2 cursor-ew-resize touch-none",onPointerDown:xn,children:n.jsx("span",{className:"pointer-events-none absolute top-1/2 left-1/2 h-16 w-[2px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-black/20 opacity-0 transition-opacity group-hover:opacity-100"})}):null,n.jsx(vr,{highlights:re,selectedId:ae,currentPage:De,flashId:bn,onSelect:Pt,onDelete:Cn,onUpdateKind:An,onUpdateComment:Tn,showOverlayHints:Nt,readOnly:u})]})]}),n.jsx(to,{open:gn,onClose:()=>_t(!1),paper:$,errorCode:yn,onCopyBibtex:$?kn:void 0,onOpenArxiv:$?Nn:void 0})]})}function Pr(){console.debug("[PdfViewerPlugin] Activated")}function Fr(){console.debug("[PdfViewerPlugin] Deactivated")}export{Dr as default,Pr as onPdfViewerActivate,Fr as onPdfViewerDeactivate};
17
+ ${ie}`:be,Ne=`${W} · ${S("page",{page:a.position.pageNumber})} · ${S("open_details_hint")}`,de=dr(),he=y===a.id,je=!!(y&&!he),Se=X?n.jsx(Jo,{isScrolledTo:H||a.id===i,position:a.position,comment:a.comment,color:a.color,hidden:je,emphasized:he,onHoverStart:F?void 0:()=>E(a.id),onHoverEnd:F?void 0:()=>E(Y=>Y===a.id?null:Y),onClick:F?void 0:()=>m(a.id,{allowToggleClose:!1,skipAutoScroll:!0}),showOverlayHint:!F&&j&&!je,overlayHintText:ke,overlayHintTitle:Ne,overlayHintBorderColor:de.borderColor,overlayHintTextColor:de.textColor,overlayHintBackgroundColor:de.backgroundColor,overlayHintTopPx:U.overlayHintTopById?.[a.id],overlayHintLeftPx:U.overlayHintLeftPx,overlayHintWidthPx:U.overlayHintWidthPx,overlayHintPageHeightPx:U.height,onOverlayHintClick:F?void 0:()=>{m(a.id,{skipAutoScroll:!0})}}):n.jsx(or,{isScrolledTo:H||a.id===i,highlight:a,hidden:je,emphasized:he,onHoverStart:F?void 0:()=>E(a.id),onHoverEnd:F?void 0:()=>E(Y=>Y===a.id?null:Y),onSelect:F?void 0:()=>m(a.id,{allowToggleClose:!1,skipAutoScroll:!0}),onChange:Y=>{P||s(a.id,{boundingRect:I(Y)},{image:h(Y)})}});return F?n.jsx("div",{className:M("pointer-events-none",se==="annotate"?"ds-pdf-ghost-annotate":"ds-pdf-ghost-guide"),style:{opacity:G,transition:"opacity 0.8s ease"},children:Se},`ghost-${p}`):Se}})}function Dr({context:e,tabId:o,setDirty:r,setTitle:i}){const{t:m}=ne("pdf_viewer"),b=e.resourceId??(typeof e.customData?.fileId=="string"?e.customData.fileId:null),s=b?String(b):"",d=Qn(s),v=typeof e.customData?.reviewRouteId=="string"?e.customData.reviewRouteId.trim():"",g=typeof e.customData?.rebuttalRouteId=="string"?e.customData.rebuttalRouteId.trim():"",f=v.length>0,x=g.length>0,j=f||x,P=(f?v:g).startsWith("shared-"),D=P?.8:1,S=x?P?"ds:rebuttal:pdf:annotation-sidebar-width:shared:v1":"ds:rebuttal:pdf:annotation-sidebar-width:v1":P?"ds:review:pdf:annotation-sidebar-width:shared:v1":"ds:review:pdf:annotation-sidebar-width:v4",C=Math.round(336*D),k=Math.round(816*D),E=Math.round(673*D),u=!!(typeof e.customData?.readOnlyMode=="boolean"&&e.customData.readOnlyMode),y=c.useMemo(()=>{if(!u)return[];const t=e.customData?.readOnlyAnnotations;return Array.isArray(t)?t.map(l=>sr(l)).filter(l=>!!l):[]},[e.customData?.readOnlyAnnotations,u]),a=c.useRef(!1),p=e.resourceName||"Untitled.pdf",_=typeof e.customData?.externalPdfUrl=="string"?e.customData.externalPdfUrl.trim():"",A=_.length>0,I=(ce.defaults.baseURL||"").replace(/\/$/,""),h=qn(s),H=c.useMemo(()=>s&&h?Wn(s):null,[s,h]),U=c.useMemo(()=>(typeof e.customData?.projectId=="string"?e.customData.projectId.trim():"")||null,[e.customData]),[F,G]=c.useState(null),[se,X]=c.useState(!1),[Z,W]=c.useState(null),[J,ge]=c.useState(null),[be,ie]=c.useState(!1),[ke,Ne]=c.useState(null),de=A?_:d?F||"":h?J||"":s?`${I}/api/v1/files/${s}/content`:"https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf",he=typeof window<"u"?localStorage.getItem("ds_access_token"):null,je=he&&(A||!d&&!h&&s)?{Authorization:`Bearer ${he}`}:void 0,{scale:Se,setScale:Y,currentPage:De,setCurrentPage:ue,totalPages:sn,sidebarVisible:B,toggleSidebar:V,selectedAnnotationId:ae,selectAnnotation:oe}=en(),Pe=zn(t=>t.updateTabPlugin),pt=Kn(t=>t.findNode),gt=ot(t=>t.updateTabState),bt=ot(t=>t.addReference),Xe=ot(t=>t.updateReference),Fe=typeof e.customData?.onOpenMarkdownView=="function"?e.customData.onOpenMarkdownView:null,ht=typeof e.customData?.onOpenReviewOpinionView=="function"?e.customData.onOpenReviewOpinionView:null,an=!!(typeof e.customData?.reviewOpinionAvailable=="boolean"&&e.customData.reviewOpinionAvailable),cn=(typeof e.customData?.reviewViewMode=="string"?e.customData.reviewViewMode:"")==="ai_review",ln=typeof e.customData?.reviewOpinionLabel=="string"?e.customData.reviewOpinionLabel:void 0,dn=typeof e.customData?.reviewOpinionTitle=="string"?e.customData.reviewOpinionTitle:void 0,Re=Gt(),{addToast:xt}=Gn(),Ze=Ft(t=>t.items),un=Ft(t=>t.errors),Oe=c.useMemo(()=>e.customData?.arxiv??null,[e.customData]),Q=!!Oe||!!(s&&Ze.some(t=>t.fileId===s)),fn=d||!s||u?"":s,{annotations:Le,createAnnotation:yt,updateAnnotation:xe,deleteAnnotation:vt}=Ao(fn),He=Xn(t=>t.user),[fe,wt]=c.useState(null),[mn,pn]=c.useState("#F1E9D0"),[gn,_t]=c.useState(!1),kt=c.useRef({}),Je=c.useRef({}),Nt=!0,[jt,Ye]=c.useState([]),Ie=c.useRef(new Map),Ee=c.useRef(null),[bn,St]=c.useState(null),[ye,hn]=c.useState(()=>{if(typeof window>"u")return E;const t=window.localStorage.getItem(S),l=t?Number(t):NaN;return Number.isFinite(l)?Math.max(C,Math.min(k,l)):E}),Rt=c.useRef(ye),Ce=c.useRef(null),It=c.useRef(B),Et=c.useRef(V),et=c.useRef(()=>{}),ve=c.useRef(null),Ct=c.useRef(null),we=c.useRef(!1),tt=hr(p);c.useEffect(()=>{Rt.current=ye},[ye]),c.useEffect(()=>{!j||typeof window>"u"||window.localStorage.setItem(S,String(ye))},[S,j,ye]);const At=c.useCallback(t=>{const l=typeof window<"u"?Math.max(C,Math.min(k,Math.floor(window.innerWidth*.75))):k;return Math.max(C,Math.min(l,t))},[k,C]),xn=c.useCallback(t=>{if(!j||t.button!==0)return;t.preventDefault(),t.stopPropagation();const l=t.clientX,N=Rt.current;document.body.style.cursor="col-resize",document.body.style.userSelect="none";const w=O=>{const q=l-O.clientX;hn(At(N+q))},T=()=>{document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",T)};document.addEventListener("mousemove",w),document.addEventListener("mouseup",T)},[At,j]),$=c.useMemo(()=>Oe||s&&Ze.find(t=>t.fileId===s)||null,[Oe,Ze,s]),yn=$?un[$.arxivId]:void 0,vn=!!(s&&!d&&(!Q||$?.overview?.trim()||$?.abstract?.trim())),wn=m(Q?"summary":"markdown"),_n=m(Q?"open_summary":"open_markdown");c.useEffect(()=>{It.current=B},[B]),c.useEffect(()=>{Et.current=V},[V]);const kn=c.useCallback(async()=>{if(!$)return;const t=Zn($),l=await Jn(t);xt({type:l?"success":"error",title:m(l?"toast_bibtex_copied_title":"toast_copy_failed_title"),description:l?$.title||$.arxivId:m("try_again"),duration:1800})},[xt,$,m]),Nn=c.useCallback(()=>{$?.arxivId&&window.open(`https://arxiv.org/abs/${$.arxivId}`,"_blank","noopener,noreferrer")},[$]),Tt=c.useCallback(()=>{const t=String(e.resourcePath||"").trim();if(t.startsWith("/FILES"))return t;if(s){const l=pt(s);if(l?.path)return Ot(l.path)}if(t)return Ot(t)},[e.resourcePath,s,pt]),$e=c.useCallback(async()=>{if(!s||d||Q)return null;const t=kt.current[s];if(t)return t;const l=Je.current[s];if(l)return l;const N=ce.get(`/api/v1/pdf/markdown/${s}`,{responseType:"text",transformResponse:[w=>w]}).then(w=>{const T=typeof w.data=="string"?w.data:String(w.data||"");return T?(kt.current[s]=T,T):null}).finally(()=>{delete Je.current[s]});return Je.current[s]=N,N},[s,Q,d]),Mt=c.useCallback(async(t,l)=>{if(!(!s||d||Q))try{const N=await $e(),w=xr(N||"",l);Xe(t,{markdownExcerpt:w||void 0,excerptStatus:w?"ready":"error"})}catch{Xe(t,{excerptStatus:"error"})}},[s,Q,d,$e,Xe]);c.useEffect(()=>{!s||d||Q||$e().catch(()=>{})},[s,Q,d,$e]);const jn=c.useCallback((t,l)=>{const N=String(t?.text||"").trim();if(!N)return;const w=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`pdf-ref-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,T=l.boundingRect?[{left:l.boundingRect.x1,top:l.boundingRect.y1,width:l.boundingRect.width,height:l.boundingRect.height,pageNumber:l.boundingRect.pageNumber}]:[];bt({id:w,kind:"pdf_text",tabId:o,fileId:s||void 0,resourceId:s||void 0,resourcePath:Tt(),resourceName:p,pageNumber:l.pageNumber,selectedText:N,markdownExcerpt:void 0,excerptStatus:s&&!d&&!Q?"loading":"idle",rects:l.rects?.map(O=>({left:O.x1,top:O.y1,width:O.width,height:O.height,pageNumber:O.pageNumber}))||T,createdAt:new Date().toISOString()}),window.dispatchEvent(new CustomEvent("ds:copilot:focus",{detail:{focus:!0}})),s&&!d&&!Q&&Mt(w,N)},[bt,Mt,s,p,Q,d,Tt,o]);c.useEffect(()=>{tt&&Pe(o,Lt.NOTEBOOK,{...e,resourceId:s,resourceName:p,mimeType:e.mimeType??"text/markdown",customData:{...e.customData||{},docKind:"markdown"}})},[e,s,p,tt,o,Pe]),c.useEffect(()=>{i(p)},[p,i]),c.useEffect(()=>{r(!1)},[r]),c.useEffect(()=>{gt(o,{contentKind:"pdf",documentMode:"pdf",pageNumber:De,isReadOnly:u})},[De,u,o,gt]),c.useEffect(()=>{const t=U||H;if(t){wt(t);return}!s||d||Yn(s).then(l=>{l?.project_id&&wt(String(l.project_id))}).catch(()=>{})},[s,A,d,U,H]),c.useEffect(()=>{if(!s||!d){G(null),X(!1),W(null);return}let t=!1,l=null;return X(!0),W(null),(async()=>{try{const{createFileObjectUrl:w}=await Ht(async()=>{const{createFileObjectUrl:T}=await import("./index-CBNVuWcP.js").then(O=>O.em);return{createFileObjectUrl:T}},__vite__mapDeps([0,1,2,3,4]));if(l=await w(s),t){URL.revokeObjectURL(l);return}G(l)}catch{t||W("Failed to load PDF from CLI server.")}finally{t||X(!1)}})(),()=>{t=!0,l&&URL.revokeObjectURL(l)}},[s,d]),c.useEffect(()=>{if(!s||!h||d){ge(null),ie(!1),Ne(null);return}let t=!1,l=null;return ie(!0),Ne(null),(async()=>{try{if(l=await no(s),t){URL.revokeObjectURL(l);return}ge(l)}catch{t||Ne("Failed to load PDF document.")}finally{t||ie(!1)}})(),()=>{t=!0,l&&URL.revokeObjectURL(l)}},[s,d,h]),c.useEffect(()=>{if(!fe)return;const t=He?.id;t&&eo(fe).then(l=>{const N=l.find(w=>w.user_id===t);N?.annotation_color&&pn(String(N.annotation_color))}).catch(()=>{})},[fe,He?.id]),c.useEffect(()=>{if(!fe||!s||d||u)return;const{socket:t,release:l}=io();Ct.current={socket:t,release:l};const N=async()=>{if(!we.current&&t.connected)try{we.current=!0,await t.emitWithAck("file:join",{projectId:fe,fileId:s,clientVersion:"1.0.0"})}catch{we.current=!1}},w=()=>void N(),T=()=>{we.current=!1},O=q=>{if(q?.fileId&&String(q.fileId)!==String(s))return;Re.invalidateQueries({queryKey:le.list(s)});const qe=typeof q?.annotationId=="string"&&q.annotationId.trim()?q.annotationId.trim():null;qe&&(Ee.current=qe,It.current||Et.current?.())};return t.on("connect",w),t.on("disconnect",T),t.on("annotation:created",O),t.on("annotation:updated",O),t.on("annotation:deleted",O),t.connected&&N(),()=>{try{t.off("connect",w),t.off("disconnect",T),t.off("annotation:created",O),t.off("annotation:updated",O),t.off("annotation:deleted",O),we.current&&t.emit("file:leave",{projectId:fe,fileId:s})}finally{we.current=!1,Ct.current=null,l()}}},[fe,s,d,u]);const re=c.useMemo(()=>u?y:Le.map(t=>({id:t.id,position:t.position,content:t.content,comment:{text:t.comment||"",emoji:t.kind},color:t.color,author:t.author??null,tags:t.tags,previewSummary:typeof t.content?.summary=="string"&&String(t.content.summary||"").trim()||null})),[Le,u,y]),Sn=c.useMemo(()=>[...re,...jt],[re,jt]);c.useEffect(()=>{const t=Ee.current;if(!t)return;const l=re.find(N=>N.id===t);l&&(oe(l.id),ue(l.position.pageNumber),et.current(l),Ee.current=null,St(l.id),Ce.current&&clearTimeout(Ce.current),Ce.current=setTimeout(()=>St(null),2200))},[re,oe,ue]),c.useEffect(()=>{const t=ve.current;return()=>{t?.setPinnedTipForHighlight(null),Ce.current&&clearTimeout(Ce.current)}},[]),c.useEffect(()=>{if(!u){a.current=!1;return}a.current||re.length!==0&&(a.current=!0,B||V())},[re.length,u,B,V]);const Ae=c.useCallback(t=>{ue(t),ve.current?.scrollToPage(t)},[ue]),Dt=c.useCallback(t=>{const l=`ai-ghost-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,N=t.rects.map(ee=>({...ee,width:ee.width??100,height:ee.height??100,pageNumber:ee.pageNumber??t.page})),w={...t.boundingRect,width:t.boundingRect.width??100,height:t.boundingRect.height??100,pageNumber:t.boundingRect.pageNumber??t.page},T={id:l,position:{boundingRect:w,rects:N,pageNumber:t.page},content:{text:t.text||""},comment:{text:"",emoji:"note"},color:t.color||"#3F5A6B",__dsGhost:!0,__dsGhostOpacity:1,__dsGhostMode:t.mode||"guide"};Ye(ee=>[...ee,T]);const O=t.durationMs??3e3,q=setTimeout(()=>{Ye(ee=>ee.map(Te=>Te.id===l?{...Te,__dsGhostOpacity:0}:Te))},O),qe=setTimeout(()=>{Ye(ee=>ee.filter(Te=>Te.id!==l)),Ie.current.delete(l),Ie.current.delete(`${l}:fade`)},O+800);Ie.current.set(l,qe),Ie.current.set(`${l}:fade`,q)},[]);c.useEffect(()=>{const t=Ie.current;return()=>{t.forEach(l=>clearTimeout(l)),t.clear()}},[]);const Be=c.useCallback(t=>{const l=typeof t?.__dsEffectId=="string"?t.__dsEffectId:null;return l?co(l)?!0:(lo(l),!1):!1},[]),Ue=c.useCallback(t=>{!t||t.fileId!==s||Be(t)||(Re.invalidateQueries({queryKey:le.list(s)}),t.page&&Ae(t.page),t.rects&&t.boundingRect&&Dt({page:t.page||1,rects:t.rects,boundingRect:t.boundingRect,color:t.color,mode:t.mode||"guide",durationMs:t.durationMs,text:t.text}),t.annotationId&&(Ee.current=t.annotationId),(t.annotationId||t.__dsEffectId)&&!B&&V())},[Dt,s,Re,Ae,B,V,Be]),Ve=c.useCallback(t=>{!t||t.fileId!==s||Be(t)||(Re.invalidateQueries({queryKey:le.list(s)}),t.page&&Ae(t.page),t.annotationId&&(Ee.current=t.annotationId,B||V()))},[s,Re,Ae,B,V,Be]),Qe=c.useCallback(()=>{if(!s)return;const t=uo(s);t.length!==0&&t.forEach(l=>{l.name==="pdf:jump"?Ue(l.data):Ve(l.data)})},[Ve,Ue,s]);c.useEffect(()=>{s&&Qe()},[s,Qe]),c.useEffect(()=>{if(typeof window>"u"||!s)return;const t=w=>{const T=w.detail;Ue(T)},l=w=>{const T=w.detail;Ve(T)},N=w=>{const T=w.detail;!T||T.fileId!==s||Qe()};return window.addEventListener("pdf:navigate",t),window.addEventListener("pdf:annotation_created",l),window.addEventListener("ds:pdf:queue",N),()=>{window.removeEventListener("pdf:navigate",t),window.removeEventListener("pdf:annotation_created",l),window.removeEventListener("ds:pdf:queue",N)}},[Ve,Ue,s,Qe]);const Rn=c.useCallback(async t=>{if(!(u||d||!s))try{const l=Me(t.comment?.emoji);(await yt({fileId:s,position:t.position,content:t.content,comment:t.comment?.text||"",kind:l,tags:[]}))?.id&&!B&&V()}catch(l){console.warn("[PdfViewerPlugin] Failed to create annotation:",l)}},[yt,s,d,u,B,V]),In=c.useCallback(async(t,l,N)=>{if(!(u||d||!s))try{const w=Le.find(q=>q.id===t);if(!w)return;const T={...w.position,...l,boundingRect:{...w.position.boundingRect,...l.boundingRect}},O={...w.content,...N};await xe(t,{position:T,content:O})}catch(w){console.warn("[PdfViewerPlugin] Failed to update annotation position/content:",w)}},[Le,s,d,u,xe]),Pt=c.useCallback((t,l)=>{const N=re.find(q=>q.id===t);if(!N)return;const w=l?.allowToggleClose!==!1,T=l?.skipAutoScroll===!0;if(w&&ae===t){oe(null),ve.current?.setPinnedTipForHighlight(null);return}B||V(),oe(t),ve.current?.setPinnedTipForHighlight(null),T||(ue(N.position.pageNumber),et.current(N))},[re,ae,B,oe,ue,V]),En=c.useCallback(t=>{const l=t.target;l&&(l.closest("[data-ds-highlight-target='true']")||l.closest("[data-ds-overlay-hint='true']")||ae&&(oe(null),ve.current?.setPinnedTipForHighlight(null)))},[ae,oe]),Cn=c.useCallback(async t=>{if(!(u||d||!s))try{await vt(t),ae===t&&oe(null)}catch(l){console.warn("[PdfViewerPlugin] Failed to delete annotation:",l)}},[vt,s,d,u,ae,oe]),An=c.useCallback(async(t,l)=>{if(!(u||d||!s))try{await xe(t,{kind:l})}catch(N){console.warn("[PdfViewerPlugin] Failed to update annotation kind:",N)}},[s,d,u,xe]),Tn=c.useCallback(async(t,l)=>{if(!(u||d||!s))try{await xe(t,{comment:l})}catch(N){console.warn("[PdfViewerPlugin] Failed to update annotation comment:",N)}},[s,d,u,xe]),Mn=c.useCallback(()=>{if(!s){window.open(de,"_blank");return}(async()=>{const{downloadFileById:t}=await Ht(async()=>{const{downloadFileById:l}=await import("./index-CBNVuWcP.js").then(N=>N.em);return{downloadFileById:l}},__vite__mapDeps([0,1,2,3,4]));await t(s,p)})()},[s,p,de]),Dn=c.useCallback(()=>{if(Fe){Fe();return}!s||d||Pe(o,Lt.PDF_MARKDOWN,{...e,customData:{...e.customData||{},pdfView:Q?"summary":"markdown"}})},[e,s,Q,d,Fe,o,Pe]);return tt?n.jsx("div",{className:"flex h-full items-center justify-center bg-muted/20",children:n.jsx("div",{className:"text-sm text-muted-foreground",children:"Switching to Markdown editor..."})}):d&&(se||Z)&&!F?n.jsx("div",{className:"h-full flex items-center justify-center bg-background",children:Z?n.jsx("div",{className:"text-sm text-muted-foreground",children:Z}):n.jsx(st,{})}):h&&(be||ke)&&!J?n.jsx("div",{className:"h-full flex items-center justify-center bg-background",children:ke?n.jsx("div",{className:"text-sm text-muted-foreground",children:ke}):n.jsx(st,{})}):n.jsxs("div",{className:"h-full flex flex-col bg-background",children:[n.jsx(Io,{scale:Se,onScaleChange:Y,currentPage:De,totalPages:sn,onPageChange:Ae,sidebarVisible:B,onSidebarToggle:V,onDownload:Mn,onInfo:$?()=>_t(!0):void 0,onMarkdownToggle:Fe||vn?Dn:void 0,markdownLabel:wn,markdownTitle:_n,reviewOpinionActive:cn,onReviewOpinionToggle:an&&ht?ht:void 0,reviewOpinionLabel:ln,reviewOpinionTitle:dn}),n.jsxs("div",{className:"flex-1 flex overflow-hidden bg-muted/10",children:[n.jsx("div",{className:"flex-1 overflow-hidden flex",children:n.jsx("div",{className:"relative h-full w-full",children:n.jsx("div",{className:"relative h-full overflow-hidden border border-border bg-background shadow-soft-card",onPointerDown:En,children:n.jsx(po,{url:de,httpHeaders:je,workerSrc:ho,cMapUrl:bo,cMapPacked:go,beforeLoad:n.jsx(st,{}),children:t=>n.jsx(wr,{pdfDocument:t,scale:Se,highlights:Sn,selectedId:ae,onSelect:Pt,onAdd:Rn,onUpdate:In,onScrollRef:l=>{et.current=l},onPageChange:l=>ue(l),pdfHighlighterRef:ve,authorColor:mn,authorHandle:(He?.email?He.email.split("@",1)[0]:"")||"user",showOverlayHints:Nt,tipPlacementMode:j?"right":"auto",readOnly:u,onAskCopilot:jn})})})})}),B&&n.jsxs("div",{className:M("relative border-l bg-background/60 backdrop-blur flex-shrink-0",j?"":"w-72"),style:j?{width:ye}:void 0,children:[j?n.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":m("resize_annotation_sidebar"),tabIndex:0,className:"group absolute inset-y-0 left-0 z-20 w-3 -translate-x-1/2 cursor-ew-resize touch-none",onPointerDown:xn,children:n.jsx("span",{className:"pointer-events-none absolute top-1/2 left-1/2 h-16 w-[2px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-black/20 opacity-0 transition-opacity group-hover:opacity-100"})}):null,n.jsx(vr,{highlights:re,selectedId:ae,currentPage:De,flashId:bn,onSelect:Pt,onDelete:Cn,onUpdateKind:An,onUpdateComment:Tn,showOverlayHints:Nt,readOnly:u})]})]}),n.jsx(to,{open:gn,onClose:()=>_t(!1),paper:$,errorCode:yn,onCopyBibtex:$?kn:void 0,onOpenArxiv:$?Nn:void 0})]})}function Pr(){console.debug("[PdfViewerPlugin] Activated")}function Fr(){console.debug("[PdfViewerPlugin] Deactivated")}export{Dr as default,Pr as onPdfViewerActivate,Fr as onPdfViewerDeactivate};
@@ -1,4 +1,4 @@
1
- import{y as le,u as Ue,f as M,m as ce,ao as Ke,ad as Ge,ap as We,aq as Xe,ar as Je,as as Ye,s as we,at as Ce,au as Le,av as Qe,aw as Ze,j as s,k as Ee,X as es,b as ss,ax as ts}from"./index-Gbl53BNp.js";import{r as n}from"./plugin-monaco-C8UgLomw.js";import"./plugin-notebook-HbW2K-1c.js";import"./plugin-terminal-MXFIPun8.js";/**
1
+ import{y as le,u as Ue,f as M,m as ce,ao as Ke,ad as Ge,ap as We,aq as Xe,ar as Je,as as Ye,s as we,at as Ce,au as Le,av as Qe,aw as Ze,j as s,k as Ee,X as es,b as ss,ax as ts}from"./index-CBNVuWcP.js";import{r as n}from"./plugin-monaco-C8UgLomw.js";import"./plugin-notebook-HbW2K-1c.js";import"./plugin-terminal-MXFIPun8.js";/**
2
2
  * @license lucide-react v0.511.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Gbl53BNp.js","assets/plugin-monaco-C8UgLomw.js","assets/plugin-terminal-MXFIPun8.js","assets/plugin-notebook-HbW2K-1c.js","assets/index-Cgla8biy.css"])))=>i.map(i=>d[i]);
2
- import{c as te,j as e,L as se,T as R,h as re,k as z,b,d as ne,e as oe,l as ae,X as H,_ as ie}from"./index-Gbl53BNp.js";import{r}from"./plugin-monaco-C8UgLomw.js";import{c as le}from"./file-jump-queue-DA-SdG__.js";import{H as ce,W as de}from"./wrap-text-CwMn-iqb.js";import{C as ue}from"./chevron-up-Dq5ofbht.js";import"./plugin-notebook-HbW2K-1c.js";import"./plugin-terminal-MXFIPun8.js";const he=1024*1024,k=1e4;function ve({context:l,tabId:y,setDirty:v,setTitle:N}){const[h,u]=r.useState(""),[d,C]=r.useState(!0),[O,P]=r.useState(null),[Q,A]=r.useState(!1),[L,q]=r.useState(!0),[S,J]=r.useState(!0),[p,B]=r.useState(0),[X,I]=r.useState(!1),[m,E]=r.useState(!1),[f,F]=r.useState(""),[g,T]=r.useState(0),[o,V]=r.useState([]),[D,K]=r.useState(null),w=r.useRef(null),x=l.resourceId,M=l.resourceName||l.resourcePath||"Untitled";r.useEffect(()=>{N(M)},[M,N]),r.useEffect(()=>{(async()=>{C(!0),P(null),I(!1);try{if(!l.resourceId){u(G),B(G.length),C(!1);return}const{getFileContent:t}=await ie(async()=>{const{getFileContent:a}=await import("./index-Gbl53BNp.js").then(i=>i.el);return{getFileContent:a}},__vite__mapDeps([0,1,2,3,4])),n=await t(l.resourceId);u(n),B(n.length),n.length>he&&I(!0)}catch(t){P(t instanceof Error?t.message:"Failed to load file")}finally{C(!1)}})()},[l.resourceId]);const c=r.useMemo(()=>h.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CBNVuWcP.js","assets/plugin-monaco-C8UgLomw.js","assets/plugin-terminal-MXFIPun8.js","assets/plugin-notebook-HbW2K-1c.js","assets/index-BpV6lusQ.css"])))=>i.map(i=>d[i]);
2
+ import{c as te,j as e,L as se,T as R,h as re,k as z,b,d as ne,e as oe,l as ae,X as H,_ as ie}from"./index-CBNVuWcP.js";import{r}from"./plugin-monaco-C8UgLomw.js";import{c as le}from"./file-jump-queue-DA-SdG__.js";import{H as ce,W as de}from"./wrap-text-BC-Hltpd.js";import{C as ue}from"./chevron-up-C9Qpx4DE.js";import"./plugin-notebook-HbW2K-1c.js";import"./plugin-terminal-MXFIPun8.js";const he=1024*1024,k=1e4;function ve({context:l,tabId:y,setDirty:v,setTitle:N}){const[h,u]=r.useState(""),[d,C]=r.useState(!0),[O,P]=r.useState(null),[Q,A]=r.useState(!1),[L,q]=r.useState(!0),[S,J]=r.useState(!0),[p,B]=r.useState(0),[X,I]=r.useState(!1),[m,E]=r.useState(!1),[f,F]=r.useState(""),[g,T]=r.useState(0),[o,V]=r.useState([]),[D,K]=r.useState(null),w=r.useRef(null),x=l.resourceId,M=l.resourceName||l.resourcePath||"Untitled";r.useEffect(()=>{N(M)},[M,N]),r.useEffect(()=>{(async()=>{C(!0),P(null),I(!1);try{if(!l.resourceId){u(G),B(G.length),C(!1);return}const{getFileContent:t}=await ie(async()=>{const{getFileContent:a}=await import("./index-CBNVuWcP.js").then(i=>i.em);return{getFileContent:a}},__vite__mapDeps([0,1,2,3,4])),n=await t(l.resourceId);u(n),B(n.length),n.length>he&&I(!0)}catch(t){P(t instanceof Error?t.message:"Failed to load file")}finally{C(!1)}})()},[l.resourceId]);const c=r.useMemo(()=>h.split(`
3
3
  `),[h]),W=r.useMemo(()=>c.length>k?c.slice(0,k):c,[c]),Y=c.length>k,_=r.useCallback(s=>{if(!x||s.fileId!==x)return;const t=s.lineStart??s.line??s.lineEnd;if(!t)return;const n=s.lineEnd??s.line??s.lineStart??t,a=Math.max(1,c.length),i=Math.min(Math.max(t,1),a),ee=Math.min(Math.max(n,i),a);K({start:i,end:ee});const $=document.getElementById(`line-${i-1}`);$&&$.scrollIntoView({behavior:"smooth",block:"center"}),w.current&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>{K(null)},2500)},[x,c.length]);r.useEffect(()=>{if(!x)return;const s=()=>{le(x).forEach(i=>_(i.data))};s();const t=a=>{const i=a.detail;_(i)},n=a=>{const i=a.detail;!i||i.fileId!==x||s()};return window.addEventListener("ds:file:jump",t),window.addEventListener("ds:file:queue",n),()=>{window.removeEventListener("ds:file:jump",t),window.removeEventListener("ds:file:queue",n),w.current&&(window.clearTimeout(w.current),w.current=null)}},[_,x]),r.useEffect(()=>{if(!f.trim()){V([]),T(0);return}const s=f.toLowerCase(),t=[];c.forEach((n,a)=>{n.toLowerCase().includes(s)&&t.push(a)}),V(t),T(0)},[f,c]);const j=r.useCallback(s=>{if(o.length===0)return;let t=g;s==="next"?t=(g+1)%o.length:t=(g-1+o.length)%o.length,T(t);const n=document.getElementById(`line-${o[t]}`);n&&n.scrollIntoView({behavior:"smooth",block:"center"})},[g,o]),Z=r.useCallback(async()=>{await te(h)&&(A(!0),setTimeout(()=>A(!1),2e3))},[h]),U=r.useMemo(()=>p<1024?`${p} B`:p<1024*1024?`${(p/1024).toFixed(1)} KB`:`${(p/(1024*1024)).toFixed(1)} MB`,[p]);return r.useEffect(()=>{const s=t=>{(t.ctrlKey||t.metaKey)&&t.key==="f"&&(t.preventDefault(),E(!0)),t.key==="Escape"&&m&&(E(!1),F("")),m&&(t.key==="F3"||t.key==="Enter"&&!t.shiftKey)&&(t.preventDefault(),j("next")),m&&(t.key==="F3"&&t.shiftKey||t.key==="Enter"&&t.shiftKey)&&(t.preventDefault(),j("prev"))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[m,j]),d?e.jsx("div",{className:"flex items-center justify-center h-full bg-background",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 text-muted-foreground",children:[e.jsx(se,{className:"w-8 h-8 animate-spin"}),e.jsx("span",{children:"Loading file..."})]})}):O?e.jsx("div",{className:"flex items-center justify-center h-full bg-background",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 text-destructive",children:[e.jsx(R,{className:"w-8 h-8"}),e.jsx("span",{children:O}),e.jsx("button",{className:"px-4 py-2 text-sm bg-destructive/10 hover:bg-destructive/20 rounded-lg transition-colors",onClick:()=>window.location.reload(),children:"Retry"})]})}):e.jsxs("div",{className:"flex flex-col h-full bg-background text-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-foreground",children:M}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[c.length," ",c.length===1?"line":"lines"," | ",U]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>E(!m),className:b("p-2 rounded hover:bg-accent transition-colors",m?"text-primary bg-accent":"text-muted-foreground"),title:"Search (Ctrl+F)",children:e.jsx(z,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>q(!L),className:b("p-2 rounded hover:bg-accent transition-colors",L?"text-primary":"text-muted-foreground"),title:"Toggle line numbers",children:e.jsx(ce,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>J(!S),className:b("p-2 rounded hover:bg-accent transition-colors",S?"text-primary":"text-muted-foreground"),title:"Toggle word wrap",children:e.jsx(de,{className:"w-4 h-4"})}),e.jsx("button",{onClick:Z,className:"p-2 rounded hover:bg-accent transition-colors text-muted-foreground hover:text-foreground",title:"Copy to clipboard",children:Q?e.jsx(ne,{className:"w-4 h-4 text-green-500"}):e.jsx(oe,{className:"w-4 h-4"})})]})]}),m&&e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/20",children:[e.jsx(z,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("input",{type:"text",value:f,onChange:s=>F(s.target.value),placeholder:"Search...",className:"flex-1 bg-transparent border-none outline-none text-sm placeholder:text-muted-foreground",autoFocus:!0}),o.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:[g+1," of ",o.length]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:()=>j("prev"),disabled:o.length===0,className:"p-1 rounded hover:bg-accent disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsx(ue,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>j("next"),disabled:o.length===0,className:"p-1 rounded hover:bg-accent disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsx(ae,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>{E(!1),F("")},className:"p-1 rounded hover:bg-accent",children:e.jsx(H,{className:"w-4 h-4"})})]})]}),X&&e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-yellow-500/10 border-b border-yellow-500/30 text-yellow-600 dark:text-yellow-400",children:[e.jsx(R,{className:"w-4 h-4 flex-shrink-0"}),e.jsxs("span",{className:"text-sm",children:["Large file (",U,"). Performance may be affected."]}),e.jsx("button",{onClick:()=>I(!1),className:"ml-auto p-1 hover:bg-yellow-500/20 rounded",children:e.jsx(H,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"flex min-h-full",children:[L&&e.jsx("div",{className:"flex-shrink-0 py-4 pr-4 text-right bg-muted/20 border-r border-border select-none sticky left-0",children:W.map((s,t)=>e.jsx("div",{id:`line-num-${t}`,className:b("px-4 text-xs leading-6 font-mono",o.includes(t)&&o[g]===t?"text-primary font-bold":o.includes(t)?"text-primary/60":"text-muted-foreground"),children:t+1},t))}),e.jsxs("pre",{className:b("flex-1 py-4 px-4 font-mono text-sm leading-6 overflow-x-auto",S&&"whitespace-pre-wrap break-all"),children:[W.map((s,t)=>{const n=o.length>0&&o[g]===t,a=f.trim()&&s.toLowerCase().includes(f.toLowerCase()),i=D&&t+1>=D.start&&t+1<=D.end;return e.jsx("div",{id:`line-${t}`,className:b("min-h-[1.5rem]",i&&"ds-citation-line-highlight",n&&"bg-primary/20",a&&!n&&"bg-primary/10"),children:a?me(s,f):s||" "},t)}),Y&&e.jsxs("div",{className:"py-4 text-center text-muted-foreground border-t border-border mt-4",children:[e.jsx(R,{className:"w-4 h-4 inline-block mr-2"}),"File truncated. Showing first ",k.toLocaleString()," ","of ",c.length.toLocaleString()," lines."]})]})]})})]})}function me(l,y){if(!y.trim())return l;const v=[],N=l.toLowerCase(),h=y.toLowerCase();let u=0,d=N.indexOf(h);for(;d!==-1;)d>u&&v.push(l.slice(u,d)),v.push(e.jsx("mark",{className:"bg-yellow-300 dark:bg-yellow-500/50 text-foreground px-0.5 rounded",children:l.slice(d,d+y.length)},d)),u=d+y.length,d=N.indexOf(h,u);return u<l.length&&v.push(l.slice(u)),v}const G=`DeepScientist - Text Viewer Demo
4
4
  ================================
5
5