@seanyeh77/ui 0.13.0 → 0.14.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.d.ts CHANGED
@@ -1445,12 +1445,15 @@ interface TourStep {
1445
1445
  title: string;
1446
1446
  /** What it does, 1 short sentence; `backticks` are code. */
1447
1447
  text: string;
1448
- /** Default 'bottom'; flips when there is no room. The card never covers the target: with no room above or below,
1449
- * the page scrolls to make room (above a target taller than the window), else the card goes right or left of it;
1450
- * only when none of that works does it sit inside the target, at the bottom. */
1448
+ /** Default 'bottom'. The card goes below, above, right or left of the target, the first side where it fits in the
1449
+ * window and covers neither the target nor `keepVisible` ('top' tries above first). With no such side the page
1450
+ * scrolls to make room; failing that, the side that covers the least of the target. */
1451
1451
  side?: 'bottom' | 'top';
1452
1452
  /** Space around the highlighted part in px. Default 6. */
1453
1453
  padding?: number;
1454
+ /** Parts the card must not cover either, e.g. the table the step talks about under a highlighted summary: same forms
1455
+ * as target. The card then goes to the next side that leaves them visible. */
1456
+ keepVisible?: TourStep['target'] | TourStep['target'][];
1454
1457
  }
1455
1458
  interface TourProps {
1456
1459
  open: boolean;
package/dist/index.js CHANGED
@@ -4933,6 +4933,7 @@ function LayerGraph(p) {
4933
4933
  onScroll();
4934
4934
  };
4935
4935
  const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
4936
+ const selListEdge = pickEdge && p.edges.find((e) => edgeId(e) === p.selectedEdge) || null;
4936
4937
  const nodeIdsAll = new Set(all.map((n) => n.id));
4937
4938
  const uses = {};
4938
4939
  for (const e of p.edges) if (sharedIds.has(e.to) && e.from !== e.to && nodeIdsAll.has(e.from)) (uses[e.to] ??= {})[e.from] = (uses[e.to]?.[e.from] ?? 0) + (e.count || 0);
@@ -4967,12 +4968,12 @@ function LayerGraph(p) {
4967
4968
  };
4968
4969
  W += shift;
4969
4970
  }
4970
- const boxesLeft = Math.min(...main.map((n) => pos[n.id].x));
4971
- const boxesRight = Math.max(0, ...main.map((n) => pos[n.id].x + NW));
4972
- const laneX = (e) => onLeft(e) ? boxesLeft - LANE - upsL.indexOf(e) * LANE_STEP : boxesRight + LANE + upsR.indexOf(e) * LANE_STEP;
4973
- const upLabelX = boxesLeft - LANE + 8;
4974
- const upLabelEndL = boxesRight + LANE - 8;
4975
- if (upsR.length) W = Math.max(W, boxesRight + LANE + (upsR.length - 1) * LANE_STEP + PAD);
4971
+ const boxesLeft = () => Math.min(...main.map((n) => pos[n.id].x));
4972
+ const boxesRight = () => Math.max(0, ...main.map((n) => pos[n.id].x + NW));
4973
+ const laneX = (e) => onLeft(e) ? boxesLeft() - LANE - upsL.indexOf(e) * LANE_STEP : boxesRight() + LANE + upsR.indexOf(e) * LANE_STEP;
4974
+ const upLabelX = () => boxesLeft() - LANE + 8;
4975
+ const upLabelEndL = () => boxesRight() + LANE - 8;
4976
+ if (upsR.length) W = Math.max(W, boxesRight() + LANE + (upsR.length - 1) * LANE_STEP + PAD);
4976
4977
  const choose = (e) => {
4977
4978
  const id = edgeId(e);
4978
4979
  const next = p.selectedEdge === id ? null : id;
@@ -5258,7 +5259,7 @@ function LayerGraph(p) {
5258
5259
  idx,
5259
5260
  e,
5260
5261
  text,
5261
- tx: L ? upLabelX : upLabelEndL,
5262
+ tx: L ? upLabelX() : upLabelEndL(),
5262
5263
  ty: Math.round((y0 + y1) / 2),
5263
5264
  left: !L,
5264
5265
  r,
@@ -5425,18 +5426,19 @@ function LayerGraph(p) {
5425
5426
  const hits = (x0, x1, y0, y1) => placed.some((q) => x0 < q[1] + (q[4] || 0) && q[0] < x1 + (q[4] || 0) && y0 < q[3] && q[2] < y1);
5426
5427
  const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
5427
5428
  const gapTo = (b, x0, lw, y0, y1) => Math.hypot(Math.max(0, b[0] - (x0 + lw), x0 - b[1]), Math.max(0, b[2] - y1, y0 - b[3]));
5428
- const alongLine = (m, own = false) => {
5429
+ const isMine = (idx, x0, lw, y0, y1) => {
5430
+ let self = Infinity;
5431
+ let other = Infinity;
5432
+ for (const sg of segs) {
5433
+ const d = gapTo(sg.box, x0, lw, y0, y1);
5434
+ if (sg.idx === idx) self = Math.min(self, d);
5435
+ else other = Math.min(other, d);
5436
+ }
5437
+ return self + 4 < other && other >= 8;
5438
+ };
5439
+ const alongLine = (m, own = true) => {
5429
5440
  const pts = ptsOf[m.idx] ?? [];
5430
- const mine = (x0, lw, y0, y1) => {
5431
- let self = Infinity;
5432
- let other = Infinity;
5433
- for (const sg of segs) {
5434
- const d = gapTo(sg.box, x0, lw, y0, y1);
5435
- if (sg.idx === m.idx) self = Math.min(self, d);
5436
- else other = Math.min(other, d);
5437
- }
5438
- return self + 4 < other && other >= 8;
5439
- };
5441
+ const mine = (x0, lw, y0, y1) => isMine(m.idx, x0, lw, y0, y1);
5440
5442
  const ok = (x0, lw, y0, y1) => (!own || mine(x0, lw, y0, y1)) && x0 >= PAD / 2 && x0 + lw <= W - PAD / 2 && y0 >= 2 && y1 <= H - 2 && !hits(x0 - 2, x0 + lw + 2, y0 - 2, y1 + 2) && !boxRects.some((q) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : x0 < sg.box[1] + 2 && sg.box[0] < x0 + lw + 2 && y0 < sg.box[3] + 2 && sg.box[2] < y1 + 2);
5441
5443
  for (const lines of wraps(m.text)) {
5442
5444
  const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
@@ -5471,9 +5473,44 @@ function LayerGraph(p) {
5471
5473
  }
5472
5474
  return null;
5473
5475
  };
5474
- const labelEl = (m, x0, top, lines = [m.text], over = false) => /* @__PURE__ */ jsx("span", {
5476
+ const numbered = [];
5477
+ const numberOn = (m, near) => {
5478
+ const pts = ptsOf[m.idx] ?? [];
5479
+ const cx = near.x0 + near.lw / 2;
5480
+ const cy = near.top;
5481
+ let best = null;
5482
+ for (let k = 0; k + 1 < pts.length; k++) {
5483
+ const [x1, y1] = pts[k];
5484
+ const [x2, y2] = pts[k + 1];
5485
+ const len = Math.hypot(x2 - x1, y2 - y1);
5486
+ for (let t = 12; t <= len - 12; t += 4) {
5487
+ const x = x1 + (x2 - x1) * t / len;
5488
+ const y = y1 + (y2 - y1) * t / len;
5489
+ const clear = !segs.some((sg) => sg.idx !== m.idx && gapTo(sg.box, x - 14, 28, y - 14, y + 14) === 0) && !boxRects.some((q) => x + 14 > q[0] && x - 14 < q[1] && y + 14 > q[2] && y - 14 < q[3]) && !hits(x - 14, x + 14, y - 14, y + 14) && !numbered.some((o) => Math.hypot(o.x - x, o.y - y) < 28);
5490
+ const d = Math.hypot(x - cx, y - cy);
5491
+ if (!best || clear && !best.clear || clear === best.clear && d < best.d) best = {
5492
+ x,
5493
+ y,
5494
+ d,
5495
+ clear
5496
+ };
5497
+ }
5498
+ }
5499
+ const at = best ?? {
5500
+ x: m.tx,
5501
+ y: m.ty - 20
5502
+ };
5503
+ numbered.push({
5504
+ n: numbered.length + 1,
5505
+ m,
5506
+ x: Math.round(at.x),
5507
+ y: Math.round(at.y)
5508
+ });
5509
+ return numbered.length;
5510
+ };
5511
+ const labelEl = (m, x0, top, lines = [m.text], over = false, num = 0) => /* @__PURE__ */ jsx("span", {
5475
5512
  "aria-hidden": pickEdge ? true : void 0,
5476
- className: cx("ui-lg-label", over && "is-over", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim", peek && !m.r && hover !== edgeId(m.e) && m.e !== selEdge && "is-quiet"),
5513
+ className: cx("ui-lg-label", over && "is-over", num > 0 && "is-numbered", num > 0 && (hover === edgeId(m.e) || m.e === selEdge) && "is-shown", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim", peek && !m.r && hover !== edgeId(m.e) && m.e !== selEdge && "is-quiet"),
5477
5514
  style: {
5478
5515
  left: x0,
5479
5516
  top
@@ -5506,6 +5543,8 @@ function LayerGraph(p) {
5506
5543
  lh: 16,
5507
5544
  lines: [m.text]
5508
5545
  };
5546
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines, true, numberOn(m, spot)));
5547
+ return;
5509
5548
  }
5510
5549
  placed.push([
5511
5550
  spot.x0,
@@ -5539,7 +5578,7 @@ function LayerGraph(p) {
5539
5578
  const start0 = Math.max(10, Math.min(H - 10, m.ty));
5540
5579
  const find = (x0, lw, lh, withLines) => {
5541
5580
  const over = (q, y0, y1) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4;
5542
- const bad = (y0, y1) => hits(x0, x0 + lw, y0 - 4, y1 + 4) || boxRects.some((q) => over(q, y0, y1)) || withLines && segs.some((g) => g.idx === m.idx ? cross(g.box, x0, lw, y0, y1) : over(g.box, y0, y1));
5581
+ const bad = (y0, y1) => hits(x0, x0 + lw, y0 - 4, y1 + 4) || boxRects.some((q) => over(q, y0, y1)) || withLines && segs.some((g) => g.idx === m.idx ? cross(g.box, x0, lw, y0, y1) : over(g.box, y0, y1)) || withLines && !isMine(m.idx, x0, lw, y0, y1);
5543
5582
  for (let k = 0; k <= 16; k++) for (const dir of k ? [-1, 1] : [0]) {
5544
5583
  const t = start0 + dir * k * 18;
5545
5584
  if (t - lh / 2 >= 2 && t + lh / 2 <= H - 2 && !bad(t - lh / 2, t + lh / 2)) return t;
@@ -5571,13 +5610,15 @@ function LayerGraph(p) {
5571
5610
  const x0 = x0Of(w);
5572
5611
  const top = find(x0, w, 16, false);
5573
5612
  if (top == null) crowd.add(g);
5574
- spot = {
5613
+ const at = {
5575
5614
  x0,
5576
5615
  top: top ?? start0,
5577
5616
  lw: w,
5578
5617
  lh: 16,
5579
5618
  lines: [m.text]
5580
5619
  };
5620
+ labels.push(labelEl(m, at.x0, at.top, at.lines, true, numberOn(m, at)));
5621
+ return;
5581
5622
  }
5582
5623
  placed.push([
5583
5624
  spot.x0,
@@ -5688,6 +5729,10 @@ function LayerGraph(p) {
5688
5729
  };
5689
5730
  }
5690
5731
  }
5732
+ if (over) {
5733
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines, true, numberOn(m, spot)));
5734
+ return;
5735
+ }
5691
5736
  placed.push([
5692
5737
  spot.x0,
5693
5738
  spot.x0 + spot.lw,
@@ -5701,6 +5746,17 @@ function LayerGraph(p) {
5701
5746
  };
5702
5747
  marks.sort((m, n) => Number(!!m.up) - Number(!!n.up) || m.ty - n.ty || m.tx - n.tx).forEach((m) => place(m, false));
5703
5748
  later.forEach((m) => place(m, true));
5749
+ for (const o of numbered) labels.push(/* @__PURE__ */ jsx("span", {
5750
+ className: cx("ui-lg-num", o.m.dim && "is-dim", (hover === edgeId(o.m.e) || o.m.e === selEdge) && "is-on"),
5751
+ style: {
5752
+ left: o.x,
5753
+ top: o.y
5754
+ },
5755
+ "aria-hidden": "true",
5756
+ onPointerEnter: pickEdge ? () => setHover(edgeId(o.m.e)) : void 0,
5757
+ onPointerLeave: pickEdge ? () => setHover(null) : void 0,
5758
+ children: o.n
5759
+ }, "n" + o.m.idx));
5704
5760
  return {
5705
5761
  paths,
5706
5762
  labels,
@@ -5709,7 +5765,8 @@ function LayerGraph(p) {
5709
5765
  crowd,
5710
5766
  wide,
5711
5767
  least,
5712
- covered
5768
+ covered,
5769
+ numbered
5713
5770
  };
5714
5771
  };
5715
5772
  for (const id in laneCount) {
@@ -5747,7 +5804,9 @@ function LayerGraph(p) {
5747
5804
  W = Math.ceil(drawn.wide);
5748
5805
  drawn = draw();
5749
5806
  }
5750
- const { paths, labels, hitPaths } = drawn;
5807
+ const { paths, labels, hitPaths, numbered } = drawn;
5808
+ const firstX = Math.min(...main.filter((n) => pos[n.id]).map((n) => boxOf(n.id).x), W);
5809
+ const selBox = sel != null && pos[sel] ? boxOf(sel) : null;
5751
5810
  const sizeText = (n) => withNum(p.sizeLabel, n, () => byCount(n, "1 個項目", "{n} 個項目"));
5752
5811
  const externalText = p.externalLabel ?? tr("repo 外");
5753
5812
  const useText = p.useLabel ?? tr("使用 {n} 次");
@@ -5861,7 +5920,7 @@ function LayerGraph(p) {
5861
5920
  id: `${uid}-le`,
5862
5921
  className: "ui-lg-listtitle",
5863
5922
  children: p.listLabels?.edges ?? tr("關係")
5864
- }), /* @__PURE__ */ jsx("ul", { children: p.edges.filter((e) => nodeIds.has(e.from) && nodeIds.has(e.to)).map((e, i) => listItem(edgeId(e) + ":" + i, e === selEdge, focus && !related(e) && !(selShared && e.to === selShared), pickEdge && edges.includes(e) ? () => choose(e) : void 0, /* @__PURE__ */ jsxs(Fragment, { children: [
5923
+ }), /* @__PURE__ */ jsx("ul", { children: p.edges.filter((e) => nodeIds.has(e.from) && nodeIds.has(e.to)).map((e, i) => listItem(edgeId(e) + ":" + i, e === selListEdge, focus && !related(e) && !(selShared && e.to === selShared), pickEdge ? () => choose(e) : void 0, /* @__PURE__ */ jsxs(Fragment, { children: [
5865
5924
  /* @__PURE__ */ jsx("span", {
5866
5925
  className: "ui-lg-code",
5867
5926
  children: nameOf(e.from)
@@ -5879,6 +5938,32 @@ function LayerGraph(p) {
5879
5938
  })]
5880
5939
  });
5881
5940
  const showList = p.listView !== false && view === "list";
5941
+ const started = React.useRef("");
5942
+ React.useLayoutEffect(() => {
5943
+ const el = scrollRef.current;
5944
+ if (!el || showList || !fitted?.full || started.current === memKey) return;
5945
+ started.current = memKey;
5946
+ if (scrollMemory.get(memKey)) return;
5947
+ const x = selBox ? selBox.x + selBox.w / 2 - el.clientWidth / (2 * scale) : firstX - 16;
5948
+ el.scrollLeft = Math.max(0, x * scale);
5949
+ });
5950
+ const selX = selBox?.x;
5951
+ const selW = selBox?.w;
5952
+ React.useEffect(() => {
5953
+ const el = scrollRef.current;
5954
+ if (!el || showList || selX == null || selW == null) return;
5955
+ const l = selX * scale;
5956
+ const r = (selX + selW) * scale;
5957
+ if (l < el.scrollLeft) el.scrollLeft = Math.max(0, l - 16);
5958
+ else if (r > el.scrollLeft + el.clientWidth) el.scrollLeft = r - el.clientWidth + 16;
5959
+ }, [
5960
+ sel,
5961
+ selX,
5962
+ selW,
5963
+ scale,
5964
+ showList,
5965
+ scrollRef
5966
+ ]);
5882
5967
  const toggleShown = p.labelToggle !== false && !showList && p.edges.some((e) => lab(e));
5883
5968
  React.useLayoutEffect(() => {
5884
5969
  const el = scrollRef.current;
@@ -6033,6 +6118,18 @@ function LayerGraph(p) {
6033
6118
  show: overflows,
6034
6119
  done: scrolled
6035
6120
  }),
6121
+ showList || !numbered.length ? null : /* @__PURE__ */ jsx("ol", {
6122
+ className: "ui-lg-numlist",
6123
+ "aria-label": tr("編號的線"),
6124
+ children: numbered.map((o) => /* @__PURE__ */ jsxs("li", {
6125
+ className: cx(o.m.dim && "is-dim"),
6126
+ children: [/* @__PURE__ */ jsx("span", {
6127
+ className: "ui-lg-num is-static",
6128
+ "aria-hidden": "true",
6129
+ children: o.n
6130
+ }), /* @__PURE__ */ jsx("span", { children: labelParts(o.m.text) })]
6131
+ }, o.n))
6132
+ }),
6036
6133
  shared.length && !showList ? /* @__PURE__ */ jsxs("div", {
6037
6134
  className: "ui-lg-shared",
6038
6135
  children: [/* @__PURE__ */ jsx("div", {
@@ -6593,23 +6690,33 @@ const PS_STATUS = {
6593
6690
  /** The outlined chip in the top bar: which project is shown and whether its data is live; opens a list to switch. */
6594
6691
  function ProjectSwitcher({ project, status = "live", statusLabel, options = [], value, onChange, footer, className }) {
6595
6692
  const st = PS_STATUS[status] ? status : "live";
6596
- const label = `${project} · ${statusLabel || tr(PS_STATUS[st])}`;
6693
+ const stText = statusLabel || tr(PS_STATUS[st]);
6694
+ const label = `${project} · ${stText}`;
6597
6695
  const chip = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
6598
6696
  className: "ui-projsw-dot",
6599
6697
  "aria-hidden": "true"
6600
- }), /* @__PURE__ */ jsx("span", {
6698
+ }), /* @__PURE__ */ jsxs("span", {
6601
6699
  className: "ui-projsw-text",
6602
- children: label
6700
+ "aria-hidden": "true",
6701
+ children: [/* @__PURE__ */ jsx("span", {
6702
+ className: "ui-projsw-name",
6703
+ children: project
6704
+ }), /* @__PURE__ */ jsxs("span", {
6705
+ className: "ui-projsw-status",
6706
+ children: [" · ", stText]
6707
+ })]
6603
6708
  })] });
6604
6709
  if (!options.length || !onChange) return /* @__PURE__ */ jsx("span", {
6605
6710
  className: cx("ui-projsw", "is-" + st, "is-static", className),
6606
6711
  role: "status",
6607
6712
  "aria-label": label,
6713
+ title: label,
6608
6714
  children: chip
6609
6715
  });
6610
6716
  return /* @__PURE__ */ jsxs(Menu$1.Root, { children: [/* @__PURE__ */ jsxs(Menu$1.Trigger, {
6611
6717
  className: cx("ui-projsw", "is-" + st, className),
6612
6718
  "aria-label": tr("切換專案,目前是 {name}", { name: label }),
6719
+ title: label,
6613
6720
  children: [chip, /* @__PURE__ */ jsx(Icon, {
6614
6721
  name: "caret-down",
6615
6722
  size: 14,
@@ -7135,58 +7242,82 @@ function bounds(target) {
7135
7242
  bottom
7136
7243
  };
7137
7244
  }
7138
- /** Where the card goes for a highlighted box: the preferred side, the other one, then right or left of the box; inside
7139
- * the box at the bottom only when none has room (the tour scrolls first to make room above or below, see makeRoom).
7140
- * Returns the anchor line the card is placed against. */
7141
- function placeCard(rect, cardH, prefer, area, cardW = 320) {
7245
+ const area = (a, b) => Math.max(0, Math.min(a.left + a.width, b.left + b.width) - Math.max(a.left, b.left)) * Math.max(0, Math.min(a.top + a.height, b.top + b.height) - Math.max(a.top, b.top));
7246
+ /** Where the card goes for a highlighted box. Below, above, right, left (above first with side 'top'): the first
7247
+ * where the card fits inside the window and covers neither the target nor the parts the step keeps visible. When
7248
+ * none does (after the tour scrolled to make room, see makeRoom), the one that covers the least of the target, then
7249
+ * of those parts. Returns the card's box: it is placed at that box's top-left corner. */
7250
+ function placeCard(rect, cardH, prefer, area_, cardW = 320, keep = []) {
7142
7251
  const margin = typeof document === "undefined" ? 12 : edge();
7143
- const vh = area?.bottom ?? (typeof window === "undefined" ? 0 : window.innerHeight);
7144
- const vt = area?.top ?? 0;
7145
- const fits = (side) => rect ? side === "bottom" ? rect.top + rect.height + GAP + cardH + margin <= vh : rect.top - GAP - cardH - margin >= vt : false;
7252
+ const vw = typeof window === "undefined" ? 0 : window.innerWidth;
7253
+ const vh = area_?.bottom ?? (typeof window === "undefined" ? 0 : window.innerHeight);
7254
+ const vt = area_?.top ?? 0;
7146
7255
  if (!rect) return {
7147
7256
  mode: "center",
7148
- side: "top",
7149
- offset: 0,
7150
- margin,
7151
- line: {
7152
- left: 0,
7153
- top: Math.max(vt + margin + cardH, (vt + vh) / 2 + cardH / 2),
7154
- width: window.innerWidth,
7155
- height: 0
7156
- }
7157
- };
7158
- const other = prefer === "bottom" ? "top" : "bottom";
7159
- const side = fits(prefer) ? prefer : fits(other) ? other : null;
7160
- if (side) return {
7161
- mode: side,
7162
- side,
7163
- offset: GAP,
7164
- margin,
7165
- line: rect
7257
+ box: {
7258
+ left: (vw - cardW) / 2,
7259
+ top: Math.max(vt + margin, (vt + vh) / 2 - cardH / 2),
7260
+ width: cardW,
7261
+ height: cardH
7262
+ },
7263
+ fits: true
7166
7264
  };
7167
- const vw = typeof window === "undefined" ? 0 : window.innerWidth;
7168
- const tallOk = cardH + 2 * margin <= vh - vt;
7169
- const beside = ["right", "left"].find((sd) => tallOk && (sd === "right" ? rect.left + rect.width + GAP + cardW + margin <= vw : rect.left - GAP - cardW - margin >= 0));
7170
- if (beside) return {
7171
- mode: beside,
7172
- side: beside,
7173
- offset: GAP,
7174
- margin,
7175
- line: rect
7265
+ const clampX = (x) => Math.max(margin, Math.min(vw - margin - cardW, x));
7266
+ const clampY = (y) => Math.max(vt + margin, Math.min(vh - margin - cardH, y));
7267
+ const midX = rect.left + rect.width / 2 - cardW / 2;
7268
+ const midY = rect.top + rect.height / 2 - cardH / 2;
7269
+ const at = {
7270
+ bottom: {
7271
+ left: midX,
7272
+ top: rect.top + rect.height + GAP
7273
+ },
7274
+ top: {
7275
+ left: midX,
7276
+ top: rect.top - GAP - cardH
7277
+ },
7278
+ right: {
7279
+ left: rect.left + rect.width + GAP,
7280
+ top: midY
7281
+ },
7282
+ left: {
7283
+ left: rect.left - GAP - cardW,
7284
+ top: midY
7285
+ }
7176
7286
  };
7177
- const end = rect.top + rect.height;
7178
- const bottom = Math.max(vt + margin + cardH, end >= vh - margin ? vh - margin : end - margin);
7287
+ const options = (prefer === "top" ? [
7288
+ "top",
7289
+ "bottom",
7290
+ "right",
7291
+ "left"
7292
+ ] : [
7293
+ "bottom",
7294
+ "top",
7295
+ "right",
7296
+ "left"
7297
+ ]).map((side) => {
7298
+ const want = at[side];
7299
+ const box = {
7300
+ left: clampX(want.left),
7301
+ top: clampY(want.top),
7302
+ width: cardW,
7303
+ height: cardH
7304
+ };
7305
+ const inside = side === "bottom" || side === "top" ? box.top === want.top : box.left === want.left;
7306
+ const onTarget = area(box, rect);
7307
+ const onKept = keep.reduce((n, k) => n + area(box, k), 0);
7308
+ return {
7309
+ mode: side,
7310
+ box,
7311
+ fits: inside && !onTarget && !onKept,
7312
+ onTarget,
7313
+ onKept
7314
+ };
7315
+ });
7316
+ const best = options.find((o) => o.fits) ?? [...options].sort((x, y) => x.onTarget - y.onTarget || x.onKept - y.onKept)[0];
7179
7317
  return {
7180
- mode: "inside",
7181
- side: "top",
7182
- offset: 0,
7183
- margin,
7184
- line: {
7185
- left: rect.left,
7186
- top: bottom,
7187
- width: rect.width,
7188
- height: 0
7189
- }
7318
+ mode: best.mode,
7319
+ box: best.box,
7320
+ fits: best.fits
7190
7321
  };
7191
7322
  }
7192
7323
  /** The first-use walkthrough: the page goes dark except the part being introduced, with a card beside it. */
@@ -7195,6 +7326,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7195
7326
  const i = Math.max(0, Math.min(steps.length - 1, controlled ?? inner));
7196
7327
  const step = steps[i];
7197
7328
  const [rect, setRect] = React.useState(null);
7329
+ const [kept, setKept] = React.useState([]);
7198
7330
  const next = React.useRef(null);
7199
7331
  const [cardH, setCardH] = React.useState(0);
7200
7332
  const [cardW, setCardW] = React.useState(320);
@@ -7248,6 +7380,12 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7248
7380
  }, [open]);
7249
7381
  const target = step?.target;
7250
7382
  const pad = step?.padding ?? 6;
7383
+ const keepList = step?.keepVisible == null ? [] : Array.isArray(step.keepVisible) ? step.keepVisible : [step.keepVisible];
7384
+ const keepKey = keepList.map((k) => typeof k === "string" ? k : "#").join("|");
7385
+ const keepRef = React.useRef(keepList);
7386
+ React.useLayoutEffect(() => {
7387
+ keepRef.current = keepList;
7388
+ });
7251
7389
  const hasStep = !!step;
7252
7390
  React.useEffect(() => {
7253
7391
  if (!open || !hasStep) return;
@@ -7282,10 +7420,21 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7282
7420
  height: Math.max(0, Math.min(window.innerHeight - 3, r.bottom + pad) - t)
7283
7421
  };
7284
7422
  }
7285
- const k = JSON.stringify(v);
7423
+ const ks = [];
7424
+ for (const kt of keepRef.current) {
7425
+ const kr = findTarget(kt)?.getBoundingClientRect();
7426
+ if (kr && kr.width) ks.push({
7427
+ left: kr.left,
7428
+ top: kr.top,
7429
+ width: kr.width,
7430
+ height: kr.height
7431
+ });
7432
+ }
7433
+ const k = JSON.stringify([v, ks]);
7286
7434
  if (k !== last) {
7287
7435
  last = k;
7288
7436
  setRect(v);
7437
+ setKept(ks);
7289
7438
  }
7290
7439
  raf = requestAnimationFrame(tick);
7291
7440
  };
@@ -7296,7 +7445,8 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7296
7445
  hasStep,
7297
7446
  i,
7298
7447
  target,
7299
- pad
7448
+ pad,
7449
+ keepKey
7300
7450
  ]);
7301
7451
  const observer = React.useRef(null);
7302
7452
  const card = React.useCallback((el) => {
@@ -7322,7 +7472,12 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7322
7472
  const r = el.getBoundingClientRect();
7323
7473
  const top = r.top - pad;
7324
7474
  const bottom = r.bottom + pad;
7325
- if (bottom + GAP + cardH + m <= ar.bottom || top - GAP - cardH - m >= ar.top) return;
7475
+ if (placeCard({
7476
+ left: r.left - pad,
7477
+ top,
7478
+ width: r.width + 2 * pad,
7479
+ height: bottom - top
7480
+ }, cardH, step?.side ?? "bottom", ar, cardW, kept).fits) return;
7326
7481
  const want = bottom - top + GAP + cardH + 2 * m <= ar.bottom - ar.top ? ar.top + m + pad : ar.top + m + cardH + GAP + pad;
7327
7482
  let box = el.parentElement;
7328
7483
  while (box && !(/(auto|scroll)/.test(getComputedStyle(box).overflowY) && box.scrollHeight > box.clientHeight)) box = box.parentElement;
@@ -7344,15 +7499,11 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7344
7499
  measured,
7345
7500
  cardH
7346
7501
  ]);
7347
- const area = open && step ? bounds(findTarget(step.target)) : void 0;
7348
- const place = placeCard(rect, cardH, step?.side ?? "bottom", area, cardW);
7349
- const line = place.line;
7350
- const anchor = React.useMemo(() => ({ getBoundingClientRect: () => line ? new DOMRect(line.left, line.top, line.width, line.height) : new DOMRect(window.innerWidth / 2, window.innerHeight / 2, 0, 0) }), [
7351
- line?.left,
7352
- line?.top,
7353
- line?.width,
7354
- line?.height
7355
- ]);
7502
+ const room = open && step ? bounds(findTarget(step.target)) : void 0;
7503
+ const place = placeCard(rect, cardH, step?.side ?? "bottom", room, cardW, kept);
7504
+ const ax = place.box.left;
7505
+ const ay = place.box.top;
7506
+ const anchor = React.useMemo(() => ({ getBoundingClientRect: () => new DOMRect(ax, ay, 0, 0) }), [ax, ay]);
7356
7507
  if (!open || !step) return null;
7357
7508
  const lastStep = i === steps.length - 1;
7358
7509
  return /* @__PURE__ */ jsx(Popover$1.Root, {
@@ -7371,13 +7522,12 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7371
7522
  }), /* @__PURE__ */ jsx(Popover$1.Positioner, {
7372
7523
  className: "ui-float ui-tour-float",
7373
7524
  anchor,
7374
- side: place.side,
7375
- align: "center",
7376
- sideOffset: place.offset,
7377
- collisionPadding: place.margin,
7525
+ side: "bottom",
7526
+ align: "start",
7527
+ sideOffset: 0,
7378
7528
  collisionAvoidance: {
7379
7529
  side: "none",
7380
- align: "shift",
7530
+ align: "none",
7381
7531
  fallbackAxisSide: "none"
7382
7532
  },
7383
7533
  children: /* @__PURE__ */ jsxs(Popover$1.Popup, {