@sesionario/blocks 1.6.0 → 1.7.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 +297 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +299 -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,301 @@ function ConfirmDestructiveDialog({
|
|
|
455
456
|
] })
|
|
456
457
|
] }) });
|
|
457
458
|
}
|
|
459
|
+
var MIN_SCALE = 1;
|
|
460
|
+
var MAX_SCALE = 4;
|
|
461
|
+
var DOUBLE_TAP_MS = 300;
|
|
462
|
+
var IDENTITY = { scale: 1, tx: 0, ty: 0 };
|
|
463
|
+
function clamp(value, min, max) {
|
|
464
|
+
return Math.min(max, Math.max(min, value));
|
|
465
|
+
}
|
|
466
|
+
function zoomToward(prev, nextScale, originX, originY) {
|
|
467
|
+
const scale = clamp(nextScale, MIN_SCALE, MAX_SCALE);
|
|
468
|
+
if (scale === MIN_SCALE) return IDENTITY;
|
|
469
|
+
const ratio = scale / prev.scale;
|
|
470
|
+
return {
|
|
471
|
+
scale,
|
|
472
|
+
tx: originX - (originX - prev.tx) * ratio,
|
|
473
|
+
ty: originY - (originY - prev.ty) * ratio
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function pointerDistance(a, b) {
|
|
477
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
478
|
+
}
|
|
479
|
+
function ImageLightbox({
|
|
480
|
+
images,
|
|
481
|
+
index,
|
|
482
|
+
onIndexChange,
|
|
483
|
+
onClose,
|
|
484
|
+
labels
|
|
485
|
+
}) {
|
|
486
|
+
const ariaLabel = labels?.ariaLabel ?? "Visor de im\xE1genes";
|
|
487
|
+
const closeLabel = labels?.close ?? "Cerrar";
|
|
488
|
+
const previousLabel = labels?.previous ?? "Anterior";
|
|
489
|
+
const nextLabel = labels?.next ?? "Siguiente";
|
|
490
|
+
const hasMultiple = images.length > 1;
|
|
491
|
+
const [transform, setTransform] = React6.useState(IDENTITY);
|
|
492
|
+
const transformRef = React6.useRef(transform);
|
|
493
|
+
transformRef.current = transform;
|
|
494
|
+
const stageRef = React6.useRef(null);
|
|
495
|
+
const pointersRef = React6.useRef(/* @__PURE__ */ new Map());
|
|
496
|
+
const pinchStartRef = React6.useRef(null);
|
|
497
|
+
const panRef = React6.useRef(null);
|
|
498
|
+
const lastTapRef = React6.useRef(
|
|
499
|
+
null
|
|
500
|
+
);
|
|
501
|
+
const resetZoom = React6.useCallback(() => {
|
|
502
|
+
setTransform(IDENTITY);
|
|
503
|
+
}, []);
|
|
504
|
+
React6.useEffect(() => {
|
|
505
|
+
resetZoom();
|
|
506
|
+
}, [index, images[index], resetZoom]);
|
|
507
|
+
function goPrev() {
|
|
508
|
+
onIndexChange((index - 1 + images.length) % images.length);
|
|
509
|
+
}
|
|
510
|
+
function goNext() {
|
|
511
|
+
onIndexChange((index + 1) % images.length);
|
|
512
|
+
}
|
|
513
|
+
React6.useEffect(() => {
|
|
514
|
+
function handleKeyDown(e) {
|
|
515
|
+
if (e.key === "Escape") {
|
|
516
|
+
onClose();
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (!hasMultiple) return;
|
|
520
|
+
if (e.key === "ArrowLeft") {
|
|
521
|
+
onIndexChange((index - 1 + images.length) % images.length);
|
|
522
|
+
} else if (e.key === "ArrowRight") {
|
|
523
|
+
onIndexChange((index + 1) % images.length);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
527
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
528
|
+
}, [index, images.length, hasMultiple, onClose, onIndexChange]);
|
|
529
|
+
React6.useEffect(() => {
|
|
530
|
+
const previousOverflow = document.body.style.overflow;
|
|
531
|
+
document.body.style.overflow = "hidden";
|
|
532
|
+
return () => {
|
|
533
|
+
document.body.style.overflow = previousOverflow;
|
|
534
|
+
};
|
|
535
|
+
}, []);
|
|
536
|
+
const stageOrigin = React6.useCallback((clientX, clientY) => {
|
|
537
|
+
const stage = stageRef.current;
|
|
538
|
+
if (!stage) return { x: 0, y: 0 };
|
|
539
|
+
const rect = stage.getBoundingClientRect();
|
|
540
|
+
return {
|
|
541
|
+
x: clientX - rect.left - rect.width / 2,
|
|
542
|
+
y: clientY - rect.top - rect.height / 2
|
|
543
|
+
};
|
|
544
|
+
}, []);
|
|
545
|
+
React6.useEffect(() => {
|
|
546
|
+
const stage = stageRef.current;
|
|
547
|
+
if (!stage) return;
|
|
548
|
+
const handleWheel = (e) => {
|
|
549
|
+
e.preventDefault();
|
|
550
|
+
e.stopPropagation();
|
|
551
|
+
const prev = transformRef.current;
|
|
552
|
+
const factor = e.deltaY > 0 ? 0.9 : 1.1;
|
|
553
|
+
const { x, y } = stageOrigin(e.clientX, e.clientY);
|
|
554
|
+
setTransform(zoomToward(prev, prev.scale * factor, x, y));
|
|
555
|
+
};
|
|
556
|
+
stage.addEventListener("wheel", handleWheel, { passive: false });
|
|
557
|
+
return () => stage.removeEventListener("wheel", handleWheel);
|
|
558
|
+
}, [stageOrigin]);
|
|
559
|
+
function beginPinch() {
|
|
560
|
+
const pts = [...pointersRef.current.values()];
|
|
561
|
+
const [a, b] = pts;
|
|
562
|
+
if (!a || !b) return;
|
|
563
|
+
const midX = (a.x + b.x) / 2;
|
|
564
|
+
const midY = (a.y + b.y) / 2;
|
|
565
|
+
const { x, y } = stageOrigin(midX, midY);
|
|
566
|
+
pinchStartRef.current = {
|
|
567
|
+
distance: Math.max(pointerDistance(a, b), 1),
|
|
568
|
+
originX: x,
|
|
569
|
+
originY: y,
|
|
570
|
+
transform: { ...transformRef.current }
|
|
571
|
+
};
|
|
572
|
+
panRef.current = null;
|
|
573
|
+
}
|
|
574
|
+
function onPointerDown(e) {
|
|
575
|
+
e.stopPropagation();
|
|
576
|
+
const stage = stageRef.current;
|
|
577
|
+
if (!stage) return;
|
|
578
|
+
stage.setPointerCapture(e.pointerId);
|
|
579
|
+
pointersRef.current.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
580
|
+
if (pointersRef.current.size === 2) {
|
|
581
|
+
beginPinch();
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
if (transformRef.current.scale > MIN_SCALE) {
|
|
585
|
+
panRef.current = {
|
|
586
|
+
pointerId: e.pointerId,
|
|
587
|
+
startX: e.clientX,
|
|
588
|
+
startY: e.clientY,
|
|
589
|
+
originTx: transformRef.current.tx,
|
|
590
|
+
originTy: transformRef.current.ty,
|
|
591
|
+
moved: false
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function onPointerMove(e) {
|
|
596
|
+
if (!pointersRef.current.has(e.pointerId)) return;
|
|
597
|
+
pointersRef.current.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
598
|
+
const pinchStart = pinchStartRef.current;
|
|
599
|
+
if (pointersRef.current.size >= 2 && pinchStart) {
|
|
600
|
+
const pts = [...pointersRef.current.values()];
|
|
601
|
+
const [a, b] = pts;
|
|
602
|
+
if (!a || !b) return;
|
|
603
|
+
const distance = Math.max(pointerDistance(a, b), 1);
|
|
604
|
+
const nextScale = pinchStart.transform.scale * (distance / pinchStart.distance);
|
|
605
|
+
setTransform(
|
|
606
|
+
zoomToward(
|
|
607
|
+
pinchStart.transform,
|
|
608
|
+
nextScale,
|
|
609
|
+
pinchStart.originX,
|
|
610
|
+
pinchStart.originY
|
|
611
|
+
)
|
|
612
|
+
);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const pan = panRef.current;
|
|
616
|
+
if (pan && pan.pointerId === e.pointerId) {
|
|
617
|
+
const dx = e.clientX - pan.startX;
|
|
618
|
+
const dy = e.clientY - pan.startY;
|
|
619
|
+
if (Math.abs(dx) > 2 || Math.abs(dy) > 2) pan.moved = true;
|
|
620
|
+
setTransform((prev) => ({
|
|
621
|
+
...prev,
|
|
622
|
+
tx: pan.originTx + dx,
|
|
623
|
+
ty: pan.originTy + dy
|
|
624
|
+
}));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function onPointerUp(e) {
|
|
628
|
+
const stage = stageRef.current;
|
|
629
|
+
if (stage?.hasPointerCapture(e.pointerId)) {
|
|
630
|
+
stage.releasePointerCapture(e.pointerId);
|
|
631
|
+
}
|
|
632
|
+
pointersRef.current.delete(e.pointerId);
|
|
633
|
+
if (pointersRef.current.size < 2) {
|
|
634
|
+
pinchStartRef.current = null;
|
|
635
|
+
}
|
|
636
|
+
if (pointersRef.current.size === 1) {
|
|
637
|
+
const remaining = [...pointersRef.current.entries()][0];
|
|
638
|
+
if (remaining && transformRef.current.scale > MIN_SCALE) {
|
|
639
|
+
const [pointerId, point] = remaining;
|
|
640
|
+
panRef.current = {
|
|
641
|
+
pointerId,
|
|
642
|
+
startX: point.x,
|
|
643
|
+
startY: point.y,
|
|
644
|
+
originTx: transformRef.current.tx,
|
|
645
|
+
originTy: transformRef.current.ty,
|
|
646
|
+
moved: true
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
const pan = panRef.current;
|
|
651
|
+
if (pan && pan.pointerId === e.pointerId) {
|
|
652
|
+
const wasMoved = pan.moved;
|
|
653
|
+
panRef.current = null;
|
|
654
|
+
if (wasMoved) return;
|
|
655
|
+
}
|
|
656
|
+
if (pointersRef.current.size === 0 && e.button === 0) {
|
|
657
|
+
const now = Date.now();
|
|
658
|
+
const last = lastTapRef.current;
|
|
659
|
+
if (last && now - last.time < DOUBLE_TAP_MS && Math.hypot(e.clientX - last.x, e.clientY - last.y) < 24) {
|
|
660
|
+
lastTapRef.current = null;
|
|
661
|
+
resetZoom();
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
lastTapRef.current = { time: now, x: e.clientX, y: e.clientY };
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
function stopDialogClose(e) {
|
|
668
|
+
e.stopPropagation();
|
|
669
|
+
}
|
|
670
|
+
const { scale, tx, ty } = transform;
|
|
671
|
+
return reactDom.createPortal(
|
|
672
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
673
|
+
"div",
|
|
674
|
+
{
|
|
675
|
+
className: "fixed inset-x-0 top-0 z-50 flex h-dvh items-center justify-center bg-black/90 p-4",
|
|
676
|
+
onClick: onClose,
|
|
677
|
+
role: "dialog",
|
|
678
|
+
"aria-modal": "true",
|
|
679
|
+
"aria-label": ariaLabel,
|
|
680
|
+
children: [
|
|
681
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
682
|
+
"button",
|
|
683
|
+
{
|
|
684
|
+
type: "button",
|
|
685
|
+
onClick: onClose,
|
|
686
|
+
"aria-label": closeLabel,
|
|
687
|
+
className: "absolute right-4 top-4 z-10 rounded-full bg-black/50 p-2 text-white transition-colors hover:bg-black/70",
|
|
688
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-5 w-5" })
|
|
689
|
+
}
|
|
690
|
+
),
|
|
691
|
+
hasMultiple && /* @__PURE__ */ jsxRuntime.jsx(
|
|
692
|
+
"button",
|
|
693
|
+
{
|
|
694
|
+
type: "button",
|
|
695
|
+
onClick: (e) => {
|
|
696
|
+
e.stopPropagation();
|
|
697
|
+
goPrev();
|
|
698
|
+
},
|
|
699
|
+
"aria-label": previousLabel,
|
|
700
|
+
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",
|
|
701
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "h-6 w-6" })
|
|
702
|
+
}
|
|
703
|
+
),
|
|
704
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
705
|
+
"div",
|
|
706
|
+
{
|
|
707
|
+
ref: stageRef,
|
|
708
|
+
className: "relative flex max-h-full max-w-full touch-none items-center justify-center",
|
|
709
|
+
"data-scale": scale,
|
|
710
|
+
onClick: stopDialogClose,
|
|
711
|
+
onPointerDown,
|
|
712
|
+
onPointerMove,
|
|
713
|
+
onPointerUp,
|
|
714
|
+
onPointerCancel: onPointerUp,
|
|
715
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
716
|
+
"img",
|
|
717
|
+
{
|
|
718
|
+
src: images[index],
|
|
719
|
+
alt: "",
|
|
720
|
+
draggable: false,
|
|
721
|
+
className: "max-h-[calc(100dvh-2rem)] max-w-full select-none rounded-lg object-contain",
|
|
722
|
+
style: {
|
|
723
|
+
transform: `translate(${tx}px, ${ty}px) scale(${scale})`,
|
|
724
|
+
cursor: scale > MIN_SCALE ? "grab" : "default"
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
)
|
|
728
|
+
}
|
|
729
|
+
),
|
|
730
|
+
hasMultiple && /* @__PURE__ */ jsxRuntime.jsx(
|
|
731
|
+
"button",
|
|
732
|
+
{
|
|
733
|
+
type: "button",
|
|
734
|
+
onClick: (e) => {
|
|
735
|
+
e.stopPropagation();
|
|
736
|
+
goNext();
|
|
737
|
+
},
|
|
738
|
+
"aria-label": nextLabel,
|
|
739
|
+
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",
|
|
740
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-6 w-6" })
|
|
741
|
+
}
|
|
742
|
+
),
|
|
743
|
+
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: [
|
|
744
|
+
index + 1,
|
|
745
|
+
" / ",
|
|
746
|
+
images.length
|
|
747
|
+
] })
|
|
748
|
+
]
|
|
749
|
+
}
|
|
750
|
+
),
|
|
751
|
+
document.body
|
|
752
|
+
);
|
|
753
|
+
}
|
|
458
754
|
var miniMenuContentClassName = "max-h-none overflow-x-visible overflow-y-visible";
|
|
459
755
|
var miniMenuContentDefaults = {
|
|
460
756
|
sideOffset: 8,
|
|
@@ -5733,6 +6029,7 @@ exports.EmptyMedia = EmptyMedia;
|
|
|
5733
6029
|
exports.EmptyState = EmptyState;
|
|
5734
6030
|
exports.EmptyTitle = EmptyTitle;
|
|
5735
6031
|
exports.ErrorState = ErrorState;
|
|
6032
|
+
exports.ImageLightbox = ImageLightbox;
|
|
5736
6033
|
exports.LanguageContext = LanguageContext;
|
|
5737
6034
|
exports.LanguageSwitcher = LanguageSwitcher;
|
|
5738
6035
|
exports.LoadingState = LoadingState;
|