@seanyeh77/ui 0.9.0 → 0.11.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-CkHGBG0X.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 = {
@@ -237,23 +239,31 @@ const PH_ALIAS = {
237
239
  "message-square": "chat-centered"
238
240
  };
239
241
  // src/internal/util.tsx
242
+ /** A value (a row or node id, a file path) as part of an element id: no spaces, so aria-owns, aria-controls and
243
+ * aria-labelledby, which split their value at spaces, still find it. */
244
+ const idPart = (s) => encodeURIComponent(s);
240
245
  /** Joins the truthy class names. */
241
246
  function cx(...names) {
242
247
  return names.filter(Boolean).join(" ");
243
248
  }
244
- function monoNums(text, nums) {
245
- const marks = [
249
+ function seenOnly(text, nums) {
250
+ return splitMarks(text).map(([t, k], i) => /* @__PURE__ */ jsx("span", {
251
+ className: cx("ui-seen", k >= 0 && "ui-num"),
252
+ "data-text": k >= 0 ? nums[k] : t
253
+ }, i));
254
+ }
255
+ function splitMarks(text) {
256
+ return text.split(/(\u0001|\u0002|\u0003)/).filter(Boolean).map((t) => [t, [
246
257
  "",
247
258
  "",
248
259
  ""
249
- ];
250
- return text.split(/(\u0001|\u0002|\u0003)/).map((t, i) => {
251
- const k = marks.indexOf(t);
252
- return k >= 0 ? /* @__PURE__ */ jsx("span", {
253
- className: "ui-num",
254
- children: nums[k]
255
- }, i) : t;
256
- });
260
+ ].indexOf(t)]);
261
+ }
262
+ function monoNums(text, nums) {
263
+ return splitMarks(text).map(([t, k], i) => k >= 0 ? /* @__PURE__ */ jsx("span", {
264
+ className: "ui-num",
265
+ children: nums[k]
266
+ }, i) : t);
257
267
  }
258
268
  /** localStorage get (no value) or set; null when storage is blocked. */
259
269
  function store(key, value) {
@@ -695,13 +705,16 @@ function Tooltip({ label, side = "top", describe = true, wrap = false, disabled
695
705
  }
696
706
  // src/components/IconButton/IconButton.tsx
697
707
  /** A square icon-only button with a tooltip. */
698
- function IconButton({ label, icon, className, tooltip = true, ...native }) {
708
+ function IconButton({ label, icon, className, tooltip = true, filled, ...native }) {
699
709
  const btn = /* @__PURE__ */ jsx("button", {
700
710
  type: "button",
701
711
  ...native,
702
712
  className: cx("ui-iconbtn", className),
703
713
  "aria-label": label,
704
- children: /* @__PURE__ */ jsx(IconOf, { icon })
714
+ children: /* @__PURE__ */ jsx(IconOf, {
715
+ icon,
716
+ filled
717
+ })
705
718
  });
706
719
  return tooltip ? /* @__PURE__ */ jsx(Tooltip, {
707
720
  label,
@@ -1021,6 +1034,7 @@ function AppShell({ nav, value, onNavigate, brand, title, breadcrumb, onSearch,
1021
1034
  icon: "dots-three"
1022
1035
  });
1023
1036
  const [moreOpen, setMoreOpen] = React.useState(false);
1037
+ if (moreOpen && !phone && !tablet) setMoreOpen(false);
1024
1038
  devWarn(phone && withIcon.length < 2, "AppShell", "phones show the top-level nav items as bottom tabs; give at least 2 of them an icon.");
1025
1039
  const current = parentOf(value)?.id ?? value;
1026
1040
  const tabValue = tabs.some((t) => t.id === current) ? current : MORE;
@@ -1350,7 +1364,7 @@ function useFocusRescue(ref, fallback) {
1350
1364
  const onIn = (e) => {
1351
1365
  if (!(e.target instanceof HTMLElement)) return;
1352
1366
  last = e.target;
1353
- index = Array.from(box.querySelectorAll(FOCUSABLE)).indexOf(last);
1367
+ index = list().indexOf(last);
1354
1368
  };
1355
1369
  const rescue = () => {
1356
1370
  const now = list();
@@ -1438,7 +1452,7 @@ function Menu({ items, label, icon = "dots-three", align = "end", triggerClassNa
1438
1452
  }) })] }), danger.length ? /* @__PURE__ */ jsx(Dialog, {
1439
1453
  open: !!asking,
1440
1454
  onClose: () => setAsking(null),
1441
- title: asking ? asking.confirm?.title ?? asking.label + "?" : "",
1455
+ title: asking ? asking.confirm?.title ?? tr("{label}?", { label: asking.label }) : "",
1442
1456
  tone: "danger",
1443
1457
  confirmLabel: asking?.confirm?.confirmLabel ?? asking?.label ?? "",
1444
1458
  onConfirm: () => {
@@ -1713,19 +1727,39 @@ function niceMax(v) {
1713
1727
  const n = Math.ceil(v / e);
1714
1728
  return (n <= 2 ? 2 : n <= 4 ? 4 : n <= 5 ? 5 : n <= 8 ? 8 : 10) * e;
1715
1729
  }
1730
+ /** ← → (and Home, End) on a chart: the item to show next, or null for any other key. */
1731
+ function chartKey(e, at, n) {
1732
+ if (e.altKey || e.metaKey || e.ctrlKey || !n) return null;
1733
+ const i = Math.max(0, at);
1734
+ const to = e.key === "ArrowRight" ? Math.min(n - 1, i + 1) : e.key === "ArrowLeft" ? Math.max(0, i - 1) : e.key === "Home" ? 0 : e.key === "End" ? n - 1 : null;
1735
+ if (to != null) e.preventDefault();
1736
+ return to;
1737
+ }
1716
1738
  // src/components/BarChart/BarChart.tsx
1717
1739
  /** Compares a few categories: rounded bars that grow in, a tooltip on hover. */
1718
1740
  function BarChart({ data, label, unit, decimals, max, className }) {
1719
1741
  const [hi, setHi] = React.useState(-1);
1720
1742
  const top = max || niceMax(Math.max(1, ...data.map((d) => d.value)));
1721
1743
  const suffix = unit ? " " + unit : "";
1744
+ const show = (i) => {
1745
+ setHi(i);
1746
+ announce(data[i].label + tr(":") + format.number(data[i].value, decimals) + suffix);
1747
+ };
1722
1748
  return /* @__PURE__ */ jsxs("div", {
1723
1749
  className: cx("ui-chart", className),
1724
1750
  children: [/* @__PURE__ */ jsxs("div", {
1725
1751
  className: "ui-bars",
1726
1752
  role: "img",
1727
1753
  "aria-label": label,
1754
+ "aria-description": tr("左右方向鍵查看每一項的數值"),
1755
+ tabIndex: data.length ? 0 : void 0,
1728
1756
  onMouseLeave: () => setHi(-1),
1757
+ onFocus: () => hi < 0 && data.length && show(0),
1758
+ onBlur: () => setHi(-1),
1759
+ onKeyDown: (e) => {
1760
+ const to = chartKey(e, hi, data.length);
1761
+ if (to != null) show(to);
1762
+ },
1729
1763
  children: [TICKS.map((f, i) => /* @__PURE__ */ jsx("div", {
1730
1764
  className: cx("ui-bars-grid", !i && "is-axis"),
1731
1765
  style: { bottom: f * 100 + "%" },
@@ -1778,6 +1812,44 @@ function Calendar({ focus, onPick, onHover, dayState }) {
1778
1812
  const today = /* @__PURE__ */ new Date();
1779
1813
  const y = month.getFullYear();
1780
1814
  const m = month.getMonth();
1815
+ const [active, setActive] = React.useState(() => focus || today);
1816
+ const cur = active.getFullYear() === y && active.getMonth() === m ? active : new Date(y, m, Math.min(active.getDate(), new Date(y, m + 1, 0).getDate()));
1817
+ const grid = React.useRef(null);
1818
+ const moveTo = React.useRef(false);
1819
+ React.useEffect(() => {
1820
+ if (!moveTo.current) return;
1821
+ moveTo.current = false;
1822
+ grid.current?.querySelector(".ui-cal-day[tabindex=\"0\"]")?.focus();
1823
+ });
1824
+ const go = (d) => {
1825
+ const step = d < cur ? -1 : 1;
1826
+ for (let k = 0; k < 31 && dayState?.(d)?.disabled; k++) d = dayAdd(d, step);
1827
+ setActive(d);
1828
+ if (d.getMonth() !== m || d.getFullYear() !== y) setMonth(new Date(d.getFullYear(), d.getMonth(), 1));
1829
+ moveTo.current = true;
1830
+ onHover?.(d);
1831
+ };
1832
+ const onKey = (e) => {
1833
+ if (browserKey(e)) return;
1834
+ const wd = (cur.getDay() - format.firstDay() + 7) % 7;
1835
+ const sameDayIn = (dm) => {
1836
+ const last = new Date(cur.getFullYear(), cur.getMonth() + dm + 1, 0).getDate();
1837
+ return new Date(cur.getFullYear(), cur.getMonth() + dm, Math.min(cur.getDate(), last));
1838
+ };
1839
+ const to = {
1840
+ ArrowLeft: () => dayAdd(cur, -1),
1841
+ ArrowRight: () => dayAdd(cur, 1),
1842
+ ArrowUp: () => dayAdd(cur, -7),
1843
+ ArrowDown: () => dayAdd(cur, 7),
1844
+ Home: () => dayAdd(cur, -wd),
1845
+ End: () => dayAdd(cur, 6 - wd),
1846
+ PageUp: () => sameDayIn(-1),
1847
+ PageDown: () => sameDayIn(1)
1848
+ };
1849
+ if (!to[e.key]) return;
1850
+ e.preventDefault();
1851
+ go(to[e.key]());
1852
+ };
1781
1853
  const start = (new Date(y, m, 1).getDay() - format.firstDay() + 7) % 7;
1782
1854
  const days = new Date(y, m + 1, 0).getDate();
1783
1855
  const cells = [...Array(start).fill(null), ...Array.from({ length: days }, (_, i) => new Date(y, m, i + 1))];
@@ -1813,9 +1885,11 @@ function Calendar({ focus, onPick, onHover, dayState }) {
1813
1885
  })
1814
1886
  ]
1815
1887
  }), /* @__PURE__ */ jsxs("div", {
1888
+ ref: grid,
1816
1889
  className: "ui-cal-grid",
1817
1890
  role: "group",
1818
1891
  "aria-label": format.month(month),
1892
+ onKeyDown: onKey,
1819
1893
  children: [format.weekdays().map((w, i) => /* @__PURE__ */ jsx("span", {
1820
1894
  className: "ui-cal-wk",
1821
1895
  "aria-hidden": "true",
@@ -1833,6 +1907,8 @@ function Calendar({ focus, onPick, onHover, dayState }) {
1833
1907
  weekday: false,
1834
1908
  long: true
1835
1909
  }) + (isToday ? tr("(今天)") : ""),
1910
+ tabIndex: sameDay(c, cur) ? 0 : -1,
1911
+ onFocus: () => !sameDay(c, cur) && setActive(c),
1836
1912
  onClick: () => onPick?.(c),
1837
1913
  onMouseEnter: onHover ? () => onHover(c) : void 0,
1838
1914
  children: c.getDate()
@@ -2047,6 +2123,38 @@ const tokenize = (lines, lang) => {
2047
2123
  const OPS = /(->|::|==|!=|<=|>=|&&|\|\||\+\+|--|<<|>>|=>|\+=|-=|\*=|\/=)/;
2048
2124
  const AFTER = /([,.([{;])/;
2049
2125
  /** A piece of code with soft break points after commas, dots and opening brackets, and operators kept together. */
2126
+ const PATH_IN_CODE = /(?<![\w./-])((?:\.{1,2}\/)?(?:[\w.-]+\/)+[\w.-]+\.[A-Za-z0-9]+(?::\d+(?:-\d+)?)?|[\w.-]+\.[A-Za-z0-9]+:\d+(?:-\d+)?)(?![\w/])/g;
2127
+ /** The paths in a comment or string as links (refHref, onRef); the rest stays text. */
2128
+ function withPaths(text, refHref, onRef) {
2129
+ const out = [];
2130
+ let at = 0;
2131
+ for (const m of text.matchAll(PATH_IN_CODE)) {
2132
+ const v = m[1];
2133
+ const href = refHref ? refHref(v) || void 0 : void 0;
2134
+ if (refHref ? !href : !onRef) continue;
2135
+ if (m.index > at) out.push(breakable(text.slice(at, m.index)));
2136
+ const click = onRef ? (e) => {
2137
+ if (href && (e.metaKey || e.ctrlKey || e.shiftKey || e.button === 1)) return;
2138
+ e.preventDefault();
2139
+ onRef(v, e);
2140
+ } : void 0;
2141
+ out.push(href ? /* @__PURE__ */ jsx("a", {
2142
+ className: "ui-cv-ref",
2143
+ href,
2144
+ onClick: click,
2145
+ children: v
2146
+ }, m.index) : /* @__PURE__ */ jsx("button", {
2147
+ type: "button",
2148
+ className: "ui-cv-ref",
2149
+ onClick: click,
2150
+ children: v
2151
+ }, m.index));
2152
+ at = m.index + v.length;
2153
+ }
2154
+ if (!out.length) return breakable(text);
2155
+ if (at < text.length) out.push(breakable(text.slice(at)));
2156
+ return out;
2157
+ }
2050
2158
  function breakable(text) {
2051
2159
  if (!OPS.test(text) && !AFTER.test(text)) return text;
2052
2160
  const out = [];
@@ -2068,7 +2176,7 @@ function breakable(text) {
2068
2176
  return out;
2069
2177
  }
2070
2178
  /** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
2071
- function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, maxHeight, className, ref }) {
2179
+ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, refHref, onRef, maxHeight, className, ref }) {
2072
2180
  const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
2073
2181
  const lang = language || languageOf(file);
2074
2182
  const toks = React.useMemo(() => highlight ? tokenizer(lines, lang) : lines.map((l) => [["", l]]), [
@@ -2123,10 +2231,10 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2123
2231
  className: "ui-cv-text",
2124
2232
  children: [/* @__PURE__ */ jsx("span", {
2125
2233
  className: "ui-visually-hidden ui-cv-sr",
2126
- children: tr("第 {n} 行", { n }) + ":"
2234
+ children: tr("第 {n} 行", { n }) + tr(":")
2127
2235
  }), toks[i].map(([cls, text], j) => cls ? /* @__PURE__ */ jsx("span", {
2128
2236
  className: cls,
2129
- children: breakable(text)
2237
+ children: (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef) : breakable(text)
2130
2238
  }, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))]
2131
2239
  })]
2132
2240
  }, i));
@@ -2146,9 +2254,9 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2146
2254
  children: title
2147
2255
  }), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsxs("span", {
2148
2256
  className: "ui-cv-lang",
2149
- children: [/* @__PURE__ */ jsxs("span", {
2257
+ children: [/* @__PURE__ */ jsx("span", {
2150
2258
  className: "ui-visually-hidden",
2151
- children: [tr("程式語言"), ":"]
2259
+ children: tr("程式語言") + tr(":")
2152
2260
  }), tr(languageLabel || LANGUAGE_NAMES[lang] || lang)]
2153
2261
  }) : null]
2154
2262
  }) : null;
@@ -2401,7 +2509,7 @@ function DangerZone({ title, description, actionLabel, onAction, confirm, classN
2401
2509
  className: "ui-danger-row",
2402
2510
  children: [/* @__PURE__ */ jsx("p", { children: description }), /* @__PURE__ */ jsx(Button, {
2403
2511
  variant: "danger",
2404
- confirm: confirm ?? { title: `${label}?` },
2512
+ confirm: confirm ?? { title: tr("{label}?", { label }) },
2405
2513
  onClick: onAction,
2406
2514
  children: label
2407
2515
  })]
@@ -2540,7 +2648,23 @@ function useScrollHint() {
2540
2648
  const ro = new ResizeObserver(measure);
2541
2649
  ro.observe(el);
2542
2650
  if (el.firstElementChild) ro.observe(el.firstElementChild);
2543
- return () => ro.disconnect();
2651
+ let raf = 0;
2652
+ const later = () => {
2653
+ cancelAnimationFrame(raf);
2654
+ raf = requestAnimationFrame(measure);
2655
+ };
2656
+ const mo = new MutationObserver(later);
2657
+ mo.observe(el, {
2658
+ childList: true,
2659
+ subtree: true,
2660
+ characterData: true
2661
+ });
2662
+ document.fonts?.ready.then(later).catch(() => {});
2663
+ return () => {
2664
+ ro.disconnect();
2665
+ mo.disconnect();
2666
+ cancelAnimationFrame(raf);
2667
+ };
2544
2668
  }, [measure]);
2545
2669
  return {
2546
2670
  ref,
@@ -2675,7 +2799,8 @@ function writeUrl(prefix, filters, values, q) {
2675
2799
  }
2676
2800
  // src/internal/FloatingPanel.tsx
2677
2801
  /** 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 }) {
2802
+ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, boundary, children, ...aria }) {
2803
+ const within = boundary?.current ?? void 0;
2679
2804
  return /* @__PURE__ */ jsxs(Popover$1.Root, {
2680
2805
  open,
2681
2806
  onOpenChange,
@@ -2690,6 +2815,12 @@ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "
2690
2815
  align,
2691
2816
  sideOffset,
2692
2817
  anchor,
2818
+ collisionBoundary: within,
2819
+ collisionPadding: within ? 0 : void 0,
2820
+ collisionAvoidance: within ? {
2821
+ side: "flip",
2822
+ align: "shift"
2823
+ } : void 0,
2693
2824
  children: /* @__PURE__ */ jsx(Popover$1.Popup, {
2694
2825
  className,
2695
2826
  "aria-label": aria["aria-label"],
@@ -2755,11 +2886,12 @@ function ColumnMenu({ cols, hidden, onToggle }) {
2755
2886
  });
2756
2887
  }
2757
2888
  /** 「篩選」 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 }) {
2889
+ function FilterButton({ filters, values, activeCount, count, onChange, onClear, boundary }) {
2759
2890
  const [open, setOpen] = React.useState(false);
2760
2891
  return /* @__PURE__ */ jsxs(FloatingPanel, {
2761
2892
  open,
2762
2893
  onOpenChange: setOpen,
2894
+ boundary,
2763
2895
  className: "ui-dt-filterpop",
2764
2896
  "aria-label": tr("篩選"),
2765
2897
  trigger: /* @__PURE__ */ jsxs("button", {
@@ -2870,6 +3002,20 @@ function FilterButton({ filters, values, activeCount, count, onChange, onClear }
2870
3002
  })]
2871
3003
  });
2872
3004
  }
3005
+ /** A short cell with its whole text in a Tooltip (a mouse; not on a touch screen, where the row's details show it). */
3006
+ function FullText({ text, children }) {
3007
+ const touch = useMedia(TOUCH_ONLY);
3008
+ return /* @__PURE__ */ jsx(Tooltip, {
3009
+ label: text,
3010
+ wrap: true,
3011
+ describe: false,
3012
+ disabled: touch || !text,
3013
+ children: /* @__PURE__ */ jsx("span", {
3014
+ className: "ui-dt-full",
3015
+ children
3016
+ })
3017
+ });
3018
+ }
2873
3019
  /** Long text in a cell. Phone cards: at most 2 lines with 「顯示全部」. Desktop: one line; the row's caret shows it in
2874
3020
  * 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
3021
  * screen: a tap would leave it over the next rows. */
@@ -2937,6 +3083,7 @@ const ARROWS = {
2937
3083
  };
2938
3084
  const get = (row, key) => row[key];
2939
3085
  const isNum = (c) => c.numeric || c.format === "money" || c.format === "percent";
3086
+ const ROW_CONTROLS = "a, button, input, select, textarea, label, [role=\"checkbox\"], [role=\"button\"], [role=\"menuitem\"], [role=\"link\"], [contenteditable]";
2940
3087
  function RowCheck({ v, label, onClick }) {
2941
3088
  return /* @__PURE__ */ jsx("button", {
2942
3089
  type: "button",
@@ -2984,8 +3131,10 @@ function DataTable(p) {
2984
3131
  const [opened, setOpened] = React.useState({});
2985
3132
  const narrow = useNarrow();
2986
3133
  const uid = React.useId();
3134
+ const rootRef = React.useRef(null);
2987
3135
  const [sel, setSel] = React.useState({});
2988
3136
  const [sumVal, setSumVal] = React.useState("all");
3137
+ const [fit, setFit] = React.useState({});
2989
3138
  const [resetKey, setResetKey] = React.useState(p.resetKey);
2990
3139
  const resetting = resetKey !== p.resetKey;
2991
3140
  if (resetting) {
@@ -3001,6 +3150,7 @@ function DataTable(p) {
3001
3150
  });
3002
3151
  setToggled({});
3003
3152
  setOpened({});
3153
+ setFit({});
3004
3154
  }
3005
3155
  const valuesKey = JSON.stringify(values);
3006
3156
  React.useEffect(() => {
@@ -3193,20 +3343,57 @@ function DataTable(p) {
3193
3343
  const m = c.mobile || (!hasTitle && ci === 0 ? "title" : null);
3194
3344
  return m ? "is-m-" + m : null;
3195
3345
  };
3196
- const longCols = shownCols.filter((c) => c.long);
3346
+ const longCols = shownCols.filter((c) => c.long || c.fullText);
3197
3347
  const expander = longCols.length > 0 && !narrow;
3198
3348
  const EXP = 40;
3349
+ const minOf = (c) => Math.max(c.width || (c.numeric ? 96 : 120), fit[c.key] || 0);
3199
3350
  const template = [
3200
3351
  expander ? "40px" : null,
3201
3352
  selectable ? "46px" : null,
3202
- ...shownCols.map((c) => c.width ? `minmax(${c.width}px, ${c.grow || 1}fr)` : c.numeric ? "minmax(96px, .8fr)" : "minmax(120px, 1fr)"),
3353
+ ...shownCols.map((c) => `minmax(${minOf(c)}px, ${c.grow || (c.width ? 1 : c.numeric ? .8 : 1)}fr)`),
3203
3354
  hasAct ? actW + "px" : null
3204
3355
  ].filter(Boolean).join(" ");
3205
- const minW = (expander ? EXP : 0) + (selectable ? 46 : 0) + shownCols.reduce((a, c) => a + (c.width || (c.numeric ? 96 : 120)), 0) + (hasAct ? actW : 0);
3356
+ const minW = (expander ? EXP : 0) + (selectable ? 46 : 0) + shownCols.reduce((a, c) => a + minOf(c), 0) + (hasAct ? actW : 0);
3206
3357
  const gridStyle = {
3207
3358
  gridTemplateColumns: template,
3208
3359
  minWidth: minW
3209
3360
  };
3361
+ React.useLayoutEffect(() => {
3362
+ const root = rootRef.current;
3363
+ if (!root || narrow) return;
3364
+ const measure = () => {
3365
+ const need = {};
3366
+ for (const el of root.querySelectorAll(".ui-dt-body .ui-dt-cell[data-col]:not(.is-long)")) {
3367
+ const over = el.scrollWidth - el.clientWidth;
3368
+ const key = el.dataset.col;
3369
+ if (over > 1 && key) need[key] = Math.max(need[key] ?? 0, Math.ceil(el.getBoundingClientRect().width + over));
3370
+ }
3371
+ setFit((f) => {
3372
+ const grow = Object.entries(need).filter(([k, w]) => w > (f[k] ?? 0));
3373
+ return grow.length ? {
3374
+ ...f,
3375
+ ...Object.fromEntries(grow)
3376
+ } : f;
3377
+ });
3378
+ };
3379
+ measure();
3380
+ let frame = 0;
3381
+ const later = () => {
3382
+ cancelAnimationFrame(frame);
3383
+ frame = requestAnimationFrame(measure);
3384
+ };
3385
+ const mo = new MutationObserver(later);
3386
+ mo.observe(root, {
3387
+ childList: true,
3388
+ subtree: true,
3389
+ characterData: true
3390
+ });
3391
+ document.fonts?.ready.then(later).catch(() => {});
3392
+ return () => {
3393
+ mo.disconnect();
3394
+ cancelAnimationFrame(frame);
3395
+ };
3396
+ }, [narrow, resetKey]);
3210
3397
  const stickyStyle = (ci) => ci === 0 && sticky ? { left: (expander ? EXP : 0) + (selectable ? 46 : 0) } : void 0;
3211
3398
  const cellClass = (c, ci, ...more) => cx("ui-dt-cell", isNum(c) && "is-num", ci === 0 && sticky && "is-sticky", ...more);
3212
3399
  const head = selectable && selIds.length && p.bulkActions ? /* @__PURE__ */ jsxs("div", {
@@ -3306,7 +3493,13 @@ function DataTable(p) {
3306
3493
  else v = markMatch(cellText(c, raw), mark);
3307
3494
  return v;
3308
3495
  };
3309
- const cell = (r, c) => c.long ? /* @__PURE__ */ jsx(LongText, { children: cellInner(r, c) }) : cellInner(r, c);
3496
+ const cell = (r, c) => {
3497
+ const v = c.long ? /* @__PURE__ */ jsx(LongText, { children: cellInner(r, c) }) : cellInner(r, c);
3498
+ return c.fullText ? /* @__PURE__ */ jsx(FullText, {
3499
+ text: c.fullText(r),
3500
+ children: v
3501
+ }) : v;
3502
+ };
3310
3503
  const total = (c, ci) => {
3311
3504
  const how = p.totals?.[c.key];
3312
3505
  const rowsAll = list.map((x) => x.r);
@@ -3323,6 +3516,7 @@ function DataTable(p) {
3323
3516
  return "";
3324
3517
  };
3325
3518
  return /* @__PURE__ */ jsxs("div", {
3519
+ ref: rootRef,
3326
3520
  className: cx("ui-dt", selIds.length && "has-sel", p.className),
3327
3521
  children: [
3328
3522
  p.caption ? /* @__PURE__ */ jsx("div", {
@@ -3392,6 +3586,7 @@ function DataTable(p) {
3392
3586
  className: "ui-dt-search"
3393
3587
  }) : null,
3394
3588
  filters.length ? /* @__PURE__ */ jsx(FilterButton, {
3589
+ boundary: rootRef,
3395
3590
  filters,
3396
3591
  values,
3397
3592
  activeCount: activeN,
@@ -3412,7 +3607,7 @@ function DataTable(p) {
3412
3607
  className: "ui-dt-result",
3413
3608
  children: [/* @__PURE__ */ jsx("span", {
3414
3609
  "aria-hidden": "true",
3415
- children: monoNums(tr("{n} / {total} 筆", {
3610
+ children: seenOnly(tr("{n} / {total} 筆", {
3416
3611
  n: "",
3417
3612
  total: ""
3418
3613
  }), [format.number(list.length), format.number(baseCount)])
@@ -3451,7 +3646,7 @@ function DataTable(p) {
3451
3646
  const id = visIds[i];
3452
3647
  const on = !!sel[id];
3453
3648
  const open = expander && !!opened[id];
3454
- const detailId = `${uid}-d-${id}`;
3649
+ const detailId = `${uid}-d-${idPart(id)}`;
3455
3650
  const rowName = shownCols[0] ? String(cellText(shownCols[0], get(x.r, shownCols[0].key)) ?? "") : "";
3456
3651
  return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsxs("div", {
3457
3652
  "data-rid": id,
@@ -3459,8 +3654,18 @@ function DataTable(p) {
3459
3654
  rowEls.current[id] = el;
3460
3655
  },
3461
3656
  role: "row",
3462
- className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
3657
+ "aria-labelledby": shownCols.length ? `${uid}-n-${start + i}` : void 0,
3658
+ className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && "has-exp"),
3463
3659
  style: gridStyle,
3660
+ onClick: expander ? (e) => {
3661
+ const t = e.target;
3662
+ if (t.closest(ROW_CONTROLS) && t.closest(ROW_CONTROLS) !== e.currentTarget) return;
3663
+ if (String(window.getSelection() ?? "")) return;
3664
+ setOpened({
3665
+ ...opened,
3666
+ [id]: !open
3667
+ });
3668
+ } : void 0,
3464
3669
  children: [
3465
3670
  expander ? /* @__PURE__ */ jsx("div", {
3466
3671
  className: "ui-dt-cell ui-dt-exp",
@@ -3492,7 +3697,10 @@ function DataTable(p) {
3492
3697
  }) : null,
3493
3698
  shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3494
3699
  role: "cell",
3700
+ id: ci === 0 ? `${uid}-n-${start + i}` : void 0,
3701
+ "aria-description": c.fullText ? c.fullText(x.r) || void 0 : void 0,
3495
3702
  "data-label": c.label,
3703
+ "data-col": c.key,
3496
3704
  className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
3497
3705
  style: stickyStyle(ci),
3498
3706
  children: cell(x.r, c)
@@ -3519,7 +3727,7 @@ function DataTable(p) {
3519
3727
  children: c.label
3520
3728
  }), /* @__PURE__ */ jsx("div", {
3521
3729
  className: "ui-dt-detail-text",
3522
- children: cellInner(x.r, c)
3730
+ children: c.fullText ? c.fullText(x.r) : cellInner(x.r, c)
3523
3731
  })]
3524
3732
  }, c.key))
3525
3733
  })
@@ -3618,9 +3826,12 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
3618
3826
  const [open, setOpen] = React.useState(false);
3619
3827
  const [typed, setTyped] = React.useState(null);
3620
3828
  const field = React.useRef(null);
3621
- const bad = typed !== null && typed !== "" && !parseDate(typed);
3829
+ const wrong = typed !== null && typed !== "" && !parseDate(typed);
3830
+ const [left, setLeft] = React.useState(false);
3831
+ const bad = wrong && left;
3622
3832
  const commit = (d) => {
3623
3833
  setTyped(null);
3834
+ setLeft(false);
3624
3835
  onChange(d);
3625
3836
  setOpen(false);
3626
3837
  };
@@ -3640,6 +3851,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
3640
3851
  className: "ui-datefield-input",
3641
3852
  value: typed ?? fmtDate(value),
3642
3853
  placeholder: "YYYY/MM/DD",
3854
+ "aria-required": required || void 0,
3643
3855
  "aria-invalid": bad || void 0,
3644
3856
  onChange: (e) => {
3645
3857
  const t = e.target.value;
@@ -3648,7 +3860,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
3648
3860
  if (d) onChange(d);
3649
3861
  else if (t === "") onChange(null);
3650
3862
  },
3651
- onBlur: () => !bad && setTyped(null)
3863
+ onBlur: () => wrong ? setLeft(true) : setTyped(null)
3652
3864
  }), /* @__PURE__ */ jsxs(FloatingPanel, {
3653
3865
  open,
3654
3866
  onOpenChange: setOpen,
@@ -3693,6 +3905,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
3693
3905
  }
3694
3906
  // src/components/DateRangePicker/DateRangePicker.tsx
3695
3907
  /** A period: quick ranges (今天、最近 7 天、最近 30 天、本月、上個月) beside one month. Click a start day, then an end day. */
3908
+ const day = (d) => format.date(d, { weekday: false });
3696
3909
  function DateRangePicker({ label, value, onChange, placeholder, className }) {
3697
3910
  const [open, setOpen] = React.useState(false);
3698
3911
  const [first, setFirst] = React.useState(null);
@@ -3730,13 +3943,13 @@ function DateRangePicker({ label, value, onChange, placeholder, className }) {
3730
3943
  className: cx("ui-datefield", "ui-rangefield", open && "is-open"),
3731
3944
  "aria-label": value[0] ? tr("{label}:{a} 到 {b}", {
3732
3945
  label: label || tr("期間"),
3733
- a: fmtDate(value[0]),
3734
- b: fmtDate(value[1])
3735
- }) : `${label || tr("期間")}:${placeholder || tr("選擇期間")}`,
3946
+ a: day(value[0]),
3947
+ b: day(value[1])
3948
+ }) : `${label || tr("期間")}${tr(":")}${placeholder || tr("選擇期間")}`,
3736
3949
  children: [/* @__PURE__ */ jsx(Icon, {
3737
3950
  name: "calendar-blank",
3738
3951
  size: 18
3739
- }), /* @__PURE__ */ jsx("span", { children: value[0] ? `${fmtDate(value[0])} – ${fmtDate(value[1])}` : placeholder || tr("選擇期間") })]
3952
+ }), /* @__PURE__ */ jsx("span", { children: value[0] ? `${day(value[0])} – ${day(value[1])}` : placeholder || tr("選擇期間") })]
3740
3953
  }),
3741
3954
  children: [/* @__PURE__ */ jsx("div", {
3742
3955
  className: "ui-quick",
@@ -3888,7 +4101,16 @@ function SplitPane({ a, b, defaultB = 420, minA = 360, minB = 280, storageKey, l
3888
4101
  onPointerMove: onMove,
3889
4102
  onPointerUp: onUp,
3890
4103
  onPointerCancel: onUp,
3891
- onDoubleClick: () => set(defaultB)
4104
+ onDoubleClick: () => set(defaultB),
4105
+ children: /* @__PURE__ */ jsxs("span", {
4106
+ className: "ui-split-grip",
4107
+ "aria-hidden": "true",
4108
+ children: [
4109
+ /* @__PURE__ */ jsx("i", {}),
4110
+ /* @__PURE__ */ jsx("i", {}),
4111
+ /* @__PURE__ */ jsx("i", {})
4112
+ ]
4113
+ })
3892
4114
  }),
3893
4115
  /* @__PURE__ */ jsx("div", {
3894
4116
  id,
@@ -3967,7 +4189,7 @@ function ErrorPage({ code, title, description, onBack, onHome, homeHref = "/", c
3967
4189
  }
3968
4190
  // src/components/ProgressBar/ProgressBar.tsx
3969
4191
  /** Progress of a task with a known end, with the percentage after the bar. */
3970
- function ProgressBar({ value, label, className }) {
4192
+ function ProgressBar({ value, label, className, ...aria }) {
3971
4193
  const v = Math.max(0, Math.min(100, value || 0));
3972
4194
  const done = v >= 100;
3973
4195
  return /* @__PURE__ */ jsxs("div", {
@@ -3983,7 +4205,7 @@ function ProgressBar({ value, label, className }) {
3983
4205
  "aria-valuemin": 0,
3984
4206
  "aria-valuemax": 100,
3985
4207
  "aria-valuenow": Math.round(v),
3986
- "aria-label": label,
4208
+ "aria-label": label || aria["aria-label"],
3987
4209
  children: /* @__PURE__ */ jsx("div", {
3988
4210
  className: "ui-progress-fill",
3989
4211
  style: { width: v + "%" }
@@ -4075,7 +4297,10 @@ function FileUpload({ label, files = [], onAdd, onRemove, onRetry, limitText, ac
4075
4297
  className: "ui-upload-size",
4076
4298
  children: fl.size
4077
4299
  }) : null]
4078
- }), !fail ? /* @__PURE__ */ jsx(ProgressBar, { value: fl.status === "done" ? 100 : fl.progress || 0 }) : /* @__PURE__ */ jsxs("div", {
4300
+ }), !fail ? /* @__PURE__ */ jsx(ProgressBar, {
4301
+ value: fl.status === "done" ? 100 : fl.progress || 0,
4302
+ "aria-label": tr("{name} 上傳進度", { name: fl.name })
4303
+ }) : /* @__PURE__ */ jsxs("div", {
4079
4304
  className: "ui-upload-error",
4080
4305
  role: "alert",
4081
4306
  children: [fl.error || tr("上傳失敗,請再試一次。"), onRetry ? /* @__PURE__ */ jsx("button", {
@@ -4123,6 +4348,14 @@ function Term({ children, title, text, content, code, action, refHref, onRef, is
4123
4348
  const txt = !!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim());
4124
4349
  setInline(txt);
4125
4350
  }, [children]);
4351
+ const block = React.useRef(null);
4352
+ const toggle = (next) => {
4353
+ if (next) {
4354
+ const el = ref.current?.closest(".ui-card, .ui-split-a, .ui-split-b, .ui-shell-main, main") ?? null;
4355
+ block.current = el && el.getBoundingClientRect().width >= 240 ? el : null;
4356
+ }
4357
+ setOpen(next);
4358
+ };
4126
4359
  const heading = title || (typeof children === "string" ? children : "");
4127
4360
  const trigger = /* @__PURE__ */ jsxs("button", {
4128
4361
  type: "button",
@@ -4189,10 +4422,11 @@ function Term({ children, title, text, content, code, action, refHref, onRef, is
4189
4422
  });
4190
4423
  return /* @__PURE__ */ jsx(FloatingPanel, {
4191
4424
  open,
4192
- onOpenChange: setOpen,
4425
+ onOpenChange: toggle,
4193
4426
  sideOffset: 8,
4194
4427
  className: "ui-term-pop",
4195
4428
  trigger,
4429
+ boundary: block,
4196
4430
  children: body(Popover$1.Title, Popover$1.Close)
4197
4431
  });
4198
4432
  }
@@ -4372,6 +4606,20 @@ function KpiCard(props) {
4372
4606
  const scrollMemory = /* @__PURE__ */ new Map();
4373
4607
  let measure;
4374
4608
  const SPLIT = /(`[^`]+`|\d[\d,.]*)/;
4609
+ /** A label with a number: {n} in a string, or a function of the number; the number comes back as \u0001 (monoNums). */
4610
+ function withNum(label, n, fallback) {
4611
+ if (typeof label === "function") {
4612
+ const t = label(n);
4613
+ for (const s of [format.number(n), String(n)]) if (t.includes(s)) return t.replace(s, "");
4614
+ return t;
4615
+ }
4616
+ return (label ?? fallback(n)).replace("{n}", "");
4617
+ }
4618
+ /** The default for one (「1 call」) where the language has its own word for it, else the {n} form. */
4619
+ function byCount(n, one, many) {
4620
+ const t = n === 1 ? tr(one) : "";
4621
+ return t && t !== one ? t : tr(many);
4622
+ }
4375
4623
  function labelWidth(text) {
4376
4624
  const parts = text.split(SPLIT).filter(Boolean);
4377
4625
  if (measure === void 0) measure = document.createElement("canvas").getContext("2d");
@@ -4386,6 +4634,8 @@ function labelWidth(text) {
4386
4634
  return w + c.measureText(t[0] === "`" ? t.slice(1, -1) : t).width;
4387
4635
  }, 0);
4388
4636
  }
4637
+ const LABELS_KEY = "ui-lg-labels:";
4638
+ const allIds = (nodes) => nodes.map((n) => n.id).join("|");
4389
4639
  const GROW = 24;
4390
4640
  const GROW_MAX = 144;
4391
4641
  /** The label on 1 line, then wrapped onto 2, 3 and 4 lines as evenly as it goes. Breaks between Chinese characters
@@ -4465,12 +4715,23 @@ const clean = (pts) => pts.filter((q, i) => {
4465
4715
  return !a || !c || !(a[0] === q[0] && q[0] === c[0] || a[1] === q[1] && q[1] === c[1]);
4466
4716
  });
4467
4717
  /** 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. */
4718
+ * shared items are listed under the diagram instead of drawn. Wider than its box: the boxes narrow (down to 120 px),
4719
+ * then the whole diagram scales down (to 0.75 at least); past that it scrolls sideways (PM). */
4469
4720
  function LayerGraph(p) {
4470
- const NW = p.nodeWidth || 200;
4721
+ const [avail, setAvail] = React.useState(0);
4722
+ const [fit, setFit] = React.useState(null);
4723
+ const fitted = fit && fit.at === avail ? fit : null;
4724
+ const NW = fitted?.nw ?? (p.nodeWidth || 200);
4471
4725
  const NH = 60;
4472
4726
  const GAP = 56;
4473
- const COL = 40;
4727
+ const spreadKey = avail + "#" + p.nodes.map((n) => n.id).join("|") + "#" + p.edges.map((e) => e.from + ">" + e.to + ":" + (e.label ?? "")).join("|");
4728
+ const [spreadAt, setSpread] = React.useState({
4729
+ key: "",
4730
+ n: 0
4731
+ });
4732
+ const spread = spreadAt.key === spreadKey ? spreadAt.n : 0;
4733
+ const COL = (fitted?.col ?? 40) + spread * 24;
4734
+ const scale = fitted?.scale ?? 1;
4474
4735
  const PAD = 16;
4475
4736
  const all = p.nodes;
4476
4737
  const sel = p.selected ?? null;
@@ -4506,13 +4767,25 @@ function LayerGraph(p) {
4506
4767
  });
4507
4768
  });
4508
4769
  const rowTop = (k) => PAD + k * NH + gaps.slice(0, k).reduce((a, b) => a + b, 0);
4770
+ const extRow = byLayer.get(EXTERNAL) ?? [];
4771
+ const extW = Math.max(NW, Math.min(p.nodeWidth || 200, W - PAD));
4772
+ const boxOf = (id) => {
4773
+ const wide = extRow.length === 1 && extRow[0].id === id ? extW : NW;
4774
+ return {
4775
+ x: pos[id].x + (NW - wide) / 2,
4776
+ w: wide
4777
+ };
4778
+ };
4509
4779
  const placeRows = () => {
4510
4780
  for (const id in pos) pos[id].y = rowTop(layerIndex[id]);
4511
- H = rowTop(layers.length - 1) + NH + PAD;
4781
+ H = rowTop(layers.length - 1) + NH + PAD + (flatRow[layers.length - 1]?.length ? FLAT_ROOM : 0);
4512
4782
  };
4513
4783
  const maxSize = Math.max(1, ...main.map((n) => sizeOf(n) || 0));
4514
4784
  const maxCount = Math.max(1, ...edges.map((e) => e.count || 0));
4515
4785
  const isUp = (e) => !!pos[e.from] && !!pos[e.to] && layerIndex[e.to] < layerIndex[e.from];
4786
+ const isFlat = (e) => !!pos[e.from] && !!pos[e.to] && e.from !== e.to && layerIndex[e.to] === layerIndex[e.from];
4787
+ const flatIn = {};
4788
+ const flatRow = {};
4516
4789
  const outs = {};
4517
4790
  const ins = {};
4518
4791
  const upOut = {};
@@ -4525,8 +4798,14 @@ function LayerGraph(p) {
4525
4798
  continue;
4526
4799
  }
4527
4800
  (outs[e.from] ??= []).push(e);
4801
+ if (isFlat(e)) {
4802
+ (flatIn[e.to] ??= []).push(e);
4803
+ (flatRow[layerIndex[e.from]] ??= []).push(e);
4804
+ continue;
4805
+ }
4528
4806
  (ins[e.to] ??= []).push(e);
4529
4807
  }
4808
+ const FLAT_ROOM = 20 + 10 * Math.max(0, (flatRow[layers.length - 1]?.length ?? 0) - 1);
4530
4809
  const ups = edges.filter(isUp);
4531
4810
  const rowOf = (id) => byLayer.get(layers[layerIndex[id]]) ?? [];
4532
4811
  const rightmost = (id) => rowOf(id)[rowOf(id).length - 1]?.id === id;
@@ -4540,6 +4819,21 @@ function LayerGraph(p) {
4540
4819
  for (const k in ins) ins[k].sort((a, b) => pos[a.from].x - pos[b.from].x);
4541
4820
  const edgeId = (e) => e.id ?? `${e.from}->${e.to}`;
4542
4821
  const pickEdge = p.onSelectEdge;
4822
+ const [labelsOn, setLabelsOn] = React.useState(() => {
4823
+ try {
4824
+ const v = window.localStorage.getItem(LABELS_KEY + (p.scrollKey ?? allIds(p.nodes)));
4825
+ if (v === "1" || v === "0") return v === "1";
4826
+ } catch {}
4827
+ return p.edgeLabels !== "hover";
4828
+ });
4829
+ const peek = !labelsOn;
4830
+ const switchLabels = () => {
4831
+ const on = !labelsOn;
4832
+ setLabelsOn(on);
4833
+ try {
4834
+ window.localStorage.setItem(LABELS_KEY + (p.scrollKey ?? allIds(p.nodes)), on ? "1" : "0");
4835
+ } catch {}
4836
+ };
4543
4837
  const [hover, setHover] = React.useState(null);
4544
4838
  const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
4545
4839
  const uid = React.useId().replace(/:/g, "");
@@ -4572,7 +4866,18 @@ function LayerGraph(p) {
4572
4866
  p.onSelect?.(on ? null : id);
4573
4867
  };
4574
4868
  const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
4575
- const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
4869
+ const countText = (e) => {
4870
+ const n = e.count ?? 0;
4871
+ return typeof p.countLabel === "function" ? p.countLabel(n) : (p.countLabel ?? byCount(n, "1 次", "{n} 次")).replace("{n}", format.number(n));
4872
+ };
4873
+ const midSentence = (t) => /^[A-Z][a-z]/.test(t) && !/^zh/i.test(format.locale()) ? t[0].toLowerCase() + t.slice(1) : t;
4874
+ const sameLabel = /* @__PURE__ */ new Map();
4875
+ for (const e of edges) if (e.inferred && e.label && pos[e.from] && pos[e.to]) sameLabel.set(e.label, (sameLabel.get(e.label) ?? 0) + 1);
4876
+ const inferredText = (e) => e.label && (sameLabel.get(e.label) ?? 0) > 1 ? tr("來自 {from},{label}", {
4877
+ from: nameOf(e.from),
4878
+ label: midSentence(e.label)
4879
+ }) : e.label || p.inferredLabel || tr("推測");
4880
+ const markText = (e) => e.inferred ? inferredText(e) : countText(e);
4576
4881
  if (upsL.length) {
4577
4882
  const left0 = Math.min(...main.map((n) => pos[n.id].x));
4578
4883
  const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
@@ -4594,14 +4899,188 @@ function LayerGraph(p) {
4594
4899
  if (next && sel != null) p.onSelect?.(null);
4595
4900
  pickEdge?.(next);
4596
4901
  };
4902
+ const LANE_H = 28;
4903
+ const txOf = (e) => Math.round(pos[e.to].x + NW * (ins[e.to].indexOf(e) + 1) / (ins[e.to].length + 1));
4904
+ const laneGroups = {};
4905
+ const laneCount = {};
4906
+ {
4907
+ const into = {};
4908
+ for (const e of edges) if (ins[e.to]?.includes(e) && (e.inferred || related(e))) (into[e.to] ??= []).push(e);
4909
+ for (const id in into) {
4910
+ if (into[id].length < 2) continue;
4911
+ laneGroups[id] = into[id].sort((a, b) => txOf(b) - txOf(a));
4912
+ laneCount[id] = into[id].length;
4913
+ }
4914
+ }
4597
4915
  const draw = () => {
4598
4916
  const paths = [];
4599
4917
  const labels = [];
4600
4918
  const need = /* @__PURE__ */ new Set();
4601
4919
  const crowd = /* @__PURE__ */ new Set();
4920
+ let covered = 0;
4921
+ const geomOf = (e) => {
4922
+ const a = pos[e.from];
4923
+ const b = pos[e.to];
4924
+ const oi = outs[e.from].indexOf(e);
4925
+ const on = outs[e.from].length;
4926
+ const sx = outX(a.x, oi, on);
4927
+ const sy = a.y + NH;
4928
+ const tx = txOf(e);
4929
+ const ty = b.y;
4930
+ const off = (oi - (on - 1) / 2) * 6;
4931
+ const skip = layerIndex[e.to] - layerIndex[e.from] > 1;
4932
+ const y1 = sy + gaps[layerIndex[e.from]] / 2 + off;
4933
+ let chx = sx;
4934
+ if (skip) {
4935
+ const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
4936
+ const mid = (sx + tx) / 2;
4937
+ 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)));
4938
+ chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
4939
+ }
4940
+ return {
4941
+ sx,
4942
+ sy,
4943
+ tx,
4944
+ ty,
4945
+ off,
4946
+ skip,
4947
+ y1,
4948
+ chx,
4949
+ from: skip ? chx : sx,
4950
+ startY: skip ? y1 : sy
4951
+ };
4952
+ };
4953
+ const lanes = /* @__PURE__ */ new Map();
4954
+ const outX = (x, i, n) => Math.round(n < 2 ? x + NW / 2 : x + 16 + (NW - 32) * i / (n - 1));
4955
+ const flatOf = (e) => {
4956
+ const a = pos[e.from];
4957
+ const b = pos[e.to];
4958
+ const oi = outs[e.from].indexOf(e);
4959
+ const on = outs[e.from].length;
4960
+ const sx = outX(a.x, oi, on);
4961
+ const j = flatRow[layerIndex[e.from]].indexOf(e);
4962
+ const ti = flatIn[e.to].indexOf(e);
4963
+ const tx = Math.round(b.x + NW - 24 - ti * 12);
4964
+ return {
4965
+ sx,
4966
+ sy: a.y + NH,
4967
+ y: a.y + NH + 14 + j * 10,
4968
+ tx,
4969
+ ty: b.y + NH
4970
+ };
4971
+ };
4972
+ const vertsOf = (e) => {
4973
+ if (isFlat(e)) {
4974
+ const f = flatOf(e);
4975
+ return [{
4976
+ x: f.sx,
4977
+ y0: f.sy,
4978
+ y1: f.y
4979
+ }, {
4980
+ x: f.tx,
4981
+ y0: f.ty,
4982
+ y1: f.y
4983
+ }];
4984
+ }
4985
+ if (isUp(e)) return [{
4986
+ x: laneX(e),
4987
+ y0: pos[e.to].y,
4988
+ y1: pos[e.from].y + NH
4989
+ }];
4990
+ const g = geomOf(e);
4991
+ if (!g.skip) return [{
4992
+ x: g.sx,
4993
+ y0: g.sy,
4994
+ y1: g.y1
4995
+ }, {
4996
+ x: g.tx,
4997
+ y0: g.y1,
4998
+ y1: g.ty
4999
+ }];
5000
+ const y2 = g.ty - gaps[layerIndex[e.to] - 1] / 2 + g.off;
5001
+ return [
5002
+ {
5003
+ x: g.sx,
5004
+ y0: g.sy,
5005
+ y1: g.y1
5006
+ },
5007
+ {
5008
+ x: g.chx,
5009
+ y0: g.y1,
5010
+ y1: y2
5011
+ },
5012
+ {
5013
+ x: g.tx,
5014
+ y0: y2,
5015
+ y1: g.ty
5016
+ }
5017
+ ];
5018
+ };
5019
+ for (const id in laneGroups) {
5020
+ const group = laneGroups[id].map((e) => ({
5021
+ e,
5022
+ g: geomOf(e),
5023
+ w: Math.ceil(labelWidth(markText(e)))
5024
+ }));
5025
+ const others = edges.filter((e) => !laneGroups[id].includes(e) && pos[e.from] && pos[e.to]).flatMap((e) => vertsOf(e).map((v) => ({
5026
+ k: -1,
5027
+ ...v
5028
+ })));
5029
+ const n = group.length;
5030
+ const laneY = (j) => group[0].g.ty - 8 - 16 - j * LANE_H;
5031
+ const perms = [];
5032
+ const permute = (rest, acc) => {
5033
+ if (!rest.length) perms.push(acc);
5034
+ else rest.forEach((x, k) => permute([...rest.slice(0, k), ...rest.slice(k + 1)], [...acc, x]));
5035
+ };
5036
+ if (n <= 6) permute([...group.keys()], []);
5037
+ else perms.push([...group.keys()]);
5038
+ let best = null;
5039
+ for (const perm of perms) {
5040
+ const ys = [];
5041
+ perm.forEach((k, j) => ys[k] = laneY(j));
5042
+ const verts = [...group.flatMap((q, k) => [{
5043
+ k,
5044
+ x: q.g.from,
5045
+ y0: q.g.startY,
5046
+ y1: ys[k]
5047
+ }, {
5048
+ k,
5049
+ x: q.g.tx,
5050
+ y0: ys[k],
5051
+ y1: q.g.ty - 8
5052
+ }]), ...others];
5053
+ 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));
5054
+ let fails = 0;
5055
+ const sides = [];
5056
+ group.forEach((q, k) => {
5057
+ const r0 = Math.max(q.g.from, q.g.tx) + 8;
5058
+ const l1 = Math.min(q.g.from, q.g.tx) - 8;
5059
+ if (free(k, r0, r0 + q.w)) sides[k] = "right";
5060
+ else if (free(k, l1 - q.w, l1)) sides[k] = "left";
5061
+ else {
5062
+ sides[k] = "right";
5063
+ fails++;
5064
+ }
5065
+ });
5066
+ if (!best || fails < best.fails) best = {
5067
+ fails,
5068
+ ys,
5069
+ sides
5070
+ };
5071
+ if (!fails) break;
5072
+ }
5073
+ if (best) group.forEach((q, k) => lanes.set(q.e, {
5074
+ y: best.ys[k],
5075
+ side: best.sides[k]
5076
+ }));
5077
+ }
4602
5078
  const marks = [];
5079
+ let wide = 0;
5080
+ let least = 0;
4603
5081
  const runs = [];
4604
5082
  const segs = [];
5083
+ const ptsOf = {};
4605
5084
  const arrows = [];
4606
5085
  const hitPaths = [];
4607
5086
  edges.forEach((e, idx) => {
@@ -4618,6 +5097,9 @@ function LayerGraph(p) {
4618
5097
  let ty;
4619
5098
  let arrow;
4620
5099
  let inn = 1;
5100
+ let laneAt = null;
5101
+ let turnFrom = 0;
5102
+ let laneSide = "right";
4621
5103
  if (up) {
4622
5104
  const lx = laneX(e);
4623
5105
  const L = onLeft(e);
@@ -4691,7 +5173,7 @@ function LayerGraph(p) {
4691
5173
  y0 + 3
4692
5174
  ]);
4693
5175
  if (e.inferred || r) {
4694
- const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
5176
+ const text = markText(e);
4695
5177
  marks.push({
4696
5178
  idx,
4697
5179
  e,
@@ -4704,28 +5186,59 @@ function LayerGraph(p) {
4704
5186
  up: true
4705
5187
  });
4706
5188
  }
5189
+ } else if (isFlat(e)) {
5190
+ const f = flatOf(e);
5191
+ tx = f.tx;
5192
+ ty = f.ty;
5193
+ pts = [
5194
+ [f.sx, f.sy],
5195
+ [f.sx, f.y],
5196
+ [f.tx, f.y],
5197
+ [f.tx, f.ty + 9]
5198
+ ];
5199
+ arrow = `M${tx - 5} ${ty + 9} L${tx + 5} ${ty + 9} L${tx} ${ty} Z`;
5200
+ arrows.push([
5201
+ tx - 5,
5202
+ tx + 5,
5203
+ ty,
5204
+ ty + 9
5205
+ ]);
5206
+ runs.push([
5207
+ Math.min(f.sx, f.tx),
5208
+ Math.max(f.sx, f.tx),
5209
+ f.y - 3,
5210
+ f.y + 3
5211
+ ]);
5212
+ if (e.inferred || r) {
5213
+ const text = markText(e);
5214
+ marks.push({
5215
+ idx,
5216
+ e,
5217
+ text,
5218
+ tx: Math.round((f.sx + f.tx) / 2),
5219
+ ty: f.y,
5220
+ left: false,
5221
+ r,
5222
+ dim,
5223
+ flat: true
5224
+ });
5225
+ }
4707
5226
  } 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
5227
  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;
5228
+ const g = geomOf(e);
5229
+ const { sx, sy, skip } = g;
5230
+ tx = g.tx;
5231
+ ty = g.ty;
5232
+ const lane = lanes.get(e);
5233
+ const laneY = lane ? lane.y : null;
5234
+ const y1 = !skip && laneY != null ? laneY : g.y1;
5235
+ if (skip) {
5236
+ const y2 = laneY ?? ty - gaps[layerIndex[e.to] - 1] / 2 + g.off;
4724
5237
  pts = [
4725
5238
  [sx, sy],
4726
5239
  [sx, y1],
4727
- [chx, y1],
4728
- [chx, y2],
5240
+ [g.chx, y1],
5241
+ [g.chx, y2],
4729
5242
  [tx, y2],
4730
5243
  [tx, ty - 8]
4731
5244
  ];
@@ -4735,6 +5248,9 @@ function LayerGraph(p) {
4735
5248
  [tx, y1],
4736
5249
  [tx, ty - 8]
4737
5250
  ];
5251
+ turnFrom = g.from;
5252
+ laneAt = laneY;
5253
+ laneSide = lane?.side ?? "right";
4738
5254
  arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
4739
5255
  arrows.push([
4740
5256
  tx - 5,
@@ -4745,6 +5261,7 @@ function LayerGraph(p) {
4745
5261
  }
4746
5262
  const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
4747
5263
  const cpts = clean(pts);
5264
+ ptsOf[idx] = cpts;
4748
5265
  for (let k = 1; k < cpts.length; k++) {
4749
5266
  const [ax, ay] = cpts[k - 1];
4750
5267
  const [bx, by] = cpts[k];
@@ -4764,13 +5281,23 @@ function LayerGraph(p) {
4764
5281
  d,
4765
5282
  strokeWidth: w
4766
5283
  }, "p" + idx));
5284
+ if (!pickEdge && peek) hitPaths.push(/* @__PURE__ */ jsx("path", {
5285
+ className: "ui-lg-hit is-peek",
5286
+ d,
5287
+ onPointerEnter: () => setHover(edgeId(e)),
5288
+ onPointerLeave: () => setHover(null)
5289
+ }, "h" + idx));
4767
5290
  if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
4768
5291
  className: "ui-lg-hit",
4769
5292
  "data-edge": edgeId(e),
4770
5293
  d,
4771
5294
  role: "button",
4772
5295
  tabIndex: 0,
4773
- "aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
5296
+ "aria-label": tr("{from} → {to},{what}", {
5297
+ from: nameOf(e.from),
5298
+ to: nameOf(e.to),
5299
+ what: markText(e).replace(/`/g, "")
5300
+ }),
4774
5301
  "aria-pressed": picked,
4775
5302
  onClick: (ev) => {
4776
5303
  ev.stopPropagation();
@@ -4778,6 +5305,8 @@ function LayerGraph(p) {
4778
5305
  },
4779
5306
  onPointerEnter: () => setHover(edgeId(e)),
4780
5307
  onPointerLeave: () => setHover(null),
5308
+ onFocus: peek ? () => setHover(edgeId(e)) : void 0,
5309
+ onBlur: peek ? () => setHover(null) : void 0,
4781
5310
  onKeyDown: (ev) => {
4782
5311
  if (ev.key === "Enter" || ev.key === " ") {
4783
5312
  ev.preventDefault();
@@ -4789,8 +5318,8 @@ function LayerGraph(p) {
4789
5318
  className: cx("ui-lg-arrow", r && "is-related", dim && "is-dim"),
4790
5319
  d: arrow
4791
5320
  }, "a" + idx));
4792
- if (!up && (e.inferred || r)) {
4793
- const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
5321
+ if (!up && !isFlat(e) && (e.inferred || r)) {
5322
+ const text = markText(e);
4794
5323
  marks.push({
4795
5324
  idx,
4796
5325
  e,
@@ -4799,22 +5328,61 @@ function LayerGraph(p) {
4799
5328
  ty,
4800
5329
  left: inn > 1 && tx < b.x + NW / 2,
4801
5330
  r,
4802
- dim
5331
+ dim,
5332
+ lane: laneAt,
5333
+ from: turnFrom,
5334
+ side: laneSide
4803
5335
  });
4804
5336
  }
4805
5337
  });
4806
5338
  const placed = [...arrows, ...runs];
4807
5339
  const boxRects = main.map((n) => [
4808
- pos[n.id].x,
4809
- pos[n.id].x + NW,
5340
+ boxOf(n.id).x,
5341
+ boxOf(n.id).x + boxOf(n.id).w,
4810
5342
  pos[n.id].y,
4811
5343
  pos[n.id].y + NH
4812
5344
  ]);
4813
5345
  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);
4814
5346
  const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
5347
+ const alongLine = (m) => {
5348
+ const pts = ptsOf[m.idx] ?? [];
5349
+ const ok = (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);
5350
+ for (const lines of wraps(m.text)) {
5351
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
5352
+ const lh = lines.length * 16;
5353
+ let best = null;
5354
+ for (let k = 1; k < pts.length; k++) {
5355
+ const [ax, ay] = pts[k - 1];
5356
+ const [bx, by] = pts[k];
5357
+ const len = Math.hypot(bx - ax, by - ay);
5358
+ for (let t = 0; t <= len; t += 6) {
5359
+ const x = ax + (bx - ax) * t / len;
5360
+ const y = ay + (by - ay) * t / len;
5361
+ const cands = ax === bx ? [[x + 8, y], [x - 8 - lw, y]] : [[x - lw / 2, y - 6 - lh / 2], [x - lw / 2, y + 6 + lh / 2]];
5362
+ for (const [x0, top] of cands) {
5363
+ const d = Math.hypot(x0 + lw / 2 - m.tx, top - m.ty);
5364
+ if (best && d >= best.d) continue;
5365
+ if (ok(x0, lw, top - lh / 2, top + lh / 2)) best = {
5366
+ x0,
5367
+ top,
5368
+ d
5369
+ };
5370
+ }
5371
+ }
5372
+ }
5373
+ if (best) return {
5374
+ x0: Math.round(best.x0),
5375
+ top: Math.round(best.top),
5376
+ lw,
5377
+ lh,
5378
+ lines
5379
+ };
5380
+ }
5381
+ return null;
5382
+ };
4815
5383
  const labelEl = (m, x0, top, lines = [m.text]) => /* @__PURE__ */ jsx("span", {
4816
5384
  "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"),
5385
+ 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
5386
  style: {
4819
5387
  left: x0,
4820
5388
  top
@@ -4829,6 +5397,34 @@ function LayerGraph(p) {
4829
5397
  }, "l" + m.idx);
4830
5398
  marks.sort((m, n) => Number(!!m.up) - Number(!!n.up) || m.ty - n.ty || m.tx - n.tx).forEach((m) => {
4831
5399
  const w = Math.ceil(labelWidth(m.text));
5400
+ if (m.flat) {
5401
+ let spot = alongLine(m);
5402
+ if (!spot) {
5403
+ const g = layerIndex[m.e.from];
5404
+ if (g < layers.length - 1) need.add(g);
5405
+ covered++;
5406
+ const x0 = Math.max(PAD / 2, Math.min(W - PAD / 2 - w, m.tx - w / 2));
5407
+ const taken = (t) => hits(x0, x0 + w, t - 10, t + 10) || boxRects.some((q) => x0 < q[1] + 2 && q[0] < x0 + w + 2 && t - 10 < q[3] && q[2] < t + 10);
5408
+ let top = m.ty + 14;
5409
+ for (let k = 0; k < 8 && taken(top); k++) top += 18;
5410
+ spot = {
5411
+ x0,
5412
+ top,
5413
+ lw: w,
5414
+ lh: 16,
5415
+ lines: [m.text]
5416
+ };
5417
+ }
5418
+ placed.push([
5419
+ spot.x0,
5420
+ spot.x0 + spot.lw,
5421
+ spot.top - spot.lh / 2 - 4,
5422
+ spot.top + spot.lh / 2 + 4,
5423
+ 6
5424
+ ]);
5425
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
5426
+ return;
5427
+ }
4832
5428
  if (m.up) {
4833
5429
  const x0Of = (lw) => Math.max(PAD / 2, Math.min(W - PAD / 2 - lw, m.left ? m.tx - lw : m.tx));
4834
5430
  const start0 = Math.max(10, Math.min(H - 10, m.ty));
@@ -4858,9 +5454,11 @@ function LayerGraph(p) {
4858
5454
  break;
4859
5455
  }
4860
5456
  }
5457
+ if (!spot) spot = alongLine(m);
4861
5458
  if (!spot) {
4862
5459
  const g = Math.max(0, Math.min(layers.length - 2, layers.findIndex((_, k) => k < layers.length - 1 && m.ty < rowTop(k + 1))));
4863
5460
  need.add(g);
5461
+ covered++;
4864
5462
  const x0 = x0Of(w);
4865
5463
  const top = find(x0, w, 16, false);
4866
5464
  if (top == null) crowd.add(g);
@@ -4896,7 +5494,24 @@ function LayerGraph(p) {
4896
5494
  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
5495
  };
4898
5496
  let spot = null;
4899
- for (const lines of wraps(m.text)) {
5497
+ if (m.lane != null) {
5498
+ const lane = m.lane;
5499
+ for (const lines of wraps(m.text)) {
5500
+ if (spot) break;
5501
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
5502
+ const lh = lines.length * 16;
5503
+ const right = Math.max(m.tx, m.from ?? m.tx) + 8;
5504
+ const left = Math.min(m.tx, m.from ?? m.tx) - 8 - lw;
5505
+ for (const x0 of m.side === "left" ? [left, right] : [right, left]) if (!spot && clear(x0, lw, lane - lh / 2, lane + lh / 2)) spot = {
5506
+ x0,
5507
+ top: lane,
5508
+ lw,
5509
+ lh,
5510
+ lines
5511
+ };
5512
+ }
5513
+ }
5514
+ for (const lines of spot ? [] : wraps(m.text)) {
4900
5515
  const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
4901
5516
  const lh = lines.length * 16;
4902
5517
  const pref = sideOf(lw);
@@ -4918,8 +5533,10 @@ function LayerGraph(p) {
4918
5533
  }
4919
5534
  if (spot) break;
4920
5535
  }
5536
+ if (!spot) spot = alongLine(m);
4921
5537
  if (!spot) {
4922
5538
  if (g >= 0) need.add(g);
5539
+ covered++;
4923
5540
  const offBoxes = (x0, lw, y0, y1) => !hits(x0, x0 + lw, y0, y1) && !boxRects.some((q) => x0 < q[1] + 2 && q[0] < x0 + lw + 2 && y0 < q[3] + 2 && q[2] < y1 + 2);
4924
5541
  for (const lines of wraps(m.text)) {
4925
5542
  const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
@@ -4960,10 +5577,12 @@ function LayerGraph(p) {
4960
5577
  placed.push([
4961
5578
  spot.x0,
4962
5579
  spot.x0 + spot.lw,
4963
- spot.top - spot.lh / 2,
4964
- spot.top + spot.lh / 2,
5580
+ spot.top - spot.lh / 2 - 2,
5581
+ spot.top + spot.lh / 2 + 2,
4965
5582
  6
4966
5583
  ]);
5584
+ wide = Math.max(wide, spot.x0 + spot.lw + PAD / 2 + 4);
5585
+ least = Math.min(least, spot.x0 - PAD / 2 - 4);
4967
5586
  labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
4968
5587
  });
4969
5588
  return {
@@ -4971,31 +5590,49 @@ function LayerGraph(p) {
4971
5590
  labels,
4972
5591
  hitPaths,
4973
5592
  need,
4974
- crowd
5593
+ crowd,
5594
+ wide,
5595
+ least,
5596
+ covered
4975
5597
  };
4976
5598
  };
5599
+ for (const id in laneCount) {
5600
+ const g = layerIndex[id] - 1;
5601
+ if (g >= 0) gaps[g] = Math.max(gaps[g], laneCount[id] * LANE_H + 40);
5602
+ }
5603
+ const floor = gaps.slice();
4977
5604
  placeRows();
4978
5605
  let drawn = draw();
4979
- const grows = () => [...drawn.need].filter((g) => gaps[g] < 200);
5606
+ const grows = () => [...drawn.need].filter((g) => gaps[g] < floor[g] + GROW_MAX);
4980
5607
  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);
5608
+ for (const g of grows()) gaps[g] = Math.min(floor[g] + GROW_MAX, gaps[g] + GROW);
4982
5609
  placeRows();
4983
5610
  drawn = draw();
4984
5611
  }
4985
- const stuck = [...drawn.need].filter((g) => gaps[g] >= 200);
5612
+ const stuck = [...drawn.need].filter((g) => gaps[g] >= floor[g] + GROW_MAX);
4986
5613
  if (stuck.length) {
4987
- for (const g of stuck) gaps[g] = GAP;
5614
+ for (const g of stuck) gaps[g] = floor[g];
4988
5615
  placeRows();
4989
5616
  drawn = draw();
4990
- const crowded = () => [...drawn.crowd].filter((g) => stuck.includes(g) && gaps[g] < 200);
5617
+ const crowded = () => [...drawn.crowd].filter((g) => stuck.includes(g) && gaps[g] < floor[g] + GROW_MAX);
4991
5618
  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);
5619
+ for (const g of crowded()) gaps[g] = Math.min(floor[g] + GROW_MAX, gaps[g] + GROW);
4993
5620
  placeRows();
4994
5621
  drawn = draw();
4995
5622
  }
4996
5623
  }
5624
+ for (let k = 0; k < 3 && drawn.least < 0; k++) {
5625
+ const shift = Math.ceil(-drawn.least);
5626
+ for (const id in pos) pos[id].x += shift;
5627
+ W += shift;
5628
+ drawn = draw();
5629
+ }
5630
+ if (drawn.wide > W) {
5631
+ W = Math.ceil(drawn.wide);
5632
+ drawn = draw();
5633
+ }
4997
5634
  const { paths, labels, hitPaths } = drawn;
4998
- const sizeText = p.sizeLabel ?? tr("{n} 個項目");
5635
+ const sizeText = (n) => withNum(p.sizeLabel, n, () => byCount(n, "1 個項目", "{n} 個項目"));
4999
5636
  const externalText = p.externalLabel ?? tr("repo 外");
5000
5637
  const useText = p.useLabel ?? tr("使用 {n} 次");
5001
5638
  const nodes = main.map((n) => {
@@ -5007,9 +5644,9 @@ function LayerGraph(p) {
5007
5644
  type: "button",
5008
5645
  className: cx("ui-lg-node", n.external && "is-external", on && "is-selected", !near(n.id) && "is-dim"),
5009
5646
  style: {
5010
- left: q.x,
5647
+ left: boxOf(n.id).x,
5011
5648
  top: q.y,
5012
- width: NW,
5649
+ width: boxOf(n.id).w,
5013
5650
  height: NH
5014
5651
  },
5015
5652
  "aria-pressed": p.onSelect ? on : void 0,
@@ -5037,7 +5674,7 @@ function LayerGraph(p) {
5037
5674
  children: /* @__PURE__ */ jsx("span", { style: { width: Math.round(size / maxSize * 100) + "%" } })
5038
5675
  }), /* @__PURE__ */ jsx("span", {
5039
5676
  className: "ui-lg-count",
5040
- children: monoNums(sizeText.replace("{n}", ""), [size])
5677
+ children: monoNums(sizeText(size), [format.number(size)])
5041
5678
  })]
5042
5679
  }) : null
5043
5680
  ]
@@ -5063,7 +5700,10 @@ function LayerGraph(p) {
5063
5700
  })]
5064
5701
  }, s.id);
5065
5702
  });
5066
- const edgeText = (e) => e.inferred ? e.label ? `${e.label}(${p.inferredLabel || tr("推測")})` : p.inferredLabel || tr("推測") : countText(e);
5703
+ const edgeText = (e) => e.inferred ? e.label ? tr("{label}({inferred})", {
5704
+ label: e.label,
5705
+ inferred: p.inferredLabel || tr("推測")
5706
+ }) : p.inferredLabel || tr("推測") : countText(e);
5067
5707
  const listItem = (key, on, dim, onClick, head, rest) => /* @__PURE__ */ jsxs("li", {
5068
5708
  className: cx("ui-lg-li", dim && "is-dim"),
5069
5709
  children: [onClick ? /* @__PURE__ */ jsx("button", {
@@ -5093,10 +5733,10 @@ function LayerGraph(p) {
5093
5733
  children: n.name || n.id
5094
5734
  }), n.external && !n.shared ? /* @__PURE__ */ jsxs("span", {
5095
5735
  className: "ui-lg-limeta",
5096
- children: [",", externalText]
5736
+ children: [tr(","), externalText]
5097
5737
  }) : size != null ? /* @__PURE__ */ jsxs("span", {
5098
5738
  className: "ui-lg-limeta",
5099
- children: [",", monoNums(sizeText.replace("{n}", ""), [size])]
5739
+ children: [tr(","), monoNums(sizeText(size), [format.number(size)])]
5100
5740
  }) : null);
5101
5741
  }) })]
5102
5742
  }), /* @__PURE__ */ jsxs("section", {
@@ -5114,20 +5754,78 @@ function LayerGraph(p) {
5114
5754
  /* @__PURE__ */ jsx("span", {
5115
5755
  className: "ui-lg-code",
5116
5756
  children: nameOf(e.to)
5757
+ }),
5758
+ /* @__PURE__ */ jsxs("span", {
5759
+ className: "ui-lg-limeta",
5760
+ children: [tr(":"), labelParts(edgeText(e))]
5117
5761
  })
5118
- ] }), /* @__PURE__ */ jsxs("span", {
5119
- className: "ui-lg-limeta",
5120
- children: [":", labelParts(edgeText(e))]
5121
- }))) })]
5762
+ ] }), null)) })]
5122
5763
  })]
5123
5764
  });
5124
5765
  const showList = p.listView !== false && view === "list";
5766
+ const toggleShown = p.labelToggle !== false && !showList && p.edges.some((e) => e.inferred);
5767
+ React.useLayoutEffect(() => {
5768
+ const el = scrollRef.current;
5769
+ if (!el) return;
5770
+ const measure = () => setAvail(el.clientWidth);
5771
+ measure();
5772
+ const ro = new ResizeObserver(measure);
5773
+ ro.observe(el);
5774
+ return () => ro.disconnect();
5775
+ }, [scrollRef, showList]);
5776
+ React.useLayoutEffect(() => {
5777
+ if (!avail || showList) return;
5778
+ if (!fitted) {
5779
+ if (W <= avail + .5) return;
5780
+ const base = p.nodeWidth || 200;
5781
+ const lose = W - avail - (cols - 1) * 16;
5782
+ const nw = Math.max(Math.min(base, 120), Math.floor(base - Math.max(0, lose) / cols));
5783
+ setFit({
5784
+ at: avail,
5785
+ nw,
5786
+ col: 24,
5787
+ scale: 1
5788
+ });
5789
+ return;
5790
+ }
5791
+ if (fitted.scale !== 1 || W <= avail + .5) return;
5792
+ const s = avail / W;
5793
+ if (s >= .75) setFit({
5794
+ ...fitted,
5795
+ scale: Math.floor(s * 1e3) / 1e3
5796
+ });
5797
+ }, [
5798
+ avail,
5799
+ showList,
5800
+ fitted,
5801
+ W,
5802
+ p.nodeWidth,
5803
+ cols
5804
+ ]);
5805
+ const coveredNow = drawn.covered;
5806
+ React.useLayoutEffect(() => {
5807
+ if (coveredNow && spread < 5) setSpread({
5808
+ key: spreadKey,
5809
+ n: spread + 1
5810
+ });
5811
+ }, [
5812
+ coveredNow,
5813
+ spread,
5814
+ spreadKey
5815
+ ]);
5125
5816
  return /* @__PURE__ */ jsxs("div", {
5126
5817
  className: cx("ui-graph ui-lg", p.className),
5127
5818
  children: [
5128
- p.listView === false ? null : /* @__PURE__ */ jsx("div", {
5819
+ p.listView === false && !toggleShown ? null : /* @__PURE__ */ jsxs("div", {
5129
5820
  className: "ui-lg-bar",
5130
- children: /* @__PURE__ */ jsx(Tabs, {
5821
+ children: [toggleShown ? /* @__PURE__ */ jsx(IconButton, {
5822
+ className: "ui-lg-labels-btn",
5823
+ icon: "tag",
5824
+ filled: labelsOn,
5825
+ label: tr("顯示線上文字"),
5826
+ "aria-pressed": labelsOn,
5827
+ onClick: switchLabels
5828
+ }) : null, p.listView === false ? null : /* @__PURE__ */ jsx(Tabs, {
5131
5829
  label: tr("顯示方式"),
5132
5830
  value: view,
5133
5831
  onChange: setView,
@@ -5138,7 +5836,7 @@ function LayerGraph(p) {
5138
5836
  id: "list",
5139
5837
  label: tr("清單")
5140
5838
  }]
5141
- })
5839
+ })]
5142
5840
  }),
5143
5841
  showList ? list : null,
5144
5842
  /* @__PURE__ */ jsx("div", {
@@ -5149,9 +5847,17 @@ function LayerGraph(p) {
5149
5847
  onScroll: onScrollKeep,
5150
5848
  children: /* @__PURE__ */ jsxs("div", {
5151
5849
  className: "ui-lg-canvas",
5152
- style: {
5850
+ style: scale === 1 ? {
5153
5851
  width: W,
5154
5852
  height: H
5853
+ } : {
5854
+ width: W,
5855
+ height: H,
5856
+ transform: `scale(${scale})`,
5857
+ transformOrigin: "0 0",
5858
+ marginRight: W * (scale - 1),
5859
+ marginBottom: H * (scale - 1),
5860
+ "--lg-scale": scale
5155
5861
  },
5156
5862
  role: "group",
5157
5863
  "aria-label": p.label || tr("架構圖"),
@@ -5166,7 +5872,14 @@ function LayerGraph(p) {
5166
5872
  }),
5167
5873
  nodes,
5168
5874
  labels,
5169
- hitPaths.length ? /* @__PURE__ */ jsx("svg", {
5875
+ hitPaths.length && !pickEdge ? /* @__PURE__ */ jsx("svg", {
5876
+ className: "ui-lg-hits",
5877
+ width: W,
5878
+ height: H,
5879
+ viewBox: `0 0 ${W} ${H}`,
5880
+ "aria-hidden": "true",
5881
+ children: hitPaths
5882
+ }) : hitPaths.length ? /* @__PURE__ */ jsx("svg", {
5170
5883
  className: "ui-lg-hits",
5171
5884
  width: W,
5172
5885
  height: H,
@@ -5218,6 +5931,10 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
5218
5931
  const Y = (v) => B - v / top * 200;
5219
5932
  const ticks = TICKS.map((f) => f * top);
5220
5933
  const suffix = unit ? " " + unit : "";
5934
+ const show = (j) => {
5935
+ setHi(j);
5936
+ announce(labels[j] + tr(":") + series.map((s) => (series.length > 1 ? s.name + " " : "") + format.number(s.values[j], decimals) + suffix).join(tr(",")));
5937
+ };
5221
5938
  const edge = {
5222
5939
  left: (L - step / 2) / 640 * 100 + "%",
5223
5940
  right: (10 - step / 2) / 640 * 100 + "%"
@@ -5234,13 +5951,22 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
5234
5951
  }) : null,
5235
5952
  /* @__PURE__ */ jsxs("div", {
5236
5953
  className: "ui-chart-plot",
5954
+ tabIndex: n ? 0 : void 0,
5955
+ role: "group",
5956
+ "aria-label": label,
5957
+ "aria-description": tr("左右方向鍵查看每一個時間點的數值"),
5237
5958
  onMouseLeave: () => setHi(-1),
5959
+ onFocus: () => hi < 0 && n && show(0),
5960
+ onBlur: () => setHi(-1),
5961
+ onKeyDown: (e) => {
5962
+ const to = chartKey(e, hi, n);
5963
+ if (to != null) show(to);
5964
+ },
5238
5965
  children: [
5239
5966
  /* @__PURE__ */ jsxs("svg", {
5240
5967
  viewBox: "0 0 640 240",
5241
5968
  width: "100%",
5242
- role: "img",
5243
- "aria-label": label,
5969
+ "aria-hidden": "true",
5244
5970
  children: [ticks.map((v, i) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
5245
5971
  x1: L,
5246
5972
  x2: R,
@@ -5599,10 +6325,13 @@ function NotificationBell({ items, onOpen, onReadAll, emptyText }) {
5599
6325
  type: "button",
5600
6326
  className: cx("ui-noti-item", !it.read && "is-unread"),
5601
6327
  onClick: () => onOpen?.(it),
5602
- children: [!it.read ? /* @__PURE__ */ jsx("span", {
6328
+ children: [!it.read ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
5603
6329
  className: "ui-noti-dot",
5604
- "aria-label": tr("未讀")
5605
- }) : null, /* @__PURE__ */ jsxs("span", {
6330
+ "aria-hidden": "true"
6331
+ }), /* @__PURE__ */ jsx("span", {
6332
+ className: "ui-visually-hidden",
6333
+ children: tr("未讀") + tr(",")
6334
+ })] }) : null, /* @__PURE__ */ jsxs("span", {
5606
6335
  className: "ui-noti-text",
5607
6336
  children: [
5608
6337
  /* @__PURE__ */ jsx("span", {
@@ -6127,6 +6856,7 @@ function Switch({ checked, onChange, label, disabled, className }) {
6127
6856
  onPointerDown: () => setPressing(true),
6128
6857
  onPointerUp: () => setPressing(false),
6129
6858
  onPointerLeave: () => setPressing(false),
6859
+ onPointerCancel: () => setPressing(false),
6130
6860
  children: /* @__PURE__ */ jsx("span", {
6131
6861
  className: "ui-switch-thumb",
6132
6862
  style: {
@@ -6199,7 +6929,10 @@ function TextArea({ label, hint, value, onChange, maxLength = 200, className, id
6199
6929
  className: "ui-count",
6200
6930
  children: [/* @__PURE__ */ jsx("span", {
6201
6931
  "aria-hidden": "true",
6202
- children: format.fraction((value || "").length, maxLength)
6932
+ children: /* @__PURE__ */ jsx("span", {
6933
+ className: "ui-seen",
6934
+ "data-text": format.fraction((value || "").length, maxLength)
6935
+ })
6203
6936
  }), /* @__PURE__ */ jsx("span", {
6204
6937
  className: "ui-visually-hidden",
6205
6938
  children: format.fractionLabel((value || "").length, maxLength, tr("字"))
@@ -6305,9 +7038,10 @@ function bounds(target) {
6305
7038
  bottom
6306
7039
  };
6307
7040
  }
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) {
7041
+ /** Where the card goes for a highlighted box: the preferred side, the other one, then right or left of the box; inside
7042
+ * the box at the bottom only when none has room (the tour scrolls first to make room above or below, see makeRoom).
7043
+ * Returns the anchor line the card is placed against. */
7044
+ function placeCard(rect, cardH, prefer, area, cardW = 320) {
6311
7045
  const margin = typeof document === "undefined" ? 12 : edge();
6312
7046
  const vh = area?.bottom ?? (typeof window === "undefined" ? 0 : window.innerHeight);
6313
7047
  const vt = area?.top ?? 0;
@@ -6333,6 +7067,16 @@ function placeCard(rect, cardH, prefer, area) {
6333
7067
  margin,
6334
7068
  line: rect
6335
7069
  };
7070
+ const vw = typeof window === "undefined" ? 0 : window.innerWidth;
7071
+ const tallOk = cardH + 2 * margin <= vh - vt;
7072
+ const beside = ["right", "left"].find((sd) => tallOk && (sd === "right" ? rect.left + rect.width + GAP + cardW + margin <= vw : rect.left - GAP - cardW - margin >= 0));
7073
+ if (beside) return {
7074
+ mode: beside,
7075
+ side: beside,
7076
+ offset: GAP,
7077
+ margin,
7078
+ line: rect
7079
+ };
6336
7080
  const end = rect.top + rect.height;
6337
7081
  const bottom = Math.max(vt + margin + cardH, end >= vh - margin ? vh - margin : end - margin);
6338
7082
  return {
@@ -6356,6 +7100,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6356
7100
  const [rect, setRect] = React.useState(null);
6357
7101
  const next = React.useRef(null);
6358
7102
  const [cardH, setCardH] = React.useState(0);
7103
+ const [cardW, setCardW] = React.useState(320);
6359
7104
  const [wasOpen, setWasOpen] = React.useState(open);
6360
7105
  if (open !== wasOpen) {
6361
7106
  setWasOpen(open);
@@ -6367,6 +7112,23 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6367
7112
  };
6368
7113
  const end = (why) => onClose?.(why);
6369
7114
  useReturnFocus(open);
7115
+ const shownStep = React.useRef(-1);
7116
+ React.useEffect(() => {
7117
+ if (!open || !step) {
7118
+ shownStep.current = -1;
7119
+ return;
7120
+ }
7121
+ if (shownStep.current !== -1 && shownStep.current !== i) announce(tr("第 {a} 步,共 {b} 步", {
7122
+ a: i + 1,
7123
+ b: steps.length
7124
+ }) + tr("。") + step.title + tr("。") + step.text.replace(/`/g, ""));
7125
+ shownStep.current = i;
7126
+ }, [
7127
+ open,
7128
+ i,
7129
+ step,
7130
+ steps.length
7131
+ ]);
6370
7132
  const cardEl = React.useRef(null);
6371
7133
  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
7134
  const onTab = (e) => {
@@ -6394,6 +7156,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6394
7156
  if (!open || !hasStep) return;
6395
7157
  let el = findTarget(target);
6396
7158
  const tall = (el?.getBoundingClientRect().height ?? 0) > window.innerHeight;
7159
+ devWarn(el && el.getBoundingClientRect().height > window.innerHeight * .7, "Tour", `第 ${i + 1} 步的目標「${target}」比視窗的 70% 高,說明卡只能蓋住它的一部分。請把 data-tour 放在較小的元素上,例如要說明的那張卡片或那一列,而不是整頁。`);
6397
7160
  if (el instanceof HTMLElement && narrowNow()) {
6398
7161
  const keep = el.style.scrollMarginTop;
6399
7162
  el.style.scrollMarginTop = bounds(el).top + edge() + pad + "px";
@@ -6444,13 +7207,48 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6444
7207
  observer.current?.disconnect();
6445
7208
  observer.current = null;
6446
7209
  if (!el) return;
6447
- const measure = () => setCardH(el.offsetHeight);
7210
+ const measure = () => {
7211
+ setCardH(el.offsetHeight);
7212
+ setCardW(el.offsetWidth);
7213
+ };
6448
7214
  measure();
6449
7215
  observer.current = new ResizeObserver(measure);
6450
7216
  observer.current.observe(el);
6451
7217
  }, []);
7218
+ const measured = cardH > 0;
7219
+ React.useEffect(() => {
7220
+ if (!open || !hasStep || !measured) return;
7221
+ const el = findTarget(target);
7222
+ if (!(el instanceof HTMLElement)) return;
7223
+ const ar = bounds(el);
7224
+ const m = edge();
7225
+ const r = el.getBoundingClientRect();
7226
+ const top = r.top - pad;
7227
+ const bottom = r.bottom + pad;
7228
+ if (bottom + GAP + cardH + m <= ar.bottom || top - GAP - cardH - m >= ar.top) return;
7229
+ const want = bottom - top + GAP + cardH + 2 * m <= ar.bottom - ar.top ? ar.top + m + pad : ar.top + m + cardH + GAP + pad;
7230
+ let box = el.parentElement;
7231
+ while (box && !(/(auto|scroll)/.test(getComputedStyle(box).overflowY) && box.scrollHeight > box.clientHeight)) box = box.parentElement;
7232
+ const dy = r.top - want;
7233
+ if (box) box.scrollBy({
7234
+ top: dy,
7235
+ behavior: "auto"
7236
+ });
7237
+ else window.scrollBy({
7238
+ top: dy,
7239
+ behavior: "auto"
7240
+ });
7241
+ }, [
7242
+ open,
7243
+ hasStep,
7244
+ i,
7245
+ target,
7246
+ pad,
7247
+ measured,
7248
+ cardH
7249
+ ]);
6452
7250
  const area = open && step ? bounds(findTarget(step.target)) : void 0;
6453
- const place = placeCard(rect, cardH, step?.side ?? "bottom", area);
7251
+ const place = placeCard(rect, cardH, step?.side ?? "bottom", area, cardW);
6454
7252
  const line = place.line;
6455
7253
  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
7254
  line?.left,
@@ -6498,10 +7296,10 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6498
7296
  className: "ui-tour-count",
6499
7297
  children: [/* @__PURE__ */ jsx("span", {
6500
7298
  "aria-hidden": "true",
6501
- children: monoNums(tr("{n} / {total}", {
7299
+ children: seenOnly(tr("{n} / {total}", {
6502
7300
  n: "",
6503
7301
  total: ""
6504
- }), [i + 1, steps.length])
7302
+ }), [String(i + 1), String(steps.length)])
6505
7303
  }), /* @__PURE__ */ jsx("span", {
6506
7304
  className: "ui-visually-hidden",
6507
7305
  children: tr("第 {a} 步,共 {b} 步", {
@@ -6847,7 +7645,7 @@ function TreeList(p) {
6847
7645
  "aria-posinset": r.pos,
6848
7646
  "aria-setsize": r.size,
6849
7647
  "aria-expanded": r.isF ? r.open : void 0,
6850
- "aria-owns": r.isF && r.open ? `${uid}-g-${r.n.id}` : void 0,
7648
+ "aria-owns": r.isF && r.open ? `${uid}-g-${idPart(r.n.id)}` : void 0,
6851
7649
  style: vars({ "--d": r.depth }),
6852
7650
  onFocus: () => focusId !== r.n.id && setFocusId(r.n.id)
6853
7651
  });
@@ -6862,7 +7660,7 @@ function TreeList(p) {
6862
7660
  ...(n.tags ?? []).map(nodeText),
6863
7661
  n.meta,
6864
7662
  n.path
6865
- ].filter(Boolean).join(","),
7663
+ ].filter(Boolean).join(tr(",")),
6866
7664
  "aria-selected": p.onSelect ? on : void 0,
6867
7665
  className: cx("ui-tree-row", "is-plain", on && "is-current", n.muted && "is-muted", r.fresh && "ui-tree-in"),
6868
7666
  onClick: () => {
@@ -6948,8 +7746,8 @@ function TreeList(p) {
6948
7746
  role: "alert",
6949
7747
  children: [
6950
7748
  tr("無法載入 {name} 的子項目", { name: r.n.name }),
6951
- r.error ? ":" + r.error : "",
6952
- "。"
7749
+ r.error ? tr(":") + r.error : "",
7750
+ tr("。").trim()
6953
7751
  ]
6954
7752
  }), /* @__PURE__ */ jsx("button", {
6955
7753
  type: "button",
@@ -7156,7 +7954,7 @@ function TreeList(p) {
7156
7954
  if (!r.x && r.open && i < every.length && every[i].depth > depth) {
7157
7955
  const [kidsOut, next] = nest(i, depth + 1);
7158
7956
  out.push(/* @__PURE__ */ jsx("div", {
7159
- id: `${uid}-g-${r.n.id}`,
7957
+ id: `${uid}-g-${idPart(r.n.id)}`,
7160
7958
  role: "group",
7161
7959
  className: "ui-tree-group",
7162
7960
  children: kidsOut