@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.cjs
CHANGED
|
@@ -8131,6 +8131,591 @@ function USAddressInput({
|
|
|
8131
8131
|
] })
|
|
8132
8132
|
] });
|
|
8133
8133
|
}
|
|
8134
|
+
function defaultPageOf(page, total) {
|
|
8135
|
+
return `${page} / ${total}`;
|
|
8136
|
+
}
|
|
8137
|
+
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)`.";
|
|
8138
|
+
function buildGetDocumentArgs(src, documentOptions) {
|
|
8139
|
+
const rest = documentOptions ?? {};
|
|
8140
|
+
if (typeof src === "string") {
|
|
8141
|
+
return { url: src, ...rest };
|
|
8142
|
+
}
|
|
8143
|
+
return { data: src, ...rest };
|
|
8144
|
+
}
|
|
8145
|
+
function PdfPageCanvas({
|
|
8146
|
+
page,
|
|
8147
|
+
layout,
|
|
8148
|
+
scale,
|
|
8149
|
+
visible,
|
|
8150
|
+
pageClassName
|
|
8151
|
+
}) {
|
|
8152
|
+
const canvasRef = React2.useRef(null);
|
|
8153
|
+
const taskRef = React2.useRef(null);
|
|
8154
|
+
React2.useEffect(() => {
|
|
8155
|
+
if (!visible || !canvasRef.current) {
|
|
8156
|
+
taskRef.current?.cancel();
|
|
8157
|
+
taskRef.current = null;
|
|
8158
|
+
const c = canvasRef.current;
|
|
8159
|
+
if (c) {
|
|
8160
|
+
const ctx2 = c.getContext("2d");
|
|
8161
|
+
if (ctx2) {
|
|
8162
|
+
ctx2.setTransform(1, 0, 0, 1, 0, 0);
|
|
8163
|
+
ctx2.clearRect(0, 0, c.width, c.height);
|
|
8164
|
+
}
|
|
8165
|
+
}
|
|
8166
|
+
return;
|
|
8167
|
+
}
|
|
8168
|
+
const canvas = canvasRef.current;
|
|
8169
|
+
const ctx = canvas.getContext("2d");
|
|
8170
|
+
if (!ctx) return;
|
|
8171
|
+
const viewport = page.getViewport({ scale });
|
|
8172
|
+
canvas.width = viewport.width;
|
|
8173
|
+
canvas.height = viewport.height;
|
|
8174
|
+
const task = page.render({
|
|
8175
|
+
canvasContext: ctx,
|
|
8176
|
+
viewport,
|
|
8177
|
+
canvas
|
|
8178
|
+
});
|
|
8179
|
+
taskRef.current = task;
|
|
8180
|
+
task.promise.catch(() => {
|
|
8181
|
+
});
|
|
8182
|
+
return () => {
|
|
8183
|
+
task.cancel();
|
|
8184
|
+
if (taskRef.current === task) {
|
|
8185
|
+
taskRef.current = null;
|
|
8186
|
+
}
|
|
8187
|
+
};
|
|
8188
|
+
}, [page, visible, scale]);
|
|
8189
|
+
const w = layout.widthPt * scale;
|
|
8190
|
+
const h = layout.heightPt * scale;
|
|
8191
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8192
|
+
"div",
|
|
8193
|
+
{
|
|
8194
|
+
className: cn("relative flex justify-center bg-muted/40", pageClassName),
|
|
8195
|
+
style: { width: w, height: h },
|
|
8196
|
+
"data-page": layout.pageNumber,
|
|
8197
|
+
children: visible ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
8198
|
+
"canvas",
|
|
8199
|
+
{
|
|
8200
|
+
ref: canvasRef,
|
|
8201
|
+
className: "block max-h-full shadow-sm",
|
|
8202
|
+
"aria-hidden": "true"
|
|
8203
|
+
}
|
|
8204
|
+
) : null
|
|
8205
|
+
}
|
|
8206
|
+
);
|
|
8207
|
+
}
|
|
8208
|
+
function PdfViewer({
|
|
8209
|
+
src,
|
|
8210
|
+
workerSrc,
|
|
8211
|
+
documentOptions,
|
|
8212
|
+
initialPage = 1,
|
|
8213
|
+
initialScale = 1,
|
|
8214
|
+
minScale = 0.5,
|
|
8215
|
+
maxScale = 4,
|
|
8216
|
+
scaleStep = 0.2,
|
|
8217
|
+
enableKeyboardShortcuts = true,
|
|
8218
|
+
labels,
|
|
8219
|
+
onLoad,
|
|
8220
|
+
onError,
|
|
8221
|
+
onPageChange,
|
|
8222
|
+
onScaleChange,
|
|
8223
|
+
className,
|
|
8224
|
+
toolbarClassName,
|
|
8225
|
+
pageClassName,
|
|
8226
|
+
toolbarEndSlot
|
|
8227
|
+
}) {
|
|
8228
|
+
const mergedLabels = labels ?? {};
|
|
8229
|
+
const toolbarLabel = mergedLabels.toolbar ?? "PDF controls";
|
|
8230
|
+
const loadingLabel = mergedLabels.loading ?? "Loading PDF\u2026";
|
|
8231
|
+
const workerErrorMessage = mergedLabels.workerMissing ?? DEFAULT_WORKER_MSG;
|
|
8232
|
+
const errorLabelFallback = mergedLabels.error ?? "Failed to load PDF";
|
|
8233
|
+
const toolbarId = React2.useId();
|
|
8234
|
+
const pageInputId = `${toolbarId}-page`;
|
|
8235
|
+
const scrollRef = React2.useRef(null);
|
|
8236
|
+
const observerRef = React2.useRef(null);
|
|
8237
|
+
const lastReportedPage = React2.useRef(0);
|
|
8238
|
+
const loadedPdfRef = React2.useRef(null);
|
|
8239
|
+
const [loadError, setLoadError] = React2.useState(null);
|
|
8240
|
+
const [busy, setBusy] = React2.useState(false);
|
|
8241
|
+
const [layouts, setLayouts] = React2.useState([]);
|
|
8242
|
+
const [pagesMap, setPagesMap] = React2.useState(
|
|
8243
|
+
null
|
|
8244
|
+
);
|
|
8245
|
+
const [scale, setScale] = React2.useState(initialScale);
|
|
8246
|
+
const [ratios, setRatios] = React2.useState({});
|
|
8247
|
+
const [pageInput, setPageInput] = React2.useState(String(initialPage));
|
|
8248
|
+
const baselineScaleRef = React2.useRef(initialScale);
|
|
8249
|
+
React2.useEffect(() => {
|
|
8250
|
+
baselineScaleRef.current = initialScale;
|
|
8251
|
+
}, [initialScale]);
|
|
8252
|
+
const pageOfFormatter = mergedLabels.pageOf ?? defaultPageOf;
|
|
8253
|
+
const resolvedGoToLabel = mergedLabels.goToPage ?? "Go to page";
|
|
8254
|
+
const zoomInLabel = mergedLabels.zoomIn ?? "Zoom in";
|
|
8255
|
+
const zoomOutLabel = mergedLabels.zoomOut ?? "Zoom out";
|
|
8256
|
+
const resetZoomLabel = mergedLabels.resetZoom ?? "Reset zoom";
|
|
8257
|
+
const fitWidthLabel = mergedLabels.fitToWidth ?? "Fit to width";
|
|
8258
|
+
const pageCount = layouts.length;
|
|
8259
|
+
const currentVisiblePage = React2.useMemo(() => {
|
|
8260
|
+
let bestPage = 1;
|
|
8261
|
+
let bestRatio = -1;
|
|
8262
|
+
for (const layout of layouts) {
|
|
8263
|
+
const r2 = ratios[layout.pageNumber] ?? 0;
|
|
8264
|
+
if (r2 > bestRatio) {
|
|
8265
|
+
bestRatio = r2;
|
|
8266
|
+
bestPage = layout.pageNumber;
|
|
8267
|
+
}
|
|
8268
|
+
}
|
|
8269
|
+
return bestRatio >= 0.01 ? bestPage : 1;
|
|
8270
|
+
}, [layouts, ratios]);
|
|
8271
|
+
const clampScaleValue = React2.useCallback(
|
|
8272
|
+
(v) => Math.min(maxScale, Math.max(minScale, v)),
|
|
8273
|
+
[minScale, maxScale]
|
|
8274
|
+
);
|
|
8275
|
+
const zoomInAct = React2.useCallback(() => {
|
|
8276
|
+
setScale((prev) => {
|
|
8277
|
+
const c = clampScaleValue(prev + scaleStep);
|
|
8278
|
+
onScaleChange?.(c);
|
|
8279
|
+
return c;
|
|
8280
|
+
});
|
|
8281
|
+
}, [clampScaleValue, onScaleChange, scaleStep]);
|
|
8282
|
+
const zoomOutAct = React2.useCallback(() => {
|
|
8283
|
+
setScale((prev) => {
|
|
8284
|
+
const c = clampScaleValue(prev - scaleStep);
|
|
8285
|
+
onScaleChange?.(c);
|
|
8286
|
+
return c;
|
|
8287
|
+
});
|
|
8288
|
+
}, [clampScaleValue, onScaleChange, scaleStep]);
|
|
8289
|
+
const resetZoomAct = React2.useCallback(() => {
|
|
8290
|
+
const c = clampScaleValue(baselineScaleRef.current);
|
|
8291
|
+
setScale(c);
|
|
8292
|
+
onScaleChange?.(c);
|
|
8293
|
+
}, [clampScaleValue, onScaleChange]);
|
|
8294
|
+
const fitToWidthAct = React2.useCallback(() => {
|
|
8295
|
+
const root = scrollRef.current;
|
|
8296
|
+
if (!root || layouts.length === 0) return;
|
|
8297
|
+
const avail = Math.max(root.clientWidth - 32, 120);
|
|
8298
|
+
const maxW = Math.max(...layouts.map((l) => l.widthPt), 1);
|
|
8299
|
+
const next = clampScaleValue(avail / maxW);
|
|
8300
|
+
setScale(next);
|
|
8301
|
+
onScaleChange?.(next);
|
|
8302
|
+
}, [clampScaleValue, layouts, onScaleChange]);
|
|
8303
|
+
React2.useEffect(() => {
|
|
8304
|
+
setPageInput(String(currentVisiblePage));
|
|
8305
|
+
if (lastReportedPage.current !== currentVisiblePage) {
|
|
8306
|
+
lastReportedPage.current = currentVisiblePage;
|
|
8307
|
+
onPageChange?.(currentVisiblePage);
|
|
8308
|
+
}
|
|
8309
|
+
}, [currentVisiblePage, onPageChange]);
|
|
8310
|
+
const scrollToPage = React2.useCallback((pageNum) => {
|
|
8311
|
+
const root = scrollRef.current;
|
|
8312
|
+
if (!root || pageNum < 1) return;
|
|
8313
|
+
const el = root.querySelector(`[data-page="${pageNum}"]`);
|
|
8314
|
+
if (el instanceof HTMLElement) {
|
|
8315
|
+
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
8316
|
+
}
|
|
8317
|
+
}, []);
|
|
8318
|
+
React2.useEffect(() => {
|
|
8319
|
+
if (!busy && pagesMap && pageCount > 0) {
|
|
8320
|
+
const p = Math.min(Math.max(1, initialPage), pageCount);
|
|
8321
|
+
requestAnimationFrame(() => scrollToPage(p));
|
|
8322
|
+
}
|
|
8323
|
+
}, [busy, pagesMap, pageCount, initialPage, scrollToPage]);
|
|
8324
|
+
const loadKey = React2.useMemo(() => {
|
|
8325
|
+
if (typeof src === "string") return src;
|
|
8326
|
+
if (src instanceof ArrayBuffer) return `ab:${src.byteLength}`;
|
|
8327
|
+
return `ua:${src.byteLength}:${src.byteOffset}:${src.buffer.byteLength}`;
|
|
8328
|
+
}, [src]);
|
|
8329
|
+
React2.useEffect(() => {
|
|
8330
|
+
let cancelled = false;
|
|
8331
|
+
let activeDoc = null;
|
|
8332
|
+
setLoadError(null);
|
|
8333
|
+
if (loadedPdfRef.current) {
|
|
8334
|
+
void loadedPdfRef.current.destroy();
|
|
8335
|
+
loadedPdfRef.current = null;
|
|
8336
|
+
}
|
|
8337
|
+
setLayouts([]);
|
|
8338
|
+
setPagesMap(null);
|
|
8339
|
+
setRatios({});
|
|
8340
|
+
const trimmedWorker = workerSrc?.trim?.() ?? "";
|
|
8341
|
+
if (!trimmedWorker) {
|
|
8342
|
+
setLoadError(workerErrorMessage);
|
|
8343
|
+
onError?.(new Error(workerErrorMessage));
|
|
8344
|
+
return () => {
|
|
8345
|
+
cancelled = true;
|
|
8346
|
+
};
|
|
8347
|
+
}
|
|
8348
|
+
void (async () => {
|
|
8349
|
+
try {
|
|
8350
|
+
setBusy(true);
|
|
8351
|
+
const pdfjs = await import('pdfjs-dist');
|
|
8352
|
+
if (cancelled) return;
|
|
8353
|
+
pdfjs.GlobalWorkerOptions.workerSrc = trimmedWorker;
|
|
8354
|
+
const loadingTask = pdfjs.getDocument(
|
|
8355
|
+
buildGetDocumentArgs(src, documentOptions)
|
|
8356
|
+
);
|
|
8357
|
+
activeDoc = await loadingTask.promise;
|
|
8358
|
+
if (cancelled) {
|
|
8359
|
+
void activeDoc.destroy();
|
|
8360
|
+
activeDoc = null;
|
|
8361
|
+
return;
|
|
8362
|
+
}
|
|
8363
|
+
const layoutsLocal = [];
|
|
8364
|
+
const mapLocal = /* @__PURE__ */ new Map();
|
|
8365
|
+
for (let p = 1; p <= activeDoc.numPages; p++) {
|
|
8366
|
+
const page = await activeDoc.getPage(p);
|
|
8367
|
+
mapLocal.set(p, page);
|
|
8368
|
+
const viewport = page.getViewport({ scale: 1 });
|
|
8369
|
+
layoutsLocal.push({
|
|
8370
|
+
pageNumber: p,
|
|
8371
|
+
widthPt: viewport.width,
|
|
8372
|
+
heightPt: viewport.height
|
|
8373
|
+
});
|
|
8374
|
+
}
|
|
8375
|
+
if (cancelled) {
|
|
8376
|
+
void activeDoc.destroy();
|
|
8377
|
+
activeDoc = null;
|
|
8378
|
+
return;
|
|
8379
|
+
}
|
|
8380
|
+
onLoad?.(activeDoc);
|
|
8381
|
+
loadedPdfRef.current = activeDoc;
|
|
8382
|
+
setLayouts(layoutsLocal);
|
|
8383
|
+
setPagesMap(mapLocal);
|
|
8384
|
+
activeDoc = null;
|
|
8385
|
+
} catch (e) {
|
|
8386
|
+
const err = e instanceof Error ? e : new Error(String(e));
|
|
8387
|
+
if (!cancelled) {
|
|
8388
|
+
setLoadError(errorLabelFallback);
|
|
8389
|
+
onError?.(err);
|
|
8390
|
+
}
|
|
8391
|
+
if (activeDoc) {
|
|
8392
|
+
void activeDoc.destroy();
|
|
8393
|
+
activeDoc = null;
|
|
8394
|
+
}
|
|
8395
|
+
} finally {
|
|
8396
|
+
if (!cancelled) setBusy(false);
|
|
8397
|
+
}
|
|
8398
|
+
})();
|
|
8399
|
+
return () => {
|
|
8400
|
+
cancelled = true;
|
|
8401
|
+
if (observerRef.current) {
|
|
8402
|
+
observerRef.current.disconnect();
|
|
8403
|
+
observerRef.current = null;
|
|
8404
|
+
}
|
|
8405
|
+
if (activeDoc) {
|
|
8406
|
+
void activeDoc.destroy();
|
|
8407
|
+
}
|
|
8408
|
+
if (loadedPdfRef.current) {
|
|
8409
|
+
void loadedPdfRef.current.destroy();
|
|
8410
|
+
loadedPdfRef.current = null;
|
|
8411
|
+
}
|
|
8412
|
+
};
|
|
8413
|
+
}, [workerSrc, loadKey, documentOptions]);
|
|
8414
|
+
React2.useEffect(() => {
|
|
8415
|
+
setScale(clampScaleValue(initialScale));
|
|
8416
|
+
}, [initialScale, clampScaleValue]);
|
|
8417
|
+
React2.useEffect(() => {
|
|
8418
|
+
if (layouts.length === 0) return;
|
|
8419
|
+
const frame = requestAnimationFrame(() => {
|
|
8420
|
+
const root = scrollRef.current;
|
|
8421
|
+
if (!root) return;
|
|
8422
|
+
if (observerRef.current) {
|
|
8423
|
+
observerRef.current.disconnect();
|
|
8424
|
+
}
|
|
8425
|
+
const io = new IntersectionObserver(
|
|
8426
|
+
(entries) => {
|
|
8427
|
+
setRatios((prev) => {
|
|
8428
|
+
const next = { ...prev };
|
|
8429
|
+
for (const e of entries) {
|
|
8430
|
+
const tgt = e.target;
|
|
8431
|
+
const p = Number(tgt.dataset.page);
|
|
8432
|
+
if (Number.isFinite(p)) next[p] = e.intersectionRatio;
|
|
8433
|
+
}
|
|
8434
|
+
return next;
|
|
8435
|
+
});
|
|
8436
|
+
},
|
|
8437
|
+
{
|
|
8438
|
+
root,
|
|
8439
|
+
rootMargin: "200px 0px",
|
|
8440
|
+
threshold: [0, 0.05, 0.25, 0.5, 0.75, 1]
|
|
8441
|
+
}
|
|
8442
|
+
);
|
|
8443
|
+
observerRef.current = io;
|
|
8444
|
+
root.querySelectorAll("[data-page]").forEach((el) => io.observe(el));
|
|
8445
|
+
});
|
|
8446
|
+
return () => {
|
|
8447
|
+
cancelAnimationFrame(frame);
|
|
8448
|
+
if (observerRef.current) {
|
|
8449
|
+
observerRef.current.disconnect();
|
|
8450
|
+
observerRef.current = null;
|
|
8451
|
+
}
|
|
8452
|
+
};
|
|
8453
|
+
}, [layouts]);
|
|
8454
|
+
const handleSubmitPage = React2.useCallback(() => {
|
|
8455
|
+
const n = Number.parseInt(pageInput, 10);
|
|
8456
|
+
if (!Number.isFinite(n) || pageCount === 0) return;
|
|
8457
|
+
const clamped = Math.min(Math.max(1, n), pageCount);
|
|
8458
|
+
scrollToPage(clamped);
|
|
8459
|
+
setPageInput(String(clamped));
|
|
8460
|
+
}, [pageInput, pageCount, scrollToPage]);
|
|
8461
|
+
const handleKeyDown = React2.useCallback(
|
|
8462
|
+
(e) => {
|
|
8463
|
+
if (!enableKeyboardShortcuts) return;
|
|
8464
|
+
if (e.target !== e.currentTarget && e.target instanceof HTMLInputElement) {
|
|
8465
|
+
return;
|
|
8466
|
+
}
|
|
8467
|
+
let handled = false;
|
|
8468
|
+
switch (e.key) {
|
|
8469
|
+
case "PageDown": {
|
|
8470
|
+
scrollToPage(Math.min(pageCount || 1, currentVisiblePage + 1));
|
|
8471
|
+
handled = true;
|
|
8472
|
+
break;
|
|
8473
|
+
}
|
|
8474
|
+
case "PageUp": {
|
|
8475
|
+
scrollToPage(Math.max(1, currentVisiblePage - 1));
|
|
8476
|
+
handled = true;
|
|
8477
|
+
break;
|
|
8478
|
+
}
|
|
8479
|
+
case "Home": {
|
|
8480
|
+
scrollToPage(1);
|
|
8481
|
+
handled = true;
|
|
8482
|
+
break;
|
|
8483
|
+
}
|
|
8484
|
+
case "End": {
|
|
8485
|
+
if (pageCount) scrollToPage(pageCount);
|
|
8486
|
+
handled = true;
|
|
8487
|
+
break;
|
|
8488
|
+
}
|
|
8489
|
+
case "+":
|
|
8490
|
+
case "=": {
|
|
8491
|
+
zoomInAct();
|
|
8492
|
+
handled = true;
|
|
8493
|
+
break;
|
|
8494
|
+
}
|
|
8495
|
+
case "-":
|
|
8496
|
+
case "_": {
|
|
8497
|
+
zoomOutAct();
|
|
8498
|
+
handled = true;
|
|
8499
|
+
break;
|
|
8500
|
+
}
|
|
8501
|
+
case "0": {
|
|
8502
|
+
resetZoomAct();
|
|
8503
|
+
handled = true;
|
|
8504
|
+
break;
|
|
8505
|
+
}
|
|
8506
|
+
}
|
|
8507
|
+
if (handled) {
|
|
8508
|
+
e.preventDefault();
|
|
8509
|
+
e.stopPropagation();
|
|
8510
|
+
}
|
|
8511
|
+
},
|
|
8512
|
+
[
|
|
8513
|
+
enableKeyboardShortcuts,
|
|
8514
|
+
pageCount,
|
|
8515
|
+
currentVisiblePage,
|
|
8516
|
+
scrollToPage,
|
|
8517
|
+
zoomInAct,
|
|
8518
|
+
zoomOutAct,
|
|
8519
|
+
resetZoomAct
|
|
8520
|
+
]
|
|
8521
|
+
);
|
|
8522
|
+
if (loadError) {
|
|
8523
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8524
|
+
"div",
|
|
8525
|
+
{
|
|
8526
|
+
className: cn("rounded-md border border-destructive/50 p-4", className),
|
|
8527
|
+
role: "alert",
|
|
8528
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm", children: loadError })
|
|
8529
|
+
}
|
|
8530
|
+
);
|
|
8531
|
+
}
|
|
8532
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8533
|
+
"div",
|
|
8534
|
+
{
|
|
8535
|
+
className: cn(
|
|
8536
|
+
"flex min-h-0 flex-col overflow-hidden rounded-md border",
|
|
8537
|
+
className
|
|
8538
|
+
),
|
|
8539
|
+
children: [
|
|
8540
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
8541
|
+
"div",
|
|
8542
|
+
{
|
|
8543
|
+
id: toolbarId,
|
|
8544
|
+
role: "toolbar",
|
|
8545
|
+
"aria-label": toolbarLabel,
|
|
8546
|
+
className: cn(
|
|
8547
|
+
"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",
|
|
8548
|
+
toolbarClassName
|
|
8549
|
+
),
|
|
8550
|
+
children: [
|
|
8551
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-xs tabular-nums sm:text-sm", children: busy || pagesMap === null ? "\u2014" : pageOfFormatter(currentVisiblePage, pageCount) }),
|
|
8552
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: pageInputId, className: "sr-only", children: resolvedGoToLabel }),
|
|
8553
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8554
|
+
"input",
|
|
8555
|
+
{
|
|
8556
|
+
id: pageInputId,
|
|
8557
|
+
type: "number",
|
|
8558
|
+
min: 1,
|
|
8559
|
+
max: Math.max(pageCount, 1),
|
|
8560
|
+
disabled: busy || pageCount === 0,
|
|
8561
|
+
className: "h-8 w-14 rounded-md border border-input bg-background px-2 text-sm tabular-nums",
|
|
8562
|
+
"aria-label": resolvedGoToLabel,
|
|
8563
|
+
value: pageInput,
|
|
8564
|
+
onChange: (ev) => setPageInput(ev.target.value),
|
|
8565
|
+
onKeyDown: (ev) => {
|
|
8566
|
+
if (ev.key === "Enter") {
|
|
8567
|
+
ev.preventDefault();
|
|
8568
|
+
handleSubmitPage();
|
|
8569
|
+
}
|
|
8570
|
+
}
|
|
8571
|
+
}
|
|
8572
|
+
),
|
|
8573
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8574
|
+
Button,
|
|
8575
|
+
{
|
|
8576
|
+
type: "button",
|
|
8577
|
+
variant: "outline",
|
|
8578
|
+
size: "icon-sm",
|
|
8579
|
+
onClick: zoomOutAct,
|
|
8580
|
+
disabled: busy || scale <= minScale,
|
|
8581
|
+
"aria-label": zoomOutLabel,
|
|
8582
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ZoomOut, { "aria-hidden": true })
|
|
8583
|
+
}
|
|
8584
|
+
),
|
|
8585
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8586
|
+
Button,
|
|
8587
|
+
{
|
|
8588
|
+
type: "button",
|
|
8589
|
+
variant: "outline",
|
|
8590
|
+
size: "icon-sm",
|
|
8591
|
+
onClick: zoomInAct,
|
|
8592
|
+
disabled: busy || scale >= maxScale,
|
|
8593
|
+
"aria-label": zoomInLabel,
|
|
8594
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ZoomIn, { "aria-hidden": true })
|
|
8595
|
+
}
|
|
8596
|
+
),
|
|
8597
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8598
|
+
Button,
|
|
8599
|
+
{
|
|
8600
|
+
type: "button",
|
|
8601
|
+
variant: "outline",
|
|
8602
|
+
size: "icon-sm",
|
|
8603
|
+
onClick: resetZoomAct,
|
|
8604
|
+
disabled: busy,
|
|
8605
|
+
"aria-label": resetZoomLabel,
|
|
8606
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { "aria-hidden": true })
|
|
8607
|
+
}
|
|
8608
|
+
),
|
|
8609
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8610
|
+
Button,
|
|
8611
|
+
{
|
|
8612
|
+
type: "button",
|
|
8613
|
+
variant: "outline",
|
|
8614
|
+
size: "icon-sm",
|
|
8615
|
+
onClick: fitToWidthAct,
|
|
8616
|
+
disabled: busy || pageCount === 0,
|
|
8617
|
+
"aria-label": fitWidthLabel,
|
|
8618
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Maximize2, { "aria-hidden": true })
|
|
8619
|
+
}
|
|
8620
|
+
),
|
|
8621
|
+
toolbarEndSlot
|
|
8622
|
+
]
|
|
8623
|
+
}
|
|
8624
|
+
),
|
|
8625
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8626
|
+
"div",
|
|
8627
|
+
{
|
|
8628
|
+
ref: scrollRef,
|
|
8629
|
+
tabIndex: 0,
|
|
8630
|
+
onKeyDown: handleKeyDown,
|
|
8631
|
+
className: "relative min-h-[240px] flex-1 overflow-auto outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
8632
|
+
"aria-busy": busy,
|
|
8633
|
+
"aria-label": busy ? loadingLabel : "PDF pages",
|
|
8634
|
+
children: busy || pagesMap === null ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground p-6 text-sm", children: loadingLabel }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center gap-4 pb-8 pt-2", children: layouts.map((layout) => {
|
|
8635
|
+
const pg = pagesMap.get(layout.pageNumber);
|
|
8636
|
+
const visible = (ratios[layout.pageNumber] ?? 0) >= 1e-3;
|
|
8637
|
+
return pg ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
8638
|
+
PdfPageCanvas,
|
|
8639
|
+
{
|
|
8640
|
+
page: pg,
|
|
8641
|
+
layout,
|
|
8642
|
+
scale,
|
|
8643
|
+
visible,
|
|
8644
|
+
pageClassName
|
|
8645
|
+
},
|
|
8646
|
+
layout.pageNumber
|
|
8647
|
+
) : null;
|
|
8648
|
+
}) })
|
|
8649
|
+
}
|
|
8650
|
+
)
|
|
8651
|
+
]
|
|
8652
|
+
}
|
|
8653
|
+
);
|
|
8654
|
+
}
|
|
8655
|
+
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";
|
|
8656
|
+
function PdfViewerDialog({
|
|
8657
|
+
open,
|
|
8658
|
+
onOpenChange,
|
|
8659
|
+
src,
|
|
8660
|
+
workerSrc,
|
|
8661
|
+
documentOptions,
|
|
8662
|
+
trigger,
|
|
8663
|
+
title,
|
|
8664
|
+
labels,
|
|
8665
|
+
forwardedProps
|
|
8666
|
+
}) {
|
|
8667
|
+
const closeLabel = labels?.close ?? "Close";
|
|
8668
|
+
const dialogTitle = labels?.dialogTitle ?? title ?? "PDF document";
|
|
8669
|
+
const dialogDescription = labels?.dialogDescription ?? "Document viewer with zoom and page navigation.";
|
|
8670
|
+
const {
|
|
8671
|
+
className: forwardedClassName,
|
|
8672
|
+
toolbarClassName: forwardedToolbarClassName,
|
|
8673
|
+
...restForwarded
|
|
8674
|
+
} = forwardedProps ?? {};
|
|
8675
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Dialog, { open, onOpenChange, children: [
|
|
8676
|
+
trigger ? /* @__PURE__ */ jsxRuntime.jsx(DialogTrigger, { asChild: true, children: trigger }) : null,
|
|
8677
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
8678
|
+
DialogContent,
|
|
8679
|
+
{
|
|
8680
|
+
className: fullscreenDialogContentClass,
|
|
8681
|
+
showCloseButton: false,
|
|
8682
|
+
children: [
|
|
8683
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "sr-only", children: dialogTitle }),
|
|
8684
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogDescription, { className: "sr-only", children: dialogDescription }),
|
|
8685
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8686
|
+
PdfViewer,
|
|
8687
|
+
{
|
|
8688
|
+
...restForwarded,
|
|
8689
|
+
src,
|
|
8690
|
+
workerSrc,
|
|
8691
|
+
documentOptions,
|
|
8692
|
+
className: cn(
|
|
8693
|
+
"min-h-0 flex-1 rounded-none border-0 bg-transparent text-white",
|
|
8694
|
+
forwardedClassName
|
|
8695
|
+
),
|
|
8696
|
+
toolbarClassName: cn(
|
|
8697
|
+
"border-white/10 bg-black/80 text-white backdrop-blur",
|
|
8698
|
+
forwardedToolbarClassName
|
|
8699
|
+
),
|
|
8700
|
+
toolbarEndSlot: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8701
|
+
Button,
|
|
8702
|
+
{
|
|
8703
|
+
type: "button",
|
|
8704
|
+
variant: "ghost",
|
|
8705
|
+
size: "icon-sm",
|
|
8706
|
+
className: "ml-auto text-white hover:bg-white/10 hover:text-white",
|
|
8707
|
+
onClick: () => onOpenChange(false),
|
|
8708
|
+
"aria-label": closeLabel,
|
|
8709
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "size-5", "aria-hidden": true })
|
|
8710
|
+
}
|
|
8711
|
+
)
|
|
8712
|
+
}
|
|
8713
|
+
)
|
|
8714
|
+
]
|
|
8715
|
+
}
|
|
8716
|
+
)
|
|
8717
|
+
] });
|
|
8718
|
+
}
|
|
8134
8719
|
|
|
8135
8720
|
exports.AvatarEditor = AvatarEditor;
|
|
8136
8721
|
exports.AvatarEditorDialog = AvatarEditorDialog;
|
|
@@ -8192,6 +8777,8 @@ exports.LanguageSwitcher = LanguageSwitcher;
|
|
|
8192
8777
|
exports.MiniCalendar = MiniCalendar;
|
|
8193
8778
|
exports.NotificationsContext = NotificationsContext;
|
|
8194
8779
|
exports.NotificationsWidget = NotificationsWidget;
|
|
8780
|
+
exports.PdfViewer = PdfViewer;
|
|
8781
|
+
exports.PdfViewerDialog = PdfViewerDialog;
|
|
8195
8782
|
exports.Popover = Popover;
|
|
8196
8783
|
exports.PopoverAnchor = PopoverAnchor;
|
|
8197
8784
|
exports.PopoverContent = PopoverContent;
|