@tent-official/react-walkthrough 1.1.101 → 1.1.102

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
@@ -536,27 +536,40 @@ var choosePopoverDir = (rect, popoverW, popoverH, gap, preferred) => {
536
536
  let offsetX = 0;
537
537
  let offsetY = 0;
538
538
  let maxHeight = void 0;
539
+ let align = "start";
539
540
  if (dir === "top" || dir === "bottom") {
540
- const popoverRight = rect.left + popoverW;
541
- if (popoverRight > vw - EDGE_MARGIN) {
542
- offsetX = vw - EDGE_MARGIN - popoverRight;
543
- }
544
- if (rect.left + offsetX < EDGE_MARGIN) {
545
- offsetX = EDGE_MARGIN - rect.left;
541
+ const rectCenter = rect.left + rect.width / 2;
542
+ align = rectCenter > vw / 2 ? "end" : "start";
543
+ if (align === "start") {
544
+ const popoverRight = rect.left + popoverW;
545
+ if (popoverRight > vw - EDGE_MARGIN) {
546
+ offsetX = vw - EDGE_MARGIN - popoverRight;
547
+ }
548
+ } else {
549
+ const popoverLeft = rect.left + rect.width - popoverW;
550
+ if (popoverLeft < EDGE_MARGIN) {
551
+ offsetX = EDGE_MARGIN - popoverLeft;
552
+ }
546
553
  }
547
554
  if (space[dir] < popoverH) {
548
555
  maxHeight = Math.max(space[dir], 60);
549
556
  }
550
557
  } else {
551
- const popoverBottom = rect.top + popoverH;
552
- if (popoverBottom > vh - EDGE_MARGIN) {
553
- offsetY = vh - EDGE_MARGIN - popoverBottom;
554
- }
555
- if (rect.top + offsetY < EDGE_MARGIN) {
556
- offsetY = EDGE_MARGIN - rect.top;
558
+ const rectMiddle = rect.top + rect.height / 2;
559
+ align = rectMiddle > vh / 2 ? "end" : "start";
560
+ if (align === "start") {
561
+ const popoverBottom = rect.top + popoverH;
562
+ if (popoverBottom > vh - EDGE_MARGIN) {
563
+ offsetY = vh - EDGE_MARGIN - popoverBottom;
564
+ }
565
+ } else {
566
+ const popoverTop = rect.top + rect.height - popoverH;
567
+ if (popoverTop < EDGE_MARGIN) {
568
+ offsetY = EDGE_MARGIN - popoverTop;
569
+ }
557
570
  }
558
571
  }
559
- return { dir, offsetX, offsetY, ...maxHeight != null && { maxHeight } };
572
+ return { dir, align, offsetX, offsetY, ...maxHeight != null && { maxHeight } };
560
573
  };
561
574
  if (preferred && fits(preferred)) return buildResult(preferred);
562
575
  const order = ["bottom", "top", "right", "left"];
@@ -596,7 +609,7 @@ var WalkthroughOverlay = ({
596
609
  prevColor,
597
610
  skipColor
598
611
  } = {}) => {
599
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
612
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
600
613
  injectKeyframes();
601
614
  const { activeTour } = useGlobalState();
602
615
  const instanceIdRef = react.useRef(null);
@@ -1031,21 +1044,9 @@ var WalkthroughOverlay = ({
1031
1044
  }
1032
1045
  const ds = displayStepRef.current;
1033
1046
  const dir = (_i = popoverPos == null ? void 0 : popoverPos.dir) != null ? _i : "bottom";
1034
- const offsetX = (_j = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _j : 0;
1035
- const offsetY = (_k = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _k : 0;
1036
- if (popoverReady && step) {
1037
- const dbgEl = document.getElementById(resolveElId(step.el));
1038
- const dbgReal = dbgEl ? dbgEl.getBoundingClientRect() : null;
1039
- console.log("[WT-DEBUG] anchor rect vs real element", {
1040
- anchorRect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },
1041
- realElement: dbgReal ? { top: dbgReal.top, left: dbgReal.left, width: dbgReal.width, height: dbgReal.height } : null,
1042
- dir,
1043
- offsetX,
1044
- offsetY,
1045
- popoverPos,
1046
- containerElement: activeTour == null ? void 0 : activeTour.containerElement
1047
- });
1048
- }
1047
+ const align = (_j = popoverPos == null ? void 0 : popoverPos.align) != null ? _j : "start";
1048
+ const offsetX = (_k = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _k : 0;
1049
+ const offsetY = (_l = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _l : 0;
1049
1050
  const anchorStyle = popoverReady ? {
1050
1051
  position: "fixed",
1051
1052
  top: rect.top,
@@ -1061,11 +1062,13 @@ var WalkthroughOverlay = ({
1061
1062
  pointerEvents: "none",
1062
1063
  zIndex: 99999
1063
1064
  };
1065
+ const hAlign = align === "end" ? { right: offsetX } : { left: offsetX };
1066
+ const vAlign = align === "end" ? { bottom: offsetY } : { top: offsetY };
1064
1067
  const dirStyles = {
1065
- bottom: { top: `calc(100% + ${$popoverGap}px)`, left: offsetX },
1066
- top: { bottom: `calc(100% + ${$popoverGap}px)`, left: offsetX },
1067
- right: { top: offsetY, left: `calc(100% + ${$popoverGap}px)` },
1068
- left: { top: offsetY, right: `calc(100% + ${$popoverGap}px)` }
1068
+ bottom: { top: `calc(100% + ${$popoverGap}px)`, ...hAlign },
1069
+ top: { bottom: `calc(100% + ${$popoverGap}px)`, ...hAlign },
1070
+ right: { left: `calc(100% + ${$popoverGap}px)`, ...vAlign },
1071
+ left: { right: `calc(100% + ${$popoverGap}px)`, ...vAlign }
1069
1072
  };
1070
1073
  const maxHeightStyle = (popoverPos == null ? void 0 : popoverPos.maxHeight) != null ? { maxHeight: popoverPos.maxHeight, overflowY: "auto" } : {};
1071
1074
  const popoverStyle = popoverReady ? {
@@ -1137,7 +1140,7 @@ var WalkthroughOverlay = ({
1137
1140
  /* @__PURE__ */ jsxRuntime.jsxs(PopoverBody, { children: [
1138
1141
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
1139
1142
  pStep.title ? /* @__PURE__ */ jsxRuntime.jsx(PopoverTitle, { children: pStep.title }) : "",
1140
- ((_l = pStep.isShowStep) != null ? _l : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1143
+ ((_m = pStep.isShowStep) != null ? _m : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1141
1144
  pDisplayCurrentStep,
1142
1145
  "/",
1143
1146
  pDisplayTotalSteps
@@ -1162,7 +1165,7 @@ var WalkthroughOverlay = ({
1162
1165
  }
1163
1166
  ) }),
1164
1167
  /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { children: [
1165
- ((_m = pStep.isShowPrev) != null ? _m : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1168
+ ((_n = pStep.isShowPrev) != null ? _n : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1166
1169
  "button",
1167
1170
  {
1168
1171
  className: "wt-btn",