@sesionario/blocks 1.6.0 → 1.8.0
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 +360 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +361 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9,6 +9,7 @@ var classVarianceAuthority = require('class-variance-authority');
|
|
|
9
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
10
10
|
var AlertDialogPrimitive = require('@radix-ui/react-alert-dialog');
|
|
11
11
|
var reactSlot = require('@radix-ui/react-slot');
|
|
12
|
+
var reactDom = require('react-dom');
|
|
12
13
|
var nextThemes = require('next-themes');
|
|
13
14
|
var framerMotion = require('framer-motion');
|
|
14
15
|
var DropdownMenuPrimitive = require('@radix-ui/react-dropdown-menu');
|
|
@@ -455,6 +456,363 @@ function ConfirmDestructiveDialog({
|
|
|
455
456
|
] })
|
|
456
457
|
] }) });
|
|
457
458
|
}
|
|
459
|
+
var COLLAPSED_MAX_HEIGHT_REM = 11;
|
|
460
|
+
function ExpandableText({
|
|
461
|
+
children,
|
|
462
|
+
expandLabel,
|
|
463
|
+
collapseLabel,
|
|
464
|
+
className,
|
|
465
|
+
textClassName
|
|
466
|
+
}) {
|
|
467
|
+
const [expanded, setExpanded] = React6.useState(false);
|
|
468
|
+
const [overflowing, setOverflowing] = React6.useState(false);
|
|
469
|
+
const contentRef = React6.useRef(null);
|
|
470
|
+
React6.useEffect(() => {
|
|
471
|
+
setExpanded(false);
|
|
472
|
+
}, [children]);
|
|
473
|
+
React6.useLayoutEffect(() => {
|
|
474
|
+
const el = contentRef.current;
|
|
475
|
+
if (!el) return;
|
|
476
|
+
const measure = () => {
|
|
477
|
+
const rootFontSize = Number.parseFloat(
|
|
478
|
+
getComputedStyle(document.documentElement).fontSize
|
|
479
|
+
);
|
|
480
|
+
const maxPx = COLLAPSED_MAX_HEIGHT_REM * (rootFontSize || 16);
|
|
481
|
+
setOverflowing(el.scrollHeight > maxPx + 1);
|
|
482
|
+
};
|
|
483
|
+
measure();
|
|
484
|
+
const observer = new ResizeObserver(measure);
|
|
485
|
+
observer.observe(el);
|
|
486
|
+
return () => observer.disconnect();
|
|
487
|
+
}, [children]);
|
|
488
|
+
const collapsed = !expanded && overflowing;
|
|
489
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("space-y-1", className), children: [
|
|
490
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
491
|
+
"div",
|
|
492
|
+
{
|
|
493
|
+
className: cn(
|
|
494
|
+
collapsed && "max-h-[11rem] overflow-hidden scroll-fade-b"
|
|
495
|
+
),
|
|
496
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
497
|
+
"p",
|
|
498
|
+
{
|
|
499
|
+
ref: contentRef,
|
|
500
|
+
className: cn(
|
|
501
|
+
"whitespace-pre-wrap text-sm leading-relaxed",
|
|
502
|
+
textClassName
|
|
503
|
+
),
|
|
504
|
+
children
|
|
505
|
+
}
|
|
506
|
+
)
|
|
507
|
+
}
|
|
508
|
+
),
|
|
509
|
+
overflowing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
510
|
+
"button",
|
|
511
|
+
{
|
|
512
|
+
type: "button",
|
|
513
|
+
className: "text-sm font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 rounded-sm",
|
|
514
|
+
"aria-expanded": expanded,
|
|
515
|
+
onClick: () => setExpanded((prev) => !prev),
|
|
516
|
+
children: expanded ? collapseLabel : expandLabel
|
|
517
|
+
}
|
|
518
|
+
) : null
|
|
519
|
+
] });
|
|
520
|
+
}
|
|
521
|
+
var MIN_SCALE = 1;
|
|
522
|
+
var MAX_SCALE = 4;
|
|
523
|
+
var DOUBLE_TAP_MS = 300;
|
|
524
|
+
var IDENTITY = { scale: 1, tx: 0, ty: 0 };
|
|
525
|
+
function clamp(value, min, max) {
|
|
526
|
+
return Math.min(max, Math.max(min, value));
|
|
527
|
+
}
|
|
528
|
+
function zoomToward(prev, nextScale, originX, originY) {
|
|
529
|
+
const scale = clamp(nextScale, MIN_SCALE, MAX_SCALE);
|
|
530
|
+
if (scale === MIN_SCALE) return IDENTITY;
|
|
531
|
+
const ratio = scale / prev.scale;
|
|
532
|
+
return {
|
|
533
|
+
scale,
|
|
534
|
+
tx: originX - (originX - prev.tx) * ratio,
|
|
535
|
+
ty: originY - (originY - prev.ty) * ratio
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
function pointerDistance(a, b) {
|
|
539
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
540
|
+
}
|
|
541
|
+
function ImageLightbox({
|
|
542
|
+
images,
|
|
543
|
+
index,
|
|
544
|
+
onIndexChange,
|
|
545
|
+
onClose,
|
|
546
|
+
labels
|
|
547
|
+
}) {
|
|
548
|
+
const ariaLabel = labels?.ariaLabel ?? "Visor de im\xE1genes";
|
|
549
|
+
const closeLabel = labels?.close ?? "Cerrar";
|
|
550
|
+
const previousLabel = labels?.previous ?? "Anterior";
|
|
551
|
+
const nextLabel = labels?.next ?? "Siguiente";
|
|
552
|
+
const hasMultiple = images.length > 1;
|
|
553
|
+
const [transform, setTransform] = React6.useState(IDENTITY);
|
|
554
|
+
const transformRef = React6.useRef(transform);
|
|
555
|
+
transformRef.current = transform;
|
|
556
|
+
const stageRef = React6.useRef(null);
|
|
557
|
+
const pointersRef = React6.useRef(/* @__PURE__ */ new Map());
|
|
558
|
+
const pinchStartRef = React6.useRef(null);
|
|
559
|
+
const panRef = React6.useRef(null);
|
|
560
|
+
const lastTapRef = React6.useRef(
|
|
561
|
+
null
|
|
562
|
+
);
|
|
563
|
+
const resetZoom = React6.useCallback(() => {
|
|
564
|
+
setTransform(IDENTITY);
|
|
565
|
+
}, []);
|
|
566
|
+
React6.useEffect(() => {
|
|
567
|
+
resetZoom();
|
|
568
|
+
}, [index, images[index], resetZoom]);
|
|
569
|
+
function goPrev() {
|
|
570
|
+
onIndexChange((index - 1 + images.length) % images.length);
|
|
571
|
+
}
|
|
572
|
+
function goNext() {
|
|
573
|
+
onIndexChange((index + 1) % images.length);
|
|
574
|
+
}
|
|
575
|
+
React6.useEffect(() => {
|
|
576
|
+
function handleKeyDown(e) {
|
|
577
|
+
if (e.key === "Escape") {
|
|
578
|
+
onClose();
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (!hasMultiple) return;
|
|
582
|
+
if (e.key === "ArrowLeft") {
|
|
583
|
+
onIndexChange((index - 1 + images.length) % images.length);
|
|
584
|
+
} else if (e.key === "ArrowRight") {
|
|
585
|
+
onIndexChange((index + 1) % images.length);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
589
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
590
|
+
}, [index, images.length, hasMultiple, onClose, onIndexChange]);
|
|
591
|
+
React6.useEffect(() => {
|
|
592
|
+
const previousOverflow = document.body.style.overflow;
|
|
593
|
+
document.body.style.overflow = "hidden";
|
|
594
|
+
return () => {
|
|
595
|
+
document.body.style.overflow = previousOverflow;
|
|
596
|
+
};
|
|
597
|
+
}, []);
|
|
598
|
+
const stageOrigin = React6.useCallback((clientX, clientY) => {
|
|
599
|
+
const stage = stageRef.current;
|
|
600
|
+
if (!stage) return { x: 0, y: 0 };
|
|
601
|
+
const rect = stage.getBoundingClientRect();
|
|
602
|
+
return {
|
|
603
|
+
x: clientX - rect.left - rect.width / 2,
|
|
604
|
+
y: clientY - rect.top - rect.height / 2
|
|
605
|
+
};
|
|
606
|
+
}, []);
|
|
607
|
+
React6.useEffect(() => {
|
|
608
|
+
const stage = stageRef.current;
|
|
609
|
+
if (!stage) return;
|
|
610
|
+
const handleWheel = (e) => {
|
|
611
|
+
e.preventDefault();
|
|
612
|
+
e.stopPropagation();
|
|
613
|
+
const prev = transformRef.current;
|
|
614
|
+
const factor = e.deltaY > 0 ? 0.9 : 1.1;
|
|
615
|
+
const { x, y } = stageOrigin(e.clientX, e.clientY);
|
|
616
|
+
setTransform(zoomToward(prev, prev.scale * factor, x, y));
|
|
617
|
+
};
|
|
618
|
+
stage.addEventListener("wheel", handleWheel, { passive: false });
|
|
619
|
+
return () => stage.removeEventListener("wheel", handleWheel);
|
|
620
|
+
}, [stageOrigin]);
|
|
621
|
+
function beginPinch() {
|
|
622
|
+
const pts = [...pointersRef.current.values()];
|
|
623
|
+
const [a, b] = pts;
|
|
624
|
+
if (!a || !b) return;
|
|
625
|
+
const midX = (a.x + b.x) / 2;
|
|
626
|
+
const midY = (a.y + b.y) / 2;
|
|
627
|
+
const { x, y } = stageOrigin(midX, midY);
|
|
628
|
+
pinchStartRef.current = {
|
|
629
|
+
distance: Math.max(pointerDistance(a, b), 1),
|
|
630
|
+
originX: x,
|
|
631
|
+
originY: y,
|
|
632
|
+
transform: { ...transformRef.current }
|
|
633
|
+
};
|
|
634
|
+
panRef.current = null;
|
|
635
|
+
}
|
|
636
|
+
function onPointerDown(e) {
|
|
637
|
+
e.stopPropagation();
|
|
638
|
+
const stage = stageRef.current;
|
|
639
|
+
if (!stage) return;
|
|
640
|
+
stage.setPointerCapture(e.pointerId);
|
|
641
|
+
pointersRef.current.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
642
|
+
if (pointersRef.current.size === 2) {
|
|
643
|
+
beginPinch();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (transformRef.current.scale > MIN_SCALE) {
|
|
647
|
+
panRef.current = {
|
|
648
|
+
pointerId: e.pointerId,
|
|
649
|
+
startX: e.clientX,
|
|
650
|
+
startY: e.clientY,
|
|
651
|
+
originTx: transformRef.current.tx,
|
|
652
|
+
originTy: transformRef.current.ty,
|
|
653
|
+
moved: false
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function onPointerMove(e) {
|
|
658
|
+
if (!pointersRef.current.has(e.pointerId)) return;
|
|
659
|
+
pointersRef.current.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
660
|
+
const pinchStart = pinchStartRef.current;
|
|
661
|
+
if (pointersRef.current.size >= 2 && pinchStart) {
|
|
662
|
+
const pts = [...pointersRef.current.values()];
|
|
663
|
+
const [a, b] = pts;
|
|
664
|
+
if (!a || !b) return;
|
|
665
|
+
const distance = Math.max(pointerDistance(a, b), 1);
|
|
666
|
+
const nextScale = pinchStart.transform.scale * (distance / pinchStart.distance);
|
|
667
|
+
setTransform(
|
|
668
|
+
zoomToward(
|
|
669
|
+
pinchStart.transform,
|
|
670
|
+
nextScale,
|
|
671
|
+
pinchStart.originX,
|
|
672
|
+
pinchStart.originY
|
|
673
|
+
)
|
|
674
|
+
);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const pan = panRef.current;
|
|
678
|
+
if (pan && pan.pointerId === e.pointerId) {
|
|
679
|
+
const dx = e.clientX - pan.startX;
|
|
680
|
+
const dy = e.clientY - pan.startY;
|
|
681
|
+
if (Math.abs(dx) > 2 || Math.abs(dy) > 2) pan.moved = true;
|
|
682
|
+
setTransform((prev) => ({
|
|
683
|
+
...prev,
|
|
684
|
+
tx: pan.originTx + dx,
|
|
685
|
+
ty: pan.originTy + dy
|
|
686
|
+
}));
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function onPointerUp(e) {
|
|
690
|
+
const stage = stageRef.current;
|
|
691
|
+
if (stage?.hasPointerCapture(e.pointerId)) {
|
|
692
|
+
stage.releasePointerCapture(e.pointerId);
|
|
693
|
+
}
|
|
694
|
+
pointersRef.current.delete(e.pointerId);
|
|
695
|
+
if (pointersRef.current.size < 2) {
|
|
696
|
+
pinchStartRef.current = null;
|
|
697
|
+
}
|
|
698
|
+
if (pointersRef.current.size === 1) {
|
|
699
|
+
const remaining = [...pointersRef.current.entries()][0];
|
|
700
|
+
if (remaining && transformRef.current.scale > MIN_SCALE) {
|
|
701
|
+
const [pointerId, point] = remaining;
|
|
702
|
+
panRef.current = {
|
|
703
|
+
pointerId,
|
|
704
|
+
startX: point.x,
|
|
705
|
+
startY: point.y,
|
|
706
|
+
originTx: transformRef.current.tx,
|
|
707
|
+
originTy: transformRef.current.ty,
|
|
708
|
+
moved: true
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
const pan = panRef.current;
|
|
713
|
+
if (pan && pan.pointerId === e.pointerId) {
|
|
714
|
+
const wasMoved = pan.moved;
|
|
715
|
+
panRef.current = null;
|
|
716
|
+
if (wasMoved) return;
|
|
717
|
+
}
|
|
718
|
+
if (pointersRef.current.size === 0 && e.button === 0) {
|
|
719
|
+
const now = Date.now();
|
|
720
|
+
const last = lastTapRef.current;
|
|
721
|
+
if (last && now - last.time < DOUBLE_TAP_MS && Math.hypot(e.clientX - last.x, e.clientY - last.y) < 24) {
|
|
722
|
+
lastTapRef.current = null;
|
|
723
|
+
resetZoom();
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
lastTapRef.current = { time: now, x: e.clientX, y: e.clientY };
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function stopDialogClose(e) {
|
|
730
|
+
e.stopPropagation();
|
|
731
|
+
}
|
|
732
|
+
const { scale, tx, ty } = transform;
|
|
733
|
+
return reactDom.createPortal(
|
|
734
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
735
|
+
"div",
|
|
736
|
+
{
|
|
737
|
+
className: "fixed inset-x-0 top-0 z-50 flex h-dvh items-center justify-center bg-black/90 p-4",
|
|
738
|
+
onClick: onClose,
|
|
739
|
+
role: "dialog",
|
|
740
|
+
"aria-modal": "true",
|
|
741
|
+
"aria-label": ariaLabel,
|
|
742
|
+
children: [
|
|
743
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
744
|
+
"button",
|
|
745
|
+
{
|
|
746
|
+
type: "button",
|
|
747
|
+
onClick: onClose,
|
|
748
|
+
"aria-label": closeLabel,
|
|
749
|
+
className: "absolute right-4 top-4 z-10 rounded-full bg-black/50 p-2 text-white transition-colors hover:bg-black/70",
|
|
750
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-5 w-5" })
|
|
751
|
+
}
|
|
752
|
+
),
|
|
753
|
+
hasMultiple && /* @__PURE__ */ jsxRuntime.jsx(
|
|
754
|
+
"button",
|
|
755
|
+
{
|
|
756
|
+
type: "button",
|
|
757
|
+
onClick: (e) => {
|
|
758
|
+
e.stopPropagation();
|
|
759
|
+
goPrev();
|
|
760
|
+
},
|
|
761
|
+
"aria-label": previousLabel,
|
|
762
|
+
className: "absolute left-4 top-1/2 z-10 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white transition-colors hover:bg-black/70",
|
|
763
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "h-6 w-6" })
|
|
764
|
+
}
|
|
765
|
+
),
|
|
766
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
767
|
+
"div",
|
|
768
|
+
{
|
|
769
|
+
ref: stageRef,
|
|
770
|
+
className: "relative flex max-h-full max-w-full touch-none items-center justify-center",
|
|
771
|
+
"data-scale": scale,
|
|
772
|
+
onClick: stopDialogClose,
|
|
773
|
+
onPointerDown,
|
|
774
|
+
onPointerMove,
|
|
775
|
+
onPointerUp,
|
|
776
|
+
onPointerCancel: onPointerUp,
|
|
777
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
778
|
+
"img",
|
|
779
|
+
{
|
|
780
|
+
src: images[index],
|
|
781
|
+
alt: "",
|
|
782
|
+
draggable: false,
|
|
783
|
+
className: "max-h-[calc(100dvh-2rem)] max-w-full select-none rounded-lg object-contain",
|
|
784
|
+
style: {
|
|
785
|
+
transform: `translate(${tx}px, ${ty}px) scale(${scale})`,
|
|
786
|
+
cursor: scale > MIN_SCALE ? "grab" : "default"
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
)
|
|
790
|
+
}
|
|
791
|
+
),
|
|
792
|
+
hasMultiple && /* @__PURE__ */ jsxRuntime.jsx(
|
|
793
|
+
"button",
|
|
794
|
+
{
|
|
795
|
+
type: "button",
|
|
796
|
+
onClick: (e) => {
|
|
797
|
+
e.stopPropagation();
|
|
798
|
+
goNext();
|
|
799
|
+
},
|
|
800
|
+
"aria-label": nextLabel,
|
|
801
|
+
className: "absolute right-4 top-1/2 z-10 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white transition-colors hover:bg-black/70",
|
|
802
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-6 w-6" })
|
|
803
|
+
}
|
|
804
|
+
),
|
|
805
|
+
hasMultiple && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "absolute bottom-4 left-1/2 z-10 -translate-x-1/2 rounded-full bg-black/50 px-3 py-1 text-xs text-white", children: [
|
|
806
|
+
index + 1,
|
|
807
|
+
" / ",
|
|
808
|
+
images.length
|
|
809
|
+
] })
|
|
810
|
+
]
|
|
811
|
+
}
|
|
812
|
+
),
|
|
813
|
+
document.body
|
|
814
|
+
);
|
|
815
|
+
}
|
|
458
816
|
var miniMenuContentClassName = "max-h-none overflow-x-visible overflow-y-visible";
|
|
459
817
|
var miniMenuContentDefaults = {
|
|
460
818
|
sideOffset: 8,
|
|
@@ -5733,6 +6091,8 @@ exports.EmptyMedia = EmptyMedia;
|
|
|
5733
6091
|
exports.EmptyState = EmptyState;
|
|
5734
6092
|
exports.EmptyTitle = EmptyTitle;
|
|
5735
6093
|
exports.ErrorState = ErrorState;
|
|
6094
|
+
exports.ExpandableText = ExpandableText;
|
|
6095
|
+
exports.ImageLightbox = ImageLightbox;
|
|
5736
6096
|
exports.LanguageContext = LanguageContext;
|
|
5737
6097
|
exports.LanguageSwitcher = LanguageSwitcher;
|
|
5738
6098
|
exports.LoadingState = LoadingState;
|