@sesionario/blocks 1.31.1 → 1.31.2

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/pdf.d.cts CHANGED
@@ -60,7 +60,8 @@ type PdfViewerDialogProps = {
60
60
  };
61
61
  /**
62
62
  * Drop-in dialog wrapper around {@link PdfViewer} using
63
- * {@link MediaViewerDialog} for the fullscreen-on-mobile shell.
63
+ * {@link MediaViewerDialog} for the fullscreen shell. Title and close live
64
+ * in the PDF toolbar (via `closeAction`) so chrome stays a single row.
64
65
  */
65
66
  declare function PdfViewerDialog({ open, onOpenChange, title, fileUrl, fileName, downloadUrl, workerSrc, initialPage, labels, }: PdfViewerDialogProps): React.JSX.Element;
66
67
 
package/dist/pdf.d.ts CHANGED
@@ -60,7 +60,8 @@ type PdfViewerDialogProps = {
60
60
  };
61
61
  /**
62
62
  * Drop-in dialog wrapper around {@link PdfViewer} using
63
- * {@link MediaViewerDialog} for the fullscreen-on-mobile shell.
63
+ * {@link MediaViewerDialog} for the fullscreen shell. Title and close live
64
+ * in the PDF toolbar (via `closeAction`) so chrome stays a single row.
64
65
  */
65
66
  declare function PdfViewerDialog({ open, onOpenChange, title, fileUrl, fileName, downloadUrl, workerSrc, initialPage, labels, }: PdfViewerDialogProps): React.JSX.Element;
66
67
 
package/dist/pdf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useState, useRef, useCallback, useEffect } from 'react';
2
2
  import { pdfjs, Document, Page, Thumbnail } from 'react-pdf';
3
- import { PanelLeftClose, PanelLeft, ChevronLeft, ChevronRight, ZoomOut, ZoomIn, RotateCw, Minimize2, Maximize2, Download, AlertTriangle, Loader2, X, XIcon } from 'lucide-react';
3
+ import { PanelLeftClose, PanelLeft, ChevronLeft, ChevronRight, ZoomOut, ZoomIn, RotateCw, Minimize2, Maximize2, Download, X, AlertTriangle, Loader2, XIcon } from 'lucide-react';
4
4
  import { clsx } from 'clsx';
5
5
  import { twMerge } from 'tailwind-merge';
6
6
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
@@ -444,10 +444,11 @@ function PdfViewer({
444
444
  const [numPages, setNumPages] = useState(0);
445
445
  const [pageNumber, setPageNumber] = useState(initialPage);
446
446
  const [zoomIndex, setZoomIndex] = useState(2);
447
- const [fitMode, setFitMode] = useState("width");
447
+ const [fitMode, setFitMode] = useState("page");
448
448
  const [rotation, setRotation] = useState(0);
449
449
  const [containerWidth, setContainerWidth] = useState(0);
450
450
  const [containerHeight, setContainerHeight] = useState(0);
451
+ const [pageNatural, setPageNatural] = useState(null);
451
452
  const [isFullscreen, setIsFullscreen] = useState(false);
452
453
  const [thumbsOpen, setThumbsOpen] = useState(false);
453
454
  const [loadError, setLoadError] = useState(false);
@@ -494,37 +495,57 @@ function PdfViewer({
494
495
  setPageNumber(initialPage);
495
496
  setPageDraft(String(initialPage));
496
497
  setZoomIndex(2);
497
- setFitMode("width");
498
+ setFitMode("page");
498
499
  setRotation(0);
499
500
  setNumPages(0);
501
+ setPageNatural(null);
500
502
  setLoadError(false);
501
503
  setThumbsOpen(false);
502
504
  reset();
503
505
  }, [fileUrl, initialPage, reset]);
504
506
  useEffect(() => {
505
507
  reset();
508
+ setPageNatural(null);
506
509
  }, [pageNumber, reset]);
510
+ const measureViewport = useCallback(() => {
511
+ const el = viewportRef.current;
512
+ if (!el) return;
513
+ const w = el.clientWidth;
514
+ const h = el.clientHeight;
515
+ if (w > 0) setContainerWidth(w);
516
+ if (h > 0) setContainerHeight(h);
517
+ }, []);
507
518
  useEffect(() => {
508
519
  if (!viewportRef.current) return;
509
520
  const el = viewportRef.current;
510
521
  const observer = new ResizeObserver((entries) => {
511
522
  const rect = entries[0]?.contentRect;
512
523
  if (!rect) return;
513
- setContainerWidth(rect.width);
514
- setContainerHeight(rect.height);
524
+ if (rect.width > 0) setContainerWidth(rect.width);
525
+ if (rect.height > 0) setContainerHeight(rect.height);
515
526
  });
516
527
  observer.observe(el);
517
- setContainerWidth(el.clientWidth);
518
- setContainerHeight(el.clientHeight);
519
- return () => observer.disconnect();
520
- }, []);
528
+ measureViewport();
529
+ const raf = requestAnimationFrame(() => {
530
+ measureViewport();
531
+ requestAnimationFrame(measureViewport);
532
+ });
533
+ return () => {
534
+ observer.disconnect();
535
+ cancelAnimationFrame(raf);
536
+ };
537
+ }, [measureViewport]);
538
+ useEffect(() => {
539
+ measureViewport();
540
+ }, [thumbsOpen, measureViewport]);
521
541
  useEffect(() => {
522
542
  function onFullscreenChange() {
523
543
  setIsFullscreen(document.fullscreenElement === shellRef.current);
544
+ requestAnimationFrame(measureViewport);
524
545
  }
525
546
  document.addEventListener("fullscreenchange", onFullscreenChange);
526
547
  return () => document.removeEventListener("fullscreenchange", onFullscreenChange);
527
- }, []);
548
+ }, [measureViewport]);
528
549
  useEffect(() => {
529
550
  function onKeyDown(e) {
530
551
  const target = e.target;
@@ -594,8 +615,20 @@ function PdfViewer({
594
615
  if (Number.isFinite(parsed)) goToPage(parsed);
595
616
  else setPageDraft(String(pageNumber));
596
617
  }
597
- const pageWidth = fitMode === "width" ? Math.max(containerWidth - 32, 240) * baseScale : void 0;
598
- const pageHeight = fitMode === "page" ? Math.max(containerHeight - 32, 240) * baseScale : void 0;
618
+ const PAD = 32;
619
+ const availW = Math.max(containerWidth - PAD, 240);
620
+ const availH = Math.max(containerHeight - PAD, 240);
621
+ const rotated = rotation % 180 !== 0 && pageNatural ? { width: pageNatural.height, height: pageNatural.width } : pageNatural;
622
+ let pageWidth;
623
+ if (fitMode === "width" || !rotated) {
624
+ pageWidth = availW * baseScale;
625
+ } else {
626
+ const scaleToFit = Math.min(
627
+ availW / rotated.width,
628
+ availH / rotated.height
629
+ );
630
+ pageWidth = rotated.width * scaleToFit * baseScale;
631
+ }
599
632
  const rawDownload = downloadUrl ?? fileUrl;
600
633
  const downloadHref = `${rawDownload}${rawDownload.includes("?") ? "&" : "?"}download=1`;
601
634
  const { scale: gestureScale, tx, ty } = transform;
@@ -810,7 +843,7 @@ function PdfViewer({
810
843
  "div",
811
844
  {
812
845
  ref: stageRef,
813
- className: "flex min-h-full touch-none items-start justify-center p-4",
846
+ className: "flex min-h-full min-w-full touch-none p-4",
814
847
  style: {
815
848
  transform: `translate(${tx}px, ${ty}px) scale(${gestureScale})`,
816
849
  transition
@@ -820,7 +853,7 @@ function PdfViewer({
820
853
  onPointerUp: handlers.onPointerUp,
821
854
  onPointerCancel: handlers.onPointerCancel,
822
855
  onTransitionEnd: clearSnapBack,
823
- children: /* @__PURE__ */ jsx(
856
+ children: /* @__PURE__ */ jsx("div", { className: "m-auto", children: /* @__PURE__ */ jsx(
824
857
  Document,
825
858
  {
826
859
  file: fileUrl,
@@ -830,6 +863,7 @@ function PdfViewer({
830
863
  const start = Math.min(Math.max(1, initialPage), pages);
831
864
  setPageNumber(start);
832
865
  setPageDraft(String(start));
866
+ setFitMode(pages === 1 ? "page" : "width");
833
867
  },
834
868
  onLoadError: () => setLoadError(true),
835
869
  loading: /* @__PURE__ */ jsx(LoadingState, { label: labels.loading ?? "Cargando PDF\u2026" }),
@@ -845,14 +879,19 @@ function PdfViewer({
845
879
  {
846
880
  pageNumber,
847
881
  width: pageWidth,
848
- height: pageHeight,
849
882
  rotate: rotation,
850
883
  renderTextLayer: true,
851
- renderAnnotationLayer: true
884
+ renderAnnotationLayer: true,
885
+ onLoadSuccess: (page) => {
886
+ setPageNatural({
887
+ width: page.originalWidth,
888
+ height: page.originalHeight
889
+ });
890
+ }
852
891
  }
853
892
  )
854
893
  }
855
- )
894
+ ) })
856
895
  }
857
896
  )
858
897
  }
@@ -966,7 +1005,9 @@ function MediaViewerDialog({
966
1005
  {
967
1006
  showCloseButton: false,
968
1007
  className: cn(
969
- "inset-0 flex h-dvh max-h-dvh w-screen max-w-none translate-x-0 translate-y-0 top-0 left-0 gap-0 overflow-hidden rounded-none border-0 p-0 shadow-none sm:max-w-none",
1008
+ // flex-col is required: without it the single child is a row item
1009
+ // sized to max-content (toolbar width) and the viewport collapses.
1010
+ "inset-0 flex flex-col h-dvh max-h-dvh w-screen max-w-none translate-x-0 translate-y-0 top-0 left-0 gap-0 overflow-hidden rounded-none border-0 p-0 shadow-none sm:max-w-none",
970
1011
  contentClassName,
971
1012
  className
972
1013
  ),
@@ -1000,31 +1041,43 @@ function PdfViewerDialog({
1000
1041
  labels
1001
1042
  }) {
1002
1043
  const viewerLabels = labels;
1044
+ const closeLabel = labels.close ?? "Cerrar";
1003
1045
  return /* @__PURE__ */ jsx(
1004
1046
  MediaViewerDialog,
1005
1047
  {
1006
1048
  open,
1007
1049
  onOpenChange,
1050
+ showCloseButton: false,
1008
1051
  labels: {
1009
- close: labels.close,
1052
+ close: closeLabel,
1010
1053
  title,
1011
1054
  description: labels.dialogDescription ?? title
1012
1055
  },
1013
- children: /* @__PURE__ */ jsxs("div", { className: "flex h-full min-h-0 flex-col pt-12", children: [
1014
- /* @__PURE__ */ jsx("div", { className: "border-b px-4 py-2 pr-14", children: /* @__PURE__ */ jsx("p", { className: "truncate text-sm font-medium", children: title }) }),
1015
- /* @__PURE__ */ jsx(
1016
- PdfViewer,
1017
- {
1018
- fileUrl,
1019
- fileName: fileName ?? title,
1020
- downloadUrl,
1021
- workerSrc,
1022
- initialPage,
1023
- labels: viewerLabels,
1024
- className: "min-h-0 flex-1"
1025
- }
1026
- )
1027
- ] })
1056
+ children: /* @__PURE__ */ jsx(
1057
+ PdfViewer,
1058
+ {
1059
+ fileUrl,
1060
+ fileName: fileName ?? title,
1061
+ downloadUrl,
1062
+ workerSrc,
1063
+ initialPage,
1064
+ labels: viewerLabels,
1065
+ className: "min-h-0 w-full min-w-0 flex-1",
1066
+ closeAction: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1067
+ /* @__PURE__ */ jsx(
1068
+ "button",
1069
+ {
1070
+ type: "button",
1071
+ onClick: () => onOpenChange(false),
1072
+ "aria-label": closeLabel,
1073
+ className: "inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md border bg-background text-foreground hover:bg-accent",
1074
+ children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
1075
+ }
1076
+ ),
1077
+ /* @__PURE__ */ jsx("span", { className: "max-w-[min(40vw,16rem)] truncate text-sm font-medium text-foreground", children: title })
1078
+ ] })
1079
+ }
1080
+ )
1028
1081
  }
1029
1082
  );
1030
1083
  }