@tent-official/react-walkthrough 1.1.97 → 1.1.99

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
@@ -519,73 +519,27 @@ var clampSize = (value, max) => {
519
519
  return clamped;
520
520
  };
521
521
  var EDGE_MARGIN = 8;
522
- var computePopoverPosition = (rect, popoverW, popoverH, gap, preferred) => {
522
+ var choosePopoverDir = (rect, popoverW, popoverH, gap, preferred) => {
523
523
  const vw = window.innerWidth;
524
524
  const vh = window.innerHeight;
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));
527
- const spaceBottom = vh - (rect.top + rect.height + gap) - EDGE_MARGIN;
528
- const spaceTop = rect.top - gap - EDGE_MARGIN;
529
- const spaceRight = vw - (rect.left + rect.width + gap) - EDGE_MARGIN;
530
- const spaceLeft = rect.left - gap - EDGE_MARGIN;
531
- const positions = {
532
- bottom: {
533
- top: rect.top + rect.height + gap,
534
- left: clampLeft(rect.left)
535
- },
536
- top: {
537
- top: rect.top - popoverH - gap,
538
- left: clampLeft(rect.left)
539
- },
540
- right: {
541
- top: clampTopH(rect.top),
542
- left: rect.left + rect.width + gap
543
- },
544
- left: {
545
- top: clampTopH(rect.top),
546
- left: rect.left - popoverW - gap
547
- }
548
- };
549
- const fitsInViewport = (pos) => pos.top >= EDGE_MARGIN && pos.left >= EDGE_MARGIN && pos.top + popoverH <= vh - EDGE_MARGIN && pos.left + popoverW <= vw - EDGE_MARGIN;
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 } };
525
+ const space = {
526
+ bottom: vh - (rect.top + rect.height + gap) - EDGE_MARGIN,
527
+ top: rect.top - gap - EDGE_MARGIN,
528
+ right: vw - (rect.left + rect.width + gap) - EDGE_MARGIN,
529
+ left: rect.left - gap - EDGE_MARGIN
554
530
  };
555
- const buildForDir = (dir) => {
556
- const pos = positions[dir];
557
- if (dir === "bottom") {
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);
567
- }
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 };
531
+ const fits = (dir) => {
532
+ if (dir === "top" || dir === "bottom") return space[dir] >= popoverH;
533
+ return space[dir] >= popoverW;
572
534
  };
573
- if (preferred && positions[preferred] && fitsInViewport(positions[preferred])) {
574
- return buildForDir(preferred);
575
- }
535
+ if (preferred && fits(preferred)) return { dir: preferred };
576
536
  const order = ["bottom", "top", "right", "left"];
577
- for (const dir of order) {
578
- if (fitsInViewport(positions[dir])) {
579
- return buildForDir(dir);
580
- }
537
+ for (const d of order) {
538
+ if (fits(d)) return { dir: d };
581
539
  }
582
- const best = [
583
- { dir: "bottom", space: spaceBottom },
584
- { dir: "top", space: spaceTop },
585
- { dir: "right", space: spaceRight },
586
- { dir: "left", space: spaceLeft }
587
- ].sort((a, b) => b.space - a.space)[0].dir;
588
- return buildForDir(best);
540
+ const best = Object.entries(space).sort((a, b) => b[1] - a[1])[0][0];
541
+ const maxH = best === "top" || best === "bottom" ? Math.max(space[best], 60) : Math.max(vh - EDGE_MARGIN * 2, 60);
542
+ return { dir: best, maxHeight: maxH };
589
543
  };
590
544
  var WT_CONTAINER_ID = "wt-portal-root";
591
545
  var getPortalContainer = () => {
@@ -617,7 +571,7 @@ var WalkthroughOverlay = ({
617
571
  prevColor,
618
572
  skipColor
619
573
  } = {}) => {
620
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
574
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
621
575
  injectKeyframes();
622
576
  const { activeTour } = useGlobalState();
623
577
  const instanceIdRef = react.useRef(null);
@@ -799,14 +753,14 @@ var WalkthroughOverlay = ({
799
753
  return;
800
754
  }
801
755
  const measured = popoverRef.current.getBoundingClientRect();
802
- const pos = computePopoverPosition(
756
+ const dirInfo = choosePopoverDir(
803
757
  rect,
804
758
  measured.width,
805
759
  measured.height,
806
760
  $popoverGap,
807
761
  step.position
808
762
  );
809
- setPopoverPos(pos);
763
+ setPopoverPos(dirInfo);
810
764
  }, [rect, step, $popoverGap, isAnimating]);
811
765
  react.useEffect(() => {
812
766
  if (nextBtnRef.current) {
@@ -1051,18 +1005,39 @@ var WalkthroughOverlay = ({
1051
1005
  displayPosRef.current = currentValidPos;
1052
1006
  }
1053
1007
  const ds = displayStepRef.current;
1008
+ const dir = (_i = popoverPos == null ? void 0 : popoverPos.dir) != null ? _i : "bottom";
1009
+ const anchorStyle = popoverReady ? {
1010
+ position: "fixed",
1011
+ top: rect.top,
1012
+ left: rect.left,
1013
+ width: rect.width,
1014
+ height: rect.height,
1015
+ pointerEvents: "none",
1016
+ zIndex: 99999
1017
+ } : {
1018
+ position: "fixed",
1019
+ top: -9999,
1020
+ left: -9999,
1021
+ pointerEvents: "none",
1022
+ zIndex: 99999
1023
+ };
1024
+ const dirStyles = {
1025
+ bottom: { top: `calc(100% + ${$popoverGap}px)`, left: 0 },
1026
+ top: { bottom: `calc(100% + ${$popoverGap}px)`, left: 0 },
1027
+ right: { top: 0, left: `calc(100% + ${$popoverGap}px)` },
1028
+ left: { top: 0, right: `calc(100% + ${$popoverGap}px)` }
1029
+ };
1030
+ const maxHeightStyle = (popoverPos == null ? void 0 : popoverPos.maxHeight) != null ? { maxHeight: popoverPos.maxHeight, overflowY: "auto" } : {};
1054
1031
  const popoverStyle = popoverReady ? {
1055
- top: popoverPos.top,
1056
- left: popoverPos.left,
1032
+ position: "absolute",
1033
+ ...dirStyles[dir],
1057
1034
  width: popoverWidth,
1058
1035
  minWidth: $popoverMinWidth,
1059
1036
  padding: $popoverPadding,
1060
1037
  borderRadius: $popoverBorderRadius,
1061
1038
  fontFamily: "inherit",
1062
- ...popoverPos.maxHeight != null && {
1063
- maxHeight: popoverPos.maxHeight,
1064
- overflowY: "auto"
1065
- }
1039
+ pointerEvents: "auto",
1040
+ ...maxHeightStyle
1066
1041
  } : {
1067
1042
  position: "fixed",
1068
1043
  top: -9999,
@@ -1118,11 +1093,11 @@ var WalkthroughOverlay = ({
1118
1093
  }
1119
1094
  )
1120
1095
  ] }) }),
1121
- /* @__PURE__ */ jsxRuntime.jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
1096
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: anchorStyle, children: /* @__PURE__ */ jsxRuntime.jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
1122
1097
  /* @__PURE__ */ jsxRuntime.jsxs(PopoverBody, { children: [
1123
1098
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
1124
1099
  pStep.title ? /* @__PURE__ */ jsxRuntime.jsx(PopoverTitle, { children: pStep.title }) : "",
1125
- ((_i = pStep.isShowStep) != null ? _i : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1100
+ ((_j = pStep.isShowStep) != null ? _j : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1126
1101
  pDisplayCurrentStep,
1127
1102
  "/",
1128
1103
  pDisplayTotalSteps
@@ -1147,7 +1122,7 @@ var WalkthroughOverlay = ({
1147
1122
  }
1148
1123
  ) }),
1149
1124
  /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { children: [
1150
- ((_j = pStep.isShowPrev) != null ? _j : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1125
+ ((_k = pStep.isShowPrev) != null ? _k : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1151
1126
  "button",
1152
1127
  {
1153
1128
  className: "wt-btn",
@@ -1168,7 +1143,7 @@ var WalkthroughOverlay = ({
1168
1143
  )
1169
1144
  ] })
1170
1145
  ] })
1171
- ] })
1146
+ ] }) })
1172
1147
  ] });
1173
1148
  return reactDom.createPortal(
1174
1149
  /* @__PURE__ */ jsxRuntime.jsx("div", { ...portalEventHandlers, style: { pointerEvents: "auto" }, children: overlay }),