UNPKG

@llamaindex/ui

Version:

A comprehensive UI component library built with React, TypeScript, and Tailwind CSS for LlamaIndex applications

223 lines (219 loc) 7.32 kB
'use strict'; var chunkNYOFAHGT_js = require('./chunk-NYOFAHGT.js'); var chunk64FRNQ3S_js = require('./chunk-64FRNQ3S.js'); var jsxRuntime = require('react/jsx-runtime'); var react = require('react'); var lucideReact = require('lucide-react'); function BoundingBoxOverlay({ boundingBoxes, zoom, containerWidth, containerHeight, onBoundingBoxClick }) { if (containerWidth === 0 || containerHeight === 0) { return null; } return /* @__PURE__ */ jsxRuntime.jsx( "svg", { style: { position: "absolute", top: 0, left: 0, width: containerWidth * zoom, height: containerHeight * zoom, pointerEvents: "none" }, viewBox: `0 0 ${containerWidth} ${containerHeight}`, children: boundingBoxes.map((box) => /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [ /* @__PURE__ */ jsxRuntime.jsx( "rect", { x: box.x, y: box.y, width: box.width, height: box.height, fill: box.color || "rgba(255, 0, 0, 0.2)", stroke: box.color || "red", strokeWidth: 2 / zoom, style: { pointerEvents: "auto", cursor: onBoundingBoxClick ? "pointer" : "default" }, onClick: () => onBoundingBoxClick == null ? void 0 : onBoundingBoxClick(box) } ), box.label && /* @__PURE__ */ jsxRuntime.jsx( "text", { x: box.x, y: box.y - 5, fill: box.color || "red", fontSize: 12 / zoom, fontWeight: "bold", children: box.label } ) ] }, box.id)) } ); } var PdfNavigator = ({ currentPage, totalPages, scale, onPageChange, onScaleChange, onDownload, onReset }) => { const [pageInput, setPageInput] = react.useState(currentPage.toString()); const [isEditing, setIsEditing] = react.useState(false); react.useEffect(() => { if (!isEditing) { setPageInput(currentPage.toString()); } }, [currentPage, isEditing]); const handlePageInputChange = (value) => { setPageInput(value); setIsEditing(true); }; const handlePageInputSubmit = () => { const pageNumber = parseInt(pageInput); if (pageNumber >= 1 && pageNumber <= totalPages) { onPageChange(pageNumber); } else { setPageInput(currentPage.toString()); } setIsEditing(false); }; const handlePageInputKeyDown = (e) => { if (e.key === "Enter") { handlePageInputSubmit(); } }; const handlePageInputFocus = () => { setIsEditing(true); }; const handlePrevPage = () => { if (currentPage > 1) { onPageChange(currentPage - 1); } }; const handleNextPage = () => { if (currentPage < totalPages) { onPageChange(currentPage + 1); } }; const handleZoomIn = () => { onScaleChange(Math.min(scale + 0.25, 3)); }; const handleZoomOut = () => { onScaleChange(Math.max(scale - 0.25, 0.5)); }; const handleReset = () => { onScaleChange(1); onReset == null ? void 0 : onReset(); }; return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute bottom-6 left-1/2 transform -translate-x-1/2 z-50", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white/95 backdrop-blur-sm border rounded-lg shadow-lg px-4 py-2 flex items-center gap-3", children: [ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [ /* @__PURE__ */ jsxRuntime.jsx( chunk64FRNQ3S_js.Button, { variant: "ghost", size: "sm", onClick: handlePrevPage, disabled: currentPage <= 1, className: "h-8 w-8 p-0", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "h-4 w-4" }) } ), /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-1", children: [ /* @__PURE__ */ jsxRuntime.jsx( chunkNYOFAHGT_js.Input, { type: "number", value: pageInput, onChange: (e) => handlePageInputChange(e.target.value), onFocus: handlePageInputFocus, onBlur: handlePageInputSubmit, onKeyDown: handlePageInputKeyDown, className: "h-7 w-7 px-1 text-center text-sm rounded-sm [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-inner-spin-button]:m-0 [&::-webkit-outer-spin-button]:m-0 [-moz-appearance:textfield]", min: 1, max: totalPages } ), /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-muted-foreground", children: "/" }), /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex items-center text-sm text-muted-foreground h-7", children: totalPages }) ] }), /* @__PURE__ */ jsxRuntime.jsx( chunk64FRNQ3S_js.Button, { variant: "ghost", size: "sm", onClick: handleNextPage, disabled: currentPage >= totalPages, className: "h-8 w-8 p-0", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-4 w-4" }) } ) ] }), /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-px h-6 bg-border" }), /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [ /* @__PURE__ */ jsxRuntime.jsx( chunk64FRNQ3S_js.Button, { variant: "ghost", size: "sm", onClick: handleZoomOut, disabled: scale <= 0.5, className: "h-8 w-8 p-0", title: "Zoom Out", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ZoomOut, { className: "h-4 w-4" }) } ), /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-sm text-muted-foreground text-center", children: [ Math.round(scale * 100), "%" ] }), /* @__PURE__ */ jsxRuntime.jsx( chunk64FRNQ3S_js.Button, { variant: "ghost", size: "sm", onClick: handleZoomIn, disabled: scale >= 3, className: "h-8 w-8 p-0", title: "Zoom In", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ZoomIn, { className: "h-4 w-4" }) } ), /* @__PURE__ */ jsxRuntime.jsx( chunk64FRNQ3S_js.Button, { variant: "ghost", size: "sm", onClick: handleReset, className: "h-8 w-8 p-0", title: "Reset Zoom", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { className: "h-4 w-4" }) } ) ] }), onDownload && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-px h-6 bg-border" }), onDownload && /* @__PURE__ */ jsxRuntime.jsx( chunk64FRNQ3S_js.Button, { variant: "ghost", size: "sm", onClick: onDownload, className: "h-8 w-8 p-0", title: "Download PDF", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "h-4 w-4" }) } ) ] }) }); }; exports.BoundingBoxOverlay = BoundingBoxOverlay; exports.PdfNavigator = PdfNavigator;