@seanyeh77/ui 0.4.0 → 0.5.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-B1gAZnIN.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-BWjH_kB_.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";
@@ -576,29 +576,32 @@ function Breadcrumb({ items, className }) {
576
576
  }
577
577
  // src/components/Tooltip/Tooltip.tsx
578
578
  /** Dark label above the element (below when there is no room), with an arrow. Appears at once on hover and focus. */
579
- function Tooltip({ label, side = "top", describe = true, children }) {
579
+ function Tooltip({ label, side = "top", describe = true, wrap = false, disabled = false, children }) {
580
580
  const id = React.useId();
581
- return /* @__PURE__ */ jsxs(Tooltip$1.Root, { children: [
582
- /* @__PURE__ */ jsx(Tooltip$1.Trigger, {
583
- delay: 0,
584
- render: children,
585
- "aria-describedby": describe ? id : void 0
586
- }),
587
- describe ? /* @__PURE__ */ jsx("span", {
588
- id,
589
- hidden: true,
590
- children: label
591
- }) : null,
592
- /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
593
- side,
594
- sideOffset: 8,
595
- className: "ui-tooltip-positioner",
596
- children: /* @__PURE__ */ jsxs(Tooltip$1.Popup, {
597
- className: "ui-tooltip",
598
- children: [label, /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "ui-tooltip-arrow" })]
599
- })
600
- }) })
601
- ] });
581
+ return /* @__PURE__ */ jsxs(Tooltip$1.Root, {
582
+ disabled,
583
+ children: [
584
+ /* @__PURE__ */ jsx(Tooltip$1.Trigger, {
585
+ delay: 0,
586
+ render: children,
587
+ "aria-describedby": describe && !disabled ? id : void 0
588
+ }),
589
+ describe && !disabled ? /* @__PURE__ */ jsx("span", {
590
+ id,
591
+ hidden: true,
592
+ children: label
593
+ }) : null,
594
+ /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
595
+ side,
596
+ sideOffset: 8,
597
+ className: "ui-tooltip-positioner",
598
+ children: /* @__PURE__ */ jsxs(Tooltip$1.Popup, {
599
+ className: wrap ? "ui-tooltip is-wrap" : "ui-tooltip",
600
+ children: [label, /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "ui-tooltip-arrow" })]
601
+ })
602
+ }) })
603
+ ]
604
+ });
602
605
  }
603
606
  // src/components/IconButton/IconButton.tsx
604
607
  /** A square icon-only button with a tooltip. */
@@ -1768,8 +1771,9 @@ function languageOf(file) {
1768
1771
  const m = /\.([A-Za-z0-9]+)$/.exec(file || "");
1769
1772
  return m && EXT[m[1].toLowerCase()] || "plain";
1770
1773
  }
1774
+ /** Header labels. A bare 「C」 reads like a button, so C is 「C 語言」. */
1771
1775
  const LANGUAGE_NAMES = {
1772
- c: "C",
1776
+ c: "C 語言",
1773
1777
  js: "JavaScript",
1774
1778
  py: "Python",
1775
1779
  sh: "Shell"
@@ -1876,9 +1880,12 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
1876
1880
  }) : /* @__PURE__ */ jsx("span", {
1877
1881
  className: "ui-cv-title",
1878
1882
  children: title
1879
- }), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsx("span", {
1883
+ }), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsxs("span", {
1880
1884
  className: "ui-cv-lang",
1881
- children: languageLabel || LANGUAGE_NAMES[lang] || lang
1885
+ children: [/* @__PURE__ */ jsxs("span", {
1886
+ className: "ui-visually-hidden",
1887
+ children: [tr("程式語言"), ":"]
1888
+ }), tr(languageLabel || LANGUAGE_NAMES[lang] || lang)]
1882
1889
  }) : null]
1883
1890
  }) : null;
1884
1891
  return /* @__PURE__ */ jsxs("div", {
@@ -2161,12 +2168,13 @@ function SearchField({ value, onChange, className, label, ...native }) {
2161
2168
  }
2162
2169
  // src/components/Tabs/Tabs.tsx
2163
2170
  /** Views of the same content. The underline moves like a droplet; arrow keys move between tabs. */
2164
- function Tabs({ items, value, onChange, label, className }) {
2171
+ function Tabs({ items, value, onChange, label, unit, className }) {
2165
2172
  const refs = React.useRef([]);
2166
2173
  const track = React.useRef(null);
2167
2174
  const [box, setBox] = React.useState(null);
2168
2175
  const [forward, setForward] = React.useState(true);
2169
2176
  const [moving, bump] = useMoving();
2177
+ devWarn(items.some((t) => t.count != null && !(t.unit || unit)), "Tabs", "a count has no unit, so it reads as a bare number. Pass unit, e.g. unit: '筆', on Tabs or on the item.");
2170
2178
  const idx = Math.max(0, items.findIndex((t) => t.id === value));
2171
2179
  React.useLayoutEffect(() => {
2172
2180
  const el = refs.current[idx];
@@ -2219,13 +2227,64 @@ function Tabs({ items, value, onChange, label, className }) {
2219
2227
  refs.current[to]?.focus();
2220
2228
  go(to);
2221
2229
  },
2222
- children: [t.label, t.count != null ? /* @__PURE__ */ jsx("span", {
2230
+ children: [t.label, t.count != null ? /* @__PURE__ */ jsxs("span", {
2223
2231
  className: "ui-tab-count",
2224
- children: format.number(t.count)
2232
+ children: [format.number(t.count), t.unit || unit ? /* @__PURE__ */ jsxs("span", {
2233
+ className: "ui-unit",
2234
+ children: [" ", tr(t.unit || unit || "")]
2235
+ }) : null]
2225
2236
  }) : null]
2226
2237
  }, t.id))]
2227
2238
  });
2228
2239
  }
2240
+ // src/internal/scrollHint.tsx
2241
+ /** A box that may be wider than its container: whether it overflows, whether more is to the right, and whether the
2242
+ * person has scrolled yet. Used by LayerGraph and DataTable for the right-edge fade and the 「左右滑動」 hint. */
2243
+ function useScrollHint() {
2244
+ const ref = React.useRef(null);
2245
+ const [more, setMore] = React.useState(false);
2246
+ const [scrolled, setScrolled] = React.useState(false);
2247
+ const [overflows, setOverflows] = React.useState(false);
2248
+ const measure = React.useCallback(() => {
2249
+ const el = ref.current;
2250
+ if (!el) return;
2251
+ const wide = el.scrollWidth > el.clientWidth + 1;
2252
+ setOverflows(wide);
2253
+ setMore(wide && el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
2254
+ }, []);
2255
+ React.useLayoutEffect(() => {
2256
+ const el = ref.current;
2257
+ if (!el) return;
2258
+ measure();
2259
+ const ro = new ResizeObserver(measure);
2260
+ ro.observe(el);
2261
+ if (el.firstElementChild) ro.observe(el.firstElementChild);
2262
+ return () => ro.disconnect();
2263
+ }, [measure]);
2264
+ return {
2265
+ ref,
2266
+ more,
2267
+ overflows,
2268
+ scrolled,
2269
+ onScroll: React.useCallback(() => {
2270
+ const el = ref.current;
2271
+ if (el && el.scrollLeft > 0) setScrolled(true);
2272
+ measure();
2273
+ }, [measure]),
2274
+ measure
2275
+ };
2276
+ }
2277
+ /** 「→ 左右滑動」 under the box, right-aligned. Hidden after the first sideways scroll but keeps its line, so nothing below jumps. */
2278
+ function ScrollHint({ show, done }) {
2279
+ return show ? /* @__PURE__ */ jsxs("span", {
2280
+ className: cx("ui-scroll-hint", done && "is-done"),
2281
+ "aria-hidden": "true",
2282
+ children: [/* @__PURE__ */ jsx(Icon, {
2283
+ name: "arrow-right",
2284
+ size: 14
2285
+ }), tr("左右滑動")]
2286
+ }) : null;
2287
+ }
2229
2288
  // src/components/DataTable/filters.ts
2230
2289
  const field = (row, key) => row[key];
2231
2290
  /** Cell text: money as NT$ 1,280, dates as 2026/11/04(三), numbers with their unit after them. */
@@ -2528,26 +2587,41 @@ function FilterButton({ filters, values, activeCount, count, onChange, onClear }
2528
2587
  })]
2529
2588
  });
2530
2589
  }
2531
- /** Long text in a cell: on phone cards at most 2 lines with 「顯示全部」. */
2590
+ /** Long text in a cell. Phone cards: at most 2 lines with 「顯示全部」. Desktop: one line; when it is cut off, hover or
2591
+ * focus shows the whole text in a Tooltip. */
2532
2592
  function LongText({ children }) {
2593
+ const box = React.useRef(null);
2533
2594
  const ref = React.useRef(null);
2595
+ const narrow = useNarrow();
2534
2596
  const [open, setOpen] = React.useState(false);
2535
2597
  const [over, setOver] = React.useState(false);
2598
+ const [cut, setCut] = React.useState("");
2536
2599
  React.useLayoutEffect(() => {
2537
2600
  const el = ref.current;
2538
- if (!el || open) return;
2539
- const check = () => setOver(el.scrollHeight > el.clientHeight + 1);
2601
+ const outer = box.current;
2602
+ if (!el || !outer || open) return;
2603
+ const check = () => {
2604
+ setOver(el.scrollHeight > el.clientHeight + 1);
2605
+ setCut(!narrow && outer.scrollWidth > outer.clientWidth + 1 ? outer.textContent ?? "" : "");
2606
+ };
2540
2607
  check();
2541
- window.addEventListener("resize", check);
2542
- return () => window.removeEventListener("resize", check);
2543
- }, [open, children]);
2544
- return /* @__PURE__ */ jsxs("span", {
2545
- className: "ui-dt-long",
2608
+ const ro = new ResizeObserver(check);
2609
+ ro.observe(outer);
2610
+ return () => ro.disconnect();
2611
+ }, [
2612
+ open,
2613
+ children,
2614
+ narrow
2615
+ ]);
2616
+ const body = /* @__PURE__ */ jsxs("span", {
2617
+ ref: box,
2618
+ className: cx("ui-dt-long", !!cut && "is-cut"),
2619
+ tabIndex: cut ? 0 : void 0,
2546
2620
  children: [/* @__PURE__ */ jsx("span", {
2547
2621
  ref,
2548
2622
  className: cx("ui-dt-long-text", !open && "is-clamped"),
2549
2623
  children
2550
- }), over || open ? /* @__PURE__ */ jsx("button", {
2624
+ }), narrow && (over || open) ? /* @__PURE__ */ jsx("button", {
2551
2625
  type: "button",
2552
2626
  className: "ui-dt-more",
2553
2627
  onClick: (e) => {
@@ -2557,6 +2631,12 @@ function LongText({ children }) {
2557
2631
  children: open ? tr("收合") : tr("顯示全部")
2558
2632
  }) : null]
2559
2633
  });
2634
+ return /* @__PURE__ */ jsx(Tooltip, {
2635
+ label: cut,
2636
+ wrap: true,
2637
+ disabled: !cut,
2638
+ children: body
2639
+ });
2560
2640
  }
2561
2641
  // src/components/DataTable/DataTable.tsx
2562
2642
  const MOVE = {
@@ -2638,6 +2718,7 @@ function DataTable(p) {
2638
2718
  devWarn(cols.some((c) => c.format === "percent" && !c.unit), "DataTable", "format: 'percent' sets 1 decimal and shows no % sign; add unit: '%' to that column.");
2639
2719
  devWarn(rows.length > 1 && rows.every((r) => get(r, "id") == null) && selectable, "DataTable", "rows have no id, so a selection follows the position, not the row. Add an id to each row.");
2640
2720
  const shownCols = cols.filter((c, i) => i === 0 || !hidden[c.key]);
2721
+ const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
2641
2722
  const bodyRef = React.useRef(null);
2642
2723
  const rowEls = React.useRef({});
2643
2724
  const snap = React.useRef(null);
@@ -2949,9 +3030,12 @@ function DataTable(p) {
2949
3030
  setView(v.id);
2950
3031
  setPage(0);
2951
3032
  },
2952
- children: [v.label, /* @__PURE__ */ jsx("span", {
3033
+ children: [v.label, /* @__PURE__ */ jsxs("span", {
2953
3034
  className: "ui-dt-view-n",
2954
- children: format.number(rows.filter((r) => !v.filter || v.filter(r)).length)
3035
+ children: [format.number(rows.filter((r) => !v.filter || v.filter(r)).length), /* @__PURE__ */ jsxs("span", {
3036
+ className: "ui-unit",
3037
+ children: [" ", tr("筆")]
3038
+ })]
2955
3039
  })]
2956
3040
  }, v.id);
2957
3041
  })
@@ -2959,6 +3043,7 @@ function DataTable(p) {
2959
3043
  summary ? /* @__PURE__ */ jsx(Tabs, {
2960
3044
  className: "ui-dt-summary",
2961
3045
  label: summary.label || tr("依狀態篩選"),
3046
+ unit: summary.unit || "筆",
2962
3047
  value: sumVal,
2963
3048
  onChange: (v) => {
2964
3049
  capture("sort");
@@ -3023,85 +3108,94 @@ function DataTable(p) {
3023
3108
  ]
3024
3109
  }),
3025
3110
  /* @__PURE__ */ jsx("div", {
3026
- className: "ui-dt-scroll",
3027
- children: /* @__PURE__ */ jsxs("div", {
3028
- className: "ui-dt-table",
3029
- role: "table",
3030
- "aria-label": p.label || p.caption,
3031
- children: [
3032
- head,
3033
- /* @__PURE__ */ jsx("div", {
3034
- ref: bodyRef,
3035
- className: "ui-dt-body",
3036
- role: "rowgroup",
3037
- children: vis.length ? vis.map((x, i) => {
3038
- const id = visIds[i];
3039
- const on = !!sel[id];
3040
- return /* @__PURE__ */ jsxs("div", {
3041
- "data-rid": id,
3042
- ref: (el) => {
3043
- rowEls.current[id] = el;
3044
- },
3045
- role: "row",
3046
- className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
3047
- style: gridStyle,
3048
- children: [
3049
- selectable ? /* @__PURE__ */ jsx("div", {
3050
- className: "ui-dt-cell ui-dt-sel",
3051
- role: "cell",
3052
- children: /* @__PURE__ */ jsx(RowCheck, {
3053
- v: on,
3054
- label: tr("選取第 {n} 筆", { n: start + i + 1 }),
3055
- onClick: () => toggle([id], !on)
3056
- })
3057
- }) : null,
3058
- shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3059
- role: "cell",
3060
- "data-label": c.label,
3061
- className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
3062
- style: stickyStyle(ci),
3063
- children: cell(x.r, c)
3064
- }, c.key)),
3065
- hasAct ? /* @__PURE__ */ jsx("div", {
3066
- className: "ui-dt-cell ui-dt-acts",
3067
- role: "cell",
3068
- children: p.rowActions?.(x.r)
3069
- }) : null
3070
- ]
3071
- }, id);
3072
- }) : /* @__PURE__ */ jsxs("div", {
3073
- className: "ui-dt-empty",
3074
- children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
3075
- onClick: clearFilters,
3076
- children: tr("清除篩選")
3077
- }) }) : null]
3078
- })
3079
- }),
3080
- p.totals && list.length ? /* @__PURE__ */ jsxs("div", {
3081
- className: "ui-dt-row ui-dt-total",
3082
- role: "row",
3083
- style: gridStyle,
3084
- children: [
3085
- selectable ? /* @__PURE__ */ jsx("div", {
3086
- className: "ui-dt-cell",
3087
- role: "cell"
3088
- }) : null,
3089
- shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3090
- role: "cell",
3091
- className: cellClass(c, ci),
3092
- style: stickyStyle(ci),
3093
- children: total(c, ci)
3094
- }, c.key)),
3095
- hasAct ? /* @__PURE__ */ jsx("div", {
3096
- className: "ui-dt-cell",
3097
- role: "cell"
3098
- }) : null
3099
- ]
3100
- }) : null
3101
- ]
3111
+ className: cx("ui-dt-scroller", scrollMore && "has-more"),
3112
+ children: /* @__PURE__ */ jsx("div", {
3113
+ className: "ui-dt-scroll",
3114
+ ref: scrollRef,
3115
+ onScroll,
3116
+ children: /* @__PURE__ */ jsxs("div", {
3117
+ className: "ui-dt-table",
3118
+ role: "table",
3119
+ "aria-label": p.label || p.caption,
3120
+ children: [
3121
+ head,
3122
+ /* @__PURE__ */ jsx("div", {
3123
+ ref: bodyRef,
3124
+ className: "ui-dt-body",
3125
+ role: "rowgroup",
3126
+ children: vis.length ? vis.map((x, i) => {
3127
+ const id = visIds[i];
3128
+ const on = !!sel[id];
3129
+ return /* @__PURE__ */ jsxs("div", {
3130
+ "data-rid": id,
3131
+ ref: (el) => {
3132
+ rowEls.current[id] = el;
3133
+ },
3134
+ role: "row",
3135
+ className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
3136
+ style: gridStyle,
3137
+ children: [
3138
+ selectable ? /* @__PURE__ */ jsx("div", {
3139
+ className: "ui-dt-cell ui-dt-sel",
3140
+ role: "cell",
3141
+ children: /* @__PURE__ */ jsx(RowCheck, {
3142
+ v: on,
3143
+ label: tr("選取第 {n} 筆", { n: start + i + 1 }),
3144
+ onClick: () => toggle([id], !on)
3145
+ })
3146
+ }) : null,
3147
+ shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3148
+ role: "cell",
3149
+ "data-label": c.label,
3150
+ className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
3151
+ style: stickyStyle(ci),
3152
+ children: cell(x.r, c)
3153
+ }, c.key)),
3154
+ hasAct ? /* @__PURE__ */ jsx("div", {
3155
+ className: "ui-dt-cell ui-dt-acts",
3156
+ role: "cell",
3157
+ children: p.rowActions?.(x.r)
3158
+ }) : null
3159
+ ]
3160
+ }, id);
3161
+ }) : /* @__PURE__ */ jsxs("div", {
3162
+ className: "ui-dt-empty",
3163
+ children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
3164
+ onClick: clearFilters,
3165
+ children: tr("清除篩選")
3166
+ }) }) : null]
3167
+ })
3168
+ }),
3169
+ p.totals && list.length ? /* @__PURE__ */ jsxs("div", {
3170
+ className: "ui-dt-row ui-dt-total",
3171
+ role: "row",
3172
+ style: gridStyle,
3173
+ children: [
3174
+ selectable ? /* @__PURE__ */ jsx("div", {
3175
+ className: "ui-dt-cell",
3176
+ role: "cell"
3177
+ }) : null,
3178
+ shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3179
+ role: "cell",
3180
+ className: cellClass(c, ci),
3181
+ style: stickyStyle(ci),
3182
+ children: total(c, ci)
3183
+ }, c.key)),
3184
+ hasAct ? /* @__PURE__ */ jsx("div", {
3185
+ className: "ui-dt-cell",
3186
+ role: "cell"
3187
+ }) : null
3188
+ ]
3189
+ }) : null
3190
+ ]
3191
+ })
3102
3192
  })
3103
3193
  }),
3104
- list.length > 0 ? /* @__PURE__ */ jsxs("div", {
3194
+ /* @__PURE__ */ jsx(ScrollHint, {
3195
+ show: overflows,
3196
+ done: scrolled
3197
+ }),
3198
+ pages > 1 ? /* @__PURE__ */ jsxs("div", {
3105
3199
  className: "ui-dt-foot",
3106
3200
  children: [/* @__PURE__ */ jsx("span", {
3107
3201
  className: "ui-dt-range",
@@ -3114,7 +3208,7 @@ function DataTable(p) {
3114
3208
  Math.min(list.length, start + pageSize),
3115
3209
  format.number(list.length)
3116
3210
  ])
3117
- }), pages > 1 ? /* @__PURE__ */ jsxs("nav", {
3211
+ }), /* @__PURE__ */ jsxs("nav", {
3118
3212
  className: "ui-dt-pages",
3119
3213
  "aria-label": tr("分頁"),
3120
3214
  children: [
@@ -3142,7 +3236,7 @@ function DataTable(p) {
3142
3236
  children: "›"
3143
3237
  })
3144
3238
  ]
3145
- }) : null]
3239
+ })]
3146
3240
  }) : null
3147
3241
  ]
3148
3242
  });
@@ -3885,10 +3979,18 @@ function LayerGraph(p) {
3885
3979
  const edgeId = (e) => e.id ?? `${e.from}->${e.to}`;
3886
3980
  const pickEdge = p.onSelectEdge;
3887
3981
  const [hover, setHover] = React.useState(null);
3982
+ const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
3888
3983
  const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
3889
- const related = (e) => selEdge ? e === selEdge : !!sel && (e.from === sel || e.to === sel);
3984
+ const uses = {};
3985
+ 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);
3986
+ const selShared = !selEdge && sel != null && sharedIds.has(sel) ? sel : null;
3987
+ const related = (e) => selEdge ? e === selEdge : !!sel && !selShared && (e.from === sel || e.to === sel);
3890
3988
  const focus = !!sel || !!selEdge;
3891
- const near = (id) => selEdge ? id === selEdge.from || id === selEdge.to : !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
3989
+ const near = (id) => selEdge ? id === selEdge.from || id === selEdge.to : selShared ? id === selShared || id in (uses[selShared] ?? {}) : !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
3990
+ const pick = (id, on) => {
3991
+ if (!on && p.selectedEdge != null) pickEdge?.(null);
3992
+ p.onSelect?.(on ? null : id);
3993
+ };
3892
3994
  const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
3893
3995
  const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
3894
3996
  const choose = (e) => {
@@ -3940,10 +4042,11 @@ function LayerGraph(p) {
3940
4042
  const r = related(e);
3941
4043
  const dim = focus && !r;
3942
4044
  const picked = e === selEdge;
3943
- const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0);
4045
+ const hovered = !!pickEdge && hover === edgeId(e) && !r;
4046
+ const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
3944
4047
  const d = route(clean(pts), 10);
3945
4048
  paths.push(/* @__PURE__ */ jsx("path", {
3946
- className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", pickEdge && hover === edgeId(e) && "is-hover"),
4049
+ className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
3947
4050
  d,
3948
4051
  strokeWidth: w
3949
4052
  }, "p" + idx));
@@ -3953,7 +4056,7 @@ function LayerGraph(p) {
3953
4056
  d,
3954
4057
  role: "button",
3955
4058
  tabIndex: 0,
3956
- "aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)}`,
4059
+ "aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
3957
4060
  "aria-pressed": picked,
3958
4061
  onClick: (ev) => {
3959
4062
  ev.stopPropagation();
@@ -4011,7 +4114,7 @@ function LayerGraph(p) {
4011
4114
  6
4012
4115
  ]);
4013
4116
  labels.push(/* @__PURE__ */ jsx("span", {
4014
- className: cx("ui-lg-label", pickEdge && "is-clickable", m.r && "is-related", m.dim && "is-dim"),
4117
+ className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
4015
4118
  style: {
4016
4119
  left: x0,
4017
4120
  top
@@ -4026,10 +4129,12 @@ function LayerGraph(p) {
4026
4129
  }, "l" + m.idx));
4027
4130
  });
4028
4131
  const sizeText = p.sizeLabel ?? tr("{n} 個項目");
4132
+ const useText = p.useLabel ?? tr("使用 {n} 次");
4029
4133
  const nodes = main.map((n) => {
4030
4134
  const q = pos[n.id];
4031
4135
  const on = n.id === sel;
4032
4136
  const size = sizeOf(n);
4137
+ const used = selShared ? uses[selShared]?.[n.id] : void 0;
4033
4138
  return /* @__PURE__ */ jsxs("button", {
4034
4139
  type: "button",
4035
4140
  className: cx("ui-lg-node", on && "is-selected", !near(n.id) && "is-dim"),
@@ -4040,13 +4145,16 @@ function LayerGraph(p) {
4040
4145
  height: NH
4041
4146
  },
4042
4147
  "aria-pressed": p.onSelect ? on : void 0,
4043
- onClick: p.onSelect ? () => {
4044
- if (!on && p.selectedEdge != null) pickEdge?.(null);
4045
- p.onSelect?.(on ? null : n.id);
4046
- } : void 0,
4047
- children: [/* @__PURE__ */ jsx("span", {
4048
- className: "ui-lg-name",
4049
- children: n.name || n.id
4148
+ onClick: p.onSelect ? () => pick(n.id, on) : void 0,
4149
+ children: [/* @__PURE__ */ jsxs("span", {
4150
+ className: "ui-lg-head",
4151
+ children: [/* @__PURE__ */ jsx("span", {
4152
+ className: "ui-lg-name",
4153
+ children: n.name || n.id
4154
+ }), used ? /* @__PURE__ */ jsx("span", {
4155
+ className: "ui-lg-use",
4156
+ children: monoNums(useText.replace("{n}", ""), [used])
4157
+ }) : null]
4050
4158
  }), size != null ? /* @__PURE__ */ jsxs("span", {
4051
4159
  className: "ui-lg-size",
4052
4160
  children: [/* @__PURE__ */ jsx("span", {
@@ -4061,21 +4169,22 @@ function LayerGraph(p) {
4061
4169
  }, n.id);
4062
4170
  });
4063
4171
  const sharedMeta = p.sharedMeta ?? tr("{a} 個項目使用,共 {b} 次");
4064
- const sharedRows = shared.map((s) => {
4065
- const callers = /* @__PURE__ */ new Set();
4066
- let total = 0;
4067
- for (const e of p.edges) if (e.to === s.id && !sharedIds.has(e.from)) {
4068
- callers.add(e.from);
4069
- total += e.count || 0;
4070
- }
4071
- return /* @__PURE__ */ jsxs("div", {
4072
- className: "ui-lg-shared-row",
4172
+ const sharedBoxes = shared.map((s) => {
4173
+ const by = uses[s.id] ?? {};
4174
+ const total = Object.values(by).reduce((a, b) => a + b, 0);
4175
+ const on = s.id === sel;
4176
+ const dim = !!selEdge || sel != null && !on && (selShared != null || !(sel in by));
4177
+ return /* @__PURE__ */ jsxs("button", {
4178
+ type: "button",
4179
+ className: cx("ui-lg-node", "ui-lg-chip", on && "is-selected", dim && "is-dim"),
4180
+ "aria-pressed": p.onSelect ? on : void 0,
4181
+ onClick: p.onSelect ? () => pick(s.id, on) : void 0,
4073
4182
  children: [/* @__PURE__ */ jsx("span", {
4074
4183
  className: "ui-lg-name",
4075
4184
  children: s.name || s.id
4076
4185
  }), /* @__PURE__ */ jsx("span", {
4077
4186
  className: "ui-lg-shared-meta",
4078
- children: monoNums(sharedMeta.replace("{a}", "").replace("{b}", ""), [callers.size, total])
4187
+ children: monoNums(sharedMeta.replace("{a}", "").replace("{b}", ""), [Object.keys(by).length, total])
4079
4188
  })]
4080
4189
  }, s.id);
4081
4190
  });
@@ -4083,51 +4192,63 @@ function LayerGraph(p) {
4083
4192
  className: cx("ui-graph ui-lg", p.className),
4084
4193
  children: [
4085
4194
  /* @__PURE__ */ jsx("div", {
4086
- className: "ui-lg-scroll",
4087
- children: /* @__PURE__ */ jsxs("div", {
4088
- className: "ui-lg-canvas",
4089
- style: {
4090
- width: W,
4091
- height: H
4092
- },
4093
- role: "group",
4094
- "aria-label": p.label || tr("架構圖"),
4095
- onClick: pickEdge && p.selectedEdge != null ? () => pickEdge(null) : void 0,
4096
- children: [
4097
- /* @__PURE__ */ jsx("svg", {
4098
- width: W,
4099
- height: H,
4100
- viewBox: `0 0 ${W} ${H}`,
4101
- "aria-hidden": "true",
4102
- children: paths
4103
- }),
4104
- nodes,
4105
- labels,
4106
- hitPaths.length ? /* @__PURE__ */ jsx("svg", {
4107
- className: "ui-lg-hits",
4195
+ className: cx("ui-lg-scroller", scrollMore && "has-more"),
4196
+ children: /* @__PURE__ */ jsx("div", {
4197
+ className: "ui-lg-scroll",
4198
+ ref: scrollRef,
4199
+ onScroll,
4200
+ children: /* @__PURE__ */ jsxs("div", {
4201
+ className: "ui-lg-canvas",
4202
+ style: {
4108
4203
  width: W,
4109
- height: H,
4110
- viewBox: `0 0 ${W} ${H}`,
4111
- children: hitPaths
4112
- }) : null
4113
- ]
4204
+ height: H
4205
+ },
4206
+ role: "group",
4207
+ "aria-label": p.label || tr("架構圖"),
4208
+ onClick: pickEdge && p.selectedEdge != null ? () => pickEdge(null) : void 0,
4209
+ children: [
4210
+ /* @__PURE__ */ jsx("svg", {
4211
+ width: W,
4212
+ height: H,
4213
+ viewBox: `0 0 ${W} ${H}`,
4214
+ "aria-hidden": "true",
4215
+ children: paths
4216
+ }),
4217
+ nodes,
4218
+ labels,
4219
+ hitPaths.length ? /* @__PURE__ */ jsx("svg", {
4220
+ className: "ui-lg-hits",
4221
+ width: W,
4222
+ height: H,
4223
+ viewBox: `0 0 ${W} ${H}`,
4224
+ children: hitPaths
4225
+ }) : null
4226
+ ]
4227
+ })
4114
4228
  })
4115
4229
  }),
4230
+ /* @__PURE__ */ jsx(ScrollHint, {
4231
+ show: overflows,
4232
+ done: scrolled
4233
+ }),
4116
4234
  shared.length ? /* @__PURE__ */ jsxs("div", {
4117
4235
  className: "ui-lg-shared",
4118
4236
  children: [/* @__PURE__ */ jsx("div", {
4119
4237
  className: "ui-lg-shared-title",
4120
4238
  children: p.sharedLabel || tr("共用項目")
4121
- }), sharedRows]
4239
+ }), /* @__PURE__ */ jsx("div", {
4240
+ className: "ui-lg-chips",
4241
+ children: sharedBoxes
4242
+ })]
4122
4243
  }) : null,
4123
- p.legend === false ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [{
4244
+ p.legend === false || !p.legendItems && !edges.some((e) => pos[e.from] && pos[e.to]) ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [...edges.some((e) => !e.inferred && pos[e.from] && pos[e.to]) ? [{
4124
4245
  type: "weight",
4125
4246
  label: "次數越多線越粗"
4126
- }, {
4247
+ }] : [], ...edges.some((e) => e.inferred && pos[e.from] && pos[e.to]) ? [{
4127
4248
  type: "inferred",
4128
4249
  label: p.inferredLabel || "推測的關係",
4129
4250
  text: p.inferredText
4130
- }] })
4251
+ }] : []] })
4131
4252
  ]
4132
4253
  });
4133
4254
  }
@@ -5248,7 +5369,6 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5248
5369
  const step = steps[i];
5249
5370
  const [rect, setRect] = React.useState(null);
5250
5371
  const next = React.useRef(null);
5251
- const card = React.useRef(null);
5252
5372
  const [cardH, setCardH] = React.useState(0);
5253
5373
  const [wasOpen, setWasOpen] = React.useState(open);
5254
5374
  if (open !== wasOpen) {
@@ -5303,15 +5423,16 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5303
5423
  target,
5304
5424
  pad
5305
5425
  ]);
5306
- React.useLayoutEffect(() => {
5307
- const el = card.current;
5308
- if (!open || !el) return;
5426
+ const observer = React.useRef(null);
5427
+ const card = React.useCallback((el) => {
5428
+ observer.current?.disconnect();
5429
+ observer.current = null;
5430
+ if (!el) return;
5309
5431
  const measure = () => setCardH(el.offsetHeight);
5310
5432
  measure();
5311
- const ro = new ResizeObserver(measure);
5312
- ro.observe(el);
5313
- return () => ro.disconnect();
5314
- }, [open, i]);
5433
+ observer.current = new ResizeObserver(measure);
5434
+ observer.current.observe(el);
5435
+ }, []);
5315
5436
  const place = placeCard(rect, cardH, step?.side ?? "bottom");
5316
5437
  const line = place.line;
5317
5438
  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) }), [