@seanyeh77/ui 0.4.1 → 0.6.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-DDglckmU.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-CDWxD999.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";
@@ -575,30 +575,48 @@ function Breadcrumb({ items, className }) {
575
575
  });
576
576
  }
577
577
  // src/components/Tooltip/Tooltip.tsx
578
+ const openNow = /* @__PURE__ */ new Set();
578
579
  /** Dark label above the element (below when there is no room), with an arrow. Appears at once on hover and focus. */
579
- function Tooltip({ label, side = "top", describe = true, children }) {
580
+ function Tooltip({ label, side = "top", describe = true, wrap = false, disabled = false, children }) {
580
581
  const id = React.useId();
581
- return /* @__PURE__ */ jsxs(Tooltip$1.Root, { children: [
582
- /* @__PURE__ */ jsx(Tooltip$1.Trigger, {
583
- delay: 0,
584
- render: children,
585
- "aria-describedby": describe ? id : void 0
586
- }),
587
- describe ? /* @__PURE__ */ jsx("span", {
588
- id,
589
- hidden: true,
590
- children: label
591
- }) : null,
592
- /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
593
- side,
594
- sideOffset: 8,
595
- className: "ui-tooltip-positioner",
596
- children: /* @__PURE__ */ jsxs(Tooltip$1.Popup, {
597
- className: "ui-tooltip",
598
- children: [label, /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "ui-tooltip-arrow" })]
599
- })
600
- }) })
601
- ] });
582
+ const [open, setOpen] = React.useState(false);
583
+ const close = React.useCallback(() => setOpen(false), []);
584
+ const shown = open && !disabled;
585
+ React.useEffect(() => {
586
+ if (!shown) return;
587
+ for (const other of openNow) if (other !== close) other();
588
+ openNow.add(close);
589
+ return () => {
590
+ openNow.delete(close);
591
+ };
592
+ }, [shown, close]);
593
+ return /* @__PURE__ */ jsxs(Tooltip$1.Root, {
594
+ disabled,
595
+ open: shown,
596
+ onOpenChange: setOpen,
597
+ children: [
598
+ /* @__PURE__ */ jsx(Tooltip$1.Trigger, {
599
+ delay: 0,
600
+ render: children,
601
+ "aria-describedby": describe && !disabled ? id : void 0,
602
+ onBlur: close
603
+ }),
604
+ describe && !disabled ? /* @__PURE__ */ jsx("span", {
605
+ id,
606
+ hidden: true,
607
+ children: label
608
+ }) : null,
609
+ /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
610
+ side,
611
+ sideOffset: 8,
612
+ className: "ui-tooltip-positioner",
613
+ children: /* @__PURE__ */ jsxs(Tooltip$1.Popup, {
614
+ className: wrap ? "ui-tooltip is-wrap" : "ui-tooltip",
615
+ children: [label, /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "ui-tooltip-arrow" })]
616
+ })
617
+ }) })
618
+ ]
619
+ });
602
620
  }
603
621
  // src/components/IconButton/IconButton.tsx
604
622
  /** A square icon-only button with a tooltip. */
@@ -671,20 +689,22 @@ function MobileTabBar({ items, value, onChange, label, className }) {
671
689
  right: `calc(${100 - idx * w - w / 2}% - 28px)`,
672
690
  transition: dropTransition("left", "right", forward)
673
691
  }
674
- }), items.map((t, i) => /* @__PURE__ */ jsx("button", {
692
+ }), items.map((t, i) => /* @__PURE__ */ jsxs("button", {
675
693
  type: "button",
676
694
  className: cx("ui-tabbar-item", i === idx && "is-selected"),
677
- "aria-label": t.label,
678
695
  "aria-current": i === idx ? "page" : void 0,
679
696
  onClick: () => {
680
697
  if (i !== idx) setForward(i > idx);
681
698
  onChange?.(t.id);
682
699
  },
683
- children: /* @__PURE__ */ jsx(IconOf, {
700
+ children: [/* @__PURE__ */ jsx(IconOf, {
684
701
  icon: t.icon,
685
702
  size: 22,
686
703
  filled: i === idx
687
- })
704
+ }), /* @__PURE__ */ jsx("span", {
705
+ className: "ui-tabbar-label",
706
+ children: t.label
707
+ })]
688
708
  }, t.id))]
689
709
  });
690
710
  }
@@ -1696,14 +1716,21 @@ function Checkbox({ checked, onChange, label, disabled, className, ...aria }) {
1696
1716
  // src/components/InlineCode/InlineCode.tsx
1697
1717
  /** Code inside a sentence: monospace on a light gray chip. A span that points somewhere is a link. */
1698
1718
  function InlineCode({ children, href, onClick, className }) {
1699
- const cls = cx("ui-code", (href || onClick) && "is-link", typeof children === "string" && children.length <= 24 && "is-short", className);
1719
+ const [inline, setInline] = React.useState(false);
1720
+ const link = React.useCallback((el) => {
1721
+ const par = el?.parentNode;
1722
+ setInline(!!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim()));
1723
+ }, []);
1724
+ const cls = cx("ui-code", (href || onClick) && "is-link", (href || onClick) && inline && "is-inline", typeof children === "string" && children.length <= 24 && "is-short", className);
1700
1725
  if (href) return /* @__PURE__ */ jsx("a", {
1726
+ ref: link,
1701
1727
  className: cls,
1702
1728
  href,
1703
1729
  onClick,
1704
1730
  children
1705
1731
  });
1706
1732
  if (onClick) return /* @__PURE__ */ jsx("button", {
1733
+ ref: link,
1707
1734
  type: "button",
1708
1735
  className: cls,
1709
1736
  onClick,
@@ -1768,8 +1795,9 @@ function languageOf(file) {
1768
1795
  const m = /\.([A-Za-z0-9]+)$/.exec(file || "");
1769
1796
  return m && EXT[m[1].toLowerCase()] || "plain";
1770
1797
  }
1798
+ /** Header labels. A bare 「C」 reads like a button, so C is 「C 語言」. */
1771
1799
  const LANGUAGE_NAMES = {
1772
- c: "C",
1800
+ c: "C 語言",
1773
1801
  js: "JavaScript",
1774
1802
  py: "Python",
1775
1803
  sh: "Shell"
@@ -1806,6 +1834,29 @@ const tokenize = (lines, lang) => {
1806
1834
  });
1807
1835
  };
1808
1836
  // src/components/CodeView/CodeView.tsx
1837
+ const OPS = /(->|::|==|!=|<=|>=|&&|\|\||\+\+|--|<<|>>|=>|\+=|-=|\*=|\/=)/;
1838
+ const AFTER = /([,.([{;])/;
1839
+ /** A piece of code with soft break points after commas, dots and opening brackets, and operators kept together. */
1840
+ function breakable(text) {
1841
+ if (!OPS.test(text) && !AFTER.test(text)) return text;
1842
+ const out = [];
1843
+ text.split(OPS).forEach((part, i) => {
1844
+ if (!part) return;
1845
+ if (i % 2) {
1846
+ out.push(/* @__PURE__ */ jsx("span", {
1847
+ className: "ui-cv-op",
1848
+ children: part
1849
+ }, i), /* @__PURE__ */ jsx("wbr", {}, i + "w"));
1850
+ return;
1851
+ }
1852
+ part.split(AFTER).forEach((bit, k) => {
1853
+ if (!bit) return;
1854
+ out.push(bit);
1855
+ if (k % 2) out.push(/* @__PURE__ */ jsx("wbr", {}, i + "." + k));
1856
+ });
1857
+ });
1858
+ return out;
1859
+ }
1809
1860
  /** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
1810
1861
  function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, maxHeight, className }) {
1811
1862
  const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
@@ -1858,8 +1909,8 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
1858
1909
  className: "ui-cv-text",
1859
1910
  children: toks[i].map(([cls, text], j) => cls ? /* @__PURE__ */ jsx("span", {
1860
1911
  className: cls,
1861
- children: text
1862
- }, j) : text)
1912
+ children: breakable(text)
1913
+ }, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))
1863
1914
  })]
1864
1915
  }, i));
1865
1916
  }
@@ -1876,9 +1927,12 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
1876
1927
  }) : /* @__PURE__ */ jsx("span", {
1877
1928
  className: "ui-cv-title",
1878
1929
  children: title
1879
- }), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsx("span", {
1930
+ }), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsxs("span", {
1880
1931
  className: "ui-cv-lang",
1881
- children: languageLabel || LANGUAGE_NAMES[lang] || lang
1932
+ children: [/* @__PURE__ */ jsxs("span", {
1933
+ className: "ui-visually-hidden",
1934
+ children: [tr("程式語言"), ":"]
1935
+ }), tr(languageLabel || LANGUAGE_NAMES[lang] || lang)]
1882
1936
  }) : null]
1883
1937
  }) : null;
1884
1938
  return /* @__PURE__ */ jsxs("div", {
@@ -2075,10 +2129,10 @@ function CommandPalette(props) {
2075
2129
  className: "ui-pal-text",
2076
2130
  children: [/* @__PURE__ */ jsxs("span", {
2077
2131
  className: "ui-pal-line",
2078
- children: [labelOf(it, at), it.kind ? /* @__PURE__ */ jsx("span", {
2132
+ children: [it.kind ? /* @__PURE__ */ jsx("span", {
2079
2133
  className: "ui-visually-hidden",
2080
- children: "," + it.kind
2081
- }) : null]
2134
+ children: it.kind + " "
2135
+ }) : null, labelOf(it, at)]
2082
2136
  }), it.detail ? /* @__PURE__ */ jsx(CodeText, {
2083
2137
  className: "ui-pal-detail",
2084
2138
  text: it.detail
@@ -2161,12 +2215,13 @@ function SearchField({ value, onChange, className, label, ...native }) {
2161
2215
  }
2162
2216
  // src/components/Tabs/Tabs.tsx
2163
2217
  /** Views of the same content. The underline moves like a droplet; arrow keys move between tabs. */
2164
- function Tabs({ items, value, onChange, label, className }) {
2218
+ function Tabs({ items, value, onChange, label, unit, className }) {
2165
2219
  const refs = React.useRef([]);
2166
2220
  const track = React.useRef(null);
2167
2221
  const [box, setBox] = React.useState(null);
2168
2222
  const [forward, setForward] = React.useState(true);
2169
2223
  const [moving, bump] = useMoving();
2224
+ devWarn(items.some((t) => t.count != null && !(t.unit || unit)), "Tabs", "a count has no unit, so it reads as a bare number. Pass unit, e.g. unit: '筆', on Tabs or on the item.");
2170
2225
  const idx = Math.max(0, items.findIndex((t) => t.id === value));
2171
2226
  React.useLayoutEffect(() => {
2172
2227
  const el = refs.current[idx];
@@ -2219,13 +2274,66 @@ function Tabs({ items, value, onChange, label, className }) {
2219
2274
  refs.current[to]?.focus();
2220
2275
  go(to);
2221
2276
  },
2222
- children: [t.label, t.count != null ? /* @__PURE__ */ jsx("span", {
2277
+ children: [t.label, t.count != null ? /* @__PURE__ */ jsxs("span", {
2223
2278
  className: "ui-tab-count",
2224
- children: format.number(t.count)
2279
+ children: [format.number(t.count), t.unit || unit ? /* @__PURE__ */ jsxs("span", {
2280
+ className: "ui-unit",
2281
+ children: [" ", tr(t.unit || unit || "")]
2282
+ }) : null]
2225
2283
  }) : null]
2226
2284
  }, t.id))]
2227
2285
  });
2228
2286
  }
2287
+ // src/internal/scrollHint.tsx
2288
+ /** A box that may be wider than its container: whether it overflows, whether more is to the right, and whether the
2289
+ * person has scrolled yet. Used by LayerGraph and DataTable for the right-edge fade and the 「左右滑動」 hint. */
2290
+ function useScrollHint() {
2291
+ const ref = React.useRef(null);
2292
+ const [more, setMore] = React.useState(false);
2293
+ const [scrolled, setScrolled] = React.useState(false);
2294
+ const [overflows, setOverflows] = React.useState(false);
2295
+ const measure = React.useCallback(() => {
2296
+ const el = ref.current;
2297
+ if (!el) return;
2298
+ const wide = el.scrollWidth > el.clientWidth + 1;
2299
+ setOverflows(wide);
2300
+ setMore(wide && el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
2301
+ }, []);
2302
+ React.useLayoutEffect(() => {
2303
+ const el = ref.current;
2304
+ if (!el) return;
2305
+ measure();
2306
+ const ro = new ResizeObserver(measure);
2307
+ ro.observe(el);
2308
+ if (el.firstElementChild) ro.observe(el.firstElementChild);
2309
+ return () => ro.disconnect();
2310
+ }, [measure]);
2311
+ return {
2312
+ ref,
2313
+ more,
2314
+ overflows,
2315
+ scrolled,
2316
+ onScroll: React.useCallback(() => {
2317
+ const el = ref.current;
2318
+ if (el && el.scrollLeft > 0) setScrolled(true);
2319
+ measure();
2320
+ }, [measure]),
2321
+ measure
2322
+ };
2323
+ }
2324
+ /** 「→ 左右滑動」 (touch) or 「→ 向右捲動」 (mouse, trackpad) under the box, right-aligned. Hidden after the first sideways
2325
+ * scroll but keeps its line, so nothing below jumps. */
2326
+ function ScrollHint({ show, done }) {
2327
+ const touch = useMedia("(pointer: coarse)");
2328
+ return show ? /* @__PURE__ */ jsxs("span", {
2329
+ className: cx("ui-scroll-hint", done && "is-done"),
2330
+ "aria-hidden": "true",
2331
+ children: [/* @__PURE__ */ jsx(Icon, {
2332
+ name: "arrow-right",
2333
+ size: 14
2334
+ }), touch ? tr("左右滑動") : tr("向右捲動")]
2335
+ }) : null;
2336
+ }
2229
2337
  // src/components/DataTable/filters.ts
2230
2338
  const field = (row, key) => row[key];
2231
2339
  /** Cell text: money as NT$ 1,280, dates as 2026/11/04(三), numbers with their unit after them. */
@@ -2528,26 +2636,41 @@ function FilterButton({ filters, values, activeCount, count, onChange, onClear }
2528
2636
  })]
2529
2637
  });
2530
2638
  }
2531
- /** Long text in a cell: on phone cards at most 2 lines with 「顯示全部」. */
2639
+ /** Long text in a cell. Phone cards: at most 2 lines with 「顯示全部」. Desktop: one line; when it is cut off, hover or
2640
+ * focus shows the whole text in a Tooltip. */
2532
2641
  function LongText({ children }) {
2642
+ const box = React.useRef(null);
2533
2643
  const ref = React.useRef(null);
2644
+ const narrow = useNarrow();
2534
2645
  const [open, setOpen] = React.useState(false);
2535
2646
  const [over, setOver] = React.useState(false);
2647
+ const [cut, setCut] = React.useState("");
2536
2648
  React.useLayoutEffect(() => {
2537
2649
  const el = ref.current;
2538
- if (!el || open) return;
2539
- const check = () => setOver(el.scrollHeight > el.clientHeight + 1);
2650
+ const outer = box.current;
2651
+ if (!el || !outer || open) return;
2652
+ const check = () => {
2653
+ setOver(el.scrollHeight > el.clientHeight + 1);
2654
+ setCut(!narrow && outer.scrollWidth > outer.clientWidth + 1 ? outer.textContent ?? "" : "");
2655
+ };
2540
2656
  check();
2541
- window.addEventListener("resize", check);
2542
- return () => window.removeEventListener("resize", check);
2543
- }, [open, children]);
2544
- return /* @__PURE__ */ jsxs("span", {
2545
- className: "ui-dt-long",
2657
+ const ro = new ResizeObserver(check);
2658
+ ro.observe(outer);
2659
+ return () => ro.disconnect();
2660
+ }, [
2661
+ open,
2662
+ children,
2663
+ narrow
2664
+ ]);
2665
+ const body = /* @__PURE__ */ jsxs("span", {
2666
+ ref: box,
2667
+ className: cx("ui-dt-long", !!cut && "is-cut"),
2668
+ tabIndex: cut ? 0 : void 0,
2546
2669
  children: [/* @__PURE__ */ jsx("span", {
2547
2670
  ref,
2548
2671
  className: cx("ui-dt-long-text", !open && "is-clamped"),
2549
2672
  children
2550
- }), over || open ? /* @__PURE__ */ jsx("button", {
2673
+ }), narrow && (over || open) ? /* @__PURE__ */ jsx("button", {
2551
2674
  type: "button",
2552
2675
  className: "ui-dt-more",
2553
2676
  onClick: (e) => {
@@ -2557,6 +2680,12 @@ function LongText({ children }) {
2557
2680
  children: open ? tr("收合") : tr("顯示全部")
2558
2681
  }) : null]
2559
2682
  });
2683
+ return /* @__PURE__ */ jsx(Tooltip, {
2684
+ label: cut,
2685
+ wrap: true,
2686
+ disabled: !cut,
2687
+ children: body
2688
+ });
2560
2689
  }
2561
2690
  // src/components/DataTable/DataTable.tsx
2562
2691
  const MOVE = {
@@ -2638,6 +2767,7 @@ function DataTable(p) {
2638
2767
  devWarn(cols.some((c) => c.format === "percent" && !c.unit), "DataTable", "format: 'percent' sets 1 decimal and shows no % sign; add unit: '%' to that column.");
2639
2768
  devWarn(rows.length > 1 && rows.every((r) => get(r, "id") == null) && selectable, "DataTable", "rows have no id, so a selection follows the position, not the row. Add an id to each row.");
2640
2769
  const shownCols = cols.filter((c, i) => i === 0 || !hidden[c.key]);
2770
+ const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
2641
2771
  const bodyRef = React.useRef(null);
2642
2772
  const rowEls = React.useRef({});
2643
2773
  const snap = React.useRef(null);
@@ -2949,9 +3079,12 @@ function DataTable(p) {
2949
3079
  setView(v.id);
2950
3080
  setPage(0);
2951
3081
  },
2952
- children: [v.label, /* @__PURE__ */ jsx("span", {
3082
+ children: [v.label, /* @__PURE__ */ jsxs("span", {
2953
3083
  className: "ui-dt-view-n",
2954
- children: format.number(rows.filter((r) => !v.filter || v.filter(r)).length)
3084
+ children: [format.number(rows.filter((r) => !v.filter || v.filter(r)).length), /* @__PURE__ */ jsxs("span", {
3085
+ className: "ui-unit",
3086
+ children: [" ", tr("筆")]
3087
+ })]
2955
3088
  })]
2956
3089
  }, v.id);
2957
3090
  })
@@ -2959,6 +3092,7 @@ function DataTable(p) {
2959
3092
  summary ? /* @__PURE__ */ jsx(Tabs, {
2960
3093
  className: "ui-dt-summary",
2961
3094
  label: summary.label || tr("依狀態篩選"),
3095
+ unit: summary.unit || "筆",
2962
3096
  value: sumVal,
2963
3097
  onChange: (v) => {
2964
3098
  capture("sort");
@@ -3023,85 +3157,94 @@ function DataTable(p) {
3023
3157
  ]
3024
3158
  }),
3025
3159
  /* @__PURE__ */ jsx("div", {
3026
- className: "ui-dt-scroll",
3027
- children: /* @__PURE__ */ jsxs("div", {
3028
- className: "ui-dt-table",
3029
- role: "table",
3030
- "aria-label": p.label || p.caption,
3031
- children: [
3032
- head,
3033
- /* @__PURE__ */ jsx("div", {
3034
- ref: bodyRef,
3035
- className: "ui-dt-body",
3036
- role: "rowgroup",
3037
- children: vis.length ? vis.map((x, i) => {
3038
- const id = visIds[i];
3039
- const on = !!sel[id];
3040
- return /* @__PURE__ */ jsxs("div", {
3041
- "data-rid": id,
3042
- ref: (el) => {
3043
- rowEls.current[id] = el;
3044
- },
3045
- role: "row",
3046
- className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
3047
- style: gridStyle,
3048
- children: [
3049
- selectable ? /* @__PURE__ */ jsx("div", {
3050
- className: "ui-dt-cell ui-dt-sel",
3051
- role: "cell",
3052
- children: /* @__PURE__ */ jsx(RowCheck, {
3053
- v: on,
3054
- label: tr("選取第 {n} 筆", { n: start + i + 1 }),
3055
- onClick: () => toggle([id], !on)
3056
- })
3057
- }) : null,
3058
- shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3059
- role: "cell",
3060
- "data-label": c.label,
3061
- className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
3062
- style: stickyStyle(ci),
3063
- children: cell(x.r, c)
3064
- }, c.key)),
3065
- hasAct ? /* @__PURE__ */ jsx("div", {
3066
- className: "ui-dt-cell ui-dt-acts",
3067
- role: "cell",
3068
- children: p.rowActions?.(x.r)
3069
- }) : null
3070
- ]
3071
- }, id);
3072
- }) : /* @__PURE__ */ jsxs("div", {
3073
- className: "ui-dt-empty",
3074
- children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
3075
- onClick: clearFilters,
3076
- children: tr("清除篩選")
3077
- }) }) : null]
3078
- })
3079
- }),
3080
- p.totals && list.length ? /* @__PURE__ */ jsxs("div", {
3081
- className: "ui-dt-row ui-dt-total",
3082
- role: "row",
3083
- style: gridStyle,
3084
- children: [
3085
- selectable ? /* @__PURE__ */ jsx("div", {
3086
- className: "ui-dt-cell",
3087
- role: "cell"
3088
- }) : null,
3089
- shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3090
- role: "cell",
3091
- className: cellClass(c, ci),
3092
- style: stickyStyle(ci),
3093
- children: total(c, ci)
3094
- }, c.key)),
3095
- hasAct ? /* @__PURE__ */ jsx("div", {
3096
- className: "ui-dt-cell",
3097
- role: "cell"
3098
- }) : null
3099
- ]
3100
- }) : null
3101
- ]
3160
+ className: cx("ui-dt-scroller", scrollMore && "has-more"),
3161
+ children: /* @__PURE__ */ jsx("div", {
3162
+ className: "ui-dt-scroll",
3163
+ ref: scrollRef,
3164
+ onScroll,
3165
+ children: /* @__PURE__ */ jsxs("div", {
3166
+ className: "ui-dt-table",
3167
+ role: "table",
3168
+ "aria-label": p.label || p.caption,
3169
+ children: [
3170
+ head,
3171
+ /* @__PURE__ */ jsx("div", {
3172
+ ref: bodyRef,
3173
+ className: "ui-dt-body",
3174
+ role: "rowgroup",
3175
+ children: vis.length ? vis.map((x, i) => {
3176
+ const id = visIds[i];
3177
+ const on = !!sel[id];
3178
+ return /* @__PURE__ */ jsxs("div", {
3179
+ "data-rid": id,
3180
+ ref: (el) => {
3181
+ rowEls.current[id] = el;
3182
+ },
3183
+ role: "row",
3184
+ className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
3185
+ style: gridStyle,
3186
+ children: [
3187
+ selectable ? /* @__PURE__ */ jsx("div", {
3188
+ className: "ui-dt-cell ui-dt-sel",
3189
+ role: "cell",
3190
+ children: /* @__PURE__ */ jsx(RowCheck, {
3191
+ v: on,
3192
+ label: tr("選取第 {n} 筆", { n: start + i + 1 }),
3193
+ onClick: () => toggle([id], !on)
3194
+ })
3195
+ }) : null,
3196
+ shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3197
+ role: "cell",
3198
+ "data-label": c.label,
3199
+ className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
3200
+ style: stickyStyle(ci),
3201
+ children: cell(x.r, c)
3202
+ }, c.key)),
3203
+ hasAct ? /* @__PURE__ */ jsx("div", {
3204
+ className: "ui-dt-cell ui-dt-acts",
3205
+ role: "cell",
3206
+ children: p.rowActions?.(x.r)
3207
+ }) : null
3208
+ ]
3209
+ }, id);
3210
+ }) : /* @__PURE__ */ jsxs("div", {
3211
+ className: "ui-dt-empty",
3212
+ children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
3213
+ onClick: clearFilters,
3214
+ children: tr("清除篩選")
3215
+ }) }) : null]
3216
+ })
3217
+ }),
3218
+ p.totals && list.length ? /* @__PURE__ */ jsxs("div", {
3219
+ className: "ui-dt-row ui-dt-total",
3220
+ role: "row",
3221
+ style: gridStyle,
3222
+ children: [
3223
+ selectable ? /* @__PURE__ */ jsx("div", {
3224
+ className: "ui-dt-cell",
3225
+ role: "cell"
3226
+ }) : null,
3227
+ shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3228
+ role: "cell",
3229
+ className: cellClass(c, ci),
3230
+ style: stickyStyle(ci),
3231
+ children: total(c, ci)
3232
+ }, c.key)),
3233
+ hasAct ? /* @__PURE__ */ jsx("div", {
3234
+ className: "ui-dt-cell",
3235
+ role: "cell"
3236
+ }) : null
3237
+ ]
3238
+ }) : null
3239
+ ]
3240
+ })
3102
3241
  })
3103
3242
  }),
3104
- list.length > 0 ? /* @__PURE__ */ jsxs("div", {
3243
+ /* @__PURE__ */ jsx(ScrollHint, {
3244
+ show: overflows,
3245
+ done: scrolled
3246
+ }),
3247
+ pages > 1 ? /* @__PURE__ */ jsxs("div", {
3105
3248
  className: "ui-dt-foot",
3106
3249
  children: [/* @__PURE__ */ jsx("span", {
3107
3250
  className: "ui-dt-range",
@@ -3114,7 +3257,7 @@ function DataTable(p) {
3114
3257
  Math.min(list.length, start + pageSize),
3115
3258
  format.number(list.length)
3116
3259
  ])
3117
- }), pages > 1 ? /* @__PURE__ */ jsxs("nav", {
3260
+ }), /* @__PURE__ */ jsxs("nav", {
3118
3261
  className: "ui-dt-pages",
3119
3262
  "aria-label": tr("分頁"),
3120
3263
  children: [
@@ -3142,7 +3285,7 @@ function DataTable(p) {
3142
3285
  children: "›"
3143
3286
  })
3144
3287
  ]
3145
- }) : null]
3288
+ })]
3146
3289
  }) : null
3147
3290
  ]
3148
3291
  });
@@ -3856,7 +3999,7 @@ function LayerGraph(p) {
3856
3999
  }
3857
4000
  const layers = [...byLayer.keys()].sort((a, b) => a - b);
3858
4001
  const cols = Math.max(1, ...layers.map((l) => byLayer.get(l)?.length ?? 0));
3859
- const W = 32 + cols * NW + (cols - 1) * COL;
4002
+ let W = 32 + cols * NW + (cols - 1) * COL;
3860
4003
  const H = 32 + layers.length * NH + Math.max(0, layers.length - 1) * GAP;
3861
4004
  const pos = {};
3862
4005
  const layerIndex = {};
@@ -3873,44 +4016,65 @@ function LayerGraph(p) {
3873
4016
  });
3874
4017
  const maxSize = Math.max(1, ...main.map((n) => sizeOf(n) || 0));
3875
4018
  const maxCount = Math.max(1, ...edges.map((e) => e.count || 0));
4019
+ const isUp = (e) => !!pos[e.from] && !!pos[e.to] && layerIndex[e.to] < layerIndex[e.from];
3876
4020
  const outs = {};
3877
4021
  const ins = {};
4022
+ const upOut = {};
4023
+ const upIn = {};
3878
4024
  for (const e of edges) {
3879
4025
  if (!pos[e.from] || !pos[e.to]) continue;
4026
+ if (isUp(e)) {
4027
+ (upOut[e.from] ??= []).push(e);
4028
+ (upIn[e.to] ??= []).push(e);
4029
+ continue;
4030
+ }
3880
4031
  (outs[e.from] ??= []).push(e);
3881
4032
  (ins[e.to] ??= []).push(e);
3882
4033
  }
4034
+ const ups = edges.filter(isUp);
4035
+ const rowOf = (id) => byLayer.get(layers[layerIndex[id]]) ?? [];
4036
+ const rightmost = (id) => rowOf(id)[rowOf(id).length - 1]?.id === id;
4037
+ const leftmost = (id) => rowOf(id)[0]?.id === id;
4038
+ const onLeft = (e) => !rightmost(e.to) && leftmost(e.to);
4039
+ const upsL = ups.filter(onLeft);
4040
+ const upsR = ups.filter((e) => !onLeft(e));
4041
+ const LANE = 20;
4042
+ const LANE_STEP = 12;
3883
4043
  for (const k in outs) outs[k].sort((a, b) => pos[a.to].x - pos[b.to].x);
3884
4044
  for (const k in ins) ins[k].sort((a, b) => pos[a.from].x - pos[b.from].x);
3885
4045
  const edgeId = (e) => e.id ?? `${e.from}->${e.to}`;
3886
4046
  const pickEdge = p.onSelectEdge;
3887
4047
  const [hover, setHover] = React.useState(null);
3888
- const scroller = React.useRef(null);
3889
- const [more, setMore] = React.useState(false);
3890
- const [scrolled, setScrolled] = React.useState(false);
3891
- const [overflows, setOverflows] = React.useState(false);
3892
- const measureScroll = React.useCallback(() => {
3893
- const el = scroller.current;
3894
- if (!el) return;
3895
- const wide = el.scrollWidth > el.clientWidth + 1;
3896
- setOverflows(wide);
3897
- setMore(wide && el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
3898
- }, []);
3899
- React.useLayoutEffect(() => {
3900
- const el = scroller.current;
3901
- if (!el) return;
3902
- measureScroll();
3903
- const ro = new ResizeObserver(measureScroll);
3904
- ro.observe(el);
3905
- if (el.firstElementChild) ro.observe(el.firstElementChild);
3906
- return () => ro.disconnect();
3907
- }, [measureScroll]);
4048
+ const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
3908
4049
  const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
3909
- const related = (e) => selEdge ? e === selEdge : !!sel && (e.from === sel || e.to === sel);
4050
+ const uses = {};
4051
+ for (const e of p.edges) if (sharedIds.has(e.to) && !sharedIds.has(e.from)) (uses[e.to] ??= {})[e.from] = (uses[e.to]?.[e.from] ?? 0) + (e.count || 0);
4052
+ const selShared = !selEdge && sel != null && sharedIds.has(sel) ? sel : null;
4053
+ const related = (e) => selEdge ? e === selEdge : !!sel && !selShared && (e.from === sel || e.to === sel);
3910
4054
  const focus = !!sel || !!selEdge;
3911
- const near = (id) => selEdge ? id === selEdge.from || id === selEdge.to : !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
4055
+ const near = (id) => selEdge ? id === selEdge.from || id === selEdge.to : selShared ? id === selShared || id in (uses[selShared] ?? {}) : !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
4056
+ const pick = (id, on) => {
4057
+ if (!on && p.selectedEdge != null) pickEdge?.(null);
4058
+ p.onSelect?.(on ? null : id);
4059
+ };
3912
4060
  const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
3913
4061
  const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
4062
+ const upW = (list) => Math.max(0, ...list.map((e) => Math.ceil(Math.max(labelWidth(e.inferred ? e.label || p.inferredLabel || tr("推測") : ""), labelWidth(countText(e))))));
4063
+ if (upsL.length) {
4064
+ const left0 = Math.min(...main.map((n) => pos[n.id].x));
4065
+ const shift = Math.max(0, PAD + upW(upsL) + 8 + (upsL.length - 1) * LANE_STEP + LANE - left0);
4066
+ for (const id in pos) pos[id] = {
4067
+ x: pos[id].x + shift,
4068
+ y: pos[id].y
4069
+ };
4070
+ W += shift;
4071
+ }
4072
+ const boxesLeft = Math.min(...main.map((n) => pos[n.id].x));
4073
+ const boxesRight = Math.max(0, ...main.map((n) => pos[n.id].x + NW));
4074
+ const laneX = (e) => onLeft(e) ? boxesLeft - LANE - upsL.indexOf(e) * LANE_STEP : boxesRight + LANE + upsR.indexOf(e) * LANE_STEP;
4075
+ const upLabelX = boxesRight + LANE + Math.max(0, upsR.length - 1) * LANE_STEP + 8;
4076
+ const upLabelEndL = boxesLeft - LANE - Math.max(0, upsL.length - 1) * LANE_STEP - 8;
4077
+ if (upsR.length) W = Math.max(W, upLabelX + upW(upsR) + PAD);
3914
4078
  const choose = (e) => {
3915
4079
  const id = edgeId(e);
3916
4080
  const next = p.selectedEdge === id ? null : id;
@@ -3920,47 +4084,148 @@ function LayerGraph(p) {
3920
4084
  const paths = [];
3921
4085
  const labels = [];
3922
4086
  const marks = [];
4087
+ const runs = [];
3923
4088
  const arrows = [];
3924
4089
  const hitPaths = [];
3925
4090
  edges.forEach((e, idx) => {
3926
4091
  const a = pos[e.from];
3927
4092
  const b = pos[e.to];
3928
4093
  if (!a || !b) return;
3929
- const oi = outs[e.from].indexOf(e);
3930
- const on = outs[e.from].length;
3931
- const ii = ins[e.to].indexOf(e);
3932
- const inn = ins[e.to].length;
3933
- const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
3934
- const sy = a.y + NH;
3935
- const tx = Math.round(b.x + NW * (ii + 1) / (inn + 1));
3936
- const ty = b.y;
3937
- const off = (oi - (on - 1) / 2) * 6;
3938
- const y1 = sy + GAP / 2 + off;
4094
+ const r = related(e);
4095
+ const dim = focus && !r;
4096
+ const picked = e === selEdge;
4097
+ const hovered = !!pickEdge && hover === edgeId(e) && !r;
4098
+ const up = isUp(e);
3939
4099
  let pts;
3940
- if (layerIndex[e.to] - layerIndex[e.from] > 1) {
3941
- const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
3942
- const mid = (sx + tx) / 2;
3943
- 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)));
3944
- const chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
3945
- const y2 = ty - GAP / 2 + off;
3946
- pts = [
4100
+ let tx;
4101
+ let ty;
4102
+ let arrow;
4103
+ let inn = 1;
4104
+ if (up) {
4105
+ const lx = laneX(e);
4106
+ const L = onLeft(e);
4107
+ const si = upOut[e.from].indexOf(e);
4108
+ const sn = upOut[e.from].length;
4109
+ const ti = upIn[e.to].indexOf(e);
4110
+ const tn = upIn[e.to].length;
4111
+ const start = [];
4112
+ let y0;
4113
+ if (L ? leftmost(e.from) : rightmost(e.from)) {
4114
+ y0 = Math.round(a.y + NH / 2 + (si - (sn - 1) / 2) * 10);
4115
+ start.push([L ? a.x : a.x + NW, y0], [lx, y0]);
4116
+ } else {
4117
+ const px = L ? a.x + 20 + si * 10 : a.x + NW - 20 - si * 10;
4118
+ y0 = a.y - 12 - si * 6;
4119
+ start.push([px, a.y], [px, y0], [lx, y0]);
4120
+ }
4121
+ let y1;
4122
+ if (L || rightmost(e.to)) {
4123
+ y1 = Math.round(b.y + NH / 2 + (ti - (tn - 1) / 2) * 10);
4124
+ tx = L ? b.x : b.x + NW;
4125
+ ty = y1;
4126
+ const back = L ? tx - 9 : tx + 9;
4127
+ pts = [
4128
+ ...start,
4129
+ [lx, y1],
4130
+ [back, y1]
4131
+ ];
4132
+ arrow = `M${back} ${ty - 5} L${back} ${ty + 5} L${tx} ${ty} Z`;
4133
+ arrows.push([
4134
+ Math.min(tx, back),
4135
+ Math.max(tx, back),
4136
+ ty - 5,
4137
+ ty + 5
4138
+ ]);
4139
+ runs.push([
4140
+ Math.min(tx, lx),
4141
+ Math.max(tx, lx),
4142
+ y1 - 3,
4143
+ y1 + 3
4144
+ ]);
4145
+ } else {
4146
+ tx = b.x + NW - 20 - ti * 10;
4147
+ y1 = b.y + NH + 12 + ti * 6;
4148
+ ty = b.y + NH;
4149
+ pts = [
4150
+ ...start,
4151
+ [lx, y1],
4152
+ [tx, y1],
4153
+ [tx, ty + 9]
4154
+ ];
4155
+ arrow = `M${tx - 5} ${ty + 9} L${tx + 5} ${ty + 9} L${tx} ${ty} Z`;
4156
+ arrows.push([
4157
+ tx - 5,
4158
+ tx + 5,
4159
+ ty,
4160
+ ty + 9
4161
+ ]);
4162
+ runs.push([
4163
+ tx,
4164
+ lx,
4165
+ y1 - 3,
4166
+ y1 + 3
4167
+ ]);
4168
+ }
4169
+ const sx0 = start[start.length - 2][0];
4170
+ runs.push([
4171
+ Math.min(sx0, lx),
4172
+ Math.max(sx0, lx),
4173
+ y0 - 3,
4174
+ y0 + 3
4175
+ ]);
4176
+ if (e.inferred || r) {
4177
+ const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
4178
+ marks.push({
4179
+ idx,
4180
+ e,
4181
+ text,
4182
+ tx: L ? upLabelEndL : upLabelX,
4183
+ ty: Math.round((y0 + y1) / 2),
4184
+ left: L,
4185
+ r,
4186
+ dim,
4187
+ up: true
4188
+ });
4189
+ }
4190
+ } else {
4191
+ const oi = outs[e.from].indexOf(e);
4192
+ const on = outs[e.from].length;
4193
+ const ii = ins[e.to].indexOf(e);
4194
+ inn = ins[e.to].length;
4195
+ const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
4196
+ const sy = a.y + NH;
4197
+ tx = Math.round(b.x + NW * (ii + 1) / (inn + 1));
4198
+ ty = b.y;
4199
+ const off = (oi - (on - 1) / 2) * 6;
4200
+ const y1 = sy + GAP / 2 + off;
4201
+ if (layerIndex[e.to] - layerIndex[e.from] > 1) {
4202
+ const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
4203
+ const mid = (sx + tx) / 2;
4204
+ 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)));
4205
+ const chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
4206
+ const y2 = ty - GAP / 2 + off;
4207
+ pts = [
4208
+ [sx, sy],
4209
+ [sx, y1],
4210
+ [chx, y1],
4211
+ [chx, y2],
4212
+ [tx, y2],
4213
+ [tx, ty - 8]
4214
+ ];
4215
+ } else pts = [
3947
4216
  [sx, sy],
3948
4217
  [sx, y1],
3949
- [chx, y1],
3950
- [chx, y2],
3951
- [tx, y2],
4218
+ [tx, y1],
3952
4219
  [tx, ty - 8]
3953
4220
  ];
3954
- } else pts = [
3955
- [sx, sy],
3956
- [sx, y1],
3957
- [tx, y1],
3958
- [tx, ty - 8]
3959
- ];
3960
- const r = related(e);
3961
- const dim = focus && !r;
3962
- const picked = e === selEdge;
3963
- const hovered = !!pickEdge && hover === edgeId(e) && !r;
4221
+ arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
4222
+ arrows.push([
4223
+ tx - 5,
4224
+ tx + 5,
4225
+ ty - 9,
4226
+ ty
4227
+ ]);
4228
+ }
3964
4229
  const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
3965
4230
  const d = route(clean(pts), 10);
3966
4231
  paths.push(/* @__PURE__ */ jsx("path", {
@@ -3974,7 +4239,7 @@ function LayerGraph(p) {
3974
4239
  d,
3975
4240
  role: "button",
3976
4241
  tabIndex: 0,
3977
- "aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)}`,
4242
+ "aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
3978
4243
  "aria-pressed": picked,
3979
4244
  onClick: (ev) => {
3980
4245
  ev.stopPropagation();
@@ -3989,17 +4254,11 @@ function LayerGraph(p) {
3989
4254
  } else if (ev.key === "Escape" && picked) pickEdge(null);
3990
4255
  }
3991
4256
  }, "h" + idx));
3992
- arrows.push([
3993
- tx - 5,
3994
- tx + 5,
3995
- ty - 9,
3996
- ty
3997
- ]);
3998
4257
  paths.push(/* @__PURE__ */ jsx("path", {
3999
4258
  className: cx("ui-lg-arrow", r && "is-related", dim && "is-dim"),
4000
- d: `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`
4259
+ d: arrow
4001
4260
  }, "a" + idx));
4002
- if (e.inferred || r) {
4261
+ if (!up && (e.inferred || r)) {
4003
4262
  const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
4004
4263
  marks.push({
4005
4264
  idx,
@@ -4013,10 +4272,39 @@ function LayerGraph(p) {
4013
4272
  });
4014
4273
  }
4015
4274
  });
4016
- const placed = [...arrows];
4275
+ const placed = [...arrows, ...runs];
4017
4276
  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);
4277
+ const labelEl = (m, x0, top) => /* @__PURE__ */ jsx("span", {
4278
+ className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
4279
+ style: {
4280
+ left: x0,
4281
+ top
4282
+ },
4283
+ onClick: pickEdge ? (ev) => {
4284
+ ev.stopPropagation();
4285
+ choose(m.e);
4286
+ } : void 0,
4287
+ onPointerEnter: pickEdge ? () => setHover(edgeId(m.e)) : void 0,
4288
+ onPointerLeave: pickEdge ? () => setHover(null) : void 0,
4289
+ children: labelParts(m.text)
4290
+ }, "l" + m.idx);
4018
4291
  marks.sort((m, n) => m.ty - n.ty || m.tx - n.tx).forEach((m) => {
4019
4292
  const w = Math.ceil(labelWidth(m.text));
4293
+ if (m.up) {
4294
+ const x0 = m.left ? m.tx - w : m.tx;
4295
+ let top = Math.max(10, Math.min(H - 10, m.ty));
4296
+ for (let k = 0; k < 8 && hits(x0, x0 + w, top - 8, top + 8) && top - 18 >= 10; k++) top -= 18;
4297
+ for (let k = 0; k < 16 && hits(x0, x0 + w, top - 8, top + 8) && top + 18 <= H - 10; k++) top += 18;
4298
+ placed.push([
4299
+ x0,
4300
+ x0 + w,
4301
+ top - 8,
4302
+ top + 8,
4303
+ 6
4304
+ ]);
4305
+ labels.push(labelEl(m, x0, top));
4306
+ return;
4307
+ }
4020
4308
  let left = m.left;
4021
4309
  if (left && m.tx - 8 - w < 0) left = false;
4022
4310
  else if (!left && m.tx + 8 + w > W) left = m.tx - 8 - w >= 0;
@@ -4031,26 +4319,15 @@ function LayerGraph(p) {
4031
4319
  top + 8,
4032
4320
  6
4033
4321
  ]);
4034
- labels.push(/* @__PURE__ */ jsx("span", {
4035
- className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
4036
- style: {
4037
- left: x0,
4038
- top
4039
- },
4040
- onClick: pickEdge ? (ev) => {
4041
- ev.stopPropagation();
4042
- choose(m.e);
4043
- } : void 0,
4044
- onPointerEnter: pickEdge ? () => setHover(edgeId(m.e)) : void 0,
4045
- onPointerLeave: pickEdge ? () => setHover(null) : void 0,
4046
- children: labelParts(m.text)
4047
- }, "l" + m.idx));
4322
+ labels.push(labelEl(m, x0, top));
4048
4323
  });
4049
4324
  const sizeText = p.sizeLabel ?? tr("{n} 個項目");
4325
+ const useText = p.useLabel ?? tr("使用 {n} 次");
4050
4326
  const nodes = main.map((n) => {
4051
4327
  const q = pos[n.id];
4052
4328
  const on = n.id === sel;
4053
4329
  const size = sizeOf(n);
4330
+ const used = selShared ? uses[selShared]?.[n.id] : void 0;
4054
4331
  return /* @__PURE__ */ jsxs("button", {
4055
4332
  type: "button",
4056
4333
  className: cx("ui-lg-node", on && "is-selected", !near(n.id) && "is-dim"),
@@ -4061,13 +4338,16 @@ function LayerGraph(p) {
4061
4338
  height: NH
4062
4339
  },
4063
4340
  "aria-pressed": p.onSelect ? on : void 0,
4064
- onClick: p.onSelect ? () => {
4065
- if (!on && p.selectedEdge != null) pickEdge?.(null);
4066
- p.onSelect?.(on ? null : n.id);
4067
- } : void 0,
4068
- children: [/* @__PURE__ */ jsx("span", {
4069
- className: "ui-lg-name",
4070
- children: n.name || n.id
4341
+ onClick: p.onSelect ? () => pick(n.id, on) : void 0,
4342
+ children: [/* @__PURE__ */ jsxs("span", {
4343
+ className: "ui-lg-head",
4344
+ children: [/* @__PURE__ */ jsx("span", {
4345
+ className: "ui-lg-name",
4346
+ children: n.name || n.id
4347
+ }), used ? /* @__PURE__ */ jsx("span", {
4348
+ className: "ui-lg-use",
4349
+ children: monoNums(useText.replace("{n}", ""), [used])
4350
+ }) : null]
4071
4351
  }), size != null ? /* @__PURE__ */ jsxs("span", {
4072
4352
  className: "ui-lg-size",
4073
4353
  children: [/* @__PURE__ */ jsx("span", {
@@ -4082,36 +4362,34 @@ function LayerGraph(p) {
4082
4362
  }, n.id);
4083
4363
  });
4084
4364
  const sharedMeta = p.sharedMeta ?? tr("{a} 個項目使用,共 {b} 次");
4085
- const sharedRows = shared.map((s) => {
4086
- const callers = /* @__PURE__ */ new Set();
4087
- let total = 0;
4088
- for (const e of p.edges) if (e.to === s.id && !sharedIds.has(e.from)) {
4089
- callers.add(e.from);
4090
- total += e.count || 0;
4091
- }
4092
- return /* @__PURE__ */ jsxs("div", {
4093
- className: "ui-lg-shared-row",
4365
+ const sharedBoxes = shared.map((s) => {
4366
+ const by = uses[s.id] ?? {};
4367
+ const total = Object.values(by).reduce((a, b) => a + b, 0);
4368
+ const on = s.id === sel;
4369
+ const dim = !!selEdge || sel != null && !on && (selShared != null || !(sel in by));
4370
+ return /* @__PURE__ */ jsxs("button", {
4371
+ type: "button",
4372
+ className: cx("ui-lg-node", "ui-lg-chip", on && "is-selected", dim && "is-dim"),
4373
+ "aria-pressed": p.onSelect ? on : void 0,
4374
+ onClick: p.onSelect ? () => pick(s.id, on) : void 0,
4094
4375
  children: [/* @__PURE__ */ jsx("span", {
4095
4376
  className: "ui-lg-name",
4096
4377
  children: s.name || s.id
4097
4378
  }), /* @__PURE__ */ jsx("span", {
4098
4379
  className: "ui-lg-shared-meta",
4099
- children: monoNums(sharedMeta.replace("{a}", "").replace("{b}", ""), [callers.size, total])
4380
+ children: monoNums(sharedMeta.replace("{a}", "").replace("{b}", ""), [Object.keys(by).length, total])
4100
4381
  })]
4101
4382
  }, s.id);
4102
4383
  });
4103
4384
  return /* @__PURE__ */ jsxs("div", {
4104
4385
  className: cx("ui-graph ui-lg", p.className),
4105
4386
  children: [
4106
- /* @__PURE__ */ jsxs("div", {
4107
- className: cx("ui-lg-scroller", more && "has-more"),
4108
- children: [/* @__PURE__ */ jsx("div", {
4387
+ /* @__PURE__ */ jsx("div", {
4388
+ className: cx("ui-lg-scroller", scrollMore && "has-more"),
4389
+ children: /* @__PURE__ */ jsx("div", {
4109
4390
  className: "ui-lg-scroll",
4110
- ref: scroller,
4111
- onScroll: () => {
4112
- setScrolled(true);
4113
- measureScroll();
4114
- },
4391
+ ref: scrollRef,
4392
+ onScroll,
4115
4393
  children: /* @__PURE__ */ jsxs("div", {
4116
4394
  className: "ui-lg-canvas",
4117
4395
  style: {
@@ -4140,30 +4418,30 @@ function LayerGraph(p) {
4140
4418
  }) : null
4141
4419
  ]
4142
4420
  })
4143
- }), overflows && !scrolled ? /* @__PURE__ */ jsxs("span", {
4144
- className: "ui-lg-hint",
4145
- "aria-hidden": "true",
4146
- children: [/* @__PURE__ */ jsx(Icon, {
4147
- name: "arrow-right",
4148
- size: 14
4149
- }), tr("左右滑動")]
4150
- }) : null]
4421
+ })
4422
+ }),
4423
+ /* @__PURE__ */ jsx(ScrollHint, {
4424
+ show: overflows,
4425
+ done: scrolled
4151
4426
  }),
4152
4427
  shared.length ? /* @__PURE__ */ jsxs("div", {
4153
4428
  className: "ui-lg-shared",
4154
4429
  children: [/* @__PURE__ */ jsx("div", {
4155
4430
  className: "ui-lg-shared-title",
4156
4431
  children: p.sharedLabel || tr("共用項目")
4157
- }), sharedRows]
4432
+ }), /* @__PURE__ */ jsx("div", {
4433
+ className: "ui-lg-chips",
4434
+ children: sharedBoxes
4435
+ })]
4158
4436
  }) : null,
4159
- p.legend === false ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [{
4437
+ p.legend === false || !p.legendItems && !edges.some((e) => pos[e.from] && pos[e.to]) ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [...edges.some((e) => !e.inferred && pos[e.from] && pos[e.to]) ? [{
4160
4438
  type: "weight",
4161
4439
  label: "次數越多線越粗"
4162
- }, {
4440
+ }] : [], ...edges.some((e) => e.inferred && pos[e.from] && pos[e.to]) ? [{
4163
4441
  type: "inferred",
4164
4442
  label: p.inferredLabel || "推測的關係",
4165
4443
  text: p.inferredText
4166
- }] })
4444
+ }] : []] })
4167
4445
  ]
4168
4446
  });
4169
4447
  }
@@ -5235,12 +5513,39 @@ const GAP = 12;
5235
5513
  function edge() {
5236
5514
  return parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--space-3")) || 12;
5237
5515
  }
5516
+ const narrowNow = () => typeof window !== "undefined" && window.innerWidth < 600;
5517
+ /** The part of the window between a phone's fixed top bar and bottom tab bar (when the target is not one of them):
5518
+ * the card stays inside it and never covers either bar. The whole window elsewhere. */
5519
+ function bounds(target) {
5520
+ const vh = typeof window === "undefined" ? 0 : window.innerHeight;
5521
+ if (!narrowNow()) return {
5522
+ top: 0,
5523
+ bottom: vh
5524
+ };
5525
+ let top = 0;
5526
+ let bottom = vh;
5527
+ const head = document.querySelector(".ui-shell-top");
5528
+ const bar = document.querySelector(".ui-tabbar");
5529
+ if (head && !(target && head.contains(target))) {
5530
+ const r = head.getBoundingClientRect();
5531
+ if (r.height && r.bottom > 0 && r.bottom < vh / 2) top = r.bottom;
5532
+ }
5533
+ if (bar && !(target && bar.contains(target))) {
5534
+ const r = bar.getBoundingClientRect();
5535
+ if (r.height && r.top > vh / 2 && r.top < vh) bottom = r.top;
5536
+ }
5537
+ return {
5538
+ top,
5539
+ bottom
5540
+ };
5541
+ }
5238
5542
  /** Where the card goes for a highlighted box: the preferred side, the other side, or inside the box at the bottom
5239
5543
  * center of the window when neither side has room. Returns the anchor line the card is placed against. */
5240
- function placeCard(rect, cardH, prefer) {
5544
+ function placeCard(rect, cardH, prefer, area) {
5241
5545
  const margin = typeof document === "undefined" ? 12 : edge();
5242
- const vh = typeof window === "undefined" ? 0 : window.innerHeight;
5243
- const fits = (side) => rect ? side === "bottom" ? rect.top + rect.height + GAP + cardH + margin <= vh : rect.top - GAP - cardH - margin >= 0 : false;
5546
+ const vh = area?.bottom ?? (typeof window === "undefined" ? 0 : window.innerHeight);
5547
+ const vt = area?.top ?? 0;
5548
+ const fits = (side) => rect ? side === "bottom" ? rect.top + rect.height + GAP + cardH + margin <= vh : rect.top - GAP - cardH - margin >= vt : false;
5244
5549
  if (!rect) return {
5245
5550
  mode: "center",
5246
5551
  side: "top",
@@ -5248,7 +5553,7 @@ function placeCard(rect, cardH, prefer) {
5248
5553
  margin,
5249
5554
  line: {
5250
5555
  left: 0,
5251
- top: Math.max(margin + cardH, vh / 2 + cardH / 2),
5556
+ top: Math.max(vt + margin + cardH, (vt + vh) / 2 + cardH / 2),
5252
5557
  width: window.innerWidth,
5253
5558
  height: 0
5254
5559
  }
@@ -5263,7 +5568,7 @@ function placeCard(rect, cardH, prefer) {
5263
5568
  line: rect
5264
5569
  };
5265
5570
  const end = rect.top + rect.height;
5266
- const bottom = Math.max(margin + cardH, end >= vh - margin ? vh - margin : end - margin);
5571
+ const bottom = Math.max(vt + margin + cardH, end >= vh - margin ? vh - margin : end - margin);
5267
5572
  return {
5268
5573
  mode: "inside",
5269
5574
  side: "top",
@@ -5302,9 +5607,17 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5302
5607
  if (!open || !hasStep) return;
5303
5608
  let el = findTarget(target);
5304
5609
  const tall = (el?.getBoundingClientRect().height ?? 0) > window.innerHeight;
5305
- el?.scrollIntoView?.({
5610
+ if (el instanceof HTMLElement && narrowNow()) {
5611
+ const keep = el.style.scrollMarginTop;
5612
+ el.style.scrollMarginTop = bounds(el).top + edge() + pad + "px";
5613
+ el.scrollIntoView?.({
5614
+ block: "start",
5615
+ behavior: "auto"
5616
+ });
5617
+ el.style.scrollMarginTop = keep;
5618
+ } else el?.scrollIntoView?.({
5306
5619
  block: tall ? "start" : "center",
5307
- behavior: reduced() ? "auto" : "smooth"
5620
+ behavior: "auto"
5308
5621
  });
5309
5622
  let raf = 0;
5310
5623
  let last = "";
@@ -5348,7 +5661,8 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5348
5661
  observer.current = new ResizeObserver(measure);
5349
5662
  observer.current.observe(el);
5350
5663
  }, []);
5351
- const place = placeCard(rect, cardH, step?.side ?? "bottom");
5664
+ const area = open && step ? bounds(findTarget(step.target)) : void 0;
5665
+ const place = placeCard(rect, cardH, step?.side ?? "bottom", area);
5352
5666
  const line = place.line;
5353
5667
  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) }), [
5354
5668
  line?.left,