@seanyeh77/ui 0.10.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-BoMMgOww.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";
@@ -239,23 +239,31 @@ const PH_ALIAS = {
239
239
  "message-square": "chat-centered"
240
240
  };
241
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);
242
245
  /** Joins the truthy class names. */
243
246
  function cx(...names) {
244
247
  return names.filter(Boolean).join(" ");
245
248
  }
246
- function monoNums(text, nums) {
247
- 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, [
248
257
  "",
249
258
  "",
250
259
  ""
251
- ];
252
- return text.split(/(\u0001|\u0002|\u0003)/).map((t, i) => {
253
- const k = marks.indexOf(t);
254
- return k >= 0 ? /* @__PURE__ */ jsx("span", {
255
- className: "ui-num",
256
- children: nums[k]
257
- }, i) : t;
258
- });
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);
259
267
  }
260
268
  /** localStorage get (no value) or set; null when storage is blocked. */
261
269
  function store(key, value) {
@@ -1026,6 +1034,7 @@ function AppShell({ nav, value, onNavigate, brand, title, breadcrumb, onSearch,
1026
1034
  icon: "dots-three"
1027
1035
  });
1028
1036
  const [moreOpen, setMoreOpen] = React.useState(false);
1037
+ if (moreOpen && !phone && !tablet) setMoreOpen(false);
1029
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.");
1030
1039
  const current = parentOf(value)?.id ?? value;
1031
1040
  const tabValue = tabs.some((t) => t.id === current) ? current : MORE;
@@ -1355,7 +1364,7 @@ function useFocusRescue(ref, fallback) {
1355
1364
  const onIn = (e) => {
1356
1365
  if (!(e.target instanceof HTMLElement)) return;
1357
1366
  last = e.target;
1358
- index = Array.from(box.querySelectorAll(FOCUSABLE)).indexOf(last);
1367
+ index = list().indexOf(last);
1359
1368
  };
1360
1369
  const rescue = () => {
1361
1370
  const now = list();
@@ -1443,7 +1452,7 @@ function Menu({ items, label, icon = "dots-three", align = "end", triggerClassNa
1443
1452
  }) })] }), danger.length ? /* @__PURE__ */ jsx(Dialog, {
1444
1453
  open: !!asking,
1445
1454
  onClose: () => setAsking(null),
1446
- title: asking ? asking.confirm?.title ?? asking.label + "?" : "",
1455
+ title: asking ? asking.confirm?.title ?? tr("{label}?", { label: asking.label }) : "",
1447
1456
  tone: "danger",
1448
1457
  confirmLabel: asking?.confirm?.confirmLabel ?? asking?.label ?? "",
1449
1458
  onConfirm: () => {
@@ -1718,19 +1727,39 @@ function niceMax(v) {
1718
1727
  const n = Math.ceil(v / e);
1719
1728
  return (n <= 2 ? 2 : n <= 4 ? 4 : n <= 5 ? 5 : n <= 8 ? 8 : 10) * e;
1720
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
+ }
1721
1738
  // src/components/BarChart/BarChart.tsx
1722
1739
  /** Compares a few categories: rounded bars that grow in, a tooltip on hover. */
1723
1740
  function BarChart({ data, label, unit, decimals, max, className }) {
1724
1741
  const [hi, setHi] = React.useState(-1);
1725
1742
  const top = max || niceMax(Math.max(1, ...data.map((d) => d.value)));
1726
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
+ };
1727
1748
  return /* @__PURE__ */ jsxs("div", {
1728
1749
  className: cx("ui-chart", className),
1729
1750
  children: [/* @__PURE__ */ jsxs("div", {
1730
1751
  className: "ui-bars",
1731
1752
  role: "img",
1732
1753
  "aria-label": label,
1754
+ "aria-description": tr("左右方向鍵查看每一項的數值"),
1755
+ tabIndex: data.length ? 0 : void 0,
1733
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
+ },
1734
1763
  children: [TICKS.map((f, i) => /* @__PURE__ */ jsx("div", {
1735
1764
  className: cx("ui-bars-grid", !i && "is-axis"),
1736
1765
  style: { bottom: f * 100 + "%" },
@@ -1783,6 +1812,44 @@ function Calendar({ focus, onPick, onHover, dayState }) {
1783
1812
  const today = /* @__PURE__ */ new Date();
1784
1813
  const y = month.getFullYear();
1785
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
+ };
1786
1853
  const start = (new Date(y, m, 1).getDay() - format.firstDay() + 7) % 7;
1787
1854
  const days = new Date(y, m + 1, 0).getDate();
1788
1855
  const cells = [...Array(start).fill(null), ...Array.from({ length: days }, (_, i) => new Date(y, m, i + 1))];
@@ -1818,9 +1885,11 @@ function Calendar({ focus, onPick, onHover, dayState }) {
1818
1885
  })
1819
1886
  ]
1820
1887
  }), /* @__PURE__ */ jsxs("div", {
1888
+ ref: grid,
1821
1889
  className: "ui-cal-grid",
1822
1890
  role: "group",
1823
1891
  "aria-label": format.month(month),
1892
+ onKeyDown: onKey,
1824
1893
  children: [format.weekdays().map((w, i) => /* @__PURE__ */ jsx("span", {
1825
1894
  className: "ui-cal-wk",
1826
1895
  "aria-hidden": "true",
@@ -1838,6 +1907,8 @@ function Calendar({ focus, onPick, onHover, dayState }) {
1838
1907
  weekday: false,
1839
1908
  long: true
1840
1909
  }) + (isToday ? tr("(今天)") : ""),
1910
+ tabIndex: sameDay(c, cur) ? 0 : -1,
1911
+ onFocus: () => !sameDay(c, cur) && setActive(c),
1841
1912
  onClick: () => onPick?.(c),
1842
1913
  onMouseEnter: onHover ? () => onHover(c) : void 0,
1843
1914
  children: c.getDate()
@@ -2052,6 +2123,38 @@ const tokenize = (lines, lang) => {
2052
2123
  const OPS = /(->|::|==|!=|<=|>=|&&|\|\||\+\+|--|<<|>>|=>|\+=|-=|\*=|\/=)/;
2053
2124
  const AFTER = /([,.([{;])/;
2054
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
+ }
2055
2158
  function breakable(text) {
2056
2159
  if (!OPS.test(text) && !AFTER.test(text)) return text;
2057
2160
  const out = [];
@@ -2073,7 +2176,7 @@ function breakable(text) {
2073
2176
  return out;
2074
2177
  }
2075
2178
  /** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
2076
- 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 }) {
2077
2180
  const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
2078
2181
  const lang = language || languageOf(file);
2079
2182
  const toks = React.useMemo(() => highlight ? tokenizer(lines, lang) : lines.map((l) => [["", l]]), [
@@ -2128,10 +2231,10 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2128
2231
  className: "ui-cv-text",
2129
2232
  children: [/* @__PURE__ */ jsx("span", {
2130
2233
  className: "ui-visually-hidden ui-cv-sr",
2131
- children: tr("第 {n} 行", { n }) + ":"
2234
+ children: tr("第 {n} 行", { n }) + tr(":")
2132
2235
  }), toks[i].map(([cls, text], j) => cls ? /* @__PURE__ */ jsx("span", {
2133
2236
  className: cls,
2134
- children: breakable(text)
2237
+ children: (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef) : breakable(text)
2135
2238
  }, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))]
2136
2239
  })]
2137
2240
  }, i));
@@ -2151,9 +2254,9 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2151
2254
  children: title
2152
2255
  }), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsxs("span", {
2153
2256
  className: "ui-cv-lang",
2154
- children: [/* @__PURE__ */ jsxs("span", {
2257
+ children: [/* @__PURE__ */ jsx("span", {
2155
2258
  className: "ui-visually-hidden",
2156
- children: [tr("程式語言"), ":"]
2259
+ children: tr("程式語言") + tr(":")
2157
2260
  }), tr(languageLabel || LANGUAGE_NAMES[lang] || lang)]
2158
2261
  }) : null]
2159
2262
  }) : null;
@@ -2406,7 +2509,7 @@ function DangerZone({ title, description, actionLabel, onAction, confirm, classN
2406
2509
  className: "ui-danger-row",
2407
2510
  children: [/* @__PURE__ */ jsx("p", { children: description }), /* @__PURE__ */ jsx(Button, {
2408
2511
  variant: "danger",
2409
- confirm: confirm ?? { title: `${label}?` },
2512
+ confirm: confirm ?? { title: tr("{label}?", { label }) },
2410
2513
  onClick: onAction,
2411
2514
  children: label
2412
2515
  })]
@@ -2907,12 +3010,9 @@ function FullText({ text, children }) {
2907
3010
  wrap: true,
2908
3011
  describe: false,
2909
3012
  disabled: touch || !text,
2910
- children: /* @__PURE__ */ jsxs("span", {
3013
+ children: /* @__PURE__ */ jsx("span", {
2911
3014
  className: "ui-dt-full",
2912
- children: [children, text ? /* @__PURE__ */ jsx("span", {
2913
- className: "ui-visually-hidden",
2914
- children: tr(",") + text
2915
- }) : null]
3015
+ children
2916
3016
  })
2917
3017
  });
2918
3018
  }
@@ -3034,6 +3134,7 @@ function DataTable(p) {
3034
3134
  const rootRef = React.useRef(null);
3035
3135
  const [sel, setSel] = React.useState({});
3036
3136
  const [sumVal, setSumVal] = React.useState("all");
3137
+ const [fit, setFit] = React.useState({});
3037
3138
  const [resetKey, setResetKey] = React.useState(p.resetKey);
3038
3139
  const resetting = resetKey !== p.resetKey;
3039
3140
  if (resetting) {
@@ -3049,6 +3150,7 @@ function DataTable(p) {
3049
3150
  });
3050
3151
  setToggled({});
3051
3152
  setOpened({});
3153
+ setFit({});
3052
3154
  }
3053
3155
  const valuesKey = JSON.stringify(values);
3054
3156
  React.useEffect(() => {
@@ -3244,17 +3346,54 @@ function DataTable(p) {
3244
3346
  const longCols = shownCols.filter((c) => c.long || c.fullText);
3245
3347
  const expander = longCols.length > 0 && !narrow;
3246
3348
  const EXP = 40;
3349
+ const minOf = (c) => Math.max(c.width || (c.numeric ? 96 : 120), fit[c.key] || 0);
3247
3350
  const template = [
3248
3351
  expander ? "40px" : null,
3249
3352
  selectable ? "46px" : null,
3250
- ...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)`),
3251
3354
  hasAct ? actW + "px" : null
3252
3355
  ].filter(Boolean).join(" ");
3253
- 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);
3254
3357
  const gridStyle = {
3255
3358
  gridTemplateColumns: template,
3256
3359
  minWidth: minW
3257
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]);
3258
3397
  const stickyStyle = (ci) => ci === 0 && sticky ? { left: (expander ? EXP : 0) + (selectable ? 46 : 0) } : void 0;
3259
3398
  const cellClass = (c, ci, ...more) => cx("ui-dt-cell", isNum(c) && "is-num", ci === 0 && sticky && "is-sticky", ...more);
3260
3399
  const head = selectable && selIds.length && p.bulkActions ? /* @__PURE__ */ jsxs("div", {
@@ -3468,7 +3607,7 @@ function DataTable(p) {
3468
3607
  className: "ui-dt-result",
3469
3608
  children: [/* @__PURE__ */ jsx("span", {
3470
3609
  "aria-hidden": "true",
3471
- children: monoNums(tr("{n} / {total} 筆", {
3610
+ children: seenOnly(tr("{n} / {total} 筆", {
3472
3611
  n: "",
3473
3612
  total: ""
3474
3613
  }), [format.number(list.length), format.number(baseCount)])
@@ -3507,7 +3646,7 @@ function DataTable(p) {
3507
3646
  const id = visIds[i];
3508
3647
  const on = !!sel[id];
3509
3648
  const open = expander && !!opened[id];
3510
- const detailId = `${uid}-d-${id}`;
3649
+ const detailId = `${uid}-d-${idPart(id)}`;
3511
3650
  const rowName = shownCols[0] ? String(cellText(shownCols[0], get(x.r, shownCols[0].key)) ?? "") : "";
3512
3651
  return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsxs("div", {
3513
3652
  "data-rid": id,
@@ -3515,6 +3654,7 @@ function DataTable(p) {
3515
3654
  rowEls.current[id] = el;
3516
3655
  },
3517
3656
  role: "row",
3657
+ "aria-labelledby": shownCols.length ? `${uid}-n-${start + i}` : void 0,
3518
3658
  className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && "has-exp"),
3519
3659
  style: gridStyle,
3520
3660
  onClick: expander ? (e) => {
@@ -3557,7 +3697,10 @@ function DataTable(p) {
3557
3697
  }) : null,
3558
3698
  shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3559
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,
3560
3702
  "data-label": c.label,
3703
+ "data-col": c.key,
3561
3704
  className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
3562
3705
  style: stickyStyle(ci),
3563
3706
  children: cell(x.r, c)
@@ -3683,9 +3826,12 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
3683
3826
  const [open, setOpen] = React.useState(false);
3684
3827
  const [typed, setTyped] = React.useState(null);
3685
3828
  const field = React.useRef(null);
3686
- 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;
3687
3832
  const commit = (d) => {
3688
3833
  setTyped(null);
3834
+ setLeft(false);
3689
3835
  onChange(d);
3690
3836
  setOpen(false);
3691
3837
  };
@@ -3705,6 +3851,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
3705
3851
  className: "ui-datefield-input",
3706
3852
  value: typed ?? fmtDate(value),
3707
3853
  placeholder: "YYYY/MM/DD",
3854
+ "aria-required": required || void 0,
3708
3855
  "aria-invalid": bad || void 0,
3709
3856
  onChange: (e) => {
3710
3857
  const t = e.target.value;
@@ -3713,7 +3860,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
3713
3860
  if (d) onChange(d);
3714
3861
  else if (t === "") onChange(null);
3715
3862
  },
3716
- onBlur: () => !bad && setTyped(null)
3863
+ onBlur: () => wrong ? setLeft(true) : setTyped(null)
3717
3864
  }), /* @__PURE__ */ jsxs(FloatingPanel, {
3718
3865
  open,
3719
3866
  onOpenChange: setOpen,
@@ -3758,6 +3905,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
3758
3905
  }
3759
3906
  // src/components/DateRangePicker/DateRangePicker.tsx
3760
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 });
3761
3909
  function DateRangePicker({ label, value, onChange, placeholder, className }) {
3762
3910
  const [open, setOpen] = React.useState(false);
3763
3911
  const [first, setFirst] = React.useState(null);
@@ -3795,13 +3943,13 @@ function DateRangePicker({ label, value, onChange, placeholder, className }) {
3795
3943
  className: cx("ui-datefield", "ui-rangefield", open && "is-open"),
3796
3944
  "aria-label": value[0] ? tr("{label}:{a} 到 {b}", {
3797
3945
  label: label || tr("期間"),
3798
- a: fmtDate(value[0]),
3799
- b: fmtDate(value[1])
3800
- }) : `${label || tr("期間")}:${placeholder || tr("選擇期間")}`,
3946
+ a: day(value[0]),
3947
+ b: day(value[1])
3948
+ }) : `${label || tr("期間")}${tr(":")}${placeholder || tr("選擇期間")}`,
3801
3949
  children: [/* @__PURE__ */ jsx(Icon, {
3802
3950
  name: "calendar-blank",
3803
3951
  size: 18
3804
- }), /* @__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("選擇期間") })]
3805
3953
  }),
3806
3954
  children: [/* @__PURE__ */ jsx("div", {
3807
3955
  className: "ui-quick",
@@ -4041,7 +4189,7 @@ function ErrorPage({ code, title, description, onBack, onHome, homeHref = "/", c
4041
4189
  }
4042
4190
  // src/components/ProgressBar/ProgressBar.tsx
4043
4191
  /** Progress of a task with a known end, with the percentage after the bar. */
4044
- function ProgressBar({ value, label, className }) {
4192
+ function ProgressBar({ value, label, className, ...aria }) {
4045
4193
  const v = Math.max(0, Math.min(100, value || 0));
4046
4194
  const done = v >= 100;
4047
4195
  return /* @__PURE__ */ jsxs("div", {
@@ -4057,7 +4205,7 @@ function ProgressBar({ value, label, className }) {
4057
4205
  "aria-valuemin": 0,
4058
4206
  "aria-valuemax": 100,
4059
4207
  "aria-valuenow": Math.round(v),
4060
- "aria-label": label,
4208
+ "aria-label": label || aria["aria-label"],
4061
4209
  children: /* @__PURE__ */ jsx("div", {
4062
4210
  className: "ui-progress-fill",
4063
4211
  style: { width: v + "%" }
@@ -4149,7 +4297,10 @@ function FileUpload({ label, files = [], onAdd, onRemove, onRetry, limitText, ac
4149
4297
  className: "ui-upload-size",
4150
4298
  children: fl.size
4151
4299
  }) : null]
4152
- }), !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", {
4153
4304
  className: "ui-upload-error",
4154
4305
  role: "alert",
4155
4306
  children: [fl.error || tr("上傳失敗,請再試一次。"), onRetry ? /* @__PURE__ */ jsx("button", {
@@ -4455,6 +4606,20 @@ function KpiCard(props) {
4455
4606
  const scrollMemory = /* @__PURE__ */ new Map();
4456
4607
  let measure;
4457
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
+ }
4458
4623
  function labelWidth(text) {
4459
4624
  const parts = text.split(SPLIT).filter(Boolean);
4460
4625
  if (measure === void 0) measure = document.createElement("canvas").getContext("2d");
@@ -4559,7 +4724,13 @@ function LayerGraph(p) {
4559
4724
  const NW = fitted?.nw ?? (p.nodeWidth || 200);
4560
4725
  const NH = 60;
4561
4726
  const GAP = 56;
4562
- const COL = fitted?.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;
4563
4734
  const scale = fitted?.scale ?? 1;
4564
4735
  const PAD = 16;
4565
4736
  const all = p.nodes;
@@ -4596,13 +4767,25 @@ function LayerGraph(p) {
4596
4767
  });
4597
4768
  });
4598
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
+ };
4599
4779
  const placeRows = () => {
4600
4780
  for (const id in pos) pos[id].y = rowTop(layerIndex[id]);
4601
- H = rowTop(layers.length - 1) + NH + PAD;
4781
+ H = rowTop(layers.length - 1) + NH + PAD + (flatRow[layers.length - 1]?.length ? FLAT_ROOM : 0);
4602
4782
  };
4603
4783
  const maxSize = Math.max(1, ...main.map((n) => sizeOf(n) || 0));
4604
4784
  const maxCount = Math.max(1, ...edges.map((e) => e.count || 0));
4605
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 = {};
4606
4789
  const outs = {};
4607
4790
  const ins = {};
4608
4791
  const upOut = {};
@@ -4615,8 +4798,14 @@ function LayerGraph(p) {
4615
4798
  continue;
4616
4799
  }
4617
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
+ }
4618
4806
  (ins[e.to] ??= []).push(e);
4619
4807
  }
4808
+ const FLAT_ROOM = 20 + 10 * Math.max(0, (flatRow[layers.length - 1]?.length ?? 0) - 1);
4620
4809
  const ups = edges.filter(isUp);
4621
4810
  const rowOf = (id) => byLayer.get(layers[layerIndex[id]]) ?? [];
4622
4811
  const rightmost = (id) => rowOf(id)[rowOf(id).length - 1]?.id === id;
@@ -4677,8 +4866,18 @@ function LayerGraph(p) {
4677
4866
  p.onSelect?.(on ? null : id);
4678
4867
  };
4679
4868
  const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
4680
- const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
4681
- const markText = (e) => e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
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);
4682
4881
  if (upsL.length) {
4683
4882
  const left0 = Math.min(...main.map((n) => pos[n.id].x));
4684
4883
  const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
@@ -4718,12 +4917,13 @@ function LayerGraph(p) {
4718
4917
  const labels = [];
4719
4918
  const need = /* @__PURE__ */ new Set();
4720
4919
  const crowd = /* @__PURE__ */ new Set();
4920
+ let covered = 0;
4721
4921
  const geomOf = (e) => {
4722
4922
  const a = pos[e.from];
4723
4923
  const b = pos[e.to];
4724
4924
  const oi = outs[e.from].indexOf(e);
4725
4925
  const on = outs[e.from].length;
4726
- const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
4926
+ const sx = outX(a.x, oi, on);
4727
4927
  const sy = a.y + NH;
4728
4928
  const tx = txOf(e);
4729
4929
  const ty = b.y;
@@ -4751,12 +4951,81 @@ function LayerGraph(p) {
4751
4951
  };
4752
4952
  };
4753
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
+ };
4754
5019
  for (const id in laneGroups) {
4755
5020
  const group = laneGroups[id].map((e) => ({
4756
5021
  e,
4757
5022
  g: geomOf(e),
4758
5023
  w: Math.ceil(labelWidth(markText(e)))
4759
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
+ })));
4760
5029
  const n = group.length;
4761
5030
  const laneY = (j) => group[0].g.ty - 8 - 16 - j * LANE_H;
4762
5031
  const perms = [];
@@ -4770,7 +5039,7 @@ function LayerGraph(p) {
4770
5039
  for (const perm of perms) {
4771
5040
  const ys = [];
4772
5041
  perm.forEach((k, j) => ys[k] = laneY(j));
4773
- const verts = group.flatMap((q, k) => [{
5042
+ const verts = [...group.flatMap((q, k) => [{
4774
5043
  k,
4775
5044
  x: q.g.from,
4776
5045
  y0: q.g.startY,
@@ -4780,7 +5049,7 @@ function LayerGraph(p) {
4780
5049
  x: q.g.tx,
4781
5050
  y0: ys[k],
4782
5051
  y1: q.g.ty - 8
4783
- }]);
5052
+ }]), ...others];
4784
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));
4785
5054
  let fails = 0;
4786
5055
  const sides = [];
@@ -4811,6 +5080,7 @@ function LayerGraph(p) {
4811
5080
  let least = 0;
4812
5081
  const runs = [];
4813
5082
  const segs = [];
5083
+ const ptsOf = {};
4814
5084
  const arrows = [];
4815
5085
  const hitPaths = [];
4816
5086
  edges.forEach((e, idx) => {
@@ -4903,7 +5173,7 @@ function LayerGraph(p) {
4903
5173
  y0 + 3
4904
5174
  ]);
4905
5175
  if (e.inferred || r) {
4906
- const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
5176
+ const text = markText(e);
4907
5177
  marks.push({
4908
5178
  idx,
4909
5179
  e,
@@ -4916,6 +5186,43 @@ function LayerGraph(p) {
4916
5186
  up: true
4917
5187
  });
4918
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
+ }
4919
5226
  } else {
4920
5227
  inn = ins[e.to].length;
4921
5228
  const g = geomOf(e);
@@ -4954,6 +5261,7 @@ function LayerGraph(p) {
4954
5261
  }
4955
5262
  const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
4956
5263
  const cpts = clean(pts);
5264
+ ptsOf[idx] = cpts;
4957
5265
  for (let k = 1; k < cpts.length; k++) {
4958
5266
  const [ax, ay] = cpts[k - 1];
4959
5267
  const [bx, by] = cpts[k];
@@ -4988,7 +5296,7 @@ function LayerGraph(p) {
4988
5296
  "aria-label": tr("{from} → {to},{what}", {
4989
5297
  from: nameOf(e.from),
4990
5298
  to: nameOf(e.to),
4991
- what: (e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")
5299
+ what: markText(e).replace(/`/g, "")
4992
5300
  }),
4993
5301
  "aria-pressed": picked,
4994
5302
  onClick: (ev) => {
@@ -5010,8 +5318,8 @@ function LayerGraph(p) {
5010
5318
  className: cx("ui-lg-arrow", r && "is-related", dim && "is-dim"),
5011
5319
  d: arrow
5012
5320
  }, "a" + idx));
5013
- if (!up && (e.inferred || r)) {
5014
- const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
5321
+ if (!up && !isFlat(e) && (e.inferred || r)) {
5322
+ const text = markText(e);
5015
5323
  marks.push({
5016
5324
  idx,
5017
5325
  e,
@@ -5029,13 +5337,49 @@ function LayerGraph(p) {
5029
5337
  });
5030
5338
  const placed = [...arrows, ...runs];
5031
5339
  const boxRects = main.map((n) => [
5032
- pos[n.id].x,
5033
- pos[n.id].x + NW,
5340
+ boxOf(n.id).x,
5341
+ boxOf(n.id).x + boxOf(n.id).w,
5034
5342
  pos[n.id].y,
5035
5343
  pos[n.id].y + NH
5036
5344
  ]);
5037
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);
5038
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
+ };
5039
5383
  const labelEl = (m, x0, top, lines = [m.text]) => /* @__PURE__ */ jsx("span", {
5040
5384
  "aria-hidden": pickEdge ? true : void 0,
5041
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"),
@@ -5053,6 +5397,34 @@ function LayerGraph(p) {
5053
5397
  }, "l" + m.idx);
5054
5398
  marks.sort((m, n) => Number(!!m.up) - Number(!!n.up) || m.ty - n.ty || m.tx - n.tx).forEach((m) => {
5055
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
+ }
5056
5428
  if (m.up) {
5057
5429
  const x0Of = (lw) => Math.max(PAD / 2, Math.min(W - PAD / 2 - lw, m.left ? m.tx - lw : m.tx));
5058
5430
  const start0 = Math.max(10, Math.min(H - 10, m.ty));
@@ -5082,9 +5454,11 @@ function LayerGraph(p) {
5082
5454
  break;
5083
5455
  }
5084
5456
  }
5457
+ if (!spot) spot = alongLine(m);
5085
5458
  if (!spot) {
5086
5459
  const g = Math.max(0, Math.min(layers.length - 2, layers.findIndex((_, k) => k < layers.length - 1 && m.ty < rowTop(k + 1))));
5087
5460
  need.add(g);
5461
+ covered++;
5088
5462
  const x0 = x0Of(w);
5089
5463
  const top = find(x0, w, 16, false);
5090
5464
  if (top == null) crowd.add(g);
@@ -5159,8 +5533,10 @@ function LayerGraph(p) {
5159
5533
  }
5160
5534
  if (spot) break;
5161
5535
  }
5536
+ if (!spot) spot = alongLine(m);
5162
5537
  if (!spot) {
5163
5538
  if (g >= 0) need.add(g);
5539
+ covered++;
5164
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);
5165
5541
  for (const lines of wraps(m.text)) {
5166
5542
  const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
@@ -5201,8 +5577,8 @@ function LayerGraph(p) {
5201
5577
  placed.push([
5202
5578
  spot.x0,
5203
5579
  spot.x0 + spot.lw,
5204
- spot.top - spot.lh / 2,
5205
- spot.top + spot.lh / 2,
5580
+ spot.top - spot.lh / 2 - 2,
5581
+ spot.top + spot.lh / 2 + 2,
5206
5582
  6
5207
5583
  ]);
5208
5584
  wide = Math.max(wide, spot.x0 + spot.lw + PAD / 2 + 4);
@@ -5216,7 +5592,8 @@ function LayerGraph(p) {
5216
5592
  need,
5217
5593
  crowd,
5218
5594
  wide,
5219
- least
5595
+ least,
5596
+ covered
5220
5597
  };
5221
5598
  };
5222
5599
  for (const id in laneCount) {
@@ -5255,7 +5632,7 @@ function LayerGraph(p) {
5255
5632
  drawn = draw();
5256
5633
  }
5257
5634
  const { paths, labels, hitPaths } = drawn;
5258
- const sizeText = p.sizeLabel ?? tr("{n} 個項目");
5635
+ const sizeText = (n) => withNum(p.sizeLabel, n, () => byCount(n, "1 個項目", "{n} 個項目"));
5259
5636
  const externalText = p.externalLabel ?? tr("repo 外");
5260
5637
  const useText = p.useLabel ?? tr("使用 {n} 次");
5261
5638
  const nodes = main.map((n) => {
@@ -5267,9 +5644,9 @@ function LayerGraph(p) {
5267
5644
  type: "button",
5268
5645
  className: cx("ui-lg-node", n.external && "is-external", on && "is-selected", !near(n.id) && "is-dim"),
5269
5646
  style: {
5270
- left: q.x,
5647
+ left: boxOf(n.id).x,
5271
5648
  top: q.y,
5272
- width: NW,
5649
+ width: boxOf(n.id).w,
5273
5650
  height: NH
5274
5651
  },
5275
5652
  "aria-pressed": p.onSelect ? on : void 0,
@@ -5297,7 +5674,7 @@ function LayerGraph(p) {
5297
5674
  children: /* @__PURE__ */ jsx("span", { style: { width: Math.round(size / maxSize * 100) + "%" } })
5298
5675
  }), /* @__PURE__ */ jsx("span", {
5299
5676
  className: "ui-lg-count",
5300
- children: monoNums(sizeText.replace("{n}", ""), [size])
5677
+ children: monoNums(sizeText(size), [format.number(size)])
5301
5678
  })]
5302
5679
  }) : null
5303
5680
  ]
@@ -5359,7 +5736,7 @@ function LayerGraph(p) {
5359
5736
  children: [tr(","), externalText]
5360
5737
  }) : size != null ? /* @__PURE__ */ jsxs("span", {
5361
5738
  className: "ui-lg-limeta",
5362
- children: [tr(","), monoNums(sizeText.replace("{n}", ""), [size])]
5739
+ children: [tr(","), monoNums(sizeText(size), [format.number(size)])]
5363
5740
  }) : null);
5364
5741
  }) })]
5365
5742
  }), /* @__PURE__ */ jsxs("section", {
@@ -5377,11 +5754,12 @@ function LayerGraph(p) {
5377
5754
  /* @__PURE__ */ jsx("span", {
5378
5755
  className: "ui-lg-code",
5379
5756
  children: nameOf(e.to)
5757
+ }),
5758
+ /* @__PURE__ */ jsxs("span", {
5759
+ className: "ui-lg-limeta",
5760
+ children: [tr(":"), labelParts(edgeText(e))]
5380
5761
  })
5381
- ] }), /* @__PURE__ */ jsxs("span", {
5382
- className: "ui-lg-limeta",
5383
- children: [tr(":"), labelParts(edgeText(e))]
5384
- }))) })]
5762
+ ] }), null)) })]
5385
5763
  })]
5386
5764
  });
5387
5765
  const showList = p.listView !== false && view === "list";
@@ -5424,6 +5802,17 @@ function LayerGraph(p) {
5424
5802
  p.nodeWidth,
5425
5803
  cols
5426
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
+ ]);
5427
5816
  return /* @__PURE__ */ jsxs("div", {
5428
5817
  className: cx("ui-graph ui-lg", p.className),
5429
5818
  children: [
@@ -5542,6 +5931,10 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
5542
5931
  const Y = (v) => B - v / top * 200;
5543
5932
  const ticks = TICKS.map((f) => f * top);
5544
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
+ };
5545
5938
  const edge = {
5546
5939
  left: (L - step / 2) / 640 * 100 + "%",
5547
5940
  right: (10 - step / 2) / 640 * 100 + "%"
@@ -5558,13 +5951,22 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
5558
5951
  }) : null,
5559
5952
  /* @__PURE__ */ jsxs("div", {
5560
5953
  className: "ui-chart-plot",
5954
+ tabIndex: n ? 0 : void 0,
5955
+ role: "group",
5956
+ "aria-label": label,
5957
+ "aria-description": tr("左右方向鍵查看每一個時間點的數值"),
5561
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
+ },
5562
5965
  children: [
5563
5966
  /* @__PURE__ */ jsxs("svg", {
5564
5967
  viewBox: "0 0 640 240",
5565
5968
  width: "100%",
5566
- role: "img",
5567
- "aria-label": label,
5969
+ "aria-hidden": "true",
5568
5970
  children: [ticks.map((v, i) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
5569
5971
  x1: L,
5570
5972
  x2: R,
@@ -5923,10 +6325,13 @@ function NotificationBell({ items, onOpen, onReadAll, emptyText }) {
5923
6325
  type: "button",
5924
6326
  className: cx("ui-noti-item", !it.read && "is-unread"),
5925
6327
  onClick: () => onOpen?.(it),
5926
- children: [!it.read ? /* @__PURE__ */ jsx("span", {
6328
+ children: [!it.read ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
5927
6329
  className: "ui-noti-dot",
5928
- "aria-label": tr("未讀")
5929
- }) : 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", {
5930
6335
  className: "ui-noti-text",
5931
6336
  children: [
5932
6337
  /* @__PURE__ */ jsx("span", {
@@ -6451,6 +6856,7 @@ function Switch({ checked, onChange, label, disabled, className }) {
6451
6856
  onPointerDown: () => setPressing(true),
6452
6857
  onPointerUp: () => setPressing(false),
6453
6858
  onPointerLeave: () => setPressing(false),
6859
+ onPointerCancel: () => setPressing(false),
6454
6860
  children: /* @__PURE__ */ jsx("span", {
6455
6861
  className: "ui-switch-thumb",
6456
6862
  style: {
@@ -6523,7 +6929,10 @@ function TextArea({ label, hint, value, onChange, maxLength = 200, className, id
6523
6929
  className: "ui-count",
6524
6930
  children: [/* @__PURE__ */ jsx("span", {
6525
6931
  "aria-hidden": "true",
6526
- children: format.fraction((value || "").length, maxLength)
6932
+ children: /* @__PURE__ */ jsx("span", {
6933
+ className: "ui-seen",
6934
+ "data-text": format.fraction((value || "").length, maxLength)
6935
+ })
6527
6936
  }), /* @__PURE__ */ jsx("span", {
6528
6937
  className: "ui-visually-hidden",
6529
6938
  children: format.fractionLabel((value || "").length, maxLength, tr("字"))
@@ -6747,6 +7156,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6747
7156
  if (!open || !hasStep) return;
6748
7157
  let el = findTarget(target);
6749
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 放在較小的元素上,例如要說明的那張卡片或那一列,而不是整頁。`);
6750
7160
  if (el instanceof HTMLElement && narrowNow()) {
6751
7161
  const keep = el.style.scrollMarginTop;
6752
7162
  el.style.scrollMarginTop = bounds(el).top + edge() + pad + "px";
@@ -6886,10 +7296,10 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6886
7296
  className: "ui-tour-count",
6887
7297
  children: [/* @__PURE__ */ jsx("span", {
6888
7298
  "aria-hidden": "true",
6889
- children: monoNums(tr("{n} / {total}", {
7299
+ children: seenOnly(tr("{n} / {total}", {
6890
7300
  n: "",
6891
7301
  total: ""
6892
- }), [i + 1, steps.length])
7302
+ }), [String(i + 1), String(steps.length)])
6893
7303
  }), /* @__PURE__ */ jsx("span", {
6894
7304
  className: "ui-visually-hidden",
6895
7305
  children: tr("第 {a} 步,共 {b} 步", {
@@ -7235,7 +7645,7 @@ function TreeList(p) {
7235
7645
  "aria-posinset": r.pos,
7236
7646
  "aria-setsize": r.size,
7237
7647
  "aria-expanded": r.isF ? r.open : void 0,
7238
- "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,
7239
7649
  style: vars({ "--d": r.depth }),
7240
7650
  onFocus: () => focusId !== r.n.id && setFocusId(r.n.id)
7241
7651
  });
@@ -7336,8 +7746,8 @@ function TreeList(p) {
7336
7746
  role: "alert",
7337
7747
  children: [
7338
7748
  tr("無法載入 {name} 的子項目", { name: r.n.name }),
7339
- r.error ? ":" + r.error : "",
7340
- "。"
7749
+ r.error ? tr(":") + r.error : "",
7750
+ tr("。").trim()
7341
7751
  ]
7342
7752
  }), /* @__PURE__ */ jsx("button", {
7343
7753
  type: "button",
@@ -7544,7 +7954,7 @@ function TreeList(p) {
7544
7954
  if (!r.x && r.open && i < every.length && every[i].depth > depth) {
7545
7955
  const [kidsOut, next] = nest(i, depth + 1);
7546
7956
  out.push(/* @__PURE__ */ jsx("div", {
7547
- id: `${uid}-g-${r.n.id}`,
7957
+ id: `${uid}-g-${idPart(r.n.id)}`,
7548
7958
  role: "group",
7549
7959
  className: "ui-tree-group",
7550
7960
  children: kidsOut