@tent-official/react-walkthrough 1.1.96 → 1.1.98

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.js CHANGED
@@ -523,21 +523,11 @@ var computePopoverPosition = (rect, popoverW, popoverH, gap, preferred) => {
523
523
  const vw = window.innerWidth;
524
524
  const vh = window.innerHeight;
525
525
  const clampLeft = (left) => Math.max(EDGE_MARGIN, Math.min(left, vw - popoverW - EDGE_MARGIN));
526
+ const clampTopH = (top) => Math.max(EDGE_MARGIN, Math.min(top, vh - popoverH - EDGE_MARGIN));
526
527
  const spaceBottom = vh - (rect.top + rect.height + gap) - EDGE_MARGIN;
527
528
  const spaceTop = rect.top - gap - EDGE_MARGIN;
528
529
  const spaceRight = vw - (rect.left + rect.width + gap) - EDGE_MARGIN;
529
530
  const spaceLeft = rect.left - gap - EDGE_MARGIN;
530
- const clampTopForVertical = (top, dir) => {
531
- const clamped = Math.max(EDGE_MARGIN, Math.min(top, vh - popoverH - EDGE_MARGIN));
532
- if (dir === "top") {
533
- return Math.min(clamped, rect.top - gap - popoverH);
534
- }
535
- if (dir === "bottom") {
536
- return Math.max(clamped, rect.top + rect.height + gap);
537
- }
538
- return clamped;
539
- };
540
- const clampTopForHorizontal = (top) => Math.max(EDGE_MARGIN, Math.min(top, vh - popoverH - EDGE_MARGIN));
541
531
  const positions = {
542
532
  bottom: {
543
533
  top: rect.top + rect.height + gap,
@@ -548,34 +538,69 @@ var computePopoverPosition = (rect, popoverW, popoverH, gap, preferred) => {
548
538
  left: clampLeft(rect.left)
549
539
  },
550
540
  right: {
551
- top: clampTopForHorizontal(rect.top),
541
+ top: clampTopH(rect.top),
552
542
  left: rect.left + rect.width + gap
553
543
  },
554
544
  left: {
555
- top: clampTopForHorizontal(rect.top),
545
+ top: clampTopH(rect.top),
556
546
  left: rect.left - popoverW - gap
557
547
  }
558
548
  };
559
549
  const fitsInViewport = (pos) => pos.top >= EDGE_MARGIN && pos.left >= EDGE_MARGIN && pos.top + popoverH <= vh - EDGE_MARGIN && pos.left + popoverW <= vw - EDGE_MARGIN;
560
- const buildResult = (pos, dir) => {
561
- let maxH = null;
550
+ const buildResult = (top, left, availableH) => {
551
+ const needsClamp = availableH < popoverH;
552
+ const maxH = needsClamp ? Math.max(availableH, 60) : null;
553
+ return { top, left, ...maxH != null && { maxHeight: maxH } };
554
+ };
555
+ const buildForDir = (dir) => {
556
+ const pos = positions[dir];
562
557
  if (dir === "bottom") {
563
- maxH = vh - pos.top - EDGE_MARGIN;
564
- } else if (dir === "top") {
565
- maxH = rect.top - gap - EDGE_MARGIN;
566
- } else {
567
- maxH = vh - EDGE_MARGIN * 2;
558
+ const anchorTop = rect.top + rect.height + gap;
559
+ return buildResult(anchorTop, clampLeft(pos.left), vh - anchorTop - EDGE_MARGIN);
560
+ }
561
+ if (dir === "top") {
562
+ const availH = spaceTop;
563
+ const effectiveH = Math.min(popoverH, availH);
564
+ const anchorTop = rect.top - gap - effectiveH;
565
+ const finalTop = Math.max(EDGE_MARGIN, anchorTop);
566
+ return buildResult(finalTop, clampLeft(pos.left), availH);
568
567
  }
569
- if (maxH >= popoverH) maxH = null;
570
- return { top: pos.top, left: pos.left, ...maxH != null && { maxHeight: Math.max(maxH, 60) } };
568
+ if (dir === "right" || dir === "left") {
569
+ return buildResult(clampTopH(pos.top), pos.left, vh - EDGE_MARGIN * 2);
570
+ }
571
+ return { top: pos.top, left: pos.left };
571
572
  };
573
+ console.log("[WT-DEBUG] computePopoverPosition", {
574
+ rect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },
575
+ popoverW,
576
+ popoverH,
577
+ gap,
578
+ preferred,
579
+ vw,
580
+ vh,
581
+ spaceTop,
582
+ spaceBottom,
583
+ spaceRight,
584
+ spaceLeft,
585
+ fits: {
586
+ bottom: fitsInViewport(positions.bottom),
587
+ top: fitsInViewport(positions.top),
588
+ right: fitsInViewport(positions.right),
589
+ left: fitsInViewport(positions.left)
590
+ },
591
+ positions
592
+ });
572
593
  if (preferred && positions[preferred] && fitsInViewport(positions[preferred])) {
573
- return buildResult(positions[preferred], preferred);
594
+ const result2 = buildForDir(preferred);
595
+ console.log("[WT-DEBUG] chosen:", preferred, "(preferred)", result2);
596
+ return result2;
574
597
  }
575
598
  const order = ["bottom", "top", "right", "left"];
576
599
  for (const dir of order) {
577
600
  if (fitsInViewport(positions[dir])) {
578
- return buildResult(positions[dir], dir);
601
+ const result2 = buildForDir(dir);
602
+ console.log("[WT-DEBUG] chosen:", dir, "(fits)", result2);
603
+ return result2;
579
604
  }
580
605
  }
581
606
  const best = [
@@ -584,10 +609,9 @@ var computePopoverPosition = (rect, popoverW, popoverH, gap, preferred) => {
584
609
  { dir: "right", space: spaceRight },
585
610
  { dir: "left", space: spaceLeft }
586
611
  ].sort((a, b) => b.space - a.space)[0].dir;
587
- const fallback = positions[best];
588
- const clampedTop = best === "top" || best === "bottom" ? clampTopForVertical(fallback.top, best) : clampTopForHorizontal(fallback.top);
589
- const clampedLeft = Math.max(EDGE_MARGIN, Math.min(fallback.left, vw - popoverW - EDGE_MARGIN));
590
- return buildResult({ top: clampedTop, left: clampedLeft }, best);
612
+ const result = buildForDir(best);
613
+ console.log("[WT-DEBUG] chosen:", best, "(fallback)", result);
614
+ return result;
591
615
  };
592
616
  var WT_CONTAINER_ID = "wt-portal-root";
593
617
  var getPortalContainer = () => {