@seanyeh77/ui 0.3.0 → 0.4.1

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.
@@ -43,6 +43,7 @@ const I18N = {
43
43
  "日期格式不正確,請寫成 2026/11/14": "Invalid date. Use 2026/11/14.",
44
44
  更多操作: "More actions",
45
45
  更多: "More",
46
+ 左右滑動: "Scroll sideways",
46
47
  全部頁面: "All pages",
47
48
  "最近 30 天": "Last 30 days",
48
49
  "最近 7 天": "Last 7 days",
@@ -397,4 +398,4 @@ const sameDay = (a, b) => !!a && !!b && a.getFullYear() === b.getFullYear() && a
397
398
  const dayAdd = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
398
399
  export { parseDate as a, addMessages as c, format as i, setLocale as l, fileSize as n, sameDay as o, fmtDate as r, I18N as s, dayAdd as t, tr as u };
399
400
 
400
- //# sourceMappingURL=format-entry-B1gAZnIN.js.map
401
+ //# sourceMappingURL=format-entry-DDglckmU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-entry-DDglckmU.js","names":[],"sources":["../src/i18n.ts","../src/format.ts"],"sourcesContent":["/* ---------- i18n and formats ----------\n Every built-in string is the zh-TW text passed through tr(); other languages come from UI.addMessages().\n Dates and numbers go through UI.format, which uses Intl for the current locale. The zh-TW rules are the\n ones the design system chose; other locales use their own conventions from Intl. */\ninterface I18nState {\n locale: string;\n currency: string;\n messages: Record<string, Record<string, string>>;\n}\n\nexport const I18N: I18nState = {\n locale: 'zh-TW',\n currency: 'TWD',\n messages: {\n en: {\n 'Email 或帳號': 'Email or username',\n '{label}:{a} 到 {b}': '{label}: {a} to {b}',\n '{n} 個百分點': '{n} pts',\n 上一頁: 'Previous page',\n 上個月: 'Previous month',\n '上傳失敗,請再試一次。': 'Upload failed. Try again.',\n 下一頁: 'Next page',\n 下個月: 'Next month',\n 主要導覽: 'Main navigation',\n 主題: 'Theme',\n 今天: 'Today',\n 全選: 'Select all',\n 全部: 'All',\n 全部標為已讀: 'Mark all as read',\n '共 {n} 筆': '{n} items',\n 分頁: 'Pagination',\n 刪除: 'Delete',\n 危險操作: 'Danger zone',\n 取消選取: 'Clear selection',\n '可以直接輸入,例如 2026/11/14': 'Type a date, e.g. 2026/11/14',\n 回上一頁: 'Go back',\n 回首頁: 'Go home',\n '完成 ✓': 'Done ✓',\n 密碼: 'Password',\n 展開側邊欄: 'Expand sidebar',\n '已選 {n} 筆': '{n} selected',\n 帳號: 'Username',\n 強調色: 'Accent color',\n '忘記密碼?': 'Forgot password?',\n 找不到符合的選項: 'No matching options',\n '拖放檔案,或 ': 'Drop files here, or ',\n 搜尋: 'Search',\n 操作: 'Actions',\n 收合側邊欄: 'Collapse sidebar',\n 放棄: 'Discard',\n '放棄未儲存的變更?': 'Discard unsaved changes?',\n '新增「{q}」': 'Add “{q}”',\n '日期格式不正確,請寫成 2026/11/14': 'Invalid date. Use 2026/11/14.',\n 更多操作: 'More actions',\n 更多: 'More',\n 左右滑動: 'Scroll sideways',\n 全部頁面: 'All pages',\n '最近 30 天': 'Last 30 days',\n '最近 7 天': 'Last 7 days',\n 期間: 'Period',\n 未讀: 'Unread',\n 本月: 'This month',\n 沒有符合的資料: 'No matching data',\n 沒有通知: 'No notifications',\n 清除: 'Clear',\n 清除搜尋: 'Clear search',\n 登入: 'Sign in',\n 發生錯誤: 'Something went wrong',\n '移除 {name}': 'Remove {name}',\n '第 {a}–{b} 筆,共 {n} 筆': '{a}–{b} of {n}',\n 繼續編輯: 'Keep editing',\n '自訂強調色(色碼)': 'Custom accent color (hex)',\n '色碼格式不正確,例如 #2457d6': 'Invalid hex, e.g. #2457d6',\n 設定分類: 'Settings sections',\n 請輸入密碼: 'Enter your password',\n 請輸入帳號: 'Enter your username',\n 請選擇: 'Select',\n 路徑: 'Breadcrumb',\n 較上週: 'vs last week',\n 載入中: 'Loading',\n '輸入 # 加 6 碼': 'Enter # and 6 digits',\n 通知: 'Notifications',\n '通知,{n} 則未讀': 'Notifications, {n} unread',\n '選取第 {n} 筆': 'Select row {n}',\n 選擇日期: 'Choose date',\n 選擇期間: 'Choose period',\n 選擇檔案: 'choose files',\n 重試: 'Retry',\n 開啟日曆: 'Open calendar',\n 關閉: 'Close',\n '關閉後,剛才的修改不會保留。': 'If you close now, your changes will be lost.',\n 關閉提示: 'Dismiss',\n 隱藏密碼: 'Hide password',\n 顯示密碼: 'Show password',\n '(今天)': ' (today)',\n 伺服器暫時無法回應: 'The server is not responding',\n 找不到這個頁面: 'Page not found',\n 沒有權限查看這個頁面: 'You do not have access to this page',\n '網址可能打錯了,或這個頁面已經移除。': 'The address may be wrong, or the page has been removed.',\n '這個問題已經記錄下來,請稍後重新整理再試。': 'The problem has been logged. Refresh the page later.',\n '請向管理員申請權限,或切換成有權限的帳號。': 'Ask an admin for access, or switch to an account that has it.',\n 自動: 'Auto',\n 淺色: 'Light',\n 深色: 'Dark',\n 藍: 'Blue',\n 靛: 'Indigo',\n 紫: 'Purple',\n 桃紅: 'Pink',\n 紅: 'Red',\n 橘: 'Orange',\n 綠: 'Green',\n 青: 'Teal',\n 草稿: 'Draft',\n 進行中: 'In progress',\n 審核中: 'In review',\n 完成: 'Done',\n 失敗: 'Failed',\n 檢視: 'Views',\n '{n} / {total} 筆': '{n} / {total}',\n 欄位: 'Columns',\n 顯示的欄位: 'Visible columns',\n 清除篩選: 'Clear filters',\n 清除全部: 'Clear all',\n 篩選: 'Filter',\n 最低: 'Min',\n 最高: 'Max',\n '合計 {n} 筆': 'Total: {n}',\n 平均: 'Avg',\n '選取 {name}': 'Select {name}',\n '{n} 個新': '{n} new',\n '{n} 個檔案': '{n} files',\n '下載 {name}': 'Download {name}',\n '已選 {n} 個檔案': '{n} files selected',\n '共 {size}': '{size} total',\n 清除選取: 'Clear selection',\n 下載: 'Download',\n 全部展開: 'Expand all',\n 全部收合: 'Collapse all',\n 這裡還沒有檔案: 'No files here yet',\n 顯示全部: 'Show all',\n 收合: 'Show less',\n 依狀態篩選: 'Filter by status',\n 展開: 'Expand',\n 沒有項目: 'Nothing here',\n 即時: 'Live',\n 已過期: 'Stale',\n 離線: 'Offline',\n 切換專案: 'Switch project',\n '切換專案,目前是 {name}': 'Switch project, now {name}',\n 推測: 'Inferred',\n '{n} 個項目': '{n} items',\n '{a} 個項目使用,共 {b} 次': 'Used {b} times by {a} items',\n 共用項目: 'Shared',\n 次數越多線越粗: 'Thicker lines mean more often',\n 架構圖: 'Architecture',\n '{n} 次': '{n} calls',\n 原始碼: 'Source',\n '顯示全部 {n} 行': 'Show all {n} lines',\n '只顯示第 {n} 行前後': 'Show only around line {n}',\n '無法載入 {name} 的子項目': 'Could not load the children of {name}',\n '找不到符合「{q}」的結果': 'No results for “{q}”',\n 輸入名稱開始搜尋: 'Type a name to search',\n 搜尋中: 'Searching',\n 搜尋結果: 'Search results',\n 最近開啟: 'Recently opened',\n 選擇: 'Select',\n 打開: 'Open',\n 取消: 'Cancel',\n 略過: 'Skip',\n 上一步: 'Back',\n 下一步: 'Next',\n 建議修正: 'Suggested fix',\n 複製修正: 'Copy fix',\n 已複製: 'Copied',\n '原本:': 'Before: ',\n '改成:': 'After: ',\n 關閉說明: 'Close explanation',\n '(說明)': ' (explain)',\n '搜尋({k})': 'Search ({k})',\n 確定的關係: 'Confirmed',\n 推測的關係: 'Inferred',\n 外部項目: 'External',\n },\n },\n};\n\nfunction msgsFor(loc: string): Record<string, string> | null {\n return I18N.messages[loc] || I18N.messages[loc.split('-')[0]] || null;\n}\n\n/** Translates a built-in zh-TW string into the current locale; {name} placeholders take vars. */\nexport function tr(key: string, vars?: Record<string, string | number>): string {\n const m = I18N.locale.startsWith('zh') ? null : msgsFor(I18N.locale);\n const out = m?.[key] ?? key;\n return vars ? out.replace(/\\{(\\w+)\\}/g, (a, k: string) => (vars[k] !== undefined ? String(vars[k]) : a)) : out;\n}\n\n/** Switches the interface language and, optionally, the currency used by format.money. */\nexport function setLocale(locale: string, opts?: { currency?: string }): void {\n I18N.locale = locale || 'zh-TW';\n if (opts?.currency) I18N.currency = opts.currency;\n if (typeof document !== 'undefined') document.documentElement.setAttribute('lang', I18N.locale);\n}\n\n/** Adds or overrides translations for a locale. Keys are the zh-TW strings. */\nexport function addMessages(locale: string, dict: Record<string, string>): void {\n I18N.messages[locale] = { ...I18N.messages[locale], ...dict };\n}\n\nexport const isZhTW = (): boolean => /^zh-(TW|Hant)/i.test(I18N.locale);\n","import { I18N, isZhTW } from './i18n';\n\n/* Dates and numbers for the current locale (setLocale). zh-TW follows the design system's rules\n (2026/11/04(三), 24-hour clock, NT$ 1,280, 萬 and 億 in KPI cards); other locales use Intl's conventions. */\n\nexport type Decimals = number | 'money' | 'percent' | 'size' | 'count';\n\nconst DECIMALS = { money: 0, percent: 1, size: 1, count: 0 } as const;\n\nconst pad2 = (n: number): string => String(n).padStart(2, '0');\n\nfunction locale(): string {\n return I18N.locale;\n}\n\n/** zh-TW: 2026/11/04(三). Other locales: their short date with weekday. */\nfunction date(d: Date | null | undefined, o: { weekday?: boolean; long?: boolean } = {}): string {\n if (!d) return '';\n const wd = o.weekday !== false;\n if (o.long) return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long', day: 'numeric', weekday: wd ? 'long' : undefined }).format(d);\n if (isZhTW()) return fmtDate(d) + (wd ? `(${new Intl.DateTimeFormat('zh-TW', { weekday: 'narrow' }).format(d)})` : '');\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: '2-digit', day: '2-digit', weekday: wd ? 'short' : undefined }).format(d);\n}\n\n/** zh-TW: 24-hour 15:57. Other locales: their own clock. */\nfunction time(d: Date | null | undefined): string {\n if (!d) return '';\n return new Intl.DateTimeFormat(\n I18N.locale,\n isZhTW() ? { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' } : { hour: 'numeric', minute: '2-digit' },\n ).format(d);\n}\n\nfunction dateTime(d: Date | null | undefined, o?: { weekday?: boolean }): string {\n return d ? `${date(d, o)} ${time(d)}` : '';\n}\n\n/** Within 7 days: 「2 小時前」、「昨天」. Older: full date and time. Pass now to test. */\nfunction relative(d: Date | null | undefined, now: Date = new Date()): string {\n if (!d) return '';\n const s = (now.getTime() - d.getTime()) / 1000;\n if (s < 0 || s >= 604800) return dateTime(d);\n const rt = new Intl.RelativeTimeFormat(I18N.locale, { numeric: 'auto' });\n if (s < 60) return rt.format(0, 'second');\n if (s < 3600) return rt.format(-Math.floor(s / 60), 'minute');\n if (s < 86400) return rt.format(-Math.floor(s / 3600), 'hour');\n return rt.format(-Math.floor(s / 86400), 'day');\n}\n\nfunction month(d: Date): string {\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long' }).format(d);\n}\n\n/** Week starts on Sunday for zh-TW; other locales use Intl's week info when the browser has it. */\nfunction firstDay(): number {\n if (isZhTW()) return 0;\n try {\n const l = new Intl.Locale(I18N.locale) as Intl.Locale & { getWeekInfo?: () => { firstDay: number }; weekInfo?: { firstDay: number } };\n const w = l.getWeekInfo ? l.getWeekInfo() : l.weekInfo;\n if (w?.firstDay) return w.firstDay % 7;\n } catch {\n /* older browsers have no week info */\n }\n return 0;\n}\n\n/** Narrow weekday names, starting from firstDay(). */\nfunction weekdays(): string[] {\n const fd = firstDay();\n const f = new Intl.DateTimeFormat(I18N.locale, { weekday: 'narrow' });\n // 2026/11/01 is a Sunday.\n return Array.from({ length: 7 }, (_, i) => f.format(new Date(2026, 10, 1 + ((fd + i) % 7))));\n}\n\n/** Decimals by unit: money 0, percent 1, size 1, count 0; pass a number to force it. */\nfunction number(v: number, dec?: Decimals): string {\n const dd = typeof dec === 'number' ? dec : dec ? DECIMALS[dec] : 0;\n return new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dd, maximumFractionDigits: dd }).format(v);\n}\n\nfunction percent(v: number, dec = 1): string {\n return new Intl.NumberFormat(I18N.locale, { style: 'percent', minimumFractionDigits: dec, maximumFractionDigits: dec }).format(v / 100);\n}\n\n/** Only KPI cards abbreviate: 1,284 萬 in zh-TW (萬、億), 12.8M in English.\n * like: format v with the unit and decimals that `like` gets, so a counting KPI keeps its width. */\nfunction compact(v: number, like?: number): string {\n const ref = like ?? v;\n if (Math.abs(ref) < 1e4) return number(v);\n if (/^zh/i.test(I18N.locale)) {\n const a = Math.abs(ref);\n const [unit, div, maxDec] = a >= 1e8 ? (['億', 1e8, 2] as const) : (['萬', 1e4, 1] as const);\n const finalStr = new Intl.NumberFormat(I18N.locale, { maximumFractionDigits: maxDec }).format(a / div);\n const sign = v < 0 ? '-' : '';\n if (like === undefined) return `${sign}${finalStr} ${unit}`;\n const digits = (finalStr.split('.')[1] || '').length;\n return `${sign}${new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: digits, maximumFractionDigits: digits }).format(Math.abs(v) / div)} ${unit}`;\n }\n const nf = new Intl.NumberFormat(I18N.locale, { notation: 'compact', maximumFractionDigits: 1 });\n if (like === undefined) return nf.format(v);\n const parts = nf.formatToParts(ref);\n let num = '';\n let dec = '';\n for (const pt of parts) {\n if (pt.type === 'integer') num += pt.value;\n if (pt.type === 'fraction') {\n num += '.' + pt.value;\n dec = pt.value;\n }\n }\n const mant = parseFloat(num) || 1;\n const scale = 10 ** Math.round(Math.log10(Math.abs(ref) / mant));\n const inner = new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dec.length, maximumFractionDigits: dec.length }).format(Math.abs(v) / scale);\n let done = false;\n const body = parts\n .map((pt) => {\n if (pt.type === 'integer' || pt.type === 'group' || pt.type === 'decimal' || pt.type === 'fraction') {\n if (done) return '';\n done = true;\n return inner;\n }\n return pt.value;\n })\n .join('');\n return (v < 0 && ref >= 0 ? '-' : '') + body;\n}\n\n/** zh-TW with TWD: NT$ 1,280, negatives -NT$ 1,280. Other locales and currencies: Intl's own symbol and order. */\nfunction money(v: number, o: { currency?: string; compact?: boolean; like?: number } = {}): string {\n const cur = o.currency || I18N.currency;\n const body = o.compact ? compact(Math.abs(v), o.like !== undefined ? Math.abs(o.like) : undefined) : number(Math.abs(v), 'money');\n if (isZhTW() && cur === 'TWD') return `${v < 0 ? '-' : ''}NT$ ${body}`;\n if (o.compact) return `${v < 0 ? '-' : ''}${body} ${cur}`;\n return new Intl.NumberFormat(I18N.locale, {\n style: 'currency',\n currency: cur,\n currencyDisplay: 'narrowSymbol',\n minimumFractionDigits: 0,\n maximumFractionDigits: cur === 'TWD' || cur === 'JPY' ? 0 : 2,\n }).format(v);\n}\n\n/** Bytes to 「186 KB」「54.9 MB」「1.2 GB」. */\nexport function fileSize(b: number | null | undefined): string {\n if (b == null || Number.isNaN(b)) return '';\n if (b < 1048576) return number(Math.max(1, Math.round(b / 1024))) + ' KB';\n if (b < 1073741824) return number(b / 1048576, 1) + ' MB';\n return number(b / 1073741824, 1) + ' GB';\n}\n\n/** Shortens a path: keeps the first segment and the last two, 「src/…/hooks/ops.c:58」. */\nfunction path(p: string | null | undefined, o: { head?: number; tail?: number } = {}): string {\n const head = o.head ?? 1;\n const tail = o.tail ?? 2;\n const parts = String(p ?? '').split('/');\n return parts.length > head + tail ? `${parts.slice(0, head).join('/')}/…/${parts.slice(-tail).join('/')}` : String(p ?? '');\n}\n\n/** Every date, number, amount, size and path shown in the UI goes through these. */\nexport const format = { locale, date, time, dateTime, relative, month, weekdays, firstDay, number, percent, compact, money, fileSize, path };\n\n/* Calendar helpers (local dates, no time). */\nexport const fmtDate = (d: Date | null | undefined): string => (d ? `${d.getFullYear()}/${pad2(d.getMonth() + 1)}/${pad2(d.getDate())}` : '');\n\nexport function parseDate(s: string | null | undefined): Date | null {\n const m = /^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})$/.exec(s || '');\n if (!m) return null;\n const d = new Date(+m[1], +m[2] - 1, +m[3]);\n return d.getMonth() === +m[2] - 1 ? d : null;\n}\n\nexport const sameDay = (a: Date | null | undefined, b: Date | null | undefined): boolean =>\n !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();\n\nexport const dayAdd = (d: Date, n: number): Date => new Date(d.getFullYear(), d.getMonth(), d.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AAI,CAAC,GAAG,OAAO;CACf,MAAM,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE;CAC1C,OAAO,EAAE,SAAS,MAAM,CAAC,EAAE,KAAK,IAAI,IAAI;AAC1C;AAEA,MAAa,WAAW,GAA4B,MAClD,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,MAAM,EAAE,YAAY,KAAK,EAAE,SAAS,MAAM,EAAE,SAAS,KAAK,EAAE,QAAQ,MAAM,EAAE,QAAQ;AAElH,MAAa,UAAU,GAAS,MAAoB,IAAI,KAAK,EAAE,YAAY,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ,IAAI,CAAC"}
package/dist/format.js CHANGED
@@ -1 +1 @@
1
- export { c as addMessages, i as format, l as setLocale, u as t } from "./format-entry-B1gAZnIN.js";
1
+ export { c as addMessages, i as format, l as setLocale, u as t } from "./format-entry-DDglckmU.js";
package/dist/index.d.ts CHANGED
@@ -854,13 +854,20 @@ interface LayerGraphEdge {
854
854
  inferred?: boolean;
855
855
  /** Label of an inferred edge; `backticks` and numbers are in Geist Mono. */
856
856
  label?: string;
857
+ /** Names the edge for selectedEdge and onSelectEdge. Default `${from}->${to}`. */
858
+ id?: string;
857
859
  }
858
860
  interface LayerGraphProps {
859
861
  nodes: LayerGraphNode[];
860
862
  edges: LayerGraphEdge[];
861
863
  selected?: string | null;
862
- /** Selecting a box dims everything unrelated and turns its lines accent. */
864
+ /** Selecting a box dims everything unrelated and turns its lines accent. Clears the selected edge. */
863
865
  onSelect?: (id: string | null) => void;
866
+ /** The selected edge's id (controlled, like selected). */
867
+ selectedEdge?: string | null;
868
+ /** Makes edges selectable: a click on a line or its label, Enter or Space. null when it is clicked again, on a click on
869
+ * the empty diagram or on Escape. Clears the selected box. Without it, edges cannot be clicked. */
870
+ onSelectEdge?: (id: string | null) => void;
864
871
  /** px. Default 200. */
865
872
  nodeWidth?: number;
866
873
  /** Text under a box's size bar; {n} is the size. Default 「{n} 個項目」. */
@@ -1330,7 +1337,8 @@ interface TourStep {
1330
1337
  title: string;
1331
1338
  /** What it does, 1 short sentence; `backticks` are code. */
1332
1339
  text: string;
1333
- /** Default 'bottom'; flips when there is no room. */
1340
+ /** Default 'bottom'; flips when there is no room. When neither side fits (a target about as tall as the window),
1341
+ * the card sits inside the target, at the bottom center of the window. */
1334
1342
  side?: 'bottom' | 'top';
1335
1343
  /** Space around the highlighted part in px. Default 6. */
1336
1344
  padding?: number;
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-DDglckmU.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";
@@ -3882,12 +3882,46 @@ function LayerGraph(p) {
3882
3882
  }
3883
3883
  for (const k in outs) outs[k].sort((a, b) => pos[a.to].x - pos[b.to].x);
3884
3884
  for (const k in ins) ins[k].sort((a, b) => pos[a.from].x - pos[b.from].x);
3885
- const related = (e) => !!sel && (e.from === sel || e.to === sel);
3886
- const near = (id) => !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
3885
+ const edgeId = (e) => e.id ?? `${e.from}->${e.to}`;
3886
+ const pickEdge = p.onSelectEdge;
3887
+ const [hover, setHover] = React.useState(null);
3888
+ const scroller = React.useRef(null);
3889
+ const [more, setMore] = React.useState(false);
3890
+ const [scrolled, setScrolled] = React.useState(false);
3891
+ const [overflows, setOverflows] = React.useState(false);
3892
+ const measureScroll = React.useCallback(() => {
3893
+ const el = scroller.current;
3894
+ if (!el) return;
3895
+ const wide = el.scrollWidth > el.clientWidth + 1;
3896
+ setOverflows(wide);
3897
+ setMore(wide && el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
3898
+ }, []);
3899
+ React.useLayoutEffect(() => {
3900
+ const el = scroller.current;
3901
+ if (!el) return;
3902
+ measureScroll();
3903
+ const ro = new ResizeObserver(measureScroll);
3904
+ ro.observe(el);
3905
+ if (el.firstElementChild) ro.observe(el.firstElementChild);
3906
+ return () => ro.disconnect();
3907
+ }, [measureScroll]);
3908
+ const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
3909
+ const related = (e) => selEdge ? e === selEdge : !!sel && (e.from === sel || e.to === sel);
3910
+ const focus = !!sel || !!selEdge;
3911
+ const near = (id) => selEdge ? id === selEdge.from || id === selEdge.to : !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
3912
+ const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
3913
+ const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
3914
+ const choose = (e) => {
3915
+ const id = edgeId(e);
3916
+ const next = p.selectedEdge === id ? null : id;
3917
+ if (next && sel != null) p.onSelect?.(null);
3918
+ pickEdge?.(next);
3919
+ };
3887
3920
  const paths = [];
3888
3921
  const labels = [];
3889
3922
  const marks = [];
3890
3923
  const arrows = [];
3924
+ const hitPaths = [];
3891
3925
  edges.forEach((e, idx) => {
3892
3926
  const a = pos[e.from];
3893
3927
  const b = pos[e.to];
@@ -3924,13 +3958,37 @@ function LayerGraph(p) {
3924
3958
  [tx, ty - 8]
3925
3959
  ];
3926
3960
  const r = related(e);
3927
- const dim = !!sel && !r;
3928
- const w = e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount);
3961
+ const dim = focus && !r;
3962
+ const picked = e === selEdge;
3963
+ const hovered = !!pickEdge && hover === edgeId(e) && !r;
3964
+ const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
3965
+ const d = route(clean(pts), 10);
3929
3966
  paths.push(/* @__PURE__ */ jsx("path", {
3930
- className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim"),
3931
- d: route(clean(pts), 10),
3967
+ className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
3968
+ d,
3932
3969
  strokeWidth: w
3933
3970
  }, "p" + idx));
3971
+ if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
3972
+ className: "ui-lg-hit",
3973
+ "data-edge": edgeId(e),
3974
+ d,
3975
+ role: "button",
3976
+ tabIndex: 0,
3977
+ "aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)}`,
3978
+ "aria-pressed": picked,
3979
+ onClick: (ev) => {
3980
+ ev.stopPropagation();
3981
+ choose(e);
3982
+ },
3983
+ onPointerEnter: () => setHover(edgeId(e)),
3984
+ onPointerLeave: () => setHover(null),
3985
+ onKeyDown: (ev) => {
3986
+ if (ev.key === "Enter" || ev.key === " ") {
3987
+ ev.preventDefault();
3988
+ choose(e);
3989
+ } else if (ev.key === "Escape" && picked) pickEdge(null);
3990
+ }
3991
+ }, "h" + idx));
3934
3992
  arrows.push([
3935
3993
  tx - 5,
3936
3994
  tx + 5,
@@ -3942,9 +4000,10 @@ function LayerGraph(p) {
3942
4000
  d: `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`
3943
4001
  }, "a" + idx));
3944
4002
  if (e.inferred || r) {
3945
- const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
4003
+ const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
3946
4004
  marks.push({
3947
4005
  idx,
4006
+ e,
3948
4007
  text,
3949
4008
  tx,
3950
4009
  ty,
@@ -3973,11 +4032,17 @@ function LayerGraph(p) {
3973
4032
  6
3974
4033
  ]);
3975
4034
  labels.push(/* @__PURE__ */ jsx("span", {
3976
- className: cx("ui-lg-label", m.r && "is-related", m.dim && "is-dim"),
4035
+ className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
3977
4036
  style: {
3978
4037
  left: x0,
3979
4038
  top
3980
4039
  },
4040
+ onClick: pickEdge ? (ev) => {
4041
+ ev.stopPropagation();
4042
+ choose(m.e);
4043
+ } : void 0,
4044
+ onPointerEnter: pickEdge ? () => setHover(edgeId(m.e)) : void 0,
4045
+ onPointerLeave: pickEdge ? () => setHover(null) : void 0,
3981
4046
  children: labelParts(m.text)
3982
4047
  }, "l" + m.idx));
3983
4048
  });
@@ -3996,7 +4061,10 @@ function LayerGraph(p) {
3996
4061
  height: NH
3997
4062
  },
3998
4063
  "aria-pressed": p.onSelect ? on : void 0,
3999
- onClick: p.onSelect ? () => p.onSelect?.(on ? null : n.id) : void 0,
4064
+ onClick: p.onSelect ? () => {
4065
+ if (!on && p.selectedEdge != null) pickEdge?.(null);
4066
+ p.onSelect?.(on ? null : n.id);
4067
+ } : void 0,
4000
4068
  children: [/* @__PURE__ */ jsx("span", {
4001
4069
  className: "ui-lg-name",
4002
4070
  children: n.name || n.id
@@ -4035,28 +4103,51 @@ function LayerGraph(p) {
4035
4103
  return /* @__PURE__ */ jsxs("div", {
4036
4104
  className: cx("ui-graph ui-lg", p.className),
4037
4105
  children: [
4038
- /* @__PURE__ */ jsx("div", {
4039
- className: "ui-lg-scroll",
4040
- children: /* @__PURE__ */ jsxs("div", {
4041
- className: "ui-lg-canvas",
4042
- style: {
4043
- width: W,
4044
- height: H
4106
+ /* @__PURE__ */ jsxs("div", {
4107
+ className: cx("ui-lg-scroller", more && "has-more"),
4108
+ children: [/* @__PURE__ */ jsx("div", {
4109
+ className: "ui-lg-scroll",
4110
+ ref: scroller,
4111
+ onScroll: () => {
4112
+ setScrolled(true);
4113
+ measureScroll();
4045
4114
  },
4046
- role: "group",
4047
- "aria-label": p.label || tr("架構圖"),
4048
- children: [
4049
- /* @__PURE__ */ jsx("svg", {
4115
+ children: /* @__PURE__ */ jsxs("div", {
4116
+ className: "ui-lg-canvas",
4117
+ style: {
4050
4118
  width: W,
4051
- height: H,
4052
- viewBox: `0 0 ${W} ${H}`,
4053
- "aria-hidden": "true",
4054
- children: paths
4055
- }),
4056
- nodes,
4057
- labels
4058
- ]
4059
- })
4119
+ height: H
4120
+ },
4121
+ role: "group",
4122
+ "aria-label": p.label || tr("架構圖"),
4123
+ onClick: pickEdge && p.selectedEdge != null ? () => pickEdge(null) : void 0,
4124
+ children: [
4125
+ /* @__PURE__ */ jsx("svg", {
4126
+ width: W,
4127
+ height: H,
4128
+ viewBox: `0 0 ${W} ${H}`,
4129
+ "aria-hidden": "true",
4130
+ children: paths
4131
+ }),
4132
+ nodes,
4133
+ labels,
4134
+ hitPaths.length ? /* @__PURE__ */ jsx("svg", {
4135
+ className: "ui-lg-hits",
4136
+ width: W,
4137
+ height: H,
4138
+ viewBox: `0 0 ${W} ${H}`,
4139
+ children: hitPaths
4140
+ }) : null
4141
+ ]
4142
+ })
4143
+ }), overflows && !scrolled ? /* @__PURE__ */ jsxs("span", {
4144
+ className: "ui-lg-hint",
4145
+ "aria-hidden": "true",
4146
+ children: [/* @__PURE__ */ jsx(Icon, {
4147
+ name: "arrow-right",
4148
+ size: 14
4149
+ }), tr("左右滑動")]
4150
+ }) : null]
4060
4151
  }),
4061
4152
  shared.length ? /* @__PURE__ */ jsxs("div", {
4062
4153
  className: "ui-lg-shared",
@@ -5139,6 +5230,53 @@ function findTarget(t) {
5139
5230
  }
5140
5231
  return t instanceof Element ? t : t.current;
5141
5232
  }
5233
+ const GAP = 12;
5234
+ /** The space kept between the card and the window edges: the --space-3 token. */
5235
+ function edge() {
5236
+ return parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--space-3")) || 12;
5237
+ }
5238
+ /** Where the card goes for a highlighted box: the preferred side, the other side, or inside the box at the bottom
5239
+ * center of the window when neither side has room. Returns the anchor line the card is placed against. */
5240
+ function placeCard(rect, cardH, prefer) {
5241
+ const margin = typeof document === "undefined" ? 12 : edge();
5242
+ const vh = typeof window === "undefined" ? 0 : window.innerHeight;
5243
+ const fits = (side) => rect ? side === "bottom" ? rect.top + rect.height + GAP + cardH + margin <= vh : rect.top - GAP - cardH - margin >= 0 : false;
5244
+ if (!rect) return {
5245
+ mode: "center",
5246
+ side: "top",
5247
+ offset: 0,
5248
+ margin,
5249
+ line: {
5250
+ left: 0,
5251
+ top: Math.max(margin + cardH, vh / 2 + cardH / 2),
5252
+ width: window.innerWidth,
5253
+ height: 0
5254
+ }
5255
+ };
5256
+ const other = prefer === "bottom" ? "top" : "bottom";
5257
+ const side = fits(prefer) ? prefer : fits(other) ? other : null;
5258
+ if (side) return {
5259
+ mode: side,
5260
+ side,
5261
+ offset: GAP,
5262
+ margin,
5263
+ line: rect
5264
+ };
5265
+ const end = rect.top + rect.height;
5266
+ const bottom = Math.max(margin + cardH, end >= vh - margin ? vh - margin : end - margin);
5267
+ return {
5268
+ mode: "inside",
5269
+ side: "top",
5270
+ offset: 0,
5271
+ margin,
5272
+ line: {
5273
+ left: rect.left,
5274
+ top: bottom,
5275
+ width: rect.width,
5276
+ height: 0
5277
+ }
5278
+ };
5279
+ }
5142
5280
  /** The first-use walkthrough: the page goes dark except the part being introduced, with a card beside it. */
5143
5281
  function Tour({ open, steps, onClose, skippable = true, step: controlled, onStepChange }) {
5144
5282
  const [inner, setInner] = React.useState(0);
@@ -5146,6 +5284,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5146
5284
  const step = steps[i];
5147
5285
  const [rect, setRect] = React.useState(null);
5148
5286
  const next = React.useRef(null);
5287
+ const [cardH, setCardH] = React.useState(0);
5149
5288
  const [wasOpen, setWasOpen] = React.useState(open);
5150
5289
  if (open !== wasOpen) {
5151
5290
  setWasOpen(open);
@@ -5162,8 +5301,9 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5162
5301
  React.useEffect(() => {
5163
5302
  if (!open || !hasStep) return;
5164
5303
  let el = findTarget(target);
5304
+ const tall = (el?.getBoundingClientRect().height ?? 0) > window.innerHeight;
5165
5305
  el?.scrollIntoView?.({
5166
- block: "center",
5306
+ block: tall ? "start" : "center",
5167
5307
  behavior: reduced() ? "auto" : "smooth"
5168
5308
  });
5169
5309
  let raf = 0;
@@ -5198,7 +5338,24 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5198
5338
  target,
5199
5339
  pad
5200
5340
  ]);
5201
- const anchor = React.useMemo(() => ({ getBoundingClientRect: () => rect ? new DOMRect(rect.left, rect.top, rect.width, rect.height) : new DOMRect(window.innerWidth / 2, window.innerHeight / 2, 0, 0) }), [rect]);
5341
+ const observer = React.useRef(null);
5342
+ const card = React.useCallback((el) => {
5343
+ observer.current?.disconnect();
5344
+ observer.current = null;
5345
+ if (!el) return;
5346
+ const measure = () => setCardH(el.offsetHeight);
5347
+ measure();
5348
+ observer.current = new ResizeObserver(measure);
5349
+ observer.current.observe(el);
5350
+ }, []);
5351
+ const place = placeCard(rect, cardH, step?.side ?? "bottom");
5352
+ const line = place.line;
5353
+ const anchor = React.useMemo(() => ({ getBoundingClientRect: () => line ? new DOMRect(line.left, line.top, line.width, line.height) : new DOMRect(window.innerWidth / 2, window.innerHeight / 2, 0, 0) }), [
5354
+ line?.left,
5355
+ line?.top,
5356
+ line?.width,
5357
+ line?.height
5358
+ ]);
5202
5359
  if (!open || !step) return null;
5203
5360
  const lastStep = i === steps.length - 1;
5204
5361
  return /* @__PURE__ */ jsx(Popover$1.Root, {
@@ -5217,52 +5374,62 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5217
5374
  }), /* @__PURE__ */ jsx(Popover$1.Positioner, {
5218
5375
  className: "ui-float ui-tour-float",
5219
5376
  anchor,
5220
- side: rect ? step.side ?? "bottom" : "bottom",
5377
+ side: place.side,
5221
5378
  align: "center",
5222
- sideOffset: rect ? 12 : -100,
5379
+ sideOffset: place.offset,
5380
+ collisionPadding: place.margin,
5381
+ collisionAvoidance: {
5382
+ side: "none",
5383
+ align: "shift",
5384
+ fallbackAxisSide: "none"
5385
+ },
5223
5386
  children: /* @__PURE__ */ jsxs(Popover$1.Popup, {
5387
+ ref: card,
5224
5388
  className: "ui-tour-card",
5389
+ "data-placement": place.mode,
5225
5390
  initialFocus: next,
5226
- children: [
5227
- /* @__PURE__ */ jsx("div", {
5228
- className: "ui-tour-count",
5229
- children: monoNums(tr("{n} / {total}", {
5230
- n: "",
5231
- total: ""
5232
- }), [i + 1, steps.length])
5233
- }),
5234
- /* @__PURE__ */ jsx(Popover$1.Title, {
5235
- className: "ui-tour-title",
5236
- children: step.title
5237
- }),
5238
- /* @__PURE__ */ jsx(CodeText, {
5239
- as: "div",
5240
- className: "ui-tour-text",
5241
- text: step.text
5242
- }),
5243
- /* @__PURE__ */ jsxs("div", {
5244
- className: "ui-tour-actions",
5245
- children: [
5246
- skippable && !lastStep ? /* @__PURE__ */ jsx("button", {
5247
- type: "button",
5248
- className: "ui-link-btn is-muted",
5249
- onClick: () => end("skip"),
5250
- children: tr("略過")
5251
- }) : null,
5252
- /* @__PURE__ */ jsx("span", { className: "ui-tour-gap" }),
5253
- i > 0 ? /* @__PURE__ */ jsx(Button, {
5254
- onClick: () => go(i - 1),
5255
- children: tr("上一步")
5256
- }) : null,
5257
- /* @__PURE__ */ jsx(Button, {
5258
- ref: next,
5259
- variant: "primary",
5260
- onClick: () => lastStep ? end("done") : go(i + 1),
5261
- children: lastStep ? tr("完成") : tr("下一步")
5262
- })
5263
- ]
5264
- })
5265
- ]
5391
+ children: [/* @__PURE__ */ jsxs("div", {
5392
+ className: "ui-tour-body",
5393
+ children: [
5394
+ /* @__PURE__ */ jsx("div", {
5395
+ className: "ui-tour-count",
5396
+ children: monoNums(tr("{n} / {total}", {
5397
+ n: "",
5398
+ total: ""
5399
+ }), [i + 1, steps.length])
5400
+ }),
5401
+ /* @__PURE__ */ jsx(Popover$1.Title, {
5402
+ className: "ui-tour-title",
5403
+ children: step.title
5404
+ }),
5405
+ /* @__PURE__ */ jsx(CodeText, {
5406
+ as: "div",
5407
+ className: "ui-tour-text",
5408
+ text: step.text
5409
+ })
5410
+ ]
5411
+ }), /* @__PURE__ */ jsxs("div", {
5412
+ className: "ui-tour-actions",
5413
+ children: [
5414
+ skippable && !lastStep ? /* @__PURE__ */ jsx("button", {
5415
+ type: "button",
5416
+ className: "ui-link-btn is-muted",
5417
+ onClick: () => end("skip"),
5418
+ children: tr("略過")
5419
+ }) : null,
5420
+ /* @__PURE__ */ jsx("span", { className: "ui-tour-gap" }),
5421
+ i > 0 ? /* @__PURE__ */ jsx(Button, {
5422
+ onClick: () => go(i - 1),
5423
+ children: tr("上一步")
5424
+ }) : null,
5425
+ /* @__PURE__ */ jsx(Button, {
5426
+ ref: next,
5427
+ variant: "primary",
5428
+ onClick: () => lastStep ? end("done") : go(i + 1),
5429
+ children: lastStep ? tr("完成") : tr("下一步")
5430
+ })
5431
+ ]
5432
+ })]
5266
5433
  }, i)
5267
5434
  })] })
5268
5435
  });