@tent-official/react-walkthrough 1.1.98 → 1.1.100

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.mjs CHANGED
@@ -517,99 +517,52 @@ var clampSize = (value, max) => {
517
517
  return clamped;
518
518
  };
519
519
  var EDGE_MARGIN = 8;
520
- var computePopoverPosition = (rect, popoverW, popoverH, gap, preferred) => {
520
+ var choosePopoverDir = (rect, popoverW, popoverH, gap, preferred) => {
521
521
  const vw = window.innerWidth;
522
522
  const vh = window.innerHeight;
523
- const clampLeft = (left) => Math.max(EDGE_MARGIN, Math.min(left, vw - popoverW - EDGE_MARGIN));
524
- const clampTopH = (top) => Math.max(EDGE_MARGIN, Math.min(top, vh - popoverH - EDGE_MARGIN));
525
- const spaceBottom = vh - (rect.top + rect.height + gap) - EDGE_MARGIN;
526
- const spaceTop = rect.top - gap - EDGE_MARGIN;
527
- const spaceRight = vw - (rect.left + rect.width + gap) - EDGE_MARGIN;
528
- const spaceLeft = rect.left - gap - EDGE_MARGIN;
529
- const positions = {
530
- bottom: {
531
- top: rect.top + rect.height + gap,
532
- left: clampLeft(rect.left)
533
- },
534
- top: {
535
- top: rect.top - popoverH - gap,
536
- left: clampLeft(rect.left)
537
- },
538
- right: {
539
- top: clampTopH(rect.top),
540
- left: rect.left + rect.width + gap
541
- },
542
- left: {
543
- top: clampTopH(rect.top),
544
- left: rect.left - popoverW - gap
545
- }
523
+ const space = {
524
+ bottom: vh - (rect.top + rect.height + gap) - EDGE_MARGIN,
525
+ top: rect.top - gap - EDGE_MARGIN,
526
+ right: vw - (rect.left + rect.width + gap) - EDGE_MARGIN,
527
+ left: rect.left - gap - EDGE_MARGIN
546
528
  };
547
- const fitsInViewport = (pos) => pos.top >= EDGE_MARGIN && pos.left >= EDGE_MARGIN && pos.top + popoverH <= vh - EDGE_MARGIN && pos.left + popoverW <= vw - EDGE_MARGIN;
548
- const buildResult = (top, left, availableH) => {
549
- const needsClamp = availableH < popoverH;
550
- const maxH = needsClamp ? Math.max(availableH, 60) : null;
551
- return { top, left, ...maxH != null && { maxHeight: maxH } };
529
+ const fits = (dir) => {
530
+ if (dir === "top" || dir === "bottom") return space[dir] >= popoverH;
531
+ return space[dir] >= popoverW;
552
532
  };
553
- const buildForDir = (dir) => {
554
- const pos = positions[dir];
555
- if (dir === "bottom") {
556
- const anchorTop = rect.top + rect.height + gap;
557
- return buildResult(anchorTop, clampLeft(pos.left), vh - anchorTop - EDGE_MARGIN);
558
- }
559
- if (dir === "top") {
560
- const availH = spaceTop;
561
- const effectiveH = Math.min(popoverH, availH);
562
- const anchorTop = rect.top - gap - effectiveH;
563
- const finalTop = Math.max(EDGE_MARGIN, anchorTop);
564
- return buildResult(finalTop, clampLeft(pos.left), availH);
565
- }
566
- if (dir === "right" || dir === "left") {
567
- return buildResult(clampTopH(pos.top), pos.left, vh - EDGE_MARGIN * 2);
533
+ const buildResult = (dir) => {
534
+ let offsetX = 0;
535
+ let offsetY = 0;
536
+ let maxHeight = void 0;
537
+ if (dir === "top" || dir === "bottom") {
538
+ const popoverRight = rect.left + popoverW;
539
+ if (popoverRight > vw - EDGE_MARGIN) {
540
+ offsetX = vw - EDGE_MARGIN - popoverRight;
541
+ }
542
+ if (rect.left + offsetX < EDGE_MARGIN) {
543
+ offsetX = EDGE_MARGIN - rect.left;
544
+ }
545
+ if (space[dir] < popoverH) {
546
+ maxHeight = Math.max(space[dir], 60);
547
+ }
548
+ } else {
549
+ const popoverBottom = rect.top + popoverH;
550
+ if (popoverBottom > vh - EDGE_MARGIN) {
551
+ offsetY = vh - EDGE_MARGIN - popoverBottom;
552
+ }
553
+ if (rect.top + offsetY < EDGE_MARGIN) {
554
+ offsetY = EDGE_MARGIN - rect.top;
555
+ }
568
556
  }
569
- return { top: pos.top, left: pos.left };
557
+ return { dir, offsetX, offsetY, ...maxHeight != null && { maxHeight } };
570
558
  };
571
- console.log("[WT-DEBUG] computePopoverPosition", {
572
- rect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },
573
- popoverW,
574
- popoverH,
575
- gap,
576
- preferred,
577
- vw,
578
- vh,
579
- spaceTop,
580
- spaceBottom,
581
- spaceRight,
582
- spaceLeft,
583
- fits: {
584
- bottom: fitsInViewport(positions.bottom),
585
- top: fitsInViewport(positions.top),
586
- right: fitsInViewport(positions.right),
587
- left: fitsInViewport(positions.left)
588
- },
589
- positions
590
- });
591
- if (preferred && positions[preferred] && fitsInViewport(positions[preferred])) {
592
- const result2 = buildForDir(preferred);
593
- console.log("[WT-DEBUG] chosen:", preferred, "(preferred)", result2);
594
- return result2;
595
- }
559
+ if (preferred && fits(preferred)) return buildResult(preferred);
596
560
  const order = ["bottom", "top", "right", "left"];
597
- for (const dir of order) {
598
- if (fitsInViewport(positions[dir])) {
599
- const result2 = buildForDir(dir);
600
- console.log("[WT-DEBUG] chosen:", dir, "(fits)", result2);
601
- return result2;
602
- }
561
+ for (const d of order) {
562
+ if (fits(d)) return buildResult(d);
603
563
  }
604
- const best = [
605
- { dir: "bottom", space: spaceBottom },
606
- { dir: "top", space: spaceTop },
607
- { dir: "right", space: spaceRight },
608
- { dir: "left", space: spaceLeft }
609
- ].sort((a, b) => b.space - a.space)[0].dir;
610
- const result = buildForDir(best);
611
- console.log("[WT-DEBUG] chosen:", best, "(fallback)", result);
612
- return result;
564
+ const best = Object.entries(space).sort((a, b) => b[1] - a[1])[0][0];
565
+ return buildResult(best);
613
566
  };
614
567
  var WT_CONTAINER_ID = "wt-portal-root";
615
568
  var getPortalContainer = () => {
@@ -641,7 +594,7 @@ var WalkthroughOverlay = ({
641
594
  prevColor,
642
595
  skipColor
643
596
  } = {}) => {
644
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
597
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
645
598
  injectKeyframes();
646
599
  const { activeTour } = useGlobalState();
647
600
  const instanceIdRef = useRef(null);
@@ -823,14 +776,14 @@ var WalkthroughOverlay = ({
823
776
  return;
824
777
  }
825
778
  const measured = popoverRef.current.getBoundingClientRect();
826
- const pos = computePopoverPosition(
779
+ const dirInfo = choosePopoverDir(
827
780
  rect,
828
781
  measured.width,
829
782
  measured.height,
830
783
  $popoverGap,
831
784
  step.position
832
785
  );
833
- setPopoverPos(pos);
786
+ setPopoverPos(dirInfo);
834
787
  }, [rect, step, $popoverGap, isAnimating]);
835
788
  useEffect(() => {
836
789
  if (nextBtnRef.current) {
@@ -1075,18 +1028,41 @@ var WalkthroughOverlay = ({
1075
1028
  displayPosRef.current = currentValidPos;
1076
1029
  }
1077
1030
  const ds = displayStepRef.current;
1031
+ const dir = (_i = popoverPos == null ? void 0 : popoverPos.dir) != null ? _i : "bottom";
1032
+ const offsetX = (_j = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _j : 0;
1033
+ const offsetY = (_k = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _k : 0;
1034
+ const anchorStyle = popoverReady ? {
1035
+ position: "fixed",
1036
+ top: rect.top,
1037
+ left: rect.left,
1038
+ width: rect.width,
1039
+ height: rect.height,
1040
+ pointerEvents: "none",
1041
+ zIndex: 99999
1042
+ } : {
1043
+ position: "fixed",
1044
+ top: -9999,
1045
+ left: -9999,
1046
+ pointerEvents: "none",
1047
+ zIndex: 99999
1048
+ };
1049
+ const dirStyles = {
1050
+ bottom: { top: `calc(100% + ${$popoverGap}px)`, left: offsetX },
1051
+ top: { bottom: `calc(100% + ${$popoverGap}px)`, left: offsetX },
1052
+ right: { top: offsetY, left: `calc(100% + ${$popoverGap}px)` },
1053
+ left: { top: offsetY, right: `calc(100% + ${$popoverGap}px)` }
1054
+ };
1055
+ const maxHeightStyle = (popoverPos == null ? void 0 : popoverPos.maxHeight) != null ? { maxHeight: popoverPos.maxHeight, overflowY: "auto" } : {};
1078
1056
  const popoverStyle = popoverReady ? {
1079
- top: popoverPos.top,
1080
- left: popoverPos.left,
1057
+ position: "absolute",
1058
+ ...dirStyles[dir],
1081
1059
  width: popoverWidth,
1082
1060
  minWidth: $popoverMinWidth,
1083
1061
  padding: $popoverPadding,
1084
1062
  borderRadius: $popoverBorderRadius,
1085
1063
  fontFamily: "inherit",
1086
- ...popoverPos.maxHeight != null && {
1087
- maxHeight: popoverPos.maxHeight,
1088
- overflowY: "auto"
1089
- }
1064
+ pointerEvents: "auto",
1065
+ ...maxHeightStyle
1090
1066
  } : {
1091
1067
  position: "fixed",
1092
1068
  top: -9999,
@@ -1142,11 +1118,11 @@ var WalkthroughOverlay = ({
1142
1118
  }
1143
1119
  )
1144
1120
  ] }) }),
1145
- /* @__PURE__ */ jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
1121
+ /* @__PURE__ */ jsx("div", { style: anchorStyle, children: /* @__PURE__ */ jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
1146
1122
  /* @__PURE__ */ jsxs(PopoverBody, { children: [
1147
1123
  /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
1148
1124
  pStep.title ? /* @__PURE__ */ jsx(PopoverTitle, { children: pStep.title }) : "",
1149
- ((_i = pStep.isShowStep) != null ? _i : pIsShowStep) && /* @__PURE__ */ jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1125
+ ((_l = pStep.isShowStep) != null ? _l : pIsShowStep) && /* @__PURE__ */ jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1150
1126
  pDisplayCurrentStep,
1151
1127
  "/",
1152
1128
  pDisplayTotalSteps
@@ -1171,7 +1147,7 @@ var WalkthroughOverlay = ({
1171
1147
  }
1172
1148
  ) }),
1173
1149
  /* @__PURE__ */ jsxs(ButtonGroup, { children: [
1174
- ((_j = pStep.isShowPrev) != null ? _j : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsx(
1150
+ ((_m = pStep.isShowPrev) != null ? _m : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsx(
1175
1151
  "button",
1176
1152
  {
1177
1153
  className: "wt-btn",
@@ -1192,7 +1168,7 @@ var WalkthroughOverlay = ({
1192
1168
  )
1193
1169
  ] })
1194
1170
  ] })
1195
- ] })
1171
+ ] }) })
1196
1172
  ] });
1197
1173
  return createPortal(
1198
1174
  /* @__PURE__ */ jsx("div", { ...portalEventHandlers, style: { pointerEvents: "auto" }, children: overlay }),