@algenium/blocks 1.7.0-rc.2 → 1.7.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +587 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -2
- package/dist/index.d.ts +64 -2
- package/dist/index.js +587 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React2 from 'react';
|
|
2
2
|
import { createContext, useContext, useState, useCallback, useEffect, useRef, useMemo, useId } from 'react';
|
|
3
3
|
import { useTheme } from 'next-themes';
|
|
4
|
-
import { CheckIcon, CircleIcon, ChevronRightIcon, Monitor, Sun, Moon, Languages, FlaskConical, X, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, XIcon, User, Pencil, Check, Loader2, Bell, CheckCheck, XCircle, AlertTriangle, CheckCircle, Info, Trash2, Clock, MapPin, Link, CalendarDays, ExternalLink, ChevronLeft, ChevronRight, Plus, HelpCircle, MessageSquare, Wifi, WifiOff, FileIcon, Download, Paperclip, Send, ArrowLeft, CreditCard, Search, CheckCircle2 } from 'lucide-react';
|
|
4
|
+
import { CheckIcon, CircleIcon, ChevronRightIcon, Monitor, Sun, Moon, Languages, FlaskConical, X, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, XIcon, User, Pencil, Check, Loader2, Bell, CheckCheck, XCircle, AlertTriangle, CheckCircle, Info, Trash2, Clock, MapPin, Link, CalendarDays, ExternalLink, ChevronLeft, ChevronRight, Plus, HelpCircle, MessageSquare, Wifi, WifiOff, FileIcon, Download, Paperclip, Send, ArrowLeft, CreditCard, Search, CheckCircle2, Maximize2 } from 'lucide-react';
|
|
5
5
|
import { AnimatePresence, motion } from 'framer-motion';
|
|
6
6
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -8100,7 +8100,592 @@ function USAddressInput({
|
|
|
8100
8100
|
] })
|
|
8101
8101
|
] });
|
|
8102
8102
|
}
|
|
8103
|
+
function defaultPageOf(page, total) {
|
|
8104
|
+
return `${page} / ${total}`;
|
|
8105
|
+
}
|
|
8106
|
+
var DEFAULT_WORKER_MSG = "PdfViewer requires a non-empty workerSrc pointing at pdf.worker matching your project's pdfjs-dist version. Example: `new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url)`.";
|
|
8107
|
+
function buildGetDocumentArgs(src, documentOptions) {
|
|
8108
|
+
const rest = documentOptions ?? {};
|
|
8109
|
+
if (typeof src === "string") {
|
|
8110
|
+
return { url: src, ...rest };
|
|
8111
|
+
}
|
|
8112
|
+
return { data: src, ...rest };
|
|
8113
|
+
}
|
|
8114
|
+
function PdfPageCanvas({
|
|
8115
|
+
page,
|
|
8116
|
+
layout,
|
|
8117
|
+
scale,
|
|
8118
|
+
visible,
|
|
8119
|
+
pageClassName
|
|
8120
|
+
}) {
|
|
8121
|
+
const canvasRef = useRef(null);
|
|
8122
|
+
const taskRef = useRef(null);
|
|
8123
|
+
useEffect(() => {
|
|
8124
|
+
if (!visible || !canvasRef.current) {
|
|
8125
|
+
taskRef.current?.cancel();
|
|
8126
|
+
taskRef.current = null;
|
|
8127
|
+
const c = canvasRef.current;
|
|
8128
|
+
if (c) {
|
|
8129
|
+
const ctx2 = c.getContext("2d");
|
|
8130
|
+
if (ctx2) {
|
|
8131
|
+
ctx2.setTransform(1, 0, 0, 1, 0, 0);
|
|
8132
|
+
ctx2.clearRect(0, 0, c.width, c.height);
|
|
8133
|
+
}
|
|
8134
|
+
}
|
|
8135
|
+
return;
|
|
8136
|
+
}
|
|
8137
|
+
const canvas = canvasRef.current;
|
|
8138
|
+
const ctx = canvas.getContext("2d");
|
|
8139
|
+
if (!ctx) return;
|
|
8140
|
+
const viewport = page.getViewport({ scale });
|
|
8141
|
+
canvas.width = viewport.width;
|
|
8142
|
+
canvas.height = viewport.height;
|
|
8143
|
+
const task = page.render({
|
|
8144
|
+
canvasContext: ctx,
|
|
8145
|
+
viewport,
|
|
8146
|
+
canvas
|
|
8147
|
+
});
|
|
8148
|
+
taskRef.current = task;
|
|
8149
|
+
task.promise.catch(() => {
|
|
8150
|
+
});
|
|
8151
|
+
return () => {
|
|
8152
|
+
task.cancel();
|
|
8153
|
+
if (taskRef.current === task) {
|
|
8154
|
+
taskRef.current = null;
|
|
8155
|
+
}
|
|
8156
|
+
};
|
|
8157
|
+
}, [page, visible, scale]);
|
|
8158
|
+
const w = layout.widthPt * scale;
|
|
8159
|
+
const h = layout.heightPt * scale;
|
|
8160
|
+
return /* @__PURE__ */ jsx(
|
|
8161
|
+
"div",
|
|
8162
|
+
{
|
|
8163
|
+
className: cn("relative flex justify-center bg-muted/40", pageClassName),
|
|
8164
|
+
style: { width: w, height: h },
|
|
8165
|
+
"data-page": layout.pageNumber,
|
|
8166
|
+
children: visible ? /* @__PURE__ */ jsx(
|
|
8167
|
+
"canvas",
|
|
8168
|
+
{
|
|
8169
|
+
ref: canvasRef,
|
|
8170
|
+
className: "block max-h-full shadow-sm",
|
|
8171
|
+
"aria-hidden": "true"
|
|
8172
|
+
}
|
|
8173
|
+
) : null
|
|
8174
|
+
}
|
|
8175
|
+
);
|
|
8176
|
+
}
|
|
8177
|
+
function PdfViewer({
|
|
8178
|
+
src,
|
|
8179
|
+
workerSrc,
|
|
8180
|
+
documentOptions,
|
|
8181
|
+
initialPage = 1,
|
|
8182
|
+
initialScale = 1,
|
|
8183
|
+
minScale = 0.5,
|
|
8184
|
+
maxScale = 4,
|
|
8185
|
+
scaleStep = 0.2,
|
|
8186
|
+
enableKeyboardShortcuts = true,
|
|
8187
|
+
labels,
|
|
8188
|
+
onLoad,
|
|
8189
|
+
onError,
|
|
8190
|
+
onPageChange,
|
|
8191
|
+
onScaleChange,
|
|
8192
|
+
className,
|
|
8193
|
+
toolbarClassName,
|
|
8194
|
+
pageClassName,
|
|
8195
|
+
toolbarEndSlot
|
|
8196
|
+
}) {
|
|
8197
|
+
const mergedLabels = labels ?? {};
|
|
8198
|
+
const toolbarLabel = mergedLabels.toolbar ?? "PDF controls";
|
|
8199
|
+
const loadingLabel = mergedLabels.loading ?? "Loading PDF\u2026";
|
|
8200
|
+
const workerErrorMessage = mergedLabels.workerMissing ?? DEFAULT_WORKER_MSG;
|
|
8201
|
+
const errorLabelFallback = mergedLabels.error ?? "Failed to load PDF";
|
|
8202
|
+
const toolbarId = useId();
|
|
8203
|
+
const pageInputId = `${toolbarId}-page`;
|
|
8204
|
+
const scrollRef = useRef(null);
|
|
8205
|
+
const observerRef = useRef(null);
|
|
8206
|
+
const lastReportedPage = useRef(0);
|
|
8207
|
+
const loadedPdfRef = useRef(null);
|
|
8208
|
+
const [loadError, setLoadError] = useState(null);
|
|
8209
|
+
const [busy, setBusy] = useState(false);
|
|
8210
|
+
const [layouts, setLayouts] = useState([]);
|
|
8211
|
+
const [pagesMap, setPagesMap] = useState(
|
|
8212
|
+
null
|
|
8213
|
+
);
|
|
8214
|
+
const [scale, setScale] = useState(initialScale);
|
|
8215
|
+
const [ratios, setRatios] = useState({});
|
|
8216
|
+
const [pageInput, setPageInput] = useState(String(initialPage));
|
|
8217
|
+
const baselineScaleRef = useRef(initialScale);
|
|
8218
|
+
useEffect(() => {
|
|
8219
|
+
baselineScaleRef.current = initialScale;
|
|
8220
|
+
}, [initialScale]);
|
|
8221
|
+
const pageOfFormatter = mergedLabels.pageOf ?? defaultPageOf;
|
|
8222
|
+
const resolvedGoToLabel = mergedLabels.goToPage ?? "Go to page";
|
|
8223
|
+
const zoomInLabel = mergedLabels.zoomIn ?? "Zoom in";
|
|
8224
|
+
const zoomOutLabel = mergedLabels.zoomOut ?? "Zoom out";
|
|
8225
|
+
const resetZoomLabel = mergedLabels.resetZoom ?? "Reset zoom";
|
|
8226
|
+
const fitWidthLabel = mergedLabels.fitToWidth ?? "Fit to width";
|
|
8227
|
+
const pageCount = layouts.length;
|
|
8228
|
+
const currentVisiblePage = useMemo(() => {
|
|
8229
|
+
let bestPage = 1;
|
|
8230
|
+
let bestRatio = -1;
|
|
8231
|
+
for (const layout of layouts) {
|
|
8232
|
+
const r2 = ratios[layout.pageNumber] ?? 0;
|
|
8233
|
+
if (r2 > bestRatio) {
|
|
8234
|
+
bestRatio = r2;
|
|
8235
|
+
bestPage = layout.pageNumber;
|
|
8236
|
+
}
|
|
8237
|
+
}
|
|
8238
|
+
return bestRatio >= 0.01 ? bestPage : 1;
|
|
8239
|
+
}, [layouts, ratios]);
|
|
8240
|
+
const clampScaleValue = useCallback(
|
|
8241
|
+
(v) => Math.min(maxScale, Math.max(minScale, v)),
|
|
8242
|
+
[minScale, maxScale]
|
|
8243
|
+
);
|
|
8244
|
+
const zoomInAct = useCallback(() => {
|
|
8245
|
+
setScale((prev) => {
|
|
8246
|
+
const c = clampScaleValue(prev + scaleStep);
|
|
8247
|
+
onScaleChange?.(c);
|
|
8248
|
+
return c;
|
|
8249
|
+
});
|
|
8250
|
+
}, [clampScaleValue, onScaleChange, scaleStep]);
|
|
8251
|
+
const zoomOutAct = useCallback(() => {
|
|
8252
|
+
setScale((prev) => {
|
|
8253
|
+
const c = clampScaleValue(prev - scaleStep);
|
|
8254
|
+
onScaleChange?.(c);
|
|
8255
|
+
return c;
|
|
8256
|
+
});
|
|
8257
|
+
}, [clampScaleValue, onScaleChange, scaleStep]);
|
|
8258
|
+
const resetZoomAct = useCallback(() => {
|
|
8259
|
+
const c = clampScaleValue(baselineScaleRef.current);
|
|
8260
|
+
setScale(c);
|
|
8261
|
+
onScaleChange?.(c);
|
|
8262
|
+
}, [clampScaleValue, onScaleChange]);
|
|
8263
|
+
const fitToWidthAct = useCallback(() => {
|
|
8264
|
+
const root = scrollRef.current;
|
|
8265
|
+
if (!root || layouts.length === 0) return;
|
|
8266
|
+
const avail = Math.max(root.clientWidth - 32, 120);
|
|
8267
|
+
const maxW = Math.max(...layouts.map((l) => l.widthPt), 1);
|
|
8268
|
+
const next = clampScaleValue(avail / maxW);
|
|
8269
|
+
setScale(next);
|
|
8270
|
+
onScaleChange?.(next);
|
|
8271
|
+
}, [clampScaleValue, layouts, onScaleChange]);
|
|
8272
|
+
useEffect(() => {
|
|
8273
|
+
setPageInput(String(currentVisiblePage));
|
|
8274
|
+
if (lastReportedPage.current !== currentVisiblePage) {
|
|
8275
|
+
lastReportedPage.current = currentVisiblePage;
|
|
8276
|
+
onPageChange?.(currentVisiblePage);
|
|
8277
|
+
}
|
|
8278
|
+
}, [currentVisiblePage, onPageChange]);
|
|
8279
|
+
const scrollToPage = useCallback((pageNum) => {
|
|
8280
|
+
const root = scrollRef.current;
|
|
8281
|
+
if (!root || pageNum < 1) return;
|
|
8282
|
+
const el = root.querySelector(`[data-page="${pageNum}"]`);
|
|
8283
|
+
if (el instanceof HTMLElement) {
|
|
8284
|
+
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
8285
|
+
}
|
|
8286
|
+
}, []);
|
|
8287
|
+
useEffect(() => {
|
|
8288
|
+
if (!busy && pagesMap && pageCount > 0) {
|
|
8289
|
+
const p = Math.min(Math.max(1, initialPage), pageCount);
|
|
8290
|
+
requestAnimationFrame(() => scrollToPage(p));
|
|
8291
|
+
}
|
|
8292
|
+
}, [busy, pagesMap, pageCount, initialPage, scrollToPage]);
|
|
8293
|
+
const loadKey = useMemo(() => {
|
|
8294
|
+
if (typeof src === "string") return src;
|
|
8295
|
+
if (src instanceof ArrayBuffer) return `ab:${src.byteLength}`;
|
|
8296
|
+
return `ua:${src.byteLength}:${src.byteOffset}:${src.buffer.byteLength}`;
|
|
8297
|
+
}, [src]);
|
|
8298
|
+
useEffect(() => {
|
|
8299
|
+
let cancelled = false;
|
|
8300
|
+
let activeDoc = null;
|
|
8301
|
+
setLoadError(null);
|
|
8302
|
+
if (loadedPdfRef.current) {
|
|
8303
|
+
void loadedPdfRef.current.destroy();
|
|
8304
|
+
loadedPdfRef.current = null;
|
|
8305
|
+
}
|
|
8306
|
+
setLayouts([]);
|
|
8307
|
+
setPagesMap(null);
|
|
8308
|
+
setRatios({});
|
|
8309
|
+
const trimmedWorker = workerSrc?.trim?.() ?? "";
|
|
8310
|
+
if (!trimmedWorker) {
|
|
8311
|
+
setLoadError(workerErrorMessage);
|
|
8312
|
+
onError?.(new Error(workerErrorMessage));
|
|
8313
|
+
return () => {
|
|
8314
|
+
cancelled = true;
|
|
8315
|
+
};
|
|
8316
|
+
}
|
|
8317
|
+
void (async () => {
|
|
8318
|
+
try {
|
|
8319
|
+
setBusy(true);
|
|
8320
|
+
const pdfjs = await import('pdfjs-dist');
|
|
8321
|
+
if (cancelled) return;
|
|
8322
|
+
pdfjs.GlobalWorkerOptions.workerSrc = trimmedWorker;
|
|
8323
|
+
const loadingTask = pdfjs.getDocument(
|
|
8324
|
+
buildGetDocumentArgs(src, documentOptions)
|
|
8325
|
+
);
|
|
8326
|
+
activeDoc = await loadingTask.promise;
|
|
8327
|
+
if (cancelled) {
|
|
8328
|
+
void activeDoc.destroy();
|
|
8329
|
+
activeDoc = null;
|
|
8330
|
+
return;
|
|
8331
|
+
}
|
|
8332
|
+
const layoutsLocal = [];
|
|
8333
|
+
const mapLocal = /* @__PURE__ */ new Map();
|
|
8334
|
+
for (let p = 1; p <= activeDoc.numPages; p++) {
|
|
8335
|
+
const page = await activeDoc.getPage(p);
|
|
8336
|
+
mapLocal.set(p, page);
|
|
8337
|
+
const viewport = page.getViewport({ scale: 1 });
|
|
8338
|
+
layoutsLocal.push({
|
|
8339
|
+
pageNumber: p,
|
|
8340
|
+
widthPt: viewport.width,
|
|
8341
|
+
heightPt: viewport.height
|
|
8342
|
+
});
|
|
8343
|
+
}
|
|
8344
|
+
if (cancelled) {
|
|
8345
|
+
void activeDoc.destroy();
|
|
8346
|
+
activeDoc = null;
|
|
8347
|
+
return;
|
|
8348
|
+
}
|
|
8349
|
+
onLoad?.(activeDoc);
|
|
8350
|
+
loadedPdfRef.current = activeDoc;
|
|
8351
|
+
setLayouts(layoutsLocal);
|
|
8352
|
+
setPagesMap(mapLocal);
|
|
8353
|
+
activeDoc = null;
|
|
8354
|
+
} catch (e) {
|
|
8355
|
+
const err = e instanceof Error ? e : new Error(String(e));
|
|
8356
|
+
if (!cancelled) {
|
|
8357
|
+
setLoadError(errorLabelFallback);
|
|
8358
|
+
onError?.(err);
|
|
8359
|
+
}
|
|
8360
|
+
if (activeDoc) {
|
|
8361
|
+
void activeDoc.destroy();
|
|
8362
|
+
activeDoc = null;
|
|
8363
|
+
}
|
|
8364
|
+
} finally {
|
|
8365
|
+
if (!cancelled) setBusy(false);
|
|
8366
|
+
}
|
|
8367
|
+
})();
|
|
8368
|
+
return () => {
|
|
8369
|
+
cancelled = true;
|
|
8370
|
+
if (observerRef.current) {
|
|
8371
|
+
observerRef.current.disconnect();
|
|
8372
|
+
observerRef.current = null;
|
|
8373
|
+
}
|
|
8374
|
+
if (activeDoc) {
|
|
8375
|
+
void activeDoc.destroy();
|
|
8376
|
+
}
|
|
8377
|
+
if (loadedPdfRef.current) {
|
|
8378
|
+
void loadedPdfRef.current.destroy();
|
|
8379
|
+
loadedPdfRef.current = null;
|
|
8380
|
+
}
|
|
8381
|
+
};
|
|
8382
|
+
}, [workerSrc, loadKey, documentOptions]);
|
|
8383
|
+
useEffect(() => {
|
|
8384
|
+
setScale(clampScaleValue(initialScale));
|
|
8385
|
+
}, [initialScale, clampScaleValue]);
|
|
8386
|
+
useEffect(() => {
|
|
8387
|
+
if (layouts.length === 0) return;
|
|
8388
|
+
const frame = requestAnimationFrame(() => {
|
|
8389
|
+
const root = scrollRef.current;
|
|
8390
|
+
if (!root) return;
|
|
8391
|
+
if (observerRef.current) {
|
|
8392
|
+
observerRef.current.disconnect();
|
|
8393
|
+
}
|
|
8394
|
+
const io = new IntersectionObserver(
|
|
8395
|
+
(entries) => {
|
|
8396
|
+
setRatios((prev) => {
|
|
8397
|
+
const next = { ...prev };
|
|
8398
|
+
for (const e of entries) {
|
|
8399
|
+
const tgt = e.target;
|
|
8400
|
+
const p = Number(tgt.dataset.page);
|
|
8401
|
+
if (Number.isFinite(p)) next[p] = e.intersectionRatio;
|
|
8402
|
+
}
|
|
8403
|
+
return next;
|
|
8404
|
+
});
|
|
8405
|
+
},
|
|
8406
|
+
{
|
|
8407
|
+
root,
|
|
8408
|
+
rootMargin: "200px 0px",
|
|
8409
|
+
threshold: [0, 0.05, 0.25, 0.5, 0.75, 1]
|
|
8410
|
+
}
|
|
8411
|
+
);
|
|
8412
|
+
observerRef.current = io;
|
|
8413
|
+
root.querySelectorAll("[data-page]").forEach((el) => io.observe(el));
|
|
8414
|
+
});
|
|
8415
|
+
return () => {
|
|
8416
|
+
cancelAnimationFrame(frame);
|
|
8417
|
+
if (observerRef.current) {
|
|
8418
|
+
observerRef.current.disconnect();
|
|
8419
|
+
observerRef.current = null;
|
|
8420
|
+
}
|
|
8421
|
+
};
|
|
8422
|
+
}, [layouts]);
|
|
8423
|
+
const handleSubmitPage = useCallback(() => {
|
|
8424
|
+
const n = Number.parseInt(pageInput, 10);
|
|
8425
|
+
if (!Number.isFinite(n) || pageCount === 0) return;
|
|
8426
|
+
const clamped = Math.min(Math.max(1, n), pageCount);
|
|
8427
|
+
scrollToPage(clamped);
|
|
8428
|
+
setPageInput(String(clamped));
|
|
8429
|
+
}, [pageInput, pageCount, scrollToPage]);
|
|
8430
|
+
const handleKeyDown = useCallback(
|
|
8431
|
+
(e) => {
|
|
8432
|
+
if (!enableKeyboardShortcuts) return;
|
|
8433
|
+
if (e.target !== e.currentTarget && e.target instanceof HTMLInputElement) {
|
|
8434
|
+
return;
|
|
8435
|
+
}
|
|
8436
|
+
let handled = false;
|
|
8437
|
+
switch (e.key) {
|
|
8438
|
+
case "PageDown": {
|
|
8439
|
+
scrollToPage(Math.min(pageCount || 1, currentVisiblePage + 1));
|
|
8440
|
+
handled = true;
|
|
8441
|
+
break;
|
|
8442
|
+
}
|
|
8443
|
+
case "PageUp": {
|
|
8444
|
+
scrollToPage(Math.max(1, currentVisiblePage - 1));
|
|
8445
|
+
handled = true;
|
|
8446
|
+
break;
|
|
8447
|
+
}
|
|
8448
|
+
case "Home": {
|
|
8449
|
+
scrollToPage(1);
|
|
8450
|
+
handled = true;
|
|
8451
|
+
break;
|
|
8452
|
+
}
|
|
8453
|
+
case "End": {
|
|
8454
|
+
if (pageCount) scrollToPage(pageCount);
|
|
8455
|
+
handled = true;
|
|
8456
|
+
break;
|
|
8457
|
+
}
|
|
8458
|
+
case "+":
|
|
8459
|
+
case "=": {
|
|
8460
|
+
zoomInAct();
|
|
8461
|
+
handled = true;
|
|
8462
|
+
break;
|
|
8463
|
+
}
|
|
8464
|
+
case "-":
|
|
8465
|
+
case "_": {
|
|
8466
|
+
zoomOutAct();
|
|
8467
|
+
handled = true;
|
|
8468
|
+
break;
|
|
8469
|
+
}
|
|
8470
|
+
case "0": {
|
|
8471
|
+
resetZoomAct();
|
|
8472
|
+
handled = true;
|
|
8473
|
+
break;
|
|
8474
|
+
}
|
|
8475
|
+
}
|
|
8476
|
+
if (handled) {
|
|
8477
|
+
e.preventDefault();
|
|
8478
|
+
e.stopPropagation();
|
|
8479
|
+
}
|
|
8480
|
+
},
|
|
8481
|
+
[
|
|
8482
|
+
enableKeyboardShortcuts,
|
|
8483
|
+
pageCount,
|
|
8484
|
+
currentVisiblePage,
|
|
8485
|
+
scrollToPage,
|
|
8486
|
+
zoomInAct,
|
|
8487
|
+
zoomOutAct,
|
|
8488
|
+
resetZoomAct
|
|
8489
|
+
]
|
|
8490
|
+
);
|
|
8491
|
+
if (loadError) {
|
|
8492
|
+
return /* @__PURE__ */ jsx(
|
|
8493
|
+
"div",
|
|
8494
|
+
{
|
|
8495
|
+
className: cn("rounded-md border border-destructive/50 p-4", className),
|
|
8496
|
+
role: "alert",
|
|
8497
|
+
children: /* @__PURE__ */ jsx("p", { className: "text-destructive text-sm", children: loadError })
|
|
8498
|
+
}
|
|
8499
|
+
);
|
|
8500
|
+
}
|
|
8501
|
+
return /* @__PURE__ */ jsxs(
|
|
8502
|
+
"div",
|
|
8503
|
+
{
|
|
8504
|
+
className: cn(
|
|
8505
|
+
"flex min-h-0 flex-col overflow-hidden rounded-md border",
|
|
8506
|
+
className
|
|
8507
|
+
),
|
|
8508
|
+
children: [
|
|
8509
|
+
/* @__PURE__ */ jsxs(
|
|
8510
|
+
"div",
|
|
8511
|
+
{
|
|
8512
|
+
id: toolbarId,
|
|
8513
|
+
role: "toolbar",
|
|
8514
|
+
"aria-label": toolbarLabel,
|
|
8515
|
+
className: cn(
|
|
8516
|
+
"sticky top-0 z-10 flex shrink-0 flex-wrap items-center gap-2 border-b bg-background/95 px-2 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/80",
|
|
8517
|
+
toolbarClassName
|
|
8518
|
+
),
|
|
8519
|
+
children: [
|
|
8520
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs tabular-nums sm:text-sm", children: busy || pagesMap === null ? "\u2014" : pageOfFormatter(currentVisiblePage, pageCount) }),
|
|
8521
|
+
/* @__PURE__ */ jsx("label", { htmlFor: pageInputId, className: "sr-only", children: resolvedGoToLabel }),
|
|
8522
|
+
/* @__PURE__ */ jsx(
|
|
8523
|
+
"input",
|
|
8524
|
+
{
|
|
8525
|
+
id: pageInputId,
|
|
8526
|
+
type: "number",
|
|
8527
|
+
min: 1,
|
|
8528
|
+
max: Math.max(pageCount, 1),
|
|
8529
|
+
disabled: busy || pageCount === 0,
|
|
8530
|
+
className: "h-8 w-14 rounded-md border border-input bg-background px-2 text-sm tabular-nums",
|
|
8531
|
+
"aria-label": resolvedGoToLabel,
|
|
8532
|
+
value: pageInput,
|
|
8533
|
+
onChange: (ev) => setPageInput(ev.target.value),
|
|
8534
|
+
onKeyDown: (ev) => {
|
|
8535
|
+
if (ev.key === "Enter") {
|
|
8536
|
+
ev.preventDefault();
|
|
8537
|
+
handleSubmitPage();
|
|
8538
|
+
}
|
|
8539
|
+
}
|
|
8540
|
+
}
|
|
8541
|
+
),
|
|
8542
|
+
/* @__PURE__ */ jsx(
|
|
8543
|
+
Button,
|
|
8544
|
+
{
|
|
8545
|
+
type: "button",
|
|
8546
|
+
variant: "outline",
|
|
8547
|
+
size: "icon-sm",
|
|
8548
|
+
onClick: zoomOutAct,
|
|
8549
|
+
disabled: busy || scale <= minScale,
|
|
8550
|
+
"aria-label": zoomOutLabel,
|
|
8551
|
+
children: /* @__PURE__ */ jsx(ZoomOut, { "aria-hidden": true })
|
|
8552
|
+
}
|
|
8553
|
+
),
|
|
8554
|
+
/* @__PURE__ */ jsx(
|
|
8555
|
+
Button,
|
|
8556
|
+
{
|
|
8557
|
+
type: "button",
|
|
8558
|
+
variant: "outline",
|
|
8559
|
+
size: "icon-sm",
|
|
8560
|
+
onClick: zoomInAct,
|
|
8561
|
+
disabled: busy || scale >= maxScale,
|
|
8562
|
+
"aria-label": zoomInLabel,
|
|
8563
|
+
children: /* @__PURE__ */ jsx(ZoomIn, { "aria-hidden": true })
|
|
8564
|
+
}
|
|
8565
|
+
),
|
|
8566
|
+
/* @__PURE__ */ jsx(
|
|
8567
|
+
Button,
|
|
8568
|
+
{
|
|
8569
|
+
type: "button",
|
|
8570
|
+
variant: "outline",
|
|
8571
|
+
size: "icon-sm",
|
|
8572
|
+
onClick: resetZoomAct,
|
|
8573
|
+
disabled: busy,
|
|
8574
|
+
"aria-label": resetZoomLabel,
|
|
8575
|
+
children: /* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true })
|
|
8576
|
+
}
|
|
8577
|
+
),
|
|
8578
|
+
/* @__PURE__ */ jsx(
|
|
8579
|
+
Button,
|
|
8580
|
+
{
|
|
8581
|
+
type: "button",
|
|
8582
|
+
variant: "outline",
|
|
8583
|
+
size: "icon-sm",
|
|
8584
|
+
onClick: fitToWidthAct,
|
|
8585
|
+
disabled: busy || pageCount === 0,
|
|
8586
|
+
"aria-label": fitWidthLabel,
|
|
8587
|
+
children: /* @__PURE__ */ jsx(Maximize2, { "aria-hidden": true })
|
|
8588
|
+
}
|
|
8589
|
+
),
|
|
8590
|
+
toolbarEndSlot
|
|
8591
|
+
]
|
|
8592
|
+
}
|
|
8593
|
+
),
|
|
8594
|
+
/* @__PURE__ */ jsx(
|
|
8595
|
+
"div",
|
|
8596
|
+
{
|
|
8597
|
+
ref: scrollRef,
|
|
8598
|
+
tabIndex: 0,
|
|
8599
|
+
onKeyDown: handleKeyDown,
|
|
8600
|
+
className: "relative min-h-[240px] flex-1 overflow-auto outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
8601
|
+
"aria-busy": busy,
|
|
8602
|
+
"aria-label": busy ? loadingLabel : "PDF pages",
|
|
8603
|
+
children: busy || pagesMap === null ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground p-6 text-sm", children: loadingLabel }) : /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center gap-4 pb-8 pt-2", children: layouts.map((layout) => {
|
|
8604
|
+
const pg = pagesMap.get(layout.pageNumber);
|
|
8605
|
+
const visible = (ratios[layout.pageNumber] ?? 0) >= 1e-3;
|
|
8606
|
+
return pg ? /* @__PURE__ */ jsx(
|
|
8607
|
+
PdfPageCanvas,
|
|
8608
|
+
{
|
|
8609
|
+
page: pg,
|
|
8610
|
+
layout,
|
|
8611
|
+
scale,
|
|
8612
|
+
visible,
|
|
8613
|
+
pageClassName
|
|
8614
|
+
},
|
|
8615
|
+
layout.pageNumber
|
|
8616
|
+
) : null;
|
|
8617
|
+
}) })
|
|
8618
|
+
}
|
|
8619
|
+
)
|
|
8620
|
+
]
|
|
8621
|
+
}
|
|
8622
|
+
);
|
|
8623
|
+
}
|
|
8624
|
+
var fullscreenDialogContentClass = "!max-w-none !w-screen !h-screen !p-0 !border-0 !bg-black/95 !rounded-none !top-0 !left-0 !translate-x-0 !translate-y-0 !gap-0 !shadow-none !flex !flex-col data-[state=open]:!zoom-in-100 data-[state=closed]:!zoom-out-100";
|
|
8625
|
+
function PdfViewerDialog({
|
|
8626
|
+
open,
|
|
8627
|
+
onOpenChange,
|
|
8628
|
+
src,
|
|
8629
|
+
workerSrc,
|
|
8630
|
+
documentOptions,
|
|
8631
|
+
trigger,
|
|
8632
|
+
title,
|
|
8633
|
+
labels,
|
|
8634
|
+
forwardedProps
|
|
8635
|
+
}) {
|
|
8636
|
+
const closeLabel = labels?.close ?? "Close";
|
|
8637
|
+
const dialogTitle = labels?.dialogTitle ?? title ?? "PDF document";
|
|
8638
|
+
const dialogDescription = labels?.dialogDescription ?? "Document viewer with zoom and page navigation.";
|
|
8639
|
+
const {
|
|
8640
|
+
className: forwardedClassName,
|
|
8641
|
+
toolbarClassName: forwardedToolbarClassName,
|
|
8642
|
+
...restForwarded
|
|
8643
|
+
} = forwardedProps ?? {};
|
|
8644
|
+
return /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange, children: [
|
|
8645
|
+
trigger ? /* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: trigger }) : null,
|
|
8646
|
+
/* @__PURE__ */ jsxs(
|
|
8647
|
+
DialogContent,
|
|
8648
|
+
{
|
|
8649
|
+
className: fullscreenDialogContentClass,
|
|
8650
|
+
showCloseButton: false,
|
|
8651
|
+
children: [
|
|
8652
|
+
/* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: dialogTitle }),
|
|
8653
|
+
/* @__PURE__ */ jsx(DialogDescription, { className: "sr-only", children: dialogDescription }),
|
|
8654
|
+
/* @__PURE__ */ jsx(
|
|
8655
|
+
PdfViewer,
|
|
8656
|
+
{
|
|
8657
|
+
...restForwarded,
|
|
8658
|
+
src,
|
|
8659
|
+
workerSrc,
|
|
8660
|
+
documentOptions,
|
|
8661
|
+
className: cn(
|
|
8662
|
+
"min-h-0 flex-1 rounded-none border-0 bg-transparent text-white",
|
|
8663
|
+
forwardedClassName
|
|
8664
|
+
),
|
|
8665
|
+
toolbarClassName: cn(
|
|
8666
|
+
"border-white/10 bg-black/80 text-white backdrop-blur",
|
|
8667
|
+
forwardedToolbarClassName
|
|
8668
|
+
),
|
|
8669
|
+
toolbarEndSlot: /* @__PURE__ */ jsx(
|
|
8670
|
+
Button,
|
|
8671
|
+
{
|
|
8672
|
+
type: "button",
|
|
8673
|
+
variant: "ghost",
|
|
8674
|
+
size: "icon-sm",
|
|
8675
|
+
className: "ml-auto text-white hover:bg-white/10 hover:text-white",
|
|
8676
|
+
onClick: () => onOpenChange(false),
|
|
8677
|
+
"aria-label": closeLabel,
|
|
8678
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-5", "aria-hidden": true })
|
|
8679
|
+
}
|
|
8680
|
+
)
|
|
8681
|
+
}
|
|
8682
|
+
)
|
|
8683
|
+
]
|
|
8684
|
+
}
|
|
8685
|
+
)
|
|
8686
|
+
] });
|
|
8687
|
+
}
|
|
8103
8688
|
|
|
8104
|
-
export { AvatarEditor, AvatarEditorDialog, BLOCKS_DATA_ENVIRONMENTS, Button, CalendarContext, CalendarSubscribeButton, CalendarView, CalendarWidget, CardInput, ChatRoomView, ChatSidebar, ChatSidebarContext, ChatSidebarProvider, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EnvironmentBanner, EnvironmentContext, EnvironmentDot, EnvironmentMiniBadge, EnvironmentSwitcher, EventDialog, EventRsvpBadge, LanguageContext, LanguageSwitcher, MiniCalendar, NotificationsContext, NotificationsWidget, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ScrollArea, ScrollBar, Slider, ThemeSwitcher, Toggle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, USAddressInput, UpcomingEvents, buttonVariants, cn, defaultLanguages, getEnvironmentDotClass, getEnvironmentLabel, isBlocksDataEnvironment, toggleVariants, useCalendarContext, useChatRoom, useChatSidebar, useDebouncedValue, useDebouncedValueStrict, useEnvironmentContext, useLanguageContext, useNotificationsContext };
|
|
8689
|
+
export { AvatarEditor, AvatarEditorDialog, BLOCKS_DATA_ENVIRONMENTS, Button, CalendarContext, CalendarSubscribeButton, CalendarView, CalendarWidget, CardInput, ChatRoomView, ChatSidebar, ChatSidebarContext, ChatSidebarProvider, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EnvironmentBanner, EnvironmentContext, EnvironmentDot, EnvironmentMiniBadge, EnvironmentSwitcher, EventDialog, EventRsvpBadge, LanguageContext, LanguageSwitcher, MiniCalendar, NotificationsContext, NotificationsWidget, PdfViewer, PdfViewerDialog, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ScrollArea, ScrollBar, Slider, ThemeSwitcher, Toggle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, USAddressInput, UpcomingEvents, buttonVariants, cn, defaultLanguages, getEnvironmentDotClass, getEnvironmentLabel, isBlocksDataEnvironment, toggleVariants, useCalendarContext, useChatRoom, useChatSidebar, useDebouncedValue, useDebouncedValueStrict, useEnvironmentContext, useLanguageContext, useNotificationsContext };
|
|
8105
8690
|
//# sourceMappingURL=index.js.map
|
|
8106
8691
|
//# sourceMappingURL=index.js.map
|