@seanyeh77/ui 0.9.0 → 0.10.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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { a as parseDate, c as addMessages, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-CbNdiURz.js";
2
+ import { a as parseDate, c as addMessages, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-BoMMgOww.js";
3
3
  import * as React from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { Tooltip as Tooltip$1 } from "@base-ui/react/tooltip";
@@ -99,7 +99,8 @@ const PH = {
99
99
  "terminal-window": "<path d=\"M128,128a8,8,0,0,1-3,6.25l-40,32a8,8,0,1,1-10-12.5L107.19,128,75,102.25a8,8,0,1,1,10-12.5l40,32A8,8,0,0,1,128,128Zm48,24H136a8,8,0,0,0,0,16h40a8,8,0,0,0,0-16Zm56-96V200a16,16,0,0,1-16,16H40a16,16,0,0,1-16-16V56A16,16,0,0,1,40,40H216A16,16,0,0,1,232,56ZM216,200V56H40V200H216Z\"/>",
100
100
  "file-code": "<path d=\"M181.66,146.34a8,8,0,0,1,0,11.32l-24,24a8,8,0,0,1-11.32-11.32L164.69,152l-18.35-18.34a8,8,0,0,1,11.32-11.32Zm-72-24a8,8,0,0,0-11.32,0l-24,24a8,8,0,0,0,0,11.32l24,24a8,8,0,0,0,11.32-11.32L91.31,152l18.35-18.34A8,8,0,0,0,109.66,122.34ZM216,88V216a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-56-8h28.69L160,51.31Zm40,136V96H152a8,8,0,0,1-8-8V40H56V216H200Z\"/>",
101
101
  hash: "<path d=\"M224,88H175.4l8.47-46.57a8,8,0,0,0-15.74-2.86l-9,49.43H111.4l8.47-46.57a8,8,0,0,0-15.74-2.86L95.14,88H48a8,8,0,0,0,0,16H92.23L83.5,152H32a8,8,0,0,0,0,16H80.6l-8.47,46.57a8,8,0,0,0,6.44,9.3A7.79,7.79,0,0,0,80,224a8,8,0,0,0,7.86-6.57l9-49.43H144.6l-8.47,46.57a8,8,0,0,0,6.44,9.3A7.79,7.79,0,0,0,144,224a8,8,0,0,0,7.86-6.57l9-49.43H208a8,8,0,0,0,0-16H163.77l8.73-48H224a8,8,0,0,0,0-16Zm-76.5,64H99.77l8.73-48h47.73Z\"/>",
102
- command: "<path d=\"M180,144H160V112h20a36,36,0,1,0-36-36V96H112V76a36,36,0,1,0-36,36H96v32H76a36,36,0,1,0,36,36V160h32v20a36,36,0,1,0,36-36ZM160,76a20,20,0,1,1,20,20H160ZM56,76a20,20,0,0,1,40,0V96H76A20,20,0,0,1,56,76ZM96,180a20,20,0,1,1-20-20H96Zm16-68h32v32H112Zm68,88a20,20,0,0,1-20-20V160h20a20,20,0,0,1,0,40Z\"/>"
102
+ command: "<path d=\"M180,144H160V112h20a36,36,0,1,0-36-36V96H112V76a36,36,0,1,0-36,36H96v32H76a36,36,0,1,0,36,36V160h32v20a36,36,0,1,0,36-36ZM160,76a20,20,0,1,1,20,20H160ZM56,76a20,20,0,0,1,40,0V96H76A20,20,0,0,1,56,76ZM96,180a20,20,0,1,1-20-20H96Zm16-68h32v32H112Zm68,88a20,20,0,0,1-20-20V160h20a20,20,0,0,1,0,40Z\"/>",
103
+ tag: "<path d=\"M243.31,136,144,36.69A15.86,15.86,0,0,0,132.69,32H40a8,8,0,0,0-8,8v92.69A15.86,15.86,0,0,0,36.69,144L136,243.31a16,16,0,0,0,22.63,0l84.68-84.68a16,16,0,0,0,0-22.63Zm-96,96L48,132.69V48h84.69L232,147.31ZM96,84A12,12,0,1,1,84,72,12,12,0,0,1,96,84Z\"/>"
103
104
  };
104
105
  const PH_FILL = {
105
106
  archive: "<path d=\"M224,48H32A16,16,0,0,0,16,64V88a16,16,0,0,0,16,16v88a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V104a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm-72,96H104a8,8,0,0,1,0-16h48a8,8,0,0,1,0,16Zm72-56H32V64H224V88Z\"/>",
@@ -191,7 +192,8 @@ const PH_FILL = {
191
192
  "terminal-window": "<path d=\"M216,40H40A16,16,0,0,0,24,56V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V56A16,16,0,0,0,216,40Zm-91,94.25-40,32a8,8,0,1,1-10-12.5L107.19,128,75,102.25a8,8,0,1,1,10-12.5l40,32a8,8,0,0,1,0,12.5ZM176,168H136a8,8,0,0,1,0-16h40a8,8,0,0,1,0,16Z\"/>",
192
193
  "file-code": "<path d=\"M213.66,82.34l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40V216a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34Zm-104,88a8,8,0,0,1-11.32,11.32l-24-24a8,8,0,0,1,0-11.32l24-24a8,8,0,0,1,11.32,11.32L91.31,152Zm72-12.68-24,24a8,8,0,0,1-11.32-11.32L164.69,152l-18.35-18.34a8,8,0,0,1,11.32-11.32l24,24A8,8,0,0,1,181.66,157.66ZM152,88V44l44,44Z\"/>",
193
194
  hash: "<path d=\"M116.25,112h31.5l-8,32h-31.5ZM224,48V208a16,16,0,0,1-16,16H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48Zm-16,56a8,8,0,0,0-8-8H168.25l7.51-30.06a8,8,0,0,0-15.52-3.88L151.75,96h-31.5l7.51-30.06a8,8,0,0,0-15.52-3.88L103.75,96H64a8,8,0,0,0,0,16H99.75l-8,32H56a8,8,0,0,0,0,16H87.75l-7.51,30.06a8,8,0,0,0,5.82,9.7,8.13,8.13,0,0,0,2,.24,8,8,0,0,0,7.75-6.06L104.25,160h31.5l-7.51,30.06a8,8,0,0,0,5.82,9.7A8.13,8.13,0,0,0,136,200a8,8,0,0,0,7.75-6.06L152.25,160H192a8,8,0,0,0,0-16H156.25l8-32H200A8,8,0,0,0,208,104Z\"/>",
194
- command: "<path d=\"M116,116h24v24H116ZM86,72a14,14,0,0,0,0,28h14V86A14,14,0,0,0,86,72Zm98,14a14,14,0,0,0-28,0v14h14A14,14,0,0,0,184,86ZM72,170a14,14,0,0,0,28,0V156H86A14,14,0,0,0,72,170ZM224,48V208a16,16,0,0,1-16,16H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48Zm-68,92V116h14a30,30,0,1,0-30-30v14H116V86a30,30,0,1,0-30,30h14v24H86a30,30,0,1,0,30,30V156h24v14a30,30,0,1,0,30-30Zm0,30a14,14,0,1,0,14-14H156Z\"/>"
195
+ command: "<path d=\"M116,116h24v24H116ZM86,72a14,14,0,0,0,0,28h14V86A14,14,0,0,0,86,72Zm98,14a14,14,0,0,0-28,0v14h14A14,14,0,0,0,184,86ZM72,170a14,14,0,0,0,28,0V156H86A14,14,0,0,0,72,170ZM224,48V208a16,16,0,0,1-16,16H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48Zm-68,92V116h14a30,30,0,1,0-30-30v14H116V86a30,30,0,1,0-30,30h14v24H86a30,30,0,1,0,30,30V156h24v14a30,30,0,1,0,30-30Zm0,30a14,14,0,1,0,14-14H156Z\"/>",
196
+ tag: "<path d=\"M243.31,136,144,36.69A15.86,15.86,0,0,0,132.69,32H40a8,8,0,0,0-8,8v92.69A15.86,15.86,0,0,0,36.69,144L136,243.31a16,16,0,0,0,22.63,0l84.68-84.68a16,16,0,0,0,0-22.63ZM84,96A12,12,0,1,1,96,84,12,12,0,0,1,84,96Z\"/>"
195
197
  };
196
198
  /** Lucide names that map to a Phosphor icon. */
197
199
  const PH_ALIAS = {
@@ -695,13 +697,16 @@ function Tooltip({ label, side = "top", describe = true, wrap = false, disabled
695
697
  }
696
698
  // src/components/IconButton/IconButton.tsx
697
699
  /** A square icon-only button with a tooltip. */
698
- function IconButton({ label, icon, className, tooltip = true, ...native }) {
700
+ function IconButton({ label, icon, className, tooltip = true, filled, ...native }) {
699
701
  const btn = /* @__PURE__ */ jsx("button", {
700
702
  type: "button",
701
703
  ...native,
702
704
  className: cx("ui-iconbtn", className),
703
705
  "aria-label": label,
704
- children: /* @__PURE__ */ jsx(IconOf, { icon })
706
+ children: /* @__PURE__ */ jsx(IconOf, {
707
+ icon,
708
+ filled
709
+ })
705
710
  });
706
711
  return tooltip ? /* @__PURE__ */ jsx(Tooltip, {
707
712
  label,
@@ -2540,7 +2545,23 @@ function useScrollHint() {
2540
2545
  const ro = new ResizeObserver(measure);
2541
2546
  ro.observe(el);
2542
2547
  if (el.firstElementChild) ro.observe(el.firstElementChild);
2543
- return () => ro.disconnect();
2548
+ let raf = 0;
2549
+ const later = () => {
2550
+ cancelAnimationFrame(raf);
2551
+ raf = requestAnimationFrame(measure);
2552
+ };
2553
+ const mo = new MutationObserver(later);
2554
+ mo.observe(el, {
2555
+ childList: true,
2556
+ subtree: true,
2557
+ characterData: true
2558
+ });
2559
+ document.fonts?.ready.then(later).catch(() => {});
2560
+ return () => {
2561
+ ro.disconnect();
2562
+ mo.disconnect();
2563
+ cancelAnimationFrame(raf);
2564
+ };
2544
2565
  }, [measure]);
2545
2566
  return {
2546
2567
  ref,
@@ -2675,7 +2696,8 @@ function writeUrl(prefix, filters, values, q) {
2675
2696
  }
2676
2697
  // src/internal/FloatingPanel.tsx
2677
2698
  /** A positioned panel next to its trigger: flips when there is no room, closes on Esc and outside press, returns focus. */
2678
- function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, children, ...aria }) {
2699
+ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, boundary, children, ...aria }) {
2700
+ const within = boundary?.current ?? void 0;
2679
2701
  return /* @__PURE__ */ jsxs(Popover$1.Root, {
2680
2702
  open,
2681
2703
  onOpenChange,
@@ -2690,6 +2712,12 @@ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "
2690
2712
  align,
2691
2713
  sideOffset,
2692
2714
  anchor,
2715
+ collisionBoundary: within,
2716
+ collisionPadding: within ? 0 : void 0,
2717
+ collisionAvoidance: within ? {
2718
+ side: "flip",
2719
+ align: "shift"
2720
+ } : void 0,
2693
2721
  children: /* @__PURE__ */ jsx(Popover$1.Popup, {
2694
2722
  className,
2695
2723
  "aria-label": aria["aria-label"],
@@ -2755,11 +2783,12 @@ function ColumnMenu({ cols, hidden, onToggle }) {
2755
2783
  });
2756
2784
  }
2757
2785
  /** 「篩選」 with the number of active filters; options apply at once and show how many rows they would leave. */
2758
- function FilterButton({ filters, values, activeCount, count, onChange, onClear }) {
2786
+ function FilterButton({ filters, values, activeCount, count, onChange, onClear, boundary }) {
2759
2787
  const [open, setOpen] = React.useState(false);
2760
2788
  return /* @__PURE__ */ jsxs(FloatingPanel, {
2761
2789
  open,
2762
2790
  onOpenChange: setOpen,
2791
+ boundary,
2763
2792
  className: "ui-dt-filterpop",
2764
2793
  "aria-label": tr("篩選"),
2765
2794
  trigger: /* @__PURE__ */ jsxs("button", {
@@ -2870,6 +2899,23 @@ function FilterButton({ filters, values, activeCount, count, onChange, onClear }
2870
2899
  })]
2871
2900
  });
2872
2901
  }
2902
+ /** A short cell with its whole text in a Tooltip (a mouse; not on a touch screen, where the row's details show it). */
2903
+ function FullText({ text, children }) {
2904
+ const touch = useMedia(TOUCH_ONLY);
2905
+ return /* @__PURE__ */ jsx(Tooltip, {
2906
+ label: text,
2907
+ wrap: true,
2908
+ describe: false,
2909
+ disabled: touch || !text,
2910
+ children: /* @__PURE__ */ jsxs("span", {
2911
+ className: "ui-dt-full",
2912
+ children: [children, text ? /* @__PURE__ */ jsx("span", {
2913
+ className: "ui-visually-hidden",
2914
+ children: tr(",") + text
2915
+ }) : null]
2916
+ })
2917
+ });
2918
+ }
2873
2919
  /** Long text in a cell. Phone cards: at most 2 lines with 「顯示全部」. Desktop: one line; the row's caret shows it in
2874
2920
  * full below the row, and with a mouse, hover or focus on a cut-off cell shows it in a Tooltip. No Tooltip on a touch
2875
2921
  * screen: a tap would leave it over the next rows. */
@@ -2937,6 +2983,7 @@ const ARROWS = {
2937
2983
  };
2938
2984
  const get = (row, key) => row[key];
2939
2985
  const isNum = (c) => c.numeric || c.format === "money" || c.format === "percent";
2986
+ const ROW_CONTROLS = "a, button, input, select, textarea, label, [role=\"checkbox\"], [role=\"button\"], [role=\"menuitem\"], [role=\"link\"], [contenteditable]";
2940
2987
  function RowCheck({ v, label, onClick }) {
2941
2988
  return /* @__PURE__ */ jsx("button", {
2942
2989
  type: "button",
@@ -2984,6 +3031,7 @@ function DataTable(p) {
2984
3031
  const [opened, setOpened] = React.useState({});
2985
3032
  const narrow = useNarrow();
2986
3033
  const uid = React.useId();
3034
+ const rootRef = React.useRef(null);
2987
3035
  const [sel, setSel] = React.useState({});
2988
3036
  const [sumVal, setSumVal] = React.useState("all");
2989
3037
  const [resetKey, setResetKey] = React.useState(p.resetKey);
@@ -3193,7 +3241,7 @@ function DataTable(p) {
3193
3241
  const m = c.mobile || (!hasTitle && ci === 0 ? "title" : null);
3194
3242
  return m ? "is-m-" + m : null;
3195
3243
  };
3196
- const longCols = shownCols.filter((c) => c.long);
3244
+ const longCols = shownCols.filter((c) => c.long || c.fullText);
3197
3245
  const expander = longCols.length > 0 && !narrow;
3198
3246
  const EXP = 40;
3199
3247
  const template = [
@@ -3306,7 +3354,13 @@ function DataTable(p) {
3306
3354
  else v = markMatch(cellText(c, raw), mark);
3307
3355
  return v;
3308
3356
  };
3309
- const cell = (r, c) => c.long ? /* @__PURE__ */ jsx(LongText, { children: cellInner(r, c) }) : cellInner(r, c);
3357
+ const cell = (r, c) => {
3358
+ const v = c.long ? /* @__PURE__ */ jsx(LongText, { children: cellInner(r, c) }) : cellInner(r, c);
3359
+ return c.fullText ? /* @__PURE__ */ jsx(FullText, {
3360
+ text: c.fullText(r),
3361
+ children: v
3362
+ }) : v;
3363
+ };
3310
3364
  const total = (c, ci) => {
3311
3365
  const how = p.totals?.[c.key];
3312
3366
  const rowsAll = list.map((x) => x.r);
@@ -3323,6 +3377,7 @@ function DataTable(p) {
3323
3377
  return "";
3324
3378
  };
3325
3379
  return /* @__PURE__ */ jsxs("div", {
3380
+ ref: rootRef,
3326
3381
  className: cx("ui-dt", selIds.length && "has-sel", p.className),
3327
3382
  children: [
3328
3383
  p.caption ? /* @__PURE__ */ jsx("div", {
@@ -3392,6 +3447,7 @@ function DataTable(p) {
3392
3447
  className: "ui-dt-search"
3393
3448
  }) : null,
3394
3449
  filters.length ? /* @__PURE__ */ jsx(FilterButton, {
3450
+ boundary: rootRef,
3395
3451
  filters,
3396
3452
  values,
3397
3453
  activeCount: activeN,
@@ -3459,8 +3515,17 @@ function DataTable(p) {
3459
3515
  rowEls.current[id] = el;
3460
3516
  },
3461
3517
  role: "row",
3462
- className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
3518
+ className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && "has-exp"),
3463
3519
  style: gridStyle,
3520
+ onClick: expander ? (e) => {
3521
+ const t = e.target;
3522
+ if (t.closest(ROW_CONTROLS) && t.closest(ROW_CONTROLS) !== e.currentTarget) return;
3523
+ if (String(window.getSelection() ?? "")) return;
3524
+ setOpened({
3525
+ ...opened,
3526
+ [id]: !open
3527
+ });
3528
+ } : void 0,
3464
3529
  children: [
3465
3530
  expander ? /* @__PURE__ */ jsx("div", {
3466
3531
  className: "ui-dt-cell ui-dt-exp",
@@ -3519,7 +3584,7 @@ function DataTable(p) {
3519
3584
  children: c.label
3520
3585
  }), /* @__PURE__ */ jsx("div", {
3521
3586
  className: "ui-dt-detail-text",
3522
- children: cellInner(x.r, c)
3587
+ children: c.fullText ? c.fullText(x.r) : cellInner(x.r, c)
3523
3588
  })]
3524
3589
  }, c.key))
3525
3590
  })
@@ -3888,7 +3953,16 @@ function SplitPane({ a, b, defaultB = 420, minA = 360, minB = 280, storageKey, l
3888
3953
  onPointerMove: onMove,
3889
3954
  onPointerUp: onUp,
3890
3955
  onPointerCancel: onUp,
3891
- onDoubleClick: () => set(defaultB)
3956
+ onDoubleClick: () => set(defaultB),
3957
+ children: /* @__PURE__ */ jsxs("span", {
3958
+ className: "ui-split-grip",
3959
+ "aria-hidden": "true",
3960
+ children: [
3961
+ /* @__PURE__ */ jsx("i", {}),
3962
+ /* @__PURE__ */ jsx("i", {}),
3963
+ /* @__PURE__ */ jsx("i", {})
3964
+ ]
3965
+ })
3892
3966
  }),
3893
3967
  /* @__PURE__ */ jsx("div", {
3894
3968
  id,
@@ -4123,6 +4197,14 @@ function Term({ children, title, text, content, code, action, refHref, onRef, is
4123
4197
  const txt = !!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim());
4124
4198
  setInline(txt);
4125
4199
  }, [children]);
4200
+ const block = React.useRef(null);
4201
+ const toggle = (next) => {
4202
+ if (next) {
4203
+ const el = ref.current?.closest(".ui-card, .ui-split-a, .ui-split-b, .ui-shell-main, main") ?? null;
4204
+ block.current = el && el.getBoundingClientRect().width >= 240 ? el : null;
4205
+ }
4206
+ setOpen(next);
4207
+ };
4126
4208
  const heading = title || (typeof children === "string" ? children : "");
4127
4209
  const trigger = /* @__PURE__ */ jsxs("button", {
4128
4210
  type: "button",
@@ -4189,10 +4271,11 @@ function Term({ children, title, text, content, code, action, refHref, onRef, is
4189
4271
  });
4190
4272
  return /* @__PURE__ */ jsx(FloatingPanel, {
4191
4273
  open,
4192
- onOpenChange: setOpen,
4274
+ onOpenChange: toggle,
4193
4275
  sideOffset: 8,
4194
4276
  className: "ui-term-pop",
4195
4277
  trigger,
4278
+ boundary: block,
4196
4279
  children: body(Popover$1.Title, Popover$1.Close)
4197
4280
  });
4198
4281
  }
@@ -4386,6 +4469,8 @@ function labelWidth(text) {
4386
4469
  return w + c.measureText(t[0] === "`" ? t.slice(1, -1) : t).width;
4387
4470
  }, 0);
4388
4471
  }
4472
+ const LABELS_KEY = "ui-lg-labels:";
4473
+ const allIds = (nodes) => nodes.map((n) => n.id).join("|");
4389
4474
  const GROW = 24;
4390
4475
  const GROW_MAX = 144;
4391
4476
  /** The label on 1 line, then wrapped onto 2, 3 and 4 lines as evenly as it goes. Breaks between Chinese characters
@@ -4465,12 +4550,17 @@ const clean = (pts) => pts.filter((q, i) => {
4465
4550
  return !a || !c || !(a[0] === q[0] && q[0] === c[0] || a[1] === q[1] && q[1] === c[1]);
4466
4551
  });
4467
4552
  /** Architecture as layers of boxes with arrows. Line width shows how often; inferred relations are dashed and labelled;
4468
- * shared items are listed under the diagram instead of drawn. Wider than the screen: scrolls sideways. */
4553
+ * shared items are listed under the diagram instead of drawn. Wider than its box: the boxes narrow (down to 120 px),
4554
+ * then the whole diagram scales down (to 0.75 at least); past that it scrolls sideways (PM). */
4469
4555
  function LayerGraph(p) {
4470
- const NW = p.nodeWidth || 200;
4556
+ const [avail, setAvail] = React.useState(0);
4557
+ const [fit, setFit] = React.useState(null);
4558
+ const fitted = fit && fit.at === avail ? fit : null;
4559
+ const NW = fitted?.nw ?? (p.nodeWidth || 200);
4471
4560
  const NH = 60;
4472
4561
  const GAP = 56;
4473
- const COL = 40;
4562
+ const COL = fitted?.col ?? 40;
4563
+ const scale = fitted?.scale ?? 1;
4474
4564
  const PAD = 16;
4475
4565
  const all = p.nodes;
4476
4566
  const sel = p.selected ?? null;
@@ -4540,6 +4630,21 @@ function LayerGraph(p) {
4540
4630
  for (const k in ins) ins[k].sort((a, b) => pos[a.from].x - pos[b.from].x);
4541
4631
  const edgeId = (e) => e.id ?? `${e.from}->${e.to}`;
4542
4632
  const pickEdge = p.onSelectEdge;
4633
+ const [labelsOn, setLabelsOn] = React.useState(() => {
4634
+ try {
4635
+ const v = window.localStorage.getItem(LABELS_KEY + (p.scrollKey ?? allIds(p.nodes)));
4636
+ if (v === "1" || v === "0") return v === "1";
4637
+ } catch {}
4638
+ return p.edgeLabels !== "hover";
4639
+ });
4640
+ const peek = !labelsOn;
4641
+ const switchLabels = () => {
4642
+ const on = !labelsOn;
4643
+ setLabelsOn(on);
4644
+ try {
4645
+ window.localStorage.setItem(LABELS_KEY + (p.scrollKey ?? allIds(p.nodes)), on ? "1" : "0");
4646
+ } catch {}
4647
+ };
4543
4648
  const [hover, setHover] = React.useState(null);
4544
4649
  const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
4545
4650
  const uid = React.useId().replace(/:/g, "");
@@ -4573,6 +4678,7 @@ function LayerGraph(p) {
4573
4678
  };
4574
4679
  const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
4575
4680
  const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
4681
+ const markText = (e) => e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
4576
4682
  if (upsL.length) {
4577
4683
  const left0 = Math.min(...main.map((n) => pos[n.id].x));
4578
4684
  const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
@@ -4594,12 +4700,115 @@ function LayerGraph(p) {
4594
4700
  if (next && sel != null) p.onSelect?.(null);
4595
4701
  pickEdge?.(next);
4596
4702
  };
4703
+ const LANE_H = 28;
4704
+ const txOf = (e) => Math.round(pos[e.to].x + NW * (ins[e.to].indexOf(e) + 1) / (ins[e.to].length + 1));
4705
+ const laneGroups = {};
4706
+ const laneCount = {};
4707
+ {
4708
+ const into = {};
4709
+ for (const e of edges) if (ins[e.to]?.includes(e) && (e.inferred || related(e))) (into[e.to] ??= []).push(e);
4710
+ for (const id in into) {
4711
+ if (into[id].length < 2) continue;
4712
+ laneGroups[id] = into[id].sort((a, b) => txOf(b) - txOf(a));
4713
+ laneCount[id] = into[id].length;
4714
+ }
4715
+ }
4597
4716
  const draw = () => {
4598
4717
  const paths = [];
4599
4718
  const labels = [];
4600
4719
  const need = /* @__PURE__ */ new Set();
4601
4720
  const crowd = /* @__PURE__ */ new Set();
4721
+ const geomOf = (e) => {
4722
+ const a = pos[e.from];
4723
+ const b = pos[e.to];
4724
+ const oi = outs[e.from].indexOf(e);
4725
+ const on = outs[e.from].length;
4726
+ const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
4727
+ const sy = a.y + NH;
4728
+ const tx = txOf(e);
4729
+ const ty = b.y;
4730
+ const off = (oi - (on - 1) / 2) * 6;
4731
+ const skip = layerIndex[e.to] - layerIndex[e.from] > 1;
4732
+ const y1 = sy + gaps[layerIndex[e.from]] / 2 + off;
4733
+ let chx = sx;
4734
+ if (skip) {
4735
+ const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
4736
+ const mid = (sx + tx) / 2;
4737
+ const chans = [next[0].x - COL / 2, ...next.map((q) => q.x + NW + COL / 2)].map((c) => Math.max(PAD / 2, Math.min(W - PAD / 2, c)));
4738
+ chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
4739
+ }
4740
+ return {
4741
+ sx,
4742
+ sy,
4743
+ tx,
4744
+ ty,
4745
+ off,
4746
+ skip,
4747
+ y1,
4748
+ chx,
4749
+ from: skip ? chx : sx,
4750
+ startY: skip ? y1 : sy
4751
+ };
4752
+ };
4753
+ const lanes = /* @__PURE__ */ new Map();
4754
+ for (const id in laneGroups) {
4755
+ const group = laneGroups[id].map((e) => ({
4756
+ e,
4757
+ g: geomOf(e),
4758
+ w: Math.ceil(labelWidth(markText(e)))
4759
+ }));
4760
+ const n = group.length;
4761
+ const laneY = (j) => group[0].g.ty - 8 - 16 - j * LANE_H;
4762
+ const perms = [];
4763
+ const permute = (rest, acc) => {
4764
+ if (!rest.length) perms.push(acc);
4765
+ else rest.forEach((x, k) => permute([...rest.slice(0, k), ...rest.slice(k + 1)], [...acc, x]));
4766
+ };
4767
+ if (n <= 6) permute([...group.keys()], []);
4768
+ else perms.push([...group.keys()]);
4769
+ let best = null;
4770
+ for (const perm of perms) {
4771
+ const ys = [];
4772
+ perm.forEach((k, j) => ys[k] = laneY(j));
4773
+ const verts = group.flatMap((q, k) => [{
4774
+ k,
4775
+ x: q.g.from,
4776
+ y0: q.g.startY,
4777
+ y1: ys[k]
4778
+ }, {
4779
+ k,
4780
+ x: q.g.tx,
4781
+ y0: ys[k],
4782
+ y1: q.g.ty - 8
4783
+ }]);
4784
+ const free = (k, x0, x1) => verts.every((v) => v.k === k ? !(v.x > x0 - 1 && v.x < x1 + 1 && v.y0 < ys[k] + 7 && v.y1 > ys[k] - 7) : !(v.x > x0 - 5 && v.x < x1 + 5 && v.y0 < ys[k] + 10 && v.y1 > ys[k] - 10));
4785
+ let fails = 0;
4786
+ const sides = [];
4787
+ group.forEach((q, k) => {
4788
+ const r0 = Math.max(q.g.from, q.g.tx) + 8;
4789
+ const l1 = Math.min(q.g.from, q.g.tx) - 8;
4790
+ if (free(k, r0, r0 + q.w)) sides[k] = "right";
4791
+ else if (free(k, l1 - q.w, l1)) sides[k] = "left";
4792
+ else {
4793
+ sides[k] = "right";
4794
+ fails++;
4795
+ }
4796
+ });
4797
+ if (!best || fails < best.fails) best = {
4798
+ fails,
4799
+ ys,
4800
+ sides
4801
+ };
4802
+ if (!fails) break;
4803
+ }
4804
+ if (best) group.forEach((q, k) => lanes.set(q.e, {
4805
+ y: best.ys[k],
4806
+ side: best.sides[k]
4807
+ }));
4808
+ }
4602
4809
  const marks = [];
4810
+ let wide = 0;
4811
+ let least = 0;
4603
4812
  const runs = [];
4604
4813
  const segs = [];
4605
4814
  const arrows = [];
@@ -4618,6 +4827,9 @@ function LayerGraph(p) {
4618
4827
  let ty;
4619
4828
  let arrow;
4620
4829
  let inn = 1;
4830
+ let laneAt = null;
4831
+ let turnFrom = 0;
4832
+ let laneSide = "right";
4621
4833
  if (up) {
4622
4834
  const lx = laneX(e);
4623
4835
  const L = onLeft(e);
@@ -4705,27 +4917,21 @@ function LayerGraph(p) {
4705
4917
  });
4706
4918
  }
4707
4919
  } else {
4708
- const oi = outs[e.from].indexOf(e);
4709
- const on = outs[e.from].length;
4710
- const ii = ins[e.to].indexOf(e);
4711
4920
  inn = ins[e.to].length;
4712
- const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
4713
- const sy = a.y + NH;
4714
- tx = Math.round(b.x + NW * (ii + 1) / (inn + 1));
4715
- ty = b.y;
4716
- const off = (oi - (on - 1) / 2) * 6;
4717
- const y1 = sy + gaps[layerIndex[e.from]] / 2 + off;
4718
- if (layerIndex[e.to] - layerIndex[e.from] > 1) {
4719
- const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
4720
- const mid = (sx + tx) / 2;
4721
- const chans = [next[0].x - COL / 2, ...next.map((q) => q.x + NW + COL / 2)].map((c) => Math.max(PAD / 2, Math.min(W - PAD / 2, c)));
4722
- const chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
4723
- const y2 = ty - gaps[layerIndex[e.to] - 1] / 2 + off;
4921
+ const g = geomOf(e);
4922
+ const { sx, sy, skip } = g;
4923
+ tx = g.tx;
4924
+ ty = g.ty;
4925
+ const lane = lanes.get(e);
4926
+ const laneY = lane ? lane.y : null;
4927
+ const y1 = !skip && laneY != null ? laneY : g.y1;
4928
+ if (skip) {
4929
+ const y2 = laneY ?? ty - gaps[layerIndex[e.to] - 1] / 2 + g.off;
4724
4930
  pts = [
4725
4931
  [sx, sy],
4726
4932
  [sx, y1],
4727
- [chx, y1],
4728
- [chx, y2],
4933
+ [g.chx, y1],
4934
+ [g.chx, y2],
4729
4935
  [tx, y2],
4730
4936
  [tx, ty - 8]
4731
4937
  ];
@@ -4735,6 +4941,9 @@ function LayerGraph(p) {
4735
4941
  [tx, y1],
4736
4942
  [tx, ty - 8]
4737
4943
  ];
4944
+ turnFrom = g.from;
4945
+ laneAt = laneY;
4946
+ laneSide = lane?.side ?? "right";
4738
4947
  arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
4739
4948
  arrows.push([
4740
4949
  tx - 5,
@@ -4764,13 +4973,23 @@ function LayerGraph(p) {
4764
4973
  d,
4765
4974
  strokeWidth: w
4766
4975
  }, "p" + idx));
4976
+ if (!pickEdge && peek) hitPaths.push(/* @__PURE__ */ jsx("path", {
4977
+ className: "ui-lg-hit is-peek",
4978
+ d,
4979
+ onPointerEnter: () => setHover(edgeId(e)),
4980
+ onPointerLeave: () => setHover(null)
4981
+ }, "h" + idx));
4767
4982
  if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
4768
4983
  className: "ui-lg-hit",
4769
4984
  "data-edge": edgeId(e),
4770
4985
  d,
4771
4986
  role: "button",
4772
4987
  tabIndex: 0,
4773
- "aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
4988
+ "aria-label": tr("{from} → {to},{what}", {
4989
+ from: nameOf(e.from),
4990
+ to: nameOf(e.to),
4991
+ what: (e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")
4992
+ }),
4774
4993
  "aria-pressed": picked,
4775
4994
  onClick: (ev) => {
4776
4995
  ev.stopPropagation();
@@ -4778,6 +4997,8 @@ function LayerGraph(p) {
4778
4997
  },
4779
4998
  onPointerEnter: () => setHover(edgeId(e)),
4780
4999
  onPointerLeave: () => setHover(null),
5000
+ onFocus: peek ? () => setHover(edgeId(e)) : void 0,
5001
+ onBlur: peek ? () => setHover(null) : void 0,
4781
5002
  onKeyDown: (ev) => {
4782
5003
  if (ev.key === "Enter" || ev.key === " ") {
4783
5004
  ev.preventDefault();
@@ -4799,7 +5020,10 @@ function LayerGraph(p) {
4799
5020
  ty,
4800
5021
  left: inn > 1 && tx < b.x + NW / 2,
4801
5022
  r,
4802
- dim
5023
+ dim,
5024
+ lane: laneAt,
5025
+ from: turnFrom,
5026
+ side: laneSide
4803
5027
  });
4804
5028
  }
4805
5029
  });
@@ -4814,7 +5038,7 @@ function LayerGraph(p) {
4814
5038
  const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
4815
5039
  const labelEl = (m, x0, top, lines = [m.text]) => /* @__PURE__ */ jsx("span", {
4816
5040
  "aria-hidden": pickEdge ? true : void 0,
4817
- className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
5041
+ className: cx("ui-lg-label", 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"),
4818
5042
  style: {
4819
5043
  left: x0,
4820
5044
  top
@@ -4896,7 +5120,24 @@ function LayerGraph(p) {
4896
5120
  return !hits(x0, x0 + lw, y0, y1) && !boxRects.some(over) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : over(sg.box));
4897
5121
  };
4898
5122
  let spot = null;
4899
- for (const lines of wraps(m.text)) {
5123
+ if (m.lane != null) {
5124
+ const lane = m.lane;
5125
+ for (const lines of wraps(m.text)) {
5126
+ if (spot) break;
5127
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
5128
+ const lh = lines.length * 16;
5129
+ const right = Math.max(m.tx, m.from ?? m.tx) + 8;
5130
+ const left = Math.min(m.tx, m.from ?? m.tx) - 8 - lw;
5131
+ for (const x0 of m.side === "left" ? [left, right] : [right, left]) if (!spot && clear(x0, lw, lane - lh / 2, lane + lh / 2)) spot = {
5132
+ x0,
5133
+ top: lane,
5134
+ lw,
5135
+ lh,
5136
+ lines
5137
+ };
5138
+ }
5139
+ }
5140
+ for (const lines of spot ? [] : wraps(m.text)) {
4900
5141
  const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
4901
5142
  const lh = lines.length * 16;
4902
5143
  const pref = sideOf(lw);
@@ -4964,6 +5205,8 @@ function LayerGraph(p) {
4964
5205
  spot.top + spot.lh / 2,
4965
5206
  6
4966
5207
  ]);
5208
+ wide = Math.max(wide, spot.x0 + spot.lw + PAD / 2 + 4);
5209
+ least = Math.min(least, spot.x0 - PAD / 2 - 4);
4967
5210
  labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
4968
5211
  });
4969
5212
  return {
@@ -4971,29 +5214,46 @@ function LayerGraph(p) {
4971
5214
  labels,
4972
5215
  hitPaths,
4973
5216
  need,
4974
- crowd
5217
+ crowd,
5218
+ wide,
5219
+ least
4975
5220
  };
4976
5221
  };
5222
+ for (const id in laneCount) {
5223
+ const g = layerIndex[id] - 1;
5224
+ if (g >= 0) gaps[g] = Math.max(gaps[g], laneCount[id] * LANE_H + 40);
5225
+ }
5226
+ const floor = gaps.slice();
4977
5227
  placeRows();
4978
5228
  let drawn = draw();
4979
- const grows = () => [...drawn.need].filter((g) => gaps[g] < 200);
5229
+ const grows = () => [...drawn.need].filter((g) => gaps[g] < floor[g] + GROW_MAX);
4980
5230
  for (let k = 0; k < GROW_MAX / GROW && grows().length; k++) {
4981
- for (const g of grows()) gaps[g] = Math.min(200, gaps[g] + GROW);
5231
+ for (const g of grows()) gaps[g] = Math.min(floor[g] + GROW_MAX, gaps[g] + GROW);
4982
5232
  placeRows();
4983
5233
  drawn = draw();
4984
5234
  }
4985
- const stuck = [...drawn.need].filter((g) => gaps[g] >= 200);
5235
+ const stuck = [...drawn.need].filter((g) => gaps[g] >= floor[g] + GROW_MAX);
4986
5236
  if (stuck.length) {
4987
- for (const g of stuck) gaps[g] = GAP;
5237
+ for (const g of stuck) gaps[g] = floor[g];
4988
5238
  placeRows();
4989
5239
  drawn = draw();
4990
- const crowded = () => [...drawn.crowd].filter((g) => stuck.includes(g) && gaps[g] < 200);
5240
+ const crowded = () => [...drawn.crowd].filter((g) => stuck.includes(g) && gaps[g] < floor[g] + GROW_MAX);
4991
5241
  for (let k = 0; k < GROW_MAX / GROW && crowded().length; k++) {
4992
- for (const g of crowded()) gaps[g] = Math.min(200, gaps[g] + GROW);
5242
+ for (const g of crowded()) gaps[g] = Math.min(floor[g] + GROW_MAX, gaps[g] + GROW);
4993
5243
  placeRows();
4994
5244
  drawn = draw();
4995
5245
  }
4996
5246
  }
5247
+ for (let k = 0; k < 3 && drawn.least < 0; k++) {
5248
+ const shift = Math.ceil(-drawn.least);
5249
+ for (const id in pos) pos[id].x += shift;
5250
+ W += shift;
5251
+ drawn = draw();
5252
+ }
5253
+ if (drawn.wide > W) {
5254
+ W = Math.ceil(drawn.wide);
5255
+ drawn = draw();
5256
+ }
4997
5257
  const { paths, labels, hitPaths } = drawn;
4998
5258
  const sizeText = p.sizeLabel ?? tr("{n} 個項目");
4999
5259
  const externalText = p.externalLabel ?? tr("repo 外");
@@ -5063,7 +5323,10 @@ function LayerGraph(p) {
5063
5323
  })]
5064
5324
  }, s.id);
5065
5325
  });
5066
- const edgeText = (e) => e.inferred ? e.label ? `${e.label}(${p.inferredLabel || tr("推測")})` : p.inferredLabel || tr("推測") : countText(e);
5326
+ const edgeText = (e) => e.inferred ? e.label ? tr("{label}({inferred})", {
5327
+ label: e.label,
5328
+ inferred: p.inferredLabel || tr("推測")
5329
+ }) : p.inferredLabel || tr("推測") : countText(e);
5067
5330
  const listItem = (key, on, dim, onClick, head, rest) => /* @__PURE__ */ jsxs("li", {
5068
5331
  className: cx("ui-lg-li", dim && "is-dim"),
5069
5332
  children: [onClick ? /* @__PURE__ */ jsx("button", {
@@ -5093,10 +5356,10 @@ function LayerGraph(p) {
5093
5356
  children: n.name || n.id
5094
5357
  }), n.external && !n.shared ? /* @__PURE__ */ jsxs("span", {
5095
5358
  className: "ui-lg-limeta",
5096
- children: [",", externalText]
5359
+ children: [tr(","), externalText]
5097
5360
  }) : size != null ? /* @__PURE__ */ jsxs("span", {
5098
5361
  className: "ui-lg-limeta",
5099
- children: [",", monoNums(sizeText.replace("{n}", ""), [size])]
5362
+ children: [tr(","), monoNums(sizeText.replace("{n}", ""), [size])]
5100
5363
  }) : null);
5101
5364
  }) })]
5102
5365
  }), /* @__PURE__ */ jsxs("section", {
@@ -5117,17 +5380,63 @@ function LayerGraph(p) {
5117
5380
  })
5118
5381
  ] }), /* @__PURE__ */ jsxs("span", {
5119
5382
  className: "ui-lg-limeta",
5120
- children: [":", labelParts(edgeText(e))]
5383
+ children: [tr(":"), labelParts(edgeText(e))]
5121
5384
  }))) })]
5122
5385
  })]
5123
5386
  });
5124
5387
  const showList = p.listView !== false && view === "list";
5388
+ const toggleShown = p.labelToggle !== false && !showList && p.edges.some((e) => e.inferred);
5389
+ React.useLayoutEffect(() => {
5390
+ const el = scrollRef.current;
5391
+ if (!el) return;
5392
+ const measure = () => setAvail(el.clientWidth);
5393
+ measure();
5394
+ const ro = new ResizeObserver(measure);
5395
+ ro.observe(el);
5396
+ return () => ro.disconnect();
5397
+ }, [scrollRef, showList]);
5398
+ React.useLayoutEffect(() => {
5399
+ if (!avail || showList) return;
5400
+ if (!fitted) {
5401
+ if (W <= avail + .5) return;
5402
+ const base = p.nodeWidth || 200;
5403
+ const lose = W - avail - (cols - 1) * 16;
5404
+ const nw = Math.max(Math.min(base, 120), Math.floor(base - Math.max(0, lose) / cols));
5405
+ setFit({
5406
+ at: avail,
5407
+ nw,
5408
+ col: 24,
5409
+ scale: 1
5410
+ });
5411
+ return;
5412
+ }
5413
+ if (fitted.scale !== 1 || W <= avail + .5) return;
5414
+ const s = avail / W;
5415
+ if (s >= .75) setFit({
5416
+ ...fitted,
5417
+ scale: Math.floor(s * 1e3) / 1e3
5418
+ });
5419
+ }, [
5420
+ avail,
5421
+ showList,
5422
+ fitted,
5423
+ W,
5424
+ p.nodeWidth,
5425
+ cols
5426
+ ]);
5125
5427
  return /* @__PURE__ */ jsxs("div", {
5126
5428
  className: cx("ui-graph ui-lg", p.className),
5127
5429
  children: [
5128
- p.listView === false ? null : /* @__PURE__ */ jsx("div", {
5430
+ p.listView === false && !toggleShown ? null : /* @__PURE__ */ jsxs("div", {
5129
5431
  className: "ui-lg-bar",
5130
- children: /* @__PURE__ */ jsx(Tabs, {
5432
+ children: [toggleShown ? /* @__PURE__ */ jsx(IconButton, {
5433
+ className: "ui-lg-labels-btn",
5434
+ icon: "tag",
5435
+ filled: labelsOn,
5436
+ label: tr("顯示線上文字"),
5437
+ "aria-pressed": labelsOn,
5438
+ onClick: switchLabels
5439
+ }) : null, p.listView === false ? null : /* @__PURE__ */ jsx(Tabs, {
5131
5440
  label: tr("顯示方式"),
5132
5441
  value: view,
5133
5442
  onChange: setView,
@@ -5138,7 +5447,7 @@ function LayerGraph(p) {
5138
5447
  id: "list",
5139
5448
  label: tr("清單")
5140
5449
  }]
5141
- })
5450
+ })]
5142
5451
  }),
5143
5452
  showList ? list : null,
5144
5453
  /* @__PURE__ */ jsx("div", {
@@ -5149,9 +5458,17 @@ function LayerGraph(p) {
5149
5458
  onScroll: onScrollKeep,
5150
5459
  children: /* @__PURE__ */ jsxs("div", {
5151
5460
  className: "ui-lg-canvas",
5152
- style: {
5461
+ style: scale === 1 ? {
5153
5462
  width: W,
5154
5463
  height: H
5464
+ } : {
5465
+ width: W,
5466
+ height: H,
5467
+ transform: `scale(${scale})`,
5468
+ transformOrigin: "0 0",
5469
+ marginRight: W * (scale - 1),
5470
+ marginBottom: H * (scale - 1),
5471
+ "--lg-scale": scale
5155
5472
  },
5156
5473
  role: "group",
5157
5474
  "aria-label": p.label || tr("架構圖"),
@@ -5166,7 +5483,14 @@ function LayerGraph(p) {
5166
5483
  }),
5167
5484
  nodes,
5168
5485
  labels,
5169
- hitPaths.length ? /* @__PURE__ */ jsx("svg", {
5486
+ hitPaths.length && !pickEdge ? /* @__PURE__ */ jsx("svg", {
5487
+ className: "ui-lg-hits",
5488
+ width: W,
5489
+ height: H,
5490
+ viewBox: `0 0 ${W} ${H}`,
5491
+ "aria-hidden": "true",
5492
+ children: hitPaths
5493
+ }) : hitPaths.length ? /* @__PURE__ */ jsx("svg", {
5170
5494
  className: "ui-lg-hits",
5171
5495
  width: W,
5172
5496
  height: H,
@@ -6305,9 +6629,10 @@ function bounds(target) {
6305
6629
  bottom
6306
6630
  };
6307
6631
  }
6308
- /** Where the card goes for a highlighted box: the preferred side, the other side, or inside the box at the bottom
6309
- * center of the window when neither side has room. Returns the anchor line the card is placed against. */
6310
- function placeCard(rect, cardH, prefer, area) {
6632
+ /** Where the card goes for a highlighted box: the preferred side, the other one, then right or left of the box; inside
6633
+ * the box at the bottom only when none has room (the tour scrolls first to make room above or below, see makeRoom).
6634
+ * Returns the anchor line the card is placed against. */
6635
+ function placeCard(rect, cardH, prefer, area, cardW = 320) {
6311
6636
  const margin = typeof document === "undefined" ? 12 : edge();
6312
6637
  const vh = area?.bottom ?? (typeof window === "undefined" ? 0 : window.innerHeight);
6313
6638
  const vt = area?.top ?? 0;
@@ -6333,6 +6658,16 @@ function placeCard(rect, cardH, prefer, area) {
6333
6658
  margin,
6334
6659
  line: rect
6335
6660
  };
6661
+ const vw = typeof window === "undefined" ? 0 : window.innerWidth;
6662
+ const tallOk = cardH + 2 * margin <= vh - vt;
6663
+ const beside = ["right", "left"].find((sd) => tallOk && (sd === "right" ? rect.left + rect.width + GAP + cardW + margin <= vw : rect.left - GAP - cardW - margin >= 0));
6664
+ if (beside) return {
6665
+ mode: beside,
6666
+ side: beside,
6667
+ offset: GAP,
6668
+ margin,
6669
+ line: rect
6670
+ };
6336
6671
  const end = rect.top + rect.height;
6337
6672
  const bottom = Math.max(vt + margin + cardH, end >= vh - margin ? vh - margin : end - margin);
6338
6673
  return {
@@ -6356,6 +6691,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6356
6691
  const [rect, setRect] = React.useState(null);
6357
6692
  const next = React.useRef(null);
6358
6693
  const [cardH, setCardH] = React.useState(0);
6694
+ const [cardW, setCardW] = React.useState(320);
6359
6695
  const [wasOpen, setWasOpen] = React.useState(open);
6360
6696
  if (open !== wasOpen) {
6361
6697
  setWasOpen(open);
@@ -6367,6 +6703,23 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6367
6703
  };
6368
6704
  const end = (why) => onClose?.(why);
6369
6705
  useReturnFocus(open);
6706
+ const shownStep = React.useRef(-1);
6707
+ React.useEffect(() => {
6708
+ if (!open || !step) {
6709
+ shownStep.current = -1;
6710
+ return;
6711
+ }
6712
+ if (shownStep.current !== -1 && shownStep.current !== i) announce(tr("第 {a} 步,共 {b} 步", {
6713
+ a: i + 1,
6714
+ b: steps.length
6715
+ }) + tr("。") + step.title + tr("。") + step.text.replace(/`/g, ""));
6716
+ shownStep.current = i;
6717
+ }, [
6718
+ open,
6719
+ i,
6720
+ step,
6721
+ steps.length
6722
+ ]);
6370
6723
  const cardEl = React.useRef(null);
6371
6724
  const tabbables = () => Array.from(cardEl.current?.querySelectorAll("button:not(:disabled), a[href], input:not(:disabled), [tabindex]:not([tabindex=\"-1\"])") ?? []).filter((e) => e.getClientRects().length > 0);
6372
6725
  const onTab = (e) => {
@@ -6444,13 +6797,48 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6444
6797
  observer.current?.disconnect();
6445
6798
  observer.current = null;
6446
6799
  if (!el) return;
6447
- const measure = () => setCardH(el.offsetHeight);
6800
+ const measure = () => {
6801
+ setCardH(el.offsetHeight);
6802
+ setCardW(el.offsetWidth);
6803
+ };
6448
6804
  measure();
6449
6805
  observer.current = new ResizeObserver(measure);
6450
6806
  observer.current.observe(el);
6451
6807
  }, []);
6808
+ const measured = cardH > 0;
6809
+ React.useEffect(() => {
6810
+ if (!open || !hasStep || !measured) return;
6811
+ const el = findTarget(target);
6812
+ if (!(el instanceof HTMLElement)) return;
6813
+ const ar = bounds(el);
6814
+ const m = edge();
6815
+ const r = el.getBoundingClientRect();
6816
+ const top = r.top - pad;
6817
+ const bottom = r.bottom + pad;
6818
+ if (bottom + GAP + cardH + m <= ar.bottom || top - GAP - cardH - m >= ar.top) return;
6819
+ const want = bottom - top + GAP + cardH + 2 * m <= ar.bottom - ar.top ? ar.top + m + pad : ar.top + m + cardH + GAP + pad;
6820
+ let box = el.parentElement;
6821
+ while (box && !(/(auto|scroll)/.test(getComputedStyle(box).overflowY) && box.scrollHeight > box.clientHeight)) box = box.parentElement;
6822
+ const dy = r.top - want;
6823
+ if (box) box.scrollBy({
6824
+ top: dy,
6825
+ behavior: "auto"
6826
+ });
6827
+ else window.scrollBy({
6828
+ top: dy,
6829
+ behavior: "auto"
6830
+ });
6831
+ }, [
6832
+ open,
6833
+ hasStep,
6834
+ i,
6835
+ target,
6836
+ pad,
6837
+ measured,
6838
+ cardH
6839
+ ]);
6452
6840
  const area = open && step ? bounds(findTarget(step.target)) : void 0;
6453
- const place = placeCard(rect, cardH, step?.side ?? "bottom", area);
6841
+ const place = placeCard(rect, cardH, step?.side ?? "bottom", area, cardW);
6454
6842
  const line = place.line;
6455
6843
  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) }), [
6456
6844
  line?.left,
@@ -6862,7 +7250,7 @@ function TreeList(p) {
6862
7250
  ...(n.tags ?? []).map(nodeText),
6863
7251
  n.meta,
6864
7252
  n.path
6865
- ].filter(Boolean).join(","),
7253
+ ].filter(Boolean).join(tr(",")),
6866
7254
  "aria-selected": p.onSelect ? on : void 0,
6867
7255
  className: cx("ui-tree-row", "is-plain", on && "is-current", n.muted && "is-muted", r.fresh && "ui-tree-in"),
6868
7256
  onClick: () => {