@seanyeh77/ui 0.13.0 → 0.15.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
@@ -1195,6 +1195,17 @@ function contrast(a, b) {
1195
1195
  const y = lum(b);
1196
1196
  return (Math.max(x, y) + .05) / (Math.min(x, y) + .05);
1197
1197
  }
1198
+ /** The accent's text color (accent-text): the accent itself when it reads on both bg and surface (4.5:1); else, in
1199
+ * light, the accent mixed with black 4 % at a time, in dark with white 5 % at a time, until it reads on both. Only
1200
+ * text changes: fills, bars, rings and dots keep the accent. */
1201
+ function accentText(hex, dark, bg, surface) {
1202
+ const reads = (c) => contrast(c, bg) >= 4.5 && contrast(c, surface) >= 4.5;
1203
+ const toward = dark ? "#ffffff" : "#000000";
1204
+ const step = dark ? .05 : .04;
1205
+ let text = hex;
1206
+ for (let k = 1; k * step <= 1 && !reads(text); k++) text = mixHex(hex, toward, k * step);
1207
+ return text;
1208
+ }
1198
1209
  /** Derives every accent token from one color (自訂強調色的換算 in docs/guidelines.md).
1199
1210
  * Returns false for anything but #rrggbb. quiet: apply without storing. */
1200
1211
  function setAccent(hex, quiet = false) {
@@ -1205,8 +1216,7 @@ function setAccent(hex, quiet = false) {
1205
1216
  const cs = getComputedStyle(root);
1206
1217
  const surface = (cs.getPropertyValue("--surface") || (dark ? "#393530" : "#ffffff")).trim();
1207
1218
  const bg = (cs.getPropertyValue("--bg") || (dark ? "#2f2a25" : "#fcfbfb")).trim();
1208
- let text = hex;
1209
- if (dark) for (let t = 0; t <= 1 && contrast(text, surface) < 4.5; t += .05) text = mixHex(hex, "#ffffff", t);
1219
+ const text = accentText(hex, dark, bg.startsWith("#") ? bg : dark ? "#2f2a25" : "#fcfbfb", surface.startsWith("#") ? surface : dark ? "#393530" : "#ffffff");
1210
1220
  const ink = "#171512";
1211
1221
  const vars = {
1212
1222
  "--accent": hex,
@@ -4933,6 +4943,7 @@ function LayerGraph(p) {
4933
4943
  onScroll();
4934
4944
  };
4935
4945
  const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
4946
+ const selListEdge = pickEdge && p.edges.find((e) => edgeId(e) === p.selectedEdge) || null;
4936
4947
  const nodeIdsAll = new Set(all.map((n) => n.id));
4937
4948
  const uses = {};
4938
4949
  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 +4978,12 @@ function LayerGraph(p) {
4967
4978
  };
4968
4979
  W += shift;
4969
4980
  }
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);
4981
+ const boxesLeft = () => Math.min(...main.map((n) => pos[n.id].x));
4982
+ const boxesRight = () => Math.max(0, ...main.map((n) => pos[n.id].x + NW));
4983
+ const laneX = (e) => onLeft(e) ? boxesLeft() - LANE - upsL.indexOf(e) * LANE_STEP : boxesRight() + LANE + upsR.indexOf(e) * LANE_STEP;
4984
+ const upLabelX = () => boxesLeft() - LANE + 8;
4985
+ const upLabelEndL = () => boxesRight() + LANE - 8;
4986
+ if (upsR.length) W = Math.max(W, boxesRight() + LANE + (upsR.length - 1) * LANE_STEP + PAD);
4976
4987
  const choose = (e) => {
4977
4988
  const id = edgeId(e);
4978
4989
  const next = p.selectedEdge === id ? null : id;
@@ -5258,7 +5269,7 @@ function LayerGraph(p) {
5258
5269
  idx,
5259
5270
  e,
5260
5271
  text,
5261
- tx: L ? upLabelX : upLabelEndL,
5272
+ tx: L ? upLabelX() : upLabelEndL(),
5262
5273
  ty: Math.round((y0 + y1) / 2),
5263
5274
  left: !L,
5264
5275
  r,
@@ -5425,18 +5436,19 @@ function LayerGraph(p) {
5425
5436
  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
5437
  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
5438
  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) => {
5439
+ const isMine = (idx, x0, lw, y0, y1) => {
5440
+ let self = Infinity;
5441
+ let other = Infinity;
5442
+ for (const sg of segs) {
5443
+ const d = gapTo(sg.box, x0, lw, y0, y1);
5444
+ if (sg.idx === idx) self = Math.min(self, d);
5445
+ else other = Math.min(other, d);
5446
+ }
5447
+ return self + 4 < other && other >= 8;
5448
+ };
5449
+ const alongLine = (m, own = true) => {
5429
5450
  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
- };
5451
+ const mine = (x0, lw, y0, y1) => isMine(m.idx, x0, lw, y0, y1);
5440
5452
  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
5453
  for (const lines of wraps(m.text)) {
5442
5454
  const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
@@ -5471,9 +5483,44 @@ function LayerGraph(p) {
5471
5483
  }
5472
5484
  return null;
5473
5485
  };
5474
- const labelEl = (m, x0, top, lines = [m.text], over = false) => /* @__PURE__ */ jsx("span", {
5486
+ const numbered = [];
5487
+ const numberOn = (m, near) => {
5488
+ const pts = ptsOf[m.idx] ?? [];
5489
+ const cx = near.x0 + near.lw / 2;
5490
+ const cy = near.top;
5491
+ let best = null;
5492
+ for (let k = 0; k + 1 < pts.length; k++) {
5493
+ const [x1, y1] = pts[k];
5494
+ const [x2, y2] = pts[k + 1];
5495
+ const len = Math.hypot(x2 - x1, y2 - y1);
5496
+ for (let t = 12; t <= len - 12; t += 4) {
5497
+ const x = x1 + (x2 - x1) * t / len;
5498
+ const y = y1 + (y2 - y1) * t / len;
5499
+ 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);
5500
+ const d = Math.hypot(x - cx, y - cy);
5501
+ if (!best || clear && !best.clear || clear === best.clear && d < best.d) best = {
5502
+ x,
5503
+ y,
5504
+ d,
5505
+ clear
5506
+ };
5507
+ }
5508
+ }
5509
+ const at = best ?? {
5510
+ x: m.tx,
5511
+ y: m.ty - 20
5512
+ };
5513
+ numbered.push({
5514
+ n: numbered.length + 1,
5515
+ m,
5516
+ x: Math.round(at.x),
5517
+ y: Math.round(at.y)
5518
+ });
5519
+ return numbered.length;
5520
+ };
5521
+ const labelEl = (m, x0, top, lines = [m.text], over = false, num = 0) => /* @__PURE__ */ jsx("span", {
5475
5522
  "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"),
5523
+ 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
5524
  style: {
5478
5525
  left: x0,
5479
5526
  top
@@ -5506,6 +5553,8 @@ function LayerGraph(p) {
5506
5553
  lh: 16,
5507
5554
  lines: [m.text]
5508
5555
  };
5556
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines, true, numberOn(m, spot)));
5557
+ return;
5509
5558
  }
5510
5559
  placed.push([
5511
5560
  spot.x0,
@@ -5539,7 +5588,7 @@ function LayerGraph(p) {
5539
5588
  const start0 = Math.max(10, Math.min(H - 10, m.ty));
5540
5589
  const find = (x0, lw, lh, withLines) => {
5541
5590
  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));
5591
+ 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
5592
  for (let k = 0; k <= 16; k++) for (const dir of k ? [-1, 1] : [0]) {
5544
5593
  const t = start0 + dir * k * 18;
5545
5594
  if (t - lh / 2 >= 2 && t + lh / 2 <= H - 2 && !bad(t - lh / 2, t + lh / 2)) return t;
@@ -5571,13 +5620,15 @@ function LayerGraph(p) {
5571
5620
  const x0 = x0Of(w);
5572
5621
  const top = find(x0, w, 16, false);
5573
5622
  if (top == null) crowd.add(g);
5574
- spot = {
5623
+ const at = {
5575
5624
  x0,
5576
5625
  top: top ?? start0,
5577
5626
  lw: w,
5578
5627
  lh: 16,
5579
5628
  lines: [m.text]
5580
5629
  };
5630
+ labels.push(labelEl(m, at.x0, at.top, at.lines, true, numberOn(m, at)));
5631
+ return;
5581
5632
  }
5582
5633
  placed.push([
5583
5634
  spot.x0,
@@ -5688,6 +5739,10 @@ function LayerGraph(p) {
5688
5739
  };
5689
5740
  }
5690
5741
  }
5742
+ if (over) {
5743
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines, true, numberOn(m, spot)));
5744
+ return;
5745
+ }
5691
5746
  placed.push([
5692
5747
  spot.x0,
5693
5748
  spot.x0 + spot.lw,
@@ -5701,6 +5756,17 @@ function LayerGraph(p) {
5701
5756
  };
5702
5757
  marks.sort((m, n) => Number(!!m.up) - Number(!!n.up) || m.ty - n.ty || m.tx - n.tx).forEach((m) => place(m, false));
5703
5758
  later.forEach((m) => place(m, true));
5759
+ for (const o of numbered) labels.push(/* @__PURE__ */ jsx("span", {
5760
+ className: cx("ui-lg-num", o.m.dim && "is-dim", (hover === edgeId(o.m.e) || o.m.e === selEdge) && "is-on"),
5761
+ style: {
5762
+ left: o.x,
5763
+ top: o.y
5764
+ },
5765
+ "aria-hidden": "true",
5766
+ onPointerEnter: pickEdge ? () => setHover(edgeId(o.m.e)) : void 0,
5767
+ onPointerLeave: pickEdge ? () => setHover(null) : void 0,
5768
+ children: o.n
5769
+ }, "n" + o.m.idx));
5704
5770
  return {
5705
5771
  paths,
5706
5772
  labels,
@@ -5709,7 +5775,8 @@ function LayerGraph(p) {
5709
5775
  crowd,
5710
5776
  wide,
5711
5777
  least,
5712
- covered
5778
+ covered,
5779
+ numbered
5713
5780
  };
5714
5781
  };
5715
5782
  for (const id in laneCount) {
@@ -5747,7 +5814,9 @@ function LayerGraph(p) {
5747
5814
  W = Math.ceil(drawn.wide);
5748
5815
  drawn = draw();
5749
5816
  }
5750
- const { paths, labels, hitPaths } = drawn;
5817
+ const { paths, labels, hitPaths, numbered } = drawn;
5818
+ const firstX = Math.min(...main.filter((n) => pos[n.id]).map((n) => boxOf(n.id).x), W);
5819
+ const selBox = sel != null && pos[sel] ? boxOf(sel) : null;
5751
5820
  const sizeText = (n) => withNum(p.sizeLabel, n, () => byCount(n, "1 個項目", "{n} 個項目"));
5752
5821
  const externalText = p.externalLabel ?? tr("repo 外");
5753
5822
  const useText = p.useLabel ?? tr("使用 {n} 次");
@@ -5861,7 +5930,7 @@ function LayerGraph(p) {
5861
5930
  id: `${uid}-le`,
5862
5931
  className: "ui-lg-listtitle",
5863
5932
  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: [
5933
+ }), /* @__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
5934
  /* @__PURE__ */ jsx("span", {
5866
5935
  className: "ui-lg-code",
5867
5936
  children: nameOf(e.from)
@@ -5879,6 +5948,32 @@ function LayerGraph(p) {
5879
5948
  })]
5880
5949
  });
5881
5950
  const showList = p.listView !== false && view === "list";
5951
+ const started = React.useRef("");
5952
+ React.useLayoutEffect(() => {
5953
+ const el = scrollRef.current;
5954
+ if (!el || showList || !fitted?.full || started.current === memKey) return;
5955
+ started.current = memKey;
5956
+ if (scrollMemory.get(memKey)) return;
5957
+ const x = selBox ? selBox.x + selBox.w / 2 - el.clientWidth / (2 * scale) : firstX - 16;
5958
+ el.scrollLeft = Math.max(0, x * scale);
5959
+ });
5960
+ const selX = selBox?.x;
5961
+ const selW = selBox?.w;
5962
+ React.useEffect(() => {
5963
+ const el = scrollRef.current;
5964
+ if (!el || showList || selX == null || selW == null) return;
5965
+ const l = selX * scale;
5966
+ const r = (selX + selW) * scale;
5967
+ if (l < el.scrollLeft) el.scrollLeft = Math.max(0, l - 16);
5968
+ else if (r > el.scrollLeft + el.clientWidth) el.scrollLeft = r - el.clientWidth + 16;
5969
+ }, [
5970
+ sel,
5971
+ selX,
5972
+ selW,
5973
+ scale,
5974
+ showList,
5975
+ scrollRef
5976
+ ]);
5882
5977
  const toggleShown = p.labelToggle !== false && !showList && p.edges.some((e) => lab(e));
5883
5978
  React.useLayoutEffect(() => {
5884
5979
  const el = scrollRef.current;
@@ -6033,6 +6128,18 @@ function LayerGraph(p) {
6033
6128
  show: overflows,
6034
6129
  done: scrolled
6035
6130
  }),
6131
+ showList || !numbered.length ? null : /* @__PURE__ */ jsx("ol", {
6132
+ className: "ui-lg-numlist",
6133
+ "aria-label": tr("編號的線"),
6134
+ children: numbered.map((o) => /* @__PURE__ */ jsxs("li", {
6135
+ className: cx(o.m.dim && "is-dim"),
6136
+ children: [/* @__PURE__ */ jsx("span", {
6137
+ className: "ui-lg-num is-static",
6138
+ "aria-hidden": "true",
6139
+ children: o.n
6140
+ }), /* @__PURE__ */ jsx("span", { children: labelParts(o.m.text) })]
6141
+ }, o.n))
6142
+ }),
6036
6143
  shared.length && !showList ? /* @__PURE__ */ jsxs("div", {
6037
6144
  className: "ui-lg-shared",
6038
6145
  children: [/* @__PURE__ */ jsx("div", {
@@ -6593,23 +6700,33 @@ const PS_STATUS = {
6593
6700
  /** The outlined chip in the top bar: which project is shown and whether its data is live; opens a list to switch. */
6594
6701
  function ProjectSwitcher({ project, status = "live", statusLabel, options = [], value, onChange, footer, className }) {
6595
6702
  const st = PS_STATUS[status] ? status : "live";
6596
- const label = `${project} · ${statusLabel || tr(PS_STATUS[st])}`;
6703
+ const stText = statusLabel || tr(PS_STATUS[st]);
6704
+ const label = `${project} · ${stText}`;
6597
6705
  const chip = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
6598
6706
  className: "ui-projsw-dot",
6599
6707
  "aria-hidden": "true"
6600
- }), /* @__PURE__ */ jsx("span", {
6708
+ }), /* @__PURE__ */ jsxs("span", {
6601
6709
  className: "ui-projsw-text",
6602
- children: label
6710
+ "aria-hidden": "true",
6711
+ children: [/* @__PURE__ */ jsx("span", {
6712
+ className: "ui-projsw-name",
6713
+ children: project
6714
+ }), /* @__PURE__ */ jsxs("span", {
6715
+ className: "ui-projsw-status",
6716
+ children: [" · ", stText]
6717
+ })]
6603
6718
  })] });
6604
6719
  if (!options.length || !onChange) return /* @__PURE__ */ jsx("span", {
6605
6720
  className: cx("ui-projsw", "is-" + st, "is-static", className),
6606
6721
  role: "status",
6607
6722
  "aria-label": label,
6723
+ title: label,
6608
6724
  children: chip
6609
6725
  });
6610
6726
  return /* @__PURE__ */ jsxs(Menu$1.Root, { children: [/* @__PURE__ */ jsxs(Menu$1.Trigger, {
6611
6727
  className: cx("ui-projsw", "is-" + st, className),
6612
6728
  "aria-label": tr("切換專案,目前是 {name}", { name: label }),
6729
+ title: label,
6613
6730
  children: [chip, /* @__PURE__ */ jsx(Icon, {
6614
6731
  name: "caret-down",
6615
6732
  size: 14,
@@ -7135,58 +7252,82 @@ function bounds(target) {
7135
7252
  bottom
7136
7253
  };
7137
7254
  }
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) {
7255
+ 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));
7256
+ /** Where the card goes for a highlighted box. Below, above, right, left (above first with side 'top'): the first
7257
+ * where the card fits inside the window and covers neither the target nor the parts the step keeps visible. When
7258
+ * none does (after the tour scrolled to make room, see makeRoom), the one that covers the least of the target, then
7259
+ * of those parts. Returns the card's box: it is placed at that box's top-left corner. */
7260
+ function placeCard(rect, cardH, prefer, area_, cardW = 320, keep = []) {
7142
7261
  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;
7262
+ const vw = typeof window === "undefined" ? 0 : window.innerWidth;
7263
+ const vh = area_?.bottom ?? (typeof window === "undefined" ? 0 : window.innerHeight);
7264
+ const vt = area_?.top ?? 0;
7146
7265
  if (!rect) return {
7147
7266
  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
7267
+ box: {
7268
+ left: (vw - cardW) / 2,
7269
+ top: Math.max(vt + margin, (vt + vh) / 2 - cardH / 2),
7270
+ width: cardW,
7271
+ height: cardH
7272
+ },
7273
+ fits: true
7166
7274
  };
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
7275
+ const clampX = (x) => Math.max(margin, Math.min(vw - margin - cardW, x));
7276
+ const clampY = (y) => Math.max(vt + margin, Math.min(vh - margin - cardH, y));
7277
+ const midX = rect.left + rect.width / 2 - cardW / 2;
7278
+ const midY = rect.top + rect.height / 2 - cardH / 2;
7279
+ const at = {
7280
+ bottom: {
7281
+ left: midX,
7282
+ top: rect.top + rect.height + GAP
7283
+ },
7284
+ top: {
7285
+ left: midX,
7286
+ top: rect.top - GAP - cardH
7287
+ },
7288
+ right: {
7289
+ left: rect.left + rect.width + GAP,
7290
+ top: midY
7291
+ },
7292
+ left: {
7293
+ left: rect.left - GAP - cardW,
7294
+ top: midY
7295
+ }
7176
7296
  };
7177
- const end = rect.top + rect.height;
7178
- const bottom = Math.max(vt + margin + cardH, end >= vh - margin ? vh - margin : end - margin);
7297
+ const options = (prefer === "top" ? [
7298
+ "top",
7299
+ "bottom",
7300
+ "right",
7301
+ "left"
7302
+ ] : [
7303
+ "bottom",
7304
+ "top",
7305
+ "right",
7306
+ "left"
7307
+ ]).map((side) => {
7308
+ const want = at[side];
7309
+ const box = {
7310
+ left: clampX(want.left),
7311
+ top: clampY(want.top),
7312
+ width: cardW,
7313
+ height: cardH
7314
+ };
7315
+ const inside = side === "bottom" || side === "top" ? box.top === want.top : box.left === want.left;
7316
+ const onTarget = area(box, rect);
7317
+ const onKept = keep.reduce((n, k) => n + area(box, k), 0);
7318
+ return {
7319
+ mode: side,
7320
+ box,
7321
+ fits: inside && !onTarget && !onKept,
7322
+ onTarget,
7323
+ onKept
7324
+ };
7325
+ });
7326
+ const best = options.find((o) => o.fits) ?? [...options].sort((x, y) => x.onTarget - y.onTarget || x.onKept - y.onKept)[0];
7179
7327
  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
- }
7328
+ mode: best.mode,
7329
+ box: best.box,
7330
+ fits: best.fits
7190
7331
  };
7191
7332
  }
7192
7333
  /** The first-use walkthrough: the page goes dark except the part being introduced, with a card beside it. */
@@ -7195,6 +7336,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7195
7336
  const i = Math.max(0, Math.min(steps.length - 1, controlled ?? inner));
7196
7337
  const step = steps[i];
7197
7338
  const [rect, setRect] = React.useState(null);
7339
+ const [kept, setKept] = React.useState([]);
7198
7340
  const next = React.useRef(null);
7199
7341
  const [cardH, setCardH] = React.useState(0);
7200
7342
  const [cardW, setCardW] = React.useState(320);
@@ -7248,6 +7390,12 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7248
7390
  }, [open]);
7249
7391
  const target = step?.target;
7250
7392
  const pad = step?.padding ?? 6;
7393
+ const keepList = step?.keepVisible == null ? [] : Array.isArray(step.keepVisible) ? step.keepVisible : [step.keepVisible];
7394
+ const keepKey = keepList.map((k) => typeof k === "string" ? k : "#").join("|");
7395
+ const keepRef = React.useRef(keepList);
7396
+ React.useLayoutEffect(() => {
7397
+ keepRef.current = keepList;
7398
+ });
7251
7399
  const hasStep = !!step;
7252
7400
  React.useEffect(() => {
7253
7401
  if (!open || !hasStep) return;
@@ -7282,10 +7430,21 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7282
7430
  height: Math.max(0, Math.min(window.innerHeight - 3, r.bottom + pad) - t)
7283
7431
  };
7284
7432
  }
7285
- const k = JSON.stringify(v);
7433
+ const ks = [];
7434
+ for (const kt of keepRef.current) {
7435
+ const kr = findTarget(kt)?.getBoundingClientRect();
7436
+ if (kr && kr.width) ks.push({
7437
+ left: kr.left,
7438
+ top: kr.top,
7439
+ width: kr.width,
7440
+ height: kr.height
7441
+ });
7442
+ }
7443
+ const k = JSON.stringify([v, ks]);
7286
7444
  if (k !== last) {
7287
7445
  last = k;
7288
7446
  setRect(v);
7447
+ setKept(ks);
7289
7448
  }
7290
7449
  raf = requestAnimationFrame(tick);
7291
7450
  };
@@ -7296,7 +7455,8 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7296
7455
  hasStep,
7297
7456
  i,
7298
7457
  target,
7299
- pad
7458
+ pad,
7459
+ keepKey
7300
7460
  ]);
7301
7461
  const observer = React.useRef(null);
7302
7462
  const card = React.useCallback((el) => {
@@ -7322,7 +7482,12 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7322
7482
  const r = el.getBoundingClientRect();
7323
7483
  const top = r.top - pad;
7324
7484
  const bottom = r.bottom + pad;
7325
- if (bottom + GAP + cardH + m <= ar.bottom || top - GAP - cardH - m >= ar.top) return;
7485
+ if (placeCard({
7486
+ left: r.left - pad,
7487
+ top,
7488
+ width: r.width + 2 * pad,
7489
+ height: bottom - top
7490
+ }, cardH, step?.side ?? "bottom", ar, cardW, kept).fits) return;
7326
7491
  const want = bottom - top + GAP + cardH + 2 * m <= ar.bottom - ar.top ? ar.top + m + pad : ar.top + m + cardH + GAP + pad;
7327
7492
  let box = el.parentElement;
7328
7493
  while (box && !(/(auto|scroll)/.test(getComputedStyle(box).overflowY) && box.scrollHeight > box.clientHeight)) box = box.parentElement;
@@ -7344,15 +7509,11 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7344
7509
  measured,
7345
7510
  cardH
7346
7511
  ]);
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
- ]);
7512
+ const room = open && step ? bounds(findTarget(step.target)) : void 0;
7513
+ const place = placeCard(rect, cardH, step?.side ?? "bottom", room, cardW, kept);
7514
+ const ax = place.box.left;
7515
+ const ay = place.box.top;
7516
+ const anchor = React.useMemo(() => ({ getBoundingClientRect: () => new DOMRect(ax, ay, 0, 0) }), [ax, ay]);
7356
7517
  if (!open || !step) return null;
7357
7518
  const lastStep = i === steps.length - 1;
7358
7519
  return /* @__PURE__ */ jsx(Popover$1.Root, {
@@ -7371,13 +7532,12 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
7371
7532
  }), /* @__PURE__ */ jsx(Popover$1.Positioner, {
7372
7533
  className: "ui-float ui-tour-float",
7373
7534
  anchor,
7374
- side: place.side,
7375
- align: "center",
7376
- sideOffset: place.offset,
7377
- collisionPadding: place.margin,
7535
+ side: "bottom",
7536
+ align: "start",
7537
+ sideOffset: 0,
7378
7538
  collisionAvoidance: {
7379
7539
  side: "none",
7380
- align: "shift",
7540
+ align: "none",
7381
7541
  fallbackAxisSide: "none"
7382
7542
  },
7383
7543
  children: /* @__PURE__ */ jsxs(Popover$1.Popup, {