@frontera-sdk/chat-ui 1.50.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +348 -0
- package/dist/af-DK_CjRn6-OPBHDTNZ.js +197 -0
- package/dist/agent-picker.d.ts +38 -0
- package/dist/agent-picker.js +8 -0
- package/dist/as-BPtSu6VN-O4ZZEAJG.js +11 -0
- package/dist/be-CrQ0smca-5HIE5K27.js +11 -0
- package/dist/bg-CrQqGwni-3IRVPZQ7.js +11 -0
- package/dist/bn-NCLZcWHi-XOZJFNIB.js +11 -0
- package/dist/ca-SUf6Y2Om-V6F2EBCA.js +38 -0
- package/dist/capture-NO5ZIGP6.js +1652 -0
- package/dist/chat.css +3555 -0
- package/dist/chat.d.ts +161 -0
- package/dist/chat.js +60498 -0
- package/dist/chunk-2KEBRV3W.js +191 -0
- package/dist/chunk-6BPHEBCF.js +639 -0
- package/dist/chunk-6HYPVNVA.js +25 -0
- package/dist/chunk-7ADM3CKD.js +10 -0
- package/dist/chunk-AFVU5VT6.js +5601 -0
- package/dist/chunk-BEJ3HQG4.js +93 -0
- package/dist/chunk-CCVPZVFK.js +28 -0
- package/dist/chunk-DGDHKMDB.js +10 -0
- package/dist/chunk-FXKXDR5K.js +2166 -0
- package/dist/chunk-GTQH7MPF.js +129 -0
- package/dist/chunk-I7SXWUAN.js +1258 -0
- package/dist/chunk-IQRPGFLI.js +234 -0
- package/dist/chunk-IXDM5R55.js +23 -0
- package/dist/chunk-JD6ETTXC.js +178 -0
- package/dist/chunk-OP4MLJDA.js +215 -0
- package/dist/chunk-PQZ2CS26.js +2315 -0
- package/dist/chunk-PR4QN5HX.js +38 -0
- package/dist/chunk-PUIVKDV5.js +271 -0
- package/dist/chunk-QSSFBZAS.js +6914 -0
- package/dist/chunk-RAKKA3WU.js +5896 -0
- package/dist/chunk-RB2Y4NYC.js +681 -0
- package/dist/chunk-VDZH5Z3K.js +72 -0
- package/dist/chunk-WMN6BPPS.js +49 -0
- package/dist/chunk-WO6DJLFE.js +10857 -0
- package/dist/chunk-X5E2DJVO.js +47634 -0
- package/dist/chunk-XJFTVKLW.js +2687 -0
- package/dist/chunk-ZS6PXIZP.js +187 -0
- package/dist/client.d.ts +89 -0
- package/dist/client.js +20 -0
- package/dist/composer.d.ts +23 -0
- package/dist/composer.js +89 -0
- package/dist/cop-C3sk0IUo-CIZA2H43.js +11 -0
- package/dist/credential.d.ts +75 -0
- package/dist/credential.js +3 -0
- package/dist/cs-CmAteokq-HAKEQPB4.js +17 -0
- package/dist/cu-CBUlrW6Y-QTZ6ZLA4.js +32 -0
- package/dist/cy-BBPa6z2x-MX6DGDNW.js +11 -0
- package/dist/da-CCDXfXtG-5YEOHMG3.js +11 -0
- package/dist/de-1901-CWoAOigE-63QFSF2A.js +11 -0
- package/dist/de-1996-BL6awyxG-R2PHKMAB.js +11 -0
- package/dist/de-ch-1901-hVThVHVb-JSDB53OZ.js +11 -0
- package/dist/el-monoton-D3aKqTz2-2V4OOFBB.js +11 -0
- package/dist/el-polyton-ogVWcTzh-3U7NGQMT.js +11 -0
- package/dist/en-gb-B7Al27b_-UKCBQFSU.js +21 -0
- package/dist/es-DcaaHPU_-NOBXSOZK.js +11 -0
- package/dist/esm-MHF25KDL.js +3 -0
- package/dist/et-B_spaleu-5UAYIW62.js +11 -0
- package/dist/eu-Ctv_kq9Z-V5DREOPN.js +11 -0
- package/dist/fi-RW5VB8Yp-YSXBK7LW.js +11 -0
- package/dist/fr-BC2onEz9-7KH5T76G.js +11 -0
- package/dist/frame.d.ts +59 -0
- package/dist/frame.js +111 -0
- package/dist/fur-AC12wySk-4PD2Y72H.js +11 -0
- package/dist/ga-Cn6LkudM-RRAAJT3N.js +58 -0
- package/dist/gl-DZGc-K_G-KYSXXTCY.js +11 -0
- package/dist/grc-DOlGgO8T-2HXBZVJ5.js +11 -0
- package/dist/gu-Bjl0l-cf-4CFSVZHZ.js +11 -0
- package/dist/header.d.ts +78 -0
- package/dist/header.js +18 -0
- package/dist/hi-DsAaTPCC-KMCFBWK7.js +11 -0
- package/dist/hr-DT1SBBes-X2TIX6EI.js +11 -0
- package/dist/hsb-DC_ITc1e-PXLERA7R.js +46 -0
- package/dist/hu-DVk7Y_ka-PJPVU54B.js +11 -0
- package/dist/hy-e995ysyO-MZBRFX52.js +11 -0
- package/dist/ia-Cr4TJH0c-D3O2FHGP.js +22 -0
- package/dist/id-DifDyWg9-MZ2BGHWI.js +58 -0
- package/dist/is-BT8UVRze-CZZCKEFI.js +11 -0
- package/dist/it-Bt_Meacx-T4Y5JYV6.js +11 -0
- package/dist/ka-jyoLzyDE-ES6EXZLW.js +11 -0
- package/dist/kmr-Cfwhwuff-TSW2R2KS.js +11 -0
- package/dist/kn-C6Lov-DP-B4BL47CE.js +11 -0
- package/dist/la-DuvHjUWw-6K7TFU6X.js +11 -0
- package/dist/la-x-classic-yTyAOQEt-YWTKMM2L.js +11 -0
- package/dist/la-x-liturgic-CXeQb4FY-B772L5E7.js +11 -0
- package/dist/lib-3ZKX25RJ.js +4511 -0
- package/dist/lt-BBe8DlDF-4YINVOZR.js +11 -0
- package/dist/lv-Q2BBHnzp-TMVQ3MX2.js +11 -0
- package/dist/message.d.ts +64 -0
- package/dist/message.js +18 -0
- package/dist/ml-2xLVYkVY-NGZLAPIN.js +11 -0
- package/dist/mn-cyrl-lHM4n0oC-DGBYYUT3.js +11 -0
- package/dist/mn-cyrl-x-lmc-3aetruI8-QHJABMOO.js +11 -0
- package/dist/mr-CjWJPVmH-X5UHV65O.js +11 -0
- package/dist/mul-ethi-D_CMSMEq-H7UMQSOQ.js +11 -0
- package/dist/nb-DI8u59ch-J4CAVI4Y.js +122 -0
- package/dist/new-session-Dw7JOgzu.d.ts +141 -0
- package/dist/new-session.d.ts +4 -0
- package/dist/new-session.js +10 -0
- package/dist/nl-BHQJ6Gvn-7BH55RA7.js +52 -0
- package/dist/nn-ntZvarUK-KKNCHHJ4.js +122 -0
- package/dist/no-B8ItS0F3-3ZXIRJ6U.js +120 -0
- package/dist/oauth-callback.d.ts +35 -0
- package/dist/oauth-callback.js +18 -0
- package/dist/oc-P_i3-xLA-XZM6E5YZ.js +11 -0
- package/dist/or-50rxpoq4-5VELAFMJ.js +11 -0
- package/dist/pa-C54UG8eN-WEJPMZ6Z.js +11 -0
- package/dist/parts.d.ts +49 -0
- package/dist/parts.js +106 -0
- package/dist/pdf-cover-thumbnail-inner-4N2Q5AAG.js +36 -0
- package/dist/pdf-deck-view-inner-FZVLAEQR.js +575 -0
- package/dist/pdf-document-view-inner-6DF54JWK.js +585 -0
- package/dist/pdf-viewer-inner-GPES3KG2.js +256 -0
- package/dist/pending-cards.d.ts +26 -0
- package/dist/pending-cards.js +9 -0
- package/dist/pi-B9cgjyG1-GD5ASDDU.js +11 -0
- package/dist/pl-9fg-ESVt-UMX7MCJM.js +32 -0
- package/dist/platform.css +4013 -0
- package/dist/pms-BRGfm5gS-SSE3AUW5.js +11 -0
- package/dist/pt-Cum2_NUC-W35JYVR4.js +11 -0
- package/dist/rm-C0MIK9N4-IWL4YTNT.js +11 -0
- package/dist/ro-0fmdH0HA-46WUTOYH.js +11 -0
- package/dist/ru-v4l-ayaq-BUGK6XCN.js +196 -0
- package/dist/sa-CKY9c_Vq-4KIJOI5Y.js +11 -0
- package/dist/sh-cyrl-BpCRFOmq-DSLQ4UY2.js +128 -0
- package/dist/sh-latn-sRy4Tuaj-UNQOR63V.js +128 -0
- package/dist/sk-_iOeDNrQ-NCTQKH25.js +17 -0
- package/dist/sl-DpiklF-D-6GG5TDVN.js +11 -0
- package/dist/sr-cyrl-Dpzrbd0W-4Q5226YJ.js +142 -0
- package/dist/sv-CFm5y56M-VTWNPZ7I.js +11 -0
- package/dist/ta-BcghgTbD-NRT35DW6.js +11 -0
- package/dist/te-B5Spl2Jk-5VE6CLN4.js +11 -0
- package/dist/th-DWX5iPSo-N5GMOQOP.js +11 -0
- package/dist/theme.d.ts +49 -0
- package/dist/theme.js +3 -0
- package/dist/tk-BMbKB10q-HGWWY5L3.js +11 -0
- package/dist/tr-CIHIuzqc-6ISBNYLV.js +11 -0
- package/dist/types-BDqLaBfH.d.ts +60 -0
- package/dist/uk-Dir3oxLs-YQ3QZRI4.js +11 -0
- package/dist/univer-workbook-BSSUE5TG.css +3555 -0
- package/dist/univer-workbook-N5IIN7CH.js +290849 -0
- package/dist/vega-chart-block-NQADYNWQ.js +2857 -0
- package/dist/zh-latn-pinyin-BdYb-Ey_-RB542AHF.js +11 -0
- package/package.json +137 -0
- package/src/styles.css +996 -0
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { zoomPercent, DECK_ZOOM_LEVELS, ArtifactSkeleton, LazyThumb } from './chunk-PUIVKDV5.js';
|
|
3
|
+
import { useTranslation } from './chunk-QSSFBZAS.js';
|
|
4
|
+
import { Button, ScrollArea } from './chunk-GTQH7MPF.js';
|
|
5
|
+
import { useIsMobile } from './chunk-IXDM5R55.js';
|
|
6
|
+
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem } from './chunk-ZS6PXIZP.js';
|
|
7
|
+
import { cn } from './chunk-DGDHKMDB.js';
|
|
8
|
+
import { ChevronLeftIcon, ChevronRightIcon, ChevronDownMediumIcon } from './chunk-AFVU5VT6.js';
|
|
9
|
+
import './chunk-PR4QN5HX.js';
|
|
10
|
+
import { memo, useState, useRef, useEffect, useCallback, useLayoutEffect } from 'react';
|
|
11
|
+
import { Page, pdfjs, Document } from 'react-pdf';
|
|
12
|
+
import 'react-pdf/dist/Page/TextLayer.css';
|
|
13
|
+
import 'react-pdf/dist/Page/AnnotationLayer.css';
|
|
14
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
15
|
+
|
|
16
|
+
var NOOP = () => {
|
|
17
|
+
};
|
|
18
|
+
var PdfDocumentPage = memo(function PdfDocumentPage2({
|
|
19
|
+
pdfDocument,
|
|
20
|
+
pageIndex,
|
|
21
|
+
displayWidth,
|
|
22
|
+
renderWidth,
|
|
23
|
+
pageDimensions,
|
|
24
|
+
shouldRender,
|
|
25
|
+
devicePixelRatio
|
|
26
|
+
}) {
|
|
27
|
+
const displayHeight = Math.round(
|
|
28
|
+
displayWidth * pageDimensions.height / pageDimensions.width
|
|
29
|
+
);
|
|
30
|
+
const renderHeight = Math.round(
|
|
31
|
+
renderWidth * pageDimensions.height / pageDimensions.width
|
|
32
|
+
);
|
|
33
|
+
const displayScale = displayWidth / renderWidth;
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
"div",
|
|
36
|
+
{
|
|
37
|
+
"data-pdf-page-index": pageIndex,
|
|
38
|
+
"data-pdf-page-live": shouldRender,
|
|
39
|
+
className: "scroll-mt-4 overflow-hidden bg-surface-raised shadow-sm",
|
|
40
|
+
style: { width: displayWidth, height: displayHeight },
|
|
41
|
+
children: shouldRender ? /* @__PURE__ */ jsx(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
style: {
|
|
45
|
+
width: renderWidth,
|
|
46
|
+
height: renderHeight,
|
|
47
|
+
transform: `scale(${displayScale})`,
|
|
48
|
+
transformOrigin: "left top"
|
|
49
|
+
},
|
|
50
|
+
children: /* @__PURE__ */ jsx(
|
|
51
|
+
Page,
|
|
52
|
+
{
|
|
53
|
+
pdf: pdfDocument,
|
|
54
|
+
pageNumber: pageIndex + 1,
|
|
55
|
+
width: renderWidth,
|
|
56
|
+
devicePixelRatio,
|
|
57
|
+
renderAnnotationLayer: false,
|
|
58
|
+
onLoadError: NOOP,
|
|
59
|
+
onRenderError: NOOP,
|
|
60
|
+
error: /* @__PURE__ */ jsx(
|
|
61
|
+
"div",
|
|
62
|
+
{
|
|
63
|
+
"aria-hidden": true,
|
|
64
|
+
style: { width: renderWidth, height: renderHeight },
|
|
65
|
+
className: "bg-surface-raised"
|
|
66
|
+
}
|
|
67
|
+
),
|
|
68
|
+
loading: /* @__PURE__ */ jsx(
|
|
69
|
+
"div",
|
|
70
|
+
{
|
|
71
|
+
"aria-hidden": true,
|
|
72
|
+
style: { width: renderWidth, height: renderHeight },
|
|
73
|
+
className: "bg-surface-raised"
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
) : /* @__PURE__ */ jsx("div", { "aria-hidden": true, className: "size-full bg-surface-raised" })
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
PdfDocumentPage.displayName = "PdfDocumentPage";
|
|
84
|
+
pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
|
|
85
|
+
var PDF_PAGE_RENDER_RADIUS = 2;
|
|
86
|
+
var THUMB_W = 120;
|
|
87
|
+
var COMPACT_THUMB_W = 76;
|
|
88
|
+
var STRIP_THUMB_W = 112;
|
|
89
|
+
var COMPACT_PANEL_WIDTH = 700;
|
|
90
|
+
var RAIL_CLOSE_DELAY_MS = 60;
|
|
91
|
+
var MAX_RAIL_TICKS = 12;
|
|
92
|
+
function PdfDocumentViewInner({
|
|
93
|
+
fileUrl,
|
|
94
|
+
title,
|
|
95
|
+
label,
|
|
96
|
+
onError,
|
|
97
|
+
versionSlot
|
|
98
|
+
}) {
|
|
99
|
+
const { t } = useTranslation();
|
|
100
|
+
const isMobile = useIsMobile();
|
|
101
|
+
const [selectedPage, setSelectedPage] = useState(0);
|
|
102
|
+
const [zoom, setZoom] = useState("fit");
|
|
103
|
+
const [loadedDocument, setLoadedDocument] = useState(null);
|
|
104
|
+
const [hostElement, setHostElement] = useState(null);
|
|
105
|
+
const [hostWidth, setHostWidth] = useState(0);
|
|
106
|
+
const [compact, setCompact] = useState(false);
|
|
107
|
+
const [railOpen, setRailOpen] = useState(false);
|
|
108
|
+
const viewerRef = useRef(null);
|
|
109
|
+
const railRef = useRef(null);
|
|
110
|
+
const railCloseTimerRef = useRef(null);
|
|
111
|
+
const pointerInside = useRef(false);
|
|
112
|
+
const mountedRef = useRef(false);
|
|
113
|
+
const activeSourceRef = useRef(fileUrl);
|
|
114
|
+
activeSourceRef.current = fileUrl;
|
|
115
|
+
const activeDocument = loadedDocument?.source === fileUrl ? loadedDocument : null;
|
|
116
|
+
const pages = activeDocument?.proxy.numPages ?? 0;
|
|
117
|
+
const pageDimensions = activeDocument?.pageDimensions ?? null;
|
|
118
|
+
const [renderPixelRatio] = useState(
|
|
119
|
+
() => typeof window === "undefined" ? 1 : Math.min(
|
|
120
|
+
window.devicePixelRatio || 1,
|
|
121
|
+
typeof window.matchMedia === "function" && window.matchMedia("(max-width: 767px)").matches ? 1.5 : 2
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
mountedRef.current = true;
|
|
126
|
+
return () => {
|
|
127
|
+
mountedRef.current = false;
|
|
128
|
+
setLoadedDocument(null);
|
|
129
|
+
};
|
|
130
|
+
}, []);
|
|
131
|
+
const openRail = useCallback(() => {
|
|
132
|
+
if (railCloseTimerRef.current) {
|
|
133
|
+
clearTimeout(railCloseTimerRef.current);
|
|
134
|
+
railCloseTimerRef.current = null;
|
|
135
|
+
}
|
|
136
|
+
setRailOpen(true);
|
|
137
|
+
}, []);
|
|
138
|
+
const closeRail = useCallback(() => {
|
|
139
|
+
if (railCloseTimerRef.current) clearTimeout(railCloseTimerRef.current);
|
|
140
|
+
railCloseTimerRef.current = setTimeout(() => {
|
|
141
|
+
setRailOpen(false);
|
|
142
|
+
railCloseTimerRef.current = null;
|
|
143
|
+
}, RAIL_CLOSE_DELAY_MS);
|
|
144
|
+
}, []);
|
|
145
|
+
useEffect(
|
|
146
|
+
() => () => {
|
|
147
|
+
if (railCloseTimerRef.current) clearTimeout(railCloseTimerRef.current);
|
|
148
|
+
},
|
|
149
|
+
[]
|
|
150
|
+
);
|
|
151
|
+
useLayoutEffect(() => {
|
|
152
|
+
const viewer = viewerRef.current;
|
|
153
|
+
if (!viewer) return;
|
|
154
|
+
const compute = () => {
|
|
155
|
+
const nextCompact = viewer.clientWidth < COMPACT_PANEL_WIDTH;
|
|
156
|
+
setCompact(nextCompact);
|
|
157
|
+
if (!nextCompact) setRailOpen(false);
|
|
158
|
+
};
|
|
159
|
+
compute();
|
|
160
|
+
const observer = new ResizeObserver(compute);
|
|
161
|
+
observer.observe(viewer);
|
|
162
|
+
return () => observer.disconnect();
|
|
163
|
+
}, []);
|
|
164
|
+
useLayoutEffect(() => {
|
|
165
|
+
if (!hostElement) return;
|
|
166
|
+
const measure = () => {
|
|
167
|
+
const styles = getComputedStyle(hostElement);
|
|
168
|
+
const horizontalPadding = (parseFloat(styles.paddingLeft) || 0) + (parseFloat(styles.paddingRight) || 0);
|
|
169
|
+
setHostWidth(Math.max(0, hostElement.clientWidth - horizontalPadding));
|
|
170
|
+
};
|
|
171
|
+
measure();
|
|
172
|
+
const observer = new ResizeObserver(measure);
|
|
173
|
+
observer.observe(hostElement);
|
|
174
|
+
return () => observer.disconnect();
|
|
175
|
+
}, [hostElement]);
|
|
176
|
+
const goToPage = useCallback(
|
|
177
|
+
(pageIndex) => {
|
|
178
|
+
const nextPage = Math.min(Math.max(0, pageIndex), Math.max(0, pages - 1));
|
|
179
|
+
setSelectedPage(nextPage);
|
|
180
|
+
hostElement?.querySelector(`[data-pdf-page-index="${nextPage}"]`)?.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
181
|
+
},
|
|
182
|
+
[hostElement, pages]
|
|
183
|
+
);
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (!hostElement || pages === 0 || typeof IntersectionObserver === "undefined") {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const visiblePages = /* @__PURE__ */ new Map();
|
|
189
|
+
const observer = new IntersectionObserver(
|
|
190
|
+
(entries) => {
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
if (entry.isIntersecting) visiblePages.set(entry.target, entry.intersectionRatio);
|
|
193
|
+
else visiblePages.delete(entry.target);
|
|
194
|
+
}
|
|
195
|
+
let mostVisiblePage = 0;
|
|
196
|
+
let highestRatio = -1;
|
|
197
|
+
for (const [element, ratio] of visiblePages) {
|
|
198
|
+
if (ratio <= highestRatio) continue;
|
|
199
|
+
highestRatio = ratio;
|
|
200
|
+
mostVisiblePage = Number(
|
|
201
|
+
element.dataset.pdfPageIndex ?? 0
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if (highestRatio >= 0) setSelectedPage(mostVisiblePage);
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
root: hostElement,
|
|
208
|
+
threshold: [0.15, 0.35, 0.5, 0.75, 1]
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
const pageElements = hostElement.querySelectorAll("[data-pdf-page-index]");
|
|
212
|
+
pageElements.forEach((element) => observer.observe(element));
|
|
213
|
+
return () => observer.disconnect();
|
|
214
|
+
}, [hostElement, pageDimensions, pages]);
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
const handleKeyDown = (event) => {
|
|
217
|
+
if (!pointerInside.current) return;
|
|
218
|
+
const target = event.target;
|
|
219
|
+
if (target && (target.tagName === "TEXTAREA" || target.tagName === "INPUT" || target.isContentEditable)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (event.key === "PageDown" || event.key === "ArrowRight") {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
goToPage(selectedPage + 1);
|
|
225
|
+
} else if (event.key === "PageUp" || event.key === "ArrowLeft") {
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
goToPage(selectedPage - 1);
|
|
228
|
+
} else if (event.key === "Home") {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
goToPage(0);
|
|
231
|
+
} else if (event.key === "End") {
|
|
232
|
+
event.preventDefault();
|
|
233
|
+
goToPage(pages - 1);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
237
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
238
|
+
}, [goToPage, pages, selectedPage]);
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
if (!isMobile && compact && !railOpen) return;
|
|
241
|
+
railRef.current?.querySelector('[data-active="true"]')?.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" });
|
|
242
|
+
}, [compact, isMobile, railOpen, selectedPage]);
|
|
243
|
+
const showRail = pages > 1;
|
|
244
|
+
const tickCount = Math.min(pages, MAX_RAIL_TICKS);
|
|
245
|
+
const activeTick = pages > 0 ? Math.min(tickCount - 1, Math.floor(selectedPage * tickCount / pages)) : 0;
|
|
246
|
+
const pageWidth = pageDimensions ? zoom === "fit" ? Math.max(1, Math.floor(hostWidth)) : Math.max(1, Math.round(pageDimensions.width * zoom)) : 0;
|
|
247
|
+
const pageRenderWidth = pageDimensions ? zoom === "fit" ? Math.max(1, Math.round(pageDimensions.width)) : pageWidth : 0;
|
|
248
|
+
const thumbWidth = isMobile ? STRIP_THUMB_W : compact ? COMPACT_THUMB_W : THUMB_W;
|
|
249
|
+
const thumbHeight = pageDimensions ? Math.round(thumbWidth * pageDimensions.height / pageDimensions.width) : Math.round(thumbWidth * 1.4);
|
|
250
|
+
const zoomLabel = zoom === "fit" ? pageDimensions ? `${zoomPercent(pageWidth, pageDimensions.width) ?? 100}%` : t("deck.zoomFit") : `${Math.round(zoom * 100)}%`;
|
|
251
|
+
const handleDocumentLoadSuccess = useCallback(
|
|
252
|
+
(document) => {
|
|
253
|
+
const source = fileUrl;
|
|
254
|
+
if (document.loadingTask.destroyed) return;
|
|
255
|
+
void document.getPage(1).then((page) => {
|
|
256
|
+
if (!mountedRef.current || activeSourceRef.current !== source) return;
|
|
257
|
+
const viewport = page.getViewport({ scale: 1 });
|
|
258
|
+
setLoadedDocument({
|
|
259
|
+
source,
|
|
260
|
+
proxy: document,
|
|
261
|
+
pageDimensions: {
|
|
262
|
+
width: viewport.width,
|
|
263
|
+
height: viewport.height
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
setSelectedPage(0);
|
|
267
|
+
}).catch(() => {
|
|
268
|
+
if (mountedRef.current && activeSourceRef.current === source) {
|
|
269
|
+
onError();
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
[fileUrl, onError]
|
|
274
|
+
);
|
|
275
|
+
const renderThumbImage = (pageIndex) => activeDocument && /* @__PURE__ */ jsx(LazyThumb, { width: thumbWidth, height: thumbHeight, className: "bg-muted", children: /* @__PURE__ */ jsx(
|
|
276
|
+
Page,
|
|
277
|
+
{
|
|
278
|
+
pdf: activeDocument.proxy,
|
|
279
|
+
pageNumber: pageIndex + 1,
|
|
280
|
+
width: thumbWidth,
|
|
281
|
+
renderTextLayer: false,
|
|
282
|
+
renderAnnotationLayer: false,
|
|
283
|
+
loading: /* @__PURE__ */ jsx(
|
|
284
|
+
"div",
|
|
285
|
+
{
|
|
286
|
+
style: { width: thumbWidth, height: thumbHeight },
|
|
287
|
+
className: "animate-pulse bg-muted"
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
) });
|
|
292
|
+
const renderPageThumb = (pageIndex) => {
|
|
293
|
+
if (!activeDocument) return null;
|
|
294
|
+
const isActive = pageIndex === selectedPage;
|
|
295
|
+
return /* @__PURE__ */ jsxs(
|
|
296
|
+
"button",
|
|
297
|
+
{
|
|
298
|
+
type: "button",
|
|
299
|
+
"data-active": isActive,
|
|
300
|
+
onClick: () => goToPage(pageIndex),
|
|
301
|
+
className: cn(
|
|
302
|
+
"flex items-start text-left transition-colors",
|
|
303
|
+
compact ? "w-full gap-2 rounded-lg p-1.5" : "w-fit shrink-0 gap-1.5 rounded-md p-2",
|
|
304
|
+
isActive ? "bg-surface-active" : compact ? "hover:bg-surface-overlay-hover" : "hover:bg-muted/60"
|
|
305
|
+
),
|
|
306
|
+
children: [
|
|
307
|
+
/* @__PURE__ */ jsx(
|
|
308
|
+
"span",
|
|
309
|
+
{
|
|
310
|
+
className: cn(
|
|
311
|
+
"w-3 shrink-0 pt-0.5 text-right text-xs tabular-nums",
|
|
312
|
+
isActive ? "font-semibold text-foreground" : "text-muted-foreground"
|
|
313
|
+
),
|
|
314
|
+
children: pageIndex + 1
|
|
315
|
+
}
|
|
316
|
+
),
|
|
317
|
+
/* @__PURE__ */ jsx(
|
|
318
|
+
"div",
|
|
319
|
+
{
|
|
320
|
+
className: cn(
|
|
321
|
+
"shrink-0 overflow-hidden border bg-surface shadow-sm",
|
|
322
|
+
compact ? "rounded-md" : "rounded",
|
|
323
|
+
isActive ? "border-transparent ring ring-foreground" : "border-border"
|
|
324
|
+
),
|
|
325
|
+
children: renderThumbImage(pageIndex)
|
|
326
|
+
}
|
|
327
|
+
)
|
|
328
|
+
]
|
|
329
|
+
},
|
|
330
|
+
pageIndex
|
|
331
|
+
);
|
|
332
|
+
};
|
|
333
|
+
return /* @__PURE__ */ jsxs(
|
|
334
|
+
"div",
|
|
335
|
+
{
|
|
336
|
+
ref: viewerRef,
|
|
337
|
+
className: "flex h-full min-h-0 flex-col bg-surface-chat",
|
|
338
|
+
onMouseEnter: () => {
|
|
339
|
+
pointerInside.current = true;
|
|
340
|
+
},
|
|
341
|
+
onMouseLeave: () => {
|
|
342
|
+
pointerInside.current = false;
|
|
343
|
+
},
|
|
344
|
+
children: [
|
|
345
|
+
/* @__PURE__ */ jsxs("div", { className: "grid h-11 shrink-0 grid-cols-[1fr_auto_1fr] items-center gap-2 border-b border-border px-2", children: [
|
|
346
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2 px-1", children: [
|
|
347
|
+
/* @__PURE__ */ jsx(
|
|
348
|
+
"span",
|
|
349
|
+
{
|
|
350
|
+
className: "min-w-0 truncate text-xs font-medium text-muted-foreground",
|
|
351
|
+
title,
|
|
352
|
+
children: label || title || "PDF"
|
|
353
|
+
}
|
|
354
|
+
),
|
|
355
|
+
versionSlot
|
|
356
|
+
] }),
|
|
357
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
358
|
+
/* @__PURE__ */ jsx(
|
|
359
|
+
Button,
|
|
360
|
+
{
|
|
361
|
+
type: "button",
|
|
362
|
+
variant: "ghost",
|
|
363
|
+
size: "icon-sm",
|
|
364
|
+
className: "size-11! md:size-7!",
|
|
365
|
+
disabled: selectedPage === 0,
|
|
366
|
+
onClick: () => goToPage(selectedPage - 1),
|
|
367
|
+
"aria-label": t("deck.prevPage"),
|
|
368
|
+
title: t("deck.prevPage"),
|
|
369
|
+
children: /* @__PURE__ */ jsx(ChevronLeftIcon, { className: "size-4" })
|
|
370
|
+
}
|
|
371
|
+
),
|
|
372
|
+
/* @__PURE__ */ jsx(
|
|
373
|
+
"span",
|
|
374
|
+
{
|
|
375
|
+
"aria-atomic": "true",
|
|
376
|
+
"aria-live": "polite",
|
|
377
|
+
className: "min-w-12 text-center text-xs tabular-nums text-foreground",
|
|
378
|
+
children: pages > 0 ? `${selectedPage + 1}/${pages}` : "\u2014/\u2014"
|
|
379
|
+
}
|
|
380
|
+
),
|
|
381
|
+
/* @__PURE__ */ jsx(
|
|
382
|
+
Button,
|
|
383
|
+
{
|
|
384
|
+
type: "button",
|
|
385
|
+
variant: "ghost",
|
|
386
|
+
size: "icon-sm",
|
|
387
|
+
className: "size-11! md:size-7!",
|
|
388
|
+
disabled: pages === 0 || selectedPage === pages - 1,
|
|
389
|
+
onClick: () => goToPage(selectedPage + 1),
|
|
390
|
+
"aria-label": t("deck.nextPage"),
|
|
391
|
+
title: t("deck.nextPage"),
|
|
392
|
+
children: /* @__PURE__ */ jsx(ChevronRightIcon, { className: "size-4" })
|
|
393
|
+
}
|
|
394
|
+
)
|
|
395
|
+
] }),
|
|
396
|
+
/* @__PURE__ */ jsx("div", { className: "flex min-w-0 items-center justify-end gap-1", children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
397
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
398
|
+
Button,
|
|
399
|
+
{
|
|
400
|
+
type: "button",
|
|
401
|
+
variant: "ghost",
|
|
402
|
+
size: "sm",
|
|
403
|
+
className: "h-11 gap-1 px-2 text-xs tabular-nums text-muted-foreground hover:text-foreground md:h-8",
|
|
404
|
+
"aria-label": t("deck.zoom"),
|
|
405
|
+
children: [
|
|
406
|
+
zoomLabel,
|
|
407
|
+
/* @__PURE__ */ jsx(ChevronDownMediumIcon, { className: "size-3.5" })
|
|
408
|
+
]
|
|
409
|
+
}
|
|
410
|
+
) }),
|
|
411
|
+
/* @__PURE__ */ jsx(DropdownMenuContent, { align: "end", className: "min-w-28", children: /* @__PURE__ */ jsxs(
|
|
412
|
+
DropdownMenuRadioGroup,
|
|
413
|
+
{
|
|
414
|
+
value: zoom === "fit" ? "fit" : String(zoom),
|
|
415
|
+
onValueChange: (value) => setZoom(value === "fit" ? "fit" : Number(value)),
|
|
416
|
+
children: [
|
|
417
|
+
/* @__PURE__ */ jsx(DropdownMenuRadioItem, { value: "fit", children: t("deck.zoomFit") }),
|
|
418
|
+
DECK_ZOOM_LEVELS.map((level) => /* @__PURE__ */ jsxs(
|
|
419
|
+
DropdownMenuRadioItem,
|
|
420
|
+
{
|
|
421
|
+
value: String(level),
|
|
422
|
+
children: [
|
|
423
|
+
Math.round(level * 100),
|
|
424
|
+
"%"
|
|
425
|
+
]
|
|
426
|
+
},
|
|
427
|
+
level
|
|
428
|
+
))
|
|
429
|
+
]
|
|
430
|
+
}
|
|
431
|
+
) })
|
|
432
|
+
] }) })
|
|
433
|
+
] }),
|
|
434
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-1 bg-muted/30", children: [
|
|
435
|
+
showRail && activeDocument && !isMobile && (compact ? /* @__PURE__ */ jsxs(
|
|
436
|
+
"div",
|
|
437
|
+
{
|
|
438
|
+
className: "relative flex min-h-0 w-11 shrink-0 items-center justify-center",
|
|
439
|
+
onMouseEnter: openRail,
|
|
440
|
+
onMouseLeave: closeRail,
|
|
441
|
+
onFocusCapture: openRail,
|
|
442
|
+
onBlurCapture: (event) => {
|
|
443
|
+
if (!event.currentTarget.contains(event.relatedTarget)) closeRail();
|
|
444
|
+
},
|
|
445
|
+
children: [
|
|
446
|
+
/* @__PURE__ */ jsx(
|
|
447
|
+
"button",
|
|
448
|
+
{
|
|
449
|
+
type: "button",
|
|
450
|
+
className: "flex h-11 w-11 flex-col items-center justify-center gap-1.5 bg-transparent p-0 outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
|
|
451
|
+
"aria-label": t("deck.showPages"),
|
|
452
|
+
"aria-expanded": railOpen,
|
|
453
|
+
onClick: (event) => {
|
|
454
|
+
event.preventDefault();
|
|
455
|
+
openRail();
|
|
456
|
+
},
|
|
457
|
+
children: Array.from({ length: tickCount }, (_, tickIndex) => /* @__PURE__ */ jsx(
|
|
458
|
+
"span",
|
|
459
|
+
{
|
|
460
|
+
"data-page-indicator": tickIndex,
|
|
461
|
+
"data-active": tickIndex === activeTick,
|
|
462
|
+
"aria-hidden": true,
|
|
463
|
+
className: cn(
|
|
464
|
+
"h-0.5 w-5 shrink-0 transition-colors",
|
|
465
|
+
tickIndex === activeTick ? "bg-foreground" : "bg-muted-foreground/20"
|
|
466
|
+
)
|
|
467
|
+
},
|
|
468
|
+
tickIndex
|
|
469
|
+
))
|
|
470
|
+
}
|
|
471
|
+
),
|
|
472
|
+
/* @__PURE__ */ jsx(
|
|
473
|
+
"div",
|
|
474
|
+
{
|
|
475
|
+
role: "dialog",
|
|
476
|
+
"aria-label": t("deck.showPages"),
|
|
477
|
+
"aria-hidden": !railOpen,
|
|
478
|
+
inert: !railOpen,
|
|
479
|
+
"data-testid": "pdf-rail-overlay",
|
|
480
|
+
"data-state": railOpen ? "open" : "closed",
|
|
481
|
+
className: cn(
|
|
482
|
+
"absolute left-3 top-1/2 z-50 max-h-[70vh] w-36 -translate-y-1/2 overflow-hidden rounded-xl border border-border bg-surface-overlay p-1.5 shadow-lg transition-opacity duration-[120ms] ease-out will-change-opacity motion-reduce:transition-none",
|
|
483
|
+
railOpen ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0"
|
|
484
|
+
),
|
|
485
|
+
children: /* @__PURE__ */ jsx(
|
|
486
|
+
"div",
|
|
487
|
+
{
|
|
488
|
+
ref: railRef,
|
|
489
|
+
className: "max-h-[calc(70vh-0.75rem)] overflow-y-auto scrollbar",
|
|
490
|
+
children: Array.from(
|
|
491
|
+
{ length: pages },
|
|
492
|
+
(_, pageIndex) => renderPageThumb(pageIndex)
|
|
493
|
+
)
|
|
494
|
+
}
|
|
495
|
+
)
|
|
496
|
+
}
|
|
497
|
+
)
|
|
498
|
+
]
|
|
499
|
+
}
|
|
500
|
+
) : /* @__PURE__ */ jsx(
|
|
501
|
+
ScrollArea,
|
|
502
|
+
{
|
|
503
|
+
scrollbars: "both",
|
|
504
|
+
className: "w-full shrink-0 border-b border-border sm:w-[164px] sm:border-b-0 sm:border-r",
|
|
505
|
+
children: /* @__PURE__ */ jsx("div", { ref: railRef, className: "flex flex-row gap-1 p-2 sm:flex-col", children: Array.from(
|
|
506
|
+
{ length: pages },
|
|
507
|
+
(_, pageIndex) => renderPageThumb(pageIndex)
|
|
508
|
+
) })
|
|
509
|
+
}
|
|
510
|
+
)),
|
|
511
|
+
/* @__PURE__ */ jsx(
|
|
512
|
+
"div",
|
|
513
|
+
{
|
|
514
|
+
ref: setHostElement,
|
|
515
|
+
className: "min-h-0 flex-1 overflow-auto overscroll-contain scrollbar px-2 py-3 md:px-4 md:py-4",
|
|
516
|
+
children: activeDocument && pages > 0 && pageWidth > 0 && pageDimensions ? /* @__PURE__ */ jsx("div", { className: "mx-auto flex w-fit min-w-full flex-col items-center gap-3 md:gap-4", children: Array.from({ length: pages }, (_, pageIndex) => /* @__PURE__ */ jsx(
|
|
517
|
+
PdfDocumentPage,
|
|
518
|
+
{
|
|
519
|
+
pdfDocument: activeDocument.proxy,
|
|
520
|
+
pageIndex,
|
|
521
|
+
displayWidth: pageWidth,
|
|
522
|
+
renderWidth: pageRenderWidth,
|
|
523
|
+
pageDimensions,
|
|
524
|
+
shouldRender: Math.abs(pageIndex - selectedPage) <= PDF_PAGE_RENDER_RADIUS,
|
|
525
|
+
devicePixelRatio: renderPixelRatio
|
|
526
|
+
},
|
|
527
|
+
pageIndex
|
|
528
|
+
)) }) : /* @__PURE__ */ jsx(ArtifactSkeleton, { format: "pdf", showChrome: false })
|
|
529
|
+
}
|
|
530
|
+
)
|
|
531
|
+
] }),
|
|
532
|
+
showRail && activeDocument && isMobile && /* @__PURE__ */ jsx(
|
|
533
|
+
"div",
|
|
534
|
+
{
|
|
535
|
+
ref: railRef,
|
|
536
|
+
"data-testid": "pdf-page-strip",
|
|
537
|
+
className: "flex shrink-0 gap-2 overflow-x-auto border-t border-border bg-surface px-2 py-2 scrollbar-hide",
|
|
538
|
+
children: Array.from({ length: pages }, (_, pageIndex) => /* @__PURE__ */ jsxs(
|
|
539
|
+
"button",
|
|
540
|
+
{
|
|
541
|
+
type: "button",
|
|
542
|
+
"data-active": pageIndex === selectedPage,
|
|
543
|
+
onClick: () => goToPage(pageIndex),
|
|
544
|
+
"aria-label": `${t("deck.page")} ${pageIndex + 1}`,
|
|
545
|
+
"aria-current": pageIndex === selectedPage,
|
|
546
|
+
className: cn(
|
|
547
|
+
"relative shrink-0 overflow-hidden rounded border bg-surface transition-colors",
|
|
548
|
+
pageIndex === selectedPage ? "border-transparent ring ring-foreground" : "border-border"
|
|
549
|
+
),
|
|
550
|
+
children: [
|
|
551
|
+
renderThumbImage(pageIndex),
|
|
552
|
+
/* @__PURE__ */ jsx(
|
|
553
|
+
"span",
|
|
554
|
+
{
|
|
555
|
+
className: cn(
|
|
556
|
+
"absolute bottom-0.5 right-0.5 rounded bg-surface-overlay/85 px-1 text-[10px] tabular-nums",
|
|
557
|
+
pageIndex === selectedPage ? "text-foreground" : "text-muted-foreground"
|
|
558
|
+
),
|
|
559
|
+
children: pageIndex + 1
|
|
560
|
+
}
|
|
561
|
+
)
|
|
562
|
+
]
|
|
563
|
+
},
|
|
564
|
+
pageIndex
|
|
565
|
+
))
|
|
566
|
+
}
|
|
567
|
+
),
|
|
568
|
+
/* @__PURE__ */ jsx(
|
|
569
|
+
Document,
|
|
570
|
+
{
|
|
571
|
+
file: fileUrl,
|
|
572
|
+
onLoadSuccess: handleDocumentLoadSuccess,
|
|
573
|
+
onLoadError: onError,
|
|
574
|
+
loading: null,
|
|
575
|
+
error: null,
|
|
576
|
+
className: "hidden"
|
|
577
|
+
},
|
|
578
|
+
fileUrl
|
|
579
|
+
)
|
|
580
|
+
]
|
|
581
|
+
}
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export { PdfDocumentViewInner as default };
|