@seanyeh77/ui 0.8.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { a as parseDate, c as addMessages, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-B2xJlA9l.js";
2
+ import { a as parseDate, c as addMessages, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-BoMMgOww.js";
3
3
  import * as React from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { Tooltip as Tooltip$1 } from "@base-ui/react/tooltip";
@@ -99,7 +99,8 @@ const PH = {
99
99
  "terminal-window": "<path d=\"M128,128a8,8,0,0,1-3,6.25l-40,32a8,8,0,1,1-10-12.5L107.19,128,75,102.25a8,8,0,1,1,10-12.5l40,32A8,8,0,0,1,128,128Zm48,24H136a8,8,0,0,0,0,16h40a8,8,0,0,0,0-16Zm56-96V200a16,16,0,0,1-16,16H40a16,16,0,0,1-16-16V56A16,16,0,0,1,40,40H216A16,16,0,0,1,232,56ZM216,200V56H40V200H216Z\"/>",
100
100
  "file-code": "<path d=\"M181.66,146.34a8,8,0,0,1,0,11.32l-24,24a8,8,0,0,1-11.32-11.32L164.69,152l-18.35-18.34a8,8,0,0,1,11.32-11.32Zm-72-24a8,8,0,0,0-11.32,0l-24,24a8,8,0,0,0,0,11.32l24,24a8,8,0,0,0,11.32-11.32L91.31,152l18.35-18.34A8,8,0,0,0,109.66,122.34ZM216,88V216a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-56-8h28.69L160,51.31Zm40,136V96H152a8,8,0,0,1-8-8V40H56V216H200Z\"/>",
101
101
  hash: "<path d=\"M224,88H175.4l8.47-46.57a8,8,0,0,0-15.74-2.86l-9,49.43H111.4l8.47-46.57a8,8,0,0,0-15.74-2.86L95.14,88H48a8,8,0,0,0,0,16H92.23L83.5,152H32a8,8,0,0,0,0,16H80.6l-8.47,46.57a8,8,0,0,0,6.44,9.3A7.79,7.79,0,0,0,80,224a8,8,0,0,0,7.86-6.57l9-49.43H144.6l-8.47,46.57a8,8,0,0,0,6.44,9.3A7.79,7.79,0,0,0,144,224a8,8,0,0,0,7.86-6.57l9-49.43H208a8,8,0,0,0,0-16H163.77l8.73-48H224a8,8,0,0,0,0-16Zm-76.5,64H99.77l8.73-48h47.73Z\"/>",
102
- command: "<path d=\"M180,144H160V112h20a36,36,0,1,0-36-36V96H112V76a36,36,0,1,0-36,36H96v32H76a36,36,0,1,0,36,36V160h32v20a36,36,0,1,0,36-36ZM160,76a20,20,0,1,1,20,20H160ZM56,76a20,20,0,0,1,40,0V96H76A20,20,0,0,1,56,76ZM96,180a20,20,0,1,1-20-20H96Zm16-68h32v32H112Zm68,88a20,20,0,0,1-20-20V160h20a20,20,0,0,1,0,40Z\"/>"
102
+ command: "<path d=\"M180,144H160V112h20a36,36,0,1,0-36-36V96H112V76a36,36,0,1,0-36,36H96v32H76a36,36,0,1,0,36,36V160h32v20a36,36,0,1,0,36-36ZM160,76a20,20,0,1,1,20,20H160ZM56,76a20,20,0,0,1,40,0V96H76A20,20,0,0,1,56,76ZM96,180a20,20,0,1,1-20-20H96Zm16-68h32v32H112Zm68,88a20,20,0,0,1-20-20V160h20a20,20,0,0,1,0,40Z\"/>",
103
+ tag: "<path d=\"M243.31,136,144,36.69A15.86,15.86,0,0,0,132.69,32H40a8,8,0,0,0-8,8v92.69A15.86,15.86,0,0,0,36.69,144L136,243.31a16,16,0,0,0,22.63,0l84.68-84.68a16,16,0,0,0,0-22.63Zm-96,96L48,132.69V48h84.69L232,147.31ZM96,84A12,12,0,1,1,84,72,12,12,0,0,1,96,84Z\"/>"
103
104
  };
104
105
  const PH_FILL = {
105
106
  archive: "<path d=\"M224,48H32A16,16,0,0,0,16,64V88a16,16,0,0,0,16,16v88a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V104a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm-72,96H104a8,8,0,0,1,0-16h48a8,8,0,0,1,0,16Zm72-56H32V64H224V88Z\"/>",
@@ -191,7 +192,8 @@ const PH_FILL = {
191
192
  "terminal-window": "<path d=\"M216,40H40A16,16,0,0,0,24,56V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V56A16,16,0,0,0,216,40Zm-91,94.25-40,32a8,8,0,1,1-10-12.5L107.19,128,75,102.25a8,8,0,1,1,10-12.5l40,32a8,8,0,0,1,0,12.5ZM176,168H136a8,8,0,0,1,0-16h40a8,8,0,0,1,0,16Z\"/>",
192
193
  "file-code": "<path d=\"M213.66,82.34l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40V216a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34Zm-104,88a8,8,0,0,1-11.32,11.32l-24-24a8,8,0,0,1,0-11.32l24-24a8,8,0,0,1,11.32,11.32L91.31,152Zm72-12.68-24,24a8,8,0,0,1-11.32-11.32L164.69,152l-18.35-18.34a8,8,0,0,1,11.32-11.32l24,24A8,8,0,0,1,181.66,157.66ZM152,88V44l44,44Z\"/>",
193
194
  hash: "<path d=\"M116.25,112h31.5l-8,32h-31.5ZM224,48V208a16,16,0,0,1-16,16H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48Zm-16,56a8,8,0,0,0-8-8H168.25l7.51-30.06a8,8,0,0,0-15.52-3.88L151.75,96h-31.5l7.51-30.06a8,8,0,0,0-15.52-3.88L103.75,96H64a8,8,0,0,0,0,16H99.75l-8,32H56a8,8,0,0,0,0,16H87.75l-7.51,30.06a8,8,0,0,0,5.82,9.7,8.13,8.13,0,0,0,2,.24,8,8,0,0,0,7.75-6.06L104.25,160h31.5l-7.51,30.06a8,8,0,0,0,5.82,9.7A8.13,8.13,0,0,0,136,200a8,8,0,0,0,7.75-6.06L152.25,160H192a8,8,0,0,0,0-16H156.25l8-32H200A8,8,0,0,0,208,104Z\"/>",
194
- command: "<path d=\"M116,116h24v24H116ZM86,72a14,14,0,0,0,0,28h14V86A14,14,0,0,0,86,72Zm98,14a14,14,0,0,0-28,0v14h14A14,14,0,0,0,184,86ZM72,170a14,14,0,0,0,28,0V156H86A14,14,0,0,0,72,170ZM224,48V208a16,16,0,0,1-16,16H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48Zm-68,92V116h14a30,30,0,1,0-30-30v14H116V86a30,30,0,1,0-30,30h14v24H86a30,30,0,1,0,30,30V156h24v14a30,30,0,1,0,30-30Zm0,30a14,14,0,1,0,14-14H156Z\"/>"
195
+ command: "<path d=\"M116,116h24v24H116ZM86,72a14,14,0,0,0,0,28h14V86A14,14,0,0,0,86,72Zm98,14a14,14,0,0,0-28,0v14h14A14,14,0,0,0,184,86ZM72,170a14,14,0,0,0,28,0V156H86A14,14,0,0,0,72,170ZM224,48V208a16,16,0,0,1-16,16H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48Zm-68,92V116h14a30,30,0,1,0-30-30v14H116V86a30,30,0,1,0-30,30h14v24H86a30,30,0,1,0,30,30V156h24v14a30,30,0,1,0,30-30Zm0,30a14,14,0,1,0,14-14H156Z\"/>",
196
+ tag: "<path d=\"M243.31,136,144,36.69A15.86,15.86,0,0,0,132.69,32H40a8,8,0,0,0-8,8v92.69A15.86,15.86,0,0,0,36.69,144L136,243.31a16,16,0,0,0,22.63,0l84.68-84.68a16,16,0,0,0,0-22.63ZM84,96A12,12,0,1,1,96,84,12,12,0,0,1,84,96Z\"/>"
195
197
  };
196
198
  /** Lucide names that map to a Phosphor icon. */
197
199
  const PH_ALIAS = {
@@ -266,7 +268,12 @@ function store(key, value) {
266
268
  function reduced() {
267
269
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
268
270
  }
269
- const IS_MAC = /Mac|iPhone|iPad/.test(typeof navigator !== "undefined" && (navigator.platform || navigator.userAgent) || "");
271
+ const nav = typeof navigator !== "undefined" ? navigator : void 0;
272
+ const IS_MAC = /mac|iphone|ipad/i.test(nav?.userAgentData?.platform || nav?.platform || nav?.userAgent || "");
273
+ /** A touch screen as the main input (phones, tablets): no keyboard to press a shortcut with, no hover. Phones and
274
+ * tablets report (pointer: coarse); (hover: none) alone is not used, since Chromium keeps it after touch emulation is
275
+ * turned off and a mouse would then lose its Tooltips. */
276
+ const TOUCH_ONLY = "(pointer: coarse)";
270
277
  const SHORTCUT = IS_MAC ? "⌘K" : "Ctrl K";
271
278
  /** Matches a media query and follows changes. */
272
279
  function useMedia(query) {
@@ -310,6 +317,20 @@ function digits(text, numbers = /(\d[\d,.:/]*)/) {
310
317
  children: t
311
318
  }, i) : t);
312
319
  }
320
+ /** Alt, Meta or Ctrl held: the key belongs to the browser or the system (Alt+← goes back a page), not to the widget. */
321
+ const browserKey = (e) => e.altKey || e.metaKey || e.ctrlKey;
322
+ /** The words in a React node, as a screen reader would read them: strings and numbers, through elements' children. */
323
+ function nodeText(node) {
324
+ if (node == null || typeof node === "boolean") return "";
325
+ if (typeof node === "string" || typeof node === "number") return String(node);
326
+ if (Array.isArray(node)) return node.map(nodeText).join("");
327
+ if (React.isValidElement(node)) {
328
+ const props = node.props;
329
+ if (typeof props["aria-label"] === "string") return props["aria-label"];
330
+ return nodeText(props.children) || (typeof props.label === "string" ? props.label : "");
331
+ }
332
+ return "";
333
+ }
313
334
  // src/icons/Icon.tsx
314
335
  const BY_MARKUP = /* @__PURE__ */ new Map();
315
336
  for (const k of Object.keys(PH)) {
@@ -676,13 +697,16 @@ function Tooltip({ label, side = "top", describe = true, wrap = false, disabled
676
697
  }
677
698
  // src/components/IconButton/IconButton.tsx
678
699
  /** A square icon-only button with a tooltip. */
679
- function IconButton({ label, icon, className, tooltip = true, ...native }) {
700
+ function IconButton({ label, icon, className, tooltip = true, filled, ...native }) {
680
701
  const btn = /* @__PURE__ */ jsx("button", {
681
702
  type: "button",
682
703
  ...native,
683
704
  className: cx("ui-iconbtn", className),
684
705
  "aria-label": label,
685
- children: /* @__PURE__ */ jsx(IconOf, { icon })
706
+ children: /* @__PURE__ */ jsx(IconOf, {
707
+ icon,
708
+ filled
709
+ })
686
710
  });
687
711
  return tooltip ? /* @__PURE__ */ jsx(Tooltip, {
688
712
  label,
@@ -693,6 +717,7 @@ function IconButton({ label, icon, className, tooltip = true, ...native }) {
693
717
  // src/components/TopBar/TopBar.tsx
694
718
  /** The bar at the top of a dashboard page: title or breadcrumb on the left, search and tools on the right. */
695
719
  function TopBar({ title, breadcrumb, onSearch, searchLabel, children, onMenu, className }) {
720
+ const touch = useMedia(TOUCH_ONLY);
696
721
  return /* @__PURE__ */ jsxs("header", {
697
722
  className: cx("ui-topbar", className),
698
723
  children: [
@@ -721,13 +746,13 @@ function TopBar({ title, breadcrumb, onSearch, searchLabel, children, onMenu, cl
721
746
  size: 16
722
747
  }),
723
748
  /* @__PURE__ */ jsx("span", { children: searchLabel || tr("搜尋") }),
724
- /* @__PURE__ */ jsx("kbd", { children: SHORTCUT })
749
+ touch ? null : /* @__PURE__ */ jsx("kbd", { children: SHORTCUT })
725
750
  ]
726
751
  }), /* @__PURE__ */ jsx(IconButton, {
727
752
  className: "ui-search-icon",
728
753
  "data-tour": "search",
729
754
  icon: "magnifying-glass",
730
- label: tr("搜尋({k})", { k: SHORTCUT }),
755
+ label: touch ? tr("搜尋") : tr("搜尋({k})", { k: SHORTCUT }),
731
756
  onClick: onSearch
732
757
  })] }) : null, children]
733
758
  })
@@ -958,15 +983,22 @@ function Drawer({ open, onClose, title, actions, dirty, width, side = "right", c
958
983
  });
959
984
  }
960
985
  // src/internal/focusMain.ts
986
+ let lastInput = "pointer";
987
+ if (typeof document !== "undefined") {
988
+ document.addEventListener("keydown", () => lastInput = "key", true);
989
+ document.addEventListener("pointerdown", () => lastInput = "pointer", true);
990
+ }
961
991
  /** Moves keyboard and screen-reader focus to the page's content: its first heading inside main (or the top bar's title),
962
- * else main itself. Call it after the app changes page, e.g. when a CommandPalette result opens another page. */
992
+ * else main itself. Call it after the app changes page, e.g. when a CommandPalette result opens another page. The
993
+ * heading gets no focus ring: a 3 px accent bar on its left after a key press, nothing after a mouse or touch. */
963
994
  function focusMain() {
964
995
  if (typeof document === "undefined") return;
965
996
  const main = document.querySelector("main");
966
997
  const target = main?.querySelector("h1, h2") ?? document.querySelector(".ui-topbar-title") ?? main;
967
998
  if (!target) return;
968
999
  if (target.tabIndex < 0 && !target.hasAttribute("tabindex")) target.setAttribute("tabindex", "-1");
969
- target.focus();
1000
+ target.setAttribute("data-ui-main-focus", lastInput);
1001
+ target.focus({ preventScroll: false });
970
1002
  }
971
1003
  // src/components/AppShell/AppShell.tsx
972
1004
  const COLLAPSE_KEY = "ui-nav-collapsed";
@@ -2470,6 +2502,7 @@ function Tabs({ items, value, onChange, label, unit, className }) {
2470
2502
  className: cx("ui-tab", i === idx && "is-selected"),
2471
2503
  onClick: () => go(i),
2472
2504
  onKeyDown: (e) => {
2505
+ if (browserKey(e)) return;
2473
2506
  const to = e.key === "ArrowRight" ? (i + 1) % items.length : e.key === "ArrowLeft" ? (i - 1 + items.length) % items.length : -1;
2474
2507
  if (to < 0) return;
2475
2508
  e.preventDefault();
@@ -2512,7 +2545,23 @@ function useScrollHint() {
2512
2545
  const ro = new ResizeObserver(measure);
2513
2546
  ro.observe(el);
2514
2547
  if (el.firstElementChild) ro.observe(el.firstElementChild);
2515
- return () => ro.disconnect();
2548
+ let raf = 0;
2549
+ const later = () => {
2550
+ cancelAnimationFrame(raf);
2551
+ raf = requestAnimationFrame(measure);
2552
+ };
2553
+ const mo = new MutationObserver(later);
2554
+ mo.observe(el, {
2555
+ childList: true,
2556
+ subtree: true,
2557
+ characterData: true
2558
+ });
2559
+ document.fonts?.ready.then(later).catch(() => {});
2560
+ return () => {
2561
+ ro.disconnect();
2562
+ mo.disconnect();
2563
+ cancelAnimationFrame(raf);
2564
+ };
2516
2565
  }, [measure]);
2517
2566
  return {
2518
2567
  ref,
@@ -2647,7 +2696,8 @@ function writeUrl(prefix, filters, values, q) {
2647
2696
  }
2648
2697
  // src/internal/FloatingPanel.tsx
2649
2698
  /** A positioned panel next to its trigger: flips when there is no room, closes on Esc and outside press, returns focus. */
2650
- function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, children, ...aria }) {
2699
+ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, boundary, children, ...aria }) {
2700
+ const within = boundary?.current ?? void 0;
2651
2701
  return /* @__PURE__ */ jsxs(Popover$1.Root, {
2652
2702
  open,
2653
2703
  onOpenChange,
@@ -2662,6 +2712,12 @@ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "
2662
2712
  align,
2663
2713
  sideOffset,
2664
2714
  anchor,
2715
+ collisionBoundary: within,
2716
+ collisionPadding: within ? 0 : void 0,
2717
+ collisionAvoidance: within ? {
2718
+ side: "flip",
2719
+ align: "shift"
2720
+ } : void 0,
2665
2721
  children: /* @__PURE__ */ jsx(Popover$1.Popup, {
2666
2722
  className,
2667
2723
  "aria-label": aria["aria-label"],
@@ -2727,11 +2783,12 @@ function ColumnMenu({ cols, hidden, onToggle }) {
2727
2783
  });
2728
2784
  }
2729
2785
  /** 「篩選」 with the number of active filters; options apply at once and show how many rows they would leave. */
2730
- function FilterButton({ filters, values, activeCount, count, onChange, onClear }) {
2786
+ function FilterButton({ filters, values, activeCount, count, onChange, onClear, boundary }) {
2731
2787
  const [open, setOpen] = React.useState(false);
2732
2788
  return /* @__PURE__ */ jsxs(FloatingPanel, {
2733
2789
  open,
2734
2790
  onOpenChange: setOpen,
2791
+ boundary,
2735
2792
  className: "ui-dt-filterpop",
2736
2793
  "aria-label": tr("篩選"),
2737
2794
  trigger: /* @__PURE__ */ jsxs("button", {
@@ -2842,12 +2899,31 @@ function FilterButton({ filters, values, activeCount, count, onChange, onClear }
2842
2899
  })]
2843
2900
  });
2844
2901
  }
2845
- /** Long text in a cell. Phone cards: at most 2 lines with 「顯示全部」. Desktop: one line; when it is cut off, hover or
2846
- * focus shows the whole text in a Tooltip. */
2902
+ /** A short cell with its whole text in a Tooltip (a mouse; not on a touch screen, where the row's details show it). */
2903
+ function FullText({ text, children }) {
2904
+ const touch = useMedia(TOUCH_ONLY);
2905
+ return /* @__PURE__ */ jsx(Tooltip, {
2906
+ label: text,
2907
+ wrap: true,
2908
+ describe: false,
2909
+ disabled: touch || !text,
2910
+ children: /* @__PURE__ */ jsxs("span", {
2911
+ className: "ui-dt-full",
2912
+ children: [children, text ? /* @__PURE__ */ jsx("span", {
2913
+ className: "ui-visually-hidden",
2914
+ children: tr(",") + text
2915
+ }) : null]
2916
+ })
2917
+ });
2918
+ }
2919
+ /** Long text in a cell. Phone cards: at most 2 lines with 「顯示全部」. Desktop: one line; the row's caret shows it in
2920
+ * full below the row, and with a mouse, hover or focus on a cut-off cell shows it in a Tooltip. No Tooltip on a touch
2921
+ * screen: a tap would leave it over the next rows. */
2847
2922
  function LongText({ children }) {
2848
2923
  const box = React.useRef(null);
2849
2924
  const ref = React.useRef(null);
2850
2925
  const narrow = useNarrow();
2926
+ const touch = useMedia(TOUCH_ONLY);
2851
2927
  const [open, setOpen] = React.useState(false);
2852
2928
  const [over, setOver] = React.useState(false);
2853
2929
  const [cut, setCut] = React.useState("");
@@ -2857,7 +2933,7 @@ function LongText({ children }) {
2857
2933
  if (!el || !outer || open) return;
2858
2934
  const check = () => {
2859
2935
  setOver(el.scrollHeight > el.clientHeight + 1);
2860
- setCut(!narrow && outer.scrollWidth > outer.clientWidth + 1 ? outer.textContent ?? "" : "");
2936
+ setCut(!narrow && !touch && outer.scrollWidth > outer.clientWidth + 1 ? outer.textContent ?? "" : "");
2861
2937
  };
2862
2938
  check();
2863
2939
  const ro = new ResizeObserver(check);
@@ -2866,7 +2942,8 @@ function LongText({ children }) {
2866
2942
  }, [
2867
2943
  open,
2868
2944
  children,
2869
- narrow
2945
+ narrow,
2946
+ touch
2870
2947
  ]);
2871
2948
  const body = /* @__PURE__ */ jsxs("span", {
2872
2949
  ref: box,
@@ -2906,6 +2983,7 @@ const ARROWS = {
2906
2983
  };
2907
2984
  const get = (row, key) => row[key];
2908
2985
  const isNum = (c) => c.numeric || c.format === "money" || c.format === "percent";
2986
+ const ROW_CONTROLS = "a, button, input, select, textarea, label, [role=\"checkbox\"], [role=\"button\"], [role=\"menuitem\"], [role=\"link\"], [contenteditable]";
2909
2987
  function RowCheck({ v, label, onClick }) {
2910
2988
  return /* @__PURE__ */ jsx("button", {
2911
2989
  type: "button",
@@ -2950,6 +3028,10 @@ function DataTable(p) {
2950
3028
  const [values, setValues] = React.useState(() => fromUrl().values);
2951
3029
  const [view, setView] = React.useState(p.views?.[0]?.id ?? null);
2952
3030
  const [toggled, setToggled] = React.useState({});
3031
+ const [opened, setOpened] = React.useState({});
3032
+ const narrow = useNarrow();
3033
+ const uid = React.useId();
3034
+ const rootRef = React.useRef(null);
2953
3035
  const [sel, setSel] = React.useState({});
2954
3036
  const [sumVal, setSumVal] = React.useState("all");
2955
3037
  const [resetKey, setResetKey] = React.useState(p.resetKey);
@@ -2966,6 +3048,7 @@ function DataTable(p) {
2966
3048
  dir: "desc"
2967
3049
  });
2968
3050
  setToggled({});
3051
+ setOpened({});
2969
3052
  }
2970
3053
  const valuesKey = JSON.stringify(values);
2971
3054
  React.useEffect(() => {
@@ -3158,17 +3241,21 @@ function DataTable(p) {
3158
3241
  const m = c.mobile || (!hasTitle && ci === 0 ? "title" : null);
3159
3242
  return m ? "is-m-" + m : null;
3160
3243
  };
3244
+ const longCols = shownCols.filter((c) => c.long || c.fullText);
3245
+ const expander = longCols.length > 0 && !narrow;
3246
+ const EXP = 40;
3161
3247
  const template = [
3248
+ expander ? "40px" : null,
3162
3249
  selectable ? "46px" : null,
3163
3250
  ...shownCols.map((c) => c.width ? `minmax(${c.width}px, ${c.grow || 1}fr)` : c.numeric ? "minmax(96px, .8fr)" : "minmax(120px, 1fr)"),
3164
3251
  hasAct ? actW + "px" : null
3165
3252
  ].filter(Boolean).join(" ");
3166
- const minW = (selectable ? 46 : 0) + shownCols.reduce((a, c) => a + (c.width || (c.numeric ? 96 : 120)), 0) + (hasAct ? actW : 0);
3253
+ const minW = (expander ? EXP : 0) + (selectable ? 46 : 0) + shownCols.reduce((a, c) => a + (c.width || (c.numeric ? 96 : 120)), 0) + (hasAct ? actW : 0);
3167
3254
  const gridStyle = {
3168
3255
  gridTemplateColumns: template,
3169
3256
  minWidth: minW
3170
3257
  };
3171
- const stickyStyle = (ci) => ci === 0 && sticky ? { left: selectable ? 46 : 0 } : void 0;
3258
+ const stickyStyle = (ci) => ci === 0 && sticky ? { left: (expander ? EXP : 0) + (selectable ? 46 : 0) } : void 0;
3172
3259
  const cellClass = (c, ci, ...more) => cx("ui-dt-cell", isNum(c) && "is-num", ci === 0 && sticky && "is-sticky", ...more);
3173
3260
  const head = selectable && selIds.length && p.bulkActions ? /* @__PURE__ */ jsxs("div", {
3174
3261
  className: "ui-dt-row ui-dt-head ui-dt-bulk",
@@ -3208,6 +3295,11 @@ function DataTable(p) {
3208
3295
  role: "row",
3209
3296
  style: gridStyle,
3210
3297
  children: [
3298
+ expander ? /* @__PURE__ */ jsx("div", {
3299
+ className: "ui-dt-cell ui-dt-exp",
3300
+ role: "columnheader",
3301
+ "aria-label": tr("詳細")
3302
+ }) : null,
3211
3303
  selectable ? /* @__PURE__ */ jsx("div", {
3212
3304
  className: "ui-dt-cell ui-dt-sel",
3213
3305
  role: "columnheader",
@@ -3244,7 +3336,7 @@ function DataTable(p) {
3244
3336
  ]
3245
3337
  });
3246
3338
  const mark = searching ? q : "";
3247
- const cell = (r, c) => {
3339
+ const cellInner = (r, c) => {
3248
3340
  const raw = get(r, c.key);
3249
3341
  let v;
3250
3342
  if (c.render) v = c.render(r);
@@ -3260,7 +3352,14 @@ function DataTable(p) {
3260
3352
  })
3261
3353
  ] });
3262
3354
  else v = markMatch(cellText(c, raw), mark);
3263
- return c.long ? /* @__PURE__ */ jsx(LongText, { children: v }) : v;
3355
+ return v;
3356
+ };
3357
+ const cell = (r, c) => {
3358
+ const v = c.long ? /* @__PURE__ */ jsx(LongText, { children: cellInner(r, c) }) : cellInner(r, c);
3359
+ return c.fullText ? /* @__PURE__ */ jsx(FullText, {
3360
+ text: c.fullText(r),
3361
+ children: v
3362
+ }) : v;
3264
3363
  };
3265
3364
  const total = (c, ci) => {
3266
3365
  const how = p.totals?.[c.key];
@@ -3278,6 +3377,7 @@ function DataTable(p) {
3278
3377
  return "";
3279
3378
  };
3280
3379
  return /* @__PURE__ */ jsxs("div", {
3380
+ ref: rootRef,
3281
3381
  className: cx("ui-dt", selIds.length && "has-sel", p.className),
3282
3382
  children: [
3283
3383
  p.caption ? /* @__PURE__ */ jsx("div", {
@@ -3347,6 +3447,7 @@ function DataTable(p) {
3347
3447
  className: "ui-dt-search"
3348
3448
  }) : null,
3349
3449
  filters.length ? /* @__PURE__ */ jsx(FilterButton, {
3450
+ boundary: rootRef,
3350
3451
  filters,
3351
3452
  values,
3352
3453
  activeCount: activeN,
@@ -3363,12 +3464,18 @@ function DataTable(p) {
3363
3464
  setPage(0);
3364
3465
  }
3365
3466
  }) : null,
3366
- /* @__PURE__ */ jsx("span", {
3467
+ /* @__PURE__ */ jsxs("span", {
3367
3468
  className: "ui-dt-result",
3368
- children: monoNums(tr("{n} / {total} 筆", {
3369
- n: "",
3370
- total: ""
3371
- }), [format.number(list.length), format.number(baseCount)])
3469
+ children: [/* @__PURE__ */ jsx("span", {
3470
+ "aria-hidden": "true",
3471
+ children: monoNums(tr("{n} / {total} 筆", {
3472
+ n: "",
3473
+ total: ""
3474
+ }), [format.number(list.length), format.number(baseCount)])
3475
+ }), /* @__PURE__ */ jsx("span", {
3476
+ className: "ui-visually-hidden",
3477
+ children: format.fractionLabel(list.length, baseCount, tr("筆"))
3478
+ })]
3372
3479
  }),
3373
3480
  p.columnMenu !== false && cols.length > 2 ? /* @__PURE__ */ jsx(ColumnMenu, {
3374
3481
  cols,
@@ -3399,15 +3506,46 @@ function DataTable(p) {
3399
3506
  children: vis.length ? vis.map((x, i) => {
3400
3507
  const id = visIds[i];
3401
3508
  const on = !!sel[id];
3402
- return /* @__PURE__ */ jsxs("div", {
3509
+ const open = expander && !!opened[id];
3510
+ const detailId = `${uid}-d-${id}`;
3511
+ const rowName = shownCols[0] ? String(cellText(shownCols[0], get(x.r, shownCols[0].key)) ?? "") : "";
3512
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsxs("div", {
3403
3513
  "data-rid": id,
3404
3514
  ref: (el) => {
3405
3515
  rowEls.current[id] = el;
3406
3516
  },
3407
3517
  role: "row",
3408
- className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
3518
+ className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && "has-exp"),
3409
3519
  style: gridStyle,
3520
+ onClick: expander ? (e) => {
3521
+ const t = e.target;
3522
+ if (t.closest(ROW_CONTROLS) && t.closest(ROW_CONTROLS) !== e.currentTarget) return;
3523
+ if (String(window.getSelection() ?? "")) return;
3524
+ setOpened({
3525
+ ...opened,
3526
+ [id]: !open
3527
+ });
3528
+ } : void 0,
3410
3529
  children: [
3530
+ expander ? /* @__PURE__ */ jsx("div", {
3531
+ className: "ui-dt-cell ui-dt-exp",
3532
+ role: "cell",
3533
+ children: /* @__PURE__ */ jsx("button", {
3534
+ type: "button",
3535
+ className: cx("ui-dt-exp-btn", open && "is-open"),
3536
+ "aria-expanded": open,
3537
+ "aria-controls": open ? detailId : void 0,
3538
+ "aria-label": tr(open ? "收合 {name}" : "展開 {name}", { name: rowName }),
3539
+ onClick: () => setOpened({
3540
+ ...opened,
3541
+ [id]: !open
3542
+ }),
3543
+ children: /* @__PURE__ */ jsx(Icon, {
3544
+ name: "caret-right",
3545
+ size: 16
3546
+ })
3547
+ })
3548
+ }) : null,
3411
3549
  selectable ? /* @__PURE__ */ jsx("div", {
3412
3550
  className: "ui-dt-cell ui-dt-sel",
3413
3551
  role: "cell",
@@ -3430,7 +3568,27 @@ function DataTable(p) {
3430
3568
  children: p.rowActions?.(x.r)
3431
3569
  }) : null
3432
3570
  ]
3433
- }, id);
3571
+ }), open ? /* @__PURE__ */ jsx("div", {
3572
+ id: detailId,
3573
+ role: "row",
3574
+ className: cx("ui-dt-detail", i % 2 && "is-even"),
3575
+ style: { minWidth: minW },
3576
+ children: /* @__PURE__ */ jsx("div", {
3577
+ role: "cell",
3578
+ className: "ui-dt-detail-cell",
3579
+ style: { paddingLeft: EXP + (selectable ? 46 : 0) + 12 },
3580
+ children: longCols.map((c) => /* @__PURE__ */ jsxs("div", {
3581
+ className: "ui-dt-detail-item",
3582
+ children: [/* @__PURE__ */ jsx("div", {
3583
+ className: "ui-dt-detail-label",
3584
+ children: c.label
3585
+ }), /* @__PURE__ */ jsx("div", {
3586
+ className: "ui-dt-detail-text",
3587
+ children: c.fullText ? c.fullText(x.r) : cellInner(x.r, c)
3588
+ })]
3589
+ }, c.key))
3590
+ })
3591
+ }) : null] }, id);
3434
3592
  }) : /* @__PURE__ */ jsxs("div", {
3435
3593
  className: "ui-dt-empty",
3436
3594
  children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
@@ -3444,6 +3602,10 @@ function DataTable(p) {
3444
3602
  role: "row",
3445
3603
  style: gridStyle,
3446
3604
  children: [
3605
+ expander ? /* @__PURE__ */ jsx("div", {
3606
+ className: "ui-dt-cell",
3607
+ role: "cell"
3608
+ }) : null,
3447
3609
  selectable ? /* @__PURE__ */ jsx("div", {
3448
3610
  className: "ui-dt-cell",
3449
3611
  role: "cell"
@@ -3679,6 +3841,137 @@ function DetailList({ items, className }) {
3679
3841
  }, i))
3680
3842
  });
3681
3843
  }
3844
+ // src/components/SplitPane/SplitPane.tsx
3845
+ /** Width of the divider between the two areas, in px; a 48 px hit area is drawn over it. */
3846
+ const HANDLE = 16;
3847
+ /** Narrower than this (px, the component's own width), the two areas stack and the divider goes away. */
3848
+ const STACK = 960;
3849
+ /** One arrow key press, in px. */
3850
+ const STEP = 16;
3851
+ const read = (key) => {
3852
+ if (!key) return null;
3853
+ try {
3854
+ const v = Number(window.localStorage.getItem("ui-split:" + key));
3855
+ return Number.isFinite(v) && v > 0 ? v : null;
3856
+ } catch {
3857
+ return null;
3858
+ }
3859
+ };
3860
+ const write = (key, v) => {
3861
+ if (!key) return;
3862
+ try {
3863
+ window.localStorage.setItem("ui-split:" + key, String(Math.round(v)));
3864
+ } catch {}
3865
+ };
3866
+ /** A main area and a side panel with a divider between them that can be dragged, moved with the arrow keys and reset
3867
+ * with a double-click. Under 960 px (its own width) the two stack, side panel below, without the divider. */
3868
+ function SplitPane({ a, b, defaultB = 420, minA = 360, minB = 280, storageKey, label, onResize, className }) {
3869
+ devWarn(defaultB < minB, "SplitPane", `defaultB (${defaultB} px) is under minB (${minB} px): the panel starts at ${minB} px. Raise defaultB or lower minB.`);
3870
+ const root = React.useRef(null);
3871
+ const [width, setWidth] = React.useState(0);
3872
+ const [side, setSide] = React.useState(() => (typeof window === "undefined" ? null : read(storageKey)) ?? defaultB);
3873
+ const [drag, setDrag] = React.useState(false);
3874
+ const dragging = React.useRef(false);
3875
+ const id = React.useId();
3876
+ React.useLayoutEffect(() => {
3877
+ const el = root.current;
3878
+ if (!el) return;
3879
+ const measure = () => setWidth(el.clientWidth);
3880
+ measure();
3881
+ const ro = new ResizeObserver(measure);
3882
+ ro.observe(el);
3883
+ return () => ro.disconnect();
3884
+ }, []);
3885
+ const stacked = width > 0 && width < STACK;
3886
+ const maxB = Math.max(minB, width - HANDLE - minA);
3887
+ const shown = Math.round(Math.min(maxB, Math.max(minB, side)));
3888
+ const valueA = Math.max(0, width - HANDLE - shown);
3889
+ const latest = React.useRef(shown);
3890
+ const set = (v, keep = true) => {
3891
+ const next = Math.round(Math.min(maxB, Math.max(minB, v)));
3892
+ latest.current = next;
3893
+ setSide(next);
3894
+ if (keep) write(storageKey, next);
3895
+ onResize?.(next);
3896
+ };
3897
+ const onKey = (e) => {
3898
+ if (browserKey(e)) return;
3899
+ const to = e.key === "ArrowLeft" ? shown + STEP : e.key === "ArrowRight" ? shown - STEP : e.key === "Home" ? maxB : e.key === "End" ? minB : e.key === "Enter" ? defaultB : null;
3900
+ if (to == null) return;
3901
+ e.preventDefault();
3902
+ set(to);
3903
+ };
3904
+ const onDown = (e) => {
3905
+ if (e.button !== 0) return;
3906
+ e.preventDefault();
3907
+ try {
3908
+ e.currentTarget.setPointerCapture(e.pointerId);
3909
+ } catch {}
3910
+ e.currentTarget.focus({ preventScroll: true });
3911
+ dragging.current = true;
3912
+ setDrag(true);
3913
+ };
3914
+ const onMove = (e) => {
3915
+ if (!dragging.current || !root.current) return;
3916
+ const r = root.current.getBoundingClientRect();
3917
+ set(r.right - e.clientX - HANDLE / 2, false);
3918
+ };
3919
+ const onUp = (e) => {
3920
+ if (!dragging.current) return;
3921
+ dragging.current = false;
3922
+ setDrag(false);
3923
+ try {
3924
+ if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId);
3925
+ } catch {}
3926
+ if (root.current) write(storageKey, latest.current);
3927
+ };
3928
+ return /* @__PURE__ */ jsxs("div", {
3929
+ ref: root,
3930
+ className: cx("ui-split", stacked && "is-stacked", drag && "is-dragging", className),
3931
+ style: stacked || !width ? void 0 : { gridTemplateColumns: `minmax(0, 1fr) ${HANDLE}px ${shown}px` },
3932
+ children: [
3933
+ /* @__PURE__ */ jsx("div", {
3934
+ className: "ui-split-a",
3935
+ children: a
3936
+ }),
3937
+ stacked ? null : /* @__PURE__ */ jsx("div", {
3938
+ role: "separator",
3939
+ tabIndex: 0,
3940
+ "aria-orientation": "vertical",
3941
+ "aria-label": label || tr("調整面板寬度"),
3942
+ "aria-controls": id,
3943
+ "aria-valuenow": valueA,
3944
+ "aria-valuemin": minA,
3945
+ "aria-valuemax": Math.max(minA, width - HANDLE - minB),
3946
+ "aria-valuetext": tr("主要區域 {a} px,面板 {b} px", {
3947
+ a: valueA,
3948
+ b: shown
3949
+ }),
3950
+ className: "ui-split-handle",
3951
+ onKeyDown: onKey,
3952
+ onPointerDown: onDown,
3953
+ onPointerMove: onMove,
3954
+ onPointerUp: onUp,
3955
+ onPointerCancel: onUp,
3956
+ onDoubleClick: () => set(defaultB),
3957
+ children: /* @__PURE__ */ jsxs("span", {
3958
+ className: "ui-split-grip",
3959
+ "aria-hidden": "true",
3960
+ children: [
3961
+ /* @__PURE__ */ jsx("i", {}),
3962
+ /* @__PURE__ */ jsx("i", {}),
3963
+ /* @__PURE__ */ jsx("i", {})
3964
+ ]
3965
+ })
3966
+ }),
3967
+ /* @__PURE__ */ jsx("div", {
3968
+ id,
3969
+ className: "ui-split-b",
3970
+ children: b
3971
+ })
3972
+ ]
3973
+ });
3974
+ }
3682
3975
  // src/components/EmptyState/EmptyState.tsx
3683
3976
  /** What a list or page shows when it has nothing yet: what is missing and the first step. */
3684
3977
  function EmptyState({ title, description, steps = [], current = 0, action }) {
@@ -3904,6 +4197,14 @@ function Term({ children, title, text, content, code, action, refHref, onRef, is
3904
4197
  const txt = !!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim());
3905
4198
  setInline(txt);
3906
4199
  }, [children]);
4200
+ const block = React.useRef(null);
4201
+ const toggle = (next) => {
4202
+ if (next) {
4203
+ const el = ref.current?.closest(".ui-card, .ui-split-a, .ui-split-b, .ui-shell-main, main") ?? null;
4204
+ block.current = el && el.getBoundingClientRect().width >= 240 ? el : null;
4205
+ }
4206
+ setOpen(next);
4207
+ };
3907
4208
  const heading = title || (typeof children === "string" ? children : "");
3908
4209
  const trigger = /* @__PURE__ */ jsxs("button", {
3909
4210
  type: "button",
@@ -3970,10 +4271,11 @@ function Term({ children, title, text, content, code, action, refHref, onRef, is
3970
4271
  });
3971
4272
  return /* @__PURE__ */ jsx(FloatingPanel, {
3972
4273
  open,
3973
- onOpenChange: setOpen,
4274
+ onOpenChange: toggle,
3974
4275
  sideOffset: 8,
3975
4276
  className: "ui-term-pop",
3976
4277
  trigger,
4278
+ boundary: block,
3977
4279
  children: body(Popover$1.Title, Popover$1.Close)
3978
4280
  });
3979
4281
  }
@@ -4167,6 +4469,8 @@ function labelWidth(text) {
4167
4469
  return w + c.measureText(t[0] === "`" ? t.slice(1, -1) : t).width;
4168
4470
  }, 0);
4169
4471
  }
4472
+ const LABELS_KEY = "ui-lg-labels:";
4473
+ const allIds = (nodes) => nodes.map((n) => n.id).join("|");
4170
4474
  const GROW = 24;
4171
4475
  const GROW_MAX = 144;
4172
4476
  /** The label on 1 line, then wrapped onto 2, 3 and 4 lines as evenly as it goes. Breaks between Chinese characters
@@ -4246,24 +4550,31 @@ const clean = (pts) => pts.filter((q, i) => {
4246
4550
  return !a || !c || !(a[0] === q[0] && q[0] === c[0] || a[1] === q[1] && q[1] === c[1]);
4247
4551
  });
4248
4552
  /** Architecture as layers of boxes with arrows. Line width shows how often; inferred relations are dashed and labelled;
4249
- * shared items are listed under the diagram instead of drawn. Wider than the screen: scrolls sideways. */
4553
+ * shared items are listed under the diagram instead of drawn. Wider than its box: the boxes narrow (down to 120 px),
4554
+ * then the whole diagram scales down (to 0.75 at least); past that it scrolls sideways (PM). */
4250
4555
  function LayerGraph(p) {
4251
- const NW = p.nodeWidth || 200;
4556
+ const [avail, setAvail] = React.useState(0);
4557
+ const [fit, setFit] = React.useState(null);
4558
+ const fitted = fit && fit.at === avail ? fit : null;
4559
+ const NW = fitted?.nw ?? (p.nodeWidth || 200);
4252
4560
  const NH = 60;
4253
4561
  const GAP = 56;
4254
- const COL = 40;
4562
+ const COL = fitted?.col ?? 40;
4563
+ const scale = fitted?.scale ?? 1;
4255
4564
  const PAD = 16;
4256
4565
  const all = p.nodes;
4257
4566
  const sel = p.selected ?? null;
4258
4567
  devWarn(all.some((n) => n.fns != null), "LayerGraph", "fns is renamed size; pass size and, for the text under the bar, sizeLabel such as 「{n} 個函式」.");
4259
- const sizeOf = (n) => n.size ?? n.fns;
4568
+ devWarn(all.some((n) => n.external && n.shared), "LayerGraph", "a node is both external and shared; it is drawn as shared. Keep one of the two.");
4569
+ const sizeOf = (n) => n.external && !n.shared ? void 0 : n.size ?? n.fns;
4260
4570
  const sharedIds = new Set(all.filter((n) => n.shared).map((n) => n.id));
4261
4571
  const main = all.filter((n) => !n.shared);
4262
4572
  const shared = all.filter((n) => n.shared);
4263
4573
  const edges = p.edges.filter((e) => !sharedIds.has(e.from) && !sharedIds.has(e.to));
4264
4574
  const byLayer = /* @__PURE__ */ new Map();
4575
+ const EXTERNAL = Number.NEGATIVE_INFINITY;
4265
4576
  for (const n of main) {
4266
- const l = n.layer || 0;
4577
+ const l = n.external ? EXTERNAL : n.layer || 0;
4267
4578
  byLayer.set(l, [...byLayer.get(l) ?? [], n]);
4268
4579
  }
4269
4580
  const layers = [...byLayer.keys()].sort((a, b) => a - b);
@@ -4319,6 +4630,21 @@ function LayerGraph(p) {
4319
4630
  for (const k in ins) ins[k].sort((a, b) => pos[a.from].x - pos[b.from].x);
4320
4631
  const edgeId = (e) => e.id ?? `${e.from}->${e.to}`;
4321
4632
  const pickEdge = p.onSelectEdge;
4633
+ const [labelsOn, setLabelsOn] = React.useState(() => {
4634
+ try {
4635
+ const v = window.localStorage.getItem(LABELS_KEY + (p.scrollKey ?? allIds(p.nodes)));
4636
+ if (v === "1" || v === "0") return v === "1";
4637
+ } catch {}
4638
+ return p.edgeLabels !== "hover";
4639
+ });
4640
+ const peek = !labelsOn;
4641
+ const switchLabels = () => {
4642
+ const on = !labelsOn;
4643
+ setLabelsOn(on);
4644
+ try {
4645
+ window.localStorage.setItem(LABELS_KEY + (p.scrollKey ?? allIds(p.nodes)), on ? "1" : "0");
4646
+ } catch {}
4647
+ };
4322
4648
  const [hover, setHover] = React.useState(null);
4323
4649
  const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
4324
4650
  const uid = React.useId().replace(/:/g, "");
@@ -4339,8 +4665,9 @@ function LayerGraph(p) {
4339
4665
  onScroll();
4340
4666
  };
4341
4667
  const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
4668
+ const nodeIdsAll = new Set(all.map((n) => n.id));
4342
4669
  const uses = {};
4343
- for (const e of p.edges) if (sharedIds.has(e.to) && !sharedIds.has(e.from)) (uses[e.to] ??= {})[e.from] = (uses[e.to]?.[e.from] ?? 0) + (e.count || 0);
4670
+ for (const e of p.edges) if (sharedIds.has(e.to) && e.from !== e.to && nodeIdsAll.has(e.from)) (uses[e.to] ??= {})[e.from] = (uses[e.to]?.[e.from] ?? 0) + (e.count || 0);
4344
4671
  const selShared = !selEdge && sel != null && sharedIds.has(sel) ? sel : null;
4345
4672
  const related = (e) => selEdge ? e === selEdge : !!sel && !selShared && (e.from === sel || e.to === sel);
4346
4673
  const focus = !!sel || !!selEdge;
@@ -4351,6 +4678,7 @@ function LayerGraph(p) {
4351
4678
  };
4352
4679
  const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
4353
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);
4354
4682
  if (upsL.length) {
4355
4683
  const left0 = Math.min(...main.map((n) => pos[n.id].x));
4356
4684
  const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
@@ -4372,11 +4700,115 @@ function LayerGraph(p) {
4372
4700
  if (next && sel != null) p.onSelect?.(null);
4373
4701
  pickEdge?.(next);
4374
4702
  };
4703
+ const LANE_H = 28;
4704
+ const txOf = (e) => Math.round(pos[e.to].x + NW * (ins[e.to].indexOf(e) + 1) / (ins[e.to].length + 1));
4705
+ const laneGroups = {};
4706
+ const laneCount = {};
4707
+ {
4708
+ const into = {};
4709
+ for (const e of edges) if (ins[e.to]?.includes(e) && (e.inferred || related(e))) (into[e.to] ??= []).push(e);
4710
+ for (const id in into) {
4711
+ if (into[id].length < 2) continue;
4712
+ laneGroups[id] = into[id].sort((a, b) => txOf(b) - txOf(a));
4713
+ laneCount[id] = into[id].length;
4714
+ }
4715
+ }
4375
4716
  const draw = () => {
4376
4717
  const paths = [];
4377
4718
  const labels = [];
4378
4719
  const need = /* @__PURE__ */ new Set();
4720
+ const crowd = /* @__PURE__ */ new Set();
4721
+ const geomOf = (e) => {
4722
+ const a = pos[e.from];
4723
+ const b = pos[e.to];
4724
+ const oi = outs[e.from].indexOf(e);
4725
+ const on = outs[e.from].length;
4726
+ const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
4727
+ const sy = a.y + NH;
4728
+ const tx = txOf(e);
4729
+ const ty = b.y;
4730
+ const off = (oi - (on - 1) / 2) * 6;
4731
+ const skip = layerIndex[e.to] - layerIndex[e.from] > 1;
4732
+ const y1 = sy + gaps[layerIndex[e.from]] / 2 + off;
4733
+ let chx = sx;
4734
+ if (skip) {
4735
+ const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
4736
+ const mid = (sx + tx) / 2;
4737
+ const chans = [next[0].x - COL / 2, ...next.map((q) => q.x + NW + COL / 2)].map((c) => Math.max(PAD / 2, Math.min(W - PAD / 2, c)));
4738
+ chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
4739
+ }
4740
+ return {
4741
+ sx,
4742
+ sy,
4743
+ tx,
4744
+ ty,
4745
+ off,
4746
+ skip,
4747
+ y1,
4748
+ chx,
4749
+ from: skip ? chx : sx,
4750
+ startY: skip ? y1 : sy
4751
+ };
4752
+ };
4753
+ const lanes = /* @__PURE__ */ new Map();
4754
+ for (const id in laneGroups) {
4755
+ const group = laneGroups[id].map((e) => ({
4756
+ e,
4757
+ g: geomOf(e),
4758
+ w: Math.ceil(labelWidth(markText(e)))
4759
+ }));
4760
+ const n = group.length;
4761
+ const laneY = (j) => group[0].g.ty - 8 - 16 - j * LANE_H;
4762
+ const perms = [];
4763
+ const permute = (rest, acc) => {
4764
+ if (!rest.length) perms.push(acc);
4765
+ else rest.forEach((x, k) => permute([...rest.slice(0, k), ...rest.slice(k + 1)], [...acc, x]));
4766
+ };
4767
+ if (n <= 6) permute([...group.keys()], []);
4768
+ else perms.push([...group.keys()]);
4769
+ let best = null;
4770
+ for (const perm of perms) {
4771
+ const ys = [];
4772
+ perm.forEach((k, j) => ys[k] = laneY(j));
4773
+ const verts = group.flatMap((q, k) => [{
4774
+ k,
4775
+ x: q.g.from,
4776
+ y0: q.g.startY,
4777
+ y1: ys[k]
4778
+ }, {
4779
+ k,
4780
+ x: q.g.tx,
4781
+ y0: ys[k],
4782
+ y1: q.g.ty - 8
4783
+ }]);
4784
+ const free = (k, x0, x1) => verts.every((v) => v.k === k ? !(v.x > x0 - 1 && v.x < x1 + 1 && v.y0 < ys[k] + 7 && v.y1 > ys[k] - 7) : !(v.x > x0 - 5 && v.x < x1 + 5 && v.y0 < ys[k] + 10 && v.y1 > ys[k] - 10));
4785
+ let fails = 0;
4786
+ const sides = [];
4787
+ group.forEach((q, k) => {
4788
+ const r0 = Math.max(q.g.from, q.g.tx) + 8;
4789
+ const l1 = Math.min(q.g.from, q.g.tx) - 8;
4790
+ if (free(k, r0, r0 + q.w)) sides[k] = "right";
4791
+ else if (free(k, l1 - q.w, l1)) sides[k] = "left";
4792
+ else {
4793
+ sides[k] = "right";
4794
+ fails++;
4795
+ }
4796
+ });
4797
+ if (!best || fails < best.fails) best = {
4798
+ fails,
4799
+ ys,
4800
+ sides
4801
+ };
4802
+ if (!fails) break;
4803
+ }
4804
+ if (best) group.forEach((q, k) => lanes.set(q.e, {
4805
+ y: best.ys[k],
4806
+ side: best.sides[k]
4807
+ }));
4808
+ }
4379
4809
  const marks = [];
4810
+ let wide = 0;
4811
+ let least = 0;
4380
4812
  const runs = [];
4381
4813
  const segs = [];
4382
4814
  const arrows = [];
@@ -4395,6 +4827,9 @@ function LayerGraph(p) {
4395
4827
  let ty;
4396
4828
  let arrow;
4397
4829
  let inn = 1;
4830
+ let laneAt = null;
4831
+ let turnFrom = 0;
4832
+ let laneSide = "right";
4398
4833
  if (up) {
4399
4834
  const lx = laneX(e);
4400
4835
  const L = onLeft(e);
@@ -4482,27 +4917,21 @@ function LayerGraph(p) {
4482
4917
  });
4483
4918
  }
4484
4919
  } else {
4485
- const oi = outs[e.from].indexOf(e);
4486
- const on = outs[e.from].length;
4487
- const ii = ins[e.to].indexOf(e);
4488
4920
  inn = ins[e.to].length;
4489
- const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
4490
- const sy = a.y + NH;
4491
- tx = Math.round(b.x + NW * (ii + 1) / (inn + 1));
4492
- ty = b.y;
4493
- const off = (oi - (on - 1) / 2) * 6;
4494
- const y1 = sy + gaps[layerIndex[e.from]] / 2 + off;
4495
- if (layerIndex[e.to] - layerIndex[e.from] > 1) {
4496
- const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
4497
- const mid = (sx + tx) / 2;
4498
- 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)));
4499
- const chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
4500
- const y2 = ty - gaps[layerIndex[e.to] - 1] / 2 + off;
4921
+ const g = geomOf(e);
4922
+ const { sx, sy, skip } = g;
4923
+ tx = g.tx;
4924
+ ty = g.ty;
4925
+ const lane = lanes.get(e);
4926
+ const laneY = lane ? lane.y : null;
4927
+ const y1 = !skip && laneY != null ? laneY : g.y1;
4928
+ if (skip) {
4929
+ const y2 = laneY ?? ty - gaps[layerIndex[e.to] - 1] / 2 + g.off;
4501
4930
  pts = [
4502
4931
  [sx, sy],
4503
4932
  [sx, y1],
4504
- [chx, y1],
4505
- [chx, y2],
4933
+ [g.chx, y1],
4934
+ [g.chx, y2],
4506
4935
  [tx, y2],
4507
4936
  [tx, ty - 8]
4508
4937
  ];
@@ -4512,6 +4941,9 @@ function LayerGraph(p) {
4512
4941
  [tx, y1],
4513
4942
  [tx, ty - 8]
4514
4943
  ];
4944
+ turnFrom = g.from;
4945
+ laneAt = laneY;
4946
+ laneSide = lane?.side ?? "right";
4515
4947
  arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
4516
4948
  arrows.push([
4517
4949
  tx - 5,
@@ -4541,13 +4973,23 @@ function LayerGraph(p) {
4541
4973
  d,
4542
4974
  strokeWidth: w
4543
4975
  }, "p" + idx));
4976
+ if (!pickEdge && peek) hitPaths.push(/* @__PURE__ */ jsx("path", {
4977
+ className: "ui-lg-hit is-peek",
4978
+ d,
4979
+ onPointerEnter: () => setHover(edgeId(e)),
4980
+ onPointerLeave: () => setHover(null)
4981
+ }, "h" + idx));
4544
4982
  if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
4545
4983
  className: "ui-lg-hit",
4546
4984
  "data-edge": edgeId(e),
4547
4985
  d,
4548
4986
  role: "button",
4549
4987
  tabIndex: 0,
4550
- "aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
4988
+ "aria-label": tr("{from} → {to},{what}", {
4989
+ from: nameOf(e.from),
4990
+ to: nameOf(e.to),
4991
+ what: (e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")
4992
+ }),
4551
4993
  "aria-pressed": picked,
4552
4994
  onClick: (ev) => {
4553
4995
  ev.stopPropagation();
@@ -4555,6 +4997,8 @@ function LayerGraph(p) {
4555
4997
  },
4556
4998
  onPointerEnter: () => setHover(edgeId(e)),
4557
4999
  onPointerLeave: () => setHover(null),
5000
+ onFocus: peek ? () => setHover(edgeId(e)) : void 0,
5001
+ onBlur: peek ? () => setHover(null) : void 0,
4558
5002
  onKeyDown: (ev) => {
4559
5003
  if (ev.key === "Enter" || ev.key === " ") {
4560
5004
  ev.preventDefault();
@@ -4576,7 +5020,10 @@ function LayerGraph(p) {
4576
5020
  ty,
4577
5021
  left: inn > 1 && tx < b.x + NW / 2,
4578
5022
  r,
4579
- dim
5023
+ dim,
5024
+ lane: laneAt,
5025
+ from: turnFrom,
5026
+ side: laneSide
4580
5027
  });
4581
5028
  }
4582
5029
  });
@@ -4591,7 +5038,7 @@ function LayerGraph(p) {
4591
5038
  const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
4592
5039
  const labelEl = (m, x0, top, lines = [m.text]) => /* @__PURE__ */ jsx("span", {
4593
5040
  "aria-hidden": pickEdge ? true : void 0,
4594
- className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
5041
+ className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim", peek && !m.r && hover !== edgeId(m.e) && m.e !== selEdge && "is-quiet"),
4595
5042
  style: {
4596
5043
  left: x0,
4597
5044
  top
@@ -4639,9 +5086,11 @@ function LayerGraph(p) {
4639
5086
  const g = Math.max(0, Math.min(layers.length - 2, layers.findIndex((_, k) => k < layers.length - 1 && m.ty < rowTop(k + 1))));
4640
5087
  need.add(g);
4641
5088
  const x0 = x0Of(w);
5089
+ const top = find(x0, w, 16, false);
5090
+ if (top == null) crowd.add(g);
4642
5091
  spot = {
4643
5092
  x0,
4644
- top: find(x0, w, 16, false) ?? start0,
5093
+ top: top ?? start0,
4645
5094
  lw: w,
4646
5095
  lh: 16,
4647
5096
  lines: [m.text]
@@ -4658,6 +5107,7 @@ function LayerGraph(p) {
4658
5107
  return;
4659
5108
  }
4660
5109
  const g = layerIndex[m.e.to] - 1;
5110
+ const gapTop = g >= 0 ? rowTop(g) + NH : 0;
4661
5111
  const sideOf = (lw) => {
4662
5112
  let left = m.left;
4663
5113
  if (left && m.tx - 8 - lw < 0) left = false;
@@ -4670,7 +5120,24 @@ function LayerGraph(p) {
4670
5120
  return !hits(x0, x0 + lw, y0, y1) && !boxRects.some(over) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : over(sg.box));
4671
5121
  };
4672
5122
  let spot = null;
4673
- for (const lines of wraps(m.text)) {
5123
+ if (m.lane != null) {
5124
+ const lane = m.lane;
5125
+ for (const lines of wraps(m.text)) {
5126
+ if (spot) break;
5127
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
5128
+ const lh = lines.length * 16;
5129
+ const right = Math.max(m.tx, m.from ?? m.tx) + 8;
5130
+ const left = Math.min(m.tx, m.from ?? m.tx) - 8 - lw;
5131
+ for (const x0 of m.side === "left" ? [left, right] : [right, left]) if (!spot && clear(x0, lw, lane - lh / 2, lane + lh / 2)) spot = {
5132
+ x0,
5133
+ top: lane,
5134
+ lw,
5135
+ lh,
5136
+ lines
5137
+ };
5138
+ }
5139
+ }
5140
+ for (const lines of spot ? [] : wraps(m.text)) {
4674
5141
  const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
4675
5142
  const lh = lines.length * 16;
4676
5143
  const pref = sideOf(lw);
@@ -4679,7 +5146,7 @@ function LayerGraph(p) {
4679
5146
  if (x0 < 0 || x0 + lw > W) continue;
4680
5147
  for (let k = 0; k < 8 && !spot; k++) {
4681
5148
  const top = m.ty - 8 - lh / 2 - k * 18;
4682
- if (top - lh / 2 < 2) break;
5149
+ if (top - lh / 2 < Math.max(2, gapTop + 2)) break;
4683
5150
  if (clear(x0, lw, top - lh / 2, top + lh / 2)) spot = {
4684
5151
  x0,
4685
5152
  top,
@@ -4694,16 +5161,42 @@ function LayerGraph(p) {
4694
5161
  }
4695
5162
  if (!spot) {
4696
5163
  if (g >= 0) need.add(g);
4697
- const x0 = at(sideOf(w), w);
4698
- let top = m.ty - 16;
4699
- for (let k = 0; k < 8 && hits(x0, x0 + w, top - 8, top + 8); k++) top -= 18;
4700
- spot = {
4701
- x0,
4702
- top,
4703
- lw: w,
4704
- lh: 16,
4705
- lines: [m.text]
4706
- };
5164
+ 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
+ for (const lines of wraps(m.text)) {
5166
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
5167
+ const lh = lines.length * 16;
5168
+ const pref = sideOf(lw);
5169
+ for (const left of [pref, !pref]) {
5170
+ const x0 = at(left, lw);
5171
+ if (x0 < 0 || x0 + lw > W) continue;
5172
+ for (let k = 0; k < 8 && !spot; k++) {
5173
+ const top = m.ty - 8 - lh / 2 - k * 18;
5174
+ if (top - lh / 2 < Math.max(2, gapTop + 2)) break;
5175
+ if (offBoxes(x0, lw, top - lh / 2, top + lh / 2)) spot = {
5176
+ x0,
5177
+ top,
5178
+ lw,
5179
+ lh,
5180
+ lines
5181
+ };
5182
+ }
5183
+ if (spot) break;
5184
+ }
5185
+ if (spot) break;
5186
+ }
5187
+ if (!spot) {
5188
+ if (g >= 0) crowd.add(g);
5189
+ const x0 = at(sideOf(w), w);
5190
+ let top = m.ty - 16;
5191
+ for (let k = 0; k < 8 && hits(x0, x0 + w, top - 8, top + 8); k++) top -= 18;
5192
+ spot = {
5193
+ x0,
5194
+ top,
5195
+ lw: w,
5196
+ lh: 16,
5197
+ lines: [m.text]
5198
+ };
5199
+ }
4707
5200
  }
4708
5201
  placed.push([
4709
5202
  spot.x0,
@@ -4712,31 +5205,58 @@ function LayerGraph(p) {
4712
5205
  spot.top + spot.lh / 2,
4713
5206
  6
4714
5207
  ]);
5208
+ wide = Math.max(wide, spot.x0 + spot.lw + PAD / 2 + 4);
5209
+ least = Math.min(least, spot.x0 - PAD / 2 - 4);
4715
5210
  labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
4716
5211
  });
4717
5212
  return {
4718
5213
  paths,
4719
5214
  labels,
4720
5215
  hitPaths,
4721
- need
5216
+ need,
5217
+ crowd,
5218
+ wide,
5219
+ least
4722
5220
  };
4723
5221
  };
5222
+ for (const id in laneCount) {
5223
+ const g = layerIndex[id] - 1;
5224
+ if (g >= 0) gaps[g] = Math.max(gaps[g], laneCount[id] * LANE_H + 40);
5225
+ }
5226
+ const floor = gaps.slice();
4724
5227
  placeRows();
4725
5228
  let drawn = draw();
4726
- const grows = () => [...drawn.need].filter((g) => gaps[g] < 200);
5229
+ const grows = () => [...drawn.need].filter((g) => gaps[g] < floor[g] + GROW_MAX);
4727
5230
  for (let k = 0; k < GROW_MAX / GROW && grows().length; k++) {
4728
- for (const g of grows()) gaps[g] = Math.min(200, gaps[g] + GROW);
5231
+ for (const g of grows()) gaps[g] = Math.min(floor[g] + GROW_MAX, gaps[g] + GROW);
4729
5232
  placeRows();
4730
5233
  drawn = draw();
4731
5234
  }
4732
- const stuck = [...drawn.need].filter((g) => gaps[g] >= 200);
5235
+ const stuck = [...drawn.need].filter((g) => gaps[g] >= floor[g] + GROW_MAX);
4733
5236
  if (stuck.length) {
4734
- for (const g of stuck) gaps[g] = GAP;
5237
+ for (const g of stuck) gaps[g] = floor[g];
4735
5238
  placeRows();
4736
5239
  drawn = draw();
5240
+ const crowded = () => [...drawn.crowd].filter((g) => stuck.includes(g) && gaps[g] < floor[g] + GROW_MAX);
5241
+ for (let k = 0; k < GROW_MAX / GROW && crowded().length; k++) {
5242
+ for (const g of crowded()) gaps[g] = Math.min(floor[g] + GROW_MAX, gaps[g] + GROW);
5243
+ placeRows();
5244
+ drawn = draw();
5245
+ }
5246
+ }
5247
+ for (let k = 0; k < 3 && drawn.least < 0; k++) {
5248
+ const shift = Math.ceil(-drawn.least);
5249
+ for (const id in pos) pos[id].x += shift;
5250
+ W += shift;
5251
+ drawn = draw();
5252
+ }
5253
+ if (drawn.wide > W) {
5254
+ W = Math.ceil(drawn.wide);
5255
+ drawn = draw();
4737
5256
  }
4738
5257
  const { paths, labels, hitPaths } = drawn;
4739
5258
  const sizeText = p.sizeLabel ?? tr("{n} 個項目");
5259
+ const externalText = p.externalLabel ?? tr("repo 外");
4740
5260
  const useText = p.useLabel ?? tr("使用 {n} 次");
4741
5261
  const nodes = main.map((n) => {
4742
5262
  const q = pos[n.id];
@@ -4745,7 +5265,7 @@ function LayerGraph(p) {
4745
5265
  const used = selShared ? uses[selShared]?.[n.id] : void 0;
4746
5266
  return /* @__PURE__ */ jsxs("button", {
4747
5267
  type: "button",
4748
- className: cx("ui-lg-node", on && "is-selected", !near(n.id) && "is-dim"),
5268
+ className: cx("ui-lg-node", n.external && "is-external", on && "is-selected", !near(n.id) && "is-dim"),
4749
5269
  style: {
4750
5270
  left: q.x,
4751
5271
  top: q.y,
@@ -4754,26 +5274,33 @@ function LayerGraph(p) {
4754
5274
  },
4755
5275
  "aria-pressed": p.onSelect ? on : void 0,
4756
5276
  onClick: p.onSelect ? () => pick(n.id, on) : void 0,
4757
- children: [/* @__PURE__ */ jsxs("span", {
4758
- className: "ui-lg-head",
4759
- children: [/* @__PURE__ */ jsx("span", {
4760
- className: "ui-lg-name",
4761
- children: n.name || n.id
4762
- }), used ? /* @__PURE__ */ jsx("span", {
4763
- className: "ui-lg-use",
4764
- children: monoNums(useText.replace("{n}", ""), [used])
4765
- }) : null]
4766
- }), size != null ? /* @__PURE__ */ jsxs("span", {
4767
- className: "ui-lg-size",
4768
- children: [/* @__PURE__ */ jsx("span", {
4769
- className: "ui-lg-track",
4770
- "aria-hidden": "true",
4771
- children: /* @__PURE__ */ jsx("span", { style: { width: Math.round(size / maxSize * 100) + "%" } })
4772
- }), /* @__PURE__ */ jsx("span", {
4773
- className: "ui-lg-count",
4774
- children: monoNums(sizeText.replace("{n}", ""), [size])
4775
- })]
4776
- }) : null]
5277
+ children: [
5278
+ /* @__PURE__ */ jsxs("span", {
5279
+ className: "ui-lg-head",
5280
+ children: [/* @__PURE__ */ jsx("span", {
5281
+ className: "ui-lg-name",
5282
+ children: n.name || n.id
5283
+ }), used ? /* @__PURE__ */ jsx("span", {
5284
+ className: "ui-lg-use",
5285
+ children: monoNums(useText.replace("{n}", ""), [used])
5286
+ }) : null]
5287
+ }),
5288
+ n.external ? /* @__PURE__ */ jsx("span", {
5289
+ className: "ui-lg-ext",
5290
+ children: externalText
5291
+ }) : null,
5292
+ size != null ? /* @__PURE__ */ jsxs("span", {
5293
+ className: "ui-lg-size",
5294
+ children: [/* @__PURE__ */ jsx("span", {
5295
+ className: "ui-lg-track",
5296
+ "aria-hidden": "true",
5297
+ children: /* @__PURE__ */ jsx("span", { style: { width: Math.round(size / maxSize * 100) + "%" } })
5298
+ }), /* @__PURE__ */ jsx("span", {
5299
+ className: "ui-lg-count",
5300
+ children: monoNums(sizeText.replace("{n}", ""), [size])
5301
+ })]
5302
+ }) : null
5303
+ ]
4777
5304
  }, n.id);
4778
5305
  });
4779
5306
  const sharedMeta = p.sharedMeta ?? tr("{a} 個項目使用,共 {b} 次");
@@ -4781,7 +5308,7 @@ function LayerGraph(p) {
4781
5308
  const by = uses[s.id] ?? {};
4782
5309
  const total = Object.values(by).reduce((a, b) => a + b, 0);
4783
5310
  const on = s.id === sel;
4784
- const dim = !!selEdge || sel != null && !on && (selShared != null || !(sel in by));
5311
+ const dim = !!selEdge || sel != null && !on && (selShared != null ? !(s.id in (uses[selShared] ?? {})) && !(selShared in by) : !(sel in by));
4785
5312
  return /* @__PURE__ */ jsxs("button", {
4786
5313
  type: "button",
4787
5314
  className: cx("ui-lg-node", "ui-lg-chip", on && "is-selected", dim && "is-dim"),
@@ -4796,7 +5323,10 @@ function LayerGraph(p) {
4796
5323
  })]
4797
5324
  }, s.id);
4798
5325
  });
4799
- const edgeText = (e) => e.inferred ? e.label ? `${e.label}(${p.inferredLabel || tr("推測")})` : p.inferredLabel || tr("推測") : countText(e);
5326
+ const edgeText = (e) => e.inferred ? e.label ? tr("{label}({inferred})", {
5327
+ label: e.label,
5328
+ inferred: p.inferredLabel || tr("推測")
5329
+ }) : p.inferredLabel || tr("推測") : countText(e);
4800
5330
  const listItem = (key, on, dim, onClick, head, rest) => /* @__PURE__ */ jsxs("li", {
4801
5331
  className: cx("ui-lg-li", dim && "is-dim"),
4802
5332
  children: [onClick ? /* @__PURE__ */ jsx("button", {
@@ -4824,9 +5354,12 @@ function LayerGraph(p) {
4824
5354
  return listItem(n.id, n.id === sel, !near(n.id), p.onSelect ? () => pick(n.id, n.id === sel) : void 0, /* @__PURE__ */ jsx("span", {
4825
5355
  className: "ui-lg-code",
4826
5356
  children: n.name || n.id
4827
- }), size != null ? /* @__PURE__ */ jsxs("span", {
5357
+ }), n.external && !n.shared ? /* @__PURE__ */ jsxs("span", {
5358
+ className: "ui-lg-limeta",
5359
+ children: [tr(","), externalText]
5360
+ }) : size != null ? /* @__PURE__ */ jsxs("span", {
4828
5361
  className: "ui-lg-limeta",
4829
- children: [",", monoNums(sizeText.replace("{n}", ""), [size])]
5362
+ children: [tr(","), monoNums(sizeText.replace("{n}", ""), [size])]
4830
5363
  }) : null);
4831
5364
  }) })]
4832
5365
  }), /* @__PURE__ */ jsxs("section", {
@@ -4847,17 +5380,63 @@ function LayerGraph(p) {
4847
5380
  })
4848
5381
  ] }), /* @__PURE__ */ jsxs("span", {
4849
5382
  className: "ui-lg-limeta",
4850
- children: [":", labelParts(edgeText(e))]
5383
+ children: [tr(":"), labelParts(edgeText(e))]
4851
5384
  }))) })]
4852
5385
  })]
4853
5386
  });
4854
5387
  const showList = p.listView !== false && view === "list";
5388
+ const toggleShown = p.labelToggle !== false && !showList && p.edges.some((e) => e.inferred);
5389
+ React.useLayoutEffect(() => {
5390
+ const el = scrollRef.current;
5391
+ if (!el) return;
5392
+ const measure = () => setAvail(el.clientWidth);
5393
+ measure();
5394
+ const ro = new ResizeObserver(measure);
5395
+ ro.observe(el);
5396
+ return () => ro.disconnect();
5397
+ }, [scrollRef, showList]);
5398
+ React.useLayoutEffect(() => {
5399
+ if (!avail || showList) return;
5400
+ if (!fitted) {
5401
+ if (W <= avail + .5) return;
5402
+ const base = p.nodeWidth || 200;
5403
+ const lose = W - avail - (cols - 1) * 16;
5404
+ const nw = Math.max(Math.min(base, 120), Math.floor(base - Math.max(0, lose) / cols));
5405
+ setFit({
5406
+ at: avail,
5407
+ nw,
5408
+ col: 24,
5409
+ scale: 1
5410
+ });
5411
+ return;
5412
+ }
5413
+ if (fitted.scale !== 1 || W <= avail + .5) return;
5414
+ const s = avail / W;
5415
+ if (s >= .75) setFit({
5416
+ ...fitted,
5417
+ scale: Math.floor(s * 1e3) / 1e3
5418
+ });
5419
+ }, [
5420
+ avail,
5421
+ showList,
5422
+ fitted,
5423
+ W,
5424
+ p.nodeWidth,
5425
+ cols
5426
+ ]);
4855
5427
  return /* @__PURE__ */ jsxs("div", {
4856
5428
  className: cx("ui-graph ui-lg", p.className),
4857
5429
  children: [
4858
- p.listView === false ? null : /* @__PURE__ */ jsx("div", {
5430
+ p.listView === false && !toggleShown ? null : /* @__PURE__ */ jsxs("div", {
4859
5431
  className: "ui-lg-bar",
4860
- children: /* @__PURE__ */ jsx(Tabs, {
5432
+ children: [toggleShown ? /* @__PURE__ */ jsx(IconButton, {
5433
+ className: "ui-lg-labels-btn",
5434
+ icon: "tag",
5435
+ filled: labelsOn,
5436
+ label: tr("顯示線上文字"),
5437
+ "aria-pressed": labelsOn,
5438
+ onClick: switchLabels
5439
+ }) : null, p.listView === false ? null : /* @__PURE__ */ jsx(Tabs, {
4861
5440
  label: tr("顯示方式"),
4862
5441
  value: view,
4863
5442
  onChange: setView,
@@ -4868,7 +5447,7 @@ function LayerGraph(p) {
4868
5447
  id: "list",
4869
5448
  label: tr("清單")
4870
5449
  }]
4871
- })
5450
+ })]
4872
5451
  }),
4873
5452
  showList ? list : null,
4874
5453
  /* @__PURE__ */ jsx("div", {
@@ -4879,9 +5458,17 @@ function LayerGraph(p) {
4879
5458
  onScroll: onScrollKeep,
4880
5459
  children: /* @__PURE__ */ jsxs("div", {
4881
5460
  className: "ui-lg-canvas",
4882
- style: {
5461
+ style: scale === 1 ? {
4883
5462
  width: W,
4884
5463
  height: H
5464
+ } : {
5465
+ width: W,
5466
+ height: H,
5467
+ transform: `scale(${scale})`,
5468
+ transformOrigin: "0 0",
5469
+ marginRight: W * (scale - 1),
5470
+ marginBottom: H * (scale - 1),
5471
+ "--lg-scale": scale
4885
5472
  },
4886
5473
  role: "group",
4887
5474
  "aria-label": p.label || tr("架構圖"),
@@ -4896,7 +5483,14 @@ function LayerGraph(p) {
4896
5483
  }),
4897
5484
  nodes,
4898
5485
  labels,
4899
- hitPaths.length ? /* @__PURE__ */ jsx("svg", {
5486
+ hitPaths.length && !pickEdge ? /* @__PURE__ */ jsx("svg", {
5487
+ className: "ui-lg-hits",
5488
+ width: W,
5489
+ height: H,
5490
+ viewBox: `0 0 ${W} ${H}`,
5491
+ "aria-hidden": "true",
5492
+ children: hitPaths
5493
+ }) : hitPaths.length ? /* @__PURE__ */ jsx("svg", {
4900
5494
  className: "ui-lg-hits",
4901
5495
  width: W,
4902
5496
  height: H,
@@ -5556,6 +6150,7 @@ function RadioGroup({ label, value, onChange, options, disabled, className }) {
5556
6150
  className: cx("ui-radio", on && "is-on"),
5557
6151
  onClick: () => onChange?.(o.value),
5558
6152
  onKeyDown: (e) => {
6153
+ if (browserKey(e)) return;
5559
6154
  if (e.key === "ArrowDown" || e.key === "ArrowRight") {
5560
6155
  e.preventDefault();
5561
6156
  move(i, 1);
@@ -5924,9 +6519,15 @@ function TextArea({ label, hint, value, onChange, maxLength = 200, className, id
5924
6519
  children: [/* @__PURE__ */ jsx("span", {
5925
6520
  className: "ui-field-hint",
5926
6521
  children: hint || ""
5927
- }), /* @__PURE__ */ jsx("span", {
6522
+ }), /* @__PURE__ */ jsxs("span", {
5928
6523
  className: "ui-count",
5929
- children: `${(value || "").length} / ${maxLength}`
6524
+ children: [/* @__PURE__ */ jsx("span", {
6525
+ "aria-hidden": "true",
6526
+ children: format.fraction((value || "").length, maxLength)
6527
+ }), /* @__PURE__ */ jsx("span", {
6528
+ className: "ui-visually-hidden",
6529
+ children: format.fractionLabel((value || "").length, maxLength, tr("字"))
6530
+ })]
5930
6531
  })]
5931
6532
  })
5932
6533
  ]
@@ -6028,9 +6629,10 @@ function bounds(target) {
6028
6629
  bottom
6029
6630
  };
6030
6631
  }
6031
- /** Where the card goes for a highlighted box: the preferred side, the other side, or inside the box at the bottom
6032
- * center of the window when neither side has room. Returns the anchor line the card is placed against. */
6033
- function placeCard(rect, cardH, prefer, area) {
6632
+ /** Where the card goes for a highlighted box: the preferred side, the other one, then right or left of the box; inside
6633
+ * the box at the bottom only when none has room (the tour scrolls first to make room above or below, see makeRoom).
6634
+ * Returns the anchor line the card is placed against. */
6635
+ function placeCard(rect, cardH, prefer, area, cardW = 320) {
6034
6636
  const margin = typeof document === "undefined" ? 12 : edge();
6035
6637
  const vh = area?.bottom ?? (typeof window === "undefined" ? 0 : window.innerHeight);
6036
6638
  const vt = area?.top ?? 0;
@@ -6056,6 +6658,16 @@ function placeCard(rect, cardH, prefer, area) {
6056
6658
  margin,
6057
6659
  line: rect
6058
6660
  };
6661
+ const vw = typeof window === "undefined" ? 0 : window.innerWidth;
6662
+ const tallOk = cardH + 2 * margin <= vh - vt;
6663
+ const beside = ["right", "left"].find((sd) => tallOk && (sd === "right" ? rect.left + rect.width + GAP + cardW + margin <= vw : rect.left - GAP - cardW - margin >= 0));
6664
+ if (beside) return {
6665
+ mode: beside,
6666
+ side: beside,
6667
+ offset: GAP,
6668
+ margin,
6669
+ line: rect
6670
+ };
6059
6671
  const end = rect.top + rect.height;
6060
6672
  const bottom = Math.max(vt + margin + cardH, end >= vh - margin ? vh - margin : end - margin);
6061
6673
  return {
@@ -6079,6 +6691,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6079
6691
  const [rect, setRect] = React.useState(null);
6080
6692
  const next = React.useRef(null);
6081
6693
  const [cardH, setCardH] = React.useState(0);
6694
+ const [cardW, setCardW] = React.useState(320);
6082
6695
  const [wasOpen, setWasOpen] = React.useState(open);
6083
6696
  if (open !== wasOpen) {
6084
6697
  setWasOpen(open);
@@ -6090,6 +6703,43 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6090
6703
  };
6091
6704
  const end = (why) => onClose?.(why);
6092
6705
  useReturnFocus(open);
6706
+ const shownStep = React.useRef(-1);
6707
+ React.useEffect(() => {
6708
+ if (!open || !step) {
6709
+ shownStep.current = -1;
6710
+ return;
6711
+ }
6712
+ if (shownStep.current !== -1 && shownStep.current !== i) announce(tr("第 {a} 步,共 {b} 步", {
6713
+ a: i + 1,
6714
+ b: steps.length
6715
+ }) + tr("。") + step.title + tr("。") + step.text.replace(/`/g, ""));
6716
+ shownStep.current = i;
6717
+ }, [
6718
+ open,
6719
+ i,
6720
+ step,
6721
+ steps.length
6722
+ ]);
6723
+ const cardEl = React.useRef(null);
6724
+ const tabbables = () => Array.from(cardEl.current?.querySelectorAll("button:not(:disabled), a[href], input:not(:disabled), [tabindex]:not([tabindex=\"-1\"])") ?? []).filter((e) => e.getClientRects().length > 0);
6725
+ const onTab = (e) => {
6726
+ if (e.key !== "Tab" || e.altKey || e.ctrlKey || e.metaKey) return;
6727
+ const list = tabbables();
6728
+ if (!list.length) return;
6729
+ e.preventDefault();
6730
+ const at = list.indexOf(document.activeElement);
6731
+ list[at < 0 ? 0 : (at + (e.shiftKey ? -1 : 1) + list.length) % list.length].focus();
6732
+ };
6733
+ React.useEffect(() => {
6734
+ if (!open) return;
6735
+ const back = (e) => {
6736
+ const box = cardEl.current;
6737
+ if (!box || !(e.target instanceof Node) || box.contains(e.target)) return;
6738
+ (next.current ?? tabbables()[0])?.focus();
6739
+ };
6740
+ document.addEventListener("focusin", back);
6741
+ return () => document.removeEventListener("focusin", back);
6742
+ }, [open]);
6093
6743
  const target = step?.target;
6094
6744
  const pad = step?.padding ?? 6;
6095
6745
  const hasStep = !!step;
@@ -6143,16 +6793,52 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6143
6793
  ]);
6144
6794
  const observer = React.useRef(null);
6145
6795
  const card = React.useCallback((el) => {
6796
+ cardEl.current = el;
6146
6797
  observer.current?.disconnect();
6147
6798
  observer.current = null;
6148
6799
  if (!el) return;
6149
- const measure = () => setCardH(el.offsetHeight);
6800
+ const measure = () => {
6801
+ setCardH(el.offsetHeight);
6802
+ setCardW(el.offsetWidth);
6803
+ };
6150
6804
  measure();
6151
6805
  observer.current = new ResizeObserver(measure);
6152
6806
  observer.current.observe(el);
6153
6807
  }, []);
6808
+ const measured = cardH > 0;
6809
+ React.useEffect(() => {
6810
+ if (!open || !hasStep || !measured) return;
6811
+ const el = findTarget(target);
6812
+ if (!(el instanceof HTMLElement)) return;
6813
+ const ar = bounds(el);
6814
+ const m = edge();
6815
+ const r = el.getBoundingClientRect();
6816
+ const top = r.top - pad;
6817
+ const bottom = r.bottom + pad;
6818
+ if (bottom + GAP + cardH + m <= ar.bottom || top - GAP - cardH - m >= ar.top) return;
6819
+ const want = bottom - top + GAP + cardH + 2 * m <= ar.bottom - ar.top ? ar.top + m + pad : ar.top + m + cardH + GAP + pad;
6820
+ let box = el.parentElement;
6821
+ while (box && !(/(auto|scroll)/.test(getComputedStyle(box).overflowY) && box.scrollHeight > box.clientHeight)) box = box.parentElement;
6822
+ const dy = r.top - want;
6823
+ if (box) box.scrollBy({
6824
+ top: dy,
6825
+ behavior: "auto"
6826
+ });
6827
+ else window.scrollBy({
6828
+ top: dy,
6829
+ behavior: "auto"
6830
+ });
6831
+ }, [
6832
+ open,
6833
+ hasStep,
6834
+ i,
6835
+ target,
6836
+ pad,
6837
+ measured,
6838
+ cardH
6839
+ ]);
6154
6840
  const area = open && step ? bounds(findTarget(step.target)) : void 0;
6155
- const place = placeCard(rect, cardH, step?.side ?? "bottom", area);
6841
+ const place = placeCard(rect, cardH, step?.side ?? "bottom", area, cardW);
6156
6842
  const line = place.line;
6157
6843
  const anchor = React.useMemo(() => ({ getBoundingClientRect: () => line ? new DOMRect(line.left, line.top, line.width, line.height) : new DOMRect(window.innerWidth / 2, window.innerHeight / 2, 0, 0) }), [
6158
6844
  line?.left,
@@ -6192,6 +6878,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
6192
6878
  className: "ui-tour-card",
6193
6879
  "data-placement": place.mode,
6194
6880
  initialFocus: next,
6881
+ onKeyDown: onTab,
6195
6882
  children: [/* @__PURE__ */ jsxs("div", {
6196
6883
  className: "ui-tour-body",
6197
6884
  children: [
@@ -6504,7 +7191,7 @@ function TreeList(p) {
6504
7191
  setFocusId(rows[j].n.id);
6505
7192
  };
6506
7193
  const onKey = (e) => {
6507
- if (e.target.getAttribute("role") !== "treeitem" || !rows.length) return;
7194
+ if (e.target.getAttribute("role") !== "treeitem" || !rows.length || browserKey(e)) return;
6508
7195
  const r = rows[cur];
6509
7196
  const k = e.key;
6510
7197
  if (!([
@@ -6531,8 +7218,10 @@ function TreeList(p) {
6531
7218
  break;
6532
7219
  }
6533
7220
  } else if (k === "Enter") {
6534
- if (plain) p.onSelect?.(r.n);
6535
- else if (r.isF) toggle(r.n);
7221
+ if (plain) {
7222
+ p.onSelect?.(r.n);
7223
+ if (r.isF) toggle(r.n);
7224
+ } else if (r.isF) toggle(r.n);
6536
7225
  else openFile(r.n);
6537
7226
  } else checkToggle(r.n);
6538
7227
  };
@@ -6556,17 +7245,18 @@ function TreeList(p) {
6556
7245
  const meta = n.meta ?? (n.path ? format.path(n.path) : "");
6557
7246
  return /* @__PURE__ */ jsxs("div", {
6558
7247
  ...itemProps(r, idx),
6559
- "aria-label": [
7248
+ "aria-label": n.ariaLabel ?? [
6560
7249
  n.name,
7250
+ ...(n.tags ?? []).map(nodeText),
6561
7251
  n.meta,
6562
7252
  n.path
6563
- ].filter(Boolean).join(","),
7253
+ ].filter(Boolean).join(tr(",")),
6564
7254
  "aria-selected": p.onSelect ? on : void 0,
6565
7255
  className: cx("ui-tree-row", "is-plain", on && "is-current", n.muted && "is-muted", r.fresh && "ui-tree-in"),
6566
7256
  onClick: () => {
6567
7257
  setFocusId(n.id);
6568
- if (p.onSelect) p.onSelect(n);
6569
- else if (isF) toggle(n);
7258
+ p.onSelect?.(n);
7259
+ if (isF) toggle(n);
6570
7260
  },
6571
7261
  children: [
6572
7262
  /* @__PURE__ */ jsx(Guides, { guides: r.guides }),
@@ -6674,6 +7364,7 @@ function TreeList(p) {
6674
7364
  const bits = (isF ? [fl.length ? tr("{n} 個檔案", { n: fl.length }) : "", dateTxt] : [dateTxt, sizeTxt]).filter(Boolean);
6675
7365
  return /* @__PURE__ */ jsxs("div", {
6676
7366
  ...itemProps(r, idx),
7367
+ "aria-label": n.ariaLabel,
6677
7368
  "aria-selected": selectable ? ck === true : void 0,
6678
7369
  className: cx("ui-tree-row", isF && "is-folder", ck === true && "is-selected", r.fresh && "ui-tree-in"),
6679
7370
  onClick: () => {
@@ -6880,6 +7571,6 @@ function TreeList(p) {
6880
7571
  })]
6881
7572
  });
6882
7573
  }
6883
- export { AccentPicker, ActionBar, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, addMessages, announce, focusMain, format, icons, initTheme, isCodeRef, setAccent, setLocale, setTheme, tr as t, useTour };
7574
+ export { AccentPicker, ActionBar, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, addMessages, announce, focusMain, format, icons, initTheme, isCodeRef, setAccent, setLocale, setTheme, tr as t, useTour };
6884
7575
 
6885
7576
  //# sourceMappingURL=index.js.map